@terreno/syncdb 57.3.0 → 57.6.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.
- package/README.md +3 -3
- package/dist/auth/betterAuthAdapter.js +1 -1
- package/dist/auth/betterAuthAdapter.js.map +1 -1
- package/dist/auth/betterAuthReactClient.d.ts +17 -0
- package/dist/auth/betterAuthReactClient.d.ts.map +1 -0
- package/dist/auth/betterAuthReactClient.js +11 -0
- package/dist/auth/betterAuthReactClient.js.map +1 -0
- package/dist/auth/betterAuthReactClient.test.d.ts +2 -0
- package/dist/auth/betterAuthReactClient.test.d.ts.map +1 -0
- package/dist/auth/betterAuthReactClient.test.js +43 -0
- package/dist/auth/betterAuthReactClient.test.js.map +1 -0
- package/dist/client.adminWindowMutation.test.d.ts +2 -0
- package/dist/client.adminWindowMutation.test.d.ts.map +1 -0
- package/dist/client.adminWindowMutation.test.js +65 -0
- package/dist/client.adminWindowMutation.test.js.map +1 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +89 -12
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +308 -12
- package/dist/client.test.js.map +1 -1
- package/dist/codegen/emitSdk.js +3 -3
- package/dist/codegen/emitSdk.js.map +1 -1
- package/dist/codegen/generate.test.js +32 -2
- package/dist/codegen/generate.test.js.map +1 -1
- package/dist/codegen/safeIdentifiers.d.ts +5 -0
- package/dist/codegen/safeIdentifiers.d.ts.map +1 -1
- package/dist/codegen/safeIdentifiers.js +8 -0
- package/dist/codegen/safeIdentifiers.js.map +1 -1
- package/dist/codegen/safeIdentifiers.test.js +20 -8
- package/dist/codegen/safeIdentifiers.test.js.map +1 -1
- package/dist/codegen/types.d.ts +4 -3
- package/dist/codegen/types.d.ts.map +1 -1
- package/dist/crypto/keyProviders.js +1 -1
- package/dist/crypto/keyProviders.js.map +1 -1
- package/dist/debug/debugChannel.test.js +5 -0
- package/dist/debug/debugChannel.test.js.map +1 -1
- package/dist/debug/debugLog.d.ts +1 -0
- package/dist/debug/debugLog.d.ts.map +1 -1
- package/dist/debug/debugLog.js +1 -0
- package/dist/debug/debugLog.js.map +1 -1
- package/dist/debug/devtools.d.ts +6 -0
- package/dist/debug/devtools.d.ts.map +1 -0
- package/dist/debug/devtools.js +111 -0
- package/dist/debug/devtools.js.map +1 -0
- package/dist/debug/devtools.test.d.ts +2 -0
- package/dist/debug/devtools.test.d.ts.map +1 -0
- package/dist/debug/devtools.test.js +168 -0
- package/dist/debug/devtools.test.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.d.ts +2 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.d.ts.map +1 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.js +19 -0
- package/dist/isolated/defaultPersisterFactoryNativeErrors.isolated.js.map +1 -0
- package/dist/mutations/outbox.d.ts +7 -3
- package/dist/mutations/outbox.d.ts.map +1 -1
- package/dist/mutations/outbox.js +6 -0
- package/dist/mutations/outbox.js.map +1 -1
- package/dist/mutations/outbox.test.js +17 -0
- package/dist/mutations/outbox.test.js.map +1 -1
- package/dist/react/collectionHooks.js +2 -2
- package/dist/react/collectionHooks.js.map +1 -1
- package/dist/storage/idb.d.ts +1 -0
- package/dist/storage/idb.d.ts.map +1 -1
- package/dist/storage/idb.js +1 -0
- package/dist/storage/idb.js.map +1 -1
- package/dist/storage/schema.d.ts.map +1 -1
- package/dist/storage/schema.js +1 -0
- package/dist/storage/schema.js.map +1 -1
- package/dist/storage/store.d.ts +3 -2
- package/dist/storage/store.d.ts.map +1 -1
- package/dist/storage/store.test.js +6 -6
- package/dist/storage/store.test.js.map +1 -1
- package/dist/storage/types.d.ts +1 -7
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/sync/deltaApplier.d.ts +2 -0
- package/dist/sync/deltaApplier.d.ts.map +1 -1
- package/dist/sync/deltaApplier.js +9 -0
- package/dist/sync/deltaApplier.js.map +1 -1
- package/dist/sync/deltaApplier.test.js +63 -0
- package/dist/sync/deltaApplier.test.js.map +1 -1
- package/dist/sync/entityRepair.d.ts +1 -0
- package/dist/sync/entityRepair.d.ts.map +1 -1
- package/dist/sync/entityRepair.js +1 -0
- package/dist/sync/entityRepair.js.map +1 -1
- package/dist/sync/httpChannel.d.ts +3 -1
- package/dist/sync/httpChannel.d.ts.map +1 -1
- package/dist/sync/httpChannel.js +3 -1
- package/dist/sync/httpChannel.js.map +1 -1
- package/dist/sync/httpChannel.test.js +68 -0
- package/dist/sync/httpChannel.test.js.map +1 -1
- package/dist/sync/replayCoordinator.d.ts +6 -12
- package/dist/sync/replayCoordinator.d.ts.map +1 -1
- package/dist/sync/replayCoordinator.js +44 -16
- package/dist/sync/replayCoordinator.js.map +1 -1
- package/dist/sync/replayCoordinator.test.js +29 -10
- package/dist/sync/replayCoordinator.test.js.map +1 -1
- package/dist/sync/socketTransport.d.ts +3 -45
- package/dist/sync/socketTransport.d.ts.map +1 -1
- package/dist/sync/socketTransport.js +73 -9
- package/dist/sync/socketTransport.js.map +1 -1
- package/dist/sync/socketTransport.test.js +41 -1
- package/dist/sync/socketTransport.test.js.map +1 -1
- package/dist/sync/transport.d.ts +9 -1
- package/dist/sync/transport.d.ts.map +1 -1
- package/dist/sync/transport.js +1 -1
- package/dist/sync/transport.js.map +1 -1
- package/dist/sync/windowHydrate.d.ts +25 -0
- package/dist/sync/windowHydrate.d.ts.map +1 -0
- package/dist/sync/windowHydrate.js +67 -0
- package/dist/sync/windowHydrate.js.map +1 -0
- package/dist/sync/windowHydrate.test.d.ts +2 -0
- package/dist/sync/windowHydrate.test.d.ts.map +1 -0
- package/dist/sync/windowHydrate.test.js +164 -0
- package/dist/sync/windowHydrate.test.js.map +1 -0
- package/dist/testing/fakeTransport.js +1 -1
- package/dist/testing/fakeTransport.js.map +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -4
- package/src/auth/betterAuthReactClient.test.ts +50 -0
- package/src/auth/betterAuthReactClient.ts +33 -0
- package/src/client.adminWindowMutation.test.ts +69 -0
- package/src/client.test.ts +321 -3
- package/src/client.ts +125 -8
- package/src/codegen/emitSdk.ts +3 -3
- package/src/codegen/generate.test.ts +35 -2
- package/src/codegen/safeIdentifiers.test.ts +37 -10
- package/src/codegen/safeIdentifiers.ts +17 -0
- package/src/codegen/types.ts +3 -3
- package/src/debug/debugChannel.test.ts +6 -0
- package/src/debug/debugLog.ts +1 -0
- package/src/debug/devtools.test.ts +234 -0
- package/src/debug/devtools.ts +196 -0
- package/src/index.ts +4 -0
- package/src/isolated/defaultPersisterFactoryNativeErrors.isolated.ts +23 -0
- package/src/mutations/outbox.test.ts +20 -0
- package/src/mutations/outbox.ts +11 -3
- package/src/react/collectionHooks.ts +2 -2
- package/src/storage/idb.ts +1 -0
- package/src/storage/schema.ts +1 -0
- package/src/storage/store.ts +2 -2
- package/src/storage/types.ts +1 -8
- package/src/sync/deltaApplier.test.ts +70 -0
- package/src/sync/deltaApplier.ts +10 -0
- package/src/sync/entityRepair.ts +1 -0
- package/src/sync/httpChannel.test.ts +82 -0
- package/src/sync/httpChannel.ts +5 -0
- package/src/sync/replayCoordinator.test.ts +28 -0
- package/src/sync/replayCoordinator.ts +53 -14
- package/src/sync/socketTransport.test.ts +45 -2
- package/src/sync/socketTransport.ts +106 -20
- package/src/sync/transport.ts +7 -1
- package/src/sync/windowHydrate.test.ts +179 -0
- package/src/sync/windowHydrate.ts +97 -0
- package/src/testing/fakeTransport.ts +1 -1
- package/src/types.ts +16 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Local-first data layer for @terreno apps: TinyBase MergeableStore, durable outbox, websocket delta sync, encrypted web persistence.
|
|
4
4
|
|
|
5
|
-
Local-first data layer for Terreno apps. A TinyBase `MergeableStore` (encrypted IndexedDB on web, expo-sqlite on native) is the UI's source of truth: reads come from the local store, writes apply optimistically and enqueue in a durable outbox, and the server reconciles asynchronously over a socket delta protocol with HTTP snapshot catch-up. Every mutation executes the existing `@terreno/api` modelRouter write path — identical permissions, hooks, and validation as REST. Supersedes `@terreno/rtk` for data-synchronization concerns (see [the migration guide](https://github.com/
|
|
5
|
+
Local-first data layer for Terreno apps. A TinyBase `MergeableStore` (encrypted IndexedDB on web, expo-sqlite on native) is the UI's source of truth: reads come from the local store, writes apply optimistically and enqueue in a durable outbox, and the server reconciles asynchronously over a socket delta protocol with HTTP snapshot catch-up. Every mutation executes the existing `@terreno/api` modelRouter write path — identical permissions, hooks, and validation as REST. Supersedes `@terreno/rtk` for data-synchronization concerns (see [the migration guide](https://github.com/TerrenoLabs/terreno/blob/master/docs/how-to/migrate-rtk-to-syncdb.md)).
|
|
6
6
|
|
|
7
7
|
## Architecture
|
|
8
8
|
|
|
@@ -455,8 +455,8 @@ This writes `store/syncDbSdk.ts` with `SYNC_COLLECTIONS`, entity types, and hook
|
|
|
455
455
|
|
|
456
456
|
## Documentation
|
|
457
457
|
|
|
458
|
-
Full API reference: [docs/reference/syncdb.md](https://github.com/
|
|
458
|
+
Full API reference: [docs/reference/syncdb.md](https://github.com/TerrenoLabs/terreno/blob/master/docs/reference/syncdb.md)
|
|
459
459
|
|
|
460
460
|
## License and Contributing
|
|
461
461
|
|
|
462
|
-
Licensed under the [MIT License](https://github.com/
|
|
462
|
+
Licensed under the [MIT License](https://github.com/TerrenoLabs/terreno/blob/master/LICENSE). See [CONTRIBUTING.md](https://github.com/TerrenoLabs/terreno/blob/master/CONTRIBUTING.md) for contribution guidelines.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Default polling cadence when the client exposes no session subscription. */
|
|
2
|
-
export const DEFAULT_AUTH_POLL_INTERVAL_MS =
|
|
2
|
+
export const DEFAULT_AUTH_POLL_INTERVAL_MS = 5_000;
|
|
3
3
|
/**
|
|
4
4
|
* Unwrap `getSession()` results: Better Auth returns a `{data}` envelope, some
|
|
5
5
|
* wrappers return the payload directly, and signed-out states are null-ish.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"betterAuthAdapter.js","sourceRoot":"","sources":["../../src/auth/betterAuthAdapter.ts"],"names":[],"mappings":"AAGA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,6BAA6B,GAAG,
|
|
1
|
+
{"version":3,"file":"betterAuthAdapter.js","sourceRoot":"","sources":["../../src/auth/betterAuthAdapter.ts"],"names":[],"mappings":"AAGA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAWnD;;;GAGG;AACH,MAAM,aAAa,GAAG,CAAC,MAAe,EAAoC,EAAE;IAC1E,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,MAAM,IAAI,GAAI,MAAoD,CAAC,IAAI,CAAC;QACxE,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,CAAC;IACD,OAAO,MAAmC,CAAC;AAC7C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,UAAgC,EAChC,UAAoC,EAAE,EACxB,EAAE;IAChB,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,6BAA6B,CAAC;IAC/E,MAAM,aAAa,GACjB,OAAO,CAAC,aAAa;QACrB,CAAC,CAAC,OAAmB,EAAE,EAAU,EAAW,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3E,MAAM,eAAe,GACnB,OAAO,CAAC,eAAe;QACvB,CAAC,CAAC,MAAe,EAAQ,EAAE,CAAC,aAA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c;oBACd,OAAO;gBACT,CAAC;gBACD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;oBAC1B,OAAO,GAAG,GAAG,CAAC;oBACd,OAAO;gBACT,CAAC;gBACD,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;oBACpB,OAAO,GAAG,GAAG,CAAC;oBACd,QAAQ,EAAE,CAAC;gBACb,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,cAAc,CAAC,CAAC;QACnB,OAAO,GAAG,EAAE;YACV,QAAQ,GAAG,IAAI,CAAC;YAChB,eAAe,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAC,CAAC;AACtD,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BetterAuthClientLike, BetterAuthGetSessionResult } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* The Better Auth *react* client delivers session changes through a nanostore atom
|
|
4
|
+
* (`$store.atoms.session`), but its `useSession` is a React hook, not the `.subscribe`
|
|
5
|
+
* surface {@link betterAuthAdapter} looks for. Without the bridge the adapter falls back to
|
|
6
|
+
* polling `getSession()`, producing constant `/api/auth/get-session` traffic.
|
|
7
|
+
*
|
|
8
|
+
* Returns a client the adapter can subscribe to, or a `getSession`-only client when the
|
|
9
|
+
* atom is missing (a future Better Auth client shape change), which keeps the polling
|
|
10
|
+
* fallback as the safety net.
|
|
11
|
+
*/
|
|
12
|
+
/** The only member of the Better Auth react client this bridge reads statically. */
|
|
13
|
+
export interface BetterAuthReactClientLike {
|
|
14
|
+
getSession: () => Promise<BetterAuthGetSessionResult>;
|
|
15
|
+
}
|
|
16
|
+
export declare const bridgeBetterAuthReactClient: (authClient: BetterAuthReactClientLike) => BetterAuthClientLike;
|
|
17
|
+
//# sourceMappingURL=betterAuthReactClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betterAuthReactClient.d.ts","sourceRoot":"","sources":["../../src/auth/betterAuthReactClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAE,0BAA0B,EAAC,MAAM,SAAS,CAAC;AAE9E;;;;;;;;;GASG;AACH,oFAAoF;AACpF,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,MAAM,OAAO,CAAC,0BAA0B,CAAC,CAAC;CACvD;AAMD,eAAO,MAAM,2BAA2B,GACtC,YAAY,yBAAyB,KACpC,oBASF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const bridgeBetterAuthReactClient = (authClient) => {
|
|
2
|
+
const sessionAtom = authClient
|
|
3
|
+
.$store?.atoms?.session;
|
|
4
|
+
return {
|
|
5
|
+
getSession: () => authClient.getSession(),
|
|
6
|
+
...(sessionAtom
|
|
7
|
+
? { useSession: { subscribe: (listener) => sessionAtom.subscribe(listener) } }
|
|
8
|
+
: {}),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=betterAuthReactClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betterAuthReactClient.js","sourceRoot":"","sources":["../../src/auth/betterAuthReactClient.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,UAAqC,EACf,EAAE;IACxB,MAAM,WAAW,GAAI,UAA0E;SAC5F,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC;IAC1B,OAAO;QACL,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE;QACzC,GAAG,CAAC,WAAW;YACb,CAAC,CAAC,EAAC,UAAU,EAAE,EAAC,SAAS,EAAE,CAAC,QAAQ,EAAgB,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAC,EAAC;YACxF,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betterAuthReactClient.test.d.ts","sourceRoot":"","sources":["../../src/auth/betterAuthReactClient.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, it } from "bun:test";
|
|
2
|
+
import { assert } from "chai";
|
|
3
|
+
import { bridgeBetterAuthReactClient } from "./betterAuthReactClient";
|
|
4
|
+
const sessionResult = { data: { session: { token: "token-1" }, user: { id: "user-1" } } };
|
|
5
|
+
describe("bridgeBetterAuthReactClient", () => {
|
|
6
|
+
it("exposes the session atom as a subscribe surface", async () => {
|
|
7
|
+
const listeners = [];
|
|
8
|
+
let unsubscribed = false;
|
|
9
|
+
const reactClient = {
|
|
10
|
+
$store: {
|
|
11
|
+
atoms: {
|
|
12
|
+
session: {
|
|
13
|
+
subscribe: (listener) => {
|
|
14
|
+
listeners.push(listener);
|
|
15
|
+
return () => {
|
|
16
|
+
unsubscribed = true;
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
getSession: async () => sessionResult,
|
|
23
|
+
};
|
|
24
|
+
const bridged = bridgeBetterAuthReactClient(reactClient);
|
|
25
|
+
assert.deepEqual(await bridged.getSession(), sessionResult);
|
|
26
|
+
assert.isFunction(bridged.useSession?.subscribe);
|
|
27
|
+
const received = [];
|
|
28
|
+
const unsubscribe = bridged.useSession?.subscribe?.((value) => {
|
|
29
|
+
received.push(value);
|
|
30
|
+
});
|
|
31
|
+
assert.equal(listeners.length, 1);
|
|
32
|
+
listeners[0]?.(sessionResult);
|
|
33
|
+
assert.deepEqual(received, [sessionResult]);
|
|
34
|
+
unsubscribe?.();
|
|
35
|
+
assert.isTrue(unsubscribed);
|
|
36
|
+
});
|
|
37
|
+
it("omits useSession when the client exposes no session atom", async () => {
|
|
38
|
+
const bridged = bridgeBetterAuthReactClient({ getSession: async () => sessionResult });
|
|
39
|
+
assert.isUndefined(bridged.useSession);
|
|
40
|
+
assert.deepEqual(await bridged.getSession(), sessionResult);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=betterAuthReactClient.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"betterAuthReactClient.test.js","sourceRoot":"","sources":["../../src/auth/betterAuthReactClient.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,EAAE,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAC,2BAA2B,EAAC,MAAM,yBAAyB,CAAC;AAEpE,MAAM,aAAa,GAAG,EAAC,IAAI,EAAE,EAAC,OAAO,EAAE,EAAC,KAAK,EAAE,SAAS,EAAC,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,QAAQ,EAAC,EAAC,EAAC,CAAC;AAElF,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/D,MAAM,SAAS,GAAoC,EAAE,CAAC;QACtD,IAAI,YAAY,GAAG,KAAK,CAAC;QACzB,MAAM,WAAW,GAAG;YAClB,MAAM,EAAE;gBACN,KAAK,EAAE;oBACL,OAAO,EAAE;wBACP,SAAS,EAAE,CAAC,QAAkC,EAAgB,EAAE;4BAC9D,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;4BACzB,OAAO,GAAS,EAAE;gCAChB,YAAY,GAAG,IAAI,CAAC;4BACtB,CAAC,CAAC;wBACJ,CAAC;qBACF;iBACF;aACF;YACD,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa;SACtC,CAAC;QAEF,MAAM,OAAO,GAAG,2BAA2B,CAAC,WAAW,CAAC,CAAC;QAEzD,MAAM,CAAC,SAAS,CAAC,MAAM,OAAO,CAAC,UAAU,EAAE,EAAE,aAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAEjD,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;YAC5D,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAClC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QAC9B,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;QAE5C,WAAW,EAAE,EAAE,CAAC;QAChB,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,OAAO,GAAG,2BAA2B,CAAC,EAAC,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,EAAC,CAAC,CAAC;QAErF,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACvC,MAAM,CAAC,SAAS,CAAC,MAAM,OAAO,CAAC,UAAU,EAAE,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.adminWindowMutation.test.d.ts","sourceRoot":"","sources":["../src/client.adminWindowMutation.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import { createSyncDb } from "./client";
|
|
3
|
+
import { createFakeTransport } from "./testing/fakeTransport";
|
|
4
|
+
const makeAuthProvider = (userId = "user-1") => {
|
|
5
|
+
const listeners = new Set();
|
|
6
|
+
const state = { userId };
|
|
7
|
+
return {
|
|
8
|
+
provider: {
|
|
9
|
+
getToken: async () => "token",
|
|
10
|
+
getUserId: async () => state.userId,
|
|
11
|
+
onAuthChange: (callback) => {
|
|
12
|
+
listeners.add(callback);
|
|
13
|
+
return () => {
|
|
14
|
+
listeners.delete(callback);
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
describe("createSyncDb admin-window mutation mode", () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
// no shared state
|
|
23
|
+
});
|
|
24
|
+
it("tags outbox rows with mutationMode adminWindow for window collections", async () => {
|
|
25
|
+
const transport = createFakeTransport();
|
|
26
|
+
const { provider } = makeAuthProvider();
|
|
27
|
+
const client = createSyncDb({
|
|
28
|
+
authProvider: provider,
|
|
29
|
+
baseUrl: "http://localhost:4000",
|
|
30
|
+
collections: ["todos"],
|
|
31
|
+
name: "admin-window-mutate-test",
|
|
32
|
+
transport,
|
|
33
|
+
windowCollections: ["todos"],
|
|
34
|
+
});
|
|
35
|
+
await client.start();
|
|
36
|
+
const { mutationId } = client.mutate({
|
|
37
|
+
collection: "todos",
|
|
38
|
+
data: { title: "window write" },
|
|
39
|
+
operation: "create",
|
|
40
|
+
});
|
|
41
|
+
expect(client.outbox.getMutation({ mutationId })?.mutationMode).toBe("adminWindow");
|
|
42
|
+
await client.stop();
|
|
43
|
+
});
|
|
44
|
+
it("does not tag product collection mutations", async () => {
|
|
45
|
+
const transport = createFakeTransport();
|
|
46
|
+
const { provider } = makeAuthProvider();
|
|
47
|
+
const client = createSyncDb({
|
|
48
|
+
authProvider: provider,
|
|
49
|
+
baseUrl: "http://localhost:4000",
|
|
50
|
+
collections: ["todos", "notes"],
|
|
51
|
+
name: "product-mutate-test",
|
|
52
|
+
transport,
|
|
53
|
+
windowCollections: ["todos"],
|
|
54
|
+
});
|
|
55
|
+
await client.start();
|
|
56
|
+
const { mutationId } = client.mutate({
|
|
57
|
+
collection: "notes",
|
|
58
|
+
data: { title: "product write" },
|
|
59
|
+
operation: "create",
|
|
60
|
+
});
|
|
61
|
+
expect(client.outbox.getMutation({ mutationId })?.mutationMode).toBeUndefined();
|
|
62
|
+
await client.stop();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=client.adminWindowMutation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.adminWindowMutation.test.js","sourceRoot":"","sources":["../src/client.adminWindowMutation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAC,MAAM,UAAU,CAAC;AAEzD,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAE5D,MAAM,gBAAgB,GAAG,CAAC,SAAwB,QAAQ,EAAE,EAAE;IAC5D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IACxC,MAAM,KAAK,GAAG,EAAC,MAAM,EAAC,CAAC;IACvB,OAAO;QACL,QAAQ,EAAE;YACR,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO;YAC7B,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM;YACnC,YAAY,EAAE,CAAC,QAAoB,EAAgB,EAAE;gBACnD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBACxB,OAAO,GAAG,EAAE;oBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC7B,CAAC,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACvD,SAAS,CAAC,GAAG,EAAE;QACb,kBAAkB;IACpB,CAAC,CAAC,CAAC;I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,UAAU,EAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YACjC,UAAU,EAAE,OAAO;YACnB,IAAI,EAAE,EAAC,KAAK,EAAE,eAAe,EAAC;YAC9B,SAAS,EAAE,QAAQ;SACpB,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAC,UAAU,EAAC,CAAC,EAAE,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;QAC9E,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { DefaultPersisterFactoryConfig, PersisterFactory } from "./persiste
|
|
|
5
5
|
import { type SyncStore } from "./storage/store";
|
|
6
6
|
import { type HttpChannel } from "./sync/httpChannel";
|
|
7
7
|
import type { SyncTransport } from "./sync/transport";
|
|
8
|
+
import { type HydrateWindowEntitiesResult } from "./sync/windowHydrate";
|
|
8
9
|
import type { AuthProvider, ConflictResolutionStrategy, SyncMutationOperation, SyncStatus } from "./types";
|
|
9
10
|
/** Periodic reconcile interval when not configured (5 minutes). */
|
|
10
11
|
export declare const DEFAULT_RECONCILE_INTERVAL_MS: number;
|
|
@@ -33,6 +34,12 @@ export interface SyncDbConfig {
|
|
|
33
34
|
baseUrl?: string;
|
|
34
35
|
/** Transport override (tests inject a fake; default is the socket transport). */
|
|
35
36
|
transport?: SyncTransport;
|
|
37
|
+
/**
|
|
38
|
+
* Optional selected organization id for `X-Organization-Id` on HTTP sync
|
|
39
|
+
* calls and the `organizationId` field on socket mutate payloads. Read at
|
|
40
|
+
* send time so admin org switches apply without reconnecting.
|
|
41
|
+
*/
|
|
42
|
+
organizationIdProvider?: () => string | undefined;
|
|
36
43
|
/** HTTP channel override (default is built from baseUrl when present). */
|
|
37
44
|
httpChannel?: HttpChannel;
|
|
38
45
|
/** Persister factory override (default is the platform default factory). */
|
|
@@ -49,6 +56,12 @@ export interface SyncDbConfig {
|
|
|
49
56
|
idbSetImpl?: DefaultPersisterFactoryConfig["idbSetImpl"];
|
|
50
57
|
/** Periodic reconcile interval in ms; 0 disables (default 5 minutes). */
|
|
51
58
|
reconcileIntervalMs?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Collections that subscribe in admin window mode: join `{collection}|admin`,
|
|
61
|
+
* skip `GET /sync/snapshot` paging (startup, catch-up, and the reconcile timer).
|
|
62
|
+
* Hydrate rows via REST membership + `/sync/entities` instead.
|
|
63
|
+
*/
|
|
64
|
+
windowCollections?: string[];
|
|
52
65
|
/** Rate limit for seq-jump-triggered reconciles per stream (default 30s). */
|
|
53
66
|
seqJumpReconcileMinIntervalMs?: number;
|
|
54
67
|
/** Millisecond clock, injectable for deterministic rate-limit tests. */
|
|
@@ -189,6 +202,15 @@ export interface SyncDb {
|
|
|
189
202
|
};
|
|
190
203
|
/** Snapshot-from-cursor catch-up for every collection (no-op without HTTP). */
|
|
191
204
|
reconcile: () => Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Upsert a window of known ids (admin membership). Missing rows are fetched
|
|
207
|
+
* from `GET /sync/entities`; ids the server does not return are ignored.
|
|
208
|
+
*/
|
|
209
|
+
hydrateWindow: (args: {
|
|
210
|
+
collection: string;
|
|
211
|
+
ids: string[];
|
|
212
|
+
restRows?: Record<string, unknown>;
|
|
213
|
+
}) => Promise<HydrateWindowEntitiesResult>;
|
|
192
214
|
/**
|
|
193
215
|
* Purge every known stream locally and re-bootstrap from cursor 0. Use when
|
|
194
216
|
* devices have diverged and a full server snapshot is needed without wiping
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAC,MAAM,kBAA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MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,EAAE,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC3C;;;;;OAKG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9C,uDAAuD;IACvD,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,2DAA2D;IAC3D,eAAe,EAAE,CAAC,IAAI,EAAE;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,0BAA0B,CAAA;KAAC,KAAK,IAAI,CAAC;IAC5F;;;;;OAKG;IACH,WAAW,EAAE,CAAC,IAAI,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAC,KAAK,IAAI,CAAC;IAChD;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,0CAA0C;IAC1C,aAAa,EAAE,MAAM,UAAU,CAAC;IAChC;;;;;;OAMG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IACrD;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,KAAG,MAypDnD,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DateTime } from "luxon";
|
|
|
2
2
|
import { createServerKeyProvider, DEFAULT_KEY_CACHE_DB_NAME } from "./crypto/keyProviders";
|
|
3
3
|
import { attachDebugChannel } from "./debug/debugChannel";
|
|
4
4
|
import { resolveDebugLog } from "./debug/debugLog";
|
|
5
|
+
import { registerSyncDbDevtools } from "./debug/devtools";
|
|
5
6
|
import { getConflict, listConflicts, pruneGhostConflicts } from "./mutations/conflicts";
|
|
6
7
|
import { createOutbox, generateMutationId } from "./mutations/outbox";
|
|
7
8
|
import { resolveConflict as applyConflictResolution } from "./mutations/resolveConflict";
|
|
@@ -17,12 +18,13 @@ import { repairMarkedEntities } from "./sync/entityRepair";
|
|
|
17
18
|
import { AuthRequiredError, createHttpChannel } from "./sync/httpChannel";
|
|
18
19
|
import { createReplayCoordinator } from "./sync/replayCoordinator";
|
|
19
20
|
import { createSocketTransport } from "./sync/socketTransport";
|
|
21
|
+
import { hydrateWindowEntities } from "./sync/windowHydrate";
|
|
20
22
|
/** Periodic reconcile interval when not configured (5 minutes). */
|
|
21
|
-
export const DEFAULT_RECONCILE_INTERVAL_MS = 5 *
|
|
23
|
+
export const DEFAULT_RECONCILE_INTERVAL_MS = 5 * 60_000;
|
|
22
24
|
/** Minimum interval between seq-jump-triggered reconciles per stream (30s). */
|
|
23
|
-
export const DEFAULT_SEQ_JUMP_RECONCILE_MIN_INTERVAL_MS =
|
|
25
|
+
export const DEFAULT_SEQ_JUMP_RECONCILE_MIN_INTERVAL_MS = 30_000;
|
|
24
26
|
/** E5: default local tombstone retention window (90 days), matching the server's (C7). */
|
|
25
|
-
export const DEFAULT_TOMBSTONE_RETENTION_MS = 90 * 24 * 60 * 60 *
|
|
27
|
+
export const DEFAULT_TOMBSTONE_RETENTION_MS = 90 * 24 * 60 * 60 * 1_000;
|
|
26
28
|
/**
|
|
27
29
|
* `start()` auth-resolution retry defaults. A host app only calls `start()` once it
|
|
28
30
|
* already believes the user is authenticated (e.g. right after its own login flow
|
|
@@ -53,15 +55,33 @@ export const createSyncDb = (config) => {
|
|
|
53
55
|
authProvider: config.authProvider,
|
|
54
56
|
// biome-ignore lint/style/noNonNullAssertion: guarded above — no transport implies baseUrl.
|
|
55
57
|
baseUrl: config.baseUrl,
|
|
58
|
+
organizationIdProvider: config.organizationIdProvider,
|
|
56
59
|
});
|
|
57
60
|
const httpChannel = config.httpChannel ??
|
|
58
61
|
(config.baseUrl
|
|
59
|
-
? createHttpChannel({
|
|
62
|
+
? createHttpChannel({
|
|
63
|
+
authProvider: config.authProvider,
|
|
64
|
+
baseUrl: config.baseUrl,
|
|
65
|
+
organizationIdProvider: config.organizationIdProvider,
|
|
66
|
+
})
|
|
60
67
|
: undefined);
|
|
61
68
|
const store = createSyncStore({
|
|
62
69
|
collections: config.collections,
|
|
63
70
|
now: () => DateTime.fromMillis(now()).toISO() ?? new Date(now()).toISOString(),
|
|
64
71
|
});
|
|
72
|
+
const windowCollectionSet = new Set(config.windowCollections ?? []);
|
|
73
|
+
const isWindowCollection = (collection) => windowCollectionSet.has(collection);
|
|
74
|
+
const skipSnapshotPaging = ({ collection, stream, mode, }) => isWindowCollection(collection) || mode === "window" || stream.endsWith("|admin");
|
|
75
|
+
const subscribeConfiguredCollections = () => {
|
|
76
|
+
const windowed = config.collections.filter((collection) => isWindowCollection(collection));
|
|
77
|
+
const full = config.collections.filter((collection) => !isWindowCollection(collection));
|
|
78
|
+
if (full.length > 0) {
|
|
79
|
+
transport.subscribe(full);
|
|
80
|
+
}
|
|
81
|
+
if (windowed.length > 0) {
|
|
82
|
+
transport.subscribe(windowed, { mode: "window" });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
65
85
|
const outbox = createOutbox({ store });
|
|
66
86
|
const debugLog = resolveDebugLog(config.debug);
|
|
67
87
|
// Mirror the debug log across browser windows/tabs (web only) so a debugger
|
|
@@ -139,6 +159,14 @@ export const createSyncDb = (config) => {
|
|
|
139
159
|
lifecycle = result.then(() => { }, () => { });
|
|
140
160
|
return result;
|
|
141
161
|
};
|
|
162
|
+
const waitForLifecycleIdle = async () => {
|
|
163
|
+
let pending = lifecycle;
|
|
164
|
+
await pending;
|
|
165
|
+
while (pending !== lifecycle) {
|
|
166
|
+
pending = lifecycle;
|
|
167
|
+
await pending;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
142
170
|
const notifyStatusChange = () => {
|
|
143
171
|
for (const listener of statusListeners) {
|
|
144
172
|
listener();
|
|
@@ -374,6 +402,9 @@ export const createSyncDb = (config) => {
|
|
|
374
402
|
return;
|
|
375
403
|
}
|
|
376
404
|
for (const [stream, collection] of streams) {
|
|
405
|
+
if (skipSnapshotPaging({ collection, stream })) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
377
408
|
await bootstrapStream({ channel: httpChannel, collection, store, stream });
|
|
378
409
|
if (isSuperseded()) {
|
|
379
410
|
return;
|
|
@@ -462,13 +493,16 @@ export const createSyncDb = (config) => {
|
|
|
462
493
|
* write). Per-stream paging is idempotent and cursor-guarded, so running it beside an
|
|
463
494
|
* in-flight reconcile is safe.
|
|
464
495
|
*/
|
|
465
|
-
const catchUpSubscribedStreams = async ({ collection, streams, }) => {
|
|
496
|
+
const catchUpSubscribedStreams = async ({ collection, mode, streams, }) => {
|
|
466
497
|
if (!httpChannel || simulatedOffline || authPaused || streams.length === 0) {
|
|
467
498
|
return;
|
|
468
499
|
}
|
|
469
500
|
if (!store.collections.includes(collection)) {
|
|
470
501
|
return;
|
|
471
502
|
}
|
|
503
|
+
if (mode === "window" || isWindowCollection(collection)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
472
506
|
const myGeneration = generation;
|
|
473
507
|
const myUserId = currentUserId;
|
|
474
508
|
const isSuperseded = () => generation !== myGeneration || currentUserId !== myUserId;
|
|
@@ -478,6 +512,9 @@ export const createSyncDb = (config) => {
|
|
|
478
512
|
if (isSuperseded()) {
|
|
479
513
|
return;
|
|
480
514
|
}
|
|
515
|
+
if (skipSnapshotPaging({ collection, mode, stream })) {
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
481
518
|
store.addKnownStream({ collection, stream });
|
|
482
519
|
await bootstrapStream({ channel: httpChannel, collection, store, stream });
|
|
483
520
|
}
|
|
@@ -588,6 +625,7 @@ export const createSyncDb = (config) => {
|
|
|
588
625
|
// the ways a device diverges in the first place, so it cannot be trusted as
|
|
589
626
|
// the authoritative list for a repair operation.
|
|
590
627
|
const streams = await syncStreams({ isSuperseded });
|
|
628
|
+
await waitForLifecycleIdle();
|
|
591
629
|
if (isSuperseded()) {
|
|
592
630
|
return skip("superseded");
|
|
593
631
|
}
|
|
@@ -616,6 +654,7 @@ export const createSyncDb = (config) => {
|
|
|
616
654
|
purged += store.purgeStream({ stream });
|
|
617
655
|
store.addKnownStream({ collection, stream });
|
|
618
656
|
await bootstrapStream({ channel: httpChannel, collection, store, stream });
|
|
657
|
+
await waitForLifecycleIdle();
|
|
619
658
|
if (isSuperseded()) {
|
|
620
659
|
return { ok: false, purged, reason: "superseded", repaired, streams: streamInfos.length };
|
|
621
660
|
}
|
|
@@ -954,13 +993,33 @@ export const createSyncDb = (config) => {
|
|
|
954
993
|
const bindDeltaHandler = () => {
|
|
955
994
|
const myEpoch = connectionEpoch;
|
|
956
995
|
const unbindPrevious = unbindDeltaHandler;
|
|
957
|
-
|
|
996
|
+
const isCurrentEpoch = () => {
|
|
958
997
|
if (myEpoch !== connectionEpoch) {
|
|
959
998
|
// A stale connection's delta arriving after a bounce for a new user.
|
|
960
|
-
return;
|
|
999
|
+
return false;
|
|
961
1000
|
}
|
|
962
|
-
|
|
963
|
-
}
|
|
1001
|
+
return true;
|
|
1002
|
+
};
|
|
1003
|
+
if (transport.onDeltaBatch) {
|
|
1004
|
+
unbindDeltaHandler = transport.onDeltaBatch((deltas) => {
|
|
1005
|
+
if (!isCurrentEpoch()) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
store.raw.transaction(() => {
|
|
1009
|
+
for (const delta of deltas) {
|
|
1010
|
+
handleDelta(delta);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
unbindDeltaHandler = transport.onDelta((delta) => {
|
|
1017
|
+
if (!isCurrentEpoch()) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
handleDelta(delta);
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
964
1023
|
unbindPrevious?.();
|
|
965
1024
|
};
|
|
966
1025
|
/**
|
|
@@ -987,7 +1046,7 @@ export const createSyncDb = (config) => {
|
|
|
987
1046
|
warn("transport reconnect after user change failed; continuing offline")(error);
|
|
988
1047
|
}
|
|
989
1048
|
bindDeltaHandler();
|
|
990
|
-
|
|
1049
|
+
subscribeConfiguredCollections();
|
|
991
1050
|
};
|
|
992
1051
|
const handleStatusChange = ({ connected: isConnected, authExpired, }) => {
|
|
993
1052
|
setConnected(isConnected);
|
|
@@ -1205,7 +1264,7 @@ export const createSyncDb = (config) => {
|
|
|
1205
1264
|
if (generation !== myGeneration) {
|
|
1206
1265
|
return;
|
|
1207
1266
|
}
|
|
1208
|
-
|
|
1267
|
+
subscribeConfiguredCollections();
|
|
1209
1268
|
// C2: run an initial stream discovery + per-stream bootstrap on start (not only via
|
|
1210
1269
|
// the reconnect status event) so a client that starts offline-then-online, or with a
|
|
1211
1270
|
// warm socket, still backfills newly-joined streams and drains legacy cursors.
|
|
@@ -1319,6 +1378,7 @@ export const createSyncDb = (config) => {
|
|
|
1319
1378
|
entityId,
|
|
1320
1379
|
...(maxAttempts !== undefined ? { maxAttempts } : {}),
|
|
1321
1380
|
mutationId,
|
|
1381
|
+
...(windowCollectionSet.has(collection) ? { mutationMode: "adminWindow" } : {}),
|
|
1322
1382
|
operation,
|
|
1323
1383
|
userId: currentUserId,
|
|
1324
1384
|
});
|
|
@@ -1434,6 +1494,18 @@ export const createSyncDb = (config) => {
|
|
|
1434
1494
|
}
|
|
1435
1495
|
return statuses;
|
|
1436
1496
|
};
|
|
1497
|
+
const hydrateWindow = async ({ collection, ids, restRows, }) => {
|
|
1498
|
+
if (!httpChannel) {
|
|
1499
|
+
throw new Error("hydrateWindow requires an HTTP channel");
|
|
1500
|
+
}
|
|
1501
|
+
return hydrateWindowEntities({
|
|
1502
|
+
channel: httpChannel,
|
|
1503
|
+
collection,
|
|
1504
|
+
ids,
|
|
1505
|
+
restRows,
|
|
1506
|
+
store,
|
|
1507
|
+
});
|
|
1508
|
+
};
|
|
1437
1509
|
const getSyncStatus = () => {
|
|
1438
1510
|
const drainProgress = currentUserId
|
|
1439
1511
|
? coordinator.getDrainProgress({ userId: currentUserId })
|
|
@@ -1516,12 +1588,13 @@ export const createSyncDb = (config) => {
|
|
|
1516
1588
|
await persisterToStop.destroy();
|
|
1517
1589
|
}
|
|
1518
1590
|
});
|
|
1519
|
-
|
|
1591
|
+
const client = {
|
|
1520
1592
|
debug: debugLog,
|
|
1521
1593
|
forceResync,
|
|
1522
1594
|
getSyncStatus,
|
|
1523
1595
|
goOffline,
|
|
1524
1596
|
goOnline,
|
|
1597
|
+
hydrateWindow,
|
|
1525
1598
|
mutate,
|
|
1526
1599
|
onStatusChange,
|
|
1527
1600
|
outbox,
|
|
@@ -1534,5 +1607,9 @@ export const createSyncDb = (config) => {
|
|
|
1534
1607
|
stop,
|
|
1535
1608
|
store,
|
|
1536
1609
|
};
|
|
1610
|
+
if (debugLog) {
|
|
1611
|
+
registerSyncDbDevtools({ client, name: config.name });
|
|
1612
|
+
}
|
|
1613
|
+
return client;
|
|
1537
1614
|
};
|
|
1538
1615
|
//# sourceMappingURL=client.js.map
|