@dxos/echo-pipeline 0.7.4-staging.f7e8224 → 0.7.5-main.499c70c
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/lib/browser/index.mjs +129 -68
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +123 -67
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +129 -68
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +1 -0
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +3 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +1 -1
- package/dist/types/src/automerge/space-collection.d.ts +2 -1
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts +3 -0
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +1 -2
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +1 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/space-state-manager.d.ts +4 -1
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +34 -34
- package/src/automerge/automerge-host.ts +8 -1
- package/src/automerge/collection-synchronizer.ts +25 -14
- package/src/automerge/mesh-echo-replicator.ts +2 -2
- package/src/automerge/space-collection.ts +4 -2
- package/src/db-host/data-service.ts +17 -3
- package/src/db-host/echo-host.ts +9 -6
- package/src/db-host/index.ts +1 -0
- package/src/db-host/space-state-manager.ts +9 -1
- package/src/edge/echo-edge-replicator.ts +47 -19
|
@@ -223,6 +223,7 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
223
223
|
* CollectionId -> State.
|
|
224
224
|
*/
|
|
225
225
|
this._perCollectionStates = /* @__PURE__ */ new Map();
|
|
226
|
+
this._activeCollections = /* @__PURE__ */ new Set();
|
|
226
227
|
this._connectedPeers = /* @__PURE__ */ new Set();
|
|
227
228
|
this.remoteStateUpdated = new Event();
|
|
228
229
|
this._sendCollectionState = params.sendCollectionState;
|
|
@@ -232,43 +233,58 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
232
233
|
async _open(ctx) {
|
|
233
234
|
scheduleTaskInterval(this._ctx, async () => {
|
|
234
235
|
for (const collectionId of this._perCollectionStates.keys()) {
|
|
235
|
-
this.
|
|
236
|
-
|
|
236
|
+
if (this._activeCollections.has(collectionId)) {
|
|
237
|
+
this.refreshCollection(collectionId);
|
|
238
|
+
await asyncReturn();
|
|
239
|
+
}
|
|
237
240
|
}
|
|
238
241
|
}, POLL_INTERVAL);
|
|
239
242
|
}
|
|
240
243
|
getRegisteredCollectionIds() {
|
|
241
244
|
return [
|
|
242
|
-
...this.
|
|
245
|
+
...this._activeCollections
|
|
243
246
|
];
|
|
244
247
|
}
|
|
245
248
|
getLocalCollectionState(collectionId) {
|
|
246
|
-
return this.
|
|
249
|
+
return this._perCollectionStates.get(collectionId)?.localState;
|
|
247
250
|
}
|
|
248
251
|
setLocalCollectionState(collectionId, state) {
|
|
252
|
+
this._activeCollections.add(collectionId);
|
|
249
253
|
log2("setLocalCollectionState", {
|
|
250
254
|
collectionId,
|
|
251
255
|
state
|
|
252
256
|
}, {
|
|
253
257
|
F: __dxlog_file2,
|
|
254
|
-
L:
|
|
258
|
+
L: 73,
|
|
255
259
|
S: this,
|
|
256
260
|
C: (f, a) => f(...a)
|
|
257
261
|
});
|
|
258
|
-
this.
|
|
262
|
+
this._getOrCreatePerCollectionState(collectionId).localState = state;
|
|
259
263
|
queueMicrotask(async () => {
|
|
260
|
-
if (!this._ctx.disposed) {
|
|
264
|
+
if (!this._ctx.disposed && this._activeCollections.has(collectionId)) {
|
|
261
265
|
this._refreshInterestedPeers(collectionId);
|
|
262
266
|
this.refreshCollection(collectionId);
|
|
263
267
|
}
|
|
264
268
|
});
|
|
265
269
|
}
|
|
270
|
+
clearLocalCollectionState(collectionId) {
|
|
271
|
+
this._activeCollections.delete(collectionId);
|
|
272
|
+
this._perCollectionStates.delete(collectionId);
|
|
273
|
+
log2("clearLocalCollectionState", {
|
|
274
|
+
collectionId
|
|
275
|
+
}, {
|
|
276
|
+
F: __dxlog_file2,
|
|
277
|
+
L: 87,
|
|
278
|
+
S: this,
|
|
279
|
+
C: (f, a) => f(...a)
|
|
280
|
+
});
|
|
281
|
+
}
|
|
266
282
|
getRemoteCollectionStates(collectionId) {
|
|
267
|
-
return this.
|
|
283
|
+
return this._getOrCreatePerCollectionState(collectionId).remoteStates;
|
|
268
284
|
}
|
|
269
285
|
refreshCollection(collectionId) {
|
|
270
286
|
let scheduleAnotherRefresh = false;
|
|
271
|
-
const state = this.
|
|
287
|
+
const state = this._getOrCreatePerCollectionState(collectionId);
|
|
272
288
|
for (const peerId of this._connectedPeers) {
|
|
273
289
|
if (state.interestedPeers.has(peerId)) {
|
|
274
290
|
const lastQueried = state.lastQueried.get(peerId) ?? 0;
|
|
@@ -294,7 +310,7 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
294
310
|
return;
|
|
295
311
|
}
|
|
296
312
|
for (const [collectionId, state] of this._perCollectionStates.entries()) {
|
|
297
|
-
if (this._shouldSyncCollection(collectionId, peerId)) {
|
|
313
|
+
if (this._activeCollections.has(collectionId) && this._shouldSyncCollection(collectionId, peerId)) {
|
|
298
314
|
state.interestedPeers.add(peerId);
|
|
299
315
|
state.lastQueried.set(peerId, Date.now());
|
|
300
316
|
this._queryCollectionState(collectionId, peerId);
|
|
@@ -315,7 +331,7 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
315
331
|
* Callback when a peer queries the state of a collection.
|
|
316
332
|
*/
|
|
317
333
|
onCollectionStateQueried(collectionId, peerId) {
|
|
318
|
-
const perCollectionState = this.
|
|
334
|
+
const perCollectionState = this._getOrCreatePerCollectionState(collectionId);
|
|
319
335
|
if (perCollectionState.localState) {
|
|
320
336
|
this._sendCollectionState(collectionId, peerId, perCollectionState.localState);
|
|
321
337
|
}
|
|
@@ -330,19 +346,19 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
330
346
|
state
|
|
331
347
|
}, {
|
|
332
348
|
F: __dxlog_file2,
|
|
333
|
-
L:
|
|
349
|
+
L: 159,
|
|
334
350
|
S: this,
|
|
335
351
|
C: (f, a) => f(...a)
|
|
336
352
|
});
|
|
337
353
|
validateCollectionState(state);
|
|
338
|
-
const perCollectionState = this.
|
|
354
|
+
const perCollectionState = this._getOrCreatePerCollectionState(collectionId);
|
|
339
355
|
perCollectionState.remoteStates.set(peerId, state);
|
|
340
356
|
this.remoteStateUpdated.emit({
|
|
341
357
|
peerId,
|
|
342
358
|
collectionId
|
|
343
359
|
});
|
|
344
360
|
}
|
|
345
|
-
|
|
361
|
+
_getOrCreatePerCollectionState(collectionId) {
|
|
346
362
|
return defaultMap(this._perCollectionStates, collectionId, () => ({
|
|
347
363
|
localState: void 0,
|
|
348
364
|
remoteStates: /* @__PURE__ */ new Map(),
|
|
@@ -353,9 +369,9 @@ var CollectionSynchronizer = class extends Resource2 {
|
|
|
353
369
|
_refreshInterestedPeers(collectionId) {
|
|
354
370
|
for (const peerId of this._connectedPeers) {
|
|
355
371
|
if (this._shouldSyncCollection(collectionId, peerId)) {
|
|
356
|
-
this.
|
|
372
|
+
this._getOrCreatePerCollectionState(collectionId).interestedPeers.add(peerId);
|
|
357
373
|
} else {
|
|
358
|
-
this.
|
|
374
|
+
this._getOrCreatePerCollectionState(collectionId).interestedPeers.delete(peerId);
|
|
359
375
|
}
|
|
360
376
|
}
|
|
361
377
|
}
|
|
@@ -1241,6 +1257,9 @@ var AutomergeHost = class extends Resource4 {
|
|
|
1241
1257
|
documents
|
|
1242
1258
|
});
|
|
1243
1259
|
}
|
|
1260
|
+
async clearLocalCollectionState(collectionId) {
|
|
1261
|
+
this._collectionSynchronizer.clearLocalCollectionState(collectionId);
|
|
1262
|
+
}
|
|
1244
1263
|
_onCollectionStateQueried(collectionId, peerId) {
|
|
1245
1264
|
this._collectionSynchronizer.onCollectionStateQueried(collectionId, peerId);
|
|
1246
1265
|
}
|
|
@@ -1274,11 +1293,14 @@ var AutomergeHost = class extends Resource4 {
|
|
|
1274
1293
|
if (toReplicate.length === 0) {
|
|
1275
1294
|
return;
|
|
1276
1295
|
}
|
|
1277
|
-
log4.info("
|
|
1296
|
+
log4.info("replicating documents after collection sync", {
|
|
1297
|
+
collectionId,
|
|
1298
|
+
peerId,
|
|
1299
|
+
toReplicate,
|
|
1278
1300
|
count: toReplicate.length
|
|
1279
1301
|
}, {
|
|
1280
1302
|
F: __dxlog_file4,
|
|
1281
|
-
L:
|
|
1303
|
+
L: 499,
|
|
1282
1304
|
S: this,
|
|
1283
1305
|
C: (f, a) => f(...a)
|
|
1284
1306
|
});
|
|
@@ -1345,7 +1367,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
1345
1367
|
var decodeCollectionState = (state) => {
|
|
1346
1368
|
invariant3(typeof state === "object" && state !== null, "Invalid state", {
|
|
1347
1369
|
F: __dxlog_file4,
|
|
1348
|
-
L:
|
|
1370
|
+
L: 560,
|
|
1349
1371
|
S: void 0,
|
|
1350
1372
|
A: [
|
|
1351
1373
|
"typeof state === 'object' && state !== null",
|
|
@@ -1514,12 +1536,12 @@ var logSendSync = (message) => {
|
|
|
1514
1536
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1515
1537
|
import { SpaceId } from "@dxos/keys";
|
|
1516
1538
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/space-collection.ts";
|
|
1517
|
-
var deriveCollectionIdFromSpaceId = (spaceId) => `space:${spaceId}`;
|
|
1539
|
+
var deriveCollectionIdFromSpaceId = (spaceId, rootDocumentId) => rootDocumentId ? `space:${spaceId}:${rootDocumentId}` : `space:${spaceId}`;
|
|
1518
1540
|
var getSpaceIdFromCollectionId = (collectionId) => {
|
|
1519
|
-
const spaceId = collectionId.
|
|
1541
|
+
const spaceId = collectionId.split(":")[1];
|
|
1520
1542
|
invariant5(SpaceId.isValid(spaceId), void 0, {
|
|
1521
1543
|
F: __dxlog_file6,
|
|
1522
|
-
L:
|
|
1544
|
+
L: 15,
|
|
1523
1545
|
S: void 0,
|
|
1524
1546
|
A: [
|
|
1525
1547
|
"SpaceId.isValid(spaceId)",
|
|
@@ -1637,10 +1659,10 @@ var MeshEchoReplicator = class {
|
|
|
1637
1659
|
documentId: params.documentId,
|
|
1638
1660
|
peerId: connection.peerId
|
|
1639
1661
|
});
|
|
1640
|
-
log6("document not found locally for share policy check
|
|
1662
|
+
log6("document not found locally for share policy check", {
|
|
1641
1663
|
peerId: connection.peerId,
|
|
1642
1664
|
documentId: params.documentId,
|
|
1643
|
-
remoteDocumentExists
|
|
1665
|
+
acceptDocument: remoteDocumentExists
|
|
1644
1666
|
}, {
|
|
1645
1667
|
F: __dxlog_file7,
|
|
1646
1668
|
L: 91,
|
|
@@ -2103,6 +2125,7 @@ var DataServiceImpl = class {
|
|
|
2103
2125
|
*/
|
|
2104
2126
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
2105
2127
|
this._automergeHost = params.automergeHost;
|
|
2128
|
+
this._spaceStateManager = params.spaceStateManager;
|
|
2106
2129
|
this._updateIndexes = params.updateIndexes;
|
|
2107
2130
|
}
|
|
2108
2131
|
subscribe(request) {
|
|
@@ -2116,7 +2139,7 @@ var DataServiceImpl = class {
|
|
|
2116
2139
|
ready();
|
|
2117
2140
|
}).catch((err) => log7.catch(err, void 0, {
|
|
2118
2141
|
F: __dxlog_file8,
|
|
2119
|
-
L:
|
|
2142
|
+
L: 70,
|
|
2120
2143
|
S: this,
|
|
2121
2144
|
C: (f, a) => f(...a)
|
|
2122
2145
|
}));
|
|
@@ -2127,7 +2150,7 @@ var DataServiceImpl = class {
|
|
|
2127
2150
|
const synchronizer = this._subscriptions.get(request.subscriptionId);
|
|
2128
2151
|
invariant7(synchronizer, "Subscription not found", {
|
|
2129
2152
|
F: __dxlog_file8,
|
|
2130
|
-
L:
|
|
2153
|
+
L: 77,
|
|
2131
2154
|
S: this,
|
|
2132
2155
|
A: [
|
|
2133
2156
|
"synchronizer",
|
|
@@ -2148,7 +2171,7 @@ var DataServiceImpl = class {
|
|
|
2148
2171
|
const synchronizer = this._subscriptions.get(request.subscriptionId);
|
|
2149
2172
|
invariant7(synchronizer, "Subscription not found", {
|
|
2150
2173
|
F: __dxlog_file8,
|
|
2151
|
-
L:
|
|
2174
|
+
L: 92,
|
|
2152
2175
|
S: this,
|
|
2153
2176
|
A: [
|
|
2154
2177
|
"synchronizer",
|
|
@@ -2190,18 +2213,29 @@ var DataServiceImpl = class {
|
|
|
2190
2213
|
}
|
|
2191
2214
|
subscribeSpaceSyncState(request) {
|
|
2192
2215
|
return new Stream(({ ctx, next, ready }) => {
|
|
2193
|
-
|
|
2216
|
+
const spaceId = request.spaceId;
|
|
2217
|
+
invariant7(SpaceId2.isValid(spaceId), void 0, {
|
|
2194
2218
|
F: __dxlog_file8,
|
|
2195
|
-
L:
|
|
2219
|
+
L: 132,
|
|
2196
2220
|
S: this,
|
|
2197
2221
|
A: [
|
|
2198
|
-
"SpaceId.isValid(
|
|
2222
|
+
"SpaceId.isValid(spaceId)",
|
|
2199
2223
|
""
|
|
2200
2224
|
]
|
|
2201
2225
|
});
|
|
2202
|
-
const
|
|
2226
|
+
const rootDocumentId = this._spaceStateManager.getSpaceRootDocumentId(spaceId);
|
|
2227
|
+
let collectionId = rootDocumentId && deriveCollectionIdFromSpaceId(spaceId, rootDocumentId);
|
|
2228
|
+
this._spaceStateManager.spaceDocumentListUpdated.on(ctx, (event) => {
|
|
2229
|
+
const newId = deriveCollectionIdFromSpaceId(spaceId, event.spaceRootId);
|
|
2230
|
+
if (newId !== collectionId) {
|
|
2231
|
+
collectionId = newId;
|
|
2232
|
+
scheduler.trigger();
|
|
2233
|
+
}
|
|
2234
|
+
});
|
|
2203
2235
|
const scheduler = new UpdateScheduler2(ctx, async () => {
|
|
2204
|
-
const state = await this._automergeHost.getCollectionSyncState(collectionId)
|
|
2236
|
+
const state = collectionId ? await this._automergeHost.getCollectionSyncState(collectionId) : {
|
|
2237
|
+
peers: []
|
|
2238
|
+
};
|
|
2205
2239
|
next({
|
|
2206
2240
|
peers: state.peers.map((peer) => ({
|
|
2207
2241
|
peerId: peer.peerId,
|
|
@@ -2827,6 +2861,9 @@ var SpaceStateManager = class extends Resource8 {
|
|
|
2827
2861
|
getRootByDocumentId(documentId) {
|
|
2828
2862
|
return this._roots.get(documentId);
|
|
2829
2863
|
}
|
|
2864
|
+
getSpaceRootDocumentId(spaceId) {
|
|
2865
|
+
return this._rootBySpace.get(spaceId);
|
|
2866
|
+
}
|
|
2830
2867
|
async assignRootToSpace(spaceId, handle) {
|
|
2831
2868
|
let root;
|
|
2832
2869
|
if (this._roots.has(handle.documentId)) {
|
|
@@ -2846,7 +2883,7 @@ var SpaceStateManager = class extends Resource8 {
|
|
|
2846
2883
|
this._rootBySpace.set(spaceId, root.handle.documentId);
|
|
2847
2884
|
const ctx = new Context5(void 0, {
|
|
2848
2885
|
F: __dxlog_file14,
|
|
2849
|
-
L:
|
|
2886
|
+
L: 62
|
|
2850
2887
|
});
|
|
2851
2888
|
this._perRootContext.set(root.handle.documentId, ctx);
|
|
2852
2889
|
await root.handle.whenReady();
|
|
@@ -2857,7 +2894,7 @@ var SpaceStateManager = class extends Resource8 {
|
|
|
2857
2894
|
];
|
|
2858
2895
|
if (!isEqual(documentIds, this._lastSpaceDocumentList.get(spaceId))) {
|
|
2859
2896
|
this._lastSpaceDocumentList.set(spaceId, documentIds);
|
|
2860
|
-
this.spaceDocumentListUpdated.emit(new SpaceDocumentListUpdatedEvent(spaceId, documentIds));
|
|
2897
|
+
this.spaceDocumentListUpdated.emit(new SpaceDocumentListUpdatedEvent(spaceId, root.documentId, prevRootId, documentIds));
|
|
2861
2898
|
}
|
|
2862
2899
|
}, {
|
|
2863
2900
|
maxFrequency: 50
|
|
@@ -2870,8 +2907,10 @@ var SpaceStateManager = class extends Resource8 {
|
|
|
2870
2907
|
}
|
|
2871
2908
|
};
|
|
2872
2909
|
var SpaceDocumentListUpdatedEvent = class {
|
|
2873
|
-
constructor(spaceId, documentIds) {
|
|
2910
|
+
constructor(spaceId, spaceRootId, previousRootId, documentIds) {
|
|
2874
2911
|
this.spaceId = spaceId;
|
|
2912
|
+
this.spaceRootId = spaceRootId;
|
|
2913
|
+
this.previousRootId = previousRootId;
|
|
2875
2914
|
this.documentIds = documentIds;
|
|
2876
2915
|
}
|
|
2877
2916
|
};
|
|
@@ -2916,6 +2955,7 @@ var EchoHost = class extends Resource9 {
|
|
|
2916
2955
|
});
|
|
2917
2956
|
this._dataService = new DataServiceImpl({
|
|
2918
2957
|
automergeHost: this._automergeHost,
|
|
2958
|
+
spaceStateManager: this._spaceStateManager,
|
|
2919
2959
|
updateIndexes: async () => {
|
|
2920
2960
|
await this._indexer.updateIndexes();
|
|
2921
2961
|
}
|
|
@@ -2979,7 +3019,11 @@ var EchoHost = class extends Resource9 {
|
|
|
2979
3019
|
await this._queryService.open(ctx);
|
|
2980
3020
|
await this._spaceStateManager.open(ctx);
|
|
2981
3021
|
this._spaceStateManager.spaceDocumentListUpdated.on(this._ctx, (e) => {
|
|
3022
|
+
if (e.previousRootId) {
|
|
3023
|
+
void this._automergeHost.clearLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId, e.previousRootId));
|
|
3024
|
+
}
|
|
2982
3025
|
void this._automergeHost.updateLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId), e.documentIds);
|
|
3026
|
+
void this._automergeHost.updateLocalCollectionState(deriveCollectionIdFromSpaceId(e.spaceId, e.spaceRootId), e.documentIds);
|
|
2983
3027
|
});
|
|
2984
3028
|
}
|
|
2985
3029
|
async _close(ctx) {
|
|
@@ -3018,7 +3062,7 @@ var EchoHost = class extends Resource9 {
|
|
|
3018
3062
|
async createSpaceRoot(spaceKey) {
|
|
3019
3063
|
invariant11(this._lifecycleState === LifecycleState4.OPEN, void 0, {
|
|
3020
3064
|
F: __dxlog_file15,
|
|
3021
|
-
L:
|
|
3065
|
+
L: 217,
|
|
3022
3066
|
S: this,
|
|
3023
3067
|
A: [
|
|
3024
3068
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3046,7 +3090,7 @@ var EchoHost = class extends Resource9 {
|
|
|
3046
3090
|
async openSpaceRoot(spaceId, automergeUrl) {
|
|
3047
3091
|
invariant11(this._lifecycleState === LifecycleState4.OPEN, void 0, {
|
|
3048
3092
|
F: __dxlog_file15,
|
|
3049
|
-
L:
|
|
3093
|
+
L: 236,
|
|
3050
3094
|
S: this,
|
|
3051
3095
|
A: [
|
|
3052
3096
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3072,15 +3116,10 @@ var EchoHost = class extends Resource9 {
|
|
|
3072
3116
|
async removeReplicator(replicator) {
|
|
3073
3117
|
await this._automergeHost.removeReplicator(replicator);
|
|
3074
3118
|
}
|
|
3075
|
-
async getSpaceSyncState(spaceId) {
|
|
3076
|
-
const collectionId = deriveCollectionIdFromSpaceId(spaceId);
|
|
3077
|
-
return this._automergeHost.getCollectionSyncState(collectionId);
|
|
3078
|
-
}
|
|
3079
3119
|
};
|
|
3080
3120
|
|
|
3081
3121
|
// packages/core/echo/echo-pipeline/src/edge/echo-edge-replicator.ts
|
|
3082
|
-
import { Mutex, scheduleTask as scheduleTask2, scheduleMicroTask } from "@dxos/async";
|
|
3083
|
-
import * as A5 from "@dxos/automerge/automerge";
|
|
3122
|
+
import { Mutex, scheduleTask as scheduleTask2, scheduleMicroTask, Trigger as Trigger2 } from "@dxos/async";
|
|
3084
3123
|
import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
3085
3124
|
import { Context as Context6, Resource as Resource10 } from "@dxos/context";
|
|
3086
3125
|
import { randomUUID } from "@dxos/crypto";
|
|
@@ -3173,14 +3212,14 @@ var EchoEdgeReplicator = class {
|
|
|
3173
3212
|
connectedSpaces: this._connectedSpaces.size
|
|
3174
3213
|
}, {
|
|
3175
3214
|
F: __dxlog_file16,
|
|
3176
|
-
L:
|
|
3215
|
+
L: 59,
|
|
3177
3216
|
S: this,
|
|
3178
3217
|
C: (f, a) => f(...a)
|
|
3179
3218
|
});
|
|
3180
3219
|
this._context = context;
|
|
3181
3220
|
this._ctx = Context6.default(void 0, {
|
|
3182
3221
|
F: __dxlog_file16,
|
|
3183
|
-
L:
|
|
3222
|
+
L: 62
|
|
3184
3223
|
});
|
|
3185
3224
|
this._ctx.onDispose(this._edgeConnection.onReconnected(() => {
|
|
3186
3225
|
this._ctx && scheduleMicroTask(this._ctx, () => this._handleReconnect());
|
|
@@ -3259,7 +3298,7 @@ var EchoEdgeReplicator = class {
|
|
|
3259
3298
|
async _openConnection(spaceId, reconnects = 0) {
|
|
3260
3299
|
invariant12(this._context, void 0, {
|
|
3261
3300
|
F: __dxlog_file16,
|
|
3262
|
-
L:
|
|
3301
|
+
L: 123,
|
|
3263
3302
|
S: this,
|
|
3264
3303
|
A: [
|
|
3265
3304
|
"this._context",
|
|
@@ -3268,7 +3307,7 @@ var EchoEdgeReplicator = class {
|
|
|
3268
3307
|
});
|
|
3269
3308
|
invariant12(!this._connections.has(spaceId), void 0, {
|
|
3270
3309
|
F: __dxlog_file16,
|
|
3271
|
-
L:
|
|
3310
|
+
L: 124,
|
|
3272
3311
|
S: this,
|
|
3273
3312
|
A: [
|
|
3274
3313
|
"!this._connections.has(spaceId)",
|
|
@@ -3298,7 +3337,7 @@ var EchoEdgeReplicator = class {
|
|
|
3298
3337
|
restartDelay
|
|
3299
3338
|
}, {
|
|
3300
3339
|
F: __dxlog_file16,
|
|
3301
|
-
L:
|
|
3340
|
+
L: 147,
|
|
3302
3341
|
S: this,
|
|
3303
3342
|
C: (f, a) => f(...a)
|
|
3304
3343
|
});
|
|
@@ -3329,10 +3368,20 @@ var EchoEdgeReplicator = class {
|
|
|
3329
3368
|
await connection.open();
|
|
3330
3369
|
}
|
|
3331
3370
|
};
|
|
3371
|
+
var MAX_INFLIGHT_REQUESTS = 5;
|
|
3332
3372
|
var EdgeReplicatorConnection = class extends Resource10 {
|
|
3333
3373
|
constructor({ edgeConnection, spaceId, context, sharedPolicyEnabled, onRemoteConnected, onRemoteDisconnected, onRestartRequested }) {
|
|
3334
3374
|
super();
|
|
3335
3375
|
this._remotePeerId = null;
|
|
3376
|
+
/**
|
|
3377
|
+
* Prevents sending too many messages to edge over this connection so that we don't overwhelm
|
|
3378
|
+
* a replicator durable object.
|
|
3379
|
+
* inflightRequests counter is incremented on outgoing sync messages and decremented on incoming messages.
|
|
3380
|
+
* The trigger is waiting while the counter is above MAX_INFLIGHT_REQUESTS.
|
|
3381
|
+
* The counter can go negative because we receive edge-initiated sync messages on doc change broadcasts.
|
|
3382
|
+
*/
|
|
3383
|
+
this._outgoingRequestsBarrier = new Trigger2();
|
|
3384
|
+
this._inflightRequests = 0;
|
|
3336
3385
|
this._edgeConnection = edgeConnection;
|
|
3337
3386
|
this._spaceId = spaceId;
|
|
3338
3387
|
this._context = context;
|
|
@@ -3342,6 +3391,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3342
3391
|
this._onRemoteConnected = onRemoteConnected;
|
|
3343
3392
|
this._onRemoteDisconnected = onRemoteDisconnected;
|
|
3344
3393
|
this._onRestartRequested = onRestartRequested;
|
|
3394
|
+
this._outgoingRequestsBarrier.wake();
|
|
3345
3395
|
this.readable = new ReadableStream({
|
|
3346
3396
|
start: (controller) => {
|
|
3347
3397
|
this._readableStreamController = controller;
|
|
@@ -3349,6 +3399,11 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3349
3399
|
});
|
|
3350
3400
|
this.writable = new WritableStream({
|
|
3351
3401
|
write: async (message, controller) => {
|
|
3402
|
+
await this._outgoingRequestsBarrier.wait();
|
|
3403
|
+
this._inflightRequests++;
|
|
3404
|
+
if (this._inflightRequests === MAX_INFLIGHT_REQUESTS) {
|
|
3405
|
+
this._outgoingRequestsBarrier.reset();
|
|
3406
|
+
}
|
|
3352
3407
|
await this._sendMessage(message);
|
|
3353
3408
|
}
|
|
3354
3409
|
});
|
|
@@ -3356,7 +3411,7 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3356
3411
|
async _open(ctx) {
|
|
3357
3412
|
log11("open", void 0, {
|
|
3358
3413
|
F: __dxlog_file16,
|
|
3359
|
-
L:
|
|
3414
|
+
L: 261,
|
|
3360
3415
|
S: this,
|
|
3361
3416
|
C: (f, a) => f(...a)
|
|
3362
3417
|
});
|
|
@@ -3368,17 +3423,18 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3368
3423
|
async _close() {
|
|
3369
3424
|
log11("close", void 0, {
|
|
3370
3425
|
F: __dxlog_file16,
|
|
3371
|
-
L:
|
|
3426
|
+
L: 273,
|
|
3372
3427
|
S: this,
|
|
3373
3428
|
C: (f, a) => f(...a)
|
|
3374
3429
|
});
|
|
3375
3430
|
this._readableStreamController.close();
|
|
3431
|
+
this._outgoingRequestsBarrier.throw(new Error("Connection closed."));
|
|
3376
3432
|
await this._onRemoteDisconnected();
|
|
3377
3433
|
}
|
|
3378
3434
|
get peerId() {
|
|
3379
3435
|
invariant12(this._remotePeerId, "Not connected", {
|
|
3380
3436
|
F: __dxlog_file16,
|
|
3381
|
-
L:
|
|
3437
|
+
L: 282,
|
|
3382
3438
|
S: this,
|
|
3383
3439
|
A: [
|
|
3384
3440
|
"this._remotePeerId",
|
|
@@ -3397,12 +3453,13 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3397
3453
|
documentId: params.documentId,
|
|
3398
3454
|
peerId: this._remotePeerId
|
|
3399
3455
|
});
|
|
3400
|
-
log11.
|
|
3456
|
+
log11.verbose("edge-replicator document not found locally for share policy check", {
|
|
3401
3457
|
documentId: params.documentId,
|
|
3402
|
-
remoteDocumentExists
|
|
3458
|
+
acceptDocument: remoteDocumentExists,
|
|
3459
|
+
remoteId: this._remotePeerId
|
|
3403
3460
|
}, {
|
|
3404
3461
|
F: __dxlog_file16,
|
|
3405
|
-
L:
|
|
3462
|
+
L: 297,
|
|
3406
3463
|
S: this,
|
|
3407
3464
|
C: (f, a) => f(...a)
|
|
3408
3465
|
});
|
|
@@ -3415,23 +3472,20 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3415
3472
|
return true;
|
|
3416
3473
|
}
|
|
3417
3474
|
const spaceId = getSpaceIdFromCollectionId(params.collectionId);
|
|
3418
|
-
return spaceId === this._spaceId;
|
|
3475
|
+
return spaceId === this._spaceId && params.collectionId.split(":").length === 3;
|
|
3419
3476
|
}
|
|
3420
3477
|
_onMessage(message) {
|
|
3421
3478
|
if (message.serviceId !== this._targetServiceId) {
|
|
3422
3479
|
return;
|
|
3423
3480
|
}
|
|
3424
3481
|
const payload = cbor2.decode(message.payload.value);
|
|
3425
|
-
log11("
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
type: payload.type,
|
|
3430
|
-
decodedData
|
|
3431
|
-
};
|
|
3482
|
+
log11.verbose("edge replicator receive", {
|
|
3483
|
+
type: payload.type,
|
|
3484
|
+
documentId: payload.type === "sync" && payload.documentId,
|
|
3485
|
+
remoteId: this._remotePeerId
|
|
3432
3486
|
}, {
|
|
3433
3487
|
F: __dxlog_file16,
|
|
3434
|
-
L:
|
|
3488
|
+
L: 326,
|
|
3435
3489
|
S: this,
|
|
3436
3490
|
C: (f, a) => f(...a)
|
|
3437
3491
|
});
|
|
@@ -3443,18 +3497,23 @@ var EdgeReplicatorConnection = class extends Resource10 {
|
|
|
3443
3497
|
this._onRestartRequested();
|
|
3444
3498
|
return;
|
|
3445
3499
|
}
|
|
3500
|
+
if (message.type === "sync") {
|
|
3501
|
+
this._inflightRequests--;
|
|
3502
|
+
if (this._inflightRequests === MAX_INFLIGHT_REQUESTS - 1) {
|
|
3503
|
+
this._outgoingRequestsBarrier.wake();
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3446
3506
|
this._readableStreamController.enqueue(message);
|
|
3447
3507
|
}
|
|
3448
3508
|
async _sendMessage(message) {
|
|
3449
3509
|
message.targetId = this._targetServiceId;
|
|
3450
|
-
log11("send", {
|
|
3510
|
+
log11.verbose("edge replicator send", {
|
|
3451
3511
|
type: message.type,
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
documentId: message.documentId
|
|
3512
|
+
documentId: message.type === "sync" && message.documentId,
|
|
3513
|
+
remoteId: this._remotePeerId
|
|
3455
3514
|
}, {
|
|
3456
3515
|
F: __dxlog_file16,
|
|
3457
|
-
L:
|
|
3516
|
+
L: 360,
|
|
3458
3517
|
S: this,
|
|
3459
3518
|
C: (f, a) => f(...a)
|
|
3460
3519
|
});
|
|
@@ -3508,9 +3567,11 @@ export {
|
|
|
3508
3567
|
QueryServiceImpl,
|
|
3509
3568
|
QueryState,
|
|
3510
3569
|
Space,
|
|
3570
|
+
SpaceDocumentListUpdatedEvent,
|
|
3511
3571
|
SpaceManager,
|
|
3512
3572
|
SpaceProtocol,
|
|
3513
3573
|
SpaceProtocolSession,
|
|
3574
|
+
SpaceStateManager,
|
|
3514
3575
|
TimeframeClock,
|
|
3515
3576
|
codec,
|
|
3516
3577
|
createIdFromSpaceKey,
|