@dxos/echo-pipeline 0.5.9-main.bd9c8b3 → 0.5.9-main.bdb299c
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 +155 -87
- 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 +193 -125
- 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 -2
- 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/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 -18
- package/src/automerge/echo-network-adapter.ts +10 -4
- package/src/automerge/mesh-echo-replicator.ts +2 -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,43 +18,44 @@ 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
60
|
var import_protocols = require("@dxos/protocols");
|
|
60
61
|
var import_tracing = require("@dxos/tracing");
|
|
@@ -62,23 +63,24 @@ var import_util = require("@dxos/util");
|
|
|
62
63
|
var import_async2 = require("@dxos/async");
|
|
63
64
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
64
65
|
var import_context2 = require("@dxos/context");
|
|
65
|
-
var
|
|
66
|
+
var import_invariant = require("@dxos/invariant");
|
|
66
67
|
var import_log = require("@dxos/log");
|
|
67
68
|
var import_context3 = require("@dxos/context");
|
|
68
69
|
var import_async3 = require("@dxos/async");
|
|
69
70
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
70
71
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
71
|
-
var
|
|
72
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
72
73
|
var import_async4 = require("@dxos/async");
|
|
74
|
+
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
73
75
|
var import_context4 = require("@dxos/context");
|
|
74
76
|
var import_debug = require("@dxos/debug");
|
|
75
77
|
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
76
|
-
var
|
|
78
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
77
79
|
var import_log2 = require("@dxos/log");
|
|
78
80
|
var import_tracing2 = require("@dxos/tracing");
|
|
79
|
-
var
|
|
81
|
+
var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
|
|
80
82
|
var import_context5 = require("@dxos/context");
|
|
81
|
-
var
|
|
83
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
82
84
|
var import_keys2 = require("@dxos/keys");
|
|
83
85
|
var import_log3 = require("@dxos/log");
|
|
84
86
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
@@ -127,7 +129,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
127
129
|
disconnect() {
|
|
128
130
|
}
|
|
129
131
|
async open() {
|
|
130
|
-
(0,
|
|
132
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
|
|
131
133
|
F: __dxlog_file,
|
|
132
134
|
L: 60,
|
|
133
135
|
S: this,
|
|
@@ -148,7 +150,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
async close() {
|
|
151
|
-
(0,
|
|
153
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
152
154
|
F: __dxlog_file,
|
|
153
155
|
L: 71,
|
|
154
156
|
S: this,
|
|
@@ -169,7 +171,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
173
|
async addReplicator(replicator) {
|
|
172
|
-
(0,
|
|
174
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
173
175
|
F: __dxlog_file,
|
|
174
176
|
L: 87,
|
|
175
177
|
S: this,
|
|
@@ -178,7 +180,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
178
180
|
""
|
|
179
181
|
]
|
|
180
182
|
});
|
|
181
|
-
(0,
|
|
183
|
+
(0, import_invariant.invariant)(this.peerId, void 0, {
|
|
182
184
|
F: __dxlog_file,
|
|
183
185
|
L: 88,
|
|
184
186
|
S: this,
|
|
@@ -187,7 +189,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
187
189
|
""
|
|
188
190
|
]
|
|
189
191
|
});
|
|
190
|
-
(0,
|
|
192
|
+
(0, import_invariant.invariant)(!this._replicators.has(replicator), void 0, {
|
|
191
193
|
F: __dxlog_file,
|
|
192
194
|
L: 89,
|
|
193
195
|
S: this,
|
|
@@ -206,7 +208,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
206
208
|
});
|
|
207
209
|
}
|
|
208
210
|
async removeReplicator(replicator) {
|
|
209
|
-
(0,
|
|
211
|
+
(0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
|
|
210
212
|
F: __dxlog_file,
|
|
211
213
|
L: 103,
|
|
212
214
|
S: this,
|
|
@@ -215,7 +217,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
215
217
|
""
|
|
216
218
|
]
|
|
217
219
|
});
|
|
218
|
-
(0,
|
|
220
|
+
(0, import_invariant.invariant)(this._replicators.has(replicator), void 0, {
|
|
219
221
|
F: __dxlog_file,
|
|
220
222
|
L: 104,
|
|
221
223
|
S: this,
|
|
@@ -243,7 +245,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
243
245
|
S: this,
|
|
244
246
|
C: (f, a) => f(...a)
|
|
245
247
|
});
|
|
246
|
-
(0,
|
|
248
|
+
(0, import_invariant.invariant)(!this._connections.has(connection.peerId), void 0, {
|
|
247
249
|
F: __dxlog_file,
|
|
248
250
|
L: 120,
|
|
249
251
|
S: this,
|
|
@@ -305,7 +307,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
305
307
|
C: (f, a) => f(...a)
|
|
306
308
|
});
|
|
307
309
|
const entry = this._connections.get(connection.peerId);
|
|
308
|
-
(0,
|
|
310
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
309
311
|
F: __dxlog_file,
|
|
310
312
|
L: 155,
|
|
311
313
|
S: this,
|
|
@@ -329,7 +331,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
329
331
|
C: (f, a) => f(...a)
|
|
330
332
|
});
|
|
331
333
|
const entry = this._connections.get(connection.peerId);
|
|
332
|
-
(0,
|
|
334
|
+
(0, import_invariant.invariant)(entry, void 0, {
|
|
333
335
|
F: __dxlog_file,
|
|
334
336
|
L: 163,
|
|
335
337
|
S: this,
|
|
@@ -359,10 +361,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
359
361
|
_emitPeerCandidate(connection) {
|
|
360
362
|
this.emit("peer-candidate", {
|
|
361
363
|
peerId: connection.peerId,
|
|
362
|
-
peerMetadata:
|
|
363
|
-
// TODO(dmaretskyi): Refactor this.
|
|
364
|
-
dxos_peerSource: "EchoNetworkAdapter"
|
|
365
|
-
}
|
|
364
|
+
peerMetadata: createEchoPeerMetadata()
|
|
366
365
|
});
|
|
367
366
|
}
|
|
368
367
|
};
|
|
@@ -378,6 +377,11 @@ _ts_decorate([
|
|
|
378
377
|
_ts_decorate([
|
|
379
378
|
import_async2.synchronized
|
|
380
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";
|
|
381
385
|
var LevelDBStorageAdapter = class extends import_context3.Resource {
|
|
382
386
|
constructor(_params) {
|
|
383
387
|
super();
|
|
@@ -499,7 +503,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
499
503
|
}
|
|
500
504
|
send(message) {
|
|
501
505
|
const peer = this._peers.get(message.targetId);
|
|
502
|
-
(0,
|
|
506
|
+
(0, import_invariant2.invariant)(peer, "Peer not found.", {
|
|
503
507
|
F: __dxlog_file2,
|
|
504
508
|
L: 51,
|
|
505
509
|
S: this,
|
|
@@ -524,7 +528,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
524
528
|
syncRepo({ id, syncMessage }) {
|
|
525
529
|
const peerId = this._getPeerId(id);
|
|
526
530
|
return new import_codec_protobuf.Stream(({ next, close }) => {
|
|
527
|
-
(0,
|
|
531
|
+
(0, import_invariant2.invariant)(!this._peers.has(peerId), "Peer already connected.", {
|
|
528
532
|
F: __dxlog_file2,
|
|
529
533
|
L: 73,
|
|
530
534
|
S: this,
|
|
@@ -548,7 +552,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
548
552
|
});
|
|
549
553
|
}
|
|
550
554
|
});
|
|
551
|
-
(0,
|
|
555
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
552
556
|
F: __dxlog_file2,
|
|
553
557
|
L: 90,
|
|
554
558
|
S: this,
|
|
@@ -564,7 +568,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
564
568
|
});
|
|
565
569
|
}
|
|
566
570
|
async sendSyncMessage({ id, syncMessage }) {
|
|
567
|
-
(0,
|
|
571
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
568
572
|
F: __dxlog_file2,
|
|
569
573
|
L: 99,
|
|
570
574
|
S: this,
|
|
@@ -577,7 +581,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
577
581
|
this.emit("message", message);
|
|
578
582
|
}
|
|
579
583
|
async getHostInfo() {
|
|
580
|
-
(0,
|
|
584
|
+
(0, import_invariant2.invariant)(this._isConnected, void 0, {
|
|
581
585
|
F: __dxlog_file2,
|
|
582
586
|
L: 105,
|
|
583
587
|
S: this,
|
|
@@ -586,7 +590,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
|
|
|
586
590
|
""
|
|
587
591
|
]
|
|
588
592
|
});
|
|
589
|
-
(0,
|
|
593
|
+
(0, import_invariant2.invariant)(this.peerId, "Peer id not set.", {
|
|
590
594
|
F: __dxlog_file2,
|
|
591
595
|
L: 106,
|
|
592
596
|
S: this,
|
|
@@ -616,7 +620,10 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
616
620
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
617
621
|
var AutomergeHost = class {
|
|
618
622
|
constructor({ db, indexMetadataStore }) {
|
|
619
|
-
this._ctx = new import_context.Context(
|
|
623
|
+
this._ctx = new import_context.Context(void 0, {
|
|
624
|
+
F: __dxlog_file3,
|
|
625
|
+
L: 71
|
|
626
|
+
});
|
|
620
627
|
this._echoNetworkAdapter = new EchoNetworkAdapter({
|
|
621
628
|
getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
|
|
622
629
|
});
|
|
@@ -655,6 +662,9 @@ var AutomergeHost = class {
|
|
|
655
662
|
await this._echoNetworkAdapter.close();
|
|
656
663
|
await this._ctx.dispose();
|
|
657
664
|
}
|
|
665
|
+
/**
|
|
666
|
+
* @deprecated To be abstracted away.
|
|
667
|
+
*/
|
|
658
668
|
get repo() {
|
|
659
669
|
return this._repo;
|
|
660
670
|
}
|
|
@@ -664,6 +674,39 @@ var AutomergeHost = class {
|
|
|
664
674
|
async removeReplicator(replicator) {
|
|
665
675
|
await this._echoNetworkAdapter.removeReplicator(replicator);
|
|
666
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
|
+
}
|
|
667
710
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
668
711
|
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
669
712
|
// NOTE: If both peers return sharePolicy=false the replication will not happen
|
|
@@ -676,7 +719,7 @@ var AutomergeHost = class {
|
|
|
676
719
|
return false;
|
|
677
720
|
}
|
|
678
721
|
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
679
|
-
if (peerMetadata
|
|
722
|
+
if (isEchoPeerMetadata(peerMetadata)) {
|
|
680
723
|
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
681
724
|
documentId
|
|
682
725
|
});
|
|
@@ -748,31 +791,36 @@ var AutomergeHost = class {
|
|
|
748
791
|
}
|
|
749
792
|
return import_keys.PublicKey.from(spaceKeyHex);
|
|
750
793
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
794
|
+
/**
|
|
795
|
+
* Flush documents to disk.
|
|
796
|
+
*/
|
|
754
797
|
async flush({ states }) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
});
|
|
765
|
-
const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
|
|
766
|
-
await waitForHeads(handle, heads);
|
|
767
|
-
}) ?? []);
|
|
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
|
+
}
|
|
768
807
|
await this._repo.flush(states?.map(({ documentId }) => documentId));
|
|
769
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Host <-> Client sync.
|
|
811
|
+
*/
|
|
770
812
|
syncRepo(request) {
|
|
771
813
|
return this._clientNetwork.syncRepo(request);
|
|
772
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Host <-> Client sync.
|
|
817
|
+
*/
|
|
773
818
|
sendSyncMessage(request) {
|
|
774
819
|
return this._clientNetwork.sendSyncMessage(request);
|
|
775
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Host <-> Client sync.
|
|
823
|
+
*/
|
|
776
824
|
async getHostInfo() {
|
|
777
825
|
return this._clientNetwork.getHostInfo();
|
|
778
826
|
}
|
|
@@ -855,32 +903,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
855
903
|
return;
|
|
856
904
|
}
|
|
857
905
|
if (!spaceState.rootUrl) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
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);
|
|
883
930
|
}
|
|
931
|
+
this._spaceRootDocHandle = existingDocHandle;
|
|
884
932
|
}
|
|
885
933
|
loadObjectDocument(objectIdOrMany) {
|
|
886
934
|
const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
|
|
@@ -889,9 +937,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
889
937
|
let hasUrlsToLoad = false;
|
|
890
938
|
const urlsToLoad = {};
|
|
891
939
|
for (const objectId of objectIds) {
|
|
892
|
-
(0,
|
|
940
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
893
941
|
F: __dxlog_file4,
|
|
894
|
-
L:
|
|
942
|
+
L: 97,
|
|
895
943
|
S: this,
|
|
896
944
|
A: [
|
|
897
945
|
"this._spaceRootDocHandle",
|
|
@@ -902,9 +950,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
902
950
|
continue;
|
|
903
951
|
}
|
|
904
952
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
905
|
-
(0,
|
|
953
|
+
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
906
954
|
F: __dxlog_file4,
|
|
907
|
-
L:
|
|
955
|
+
L: 102,
|
|
908
956
|
S: this,
|
|
909
957
|
A: [
|
|
910
958
|
"spaceRootDoc",
|
|
@@ -918,7 +966,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
918
966
|
objectId
|
|
919
967
|
}, {
|
|
920
968
|
F: __dxlog_file4,
|
|
921
|
-
L:
|
|
969
|
+
L: 106,
|
|
922
970
|
S: this,
|
|
923
971
|
C: (f, a) => f(...a)
|
|
924
972
|
});
|
|
@@ -931,6 +979,32 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
931
979
|
this._loadLinkedObjects(urlsToLoad);
|
|
932
980
|
}
|
|
933
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
|
+
}
|
|
934
1008
|
onObjectLinksUpdated(links) {
|
|
935
1009
|
if (!links) {
|
|
936
1010
|
return;
|
|
@@ -940,9 +1014,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
940
1014
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
941
1015
|
}
|
|
942
1016
|
getSpaceRootDocHandle() {
|
|
943
|
-
(0,
|
|
1017
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
944
1018
|
F: __dxlog_file4,
|
|
945
|
-
L:
|
|
1019
|
+
L: 140,
|
|
946
1020
|
S: this,
|
|
947
1021
|
A: [
|
|
948
1022
|
"this._spaceRootDocHandle",
|
|
@@ -952,9 +1026,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
952
1026
|
return this._spaceRootDocHandle;
|
|
953
1027
|
}
|
|
954
1028
|
createDocumentForObject(objectId) {
|
|
955
|
-
(0,
|
|
1029
|
+
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
956
1030
|
F: __dxlog_file4,
|
|
957
|
-
L:
|
|
1031
|
+
L: 145,
|
|
958
1032
|
S: this,
|
|
959
1033
|
A: [
|
|
960
1034
|
"this._spaceRootDocHandle",
|
|
@@ -999,7 +1073,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
999
1073
|
actualDocumentUrl: objectDocumentHandle.url
|
|
1000
1074
|
}, {
|
|
1001
1075
|
F: __dxlog_file4,
|
|
1002
|
-
L:
|
|
1076
|
+
L: 177,
|
|
1003
1077
|
S: this,
|
|
1004
1078
|
C: (f, a) => f(...a)
|
|
1005
1079
|
});
|
|
@@ -1008,7 +1082,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1008
1082
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
1009
1083
|
import_log2.log.warn("object document was already loaded", logMeta, {
|
|
1010
1084
|
F: __dxlog_file4,
|
|
1011
|
-
L:
|
|
1085
|
+
L: 184,
|
|
1012
1086
|
S: this,
|
|
1013
1087
|
C: (f, a) => f(...a)
|
|
1014
1088
|
});
|
|
@@ -1017,7 +1091,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1017
1091
|
const handle = this._repo.find(automergeUrl);
|
|
1018
1092
|
import_log2.log.debug("document loading triggered", logMeta, {
|
|
1019
1093
|
F: __dxlog_file4,
|
|
1020
|
-
L:
|
|
1094
|
+
L: 188,
|
|
1021
1095
|
S: this,
|
|
1022
1096
|
C: (f, a) => f(...a)
|
|
1023
1097
|
});
|
|
@@ -1040,7 +1114,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1040
1114
|
state: docHandle.state
|
|
1041
1115
|
}, {
|
|
1042
1116
|
F: __dxlog_file4,
|
|
1043
|
-
L:
|
|
1117
|
+
L: 204,
|
|
1044
1118
|
S: this,
|
|
1045
1119
|
C: (f, a) => f(...a)
|
|
1046
1120
|
});
|
|
@@ -1054,14 +1128,6 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1054
1128
|
}
|
|
1055
1129
|
return docHandle;
|
|
1056
1130
|
}
|
|
1057
|
-
_createContextBoundSpaceRootDocument(ctx) {
|
|
1058
|
-
const docHandle = this._repo.create();
|
|
1059
|
-
this._spaceRootDocHandle = docHandle;
|
|
1060
|
-
ctx.onDispose(() => {
|
|
1061
|
-
docHandle.delete();
|
|
1062
|
-
this._spaceRootDocHandle = null;
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
1131
|
_initDocAccess(handle) {
|
|
1066
1132
|
handle.change((newDoc) => {
|
|
1067
1133
|
newDoc.access ??= {
|
|
@@ -1082,7 +1148,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1082
1148
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
1083
1149
|
import_log2.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1084
1150
|
F: __dxlog_file4,
|
|
1085
|
-
L:
|
|
1151
|
+
L: 231,
|
|
1086
1152
|
S: this,
|
|
1087
1153
|
C: (f, a) => f(...a)
|
|
1088
1154
|
});
|
|
@@ -1092,7 +1158,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1092
1158
|
if (objectDocHandle?.url !== handle.url) {
|
|
1093
1159
|
import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1094
1160
|
F: __dxlog_file4,
|
|
1095
|
-
L:
|
|
1161
|
+
L: 236,
|
|
1096
1162
|
S: this,
|
|
1097
1163
|
C: (f, a) => f(...a)
|
|
1098
1164
|
});
|
|
@@ -1111,7 +1177,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1111
1177
|
err
|
|
1112
1178
|
}, {
|
|
1113
1179
|
F: __dxlog_file4,
|
|
1114
|
-
L:
|
|
1180
|
+
L: 242,
|
|
1115
1181
|
S: this,
|
|
1116
1182
|
C: (f, a) => f(...a)
|
|
1117
1183
|
});
|
|
@@ -1149,7 +1215,7 @@ var MeshEchoReplicator = class {
|
|
|
1149
1215
|
this._context = null;
|
|
1150
1216
|
}
|
|
1151
1217
|
createExtension() {
|
|
1152
|
-
(0,
|
|
1218
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1153
1219
|
F: __dxlog_file5,
|
|
1154
1220
|
L: 54,
|
|
1155
1221
|
S: this,
|
|
@@ -1169,7 +1235,7 @@ var MeshEchoReplicator = class {
|
|
|
1169
1235
|
S: this,
|
|
1170
1236
|
C: (f, a) => f(...a)
|
|
1171
1237
|
});
|
|
1172
|
-
(0,
|
|
1238
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1173
1239
|
F: __dxlog_file5,
|
|
1174
1240
|
L: 60,
|
|
1175
1241
|
S: this,
|
|
@@ -1182,8 +1248,8 @@ var MeshEchoReplicator = class {
|
|
|
1182
1248
|
this._context.onConnectionAuthScopeChanged(connection);
|
|
1183
1249
|
} else {
|
|
1184
1250
|
this._connectionsPerPeer.set(connection.peerId, connection);
|
|
1185
|
-
await connection.enable();
|
|
1186
1251
|
this._context.onConnectionOpen(connection);
|
|
1252
|
+
await connection.enable();
|
|
1187
1253
|
}
|
|
1188
1254
|
},
|
|
1189
1255
|
onRemoteDisconnected: async () => {
|
|
@@ -1196,8 +1262,8 @@ var MeshEchoReplicator = class {
|
|
|
1196
1262
|
C: (f, a) => f(...a)
|
|
1197
1263
|
});
|
|
1198
1264
|
this._context?.onConnectionClosed(connection);
|
|
1199
|
-
await connection.disable();
|
|
1200
1265
|
this._connectionsPerPeer.delete(connection.peerId);
|
|
1266
|
+
await connection.disable();
|
|
1201
1267
|
this._connections.delete(connection);
|
|
1202
1268
|
},
|
|
1203
1269
|
shouldAdvertize: async (params) => {
|
|
@@ -1210,7 +1276,7 @@ var MeshEchoReplicator = class {
|
|
|
1210
1276
|
S: this,
|
|
1211
1277
|
C: (f, a) => f(...a)
|
|
1212
1278
|
});
|
|
1213
|
-
(0,
|
|
1279
|
+
(0, import_invariant4.invariant)(this._context, void 0, {
|
|
1214
1280
|
F: __dxlog_file5,
|
|
1215
1281
|
L: 79,
|
|
1216
1282
|
S: this,
|
|
@@ -1310,7 +1376,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1310
1376
|
this.writable = new WritableStream({
|
|
1311
1377
|
write: async (message, controller) => {
|
|
1312
1378
|
this.replicatorExtension.sendSyncMessage({
|
|
1313
|
-
payload:
|
|
1379
|
+
payload: import_automerge_repo5.cbor.encode(message)
|
|
1314
1380
|
}).catch((err) => {
|
|
1315
1381
|
controller.error(err);
|
|
1316
1382
|
});
|
|
@@ -1338,7 +1404,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1338
1404
|
if (!this._isEnabled) {
|
|
1339
1405
|
return;
|
|
1340
1406
|
}
|
|
1341
|
-
const message =
|
|
1407
|
+
const message = import_automerge_repo5.cbor.decode(payload);
|
|
1342
1408
|
readableStreamController.enqueue(message);
|
|
1343
1409
|
},
|
|
1344
1410
|
onClose: async () => {
|
|
@@ -1350,7 +1416,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1350
1416
|
});
|
|
1351
1417
|
}
|
|
1352
1418
|
get peerId() {
|
|
1353
|
-
(0,
|
|
1419
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1354
1420
|
F: __dxlog_file5,
|
|
1355
1421
|
L: 215,
|
|
1356
1422
|
S: this,
|
|
@@ -1369,7 +1435,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1369
1435
|
* Call after the remote peer has connected.
|
|
1370
1436
|
*/
|
|
1371
1437
|
async enable() {
|
|
1372
|
-
(0,
|
|
1438
|
+
(0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
|
|
1373
1439
|
F: __dxlog_file5,
|
|
1374
1440
|
L: 228,
|
|
1375
1441
|
S: this,
|
|
@@ -1393,6 +1459,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
|
|
|
1393
1459
|
AuthStatus,
|
|
1394
1460
|
AutomergeDocumentLoaderImpl,
|
|
1395
1461
|
AutomergeHost,
|
|
1462
|
+
CredentialRetrieverExtension,
|
|
1463
|
+
CredentialServerExtension,
|
|
1396
1464
|
DataServiceImpl,
|
|
1397
1465
|
LevelDBStorageAdapter,
|
|
1398
1466
|
LocalHostNetworkAdapter,
|