@dxos/echo-pipeline 0.5.9-main.bf0ae3e → 0.5.9-main.bf3bb8f

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 +186 -127
  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 +234 -175
  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 +33 -22
  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,10 +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
- import { invariant as invariant4 } from "@dxos/invariant";
819
- import { log as log3 } from "@dxos/log";
849
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
850
+ import { invariant as invariant3 } from "@dxos/invariant";
851
+ import { log as log2 } from "@dxos/log";
820
852
  import { trace as trace2 } from "@dxos/tracing";
821
853
  function _ts_decorate3(decorators, target, key, desc) {
822
854
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -850,32 +882,32 @@ var AutomergeDocumentLoaderImpl = class {
850
882
  return;
851
883
  }
852
884
  if (!spaceState.rootUrl) {
853
- log3.error("Database opened with no rootUrl", {
854
- spaceId: this._spaceId
855
- }, {
856
- F: __dxlog_file4,
857
- L: 72,
858
- S: this,
859
- C: (f, a) => f(...a)
860
- });
861
- this._createContextBoundSpaceRootDocument(ctx);
862
- } else {
863
- const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
864
- const doc = existingDocHandle.docSync();
865
- invariant4(doc, void 0, {
866
- F: __dxlog_file4,
867
- L: 77,
868
- S: this,
869
- A: [
870
- "doc",
871
- ""
872
- ]
873
- });
874
- if (doc.access == null) {
875
- this._initDocAccess(existingDocHandle);
876
- }
877
- 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);
878
909
  }
910
+ this._spaceRootDocHandle = existingDocHandle;
879
911
  }
880
912
  loadObjectDocument(objectIdOrMany) {
881
913
  const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
@@ -884,9 +916,9 @@ var AutomergeDocumentLoaderImpl = class {
884
916
  let hasUrlsToLoad = false;
885
917
  const urlsToLoad = {};
886
918
  for (const objectId of objectIds) {
887
- invariant4(this._spaceRootDocHandle, void 0, {
919
+ invariant3(this._spaceRootDocHandle, void 0, {
888
920
  F: __dxlog_file4,
889
- L: 90,
921
+ L: 97,
890
922
  S: this,
891
923
  A: [
892
924
  "this._spaceRootDocHandle",
@@ -897,9 +929,9 @@ var AutomergeDocumentLoaderImpl = class {
897
929
  continue;
898
930
  }
899
931
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
900
- invariant4(spaceRootDoc, void 0, {
932
+ invariant3(spaceRootDoc, void 0, {
901
933
  F: __dxlog_file4,
902
- L: 95,
934
+ L: 102,
903
935
  S: this,
904
936
  A: [
905
937
  "spaceRootDoc",
@@ -909,11 +941,11 @@ var AutomergeDocumentLoaderImpl = class {
909
941
  const documentUrl = (spaceRootDoc.links ?? {})[objectId];
910
942
  if (documentUrl == null) {
911
943
  this._objectsPendingDocumentLoad.add(objectId);
912
- log3.info("loading delayed until object links are initialized", {
944
+ log2.info("loading delayed until object links are initialized", {
913
945
  objectId
914
946
  }, {
915
947
  F: __dxlog_file4,
916
- L: 99,
948
+ L: 106,
917
949
  S: this,
918
950
  C: (f, a) => f(...a)
919
951
  });
@@ -926,6 +958,32 @@ var AutomergeDocumentLoaderImpl = class {
926
958
  this._loadLinkedObjects(urlsToLoad);
927
959
  }
928
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
+ }
929
987
  onObjectLinksUpdated(links) {
930
988
  if (!links) {
931
989
  return;
@@ -935,9 +993,9 @@ var AutomergeDocumentLoaderImpl = class {
935
993
  linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
936
994
  }
937
995
  getSpaceRootDocHandle() {
938
- invariant4(this._spaceRootDocHandle, void 0, {
996
+ invariant3(this._spaceRootDocHandle, void 0, {
939
997
  F: __dxlog_file4,
940
- L: 122,
998
+ L: 140,
941
999
  S: this,
942
1000
  A: [
943
1001
  "this._spaceRootDocHandle",
@@ -947,16 +1005,18 @@ var AutomergeDocumentLoaderImpl = class {
947
1005
  return this._spaceRootDocHandle;
948
1006
  }
949
1007
  createDocumentForObject(objectId) {
950
- invariant4(this._spaceRootDocHandle, void 0, {
1008
+ invariant3(this._spaceRootDocHandle, void 0, {
951
1009
  F: __dxlog_file4,
952
- L: 127,
1010
+ L: 145,
953
1011
  S: this,
954
1012
  A: [
955
1013
  "this._spaceRootDocHandle",
956
1014
  ""
957
1015
  ]
958
1016
  });
959
- const spaceDocHandle = this._repo.create();
1017
+ const spaceDocHandle = this._repo.create({
1018
+ version: SpaceDocVersion.CURRENT
1019
+ });
960
1020
  this._initDocAccess(spaceDocHandle);
961
1021
  this.onObjectBoundToDocument(spaceDocHandle, objectId);
962
1022
  this._spaceRootDocHandle.change((newDoc) => {
@@ -987,30 +1047,30 @@ var AutomergeDocumentLoaderImpl = class {
987
1047
  };
988
1048
  const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
989
1049
  if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
990
- 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", {
991
1051
  ...logMeta,
992
1052
  actualDocumentUrl: objectDocumentHandle.url
993
1053
  }, {
994
1054
  F: __dxlog_file4,
995
- L: 157,
1055
+ L: 177,
996
1056
  S: this,
997
1057
  C: (f, a) => f(...a)
998
1058
  });
999
1059
  continue;
1000
1060
  }
1001
1061
  if (objectDocumentHandle?.url === automergeUrl) {
1002
- log3.warn("object document was already loaded", logMeta, {
1062
+ log2.warn("object document was already loaded", logMeta, {
1003
1063
  F: __dxlog_file4,
1004
- L: 164,
1064
+ L: 184,
1005
1065
  S: this,
1006
1066
  C: (f, a) => f(...a)
1007
1067
  });
1008
1068
  continue;
1009
1069
  }
1010
1070
  const handle = this._repo.find(automergeUrl);
1011
- log3.debug("document loading triggered", logMeta, {
1071
+ log2.debug("document loading triggered", logMeta, {
1012
1072
  F: __dxlog_file4,
1013
- L: 168,
1073
+ L: 188,
1014
1074
  S: this,
1015
1075
  C: (f, a) => f(...a)
1016
1076
  });
@@ -1023,17 +1083,17 @@ var AutomergeDocumentLoaderImpl = class {
1023
1083
  while (true) {
1024
1084
  try {
1025
1085
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (CoreDatabase)", async () => {
1026
- await cancelWithContext(ctx, docHandle.whenReady());
1086
+ await cancelWithContext2(ctx, docHandle.whenReady());
1027
1087
  });
1028
1088
  break;
1029
1089
  } catch (err) {
1030
1090
  if (`${err}`.includes("Timeout")) {
1031
- log3.info("wraparound", {
1091
+ log2.info("wraparound", {
1032
1092
  id: docHandle.documentId,
1033
1093
  state: docHandle.state
1034
1094
  }, {
1035
1095
  F: __dxlog_file4,
1036
- L: 184,
1096
+ L: 204,
1037
1097
  S: this,
1038
1098
  C: (f, a) => f(...a)
1039
1099
  });
@@ -1047,14 +1107,6 @@ var AutomergeDocumentLoaderImpl = class {
1047
1107
  }
1048
1108
  return docHandle;
1049
1109
  }
1050
- _createContextBoundSpaceRootDocument(ctx) {
1051
- const docHandle = this._repo.create();
1052
- this._spaceRootDocHandle = docHandle;
1053
- ctx.onDispose(() => {
1054
- docHandle.delete();
1055
- this._spaceRootDocHandle = null;
1056
- });
1057
- }
1058
1110
  _initDocAccess(handle) {
1059
1111
  handle.change((newDoc) => {
1060
1112
  newDoc.access ??= {
@@ -1073,9 +1125,9 @@ var AutomergeDocumentLoaderImpl = class {
1073
1125
  docUrl: handle.url
1074
1126
  };
1075
1127
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1076
- log3.info("document loaded after all listeners were removed", logMeta, {
1128
+ log2.info("document loaded after all listeners were removed", logMeta, {
1077
1129
  F: __dxlog_file4,
1078
- L: 220,
1130
+ L: 231,
1079
1131
  S: this,
1080
1132
  C: (f, a) => f(...a)
1081
1133
  });
@@ -1083,9 +1135,9 @@ var AutomergeDocumentLoaderImpl = class {
1083
1135
  }
1084
1136
  const objectDocHandle = this._objectDocumentHandles.get(objectId);
1085
1137
  if (objectDocHandle?.url !== handle.url) {
1086
- 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, {
1087
1139
  F: __dxlog_file4,
1088
- L: 225,
1140
+ L: 236,
1089
1141
  S: this,
1090
1142
  C: (f, a) => f(...a)
1091
1143
  });
@@ -1097,14 +1149,14 @@ var AutomergeDocumentLoaderImpl = class {
1097
1149
  });
1098
1150
  } catch (err) {
1099
1151
  const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1100
- log3.warn("failed to load a document", {
1152
+ log2.warn("failed to load a document", {
1101
1153
  objectId,
1102
1154
  automergeUrl: handle.url,
1103
1155
  retryLoading: shouldRetryLoading,
1104
1156
  err
1105
1157
  }, {
1106
1158
  F: __dxlog_file4,
1107
- L: 231,
1159
+ L: 242,
1108
1160
  S: this,
1109
1161
  C: (f, a) => f(...a)
1110
1162
  });
@@ -1126,9 +1178,9 @@ AutomergeDocumentLoaderImpl = _ts_decorate3([
1126
1178
  // packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts
1127
1179
  import { cbor as cbor2 } from "@dxos/automerge/automerge-repo";
1128
1180
  import { Resource as Resource2 } from "@dxos/context";
1129
- import { invariant as invariant5 } from "@dxos/invariant";
1181
+ import { invariant as invariant4 } from "@dxos/invariant";
1130
1182
  import { PublicKey as PublicKey2 } from "@dxos/keys";
1131
- import { log as log4 } from "@dxos/log";
1183
+ import { log as log3 } from "@dxos/log";
1132
1184
  import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
1133
1185
  import { ComplexMap, ComplexSet, defaultMap } from "@dxos/util";
1134
1186
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
@@ -1157,7 +1209,7 @@ var MeshEchoReplicator = class {
1157
1209
  this._context = null;
1158
1210
  }
1159
1211
  createExtension() {
1160
- invariant5(this._context, void 0, {
1212
+ invariant4(this._context, void 0, {
1161
1213
  F: __dxlog_file5,
1162
1214
  L: 54,
1163
1215
  S: this,
@@ -1169,7 +1221,7 @@ var MeshEchoReplicator = class {
1169
1221
  const connection = new MeshReplicatorConnection({
1170
1222
  ownPeerId: this._context.peerId,
1171
1223
  onRemoteConnected: async () => {
1172
- log4("onRemoteConnected", {
1224
+ log3("onRemoteConnected", {
1173
1225
  peerId: connection.peerId
1174
1226
  }, {
1175
1227
  F: __dxlog_file5,
@@ -1177,7 +1229,7 @@ var MeshEchoReplicator = class {
1177
1229
  S: this,
1178
1230
  C: (f, a) => f(...a)
1179
1231
  });
1180
- invariant5(this._context, void 0, {
1232
+ invariant4(this._context, void 0, {
1181
1233
  F: __dxlog_file5,
1182
1234
  L: 60,
1183
1235
  S: this,
@@ -1190,12 +1242,12 @@ var MeshEchoReplicator = class {
1190
1242
  this._context.onConnectionAuthScopeChanged(connection);
1191
1243
  } else {
1192
1244
  this._connectionsPerPeer.set(connection.peerId, connection);
1193
- await connection.enable();
1194
1245
  this._context.onConnectionOpen(connection);
1246
+ await connection.enable();
1195
1247
  }
1196
1248
  },
1197
1249
  onRemoteDisconnected: async () => {
1198
- log4("onRemoteDisconnected", {
1250
+ log3("onRemoteDisconnected", {
1199
1251
  peerId: connection.peerId
1200
1252
  }, {
1201
1253
  F: __dxlog_file5,
@@ -1204,12 +1256,12 @@ var MeshEchoReplicator = class {
1204
1256
  C: (f, a) => f(...a)
1205
1257
  });
1206
1258
  this._context?.onConnectionClosed(connection);
1207
- await connection.disable();
1208
1259
  this._connectionsPerPeer.delete(connection.peerId);
1260
+ await connection.disable();
1209
1261
  this._connections.delete(connection);
1210
1262
  },
1211
1263
  shouldAdvertize: async (params) => {
1212
- log4("shouldAdvertize", {
1264
+ log3("shouldAdvertize", {
1213
1265
  peerId: connection.peerId,
1214
1266
  documentId: params.documentId
1215
1267
  }, {
@@ -1218,7 +1270,7 @@ var MeshEchoReplicator = class {
1218
1270
  S: this,
1219
1271
  C: (f, a) => f(...a)
1220
1272
  });
1221
- invariant5(this._context, void 0, {
1273
+ invariant4(this._context, void 0, {
1222
1274
  F: __dxlog_file5,
1223
1275
  L: 79,
1224
1276
  S: this,
@@ -1230,7 +1282,7 @@ var MeshEchoReplicator = class {
1230
1282
  try {
1231
1283
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1232
1284
  if (!spaceKey) {
1233
- log4("space key not found for share policy check", {
1285
+ log3("space key not found for share policy check", {
1234
1286
  peerId: connection.peerId,
1235
1287
  documentId: params.documentId
1236
1288
  }, {
@@ -1243,7 +1295,7 @@ var MeshEchoReplicator = class {
1243
1295
  }
1244
1296
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1245
1297
  if (!connection.remoteDeviceKey) {
1246
- log4("device key not found for share policy check", {
1298
+ log3("device key not found for share policy check", {
1247
1299
  peerId: connection.peerId,
1248
1300
  documentId: params.documentId
1249
1301
  }, {
@@ -1255,7 +1307,7 @@ var MeshEchoReplicator = class {
1255
1307
  return false;
1256
1308
  }
1257
1309
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1258
- log4("share policy check", {
1310
+ log3("share policy check", {
1259
1311
  localPeer: this._context.peerId,
1260
1312
  remotePeer: connection.peerId,
1261
1313
  documentId: params.documentId,
@@ -1270,7 +1322,7 @@ var MeshEchoReplicator = class {
1270
1322
  });
1271
1323
  return isAuthorized;
1272
1324
  } catch (err) {
1273
- log4.catch(err, void 0, {
1325
+ log3.catch(err, void 0, {
1274
1326
  F: __dxlog_file5,
1275
1327
  L: 111,
1276
1328
  S: this,
@@ -1284,7 +1336,7 @@ var MeshEchoReplicator = class {
1284
1336
  return connection.replicatorExtension;
1285
1337
  }
1286
1338
  authorizeDevice(spaceKey, deviceKey) {
1287
- log4("authorizeDevice", {
1339
+ log3("authorizeDevice", {
1288
1340
  spaceKey,
1289
1341
  deviceKey
1290
1342
  }, {
@@ -1294,6 +1346,11 @@ var MeshEchoReplicator = class {
1294
1346
  C: (f, a) => f(...a)
1295
1347
  });
1296
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
+ }
1297
1354
  }
1298
1355
  };
1299
1356
  var MeshReplicatorConnection = class extends Resource2 {
@@ -1325,13 +1382,13 @@ var MeshReplicatorConnection = class extends Resource2 {
1325
1382
  onStartReplication: async (info, remotePeerId) => {
1326
1383
  this.remoteDeviceKey = remotePeerId;
1327
1384
  this._remotePeerId = info.id;
1328
- log4("onStartReplication", {
1385
+ log3("onStartReplication", {
1329
1386
  id: info.id,
1330
1387
  thisPeerId: this.peerId,
1331
1388
  remotePeerId: remotePeerId.toHex()
1332
1389
  }, {
1333
1390
  F: __dxlog_file5,
1334
- L: 187,
1391
+ L: 192,
1335
1392
  S: this,
1336
1393
  C: (f, a) => f(...a)
1337
1394
  });
@@ -1353,9 +1410,9 @@ var MeshReplicatorConnection = class extends Resource2 {
1353
1410
  });
1354
1411
  }
1355
1412
  get peerId() {
1356
- invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1413
+ invariant4(this._remotePeerId != null, "Remote peer has not connected yet.", {
1357
1414
  F: __dxlog_file5,
1358
- L: 210,
1415
+ L: 215,
1359
1416
  S: this,
1360
1417
  A: [
1361
1418
  "this._remotePeerId != null",
@@ -1372,9 +1429,9 @@ var MeshReplicatorConnection = class extends Resource2 {
1372
1429
  * Call after the remote peer has connected.
1373
1430
  */
1374
1431
  async enable() {
1375
- invariant5(this._remotePeerId != null, "Remote peer has not connected yet.", {
1432
+ invariant4(this._remotePeerId != null, "Remote peer has not connected yet.", {
1376
1433
  F: __dxlog_file5,
1377
- L: 223,
1434
+ L: 228,
1378
1435
  S: this,
1379
1436
  A: [
1380
1437
  "this._remotePeerId != null",
@@ -1395,6 +1452,8 @@ export {
1395
1452
  AuthStatus,
1396
1453
  AutomergeDocumentLoaderImpl,
1397
1454
  AutomergeHost,
1455
+ CredentialRetrieverExtension,
1456
+ CredentialServerExtension,
1398
1457
  DataServiceImpl,
1399
1458
  LevelDBStorageAdapter,
1400
1459
  LocalHostNetworkAdapter,