@dxos/echo-pipeline 0.1.53-main.b6f5d87 → 0.1.53-main.ceb8ff5

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,8 +1,8 @@
1
- import "@dxos/node-std/globals"
1
+ import "@dxos/node-std/globals";
2
2
 
3
3
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
4
4
  import CRC32 from "crc-32";
5
- import assert from "@dxos/node-std/assert";
5
+ import invariant from "tiny-invariant";
6
6
  import { synchronized, Event } from "@dxos/async";
7
7
  import { DataCorruptionError } from "@dxos/errors";
8
8
  import { log } from "@dxos/log";
@@ -127,7 +127,7 @@ var MetadataStore = class {
127
127
  return this._metadata.identity.haloSpace;
128
128
  }
129
129
  const space = this.spaces.find((space2) => space2.key === spaceKey);
130
- assert(space, "Space not found");
130
+ invariant(space, "Space not found");
131
131
  return space;
132
132
  }
133
133
  /**
@@ -147,13 +147,13 @@ var MetadataStore = class {
147
147
  return this._metadata.identity;
148
148
  }
149
149
  async setIdentityRecord(record) {
150
- assert(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
150
+ invariant(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
151
151
  this._metadata.identity = record;
152
152
  await this._save();
153
153
  }
154
154
  async addSpace(record) {
155
155
  var _a, _b, _c;
156
- assert(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
156
+ invariant(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
157
157
  ((_c = (_b = this._metadata).spaces) != null ? _c : _b.spaces = []).push(record);
158
158
  await this._save();
159
159
  }
@@ -191,10 +191,10 @@ var codec = schema2.getCodecForType("dxos.echo.feed.FeedMessage");
191
191
  var valueEncoding = createCodecEncoding(codec);
192
192
 
193
193
  // packages/core/echo/echo-pipeline/src/common/feeds.ts
194
- import assert2 from "@dxos/node-std/assert";
194
+ import invariant2 from "tiny-invariant";
195
195
  var createMappedFeedWriter = (mapper, writer) => {
196
- assert2(mapper);
197
- assert2(writer);
196
+ invariant2(mapper);
197
+ invariant2(writer);
198
198
  return {
199
199
  write: async (data, options) => await writer.write(await mapper(data), options)
200
200
  };
@@ -298,7 +298,7 @@ __decorate2([
298
298
  ], TimeframeClock.prototype, "waitUntilReached", null);
299
299
 
300
300
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
301
- import assert4 from "@dxos/node-std/assert";
301
+ import invariant4 from "tiny-invariant";
302
302
  import { Event as Event3, sleep, synchronized as synchronized2, Trigger } from "@dxos/async";
303
303
  import { Context, rejectOnDispose } from "@dxos/context";
304
304
  import { failUndefined } from "@dxos/debug";
@@ -309,19 +309,23 @@ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
309
309
  import { ComplexMap } from "@dxos/util";
310
310
 
311
311
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
312
- import debug from "debug";
313
- import assert3 from "@dxos/node-std/assert";
314
- var log3 = debug("dxos:echo-db:message-selector");
312
+ import invariant3 from "tiny-invariant";
313
+ import { log as log3 } from "@dxos/log";
315
314
  var createMessageSelector = (timeframeClock) => {
316
315
  return (messages) => {
317
316
  for (let i = 0; i < messages.length; i++) {
318
317
  const { data: { timeframe } } = messages[i];
319
- assert3(timeframe);
318
+ invariant3(timeframe);
320
319
  if (!timeframeClock.hasGaps(timeframe)) {
321
320
  return i;
322
321
  }
323
322
  }
324
- log3("Skipping...");
323
+ log3("Skipping...", {}, {
324
+ file: "message-selector.ts",
325
+ line: 34,
326
+ scope: void 0,
327
+ callSite: (f, a) => f(...a)
328
+ });
325
329
  };
326
330
  };
327
331
 
@@ -451,7 +455,7 @@ var Pipeline = class {
451
455
  return this._state;
452
456
  }
453
457
  get writer() {
454
- assert4(this._writer, "Writer not set.");
458
+ invariant4(this._writer, "Writer not set.");
455
459
  return this._writer;
456
460
  }
457
461
  getFeeds() {
@@ -470,8 +474,8 @@ var Pipeline = class {
470
474
  return this._feeds.has(feedKey);
471
475
  }
472
476
  setWriteFeed(feed) {
473
- assert4(!this._writer, "Writer already set.");
474
- assert4(feed.properties.writable, "Feed must be writable.");
477
+ invariant4(!this._writer, "Writer already set.");
478
+ invariant4(feed.properties.writable, "Feed must be writable.");
475
479
  this._writer = createMappedFeedWriter((payload) => ({
476
480
  timeframe: this._timeframeClock.timeframe,
477
481
  payload
@@ -517,7 +521,7 @@ var Pipeline = class {
517
521
  * @param timeframe Timeframe of already processed messages. The pipeline will start processing messages AFTER this timeframe.
518
522
  */
519
523
  async setCursor(timeframe) {
520
- assert4(!this._isStarted || this._isPaused, "Invalid state.");
524
+ invariant4(!this._isStarted || this._isPaused, "Invalid state.");
521
525
  this._state._startTimeframe = timeframe;
522
526
  this._timeframeClock.setTimeframe(timeframe);
523
527
  for (const feed of this._feeds.values()) {
@@ -533,7 +537,7 @@ var Pipeline = class {
533
537
  * Calling pause while processing will cause a deadlock.
534
538
  */
535
539
  async pause() {
536
- assert4(this._isStarted, "Pipeline is not open.");
540
+ invariant4(this._isStarted, "Pipeline is not open.");
537
541
  if (this._isPaused) {
538
542
  return;
539
543
  }
@@ -542,8 +546,8 @@ var Pipeline = class {
542
546
  this._isPaused = true;
543
547
  }
544
548
  async unpause() {
545
- assert4(this._isStarted, "Pipeline is not open.");
546
- assert4(this._isPaused, "Pipeline is not paused.");
549
+ invariant4(this._isStarted, "Pipeline is not open.");
550
+ invariant4(this._isPaused, "Pipeline is not paused.");
547
551
  this._pauseTrigger.wake();
548
552
  this._isPaused = false;
549
553
  }
@@ -552,15 +556,15 @@ var Pipeline = class {
552
556
  * Updates the timeframe clock after the message has bee processed.
553
557
  */
554
558
  async *consume() {
555
- assert4(!this._isOpen, "Pipeline is already being consumed.");
559
+ invariant4(!this._isOpen, "Pipeline is already being consumed.");
556
560
  this._isOpen = true;
557
- assert4(this._feedSetIterator, "Iterator not initialized.");
561
+ invariant4(this._feedSetIterator, "Iterator not initialized.");
558
562
  let lastFeedSetIterator = this._feedSetIterator;
559
563
  let iterable = lastFeedSetIterator[Symbol.asyncIterator]();
560
564
  while (!this._isStopping) {
561
565
  await this._pauseTrigger.wait();
562
566
  if (lastFeedSetIterator !== this._feedSetIterator) {
563
- assert4(this._feedSetIterator, "Iterator not initialized.");
567
+ invariant4(this._feedSetIterator, "Iterator not initialized.");
564
568
  lastFeedSetIterator = this._feedSetIterator;
565
569
  iterable = lastFeedSetIterator[Symbol.asyncIterator]();
566
570
  }
@@ -639,7 +643,7 @@ __decorate3([
639
643
  ], Pipeline.prototype, "unpause", null);
640
644
 
641
645
  // packages/core/echo/echo-pipeline/src/space/auth.ts
642
- import assert5 from "@dxos/node-std/assert";
646
+ import invariant5 from "tiny-invariant";
643
647
  import { runInContext, scheduleTask } from "@dxos/async";
644
648
  import { Context as Context2 } from "@dxos/context";
645
649
  import { randomBytes } from "@dxos/crypto";
@@ -702,9 +706,9 @@ var AuthExtension = class extends RpcExtension {
702
706
  const { credential } = await this.rpc.AuthService.authenticate({
703
707
  challenge
704
708
  });
705
- assert5((credential == null ? void 0 : credential.length) > 0, "invalid credential");
709
+ invariant5((credential == null ? void 0 : credential.length) > 0, "invalid credential");
706
710
  const success = await this._authParams.verifier(challenge, credential);
707
- assert5(success, "credential not verified");
711
+ invariant5(success, "credential not verified");
708
712
  runInContext(this._ctx, () => this._authParams.onAuthSuccess());
709
713
  } catch (err) {
710
714
  log5("auth failed", err, {
@@ -725,7 +729,7 @@ var AuthExtension = class extends RpcExtension {
725
729
  };
726
730
 
727
731
  // packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts
728
- import assert6 from "@dxos/node-std/assert";
732
+ import invariant6 from "tiny-invariant";
729
733
  import { Stream } from "@dxos/codec-protobuf";
730
734
  import { tagMutationsInBatch, setMetadataOnObject } from "@dxos/echo-db";
731
735
  import { log as log6 } from "@dxos/log";
@@ -751,7 +755,7 @@ var DataServiceHost = class {
751
755
  this._itemDemuxer.mutation.on(ctx, (message) => {
752
756
  var _a;
753
757
  const { batch, meta } = message;
754
- assert6(!meta.clientTag, "Unexpected client tag in mutation message");
758
+ invariant6(!meta.clientTag, "Unexpected client tag in mutation message");
755
759
  log6("message", {
756
760
  batch,
757
761
  meta
@@ -784,7 +788,7 @@ var DataServiceHost = class {
784
788
  }
785
789
  async write(request) {
786
790
  var _a, _b;
787
- assert6(this._writeStream, "Cannot write mutations in readonly mode");
791
+ invariant6(this._writeStream, "Cannot write mutations in readonly mode");
788
792
  log6("write", {
789
793
  clientTag: request.clientTag,
790
794
  objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
@@ -969,7 +973,7 @@ var SnapshotStore = class {
969
973
  };
970
974
 
971
975
  // packages/core/echo/echo-pipeline/src/dbhost/data-service.ts
972
- import assert7 from "@dxos/node-std/assert";
976
+ import invariant7 from "tiny-invariant";
973
977
  import { raise } from "@dxos/debug";
974
978
  import { PublicKey as PublicKey3 } from "@dxos/keys";
975
979
  import { log as log7 } from "@dxos/log";
@@ -1013,21 +1017,21 @@ var DataServiceImpl = class {
1013
1017
  }
1014
1018
  subscribe(request) {
1015
1019
  var _a;
1016
- assert7(request.spaceKey);
1020
+ invariant7(request.spaceKey);
1017
1021
  const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
1018
1022
  return host.subscribe();
1019
1023
  }
1020
1024
  write(request) {
1021
1025
  var _a;
1022
- assert7(request.spaceKey);
1023
- assert7(request.batch);
1026
+ invariant7(request.spaceKey);
1027
+ invariant7(request.batch);
1024
1028
  const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
1025
1029
  return host.write(request);
1026
1030
  }
1027
1031
  };
1028
1032
 
1029
1033
  // packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
1030
- import assert8 from "@dxos/node-std/assert";
1034
+ import invariant8 from "tiny-invariant";
1031
1035
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1032
1036
  import { Context as Context3 } from "@dxos/context";
1033
1037
  import { checkCredentialType } from "@dxos/credentials";
@@ -1100,8 +1104,8 @@ var DataPipeline = class DataPipeline2 {
1100
1104
  }
1101
1105
  const feedWriter = {
1102
1106
  write: (data, options) => {
1103
- assert8(this._pipeline, "Pipeline is not initialized.");
1104
- assert8(this.currentEpoch, "Epoch is not initialized.");
1107
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1108
+ invariant8(this.currentEpoch, "Epoch is not initialized.");
1105
1109
  return this._pipeline.writer.write({
1106
1110
  data
1107
1111
  }, options);
@@ -1151,7 +1155,7 @@ var DataPipeline = class DataPipeline2 {
1151
1155
  await this._processEpochInSeparateTask(this.currentEpoch);
1152
1156
  await waitForOneEpoch;
1153
1157
  }
1154
- assert8(this._pipeline, "Pipeline is not initialized.");
1158
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1155
1159
  for await (const msg of this._pipeline.consume()) {
1156
1160
  const { feedKey, seq, data } = msg;
1157
1161
  log8("processing message", {
@@ -1209,7 +1213,7 @@ var DataPipeline = class DataPipeline2 {
1209
1213
  }
1210
1214
  }
1211
1215
  _createSnapshot() {
1212
- assert8(this.databaseHost, "Database backend is not initialized.");
1216
+ invariant8(this.databaseHost, "Database backend is not initialized.");
1213
1217
  return {
1214
1218
  spaceKey: this._params.spaceKey.asUint8Array(),
1215
1219
  timeframe: this._pipeline.state.timeframe,
@@ -1297,8 +1301,8 @@ var DataPipeline = class DataPipeline2 {
1297
1301
  });
1298
1302
  }
1299
1303
  async _processEpoch(ctx, epoch) {
1300
- assert8(this._isOpen, "Space is closed.");
1301
- assert8(this._pipeline);
1304
+ invariant8(this._isOpen, "Space is closed.");
1305
+ invariant8(this._pipeline);
1302
1306
  this._lastProcessedEpoch = epoch.number;
1303
1307
  log8("Processing epoch", {
1304
1308
  epoch
@@ -1323,12 +1327,12 @@ var DataPipeline = class DataPipeline2 {
1323
1327
  await this._pipeline.unpause();
1324
1328
  }
1325
1329
  async waitUntilTimeframe(timeframe) {
1326
- assert8(this._pipeline, "Pipeline is not initialized.");
1330
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1327
1331
  await this._pipeline.state.waitUntilTimeframe(timeframe);
1328
1332
  }
1329
1333
  async createEpoch() {
1330
- assert8(this._pipeline);
1331
- assert8(this.currentEpoch);
1334
+ invariant8(this._pipeline);
1335
+ invariant8(this.currentEpoch);
1332
1336
  await this._pipeline.pause();
1333
1337
  const snapshot = await this._createSnapshot();
1334
1338
  const snapshotCid = await this._params.snapshotManager.store(snapshot);
@@ -1362,7 +1366,7 @@ DataPipeline = __decorate5([
1362
1366
  ], DataPipeline);
1363
1367
 
1364
1368
  // packages/core/echo/echo-pipeline/src/space/space.ts
1365
- import assert9 from "@dxos/node-std/assert";
1369
+ import invariant9 from "tiny-invariant";
1366
1370
  import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeaks3, Lock } from "@dxos/async";
1367
1371
  import { log as log10, logInfo } from "@dxos/log";
1368
1372
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
@@ -1531,7 +1535,7 @@ var Space = class Space2 {
1531
1535
  // Processes epoch credentials.
1532
1536
  this._dataPipelineCredentialConsumer = void 0;
1533
1537
  this._isOpen = false;
1534
- assert9(params.spaceKey && params.feedProvider);
1538
+ invariant9(params.spaceKey && params.feedProvider);
1535
1539
  this._key = params.spaceKey;
1536
1540
  this._genesisFeedKey = params.genesisFeed.key;
1537
1541
  this._feedProvider = params.feedProvider;
@@ -1632,14 +1636,14 @@ var Space = class Space2 {
1632
1636
  return this._snapshotManager;
1633
1637
  }
1634
1638
  setControlFeed(feed) {
1635
- assert9(!this._controlFeed, "Control feed already set.");
1639
+ invariant9(!this._controlFeed, "Control feed already set.");
1636
1640
  this._controlFeed = feed;
1637
1641
  this._controlPipeline.setWriteFeed(feed);
1638
1642
  return this;
1639
1643
  }
1640
1644
  setDataFeed(feed) {
1641
1645
  var _a;
1642
- assert9(!this._dataFeed, "Data feed already set.");
1646
+ invariant9(!this._dataFeed, "Data feed already set.");
1643
1647
  this._dataFeed = feed;
1644
1648
  (_a = this._dataPipeline.pipeline) == null ? void 0 : _a.setWriteFeed(feed);
1645
1649
  return this;
@@ -1711,7 +1715,7 @@ var Space = class Space2 {
1711
1715
  scope: this,
1712
1716
  callSite: (f, a) => f(...a)
1713
1717
  });
1714
- assert9(this._isOpen, "Space must be open to initialize data pipeline.");
1718
+ invariant9(this._isOpen, "Space must be open to initialize data pipeline.");
1715
1719
  await this._dataPipeline.open();
1716
1720
  }
1717
1721
  };
@@ -1732,7 +1736,7 @@ Space = __decorate6([
1732
1736
  ], Space);
1733
1737
 
1734
1738
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
1735
- import { discoveryKey, sha256 } from "@dxos/crypto";
1739
+ import { discoveryKey, subtleCrypto as subtleCrypto2 } from "@dxos/crypto";
1736
1740
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1737
1741
  import { log as log11, logInfo as logInfo2 } from "@dxos/log";
1738
1742
  import { MMSTTopology } from "@dxos/network-manager";
@@ -1763,7 +1767,7 @@ var SpaceProtocol = class {
1763
1767
  this.blobSync = new BlobSync({
1764
1768
  blobStore
1765
1769
  });
1766
- this._topic = PublicKey5.from(discoveryKey(sha256(topic.toHex())));
1770
+ this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey5.from);
1767
1771
  }
1768
1772
  get sessions() {
1769
1773
  return this._sessions;
@@ -1780,7 +1784,7 @@ var SpaceProtocol = class {
1780
1784
  key: feed.key
1781
1785
  }, {
1782
1786
  file: "space-protocol.ts",
1783
- line: 94,
1787
+ line: 96,
1784
1788
  scope: this,
1785
1789
  callSite: (f, a) => f(...a)
1786
1790
  });
@@ -1802,20 +1806,20 @@ var SpaceProtocol = class {
1802
1806
  await this.blobSync.open();
1803
1807
  log11("starting...", {}, {
1804
1808
  file: "space-protocol.ts",
1805
- line: 119,
1809
+ line: 121,
1806
1810
  scope: this,
1807
1811
  callSite: (f, a) => f(...a)
1808
1812
  });
1809
1813
  this._connection = await this._networkManager.joinSwarm({
1810
1814
  protocolProvider: this._createProtocolProvider(credentials),
1811
1815
  peerId: this._swarmIdentity.peerKey,
1812
- topic: this._topic,
1816
+ topic: await this._topic,
1813
1817
  topology: new MMSTTopology(topologyConfig),
1814
1818
  label: `Protocol swarm: ${this._topic}`
1815
1819
  });
1816
1820
  log11("started", {}, {
1817
1821
  file: "space-protocol.ts",
1818
- line: 128,
1822
+ line: 130,
1819
1823
  scope: this,
1820
1824
  callSite: (f, a) => f(...a)
1821
1825
  });
@@ -1825,14 +1829,14 @@ var SpaceProtocol = class {
1825
1829
  if (this._connection) {
1826
1830
  log11("stopping...", {}, {
1827
1831
  file: "space-protocol.ts",
1828
- line: 135,
1832
+ line: 137,
1829
1833
  scope: this,
1830
1834
  callSite: (f, a) => f(...a)
1831
1835
  });
1832
1836
  await this._connection.close();
1833
1837
  log11("stopped", {}, {
1834
1838
  file: "space-protocol.ts",
1835
- line: 137,
1839
+ line: 139,
1836
1840
  scope: this,
1837
1841
  callSite: (f, a) => f(...a)
1838
1842
  });
@@ -1885,6 +1889,9 @@ var SpaceProtocolSession = class {
1885
1889
  get authStatus() {
1886
1890
  return this._authStatus;
1887
1891
  }
1892
+ get stats() {
1893
+ return this._teleport.stats;
1894
+ }
1888
1895
  get stream() {
1889
1896
  return this._teleport.stream;
1890
1897
  }
@@ -1897,7 +1904,7 @@ var SpaceProtocolSession = class {
1897
1904
  var _a;
1898
1905
  log11("Peer authenticated", {}, {
1899
1906
  file: "space-protocol.ts",
1900
- line: 230,
1907
+ line: 236,
1901
1908
  scope: this,
1902
1909
  callSite: (f, a) => f(...a)
1903
1910
  });
@@ -2050,4 +2057,4 @@ export {
2050
2057
  SpaceProtocolSession,
2051
2058
  SpaceManager
2052
2059
  };
2053
- //# sourceMappingURL=chunk-ZZV4HWSG.mjs.map
2060
+ //# sourceMappingURL=chunk-ZYDZBSIT.mjs.map