@interop/was-react 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +4 -3
  2. package/dist/auth/verifyResponse.d.ts.map +1 -1
  3. package/dist/auth/verifyResponse.js +10 -5
  4. package/dist/auth/verifyResponse.js.map +1 -1
  5. package/dist/identity/agents.d.ts +5 -0
  6. package/dist/identity/agents.d.ts.map +1 -1
  7. package/dist/identity/agents.js +10 -3
  8. package/dist/identity/agents.js.map +1 -1
  9. package/dist/identity/seedCredential.d.ts +5 -1
  10. package/dist/identity/seedCredential.d.ts.map +1 -1
  11. package/dist/identity/seedCredential.js +15 -28
  12. package/dist/identity/seedCredential.js.map +1 -1
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +7 -6
  16. package/dist/index.js.map +1 -1
  17. package/dist/react/hooks.d.ts +3 -2
  18. package/dist/react/hooks.d.ts.map +1 -1
  19. package/dist/react/hooks.js +8 -4
  20. package/dist/react/hooks.js.map +1 -1
  21. package/dist/session/authStore.d.ts +9 -0
  22. package/dist/session/authStore.d.ts.map +1 -1
  23. package/dist/session/authStore.js +69 -40
  24. package/dist/session/authStore.js.map +1 -1
  25. package/dist/session/localWipe.d.ts +1 -1
  26. package/dist/session/localWipe.js +2 -2
  27. package/dist/session/localWipe.js.map +1 -1
  28. package/dist/storage/adopt.d.ts +4 -1
  29. package/dist/storage/adopt.d.ts.map +1 -1
  30. package/dist/storage/adopt.js +4 -3
  31. package/dist/storage/adopt.js.map +1 -1
  32. package/dist/storage/entityStore.d.ts.map +1 -1
  33. package/dist/storage/entityStore.js +3 -0
  34. package/dist/storage/entityStore.js.map +1 -1
  35. package/dist/storage/publicUrl.js +3 -3
  36. package/dist/storage/storageContext.d.ts +175 -0
  37. package/dist/storage/storageContext.d.ts.map +1 -0
  38. package/dist/storage/storageContext.js +327 -0
  39. package/dist/storage/storageContext.js.map +1 -0
  40. package/dist/storage/storageManager.d.ts +57 -76
  41. package/dist/storage/storageManager.d.ts.map +1 -1
  42. package/dist/storage/storageManager.js +55 -150
  43. package/dist/storage/storageManager.js.map +1 -1
  44. package/dist/storage/syncController.d.ts +10 -1
  45. package/dist/storage/syncController.d.ts.map +1 -1
  46. package/dist/storage/syncController.js +12 -4
  47. package/dist/storage/syncController.js.map +1 -1
  48. package/dist/storage/syncStatusStore.d.ts +23 -2
  49. package/dist/storage/syncStatusStore.d.ts.map +1 -1
  50. package/dist/storage/syncStatusStore.js +22 -13
  51. package/dist/storage/syncStatusStore.js.map +1 -1
  52. package/dist/storage/writerId.d.ts +36 -0
  53. package/dist/storage/writerId.d.ts.map +1 -0
  54. package/dist/storage/writerId.js +76 -0
  55. package/dist/storage/writerId.js.map +1 -0
  56. package/package.json +9 -9
  57. package/dist/storage/rehydrate.d.ts +0 -64
  58. package/dist/storage/rehydrate.d.ts.map +0 -1
  59. package/dist/storage/rehydrate.js +0 -132
  60. package/dist/storage/rehydrate.js.map +0 -1
@@ -1,115 +1,96 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * The storage manager: the one remaining process-wide pointer, to the ACTIVE
6
+ * {@link StorageContext}, plus the app-facing facades over it. Entity stores
7
+ * are created at module level, before any session exists, so their verbs
8
+ * cannot hold a context of their own; they reach the live session through
9
+ * {@link requireStore} / {@link requireRemoteStore} / {@link stampLww} here,
10
+ * which resolve to whichever context is active. Keeping the facade free of
11
+ * store imports (no cycle) also lets the session store own the init/hydrate
12
+ * ordering.
13
+ *
14
+ * Activation is deliberate about the two-providers case: a context with a
15
+ * replica attached is live, and a live context is never replaced -- a second
16
+ * session attaching a replica of its own throws instead of silently taking the
17
+ * facades over. A context without a replica (created but not booted, or torn
18
+ * down) is inert and is replaced without complaint, which is what a React
19
+ * dev-mode double `useState` initializer or a test's sequence of stores needs.
20
+ */
1
21
  import type { LwwFields } from '../sync/lww.js';
2
22
  import type { LocalStore } from './localStore.js';
23
+ import type { StorageContext } from './storageContext.js';
3
24
  import type { WasRemoteStore } from './wasRemoteStore.js';
4
25
  /**
5
- * Installs the opened store (called once by the app bootstrap).
26
+ * Makes `context` the active one (called by the session store at creation, so
27
+ * the facades resolve before any replica opens, again right before it opens a
28
+ * replica, and by {@link StorageContext.attachStore}). Idempotent for the
29
+ * context already active; throws while a DIFFERENT context still has a replica
30
+ * attached.
6
31
  *
7
- * @param store {LocalStore}
32
+ * @param context {StorageContext}
8
33
  * @returns {void}
9
34
  */
10
- export declare function setLocalStore(store: LocalStore): void;
35
+ export declare function activateStorageContext(context: StorageContext): void;
11
36
  /**
12
- * The opened store, or throws if the app has not bootstrapped yet.
37
+ * Releases the active pointer if `context` holds it (a torn-down session); a
38
+ * no-op for any other context.
13
39
  *
14
- * @returns {LocalStore}
40
+ * @param context {StorageContext}
41
+ * @returns {void}
15
42
  */
16
- export declare function requireStore(): LocalStore;
43
+ export declare function deactivateStorageContext(context: StorageContext): void;
17
44
  /**
18
- * Whether the store has been opened.
45
+ * Whether a storage context is active.
19
46
  *
20
47
  * @returns {boolean}
21
48
  */
22
- export declare function hasStore(): boolean;
49
+ export declare function hasStorageContext(): boolean;
23
50
  /**
24
- * Releases the held store reference (logout; the caller closes the db).
51
+ * The active storage context, or throws if no session store has been created.
25
52
  *
26
- * @returns {void}
53
+ * @returns {StorageContext}
27
54
  */
28
- export declare function clearLocalStore(): void;
55
+ export declare function requireStorageContext(): StorageContext;
29
56
  /**
30
- * Installs the per-session delegated remote store (set once background sync
31
- * has bootstrapped it from the granted zcaps).
57
+ * The active session's opened replica, or throws if none is open.
32
58
  *
33
- * @param store {WasRemoteStore}
34
- * @returns {void}
35
- */
36
- export declare function setRemoteStore(store: WasRemoteStore): void;
37
- /**
38
- * The connected session's remote store, or throws while no wallet-connected
39
- * session is active (local-only mode, or sync has not bootstrapped yet).
40
- *
41
- * @returns {WasRemoteStore}
59
+ * @returns {LocalStore}
42
60
  */
43
- export declare function requireRemoteStore(): WasRemoteStore;
61
+ export declare function requireStore(): LocalStore;
44
62
  /**
45
- * Whether a connected session's remote store is available.
63
+ * Whether the active session has a replica open.
46
64
  *
47
65
  * @returns {boolean}
48
66
  */
49
- export declare function hasRemoteStore(): boolean;
50
- /**
51
- * Releases the held remote store reference (logout / sync teardown).
52
- *
53
- * @returns {void}
54
- */
55
- export declare function clearRemoteStore(): void;
67
+ export declare function hasStore(): boolean;
56
68
  /**
57
- * A stable per-install writer id (the last-write-wins tiebreak stamped into
58
- * every payload), persisted in localStorage under `<prefix>writerId`. In an
59
- * environment without `localStorage` it falls back to a process-stable
60
- * unpersisted id instead of throwing.
61
- *
62
- * The id is an unkeyed, clearable attribution label -- never an identity. On a
63
- * miss it adopts a value left under the pre-rename `<prefix>clientId` key and
64
- * removes the old one, so an existing install keeps stamping the same id
65
- * across the rename rather than looking like a second writer.
69
+ * The active session's remote store, or throws while no wallet-connected
70
+ * session is active.
66
71
  *
67
- * @param [options] {object}
68
- * @param [options.storageKeyPrefix] {string} the localStorage key prefix
69
- * (defaults to {@link DEFAULT_STORAGE_KEY_PREFIX})
70
- * @returns {string}
72
+ * @returns {WasRemoteStore}
71
73
  */
72
- export declare function getWriterId({ storageKeyPrefix }?: {
73
- storageKeyPrefix?: string;
74
- }): string;
74
+ export declare function requireRemoteStore(): WasRemoteStore;
75
75
  /**
76
- * Installs the session's resolved writer id (called once by the session store,
77
- * under the app's configured `storageKeyPrefix`, before any replica opens).
76
+ * Whether the active session has a remote store available.
78
77
  *
79
- * @param id {string}
80
- * @returns {void}
78
+ * @returns {boolean}
81
79
  */
82
- export declare function setWriterId(id: string): void;
80
+ export declare function hasRemoteStore(): boolean;
83
81
  /**
84
- * The session's resolved writer id, or throws if it has not been installed
85
- * yet. Deliberately never falls back to {@link getWriterId}: that would resolve
86
- * under the DEFAULT key prefix, so an app with a custom `storageKeyPrefix`
87
- * would silently stamp a second writer id.
82
+ * The active session's writer id, or throws if no session store exists yet.
83
+ * Deliberately never falls back to `getWriterId`: that would resolve under the
84
+ * DEFAULT key prefix, so an app with a custom `storageKeyPrefix` would silently
85
+ * stamp a second writer id.
88
86
  *
89
87
  * @returns {string}
90
88
  */
91
89
  export declare function requireWriterId(): string;
92
90
  /**
93
- * Clears the persisted writer id (the clear-data grade of the wipe): removes
94
- * both the current key and the pre-rename one, so nothing this library wrote
95
- * survives in localStorage. A fresh id is installed in memory rather than the
96
- * resolved one being dropped, because the session keeps running over its new
97
- * anonymous replica and its write verbs still have to stamp; nothing persists
98
- * it, so the next run resolves and stores an id of its own.
99
- *
100
- * @param [options] {object}
101
- * @param [options.storageKeyPrefix] {string} the localStorage key prefix
102
- * (defaults to {@link DEFAULT_STORAGE_KEY_PREFIX})
103
- * @returns {void}
104
- */
105
- export declare function clearWriterId({ storageKeyPrefix }?: {
106
- storageKeyPrefix?: string;
107
- }): void;
108
- /**
109
- * Stamps a payload with fresh last-write-wins fields: the current instant as
110
- * `updatedAt` and the session's resolved writer id. Any values the caller
111
- * supplied are overwritten -- a stamp must describe THIS write, or a hydrated
112
- * doc's older `updatedAt` would ride a later edit and lose the conflict.
91
+ * Stamps a payload with fresh last-write-wins fields under the active session
92
+ * (see {@link StorageContext.stampLww}); the entity-store write verbs call it
93
+ * on every write, and an app writing through `LocalStore` directly does too.
113
94
  *
114
95
  * @param payload {object}
115
96
  * @returns {object} the payload with the LWW fields set
@@ -1 +1 @@
1
- {"version":3,"file":"storageManager.d.ts","sourceRoot":"","sources":["../../src/storage/storageManager.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAKzD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAErD;AAED;;;;GAIG;A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AAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAIzD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAQpE;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAItE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,cAAc,CAOtD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,UAAU,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,cAAc,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAE5E"}
@@ -1,200 +1,105 @@
1
- /*!
2
- * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
- */
4
- /**
5
- * The storage manager: a thin process-wide holder for the one {@link LocalStore}
6
- * instance, the per-session {@link WasRemoteStore}, plus the per-install writer
7
- * id. Entity stores reach for the stores through {@link requireStore} /
8
- * {@link requireRemoteStore} inside their verbs rather than importing them
9
- * directly, which keeps this module free of store imports (no cycle) and lets
10
- * the app own the init/hydrate ordering.
11
- *
12
- * It also owns the writer-id concern end to end: {@link getWriterId} resolves
13
- * the per-install id, {@link setWriterId} installs the session's resolved value,
14
- * {@link clearWriterId} removes it (the clear-data wipe), and {@link stampLww}
15
- * is the one place a payload's last-write-wins fields are minted, so no caller
16
- * has to remember to stamp.
17
- */
18
- import { uuidv7 } from 'uuidv7';
19
- import { DEFAULT_STORAGE_KEY_PREFIX } from '../config.js';
20
- let localStore = null;
21
- let remoteStore = null;
1
+ let active = null;
22
2
  /**
23
- * Installs the opened store (called once by the app bootstrap).
3
+ * Makes `context` the active one (called by the session store at creation, so
4
+ * the facades resolve before any replica opens, again right before it opens a
5
+ * replica, and by {@link StorageContext.attachStore}). Idempotent for the
6
+ * context already active; throws while a DIFFERENT context still has a replica
7
+ * attached.
24
8
  *
25
- * @param store {LocalStore}
9
+ * @param context {StorageContext}
26
10
  * @returns {void}
27
11
  */
28
- export function setLocalStore(store) {
29
- localStore = store;
30
- }
31
- /**
32
- * The opened store, or throws if the app has not bootstrapped yet.
33
- *
34
- * @returns {LocalStore}
35
- */
36
- export function requireStore() {
37
- if (!localStore) {
38
- throw new Error('LocalStore is not initialized; open it first.');
12
+ export function activateStorageContext(context) {
13
+ if (active && active !== context && active.hasStore()) {
14
+ throw new Error('Another storage context still has a replica attached; ' +
15
+ 'one process hosts one live session (one provider) at a time.');
39
16
  }
40
- return localStore;
41
- }
42
- /**
43
- * Whether the store has been opened.
44
- *
45
- * @returns {boolean}
46
- */
47
- export function hasStore() {
48
- return localStore !== null;
17
+ active = context;
49
18
  }
50
19
  /**
51
- * Releases the held store reference (logout; the caller closes the db).
20
+ * Releases the active pointer if `context` holds it (a torn-down session); a
21
+ * no-op for any other context.
52
22
  *
23
+ * @param context {StorageContext}
53
24
  * @returns {void}
54
25
  */
55
- export function clearLocalStore() {
56
- localStore = null;
26
+ export function deactivateStorageContext(context) {
27
+ if (active === context) {
28
+ active = null;
29
+ }
57
30
  }
58
31
  /**
59
- * Installs the per-session delegated remote store (set once background sync
60
- * has bootstrapped it from the granted zcaps).
32
+ * Whether a storage context is active.
61
33
  *
62
- * @param store {WasRemoteStore}
63
- * @returns {void}
34
+ * @returns {boolean}
64
35
  */
65
- export function setRemoteStore(store) {
66
- remoteStore = store;
36
+ export function hasStorageContext() {
37
+ return active !== null;
67
38
  }
68
39
  /**
69
- * The connected session's remote store, or throws while no wallet-connected
70
- * session is active (local-only mode, or sync has not bootstrapped yet).
40
+ * The active storage context, or throws if no session store has been created.
71
41
  *
72
- * @returns {WasRemoteStore}
42
+ * @returns {StorageContext}
73
43
  */
74
- export function requireRemoteStore() {
75
- if (!remoteStore) {
76
- throw new Error('No WAS remote store is available; connect a wallet session first.');
44
+ export function requireStorageContext() {
45
+ if (!active) {
46
+ throw new Error('No storage context is active; create the session store first.');
77
47
  }
78
- return remoteStore;
48
+ return active;
79
49
  }
80
50
  /**
81
- * Whether a connected session's remote store is available.
51
+ * The active session's opened replica, or throws if none is open.
82
52
  *
83
- * @returns {boolean}
53
+ * @returns {LocalStore}
84
54
  */
85
- export function hasRemoteStore() {
86
- return remoteStore !== null;
55
+ export function requireStore() {
56
+ return requireStorageContext().requireStore();
87
57
  }
88
58
  /**
89
- * Releases the held remote store reference (logout / sync teardown).
59
+ * Whether the active session has a replica open.
90
60
  *
91
- * @returns {void}
61
+ * @returns {boolean}
92
62
  */
93
- export function clearRemoteStore() {
94
- remoteStore = null;
63
+ export function hasStore() {
64
+ return active?.hasStore() ?? false;
95
65
  }
96
66
  /**
97
- * The unpersisted fallback writer id for environments without `localStorage`
98
- * (tests, SSR): process-stable, so every stamp within one run agrees, minted
99
- * fresh on the next run.
100
- */
101
- let fallbackWriterId = null;
102
- /**
103
- * A stable per-install writer id (the last-write-wins tiebreak stamped into
104
- * every payload), persisted in localStorage under `<prefix>writerId`. In an
105
- * environment without `localStorage` it falls back to a process-stable
106
- * unpersisted id instead of throwing.
67
+ * The active session's remote store, or throws while no wallet-connected
68
+ * session is active.
107
69
  *
108
- * The id is an unkeyed, clearable attribution label -- never an identity. On a
109
- * miss it adopts a value left under the pre-rename `<prefix>clientId` key and
110
- * removes the old one, so an existing install keeps stamping the same id
111
- * across the rename rather than looking like a second writer.
112
- *
113
- * @param [options] {object}
114
- * @param [options.storageKeyPrefix] {string} the localStorage key prefix
115
- * (defaults to {@link DEFAULT_STORAGE_KEY_PREFIX})
116
- * @returns {string}
70
+ * @returns {WasRemoteStore}
117
71
  */
118
- export function getWriterId({ storageKeyPrefix = DEFAULT_STORAGE_KEY_PREFIX } = {}) {
119
- const writerIdKey = `${storageKeyPrefix}writerId`;
120
- const legacyKey = `${storageKeyPrefix}clientId`;
121
- try {
122
- let id = localStorage.getItem(writerIdKey);
123
- if (!id) {
124
- id = localStorage.getItem(legacyKey) || uuidv7();
125
- localStorage.setItem(writerIdKey, id);
126
- localStorage.removeItem(legacyKey);
127
- }
128
- return id;
129
- }
130
- catch {
131
- fallbackWriterId ??= uuidv7();
132
- return fallbackWriterId;
133
- }
72
+ export function requireRemoteStore() {
73
+ return requireStorageContext().requireRemoteStore();
134
74
  }
135
- let resolvedWriterId = null;
136
75
  /**
137
- * Installs the session's resolved writer id (called once by the session store,
138
- * under the app's configured `storageKeyPrefix`, before any replica opens).
76
+ * Whether the active session has a remote store available.
139
77
  *
140
- * @param id {string}
141
- * @returns {void}
78
+ * @returns {boolean}
142
79
  */
143
- export function setWriterId(id) {
144
- resolvedWriterId = id;
80
+ export function hasRemoteStore() {
81
+ return active?.hasRemoteStore() ?? false;
145
82
  }
146
83
  /**
147
- * The session's resolved writer id, or throws if it has not been installed
148
- * yet. Deliberately never falls back to {@link getWriterId}: that would resolve
149
- * under the DEFAULT key prefix, so an app with a custom `storageKeyPrefix`
150
- * would silently stamp a second writer id.
84
+ * The active session's writer id, or throws if no session store exists yet.
85
+ * Deliberately never falls back to `getWriterId`: that would resolve under the
86
+ * DEFAULT key prefix, so an app with a custom `storageKeyPrefix` would silently
87
+ * stamp a second writer id.
151
88
  *
152
89
  * @returns {string}
153
90
  */
154
91
  export function requireWriterId() {
155
- if (!resolvedWriterId) {
156
- throw new Error('Writer id is not resolved; create the session store first.');
157
- }
158
- return resolvedWriterId;
159
- }
160
- /**
161
- * Clears the persisted writer id (the clear-data grade of the wipe): removes
162
- * both the current key and the pre-rename one, so nothing this library wrote
163
- * survives in localStorage. A fresh id is installed in memory rather than the
164
- * resolved one being dropped, because the session keeps running over its new
165
- * anonymous replica and its write verbs still have to stamp; nothing persists
166
- * it, so the next run resolves and stores an id of its own.
167
- *
168
- * @param [options] {object}
169
- * @param [options.storageKeyPrefix] {string} the localStorage key prefix
170
- * (defaults to {@link DEFAULT_STORAGE_KEY_PREFIX})
171
- * @returns {void}
172
- */
173
- export function clearWriterId({ storageKeyPrefix = DEFAULT_STORAGE_KEY_PREFIX } = {}) {
174
- try {
175
- localStorage.removeItem(`${storageKeyPrefix}writerId`);
176
- localStorage.removeItem(`${storageKeyPrefix}clientId`);
177
- }
178
- catch {
179
- // No localStorage in this environment: nothing was persisted to clear.
180
- }
181
- fallbackWriterId = null;
182
- setWriterId(uuidv7());
92
+ return requireStorageContext().writerId;
183
93
  }
184
94
  /**
185
- * Stamps a payload with fresh last-write-wins fields: the current instant as
186
- * `updatedAt` and the session's resolved writer id. Any values the caller
187
- * supplied are overwritten -- a stamp must describe THIS write, or a hydrated
188
- * doc's older `updatedAt` would ride a later edit and lose the conflict.
95
+ * Stamps a payload with fresh last-write-wins fields under the active session
96
+ * (see {@link StorageContext.stampLww}); the entity-store write verbs call it
97
+ * on every write, and an app writing through `LocalStore` directly does too.
189
98
  *
190
99
  * @param payload {object}
191
100
  * @returns {object} the payload with the LWW fields set
192
101
  */
193
102
  export function stampLww(payload) {
194
- return {
195
- ...payload,
196
- updatedAt: new Date().toISOString(),
197
- writerId: requireWriterId()
198
- };
103
+ return requireStorageContext().stampLww(payload);
199
104
  }
200
105
  //# sourceMappingURL=storageManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storageManager.js","sourceRoot":"","sources":["../../src/storage/storageManager.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAKzD,IAAI,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AE,CAAC,WAAW,EAAE;QACnC,QAAQ,EAAE,eAAe,EAAE;KAC5B,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"storageManager.js","sourceRoot":"","sources":["../../src/storage/storageManager.ts"],"names":[],"mappings":"AAyBA,IAAI,MAAM,GAA0B,IAAI,CAAA;AAExC;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAuB;IAC5D,IAAI,MAAM,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,wDAAwD;YACtD,8DAA8D,CACjE,CAAA;IACH,CAAC;IACD,MAAM,GAAG,OAAO,CAAA;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAuB;IAC9D,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;QACvB,MAAM,GAAG,IAAI,CAAA;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,MAAM,KAAK,IAAI,CAAA;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,qBAAqB,EAAE,CAAC,YAAY,EAAE,CAAA;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,MAAM,EAAE,QAAQ,EAAE,IAAI,KAAK,CAAA;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,qBAAqB,EAAE,CAAC,kBAAkB,EAAE,CAAA;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,EAAE,cAAc,EAAE,IAAI,KAAK,CAAA;AAC1C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,qBAAqB,EAAE,CAAC,QAAQ,CAAA;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAA2B,OAAU;IAC3D,OAAO,qBAAqB,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AAClD,CAAC"}
@@ -3,6 +3,7 @@ import { type SyncedDoc } from '../sync/index.js';
3
3
  import { type WasCollectionConfig, type WasSyncConfig } from '../config.js';
4
4
  import type { LocalStore } from './localStore.js';
5
5
  import type { WasRemoteStore } from './wasRemoteStore.js';
6
+ import type { SyncStatusStore } from './syncStatusStore.js';
6
7
  /**
7
8
  * Whether a replication error signals expired/revoked storage access. Every WAS
8
9
  * request the replication makes funnels through the sync port, which maps a
@@ -24,8 +25,16 @@ export declare function isAuthError(err: unknown): boolean;
24
25
  */
25
26
  export declare class SyncController {
26
27
  #private;
27
- constructor({ collections, sync }: {
28
+ /**
29
+ * @param options {object}
30
+ * @param options.collections {WasCollectionConfig[]}
31
+ * @param options.syncStatus {SyncStatusStore} the session's per-collection
32
+ * status store this controller reports into
33
+ * @param [options.sync] {WasSyncConfig}
34
+ */
35
+ constructor({ collections, syncStatus, sync }: {
28
36
  collections: WasCollectionConfig[];
37
+ syncStatus: SyncStatusStore;
29
38
  sync?: WasSyncConfig;
30
39
  });
31
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"syncController.d.ts","sourceRoot":"","sources":["../../src/storage/syncController.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAML,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAQzD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA+BjD;AAED;;GAEG;AACH,qBAAa,cAAc;;gBAYb,EACV,WAAW,EACX,IAAI,EACL,EAAE;QACD,WAAW,EAAE,mBAAmB,EAAE,CAAA;QAClC,IAAI,CAAC,EAAE,aAAa,CAAA;KACrB;IAKD;;;;;;;;;;;;;OAaG;IACG,KAAK,CAAC,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,WAAW,EACZ,EAAE;QACD,WAAW,EAAE,cAAc,CAAA;QAC3B,UAAU,EAAE,UAAU,CAAA;QACtB,cAAc,CAAC,EAAE,CACf,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,KAC5B,IAAI,CAAA;QACT,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgIjB;;;;;OAKG;IACH,MAAM,IAAI,IAAI;IAMd;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
1
+ {"version":3,"file":"syncController.d.ts","sourceRoot":"","sources":["../../src/storage/syncController.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAML,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAO3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CA+BjD;AAED;;GAEG;AACH,qBAAa,cAAc;;IAazB;;;;;;OAMG;gBACS,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACL,EAAE;QACD,WAAW,EAAE,mBAAmB,EAAE,CAAA;QAClC,UAAU,EAAE,eAAe,CAAA;QAC3B,IAAI,CAAC,EAAE,aAAa,CAAA;KACrB;IAMD;;;;;;;;;;;;;OAaG;IACG,KAAK,CAAC,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,WAAW,EACZ,EAAE;QACD,WAAW,EAAE,cAAc,CAAA;QAC3B,UAAU,EAAE,UAAU,CAAA;QACtB,cAAc,CAAC,EAAE,CACf,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,KAC5B,IAAI,CAAA;QACT,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgIjB;;;;;OAKG;IACH,MAAM,IAAI,IAAI;IAMd;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
@@ -1,6 +1,5 @@
1
1
  import { createWasReplication, createWasSyncPort, withFeedMasterRead, WasSyncAuthError } from '../sync/index.js';
2
2
  import { DEFAULT_SYNC_POLL_MS } from '../config.js';
3
- import { useSyncStatusStore } from './syncStatusStore.js';
4
3
  /**
5
4
  * Whether a replication error signals expired/revoked storage access. Every WAS
6
5
  * request the replication makes funnels through the sync port, which maps a
@@ -48,13 +47,22 @@ export function isAuthError(err) {
48
47
  export class SyncController {
49
48
  #collections;
50
49
  #sync;
50
+ #syncStatus;
51
51
  #replications = [];
52
52
  #onlineHandler;
53
53
  #pollTimer;
54
54
  #started = false;
55
55
  #stopped = false;
56
- constructor({ collections, sync }) {
56
+ /**
57
+ * @param options {object}
58
+ * @param options.collections {WasCollectionConfig[]}
59
+ * @param options.syncStatus {SyncStatusStore} the session's per-collection
60
+ * status store this controller reports into
61
+ * @param [options.sync] {WasSyncConfig}
62
+ */
63
+ constructor({ collections, syncStatus, sync }) {
57
64
  this.#collections = collections;
65
+ this.#syncStatus = syncStatus;
58
66
  this.#sync = sync ?? {};
59
67
  }
60
68
  /**
@@ -79,7 +87,7 @@ export class SyncController {
79
87
  return;
80
88
  }
81
89
  this.#started = true;
82
- const setStatus = useSyncStatusStore.getState().setStatus;
90
+ const setStatus = this.#syncStatus.getState().setStatus;
83
91
  const batchSize = this.#sync.batchSize;
84
92
  const retryMs = this.#sync.retryMs;
85
93
  const pollMs = this.#sync.pollMs ?? DEFAULT_SYNC_POLL_MS;
@@ -211,7 +219,7 @@ export class SyncController {
211
219
  // bootstrap) sees the controller as terminally stopped and bails.
212
220
  this.#stopped = true;
213
221
  await this.#teardownReplications();
214
- useSyncStatusStore.getState().reset();
222
+ this.#syncStatus.getState().reset();
215
223
  this.#started = false;
216
224
  }
217
225
  }
@@ -1 +1 @@
1
- {"version":3,"file":"syncController.js","sourceRoot":"","sources":["../../src/storage/syncController.ts"],"names":[],"mappings":"AAgCA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAGjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,oBAAoB,EAGrB,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAOzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAA;IAC/B,MAAM,KAAK,GAAc,CAAC,GAAG,CAAC,CAAA;IAC9B,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;QAC7B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,GAA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AAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;gBACzC,YAAY,CAAC,WAAW,EAAE,CAAA;YAC5B,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,KAAK,CAAC,MAAM,EAAE,CAAA;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;IACzB,CAAC;IAED;;;;;OAKG;IACH,MAAM;QACJ,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3C,KAAK,CAAC,MAAM,EAAE,CAAA;QAChB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI;QACR,qEAAqE;QACrE,kEAAkE;QAClE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;QAClC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;IACvB,CAAC;CACF"}
@@ -1,3 +1,15 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * The per-collection replication status store, mirroring the WAS per-replica
6
+ * sync-status vocabulary, keyed by the registry's logical collection key. One
7
+ * is created per {@link StorageContext} (so per session provider, never
8
+ * process-wide): the sync controller writes to it off the RxDB replication
9
+ * `active$` / `error$` streams, and `useSyncStatus` reads it through the
10
+ * provider. In-memory only, like the session -- reset on logout.
11
+ */
12
+ import { type StoreApi } from 'zustand/vanilla';
1
13
  /**
2
14
  * A single collection's replication status:
3
15
  * - `idle` -- configured but no cycle has run yet
@@ -6,7 +18,7 @@
6
18
  * - `error` -- last cycle failed (RxDB is backing off / will retry)
7
19
  */
8
20
  export type SyncStatus = 'idle' | 'syncing' | 'synced' | 'error';
9
- export declare const useSyncStatusStore: import("zustand").UseBoundStore<import("zustand").StoreApi<{
21
+ interface SyncStatusState {
10
22
  /**
11
23
  * Keyed by the registry's LOGICAL collection key (`WasCollectionConfig.key`,
12
24
  * e.g. `actionItems`), not the WAS wire id. Two registry entries may share one
@@ -17,7 +29,15 @@ export declare const useSyncStatusStore: import("zustand").UseBoundStore<import(
17
29
  statuses: Record<string, SyncStatus>;
18
30
  setStatus: (collectionKey: string, status: SyncStatus) => void;
19
31
  reset: () => void;
20
- }>>;
32
+ }
33
+ export type SyncStatusStore = StoreApi<SyncStatusState>;
34
+ /**
35
+ * Creates one session's sync status store (a vanilla zustand store; subscribe
36
+ * to it from React with zustand's `useStore`).
37
+ *
38
+ * @returns {SyncStatusStore}
39
+ */
40
+ export declare function createSyncStatusStore(): SyncStatusStore;
21
41
  /**
22
42
  * The aggregate replication status derived from the per-collection statuses:
23
43
  * `offline` when no replication is running (local-only), otherwise rolled up as
@@ -41,4 +61,5 @@ export declare function deriveSyncRollup(statuses: SyncStatus[]): {
41
61
  label: string;
42
62
  title: string;
43
63
  };
64
+ export {};
44
65
  //# sourceMappingURL=syncStatusStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"syncStatusStore.d.ts","sourceRoot":"","sources":["../../src/storage/syncStatusStore.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEhE,eAAO,MAAM,kBAAkB;IAC7B;;;;;;OAMG;cACO,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;eACzB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI;WACvD,MAAM,IAAI;GAQhB,CAAA;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,C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