@dxos/echo-pipeline 0.3.9-main.604ae36 → 0.3.9-main.62f3346

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.
@@ -1,5 +1,12 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
+ // inject-globals:@inject-globals
4
+ import {
5
+ global,
6
+ Buffer,
7
+ process
8
+ } from "@dxos/node-std/inject-globals";
9
+
3
10
  // packages/core/echo/echo-pipeline/src/common/codec.ts
4
11
  import { createCodecEncoding } from "@dxos/hypercore";
5
12
  import { schema } from "@dxos/protocols";
@@ -122,7 +129,7 @@ var DataServiceHost = class {
122
129
  const { batch, meta } = message;
123
130
  invariant2(!meta.clientTag, "Unexpected client tag in mutation message", {
124
131
  F: __dxlog_file2,
125
- L: 137,
132
+ L: 138,
126
133
  S: this,
127
134
  A: [
128
135
  "!(meta as any).clientTag",
@@ -134,7 +141,7 @@ var DataServiceHost = class {
134
141
  meta
135
142
  }, {
136
143
  F: __dxlog_file2,
137
- L: 138,
144
+ L: 139,
138
145
  S: this,
139
146
  C: (f, a) => f(...a)
140
147
  });
@@ -178,7 +185,7 @@ var DataServiceHost = class {
178
185
  async write(request) {
179
186
  invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
180
187
  F: __dxlog_file2,
181
- L: 183,
188
+ L: 184,
182
189
  S: this,
183
190
  A: [
184
191
  "!this._ctx.disposed",
@@ -187,7 +194,7 @@ var DataServiceHost = class {
187
194
  });
188
195
  invariant2(this._writeStream, "Cannot write mutations in readonly mode", {
189
196
  F: __dxlog_file2,
190
- L: 184,
197
+ L: 185,
191
198
  S: this,
192
199
  A: [
193
200
  "this._writeStream",
@@ -199,7 +206,7 @@ var DataServiceHost = class {
199
206
  objectCount: request.batch.objects?.length ?? 0
200
207
  }, {
201
208
  F: __dxlog_file2,
202
- L: 186,
209
+ L: 187,
203
210
  S: this,
204
211
  C: (f, a) => f(...a)
205
212
  });
@@ -213,7 +220,7 @@ var DataServiceHost = class {
213
220
  seq: receipt2.seq
214
221
  }, {
215
222
  F: __dxlog_file2,
216
- L: 195,
223
+ L: 196,
217
224
  S: this,
218
225
  C: (f, a) => f(...a)
219
226
  });
@@ -229,6 +236,9 @@ var DataServiceHost = class {
229
236
  async flush() {
230
237
  await this._flush();
231
238
  }
239
+ getHostInfo() {
240
+ throw new Error("Method not implemented.");
241
+ }
232
242
  syncRepo(request) {
233
243
  throw new Error("Method not implemented.");
234
244
  }
@@ -381,13 +391,13 @@ var DataServiceSubscriptions = class {
381
391
  spaceKey
382
392
  }, {
383
393
  F: __dxlog_file3,
384
- L: 34,
394
+ L: 35,
385
395
  S: this,
386
396
  C: (f, a) => f(...a)
387
397
  });
388
398
  invariant3(!this._spaces.has(spaceKey), void 0, {
389
399
  F: __dxlog_file3,
390
- L: 35,
400
+ L: 36,
391
401
  S: this,
392
402
  A: [
393
403
  "!this._spaces.has(spaceKey)",
@@ -402,7 +412,7 @@ var DataServiceSubscriptions = class {
402
412
  spaceKey
403
413
  }, {
404
414
  F: __dxlog_file3,
405
- L: 41,
415
+ L: 42,
406
416
  S: this,
407
417
  C: (f, a) => f(...a)
408
418
  });
@@ -422,7 +432,7 @@ var DataServiceImpl = class {
422
432
  subscribe(request) {
423
433
  invariant3(request.spaceKey, void 0, {
424
434
  F: __dxlog_file3,
425
- L: 63,
435
+ L: 64,
426
436
  S: this,
427
437
  A: [
428
438
  "request.spaceKey",
@@ -435,7 +445,7 @@ var DataServiceImpl = class {
435
445
  write(request) {
436
446
  invariant3(request.spaceKey, void 0, {
437
447
  F: __dxlog_file3,
438
- L: 70,
448
+ L: 71,
439
449
  S: this,
440
450
  A: [
441
451
  "request.spaceKey",
@@ -444,7 +454,7 @@ var DataServiceImpl = class {
444
454
  });
445
455
  invariant3(request.batch, void 0, {
446
456
  F: __dxlog_file3,
447
- L: 71,
457
+ L: 72,
448
458
  S: this,
449
459
  A: [
450
460
  "request.batch",
@@ -457,7 +467,7 @@ var DataServiceImpl = class {
457
467
  flush(request) {
458
468
  invariant3(request.spaceKey, void 0, {
459
469
  F: __dxlog_file3,
460
- L: 78,
470
+ L: 79,
461
471
  S: this,
462
472
  A: [
463
473
  "request.spaceKey",
@@ -467,11 +477,15 @@ var DataServiceImpl = class {
467
477
  const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
468
478
  return host.flush();
469
479
  }
480
+ // Automerge specific.
481
+ async getHostInfo(request) {
482
+ return this._automergeHost.getHostInfo();
483
+ }
470
484
  syncRepo(request) {
471
- throw new Error("Method not implemented.");
485
+ return this._automergeHost.syncRepo(request);
472
486
  }
473
487
  sendSyncMessage(request) {
474
- throw new Error("Method not implemented.");
488
+ return this._automergeHost.sendSyncMessage(request);
475
489
  }
476
490
  };
477
491
 
@@ -2748,32 +2762,48 @@ var AutomergeHost = class {
2748
2762
  // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
2749
2763
  sharePolicy: async (peerId, documentId) => true
2750
2764
  });
2765
+ this._clientNetwork.ready();
2751
2766
  }
2752
2767
  get repo() {
2753
2768
  return this._repo;
2754
2769
  }
2770
+ async close() {
2771
+ await this._clientNetwork.close();
2772
+ }
2773
+ //
2774
+ // Methods for client-services.
2775
+ //
2755
2776
  syncRepo(request) {
2756
2777
  return this._clientNetwork.syncRepo(request);
2757
2778
  }
2758
2779
  sendSyncMessage(request) {
2759
2780
  return this._clientNetwork.sendSyncMessage(request);
2760
2781
  }
2782
+ getHostInfo() {
2783
+ return this._clientNetwork.getHostInfo();
2784
+ }
2761
2785
  };
2762
2786
  var LocalHostNetworkAdapter = class extends NetworkAdapter {
2763
2787
  constructor() {
2764
- super();
2788
+ super(...arguments);
2765
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() {
2766
2795
  this.emit("ready", {
2767
2796
  network: this
2768
2797
  });
2769
2798
  }
2770
2799
  connect(peerId) {
2800
+ this.peerId = peerId;
2771
2801
  }
2772
2802
  send(message) {
2773
2803
  const peer = this._peers.get(message.targetId);
2774
2804
  invariant10(peer, "Peer not found.", {
2775
2805
  F: __dxlog_file14,
2776
- L: 83,
2806
+ L: 100,
2777
2807
  S: this,
2778
2808
  A: [
2779
2809
  "peer",
@@ -2782,15 +2812,18 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2782
2812
  });
2783
2813
  peer.send(message);
2784
2814
  }
2815
+ async close() {
2816
+ this._peers.forEach((peer) => peer.disconnect());
2817
+ this.emit("close");
2818
+ }
2785
2819
  disconnect() {
2786
- throw new Error("Method not implemented.");
2787
2820
  }
2788
2821
  syncRepo({ id, syncMessage }) {
2789
2822
  const peerId = this._getPeerId(id);
2790
2823
  return new Stream2(({ next, close }) => {
2791
2824
  invariant10(!this._peers.has(peerId), "Peer already connected.", {
2792
2825
  F: __dxlog_file14,
2793
- L: 95,
2826
+ L: 118,
2794
2827
  S: this,
2795
2828
  A: [
2796
2829
  "!this._peers.has(peerId)",
@@ -2821,6 +2854,20 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2821
2854
  const message = cbor.decode(syncMessage);
2822
2855
  this.emit("message", message);
2823
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
+ }
2824
2871
  _getPeerId(id) {
2825
2872
  return id;
2826
2873
  }
@@ -2845,6 +2892,9 @@ var AutomergeStorageAdapter = class extends StorageAdapter {
2845
2892
  const filename = this._getFilename(key);
2846
2893
  const file = this._directory.getOrCreateFile(filename);
2847
2894
  const { size } = await file.stat();
2895
+ if (!size || size === 0) {
2896
+ return void 0;
2897
+ }
2848
2898
  const buffer = await file.read(0, size);
2849
2899
  return bufferToArray(buffer);
2850
2900
  }
@@ -2916,4 +2966,4 @@ export {
2916
2966
  SpaceManager,
2917
2967
  AutomergeHost
2918
2968
  };
2919
- //# sourceMappingURL=chunk-CLHJJVQE.mjs.map
2969
+ //# sourceMappingURL=chunk-RV3JOJQ4.mjs.map