saveRule function infrastructure exported ✓ 100.0%
Last updated: 2026-02-24T21:07:57.583Z
Metrics
LOC: 18
Complexity: 3
Params: 1
Coverage: 100.0% (7/7 lines, 4x executed)
Signature
saveRule(rule: FieldRule): : Promise<void>
Summary
Saves a field rule (upsert). Updates updatedAt on existing rules; sets both createdAt and updatedAt on new ones.
Tags
#@param rule - The rule to save
Source Code
export async function saveRule(rule: FieldRule): Promise<void> {
await updateStorageAtomically(
STORAGE_KEYS.RULES,
[] as FieldRule[],
(rules) => {
const next = [...rules];
const existingIndex = next.findIndex((r) => r.id === rule.id);
if (existingIndex >= 0) {
next[existingIndex] = { ...rule, updatedAt: Date.now() };
} else {
next.push({ ...rule, createdAt: Date.now(), updatedAt: Date.now() });
}
return next;
},
);
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| updateStorageAtomically | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handle | uses |