@dxos/echo-pipeline 0.1.56-main.538bda2 → 0.1.56-main.5db35f4

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.
@@ -39,6 +39,7 @@ import { Context } from "@dxos/context";
39
39
  import { tagMutationsInBatch, setMetadataOnObject } from "@dxos/echo-db";
40
40
  import { invariant as invariant2 } from "@dxos/invariant";
41
41
  import { log } from "@dxos/log";
42
+ import { EchoEvent } from "@dxos/protocols/proto/dxos/echo/service";
42
43
  import { ComplexMap } from "@dxos/util";
43
44
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
44
45
  var DataServiceHost = class {
@@ -66,11 +67,19 @@ var DataServiceHost = class {
66
67
  objects
67
68
  }
68
69
  });
70
+ this._itemDemuxer.snapshot.on(ctx, (snapshot) => {
71
+ next({
72
+ action: EchoEvent.DatabaseAction.RESET,
73
+ batch: {
74
+ objects: snapshot.items
75
+ }
76
+ });
77
+ });
69
78
  this._itemDemuxer.mutation.on(ctx, (message) => {
70
79
  const { batch, meta } = message;
71
80
  invariant2(!meta.clientTag, "Unexpected client tag in mutation message", {
72
81
  F: __dxlog_file2,
73
- L: 61,
82
+ L: 68,
74
83
  S: this,
75
84
  A: [
76
85
  "!(meta as any).clientTag",
@@ -82,7 +91,7 @@ var DataServiceHost = class {
82
91
  meta
83
92
  }, {
84
93
  F: __dxlog_file2,
85
- L: 62,
94
+ L: 69,
86
95
  S: this,
87
96
  C: (f, a) => f(...a)
88
97
  });
@@ -110,7 +119,7 @@ var DataServiceHost = class {
110
119
  async write(request) {
111
120
  invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
112
121
  F: __dxlog_file2,
113
- L: 88,
122
+ L: 95,
114
123
  S: this,
115
124
  A: [
116
125
  "!this._ctx.disposed",
@@ -119,7 +128,7 @@ var DataServiceHost = class {
119
128
  });
120
129
  invariant2(this._writeStream, "Cannot write mutations in readonly mode", {
121
130
  F: __dxlog_file2,
122
- L: 89,
131
+ L: 96,
123
132
  S: this,
124
133
  A: [
125
134
  "this._writeStream",
@@ -131,7 +140,7 @@ var DataServiceHost = class {
131
140
  objectCount: request.batch.objects?.length ?? 0
132
141
  }, {
133
142
  F: __dxlog_file2,
134
- L: 91,
143
+ L: 98,
135
144
  S: this,
136
145
  C: (f, a) => f(...a)
137
146
  });
@@ -145,7 +154,7 @@ var DataServiceHost = class {
145
154
  seq: receipt2.seq
146
155
  }, {
147
156
  F: __dxlog_file2,
148
- L: 100,
157
+ L: 107,
149
158
  S: this,
150
159
  C: (f, a) => f(...a)
151
160
  });
@@ -716,7 +725,7 @@ import { invariant as invariant6 } from "@dxos/invariant";
716
725
  import { PublicKey as PublicKey3 } from "@dxos/keys";
717
726
  import { log as log6 } from "@dxos/log";
718
727
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
719
- import { ComplexMap as ComplexMap3 } from "@dxos/util";
728
+ import { ComplexMap as ComplexMap3, getPrototypeSpecificInstanceId } from "@dxos/util";
720
729
 
721
730
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
722
731
  import { invariant as invariant5 } from "@dxos/invariant";
@@ -869,7 +878,7 @@ var Pipeline = class {
869
878
  this._pauseTrigger = new Trigger().wake();
870
879
  this._isStopping = false;
871
880
  this._isStarted = false;
872
- this._isOpen = false;
881
+ this._isBeingConsumed = false;
873
882
  this._isPaused = false;
874
883
  }
875
884
  get state() {
@@ -900,12 +909,14 @@ var Pipeline = class {
900
909
  if (this._feedSetIterator) {
901
910
  await this._feedSetIterator.addFeed(feed);
902
911
  }
903
- this._setFeedDownloadState(feed);
912
+ if (this._isStarted && !this._isPaused) {
913
+ this._setFeedDownloadState(feed);
914
+ }
904
915
  }
905
916
  setWriteFeed(feed) {
906
917
  invariant6(!this._writer, "Writer already set.", {
907
918
  F: __dxlog_file7,
908
- L: 253,
919
+ L: 257,
909
920
  S: this,
910
921
  A: [
911
922
  "!this._writer",
@@ -914,7 +925,7 @@ var Pipeline = class {
914
925
  });
915
926
  invariant6(feed.properties.writable, "Feed must be writable.", {
916
927
  F: __dxlog_file7,
917
- L: 254,
928
+ L: 258,
918
929
  S: this,
919
930
  A: [
920
931
  "feed.properties.writable",
@@ -929,7 +940,7 @@ var Pipeline = class {
929
940
  async start() {
930
941
  invariant6(!this._isStarted, "Pipeline is already started.", {
931
942
  F: __dxlog_file7,
932
- L: 267,
943
+ L: 271,
933
944
  S: this,
934
945
  A: [
935
946
  "!this._isStarted",
@@ -938,7 +949,7 @@ var Pipeline = class {
938
949
  });
939
950
  log6("starting...", void 0, {
940
951
  F: __dxlog_file7,
941
- L: 268,
952
+ L: 272,
942
953
  S: this,
943
954
  C: (f, a) => f(...a)
944
955
  });
@@ -947,15 +958,20 @@ var Pipeline = class {
947
958
  this._isStarted = true;
948
959
  log6("started", void 0, {
949
960
  F: __dxlog_file7,
950
- L: 272,
961
+ L: 276,
951
962
  S: this,
952
963
  C: (f, a) => f(...a)
953
964
  });
965
+ if (!this._isPaused) {
966
+ for (const feed of this._feeds.values()) {
967
+ this._setFeedDownloadState(feed);
968
+ }
969
+ }
954
970
  }
955
971
  async stop() {
956
972
  log6("stopping...", void 0, {
957
973
  F: __dxlog_file7,
958
- L: 277,
974
+ L: 287,
959
975
  S: this,
960
976
  C: (f, a) => f(...a)
961
977
  });
@@ -968,7 +984,7 @@ var Pipeline = class {
968
984
  this._isStarted = false;
969
985
  log6("stopped", void 0, {
970
986
  F: __dxlog_file7,
971
- L: 285,
987
+ L: 295,
972
988
  S: this,
973
989
  C: (f, a) => f(...a)
974
990
  });
@@ -980,7 +996,7 @@ var Pipeline = class {
980
996
  async setCursor(timeframe) {
981
997
  invariant6(!this._isStarted || this._isPaused, "Invalid state.", {
982
998
  F: __dxlog_file7,
983
- L: 294,
999
+ L: 304,
984
1000
  S: this,
985
1001
  A: [
986
1002
  "!this._isStarted || this._isPaused",
@@ -989,9 +1005,6 @@ var Pipeline = class {
989
1005
  });
990
1006
  this._state._startTimeframe = timeframe;
991
1007
  this._timeframeClock.setTimeframe(timeframe);
992
- for (const feed of this._feeds.values()) {
993
- this._setFeedDownloadState(feed);
994
- }
995
1008
  if (this._feedSetIterator) {
996
1009
  await this._feedSetIterator.close();
997
1010
  await this._initIterator();
@@ -1002,15 +1015,6 @@ var Pipeline = class {
1002
1015
  * Calling pause while processing will cause a deadlock.
1003
1016
  */
1004
1017
  async pause() {
1005
- invariant6(this._isStarted, "Pipeline is not open.", {
1006
- F: __dxlog_file7,
1007
- L: 316,
1008
- S: this,
1009
- A: [
1010
- "this._isStarted",
1011
- "'Pipeline is not open.'"
1012
- ]
1013
- });
1014
1018
  if (this._isPaused) {
1015
1019
  return;
1016
1020
  }
@@ -1019,18 +1023,9 @@ var Pipeline = class {
1019
1023
  this._isPaused = true;
1020
1024
  }
1021
1025
  async unpause() {
1022
- invariant6(this._isStarted, "Pipeline is not open.", {
1023
- F: __dxlog_file7,
1024
- L: 328,
1025
- S: this,
1026
- A: [
1027
- "this._isStarted",
1028
- "'Pipeline is not open.'"
1029
- ]
1030
- });
1031
1026
  invariant6(this._isPaused, "Pipeline is not paused.", {
1032
1027
  F: __dxlog_file7,
1033
- L: 329,
1028
+ L: 334,
1034
1029
  S: this,
1035
1030
  A: [
1036
1031
  "this._isPaused",
@@ -1039,25 +1034,28 @@ var Pipeline = class {
1039
1034
  });
1040
1035
  this._pauseTrigger.wake();
1041
1036
  this._isPaused = false;
1037
+ for (const feed of this._feeds.values()) {
1038
+ this._setFeedDownloadState(feed);
1039
+ }
1042
1040
  }
1043
1041
  /**
1044
1042
  * Starts to iterate over the ordered messages from the added feeds.
1045
1043
  * Updates the timeframe clock after the message has bee processed.
1046
1044
  */
1047
1045
  async *consume() {
1048
- invariant6(!this._isOpen, "Pipeline is already being consumed.", {
1046
+ invariant6(!this._isBeingConsumed, "Pipeline is already being consumed.", {
1049
1047
  F: __dxlog_file7,
1050
- L: 340,
1048
+ L: 349,
1051
1049
  S: this,
1052
1050
  A: [
1053
- "!this._isOpen",
1051
+ "!this._isBeingConsumed",
1054
1052
  "'Pipeline is already being consumed.'"
1055
1053
  ]
1056
1054
  });
1057
- this._isOpen = true;
1055
+ this._isBeingConsumed = true;
1058
1056
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1059
1057
  F: __dxlog_file7,
1060
- L: 343,
1058
+ L: 352,
1061
1059
  S: this,
1062
1060
  A: [
1063
1061
  "this._feedSetIterator",
@@ -1071,7 +1069,7 @@ var Pipeline = class {
1071
1069
  if (lastFeedSetIterator !== this._feedSetIterator) {
1072
1070
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1073
1071
  F: __dxlog_file7,
1074
- L: 352,
1072
+ L: 361,
1075
1073
  S: this,
1076
1074
  A: [
1077
1075
  "this._feedSetIterator",
@@ -1091,15 +1089,31 @@ var Pipeline = class {
1091
1089
  this._timeframeClock.updateTimeframe();
1092
1090
  }
1093
1091
  }
1094
- this._isOpen = false;
1092
+ this._isBeingConsumed = false;
1095
1093
  }
1096
1094
  _setFeedDownloadState(feed) {
1097
1095
  const timeframe = this._state._startTimeframe;
1098
- const seq = timeframe.get(feed.key) ?? 0;
1096
+ const seq = timeframe.get(feed.key) ?? -1;
1097
+ log6("setFeedDownloadState", {
1098
+ feed: feed.key,
1099
+ feedInstance: getPrototypeSpecificInstanceId(feed),
1100
+ seq,
1101
+ isBeingConsumed: this._isBeingConsumed,
1102
+ isStarted: this._isStarted,
1103
+ isPaused: this._isPaused
1104
+ }, {
1105
+ F: __dxlog_file7,
1106
+ L: 386,
1107
+ S: this,
1108
+ C: (f, a) => f(...a)
1109
+ });
1110
+ if (!this._isStarted || this._isPaused) {
1111
+ console.log(new Error().stack);
1112
+ }
1099
1113
  feed.undownload({
1100
1114
  callback: () => log6("undownload", void 0, {
1101
1115
  F: __dxlog_file7,
1102
- L: 377,
1116
+ L: 398,
1103
1117
  S: this,
1104
1118
  C: (f, a) => f(...a)
1105
1119
  })
@@ -1112,7 +1126,7 @@ var Pipeline = class {
1112
1126
  err
1113
1127
  }, {
1114
1128
  F: __dxlog_file7,
1115
- L: 379,
1129
+ L: 400,
1116
1130
  S: this,
1117
1131
  C: (f, a) => f(...a)
1118
1132
  });
@@ -1126,7 +1140,7 @@ var Pipeline = class {
1126
1140
  this._feedSetIterator.stalled.on((iterator) => {
1127
1141
  log6.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
1128
1142
  F: __dxlog_file7,
1129
- L: 390,
1143
+ L: 411,
1130
1144
  S: this,
1131
1145
  C: (f, a) => f(...a)
1132
1146
  });
@@ -1323,8 +1337,8 @@ var DataPipeline = class DataPipeline2 {
1323
1337
  }
1324
1338
  this._pipeline = new Pipeline();
1325
1339
  await this._params.onPipelineCreated(this._pipeline);
1326
- await this._pipeline.start();
1327
1340
  await this._pipeline.pause();
1341
+ await this._pipeline.start();
1328
1342
  if (this._targetTimeframe) {
1329
1343
  this._pipeline.state.setTargetTimeframe(this._targetTimeframe);
1330
1344
  }
@@ -1332,7 +1346,7 @@ var DataPipeline = class DataPipeline2 {
1332
1346
  write: (data, options) => {
1333
1347
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1334
1348
  F: __dxlog_file9,
1335
- L: 145,
1349
+ L: 146,
1336
1350
  S: this,
1337
1351
  A: [
1338
1352
  "this._pipeline",
@@ -1341,7 +1355,7 @@ var DataPipeline = class DataPipeline2 {
1341
1355
  });
1342
1356
  invariant8(this.currentEpoch, "Epoch is not initialized.", {
1343
1357
  F: __dxlog_file9,
1344
- L: 146,
1358
+ L: 147,
1345
1359
  S: this,
1346
1360
  A: [
1347
1361
  "this.currentEpoch",
@@ -1367,7 +1381,7 @@ var DataPipeline = class DataPipeline2 {
1367
1381
  }
1368
1382
  log8("close", void 0, {
1369
1383
  F: __dxlog_file9,
1370
- L: 170,
1384
+ L: 171,
1371
1385
  S: this,
1372
1386
  C: (f, a) => f(...a)
1373
1387
  });
@@ -1382,7 +1396,7 @@ var DataPipeline = class DataPipeline2 {
1382
1396
  } catch (err) {
1383
1397
  log8.catch(err, void 0, {
1384
1398
  F: __dxlog_file9,
1385
- L: 183,
1399
+ L: 184,
1386
1400
  S: this,
1387
1401
  C: (f, a) => f(...a)
1388
1402
  });
@@ -1406,7 +1420,7 @@ var DataPipeline = class DataPipeline2 {
1406
1420
  }
1407
1421
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1408
1422
  F: __dxlog_file9,
1409
- L: 206,
1423
+ L: 207,
1410
1424
  S: this,
1411
1425
  A: [
1412
1426
  "this._pipeline",
@@ -1420,7 +1434,7 @@ var DataPipeline = class DataPipeline2 {
1420
1434
  seq
1421
1435
  }, {
1422
1436
  F: __dxlog_file9,
1423
- L: 209,
1437
+ L: 210,
1424
1438
  S: this,
1425
1439
  C: (f, a) => f(...a)
1426
1440
  });
@@ -1432,7 +1446,7 @@ var DataPipeline = class DataPipeline2 {
1432
1446
  feedKey
1433
1447
  }, {
1434
1448
  F: __dxlog_file9,
1435
- L: 215,
1449
+ L: 216,
1436
1450
  S: this,
1437
1451
  C: (f, a) => f(...a)
1438
1452
  });
@@ -1455,7 +1469,7 @@ var DataPipeline = class DataPipeline2 {
1455
1469
  spaceKey: this._params.spaceKey.toHex()
1456
1470
  }, {
1457
1471
  F: __dxlog_file9,
1458
- L: 232,
1472
+ L: 233,
1459
1473
  S: this,
1460
1474
  C: (f, a) => f(...a)
1461
1475
  });
@@ -1464,7 +1478,7 @@ var DataPipeline = class DataPipeline2 {
1464
1478
  } catch (err) {
1465
1479
  log8.catch(err, void 0, {
1466
1480
  F: __dxlog_file9,
1467
- L: 242,
1481
+ L: 243,
1468
1482
  S: this,
1469
1483
  C: (f, a) => f(...a)
1470
1484
  });
@@ -1474,7 +1488,7 @@ var DataPipeline = class DataPipeline2 {
1474
1488
  _createSnapshot() {
1475
1489
  invariant8(this.databaseHost, "Database backend is not initialized.", {
1476
1490
  F: __dxlog_file9,
1477
- L: 248,
1491
+ L: 249,
1478
1492
  S: this,
1479
1493
  A: [
1480
1494
  "this.databaseHost",
@@ -1503,7 +1517,7 @@ var DataPipeline = class DataPipeline2 {
1503
1517
  } catch (err) {
1504
1518
  log8.warn("Failed to cache properties", err, {
1505
1519
  F: __dxlog_file9,
1506
- L: 277,
1520
+ L: 278,
1507
1521
  S: this,
1508
1522
  C: (f, a) => f(...a)
1509
1523
  });
@@ -1529,14 +1543,14 @@ var DataPipeline = class DataPipeline2 {
1529
1543
  if (err instanceof CancelledError) {
1530
1544
  log8("Epoch processing cancelled.", void 0, {
1531
1545
  F: __dxlog_file9,
1532
- L: 309,
1546
+ L: 310,
1533
1547
  S: this,
1534
1548
  C: (f, a) => f(...a)
1535
1549
  });
1536
1550
  } else {
1537
1551
  log8.catch(err, void 0, {
1538
1552
  F: __dxlog_file9,
1539
- L: 311,
1553
+ L: 312,
1540
1554
  S: this,
1541
1555
  C: (f, a) => f(...a)
1542
1556
  });
@@ -1552,7 +1566,7 @@ var DataPipeline = class DataPipeline2 {
1552
1566
  epoch
1553
1567
  }, {
1554
1568
  F: __dxlog_file9,
1555
- L: 321,
1569
+ L: 322,
1556
1570
  S: this,
1557
1571
  C: (f, a) => f(...a)
1558
1572
  });
@@ -1564,7 +1578,7 @@ var DataPipeline = class DataPipeline2 {
1564
1578
  async _processEpoch(ctx, epoch) {
1565
1579
  invariant8(this._isOpen, "Space is closed.", {
1566
1580
  F: __dxlog_file9,
1567
- L: 331,
1581
+ L: 332,
1568
1582
  S: this,
1569
1583
  A: [
1570
1584
  "this._isOpen",
@@ -1573,7 +1587,7 @@ var DataPipeline = class DataPipeline2 {
1573
1587
  });
1574
1588
  invariant8(this._pipeline, void 0, {
1575
1589
  F: __dxlog_file9,
1576
- L: 332,
1590
+ L: 333,
1577
1591
  S: this,
1578
1592
  A: [
1579
1593
  "this._pipeline",
@@ -1585,7 +1599,7 @@ var DataPipeline = class DataPipeline2 {
1585
1599
  epoch
1586
1600
  }, {
1587
1601
  F: __dxlog_file9,
1588
- L: 335,
1602
+ L: 336,
1589
1603
  S: this,
1590
1604
  C: (f, a) => f(...a)
1591
1605
  });
@@ -2388,4 +2402,4 @@ export {
2388
2402
  SpaceProtocolSession,
2389
2403
  SpaceManager
2390
2404
  };
2391
- //# sourceMappingURL=chunk-3OTHGQEY.mjs.map
2405
+ //# sourceMappingURL=chunk-WS36YFR3.mjs.map