@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
|
@@ -1714,7 +1714,11 @@ var MessageReceiver = class {
|
|
|
1714
1714
|
if (emitSynced && syncMessageType === messageYjsSyncStep2) provider.synced = true;
|
|
1715
1715
|
}
|
|
1716
1716
|
applySyncStatusMessage(provider, applied) {
|
|
1717
|
-
if (applied)
|
|
1717
|
+
if (applied) {
|
|
1718
|
+
provider.decrementUnsyncedChanges();
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1721
|
+
provider.reportWriteRejected("server did not apply the update (permission or validation)", "validation");
|
|
1718
1722
|
}
|
|
1719
1723
|
applyAwarenessMessage(provider) {
|
|
1720
1724
|
if (!provider.awareness) return;
|
|
@@ -2457,6 +2461,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2457
2461
|
forceSyncInterval: false,
|
|
2458
2462
|
onAuthenticated: () => null,
|
|
2459
2463
|
onAuthenticationFailed: () => null,
|
|
2464
|
+
onWriteRejected: () => null,
|
|
2460
2465
|
onRateLimited: () => null,
|
|
2461
2466
|
onOpen: () => null,
|
|
2462
2467
|
onReconnected: () => null,
|
|
@@ -2496,6 +2501,8 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2496
2501
|
this.forwardDisconnect = (e) => this.emit("disconnect", e);
|
|
2497
2502
|
this.forwardDestroy = () => this.emit("destroy");
|
|
2498
2503
|
this.forwardRateLimited = () => this.emit("rateLimited");
|
|
2504
|
+
this.lastWriteRejection = null;
|
|
2505
|
+
this.writeRejectionCount = 0;
|
|
2499
2506
|
this.setConfiguration(configuration);
|
|
2500
2507
|
this.configuration.document = configuration.document ? configuration.document : new Y.Doc();
|
|
2501
2508
|
this.configuration.awareness = configuration.awareness !== void 0 ? configuration.awareness : new Awareness(this.document);
|
|
@@ -2513,6 +2520,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2513
2520
|
this.on("unsyncedChanges", this.configuration.onUnsyncedChanges);
|
|
2514
2521
|
this.on("authenticated", this.configuration.onAuthenticated);
|
|
2515
2522
|
this.on("authenticationFailed", this.configuration.onAuthenticationFailed);
|
|
2523
|
+
this.on("writeRejected", this.configuration.onWriteRejected);
|
|
2516
2524
|
this.on("rateLimited", this.configuration.onRateLimited);
|
|
2517
2525
|
this.awareness?.on("update", () => {
|
|
2518
2526
|
this.emit("awarenessUpdate", { states: awarenessStatesToArray(this.awareness.getStates()) });
|
|
@@ -2784,6 +2792,7 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2784
2792
|
this.configuration.websocketProvider.attach(this);
|
|
2785
2793
|
}
|
|
2786
2794
|
permissionDeniedHandler(reason) {
|
|
2795
|
+
if (this._hasEverAuthenticated && this.isSynced) this.reportWriteRejected(reason, "permission");
|
|
2787
2796
|
this.emit("authenticationFailed", { reason });
|
|
2788
2797
|
this.isAuthenticated = false;
|
|
2789
2798
|
if (this.manageSocket && !this._hasEverAuthenticated) try {
|
|
@@ -2792,6 +2801,23 @@ var AbracadabraBaseProvider = class AbracadabraBaseProvider extends EventEmitter
|
|
|
2792
2801
|
if (!this.manageSocket && !this.isSynced && this._isAttached && this._resubscribeAttempts < AbracadabraBaseProvider.MAX_RESUBSCRIBE_ATTEMPTS && AbracadabraBaseProvider.isTransientSubscribeDenial(reason)) this.scheduleResubscribe();
|
|
2793
2802
|
}
|
|
2794
2803
|
/**
|
|
2804
|
+
* Record and announce a server-refused local change.
|
|
2805
|
+
*
|
|
2806
|
+
* Called from both nack paths: the permission-denied auth frame and
|
|
2807
|
+
* `SyncStatus(applied=0)`. Deliberately does NOT touch the unsynced counter
|
|
2808
|
+
* — the update stays queued so a retry can land it once the cause is fixed.
|
|
2809
|
+
*/
|
|
2810
|
+
reportWriteRejected(reason, kind) {
|
|
2811
|
+
const data = {
|
|
2812
|
+
documentName: this.configuration.name,
|
|
2813
|
+
reason,
|
|
2814
|
+
kind
|
|
2815
|
+
};
|
|
2816
|
+
this.lastWriteRejection = data;
|
|
2817
|
+
this.writeRejectionCount += 1;
|
|
2818
|
+
this.emit("writeRejected", data);
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2795
2821
|
* Whether a permission-denied reason reflects a *transient* server condition
|
|
2796
2822
|
* a retry can clear (a freshly-created doc not yet visible on this replica, or
|
|
2797
2823
|
* a dropped subscribe-ordering) rather than a permanent authorization failure.
|
|
@@ -3463,6 +3489,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
3463
3489
|
async flushPendingUpdates() {
|
|
3464
3490
|
const store = this.offlineStore;
|
|
3465
3491
|
if (!store) return;
|
|
3492
|
+
await this.persistSnapshot();
|
|
3466
3493
|
if (this.canWrite) {
|
|
3467
3494
|
const updates = await store.getPendingUpdates();
|
|
3468
3495
|
if (updates.length > 0) {
|
|
@@ -3478,6 +3505,22 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
3478
3505
|
childDocumentName: childId
|
|
3479
3506
|
});
|
|
3480
3507
|
}
|
|
3508
|
+
}
|
|
3509
|
+
/**
|
|
3510
|
+
* Persist the current merged document state to the offline store.
|
|
3511
|
+
*
|
|
3512
|
+
* This is the ONLY path that persists server-delivered content
|
|
3513
|
+
* (`documentUpdateHandler` skips `origin === this`), so it MUST run for
|
|
3514
|
+
* read-only roles too — otherwise observers/viewers get a permanently
|
|
3515
|
+
* empty offline cache and every cold start waits for a full re-sync.
|
|
3516
|
+
*
|
|
3517
|
+
* Public so short-lived consumers that load a document, read it and
|
|
3518
|
+
* immediately unload it (BackgroundSyncManager) can force the write to
|
|
3519
|
+
* land before teardown instead of racing `destroy()`.
|
|
3520
|
+
*/
|
|
3521
|
+
async persistSnapshot() {
|
|
3522
|
+
const store = this.offlineStore;
|
|
3523
|
+
if (!store) return;
|
|
3481
3524
|
const snapshot = Y.encodeStateAsUpdate(this.document);
|
|
3482
3525
|
await store.saveDocSnapshot(snapshot).catch(() => null);
|
|
3483
3526
|
}
|
|
@@ -10958,6 +11001,28 @@ var AbracadabraClient = class {
|
|
|
10958
11001
|
return (await this.request("GET", `/docs/search?${params.toString()}`)).results;
|
|
10959
11002
|
}
|
|
10960
11003
|
/**
|
|
11004
|
+
* Documents that link TO `docId`, via `GET /docs/:id/backlinks`.
|
|
11005
|
+
*
|
|
11006
|
+
* Served from the server's `doc_links` index, which is rebuilt from each
|
|
11007
|
+
* document's CRDT state whenever a snapshot is written. Prefer this over
|
|
11008
|
+
* inverting links from a local cache: a client can only invert what it has
|
|
11009
|
+
* downloaded, so on a large space a purely local backlink list is silently
|
|
11010
|
+
* incomplete rather than empty-and-obviously-wrong.
|
|
11011
|
+
*
|
|
11012
|
+
* The caller must be able to read the target document, and each hit is
|
|
11013
|
+
* cascade-filtered, so this never reveals a document the caller couldn't
|
|
11014
|
+
* otherwise see. `limit` is clamped to `[1, 200]` server-side (default 50).
|
|
11015
|
+
*
|
|
11016
|
+
* Throws on servers that predate the endpoint — callers that need to work
|
|
11017
|
+
* against older deployments should catch and fall back to a local index.
|
|
11018
|
+
*/
|
|
11019
|
+
async getBacklinks(docId, opts) {
|
|
11020
|
+
const params = new URLSearchParams();
|
|
11021
|
+
if (opts?.limit != null) params.set("limit", String(opts.limit));
|
|
11022
|
+
const qs = params.toString();
|
|
11023
|
+
return (await this.request("GET", `/docs/${encodeURIComponent(docId)}/backlinks${qs ? `?${qs}` : ""}`)).results;
|
|
11024
|
+
}
|
|
11025
|
+
/**
|
|
10961
11026
|
* Query for documents matching a structural predicate. v1 of the
|
|
10962
11027
|
* indexed-query layer described in
|
|
10963
11028
|
* `ARCHITECTURE/20-kickoff-phase3-queries.md`.
|
|
@@ -17110,6 +17175,7 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
17110
17175
|
try {
|
|
17111
17176
|
await childProvider.ready;
|
|
17112
17177
|
await this._waitForSynced(childProvider);
|
|
17178
|
+
if (typeof childProvider.persistSnapshot === "function") await childProvider.persistSnapshot();
|
|
17113
17179
|
{
|
|
17114
17180
|
const treeEntry = treeMap.get(docId);
|
|
17115
17181
|
this.emit("docSynced", {
|