@dxos/echo-pipeline 0.3.9-main.eb5df3b → 0.3.9-main.ee839a8

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.
@@ -129,7 +129,7 @@ var DataServiceHost = class {
129
129
  const { batch, meta } = message;
130
130
  invariant2(!meta.clientTag, "Unexpected client tag in mutation message", {
131
131
  F: __dxlog_file2,
132
- L: 137,
132
+ L: 138,
133
133
  S: this,
134
134
  A: [
135
135
  "!(meta as any).clientTag",
@@ -141,7 +141,7 @@ var DataServiceHost = class {
141
141
  meta
142
142
  }, {
143
143
  F: __dxlog_file2,
144
- L: 138,
144
+ L: 139,
145
145
  S: this,
146
146
  C: (f, a) => f(...a)
147
147
  });
@@ -185,7 +185,7 @@ var DataServiceHost = class {
185
185
  async write(request) {
186
186
  invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
187
187
  F: __dxlog_file2,
188
- L: 183,
188
+ L: 184,
189
189
  S: this,
190
190
  A: [
191
191
  "!this._ctx.disposed",
@@ -194,7 +194,7 @@ var DataServiceHost = class {
194
194
  });
195
195
  invariant2(this._writeStream, "Cannot write mutations in readonly mode", {
196
196
  F: __dxlog_file2,
197
- L: 184,
197
+ L: 185,
198
198
  S: this,
199
199
  A: [
200
200
  "this._writeStream",
@@ -206,7 +206,7 @@ var DataServiceHost = class {
206
206
  objectCount: request.batch.objects?.length ?? 0
207
207
  }, {
208
208
  F: __dxlog_file2,
209
- L: 186,
209
+ L: 187,
210
210
  S: this,
211
211
  C: (f, a) => f(...a)
212
212
  });
@@ -220,7 +220,7 @@ var DataServiceHost = class {
220
220
  seq: receipt2.seq
221
221
  }, {
222
222
  F: __dxlog_file2,
223
- L: 195,
223
+ L: 196,
224
224
  S: this,
225
225
  C: (f, a) => f(...a)
226
226
  });
@@ -236,6 +236,9 @@ var DataServiceHost = class {
236
236
  async flush() {
237
237
  await this._flush();
238
238
  }
239
+ getHostInfo() {
240
+ throw new Error("Method not implemented.");
241
+ }
239
242
  syncRepo(request) {
240
243
  throw new Error("Method not implemented.");
241
244
  }
@@ -388,13 +391,13 @@ var DataServiceSubscriptions = class {
388
391
  spaceKey
389
392
  }, {
390
393
  F: __dxlog_file3,
391
- L: 34,
394
+ L: 35,
392
395
  S: this,
393
396
  C: (f, a) => f(...a)
394
397
  });
395
398
  invariant3(!this._spaces.has(spaceKey), void 0, {
396
399
  F: __dxlog_file3,
397
- L: 35,
400
+ L: 36,
398
401
  S: this,
399
402
  A: [
400
403
  "!this._spaces.has(spaceKey)",
@@ -409,7 +412,7 @@ var DataServiceSubscriptions = class {
409
412
  spaceKey
410
413
  }, {
411
414
  F: __dxlog_file3,
412
- L: 41,
415
+ L: 42,
413
416
  S: this,
414
417
  C: (f, a) => f(...a)
415
418
  });
@@ -429,7 +432,7 @@ var DataServiceImpl = class {
429
432
  subscribe(request) {
430
433
  invariant3(request.spaceKey, void 0, {
431
434
  F: __dxlog_file3,
432
- L: 63,
435
+ L: 64,
433
436
  S: this,
434
437
  A: [
435
438
  "request.spaceKey",
@@ -442,7 +445,7 @@ var DataServiceImpl = class {
442
445
  write(request) {
443
446
  invariant3(request.spaceKey, void 0, {
444
447
  F: __dxlog_file3,
445
- L: 70,
448
+ L: 71,
446
449
  S: this,
447
450
  A: [
448
451
  "request.spaceKey",
@@ -451,7 +454,7 @@ var DataServiceImpl = class {
451
454
  });
452
455
  invariant3(request.batch, void 0, {
453
456
  F: __dxlog_file3,
454
- L: 71,
457
+ L: 72,
455
458
  S: this,
456
459
  A: [
457
460
  "request.batch",
@@ -464,7 +467,7 @@ var DataServiceImpl = class {
464
467
  flush(request) {
465
468
  invariant3(request.spaceKey, void 0, {
466
469
  F: __dxlog_file3,
467
- L: 78,
470
+ L: 79,
468
471
  S: this,
469
472
  A: [
470
473
  "request.spaceKey",
@@ -474,11 +477,15 @@ var DataServiceImpl = class {
474
477
  const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
475
478
  return host.flush();
476
479
  }
480
+ // Automerge specific.
481
+ async getHostInfo(request) {
482
+ return this._automergeHost.getHostInfo();
483
+ }
477
484
  syncRepo(request) {
478
- throw new Error("Method not implemented.");
485
+ return this._automergeHost.syncRepo(request);
479
486
  }
480
487
  sendSyncMessage(request) {
481
- throw new Error("Method not implemented.");
488
+ return this._automergeHost.sendSyncMessage(request);
482
489
  }
483
490
  };
484
491
 
@@ -2680,7 +2687,7 @@ var SpaceManager = class SpaceManager2 {
2680
2687
  id: this._instanceId
2681
2688
  }), {
2682
2689
  F: __dxlog_file13,
2683
- L: 97,
2690
+ L: 100,
2684
2691
  S: this,
2685
2692
  C: (f, a) => f(...a)
2686
2693
  });
@@ -2688,7 +2695,7 @@ var SpaceManager = class SpaceManager2 {
2688
2695
  spaceKey: metadata.genesisFeedKey
2689
2696
  }, {
2690
2697
  F: __dxlog_file13,
2691
- L: 98,
2698
+ L: 101,
2692
2699
  S: this,
2693
2700
  C: (f, a) => f(...a)
2694
2701
  });
@@ -2718,7 +2725,7 @@ var SpaceManager = class SpaceManager2 {
2718
2725
  id: this._instanceId
2719
2726
  }), {
2720
2727
  F: __dxlog_file13,
2721
- L: 126,
2728
+ L: 129,
2722
2729
  S: this,
2723
2730
  C: (f, a) => f(...a)
2724
2731
  });
@@ -2739,6 +2746,8 @@ SpaceManager = _ts_decorate8([
2739
2746
  import { Repo, NetworkAdapter, StorageAdapter, cbor } from "@dxos/automerge/automerge-repo";
2740
2747
  import { Stream as Stream2 } from "@dxos/codec-protobuf";
2741
2748
  import { invariant as invariant10 } from "@dxos/invariant";
2749
+ import { log as log13 } from "@dxos/log";
2750
+ import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
2742
2751
  import { arrayToBuffer as arrayToBuffer2, bufferToArray } from "@dxos/util";
2743
2752
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
2744
2753
  var AutomergeHost = class {
@@ -2748,39 +2757,62 @@ var AutomergeHost = class {
2748
2757
  this._storage = new AutomergeStorageAdapter(storageDirectory);
2749
2758
  this._repo = new Repo({
2750
2759
  network: [
2751
- // this._meshNetwork,
2752
- this._clientNetwork
2760
+ this._clientNetwork,
2761
+ this._meshNetwork
2753
2762
  ],
2754
2763
  storage: this._storage,
2755
2764
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
2756
2765
  sharePolicy: async (peerId, documentId) => true
2757
2766
  });
2767
+ this._clientNetwork.ready();
2768
+ this._meshNetwork.ready();
2758
2769
  }
2759
2770
  get repo() {
2760
2771
  return this._repo;
2761
2772
  }
2773
+ async close() {
2774
+ await this._clientNetwork.close();
2775
+ }
2776
+ //
2777
+ // Methods for client-services.
2778
+ //
2762
2779
  syncRepo(request) {
2763
2780
  return this._clientNetwork.syncRepo(request);
2764
2781
  }
2765
2782
  sendSyncMessage(request) {
2766
2783
  return this._clientNetwork.sendSyncMessage(request);
2767
2784
  }
2785
+ getHostInfo() {
2786
+ return this._clientNetwork.getHostInfo();
2787
+ }
2788
+ //
2789
+ // Mesh replication.
2790
+ //
2791
+ createExtension() {
2792
+ return this._meshNetwork.createExtension();
2793
+ }
2768
2794
  };
2769
2795
  var LocalHostNetworkAdapter = class extends NetworkAdapter {
2770
2796
  constructor() {
2771
- super();
2797
+ super(...arguments);
2772
2798
  this._peers = /* @__PURE__ */ new Map();
2799
+ }
2800
+ /**
2801
+ * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
2802
+ */
2803
+ ready() {
2773
2804
  this.emit("ready", {
2774
2805
  network: this
2775
2806
  });
2776
2807
  }
2777
2808
  connect(peerId) {
2809
+ this.peerId = peerId;
2778
2810
  }
2779
2811
  send(message) {
2780
2812
  const peer = this._peers.get(message.targetId);
2781
2813
  invariant10(peer, "Peer not found.", {
2782
2814
  F: __dxlog_file14,
2783
- L: 83,
2815
+ L: 108,
2784
2816
  S: this,
2785
2817
  A: [
2786
2818
  "peer",
@@ -2789,15 +2821,18 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2789
2821
  });
2790
2822
  peer.send(message);
2791
2823
  }
2824
+ async close() {
2825
+ this._peers.forEach((peer) => peer.disconnect());
2826
+ this.emit("close");
2827
+ }
2792
2828
  disconnect() {
2793
- throw new Error("Method not implemented.");
2794
2829
  }
2795
2830
  syncRepo({ id, syncMessage }) {
2796
2831
  const peerId = this._getPeerId(id);
2797
2832
  return new Stream2(({ next, close }) => {
2798
2833
  invariant10(!this._peers.has(peerId), "Peer already connected.", {
2799
2834
  F: __dxlog_file14,
2800
- L: 95,
2835
+ L: 126,
2801
2836
  S: this,
2802
2837
  A: [
2803
2838
  "!this._peers.has(peerId)",
@@ -2828,19 +2863,95 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2828
2863
  const message = cbor.decode(syncMessage);
2829
2864
  this.emit("message", message);
2830
2865
  }
2866
+ getHostInfo() {
2867
+ invariant10(this.peerId, "Peer id not set.", {
2868
+ F: __dxlog_file14,
2869
+ L: 155,
2870
+ S: this,
2871
+ A: [
2872
+ "this.peerId",
2873
+ "'Peer id not set.'"
2874
+ ]
2875
+ });
2876
+ return {
2877
+ peerId: this.peerId
2878
+ };
2879
+ }
2831
2880
  _getPeerId(id) {
2832
2881
  return id;
2833
2882
  }
2834
2883
  };
2835
2884
  var MeshNetworkAdapter = class extends NetworkAdapter {
2885
+ constructor() {
2886
+ super(...arguments);
2887
+ this._extensions = /* @__PURE__ */ new Map();
2888
+ }
2889
+ /**
2890
+ * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
2891
+ */
2892
+ ready() {
2893
+ this.emit("ready", {
2894
+ network: this
2895
+ });
2896
+ }
2836
2897
  connect(peerId) {
2837
- throw new Error("Method not implemented.");
2898
+ this.peerId = peerId;
2838
2899
  }
2839
2900
  send(message) {
2840
- throw new Error("Method not implemented.");
2901
+ const receiverId = message.targetId;
2902
+ const extension = this._extensions.get(receiverId);
2903
+ invariant10(extension, "Extension not found.", {
2904
+ F: __dxlog_file14,
2905
+ L: 190,
2906
+ S: this,
2907
+ A: [
2908
+ "extension",
2909
+ "'Extension not found.'"
2910
+ ]
2911
+ });
2912
+ extension.sendSyncMessage({
2913
+ payload: cbor.encode(message)
2914
+ }).catch((err) => log13.catch(err, void 0, {
2915
+ F: __dxlog_file14,
2916
+ L: 191,
2917
+ S: this,
2918
+ C: (f, a) => f(...a)
2919
+ }));
2841
2920
  }
2842
2921
  disconnect() {
2843
- throw new Error("Method not implemented.");
2922
+ }
2923
+ createExtension() {
2924
+ invariant10(this.peerId, "Peer id not set.", {
2925
+ F: __dxlog_file14,
2926
+ L: 199,
2927
+ S: this,
2928
+ A: [
2929
+ "this.peerId",
2930
+ "'Peer id not set.'"
2931
+ ]
2932
+ });
2933
+ let peerInfo;
2934
+ const extension = new AutomergeReplicator({
2935
+ peerId: this.peerId
2936
+ }, {
2937
+ onStartReplication: async (info) => {
2938
+ peerInfo = info;
2939
+ this._extensions.set(info.id, extension);
2940
+ this.emit("peer-candidate", {
2941
+ peerId: info.id
2942
+ });
2943
+ },
2944
+ onSyncMessage: async ({ payload }) => {
2945
+ const message = cbor.decode(payload);
2946
+ this.emit("message", message);
2947
+ },
2948
+ onClose: async () => {
2949
+ peerInfo && this.emit("peer-disconnected", {
2950
+ peerId: peerInfo.id
2951
+ });
2952
+ }
2953
+ });
2954
+ return extension;
2844
2955
  }
2845
2956
  };
2846
2957
  var AutomergeStorageAdapter = class extends StorageAdapter {
@@ -2852,6 +2963,9 @@ var AutomergeStorageAdapter = class extends StorageAdapter {
2852
2963
  const filename = this._getFilename(key);
2853
2964
  const file = this._directory.getOrCreateFile(filename);
2854
2965
  const { size } = await file.stat();
2966
+ if (!size || size === 0) {
2967
+ return void 0;
2968
+ }
2855
2969
  const buffer = await file.read(0, size);
2856
2970
  return bufferToArray(buffer);
2857
2971
  }
@@ -2923,4 +3037,4 @@ export {
2923
3037
  SpaceManager,
2924
3038
  AutomergeHost
2925
3039
  };
2926
- //# sourceMappingURL=chunk-T627FAUD.mjs.map
3040
+ //# sourceMappingURL=chunk-6XOL2DVG.mjs.map