@dxos/echo-pipeline 0.6.1 → 0.6.2-main.8a232a5

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 (45) hide show
  1. package/dist/lib/browser/{chunk-DMUP426Q.mjs → chunk-UJQ5VS5V.mjs} +383 -196
  2. package/dist/lib/browser/chunk-UJQ5VS5V.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +59 -562
  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 +1 -1
  7. package/dist/lib/node/{chunk-NH5WJKOW.cjs → chunk-RH6TDRML.cjs} +438 -256
  8. package/dist/lib/node/chunk-RH6TDRML.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +80 -581
  10. package/dist/lib/node/index.cjs.map +4 -4
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/testing/index.cjs +11 -11
  13. package/dist/types/src/automerge/automerge-host.d.ts +2 -17
  14. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
  15. package/dist/types/src/automerge/echo-network-adapter.d.ts +1 -1
  16. package/dist/types/src/automerge/index.d.ts +0 -2
  17. package/dist/types/src/automerge/index.d.ts.map +1 -1
  18. package/dist/types/src/db-host/data-service.d.ts +10 -7
  19. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  20. package/dist/types/src/db-host/documents-synchronizer.d.ts +43 -0
  21. package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -0
  22. package/dist/types/src/db-host/documents-synchronizer.test.d.ts +2 -0
  23. package/dist/types/src/db-host/documents-synchronizer.test.d.ts.map +1 -0
  24. package/dist/types/src/db-host/index.d.ts +1 -0
  25. package/dist/types/src/db-host/index.d.ts.map +1 -1
  26. package/package.json +33 -33
  27. package/src/automerge/automerge-host.ts +6 -56
  28. package/src/automerge/automerge-repo.test.ts +124 -1
  29. package/src/automerge/echo-network-adapter.ts +1 -1
  30. package/src/automerge/index.ts +0 -2
  31. package/src/db-host/data-service.ts +49 -25
  32. package/src/db-host/documents-synchronizer.test.ts +40 -0
  33. package/src/db-host/documents-synchronizer.ts +156 -0
  34. package/src/db-host/index.ts +1 -0
  35. package/dist/lib/browser/chunk-DMUP426Q.mjs.map +0 -7
  36. package/dist/lib/node/chunk-NH5WJKOW.cjs.map +0 -7
  37. package/dist/types/src/automerge/automerge-doc-loader.d.ts +0 -71
  38. package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +0 -1
  39. package/dist/types/src/automerge/automerge-doc-loader.test.d.ts +0 -2
  40. package/dist/types/src/automerge/automerge-doc-loader.test.d.ts.map +0 -1
  41. package/dist/types/src/automerge/local-host-network-adapter.d.ts +0 -30
  42. package/dist/types/src/automerge/local-host-network-adapter.d.ts.map +0 -1
  43. package/src/automerge/automerge-doc-loader.test.ts +0 -103
  44. package/src/automerge/automerge-doc-loader.ts +0 -267
  45. package/src/automerge/local-host-network-adapter.ts +0 -115
@@ -18,40 +18,39 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- AuthExtension: () => import_chunk_NH5WJKOW.AuthExtension,
22
- AuthStatus: () => import_chunk_NH5WJKOW.AuthStatus,
23
- AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
21
+ AuthExtension: () => import_chunk_RH6TDRML.AuthExtension,
22
+ AuthStatus: () => import_chunk_RH6TDRML.AuthStatus,
24
23
  AutomergeHost: () => AutomergeHost,
25
- CredentialRetrieverExtension: () => import_chunk_NH5WJKOW.CredentialRetrieverExtension,
26
- CredentialServerExtension: () => import_chunk_NH5WJKOW.CredentialServerExtension,
27
- DataServiceImpl: () => import_chunk_NH5WJKOW.DataServiceImpl,
24
+ CredentialRetrieverExtension: () => import_chunk_RH6TDRML.CredentialRetrieverExtension,
25
+ CredentialServerExtension: () => import_chunk_RH6TDRML.CredentialServerExtension,
26
+ DataServiceImpl: () => import_chunk_RH6TDRML.DataServiceImpl,
27
+ DocumentsSynchronizer: () => import_chunk_RH6TDRML.DocumentsSynchronizer,
28
28
  LevelDBStorageAdapter: () => LevelDBStorageAdapter,
29
- LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
30
- MOCK_AUTH_PROVIDER: () => import_chunk_NH5WJKOW.MOCK_AUTH_PROVIDER,
31
- MOCK_AUTH_VERIFIER: () => import_chunk_NH5WJKOW.MOCK_AUTH_VERIFIER,
29
+ MOCK_AUTH_PROVIDER: () => import_chunk_RH6TDRML.MOCK_AUTH_PROVIDER,
30
+ MOCK_AUTH_VERIFIER: () => import_chunk_RH6TDRML.MOCK_AUTH_VERIFIER,
32
31
  MeshEchoReplicator: () => MeshEchoReplicator,
33
- MetadataStore: () => import_chunk_NH5WJKOW.MetadataStore,
34
- Pipeline: () => import_chunk_NH5WJKOW.Pipeline,
35
- SnapshotManager: () => import_chunk_NH5WJKOW.SnapshotManager,
36
- SnapshotStore: () => import_chunk_NH5WJKOW.SnapshotStore,
37
- Space: () => import_chunk_NH5WJKOW.Space,
38
- SpaceManager: () => import_chunk_NH5WJKOW.SpaceManager,
39
- SpaceProtocol: () => import_chunk_NH5WJKOW.SpaceProtocol,
40
- SpaceProtocolSession: () => import_chunk_NH5WJKOW.SpaceProtocolSession,
41
- TimeframeClock: () => import_chunk_NH5WJKOW.TimeframeClock,
42
- codec: () => import_chunk_NH5WJKOW.codec,
43
- createIdFromSpaceKey: () => import_chunk_NH5WJKOW.createIdFromSpaceKey,
44
- createMappedFeedWriter: () => import_chunk_NH5WJKOW.createMappedFeedWriter,
32
+ MetadataStore: () => import_chunk_RH6TDRML.MetadataStore,
33
+ Pipeline: () => import_chunk_RH6TDRML.Pipeline,
34
+ SnapshotManager: () => import_chunk_RH6TDRML.SnapshotManager,
35
+ SnapshotStore: () => import_chunk_RH6TDRML.SnapshotStore,
36
+ Space: () => import_chunk_RH6TDRML.Space,
37
+ SpaceManager: () => import_chunk_RH6TDRML.SpaceManager,
38
+ SpaceProtocol: () => import_chunk_RH6TDRML.SpaceProtocol,
39
+ SpaceProtocolSession: () => import_chunk_RH6TDRML.SpaceProtocolSession,
40
+ TimeframeClock: () => import_chunk_RH6TDRML.TimeframeClock,
41
+ codec: () => import_chunk_RH6TDRML.codec,
42
+ createIdFromSpaceKey: () => import_chunk_RH6TDRML.createIdFromSpaceKey,
43
+ createMappedFeedWriter: () => import_chunk_RH6TDRML.createMappedFeedWriter,
45
44
  encodingOptions: () => encodingOptions,
46
45
  getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
47
- hasInvitationExpired: () => import_chunk_NH5WJKOW.hasInvitationExpired,
48
- mapFeedIndexesToTimeframe: () => import_chunk_NH5WJKOW.mapFeedIndexesToTimeframe,
49
- mapTimeframeToFeedIndexes: () => import_chunk_NH5WJKOW.mapTimeframeToFeedIndexes,
50
- startAfter: () => import_chunk_NH5WJKOW.startAfter,
51
- valueEncoding: () => import_chunk_NH5WJKOW.valueEncoding
46
+ hasInvitationExpired: () => import_chunk_RH6TDRML.hasInvitationExpired,
47
+ mapFeedIndexesToTimeframe: () => import_chunk_RH6TDRML.mapFeedIndexesToTimeframe,
48
+ mapTimeframeToFeedIndexes: () => import_chunk_RH6TDRML.mapTimeframeToFeedIndexes,
49
+ startAfter: () => import_chunk_RH6TDRML.startAfter,
50
+ valueEncoding: () => import_chunk_RH6TDRML.valueEncoding
52
51
  });
53
52
  module.exports = __toCommonJS(node_exports);
54
- var import_chunk_NH5WJKOW = require("./chunk-NH5WJKOW.cjs");
53
+ var import_chunk_RH6TDRML = require("./chunk-RH6TDRML.cjs");
55
54
  var import_async = require("@dxos/async");
56
55
  var import_automerge = require("@dxos/automerge/automerge");
57
56
  var import_automerge_repo = require("@dxos/automerge/automerge-repo");
@@ -69,26 +68,14 @@ var import_invariant2 = require("@dxos/invariant");
69
68
  var import_log2 = require("@dxos/log");
70
69
  var import_indexing = require("@dxos/indexing");
71
70
  var import_context3 = require("@dxos/context");
72
- var import_async3 = require("@dxos/async");
73
- var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
74
- var import_codec_protobuf = require("@dxos/codec-protobuf");
75
71
  var import_invariant3 = require("@dxos/invariant");
76
- var import_async4 = require("@dxos/async");
77
- var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
72
+ var import_keys2 = require("@dxos/keys");
73
+ var import_log3 = require("@dxos/log");
74
+ var import_util2 = require("@dxos/util");
75
+ var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
78
76
  var import_context4 = require("@dxos/context");
79
- var import_debug = require("@dxos/debug");
80
- var import_echo_protocol = require("@dxos/echo-protocol");
81
77
  var import_invariant4 = require("@dxos/invariant");
82
- var import_log3 = require("@dxos/log");
83
- var import_tracing2 = require("@dxos/tracing");
84
- var import_invariant5 = require("@dxos/invariant");
85
- var import_keys2 = require("@dxos/keys");
86
78
  var import_log4 = require("@dxos/log");
87
- var import_util2 = require("@dxos/util");
88
- var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
89
- var import_context5 = require("@dxos/context");
90
- var import_invariant6 = require("@dxos/invariant");
91
- var import_log5 = require("@dxos/log");
92
79
  var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
93
80
  function _ts_decorate(decorators, target, key, desc) {
94
81
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -150,7 +137,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
150
137
  }
151
138
  async close() {
152
139
  if (this._lifecycleState === import_context2.LifecycleState.CLOSED) {
153
- return;
140
+ return this;
154
141
  }
155
142
  for (const replicator of this._replicators) {
156
143
  await replicator.disconnect();
@@ -493,138 +480,6 @@ var encodingOptions = {
493
480
  valueEncoding: "buffer"
494
481
  };
495
482
  var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
496
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
497
- var LocalHostNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
498
- constructor() {
499
- super(...arguments);
500
- this._peers = /* @__PURE__ */ new Map();
501
- this._connected = new import_async3.Trigger();
502
- this._isConnected = false;
503
- }
504
- /**
505
- * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
506
- */
507
- ready() {
508
- this.emit("ready", {
509
- network: this
510
- });
511
- }
512
- /**
513
- * Called by `Repo` to connect to the network.
514
- *
515
- * @param peerId Our peer Id.
516
- */
517
- connect(peerId) {
518
- this.peerId = peerId;
519
- this._isConnected = true;
520
- this._connected.wake();
521
- }
522
- send(message) {
523
- const peer = this._peers.get(message.targetId);
524
- (0, import_invariant3.invariant)(peer, "Peer not found.", {
525
- F: __dxlog_file2,
526
- L: 51,
527
- S: this,
528
- A: [
529
- "peer",
530
- "'Peer not found.'"
531
- ]
532
- });
533
- peer.send(message);
534
- }
535
- async close() {
536
- this._peers.forEach((peer) => peer.disconnect());
537
- this.emit("close");
538
- }
539
- disconnect() {
540
- }
541
- async whenConnected() {
542
- await this._connected.wait({
543
- timeout: 1e4
544
- });
545
- }
546
- syncRepo({ id, syncMessage }) {
547
- const peerId = this._getPeerId(id);
548
- return new import_codec_protobuf.Stream(({ next, close }) => {
549
- (0, import_invariant3.invariant)(!this._peers.has(peerId), "Peer already connected.", {
550
- F: __dxlog_file2,
551
- L: 73,
552
- S: this,
553
- A: [
554
- "!this._peers.has(peerId)",
555
- "'Peer already connected.'"
556
- ]
557
- });
558
- this._peers.set(peerId, {
559
- connected: true,
560
- send: (message) => {
561
- next({
562
- syncMessage: import_automerge_repo3.cbor.encode(message)
563
- });
564
- },
565
- disconnect: () => {
566
- this._peers.delete(peerId);
567
- close();
568
- this.emit("peer-disconnected", {
569
- peerId
570
- });
571
- }
572
- });
573
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
574
- F: __dxlog_file2,
575
- L: 90,
576
- S: this,
577
- A: [
578
- "this._isConnected",
579
- ""
580
- ]
581
- });
582
- this.emit("peer-candidate", {
583
- peerMetadata: {},
584
- peerId
585
- });
586
- });
587
- }
588
- async sendSyncMessage({ id, syncMessage }) {
589
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
590
- F: __dxlog_file2,
591
- L: 99,
592
- S: this,
593
- A: [
594
- "this._isConnected",
595
- ""
596
- ]
597
- });
598
- const message = import_automerge_repo3.cbor.decode(syncMessage);
599
- this.emit("message", message);
600
- }
601
- async getHostInfo() {
602
- (0, import_invariant3.invariant)(this._isConnected, void 0, {
603
- F: __dxlog_file2,
604
- L: 105,
605
- S: this,
606
- A: [
607
- "this._isConnected",
608
- ""
609
- ]
610
- });
611
- (0, import_invariant3.invariant)(this.peerId, "Peer id not set.", {
612
- F: __dxlog_file2,
613
- L: 106,
614
- S: this,
615
- A: [
616
- "this.peerId",
617
- "'Peer id not set.'"
618
- ]
619
- });
620
- return {
621
- peerId: this.peerId
622
- };
623
- }
624
- _getPeerId(id) {
625
- return id;
626
- }
627
- };
628
483
  function _ts_decorate2(decorators, target, key, desc) {
629
484
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
630
485
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -635,7 +490,7 @@ function _ts_decorate2(decorators, target, key, desc) {
635
490
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
636
491
  return c > 3 && r && Object.defineProperty(target, key, r), r;
637
492
  }
638
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
493
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
639
494
  var AutomergeHost = class extends import_context.Resource {
640
495
  constructor({ db, indexMetadataStore }) {
641
496
  super();
@@ -658,26 +513,20 @@ var AutomergeHost = class extends import_context.Resource {
658
513
  async _open() {
659
514
  this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
660
515
  await this._storage.open?.();
661
- this._clientNetwork = new LocalHostNetworkAdapter();
662
516
  this._repo = new import_automerge_repo.Repo({
663
517
  peerId: this._peerId,
664
518
  sharePolicy: this._sharePolicy.bind(this),
665
519
  storage: this._storage,
666
520
  network: [
667
- // Downstream client.
668
- this._clientNetwork,
669
521
  // Upstream swarm.
670
522
  this._echoNetworkAdapter
671
523
  ]
672
524
  });
673
- this._clientNetwork.ready();
674
525
  await this._echoNetworkAdapter.open();
675
- await this._clientNetwork.whenConnected();
676
526
  await this._echoNetworkAdapter.whenConnected();
677
527
  }
678
528
  async _close() {
679
529
  await this._storage.close?.();
680
- await this._clientNetwork.close();
681
530
  await this._echoNetworkAdapter.close();
682
531
  await this._ctx.dispose();
683
532
  }
@@ -739,8 +588,8 @@ var AutomergeHost = class extends import_context.Resource {
739
588
  return;
740
589
  }
741
590
  const handle = await this.loadDoc(import_context.Context.default(void 0, {
742
- F: __dxlog_file3,
743
- L: 207
591
+ F: __dxlog_file2,
592
+ L: 189
744
593
  }), documentId);
745
594
  await waitForHeads(handle, heads2);
746
595
  }) ?? []);
@@ -751,8 +600,8 @@ var AutomergeHost = class extends import_context.Resource {
751
600
  import_log.log.info("re-indexing heads for document", {
752
601
  documentId
753
602
  }, {
754
- F: __dxlog_file3,
755
- L: 218,
603
+ F: __dxlog_file2,
604
+ L: 200,
756
605
  S: this,
757
606
  C: (f, a) => f(...a)
758
607
  });
@@ -767,8 +616,8 @@ var AutomergeHost = class extends import_context.Resource {
767
616
  import_log.log.warn("document is not available locally, skipping", {
768
617
  documentId
769
618
  }, {
770
- F: __dxlog_file3,
771
- L: 222,
619
+ F: __dxlog_file2,
620
+ L: 204,
772
621
  S: this,
773
622
  C: (f, a) => f(...a)
774
623
  });
@@ -776,8 +625,8 @@ var AutomergeHost = class extends import_context.Resource {
776
625
  }
777
626
  const doc = handle.docSync();
778
627
  (0, import_invariant.invariant)(doc, void 0, {
779
- F: __dxlog_file3,
780
- L: 227,
628
+ F: __dxlog_file2,
629
+ L: 209,
781
630
  S: this,
782
631
  A: [
783
632
  "doc",
@@ -790,8 +639,8 @@ var AutomergeHost = class extends import_context.Resource {
790
639
  await batch.write();
791
640
  }
792
641
  import_log.log.info("done re-indexing heads", void 0, {
793
- F: __dxlog_file3,
794
- L: 234,
642
+ F: __dxlog_file2,
643
+ L: 216,
795
644
  S: this,
796
645
  C: (f, a) => f(...a)
797
646
  });
@@ -884,17 +733,8 @@ var AutomergeHost = class extends import_context.Resource {
884
733
  /**
885
734
  * Flush documents to disk.
886
735
  */
887
- async flush({ states } = {}) {
888
- if (states) {
889
- await Promise.all(states.map(async ({ heads, documentId }) => {
890
- if (!heads) {
891
- return;
892
- }
893
- const handle = this._repo.handles[documentId] ?? this._repo.find(documentId);
894
- await waitForHeads(handle, heads);
895
- }) ?? []);
896
- }
897
- await this._repo.flush(states?.map(({ documentId }) => documentId));
736
+ async flush({ documentIds } = {}) {
737
+ await this._repo.flush(documentIds);
898
738
  }
899
739
  async getHeads(documentId) {
900
740
  const handle = this._repo.handles[documentId];
@@ -908,24 +748,6 @@ var AutomergeHost = class extends import_context.Resource {
908
748
  return this._headsStore.getHeads(documentId);
909
749
  }
910
750
  }
911
- /**
912
- * Host <-> Client sync.
913
- */
914
- syncRepo(request) {
915
- return this._clientNetwork.syncRepo(request);
916
- }
917
- /**
918
- * Host <-> Client sync.
919
- */
920
- sendSyncMessage(request) {
921
- return this._clientNetwork.sendSyncMessage(request);
922
- }
923
- /**
924
- * Host <-> Client sync.
925
- */
926
- async getHostInfo() {
927
- return this._clientNetwork.getHostInfo();
928
- }
929
751
  };
930
752
  _ts_decorate2([
931
753
  import_tracing.trace.info()
@@ -970,331 +792,9 @@ var waitForHeads = async (handle, heads) => {
970
792
  var changeIsPresentInDoc = (doc, changeHash) => {
971
793
  return !!(0, import_automerge.getBackend)(doc).getChangeByHash(changeHash);
972
794
  };
973
- function _ts_decorate3(decorators, target, key, desc) {
974
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
975
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
976
- r = Reflect.decorate(decorators, target, key, desc);
977
- else
978
- for (var i = decorators.length - 1; i >= 0; i--)
979
- if (d = decorators[i])
980
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
981
- return c > 3 && r && Object.defineProperty(target, key, r), r;
982
- }
983
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
984
- var AutomergeDocumentLoaderImpl = class {
985
- constructor(_spaceId, _repo, _spaceKey) {
986
- this._spaceId = _spaceId;
987
- this._repo = _repo;
988
- this._spaceKey = _spaceKey;
989
- this._spaceRootDocHandle = null;
990
- this._objectDocumentHandles = /* @__PURE__ */ new Map();
991
- this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
992
- this.onObjectDocumentLoaded = new import_async4.Event();
993
- }
994
- getAllHandles() {
995
- return this._spaceRootDocHandle != null ? [
996
- this._spaceRootDocHandle,
997
- ...new Set(this._objectDocumentHandles.values())
998
- ] : [];
999
- }
1000
- async loadSpaceRootDocHandle(ctx, spaceState) {
1001
- if (this._spaceRootDocHandle != null) {
1002
- return;
1003
- }
1004
- if (!spaceState.rootUrl) {
1005
- throw new Error("Database opened with no rootUrl");
1006
- }
1007
- const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
1008
- const doc = existingDocHandle.docSync();
1009
- (0, import_invariant4.invariant)(doc, void 0, {
1010
- F: __dxlog_file4,
1011
- L: 84,
1012
- S: this,
1013
- A: [
1014
- "doc",
1015
- ""
1016
- ]
1017
- });
1018
- (0, import_invariant4.invariant)(doc.version === import_echo_protocol.SpaceDocVersion.CURRENT, void 0, {
1019
- F: __dxlog_file4,
1020
- L: 85,
1021
- S: this,
1022
- A: [
1023
- "doc.version === SpaceDocVersion.CURRENT",
1024
- ""
1025
- ]
1026
- });
1027
- if (doc.access == null) {
1028
- this._initDocAccess(existingDocHandle);
1029
- }
1030
- this._spaceRootDocHandle = existingDocHandle;
1031
- }
1032
- loadObjectDocument(objectIdOrMany) {
1033
- const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
1034
- objectIdOrMany
1035
- ];
1036
- let hasUrlsToLoad = false;
1037
- const urlsToLoad = {};
1038
- for (const objectId of objectIds) {
1039
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1040
- F: __dxlog_file4,
1041
- L: 97,
1042
- S: this,
1043
- A: [
1044
- "this._spaceRootDocHandle",
1045
- ""
1046
- ]
1047
- });
1048
- if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
1049
- continue;
1050
- }
1051
- const spaceRootDoc = this._spaceRootDocHandle.docSync();
1052
- (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
1053
- F: __dxlog_file4,
1054
- L: 102,
1055
- S: this,
1056
- A: [
1057
- "spaceRootDoc",
1058
- ""
1059
- ]
1060
- });
1061
- const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1062
- if (documentUrl == null) {
1063
- this._objectsPendingDocumentLoad.add(objectId);
1064
- import_log3.log.info("loading delayed until object links are initialized", {
1065
- objectId
1066
- }, {
1067
- F: __dxlog_file4,
1068
- L: 106,
1069
- S: this,
1070
- C: (f, a) => f(...a)
1071
- });
1072
- } else {
1073
- urlsToLoad[objectId] = documentUrl;
1074
- hasUrlsToLoad = true;
1075
- }
1076
- }
1077
- if (hasUrlsToLoad) {
1078
- this._loadLinkedObjects(urlsToLoad);
1079
- }
1080
- }
1081
- getObjectDocumentId(objectId) {
1082
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1083
- F: __dxlog_file4,
1084
- L: 118,
1085
- S: this,
1086
- A: [
1087
- "this._spaceRootDocHandle",
1088
- ""
1089
- ]
1090
- });
1091
- const spaceRootDoc = this._spaceRootDocHandle.docSync();
1092
- (0, import_invariant4.invariant)(spaceRootDoc, void 0, {
1093
- F: __dxlog_file4,
1094
- L: 120,
1095
- S: this,
1096
- A: [
1097
- "spaceRootDoc",
1098
- ""
1099
- ]
1100
- });
1101
- if (spaceRootDoc.objects?.[objectId]) {
1102
- return this._spaceRootDocHandle.documentId;
1103
- }
1104
- const documentUrl = (spaceRootDoc.links ?? {})[objectId];
1105
- return documentUrl && (0, import_automerge_repo4.interpretAsDocumentId)(documentUrl);
1106
- }
1107
- onObjectLinksUpdated(links) {
1108
- if (!links) {
1109
- return;
1110
- }
1111
- const linksAwaitingLoad = Object.entries(links).filter(([objectId]) => this._objectsPendingDocumentLoad.has(objectId));
1112
- this._loadLinkedObjects(Object.fromEntries(linksAwaitingLoad));
1113
- linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
1114
- }
1115
- getSpaceRootDocHandle() {
1116
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1117
- F: __dxlog_file4,
1118
- L: 140,
1119
- S: this,
1120
- A: [
1121
- "this._spaceRootDocHandle",
1122
- ""
1123
- ]
1124
- });
1125
- return this._spaceRootDocHandle;
1126
- }
1127
- createDocumentForObject(objectId) {
1128
- (0, import_invariant4.invariant)(this._spaceRootDocHandle, void 0, {
1129
- F: __dxlog_file4,
1130
- L: 145,
1131
- S: this,
1132
- A: [
1133
- "this._spaceRootDocHandle",
1134
- ""
1135
- ]
1136
- });
1137
- const spaceDocHandle = this._repo.create({
1138
- version: import_echo_protocol.SpaceDocVersion.CURRENT
1139
- });
1140
- this._initDocAccess(spaceDocHandle);
1141
- this.onObjectBoundToDocument(spaceDocHandle, objectId);
1142
- this._spaceRootDocHandle.change((newDoc) => {
1143
- newDoc.links ??= {};
1144
- newDoc.links[objectId] = spaceDocHandle.url;
1145
- });
1146
- return spaceDocHandle;
1147
- }
1148
- onObjectBoundToDocument(handle, objectId) {
1149
- this._objectDocumentHandles.set(objectId, handle);
1150
- }
1151
- clearHandleReferences() {
1152
- const objectsWithHandles = [
1153
- ...this._objectDocumentHandles.keys()
1154
- ];
1155
- this._objectDocumentHandles.clear();
1156
- this._spaceRootDocHandle = null;
1157
- return objectsWithHandles;
1158
- }
1159
- _loadLinkedObjects(links) {
1160
- if (!links) {
1161
- return;
1162
- }
1163
- for (const [objectId, automergeUrl] of Object.entries(links)) {
1164
- const logMeta = {
1165
- objectId,
1166
- automergeUrl
1167
- };
1168
- const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
1169
- if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
1170
- import_log3.log.warn("object already inlined in a different document, ignoring the link", {
1171
- ...logMeta,
1172
- actualDocumentUrl: objectDocumentHandle.url
1173
- }, {
1174
- F: __dxlog_file4,
1175
- L: 177,
1176
- S: this,
1177
- C: (f, a) => f(...a)
1178
- });
1179
- continue;
1180
- }
1181
- if (objectDocumentHandle?.url === automergeUrl) {
1182
- import_log3.log.warn("object document was already loaded", logMeta, {
1183
- F: __dxlog_file4,
1184
- L: 184,
1185
- S: this,
1186
- C: (f, a) => f(...a)
1187
- });
1188
- continue;
1189
- }
1190
- const handle = this._repo.find(automergeUrl);
1191
- import_log3.log.debug("document loading triggered", logMeta, {
1192
- F: __dxlog_file4,
1193
- L: 188,
1194
- S: this,
1195
- C: (f, a) => f(...a)
1196
- });
1197
- this._objectDocumentHandles.set(objectId, handle);
1198
- void this._createObjectOnDocumentLoad(handle, objectId);
1199
- }
1200
- }
1201
- async _initDocHandle(ctx, url) {
1202
- const docHandle = this._repo.find(url);
1203
- while (true) {
1204
- try {
1205
- await (0, import_debug.warnAfterTimeout)(5e3, "Automerge root doc load timeout (CoreDatabase)", async () => {
1206
- await (0, import_context4.cancelWithContext)(ctx, docHandle.whenReady());
1207
- });
1208
- break;
1209
- } catch (err) {
1210
- if (`${err}`.includes("Timeout")) {
1211
- import_log3.log.info("wraparound", {
1212
- id: docHandle.documentId,
1213
- state: docHandle.state
1214
- }, {
1215
- F: __dxlog_file4,
1216
- L: 204,
1217
- S: this,
1218
- C: (f, a) => f(...a)
1219
- });
1220
- continue;
1221
- }
1222
- throw err;
1223
- }
1224
- }
1225
- if (docHandle.state === "unavailable") {
1226
- throw new Error("Automerge document is unavailable");
1227
- }
1228
- return docHandle;
1229
- }
1230
- _initDocAccess(handle) {
1231
- handle.change((newDoc) => {
1232
- newDoc.access ??= {
1233
- spaceKey: this._spaceKey.toHex()
1234
- };
1235
- newDoc.access.spaceKey = this._spaceKey.toHex();
1236
- });
1237
- }
1238
- async _createObjectOnDocumentLoad(handle, objectId) {
1239
- try {
1240
- await handle.whenReady();
1241
- const logMeta = {
1242
- objectId,
1243
- docUrl: handle.url
1244
- };
1245
- if (this.onObjectDocumentLoaded.listenerCount() === 0) {
1246
- import_log3.log.info("document loaded after all listeners were removed", logMeta, {
1247
- F: __dxlog_file4,
1248
- L: 231,
1249
- S: this,
1250
- C: (f, a) => f(...a)
1251
- });
1252
- return;
1253
- }
1254
- const objectDocHandle = this._objectDocumentHandles.get(objectId);
1255
- if (objectDocHandle?.url !== handle.url) {
1256
- import_log3.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
1257
- F: __dxlog_file4,
1258
- L: 236,
1259
- S: this,
1260
- C: (f, a) => f(...a)
1261
- });
1262
- return;
1263
- }
1264
- this.onObjectDocumentLoaded.emit({
1265
- handle,
1266
- objectId
1267
- });
1268
- } catch (err) {
1269
- const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
1270
- import_log3.log.warn("failed to load a document", {
1271
- objectId,
1272
- automergeUrl: handle.url,
1273
- retryLoading: shouldRetryLoading,
1274
- err
1275
- }, {
1276
- F: __dxlog_file4,
1277
- L: 242,
1278
- S: this,
1279
- C: (f, a) => f(...a)
1280
- });
1281
- if (shouldRetryLoading) {
1282
- await this._createObjectOnDocumentLoad(handle, objectId);
1283
- }
1284
- }
1285
- }
1286
- };
1287
- _ts_decorate3([
1288
- import_tracing2.trace.span({
1289
- showInBrowserTimeline: true
1290
- })
1291
- ], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
1292
- AutomergeDocumentLoaderImpl = _ts_decorate3([
1293
- import_tracing2.trace.resource()
1294
- ], AutomergeDocumentLoaderImpl);
1295
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator-connection.ts";
795
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator-connection.ts";
1296
796
  var DEFAULT_FACTORY = (params) => new import_teleport_extension_automerge_replicator.AutomergeReplicator(...params);
1297
- var MeshReplicatorConnection = class extends import_context5.Resource {
797
+ var MeshReplicatorConnection = class extends import_context4.Resource {
1298
798
  constructor(_params) {
1299
799
  super();
1300
800
  this._params = _params;
@@ -1310,8 +810,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1310
810
  });
1311
811
  this.writable = new WritableStream({
1312
812
  write: async (message, controller) => {
1313
- (0, import_invariant6.invariant)(this._isEnabled, "Writing to a disabled connection", {
1314
- F: __dxlog_file5,
813
+ (0, import_invariant4.invariant)(this._isEnabled, "Writing to a disabled connection", {
814
+ F: __dxlog_file3,
1315
815
  L: 47,
1316
816
  S: this,
1317
817
  A: [
@@ -1321,7 +821,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1321
821
  });
1322
822
  try {
1323
823
  await this.replicatorExtension.sendSyncMessage({
1324
- payload: import_automerge_repo5.cbor.encode(message)
824
+ payload: import_automerge_repo3.cbor.encode(message)
1325
825
  });
1326
826
  } catch (err) {
1327
827
  controller.error(err);
@@ -1338,12 +838,12 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1338
838
  onStartReplication: async (info, remotePeerId) => {
1339
839
  this.remoteDeviceKey = remotePeerId;
1340
840
  this._remotePeerId = info.id;
1341
- (0, import_log5.log)("onStartReplication", {
841
+ (0, import_log4.log)("onStartReplication", {
1342
842
  id: info.id,
1343
843
  thisPeerId: this.peerId,
1344
844
  remotePeerId: remotePeerId.toHex()
1345
845
  }, {
1346
- F: __dxlog_file5,
846
+ F: __dxlog_file3,
1347
847
  L: 81,
1348
848
  S: this,
1349
849
  C: (f, a) => f(...a)
@@ -1354,7 +854,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1354
854
  if (!this._isEnabled) {
1355
855
  return;
1356
856
  }
1357
- const message = import_automerge_repo5.cbor.decode(payload);
857
+ const message = import_automerge_repo3.cbor.decode(payload);
1358
858
  readableStreamController.enqueue(message);
1359
859
  },
1360
860
  onClose: async () => {
@@ -1369,8 +869,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1369
869
  }
1370
870
  }
1371
871
  get peerId() {
1372
- (0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1373
- F: __dxlog_file5,
872
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
873
+ F: __dxlog_file3,
1374
874
  L: 107,
1375
875
  S: this,
1376
876
  A: [
@@ -1388,8 +888,8 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1388
888
  * Call after the remote peer has connected.
1389
889
  */
1390
890
  enable() {
1391
- (0, import_invariant6.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
1392
- F: __dxlog_file5,
891
+ (0, import_invariant4.invariant)(this._remotePeerId != null, "Remote peer has not connected yet.", {
892
+ F: __dxlog_file3,
1393
893
  L: 120,
1394
894
  S: this,
1395
895
  A: [
@@ -1406,7 +906,7 @@ var MeshReplicatorConnection = class extends import_context5.Resource {
1406
906
  this._isEnabled = false;
1407
907
  }
1408
908
  };
1409
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
909
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-echo-replicator.ts";
1410
910
  var MeshEchoReplicator = class {
1411
911
  constructor() {
1412
912
  this._connections = /* @__PURE__ */ new Set();
@@ -1426,8 +926,8 @@ var MeshEchoReplicator = class {
1426
926
  this._context = null;
1427
927
  }
1428
928
  createExtension(extensionFactory) {
1429
- (0, import_invariant5.invariant)(this._context, void 0, {
1430
- F: __dxlog_file6,
929
+ (0, import_invariant3.invariant)(this._context, void 0, {
930
+ F: __dxlog_file4,
1431
931
  L: 51,
1432
932
  S: this,
1433
933
  A: [
@@ -1439,16 +939,16 @@ var MeshEchoReplicator = class {
1439
939
  ownPeerId: this._context.peerId,
1440
940
  replicatorFactory: extensionFactory,
1441
941
  onRemoteConnected: async () => {
1442
- (0, import_log4.log)("onRemoteConnected", {
942
+ (0, import_log3.log)("onRemoteConnected", {
1443
943
  peerId: connection.peerId
1444
944
  }, {
1445
- F: __dxlog_file6,
945
+ F: __dxlog_file4,
1446
946
  L: 57,
1447
947
  S: this,
1448
948
  C: (f, a) => f(...a)
1449
949
  });
1450
- (0, import_invariant5.invariant)(this._context, void 0, {
1451
- F: __dxlog_file6,
950
+ (0, import_invariant3.invariant)(this._context, void 0, {
951
+ F: __dxlog_file4,
1452
952
  L: 58,
1453
953
  S: this,
1454
954
  A: [
@@ -1465,10 +965,10 @@ var MeshEchoReplicator = class {
1465
965
  }
1466
966
  },
1467
967
  onRemoteDisconnected: async () => {
1468
- (0, import_log4.log)("onRemoteDisconnected", {
968
+ (0, import_log3.log)("onRemoteDisconnected", {
1469
969
  peerId: connection.peerId
1470
970
  }, {
1471
- F: __dxlog_file6,
971
+ F: __dxlog_file4,
1472
972
  L: 69,
1473
973
  S: this,
1474
974
  C: (f, a) => f(...a)
@@ -1479,17 +979,17 @@ var MeshEchoReplicator = class {
1479
979
  this._connections.delete(connection);
1480
980
  },
1481
981
  shouldAdvertise: async (params) => {
1482
- (0, import_log4.log)("shouldAdvertise", {
982
+ (0, import_log3.log)("shouldAdvertise", {
1483
983
  peerId: connection.peerId,
1484
984
  documentId: params.documentId
1485
985
  }, {
1486
- F: __dxlog_file6,
986
+ F: __dxlog_file4,
1487
987
  L: 76,
1488
988
  S: this,
1489
989
  C: (f, a) => f(...a)
1490
990
  });
1491
- (0, import_invariant5.invariant)(this._context, void 0, {
1492
- F: __dxlog_file6,
991
+ (0, import_invariant3.invariant)(this._context, void 0, {
992
+ F: __dxlog_file4,
1493
993
  L: 77,
1494
994
  S: this,
1495
995
  A: [
@@ -1500,11 +1000,11 @@ var MeshEchoReplicator = class {
1500
1000
  try {
1501
1001
  const spaceKey = await this._context.getContainingSpaceForDocument(params.documentId);
1502
1002
  if (!spaceKey) {
1503
- (0, import_log4.log)("space key not found for share policy check", {
1003
+ (0, import_log3.log)("space key not found for share policy check", {
1504
1004
  peerId: connection.peerId,
1505
1005
  documentId: params.documentId
1506
1006
  }, {
1507
- F: __dxlog_file6,
1007
+ F: __dxlog_file4,
1508
1008
  L: 81,
1509
1009
  S: this,
1510
1010
  C: (f, a) => f(...a)
@@ -1513,11 +1013,11 @@ var MeshEchoReplicator = class {
1513
1013
  }
1514
1014
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
1515
1015
  if (!connection.remoteDeviceKey) {
1516
- (0, import_log4.log)("device key not found for share policy check", {
1016
+ (0, import_log3.log)("device key not found for share policy check", {
1517
1017
  peerId: connection.peerId,
1518
1018
  documentId: params.documentId
1519
1019
  }, {
1520
- F: __dxlog_file6,
1020
+ F: __dxlog_file4,
1521
1021
  L: 91,
1522
1022
  S: this,
1523
1023
  C: (f, a) => f(...a)
@@ -1525,7 +1025,7 @@ var MeshEchoReplicator = class {
1525
1025
  return false;
1526
1026
  }
1527
1027
  const isAuthorized = authorizedDevices?.has(connection.remoteDeviceKey) ?? false;
1528
- (0, import_log4.log)("share policy check", {
1028
+ (0, import_log3.log)("share policy check", {
1529
1029
  localPeer: this._context.peerId,
1530
1030
  remotePeer: connection.peerId,
1531
1031
  documentId: params.documentId,
@@ -1533,15 +1033,15 @@ var MeshEchoReplicator = class {
1533
1033
  spaceKey,
1534
1034
  isAuthorized
1535
1035
  }, {
1536
- F: __dxlog_file6,
1036
+ F: __dxlog_file4,
1537
1037
  L: 99,
1538
1038
  S: this,
1539
1039
  C: (f, a) => f(...a)
1540
1040
  });
1541
1041
  return isAuthorized;
1542
1042
  } catch (err) {
1543
- import_log4.log.catch(err, void 0, {
1544
- F: __dxlog_file6,
1043
+ import_log3.log.catch(err, void 0, {
1044
+ F: __dxlog_file4,
1545
1045
  L: 109,
1546
1046
  S: this,
1547
1047
  C: (f, a) => f(...a)
@@ -1554,11 +1054,11 @@ var MeshEchoReplicator = class {
1554
1054
  return connection.replicatorExtension;
1555
1055
  }
1556
1056
  authorizeDevice(spaceKey, deviceKey) {
1557
- (0, import_log4.log)("authorizeDevice", {
1057
+ (0, import_log3.log)("authorizeDevice", {
1558
1058
  spaceKey,
1559
1059
  deviceKey
1560
1060
  }, {
1561
- F: __dxlog_file6,
1061
+ F: __dxlog_file4,
1562
1062
  L: 120,
1563
1063
  S: this,
1564
1064
  C: (f, a) => f(...a)
@@ -1577,13 +1077,12 @@ var MeshEchoReplicator = class {
1577
1077
  0 && (module.exports = {
1578
1078
  AuthExtension,
1579
1079
  AuthStatus,
1580
- AutomergeDocumentLoaderImpl,
1581
1080
  AutomergeHost,
1582
1081
  CredentialRetrieverExtension,
1583
1082
  CredentialServerExtension,
1584
1083
  DataServiceImpl,
1084
+ DocumentsSynchronizer,
1585
1085
  LevelDBStorageAdapter,
1586
- LocalHostNetworkAdapter,
1587
1086
  MOCK_AUTH_PROVIDER,
1588
1087
  MOCK_AUTH_VERIFIER,
1589
1088
  MeshEchoReplicator,