mindoodb 0.0.73 → 0.0.75
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/dist/browser/index.mjs +9 -0
- package/dist/core/BackgroundTaskTracker.d.ts +18 -0
- package/dist/core/BackgroundTaskTracker.d.ts.map +1 -0
- package/dist/core/BackgroundTaskTracker.js +37 -0
- package/dist/core/BackgroundTaskTracker.js.map +1 -0
- package/dist/core/BaseMindooDB.d.ts +43 -7
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +271 -79
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +30 -12
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +90 -65
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts +57 -14
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +319 -164
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts +34 -0
- package/dist/core/appendonlystores/migration/StoreMigration.d.ts.map +1 -0
- package/dist/core/appendonlystores/migration/StoreMigration.js +70 -0
- package/dist/core/appendonlystores/migration/StoreMigration.js.map +1 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.d.ts +97 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.js +128 -0
- package/dist/core/appendonlystores/rpc/RpcContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.d.ts +24 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.js +102 -0
- package/dist/core/appendonlystores/rpc/StoreRpcServer.js.map +1 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.d.ts +15 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.d.ts.map +1 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.js +100 -0
- package/dist/core/appendonlystores/rpc/storeRpcCodec.js.map +1 -0
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts +3 -0
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js +18 -11
- package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts +13 -0
- package/dist/core/appendonlystores/sqlite/SqliteDriver.d.ts.map +1 -1
- package/dist/core/appendonlystores/sqlite/SqliteDriver.js +74 -0
- package/dist/core/appendonlystores/sqlite/SqliteDriver.js.map +1 -1
- package/dist/core/cache/CacheManager.d.ts +4 -1
- package/dist/core/cache/CacheManager.d.ts.map +1 -1
- package/dist/core/cache/CacheManager.js +47 -19
- package/dist/core/cache/CacheManager.js.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/indexing/fulltext/DocumentFullTextIndex.d.ts +16 -1
- package/dist/core/indexing/fulltext/DocumentFullTextIndex.d.ts.map +1 -1
- package/dist/core/indexing/fulltext/DocumentFullTextIndex.js +86 -14
- package/dist/core/indexing/fulltext/DocumentFullTextIndex.js.map +1 -1
- package/dist/core/indexing/summary/DocumentSummaryStore.d.ts +2 -0
- package/dist/core/indexing/summary/DocumentSummaryStore.d.ts.map +1 -1
- package/dist/core/indexing/summary/DocumentSummaryStore.js +19 -5
- package/dist/core/indexing/summary/DocumentSummaryStore.js.map +1 -1
- package/dist/core/types.d.ts +29 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +22 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/utils/singleFlight.d.ts +21 -0
- package/dist/core/utils/singleFlight.d.ts.map +1 -0
- package/dist/core/utils/singleFlight.js +47 -0
- package/dist/core/utils/singleFlight.js.map +1 -0
- package/dist/core/utils/timeSource.d.ts +3 -1
- package/dist/core/utils/timeSource.d.ts.map +1 -1
- package/dist/core/utils/timeSource.js +4 -0
- package/dist/core/utils/timeSource.js.map +1 -1
- package/dist/sqlite/index.d.ts +2 -0
- package/dist/sqlite/index.d.ts.map +1 -1
- package/dist/sqlite/index.js +8 -1
- package/dist/sqlite/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -50,11 +50,12 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
50
50
|
*/
|
|
51
51
|
private unsubscribeKeyBagChanges;
|
|
52
52
|
/**
|
|
53
|
-
* Single-flight
|
|
54
|
-
* coalesce
|
|
55
|
-
*
|
|
53
|
+
* Single-flight for {@link reconcileKeyBagChanges}. Concurrent calls
|
|
54
|
+
* coalesce so live listener firings and explicit calls cannot race; a call
|
|
55
|
+
* arriving mid-run gets one follow-up run, so a KeyBag change made while
|
|
56
|
+
* databases were being reconciled is not left unconsumed.
|
|
56
57
|
*/
|
|
57
|
-
private
|
|
58
|
+
private readonly keyBagReconcile;
|
|
58
59
|
private decryptedTenantKeyCache?;
|
|
59
60
|
private decryptedUserSigningKeyCache?;
|
|
60
61
|
private decryptedUserEncryptionKeyCache?;
|
|
@@ -74,8 +75,10 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
74
75
|
private readonly importedVerifyKeyCache;
|
|
75
76
|
private static readonly MAX_IMPORTED_KEY_CACHE_ENTRIES;
|
|
76
77
|
private logger;
|
|
77
|
-
private
|
|
78
|
+
private readonly keyDistributionReconcile;
|
|
78
79
|
private userKeyReconcileScheduled;
|
|
80
|
+
/** Fire-and-forget work of this tenant; see {@link whenBackgroundIdle}. */
|
|
81
|
+
private readonly backgroundTasks;
|
|
79
82
|
private readonly userKeys;
|
|
80
83
|
private readonly sealedGenerations;
|
|
81
84
|
private cacheManager;
|
|
@@ -134,6 +137,19 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
134
137
|
* unbounded-allocates.
|
|
135
138
|
*/
|
|
136
139
|
scheduleUserKeyReconcile(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Register fire-and-forget work so {@link whenBackgroundIdle} and shutdown
|
|
142
|
+
* wait for it. The task must handle its own errors.
|
|
143
|
+
*/
|
|
144
|
+
trackBackgroundTask(task: Promise<unknown>): void;
|
|
145
|
+
/**
|
|
146
|
+
* Resolve once neither this tenant nor any of its open databases has
|
|
147
|
+
* background work left (trust/key reconciles, auto-follow catch-ups,
|
|
148
|
+
* pending change events), including work that finishing tasks start.
|
|
149
|
+
*
|
|
150
|
+
* @internal Shutdown and test hook.
|
|
151
|
+
*/
|
|
152
|
+
whenBackgroundIdle(): Promise<void>;
|
|
137
153
|
noteUserDirectoryFetched(): void;
|
|
138
154
|
noteUserDirectoryFetchFailed(error: unknown): void;
|
|
139
155
|
listPendingUserKeyDevices(): Promise<PendingUserKeyDevice[]>;
|
|
@@ -325,12 +341,14 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
325
341
|
* Designed as the single barrier callers can `await` to be certain that
|
|
326
342
|
* subsequent reads observe the latest add/remove of doc keys. Behaviour:
|
|
327
343
|
*
|
|
328
|
-
* - Idempotent and concurrency-safe. Concurrent callers share
|
|
329
|
-
*
|
|
330
|
-
* call after the cursor catches up is a
|
|
344
|
+
* - Idempotent and concurrency-safe. Concurrent callers share one run;
|
|
345
|
+
* a call arriving mid-run gets one follow-up run (see
|
|
346
|
+
* {@link keyBagReconcile}), and a call after the cursor catches up is a
|
|
347
|
+
* fast no-op.
|
|
331
348
|
* - Cursor-based. Replays from the persisted cursor in
|
|
332
349
|
* {@link keyBagChangeCursor}, so missed live notifications are
|
|
333
|
-
* automatically recovered.
|
|
350
|
+
* automatically recovered. The cursor advances only after every open
|
|
351
|
+
* database was reconciled, so a failed run is retried by the next call.
|
|
334
352
|
* - Tenant-scoped. Events for other tenants in a shared KeyBag are
|
|
335
353
|
* consumed (the cursor still advances) but ignored.
|
|
336
354
|
* - Invalidates the cached tenant default key when its add/remove was
|
|
@@ -339,6 +357,7 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
339
357
|
* cuts and never participate in visibility reconciliation.
|
|
340
358
|
*/
|
|
341
359
|
reconcileKeyBagChanges(): Promise<void>;
|
|
360
|
+
private runKeyBagReconcile;
|
|
342
361
|
/**
|
|
343
362
|
* Author-trust reconcile across all open live databases: when the tenant
|
|
344
363
|
* directory learns about new trusted signing keys (grantaccess documents
|
|
@@ -518,9 +537,8 @@ export declare class BaseMindooTenant implements MindooTenant {
|
|
|
518
537
|
* Single-flight, best-effort wrapper around
|
|
519
538
|
* {@link reconcileKeyDistributionsForCurrentUser} for the run-always trigger
|
|
520
539
|
* (docs/accesscontrol.md §13). Fired on directory bring-up and after every
|
|
521
|
-
* directory pull. Never throws
|
|
522
|
-
*
|
|
523
|
-
* directory access from re-triggering it.
|
|
540
|
+
* directory pull. Never throws: a reconcile error is logged and swallowed.
|
|
541
|
+
* Resolves after a run that started after this call.
|
|
524
542
|
*/
|
|
525
543
|
reconcileKeyDistributionsForCurrentUserSafe(): Promise<void>;
|
|
526
544
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseMindooTenant.d.ts","sourceRoot":"","sources":["../../src/core/BaseMindooTenant.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,qBAAqB,EACrB,4BAA4B,EAE5B,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,YAAY,EAGZ,yBAAyB,EACzB,sBAAsB,EAEtB,sBAAsB,EAIvB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAkB,MAAM,UAAU,CAAC;AACvE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EAAE,MAAM,GAC1B,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;;;OAOG;IACG,oCAAoC,CACxC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE,CAAC,GAClE,OAAO,CAAC,MAAM,CAAC;IAwBlB,8FAA8F;IACxF,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ7D;;;;;OAKG;IACG,sBAAsB,CAC1B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAchF;;;;;;;;OAQG;IACG,wCAAwC,CAC5C,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC;IAiClB,oEAAoE;IACpE,OAAO,CAAC,4BAA4B;IAIpC;;;;;;OAMG;cACa,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA8B7E;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,qCAAqC,IAAI,OAAO;IAI1D;;;;;;;;;;OAUG;IACG,wBAAwB,CAC5B,OAAO,EAAE,UAAU,EACnB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC;IAgEtB;;;;;;;OAOG;IACG,wBAAwB,CAC5B,gBAAgB,EAAE,UAAU,EAC5B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,UAAU,CAAC;CA2DvB"}
|
|
@@ -30,6 +30,8 @@ const joinRequestUri_1 = require("./uri/joinRequestUri");
|
|
|
30
30
|
const EncryptedLocalCacheStore_1 = require("./cache/EncryptedLocalCacheStore");
|
|
31
31
|
const CacheManager_1 = require("./cache/CacheManager");
|
|
32
32
|
const databaseIdValidation_1 = require("./databaseIdValidation");
|
|
33
|
+
const BackgroundTaskTracker_1 = require("./BackgroundTaskTracker");
|
|
34
|
+
const singleFlight_1 = require("./utils/singleFlight");
|
|
33
35
|
/**
|
|
34
36
|
* BaseMindooTenant is a platform-agnostic implementation of MindooTenant
|
|
35
37
|
* that works in both browser and server environments.
|
|
@@ -73,11 +75,12 @@ class BaseMindooTenant {
|
|
|
73
75
|
*/
|
|
74
76
|
this.unsubscribeKeyBagChanges = null;
|
|
75
77
|
/**
|
|
76
|
-
* Single-flight
|
|
77
|
-
* coalesce
|
|
78
|
-
*
|
|
78
|
+
* Single-flight for {@link reconcileKeyBagChanges}. Concurrent calls
|
|
79
|
+
* coalesce so live listener firings and explicit calls cannot race; a call
|
|
80
|
+
* arriving mid-run gets one follow-up run, so a KeyBag change made while
|
|
81
|
+
* databases were being reconciled is not left unconsumed.
|
|
79
82
|
*/
|
|
80
|
-
this.
|
|
83
|
+
this.keyBagReconcile = new singleFlight_1.SingleFlight(() => this.runKeyBagReconcile());
|
|
81
84
|
/**
|
|
82
85
|
* Cache of imported AES-GCM `CryptoKey`s, keyed by usage + raw key bytes
|
|
83
86
|
* (hex). `subtle.importKey` costs a WebCrypto round trip per call, which
|
|
@@ -92,14 +95,23 @@ class BaseMindooTenant {
|
|
|
92
95
|
* documents, so the per-call SPKI import is on the hot read path.
|
|
93
96
|
*/
|
|
94
97
|
this.importedVerifyKeyCache = new Map();
|
|
95
|
-
// Single-flight
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// run
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
this.
|
|
98
|
+
// Single-flight for the SDK-driven key-distribution reconcile (§13), fired on
|
|
99
|
+
// directory bring-up and after each directory pull. A trigger arriving
|
|
100
|
+
// mid-run (e.g. a pull that brought a new distribution) gets one follow-up
|
|
101
|
+
// run instead of being dropped. The driver's own re-trigger (directory
|
|
102
|
+
// bring-up inside getDirectoryDB) is fire-and-forget, never awaited inside
|
|
103
|
+
// the run, so it queues a follow-up rather than waiting for itself.
|
|
104
|
+
this.keyDistributionReconcile = new singleFlight_1.SingleFlight(async () => {
|
|
105
|
+
try {
|
|
106
|
+
await this.reconcileKeyDistributionsForCurrentUser();
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
this.logger.warn(`reconcileKeyDistributionsForCurrentUserSafe: ${error}`);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
102
112
|
this.userKeyReconcileScheduled = false;
|
|
113
|
+
/** Fire-and-forget work of this tenant; see {@link whenBackgroundIdle}. */
|
|
114
|
+
this.backgroundTasks = new BackgroundTaskTracker_1.BackgroundTaskTracker();
|
|
103
115
|
this.userKeys = new UserKeyManager_1.UserKeyManager(this);
|
|
104
116
|
this.sealedGenerations = new Map();
|
|
105
117
|
// Local cache support
|
|
@@ -136,7 +148,9 @@ class BaseMindooTenant {
|
|
|
136
148
|
// Fire-and-forget: errors are surfaced via the reconcile path itself.
|
|
137
149
|
// We intentionally do not await here to keep the mutation call site
|
|
138
150
|
// synchronous from the listener's perspective.
|
|
139
|
-
|
|
151
|
+
this.trackBackgroundTask(this.reconcileKeyBagChanges().catch((error) => {
|
|
152
|
+
this.logger.warn(`reconcileKeyBagChanges: ${error}`);
|
|
153
|
+
}));
|
|
140
154
|
});
|
|
141
155
|
// Pre-warm the per-user CryptoKey caches so getDecryptedSigningKey()
|
|
142
156
|
// and getDecryptedEncryptionKey() never run PBKDF2 + decryptPrivateKey
|
|
@@ -191,6 +205,9 @@ class BaseMindooTenant {
|
|
|
191
205
|
// times - the disposer is nulled out after the first call.
|
|
192
206
|
this.unsubscribeKeyBagChanges?.();
|
|
193
207
|
this.unsubscribeKeyBagChanges = null;
|
|
208
|
+
// Background catch-ups write into the cache; let them finish before the
|
|
209
|
+
// final flush instead of racing the teardown.
|
|
210
|
+
await this.whenBackgroundIdle();
|
|
194
211
|
if (this.cacheManager) {
|
|
195
212
|
await this.cacheManager.dispose();
|
|
196
213
|
this.cacheManager = null;
|
|
@@ -235,12 +252,40 @@ class BaseMindooTenant {
|
|
|
235
252
|
if (this.userKeys.isReconciling() || this.userKeyReconcileScheduled)
|
|
236
253
|
return;
|
|
237
254
|
this.userKeyReconcileScheduled = true;
|
|
238
|
-
|
|
255
|
+
this.trackBackgroundTask(Promise.resolve().then(() => {
|
|
239
256
|
this.userKeyReconcileScheduled = false;
|
|
240
257
|
if (this.userKeys.isReconciling())
|
|
241
258
|
return;
|
|
242
|
-
|
|
243
|
-
});
|
|
259
|
+
return this.reconcileUserKeysSafe();
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Register fire-and-forget work so {@link whenBackgroundIdle} and shutdown
|
|
264
|
+
* wait for it. The task must handle its own errors.
|
|
265
|
+
*/
|
|
266
|
+
trackBackgroundTask(task) {
|
|
267
|
+
this.backgroundTasks.run(task);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Resolve once neither this tenant nor any of its open databases has
|
|
271
|
+
* background work left (trust/key reconciles, auto-follow catch-ups,
|
|
272
|
+
* pending change events), including work that finishing tasks start.
|
|
273
|
+
*
|
|
274
|
+
* @internal Shutdown and test hook.
|
|
275
|
+
*/
|
|
276
|
+
async whenBackgroundIdle() {
|
|
277
|
+
for (;;) {
|
|
278
|
+
let waited = await this.backgroundTasks.settle();
|
|
279
|
+
for (const db of Array.from(this.databaseCache.values())) {
|
|
280
|
+
const idle = db.whenBackgroundIdle;
|
|
281
|
+
if (idle && (await idle.call(db))) {
|
|
282
|
+
waited = true;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (!waited) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
244
289
|
}
|
|
245
290
|
noteUserDirectoryFetched() {
|
|
246
291
|
this.userKeys.noteUserDirectoryFetched();
|
|
@@ -1181,12 +1226,14 @@ class BaseMindooTenant {
|
|
|
1181
1226
|
* Designed as the single barrier callers can `await` to be certain that
|
|
1182
1227
|
* subsequent reads observe the latest add/remove of doc keys. Behaviour:
|
|
1183
1228
|
*
|
|
1184
|
-
* - Idempotent and concurrency-safe. Concurrent callers share
|
|
1185
|
-
*
|
|
1186
|
-
* call after the cursor catches up is a
|
|
1229
|
+
* - Idempotent and concurrency-safe. Concurrent callers share one run;
|
|
1230
|
+
* a call arriving mid-run gets one follow-up run (see
|
|
1231
|
+
* {@link keyBagReconcile}), and a call after the cursor catches up is a
|
|
1232
|
+
* fast no-op.
|
|
1187
1233
|
* - Cursor-based. Replays from the persisted cursor in
|
|
1188
1234
|
* {@link keyBagChangeCursor}, so missed live notifications are
|
|
1189
|
-
* automatically recovered.
|
|
1235
|
+
* automatically recovered. The cursor advances only after every open
|
|
1236
|
+
* database was reconciled, so a failed run is retried by the next call.
|
|
1190
1237
|
* - Tenant-scoped. Events for other tenants in a shared KeyBag are
|
|
1191
1238
|
* consumed (the cursor still advances) but ignored.
|
|
1192
1239
|
* - Invalidates the cached tenant default key when its add/remove was
|
|
@@ -1195,34 +1242,30 @@ class BaseMindooTenant {
|
|
|
1195
1242
|
* cuts and never participate in visibility reconciliation.
|
|
1196
1243
|
*/
|
|
1197
1244
|
async reconcileKeyBagChanges() {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
continue;
|
|
1211
|
-
}
|
|
1212
|
-
sawTenantDocKeyChange = true;
|
|
1213
|
-
if (event.keyId === types_1.DEFAULT_TENANT_KEY_ID) {
|
|
1214
|
-
// The cached plaintext default key may now refer to a rotated
|
|
1215
|
-
// or removed version; drop it so the next access re-resolves.
|
|
1216
|
-
this.decryptedTenantKeyCache = undefined;
|
|
1217
|
-
}
|
|
1245
|
+
return this.keyBagReconcile.run();
|
|
1246
|
+
}
|
|
1247
|
+
async runKeyBagReconcile() {
|
|
1248
|
+
let sawTenantDocKeyChange = false;
|
|
1249
|
+
let latestCursor = this.keyBagChangeCursor;
|
|
1250
|
+
// Consume every pending event so the cursor advances even for
|
|
1251
|
+
// unrelated tenants sharing the same bag. We only need to react to
|
|
1252
|
+
// doc keys for our own tenant though.
|
|
1253
|
+
for await (const event of this.keyBag.iterateChangesSince(this.keyBagChangeCursor)) {
|
|
1254
|
+
latestCursor = { changeSeq: event.changeSeq };
|
|
1255
|
+
if (event.type !== "doc" || event.tenantId !== this.tenantId) {
|
|
1256
|
+
continue;
|
|
1218
1257
|
}
|
|
1219
|
-
|
|
1220
|
-
if (
|
|
1221
|
-
|
|
1258
|
+
sawTenantDocKeyChange = true;
|
|
1259
|
+
if (event.keyId === types_1.DEFAULT_TENANT_KEY_ID) {
|
|
1260
|
+
// The cached plaintext default key may now refer to a rotated
|
|
1261
|
+
// or removed version; drop it so the next access re-resolves.
|
|
1262
|
+
this.decryptedTenantKeyCache = undefined;
|
|
1222
1263
|
}
|
|
1264
|
+
}
|
|
1265
|
+
if (sawTenantDocKeyChange) {
|
|
1223
1266
|
// Notify every open live database; time-travel views are read-only
|
|
1224
1267
|
// historical snapshots and intentionally skip reconciliation.
|
|
1225
|
-
for (const db of this.databaseCache.values()) {
|
|
1268
|
+
for (const db of Array.from(this.databaseCache.values())) {
|
|
1226
1269
|
if (db.isTimeTravelMode()) {
|
|
1227
1270
|
continue;
|
|
1228
1271
|
}
|
|
@@ -1231,13 +1274,8 @@ class BaseMindooTenant {
|
|
|
1231
1274
|
await reconcile.call(db);
|
|
1232
1275
|
}
|
|
1233
1276
|
}
|
|
1234
|
-
})();
|
|
1235
|
-
try {
|
|
1236
|
-
await this.keyBagReconcilePromise;
|
|
1237
|
-
}
|
|
1238
|
-
finally {
|
|
1239
|
-
this.keyBagReconcilePromise = null;
|
|
1240
1277
|
}
|
|
1278
|
+
this.keyBagChangeCursor = latestCursor;
|
|
1241
1279
|
}
|
|
1242
1280
|
/**
|
|
1243
1281
|
* Author-trust reconcile across all open live databases: when the tenant
|
|
@@ -2067,24 +2105,11 @@ class BaseMindooTenant {
|
|
|
2067
2105
|
* Single-flight, best-effort wrapper around
|
|
2068
2106
|
* {@link reconcileKeyDistributionsForCurrentUser} for the run-always trigger
|
|
2069
2107
|
* (docs/accesscontrol.md §13). Fired on directory bring-up and after every
|
|
2070
|
-
* directory pull. Never throws
|
|
2071
|
-
*
|
|
2072
|
-
* directory access from re-triggering it.
|
|
2108
|
+
* directory pull. Never throws: a reconcile error is logged and swallowed.
|
|
2109
|
+
* Resolves after a run that started after this call.
|
|
2073
2110
|
*/
|
|
2074
2111
|
async reconcileKeyDistributionsForCurrentUserSafe() {
|
|
2075
|
-
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
this.reconcileInFlight = true;
|
|
2079
|
-
try {
|
|
2080
|
-
await this.reconcileKeyDistributionsForCurrentUser();
|
|
2081
|
-
}
|
|
2082
|
-
catch (error) {
|
|
2083
|
-
this.logger.warn(`reconcileKeyDistributionsForCurrentUserSafe: ${error}`);
|
|
2084
|
-
}
|
|
2085
|
-
finally {
|
|
2086
|
-
this.reconcileInFlight = false;
|
|
2087
|
-
}
|
|
2112
|
+
await this.keyDistributionReconcile.run();
|
|
2088
2113
|
}
|
|
2089
2114
|
/**
|
|
2090
2115
|
* Export **all** stored versions of a document key for an admin-blind key
|