@dxos/echo-pipeline 0.5.9-main.f099efe → 0.5.9-next.73dcc17

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.
@@ -56,7 +56,6 @@ var import_async = require("@dxos/async");
56
56
  var import_automerge = require("@dxos/automerge/automerge");
57
57
  var import_automerge_repo = require("@dxos/automerge/automerge-repo");
58
58
  var import_context = require("@dxos/context");
59
- var import_invariant = require("@dxos/invariant");
60
59
  var import_keys = require("@dxos/keys");
61
60
  var import_protocols = require("@dxos/protocols");
62
61
  var import_tracing = require("@dxos/tracing");
@@ -64,23 +63,24 @@ var import_util = require("@dxos/util");
64
63
  var import_async2 = require("@dxos/async");
65
64
  var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
66
65
  var import_context2 = require("@dxos/context");
67
- var import_invariant2 = require("@dxos/invariant");
66
+ var import_invariant = require("@dxos/invariant");
68
67
  var import_log = require("@dxos/log");
69
68
  var import_context3 = require("@dxos/context");
70
69
  var import_async3 = require("@dxos/async");
71
70
  var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
72
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
73
- var import_invariant3 = require("@dxos/invariant");
72
+ var import_invariant2 = require("@dxos/invariant");
74
73
  var import_async4 = require("@dxos/async");
74
+ var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
75
75
  var import_context4 = require("@dxos/context");
76
76
  var import_debug = require("@dxos/debug");
77
77
  var import_echo_protocol = require("@dxos/echo-protocol");
78
- var import_invariant4 = require("@dxos/invariant");
78
+ var import_invariant3 = require("@dxos/invariant");
79
79
  var import_log2 = require("@dxos/log");
80
80
  var import_tracing2 = require("@dxos/tracing");
81
- var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
81
+ var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
82
82
  var import_context5 = require("@dxos/context");
83
- var import_invariant5 = require("@dxos/invariant");
83
+ var import_invariant4 = require("@dxos/invariant");
84
84
  var import_keys2 = require("@dxos/keys");
85
85
  var import_log3 = require("@dxos/log");
86
86
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
@@ -129,7 +129,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
129
129
  disconnect() {
130
130
  }
131
131
  async open() {
132
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
132
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.CLOSED, void 0, {
133
133
  F: __dxlog_file,
134
134
  L: 60,
135
135
  S: this,
@@ -150,7 +150,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
150
150
  });
151
151
  }
152
152
  async close() {
153
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
153
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
154
154
  F: __dxlog_file,
155
155
  L: 71,
156
156
  S: this,
@@ -171,7 +171,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
171
171
  });
172
172
  }
173
173
  async addReplicator(replicator) {
174
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
174
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
175
175
  F: __dxlog_file,
176
176
  L: 87,
177
177
  S: this,
@@ -180,7 +180,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
180
180
  ""
181
181
  ]
182
182
  });
183
- (0, import_invariant2.invariant)(this.peerId, void 0, {
183
+ (0, import_invariant.invariant)(this.peerId, void 0, {
184
184
  F: __dxlog_file,
185
185
  L: 88,
186
186
  S: this,
@@ -189,7 +189,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
189
189
  ""
190
190
  ]
191
191
  });
192
- (0, import_invariant2.invariant)(!this._replicators.has(replicator), void 0, {
192
+ (0, import_invariant.invariant)(!this._replicators.has(replicator), void 0, {
193
193
  F: __dxlog_file,
194
194
  L: 89,
195
195
  S: this,
@@ -208,7 +208,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
208
208
  });
209
209
  }
210
210
  async removeReplicator(replicator) {
211
- (0, import_invariant2.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
211
+ (0, import_invariant.invariant)(this._lifecycleState === import_context2.LifecycleState.OPEN, void 0, {
212
212
  F: __dxlog_file,
213
213
  L: 103,
214
214
  S: this,
@@ -217,7 +217,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
217
217
  ""
218
218
  ]
219
219
  });
220
- (0, import_invariant2.invariant)(this._replicators.has(replicator), void 0, {
220
+ (0, import_invariant.invariant)(this._replicators.has(replicator), void 0, {
221
221
  F: __dxlog_file,
222
222
  L: 104,
223
223
  S: this,
@@ -245,7 +245,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
245
245
  S: this,
246
246
  C: (f, a) => f(...a)
247
247
  });
248
- (0, import_invariant2.invariant)(!this._connections.has(connection.peerId), void 0, {
248
+ (0, import_invariant.invariant)(!this._connections.has(connection.peerId), void 0, {
249
249
  F: __dxlog_file,
250
250
  L: 120,
251
251
  S: this,
@@ -307,7 +307,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
307
307
  C: (f, a) => f(...a)
308
308
  });
309
309
  const entry = this._connections.get(connection.peerId);
310
- (0, import_invariant2.invariant)(entry, void 0, {
310
+ (0, import_invariant.invariant)(entry, void 0, {
311
311
  F: __dxlog_file,
312
312
  L: 155,
313
313
  S: this,
@@ -331,7 +331,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
331
331
  C: (f, a) => f(...a)
332
332
  });
333
333
  const entry = this._connections.get(connection.peerId);
334
- (0, import_invariant2.invariant)(entry, void 0, {
334
+ (0, import_invariant.invariant)(entry, void 0, {
335
335
  F: __dxlog_file,
336
336
  L: 163,
337
337
  S: this,
@@ -361,10 +361,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
361
361
  _emitPeerCandidate(connection) {
362
362
  this.emit("peer-candidate", {
363
363
  peerId: connection.peerId,
364
- peerMetadata: {
365
- // TODO(dmaretskyi): Refactor this.
366
- dxos_peerSource: "EchoNetworkAdapter"
367
- }
364
+ peerMetadata: createEchoPeerMetadata()
368
365
  });
369
366
  }
370
367
  };
@@ -380,6 +377,11 @@ _ts_decorate([
380
377
  _ts_decorate([
381
378
  import_async2.synchronized
382
379
  ], EchoNetworkAdapter.prototype, "removeReplicator", null);
380
+ var createEchoPeerMetadata = () => ({
381
+ // TODO(dmaretskyi): Refactor this.
382
+ dxos_peerSource: "EchoNetworkAdapter"
383
+ });
384
+ var isEchoPeerMetadata = (metadata) => metadata?.dxos_peerSource === "EchoNetworkAdapter";
383
385
  var LevelDBStorageAdapter = class extends import_context3.Resource {
384
386
  constructor(_params) {
385
387
  super();
@@ -501,7 +503,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
501
503
  }
502
504
  send(message) {
503
505
  const peer = this._peers.get(message.targetId);
504
- (0, import_invariant3.invariant)(peer, "Peer not found.", {
506
+ (0, import_invariant2.invariant)(peer, "Peer not found.", {
505
507
  F: __dxlog_file2,
506
508
  L: 51,
507
509
  S: this,
@@ -526,7 +528,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
526
528
  syncRepo({ id, syncMessage }) {
527
529
  const peerId = this._getPeerId(id);
528
530
  return new import_codec_protobuf.Stream(({ next, close }) => {
529
- (0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
531
+ (0, import_invariant2.invariant)(!this._peers.has(peerId), "Peer already connected.", {
530
532
  F: __dxlog_file2,
531
533
  L: 73,
532
534
  S: this,
@@ -550,7 +552,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
550
552
  });
551
553
  }
552
554
  });
553
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
555
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
554
556
  F: __dxlog_file2,
555
557
  L: 90,
556
558
  S: this,
@@ -566,7 +568,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
566
568
  });
567
569
  }
568
570
  async sendSyncMessage({ id, syncMessage }) {
569
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
571
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
570
572
  F: __dxlog_file2,
571
573
  L: 99,
572
574
  S: this,
@@ -579,7 +581,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
579
581
  this.emit("message", message);
580
582
  }
581
583
  async getHostInfo() {
582
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
584
+ (0, import_invariant2.invariant)(this._isConnected, void 0, {
583
585
  F: __dxlog_file2,
584
586
  L: 105,
585
587
  S: this,
@@ -588,7 +590,7 @@ var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapte
588
590
  ""
589
591
  ]
590
592
  });
591
- (0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
593
+ (0, import_invariant2.invariant)(this.peerId, "Peer id not set.", {
592
594
  F: __dxlog_file2,
593
595
  L: 106,
594
596
  S: this,
@@ -620,7 +622,7 @@ var AutomergeHost = class {
620
622
  constructor({ db, indexMetadataStore }) {
621
623
  this._ctx = new import_context.Context(void 0, {
622
624
  F: __dxlog_file3,
623
- L: 49
625
+ L: 71
624
626
  });
625
627
  this._echoNetworkAdapter = new EchoNetworkAdapter({
626
628
  getContainingSpaceForDocument: this._getContainingSpaceForDocument.bind(this)
@@ -660,6 +662,9 @@ var AutomergeHost = class {
660
662
  await this._echoNetworkAdapter.close();
661
663
  await this._ctx.dispose();
662
664
  }
665
+ /**
666
+ * @deprecated To be abstracted away.
667
+ */
663
668
  get repo() {
664
669
  return this._repo;
665
670
  }
@@ -669,6 +674,39 @@ var AutomergeHost = class {
669
674
  async removeReplicator(replicator) {
670
675
  await this._echoNetworkAdapter.removeReplicator(replicator);
671
676
  }
677
+ /**
678
+ * Loads the document handle from the repo and waits for it to be ready.
679
+ */
680
+ async loadDoc(ctx, documentId, opts) {
681
+ let handle;
682
+ if (typeof documentId === "string") {
683
+ handle = this._repo.handles[documentId];
684
+ }
685
+ if (!handle) {
686
+ handle = this._repo.find(documentId);
687
+ }
688
+ if (!handle.isReady()) {
689
+ if (!opts?.timeout) {
690
+ await (0, import_context.cancelWithContext)(ctx, handle.whenReady());
691
+ } else {
692
+ await (0, import_context.cancelWithContext)(ctx, (0, import_async.asyncTimeout)(handle.whenReady(), opts.timeout));
693
+ }
694
+ }
695
+ return handle;
696
+ }
697
+ /**
698
+ * Create new persisted document.
699
+ */
700
+ createDoc(initialValue, opts) {
701
+ if (opts?.preserveHistory) {
702
+ if (!(0, import_automerge.isAutomerge)(initialValue)) {
703
+ throw new TypeError("Initial value must be an Automerge document");
704
+ }
705
+ return this._repo.import((0, import_automerge.save)(initialValue));
706
+ } else {
707
+ return this._repo.create(initialValue);
708
+ }
709
+ }
672
710
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
673
711
  // Hosts, running in the worker, don't share documents unless requested by other peers.
674
712
  // NOTE: If both peers return sharePolicy=false the replication will not happen
@@ -681,7 +719,7 @@ var AutomergeHost = class {
681
719
  return false;
682
720
  }
683
721
  const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
684
- if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
722
+ if (isEchoPeerMetadata(peerMetadata)) {
685
723
  return this._echoNetworkAdapter.shouldAdvertize(peerId, {
686
724
  documentId
687
725
  });
@@ -753,31 +791,36 @@ var AutomergeHost = class {
753
791
  }
754
792
  return import_keys.PublicKey.from(spaceKeyHex);
755
793
  }
756
- //
757
- // Methods for client-services.
758
- //
794
+ /**
795
+ * Flush documents to disk.
796
+ */
759
797
  async flush({ states }) {
760
- await Promise.all(states?.map(async ({ heads, documentId }) => {
761
- (0, import_invariant.invariant)(heads, "heads are required for flush", {
762
- F: __dxlog_file3,
763
- L: 223,
764
- S: this,
765
- A: [
766
- "heads",
767
- "'heads are required for flush'"
768
- ]
769
- });
770
- const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
771
- await waitForHeads(handle, heads);
772
- }) ?? []);
798
+ if (states) {
799
+ await Promise.all(states.map(async ({ heads, documentId }) => {
800
+ if (!heads) {
801
+ return;
802
+ }
803
+ const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
804
+ await waitForHeads(handle, heads);
805
+ }) ?? []);
806
+ }
773
807
  await this._repo.flush(states?.map(({ documentId }) => documentId));
774
808
  }
809
+ /**
810
+ * Host <-> Client sync.
811
+ */
775
812
  syncRepo(request) {
776
813
  return this._clientNetwork.syncRepo(request);
777
814
  }
815
+ /**
816
+ * Host <-> Client sync.
817
+ */
778
818
  sendSyncMessage(request) {
779
819
  return this._clientNetwork.sendSyncMessage(request);
780
820
  }
821
+ /**
822
+ * Host <-> Client sync.
823
+ */
781
824
  async getHostInfo() {
782
825
  return this._clientNetwork.getHostInfo();
783
826
  }
@@ -860,32 +903,32 @@ var AutomergeDocumentLoaderImpl = class {
860
903
  return;
861
904
  }
862
905
  if (!spaceState.rootUrl) {
863
- import_log2.log.error("Database opened with no rootUrl", {
864
- spaceId: this._spaceId
865
- }, {
866
- F: __dxlog_file4,
867
- L: 72,
868
- S: this,
869
- C: (f, a) => f(...a)
870
- });
871
- this._createContextBoundSpaceRootDocument(ctx);
872
- } else {
873
- const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
874
- const doc = existingDocHandle.docSync();
875
- (0, import_invariant4.invariant)(doc, void 0, {
876
- F: __dxlog_file4,
877
- L: 77,
878
- S: this,
879
- A: [
880
- "doc",
881
- ""
882
- ]
883
- });
884
- if (doc.access == null) {
885
- this._initDocAccess(existingDocHandle);
886
- }
887
- this._spaceRootDocHandle = existingDocHandle;
906
+ throw new Error("Database opened with no rootUrl");
907
+ }
908
+ const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
909
+ const doc = existingDocHandle.docSync();
910
+ (0, import_invariant3.invariant)(doc, void 0, {
911
+ F: __dxlog_file4,
912
+ L: 84,
913
+ S: this,
914
+ A: [
915
+ "doc",
916
+ ""
917
+ ]
918
+ });
919
+ (0, import_invariant3.invariant)(doc.version === import_echo_protocol.SpaceDocVersion.CURRENT, void 0, {
920
+ F: __dxlog_file4,
921
+ L: 85,
922
+ S: this,
923
+ A: [
924
+ "doc.version === SpaceDocVersion.CURRENT",
925
+ ""
926
+ ]
927
+ });
928
+ if (doc.access == null) {
929
+ this._initDocAccess(existingDocHandle);
888
930
  }
931
+ this._spaceRootDocHandle = existingDocHandle;
889
932
  }
890
933
  loadObjectDocument(objectIdOrMany) {
891
934
  const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
@@ -894,9 +937,9 @@ var AutomergeDocumentLoaderImpl = class {
894
937
  let hasUrlsToLoad = false;
895
938
  const urlsToLoad = {};
896
939
  for (const objectId of objectIds) {
897
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
940
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
898
941
  F: __dxlog_file4,
899
- L: 90,
942
+ L: 97,
900
943
  S: this,
901
944
  A: [
902
945
  "this._spaceRootDocHandle",
@@ -907,9 +950,9 @@ var AutomergeDocumentLoaderImpl = class {
907
950
  continue;
908
951
  }
909
952
  const spaceRootDoc = this._spaceRootDocHandle.docSync();
910
- (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
953
+ (0, import_invariant3.invariant)(spaceRootDoc, void 0, {
911
954
  F: __dxlog_file4,
912
- L: 95,
955
+ L: 102,
913
956
  S: this,
914
957
  A: [
915
958
  "spaceRootDoc",
@@ -923,7 +966,7 @@ var AutomergeDocumentLoaderImpl = class {
923
966
  objectId
924
967
  }, {
925
968
  F: __dxlog_file4,
926
- L: 99,
969
+ L: 106,
927
970
  S: this,
928
971
  C: (f, a) => f(...a)
929
972
  });
@@ -936,6 +979,32 @@ var AutomergeDocumentLoaderImpl = class {
936
979
  this._loadLinkedObjects(urlsToLoad);
937
980
  }
938
981
  }
982
+ getObjectDocumentId(objectId) {
983
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
984
+ F: __dxlog_file4,
985
+ L: 118,
986
+ S: this,
987
+ A: [
988
+ "this._spaceRootDocHandle",
989
+ ""
990
+ ]
991
+ });
992
+ const spaceRootDoc = this._spaceRootDocHandle.docSync();
993
+ (0, import_invariant3.invariant)(spaceRootDoc, void 0, {
994
+ F: __dxlog_file4,
995
+ L: 120,
996
+ S: this,
997
+ A: [
998
+ "spaceRootDoc",
999
+ ""
1000
+ ]
1001
+ });
1002
+ if (spaceRootDoc.objects?.[objectId]) {
1003
+ return this._spaceRootDocHandle.documentId;
1004
+ }
1005
+ const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1006
+ return documentUrl && (0, import_automerge_repo4.interpretAsDocumentId)(documentUrl);
1007
+ }
939
1008
  onObjectLinksUpdated(links) {
940
1009
  if (!links) {
941
1010
  return;
@@ -945,9 +1014,9 @@ var AutomergeDocumentLoaderImpl = class {
945
1014
  linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
946
1015
  }
947
1016
  getSpaceRootDocHandle() {
948
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1017
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
949
1018
  F: __dxlog_file4,
950
- L: 122,
1019
+ L: 140,
951
1020
  S: this,
952
1021
  A: [
953
1022
  "this._spaceRootDocHandle",
@@ -957,9 +1026,9 @@ var AutomergeDocumentLoaderImpl = class {
957
1026
  return this._spaceRootDocHandle;
958
1027
  }
959
1028
  createDocumentForObject(objectId) {
960
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1029
+ (0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
961
1030
  F: __dxlog_file4,
962
- L: 127,
1031
+ L: 145,
963
1032
  S: this,
964
1033
  A: [
965
1034
  "this._spaceRootDocHandle",
@@ -1004,7 +1073,7 @@ var AutomergeDocumentLoaderImpl = class {
1004
1073
  actualDocumentUrl: objectDocumentHandle.url
1005
1074
  }, {
1006
1075
  F: __dxlog_file4,
1007
- L: 159,
1076
+ L: 177,
1008
1077
  S: this,
1009
1078
  C: (f, a) => f(...a)
1010
1079
  });
@@ -1013,7 +1082,7 @@ var AutomergeDocumentLoaderImpl = class {
1013
1082
  if (objectDocumentHandle?.url === automergeUrl) {
1014
1083
  import_log2.log.warn("object document was already loaded", logMeta, {
1015
1084
  F: __dxlog_file4,
1016
- L: 166,
1085
+ L: 184,
1017
1086
  S: this,
1018
1087
  C: (f, a) => f(...a)
1019
1088
  });
@@ -1022,7 +1091,7 @@ var AutomergeDocumentLoaderImpl = class {
1022
1091
  const handle = this._repo.find(automergeUrl);
1023
1092
  import_log2.log.debug("document loading triggered", logMeta, {
1024
1093
  F: __dxlog_file4,
1025
- L: 170,
1094
+ L: 188,
1026
1095
  S: this,
1027
1096
  C: (f, a) => f(...a)
1028
1097
  });
@@ -1045,7 +1114,7 @@ var AutomergeDocumentLoaderImpl = class {
1045
1114
  state: docHandle.state
1046
1115
  }, {
1047
1116
  F: __dxlog_file4,
1048
- L: 186,
1117
+ L: 204,
1049
1118
  S: this,
1050
1119
  C: (f, a) => f(...a)
1051
1120
  });
@@ -1059,14 +1128,6 @@ var AutomergeDocumentLoaderImpl = class {
1059
1128
  }
1060
1129
  return docHandle;
1061
1130
  }
1062
- _createContextBoundSpaceRootDocument(ctx) {
1063
- const docHandle = this._repo.create();
1064
- this._spaceRootDocHandle = docHandle;
1065
- ctx.onDispose(() => {
1066
- docHandle.delete();
1067
- this._spaceRootDocHandle = null;
1068
- });
1069
- }
1070
1131
  _initDocAccess(handle) {
1071
1132
  handle.change((newDoc) => {
1072
1133
  newDoc.access ??= {
@@ -1087,7 +1148,7 @@ var AutomergeDocumentLoaderImpl = class {
1087
1148
  if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1088
1149
  import_log2.log.info("document loaded after all listeners were removed", logMeta, {
1089
1150
  F: __dxlog_file4,
1090
- L: 222,
1151
+ L: 231,
1091
1152
  S: this,
1092
1153
  C: (f, a) => f(...a)
1093
1154
  });
@@ -1097,7 +1158,7 @@ var AutomergeDocumentLoaderImpl = class {
1097
1158
  if (objectDocHandle?.url !== handle.url) {
1098
1159
  import_log2.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1099
1160
  F: __dxlog_file4,
1100
- L: 227,
1161
+ L: 236,
1101
1162
  S: this,
1102
1163
  C: (f, a) => f(...a)
1103
1164
  });
@@ -1116,7 +1177,7 @@ var AutomergeDocumentLoaderImpl = class {
1116
1177
  err
1117
1178
  }, {
1118
1179
  F: __dxlog_file4,
1119
- L: 233,
1180
+ L: 242,
1120
1181
  S: this,
1121
1182
  C: (f, a) => f(...a)
1122
1183
  });
@@ -1154,7 +1215,7 @@ var MeshEchoReplicator = class {
1154
1215
  this._context = null;
1155
1216
  }
1156
1217
  createExtension() {
1157
- (0, import_invariant5.invariant)(this._context, void 0, {
1218
+ (0, import_invariant4.invariant)(this._context, void 0, {
1158
1219
  F: __dxlog_file5,
1159
1220
  L: 54,
1160
1221
  S: this,
@@ -1174,7 +1235,7 @@ var MeshEchoReplicator = class {
1174
1235
  S: this,
1175
1236
  C: (f, a) => f(...a)
1176
1237
  });
1177
- (0, import_invariant5.invariant)(this._context, void 0, {
1238
+ (0, import_invariant4.invariant)(this._context, void 0, {
1178
1239
  F: __dxlog_file5,
1179
1240
  L: 60,
1180
1241
  S: this,
@@ -1187,8 +1248,8 @@ var MeshEchoReplicator = class {
1187
1248
  this._context.onConnectionAuthScopeChanged(connection);
1188
1249
  } else {
1189
1250
  this._connectionsPerPeer.set(connection.peerId, connection);
1190
- await connection.enable();
1191
1251
  this._context.onConnectionOpen(connection);
1252
+ await connection.enable();
1192
1253
  }
1193
1254
  },
1194
1255
  onRemoteDisconnected: async () => {
@@ -1215,7 +1276,7 @@ var MeshEchoReplicator = class {
1215
1276
  S: this,
1216
1277
  C: (f, a) => f(...a)
1217
1278
  });
1218
- (0, import_invariant5.invariant)(this._context, void 0, {
1279
+ (0, import_invariant4.invariant)(this._context, void 0, {
1219
1280
  F: __dxlog_file5,
1220
1281
  L: 79,
1221
1282
  S: this,
@@ -1315,7 +1376,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1315
1376
  this.writable = new WritableStream({
1316
1377
  write: async (message, controller) => {
1317
1378
  this.replicatorExtension.sendSyncMessage({
1318
- payload: import_automerge_repo4.cbor.encode(message)
1379
+ payload: import_automerge_repo5.cbor.encode(message)
1319
1380
  }).catch((err) => {
1320
1381
  controller.error(err);
1321
1382
  });
@@ -1343,7 +1404,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1343
1404
  if (!this._isEnabled) {
1344
1405
  return;
1345
1406
  }
1346
- const message = import_automerge_repo4.cbor.decode(payload);
1407
+ const message = import_automerge_repo5.cbor.decode(payload);
1347
1408
  readableStreamController.enqueue(message);
1348
1409
  },
1349
1410
  onClose: async () => {
@@ -1355,7 +1416,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1355
1416
  });
1356
1417
  }
1357
1418
  get peerId() {
1358
- (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1419
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1359
1420
  F: __dxlog_file5,
1360
1421
  L: 215,
1361
1422
  S: this,
@@ -1374,7 +1435,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1374
1435
  * Call after the remote peer has connected.
1375
1436
  */
1376
1437
  async enable() {
1377
- (0, import_invariant5.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1438
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1378
1439
  F: __dxlog_file5,
1379
1440
  L: 228,
1380
1441
  S: this,