@dxos/echo-pipeline 0.5.9-next.a50ff17 → 0.6.0

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 (36) 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 +182 -126
  4. package/dist/lib/browser/index.mjs.map +3 -3
  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 +230 -174
  11. package/dist/lib/node/index.cjs.map +3 -3
  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 +2 -1
  16. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
  17. package/dist/types/src/automerge/automerge-host.d.ts +40 -3
  18. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  19. package/dist/types/src/automerge/echo-network-adapter.d.ts +2 -0
  20. package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
  21. package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
  22. package/dist/types/src/space/admission-discovery-extension.d.ts +30 -0
  23. package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -0
  24. package/dist/types/src/space/index.d.ts +1 -0
  25. package/dist/types/src/space/index.d.ts.map +1 -1
  26. package/dist/types/src/space/space-manager.d.ts +8 -0
  27. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  28. package/package.json +33 -33
  29. package/src/automerge/automerge-doc-loader.test.ts +8 -5
  30. package/src/automerge/automerge-doc-loader.ts +29 -20
  31. package/src/automerge/automerge-host.ts +96 -32
  32. package/src/automerge/echo-network-adapter.ts +10 -4
  33. package/src/automerge/mesh-echo-replicator.ts +7 -2
  34. package/src/space/admission-discovery-extension.ts +90 -0
  35. package/src/space/index.ts +1 -0
  36. package/src/space/space-manager.ts +46 -1
@@ -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,16 +25,14 @@ 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
- import { Event } from "@dxos/async";
30
- import { next as automerge, getBackend, getHeads } from "@dxos/automerge/automerge";
31
+ import { Event, asyncTimeout } from "@dxos/async";
32
+ import { next as automerge, getBackend, getHeads, isAutomerge, save } from "@dxos/automerge/automerge";
31
33
  import { Repo } from "@dxos/automerge/automerge-repo";
32
- import { Context } from "@dxos/context";
33
- import { invariant as invariant3 } from "@dxos/invariant";
34
+ import { Context, cancelWithContext } from "@dxos/context";
34
35
  import { PublicKey } from "@dxos/keys";
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";
@@ -319,10 +319,7 @@ var EchoNetworkAdapter = class extends NetworkAdapter {
319
319
  _emitPeerCandidate(connection) {
320
320
  this.emit("peer-candidate", {
321
321
  peerId: connection.peerId,
322
- peerMetadata: {
323
- // TODO(dmaretskyi): Refactor this.
324
- dxos_peerSource: "EchoNetworkAdapter"
325
- }
322
+ peerMetadata: createEchoPeerMetadata()
326
323
  });
327
324
  }
328
325
  };
@@ -338,6 +335,11 @@ _ts_decorate([
338
335
  _ts_decorate([
339
336
  synchronized
340
337
  ], EchoNetworkAdapter.prototype, "removeReplicator", null);
338
+ var createEchoPeerMetadata = () => ({
339
+ // TODO(dmaretskyi): Refactor this.
340
+ dxos_peerSource: "EchoNetworkAdapter"
341
+ });
342
+ var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetworkAdapter";
341
343
 
342
344
  // packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
343
345
  import { LifecycleState as LifecycleState2, Resource } from "@dxos/context";
@@ -587,11 +589,13 @@ function _ts_decorate2(decorators, target, key, desc) {
587
589
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
588
590
  var AutomergeHost = class {
589
591
  constructor({ db, indexMetadataStore }) {
590
- this._ctx = new Context();
592
+ this._ctx = new Context(void 0, {
593
+ F: __dxlog_file3,
594
+ L: 71
595
+ });
591
596
  this._echoNetworkAdapter = new EchoNetworkAdapter({
592
597
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
593
598
  });
594
- this._requestedDocs = /* @__PURE__ */ new Set();
595
599
  this._storage = new LevelDBStorageAdapter({
596
600
  db,
597
601
  callbacks: {
@@ -627,6 +631,9 @@ var AutomergeHost = class {
627
631
  await this._echoNetworkAdapter.close();
628
632
  await this._ctx.dispose();
629
633
  }
634
+ /**
635
+ * @deprecated To be abstracted away.
636
+ */
630
637
  get repo() {
631
638
  return this._repo;
632
639
  }
@@ -636,6 +643,39 @@ var AutomergeHost = class {
636
643
  async removeReplicator(replicator) {
637
644
  await this._echoNetworkAdapter.removeReplicator(replicator);
638
645
  }
646
+ /**
647
+ * Loads the document handle from the repo and waits for it to be ready.
648
+ */
649
+ async loadDoc(ctx, documentId, opts) {
650
+ let handle;
651
+ if (typeof documentId === "string") {
652
+ handle = this._repo.handles[documentId];
653
+ }
654
+ if (!handle) {
655
+ handle = this._repo.find(documentId);
656
+ }
657
+ if (!handle.isReady()) {
658
+ if (!opts?.timeout) {
659
+ await cancelWithContext(ctx, handle.whenReady());
660
+ } else {
661
+ await cancelWithContext(ctx, asyncTimeout(handle.whenReady(), opts.timeout));
662
+ }
663
+ }
664
+ return handle;
665
+ }
666
+ /**
667
+ * Create new persisted document.
668
+ */
669
+ createDoc(initialValue, opts) {
670
+ if (opts?.preserveHistory) {
671
+ if (!isAutomerge(initialValue)) {
672
+ throw new TypeError("Initial value must be an Automerge document");
673
+ }
674
+ return this._repo.import(save(initialValue));
675
+ } else {
676
+ return this._repo.create(initialValue);
677
+ }
678
+ }
639
679
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
640
680
  // Hosts, running in the worker, don't share documents unless requested by other peers.
641
681
  // NOTE: If both peers return sharePolicy=false the replication will not happen
@@ -647,23 +687,8 @@ var AutomergeHost = class {
647
687
  if (!documentId) {
648
688
  return false;
649
689
  }
650
- const doc = this._repo.handles[documentId]?.docSync();
651
- if (!doc) {
652
- const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
653
- log2("doc share policy check", {
654
- peerId,
655
- documentId,
656
- isRequested
657
- }, {
658
- F: __dxlog_file3,
659
- L: 143,
660
- S: this,
661
- C: (f, a) => f(...a)
662
- });
663
- return isRequested;
664
- }
665
690
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
666
- if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
691
+ if (isEchoPeerMetadata(peerMetadata)) {
667
692
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
668
693
  documentId
669
694
  });
@@ -735,31 +760,36 @@ var AutomergeHost = class {
735
760
  }
736
761
  return PublicKey.from(spaceKeyHex);
737
762
  }
738
- //
739
- // Methods for client-services.
740
- //
763
+ /**
764
+ * Flush documents to disk.
765
+ */
741
766
  async flush({ states }) {
742
- await Promise.all(states?.map(async ({ heads, documentId }) => {
743
- invariant3(heads, "heads are required for flush", {
744
- F: __dxlog_file3,
745
- L: 237,
746
- S: this,
747
- A: [
748
- "heads",
749
- "'heads are required for flush'"
750
- ]
751
- });
752
- const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
753
- await waitForHeads(handle, heads);
754
- }) ?? []);
767
+ if (states) {
768
+ await Promise.all(states.map(async ({ heads, documentId }) => {
769
+ if (!heads) {
770
+ return;
771
+ }
772
+ const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
773
+ await waitForHeads(handle, heads);
774
+ }) ?? []);
775
+ }
755
776
  await this._repo.flush(states?.map(({ documentId }) => documentId));
756
777
  }
778
+ /**
779
+ * Host <-> Client sync.
780
+ */
757
781
  syncRepo(request) {
758
782
  return this._clientNetwork.syncRepo(request);
759
783
  }
784
+ /**
785
+ * Host <-> Client sync.
786
+ */
760
787
  sendSyncMessage(request) {
761
788
  return this._clientNetwork.sendSyncMessage(request);
762
789
  }
790
+ /**
791
+ * Host <-> Client sync.
792
+ */
763
793
  async getHostInfo() {
764
794
  return this._clientNetwork.getHostInfo();
765
795
  }
@@ -813,11 +843,12 @@ var changeIsPresentInDoc = (doc, changeHash) => {
813
843
 
814
844
  // packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts
815
845
  import { Event as Event2 } from "@dxos/async";
816
- import { cancelWithContext } from "@dxos/context";
846
+ import { interpretAsDocumentId } from "@dxos/automerge/automerge-repo";
847
+ import { cancelWithContext as cancelWithContext2 } from "@dxos/context";
817
848
  import { warnAfterTimeout } from "@dxos/debug";
818
849
  import { SpaceDocVersion } from "@dxos/echo-protocol";
819
- import { invariant as invariant4 } from "@dxos/invariant";
820
- import { log as log3 } from "@dxos/log";
850
+ import { invariant as invariant3 } from "@dxos/invariant";
851
+ import { log as log2 } from "@dxos/log";
821
852
  import { trace as trace2 } from "@dxos/tracing";
822
853
  function _ts_decorate3(decorators, target, key, desc) {
823
854
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -851,32 +882,32 @@ var AutomergeDocumentLoaderImpl = class {
851
882
  return;
852
883
  }
853
884
  if (!spaceState.rootUrl) {
854
- log3.error("Database opened with no rootUrl", {
855
- spaceId: this._spaceId
856
- }, {
857
- F: __dxlog_file4,
858
- L: 72,
859
- S: this,
860
- C: (f, a) => f(...a)
861
- });
862
- this._createContextBoundSpaceRootDocument(ctx);
863
- } else {
864
- const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
865
- const doc = existingDocHandle.docSync();
866
- invariant4(doc, void 0, {
867
- F: __dxlog_file4,
868
- L: 77,
869
- S: this,
870
- A: [
871
- "doc",
872
- ""
873
- ]
874
- });
875
- if (doc.access == null) {
876
- this._initDocAccess(existingDocHandle);
877
- }
878
- this._spaceRootDocHandle = existingDocHandle;
885
+ throw new Error("Database opened with no rootUrl");
886
+ }
887
+ const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
888
+ const doc = existingDocHandle.docSync();
889
+ invariant3(doc, void 0, {
890
+ F: __dxlog_file4,
891
+ L: 84,
892
+ S: this,
893
+ A: [
894
+ "doc",
895
+ ""
896
+ ]
897
+ });
898
+ invariant3(doc.version === SpaceDocVersion.CURRENT, void 0, {
899
+ F: __dxlog_file4,
900
+ L: 85,
901
+ S: this,
902
+ A: [
903
+ "doc.version === SpaceDocVersion.CURRENT",
904
+ ""
905
+ ]
906
+ });
907
+ if (doc.access == null) {
908
+ this._initDocAccess(existingDocHandle);
879
909
  }
910
+ this._spaceRootDocHandle = existingDocHandle;
880
911
  }
881
912
  loadObjectDocument(objectIdOrMany) {
882
913
  const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
@@ -885,9 +916,9 @@ var AutomergeDocumentLoaderImpl = class {
885
916
  let hasUrlsToLoad = false;
886
917
  const urlsToLoad = {};
887
918
  for (const objectId of objectIds) {
888
- invariant4(this._spaceRootDocHandle, void 0, {
919
+ invariant3(this._spaceRootDocHandle, void 0, {
889
920
  F: __dxlog_file4,
890
- L: 90,
921
+ L: 97,
891
922
  S: this,
892
923
  A: [
893
924
  "this._spaceRootDocHandle",
@@ -898,9 +929,9 @@ var AutomergeDocumentLoaderImpl = class {
898
929
  continue;
899
930
  }
900
931
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
901
- invariant4(spaceRootDoc, void 0, {
932
+ invariant3(spaceRootDoc, void 0, {
902
933
  F: __dxlog_file4,
903
- L: 95,
934
+ L: 102,
904
935
  S: this,
905
936
  A: [
906
937
  "spaceRootDoc",
@@ -910,11 +941,11 @@ var AutomergeDocumentLoaderImpl = class {
910
941
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
911
942
  if (documentUrl == null) {
912
943
  this._objectsPendingDocumentLoad.add(objectId);
913
- log3.info("loading delayed until object links are initialized", {
944
+ log2.info("loading delayed until object links are initialized", {
914
945
  objectId
915
946
  }, {
916
947
  F: __dxlog_file4,
917
- L: 99,
948
+ L: 106,
918
949
  S: this,
919
950
  C: (f, a) => f(...a)
920
951
  });
@@ -927,6 +958,32 @@ var AutomergeDocumentLoaderImpl = class {
927
958
  this._loadLinkedObjects(urlsToLoad);
928
959
  }
929
960
  }
961
+ getObjectDocumentId(objectId) {
962
+ invariant3(this._spaceRootDocHandle, void 0, {
963
+ F: __dxlog_file4,
964
+ L: 118,
965
+ S: this,
966
+ A: [
967
+ "this._spaceRootDocHandle",
968
+ ""
969
+ ]
970
+ });
971
+ const spaceRootDoc = this._spaceRootDocHandle.docSync();
972
+ invariant3(spaceRootDoc, void 0, {
973
+ F: __dxlog_file4,
974
+ L: 120,
975
+ S: this,
976
+ A: [
977
+ "spaceRootDoc",
978
+ ""
979
+ ]
980
+ });
981
+ if (spaceRootDoc.objects?.[objectId]) {
982
+ return this._spaceRootDocHandle.documentId;
983
+ }
984
+ const documentUrl = (spaceRootDoc.links ?? {})[objectId];
985
+ return documentUrl && interpretAsDocumentId(documentUrl);
986
+ }
930
987
  onObjectLinksUpdated(links) {
931
988
  if (!links) {
932
989
  return;
@@ -936,9 +993,9 @@ var AutomergeDocumentLoaderImpl = class {
936
993
  linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
937
994
  }
938
995
  getSpaceRootDocHandle() {
939
- invariant4(this._spaceRootDocHandle, void 0, {
996
+ invariant3(this._spaceRootDocHandle, void 0, {
940
997
  F: __dxlog_file4,
941
- L: 122,
998
+ L: 140,
942
999
  S: this,
943
1000
  A: [
944
1001
  "this._spaceRootDocHandle",
@@ -948,9 +1005,9 @@ var AutomergeDocumentLoaderImpl = class {
948
1005
  return this._spaceRootDocHandle;
949
1006
  }
950
1007
  createDocumentForObject(objectId) {
951
- invariant4(this._spaceRootDocHandle, void 0, {
1008
+ invariant3(this._spaceRootDocHandle, void 0, {
952
1009
  F: __dxlog_file4,
953
- L: 127,
1010
+ L: 145,
954
1011
  S: this,
955
1012
  A: [
956
1013
  "this._spaceRootDocHandle",
@@ -990,30 +1047,30 @@ var AutomergeDocumentLoaderImpl = class {
990
1047
  };
991
1048
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
992
1049
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
993
- log3.warn("object already inlined in a different document, ignoring the link", {
1050
+ log2.warn("object already inlined in a different document, ignoring the link", {
994
1051
  ...logMeta,
995
1052
  actualDocumentUrl: objectDocumentHandle.url
996
1053
  }, {
997
1054
  F: __dxlog_file4,
998
- L: 159,
1055
+ L: 177,
999
1056
  S: this,
1000
1057
  C: (f, a) => f(...a)
1001
1058
  });
1002
1059
  continue;
1003
1060
  }
1004
1061
  if (objectDocumentHandle?.url === automergeUrl) {
1005
- log3.warn("object document was already loaded", logMeta, {
1062
+ log2.warn("object document was already loaded", logMeta, {
1006
1063
  F: __dxlog_file4,
1007
- L: 166,
1064
+ L: 184,
1008
1065
  S: this,
1009
1066
  C: (f, a) => f(...a)
1010
1067
  });
1011
1068
  continue;
1012
1069
  }
1013
1070
  const handle = this._repo.find(automergeUrl);
1014
- log3.debug("document loading triggered", logMeta, {
1071
+ log2.debug("document loading triggered", logMeta, {
1015
1072
  F: __dxlog_file4,
1016
- L: 170,
1073
+ L: 188,
1017
1074
  S: this,
1018
1075
  C: (f, a) => f(...a)
1019
1076
  });
@@ -1026,17 +1083,17 @@ var AutomergeDocumentLoaderImpl = class {
1026
1083
  while (true) {
1027
1084
  try {
1028
1085
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (CoreDatabase)", async () => {
1029
- await cancelWithContext(ctx, docHandle.whenReady());
1086
+ await cancelWithContext2(ctx, docHandle.whenReady());
1030
1087
  });
1031
1088
  break;
1032
1089
  } catch (err) {
1033
1090
  if (`${err}`.includes("Timeout")) {
1034
- log3.info("wraparound", {
1091
+ log2.info("wraparound", {
1035
1092
  id: docHandle.documentId,
1036
1093
  state: docHandle.state
1037
1094
  }, {
1038
1095
  F: __dxlog_file4,
1039
- L: 186,
1096
+ L: 204,
1040
1097
  S: this,
1041
1098
  C: (f, a) => f(...a)
1042
1099
  });
@@ -1050,14 +1107,6 @@ var AutomergeDocumentLoaderImpl = class {
1050
1107
  }
1051
1108
  return docHandle;
1052
1109
  }
1053
- _createContextBoundSpaceRootDocument(ctx) {
1054
- const docHandle = this._repo.create();
1055
- this._spaceRootDocHandle = docHandle;
1056
- ctx.onDispose(() => {
1057
- docHandle.delete();
1058
- this._spaceRootDocHandle = null;
1059
- });
1060
- }
1061
1110
  _initDocAccess(handle) {
1062
1111
  handle.change((newDoc) => {
1063
1112
  newDoc.access ??= {
@@ -1076,9 +1125,9 @@ var AutomergeDocumentLoaderImpl = class {
1076
1125
  docUrl: handle.url
1077
1126
  };
1078
1127
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1079
- log3.info("document loaded after all listeners were removed", logMeta, {
1128
+ log2.info("document loaded after all listeners were removed", logMeta, {
1080
1129
  F: __dxlog_file4,
1081
- L: 222,
1130
+ L: 231,
1082
1131
  S: this,
1083
1132
  C: (f, a) => f(...a)
1084
1133
  });
@@ -1086,9 +1135,9 @@ var AutomergeDocumentLoaderImpl = class {
1086
1135
  }
1087
1136
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1088
1137
  if (objectDocHandle?.url !== handle.url) {
1089
- log3.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1138
+ log2.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1090
1139
  F: __dxlog_file4,
1091
- L: 227,
1140
+ L: 236,
1092
1141
  S: this,
1093
1142
  C: (f, a) => f(...a)
1094
1143
  });
@@ -1100,14 +1149,14 @@ var AutomergeDocumentLoaderImpl = class {
1100
1149
  });
1101
1150
  } catch (err) {
1102
1151
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1103
- log3.warn("failed to load a document", {
1152
+ log2.warn("failed to load a document", {
1104
1153
  objectId,
1105
1154
  automergeUrl: handle.url,
1106
1155
  retryLoading: shouldRetryLoading,
1107
1156
  err
1108
1157
  }, {
1109
1158
  F: __dxlog_file4,
1110
- L: 233,
1159
+ L: 242,
1111
1160
  S: this,
1112
1161
  C: (f, a) => f(...a)
1113
1162
  });
@@ -1129,9 +1178,9 @@ AutomergeDocumentLoaderImpl = _ts_decorate3([
1129
1178
  // packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts
1130
1179
  import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1131
1180
  import { Resource as Resource2 } from "@dxos/context";
1132
- import { invariant as invariant5 } from "@dxos/invariant";
1181
+ import { invariant as invariant4 } from "@dxos/invariant";
1133
1182
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1134
- import { log as log4 } from "@dxos/log";
1183
+ import { log as log3 } from "@dxos/log";
1135
1184
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1136
1185
  import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
1137
1186
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
@@ -1160,7 +1209,7 @@ var MeshEchoReplicator = class {
1160
1209
  this._context = null;
1161
1210
  }
1162
1211
  createExtension() {
1163
- invariant5(this._context, void 0, {
1212
+ invariant4(this._context, void 0, {
1164
1213
  F: __dxlog_file5,
1165
1214
  L: 54,
1166
1215
  S: this,
@@ -1172,7 +1221,7 @@ var MeshEchoReplicator = class {
1172
1221
  const connection = new MeshReplicatorConnection({
1173
1222
  ownPeerId: this._context.peerId,
1174
1223
  onRemoteConnected: async () => {
1175
- log4("onRemoteConnected", {
1224
+ log3("onRemoteConnected", {
1176
1225
  peerId: connection.peerId
1177
1226
  }, {
1178
1227
  F: __dxlog_file5,
@@ -1180,7 +1229,7 @@ var MeshEchoReplicator = class {
1180
1229
  S: this,
1181
1230
  C: (f, a) => f(...a)
1182
1231
  });
1183
- invariant5(this._context, void 0, {
1232
+ invariant4(this._context, void 0, {
1184
1233
  F: __dxlog_file5,
1185
1234
  L: 60,
1186
1235
  S: this,
@@ -1193,12 +1242,12 @@ var MeshEchoReplicator = class {
1193
1242
  this._context.onConnectionAuthScopeChanged(connection);
1194
1243
  } else {
1195
1244
  this._connectionsPerPeer.set(connection.peerId, connection);
1196
- await connection.enable();
1197
1245
  this._context.onConnectionOpen(connection);
1246
+ await connection.enable();
1198
1247
  }
1199
1248
  },
1200
1249
  onRemoteDisconnected: async () => {
1201
- log4("onRemoteDisconnected", {
1250
+ log3("onRemoteDisconnected", {
1202
1251
  peerId: connection.peerId
1203
1252
  }, {
1204
1253
  F: __dxlog_file5,
@@ -1207,12 +1256,12 @@ var MeshEchoReplicator = class {
1207
1256
  C: (f, a) => f(...a)
1208
1257
  });
1209
1258
  this._context?.onConnectionClosed(connection);
1210
- await connection.disable();
1211
1259
  this._connectionsPerPeer.delete(connection.peerId);
1260
+ await connection.disable();
1212
1261
  this._connections.delete(connection);
1213
1262
  },
1214
1263
  shouldAdvertize: async (params) => {
1215
- log4("shouldAdvertize", {
1264
+ log3("shouldAdvertize", {
1216
1265
  peerId: connection.peerId,
1217
1266
  documentId: params.documentId
1218
1267
  }, {
@@ -1221,7 +1270,7 @@ var MeshEchoReplicator = class {
1221
1270
  S: this,
1222
1271
  C: (f, a) => f(...a)
1223
1272
  });
1224
- invariant5(this._context, void 0, {
1273
+ invariant4(this._context, void 0, {
1225
1274
  F: __dxlog_file5,
1226
1275
  L: 79,
1227
1276
  S: this,
@@ -1233,7 +1282,7 @@ var MeshEchoReplicator = class {
1233
1282
  try {
1234
1283
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1235
1284
  if (!spaceKey) {
1236
- log4("space key not found for share policy check", {
1285
+ log3("space key not found for share policy check", {
1237
1286
  peerId: connection.peerId,
1238
1287
  documentId: params.documentId
1239
1288
  }, {
@@ -1246,7 +1295,7 @@ var MeshEchoReplicator = class {
1246
1295
  }
1247
1296
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1248
1297
  if (!connection.remoteDeviceKey) {
1249
- log4("device key not found for share policy check", {
1298
+ log3("device key not found for share policy check", {
1250
1299
  peerId: connection.peerId,
1251
1300
  documentId: params.documentId
1252
1301
  }, {
@@ -1258,7 +1307,7 @@ var MeshEchoReplicator = class {
1258
1307
  return false;
1259
1308
  }
1260
1309
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1261
- log4("share policy check", {
1310
+ log3("share policy check", {
1262
1311
  localPeer: this._context.peerId,
1263
1312
  remotePeer: connection.peerId,
1264
1313
  documentId: params.documentId,
@@ -1273,7 +1322,7 @@ var MeshEchoReplicator = class {
1273
1322
  });
1274
1323
  return isAuthorized;
1275
1324
  } catch (err) {
1276
- log4.catch(err, void 0, {
1325
+ log3.catch(err, void 0, {
1277
1326
  F: __dxlog_file5,
1278
1327
  L: 111,
1279
1328
  S: this,
@@ -1287,7 +1336,7 @@ var MeshEchoReplicator = class {
1287
1336
  return connection.replicatorExtension;
1288
1337
  }
1289
1338
  authorizeDevice(spaceKey, deviceKey) {
1290
- log4("authorizeDevice", {
1339
+ log3("authorizeDevice", {
1291
1340
  spaceKey,
1292
1341
  deviceKey
1293
1342
  }, {
@@ -1297,6 +1346,11 @@ var MeshEchoReplicator = class {
1297
1346
  C: (f, a) => f(...a)
1298
1347
  });
1299
1348
  defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey2.hash)).add(deviceKey);
1349
+ for (const connection of this._connections) {
1350
+ if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
1351
+ this._context?.onConnectionAuthScopeChanged(connection);
1352
+ }
1353
+ }
1300
1354
  }
1301
1355
  };
1302
1356
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1328,13 +1382,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1328
1382
  onStartReplication: async (info, remotePeerId) => {
1329
1383
  this.remoteDeviceKey = remotePeerId;
1330
1384
  this._remotePeerId = info.id;
1331
- log4("onStartReplication", {
1385
+ log3("onStartReplication", {
1332
1386
  id: info.id,
1333
1387
  thisPeerId: this.peerId,
1334
1388
  remotePeerId: remotePeerId.toHex()
1335
1389
  }, {
1336
1390
  F: __dxlog_file5,
1337
- L: 187,
1391
+ L: 192,
1338
1392
  S: this,
1339
1393
  C: (f, a) => f(...a)
1340
1394
  });
@@ -1356,9 +1410,9 @@ var MeshReplicatorConnection = class extends Resource2 {
1356
1410
  });
1357
1411
  }
1358
1412
  get peerId() {
1359
- invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1413
+ invariant4(this._remotePeerId != null, "Remote peer has not connected yet.", {
1360
1414
  F: __dxlog_file5,
1361
- L: 210,
1415
+ L: 215,
1362
1416
  S: this,
1363
1417
  A: [
1364
1418
  "this._remotePeerId != null",
@@ -1375,9 +1429,9 @@ var MeshReplicatorConnection = class extends Resource2 {
1375
1429
  * Call after the remote peer has connected.
1376
1430
  */
1377
1431
  async enable() {
1378
- invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1432
+ invariant4(this._remotePeerId != null, "Remote peer has not connected yet.", {
1379
1433
  F: __dxlog_file5,
1380
- L: 223,
1434
+ L: 228,
1381
1435
  S: this,
1382
1436
  A: [
1383
1437
  "this._remotePeerId != null",
@@ -1398,6 +1452,8 @@ export {
1398
1452
  AuthStatus,
1399
1453
  AutomergeDocumentLoaderImpl,
1400
1454
  AutomergeHost,
1455
+ CredentialRetrieverExtension,
1456
+ CredentialServerExtension,
1401
1457
  DataServiceImpl,
1402
1458
  LevelDBStorageAdapter,
1403
1459
  LocalHostNetworkAdapter,