@dxos/echo-pipeline 0.5.9-main.07b4bad → 0.5.9-main.1c1903d

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