@dxos/echo-pipeline 0.6.1-main.ff751ec → 0.6.1-next.f8e935e
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/{chunk-O3MAK5PY.mjs → chunk-DMUP426Q.mjs} +17 -5
- package/dist/lib/browser/chunk-DMUP426Q.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +284 -184
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-QATBVT6S.cjs → chunk-NH5WJKOW.cjs} +20 -8
- package/dist/lib/node/chunk-NH5WJKOW.cjs.map +7 -0
- package/dist/lib/node/index.cjs +327 -231
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +11 -11
- package/dist/types/src/automerge/automerge-host.d.ts +6 -2
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -2
- package/dist/types/src/automerge/echo-network-adapter.test.d.ts +2 -0
- package/dist/types/src/automerge/echo-network-adapter.test.d.ts.map +1 -0
- package/dist/types/src/automerge/echo-replicator.d.ts +5 -6
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +35 -0
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -0
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts +2 -2
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts +11 -3
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-host.ts +57 -11
- package/src/automerge/automerge-repo.test.ts +117 -1
- package/src/automerge/echo-network-adapter.test.ts +131 -0
- package/src/automerge/echo-network-adapter.ts +4 -4
- package/src/automerge/echo-replicator.ts +6 -9
- package/src/automerge/mesh-echo-replicator-connection.ts +130 -0
- package/src/automerge/mesh-echo-replicator.ts +15 -123
- package/src/db-host/data-service.ts +38 -5
- package/dist/lib/browser/chunk-O3MAK5PY.mjs.map +0 -7
- package/dist/lib/node/chunk-QATBVT6S.cjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,74 +18,78 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
AuthExtension: () =>
|
|
22
|
-
AuthStatus: () =>
|
|
21
|
+
AuthExtension: () => import_chunk_NH5WJKOW.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_NH5WJKOW.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
|
-
CredentialRetrieverExtension: () =>
|
|
26
|
-
CredentialServerExtension: () =>
|
|
27
|
-
DataServiceImpl: () =>
|
|
25
|
+
CredentialRetrieverExtension: () => import_chunk_NH5WJKOW.CredentialRetrieverExtension,
|
|
26
|
+
CredentialServerExtension: () => import_chunk_NH5WJKOW.CredentialServerExtension,
|
|
27
|
+
DataServiceImpl: () => import_chunk_NH5WJKOW.DataServiceImpl,
|
|
28
28
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
29
29
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
30
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
31
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
30
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_NH5WJKOW.MOCK_AUTH_PROVIDER,
|
|
31
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_NH5WJKOW.MOCK_AUTH_VERIFIER,
|
|
32
32
|
MeshEchoReplicator: () => MeshEchoReplicator,
|
|
33
|
-
MetadataStore: () =>
|
|
34
|
-
Pipeline: () =>
|
|
35
|
-
SnapshotManager: () =>
|
|
36
|
-
SnapshotStore: () =>
|
|
37
|
-
Space: () =>
|
|
38
|
-
SpaceManager: () =>
|
|
39
|
-
SpaceProtocol: () =>
|
|
40
|
-
SpaceProtocolSession: () =>
|
|
41
|
-
TimeframeClock: () =>
|
|
42
|
-
codec: () =>
|
|
43
|
-
createIdFromSpaceKey: () =>
|
|
44
|
-
createMappedFeedWriter: () =>
|
|
33
|
+
MetadataStore: () => import_chunk_NH5WJKOW.MetadataStore,
|
|
34
|
+
Pipeline: () => import_chunk_NH5WJKOW.Pipeline,
|
|
35
|
+
SnapshotManager: () => import_chunk_NH5WJKOW.SnapshotManager,
|
|
36
|
+
SnapshotStore: () => import_chunk_NH5WJKOW.SnapshotStore,
|
|
37
|
+
Space: () => import_chunk_NH5WJKOW.Space,
|
|
38
|
+
SpaceManager: () => import_chunk_NH5WJKOW.SpaceManager,
|
|
39
|
+
SpaceProtocol: () => import_chunk_NH5WJKOW.SpaceProtocol,
|
|
40
|
+
SpaceProtocolSession: () => import_chunk_NH5WJKOW.SpaceProtocolSession,
|
|
41
|
+
TimeframeClock: () => import_chunk_NH5WJKOW.TimeframeClock,
|
|
42
|
+
codec: () => import_chunk_NH5WJKOW.codec,
|
|
43
|
+
createIdFromSpaceKey: () => import_chunk_NH5WJKOW.createIdFromSpaceKey,
|
|
44
|
+
createMappedFeedWriter: () => import_chunk_NH5WJKOW.createMappedFeedWriter,
|
|
45
45
|
encodingOptions: () => encodingOptions,
|
|
46
46
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
47
|
-
hasInvitationExpired: () =>
|
|
48
|
-
mapFeedIndexesToTimeframe: () =>
|
|
49
|
-
mapTimeframeToFeedIndexes: () =>
|
|
50
|
-
startAfter: () =>
|
|
51
|
-
valueEncoding: () =>
|
|
47
|
+
hasInvitationExpired: () => import_chunk_NH5WJKOW.hasInvitationExpired,
|
|
48
|
+
mapFeedIndexesToTimeframe: () => import_chunk_NH5WJKOW.mapFeedIndexesToTimeframe,
|
|
49
|
+
mapTimeframeToFeedIndexes: () => import_chunk_NH5WJKOW.mapTimeframeToFeedIndexes,
|
|
50
|
+
startAfter: () => import_chunk_NH5WJKOW.startAfter,
|
|
51
|
+
valueEncoding: () => import_chunk_NH5WJKOW.valueEncoding
|
|
52
52
|
});
|
|
53
53
|
module.exports = __toCommonJS(node_exports);
|
|
54
|
-
var
|
|
54
|
+
var import_chunk_NH5WJKOW = require("./chunk-NH5WJKOW.cjs");
|
|
55
55
|
var import_async = require("@dxos/async");
|
|
56
56
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
57
57
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
58
58
|
var import_context = require("@dxos/context");
|
|
59
|
+
var import_invariant = require("@dxos/invariant");
|
|
59
60
|
var import_keys = require("@dxos/keys");
|
|
61
|
+
var import_log = require("@dxos/log");
|
|
60
62
|
var import_protocols = require("@dxos/protocols");
|
|
61
63
|
var import_tracing = require("@dxos/tracing");
|
|
62
64
|
var import_util = require("@dxos/util");
|
|
63
65
|
var import_async2 = require("@dxos/async");
|
|
64
66
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
65
67
|
var import_context2 = require("@dxos/context");
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
69
|
+
var import_log2 = require("@dxos/log");
|
|
68
70
|
var import_indexing = require("@dxos/indexing");
|
|
69
71
|
var import_context3 = require("@dxos/context");
|
|
70
72
|
var import_async3 = require("@dxos/async");
|
|
71
73
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
72
74
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
73
|
-
var
|
|
75
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
74
76
|
var import_async4 = require("@dxos/async");
|
|
75
77
|
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
76
78
|
var import_context4 = require("@dxos/context");
|
|
77
79
|
var import_debug = require("@dxos/debug");
|
|
78
80
|
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
82
|
+
var import_log3 = require("@dxos/log");
|
|
81
83
|
var import_tracing2 = require("@dxos/tracing");
|
|
84
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
85
|
+
var import_keys2 = require("@dxos/keys");
|
|
86
|
+
var import_log4 = require("@dxos/log");
|
|
87
|
+
var import_util2 = require("@dxos/util");
|
|
82
88
|
var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
|
|
83
89
|
var import_context5 = require("@dxos/context");
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
var import_log3 = require("@dxos/log");
|
|
90
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
91
|
+
var import_log5 = require("@dxos/log");
|
|
87
92
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
88
|
-
var import_util2 = require("@dxos/util");
|
|
89
93
|
function _ts_decorate(decorators, target, key, desc) {
|
|
90
94
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
91
95
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -118,7 +122,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
118
122
|
}
|
|
119
123
|
connectionEntry.writer.write(message).catch((err) => {
|
|
120
124
|
if (connectionEntry.isOpen) {
|
|
121
|
-
|
|
125
|
+
import_log2.log.catch(err, void 0, {
|
|
122
126
|
F: __dxlog_file,
|
|
123
127
|
L: 49,
|
|
124
128
|
S: this,
|
|
@@ -134,7 +138,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
140
|
this._lifecycleState = import_context2.LifecycleState.OPEN;
|
|
137
|
-
(0,
|
|
141
|
+
(0, import_log2.log)("emit ready", void 0, {
|
|
138
142
|
F: __dxlog_file,
|
|
139
143
|
L: 65,
|
|
140
144
|
S: this,
|
|
@@ -160,7 +164,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
160
164
|
});
|
|
161
165
|
}
|
|
162
166
|
async addReplicator(replicator) {
|
|
163
|
-
(0,
|
|
167
|
+
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
164
168
|
F: __dxlog_file,
|
|
165
169
|
L: 91,
|
|
166
170
|
S: this,
|
|
@@ -169,7 +173,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
169
173
|
""
|
|
170
174
|
]
|
|
171
175
|
});
|
|
172
|
-
(0,
|
|
176
|
+
(0, import_invariant2.invariant)(this.peerId, void 0, {
|
|
173
177
|
F: __dxlog_file,
|
|
174
178
|
L: 92,
|
|
175
179
|
S: this,
|
|
@@ -178,7 +182,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
178
182
|
""
|
|
179
183
|
]
|
|
180
184
|
});
|
|
181
|
-
(0,
|
|
185
|
+
(0, import_invariant2.invariant)(!this._replicators.has(replicator), void 0, {
|
|
182
186
|
F: __dxlog_file,
|
|
183
187
|
L: 93,
|
|
184
188
|
S: this,
|
|
@@ -197,7 +201,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
197
201
|
});
|
|
198
202
|
}
|
|
199
203
|
async removeReplicator(replicator) {
|
|
200
|
-
(0,
|
|
204
|
+
(0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
201
205
|
F: __dxlog_file,
|
|
202
206
|
L: 107,
|
|
203
207
|
S: this,
|
|
@@ -206,7 +210,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
206
210
|
""
|
|
207
211
|
]
|
|
208
212
|
});
|
|
209
|
-
(0,
|
|
213
|
+
(0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
|
|
210
214
|
F: __dxlog_file,
|
|
211
215
|
L: 108,
|
|
212
216
|
S: this,
|
|
@@ -218,15 +222,15 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
218
222
|
await replicator.disconnect();
|
|
219
223
|
this._replicators.delete(replicator);
|
|
220
224
|
}
|
|
221
|
-
async
|
|
225
|
+
async shouldAdvertise(peerId, params) {
|
|
222
226
|
const connection = this._connections.get(peerId);
|
|
223
227
|
if (!connection) {
|
|
224
228
|
return false;
|
|
225
229
|
}
|
|
226
|
-
return connection.connection.
|
|
230
|
+
return connection.connection.shouldAdvertise(params);
|
|
227
231
|
}
|
|
228
232
|
_onConnectionOpen(connection) {
|
|
229
|
-
(0,
|
|
233
|
+
(0, import_log2.log)("Connection opened", {
|
|
230
234
|
peerId: connection.peerId
|
|
231
235
|
}, {
|
|
232
236
|
F: __dxlog_file,
|
|
@@ -234,7 +238,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
234
238
|
S: this,
|
|
235
239
|
C: (f, a) => f(...a)
|
|
236
240
|
});
|
|
237
|
-
(0,
|
|
241
|
+
(0, import_invariant2.invariant)(!this._connections.has(connection.peerId), void 0, {
|
|
238
242
|
F: __dxlog_file,
|
|
239
243
|
L: 124,
|
|
240
244
|
S: this,
|
|
@@ -263,7 +267,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
263
267
|
}
|
|
264
268
|
} catch (err) {
|
|
265
269
|
if (connectionEntry.isOpen) {
|
|
266
|
-
|
|
270
|
+
import_log2.log.catch(err, void 0, {
|
|
267
271
|
F: __dxlog_file,
|
|
268
272
|
L: 143,
|
|
269
273
|
S: this,
|
|
@@ -272,7 +276,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
});
|
|
275
|
-
(0,
|
|
279
|
+
(0, import_log2.log)("emit peer-candidate", {
|
|
276
280
|
peerId: connection.peerId
|
|
277
281
|
}, {
|
|
278
282
|
F: __dxlog_file,
|
|
@@ -287,7 +291,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
287
291
|
* TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
|
|
288
292
|
*/
|
|
289
293
|
_onConnectionAuthScopeChanged(connection) {
|
|
290
|
-
(0,
|
|
294
|
+
(0, import_log2.log)("Connection auth scope changed", {
|
|
291
295
|
peerId: connection.peerId
|
|
292
296
|
}, {
|
|
293
297
|
F: __dxlog_file,
|
|
@@ -296,7 +300,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
296
300
|
C: (f, a) => f(...a)
|
|
297
301
|
});
|
|
298
302
|
const entry = this._connections.get(connection.peerId);
|
|
299
|
-
(0,
|
|
303
|
+
(0, import_invariant2.invariant)(entry, void 0, {
|
|
300
304
|
F: __dxlog_file,
|
|
301
305
|
L: 159,
|
|
302
306
|
S: this,
|
|
@@ -311,7 +315,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
311
315
|
this._emitPeerCandidate(connection);
|
|
312
316
|
}
|
|
313
317
|
_onConnectionClosed(connection) {
|
|
314
|
-
(0,
|
|
318
|
+
(0, import_log2.log)("Connection closed", {
|
|
315
319
|
peerId: connection.peerId
|
|
316
320
|
}, {
|
|
317
321
|
F: __dxlog_file,
|
|
@@ -320,7 +324,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
320
324
|
C: (f, a) => f(...a)
|
|
321
325
|
});
|
|
322
326
|
const entry = this._connections.get(connection.peerId);
|
|
323
|
-
(0,
|
|
327
|
+
(0, import_invariant2.invariant)(entry, void 0, {
|
|
324
328
|
F: __dxlog_file,
|
|
325
329
|
L: 167,
|
|
326
330
|
S: this,
|
|
@@ -333,13 +337,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
333
337
|
this.emit("peer-disconnected", {
|
|
334
338
|
peerId: connection.peerId
|
|
335
339
|
});
|
|
336
|
-
void entry.reader.cancel().catch((err) =>
|
|
340
|
+
void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
|
|
337
341
|
F: __dxlog_file,
|
|
338
342
|
L: 172,
|
|
339
343
|
S: this,
|
|
340
344
|
C: (f, a) => f(...a)
|
|
341
345
|
}));
|
|
342
|
-
void entry.writer.abort().catch((err) =>
|
|
346
|
+
void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
|
|
343
347
|
F: __dxlog_file,
|
|
344
348
|
L: 173,
|
|
345
349
|
S: this,
|
|
@@ -517,7 +521,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
517
521
|
}
|
|
518
522
|
send(message) {
|
|
519
523
|
const peer = this._peers.get(message.targetId);
|
|
520
|
-
(0,
|
|
524
|
+
(0, import_invariant3.invariant)(peer, "Peer not found.", {
|
|
521
525
|
F: __dxlog_file2,
|
|
522
526
|
L: 51,
|
|
523
527
|
S: this,
|
|
@@ -542,7 +546,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
542
546
|
syncRepo({ id, syncMessage }) {
|
|
543
547
|
const peerId = this._getPeerId(id);
|
|
544
548
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
545
|
-
(0,
|
|
549
|
+
(0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
546
550
|
F: __dxlog_file2,
|
|
547
551
|
L: 73,
|
|
548
552
|
S: this,
|
|
@@ -566,7 +570,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
566
570
|
});
|
|
567
571
|
}
|
|
568
572
|
});
|
|
569
|
-
(0,
|
|
573
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
570
574
|
F: __dxlog_file2,
|
|
571
575
|
L: 90,
|
|
572
576
|
S: this,
|
|
@@ -582,7 +586,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
582
586
|
});
|
|
583
587
|
}
|
|
584
588
|
async sendSyncMessage({ id, syncMessage }) {
|
|
585
|
-
(0,
|
|
589
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
586
590
|
F: __dxlog_file2,
|
|
587
591
|
L: 99,
|
|
588
592
|
S: this,
|
|
@@ -595,7 +599,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
595
599
|
this.emit("message", message);
|
|
596
600
|
}
|
|
597
601
|
async getHostInfo() {
|
|
598
|
-
(0,
|
|
602
|
+
(0, import_invariant3.invariant)(this._isConnected, void 0, {
|
|
599
603
|
F: __dxlog_file2,
|
|
600
604
|
L: 105,
|
|
601
605
|
S: this,
|
|
@@ -604,7 +608,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
604
608
|
""
|
|
605
609
|
]
|
|
606
610
|
});
|
|
607
|
-
(0,
|
|
611
|
+
(0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
|
|
608
612
|
F: __dxlog_file2,
|
|
609
613
|
L: 106,
|
|
610
614
|
S: this,
|
|
@@ -631,12 +635,14 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
631
635
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
632
636
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
633
637
|
}
|
|
638
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
634
639
|
var AutomergeHost = class extends import_context.Resource {
|
|
635
640
|
constructor({ db, indexMetadataStore }) {
|
|
636
641
|
super();
|
|
637
642
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
638
643
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
639
644
|
});
|
|
645
|
+
this._db = db;
|
|
640
646
|
this._storage = new LevelDBStorageAdapter({
|
|
641
647
|
db: db.sublevel("automerge"),
|
|
642
648
|
callbacks: {
|
|
@@ -681,6 +687,9 @@ var AutomergeHost = class extends import_context.Resource {
|
|
|
681
687
|
get repo() {
|
|
682
688
|
return this._repo;
|
|
683
689
|
}
|
|
690
|
+
get loadedDocsCount() {
|
|
691
|
+
return Object.keys(this._repo.handles).length;
|
|
692
|
+
}
|
|
684
693
|
async addReplicator(replicator) {
|
|
685
694
|
await this._echoNetworkAdapter.addReplicator(replicator);
|
|
686
695
|
}
|
|
@@ -720,6 +729,73 @@ var AutomergeHost = class extends import_context.Resource {
|
|
|
720
729
|
return this._repo.create(initialValue);
|
|
721
730
|
}
|
|
722
731
|
}
|
|
732
|
+
async waitUntilHeadsReplicated(heads) {
|
|
733
|
+
await Promise.all(heads.entries?.map(async ({ documentId, heads: heads2 }) => {
|
|
734
|
+
if (!heads2 || heads2.length === 0) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
const currentHeads = this.getHeads(documentId);
|
|
738
|
+
if (currentHeads !== null && (0, import_automerge.equals)(currentHeads, heads2)) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const handle = await this.loadDoc(import_context.Context.default(void 0, {
|
|
742
|
+
F: __dxlog_file3,
|
|
743
|
+
L: 207
|
|
744
|
+
}), documentId);
|
|
745
|
+
await waitForHeads(handle, heads2);
|
|
746
|
+
}) ?? []);
|
|
747
|
+
await this._repo.flush(heads.entries?.map((entry) => entry.documentId) ?? []);
|
|
748
|
+
}
|
|
749
|
+
async reIndexHeads(documentIds) {
|
|
750
|
+
for (const documentId of documentIds) {
|
|
751
|
+
import_log.log.info("re-indexing heads for document", {
|
|
752
|
+
documentId
|
|
753
|
+
}, {
|
|
754
|
+
F: __dxlog_file3,
|
|
755
|
+
L: 218,
|
|
756
|
+
S: this,
|
|
757
|
+
C: (f, a) => f(...a)
|
|
758
|
+
});
|
|
759
|
+
const handle = this._repo.find(documentId);
|
|
760
|
+
await handle.whenReady([
|
|
761
|
+
"ready",
|
|
762
|
+
"requesting"
|
|
763
|
+
]);
|
|
764
|
+
if (handle.inState([
|
|
765
|
+
"requesting"
|
|
766
|
+
])) {
|
|
767
|
+
import_log.log.warn("document is not available locally, skipping", {
|
|
768
|
+
documentId
|
|
769
|
+
}, {
|
|
770
|
+
F: __dxlog_file3,
|
|
771
|
+
L: 222,
|
|
772
|
+
S: this,
|
|
773
|
+
C: (f, a) => f(...a)
|
|
774
|
+
});
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
const doc = handle.docSync();
|
|
778
|
+
(0, import_invariant.invariant)(doc, void 0, {
|
|
779
|
+
F: __dxlog_file3,
|
|
780
|
+
L: 227,
|
|
781
|
+
S: this,
|
|
782
|
+
A: [
|
|
783
|
+
"doc",
|
|
784
|
+
""
|
|
785
|
+
]
|
|
786
|
+
});
|
|
787
|
+
const heads = (0, import_automerge.getHeads)(doc);
|
|
788
|
+
const batch = this._db.batch();
|
|
789
|
+
this._headsStore.setHeads(documentId, heads, batch);
|
|
790
|
+
await batch.write();
|
|
791
|
+
}
|
|
792
|
+
import_log.log.info("done re-indexing heads", void 0, {
|
|
793
|
+
F: __dxlog_file3,
|
|
794
|
+
L: 234,
|
|
795
|
+
S: this,
|
|
796
|
+
C: (f, a) => f(...a)
|
|
797
|
+
});
|
|
798
|
+
}
|
|
723
799
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
724
800
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
725
801
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -733,7 +809,7 @@ var AutomergeHost = class extends import_context.Resource {
|
|
|
733
809
|
}
|
|
734
810
|
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
735
811
|
if (isEchoPeerMetadata(peerMetadata)) {
|
|
736
|
-
return this._echoNetworkAdapter.
|
|
812
|
+
return this._echoNetworkAdapter.shouldAdvertise(peerId, {
|
|
737
813
|
documentId
|
|
738
814
|
});
|
|
739
815
|
}
|
|
@@ -880,18 +956,15 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
880
956
|
return String(rawSpaceKey);
|
|
881
957
|
};
|
|
882
958
|
var waitForHeads = async (handle, heads) => {
|
|
883
|
-
await handle.whenReady();
|
|
884
959
|
const unavailableHeads = new Set(heads);
|
|
960
|
+
await handle.whenReady();
|
|
885
961
|
await import_async.Event.wrap(handle, "change").waitForCondition(() => {
|
|
886
962
|
for (const changeHash of unavailableHeads.values()) {
|
|
887
963
|
if (changeIsPresentInDoc(handle.docSync(), changeHash)) {
|
|
888
964
|
unavailableHeads.delete(changeHash);
|
|
889
965
|
}
|
|
890
966
|
}
|
|
891
|
-
|
|
892
|
-
return true;
|
|
893
|
-
}
|
|
894
|
-
return false;
|
|
967
|
+
return unavailableHeads.size === 0;
|
|
895
968
|
});
|
|
896
969
|
};
|
|
897
970
|
var changeIsPresentInDoc = (doc, changeHash) => {
|
|
@@ -907,7 +980,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
907
980
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
908
981
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
909
982
|
}
|
|
910
|
-
var
|
|
983
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
911
984
|
var AutomergeDocumentLoaderImpl = class {
|
|
912
985
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
913
986
|
this._spaceId = _spaceId;
|
|
@@ -933,8 +1006,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
933
1006
|
}
|
|
934
1007
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
935
1008
|
const doc = existingDocHandle.docSync();
|
|
936
|
-
(0,
|
|
937
|
-
F:
|
|
1009
|
+
(0, import_invariant4.invariant)(doc, void 0, {
|
|
1010
|
+
F: __dxlog_file4,
|
|
938
1011
|
L: 84,
|
|
939
1012
|
S: this,
|
|
940
1013
|
A: [
|
|
@@ -942,8 +1015,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
942
1015
|
""
|
|
943
1016
|
]
|
|
944
1017
|
});
|
|
945
|
-
(0,
|
|
946
|
-
F:
|
|
1018
|
+
(0, import_invariant4.invariant)(doc.version === import_echo_protocol.SpaceDocVersion.CURRENT, void 0, {
|
|
1019
|
+
F: __dxlog_file4,
|
|
947
1020
|
L: 85,
|
|
948
1021
|
S: this,
|
|
949
1022
|
A: [
|
|
@@ -963,8 +1036,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
963
1036
|
let hasUrlsToLoad = false;
|
|
964
1037
|
const urlsToLoad = {};
|
|
965
1038
|
for (const objectId of objectIds) {
|
|
966
|
-
(0,
|
|
967
|
-
F:
|
|
1039
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1040
|
+
F: __dxlog_file4,
|
|
968
1041
|
L: 97,
|
|
969
1042
|
S: this,
|
|
970
1043
|
A: [
|
|
@@ -976,8 +1049,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
976
1049
|
continue;
|
|
977
1050
|
}
|
|
978
1051
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
979
|
-
(0,
|
|
980
|
-
F:
|
|
1052
|
+
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
1053
|
+
F: __dxlog_file4,
|
|
981
1054
|
L: 102,
|
|
982
1055
|
S: this,
|
|
983
1056
|
A: [
|
|
@@ -988,10 +1061,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
988
1061
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
989
1062
|
if (documentUrl == null) {
|
|
990
1063
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
991
|
-
|
|
1064
|
+
import_log3.log.info("loading delayed until object links are initialized", {
|
|
992
1065
|
objectId
|
|
993
1066
|
}, {
|
|
994
|
-
F:
|
|
1067
|
+
F: __dxlog_file4,
|
|
995
1068
|
L: 106,
|
|
996
1069
|
S: this,
|
|
997
1070
|
C: (f, a) => f(...a)
|
|
@@ -1006,8 +1079,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1006
1079
|
}
|
|
1007
1080
|
}
|
|
1008
1081
|
getObjectDocumentId(objectId) {
|
|
1009
|
-
(0,
|
|
1010
|
-
F:
|
|
1082
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1083
|
+
F: __dxlog_file4,
|
|
1011
1084
|
L: 118,
|
|
1012
1085
|
S: this,
|
|
1013
1086
|
A: [
|
|
@@ -1016,8 +1089,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1016
1089
|
]
|
|
1017
1090
|
});
|
|
1018
1091
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1019
|
-
(0,
|
|
1020
|
-
F:
|
|
1092
|
+
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
1093
|
+
F: __dxlog_file4,
|
|
1021
1094
|
L: 120,
|
|
1022
1095
|
S: this,
|
|
1023
1096
|
A: [
|
|
@@ -1040,8 +1113,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1040
1113
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
1041
1114
|
}
|
|
1042
1115
|
getSpaceRootDocHandle() {
|
|
1043
|
-
(0,
|
|
1044
|
-
F:
|
|
1116
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1117
|
+
F: __dxlog_file4,
|
|
1045
1118
|
L: 140,
|
|
1046
1119
|
S: this,
|
|
1047
1120
|
A: [
|
|
@@ -1052,8 +1125,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1052
1125
|
return this._spaceRootDocHandle;
|
|
1053
1126
|
}
|
|
1054
1127
|
createDocumentForObject(objectId) {
|
|
1055
|
-
(0,
|
|
1056
|
-
F:
|
|
1128
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1129
|
+
F: __dxlog_file4,
|
|
1057
1130
|
L: 145,
|
|
1058
1131
|
S: this,
|
|
1059
1132
|
A: [
|
|
@@ -1094,11 +1167,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1094
1167
|
};
|
|
1095
1168
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1096
1169
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1097
|
-
|
|
1170
|
+
import_log3.log.warn("object already inlined in a different document, ignoring the link", {
|
|
1098
1171
|
...logMeta,
|
|
1099
1172
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1100
1173
|
}, {
|
|
1101
|
-
F:
|
|
1174
|
+
F: __dxlog_file4,
|
|
1102
1175
|
L: 177,
|
|
1103
1176
|
S: this,
|
|
1104
1177
|
C: (f, a) => f(...a)
|
|
@@ -1106,8 +1179,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1106
1179
|
continue;
|
|
1107
1180
|
}
|
|
1108
1181
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1109
|
-
|
|
1110
|
-
F:
|
|
1182
|
+
import_log3.log.warn("object document was already loaded", logMeta, {
|
|
1183
|
+
F: __dxlog_file4,
|
|
1111
1184
|
L: 184,
|
|
1112
1185
|
S: this,
|
|
1113
1186
|
C: (f, a) => f(...a)
|
|
@@ -1115,8 +1188,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1115
1188
|
continue;
|
|
1116
1189
|
}
|
|
1117
1190
|
const handle = this._repo.find(automergeUrl);
|
|
1118
|
-
|
|
1119
|
-
F:
|
|
1191
|
+
import_log3.log.debug("document loading triggered", logMeta, {
|
|
1192
|
+
F: __dxlog_file4,
|
|
1120
1193
|
L: 188,
|
|
1121
1194
|
S: this,
|
|
1122
1195
|
C: (f, a) => f(...a)
|
|
@@ -1135,11 +1208,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1135
1208
|
break;
|
|
1136
1209
|
} catch (err) {
|
|
1137
1210
|
if (`${err}`.includes("Timeout")) {
|
|
1138
|
-
|
|
1211
|
+
import_log3.log.info("wraparound", {
|
|
1139
1212
|
id: docHandle.documentId,
|
|
1140
1213
|
state: docHandle.state
|
|
1141
1214
|
}, {
|
|
1142
|
-
F:
|
|
1215
|
+
F: __dxlog_file4,
|
|
1143
1216
|
L: 204,
|
|
1144
1217
|
S: this,
|
|
1145
1218
|
C: (f, a) => f(...a)
|
|
@@ -1170,8 +1243,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1170
1243
|
docUrl: handle.url
|
|
1171
1244
|
};
|
|
1172
1245
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1173
|
-
|
|
1174
|
-
F:
|
|
1246
|
+
import_log3.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1247
|
+
F: __dxlog_file4,
|
|
1175
1248
|
L: 231,
|
|
1176
1249
|
S: this,
|
|
1177
1250
|
C: (f, a) => f(...a)
|
|
@@ -1180,8 +1253,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1180
1253
|
}
|
|
1181
1254
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1182
1255
|
if (objectDocHandle?.url !== handle.url) {
|
|
1183
|
-
|
|
1184
|
-
F:
|
|
1256
|
+
import_log3.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1257
|
+
F: __dxlog_file4,
|
|
1185
1258
|
L: 236,
|
|
1186
1259
|
S: this,
|
|
1187
1260
|
C: (f, a) => f(...a)
|
|
@@ -1194,13 +1267,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1194
1267
|
});
|
|
1195
1268
|
} catch (err) {
|
|
1196
1269
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1197
|
-
|
|
1270
|
+
import_log3.log.warn("failed to load a document", {
|
|
1198
1271
|
objectId,
|
|
1199
1272
|
automergeUrl: handle.url,
|
|
1200
1273
|
retryLoading: shouldRetryLoading,
|
|
1201
1274
|
err
|
|
1202
1275
|
}, {
|
|
1203
|
-
F:
|
|
1276
|
+
F: __dxlog_file4,
|
|
1204
1277
|
L: 242,
|
|
1205
1278
|
S: this,
|
|
1206
1279
|
C: (f, a) => f(...a)
|
|
@@ -1219,7 +1292,121 @@ _ts_decorate3([
|
|
|
1219
1292
|
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1220
1293
|
import_tracing2.trace.resource()
|
|
1221
1294
|
], AutomergeDocumentLoaderImpl);
|
|
1222
|
-
var
|
|
1295
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator-connection.ts";
|
|
1296
|
+
var DEFAULT_FACTORY = (params) => new import_teleport_extension_automerge_replicator.AutomergeReplicator(...params);
|
|
1297
|
+
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
1298
|
+
constructor(_params) {
|
|
1299
|
+
super();
|
|
1300
|
+
this._params = _params;
|
|
1301
|
+
this.remoteDeviceKey = null;
|
|
1302
|
+
this._remotePeerId = null;
|
|
1303
|
+
this._isEnabled = false;
|
|
1304
|
+
let readableStreamController;
|
|
1305
|
+
this.readable = new ReadableStream({
|
|
1306
|
+
start: (controller) => {
|
|
1307
|
+
readableStreamController = controller;
|
|
1308
|
+
this._ctx.onDispose(() => controller.close());
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
this.writable = new WritableStream({
|
|
1312
|
+
write: async (message, controller) => {
|
|
1313
|
+
(0, import_invariant6.invariant)(this._isEnabled, "Writing to a disabled connection", {
|
|
1314
|
+
F: __dxlog_file5,
|
|
1315
|
+
L: 47,
|
|
1316
|
+
S: this,
|
|
1317
|
+
A: [
|
|
1318
|
+
"this._isEnabled",
|
|
1319
|
+
"'Writing to a disabled connection'"
|
|
1320
|
+
]
|
|
1321
|
+
});
|
|
1322
|
+
try {
|
|
1323
|
+
await this.replicatorExtension.sendSyncMessage({
|
|
1324
|
+
payload: import_automerge_repo5.cbor.encode(message)
|
|
1325
|
+
});
|
|
1326
|
+
} catch (err) {
|
|
1327
|
+
controller.error(err);
|
|
1328
|
+
this._disconnectIfEnabled();
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
const createAutomergeReplicator = this._params.replicatorFactory ?? DEFAULT_FACTORY;
|
|
1333
|
+
this.replicatorExtension = createAutomergeReplicator([
|
|
1334
|
+
{
|
|
1335
|
+
peerId: this._params.ownPeerId
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
onStartReplication: async (info, remotePeerId) => {
|
|
1339
|
+
this.remoteDeviceKey = remotePeerId;
|
|
1340
|
+
this._remotePeerId = info.id;
|
|
1341
|
+
(0, import_log5.log)("onStartReplication", {
|
|
1342
|
+
id: info.id,
|
|
1343
|
+
thisPeerId: this.peerId,
|
|
1344
|
+
remotePeerId: remotePeerId.toHex()
|
|
1345
|
+
}, {
|
|
1346
|
+
F: __dxlog_file5,
|
|
1347
|
+
L: 81,
|
|
1348
|
+
S: this,
|
|
1349
|
+
C: (f, a) => f(...a)
|
|
1350
|
+
});
|
|
1351
|
+
this._params.onRemoteConnected();
|
|
1352
|
+
},
|
|
1353
|
+
onSyncMessage: async ({ payload }) => {
|
|
1354
|
+
if (!this._isEnabled) {
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1358
|
+
readableStreamController.enqueue(message);
|
|
1359
|
+
},
|
|
1360
|
+
onClose: async () => {
|
|
1361
|
+
this._disconnectIfEnabled();
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
]);
|
|
1365
|
+
}
|
|
1366
|
+
_disconnectIfEnabled() {
|
|
1367
|
+
if (this._isEnabled) {
|
|
1368
|
+
this._params.onRemoteDisconnected();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
get peerId() {
|
|
1372
|
+
(0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1373
|
+
F: __dxlog_file5,
|
|
1374
|
+
L: 107,
|
|
1375
|
+
S: this,
|
|
1376
|
+
A: [
|
|
1377
|
+
"this._remotePeerId != null",
|
|
1378
|
+
"'Remote peer has not connected yet.'"
|
|
1379
|
+
]
|
|
1380
|
+
});
|
|
1381
|
+
return this._remotePeerId;
|
|
1382
|
+
}
|
|
1383
|
+
async shouldAdvertise(params) {
|
|
1384
|
+
return this._params.shouldAdvertise(params);
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Start exchanging messages with the remote peer.
|
|
1388
|
+
* Call after the remote peer has connected.
|
|
1389
|
+
*/
|
|
1390
|
+
enable() {
|
|
1391
|
+
(0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1392
|
+
F: __dxlog_file5,
|
|
1393
|
+
L: 120,
|
|
1394
|
+
S: this,
|
|
1395
|
+
A: [
|
|
1396
|
+
"this._remotePeerId != null",
|
|
1397
|
+
"'Remote peer has not connected yet.'"
|
|
1398
|
+
]
|
|
1399
|
+
});
|
|
1400
|
+
this._isEnabled = true;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Stop exchanging messages with the remote peer.
|
|
1404
|
+
*/
|
|
1405
|
+
disable() {
|
|
1406
|
+
this._isEnabled = false;
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1223
1410
|
var MeshEchoReplicator = class {
|
|
1224
1411
|
constructor() {
|
|
1225
1412
|
this._connections = /* @__PURE__ */ new Set();
|
|
@@ -1238,10 +1425,10 @@ var MeshEchoReplicator = class {
|
|
|
1238
1425
|
this._connectionsPerPeer.clear();
|
|
1239
1426
|
this._context = null;
|
|
1240
1427
|
}
|
|
1241
|
-
createExtension() {
|
|
1242
|
-
(0,
|
|
1243
|
-
F:
|
|
1244
|
-
L:
|
|
1428
|
+
createExtension(extensionFactory) {
|
|
1429
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1430
|
+
F: __dxlog_file6,
|
|
1431
|
+
L: 51,
|
|
1245
1432
|
S: this,
|
|
1246
1433
|
A: [
|
|
1247
1434
|
"this._context",
|
|
@@ -1250,18 +1437,19 @@ var MeshEchoReplicator = class {
|
|
|
1250
1437
|
});
|
|
1251
1438
|
const connection = new MeshReplicatorConnection({
|
|
1252
1439
|
ownPeerId: this._context.peerId,
|
|
1440
|
+
replicatorFactory: extensionFactory,
|
|
1253
1441
|
onRemoteConnected: async () => {
|
|
1254
|
-
(0,
|
|
1442
|
+
(0, import_log4.log)("onRemoteConnected", {
|
|
1255
1443
|
peerId: connection.peerId
|
|
1256
1444
|
}, {
|
|
1257
|
-
F:
|
|
1258
|
-
L:
|
|
1445
|
+
F: __dxlog_file6,
|
|
1446
|
+
L: 57,
|
|
1259
1447
|
S: this,
|
|
1260
1448
|
C: (f, a) => f(...a)
|
|
1261
1449
|
});
|
|
1262
|
-
(0,
|
|
1263
|
-
F:
|
|
1264
|
-
L:
|
|
1450
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1451
|
+
F: __dxlog_file6,
|
|
1452
|
+
L: 58,
|
|
1265
1453
|
S: this,
|
|
1266
1454
|
A: [
|
|
1267
1455
|
"this._context",
|
|
@@ -1273,36 +1461,36 @@ var MeshEchoReplicator = class {
|
|
|
1273
1461
|
} else {
|
|
1274
1462
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1275
1463
|
this._context.onConnectionOpen(connection);
|
|
1276
|
-
|
|
1464
|
+
connection.enable();
|
|
1277
1465
|
}
|
|
1278
1466
|
},
|
|
1279
1467
|
onRemoteDisconnected: async () => {
|
|
1280
|
-
(0,
|
|
1468
|
+
(0, import_log4.log)("onRemoteDisconnected", {
|
|
1281
1469
|
peerId: connection.peerId
|
|
1282
1470
|
}, {
|
|
1283
|
-
F:
|
|
1284
|
-
L:
|
|
1471
|
+
F: __dxlog_file6,
|
|
1472
|
+
L: 69,
|
|
1285
1473
|
S: this,
|
|
1286
1474
|
C: (f, a) => f(...a)
|
|
1287
1475
|
});
|
|
1288
1476
|
this._context?.onConnectionClosed(connection);
|
|
1289
1477
|
this._connectionsPerPeer.delete(connection.peerId);
|
|
1290
|
-
|
|
1478
|
+
connection.disable();
|
|
1291
1479
|
this._connections.delete(connection);
|
|
1292
1480
|
},
|
|
1293
|
-
|
|
1294
|
-
(0,
|
|
1481
|
+
shouldAdvertise: async (params) => {
|
|
1482
|
+
(0, import_log4.log)("shouldAdvertise", {
|
|
1295
1483
|
peerId: connection.peerId,
|
|
1296
1484
|
documentId: params.documentId
|
|
1297
1485
|
}, {
|
|
1298
|
-
F:
|
|
1299
|
-
L:
|
|
1486
|
+
F: __dxlog_file6,
|
|
1487
|
+
L: 76,
|
|
1300
1488
|
S: this,
|
|
1301
1489
|
C: (f, a) => f(...a)
|
|
1302
1490
|
});
|
|
1303
|
-
(0,
|
|
1304
|
-
F:
|
|
1305
|
-
L:
|
|
1491
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1492
|
+
F: __dxlog_file6,
|
|
1493
|
+
L: 77,
|
|
1306
1494
|
S: this,
|
|
1307
1495
|
A: [
|
|
1308
1496
|
"this._context",
|
|
@@ -1312,12 +1500,12 @@ var MeshEchoReplicator = class {
|
|
|
1312
1500
|
try {
|
|
1313
1501
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1314
1502
|
if (!spaceKey) {
|
|
1315
|
-
(0,
|
|
1503
|
+
(0, import_log4.log)("space key not found for share policy check", {
|
|
1316
1504
|
peerId: connection.peerId,
|
|
1317
1505
|
documentId: params.documentId
|
|
1318
1506
|
}, {
|
|
1319
|
-
F:
|
|
1320
|
-
L:
|
|
1507
|
+
F: __dxlog_file6,
|
|
1508
|
+
L: 81,
|
|
1321
1509
|
S: this,
|
|
1322
1510
|
C: (f, a) => f(...a)
|
|
1323
1511
|
});
|
|
@@ -1325,19 +1513,19 @@ var MeshEchoReplicator = class {
|
|
|
1325
1513
|
}
|
|
1326
1514
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1327
1515
|
if (!connection.remoteDeviceKey) {
|
|
1328
|
-
(0,
|
|
1516
|
+
(0, import_log4.log)("device key not found for share policy check", {
|
|
1329
1517
|
peerId: connection.peerId,
|
|
1330
1518
|
documentId: params.documentId
|
|
1331
1519
|
}, {
|
|
1332
|
-
F:
|
|
1333
|
-
L:
|
|
1520
|
+
F: __dxlog_file6,
|
|
1521
|
+
L: 91,
|
|
1334
1522
|
S: this,
|
|
1335
1523
|
C: (f, a) => f(...a)
|
|
1336
1524
|
});
|
|
1337
1525
|
return false;
|
|
1338
1526
|
}
|
|
1339
1527
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1340
|
-
(0,
|
|
1528
|
+
(0, import_log4.log)("share policy check", {
|
|
1341
1529
|
localPeer: this._context.peerId,
|
|
1342
1530
|
remotePeer: connection.peerId,
|
|
1343
1531
|
documentId: params.documentId,
|
|
@@ -1345,16 +1533,16 @@ var MeshEchoReplicator = class {
|
|
|
1345
1533
|
spaceKey,
|
|
1346
1534
|
isAuthorized
|
|
1347
1535
|
}, {
|
|
1348
|
-
F:
|
|
1349
|
-
L:
|
|
1536
|
+
F: __dxlog_file6,
|
|
1537
|
+
L: 99,
|
|
1350
1538
|
S: this,
|
|
1351
1539
|
C: (f, a) => f(...a)
|
|
1352
1540
|
});
|
|
1353
1541
|
return isAuthorized;
|
|
1354
1542
|
} catch (err) {
|
|
1355
|
-
|
|
1356
|
-
F:
|
|
1357
|
-
L:
|
|
1543
|
+
import_log4.log.catch(err, void 0, {
|
|
1544
|
+
F: __dxlog_file6,
|
|
1545
|
+
L: 109,
|
|
1358
1546
|
S: this,
|
|
1359
1547
|
C: (f, a) => f(...a)
|
|
1360
1548
|
});
|
|
@@ -1366,115 +1554,23 @@ var MeshEchoReplicator = class {
|
|
|
1366
1554
|
return connection.replicatorExtension;
|
|
1367
1555
|
}
|
|
1368
1556
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1369
|
-
(0,
|
|
1557
|
+
(0, import_log4.log)("authorizeDevice", {
|
|
1370
1558
|
spaceKey,
|
|
1371
1559
|
deviceKey
|
|
1372
1560
|
}, {
|
|
1373
|
-
F:
|
|
1374
|
-
L:
|
|
1561
|
+
F: __dxlog_file6,
|
|
1562
|
+
L: 120,
|
|
1375
1563
|
S: this,
|
|
1376
1564
|
C: (f, a) => f(...a)
|
|
1377
1565
|
});
|
|
1378
1566
|
(0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
|
|
1379
1567
|
for (const connection of this._connections) {
|
|
1380
1568
|
if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
|
|
1381
|
-
this.
|
|
1382
|
-
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
};
|
|
1386
|
-
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
1387
|
-
constructor(_params) {
|
|
1388
|
-
super();
|
|
1389
|
-
this._params = _params;
|
|
1390
|
-
this.remoteDeviceKey = null;
|
|
1391
|
-
this._remotePeerId = null;
|
|
1392
|
-
this._isEnabled = false;
|
|
1393
|
-
let readableStreamController;
|
|
1394
|
-
this.readable = new ReadableStream({
|
|
1395
|
-
start: (controller) => {
|
|
1396
|
-
readableStreamController = controller;
|
|
1397
|
-
this._ctx.onDispose(() => controller.close());
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
this.writable = new WritableStream({
|
|
1401
|
-
write: async (message, controller) => {
|
|
1402
|
-
this.replicatorExtension.sendSyncMessage({
|
|
1403
|
-
payload: import_automerge_repo5.cbor.encode(message)
|
|
1404
|
-
}).catch((err) => {
|
|
1405
|
-
controller.error(err);
|
|
1406
|
-
});
|
|
1407
|
-
}
|
|
1408
|
-
});
|
|
1409
|
-
this.replicatorExtension = new import_teleport_extension_automerge_replicator.AutomergeReplicator({
|
|
1410
|
-
peerId: this._params.ownPeerId
|
|
1411
|
-
}, {
|
|
1412
|
-
onStartReplication: async (info, remotePeerId) => {
|
|
1413
|
-
this.remoteDeviceKey = remotePeerId;
|
|
1414
|
-
this._remotePeerId = info.id;
|
|
1415
|
-
(0, import_log3.log)("onStartReplication", {
|
|
1416
|
-
id: info.id,
|
|
1417
|
-
thisPeerId: this.peerId,
|
|
1418
|
-
remotePeerId: remotePeerId.toHex()
|
|
1419
|
-
}, {
|
|
1420
|
-
F: __dxlog_file4,
|
|
1421
|
-
L: 192,
|
|
1422
|
-
S: this,
|
|
1423
|
-
C: (f, a) => f(...a)
|
|
1424
|
-
});
|
|
1425
|
-
await this._params.onRemoteConnected();
|
|
1426
|
-
},
|
|
1427
|
-
onSyncMessage: async ({ payload }) => {
|
|
1428
|
-
if (!this._isEnabled) {
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1432
|
-
readableStreamController.enqueue(message);
|
|
1433
|
-
},
|
|
1434
|
-
onClose: async () => {
|
|
1435
|
-
if (!this._isEnabled) {
|
|
1436
|
-
return;
|
|
1569
|
+
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1570
|
+
this._context?.onConnectionAuthScopeChanged(connection);
|
|
1437
1571
|
}
|
|
1438
|
-
await this._params.onRemoteDisconnected();
|
|
1439
1572
|
}
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
get peerId() {
|
|
1443
|
-
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1444
|
-
F: __dxlog_file4,
|
|
1445
|
-
L: 215,
|
|
1446
|
-
S: this,
|
|
1447
|
-
A: [
|
|
1448
|
-
"this._remotePeerId != null",
|
|
1449
|
-
"'Remote peer has not connected yet.'"
|
|
1450
|
-
]
|
|
1451
|
-
});
|
|
1452
|
-
return this._remotePeerId;
|
|
1453
|
-
}
|
|
1454
|
-
async shouldAdvertize(params) {
|
|
1455
|
-
return this._params.shouldAdvertize(params);
|
|
1456
|
-
}
|
|
1457
|
-
/**
|
|
1458
|
-
* Start exchanging messages with the remote peer.
|
|
1459
|
-
* Call after the remote peer has connected.
|
|
1460
|
-
*/
|
|
1461
|
-
async enable() {
|
|
1462
|
-
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1463
|
-
F: __dxlog_file4,
|
|
1464
|
-
L: 228,
|
|
1465
|
-
S: this,
|
|
1466
|
-
A: [
|
|
1467
|
-
"this._remotePeerId != null",
|
|
1468
|
-
"'Remote peer has not connected yet.'"
|
|
1469
|
-
]
|
|
1470
|
-
});
|
|
1471
|
-
this._isEnabled = true;
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Stop exchanging messages with the remote peer.
|
|
1475
|
-
*/
|
|
1476
|
-
async disable() {
|
|
1477
|
-
this._isEnabled = false;
|
|
1573
|
+
}
|
|
1478
1574
|
}
|
|
1479
1575
|
};
|
|
1480
1576
|
// Annotate the CommonJS export names for ESM import in node:
|