@dxos/echo-pipeline 0.1.56-main.8d1cf70 → 0.1.56-main.96bcef8

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,37 @@ 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.info("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("data", data, {
1124
+ F: __dxlog_file7,
1125
+ L: 401,
1126
+ S: this,
1127
+ C: (f, a) => f(...a)
1128
+ });
1129
+ }
1133
1130
  });
1131
+ this._downloads.set(feed, handle);
1134
1132
  }
1135
1133
  async _initIterator() {
1136
1134
  this._feedSetIterator = new FeedSetIterator(createMessageSelector(this._timeframeClock), {
@@ -1140,7 +1138,7 @@ var Pipeline = class {
1140
1138
  this._feedSetIterator.stalled.on((iterator) => {
1141
1139
  log6.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
1142
1140
  F: __dxlog_file7,
1143
- L: 411,
1141
+ L: 415,
1144
1142
  S: this,
1145
1143
  C: (f, a) => f(...a)
1146
1144
  });
@@ -1274,10 +1272,10 @@ var AuthExtension = class extends RpcExtension {
1274
1272
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1275
1273
  import { Context as Context4 } from "@dxos/context";
1276
1274
  import { checkCredentialType } from "@dxos/credentials";
1277
- import { getStateMachineFromItem, ItemManager } from "@dxos/echo-db";
1275
+ import { getStateMachineFromItem, ItemManager, TYPE_PROPERTIES } from "@dxos/echo-db";
1278
1276
  import { CancelledError } from "@dxos/errors";
1279
1277
  import { invariant as invariant8 } from "@dxos/invariant";
1280
- import { log as log8 } from "@dxos/log";
1278
+ import { log as log8, omit } from "@dxos/log";
1281
1279
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1282
1280
  import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1283
1281
  import { tracer } from "@dxos/util";
@@ -1516,7 +1514,7 @@ var DataPipeline = class DataPipeline2 {
1516
1514
  const cache = {};
1517
1515
  try {
1518
1516
  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");
1517
+ (getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
1520
1518
  if (propertiesItem) {
1521
1519
  cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
1522
1520
  }
@@ -1568,14 +1566,6 @@ var DataPipeline = class DataPipeline2 {
1568
1566
  if (!this._isOpen) {
1569
1567
  return;
1570
1568
  }
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
1569
  await this._processEpoch(ctx, epoch.subject.assertion);
1580
1570
  this.appliedEpoch = epoch;
1581
1571
  this.onNewEpoch.emit(epoch);
@@ -1584,7 +1574,7 @@ var DataPipeline = class DataPipeline2 {
1584
1574
  async _processEpoch(ctx, epoch) {
1585
1575
  invariant8(this._isOpen, "Space is closed.", {
1586
1576
  F: __dxlog_file9,
1587
- L: 345,
1577
+ L: 344,
1588
1578
  S: this,
1589
1579
  A: [
1590
1580
  "this._isOpen",
@@ -1593,7 +1583,7 @@ var DataPipeline = class DataPipeline2 {
1593
1583
  });
1594
1584
  invariant8(this._pipeline, void 0, {
1595
1585
  F: __dxlog_file9,
1596
- L: 346,
1586
+ L: 345,
1597
1587
  S: this,
1598
1588
  A: [
1599
1589
  "this._pipeline",
@@ -1601,11 +1591,11 @@ var DataPipeline = class DataPipeline2 {
1601
1591
  ]
1602
1592
  });
1603
1593
  this._lastProcessedEpoch = epoch.number;
1604
- log8("Processing epoch", {
1605
- epoch
1594
+ log8("processing", {
1595
+ epoch: omit(epoch, "proof")
1606
1596
  }, {
1607
1597
  F: __dxlog_file9,
1608
- L: 349,
1598
+ L: 348,
1609
1599
  S: this,
1610
1600
  C: (f, a) => f(...a)
1611
1601
  });
@@ -1613,9 +1603,9 @@ var DataPipeline = class DataPipeline2 {
1613
1603
  const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
1614
1604
  this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
1615
1605
  }
1616
- log8("restarting pipeline for epoch", void 0, {
1606
+ log8("restarting pipeline from epoch", void 0, {
1617
1607
  F: __dxlog_file9,
1618
- L: 356,
1608
+ L: 354,
1619
1609
  S: this,
1620
1610
  C: (f, a) => f(...a)
1621
1611
  });
@@ -1626,7 +1616,7 @@ var DataPipeline = class DataPipeline2 {
1626
1616
  async waitUntilTimeframe(timeframe) {
1627
1617
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1628
1618
  F: __dxlog_file9,
1629
- L: 364,
1619
+ L: 361,
1630
1620
  S: this,
1631
1621
  A: [
1632
1622
  "this._pipeline",
@@ -1638,7 +1628,7 @@ var DataPipeline = class DataPipeline2 {
1638
1628
  async createEpoch() {
1639
1629
  invariant8(this._pipeline, void 0, {
1640
1630
  F: __dxlog_file9,
1641
- L: 370,
1631
+ L: 367,
1642
1632
  S: this,
1643
1633
  A: [
1644
1634
  "this._pipeline",
@@ -1647,7 +1637,7 @@ var DataPipeline = class DataPipeline2 {
1647
1637
  });
1648
1638
  invariant8(this.currentEpoch, void 0, {
1649
1639
  F: __dxlog_file9,
1650
- L: 371,
1640
+ L: 368,
1651
1641
  S: this,
1652
1642
  A: [
1653
1643
  "this.currentEpoch",
@@ -2182,7 +2172,7 @@ var SpaceProtocol = class {
2182
2172
  key: feed.key
2183
2173
  }, {
2184
2174
  F: __dxlog_file12,
2185
- L: 95,
2175
+ L: 96,
2186
2176
  S: this,
2187
2177
  C: (f, a) => f(...a)
2188
2178
  });
@@ -2191,6 +2181,7 @@ var SpaceProtocol = class {
2191
2181
  session.replicator.addFeed(feed);
2192
2182
  }
2193
2183
  }
2184
+ // TODO(burdon): Rename open? Common open/close interfaces for all services?
2194
2185
  async start() {
2195
2186
  if (this._connection) {
2196
2187
  return;
@@ -2204,7 +2195,7 @@ var SpaceProtocol = class {
2204
2195
  await this.blobSync.open();
2205
2196
  log11("starting...", void 0, {
2206
2197
  F: __dxlog_file12,
2207
- L: 120,
2198
+ L: 122,
2208
2199
  S: this,
2209
2200
  C: (f, a) => f(...a)
2210
2201
  });
@@ -2214,11 +2205,11 @@ var SpaceProtocol = class {
2214
2205
  peerId: this._swarmIdentity.peerKey,
2215
2206
  topic,
2216
2207
  topology: new MMSTTopology(topologyConfig),
2217
- label: `Protocol swarm: ${topic}`
2208
+ label: `space swarm ${topic.truncate()}`
2218
2209
  });
2219
2210
  log11("started", void 0, {
2220
2211
  F: __dxlog_file12,
2221
- L: 130,
2212
+ L: 132,
2222
2213
  S: this,
2223
2214
  C: (f, a) => f(...a)
2224
2215
  });
@@ -2228,14 +2219,14 @@ var SpaceProtocol = class {
2228
2219
  if (this._connection) {
2229
2220
  log11("stopping...", void 0, {
2230
2221
  F: __dxlog_file12,
2231
- L: 137,
2222
+ L: 139,
2232
2223
  S: this,
2233
2224
  C: (f, a) => f(...a)
2234
2225
  });
2235
2226
  await this._connection.close();
2236
2227
  log11("stopped", void 0, {
2237
2228
  F: __dxlog_file12,
2238
- L: 139,
2229
+ L: 141,
2239
2230
  S: this,
2240
2231
  C: (f, a) => f(...a)
2241
2232
  });
@@ -2302,7 +2293,7 @@ var SpaceProtocolSession = class {
2302
2293
  onAuthSuccess: () => {
2303
2294
  log11("Peer authenticated", void 0, {
2304
2295
  F: __dxlog_file12,
2305
- L: 236,
2296
+ L: 238,
2306
2297
  S: this,
2307
2298
  C: (f, a) => f(...a)
2308
2299
  });
@@ -2411,7 +2402,7 @@ var SpaceManager = class SpaceManager2 {
2411
2402
  id: this._instanceId
2412
2403
  }), {
2413
2404
  F: __dxlog_file13,
2414
- L: 125,
2405
+ L: 126,
2415
2406
  S: this,
2416
2407
  C: (f, a) => f(...a)
2417
2408
  });
@@ -2454,4 +2445,4 @@ export {
2454
2445
  SpaceProtocolSession,
2455
2446
  SpaceManager
2456
2447
  };
2457
- //# sourceMappingURL=chunk-FCDYN74V.mjs.map
2448
+ //# sourceMappingURL=chunk-GDF4DQU2.mjs.map