@dxos/echo-pipeline 0.5.9-main.a50ff17 → 0.5.9-main.a75fa71

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.
Files changed (33) hide show
  1. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-HS77A4I4.mjs} +174 -23
  2. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs.map → chunk-HS77A4I4.mjs.map} +4 -4
  3. package/dist/lib/browser/index.mjs +119 -82
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +11 -7
  7. package/dist/lib/browser/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs → chunk-Y5U7UXEL.cjs} +185 -34
  9. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs.map → chunk-Y5U7UXEL.cjs.map} +4 -4
  10. package/dist/lib/node/index.cjs +164 -127
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +21 -17
  14. package/dist/lib/node/testing/index.cjs.map +1 -1
  15. package/dist/types/src/automerge/automerge-host.d.ts +40 -3
  16. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  17. package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -0
  18. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  19. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  20. package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  21. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  22. package/dist/types/src/space/index.d.ts +1 -0
  23. package/dist/types/src/space/index.d.ts.map +1 -1
  24. package/dist/types/src/space/space-manager.d.ts +8 -0
  25. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  26. package/package.json +33 -33
  27. package/src/automerge/automerge-doc-loader.test.ts +2 -3
  28. package/src/automerge/automerge-host.ts +96 -32
  29. package/src/automerge/echo-network-adapter.ts +10 -4
  30. package/src/automerge/mesh-echo-replicator.ts +6 -1
  31. package/src/space/admission-discovery-extension.ts +90 -0
  32. package/src/space/index.ts +1 -0
  33. package/src/space/space-manager.ts +46 -1
@@ -18,70 +18,70 @@ 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: () => import_chunk_QPCNQ4ZK.AuthExtension,
22
- AuthStatus: () => import_chunk_QPCNQ4ZK.AuthStatus,
21
+ AuthExtension: () => import_chunk_Y5U7UXEL.AuthExtension,
22
+ AuthStatus: () => import_chunk_Y5U7UXEL.AuthStatus,
23
23
  AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
24
24
  AutomergeHost: () => AutomergeHost,
25
- DataServiceImpl: () => import_chunk_QPCNQ4ZK.DataServiceImpl,
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: () => import_chunk_QPCNQ4ZK.MOCK_AUTH_PROVIDER,
29
- MOCK_AUTH_VERIFIER: () => import_chunk_QPCNQ4ZK.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: () => import_chunk_QPCNQ4ZK.MetadataStore,
32
- Pipeline: () => import_chunk_QPCNQ4ZK.Pipeline,
33
- SnapshotManager: () => import_chunk_QPCNQ4ZK.SnapshotManager,
34
- SnapshotStore: () => import_chunk_QPCNQ4ZK.SnapshotStore,
35
- Space: () => import_chunk_QPCNQ4ZK.Space,
36
- SpaceManager: () => import_chunk_QPCNQ4ZK.SpaceManager,
37
- SpaceProtocol: () => import_chunk_QPCNQ4ZK.SpaceProtocol,
38
- SpaceProtocolSession: () => import_chunk_QPCNQ4ZK.SpaceProtocolSession,
39
- TimeframeClock: () => import_chunk_QPCNQ4ZK.TimeframeClock,
40
- codec: () => import_chunk_QPCNQ4ZK.codec,
41
- createIdFromSpaceKey: () => import_chunk_QPCNQ4ZK.createIdFromSpaceKey,
42
- createMappedFeedWriter: () => import_chunk_QPCNQ4ZK.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: () => import_chunk_QPCNQ4ZK.hasInvitationExpired,
46
- mapFeedIndexesToTimeframe: () => import_chunk_QPCNQ4ZK.mapFeedIndexesToTimeframe,
47
- mapTimeframeToFeedIndexes: () => import_chunk_QPCNQ4ZK.mapTimeframeToFeedIndexes,
48
- startAfter: () => import_chunk_QPCNQ4ZK.startAfter,
49
- valueEncoding: () => import_chunk_QPCNQ4ZK.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 import_chunk_QPCNQ4ZK = require("./chunk-QPCNQ4ZK.cjs");
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 import_invariant2 = require("@dxos/invariant");
67
- var import_log2 = require("@dxos/log");
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 import_invariant3 = require("@dxos/invariant");
72
+ var import_invariant2 = require("@dxos/invariant");
73
73
  var import_async4 = require("@dxos/async");
74
74
  var import_context4 = require("@dxos/context");
75
75
  var import_debug = require("@dxos/debug");
76
76
  var import_echo_protocol = require("@dxos/echo-protocol");
77
- var import_invariant4 = require("@dxos/invariant");
78
- var import_log3 = require("@dxos/log");
77
+ var import_invariant3 = require("@dxos/invariant");
78
+ var import_log2 = require("@dxos/log");
79
79
  var import_tracing2 = require("@dxos/tracing");
80
80
  var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
81
81
  var import_context5 = require("@dxos/context");
82
- var import_invariant5 = require("@dxos/invariant");
82
+ var import_invariant4 = require("@dxos/invariant");
83
83
  var import_keys2 = require("@dxos/keys");
84
- var import_log4 = require("@dxos/log");
84
+ var import_log3 = require("@dxos/log");
85
85
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
86
86
  var import_util2 = require("@dxos/util");
87
87
  function _ts_decorate(decorators, target, key, desc) {
@@ -116,7 +116,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
116
116
  }
117
117
  connectionEntry.writer.write(message).catch((err) => {
118
118
  if (connectionEntry.isOpen) {
119
- import_log2.log.catch(err, void 0, {
119
+ import_log.log.catch(err, void 0, {
120
120
  F: __dxlog_file,
121
121
  L: 49,
122
122
  S: this,
@@ -128,7 +128,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
128
128
  disconnect() {
129
129
  }
130
130
  async open() {
131
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
131
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
132
132
  F: __dxlog_file,
133
133
  L: 60,
134
134
  S: this,
@@ -138,7 +138,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
138
138
  ]
139
139
  });
140
140
  this._lifecycleState = import_context2.LifecycleState.OPEN;
141
- (0, import_log2.log)("emit ready", void 0, {
141
+ (0, import_log.log)("emit ready", void 0, {
142
142
  F: __dxlog_file,
143
143
  L: 63,
144
144
  S: this,
@@ -149,7 +149,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
149
149
  });
150
150
  }
151
151
  async close() {
152
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
152
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
153
153
  F: __dxlog_file,
154
154
  L: 71,
155
155
  S: this,
@@ -170,7 +170,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
170
170
  });
171
171
  }
172
172
  async addReplicator(replicator) {
173
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
173
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
174
174
  F: __dxlog_file,
175
175
  L: 87,
176
176
  S: this,
@@ -179,7 +179,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
179
179
  ""
180
180
  ]
181
181
  });
182
- (0, import_invariant2.invariant)(this.peerId, void 0, {
182
+ (0, import_invariant.invariant)(this.peerId, void 0, {
183
183
  F: __dxlog_file,
184
184
  L: 88,
185
185
  S: this,
@@ -188,7 +188,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
188
188
  ""
189
189
  ]
190
190
  });
191
- (0, import_invariant2.invariant)(!this._replicators.has(replicator), void 0, {
191
+ (0, import_invariant.invariant)(!this._replicators.has(replicator), void 0, {
192
192
  F: __dxlog_file,
193
193
  L: 89,
194
194
  S: this,
@@ -207,7 +207,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
207
207
  });
208
208
  }
209
209
  async removeReplicator(replicator) {
210
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
210
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
211
211
  F: __dxlog_file,
212
212
  L: 103,
213
213
  S: this,
@@ -216,7 +216,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
216
216
  ""
217
217
  ]
218
218
  });
219
- (0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
219
+ (0, import_invariant.invariant)(this._replicators.has(replicator), void 0, {
220
220
  F: __dxlog_file,
221
221
  L: 104,
222
222
  S: this,
@@ -236,7 +236,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
236
236
  return connection.connection.shouldAdvertize(params);
237
237
  }
238
238
  _onConnectionOpen(connection) {
239
- (0, import_log2.log)("Connection opened", {
239
+ (0, import_log.log)("Connection opened", {
240
240
  peerId: connection.peerId
241
241
  }, {
242
242
  F: __dxlog_file,
@@ -244,7 +244,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
244
244
  S: this,
245
245
  C: (f, a) => f(...a)
246
246
  });
247
- (0, import_invariant2.invariant)(!this._connections.has(connection.peerId), void 0, {
247
+ (0, import_invariant.invariant)(!this._connections.has(connection.peerId), void 0, {
248
248
  F: __dxlog_file,
249
249
  L: 120,
250
250
  S: this,
@@ -273,7 +273,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
273
273
  }
274
274
  } catch (err) {
275
275
  if (connectionEntry.isOpen) {
276
- import_log2.log.catch(err, void 0, {
276
+ import_log.log.catch(err, void 0, {
277
277
  F: __dxlog_file,
278
278
  L: 139,
279
279
  S: this,
@@ -282,7 +282,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
282
282
  }
283
283
  }
284
284
  });
285
- (0, import_log2.log)("emit peer-candidate", {
285
+ (0, import_log.log)("emit peer-candidate", {
286
286
  peerId: connection.peerId
287
287
  }, {
288
288
  F: __dxlog_file,
@@ -297,7 +297,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
297
297
  * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
298
298
  */
299
299
  _onConnectionAuthScopeChanged(connection) {
300
- (0, import_log2.log)("Connection auth scope changed", {
300
+ (0, import_log.log)("Connection auth scope changed", {
301
301
  peerId: connection.peerId
302
302
  }, {
303
303
  F: __dxlog_file,
@@ -306,7 +306,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
306
306
  C: (f, a) => f(...a)
307
307
  });
308
308
  const entry = this._connections.get(connection.peerId);
309
- (0, import_invariant2.invariant)(entry, void 0, {
309
+ (0, import_invariant.invariant)(entry, void 0, {
310
310
  F: __dxlog_file,
311
311
  L: 155,
312
312
  S: this,
@@ -321,7 +321,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
321
321
  this._emitPeerCandidate(connection);
322
322
  }
323
323
  _onConnectionClosed(connection) {
324
- (0, import_log2.log)("Connection closed", {
324
+ (0, import_log.log)("Connection closed", {
325
325
  peerId: connection.peerId
326
326
  }, {
327
327
  F: __dxlog_file,
@@ -330,7 +330,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
330
330
  C: (f, a) => f(...a)
331
331
  });
332
332
  const entry = this._connections.get(connection.peerId);
333
- (0, import_invariant2.invariant)(entry, void 0, {
333
+ (0, import_invariant.invariant)(entry, void 0, {
334
334
  F: __dxlog_file,
335
335
  L: 163,
336
336
  S: this,
@@ -343,13 +343,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
343
343
  this.emit("peer-disconnected", {
344
344
  peerId: connection.peerId
345
345
  });
346
- void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
346
+ void entry.reader.cancel().catch((err) => import_log.log.catch(err, void 0, {
347
347
  F: __dxlog_file,
348
348
  L: 168,
349
349
  S: this,
350
350
  C: (f, a) => f(...a)
351
351
  }));
352
- void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
352
+ void entry.writer.abort().catch((err) => import_log.log.catch(err, void 0, {
353
353
  F: __dxlog_file,
354
354
  L: 169,
355
355
  S: this,
@@ -360,10 +360,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
360
360
  _emitPeerCandidate(connection) {
361
361
  this.emit("peer-candidate", {
362
362
  peerId: connection.peerId,
363
- peerMetadata: {
364
- // TODO(dmaretskyi): Refactor this.
365
- dxos_peerSource: "EchoNetworkAdapter"
366
- }
363
+ peerMetadata: createEchoPeerMetadata()
367
364
  });
368
365
  }
369
366
  };
@@ -379,6 +376,11 @@ _ts_decorate([
379
376
  _ts_decorate([
380
377
  import_async2.synchronized
381
378
  ], EchoNetworkAdapter.prototype, "removeReplicator", null);
379
+ var createEchoPeerMetadata = () => ({
380
+ // TODO(dmaretskyi): Refactor this.
381
+ dxos_peerSource: "EchoNetworkAdapter"
382
+ });
383
+ var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetworkAdapter";
382
384
  var LevelDBStorageAdapter = class extends import_context3.Resource {
383
385
  constructor(_params) {
384
386
  super();
@@ -500,7 +502,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
500
502
  }
501
503
  send(message) {
502
504
  const peer = this._peers.get(message.targetId);
503
- (0, import_invariant3.invariant)(peer, "Peer not found.", {
505
+ (0, import_invariant2.invariant)(peer, "Peer not found.", {
504
506
  F: __dxlog_file2,
505
507
  L: 51,
506
508
  S: this,
@@ -525,7 +527,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
525
527
  syncRepo({ id, syncMessage }) {
526
528
  const peerId = this._getPeerId(id);
527
529
  return new import_codec_protobuf.Stream(({ next, close }) => {
528
- (0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
530
+ (0, import_invariant2.invariant)(!this._peers.has(peerId), "Peer already connected.", {
529
531
  F: __dxlog_file2,
530
532
  L: 73,
531
533
  S: this,
@@ -549,7 +551,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
549
551
  });
550
552
  }
551
553
  });
552
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
554
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
553
555
  F: __dxlog_file2,
554
556
  L: 90,
555
557
  S: this,
@@ -565,7 +567,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
565
567
  });
566
568
  }
567
569
  async sendSyncMessage({ id, syncMessage }) {
568
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
570
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
569
571
  F: __dxlog_file2,
570
572
  L: 99,
571
573
  S: this,
@@ -578,7 +580,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
578
580
  this.emit("message", message);
579
581
  }
580
582
  async getHostInfo() {
581
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
583
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
582
584
  F: __dxlog_file2,
583
585
  L: 105,
584
586
  S: this,
@@ -587,7 +589,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
587
589
  ""
588
590
  ]
589
591
  });
590
- (0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
592
+ (0, import_invariant2.invariant)(this.peerId, "Peer id not set.", {
591
593
  F: __dxlog_file2,
592
594
  L: 106,
593
595
  S: this,
@@ -617,11 +619,13 @@ function _ts_decorate2(decorators, target, key, desc) {
617
619
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
618
620
  var AutomergeHost = class {
619
621
  constructor({ db, indexMetadataStore }) {
620
- this._ctx = new import_context.Context();
622
+ this._ctx = new import_context.Context(void 0, {
623
+ F: __dxlog_file3,
624
+ L: 71
625
+ });
621
626
  this._echoNetworkAdapter = new EchoNetworkAdapter({
622
627
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
623
628
  });
624
- this._requestedDocs = /* @__PURE__ */ new Set();
625
629
  this._storage = new LevelDBStorageAdapter({
626
630
  db,
627
631
  callbacks: {
@@ -657,6 +661,9 @@ var AutomergeHost = class {
657
661
  await this._echoNetworkAdapter.close();
658
662
  await this._ctx.dispose();
659
663
  }
664
+ /**
665
+ * @deprecated To be abstracted away.
666
+ */
660
667
  get repo() {
661
668
  return this._repo;
662
669
  }
@@ -666,6 +673,39 @@ var AutomergeHost = class {
666
673
  async removeReplicator(replicator) {
667
674
  await this._echoNetworkAdapter.removeReplicator(replicator);
668
675
  }
676
+ /**
677
+ * Loads the document handle from the repo and waits for it to be ready.
678
+ */
679
+ async loadDoc(ctx, documentId, opts) {
680
+ let handle;
681
+ if (typeof documentId === "string") {
682
+ handle = this._repo.handles[documentId];
683
+ }
684
+ if (!handle) {
685
+ handle = this._repo.find(documentId);
686
+ }
687
+ if (!handle.isReady()) {
688
+ if (!opts?.timeout) {
689
+ await (0, import_context.cancelWithContext)(ctx, handle.whenReady());
690
+ } else {
691
+ await (0, import_context.cancelWithContext)(ctx, (0, import_async.asyncTimeout)(handle.whenReady(), opts.timeout));
692
+ }
693
+ }
694
+ return handle;
695
+ }
696
+ /**
697
+ * Create new persisted document.
698
+ */
699
+ createDoc(initialValue, opts) {
700
+ if (opts?.preserveHistory) {
701
+ if (!(0, import_automerge.isAutomerge)(initialValue)) {
702
+ throw new TypeError("Initial value must be an Automerge document");
703
+ }
704
+ return this._repo.import((0, import_automerge.save)(initialValue));
705
+ } else {
706
+ return this._repo.create(initialValue);
707
+ }
708
+ }
669
709
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
670
710
  // Hosts, running in the worker, don't share documents unless requested by other peers.
671
711
  // NOTE: If both peers return sharePolicy=false the replication will not happen
@@ -677,23 +717,8 @@ var AutomergeHost = class {
677
717
  if (!documentId) {
678
718
  return false;
679
719
  }
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
720
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
696
- if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
721
+ if (isEchoPeerMetadata(peerMetadata)) {
697
722
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
698
723
  documentId
699
724
  });
@@ -765,31 +790,36 @@ var AutomergeHost = class {
765
790
  }
766
791
  return import_keys.PublicKey.from(spaceKeyHex);
767
792
  }
768
- //
769
- // Methods for client-services.
770
- //
793
+ /**
794
+ * Flush documents to disk.
795
+ */
771
796
  async flush({ states }) {
772
- await Promise.all(states?.map(async ({ heads, documentId }) => {
773
- (0, import_invariant.invariant)(heads, "heads are required for flush", {
774
- F: __dxlog_file3,
775
- L: 237,
776
- S: this,
777
- A: [
778
- "heads",
779
- "'heads are required for flush'"
780
- ]
781
- });
782
- const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
783
- await waitForHeads(handle, heads);
784
- }) ?? []);
797
+ if (states) {
798
+ await Promise.all(states.map(async ({ heads, documentId }) => {
799
+ if (!heads) {
800
+ return;
801
+ }
802
+ const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
803
+ await waitForHeads(handle, heads);
804
+ }) ?? []);
805
+ }
785
806
  await this._repo.flush(states?.map(({ documentId }) => documentId));
786
807
  }
808
+ /**
809
+ * Host <-> Client sync.
810
+ */
787
811
  syncRepo(request) {
788
812
  return this._clientNetwork.syncRepo(request);
789
813
  }
814
+ /**
815
+ * Host <-> Client sync.
816
+ */
790
817
  sendSyncMessage(request) {
791
818
  return this._clientNetwork.sendSyncMessage(request);
792
819
  }
820
+ /**
821
+ * Host <-> Client sync.
822
+ */
793
823
  async getHostInfo() {
794
824
  return this._clientNetwork.getHostInfo();
795
825
  }
@@ -872,7 +902,7 @@ var AutomergeDocumentLoaderImpl = class {
872
902
  return;
873
903
  }
874
904
  if (!spaceState.rootUrl) {
875
- import_log3.log.error("Database opened with no rootUrl", {
905
+ import_log2.log.error("Database opened with no rootUrl", {
876
906
  spaceId: this._spaceId
877
907
  }, {
878
908
  F: __dxlog_file4,
@@ -884,7 +914,7 @@ var AutomergeDocumentLoaderImpl = class {
884
914
  } else {
885
915
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
886
916
  const doc = existingDocHandle.docSync();
887
- (0, import_invariant4.invariant)(doc, void 0, {
917
+ (0, import_invariant3.invariant)(doc, void 0, {
888
918
  F: __dxlog_file4,
889
919
  L: 77,
890
920
  S: this,
@@ -906,7 +936,7 @@ var AutomergeDocumentLoaderImpl = class {
906
936
  let hasUrlsToLoad = false;
907
937
  const urlsToLoad = {};
908
938
  for (const objectId of objectIds) {
909
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
939
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
910
940
  F: __dxlog_file4,
911
941
  L: 90,
912
942
  S: this,
@@ -919,7 +949,7 @@ var AutomergeDocumentLoaderImpl = class {
919
949
  continue;
920
950
  }
921
951
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
922
- (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
952
+ (0, import_invariant3.invariant)(spaceRootDoc, void 0, {
923
953
  F: __dxlog_file4,
924
954
  L: 95,
925
955
  S: this,
@@ -931,7 +961,7 @@ var AutomergeDocumentLoaderImpl = class {
931
961
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
932
962
  if (documentUrl == null) {
933
963
  this._objectsPendingDocumentLoad.add(objectId);
934
- import_log3.log.info("loading delayed until object links are initialized", {
964
+ import_log2.log.info("loading delayed until object links are initialized", {
935
965
  objectId
936
966
  }, {
937
967
  F: __dxlog_file4,
@@ -957,7 +987,7 @@ var AutomergeDocumentLoaderImpl = class {
957
987
  linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
958
988
  }
959
989
  getSpaceRootDocHandle() {
960
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
990
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
961
991
  F: __dxlog_file4,
962
992
  L: 122,
963
993
  S: this,
@@ -969,7 +999,7 @@ var AutomergeDocumentLoaderImpl = class {
969
999
  return this._spaceRootDocHandle;
970
1000
  }
971
1001
  createDocumentForObject(objectId) {
972
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1002
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
973
1003
  F: __dxlog_file4,
974
1004
  L: 127,
975
1005
  S: this,
@@ -1011,7 +1041,7 @@ var AutomergeDocumentLoaderImpl = class {
1011
1041
  };
1012
1042
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1013
1043
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1014
- import_log3.log.warn("object already inlined in a different document, ignoring the link", {
1044
+ import_log2.log.warn("object already inlined in a different document, ignoring the link", {
1015
1045
  ...logMeta,
1016
1046
  actualDocumentUrl: objectDocumentHandle.url
1017
1047
  }, {
@@ -1023,7 +1053,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
1053
  continue;
1024
1054
  }
1025
1055
  if (objectDocumentHandle?.url === automergeUrl) {
1026
- import_log3.log.warn("object document was already loaded", logMeta, {
1056
+ import_log2.log.warn("object document was already loaded", logMeta, {
1027
1057
  F: __dxlog_file4,
1028
1058
  L: 166,
1029
1059
  S: this,
@@ -1032,7 +1062,7 @@ var AutomergeDocumentLoaderImpl = class {
1032
1062
  continue;
1033
1063
  }
1034
1064
  const handle = this._repo.find(automergeUrl);
1035
- import_log3.log.debug("document loading triggered", logMeta, {
1065
+ import_log2.log.debug("document loading triggered", logMeta, {
1036
1066
  F: __dxlog_file4,
1037
1067
  L: 170,
1038
1068
  S: this,
@@ -1052,7 +1082,7 @@ var AutomergeDocumentLoaderImpl = class {
1052
1082
  break;
1053
1083
  } catch (err) {
1054
1084
  if (`${err}`.includes("Timeout")) {
1055
- import_log3.log.info("wraparound", {
1085
+ import_log2.log.info("wraparound", {
1056
1086
  id: docHandle.documentId,
1057
1087
  state: docHandle.state
1058
1088
  }, {
@@ -1097,7 +1127,7 @@ var AutomergeDocumentLoaderImpl = class {
1097
1127
  docUrl: handle.url
1098
1128
  };
1099
1129
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1100
- import_log3.log.info("document loaded after all listeners were removed", logMeta, {
1130
+ import_log2.log.info("document loaded after all listeners were removed", logMeta, {
1101
1131
  F: __dxlog_file4,
1102
1132
  L: 222,
1103
1133
  S: this,
@@ -1107,7 +1137,7 @@ var AutomergeDocumentLoaderImpl = class {
1107
1137
  }
1108
1138
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1109
1139
  if (objectDocHandle?.url !== handle.url) {
1110
- import_log3.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1140
+ import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1111
1141
  F: __dxlog_file4,
1112
1142
  L: 227,
1113
1143
  S: this,
@@ -1121,7 +1151,7 @@ var AutomergeDocumentLoaderImpl = class {
1121
1151
  });
1122
1152
  } catch (err) {
1123
1153
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1124
- import_log3.log.warn("failed to load a document", {
1154
+ import_log2.log.warn("failed to load a document", {
1125
1155
  objectId,
1126
1156
  automergeUrl: handle.url,
1127
1157
  retryLoading: shouldRetryLoading,
@@ -1166,7 +1196,7 @@ var MeshEchoReplicator = class {
1166
1196
  this._context = null;
1167
1197
  }
1168
1198
  createExtension() {
1169
- (0, import_invariant5.invariant)(this._context, void 0, {
1199
+ (0, import_invariant4.invariant)(this._context, void 0, {
1170
1200
  F: __dxlog_file5,
1171
1201
  L: 54,
1172
1202
  S: this,
@@ -1178,7 +1208,7 @@ var MeshEchoReplicator = class {
1178
1208
  const connection = new MeshReplicatorConnection({
1179
1209
  ownPeerId: this._context.peerId,
1180
1210
  onRemoteConnected: async () => {
1181
- (0, import_log4.log)("onRemoteConnected", {
1211
+ (0, import_log3.log)("onRemoteConnected", {
1182
1212
  peerId: connection.peerId
1183
1213
  }, {
1184
1214
  F: __dxlog_file5,
@@ -1186,7 +1216,7 @@ var MeshEchoReplicator = class {
1186
1216
  S: this,
1187
1217
  C: (f, a) => f(...a)
1188
1218
  });
1189
- (0, import_invariant5.invariant)(this._context, void 0, {
1219
+ (0, import_invariant4.invariant)(this._context, void 0, {
1190
1220
  F: __dxlog_file5,
1191
1221
  L: 60,
1192
1222
  S: this,
@@ -1204,7 +1234,7 @@ var MeshEchoReplicator = class {
1204
1234
  }
1205
1235
  },
1206
1236
  onRemoteDisconnected: async () => {
1207
- (0, import_log4.log)("onRemoteDisconnected", {
1237
+ (0, import_log3.log)("onRemoteDisconnected", {
1208
1238
  peerId: connection.peerId
1209
1239
  }, {
1210
1240
  F: __dxlog_file5,
@@ -1213,12 +1243,12 @@ var MeshEchoReplicator = class {
1213
1243
  C: (f, a) => f(...a)
1214
1244
  });
1215
1245
  this._context?.onConnectionClosed(connection);
1216
- await connection.disable();
1217
1246
  this._connectionsPerPeer.delete(connection.peerId);
1247
+ await connection.disable();
1218
1248
  this._connections.delete(connection);
1219
1249
  },
1220
1250
  shouldAdvertize: async (params) => {
1221
- (0, import_log4.log)("shouldAdvertize", {
1251
+ (0, import_log3.log)("shouldAdvertize", {
1222
1252
  peerId: connection.peerId,
1223
1253
  documentId: params.documentId
1224
1254
  }, {
@@ -1227,7 +1257,7 @@ var MeshEchoReplicator = class {
1227
1257
  S: this,
1228
1258
  C: (f, a) => f(...a)
1229
1259
  });
1230
- (0, import_invariant5.invariant)(this._context, void 0, {
1260
+ (0, import_invariant4.invariant)(this._context, void 0, {
1231
1261
  F: __dxlog_file5,
1232
1262
  L: 79,
1233
1263
  S: this,
@@ -1239,7 +1269,7 @@ var MeshEchoReplicator = class {
1239
1269
  try {
1240
1270
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1241
1271
  if (!spaceKey) {
1242
- (0, import_log4.log)("space key not found for share policy check", {
1272
+ (0, import_log3.log)("space key not found for share policy check", {
1243
1273
  peerId: connection.peerId,
1244
1274
  documentId: params.documentId
1245
1275
  }, {
@@ -1252,7 +1282,7 @@ var MeshEchoReplicator = class {
1252
1282
  }
1253
1283
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1254
1284
  if (!connection.remoteDeviceKey) {
1255
- (0, import_log4.log)("device key not found for share policy check", {
1285
+ (0, import_log3.log)("device key not found for share policy check", {
1256
1286
  peerId: connection.peerId,
1257
1287
  documentId: params.documentId
1258
1288
  }, {
@@ -1264,7 +1294,7 @@ var MeshEchoReplicator = class {
1264
1294
  return false;
1265
1295
  }
1266
1296
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1267
- (0, import_log4.log)("share policy check", {
1297
+ (0, import_log3.log)("share policy check", {
1268
1298
  localPeer: this._context.peerId,
1269
1299
  remotePeer: connection.peerId,
1270
1300
  documentId: params.documentId,
@@ -1279,7 +1309,7 @@ var MeshEchoReplicator = class {
1279
1309
  });
1280
1310
  return isAuthorized;
1281
1311
  } catch (err) {
1282
- import_log4.log.catch(err, void 0, {
1312
+ import_log3.log.catch(err, void 0, {
1283
1313
  F: __dxlog_file5,
1284
1314
  L: 111,
1285
1315
  S: this,
@@ -1293,7 +1323,7 @@ var MeshEchoReplicator = class {
1293
1323
  return connection.replicatorExtension;
1294
1324
  }
1295
1325
  authorizeDevice(spaceKey, deviceKey) {
1296
- (0, import_log4.log)("authorizeDevice", {
1326
+ (0, import_log3.log)("authorizeDevice", {
1297
1327
  spaceKey,
1298
1328
  deviceKey
1299
1329
  }, {
@@ -1303,6 +1333,11 @@ var MeshEchoReplicator = class {
1303
1333
  C: (f, a) => f(...a)
1304
1334
  });
1305
1335
  (0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1336
+ for (const connection of this._connections) {
1337
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1338
+ this._context?.onConnectionAuthScopeChanged(connection);
1339
+ }
1340
+ }
1306
1341
  }
1307
1342
  };
1308
1343
  var MeshReplicatorConnection = class extends import_context5.Resource {
@@ -1334,13 +1369,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1334
1369
  onStartReplication: async (info, remotePeerId) => {
1335
1370
  this.remoteDeviceKey = remotePeerId;
1336
1371
  this._remotePeerId = info.id;
1337
- (0, import_log4.log)("onStartReplication", {
1372
+ (0, import_log3.log)("onStartReplication", {
1338
1373
  id: info.id,
1339
1374
  thisPeerId: this.peerId,
1340
1375
  remotePeerId: remotePeerId.toHex()
1341
1376
  }, {
1342
1377
  F: __dxlog_file5,
1343
- L: 187,
1378
+ L: 192,
1344
1379
  S: this,
1345
1380
  C: (f, a) => f(...a)
1346
1381
  });
@@ -1362,9 +1397,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1362
1397
  });
1363
1398
  }
1364
1399
  get peerId() {
1365
- (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1400
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1366
1401
  F: __dxlog_file5,
1367
- L: 210,
1402
+ L: 215,
1368
1403
  S: this,
1369
1404
  A: [
1370
1405
  "this._remotePeerId != null",
@@ -1381,9 +1416,9 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1381
1416
  * Call after the remote peer has connected.
1382
1417
  */
1383
1418
  async enable() {
1384
- (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1419
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1385
1420
  F: __dxlog_file5,
1386
- L: 223,
1421
+ L: 228,
1387
1422
  S: this,
1388
1423
  A: [
1389
1424
  "this._remotePeerId != null",
@@ -1405,6 +1440,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1405
1440
  AuthStatus,
1406
1441
  AutomergeDocumentLoaderImpl,
1407
1442
  AutomergeHost,
1443
+ CredentialRetrieverExtension,
1444
+ CredentialServerExtension,
1408
1445
  DataServiceImpl,
1409
1446
  LevelDBStorageAdapter,
1410
1447
  LocalHostNetworkAdapter,