@dxos/echo-pipeline 0.5.9-main.ea1d25b → 0.5.9-main.eacfffa

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 (43) hide show
  1. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-ZCEMVITI.mjs} +28 -7
  2. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs.map → chunk-ZCEMVITI.mjs.map} +1 -1
  3. package/dist/lib/browser/index.mjs +138 -230
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +11 -7
  7. package/dist/lib/browser/testing/index.mjs.map +1 -1
  8. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs → chunk-V2O4ACHA.cjs} +31 -10
  9. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs.map → chunk-V2O4ACHA.cjs.map} +1 -1
  10. package/dist/lib/node/index.cjs +172 -259
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +21 -17
  14. package/dist/lib/node/testing/index.cjs.map +1 -1
  15. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  16. package/dist/types/src/automerge/automerge-host.d.ts +1 -9
  17. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  18. package/dist/types/src/automerge/echo-network-adapter.d.ts +6 -0
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  20. package/dist/types/src/automerge/echo-replicator.d.ts +1 -0
  21. package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
  22. package/dist/types/src/automerge/index.d.ts +0 -1
  23. package/dist/types/src/automerge/index.d.ts.map +1 -1
  24. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  25. package/package.json +33 -33
  26. package/src/automerge/automerge-doc-loader.test.ts +2 -3
  27. package/src/automerge/automerge-doc-loader.ts +4 -2
  28. package/src/automerge/automerge-host.ts +8 -35
  29. package/src/automerge/echo-network-adapter.ts +24 -8
  30. package/src/automerge/echo-replicator.ts +2 -0
  31. package/src/automerge/index.ts +0 -1
  32. package/src/automerge/mesh-echo-replicator.ts +8 -1
  33. package/src/automerge/storage-adapter.test.ts +103 -139
  34. package/src/space/space-protocol.test.ts +2 -0
  35. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  36. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  37. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  38. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  39. package/dist/types/src/automerge/migrations.d.ts +0 -7
  40. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  41. package/src/automerge/automerge-storage-adapter.ts +0 -103
  42. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  43. package/src/automerge/migrations.ts +0 -42
@@ -23,7 +23,7 @@ import {
23
23
  mapTimeframeToFeedIndexes,
24
24
  startAfter,
25
25
  valueEncoding
26
- } from "./chunk-I2J5TTHJ.mjs";
26
+ } from "./chunk-ZCEMVITI.mjs";
27
27
 
28
28
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
29
29
  import { Event } from "@dxos/async";
@@ -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)
258
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
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,27 @@ 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 }) {
671
- this._ctx = new Context();
588
+ constructor({ db, indexMetadataStore }) {
589
+ this._ctx = new Context(void 0, {
590
+ F: __dxlog_file3,
591
+ L: 49
592
+ });
672
593
  this._echoNetworkAdapter = new EchoNetworkAdapter({
673
594
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
674
595
  });
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
596
  this._storage = new LevelDBStorageAdapter({
687
- db: this._db,
597
+ db,
688
598
  callbacks: {
689
599
  beforeSave: async (params) => this._beforeSave(params),
690
600
  afterSave: async () => this._afterSave()
691
601
  }
692
602
  });
603
+ this._indexMetadataStore = indexMetadataStore;
604
+ }
605
+ async open() {
606
+ this._peerId = `host-${PublicKey.random().toHex()}`;
693
607
  await this._storage.open?.();
694
608
  this._clientNetwork = new LocalHostNetworkAdapter();
695
609
  this._repo = new Repo({
@@ -734,21 +648,6 @@ var AutomergeHost = class {
734
648
  if (!documentId) {
735
649
  return false;
736
650
  }
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
651
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
753
652
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
754
653
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -828,8 +727,8 @@ var AutomergeHost = class {
828
727
  async flush({ states }) {
829
728
  await Promise.all(states?.map(async ({ heads, documentId }) => {
830
729
  invariant3(heads, "heads are required for flush", {
831
- F: __dxlog_file4,
832
- L: 250,
730
+ F: __dxlog_file3,
731
+ L: 223,
833
732
  S: this,
834
733
  A: [
835
734
  "heads",
@@ -902,8 +801,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
902
801
  import { Event as Event2 } from "@dxos/async";
903
802
  import { cancelWithContext } from "@dxos/context";
904
803
  import { warnAfterTimeout } from "@dxos/debug";
804
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
905
805
  import { invariant as invariant4 } from "@dxos/invariant";
906
- import { log as log4 } from "@dxos/log";
806
+ import { log as log2 } from "@dxos/log";
907
807
  import { trace as trace2 } from "@dxos/tracing";
908
808
  function _ts_decorate3(decorators, target, key, desc) {
909
809
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -915,7 +815,7 @@ function _ts_decorate3(decorators, target, key, desc) {
915
815
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
916
816
  return c > 3 && r && Object.defineProperty(target, key, r), r;
917
817
  }
918
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
818
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
919
819
  var AutomergeDocumentLoaderImpl = class {
920
820
  constructor(_spaceId, _repo, _spaceKey) {
921
821
  this._spaceId = _spaceId;
@@ -937,10 +837,10 @@ var AutomergeDocumentLoaderImpl = class {
937
837
  return;
938
838
  }
939
839
  if (!spaceState.rootUrl) {
940
- log4.error("Database opened with no rootUrl", {
840
+ log2.error("Database opened with no rootUrl", {
941
841
  spaceId: this._spaceId
942
842
  }, {
943
- F: __dxlog_file5,
843
+ F: __dxlog_file4,
944
844
  L: 72,
945
845
  S: this,
946
846
  C: (f, a) => f(...a)
@@ -950,7 +850,7 @@ var AutomergeDocumentLoaderImpl = class {
950
850
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
951
851
  const doc = existingDocHandle.docSync();
952
852
  invariant4(doc, void 0, {
953
- F: __dxlog_file5,
853
+ F: __dxlog_file4,
954
854
  L: 77,
955
855
  S: this,
956
856
  A: [
@@ -972,7 +872,7 @@ var AutomergeDocumentLoaderImpl = class {
972
872
  const urlsToLoad = {};
973
873
  for (const objectId of objectIds) {
974
874
  invariant4(this._spaceRootDocHandle, void 0, {
975
- F: __dxlog_file5,
875
+ F: __dxlog_file4,
976
876
  L: 90,
977
877
  S: this,
978
878
  A: [
@@ -985,7 +885,7 @@ var AutomergeDocumentLoaderImpl = class {
985
885
  }
986
886
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
987
887
  invariant4(spaceRootDoc, void 0, {
988
- F: __dxlog_file5,
888
+ F: __dxlog_file4,
989
889
  L: 95,
990
890
  S: this,
991
891
  A: [
@@ -996,10 +896,10 @@ var AutomergeDocumentLoaderImpl = class {
996
896
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
997
897
  if (documentUrl == null) {
998
898
  this._objectsPendingDocumentLoad.add(objectId);
999
- log4.info("loading delayed until object links are initialized", {
899
+ log2.info("loading delayed until object links are initialized", {
1000
900
  objectId
1001
901
  }, {
1002
- F: __dxlog_file5,
902
+ F: __dxlog_file4,
1003
903
  L: 99,
1004
904
  S: this,
1005
905
  C: (f, a) => f(...a)
@@ -1023,7 +923,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
923
  }
1024
924
  getSpaceRootDocHandle() {
1025
925
  invariant4(this._spaceRootDocHandle, void 0, {
1026
- F: __dxlog_file5,
926
+ F: __dxlog_file4,
1027
927
  L: 122,
1028
928
  S: this,
1029
929
  A: [
@@ -1035,7 +935,7 @@ var AutomergeDocumentLoaderImpl = class {
1035
935
  }
1036
936
  createDocumentForObject(objectId) {
1037
937
  invariant4(this._spaceRootDocHandle, void 0, {
1038
- F: __dxlog_file5,
938
+ F: __dxlog_file4,
1039
939
  L: 127,
1040
940
  S: this,
1041
941
  A: [
@@ -1043,7 +943,9 @@ var AutomergeDocumentLoaderImpl = class {
1043
943
  ""
1044
944
  ]
1045
945
  });
1046
- const spaceDocHandle = this._repo.create();
946
+ const spaceDocHandle = this._repo.create({
947
+ version: SpaceDocVersion.CURRENT
948
+ });
1047
949
  this._initDocAccess(spaceDocHandle);
1048
950
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1049
951
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1074,30 +976,30 @@ var AutomergeDocumentLoaderImpl = class {
1074
976
  };
1075
977
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1076
978
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1077
- log4.warn("object already inlined in a different document, ignoring the link", {
979
+ log2.warn("object already inlined in a different document, ignoring the link", {
1078
980
  ...logMeta,
1079
981
  actualDocumentUrl: objectDocumentHandle.url
1080
982
  }, {
1081
- F: __dxlog_file5,
1082
- L: 157,
983
+ F: __dxlog_file4,
984
+ L: 159,
1083
985
  S: this,
1084
986
  C: (f, a) => f(...a)
1085
987
  });
1086
988
  continue;
1087
989
  }
1088
990
  if (objectDocumentHandle?.url === automergeUrl) {
1089
- log4.warn("object document was already loaded", logMeta, {
1090
- F: __dxlog_file5,
1091
- L: 164,
991
+ log2.warn("object document was already loaded", logMeta, {
992
+ F: __dxlog_file4,
993
+ L: 166,
1092
994
  S: this,
1093
995
  C: (f, a) => f(...a)
1094
996
  });
1095
997
  continue;
1096
998
  }
1097
999
  const handle = this._repo.find(automergeUrl);
1098
- log4.debug("document loading triggered", logMeta, {
1099
- F: __dxlog_file5,
1100
- L: 168,
1000
+ log2.debug("document loading triggered", logMeta, {
1001
+ F: __dxlog_file4,
1002
+ L: 170,
1101
1003
  S: this,
1102
1004
  C: (f, a) => f(...a)
1103
1005
  });
@@ -1115,12 +1017,12 @@ var AutomergeDocumentLoaderImpl = class {
1115
1017
  break;
1116
1018
  } catch (err) {
1117
1019
  if (`${err}`.includes("Timeout")) {
1118
- log4.info("wraparound", {
1020
+ log2.info("wraparound", {
1119
1021
  id: docHandle.documentId,
1120
1022
  state: docHandle.state
1121
1023
  }, {
1122
- F: __dxlog_file5,
1123
- L: 184,
1024
+ F: __dxlog_file4,
1025
+ L: 186,
1124
1026
  S: this,
1125
1027
  C: (f, a) => f(...a)
1126
1028
  });
@@ -1160,9 +1062,9 @@ var AutomergeDocumentLoaderImpl = class {
1160
1062
  docUrl: handle.url
1161
1063
  };
1162
1064
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1163
- log4.info("document loaded after all listeners were removed", logMeta, {
1164
- F: __dxlog_file5,
1165
- L: 220,
1065
+ log2.info("document loaded after all listeners were removed", logMeta, {
1066
+ F: __dxlog_file4,
1067
+ L: 222,
1166
1068
  S: this,
1167
1069
  C: (f, a) => f(...a)
1168
1070
  });
@@ -1170,9 +1072,9 @@ var AutomergeDocumentLoaderImpl = class {
1170
1072
  }
1171
1073
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1172
1074
  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,
1075
+ log2.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1076
+ F: __dxlog_file4,
1077
+ L: 227,
1176
1078
  S: this,
1177
1079
  C: (f, a) => f(...a)
1178
1080
  });
@@ -1184,14 +1086,14 @@ var AutomergeDocumentLoaderImpl = class {
1184
1086
  });
1185
1087
  } catch (err) {
1186
1088
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1187
- log4.warn("failed to load a document", {
1089
+ log2.warn("failed to load a document", {
1188
1090
  objectId,
1189
1091
  automergeUrl: handle.url,
1190
1092
  retryLoading: shouldRetryLoading,
1191
1093
  err
1192
1094
  }, {
1193
- F: __dxlog_file5,
1194
- L: 231,
1095
+ F: __dxlog_file4,
1096
+ L: 233,
1195
1097
  S: this,
1196
1098
  C: (f, a) => f(...a)
1197
1099
  });
@@ -1215,10 +1117,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1215
1117
  import { Resource as Resource2 } from "@dxos/context";
1216
1118
  import { invariant as invariant5 } from "@dxos/invariant";
1217
1119
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1218
- import { log as log5 } from "@dxos/log";
1120
+ import { log as log3 } from "@dxos/log";
1219
1121
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1220
1122
  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";
1123
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1222
1124
  var MeshEchoReplicator = class {
1223
1125
  constructor() {
1224
1126
  this._connections = /* @__PURE__ */ new Set();
@@ -1245,7 +1147,7 @@ var MeshEchoReplicator = class {
1245
1147
  }
1246
1148
  createExtension() {
1247
1149
  invariant5(this._context, void 0, {
1248
- F: __dxlog_file6,
1150
+ F: __dxlog_file5,
1249
1151
  L: 54,
1250
1152
  S: this,
1251
1153
  A: [
@@ -1256,16 +1158,16 @@ var MeshEchoReplicator = class {
1256
1158
  const connection = new MeshReplicatorConnection({
1257
1159
  ownPeerId: this._context.peerId,
1258
1160
  onRemoteConnected: async () => {
1259
- log5("onRemoteConnected", {
1161
+ log3("onRemoteConnected", {
1260
1162
  peerId: connection.peerId
1261
1163
  }, {
1262
- F: __dxlog_file6,
1164
+ F: __dxlog_file5,
1263
1165
  L: 59,
1264
1166
  S: this,
1265
1167
  C: (f, a) => f(...a)
1266
1168
  });
1267
1169
  invariant5(this._context, void 0, {
1268
- F: __dxlog_file6,
1170
+ F: __dxlog_file5,
1269
1171
  L: 60,
1270
1172
  S: this,
1271
1173
  A: [
@@ -1273,18 +1175,20 @@ var MeshEchoReplicator = class {
1273
1175
  ""
1274
1176
  ]
1275
1177
  });
1276
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1178
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1179
+ this._context.onConnectionAuthScopeChanged(connection);
1180
+ } else {
1277
1181
  this._connectionsPerPeer.set(connection.peerId, connection);
1278
1182
  await connection.enable();
1279
1183
  this._context.onConnectionOpen(connection);
1280
1184
  }
1281
1185
  },
1282
1186
  onRemoteDisconnected: async () => {
1283
- log5("onRemoteDisconnected", {
1187
+ log3("onRemoteDisconnected", {
1284
1188
  peerId: connection.peerId
1285
1189
  }, {
1286
- F: __dxlog_file6,
1287
- L: 69,
1190
+ F: __dxlog_file5,
1191
+ L: 71,
1288
1192
  S: this,
1289
1193
  C: (f, a) => f(...a)
1290
1194
  });
@@ -1294,18 +1198,18 @@ var MeshEchoReplicator = class {
1294
1198
  this._connections.delete(connection);
1295
1199
  },
1296
1200
  shouldAdvertize: async (params) => {
1297
- log5("shouldAdvertize", {
1201
+ log3("shouldAdvertize", {
1298
1202
  peerId: connection.peerId,
1299
1203
  documentId: params.documentId
1300
1204
  }, {
1301
- F: __dxlog_file6,
1302
- L: 76,
1205
+ F: __dxlog_file5,
1206
+ L: 78,
1303
1207
  S: this,
1304
1208
  C: (f, a) => f(...a)
1305
1209
  });
1306
1210
  invariant5(this._context, void 0, {
1307
- F: __dxlog_file6,
1308
- L: 77,
1211
+ F: __dxlog_file5,
1212
+ L: 79,
1309
1213
  S: this,
1310
1214
  A: [
1311
1215
  "this._context",
@@ -1315,12 +1219,12 @@ var MeshEchoReplicator = class {
1315
1219
  try {
1316
1220
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1317
1221
  if (!spaceKey) {
1318
- log5("space key not found for share policy check", {
1222
+ log3("space key not found for share policy check", {
1319
1223
  peerId: connection.peerId,
1320
1224
  documentId: params.documentId
1321
1225
  }, {
1322
- F: __dxlog_file6,
1323
- L: 81,
1226
+ F: __dxlog_file5,
1227
+ L: 83,
1324
1228
  S: this,
1325
1229
  C: (f, a) => f(...a)
1326
1230
  });
@@ -1328,19 +1232,19 @@ var MeshEchoReplicator = class {
1328
1232
  }
1329
1233
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1330
1234
  if (!connection.remoteDeviceKey) {
1331
- log5("device key not found for share policy check", {
1235
+ log3("device key not found for share policy check", {
1332
1236
  peerId: connection.peerId,
1333
1237
  documentId: params.documentId
1334
1238
  }, {
1335
- F: __dxlog_file6,
1336
- L: 91,
1239
+ F: __dxlog_file5,
1240
+ L: 93,
1337
1241
  S: this,
1338
1242
  C: (f, a) => f(...a)
1339
1243
  });
1340
1244
  return false;
1341
1245
  }
1342
1246
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1343
- log5("share policy check", {
1247
+ log3("share policy check", {
1344
1248
  localPeer: this._context.peerId,
1345
1249
  remotePeer: connection.peerId,
1346
1250
  documentId: params.documentId,
@@ -1348,16 +1252,16 @@ var MeshEchoReplicator = class {
1348
1252
  spaceKey,
1349
1253
  isAuthorized
1350
1254
  }, {
1351
- F: __dxlog_file6,
1352
- L: 99,
1255
+ F: __dxlog_file5,
1256
+ L: 101,
1353
1257
  S: this,
1354
1258
  C: (f, a) => f(...a)
1355
1259
  });
1356
1260
  return isAuthorized;
1357
1261
  } catch (err) {
1358
- log5.catch(err, void 0, {
1359
- F: __dxlog_file6,
1360
- L: 109,
1262
+ log3.catch(err, void 0, {
1263
+ F: __dxlog_file5,
1264
+ L: 111,
1361
1265
  S: this,
1362
1266
  C: (f, a) => f(...a)
1363
1267
  });
@@ -1369,16 +1273,21 @@ var MeshEchoReplicator = class {
1369
1273
  return connection.replicatorExtension;
1370
1274
  }
1371
1275
  authorizeDevice(spaceKey, deviceKey) {
1372
- log5("authorizeDevice", {
1276
+ log3("authorizeDevice", {
1373
1277
  spaceKey,
1374
1278
  deviceKey
1375
1279
  }, {
1376
- F: __dxlog_file6,
1377
- L: 120,
1280
+ F: __dxlog_file5,
1281
+ L: 122,
1378
1282
  S: this,
1379
1283
  C: (f, a) => f(...a)
1380
1284
  });
1381
1285
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey2.hash)).add(deviceKey);
1286
+ for (const connection of this._connections) {
1287
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1288
+ this._context?.onConnectionAuthScopeChanged(connection);
1289
+ }
1290
+ }
1382
1291
  }
1383
1292
  };
1384
1293
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1410,13 +1319,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1410
1319
  onStartReplication: async (info, remotePeerId) => {
1411
1320
  this.remoteDeviceKey = remotePeerId;
1412
1321
  this._remotePeerId = info.id;
1413
- log5("onStartReplication", {
1322
+ log3("onStartReplication", {
1414
1323
  id: info.id,
1415
1324
  thisPeerId: this.peerId,
1416
1325
  remotePeerId: remotePeerId.toHex()
1417
1326
  }, {
1418
- F: __dxlog_file6,
1419
- L: 185,
1327
+ F: __dxlog_file5,
1328
+ L: 192,
1420
1329
  S: this,
1421
1330
  C: (f, a) => f(...a)
1422
1331
  });
@@ -1439,8 +1348,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1439
1348
  }
1440
1349
  get peerId() {
1441
1350
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1442
- F: __dxlog_file6,
1443
- L: 208,
1351
+ F: __dxlog_file5,
1352
+ L: 215,
1444
1353
  S: this,
1445
1354
  A: [
1446
1355
  "this._remotePeerId != null",
@@ -1458,8 +1367,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1458
1367
  */
1459
1368
  async enable() {
1460
1369
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1461
- F: __dxlog_file6,
1462
- L: 221,
1370
+ F: __dxlog_file5,
1371
+ L: 228,
1463
1372
  S: this,
1464
1373
  A: [
1465
1374
  "this._remotePeerId != null",
@@ -1480,7 +1389,6 @@ export {
1480
1389
  AuthStatus,
1481
1390
  AutomergeDocumentLoaderImpl,
1482
1391
  AutomergeHost,
1483
- AutomergeStorageAdapter,
1484
1392
  DataServiceImpl,
1485
1393
  LevelDBStorageAdapter,
1486
1394
  LocalHostNetworkAdapter,