@abraca/dabra 2.77.0 → 2.79.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 +67 -1
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +67 -1
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +102 -1
- package/package.json +2 -2
- package/src/AbracadabraBaseProvider.ts +47 -0
- package/src/AbracadabraClient.ts +31 -0
- package/src/AbracadabraProvider.ts +32 -7
- package/src/BackgroundSyncManager.ts +11 -0
- package/src/MessageReceiver.ts +15 -0
- package/src/types.ts +52 -0
|
@@ -1744,7 +1744,11 @@ var MessageReceiver = class {
|
|
|
1744
1744
|
if (emitSynced && syncMessageType === messageYjsSyncStep2) provider.synced = true;
|
|
1745
1745
|
}
|
|
1746
1746
|
applySyncStatusMessage(provider, applied) {
|
|
1747
|
-
if (applied)
|
|
1747
|
+
if (applied) {
|
|
1748
|
+
provider.decrementUnsyncedChanges();
|
|
1749
|
+
return;
|
|
1750
|
+
}
|
|
1751
|
+
provider.reportWriteRejected("server did not apply the update (permission or validation)", "validation");
|
|
1748
1752
|
}
|
|
1749
1753
|
applyAwarenessMessage(provider) {
|
|
1750
1754
|
if (!provider.awareness) return;
|
|
@@ -2487,6 +2491,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2487
2491
|
forceSyncInterval: false,
|
|
2488
2492
|
onAuthenticated: () => null,
|
|
2489
2493
|
onAuthenticationFailed: () => null,
|
|
2494
|
+
onWriteRejected: () => null,
|
|
2490
2495
|
onRateLimited: () => null,
|
|
2491
2496
|
onOpen: () => null,
|
|
2492
2497
|
onReconnected: () => null,
|
|
@@ -2526,6 +2531,8 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2526
2531
|
this.forwardDisconnect = (e) => this.emit("disconnect", e);
|
|
2527
2532
|
this.forwardDestroy = () => this.emit("destroy");
|
|
2528
2533
|
this.forwardRateLimited = () => this.emit("rateLimited");
|
|
2534
|
+
this.lastWriteRejection = null;
|
|
2535
|
+
this.writeRejectionCount = 0;
|
|
2529
2536
|
this.setConfiguration(configuration);
|
|
2530
2537
|
this.configuration.document = configuration.document ? configuration.document : new yjs.Doc();
|
|
2531
2538
|
this.configuration.awareness = configuration.awareness !== void 0 ? configuration.awareness : new Awareness(this.document);
|
|
@@ -2543,6 +2550,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2543
2550
|
this.on("unsyncedChanges", this.configuration.onUnsyncedChanges);
|
|
2544
2551
|
this.on("authenticated", this.configuration.onAuthenticated);
|
|
2545
2552
|
this.on("authenticationFailed", this.configuration.onAuthenticationFailed);
|
|
2553
|
+
this.on("writeRejected", this.configuration.onWriteRejected);
|
|
2546
2554
|
this.on("rateLimited", this.configuration.onRateLimited);
|
|
2547
2555
|
this.awareness?.on("update", () => {
|
|
2548
2556
|
this.emit("awarenessUpdate", { states: awarenessStatesToArray(this.awareness.getStates()) });
|
|
@@ -2814,6 +2822,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2814
2822
|
this.configuration.websocketProvider.attach(this);
|
|
2815
2823
|
}
|
|
2816
2824
|
permissionDeniedHandler(reason) {
|
|
2825
|
+
if (this._hasEverAuthenticated && this.isSynced) this.reportWriteRejected(reason, "permission");
|
|
2817
2826
|
this.emit("authenticationFailed", { reason });
|
|
2818
2827
|
this.isAuthenticated = false;
|
|
2819
2828
|
if (this.manageSocket && !this._hasEverAuthenticated) try {
|
|
@@ -2822,6 +2831,23 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2822
2831
|
if (!this.manageSocket && !this.isSynced && this._isAttached && this._resubscribeAttempts < AbracadabraBaseProvider.MAX_RESUBSCRIBE_ATTEMPTS && AbracadabraBaseProvider.isTransientSubscribeDenial(reason)) this.scheduleResubscribe();
|
|
2823
2832
|
}
|
|
2824
2833
|
/**
|
|
2834
|
+
* Record and announce a server-refused local change.
|
|
2835
|
+
*
|
|
2836
|
+
* Called from both nack paths: the permission-denied auth frame and
|
|
2837
|
+
* `SyncStatus(applied=0)`. Deliberately does NOT touch the unsynced counter
|
|
2838
|
+
* — the update stays queued so a retry can land it once the cause is fixed.
|
|
2839
|
+
*/
|
|
2840
|
+
reportWriteRejected(reason, kind) {
|
|
2841
|
+
const data = {
|
|
2842
|
+
documentName: this.configuration.name,
|
|
2843
|
+
reason,
|
|
2844
|
+
kind
|
|
2845
|
+
};
|
|
2846
|
+
this.lastWriteRejection = data;
|
|
2847
|
+
this.writeRejectionCount += 1;
|
|
2848
|
+
this.emit("writeRejected", data);
|
|
2849
|
+
}
|
|
2850
|
+
/**
|
|
2825
2851
|
* Whether a permission-denied reason reflects a *transient* server condition
|
|
2826
2852
|
* a retry can clear (a freshly-created doc not yet visible on this replica, or
|
|
2827
2853
|
* a dropped subscribe-ordering) rather than a permanent authorization failure.
|
|
@@ -3493,6 +3519,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
3493
3519
|
async flushPendingUpdates() {
|
|
3494
3520
|
const store = this.offlineStore;
|
|
3495
3521
|
if (!store) return;
|
|
3522
|
+
await this.persistSnapshot();
|
|
3496
3523
|
if (this.canWrite) {
|
|
3497
3524
|
const updates = await store.getPendingUpdates();
|
|
3498
3525
|
if (updates.length > 0) {
|
|
@@ -3508,6 +3535,22 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
3508
3535
|
childDocumentName: childId
|
|
3509
3536
|
});
|
|
3510
3537
|
}
|
|
3538
|
+
}
|
|
3539
|
+
/**
|
|
3540
|
+
* Persist the current merged document state to the offline store.
|
|
3541
|
+
*
|
|
3542
|
+
* This is the ONLY path that persists server-delivered content
|
|
3543
|
+
* (`documentUpdateHandler` skips `origin === this`), so it MUST run for
|
|
3544
|
+
* read-only roles too — otherwise observers/viewers get a permanently
|
|
3545
|
+
* empty offline cache and every cold start waits for a full re-sync.
|
|
3546
|
+
*
|
|
3547
|
+
* Public so short-lived consumers that load a document, read it and
|
|
3548
|
+
* immediately unload it (BackgroundSyncManager) can force the write to
|
|
3549
|
+
* land before teardown instead of racing `destroy()`.
|
|
3550
|
+
*/
|
|
3551
|
+
async persistSnapshot() {
|
|
3552
|
+
const store = this.offlineStore;
|
|
3553
|
+
if (!store) return;
|
|
3511
3554
|
const snapshot = yjs.encodeStateAsUpdate(this.document);
|
|
3512
3555
|
await store.saveDocSnapshot(snapshot).catch(() => null);
|
|
3513
3556
|
}
|
|
@@ -10988,6 +11031,28 @@ var AbracadabraClient = class {
|
|
|
10988
11031
|
return (await this.request("GET", `/docs/search?${params.toString()}`)).results;
|
|
10989
11032
|
}
|
|
10990
11033
|
/**
|
|
11034
|
+
* Documents that link TO `docId`, via `GET /docs/:id/backlinks`.
|
|
11035
|
+
*
|
|
11036
|
+
* Served from the server's `doc_links` index, which is rebuilt from each
|
|
11037
|
+
* document's CRDT state whenever a snapshot is written. Prefer this over
|
|
11038
|
+
* inverting links from a local cache: a client can only invert what it has
|
|
11039
|
+
* downloaded, so on a large space a purely local backlink list is silently
|
|
11040
|
+
* incomplete rather than empty-and-obviously-wrong.
|
|
11041
|
+
*
|
|
11042
|
+
* The caller must be able to read the target document, and each hit is
|
|
11043
|
+
* cascade-filtered, so this never reveals a document the caller couldn't
|
|
11044
|
+
* otherwise see. `limit` is clamped to `[1, 200]` server-side (default 50).
|
|
11045
|
+
*
|
|
11046
|
+
* Throws on servers that predate the endpoint — callers that need to work
|
|
11047
|
+
* against older deployments should catch and fall back to a local index.
|
|
11048
|
+
*/
|
|
11049
|
+
async getBacklinks(docId, opts) {
|
|
11050
|
+
const params = new URLSearchParams();
|
|
11051
|
+
if (opts?.limit != null) params.set("limit", String(opts.limit));
|
|
11052
|
+
const qs = params.toString();
|
|
11053
|
+
return (await this.request("GET", `/docs/${encodeURIComponent(docId)}/backlinks${qs ? `?${qs}` : ""}`)).results;
|
|
11054
|
+
}
|
|
11055
|
+
/**
|
|
10991
11056
|
* Query for documents matching a structural predicate. v1 of the
|
|
10992
11057
|
* indexed-query layer described in
|
|
10993
11058
|
* `ARCHITECTURE/20-kickoff-phase3-queries.md`.
|
|
@@ -17163,6 +17228,7 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
17163
17228
|
try {
|
|
17164
17229
|
await childProvider.ready;
|
|
17165
17230
|
await this._waitForSynced(childProvider);
|
|
17231
|
+
if (typeof childProvider.persistSnapshot === "function") await childProvider.persistSnapshot();
|
|
17166
17232
|
{
|
|
17167
17233
|
const treeEntry = treeMap.get(docId);
|
|
17168
17234
|
this.emit("docSynced", {
|