@dxos/echo-pipeline 0.5.9-main.bdf733d → 0.5.9-main.bf3bb8f
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 +272 -299
- package/dist/lib/browser/index.mjs.map +4 -4
- 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 +321 -343
- package/dist/lib/node/index.cjs.map +4 -4
- 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 -10
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +8 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +0 -1
- package/dist/types/src/automerge/index.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 +33 -22
- package/src/automerge/automerge-host.ts +104 -53
- package/src/automerge/echo-network-adapter.ts +30 -8
- package/src/automerge/echo-replicator.ts +2 -0
- package/src/automerge/index.ts +0 -1
- package/src/automerge/mesh-echo-replicator.ts +10 -3
- package/src/automerge/storage-adapter.test.ts +103 -139
- 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/src/space/space-protocol.test.ts +2 -0
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
- package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
- package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
- package/dist/types/src/automerge/migrations.d.ts +0 -7
- package/dist/types/src/automerge/migrations.d.ts.map +0 -1
- package/src/automerge/automerge-storage-adapter.ts +0 -103
- package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
- package/src/automerge/migrations.ts +0 -42
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,76 +18,73 @@ 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
|
-
|
|
26
|
-
|
|
25
|
+
CredentialRetrieverExtension: () => import_chunk_Y5U7UXEL.CredentialRetrieverExtension,
|
|
26
|
+
CredentialServerExtension: () => import_chunk_Y5U7UXEL.CredentialServerExtension,
|
|
27
|
+
DataServiceImpl: () => import_chunk_Y5U7UXEL.DataServiceImpl,
|
|
27
28
|
LevelDBStorageAdapter: () => LevelDBStorageAdapter,
|
|
28
29
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
29
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
30
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
30
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_Y5U7UXEL.MOCK_AUTH_PROVIDER,
|
|
31
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_Y5U7UXEL.MOCK_AUTH_VERIFIER,
|
|
31
32
|
MeshEchoReplicator: () => MeshEchoReplicator,
|
|
32
|
-
MetadataStore: () =>
|
|
33
|
-
Pipeline: () =>
|
|
34
|
-
SnapshotManager: () =>
|
|
35
|
-
SnapshotStore: () =>
|
|
36
|
-
Space: () =>
|
|
37
|
-
SpaceManager: () =>
|
|
38
|
-
SpaceProtocol: () =>
|
|
39
|
-
SpaceProtocolSession: () =>
|
|
40
|
-
TimeframeClock: () =>
|
|
41
|
-
codec: () =>
|
|
42
|
-
createIdFromSpaceKey: () =>
|
|
43
|
-
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,
|
|
44
45
|
encodingOptions: () => encodingOptions,
|
|
45
46
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
46
|
-
hasInvitationExpired: () =>
|
|
47
|
-
mapFeedIndexesToTimeframe: () =>
|
|
48
|
-
mapTimeframeToFeedIndexes: () =>
|
|
49
|
-
startAfter: () =>
|
|
50
|
-
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
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(node_exports);
|
|
53
|
-
var
|
|
54
|
+
var import_chunk_Y5U7UXEL = require("./chunk-Y5U7UXEL.cjs");
|
|
54
55
|
var import_async = require("@dxos/async");
|
|
55
56
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
56
57
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
57
58
|
var import_context = require("@dxos/context");
|
|
58
|
-
var import_invariant = require("@dxos/invariant");
|
|
59
59
|
var import_keys = require("@dxos/keys");
|
|
60
|
-
var import_log = require("@dxos/log");
|
|
61
60
|
var import_protocols = require("@dxos/protocols");
|
|
62
61
|
var import_tracing = require("@dxos/tracing");
|
|
63
62
|
var import_util = require("@dxos/util");
|
|
64
63
|
var import_async2 = require("@dxos/async");
|
|
65
64
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
66
65
|
var import_context2 = require("@dxos/context");
|
|
67
|
-
var
|
|
68
|
-
var
|
|
66
|
+
var import_invariant = require("@dxos/invariant");
|
|
67
|
+
var import_log = require("@dxos/log");
|
|
69
68
|
var import_context3 = require("@dxos/context");
|
|
70
69
|
var import_async3 = require("@dxos/async");
|
|
71
70
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
72
71
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
73
|
-
var
|
|
74
|
-
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
75
|
-
var import_log3 = require("@dxos/log");
|
|
76
|
-
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
77
|
-
var import_util2 = require("@dxos/util");
|
|
72
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
78
73
|
var import_async4 = require("@dxos/async");
|
|
74
|
+
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
79
75
|
var import_context4 = require("@dxos/context");
|
|
80
76
|
var import_debug = require("@dxos/debug");
|
|
81
|
-
var
|
|
82
|
-
var
|
|
77
|
+
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
78
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
79
|
+
var import_log2 = require("@dxos/log");
|
|
83
80
|
var import_tracing2 = require("@dxos/tracing");
|
|
84
|
-
var
|
|
81
|
+
var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
|
|
85
82
|
var import_context5 = require("@dxos/context");
|
|
86
|
-
var
|
|
83
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
87
84
|
var import_keys2 = require("@dxos/keys");
|
|
88
|
-
var
|
|
85
|
+
var import_log3 = require("@dxos/log");
|
|
89
86
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
90
|
-
var
|
|
87
|
+
var import_util2 = require("@dxos/util");
|
|
91
88
|
function _ts_decorate(decorators, target, key, desc) {
|
|
92
89
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
93
90
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -120,7 +117,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
120
117
|
}
|
|
121
118
|
connectionEntry.writer.write(message).catch((err) => {
|
|
122
119
|
if (connectionEntry.isOpen) {
|
|
123
|
-
|
|
120
|
+
import_log.log.catch(err, void 0, {
|
|
124
121
|
F: __dxlog_file,
|
|
125
122
|
L: 49,
|
|
126
123
|
S: this,
|
|
@@ -132,7 +129,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
132
129
|
disconnect() {
|
|
133
130
|
}
|
|
134
131
|
async open() {
|
|
135
|
-
(0,
|
|
132
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
|
|
136
133
|
F: __dxlog_file,
|
|
137
134
|
L: 60,
|
|
138
135
|
S: this,
|
|
@@ -142,7 +139,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
142
139
|
]
|
|
143
140
|
});
|
|
144
141
|
this._lifecycleState = import_context2.LifecycleState.OPEN;
|
|
145
|
-
(0,
|
|
142
|
+
(0, import_log.log)("emit ready", void 0, {
|
|
146
143
|
F: __dxlog_file,
|
|
147
144
|
L: 63,
|
|
148
145
|
S: this,
|
|
@@ -153,7 +150,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
153
150
|
});
|
|
154
151
|
}
|
|
155
152
|
async close() {
|
|
156
|
-
(0,
|
|
153
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
157
154
|
F: __dxlog_file,
|
|
158
155
|
L: 71,
|
|
159
156
|
S: this,
|
|
@@ -174,7 +171,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
174
171
|
});
|
|
175
172
|
}
|
|
176
173
|
async addReplicator(replicator) {
|
|
177
|
-
(0,
|
|
174
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
178
175
|
F: __dxlog_file,
|
|
179
176
|
L: 87,
|
|
180
177
|
S: this,
|
|
@@ -183,7 +180,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
183
180
|
""
|
|
184
181
|
]
|
|
185
182
|
});
|
|
186
|
-
(0,
|
|
183
|
+
(0, import_invariant.invariant)(this.peerId, void 0, {
|
|
187
184
|
F: __dxlog_file,
|
|
188
185
|
L: 88,
|
|
189
186
|
S: this,
|
|
@@ -192,7 +189,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
192
189
|
""
|
|
193
190
|
]
|
|
194
191
|
});
|
|
195
|
-
(0,
|
|
192
|
+
(0, import_invariant.invariant)(!this._replicators.has(replicator), void 0, {
|
|
196
193
|
F: __dxlog_file,
|
|
197
194
|
L: 89,
|
|
198
195
|
S: this,
|
|
@@ -206,29 +203,29 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
206
203
|
peerId: this.peerId,
|
|
207
204
|
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
208
205
|
onConnectionClosed: this._onConnectionClosed.bind(this),
|
|
206
|
+
onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
|
|
209
207
|
getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
|
|
210
208
|
});
|
|
211
209
|
}
|
|
212
210
|
async removeReplicator(replicator) {
|
|
213
|
-
(0,
|
|
211
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
214
212
|
F: __dxlog_file,
|
|
215
|
-
L:
|
|
213
|
+
L: 103,
|
|
216
214
|
S: this,
|
|
217
215
|
A: [
|
|
218
216
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
219
217
|
""
|
|
220
218
|
]
|
|
221
219
|
});
|
|
222
|
-
(0,
|
|
220
|
+
(0, import_invariant.invariant)(this._replicators.has(replicator), void 0, {
|
|
223
221
|
F: __dxlog_file,
|
|
224
|
-
L:
|
|
222
|
+
L: 104,
|
|
225
223
|
S: this,
|
|
226
224
|
A: [
|
|
227
225
|
"this._replicators.has(replicator)",
|
|
228
226
|
""
|
|
229
227
|
]
|
|
230
228
|
});
|
|
231
|
-
"";
|
|
232
229
|
await replicator.disconnect();
|
|
233
230
|
this._replicators.delete(replicator);
|
|
234
231
|
}
|
|
@@ -240,7 +237,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
240
237
|
return connection.connection.shouldAdvertize(params);
|
|
241
238
|
}
|
|
242
239
|
_onConnectionOpen(connection) {
|
|
243
|
-
(0,
|
|
240
|
+
(0, import_log.log)("Connection opened", {
|
|
244
241
|
peerId: connection.peerId
|
|
245
242
|
}, {
|
|
246
243
|
F: __dxlog_file,
|
|
@@ -248,7 +245,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
248
245
|
S: this,
|
|
249
246
|
C: (f, a) => f(...a)
|
|
250
247
|
});
|
|
251
|
-
(0,
|
|
248
|
+
(0, import_invariant.invariant)(!this._connections.has(connection.peerId), void 0, {
|
|
252
249
|
F: __dxlog_file,
|
|
253
250
|
L: 120,
|
|
254
251
|
S: this,
|
|
@@ -277,7 +274,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
277
274
|
}
|
|
278
275
|
} catch (err) {
|
|
279
276
|
if (connectionEntry.isOpen) {
|
|
280
|
-
|
|
277
|
+
import_log.log.catch(err, void 0, {
|
|
281
278
|
F: __dxlog_file,
|
|
282
279
|
L: 139,
|
|
283
280
|
S: this,
|
|
@@ -286,7 +283,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
286
283
|
}
|
|
287
284
|
}
|
|
288
285
|
});
|
|
289
|
-
(0,
|
|
286
|
+
(0, import_log.log)("emit peer-candidate", {
|
|
290
287
|
peerId: connection.peerId
|
|
291
288
|
}, {
|
|
292
289
|
F: __dxlog_file,
|
|
@@ -294,27 +291,49 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
294
291
|
S: this,
|
|
295
292
|
C: (f, a) => f(...a)
|
|
296
293
|
});
|
|
297
|
-
this.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
294
|
+
this._emitPeerCandidate(connection);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
|
|
298
|
+
* TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
|
|
299
|
+
*/
|
|
300
|
+
_onConnectionAuthScopeChanged(connection) {
|
|
301
|
+
(0, import_log.log)("Connection auth scope changed", {
|
|
302
|
+
peerId: connection.peerId
|
|
303
|
+
}, {
|
|
304
|
+
F: __dxlog_file,
|
|
305
|
+
L: 153,
|
|
306
|
+
S: this,
|
|
307
|
+
C: (f, a) => f(...a)
|
|
308
|
+
});
|
|
309
|
+
const entry = this._connections.get(connection.peerId);
|
|
310
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
311
|
+
F: __dxlog_file,
|
|
312
|
+
L: 155,
|
|
313
|
+
S: this,
|
|
314
|
+
A: [
|
|
315
|
+
"entry",
|
|
316
|
+
""
|
|
317
|
+
]
|
|
318
|
+
});
|
|
319
|
+
this.emit("peer-disconnected", {
|
|
320
|
+
peerId: connection.peerId
|
|
303
321
|
});
|
|
322
|
+
this._emitPeerCandidate(connection);
|
|
304
323
|
}
|
|
305
324
|
_onConnectionClosed(connection) {
|
|
306
|
-
(0,
|
|
325
|
+
(0, import_log.log)("Connection closed", {
|
|
307
326
|
peerId: connection.peerId
|
|
308
327
|
}, {
|
|
309
328
|
F: __dxlog_file,
|
|
310
|
-
L:
|
|
329
|
+
L: 161,
|
|
311
330
|
S: this,
|
|
312
331
|
C: (f, a) => f(...a)
|
|
313
332
|
});
|
|
314
333
|
const entry = this._connections.get(connection.peerId);
|
|
315
|
-
(0,
|
|
334
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
316
335
|
F: __dxlog_file,
|
|
317
|
-
L:
|
|
336
|
+
L: 163,
|
|
318
337
|
S: this,
|
|
319
338
|
A: [
|
|
320
339
|
"entry",
|
|
@@ -325,20 +344,26 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
325
344
|
this.emit("peer-disconnected", {
|
|
326
345
|
peerId: connection.peerId
|
|
327
346
|
});
|
|
328
|
-
void entry.reader.cancel().catch((err) =>
|
|
347
|
+
void entry.reader.cancel().catch((err) => import_log.log.catch(err, void 0, {
|
|
329
348
|
F: __dxlog_file,
|
|
330
|
-
L:
|
|
349
|
+
L: 168,
|
|
331
350
|
S: this,
|
|
332
351
|
C: (f, a) => f(...a)
|
|
333
352
|
}));
|
|
334
|
-
void entry.writer.abort().catch((err) =>
|
|
353
|
+
void entry.writer.abort().catch((err) => import_log.log.catch(err, void 0, {
|
|
335
354
|
F: __dxlog_file,
|
|
336
|
-
L:
|
|
355
|
+
L: 169,
|
|
337
356
|
S: this,
|
|
338
357
|
C: (f, a) => f(...a)
|
|
339
358
|
}));
|
|
340
359
|
this._connections.delete(connection.peerId);
|
|
341
360
|
}
|
|
361
|
+
_emitPeerCandidate(connection) {
|
|
362
|
+
this.emit("peer-candidate", {
|
|
363
|
+
peerId: connection.peerId,
|
|
364
|
+
peerMetadata: createEchoPeerMetadata()
|
|
365
|
+
});
|
|
366
|
+
}
|
|
342
367
|
};
|
|
343
368
|
_ts_decorate([
|
|
344
369
|
import_async2.synchronized
|
|
@@ -352,6 +377,11 @@ _ts_decorate([
|
|
|
352
377
|
_ts_decorate([
|
|
353
378
|
import_async2.synchronized
|
|
354
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";
|
|
355
385
|
var LevelDBStorageAdapter = class extends import_context3.Resource {
|
|
356
386
|
constructor(_params) {
|
|
357
387
|
super();
|
|
@@ -473,7 +503,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
473
503
|
}
|
|
474
504
|
send(message) {
|
|
475
505
|
const peer = this._peers.get(message.targetId);
|
|
476
|
-
(0,
|
|
506
|
+
(0, import_invariant2.invariant)(peer, "Peer not found.", {
|
|
477
507
|
F: __dxlog_file2,
|
|
478
508
|
L: 51,
|
|
479
509
|
S: this,
|
|
@@ -498,7 +528,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
498
528
|
syncRepo({ id, syncMessage }) {
|
|
499
529
|
const peerId = this._getPeerId(id);
|
|
500
530
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
501
|
-
(0,
|
|
531
|
+
(0, import_invariant2.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
502
532
|
F: __dxlog_file2,
|
|
503
533
|
L: 73,
|
|
504
534
|
S: this,
|
|
@@ -522,7 +552,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
522
552
|
});
|
|
523
553
|
}
|
|
524
554
|
});
|
|
525
|
-
(0,
|
|
555
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
526
556
|
F: __dxlog_file2,
|
|
527
557
|
L: 90,
|
|
528
558
|
S: this,
|
|
@@ -538,7 +568,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
538
568
|
});
|
|
539
569
|
}
|
|
540
570
|
async sendSyncMessage({ id, syncMessage }) {
|
|
541
|
-
(0,
|
|
571
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
542
572
|
F: __dxlog_file2,
|
|
543
573
|
L: 99,
|
|
544
574
|
S: this,
|
|
@@ -551,7 +581,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
551
581
|
this.emit("message", message);
|
|
552
582
|
}
|
|
553
583
|
async getHostInfo() {
|
|
554
|
-
(0,
|
|
584
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
555
585
|
F: __dxlog_file2,
|
|
556
586
|
L: 105,
|
|
557
587
|
S: this,
|
|
@@ -560,7 +590,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
560
590
|
""
|
|
561
591
|
]
|
|
562
592
|
});
|
|
563
|
-
(0,
|
|
593
|
+
(0, import_invariant2.invariant)(this.peerId, "Peer id not set.", {
|
|
564
594
|
F: __dxlog_file2,
|
|
565
595
|
L: 106,
|
|
566
596
|
S: this,
|
|
@@ -577,108 +607,6 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
577
607
|
return id;
|
|
578
608
|
}
|
|
579
609
|
};
|
|
580
|
-
var AutomergeStorageAdapter = class {
|
|
581
|
-
constructor(_directory) {
|
|
582
|
-
this._directory = _directory;
|
|
583
|
-
this._state = "opened";
|
|
584
|
-
}
|
|
585
|
-
async load(key) {
|
|
586
|
-
if (this._state !== "opened") {
|
|
587
|
-
return void 0;
|
|
588
|
-
}
|
|
589
|
-
const filename = this._getFilename(key);
|
|
590
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
591
|
-
const { size } = await file.stat();
|
|
592
|
-
if (!size || size === 0) {
|
|
593
|
-
return void 0;
|
|
594
|
-
}
|
|
595
|
-
const buffer = await file.read(0, size);
|
|
596
|
-
return (0, import_util2.bufferToArray)(buffer);
|
|
597
|
-
}
|
|
598
|
-
async save(key, data) {
|
|
599
|
-
if (this._state !== "opened") {
|
|
600
|
-
return void 0;
|
|
601
|
-
}
|
|
602
|
-
const filename = this._getFilename(key);
|
|
603
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
604
|
-
await file.write(0, (0, import_util2.arrayToBuffer)(data));
|
|
605
|
-
await file.truncate?.(data.length);
|
|
606
|
-
await file.flush?.();
|
|
607
|
-
}
|
|
608
|
-
async remove(key) {
|
|
609
|
-
if (this._state !== "opened") {
|
|
610
|
-
return void 0;
|
|
611
|
-
}
|
|
612
|
-
const filename = this._getFilename(key);
|
|
613
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
614
|
-
await file.destroy();
|
|
615
|
-
}
|
|
616
|
-
async loadRange(keyPrefix) {
|
|
617
|
-
if (this._state !== "opened") {
|
|
618
|
-
return [];
|
|
619
|
-
}
|
|
620
|
-
const filename = this._getFilename(keyPrefix);
|
|
621
|
-
const entries = await this._directory.list();
|
|
622
|
-
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
623
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
624
|
-
const { size } = await file.stat();
|
|
625
|
-
const buffer = await file.read(0, size);
|
|
626
|
-
return {
|
|
627
|
-
key: this._getKeyFromFilename(entry),
|
|
628
|
-
data: (0, import_util2.bufferToArray)(buffer)
|
|
629
|
-
};
|
|
630
|
-
}));
|
|
631
|
-
}
|
|
632
|
-
async removeRange(keyPrefix) {
|
|
633
|
-
if (this._state !== "opened") {
|
|
634
|
-
return void 0;
|
|
635
|
-
}
|
|
636
|
-
const filename = this._getFilename(keyPrefix);
|
|
637
|
-
const entries = await this._directory.list();
|
|
638
|
-
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
639
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
640
|
-
await file.destroy();
|
|
641
|
-
}));
|
|
642
|
-
}
|
|
643
|
-
async close() {
|
|
644
|
-
this._state = "closed";
|
|
645
|
-
}
|
|
646
|
-
_getFilename(key) {
|
|
647
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
648
|
-
}
|
|
649
|
-
_getKeyFromFilename(filename) {
|
|
650
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
654
|
-
var levelMigration = async ({ db, directory }) => {
|
|
655
|
-
const isNewLevel = !await db.iterator({
|
|
656
|
-
...encodingOptions
|
|
657
|
-
}).next();
|
|
658
|
-
if (!isNewLevel) {
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
const oldStorageAdapter = directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
662
|
-
const chunks = await oldStorageAdapter.loadRange([]);
|
|
663
|
-
if (chunks.length === 0) {
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
const batch = db.batch();
|
|
667
|
-
import_log3.log.info("found chunks on old storage adapter", {
|
|
668
|
-
chunks: chunks.length
|
|
669
|
-
}, {
|
|
670
|
-
F: __dxlog_file3,
|
|
671
|
-
L: 37,
|
|
672
|
-
S: void 0,
|
|
673
|
-
C: (f, a) => f(...a)
|
|
674
|
-
});
|
|
675
|
-
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
676
|
-
data && batch.put(key, data, {
|
|
677
|
-
...encodingOptions
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
await batch.write();
|
|
681
|
-
};
|
|
682
610
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
683
611
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
684
612
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -689,31 +617,27 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
689
617
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
690
618
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
691
619
|
}
|
|
692
|
-
var
|
|
620
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
693
621
|
var AutomergeHost = class {
|
|
694
|
-
constructor({
|
|
695
|
-
this._ctx = new import_context.Context(
|
|
622
|
+
constructor({ db, indexMetadataStore }) {
|
|
623
|
+
this._ctx = new import_context.Context(void 0, {
|
|
624
|
+
F: __dxlog_file3,
|
|
625
|
+
L: 71
|
|
626
|
+
});
|
|
696
627
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
697
628
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
698
629
|
});
|
|
699
|
-
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
700
|
-
this._directory = directory;
|
|
701
|
-
this._db = db;
|
|
702
|
-
this._indexMetadataStore = indexMetadataStore;
|
|
703
|
-
}
|
|
704
|
-
async open() {
|
|
705
|
-
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
706
|
-
this._directory && await levelMigration({
|
|
707
|
-
db: this._db,
|
|
708
|
-
directory: this._directory
|
|
709
|
-
});
|
|
710
630
|
this._storage = new LevelDBStorageAdapter({
|
|
711
|
-
db
|
|
631
|
+
db,
|
|
712
632
|
callbacks: {
|
|
713
633
|
beforeSave: async (params) => this._beforeSave(params),
|
|
714
634
|
afterSave: async () => this._afterSave()
|
|
715
635
|
}
|
|
716
636
|
});
|
|
637
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
638
|
+
}
|
|
639
|
+
async open() {
|
|
640
|
+
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
717
641
|
await this._storage.open?.();
|
|
718
642
|
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
719
643
|
this._repo = new import_automerge_repo.Repo({
|
|
@@ -738,6 +662,9 @@ var AutomergeHost = class {
|
|
|
738
662
|
await this._echoNetworkAdapter.close();
|
|
739
663
|
await this._ctx.dispose();
|
|
740
664
|
}
|
|
665
|
+
/**
|
|
666
|
+
* @deprecated To be abstracted away.
|
|
667
|
+
*/
|
|
741
668
|
get repo() {
|
|
742
669
|
return this._repo;
|
|
743
670
|
}
|
|
@@ -747,6 +674,39 @@ var AutomergeHost = class {
|
|
|
747
674
|
async removeReplicator(replicator) {
|
|
748
675
|
await this._echoNetworkAdapter.removeReplicator(replicator);
|
|
749
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
|
+
}
|
|
750
710
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
751
711
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
752
712
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -758,23 +718,8 @@ var AutomergeHost = class {
|
|
|
758
718
|
if (!documentId) {
|
|
759
719
|
return false;
|
|
760
720
|
}
|
|
761
|
-
const doc = this._repo.handles[documentId]?.docSync();
|
|
762
|
-
if (!doc) {
|
|
763
|
-
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
764
|
-
(0, import_log.log)("doc share policy check", {
|
|
765
|
-
peerId,
|
|
766
|
-
documentId,
|
|
767
|
-
isRequested
|
|
768
|
-
}, {
|
|
769
|
-
F: __dxlog_file4,
|
|
770
|
-
L: 156,
|
|
771
|
-
S: this,
|
|
772
|
-
C: (f, a) => f(...a)
|
|
773
|
-
});
|
|
774
|
-
return isRequested;
|
|
775
|
-
}
|
|
776
721
|
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
777
|
-
if (peerMetadata
|
|
722
|
+
if (isEchoPeerMetadata(peerMetadata)) {
|
|
778
723
|
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
779
724
|
documentId
|
|
780
725
|
});
|
|
@@ -846,31 +791,36 @@ var AutomergeHost = class {
|
|
|
846
791
|
}
|
|
847
792
|
return import_keys.PublicKey.from(spaceKeyHex);
|
|
848
793
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
794
|
+
/**
|
|
795
|
+
* Flush documents to disk.
|
|
796
|
+
*/
|
|
852
797
|
async flush({ states }) {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
});
|
|
863
|
-
const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
|
|
864
|
-
await waitForHeads(handle, heads);
|
|
865
|
-
}) ?? []);
|
|
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
|
+
}
|
|
866
807
|
await this._repo.flush(states?.map(({ documentId }) => documentId));
|
|
867
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Host <-> Client sync.
|
|
811
|
+
*/
|
|
868
812
|
syncRepo(request) {
|
|
869
813
|
return this._clientNetwork.syncRepo(request);
|
|
870
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Host <-> Client sync.
|
|
817
|
+
*/
|
|
871
818
|
sendSyncMessage(request) {
|
|
872
819
|
return this._clientNetwork.sendSyncMessage(request);
|
|
873
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Host <-> Client sync.
|
|
823
|
+
*/
|
|
874
824
|
async getHostInfo() {
|
|
875
825
|
return this._clientNetwork.getHostInfo();
|
|
876
826
|
}
|
|
@@ -931,7 +881,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
931
881
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
932
882
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
933
883
|
}
|
|
934
|
-
var
|
|
884
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
935
885
|
var AutomergeDocumentLoaderImpl = class {
|
|
936
886
|
constructor(_spaceId, _repo, _spaceKey) {
|
|
937
887
|
this._spaceId = _spaceId;
|
|
@@ -953,32 +903,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
953
903
|
return;
|
|
954
904
|
}
|
|
955
905
|
if (!spaceState.rootUrl) {
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
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);
|
|
981
930
|
}
|
|
931
|
+
this._spaceRootDocHandle = existingDocHandle;
|
|
982
932
|
}
|
|
983
933
|
loadObjectDocument(objectIdOrMany) {
|
|
984
934
|
const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
|
|
@@ -987,9 +937,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
987
937
|
let hasUrlsToLoad = false;
|
|
988
938
|
const urlsToLoad = {};
|
|
989
939
|
for (const objectId of objectIds) {
|
|
990
|
-
(0,
|
|
991
|
-
F:
|
|
992
|
-
L:
|
|
940
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
941
|
+
F: __dxlog_file4,
|
|
942
|
+
L: 97,
|
|
993
943
|
S: this,
|
|
994
944
|
A: [
|
|
995
945
|
"this._spaceRootDocHandle",
|
|
@@ -1000,9 +950,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1000
950
|
continue;
|
|
1001
951
|
}
|
|
1002
952
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1003
|
-
(0,
|
|
1004
|
-
F:
|
|
1005
|
-
L:
|
|
953
|
+
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
954
|
+
F: __dxlog_file4,
|
|
955
|
+
L: 102,
|
|
1006
956
|
S: this,
|
|
1007
957
|
A: [
|
|
1008
958
|
"spaceRootDoc",
|
|
@@ -1012,11 +962,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1012
962
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
1013
963
|
if (documentUrl == null) {
|
|
1014
964
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
1015
|
-
|
|
965
|
+
import_log2.log.info("loading delayed until object links are initialized", {
|
|
1016
966
|
objectId
|
|
1017
967
|
}, {
|
|
1018
|
-
F:
|
|
1019
|
-
L:
|
|
968
|
+
F: __dxlog_file4,
|
|
969
|
+
L: 106,
|
|
1020
970
|
S: this,
|
|
1021
971
|
C: (f, a) => f(...a)
|
|
1022
972
|
});
|
|
@@ -1029,6 +979,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1029
979
|
this._loadLinkedObjects(urlsToLoad);
|
|
1030
980
|
}
|
|
1031
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
|
+
}
|
|
1032
1008
|
onObjectLinksUpdated(links) {
|
|
1033
1009
|
if (!links) {
|
|
1034
1010
|
return;
|
|
@@ -1038,9 +1014,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1038
1014
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
1039
1015
|
}
|
|
1040
1016
|
getSpaceRootDocHandle() {
|
|
1041
|
-
(0,
|
|
1042
|
-
F:
|
|
1043
|
-
L:
|
|
1017
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1018
|
+
F: __dxlog_file4,
|
|
1019
|
+
L: 140,
|
|
1044
1020
|
S: this,
|
|
1045
1021
|
A: [
|
|
1046
1022
|
"this._spaceRootDocHandle",
|
|
@@ -1050,16 +1026,18 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1050
1026
|
return this._spaceRootDocHandle;
|
|
1051
1027
|
}
|
|
1052
1028
|
createDocumentForObject(objectId) {
|
|
1053
|
-
(0,
|
|
1054
|
-
F:
|
|
1055
|
-
L:
|
|
1029
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
1030
|
+
F: __dxlog_file4,
|
|
1031
|
+
L: 145,
|
|
1056
1032
|
S: this,
|
|
1057
1033
|
A: [
|
|
1058
1034
|
"this._spaceRootDocHandle",
|
|
1059
1035
|
""
|
|
1060
1036
|
]
|
|
1061
1037
|
});
|
|
1062
|
-
const spaceDocHandle = this._repo.create(
|
|
1038
|
+
const spaceDocHandle = this._repo.create({
|
|
1039
|
+
version: import_echo_protocol.SpaceDocVersion.CURRENT
|
|
1040
|
+
});
|
|
1063
1041
|
this._initDocAccess(spaceDocHandle);
|
|
1064
1042
|
this.onObjectBoundToDocument(spaceDocHandle, objectId);
|
|
1065
1043
|
this._spaceRootDocHandle.change((newDoc) => {
|
|
@@ -1090,30 +1068,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1090
1068
|
};
|
|
1091
1069
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
1092
1070
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
1093
|
-
|
|
1071
|
+
import_log2.log.warn("object already inlined in a different document, ignoring the link", {
|
|
1094
1072
|
...logMeta,
|
|
1095
1073
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1096
1074
|
}, {
|
|
1097
|
-
F:
|
|
1098
|
-
L:
|
|
1075
|
+
F: __dxlog_file4,
|
|
1076
|
+
L: 177,
|
|
1099
1077
|
S: this,
|
|
1100
1078
|
C: (f, a) => f(...a)
|
|
1101
1079
|
});
|
|
1102
1080
|
continue;
|
|
1103
1081
|
}
|
|
1104
1082
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1105
|
-
|
|
1106
|
-
F:
|
|
1107
|
-
L:
|
|
1083
|
+
import_log2.log.warn("object document was already loaded", logMeta, {
|
|
1084
|
+
F: __dxlog_file4,
|
|
1085
|
+
L: 184,
|
|
1108
1086
|
S: this,
|
|
1109
1087
|
C: (f, a) => f(...a)
|
|
1110
1088
|
});
|
|
1111
1089
|
continue;
|
|
1112
1090
|
}
|
|
1113
1091
|
const handle = this._repo.find(automergeUrl);
|
|
1114
|
-
|
|
1115
|
-
F:
|
|
1116
|
-
L:
|
|
1092
|
+
import_log2.log.debug("document loading triggered", logMeta, {
|
|
1093
|
+
F: __dxlog_file4,
|
|
1094
|
+
L: 188,
|
|
1117
1095
|
S: this,
|
|
1118
1096
|
C: (f, a) => f(...a)
|
|
1119
1097
|
});
|
|
@@ -1131,12 +1109,12 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1131
1109
|
break;
|
|
1132
1110
|
} catch (err) {
|
|
1133
1111
|
if (`${err}`.includes("Timeout")) {
|
|
1134
|
-
|
|
1112
|
+
import_log2.log.info("wraparound", {
|
|
1135
1113
|
id: docHandle.documentId,
|
|
1136
1114
|
state: docHandle.state
|
|
1137
1115
|
}, {
|
|
1138
|
-
F:
|
|
1139
|
-
L:
|
|
1116
|
+
F: __dxlog_file4,
|
|
1117
|
+
L: 204,
|
|
1140
1118
|
S: this,
|
|
1141
1119
|
C: (f, a) => f(...a)
|
|
1142
1120
|
});
|
|
@@ -1150,14 +1128,6 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1150
1128
|
}
|
|
1151
1129
|
return docHandle;
|
|
1152
1130
|
}
|
|
1153
|
-
_createContextBoundSpaceRootDocument(ctx) {
|
|
1154
|
-
const docHandle = this._repo.create();
|
|
1155
|
-
this._spaceRootDocHandle = docHandle;
|
|
1156
|
-
ctx.onDispose(() => {
|
|
1157
|
-
docHandle.delete();
|
|
1158
|
-
this._spaceRootDocHandle = null;
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
1131
|
_initDocAccess(handle) {
|
|
1162
1132
|
handle.change((newDoc) => {
|
|
1163
1133
|
newDoc.access ??= {
|
|
@@ -1176,9 +1146,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1176
1146
|
docUrl: handle.url
|
|
1177
1147
|
};
|
|
1178
1148
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1179
|
-
|
|
1180
|
-
F:
|
|
1181
|
-
L:
|
|
1149
|
+
import_log2.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1150
|
+
F: __dxlog_file4,
|
|
1151
|
+
L: 231,
|
|
1182
1152
|
S: this,
|
|
1183
1153
|
C: (f, a) => f(...a)
|
|
1184
1154
|
});
|
|
@@ -1186,9 +1156,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1186
1156
|
}
|
|
1187
1157
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
1188
1158
|
if (objectDocHandle?.url !== handle.url) {
|
|
1189
|
-
|
|
1190
|
-
F:
|
|
1191
|
-
L:
|
|
1159
|
+
import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1160
|
+
F: __dxlog_file4,
|
|
1161
|
+
L: 236,
|
|
1192
1162
|
S: this,
|
|
1193
1163
|
C: (f, a) => f(...a)
|
|
1194
1164
|
});
|
|
@@ -1200,14 +1170,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1200
1170
|
});
|
|
1201
1171
|
} catch (err) {
|
|
1202
1172
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1203
|
-
|
|
1173
|
+
import_log2.log.warn("failed to load a document", {
|
|
1204
1174
|
objectId,
|
|
1205
1175
|
automergeUrl: handle.url,
|
|
1206
1176
|
retryLoading: shouldRetryLoading,
|
|
1207
1177
|
err
|
|
1208
1178
|
}, {
|
|
1209
|
-
F:
|
|
1210
|
-
L:
|
|
1179
|
+
F: __dxlog_file4,
|
|
1180
|
+
L: 242,
|
|
1211
1181
|
S: this,
|
|
1212
1182
|
C: (f, a) => f(...a)
|
|
1213
1183
|
});
|
|
@@ -1225,12 +1195,12 @@ _ts_decorate3([
|
|
|
1225
1195
|
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1226
1196
|
import_tracing2.trace.resource()
|
|
1227
1197
|
], AutomergeDocumentLoaderImpl);
|
|
1228
|
-
var
|
|
1198
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
|
|
1229
1199
|
var MeshEchoReplicator = class {
|
|
1230
1200
|
constructor() {
|
|
1231
1201
|
this._connections = /* @__PURE__ */ new Set();
|
|
1232
1202
|
this._connectionsPerPeer = /* @__PURE__ */ new Map();
|
|
1233
|
-
this._authorizedDevices = new
|
|
1203
|
+
this._authorizedDevices = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
|
|
1234
1204
|
this._context = null;
|
|
1235
1205
|
}
|
|
1236
1206
|
async connect(context) {
|
|
@@ -1245,8 +1215,8 @@ var MeshEchoReplicator = class {
|
|
|
1245
1215
|
this._context = null;
|
|
1246
1216
|
}
|
|
1247
1217
|
createExtension() {
|
|
1248
|
-
(0,
|
|
1249
|
-
F:
|
|
1218
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1219
|
+
F: __dxlog_file5,
|
|
1250
1220
|
L: 54,
|
|
1251
1221
|
S: this,
|
|
1252
1222
|
A: [
|
|
@@ -1257,16 +1227,16 @@ var MeshEchoReplicator = class {
|
|
|
1257
1227
|
const connection = new MeshReplicatorConnection({
|
|
1258
1228
|
ownPeerId: this._context.peerId,
|
|
1259
1229
|
onRemoteConnected: async () => {
|
|
1260
|
-
(0,
|
|
1230
|
+
(0, import_log3.log)("onRemoteConnected", {
|
|
1261
1231
|
peerId: connection.peerId
|
|
1262
1232
|
}, {
|
|
1263
|
-
F:
|
|
1233
|
+
F: __dxlog_file5,
|
|
1264
1234
|
L: 59,
|
|
1265
1235
|
S: this,
|
|
1266
1236
|
C: (f, a) => f(...a)
|
|
1267
1237
|
});
|
|
1268
|
-
(0,
|
|
1269
|
-
F:
|
|
1238
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1239
|
+
F: __dxlog_file5,
|
|
1270
1240
|
L: 60,
|
|
1271
1241
|
S: this,
|
|
1272
1242
|
A: [
|
|
@@ -1274,39 +1244,41 @@ var MeshEchoReplicator = class {
|
|
|
1274
1244
|
""
|
|
1275
1245
|
]
|
|
1276
1246
|
});
|
|
1277
|
-
if (
|
|
1247
|
+
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
1248
|
+
this._context.onConnectionAuthScopeChanged(connection);
|
|
1249
|
+
} else {
|
|
1278
1250
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1279
|
-
await connection.enable();
|
|
1280
1251
|
this._context.onConnectionOpen(connection);
|
|
1252
|
+
await connection.enable();
|
|
1281
1253
|
}
|
|
1282
1254
|
},
|
|
1283
1255
|
onRemoteDisconnected: async () => {
|
|
1284
|
-
(0,
|
|
1256
|
+
(0, import_log3.log)("onRemoteDisconnected", {
|
|
1285
1257
|
peerId: connection.peerId
|
|
1286
1258
|
}, {
|
|
1287
|
-
F:
|
|
1288
|
-
L:
|
|
1259
|
+
F: __dxlog_file5,
|
|
1260
|
+
L: 71,
|
|
1289
1261
|
S: this,
|
|
1290
1262
|
C: (f, a) => f(...a)
|
|
1291
1263
|
});
|
|
1292
1264
|
this._context?.onConnectionClosed(connection);
|
|
1293
|
-
await connection.disable();
|
|
1294
1265
|
this._connectionsPerPeer.delete(connection.peerId);
|
|
1266
|
+
await connection.disable();
|
|
1295
1267
|
this._connections.delete(connection);
|
|
1296
1268
|
},
|
|
1297
1269
|
shouldAdvertize: async (params) => {
|
|
1298
|
-
(0,
|
|
1270
|
+
(0, import_log3.log)("shouldAdvertize", {
|
|
1299
1271
|
peerId: connection.peerId,
|
|
1300
1272
|
documentId: params.documentId
|
|
1301
1273
|
}, {
|
|
1302
|
-
F:
|
|
1303
|
-
L:
|
|
1274
|
+
F: __dxlog_file5,
|
|
1275
|
+
L: 78,
|
|
1304
1276
|
S: this,
|
|
1305
1277
|
C: (f, a) => f(...a)
|
|
1306
1278
|
});
|
|
1307
|
-
(0,
|
|
1308
|
-
F:
|
|
1309
|
-
L:
|
|
1279
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1280
|
+
F: __dxlog_file5,
|
|
1281
|
+
L: 79,
|
|
1310
1282
|
S: this,
|
|
1311
1283
|
A: [
|
|
1312
1284
|
"this._context",
|
|
@@ -1316,12 +1288,12 @@ var MeshEchoReplicator = class {
|
|
|
1316
1288
|
try {
|
|
1317
1289
|
const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
|
|
1318
1290
|
if (!spaceKey) {
|
|
1319
|
-
(0,
|
|
1291
|
+
(0, import_log3.log)("space key not found for share policy check", {
|
|
1320
1292
|
peerId: connection.peerId,
|
|
1321
1293
|
documentId: params.documentId
|
|
1322
1294
|
}, {
|
|
1323
|
-
F:
|
|
1324
|
-
L:
|
|
1295
|
+
F: __dxlog_file5,
|
|
1296
|
+
L: 83,
|
|
1325
1297
|
S: this,
|
|
1326
1298
|
C: (f, a) => f(...a)
|
|
1327
1299
|
});
|
|
@@ -1329,19 +1301,19 @@ var MeshEchoReplicator = class {
|
|
|
1329
1301
|
}
|
|
1330
1302
|
const authorizedDevices = this._authorizedDevices.get(spaceKey);
|
|
1331
1303
|
if (!connection.remoteDeviceKey) {
|
|
1332
|
-
(0,
|
|
1304
|
+
(0, import_log3.log)("device key not found for share policy check", {
|
|
1333
1305
|
peerId: connection.peerId,
|
|
1334
1306
|
documentId: params.documentId
|
|
1335
1307
|
}, {
|
|
1336
|
-
F:
|
|
1337
|
-
L:
|
|
1308
|
+
F: __dxlog_file5,
|
|
1309
|
+
L: 93,
|
|
1338
1310
|
S: this,
|
|
1339
1311
|
C: (f, a) => f(...a)
|
|
1340
1312
|
});
|
|
1341
1313
|
return false;
|
|
1342
1314
|
}
|
|
1343
1315
|
const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
|
|
1344
|
-
(0,
|
|
1316
|
+
(0, import_log3.log)("share policy check", {
|
|
1345
1317
|
localPeer: this._context.peerId,
|
|
1346
1318
|
remotePeer: connection.peerId,
|
|
1347
1319
|
documentId: params.documentId,
|
|
@@ -1349,16 +1321,16 @@ var MeshEchoReplicator = class {
|
|
|
1349
1321
|
spaceKey,
|
|
1350
1322
|
isAuthorized
|
|
1351
1323
|
}, {
|
|
1352
|
-
F:
|
|
1353
|
-
L:
|
|
1324
|
+
F: __dxlog_file5,
|
|
1325
|
+
L: 101,
|
|
1354
1326
|
S: this,
|
|
1355
1327
|
C: (f, a) => f(...a)
|
|
1356
1328
|
});
|
|
1357
1329
|
return isAuthorized;
|
|
1358
1330
|
} catch (err) {
|
|
1359
|
-
|
|
1360
|
-
F:
|
|
1361
|
-
L:
|
|
1331
|
+
import_log3.log.catch(err, void 0, {
|
|
1332
|
+
F: __dxlog_file5,
|
|
1333
|
+
L: 111,
|
|
1362
1334
|
S: this,
|
|
1363
1335
|
C: (f, a) => f(...a)
|
|
1364
1336
|
});
|
|
@@ -1370,16 +1342,21 @@ var MeshEchoReplicator = class {
|
|
|
1370
1342
|
return connection.replicatorExtension;
|
|
1371
1343
|
}
|
|
1372
1344
|
authorizeDevice(spaceKey, deviceKey) {
|
|
1373
|
-
(0,
|
|
1345
|
+
(0, import_log3.log)("authorizeDevice", {
|
|
1374
1346
|
spaceKey,
|
|
1375
1347
|
deviceKey
|
|
1376
1348
|
}, {
|
|
1377
|
-
F:
|
|
1378
|
-
L:
|
|
1349
|
+
F: __dxlog_file5,
|
|
1350
|
+
L: 122,
|
|
1379
1351
|
S: this,
|
|
1380
1352
|
C: (f, a) => f(...a)
|
|
1381
1353
|
});
|
|
1382
|
-
(0,
|
|
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
|
+
}
|
|
1383
1360
|
}
|
|
1384
1361
|
};
|
|
1385
1362
|
var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
@@ -1399,7 +1376,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1399
1376
|
this.writable = new WritableStream({
|
|
1400
1377
|
write: async (message, controller) => {
|
|
1401
1378
|
this.replicatorExtension.sendSyncMessage({
|
|
1402
|
-
payload:
|
|
1379
|
+
payload: import_automerge_repo5.cbor.encode(message)
|
|
1403
1380
|
}).catch((err) => {
|
|
1404
1381
|
controller.error(err);
|
|
1405
1382
|
});
|
|
@@ -1411,13 +1388,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1411
1388
|
onStartReplication: async (info, remotePeerId) => {
|
|
1412
1389
|
this.remoteDeviceKey = remotePeerId;
|
|
1413
1390
|
this._remotePeerId = info.id;
|
|
1414
|
-
(0,
|
|
1391
|
+
(0, import_log3.log)("onStartReplication", {
|
|
1415
1392
|
id: info.id,
|
|
1416
1393
|
thisPeerId: this.peerId,
|
|
1417
1394
|
remotePeerId: remotePeerId.toHex()
|
|
1418
1395
|
}, {
|
|
1419
|
-
F:
|
|
1420
|
-
L:
|
|
1396
|
+
F: __dxlog_file5,
|
|
1397
|
+
L: 192,
|
|
1421
1398
|
S: this,
|
|
1422
1399
|
C: (f, a) => f(...a)
|
|
1423
1400
|
});
|
|
@@ -1427,7 +1404,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1427
1404
|
if (!this._isEnabled) {
|
|
1428
1405
|
return;
|
|
1429
1406
|
}
|
|
1430
|
-
const message =
|
|
1407
|
+
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1431
1408
|
readableStreamController.enqueue(message);
|
|
1432
1409
|
},
|
|
1433
1410
|
onClose: async () => {
|
|
@@ -1439,9 +1416,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1439
1416
|
});
|
|
1440
1417
|
}
|
|
1441
1418
|
get peerId() {
|
|
1442
|
-
(0,
|
|
1443
|
-
F:
|
|
1444
|
-
L:
|
|
1419
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1420
|
+
F: __dxlog_file5,
|
|
1421
|
+
L: 215,
|
|
1445
1422
|
S: this,
|
|
1446
1423
|
A: [
|
|
1447
1424
|
"this._remotePeerId != null",
|
|
@@ -1458,9 +1435,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1458
1435
|
* Call after the remote peer has connected.
|
|
1459
1436
|
*/
|
|
1460
1437
|
async enable() {
|
|
1461
|
-
(0,
|
|
1462
|
-
F:
|
|
1463
|
-
L:
|
|
1438
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1439
|
+
F: __dxlog_file5,
|
|
1440
|
+
L: 228,
|
|
1464
1441
|
S: this,
|
|
1465
1442
|
A: [
|
|
1466
1443
|
"this._remotePeerId != null",
|
|
@@ -1482,7 +1459,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1482
1459
|
AuthStatus,
|
|
1483
1460
|
AutomergeDocumentLoaderImpl,
|
|
1484
1461
|
AutomergeHost,
|
|
1485
|
-
|
|
1462
|
+
CredentialRetrieverExtension,
|
|
1463
|
+
CredentialServerExtension,
|
|
1486
1464
|
DataServiceImpl,
|
|
1487
1465
|
LevelDBStorageAdapter,
|
|
1488
1466
|
LocalHostNetworkAdapter,
|