@dxos/echo-pipeline 0.6.1-main.c633aeb → 0.6.1-main.d9fdca4
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-HS77A4I4.mjs → chunk-A2LCXJVD.mjs} +16 -1
- package/dist/lib/browser/chunk-A2LCXJVD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +264 -180
- 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-Y5U7UXEL.cjs → chunk-GHBIMYZK.cjs} +19 -4
- package/dist/lib/node/chunk-GHBIMYZK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +309 -229
- 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 +3 -0
- 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 +4 -2
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-doc-loader.ts +1 -1
- package/src/automerge/automerge-host.ts +31 -5
- package/src/automerge/automerge-repo.test.ts +76 -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 +22 -2
- package/dist/lib/browser/chunk-HS77A4I4.mjs.map +0 -7
- package/dist/lib/node/chunk-Y5U7UXEL.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_GHBIMYZK.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_GHBIMYZK.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
|
-
CredentialRetrieverExtension: () =>
|
|
26
|
-
CredentialServerExtension: () =>
|
|
27
|
-
DataServiceImpl: () =>
|
|
25
|
+
CredentialRetrieverExtension: () => import_chunk_GHBIMYZK.CredentialRetrieverExtension,
|
|
26
|
+
CredentialServerExtension: () => import_chunk_GHBIMYZK.CredentialServerExtension,
|
|
27
|
+
DataServiceImpl: () => import_chunk_GHBIMYZK.DataServiceImpl,
|
|
28
28
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
29
29
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
30
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
31
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
30
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_GHBIMYZK.MOCK_AUTH_PROVIDER,
|
|
31
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_GHBIMYZK.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_GHBIMYZK.MetadataStore,
|
|
34
|
+
Pipeline: () => import_chunk_GHBIMYZK.Pipeline,
|
|
35
|
+
SnapshotManager: () => import_chunk_GHBIMYZK.SnapshotManager,
|
|
36
|
+
SnapshotStore: () => import_chunk_GHBIMYZK.SnapshotStore,
|
|
37
|
+
Space: () => import_chunk_GHBIMYZK.Space,
|
|
38
|
+
SpaceManager: () => import_chunk_GHBIMYZK.SpaceManager,
|
|
39
|
+
SpaceProtocol: () => import_chunk_GHBIMYZK.SpaceProtocol,
|
|
40
|
+
SpaceProtocolSession: () => import_chunk_GHBIMYZK.SpaceProtocolSession,
|
|
41
|
+
TimeframeClock: () => import_chunk_GHBIMYZK.TimeframeClock,
|
|
42
|
+
codec: () => import_chunk_GHBIMYZK.codec,
|
|
43
|
+
createIdFromSpaceKey: () => import_chunk_GHBIMYZK.createIdFromSpaceKey,
|
|
44
|
+
createMappedFeedWriter: () => import_chunk_GHBIMYZK.createMappedFeedWriter,
|
|
45
45
|
encodingOptions: () => encodingOptions,
|
|
46
46
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
47
|
-
hasInvitationExpired: () =>
|
|
48
|
-
mapFeedIndexesToTimeframe: () =>
|
|
49
|
-
mapTimeframeToFeedIndexes: () =>
|
|
50
|
-
startAfter: () =>
|
|
51
|
-
valueEncoding: () =>
|
|
47
|
+
hasInvitationExpired: () => import_chunk_GHBIMYZK.hasInvitationExpired,
|
|
48
|
+
mapFeedIndexesToTimeframe: () => import_chunk_GHBIMYZK.mapFeedIndexesToTimeframe,
|
|
49
|
+
mapTimeframeToFeedIndexes: () => import_chunk_GHBIMYZK.mapTimeframeToFeedIndexes,
|
|
50
|
+
startAfter: () => import_chunk_GHBIMYZK.startAfter,
|
|
51
|
+
valueEncoding: () => import_chunk_GHBIMYZK.valueEncoding
|
|
52
52
|
});
|
|
53
53
|
module.exports = __toCommonJS(node_exports);
|
|
54
|
-
var
|
|
54
|
+
var import_chunk_GHBIMYZK = require("./chunk-GHBIMYZK.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,56 @@ var AutomergeHost = class extends import_context.Resource {
|
|
|
720
729
|
return this._repo.create(initialValue);
|
|
721
730
|
}
|
|
722
731
|
}
|
|
732
|
+
async reIndexHeads(documentIds) {
|
|
733
|
+
for (const documentId of documentIds) {
|
|
734
|
+
import_log.log.info("reindexing heads for document", {
|
|
735
|
+
documentId
|
|
736
|
+
}, {
|
|
737
|
+
F: __dxlog_file3,
|
|
738
|
+
L: 195,
|
|
739
|
+
S: this,
|
|
740
|
+
C: (f, a) => f(...a)
|
|
741
|
+
});
|
|
742
|
+
const handle = this._repo.find(documentId);
|
|
743
|
+
await handle.whenReady([
|
|
744
|
+
"ready",
|
|
745
|
+
"requesting"
|
|
746
|
+
]);
|
|
747
|
+
if (handle.inState([
|
|
748
|
+
"requesting"
|
|
749
|
+
])) {
|
|
750
|
+
import_log.log.warn("document is not available locally, skipping", {
|
|
751
|
+
documentId
|
|
752
|
+
}, {
|
|
753
|
+
F: __dxlog_file3,
|
|
754
|
+
L: 199,
|
|
755
|
+
S: this,
|
|
756
|
+
C: (f, a) => f(...a)
|
|
757
|
+
});
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
const doc = handle.docSync();
|
|
761
|
+
(0, import_invariant.invariant)(doc, void 0, {
|
|
762
|
+
F: __dxlog_file3,
|
|
763
|
+
L: 204,
|
|
764
|
+
S: this,
|
|
765
|
+
A: [
|
|
766
|
+
"doc",
|
|
767
|
+
""
|
|
768
|
+
]
|
|
769
|
+
});
|
|
770
|
+
const heads = (0, import_automerge.getHeads)(doc);
|
|
771
|
+
const batch = this._db.batch();
|
|
772
|
+
this._headsStore.setHeads(documentId, heads, batch);
|
|
773
|
+
await batch.write();
|
|
774
|
+
}
|
|
775
|
+
import_log.log.info("done reindexing heads", void 0, {
|
|
776
|
+
F: __dxlog_file3,
|
|
777
|
+
L: 211,
|
|
778
|
+
S: this,
|
|
779
|
+
C: (f, a) => f(...a)
|
|
780
|
+
});
|
|
781
|
+
}
|
|
723
782
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
724
783
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
725
784
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -733,7 +792,7 @@ var AutomergeHost = class extends import_context.Resource {
|
|
|
733
792
|
}
|
|
734
793
|
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
735
794
|
if (isEchoPeerMetadata(peerMetadata)) {
|
|
736
|
-
return this._echoNetworkAdapter.
|
|
795
|
+
return this._echoNetworkAdapter.shouldAdvertise(peerId, {
|
|
737
796
|
documentId
|
|
738
797
|
});
|
|
739
798
|
}
|
|
@@ -907,7 +966,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
907
966
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
908
967
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
909
968
|
}
|
|
910
|
-
var
|
|
969
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
911
970
|
var AutomergeDocumentLoaderImpl = class {
|
|
912
971
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
913
972
|
this._spaceId = _spaceId;
|
|
@@ -933,8 +992,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
933
992
|
}
|
|
934
993
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
935
994
|
const doc = existingDocHandle.docSync();
|
|
936
|
-
(0,
|
|
937
|
-
F:
|
|
995
|
+
(0, import_invariant4.invariant)(doc, void 0, {
|
|
996
|
+
F: __dxlog_file4,
|
|
938
997
|
L: 84,
|
|
939
998
|
S: this,
|
|
940
999
|
A: [
|
|
@@ -942,8 +1001,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
942
1001
|
""
|
|
943
1002
|
]
|
|
944
1003
|
});
|
|
945
|
-
(0,
|
|
946
|
-
F:
|
|
1004
|
+
(0, import_invariant4.invariant)(doc.version === import_echo_protocol.SpaceDocVersion.CURRENT, void 0, {
|
|
1005
|
+
F: __dxlog_file4,
|
|
947
1006
|
L: 85,
|
|
948
1007
|
S: this,
|
|
949
1008
|
A: [
|
|
@@ -963,8 +1022,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
963
1022
|
let hasUrlsToLoad = false;
|
|
964
1023
|
const urlsToLoad = {};
|
|
965
1024
|
for (const objectId of objectIds) {
|
|
966
|
-
(0,
|
|
967
|
-
F:
|
|
1025
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1026
|
+
F: __dxlog_file4,
|
|
968
1027
|
L: 97,
|
|
969
1028
|
S: this,
|
|
970
1029
|
A: [
|
|
@@ -976,8 +1035,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
976
1035
|
continue;
|
|
977
1036
|
}
|
|
978
1037
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
979
|
-
(0,
|
|
980
|
-
F:
|
|
1038
|
+
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
1039
|
+
F: __dxlog_file4,
|
|
981
1040
|
L: 102,
|
|
982
1041
|
S: this,
|
|
983
1042
|
A: [
|
|
@@ -988,10 +1047,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
988
1047
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
989
1048
|
if (documentUrl == null) {
|
|
990
1049
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
991
|
-
|
|
1050
|
+
import_log3.log.info("loading delayed until object links are initialized", {
|
|
992
1051
|
objectId
|
|
993
1052
|
}, {
|
|
994
|
-
F:
|
|
1053
|
+
F: __dxlog_file4,
|
|
995
1054
|
L: 106,
|
|
996
1055
|
S: this,
|
|
997
1056
|
C: (f, a) => f(...a)
|
|
@@ -1006,8 +1065,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1006
1065
|
}
|
|
1007
1066
|
}
|
|
1008
1067
|
getObjectDocumentId(objectId) {
|
|
1009
|
-
(0,
|
|
1010
|
-
F:
|
|
1068
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1069
|
+
F: __dxlog_file4,
|
|
1011
1070
|
L: 118,
|
|
1012
1071
|
S: this,
|
|
1013
1072
|
A: [
|
|
@@ -1016,8 +1075,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1016
1075
|
]
|
|
1017
1076
|
});
|
|
1018
1077
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1019
|
-
(0,
|
|
1020
|
-
F:
|
|
1078
|
+
(0, import_invariant4.invariant)(spaceRootDoc, void 0, {
|
|
1079
|
+
F: __dxlog_file4,
|
|
1021
1080
|
L: 120,
|
|
1022
1081
|
S: this,
|
|
1023
1082
|
A: [
|
|
@@ -1040,8 +1099,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1040
1099
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
1041
1100
|
}
|
|
1042
1101
|
getSpaceRootDocHandle() {
|
|
1043
|
-
(0,
|
|
1044
|
-
F:
|
|
1102
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1103
|
+
F: __dxlog_file4,
|
|
1045
1104
|
L: 140,
|
|
1046
1105
|
S: this,
|
|
1047
1106
|
A: [
|
|
@@ -1052,8 +1111,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1052
1111
|
return this._spaceRootDocHandle;
|
|
1053
1112
|
}
|
|
1054
1113
|
createDocumentForObject(objectId) {
|
|
1055
|
-
(0,
|
|
1056
|
-
F:
|
|
1114
|
+
(0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1115
|
+
F: __dxlog_file4,
|
|
1057
1116
|
L: 145,
|
|
1058
1117
|
S: this,
|
|
1059
1118
|
A: [
|
|
@@ -1094,11 +1153,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1094
1153
|
};
|
|
1095
1154
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1096
1155
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1097
|
-
|
|
1156
|
+
import_log3.log.warn("object already inlined in a different document, ignoring the link", {
|
|
1098
1157
|
...logMeta,
|
|
1099
1158
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1100
1159
|
}, {
|
|
1101
|
-
F:
|
|
1160
|
+
F: __dxlog_file4,
|
|
1102
1161
|
L: 177,
|
|
1103
1162
|
S: this,
|
|
1104
1163
|
C: (f, a) => f(...a)
|
|
@@ -1106,8 +1165,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1106
1165
|
continue;
|
|
1107
1166
|
}
|
|
1108
1167
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1109
|
-
|
|
1110
|
-
F:
|
|
1168
|
+
import_log3.log.warn("object document was already loaded", logMeta, {
|
|
1169
|
+
F: __dxlog_file4,
|
|
1111
1170
|
L: 184,
|
|
1112
1171
|
S: this,
|
|
1113
1172
|
C: (f, a) => f(...a)
|
|
@@ -1115,8 +1174,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1115
1174
|
continue;
|
|
1116
1175
|
}
|
|
1117
1176
|
const handle = this._repo.find(automergeUrl);
|
|
1118
|
-
|
|
1119
|
-
F:
|
|
1177
|
+
import_log3.log.debug("document loading triggered", logMeta, {
|
|
1178
|
+
F: __dxlog_file4,
|
|
1120
1179
|
L: 188,
|
|
1121
1180
|
S: this,
|
|
1122
1181
|
C: (f, a) => f(...a)
|
|
@@ -1135,11 +1194,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1135
1194
|
break;
|
|
1136
1195
|
} catch (err) {
|
|
1137
1196
|
if (`${err}`.includes("Timeout")) {
|
|
1138
|
-
|
|
1197
|
+
import_log3.log.info("wraparound", {
|
|
1139
1198
|
id: docHandle.documentId,
|
|
1140
1199
|
state: docHandle.state
|
|
1141
1200
|
}, {
|
|
1142
|
-
F:
|
|
1201
|
+
F: __dxlog_file4,
|
|
1143
1202
|
L: 204,
|
|
1144
1203
|
S: this,
|
|
1145
1204
|
C: (f, a) => f(...a)
|
|
@@ -1164,16 +1223,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1164
1223
|
}
|
|
1165
1224
|
async _createObjectOnDocumentLoad(handle, objectId) {
|
|
1166
1225
|
try {
|
|
1167
|
-
await handle.
|
|
1168
|
-
"ready"
|
|
1169
|
-
]);
|
|
1226
|
+
await handle.whenReady();
|
|
1170
1227
|
const logMeta = {
|
|
1171
1228
|
objectId,
|
|
1172
1229
|
docUrl: handle.url
|
|
1173
1230
|
};
|
|
1174
1231
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1175
|
-
|
|
1176
|
-
F:
|
|
1232
|
+
import_log3.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1233
|
+
F: __dxlog_file4,
|
|
1177
1234
|
L: 231,
|
|
1178
1235
|
S: this,
|
|
1179
1236
|
C: (f, a) => f(...a)
|
|
@@ -1182,8 +1239,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1182
1239
|
}
|
|
1183
1240
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1184
1241
|
if (objectDocHandle?.url !== handle.url) {
|
|
1185
|
-
|
|
1186
|
-
F:
|
|
1242
|
+
import_log3.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1243
|
+
F: __dxlog_file4,
|
|
1187
1244
|
L: 236,
|
|
1188
1245
|
S: this,
|
|
1189
1246
|
C: (f, a) => f(...a)
|
|
@@ -1196,13 +1253,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1196
1253
|
});
|
|
1197
1254
|
} catch (err) {
|
|
1198
1255
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1199
|
-
|
|
1256
|
+
import_log3.log.warn("failed to load a document", {
|
|
1200
1257
|
objectId,
|
|
1201
1258
|
automergeUrl: handle.url,
|
|
1202
1259
|
retryLoading: shouldRetryLoading,
|
|
1203
1260
|
err
|
|
1204
1261
|
}, {
|
|
1205
|
-
F:
|
|
1262
|
+
F: __dxlog_file4,
|
|
1206
1263
|
L: 242,
|
|
1207
1264
|
S: this,
|
|
1208
1265
|
C: (f, a) => f(...a)
|
|
@@ -1221,7 +1278,121 @@ _ts_decorate3([
|
|
|
1221
1278
|
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1222
1279
|
import_tracing2.trace.resource()
|
|
1223
1280
|
], AutomergeDocumentLoaderImpl);
|
|
1224
|
-
var
|
|
1281
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator-connection.ts";
|
|
1282
|
+
var DEFAULT_FACTORY = (params) => new import_teleport_extension_automerge_replicator.AutomergeReplicator(...params);
|
|
1283
|
+
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
1284
|
+
constructor(_params) {
|
|
1285
|
+
super();
|
|
1286
|
+
this._params = _params;
|
|
1287
|
+
this.remoteDeviceKey = null;
|
|
1288
|
+
this._remotePeerId = null;
|
|
1289
|
+
this._isEnabled = false;
|
|
1290
|
+
let readableStreamController;
|
|
1291
|
+
this.readable = new ReadableStream({
|
|
1292
|
+
start: (controller) => {
|
|
1293
|
+
readableStreamController = controller;
|
|
1294
|
+
this._ctx.onDispose(() => controller.close());
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
this.writable = new WritableStream({
|
|
1298
|
+
write: async (message, controller) => {
|
|
1299
|
+
(0, import_invariant6.invariant)(this._isEnabled, "Writing to a disabled connection", {
|
|
1300
|
+
F: __dxlog_file5,
|
|
1301
|
+
L: 47,
|
|
1302
|
+
S: this,
|
|
1303
|
+
A: [
|
|
1304
|
+
"this._isEnabled",
|
|
1305
|
+
"'Writing to a disabled connection'"
|
|
1306
|
+
]
|
|
1307
|
+
});
|
|
1308
|
+
try {
|
|
1309
|
+
await this.replicatorExtension.sendSyncMessage({
|
|
1310
|
+
payload: import_automerge_repo5.cbor.encode(message)
|
|
1311
|
+
});
|
|
1312
|
+
} catch (err) {
|
|
1313
|
+
controller.error(err);
|
|
1314
|
+
this._disconnectIfEnabled();
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
const createAutomergeReplicator = this._params.replicatorFactory ?? DEFAULT_FACTORY;
|
|
1319
|
+
this.replicatorExtension = createAutomergeReplicator([
|
|
1320
|
+
{
|
|
1321
|
+
peerId: this._params.ownPeerId
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
onStartReplication: async (info, remotePeerId) => {
|
|
1325
|
+
this.remoteDeviceKey = remotePeerId;
|
|
1326
|
+
this._remotePeerId = info.id;
|
|
1327
|
+
(0, import_log5.log)("onStartReplication", {
|
|
1328
|
+
id: info.id,
|
|
1329
|
+
thisPeerId: this.peerId,
|
|
1330
|
+
remotePeerId: remotePeerId.toHex()
|
|
1331
|
+
}, {
|
|
1332
|
+
F: __dxlog_file5,
|
|
1333
|
+
L: 81,
|
|
1334
|
+
S: this,
|
|
1335
|
+
C: (f, a) => f(...a)
|
|
1336
|
+
});
|
|
1337
|
+
this._params.onRemoteConnected();
|
|
1338
|
+
},
|
|
1339
|
+
onSyncMessage: async ({ payload }) => {
|
|
1340
|
+
if (!this._isEnabled) {
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1344
|
+
readableStreamController.enqueue(message);
|
|
1345
|
+
},
|
|
1346
|
+
onClose: async () => {
|
|
1347
|
+
this._disconnectIfEnabled();
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
]);
|
|
1351
|
+
}
|
|
1352
|
+
_disconnectIfEnabled() {
|
|
1353
|
+
if (this._isEnabled) {
|
|
1354
|
+
this._params.onRemoteDisconnected();
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
get peerId() {
|
|
1358
|
+
(0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1359
|
+
F: __dxlog_file5,
|
|
1360
|
+
L: 107,
|
|
1361
|
+
S: this,
|
|
1362
|
+
A: [
|
|
1363
|
+
"this._remotePeerId != null",
|
|
1364
|
+
"'Remote peer has not connected yet.'"
|
|
1365
|
+
]
|
|
1366
|
+
});
|
|
1367
|
+
return this._remotePeerId;
|
|
1368
|
+
}
|
|
1369
|
+
async shouldAdvertise(params) {
|
|
1370
|
+
return this._params.shouldAdvertise(params);
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Start exchanging messages with the remote peer.
|
|
1374
|
+
* Call after the remote peer has connected.
|
|
1375
|
+
*/
|
|
1376
|
+
enable() {
|
|
1377
|
+
(0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1378
|
+
F: __dxlog_file5,
|
|
1379
|
+
L: 120,
|
|
1380
|
+
S: this,
|
|
1381
|
+
A: [
|
|
1382
|
+
"this._remotePeerId != null",
|
|
1383
|
+
"'Remote peer has not connected yet.'"
|
|
1384
|
+
]
|
|
1385
|
+
});
|
|
1386
|
+
this._isEnabled = true;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Stop exchanging messages with the remote peer.
|
|
1390
|
+
*/
|
|
1391
|
+
disable() {
|
|
1392
|
+
this._isEnabled = false;
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1225
1396
|
var MeshEchoReplicator = class {
|
|
1226
1397
|
constructor() {
|
|
1227
1398
|
this._connections = /* @__PURE__ */ new Set();
|
|
@@ -1240,10 +1411,10 @@ var MeshEchoReplicator = class {
|
|
|
1240
1411
|
this._connectionsPerPeer.clear();
|
|
1241
1412
|
this._context = null;
|
|
1242
1413
|
}
|
|
1243
|
-
createExtension() {
|
|
1244
|
-
(0,
|
|
1245
|
-
F:
|
|
1246
|
-
L:
|
|
1414
|
+
createExtension(extensionFactory) {
|
|
1415
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1416
|
+
F: __dxlog_file6,
|
|
1417
|
+
L: 51,
|
|
1247
1418
|
S: this,
|
|
1248
1419
|
A: [
|
|
1249
1420
|
"this._context",
|
|
@@ -1252,18 +1423,19 @@ var MeshEchoReplicator = class {
|
|
|
1252
1423
|
});
|
|
1253
1424
|
const connection = new MeshReplicatorConnection({
|
|
1254
1425
|
ownPeerId: this._context.peerId,
|
|
1426
|
+
replicatorFactory: extensionFactory,
|
|
1255
1427
|
onRemoteConnected: async () => {
|
|
1256
|
-
(0,
|
|
1428
|
+
(0, import_log4.log)("onRemoteConnected", {
|
|
1257
1429
|
peerId: connection.peerId
|
|
1258
1430
|
}, {
|
|
1259
|
-
F:
|
|
1260
|
-
L:
|
|
1431
|
+
F: __dxlog_file6,
|
|
1432
|
+
L: 57,
|
|
1261
1433
|
S: this,
|
|
1262
1434
|
C: (f, a) => f(...a)
|
|
1263
1435
|
});
|
|
1264
|
-
(0,
|
|
1265
|
-
F:
|
|
1266
|
-
L:
|
|
1436
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1437
|
+
F: __dxlog_file6,
|
|
1438
|
+
L: 58,
|
|
1267
1439
|
S: this,
|
|
1268
1440
|
A: [
|
|
1269
1441
|
"this._context",
|
|
@@ -1275,36 +1447,36 @@ var MeshEchoReplicator = class {
|
|
|
1275
1447
|
} else {
|
|
1276
1448
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1277
1449
|
this._context.onConnectionOpen(connection);
|
|
1278
|
-
|
|
1450
|
+
connection.enable();
|
|
1279
1451
|
}
|
|
1280
1452
|
},
|
|
1281
1453
|
onRemoteDisconnected: async () => {
|
|
1282
|
-
(0,
|
|
1454
|
+
(0, import_log4.log)("onRemoteDisconnected", {
|
|
1283
1455
|
peerId: connection.peerId
|
|
1284
1456
|
}, {
|
|
1285
|
-
F:
|
|
1286
|
-
L:
|
|
1457
|
+
F: __dxlog_file6,
|
|
1458
|
+
L: 69,
|
|
1287
1459
|
S: this,
|
|
1288
1460
|
C: (f, a) => f(...a)
|
|
1289
1461
|
});
|
|
1290
1462
|
this._context?.onConnectionClosed(connection);
|
|
1291
1463
|
this._connectionsPerPeer.delete(connection.peerId);
|
|
1292
|
-
|
|
1464
|
+
connection.disable();
|
|
1293
1465
|
this._connections.delete(connection);
|
|
1294
1466
|
},
|
|
1295
|
-
|
|
1296
|
-
(0,
|
|
1467
|
+
shouldAdvertise: async (params) => {
|
|
1468
|
+
(0, import_log4.log)("shouldAdvertise", {
|
|
1297
1469
|
peerId: connection.peerId,
|
|
1298
1470
|
documentId: params.documentId
|
|
1299
1471
|
}, {
|
|
1300
|
-
F:
|
|
1301
|
-
L:
|
|
1472
|
+
F: __dxlog_file6,
|
|
1473
|
+
L: 76,
|
|
1302
1474
|
S: this,
|
|
1303
1475
|
C: (f, a) => f(...a)
|
|
1304
1476
|
});
|
|
1305
|
-
(0,
|
|
1306
|
-
F:
|
|
1307
|
-
L:
|
|
1477
|
+
(0, import_invariant5.invariant)(this._context, void 0, {
|
|
1478
|
+
F: __dxlog_file6,
|
|
1479
|
+
L: 77,
|
|
1308
1480
|
S: this,
|
|
1309
1481
|
A: [
|
|
1310
1482
|
"this._context",
|
|
@@ -1314,12 +1486,12 @@ var MeshEchoReplicator = class {
|
|
|
1314
1486
|
try {
|
|
1315
1487
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1316
1488
|
if (!spaceKey) {
|
|
1317
|
-
(0,
|
|
1489
|
+
(0, import_log4.log)("space key not found for share policy check", {
|
|
1318
1490
|
peerId: connection.peerId,
|
|
1319
1491
|
documentId: params.documentId
|
|
1320
1492
|
}, {
|
|
1321
|
-
F:
|
|
1322
|
-
L:
|
|
1493
|
+
F: __dxlog_file6,
|
|
1494
|
+
L: 81,
|
|
1323
1495
|
S: this,
|
|
1324
1496
|
C: (f, a) => f(...a)
|
|
1325
1497
|
});
|
|
@@ -1327,19 +1499,19 @@ var MeshEchoReplicator = class {
|
|
|
1327
1499
|
}
|
|
1328
1500
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1329
1501
|
if (!connection.remoteDeviceKey) {
|
|
1330
|
-
(0,
|
|
1502
|
+
(0, import_log4.log)("device key not found for share policy check", {
|
|
1331
1503
|
peerId: connection.peerId,
|
|
1332
1504
|
documentId: params.documentId
|
|
1333
1505
|
}, {
|
|
1334
|
-
F:
|
|
1335
|
-
L:
|
|
1506
|
+
F: __dxlog_file6,
|
|
1507
|
+
L: 91,
|
|
1336
1508
|
S: this,
|
|
1337
1509
|
C: (f, a) => f(...a)
|
|
1338
1510
|
});
|
|
1339
1511
|
return false;
|
|
1340
1512
|
}
|
|
1341
1513
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1342
|
-
(0,
|
|
1514
|
+
(0, import_log4.log)("share policy check", {
|
|
1343
1515
|
localPeer: this._context.peerId,
|
|
1344
1516
|
remotePeer: connection.peerId,
|
|
1345
1517
|
documentId: params.documentId,
|
|
@@ -1347,16 +1519,16 @@ var MeshEchoReplicator = class {
|
|
|
1347
1519
|
spaceKey,
|
|
1348
1520
|
isAuthorized
|
|
1349
1521
|
}, {
|
|
1350
|
-
F:
|
|
1351
|
-
L:
|
|
1522
|
+
F: __dxlog_file6,
|
|
1523
|
+
L: 99,
|
|
1352
1524
|
S: this,
|
|
1353
1525
|
C: (f, a) => f(...a)
|
|
1354
1526
|
});
|
|
1355
1527
|
return isAuthorized;
|
|
1356
1528
|
} catch (err) {
|
|
1357
|
-
|
|
1358
|
-
F:
|
|
1359
|
-
L:
|
|
1529
|
+
import_log4.log.catch(err, void 0, {
|
|
1530
|
+
F: __dxlog_file6,
|
|
1531
|
+
L: 109,
|
|
1360
1532
|
S: this,
|
|
1361
1533
|
C: (f, a) => f(...a)
|
|
1362
1534
|
});
|
|
@@ -1368,115 +1540,23 @@ var MeshEchoReplicator = class {
|
|
|
1368
1540
|
return connection.replicatorExtension;
|
|
1369
1541
|
}
|
|
1370
1542
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1371
|
-
(0,
|
|
1543
|
+
(0, import_log4.log)("authorizeDevice", {
|
|
1372
1544
|
spaceKey,
|
|
1373
1545
|
deviceKey
|
|
1374
1546
|
}, {
|
|
1375
|
-
F:
|
|
1376
|
-
L:
|
|
1547
|
+
F: __dxlog_file6,
|
|
1548
|
+
L: 120,
|
|
1377
1549
|
S: this,
|
|
1378
1550
|
C: (f, a) => f(...a)
|
|
1379
1551
|
});
|
|
1380
1552
|
(0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
|
|
1381
1553
|
for (const connection of this._connections) {
|
|
1382
1554
|
if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
|
|
1383
|
-
this.
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
};
|
|
1388
|
-
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
1389
|
-
constructor(_params) {
|
|
1390
|
-
super();
|
|
1391
|
-
this._params = _params;
|
|
1392
|
-
this.remoteDeviceKey = null;
|
|
1393
|
-
this._remotePeerId = null;
|
|
1394
|
-
this._isEnabled = false;
|
|
1395
|
-
let readableStreamController;
|
|
1396
|
-
this.readable = new ReadableStream({
|
|
1397
|
-
start: (controller) => {
|
|
1398
|
-
readableStreamController = controller;
|
|
1399
|
-
this._ctx.onDispose(() => controller.close());
|
|
1400
|
-
}
|
|
1401
|
-
});
|
|
1402
|
-
this.writable = new WritableStream({
|
|
1403
|
-
write: async (message, controller) => {
|
|
1404
|
-
this.replicatorExtension.sendSyncMessage({
|
|
1405
|
-
payload: import_automerge_repo5.cbor.encode(message)
|
|
1406
|
-
}).catch((err) => {
|
|
1407
|
-
controller.error(err);
|
|
1408
|
-
});
|
|
1409
|
-
}
|
|
1410
|
-
});
|
|
1411
|
-
this.replicatorExtension = new import_teleport_extension_automerge_replicator.AutomergeReplicator({
|
|
1412
|
-
peerId: this._params.ownPeerId
|
|
1413
|
-
}, {
|
|
1414
|
-
onStartReplication: async (info, remotePeerId) => {
|
|
1415
|
-
this.remoteDeviceKey = remotePeerId;
|
|
1416
|
-
this._remotePeerId = info.id;
|
|
1417
|
-
(0, import_log3.log)("onStartReplication", {
|
|
1418
|
-
id: info.id,
|
|
1419
|
-
thisPeerId: this.peerId,
|
|
1420
|
-
remotePeerId: remotePeerId.toHex()
|
|
1421
|
-
}, {
|
|
1422
|
-
F: __dxlog_file4,
|
|
1423
|
-
L: 192,
|
|
1424
|
-
S: this,
|
|
1425
|
-
C: (f, a) => f(...a)
|
|
1426
|
-
});
|
|
1427
|
-
await this._params.onRemoteConnected();
|
|
1428
|
-
},
|
|
1429
|
-
onSyncMessage: async ({ payload }) => {
|
|
1430
|
-
if (!this._isEnabled) {
|
|
1431
|
-
return;
|
|
1432
|
-
}
|
|
1433
|
-
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1434
|
-
readableStreamController.enqueue(message);
|
|
1435
|
-
},
|
|
1436
|
-
onClose: async () => {
|
|
1437
|
-
if (!this._isEnabled) {
|
|
1438
|
-
return;
|
|
1555
|
+
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1556
|
+
this._context?.onConnectionAuthScopeChanged(connection);
|
|
1439
1557
|
}
|
|
1440
|
-
await this._params.onRemoteDisconnected();
|
|
1441
1558
|
}
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
get peerId() {
|
|
1445
|
-
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1446
|
-
F: __dxlog_file4,
|
|
1447
|
-
L: 215,
|
|
1448
|
-
S: this,
|
|
1449
|
-
A: [
|
|
1450
|
-
"this._remotePeerId != null",
|
|
1451
|
-
"'Remote peer has not connected yet.'"
|
|
1452
|
-
]
|
|
1453
|
-
});
|
|
1454
|
-
return this._remotePeerId;
|
|
1455
|
-
}
|
|
1456
|
-
async shouldAdvertize(params) {
|
|
1457
|
-
return this._params.shouldAdvertize(params);
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* Start exchanging messages with the remote peer.
|
|
1461
|
-
* Call after the remote peer has connected.
|
|
1462
|
-
*/
|
|
1463
|
-
async enable() {
|
|
1464
|
-
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1465
|
-
F: __dxlog_file4,
|
|
1466
|
-
L: 228,
|
|
1467
|
-
S: this,
|
|
1468
|
-
A: [
|
|
1469
|
-
"this._remotePeerId != null",
|
|
1470
|
-
"'Remote peer has not connected yet.'"
|
|
1471
|
-
]
|
|
1472
|
-
});
|
|
1473
|
-
this._isEnabled = true;
|
|
1474
|
-
}
|
|
1475
|
-
/**
|
|
1476
|
-
* Stop exchanging messages with the remote peer.
|
|
1477
|
-
*/
|
|
1478
|
-
async disable() {
|
|
1479
|
-
this._isEnabled = false;
|
|
1559
|
+
}
|
|
1480
1560
|
}
|
|
1481
1561
|
};
|
|
1482
1562
|
// Annotate the CommonJS export names for ESM import in node:
|