@dxos/echo-pipeline 0.5.9-main.bdf733d → 0.5.9-main.bfee100

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
@@ -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",
@@ -903,7 +816,7 @@ import { Event as Event2 } from "@dxos/async";
903
816
  import { cancelWithContext } from "@dxos/context";
904
817
  import { warnAfterTimeout } from "@dxos/debug";
905
818
  import { invariant as invariant4 } from "@dxos/invariant";
906
- import { log as log4 } from "@dxos/log";
819
+ import { log as log3 } from "@dxos/log";
907
820
  import { trace as trace2 } from "@dxos/tracing";
908
821
  function _ts_decorate3(decorators, target, key, desc) {
909
822
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -915,7 +828,7 @@ function _ts_decorate3(decorators, target, key, desc) {
915
828
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
916
829
  return c > 3 && r && Object.defineProperty(target, key, r), r;
917
830
  }
918
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
831
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
919
832
  var AutomergeDocumentLoaderImpl = class {
920
833
  constructor(_spaceId, _repo, _spaceKey) {
921
834
  this._spaceId = _spaceId;
@@ -937,10 +850,10 @@ var AutomergeDocumentLoaderImpl = class {
937
850
  return;
938
851
  }
939
852
  if (!spaceState.rootUrl) {
940
- log4.error("Database opened with no rootUrl", {
853
+ log3.error("Database opened with no rootUrl", {
941
854
  spaceId: this._spaceId
942
855
  }, {
943
- F: __dxlog_file5,
856
+ F: __dxlog_file4,
944
857
  L: 72,
945
858
  S: this,
946
859
  C: (f, a) => f(...a)
@@ -950,7 +863,7 @@ var AutomergeDocumentLoaderImpl = class {
950
863
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
951
864
  const doc = existingDocHandle.docSync();
952
865
  invariant4(doc, void 0, {
953
- F: __dxlog_file5,
866
+ F: __dxlog_file4,
954
867
  L: 77,
955
868
  S: this,
956
869
  A: [
@@ -972,7 +885,7 @@ var AutomergeDocumentLoaderImpl = class {
972
885
  const urlsToLoad = {};
973
886
  for (const objectId of objectIds) {
974
887
  invariant4(this._spaceRootDocHandle, void 0, {
975
- F: __dxlog_file5,
888
+ F: __dxlog_file4,
976
889
  L: 90,
977
890
  S: this,
978
891
  A: [
@@ -985,7 +898,7 @@ var AutomergeDocumentLoaderImpl = class {
985
898
  }
986
899
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
987
900
  invariant4(spaceRootDoc, void 0, {
988
- F: __dxlog_file5,
901
+ F: __dxlog_file4,
989
902
  L: 95,
990
903
  S: this,
991
904
  A: [
@@ -996,10 +909,10 @@ var AutomergeDocumentLoaderImpl = class {
996
909
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
997
910
  if (documentUrl == null) {
998
911
  this._objectsPendingDocumentLoad.add(objectId);
999
- log4.info("loading delayed until object links are initialized", {
912
+ log3.info("loading delayed until object links are initialized", {
1000
913
  objectId
1001
914
  }, {
1002
- F: __dxlog_file5,
915
+ F: __dxlog_file4,
1003
916
  L: 99,
1004
917
  S: this,
1005
918
  C: (f, a) => f(...a)
@@ -1023,7 +936,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
936
  }
1024
937
  getSpaceRootDocHandle() {
1025
938
  invariant4(this._spaceRootDocHandle, void 0, {
1026
- F: __dxlog_file5,
939
+ F: __dxlog_file4,
1027
940
  L: 122,
1028
941
  S: this,
1029
942
  A: [
@@ -1035,7 +948,7 @@ var AutomergeDocumentLoaderImpl = class {
1035
948
  }
1036
949
  createDocumentForObject(objectId) {
1037
950
  invariant4(this._spaceRootDocHandle, void 0, {
1038
- F: __dxlog_file5,
951
+ F: __dxlog_file4,
1039
952
  L: 127,
1040
953
  S: this,
1041
954
  A: [
@@ -1074,11 +987,11 @@ var AutomergeDocumentLoaderImpl = class {
1074
987
  };
1075
988
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1076
989
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1077
- log4.warn("object already inlined in a different document, ignoring the link", {
990
+ log3.warn("object already inlined in a different document, ignoring the link", {
1078
991
  ...logMeta,
1079
992
  actualDocumentUrl: objectDocumentHandle.url
1080
993
  }, {
1081
- F: __dxlog_file5,
994
+ F: __dxlog_file4,
1082
995
  L: 157,
1083
996
  S: this,
1084
997
  C: (f, a) => f(...a)
@@ -1086,8 +999,8 @@ var AutomergeDocumentLoaderImpl = class {
1086
999
  continue;
1087
1000
  }
1088
1001
  if (objectDocumentHandle?.url === automergeUrl) {
1089
- log4.warn("object document was already loaded", logMeta, {
1090
- F: __dxlog_file5,
1002
+ log3.warn("object document was already loaded", logMeta, {
1003
+ F: __dxlog_file4,
1091
1004
  L: 164,
1092
1005
  S: this,
1093
1006
  C: (f, a) => f(...a)
@@ -1095,8 +1008,8 @@ var AutomergeDocumentLoaderImpl = class {
1095
1008
  continue;
1096
1009
  }
1097
1010
  const handle = this._repo.find(automergeUrl);
1098
- log4.debug("document loading triggered", logMeta, {
1099
- F: __dxlog_file5,
1011
+ log3.debug("document loading triggered", logMeta, {
1012
+ F: __dxlog_file4,
1100
1013
  L: 168,
1101
1014
  S: this,
1102
1015
  C: (f, a) => f(...a)
@@ -1115,11 +1028,11 @@ var AutomergeDocumentLoaderImpl = class {
1115
1028
  break;
1116
1029
  } catch (err) {
1117
1030
  if (`${err}`.includes("Timeout")) {
1118
- log4.info("wraparound", {
1031
+ log3.info("wraparound", {
1119
1032
  id: docHandle.documentId,
1120
1033
  state: docHandle.state
1121
1034
  }, {
1122
- F: __dxlog_file5,
1035
+ F: __dxlog_file4,
1123
1036
  L: 184,
1124
1037
  S: this,
1125
1038
  C: (f, a) => f(...a)
@@ -1160,8 +1073,8 @@ var AutomergeDocumentLoaderImpl = class {
1160
1073
  docUrl: handle.url
1161
1074
  };
1162
1075
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1163
- log4.info("document loaded after all listeners were removed", logMeta, {
1164
- F: __dxlog_file5,
1076
+ log3.info("document loaded after all listeners were removed", logMeta, {
1077
+ F: __dxlog_file4,
1165
1078
  L: 220,
1166
1079
  S: this,
1167
1080
  C: (f, a) => f(...a)
@@ -1170,8 +1083,8 @@ var AutomergeDocumentLoaderImpl = class {
1170
1083
  }
1171
1084
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1172
1085
  if (objectDocHandle?.url !== handle.url) {
1173
- log4.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1174
- F: __dxlog_file5,
1086
+ log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1087
+ F: __dxlog_file4,
1175
1088
  L: 225,
1176
1089
  S: this,
1177
1090
  C: (f, a) => f(...a)
@@ -1184,13 +1097,13 @@ var AutomergeDocumentLoaderImpl = class {
1184
1097
  });
1185
1098
  } catch (err) {
1186
1099
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1187
- log4.warn("failed to load a document", {
1100
+ log3.warn("failed to load a document", {
1188
1101
  objectId,
1189
1102
  automergeUrl: handle.url,
1190
1103
  retryLoading: shouldRetryLoading,
1191
1104
  err
1192
1105
  }, {
1193
- F: __dxlog_file5,
1106
+ F: __dxlog_file4,
1194
1107
  L: 231,
1195
1108
  S: this,
1196
1109
  C: (f, a) => f(...a)
@@ -1215,10 +1128,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1215
1128
  import { Resource as Resource2 } from "@dxos/context";
1216
1129
  import { invariant as invariant5 } from "@dxos/invariant";
1217
1130
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1218
- import { log as log5 } from "@dxos/log";
1131
+ import { log as log4 } from "@dxos/log";
1219
1132
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1220
1133
  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";
1134
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1222
1135
  var MeshEchoReplicator = class {
1223
1136
  constructor() {
1224
1137
  this._connections = /* @__PURE__ */ new Set();
@@ -1245,7 +1158,7 @@ var MeshEchoReplicator = class {
1245
1158
  }
1246
1159
  createExtension() {
1247
1160
  invariant5(this._context, void 0, {
1248
- F: __dxlog_file6,
1161
+ F: __dxlog_file5,
1249
1162
  L: 54,
1250
1163
  S: this,
1251
1164
  A: [
@@ -1256,16 +1169,16 @@ var MeshEchoReplicator = class {
1256
1169
  const connection = new MeshReplicatorConnection({
1257
1170
  ownPeerId: this._context.peerId,
1258
1171
  onRemoteConnected: async () => {
1259
- log5("onRemoteConnected", {
1172
+ log4("onRemoteConnected", {
1260
1173
  peerId: connection.peerId
1261
1174
  }, {
1262
- F: __dxlog_file6,
1175
+ F: __dxlog_file5,
1263
1176
  L: 59,
1264
1177
  S: this,
1265
1178
  C: (f, a) => f(...a)
1266
1179
  });
1267
1180
  invariant5(this._context, void 0, {
1268
- F: __dxlog_file6,
1181
+ F: __dxlog_file5,
1269
1182
  L: 60,
1270
1183
  S: this,
1271
1184
  A: [
@@ -1273,18 +1186,20 @@ var MeshEchoReplicator = class {
1273
1186
  ""
1274
1187
  ]
1275
1188
  });
1276
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1189
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1190
+ this._context.onConnectionAuthScopeChanged(connection);
1191
+ } else {
1277
1192
  this._connectionsPerPeer.set(connection.peerId, connection);
1278
1193
  await connection.enable();
1279
1194
  this._context.onConnectionOpen(connection);
1280
1195
  }
1281
1196
  },
1282
1197
  onRemoteDisconnected: async () => {
1283
- log5("onRemoteDisconnected", {
1198
+ log4("onRemoteDisconnected", {
1284
1199
  peerId: connection.peerId
1285
1200
  }, {
1286
- F: __dxlog_file6,
1287
- L: 69,
1201
+ F: __dxlog_file5,
1202
+ L: 71,
1288
1203
  S: this,
1289
1204
  C: (f, a) => f(...a)
1290
1205
  });
@@ -1294,18 +1209,18 @@ var MeshEchoReplicator = class {
1294
1209
  this._connections.delete(connection);
1295
1210
  },
1296
1211
  shouldAdvertize: async (params) => {
1297
- log5("shouldAdvertize", {
1212
+ log4("shouldAdvertize", {
1298
1213
  peerId: connection.peerId,
1299
1214
  documentId: params.documentId
1300
1215
  }, {
1301
- F: __dxlog_file6,
1302
- L: 76,
1216
+ F: __dxlog_file5,
1217
+ L: 78,
1303
1218
  S: this,
1304
1219
  C: (f, a) => f(...a)
1305
1220
  });
1306
1221
  invariant5(this._context, void 0, {
1307
- F: __dxlog_file6,
1308
- L: 77,
1222
+ F: __dxlog_file5,
1223
+ L: 79,
1309
1224
  S: this,
1310
1225
  A: [
1311
1226
  "this._context",
@@ -1315,12 +1230,12 @@ var MeshEchoReplicator = class {
1315
1230
  try {
1316
1231
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1317
1232
  if (!spaceKey) {
1318
- log5("space key not found for share policy check", {
1233
+ log4("space key not found for share policy check", {
1319
1234
  peerId: connection.peerId,
1320
1235
  documentId: params.documentId
1321
1236
  }, {
1322
- F: __dxlog_file6,
1323
- L: 81,
1237
+ F: __dxlog_file5,
1238
+ L: 83,
1324
1239
  S: this,
1325
1240
  C: (f, a) => f(...a)
1326
1241
  });
@@ -1328,19 +1243,19 @@ var MeshEchoReplicator = class {
1328
1243
  }
1329
1244
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1330
1245
  if (!connection.remoteDeviceKey) {
1331
- log5("device key not found for share policy check", {
1246
+ log4("device key not found for share policy check", {
1332
1247
  peerId: connection.peerId,
1333
1248
  documentId: params.documentId
1334
1249
  }, {
1335
- F: __dxlog_file6,
1336
- L: 91,
1250
+ F: __dxlog_file5,
1251
+ L: 93,
1337
1252
  S: this,
1338
1253
  C: (f, a) => f(...a)
1339
1254
  });
1340
1255
  return false;
1341
1256
  }
1342
1257
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1343
- log5("share policy check", {
1258
+ log4("share policy check", {
1344
1259
  localPeer: this._context.peerId,
1345
1260
  remotePeer: connection.peerId,
1346
1261
  documentId: params.documentId,
@@ -1348,16 +1263,16 @@ var MeshEchoReplicator = class {
1348
1263
  spaceKey,
1349
1264
  isAuthorized
1350
1265
  }, {
1351
- F: __dxlog_file6,
1352
- L: 99,
1266
+ F: __dxlog_file5,
1267
+ L: 101,
1353
1268
  S: this,
1354
1269
  C: (f, a) => f(...a)
1355
1270
  });
1356
1271
  return isAuthorized;
1357
1272
  } catch (err) {
1358
- log5.catch(err, void 0, {
1359
- F: __dxlog_file6,
1360
- L: 109,
1273
+ log4.catch(err, void 0, {
1274
+ F: __dxlog_file5,
1275
+ L: 111,
1361
1276
  S: this,
1362
1277
  C: (f, a) => f(...a)
1363
1278
  });
@@ -1369,12 +1284,12 @@ var MeshEchoReplicator = class {
1369
1284
  return connection.replicatorExtension;
1370
1285
  }
1371
1286
  authorizeDevice(spaceKey, deviceKey) {
1372
- log5("authorizeDevice", {
1287
+ log4("authorizeDevice", {
1373
1288
  spaceKey,
1374
1289
  deviceKey
1375
1290
  }, {
1376
- F: __dxlog_file6,
1377
- L: 120,
1291
+ F: __dxlog_file5,
1292
+ L: 122,
1378
1293
  S: this,
1379
1294
  C: (f, a) => f(...a)
1380
1295
  });
@@ -1410,13 +1325,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1410
1325
  onStartReplication: async (info, remotePeerId) => {
1411
1326
  this.remoteDeviceKey = remotePeerId;
1412
1327
  this._remotePeerId = info.id;
1413
- log5("onStartReplication", {
1328
+ log4("onStartReplication", {
1414
1329
  id: info.id,
1415
1330
  thisPeerId: this.peerId,
1416
1331
  remotePeerId: remotePeerId.toHex()
1417
1332
  }, {
1418
- F: __dxlog_file6,
1419
- L: 185,
1333
+ F: __dxlog_file5,
1334
+ L: 187,
1420
1335
  S: this,
1421
1336
  C: (f, a) => f(...a)
1422
1337
  });
@@ -1439,8 +1354,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1439
1354
  }
1440
1355
  get peerId() {
1441
1356
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1442
- F: __dxlog_file6,
1443
- L: 208,
1357
+ F: __dxlog_file5,
1358
+ L: 210,
1444
1359
  S: this,
1445
1360
  A: [
1446
1361
  "this._remotePeerId != null",
@@ -1458,8 +1373,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1458
1373
  */
1459
1374
  async enable() {
1460
1375
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1461
- F: __dxlog_file6,
1462
- L: 221,
1376
+ F: __dxlog_file5,
1377
+ L: 223,
1463
1378
  S: this,
1464
1379
  A: [
1465
1380
  "this._remotePeerId != null",
@@ -1480,7 +1395,6 @@ export {
1480
1395
  AuthStatus,
1481
1396
  AutomergeDocumentLoaderImpl,
1482
1397
  AutomergeHost,
1483
- AutomergeStorageAdapter,
1484
1398
  DataServiceImpl,
1485
1399
  LevelDBStorageAdapter,
1486
1400
  LocalHostNetworkAdapter,