@dxos/echo-pipeline 0.1.56-main.6fb6466 → 0.1.56-main.71eb10c

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.
@@ -87,7 +87,7 @@ var DataServiceHost = class {
87
87
  ]
88
88
  });
89
89
  log("message", {
90
- batch,
90
+ batch: batch.objects?.length,
91
91
  meta
92
92
  }, {
93
93
  F: __dxlog_file2,
@@ -725,7 +725,7 @@ import { invariant as invariant6 } from "@dxos/invariant";
725
725
  import { PublicKey as PublicKey3 } from "@dxos/keys";
726
726
  import { log as log6 } from "@dxos/log";
727
727
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
728
- import { ComplexMap as ComplexMap3, getPrototypeSpecificInstanceId } from "@dxos/util";
728
+ import { ComplexMap as ComplexMap3 } from "@dxos/util";
729
729
 
730
730
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
731
731
  import { invariant as invariant5 } from "@dxos/invariant";
@@ -876,6 +876,8 @@ var Pipeline = class {
876
876
  // Waits for the message consumer to process the message and yield control back to the pipeline.
877
877
  this._processingTrigger = new Trigger().wake();
878
878
  this._pauseTrigger = new Trigger().wake();
879
+ // Pending downloads.
880
+ this._downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
879
881
  this._isStopping = false;
880
882
  this._isStarted = false;
881
883
  this._isBeingConsumed = false;
@@ -887,7 +889,7 @@ var Pipeline = class {
887
889
  get writer() {
888
890
  invariant6(this._writer, "Writer not set.", {
889
891
  F: __dxlog_file7,
890
- L: 230,
892
+ L: 233,
891
893
  S: this,
892
894
  A: [
893
895
  "this._writer",
@@ -916,7 +918,7 @@ var Pipeline = class {
916
918
  setWriteFeed(feed) {
917
919
  invariant6(!this._writer, "Writer already set.", {
918
920
  F: __dxlog_file7,
919
- L: 257,
921
+ L: 260,
920
922
  S: this,
921
923
  A: [
922
924
  "!this._writer",
@@ -925,7 +927,7 @@ var Pipeline = class {
925
927
  });
926
928
  invariant6(feed.properties.writable, "Feed must be writable.", {
927
929
  F: __dxlog_file7,
928
- L: 258,
930
+ L: 261,
929
931
  S: this,
930
932
  A: [
931
933
  "feed.properties.writable",
@@ -940,7 +942,7 @@ var Pipeline = class {
940
942
  async start() {
941
943
  invariant6(!this._isStarted, "Pipeline is already started.", {
942
944
  F: __dxlog_file7,
943
- L: 271,
945
+ L: 274,
944
946
  S: this,
945
947
  A: [
946
948
  "!this._isStarted",
@@ -949,7 +951,7 @@ var Pipeline = class {
949
951
  });
950
952
  log6("starting...", void 0, {
951
953
  F: __dxlog_file7,
952
- L: 272,
954
+ L: 275,
953
955
  S: this,
954
956
  C: (f, a) => f(...a)
955
957
  });
@@ -958,7 +960,7 @@ var Pipeline = class {
958
960
  this._isStarted = true;
959
961
  log6("started", void 0, {
960
962
  F: __dxlog_file7,
961
- L: 276,
963
+ L: 279,
962
964
  S: this,
963
965
  C: (f, a) => f(...a)
964
966
  });
@@ -971,11 +973,15 @@ var Pipeline = class {
971
973
  async stop() {
972
974
  log6("stopping...", void 0, {
973
975
  F: __dxlog_file7,
974
- L: 287,
976
+ L: 290,
975
977
  S: this,
976
978
  C: (f, a) => f(...a)
977
979
  });
978
980
  this._isStopping = true;
981
+ for (const [feed, handle] of this._downloads.entries()) {
982
+ feed.undownload(handle);
983
+ }
984
+ this._downloads.clear();
979
985
  await this._feedSetIterator?.close();
980
986
  await this._processingTrigger.wait();
981
987
  await this._state._ctx.dispose();
@@ -984,7 +990,7 @@ var Pipeline = class {
984
990
  this._isStarted = false;
985
991
  log6("stopped", void 0, {
986
992
  F: __dxlog_file7,
987
- L: 295,
993
+ L: 302,
988
994
  S: this,
989
995
  C: (f, a) => f(...a)
990
996
  });
@@ -996,7 +1002,7 @@ var Pipeline = class {
996
1002
  async setCursor(timeframe) {
997
1003
  invariant6(!this._isStarted || this._isPaused, "Invalid state.", {
998
1004
  F: __dxlog_file7,
999
- L: 304,
1005
+ L: 311,
1000
1006
  S: this,
1001
1007
  A: [
1002
1008
  "!this._isStarted || this._isPaused",
@@ -1025,7 +1031,7 @@ var Pipeline = class {
1025
1031
  async unpause() {
1026
1032
  invariant6(this._isPaused, "Pipeline is not paused.", {
1027
1033
  F: __dxlog_file7,
1028
- L: 334,
1034
+ L: 340,
1029
1035
  S: this,
1030
1036
  A: [
1031
1037
  "this._isPaused",
@@ -1045,7 +1051,7 @@ var Pipeline = class {
1045
1051
  async *consume() {
1046
1052
  invariant6(!this._isBeingConsumed, "Pipeline is already being consumed.", {
1047
1053
  F: __dxlog_file7,
1048
- L: 349,
1054
+ L: 355,
1049
1055
  S: this,
1050
1056
  A: [
1051
1057
  "!this._isBeingConsumed",
@@ -1055,7 +1061,7 @@ var Pipeline = class {
1055
1061
  this._isBeingConsumed = true;
1056
1062
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1057
1063
  F: __dxlog_file7,
1058
- L: 352,
1064
+ L: 358,
1059
1065
  S: this,
1060
1066
  A: [
1061
1067
  "this._feedSetIterator",
@@ -1069,7 +1075,7 @@ var Pipeline = class {
1069
1075
  if (lastFeedSetIterator !== this._feedSetIterator) {
1070
1076
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1071
1077
  F: __dxlog_file7,
1072
- L: 361,
1078
+ L: 367,
1073
1079
  S: this,
1074
1080
  A: [
1075
1081
  "this._feedSetIterator",
@@ -1092,45 +1098,39 @@ var Pipeline = class {
1092
1098
  this._isBeingConsumed = false;
1093
1099
  }
1094
1100
  _setFeedDownloadState(feed) {
1101
+ let handle = this._downloads.get(feed);
1102
+ if (handle) {
1103
+ feed.undownload(handle);
1104
+ }
1095
1105
  const timeframe = this._state._startTimeframe;
1096
1106
  const seq = timeframe.get(feed.key) ?? -1;
1097
- log6("setFeedDownloadState", {
1098
- feed: feed.key,
1099
- feedInstance: getPrototypeSpecificInstanceId(feed),
1107
+ log6("download", {
1108
+ feed: feed.key.truncate(),
1100
1109
  seq,
1101
- isBeingConsumed: this._isBeingConsumed,
1102
- isStarted: this._isStarted,
1103
- isPaused: this._isPaused
1110
+ length: feed.length
1104
1111
  }, {
1105
1112
  F: __dxlog_file7,
1106
- L: 386,
1113
+ L: 396,
1107
1114
  S: this,
1108
1115
  C: (f, a) => f(...a)
1109
1116
  });
1110
- if (!this._isStarted || this._isPaused) {
1111
- console.log(new Error().stack);
1112
- }
1113
- feed.undownload({
1114
- callback: () => log6("undownload", void 0, {
1115
- F: __dxlog_file7,
1116
- L: 398,
1117
- S: this,
1118
- C: (f, a) => f(...a)
1119
- })
1120
- });
1121
- feed.download({
1117
+ handle = feed.download({
1122
1118
  start: seq + 1,
1123
1119
  linear: true
1124
- }).catch((err) => {
1125
- log6("failed to download feed", {
1126
- err
1127
- }, {
1128
- F: __dxlog_file7,
1129
- L: 400,
1130
- S: this,
1131
- C: (f, a) => f(...a)
1132
- });
1120
+ }, (err, data) => {
1121
+ if (err) {
1122
+ } else {
1123
+ log6.info("downloaded", {
1124
+ data
1125
+ }, {
1126
+ F: __dxlog_file7,
1127
+ L: 401,
1128
+ S: this,
1129
+ C: (f, a) => f(...a)
1130
+ });
1131
+ }
1133
1132
  });
1133
+ this._downloads.set(feed, handle);
1134
1134
  }
1135
1135
  async _initIterator() {
1136
1136
  this._feedSetIterator = new FeedSetIterator(createMessageSelector(this._timeframeClock), {
@@ -1140,7 +1140,7 @@ var Pipeline = class {
1140
1140
  this._feedSetIterator.stalled.on((iterator) => {
1141
1141
  log6.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
1142
1142
  F: __dxlog_file7,
1143
- L: 411,
1143
+ L: 415,
1144
1144
  S: this,
1145
1145
  C: (f, a) => f(...a)
1146
1146
  });
@@ -1274,10 +1274,10 @@ var AuthExtension = class extends RpcExtension {
1274
1274
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1275
1275
  import { Context as Context4 } from "@dxos/context";
1276
1276
  import { checkCredentialType } from "@dxos/credentials";
1277
- import { getStateMachineFromItem, ItemManager } from "@dxos/echo-db";
1277
+ import { getStateMachineFromItem, ItemManager, TYPE_PROPERTIES } from "@dxos/echo-db";
1278
1278
  import { CancelledError } from "@dxos/errors";
1279
1279
  import { invariant as invariant8 } from "@dxos/invariant";
1280
- import { log as log8 } from "@dxos/log";
1280
+ import { log as log8, omit } from "@dxos/log";
1281
1281
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1282
1282
  import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1283
1283
  import { tracer } from "@dxos/util";
@@ -1516,7 +1516,7 @@ var DataPipeline = class DataPipeline2 {
1516
1516
  const cache = {};
1517
1517
  try {
1518
1518
  const propertiesItem = this.itemManager.items.find((item) => item.modelMeta?.type === "dxos:model/document" && // TODO(burdon): Document?
1519
- (getStateMachineFromItem(item)?.snapshot()).type === "dxos.sdk.client.Properties");
1519
+ (getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
1520
1520
  if (propertiesItem) {
1521
1521
  cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
1522
1522
  }
@@ -1568,14 +1568,6 @@ var DataPipeline = class DataPipeline2 {
1568
1568
  if (!this._isOpen) {
1569
1569
  return;
1570
1570
  }
1571
- log8("process epoch", {
1572
- epoch
1573
- }, {
1574
- F: __dxlog_file9,
1575
- L: 335,
1576
- S: this,
1577
- C: (f, a) => f(...a)
1578
- });
1579
1571
  await this._processEpoch(ctx, epoch.subject.assertion);
1580
1572
  this.appliedEpoch = epoch;
1581
1573
  this.onNewEpoch.emit(epoch);
@@ -1584,7 +1576,7 @@ var DataPipeline = class DataPipeline2 {
1584
1576
  async _processEpoch(ctx, epoch) {
1585
1577
  invariant8(this._isOpen, "Space is closed.", {
1586
1578
  F: __dxlog_file9,
1587
- L: 345,
1579
+ L: 344,
1588
1580
  S: this,
1589
1581
  A: [
1590
1582
  "this._isOpen",
@@ -1593,7 +1585,7 @@ var DataPipeline = class DataPipeline2 {
1593
1585
  });
1594
1586
  invariant8(this._pipeline, void 0, {
1595
1587
  F: __dxlog_file9,
1596
- L: 346,
1588
+ L: 345,
1597
1589
  S: this,
1598
1590
  A: [
1599
1591
  "this._pipeline",
@@ -1601,11 +1593,11 @@ var DataPipeline = class DataPipeline2 {
1601
1593
  ]
1602
1594
  });
1603
1595
  this._lastProcessedEpoch = epoch.number;
1604
- log8("Processing epoch", {
1605
- epoch
1596
+ log8("processing", {
1597
+ epoch: omit(epoch, "proof")
1606
1598
  }, {
1607
1599
  F: __dxlog_file9,
1608
- L: 349,
1600
+ L: 348,
1609
1601
  S: this,
1610
1602
  C: (f, a) => f(...a)
1611
1603
  });
@@ -1613,9 +1605,9 @@ var DataPipeline = class DataPipeline2 {
1613
1605
  const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
1614
1606
  this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
1615
1607
  }
1616
- log8("restarting pipeline for epoch", void 0, {
1608
+ log8("restarting pipeline from epoch", void 0, {
1617
1609
  F: __dxlog_file9,
1618
- L: 356,
1610
+ L: 354,
1619
1611
  S: this,
1620
1612
  C: (f, a) => f(...a)
1621
1613
  });
@@ -1626,7 +1618,7 @@ var DataPipeline = class DataPipeline2 {
1626
1618
  async waitUntilTimeframe(timeframe) {
1627
1619
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1628
1620
  F: __dxlog_file9,
1629
- L: 364,
1621
+ L: 361,
1630
1622
  S: this,
1631
1623
  A: [
1632
1624
  "this._pipeline",
@@ -1638,7 +1630,7 @@ var DataPipeline = class DataPipeline2 {
1638
1630
  async createEpoch() {
1639
1631
  invariant8(this._pipeline, void 0, {
1640
1632
  F: __dxlog_file9,
1641
- L: 370,
1633
+ L: 367,
1642
1634
  S: this,
1643
1635
  A: [
1644
1636
  "this._pipeline",
@@ -1647,7 +1639,7 @@ var DataPipeline = class DataPipeline2 {
1647
1639
  });
1648
1640
  invariant8(this.currentEpoch, void 0, {
1649
1641
  F: __dxlog_file9,
1650
- L: 371,
1642
+ L: 368,
1651
1643
  S: this,
1652
1644
  A: [
1653
1645
  "this.currentEpoch",
@@ -2182,7 +2174,7 @@ var SpaceProtocol = class {
2182
2174
  key: feed.key
2183
2175
  }, {
2184
2176
  F: __dxlog_file12,
2185
- L: 95,
2177
+ L: 96,
2186
2178
  S: this,
2187
2179
  C: (f, a) => f(...a)
2188
2180
  });
@@ -2191,6 +2183,7 @@ var SpaceProtocol = class {
2191
2183
  session.replicator.addFeed(feed);
2192
2184
  }
2193
2185
  }
2186
+ // TODO(burdon): Rename open? Common open/close interfaces for all services?
2194
2187
  async start() {
2195
2188
  if (this._connection) {
2196
2189
  return;
@@ -2204,7 +2197,7 @@ var SpaceProtocol = class {
2204
2197
  await this.blobSync.open();
2205
2198
  log11("starting...", void 0, {
2206
2199
  F: __dxlog_file12,
2207
- L: 120,
2200
+ L: 122,
2208
2201
  S: this,
2209
2202
  C: (f, a) => f(...a)
2210
2203
  });
@@ -2214,11 +2207,11 @@ var SpaceProtocol = class {
2214
2207
  peerId: this._swarmIdentity.peerKey,
2215
2208
  topic,
2216
2209
  topology: new MMSTTopology(topologyConfig),
2217
- label: `Protocol swarm: ${topic}`
2210
+ label: `space swarm ${topic.truncate()}`
2218
2211
  });
2219
2212
  log11("started", void 0, {
2220
2213
  F: __dxlog_file12,
2221
- L: 130,
2214
+ L: 132,
2222
2215
  S: this,
2223
2216
  C: (f, a) => f(...a)
2224
2217
  });
@@ -2228,14 +2221,14 @@ var SpaceProtocol = class {
2228
2221
  if (this._connection) {
2229
2222
  log11("stopping...", void 0, {
2230
2223
  F: __dxlog_file12,
2231
- L: 137,
2224
+ L: 139,
2232
2225
  S: this,
2233
2226
  C: (f, a) => f(...a)
2234
2227
  });
2235
2228
  await this._connection.close();
2236
2229
  log11("stopped", void 0, {
2237
2230
  F: __dxlog_file12,
2238
- L: 139,
2231
+ L: 141,
2239
2232
  S: this,
2240
2233
  C: (f, a) => f(...a)
2241
2234
  });
@@ -2302,7 +2295,7 @@ var SpaceProtocolSession = class {
2302
2295
  onAuthSuccess: () => {
2303
2296
  log11("Peer authenticated", void 0, {
2304
2297
  F: __dxlog_file12,
2305
- L: 236,
2298
+ L: 238,
2306
2299
  S: this,
2307
2300
  C: (f, a) => f(...a)
2308
2301
  });
@@ -2411,7 +2404,7 @@ var SpaceManager = class SpaceManager2 {
2411
2404
  id: this._instanceId
2412
2405
  }), {
2413
2406
  F: __dxlog_file13,
2414
- L: 125,
2407
+ L: 126,
2415
2408
  S: this,
2416
2409
  C: (f, a) => f(...a)
2417
2410
  });
@@ -2454,4 +2447,4 @@ export {
2454
2447
  SpaceProtocolSession,
2455
2448
  SpaceManager
2456
2449
  };
2457
- //# sourceMappingURL=chunk-FCDYN74V.mjs.map
2450
+ //# sourceMappingURL=chunk-GELWTWOW.mjs.map