@dxos/echo-pipeline 0.1.56-main.6293c6e → 0.1.56-main.6fb6466

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
  });
@@ -1265,6 +1279,7 @@ import { CancelledError } from "@dxos/errors";
1265
1279
  import { invariant as invariant8 } from "@dxos/invariant";
1266
1280
  import { log as log8 } from "@dxos/log";
1267
1281
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1282
+ import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1268
1283
  import { tracer } from "@dxos/util";
1269
1284
  function _ts_decorate5(decorators, target, key, desc) {
1270
1285
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1291,6 +1306,8 @@ var DataPipeline = class DataPipeline2 {
1291
1306
  this._lastTimeframeSaveTime = 0;
1292
1307
  this._lastSnapshotSaveTime = 0;
1293
1308
  this._lastProcessedEpoch = -1;
1309
+ this._usage = new TimeUsageCounter();
1310
+ this._mutations = new TimeSeriesCounter();
1294
1311
  this.currentEpoch = void 0;
1295
1312
  this.appliedEpoch = void 0;
1296
1313
  this.onNewEpoch = new Event4();
@@ -1323,8 +1340,8 @@ var DataPipeline = class DataPipeline2 {
1323
1340
  }
1324
1341
  this._pipeline = new Pipeline();
1325
1342
  await this._params.onPipelineCreated(this._pipeline);
1326
- await this._pipeline.start();
1327
1343
  await this._pipeline.pause();
1344
+ await this._pipeline.start();
1328
1345
  if (this._targetTimeframe) {
1329
1346
  this._pipeline.state.setTargetTimeframe(this._targetTimeframe);
1330
1347
  }
@@ -1332,7 +1349,7 @@ var DataPipeline = class DataPipeline2 {
1332
1349
  write: (data, options) => {
1333
1350
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1334
1351
  F: __dxlog_file9,
1335
- L: 145,
1352
+ L: 154,
1336
1353
  S: this,
1337
1354
  A: [
1338
1355
  "this._pipeline",
@@ -1341,7 +1358,7 @@ var DataPipeline = class DataPipeline2 {
1341
1358
  });
1342
1359
  invariant8(this.currentEpoch, "Epoch is not initialized.", {
1343
1360
  F: __dxlog_file9,
1344
- L: 146,
1361
+ L: 155,
1345
1362
  S: this,
1346
1363
  A: [
1347
1364
  "this.currentEpoch",
@@ -1367,7 +1384,7 @@ var DataPipeline = class DataPipeline2 {
1367
1384
  }
1368
1385
  log8("close", void 0, {
1369
1386
  F: __dxlog_file9,
1370
- L: 170,
1387
+ L: 179,
1371
1388
  S: this,
1372
1389
  C: (f, a) => f(...a)
1373
1390
  });
@@ -1382,7 +1399,7 @@ var DataPipeline = class DataPipeline2 {
1382
1399
  } catch (err) {
1383
1400
  log8.catch(err, void 0, {
1384
1401
  F: __dxlog_file9,
1385
- L: 183,
1402
+ L: 192,
1386
1403
  S: this,
1387
1404
  C: (f, a) => f(...a)
1388
1405
  });
@@ -1406,7 +1423,7 @@ var DataPipeline = class DataPipeline2 {
1406
1423
  }
1407
1424
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1408
1425
  F: __dxlog_file9,
1409
- L: 206,
1426
+ L: 215,
1410
1427
  S: this,
1411
1428
  A: [
1412
1429
  "this._pipeline",
@@ -1414,13 +1431,15 @@ var DataPipeline = class DataPipeline2 {
1414
1431
  ]
1415
1432
  });
1416
1433
  for await (const msg of this._pipeline.consume()) {
1434
+ const span = this._usage.beginRecording();
1435
+ this._mutations.inc();
1417
1436
  const { feedKey, seq, data } = msg;
1418
1437
  log8("processing message", {
1419
1438
  feedKey,
1420
1439
  seq
1421
1440
  }, {
1422
1441
  F: __dxlog_file9,
1423
- L: 209,
1442
+ L: 221,
1424
1443
  S: this,
1425
1444
  C: (f, a) => f(...a)
1426
1445
  });
@@ -1432,7 +1451,7 @@ var DataPipeline = class DataPipeline2 {
1432
1451
  feedKey
1433
1452
  }, {
1434
1453
  F: __dxlog_file9,
1435
- L: 215,
1454
+ L: 227,
1436
1455
  S: this,
1437
1456
  C: (f, a) => f(...a)
1438
1457
  });
@@ -1455,7 +1474,7 @@ var DataPipeline = class DataPipeline2 {
1455
1474
  spaceKey: this._params.spaceKey.toHex()
1456
1475
  }, {
1457
1476
  F: __dxlog_file9,
1458
- L: 232,
1477
+ L: 244,
1459
1478
  S: this,
1460
1479
  C: (f, a) => f(...a)
1461
1480
  });
@@ -1464,17 +1483,18 @@ var DataPipeline = class DataPipeline2 {
1464
1483
  } catch (err) {
1465
1484
  log8.catch(err, void 0, {
1466
1485
  F: __dxlog_file9,
1467
- L: 242,
1486
+ L: 254,
1468
1487
  S: this,
1469
1488
  C: (f, a) => f(...a)
1470
1489
  });
1471
1490
  }
1491
+ span.end();
1472
1492
  }
1473
1493
  }
1474
1494
  _createSnapshot() {
1475
1495
  invariant8(this.databaseHost, "Database backend is not initialized.", {
1476
1496
  F: __dxlog_file9,
1477
- L: 248,
1497
+ L: 262,
1478
1498
  S: this,
1479
1499
  A: [
1480
1500
  "this.databaseHost",
@@ -1503,7 +1523,7 @@ var DataPipeline = class DataPipeline2 {
1503
1523
  } catch (err) {
1504
1524
  log8.warn("Failed to cache properties", err, {
1505
1525
  F: __dxlog_file9,
1506
- L: 277,
1526
+ L: 291,
1507
1527
  S: this,
1508
1528
  C: (f, a) => f(...a)
1509
1529
  });
@@ -1529,14 +1549,14 @@ var DataPipeline = class DataPipeline2 {
1529
1549
  if (err instanceof CancelledError) {
1530
1550
  log8("Epoch processing cancelled.", void 0, {
1531
1551
  F: __dxlog_file9,
1532
- L: 309,
1552
+ L: 323,
1533
1553
  S: this,
1534
1554
  C: (f, a) => f(...a)
1535
1555
  });
1536
1556
  } else {
1537
1557
  log8.catch(err, void 0, {
1538
1558
  F: __dxlog_file9,
1539
- L: 311,
1559
+ L: 325,
1540
1560
  S: this,
1541
1561
  C: (f, a) => f(...a)
1542
1562
  });
@@ -1552,7 +1572,7 @@ var DataPipeline = class DataPipeline2 {
1552
1572
  epoch
1553
1573
  }, {
1554
1574
  F: __dxlog_file9,
1555
- L: 321,
1575
+ L: 335,
1556
1576
  S: this,
1557
1577
  C: (f, a) => f(...a)
1558
1578
  });
@@ -1564,7 +1584,7 @@ var DataPipeline = class DataPipeline2 {
1564
1584
  async _processEpoch(ctx, epoch) {
1565
1585
  invariant8(this._isOpen, "Space is closed.", {
1566
1586
  F: __dxlog_file9,
1567
- L: 331,
1587
+ L: 345,
1568
1588
  S: this,
1569
1589
  A: [
1570
1590
  "this._isOpen",
@@ -1573,7 +1593,7 @@ var DataPipeline = class DataPipeline2 {
1573
1593
  });
1574
1594
  invariant8(this._pipeline, void 0, {
1575
1595
  F: __dxlog_file9,
1576
- L: 332,
1596
+ L: 346,
1577
1597
  S: this,
1578
1598
  A: [
1579
1599
  "this._pipeline",
@@ -1585,7 +1605,7 @@ var DataPipeline = class DataPipeline2 {
1585
1605
  epoch
1586
1606
  }, {
1587
1607
  F: __dxlog_file9,
1588
- L: 335,
1608
+ L: 349,
1589
1609
  S: this,
1590
1610
  C: (f, a) => f(...a)
1591
1611
  });
@@ -1595,7 +1615,7 @@ var DataPipeline = class DataPipeline2 {
1595
1615
  }
1596
1616
  log8("restarting pipeline for epoch", void 0, {
1597
1617
  F: __dxlog_file9,
1598
- L: 343,
1618
+ L: 356,
1599
1619
  S: this,
1600
1620
  C: (f, a) => f(...a)
1601
1621
  });
@@ -1606,7 +1626,7 @@ var DataPipeline = class DataPipeline2 {
1606
1626
  async waitUntilTimeframe(timeframe) {
1607
1627
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1608
1628
  F: __dxlog_file9,
1609
- L: 351,
1629
+ L: 364,
1610
1630
  S: this,
1611
1631
  A: [
1612
1632
  "this._pipeline",
@@ -1618,7 +1638,7 @@ var DataPipeline = class DataPipeline2 {
1618
1638
  async createEpoch() {
1619
1639
  invariant8(this._pipeline, void 0, {
1620
1640
  F: __dxlog_file9,
1621
- L: 357,
1641
+ L: 370,
1622
1642
  S: this,
1623
1643
  A: [
1624
1644
  "this._pipeline",
@@ -1627,7 +1647,7 @@ var DataPipeline = class DataPipeline2 {
1627
1647
  });
1628
1648
  invariant8(this.currentEpoch, void 0, {
1629
1649
  F: __dxlog_file9,
1630
- L: 358,
1650
+ L: 371,
1631
1651
  S: this,
1632
1652
  A: [
1633
1653
  "this.currentEpoch",
@@ -1650,6 +1670,12 @@ var DataPipeline = class DataPipeline2 {
1650
1670
  await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
1651
1671
  }
1652
1672
  };
1673
+ _ts_decorate5([
1674
+ trace.metricsCounter()
1675
+ ], DataPipeline.prototype, "_usage", void 0);
1676
+ _ts_decorate5([
1677
+ trace.metricsCounter()
1678
+ ], DataPipeline.prototype, "_mutations", void 0);
1653
1679
  _ts_decorate5([
1654
1680
  synchronized3
1655
1681
  ], DataPipeline.prototype, "open", null);
@@ -1663,7 +1689,8 @@ _ts_decorate5([
1663
1689
  synchronized3
1664
1690
  ], DataPipeline.prototype, "createEpoch", null);
1665
1691
  DataPipeline = _ts_decorate5([
1666
- trackLeaks2("open", "close")
1692
+ trackLeaks2("open", "close"),
1693
+ trace.resource()
1667
1694
  ], DataPipeline);
1668
1695
 
1669
1696
  // packages/core/echo/echo-pipeline/src/space/space.ts
@@ -1671,22 +1698,36 @@ import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeak
1671
1698
  import { invariant as invariant9 } from "@dxos/invariant";
1672
1699
  import { log as log10, logInfo } from "@dxos/log";
1673
1700
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
1674
- import { trace } from "@dxos/tracing";
1701
+ import { trace as trace3 } from "@dxos/tracing";
1675
1702
  import { Callback as Callback2 } from "@dxos/util";
1676
1703
 
1677
1704
  // packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
1705
+ import { Context as Context5 } from "@dxos/context";
1678
1706
  import { SpaceStateMachine } from "@dxos/credentials";
1679
1707
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1680
1708
  import { log as log9 } from "@dxos/log";
1681
1709
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1682
1710
  import { Timeframe as Timeframe4 } from "@dxos/timeframe";
1711
+ import { TimeSeriesCounter as TimeSeriesCounter2, TimeUsageCounter as TimeUsageCounter2, trace as trace2 } from "@dxos/tracing";
1683
1712
  import { Callback, tracer as tracer2 } from "@dxos/util";
1713
+ function _ts_decorate6(decorators, target, key, desc) {
1714
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1715
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1716
+ r = Reflect.decorate(decorators, target, key, desc);
1717
+ else
1718
+ for (var i = decorators.length - 1; i >= 0; i--)
1719
+ if (d = decorators[i])
1720
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1721
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1722
+ }
1684
1723
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1685
1724
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
1686
- var ControlPipeline = class {
1725
+ var ControlPipeline = class ControlPipeline2 {
1687
1726
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1688
1727
  this._lastTimeframeSaveTime = Date.now();
1689
1728
  this.onFeedAdmitted = new Callback();
1729
+ this._usage = new TimeUsageCounter2();
1730
+ this._mutations = new TimeSeriesCounter2();
1690
1731
  this._spaceKey = spaceKey;
1691
1732
  this._metadata = metadataStore;
1692
1733
  this._pipeline = new Pipeline();
@@ -1697,7 +1738,7 @@ var ControlPipeline = class {
1697
1738
  key: info.key
1698
1739
  }, {
1699
1740
  F: __dxlog_file10,
1700
- L: 51,
1741
+ L: 61,
1701
1742
  S: this,
1702
1743
  C: (f, a) => f(...a)
1703
1744
  });
@@ -1708,7 +1749,7 @@ var ControlPipeline = class {
1708
1749
  } catch (err) {
1709
1750
  log9.catch(err, void 0, {
1710
1751
  F: __dxlog_file10,
1711
- L: 59,
1752
+ L: 69,
1712
1753
  S: this,
1713
1754
  C: (f, a) => f(...a)
1714
1755
  });
@@ -1731,57 +1772,66 @@ var ControlPipeline = class {
1731
1772
  async start() {
1732
1773
  log9("starting...", void 0, {
1733
1774
  F: __dxlog_file10,
1734
- L: 83,
1775
+ L: 93,
1735
1776
  S: this,
1736
1777
  C: (f, a) => f(...a)
1737
1778
  });
1738
1779
  setTimeout(async () => {
1739
- for await (const msg of this._pipeline.consume()) {
1740
- try {
1741
- log9("processing", {
1742
- key: msg.feedKey,
1743
- seq: msg.seq
1744
- }, {
1745
- F: __dxlog_file10,
1746
- L: 88,
1747
- S: this,
1748
- C: (f, a) => f(...a)
1749
- });
1750
- if (msg.data.payload.credential) {
1751
- const timer = tracer2.mark("dxos.echo.pipeline.control");
1752
- const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1753
- timer.end();
1754
- if (!result) {
1755
- log9.warn("processing failed", {
1756
- msg
1757
- }, {
1758
- F: __dxlog_file10,
1759
- L: 98,
1760
- S: this,
1761
- C: (f, a) => f(...a)
1762
- });
1763
- } else {
1764
- await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1765
- }
1766
- }
1767
- } catch (err) {
1768
- log9.catch(err, void 0, {
1769
- F: __dxlog_file10,
1770
- L: 104,
1771
- S: this,
1772
- C: (f, a) => f(...a)
1773
- });
1774
- }
1775
- }
1780
+ void this._consumePipeline(new Context5());
1776
1781
  });
1777
1782
  await this._pipeline.start();
1778
1783
  log9("started", void 0, {
1779
1784
  F: __dxlog_file10,
1780
- L: 110,
1785
+ L: 99,
1781
1786
  S: this,
1782
1787
  C: (f, a) => f(...a)
1783
1788
  });
1784
1789
  }
1790
+ async _consumePipeline(ctx) {
1791
+ for await (const msg of this._pipeline.consume()) {
1792
+ const span = this._usage.beginRecording();
1793
+ this._mutations.inc();
1794
+ try {
1795
+ await this._processMessage(ctx, msg);
1796
+ } catch (err) {
1797
+ log9.catch(err, void 0, {
1798
+ F: __dxlog_file10,
1799
+ L: 111,
1800
+ S: this,
1801
+ C: (f, a) => f(...a)
1802
+ });
1803
+ }
1804
+ span.end();
1805
+ }
1806
+ }
1807
+ async _processMessage(ctx, msg) {
1808
+ log9("processing", {
1809
+ key: msg.feedKey,
1810
+ seq: msg.seq
1811
+ }, {
1812
+ F: __dxlog_file10,
1813
+ L: 121,
1814
+ S: this,
1815
+ C: (f, a) => f(...a)
1816
+ });
1817
+ if (msg.data.payload.credential) {
1818
+ const timer = tracer2.mark("dxos.echo.pipeline.control");
1819
+ const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1820
+ timer.end();
1821
+ if (!result) {
1822
+ log9.warn("processing failed", {
1823
+ msg
1824
+ }, {
1825
+ F: __dxlog_file10,
1826
+ L: 131,
1827
+ S: this,
1828
+ C: (f, a) => f(...a)
1829
+ });
1830
+ } else {
1831
+ await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1832
+ }
1833
+ }
1834
+ }
1785
1835
  async _noteTargetStateIfNeeded(timeframe) {
1786
1836
  if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2) {
1787
1837
  this._lastTimeframeSaveTime = Date.now();
@@ -1791,7 +1841,7 @@ var ControlPipeline = class {
1791
1841
  async stop() {
1792
1842
  log9("stopping...", void 0, {
1793
1843
  F: __dxlog_file10,
1794
- L: 124,
1844
+ L: 149,
1795
1845
  S: this,
1796
1846
  C: (f, a) => f(...a)
1797
1847
  });
@@ -1799,7 +1849,7 @@ var ControlPipeline = class {
1799
1849
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1800
1850
  log9("stopped", void 0, {
1801
1851
  F: __dxlog_file10,
1802
- L: 127,
1852
+ L: 152,
1803
1853
  S: this,
1804
1854
  C: (f, a) => f(...a)
1805
1855
  });
@@ -1812,16 +1862,31 @@ var ControlPipeline = class {
1812
1862
  } catch (err) {
1813
1863
  log9(err, void 0, {
1814
1864
  F: __dxlog_file10,
1815
- L: 136,
1865
+ L: 161,
1816
1866
  S: this,
1817
1867
  C: (f, a) => f(...a)
1818
1868
  });
1819
1869
  }
1820
1870
  }
1821
1871
  };
1872
+ _ts_decorate6([
1873
+ trace2.metricsCounter()
1874
+ ], ControlPipeline.prototype, "_usage", void 0);
1875
+ _ts_decorate6([
1876
+ trace2.metricsCounter()
1877
+ ], ControlPipeline.prototype, "_mutations", void 0);
1878
+ _ts_decorate6([
1879
+ trace2.span()
1880
+ ], ControlPipeline.prototype, "_consumePipeline", null);
1881
+ _ts_decorate6([
1882
+ trace2.span()
1883
+ ], ControlPipeline.prototype, "_processMessage", null);
1884
+ ControlPipeline = _ts_decorate6([
1885
+ trace2.resource()
1886
+ ], ControlPipeline);
1822
1887
 
1823
1888
  // packages/core/echo/echo-pipeline/src/space/space.ts
1824
- function _ts_decorate6(decorators, target, key, desc) {
1889
+ function _ts_decorate7(decorators, target, key, desc) {
1825
1890
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1826
1891
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1827
1892
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1947,7 +2012,7 @@ var Space = class Space2 {
1947
2012
  setControlFeed(feed) {
1948
2013
  invariant9(!this._controlFeed, "Control feed already set.", {
1949
2014
  F: __dxlog_file11,
1950
- L: 183,
2015
+ L: 184,
1951
2016
  S: this,
1952
2017
  A: [
1953
2018
  "!this._controlFeed",
@@ -1961,7 +2026,7 @@ var Space = class Space2 {
1961
2026
  setDataFeed(feed) {
1962
2027
  invariant9(!this._dataFeed, "Data feed already set.", {
1963
2028
  F: __dxlog_file11,
1964
- L: 190,
2029
+ L: 191,
1965
2030
  S: this,
1966
2031
  A: [
1967
2032
  "!this._dataFeed",
@@ -1987,7 +2052,7 @@ var Space = class Space2 {
1987
2052
  async open(ctx) {
1988
2053
  log10("opening...", void 0, {
1989
2054
  F: __dxlog_file11,
1990
- L: 212,
2055
+ L: 213,
1991
2056
  S: this,
1992
2057
  C: (f, a) => f(...a)
1993
2058
  });
@@ -2000,7 +2065,7 @@ var Space = class Space2 {
2000
2065
  this._isOpen = true;
2001
2066
  log10("opened", void 0, {
2002
2067
  F: __dxlog_file11,
2003
- L: 223,
2068
+ L: 224,
2004
2069
  S: this,
2005
2070
  C: (f, a) => f(...a)
2006
2071
  });
@@ -2010,7 +2075,7 @@ var Space = class Space2 {
2010
2075
  key: this._key
2011
2076
  }, {
2012
2077
  F: __dxlog_file11,
2013
- L: 228,
2078
+ L: 229,
2014
2079
  S: this,
2015
2080
  C: (f, a) => f(...a)
2016
2081
  });
@@ -2024,7 +2089,7 @@ var Space = class Space2 {
2024
2089
  this._isOpen = false;
2025
2090
  log10("closed", void 0, {
2026
2091
  F: __dxlog_file11,
2027
- L: 241,
2092
+ L: 242,
2028
2093
  S: this,
2029
2094
  C: (f, a) => f(...a)
2030
2095
  });
@@ -2032,13 +2097,13 @@ var Space = class Space2 {
2032
2097
  async initializeDataPipeline() {
2033
2098
  log10("initializeDataPipeline", void 0, {
2034
2099
  F: __dxlog_file11,
2035
- L: 246,
2100
+ L: 247,
2036
2101
  S: this,
2037
2102
  C: (f, a) => f(...a)
2038
2103
  });
2039
2104
  invariant9(this._isOpen, "Space must be open to initialize data pipeline.", {
2040
2105
  F: __dxlog_file11,
2041
- L: 247,
2106
+ L: 248,
2042
2107
  S: this,
2043
2108
  A: [
2044
2109
  "this._isOpen",
@@ -2048,22 +2113,23 @@ var Space = class Space2 {
2048
2113
  await this._dataPipeline.open();
2049
2114
  }
2050
2115
  };
2051
- _ts_decorate6([
2052
- logInfo
2116
+ _ts_decorate7([
2117
+ logInfo,
2118
+ trace3.info()
2053
2119
  ], Space.prototype, "key", null);
2054
- _ts_decorate6([
2120
+ _ts_decorate7([
2055
2121
  synchronized4,
2056
- trace.span()
2122
+ trace3.span()
2057
2123
  ], Space.prototype, "open", null);
2058
- _ts_decorate6([
2124
+ _ts_decorate7([
2059
2125
  synchronized4
2060
2126
  ], Space.prototype, "close", null);
2061
- _ts_decorate6([
2127
+ _ts_decorate7([
2062
2128
  synchronized4
2063
2129
  ], Space.prototype, "initializeDataPipeline", null);
2064
- Space = _ts_decorate6([
2130
+ Space = _ts_decorate7([
2065
2131
  trackLeaks3("open", "close"),
2066
- trace.resource()
2132
+ trace3.resource()
2067
2133
  ], Space);
2068
2134
 
2069
2135
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
@@ -2075,7 +2141,7 @@ import { Teleport } from "@dxos/teleport";
2075
2141
  import { BlobSync } from "@dxos/teleport-extension-object-sync";
2076
2142
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
2077
2143
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
2078
- function _ts_decorate7(decorators, target, key, desc) {
2144
+ function _ts_decorate8(decorators, target, key, desc) {
2079
2145
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2080
2146
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2081
2147
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2192,10 +2258,10 @@ var SpaceProtocol = class {
2192
2258
  };
2193
2259
  }
2194
2260
  };
2195
- _ts_decorate7([
2261
+ _ts_decorate8([
2196
2262
  logInfo2
2197
2263
  ], SpaceProtocol.prototype, "_topic", void 0);
2198
- _ts_decorate7([
2264
+ _ts_decorate8([
2199
2265
  logInfo2
2200
2266
  ], SpaceProtocol.prototype, "_ownPeerKey", null);
2201
2267
  var AuthStatus;
@@ -2255,10 +2321,10 @@ var SpaceProtocolSession = class {
2255
2321
  await this._teleport.close();
2256
2322
  }
2257
2323
  };
2258
- _ts_decorate7([
2324
+ _ts_decorate8([
2259
2325
  logInfo2
2260
2326
  ], SpaceProtocolSession.prototype, "_wireParams", void 0);
2261
- _ts_decorate7([
2327
+ _ts_decorate8([
2262
2328
  logInfo2
2263
2329
  ], SpaceProtocolSession.prototype, "authStatus", null);
2264
2330
 
@@ -2267,9 +2333,9 @@ import { synchronized as synchronized5, trackLeaks as trackLeaks4 } from "@dxos/
2267
2333
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2268
2334
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2269
2335
  import { log as log12 } from "@dxos/log";
2270
- import { trace as trace2 } from "@dxos/protocols";
2336
+ import { trace as trace4 } from "@dxos/protocols";
2271
2337
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
2272
- function _ts_decorate8(decorators, target, key, desc) {
2338
+ function _ts_decorate9(decorators, target, key, desc) {
2273
2339
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2274
2340
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2275
2341
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2303,7 +2369,7 @@ var SpaceManager = class SpaceManager2 {
2303
2369
  ].map((space) => space.close()));
2304
2370
  }
2305
2371
  async constructSpace({ metadata, swarmIdentity, onNetworkConnection, onAuthFailure, memberKey }) {
2306
- log12.trace("dxos.echo.space-manager.construct-space", trace2.begin({
2372
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.begin({
2307
2373
  id: this._instanceId
2308
2374
  }), {
2309
2375
  F: __dxlog_file13,
@@ -2341,7 +2407,7 @@ var SpaceManager = class SpaceManager2 {
2341
2407
  memberKey
2342
2408
  });
2343
2409
  this._spaces.set(space.key, space);
2344
- log12.trace("dxos.echo.space-manager.construct-space", trace2.end({
2410
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.end({
2345
2411
  id: this._instanceId
2346
2412
  }), {
2347
2413
  F: __dxlog_file13,
@@ -2352,13 +2418,13 @@ var SpaceManager = class SpaceManager2 {
2352
2418
  return space;
2353
2419
  }
2354
2420
  };
2355
- _ts_decorate8([
2421
+ _ts_decorate9([
2356
2422
  synchronized5
2357
2423
  ], SpaceManager.prototype, "open", null);
2358
- _ts_decorate8([
2424
+ _ts_decorate9([
2359
2425
  synchronized5
2360
2426
  ], SpaceManager.prototype, "close", null);
2361
- SpaceManager = _ts_decorate8([
2427
+ SpaceManager = _ts_decorate9([
2362
2428
  trackLeaks4("open", "close")
2363
2429
  ], SpaceManager);
2364
2430
 
@@ -2388,4 +2454,4 @@ export {
2388
2454
  SpaceProtocolSession,
2389
2455
  SpaceManager
2390
2456
  };
2391
- //# sourceMappingURL=chunk-3OTHGQEY.mjs.map
2457
+ //# sourceMappingURL=chunk-FCDYN74V.mjs.map