@dxos/echo-pipeline 0.1.58-main.e460f33 → 0.1.58-main.e4cedde

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.
@@ -32,11 +32,16 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  AuthExtension: () => AuthExtension,
34
34
  AuthStatus: () => AuthStatus,
35
+ DBError: () => DBError,
35
36
  DataPipeline: () => DataPipeline,
36
37
  DataServiceHost: () => DataServiceHost,
37
38
  DataServiceImpl: () => DataServiceImpl,
38
39
  DataServiceSubscriptions: () => DataServiceSubscriptions,
39
40
  DatabaseHost: () => DatabaseHost,
41
+ EntityNotFoundError: () => EntityNotFoundError,
42
+ IdentityNotInitializedError: () => IdentityNotInitializedError,
43
+ InvalidInvitationError: () => InvalidInvitationError,
44
+ InvalidStorageVersionError: () => InvalidStorageVersionError,
40
45
  MOCK_AUTH_PROVIDER: () => MOCK_AUTH_PROVIDER,
41
46
  MOCK_AUTH_VERIFIER: () => MOCK_AUTH_VERIFIER,
42
47
  MetadataStore: () => MetadataStore,
@@ -45,9 +50,11 @@ __export(src_exports, {
45
50
  SnapshotStore: () => SnapshotStore,
46
51
  Space: () => Space,
47
52
  SpaceManager: () => SpaceManager,
53
+ SpaceNotFoundError: () => SpaceNotFoundError,
48
54
  SpaceProtocol: () => SpaceProtocol,
49
55
  SpaceProtocolSession: () => SpaceProtocolSession,
50
56
  TimeframeClock: () => TimeframeClock,
57
+ UnknownModelError: () => UnknownModelError,
51
58
  codec: () => codec,
52
59
  createMappedFeedWriter: () => createMappedFeedWriter,
53
60
  mapFeedIndexesToTimeframe: () => mapFeedIndexesToTimeframe,
@@ -477,9 +484,59 @@ var DataServiceImpl = class {
477
484
  }
478
485
  };
479
486
 
487
+ // packages/core/echo/echo-pipeline/src/errors/errors.ts
488
+ var DBError = class extends Error {
489
+ constructor(code, message, context) {
490
+ super(message ? `${code}: ${message}` : code.toString());
491
+ this.code = code;
492
+ this.context = context;
493
+ Object.setPrototypeOf(this, new.target.prototype);
494
+ }
495
+ };
496
+ var IdentityNotInitializedError = class extends DBError {
497
+ constructor() {
498
+ super("IDENTITY_NOT_INITIALIZED", "Identity not initialized.");
499
+ }
500
+ };
501
+ var InvalidInvitationError = class extends DBError {
502
+ constructor() {
503
+ super("INVALID_INVITATION", "Invitation is invalid.");
504
+ }
505
+ };
506
+ var InvalidStorageVersionError = class extends DBError {
507
+ constructor(expected, actual) {
508
+ super("INVALID_STORAGE_VERSION", "Invalid storage version.", {
509
+ expected,
510
+ actual
511
+ });
512
+ }
513
+ };
514
+ var SpaceNotFoundError = class extends DBError {
515
+ constructor(spaceKey) {
516
+ super("SPACE_NOT_FOUND", "Space not found.", {
517
+ spaceKey
518
+ });
519
+ }
520
+ };
521
+ var EntityNotFoundError = class extends DBError {
522
+ constructor(entityId) {
523
+ super("ITEM_NOT_FOUND", "Item not found.", {
524
+ entityId
525
+ });
526
+ }
527
+ };
528
+ var UnknownModelError = class extends DBError {
529
+ constructor(model) {
530
+ super("UNKNOWN_MODEL", "Unknown model.", {
531
+ model
532
+ });
533
+ }
534
+ };
535
+
480
536
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
481
537
  var import_crc_32 = __toESM(require("crc-32"));
482
538
  var import_async2 = require("@dxos/async");
539
+ var import_errors = require("@dxos/errors");
483
540
  var import_invariant4 = require("@dxos/invariant");
484
541
  var import_keys3 = require("@dxos/keys");
485
542
  var import_log3 = require("@dxos/log");
@@ -542,12 +599,12 @@ var MetadataStore = class {
542
599
  name: file.filename
543
600
  }, {
544
601
  F: __dxlog_file4,
545
- L: 81,
602
+ L: 82,
546
603
  S: this,
547
604
  C: (f, a) => f(...a)
548
605
  });
549
606
  if (fileLength < dataSize + 8) {
550
- throw new import_protocols4.DataCorruptionError("Metadata size is smaller than expected.", {
607
+ throw new import_errors.DataCorruptionError("Metadata size is smaller than expected.", {
551
608
  fileLength,
552
609
  dataSize
553
610
  });
@@ -555,7 +612,7 @@ var MetadataStore = class {
555
612
  const data = await file.read(8, dataSize);
556
613
  const calculatedChecksum = import_crc_32.default.buf(data);
557
614
  if (calculatedChecksum !== checksum) {
558
- throw new import_protocols4.DataCorruptionError("Metadata checksum is invalid.");
615
+ throw new import_errors.DataCorruptionError("Metadata checksum is invalid.");
559
616
  }
560
617
  return codec2.decode(data);
561
618
  } finally {
@@ -575,7 +632,7 @@ var MetadataStore = class {
575
632
  checksum
576
633
  }, {
577
634
  F: __dxlog_file4,
578
- L: 113,
635
+ L: 114,
579
636
  S: this,
580
637
  C: (f, a) => f(...a)
581
638
  });
@@ -607,7 +664,7 @@ var MetadataStore = class {
607
664
  err
608
665
  }, {
609
666
  F: __dxlog_file4,
610
- L: 144,
667
+ L: 145,
611
668
  S: this,
612
669
  C: (f, a) => f(...a)
613
670
  });
@@ -624,7 +681,7 @@ var MetadataStore = class {
624
681
  err
625
682
  }, {
626
683
  F: __dxlog_file4,
627
- L: 156,
684
+ L: 157,
628
685
  S: this,
629
686
  C: (f, a) => f(...a)
630
687
  });
@@ -654,7 +711,7 @@ var MetadataStore = class {
654
711
  err
655
712
  }, {
656
713
  F: __dxlog_file4,
657
- L: 185,
714
+ L: 186,
658
715
  S: this,
659
716
  C: (f, a) => f(...a)
660
717
  });
@@ -675,7 +732,7 @@ var MetadataStore = class {
675
732
  const space = this.spaces.find((space2) => space2.key === spaceKey);
676
733
  (0, import_invariant4.invariant)(space, "Space not found", {
677
734
  F: __dxlog_file4,
678
- L: 207,
735
+ L: 208,
679
736
  S: this,
680
737
  A: [
681
738
  "space",
@@ -699,7 +756,7 @@ var MetadataStore = class {
699
756
  async clear() {
700
757
  (0, import_log3.log)("clearing all metadata", void 0, {
701
758
  F: __dxlog_file4,
702
- L: 226,
759
+ L: 227,
703
760
  S: this,
704
761
  C: (f, a) => f(...a)
705
762
  });
@@ -712,7 +769,7 @@ var MetadataStore = class {
712
769
  async setIdentityRecord(record) {
713
770
  (0, import_invariant4.invariant)(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
714
771
  F: __dxlog_file4,
715
- L: 236,
772
+ L: 237,
716
773
  S: this,
717
774
  A: [
718
775
  "!this._metadata.identity",
@@ -726,7 +783,7 @@ var MetadataStore = class {
726
783
  async addSpace(record) {
727
784
  (0, import_invariant4.invariant)(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
728
785
  F: __dxlog_file4,
729
- L: 244,
786
+ L: 245,
730
787
  S: this,
731
788
  A: [
732
789
  "!(this._metadata.spaces ?? []).find((space) => space.key === record.key)",
@@ -1714,9 +1771,9 @@ var import_async7 = require("@dxos/async");
1714
1771
  var import_context6 = require("@dxos/context");
1715
1772
  var import_credentials3 = require("@dxos/credentials");
1716
1773
  var import_echo_db3 = require("@dxos/echo-db");
1774
+ var import_errors2 = require("@dxos/errors");
1717
1775
  var import_invariant8 = require("@dxos/invariant");
1718
1776
  var import_log9 = require("@dxos/log");
1719
- var import_protocols6 = require("@dxos/protocols");
1720
1777
  var import_timeframe4 = require("@dxos/timeframe");
1721
1778
  var import_tracing2 = require("@dxos/tracing");
1722
1779
  var import_util6 = require("@dxos/util");
@@ -1788,7 +1845,7 @@ var DataPipeline = class DataPipeline2 {
1788
1845
  write: (data, options) => {
1789
1846
  (0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
1790
1847
  F: __dxlog_file10,
1791
- L: 153,
1848
+ L: 154,
1792
1849
  S: this,
1793
1850
  A: [
1794
1851
  "this._pipeline",
@@ -1797,7 +1854,7 @@ var DataPipeline = class DataPipeline2 {
1797
1854
  });
1798
1855
  (0, import_invariant8.invariant)(this.currentEpoch, "Epoch is not initialized.", {
1799
1856
  F: __dxlog_file10,
1800
- L: 154,
1857
+ L: 155,
1801
1858
  S: this,
1802
1859
  A: [
1803
1860
  "this.currentEpoch",
@@ -1823,7 +1880,7 @@ var DataPipeline = class DataPipeline2 {
1823
1880
  }
1824
1881
  (0, import_log9.log)("close", void 0, {
1825
1882
  F: __dxlog_file10,
1826
- L: 178,
1883
+ L: 179,
1827
1884
  S: this,
1828
1885
  C: (f, a) => f(...a)
1829
1886
  });
@@ -1838,7 +1895,7 @@ var DataPipeline = class DataPipeline2 {
1838
1895
  } catch (err) {
1839
1896
  import_log9.log.catch(err, void 0, {
1840
1897
  F: __dxlog_file10,
1841
- L: 191,
1898
+ L: 192,
1842
1899
  S: this,
1843
1900
  C: (f, a) => f(...a)
1844
1901
  });
@@ -1863,7 +1920,7 @@ var DataPipeline = class DataPipeline2 {
1863
1920
  let messageCounter = 0;
1864
1921
  (0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
1865
1922
  F: __dxlog_file10,
1866
- L: 216,
1923
+ L: 217,
1867
1924
  S: this,
1868
1925
  A: [
1869
1926
  "this._pipeline",
@@ -1879,7 +1936,7 @@ var DataPipeline = class DataPipeline2 {
1879
1936
  seq
1880
1937
  }, {
1881
1938
  F: __dxlog_file10,
1882
- L: 222,
1939
+ L: 223,
1883
1940
  S: this,
1884
1941
  C: (f, a) => f(...a)
1885
1942
  });
@@ -1891,7 +1948,7 @@ var DataPipeline = class DataPipeline2 {
1891
1948
  feedKey
1892
1949
  }, {
1893
1950
  F: __dxlog_file10,
1894
- L: 228,
1951
+ L: 229,
1895
1952
  S: this,
1896
1953
  C: (f, a) => f(...a)
1897
1954
  });
@@ -1914,7 +1971,7 @@ var DataPipeline = class DataPipeline2 {
1914
1971
  spaceKey: this._params.spaceKey.toHex()
1915
1972
  }, {
1916
1973
  F: __dxlog_file10,
1917
- L: 245,
1974
+ L: 246,
1918
1975
  S: this,
1919
1976
  C: (f, a) => f(...a)
1920
1977
  });
@@ -1923,7 +1980,7 @@ var DataPipeline = class DataPipeline2 {
1923
1980
  } catch (err) {
1924
1981
  import_log9.log.catch(err, void 0, {
1925
1982
  F: __dxlog_file10,
1926
- L: 255,
1983
+ L: 256,
1927
1984
  S: this,
1928
1985
  C: (f, a) => f(...a)
1929
1986
  });
@@ -1938,7 +1995,7 @@ var DataPipeline = class DataPipeline2 {
1938
1995
  _createSnapshot() {
1939
1996
  (0, import_invariant8.invariant)(this.databaseHost, "Database backend is not initialized.", {
1940
1997
  F: __dxlog_file10,
1941
- L: 269,
1998
+ L: 270,
1942
1999
  S: this,
1943
2000
  A: [
1944
2001
  "this.databaseHost",
@@ -1967,7 +2024,7 @@ var DataPipeline = class DataPipeline2 {
1967
2024
  } catch (err) {
1968
2025
  import_log9.log.warn("Failed to cache properties", err, {
1969
2026
  F: __dxlog_file10,
1970
- L: 298,
2027
+ L: 299,
1971
2028
  S: this,
1972
2029
  C: (f, a) => f(...a)
1973
2030
  });
@@ -1993,17 +2050,17 @@ var DataPipeline = class DataPipeline2 {
1993
2050
  await this._epochCtx?.dispose();
1994
2051
  const ctx = new import_context6.Context({
1995
2052
  onError: (err) => {
1996
- if (err instanceof import_protocols6.CancelledError) {
2053
+ if (err instanceof import_errors2.CancelledError) {
1997
2054
  (0, import_log9.log)("Epoch processing cancelled.", void 0, {
1998
2055
  F: __dxlog_file10,
1999
- L: 334,
2056
+ L: 335,
2000
2057
  S: this,
2001
2058
  C: (f, a) => f(...a)
2002
2059
  });
2003
2060
  } else {
2004
2061
  import_log9.log.catch(err, void 0, {
2005
2062
  F: __dxlog_file10,
2006
- L: 336,
2063
+ L: 337,
2007
2064
  S: this,
2008
2065
  C: (f, a) => f(...a)
2009
2066
  });
@@ -2023,7 +2080,7 @@ var DataPipeline = class DataPipeline2 {
2023
2080
  async _processEpoch(ctx, epoch) {
2024
2081
  (0, import_invariant8.invariant)(this._isOpen, "Space is closed.", {
2025
2082
  F: __dxlog_file10,
2026
- L: 355,
2083
+ L: 356,
2027
2084
  S: this,
2028
2085
  A: [
2029
2086
  "this._isOpen",
@@ -2032,7 +2089,7 @@ var DataPipeline = class DataPipeline2 {
2032
2089
  });
2033
2090
  (0, import_invariant8.invariant)(this._pipeline, void 0, {
2034
2091
  F: __dxlog_file10,
2035
- L: 356,
2092
+ L: 357,
2036
2093
  S: this,
2037
2094
  A: [
2038
2095
  "this._pipeline",
@@ -2044,7 +2101,7 @@ var DataPipeline = class DataPipeline2 {
2044
2101
  epoch: (0, import_log9.omit)(epoch, "proof")
2045
2102
  }, {
2046
2103
  F: __dxlog_file10,
2047
- L: 359,
2104
+ L: 360,
2048
2105
  S: this,
2049
2106
  C: (f, a) => f(...a)
2050
2107
  });
@@ -2054,7 +2111,7 @@ var DataPipeline = class DataPipeline2 {
2054
2111
  }
2055
2112
  (0, import_log9.log)("restarting pipeline from epoch", void 0, {
2056
2113
  F: __dxlog_file10,
2057
- L: 365,
2114
+ L: 366,
2058
2115
  S: this,
2059
2116
  C: (f, a) => f(...a)
2060
2117
  });
@@ -2065,7 +2122,7 @@ var DataPipeline = class DataPipeline2 {
2065
2122
  async waitUntilTimeframe(timeframe) {
2066
2123
  (0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
2067
2124
  F: __dxlog_file10,
2068
- L: 372,
2125
+ L: 373,
2069
2126
  S: this,
2070
2127
  A: [
2071
2128
  "this._pipeline",
@@ -2077,7 +2134,7 @@ var DataPipeline = class DataPipeline2 {
2077
2134
  async createEpoch() {
2078
2135
  (0, import_invariant8.invariant)(this._pipeline, void 0, {
2079
2136
  F: __dxlog_file10,
2080
- L: 378,
2137
+ L: 379,
2081
2138
  S: this,
2082
2139
  A: [
2083
2140
  "this._pipeline",
@@ -2086,7 +2143,7 @@ var DataPipeline = class DataPipeline2 {
2086
2143
  });
2087
2144
  (0, import_invariant8.invariant)(this.currentEpoch, void 0, {
2088
2145
  F: __dxlog_file10,
2089
- L: 379,
2146
+ L: 380,
2090
2147
  S: this,
2091
2148
  A: [
2092
2149
  "this.currentEpoch",
@@ -2117,7 +2174,7 @@ var DataPipeline = class DataPipeline2 {
2117
2174
  } catch (err) {
2118
2175
  import_log9.log.catch(err, void 0, {
2119
2176
  F: __dxlog_file10,
2120
- L: 409,
2177
+ L: 410,
2121
2178
  S: this,
2122
2179
  C: (f, a) => f(...a)
2123
2180
  });
@@ -2402,7 +2459,7 @@ var import_async9 = require("@dxos/async");
2402
2459
  var import_debug4 = require("@dxos/debug");
2403
2460
  var import_keys7 = require("@dxos/keys");
2404
2461
  var import_log12 = require("@dxos/log");
2405
- var import_protocols7 = require("@dxos/protocols");
2462
+ var import_protocols6 = require("@dxos/protocols");
2406
2463
  var import_util9 = require("@dxos/util");
2407
2464
 
2408
2465
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
@@ -2646,7 +2703,7 @@ var SpaceManager = class SpaceManager2 {
2646
2703
  ].map((space) => space.close()));
2647
2704
  }
2648
2705
  async constructSpace({ metadata, swarmIdentity, onNetworkConnection, onAuthFailure, memberKey }) {
2649
- import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols7.trace.begin({
2706
+ import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols6.trace.begin({
2650
2707
  id: this._instanceId
2651
2708
  }), {
2652
2709
  F: __dxlog_file13,
@@ -2684,7 +2741,7 @@ var SpaceManager = class SpaceManager2 {
2684
2741
  memberKey
2685
2742
  });
2686
2743
  this._spaces.set(space.key, space);
2687
- import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols7.trace.end({
2744
+ import_log12.log.trace("dxos.echo.space-manager.construct-space", import_protocols6.trace.end({
2688
2745
  id: this._instanceId
2689
2746
  }), {
2690
2747
  F: __dxlog_file13,
@@ -2708,11 +2765,16 @@ SpaceManager = _ts_decorate9([
2708
2765
  0 && (module.exports = {
2709
2766
  AuthExtension,
2710
2767
  AuthStatus,
2768
+ DBError,
2711
2769
  DataPipeline,
2712
2770
  DataServiceHost,
2713
2771
  DataServiceImpl,
2714
2772
  DataServiceSubscriptions,
2715
2773
  DatabaseHost,
2774
+ EntityNotFoundError,
2775
+ IdentityNotInitializedError,
2776
+ InvalidInvitationError,
2777
+ InvalidStorageVersionError,
2716
2778
  MOCK_AUTH_PROVIDER,
2717
2779
  MOCK_AUTH_VERIFIER,
2718
2780
  MetadataStore,
@@ -2721,9 +2783,11 @@ SpaceManager = _ts_decorate9([
2721
2783
  SnapshotStore,
2722
2784
  Space,
2723
2785
  SpaceManager,
2786
+ SpaceNotFoundError,
2724
2787
  SpaceProtocol,
2725
2788
  SpaceProtocolSession,
2726
2789
  TimeframeClock,
2790
+ UnknownModelError,
2727
2791
  codec,
2728
2792
  createMappedFeedWriter,
2729
2793
  mapFeedIndexesToTimeframe,