@dxos/echo-pipeline 0.3.9-main.a33ec16 → 0.3.9-main.a983bcd

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,45 @@ 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
+ //
2771
+ // Methods for client-services.
2772
+ //
2755
2773
  syncRepo(request) {
2756
2774
  return this._clientNetwork.syncRepo(request);
2757
2775
  }
2758
2776
  sendSyncMessage(request) {
2759
2777
  return this._clientNetwork.sendSyncMessage(request);
2760
2778
  }
2779
+ getHostInfo() {
2780
+ return this._clientNetwork.getHostInfo();
2781
+ }
2761
2782
  };
2762
2783
  var LocalHostNetworkAdapter = class extends NetworkAdapter {
2763
2784
  constructor() {
2764
- super();
2785
+ super(...arguments);
2765
2786
  this._peers = /* @__PURE__ */ new Map();
2787
+ }
2788
+ /**
2789
+ * Emits `ready` event. That signals to `Repo` that it can start using the adapter.
2790
+ */
2791
+ ready() {
2766
2792
  this.emit("ready", {
2767
2793
  network: this
2768
2794
  });
2769
2795
  }
2770
2796
  connect(peerId) {
2797
+ this.peerId = peerId;
2771
2798
  }
2772
2799
  send(message) {
2773
2800
  const peer = this._peers.get(message.targetId);
2774
2801
  invariant10(peer, "Peer not found.", {
2775
2802
  F: __dxlog_file14,
2776
- L: 83,
2803
+ L: 96,
2777
2804
  S: this,
2778
2805
  A: [
2779
2806
  "peer",
@@ -2783,14 +2810,14 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2783
2810
  peer.send(message);
2784
2811
  }
2785
2812
  disconnect() {
2786
- throw new Error("Method not implemented.");
2813
+ this._peers.forEach((peer) => peer.disconnect());
2787
2814
  }
2788
2815
  syncRepo({ id, syncMessage }) {
2789
2816
  const peerId = this._getPeerId(id);
2790
2817
  return new Stream2(({ next, close }) => {
2791
2818
  invariant10(!this._peers.has(peerId), "Peer already connected.", {
2792
2819
  F: __dxlog_file14,
2793
- L: 95,
2820
+ L: 108,
2794
2821
  S: this,
2795
2822
  A: [
2796
2823
  "!this._peers.has(peerId)",
@@ -2821,6 +2848,20 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2821
2848
  const message = cbor.decode(syncMessage);
2822
2849
  this.emit("message", message);
2823
2850
  }
2851
+ getHostInfo() {
2852
+ invariant10(this.peerId, "Peer id not set.", {
2853
+ F: __dxlog_file14,
2854
+ L: 137,
2855
+ S: this,
2856
+ A: [
2857
+ "this.peerId",
2858
+ "'Peer id not set.'"
2859
+ ]
2860
+ });
2861
+ return {
2862
+ peerId: this.peerId
2863
+ };
2864
+ }
2824
2865
  _getPeerId(id) {
2825
2866
  return id;
2826
2867
  }
@@ -2845,6 +2886,9 @@ var AutomergeStorageAdapter = class extends StorageAdapter {
2845
2886
  const filename = this._getFilename(key);
2846
2887
  const file = this._directory.getOrCreateFile(filename);
2847
2888
  const { size } = await file.stat();
2889
+ if (!size || size === 0) {
2890
+ return void 0;
2891
+ }
2848
2892
  const buffer = await file.read(0, size);
2849
2893
  return bufferToArray(buffer);
2850
2894
  }
@@ -2916,4 +2960,4 @@ export {
2916
2960
  SpaceManager,
2917
2961
  AutomergeHost
2918
2962
  };
2919
- //# sourceMappingURL=chunk-CLHJJVQE.mjs.map
2963
+ //# sourceMappingURL=chunk-T5EIODOA.mjs.map