@gonvex/client 0.1.32 → 0.3.1

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 +125 -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 +176 -133
  9. package/dist/index.js +1177 -1140
  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 +2 -48
  15. package/dist/kv-stores.js +24 -411
  16. package/dist/kv-stores.js.map +1 -1
  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 +25 -25
  24. package/dist/outbox.js +27 -27
  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,193 @@
1
+ import { Dexie } from "dexie";
2
+ const defaultReplicaScope = "default";
3
+ const replicaSchemaVersion = 3;
4
+ /** Atomic normalized web persistence for the Gonvex Local Replica. */
5
+ export class IndexedDBLocalReplicaStorage {
6
+ database;
7
+ initialized;
8
+ constructor(name = "gonvex-local-replica") {
9
+ this.database = new Dexie(name);
10
+ this.database.version(1).stores({ snapshots: "&key" });
11
+ this.database.version(2).stores({ snapshots: "&scope" }).upgrade(async (transaction) => {
12
+ await transaction.table("snapshots").toCollection().modify((record) => {
13
+ record.scope = defaultReplicaScope;
14
+ delete record.key;
15
+ });
16
+ });
17
+ this.database.version(replicaSchemaVersion).stores({
18
+ entities: "[scope+entity+id], scope, [scope+entity]",
19
+ windows: "[scope+signature], scope",
20
+ meta: "[scope+key], scope",
21
+ // Retain the old table only as a one-time upgrade source. It is never
22
+ // read after initialization and is removed from the active schema.
23
+ snapshots: "&scope",
24
+ }).upgrade(async (transaction) => {
25
+ const snapshots = await transaction.table("snapshots").toArray();
26
+ const entities = transaction.table("entities");
27
+ const windows = transaction.table("windows");
28
+ const meta = transaction.table("meta");
29
+ for (const record of snapshots) {
30
+ const scope = record.scope ?? defaultReplicaScope;
31
+ const snapshot = record.snapshot;
32
+ for (const [entity, rows] of Object.entries(snapshot.entities ?? {})) {
33
+ for (const [id, value] of Object.entries(rows)) {
34
+ await entities.put({ scope, entity, id, value: JSON.stringify(value) });
35
+ }
36
+ }
37
+ for (const [signature, window] of Object.entries(snapshot.liveQueries ?? {})) {
38
+ await windows.put({ scope, signature, value: JSON.stringify(window) });
39
+ }
40
+ if (snapshot.cursor) {
41
+ await meta.put({ scope, key: "cursor", value: JSON.stringify(snapshot.cursor) });
42
+ }
43
+ }
44
+ // The upgrade transaction is atomic: only remove the legacy full
45
+ // snapshots after every entity/window/cursor has been copied into the
46
+ // normalized stores. Keeping the source rows would retain a second,
47
+ // row-bearing server-state store indefinitely.
48
+ await transaction.table("snapshots").clear();
49
+ });
50
+ }
51
+ initialize() {
52
+ return this.initialized ??= this.database.open().then(() => undefined);
53
+ }
54
+ async load(scope = defaultReplicaScope) {
55
+ await this.initialize();
56
+ const normalizedScope = normalizeScope(scope);
57
+ const [entityRecords, windowRecords, cursor] = await Promise.all([
58
+ this.database.entities.where("scope").equals(normalizedScope).toArray(),
59
+ this.database.windows.where("scope").equals(normalizedScope).toArray(),
60
+ this.database.meta.get([normalizedScope, "cursor"]),
61
+ ]);
62
+ if (entityRecords.length === 0 && windowRecords.length === 0 && !cursor)
63
+ return undefined;
64
+ const entities = {};
65
+ for (const record of entityRecords)
66
+ (entities[record.entity] ??= {})[record.id] = JSON.parse(record.value);
67
+ const liveQueries = {};
68
+ for (const record of windowRecords)
69
+ liveQueries[record.signature] = JSON.parse(record.value);
70
+ return {
71
+ cursor: cursor ? JSON.parse(cursor.value) : undefined,
72
+ entities,
73
+ liveQueries,
74
+ };
75
+ }
76
+ async applyTransaction(transaction, _snapshot, scope = defaultReplicaScope) {
77
+ await this.initialize();
78
+ const normalizedScope = normalizeScope(scope);
79
+ await this.database.transaction("rw", this.database.entities, this.database.windows, this.database.meta, async () => {
80
+ const previous = await this.database.meta.get([normalizedScope, "cursor"]);
81
+ if (previous && JSON.parse(previous.value).epoch !== transaction.cursor.epoch) {
82
+ await this.database.entities.where("scope").equals(normalizedScope).delete();
83
+ await this.database.windows.where("scope").equals(normalizedScope).delete();
84
+ }
85
+ for (const change of transaction.changes) {
86
+ if (change.operation === "delete") {
87
+ await this.database.entities.delete([normalizedScope, change.entity, change.id]);
88
+ const windows = await this.database.windows.where("scope").equals(normalizedScope).toArray();
89
+ for (const record of windows) {
90
+ const window = JSON.parse(record.value);
91
+ if (!window.ids.includes(change.id))
92
+ continue;
93
+ window.ids = window.ids.filter((id) => id !== change.id);
94
+ await this.database.windows.put({ ...record, value: JSON.stringify(window) });
95
+ }
96
+ }
97
+ else if (change.newValue) {
98
+ await this.database.entities.put({
99
+ scope: normalizedScope,
100
+ entity: change.entity,
101
+ id: change.id,
102
+ value: JSON.stringify(change.newValue),
103
+ });
104
+ }
105
+ }
106
+ for (const membership of transaction.memberships ?? []) {
107
+ await this.database.windows.put({
108
+ scope: normalizedScope,
109
+ signature: membership.signature,
110
+ value: JSON.stringify(normalizeWindow(membership)),
111
+ });
112
+ }
113
+ await this.database.meta.put({ scope: normalizedScope, key: "cursor", value: JSON.stringify(transaction.cursor) });
114
+ });
115
+ }
116
+ async replaceWindow(window, snapshot, scope = defaultReplicaScope) {
117
+ await this.initialize();
118
+ const normalizedScope = normalizeScope(scope);
119
+ await this.database.transaction("rw", this.database.entities, this.database.windows, this.database.meta, async () => {
120
+ for (const [entity, rows] of Object.entries(snapshot.entities)) {
121
+ for (const [id, value] of Object.entries(rows)) {
122
+ await this.database.entities.put({ scope: normalizedScope, entity, id, value: JSON.stringify(value) });
123
+ }
124
+ }
125
+ await this.database.windows.put({ scope: normalizedScope, signature: window.signature, value: JSON.stringify(normalizeWindow(window)) });
126
+ if (snapshot.cursor)
127
+ await this.database.meta.put({ scope: normalizedScope, key: "cursor", value: JSON.stringify(snapshot.cursor) });
128
+ });
129
+ }
130
+ async applyWindowDelta(window, _delta, snapshot, scope = defaultReplicaScope) {
131
+ // The in-memory replica has already computed the normalized result. The
132
+ // storage transaction receives that result and persists it atomically;
133
+ // retaining unrelated entities is deliberate and conservative.
134
+ await this.replaceWindow(window, snapshot, scope);
135
+ }
136
+ async removeWindow(signature, snapshot, scope = defaultReplicaScope) {
137
+ await this.initialize();
138
+ const normalizedScope = normalizeScope(scope);
139
+ await this.database.transaction("rw", this.database.windows, this.database.meta, async () => {
140
+ await this.database.windows.delete([normalizedScope, signature]);
141
+ if (snapshot.cursor)
142
+ await this.database.meta.put({ scope: normalizedScope, key: "cursor", value: JSON.stringify(snapshot.cursor) });
143
+ });
144
+ }
145
+ async replaceSnapshot(snapshot, scope = defaultReplicaScope) {
146
+ await this.initialize();
147
+ const normalizedScope = normalizeScope(scope);
148
+ await this.database.transaction("rw", this.database.entities, this.database.windows, this.database.meta, async () => {
149
+ await this.database.entities.where("scope").equals(normalizedScope).delete();
150
+ await this.database.windows.where("scope").equals(normalizedScope).delete();
151
+ await this.database.meta.delete([normalizedScope, "cursor"]);
152
+ for (const [entity, rows] of Object.entries(snapshot.entities)) {
153
+ for (const [id, value] of Object.entries(rows)) {
154
+ await this.database.entities.put({ scope: normalizedScope, entity, id, value: JSON.stringify(value) });
155
+ }
156
+ }
157
+ for (const [signature, window] of Object.entries(snapshot.liveQueries)) {
158
+ await this.database.windows.put({ scope: normalizedScope, signature, value: JSON.stringify(normalizeWindow(window)) });
159
+ }
160
+ if (snapshot.cursor)
161
+ await this.database.meta.put({ scope: normalizedScope, key: "cursor", value: JSON.stringify(snapshot.cursor) });
162
+ });
163
+ }
164
+ async clear(scope = defaultReplicaScope) {
165
+ await this.initialize();
166
+ const normalizedScope = normalizeScope(scope);
167
+ await this.database.transaction("rw", this.database.entities, this.database.windows, this.database.meta, async () => {
168
+ await this.database.entities.where("scope").equals(normalizedScope).delete();
169
+ await this.database.windows.where("scope").equals(normalizedScope).delete();
170
+ await this.database.meta.where("scope").equals(normalizedScope).delete();
171
+ });
172
+ }
173
+ close() {
174
+ this.database.close();
175
+ }
176
+ }
177
+ export function indexedDBLocalReplica(name) {
178
+ return new IndexedDBLocalReplicaStorage(name);
179
+ }
180
+ function normalizeScope(scope) {
181
+ return typeof scope === "string" && scope.trim() ? scope : defaultReplicaScope;
182
+ }
183
+ function normalizeWindow(value) {
184
+ return {
185
+ ...value,
186
+ kind: value.kind ?? "live",
187
+ key: value.key ?? "id",
188
+ ids: [...value.ids],
189
+ resultPath: value.resultPath ? [...value.resultPath] : undefined,
190
+ hashes: value.hashes ? { ...value.hashes } : undefined,
191
+ };
192
+ }
193
+ //# sourceMappingURL=indexeddb-replica.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexeddb-replica.js","sourceRoot":"","sources":["../src/indexeddb-replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,OAAO,CAAC;AAqB1C,MAAM,mBAAmB,GAAiB,SAAS,CAAC;AACpD,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B,sEAAsE;AACtE,MAAM,OAAO,4BAA4B;IACtB,QAAQ,CAAkB;IACnC,WAAW,CAAiB;IAEpC,YAAY,IAAI,GAAG,sBAAsB;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,CAAC,IAAI,CAAoB,CAAC;QACnD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YACrF,MAAM,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,MAA+C,EAAE,EAAE;gBAC7G,MAAM,CAAC,KAAK,GAAG,mBAAmB,CAAC;gBACnC,OAAO,MAAM,CAAC,G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I,IAAI,MAAM;QAC1B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,IAAI;QACtB,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;QACnB,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;QAChE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;KACvD,CAAC;AACJ,CAAC"}
@@ -1,14 +1,5 @@
1
1
  import type { OutboxStore } from "./outbox.js";
2
- import { type QueryCacheStore } from "./query-cache.js";
3
- import { type SyncStore } from "./sync-store.js";
4
- /**
5
- * Injectable Gonvex persistence over a tiny key-value backend.
6
- *
7
- * The client defaults to Dexie/IndexedDB. React Native has neither, so these
8
- * factories implement {@link QueryCacheStore}, {@link SyncStore}, and
9
- * {@link OutboxStore} against a five-method string store the host binds once —
10
- * an expo-sqlite table in production, {@link createMemoryGonvexKv} in tests.
11
- */
2
+ /** Minimal host persistence boundary used by the reducer outbox and adapters. */
12
3
  export type GonvexKv = {
13
4
  get(table: string, key: string): Promise<string | undefined>;
14
5
  set(table: string, key: string, value: string): Promise<void>;
@@ -19,43 +10,6 @@ export type GonvexKv = {
19
10
  }>>;
20
11
  clear(table: string, keyPrefix?: string): Promise<void>;
21
12
  };
22
- export declare const kvQueryCacheTable = "query_cache";
23
- export declare const kvSyncCollectionTable = "sync_collections";
24
- export declare const kvSyncDirectiveTable = "sync_directives";
25
- export declare const kvMutationOutboxTable = "mutation_outbox";
26
- /** An in-memory {@link GonvexKv} for tests and ephemeral sessions. */
13
+ export declare const kvReducerOutboxTable = "reducer_outbox";
27
14
  export declare function createMemoryGonvexKv(): GonvexKv;
28
- export type KvQueryCacheStoreOptions = {
29
- maxAgeMs?: number;
30
- maxEntryBytes?: number;
31
- maxEntriesPerScope?: number;
32
- maxBytesPerScope?: number;
33
- maxBytes?: number;
34
- /** Invoked whenever a write lands under a scope not seen since the last one. */
35
- onScope?: (scope: string) => void | Promise<void>;
36
- };
37
- /**
38
- * A {@link QueryCacheStore} over an injected {@link GonvexKv}. Records are
39
- * keyed by `scope\u0000path\u0000stableArgs`, revision-guarded like the Dexie
40
- * store, and LRU-evicted by `lastAccessedAt` against per-scope and global
41
- * caps. A failing backend permanently disables the cache for the session;
42
- * server data remains authoritative.
43
- */
44
- export declare function createKvQueryCacheStore(kv: GonvexKv, options?: KvQueryCacheStoreOptions): QueryCacheStore;
45
- export type KvSyncStoreOptions = {
46
- maxBytes?: number;
47
- };
48
- /**
49
- * A {@link SyncStore} over an injected {@link GonvexKv}. Each collection is
50
- * one record holding its rows, cursor, and metadata; deltas are applied by
51
- * key against the stored rows. Collections are LRU-evicted by
52
- * `lastAccessedAt` once the table exceeds `maxBytes`. A failing backend
53
- * permanently disables the store for the session.
54
- */
55
- export declare function createKvSyncStore(kv: GonvexKv, options?: KvSyncStoreOptions): SyncStore;
56
- /**
57
- * An {@link OutboxStore} over an injected {@link GonvexKv}. Entries are
58
- * whole JSON records keyed by their queue id; ordering, causal barriers, and
59
- * inflight recovery stay in {@link StoreMutationOutbox}.
60
- */
61
15
  export declare function createKvOutboxStore(kv: GonvexKv): OutboxStore;