@abraca/dabra 0.9.0 → 1.0.1
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 +7081 -2848
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +7063 -2864
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +409 -114
- package/package.json +2 -1
- package/src/AbracadabraClient.ts +79 -2
- package/src/AbracadabraProvider.ts +15 -1
- package/src/BackgroundSyncManager.ts +400 -0
- package/src/BackgroundSyncPersistence.ts +107 -0
- package/src/CryptoIdentityKeystore.ts +65 -2
- package/src/DocKeyManager.ts +107 -0
- package/src/E2EAbracadabraProvider.ts +200 -0
- package/src/E2EOfflineStore.ts +55 -0
- package/src/EncryptedY.ts +145 -0
- package/src/FileBlobStore.ts +36 -0
- package/src/OfflineStore.ts +23 -0
- package/src/TreeTimestamps.ts +51 -0
- package/src/index.ts +10 -0
- package/src/types.ts +6 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TreeTimestamps
|
|
3
|
+
*
|
|
4
|
+
* Attaches an afterUpdate observer on a child Y.Doc so that whenever a
|
|
5
|
+
* non-offline update is applied, the `updatedAt` timestamp on the
|
|
6
|
+
* corresponding entry in the root doc's `doc-tree` map is written.
|
|
7
|
+
*
|
|
8
|
+
* This propagates "last edited" timestamps to all peers via the root CRDT,
|
|
9
|
+
* without requiring any server-side changes.
|
|
10
|
+
*
|
|
11
|
+
* Limitation: at least one client must have the child doc open after an edit
|
|
12
|
+
* for the timestamp to propagate (eventually consistent).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as Y from "yjs";
|
|
16
|
+
import type { OfflineStore } from "./OfflineStore.ts";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Attach an observer that writes `updatedAt: Date.now()` to the root
|
|
20
|
+
* doc-tree entry for `childDocId` whenever the child doc receives a
|
|
21
|
+
* non-offline update.
|
|
22
|
+
*
|
|
23
|
+
* @param treeMap The root doc's "doc-tree" Y.Map.
|
|
24
|
+
* @param childDocId The child document's UUID (key in treeMap).
|
|
25
|
+
* @param childDoc The child Y.Doc to observe.
|
|
26
|
+
* @param offlineStore The child provider's OfflineStore (used to detect
|
|
27
|
+
* offline-replay origins and skip them). Pass null when
|
|
28
|
+
* the offline store is disabled.
|
|
29
|
+
* @returns Cleanup function — call on provider destroy.
|
|
30
|
+
*/
|
|
31
|
+
export function attachUpdatedAtObserver(
|
|
32
|
+
treeMap: Y.Map<any>,
|
|
33
|
+
childDocId: string,
|
|
34
|
+
childDoc: Y.Doc,
|
|
35
|
+
offlineStore: OfflineStore | null,
|
|
36
|
+
): () => void {
|
|
37
|
+
function handler(update: Uint8Array, origin: unknown): void {
|
|
38
|
+
// Skip updates replayed from the local offline store — they represent
|
|
39
|
+
// content that was already "seen" and shouldn't advance updatedAt.
|
|
40
|
+
if (offlineStore !== null && origin === offlineStore) return;
|
|
41
|
+
|
|
42
|
+
// Update the root tree entry (no-op if the entry doesn't exist).
|
|
43
|
+
const entry = treeMap.get(childDocId);
|
|
44
|
+
if (!entry) return;
|
|
45
|
+
|
|
46
|
+
treeMap.set(childDocId, { ...entry, updatedAt: Date.now() });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
childDoc.on("update", handler);
|
|
50
|
+
return () => childDoc.off("update", handler);
|
|
51
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,3 +13,13 @@ export { DocumentCache } from "./DocumentCache.ts";
|
|
|
13
13
|
export type { DocumentCacheOptions } from "./DocumentCache.ts";
|
|
14
14
|
export { SearchIndex } from "./SearchIndex.ts";
|
|
15
15
|
export { FileBlobStore } from "./FileBlobStore.ts";
|
|
16
|
+
export { DocKeyManager } from "./DocKeyManager.ts";
|
|
17
|
+
export { E2EAbracadabraProvider } from "./E2EAbracadabraProvider.ts";
|
|
18
|
+
export { E2EOfflineStore } from "./E2EOfflineStore.ts";
|
|
19
|
+
export * from "./EncryptedY.ts";
|
|
20
|
+
export type { DocEncryptionInfo } from "./types.ts";
|
|
21
|
+
export { attachUpdatedAtObserver } from "./TreeTimestamps.ts";
|
|
22
|
+
export { BackgroundSyncManager } from "./BackgroundSyncManager.ts";
|
|
23
|
+
export type { BackgroundSyncManagerOptions } from "./BackgroundSyncManager.ts";
|
|
24
|
+
export { BackgroundSyncPersistence } from "./BackgroundSyncPersistence.ts";
|
|
25
|
+
export type { DocSyncState } from "./BackgroundSyncPersistence.ts";
|
package/src/types.ts
CHANGED