@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.
- package/dist/abracadabra-provider.cjs +40 -0
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +40 -0
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +46 -1
- package/package.json +2 -2
- package/src/AbracadabraClient.ts +31 -0
- package/src/AbracadabraProvider.ts +32 -7
- package/src/BackgroundSyncManager.ts +11 -0
- package/src/types.ts +14 -0
package/dist/index.d.ts
CHANGED
|
@@ -584,6 +584,25 @@ declare class AbracadabraClient {
|
|
|
584
584
|
searchDocs(query: string, opts?: {
|
|
585
585
|
limit?: number;
|
|
586
586
|
}): Promise<DocSearchHit[]>;
|
|
587
|
+
/**
|
|
588
|
+
* Documents that link TO `docId`, via `GET /docs/:id/backlinks`.
|
|
589
|
+
*
|
|
590
|
+
* Served from the server's `doc_links` index, which is rebuilt from each
|
|
591
|
+
* document's CRDT state whenever a snapshot is written. Prefer this over
|
|
592
|
+
* inverting links from a local cache: a client can only invert what it has
|
|
593
|
+
* downloaded, so on a large space a purely local backlink list is silently
|
|
594
|
+
* incomplete rather than empty-and-obviously-wrong.
|
|
595
|
+
*
|
|
596
|
+
* The caller must be able to read the target document, and each hit is
|
|
597
|
+
* cascade-filtered, so this never reveals a document the caller couldn't
|
|
598
|
+
* otherwise see. `limit` is clamped to `[1, 200]` server-side (default 50).
|
|
599
|
+
*
|
|
600
|
+
* Throws on servers that predate the endpoint — callers that need to work
|
|
601
|
+
* against older deployments should catch and fall back to a local index.
|
|
602
|
+
*/
|
|
603
|
+
getBacklinks(docId: string, opts?: {
|
|
604
|
+
limit?: number;
|
|
605
|
+
}): Promise<DocBacklink[]>;
|
|
587
606
|
/**
|
|
588
607
|
* Query for documents matching a structural predicate. v1 of the
|
|
589
608
|
* indexed-query layer described in
|
|
@@ -1506,6 +1525,19 @@ declare class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
1506
1525
|
* errors across async await boundaries.
|
|
1507
1526
|
*/
|
|
1508
1527
|
private flushPendingUpdates;
|
|
1528
|
+
/**
|
|
1529
|
+
* Persist the current merged document state to the offline store.
|
|
1530
|
+
*
|
|
1531
|
+
* This is the ONLY path that persists server-delivered content
|
|
1532
|
+
* (`documentUpdateHandler` skips `origin === this`), so it MUST run for
|
|
1533
|
+
* read-only roles too — otherwise observers/viewers get a permanently
|
|
1534
|
+
* empty offline cache and every cold start waits for a full re-sync.
|
|
1535
|
+
*
|
|
1536
|
+
* Public so short-lived consumers that load a document, read it and
|
|
1537
|
+
* immediately unload it (BackgroundSyncManager) can force the write to
|
|
1538
|
+
* land before teardown instead of racing `destroy()`.
|
|
1539
|
+
*/
|
|
1540
|
+
persistSnapshot(): Promise<void>;
|
|
1509
1541
|
get isConnected(): boolean;
|
|
1510
1542
|
destroy(): void;
|
|
1511
1543
|
}
|
|
@@ -2020,6 +2052,19 @@ interface SearchResult {
|
|
|
2020
2052
|
* a backend-specific score (SQLite bm25 vs Postgres ts_rank); the only
|
|
2021
2053
|
* guarantee is that hits arrive in best-first order.
|
|
2022
2054
|
*/
|
|
2055
|
+
/**
|
|
2056
|
+
* One inbound link, as returned by `GET /docs/:id/backlinks`.
|
|
2057
|
+
*
|
|
2058
|
+
* Deliberately thin: identity plus enough to render a row. Anything richer
|
|
2059
|
+
* (icon, breadcrumb, the sentence the link sits in) lives in the client's own
|
|
2060
|
+
* tree/index — the server index only knows the edge.
|
|
2061
|
+
*/
|
|
2062
|
+
interface DocBacklink {
|
|
2063
|
+
doc_id: string;
|
|
2064
|
+
label: string | null;
|
|
2065
|
+
/** Structural role tag (`space`/`page`/`channel`/…), when the doc has one. */
|
|
2066
|
+
kind: string | null;
|
|
2067
|
+
}
|
|
2023
2068
|
interface DocSearchHit {
|
|
2024
2069
|
doc_id: string;
|
|
2025
2070
|
parent_id: string | null;
|
|
@@ -6002,4 +6047,4 @@ declare function collectMediaFileBlocks(root: Y.XmlFragment | Y.XmlElement): Med
|
|
|
6002
6047
|
*/
|
|
6003
6048
|
declare function reconcileDocCover(treeMap: Y.Map<unknown>, docId: string, fragment: Y.XmlFragment | Y.XmlElement): void;
|
|
6004
6049
|
//#endregion
|
|
6005
|
-
export { AbracadabraBaseProvider, AbracadabraBaseProviderConfiguration, AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AbracadabraWS, AbracadabraWSConfiguration, AbracadabraWebRTC, type AbracadabraWebRTCConfiguration, AbracadabraWebSocketConn, AdminConfigField, AdminConfigOriginKind, AuditLogEntry, AuditQueryOpts, AuditVerifyResult, AuthFailureContext, AuthFailureReason, AuthMessageType, AuthorizedScope, AwarenessError, BackgroundSyncManager, type BackgroundSyncManagerOptions, BackgroundSyncPersistence, BroadcastChannelSync, CHANNEL_NAMES, ChannelKeyResolver, type ChatChannel, ChatClient, type ChatClientTransport, type MarkReadInput as ChatMarkReadInput, type ChatMessage, type ChatReadCursor, type ChatReadReceipt, type ChatTypingEvent, type ChildrenPage, CloseEvent, CompleteAbracadabraBaseProviderConfiguration, CompleteAbracadabraWSConfiguration, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, type ConnectPolicyResult, ConnectionTimeout, Constructable, ConstructableOutgoingMessage, ContentManager, type CreateNotificationInput, CryptoIdentity, CryptoIdentityKeystore, DEFAULT_FILE_CHUNK_SIZE, DEFAULT_ICE_SERVERS, DataChannelRouter, type DeleteMessageInput, DevicePairingChannel, type DevicePairingConfig, DeviceRegistrationService, type DeviceServerStatus, type DeviceSessionRecord, type DeviceSessionStorage, type DeviceTier, type DocEncryptionInfo, DocKeyManager, DocSearchHit, type DocSyncState, type DocSyncStatus, type DocumentBlock, DocumentCache, type DocumentCacheOptions, type DocumentContent, DocumentManager, type DocumentManagerConfig, DocumentMeta, type DocumentMetaInfo, type DocumentMetaWire, E2EAbracadabraProvider, E2EEChannel, type E2EEIdentity, E2EOfflineStore, type EditMessageInput, EffectivePermissionEntry, EffectivePermissionsResponse, EffectiveRole, EncryptedChatClient, EncryptedYMap, EncryptedYText, EnvSnapshotExtension, EnvSnapshotItem, EnvSnapshotResponse, type FetchInboxInput, type FetchNotificationsInput, FileBlobStore, FileTransferChannel, FileTransferHandle, type FileTransferMeta, type FileTransferStatus, type FoldedMessage, Forbidden, GEO_TYPE_META_SCHEMAS, type GetChatHistoryInput, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, type IdentityDeviceEntry, type IdentityDocConfiguration, IdentityDocProvider, type IdentityProfile, type IdentityServerEntry, type IdentitySpaceEntry, type InboxEntry, type MarkReadInput$1 as InboxMarkReadInput, InviteRow, KEY_EXCHANGE_CHANNEL, type KeyAuthClient, Kind, type LoadKeyFileOptions, LocalStorageDeviceSessionStorage, type LoginOrRegisterOptions, ManualSignaling, type ManualSignalingBlob, type MediaFileBlock, type MessageRecord, MessageTooBig, MessageType, MetaFieldType, MetaManager, MetaValidationError, type NodeKeypair, type NotificationReadUpdate, type NotificationRecord, NotificationsClient, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PAGE_TYPES, PageMeta, PageTypeInfo, PageTypeMetaField, type PairingRequest, type PairingResult, PeerConnection, type PeerInfo, type PeerState, PendingSubdoc, PermissionEntry, type PolicyAuthClient, PublicKeyInfo, QUERY_PREFIX, QueryClient, QueryError, type QueryFrame, type QueryKind, type QuerySpec, type QuerySubscriptionHandle, type QuerySubscriptionHandlers, type QueryTransport, RPC_PREFIX, ReadyzStatus, ResetConnection, type RpcCallHandle, type RpcCallOptions, RpcClient, RpcError, type RpcErrorCode, type RpcErrorPayload, type RpcFrame, type RpcHandler, type RpcHandlerContext, type RpcKind, type RpcTarget, type RpcTransport, SERVER_ROOT_ID, type SchemaDocTypeName, type SchemaMetaOf, type SchemaRegistryLike, type SchemaValidatorLike, SearchIndex, SearchResult, type SendChatMessageInput, type SendMessageInput, type SendMessageResult, ServerInfo, type ServerProfile, type ServerRegistry, type SignalingIncoming, type SignalingOutgoing, SignalingSocket, SnapshotCreateResult, SnapshotData, SnapshotFileEntry, SnapshotForkResult, SnapshotMeta, SnapshotRestoreResult, StatesArray, StreamTokenInfo, SubdocMessage, SubdocRegisteredEvent, TYPE_ALIASES, ThumbnailOptions, TokenManager, type TokenManagerOptions, TreeEntry, TreeManager, TreeNode, TreeSearchResult, TypedDocTypeMismatchError, type TypedDocsClient, type TypedTreeEntry, Unauthorized, UploadInfo, UploadMeta, UploadQueueEntry, UploadQueueStatus, UserMetaField, UserProfile, WebSocketStatus, WsReadyStates, YjsDataChannel, addServer, attachUpdatedAtObserver, awarenessStatesToArray, wordlist as bip39Wordlist, buildBlockquoteElement, buildBlocksFromMarkdown, buildBulletListElement, buildCodeBlockElement, buildHeadingElement, buildHorizontalRuleElement, buildOrderedListElement, buildParagraphElement, buildTaskListElement, collectMediaFileBlocks, decryptChatContent, decryptField, defaultKeyFileFor, deriveDmDocId, deriveIdentityDocId, deriveSeedWrappingKey, deterministicKeypair, encryptChatContent, encryptField, filenameToLabel, foldRecords, generateMnemonic, isEncryptedContent, isPlaceholderLabel, loadOrCreateKeyFile, loadServerRegistry, loginOrRegisterWithKey, loginOrRegisterWithPolicy, makeChallengeSigner, makeEncryptedYMap, makeEncryptedYText, makeEntryMap, migrateLegacyDefault, mnemonicToEd25519Seed, mnemonicToKeyPair, normalizeRootId, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onCompactedParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onReconnectedParameters, onServerErrorParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters, openSyncedProvider, parseFrontmatter, patchEntry, pickEntrySpace, populateYDocFromMarkdown, readAuthMessage, readBlocksFromFragment, readEntries, reconcileDocCover, recordFromYAny, removeServer, resolvePageType, resolveServer, saveServerRegistry, serverRegistryPath, setDefault, signChallengeWithSeed, toPlain, unwrapSeed, validateMnemonic, waitForSync, withTimeout, wrapSeed, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest, yjsToMarkdown };
|
|
6050
|
+
export { AbracadabraBaseProvider, AbracadabraBaseProviderConfiguration, AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AbracadabraWS, AbracadabraWSConfiguration, AbracadabraWebRTC, type AbracadabraWebRTCConfiguration, AbracadabraWebSocketConn, AdminConfigField, AdminConfigOriginKind, AuditLogEntry, AuditQueryOpts, AuditVerifyResult, AuthFailureContext, AuthFailureReason, AuthMessageType, AuthorizedScope, AwarenessError, BackgroundSyncManager, type BackgroundSyncManagerOptions, BackgroundSyncPersistence, BroadcastChannelSync, CHANNEL_NAMES, ChannelKeyResolver, type ChatChannel, ChatClient, type ChatClientTransport, type MarkReadInput as ChatMarkReadInput, type ChatMessage, type ChatReadCursor, type ChatReadReceipt, type ChatTypingEvent, type ChildrenPage, CloseEvent, CompleteAbracadabraBaseProviderConfiguration, CompleteAbracadabraWSConfiguration, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, type ConnectPolicyResult, ConnectionTimeout, Constructable, ConstructableOutgoingMessage, ContentManager, type CreateNotificationInput, CryptoIdentity, CryptoIdentityKeystore, DEFAULT_FILE_CHUNK_SIZE, DEFAULT_ICE_SERVERS, DataChannelRouter, type DeleteMessageInput, DevicePairingChannel, type DevicePairingConfig, DeviceRegistrationService, type DeviceServerStatus, type DeviceSessionRecord, type DeviceSessionStorage, type DeviceTier, DocBacklink, type DocEncryptionInfo, DocKeyManager, DocSearchHit, type DocSyncState, type DocSyncStatus, type DocumentBlock, DocumentCache, type DocumentCacheOptions, type DocumentContent, DocumentManager, type DocumentManagerConfig, DocumentMeta, type DocumentMetaInfo, type DocumentMetaWire, E2EAbracadabraProvider, E2EEChannel, type E2EEIdentity, E2EOfflineStore, type EditMessageInput, EffectivePermissionEntry, EffectivePermissionsResponse, EffectiveRole, EncryptedChatClient, EncryptedYMap, EncryptedYText, EnvSnapshotExtension, EnvSnapshotItem, EnvSnapshotResponse, type FetchInboxInput, type FetchNotificationsInput, FileBlobStore, FileTransferChannel, FileTransferHandle, type FileTransferMeta, type FileTransferStatus, type FoldedMessage, Forbidden, GEO_TYPE_META_SCHEMAS, type GetChatHistoryInput, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, type IdentityDeviceEntry, type IdentityDocConfiguration, IdentityDocProvider, type IdentityProfile, type IdentityServerEntry, type IdentitySpaceEntry, type InboxEntry, type MarkReadInput$1 as InboxMarkReadInput, InviteRow, KEY_EXCHANGE_CHANNEL, type KeyAuthClient, Kind, type LoadKeyFileOptions, LocalStorageDeviceSessionStorage, type LoginOrRegisterOptions, ManualSignaling, type ManualSignalingBlob, type MediaFileBlock, type MessageRecord, MessageTooBig, MessageType, MetaFieldType, MetaManager, MetaValidationError, type NodeKeypair, type NotificationReadUpdate, type NotificationRecord, NotificationsClient, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PAGE_TYPES, PageMeta, PageTypeInfo, PageTypeMetaField, type PairingRequest, type PairingResult, PeerConnection, type PeerInfo, type PeerState, PendingSubdoc, PermissionEntry, type PolicyAuthClient, PublicKeyInfo, QUERY_PREFIX, QueryClient, QueryError, type QueryFrame, type QueryKind, type QuerySpec, type QuerySubscriptionHandle, type QuerySubscriptionHandlers, type QueryTransport, RPC_PREFIX, ReadyzStatus, ResetConnection, type RpcCallHandle, type RpcCallOptions, RpcClient, RpcError, type RpcErrorCode, type RpcErrorPayload, type RpcFrame, type RpcHandler, type RpcHandlerContext, type RpcKind, type RpcTarget, type RpcTransport, SERVER_ROOT_ID, type SchemaDocTypeName, type SchemaMetaOf, type SchemaRegistryLike, type SchemaValidatorLike, SearchIndex, SearchResult, type SendChatMessageInput, type SendMessageInput, type SendMessageResult, ServerInfo, type ServerProfile, type ServerRegistry, type SignalingIncoming, type SignalingOutgoing, SignalingSocket, SnapshotCreateResult, SnapshotData, SnapshotFileEntry, SnapshotForkResult, SnapshotMeta, SnapshotRestoreResult, StatesArray, StreamTokenInfo, SubdocMessage, SubdocRegisteredEvent, TYPE_ALIASES, ThumbnailOptions, TokenManager, type TokenManagerOptions, TreeEntry, TreeManager, TreeNode, TreeSearchResult, TypedDocTypeMismatchError, type TypedDocsClient, type TypedTreeEntry, Unauthorized, UploadInfo, UploadMeta, UploadQueueEntry, UploadQueueStatus, UserMetaField, UserProfile, WebSocketStatus, WsReadyStates, YjsDataChannel, addServer, attachUpdatedAtObserver, awarenessStatesToArray, wordlist as bip39Wordlist, buildBlockquoteElement, buildBlocksFromMarkdown, buildBulletListElement, buildCodeBlockElement, buildHeadingElement, buildHorizontalRuleElement, buildOrderedListElement, buildParagraphElement, buildTaskListElement, collectMediaFileBlocks, decryptChatContent, decryptField, defaultKeyFileFor, deriveDmDocId, deriveIdentityDocId, deriveSeedWrappingKey, deterministicKeypair, encryptChatContent, encryptField, filenameToLabel, foldRecords, generateMnemonic, isEncryptedContent, isPlaceholderLabel, loadOrCreateKeyFile, loadServerRegistry, loginOrRegisterWithKey, loginOrRegisterWithPolicy, makeChallengeSigner, makeEncryptedYMap, makeEncryptedYText, makeEntryMap, migrateLegacyDefault, mnemonicToEd25519Seed, mnemonicToKeyPair, normalizeRootId, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onCompactedParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onReconnectedParameters, onServerErrorParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters, openSyncedProvider, parseFrontmatter, patchEntry, pickEntrySpace, populateYDocFromMarkdown, readAuthMessage, readBlocksFromFragment, readEntries, reconcileDocCover, recordFromYAny, removeServer, resolvePageType, resolveServer, saveServerRegistry, serverRegistryPath, setDefault, signChallengeWithSeed, toPlain, unwrapSeed, validateMnemonic, waitForSync, withTimeout, wrapSeed, writeAuthenticated, writeAuthentication, writePermissionDenied, writeTokenSyncRequest, yjsToMarkdown };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.78.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.78.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
package/src/AbracadabraClient.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
SnapshotCreateResult,
|
|
18
18
|
SnapshotRestoreResult,
|
|
19
19
|
SnapshotForkResult,
|
|
20
|
+
DocBacklink,
|
|
20
21
|
DocSearchHit,
|
|
21
22
|
AuditLogEntry,
|
|
22
23
|
AuditQueryOpts,
|
|
@@ -675,6 +676,36 @@ export class AbracadabraClient {
|
|
|
675
676
|
return res.results;
|
|
676
677
|
}
|
|
677
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Documents that link TO `docId`, via `GET /docs/:id/backlinks`.
|
|
681
|
+
*
|
|
682
|
+
* Served from the server's `doc_links` index, which is rebuilt from each
|
|
683
|
+
* document's CRDT state whenever a snapshot is written. Prefer this over
|
|
684
|
+
* inverting links from a local cache: a client can only invert what it has
|
|
685
|
+
* downloaded, so on a large space a purely local backlink list is silently
|
|
686
|
+
* incomplete rather than empty-and-obviously-wrong.
|
|
687
|
+
*
|
|
688
|
+
* The caller must be able to read the target document, and each hit is
|
|
689
|
+
* cascade-filtered, so this never reveals a document the caller couldn't
|
|
690
|
+
* otherwise see. `limit` is clamped to `[1, 200]` server-side (default 50).
|
|
691
|
+
*
|
|
692
|
+
* Throws on servers that predate the endpoint — callers that need to work
|
|
693
|
+
* against older deployments should catch and fall back to a local index.
|
|
694
|
+
*/
|
|
695
|
+
async getBacklinks(
|
|
696
|
+
docId: string,
|
|
697
|
+
opts?: { limit?: number },
|
|
698
|
+
): Promise<DocBacklink[]> {
|
|
699
|
+
const params = new URLSearchParams();
|
|
700
|
+
if (opts?.limit != null) params.set("limit", String(opts.limit));
|
|
701
|
+
const qs = params.toString();
|
|
702
|
+
const res = await this.request<{ results: DocBacklink[] }>(
|
|
703
|
+
"GET",
|
|
704
|
+
`/docs/${encodeURIComponent(docId)}/backlinks${qs ? `?${qs}` : ""}`,
|
|
705
|
+
);
|
|
706
|
+
return res.results;
|
|
707
|
+
}
|
|
708
|
+
|
|
678
709
|
/**
|
|
679
710
|
* Query for documents matching a structural predicate. v1 of the
|
|
680
711
|
* indexed-query layer described in
|
|
@@ -815,10 +815,23 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
815
815
|
const store = this.offlineStore;
|
|
816
816
|
if (!store) return;
|
|
817
817
|
|
|
818
|
+
// Snapshot FIRST, before any awaited IndexedDB round-trip below.
|
|
819
|
+
//
|
|
820
|
+
// This used to run last, and the delay lost the write outright for
|
|
821
|
+
// short-lived providers: BackgroundSyncManager loads a child, awaits
|
|
822
|
+
// "synced", then unloads it in a `finally` — and `unloadChild` →
|
|
823
|
+
// `destroy()` closes the offline store. The `getPendingUpdates()` await
|
|
824
|
+
// here was enough of a gap for the store to be gone by the time the
|
|
825
|
+
// snapshot was written, and the failure is swallowed by `.catch()`.
|
|
826
|
+
// Measured on a real profile: 126 documents marked "synced" by
|
|
827
|
+
// background sync, 11 with a persisted snapshot. That is an empty
|
|
828
|
+
// offline cache for the other 115 — no offline reading, and nothing on
|
|
829
|
+
// disk for the client-side search/backlink index to walk.
|
|
830
|
+
await this.persistSnapshot();
|
|
831
|
+
|
|
818
832
|
// Flushing queued *local* writes / subdoc registrations over the wire
|
|
819
833
|
// is only meaningful for writers — a read-only session has none and
|
|
820
|
-
// must not send.
|
|
821
|
-
// guard.
|
|
834
|
+
// must not send.
|
|
822
835
|
if (this.canWrite) {
|
|
823
836
|
const updates = await store.getPendingUpdates();
|
|
824
837
|
if (updates.length > 0) {
|
|
@@ -840,11 +853,23 @@ export class AbracadabraProvider extends AbracadabraBaseProvider {
|
|
|
840
853
|
}
|
|
841
854
|
}
|
|
842
855
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* Persist the current merged document state to the offline store.
|
|
860
|
+
*
|
|
861
|
+
* This is the ONLY path that persists server-delivered content
|
|
862
|
+
* (`documentUpdateHandler` skips `origin === this`), so it MUST run for
|
|
863
|
+
* read-only roles too — otherwise observers/viewers get a permanently
|
|
864
|
+
* empty offline cache and every cold start waits for a full re-sync.
|
|
865
|
+
*
|
|
866
|
+
* Public so short-lived consumers that load a document, read it and
|
|
867
|
+
* immediately unload it (BackgroundSyncManager) can force the write to
|
|
868
|
+
* land before teardown instead of racing `destroy()`.
|
|
869
|
+
*/
|
|
870
|
+
async persistSnapshot(): Promise<void> {
|
|
871
|
+
const store = this.offlineStore;
|
|
872
|
+
if (!store) return;
|
|
848
873
|
const snapshot = Y.encodeStateAsUpdate(this.document);
|
|
849
874
|
await store.saveDocSnapshot(snapshot).catch(() => null);
|
|
850
875
|
}
|
|
@@ -628,6 +628,17 @@ export class BackgroundSyncManager extends EventEmitter {
|
|
|
628
628
|
await childProvider.ready;
|
|
629
629
|
await this._waitForSynced(childProvider);
|
|
630
630
|
|
|
631
|
+
// Force the offline snapshot to disk BEFORE the `finally` below
|
|
632
|
+
// unloads (and therefore destroys) this provider. The provider's own
|
|
633
|
+
// "synced" handler also writes one, but that runs concurrently and
|
|
634
|
+
// loses the race often enough that most background-synced documents
|
|
635
|
+
// ended up with an empty offline cache — which is also why the
|
|
636
|
+
// client-side search/backlink index had almost nothing to walk.
|
|
637
|
+
// "Synced" must mean "on disk", or this manager is lying.
|
|
638
|
+
if (typeof (childProvider as any).persistSnapshot === "function") {
|
|
639
|
+
await (childProvider as any).persistSnapshot();
|
|
640
|
+
}
|
|
641
|
+
|
|
631
642
|
// Emit docSynced while the child is still loaded so listeners can
|
|
632
643
|
// extract data (search text, file refs) without opening a new IDB.
|
|
633
644
|
{
|
package/src/types.ts
CHANGED
|
@@ -451,6 +451,20 @@ export interface SearchResult {
|
|
|
451
451
|
* a backend-specific score (SQLite bm25 vs Postgres ts_rank); the only
|
|
452
452
|
* guarantee is that hits arrive in best-first order.
|
|
453
453
|
*/
|
|
454
|
+
/**
|
|
455
|
+
* One inbound link, as returned by `GET /docs/:id/backlinks`.
|
|
456
|
+
*
|
|
457
|
+
* Deliberately thin: identity plus enough to render a row. Anything richer
|
|
458
|
+
* (icon, breadcrumb, the sentence the link sits in) lives in the client's own
|
|
459
|
+
* tree/index — the server index only knows the edge.
|
|
460
|
+
*/
|
|
461
|
+
export interface DocBacklink {
|
|
462
|
+
doc_id: string;
|
|
463
|
+
label: string | null;
|
|
464
|
+
/** Structural role tag (`space`/`page`/`channel`/…), when the doc has one. */
|
|
465
|
+
kind: string | null;
|
|
466
|
+
}
|
|
467
|
+
|
|
454
468
|
export interface DocSearchHit {
|
|
455
469
|
doc_id: string;
|
|
456
470
|
parent_id: string | null;
|