@abraca/dabra 2.77.0 → 2.78.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.
@@ -3463,6 +3463,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3463
3463
  async flushPendingUpdates() {
3464
3464
  const store = this.offlineStore;
3465
3465
  if (!store) return;
3466
+ await this.persistSnapshot();
3466
3467
  if (this.canWrite) {
3467
3468
  const updates = await store.getPendingUpdates();
3468
3469
  if (updates.length > 0) {
@@ -3478,6 +3479,22 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3478
3479
  childDocumentName: childId
3479
3480
  });
3480
3481
  }
3482
+ }
3483
+ /**
3484
+ * Persist the current merged document state to the offline store.
3485
+ *
3486
+ * This is the ONLY path that persists server-delivered content
3487
+ * (`documentUpdateHandler` skips `origin === this`), so it MUST run for
3488
+ * read-only roles too — otherwise observers/viewers get a permanently
3489
+ * empty offline cache and every cold start waits for a full re-sync.
3490
+ *
3491
+ * Public so short-lived consumers that load a document, read it and
3492
+ * immediately unload it (BackgroundSyncManager) can force the write to
3493
+ * land before teardown instead of racing `destroy()`.
3494
+ */
3495
+ async persistSnapshot() {
3496
+ const store = this.offlineStore;
3497
+ if (!store) return;
3481
3498
  const snapshot = Y.encodeStateAsUpdate(this.document);
3482
3499
  await store.saveDocSnapshot(snapshot).catch(() => null);
3483
3500
  }
@@ -10958,6 +10975,28 @@ var AbracadabraClient = class {
10958
10975
  return (await this.request("GET", `/docs/search?${params.toString()}`)).results;
10959
10976
  }
10960
10977
  /**
10978
+ * Documents that link TO `docId`, via `GET /docs/:id/backlinks`.
10979
+ *
10980
+ * Served from the server's `doc_links` index, which is rebuilt from each
10981
+ * document's CRDT state whenever a snapshot is written. Prefer this over
10982
+ * inverting links from a local cache: a client can only invert what it has
10983
+ * downloaded, so on a large space a purely local backlink list is silently
10984
+ * incomplete rather than empty-and-obviously-wrong.
10985
+ *
10986
+ * The caller must be able to read the target document, and each hit is
10987
+ * cascade-filtered, so this never reveals a document the caller couldn't
10988
+ * otherwise see. `limit` is clamped to `[1, 200]` server-side (default 50).
10989
+ *
10990
+ * Throws on servers that predate the endpoint — callers that need to work
10991
+ * against older deployments should catch and fall back to a local index.
10992
+ */
10993
+ async getBacklinks(docId, opts) {
10994
+ const params = new URLSearchParams();
10995
+ if (opts?.limit != null) params.set("limit", String(opts.limit));
10996
+ const qs = params.toString();
10997
+ return (await this.request("GET", `/docs/${encodeURIComponent(docId)}/backlinks${qs ? `?${qs}` : ""}`)).results;
10998
+ }
10999
+ /**
10961
11000
  * Query for documents matching a structural predicate. v1 of the
10962
11001
  * indexed-query layer described in
10963
11002
  * `ARCHITECTURE/20-kickoff-phase3-queries.md`.
@@ -17110,6 +17149,7 @@ var BackgroundSyncManager = class extends EventEmitter {
17110
17149
  try {
17111
17150
  await childProvider.ready;
17112
17151
  await this._waitForSynced(childProvider);
17152
+ if (typeof childProvider.persistSnapshot === "function") await childProvider.persistSnapshot();
17113
17153
  {
17114
17154
  const treeEntry = treeMap.get(docId);
17115
17155
  this.emit("docSynced", {