@interop/was-react 0.18.1 → 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.
- package/README.md +4 -3
- package/dist/auth/verifyResponse.d.ts.map +1 -1
- package/dist/auth/verifyResponse.js +14 -7
- package/dist/auth/verifyResponse.js.map +1 -1
- package/dist/identity/agents.d.ts +5 -0
- package/dist/identity/agents.d.ts.map +1 -1
- package/dist/identity/agents.js +10 -3
- package/dist/identity/agents.js.map +1 -1
- package/dist/identity/seedCredential.d.ts +5 -1
- package/dist/identity/seedCredential.d.ts.map +1 -1
- package/dist/identity/seedCredential.js +15 -28
- package/dist/identity/seedCredential.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/mui/ClearDataDialog.d.ts.map +1 -1
- package/dist/mui/ClearDataDialog.js +14 -12
- package/dist/mui/ClearDataDialog.js.map +1 -1
- package/dist/mui/LogoutDialog.d.ts.map +1 -1
- package/dist/mui/LogoutDialog.js +12 -8
- package/dist/mui/LogoutDialog.js.map +1 -1
- package/dist/react/hooks.d.ts +11 -7
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/hooks.js +14 -8
- package/dist/react/hooks.js.map +1 -1
- package/dist/session/authStore.d.ts +30 -9
- package/dist/session/authStore.d.ts.map +1 -1
- package/dist/session/authStore.js +147 -48
- package/dist/session/authStore.js.map +1 -1
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +1 -0
- package/dist/session/index.js.map +1 -1
- package/dist/session/localWipe.d.ts +144 -0
- package/dist/session/localWipe.d.ts.map +1 -0
- package/dist/session/localWipe.js +190 -0
- package/dist/session/localWipe.js.map +1 -0
- package/dist/storage/adopt.d.ts +4 -1
- package/dist/storage/adopt.d.ts.map +1 -1
- package/dist/storage/adopt.js +4 -3
- package/dist/storage/adopt.js.map +1 -1
- package/dist/storage/entityStore.d.ts.map +1 -1
- package/dist/storage/entityStore.js +3 -0
- package/dist/storage/entityStore.js.map +1 -1
- package/dist/storage/publicUrl.js +3 -3
- package/dist/storage/storageContext.d.ts +175 -0
- package/dist/storage/storageContext.d.ts.map +1 -0
- package/dist/storage/storageContext.js +327 -0
- package/dist/storage/storageContext.js.map +1 -0
- package/dist/storage/storageManager.d.ts +57 -60
- package/dist/storage/storageManager.d.ts.map +1 -1
- package/dist/storage/storageManager.js +55 -125
- package/dist/storage/storageManager.js.map +1 -1
- package/dist/storage/syncController.d.ts +10 -1
- package/dist/storage/syncController.d.ts.map +1 -1
- package/dist/storage/syncController.js +12 -4
- package/dist/storage/syncController.js.map +1 -1
- package/dist/storage/syncStatusStore.d.ts +23 -2
- package/dist/storage/syncStatusStore.d.ts.map +1 -1
- package/dist/storage/syncStatusStore.js +22 -13
- package/dist/storage/syncStatusStore.js.map +1 -1
- package/dist/storage/writerId.d.ts +36 -0
- package/dist/storage/writerId.d.ts.map +1 -0
- package/dist/storage/writerId.js +76 -0
- package/dist/storage/writerId.js.map +1 -0
- package/package.json +13 -13
- package/dist/storage/rehydrate.d.ts +0 -64
- package/dist/storage/rehydrate.d.ts.map +0 -1
- package/dist/storage/rehydrate.js +0 -132
- package/dist/storage/rehydrate.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The wipe enumeration: the one list of durable local state this library leaves
|
|
6
|
+
* on a browser, and the one executor that deletes it. Clearing data must leave
|
|
7
|
+
* nothing behind, and the failure it exists to prevent is an ORPHANED database
|
|
8
|
+
* -- one whose name is derived from an identity the clear itself destroyed, so
|
|
9
|
+
* no later run can name it, let alone delete it.
|
|
10
|
+
*
|
|
11
|
+
* Three rules keep that from happening:
|
|
12
|
+
*
|
|
13
|
+
* - Snapshot first. Every target is derived from live state BEFORE anything is
|
|
14
|
+
* deleted ({@link snapshotWipeTargets}), so the order of the deletions that
|
|
15
|
+
* follow cannot lose a name.
|
|
16
|
+
* - Delete by known name. Each replica's database name is computable from its
|
|
17
|
+
* controller DID through `dbNameForController`, so it is deleted by that name
|
|
18
|
+
* whether or not the engine can enumerate databases.
|
|
19
|
+
* - Treat `indexedDB.databases()` as discovery and verification, never as the
|
|
20
|
+
* deletion gate. An engine that does not implement it still gets every named
|
|
21
|
+
* database deleted; what it cannot confirm is reported as `unverified` rather
|
|
22
|
+
* than counted toward an outcome that reads clean.
|
|
23
|
+
*
|
|
24
|
+
* What the prefix sweep reaches beyond the snapshot: anonymous replicas that
|
|
25
|
+
* earlier versions of this library already orphaned, and the replicas of other
|
|
26
|
+
* wallet identities on this browser. Both are this app's own databases under
|
|
27
|
+
* its own `dbName`, and removing them is what clearing data means.
|
|
28
|
+
*
|
|
29
|
+
* What no enumeration here reaches, stated plainly: data already synced to the
|
|
30
|
+
* WAS server (this is a local clear, not an account deletion), forensic
|
|
31
|
+
* recoverability of deleted IndexedDB data, and anything the app itself
|
|
32
|
+
* persisted outside this library.
|
|
33
|
+
*/
|
|
34
|
+
import type { RxStorage } from 'rxdb/plugins/core';
|
|
35
|
+
/**
|
|
36
|
+
* Every durable local target of a wipe, derived up front.
|
|
37
|
+
*/
|
|
38
|
+
export interface WipeTargets {
|
|
39
|
+
/**
|
|
40
|
+
* The RxDB replica database names, one per controller DID the snapshot could
|
|
41
|
+
* reach (the connected identity, the anonymous one, or both).
|
|
42
|
+
*/
|
|
43
|
+
replicaDbNames: string[];
|
|
44
|
+
/**
|
|
45
|
+
* The raw-IndexedDB seed stores: the session store (app-key seed, session
|
|
46
|
+
* record, descriptor cache) and the anonymous seed store.
|
|
47
|
+
*/
|
|
48
|
+
seedStoreDbNames: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The name prefixes the sweep matches: the app's own base `dbName` (the seed
|
|
51
|
+
* stores) and the RxDB/Dexie mangling of it (each replica collection is its
|
|
52
|
+
* own IndexedDB database, named `rxdb-dexie-<dbName>-<hash>--<v>--<name>`).
|
|
53
|
+
* Empty means no sweep: only the named targets and their Dexie sub-databases
|
|
54
|
+
* are deleted and verified.
|
|
55
|
+
*/
|
|
56
|
+
idbNamePrefixes: string[];
|
|
57
|
+
/**
|
|
58
|
+
* The localStorage prefix whose writer id is cleared, or `null` to leave it
|
|
59
|
+
* in place (the logout grade: the user is expected to log back in on this
|
|
60
|
+
* browser, and the id is only an attribution stamp).
|
|
61
|
+
*/
|
|
62
|
+
storageKeyPrefix: string | null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* What a wipe deleted, and what it could not confirm.
|
|
66
|
+
*/
|
|
67
|
+
export interface LocalWipeReport {
|
|
68
|
+
/**
|
|
69
|
+
* The database names the executor issued a delete for and, where the engine
|
|
70
|
+
* could confirm it, saw gone afterwards.
|
|
71
|
+
*/
|
|
72
|
+
removed: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Databases still present after the wipe, or whose delete threw.
|
|
75
|
+
*/
|
|
76
|
+
failed: string[];
|
|
77
|
+
/**
|
|
78
|
+
* Deletions that were issued but could not be confirmed -- an engine without
|
|
79
|
+
* `indexedDB.databases()`, or a delete another tab is blocking. Neither a
|
|
80
|
+
* success nor a failure: a caller states the unconfirmed outcome rather than
|
|
81
|
+
* claiming a clean wipe.
|
|
82
|
+
*/
|
|
83
|
+
unverified: string[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Derives every wipe target from live state, before anything is deleted, at one
|
|
87
|
+
* of the two grades the library ships:
|
|
88
|
+
*
|
|
89
|
+
* - `logout` (log out and erase): the CONNECTED replica and the session store.
|
|
90
|
+
* The anonymous replica and the writer id deliberately survive -- a
|
|
91
|
+
* local-first app keeps working logged out, and the user is expected to log
|
|
92
|
+
* back in on this browser -- so this grade runs no prefix sweep, which would
|
|
93
|
+
* reach the anonymous replica it is meant to spare.
|
|
94
|
+
* - `clear` (clear data): everything this app ever wrote here -- both replicas,
|
|
95
|
+
* both seed stores, the writer id -- plus a prefix sweep for whatever the
|
|
96
|
+
* snapshot could not name.
|
|
97
|
+
*
|
|
98
|
+
* The anonymous controller DID must be resolved by the caller (re-derived from
|
|
99
|
+
* the persisted anonymous seed) while that seed still exists: once it is
|
|
100
|
+
* discarded, the database it names is unreachable.
|
|
101
|
+
*
|
|
102
|
+
* @param options {object}
|
|
103
|
+
* @param options.dbName {string} the app's base database name
|
|
104
|
+
* @param options.grade {'logout' | 'clear'}
|
|
105
|
+
* @param [options.connectedControllerDid] {string | null} the wallet-derived
|
|
106
|
+
* controller DID, when a connected replica is open
|
|
107
|
+
* @param [options.anonControllerDid] {string | null} the anonymous controller
|
|
108
|
+
* DID (`clear` only; ignored at the `logout` grade)
|
|
109
|
+
* @param [options.storageKeyPrefix] {string} the localStorage prefix whose
|
|
110
|
+
* writer id the `clear` grade removes
|
|
111
|
+
* @returns {WipeTargets}
|
|
112
|
+
*/
|
|
113
|
+
export declare function snapshotWipeTargets({ dbName, grade, connectedControllerDid, anonControllerDid, storageKeyPrefix }: {
|
|
114
|
+
dbName: string;
|
|
115
|
+
grade: 'logout' | 'clear';
|
|
116
|
+
connectedControllerDid?: string | null;
|
|
117
|
+
anonControllerDid?: string | null;
|
|
118
|
+
storageKeyPrefix?: string;
|
|
119
|
+
}): WipeTargets;
|
|
120
|
+
/**
|
|
121
|
+
* Executes a wipe over a snapshot: the replica databases (through RxDB, so each
|
|
122
|
+
* one's internal metadata store goes with its collections), the seed stores,
|
|
123
|
+
* then a prefix sweep for anything the snapshot could not name, then the writer
|
|
124
|
+
* id. Every stage is best-effort and its failure is collected rather than
|
|
125
|
+
* aborting the rest, because a stage that throws must not leave the later
|
|
126
|
+
* stages' state behind.
|
|
127
|
+
*
|
|
128
|
+
* The live replica must already be torn down (an open database blocks its own
|
|
129
|
+
* deletion), which is the caller's job.
|
|
130
|
+
*
|
|
131
|
+
* @param options {object}
|
|
132
|
+
* @param options.targets {WipeTargets}
|
|
133
|
+
* @param [options.storage] {RxStorage<unknown, unknown>} the RxDB storage the
|
|
134
|
+
* replicas were created with (defaults to Dexie/IndexedDB)
|
|
135
|
+
* @param [options.idb] {IDBFactory} the IndexedDB factory (defaults to the
|
|
136
|
+
* global one; inject a fake for tests)
|
|
137
|
+
* @returns {Promise<LocalWipeReport>}
|
|
138
|
+
*/
|
|
139
|
+
export declare function executeLocalWipe({ targets, storage, idb }: {
|
|
140
|
+
targets: WipeTargets;
|
|
141
|
+
storage?: RxStorage<unknown, unknown>;
|
|
142
|
+
idb?: IDBFactory;
|
|
143
|
+
}): Promise<LocalWipeReport>;
|
|
144
|
+
//# sourceMappingURL=localWipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localWipe.d.ts","sourceRoot":"","sources":["../../src/session/localWipe.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAKlD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,KAAK,EACL,sBAAsB,EACtB,iBAAiB,EACjB,gBAA6C,EAC9C,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,GAAG,WAAW,CAgBd;AAiDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,OAAO,EACP,OAAO,EACP,GAAe,EAChB,EAAE;IACD,OAAO,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACrC,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB,GAAG,OAAO,CAAC,eAAe,CAAC,CA2F3B"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { DEFAULT_STORAGE_KEY_PREFIX } from '../config.js';
|
|
2
|
+
import { LocalStore, dbNameForController } from '../storage/localStore.js';
|
|
3
|
+
import { clearPersistedWriterId } from '../storage/writerId.js';
|
|
4
|
+
/**
|
|
5
|
+
* Derives every wipe target from live state, before anything is deleted, at one
|
|
6
|
+
* of the two grades the library ships:
|
|
7
|
+
*
|
|
8
|
+
* - `logout` (log out and erase): the CONNECTED replica and the session store.
|
|
9
|
+
* The anonymous replica and the writer id deliberately survive -- a
|
|
10
|
+
* local-first app keeps working logged out, and the user is expected to log
|
|
11
|
+
* back in on this browser -- so this grade runs no prefix sweep, which would
|
|
12
|
+
* reach the anonymous replica it is meant to spare.
|
|
13
|
+
* - `clear` (clear data): everything this app ever wrote here -- both replicas,
|
|
14
|
+
* both seed stores, the writer id -- plus a prefix sweep for whatever the
|
|
15
|
+
* snapshot could not name.
|
|
16
|
+
*
|
|
17
|
+
* The anonymous controller DID must be resolved by the caller (re-derived from
|
|
18
|
+
* the persisted anonymous seed) while that seed still exists: once it is
|
|
19
|
+
* discarded, the database it names is unreachable.
|
|
20
|
+
*
|
|
21
|
+
* @param options {object}
|
|
22
|
+
* @param options.dbName {string} the app's base database name
|
|
23
|
+
* @param options.grade {'logout' | 'clear'}
|
|
24
|
+
* @param [options.connectedControllerDid] {string | null} the wallet-derived
|
|
25
|
+
* controller DID, when a connected replica is open
|
|
26
|
+
* @param [options.anonControllerDid] {string | null} the anonymous controller
|
|
27
|
+
* DID (`clear` only; ignored at the `logout` grade)
|
|
28
|
+
* @param [options.storageKeyPrefix] {string} the localStorage prefix whose
|
|
29
|
+
* writer id the `clear` grade removes
|
|
30
|
+
* @returns {WipeTargets}
|
|
31
|
+
*/
|
|
32
|
+
export function snapshotWipeTargets({ dbName, grade, connectedControllerDid, anonControllerDid, storageKeyPrefix = DEFAULT_STORAGE_KEY_PREFIX }) {
|
|
33
|
+
const clearing = grade === 'clear';
|
|
34
|
+
const dids = [
|
|
35
|
+
connectedControllerDid,
|
|
36
|
+
...(clearing ? [anonControllerDid] : [])
|
|
37
|
+
].filter(did => !!did);
|
|
38
|
+
return {
|
|
39
|
+
replicaDbNames: [...new Set(dids)].map(controllerDid => dbNameForController({ dbName, controllerDid })),
|
|
40
|
+
seedStoreDbNames: clearing
|
|
41
|
+
? [`${dbName}-session`, `${dbName}-anon`]
|
|
42
|
+
: [`${dbName}-session`],
|
|
43
|
+
idbNamePrefixes: clearing ? [`${dbName}-`, `rxdb-dexie-${dbName}-`] : [],
|
|
44
|
+
storageKeyPrefix: clearing ? storageKeyPrefix : null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Lists the IndexedDB database names, or `null` on an engine that does not
|
|
49
|
+
* implement `databases()` (or refuses the call).
|
|
50
|
+
*
|
|
51
|
+
* @param idb {IDBFactory}
|
|
52
|
+
* @returns {Promise<string[] | null>}
|
|
53
|
+
*/
|
|
54
|
+
async function listDatabaseNames(idb) {
|
|
55
|
+
if (typeof idb.databases !== 'function') {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const listed = await idb.databases();
|
|
60
|
+
return listed.map(entry => entry.name).filter(name => !!name);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.warn('Could not enumerate IndexedDB databases:', err);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Deletes one IndexedDB database by name. A delete another connection is
|
|
69
|
+
* blocking is reported rather than awaited forever: the request stays pending
|
|
70
|
+
* in the engine, and the executor's verification probe is what decides whether
|
|
71
|
+
* it landed.
|
|
72
|
+
*
|
|
73
|
+
* @param options {object}
|
|
74
|
+
* @param options.name {string}
|
|
75
|
+
* @param options.idb {IDBFactory}
|
|
76
|
+
* @returns {Promise<{ blocked: boolean }>}
|
|
77
|
+
*/
|
|
78
|
+
async function deleteIdbDatabase({ name, idb }) {
|
|
79
|
+
return await new Promise((resolve, reject) => {
|
|
80
|
+
const request = idb.deleteDatabase(name);
|
|
81
|
+
request.onsuccess = () => resolve({ blocked: false });
|
|
82
|
+
request.onblocked = () => resolve({ blocked: true });
|
|
83
|
+
request.onerror = () => reject(request.error ?? new Error(`Could not delete database ${name}.`));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Executes a wipe over a snapshot: the replica databases (through RxDB, so each
|
|
88
|
+
* one's internal metadata store goes with its collections), the seed stores,
|
|
89
|
+
* then a prefix sweep for anything the snapshot could not name, then the writer
|
|
90
|
+
* id. Every stage is best-effort and its failure is collected rather than
|
|
91
|
+
* aborting the rest, because a stage that throws must not leave the later
|
|
92
|
+
* stages' state behind.
|
|
93
|
+
*
|
|
94
|
+
* The live replica must already be torn down (an open database blocks its own
|
|
95
|
+
* deletion), which is the caller's job.
|
|
96
|
+
*
|
|
97
|
+
* @param options {object}
|
|
98
|
+
* @param options.targets {WipeTargets}
|
|
99
|
+
* @param [options.storage] {RxStorage<unknown, unknown>} the RxDB storage the
|
|
100
|
+
* replicas were created with (defaults to Dexie/IndexedDB)
|
|
101
|
+
* @param [options.idb] {IDBFactory} the IndexedDB factory (defaults to the
|
|
102
|
+
* global one; inject a fake for tests)
|
|
103
|
+
* @returns {Promise<LocalWipeReport>}
|
|
104
|
+
*/
|
|
105
|
+
export async function executeLocalWipe({ targets, storage, idb = indexedDB }) {
|
|
106
|
+
const issued = new Set();
|
|
107
|
+
const failed = new Set();
|
|
108
|
+
const unverified = new Set();
|
|
109
|
+
// Deletes another connection is holding up. The engine keeps the request
|
|
110
|
+
// pending, so one of these still standing at the end is unconfirmed rather
|
|
111
|
+
// than failed.
|
|
112
|
+
const blockedNames = new Set();
|
|
113
|
+
for (const name of targets.replicaDbNames) {
|
|
114
|
+
try {
|
|
115
|
+
await LocalStore.removeDatabase({
|
|
116
|
+
dbName: name,
|
|
117
|
+
...(storage && { storage })
|
|
118
|
+
});
|
|
119
|
+
issued.add(name);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
console.warn(`Could not remove the replica database ${name}:`, err);
|
|
123
|
+
failed.add(name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const name of targets.seedStoreDbNames) {
|
|
127
|
+
try {
|
|
128
|
+
const { blocked } = await deleteIdbDatabase({ name, idb });
|
|
129
|
+
issued.add(name);
|
|
130
|
+
if (blocked) {
|
|
131
|
+
blockedNames.add(name);
|
|
132
|
+
unverified.add(name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
console.warn(`Could not delete the seed store ${name}:`, err);
|
|
137
|
+
failed.add(name);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// What the sweep deletes and the verification probe looks for: anything
|
|
141
|
+
// under one of the app's prefixes, plus every named target and the Dexie
|
|
142
|
+
// sub-databases that embed its name. The second half is what makes RxDB's
|
|
143
|
+
// own removal complete -- `RxDatabase.remove()` clears each collection's
|
|
144
|
+
// table but leaves its IndexedDB database standing.
|
|
145
|
+
function matchesApp(name) {
|
|
146
|
+
return (targets.idbNamePrefixes.some(prefix => name.startsWith(prefix)) ||
|
|
147
|
+
[...targets.replicaDbNames, ...targets.seedStoreDbNames].some(target => name === target || name.includes(target)));
|
|
148
|
+
}
|
|
149
|
+
const listed = await listDatabaseNames(idb);
|
|
150
|
+
if (listed === null) {
|
|
151
|
+
// No enumeration: the named deletes above still ran, but nothing sweeps
|
|
152
|
+
// and nothing confirms, so every issued name is reported unconfirmed.
|
|
153
|
+
for (const name of issued) {
|
|
154
|
+
unverified.add(name);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
for (const name of listed.filter(matchesApp)) {
|
|
159
|
+
try {
|
|
160
|
+
const { blocked } = await deleteIdbDatabase({ name, idb });
|
|
161
|
+
issued.add(name);
|
|
162
|
+
if (blocked) {
|
|
163
|
+
blockedNames.add(name);
|
|
164
|
+
unverified.add(name);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.warn(`Could not delete the database ${name}:`, err);
|
|
169
|
+
failed.add(name);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (targets.storageKeyPrefix !== null) {
|
|
174
|
+
clearPersistedWriterId({ storageKeyPrefix: targets.storageKeyPrefix });
|
|
175
|
+
}
|
|
176
|
+
const remaining = await listDatabaseNames(idb);
|
|
177
|
+
for (const name of (remaining ?? []).filter(matchesApp)) {
|
|
178
|
+
if (blockedNames.has(name)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
unverified.delete(name);
|
|
182
|
+
failed.add(name);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
removed: [...issued].filter(name => !failed.has(name)),
|
|
186
|
+
failed: [...failed],
|
|
187
|
+
unverified: [...unverified]
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=localWipe.js.map
|
|
@@ -0,0 +1 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AA;gBAC3D,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACtC,sBAAsB,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACxE,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAC9C,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACxD,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,SAAQ;QACV,CAAC;QACD,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACvB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC;QACnB,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC;KAC5B,CAAA;AACH,CAAC"}
|
package/dist/storage/adopt.d.ts
CHANGED
|
@@ -14,12 +14,15 @@ import type { LocalStore } from './localStore.js';
|
|
|
14
14
|
* @param options.store {LocalStore} the open connected replica
|
|
15
15
|
* @param options.entities {Record<string, Array<{ id: string }>>} decrypted
|
|
16
16
|
* payloads per collection key, as collected from the anonymous replica
|
|
17
|
+
* @param options.writerId {string} the session's writer id, stamped onto
|
|
18
|
+
* adopted payloads that carry no LWW fields
|
|
17
19
|
* @returns {Promise<void>}
|
|
18
20
|
*/
|
|
19
|
-
export declare function mergeAdopted({ store, entities }: {
|
|
21
|
+
export declare function mergeAdopted({ store, entities, writerId }: {
|
|
20
22
|
store: LocalStore;
|
|
21
23
|
entities: Record<string, Array<{
|
|
22
24
|
id: string;
|
|
23
25
|
}>>;
|
|
26
|
+
writerId: string;
|
|
24
27
|
}): Promise<void>;
|
|
25
28
|
//# sourceMappingURL=adopt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adopt.d.ts","sourceRoot":"","sources":["../../src/storage/adopt.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"adopt.d.ts","sourceRoot":"","sources":["../../src/storage/adopt.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,QAAQ,EACT,EAAE;IACD,KAAK,EAAE,UAAU,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAA;IAC/C,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmChB"}
|
package/dist/storage/adopt.js
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
* new one.
|
|
24
24
|
*/
|
|
25
25
|
import { lwwFields, remotePayloadWins } from '../sync/lww.js';
|
|
26
|
-
import { requireWriterId } from './storageManager.js';
|
|
27
26
|
/**
|
|
28
27
|
* Merges the collected anonymous-replica payloads into `store` (the already
|
|
29
28
|
* open connected replica) under the per-uuid LWW policy above. Runs before the
|
|
@@ -39,9 +38,11 @@ import { requireWriterId } from './storageManager.js';
|
|
|
39
38
|
* @param options.store {LocalStore} the open connected replica
|
|
40
39
|
* @param options.entities {Record<string, Array<{ id: string }>>} decrypted
|
|
41
40
|
* payloads per collection key, as collected from the anonymous replica
|
|
41
|
+
* @param options.writerId {string} the session's writer id, stamped onto
|
|
42
|
+
* adopted payloads that carry no LWW fields
|
|
42
43
|
* @returns {Promise<void>}
|
|
43
44
|
*/
|
|
44
|
-
export async function mergeAdopted({ store, entities }) {
|
|
45
|
+
export async function mergeAdopted({ store, entities, writerId }) {
|
|
45
46
|
let stamp = null;
|
|
46
47
|
// Collections are separate RxDB collections and each logical uuid appears at
|
|
47
48
|
// most once per collection, so every write below is independent of every
|
|
@@ -54,7 +55,7 @@ export async function mergeAdopted({ store, entities }) {
|
|
|
54
55
|
if (!adoptedLww) {
|
|
55
56
|
stamp ??= {
|
|
56
57
|
updatedAt: new Date().toISOString(),
|
|
57
|
-
writerId
|
|
58
|
+
writerId
|
|
58
59
|
};
|
|
59
60
|
adopted = { ...payload, ...stamp };
|
|
60
61
|
adoptedLww = stamp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adopt.js","sourceRoot":"","sources":["../../src/storage/adopt.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"adopt.js","sourceRoot":"","sources":["../../src/storage/adopt.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAG7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,QAAQ,EAKT;IACC,IAAI,KAAK,GAAmD,IAAI,CAAA;IAChE,6EAA6E;IAC7E,yEAAyE;IACzE,qEAAqE;IACrE,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK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","sources":["../../src/storage/entityStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"entityStore.d.ts","sourceRoot":"","sources":["../../src/storage/entityStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAA;AAOnE;;;;;GAKG;AACH,KAAK,eAAe,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,GAAG;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;IACnD;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACpB;;OAEG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B;;;;OAIG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD;;;OAGG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD;;;;;;OAMG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClD;;OAEG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC;;;;;OAKG;IACH,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAA;IAC/B;;;;;;;OAOG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAA;IACvB;;;OAGG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAChE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACxD,aAAa,EAAE,MAAM,GACpB,aAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAqJzC"}
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
* local writes stay immediate so a single edit is snappy.
|
|
23
23
|
*/
|
|
24
24
|
import { create } from 'zustand';
|
|
25
|
+
// The verbs resolve the ACTIVE session's context on every call rather than
|
|
26
|
+
// capturing one: an entity store is created at module level, before any
|
|
27
|
+
// session exists, and outlives every session it serves.
|
|
25
28
|
import { requireStore, requireRemoteStore, stampLww } from './storageManager.js';
|
|
26
29
|
import { lwwFields, remotePayloadWins } from '../sync/lww.js';
|
|
27
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStore.js","sourceRoot":"","sources":["../../src/storage/entityStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EA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,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;gBACzC,mEAAmE;gBACnE,qEAAqE;gBACrE,kDAAkD;gBAClD,MAAM,EAAE,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAA;gBAC7D,MAAM,IAAI,GAAG,MAAM,kBAAkB,EAAE,CAAC,yBAAyB,CAAC;oBAChE,YAAY,EAAE,EAAE;oBAChB,MAAM;oBACN,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC;oBACrC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;iBACxC,CAAC,CAAA;gBACF,gEAAgE;gBAChE,kEAAkE;gBAClE,+DAA+D;gBAC/D,wCAAwC;gBACxC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS;qBACxB,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;qBAC/C,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAS,CAAC,CAAA;gBACtC,OAAO;oBACL,IAAI;oBACJ,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;iBAC1D,CAAA;YACH,CAAC;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* logical collection key and a document id, composes the stable,
|
|
7
7
|
* world-readable resource URL of that document in a public (plaintext)
|
|
8
8
|
* collection. It routes the logical key to its WAS collection id through the
|
|
9
|
-
*
|
|
10
|
-
* requires an open {@link LocalStore} and a wallet-connected session
|
|
11
|
-
* remote
|
|
9
|
+
* active session's storage context exactly as {@link EntityStore.query} does,
|
|
10
|
+
* so it requires an open {@link LocalStore} and a wallet-connected session
|
|
11
|
+
* (a remote store), and fails closed on non-public collections.
|
|
12
12
|
*/
|
|
13
13
|
import { requireStore, requireRemoteStore } from './storageManager.js';
|
|
14
14
|
/**
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { StoreRegistry } from '../config.js';
|
|
2
|
+
import type { Json } from '../sync/index.js';
|
|
3
|
+
import type { LwwFields } from '../sync/lww.js';
|
|
4
|
+
import type { LocalStore } from './localStore.js';
|
|
5
|
+
import { type SyncStatusStore } from './syncStatusStore.js';
|
|
6
|
+
import type { WasRemoteStore } from './wasRemoteStore.js';
|
|
7
|
+
export declare class StorageContext {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* The app's per-collection hydrate/patch handlers; the change patches and the
|
|
11
|
+
* scheduled re-hydrates route on it.
|
|
12
|
+
*/
|
|
13
|
+
readonly registry: StoreRegistry;
|
|
14
|
+
/**
|
|
15
|
+
* This session's per-collection replication statuses.
|
|
16
|
+
*/
|
|
17
|
+
readonly syncStatus: SyncStatusStore;
|
|
18
|
+
/**
|
|
19
|
+
* @param options {object}
|
|
20
|
+
* @param options.registry {StoreRegistry}
|
|
21
|
+
* @param options.writerId {string} the resolved per-install writer id (see
|
|
22
|
+
* `getWriterId`), the value every stamp of this session carries
|
|
23
|
+
*/
|
|
24
|
+
constructor({ registry, writerId }: {
|
|
25
|
+
registry: StoreRegistry;
|
|
26
|
+
writerId: string;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* The writer id this session stamps with: an unkeyed, clearable attribution
|
|
30
|
+
* label, never an identity.
|
|
31
|
+
*
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
get writerId(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Replaces the in-memory writer id with a fresh one (the clear-data wipe,
|
|
37
|
+
* after `clearPersistedWriterId` removed the persisted one). The session
|
|
38
|
+
* keeps running over its new anonymous replica and its write verbs still
|
|
39
|
+
* have to stamp; nothing persists the new id, so the next run resolves and
|
|
40
|
+
* stores an id of its own.
|
|
41
|
+
*
|
|
42
|
+
* @returns {string} the new id
|
|
43
|
+
*/
|
|
44
|
+
resetWriterId(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Stamps a payload with fresh last-write-wins fields: the current instant as
|
|
47
|
+
* `updatedAt` and this session's writer id. Any values the caller supplied
|
|
48
|
+
* are overwritten -- a stamp must describe THIS write, or a hydrated doc's
|
|
49
|
+
* older `updatedAt` would ride a later edit and lose the conflict.
|
|
50
|
+
*
|
|
51
|
+
* @param payload {object}
|
|
52
|
+
* @returns {object} the payload with the LWW fields set
|
|
53
|
+
*/
|
|
54
|
+
stampLww<T extends {
|
|
55
|
+
id: string;
|
|
56
|
+
}>(payload: T): T & LwwFields;
|
|
57
|
+
/**
|
|
58
|
+
* Installs the opened replica and makes this the process's active context
|
|
59
|
+
* (the one the app-facing facades and the entity-store verbs resolve to).
|
|
60
|
+
* Throws if ANOTHER context still has a replica attached: two live sessions
|
|
61
|
+
* in one process would write into each other's entity stores.
|
|
62
|
+
*
|
|
63
|
+
* @param store {LocalStore}
|
|
64
|
+
* @returns {void}
|
|
65
|
+
*/
|
|
66
|
+
attachStore(store: LocalStore): void;
|
|
67
|
+
/**
|
|
68
|
+
* Releases the replica (the caller closes or deletes it) and cancels every
|
|
69
|
+
* pending re-hydrate; anything still in flight against the old replica sees
|
|
70
|
+
* the generation change and ends as a no-op.
|
|
71
|
+
*
|
|
72
|
+
* @returns {LocalStore | null} the replica that was attached, if any
|
|
73
|
+
*/
|
|
74
|
+
detachStore(): LocalStore | null;
|
|
75
|
+
/**
|
|
76
|
+
* Whether a replica is attached.
|
|
77
|
+
*
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
hasStore(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The attached replica, or throws if none is open.
|
|
83
|
+
*
|
|
84
|
+
* @returns {LocalStore}
|
|
85
|
+
*/
|
|
86
|
+
requireStore(): LocalStore;
|
|
87
|
+
/**
|
|
88
|
+
* Runs `op` against the replica attached now and resolves with its result
|
|
89
|
+
* only if that same replica is still attached when `op` settles. Resolves
|
|
90
|
+
* `undefined` when no replica is attached, or when it was detached or
|
|
91
|
+
* swapped meanwhile -- including when `op` rejected after the swap, since a
|
|
92
|
+
* read torn by its own teardown is expected noise, not an error. A rejection
|
|
93
|
+
* against a replica that is still attached propagates.
|
|
94
|
+
*
|
|
95
|
+
* @param op {(store: LocalStore) => Promise<T>}
|
|
96
|
+
* @returns {Promise<T | undefined>}
|
|
97
|
+
*/
|
|
98
|
+
whileAttached<T>(op: (store: LocalStore) => Promise<T>): Promise<T | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Installs the connected session's delegated remote store (once background
|
|
101
|
+
* sync has bootstrapped it from the granted zcaps).
|
|
102
|
+
*
|
|
103
|
+
* @param store {WasRemoteStore}
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
106
|
+
attachRemoteStore(store: WasRemoteStore): void;
|
|
107
|
+
/**
|
|
108
|
+
* Releases the remote store (logout / sync teardown).
|
|
109
|
+
*
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
112
|
+
detachRemoteStore(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Whether a connected session's remote store is available.
|
|
115
|
+
*
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
hasRemoteStore(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The connected session's remote store, or throws while no wallet-connected
|
|
121
|
+
* session is active (local-only mode, or sync has not bootstrapped yet).
|
|
122
|
+
*
|
|
123
|
+
* @returns {WasRemoteStore}
|
|
124
|
+
*/
|
|
125
|
+
requireRemoteStore(): WasRemoteStore;
|
|
126
|
+
/**
|
|
127
|
+
* Hydrates every registered store from the attached replica.
|
|
128
|
+
*
|
|
129
|
+
* @returns {Promise<void>}
|
|
130
|
+
*/
|
|
131
|
+
hydrateAll(): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Empties every registered store (logout).
|
|
134
|
+
*
|
|
135
|
+
* @returns {void}
|
|
136
|
+
*/
|
|
137
|
+
clearEntityStores(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Patches ONE store from a single RxDB change event (per-doc, no
|
|
140
|
+
* whole-collection re-hydrate): decrypt the changed envelope, then upsert the
|
|
141
|
+
* payload (INSERT / UPDATE, including conflict-resolved rows) or drop it
|
|
142
|
+
* (DELETE / tombstone). The `uuid -> envelopeId` index is kept in step so a
|
|
143
|
+
* later local edit of a remotely-created doc still finds its envelope. Falls
|
|
144
|
+
* back to a debounced whole-collection re-hydrate if the envelope is missing
|
|
145
|
+
* or fails to decrypt.
|
|
146
|
+
*
|
|
147
|
+
* Fired floating off the RxDB change stream, so a logout/login teardown can
|
|
148
|
+
* detach or swap the replica while the decrypt is in flight; the decrypt runs
|
|
149
|
+
* under {@link StorageContext.whileAttached}, so an event that outlives its
|
|
150
|
+
* replica is dropped rather than patched into the next session's stores.
|
|
151
|
+
*
|
|
152
|
+
* @param collectionKey {string}
|
|
153
|
+
* @param event {object} an RxDB change event (operation + documentData)
|
|
154
|
+
* @returns {Promise<void>}
|
|
155
|
+
*/
|
|
156
|
+
patchFromChange(collectionKey: string, event: {
|
|
157
|
+
operation: string;
|
|
158
|
+
documentData?: {
|
|
159
|
+
id: string;
|
|
160
|
+
data?: Json;
|
|
161
|
+
_deleted?: boolean;
|
|
162
|
+
};
|
|
163
|
+
}): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Schedules a debounced re-hydrate of one collection's store after a pull.
|
|
166
|
+
* A no-op without an attached replica, and the timer itself is bound to the
|
|
167
|
+
* replica attached now: a detach cancels it, and one that still fires after
|
|
168
|
+
* a swap finds the generation changed and does nothing.
|
|
169
|
+
*
|
|
170
|
+
* @param collectionKey {string}
|
|
171
|
+
* @returns {void}
|
|
172
|
+
*/
|
|
173
|
+
scheduleRehydrate(collectionKey: string): void;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=storageContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storageContext.d.ts","sourceRoot":"","sources":["../../src/storage/storageContext.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAOzD,qBAAa,cAAc;;IACzB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAA;IAChC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,eAAe,CAA0B;IAU9D;;;;;OAKG;gBACS,EACV,QAAQ,EACR,QAAQ,EACT,EAAE;QACD,QAAQ,EAAE,aAAa,CAAA;QACvB,QAAQ,EAAE,MAAM,CAAA;KACjB;IAKD;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;;;;;;OAQG;IACH,aAAa,IAAI,MAAM;IAKvB;;;;;;;;OAQG;IACH,QAAQ,CAAC,CAAC,SAAS;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAQ7D;;;;;;;;OAQG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAMpC;;;;;;OAMG;IACH,WAAW,IAAI,UAAU,GAAG,IAAI;IAWhC;;;;OAIG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;OAIG;IACH,YAAY,IAAI,UAAU;IAO1B;;;;;;;;;;OAUG;IACG,aAAa,CAAC,C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