@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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { idbGet, idbSet } from "../storage/idb";
|
|
2
|
+
import { createAesGcmCodec, getSubtleCrypto } from "./aesGcmCodec";
|
|
3
|
+
/** Default IndexedDB database used to cache derived/generated CryptoKeys. */
|
|
4
|
+
export const DEFAULT_KEY_CACHE_DB_NAME = "terreno-syncdb-keys";
|
|
5
|
+
const SERVER_KEY_MATERIAL_BYTES = 32;
|
|
6
|
+
const fromBase64 = (value) => {
|
|
7
|
+
if (typeof Buffer !== "undefined") {
|
|
8
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
9
|
+
}
|
|
10
|
+
const binary = atob(value);
|
|
11
|
+
const bytes = new Uint8Array(binary.length);
|
|
12
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
13
|
+
bytes[i] = binary.charCodeAt(i);
|
|
14
|
+
}
|
|
15
|
+
return bytes;
|
|
16
|
+
};
|
|
17
|
+
// See aesGcmCodec.ts: bridges Uint8Array<ArrayBufferLike> to BufferSource.
|
|
18
|
+
const asBufferSource = (bytes) => bytes;
|
|
19
|
+
/**
|
|
20
|
+
* Wrap key resolution + caching so concurrent `getKey` calls for the same user
|
|
21
|
+
* share one in-flight promise (two racing calls must never persist two
|
|
22
|
+
* different keys — the loser's key would silently fail to decrypt later).
|
|
23
|
+
*/
|
|
24
|
+
const createCachedKeyResolver = ({ cacheDbName, deriveKey, scope, }) => {
|
|
25
|
+
const inFlight = new Map();
|
|
26
|
+
const resolveKey = async ({ userId }) => {
|
|
27
|
+
const cacheKey = `${scope}:${userId}`;
|
|
28
|
+
const cached = await idbGet({ databaseName: cacheDbName, key: cacheKey });
|
|
29
|
+
if (cached) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
const key = await deriveKey({ userId });
|
|
33
|
+
await idbSet({ databaseName: cacheDbName, key: cacheKey, value: key });
|
|
34
|
+
return key;
|
|
35
|
+
};
|
|
36
|
+
const getKey = ({ userId }) => {
|
|
37
|
+
const existing = inFlight.get(userId);
|
|
38
|
+
if (existing) {
|
|
39
|
+
return existing;
|
|
40
|
+
}
|
|
41
|
+
const promise = resolveKey({ userId }).catch((error) => {
|
|
42
|
+
// Failed resolutions must not poison future attempts (e.g. offline fetch).
|
|
43
|
+
inFlight.delete(userId);
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
inFlight.set(userId, promise);
|
|
47
|
+
return promise;
|
|
48
|
+
};
|
|
49
|
+
return { getKey };
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Default web key provider: fetches per-user key material from the server
|
|
53
|
+
* (`GET /sync/key`, wired by the caller), HKDF-SHA256-derives a non-extractable
|
|
54
|
+
* AES-256-GCM key with salt `${appName}:${userId}`, and caches the derived
|
|
55
|
+
* CryptoKey in IndexedDB so an offline cold start needs no network. A cache hit
|
|
56
|
+
* skips `fetchKeyMaterial` entirely.
|
|
57
|
+
*/
|
|
58
|
+
export const createServerKeyProvider = ({ appName, fetchKeyMaterial, cacheDbName = DEFAULT_KEY_CACHE_DB_NAME, }) => {
|
|
59
|
+
const deriveKey = async ({ userId }) => {
|
|
60
|
+
const subtle = getSubtleCrypto();
|
|
61
|
+
const material = fromBase64(await fetchKeyMaterial());
|
|
62
|
+
if (material.length !== SERVER_KEY_MATERIAL_BYTES) {
|
|
63
|
+
throw new Error(`Server key material must be ${SERVER_KEY_MATERIAL_BYTES} bytes, got ${material.length}`);
|
|
64
|
+
}
|
|
65
|
+
const baseKey = await subtle.importKey("raw", asBufferSource(material), "HKDF", false, [
|
|
66
|
+
"deriveKey",
|
|
67
|
+
]);
|
|
68
|
+
return subtle.deriveKey({
|
|
69
|
+
hash: "SHA-256",
|
|
70
|
+
info: new Uint8Array(0),
|
|
71
|
+
name: "HKDF",
|
|
72
|
+
salt: asBufferSource(new TextEncoder().encode(`${appName}:${userId}`)),
|
|
73
|
+
}, baseKey, { length: 256, name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
74
|
+
};
|
|
75
|
+
return createCachedKeyResolver({ cacheDbName, deriveKey, scope: `server:${appName}` });
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Device-local key provider: generates a random non-extractable AES-256-GCM key
|
|
79
|
+
* on first use and persists it in IndexedDB for reuse across sessions. Data
|
|
80
|
+
* encrypted with it is only readable on this device (no server escrow).
|
|
81
|
+
*/
|
|
82
|
+
export const createLocalKeyProvider = ({ cacheDbName = DEFAULT_KEY_CACHE_DB_NAME, } = {}) => {
|
|
83
|
+
const deriveKey = async () => getSubtleCrypto().generateKey({ length: 256, name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
84
|
+
return createCachedKeyResolver({ cacheDbName, deriveKey, scope: "local" });
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* AES-GCM codec whose key is resolved lazily from a {@link KeyProvider} on
|
|
88
|
+
* first use. Lets persister factories stay synchronous while key
|
|
89
|
+
* fetch/derivation happens on the first load/save.
|
|
90
|
+
*/
|
|
91
|
+
export const createKeyProviderCodec = ({ keyProvider, userId, }) => {
|
|
92
|
+
let codecPromise;
|
|
93
|
+
const resolveCodec = () => {
|
|
94
|
+
codecPromise ?? (codecPromise = keyProvider.getKey({ userId }).then((key) => createAesGcmCodec({ key })));
|
|
95
|
+
return codecPromise;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
decode: async (payload) => (await resolveCodec()).decode(payload),
|
|
99
|
+
encode: async (plaintext) => (await resolveCodec()).encode(plaintext),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=keyProviders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyProviders.js","sourceRoot":"","sources":["../../src/crypto/keyProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAGjE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE/D,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAc,EAAE;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IACtD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AAmB,EAAmB,EAAE,CAAC,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;QAC9F,MAAM,EAAE,KAAK,EAAE,SAAiB,EAAuB,EAAE,CACvD,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;KAC3C,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyProviders.test.d.ts","sourceRoot":"","sources":["../../src/crypto/keyProviders.test.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import "fake-indexeddb/auto";
|
|
2
|
+
import { describe, expect, it, mock } from "bun:test";
|
|
3
|
+
import { idbGet } from "../storage/idb";
|
|
4
|
+
import { createAesGcmCodec, PayloadIntegrityError } from "./aesGcmCodec";
|
|
5
|
+
import { createKeyProviderCodec, createLocalKeyProvider, createServerKeyProvider, } from "./keyProviders";
|
|
6
|
+
let dbCounter = 0;
|
|
7
|
+
const uniqueDbName = () => `key-cache-test-${Date.now()}-${dbCounter++}`;
|
|
8
|
+
const randomMaterialBase64 = () => Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64");
|
|
9
|
+
const roundTripAcrossKeys = async ({ decryptKey, encryptKey, }) => {
|
|
10
|
+
const payload = await createAesGcmCodec({ key: encryptKey }).encode("cross-key payload");
|
|
11
|
+
return createAesGcmCodec({ key: decryptKey }).decode(payload);
|
|
12
|
+
};
|
|
13
|
+
describe("createServerKeyProvider", () => {
|
|
14
|
+
it("derives a non-extractable AES-GCM key", async () => {
|
|
15
|
+
const provider = createServerKeyProvider({
|
|
16
|
+
appName: "demo",
|
|
17
|
+
cacheDbName: uniqueDbName(),
|
|
18
|
+
fetchKeyMaterial: async () => randomMaterialBase64(),
|
|
19
|
+
});
|
|
20
|
+
const key = await provider.getKey({ userId: "u1" });
|
|
21
|
+
expect(key.extractable).toBe(false);
|
|
22
|
+
expect(key.algorithm.name).toBe("AES-GCM");
|
|
23
|
+
expect(key.algorithm.length).toBe(256);
|
|
24
|
+
});
|
|
25
|
+
it("derives deterministically: same material + salt yields interoperable keys", async () => {
|
|
26
|
+
const material = randomMaterialBase64();
|
|
27
|
+
const providerA = createServerKeyProvider({
|
|
28
|
+
appName: "demo",
|
|
29
|
+
cacheDbName: uniqueDbName(),
|
|
30
|
+
fetchKeyMaterial: async () => material,
|
|
31
|
+
});
|
|
32
|
+
const providerB = createServerKeyProvider({
|
|
33
|
+
appName: "demo",
|
|
34
|
+
cacheDbName: uniqueDbName(),
|
|
35
|
+
fetchKeyMaterial: async () => material,
|
|
36
|
+
});
|
|
37
|
+
const decrypted = await roundTripAcrossKeys({
|
|
38
|
+
decryptKey: await providerB.getKey({ userId: "u1" }),
|
|
39
|
+
encryptKey: await providerA.getKey({ userId: "u1" }),
|
|
40
|
+
});
|
|
41
|
+
expect(decrypted).toBe("cross-key payload");
|
|
42
|
+
});
|
|
43
|
+
it("derives distinct keys per userId (salt isolation)", async () => {
|
|
44
|
+
const material = randomMaterialBase64();
|
|
45
|
+
const provider = createServerKeyProvider({
|
|
46
|
+
appName: "demo",
|
|
47
|
+
cacheDbName: uniqueDbName(),
|
|
48
|
+
fetchKeyMaterial: async () => material,
|
|
49
|
+
});
|
|
50
|
+
expect(roundTripAcrossKeys({
|
|
51
|
+
decryptKey: await provider.getKey({ userId: "u2" }),
|
|
52
|
+
encryptKey: await provider.getKey({ userId: "u1" }),
|
|
53
|
+
})).rejects.toBeInstanceOf(PayloadIntegrityError);
|
|
54
|
+
});
|
|
55
|
+
it("derives distinct keys per appName (salt isolation)", async () => {
|
|
56
|
+
const material = randomMaterialBase64();
|
|
57
|
+
const providerA = createServerKeyProvider({
|
|
58
|
+
appName: "app-a",
|
|
59
|
+
cacheDbName: uniqueDbName(),
|
|
60
|
+
fetchKeyMaterial: async () => material,
|
|
61
|
+
});
|
|
62
|
+
const providerB = createServerKeyProvider({
|
|
63
|
+
appName: "app-b",
|
|
64
|
+
cacheDbName: uniqueDbName(),
|
|
65
|
+
fetchKeyMaterial: async () => material,
|
|
66
|
+
});
|
|
67
|
+
expect(roundTripAcrossKeys({
|
|
68
|
+
decryptKey: await providerB.getKey({ userId: "u1" }),
|
|
69
|
+
encryptKey: await providerA.getKey({ userId: "u1" }),
|
|
70
|
+
})).rejects.toBeInstanceOf(PayloadIntegrityError);
|
|
71
|
+
});
|
|
72
|
+
it("skips the fetch on a cache hit (repeat and concurrent calls)", async () => {
|
|
73
|
+
const fetchKeyMaterial = mock(async () => randomMaterialBase64());
|
|
74
|
+
const provider = createServerKeyProvider({
|
|
75
|
+
appName: "demo",
|
|
76
|
+
cacheDbName: uniqueDbName(),
|
|
77
|
+
fetchKeyMaterial,
|
|
78
|
+
});
|
|
79
|
+
const [k1, k2] = await Promise.all([
|
|
80
|
+
provider.getKey({ userId: "u1" }),
|
|
81
|
+
provider.getKey({ userId: "u1" }),
|
|
82
|
+
]);
|
|
83
|
+
expect(k1).toBe(k2);
|
|
84
|
+
await provider.getKey({ userId: "u1" });
|
|
85
|
+
expect(fetchKeyMaterial).toHaveBeenCalledTimes(1);
|
|
86
|
+
});
|
|
87
|
+
it("cold-starts offline from the IndexedDB cache without any network", async () => {
|
|
88
|
+
const cacheDbName = uniqueDbName();
|
|
89
|
+
const material = randomMaterialBase64();
|
|
90
|
+
const onlineProvider = createServerKeyProvider({
|
|
91
|
+
appName: "demo",
|
|
92
|
+
cacheDbName,
|
|
93
|
+
fetchKeyMaterial: async () => material,
|
|
94
|
+
});
|
|
95
|
+
const onlineKey = await onlineProvider.getKey({ userId: "u1" });
|
|
96
|
+
const offlineProvider = createServerKeyProvider({
|
|
97
|
+
appName: "demo",
|
|
98
|
+
cacheDbName,
|
|
99
|
+
fetchKeyMaterial: async () => {
|
|
100
|
+
throw new Error("network unavailable");
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const offlineKey = await offlineProvider.getKey({ userId: "u1" });
|
|
104
|
+
const decrypted = await roundTripAcrossKeys({ decryptKey: offlineKey, encryptKey: onlineKey });
|
|
105
|
+
expect(decrypted).toBe("cross-key payload");
|
|
106
|
+
});
|
|
107
|
+
it("rejects key material that is not exactly 32 bytes", async () => {
|
|
108
|
+
const provider = createServerKeyProvider({
|
|
109
|
+
appName: "demo",
|
|
110
|
+
cacheDbName: uniqueDbName(),
|
|
111
|
+
fetchKeyMaterial: async () => Buffer.from(crypto.getRandomValues(new Uint8Array(16))).toString("base64"),
|
|
112
|
+
});
|
|
113
|
+
expect(provider.getKey({ userId: "u1" })).rejects.toThrow("32 bytes");
|
|
114
|
+
});
|
|
115
|
+
it("does not poison future attempts after a failed fetch", async () => {
|
|
116
|
+
const material = randomMaterialBase64();
|
|
117
|
+
let shouldFail = true;
|
|
118
|
+
const provider = createServerKeyProvider({
|
|
119
|
+
appName: "demo",
|
|
120
|
+
cacheDbName: uniqueDbName(),
|
|
121
|
+
fetchKeyMaterial: async () => {
|
|
122
|
+
if (shouldFail) {
|
|
123
|
+
throw new Error("network unavailable");
|
|
124
|
+
}
|
|
125
|
+
return material;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
expect(provider.getKey({ userId: "u1" })).rejects.toThrow("network unavailable");
|
|
129
|
+
shouldFail = false;
|
|
130
|
+
const key = await provider.getKey({ userId: "u1" });
|
|
131
|
+
expect(key.type).toBe("secret");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe("createLocalKeyProvider", () => {
|
|
135
|
+
it("generates a non-extractable AES-GCM key on first use", async () => {
|
|
136
|
+
const provider = createLocalKeyProvider({ cacheDbName: uniqueDbName() });
|
|
137
|
+
const key = await provider.getKey({ userId: "u1" });
|
|
138
|
+
expect(key.extractable).toBe(false);
|
|
139
|
+
expect(key.algorithm.name).toBe("AES-GCM");
|
|
140
|
+
expect(key.algorithm.length).toBe(256);
|
|
141
|
+
});
|
|
142
|
+
it("persists the key across fresh provider instances (same IndexedDB)", async () => {
|
|
143
|
+
const cacheDbName = uniqueDbName();
|
|
144
|
+
const first = await createLocalKeyProvider({ cacheDbName }).getKey({ userId: "u1" });
|
|
145
|
+
const second = await createLocalKeyProvider({ cacheDbName }).getKey({ userId: "u1" });
|
|
146
|
+
const decrypted = await roundTripAcrossKeys({ decryptKey: second, encryptKey: first });
|
|
147
|
+
expect(decrypted).toBe("cross-key payload");
|
|
148
|
+
});
|
|
149
|
+
it("shares one key across concurrent first calls (no split-brain keys)", async () => {
|
|
150
|
+
const provider = createLocalKeyProvider({ cacheDbName: uniqueDbName() });
|
|
151
|
+
const [k1, k2] = await Promise.all([
|
|
152
|
+
provider.getKey({ userId: "u1" }),
|
|
153
|
+
provider.getKey({ userId: "u1" }),
|
|
154
|
+
]);
|
|
155
|
+
expect(k1).toBe(k2);
|
|
156
|
+
});
|
|
157
|
+
it("scopes keys per userId", async () => {
|
|
158
|
+
const provider = createLocalKeyProvider({ cacheDbName: uniqueDbName() });
|
|
159
|
+
expect(roundTripAcrossKeys({
|
|
160
|
+
decryptKey: await provider.getKey({ userId: "u2" }),
|
|
161
|
+
encryptKey: await provider.getKey({ userId: "u1" }),
|
|
162
|
+
})).rejects.toBeInstanceOf(PayloadIntegrityError);
|
|
163
|
+
});
|
|
164
|
+
it("caches the CryptoKey itself in IndexedDB", async () => {
|
|
165
|
+
const cacheDbName = uniqueDbName();
|
|
166
|
+
await createLocalKeyProvider({ cacheDbName }).getKey({ userId: "u1" });
|
|
167
|
+
const stored = await idbGet({ databaseName: cacheDbName, key: "local:u1" });
|
|
168
|
+
expect(stored).toBeInstanceOf(CryptoKey);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe("createKeyProviderCodec", () => {
|
|
172
|
+
it("round-trips using a lazily resolved key", async () => {
|
|
173
|
+
const provider = createLocalKeyProvider({ cacheDbName: uniqueDbName() });
|
|
174
|
+
const codec = createKeyProviderCodec({ keyProvider: provider, userId: "u1" });
|
|
175
|
+
const payload = await codec.encode("lazy key payload");
|
|
176
|
+
expect(await codec.decode(payload)).toBe("lazy key payload");
|
|
177
|
+
});
|
|
178
|
+
it("resolves the key from the provider exactly once", async () => {
|
|
179
|
+
const inner = createLocalKeyProvider({ cacheDbName: uniqueDbName() });
|
|
180
|
+
const getKey = mock(({ userId }) => inner.getKey({ userId }));
|
|
181
|
+
const spyProvider = { getKey };
|
|
182
|
+
const codec = createKeyProviderCodec({ keyProvider: spyProvider, userId: "u1" });
|
|
183
|
+
await codec.decode(await codec.encode("a"));
|
|
184
|
+
await codec.encode("b");
|
|
185
|
+
expect(getKey).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(getKey).toHaveBeenCalledWith({ userId: "u1" });
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
//# sourceMappingURL=keyProviders.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyProviders.test.js","sourceRoot":"","sources":["../../src/crypto/keyProviders.test.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAC,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAC,iBAAiB,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AAGxB,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC,kBAAkB,IAAI,CAAC,GAAG,EAAE,IAAI,SAAS,EAAE,EAAE,CAAC;AAEjF,MAAM,oBAAoB,GAAG,GAAW,EAAE,CACxC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC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5E,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACvD,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/D,MAAM,KAAK,GAAG,sBAAsB,CAAC,EAAC,WAAW,EAAE,YAAY,EAAE,EAAC,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,EAAC,MAAM,EAAmB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC;QAC5E,MAAM,WAAW,GAAgB,EAAC,MAAM,EAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,sBAAsB,CAAC,EAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;QAC/E,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5C,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,CAAC,oBAAoB,CAAC,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption primitives for at-rest protection of persisted data. Encryption is
|
|
3
|
+
* applied at the persistence boundary (the serialized store blob), keeping the
|
|
4
|
+
* in-memory store plaintext for querying while only ciphertext lands in
|
|
5
|
+
* IndexedDB/SQLite.
|
|
6
|
+
*/
|
|
7
|
+
/** Symmetric codec applied to the serialized store blob before persistence. */
|
|
8
|
+
export interface PayloadCodec {
|
|
9
|
+
/** Encrypt/encode a plaintext string into a binary payload for storage. */
|
|
10
|
+
encode(plaintext: string): Promise<Uint8Array>;
|
|
11
|
+
/** Decrypt/decode a previously encoded binary payload. */
|
|
12
|
+
decode(payload: Uint8Array): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the per-user symmetric encryption key. Implementations must return
|
|
16
|
+
* non-extractable AES-GCM keys so raw key bytes never sit in page-inspectable
|
|
17
|
+
* memory or storage.
|
|
18
|
+
*/
|
|
19
|
+
export interface KeyProvider {
|
|
20
|
+
getKey({ userId }: {
|
|
21
|
+
userId: string;
|
|
22
|
+
}): Promise<CryptoKey>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/crypto/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,0DAA0D;IAC1D,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAC,MAAM,EAAC,EAAE;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption primitives for at-rest protection of persisted data. Encryption is
|
|
3
|
+
* applied at the persistence boundary (the serialized store blob), keeping the
|
|
4
|
+
* in-memory store plaintext for querying while only ciphertext lands in
|
|
5
|
+
* IndexedDB/SQLite.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/crypto/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-window bridge for the SyncDB debug log.
|
|
3
|
+
*
|
|
4
|
+
* The debug log (see `debugLog.ts`) is an in-memory, per-client recorder. Each
|
|
5
|
+
* browser window loads the app bundle fresh, so it builds its own `SyncDb`
|
|
6
|
+
* singleton with its own log. That means the debugger — which is designed to run
|
|
7
|
+
* side-by-side in a SECOND browser window — never sees local mutations recorded
|
|
8
|
+
* by the primary app window: they live only in the app window's heap.
|
|
9
|
+
*
|
|
10
|
+
* This bridge mirrors locally-recorded events onto a `BroadcastChannel` and
|
|
11
|
+
* re-records events received from peer windows into the local log, so a debugger
|
|
12
|
+
* open in any window shows the full picture (local mutations included), live.
|
|
13
|
+
*
|
|
14
|
+
* It is web-only: on native / SSR / older runtimes without `BroadcastChannel`
|
|
15
|
+
* the default factory returns nothing and `attachDebugChannel` no-ops. The
|
|
16
|
+
* channel is only ever created when a debug log exists (dev builds by default),
|
|
17
|
+
* so there is zero overhead in production where debug is off.
|
|
18
|
+
*/
|
|
19
|
+
import type { SyncDebugEvent, SyncDebugLog } from "./debugLog";
|
|
20
|
+
/** Message shape sent between windows. `origin` lets a sender ignore echoes. */
|
|
21
|
+
interface DebugChannelMessage {
|
|
22
|
+
origin: string;
|
|
23
|
+
event: SyncDebugEvent;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Minimal structural subset of the DOM `BroadcastChannel` we rely on. Declared
|
|
27
|
+
* locally (rather than depending on DOM lib types) so the package compiles under
|
|
28
|
+
* a non-DOM `lib` and so tests can inject an in-memory fake.
|
|
29
|
+
*/
|
|
30
|
+
export interface DebugBroadcastChannelLike {
|
|
31
|
+
postMessage: (message: DebugChannelMessage) => void;
|
|
32
|
+
close: () => void;
|
|
33
|
+
onmessage: ((event: {
|
|
34
|
+
data: DebugChannelMessage;
|
|
35
|
+
}) => void) | null;
|
|
36
|
+
}
|
|
37
|
+
export interface DebugChannelBridge {
|
|
38
|
+
/** Tear down: stop mirroring and close the underlying channel. */
|
|
39
|
+
close: () => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Wire a debug log to peer windows. Returns `undefined` when no channel is
|
|
43
|
+
* available (native / SSR), in which case the log stays purely local.
|
|
44
|
+
*/
|
|
45
|
+
export declare const attachDebugChannel: ({ log, name, createChannel, }: {
|
|
46
|
+
log: SyncDebugLog;
|
|
47
|
+
name: string;
|
|
48
|
+
/** Channel factory; injectable for tests. Defaults to a real BroadcastChannel. */
|
|
49
|
+
createChannel?: (channelName: string) => DebugBroadcastChannelLike | undefined;
|
|
50
|
+
}) => DebugChannelBridge | undefined;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=debugChannel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugChannel.d.ts","sourceRoot":"","sources":["../../src/debug/debugChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,YAAY,CAAC;AAK7D,gFAAgF;AAChF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,cAAc,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACpD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE;QAAC,IAAI,EAAE,mBAAmB,CAAA;KAAC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAClE;AAED,MAAM,WAAW,kBAAkB;IACjC,kEAAkE;IAClE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AASD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,+BAIhC;IACD,GAAG,EAAE,YAAY,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,kFAAkF;IAClF,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,yBAAyB,GAAG,SAAS,CAAC;CAChF,KAAG,kBAAkB,GAAG,SA6CxB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-window bridge for the SyncDB debug log.
|
|
3
|
+
*
|
|
4
|
+
* The debug log (see `debugLog.ts`) is an in-memory, per-client recorder. Each
|
|
5
|
+
* browser window loads the app bundle fresh, so it builds its own `SyncDb`
|
|
6
|
+
* singleton with its own log. That means the debugger — which is designed to run
|
|
7
|
+
* side-by-side in a SECOND browser window — never sees local mutations recorded
|
|
8
|
+
* by the primary app window: they live only in the app window's heap.
|
|
9
|
+
*
|
|
10
|
+
* This bridge mirrors locally-recorded events onto a `BroadcastChannel` and
|
|
11
|
+
* re-records events received from peer windows into the local log, so a debugger
|
|
12
|
+
* open in any window shows the full picture (local mutations included), live.
|
|
13
|
+
*
|
|
14
|
+
* It is web-only: on native / SSR / older runtimes without `BroadcastChannel`
|
|
15
|
+
* the default factory returns nothing and `attachDebugChannel` no-ops. The
|
|
16
|
+
* channel is only ever created when a debug log exists (dev builds by default),
|
|
17
|
+
* so there is zero overhead in production where debug is off.
|
|
18
|
+
*/
|
|
19
|
+
/** Channel name prefix; scoped per db `name` so unrelated apps never cross-talk. */
|
|
20
|
+
const CHANNEL_PREFIX = "terreno-syncdb-debug";
|
|
21
|
+
const defaultChannelFactory = (channelName) => {
|
|
22
|
+
if (typeof BroadcastChannel === "undefined") {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return new BroadcastChannel(channelName);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Wire a debug log to peer windows. Returns `undefined` when no channel is
|
|
29
|
+
* available (native / SSR), in which case the log stays purely local.
|
|
30
|
+
*/
|
|
31
|
+
export const attachDebugChannel = ({ log, name, createChannel = defaultChannelFactory, }) => {
|
|
32
|
+
const channel = createChannel(`${CHANNEL_PREFIX}:${name}`);
|
|
33
|
+
if (!channel) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
// Unique per bridge instance (i.e. per window). Used to drop echoes and to
|
|
37
|
+
// keep a peer's re-recorded event from bouncing back and forth forever.
|
|
38
|
+
const origin = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
39
|
+
// True only while we are re-recording a peer's event into the local log, so
|
|
40
|
+
// the subscribe callback below skips broadcasting it back out (no echo loop).
|
|
41
|
+
let ingestingRemote = false;
|
|
42
|
+
const unsubscribe = log.subscribe((event) => {
|
|
43
|
+
if (ingestingRemote) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
channel.postMessage({ event, origin });
|
|
47
|
+
});
|
|
48
|
+
channel.onmessage = (messageEvent) => {
|
|
49
|
+
const data = messageEvent.data;
|
|
50
|
+
if (!data || data.origin === origin) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Re-record the peer's event locally: it gets a fresh local id (ids only need
|
|
54
|
+
// to be monotonic within a window) but keeps its original timestamp, type, and
|
|
55
|
+
// detail so the debugger renders it inline with local events.
|
|
56
|
+
const { id: _id, ...input } = data.event;
|
|
57
|
+
ingestingRemote = true;
|
|
58
|
+
try {
|
|
59
|
+
log.record(input);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
ingestingRemote = false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
close: () => {
|
|
67
|
+
unsubscribe();
|
|
68
|
+
channel.onmessage = null;
|
|
69
|
+
channel.close();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
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AC,SAAS,GAAG,CAAC,YAAY,EAAQ,EAAE;QACzC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;QAC/B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YACpC,OAAO;QACT,CAAC;QACD,8EAA8E;QAC9E,+EAA+E;QAC/E,8DAA8D;QAC9D,MAAM,EAAC,EAAE,EAAE,GAAG,EAAE,GAAG,KAAK,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACvC,eAAe,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,eAAe,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,GAAS,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;YACzB,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugChannel.test.d.ts","sourceRoot":"","sources":["../../src/debug/debugChannel.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { attachDebugChannel } from "./debugChannel";
|
|
3
|
+
import { createSyncDebugLog } from "./debugLog";
|
|
4
|
+
/**
|
|
5
|
+
* An in-memory BroadcastChannel hub so tests exercise the bridge without a real
|
|
6
|
+
* DOM `BroadcastChannel`. Every channel created from the same hub delivers each
|
|
7
|
+
* `postMessage` to all OTHER channels (never back to the sender), mirroring the
|
|
8
|
+
* real cross-window semantics we depend on.
|
|
9
|
+
*/
|
|
10
|
+
const createChannelHub = () => {
|
|
11
|
+
const channels = new Set();
|
|
12
|
+
return {
|
|
13
|
+
create: (_name) => {
|
|
14
|
+
const channel = {
|
|
15
|
+
close: () => {
|
|
16
|
+
channels.delete(channel);
|
|
17
|
+
},
|
|
18
|
+
onmessage: null,
|
|
19
|
+
postMessage: (message) => {
|
|
20
|
+
for (const peer of channels) {
|
|
21
|
+
if (peer !== channel) {
|
|
22
|
+
peer.onmessage?.({ data: message });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
channels.add(channel);
|
|
28
|
+
return channel;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
describe("attachDebugChannel", () => {
|
|
33
|
+
it("returns undefined when no channel is available (native/SSR)", () => {
|
|
34
|
+
const log = createSyncDebugLog();
|
|
35
|
+
const bridge = attachDebugChannel({
|
|
36
|
+
createChannel: () => undefined,
|
|
37
|
+
log,
|
|
38
|
+
name: "app",
|
|
39
|
+
});
|
|
40
|
+
expect(bridge).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
it("mirrors a locally-recorded event into a peer window's log", () => {
|
|
43
|
+
const hub = createChannelHub();
|
|
44
|
+
const appLog = createSyncDebugLog();
|
|
45
|
+
const debuggerLog = createSyncDebugLog();
|
|
46
|
+
attachDebugChannel({ createChannel: hub.create, log: appLog, name: "app" });
|
|
47
|
+
attachDebugChannel({ createChannel: hub.create, log: debuggerLog, name: "app" });
|
|
48
|
+
appLog.record({
|
|
49
|
+
collection: "todos",
|
|
50
|
+
detail: { data: { title: "buy milk" } },
|
|
51
|
+
direction: "local",
|
|
52
|
+
entityId: "t1",
|
|
53
|
+
label: "create todos/t1",
|
|
54
|
+
operation: "create",
|
|
55
|
+
type: "mutate",
|
|
56
|
+
});
|
|
57
|
+
const mirrored = debuggerLog.getEvents();
|
|
58
|
+
expect(mirrored).toHaveLength(1);
|
|
59
|
+
expect(mirrored[0].type).toBe("mutate");
|
|
60
|
+
expect(mirrored[0].label).toBe("create todos/t1");
|
|
61
|
+
// The create/update body survives the hop so the debugger can show it.
|
|
62
|
+
expect(mirrored[0].detail?.data).toEqual({ title: "buy milk" });
|
|
63
|
+
});
|
|
64
|
+
it("preserves the original timestamp but assigns a fresh local id on the peer", () => {
|
|
65
|
+
const hub = createChannelHub();
|
|
66
|
+
const appLog = createSyncDebugLog();
|
|
67
|
+
const debuggerLog = createSyncDebugLog();
|
|
68
|
+
// Pre-seed the peer so its next id differs from the source event's id.
|
|
69
|
+
debuggerLog.record({ direction: "system", label: "seed", type: "connect" });
|
|
70
|
+
attachDebugChannel({ createChannel: hub.create, log: appLog, name: "app" });
|
|
71
|
+
attachDebugChannel({ createChannel: hub.create, log: debuggerLog, name: "app" });
|
|
72
|
+
const source = appLog.record({
|
|
73
|
+
direction: "local",
|
|
74
|
+
label: "create todos/t1",
|
|
75
|
+
timestamp: "2026-07-16T16:01:45.011-07:00",
|
|
76
|
+
type: "mutate",
|
|
77
|
+
});
|
|
78
|
+
const mirrored = debuggerLog.getEvents().find((event) => event.label === "create todos/t1");
|
|
79
|
+
expect(mirrored?.timestamp).toBe("2026-07-16T16:01:45.011-07:00");
|
|
80
|
+
expect(mirrored?.id).not.toBe(source.id);
|
|
81
|
+
});
|
|
82
|
+
it("does not echo a mirrored event back to the origin (no infinite loop)", () => {
|
|
83
|
+
const hub = createChannelHub();
|
|
84
|
+
const appLog = createSyncDebugLog();
|
|
85
|
+
const debuggerLog = createSyncDebugLog();
|
|
86
|
+
attachDebugChannel({ createChannel: hub.create, log: appLog, name: "app" });
|
|
87
|
+
attachDebugChannel({ createChannel: hub.create, log: debuggerLog, name: "app" });
|
|
88
|
+
appLog.record({ direction: "local", label: "one", type: "mutate" });
|
|
89
|
+
// The source window keeps exactly one event; the peer's re-record must not
|
|
90
|
+
// bounce back and inflate the source log.
|
|
91
|
+
expect(appLog.getEvents()).toHaveLength(1);
|
|
92
|
+
expect(debuggerLog.getEvents()).toHaveLength(1);
|
|
93
|
+
});
|
|
94
|
+
it("stops mirroring after close()", () => {
|
|
95
|
+
const hub = createChannelHub();
|
|
96
|
+
const appLog = createSyncDebugLog();
|
|
97
|
+
const debuggerLog = createSyncDebugLog();
|
|
98
|
+
const appBridge = attachDebugChannel({ createChannel: hub.create, log: appLog, name: "app" });
|
|
99
|
+
attachDebugChannel({ createChannel: hub.create, log: debuggerLog, name: "app" });
|
|
100
|
+
appBridge?.close();
|
|
101
|
+
appLog.record({ direction: "local", label: "after close", type: "mutate" });
|
|
102
|
+
expect(debuggerLog.getEvents()).toHaveLength(0);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=debugChannel.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugChannel.test.js","sourceRoot":"","sources":["../../src/debug/debugChannel.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAC,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAC,kBAAkB,EAAiC,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAC,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,GAEvB,EAAE;IACF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IACtD,OAAO;QACL,MAAM,EAAE,CAAC,KAAa,EAA6B,EAAE;YACnD,MAAM,OAAO,GAA8B;gBACzC,KAAK,EAAE,GAAG,EAAE;oBACV,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC3B,CAAC;gBACD,SAAS,EAAE,IAAI;gBACf,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE;oBACvB,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;wBAC5B,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;4BACrB,IAAI,CAAC,SAAS,EAAE,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;wBACpC,CAAC;oBACH,CAAC;gBACH,CAAC;aACF,CAAC;YACF,QAAQ,C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