loro-repo 0.23.3 → 0.25.0

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 (48) hide show
  1. package/README.md +51 -0
  2. package/dist/doc-updates.cjs +108 -0
  3. package/dist/doc-updates.cjs.map +1 -1
  4. package/dist/doc-updates.js +90 -1
  5. package/dist/doc-updates.js.map +1 -1
  6. package/dist/effect.cjs +1 -1
  7. package/dist/effect.js +1 -1
  8. package/dist/index.cjs +184 -359
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +141 -316
  11. package/dist/index.js.map +1 -1
  12. package/dist/meta-snapshot.cjs.map +1 -1
  13. package/dist/meta-snapshot.js.map +1 -1
  14. package/dist/storage/filesystem.cjs +1 -1
  15. package/dist/storage/filesystem.js +1 -1
  16. package/dist/storage/indexeddb.cjs +77 -26
  17. package/dist/storage/indexeddb.cjs.map +1 -1
  18. package/dist/storage/indexeddb.d.cts +39 -5
  19. package/dist/storage/indexeddb.d.ts +39 -5
  20. package/dist/storage/indexeddb.js +77 -26
  21. package/dist/storage/indexeddb.js.map +1 -1
  22. package/dist/storage/sqlite.cjs +37 -20
  23. package/dist/storage/sqlite.cjs.map +1 -1
  24. package/dist/storage/sqlite.d.cts +23 -1
  25. package/dist/storage/sqlite.d.ts +23 -1
  26. package/dist/storage/sqlite.js +38 -21
  27. package/dist/storage/sqlite.js.map +1 -1
  28. package/dist/streams.d.cts +54 -3
  29. package/dist/streams.d.ts +54 -3
  30. package/dist/transport/streams.cjs +159 -26
  31. package/dist/transport/streams.cjs.map +1 -1
  32. package/dist/transport/streams.js +157 -24
  33. package/dist/transport/streams.js.map +1 -1
  34. package/dist/types.d.cts +18 -5
  35. package/dist/types.d.ts +18 -5
  36. package/dist/utils.cjs +446 -0
  37. package/dist/utils.cjs.map +1 -0
  38. package/dist/utils.js +375 -0
  39. package/dist/utils.js.map +1 -0
  40. package/dist/write-failure.cjs +47 -0
  41. package/dist/write-failure.cjs.map +1 -0
  42. package/dist/write-failure.js +42 -0
  43. package/dist/write-failure.js.map +1 -0
  44. package/package.json +4 -4
  45. package/dist/flock-persistence-journal.cjs +0 -170
  46. package/dist/flock-persistence-journal.cjs.map +0 -1
  47. package/dist/flock-persistence-journal.js +0 -159
  48. package/dist/flock-persistence-journal.js.map +0 -1
package/README.md CHANGED
@@ -148,6 +148,57 @@ Key points:
148
148
  - `FileSystemStorageAdaptor` (`src/storage/filesystem.ts`)
149
149
  - `SqliteRepoStore` (`src/storage/sqlite.ts`, Node.js only)
150
150
 
151
+ ## Pending imported document updates
152
+
153
+ This release requires `loro-crdt ^1.17.0`, which provides
154
+ `LoroDoc.exportPendingUpdates()`. Upgrade Loro together with LoroRepo. Existing
155
+ stored documents and update journals remain compatible.
156
+
157
+ Promise-managed documents automatically persist received updates even when their
158
+ causal dependencies are missing and no applied event or version change occurs.
159
+ This includes `import`, `importBatch`, the legacy `importUpdateBatch`, and
160
+ `importJsonUpdates`. The methods keep their original receiver, return and error
161
+ behavior. Detached reads copy both applied state and pending operations. They
162
+ retry changing export checkpoints at most eight times, then reject if a subscriber
163
+ keeps creating another transaction during every commit.
164
+
165
+ Pending operations use the existing ordinary `doc-update` journal, without a
166
+ second sidecar or storage-format migration. Successful incomplete imports retain
167
+ only their newly received input, rather than appending the entire growing pending
168
+ queue at every save. Complete imports keep the normal applied-version delta path;
169
+ complete snapshots are not stored a second time as raw input. Loro's
170
+ `exportPendingUpdates()` supplies a consistent pending checkpoint and the recovery
171
+ fallback for an import that accepted a prefix before failing. Each save captures
172
+ applied bytes and pending bytes before awaiting storage. An atomic
173
+ `saveMany` writes them together when available; otherwise pending bytes are
174
+ appended first, retaining the previous checkpoint if a later write fails.
175
+ Arrivals during an asynchronous save remain dirty for a later capture. Encoding
176
+ and storage failures reject explicit persistence and retain work for retry.
177
+ An absent pending result clears the in-memory pending baseline; after the missing
178
+ dependencies apply, normal journal consolidation removes the covered records.
179
+
180
+ Custom storage adapters must replay and retain incomplete `doc-update` inputs.
181
+ Saving a `doc-snapshot` must preserve unresolved journal inputs and concurrently
182
+ appended inputs: an ordinary snapshot only contains applied state, even when it
183
+ comes from an explicit persistence barrier. Importing an update and immediately
184
+ saving only an ordinary snapshot loses its pending operations. The bundled SQLite, IndexedDB and filesystem adapters already
185
+ retain such journals, including data written by older versions. Native Effect
186
+ controlled imports keep their existing exact-input journal; they do not store a
187
+ second copy through this Promise observer. Pending persistence does not establish
188
+ remote catch-up or permit cursor advancement; transport guards are unchanged.
189
+
190
+ Binary update inputs are copied before import callbacks can change the caller's
191
+ buffer. Known mode-3 snapshot-only imports skip that copy using Loro's documented
192
+ envelope; the original import still validates their contents. Mixed batches keep
193
+ all their inputs until the aggregate import status is known, then discard copies
194
+ when complete. This preserves the original bytes if only part of a batch applies.
195
+ Unloading retries a changing persistence checkpoint at most eight times; if writes
196
+ continue, it rejects while keeping the cached document dirty for a later retry.
197
+ This limit concerns local persistence capture, independently of network recovery.
198
+ `flush()` retains its existing drain-until-quiescent contract, so it can continue
199
+ while a producer keeps writing. `destroy()` stops rooms and closes transports
200
+ before running the document manager's final flush.
201
+
151
202
  ## Classifying storage failures
152
203
 
153
204
  `IndexedDBStorageAdaptor` wraps backend failures in a `RepoStorageError`
@@ -1,3 +1,6 @@
1
+ const require_chunk = require('./chunk.cjs');
2
+ let loro_crdt = require("loro-crdt");
3
+ loro_crdt = require_chunk.__toESM(loro_crdt);
1
4
 
2
5
  //#region src/storage/doc-updates.ts
3
6
  const pending = Symbol.for("loro-repo.document-pending-updates.v1");
@@ -44,6 +47,93 @@ function applyStoredDocUpdates(doc, updates) {
44
47
  }
45
48
  const storedDocComplete = (doc) => doc[completeness] !== false;
46
49
  const storedPendingUpdates = (doc) => doc[pending] ?? [];
50
+ /**
51
+ * The documented Loro envelope has magic `loro` and a big-endian mode at
52
+ * bytes 20..22. Mode 3 snapshots contain applied history, never pending input.
53
+ * This is only a copy optimization: import still validates the entire blob.
54
+ * Unknown/legacy encodings retain the conservative copy path.
55
+ * https://github.com/loro-dev/loro/blob/main/docs/encoding-xxhash32.md#document-envelope-checksum
56
+ */
57
+ function isCompleteSnapshot(bytes) {
58
+ return bytes.length >= 22 && bytes[0] === 108 && bytes[1] === 111 && bytes[2] === 114 && bytes[3] === 111 && bytes[20] === 0 && bytes[21] === 3;
59
+ }
60
+ /** Preserve exact successful inputs, including pending-only imports with no event. */
61
+ function observeDocImports(doc, onImport) {
62
+ const restorers = [];
63
+ const observe = (key) => {
64
+ const original = doc[key];
65
+ const own = Object.getOwnPropertyDescriptor(doc, key);
66
+ const wrapped = function(...args) {
67
+ let input;
68
+ if (this === doc) try {
69
+ if (key === "importJsonUpdates") input = {
70
+ kind: "json",
71
+ json: typeof args[0] === "string" ? args[0] : structuredClone(args[0])
72
+ };
73
+ else {
74
+ const updates = key === "import" ? [args[0]] : args[0];
75
+ input = {
76
+ kind: "binary",
77
+ updates: updates.every(isCompleteSnapshot) ? [] : updates.map((bytes) => Uint8Array.from(bytes))
78
+ };
79
+ }
80
+ } catch {}
81
+ let succeeded = false;
82
+ try {
83
+ const result = Reflect.apply(original, this, args);
84
+ succeeded = true;
85
+ if (!result.pending?.size) input = {
86
+ kind: "binary",
87
+ updates: []
88
+ };
89
+ else if (input?.kind === "binary" && input.updates.length === 0) input = void 0;
90
+ return result;
91
+ } finally {
92
+ if (this === doc) onImport(succeeded ? input : void 0);
93
+ }
94
+ };
95
+ Object.defineProperty(doc, key, {
96
+ value: wrapped,
97
+ configurable: true,
98
+ writable: true
99
+ });
100
+ restorers.push(() => {
101
+ if (doc[key] !== wrapped) return;
102
+ if (own) Object.defineProperty(doc, key, own);
103
+ else Reflect.deleteProperty(doc, key);
104
+ });
105
+ };
106
+ try {
107
+ observe("import");
108
+ observe("importBatch");
109
+ observe("importUpdateBatch");
110
+ observe("importJsonUpdates");
111
+ } catch (error) {
112
+ for (const restore of restorers) restore();
113
+ throw error;
114
+ }
115
+ return () => {
116
+ for (const restore of restorers) restore();
117
+ };
118
+ }
119
+ /** Convert only this JSON input, not the live document's accumulated pending queue. */
120
+ function receivedDocUpdates(input) {
121
+ if (input.kind === "binary") return input.updates;
122
+ const copy = new loro_crdt.LoroDoc();
123
+ try {
124
+ copy.importJsonUpdates(input.json);
125
+ const updates = [];
126
+ if (copy.oplogFrontiers().length) updates.push(copy.export({ mode: "update" }));
127
+ const pending$1 = copy.exportPendingUpdates();
128
+ if (pending$1 !== void 0) updates.push(pending$1);
129
+ return updates;
130
+ } finally {
131
+ copy.free();
132
+ }
133
+ }
134
+ function samePendingUpdates(left, right) {
135
+ return left === right || left !== void 0 && right !== void 0 && left.length === right.length && left.every((byte, index) => byte === right[index]);
136
+ }
47
137
 
48
138
  //#endregion
49
139
  Object.defineProperty(exports, 'applyStoredDocUpdates', {
@@ -58,6 +148,24 @@ Object.defineProperty(exports, 'makeDocImporter', {
58
148
  return makeDocImporter;
59
149
  }
60
150
  });
151
+ Object.defineProperty(exports, 'observeDocImports', {
152
+ enumerable: true,
153
+ get: function () {
154
+ return observeDocImports;
155
+ }
156
+ });
157
+ Object.defineProperty(exports, 'receivedDocUpdates', {
158
+ enumerable: true,
159
+ get: function () {
160
+ return receivedDocUpdates;
161
+ }
162
+ });
163
+ Object.defineProperty(exports, 'samePendingUpdates', {
164
+ enumerable: true,
165
+ get: function () {
166
+ return samePendingUpdates;
167
+ }
168
+ });
61
169
  Object.defineProperty(exports, 'storedDocComplete', {
62
170
  enumerable: true,
63
171
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"file":"doc-updates.cjs","names":["remaining: Array<{ start: number; end: number }>"],"sources":["../src/storage/doc-updates.ts"],"sourcesContent":["import type { LoroDoc } from 'loro-crdt';\n\nconst pending = Symbol.for('loro-repo.document-pending-updates.v1');\nconst completeness = Symbol.for('loro-repo.document-import-completeness.v1');\ntype TrackedDoc = LoroDoc & { [completeness]?: boolean; [pending]?: readonly Uint8Array[] };\n\n/** Pending input bytes cannot be represented by a snapshot. Keep their journal. */\nexport function makeDocImporter(doc: LoroDoc) {\n const unresolved = new Map<string, Array<{ start: number; end: number }>>();\n return (\n updates: readonly Uint8Array[],\n onImport?: (status: ReturnType<LoroDoc['import']>) => void\n ): boolean => {\n // Preserve sequential import and its observable hydration boundary. Track\n // all unresolved ranges: a later successful import can resolve an earlier one.\n for (const bytes of updates) {\n const status = doc.import(bytes);\n onImport?.(status);\n for (const [peer, span] of status.pending ?? []) {\n const key = String(peer);\n const spans = unresolved.get(key) ?? [];\n spans.push(span);\n unresolved.set(key, spans);\n }\n for (const [peer, applied] of status.success) {\n const key = String(peer);\n const remaining: Array<{ start: number; end: number }> = [];\n for (const span of unresolved.get(key) ?? []) {\n if (applied.end <= span.start || applied.start >= span.end) remaining.push(span);\n else {\n if (span.start < applied.start)\n remaining.push({ start: span.start, end: applied.start });\n if (applied.end < span.end) remaining.push({ start: applied.end, end: span.end });\n }\n }\n if (remaining.length) unresolved.set(key, remaining);\n else unresolved.delete(key);\n }\n }\n return unresolved.size === 0;\n };\n}\n\nexport function applyStoredDocUpdates(doc: LoroDoc, updates: readonly Uint8Array[]): boolean {\n const complete = makeDocImporter(doc)(updates);\n (doc as TrackedDoc)[completeness] = complete;\n (doc as TrackedDoc)[pending] = complete ? [] : updates.map((bytes) => bytes.slice());\n return complete;\n}\nexport const storedDocComplete = (doc: LoroDoc): boolean =>\n (doc as TrackedDoc)[completeness] !== false;\n\nexport const storedPendingUpdates = (doc: LoroDoc): readonly Uint8Array[] =>\n (doc as TrackedDoc)[pending] ?? [];\n"],"mappings":";;AAEA,MAAM,UAAU,OAAO,IAAI,wCAAwC;AACnE,MAAM,eAAe,OAAO,IAAI,4CAA4C;;AAI5E,SAAgB,gBAAgB,KAAc;CAC5C,MAAM,6BAAa,IAAI,KAAoD;AAC3E,SACE,SACA,aACY;AAGZ,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,SAAS,IAAI,OAAO,MAAM;AAChC,cAAW,OAAO;AAClB,QAAK,MAAM,CAAC,MAAM,SAAS,OAAO,WAAW,EAAE,EAAE;IAC/C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE;AACvC,UAAM,KAAK,KAAK;AAChB,eAAW,IAAI,KAAK,MAAM;;AAE5B,QAAK,MAAM,CAAC,MAAM,YAAY,OAAO,SAAS;IAC5C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAMA,YAAmD,EAAE;AAC3D,SAAK,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE,CAC1C,KAAI,QAAQ,OAAO,KAAK,SAAS,QAAQ,SAAS,KAAK,IAAK,WAAU,KAAK,KAAK;SAC3E;AACH,SAAI,KAAK,QAAQ,QAAQ,MACvB,WAAU,KAAK;MAAE,OAAO,KAAK;MAAO,KAAK,QAAQ;MAAO,CAAC;AAC3D,SAAI,QAAQ,MAAM,KAAK,IAAK,WAAU,KAAK;MAAE,OAAO,QAAQ;MAAK,KAAK,KAAK;MAAK,CAAC;;AAGrF,QAAI,UAAU,OAAQ,YAAW,IAAI,KAAK,UAAU;QAC/C,YAAW,OAAO,IAAI;;;AAG/B,SAAO,WAAW,SAAS;;;AAI/B,SAAgB,sBAAsB,KAAc,SAAyC;CAC3F,MAAM,WAAW,gBAAgB,IAAI,CAAC,QAAQ;AAC9C,CAAC,IAAmB,gBAAgB;AACpC,CAAC,IAAmB,WAAW,WAAW,EAAE,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;AACpF,QAAO;;AAET,MAAa,qBAAqB,QAC/B,IAAmB,kBAAkB;AAExC,MAAa,wBAAwB,QAClC,IAAmB,YAAY,EAAE"}
1
+ {"version":3,"file":"doc-updates.cjs","names":["remaining: Array<{ start: number; end: number }>","restorers: Array<() => void>","input: ReceivedDocInput | undefined","LoroDoc","updates: Uint8Array[]","pending"],"sources":["../src/storage/doc-updates.ts"],"sourcesContent":["import { LoroDoc, type ImportStatus } from 'loro-crdt';\n\nconst pending = Symbol.for('loro-repo.document-pending-updates.v1');\nconst completeness = Symbol.for('loro-repo.document-import-completeness.v1');\ntype TrackedDoc = LoroDoc & { [completeness]?: boolean; [pending]?: readonly Uint8Array[] };\n\n/** Pending input bytes cannot be represented by a snapshot. Keep their journal. */\nexport function makeDocImporter(doc: LoroDoc) {\n const unresolved = new Map<string, Array<{ start: number; end: number }>>();\n return (\n updates: readonly Uint8Array[],\n onImport?: (status: ReturnType<LoroDoc['import']>) => void\n ): boolean => {\n // Preserve sequential import and its observable hydration boundary. Track\n // all unresolved ranges: a later successful import can resolve an earlier one.\n for (const bytes of updates) {\n const status = doc.import(bytes);\n onImport?.(status);\n for (const [peer, span] of status.pending ?? []) {\n const key = String(peer);\n const spans = unresolved.get(key) ?? [];\n spans.push(span);\n unresolved.set(key, spans);\n }\n for (const [peer, applied] of status.success) {\n const key = String(peer);\n const remaining: Array<{ start: number; end: number }> = [];\n for (const span of unresolved.get(key) ?? []) {\n if (applied.end <= span.start || applied.start >= span.end) remaining.push(span);\n else {\n if (span.start < applied.start)\n remaining.push({ start: span.start, end: applied.start });\n if (applied.end < span.end) remaining.push({ start: applied.end, end: span.end });\n }\n }\n if (remaining.length) unresolved.set(key, remaining);\n else unresolved.delete(key);\n }\n }\n return unresolved.size === 0;\n };\n}\n\nexport function applyStoredDocUpdates(doc: LoroDoc, updates: readonly Uint8Array[]): boolean {\n const complete = makeDocImporter(doc)(updates);\n (doc as TrackedDoc)[completeness] = complete;\n (doc as TrackedDoc)[pending] = complete ? [] : updates.map((bytes) => bytes.slice());\n return complete;\n}\nexport const storedDocComplete = (doc: LoroDoc): boolean =>\n (doc as TrackedDoc)[completeness] !== false;\n\nexport const storedPendingUpdates = (doc: LoroDoc): readonly Uint8Array[] =>\n (doc as TrackedDoc)[pending] ?? [];\n\nexport type ReceivedDocInput =\n | { readonly kind: \"binary\"; readonly updates: readonly Uint8Array[] }\n | { readonly kind: \"json\"; readonly json: Parameters<LoroDoc[\"importJsonUpdates\"]>[0] };\n\n/**\n * The documented Loro envelope has magic `loro` and a big-endian mode at\n * bytes 20..22. Mode 3 snapshots contain applied history, never pending input.\n * This is only a copy optimization: import still validates the entire blob.\n * Unknown/legacy encodings retain the conservative copy path.\n * https://github.com/loro-dev/loro/blob/main/docs/encoding-xxhash32.md#document-envelope-checksum\n */\nfunction isCompleteSnapshot(bytes: Uint8Array): boolean {\n return bytes.length >= 22 && bytes[0] === 108 && bytes[1] === 111 &&\n bytes[2] === 114 && bytes[3] === 111 && bytes[20] === 0 && bytes[21] === 3;\n}\n\n/** Preserve exact successful inputs, including pending-only imports with no event. */\nexport function observeDocImports(\n doc: LoroDoc,\n onImport: (input: ReceivedDocInput | undefined) => void,\n): () => void {\n const restorers: Array<() => void> = [];\n const observe = <K extends \"import\" | \"importBatch\" | \"importUpdateBatch\" | \"importJsonUpdates\">(\n key: K,\n ) => {\n const original = doc[key];\n const own = Object.getOwnPropertyDescriptor(doc, key);\n const wrapped = function (this: LoroDoc, ...args: unknown[]) {\n let input: ReceivedDocInput | undefined;\n if (this === doc) {\n // Copy before native import can synchronously invoke user callbacks.\n // Capture failures must not change the original public import behavior.\n try {\n if (key === \"importJsonUpdates\") {\n input = {\n kind: \"json\",\n json:\n typeof args[0] === \"string\"\n ? args[0]\n : (structuredClone(args[0]) as Parameters<LoroDoc[\"importJsonUpdates\"]>[0]),\n };\n } else {\n const updates = (key === \"import\" ? [args[0]] : args[0]) as Uint8Array[];\n // A batch returns one aggregate status. Copy mixed batches in\n // full so a pending result never relies on classifying which\n // input contributed it. Closed snapshot-only imports avoid the\n // large copy; complete results below discard all copies.\n const copies = updates.every(isCompleteSnapshot)\n ? [] : updates.map((bytes) => Uint8Array.from(bytes));\n input = { kind: \"binary\", updates: copies };\n }\n } catch {\n /* The save falls back to the live pending checkpoint. */\n }\n }\n let succeeded = false;\n try {\n const result = Reflect.apply(original, this, args);\n succeeded = true;\n const status = result as ImportStatus;\n if (!status.pending?.size) input = { kind: \"binary\", updates: [] };\n // Never silently drop pending data if a future snapshot encoding\n // starts retaining it. Preserve the canonical checkpoint instead.\n else if (input?.kind === \"binary\" && input.updates.length === 0) input = undefined;\n return result;\n } finally {\n // A failed batch can have accepted a prefix. Never journal malformed\n // input; retain that accepted prefix through the normal checkpoint.\n if (this === doc) onImport(succeeded ? input : undefined);\n }\n };\n Object.defineProperty(doc, key, { value: wrapped, configurable: true, writable: true });\n restorers.push(() => {\n if (doc[key] !== wrapped) return;\n if (own) Object.defineProperty(doc, key, own);\n else Reflect.deleteProperty(doc, key);\n });\n };\n try {\n observe(\"import\");\n observe(\"importBatch\");\n observe(\"importUpdateBatch\");\n observe(\"importJsonUpdates\");\n } catch (error) {\n for (const restore of restorers) restore();\n throw error;\n }\n return () => {\n for (const restore of restorers) restore();\n };\n}\n\n/** Convert only this JSON input, not the live document's accumulated pending queue. */\nexport function receivedDocUpdates(input: ReceivedDocInput): readonly Uint8Array[] {\n if (input.kind === \"binary\") return input.updates;\n const copy = new LoroDoc();\n try {\n copy.importJsonUpdates(input.json);\n const updates: Uint8Array[] = [];\n if (copy.oplogFrontiers().length) updates.push(copy.export({ mode: \"update\" }));\n const pending = copy.exportPendingUpdates();\n if (pending !== undefined) updates.push(pending);\n return updates;\n } finally {\n copy.free();\n }\n}\n\nexport function samePendingUpdates(\n left: Uint8Array | undefined,\n right: Uint8Array | undefined,\n): boolean {\n return (\n left === right ||\n (left !== undefined &&\n right !== undefined &&\n left.length === right.length &&\n left.every((byte, index) => byte === right[index]))\n );\n}\n"],"mappings":";;;;;AAEA,MAAM,UAAU,OAAO,IAAI,wCAAwC;AACnE,MAAM,eAAe,OAAO,IAAI,4CAA4C;;AAI5E,SAAgB,gBAAgB,KAAc;CAC5C,MAAM,6BAAa,IAAI,KAAoD;AAC3E,SACE,SACA,aACY;AAGZ,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,SAAS,IAAI,OAAO,MAAM;AAChC,cAAW,OAAO;AAClB,QAAK,MAAM,CAAC,MAAM,SAAS,OAAO,WAAW,EAAE,EAAE;IAC/C,MAAM,MAA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AU,QAAO,MAAM;CAC1C,MAAM,OAAO,IAAIC,mBAAS;AAC1B,KAAI;AACF,OAAK,kBAAkB,MAAM,KAAK;EAClC,MAAMC,UAAwB,EAAE;AAChC,MAAI,KAAK,gBAAgB,CAAC,OAAQ,SAAQ,KAAK,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC,CAAC;EAC/E,MAAMC,YAAU,KAAK,sBAAsB;AAC3C,MAAIA,cAAY,OAAW,SAAQ,KAAKA,UAAQ;AAChD,SAAO;WACC;AACR,OAAK,MAAM;;;AAIf,SAAgB,mBACd,MACA,OACS;AACT,QACE,SAAS,SACR,SAAS,UACR,UAAU,UACV,KAAK,WAAW,MAAM,UACtB,KAAK,OAAO,MAAM,UAAU,SAAS,MAAM,OAAO"}
@@ -1,3 +1,5 @@
1
+ import { LoroDoc } from "loro-crdt";
2
+
1
3
  //#region src/storage/doc-updates.ts
2
4
  const pending = Symbol.for("loro-repo.document-pending-updates.v1");
3
5
  const completeness = Symbol.for("loro-repo.document-import-completeness.v1");
@@ -43,7 +45,94 @@ function applyStoredDocUpdates(doc, updates) {
43
45
  }
44
46
  const storedDocComplete = (doc) => doc[completeness] !== false;
45
47
  const storedPendingUpdates = (doc) => doc[pending] ?? [];
48
+ /**
49
+ * The documented Loro envelope has magic `loro` and a big-endian mode at
50
+ * bytes 20..22. Mode 3 snapshots contain applied history, never pending input.
51
+ * This is only a copy optimization: import still validates the entire blob.
52
+ * Unknown/legacy encodings retain the conservative copy path.
53
+ * https://github.com/loro-dev/loro/blob/main/docs/encoding-xxhash32.md#document-envelope-checksum
54
+ */
55
+ function isCompleteSnapshot(bytes) {
56
+ return bytes.length >= 22 && bytes[0] === 108 && bytes[1] === 111 && bytes[2] === 114 && bytes[3] === 111 && bytes[20] === 0 && bytes[21] === 3;
57
+ }
58
+ /** Preserve exact successful inputs, including pending-only imports with no event. */
59
+ function observeDocImports(doc, onImport) {
60
+ const restorers = [];
61
+ const observe = (key) => {
62
+ const original = doc[key];
63
+ const own = Object.getOwnPropertyDescriptor(doc, key);
64
+ const wrapped = function(...args) {
65
+ let input;
66
+ if (this === doc) try {
67
+ if (key === "importJsonUpdates") input = {
68
+ kind: "json",
69
+ json: typeof args[0] === "string" ? args[0] : structuredClone(args[0])
70
+ };
71
+ else {
72
+ const updates = key === "import" ? [args[0]] : args[0];
73
+ input = {
74
+ kind: "binary",
75
+ updates: updates.every(isCompleteSnapshot) ? [] : updates.map((bytes) => Uint8Array.from(bytes))
76
+ };
77
+ }
78
+ } catch {}
79
+ let succeeded = false;
80
+ try {
81
+ const result = Reflect.apply(original, this, args);
82
+ succeeded = true;
83
+ if (!result.pending?.size) input = {
84
+ kind: "binary",
85
+ updates: []
86
+ };
87
+ else if (input?.kind === "binary" && input.updates.length === 0) input = void 0;
88
+ return result;
89
+ } finally {
90
+ if (this === doc) onImport(succeeded ? input : void 0);
91
+ }
92
+ };
93
+ Object.defineProperty(doc, key, {
94
+ value: wrapped,
95
+ configurable: true,
96
+ writable: true
97
+ });
98
+ restorers.push(() => {
99
+ if (doc[key] !== wrapped) return;
100
+ if (own) Object.defineProperty(doc, key, own);
101
+ else Reflect.deleteProperty(doc, key);
102
+ });
103
+ };
104
+ try {
105
+ observe("import");
106
+ observe("importBatch");
107
+ observe("importUpdateBatch");
108
+ observe("importJsonUpdates");
109
+ } catch (error) {
110
+ for (const restore of restorers) restore();
111
+ throw error;
112
+ }
113
+ return () => {
114
+ for (const restore of restorers) restore();
115
+ };
116
+ }
117
+ /** Convert only this JSON input, not the live document's accumulated pending queue. */
118
+ function receivedDocUpdates(input) {
119
+ if (input.kind === "binary") return input.updates;
120
+ const copy = new LoroDoc();
121
+ try {
122
+ copy.importJsonUpdates(input.json);
123
+ const updates = [];
124
+ if (copy.oplogFrontiers().length) updates.push(copy.export({ mode: "update" }));
125
+ const pending$1 = copy.exportPendingUpdates();
126
+ if (pending$1 !== void 0) updates.push(pending$1);
127
+ return updates;
128
+ } finally {
129
+ copy.free();
130
+ }
131
+ }
132
+ function samePendingUpdates(left, right) {
133
+ return left === right || left !== void 0 && right !== void 0 && left.length === right.length && left.every((byte, index) => byte === right[index]);
134
+ }
46
135
 
47
136
  //#endregion
48
- export { storedPendingUpdates as i, makeDocImporter as n, storedDocComplete as r, applyStoredDocUpdates as t };
137
+ export { samePendingUpdates as a, receivedDocUpdates as i, makeDocImporter as n, storedDocComplete as o, observeDocImports as r, storedPendingUpdates as s, applyStoredDocUpdates as t };
49
138
  //# sourceMappingURL=doc-updates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"doc-updates.js","names":["remaining: Array<{ start: number; end: number }>"],"sources":["../src/storage/doc-updates.ts"],"sourcesContent":["import type { LoroDoc } from 'loro-crdt';\n\nconst pending = Symbol.for('loro-repo.document-pending-updates.v1');\nconst completeness = Symbol.for('loro-repo.document-import-completeness.v1');\ntype TrackedDoc = LoroDoc & { [completeness]?: boolean; [pending]?: readonly Uint8Array[] };\n\n/** Pending input bytes cannot be represented by a snapshot. Keep their journal. */\nexport function makeDocImporter(doc: LoroDoc) {\n const unresolved = new Map<string, Array<{ start: number; end: number }>>();\n return (\n updates: readonly Uint8Array[],\n onImport?: (status: ReturnType<LoroDoc['import']>) => void\n ): boolean => {\n // Preserve sequential import and its observable hydration boundary. Track\n // all unresolved ranges: a later successful import can resolve an earlier one.\n for (const bytes of updates) {\n const status = doc.import(bytes);\n onImport?.(status);\n for (const [peer, span] of status.pending ?? []) {\n const key = String(peer);\n const spans = unresolved.get(key) ?? [];\n spans.push(span);\n unresolved.set(key, spans);\n }\n for (const [peer, applied] of status.success) {\n const key = String(peer);\n const remaining: Array<{ start: number; end: number }> = [];\n for (const span of unresolved.get(key) ?? []) {\n if (applied.end <= span.start || applied.start >= span.end) remaining.push(span);\n else {\n if (span.start < applied.start)\n remaining.push({ start: span.start, end: applied.start });\n if (applied.end < span.end) remaining.push({ start: applied.end, end: span.end });\n }\n }\n if (remaining.length) unresolved.set(key, remaining);\n else unresolved.delete(key);\n }\n }\n return unresolved.size === 0;\n };\n}\n\nexport function applyStoredDocUpdates(doc: LoroDoc, updates: readonly Uint8Array[]): boolean {\n const complete = makeDocImporter(doc)(updates);\n (doc as TrackedDoc)[completeness] = complete;\n (doc as TrackedDoc)[pending] = complete ? [] : updates.map((bytes) => bytes.slice());\n return complete;\n}\nexport const storedDocComplete = (doc: LoroDoc): boolean =>\n (doc as TrackedDoc)[completeness] !== false;\n\nexport const storedPendingUpdates = (doc: LoroDoc): readonly Uint8Array[] =>\n (doc as TrackedDoc)[pending] ?? [];\n"],"mappings":";AAEA,MAAM,UAAU,OAAO,IAAI,wCAAwC;AACnE,MAAM,eAAe,OAAO,IAAI,4CAA4C;;AAI5E,SAAgB,gBAAgB,KAAc;CAC5C,MAAM,6BAAa,IAAI,KAAoD;AAC3E,SACE,SACA,aACY;AAGZ,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,SAAS,IAAI,OAAO,MAAM;AAChC,cAAW,OAAO;AAClB,QAAK,MAAM,CAAC,MAAM,SAAS,OAAO,WAAW,EAAE,EAAE;IAC/C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE;AACvC,UAAM,KAAK,KAAK;AAChB,eAAW,IAAI,KAAK,MAAM;;AAE5B,QAAK,MAAM,CAAC,MAAM,YAAY,OAAO,SAAS;IAC5C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAMA,YAAmD,EAAE;AAC3D,SAAK,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE,CAC1C,KAAI,QAAQ,OAAO,KAAK,SAAS,QAAQ,SAAS,KAAK,IAAK,WAAU,KAAK,KAAK;SAC3E;AACH,SAAI,KAAK,QAAQ,QAAQ,MACvB,WAAU,KAAK;MAAE,OAAO,KAAK;MAAO,KAAK,QAAQ;MAAO,CAAC;AAC3D,SAAI,QAAQ,MAAM,KAAK,IAAK,WAAU,KAAK;MAAE,OAAO,QAAQ;MAAK,KAAK,KAAK;MAAK,CAAC;;AAGrF,QAAI,UAAU,OAAQ,YAAW,IAAI,KAAK,UAAU;QAC/C,YAAW,OAAO,IAAI;;;AAG/B,SAAO,WAAW,SAAS;;;AAI/B,SAAgB,sBAAsB,KAAc,SAAyC;CAC3F,MAAM,WAAW,gBAAgB,IAAI,CAAC,QAAQ;AAC9C,CAAC,IAAmB,gBAAgB;AACpC,CAAC,IAAmB,WAAW,WAAW,EAAE,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;AACpF,QAAO;;AAET,MAAa,qBAAqB,QAC/B,IAAmB,kBAAkB;AAExC,MAAa,wBAAwB,QAClC,IAAmB,YAAY,EAAE"}
1
+ {"version":3,"file":"doc-updates.js","names":["remaining: Array<{ start: number; end: number }>","restorers: Array<() => void>","input: ReceivedDocInput | undefined","updates: Uint8Array[]","pending"],"sources":["../src/storage/doc-updates.ts"],"sourcesContent":["import { LoroDoc, type ImportStatus } from 'loro-crdt';\n\nconst pending = Symbol.for('loro-repo.document-pending-updates.v1');\nconst completeness = Symbol.for('loro-repo.document-import-completeness.v1');\ntype TrackedDoc = LoroDoc & { [completeness]?: boolean; [pending]?: readonly Uint8Array[] };\n\n/** Pending input bytes cannot be represented by a snapshot. Keep their journal. */\nexport function makeDocImporter(doc: LoroDoc) {\n const unresolved = new Map<string, Array<{ start: number; end: number }>>();\n return (\n updates: readonly Uint8Array[],\n onImport?: (status: ReturnType<LoroDoc['import']>) => void\n ): boolean => {\n // Preserve sequential import and its observable hydration boundary. Track\n // all unresolved ranges: a later successful import can resolve an earlier one.\n for (const bytes of updates) {\n const status = doc.import(bytes);\n onImport?.(status);\n for (const [peer, span] of status.pending ?? []) {\n const key = String(peer);\n const spans = unresolved.get(key) ?? [];\n spans.push(span);\n unresolved.set(key, spans);\n }\n for (const [peer, applied] of status.success) {\n const key = String(peer);\n const remaining: Array<{ start: number; end: number }> = [];\n for (const span of unresolved.get(key) ?? []) {\n if (applied.end <= span.start || applied.start >= span.end) remaining.push(span);\n else {\n if (span.start < applied.start)\n remaining.push({ start: span.start, end: applied.start });\n if (applied.end < span.end) remaining.push({ start: applied.end, end: span.end });\n }\n }\n if (remaining.length) unresolved.set(key, remaining);\n else unresolved.delete(key);\n }\n }\n return unresolved.size === 0;\n };\n}\n\nexport function applyStoredDocUpdates(doc: LoroDoc, updates: readonly Uint8Array[]): boolean {\n const complete = makeDocImporter(doc)(updates);\n (doc as TrackedDoc)[completeness] = complete;\n (doc as TrackedDoc)[pending] = complete ? [] : updates.map((bytes) => bytes.slice());\n return complete;\n}\nexport const storedDocComplete = (doc: LoroDoc): boolean =>\n (doc as TrackedDoc)[completeness] !== false;\n\nexport const storedPendingUpdates = (doc: LoroDoc): readonly Uint8Array[] =>\n (doc as TrackedDoc)[pending] ?? [];\n\nexport type ReceivedDocInput =\n | { readonly kind: \"binary\"; readonly updates: readonly Uint8Array[] }\n | { readonly kind: \"json\"; readonly json: Parameters<LoroDoc[\"importJsonUpdates\"]>[0] };\n\n/**\n * The documented Loro envelope has magic `loro` and a big-endian mode at\n * bytes 20..22. Mode 3 snapshots contain applied history, never pending input.\n * This is only a copy optimization: import still validates the entire blob.\n * Unknown/legacy encodings retain the conservative copy path.\n * https://github.com/loro-dev/loro/blob/main/docs/encoding-xxhash32.md#document-envelope-checksum\n */\nfunction isCompleteSnapshot(bytes: Uint8Array): boolean {\n return bytes.length >= 22 && bytes[0] === 108 && bytes[1] === 111 &&\n bytes[2] === 114 && bytes[3] === 111 && bytes[20] === 0 && bytes[21] === 3;\n}\n\n/** Preserve exact successful inputs, including pending-only imports with no event. */\nexport function observeDocImports(\n doc: LoroDoc,\n onImport: (input: ReceivedDocInput | undefined) => void,\n): () => void {\n const restorers: Array<() => void> = [];\n const observe = <K extends \"import\" | \"importBatch\" | \"importUpdateBatch\" | \"importJsonUpdates\">(\n key: K,\n ) => {\n const original = doc[key];\n const own = Object.getOwnPropertyDescriptor(doc, key);\n const wrapped = function (this: LoroDoc, ...args: unknown[]) {\n let input: ReceivedDocInput | undefined;\n if (this === doc) {\n // Copy before native import can synchronously invoke user callbacks.\n // Capture failures must not change the original public import behavior.\n try {\n if (key === \"importJsonUpdates\") {\n input = {\n kind: \"json\",\n json:\n typeof args[0] === \"string\"\n ? args[0]\n : (structuredClone(args[0]) as Parameters<LoroDoc[\"importJsonUpdates\"]>[0]),\n };\n } else {\n const updates = (key === \"import\" ? [args[0]] : args[0]) as Uint8Array[];\n // A batch returns one aggregate status. Copy mixed batches in\n // full so a pending result never relies on classifying which\n // input contributed it. Closed snapshot-only imports avoid the\n // large copy; complete results below discard all copies.\n const copies = updates.every(isCompleteSnapshot)\n ? [] : updates.map((bytes) => Uint8Array.from(bytes));\n input = { kind: \"binary\", updates: copies };\n }\n } catch {\n /* The save falls back to the live pending checkpoint. */\n }\n }\n let succeeded = false;\n try {\n const result = Reflect.apply(original, this, args);\n succeeded = true;\n const status = result as ImportStatus;\n if (!status.pending?.size) input = { kind: \"binary\", updates: [] };\n // Never silently drop pending data if a future snapshot encoding\n // starts retaining it. Preserve the canonical checkpoint instead.\n else if (input?.kind === \"binary\" && input.updates.length === 0) input = undefined;\n return result;\n } finally {\n // A failed batch can have accepted a prefix. Never journal malformed\n // input; retain that accepted prefix through the normal checkpoint.\n if (this === doc) onImport(succeeded ? input : undefined);\n }\n };\n Object.defineProperty(doc, key, { value: wrapped, configurable: true, writable: true });\n restorers.push(() => {\n if (doc[key] !== wrapped) return;\n if (own) Object.defineProperty(doc, key, own);\n else Reflect.deleteProperty(doc, key);\n });\n };\n try {\n observe(\"import\");\n observe(\"importBatch\");\n observe(\"importUpdateBatch\");\n observe(\"importJsonUpdates\");\n } catch (error) {\n for (const restore of restorers) restore();\n throw error;\n }\n return () => {\n for (const restore of restorers) restore();\n };\n}\n\n/** Convert only this JSON input, not the live document's accumulated pending queue. */\nexport function receivedDocUpdates(input: ReceivedDocInput): readonly Uint8Array[] {\n if (input.kind === \"binary\") return input.updates;\n const copy = new LoroDoc();\n try {\n copy.importJsonUpdates(input.json);\n const updates: Uint8Array[] = [];\n if (copy.oplogFrontiers().length) updates.push(copy.export({ mode: \"update\" }));\n const pending = copy.exportPendingUpdates();\n if (pending !== undefined) updates.push(pending);\n return updates;\n } finally {\n copy.free();\n }\n}\n\nexport function samePendingUpdates(\n left: Uint8Array | undefined,\n right: Uint8Array | undefined,\n): boolean {\n return (\n left === right ||\n (left !== undefined &&\n right !== undefined &&\n left.length === right.length &&\n left.every((byte, index) => byte === right[index]))\n );\n}\n"],"mappings":";;;AAEA,MAAM,UAAU,OAAO,IAAI,wCAAwC;AACnE,MAAM,eAAe,OAAO,IAAI,4CAA4C;;AAI5E,SAAgB,gBAAgB,KAAc;CAC5C,MAAM,6BAAa,IAAI,KAAoD;AAC3E,SACE,SACA,aACY;AAGZ,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,SAAS,IAAI,OAAO,MAAM;AAChC,cAAW,OAAO;AAClB,QAAK,MAAM,CAAC,MAAM,SAAS,OAAO,WAAW,EAAE,EAAE;IAC/C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE;AACvC,UAAM,KAAK,KAAK;AAChB,eAAW,IAAI,KAAK,MAAM;;AAE5B,QAAK,MAAM,CAAC,MAAM,YAAY,OAAO,SAAS;IAC5C,MAAM,MAAM,OAAO,KAAK;IACxB,MAAMA,YAAmD,EAAE;AAC3D,SAAK,MAAM,QAAQ,WAAW,IAAI,IAAI,IAAI,EAAE,CAC1C,KAAI,QAAQ,OAAO,KAAK,SAAS,QAAQ,SAAS,KAAK,IAAK,WAAU,KAAK,KAAK;SAC3E;AACH,SAAI,KAAK,QAAQ,QAAQ,MACvB,WAAU,KAAK;MAAE,OAAO,KAAK;MAAO,KAAK,QAAQ;MAAO,CAAC;AAC3D,SAAI,QAAQ,MAAM,KAAK,IAAK,WAAU,KAAK;MAAE,OAAO,QAAQ;MAAK,KAAK,KAAK;MAAK,CAAC;;AAGrF,QAAI,UAAU,OAAQ,YAAW,IAAI,K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AAS,EAAE;KAAE;aAGzD,OAAO,SAAS,YAAY,MAAM,QAAQ,WAAW,EAAG,SAAQ;AACzE,WAAO;aACC;AAGR,QAAI,SAAS,IAAK,UAAS,YAAY,QAAQ,OAAU;;;AAG7D,SAAO,eAAe,KAAK,KAAK;GAAE,OAAO;GAAS,cAAc;GAAM,UAAU;GAAM,CAAC;AACvF,YAAU,WAAW;AACnB,OAAI,IAAI,SAAS,QAAS;AAC1B,OAAI,IAAK,QAAO,eAAe,KAAK,KAAK,IAAI;OACxC,SAAQ,eAAe,KAAK,IAAI;IACrC;;AAEJ,KAAI;AACF,UAAQ,SAAS;AACjB,UAAQ,cAAc;AACtB,UAAQ,oBAAoB;AAC5B,UAAQ,oBAAoB;UACrB,OAAO;AACd,OAAK,MAAM,WAAW,UAAW,UAAS;AAC1C,QAAM;;AAER,cAAa;AACX,OAAK,MAAM,WAAW,UAAW,UAAS;;;;AAK9C,SAAgB,mBAAmB,OAAgD;AACjF,KAAI,MAAM,SAAS,SAAU,QAAO,MAAM;CAC1C,MAAM,OAAO,IAAI,SAAS;AAC1B,KAAI;AACF,OAAK,kBAAkB,MAAM,KAAK;EAClC,MAAMC,UAAwB,EAAE;AAChC,MAAI,KAAK,gBAAgB,CAAC,OAAQ,SAAQ,KAAK,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC,CAAC;EAC/E,MAAMC,YAAU,KAAK,sBAAsB;AAC3C,MAAIA,cAAY,OAAW,SAAQ,KAAKA,UAAQ;AAChD,SAAO;WACC;AACR,OAAK,MAAM;;;AAIf,SAAgB,mBACd,MACA,OACS;AACT,QACE,SAAS,SACR,SAAS,UACR,UAAU,UACV,KAAK,WAAW,MAAM,UACtB,KAAK,OAAO,MAAM,UAAU,SAAS,MAAM,OAAO"}
package/dist/effect.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('./chunk.cjs');
2
2
  const require_meta_snapshot = require('./meta-snapshot.cjs');
3
- const require_room_state = require('./room-state.cjs');
4
3
  const require_doc_updates = require('./doc-updates.cjs');
4
+ const require_room_state = require('./room-state.cjs');
5
5
  let __loro_dev_flock_wasm = require("@loro-dev/flock-wasm");
6
6
  __loro_dev_flock_wasm = require_chunk.__toESM(__loro_dev_flock_wasm);
7
7
  let loro_crdt = require("loro-crdt");
package/dist/effect.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { r as isFlockFile, t as encodeMetaJsonUpdate, u as RepoWriterLocked } from "./meta-snapshot.js";
2
+ import { n as makeDocImporter, o as storedDocComplete, s as storedPendingUpdates } from "./doc-updates.js";
2
3
  import { a as RepoIOError, c as RepoResnapshotRequired, d as RepoUnsupported, f as scopedUse, i as RepoDocAlreadyExists, l as RepoResourceBusy, n as makeRoomState, o as RepoMigrationIncomplete, r as RepoClosed, s as RepoReleaseFailed, t as initialRoomState, u as RepoSyncFailed } from "./room-state.js";
3
- import { i as storedPendingUpdates, n as makeDocImporter, r as storedDocComplete } from "./doc-updates.js";
4
4
  import { Flock, decodeVersionVector, encodeVersionVector } from "@loro-dev/flock-wasm";
5
5
  import { EphemeralStore, LoroDoc, VersionVector, decodeImportBlobMeta } from "loro-crdt";
6
6
  import { Cause, Clock, Deferred, Effect, Exit, Layer, PubSub, Queue, RcMap, Schema, Scope, Semaphore, Stream, SubscriptionRef } from "effect";