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

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
@@ -32,7 +32,7 @@ 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";
35
+ import { log as log2 } from "@dxos/log";
36
36
  import { objectPointerCodec } from "@dxos/protocols";
37
37
  import { trace } from "@dxos/tracing";
38
38
  import { mapValues } from "@dxos/util";
@@ -161,13 +161,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
161
161
  peerId: this.peerId,
162
162
  onConnectionOpen: this._onConnectionOpen.bind(this),
163
163
  onConnectionClosed: this._onConnectionClosed.bind(this),
164
+ onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
164
165
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
165
166
  });
166
167
  }
167
168
  async removeReplicator(replicator) {
168
169
  invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
169
170
  F: __dxlog_file,
170
- L: 102,
171
+ L: 103,
171
172
  S: this,
172
173
  A: [
173
174
  "this._lifecycleState === LifecycleState.OPEN",
@@ -176,14 +177,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
176
177
  });
177
178
  invariant(this._replicators.has(replicator), void 0, {
178
179
  F: __dxlog_file,
179
- L: 103,
180
+ L: 104,
180
181
  S: this,
181
182
  A: [
182
183
  "this._replicators.has(replicator)",
183
184
  ""
184
185
  ]
185
186
  });
186
- "";
187
187
  await replicator.disconnect();
188
188
  this._replicators.delete(replicator);
189
189
  }
@@ -249,27 +249,49 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
249
249
  S: this,
250
250
  C: (f, a) => f(...a)
251
251
  });
252
- this.emit("peer-candidate", {
253
- peerId: connection.peerId,
254
- peerMetadata: {
255
- // TODO(dmaretskyi): Refactor this.
256
- dxos_peerSource: "EchoNetworkAdapter"
257
- }
252
+ this._emitPeerCandidate(connection);
253
+ }
254
+ /**
255
+ * Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
256
+ * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
257
+ */
258
+ _onConnectionAuthScopeChanged(connection) {
259
+ log("Connection auth scope changed", {
260
+ peerId: connection.peerId
261
+ }, {
262
+ F: __dxlog_file,
263
+ L: 153,
264
+ S: this,
265
+ C: (f, a) => f(...a)
266
+ });
267
+ const entry = this._connections.get(connection.peerId);
268
+ invariant(entry, void 0, {
269
+ F: __dxlog_file,
270
+ L: 155,
271
+ S: this,
272
+ A: [
273
+ "entry",
274
+ ""
275
+ ]
276
+ });
277
+ this.emit("peer-disconnected", {
278
+ peerId: connection.peerId
258
279
  });
280
+ this._emitPeerCandidate(connection);
259
281
  }
260
282
  _onConnectionClosed(connection) {
261
283
  log("Connection closed", {
262
284
  peerId: connection.peerId
263
285
  }, {
264
286
  F: __dxlog_file,
265
- L: 155,
287
+ L: 161,
266
288
  S: this,
267
289
  C: (f, a) => f(...a)
268
290
  });
269
291
  const entry = this._connections.get(connection.peerId);
270
292
  invariant(entry, void 0, {
271
293
  F: __dxlog_file,
272
- L: 157,
294
+ L: 163,
273
295
  S: this,
274
296
  A: [
275
297
  "entry",
@@ -282,18 +304,27 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
282
304
  });
283
305
  void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
284
306
  F: __dxlog_file,
285
- L: 162,
307
+ L: 168,
286
308
  S: this,
287
309
  C: (f, a) => f(...a)
288
310
  }));
289
311
  void entry.writer.abort().catch((err) => log.catch(err, void 0, {
290
312
  F: __dxlog_file,
291
- L: 163,
313
+ L: 169,
292
314
  S: this,
293
315
  C: (f, a) => f(...a)
294
316
  }));
295
317
  this._connections.delete(connection.peerId);
296
318
  }
319
+ _emitPeerCandidate(connection) {
320
+ this.emit("peer-candidate", {
321
+ peerId: connection.peerId,
322
+ peerMetadata: {
323
+ // TODO(dmaretskyi): Refactor this.
324
+ dxos_peerSource: "EchoNetworkAdapter"
325
+ }
326
+ });
327
+ }
297
328
  };
298
329
  _ts_decorate([
299
330
  synchronized
@@ -542,118 +573,6 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
542
573
  }
543
574
  };
544
575
 
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
576
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
658
577
  function _ts_decorate2(decorators, target, key, desc) {
659
578
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -665,31 +584,25 @@ function _ts_decorate2(decorators, target, key, desc) {
665
584
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
666
585
  return c > 3 && r && Object.defineProperty(target, key, r), r;
667
586
  }
668
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
587
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
669
588
  var AutomergeHost = class {
670
- constructor({ directory, db, indexMetadataStore }) {
589
+ constructor({ db, indexMetadataStore }) {
671
590
  this._ctx = new Context();
672
591
  this._echoNetworkAdapter = new EchoNetworkAdapter({
673
592
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
674
593
  });
675
594
  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
595
  this._storage = new LevelDBStorageAdapter({
687
- db: this._db,
596
+ db,
688
597
  callbacks: {
689
598
  beforeSave: async (params) => this._beforeSave(params),
690
599
  afterSave: async () => this._afterSave()
691
600
  }
692
601
  });
602
+ this._indexMetadataStore = indexMetadataStore;
603
+ }
604
+ async open() {
605
+ this._peerId = `host-${PublicKey.random().toHex()}`;
693
606
  await this._storage.open?.();
694
607
  this._clientNetwork = new LocalHostNetworkAdapter();
695
608
  this._repo = new Repo({
@@ -737,13 +650,13 @@ var AutomergeHost = class {
737
650
  const doc = this._repo.handles[documentId]?.docSync();
738
651
  if (!doc) {
739
652
  const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
740
- log3("doc share policy check", {
653
+ log2("doc share policy check", {
741
654
  peerId,
742
655
  documentId,
743
656
  isRequested
744
657
  }, {
745
- F: __dxlog_file4,
746
- L: 156,
658
+ F: __dxlog_file3,
659
+ L: 143,
747
660
  S: this,
748
661
  C: (f, a) => f(...a)
749
662
  });
@@ -828,8 +741,8 @@ var AutomergeHost = class {
828
741
  async flush({ states }) {
829
742
  await Promise.all(states?.map(async ({ heads, documentId }) => {
830
743
  invariant3(heads, "heads are required for flush", {
831
- F: __dxlog_file4,
832
- L: 250,
744
+ F: __dxlog_file3,
745
+ L: 237,
833
746
  S: this,
834
747
  A: [
835
748
  "heads",
@@ -902,8 +815,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
902
815
  import { Event as Event2 } from "@dxos/async";
903
816
  import { cancelWithContext } from "@dxos/context";
904
817
  import { warnAfterTimeout } from "@dxos/debug";
818
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
905
819
  import { invariant as invariant4 } from "@dxos/invariant";
906
- import { log as log4 } from "@dxos/log";
820
+ import { log as log3 } from "@dxos/log";
907
821
  import { trace as trace2 } from "@dxos/tracing";
908
822
  function _ts_decorate3(decorators, target, key, desc) {
909
823
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -915,7 +829,7 @@ function _ts_decorate3(decorators, target, key, desc) {
915
829
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
916
830
  return c > 3 && r && Object.defineProperty(target, key, r), r;
917
831
  }
918
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
832
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
919
833
  var AutomergeDocumentLoaderImpl = class {
920
834
  constructor(_spaceId, _repo, _spaceKey) {
921
835
  this._spaceId = _spaceId;
@@ -937,10 +851,10 @@ var AutomergeDocumentLoaderImpl = class {
937
851
  return;
938
852
  }
939
853
  if (!spaceState.rootUrl) {
940
- log4.error("Database opened with no rootUrl", {
854
+ log3.error("Database opened with no rootUrl", {
941
855
  spaceId: this._spaceId
942
856
  }, {
943
- F: __dxlog_file5,
857
+ F: __dxlog_file4,
944
858
  L: 72,
945
859
  S: this,
946
860
  C: (f, a) => f(...a)
@@ -950,7 +864,7 @@ var AutomergeDocumentLoaderImpl = class {
950
864
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
951
865
  const doc = existingDocHandle.docSync();
952
866
  invariant4(doc, void 0, {
953
- F: __dxlog_file5,
867
+ F: __dxlog_file4,
954
868
  L: 77,
955
869
  S: this,
956
870
  A: [
@@ -972,7 +886,7 @@ var AutomergeDocumentLoaderImpl = class {
972
886
  const urlsToLoad = {};
973
887
  for (const objectId of objectIds) {
974
888
  invariant4(this._spaceRootDocHandle, void 0, {
975
- F: __dxlog_file5,
889
+ F: __dxlog_file4,
976
890
  L: 90,
977
891
  S: this,
978
892
  A: [
@@ -985,7 +899,7 @@ var AutomergeDocumentLoaderImpl = class {
985
899
  }
986
900
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
987
901
  invariant4(spaceRootDoc, void 0, {
988
- F: __dxlog_file5,
902
+ F: __dxlog_file4,
989
903
  L: 95,
990
904
  S: this,
991
905
  A: [
@@ -996,10 +910,10 @@ var AutomergeDocumentLoaderImpl = class {
996
910
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
997
911
  if (documentUrl == null) {
998
912
  this._objectsPendingDocumentLoad.add(objectId);
999
- log4.info("loading delayed until object links are initialized", {
913
+ log3.info("loading delayed until object links are initialized", {
1000
914
  objectId
1001
915
  }, {
1002
- F: __dxlog_file5,
916
+ F: __dxlog_file4,
1003
917
  L: 99,
1004
918
  S: this,
1005
919
  C: (f, a) => f(...a)
@@ -1023,7 +937,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
937
  }
1024
938
  getSpaceRootDocHandle() {
1025
939
  invariant4(this._spaceRootDocHandle, void 0, {
1026
- F: __dxlog_file5,
940
+ F: __dxlog_file4,
1027
941
  L: 122,
1028
942
  S: this,
1029
943
  A: [
@@ -1035,7 +949,7 @@ var AutomergeDocumentLoaderImpl = class {
1035
949
  }
1036
950
  createDocumentForObject(objectId) {
1037
951
  invariant4(this._spaceRootDocHandle, void 0, {
1038
- F: __dxlog_file5,
952
+ F: __dxlog_file4,
1039
953
  L: 127,
1040
954
  S: this,
1041
955
  A: [
@@ -1043,7 +957,9 @@ var AutomergeDocumentLoaderImpl = class {
1043
957
  ""
1044
958
  ]
1045
959
  });
1046
- const spaceDocHandle = this._repo.create();
960
+ const spaceDocHandle = this._repo.create({
961
+ version: SpaceDocVersion.CURRENT
962
+ });
1047
963
  this._initDocAccess(spaceDocHandle);
1048
964
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1049
965
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1074,30 +990,30 @@ var AutomergeDocumentLoaderImpl = class {
1074
990
  };
1075
991
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1076
992
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1077
- log4.warn("object already inlined in a different document, ignoring the link", {
993
+ log3.warn("object already inlined in a different document, ignoring the link", {
1078
994
  ...logMeta,
1079
995
  actualDocumentUrl: objectDocumentHandle.url
1080
996
  }, {
1081
- F: __dxlog_file5,
1082
- L: 157,
997
+ F: __dxlog_file4,
998
+ L: 159,
1083
999
  S: this,
1084
1000
  C: (f, a) => f(...a)
1085
1001
  });
1086
1002
  continue;
1087
1003
  }
1088
1004
  if (objectDocumentHandle?.url === automergeUrl) {
1089
- log4.warn("object document was already loaded", logMeta, {
1090
- F: __dxlog_file5,
1091
- L: 164,
1005
+ log3.warn("object document was already loaded", logMeta, {
1006
+ F: __dxlog_file4,
1007
+ L: 166,
1092
1008
  S: this,
1093
1009
  C: (f, a) => f(...a)
1094
1010
  });
1095
1011
  continue;
1096
1012
  }
1097
1013
  const handle = this._repo.find(automergeUrl);
1098
- log4.debug("document loading triggered", logMeta, {
1099
- F: __dxlog_file5,
1100
- L: 168,
1014
+ log3.debug("document loading triggered", logMeta, {
1015
+ F: __dxlog_file4,
1016
+ L: 170,
1101
1017
  S: this,
1102
1018
  C: (f, a) => f(...a)
1103
1019
  });
@@ -1115,12 +1031,12 @@ var AutomergeDocumentLoaderImpl = class {
1115
1031
  break;
1116
1032
  } catch (err) {
1117
1033
  if (`${err}`.includes("Timeout")) {
1118
- log4.info("wraparound", {
1034
+ log3.info("wraparound", {
1119
1035
  id: docHandle.documentId,
1120
1036
  state: docHandle.state
1121
1037
  }, {
1122
- F: __dxlog_file5,
1123
- L: 184,
1038
+ F: __dxlog_file4,
1039
+ L: 186,
1124
1040
  S: this,
1125
1041
  C: (f, a) => f(...a)
1126
1042
  });
@@ -1160,9 +1076,9 @@ var AutomergeDocumentLoaderImpl = class {
1160
1076
  docUrl: handle.url
1161
1077
  };
1162
1078
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1163
- log4.info("document loaded after all listeners were removed", logMeta, {
1164
- F: __dxlog_file5,
1165
- L: 220,
1079
+ log3.info("document loaded after all listeners were removed", logMeta, {
1080
+ F: __dxlog_file4,
1081
+ L: 222,
1166
1082
  S: this,
1167
1083
  C: (f, a) => f(...a)
1168
1084
  });
@@ -1170,9 +1086,9 @@ var AutomergeDocumentLoaderImpl = class {
1170
1086
  }
1171
1087
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1172
1088
  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,
1089
+ log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1090
+ F: __dxlog_file4,
1091
+ L: 227,
1176
1092
  S: this,
1177
1093
  C: (f, a) => f(...a)
1178
1094
  });
@@ -1184,14 +1100,14 @@ var AutomergeDocumentLoaderImpl = class {
1184
1100
  });
1185
1101
  } catch (err) {
1186
1102
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1187
- log4.warn("failed to load a document", {
1103
+ log3.warn("failed to load a document", {
1188
1104
  objectId,
1189
1105
  automergeUrl: handle.url,
1190
1106
  retryLoading: shouldRetryLoading,
1191
1107
  err
1192
1108
  }, {
1193
- F: __dxlog_file5,
1194
- L: 231,
1109
+ F: __dxlog_file4,
1110
+ L: 233,
1195
1111
  S: this,
1196
1112
  C: (f, a) => f(...a)
1197
1113
  });
@@ -1215,10 +1131,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1215
1131
  import { Resource as Resource2 } from "@dxos/context";
1216
1132
  import { invariant as invariant5 } from "@dxos/invariant";
1217
1133
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1218
- import { log as log5 } from "@dxos/log";
1134
+ import { log as log4 } from "@dxos/log";
1219
1135
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1220
1136
  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";
1137
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1222
1138
  var MeshEchoReplicator = class {
1223
1139
  constructor() {
1224
1140
  this._connections = /* @__PURE__ */ new Set();
@@ -1245,7 +1161,7 @@ var MeshEchoReplicator = class {
1245
1161
  }
1246
1162
  createExtension() {
1247
1163
  invariant5(this._context, void 0, {
1248
- F: __dxlog_file6,
1164
+ F: __dxlog_file5,
1249
1165
  L: 54,
1250
1166
  S: this,
1251
1167
  A: [
@@ -1256,16 +1172,16 @@ var MeshEchoReplicator = class {
1256
1172
  const connection = new MeshReplicatorConnection({
1257
1173
  ownPeerId: this._context.peerId,
1258
1174
  onRemoteConnected: async () => {
1259
- log5("onRemoteConnected", {
1175
+ log4("onRemoteConnected", {
1260
1176
  peerId: connection.peerId
1261
1177
  }, {
1262
- F: __dxlog_file6,
1178
+ F: __dxlog_file5,
1263
1179
  L: 59,
1264
1180
  S: this,
1265
1181
  C: (f, a) => f(...a)
1266
1182
  });
1267
1183
  invariant5(this._context, void 0, {
1268
- F: __dxlog_file6,
1184
+ F: __dxlog_file5,
1269
1185
  L: 60,
1270
1186
  S: this,
1271
1187
  A: [
@@ -1273,18 +1189,20 @@ var MeshEchoReplicator = class {
1273
1189
  ""
1274
1190
  ]
1275
1191
  });
1276
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1192
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1193
+ this._context.onConnectionAuthScopeChanged(connection);
1194
+ } else {
1277
1195
  this._connectionsPerPeer.set(connection.peerId, connection);
1278
1196
  await connection.enable();
1279
1197
  this._context.onConnectionOpen(connection);
1280
1198
  }
1281
1199
  },
1282
1200
  onRemoteDisconnected: async () => {
1283
- log5("onRemoteDisconnected", {
1201
+ log4("onRemoteDisconnected", {
1284
1202
  peerId: connection.peerId
1285
1203
  }, {
1286
- F: __dxlog_file6,
1287
- L: 69,
1204
+ F: __dxlog_file5,
1205
+ L: 71,
1288
1206
  S: this,
1289
1207
  C: (f, a) => f(...a)
1290
1208
  });
@@ -1294,18 +1212,18 @@ var MeshEchoReplicator = class {
1294
1212
  this._connections.delete(connection);
1295
1213
  },
1296
1214
  shouldAdvertize: async (params) => {
1297
- log5("shouldAdvertize", {
1215
+ log4("shouldAdvertize", {
1298
1216
  peerId: connection.peerId,
1299
1217
  documentId: params.documentId
1300
1218
  }, {
1301
- F: __dxlog_file6,
1302
- L: 76,
1219
+ F: __dxlog_file5,
1220
+ L: 78,
1303
1221
  S: this,
1304
1222
  C: (f, a) => f(...a)
1305
1223
  });
1306
1224
  invariant5(this._context, void 0, {
1307
- F: __dxlog_file6,
1308
- L: 77,
1225
+ F: __dxlog_file5,
1226
+ L: 79,
1309
1227
  S: this,
1310
1228
  A: [
1311
1229
  "this._context",
@@ -1315,12 +1233,12 @@ var MeshEchoReplicator = class {
1315
1233
  try {
1316
1234
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1317
1235
  if (!spaceKey) {
1318
- log5("space key not found for share policy check", {
1236
+ log4("space key not found for share policy check", {
1319
1237
  peerId: connection.peerId,
1320
1238
  documentId: params.documentId
1321
1239
  }, {
1322
- F: __dxlog_file6,
1323
- L: 81,
1240
+ F: __dxlog_file5,
1241
+ L: 83,
1324
1242
  S: this,
1325
1243
  C: (f, a) => f(...a)
1326
1244
  });
@@ -1328,19 +1246,19 @@ var MeshEchoReplicator = class {
1328
1246
  }
1329
1247
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1330
1248
  if (!connection.remoteDeviceKey) {
1331
- log5("device key not found for share policy check", {
1249
+ log4("device key not found for share policy check", {
1332
1250
  peerId: connection.peerId,
1333
1251
  documentId: params.documentId
1334
1252
  }, {
1335
- F: __dxlog_file6,
1336
- L: 91,
1253
+ F: __dxlog_file5,
1254
+ L: 93,
1337
1255
  S: this,
1338
1256
  C: (f, a) => f(...a)
1339
1257
  });
1340
1258
  return false;
1341
1259
  }
1342
1260
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1343
- log5("share policy check", {
1261
+ log4("share policy check", {
1344
1262
  localPeer: this._context.peerId,
1345
1263
  remotePeer: connection.peerId,
1346
1264
  documentId: params.documentId,
@@ -1348,16 +1266,16 @@ var MeshEchoReplicator = class {
1348
1266
  spaceKey,
1349
1267
  isAuthorized
1350
1268
  }, {
1351
- F: __dxlog_file6,
1352
- L: 99,
1269
+ F: __dxlog_file5,
1270
+ L: 101,
1353
1271
  S: this,
1354
1272
  C: (f, a) => f(...a)
1355
1273
  });
1356
1274
  return isAuthorized;
1357
1275
  } catch (err) {
1358
- log5.catch(err, void 0, {
1359
- F: __dxlog_file6,
1360
- L: 109,
1276
+ log4.catch(err, void 0, {
1277
+ F: __dxlog_file5,
1278
+ L: 111,
1361
1279
  S: this,
1362
1280
  C: (f, a) => f(...a)
1363
1281
  });
@@ -1369,12 +1287,12 @@ var MeshEchoReplicator = class {
1369
1287
  return connection.replicatorExtension;
1370
1288
  }
1371
1289
  authorizeDevice(spaceKey, deviceKey) {
1372
- log5("authorizeDevice", {
1290
+ log4("authorizeDevice", {
1373
1291
  spaceKey,
1374
1292
  deviceKey
1375
1293
  }, {
1376
- F: __dxlog_file6,
1377
- L: 120,
1294
+ F: __dxlog_file5,
1295
+ L: 122,
1378
1296
  S: this,
1379
1297
  C: (f, a) => f(...a)
1380
1298
  });
@@ -1410,13 +1328,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1410
1328
  onStartReplication: async (info, remotePeerId) => {
1411
1329
  this.remoteDeviceKey = remotePeerId;
1412
1330
  this._remotePeerId = info.id;
1413
- log5("onStartReplication", {
1331
+ log4("onStartReplication", {
1414
1332
  id: info.id,
1415
1333
  thisPeerId: this.peerId,
1416
1334
  remotePeerId: remotePeerId.toHex()
1417
1335
  }, {
1418
- F: __dxlog_file6,
1419
- L: 185,
1336
+ F: __dxlog_file5,
1337
+ L: 187,
1420
1338
  S: this,
1421
1339
  C: (f, a) => f(...a)
1422
1340
  });
@@ -1439,8 +1357,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1439
1357
  }
1440
1358
  get peerId() {
1441
1359
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1442
- F: __dxlog_file6,
1443
- L: 208,
1360
+ F: __dxlog_file5,
1361
+ L: 210,
1444
1362
  S: this,
1445
1363
  A: [
1446
1364
  "this._remotePeerId != null",
@@ -1458,8 +1376,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1458
1376
  */
1459
1377
  async enable() {
1460
1378
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1461
- F: __dxlog_file6,
1462
- L: 221,
1379
+ F: __dxlog_file5,
1380
+ L: 223,
1463
1381
  S: this,
1464
1382
  A: [
1465
1383
  "this._remotePeerId != null",
@@ -1480,7 +1398,6 @@ export {
1480
1398
  AuthStatus,
1481
1399
  AutomergeDocumentLoaderImpl,
1482
1400
  AutomergeHost,
1483
- AutomergeStorageAdapter,
1484
1401
  DataServiceImpl,
1485
1402
  LevelDBStorageAdapter,
1486
1403
  LocalHostNetworkAdapter,