@abraca/dabra 2.25.0 → 2.26.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/index.d.ts
CHANGED
|
@@ -3189,7 +3189,7 @@ declare function makeEncryptedYText(ydoc: Y.Doc, fieldName: string, docKey: Cryp
|
|
|
3189
3189
|
//#region packages/provider/src/TreeTimestamps.d.ts
|
|
3190
3190
|
/**
|
|
3191
3191
|
* Attach an observer that writes `updatedAt` to the root doc-tree entry for
|
|
3192
|
-
* `childDocId` whenever the child doc receives a
|
|
3192
|
+
* `childDocId` whenever the child doc receives a local edit.
|
|
3193
3193
|
*
|
|
3194
3194
|
* @param treeMap The root doc's "doc-tree" Y.Map.
|
|
3195
3195
|
* @param childDocId The child document's UUID (key in treeMap).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.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.26.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
package/src/TreeTimestamps.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TreeTimestamps
|
|
3
3
|
*
|
|
4
|
-
* Attaches an
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Attaches an afterTransaction observer on a child Y.Doc so that whenever a
|
|
5
|
+
* LOCAL edit is made, the `updatedAt` timestamp on the corresponding entry
|
|
6
|
+
* in the root doc's `doc-tree` map is written.
|
|
7
7
|
*
|
|
8
8
|
* This propagates "last edited" timestamps to all peers via the root CRDT,
|
|
9
9
|
* without requiring any server-side changes.
|
|
@@ -20,7 +20,7 @@ import type { OfflineStore } from "./OfflineStore.ts";
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Attach an observer that writes `updatedAt` to the root doc-tree entry for
|
|
23
|
-
* `childDocId` whenever the child doc receives a
|
|
23
|
+
* `childDocId` whenever the child doc receives a local edit.
|
|
24
24
|
*
|
|
25
25
|
* @param treeMap The root doc's "doc-tree" Y.Map.
|
|
26
26
|
* @param childDocId The child document's UUID (key in treeMap).
|
|
@@ -64,8 +64,17 @@ export function attachUpdatedAtObserver(
|
|
|
64
64
|
writeTs(ts);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function handler(
|
|
68
|
-
|
|
67
|
+
function handler(tr: Y.Transaction): void {
|
|
68
|
+
// Only LOCAL edits stamp updatedAt. Remote updates (tr.local === false:
|
|
69
|
+
// initial sync replay, other peers' edits, offline-store replay,
|
|
70
|
+
// cross-tab broadcast) are stamped by the client that made them and the
|
|
71
|
+
// timestamp propagates through the root CRDT — counting them here
|
|
72
|
+
// turned "last edited" into "last synced on this client": merely
|
|
73
|
+
// opening a doc bumped its updatedAt to now.
|
|
74
|
+
if (!tr.local) return;
|
|
75
|
+
if (offlineStore !== null && tr.origin === offlineStore) return;
|
|
76
|
+
// No-op transactions (nothing actually changed) don't count as edits.
|
|
77
|
+
if (tr.changed.size === 0) return;
|
|
69
78
|
|
|
70
79
|
const now = Date.now();
|
|
71
80
|
if (now - lastFlushedAt >= throttleMs) {
|
|
@@ -80,10 +89,10 @@ export function attachUpdatedAtObserver(
|
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
childDoc.on("
|
|
92
|
+
childDoc.on("afterTransaction", handler);
|
|
84
93
|
|
|
85
94
|
return () => {
|
|
86
|
-
childDoc.off("
|
|
95
|
+
childDoc.off("afterTransaction", handler);
|
|
87
96
|
if (timer !== null) {
|
|
88
97
|
clearTimeout(timer);
|
|
89
98
|
flushPending();
|