@elytracms/studio 0.0.101 → 0.0.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/convex/asset-meta-patch.test.ts +7 -27
  2. package/convex/assets.ts +6 -41
  3. package/convex/cms.ts +2 -29
  4. package/convex/delivery.ts +2 -2
  5. package/convex/record-functions.ts +15 -82
  6. package/convex/redirects.ts +11 -116
  7. package/convex/schema.ts +4 -23
  8. package/convex/triggers.ts +7 -14
  9. package/dist/components/ai/ai-chat-panel.js +8 -5
  10. package/dist/components/ai/ai-chat-panel.js.map +1 -1
  11. package/dist/components/ai/translate-skipped.js +1 -0
  12. package/dist/components/ai/translate-skipped.js.map +1 -1
  13. package/dist/components/assets/asset-detail.js +1 -2
  14. package/dist/components/assets/asset-detail.js.map +1 -1
  15. package/dist/components/assets/asset-metadata.d.ts +2 -9
  16. package/dist/components/assets/asset-metadata.js +3 -10
  17. package/dist/components/assets/asset-metadata.js.map +1 -1
  18. package/dist/components/assets/asset-search.js +1 -1
  19. package/dist/components/assets/asset-search.js.map +1 -1
  20. package/dist/components/assets/asset-selection.js +2 -2
  21. package/dist/components/assets/asset-selection.js.map +1 -1
  22. package/dist/components/assets/assets-collection-view-source.d.ts +2 -3
  23. package/dist/components/assets/assets-collection-view-source.js +2 -3
  24. package/dist/components/assets/assets-collection-view-source.js.map +1 -1
  25. package/dist/components/builder/__fixtures__/reuse-race.d.ts +30 -0
  26. package/dist/components/builder/__fixtures__/reuse-race.js +77 -0
  27. package/dist/components/builder/__fixtures__/reuse-race.js.map +1 -0
  28. package/dist/components/builder/composition-field-editor.js +3 -3
  29. package/dist/components/builder/composition-field-editor.js.map +1 -1
  30. package/dist/components/builder/reuse-context.d.ts +2 -1
  31. package/dist/components/builder/reuse-context.js +5 -20
  32. package/dist/components/builder/reuse-context.js.map +1 -1
  33. package/dist/components/builder/reuse.d.ts +18 -11
  34. package/dist/components/builder/reuse.js +12 -14
  35. package/dist/components/builder/reuse.js.map +1 -1
  36. package/dist/components/cms/asset-field.js +1 -3
  37. package/dist/components/cms/asset-field.js.map +1 -1
  38. package/dist/components/cms/cell.d.ts +2 -2
  39. package/dist/components/cms/cell.js +8 -18
  40. package/dist/components/cms/cell.js.map +1 -1
  41. package/dist/components/cms/detail-editor.js +2 -1
  42. package/dist/components/cms/detail-editor.js.map +1 -1
  43. package/dist/components/cms/field-control.js +13 -1
  44. package/dist/components/cms/field-control.js.map +1 -1
  45. package/dist/lib/ai/chat-context.d.ts +6 -2
  46. package/dist/lib/ai/chat-context.js +11 -5
  47. package/dist/lib/ai/chat-context.js.map +1 -1
  48. package/dist/lib/ai/knowledge.d.ts +9 -9
  49. package/dist/lib/ai/knowledge.js +22 -0
  50. package/dist/lib/ai/knowledge.js.map +1 -1
  51. package/dist/lib/ai/tools.d.ts +8 -1
  52. package/dist/lib/ai/tools.js +33 -15
  53. package/dist/lib/ai/tools.js.map +1 -1
  54. package/dist/lib/ai/translate-document.d.ts +8 -1
  55. package/dist/lib/ai/translate-document.js +20 -5
  56. package/dist/lib/ai/translate-document.js.map +1 -1
  57. package/dist/lib/ai/update-fields.js +5 -12
  58. package/dist/lib/ai/update-fields.js.map +1 -1
  59. package/dist/lib/ai/writer-form.d.ts +61 -0
  60. package/dist/lib/ai/writer-form.js +218 -27
  61. package/dist/lib/ai/writer-form.js.map +1 -1
  62. package/dist/lib/assets/upload.d.ts +1 -2
  63. package/dist/lib/assets/upload.js +1 -2
  64. package/dist/lib/assets/upload.js.map +1 -1
  65. package/dist/lib/engine-version.d.ts +1 -1
  66. package/dist/lib/engine-version.js +1 -1
  67. package/dist/lib/engine-version.js.map +1 -1
  68. package/dist/lib/i18n/messages.de.js +9 -1
  69. package/dist/lib/i18n/messages.de.js.map +1 -1
  70. package/dist/lib/i18n/messages.en.d.ts +7 -0
  71. package/dist/lib/i18n/messages.en.js +11 -1
  72. package/dist/lib/i18n/messages.en.js.map +1 -1
  73. package/dist/lib/operations/cms-persistence.d.ts +20 -10
  74. package/dist/lib/operations/cms-persistence.js +11 -3
  75. package/dist/lib/operations/cms-persistence.js.map +1 -1
  76. package/dist/lib/persistence/convex-adapter.js +7 -2
  77. package/dist/lib/persistence/convex-adapter.js.map +1 -1
  78. package/package.json +3 -3
  79. package/convex/asset-alt-migration.test.ts +0 -127
  80. package/convex/redirect-migration.test.ts +0 -205
  81. package/convex/version-kind-stamping.test.ts +0 -118
@@ -1 +1 @@
1
- {"version":3,"file":"cms-persistence.js","sourceRoot":"","sources":["../../../src/lib/operations/cms-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,0BAA0B,CAAA;AAYjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAoIpD,2FAA2F;AAC3F,MAAM,UAAU,oBAAoB,CAAC,KAAqB;IACxD,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAA;IAC9C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAA;IAC3D,OAAO,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACpD,CAAC;AA2KD,uHAAuH;AACvH,MAAM,cAAc,GAAG,CAAC,CAAA;AAexB,qHAAqH;AACrH,MAAM,eAAe,GAAG,GAAG,CAAA;AAqB3B;;;;;;;;;;;;;GAaG;AACH,SAAS,YAAY,CAAC,UAA0B,EAAE,IAA2B;IAC3E,IAAI,EAAE,GAAG,UAAU,CAA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KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;gBAClG,QAAQ,CAAC,KAAK,CAAC,CAAA;YACjB,CAAC;YACD,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,aAAa,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG;YACb,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC3C,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;oBAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;YACtD,CAAC;YACD,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import {\n applyDocumentPatches,\n documentKey,\n expandValuePath,\n fieldPositionPatches,\n formatValuePath,\n isValuePathPrefix,\n readValueAt,\n selfTypeDocument,\n semanticValueEqual,\n touchedPaths,\n touchedPathsOfEntry,\n valuePathsOverlap,\n} from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n DocumentRef,\n PropFieldLookup,\n RefusedPatch,\n ValuePath,\n} from '@elytracms/core/cms-core'\nimport type { CmsDocumentRecord, DocumentPatchRecord } from '@elytracms/core/persistence'\nimport type { OperationError, OperationResult, OperationsClient } from './operations-package'\nimport { createPersistQueue } from './persist-queue'\n\n/**\n * CMS session → operations persistence (EC-141 → EC-595 part A2 → EC-647): the PATCH QUEUE.\n *\n * The CMS session keeps documents as optimistic, synchronous state; every write is\n * mirrored onto the operations layer through the revisioned aggregate's two verbs\n * (EC-595, ratified 2026-10-24): `documents.patch` for editing, `documents.replace`\n * for whole-document writers (create, import, the slot alias). There is no document\n * diffing anywhere: every writer EMITS the patches it made at its source (the form's\n * field path, the canvas's node patches, the AI proposal's field changes, bulk\n * set-field, transfer) and hands them to {@link CmsPersister.commit}.\n *\n * **Per document, the persister keeps** the server row it last adopted (`base`), the\n * committed-but-unacknowledged writes (each with the revision it was AUTHORED against),\n * the refused paths awaiting a decision, and the writes it made itself (the own-write\n * ledger). It derives the session's view of the document from them:\n *\n * display = base.document ⊕ unresolved conflicts (mine) ⊕ in-flight ⊕ queued\n *\n * by re-applying the patches with THE merge (`applyDocumentPatches`, `since: []`) — the\n * same pure function both stores run (a queued whole-document write resets the view to\n * its snapshot at its place in the order). So local edits win on their paths until they\n * are flushed (EC-595 point 7), and a server row adopted underneath them (a write\n * result, a subscription push, a conflict's `current`) shows everywhere else at once.\n *\n * **A value and the revision it was authored against travel together (EC-647).** Every\n * view this persister shows is registered with the revision it is at\n * ({@link CmsPersister.revisionOfView} — the shown document object IS the token), and a\n * writer hands each patch over WITH the revision of the view it was authored on\n * (`bases`, required). The persister never substitutes a newer revision for it — not at\n * commit (the old `bases ?? tracked revision` default), not at send (the old\n * `queued.base ?? entry.base.revision`), not in a whole-document `replace` (which read\n * the tracked revision at SEND time — Codex F10), and not for an untracked document\n * (which sent at whatever revision a later read returned). A write that cannot name the\n * revision it was authored against is refused, visibly — it never borrows one.\n *\n * - **A view's token is per position (EC-667, Codex F18).** A view that shows a pending\n * write is a COMPOSITE: no single underlying revision names it. Each shown view is\n * registered with its provenance at display time — the base's revision, or under a\n * pending whole-document write its snapshot's authoring revision, and over that each\n * own unacknowledged write shown (queued, in flight, an open conflict's \"mine\") with\n * the base it was authored at. `revisionOfView(view, path)` is the revision the content\n * at `path` was authored against: the earliest of the floor and of the shown writes that\n * OVERLAP `path` — at it, at an ancestor, or at a descendant, whose content the value at\n * `path` contains (EC-681, Codex F23); a sibling's write does not lower it. Positions\n * are compared in their STRUCTURAL form, as the store compares them (EC-693, Codex F28):\n * a node path carries its component ancestry — each shown write's as the merge applied\n * it in that view, the asked path's expanded against the view — so a parent node's token\n * sees a pending write of its child's prop, which a submitted `nodePropPath` names\n * without the parent.\n * `revisionOfView(view)` — a whole-document writer — the EARLIEST of all. The record is\n * immutable, so it outlives the pending write: an edit started on a view that showed a\n * snapshot keeps the snapshot's revision after the snapshot is refused or fails\n * (before EC-667 the composite was named by the base's revision — a colleague's change\n * adopted underneath a pending snapshot lent the edit its revision, and the edit,\n * authored on the old content, overwrote it).\n * - **A position under one of this session's own unacknowledged writes** (queued, in\n * flight, or an open conflict's \"mine\") was authored against THAT write's base: the\n * view showed mine there, not a colleague's change that may sit underneath it. The\n * later write takes the earlier base, so a colleague's hidden change is still refused\n * on it (same-field supersession has always kept the earlier base for this reason).\n * - **The own-write ledger.** A base may be LIFTED, at send time, across revisions this\n * persister wrote — and only those: across a run of consecutive own revisions right\n * after it (nothing foreign happened in between), or to an own write's revision when\n * the patch only touches positions that write covered (both read where they land in the\n * server row, node ancestry included — EC-693) and the write was sent at or\n * below the patch's base (the store refused every foreign change of those positions in\n * between, or the write would not have applied) — or, EC-681, across a revision someone\n * else wrote that the patch log shows touched none of the patch's positions (the store\n * would not refuse the patch on it), read only when an own write beyond it would\n * otherwise refuse the patch. Without it, the session's second edit of a position, made\n * at the revision its first was authored against, would be refused by its own first\n * write — and an edit of a parent, authored over an own child write, by that child's.\n * - **The provisional view** (`undefined` authoring revision): a document whose view\n * has no revision yet — our own create in flight, or a document the session never\n * tracked (a staged transfer). Writes on it are based on the revision our create\n * landed at, or — untracked — on a read of the document that EQUALS the view they were\n * authored on; anything else is refused as a conflict per position.\n *\n * Consecutive runs of equal (lifted) base are sent in commit order, one\n * `documents.patch` call per run; a queued whole-document write is sent in its place in\n * that order.\n *\n * **A refused path is a conflict ON THAT FIELD** ({@link DocumentConflict}): the\n * session shows \"changed by X — take theirs / keep mine\"; until the user decides, the\n * field keeps showing mine (and further edits of it replace mine without being sent);\n * keep-mine re-sends at the current base — the ONE deliberate \"at the current base\"\n * write: the user chose it after seeing theirs; take-theirs drops mine. Never a\n * whole-document dialog, never a silent overwrite.\n */\n\n/** One refused patch awaiting the user's decision (EC-595 binding point 5). */\nexport interface DocumentConflict {\n /** Stable id for the UI (`<key>|<path>`); one conflict per path. */\n readonly id: string\n readonly ref: DocumentRef\n /** The refused patch — \"mine\". */\n readonly patch: DocumentPatch\n /** The submitted target path. */\n readonly path: ValuePath\n /** The value at that path on the server NOW — \"theirs\" (`undefined` = absent). */\n readonly theirs: unknown\n /** `conflict` — changed since the base; `invalid` — never resolved (e.g. its node is gone). */\n readonly reason: RefusedPatch['reason']\n /** The server revision the refusal was made at. */\n readonly revision: number\n /** Who changed the path (the patch log's actor), once resolved; `undefined` while unknown. */\n readonly actor?: string\n}\n\n/** How one {@link CmsPersister.commit} ended once its patches were acknowledged. */\nexport type CommitOutcome =\n | { readonly status: 'applied'; readonly record: CmsDocumentRecord }\n /** Refused per field — the conflicts stay open on the document for the user to resolve. */\n | { readonly status: 'refused'; readonly conflicts: readonly DocumentConflict[] }\n /**\n * A transport / authorization failure, or a write that named no authoring revision (also\n * reported through `onError`). A write the backend did not judge is KEPT (EC-674): it\n * stays shown and queued, and the next commit or forced flush re-sends it — its commit,\n * and every commit queued behind it, settles `failed` with that error when the drain\n * stops on it (EC-686), never left waiting.\n */\n | { readonly status: 'failed'; readonly error: OperationError }\n\n/**\n * EC-728 — what {@link CmsPersister.deleteCreated} did: `deleted`; `gone` (already deleted);\n * `changed` (written since the create — edited or published); `referenced` (a strict relation\n * references it); `not-created` (this session holds no create receipt for it); `failed`.\n */\nexport type DeleteCreatedOutcome = 'deleted' | 'gone' | 'changed' | 'referenced' | 'not-created' | 'failed'\n\n/** EC-728 — the refusal of a conditional delete, read off the operation's error (pure). */\nexport function deleteCreatedRefusal(error: OperationError): Exclude<DeleteCreatedOutcome, 'deleted' | 'not-created'> {\n if (error.code === 'not-found') return 'gone'\n if (error.code !== 'conflict') return 'failed'\n if ((error.referrers?.length ?? 0) > 0) return 'referenced'\n return error.current === null ? 'gone' : 'changed'\n}\n\nexport interface CmsPersister {\n /** Adopt a server row as this session's base for its document (hydration, a create result). */\n track(row: TrackedRow): void\n /**\n * The revision of the server row the session last adopted for a document (`undefined` =\n * untracked). A document deleted since still answers its removed lifetime's last\n * revision (EC-673): a publish conditioned on it is refused, never sent unconditionally\n * into a re-creation this session never showed — so whether to create or replace is\n * never decided on it alone ({@link importWrite} decides on the row the session shows).\n */\n revisionOf(ref: DocumentRef): number | undefined\n /** The session's view of a tracked document (base ⊕ local), or `undefined`. */\n documentOf(ref: DocumentRef): CmsDocument | undefined\n /**\n * EC-647 — the revision a document value this persister SHOWED is at: every view it\n * emits (`onDocument`, {@link documentOf}) and every row it tracks is registered with\n * its revision, so a writer holding the value it displayed holds its revision too —\n * the pair cannot drift apart. `undefined` for a value the persister never showed (a\n * copy, a fixture), or a provisional view (our own create in flight, an untracked\n * document).\n *\n * EC-667 — per position: `path` given, the revision the content the view shows AT\n * `path` was authored against (an editor's first keystroke there); without it, the\n * EARLIEST authoring revision of any position the view shows — the token of a\n * whole-document writer (a replace, an import). A view showing a pending write is never\n * named by the base's revision alone (see the module doc).\n */\n revisionOfView(view: CmsDocument, path?: ValuePath): number | undefined\n /**\n * Commit patches a writer made and flush them. The session's view updates\n * synchronously (via `onDocument`); the patches persist in order through\n * `documents.patch`. `bases` — REQUIRED, one per patch: the revision of the view the\n * writer authored that patch against (an editor field: the revision its draft was at\n * when the user STARTED that edit; the canvas: the revision of the value its delta is\n * measured from; a table row: {@link revisionOfView} of the row it showed; an AI\n * proposal: the revision of the read it was built from). `undefined` entries mean the\n * view was provisional (see the module doc) — on a document this session tracks and\n * did not create, such a patch is refused. `view` — the session's current document,\n * the provisional view of a document this session holds no revision for (a staged\n * transfer).\n */\n commit(\n ref: DocumentRef,\n patches: readonly DocumentPatch[],\n bases: readonly (number | undefined)[],\n view?: CmsDocument,\n ): Promise<CommitOutcome>\n /** Adopt a server row one of the session's OWN direct writes returned (publish, restore). */\n adoptRecord(record: CmsDocumentRecord): void\n /** Create a document (insert-if-absent: `documents.replace` `{ ifAbsent: true }`). */\n create(document: CmsDocument): void\n /**\n * Write a whole document at the revision it was AUTHORED against (EC-647 — the\n * snapshot and its revision travel together; Codex F10): an import, the slot alias. A\n * move since then — by anyone but this session's own writes — is refused as a\n * conflict, never overwritten. `revision` `undefined`: the snapshot was authored on a\n * provisional view (our own pending create; insert-if-absent when untracked). Sent in\n * its place among the session's queued patches.\n *\n * EC-686 (the owner's ruling, per-position): when the store refuses it, it is decomposed\n * into what the author changed against `authoredOn` — the document the snapshot was made\n * from — and each position is re-sent: it lands, or becomes that field's ordinary\n * conflict. Never a whole-document keep-mine. Without `authoredOn` nothing can be judged\n * per position: the refusal adopts the current row and is reported, as before — never a\n * guess (the session's view at that moment may hold changes the snapshot never saw, which\n * a diff against it would re-send as the author's).\n */\n replace(document: CmsDocument, revision: number | undefined, authoredOn?: CmsDocument): void\n deleteDocument(ref: DocumentRef): void\n /**\n * EC-728 — delete a document THIS session created, only while it is exactly as created:\n * `documents.delete` with the precondition `{ revision }` = the revision this session's own\n * create landed at (its receipt — never a later read), so a write by anyone since (an edit,\n * a publish) refuses it in the store's own step, and the store's strict-referrer guard\n * refuses it while a strict relation references it. Sent after every write queued before\n * it. Nothing is reported on the session's error surface — a refusal is an expected answer\n * the caller words; the session drops the document only once the store has deleted it.\n */\n deleteCreated(ref: DocumentRef): Promise<DeleteCreatedOutcome>\n unpublishDocument(ref: DocumentRef): void\n /**\n * Adopt a server row pushed by the document subscription (EC-595 point 7): applied\n * under the local patches (local wins until flushed); held while a write is in flight\n * and applied after it, so an echo of our own write never races its result.\n * `undefined` = the document is gone.\n */\n adoptSnapshot(ref: DocumentRef, record: CmsDocumentRecord | undefined): void\n /** The unresolved conflicts on a document. */\n conflicts(ref: DocumentRef): readonly DocumentConflict[]\n /** Resolve a conflict: `theirs` adopts the server value; `mine` re-sends at the current base. */\n resolveConflict(ref: DocumentRef, conflictId: string, choice: 'theirs' | 'mine'): void\n /** Await every queued write (of one document, or all). The FORCED FLUSH's persistence half. */\n flush(ref?: DocumentRef): Promise<void>\n}\n\nexport interface CmsPersisterOptions {\n projectId: string\n getOperations: () => Promise<OperationsClient>\n /** The session's collections (read lazily via a ref) — the create/import canonicaliser's lens. */\n getCollections: () => readonly CollectionDef[]\n /** Component-prop field-defs (EC-277), so a created document's composition props are canonical too. */\n lookupManifest?: PropFieldLookup\n /** A failed / denied write that is not a per-field conflict — rendered by the session, never silent. */\n onError: (error: OperationError) => void\n /**\n * The session's view of a document changed (an optimistic commit, an adopted server\n * row, a resolved conflict) — `undefined` when the document is gone. Synchronous. The\n * document object is registered with its revision ({@link CmsPersister.revisionOfView}).\n */\n onDocument?: (ref: DocumentRef, document: CmsDocument | undefined) => void\n /**\n * A server row was adopted (EC-449 and friends): the session stamps the chokepoint's\n * `hasUnpublishedChanges`, `updatedAt`, `publishedAt` from it — and, since the row\n * carries the CANONICAL saved values, the session adopts those too (EC-586\n * found-but-left: the studio never adopted the saved canonical document).\n */\n onRecord?: (record: CmsDocumentRecord) => void\n /** A document's conflict list changed. */\n onConflicts?: (ref: DocumentRef, conflicts: readonly DocumentConflict[]) => void\n}\n\n/** What the session hydrated for a document: its value and the revision it is at. */\nexport type TrackedRow = Pick<CmsDocumentRecord, 'document' | 'revision'>\n\n/** A committed patch and the revision it was AUTHORED against (EC-647 — never a tracked one). */\ninterface QueuedPatch {\n readonly kind: 'patch'\n readonly patch: DocumentPatch\n /** `undefined`: authored on the provisional view (our own pending create / an untracked document). */\n base: number | undefined\n /** The commits waiting on this patch (a superseded value write hands its waiters on). */\n readonly settle: ((outcome: CommitOutcome) => void)[]\n /**\n * EC-686 — re-sent after the store refused the run it was in as a whole ({@link isolate}):\n * `'resent'` with the run's other innocents, `'alone'` by itself. Never isolated again.\n */\n readonly isolated?: 'resent' | 'alone'\n}\n\n/** A whole-document write, queued in its place among the patches (EC-647). */\ninterface QueuedReplace {\n readonly kind: 'replace'\n readonly document: CmsDocument\n /** The revision the snapshot was authored against (`undefined`: on the provisional view). */\n base: number | undefined\n /** EC-686 — the document the snapshot was made from: what a refusal decomposes it against ({@link decompose}). */\n readonly authoredOn?: CmsDocument\n /** EC-686 — this write only carries a decomposed alias ({@link QueuedAlias}), re-sent this many times. */\n readonly aliasAttempt?: number\n}\n\n/**\n * EC-686 — the slot alias of a refused whole-document write, re-sent by itself after its\n * decomposed positions: the alias is the one document key the value-position grammar has\n * no position for (measured: a `field` path named `alias` writes `values.alias`), so it\n * travels as the server row the session holds, unchanged, with this alias ({@link resolveAlias}).\n */\ninterface QueuedAlias {\n readonly kind: 'alias'\n /** The alias the author chose (`undefined`: removed). */\n readonly alias: string | undefined\n /** The alias the author's view showed: re-sent only while the row still carries it. */\n readonly authored: string | undefined\n /** How many times it has been re-sent ({@link ALIAS_ATTEMPTS}). */\n readonly attempt: number\n}\n\ntype QueuedWrite = QueuedPatch | QueuedReplace | QueuedAlias\n\n/** EC-686 — a decomposed alias is re-sent at most this often (each time a colleague wrote the document in between). */\nconst ALIAS_ATTEMPTS = 3\n\n/** One write THIS persister made and the store acknowledged (EC-647 — the own-write ledger). */\ninterface OwnWrite {\n readonly revision: number\n /** The base revision it was sent at (`undefined`: insert-if-absent, or a write with no base). */\n readonly sentBase: number | undefined\n /**\n * The positions its APPLIED patches touched at the store ({@link footprint}, node\n * ancestry included — EC-693): `undefined` = the whole document (a replace / create —\n * lifted across only as a consecutive own revision); `[]` = none (an unpublish).\n */\n readonly paths: readonly ValuePath[] | undefined\n}\n\n/** How many own writes a document's ledger keeps (an older base just stops lifting — a conflict, never a borrow). */\nconst OWN_WRITES_KEPT = 256\n\n/**\n * EC-667 — what a view this persister SHOWED was authored against, position by position,\n * recorded when it is shown (the shown object is the token; the record never changes).\n */\ninterface ViewProvenance {\n /**\n * The revision every position no entry of {@link writes} covers was authored at: the\n * base's — or, under a pending whole-document write, its snapshot's authoring revision\n * (`undefined`: none).\n */\n readonly floor: number | undefined\n /**\n * This session's own unacknowledged writes shown over it: the positions each touched in\n * THIS view ({@link mergedPositions}, node ancestry included — EC-693) and the base it was\n * authored at.\n */\n readonly writes: readonly { readonly paths: readonly ValuePath[]; readonly base: number | undefined }[]\n}\n\n/**\n * EC-667 → EC-681 — the revision the content a view shows at `path` was authored against:\n * a token describes the WHOLE value a writer of `path` may replace. It is the earliest of\n * the floor and of every shown write whose positions OVERLAP `path` structurally — a write\n * at an ancestor of `path`, at `path`, or at a DESCENDANT of it (the value at `path`\n * contains that write's content). A write at a sibling position does not lower it.\n * `undefined` path — a whole-document writer — the earliest of all. `path` and the writes'\n * positions are in the view's structural form (EC-693: node ancestry included).\n *\n * Minted when the view is shown, never when the edit commits (Codex F18, F23): a\n * descendant write may be refused and its conflict resolved before an edit of `path`\n * started on this view commits, and that edit still carries the descendant's old content.\n * The own descendant write that then APPLIES is lifted across at send time ({@link lift}).\n */\nfunction provenanceAt(provenance: ViewProvenance, path: ValuePath | undefined): number | undefined {\n let at = provenance.floor\n for (const write of provenance.writes) {\n if (path === undefined || write.paths.some((written) => valuePathsOverlap(written, path))) {\n at = earlierBase(at, write.base)\n }\n }\n return at\n}\n\n/**\n * EC-681 — whether a write at `a` may overlap one at `b` as the STORE judges it: THE\n * conflict relation (`valuePathsOverlap`) unless BOTH name a component node — then any two\n * in overlapping field positions. The store compares node paths EXPANDED by their ancestry\n * (`value-path.ts`) against ITS document, which may hold a colleague's move this session\n * has not adopted, so the persister never claims two node paths of one field apart — not\n * even in their expanded form (EC-693 kept this conservative on purpose). Conservative by\n * construction: a \"may\" that is wrong costs a lift (a conflict at worst), never a borrow.\n */\nfunction mayOverlap(a: ValuePath, b: ValuePath): boolean {\n const fieldOf = (path: ValuePath) => {\n const node = path.findIndex((segment) => segment.kind === 'node')\n return node < 0 ? undefined : path.slice(0, node)\n }\n const fieldA = fieldOf(a)\n const fieldB = fieldOf(b)\n return fieldA && fieldB ? valuePathsOverlap(fieldA, fieldB) : valuePathsOverlap(a, b)\n}\n\n/**\n * EC-693 — THE containment fact the persister reads (Codex F28): the positions each patch\n * touches as THE merge reports them — `applyDocumentPatches(...).applied`, the patches\n * applied in order over `document`, each expanded against the document it applied to\n * (node ancestry included). `undefined` for a patch the merge does not apply there (its\n * node is not in that document): it has no position in it. Never a second expansion.\n *\n * The merge puts every input patch in exactly one of `applied` (in input order) and\n * `refused` (the input object itself); a fresh object per input keeps a patch object that\n * occurs twice apart.\n */\nfunction mergedPositions(\n document: CmsDocument,\n patches: readonly DocumentPatch[],\n): { readonly document: CmsDocument; readonly positions: readonly (ValuePath[] | undefined)[] } {\n if (patches.length === 0) return { document, positions: [] }\n const inputs = patches.map((patch): DocumentPatch => ({ ...patch }))\n const merged = applyDocumentPatches({ document, patches: inputs, since: [] })\n const refused = new Set<DocumentPatch>(merged.refused.map((refusal) => refusal.patch))\n let next = 0\n return {\n document: merged.document,\n positions: inputs.map((input) => (refused.has(input) ? undefined : touchedPaths(merged.applied[next++]!))),\n }\n}\n\n/**\n * EC-693 — the positions an applied run touched at the store: {@link mergedPositions} over\n * the row the run was sent from, in order. The store applied exactly these patches, in this\n * order, and would have refused one whose node (or an ancestor) a change since its base had\n * moved — so the ancestry each landed under is the row's. The submitted form where the merge\n * has none.\n */\nfunction footprint(row: CmsDocument | undefined, patches: readonly DocumentPatch[]): ValuePath[] {\n const merged = row ? mergedPositions(row, patches).positions : []\n return patches.flatMap((patch, index) => merged[index] ?? touchedPaths(patch))\n}\n\n/** EC-681 — the patch log rows after a write's base, by revision (what {@link lift} may read). */\ntype PatchLog = ReadonlyMap<number, DocumentPatchRecord>\n\n/** A patch's identity within one call: op + target path (no two value writes of one path share a run). */\nfunction targetKey(op: DocumentPatch['op'], path: ValuePath): string {\n return `${op} ${formatValuePath(path)}`\n}\n\nfunction patchTarget(patch: DocumentPatch): ValuePath {\n return patch.op === 'insert' ? [...patch.at.parent, { kind: 'node', id: patch.node.id }] : patch.path\n}\n\ninterface Entry {\n readonly ref: DocumentRef\n base: TrackedRow | undefined\n /** The session's document while no server row is adopted yet (a create in flight, an untracked doc). */\n provisional: CmsDocument | undefined\n /** Committed, not yet sent — patches and whole-document writes, in commit order. */\n queue: QueuedWrite[]\n /** Sent, awaiting the result. */\n inFlight: QueuedPatch[]\n /** A queued whole-document write that was sent, awaiting the result. */\n inFlightReplace: QueuedReplace | undefined\n /** A whole-document write (create / replace / unpublish / delete) in flight. */\n busy: boolean\n conflicts: DocumentConflict[]\n /** The base each open conflict's \"mine\" was authored against (by conflict id). */\n conflictBases: Map<string, number | undefined>\n /** A subscription row that arrived during a write (`null` = gone); adopted after it. */\n held: CmsDocumentRecord | null | undefined\n /** A drain is queued. */\n scheduled: boolean\n deleted: boolean\n /** Our own create of this document is in flight. */\n creating: boolean\n /** The revision our own create landed at (the base of every write authored on its provisional view). */\n created: number | undefined\n /** The own-write ledger (newest last). */\n own: OwnWrite[]\n}\n\nfunction conflictId(ref: DocumentRef, path: ValuePath): string {\n return `${documentKey(ref)}|${formatValuePath(path)}`\n}\n\n/** EC-693 — where the own writes a view shows, and a commit's patches over it, touch it ({@link mergedPositions}). */\ntype ViewPositions = ReadonlyMap<DocumentPatch, readonly ValuePath[]>\n\nfunction pathsOverlap(a: readonly ValuePath[], b: readonly ValuePath[]): boolean {\n return a.some((p) => b.some((q) => valuePathsOverlap(p, q)))\n}\n\n/**\n * Whether two own writes may touch a common position (either touches a prefix of the\n * other's): as submitted, or — EC-693 — where both touch the view (node ancestry\n * included: a write of a parent node and one of its child's prop). Either is enough; a\n * \"may\" lowers a base (a conflict at worst), never borrows one.\n */\nfunction patchesOverlap(a: DocumentPatch, b: DocumentPatch, positions?: ViewPositions): boolean {\n if (pathsOverlap(touchedPaths(a), touchedPaths(b))) return true\n const atA = positions?.get(a)\n const atB = positions?.get(b)\n return atA !== undefined && atB !== undefined && pathsOverlap(atA, atB)\n}\n\n/**\n * EC-693 — two value writes of ONE position (the open conflict a later edit replaces): the\n * same submitted path, or the same position in the view.\n */\nfunction samePosition(\n a: Extract<DocumentPatch, { op: 'set' | 'unset' }>,\n b: Extract<DocumentPatch, { op: 'set' | 'unset' }>,\n positions: ViewPositions,\n): boolean {\n if (samePath(a.path, b.path)) return true\n const atA = positions.get(a)?.[0]\n const atB = positions.get(b)?.[0]\n return atA !== undefined && atB !== undefined && samePath(atA, atB)\n}\n\n/** A `set`/`unset` on exactly one path — the shape a later edit of the same field supersedes. */\nfunction isValueWrite(patch: DocumentPatch): patch is Extract<DocumentPatch, { op: 'set' | 'unset' }> {\n return patch.op === 'set' || patch.op === 'unset'\n}\n\nfunction samePath(a: ValuePath, b: ValuePath): boolean {\n return a.length === b.length && valuePathsOverlap(a, b)\n}\n\n/** The earlier of two authoring bases (`undefined` — the provisional view — is the earliest of all). */\nfunction earlierBase(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined || b === undefined ? undefined : Math.min(a, b)\n}\n\n/**\n * An import's whole-document write (EC-595 A2 → EC-647 → EC-673): a row the session SHOWS\n * and holds a revision for is REPLACED at the revision of the row it showed (the one the\n * import was judged against); any other row is CREATED (insert-if-absent).\n *\n * EC-673: the decision is the SHOWN row's, never the tracked revision alone. A document\n * deleted earlier in the session is not shown, but its entry can still answer a\n * revision — the editor's Delete and a colleague's delete keep the deleted lifetime's\n * base, and the list's bulk Delete never tells the persister at all. Deciding on that\n * revision sent the import down `replace`: queued on a deleted entry and skipped, or\n * refused as unauthored with the deleted lifetime's values shown again. A replace with no\n * shown row could never be right anyway — it names no revision it was authored against.\n */\nexport function importWrite(\n persister: Pick<CmsPersister, 'revisionOf' | 'revisionOfView' | 'replace' | 'create'>,\n document: CmsDocument,\n shown: CmsDocument | undefined,\n): void {\n if (shown && persister.revisionOf(document) !== undefined) {\n // EC-686: with the row it was judged against — what a refusal decomposes it against.\n persister.replace(document, persister.revisionOfView(shown), shown)\n } else persister.create(document)\n}\n\n/**\n * EC-674 → EC-686 — THE classification of a write that failed without a per-field conflict\n * (one declaration, read by the whole-document and the patch path): `true` = KEPT — put\n * back, still shown, re-sent by the next commit or forced flush — for the one failure the\n * store did not JUDGE, `backend-unavailable`, whatever the message. `false` = DROPPED for\n * the store's verdicts, `validation`, `unauthorized` and `not-found`, and for `unknown`: the\n * same write fails the same way again, so it is reported and the writes behind it drain.\n *\n * Why `unknown` is now a verdict (EC-686, classify by WHO failed — the binding rule): the\n * Convex adapter makes every failure out of a backend call that is not a mapped engine\n * error `backend-unavailable` (a network failure, a gateway's 5xx, an expired session, an\n * OCC exhaustion or a timeout, keeping the backend's message), so an `unknown` is a failure\n * of the engine in THIS process — an undeclared field type's `canonicalise` crash — which\n * the same input repeats. Kept, it waited in front of every later write of the document\n * (EC-674's accepted cost); dropped, it is visible and nothing behind it waits.\n */\nfunction keepsFailedWrite(error: OperationError): boolean {\n return error.code === 'backend-unavailable'\n}\n\n/**\n * EC-686 — a dropped verdict on a run as a whole that may be one patch's alone: `validation`\n * (an input or value issue), `unauthorized` (an authorization hook may judge by the\n * patches), an in-process `unknown` (one patch's crash). Not `not-found` — the document is\n * gone for every patch — and never a kept failure.\n */\nfunction isolates(error: OperationError): boolean {\n return error.code === 'validation' || error.code === 'unauthorized' || error.code === 'unknown'\n}\n\n/**\n * EC-686 — the patches a verdict on a whole run names (`validation` issues located at\n * `['patches', i, …]`, i in the run): `undefined` when any issue is not located there (or\n * the verdict carries none) — then no patch is known innocent.\n */\nfunction locatedCulprits(error: OperationError, size: number): ReadonlySet<number> | undefined {\n if (error.code !== 'validation' || !error.issues?.length) return undefined\n const culprits = new Set<number>()\n for (const issue of error.issues) {\n const index = issue.path?.[0] === 'patches' ? issue.path[1] : undefined\n if (typeof index !== 'number' || !Number.isInteger(index) || index < 0 || index >= size) return undefined\n culprits.add(index)\n }\n return culprits\n}\n\n/** A write against a document this session no longer holds (deleted here or elsewhere). */\nfunction goneError(ref: DocumentRef): OperationError {\n return { code: 'not-found', message: 'The document is gone.', entity: 'cms-document', key: documentKey(ref) }\n}\n\n/** The refusal of a write that names no revision it was authored against (EC-647). */\nfunction unauthoredError(ref: DocumentRef): OperationError {\n return {\n code: 'conflict',\n key: documentKey(ref),\n message:\n 'A change was not saved: it does not say which revision of the document it was made on, so it could overwrite a change made since (EC-647).',\n messageRef: { key: 'cms.conflict.unauthored' },\n }\n}\n\n/**\n * EC-686 — a slot change someone else's slot change came before: the alias has no position\n * to hold an ordinary conflict on, so theirs is kept, and the author is told (the table\n * cell's precedent, `cms.conflict.cellRefused`).\n */\nfunction aliasRefusedError(ref: DocumentRef): OperationError {\n return {\n code: 'conflict',\n key: documentKey(ref),\n message: 'The slot was changed by someone else since you chose it — theirs is kept. Choose it again to change it.',\n messageRef: { key: 'cms.conflict.aliasRefused' },\n }\n}\n\n/** `document` with its slot alias set (or removed) — a fresh object. */\nfunction withAlias(document: CmsDocument, alias: string | undefined): CmsDocument {\n const next = { ...document }\n if (alias === undefined) delete next.alias\n else next.alias = alias\n return next\n}\n\n/**\n * EC-686 item 1 — what a whole-document snapshot changed against the view it was made from,\n * position by position: a `set` (or an `unset`, the value gone) of every field position —\n * `values[f]`, `localized[l][f]` — whose value differs by THE equality. Every value change of\n * a document is one of these; its slot `alias` is the one key that is not.\n *\n * EC-703 (Codex round 6 F33): THE own-property per-position diff (`fieldPositionPatches`,\n * cms-core — the one the publish strip reads too). This copy read `bucket.after[key]`, so a\n * removed field named after an `Object.prototype` member became `set constructor = Object`\n * and every later `documentOf` threw (measured).\n */\nfunction positionPatches(view: CmsDocument, snapshot: CmsDocument): DocumentPatch[] {\n return fieldPositionPatches(view, snapshot)\n}\n\nexport function createCmsPersister(options: CmsPersisterOptions): CmsPersister {\n const queue = createPersistQueue((error) => {\n options.onError({\n code: 'unknown',\n message: error instanceof Error ? error.message : String(error),\n })\n })\n const entries = new Map<string, Entry>()\n /** EC-647 / EC-667: every document value this persister showed or tracked → what it was authored against. */\n const shown = new WeakMap<CmsDocument, ViewProvenance>()\n /** A server row's document: every position at its revision. */\n const registerRow = (row: TrackedRow) => shown.set(row.document, { floor: row.revision, writes: [] })\n /** EC-693: {@link serverPositions}, per server row and patch (a row and a queued patch never change). */\n const atRow = new WeakMap<CmsDocument, WeakMap<DocumentPatch, readonly ValuePath[]>>()\n\n /**\n * EC-693 — where a patch lands in the server row the session holds (`entry.base`, at or\n * after every write the own-write ledger records): its positions as THE merge reports\n * them on that row alone ({@link mergedPositions}), the submitted form where the merge does\n * not apply it there. What {@link lift} and the actor lookup read — never the view's\n * evolving frame: an own write still queued ahead of the patch (a move of its node) has\n * not happened at the store.\n */\n function serverPositions(entry: Entry, patch: DocumentPatch): readonly ValuePath[] {\n const row = entry.base?.document\n if (!row) return touchedPaths(patch)\n let byPatch = atRow.get(row)\n if (!byPatch) atRow.set(row, (byPatch = new WeakMap()))\n let positions = byPatch.get(patch)\n if (!positions) byPatch.set(patch, (positions = mergedPositions(row, [patch]).positions[0] ?? touchedPaths(patch)))\n return positions\n }\n\n function entryOf(ref: DocumentRef): Entry {\n const key = documentKey(ref)\n let entry = entries.get(key)\n if (!entry) {\n entry = {\n ref: { collection: ref.collection, id: ref.id },\n base: undefined,\n provisional: undefined,\n queue: [],\n inFlight: [],\n inFlightReplace: undefined,\n busy: false,\n conflicts: [],\n conflictBases: new Map(),\n held: undefined,\n scheduled: false,\n deleted: false,\n creating: false,\n created: undefined,\n own: [],\n }\n entries.set(key, entry)\n }\n return entry\n }\n\n /** EC-586: THE write canonicaliser over a whole document a writer hands us (create/import). */\n function canonical(doc: CmsDocument): CmsDocument {\n const collection = options.getCollections().find((c) => c.id === doc.collection)\n if (!collection) return doc\n return selfTypeDocument(doc, collection, options.lookupManifest ? { lookupManifest: options.lookupManifest } : {})\n }\n\n /** The queued patches (not whole-document writes). */\n function queuedPatches(entry: Entry): QueuedPatch[] {\n return entry.queue.filter((queued): queued is QueuedPatch => queued.kind === 'patch')\n }\n\n /**\n * The session's view: base ⊕ unresolved mine ⊕ in-flight ⊕ queued (the pure merge, no\n * log; a whole-document write resets it to its snapshot) — and, EC-693, `extra` (a\n * commit's patches) over it. With what each shown position was authored against (EC-647\n * → EC-667: the base's revision, a pending snapshot's, each shown write's base) and where\n * each shown write — and each of `extra` — touches the view ({@link mergedPositions}):\n * computed on every call, never frozen when a write is queued, so a colleague's move\n * adopted underneath moves the pending write's position with its node.\n */\n function compose(entry: Entry, extra: readonly DocumentPatch[] = []) {\n const baseDocument = entry.base?.document ?? entry.provisional\n if (entry.deleted || !baseDocument) return undefined\n let document = baseDocument\n let floor = entry.base?.revision\n let shownWrites: { readonly patch: DocumentPatch; readonly base: number | undefined }[] = entry.conflicts.map(\n (conflict) => ({ patch: conflict.patch, base: entry.conflictBases.get(conflict.id) }),\n )\n const pending: QueuedWrite[] = [\n ...entry.inFlight,\n ...(entry.inFlightReplace ? [entry.inFlightReplace] : []),\n ...entry.queue,\n ]\n // EC-686: a pending decomposed alias shows over everything before it (the newest wins).\n let alias: { readonly value: string | undefined } | undefined\n for (const queued of pending) {\n if (queued.kind === 'replace') {\n // The snapshot was authored over everything before it (the editor's draft): every\n // position now shows content authored at the SNAPSHOT's revision (EC-667).\n shownWrites = []\n document = queued.document\n floor = queued.base\n alias = undefined\n } else if (queued.kind === 'alias') {\n alias = { value: queued.alias }\n } else {\n shownWrites.push({ patch: queued.patch, base: queued.base })\n }\n }\n const merged = mergedPositions(document, [...shownWrites.map((write) => write.patch), ...extra])\n // A write the merge did not apply in this view shows nothing: its submitted form keeps\n // the tokens it may concern conservative.\n const writes = shownWrites.map((write, index) => ({\n patch: write.patch,\n paths: merged.positions[index] ?? touchedPaths(write.patch),\n base: write.base,\n }))\n const positions = new Map<DocumentPatch, readonly ValuePath[]>()\n for (const write of writes) positions.set(write.patch, write.paths)\n extra.forEach((patch, index) => {\n const at = merged.positions[shownWrites.length + index]\n if (at) positions.set(patch, at)\n })\n return { document: alias ? withAlias(merged.document, alias.value) : merged.document, floor, writes, positions: positions as ViewPositions }\n }\n\n /**\n * The session's view ({@link compose}), registered with what it was authored against,\n * position by position; a provisional view has none.\n */\n function display(entry: Entry): CmsDocument | undefined {\n const view = compose(entry)\n if (!view) return undefined\n if (entry.base) {\n shown.set(view.document, { floor: view.floor, writes: view.writes.map(({ paths, base }) => ({ paths, base })) })\n }\n return view.document\n }\n\n function emitDocument(entry: Entry): void {\n if (entry.deleted) return\n const view = display(entry)\n if (view) options.onDocument?.(entry.ref, view)\n }\n\n function emitConflicts(entry: Entry): void {\n options.onConflicts?.(entry.ref, [...entry.conflicts])\n }\n\n /** Adopt a server row as the base (never a lower revision), re-derive the view. */\n function adopt(entry: Entry, record: CmsDocumentRecord): void {\n if (entry.base && record.revision < entry.base.revision) return\n entry.base = record\n registerRow(record)\n options.onRecord?.(record)\n emitDocument(entry)\n }\n\n /** After a write: apply a subscription row that arrived meanwhile, if newer. */\n function adoptHeld(entry: Entry): void {\n const held = entry.held\n entry.held = undefined\n if (held === undefined) return\n if (held === null) {\n markGone(entry)\n return\n }\n if (!entry.base || held.revision > entry.base.revision) adopt(entry, held)\n }\n\n function settleAll(queued: readonly QueuedPatch[], outcome: CommitOutcome): void {\n for (const item of queued) for (const settle of item.settle) settle(outcome)\n }\n\n /** Drop every queued write, settling its waiters (the document is gone, or the writes cannot be based). */\n function dropQueued(entry: Entry, outcome: CommitOutcome, which: (queued: QueuedWrite) => boolean = () => true): void {\n const dropped = entry.queue.filter(which)\n entry.queue = entry.queue.filter((queued) => !which(queued))\n settleAll(\n dropped.filter((queued): queued is QueuedPatch => queued.kind === 'patch'),\n outcome,\n )\n }\n\n function markGone(entry: Entry): void {\n if (entry.deleted) return\n entry.deleted = true\n dropQueued(entry, { status: 'failed', error: goneError(entry.ref) })\n options.onDocument?.(entry.ref, undefined)\n }\n\n /**\n * EC-673 — writes queued on a document this session no longer holds (one put back by a\n * failed send after a delete, a \"keep mine\" on a document that went away): refused and\n * REPORTED, never left in the queue for the drain to skip — nor sent into a later\n * re-create of the id, whose first revision the own-write ledger would lift them across.\n */\n function refuseQueued(entry: Entry): void {\n if (entry.queue.length === 0) return\n const error = goneError(entry.ref)\n dropQueued(entry, { status: 'failed', error })\n options.onError(error)\n }\n\n function schedule(entry: Entry): void {\n if (entry.scheduled) return\n entry.scheduled = true\n queue.push(async () => {\n entry.scheduled = false\n await drain(entry)\n adoptHeld(entry)\n })\n }\n\n /** EC-647: record one of this persister's acknowledged writes (the own-write ledger). */\n function recordOwn(entry: Entry, write: OwnWrite): void {\n entry.own.push(write)\n if (entry.own.length > OWN_WRITES_KEPT) entry.own.splice(0, entry.own.length - OWN_WRITES_KEPT)\n }\n\n /**\n * EC-647 → EC-681 — THE lift: the base a write authored at `base` is SENT at. It crosses\n * a revision only where the store's refusal on it would be a refusal of OUR content —\n * never a change by anyone else of a position the write touches. Three rules, applied\n * until none moves it:\n * 1. the next revision is one of this persister's own writes (a run of own writes);\n * 2. an own write that covered every position `patch` touches (each at or under one of its\n * paths) and was sent at or below the lifted base: its revision — the store refused\n * every foreign change of those positions in between, or it would not have applied.\n * EC-693: both read where they land at the store — the own write's {@link footprint},\n * the patch's {@link serverPositions} — node ancestry included: a submitted path names\n * a node's ancestry as the writer believed it, the store reads it from the document;\n * 3. (EC-681, `log` given) the next revision is someone else's and touched none of\n * the patch's positions ({@link mayOverlap}, the store's own row reading\n * `touchedPathsOfEntry`): the store would not refuse the write on it, so crossing it\n * moves nothing — it only lets rule 1 reach an own write beyond it. That is the case\n * rule 2 cannot prove: an ancestor's write over an own DESCENDANT write (whose\n * acceptance says nothing of the ancestor's other descendants), past an unrelated\n * colleague write in between.\n * A whole-document write (`patch` undefined) takes rule 1 only.\n */\n function lift(entry: Entry, base: number, patch: DocumentPatch | undefined, log?: PatchLog): number {\n const paths = patch ? () => serverPositions(entry, patch) : undefined\n let lifted = base\n for (;;) {\n if (entry.own.some((write) => write.revision === lifted + 1)) {\n lifted += 1\n continue\n }\n const covering = paths\n ? entry.own.find(\n (write) =>\n write.revision > lifted &&\n write.paths !== undefined &&\n write.sentBase !== undefined &&\n write.sentBase <= lifted &&\n paths().every((path) => write.paths!.some((covered) => isValuePathPrefix(covered, path))),\n )\n : undefined\n if (covering) {\n lifted = covering.revision\n continue\n }\n const foreign = paths ? log?.get(lifted + 1) : undefined\n if (foreign && !touchedPathsOfEntry(foreign).some((logged) => paths!().some((path) => mayOverlap(logged, path)))) {\n lifted += 1\n continue\n }\n return lifted\n }\n }\n\n /**\n * EC-681 — the patch log {@link lift} rule 3 reads for a queued patch: only when an own\n * write the store would refuse it on lies beyond its lift (an own write that may overlap\n * its positions, past a revision someone else wrote), read after that lift. `undefined`\n * when not needed or not readable — then no lift, a conflict at worst, never a borrow.\n */\n async function liftLog(entry: Entry, operations: OperationsClient, queued: QueuedPatch): Promise<PatchLog | undefined> {\n const lifted = lift(entry, queued.base!, queued.patch)\n const blocking = entry.own.some(\n (write) =>\n write.revision > lifted &&\n (write.paths === undefined ||\n write.paths.some((own) => serverPositions(entry, queued.patch).some((path) => mayOverlap(own, path)))),\n )\n if (!blocking) return undefined\n const read = await operations.documents.listPatches({\n projectId: options.projectId,\n ref: entry.ref,\n afterRevision: lifted,\n })\n return read.ok ? new Map(read.value.map((row) => [row.revision, row])) : undefined\n }\n\n /**\n * EC-647 — the base a write is QUEUED with: the revision it was authored against, or\n * the earlier base of an own unacknowledged write on the same positions (the view\n * showed mine there, not whatever may sit underneath it) — EC-693: as submitted, or in\n * the view (`positions`).\n */\n function authoredBase(\n entry: Entry,\n patch: DocumentPatch | undefined,\n authored: number | undefined,\n positions?: ViewPositions,\n ): number | undefined {\n let base = authored\n const overlaps = (other: DocumentPatch) => patch === undefined || patchesOverlap(other, patch, positions)\n for (const queued of [...entry.inFlight, ...entry.queue]) {\n // A decomposed alias names no value position (and is sent at the row it then finds).\n if (queued.kind === 'alias') continue\n if (queued.kind === 'replace' || overlaps(queued.patch)) base = earlierBase(base, queued.base)\n }\n if (entry.inFlightReplace) base = earlierBase(base, entry.inFlightReplace.base)\n for (const conflict of entry.conflicts) {\n if (overlaps(conflict.patch)) base = earlierBase(base, entry.conflictBases.get(conflict.id))\n }\n return base\n }\n\n /** Whether a write may be authored on a provisional view (our own create, or an untracked document). */\n function provisionalAllowed(entry: Entry): boolean {\n return entry.creating || entry.created !== undefined || !entry.base\n }\n\n /** Our own create landed (or failed): base every write authored on its provisional view. */\n function baseOnCreated(entry: Entry): void {\n if (entry.created === undefined) return\n for (const queued of entry.queue) if (queued.kind !== 'alias' && queued.base === undefined) queued.base = entry.created\n }\n\n /**\n * EC-647 — writes authored on the provisional view of a document this session holds no\n * revision for (a staged transfer): read it; when it still EQUALS the view they were\n * authored on, that read's revision is theirs — otherwise each is refused as a\n * conflict on its position (theirs = the read). Never \"whatever revision the read\n * returns\". `false` when the read failed (the writes stay queued, the error shows).\n */\n async function baseOnRead(entry: Entry, operations: OperationsClient): Promise<boolean> {\n if (!entry.queue.some((queued) => queued.kind === 'patch' && queued.base === undefined)) return true\n if (entry.created !== undefined) {\n baseOnCreated(entry)\n return true\n }\n if (entry.base) {\n // A tracked document this session did not create: commit already refused these.\n const error = unauthoredError(entry.ref)\n dropQueued(entry, { status: 'failed', error }, (queued) => queued.kind === 'patch' && queued.base === undefined)\n options.onError(error)\n return true\n }\n const read = await operations.documents.get({ projectId: options.projectId, ref: entry.ref })\n if (!read.ok) {\n // The writes stay queued for the next flush; their commits learn why now (EC-686).\n if (!entry.scheduled) settleWaiting(entry, { status: 'failed', error: read.error })\n options.onError(read.error)\n return false\n }\n const record = read.value\n const authoredOn = entry.provisional\n if (authoredOn && semanticValueEqual(record.document, authoredOn)) {\n for (const queued of entry.queue) if (queued.kind === 'patch' && queued.base === undefined) queued.base = record.revision\n } else {\n const refused: DocumentConflict[] = []\n for (const queued of queuedPatches(entry)) {\n if (queued.base !== undefined) continue\n const path = patchTarget(queued.patch)\n const conflict = upsertConflict(\n entry,\n {\n patch: queued.patch,\n reason: 'conflict',\n path,\n current: readValueAt(record.document, path),\n detail: 'the document changed since the view this edit was made on',\n },\n record.revision,\n record.revision,\n )\n refused.push(conflict)\n for (const settle of queued.settle) settle({ status: 'refused', conflicts: [conflict] })\n }\n entry.queue = entry.queue.filter((queued) => !(queued.kind === 'patch' && queued.base === undefined))\n if (refused.length > 0) emitConflicts(entry)\n }\n adopt(entry, record)\n return true\n }\n\n /**\n * Who changed a refused path — the newest patch-log row in (base, current] touching it.\n * Best-effort. The log stores its paths expanded (node ancestry included), so the refused\n * patch is read where it lands in the server row ({@link serverPositions}, EC-693) — a\n * child prop's conflict names its parent there, as the colleague's logged write does.\n */\n async function resolveActors(entry: Entry, sentBase: number, refused: readonly DocumentConflict[]): Promise<void> {\n try {\n const operations = await options.getOperations()\n const log = await operations.documents.listPatches({\n projectId: options.projectId,\n ref: entry.ref,\n afterRevision: sentBase,\n })\n if (!log.ok) return\n let changed = false\n entry.conflicts = entry.conflicts.map((conflict) => {\n if (conflict.actor !== undefined || !refused.some((r) => r.id === conflict.id)) return conflict\n const at = serverPositions(entry, conflict.patch)\n const row = [...log.value]\n .reverse()\n .find(\n (candidate) =>\n candidate.kind === 'replace' || candidate.patches.some((patch) => pathsOverlap(touchedPaths(patch), at)),\n )\n if (!row?.actor) return conflict\n changed = true\n return { ...conflict, actor: row.actor }\n })\n if (changed) emitConflicts(entry)\n } catch {\n // The actor is decoration on a conflict the user can already resolve.\n }\n }\n\n /**\n * EC-674 — a write that failed without a per-field conflict: KEPT when the store did not\n * judge it ({@link keepsFailedWrite}) — back at the head of the queue, still shown,\n * re-sent by the next commit or forced flush at its own authoring base (a retry never\n * borrows a newer revision) — or DROPPED on the store's verdict, and the view re-derived\n * without it. Reported either way. `true` when kept: the drain stops there, so nothing\n * committed after it is sent ahead of it — and, EC-686, every commit still waiting on a\n * write queued behind it settles now ({@link settleWaiting}). The one path for both the\n * whole-document write and the patch run.\n */\n function failedWrite(entry: Entry, writes: readonly QueuedWrite[], error: OperationError): boolean {\n const kept = keepsFailedWrite(error)\n if (kept) {\n entry.queue.unshift(...writes)\n // A drain already scheduled (a commit made meanwhile) re-sends them at once: they\n // settle with its outcome instead.\n if (!entry.scheduled) settleWaiting(entry, { status: 'failed', error })\n } else emitDocument(entry)\n options.onError(error)\n return kept\n }\n\n /**\n * EC-686 — the drain stopped with writes still queued (kept, shown, re-sent by the next\n * commit or forced flush): the commits waiting on them settle with why, never left\n * hanging until a later flush lands them (an awaiting caller — a table cell, bulk\n * set-field — would wait with them). Each settles once; the write stays queued. Not\n * when a drain is already scheduled: it re-sends them at once, and they settle with it.\n */\n function settleWaiting(entry: Entry, outcome: CommitOutcome): void {\n entry.queue = entry.queue.map((queued) => {\n if (queued.kind !== 'patch' || queued.settle.length === 0) return queued\n settleAll([queued], outcome)\n return { ...queued, settle: [] }\n })\n }\n\n /**\n * EC-686 — a verdict on a run of several patches as a whole ({@link isolates}): its\n * innocents are not dropped with its culprit. A `validation` that\n * locates every culprit ({@link locatedCulprits}) drops those, and the rest go back to the\n * head of the queue to be re-sent once as a run (`'resent'`); otherwise each patch is\n * re-sent once alone (`'alone'`), so the refusal finds its culprit. The verdict is\n * reported once; a culprit's commit settles `failed` now, an innocent's after its\n * re-send. The re-sent patches keep their authoring bases (lift rule 1 crosses each\n * own revision a re-send lands at), and are never isolated again.\n */\n function isolate(entry: Entry, run: readonly QueuedPatch[], error: OperationError): void {\n const culprits = locatedCulprits(error, run.length)\n const resend: QueuedPatch[] = culprits\n ? run.filter((_, index) => !culprits.has(index)).map((queued) => ({ ...queued, isolated: 'resent' }))\n : run.map((queued) => ({ ...queued, isolated: 'alone' }))\n if (culprits) settleAll(run.filter((_, index) => culprits.has(index)), { status: 'failed', error })\n entry.queue.unshift(...resend)\n emitDocument(entry)\n options.onError(error)\n }\n\n /**\n * EC-686 item 1 (the owner's ruling, 2026-10-28: per-position) — a whole-document write the\n * store refused, in the writes that re-send it: what its author changed against the view\n * the snapshot was made from ({@link positionPatches}), each authored where that view had\n * it (its token at the position — EC-667 — else the snapshot's revision). Sent next, each\n * lands on the current row, or — a position someone else changed since — becomes that\n * field's ordinary conflict, the authored value still shown. Never the snapshot again: a\n * whole-document keep-mine would re-send it over every colleague change since.\n *\n * The slot alias, the key the grammar has no position for, follows them alone\n * ({@link QueuedAlias}) when the row still carries the alias the author saw; when someone\n * else changed it too, there is no position for a conflict — theirs is kept and the author\n * is told (`aliasRefused`). `undefined` when nothing can be judged per position: no view,\n * or no revision (an insert-if-absent).\n */\n function decompose(\n entry: Entry,\n write: QueuedReplace,\n current: CmsDocument,\n ): { readonly writes: QueuedWrite[]; readonly aliasRefused: boolean } | undefined {\n const base = write.base ?? entry.created\n const view = write.authoredOn\n if (base === undefined || !view) return undefined\n const provenance = shown.get(view)\n const writes: QueuedWrite[] = positionPatches(view, write.document).map((patch) => ({\n kind: 'patch',\n patch,\n base: (provenance ? provenanceAt(provenance, touchedPaths(patch)[0]) : undefined) ?? base,\n settle: [],\n }))\n let aliasRefused = false\n const alias = write.document.alias\n if (alias !== view.alias && alias !== current.alias) {\n if (current.alias === view.alias) writes.push({ kind: 'alias', alias, authored: view.alias, attempt: write.aliasAttempt ?? 0 })\n else aliasRefused = true\n }\n return { writes, aliasRefused }\n }\n\n /**\n * EC-686 — the queue's head is a decomposed alias: it becomes the whole-document write that\n * carries it — the server row the session holds, unchanged, with the alias, at that row's\n * revision (so it changes the alias and nothing else; a write since refuses it, and it is\n * decomposed again, at most {@link ALIAS_ATTEMPTS} times) — or it is done: the row already\n * carries it, or someone else changed the slot since the author's view (theirs kept, told).\n */\n function resolveAlias(entry: Entry, write: QueuedAlias): void {\n entry.queue.shift()\n const row = entry.base\n if (!row || row.document.alias === write.alias) {\n emitDocument(entry)\n return\n }\n if (row.document.alias !== write.authored || write.attempt >= ALIAS_ATTEMPTS) {\n emitDocument(entry)\n options.onError(aliasRefusedError(entry.ref))\n return\n }\n entry.queue.unshift({\n kind: 'replace',\n document: withAlias(row.document, write.alias),\n base: row.revision,\n authoredOn: row.document,\n aliasAttempt: write.attempt + 1,\n })\n }\n\n /** Send one queued whole-document write at the revision its snapshot was authored against. `false` → stop draining. */\n async function sendReplace(entry: Entry, operations: OperationsClient, write: QueuedReplace): Promise<boolean> {\n const precondition =\n write.base !== undefined\n ? { revision: lift(entry, write.base, undefined) }\n : entry.created !== undefined\n ? { revision: lift(entry, entry.created, undefined) }\n : !entry.base\n ? { ifAbsent: true as const }\n : undefined\n entry.queue.shift()\n if (!precondition) {\n // A tracked document this session did not create, written whole from a view with no revision.\n options.onError(unauthoredError(entry.ref))\n emitDocument(entry)\n return true\n }\n entry.inFlightReplace = write\n entry.busy = true\n try {\n const result = await operations.documents.replace({\n projectId: options.projectId,\n document: write.document,\n precondition,\n })\n entry.inFlightReplace = undefined\n if (result.ok) {\n recordOwn(entry, {\n revision: result.value.revision,\n sentBase: 'revision' in precondition ? precondition.revision : undefined,\n paths: undefined,\n })\n adopt(entry, result.value)\n } else if (result.error.code === 'conflict' && 'current' in result.error && result.error.current) {\n // EC-686 item 1: refused as a whole — re-sent per position, in its place in the queue.\n const parts = decompose(entry, write, result.error.current.document)\n if (parts) entry.queue.unshift(...parts.writes)\n adopt(entry, result.error.current)\n if (!parts) options.onError(result.error)\n else if (parts.aliasRefused) options.onError(aliasRefusedError(entry.ref))\n } else if (failedWrite(entry, [write], result.error)) {\n return false\n }\n } finally {\n entry.inFlightReplace = undefined\n entry.busy = false\n adoptHeld(entry)\n }\n return true\n }\n\n /** Send the queue — runs of equal (lifted) base, whole-document writes in their place — until it is empty or a write fails. */\n async function drain(entry: Entry): Promise<void> {\n while (entry.queue.length > 0) {\n if (entry.deleted) {\n refuseQueued(entry)\n return\n }\n const operations = await options.getOperations()\n if (!(await baseOnRead(entry, operations))) return\n const head = entry.queue[0]\n if (!head) return\n if (head.kind === 'replace') {\n if (!(await sendReplace(entry, operations, head))) return\n continue\n }\n if (head.kind === 'alias') {\n resolveAlias(entry, head)\n continue\n }\n const log = await liftLog(entry, operations, head)\n // The queue may have moved while the log was read (a superseding edit, a delete): start over.\n if (entry.queue[0] !== head) continue\n const sendBase = (queued: QueuedPatch) => lift(entry, queued.base!, queued.patch, log)\n const first = sendBase(head)\n let end = 1\n // EC-686: a patch re-sent after its run was refused travels only with the run's other\n // innocents — or alone ({@link isolate}).\n while (head.isolated !== 'alone' && end < entry.queue.length) {\n const next = entry.queue[end]!\n if (next.kind !== 'patch' || next.isolated !== head.isolated || sendBase(next) !== first) break\n end += 1\n }\n const run = entry.queue.splice(0, end) as QueuedPatch[]\n entry.inFlight = run\n // EC-693: the row the run is sent from — where its applied patches land ({@link footprint}).\n const sentFrom = entry.base?.document\n const result = await operations.documents.patch({\n projectId: options.projectId,\n ref: entry.ref,\n baseRevision: first,\n patches: run.map((queued) => queued.patch),\n })\n entry.inFlight = []\n if (result.ok) {\n recordOwn(entry, {\n revision: result.value.revision,\n sentBase: first,\n paths: footprint(sentFrom, run.map((queued) => queued.patch)),\n })\n adopt(entry, result.value)\n adoptHeld(entry)\n settleAll(run, { status: 'applied', record: result.value })\n continue\n }\n const error = result.error\n if (error.code === 'conflict' && error.refused && error.current) {\n const current = error.current\n // Refusals are matched to the run by op + target path (the operation re-parses\n // and canonicalises the patches, so object identity does not survive the call).\n const refusedByKey = new Map(\n error.refused.map((refused) => [targetKey(refused.patch.op, refused.path), refused]),\n )\n const applied: QueuedPatch[] = []\n const conflicts: DocumentConflict[] = []\n for (const queued of run) {\n const refused = refusedByKey.get(targetKey(queued.patch.op, patchTarget(queued.patch)))\n if (!refused) {\n applied.push(queued)\n continue\n }\n // MINE is what the user wrote (the queued patch), not the canonicalised echo.\n const conflict = upsertConflict(entry, { ...refused, patch: queued.patch }, current.revision, queued.base)\n conflicts.push(conflict)\n for (const settle of queued.settle) settle({ status: 'refused', conflicts: [conflict] })\n }\n // A partially applied run IS a write of ours (the row it returns is after it);\n // a wholly refused one wrote nothing — its row is someone else's revision.\n if (applied.length > 0) {\n recordOwn(entry, {\n revision: current.revision,\n sentBase: first,\n paths: footprint(sentFrom, applied.map((queued) => queued.patch)),\n })\n }\n adopt(entry, current)\n adoptHeld(entry)\n emitConflicts(entry)\n settleAll(applied, { status: 'applied', record: current })\n void resolveActors(entry, first, conflicts)\n continue\n }\n if (error.code === 'conflict' && 'current' in error && error.current === null) {\n // The document was deleted since — nothing to write into.\n markGone(entry)\n options.onError(error)\n settleAll(run, { status: 'failed', error })\n return\n }\n // EC-686 — a verdict on a run of several patches, not yet isolated: re-sent once\n // without its culprits. A `not-found` is the document's and names none; a kept\n // failure is not a verdict.\n if (run.length > 1 && head.isolated === undefined && isolates(error)) {\n isolate(entry, run, error)\n adoptHeld(entry)\n continue\n }\n // EC-674 — any other failure: the commits waiting on the run learn of it now. One the\n // store did not judge keeps the patches (shown, unsent; the next commit or forced flush\n // re-sends them); a verdict (validation, unauthorized, not-found, an in-process\n // `unknown`) drops them, and the writes behind it drain — put back, it would be refused\n // in front of every later write.\n settleAll(run, { status: 'failed', error })\n const kept = failedWrite(entry, run.map((queued) => ({ ...queued, settle: [] })), error)\n adoptHeld(entry)\n if (kept) return\n }\n }\n\n function upsertConflict(\n entry: Entry,\n refused: RefusedPatch,\n revision: number,\n base: number | undefined,\n ): DocumentConflict {\n const conflict: DocumentConflict = {\n id: conflictId(entry.ref, refused.path),\n ref: entry.ref,\n patch: refused.patch,\n path: refused.path,\n theirs: refused.current,\n reason: refused.reason,\n revision,\n }\n entry.conflicts = [...entry.conflicts.filter((c) => c.id !== conflict.id), conflict]\n entry.conflictBases.set(conflict.id, base)\n return conflict\n }\n\n function command(entry: Entry, run: (operations: OperationsClient) => Promise<OperationResult<unknown>>): void {\n queue.push(async () => {\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await run(operations)\n if (!result.ok) options.onError(result.error)\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n }\n\n return {\n track(row) {\n const entry = entryOf(row.document)\n registerRow(row)\n if (!entry.base || row.revision > entry.base.revision) entry.base = row\n },\n revisionOf: (ref) => entries.get(documentKey(ref))?.base?.revision,\n documentOf: (ref) => {\n const entry = entries.get(documentKey(ref))\n return entry ? display(entry) : undefined\n },\n revisionOfView: (view, path) => {\n const provenance = shown.get(view)\n if (!provenance) return undefined\n // EC-693: the asked position in the view's structural form, as its shown writes are.\n return provenanceAt(provenance, path && (expandValuePath(view, path) ?? path))\n },\n adoptRecord(record) {\n const entry = entryOf(record.document)\n if (entry.deleted) return\n if (!entry.base || record.revision > entry.base.revision) adopt(entry, record)\n },\n commit(ref, patches, bases, view) {\n const entry = entryOf(ref)\n if (patches.length === 0) return Promise.resolve<CommitOutcome>({ status: 'failed', error: goneError(ref) })\n if (entry.deleted) {\n // EC-673: a write that cannot be sent is reported, not only settled — the editor's\n // committer and the transfer dialog do not read the outcome.\n const error = goneError(ref)\n options.onError(error)\n return Promise.resolve<CommitOutcome>({ status: 'failed', error })\n }\n if (!Array.isArray(bases)) {\n // EC-647: a writer that names no authoring revision at all — never given the tracked one.\n const error = unauthoredError(ref)\n options.onError(error)\n return Promise.resolve<CommitOutcome>({ status: 'failed', error })\n }\n if (!entry.base && !entry.provisional && view) entry.provisional = view\n // EC-693: where the shown own writes and these patches touch the view they were authored on.\n const positions = compose(entry, patches)?.positions ?? new Map<DocumentPatch, readonly ValuePath[]>()\n let conflictsChanged = false\n let unauthored = false\n const waits: Promise<CommitOutcome>[] = []\n for (const [index, patch] of patches.entries()) {\n const authored = bases[index]\n let settle!: (outcome: CommitOutcome) => void\n waits.push(new Promise<CommitOutcome>((resolve) => (settle = resolve)))\n if (authored === undefined && !provisionalAllowed(entry)) {\n // EC-647: authored on a view with no revision, on a document this session\n // tracks and did not create — it cannot be checked, so it is not sent.\n unauthored = true\n settle({ status: 'failed', error: unauthoredError(ref) })\n continue\n }\n // A field with an unresolved conflict: the new value replaces MINE, unsent —\n // the user decides (keep mine sends it), never an implicit overwrite of theirs.\n // EC-693: the conflict at THIS position, as submitted or in the view — never merely\n // the first overlapping one (an open conflict at an ancestor would hide it).\n const open = isValueWrite(patch)\n ? entry.conflicts.find((conflict) => isValueWrite(conflict.patch) && samePosition(conflict.patch, patch, positions))\n : undefined\n if (open) {\n const replaced: DocumentConflict = { ...open, patch }\n entry.conflicts = entry.conflicts.map((c) => (c === open ? replaced : c))\n conflictsChanged = true\n settle({ status: 'refused', conflicts: [replaced] })\n continue\n }\n const base = authoredBase(entry, patch, authored, positions)\n // A later value write of the same field supersedes an unsent one (keeping the\n // EARLIER base — the user never saw a foreign value of a field they were typing\n // in). Only after the last queued whole-document write: one before it is sent\n // before the snapshot that was authored over it.\n if (isValueWrite(patch)) {\n let after = 0\n entry.queue.forEach((queued, at) => {\n if (queued.kind === 'replace') after = at + 1\n })\n const pending = entry.queue.findIndex(\n (queued, at) =>\n at >= after && queued.kind === 'patch' && isValueWrite(queued.patch) && samePath(queued.patch.path, patch.path),\n )\n if (pending >= 0) {\n const superseded = entry.queue[pending] as QueuedPatch\n entry.queue[pending] = {\n kind: 'patch',\n patch,\n base: earlierBase(superseded.base, base),\n settle: [...superseded.settle, settle],\n }\n continue\n }\n }\n entry.queue.push({ kind: 'patch', patch, base, settle: [settle] })\n }\n if (unauthored) options.onError(unauthoredError(ref))\n emitDocument(entry)\n if (conflictsChanged) emitConflicts(entry)\n schedule(entry)\n // The commit's outcome: failed if any of its patches failed, refused if any was.\n return Promise.all(waits).then((outcomes): CommitOutcome => {\n const failed = outcomes.find((o) => o.status === 'failed')\n if (failed) return failed\n const refused = outcomes.flatMap((o) => (o.status === 'refused' ? o.conflicts : []))\n if (refused.length > 0) return { status: 'refused', conflicts: refused }\n return outcomes[outcomes.length - 1]!\n })\n },\n create(document) {\n const doc = canonical(document)\n const entry = entryOf(doc)\n // A fresh document: nothing of an earlier incarnation of this ref carries over —\n // EC-673: its queued writes (refused and reported, never sent into this one) and its\n // open conflicts (a colleague's delete keeps them; their \"mine\" is not laid over this one).\n if (entry.deleted) {\n refuseQueued(entry)\n if (entry.conflicts.length > 0) {\n entry.conflicts = []\n entry.conflictBases.clear()\n emitConflicts(entry)\n }\n }\n entry.deleted = false\n entry.base = undefined\n entry.own = []\n entry.created = undefined\n entry.creating = true\n // Optimistic: the session shows the document at once; the base is the created row.\n entry.provisional = doc\n options.onDocument?.(entry.ref, doc)\n queue.push(async () => {\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.replace({\n projectId: options.projectId,\n document: doc,\n precondition: { ifAbsent: true },\n })\n if (result.ok) {\n entry.created = result.value.revision\n recordOwn(entry, { revision: result.value.revision, sentBase: undefined, paths: undefined })\n baseOnCreated(entry)\n adopt(entry, result.value)\n } else {\n options.onError(result.error)\n // EC-647: the writes authored on the document we meant to create have no\n // revision to be based on — never the revision of a row someone else wrote.\n dropQueued(entry, { status: 'failed', error: result.error }, (queued) => queued.kind !== 'alias' && queued.base === undefined)\n }\n } finally {\n entry.creating = false\n entry.busy = false\n adoptHeld(entry)\n }\n if (entry.queue.length > 0) await drain(entry)\n })\n },\n replace(document, revision, authoredOn) {\n const doc = canonical(document)\n const entry = entryOf(doc)\n if (entry.deleted) {\n // EC-673: a document this session no longer holds has nothing to replace — refused\n // and reported here, never queued for a drain that skips it (or a re-create of the\n // id that would send it). A new document of the id is a `create`.\n options.onError(goneError(entry.ref))\n return\n }\n if (!entry.base && !entry.provisional) entry.provisional = doc\n // Queued in its place: the patches committed before it are sent first (the snapshot\n // holds them), the ones committed after it are sent after it (it does not). EC-647\n // (Codex F10): one with no authoring revision on a document this session tracks and\n // did not create is refused there, in order — never sent at the tracked revision.\n // EC-686: with the document it was made from — what a refusal decomposes it against.\n entry.queue.push({ kind: 'replace', document: doc, base: authoredBase(entry, undefined, revision), ...(authoredOn ? { authoredOn } : {}) })\n emitDocument(entry)\n schedule(entry)\n },\n deleteCreated(ref) {\n const entry = entryOf(ref)\n return new Promise<DeleteCreatedOutcome>((resolve) => {\n // Queued like every write: whatever was committed before it is sent first.\n queue.push(async () => {\n if (entry.deleted) return resolve('gone')\n if (entry.created === undefined) return resolve('not-created')\n // A write of ours committed and not sent yet is an edit since the create.\n if (entry.queue.length > 0) return resolve('changed')\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.delete({\n projectId: options.projectId,\n ref: entry.ref,\n precondition: { revision: entry.created },\n })\n if (result.ok) {\n markGone(entry)\n resolve('deleted')\n } else resolve(deleteCreatedRefusal(result.error))\n } catch {\n resolve('failed')\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n })\n },\n deleteDocument(ref) {\n const entry = entryOf(ref)\n dropQueued(entry, { status: 'failed', error: goneError(ref) })\n entry.conflicts = []\n entry.conflictBases.clear()\n entry.deleted = true\n emitConflicts(entry)\n command(entry, (operations) => operations.documents.delete({ projectId: options.projectId, ref }))\n },\n unpublishDocument(ref) {\n const entry = entryOf(ref)\n queue.push(async () => {\n await drain(entry)\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.unpublish({ projectId: options.projectId, ref })\n if (result.ok) {\n recordOwn(entry, { revision: result.value.revision, sentBase: undefined, paths: [] })\n adopt(entry, result.value)\n } else options.onError(result.error)\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n },\n adoptSnapshot(ref, record) {\n const entry = entryOf(ref)\n if (entry.inFlight.length > 0 || entry.busy || entry.scheduled) {\n // Hold it: the write's own result decides first; the newer of the two wins.\n if (record === undefined) entry.held = null\n else if (!entry.held || record.revision > entry.held.revision) entry.held = record\n return\n }\n if (record === undefined) {\n if (entry.base) markGone(entry)\n return\n }\n if (!entry.base || record.revision > entry.base.revision) adopt(entry, record)\n },\n conflicts: (ref) => entries.get(documentKey(ref))?.conflicts ?? [],\n resolveConflict(ref, id, choice) {\n const entry = entries.get(documentKey(ref))\n if (!entry) return\n const conflict = entry.conflicts.find((c) => c.id === id)\n if (!conflict) return\n entry.conflicts = entry.conflicts.filter((c) => c !== conflict)\n entry.conflictBases.delete(conflict.id)\n if (choice === 'mine') {\n // Keep mine: re-send at the CURRENT base — a visible, explicit second write, and\n // the one deliberate \"at the current base\" write (EC-647): the user chose it\n // after seeing theirs.\n entry.queue.push({ kind: 'patch', patch: conflict.patch, base: entry.base?.revision, settle: [] })\n schedule(entry)\n }\n emitDocument(entry)\n emitConflicts(entry)\n },\n async flush(ref) {\n if (ref) {\n const entry = entries.get(documentKey(ref))\n if (entry && entry.queue.length > 0) schedule(entry)\n }\n await queue.flush()\n },\n }\n}\n"]}
1
+ {"version":3,"file":"cms-persistence.js","sourceRoot":"","sources":["../../../src/lib/operations/cms-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,0BAA0B,CAAA;AAYjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAqIpD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAqB;IACxD,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,MAAM,CAAA;IAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAA;IAC9C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAA;IAC3D,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,CAAA;IACzC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC7C,CAAC;AA8KD,uHAAuH;AACvH,MAAM,cAAc,GAAG,CAAC,CAAA;AAexB,qHAAqH;AACrH,MAAM,eAAe,GAAG,GAAG,CAAA;AAqB3B;;;;;;;;;;;;;GAaG;AACH,SAAS,YAAY,CAAC,UAA0B,EAAE,IAA2B;IAC3E,IAAI,EAAE,GAAG,UAAU,CAAC,KAAK,CAAA;IACzB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;QACtC,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC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EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAA;gBAClG,QAAQ,CAAC,KAAK,CAAC,CAAA;YACjB,CAAC;YACD,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,aAAa,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG;YACb,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC3C,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;oBAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;YACtD,CAAC;YACD,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import {\n applyDocumentPatches,\n documentKey,\n expandValuePath,\n fieldPositionPatches,\n formatValuePath,\n isValuePathPrefix,\n readValueAt,\n selfTypeDocument,\n semanticValueEqual,\n touchedPaths,\n touchedPathsOfEntry,\n valuePathsOverlap,\n} from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n DocumentRef,\n PropFieldLookup,\n RefusedPatch,\n ValuePath,\n} from '@elytracms/core/cms-core'\nimport type { CmsDocumentRecord, DocumentPatchRecord } from '@elytracms/core/persistence'\nimport type { OperationError, OperationResult, OperationsClient } from './operations-package'\nimport { createPersistQueue } from './persist-queue'\n\n/**\n * CMS session → operations persistence (EC-141 → EC-595 part A2 → EC-647): the PATCH QUEUE.\n *\n * The CMS session keeps documents as optimistic, synchronous state; every write is\n * mirrored onto the operations layer through the revisioned aggregate's two verbs\n * (EC-595, ratified 2026-10-24): `documents.patch` for editing, `documents.replace`\n * for whole-document writers (create, import, the slot alias). There is no document\n * diffing anywhere: every writer EMITS the patches it made at its source (the form's\n * field path, the canvas's node patches, the AI proposal's field changes, bulk\n * set-field, transfer) and hands them to {@link CmsPersister.commit}.\n *\n * **Per document, the persister keeps** the server row it last adopted (`base`), the\n * committed-but-unacknowledged writes (each with the revision it was AUTHORED against),\n * the refused paths awaiting a decision, and the writes it made itself (the own-write\n * ledger). It derives the session's view of the document from them:\n *\n * display = base.document ⊕ unresolved conflicts (mine) ⊕ in-flight ⊕ queued\n *\n * by re-applying the patches with THE merge (`applyDocumentPatches`, `since: []`) — the\n * same pure function both stores run (a queued whole-document write resets the view to\n * its snapshot at its place in the order). So local edits win on their paths until they\n * are flushed (EC-595 point 7), and a server row adopted underneath them (a write\n * result, a subscription push, a conflict's `current`) shows everywhere else at once.\n *\n * **A value and the revision it was authored against travel together (EC-647).** Every\n * view this persister shows is registered with the revision it is at\n * ({@link CmsPersister.revisionOfView} — the shown document object IS the token), and a\n * writer hands each patch over WITH the revision of the view it was authored on\n * (`bases`, required). The persister never substitutes a newer revision for it — not at\n * commit (the old `bases ?? tracked revision` default), not at send (the old\n * `queued.base ?? entry.base.revision`), not in a whole-document `replace` (which read\n * the tracked revision at SEND time — Codex F10), and not for an untracked document\n * (which sent at whatever revision a later read returned). A write that cannot name the\n * revision it was authored against is refused, visibly — it never borrows one.\n *\n * - **A view's token is per position (EC-667, Codex F18).** A view that shows a pending\n * write is a COMPOSITE: no single underlying revision names it. Each shown view is\n * registered with its provenance at display time — the base's revision, or under a\n * pending whole-document write its snapshot's authoring revision, and over that each\n * own unacknowledged write shown (queued, in flight, an open conflict's \"mine\") with\n * the base it was authored at. `revisionOfView(view, path)` is the revision the content\n * at `path` was authored against: the earliest of the floor and of the shown writes that\n * OVERLAP `path` — at it, at an ancestor, or at a descendant, whose content the value at\n * `path` contains (EC-681, Codex F23); a sibling's write does not lower it. Positions\n * are compared in their STRUCTURAL form, as the store compares them (EC-693, Codex F28):\n * a node path carries its component ancestry — each shown write's as the merge applied\n * it in that view, the asked path's expanded against the view — so a parent node's token\n * sees a pending write of its child's prop, which a submitted `nodePropPath` names\n * without the parent.\n * `revisionOfView(view)` — a whole-document writer — the EARLIEST of all. The record is\n * immutable, so it outlives the pending write: an edit started on a view that showed a\n * snapshot keeps the snapshot's revision after the snapshot is refused or fails\n * (before EC-667 the composite was named by the base's revision — a colleague's change\n * adopted underneath a pending snapshot lent the edit its revision, and the edit,\n * authored on the old content, overwrote it).\n * - **A position under one of this session's own unacknowledged writes** (queued, in\n * flight, or an open conflict's \"mine\") was authored against THAT write's base: the\n * view showed mine there, not a colleague's change that may sit underneath it. The\n * later write takes the earlier base, so a colleague's hidden change is still refused\n * on it (same-field supersession has always kept the earlier base for this reason).\n * - **The own-write ledger.** A base may be LIFTED, at send time, across revisions this\n * persister wrote — and only those: across a run of consecutive own revisions right\n * after it (nothing foreign happened in between), or to an own write's revision when\n * the patch only touches positions that write covered (both read where they land in the\n * server row, node ancestry included — EC-693) and the write was sent at or\n * below the patch's base (the store refused every foreign change of those positions in\n * between, or the write would not have applied) — or, EC-681, across a revision someone\n * else wrote that the patch log shows touched none of the patch's positions (the store\n * would not refuse the patch on it), read only when an own write beyond it would\n * otherwise refuse the patch. Without it, the session's second edit of a position, made\n * at the revision its first was authored against, would be refused by its own first\n * write — and an edit of a parent, authored over an own child write, by that child's.\n * - **The provisional view** (`undefined` authoring revision): a document whose view\n * has no revision yet — our own create in flight, or a document the session never\n * tracked (a staged transfer). Writes on it are based on the revision our create\n * landed at, or — untracked — on a read of the document that EQUALS the view they were\n * authored on; anything else is refused as a conflict per position.\n *\n * Consecutive runs of equal (lifted) base are sent in commit order, one\n * `documents.patch` call per run; a queued whole-document write is sent in its place in\n * that order.\n *\n * **A refused path is a conflict ON THAT FIELD** ({@link DocumentConflict}): the\n * session shows \"changed by X — take theirs / keep mine\"; until the user decides, the\n * field keeps showing mine (and further edits of it replace mine without being sent);\n * keep-mine re-sends at the current base — the ONE deliberate \"at the current base\"\n * write: the user chose it after seeing theirs; take-theirs drops mine. Never a\n * whole-document dialog, never a silent overwrite.\n */\n\n/** One refused patch awaiting the user's decision (EC-595 binding point 5). */\nexport interface DocumentConflict {\n /** Stable id for the UI (`<key>|<path>`); one conflict per path. */\n readonly id: string\n readonly ref: DocumentRef\n /** The refused patch — \"mine\". */\n readonly patch: DocumentPatch\n /** The submitted target path. */\n readonly path: ValuePath\n /** The value at that path on the server NOW — \"theirs\" (`undefined` = absent). */\n readonly theirs: unknown\n /** `conflict` — changed since the base; `invalid` — never resolved (e.g. its node is gone). */\n readonly reason: RefusedPatch['reason']\n /** The server revision the refusal was made at. */\n readonly revision: number\n /** Who changed the path (the patch log's actor), once resolved; `undefined` while unknown. */\n readonly actor?: string\n}\n\n/** How one {@link CmsPersister.commit} ended once its patches were acknowledged. */\nexport type CommitOutcome =\n | { readonly status: 'applied'; readonly record: CmsDocumentRecord }\n /** Refused per field — the conflicts stay open on the document for the user to resolve. */\n | { readonly status: 'refused'; readonly conflicts: readonly DocumentConflict[] }\n /**\n * A transport / authorization failure, or a write that named no authoring revision (also\n * reported through `onError`). A write the backend did not judge is KEPT (EC-674): it\n * stays shown and queued, and the next commit or forced flush re-sends it — its commit,\n * and every commit queued behind it, settles `failed` with that error when the drain\n * stops on it (EC-686), never left waiting.\n */\n | { readonly status: 'failed'; readonly error: OperationError }\n\n/**\n * EC-728 — what {@link CmsPersister.deleteCreated} did: `deleted`; `gone` (already deleted);\n * `changed` (written since the create — edited or published); `referenced` (a document\n * references it — any relation, weak or strict, draft or published, EC-739); `not-created`\n * (this session holds no create receipt for it); `failed`.\n */\nexport type DeleteCreatedOutcome = 'deleted' | 'gone' | 'changed' | 'referenced' | 'not-created' | 'failed'\n\n/**\n * EC-728 — the refusal of a conditional delete, read off the operation's error (pure). EC-739:\n * `referenced` when the conflict names referrers (the unreferenced guard's refusal, before the\n * store or re-judged after it refused); `changed` only for a REVISION conflict — one carrying\n * the current row; `gone` when that row is absent. A conflict carrying neither (a referrer that\n * refused the store's step and was gone again by the re-judge) is `failed`: it was never an edit.\n */\nexport function deleteCreatedRefusal(error: OperationError): Exclude<DeleteCreatedOutcome, 'deleted' | 'not-created'> {\n if (error.code === 'not-found') return 'gone'\n if (error.code !== 'conflict') return 'failed'\n if ((error.referrers?.length ?? 0) > 0) return 'referenced'\n if (error.current === null) return 'gone'\n return error.current ? 'changed' : 'failed'\n}\n\nexport interface CmsPersister {\n /** Adopt a server row as this session's base for its document (hydration, a create result). */\n track(row: TrackedRow): void\n /**\n * The revision of the server row the session last adopted for a document (`undefined` =\n * untracked). A document deleted since still answers its removed lifetime's last\n * revision (EC-673): a publish conditioned on it is refused, never sent unconditionally\n * into a re-creation this session never showed — so whether to create or replace is\n * never decided on it alone ({@link importWrite} decides on the row the session shows).\n */\n revisionOf(ref: DocumentRef): number | undefined\n /** The session's view of a tracked document (base ⊕ local), or `undefined`. */\n documentOf(ref: DocumentRef): CmsDocument | undefined\n /**\n * EC-647 — the revision a document value this persister SHOWED is at: every view it\n * emits (`onDocument`, {@link documentOf}) and every row it tracks is registered with\n * its revision, so a writer holding the value it displayed holds its revision too —\n * the pair cannot drift apart. `undefined` for a value the persister never showed (a\n * copy, a fixture), or a provisional view (our own create in flight, an untracked\n * document).\n *\n * EC-667 — per position: `path` given, the revision the content the view shows AT\n * `path` was authored against (an editor's first keystroke there); without it, the\n * EARLIEST authoring revision of any position the view shows — the token of a\n * whole-document writer (a replace, an import). A view showing a pending write is never\n * named by the base's revision alone (see the module doc).\n */\n revisionOfView(view: CmsDocument, path?: ValuePath): number | undefined\n /**\n * Commit patches a writer made and flush them. The session's view updates\n * synchronously (via `onDocument`); the patches persist in order through\n * `documents.patch`. `bases` — REQUIRED, one per patch: the revision of the view the\n * writer authored that patch against (an editor field: the revision its draft was at\n * when the user STARTED that edit; the canvas: the revision of the value its delta is\n * measured from; a table row: {@link revisionOfView} of the row it showed; an AI\n * proposal: the revision of the read it was built from). `undefined` entries mean the\n * view was provisional (see the module doc) — on a document this session tracks and\n * did not create, such a patch is refused. `view` — the session's current document,\n * the provisional view of a document this session holds no revision for (a staged\n * transfer).\n */\n commit(\n ref: DocumentRef,\n patches: readonly DocumentPatch[],\n bases: readonly (number | undefined)[],\n view?: CmsDocument,\n ): Promise<CommitOutcome>\n /** Adopt a server row one of the session's OWN direct writes returned (publish, restore). */\n adoptRecord(record: CmsDocumentRecord): void\n /** Create a document (insert-if-absent: `documents.replace` `{ ifAbsent: true }`). */\n create(document: CmsDocument): void\n /**\n * Write a whole document at the revision it was AUTHORED against (EC-647 — the\n * snapshot and its revision travel together; Codex F10): an import, the slot alias. A\n * move since then — by anyone but this session's own writes — is refused as a\n * conflict, never overwritten. `revision` `undefined`: the snapshot was authored on a\n * provisional view (our own pending create; insert-if-absent when untracked). Sent in\n * its place among the session's queued patches.\n *\n * EC-686 (the owner's ruling, per-position): when the store refuses it, it is decomposed\n * into what the author changed against `authoredOn` — the document the snapshot was made\n * from — and each position is re-sent: it lands, or becomes that field's ordinary\n * conflict. Never a whole-document keep-mine. Without `authoredOn` nothing can be judged\n * per position: the refusal adopts the current row and is reported, as before — never a\n * guess (the session's view at that moment may hold changes the snapshot never saw, which\n * a diff against it would re-send as the author's).\n */\n replace(document: CmsDocument, revision: number | undefined, authoredOn?: CmsDocument): void\n deleteDocument(ref: DocumentRef): void\n /**\n * EC-728 — delete a document THIS session created, only while it is exactly as created and\n * nobody else has it: `documents.delete` with the precondition `{ revision, unreferenced }`.\n * `revision` = the revision this session's own create landed at (its receipt — never a later\n * read), so a write by anyone since (an edit, a publish — \"never published\" needs nothing\n * more) refuses it in the store's own step; `unreferenced` (EC-739) refuses it while ANY\n * document references it — weak or strict, draft or published — judged by the operation and\n * re-checked by the store in that same step, so a reference saved since the guard's read\n * refuses it too. One write, every condition. Sent after every write queued before it.\n * Nothing is reported on the session's error surface — a refusal is an expected answer the\n * caller words; the session drops the document only once the store has deleted it.\n */\n deleteCreated(ref: DocumentRef): Promise<DeleteCreatedOutcome>\n unpublishDocument(ref: DocumentRef): void\n /**\n * Adopt a server row pushed by the document subscription (EC-595 point 7): applied\n * under the local patches (local wins until flushed); held while a write is in flight\n * and applied after it, so an echo of our own write never races its result.\n * `undefined` = the document is gone.\n */\n adoptSnapshot(ref: DocumentRef, record: CmsDocumentRecord | undefined): void\n /** The unresolved conflicts on a document. */\n conflicts(ref: DocumentRef): readonly DocumentConflict[]\n /** Resolve a conflict: `theirs` adopts the server value; `mine` re-sends at the current base. */\n resolveConflict(ref: DocumentRef, conflictId: string, choice: 'theirs' | 'mine'): void\n /** Await every queued write (of one document, or all). The FORCED FLUSH's persistence half. */\n flush(ref?: DocumentRef): Promise<void>\n}\n\nexport interface CmsPersisterOptions {\n projectId: string\n getOperations: () => Promise<OperationsClient>\n /** The session's collections (read lazily via a ref) — the create/import canonicaliser's lens. */\n getCollections: () => readonly CollectionDef[]\n /** Component-prop field-defs (EC-277), so a created document's composition props are canonical too. */\n lookupManifest?: PropFieldLookup\n /** A failed / denied write that is not a per-field conflict — rendered by the session, never silent. */\n onError: (error: OperationError) => void\n /**\n * The session's view of a document changed (an optimistic commit, an adopted server\n * row, a resolved conflict) — `undefined` when the document is gone. Synchronous. The\n * document object is registered with its revision ({@link CmsPersister.revisionOfView}).\n */\n onDocument?: (ref: DocumentRef, document: CmsDocument | undefined) => void\n /**\n * A server row was adopted (EC-449 and friends): the session stamps the chokepoint's\n * `hasUnpublishedChanges`, `updatedAt`, `publishedAt` from it — and, since the row\n * carries the CANONICAL saved values, the session adopts those too (EC-586\n * found-but-left: the studio never adopted the saved canonical document).\n */\n onRecord?: (record: CmsDocumentRecord) => void\n /** A document's conflict list changed. */\n onConflicts?: (ref: DocumentRef, conflicts: readonly DocumentConflict[]) => void\n}\n\n/** What the session hydrated for a document: its value and the revision it is at. */\nexport type TrackedRow = Pick<CmsDocumentRecord, 'document' | 'revision'>\n\n/** A committed patch and the revision it was AUTHORED against (EC-647 — never a tracked one). */\ninterface QueuedPatch {\n readonly kind: 'patch'\n readonly patch: DocumentPatch\n /** `undefined`: authored on the provisional view (our own pending create / an untracked document). */\n base: number | undefined\n /** The commits waiting on this patch (a superseded value write hands its waiters on). */\n readonly settle: ((outcome: CommitOutcome) => void)[]\n /**\n * EC-686 — re-sent after the store refused the run it was in as a whole ({@link isolate}):\n * `'resent'` with the run's other innocents, `'alone'` by itself. Never isolated again.\n */\n readonly isolated?: 'resent' | 'alone'\n}\n\n/** A whole-document write, queued in its place among the patches (EC-647). */\ninterface QueuedReplace {\n readonly kind: 'replace'\n readonly document: CmsDocument\n /** The revision the snapshot was authored against (`undefined`: on the provisional view). */\n base: number | undefined\n /** EC-686 — the document the snapshot was made from: what a refusal decomposes it against ({@link decompose}). */\n readonly authoredOn?: CmsDocument\n /** EC-686 — this write only carries a decomposed alias ({@link QueuedAlias}), re-sent this many times. */\n readonly aliasAttempt?: number\n}\n\n/**\n * EC-686 — the slot alias of a refused whole-document write, re-sent by itself after its\n * decomposed positions: the alias is the one document key the value-position grammar has\n * no position for (measured: a `field` path named `alias` writes `values.alias`), so it\n * travels as the server row the session holds, unchanged, with this alias ({@link resolveAlias}).\n */\ninterface QueuedAlias {\n readonly kind: 'alias'\n /** The alias the author chose (`undefined`: removed). */\n readonly alias: string | undefined\n /** The alias the author's view showed: re-sent only while the row still carries it. */\n readonly authored: string | undefined\n /** How many times it has been re-sent ({@link ALIAS_ATTEMPTS}). */\n readonly attempt: number\n}\n\ntype QueuedWrite = QueuedPatch | QueuedReplace | QueuedAlias\n\n/** EC-686 — a decomposed alias is re-sent at most this often (each time a colleague wrote the document in between). */\nconst ALIAS_ATTEMPTS = 3\n\n/** One write THIS persister made and the store acknowledged (EC-647 — the own-write ledger). */\ninterface OwnWrite {\n readonly revision: number\n /** The base revision it was sent at (`undefined`: insert-if-absent, or a write with no base). */\n readonly sentBase: number | undefined\n /**\n * The positions its APPLIED patches touched at the store ({@link footprint}, node\n * ancestry included — EC-693): `undefined` = the whole document (a replace / create —\n * lifted across only as a consecutive own revision); `[]` = none (an unpublish).\n */\n readonly paths: readonly ValuePath[] | undefined\n}\n\n/** How many own writes a document's ledger keeps (an older base just stops lifting — a conflict, never a borrow). */\nconst OWN_WRITES_KEPT = 256\n\n/**\n * EC-667 — what a view this persister SHOWED was authored against, position by position,\n * recorded when it is shown (the shown object is the token; the record never changes).\n */\ninterface ViewProvenance {\n /**\n * The revision every position no entry of {@link writes} covers was authored at: the\n * base's — or, under a pending whole-document write, its snapshot's authoring revision\n * (`undefined`: none).\n */\n readonly floor: number | undefined\n /**\n * This session's own unacknowledged writes shown over it: the positions each touched in\n * THIS view ({@link mergedPositions}, node ancestry included — EC-693) and the base it was\n * authored at.\n */\n readonly writes: readonly { readonly paths: readonly ValuePath[]; readonly base: number | undefined }[]\n}\n\n/**\n * EC-667 → EC-681 — the revision the content a view shows at `path` was authored against:\n * a token describes the WHOLE value a writer of `path` may replace. It is the earliest of\n * the floor and of every shown write whose positions OVERLAP `path` structurally — a write\n * at an ancestor of `path`, at `path`, or at a DESCENDANT of it (the value at `path`\n * contains that write's content). A write at a sibling position does not lower it.\n * `undefined` path — a whole-document writer — the earliest of all. `path` and the writes'\n * positions are in the view's structural form (EC-693: node ancestry included).\n *\n * Minted when the view is shown, never when the edit commits (Codex F18, F23): a\n * descendant write may be refused and its conflict resolved before an edit of `path`\n * started on this view commits, and that edit still carries the descendant's old content.\n * The own descendant write that then APPLIES is lifted across at send time ({@link lift}).\n */\nfunction provenanceAt(provenance: ViewProvenance, path: ValuePath | undefined): number | undefined {\n let at = provenance.floor\n for (const write of provenance.writes) {\n if (path === undefined || write.paths.some((written) => valuePathsOverlap(written, path))) {\n at = earlierBase(at, write.base)\n }\n }\n return at\n}\n\n/**\n * EC-681 — whether a write at `a` may overlap one at `b` as the STORE judges it: THE\n * conflict relation (`valuePathsOverlap`) unless BOTH name a component node — then any two\n * in overlapping field positions. The store compares node paths EXPANDED by their ancestry\n * (`value-path.ts`) against ITS document, which may hold a colleague's move this session\n * has not adopted, so the persister never claims two node paths of one field apart — not\n * even in their expanded form (EC-693 kept this conservative on purpose). Conservative by\n * construction: a \"may\" that is wrong costs a lift (a conflict at worst), never a borrow.\n */\nfunction mayOverlap(a: ValuePath, b: ValuePath): boolean {\n const fieldOf = (path: ValuePath) => {\n const node = path.findIndex((segment) => segment.kind === 'node')\n return node < 0 ? undefined : path.slice(0, node)\n }\n const fieldA = fieldOf(a)\n const fieldB = fieldOf(b)\n return fieldA && fieldB ? valuePathsOverlap(fieldA, fieldB) : valuePathsOverlap(a, b)\n}\n\n/**\n * EC-693 — THE containment fact the persister reads (Codex F28): the positions each patch\n * touches as THE merge reports them — `applyDocumentPatches(...).applied`, the patches\n * applied in order over `document`, each expanded against the document it applied to\n * (node ancestry included). `undefined` for a patch the merge does not apply there (its\n * node is not in that document): it has no position in it. Never a second expansion.\n *\n * The merge puts every input patch in exactly one of `applied` (in input order) and\n * `refused` (the input object itself); a fresh object per input keeps a patch object that\n * occurs twice apart.\n */\nfunction mergedPositions(\n document: CmsDocument,\n patches: readonly DocumentPatch[],\n): { readonly document: CmsDocument; readonly positions: readonly (ValuePath[] | undefined)[] } {\n if (patches.length === 0) return { document, positions: [] }\n const inputs = patches.map((patch): DocumentPatch => ({ ...patch }))\n const merged = applyDocumentPatches({ document, patches: inputs, since: [] })\n const refused = new Set<DocumentPatch>(merged.refused.map((refusal) => refusal.patch))\n let next = 0\n return {\n document: merged.document,\n positions: inputs.map((input) => (refused.has(input) ? undefined : touchedPaths(merged.applied[next++]!))),\n }\n}\n\n/**\n * EC-693 — the positions an applied run touched at the store: {@link mergedPositions} over\n * the row the run was sent from, in order. The store applied exactly these patches, in this\n * order, and would have refused one whose node (or an ancestor) a change since its base had\n * moved — so the ancestry each landed under is the row's. The submitted form where the merge\n * has none.\n */\nfunction footprint(row: CmsDocument | undefined, patches: readonly DocumentPatch[]): ValuePath[] {\n const merged = row ? mergedPositions(row, patches).positions : []\n return patches.flatMap((patch, index) => merged[index] ?? touchedPaths(patch))\n}\n\n/** EC-681 — the patch log rows after a write's base, by revision (what {@link lift} may read). */\ntype PatchLog = ReadonlyMap<number, DocumentPatchRecord>\n\n/** A patch's identity within one call: op + target path (no two value writes of one path share a run). */\nfunction targetKey(op: DocumentPatch['op'], path: ValuePath): string {\n return `${op} ${formatValuePath(path)}`\n}\n\nfunction patchTarget(patch: DocumentPatch): ValuePath {\n return patch.op === 'insert' ? [...patch.at.parent, { kind: 'node', id: patch.node.id }] : patch.path\n}\n\ninterface Entry {\n readonly ref: DocumentRef\n base: TrackedRow | undefined\n /** The session's document while no server row is adopted yet (a create in flight, an untracked doc). */\n provisional: CmsDocument | undefined\n /** Committed, not yet sent — patches and whole-document writes, in commit order. */\n queue: QueuedWrite[]\n /** Sent, awaiting the result. */\n inFlight: QueuedPatch[]\n /** A queued whole-document write that was sent, awaiting the result. */\n inFlightReplace: QueuedReplace | undefined\n /** A whole-document write (create / replace / unpublish / delete) in flight. */\n busy: boolean\n conflicts: DocumentConflict[]\n /** The base each open conflict's \"mine\" was authored against (by conflict id). */\n conflictBases: Map<string, number | undefined>\n /** A subscription row that arrived during a write (`null` = gone); adopted after it. */\n held: CmsDocumentRecord | null | undefined\n /** A drain is queued. */\n scheduled: boolean\n deleted: boolean\n /** Our own create of this document is in flight. */\n creating: boolean\n /** The revision our own create landed at (the base of every write authored on its provisional view). */\n created: number | undefined\n /** The own-write ledger (newest last). */\n own: OwnWrite[]\n}\n\nfunction conflictId(ref: DocumentRef, path: ValuePath): string {\n return `${documentKey(ref)}|${formatValuePath(path)}`\n}\n\n/** EC-693 — where the own writes a view shows, and a commit's patches over it, touch it ({@link mergedPositions}). */\ntype ViewPositions = ReadonlyMap<DocumentPatch, readonly ValuePath[]>\n\nfunction pathsOverlap(a: readonly ValuePath[], b: readonly ValuePath[]): boolean {\n return a.some((p) => b.some((q) => valuePathsOverlap(p, q)))\n}\n\n/**\n * Whether two own writes may touch a common position (either touches a prefix of the\n * other's): as submitted, or — EC-693 — where both touch the view (node ancestry\n * included: a write of a parent node and one of its child's prop). Either is enough; a\n * \"may\" lowers a base (a conflict at worst), never borrows one.\n */\nfunction patchesOverlap(a: DocumentPatch, b: DocumentPatch, positions?: ViewPositions): boolean {\n if (pathsOverlap(touchedPaths(a), touchedPaths(b))) return true\n const atA = positions?.get(a)\n const atB = positions?.get(b)\n return atA !== undefined && atB !== undefined && pathsOverlap(atA, atB)\n}\n\n/**\n * EC-693 — two value writes of ONE position (the open conflict a later edit replaces): the\n * same submitted path, or the same position in the view.\n */\nfunction samePosition(\n a: Extract<DocumentPatch, { op: 'set' | 'unset' }>,\n b: Extract<DocumentPatch, { op: 'set' | 'unset' }>,\n positions: ViewPositions,\n): boolean {\n if (samePath(a.path, b.path)) return true\n const atA = positions.get(a)?.[0]\n const atB = positions.get(b)?.[0]\n return atA !== undefined && atB !== undefined && samePath(atA, atB)\n}\n\n/** A `set`/`unset` on exactly one path — the shape a later edit of the same field supersedes. */\nfunction isValueWrite(patch: DocumentPatch): patch is Extract<DocumentPatch, { op: 'set' | 'unset' }> {\n return patch.op === 'set' || patch.op === 'unset'\n}\n\nfunction samePath(a: ValuePath, b: ValuePath): boolean {\n return a.length === b.length && valuePathsOverlap(a, b)\n}\n\n/** The earlier of two authoring bases (`undefined` — the provisional view — is the earliest of all). */\nfunction earlierBase(a: number | undefined, b: number | undefined): number | undefined {\n return a === undefined || b === undefined ? undefined : Math.min(a, b)\n}\n\n/**\n * An import's whole-document write (EC-595 A2 → EC-647 → EC-673): a row the session SHOWS\n * and holds a revision for is REPLACED at the revision of the row it showed (the one the\n * import was judged against); any other row is CREATED (insert-if-absent).\n *\n * EC-673: the decision is the SHOWN row's, never the tracked revision alone. A document\n * deleted earlier in the session is not shown, but its entry can still answer a\n * revision — the editor's Delete and a colleague's delete keep the deleted lifetime's\n * base, and the list's bulk Delete never tells the persister at all. Deciding on that\n * revision sent the import down `replace`: queued on a deleted entry and skipped, or\n * refused as unauthored with the deleted lifetime's values shown again. A replace with no\n * shown row could never be right anyway — it names no revision it was authored against.\n */\nexport function importWrite(\n persister: Pick<CmsPersister, 'revisionOf' | 'revisionOfView' | 'replace' | 'create'>,\n document: CmsDocument,\n shown: CmsDocument | undefined,\n): void {\n if (shown && persister.revisionOf(document) !== undefined) {\n // EC-686: with the row it was judged against — what a refusal decomposes it against.\n persister.replace(document, persister.revisionOfView(shown), shown)\n } else persister.create(document)\n}\n\n/**\n * EC-674 → EC-686 — THE classification of a write that failed without a per-field conflict\n * (one declaration, read by the whole-document and the patch path): `true` = KEPT — put\n * back, still shown, re-sent by the next commit or forced flush — for the one failure the\n * store did not JUDGE, `backend-unavailable`, whatever the message. `false` = DROPPED for\n * the store's verdicts, `validation`, `unauthorized` and `not-found`, and for `unknown`: the\n * same write fails the same way again, so it is reported and the writes behind it drain.\n *\n * Why `unknown` is now a verdict (EC-686, classify by WHO failed — the binding rule): the\n * Convex adapter makes every failure out of a backend call that is not a mapped engine\n * error `backend-unavailable` (a network failure, a gateway's 5xx, an expired session, an\n * OCC exhaustion or a timeout, keeping the backend's message), so an `unknown` is a failure\n * of the engine in THIS process — an undeclared field type's `canonicalise` crash — which\n * the same input repeats. Kept, it waited in front of every later write of the document\n * (EC-674's accepted cost); dropped, it is visible and nothing behind it waits.\n */\nfunction keepsFailedWrite(error: OperationError): boolean {\n return error.code === 'backend-unavailable'\n}\n\n/**\n * EC-686 — a dropped verdict on a run as a whole that may be one patch's alone: `validation`\n * (an input or value issue), `unauthorized` (an authorization hook may judge by the\n * patches), an in-process `unknown` (one patch's crash). Not `not-found` — the document is\n * gone for every patch — and never a kept failure.\n */\nfunction isolates(error: OperationError): boolean {\n return error.code === 'validation' || error.code === 'unauthorized' || error.code === 'unknown'\n}\n\n/**\n * EC-686 — the patches a verdict on a whole run names (`validation` issues located at\n * `['patches', i, …]`, i in the run): `undefined` when any issue is not located there (or\n * the verdict carries none) — then no patch is known innocent.\n */\nfunction locatedCulprits(error: OperationError, size: number): ReadonlySet<number> | undefined {\n if (error.code !== 'validation' || !error.issues?.length) return undefined\n const culprits = new Set<number>()\n for (const issue of error.issues) {\n const index = issue.path?.[0] === 'patches' ? issue.path[1] : undefined\n if (typeof index !== 'number' || !Number.isInteger(index) || index < 0 || index >= size) return undefined\n culprits.add(index)\n }\n return culprits\n}\n\n/** A write against a document this session no longer holds (deleted here or elsewhere). */\nfunction goneError(ref: DocumentRef): OperationError {\n return { code: 'not-found', message: 'The document is gone.', entity: 'cms-document', key: documentKey(ref) }\n}\n\n/** The refusal of a write that names no revision it was authored against (EC-647). */\nfunction unauthoredError(ref: DocumentRef): OperationError {\n return {\n code: 'conflict',\n key: documentKey(ref),\n message:\n 'A change was not saved: it does not say which revision of the document it was made on, so it could overwrite a change made since (EC-647).',\n messageRef: { key: 'cms.conflict.unauthored' },\n }\n}\n\n/**\n * EC-686 — a slot change someone else's slot change came before: the alias has no position\n * to hold an ordinary conflict on, so theirs is kept, and the author is told (the table\n * cell's precedent, `cms.conflict.cellRefused`).\n */\nfunction aliasRefusedError(ref: DocumentRef): OperationError {\n return {\n code: 'conflict',\n key: documentKey(ref),\n message: 'The slot was changed by someone else since you chose it — theirs is kept. Choose it again to change it.',\n messageRef: { key: 'cms.conflict.aliasRefused' },\n }\n}\n\n/** `document` with its slot alias set (or removed) — a fresh object. */\nfunction withAlias(document: CmsDocument, alias: string | undefined): CmsDocument {\n const next = { ...document }\n if (alias === undefined) delete next.alias\n else next.alias = alias\n return next\n}\n\n/**\n * EC-686 item 1 — what a whole-document snapshot changed against the view it was made from,\n * position by position: a `set` (or an `unset`, the value gone) of every field position —\n * `values[f]`, `localized[l][f]` — whose value differs by THE equality. Every value change of\n * a document is one of these; its slot `alias` is the one key that is not.\n *\n * EC-703 (Codex round 6 F33): THE own-property per-position diff (`fieldPositionPatches`,\n * cms-core — the one the publish strip reads too). This copy read `bucket.after[key]`, so a\n * removed field named after an `Object.prototype` member became `set constructor = Object`\n * and every later `documentOf` threw (measured).\n */\nfunction positionPatches(view: CmsDocument, snapshot: CmsDocument): DocumentPatch[] {\n return fieldPositionPatches(view, snapshot)\n}\n\nexport function createCmsPersister(options: CmsPersisterOptions): CmsPersister {\n const queue = createPersistQueue((error) => {\n options.onError({\n code: 'unknown',\n message: error instanceof Error ? error.message : String(error),\n })\n })\n const entries = new Map<string, Entry>()\n /** EC-647 / EC-667: every document value this persister showed or tracked → what it was authored against. */\n const shown = new WeakMap<CmsDocument, ViewProvenance>()\n /** A server row's document: every position at its revision. */\n const registerRow = (row: TrackedRow) => shown.set(row.document, { floor: row.revision, writes: [] })\n /** EC-693: {@link serverPositions}, per server row and patch (a row and a queued patch never change). */\n const atRow = new WeakMap<CmsDocument, WeakMap<DocumentPatch, readonly ValuePath[]>>()\n\n /**\n * EC-693 — where a patch lands in the server row the session holds (`entry.base`, at or\n * after every write the own-write ledger records): its positions as THE merge reports\n * them on that row alone ({@link mergedPositions}), the submitted form where the merge does\n * not apply it there. What {@link lift} and the actor lookup read — never the view's\n * evolving frame: an own write still queued ahead of the patch (a move of its node) has\n * not happened at the store.\n */\n function serverPositions(entry: Entry, patch: DocumentPatch): readonly ValuePath[] {\n const row = entry.base?.document\n if (!row) return touchedPaths(patch)\n let byPatch = atRow.get(row)\n if (!byPatch) atRow.set(row, (byPatch = new WeakMap()))\n let positions = byPatch.get(patch)\n if (!positions) byPatch.set(patch, (positions = mergedPositions(row, [patch]).positions[0] ?? touchedPaths(patch)))\n return positions\n }\n\n function entryOf(ref: DocumentRef): Entry {\n const key = documentKey(ref)\n let entry = entries.get(key)\n if (!entry) {\n entry = {\n ref: { collection: ref.collection, id: ref.id },\n base: undefined,\n provisional: undefined,\n queue: [],\n inFlight: [],\n inFlightReplace: undefined,\n busy: false,\n conflicts: [],\n conflictBases: new Map(),\n held: undefined,\n scheduled: false,\n deleted: false,\n creating: false,\n created: undefined,\n own: [],\n }\n entries.set(key, entry)\n }\n return entry\n }\n\n /** EC-586: THE write canonicaliser over a whole document a writer hands us (create/import). */\n function canonical(doc: CmsDocument): CmsDocument {\n const collection = options.getCollections().find((c) => c.id === doc.collection)\n if (!collection) return doc\n return selfTypeDocument(doc, collection, options.lookupManifest ? { lookupManifest: options.lookupManifest } : {})\n }\n\n /** The queued patches (not whole-document writes). */\n function queuedPatches(entry: Entry): QueuedPatch[] {\n return entry.queue.filter((queued): queued is QueuedPatch => queued.kind === 'patch')\n }\n\n /**\n * The session's view: base ⊕ unresolved mine ⊕ in-flight ⊕ queued (the pure merge, no\n * log; a whole-document write resets it to its snapshot) — and, EC-693, `extra` (a\n * commit's patches) over it. With what each shown position was authored against (EC-647\n * → EC-667: the base's revision, a pending snapshot's, each shown write's base) and where\n * each shown write — and each of `extra` — touches the view ({@link mergedPositions}):\n * computed on every call, never frozen when a write is queued, so a colleague's move\n * adopted underneath moves the pending write's position with its node.\n */\n function compose(entry: Entry, extra: readonly DocumentPatch[] = []) {\n const baseDocument = entry.base?.document ?? entry.provisional\n if (entry.deleted || !baseDocument) return undefined\n let document = baseDocument\n let floor = entry.base?.revision\n let shownWrites: { readonly patch: DocumentPatch; readonly base: number | undefined }[] = entry.conflicts.map(\n (conflict) => ({ patch: conflict.patch, base: entry.conflictBases.get(conflict.id) }),\n )\n const pending: QueuedWrite[] = [\n ...entry.inFlight,\n ...(entry.inFlightReplace ? [entry.inFlightReplace] : []),\n ...entry.queue,\n ]\n // EC-686: a pending decomposed alias shows over everything before it (the newest wins).\n let alias: { readonly value: string | undefined } | undefined\n for (const queued of pending) {\n if (queued.kind === 'replace') {\n // The snapshot was authored over everything before it (the editor's draft): every\n // position now shows content authored at the SNAPSHOT's revision (EC-667).\n shownWrites = []\n document = queued.document\n floor = queued.base\n alias = undefined\n } else if (queued.kind === 'alias') {\n alias = { value: queued.alias }\n } else {\n shownWrites.push({ patch: queued.patch, base: queued.base })\n }\n }\n const merged = mergedPositions(document, [...shownWrites.map((write) => write.patch), ...extra])\n // A write the merge did not apply in this view shows nothing: its submitted form keeps\n // the tokens it may concern conservative.\n const writes = shownWrites.map((write, index) => ({\n patch: write.patch,\n paths: merged.positions[index] ?? touchedPaths(write.patch),\n base: write.base,\n }))\n const positions = new Map<DocumentPatch, readonly ValuePath[]>()\n for (const write of writes) positions.set(write.patch, write.paths)\n extra.forEach((patch, index) => {\n const at = merged.positions[shownWrites.length + index]\n if (at) positions.set(patch, at)\n })\n return { document: alias ? withAlias(merged.document, alias.value) : merged.document, floor, writes, positions: positions as ViewPositions }\n }\n\n /**\n * The session's view ({@link compose}), registered with what it was authored against,\n * position by position; a provisional view has none.\n */\n function display(entry: Entry): CmsDocument | undefined {\n const view = compose(entry)\n if (!view) return undefined\n if (entry.base) {\n shown.set(view.document, { floor: view.floor, writes: view.writes.map(({ paths, base }) => ({ paths, base })) })\n }\n return view.document\n }\n\n function emitDocument(entry: Entry): void {\n if (entry.deleted) return\n const view = display(entry)\n if (view) options.onDocument?.(entry.ref, view)\n }\n\n function emitConflicts(entry: Entry): void {\n options.onConflicts?.(entry.ref, [...entry.conflicts])\n }\n\n /** Adopt a server row as the base (never a lower revision), re-derive the view. */\n function adopt(entry: Entry, record: CmsDocumentRecord): void {\n if (entry.base && record.revision < entry.base.revision) return\n entry.base = record\n registerRow(record)\n options.onRecord?.(record)\n emitDocument(entry)\n }\n\n /** After a write: apply a subscription row that arrived meanwhile, if newer. */\n function adoptHeld(entry: Entry): void {\n const held = entry.held\n entry.held = undefined\n if (held === undefined) return\n if (held === null) {\n markGone(entry)\n return\n }\n if (!entry.base || held.revision > entry.base.revision) adopt(entry, held)\n }\n\n function settleAll(queued: readonly QueuedPatch[], outcome: CommitOutcome): void {\n for (const item of queued) for (const settle of item.settle) settle(outcome)\n }\n\n /** Drop every queued write, settling its waiters (the document is gone, or the writes cannot be based). */\n function dropQueued(entry: Entry, outcome: CommitOutcome, which: (queued: QueuedWrite) => boolean = () => true): void {\n const dropped = entry.queue.filter(which)\n entry.queue = entry.queue.filter((queued) => !which(queued))\n settleAll(\n dropped.filter((queued): queued is QueuedPatch => queued.kind === 'patch'),\n outcome,\n )\n }\n\n function markGone(entry: Entry): void {\n if (entry.deleted) return\n entry.deleted = true\n dropQueued(entry, { status: 'failed', error: goneError(entry.ref) })\n options.onDocument?.(entry.ref, undefined)\n }\n\n /**\n * EC-673 — writes queued on a document this session no longer holds (one put back by a\n * failed send after a delete, a \"keep mine\" on a document that went away): refused and\n * REPORTED, never left in the queue for the drain to skip — nor sent into a later\n * re-create of the id, whose first revision the own-write ledger would lift them across.\n */\n function refuseQueued(entry: Entry): void {\n if (entry.queue.length === 0) return\n const error = goneError(entry.ref)\n dropQueued(entry, { status: 'failed', error })\n options.onError(error)\n }\n\n function schedule(entry: Entry): void {\n if (entry.scheduled) return\n entry.scheduled = true\n queue.push(async () => {\n entry.scheduled = false\n await drain(entry)\n adoptHeld(entry)\n })\n }\n\n /** EC-647: record one of this persister's acknowledged writes (the own-write ledger). */\n function recordOwn(entry: Entry, write: OwnWrite): void {\n entry.own.push(write)\n if (entry.own.length > OWN_WRITES_KEPT) entry.own.splice(0, entry.own.length - OWN_WRITES_KEPT)\n }\n\n /**\n * EC-647 → EC-681 — THE lift: the base a write authored at `base` is SENT at. It crosses\n * a revision only where the store's refusal on it would be a refusal of OUR content —\n * never a change by anyone else of a position the write touches. Three rules, applied\n * until none moves it:\n * 1. the next revision is one of this persister's own writes (a run of own writes);\n * 2. an own write that covered every position `patch` touches (each at or under one of its\n * paths) and was sent at or below the lifted base: its revision — the store refused\n * every foreign change of those positions in between, or it would not have applied.\n * EC-693: both read where they land at the store — the own write's {@link footprint},\n * the patch's {@link serverPositions} — node ancestry included: a submitted path names\n * a node's ancestry as the writer believed it, the store reads it from the document;\n * 3. (EC-681, `log` given) the next revision is someone else's and touched none of\n * the patch's positions ({@link mayOverlap}, the store's own row reading\n * `touchedPathsOfEntry`): the store would not refuse the write on it, so crossing it\n * moves nothing — it only lets rule 1 reach an own write beyond it. That is the case\n * rule 2 cannot prove: an ancestor's write over an own DESCENDANT write (whose\n * acceptance says nothing of the ancestor's other descendants), past an unrelated\n * colleague write in between.\n * A whole-document write (`patch` undefined) takes rule 1 only.\n */\n function lift(entry: Entry, base: number, patch: DocumentPatch | undefined, log?: PatchLog): number {\n const paths = patch ? () => serverPositions(entry, patch) : undefined\n let lifted = base\n for (;;) {\n if (entry.own.some((write) => write.revision === lifted + 1)) {\n lifted += 1\n continue\n }\n const covering = paths\n ? entry.own.find(\n (write) =>\n write.revision > lifted &&\n write.paths !== undefined &&\n write.sentBase !== undefined &&\n write.sentBase <= lifted &&\n paths().every((path) => write.paths!.some((covered) => isValuePathPrefix(covered, path))),\n )\n : undefined\n if (covering) {\n lifted = covering.revision\n continue\n }\n const foreign = paths ? log?.get(lifted + 1) : undefined\n if (foreign && !touchedPathsOfEntry(foreign).some((logged) => paths!().some((path) => mayOverlap(logged, path)))) {\n lifted += 1\n continue\n }\n return lifted\n }\n }\n\n /**\n * EC-681 — the patch log {@link lift} rule 3 reads for a queued patch: only when an own\n * write the store would refuse it on lies beyond its lift (an own write that may overlap\n * its positions, past a revision someone else wrote), read after that lift. `undefined`\n * when not needed or not readable — then no lift, a conflict at worst, never a borrow.\n */\n async function liftLog(entry: Entry, operations: OperationsClient, queued: QueuedPatch): Promise<PatchLog | undefined> {\n const lifted = lift(entry, queued.base!, queued.patch)\n const blocking = entry.own.some(\n (write) =>\n write.revision > lifted &&\n (write.paths === undefined ||\n write.paths.some((own) => serverPositions(entry, queued.patch).some((path) => mayOverlap(own, path)))),\n )\n if (!blocking) return undefined\n const read = await operations.documents.listPatches({\n projectId: options.projectId,\n ref: entry.ref,\n afterRevision: lifted,\n })\n return read.ok ? new Map(read.value.map((row) => [row.revision, row])) : undefined\n }\n\n /**\n * EC-647 — the base a write is QUEUED with: the revision it was authored against, or\n * the earlier base of an own unacknowledged write on the same positions (the view\n * showed mine there, not whatever may sit underneath it) — EC-693: as submitted, or in\n * the view (`positions`).\n */\n function authoredBase(\n entry: Entry,\n patch: DocumentPatch | undefined,\n authored: number | undefined,\n positions?: ViewPositions,\n ): number | undefined {\n let base = authored\n const overlaps = (other: DocumentPatch) => patch === undefined || patchesOverlap(other, patch, positions)\n for (const queued of [...entry.inFlight, ...entry.queue]) {\n // A decomposed alias names no value position (and is sent at the row it then finds).\n if (queued.kind === 'alias') continue\n if (queued.kind === 'replace' || overlaps(queued.patch)) base = earlierBase(base, queued.base)\n }\n if (entry.inFlightReplace) base = earlierBase(base, entry.inFlightReplace.base)\n for (const conflict of entry.conflicts) {\n if (overlaps(conflict.patch)) base = earlierBase(base, entry.conflictBases.get(conflict.id))\n }\n return base\n }\n\n /** Whether a write may be authored on a provisional view (our own create, or an untracked document). */\n function provisionalAllowed(entry: Entry): boolean {\n return entry.creating || entry.created !== undefined || !entry.base\n }\n\n /** Our own create landed (or failed): base every write authored on its provisional view. */\n function baseOnCreated(entry: Entry): void {\n if (entry.created === undefined) return\n for (const queued of entry.queue) if (queued.kind !== 'alias' && queued.base === undefined) queued.base = entry.created\n }\n\n /**\n * EC-647 — writes authored on the provisional view of a document this session holds no\n * revision for (a staged transfer): read it; when it still EQUALS the view they were\n * authored on, that read's revision is theirs — otherwise each is refused as a\n * conflict on its position (theirs = the read). Never \"whatever revision the read\n * returns\". `false` when the read failed (the writes stay queued, the error shows).\n */\n async function baseOnRead(entry: Entry, operations: OperationsClient): Promise<boolean> {\n if (!entry.queue.some((queued) => queued.kind === 'patch' && queued.base === undefined)) return true\n if (entry.created !== undefined) {\n baseOnCreated(entry)\n return true\n }\n if (entry.base) {\n // A tracked document this session did not create: commit already refused these.\n const error = unauthoredError(entry.ref)\n dropQueued(entry, { status: 'failed', error }, (queued) => queued.kind === 'patch' && queued.base === undefined)\n options.onError(error)\n return true\n }\n const read = await operations.documents.get({ projectId: options.projectId, ref: entry.ref })\n if (!read.ok) {\n // The writes stay queued for the next flush; their commits learn why now (EC-686).\n if (!entry.scheduled) settleWaiting(entry, { status: 'failed', error: read.error })\n options.onError(read.error)\n return false\n }\n const record = read.value\n const authoredOn = entry.provisional\n if (authoredOn && semanticValueEqual(record.document, authoredOn)) {\n for (const queued of entry.queue) if (queued.kind === 'patch' && queued.base === undefined) queued.base = record.revision\n } else {\n const refused: DocumentConflict[] = []\n for (const queued of queuedPatches(entry)) {\n if (queued.base !== undefined) continue\n const path = patchTarget(queued.patch)\n const conflict = upsertConflict(\n entry,\n {\n patch: queued.patch,\n reason: 'conflict',\n path,\n current: readValueAt(record.document, path),\n detail: 'the document changed since the view this edit was made on',\n },\n record.revision,\n record.revision,\n )\n refused.push(conflict)\n for (const settle of queued.settle) settle({ status: 'refused', conflicts: [conflict] })\n }\n entry.queue = entry.queue.filter((queued) => !(queued.kind === 'patch' && queued.base === undefined))\n if (refused.length > 0) emitConflicts(entry)\n }\n adopt(entry, record)\n return true\n }\n\n /**\n * Who changed a refused path — the newest patch-log row in (base, current] touching it.\n * Best-effort. The log stores its paths expanded (node ancestry included), so the refused\n * patch is read where it lands in the server row ({@link serverPositions}, EC-693) — a\n * child prop's conflict names its parent there, as the colleague's logged write does.\n */\n async function resolveActors(entry: Entry, sentBase: number, refused: readonly DocumentConflict[]): Promise<void> {\n try {\n const operations = await options.getOperations()\n const log = await operations.documents.listPatches({\n projectId: options.projectId,\n ref: entry.ref,\n afterRevision: sentBase,\n })\n if (!log.ok) return\n let changed = false\n entry.conflicts = entry.conflicts.map((conflict) => {\n if (conflict.actor !== undefined || !refused.some((r) => r.id === conflict.id)) return conflict\n const at = serverPositions(entry, conflict.patch)\n const row = [...log.value]\n .reverse()\n .find(\n (candidate) =>\n candidate.kind === 'replace' || candidate.patches.some((patch) => pathsOverlap(touchedPaths(patch), at)),\n )\n if (!row?.actor) return conflict\n changed = true\n return { ...conflict, actor: row.actor }\n })\n if (changed) emitConflicts(entry)\n } catch {\n // The actor is decoration on a conflict the user can already resolve.\n }\n }\n\n /**\n * EC-674 — a write that failed without a per-field conflict: KEPT when the store did not\n * judge it ({@link keepsFailedWrite}) — back at the head of the queue, still shown,\n * re-sent by the next commit or forced flush at its own authoring base (a retry never\n * borrows a newer revision) — or DROPPED on the store's verdict, and the view re-derived\n * without it. Reported either way. `true` when kept: the drain stops there, so nothing\n * committed after it is sent ahead of it — and, EC-686, every commit still waiting on a\n * write queued behind it settles now ({@link settleWaiting}). The one path for both the\n * whole-document write and the patch run.\n */\n function failedWrite(entry: Entry, writes: readonly QueuedWrite[], error: OperationError): boolean {\n const kept = keepsFailedWrite(error)\n if (kept) {\n entry.queue.unshift(...writes)\n // A drain already scheduled (a commit made meanwhile) re-sends them at once: they\n // settle with its outcome instead.\n if (!entry.scheduled) settleWaiting(entry, { status: 'failed', error })\n } else emitDocument(entry)\n options.onError(error)\n return kept\n }\n\n /**\n * EC-686 — the drain stopped with writes still queued (kept, shown, re-sent by the next\n * commit or forced flush): the commits waiting on them settle with why, never left\n * hanging until a later flush lands them (an awaiting caller — a table cell, bulk\n * set-field — would wait with them). Each settles once; the write stays queued. Not\n * when a drain is already scheduled: it re-sends them at once, and they settle with it.\n */\n function settleWaiting(entry: Entry, outcome: CommitOutcome): void {\n entry.queue = entry.queue.map((queued) => {\n if (queued.kind !== 'patch' || queued.settle.length === 0) return queued\n settleAll([queued], outcome)\n return { ...queued, settle: [] }\n })\n }\n\n /**\n * EC-686 — a verdict on a run of several patches as a whole ({@link isolates}): its\n * innocents are not dropped with its culprit. A `validation` that\n * locates every culprit ({@link locatedCulprits}) drops those, and the rest go back to the\n * head of the queue to be re-sent once as a run (`'resent'`); otherwise each patch is\n * re-sent once alone (`'alone'`), so the refusal finds its culprit. The verdict is\n * reported once; a culprit's commit settles `failed` now, an innocent's after its\n * re-send. The re-sent patches keep their authoring bases (lift rule 1 crosses each\n * own revision a re-send lands at), and are never isolated again.\n */\n function isolate(entry: Entry, run: readonly QueuedPatch[], error: OperationError): void {\n const culprits = locatedCulprits(error, run.length)\n const resend: QueuedPatch[] = culprits\n ? run.filter((_, index) => !culprits.has(index)).map((queued) => ({ ...queued, isolated: 'resent' }))\n : run.map((queued) => ({ ...queued, isolated: 'alone' }))\n if (culprits) settleAll(run.filter((_, index) => culprits.has(index)), { status: 'failed', error })\n entry.queue.unshift(...resend)\n emitDocument(entry)\n options.onError(error)\n }\n\n /**\n * EC-686 item 1 (the owner's ruling, 2026-10-28: per-position) — a whole-document write the\n * store refused, in the writes that re-send it: what its author changed against the view\n * the snapshot was made from ({@link positionPatches}), each authored where that view had\n * it (its token at the position — EC-667 — else the snapshot's revision). Sent next, each\n * lands on the current row, or — a position someone else changed since — becomes that\n * field's ordinary conflict, the authored value still shown. Never the snapshot again: a\n * whole-document keep-mine would re-send it over every colleague change since.\n *\n * The slot alias, the key the grammar has no position for, follows them alone\n * ({@link QueuedAlias}) when the row still carries the alias the author saw; when someone\n * else changed it too, there is no position for a conflict — theirs is kept and the author\n * is told (`aliasRefused`). `undefined` when nothing can be judged per position: no view,\n * or no revision (an insert-if-absent).\n */\n function decompose(\n entry: Entry,\n write: QueuedReplace,\n current: CmsDocument,\n ): { readonly writes: QueuedWrite[]; readonly aliasRefused: boolean } | undefined {\n const base = write.base ?? entry.created\n const view = write.authoredOn\n if (base === undefined || !view) return undefined\n const provenance = shown.get(view)\n const writes: QueuedWrite[] = positionPatches(view, write.document).map((patch) => ({\n kind: 'patch',\n patch,\n base: (provenance ? provenanceAt(provenance, touchedPaths(patch)[0]) : undefined) ?? base,\n settle: [],\n }))\n let aliasRefused = false\n const alias = write.document.alias\n if (alias !== view.alias && alias !== current.alias) {\n if (current.alias === view.alias) writes.push({ kind: 'alias', alias, authored: view.alias, attempt: write.aliasAttempt ?? 0 })\n else aliasRefused = true\n }\n return { writes, aliasRefused }\n }\n\n /**\n * EC-686 — the queue's head is a decomposed alias: it becomes the whole-document write that\n * carries it — the server row the session holds, unchanged, with the alias, at that row's\n * revision (so it changes the alias and nothing else; a write since refuses it, and it is\n * decomposed again, at most {@link ALIAS_ATTEMPTS} times) — or it is done: the row already\n * carries it, or someone else changed the slot since the author's view (theirs kept, told).\n */\n function resolveAlias(entry: Entry, write: QueuedAlias): void {\n entry.queue.shift()\n const row = entry.base\n if (!row || row.document.alias === write.alias) {\n emitDocument(entry)\n return\n }\n if (row.document.alias !== write.authored || write.attempt >= ALIAS_ATTEMPTS) {\n emitDocument(entry)\n options.onError(aliasRefusedError(entry.ref))\n return\n }\n entry.queue.unshift({\n kind: 'replace',\n document: withAlias(row.document, write.alias),\n base: row.revision,\n authoredOn: row.document,\n aliasAttempt: write.attempt + 1,\n })\n }\n\n /** Send one queued whole-document write at the revision its snapshot was authored against. `false` → stop draining. */\n async function sendReplace(entry: Entry, operations: OperationsClient, write: QueuedReplace): Promise<boolean> {\n const precondition =\n write.base !== undefined\n ? { revision: lift(entry, write.base, undefined) }\n : entry.created !== undefined\n ? { revision: lift(entry, entry.created, undefined) }\n : !entry.base\n ? { ifAbsent: true as const }\n : undefined\n entry.queue.shift()\n if (!precondition) {\n // A tracked document this session did not create, written whole from a view with no revision.\n options.onError(unauthoredError(entry.ref))\n emitDocument(entry)\n return true\n }\n entry.inFlightReplace = write\n entry.busy = true\n try {\n const result = await operations.documents.replace({\n projectId: options.projectId,\n document: write.document,\n precondition,\n })\n entry.inFlightReplace = undefined\n if (result.ok) {\n recordOwn(entry, {\n revision: result.value.revision,\n sentBase: 'revision' in precondition ? precondition.revision : undefined,\n paths: undefined,\n })\n adopt(entry, result.value)\n } else if (result.error.code === 'conflict' && 'current' in result.error && result.error.current) {\n // EC-686 item 1: refused as a whole — re-sent per position, in its place in the queue.\n const parts = decompose(entry, write, result.error.current.document)\n if (parts) entry.queue.unshift(...parts.writes)\n adopt(entry, result.error.current)\n if (!parts) options.onError(result.error)\n else if (parts.aliasRefused) options.onError(aliasRefusedError(entry.ref))\n } else if (failedWrite(entry, [write], result.error)) {\n return false\n }\n } finally {\n entry.inFlightReplace = undefined\n entry.busy = false\n adoptHeld(entry)\n }\n return true\n }\n\n /** Send the queue — runs of equal (lifted) base, whole-document writes in their place — until it is empty or a write fails. */\n async function drain(entry: Entry): Promise<void> {\n while (entry.queue.length > 0) {\n if (entry.deleted) {\n refuseQueued(entry)\n return\n }\n const operations = await options.getOperations()\n if (!(await baseOnRead(entry, operations))) return\n const head = entry.queue[0]\n if (!head) return\n if (head.kind === 'replace') {\n if (!(await sendReplace(entry, operations, head))) return\n continue\n }\n if (head.kind === 'alias') {\n resolveAlias(entry, head)\n continue\n }\n const log = await liftLog(entry, operations, head)\n // The queue may have moved while the log was read (a superseding edit, a delete): start over.\n if (entry.queue[0] !== head) continue\n const sendBase = (queued: QueuedPatch) => lift(entry, queued.base!, queued.patch, log)\n const first = sendBase(head)\n let end = 1\n // EC-686: a patch re-sent after its run was refused travels only with the run's other\n // innocents — or alone ({@link isolate}).\n while (head.isolated !== 'alone' && end < entry.queue.length) {\n const next = entry.queue[end]!\n if (next.kind !== 'patch' || next.isolated !== head.isolated || sendBase(next) !== first) break\n end += 1\n }\n const run = entry.queue.splice(0, end) as QueuedPatch[]\n entry.inFlight = run\n // EC-693: the row the run is sent from — where its applied patches land ({@link footprint}).\n const sentFrom = entry.base?.document\n const result = await operations.documents.patch({\n projectId: options.projectId,\n ref: entry.ref,\n baseRevision: first,\n patches: run.map((queued) => queued.patch),\n })\n entry.inFlight = []\n if (result.ok) {\n recordOwn(entry, {\n revision: result.value.revision,\n sentBase: first,\n paths: footprint(sentFrom, run.map((queued) => queued.patch)),\n })\n adopt(entry, result.value)\n adoptHeld(entry)\n settleAll(run, { status: 'applied', record: result.value })\n continue\n }\n const error = result.error\n if (error.code === 'conflict' && error.refused && error.current) {\n const current = error.current\n // Refusals are matched to the run by op + target path (the operation re-parses\n // and canonicalises the patches, so object identity does not survive the call).\n const refusedByKey = new Map(\n error.refused.map((refused) => [targetKey(refused.patch.op, refused.path), refused]),\n )\n const applied: QueuedPatch[] = []\n const conflicts: DocumentConflict[] = []\n for (const queued of run) {\n const refused = refusedByKey.get(targetKey(queued.patch.op, patchTarget(queued.patch)))\n if (!refused) {\n applied.push(queued)\n continue\n }\n // MINE is what the user wrote (the queued patch), not the canonicalised echo.\n const conflict = upsertConflict(entry, { ...refused, patch: queued.patch }, current.revision, queued.base)\n conflicts.push(conflict)\n for (const settle of queued.settle) settle({ status: 'refused', conflicts: [conflict] })\n }\n // A partially applied run IS a write of ours (the row it returns is after it);\n // a wholly refused one wrote nothing — its row is someone else's revision.\n if (applied.length > 0) {\n recordOwn(entry, {\n revision: current.revision,\n sentBase: first,\n paths: footprint(sentFrom, applied.map((queued) => queued.patch)),\n })\n }\n adopt(entry, current)\n adoptHeld(entry)\n emitConflicts(entry)\n settleAll(applied, { status: 'applied', record: current })\n void resolveActors(entry, first, conflicts)\n continue\n }\n if (error.code === 'conflict' && 'current' in error && error.current === null) {\n // The document was deleted since — nothing to write into.\n markGone(entry)\n options.onError(error)\n settleAll(run, { status: 'failed', error })\n return\n }\n // EC-686 — a verdict on a run of several patches, not yet isolated: re-sent once\n // without its culprits. A `not-found` is the document's and names none; a kept\n // failure is not a verdict.\n if (run.length > 1 && head.isolated === undefined && isolates(error)) {\n isolate(entry, run, error)\n adoptHeld(entry)\n continue\n }\n // EC-674 — any other failure: the commits waiting on the run learn of it now. One the\n // store did not judge keeps the patches (shown, unsent; the next commit or forced flush\n // re-sends them); a verdict (validation, unauthorized, not-found, an in-process\n // `unknown`) drops them, and the writes behind it drain — put back, it would be refused\n // in front of every later write.\n settleAll(run, { status: 'failed', error })\n const kept = failedWrite(entry, run.map((queued) => ({ ...queued, settle: [] })), error)\n adoptHeld(entry)\n if (kept) return\n }\n }\n\n function upsertConflict(\n entry: Entry,\n refused: RefusedPatch,\n revision: number,\n base: number | undefined,\n ): DocumentConflict {\n const conflict: DocumentConflict = {\n id: conflictId(entry.ref, refused.path),\n ref: entry.ref,\n patch: refused.patch,\n path: refused.path,\n theirs: refused.current,\n reason: refused.reason,\n revision,\n }\n entry.conflicts = [...entry.conflicts.filter((c) => c.id !== conflict.id), conflict]\n entry.conflictBases.set(conflict.id, base)\n return conflict\n }\n\n function command(entry: Entry, run: (operations: OperationsClient) => Promise<OperationResult<unknown>>): void {\n queue.push(async () => {\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await run(operations)\n if (!result.ok) options.onError(result.error)\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n }\n\n return {\n track(row) {\n const entry = entryOf(row.document)\n registerRow(row)\n if (!entry.base || row.revision > entry.base.revision) entry.base = row\n },\n revisionOf: (ref) => entries.get(documentKey(ref))?.base?.revision,\n documentOf: (ref) => {\n const entry = entries.get(documentKey(ref))\n return entry ? display(entry) : undefined\n },\n revisionOfView: (view, path) => {\n const provenance = shown.get(view)\n if (!provenance) return undefined\n // EC-693: the asked position in the view's structural form, as its shown writes are.\n return provenanceAt(provenance, path && (expandValuePath(view, path) ?? path))\n },\n adoptRecord(record) {\n const entry = entryOf(record.document)\n if (entry.deleted) return\n if (!entry.base || record.revision > entry.base.revision) adopt(entry, record)\n },\n commit(ref, patches, bases, view) {\n const entry = entryOf(ref)\n if (patches.length === 0) return Promise.resolve<CommitOutcome>({ status: 'failed', error: goneError(ref) })\n if (entry.deleted) {\n // EC-673: a write that cannot be sent is reported, not only settled — the editor's\n // committer and the transfer dialog do not read the outcome.\n const error = goneError(ref)\n options.onError(error)\n return Promise.resolve<CommitOutcome>({ status: 'failed', error })\n }\n if (!Array.isArray(bases)) {\n // EC-647: a writer that names no authoring revision at all — never given the tracked one.\n const error = unauthoredError(ref)\n options.onError(error)\n return Promise.resolve<CommitOutcome>({ status: 'failed', error })\n }\n if (!entry.base && !entry.provisional && view) entry.provisional = view\n // EC-693: where the shown own writes and these patches touch the view they were authored on.\n const positions = compose(entry, patches)?.positions ?? new Map<DocumentPatch, readonly ValuePath[]>()\n let conflictsChanged = false\n let unauthored = false\n const waits: Promise<CommitOutcome>[] = []\n for (const [index, patch] of patches.entries()) {\n const authored = bases[index]\n let settle!: (outcome: CommitOutcome) => void\n waits.push(new Promise<CommitOutcome>((resolve) => (settle = resolve)))\n if (authored === undefined && !provisionalAllowed(entry)) {\n // EC-647: authored on a view with no revision, on a document this session\n // tracks and did not create — it cannot be checked, so it is not sent.\n unauthored = true\n settle({ status: 'failed', error: unauthoredError(ref) })\n continue\n }\n // A field with an unresolved conflict: the new value replaces MINE, unsent —\n // the user decides (keep mine sends it), never an implicit overwrite of theirs.\n // EC-693: the conflict at THIS position, as submitted or in the view — never merely\n // the first overlapping one (an open conflict at an ancestor would hide it).\n const open = isValueWrite(patch)\n ? entry.conflicts.find((conflict) => isValueWrite(conflict.patch) && samePosition(conflict.patch, patch, positions))\n : undefined\n if (open) {\n const replaced: DocumentConflict = { ...open, patch }\n entry.conflicts = entry.conflicts.map((c) => (c === open ? replaced : c))\n conflictsChanged = true\n settle({ status: 'refused', conflicts: [replaced] })\n continue\n }\n const base = authoredBase(entry, patch, authored, positions)\n // A later value write of the same field supersedes an unsent one (keeping the\n // EARLIER base — the user never saw a foreign value of a field they were typing\n // in). Only after the last queued whole-document write: one before it is sent\n // before the snapshot that was authored over it.\n if (isValueWrite(patch)) {\n let after = 0\n entry.queue.forEach((queued, at) => {\n if (queued.kind === 'replace') after = at + 1\n })\n const pending = entry.queue.findIndex(\n (queued, at) =>\n at >= after && queued.kind === 'patch' && isValueWrite(queued.patch) && samePath(queued.patch.path, patch.path),\n )\n if (pending >= 0) {\n const superseded = entry.queue[pending] as QueuedPatch\n entry.queue[pending] = {\n kind: 'patch',\n patch,\n base: earlierBase(superseded.base, base),\n settle: [...superseded.settle, settle],\n }\n continue\n }\n }\n entry.queue.push({ kind: 'patch', patch, base, settle: [settle] })\n }\n if (unauthored) options.onError(unauthoredError(ref))\n emitDocument(entry)\n if (conflictsChanged) emitConflicts(entry)\n schedule(entry)\n // The commit's outcome: failed if any of its patches failed, refused if any was.\n return Promise.all(waits).then((outcomes): CommitOutcome => {\n const failed = outcomes.find((o) => o.status === 'failed')\n if (failed) return failed\n const refused = outcomes.flatMap((o) => (o.status === 'refused' ? o.conflicts : []))\n if (refused.length > 0) return { status: 'refused', conflicts: refused }\n return outcomes[outcomes.length - 1]!\n })\n },\n create(document) {\n const doc = canonical(document)\n const entry = entryOf(doc)\n // A fresh document: nothing of an earlier incarnation of this ref carries over —\n // EC-673: its queued writes (refused and reported, never sent into this one) and its\n // open conflicts (a colleague's delete keeps them; their \"mine\" is not laid over this one).\n if (entry.deleted) {\n refuseQueued(entry)\n if (entry.conflicts.length > 0) {\n entry.conflicts = []\n entry.conflictBases.clear()\n emitConflicts(entry)\n }\n }\n entry.deleted = false\n entry.base = undefined\n entry.own = []\n entry.created = undefined\n entry.creating = true\n // Optimistic: the session shows the document at once; the base is the created row.\n entry.provisional = doc\n options.onDocument?.(entry.ref, doc)\n queue.push(async () => {\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.replace({\n projectId: options.projectId,\n document: doc,\n precondition: { ifAbsent: true },\n })\n if (result.ok) {\n entry.created = result.value.revision\n recordOwn(entry, { revision: result.value.revision, sentBase: undefined, paths: undefined })\n baseOnCreated(entry)\n adopt(entry, result.value)\n } else {\n options.onError(result.error)\n // EC-647: the writes authored on the document we meant to create have no\n // revision to be based on — never the revision of a row someone else wrote.\n dropQueued(entry, { status: 'failed', error: result.error }, (queued) => queued.kind !== 'alias' && queued.base === undefined)\n }\n } finally {\n entry.creating = false\n entry.busy = false\n adoptHeld(entry)\n }\n if (entry.queue.length > 0) await drain(entry)\n })\n },\n replace(document, revision, authoredOn) {\n const doc = canonical(document)\n const entry = entryOf(doc)\n if (entry.deleted) {\n // EC-673: a document this session no longer holds has nothing to replace — refused\n // and reported here, never queued for a drain that skips it (or a re-create of the\n // id that would send it). A new document of the id is a `create`.\n options.onError(goneError(entry.ref))\n return\n }\n if (!entry.base && !entry.provisional) entry.provisional = doc\n // Queued in its place: the patches committed before it are sent first (the snapshot\n // holds them), the ones committed after it are sent after it (it does not). EC-647\n // (Codex F10): one with no authoring revision on a document this session tracks and\n // did not create is refused there, in order — never sent at the tracked revision.\n // EC-686: with the document it was made from — what a refusal decomposes it against.\n entry.queue.push({ kind: 'replace', document: doc, base: authoredBase(entry, undefined, revision), ...(authoredOn ? { authoredOn } : {}) })\n emitDocument(entry)\n schedule(entry)\n },\n deleteCreated(ref) {\n const entry = entryOf(ref)\n return new Promise<DeleteCreatedOutcome>((resolve) => {\n // Queued like every write: whatever was committed before it is sent first.\n queue.push(async () => {\n if (entry.deleted) return resolve('gone')\n if (entry.created === undefined) return resolve('not-created')\n // A write of ours committed and not sent yet is an edit since the create.\n if (entry.queue.length > 0) return resolve('changed')\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.delete({\n projectId: options.projectId,\n ref: entry.ref,\n precondition: { revision: entry.created, unreferenced: true },\n })\n if (result.ok) {\n markGone(entry)\n resolve('deleted')\n } else resolve(deleteCreatedRefusal(result.error))\n } catch {\n resolve('failed')\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n })\n },\n deleteDocument(ref) {\n const entry = entryOf(ref)\n dropQueued(entry, { status: 'failed', error: goneError(ref) })\n entry.conflicts = []\n entry.conflictBases.clear()\n entry.deleted = true\n emitConflicts(entry)\n command(entry, (operations) => operations.documents.delete({ projectId: options.projectId, ref }))\n },\n unpublishDocument(ref) {\n const entry = entryOf(ref)\n queue.push(async () => {\n await drain(entry)\n const operations = await options.getOperations()\n entry.busy = true\n try {\n const result = await operations.documents.unpublish({ projectId: options.projectId, ref })\n if (result.ok) {\n recordOwn(entry, { revision: result.value.revision, sentBase: undefined, paths: [] })\n adopt(entry, result.value)\n } else options.onError(result.error)\n } finally {\n entry.busy = false\n adoptHeld(entry)\n }\n })\n },\n adoptSnapshot(ref, record) {\n const entry = entryOf(ref)\n if (entry.inFlight.length > 0 || entry.busy || entry.scheduled) {\n // Hold it: the write's own result decides first; the newer of the two wins.\n if (record === undefined) entry.held = null\n else if (!entry.held || record.revision > entry.held.revision) entry.held = record\n return\n }\n if (record === undefined) {\n if (entry.base) markGone(entry)\n return\n }\n if (!entry.base || record.revision > entry.base.revision) adopt(entry, record)\n },\n conflicts: (ref) => entries.get(documentKey(ref))?.conflicts ?? [],\n resolveConflict(ref, id, choice) {\n const entry = entries.get(documentKey(ref))\n if (!entry) return\n const conflict = entry.conflicts.find((c) => c.id === id)\n if (!conflict) return\n entry.conflicts = entry.conflicts.filter((c) => c !== conflict)\n entry.conflictBases.delete(conflict.id)\n if (choice === 'mine') {\n // Keep mine: re-send at the CURRENT base — a visible, explicit second write, and\n // the one deliberate \"at the current base\" write (EC-647): the user chose it\n // after seeing theirs.\n entry.queue.push({ kind: 'patch', patch: conflict.patch, base: entry.base?.revision, settle: [] })\n schedule(entry)\n }\n emitDocument(entry)\n emitConflicts(entry)\n },\n async flush(ref) {\n if (ref) {\n const entry = entries.get(documentKey(ref))\n if (entry && entry.queue.length > 0) schedule(entry)\n }\n await queue.flush()\n },\n }\n}\n"]}