saveForm function infrastructure exported ✓ 100.0%

Last updated: 2026-03-01T23:25:47.133Z

Metrics

LOC: 18 Complexity: 3 Params: 1 Coverage: 100.0% (7/7 lines, 5x executed)

Signature

saveForm(form: SavedForm): : Promise<void>

Summary

Saves a form template (upsert). Updates timestamps appropriately.

Tags

#@param form - The saved form to persist

Source Code

export async function saveForm(form: SavedForm): Promise<void> {
  await updateStorageAtomically(
    STORAGE_KEYS.SAVED_FORMS,
    [] as SavedForm[],
    (forms) => {
      const next = [...forms];
      const existingIndex = next.findIndex((f) => f.id === form.id);

      if (existingIndex >= 0) {
        next[existingIndex] = { ...form, updatedAt: Date.now() };
      } else {
        next.push({ ...form, createdAt: Date.now(), updatedAt: Date.now() });
      }

      return next;
    },
  );
}

Dependencies (Outgoing)

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

Impact (Incoming)

graph LR saveForm["saveForm"] FillableElement["FillableElement"] handle["handle"] FillableElement -->|uses| saveForm handle -->|uses| saveForm style saveForm fill:#dbeafe,stroke:#2563eb,stroke-width:2px click saveForm "639eb913ec8fd306.html" click FillableElement "2ecf5aaac3f668a8.html" click handle "02de534415e566f4.html"
SourceType
FillableElement uses
handle uses