@dxos/echo-pipeline 0.5.9-main.cb71230 → 0.5.9-main.d63ef8d

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 (34) hide show
  1. package/dist/lib/browser/index.mjs +132 -215
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +133 -211
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  8. package/dist/types/src/automerge/automerge-host.d.ts +1 -8
  9. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  10. package/dist/types/src/automerge/echo-network-adapter.d.ts +6 -0
  11. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  12. package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
  13. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  14. package/dist/types/src/automerge/index.d.ts +0 -1
  15. package/dist/types/src/automerge/index.d.ts.map +1 -1
  16. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  17. package/package.json +33 -33
  18. package/src/automerge/automerge-doc-loader.ts +4 -2
  19. package/src/automerge/automerge-host.ts +8 -21
  20. package/src/automerge/echo-network-adapter.ts +24 -8
  21. package/src/automerge/echo-replicator.ts +2 -0
  22. package/src/automerge/index.ts +0 -1
  23. package/src/automerge/mesh-echo-replicator.ts +3 -1
  24. package/src/automerge/storage-adapter.test.ts +103 -139
  25. package/src/space/space-protocol.test.ts +2 -0
  26. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  27. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  28. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  29. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  30. package/dist/types/src/automerge/migrations.d.ts +0 -7
  31. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  32. package/src/automerge/automerge-storage-adapter.ts +0 -103
  33. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  34. package/src/automerge/migrations.ts +0 -42
@@ -22,7 +22,6 @@ __export(node_exports, {
22
22
  AuthStatus: () => import_chunk_QPCNQ4ZK.AuthStatus,
23
23
  AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
24
24
  AutomergeHost: () => AutomergeHost,
25
- AutomergeStorageAdapter: () => AutomergeStorageAdapter,
26
25
  DataServiceImpl: () => import_chunk_QPCNQ4ZK.DataServiceImpl,
27
26
  LevelDBStorageAdapter: () => LevelDBStorageAdapter,
28
27
  LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
@@ -71,23 +70,20 @@ var import_async3 = require("@dxos/async");
71
70
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
72
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
72
  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
73
  var import_async4 = require("@dxos/async");
79
74
  var import_context4 = require("@dxos/context");
80
75
  var import_debug = require("@dxos/debug");
76
+ var import_echo_protocol = require("@dxos/echo-protocol");
81
77
  var import_invariant4 = require("@dxos/invariant");
82
- var import_log4 = require("@dxos/log");
78
+ var import_log3 = require("@dxos/log");
83
79
  var import_tracing2 = require("@dxos/tracing");
84
80
  var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
85
81
  var import_context5 = require("@dxos/context");
86
82
  var import_invariant5 = require("@dxos/invariant");
87
83
  var import_keys2 = require("@dxos/keys");
88
- var import_log5 = require("@dxos/log");
84
+ var import_log4 = require("@dxos/log");
89
85
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
90
- var import_util3 = require("@dxos/util");
86
+ var import_util2 = require("@dxos/util");
91
87
  function _ts_decorate(decorators, target, key, desc) {
92
88
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
93
89
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -206,13 +202,14 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
206
202
  peerId: this.peerId,
207
203
  onConnectionOpen: this._onConnectionOpen.bind(this),
208
204
  onConnectionClosed: this._onConnectionClosed.bind(this),
205
+ onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
209
206
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
210
207
  });
211
208
  }
212
209
  async removeReplicator(replicator) {
213
210
  (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
214
211
  F: __dxlog_file,
215
- L: 102,
212
+ L: 103,
216
213
  S: this,
217
214
  A: [
218
215
  "this._lifecycleState === LifecycleState.OPEN",
@@ -221,14 +218,13 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
221
218
  });
222
219
  (0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
223
220
  F: __dxlog_file,
224
- L: 103,
221
+ L: 104,
225
222
  S: this,
226
223
  A: [
227
224
  "this._replicators.has(replicator)",
228
225
  ""
229
226
  ]
230
227
  });
231
- "";
232
228
  await replicator.disconnect();
233
229
  this._replicators.delete(replicator);
234
230
  }
@@ -294,27 +290,49 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
294
290
  S: this,
295
291
  C: (f, a) => f(...a)
296
292
  });
297
- this.emit("peer-candidate", {
298
- peerId: connection.peerId,
299
- peerMetadata: {
300
- // TODO(dmaretskyi): Refactor this.
301
- dxos_peerSource: "EchoNetworkAdapter"
302
- }
293
+ this._emitPeerCandidate(connection);
294
+ }
295
+ /**
296
+ * Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
297
+ * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
298
+ */
299
+ _onConnectionAuthScopeChanged(connection) {
300
+ (0, import_log2.log)("Connection auth scope changed", {
301
+ peerId: connection.peerId
302
+ }, {
303
+ F: __dxlog_file,
304
+ L: 153,
305
+ S: this,
306
+ C: (f, a) => f(...a)
303
307
  });
308
+ const entry = this._connections.get(connection.peerId);
309
+ (0, import_invariant2.invariant)(entry, void 0, {
310
+ F: __dxlog_file,
311
+ L: 155,
312
+ S: this,
313
+ A: [
314
+ "entry",
315
+ ""
316
+ ]
317
+ });
318
+ this.emit("peer-disconnected", {
319
+ peerId: connection.peerId
320
+ });
321
+ this._emitPeerCandidate(connection);
304
322
  }
305
323
  _onConnectionClosed(connection) {
306
324
  (0, import_log2.log)("Connection closed", {
307
325
  peerId: connection.peerId
308
326
  }, {
309
327
  F: __dxlog_file,
310
- L: 155,
328
+ L: 161,
311
329
  S: this,
312
330
  C: (f, a) => f(...a)
313
331
  });
314
332
  const entry = this._connections.get(connection.peerId);
315
333
  (0, import_invariant2.invariant)(entry, void 0, {
316
334
  F: __dxlog_file,
317
- L: 157,
335
+ L: 163,
318
336
  S: this,
319
337
  A: [
320
338
  "entry",
@@ -327,18 +345,27 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
327
345
  });
328
346
  void entry.reader.cancel().catch((err) => import_log2.log.catch(err, void 0, {
329
347
  F: __dxlog_file,
330
- L: 162,
348
+ L: 168,
331
349
  S: this,
332
350
  C: (f, a) => f(...a)
333
351
  }));
334
352
  void entry.writer.abort().catch((err) => import_log2.log.catch(err, void 0, {
335
353
  F: __dxlog_file,
336
- L: 163,
354
+ L: 169,
337
355
  S: this,
338
356
  C: (f, a) => f(...a)
339
357
  }));
340
358
  this._connections.delete(connection.peerId);
341
359
  }
360
+ _emitPeerCandidate(connection) {
361
+ this.emit("peer-candidate", {
362
+ peerId: connection.peerId,
363
+ peerMetadata: {
364
+ // TODO(dmaretskyi): Refactor this.
365
+ dxos_peerSource: "EchoNetworkAdapter"
366
+ }
367
+ });
368
+ }
342
369
  };
343
370
  _ts_decorate([
344
371
  import_async2.synchronized
@@ -577,108 +604,6 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
577
604
  return id;
578
605
  }
579
606
  };
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
607
  function _ts_decorate2(decorators, target, key, desc) {
683
608
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
684
609
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -689,31 +614,25 @@ function _ts_decorate2(decorators, target, key, desc) {
689
614
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
690
615
  return c > 3 && r && Object.defineProperty(target, key, r), r;
691
616
  }
692
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
617
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
693
618
  var AutomergeHost = class {
694
- constructor({ directory, db, indexMetadataStore }) {
619
+ constructor({ db, indexMetadataStore }) {
695
620
  this._ctx = new import_context.Context();
696
621
  this._echoNetworkAdapter = new EchoNetworkAdapter({
697
622
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
698
623
  });
699
624
  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
625
  this._storage = new LevelDBStorageAdapter({
711
- db: this._db,
626
+ db,
712
627
  callbacks: {
713
628
  beforeSave: async (params) => this._beforeSave(params),
714
629
  afterSave: async () => this._afterSave()
715
630
  }
716
631
  });
632
+ this._indexMetadataStore = indexMetadataStore;
633
+ }
634
+ async open() {
635
+ this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
717
636
  await this._storage.open?.();
718
637
  this._clientNetwork = new LocalHostNetworkAdapter();
719
638
  this._repo = new import_automerge_repo.Repo({
@@ -766,8 +685,8 @@ var AutomergeHost = class {
766
685
  documentId,
767
686
  isRequested
768
687
  }, {
769
- F: __dxlog_file4,
770
- L: 156,
688
+ F: __dxlog_file3,
689
+ L: 143,
771
690
  S: this,
772
691
  C: (f, a) => f(...a)
773
692
  });
@@ -852,8 +771,8 @@ var AutomergeHost = class {
852
771
  async flush({ states }) {
853
772
  await Promise.all(states?.map(async ({ heads, documentId }) => {
854
773
  (0, import_invariant.invariant)(heads, "heads are required for flush", {
855
- F: __dxlog_file4,
856
- L: 250,
774
+ F: __dxlog_file3,
775
+ L: 237,
857
776
  S: this,
858
777
  A: [
859
778
  "heads",
@@ -931,7 +850,7 @@ function _ts_decorate3(decorators, target, key, desc) {
931
850
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
932
851
  return c > 3 && r && Object.defineProperty(target, key, r), r;
933
852
  }
934
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
853
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
935
854
  var AutomergeDocumentLoaderImpl = class {
936
855
  constructor(_spaceId, _repo, _spaceKey) {
937
856
  this._spaceId = _spaceId;
@@ -953,10 +872,10 @@ var AutomergeDocumentLoaderImpl = class {
953
872
  return;
954
873
  }
955
874
  if (!spaceState.rootUrl) {
956
- import_log4.log.error("Database opened with no rootUrl", {
875
+ import_log3.log.error("Database opened with no rootUrl", {
957
876
  spaceId: this._spaceId
958
877
  }, {
959
- F: __dxlog_file5,
878
+ F: __dxlog_file4,
960
879
  L: 72,
961
880
  S: this,
962
881
  C: (f, a) => f(...a)
@@ -966,7 +885,7 @@ var AutomergeDocumentLoaderImpl = class {
966
885
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
967
886
  const doc = existingDocHandle.docSync();
968
887
  (0, import_invariant4.invariant)(doc, void 0, {
969
- F: __dxlog_file5,
888
+ F: __dxlog_file4,
970
889
  L: 77,
971
890
  S: this,
972
891
  A: [
@@ -988,7 +907,7 @@ var AutomergeDocumentLoaderImpl = class {
988
907
  const urlsToLoad = {};
989
908
  for (const objectId of objectIds) {
990
909
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
991
- F: __dxlog_file5,
910
+ F: __dxlog_file4,
992
911
  L: 90,
993
912
  S: this,
994
913
  A: [
@@ -1001,7 +920,7 @@ var AutomergeDocumentLoaderImpl = class {
1001
920
  }
1002
921
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
1003
922
  (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
1004
- F: __dxlog_file5,
923
+ F: __dxlog_file4,
1005
924
  L: 95,
1006
925
  S: this,
1007
926
  A: [
@@ -1012,10 +931,10 @@ var AutomergeDocumentLoaderImpl = class {
1012
931
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1013
932
  if (documentUrl == null) {
1014
933
  this._objectsPendingDocumentLoad.add(objectId);
1015
- import_log4.log.info("loading delayed until object links are initialized", {
934
+ import_log3.log.info("loading delayed until object links are initialized", {
1016
935
  objectId
1017
936
  }, {
1018
- F: __dxlog_file5,
937
+ F: __dxlog_file4,
1019
938
  L: 99,
1020
939
  S: this,
1021
940
  C: (f, a) => f(...a)
@@ -1039,7 +958,7 @@ var AutomergeDocumentLoaderImpl = class {
1039
958
  }
1040
959
  getSpaceRootDocHandle() {
1041
960
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1042
- F: __dxlog_file5,
961
+ F: __dxlog_file4,
1043
962
  L: 122,
1044
963
  S: this,
1045
964
  A: [
@@ -1051,7 +970,7 @@ var AutomergeDocumentLoaderImpl = class {
1051
970
  }
1052
971
  createDocumentForObject(objectId) {
1053
972
  (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1054
- F: __dxlog_file5,
973
+ F: __dxlog_file4,
1055
974
  L: 127,
1056
975
  S: this,
1057
976
  A: [
@@ -1059,7 +978,9 @@ var AutomergeDocumentLoaderImpl = class {
1059
978
  ""
1060
979
  ]
1061
980
  });
1062
- const spaceDocHandle = this._repo.create();
981
+ const spaceDocHandle = this._repo.create({
982
+ version: import_echo_protocol.SpaceDocVersion.CURRENT
983
+ });
1063
984
  this._initDocAccess(spaceDocHandle);
1064
985
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1065
986
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1090,30 +1011,30 @@ var AutomergeDocumentLoaderImpl = class {
1090
1011
  };
1091
1012
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1092
1013
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1093
- import_log4.log.warn("object already inlined in a different document, ignoring the link", {
1014
+ import_log3.log.warn("object already inlined in a different document, ignoring the link", {
1094
1015
  ...logMeta,
1095
1016
  actualDocumentUrl: objectDocumentHandle.url
1096
1017
  }, {
1097
- F: __dxlog_file5,
1098
- L: 157,
1018
+ F: __dxlog_file4,
1019
+ L: 159,
1099
1020
  S: this,
1100
1021
  C: (f, a) => f(...a)
1101
1022
  });
1102
1023
  continue;
1103
1024
  }
1104
1025
  if (objectDocumentHandle?.url === automergeUrl) {
1105
- import_log4.log.warn("object document was already loaded", logMeta, {
1106
- F: __dxlog_file5,
1107
- L: 164,
1026
+ import_log3.log.warn("object document was already loaded", logMeta, {
1027
+ F: __dxlog_file4,
1028
+ L: 166,
1108
1029
  S: this,
1109
1030
  C: (f, a) => f(...a)
1110
1031
  });
1111
1032
  continue;
1112
1033
  }
1113
1034
  const handle = this._repo.find(automergeUrl);
1114
- import_log4.log.debug("document loading triggered", logMeta, {
1115
- F: __dxlog_file5,
1116
- L: 168,
1035
+ import_log3.log.debug("document loading triggered", logMeta, {
1036
+ F: __dxlog_file4,
1037
+ L: 170,
1117
1038
  S: this,
1118
1039
  C: (f, a) => f(...a)
1119
1040
  });
@@ -1131,12 +1052,12 @@ var AutomergeDocumentLoaderImpl = class {
1131
1052
  break;
1132
1053
  } catch (err) {
1133
1054
  if (`${err}`.includes("Timeout")) {
1134
- import_log4.log.info("wraparound", {
1055
+ import_log3.log.info("wraparound", {
1135
1056
  id: docHandle.documentId,
1136
1057
  state: docHandle.state
1137
1058
  }, {
1138
- F: __dxlog_file5,
1139
- L: 184,
1059
+ F: __dxlog_file4,
1060
+ L: 186,
1140
1061
  S: this,
1141
1062
  C: (f, a) => f(...a)
1142
1063
  });
@@ -1176,9 +1097,9 @@ var AutomergeDocumentLoaderImpl = class {
1176
1097
  docUrl: handle.url
1177
1098
  };
1178
1099
  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,
1100
+ import_log3.log.info("document loaded after all listeners were removed", logMeta, {
1101
+ F: __dxlog_file4,
1102
+ L: 222,
1182
1103
  S: this,
1183
1104
  C: (f, a) => f(...a)
1184
1105
  });
@@ -1186,9 +1107,9 @@ var AutomergeDocumentLoaderImpl = class {
1186
1107
  }
1187
1108
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1188
1109
  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,
1110
+ import_log3.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1111
+ F: __dxlog_file4,
1112
+ L: 227,
1192
1113
  S: this,
1193
1114
  C: (f, a) => f(...a)
1194
1115
  });
@@ -1200,14 +1121,14 @@ var AutomergeDocumentLoaderImpl = class {
1200
1121
  });
1201
1122
  } catch (err) {
1202
1123
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1203
- import_log4.log.warn("failed to load a document", {
1124
+ import_log3.log.warn("failed to load a document", {
1204
1125
  objectId,
1205
1126
  automergeUrl: handle.url,
1206
1127
  retryLoading: shouldRetryLoading,
1207
1128
  err
1208
1129
  }, {
1209
- F: __dxlog_file5,
1210
- L: 231,
1130
+ F: __dxlog_file4,
1131
+ L: 233,
1211
1132
  S: this,
1212
1133
  C: (f, a) => f(...a)
1213
1134
  });
@@ -1225,12 +1146,12 @@ _ts_decorate3([
1225
1146
  AutomergeDocumentLoaderImpl = _ts_decorate3([
1226
1147
  import_tracing2.trace.resource()
1227
1148
  ], AutomergeDocumentLoaderImpl);
1228
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1149
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1229
1150
  var MeshEchoReplicator = class {
1230
1151
  constructor() {
1231
1152
  this._connections = /* @__PURE__ */ new Set();
1232
1153
  this._connectionsPerPeer = /* @__PURE__ */ new Map();
1233
- this._authorizedDevices = new import_util3.ComplexMap(import_keys2.PublicKey.hash);
1154
+ this._authorizedDevices = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
1234
1155
  this._context = null;
1235
1156
  }
1236
1157
  async connect(context) {
@@ -1246,7 +1167,7 @@ var MeshEchoReplicator = class {
1246
1167
  }
1247
1168
  createExtension() {
1248
1169
  (0, import_invariant5.invariant)(this._context, void 0, {
1249
- F: __dxlog_file6,
1170
+ F: __dxlog_file5,
1250
1171
  L: 54,
1251
1172
  S: this,
1252
1173
  A: [
@@ -1257,16 +1178,16 @@ var MeshEchoReplicator = class {
1257
1178
  const connection = new MeshReplicatorConnection({
1258
1179
  ownPeerId: this._context.peerId,
1259
1180
  onRemoteConnected: async () => {
1260
- (0, import_log5.log)("onRemoteConnected", {
1181
+ (0, import_log4.log)("onRemoteConnected", {
1261
1182
  peerId: connection.peerId
1262
1183
  }, {
1263
- F: __dxlog_file6,
1184
+ F: __dxlog_file5,
1264
1185
  L: 59,
1265
1186
  S: this,
1266
1187
  C: (f, a) => f(...a)
1267
1188
  });
1268
1189
  (0, import_invariant5.invariant)(this._context, void 0, {
1269
- F: __dxlog_file6,
1190
+ F: __dxlog_file5,
1270
1191
  L: 60,
1271
1192
  S: this,
1272
1193
  A: [
@@ -1274,18 +1195,20 @@ var MeshEchoReplicator = class {
1274
1195
  ""
1275
1196
  ]
1276
1197
  });
1277
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1198
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1199
+ this._context.onConnectionAuthScopeChanged(connection);
1200
+ } else {
1278
1201
  this._connectionsPerPeer.set(connection.peerId, connection);
1279
1202
  await connection.enable();
1280
1203
  this._context.onConnectionOpen(connection);
1281
1204
  }
1282
1205
  },
1283
1206
  onRemoteDisconnected: async () => {
1284
- (0, import_log5.log)("onRemoteDisconnected", {
1207
+ (0, import_log4.log)("onRemoteDisconnected", {
1285
1208
  peerId: connection.peerId
1286
1209
  }, {
1287
- F: __dxlog_file6,
1288
- L: 69,
1210
+ F: __dxlog_file5,
1211
+ L: 71,
1289
1212
  S: this,
1290
1213
  C: (f, a) => f(...a)
1291
1214
  });
@@ -1295,18 +1218,18 @@ var MeshEchoReplicator = class {
1295
1218
  this._connections.delete(connection);
1296
1219
  },
1297
1220
  shouldAdvertize: async (params) => {
1298
- (0, import_log5.log)("shouldAdvertize", {
1221
+ (0, import_log4.log)("shouldAdvertize", {
1299
1222
  peerId: connection.peerId,
1300
1223
  documentId: params.documentId
1301
1224
  }, {
1302
- F: __dxlog_file6,
1303
- L: 76,
1225
+ F: __dxlog_file5,
1226
+ L: 78,
1304
1227
  S: this,
1305
1228
  C: (f, a) => f(...a)
1306
1229
  });
1307
1230
  (0, import_invariant5.invariant)(this._context, void 0, {
1308
- F: __dxlog_file6,
1309
- L: 77,
1231
+ F: __dxlog_file5,
1232
+ L: 79,
1310
1233
  S: this,
1311
1234
  A: [
1312
1235
  "this._context",
@@ -1316,12 +1239,12 @@ var MeshEchoReplicator = class {
1316
1239
  try {
1317
1240
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1318
1241
  if (!spaceKey) {
1319
- (0, import_log5.log)("space key not found for share policy check", {
1242
+ (0, import_log4.log)("space key not found for share policy check", {
1320
1243
  peerId: connection.peerId,
1321
1244
  documentId: params.documentId
1322
1245
  }, {
1323
- F: __dxlog_file6,
1324
- L: 81,
1246
+ F: __dxlog_file5,
1247
+ L: 83,
1325
1248
  S: this,
1326
1249
  C: (f, a) => f(...a)
1327
1250
  });
@@ -1329,19 +1252,19 @@ var MeshEchoReplicator = class {
1329
1252
  }
1330
1253
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1331
1254
  if (!connection.remoteDeviceKey) {
1332
- (0, import_log5.log)("device key not found for share policy check", {
1255
+ (0, import_log4.log)("device key not found for share policy check", {
1333
1256
  peerId: connection.peerId,
1334
1257
  documentId: params.documentId
1335
1258
  }, {
1336
- F: __dxlog_file6,
1337
- L: 91,
1259
+ F: __dxlog_file5,
1260
+ L: 93,
1338
1261
  S: this,
1339
1262
  C: (f, a) => f(...a)
1340
1263
  });
1341
1264
  return false;
1342
1265
  }
1343
1266
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1344
- (0, import_log5.log)("share policy check", {
1267
+ (0, import_log4.log)("share policy check", {
1345
1268
  localPeer: this._context.peerId,
1346
1269
  remotePeer: connection.peerId,
1347
1270
  documentId: params.documentId,
@@ -1349,16 +1272,16 @@ var MeshEchoReplicator = class {
1349
1272
  spaceKey,
1350
1273
  isAuthorized
1351
1274
  }, {
1352
- F: __dxlog_file6,
1353
- L: 99,
1275
+ F: __dxlog_file5,
1276
+ L: 101,
1354
1277
  S: this,
1355
1278
  C: (f, a) => f(...a)
1356
1279
  });
1357
1280
  return isAuthorized;
1358
1281
  } catch (err) {
1359
- import_log5.log.catch(err, void 0, {
1360
- F: __dxlog_file6,
1361
- L: 109,
1282
+ import_log4.log.catch(err, void 0, {
1283
+ F: __dxlog_file5,
1284
+ L: 111,
1362
1285
  S: this,
1363
1286
  C: (f, a) => f(...a)
1364
1287
  });
@@ -1370,16 +1293,16 @@ var MeshEchoReplicator = class {
1370
1293
  return connection.replicatorExtension;
1371
1294
  }
1372
1295
  authorizeDevice(spaceKey, deviceKey) {
1373
- (0, import_log5.log)("authorizeDevice", {
1296
+ (0, import_log4.log)("authorizeDevice", {
1374
1297
  spaceKey,
1375
1298
  deviceKey
1376
1299
  }, {
1377
- F: __dxlog_file6,
1378
- L: 120,
1300
+ F: __dxlog_file5,
1301
+ L: 122,
1379
1302
  S: this,
1380
1303
  C: (f, a) => f(...a)
1381
1304
  });
1382
- (0, import_util3.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util3.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1305
+ (0, import_util2.defaultMap)(this._authorizedDevices, spaceKey, () => new import_util2.ComplexSet(import_keys2.PublicKey.hash)).add(deviceKey);
1383
1306
  }
1384
1307
  };
1385
1308
  var MeshReplicatorConnection = class extends import_context5.Resource {
@@ -1411,13 +1334,13 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1411
1334
  onStartReplication: async (info, remotePeerId) => {
1412
1335
  this.remoteDeviceKey = remotePeerId;
1413
1336
  this._remotePeerId = info.id;
1414
- (0, import_log5.log)("onStartReplication", {
1337
+ (0, import_log4.log)("onStartReplication", {
1415
1338
  id: info.id,
1416
1339
  thisPeerId: this.peerId,
1417
1340
  remotePeerId: remotePeerId.toHex()
1418
1341
  }, {
1419
- F: __dxlog_file6,
1420
- L: 185,
1342
+ F: __dxlog_file5,
1343
+ L: 187,
1421
1344
  S: this,
1422
1345
  C: (f, a) => f(...a)
1423
1346
  });
@@ -1440,8 +1363,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1440
1363
  }
1441
1364
  get peerId() {
1442
1365
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1443
- F: __dxlog_file6,
1444
- L: 208,
1366
+ F: __dxlog_file5,
1367
+ L: 210,
1445
1368
  S: this,
1446
1369
  A: [
1447
1370
  "this._remotePeerId != null",
@@ -1459,8 +1382,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1459
1382
  */
1460
1383
  async enable() {
1461
1384
  (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1462
- F: __dxlog_file6,
1463
- L: 221,
1385
+ F: __dxlog_file5,
1386
+ L: 223,
1464
1387
  S: this,
1465
1388
  A: [
1466
1389
  "this._remotePeerId != null",
@@ -1482,7 +1405,6 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1482
1405
  AuthStatus,
1483
1406
  AutomergeDocumentLoaderImpl,
1484
1407
  AutomergeHost,
1485
- AutomergeStorageAdapter,
1486
1408
  DataServiceImpl,
1487
1409
  LevelDBStorageAdapter,
1488
1410
  LocalHostNetworkAdapter,