@abraca/dabra 2.30.0 → 2.32.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/dist/abracadabra-provider.cjs +26 -5
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +26 -5
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +30 -1
- package/package.json +2 -2
- package/src/AbracadabraProvider.ts +14 -0
- package/src/BackgroundSyncManager.ts +21 -5
- package/src/DeviceRegistrationService.ts +25 -11
- package/src/types.ts +19 -1
package/dist/index.d.ts
CHANGED
|
@@ -1379,6 +1379,17 @@ declare class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
1379
1379
|
getChild(childId: string): AbracadabraProvider | null;
|
|
1380
1380
|
/** Check if a child provider is already loaded. */
|
|
1381
1381
|
hasChild(childId: string): boolean;
|
|
1382
|
+
/**
|
|
1383
|
+
* Whether a loaded child is currently transient — loaded with
|
|
1384
|
+
* `{ evictable: false }` (e.g. by a background indexer/sync) and not since
|
|
1385
|
+
* promoted to a normal UI-held child. A later `loadChild(id)` with the
|
|
1386
|
+
* default `evictable: true` clears this flag.
|
|
1387
|
+
*
|
|
1388
|
+
* Background loaders use this to decide whether they still own a child
|
|
1389
|
+
* before unloading it: if the UI opened the same doc mid-sync, the child is
|
|
1390
|
+
* no longer transient and must NOT be destroyed out from under the view.
|
|
1391
|
+
*/
|
|
1392
|
+
isChildTransient(childId: string): boolean;
|
|
1382
1393
|
/**
|
|
1383
1394
|
* Create (or return cached) a child AbracadabraProvider for a given
|
|
1384
1395
|
* child document id. Each child shares the parent's WebSocket via
|
|
@@ -1923,8 +1934,26 @@ interface SearchResult {
|
|
|
1923
1934
|
interface DocSearchHit {
|
|
1924
1935
|
doc_id: string;
|
|
1925
1936
|
parent_id: string | null;
|
|
1926
|
-
|
|
1937
|
+
/**
|
|
1938
|
+
* Structural role tag (`space`/`page`/`channel`/…) — what the doc *is*,
|
|
1939
|
+
* not how it renders. See {@link doc_type} for the renderer/page type.
|
|
1940
|
+
*/
|
|
1927
1941
|
kind: string | null;
|
|
1942
|
+
label: string | null;
|
|
1943
|
+
/**
|
|
1944
|
+
* Renderer / page type (`kanban`/`graph`/`calendar`/…), surfaced by the
|
|
1945
|
+
* server from `documents.doc_type` or the CRDT-derived
|
|
1946
|
+
* `doc_meta_index.kind`. Use this as the renderer hint when opening a hit.
|
|
1947
|
+
* Absent from older servers and for plain docs.
|
|
1948
|
+
*/
|
|
1949
|
+
doc_type?: string | null;
|
|
1950
|
+
/**
|
|
1951
|
+
* The top-level space (`kind: "space"`) that contains this hit, resolved
|
|
1952
|
+
* server-side by walking the CRDT tree. Lets a client jump straight to the
|
|
1953
|
+
* space without a client-side parent walk. Absent from older servers or
|
|
1954
|
+
* when no `kind="space"` ancestor was found.
|
|
1955
|
+
*/
|
|
1956
|
+
space_id?: string | null;
|
|
1928
1957
|
/** HTML-safe snippet with `<mark>` markers around the matched tokens. */
|
|
1929
1958
|
snippet: string;
|
|
1930
1959
|
rank: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yjs": "^13.6.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@abraca/schema": "2.
|
|
44
|
+
"@abraca/schema": "2.32.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
|
@@ -529,6 +529,20 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
529
529
|
return this.childProviders.has(childId);
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Whether a loaded child is currently transient — loaded with
|
|
534
|
+
* `{ evictable: false }` (e.g. by a background indexer/sync) and not since
|
|
535
|
+
* promoted to a normal UI-held child. A later `loadChild(id)` with the
|
|
536
|
+
* default `evictable: true` clears this flag.
|
|
537
|
+
*
|
|
538
|
+
* Background loaders use this to decide whether they still own a child
|
|
539
|
+
* before unloading it: if the UI opened the same doc mid-sync, the child is
|
|
540
|
+
* no longer transient and must NOT be destroyed out from under the view.
|
|
541
|
+
*/
|
|
542
|
+
isChildTransient(childId: string): boolean {
|
|
543
|
+
return this.transientChildren.has(childId);
|
|
544
|
+
}
|
|
545
|
+
|
|
532
546
|
/**
|
|
533
547
|
* Create (or return cached) a child AbracadabraProvider for a given
|
|
534
548
|
* child document id. Each child shares the parent's WebSocket via
|
|
@@ -615,7 +615,13 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
|
|
618
|
+
// Load transiently: a background-sync child must neither count toward
|
|
619
|
+
// the parent's LRU budget nor evict the user's open docs, and it must
|
|
620
|
+
// not be evicted out from under its own in-flight sync. We clean it up
|
|
621
|
+
// explicitly in `finally`.
|
|
622
|
+
const childProvider = await this.rootProvider.loadChild(docId, {
|
|
623
|
+
evictable: false,
|
|
624
|
+
});
|
|
619
625
|
|
|
620
626
|
try {
|
|
621
627
|
// Wait for ready (offline snapshot loaded) then synced (server sync done)
|
|
@@ -651,11 +657,21 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
651
657
|
isE2E: false,
|
|
652
658
|
};
|
|
653
659
|
} finally {
|
|
654
|
-
//
|
|
655
|
-
//
|
|
656
|
-
//
|
|
660
|
+
// Release the provider only if we created it solely for background
|
|
661
|
+
// sync. Two cases keep it alive:
|
|
662
|
+
// - `alreadyCached`: it was loaded before we started — the UI owns it.
|
|
663
|
+
// - the user OPENED it mid-sync: `loadChild` (default evictable)
|
|
664
|
+
// promoted it out of transient, so it's no longer ours. Destroying
|
|
665
|
+
// it here would detach the provider under a doc they're viewing,
|
|
666
|
+
// leaving it stuck on a blue/"retrying" indicator until reload.
|
|
667
|
+
// `isChildTransient` is a newer provider API; fall back to the old
|
|
668
|
+
// unconditional unload if the parent predates it.
|
|
657
669
|
if (!alreadyCached) {
|
|
658
|
-
|
|
670
|
+
const stillOurs =
|
|
671
|
+
typeof (this.rootProvider as any).isChildTransient === "function"
|
|
672
|
+
? (this.rootProvider as any).isChildTransient(docId)
|
|
673
|
+
: true;
|
|
674
|
+
if (stillOurs) this.rootProvider.unloadChild(docId);
|
|
659
675
|
}
|
|
660
676
|
}
|
|
661
677
|
}
|
|
@@ -178,6 +178,14 @@ export class DeviceRegistrationService {
|
|
|
178
178
|
|
|
179
179
|
const devicesMap = identityDoc.devicesMap;
|
|
180
180
|
|
|
181
|
+
// Pending revocations are collected during the (synchronous) scan and
|
|
182
|
+
// executed AFTER it — never fire-and-forget inside the forEach. The old
|
|
183
|
+
// code kicked off `client.revokeKey(...)` without awaiting, so reconcile
|
|
184
|
+
// resolved before the revoke landed: the caller's next request then
|
|
185
|
+
// raced the in-flight revoke and ran with a token the revoke had just
|
|
186
|
+
// invalidated server-side (revoke re-mints + bumps tokens_invalid_before).
|
|
187
|
+
const pendingRevocations: { devicePub: string; keyId: string }[] = [];
|
|
188
|
+
|
|
181
189
|
// 1. Verify Y.Doc matches server reality
|
|
182
190
|
devicesMap.forEach((yEntry, devicePub) => {
|
|
183
191
|
const serversYMap = yEntry.get("servers") as
|
|
@@ -211,22 +219,28 @@ export class DeviceRegistrationService {
|
|
|
211
219
|
});
|
|
212
220
|
}
|
|
213
221
|
|
|
214
|
-
//
|
|
222
|
+
// Queue revocation if we're a master device — executed (awaited)
|
|
223
|
+
// after the scan, below.
|
|
215
224
|
if (revokedAt && isMaster) {
|
|
216
|
-
|
|
217
|
-
.revokeKey(serverKey.id)
|
|
218
|
-
.then(() => {
|
|
219
|
-
identityDoc.setDeviceServerStatus(
|
|
220
|
-
devicePub,
|
|
221
|
-
serverUrl,
|
|
222
|
-
{ registered: false },
|
|
223
|
-
);
|
|
224
|
-
})
|
|
225
|
-
.catch(() => {});
|
|
225
|
+
pendingRevocations.push({ devicePub, keyId: serverKey.id });
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
// Execute queued revocations serially so each `revokeKey` captures the
|
|
231
|
+
// re-minted token (revokeKey updates the client's token) before the next
|
|
232
|
+
// call — and so reconcile only resolves once they have actually landed.
|
|
233
|
+
for (const { devicePub, keyId } of pendingRevocations) {
|
|
234
|
+
try {
|
|
235
|
+
await client.revokeKey(keyId);
|
|
236
|
+
identityDoc.setDeviceServerStatus(devicePub, serverUrl, {
|
|
237
|
+
registered: false,
|
|
238
|
+
});
|
|
239
|
+
} catch {
|
|
240
|
+
// Leave Y.Doc as-is; the next reconcile retries.
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
230
244
|
// 2. Import unknown server keys into Y.Doc (migration)
|
|
231
245
|
for (const key of serverKeys) {
|
|
232
246
|
if (key.revoked) continue;
|
package/src/types.ts
CHANGED
|
@@ -421,8 +421,26 @@ export interface SearchResult {
|
|
|
421
421
|
export interface DocSearchHit {
|
|
422
422
|
doc_id: string;
|
|
423
423
|
parent_id: string | null;
|
|
424
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Structural role tag (`space`/`page`/`channel`/…) — what the doc *is*,
|
|
426
|
+
* not how it renders. See {@link doc_type} for the renderer/page type.
|
|
427
|
+
*/
|
|
425
428
|
kind: string | null;
|
|
429
|
+
label: string | null;
|
|
430
|
+
/**
|
|
431
|
+
* Renderer / page type (`kanban`/`graph`/`calendar`/…), surfaced by the
|
|
432
|
+
* server from `documents.doc_type` or the CRDT-derived
|
|
433
|
+
* `doc_meta_index.kind`. Use this as the renderer hint when opening a hit.
|
|
434
|
+
* Absent from older servers and for plain docs.
|
|
435
|
+
*/
|
|
436
|
+
doc_type?: string | null;
|
|
437
|
+
/**
|
|
438
|
+
* The top-level space (`kind: "space"`) that contains this hit, resolved
|
|
439
|
+
* server-side by walking the CRDT tree. Lets a client jump straight to the
|
|
440
|
+
* space without a client-side parent walk. Absent from older servers or
|
|
441
|
+
* when no `kind="space"` ancestor was found.
|
|
442
|
+
*/
|
|
443
|
+
space_id?: string | null;
|
|
426
444
|
/** HTML-safe snippet with `<mark>` markers around the matched tokens. */
|
|
427
445
|
snippet: string;
|
|
428
446
|
rank: number;
|