@terreno/syncdb 56.0.0-beta.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 +419 -0
- package/dist/auth/betterAuthAdapter.d.ts +22 -0
- package/dist/auth/betterAuthAdapter.d.ts.map +1 -0
- package/dist/auth/betterAuthAdapter.js +181 -0
- package/dist/auth/betterAuthAdapter.js.map +1 -0
- package/dist/auth/betterAuthAdapter.test.d.ts +2 -0
- package/dist/auth/betterAuthAdapter.test.d.ts.map +1 -0
- package/dist/auth/betterAuthAdapter.test.js +350 -0
- package/dist/auth/betterAuthAdapter.test.js.map +1 -0
- package/dist/auth/types.d.ts +42 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +9 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/client.d.ts +246 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1415 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +2310 -0
- package/dist/client.test.js.map +1 -0
- package/dist/crypto/aesGcmCodec.d.ts +33 -0
- package/dist/crypto/aesGcmCodec.d.ts.map +1 -0
- package/dist/crypto/aesGcmCodec.js +80 -0
- package/dist/crypto/aesGcmCodec.js.map +1 -0
- package/dist/crypto/aesGcmCodec.test.d.ts +2 -0
- package/dist/crypto/aesGcmCodec.test.d.ts.map +1 -0
- package/dist/crypto/aesGcmCodec.test.js +83 -0
- package/dist/crypto/aesGcmCodec.test.js.map +1 -0
- package/dist/crypto/identityCodec.d.ts +7 -0
- package/dist/crypto/identityCodec.d.ts.map +1 -0
- package/dist/crypto/identityCodec.js +9 -0
- package/dist/crypto/identityCodec.js.map +1 -0
- package/dist/crypto/keyProviders.d.ts +34 -0
- package/dist/crypto/keyProviders.d.ts.map +1 -0
- package/dist/crypto/keyProviders.js +102 -0
- package/dist/crypto/keyProviders.js.map +1 -0
- package/dist/crypto/keyProviders.test.d.ts +2 -0
- package/dist/crypto/keyProviders.test.d.ts.map +1 -0
- package/dist/crypto/keyProviders.test.js +189 -0
- package/dist/crypto/keyProviders.test.js.map +1 -0
- package/dist/crypto/types.d.ts +24 -0
- package/dist/crypto/types.d.ts.map +1 -0
- package/dist/crypto/types.js +8 -0
- package/dist/crypto/types.js.map +1 -0
- package/dist/debug/debugChannel.d.ts +52 -0
- package/dist/debug/debugChannel.d.ts.map +1 -0
- package/dist/debug/debugChannel.js +73 -0
- package/dist/debug/debugChannel.js.map +1 -0
- package/dist/debug/debugChannel.test.d.ts +2 -0
- package/dist/debug/debugChannel.test.d.ts.map +1 -0
- package/dist/debug/debugChannel.test.js +105 -0
- package/dist/debug/debugChannel.test.js.map +1 -0
- package/dist/debug/debugLog.d.ts +111 -0
- package/dist/debug/debugLog.d.ts.map +1 -0
- package/dist/debug/debugLog.js +150 -0
- package/dist/debug/debugLog.js.map +1 -0
- package/dist/debug/debugLog.test.d.ts +2 -0
- package/dist/debug/debugLog.test.d.ts.map +1 -0
- package/dist/debug/debugLog.test.js +121 -0
- package/dist/debug/debugLog.test.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/isolated/defaultPersisterFactoryNative.isolated.d.ts +2 -0
- package/dist/isolated/defaultPersisterFactoryNative.isolated.d.ts.map +1 -0
- package/dist/isolated/defaultPersisterFactoryNative.isolated.js +38 -0
- package/dist/isolated/defaultPersisterFactoryNative.isolated.js.map +1 -0
- package/dist/mutations/conflicts.d.ts +31 -0
- package/dist/mutations/conflicts.d.ts.map +1 -0
- package/dist/mutations/conflicts.js +73 -0
- package/dist/mutations/conflicts.js.map +1 -0
- package/dist/mutations/outbox.d.ts +174 -0
- package/dist/mutations/outbox.d.ts.map +1 -0
- package/dist/mutations/outbox.js +385 -0
- package/dist/mutations/outbox.js.map +1 -0
- package/dist/mutations/outbox.test.d.ts +2 -0
- package/dist/mutations/outbox.test.d.ts.map +1 -0
- package/dist/mutations/outbox.test.js +643 -0
- package/dist/mutations/outbox.test.js.map +1 -0
- package/dist/mutations/resolveConflict.d.ts +32 -0
- package/dist/mutations/resolveConflict.d.ts.map +1 -0
- package/dist/mutations/resolveConflict.js +101 -0
- package/dist/mutations/resolveConflict.js.map +1 -0
- package/dist/mutations/resolveConflict.test.d.ts +2 -0
- package/dist/mutations/resolveConflict.test.d.ts.map +1 -0
- package/dist/mutations/resolveConflict.test.js +282 -0
- package/dist/mutations/resolveConflict.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.d.ts +9 -0
- package/dist/persisters/defaultPersisterFactory.d.ts.map +1 -0
- package/dist/persisters/defaultPersisterFactory.js +9 -0
- package/dist/persisters/defaultPersisterFactory.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts +10 -0
- package/dist/persisters/defaultPersisterFactory.native.d.ts.map +1 -0
- package/dist/persisters/defaultPersisterFactory.native.js +44 -0
- package/dist/persisters/defaultPersisterFactory.native.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.test.d.ts +2 -0
- package/dist/persisters/defaultPersisterFactory.test.d.ts.map +1 -0
- package/dist/persisters/defaultPersisterFactory.test.js +177 -0
- package/dist/persisters/defaultPersisterFactory.test.js.map +1 -0
- package/dist/persisters/defaultPersisterFactory.web.d.ts +17 -0
- package/dist/persisters/defaultPersisterFactory.web.d.ts.map +1 -0
- package/dist/persisters/defaultPersisterFactory.web.js +65 -0
- package/dist/persisters/defaultPersisterFactory.web.js.map +1 -0
- package/dist/persisters/encryptedIndexedDbPersister.d.ts +46 -0
- package/dist/persisters/encryptedIndexedDbPersister.d.ts.map +1 -0
- package/dist/persisters/encryptedIndexedDbPersister.js +171 -0
- package/dist/persisters/encryptedIndexedDbPersister.js.map +1 -0
- package/dist/persisters/encryptedIndexedDbPersister.test.d.ts +2 -0
- package/dist/persisters/encryptedIndexedDbPersister.test.d.ts.map +1 -0
- package/dist/persisters/encryptedIndexedDbPersister.test.js +352 -0
- package/dist/persisters/encryptedIndexedDbPersister.test.js.map +1 -0
- package/dist/persisters/memoryPersister.d.ts +19 -0
- package/dist/persisters/memoryPersister.d.ts.map +1 -0
- package/dist/persisters/memoryPersister.js +31 -0
- package/dist/persisters/memoryPersister.js.map +1 -0
- package/dist/persisters/memoryPersister.test.d.ts +2 -0
- package/dist/persisters/memoryPersister.test.d.ts.map +1 -0
- package/dist/persisters/memoryPersister.test.js +113 -0
- package/dist/persisters/memoryPersister.test.js.map +1 -0
- package/dist/persisters/types.d.ts +65 -0
- package/dist/persisters/types.d.ts.map +1 -0
- package/dist/persisters/types.js +2 -0
- package/dist/persisters/types.js.map +1 -0
- package/dist/react/hooks.d.ts +132 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +269 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/hooks.test.d.ts +2 -0
- package/dist/react/hooks.test.d.ts.map +1 -0
- package/dist/react/hooks.test.js +645 -0
- package/dist/react/hooks.test.js.map +1 -0
- package/dist/react/index.d.ts +11 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +11 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/provider.d.ts +11 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +17 -0
- package/dist/react/provider.js.map +1 -0
- package/dist/storage/idb.d.ts +27 -0
- package/dist/storage/idb.d.ts.map +1 -0
- package/dist/storage/idb.js +72 -0
- package/dist/storage/idb.js.map +1 -0
- package/dist/storage/idb.test.d.ts +2 -0
- package/dist/storage/idb.test.d.ts.map +1 -0
- package/dist/storage/idb.test.js +100 -0
- package/dist/storage/idb.test.js.map +1 -0
- package/dist/storage/purgeUnknownStream.test.d.ts +2 -0
- package/dist/storage/purgeUnknownStream.test.d.ts.map +1 -0
- package/dist/storage/purgeUnknownStream.test.js +64 -0
- package/dist/storage/purgeUnknownStream.test.js.map +1 -0
- package/dist/storage/schema.d.ts +33 -0
- package/dist/storage/schema.d.ts.map +1 -0
- package/dist/storage/schema.js +92 -0
- package/dist/storage/schema.js.map +1 -0
- package/dist/storage/store.d.ts +136 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +275 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/storage/store.test.d.ts +2 -0
- package/dist/storage/store.test.d.ts.map +1 -0
- package/dist/storage/store.test.js +357 -0
- package/dist/storage/store.test.js.map +1 -0
- package/dist/storage/types.d.ts +146 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +32 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/storage/wipe.d.ts +22 -0
- package/dist/storage/wipe.d.ts.map +1 -0
- package/dist/storage/wipe.js +43 -0
- package/dist/storage/wipe.js.map +1 -0
- package/dist/storage/wipe.test.d.ts +2 -0
- package/dist/storage/wipe.test.d.ts.map +1 -0
- package/dist/storage/wipe.test.js +95 -0
- package/dist/storage/wipe.test.js.map +1 -0
- package/dist/sync/bootstrap.d.ts +64 -0
- package/dist/sync/bootstrap.d.ts.map +1 -0
- package/dist/sync/bootstrap.js +160 -0
- package/dist/sync/bootstrap.js.map +1 -0
- package/dist/sync/bootstrap.test.d.ts +2 -0
- package/dist/sync/bootstrap.test.d.ts.map +1 -0
- package/dist/sync/bootstrap.test.js +447 -0
- package/dist/sync/bootstrap.test.js.map +1 -0
- package/dist/sync/cursor.d.ts +67 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +74 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/cursor.test.d.ts +2 -0
- package/dist/sync/cursor.test.d.ts.map +1 -0
- package/dist/sync/cursor.test.js +73 -0
- package/dist/sync/cursor.test.js.map +1 -0
- package/dist/sync/deltaApplier.d.ts +30 -0
- package/dist/sync/deltaApplier.d.ts.map +1 -0
- package/dist/sync/deltaApplier.js +61 -0
- package/dist/sync/deltaApplier.js.map +1 -0
- package/dist/sync/deltaApplier.test.d.ts +2 -0
- package/dist/sync/deltaApplier.test.d.ts.map +1 -0
- package/dist/sync/deltaApplier.test.js +212 -0
- package/dist/sync/deltaApplier.test.js.map +1 -0
- package/dist/sync/entityRepair.d.ts +45 -0
- package/dist/sync/entityRepair.d.ts.map +1 -0
- package/dist/sync/entityRepair.js +91 -0
- package/dist/sync/entityRepair.js.map +1 -0
- package/dist/sync/entityRepair.test.d.ts +2 -0
- package/dist/sync/entityRepair.test.d.ts.map +1 -0
- package/dist/sync/entityRepair.test.js +146 -0
- package/dist/sync/entityRepair.test.js.map +1 -0
- package/dist/sync/httpChannel.d.ts +74 -0
- package/dist/sync/httpChannel.d.ts.map +1 -0
- package/dist/sync/httpChannel.js +123 -0
- package/dist/sync/httpChannel.js.map +1 -0
- package/dist/sync/httpChannel.test.d.ts +2 -0
- package/dist/sync/httpChannel.test.d.ts.map +1 -0
- package/dist/sync/httpChannel.test.js +215 -0
- package/dist/sync/httpChannel.test.js.map +1 -0
- package/dist/sync/replayCoordinator.d.ts +212 -0
- package/dist/sync/replayCoordinator.d.ts.map +1 -0
- package/dist/sync/replayCoordinator.js +1110 -0
- package/dist/sync/replayCoordinator.js.map +1 -0
- package/dist/sync/replayCoordinator.test.d.ts +2 -0
- package/dist/sync/replayCoordinator.test.d.ts.map +1 -0
- package/dist/sync/replayCoordinator.test.js +1496 -0
- package/dist/sync/replayCoordinator.test.js.map +1 -0
- package/dist/sync/socketTransport.d.ts +56 -0
- package/dist/sync/socketTransport.d.ts.map +1 -0
- package/dist/sync/socketTransport.js +292 -0
- package/dist/sync/socketTransport.js.map +1 -0
- package/dist/sync/socketTransport.test.d.ts +2 -0
- package/dist/sync/socketTransport.test.d.ts.map +1 -0
- package/dist/sync/socketTransport.test.js +346 -0
- package/dist/sync/socketTransport.test.js.map +1 -0
- package/dist/sync/transport.d.ts +80 -0
- package/dist/sync/transport.d.ts.map +1 -0
- package/dist/sync/transport.js +5 -0
- package/dist/sync/transport.js.map +1 -0
- package/dist/testing/fakeTransport.d.ts +55 -0
- package/dist/testing/fakeTransport.d.ts.map +1 -0
- package/dist/testing/fakeTransport.js +139 -0
- package/dist/testing/fakeTransport.js.map +1 -0
- package/dist/testing/fakeTransport.test.d.ts +2 -0
- package/dist/testing/fakeTransport.test.d.ts.map +1 -0
- package/dist/testing/fakeTransport.test.js +112 -0
- package/dist/testing/fakeTransport.test.js.map +1 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +13 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types.d.ts +271 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
- package/src/auth/betterAuthAdapter.test.ts +455 -0
- package/src/auth/betterAuthAdapter.ts +214 -0
- package/src/auth/types.ts +49 -0
- package/src/client.test.ts +2670 -0
- package/src/client.ts +1748 -0
- package/src/crypto/aesGcmCodec.test.ts +103 -0
- package/src/crypto/aesGcmCodec.ts +98 -0
- package/src/crypto/identityCodec.ts +10 -0
- package/src/crypto/keyProviders.test.ts +228 -0
- package/src/crypto/keyProviders.ts +153 -0
- package/src/crypto/types.ts +23 -0
- package/src/debug/debugChannel.test.ts +121 -0
- package/src/debug/debugChannel.ts +112 -0
- package/src/debug/debugLog.test.ts +139 -0
- package/src/debug/debugLog.ts +272 -0
- package/src/index.ts +157 -0
- package/src/isolated/defaultPersisterFactoryNative.isolated.ts +45 -0
- package/src/mutations/conflicts.ts +108 -0
- package/src/mutations/outbox.test.ts +754 -0
- package/src/mutations/outbox.ts +585 -0
- package/src/mutations/resolveConflict.test.ts +338 -0
- package/src/mutations/resolveConflict.ts +115 -0
- package/src/persisters/defaultPersisterFactory.native.ts +53 -0
- package/src/persisters/defaultPersisterFactory.test.ts +207 -0
- package/src/persisters/defaultPersisterFactory.ts +12 -0
- package/src/persisters/defaultPersisterFactory.web.ts +78 -0
- package/src/persisters/encryptedIndexedDbPersister.test.ts +381 -0
- package/src/persisters/encryptedIndexedDbPersister.ts +218 -0
- package/src/persisters/memoryPersister.test.ts +136 -0
- package/src/persisters/memoryPersister.ts +52 -0
- package/src/persisters/types.ts +71 -0
- package/src/react/hooks.test.tsx +761 -0
- package/src/react/hooks.ts +409 -0
- package/src/react/index.ts +11 -0
- package/src/react/provider.tsx +27 -0
- package/src/storage/idb.test.ts +116 -0
- package/src/storage/idb.ts +112 -0
- package/src/storage/purgeUnknownStream.test.ts +74 -0
- package/src/storage/schema.ts +103 -0
- package/src/storage/store.test.ts +424 -0
- package/src/storage/store.ts +461 -0
- package/src/storage/types.ts +159 -0
- package/src/storage/wipe.test.ts +111 -0
- package/src/storage/wipe.ts +58 -0
- package/src/sync/bootstrap.test.ts +486 -0
- package/src/sync/bootstrap.ts +217 -0
- package/src/sync/cursor.test.ts +84 -0
- package/src/sync/cursor.ts +113 -0
- package/src/sync/deltaApplier.test.ts +237 -0
- package/src/sync/deltaApplier.ts +84 -0
- package/src/sync/entityRepair.test.ts +161 -0
- package/src/sync/entityRepair.ts +124 -0
- package/src/sync/httpChannel.test.ts +265 -0
- package/src/sync/httpChannel.ts +220 -0
- package/src/sync/replayCoordinator.test.ts +1709 -0
- package/src/sync/replayCoordinator.ts +1370 -0
- package/src/sync/socketTransport.test.ts +413 -0
- package/src/sync/socketTransport.ts +379 -0
- package/src/sync/transport.ts +76 -0
- package/src/testing/fakeTransport.test.ts +125 -0
- package/src/testing/fakeTransport.ts +206 -0
- package/src/testing/index.ts +18 -0
- package/src/types.ts +284 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @terreno/syncdb — local-first data layer for Terreno apps.
|
|
3
|
+
*
|
|
4
|
+
* The on-device store (TinyBase MergeableStore) is the UI's source of truth:
|
|
5
|
+
* reads come from the local store, writes apply optimistically to local state and a
|
|
6
|
+
* durable outbox, and the server is asynchronous reconciliation over a websocket
|
|
7
|
+
* delta protocol with HTTP snapshot catch-up. Supersedes @terreno/rtk for
|
|
8
|
+
* data-synchronization concerns. See docs/implementationPlans/syncdb-local-first.md.
|
|
9
|
+
*
|
|
10
|
+
* This module is the package's public API: everything re-exported here is
|
|
11
|
+
* semver-protected, and everything else under `src/` is an internal detail that may
|
|
12
|
+
* change in a patch release. Deliberately absent are the pieces that let a host app
|
|
13
|
+
* corrupt the store's invariants behind the client's back — cell-level cursor
|
|
14
|
+
* mutators, outbox/conflict writers, raw row shapes, the IndexedDB helpers, and the
|
|
15
|
+
* debug broadcast bridge. Reach for `client.store`/`client.outbox` (or the React
|
|
16
|
+
* hooks) instead, and open an issue if something genuinely needs promoting.
|
|
17
|
+
*
|
|
18
|
+
* Two other entry points exist:
|
|
19
|
+
* - `@terreno/syncdb/react` (src/react/index.ts) — React bindings. They live on
|
|
20
|
+
* their own subpath because react is an optional peer dependency and this entry
|
|
21
|
+
* must stay importable without it.
|
|
22
|
+
* - `@terreno/syncdb/testing` (src/testing/index.ts) — test doubles such as
|
|
23
|
+
* `createFakeTransport`, kept out of production bundles.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// --- Client ---------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
createSyncDb,
|
|
30
|
+
DEFAULT_RECONCILE_INTERVAL_MS,
|
|
31
|
+
DEFAULT_SEQ_JUMP_RECONCILE_MIN_INTERVAL_MS,
|
|
32
|
+
DEFAULT_START_AUTH_RETRY_ATTEMPTS,
|
|
33
|
+
DEFAULT_START_AUTH_RETRY_DELAY_MS,
|
|
34
|
+
DEFAULT_TOMBSTONE_RETENTION_MS,
|
|
35
|
+
type ForceResyncResult,
|
|
36
|
+
type ForceResyncSkipReason,
|
|
37
|
+
type MutateArgs,
|
|
38
|
+
type SyncDb,
|
|
39
|
+
type SyncDbConfig,
|
|
40
|
+
} from "./client";
|
|
41
|
+
|
|
42
|
+
// --- Protocol, status, and conflict types --------------------------------
|
|
43
|
+
|
|
44
|
+
export type {
|
|
45
|
+
AuthProvider,
|
|
46
|
+
ConflictResolutionStrategy,
|
|
47
|
+
OutboxMutation,
|
|
48
|
+
OutboxStatus,
|
|
49
|
+
SyncAck,
|
|
50
|
+
SyncCollectionStatus,
|
|
51
|
+
SyncConflict,
|
|
52
|
+
SyncDelta,
|
|
53
|
+
SyncEntitiesResponse,
|
|
54
|
+
SyncMutateBatchRequest,
|
|
55
|
+
SyncMutateBatchResponse,
|
|
56
|
+
SyncMutateBatchResult,
|
|
57
|
+
SyncMutateRequest,
|
|
58
|
+
SyncMutationOperation,
|
|
59
|
+
SyncNack,
|
|
60
|
+
SyncNackCode,
|
|
61
|
+
SyncSnapshotEntity,
|
|
62
|
+
SyncSnapshotResponse,
|
|
63
|
+
SyncStatus,
|
|
64
|
+
SyncStreamInfo,
|
|
65
|
+
} from "./types";
|
|
66
|
+
|
|
67
|
+
// --- Local store and outbox (read surface) -------------------------------
|
|
68
|
+
// `client.store` is typed as SyncStore and `client.outbox` as Outbox;
|
|
69
|
+
// OUTBOX_TABLE names the table to pass to `client.store.raw.getTable(...)` when
|
|
70
|
+
// inspecting queued mutations directly (what the example app's sync health UI
|
|
71
|
+
// does). Reading conflicts outside React goes through `listConflicts`; writing to
|
|
72
|
+
// any reserved table is the client's job alone.
|
|
73
|
+
|
|
74
|
+
export {listConflicts} from "./mutations/conflicts";
|
|
75
|
+
export {generateMutationId, type Outbox} from "./mutations/outbox";
|
|
76
|
+
export type {SyncStore} from "./storage/store";
|
|
77
|
+
export {OUTBOX_TABLE, type SyncEntity} from "./storage/types";
|
|
78
|
+
export {wipeLocalData} from "./storage/wipe";
|
|
79
|
+
|
|
80
|
+
// --- Auth -----------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
type BetterAuthAdapterOptions,
|
|
84
|
+
betterAuthAdapter,
|
|
85
|
+
DEFAULT_AUTH_POLL_INTERVAL_MS,
|
|
86
|
+
} from "./auth/betterAuthAdapter";
|
|
87
|
+
export type {
|
|
88
|
+
BetterAuthClientLike,
|
|
89
|
+
BetterAuthGetSessionResult,
|
|
90
|
+
BetterAuthSessionAtomLike,
|
|
91
|
+
BetterAuthSessionDataLike,
|
|
92
|
+
BetterAuthSessionLike,
|
|
93
|
+
BetterAuthUserLike,
|
|
94
|
+
} from "./auth/types";
|
|
95
|
+
|
|
96
|
+
// --- Encryption (web persistence) ----------------------------------------
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
AES_GCM_ENVELOPE_VERSION,
|
|
100
|
+
createAesGcmCodec,
|
|
101
|
+
PayloadIntegrityError,
|
|
102
|
+
UnknownEnvelopeVersionError,
|
|
103
|
+
} from "./crypto/aesGcmCodec";
|
|
104
|
+
export {identityCodec} from "./crypto/identityCodec";
|
|
105
|
+
export {
|
|
106
|
+
createKeyProviderCodec,
|
|
107
|
+
createLocalKeyProvider,
|
|
108
|
+
createServerKeyProvider,
|
|
109
|
+
DEFAULT_KEY_CACHE_DB_NAME,
|
|
110
|
+
} from "./crypto/keyProviders";
|
|
111
|
+
export type {KeyProvider, PayloadCodec} from "./crypto/types";
|
|
112
|
+
|
|
113
|
+
// --- Persisters -----------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
export {createDefaultPersisterFactory} from "./persisters/defaultPersisterFactory";
|
|
116
|
+
export {createEncryptedIndexedDbPersister} from "./persisters/encryptedIndexedDbPersister";
|
|
117
|
+
export {
|
|
118
|
+
clearMemoryPersisterData,
|
|
119
|
+
createMemoryPersister,
|
|
120
|
+
memoryPersisterFactory,
|
|
121
|
+
} from "./persisters/memoryPersister";
|
|
122
|
+
export type {DefaultPersisterFactoryConfig, PersisterFactory} from "./persisters/types";
|
|
123
|
+
|
|
124
|
+
// --- Transports (only needed to override the defaults) -------------------
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
AuthRequiredError,
|
|
128
|
+
createHttpChannel,
|
|
129
|
+
type FetchLike,
|
|
130
|
+
type FetchSnapshotPageArgs,
|
|
131
|
+
type HttpChannel,
|
|
132
|
+
type HttpChannelConfig,
|
|
133
|
+
} from "./sync/httpChannel";
|
|
134
|
+
export {createSocketTransport, type SocketTransportConfig} from "./sync/socketTransport";
|
|
135
|
+
export {
|
|
136
|
+
DEFAULT_BATCH_SIZE,
|
|
137
|
+
DEFAULT_MUTATION_TIMEOUT_MS,
|
|
138
|
+
type SendMutationBatchResult,
|
|
139
|
+
type SendMutationResult,
|
|
140
|
+
type SyncTransport,
|
|
141
|
+
type TransportStatus,
|
|
142
|
+
} from "./sync/transport";
|
|
143
|
+
|
|
144
|
+
// --- Debug log ------------------------------------------------------------
|
|
145
|
+
// Enabled with `SyncDbConfig.debug`, read through `client.debug` or the React
|
|
146
|
+
// `useSyncDebugLog()` hook. The cross-tab BroadcastChannel bridge is internal.
|
|
147
|
+
|
|
148
|
+
export type {
|
|
149
|
+
SyncDebugDirection,
|
|
150
|
+
SyncDebugEvent,
|
|
151
|
+
SyncDebugEventType,
|
|
152
|
+
SyncDebugLog,
|
|
153
|
+
SyncDebugLogOptions,
|
|
154
|
+
SyncDebugRecordInput,
|
|
155
|
+
SyncDebugSnapshot,
|
|
156
|
+
SyncDebugStats,
|
|
157
|
+
} from "./debug/debugLog";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolated test (own `bun test` invocation via scripts/check-coverage.ts):
|
|
3
|
+
* `mock.module` replaces the expo-sqlite native module and TinyBase's
|
|
4
|
+
* expo-sqlite persister module globally for the process (the latter imports
|
|
5
|
+
* expo-sqlite at its top level, which cannot load outside React Native), so
|
|
6
|
+
* this must not share a test pass with the rest of the suite.
|
|
7
|
+
*/
|
|
8
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
9
|
+
|
|
10
|
+
const fakeDb = {fake: true};
|
|
11
|
+
const fakePersister = {marker: "fake-persister"};
|
|
12
|
+
const openDatabaseSync = mock((_databaseName: string) => fakeDb);
|
|
13
|
+
const createExpoSqlitePersister = mock(
|
|
14
|
+
(_store: unknown, _db: unknown, _tableName: string) => fakePersister
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
mock.module("expo-sqlite", () => ({openDatabaseSync}));
|
|
18
|
+
mock.module("tinybase/persisters/persister-expo-sqlite", () => ({createExpoSqlitePersister}));
|
|
19
|
+
|
|
20
|
+
import {createDefaultPersisterFactory} from "../persisters/defaultPersisterFactory.native";
|
|
21
|
+
import {createSyncStore} from "../storage/store";
|
|
22
|
+
|
|
23
|
+
describe("createDefaultPersisterFactory (native)", () => {
|
|
24
|
+
it("opens the expo-sqlite database lazily and wires the JSON-mode persister", () => {
|
|
25
|
+
const factory = createDefaultPersisterFactory();
|
|
26
|
+
// Nothing touches expo-sqlite until a persister is actually created.
|
|
27
|
+
expect(openDatabaseSync).not.toHaveBeenCalled();
|
|
28
|
+
|
|
29
|
+
const store = createSyncStore({collections: ["todos"]});
|
|
30
|
+
const persister = factory({databaseName: "terreno-syncdb.db", store: store.raw});
|
|
31
|
+
expect(openDatabaseSync).toHaveBeenCalledWith("terreno-syncdb.db");
|
|
32
|
+
// JSON serialization mode: the third argument is a string table name
|
|
33
|
+
// (tabular config objects cannot persist MergeableStore CRDT metadata).
|
|
34
|
+
expect(createExpoSqlitePersister).toHaveBeenCalledWith(store.raw, fakeDb, "terreno_syncdb");
|
|
35
|
+
expect(persister).toBe(fakePersister as unknown as ReturnType<typeof factory>);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("honors a custom storeTableName", () => {
|
|
39
|
+
const factory = createDefaultPersisterFactory({storeTableName: "custom_table"});
|
|
40
|
+
const store = createSyncStore({collections: ["todos"]});
|
|
41
|
+
factory({databaseName: "custom.db", store: store.raw});
|
|
42
|
+
expect(openDatabaseSync).toHaveBeenCalledWith("custom.db");
|
|
43
|
+
expect(createExpoSqlitePersister).toHaveBeenCalledWith(store.raw, fakeDb, "custom_table");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type {Row} from "tinybase";
|
|
2
|
+
|
|
3
|
+
import type {SyncStore} from "../storage/store";
|
|
4
|
+
import {CONFLICTS_TABLE, type ConflictRow} from "../storage/types";
|
|
5
|
+
import type {SyncConflict} from "../types";
|
|
6
|
+
|
|
7
|
+
const rowToConflict = (mutationId: string, row: Partial<ConflictRow>): SyncConflict => ({
|
|
8
|
+
collection: row.collection ?? "",
|
|
9
|
+
dismissed: Boolean(row.dismissed),
|
|
10
|
+
entityId: row.entityId ?? "",
|
|
11
|
+
localData: row.localData ?? "null",
|
|
12
|
+
mutationId,
|
|
13
|
+
serverData: row.serverData ?? "null",
|
|
14
|
+
serverDeleted: Boolean(row.serverDeleted),
|
|
15
|
+
serverSeq: row.serverSeq ?? 0,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A conflict row is only actionable when it still names the entity it belongs
|
|
20
|
+
* to. Stores persisted before the schema dropped its cell defaults can hold
|
|
21
|
+
* husk rows left by TinyBase re-materializing a deleted row's defaults on load
|
|
22
|
+
* (see `buildTablesSchema`); resolving one used to throw `Unknown collection
|
|
23
|
+
* ""`. Reads skip them and {@link pruneGhostConflicts} clears them at startup.
|
|
24
|
+
*/
|
|
25
|
+
const isActionable = (row: Partial<ConflictRow>): boolean =>
|
|
26
|
+
Boolean(row.collection) && Boolean(row.entityId);
|
|
27
|
+
|
|
28
|
+
/** Record an unresolved conflict in the `_conflicts` table (rowId = mutationId). */
|
|
29
|
+
export const writeConflict = ({
|
|
30
|
+
store,
|
|
31
|
+
conflict,
|
|
32
|
+
}: {
|
|
33
|
+
store: SyncStore;
|
|
34
|
+
conflict: SyncConflict;
|
|
35
|
+
}): void => {
|
|
36
|
+
const {mutationId, serverDeleted, ...rest} = conflict;
|
|
37
|
+
const row: ConflictRow = {...rest, serverDeleted: Boolean(serverDeleted)};
|
|
38
|
+
store.raw.setRow(CONFLICTS_TABLE, mutationId, row as unknown as Row);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Read one conflict by its mutationId, or undefined when absent (or a husk row). */
|
|
42
|
+
export const getConflict = ({
|
|
43
|
+
store,
|
|
44
|
+
mutationId,
|
|
45
|
+
}: {
|
|
46
|
+
store: SyncStore;
|
|
47
|
+
mutationId: string;
|
|
48
|
+
}): SyncConflict | undefined => {
|
|
49
|
+
if (!store.raw.hasRow(CONFLICTS_TABLE, mutationId)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const row = store.raw.getRow(CONFLICTS_TABLE, mutationId) as Partial<ConflictRow>;
|
|
53
|
+
if (!isActionable(row)) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return rowToConflict(mutationId, row);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Remove a conflict row (after resolution). */
|
|
60
|
+
export const deleteConflict = ({
|
|
61
|
+
store,
|
|
62
|
+
mutationId,
|
|
63
|
+
}: {
|
|
64
|
+
store: SyncStore;
|
|
65
|
+
mutationId: string;
|
|
66
|
+
}): void => {
|
|
67
|
+
store.raw.delRow(CONFLICTS_TABLE, mutationId);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** All unresolved conflicts (dismissed rows excluded unless requested). */
|
|
71
|
+
export const listConflicts = ({
|
|
72
|
+
store,
|
|
73
|
+
includeDismissed = false,
|
|
74
|
+
}: {
|
|
75
|
+
store: SyncStore;
|
|
76
|
+
includeDismissed?: boolean;
|
|
77
|
+
}): SyncConflict[] => {
|
|
78
|
+
const conflicts: SyncConflict[] = [];
|
|
79
|
+
for (const [mutationId, row] of Object.entries(store.raw.getTable(CONFLICTS_TABLE))) {
|
|
80
|
+
const typedRow = row as Partial<ConflictRow>;
|
|
81
|
+
if (!isActionable(typedRow)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const conflict = rowToConflict(mutationId, typedRow);
|
|
85
|
+
if (!includeDismissed && conflict.dismissed) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
conflicts.push(conflict);
|
|
89
|
+
}
|
|
90
|
+
return conflicts;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Delete husk `_conflicts` rows (see {@link isActionable}) so they stop
|
|
95
|
+
* inflating conflict counts in a store that persisted them. Returns the
|
|
96
|
+
* mutationIds removed.
|
|
97
|
+
*/
|
|
98
|
+
export const pruneGhostConflicts = ({store}: {store: SyncStore}): string[] => {
|
|
99
|
+
const removed: string[] = [];
|
|
100
|
+
for (const [mutationId, row] of Object.entries(store.raw.getTable(CONFLICTS_TABLE))) {
|
|
101
|
+
if (isActionable(row as Partial<ConflictRow>)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
store.raw.delRow(CONFLICTS_TABLE, mutationId);
|
|
105
|
+
removed.push(mutationId);
|
|
106
|
+
}
|
|
107
|
+
return removed;
|
|
108
|
+
};
|