@dxos/echo-pipeline 0.3.9-main.915c0ba → 0.3.9-main.a33ec16

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 (37) hide show
  1. package/dist/lib/browser/{chunk-HSZ2EJ74.mjs → chunk-CLHJJVQE.mjs} +197 -31
  2. package/dist/lib/browser/chunk-CLHJJVQE.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +7 -2
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-RMIDX4JE.cjs → chunk-XWUUSV4Y.cjs} +198 -33
  8. package/dist/lib/node/chunk-XWUUSV4Y.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +27 -25
  10. package/dist/lib/node/index.cjs.map +2 -2
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/testing/index.cjs +18 -14
  13. package/dist/lib/node/testing/index.cjs.map +3 -3
  14. package/dist/types/src/automerge/automerge-host.d.ts +15 -0
  15. package/dist/types/src/automerge/automerge-host.d.ts.map +1 -0
  16. package/dist/types/src/automerge/automerge-host.test.d.ts +2 -0
  17. package/dist/types/src/automerge/automerge-host.test.d.ts.map +1 -0
  18. package/dist/types/src/automerge/index.d.ts +2 -0
  19. package/dist/types/src/automerge/index.d.ts.map +1 -0
  20. package/dist/types/src/db-host/data-service.d.ts +3 -1
  21. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  22. package/dist/types/src/index.d.ts +1 -0
  23. package/dist/types/src/index.d.ts.map +1 -1
  24. package/dist/types/src/space/data-pipeline.d.ts +4 -0
  25. package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
  26. package/dist/types/src/testing/util.d.ts.map +1 -1
  27. package/package.json +32 -31
  28. package/src/automerge/automerge-host.test.ts +42 -0
  29. package/src/automerge/automerge-host.ts +212 -0
  30. package/src/automerge/index.ts +5 -0
  31. package/src/db-host/data-service.ts +5 -1
  32. package/src/index.ts +1 -0
  33. package/src/space/data-pipeline.ts +10 -0
  34. package/src/testing/util.ts +4 -1
  35. package/src/tests/database.test.ts +4 -1
  36. package/dist/lib/browser/chunk-HSZ2EJ74.mjs.map +0 -7
  37. package/dist/lib/node/chunk-RMIDX4JE.cjs.map +0 -7
@@ -381,13 +381,13 @@ var DataServiceSubscriptions = class {
381
381
  spaceKey
382
382
  }, {
383
383
  F: __dxlog_file3,
384
- L: 33,
384
+ L: 34,
385
385
  S: this,
386
386
  C: (f, a) => f(...a)
387
387
  });
388
388
  invariant3(!this._spaces.has(spaceKey), void 0, {
389
389
  F: __dxlog_file3,
390
- L: 34,
390
+ L: 35,
391
391
  S: this,
392
392
  A: [
393
393
  "!this._spaces.has(spaceKey)",
@@ -402,7 +402,7 @@ var DataServiceSubscriptions = class {
402
402
  spaceKey
403
403
  }, {
404
404
  F: __dxlog_file3,
405
- L: 40,
405
+ L: 41,
406
406
  S: this,
407
407
  C: (f, a) => f(...a)
408
408
  });
@@ -415,13 +415,14 @@ var DataServiceSubscriptions = class {
415
415
  }
416
416
  };
417
417
  var DataServiceImpl = class {
418
- constructor(_subscriptions) {
418
+ constructor(_subscriptions, _automergeHost) {
419
419
  this._subscriptions = _subscriptions;
420
+ this._automergeHost = _automergeHost;
420
421
  }
421
422
  subscribe(request) {
422
423
  invariant3(request.spaceKey, void 0, {
423
424
  F: __dxlog_file3,
424
- L: 59,
425
+ L: 63,
425
426
  S: this,
426
427
  A: [
427
428
  "request.spaceKey",
@@ -434,7 +435,7 @@ var DataServiceImpl = class {
434
435
  write(request) {
435
436
  invariant3(request.spaceKey, void 0, {
436
437
  F: __dxlog_file3,
437
- L: 66,
438
+ L: 70,
438
439
  S: this,
439
440
  A: [
440
441
  "request.spaceKey",
@@ -443,7 +444,7 @@ var DataServiceImpl = class {
443
444
  });
444
445
  invariant3(request.batch, void 0, {
445
446
  F: __dxlog_file3,
446
- L: 67,
447
+ L: 71,
447
448
  S: this,
448
449
  A: [
449
450
  "request.batch",
@@ -456,7 +457,7 @@ var DataServiceImpl = class {
456
457
  flush(request) {
457
458
  invariant3(request.spaceKey, void 0, {
458
459
  F: __dxlog_file3,
459
- L: 74,
460
+ L: 78,
460
461
  S: this,
461
462
  A: [
462
463
  "request.spaceKey",
@@ -1517,7 +1518,7 @@ var DataPipeline = class DataPipeline2 {
1517
1518
  write: (data, options) => {
1518
1519
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1519
1520
  F: __dxlog_file9,
1520
- L: 159,
1521
+ L: 164,
1521
1522
  S: this,
1522
1523
  A: [
1523
1524
  "this._pipeline",
@@ -1526,7 +1527,7 @@ var DataPipeline = class DataPipeline2 {
1526
1527
  });
1527
1528
  invariant8(this.currentEpoch, "Epoch is not initialized.", {
1528
1529
  F: __dxlog_file9,
1529
- L: 160,
1530
+ L: 165,
1530
1531
  S: this,
1531
1532
  A: [
1532
1533
  "this.currentEpoch",
@@ -1552,7 +1553,7 @@ var DataPipeline = class DataPipeline2 {
1552
1553
  }
1553
1554
  log8("close", void 0, {
1554
1555
  F: __dxlog_file9,
1555
- L: 184,
1556
+ L: 189,
1556
1557
  S: this,
1557
1558
  C: (f, a) => f(...a)
1558
1559
  });
@@ -1567,7 +1568,7 @@ var DataPipeline = class DataPipeline2 {
1567
1568
  } catch (err) {
1568
1569
  log8.catch(err, void 0, {
1569
1570
  F: __dxlog_file9,
1570
- L: 197,
1571
+ L: 202,
1571
1572
  S: this,
1572
1573
  C: (f, a) => f(...a)
1573
1574
  });
@@ -1592,7 +1593,7 @@ var DataPipeline = class DataPipeline2 {
1592
1593
  let messageCounter = 0;
1593
1594
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1594
1595
  F: __dxlog_file9,
1595
- L: 223,
1596
+ L: 228,
1596
1597
  S: this,
1597
1598
  A: [
1598
1599
  "this._pipeline",
@@ -1608,7 +1609,7 @@ var DataPipeline = class DataPipeline2 {
1608
1609
  seq
1609
1610
  }, {
1610
1611
  F: __dxlog_file9,
1611
- L: 229,
1612
+ L: 234,
1612
1613
  S: this,
1613
1614
  C: (f, a) => f(...a)
1614
1615
  });
@@ -1620,7 +1621,7 @@ var DataPipeline = class DataPipeline2 {
1620
1621
  feedKey
1621
1622
  }, {
1622
1623
  F: __dxlog_file9,
1623
- L: 235,
1624
+ L: 240,
1624
1625
  S: this,
1625
1626
  C: (f, a) => f(...a)
1626
1627
  });
@@ -1643,7 +1644,7 @@ var DataPipeline = class DataPipeline2 {
1643
1644
  spaceKey: this._params.spaceKey.toHex()
1644
1645
  }, {
1645
1646
  F: __dxlog_file9,
1646
- L: 252,
1647
+ L: 257,
1647
1648
  S: this,
1648
1649
  C: (f, a) => f(...a)
1649
1650
  });
@@ -1652,7 +1653,7 @@ var DataPipeline = class DataPipeline2 {
1652
1653
  } catch (err) {
1653
1654
  log8.catch(err, void 0, {
1654
1655
  F: __dxlog_file9,
1655
- L: 262,
1656
+ L: 267,
1656
1657
  S: this,
1657
1658
  C: (f, a) => f(...a)
1658
1659
  });
@@ -1667,7 +1668,7 @@ var DataPipeline = class DataPipeline2 {
1667
1668
  _createSnapshot() {
1668
1669
  invariant8(this.databaseHost, "Database backend is not initialized.", {
1669
1670
  F: __dxlog_file9,
1670
- L: 276,
1671
+ L: 281,
1671
1672
  S: this,
1672
1673
  A: [
1673
1674
  "this.databaseHost",
@@ -1696,7 +1697,7 @@ var DataPipeline = class DataPipeline2 {
1696
1697
  } catch (err) {
1697
1698
  log8.warn("Failed to cache properties", err, {
1698
1699
  F: __dxlog_file9,
1699
- L: 305,
1700
+ L: 310,
1700
1701
  S: this,
1701
1702
  C: (f, a) => f(...a)
1702
1703
  });
@@ -1725,14 +1726,14 @@ var DataPipeline = class DataPipeline2 {
1725
1726
  if (err instanceof CancelledError) {
1726
1727
  log8("Epoch processing cancelled.", void 0, {
1727
1728
  F: __dxlog_file9,
1728
- L: 341,
1729
+ L: 346,
1729
1730
  S: this,
1730
1731
  C: (f, a) => f(...a)
1731
1732
  });
1732
1733
  } else {
1733
1734
  log8.catch(err, void 0, {
1734
1735
  F: __dxlog_file9,
1735
- L: 343,
1736
+ L: 348,
1736
1737
  S: this,
1737
1738
  C: (f, a) => f(...a)
1738
1739
  });
@@ -1745,6 +1746,9 @@ var DataPipeline = class DataPipeline2 {
1745
1746
  return;
1746
1747
  }
1747
1748
  await this._processEpoch(ctx, epoch.subject.assertion);
1749
+ if (epoch.subject.assertion.snapshotCid === void 0) {
1750
+ epoch.subject.assertion.snapshotCid = this.appliedEpoch?.subject.assertion.snapshotCid;
1751
+ }
1748
1752
  this.appliedEpoch = epoch;
1749
1753
  this.onNewEpoch.emit(epoch);
1750
1754
  });
@@ -1752,7 +1756,7 @@ var DataPipeline = class DataPipeline2 {
1752
1756
  async _processEpoch(ctx, epoch) {
1753
1757
  invariant8(this._isOpen, "Space is closed.", {
1754
1758
  F: __dxlog_file9,
1755
- L: 362,
1759
+ L: 372,
1756
1760
  S: this,
1757
1761
  A: [
1758
1762
  "this._isOpen",
@@ -1761,7 +1765,7 @@ var DataPipeline = class DataPipeline2 {
1761
1765
  });
1762
1766
  invariant8(this._pipeline, void 0, {
1763
1767
  F: __dxlog_file9,
1764
- L: 363,
1768
+ L: 373,
1765
1769
  S: this,
1766
1770
  A: [
1767
1771
  "this._pipeline",
@@ -1773,7 +1777,7 @@ var DataPipeline = class DataPipeline2 {
1773
1777
  epoch: omit(epoch, "proof")
1774
1778
  }, {
1775
1779
  F: __dxlog_file9,
1776
- L: 366,
1780
+ L: 376,
1777
1781
  S: this,
1778
1782
  C: (f, a) => f(...a)
1779
1783
  });
@@ -1783,7 +1787,7 @@ var DataPipeline = class DataPipeline2 {
1783
1787
  }
1784
1788
  log8("restarting pipeline from epoch", void 0, {
1785
1789
  F: __dxlog_file9,
1786
- L: 372,
1790
+ L: 382,
1787
1791
  S: this,
1788
1792
  C: (f, a) => f(...a)
1789
1793
  });
@@ -1794,7 +1798,7 @@ var DataPipeline = class DataPipeline2 {
1794
1798
  async waitUntilTimeframe(timeframe) {
1795
1799
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1796
1800
  F: __dxlog_file9,
1797
- L: 379,
1801
+ L: 389,
1798
1802
  S: this,
1799
1803
  A: [
1800
1804
  "this._pipeline",
@@ -1806,7 +1810,7 @@ var DataPipeline = class DataPipeline2 {
1806
1810
  async createEpoch() {
1807
1811
  invariant8(this._pipeline, void 0, {
1808
1812
  F: __dxlog_file9,
1809
- L: 385,
1813
+ L: 395,
1810
1814
  S: this,
1811
1815
  A: [
1812
1816
  "this._pipeline",
@@ -1815,7 +1819,7 @@ var DataPipeline = class DataPipeline2 {
1815
1819
  });
1816
1820
  invariant8(this.currentEpoch, void 0, {
1817
1821
  F: __dxlog_file9,
1818
- L: 386,
1822
+ L: 396,
1819
1823
  S: this,
1820
1824
  A: [
1821
1825
  "this.currentEpoch",
@@ -1846,7 +1850,7 @@ var DataPipeline = class DataPipeline2 {
1846
1850
  } catch (err) {
1847
1851
  log8.catch(err, void 0, {
1848
1852
  F: __dxlog_file9,
1849
- L: 416,
1853
+ L: 426,
1850
1854
  S: this,
1851
1855
  C: (f, a) => f(...a)
1852
1856
  });
@@ -2724,6 +2728,167 @@ SpaceManager = _ts_decorate8([
2724
2728
  trackLeaks4("open", "close")
2725
2729
  ], SpaceManager);
2726
2730
 
2731
+ // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
2732
+ import { Repo, NetworkAdapter, StorageAdapter, cbor } from "@dxos/automerge/automerge-repo";
2733
+ import { Stream as Stream2 } from "@dxos/codec-protobuf";
2734
+ import { invariant as invariant10 } from "@dxos/invariant";
2735
+ import { arrayToBuffer as arrayToBuffer2, bufferToArray } from "@dxos/util";
2736
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
2737
+ var AutomergeHost = class {
2738
+ constructor(storageDirectory) {
2739
+ this._meshNetwork = new MeshNetworkAdapter();
2740
+ this._clientNetwork = new LocalHostNetworkAdapter();
2741
+ this._storage = new AutomergeStorageAdapter(storageDirectory);
2742
+ this._repo = new Repo({
2743
+ network: [
2744
+ // this._meshNetwork,
2745
+ this._clientNetwork
2746
+ ],
2747
+ storage: this._storage,
2748
+ // TODO(dmaretskyi): Share based on HALO permissions and space affinity.
2749
+ sharePolicy: async (peerId, documentId) => true
2750
+ });
2751
+ }
2752
+ get repo() {
2753
+ return this._repo;
2754
+ }
2755
+ syncRepo(request) {
2756
+ return this._clientNetwork.syncRepo(request);
2757
+ }
2758
+ sendSyncMessage(request) {
2759
+ return this._clientNetwork.sendSyncMessage(request);
2760
+ }
2761
+ };
2762
+ var LocalHostNetworkAdapter = class extends NetworkAdapter {
2763
+ constructor() {
2764
+ super();
2765
+ this._peers = /* @__PURE__ */ new Map();
2766
+ this.emit("ready", {
2767
+ network: this
2768
+ });
2769
+ }
2770
+ connect(peerId) {
2771
+ }
2772
+ send(message) {
2773
+ const peer = this._peers.get(message.targetId);
2774
+ invariant10(peer, "Peer not found.", {
2775
+ F: __dxlog_file14,
2776
+ L: 83,
2777
+ S: this,
2778
+ A: [
2779
+ "peer",
2780
+ "'Peer not found.'"
2781
+ ]
2782
+ });
2783
+ peer.send(message);
2784
+ }
2785
+ disconnect() {
2786
+ throw new Error("Method not implemented.");
2787
+ }
2788
+ syncRepo({ id, syncMessage }) {
2789
+ const peerId = this._getPeerId(id);
2790
+ return new Stream2(({ next, close }) => {
2791
+ invariant10(!this._peers.has(peerId), "Peer already connected.", {
2792
+ F: __dxlog_file14,
2793
+ L: 95,
2794
+ S: this,
2795
+ A: [
2796
+ "!this._peers.has(peerId)",
2797
+ "'Peer already connected.'"
2798
+ ]
2799
+ });
2800
+ this._peers.set(peerId, {
2801
+ connected: true,
2802
+ send: (message) => {
2803
+ next({
2804
+ syncMessage: cbor.encode(message)
2805
+ });
2806
+ },
2807
+ disconnect: () => {
2808
+ this._peers.delete(peerId);
2809
+ close();
2810
+ this.emit("peer-disconnected", {
2811
+ peerId
2812
+ });
2813
+ }
2814
+ });
2815
+ this.emit("peer-candidate", {
2816
+ peerId
2817
+ });
2818
+ });
2819
+ }
2820
+ async sendSyncMessage({ id, syncMessage }) {
2821
+ const message = cbor.decode(syncMessage);
2822
+ this.emit("message", message);
2823
+ }
2824
+ _getPeerId(id) {
2825
+ return id;
2826
+ }
2827
+ };
2828
+ var MeshNetworkAdapter = class extends NetworkAdapter {
2829
+ connect(peerId) {
2830
+ throw new Error("Method not implemented.");
2831
+ }
2832
+ send(message) {
2833
+ throw new Error("Method not implemented.");
2834
+ }
2835
+ disconnect() {
2836
+ throw new Error("Method not implemented.");
2837
+ }
2838
+ };
2839
+ var AutomergeStorageAdapter = class extends StorageAdapter {
2840
+ constructor(_directory) {
2841
+ super();
2842
+ this._directory = _directory;
2843
+ }
2844
+ async load(key) {
2845
+ const filename = this._getFilename(key);
2846
+ const file = this._directory.getOrCreateFile(filename);
2847
+ const { size } = await file.stat();
2848
+ const buffer = await file.read(0, size);
2849
+ return bufferToArray(buffer);
2850
+ }
2851
+ async save(key, data) {
2852
+ const filename = this._getFilename(key);
2853
+ const file = this._directory.getOrCreateFile(filename);
2854
+ await file.write(0, arrayToBuffer2(data));
2855
+ await file.truncate?.(data.length);
2856
+ await file.flush?.();
2857
+ }
2858
+ async remove(key) {
2859
+ const filename = this._getFilename(key);
2860
+ const file = this._directory.getOrCreateFile(filename);
2861
+ await file.truncate?.(0);
2862
+ }
2863
+ async loadRange(keyPrefix) {
2864
+ const filename = this._getFilename(keyPrefix);
2865
+ const entries = await this._directory.list();
2866
+ return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
2867
+ const file = this._directory.getOrCreateFile(entry);
2868
+ const { size } = await file.stat();
2869
+ const buffer = await file.read(0, size);
2870
+ return {
2871
+ key: this._getKeyFromFilename(entry),
2872
+ data: bufferToArray(buffer)
2873
+ };
2874
+ }));
2875
+ }
2876
+ async removeRange(keyPrefix) {
2877
+ const filename = this._getFilename(keyPrefix);
2878
+ const entries = await this._directory.list();
2879
+ await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
2880
+ const file = this._directory.getOrCreateFile(filename);
2881
+ await file.truncate?.(0);
2882
+ }));
2883
+ }
2884
+ _getFilename(key) {
2885
+ return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
2886
+ }
2887
+ _getKeyFromFilename(filename) {
2888
+ return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
2889
+ }
2890
+ };
2891
+
2727
2892
  export {
2728
2893
  codec,
2729
2894
  valueEncoding,
@@ -2748,6 +2913,7 @@ export {
2748
2913
  SpaceProtocol,
2749
2914
  AuthStatus,
2750
2915
  SpaceProtocolSession,
2751
- SpaceManager
2916
+ SpaceManager,
2917
+ AutomergeHost
2752
2918
  };
2753
- //# sourceMappingURL=chunk-HSZ2EJ74.mjs.map
2919
+ //# sourceMappingURL=chunk-CLHJJVQE.mjs.map