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)

graph LR saveRule["saveRule"] updateStorageAtomically["updateStorageAtomically"] saveRule -->|calls| updateStorageAtomically style saveRule fill:#dbeafe,stroke:#2563eb,stroke-width:2px click saveRule "63edd701c4b09a38.html" click updateStorageAtomically "bf2f57323401fa98.html"
TargetType
updateStorageAtomically calls

Impact (Incoming)

graph LR saveRule["saveRule"] handle["handle"] handle -->|uses| saveRule style saveRule fill:#dbeafe,stroke:#2563eb,stroke-width:2px click saveRule "63edd701c4b09a38.html" click handle "57ebaea8374ad16b.html"
SourceType
handle uses