@dxos/echo-pipeline 0.3.9-main.f8fc6b9 → 0.3.9-next.4584ca9

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
 
@@ -2755,32 +2762,48 @@ var AutomergeHost = class {
2755
2762
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
2756
2763
  sharePolicy: async (peerId, documentId) => true
2757
2764
  });
2765
+ this._clientNetwork.ready();
2758
2766
  }
2759
2767
  get repo() {
2760
2768
  return this._repo;
2761
2769
  }
2770
+ async close() {
2771
+ await this._clientNetwork.close();
2772
+ }
2773
+ //
2774
+ // Methods for client-services.
2775
+ //
2762
2776
  syncRepo(request) {
2763
2777
  return this._clientNetwork.syncRepo(request);
2764
2778
  }
2765
2779
  sendSyncMessage(request) {
2766
2780
  return this._clientNetwork.sendSyncMessage(request);
2767
2781
  }
2782
+ getHostInfo() {
2783
+ return this._clientNetwork.getHostInfo();
2784
+ }
2768
2785
  };
2769
2786
  var LocalHostNetworkAdapter = class extends NetworkAdapter {
2770
2787
  constructor() {
2771
- super();
2788
+ super(...arguments);
2772
2789
  this._peers = /* @__PURE__ */ new Map();
2790
+ }
2791
+ /**
2792
+ * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
2793
+ */
2794
+ ready() {
2773
2795
  this.emit("ready", {
2774
2796
  network: this
2775
2797
  });
2776
2798
  }
2777
2799
  connect(peerId) {
2800
+ this.peerId = peerId;
2778
2801
  }
2779
2802
  send(message) {
2780
2803
  const peer = this._peers.get(message.targetId);
2781
2804
  invariant10(peer, "Peer not found.", {
2782
2805
  F: __dxlog_file14,
2783
- L: 83,
2806
+ L: 100,
2784
2807
  S: this,
2785
2808
  A: [
2786
2809
  "peer",
@@ -2789,15 +2812,18 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2789
2812
  });
2790
2813
  peer.send(message);
2791
2814
  }
2815
+ async close() {
2816
+ this._peers.forEach((peer) => peer.disconnect());
2817
+ this.emit("close");
2818
+ }
2792
2819
  disconnect() {
2793
- throw new Error("Method not implemented.");
2794
2820
  }
2795
2821
  syncRepo({ id, syncMessage }) {
2796
2822
  const peerId = this._getPeerId(id);
2797
2823
  return new Stream2(({ next, close }) => {
2798
2824
  invariant10(!this._peers.has(peerId), "Peer already connected.", {
2799
2825
  F: __dxlog_file14,
2800
- L: 95,
2826
+ L: 118,
2801
2827
  S: this,
2802
2828
  A: [
2803
2829
  "!this._peers.has(peerId)",
@@ -2828,6 +2854,20 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2828
2854
  const message = cbor.decode(syncMessage);
2829
2855
  this.emit("message", message);
2830
2856
  }
2857
+ getHostInfo() {
2858
+ invariant10(this.peerId, "Peer id not set.", {
2859
+ F: __dxlog_file14,
2860
+ L: 147,
2861
+ S: this,
2862
+ A: [
2863
+ "this.peerId",
2864
+ "'Peer id not set.'"
2865
+ ]
2866
+ });
2867
+ return {
2868
+ peerId: this.peerId
2869
+ };
2870
+ }
2831
2871
  _getPeerId(id) {
2832
2872
  return id;
2833
2873
  }
@@ -2852,6 +2892,9 @@ var AutomergeStorageAdapter = class extends StorageAdapter {
2852
2892
  const filename = this._getFilename(key);
2853
2893
  const file = this._directory.getOrCreateFile(filename);
2854
2894
  const { size } = await file.stat();
2895
+ if (!size || size === 0) {
2896
+ return void 0;
2897
+ }
2855
2898
  const buffer = await file.read(0, size);
2856
2899
  return bufferToArray(buffer);
2857
2900
  }
@@ -2923,4 +2966,4 @@ export {
2923
2966
  SpaceManager,
2924
2967
  AutomergeHost
2925
2968
  };
2926
- //# sourceMappingURL=chunk-T627FAUD.mjs.map
2969
+ //# sourceMappingURL=chunk-RV3JOJQ4.mjs.map