@dxos/echo-pipeline 0.5.9-main.ea1d25b → 0.5.9-next.728078d

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 (35) hide show
  1. package/dist/lib/browser/index.mjs +133 -228
  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 +145 -235
  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 -9
  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.test.ts +2 -3
  19. package/src/automerge/automerge-doc-loader.ts +4 -2
  20. package/src/automerge/automerge-host.ts +8 -35
  21. package/src/automerge/echo-network-adapter.ts +24 -8
  22. package/src/automerge/echo-replicator.ts +2 -0
  23. package/src/automerge/index.ts +0 -1
  24. package/src/automerge/mesh-echo-replicator.ts +8 -1
  25. package/src/automerge/storage-adapter.test.ts +103 -139
  26. package/src/space/space-protocol.test.ts +2 -0
  27. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  28. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  29. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  30. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  31. package/dist/types/src/automerge/migrations.d.ts +0 -7
  32. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  33. package/src/automerge/automerge-storage-adapter.ts +0 -103
  34. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  35. package/src/automerge/migrations.ts +0 -42
@@ -32,7 +32,6 @@ import { Repo } from "@dxos/automerge/automerge-repo";
32
32
  import { Context } from "@dxos/context";
33
33
  import { invariant as invariant3 } from "@dxos/invariant";
34
34
  import { PublicKey } from "@dxos/keys";
35
- import { log as log3 } from "@dxos/log";
36
35
  import { objectPointerCodec } from "@dxos/protocols";
37
36
  import { trace } from "@dxos/tracing";
38
37
  import { mapValues } from "@dxos/util";
@@ -161,13 +160,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
161
160
  peerId: this.peerId,
162
161
  onConnectionOpen: this._onConnectionOpen.bind(this),
163
162
  onConnectionClosed: this._onConnectionClosed.bind(this),
163
+ onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
164
164
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
165
165
  });
166
166
  }
167
167
  async removeReplicator(replicator) {
168
168
  invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
169
169
  F: __dxlog_file,
170
- L: 102,
170
+ L: 103,
171
171
  S: this,
172
172
  A: [
173
173
  "this._lifecycleState === LifecycleState.OPEN",
@@ -176,14 +176,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
176
176
  });
177
177
  invariant(this._replicators.has(replicator), void 0, {
178
178
  F: __dxlog_file,
179
- L: 103,
179
+ L: 104,
180
180
  S: this,
181
181
  A: [
182
182
  "this._replicators.has(replicator)",
183
183
  ""
184
184
  ]
185
185
  });
186
- "";
187
186
  await replicator.disconnect();
188
187
  this._replicators.delete(replicator);
189
188
  }
@@ -249,27 +248,49 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
249
248
  S: this,
250
249
  C: (f, a) => f(...a)
251
250
  });
252
- this.emit("peer-candidate", {
253
- peerId: connection.peerId,
254
- peerMetadata: {
255
- // TODO(dmaretskyi): Refactor this.
256
- dxos_peerSource: "EchoNetworkAdapter"
257
- }
251
+ this._emitPeerCandidate(connection);
252
+ }
253
+ /**
254
+ * Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
255
+ * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
256
+ */
257
+ _onConnectionAuthScopeChanged(connection) {
258
+ log("Connection auth scope changed", {
259
+ peerId: connection.peerId
260
+ }, {
261
+ F: __dxlog_file,
262
+ L: 153,
263
+ S: this,
264
+ C: (f, a) => f(...a)
265
+ });
266
+ const entry = this._connections.get(connection.peerId);
267
+ invariant(entry, void 0, {
268
+ F: __dxlog_file,
269
+ L: 155,
270
+ S: this,
271
+ A: [
272
+ "entry",
273
+ ""
274
+ ]
275
+ });
276
+ this.emit("peer-disconnected", {
277
+ peerId: connection.peerId
258
278
  });
279
+ this._emitPeerCandidate(connection);
259
280
  }
260
281
  _onConnectionClosed(connection) {
261
282
  log("Connection closed", {
262
283
  peerId: connection.peerId
263
284
  }, {
264
285
  F: __dxlog_file,
265
- L: 155,
286
+ L: 161,
266
287
  S: this,
267
288
  C: (f, a) => f(...a)
268
289
  });
269
290
  const entry = this._connections.get(connection.peerId);
270
291
  invariant(entry, void 0, {
271
292
  F: __dxlog_file,
272
- L: 157,
293
+ L: 163,
273
294
  S: this,
274
295
  A: [
275
296
  "entry",
@@ -282,18 +303,27 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
282
303
  });
283
304
  void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
284
305
  F: __dxlog_file,
285
- L: 162,
306
+ L: 168,
286
307
  S: this,
287
308
  C: (f, a) => f(...a)
288
309
  }));
289
310
  void entry.writer.abort().catch((err) => log.catch(err, void 0, {
290
311
  F: __dxlog_file,
291
- L: 163,
312
+ L: 169,
292
313
  S: this,
293
314
  C: (f, a) => f(...a)
294
315
  }));
295
316
  this._connections.delete(connection.peerId);
296
317
  }
318
+ _emitPeerCandidate(connection) {
319
+ this.emit("peer-candidate", {
320
+ peerId: connection.peerId,
321
+ peerMetadata: {
322
+ // TODO(dmaretskyi): Refactor this.
323
+ dxos_peerSource: "EchoNetworkAdapter"
324
+ }
325
+ });
326
+ }
297
327
  };
298
328
  _ts_decorate([
299
329
  synchronized
@@ -542,118 +572,6 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
542
572
  }
543
573
  };
544
574
 
545
- // packages/core/echo/echo-pipeline/src/automerge/migrations.ts
546
- import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
547
- import { log as log2 } from "@dxos/log";
548
- import { StorageType } from "@dxos/random-access-storage";
549
-
550
- // packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
551
- import { arrayToBuffer, bufferToArray } from "@dxos/util";
552
- var AutomergeStorageAdapter = class {
553
- constructor(_directory) {
554
- this._directory = _directory;
555
- this._state = "opened";
556
- }
557
- async load(key) {
558
- if (this._state !== "opened") {
559
- return void 0;
560
- }
561
- const filename = this._getFilename(key);
562
- const file = this._directory.getOrCreateFile(filename);
563
- const { size } = await file.stat();
564
- if (!size || size === 0) {
565
- return void 0;
566
- }
567
- const buffer = await file.read(0, size);
568
- return bufferToArray(buffer);
569
- }
570
- async save(key, data) {
571
- if (this._state !== "opened") {
572
- return void 0;
573
- }
574
- const filename = this._getFilename(key);
575
- const file = this._directory.getOrCreateFile(filename);
576
- await file.write(0, arrayToBuffer(data));
577
- await file.truncate?.(data.length);
578
- await file.flush?.();
579
- }
580
- async remove(key) {
581
- if (this._state !== "opened") {
582
- return void 0;
583
- }
584
- const filename = this._getFilename(key);
585
- const file = this._directory.getOrCreateFile(filename);
586
- await file.destroy();
587
- }
588
- async loadRange(keyPrefix) {
589
- if (this._state !== "opened") {
590
- return [];
591
- }
592
- const filename = this._getFilename(keyPrefix);
593
- const entries = await this._directory.list();
594
- return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
595
- const file = this._directory.getOrCreateFile(entry);
596
- const { size } = await file.stat();
597
- const buffer = await file.read(0, size);
598
- return {
599
- key: this._getKeyFromFilename(entry),
600
- data: bufferToArray(buffer)
601
- };
602
- }));
603
- }
604
- async removeRange(keyPrefix) {
605
- if (this._state !== "opened") {
606
- return void 0;
607
- }
608
- const filename = this._getFilename(keyPrefix);
609
- const entries = await this._directory.list();
610
- await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
611
- const file = this._directory.getOrCreateFile(entry);
612
- await file.destroy();
613
- }));
614
- }
615
- async close() {
616
- this._state = "closed";
617
- }
618
- _getFilename(key) {
619
- return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
620
- }
621
- _getKeyFromFilename(filename) {
622
- return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
623
- }
624
- };
625
-
626
- // packages/core/echo/echo-pipeline/src/automerge/migrations.ts
627
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
628
- var levelMigration = async ({ db, directory }) => {
629
- const isNewLevel = !await db.iterator({
630
- ...encodingOptions
631
- }).next();
632
- if (!isNewLevel) {
633
- return;
634
- }
635
- const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
636
- const chunks = await oldStorageAdapter.loadRange([]);
637
- if (chunks.length === 0) {
638
- return;
639
- }
640
- const batch = db.batch();
641
- log2.info("found chunks on old storage adapter", {
642
- chunks: chunks.length
643
- }, {
644
- F: __dxlog_file3,
645
- L: 37,
646
- S: void 0,
647
- C: (f, a) => f(...a)
648
- });
649
- for (const { key, data } of await oldStorageAdapter.loadRange([])) {
650
- data && batch.put(key, data, {
651
- ...encodingOptions
652
- });
653
- }
654
- await batch.write();
655
- };
656
-
657
575
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
658
576
  function _ts_decorate2(decorators, target, key, desc) {
659
577
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -665,31 +583,24 @@ function _ts_decorate2(decorators, target, key, desc) {
665
583
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
666
584
  return c > 3 && r && Object.defineProperty(target, key, r), r;
667
585
  }
668
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
586
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
669
587
  var AutomergeHost = class {
670
- constructor({ directory, db, indexMetadataStore }) {
588
+ constructor({ db, indexMetadataStore }) {
671
589
  this._ctx = new Context();
672
590
  this._echoNetworkAdapter = new EchoNetworkAdapter({
673
591
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
674
592
  });
675
- this._requestedDocs = /* @__PURE__ */ new Set();
676
- this._directory = directory;
677
- this._db = db;
678
- this._indexMetadataStore = indexMetadataStore;
679
- }
680
- async open() {
681
- this._peerId = `host-${PublicKey.random().toHex()}`;
682
- this._directory && await levelMigration({
683
- db: this._db,
684
- directory: this._directory
685
- });
686
593
  this._storage = new LevelDBStorageAdapter({
687
- db: this._db,
594
+ db,
688
595
  callbacks: {
689
596
  beforeSave: async (params) => this._beforeSave(params),
690
597
  afterSave: async () => this._afterSave()
691
598
  }
692
599
  });
600
+ this._indexMetadataStore = indexMetadataStore;
601
+ }
602
+ async open() {
603
+ this._peerId = `host-${PublicKey.random().toHex()}`;
693
604
  await this._storage.open?.();
694
605
  this._clientNetwork = new LocalHostNetworkAdapter();
695
606
  this._repo = new Repo({
@@ -734,21 +645,6 @@ var AutomergeHost = class {
734
645
  if (!documentId) {
735
646
  return false;
736
647
  }
737
- const doc = this._repo.handles[documentId]?.docSync();
738
- if (!doc) {
739
- const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
740
- log3("doc share policy check", {
741
- peerId,
742
- documentId,
743
- isRequested
744
- }, {
745
- F: __dxlog_file4,
746
- L: 156,
747
- S: this,
748
- C: (f, a) => f(...a)
749
- });
750
- return isRequested;
751
- }
752
648
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
753
649
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
754
650
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -828,8 +724,8 @@ var AutomergeHost = class {
828
724
  async flush({ states }) {
829
725
  await Promise.all(states?.map(async ({ heads, documentId }) => {
830
726
  invariant3(heads, "heads are required for flush", {
831
- F: __dxlog_file4,
832
- L: 250,
727
+ F: __dxlog_file3,
728
+ L: 223,
833
729
  S: this,
834
730
  A: [
835
731
  "heads",
@@ -902,8 +798,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
902
798
  import { Event as Event2 } from "@dxos/async";
903
799
  import { cancelWithContext } from "@dxos/context";
904
800
  import { warnAfterTimeout } from "@dxos/debug";
801
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
905
802
  import { invariant as invariant4 } from "@dxos/invariant";
906
- import { log as log4 } from "@dxos/log";
803
+ import { log as log2 } from "@dxos/log";
907
804
  import { trace as trace2 } from "@dxos/tracing";
908
805
  function _ts_decorate3(decorators, target, key, desc) {
909
806
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -915,7 +812,7 @@ function _ts_decorate3(decorators, target, key, desc) {
915
812
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
916
813
  return c > 3 && r && Object.defineProperty(target, key, r), r;
917
814
  }
918
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
815
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
919
816
  var AutomergeDocumentLoaderImpl = class {
920
817
  constructor(_spaceId, _repo, _spaceKey) {
921
818
  this._spaceId = _spaceId;
@@ -937,10 +834,10 @@ var AutomergeDocumentLoaderImpl = class {
937
834
  return;
938
835
  }
939
836
  if (!spaceState.rootUrl) {
940
- log4.error("Database opened with no rootUrl", {
837
+ log2.error("Database opened with no rootUrl", {
941
838
  spaceId: this._spaceId
942
839
  }, {
943
- F: __dxlog_file5,
840
+ F: __dxlog_file4,
944
841
  L: 72,
945
842
  S: this,
946
843
  C: (f, a) => f(...a)
@@ -950,7 +847,7 @@ var AutomergeDocumentLoaderImpl = class {
950
847
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
951
848
  const doc = existingDocHandle.docSync();
952
849
  invariant4(doc, void 0, {
953
- F: __dxlog_file5,
850
+ F: __dxlog_file4,
954
851
  L: 77,
955
852
  S: this,
956
853
  A: [
@@ -972,7 +869,7 @@ var AutomergeDocumentLoaderImpl = class {
972
869
  const urlsToLoad = {};
973
870
  for (const objectId of objectIds) {
974
871
  invariant4(this._spaceRootDocHandle, void 0, {
975
- F: __dxlog_file5,
872
+ F: __dxlog_file4,
976
873
  L: 90,
977
874
  S: this,
978
875
  A: [
@@ -985,7 +882,7 @@ var AutomergeDocumentLoaderImpl = class {
985
882
  }
986
883
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
987
884
  invariant4(spaceRootDoc, void 0, {
988
- F: __dxlog_file5,
885
+ F: __dxlog_file4,
989
886
  L: 95,
990
887
  S: this,
991
888
  A: [
@@ -996,10 +893,10 @@ var AutomergeDocumentLoaderImpl = class {
996
893
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
997
894
  if (documentUrl == null) {
998
895
  this._objectsPendingDocumentLoad.add(objectId);
999
- log4.info("loading delayed until object links are initialized", {
896
+ log2.info("loading delayed until object links are initialized", {
1000
897
  objectId
1001
898
  }, {
1002
- F: __dxlog_file5,
899
+ F: __dxlog_file4,
1003
900
  L: 99,
1004
901
  S: this,
1005
902
  C: (f, a) => f(...a)
@@ -1023,7 +920,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
920
  }
1024
921
  getSpaceRootDocHandle() {
1025
922
  invariant4(this._spaceRootDocHandle, void 0, {
1026
- F: __dxlog_file5,
923
+ F: __dxlog_file4,
1027
924
  L: 122,
1028
925
  S: this,
1029
926
  A: [
@@ -1035,7 +932,7 @@ var AutomergeDocumentLoaderImpl = class {
1035
932
  }
1036
933
  createDocumentForObject(objectId) {
1037
934
  invariant4(this._spaceRootDocHandle, void 0, {
1038
- F: __dxlog_file5,
935
+ F: __dxlog_file4,
1039
936
  L: 127,
1040
937
  S: this,
1041
938
  A: [
@@ -1043,7 +940,9 @@ var AutomergeDocumentLoaderImpl = class {
1043
940
  ""
1044
941
  ]
1045
942
  });
1046
- const spaceDocHandle = this._repo.create();
943
+ const spaceDocHandle = this._repo.create({
944
+ version: SpaceDocVersion.CURRENT
945
+ });
1047
946
  this._initDocAccess(spaceDocHandle);
1048
947
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1049
948
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1074,30 +973,30 @@ var AutomergeDocumentLoaderImpl = class {
1074
973
  };
1075
974
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1076
975
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1077
- log4.warn("object already inlined in a different document, ignoring the link", {
976
+ log2.warn("object already inlined in a different document, ignoring the link", {
1078
977
  ...logMeta,
1079
978
  actualDocumentUrl: objectDocumentHandle.url
1080
979
  }, {
1081
- F: __dxlog_file5,
1082
- L: 157,
980
+ F: __dxlog_file4,
981
+ L: 159,
1083
982
  S: this,
1084
983
  C: (f, a) => f(...a)
1085
984
  });
1086
985
  continue;
1087
986
  }
1088
987
  if (objectDocumentHandle?.url === automergeUrl) {
1089
- log4.warn("object document was already loaded", logMeta, {
1090
- F: __dxlog_file5,
1091
- L: 164,
988
+ log2.warn("object document was already loaded", logMeta, {
989
+ F: __dxlog_file4,
990
+ L: 166,
1092
991
  S: this,
1093
992
  C: (f, a) => f(...a)
1094
993
  });
1095
994
  continue;
1096
995
  }
1097
996
  const handle = this._repo.find(automergeUrl);
1098
- log4.debug("document loading triggered", logMeta, {
1099
- F: __dxlog_file5,
1100
- L: 168,
997
+ log2.debug("document loading triggered", logMeta, {
998
+ F: __dxlog_file4,
999
+ L: 170,
1101
1000
  S: this,
1102
1001
  C: (f, a) => f(...a)
1103
1002
  });
@@ -1115,12 +1014,12 @@ var AutomergeDocumentLoaderImpl = class {
1115
1014
  break;
1116
1015
  } catch (err) {
1117
1016
  if (`${err}`.includes("Timeout")) {
1118
- log4.info("wraparound", {
1017
+ log2.info("wraparound", {
1119
1018
  id: docHandle.documentId,
1120
1019
  state: docHandle.state
1121
1020
  }, {
1122
- F: __dxlog_file5,
1123
- L: 184,
1021
+ F: __dxlog_file4,
1022
+ L: 186,
1124
1023
  S: this,
1125
1024
  C: (f, a) => f(...a)
1126
1025
  });
@@ -1160,9 +1059,9 @@ var AutomergeDocumentLoaderImpl = class {
1160
1059
  docUrl: handle.url
1161
1060
  };
1162
1061
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1163
- log4.info("document loaded after all listeners were removed", logMeta, {
1164
- F: __dxlog_file5,
1165
- L: 220,
1062
+ log2.info("document loaded after all listeners were removed", logMeta, {
1063
+ F: __dxlog_file4,
1064
+ L: 222,
1166
1065
  S: this,
1167
1066
  C: (f, a) => f(...a)
1168
1067
  });
@@ -1170,9 +1069,9 @@ var AutomergeDocumentLoaderImpl = class {
1170
1069
  }
1171
1070
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1172
1071
  if (objectDocHandle?.url !== handle.url) {
1173
- log4.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1174
- F: __dxlog_file5,
1175
- L: 225,
1072
+ log2.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1073
+ F: __dxlog_file4,
1074
+ L: 227,
1176
1075
  S: this,
1177
1076
  C: (f, a) => f(...a)
1178
1077
  });
@@ -1184,14 +1083,14 @@ var AutomergeDocumentLoaderImpl = class {
1184
1083
  });
1185
1084
  } catch (err) {
1186
1085
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1187
- log4.warn("failed to load a document", {
1086
+ log2.warn("failed to load a document", {
1188
1087
  objectId,
1189
1088
  automergeUrl: handle.url,
1190
1089
  retryLoading: shouldRetryLoading,
1191
1090
  err
1192
1091
  }, {
1193
- F: __dxlog_file5,
1194
- L: 231,
1092
+ F: __dxlog_file4,
1093
+ L: 233,
1195
1094
  S: this,
1196
1095
  C: (f, a) => f(...a)
1197
1096
  });
@@ -1215,10 +1114,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1215
1114
  import { Resource as Resource2 } from "@dxos/context";
1216
1115
  import { invariant as invariant5 } from "@dxos/invariant";
1217
1116
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1218
- import { log as log5 } from "@dxos/log";
1117
+ import { log as log3 } from "@dxos/log";
1219
1118
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1220
1119
  import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
1221
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1120
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1222
1121
  var MeshEchoReplicator = class {
1223
1122
  constructor() {
1224
1123
  this._connections = /* @__PURE__ */ new Set();
@@ -1245,7 +1144,7 @@ var MeshEchoReplicator = class {
1245
1144
  }
1246
1145
  createExtension() {
1247
1146
  invariant5(this._context, void 0, {
1248
- F: __dxlog_file6,
1147
+ F: __dxlog_file5,
1249
1148
  L: 54,
1250
1149
  S: this,
1251
1150
  A: [
@@ -1256,16 +1155,16 @@ var MeshEchoReplicator = class {
1256
1155
  const connection = new MeshReplicatorConnection({
1257
1156
  ownPeerId: this._context.peerId,
1258
1157
  onRemoteConnected: async () => {
1259
- log5("onRemoteConnected", {
1158
+ log3("onRemoteConnected", {
1260
1159
  peerId: connection.peerId
1261
1160
  }, {
1262
- F: __dxlog_file6,
1161
+ F: __dxlog_file5,
1263
1162
  L: 59,
1264
1163
  S: this,
1265
1164
  C: (f, a) => f(...a)
1266
1165
  });
1267
1166
  invariant5(this._context, void 0, {
1268
- F: __dxlog_file6,
1167
+ F: __dxlog_file5,
1269
1168
  L: 60,
1270
1169
  S: this,
1271
1170
  A: [
@@ -1273,18 +1172,20 @@ var MeshEchoReplicator = class {
1273
1172
  ""
1274
1173
  ]
1275
1174
  });
1276
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1175
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1176
+ this._context.onConnectionAuthScopeChanged(connection);
1177
+ } else {
1277
1178
  this._connectionsPerPeer.set(connection.peerId, connection);
1278
1179
  await connection.enable();
1279
1180
  this._context.onConnectionOpen(connection);
1280
1181
  }
1281
1182
  },
1282
1183
  onRemoteDisconnected: async () => {
1283
- log5("onRemoteDisconnected", {
1184
+ log3("onRemoteDisconnected", {
1284
1185
  peerId: connection.peerId
1285
1186
  }, {
1286
- F: __dxlog_file6,
1287
- L: 69,
1187
+ F: __dxlog_file5,
1188
+ L: 71,
1288
1189
  S: this,
1289
1190
  C: (f, a) => f(...a)
1290
1191
  });
@@ -1294,18 +1195,18 @@ var MeshEchoReplicator = class {
1294
1195
  this._connections.delete(connection);
1295
1196
  },
1296
1197
  shouldAdvertize: async (params) => {
1297
- log5("shouldAdvertize", {
1198
+ log3("shouldAdvertize", {
1298
1199
  peerId: connection.peerId,
1299
1200
  documentId: params.documentId
1300
1201
  }, {
1301
- F: __dxlog_file6,
1302
- L: 76,
1202
+ F: __dxlog_file5,
1203
+ L: 78,
1303
1204
  S: this,
1304
1205
  C: (f, a) => f(...a)
1305
1206
  });
1306
1207
  invariant5(this._context, void 0, {
1307
- F: __dxlog_file6,
1308
- L: 77,
1208
+ F: __dxlog_file5,
1209
+ L: 79,
1309
1210
  S: this,
1310
1211
  A: [
1311
1212
  "this._context",
@@ -1315,12 +1216,12 @@ var MeshEchoReplicator = class {
1315
1216
  try {
1316
1217
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1317
1218
  if (!spaceKey) {
1318
- log5("space key not found for share policy check", {
1219
+ log3("space key not found for share policy check", {
1319
1220
  peerId: connection.peerId,
1320
1221
  documentId: params.documentId
1321
1222
  }, {
1322
- F: __dxlog_file6,
1323
- L: 81,
1223
+ F: __dxlog_file5,
1224
+ L: 83,
1324
1225
  S: this,
1325
1226
  C: (f, a) => f(...a)
1326
1227
  });
@@ -1328,19 +1229,19 @@ var MeshEchoReplicator = class {
1328
1229
  }
1329
1230
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1330
1231
  if (!connection.remoteDeviceKey) {
1331
- log5("device key not found for share policy check", {
1232
+ log3("device key not found for share policy check", {
1332
1233
  peerId: connection.peerId,
1333
1234
  documentId: params.documentId
1334
1235
  }, {
1335
- F: __dxlog_file6,
1336
- L: 91,
1236
+ F: __dxlog_file5,
1237
+ L: 93,
1337
1238
  S: this,
1338
1239
  C: (f, a) => f(...a)
1339
1240
  });
1340
1241
  return false;
1341
1242
  }
1342
1243
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1343
- log5("share policy check", {
1244
+ log3("share policy check", {
1344
1245
  localPeer: this._context.peerId,
1345
1246
  remotePeer: connection.peerId,
1346
1247
  documentId: params.documentId,
@@ -1348,16 +1249,16 @@ var MeshEchoReplicator = class {
1348
1249
  spaceKey,
1349
1250
  isAuthorized
1350
1251
  }, {
1351
- F: __dxlog_file6,
1352
- L: 99,
1252
+ F: __dxlog_file5,
1253
+ L: 101,
1353
1254
  S: this,
1354
1255
  C: (f, a) => f(...a)
1355
1256
  });
1356
1257
  return isAuthorized;
1357
1258
  } catch (err) {
1358
- log5.catch(err, void 0, {
1359
- F: __dxlog_file6,
1360
- L: 109,
1259
+ log3.catch(err, void 0, {
1260
+ F: __dxlog_file5,
1261
+ L: 111,
1361
1262
  S: this,
1362
1263
  C: (f, a) => f(...a)
1363
1264
  });
@@ -1369,16 +1270,21 @@ var MeshEchoReplicator = class {
1369
1270
  return connection.replicatorExtension;
1370
1271
  }
1371
1272
  authorizeDevice(spaceKey, deviceKey) {
1372
- log5("authorizeDevice", {
1273
+ log3("authorizeDevice", {
1373
1274
  spaceKey,
1374
1275
  deviceKey
1375
1276
  }, {
1376
- F: __dxlog_file6,
1377
- L: 120,
1277
+ F: __dxlog_file5,
1278
+ L: 122,
1378
1279
  S: this,
1379
1280
  C: (f, a) => f(...a)
1380
1281
  });
1381
1282
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey2.hash)).add(deviceKey);
1283
+ for (const connection of this._connections) {
1284
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1285
+ this._context?.onConnectionAuthScopeChanged(connection);
1286
+ }
1287
+ }
1382
1288
  }
1383
1289
  };
1384
1290
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1410,13 +1316,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1410
1316
  onStartReplication: async (info, remotePeerId) => {
1411
1317
  this.remoteDeviceKey = remotePeerId;
1412
1318
  this._remotePeerId = info.id;
1413
- log5("onStartReplication", {
1319
+ log3("onStartReplication", {
1414
1320
  id: info.id,
1415
1321
  thisPeerId: this.peerId,
1416
1322
  remotePeerId: remotePeerId.toHex()
1417
1323
  }, {
1418
- F: __dxlog_file6,
1419
- L: 185,
1324
+ F: __dxlog_file5,
1325
+ L: 192,
1420
1326
  S: this,
1421
1327
  C: (f, a) => f(...a)
1422
1328
  });
@@ -1439,8 +1345,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1439
1345
  }
1440
1346
  get peerId() {
1441
1347
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1442
- F: __dxlog_file6,
1443
- L: 208,
1348
+ F: __dxlog_file5,
1349
+ L: 215,
1444
1350
  S: this,
1445
1351
  A: [
1446
1352
  "this._remotePeerId != null",
@@ -1458,8 +1364,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1458
1364
  */
1459
1365
  async enable() {
1460
1366
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1461
- F: __dxlog_file6,
1462
- L: 221,
1367
+ F: __dxlog_file5,
1368
+ L: 228,
1463
1369
  S: this,
1464
1370
  A: [
1465
1371
  "this._remotePeerId != null",
@@ -1480,7 +1386,6 @@ export {
1480
1386
  AuthStatus,
1481
1387
  AutomergeDocumentLoaderImpl,
1482
1388
  AutomergeHost,
1483
- AutomergeStorageAdapter,
1484
1389
  DataServiceImpl,
1485
1390
  LevelDBStorageAdapter,
1486
1391
  LocalHostNetworkAdapter,