@gonvex/client 0.1.31 → 0.3.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 (59) hide show
  1. package/README.md +119 -95
  2. package/dist/control.d.ts +416 -0
  3. package/dist/control.js +210 -0
  4. package/dist/control.js.map +1 -0
  5. package/dist/error-reporter.d.ts +20 -6
  6. package/dist/error-reporter.js +55 -27
  7. package/dist/error-reporter.js.map +1 -1
  8. package/dist/index.d.ts +170 -132
  9. package/dist/index.js +1123 -1138
  10. package/dist/index.js.map +1 -1
  11. package/dist/indexeddb-replica.d.ts +20 -0
  12. package/dist/indexeddb-replica.js +193 -0
  13. package/dist/indexeddb-replica.js.map +1 -0
  14. package/dist/kv-stores.d.ts +15 -0
  15. package/dist/kv-stores.js +60 -0
  16. package/dist/kv-stores.js.map +1 -0
  17. package/dist/local-replica.d.ts +240 -0
  18. package/dist/local-replica.js +590 -0
  19. package/dist/local-replica.js.map +1 -0
  20. package/dist/optimistic.d.ts +34 -55
  21. package/dist/optimistic.js +70 -269
  22. package/dist/optimistic.js.map +1 -1
  23. package/dist/outbox.d.ts +74 -16
  24. package/dist/outbox.js +194 -14
  25. package/dist/outbox.js.map +1 -1
  26. package/dist/query-expression.d.ts +58 -0
  27. package/dist/query-expression.js +164 -0
  28. package/dist/query-expression.js.map +1 -0
  29. package/dist/replica-integrity.d.ts +5 -0
  30. package/dist/replica-integrity.js +58 -0
  31. package/dist/replica-integrity.js.map +1 -0
  32. package/package.json +4 -4
  33. package/dist/browser-cache-client.d.ts +0 -77
  34. package/dist/browser-cache-client.js +0 -156
  35. package/dist/browser-cache-client.js.map +0 -1
  36. package/dist/browser-cache-shared-worker.d.ts +0 -35
  37. package/dist/browser-cache-shared-worker.js +0 -118
  38. package/dist/browser-cache-shared-worker.js.map +0 -1
  39. package/dist/browser-cache.d.ts +0 -43
  40. package/dist/browser-cache.js +0 -67
  41. package/dist/browser-cache.js.map +0 -1
  42. package/dist/browser-capabilities.d.ts +0 -21
  43. package/dist/browser-capabilities.js +0 -31
  44. package/dist/browser-capabilities.js.map +0 -1
  45. package/dist/cache-coordinator.d.ts +0 -37
  46. package/dist/cache-coordinator.js +0 -109
  47. package/dist/cache-coordinator.js.map +0 -1
  48. package/dist/cache.d.ts +0 -74
  49. package/dist/cache.js +0 -120
  50. package/dist/cache.js.map +0 -1
  51. package/dist/persistent-cache.d.ts +0 -41
  52. package/dist/persistent-cache.js +0 -103
  53. package/dist/persistent-cache.js.map +0 -1
  54. package/dist/query-cache.d.ts +0 -88
  55. package/dist/query-cache.js +0 -346
  56. package/dist/query-cache.js.map +0 -1
  57. package/dist/sync-store.d.ts +0 -96
  58. package/dist/sync-store.js +0 -500
  59. package/dist/sync-store.js.map +0 -1
@@ -0,0 +1,590 @@
1
+ const defaultReplicaScope = "default";
2
+ export class LocalReplica {
3
+ storage;
4
+ cursorValue;
5
+ entities = new Map();
6
+ liveQueries = new Map();
7
+ /** Rows introduced by a materialized window may be reclaimed conservatively. */
8
+ windowOwned = new Map();
9
+ pendingCommands = new Map();
10
+ listeners = new Set();
11
+ persistence = Promise.resolve();
12
+ application = Promise.resolve();
13
+ hydration;
14
+ freshnessValue = "verifying";
15
+ versionValue = 0;
16
+ scopeValue = defaultReplicaScope;
17
+ // The default scope starts as an immediately usable empty in-memory store.
18
+ // Persistence is restored only by hydrate()/activateScope(), so direct
19
+ // callers can still materialize before an async adapter is consulted.
20
+ scopeLoaded = true;
21
+ scopeActivation;
22
+ scopeActivationName;
23
+ scopeActivationGeneration = 0;
24
+ constructor(storage) {
25
+ this.storage = storage;
26
+ }
27
+ hydrate() {
28
+ if (this.hydration)
29
+ return this.hydration;
30
+ this.hydration = this.activateScope(defaultReplicaScope, true);
31
+ return this.hydration;
32
+ }
33
+ /**
34
+ * Atomically switch the authoritative store to an opaque persistence scope.
35
+ * A newer request supersedes an older one even if the older storage read is
36
+ * slow (or resolves after auth has already changed again).
37
+ */
38
+ activateScope(scope = defaultReplicaScope, forceReload = false) {
39
+ const nextScope = normalizeReplicaScope(scope);
40
+ if (!forceReload && this.scopeLoaded && this.scopeValue === nextScope)
41
+ return this.application;
42
+ if (this.scopeActivation && this.scopeActivationName === nextScope)
43
+ return this.scopeActivation;
44
+ // Fail closed immediately while the async read is in flight. This keeps a
45
+ // synchronous auth change from exposing the prior identity's rows.
46
+ const wasLoaded = this.scopeLoaded;
47
+ this.scopeLoaded = false;
48
+ if (wasLoaded)
49
+ this.notify();
50
+ const generation = ++this.scopeActivationGeneration;
51
+ const activation = this.application.then(async () => {
52
+ // A prior transaction may still be in the storage queue. Wait for it so
53
+ // a same-scope activation cannot load a snapshot from before its commit.
54
+ await this.persistence;
55
+ const snapshot = await this.storage?.load(nextScope);
56
+ if (generation !== this.scopeActivationGeneration)
57
+ return;
58
+ this.scopeValue = nextScope;
59
+ this.scopeLoaded = true;
60
+ this.cursorValue = snapshot?.cursor;
61
+ this.entities = snapshot ? entitiesFromSnapshot(snapshot.entities) : new Map();
62
+ this.liveQueries = snapshot
63
+ ? new Map(Object.entries(snapshot.liveQueries).map(([key, value]) => [key, normalizeWindow(value)]))
64
+ : new Map();
65
+ this.windowOwned.clear();
66
+ // Optimistic commands belong to the old identity and must never be
67
+ // projected while the newly restored scope is becoming authoritative.
68
+ this.pendingCommands.clear();
69
+ this.freshnessValue = "verifying";
70
+ this.notify();
71
+ });
72
+ this.application = activation.catch(() => undefined);
73
+ this.scopeActivation = activation;
74
+ this.scopeActivationName = nextScope;
75
+ return activation;
76
+ }
77
+ cursor() {
78
+ return this.scopeLoaded && this.cursorValue ? { ...this.cursorValue } : undefined;
79
+ }
80
+ freshness() {
81
+ return this.freshnessValue;
82
+ }
83
+ version() { return this.versionValue; }
84
+ setFreshness(freshness) {
85
+ if (freshness === this.freshnessValue)
86
+ return;
87
+ this.freshnessValue = freshness;
88
+ this.notify();
89
+ }
90
+ subscribe(listener) {
91
+ this.listeners.add(listener);
92
+ return () => this.listeners.delete(listener);
93
+ }
94
+ applyOptimistic(commandId, patches) {
95
+ commandId = commandId.trim();
96
+ if (!commandId)
97
+ throw new Error("optimistic commandId is required");
98
+ this.pendingCommands.set(commandId, { commandId, patches: patches.map(cloneOptimisticPatch) });
99
+ this.notify();
100
+ }
101
+ acknowledgeCommand(commandId, committedRevision) {
102
+ const pending = this.pendingCommands.get(commandId);
103
+ if (!pending)
104
+ return;
105
+ if (!committedRevision)
106
+ return;
107
+ pending.committedRevision = committedRevision;
108
+ this.reconcileCommands();
109
+ }
110
+ rejectCommand(commandId) {
111
+ if (!this.pendingCommands.delete(commandId))
112
+ return;
113
+ this.notify();
114
+ }
115
+ /** True while an optimistic command still contributes visible patches. */
116
+ hasPendingCommand(commandId) {
117
+ return this.pendingCommands.has(commandId);
118
+ }
119
+ applyTransaction(transaction, scope) {
120
+ const requestedScope = scope === undefined ? undefined : normalizeReplicaScope(scope);
121
+ const application = this.application.then(() => this.applyTransactionNow(transaction, requestedScope));
122
+ this.application = application.catch(() => undefined);
123
+ return application;
124
+ }
125
+ materializeWindow(input) {
126
+ const application = this.application.then(() => this.materializeWindowNow(input));
127
+ this.application = application.catch(() => undefined);
128
+ return application;
129
+ }
130
+ /** Replace one server/cache window while retaining shared normalized entities. */
131
+ replaceWindow(input) {
132
+ return this.materializeWindow(input);
133
+ }
134
+ /** Apply a bounded window delta and persist it in the same transaction. */
135
+ applyWindowDelta(input) {
136
+ const application = this.application.then(async () => {
137
+ const existing = this.liveQueries.get(input.signature);
138
+ const deleted = new Set(input.deleted.map(String));
139
+ const ids = (existing?.ids ?? []).filter((id) => !deleted.has(id));
140
+ for (const row of input.upserts) {
141
+ const rawID = row[input.key];
142
+ const id = typeof rawID === "string" || typeof rawID === "number" ? String(rawID) : "";
143
+ if (id && !ids.includes(id))
144
+ ids.push(id);
145
+ }
146
+ const rows = ids
147
+ .map((id) => input.upserts.find((row) => String(row[input.key]) === id) ?? this.entities.get(input.entity)?.get(id))
148
+ .filter((row) => row !== undefined)
149
+ .map(cloneRow);
150
+ await this.materializeWindowNow({
151
+ ...input,
152
+ rows,
153
+ completeness: input.completeness ?? existing?.completeness ?? "partial",
154
+ source: input.source ?? existing?.source ?? "server",
155
+ removedIDs: [...deleted],
156
+ });
157
+ });
158
+ this.application = application.catch(() => undefined);
159
+ return application;
160
+ }
161
+ getWindow(signature) {
162
+ const window = this.liveQueries.get(signature);
163
+ return window ? cloneWindow(window) : undefined;
164
+ }
165
+ listWindows() {
166
+ return [...this.liveQueries.values()].map(cloneWindow);
167
+ }
168
+ windowRows(signature) {
169
+ return this.liveQuery(signature).rows;
170
+ }
171
+ removeWindow(signature, scope) {
172
+ const application = this.application.then(async () => {
173
+ if (scope !== undefined && normalizeReplicaScope(scope) !== this.scopeValue)
174
+ return;
175
+ if (!this.liveQueries.has(signature))
176
+ return;
177
+ const nextQueries = new Map(this.liveQueries);
178
+ nextQueries.delete(signature);
179
+ const snapshot = snapshotFrom(this.cursorValue, this.entities, nextQueries);
180
+ if (this.storage?.removeWindow) {
181
+ await this.persist(() => this.storage.removeWindow(signature, snapshot, this.scopeValue));
182
+ }
183
+ else if (this.storage?.replaceSnapshot) {
184
+ await this.persist(() => this.storage.replaceSnapshot(snapshot, this.scopeValue));
185
+ }
186
+ this.liveQueries = nextQueries;
187
+ this.pruneOwnedEntitiesAfterRemoval(signature, nextQueries);
188
+ this.notify();
189
+ });
190
+ this.application = application.catch(() => undefined);
191
+ return application;
192
+ }
193
+ clear(scope) {
194
+ const application = this.application.then(async () => {
195
+ if (scope !== undefined && normalizeReplicaScope(scope) !== this.scopeValue)
196
+ return;
197
+ if (this.storage?.clear)
198
+ await this.persist(() => this.storage.clear(this.scopeValue));
199
+ this.cursorValue = undefined;
200
+ this.entities.clear();
201
+ this.liveQueries.clear();
202
+ this.windowOwned.clear();
203
+ this.pendingCommands.clear();
204
+ this.freshnessValue = "verifying";
205
+ this.notify();
206
+ });
207
+ this.application = application.catch(() => undefined);
208
+ return application;
209
+ }
210
+ async materializeWindowNow(input) {
211
+ if (input.scope !== undefined && normalizeReplicaScope(input.scope) !== this.scopeValue)
212
+ return;
213
+ if (!input.signature.trim() || !input.entity.trim() || !input.key.trim()) {
214
+ throw new Error("replica materialization requires signature, entity, and key");
215
+ }
216
+ const nextEntities = cloneEntities(this.entities);
217
+ // Clone memberships before changing them. Persistence may be asynchronous,
218
+ // and readers must continue to observe the prior complete version until the
219
+ // transaction commits locally and the single state swap below runs.
220
+ const nextQueries = new Map([...this.liveQueries.entries()].map(([signature, window]) => [signature, cloneWindow(window)]));
221
+ if (input.cursor && this.cursorValue && input.cursor.epoch !== this.cursorValue.epoch) {
222
+ nextEntities.clear();
223
+ nextQueries.clear();
224
+ }
225
+ const entityRows = nextEntities.get(input.entity) ?? new Map();
226
+ nextEntities.set(input.entity, entityRows);
227
+ const ids = [];
228
+ for (const row of input.rows) {
229
+ const rawID = row[input.key];
230
+ const id = typeof rawID === "string" || typeof rawID === "number" ? String(rawID) : "";
231
+ if (!id)
232
+ continue;
233
+ ids.push(id);
234
+ entityRows.set(id, cloneRow(row));
235
+ }
236
+ const previous = nextQueries.get(input.signature);
237
+ const window = {
238
+ signature: input.signature,
239
+ kind: input.kind ?? "live",
240
+ entity: input.entity,
241
+ key: input.key,
242
+ ids,
243
+ cursor: input.cursor ? { ...input.cursor } : undefined,
244
+ completeness: input.completeness,
245
+ source: input.source,
246
+ resultSkeleton: input.resultSkeleton === undefined ? undefined : structuredClone(input.resultSkeleton),
247
+ resultPath: input.resultPath ? [...input.resultPath] : undefined,
248
+ scalar: input.scalar === undefined ? undefined : structuredClone(input.scalar),
249
+ windowRevision: input.windowRevision,
250
+ subscriptionRevision: input.subscriptionRevision ? { ...input.subscriptionRevision } : undefined,
251
+ mode: input.mode,
252
+ truncated: input.truncated,
253
+ orderBy: input.orderBy,
254
+ orderDirection: input.orderDirection,
255
+ maxRows: input.maxRows,
256
+ maxBytes: input.maxBytes,
257
+ hashes: input.hashes ? { ...input.hashes } : undefined,
258
+ };
259
+ nextQueries.set(input.signature, window);
260
+ for (const id of input.removedIDs ?? []) {
261
+ const stillReferenced = [...nextQueries.values()].some((candidate) => candidate.ids.includes(id));
262
+ if (!stillReferenced)
263
+ nextEntities.get(input.entity)?.delete(id);
264
+ }
265
+ this.trackWindowOwnership(window, input.rows, previous);
266
+ let nextCursor = this.cursorValue;
267
+ if (input.cursor && (!nextCursor || input.cursor.epoch !== nextCursor.epoch || input.cursor.revision > nextCursor.revision)) {
268
+ nextCursor = { ...input.cursor };
269
+ }
270
+ const snapshot = snapshotFrom(nextCursor, nextEntities, nextQueries);
271
+ const writeScope = this.scopeValue;
272
+ if (this.storage?.replaceWindow) {
273
+ await this.persist(() => this.storage.replaceWindow(window, snapshot, writeScope));
274
+ }
275
+ else if (this.storage?.replaceSnapshot) {
276
+ await this.persist(() => this.storage.replaceSnapshot(snapshot, writeScope));
277
+ }
278
+ this.entities = nextEntities;
279
+ this.liveQueries = nextQueries;
280
+ this.pruneOwnedEntities(input.signature);
281
+ this.cursorValue = nextCursor;
282
+ if (input.source === "server")
283
+ this.freshnessValue = "current";
284
+ this.notify();
285
+ }
286
+ async applyTransactionNow(transaction, scope) {
287
+ if (scope !== undefined && scope !== this.scopeValue)
288
+ return;
289
+ validateTransaction(transaction);
290
+ if (this.cursorValue?.epoch === transaction.cursor.epoch && transaction.cursor.revision <= this.cursorValue.revision) {
291
+ return;
292
+ }
293
+ const nextEntities = cloneEntities(this.entities);
294
+ // A transaction is invisible until its storage write succeeds. Deep-clone
295
+ // memberships because row deletion edits their ordered ID arrays.
296
+ const nextQueries = new Map([...this.liveQueries.entries()].map(([signature, window]) => [signature, cloneWindow(window)]));
297
+ if (this.cursorValue && this.cursorValue.epoch !== transaction.cursor.epoch) {
298
+ nextEntities.clear();
299
+ nextQueries.clear();
300
+ this.windowOwned.clear();
301
+ }
302
+ for (const change of transaction.changes) {
303
+ const rows = nextEntities.get(change.entity) ?? new Map();
304
+ nextEntities.set(change.entity, rows);
305
+ if (change.operation === "delete") {
306
+ rows.delete(change.id);
307
+ for (const window of nextQueries.values()) {
308
+ if (window.ids.includes(change.id)) {
309
+ window.ids = window.ids.filter((id) => id !== change.id);
310
+ }
311
+ }
312
+ }
313
+ else if (change.newValue)
314
+ rows.set(change.id, cloneRow(change.newValue));
315
+ }
316
+ for (const membership of transaction.memberships ?? []) {
317
+ nextQueries.set(membership.signature, normalizeWindow(membership));
318
+ }
319
+ const snapshot = snapshotFrom(transaction.cursor, nextEntities, nextQueries);
320
+ const writeScope = this.scopeValue;
321
+ await this.persist(() => this.storage?.applyTransaction(transaction, snapshot, writeScope));
322
+ // Publish the whole committed transaction in one state swap and notify UI
323
+ // exactly once. No subscriber can observe a partial entity/query update.
324
+ this.entities = nextEntities;
325
+ this.liveQueries = nextQueries;
326
+ this.cursorValue = { ...transaction.cursor };
327
+ this.freshnessValue = "current";
328
+ if (transaction.originCommandId)
329
+ this.pendingCommands.delete(transaction.originCommandId);
330
+ this.reconcileCommands(false);
331
+ this.notify();
332
+ }
333
+ entity(entity, id) {
334
+ if (!this.scopeLoaded)
335
+ return undefined;
336
+ let row = this.entities.get(entity)?.get(id);
337
+ let selected = row ? cloneRow(row) : undefined;
338
+ for (const command of this.pendingCommands.values()) {
339
+ for (const patch of command.patches) {
340
+ if ((patch.entity ?? patch.collection) !== entity || patch.rowId !== id)
341
+ continue;
342
+ if (patch.op === "delete")
343
+ selected = undefined;
344
+ if (patch.op === "insert")
345
+ selected = cloneRow(patch.fields);
346
+ if (patch.op === "upsert")
347
+ selected = cloneRow(patch.fields);
348
+ if (patch.op === "patch")
349
+ selected = { ...(selected ?? {}), ...patch.fields };
350
+ }
351
+ }
352
+ return selected;
353
+ }
354
+ /** Resolve several IDs from one atomic Local Replica version. */
355
+ entityBatch(entity, ids) {
356
+ return ids.map((id) => this.entity(entity, id));
357
+ }
358
+ /** All cached rows for one normalized entity, including optimistic overlays. */
359
+ entityRows(entity) {
360
+ if (!this.scopeLoaded)
361
+ return [];
362
+ const ids = new Set(this.entities.get(entity)?.keys() ?? []);
363
+ for (const command of this.pendingCommands.values()) {
364
+ for (const patch of command.patches) {
365
+ if ((patch.entity ?? patch.collection) === entity)
366
+ ids.add(patch.rowId);
367
+ }
368
+ }
369
+ return [...ids]
370
+ .map((id) => this.entity(entity, id))
371
+ .filter((row) => row !== undefined);
372
+ }
373
+ /** Exact only when an authoritative, non-truncated Replica Collection covers the entity. */
374
+ entityCompleteness(entity) {
375
+ if (!this.scopeLoaded)
376
+ return "partial";
377
+ return [...this.liveQueries.values()].some((window) => (window.kind === "replica"
378
+ && window.entity === entity
379
+ && window.completeness === "complete"
380
+ && window.truncated !== true)) ? "complete" : "partial";
381
+ }
382
+ liveQuery(signature) {
383
+ if (!this.scopeLoaded) {
384
+ return { rows: [], ids: [], source: "cache", completeness: "partial", freshness: this.freshnessValue };
385
+ }
386
+ const membership = this.liveQueries.get(signature);
387
+ if (!membership) {
388
+ return { rows: [], ids: [], source: "cache", completeness: "partial", freshness: this.freshnessValue };
389
+ }
390
+ const rows = membership.ids
391
+ .map((id) => this.entity(membership.entity, id))
392
+ .filter((row) => row !== undefined);
393
+ const metadata = windowResultMetadata(membership.resultSkeleton, membership.resultPath);
394
+ return {
395
+ rows,
396
+ ids: [...membership.ids],
397
+ ...metadata,
398
+ source: this.freshnessValue === "current" ? membership.source : "cache",
399
+ completeness: membership.completeness,
400
+ freshness: this.freshnessValue,
401
+ };
402
+ }
403
+ /** Rows and protocol-owned completeness for one Replica Collection window. */
404
+ collectionState(signature) {
405
+ const result = this.liveQuery(signature);
406
+ const window = this.scopeLoaded ? this.liveQueries.get(signature) : undefined;
407
+ return {
408
+ ...result,
409
+ truncated: window?.truncated === true,
410
+ computedRevision: window?.cursor?.revision ?? window?.subscriptionRevision?.sequence ?? 0,
411
+ };
412
+ }
413
+ hasLiveQuery(signature) {
414
+ return this.scopeLoaded && this.liveQueries.has(signature);
415
+ }
416
+ snapshot() {
417
+ if (!this.scopeLoaded)
418
+ return { entities: {}, liveQueries: {} };
419
+ return snapshotFrom(this.cursorValue, this.entities, this.liveQueries);
420
+ }
421
+ reconcileCommands(notify = true) {
422
+ const revision = this.cursorValue?.revision ?? 0;
423
+ let changed = false;
424
+ for (const [commandId, command] of this.pendingCommands) {
425
+ if (command.committedRevision && revision >= command.committedRevision) {
426
+ this.pendingCommands.delete(commandId);
427
+ changed = true;
428
+ }
429
+ }
430
+ if (changed && notify)
431
+ this.notify();
432
+ }
433
+ persist(operation) {
434
+ const attempt = this.persistence.then(async () => { await operation(); });
435
+ this.persistence = attempt.catch(() => undefined);
436
+ return attempt;
437
+ }
438
+ notify() {
439
+ this.versionValue += 1;
440
+ for (const listener of [...this.listeners])
441
+ listener();
442
+ }
443
+ trackWindowOwnership(window, rows, previous) {
444
+ const owned = this.windowOwned.get(window.signature) ?? new Map();
445
+ const oldIDs = new Set(previous?.ids ?? []);
446
+ const newIDs = new Set(window.ids);
447
+ for (const id of oldIDs) {
448
+ if (!newIDs.has(id))
449
+ owned.delete(id);
450
+ }
451
+ for (const row of rows) {
452
+ const rawID = row[window.key];
453
+ const id = typeof rawID === "string" || typeof rawID === "number" ? String(rawID) : "";
454
+ if (!id)
455
+ continue;
456
+ const owners = owned.get(id) ?? new Set();
457
+ owners.add(window.signature);
458
+ owned.set(id, owners);
459
+ }
460
+ this.windowOwned.set(window.signature, owned);
461
+ }
462
+ pruneOwnedEntities(signature) {
463
+ const owned = this.windowOwned.get(signature);
464
+ if (!owned)
465
+ return;
466
+ const sourceWindow = this.liveQueries.get(signature);
467
+ for (const [id] of owned) {
468
+ const stillReferenced = [...this.liveQueries.values()].some((window) => (window.entity === sourceWindow?.entity && window.ids.includes(id)));
469
+ if (!stillReferenced && sourceWindow) {
470
+ this.entities.get(sourceWindow.entity)?.delete(id);
471
+ }
472
+ }
473
+ this.windowOwned.delete(signature);
474
+ }
475
+ pruneOwnedEntitiesAfterRemoval(signature, remaining) {
476
+ const owned = this.windowOwned.get(signature);
477
+ if (!owned)
478
+ return;
479
+ const removed = [...owned.keys()];
480
+ for (const id of removed) {
481
+ const stillReferenced = [...remaining.values()].some((window) => window.ids.includes(id));
482
+ if (stillReferenced)
483
+ continue;
484
+ // The removed window's entity cannot be recovered from the map after the
485
+ // removal. Keep the row conservatively rather than risk deleting a row
486
+ // populated by a transaction or another entity projection.
487
+ }
488
+ this.windowOwned.delete(signature);
489
+ }
490
+ }
491
+ export class MemoryLocalReplicaStorage {
492
+ values = new Map();
493
+ async load(scope = defaultReplicaScope) {
494
+ const value = this.values.get(normalizeReplicaScope(scope));
495
+ return value ? cloneSnapshot(value) : undefined;
496
+ }
497
+ async applyTransaction(_transaction, snapshot, scope = defaultReplicaScope) {
498
+ this.values.set(normalizeReplicaScope(scope), cloneSnapshot(snapshot));
499
+ }
500
+ async replaceSnapshot(snapshot, scope = defaultReplicaScope) {
501
+ this.values.set(normalizeReplicaScope(scope), cloneSnapshot(snapshot));
502
+ }
503
+ async replaceWindow(_window, snapshot, scope = defaultReplicaScope) {
504
+ this.values.set(normalizeReplicaScope(scope), cloneSnapshot(snapshot));
505
+ }
506
+ async applyWindowDelta(_window, _delta, snapshot, scope = defaultReplicaScope) {
507
+ this.values.set(normalizeReplicaScope(scope), cloneSnapshot(snapshot));
508
+ }
509
+ async removeWindow(_signature, snapshot, scope = defaultReplicaScope) {
510
+ this.values.set(normalizeReplicaScope(scope), cloneSnapshot(snapshot));
511
+ }
512
+ async clear(scope = defaultReplicaScope) {
513
+ this.values.delete(normalizeReplicaScope(scope));
514
+ }
515
+ }
516
+ function validateTransaction(transaction) {
517
+ if (!transaction.cursor.epoch.trim() || transaction.cursor.revision <= 0) {
518
+ throw new Error("replica transaction requires a positive revision and epoch");
519
+ }
520
+ for (const change of transaction.changes) {
521
+ if (!change.entity.trim() || !change.id.trim())
522
+ throw new Error("replica change requires entity and id");
523
+ if (change.operation !== "delete" && !change.newValue)
524
+ throw new Error("replica upsert requires newValue");
525
+ }
526
+ }
527
+ function cloneOptimisticPatch(patch) {
528
+ if (patch.op === "delete")
529
+ return { ...patch };
530
+ if (patch.op === "insert")
531
+ return { ...patch, fields: structuredClone(patch.fields) };
532
+ return { ...patch, fields: structuredClone(patch.fields) };
533
+ }
534
+ function cloneRow(row) { return structuredClone(row); }
535
+ function windowResultMetadata(result, resultPath) {
536
+ if (!result || typeof result !== "object" || Array.isArray(result) || !resultPath?.length)
537
+ return {};
538
+ let current = result;
539
+ for (const part of resultPath.slice(0, -1)) {
540
+ if (typeof current !== "object" || current === null || Array.isArray(current))
541
+ return {};
542
+ current = current[part];
543
+ }
544
+ if (typeof current !== "object" || current === null || Array.isArray(current))
545
+ return {};
546
+ const record = current;
547
+ const metadata = {};
548
+ if (typeof record.total === "number" && Number.isSafeInteger(record.total) && record.total >= 0)
549
+ metadata.total = record.total;
550
+ if (typeof record.offset === "number" && Number.isSafeInteger(record.offset) && record.offset >= 0)
551
+ metadata.offset = record.offset;
552
+ if (typeof record.limit === "number" && Number.isSafeInteger(record.limit) && record.limit >= 0)
553
+ metadata.limit = record.limit;
554
+ return metadata;
555
+ }
556
+ function normalizeWindow(value) {
557
+ return {
558
+ ...value,
559
+ kind: value.kind ?? "live",
560
+ key: value.key ?? "id",
561
+ ids: [...value.ids],
562
+ cursor: value.cursor ? { ...value.cursor } : undefined,
563
+ resultPath: value.resultPath ? [...value.resultPath] : undefined,
564
+ subscriptionRevision: value.subscriptionRevision ? { ...value.subscriptionRevision } : undefined,
565
+ hashes: value.hashes ? { ...value.hashes } : undefined,
566
+ };
567
+ }
568
+ function cloneWindow(value) { return normalizeWindow(value); }
569
+ function cloneEntities(source) {
570
+ return new Map([...source].map(([entity, rows]) => [entity, new Map([...rows].map(([id, row]) => [id, cloneRow(row)]))]));
571
+ }
572
+ function entitiesFromSnapshot(source) {
573
+ return new Map(Object.entries(source).map(([entity, rows]) => [entity, new Map(Object.entries(rows).map(([id, row]) => [id, cloneRow(row)]))]));
574
+ }
575
+ function snapshotFrom(cursor, entities, liveQueries) {
576
+ return {
577
+ cursor: cursor ? { ...cursor } : undefined,
578
+ entities: Object.fromEntries([...entities].map(([entity, rows]) => [entity, Object.fromEntries([...rows].map(([id, row]) => [id, cloneRow(row)]))])),
579
+ liveQueries: Object.fromEntries([...liveQueries].map(([key, value]) => [key, cloneWindow(value)])),
580
+ };
581
+ }
582
+ function cloneSnapshot(value) {
583
+ return snapshotFrom(value.cursor, entitiesFromSnapshot(value.entities), new Map(Object.entries(value.liveQueries).map(([key, window]) => [key, normalizeWindow(window)])));
584
+ }
585
+ function normalizeReplicaScope(scope) {
586
+ if (typeof scope !== "string" || !scope.trim())
587
+ return defaultReplicaScope;
588
+ return scope;
589
+ }
590
+ //# sourceMappingURL=local-replica.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-replica.js","sourceRoot":"","sources":["../src/local-replica.ts"],"names":[],"mappings":"AAqDA,MAAM,mBAAmB,GAAiB,SAAS,CAAC;AA6EpD,MAAM,OAAO,YAAY;IAsBM;IArBrB,WAAW,CAAiB;IAC5B,QAAQ,GAAG,IAAI,GAAG,EAAmC,CAAC;IACtD,WAAW,GAAG,IAAI,GAAG,EAAyB,CAAC;IACvD,gFAAgF;IAC/D,WAAW,GAAG,IAAI,GAAG,EAAoC,CAAC;IACnE,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;IACpD,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAClC,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,SAAS,CAAiB;IAC1B,cAAc,GAAqB,WAAW,CAAC;IAC/C,YAAY,GAAG,CAAC,CAAC;IACjB,UAAU,GAAiB,mBAAmB,CAAC;IACvD,2EAA2E;IAC3E,uEAAuE;IACvE,sEAAsE;IAC9D,WAAW,GAAG,IAAI,CAAC;IACnB,eAAe,CAAiB;IAChC,mBAAmB,CAAgB;IACnC,yBAAyB,GAAG,CAAC,CAAC;IAEtC,YAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAs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