@dxos/echo-pipeline 0.5.9-main.ea1d25b → 0.5.9-main.f099efe

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 (52) 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 +143 -231
  4. package/dist/lib/browser/index.mjs.map +4 -4
  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 +177 -260
  11. package/dist/lib/node/index.cjs.map +4 -4
  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-doc-loader.d.ts.map +1 -1
  16. package/dist/types/src/automerge/automerge-host.d.ts +1 -9
  17. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  18. package/dist/types/src/automerge/echo-network-adapter.d.ts +6 -0
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  20. package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
  21. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  22. package/dist/types/src/automerge/index.d.ts +0 -1
  23. package/dist/types/src/automerge/index.d.ts.map +1 -1
  24. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  25. package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  26. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  27. package/dist/types/src/space/index.d.ts +1 -0
  28. package/dist/types/src/space/index.d.ts.map +1 -1
  29. package/dist/types/src/space/space-manager.d.ts +8 -0
  30. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  31. package/package.json +33 -33
  32. package/src/automerge/automerge-doc-loader.test.ts +2 -3
  33. package/src/automerge/automerge-doc-loader.ts +4 -2
  34. package/src/automerge/automerge-host.ts +8 -35
  35. package/src/automerge/echo-network-adapter.ts +24 -8
  36. package/src/automerge/echo-replicator.ts +2 -0
  37. package/src/automerge/index.ts +0 -1
  38. package/src/automerge/mesh-echo-replicator.ts +9 -2
  39. package/src/automerge/storage-adapter.test.ts +103 -139
  40. package/src/space/admission-discovery-extension.ts +90 -0
  41. package/src/space/index.ts +1 -0
  42. package/src/space/space-manager.ts +46 -1
  43. package/src/space/space-protocol.test.ts +2 -0
  44. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  45. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  46. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  47. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  48. package/dist/types/src/automerge/migrations.d.ts +0 -7
  49. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  50. package/src/automerge/automerge-storage-adapter.ts +0 -103
  51. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  52. package/src/automerge/migrations.ts +0 -42
@@ -18,46 +18,46 @@ 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
- AutomergeStorageAdapter: () => AutomergeStorageAdapter,
26
- DataServiceImpl: () => import_chunk_QPCNQ4ZK.DataServiceImpl,
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: () => import_chunk_QPCNQ4ZK.MOCK_AUTH_PROVIDER,
30
- 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,
31
32
  MeshEchoReplicator: () => MeshEchoReplicator,
32
- MetadataStore: () => import_chunk_QPCNQ4ZK.MetadataStore,
33
- Pipeline: () => import_chunk_QPCNQ4ZK.Pipeline,
34
- SnapshotManager: () => import_chunk_QPCNQ4ZK.SnapshotManager,
35
- SnapshotStore: () => import_chunk_QPCNQ4ZK.SnapshotStore,
36
- Space: () => import_chunk_QPCNQ4ZK.Space,
37
- SpaceManager: () => import_chunk_QPCNQ4ZK.SpaceManager,
38
- SpaceProtocol: () => import_chunk_QPCNQ4ZK.SpaceProtocol,
39
- SpaceProtocolSession: () => import_chunk_QPCNQ4ZK.SpaceProtocolSession,
40
- TimeframeClock: () => import_chunk_QPCNQ4ZK.TimeframeClock,
41
- codec: () => import_chunk_QPCNQ4ZK.codec,
42
- createIdFromSpaceKey: () => import_chunk_QPCNQ4ZK.createIdFromSpaceKey,
43
- 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,
44
45
  encodingOptions: () => encodingOptions,
45
46
  getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
46
- hasInvitationExpired: () => import_chunk_QPCNQ4ZK.hasInvitationExpired,
47
- mapFeedIndexesToTimeframe: () => import_chunk_QPCNQ4ZK.mapFeedIndexesToTimeframe,
48
- mapTimeframeToFeedIndexes: () => import_chunk_QPCNQ4ZK.mapTimeframeToFeedIndexes,
49
- startAfter: () => import_chunk_QPCNQ4ZK.startAfter,
50
- 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
51
52
  });
52
53
  module.exports = __toCommonJS(node_exports);
53
- var import_chunk_QPCNQ4ZK = require("./chunk-QPCNQ4ZK.cjs");
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
59
  var import_invariant = require("@dxos/invariant");
59
60
  var import_keys = require("@dxos/keys");
60
- var import_log = require("@dxos/log");
61
61
  var import_protocols = require("@dxos/protocols");
62
62
  var import_tracing = require("@dxos/tracing");
63
63
  var import_util = require("@dxos/util");
@@ -65,29 +65,26 @@ var import_async2 = require("@dxos/async");
65
65
  var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
66
66
  var import_context2 = require("@dxos/context");
67
67
  var import_invariant2 = require("@dxos/invariant");
68
- var import_log2 = require("@dxos/log");
68
+ var import_log = require("@dxos/log");
69
69
  var import_context3 = require("@dxos/context");
70
70
  var import_async3 = require("@dxos/async");
71
71
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
72
72
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
73
  var import_invariant3 = require("@dxos/invariant");
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");
78
74
  var import_async4 = require("@dxos/async");
79
75
  var import_context4 = require("@dxos/context");
80
76
  var import_debug = require("@dxos/debug");
77
+ var import_echo_protocol = require("@dxos/echo-protocol");
81
78
  var import_invariant4 = require("@dxos/invariant");
82
- var import_log4 = require("@dxos/log");
79
+ var import_log2 = require("@dxos/log");
83
80
  var import_tracing2 = require("@dxos/tracing");
84
81
  var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
85
82
  var import_context5 = require("@dxos/context");
86
83
  var import_invariant5 = require("@dxos/invariant");
87
84
  var import_keys2 = require("@dxos/keys");
88
- var import_log5 = require("@dxos/log");
85
+ var import_log3 = require("@dxos/log");
89
86
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
90
- var import_util3 = require("@dxos/util");
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
- import_log2.log.catch(err, void 0, {
120
+ import_log.log.catch(err, void 0, {
124
121
  F: __dxlog_file,
125
122
  L: 49,
126
123
  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, import_log2.log)("emit ready", void 0, {
142
+ (0, import_log.log)("emit ready", void 0, {
146
143
  F: __dxlog_file,
147
144
  L: 63,
148
145
  S: this,
@@ -206,13 +203,14 @@ 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
211
  (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
214
212
  F: __dxlog_file,
215
- L: 102,
213
+ L: 103,
216
214
  S: this,
217
215
  A: [
218
216
  "this._lifecycleState === LifecycleState.OPEN",
@@ -221,14 +219,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
221
219
  });
222
220
  (0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
223
221
  F: __dxlog_file,
224
- L: 103,
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, import_log2.log)("Connection opened", {
240
+ (0, import_log.log)("Connection opened", {
244
241
  peerId: connection.peerId
245
242
  }, {
246
243
  F: __dxlog_file,
@@ -277,7 +274,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
277
274
  }
278
275
  } catch (err) {
279
276
  if (connectionEntry.isOpen) {
280
- import_log2.log.catch(err, void 0, {
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, import_log2.log)("emit peer-candidate", {
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.emit("peer-candidate", {
298
- peerId: connection.peerId,
299
- peerMetadata: {
300
- // TODO(dmaretskyi): Refactor this.
301
- dxos_peerSource: "EchoNetworkAdapter"
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_invariant2.invariant)(entry, void 0, {
311
+ F: __dxlog_file,
312
+ L: 155,
313
+ S: this,
314
+ A: [
315
+ "entry",
316
+ ""
317
+ ]
303
318
  });
319
+ this.emit("peer-disconnected", {
320
+ peerId: connection.peerId
321
+ });
322
+ this._emitPeerCandidate(connection);
304
323
  }
305
324
  _onConnectionClosed(connection) {
306
- (0, import_log2.log)("Connection closed", {
325
+ (0, import_log.log)("Connection closed", {
307
326
  peerId: connection.peerId
308
327
  }, {
309
328
  F: __dxlog_file,
310
- L: 155,
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
334
  (0, import_invariant2.invariant)(entry, void 0, {
316
335
  F: __dxlog_file,
317
- L: 157,
336
+ L: 163,
318
337
  S: this,
319
338
  A: [
320
339
  "entry",
@@ -325,20 +344,29 @@ 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) => import_log2.log.catch(err, void 0, {
347
+ void entry.reader.cancel().catch((err) => import_log.log.catch(err, void 0, {
329
348
  F: __dxlog_file,
330
- L: 162,
349
+ L: 168,
331
350
  S: this,
332
351
  C: (f, a) => f(...a)
333
352
  }));
334
- void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
353
+ void entry.writer.abort().catch((err) => import_log.log.catch(err, void 0, {
335
354
  F: __dxlog_file,
336
- L: 163,
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: {
365
+ // TODO(dmaretskyi): Refactor this.
366
+ dxos_peerSource: "EchoNetworkAdapter"
367
+ }
368
+ });
369
+ }
342
370
  };
343
371
  _ts_decorate([
344
372
  import_async2.synchronized
@@ -577,108 +605,6 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
577
605
  return id;
578
606
  }
579
607
  };
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
608
  function _ts_decorate2(decorators, target, key, desc) {
683
609
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
684
610
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -689,31 +615,27 @@ function _ts_decorate2(decorators, target, key, desc) {
689
615
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
690
616
  return c > 3 && r && Object.defineProperty(target, key, r), r;
691
617
  }
692
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
618
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
693
619
  var AutomergeHost = class {
694
- constructor({ directory, db, indexMetadataStore }) {
695
- this._ctx = new import_context.Context();
620
+ constructor({ db, indexMetadataStore }) {
621
+ this._ctx = new import_context.Context(void 0, {
622
+ F: __dxlog_file3,
623
+ L: 49
624
+ });
696
625
  this._echoNetworkAdapter = new EchoNetworkAdapter({
697
626
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
698
627
  });
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
628
  this._storage = new LevelDBStorageAdapter({
711
- db: this._db,
629
+ db,
712
630
  callbacks: {
713
631
  beforeSave: async (params) => this._beforeSave(params),
714
632
  afterSave: async () => this._afterSave()
715
633
  }
716
634
  });
635
+ this._indexMetadataStore = indexMetadataStore;
636
+ }
637
+ async open() {
638
+ this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
717
639
  await this._storage.open?.();
718
640
  this._clientNetwork = new LocalHostNetworkAdapter();
719
641
  this._repo = new import_automerge_repo.Repo({
@@ -758,21 +680,6 @@ var AutomergeHost = class {
758
680
  if (!documentId) {
759
681
  return false;
760
682
  }
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
683
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
777
684
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
778
685
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -852,8 +759,8 @@ var AutomergeHost = class {
852
759
  async flush({ states }) {
853
760
  await Promise.all(states?.map(async ({ heads, documentId }) => {
854
761
  (0, import_invariant.invariant)(heads, "heads are required for flush", {
855
- F: __dxlog_file4,
856
- L: 250,
762
+ F: __dxlog_file3,
763
+ L: 223,
857
764
  S: this,
858
765
  A: [
859
766
  "heads",
@@ -931,7 +838,7 @@ function _ts_decorate3(decorators, target, key, desc) {
931
838
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
932
839
  return c > 3 && r && Object.defineProperty(target, key, r), r;
933
840
  }
934
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
841
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
935
842
  var AutomergeDocumentLoaderImpl = class {
936
843
  constructor(_spaceId, _repo, _spaceKey) {
937
844
  this._spaceId = _spaceId;
@@ -953,10 +860,10 @@ var AutomergeDocumentLoaderImpl = class {
953
860
  return;
954
861
  }
955
862
  if (!spaceState.rootUrl) {
956
- import_log4.log.error("Database opened with no rootUrl", {
863
+ import_log2.log.error("Database opened with no rootUrl", {
957
864
  spaceId: this._spaceId
958
865
  }, {
959
- F: __dxlog_file5,
866
+ F: __dxlog_file4,
960
867
  L: 72,
961
868
  S: this,
962
869
  C: (f, a) => f(...a)
@@ -966,7 +873,7 @@ var AutomergeDocumentLoaderImpl = class {
966
873
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
967
874
  const doc = existingDocHandle.docSync();
968
875
  (0, import_invariant4.invariant)(doc, void 0, {
969
- F: __dxlog_file5,
876
+ F: __dxlog_file4,
970
877
  L: 77,
971
878
  S: this,
972
879
  A: [
@@ -988,7 +895,7 @@ var AutomergeDocumentLoaderImpl = class {
988
895
  const urlsToLoad = {};
989
896
  for (const objectId of objectIds) {
990
897
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
991
- F: __dxlog_file5,
898
+ F: __dxlog_file4,
992
899
  L: 90,
993
900
  S: this,
994
901
  A: [
@@ -1001,7 +908,7 @@ var AutomergeDocumentLoaderImpl = class {
1001
908
  }
1002
909
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
1003
910
  (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
1004
- F: __dxlog_file5,
911
+ F: __dxlog_file4,
1005
912
  L: 95,
1006
913
  S: this,
1007
914
  A: [
@@ -1012,10 +919,10 @@ var AutomergeDocumentLoaderImpl = class {
1012
919
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1013
920
  if (documentUrl == null) {
1014
921
  this._objectsPendingDocumentLoad.add(objectId);
1015
- import_log4.log.info("loading delayed until object links are initialized", {
922
+ import_log2.log.info("loading delayed until object links are initialized", {
1016
923
  objectId
1017
924
  }, {
1018
- F: __dxlog_file5,
925
+ F: __dxlog_file4,
1019
926
  L: 99,
1020
927
  S: this,
1021
928
  C: (f, a) => f(...a)
@@ -1039,7 +946,7 @@ var AutomergeDocumentLoaderImpl = class {
1039
946
  }
1040
947
  getSpaceRootDocHandle() {
1041
948
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1042
- F: __dxlog_file5,
949
+ F: __dxlog_file4,
1043
950
  L: 122,
1044
951
  S: this,
1045
952
  A: [
@@ -1051,7 +958,7 @@ var AutomergeDocumentLoaderImpl = class {
1051
958
  }
1052
959
  createDocumentForObject(objectId) {
1053
960
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1054
- F: __dxlog_file5,
961
+ F: __dxlog_file4,
1055
962
  L: 127,
1056
963
  S: this,
1057
964
  A: [
@@ -1059,7 +966,9 @@ var AutomergeDocumentLoaderImpl = class {
1059
966
  ""
1060
967
  ]
1061
968
  });
1062
- const spaceDocHandle = this._repo.create();
969
+ const spaceDocHandle = this._repo.create({
970
+ version: import_echo_protocol.SpaceDocVersion.CURRENT
971
+ });
1063
972
  this._initDocAccess(spaceDocHandle);
1064
973
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1065
974
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1090,30 +999,30 @@ var AutomergeDocumentLoaderImpl = class {
1090
999
  };
1091
1000
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1092
1001
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1093
- import_log4.log.warn("object already inlined in a different document, ignoring the link", {
1002
+ import_log2.log.warn("object already inlined in a different document, ignoring the link", {
1094
1003
  ...logMeta,
1095
1004
  actualDocumentUrl: objectDocumentHandle.url
1096
1005
  }, {
1097
- F: __dxlog_file5,
1098
- L: 157,
1006
+ F: __dxlog_file4,
1007
+ L: 159,
1099
1008
  S: this,
1100
1009
  C: (f, a) => f(...a)
1101
1010
  });
1102
1011
  continue;
1103
1012
  }
1104
1013
  if (objectDocumentHandle?.url === automergeUrl) {
1105
- import_log4.log.warn("object document was already loaded", logMeta, {
1106
- F: __dxlog_file5,
1107
- L: 164,
1014
+ import_log2.log.warn("object document was already loaded", logMeta, {
1015
+ F: __dxlog_file4,
1016
+ L: 166,
1108
1017
  S: this,
1109
1018
  C: (f, a) => f(...a)
1110
1019
  });
1111
1020
  continue;
1112
1021
  }
1113
1022
  const handle = this._repo.find(automergeUrl);
1114
- import_log4.log.debug("document loading triggered", logMeta, {
1115
- F: __dxlog_file5,
1116
- L: 168,
1023
+ import_log2.log.debug("document loading triggered", logMeta, {
1024
+ F: __dxlog_file4,
1025
+ L: 170,
1117
1026
  S: this,
1118
1027
  C: (f, a) => f(...a)
1119
1028
  });
@@ -1131,12 +1040,12 @@ var AutomergeDocumentLoaderImpl = class {
1131
1040
  break;
1132
1041
  } catch (err) {
1133
1042
  if (`${err}`.includes("Timeout")) {
1134
- import_log4.log.info("wraparound", {
1043
+ import_log2.log.info("wraparound", {
1135
1044
  id: docHandle.documentId,
1136
1045
  state: docHandle.state
1137
1046
  }, {
1138
- F: __dxlog_file5,
1139
- L: 184,
1047
+ F: __dxlog_file4,
1048
+ L: 186,
1140
1049
  S: this,
1141
1050
  C: (f, a) => f(...a)
1142
1051
  });
@@ -1176,9 +1085,9 @@ var AutomergeDocumentLoaderImpl = class {
1176
1085
  docUrl: handle.url
1177
1086
  };
1178
1087
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1179
- import_log4.log.info("document loaded after all listeners were removed", logMeta, {
1180
- F: __dxlog_file5,
1181
- L: 220,
1088
+ import_log2.log.info("document loaded after all listeners were removed", logMeta, {
1089
+ F: __dxlog_file4,
1090
+ L: 222,
1182
1091
  S: this,
1183
1092
  C: (f, a) => f(...a)
1184
1093
  });
@@ -1186,9 +1095,9 @@ var AutomergeDocumentLoaderImpl = class {
1186
1095
  }
1187
1096
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1188
1097
  if (objectDocHandle?.url !== handle.url) {
1189
- import_log4.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1190
- F: __dxlog_file5,
1191
- L: 225,
1098
+ import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1099
+ F: __dxlog_file4,
1100
+ L: 227,
1192
1101
  S: this,
1193
1102
  C: (f, a) => f(...a)
1194
1103
  });
@@ -1200,14 +1109,14 @@ var AutomergeDocumentLoaderImpl = class {
1200
1109
  });
1201
1110
  } catch (err) {
1202
1111
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1203
- import_log4.log.warn("failed to load a document", {
1112
+ import_log2.log.warn("failed to load a document", {
1204
1113
  objectId,
1205
1114
  automergeUrl: handle.url,
1206
1115
  retryLoading: shouldRetryLoading,
1207
1116
  err
1208
1117
  }, {
1209
- F: __dxlog_file5,
1210
- L: 231,
1118
+ F: __dxlog_file4,
1119
+ L: 233,
1211
1120
  S: this,
1212
1121
  C: (f, a) => f(...a)
1213
1122
  });
@@ -1225,12 +1134,12 @@ _ts_decorate3([
1225
1134
  AutomergeDocumentLoaderImpl = _ts_decorate3([
1226
1135
  import_tracing2.trace.resource()
1227
1136
  ], AutomergeDocumentLoaderImpl);
1228
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1137
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1229
1138
  var MeshEchoReplicator = class {
1230
1139
  constructor() {
1231
1140
  this._connections = /* @__PURE__ */ new Set();
1232
1141
  this._connectionsPerPeer = /* @__PURE__ */ new Map();
1233
- this._authorizedDevices = new import_util3.ComplexMap(import_keys2.PublicKey.hash);
1142
+ this._authorizedDevices = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
1234
1143
  this._context = null;
1235
1144
  }
1236
1145
  async connect(context) {
@@ -1246,7 +1155,7 @@ var MeshEchoReplicator = class {
1246
1155
  }
1247
1156
  createExtension() {
1248
1157
  (0, import_invariant5.invariant)(this._context, void 0, {
1249
- F: __dxlog_file6,
1158
+ F: __dxlog_file5,
1250
1159
  L: 54,
1251
1160
  S: this,
1252
1161
  A: [
@@ -1257,16 +1166,16 @@ var MeshEchoReplicator = class {
1257
1166
  const connection = new MeshReplicatorConnection({
1258
1167
  ownPeerId: this._context.peerId,
1259
1168
  onRemoteConnected: async () => {
1260
- (0, import_log5.log)("onRemoteConnected", {
1169
+ (0, import_log3.log)("onRemoteConnected", {
1261
1170
  peerId: connection.peerId
1262
1171
  }, {
1263
- F: __dxlog_file6,
1172
+ F: __dxlog_file5,
1264
1173
  L: 59,
1265
1174
  S: this,
1266
1175
  C: (f, a) => f(...a)
1267
1176
  });
1268
1177
  (0, import_invariant5.invariant)(this._context, void 0, {
1269
- F: __dxlog_file6,
1178
+ F: __dxlog_file5,
1270
1179
  L: 60,
1271
1180
  S: this,
1272
1181
  A: [
@@ -1274,39 +1183,41 @@ var MeshEchoReplicator = class {
1274
1183
  ""
1275
1184
  ]
1276
1185
  });
1277
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1186
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1187
+ this._context.onConnectionAuthScopeChanged(connection);
1188
+ } else {
1278
1189
  this._connectionsPerPeer.set(connection.peerId, connection);
1279
1190
  await connection.enable();
1280
1191
  this._context.onConnectionOpen(connection);
1281
1192
  }
1282
1193
  },
1283
1194
  onRemoteDisconnected: async () => {
1284
- (0, import_log5.log)("onRemoteDisconnected", {
1195
+ (0, import_log3.log)("onRemoteDisconnected", {
1285
1196
  peerId: connection.peerId
1286
1197
  }, {
1287
- F: __dxlog_file6,
1288
- L: 69,
1198
+ F: __dxlog_file5,
1199
+ L: 71,
1289
1200
  S: this,
1290
1201
  C: (f, a) => f(...a)
1291
1202
  });
1292
1203
  this._context?.onConnectionClosed(connection);
1293
- await connection.disable();
1294
1204
  this._connectionsPerPeer.delete(connection.peerId);
1205
+ await connection.disable();
1295
1206
  this._connections.delete(connection);
1296
1207
  },
1297
1208
  shouldAdvertize: async (params) => {
1298
- (0, import_log5.log)("shouldAdvertize", {
1209
+ (0, import_log3.log)("shouldAdvertize", {
1299
1210
  peerId: connection.peerId,
1300
1211
  documentId: params.documentId
1301
1212
  }, {
1302
- F: __dxlog_file6,
1303
- L: 76,
1213
+ F: __dxlog_file5,
1214
+ L: 78,
1304
1215
  S: this,
1305
1216
  C: (f, a) => f(...a)
1306
1217
  });
1307
1218
  (0, import_invariant5.invariant)(this._context, void 0, {
1308
- F: __dxlog_file6,
1309
- L: 77,
1219
+ F: __dxlog_file5,
1220
+ L: 79,
1310
1221
  S: this,
1311
1222
  A: [
1312
1223
  "this._context",
@@ -1316,12 +1227,12 @@ var MeshEchoReplicator = class {
1316
1227
  try {
1317
1228
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1318
1229
  if (!spaceKey) {
1319
- (0, import_log5.log)("space key not found for share policy check", {
1230
+ (0, import_log3.log)("space key not found for share policy check", {
1320
1231
  peerId: connection.peerId,
1321
1232
  documentId: params.documentId
1322
1233
  }, {
1323
- F: __dxlog_file6,
1324
- L: 81,
1234
+ F: __dxlog_file5,
1235
+ L: 83,
1325
1236
  S: this,
1326
1237
  C: (f, a) => f(...a)
1327
1238
  });
@@ -1329,19 +1240,19 @@ var MeshEchoReplicator = class {
1329
1240
  }
1330
1241
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1331
1242
  if (!connection.remoteDeviceKey) {
1332
- (0, import_log5.log)("device key not found for share policy check", {
1243
+ (0, import_log3.log)("device key not found for share policy check", {
1333
1244
  peerId: connection.peerId,
1334
1245
  documentId: params.documentId
1335
1246
  }, {
1336
- F: __dxlog_file6,
1337
- L: 91,
1247
+ F: __dxlog_file5,
1248
+ L: 93,
1338
1249
  S: this,
1339
1250
  C: (f, a) => f(...a)
1340
1251
  });
1341
1252
  return false;
1342
1253
  }
1343
1254
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1344
- (0, import_log5.log)("share policy check", {
1255
+ (0, import_log3.log)("share policy check", {
1345
1256
  localPeer: this._context.peerId,
1346
1257
  remotePeer: connection.peerId,
1347
1258
  documentId: params.documentId,
@@ -1349,16 +1260,16 @@ var MeshEchoReplicator = class {
1349
1260
  spaceKey,
1350
1261
  isAuthorized
1351
1262
  }, {
1352
- F: __dxlog_file6,
1353
- L: 99,
1263
+ F: __dxlog_file5,
1264
+ L: 101,
1354
1265
  S: this,
1355
1266
  C: (f, a) => f(...a)
1356
1267
  });
1357
1268
  return isAuthorized;
1358
1269
  } catch (err) {
1359
- import_log5.log.catch(err, void 0, {
1360
- F: __dxlog_file6,
1361
- L: 109,
1270
+ import_log3.log.catch(err, void 0, {
1271
+ F: __dxlog_file5,
1272
+ L: 111,
1362
1273
  S: this,
1363
1274
  C: (f, a) => f(...a)
1364
1275
  });
@@ -1370,16 +1281,21 @@ var MeshEchoReplicator = class {
1370
1281
  return connection.replicatorExtension;
1371
1282
  }
1372
1283
  authorizeDevice(spaceKey, deviceKey) {
1373
- (0, import_log5.log)("authorizeDevice", {
1284
+ (0, import_log3.log)("authorizeDevice", {
1374
1285
  spaceKey,
1375
1286
  deviceKey
1376
1287
  }, {
1377
- F: __dxlog_file6,
1378
- L: 120,
1288
+ F: __dxlog_file5,
1289
+ L: 122,
1379
1290
  S: this,
1380
1291
  C: (f, a) => f(...a)
1381
1292
  });
1382
- (0, import_util3.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util3.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1293
+ (0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1294
+ for (const connection of this._connections) {
1295
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1296
+ this._context?.onConnectionAuthScopeChanged(connection);
1297
+ }
1298
+ }
1383
1299
  }
1384
1300
  };
1385
1301
  var MeshReplicatorConnection = class extends import_context5.Resource {
@@ -1411,13 +1327,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1411
1327
  onStartReplication: async (info, remotePeerId) => {
1412
1328
  this.remoteDeviceKey = remotePeerId;
1413
1329
  this._remotePeerId = info.id;
1414
- (0, import_log5.log)("onStartReplication", {
1330
+ (0, import_log3.log)("onStartReplication", {
1415
1331
  id: info.id,
1416
1332
  thisPeerId: this.peerId,
1417
1333
  remotePeerId: remotePeerId.toHex()
1418
1334
  }, {
1419
- F: __dxlog_file6,
1420
- L: 185,
1335
+ F: __dxlog_file5,
1336
+ L: 192,
1421
1337
  S: this,
1422
1338
  C: (f, a) => f(...a)
1423
1339
  });
@@ -1440,8 +1356,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1440
1356
  }
1441
1357
  get peerId() {
1442
1358
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1443
- F: __dxlog_file6,
1444
- L: 208,
1359
+ F: __dxlog_file5,
1360
+ L: 215,
1445
1361
  S: this,
1446
1362
  A: [
1447
1363
  "this._remotePeerId != null",
@@ -1459,8 +1375,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1459
1375
  */
1460
1376
  async enable() {
1461
1377
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1462
- F: __dxlog_file6,
1463
- L: 221,
1378
+ F: __dxlog_file5,
1379
+ L: 228,
1464
1380
  S: this,
1465
1381
  A: [
1466
1382
  "this._remotePeerId != null",
@@ -1482,7 +1398,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1482
1398
  AuthStatus,
1483
1399
  AutomergeDocumentLoaderImpl,
1484
1400
  AutomergeHost,
1485
- AutomergeStorageAdapter,
1401
+ CredentialRetrieverExtension,
1402
+ CredentialServerExtension,
1486
1403
  DataServiceImpl,
1487
1404
  LevelDBStorageAdapter,
1488
1405
  LocalHostNetworkAdapter,