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

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 (52) hide show
  1. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs → chunk-HS77A4I4.mjs} +174 -23
  2. package/dist/lib/browser/{chunk-I2J5TTHJ.mjs.map → chunk-HS77A4I4.mjs.map} +4 -4
  3. package/dist/lib/browser/index.mjs +143 -231
  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-Y5U7UXEL.cjs} +185 -34
  9. package/dist/lib/node/{chunk-QPCNQ4ZK.cjs.map → chunk-Y5U7UXEL.cjs.map} +4 -4
  10. package/dist/lib/node/index.cjs +177 -260
  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/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  26. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  27. package/dist/types/src/space/index.d.ts +1 -0
  28. package/dist/types/src/space/index.d.ts.map +1 -1
  29. package/dist/types/src/space/space-manager.d.ts +8 -0
  30. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  31. package/package.json +33 -33
  32. package/src/automerge/automerge-doc-loader.test.ts +2 -3
  33. package/src/automerge/automerge-doc-loader.ts +4 -2
  34. package/src/automerge/automerge-host.ts +8 -35
  35. package/src/automerge/echo-network-adapter.ts +24 -8
  36. package/src/automerge/echo-replicator.ts +2 -0
  37. package/src/automerge/index.ts +0 -1
  38. package/src/automerge/mesh-echo-replicator.ts +9 -2
  39. package/src/automerge/storage-adapter.test.ts +103 -139
  40. package/src/space/admission-discovery-extension.ts +90 -0
  41. package/src/space/index.ts +1 -0
  42. package/src/space/space-manager.ts +46 -1
  43. package/src/space/space-protocol.test.ts +2 -0
  44. package/dist/types/src/automerge/automerge-storage-adapter.d.ts +0 -16
  45. package/dist/types/src/automerge/automerge-storage-adapter.d.ts.map +0 -1
  46. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts +0 -25
  47. package/dist/types/src/automerge/automerge-storage/342/200/223wrapper.d.ts.map +0 -1
  48. package/dist/types/src/automerge/migrations.d.ts +0 -7
  49. package/dist/types/src/automerge/migrations.d.ts.map +0 -1
  50. package/src/automerge/automerge-storage-adapter.ts +0 -103
  51. package/src/automerge/automerge-storage/342/200/223wrapper.ts +0 -59
  52. package/src/automerge/migrations.ts +0 -42
@@ -3,6 +3,8 @@ import {
3
3
  AuthExtension,
4
4
  AuthStatus,
5
5
  Buffer,
6
+ CredentialRetrieverExtension,
7
+ CredentialServerExtension,
6
8
  DataServiceImpl,
7
9
  MOCK_AUTH_PROVIDER,
8
10
  MOCK_AUTH_VERIFIER,
@@ -23,7 +25,7 @@ import {
23
25
  mapTimeframeToFeedIndexes,
24
26
  startAfter,
25
27
  valueEncoding
26
- } from "./chunk-I2J5TTHJ.mjs";
28
+ } from "./chunk-HS77A4I4.mjs";
27
29
 
28
30
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
29
31
  import { Event } from "@dxos/async";
@@ -32,7 +34,6 @@ import { Repo } from "@dxos/automerge/automerge-repo";
32
34
  import { Context } from "@dxos/context";
33
35
  import { invariant as invariant3 } from "@dxos/invariant";
34
36
  import { PublicKey } from "@dxos/keys";
35
- import { log as log3 } from "@dxos/log";
36
37
  import { objectPointerCodec } from "@dxos/protocols";
37
38
  import { trace } from "@dxos/tracing";
38
39
  import { mapValues } from "@dxos/util";
@@ -161,13 +162,14 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
161
162
  peerId: this.peerId,
162
163
  onConnectionOpen: this._onConnectionOpen.bind(this),
163
164
  onConnectionClosed: this._onConnectionClosed.bind(this),
165
+ onConnectionAuthScopeChanged: this._onConnectionAuthScopeChanged.bind(this),
164
166
  getContainingSpaceForDocument: this._params.getContainingSpaceForDocument
165
167
  });
166
168
  }
167
169
  async removeReplicator(replicator) {
168
170
  invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
169
171
  F: __dxlog_file,
170
- L: 102,
172
+ L: 103,
171
173
  S: this,
172
174
  A: [
173
175
  "this._lifecycleState === LifecycleState.OPEN",
@@ -176,14 +178,13 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
176
178
  });
177
179
  invariant(this._replicators.has(replicator), void 0, {
178
180
  F: __dxlog_file,
179
- L: 103,
181
+ L: 104,
180
182
  S: this,
181
183
  A: [
182
184
  "this._replicators.has(replicator)",
183
185
  ""
184
186
  ]
185
187
  });
186
- "";
187
188
  await replicator.disconnect();
188
189
  this._replicators.delete(replicator);
189
190
  }
@@ -249,27 +250,49 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
249
250
  S: this,
250
251
  C: (f, a) => f(...a)
251
252
  });
252
- this.emit("peer-candidate", {
253
- peerId: connection.peerId,
254
- peerMetadata: {
255
- // TODO(dmaretskyi): Refactor this.
256
- dxos_peerSource: "EchoNetworkAdapter"
257
- }
253
+ this._emitPeerCandidate(connection);
254
+ }
255
+ /**
256
+ * Trigger doc-synchronizer shared documents set recalculation. Happens on peer-candidate.
257
+ * TODO(y): replace with a proper API call when sharePolicy update becomes supported by automerge-repo
258
+ */
259
+ _onConnectionAuthScopeChanged(connection) {
260
+ log("Connection auth scope changed", {
261
+ peerId: connection.peerId
262
+ }, {
263
+ F: __dxlog_file,
264
+ L: 153,
265
+ S: this,
266
+ C: (f, a) => f(...a)
258
267
  });
268
+ const entry = this._connections.get(connection.peerId);
269
+ invariant(entry, void 0, {
270
+ F: __dxlog_file,
271
+ L: 155,
272
+ S: this,
273
+ A: [
274
+ "entry",
275
+ ""
276
+ ]
277
+ });
278
+ this.emit("peer-disconnected", {
279
+ peerId: connection.peerId
280
+ });
281
+ this._emitPeerCandidate(connection);
259
282
  }
260
283
  _onConnectionClosed(connection) {
261
284
  log("Connection closed", {
262
285
  peerId: connection.peerId
263
286
  }, {
264
287
  F: __dxlog_file,
265
- L: 155,
288
+ L: 161,
266
289
  S: this,
267
290
  C: (f, a) => f(...a)
268
291
  });
269
292
  const entry = this._connections.get(connection.peerId);
270
293
  invariant(entry, void 0, {
271
294
  F: __dxlog_file,
272
- L: 157,
295
+ L: 163,
273
296
  S: this,
274
297
  A: [
275
298
  "entry",
@@ -282,18 +305,27 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
282
305
  });
283
306
  void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
284
307
  F: __dxlog_file,
285
- L: 162,
308
+ L: 168,
286
309
  S: this,
287
310
  C: (f, a) => f(...a)
288
311
  }));
289
312
  void entry.writer.abort().catch((err) => log.catch(err, void 0, {
290
313
  F: __dxlog_file,
291
- L: 163,
314
+ L: 169,
292
315
  S: this,
293
316
  C: (f, a) => f(...a)
294
317
  }));
295
318
  this._connections.delete(connection.peerId);
296
319
  }
320
+ _emitPeerCandidate(connection) {
321
+ this.emit("peer-candidate", {
322
+ peerId: connection.peerId,
323
+ peerMetadata: {
324
+ // TODO(dmaretskyi): Refactor this.
325
+ dxos_peerSource: "EchoNetworkAdapter"
326
+ }
327
+ });
328
+ }
297
329
  };
298
330
  _ts_decorate([
299
331
  synchronized
@@ -542,118 +574,6 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
542
574
  }
543
575
  };
544
576
 
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
577
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
658
578
  function _ts_decorate2(decorators, target, key, desc) {
659
579
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -665,31 +585,27 @@ function _ts_decorate2(decorators, target, key, desc) {
665
585
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
666
586
  return c > 3 && r && Object.defineProperty(target, key, r), r;
667
587
  }
668
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
588
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
669
589
  var AutomergeHost = class {
670
- constructor({ directory, db, indexMetadataStore }) {
671
- this._ctx = new Context();
590
+ constructor({ db, indexMetadataStore }) {
591
+ this._ctx = new Context(void 0, {
592
+ F: __dxlog_file3,
593
+ L: 49
594
+ });
672
595
  this._echoNetworkAdapter = new EchoNetworkAdapter({
673
596
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
674
597
  });
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
598
  this._storage = new LevelDBStorageAdapter({
687
- db: this._db,
599
+ db,
688
600
  callbacks: {
689
601
  beforeSave: async (params) => this._beforeSave(params),
690
602
  afterSave: async () => this._afterSave()
691
603
  }
692
604
  });
605
+ this._indexMetadataStore = indexMetadataStore;
606
+ }
607
+ async open() {
608
+ this._peerId = `host-${PublicKey.random().toHex()}`;
693
609
  await this._storage.open?.();
694
610
  this._clientNetwork = new LocalHostNetworkAdapter();
695
611
  this._repo = new Repo({
@@ -734,21 +650,6 @@ var AutomergeHost = class {
734
650
  if (!documentId) {
735
651
  return false;
736
652
  }
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
653
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
753
654
  if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
754
655
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
@@ -828,8 +729,8 @@ var AutomergeHost = class {
828
729
  async flush({ states }) {
829
730
  await Promise.all(states?.map(async ({ heads, documentId }) => {
830
731
  invariant3(heads, "heads are required for flush", {
831
- F: __dxlog_file4,
832
- L: 250,
732
+ F: __dxlog_file3,
733
+ L: 223,
833
734
  S: this,
834
735
  A: [
835
736
  "heads",
@@ -902,8 +803,9 @@ var changeIsPresentInDoc = (doc, changeHash) => {
902
803
  import { Event as Event2 } from "@dxos/async";
903
804
  import { cancelWithContext } from "@dxos/context";
904
805
  import { warnAfterTimeout } from "@dxos/debug";
806
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
905
807
  import { invariant as invariant4 } from "@dxos/invariant";
906
- import { log as log4 } from "@dxos/log";
808
+ import { log as log2 } from "@dxos/log";
907
809
  import { trace as trace2 } from "@dxos/tracing";
908
810
  function _ts_decorate3(decorators, target, key, desc) {
909
811
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -915,7 +817,7 @@ function _ts_decorate3(decorators, target, key, desc) {
915
817
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
916
818
  return c > 3 && r && Object.defineProperty(target, key, r), r;
917
819
  }
918
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
820
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
919
821
  var AutomergeDocumentLoaderImpl = class {
920
822
  constructor(_spaceId, _repo, _spaceKey) {
921
823
  this._spaceId = _spaceId;
@@ -937,10 +839,10 @@ var AutomergeDocumentLoaderImpl = class {
937
839
  return;
938
840
  }
939
841
  if (!spaceState.rootUrl) {
940
- log4.error("Database opened with no rootUrl", {
842
+ log2.error("Database opened with no rootUrl", {
941
843
  spaceId: this._spaceId
942
844
  }, {
943
- F: __dxlog_file5,
845
+ F: __dxlog_file4,
944
846
  L: 72,
945
847
  S: this,
946
848
  C: (f, a) => f(...a)
@@ -950,7 +852,7 @@ var AutomergeDocumentLoaderImpl = class {
950
852
  const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
951
853
  const doc = existingDocHandle.docSync();
952
854
  invariant4(doc, void 0, {
953
- F: __dxlog_file5,
855
+ F: __dxlog_file4,
954
856
  L: 77,
955
857
  S: this,
956
858
  A: [
@@ -972,7 +874,7 @@ var AutomergeDocumentLoaderImpl = class {
972
874
  const urlsToLoad = {};
973
875
  for (const objectId of objectIds) {
974
876
  invariant4(this._spaceRootDocHandle, void 0, {
975
- F: __dxlog_file5,
877
+ F: __dxlog_file4,
976
878
  L: 90,
977
879
  S: this,
978
880
  A: [
@@ -985,7 +887,7 @@ var AutomergeDocumentLoaderImpl = class {
985
887
  }
986
888
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
987
889
  invariant4(spaceRootDoc, void 0, {
988
- F: __dxlog_file5,
890
+ F: __dxlog_file4,
989
891
  L: 95,
990
892
  S: this,
991
893
  A: [
@@ -996,10 +898,10 @@ var AutomergeDocumentLoaderImpl = class {
996
898
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
997
899
  if (documentUrl == null) {
998
900
  this._objectsPendingDocumentLoad.add(objectId);
999
- log4.info("loading delayed until object links are initialized", {
901
+ log2.info("loading delayed until object links are initialized", {
1000
902
  objectId
1001
903
  }, {
1002
- F: __dxlog_file5,
904
+ F: __dxlog_file4,
1003
905
  L: 99,
1004
906
  S: this,
1005
907
  C: (f, a) => f(...a)
@@ -1023,7 +925,7 @@ var AutomergeDocumentLoaderImpl = class {
1023
925
  }
1024
926
  getSpaceRootDocHandle() {
1025
927
  invariant4(this._spaceRootDocHandle, void 0, {
1026
- F: __dxlog_file5,
928
+ F: __dxlog_file4,
1027
929
  L: 122,
1028
930
  S: this,
1029
931
  A: [
@@ -1035,7 +937,7 @@ var AutomergeDocumentLoaderImpl = class {
1035
937
  }
1036
938
  createDocumentForObject(objectId) {
1037
939
  invariant4(this._spaceRootDocHandle, void 0, {
1038
- F: __dxlog_file5,
940
+ F: __dxlog_file4,
1039
941
  L: 127,
1040
942
  S: this,
1041
943
  A: [
@@ -1043,7 +945,9 @@ var AutomergeDocumentLoaderImpl = class {
1043
945
  ""
1044
946
  ]
1045
947
  });
1046
- const spaceDocHandle = this._repo.create();
948
+ const spaceDocHandle = this._repo.create({
949
+ version: SpaceDocVersion.CURRENT
950
+ });
1047
951
  this._initDocAccess(spaceDocHandle);
1048
952
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
1049
953
  this._spaceRootDocHandle.change((newDoc) => {
@@ -1074,30 +978,30 @@ var AutomergeDocumentLoaderImpl = class {
1074
978
  };
1075
979
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1076
980
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1077
- log4.warn("object already inlined in a different document, ignoring the link", {
981
+ log2.warn("object already inlined in a different document, ignoring the link", {
1078
982
  ...logMeta,
1079
983
  actualDocumentUrl: objectDocumentHandle.url
1080
984
  }, {
1081
- F: __dxlog_file5,
1082
- L: 157,
985
+ F: __dxlog_file4,
986
+ L: 159,
1083
987
  S: this,
1084
988
  C: (f, a) => f(...a)
1085
989
  });
1086
990
  continue;
1087
991
  }
1088
992
  if (objectDocumentHandle?.url === automergeUrl) {
1089
- log4.warn("object document was already loaded", logMeta, {
1090
- F: __dxlog_file5,
1091
- L: 164,
993
+ log2.warn("object document was already loaded", logMeta, {
994
+ F: __dxlog_file4,
995
+ L: 166,
1092
996
  S: this,
1093
997
  C: (f, a) => f(...a)
1094
998
  });
1095
999
  continue;
1096
1000
  }
1097
1001
  const handle = this._repo.find(automergeUrl);
1098
- log4.debug("document loading triggered", logMeta, {
1099
- F: __dxlog_file5,
1100
- L: 168,
1002
+ log2.debug("document loading triggered", logMeta, {
1003
+ F: __dxlog_file4,
1004
+ L: 170,
1101
1005
  S: this,
1102
1006
  C: (f, a) => f(...a)
1103
1007
  });
@@ -1115,12 +1019,12 @@ var AutomergeDocumentLoaderImpl = class {
1115
1019
  break;
1116
1020
  } catch (err) {
1117
1021
  if (`${err}`.includes("Timeout")) {
1118
- log4.info("wraparound", {
1022
+ log2.info("wraparound", {
1119
1023
  id: docHandle.documentId,
1120
1024
  state: docHandle.state
1121
1025
  }, {
1122
- F: __dxlog_file5,
1123
- L: 184,
1026
+ F: __dxlog_file4,
1027
+ L: 186,
1124
1028
  S: this,
1125
1029
  C: (f, a) => f(...a)
1126
1030
  });
@@ -1160,9 +1064,9 @@ var AutomergeDocumentLoaderImpl = class {
1160
1064
  docUrl: handle.url
1161
1065
  };
1162
1066
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1163
- log4.info("document loaded after all listeners were removed", logMeta, {
1164
- F: __dxlog_file5,
1165
- L: 220,
1067
+ log2.info("document loaded after all listeners were removed", logMeta, {
1068
+ F: __dxlog_file4,
1069
+ L: 222,
1166
1070
  S: this,
1167
1071
  C: (f, a) => f(...a)
1168
1072
  });
@@ -1170,9 +1074,9 @@ var AutomergeDocumentLoaderImpl = class {
1170
1074
  }
1171
1075
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1172
1076
  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,
1077
+ log2.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1078
+ F: __dxlog_file4,
1079
+ L: 227,
1176
1080
  S: this,
1177
1081
  C: (f, a) => f(...a)
1178
1082
  });
@@ -1184,14 +1088,14 @@ var AutomergeDocumentLoaderImpl = class {
1184
1088
  });
1185
1089
  } catch (err) {
1186
1090
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1187
- log4.warn("failed to load a document", {
1091
+ log2.warn("failed to load a document", {
1188
1092
  objectId,
1189
1093
  automergeUrl: handle.url,
1190
1094
  retryLoading: shouldRetryLoading,
1191
1095
  err
1192
1096
  }, {
1193
- F: __dxlog_file5,
1194
- L: 231,
1097
+ F: __dxlog_file4,
1098
+ L: 233,
1195
1099
  S: this,
1196
1100
  C: (f, a) => f(...a)
1197
1101
  });
@@ -1215,10 +1119,10 @@ import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1215
1119
  import { Resource as Resource2 } from "@dxos/context";
1216
1120
  import { invariant as invariant5 } from "@dxos/invariant";
1217
1121
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1218
- import { log as log5 } from "@dxos/log";
1122
+ import { log as log3 } from "@dxos/log";
1219
1123
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1220
1124
  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";
1125
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1222
1126
  var MeshEchoReplicator = class {
1223
1127
  constructor() {
1224
1128
  this._connections = /* @__PURE__ */ new Set();
@@ -1245,7 +1149,7 @@ var MeshEchoReplicator = class {
1245
1149
  }
1246
1150
  createExtension() {
1247
1151
  invariant5(this._context, void 0, {
1248
- F: __dxlog_file6,
1152
+ F: __dxlog_file5,
1249
1153
  L: 54,
1250
1154
  S: this,
1251
1155
  A: [
@@ -1256,16 +1160,16 @@ var MeshEchoReplicator = class {
1256
1160
  const connection = new MeshReplicatorConnection({
1257
1161
  ownPeerId: this._context.peerId,
1258
1162
  onRemoteConnected: async () => {
1259
- log5("onRemoteConnected", {
1163
+ log3("onRemoteConnected", {
1260
1164
  peerId: connection.peerId
1261
1165
  }, {
1262
- F: __dxlog_file6,
1166
+ F: __dxlog_file5,
1263
1167
  L: 59,
1264
1168
  S: this,
1265
1169
  C: (f, a) => f(...a)
1266
1170
  });
1267
1171
  invariant5(this._context, void 0, {
1268
- F: __dxlog_file6,
1172
+ F: __dxlog_file5,
1269
1173
  L: 60,
1270
1174
  S: this,
1271
1175
  A: [
@@ -1273,39 +1177,41 @@ var MeshEchoReplicator = class {
1273
1177
  ""
1274
1178
  ]
1275
1179
  });
1276
- if (!this._connectionsPerPeer.has(connection.peerId)) {
1180
+ if (this._connectionsPerPeer.has(connection.peerId)) {
1181
+ this._context.onConnectionAuthScopeChanged(connection);
1182
+ } else {
1277
1183
  this._connectionsPerPeer.set(connection.peerId, connection);
1278
1184
  await connection.enable();
1279
1185
  this._context.onConnectionOpen(connection);
1280
1186
  }
1281
1187
  },
1282
1188
  onRemoteDisconnected: async () => {
1283
- log5("onRemoteDisconnected", {
1189
+ log3("onRemoteDisconnected", {
1284
1190
  peerId: connection.peerId
1285
1191
  }, {
1286
- F: __dxlog_file6,
1287
- L: 69,
1192
+ F: __dxlog_file5,
1193
+ L: 71,
1288
1194
  S: this,
1289
1195
  C: (f, a) => f(...a)
1290
1196
  });
1291
1197
  this._context?.onConnectionClosed(connection);
1292
- await connection.disable();
1293
1198
  this._connectionsPerPeer.delete(connection.peerId);
1199
+ await connection.disable();
1294
1200
  this._connections.delete(connection);
1295
1201
  },
1296
1202
  shouldAdvertize: async (params) => {
1297
- log5("shouldAdvertize", {
1203
+ log3("shouldAdvertize", {
1298
1204
  peerId: connection.peerId,
1299
1205
  documentId: params.documentId
1300
1206
  }, {
1301
- F: __dxlog_file6,
1302
- L: 76,
1207
+ F: __dxlog_file5,
1208
+ L: 78,
1303
1209
  S: this,
1304
1210
  C: (f, a) => f(...a)
1305
1211
  });
1306
1212
  invariant5(this._context, void 0, {
1307
- F: __dxlog_file6,
1308
- L: 77,
1213
+ F: __dxlog_file5,
1214
+ L: 79,
1309
1215
  S: this,
1310
1216
  A: [
1311
1217
  "this._context",
@@ -1315,12 +1221,12 @@ var MeshEchoReplicator = class {
1315
1221
  try {
1316
1222
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1317
1223
  if (!spaceKey) {
1318
- log5("space key not found for share policy check", {
1224
+ log3("space key not found for share policy check", {
1319
1225
  peerId: connection.peerId,
1320
1226
  documentId: params.documentId
1321
1227
  }, {
1322
- F: __dxlog_file6,
1323
- L: 81,
1228
+ F: __dxlog_file5,
1229
+ L: 83,
1324
1230
  S: this,
1325
1231
  C: (f, a) => f(...a)
1326
1232
  });
@@ -1328,19 +1234,19 @@ var MeshEchoReplicator = class {
1328
1234
  }
1329
1235
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1330
1236
  if (!connection.remoteDeviceKey) {
1331
- log5("device key not found for share policy check", {
1237
+ log3("device key not found for share policy check", {
1332
1238
  peerId: connection.peerId,
1333
1239
  documentId: params.documentId
1334
1240
  }, {
1335
- F: __dxlog_file6,
1336
- L: 91,
1241
+ F: __dxlog_file5,
1242
+ L: 93,
1337
1243
  S: this,
1338
1244
  C: (f, a) => f(...a)
1339
1245
  });
1340
1246
  return false;
1341
1247
  }
1342
1248
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1343
- log5("share policy check", {
1249
+ log3("share policy check", {
1344
1250
  localPeer: this._context.peerId,
1345
1251
  remotePeer: connection.peerId,
1346
1252
  documentId: params.documentId,
@@ -1348,16 +1254,16 @@ var MeshEchoReplicator = class {
1348
1254
  spaceKey,
1349
1255
  isAuthorized
1350
1256
  }, {
1351
- F: __dxlog_file6,
1352
- L: 99,
1257
+ F: __dxlog_file5,
1258
+ L: 101,
1353
1259
  S: this,
1354
1260
  C: (f, a) => f(...a)
1355
1261
  });
1356
1262
  return isAuthorized;
1357
1263
  } catch (err) {
1358
- log5.catch(err, void 0, {
1359
- F: __dxlog_file6,
1360
- L: 109,
1264
+ log3.catch(err, void 0, {
1265
+ F: __dxlog_file5,
1266
+ L: 111,
1361
1267
  S: this,
1362
1268
  C: (f, a) => f(...a)
1363
1269
  });
@@ -1369,16 +1275,21 @@ var MeshEchoReplicator = class {
1369
1275
  return connection.replicatorExtension;
1370
1276
  }
1371
1277
  authorizeDevice(spaceKey, deviceKey) {
1372
- log5("authorizeDevice", {
1278
+ log3("authorizeDevice", {
1373
1279
  spaceKey,
1374
1280
  deviceKey
1375
1281
  }, {
1376
- F: __dxlog_file6,
1377
- L: 120,
1282
+ F: __dxlog_file5,
1283
+ L: 122,
1378
1284
  S: this,
1379
1285
  C: (f, a) => f(...a)
1380
1286
  });
1381
1287
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey2.hash)).add(deviceKey);
1288
+ for (const connection of this._connections) {
1289
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1290
+ this._context?.onConnectionAuthScopeChanged(connection);
1291
+ }
1292
+ }
1382
1293
  }
1383
1294
  };
1384
1295
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1410,13 +1321,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1410
1321
  onStartReplication: async (info, remotePeerId) => {
1411
1322
  this.remoteDeviceKey = remotePeerId;
1412
1323
  this._remotePeerId = info.id;
1413
- log5("onStartReplication", {
1324
+ log3("onStartReplication", {
1414
1325
  id: info.id,
1415
1326
  thisPeerId: this.peerId,
1416
1327
  remotePeerId: remotePeerId.toHex()
1417
1328
  }, {
1418
- F: __dxlog_file6,
1419
- L: 185,
1329
+ F: __dxlog_file5,
1330
+ L: 192,
1420
1331
  S: this,
1421
1332
  C: (f, a) => f(...a)
1422
1333
  });
@@ -1439,8 +1350,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1439
1350
  }
1440
1351
  get peerId() {
1441
1352
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1442
- F: __dxlog_file6,
1443
- L: 208,
1353
+ F: __dxlog_file5,
1354
+ L: 215,
1444
1355
  S: this,
1445
1356
  A: [
1446
1357
  "this._remotePeerId != null",
@@ -1458,8 +1369,8 @@ var MeshReplicatorConnection = class extends Resource2 {
1458
1369
  */
1459
1370
  async enable() {
1460
1371
  invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1461
- F: __dxlog_file6,
1462
- L: 221,
1372
+ F: __dxlog_file5,
1373
+ L: 228,
1463
1374
  S: this,
1464
1375
  A: [
1465
1376
  "this._remotePeerId != null",
@@ -1480,7 +1391,8 @@ export {
1480
1391
  AuthStatus,
1481
1392
  AutomergeDocumentLoaderImpl,
1482
1393
  AutomergeHost,
1483
- AutomergeStorageAdapter,
1394
+ CredentialRetrieverExtension,
1395
+ CredentialServerExtension,
1484
1396
  DataServiceImpl,
1485
1397
  LevelDBStorageAdapter,
1486
1398
  LocalHostNetworkAdapter,