@rozek/sds-sync-engine 0.0.7 → 0.0.9
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/sds-sync-engine.js +28 -28
- package/package.json +4 -4
package/dist/sds-sync-engine.js
CHANGED
|
@@ -15,7 +15,7 @@ var G = (n, e, s, i) => ({
|
|
|
15
15
|
});
|
|
16
16
|
import { SDS_Error as U } from "@rozek/sds-core";
|
|
17
17
|
const ot = 512 * 1024;
|
|
18
|
-
var u, d, a, P,
|
|
18
|
+
var u, d, a, P, V, k, N, _, L, M, C, D, H, T, b, S, m, w, x, R, g, y, h, J, K, W, X, Y, Q, Z, I, O, tt, j;
|
|
19
19
|
class at {
|
|
20
20
|
//----------------------------------------------------------------------------//
|
|
21
21
|
// Constructor //
|
|
@@ -26,13 +26,13 @@ class at {
|
|
|
26
26
|
r(this, d);
|
|
27
27
|
r(this, a);
|
|
28
28
|
r(this, P);
|
|
29
|
-
r(this,
|
|
29
|
+
r(this, V);
|
|
30
30
|
F(this, "PeerId", crypto.randomUUID());
|
|
31
|
-
r(this,
|
|
31
|
+
r(this, k);
|
|
32
32
|
r(this, N);
|
|
33
33
|
r(this, _, []);
|
|
34
34
|
// outgoing patch queue (patches created while disconnected)
|
|
35
|
-
r(this,
|
|
35
|
+
r(this, L, 0);
|
|
36
36
|
// accumulated patch bytes since last checkpoint
|
|
37
37
|
r(this, M, 0);
|
|
38
38
|
// sequence number of the last saved snapshot
|
|
@@ -44,10 +44,10 @@ class at {
|
|
|
44
44
|
// each local mutation. Backend-agnostic: the DataStore owns the format.
|
|
45
45
|
r(this, D, new Uint8Array(0));
|
|
46
46
|
// heartbeat timer
|
|
47
|
+
r(this, H);
|
|
47
48
|
r(this, T);
|
|
48
|
-
r(this, b);
|
|
49
49
|
// presence peer tracking
|
|
50
|
-
r(this,
|
|
50
|
+
r(this, b, /* @__PURE__ */ new Map());
|
|
51
51
|
r(this, S, /* @__PURE__ */ new Map());
|
|
52
52
|
r(this, m, /* @__PURE__ */ new Set());
|
|
53
53
|
// BroadcastChannel (optional, browser/tauri only)
|
|
@@ -60,7 +60,7 @@ class at {
|
|
|
60
60
|
// tracks entryId → blob hash for all entries whose value is in a *-reference kind;
|
|
61
61
|
// used to call releaseValue() when the entry's value changes or the entry is purged
|
|
62
62
|
r(this, y, /* @__PURE__ */ new Map());
|
|
63
|
-
c(this, u, e), c(this, d, s.PersistenceProvider ?? void 0), c(this, a, s.NetworkProvider ?? void 0), c(this, P, s.PresenceProvider ?? s.NetworkProvider ?? void 0), c(this,
|
|
63
|
+
c(this, u, e), c(this, d, s.PersistenceProvider ?? void 0), c(this, a, s.NetworkProvider ?? void 0), c(this, P, s.PresenceProvider ?? s.NetworkProvider ?? void 0), c(this, V, s.PresenceTimeoutMs ?? 12e4), (s.BroadcastChannel ?? !0) && typeof BroadcastChannel < "u" && t(this, a) != null && c(this, w, new BroadcastChannel(`sds:${t(this, a).StoreId}`));
|
|
64
64
|
}
|
|
65
65
|
//----------------------------------------------------------------------------//
|
|
66
66
|
// Lifecycle //
|
|
@@ -82,7 +82,7 @@ class at {
|
|
|
82
82
|
/**** stop ****/
|
|
83
83
|
async stop() {
|
|
84
84
|
var e, s, i;
|
|
85
|
-
t(this,
|
|
85
|
+
t(this, H) != null && (clearInterval(t(this, H)), c(this, H, void 0));
|
|
86
86
|
for (const o of t(this, S).values())
|
|
87
87
|
clearTimeout(o);
|
|
88
88
|
t(this, S).clear();
|
|
@@ -91,7 +91,7 @@ class at {
|
|
|
91
91
|
o();
|
|
92
92
|
} catch {
|
|
93
93
|
}
|
|
94
|
-
c(this, g, []), (e = t(this, w)) == null || e.close(), c(this, w, void 0), (s = t(this, a)) == null || s.disconnect(), t(this, d) != null &&
|
|
94
|
+
c(this, g, []), (e = t(this, w)) == null || e.close(), c(this, w, void 0), (s = t(this, a)) == null || s.disconnect(), t(this, d) != null && await v(this, h, Q).call(this), await ((i = t(this, d)) == null ? void 0 : i.close());
|
|
95
95
|
}
|
|
96
96
|
//----------------------------------------------------------------------------//
|
|
97
97
|
// Network Connection //
|
|
@@ -100,7 +100,7 @@ class at {
|
|
|
100
100
|
async connectTo(e, s) {
|
|
101
101
|
if (t(this, a) == null)
|
|
102
102
|
throw new U("no-network-provider", "no NetworkProvider configured");
|
|
103
|
-
c(this,
|
|
103
|
+
c(this, k, e), c(this, N, s), await t(this, a).connect(e, s);
|
|
104
104
|
}
|
|
105
105
|
/**** disconnect ****/
|
|
106
106
|
disconnect() {
|
|
@@ -112,12 +112,12 @@ class at {
|
|
|
112
112
|
async reconnect() {
|
|
113
113
|
if (t(this, a) == null)
|
|
114
114
|
throw new U("no-network-provider", "no NetworkProvider configured");
|
|
115
|
-
if (t(this,
|
|
115
|
+
if (t(this, k) == null)
|
|
116
116
|
throw new U(
|
|
117
117
|
"not-yet-connected",
|
|
118
118
|
"connectTo() has not been called yet; cannot reconnect"
|
|
119
119
|
);
|
|
120
|
-
await t(this, a).connect(t(this,
|
|
120
|
+
await t(this, a).connect(t(this, k), t(this, N));
|
|
121
121
|
}
|
|
122
122
|
/**** ConnectionState ****/
|
|
123
123
|
get ConnectionState() {
|
|
@@ -135,7 +135,7 @@ class at {
|
|
|
135
135
|
/**** setPresenceTo ****/
|
|
136
136
|
setPresenceTo(e) {
|
|
137
137
|
var i, o;
|
|
138
|
-
c(this,
|
|
138
|
+
c(this, T, e);
|
|
139
139
|
const s = { ...e, PeerId: this.PeerId };
|
|
140
140
|
(i = t(this, P)) == null || i.sendLocalState(e), (o = t(this, w)) == null || o.postMessage({ type: "presence", payload: e });
|
|
141
141
|
for (const l of t(this, m))
|
|
@@ -147,7 +147,7 @@ class at {
|
|
|
147
147
|
}
|
|
148
148
|
/**** PeerSet (remote peers only) ****/
|
|
149
149
|
get PeerSet() {
|
|
150
|
-
return t(this,
|
|
150
|
+
return t(this, b);
|
|
151
151
|
}
|
|
152
152
|
/**** onPresenceChange ****/
|
|
153
153
|
onPresenceChange(e) {
|
|
@@ -156,7 +156,7 @@ class at {
|
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
u = new WeakMap(), d = new WeakMap(), a = new WeakMap(), P = new WeakMap(),
|
|
159
|
+
u = new WeakMap(), d = new WeakMap(), a = new WeakMap(), P = new WeakMap(), V = new WeakMap(), k = new WeakMap(), N = new WeakMap(), _ = new WeakMap(), L = new WeakMap(), M = new WeakMap(), C = new WeakMap(), D = new WeakMap(), H = new WeakMap(), T = new WeakMap(), b = new WeakMap(), S = new WeakMap(), m = new WeakMap(), w = new WeakMap(), x = new WeakMap(), R = new WeakMap(), g = new WeakMap(), y = new WeakMap(), h = new WeakSet(), J = async function() {
|
|
160
160
|
if (t(this, d) == null)
|
|
161
161
|
return;
|
|
162
162
|
await t(this, d).loadSnapshot();
|
|
@@ -183,7 +183,7 @@ K = function() {
|
|
|
183
183
|
G(this, C)._++;
|
|
184
184
|
const l = t(this, u).exportPatch(o);
|
|
185
185
|
c(this, D, t(this, u).currentCursor), l.byteLength !== 0 && (t(this, d) != null && (t(this, d).appendPatch(l, t(this, C)).catch(() => {
|
|
186
|
-
}), c(this,
|
|
186
|
+
}), c(this, L, t(this, L) + l.byteLength), t(this, L) >= ot && v(this, h, Q).call(this).catch(() => {
|
|
187
187
|
})), ((f = t(this, a)) == null ? void 0 : f.ConnectionState) === "connected" ? (t(this, a).sendPatch(l), (q = t(this, w)) == null || q.postMessage({ type: "patch", payload: l })) : t(this, _).push(l), v(this, h, I).call(this, i, "send").catch(() => {
|
|
188
188
|
}));
|
|
189
189
|
});
|
|
@@ -213,10 +213,10 @@ W = function() {
|
|
|
213
213
|
}
|
|
214
214
|
}, /**** #wirePresenceHeartbeat — starts a periodic timer to re-broadcast local presence state ****/
|
|
215
215
|
X = function() {
|
|
216
|
-
const e = t(this,
|
|
217
|
-
c(this,
|
|
216
|
+
const e = t(this, V) / 4;
|
|
217
|
+
c(this, H, setInterval(() => {
|
|
218
218
|
var s, i;
|
|
219
|
-
t(this,
|
|
219
|
+
t(this, T) != null && ((s = t(this, P)) == null || s.sendLocalState(t(this, T)), (i = t(this, w)) == null || i.postMessage({ type: "presence", payload: t(this, T) }));
|
|
220
220
|
}, e));
|
|
221
221
|
}, /**** #wireBroadcastChannel — wires the BroadcastChannel for cross-tab patch and presence relay ****/
|
|
222
222
|
Y = function() {
|
|
@@ -237,7 +237,7 @@ Y = function() {
|
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
239
|
}, Q = async function() {
|
|
240
|
-
t(this, d) != null && (await t(this, d).saveSnapshot(t(this, u).asBinary()), await t(this, d).prunePatches(t(this, C)), c(this, M, t(this, C)), c(this,
|
|
240
|
+
t(this, d) != null && (await t(this, d).saveSnapshot(t(this, u).asBinary()), await t(this, d).prunePatches(t(this, C)), c(this, M, t(this, C)), c(this, L, 0));
|
|
241
241
|
}, //----------------------------------------------------------------------------//
|
|
242
242
|
// Offline Queue Flush //
|
|
243
243
|
//----------------------------------------------------------------------------//
|
|
@@ -256,8 +256,8 @@ Z = function() {
|
|
|
256
256
|
for (const [f, q] of Object.entries(e)) {
|
|
257
257
|
const $ = q;
|
|
258
258
|
if ($.has("Existence")) {
|
|
259
|
-
const
|
|
260
|
-
|
|
259
|
+
const B = t(this, y).get(f);
|
|
260
|
+
B != null && (await ((i = t(this, d)) == null ? void 0 : i.releaseValue(B)), t(this, y).delete(f));
|
|
261
261
|
}
|
|
262
262
|
if (!$.has("Value"))
|
|
263
263
|
continue;
|
|
@@ -268,8 +268,8 @@ Z = function() {
|
|
|
268
268
|
continue;
|
|
269
269
|
}
|
|
270
270
|
if (s === "send") {
|
|
271
|
-
const
|
|
272
|
-
|
|
271
|
+
const B = t(this, u).getValueBlobByHash(p.Hash);
|
|
272
|
+
B != null && (await ((l = t(this, d)) == null ? void 0 : l.saveValue(p.Hash, B)), t(this, y).set(f, p.Hash), t(this, a).ConnectionState === "connected" && t(this, a).sendValue(p.Hash, B));
|
|
273
273
|
} else
|
|
274
274
|
t(this, y).set(f, p.Hash), !t(this, u).hasValueBlob(p.Hash) && t(this, a).ConnectionState === "connected" && t(this, a).requestValue(p.Hash);
|
|
275
275
|
}
|
|
@@ -284,7 +284,7 @@ O = function(e, s) {
|
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
286
|
const i = { ...s, _lastSeen: Date.now() };
|
|
287
|
-
t(this,
|
|
287
|
+
t(this, b).set(e, i), v(this, h, tt).call(this, e);
|
|
288
288
|
for (const o of t(this, m))
|
|
289
289
|
try {
|
|
290
290
|
o(e, s, "remote");
|
|
@@ -299,14 +299,14 @@ tt = function(e) {
|
|
|
299
299
|
() => {
|
|
300
300
|
v(this, h, j).call(this, e);
|
|
301
301
|
},
|
|
302
|
-
t(this,
|
|
302
|
+
t(this, V)
|
|
303
303
|
);
|
|
304
304
|
t(this, S).set(e, i);
|
|
305
305
|
}, /**** #removePeer — removes a peer from the peer set and notifies presence change handlers ****/
|
|
306
306
|
j = function(e) {
|
|
307
|
-
if (!t(this,
|
|
307
|
+
if (!t(this, b).has(e))
|
|
308
308
|
return;
|
|
309
|
-
t(this,
|
|
309
|
+
t(this, b).delete(e);
|
|
310
310
|
const s = t(this, S).get(e);
|
|
311
311
|
s != null && (clearTimeout(s), t(this, S).delete(e));
|
|
312
312
|
for (const i of t(this, m))
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rozek/sds-sync-engine",
|
|
3
3
|
"description": "Coordinates persistence, network and presence for shareable-data-store",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"author": "Andreas Rozek",
|
|
6
6
|
"homepage": "https://github.com/rozek/shareable-data-store#readme",
|
|
7
7
|
"repository": {
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@rozek/sds-core": "0.0.
|
|
30
|
+
"@rozek/sds-core": "0.0.9"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typescript": "^5.7.2",
|
|
34
34
|
"vite": "^6.0.0",
|
|
35
35
|
"vite-plugin-dts": "^4.0.0",
|
|
36
36
|
"vitest": "^2.0.0",
|
|
37
|
-
"@rozek/sds-core": "0.0.
|
|
38
|
-
"@rozek/sds-core-jj": "0.0.
|
|
37
|
+
"@rozek/sds-core": "0.0.9",
|
|
38
|
+
"@rozek/sds-core-jj": "0.0.9"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|