@dxos/echo-pipeline 0.5.9-next.a50ff17 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-HS77A4I4.mjs} +174 -23
- package/dist/lib/browser/{chunk-I2J5TTHJ.mjs.map → chunk-HS77A4I4.mjs.map} +4 -4
- package/dist/lib/browser/index.mjs +182 -126
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +11 -7
- package/dist/lib/browser/testing/index.mjs.map +1 -1
- package/dist/lib/node/{chunk-QPCNQ4ZK.cjs → chunk-Y5U7UXEL.cjs} +185 -34
- package/dist/lib/node/{chunk-QPCNQ4ZK.cjs.map → chunk-Y5U7UXEL.cjs.map} +4 -4
- package/dist/lib/node/index.cjs +230 -174
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +21 -17
- package/dist/lib/node/testing/index.cjs.map +1 -1
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +2 -1
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +40 -3
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
- package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
- package/dist/types/src/space/index.d.ts +1 -0
- package/dist/types/src/space/index.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +8 -0
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-doc-loader.test.ts +8 -5
- package/src/automerge/automerge-doc-loader.ts +29 -20
- package/src/automerge/automerge-host.ts +96 -32
- package/src/automerge/echo-network-adapter.ts +10 -4
- package/src/automerge/mesh-echo-replicator.ts +7 -2
- package/src/space/admission-discovery-extension.ts +90 -0
- package/src/space/index.ts +1 -0
- package/src/space/space-manager.ts +46 -1
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,70 +18,71 @@ 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_Y5U7UXEL.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_Y5U7UXEL.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
|
-
|
|
25
|
+
CredentialRetrieverExtension: () => import_chunk_Y5U7UXEL.CredentialRetrieverExtension,
|
|
26
|
+
CredentialServerExtension: () => import_chunk_Y5U7UXEL.CredentialServerExtension,
|
|
27
|
+
DataServiceImpl: () => import_chunk_Y5U7UXEL.DataServiceImpl,
|
|
26
28
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
27
29
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
28
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
29
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
30
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_Y5U7UXEL.MOCK_AUTH_PROVIDER,
|
|
31
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_Y5U7UXEL.MOCK_AUTH_VERIFIER,
|
|
30
32
|
MeshEchoReplicator: () => MeshEchoReplicator,
|
|
31
|
-
MetadataStore: () =>
|
|
32
|
-
Pipeline: () =>
|
|
33
|
-
SnapshotManager: () =>
|
|
34
|
-
SnapshotStore: () =>
|
|
35
|
-
Space: () =>
|
|
36
|
-
SpaceManager: () =>
|
|
37
|
-
SpaceProtocol: () =>
|
|
38
|
-
SpaceProtocolSession: () =>
|
|
39
|
-
TimeframeClock: () =>
|
|
40
|
-
codec: () =>
|
|
41
|
-
createIdFromSpaceKey: () =>
|
|
42
|
-
createMappedFeedWriter: () =>
|
|
33
|
+
MetadataStore: () => import_chunk_Y5U7UXEL.MetadataStore,
|
|
34
|
+
Pipeline: () => import_chunk_Y5U7UXEL.Pipeline,
|
|
35
|
+
SnapshotManager: () => import_chunk_Y5U7UXEL.SnapshotManager,
|
|
36
|
+
SnapshotStore: () => import_chunk_Y5U7UXEL.SnapshotStore,
|
|
37
|
+
Space: () => import_chunk_Y5U7UXEL.Space,
|
|
38
|
+
SpaceManager: () => import_chunk_Y5U7UXEL.SpaceManager,
|
|
39
|
+
SpaceProtocol: () => import_chunk_Y5U7UXEL.SpaceProtocol,
|
|
40
|
+
SpaceProtocolSession: () => import_chunk_Y5U7UXEL.SpaceProtocolSession,
|
|
41
|
+
TimeframeClock: () => import_chunk_Y5U7UXEL.TimeframeClock,
|
|
42
|
+
codec: () => import_chunk_Y5U7UXEL.codec,
|
|
43
|
+
createIdFromSpaceKey: () => import_chunk_Y5U7UXEL.createIdFromSpaceKey,
|
|
44
|
+
createMappedFeedWriter: () => import_chunk_Y5U7UXEL.createMappedFeedWriter,
|
|
43
45
|
encodingOptions: () => encodingOptions,
|
|
44
46
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
45
|
-
hasInvitationExpired: () =>
|
|
46
|
-
mapFeedIndexesToTimeframe: () =>
|
|
47
|
-
mapTimeframeToFeedIndexes: () =>
|
|
48
|
-
startAfter: () =>
|
|
49
|
-
valueEncoding: () =>
|
|
47
|
+
hasInvitationExpired: () => import_chunk_Y5U7UXEL.hasInvitationExpired,
|
|
48
|
+
mapFeedIndexesToTimeframe: () => import_chunk_Y5U7UXEL.mapFeedIndexesToTimeframe,
|
|
49
|
+
mapTimeframeToFeedIndexes: () => import_chunk_Y5U7UXEL.mapTimeframeToFeedIndexes,
|
|
50
|
+
startAfter: () => import_chunk_Y5U7UXEL.startAfter,
|
|
51
|
+
valueEncoding: () => import_chunk_Y5U7UXEL.valueEncoding
|
|
50
52
|
});
|
|
51
53
|
module.exports = __toCommonJS(node_exports);
|
|
52
|
-
var
|
|
54
|
+
var import_chunk_Y5U7UXEL = require("./chunk-Y5U7UXEL.cjs");
|
|
53
55
|
var import_async = require("@dxos/async");
|
|
54
56
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
55
57
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
56
58
|
var import_context = require("@dxos/context");
|
|
57
|
-
var import_invariant = require("@dxos/invariant");
|
|
58
59
|
var import_keys = require("@dxos/keys");
|
|
59
|
-
var import_log = require("@dxos/log");
|
|
60
60
|
var import_protocols = require("@dxos/protocols");
|
|
61
61
|
var import_tracing = require("@dxos/tracing");
|
|
62
62
|
var import_util = require("@dxos/util");
|
|
63
63
|
var import_async2 = require("@dxos/async");
|
|
64
64
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
65
65
|
var import_context2 = require("@dxos/context");
|
|
66
|
-
var
|
|
67
|
-
var
|
|
66
|
+
var import_invariant = require("@dxos/invariant");
|
|
67
|
+
var import_log = require("@dxos/log");
|
|
68
68
|
var import_context3 = require("@dxos/context");
|
|
69
69
|
var import_async3 = require("@dxos/async");
|
|
70
70
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
71
71
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
72
|
-
var
|
|
72
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
73
73
|
var import_async4 = require("@dxos/async");
|
|
74
|
+
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
74
75
|
var import_context4 = require("@dxos/context");
|
|
75
76
|
var import_debug = require("@dxos/debug");
|
|
76
77
|
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
77
|
-
var
|
|
78
|
-
var
|
|
78
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
79
|
+
var import_log2 = require("@dxos/log");
|
|
79
80
|
var import_tracing2 = require("@dxos/tracing");
|
|
80
|
-
var
|
|
81
|
+
var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
|
|
81
82
|
var import_context5 = require("@dxos/context");
|
|
82
|
-
var
|
|
83
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
83
84
|
var import_keys2 = require("@dxos/keys");
|
|
84
|
-
var
|
|
85
|
+
var import_log3 = require("@dxos/log");
|
|
85
86
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
86
87
|
var import_util2 = require("@dxos/util");
|
|
87
88
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -116,7 +117,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
116
117
|
}
|
|
117
118
|
connectionEntry.writer.write(message).catch((err) => {
|
|
118
119
|
if (connectionEntry.isOpen) {
|
|
119
|
-
|
|
120
|
+
import_log.log.catch(err, void 0, {
|
|
120
121
|
F: __dxlog_file,
|
|
121
122
|
L: 49,
|
|
122
123
|
S: this,
|
|
@@ -128,7 +129,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
128
129
|
disconnect() {
|
|
129
130
|
}
|
|
130
131
|
async open() {
|
|
131
|
-
(0,
|
|
132
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
|
|
132
133
|
F: __dxlog_file,
|
|
133
134
|
L: 60,
|
|
134
135
|
S: this,
|
|
@@ -138,7 +139,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
138
139
|
]
|
|
139
140
|
});
|
|
140
141
|
this._lifecycleState = import_context2.LifecycleState.OPEN;
|
|
141
|
-
(0,
|
|
142
|
+
(0, import_log.log)("emit ready", void 0, {
|
|
142
143
|
F: __dxlog_file,
|
|
143
144
|
L: 63,
|
|
144
145
|
S: this,
|
|
@@ -149,7 +150,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
async close() {
|
|
152
|
-
(0,
|
|
153
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
153
154
|
F: __dxlog_file,
|
|
154
155
|
L: 71,
|
|
155
156
|
S: this,
|
|
@@ -170,7 +171,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
170
171
|
});
|
|
171
172
|
}
|
|
172
173
|
async addReplicator(replicator) {
|
|
173
|
-
(0,
|
|
174
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
174
175
|
F: __dxlog_file,
|
|
175
176
|
L: 87,
|
|
176
177
|
S: this,
|
|
@@ -179,7 +180,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
179
180
|
""
|
|
180
181
|
]
|
|
181
182
|
});
|
|
182
|
-
(0,
|
|
183
|
+
(0, import_invariant.invariant)(this.peerId, void 0, {
|
|
183
184
|
F: __dxlog_file,
|
|
184
185
|
L: 88,
|
|
185
186
|
S: this,
|
|
@@ -188,7 +189,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
188
189
|
""
|
|
189
190
|
]
|
|
190
191
|
});
|
|
191
|
-
(0,
|
|
192
|
+
(0, import_invariant.invariant)(!this._replicators.has(replicator), void 0, {
|
|
192
193
|
F: __dxlog_file,
|
|
193
194
|
L: 89,
|
|
194
195
|
S: this,
|
|
@@ -207,7 +208,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
207
208
|
});
|
|
208
209
|
}
|
|
209
210
|
async removeReplicator(replicator) {
|
|
210
|
-
(0,
|
|
211
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
211
212
|
F: __dxlog_file,
|
|
212
213
|
L: 103,
|
|
213
214
|
S: this,
|
|
@@ -216,7 +217,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
216
217
|
""
|
|
217
218
|
]
|
|
218
219
|
});
|
|
219
|
-
(0,
|
|
220
|
+
(0, import_invariant.invariant)(this._replicators.has(replicator), void 0, {
|
|
220
221
|
F: __dxlog_file,
|
|
221
222
|
L: 104,
|
|
222
223
|
S: this,
|
|
@@ -236,7 +237,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
236
237
|
return connection.connection.shouldAdvertize(params);
|
|
237
238
|
}
|
|
238
239
|
_onConnectionOpen(connection) {
|
|
239
|
-
(0,
|
|
240
|
+
(0, import_log.log)("Connection opened", {
|
|
240
241
|
peerId: connection.peerId
|
|
241
242
|
}, {
|
|
242
243
|
F: __dxlog_file,
|
|
@@ -244,7 +245,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
244
245
|
S: this,
|
|
245
246
|
C: (f, a) => f(...a)
|
|
246
247
|
});
|
|
247
|
-
(0,
|
|
248
|
+
(0, import_invariant.invariant)(!this._connections.has(connection.peerId), void 0, {
|
|
248
249
|
F: __dxlog_file,
|
|
249
250
|
L: 120,
|
|
250
251
|
S: this,
|
|
@@ -273,7 +274,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
273
274
|
}
|
|
274
275
|
} catch (err) {
|
|
275
276
|
if (connectionEntry.isOpen) {
|
|
276
|
-
|
|
277
|
+
import_log.log.catch(err, void 0, {
|
|
277
278
|
F: __dxlog_file,
|
|
278
279
|
L: 139,
|
|
279
280
|
S: this,
|
|
@@ -282,7 +283,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
});
|
|
285
|
-
(0,
|
|
286
|
+
(0, import_log.log)("emit peer-candidate", {
|
|
286
287
|
peerId: connection.peerId
|
|
287
288
|
}, {
|
|
288
289
|
F: __dxlog_file,
|
|
@@ -297,7 +298,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
297
298
|
* TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
|
|
298
299
|
*/
|
|
299
300
|
_onConnectionAuthScopeChanged(connection) {
|
|
300
|
-
(0,
|
|
301
|
+
(0, import_log.log)("Connection auth scope changed", {
|
|
301
302
|
peerId: connection.peerId
|
|
302
303
|
}, {
|
|
303
304
|
F: __dxlog_file,
|
|
@@ -306,7 +307,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
306
307
|
C: (f, a) => f(...a)
|
|
307
308
|
});
|
|
308
309
|
const entry = this._connections.get(connection.peerId);
|
|
309
|
-
(0,
|
|
310
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
310
311
|
F: __dxlog_file,
|
|
311
312
|
L: 155,
|
|
312
313
|
S: this,
|
|
@@ -321,7 +322,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
321
322
|
this._emitPeerCandidate(connection);
|
|
322
323
|
}
|
|
323
324
|
_onConnectionClosed(connection) {
|
|
324
|
-
(0,
|
|
325
|
+
(0, import_log.log)("Connection closed", {
|
|
325
326
|
peerId: connection.peerId
|
|
326
327
|
}, {
|
|
327
328
|
F: __dxlog_file,
|
|
@@ -330,7 +331,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
330
331
|
C: (f, a) => f(...a)
|
|
331
332
|
});
|
|
332
333
|
const entry = this._connections.get(connection.peerId);
|
|
333
|
-
(0,
|
|
334
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
334
335
|
F: __dxlog_file,
|
|
335
336
|
L: 163,
|
|
336
337
|
S: this,
|
|
@@ -343,13 +344,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
343
344
|
this.emit("peer-disconnected", {
|
|
344
345
|
peerId: connection.peerId
|
|
345
346
|
});
|
|
346
|
-
void entry.reader.cancel().catch((err) =>
|
|
347
|
+
void entry.reader.cancel().catch((err) => import_log.log.catch(err, void 0, {
|
|
347
348
|
F: __dxlog_file,
|
|
348
349
|
L: 168,
|
|
349
350
|
S: this,
|
|
350
351
|
C: (f, a) => f(...a)
|
|
351
352
|
}));
|
|
352
|
-
void entry.writer.abort().catch((err) =>
|
|
353
|
+
void entry.writer.abort().catch((err) => import_log.log.catch(err, void 0, {
|
|
353
354
|
F: __dxlog_file,
|
|
354
355
|
L: 169,
|
|
355
356
|
S: this,
|
|
@@ -360,10 +361,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
360
361
|
_emitPeerCandidate(connection) {
|
|
361
362
|
this.emit("peer-candidate", {
|
|
362
363
|
peerId: connection.peerId,
|
|
363
|
-
peerMetadata:
|
|
364
|
-
// TODO(dmaretskyi): Refactor this.
|
|
365
|
-
dxos_peerSource: "EchoNetworkAdapter"
|
|
366
|
-
}
|
|
364
|
+
peerMetadata: createEchoPeerMetadata()
|
|
367
365
|
});
|
|
368
366
|
}
|
|
369
367
|
};
|
|
@@ -379,6 +377,11 @@ _ts_decorate([
|
|
|
379
377
|
_ts_decorate([
|
|
380
378
|
import_async2.synchronized
|
|
381
379
|
], EchoNetworkAdapter.prototype, "removeReplicator", null);
|
|
380
|
+
var createEchoPeerMetadata = () => ({
|
|
381
|
+
// TODO(dmaretskyi): Refactor this.
|
|
382
|
+
dxos_peerSource: "EchoNetworkAdapter"
|
|
383
|
+
});
|
|
384
|
+
var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetworkAdapter";
|
|
382
385
|
var LevelDBStorageAdapter = class extends import_context3.Resource {
|
|
383
386
|
constructor(_params) {
|
|
384
387
|
super();
|
|
@@ -500,7 +503,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
500
503
|
}
|
|
501
504
|
send(message) {
|
|
502
505
|
const peer = this._peers.get(message.targetId);
|
|
503
|
-
(0,
|
|
506
|
+
(0, import_invariant2.invariant)(peer, "Peer not found.", {
|
|
504
507
|
F: __dxlog_file2,
|
|
505
508
|
L: 51,
|
|
506
509
|
S: this,
|
|
@@ -525,7 +528,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
525
528
|
syncRepo({ id, syncMessage }) {
|
|
526
529
|
const peerId = this._getPeerId(id);
|
|
527
530
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
528
|
-
(0,
|
|
531
|
+
(0, import_invariant2.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
529
532
|
F: __dxlog_file2,
|
|
530
533
|
L: 73,
|
|
531
534
|
S: this,
|
|
@@ -549,7 +552,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
549
552
|
});
|
|
550
553
|
}
|
|
551
554
|
});
|
|
552
|
-
(0,
|
|
555
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
553
556
|
F: __dxlog_file2,
|
|
554
557
|
L: 90,
|
|
555
558
|
S: this,
|
|
@@ -565,7 +568,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
565
568
|
});
|
|
566
569
|
}
|
|
567
570
|
async sendSyncMessage({ id, syncMessage }) {
|
|
568
|
-
(0,
|
|
571
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
569
572
|
F: __dxlog_file2,
|
|
570
573
|
L: 99,
|
|
571
574
|
S: this,
|
|
@@ -578,7 +581,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
578
581
|
this.emit("message", message);
|
|
579
582
|
}
|
|
580
583
|
async getHostInfo() {
|
|
581
|
-
(0,
|
|
584
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
582
585
|
F: __dxlog_file2,
|
|
583
586
|
L: 105,
|
|
584
587
|
S: this,
|
|
@@ -587,7 +590,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
587
590
|
""
|
|
588
591
|
]
|
|
589
592
|
});
|
|
590
|
-
(0,
|
|
593
|
+
(0, import_invariant2.invariant)(this.peerId, "Peer id not set.", {
|
|
591
594
|
F: __dxlog_file2,
|
|
592
595
|
L: 106,
|
|
593
596
|
S: this,
|
|
@@ -617,11 +620,13 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
617
620
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
618
621
|
var AutomergeHost = class {
|
|
619
622
|
constructor({ db, indexMetadataStore }) {
|
|
620
|
-
this._ctx = new import_context.Context(
|
|
623
|
+
this._ctx = new import_context.Context(void 0, {
|
|
624
|
+
F: __dxlog_file3,
|
|
625
|
+
L: 71
|
|
626
|
+
});
|
|
621
627
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
622
628
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
623
629
|
});
|
|
624
|
-
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
625
630
|
this._storage = new LevelDBStorageAdapter({
|
|
626
631
|
db,
|
|
627
632
|
callbacks: {
|
|
@@ -657,6 +662,9 @@ var AutomergeHost = class {
|
|
|
657
662
|
await this._echoNetworkAdapter.close();
|
|
658
663
|
await this._ctx.dispose();
|
|
659
664
|
}
|
|
665
|
+
/**
|
|
666
|
+
* @deprecated To be abstracted away.
|
|
667
|
+
*/
|
|
660
668
|
get repo() {
|
|
661
669
|
return this._repo;
|
|
662
670
|
}
|
|
@@ -666,6 +674,39 @@ var AutomergeHost = class {
|
|
|
666
674
|
async removeReplicator(replicator) {
|
|
667
675
|
await this._echoNetworkAdapter.removeReplicator(replicator);
|
|
668
676
|
}
|
|
677
|
+
/**
|
|
678
|
+
* Loads the document handle from the repo and waits for it to be ready.
|
|
679
|
+
*/
|
|
680
|
+
async loadDoc(ctx, documentId, opts) {
|
|
681
|
+
let handle;
|
|
682
|
+
if (typeof documentId === "string") {
|
|
683
|
+
handle = this._repo.handles[documentId];
|
|
684
|
+
}
|
|
685
|
+
if (!handle) {
|
|
686
|
+
handle = this._repo.find(documentId);
|
|
687
|
+
}
|
|
688
|
+
if (!handle.isReady()) {
|
|
689
|
+
if (!opts?.timeout) {
|
|
690
|
+
await (0, import_context.cancelWithContext)(ctx, handle.whenReady());
|
|
691
|
+
} else {
|
|
692
|
+
await (0, import_context.cancelWithContext)(ctx, (0, import_async.asyncTimeout)(handle.whenReady(), opts.timeout));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return handle;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Create new persisted document.
|
|
699
|
+
*/
|
|
700
|
+
createDoc(initialValue, opts) {
|
|
701
|
+
if (opts?.preserveHistory) {
|
|
702
|
+
if (!(0, import_automerge.isAutomerge)(initialValue)) {
|
|
703
|
+
throw new TypeError("Initial value must be an Automerge document");
|
|
704
|
+
}
|
|
705
|
+
return this._repo.import((0, import_automerge.save)(initialValue));
|
|
706
|
+
} else {
|
|
707
|
+
return this._repo.create(initialValue);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
669
710
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
670
711
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
671
712
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -677,23 +718,8 @@ var AutomergeHost = class {
|
|
|
677
718
|
if (!documentId) {
|
|
678
719
|
return false;
|
|
679
720
|
}
|
|
680
|
-
const doc = this._repo.handles[documentId]?.docSync();
|
|
681
|
-
if (!doc) {
|
|
682
|
-
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
683
|
-
(0, import_log.log)("doc share policy check", {
|
|
684
|
-
peerId,
|
|
685
|
-
documentId,
|
|
686
|
-
isRequested
|
|
687
|
-
}, {
|
|
688
|
-
F: __dxlog_file3,
|
|
689
|
-
L: 143,
|
|
690
|
-
S: this,
|
|
691
|
-
C: (f, a) => f(...a)
|
|
692
|
-
});
|
|
693
|
-
return isRequested;
|
|
694
|
-
}
|
|
695
721
|
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
696
|
-
if (peerMetadata
|
|
722
|
+
if (isEchoPeerMetadata(peerMetadata)) {
|
|
697
723
|
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
698
724
|
documentId
|
|
699
725
|
});
|
|
@@ -765,31 +791,36 @@ var AutomergeHost = class {
|
|
|
765
791
|
}
|
|
766
792
|
return import_keys.PublicKey.from(spaceKeyHex);
|
|
767
793
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
794
|
+
/**
|
|
795
|
+
* Flush documents to disk.
|
|
796
|
+
*/
|
|
771
797
|
async flush({ states }) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
});
|
|
782
|
-
const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
|
|
783
|
-
await waitForHeads(handle, heads);
|
|
784
|
-
}) ?? []);
|
|
798
|
+
if (states) {
|
|
799
|
+
await Promise.all(states.map(async ({ heads, documentId }) => {
|
|
800
|
+
if (!heads) {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
|
|
804
|
+
await waitForHeads(handle, heads);
|
|
805
|
+
}) ?? []);
|
|
806
|
+
}
|
|
785
807
|
await this._repo.flush(states?.map(({ documentId }) => documentId));
|
|
786
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Host <-> Client sync.
|
|
811
|
+
*/
|
|
787
812
|
syncRepo(request) {
|
|
788
813
|
return this._clientNetwork.syncRepo(request);
|
|
789
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Host <-> Client sync.
|
|
817
|
+
*/
|
|
790
818
|
sendSyncMessage(request) {
|
|
791
819
|
return this._clientNetwork.sendSyncMessage(request);
|
|
792
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Host <-> Client sync.
|
|
823
|
+
*/
|
|
793
824
|
async getHostInfo() {
|
|
794
825
|
return this._clientNetwork.getHostInfo();
|
|
795
826
|
}
|
|
@@ -872,32 +903,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
872
903
|
return;
|
|
873
904
|
}
|
|
874
905
|
if (!spaceState.rootUrl) {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
this._spaceRootDocHandle = existingDocHandle;
|
|
906
|
+
throw new Error("Database opened with no rootUrl");
|
|
907
|
+
}
|
|
908
|
+
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
909
|
+
const doc = existingDocHandle.docSync();
|
|
910
|
+
(0, import_invariant3.invariant)(doc, void 0, {
|
|
911
|
+
F: __dxlog_file4,
|
|
912
|
+
L: 84,
|
|
913
|
+
S: this,
|
|
914
|
+
A: [
|
|
915
|
+
"doc",
|
|
916
|
+
""
|
|
917
|
+
]
|
|
918
|
+
});
|
|
919
|
+
(0, import_invariant3.invariant)(doc.version === import_echo_protocol.SpaceDocVersion.CURRENT, void 0, {
|
|
920
|
+
F: __dxlog_file4,
|
|
921
|
+
L: 85,
|
|
922
|
+
S: this,
|
|
923
|
+
A: [
|
|
924
|
+
"doc.version === SpaceDocVersion.CURRENT",
|
|
925
|
+
""
|
|
926
|
+
]
|
|
927
|
+
});
|
|
928
|
+
if (doc.access == null) {
|
|
929
|
+
this._initDocAccess(existingDocHandle);
|
|
900
930
|
}
|
|
931
|
+
this._spaceRootDocHandle = existingDocHandle;
|
|
901
932
|
}
|
|
902
933
|
loadObjectDocument(objectIdOrMany) {
|
|
903
934
|
const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
|
|
@@ -906,9 +937,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
906
937
|
let hasUrlsToLoad = false;
|
|
907
938
|
const urlsToLoad = {};
|
|
908
939
|
for (const objectId of objectIds) {
|
|
909
|
-
(0,
|
|
940
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
910
941
|
F: __dxlog_file4,
|
|
911
|
-
L:
|
|
942
|
+
L: 97,
|
|
912
943
|
S: this,
|
|
913
944
|
A: [
|
|
914
945
|
"this._spaceRootDocHandle",
|
|
@@ -919,9 +950,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
919
950
|
continue;
|
|
920
951
|
}
|
|
921
952
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
922
|
-
(0,
|
|
953
|
+
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
923
954
|
F: __dxlog_file4,
|
|
924
|
-
L:
|
|
955
|
+
L: 102,
|
|
925
956
|
S: this,
|
|
926
957
|
A: [
|
|
927
958
|
"spaceRootDoc",
|
|
@@ -931,11 +962,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
931
962
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
932
963
|
if (documentUrl == null) {
|
|
933
964
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
934
|
-
|
|
965
|
+
import_log2.log.info("loading delayed until object links are initialized", {
|
|
935
966
|
objectId
|
|
936
967
|
}, {
|
|
937
968
|
F: __dxlog_file4,
|
|
938
|
-
L:
|
|
969
|
+
L: 106,
|
|
939
970
|
S: this,
|
|
940
971
|
C: (f, a) => f(...a)
|
|
941
972
|
});
|
|
@@ -948,6 +979,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
948
979
|
this._loadLinkedObjects(urlsToLoad);
|
|
949
980
|
}
|
|
950
981
|
}
|
|
982
|
+
getObjectDocumentId(objectId) {
|
|
983
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
984
|
+
F: __dxlog_file4,
|
|
985
|
+
L: 118,
|
|
986
|
+
S: this,
|
|
987
|
+
A: [
|
|
988
|
+
"this._spaceRootDocHandle",
|
|
989
|
+
""
|
|
990
|
+
]
|
|
991
|
+
});
|
|
992
|
+
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
993
|
+
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
994
|
+
F: __dxlog_file4,
|
|
995
|
+
L: 120,
|
|
996
|
+
S: this,
|
|
997
|
+
A: [
|
|
998
|
+
"spaceRootDoc",
|
|
999
|
+
""
|
|
1000
|
+
]
|
|
1001
|
+
});
|
|
1002
|
+
if (spaceRootDoc.objects?.[objectId]) {
|
|
1003
|
+
return this._spaceRootDocHandle.documentId;
|
|
1004
|
+
}
|
|
1005
|
+
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
1006
|
+
return documentUrl && (0, import_automerge_repo4.interpretAsDocumentId)(documentUrl);
|
|
1007
|
+
}
|
|
951
1008
|
onObjectLinksUpdated(links) {
|
|
952
1009
|
if (!links) {
|
|
953
1010
|
return;
|
|
@@ -957,9 +1014,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
957
1014
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
958
1015
|
}
|
|
959
1016
|
getSpaceRootDocHandle() {
|
|
960
|
-
(0,
|
|
1017
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
961
1018
|
F: __dxlog_file4,
|
|
962
|
-
L:
|
|
1019
|
+
L: 140,
|
|
963
1020
|
S: this,
|
|
964
1021
|
A: [
|
|
965
1022
|
"this._spaceRootDocHandle",
|
|
@@ -969,9 +1026,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
969
1026
|
return this._spaceRootDocHandle;
|
|
970
1027
|
}
|
|
971
1028
|
createDocumentForObject(objectId) {
|
|
972
|
-
(0,
|
|
1029
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
973
1030
|
F: __dxlog_file4,
|
|
974
|
-
L:
|
|
1031
|
+
L: 145,
|
|
975
1032
|
S: this,
|
|
976
1033
|
A: [
|
|
977
1034
|
"this._spaceRootDocHandle",
|
|
@@ -1011,30 +1068,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1011
1068
|
};
|
|
1012
1069
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1013
1070
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1014
|
-
|
|
1071
|
+
import_log2.log.warn("object already inlined in a different document, ignoring the link", {
|
|
1015
1072
|
...logMeta,
|
|
1016
1073
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1017
1074
|
}, {
|
|
1018
1075
|
F: __dxlog_file4,
|
|
1019
|
-
L:
|
|
1076
|
+
L: 177,
|
|
1020
1077
|
S: this,
|
|
1021
1078
|
C: (f, a) => f(...a)
|
|
1022
1079
|
});
|
|
1023
1080
|
continue;
|
|
1024
1081
|
}
|
|
1025
1082
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1026
|
-
|
|
1083
|
+
import_log2.log.warn("object document was already loaded", logMeta, {
|
|
1027
1084
|
F: __dxlog_file4,
|
|
1028
|
-
L:
|
|
1085
|
+
L: 184,
|
|
1029
1086
|
S: this,
|
|
1030
1087
|
C: (f, a) => f(...a)
|
|
1031
1088
|
});
|
|
1032
1089
|
continue;
|
|
1033
1090
|
}
|
|
1034
1091
|
const handle = this._repo.find(automergeUrl);
|
|
1035
|
-
|
|
1092
|
+
import_log2.log.debug("document loading triggered", logMeta, {
|
|
1036
1093
|
F: __dxlog_file4,
|
|
1037
|
-
L:
|
|
1094
|
+
L: 188,
|
|
1038
1095
|
S: this,
|
|
1039
1096
|
C: (f, a) => f(...a)
|
|
1040
1097
|
});
|
|
@@ -1052,12 +1109,12 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1052
1109
|
break;
|
|
1053
1110
|
} catch (err) {
|
|
1054
1111
|
if (`${err}`.includes("Timeout")) {
|
|
1055
|
-
|
|
1112
|
+
import_log2.log.info("wraparound", {
|
|
1056
1113
|
id: docHandle.documentId,
|
|
1057
1114
|
state: docHandle.state
|
|
1058
1115
|
}, {
|
|
1059
1116
|
F: __dxlog_file4,
|
|
1060
|
-
L:
|
|
1117
|
+
L: 204,
|
|
1061
1118
|
S: this,
|
|
1062
1119
|
C: (f, a) => f(...a)
|
|
1063
1120
|
});
|
|
@@ -1071,14 +1128,6 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1071
1128
|
}
|
|
1072
1129
|
return docHandle;
|
|
1073
1130
|
}
|
|
1074
|
-
_createContextBoundSpaceRootDocument(ctx) {
|
|
1075
|
-
const docHandle = this._repo.create();
|
|
1076
|
-
this._spaceRootDocHandle = docHandle;
|
|
1077
|
-
ctx.onDispose(() => {
|
|
1078
|
-
docHandle.delete();
|
|
1079
|
-
this._spaceRootDocHandle = null;
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
1131
|
_initDocAccess(handle) {
|
|
1083
1132
|
handle.change((newDoc) => {
|
|
1084
1133
|
newDoc.access ??= {
|
|
@@ -1097,9 +1146,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1097
1146
|
docUrl: handle.url
|
|
1098
1147
|
};
|
|
1099
1148
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1100
|
-
|
|
1149
|
+
import_log2.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1101
1150
|
F: __dxlog_file4,
|
|
1102
|
-
L:
|
|
1151
|
+
L: 231,
|
|
1103
1152
|
S: this,
|
|
1104
1153
|
C: (f, a) => f(...a)
|
|
1105
1154
|
});
|
|
@@ -1107,9 +1156,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1107
1156
|
}
|
|
1108
1157
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1109
1158
|
if (objectDocHandle?.url !== handle.url) {
|
|
1110
|
-
|
|
1159
|
+
import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1111
1160
|
F: __dxlog_file4,
|
|
1112
|
-
L:
|
|
1161
|
+
L: 236,
|
|
1113
1162
|
S: this,
|
|
1114
1163
|
C: (f, a) => f(...a)
|
|
1115
1164
|
});
|
|
@@ -1121,14 +1170,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1121
1170
|
});
|
|
1122
1171
|
} catch (err) {
|
|
1123
1172
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1124
|
-
|
|
1173
|
+
import_log2.log.warn("failed to load a document", {
|
|
1125
1174
|
objectId,
|
|
1126
1175
|
automergeUrl: handle.url,
|
|
1127
1176
|
retryLoading: shouldRetryLoading,
|
|
1128
1177
|
err
|
|
1129
1178
|
}, {
|
|
1130
1179
|
F: __dxlog_file4,
|
|
1131
|
-
L:
|
|
1180
|
+
L: 242,
|
|
1132
1181
|
S: this,
|
|
1133
1182
|
C: (f, a) => f(...a)
|
|
1134
1183
|
});
|
|
@@ -1166,7 +1215,7 @@ var MeshEchoReplicator = class {
|
|
|
1166
1215
|
this._context = null;
|
|
1167
1216
|
}
|
|
1168
1217
|
createExtension() {
|
|
1169
|
-
(0,
|
|
1218
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1170
1219
|
F: __dxlog_file5,
|
|
1171
1220
|
L: 54,
|
|
1172
1221
|
S: this,
|
|
@@ -1178,7 +1227,7 @@ var MeshEchoReplicator = class {
|
|
|
1178
1227
|
const connection = new MeshReplicatorConnection({
|
|
1179
1228
|
ownPeerId: this._context.peerId,
|
|
1180
1229
|
onRemoteConnected: async () => {
|
|
1181
|
-
(0,
|
|
1230
|
+
(0, import_log3.log)("onRemoteConnected", {
|
|
1182
1231
|
peerId: connection.peerId
|
|
1183
1232
|
}, {
|
|
1184
1233
|
F: __dxlog_file5,
|
|
@@ -1186,7 +1235,7 @@ var MeshEchoReplicator = class {
|
|
|
1186
1235
|
S: this,
|
|
1187
1236
|
C: (f, a) => f(...a)
|
|
1188
1237
|
});
|
|
1189
|
-
(0,
|
|
1238
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1190
1239
|
F: __dxlog_file5,
|
|
1191
1240
|
L: 60,
|
|
1192
1241
|
S: this,
|
|
@@ -1199,12 +1248,12 @@ var MeshEchoReplicator = class {
|
|
|
1199
1248
|
this._context.onConnectionAuthScopeChanged(connection);
|
|
1200
1249
|
} else {
|
|
1201
1250
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1202
|
-
await connection.enable();
|
|
1203
1251
|
this._context.onConnectionOpen(connection);
|
|
1252
|
+
await connection.enable();
|
|
1204
1253
|
}
|
|
1205
1254
|
},
|
|
1206
1255
|
onRemoteDisconnected: async () => {
|
|
1207
|
-
(0,
|
|
1256
|
+
(0, import_log3.log)("onRemoteDisconnected", {
|
|
1208
1257
|
peerId: connection.peerId
|
|
1209
1258
|
}, {
|
|
1210
1259
|
F: __dxlog_file5,
|
|
@@ -1213,12 +1262,12 @@ var MeshEchoReplicator = class {
|
|
|
1213
1262
|
C: (f, a) => f(...a)
|
|
1214
1263
|
});
|
|
1215
1264
|
this._context?.onConnectionClosed(connection);
|
|
1216
|
-
await connection.disable();
|
|
1217
1265
|
this._connectionsPerPeer.delete(connection.peerId);
|
|
1266
|
+
await connection.disable();
|
|
1218
1267
|
this._connections.delete(connection);
|
|
1219
1268
|
},
|
|
1220
1269
|
shouldAdvertize: async (params) => {
|
|
1221
|
-
(0,
|
|
1270
|
+
(0, import_log3.log)("shouldAdvertize", {
|
|
1222
1271
|
peerId: connection.peerId,
|
|
1223
1272
|
documentId: params.documentId
|
|
1224
1273
|
}, {
|
|
@@ -1227,7 +1276,7 @@ var MeshEchoReplicator = class {
|
|
|
1227
1276
|
S: this,
|
|
1228
1277
|
C: (f, a) => f(...a)
|
|
1229
1278
|
});
|
|
1230
|
-
(0,
|
|
1279
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1231
1280
|
F: __dxlog_file5,
|
|
1232
1281
|
L: 79,
|
|
1233
1282
|
S: this,
|
|
@@ -1239,7 +1288,7 @@ var MeshEchoReplicator = class {
|
|
|
1239
1288
|
try {
|
|
1240
1289
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1241
1290
|
if (!spaceKey) {
|
|
1242
|
-
(0,
|
|
1291
|
+
(0, import_log3.log)("space key not found for share policy check", {
|
|
1243
1292
|
peerId: connection.peerId,
|
|
1244
1293
|
documentId: params.documentId
|
|
1245
1294
|
}, {
|
|
@@ -1252,7 +1301,7 @@ var MeshEchoReplicator = class {
|
|
|
1252
1301
|
}
|
|
1253
1302
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1254
1303
|
if (!connection.remoteDeviceKey) {
|
|
1255
|
-
(0,
|
|
1304
|
+
(0, import_log3.log)("device key not found for share policy check", {
|
|
1256
1305
|
peerId: connection.peerId,
|
|
1257
1306
|
documentId: params.documentId
|
|
1258
1307
|
}, {
|
|
@@ -1264,7 +1313,7 @@ var MeshEchoReplicator = class {
|
|
|
1264
1313
|
return false;
|
|
1265
1314
|
}
|
|
1266
1315
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1267
|
-
(0,
|
|
1316
|
+
(0, import_log3.log)("share policy check", {
|
|
1268
1317
|
localPeer: this._context.peerId,
|
|
1269
1318
|
remotePeer: connection.peerId,
|
|
1270
1319
|
documentId: params.documentId,
|
|
@@ -1279,7 +1328,7 @@ var MeshEchoReplicator = class {
|
|
|
1279
1328
|
});
|
|
1280
1329
|
return isAuthorized;
|
|
1281
1330
|
} catch (err) {
|
|
1282
|
-
|
|
1331
|
+
import_log3.log.catch(err, void 0, {
|
|
1283
1332
|
F: __dxlog_file5,
|
|
1284
1333
|
L: 111,
|
|
1285
1334
|
S: this,
|
|
@@ -1293,7 +1342,7 @@ var MeshEchoReplicator = class {
|
|
|
1293
1342
|
return connection.replicatorExtension;
|
|
1294
1343
|
}
|
|
1295
1344
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1296
|
-
(0,
|
|
1345
|
+
(0, import_log3.log)("authorizeDevice", {
|
|
1297
1346
|
spaceKey,
|
|
1298
1347
|
deviceKey
|
|
1299
1348
|
}, {
|
|
@@ -1303,6 +1352,11 @@ var MeshEchoReplicator = class {
|
|
|
1303
1352
|
C: (f, a) => f(...a)
|
|
1304
1353
|
});
|
|
1305
1354
|
(0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
|
|
1355
|
+
for (const connection of this._connections) {
|
|
1356
|
+
if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
|
|
1357
|
+
this._context?.onConnectionAuthScopeChanged(connection);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1306
1360
|
}
|
|
1307
1361
|
};
|
|
1308
1362
|
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
@@ -1322,7 +1376,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1322
1376
|
this.writable = new WritableStream({
|
|
1323
1377
|
write: async (message, controller) => {
|
|
1324
1378
|
this.replicatorExtension.sendSyncMessage({
|
|
1325
|
-
payload:
|
|
1379
|
+
payload: import_automerge_repo5.cbor.encode(message)
|
|
1326
1380
|
}).catch((err) => {
|
|
1327
1381
|
controller.error(err);
|
|
1328
1382
|
});
|
|
@@ -1334,13 +1388,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1334
1388
|
onStartReplication: async (info, remotePeerId) => {
|
|
1335
1389
|
this.remoteDeviceKey = remotePeerId;
|
|
1336
1390
|
this._remotePeerId = info.id;
|
|
1337
|
-
(0,
|
|
1391
|
+
(0, import_log3.log)("onStartReplication", {
|
|
1338
1392
|
id: info.id,
|
|
1339
1393
|
thisPeerId: this.peerId,
|
|
1340
1394
|
remotePeerId: remotePeerId.toHex()
|
|
1341
1395
|
}, {
|
|
1342
1396
|
F: __dxlog_file5,
|
|
1343
|
-
L:
|
|
1397
|
+
L: 192,
|
|
1344
1398
|
S: this,
|
|
1345
1399
|
C: (f, a) => f(...a)
|
|
1346
1400
|
});
|
|
@@ -1350,7 +1404,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1350
1404
|
if (!this._isEnabled) {
|
|
1351
1405
|
return;
|
|
1352
1406
|
}
|
|
1353
|
-
const message =
|
|
1407
|
+
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1354
1408
|
readableStreamController.enqueue(message);
|
|
1355
1409
|
},
|
|
1356
1410
|
onClose: async () => {
|
|
@@ -1362,9 +1416,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1362
1416
|
});
|
|
1363
1417
|
}
|
|
1364
1418
|
get peerId() {
|
|
1365
|
-
(0,
|
|
1419
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1366
1420
|
F: __dxlog_file5,
|
|
1367
|
-
L:
|
|
1421
|
+
L: 215,
|
|
1368
1422
|
S: this,
|
|
1369
1423
|
A: [
|
|
1370
1424
|
"this._remotePeerId != null",
|
|
@@ -1381,9 +1435,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1381
1435
|
* Call after the remote peer has connected.
|
|
1382
1436
|
*/
|
|
1383
1437
|
async enable() {
|
|
1384
|
-
(0,
|
|
1438
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1385
1439
|
F: __dxlog_file5,
|
|
1386
|
-
L:
|
|
1440
|
+
L: 228,
|
|
1387
1441
|
S: this,
|
|
1388
1442
|
A: [
|
|
1389
1443
|
"this._remotePeerId != null",
|
|
@@ -1405,6 +1459,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1405
1459
|
AuthStatus,
|
|
1406
1460
|
AutomergeDocumentLoaderImpl,
|
|
1407
1461
|
AutomergeHost,
|
|
1462
|
+
CredentialRetrieverExtension,
|
|
1463
|
+
CredentialServerExtension,
|
|
1408
1464
|
DataServiceImpl,
|
|
1409
1465
|
LevelDBStorageAdapter,
|
|
1410
1466
|
LocalHostNetworkAdapter,
|