@dxos/echo-pipeline 0.1.56-main.fd2d497 → 0.1.56-next.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.
Files changed (37) hide show
  1. package/dist/lib/browser/{chunk-M66GL5HD.mjs → chunk-GELWTWOW.mjs} +223 -169
  2. package/dist/lib/browser/chunk-GELWTWOW.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/index.cjs +226 -172
  7. package/dist/lib/node/index.cjs.map +3 -3
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +228 -174
  10. package/dist/lib/node/testing/index.cjs.map +3 -3
  11. package/dist/types/src/db-host/data-service-host.d.ts.map +1 -1
  12. package/dist/types/src/pipeline/pipeline-stress.test.d.ts +2 -0
  13. package/dist/types/src/pipeline/pipeline-stress.test.d.ts.map +1 -0
  14. package/dist/types/src/pipeline/pipeline.d.ts +3 -2
  15. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  16. package/dist/types/src/space/control-pipeline.d.ts +4 -0
  17. package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
  18. package/dist/types/src/space/data-pipeline.d.ts +2 -0
  19. package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
  20. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  21. package/dist/types/src/space/space-protocol.d.ts.map +1 -1
  22. package/dist/types/src/space/space.d.ts.map +1 -1
  23. package/dist/types/src/testing/database-test-rig.d.ts +4 -1
  24. package/dist/types/src/testing/database-test-rig.d.ts.map +1 -1
  25. package/package.json +32 -32
  26. package/src/db-host/data-service-host.ts +9 -2
  27. package/src/pipeline/pipeline-stress.test.ts +226 -0
  28. package/src/pipeline/pipeline.test.ts +2 -214
  29. package/src/pipeline/pipeline.ts +27 -23
  30. package/src/space/control-pipeline.ts +47 -22
  31. package/src/space/data-pipeline.ts +18 -9
  32. package/src/space/space-manager.ts +1 -0
  33. package/src/space/space-protocol.ts +3 -1
  34. package/src/space/space.ts +1 -0
  35. package/src/testing/database-test-rig.ts +27 -2
  36. package/src/tests/database-unit.test.ts +39 -0
  37. package/dist/lib/browser/chunk-M66GL5HD.mjs.map +0 -7
@@ -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",
@@ -78,11 +87,11 @@ var DataServiceHost = class {
78
87
  ]
79
88
  });
80
89
  log("message", {
81
- batch,
90
+ batch: batch.objects?.length,
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, getPrototypeSpecificInstanceId } from "@dxos/util";
728
+ import { ComplexMap as ComplexMap3 } 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";
@@ -867,6 +876,8 @@ var Pipeline = class {
867
876
  // Waits for the message consumer to process the message and yield control back to the pipeline.
868
877
  this._processingTrigger = new Trigger().wake();
869
878
  this._pauseTrigger = new Trigger().wake();
879
+ // Pending downloads.
880
+ this._downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
870
881
  this._isStopping = false;
871
882
  this._isStarted = false;
872
883
  this._isBeingConsumed = false;
@@ -878,7 +889,7 @@ var Pipeline = class {
878
889
  get writer() {
879
890
  invariant6(this._writer, "Writer not set.", {
880
891
  F: __dxlog_file7,
881
- L: 230,
892
+ L: 233,
882
893
  S: this,
883
894
  A: [
884
895
  "this._writer",
@@ -907,7 +918,7 @@ var Pipeline = class {
907
918
  setWriteFeed(feed) {
908
919
  invariant6(!this._writer, "Writer already set.", {
909
920
  F: __dxlog_file7,
910
- L: 257,
921
+ L: 260,
911
922
  S: this,
912
923
  A: [
913
924
  "!this._writer",
@@ -916,7 +927,7 @@ var Pipeline = class {
916
927
  });
917
928
  invariant6(feed.properties.writable, "Feed must be writable.", {
918
929
  F: __dxlog_file7,
919
- L: 258,
930
+ L: 261,
920
931
  S: this,
921
932
  A: [
922
933
  "feed.properties.writable",
@@ -931,7 +942,7 @@ var Pipeline = class {
931
942
  async start() {
932
943
  invariant6(!this._isStarted, "Pipeline is already started.", {
933
944
  F: __dxlog_file7,
934
- L: 271,
945
+ L: 274,
935
946
  S: this,
936
947
  A: [
937
948
  "!this._isStarted",
@@ -940,7 +951,7 @@ var Pipeline = class {
940
951
  });
941
952
  log6("starting...", void 0, {
942
953
  F: __dxlog_file7,
943
- L: 272,
954
+ L: 275,
944
955
  S: this,
945
956
  C: (f, a) => f(...a)
946
957
  });
@@ -949,7 +960,7 @@ var Pipeline = class {
949
960
  this._isStarted = true;
950
961
  log6("started", void 0, {
951
962
  F: __dxlog_file7,
952
- L: 276,
963
+ L: 279,
953
964
  S: this,
954
965
  C: (f, a) => f(...a)
955
966
  });
@@ -962,11 +973,15 @@ var Pipeline = class {
962
973
  async stop() {
963
974
  log6("stopping...", void 0, {
964
975
  F: __dxlog_file7,
965
- L: 287,
976
+ L: 290,
966
977
  S: this,
967
978
  C: (f, a) => f(...a)
968
979
  });
969
980
  this._isStopping = true;
981
+ for (const [feed, handle] of this._downloads.entries()) {
982
+ feed.undownload(handle);
983
+ }
984
+ this._downloads.clear();
970
985
  await this._feedSetIterator?.close();
971
986
  await this._processingTrigger.wait();
972
987
  await this._state._ctx.dispose();
@@ -975,7 +990,7 @@ var Pipeline = class {
975
990
  this._isStarted = false;
976
991
  log6("stopped", void 0, {
977
992
  F: __dxlog_file7,
978
- L: 295,
993
+ L: 302,
979
994
  S: this,
980
995
  C: (f, a) => f(...a)
981
996
  });
@@ -987,7 +1002,7 @@ var Pipeline = class {
987
1002
  async setCursor(timeframe) {
988
1003
  invariant6(!this._isStarted || this._isPaused, "Invalid state.", {
989
1004
  F: __dxlog_file7,
990
- L: 304,
1005
+ L: 311,
991
1006
  S: this,
992
1007
  A: [
993
1008
  "!this._isStarted || this._isPaused",
@@ -1016,7 +1031,7 @@ var Pipeline = class {
1016
1031
  async unpause() {
1017
1032
  invariant6(this._isPaused, "Pipeline is not paused.", {
1018
1033
  F: __dxlog_file7,
1019
- L: 334,
1034
+ L: 340,
1020
1035
  S: this,
1021
1036
  A: [
1022
1037
  "this._isPaused",
@@ -1036,7 +1051,7 @@ var Pipeline = class {
1036
1051
  async *consume() {
1037
1052
  invariant6(!this._isBeingConsumed, "Pipeline is already being consumed.", {
1038
1053
  F: __dxlog_file7,
1039
- L: 349,
1054
+ L: 355,
1040
1055
  S: this,
1041
1056
  A: [
1042
1057
  "!this._isBeingConsumed",
@@ -1046,7 +1061,7 @@ var Pipeline = class {
1046
1061
  this._isBeingConsumed = true;
1047
1062
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1048
1063
  F: __dxlog_file7,
1049
- L: 352,
1064
+ L: 358,
1050
1065
  S: this,
1051
1066
  A: [
1052
1067
  "this._feedSetIterator",
@@ -1060,7 +1075,7 @@ var Pipeline = class {
1060
1075
  if (lastFeedSetIterator !== this._feedSetIterator) {
1061
1076
  invariant6(this._feedSetIterator, "Iterator not initialized.", {
1062
1077
  F: __dxlog_file7,
1063
- L: 361,
1078
+ L: 367,
1064
1079
  S: this,
1065
1080
  A: [
1066
1081
  "this._feedSetIterator",
@@ -1083,45 +1098,39 @@ var Pipeline = class {
1083
1098
  this._isBeingConsumed = false;
1084
1099
  }
1085
1100
  _setFeedDownloadState(feed) {
1101
+ let handle = this._downloads.get(feed);
1102
+ if (handle) {
1103
+ feed.undownload(handle);
1104
+ }
1086
1105
  const timeframe = this._state._startTimeframe;
1087
1106
  const seq = timeframe.get(feed.key) ?? -1;
1088
- log6.info("setFeedDownloadState", {
1089
- feed: feed.key,
1090
- feedInstance: getPrototypeSpecificInstanceId(feed),
1107
+ log6("download", {
1108
+ feed: feed.key.truncate(),
1091
1109
  seq,
1092
- isBeingConsumed: this._isBeingConsumed,
1093
- isStarted: this._isStarted,
1094
- isPaused: this._isPaused
1110
+ length: feed.length
1095
1111
  }, {
1096
1112
  F: __dxlog_file7,
1097
- L: 386,
1113
+ L: 396,
1098
1114
  S: this,
1099
1115
  C: (f, a) => f(...a)
1100
1116
  });
1101
- if (!this._isStarted || this._isPaused) {
1102
- console.log(new Error().stack);
1103
- }
1104
- feed.undownload({
1105
- callback: () => log6("undownload", void 0, {
1106
- F: __dxlog_file7,
1107
- L: 398,
1108
- S: this,
1109
- C: (f, a) => f(...a)
1110
- })
1111
- });
1112
- feed.download({
1117
+ handle = feed.download({
1113
1118
  start: seq + 1,
1114
1119
  linear: true
1115
- }).catch((err) => {
1116
- log6("failed to download feed", {
1117
- err
1118
- }, {
1119
- F: __dxlog_file7,
1120
- L: 400,
1121
- S: this,
1122
- C: (f, a) => f(...a)
1123
- });
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
+ }
1124
1132
  });
1133
+ this._downloads.set(feed, handle);
1125
1134
  }
1126
1135
  async _initIterator() {
1127
1136
  this._feedSetIterator = new FeedSetIterator(createMessageSelector(this._timeframeClock), {
@@ -1131,7 +1140,7 @@ var Pipeline = class {
1131
1140
  this._feedSetIterator.stalled.on((iterator) => {
1132
1141
  log6.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
1133
1142
  F: __dxlog_file7,
1134
- L: 411,
1143
+ L: 415,
1135
1144
  S: this,
1136
1145
  C: (f, a) => f(...a)
1137
1146
  });
@@ -1265,11 +1274,12 @@ var AuthExtension = class extends RpcExtension {
1265
1274
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1266
1275
  import { Context as Context4 } from "@dxos/context";
1267
1276
  import { checkCredentialType } from "@dxos/credentials";
1268
- import { getStateMachineFromItem, ItemManager } from "@dxos/echo-db";
1277
+ import { getStateMachineFromItem, ItemManager, TYPE_PROPERTIES } from "@dxos/echo-db";
1269
1278
  import { CancelledError } from "@dxos/errors";
1270
1279
  import { invariant as invariant8 } from "@dxos/invariant";
1271
- import { log as log8 } from "@dxos/log";
1280
+ import { log as log8, omit } from "@dxos/log";
1272
1281
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1282
+ import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1273
1283
  import { tracer } from "@dxos/util";
1274
1284
  function _ts_decorate5(decorators, target, key, desc) {
1275
1285
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1296,6 +1306,8 @@ var DataPipeline = class DataPipeline2 {
1296
1306
  this._lastTimeframeSaveTime = 0;
1297
1307
  this._lastSnapshotSaveTime = 0;
1298
1308
  this._lastProcessedEpoch = -1;
1309
+ this._usage = new TimeUsageCounter();
1310
+ this._mutations = new TimeSeriesCounter();
1299
1311
  this.currentEpoch = void 0;
1300
1312
  this.appliedEpoch = void 0;
1301
1313
  this.onNewEpoch = new Event4();
@@ -1337,7 +1349,7 @@ var DataPipeline = class DataPipeline2 {
1337
1349
  write: (data, options) => {
1338
1350
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1339
1351
  F: __dxlog_file9,
1340
- L: 146,
1352
+ L: 154,
1341
1353
  S: this,
1342
1354
  A: [
1343
1355
  "this._pipeline",
@@ -1346,7 +1358,7 @@ var DataPipeline = class DataPipeline2 {
1346
1358
  });
1347
1359
  invariant8(this.currentEpoch, "Epoch is not initialized.", {
1348
1360
  F: __dxlog_file9,
1349
- L: 147,
1361
+ L: 155,
1350
1362
  S: this,
1351
1363
  A: [
1352
1364
  "this.currentEpoch",
@@ -1372,7 +1384,7 @@ var DataPipeline = class DataPipeline2 {
1372
1384
  }
1373
1385
  log8("close", void 0, {
1374
1386
  F: __dxlog_file9,
1375
- L: 171,
1387
+ L: 179,
1376
1388
  S: this,
1377
1389
  C: (f, a) => f(...a)
1378
1390
  });
@@ -1387,7 +1399,7 @@ var DataPipeline = class DataPipeline2 {
1387
1399
  } catch (err) {
1388
1400
  log8.catch(err, void 0, {
1389
1401
  F: __dxlog_file9,
1390
- L: 184,
1402
+ L: 192,
1391
1403
  S: this,
1392
1404
  C: (f, a) => f(...a)
1393
1405
  });
@@ -1411,7 +1423,7 @@ var DataPipeline = class DataPipeline2 {
1411
1423
  }
1412
1424
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1413
1425
  F: __dxlog_file9,
1414
- L: 207,
1426
+ L: 215,
1415
1427
  S: this,
1416
1428
  A: [
1417
1429
  "this._pipeline",
@@ -1419,13 +1431,15 @@ var DataPipeline = class DataPipeline2 {
1419
1431
  ]
1420
1432
  });
1421
1433
  for await (const msg of this._pipeline.consume()) {
1434
+ const span = this._usage.beginRecording();
1435
+ this._mutations.inc();
1422
1436
  const { feedKey, seq, data } = msg;
1423
1437
  log8("processing message", {
1424
1438
  feedKey,
1425
1439
  seq
1426
1440
  }, {
1427
1441
  F: __dxlog_file9,
1428
- L: 210,
1442
+ L: 221,
1429
1443
  S: this,
1430
1444
  C: (f, a) => f(...a)
1431
1445
  });
@@ -1437,7 +1451,7 @@ var DataPipeline = class DataPipeline2 {
1437
1451
  feedKey
1438
1452
  }, {
1439
1453
  F: __dxlog_file9,
1440
- L: 216,
1454
+ L: 227,
1441
1455
  S: this,
1442
1456
  C: (f, a) => f(...a)
1443
1457
  });
@@ -1460,7 +1474,7 @@ var DataPipeline = class DataPipeline2 {
1460
1474
  spaceKey: this._params.spaceKey.toHex()
1461
1475
  }, {
1462
1476
  F: __dxlog_file9,
1463
- L: 233,
1477
+ L: 244,
1464
1478
  S: this,
1465
1479
  C: (f, a) => f(...a)
1466
1480
  });
@@ -1469,17 +1483,18 @@ var DataPipeline = class DataPipeline2 {
1469
1483
  } catch (err) {
1470
1484
  log8.catch(err, void 0, {
1471
1485
  F: __dxlog_file9,
1472
- L: 243,
1486
+ L: 254,
1473
1487
  S: this,
1474
1488
  C: (f, a) => f(...a)
1475
1489
  });
1476
1490
  }
1491
+ span.end();
1477
1492
  }
1478
1493
  }
1479
1494
  _createSnapshot() {
1480
1495
  invariant8(this.databaseHost, "Database backend is not initialized.", {
1481
1496
  F: __dxlog_file9,
1482
- L: 249,
1497
+ L: 262,
1483
1498
  S: this,
1484
1499
  A: [
1485
1500
  "this.databaseHost",
@@ -1501,14 +1516,14 @@ var DataPipeline = class DataPipeline2 {
1501
1516
  const cache = {};
1502
1517
  try {
1503
1518
  const propertiesItem = this.itemManager.items.find((item) => item.modelMeta?.type === "dxos:model/document" && // TODO(burdon): Document?
1504
- (getStateMachineFromItem(item)?.snapshot()).type === "dxos.sdk.client.Properties");
1519
+ (getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
1505
1520
  if (propertiesItem) {
1506
1521
  cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
1507
1522
  }
1508
1523
  } catch (err) {
1509
1524
  log8.warn("Failed to cache properties", err, {
1510
1525
  F: __dxlog_file9,
1511
- L: 278,
1526
+ L: 291,
1512
1527
  S: this,
1513
1528
  C: (f, a) => f(...a)
1514
1529
  });
@@ -1534,14 +1549,14 @@ var DataPipeline = class DataPipeline2 {
1534
1549
  if (err instanceof CancelledError) {
1535
1550
  log8("Epoch processing cancelled.", void 0, {
1536
1551
  F: __dxlog_file9,
1537
- L: 310,
1552
+ L: 323,
1538
1553
  S: this,
1539
1554
  C: (f, a) => f(...a)
1540
1555
  });
1541
1556
  } else {
1542
1557
  log8.catch(err, void 0, {
1543
1558
  F: __dxlog_file9,
1544
- L: 312,
1559
+ L: 325,
1545
1560
  S: this,
1546
1561
  C: (f, a) => f(...a)
1547
1562
  });
@@ -1553,14 +1568,6 @@ var DataPipeline = class DataPipeline2 {
1553
1568
  if (!this._isOpen) {
1554
1569
  return;
1555
1570
  }
1556
- log8("process epoch", {
1557
- epoch
1558
- }, {
1559
- F: __dxlog_file9,
1560
- L: 322,
1561
- S: this,
1562
- C: (f, a) => f(...a)
1563
- });
1564
1571
  await this._processEpoch(ctx, epoch.subject.assertion);
1565
1572
  this.appliedEpoch = epoch;
1566
1573
  this.onNewEpoch.emit(epoch);
@@ -1569,7 +1576,7 @@ var DataPipeline = class DataPipeline2 {
1569
1576
  async _processEpoch(ctx, epoch) {
1570
1577
  invariant8(this._isOpen, "Space is closed.", {
1571
1578
  F: __dxlog_file9,
1572
- L: 332,
1579
+ L: 344,
1573
1580
  S: this,
1574
1581
  A: [
1575
1582
  "this._isOpen",
@@ -1578,7 +1585,7 @@ var DataPipeline = class DataPipeline2 {
1578
1585
  });
1579
1586
  invariant8(this._pipeline, void 0, {
1580
1587
  F: __dxlog_file9,
1581
- L: 333,
1588
+ L: 345,
1582
1589
  S: this,
1583
1590
  A: [
1584
1591
  "this._pipeline",
@@ -1586,11 +1593,11 @@ var DataPipeline = class DataPipeline2 {
1586
1593
  ]
1587
1594
  });
1588
1595
  this._lastProcessedEpoch = epoch.number;
1589
- log8("Processing epoch", {
1590
- epoch
1596
+ log8("processing", {
1597
+ epoch: omit(epoch, "proof")
1591
1598
  }, {
1592
1599
  F: __dxlog_file9,
1593
- L: 336,
1600
+ L: 348,
1594
1601
  S: this,
1595
1602
  C: (f, a) => f(...a)
1596
1603
  });
@@ -1598,9 +1605,9 @@ var DataPipeline = class DataPipeline2 {
1598
1605
  const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
1599
1606
  this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
1600
1607
  }
1601
- log8("restarting pipeline for epoch", void 0, {
1608
+ log8("restarting pipeline from epoch", void 0, {
1602
1609
  F: __dxlog_file9,
1603
- L: 344,
1610
+ L: 354,
1604
1611
  S: this,
1605
1612
  C: (f, a) => f(...a)
1606
1613
  });
@@ -1611,7 +1618,7 @@ var DataPipeline = class DataPipeline2 {
1611
1618
  async waitUntilTimeframe(timeframe) {
1612
1619
  invariant8(this._pipeline, "Pipeline is not initialized.", {
1613
1620
  F: __dxlog_file9,
1614
- L: 352,
1621
+ L: 361,
1615
1622
  S: this,
1616
1623
  A: [
1617
1624
  "this._pipeline",
@@ -1623,7 +1630,7 @@ var DataPipeline = class DataPipeline2 {
1623
1630
  async createEpoch() {
1624
1631
  invariant8(this._pipeline, void 0, {
1625
1632
  F: __dxlog_file9,
1626
- L: 358,
1633
+ L: 367,
1627
1634
  S: this,
1628
1635
  A: [
1629
1636
  "this._pipeline",
@@ -1632,7 +1639,7 @@ var DataPipeline = class DataPipeline2 {
1632
1639
  });
1633
1640
  invariant8(this.currentEpoch, void 0, {
1634
1641
  F: __dxlog_file9,
1635
- L: 359,
1642
+ L: 368,
1636
1643
  S: this,
1637
1644
  A: [
1638
1645
  "this.currentEpoch",
@@ -1655,6 +1662,12 @@ var DataPipeline = class DataPipeline2 {
1655
1662
  await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
1656
1663
  }
1657
1664
  };
1665
+ _ts_decorate5([
1666
+ trace.metricsCounter()
1667
+ ], DataPipeline.prototype, "_usage", void 0);
1668
+ _ts_decorate5([
1669
+ trace.metricsCounter()
1670
+ ], DataPipeline.prototype, "_mutations", void 0);
1658
1671
  _ts_decorate5([
1659
1672
  synchronized3
1660
1673
  ], DataPipeline.prototype, "open", null);
@@ -1668,7 +1681,8 @@ _ts_decorate5([
1668
1681
  synchronized3
1669
1682
  ], DataPipeline.prototype, "createEpoch", null);
1670
1683
  DataPipeline = _ts_decorate5([
1671
- trackLeaks2("open", "close")
1684
+ trackLeaks2("open", "close"),
1685
+ trace.resource()
1672
1686
  ], DataPipeline);
1673
1687
 
1674
1688
  // packages/core/echo/echo-pipeline/src/space/space.ts
@@ -1676,22 +1690,36 @@ import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeak
1676
1690
  import { invariant as invariant9 } from "@dxos/invariant";
1677
1691
  import { log as log10, logInfo } from "@dxos/log";
1678
1692
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
1679
- import { trace } from "@dxos/tracing";
1693
+ import { trace as trace3 } from "@dxos/tracing";
1680
1694
  import { Callback as Callback2 } from "@dxos/util";
1681
1695
 
1682
1696
  // packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
1697
+ import { Context as Context5 } from "@dxos/context";
1683
1698
  import { SpaceStateMachine } from "@dxos/credentials";
1684
1699
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1685
1700
  import { log as log9 } from "@dxos/log";
1686
1701
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1687
1702
  import { Timeframe as Timeframe4 } from "@dxos/timeframe";
1703
+ import { TimeSeriesCounter as TimeSeriesCounter2, TimeUsageCounter as TimeUsageCounter2, trace as trace2 } from "@dxos/tracing";
1688
1704
  import { Callback, tracer as tracer2 } from "@dxos/util";
1705
+ function _ts_decorate6(decorators, target, key, desc) {
1706
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1707
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1708
+ r = Reflect.decorate(decorators, target, key, desc);
1709
+ else
1710
+ for (var i = decorators.length - 1; i >= 0; i--)
1711
+ if (d = decorators[i])
1712
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1713
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1714
+ }
1689
1715
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1690
1716
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
1691
- var ControlPipeline = class {
1717
+ var ControlPipeline = class ControlPipeline2 {
1692
1718
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1693
1719
  this._lastTimeframeSaveTime = Date.now();
1694
1720
  this.onFeedAdmitted = new Callback();
1721
+ this._usage = new TimeUsageCounter2();
1722
+ this._mutations = new TimeSeriesCounter2();
1695
1723
  this._spaceKey = spaceKey;
1696
1724
  this._metadata = metadataStore;
1697
1725
  this._pipeline = new Pipeline();
@@ -1702,7 +1730,7 @@ var ControlPipeline = class {
1702
1730
  key: info.key
1703
1731
  }, {
1704
1732
  F: __dxlog_file10,
1705
- L: 51,
1733
+ L: 61,
1706
1734
  S: this,
1707
1735
  C: (f, a) => f(...a)
1708
1736
  });
@@ -1713,7 +1741,7 @@ var ControlPipeline = class {
1713
1741
  } catch (err) {
1714
1742
  log9.catch(err, void 0, {
1715
1743
  F: __dxlog_file10,
1716
- L: 59,
1744
+ L: 69,
1717
1745
  S: this,
1718
1746
  C: (f, a) => f(...a)
1719
1747
  });
@@ -1736,56 +1764,65 @@ var ControlPipeline = class {
1736
1764
  async start() {
1737
1765
  log9("starting...", void 0, {
1738
1766
  F: __dxlog_file10,
1739
- L: 83,
1767
+ L: 93,
1740
1768
  S: this,
1741
1769
  C: (f, a) => f(...a)
1742
1770
  });
1743
1771
  setTimeout(async () => {
1744
- for await (const msg of this._pipeline.consume()) {
1745
- try {
1746
- log9("processing", {
1747
- key: msg.feedKey,
1748
- seq: msg.seq
1749
- }, {
1750
- F: __dxlog_file10,
1751
- L: 88,
1752
- S: this,
1753
- C: (f, a) => f(...a)
1754
- });
1755
- if (msg.data.payload.credential) {
1756
- const timer = tracer2.mark("dxos.echo.pipeline.control");
1757
- const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1758
- timer.end();
1759
- if (!result) {
1760
- log9.warn("processing failed", {
1761
- msg
1762
- }, {
1763
- F: __dxlog_file10,
1764
- L: 98,
1765
- S: this,
1766
- C: (f, a) => f(...a)
1767
- });
1768
- } else {
1769
- await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1770
- }
1771
- }
1772
- } catch (err) {
1773
- log9.catch(err, void 0, {
1774
- F: __dxlog_file10,
1775
- L: 104,
1776
- S: this,
1777
- C: (f, a) => f(...a)
1778
- });
1779
- }
1780
- }
1772
+ void this._consumePipeline(new Context5());
1781
1773
  });
1782
1774
  await this._pipeline.start();
1783
1775
  log9("started", void 0, {
1784
1776
  F: __dxlog_file10,
1785
- L: 110,
1777
+ L: 99,
1778
+ S: this,
1779
+ C: (f, a) => f(...a)
1780
+ });
1781
+ }
1782
+ async _consumePipeline(ctx) {
1783
+ for await (const msg of this._pipeline.consume()) {
1784
+ const span = this._usage.beginRecording();
1785
+ this._mutations.inc();
1786
+ try {
1787
+ await this._processMessage(ctx, msg);
1788
+ } catch (err) {
1789
+ log9.catch(err, void 0, {
1790
+ F: __dxlog_file10,
1791
+ L: 111,
1792
+ S: this,
1793
+ C: (f, a) => f(...a)
1794
+ });
1795
+ }
1796
+ span.end();
1797
+ }
1798
+ }
1799
+ async _processMessage(ctx, msg) {
1800
+ log9("processing", {
1801
+ key: msg.feedKey,
1802
+ seq: msg.seq
1803
+ }, {
1804
+ F: __dxlog_file10,
1805
+ L: 121,
1786
1806
  S: this,
1787
1807
  C: (f, a) => f(...a)
1788
1808
  });
1809
+ if (msg.data.payload.credential) {
1810
+ const timer = tracer2.mark("dxos.echo.pipeline.control");
1811
+ const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1812
+ timer.end();
1813
+ if (!result) {
1814
+ log9.warn("processing failed", {
1815
+ msg
1816
+ }, {
1817
+ F: __dxlog_file10,
1818
+ L: 131,
1819
+ S: this,
1820
+ C: (f, a) => f(...a)
1821
+ });
1822
+ } else {
1823
+ await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1824
+ }
1825
+ }
1789
1826
  }
1790
1827
  async _noteTargetStateIfNeeded(timeframe) {
1791
1828
  if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2) {
@@ -1796,7 +1833,7 @@ var ControlPipeline = class {
1796
1833
  async stop() {
1797
1834
  log9("stopping...", void 0, {
1798
1835
  F: __dxlog_file10,
1799
- L: 124,
1836
+ L: 149,
1800
1837
  S: this,
1801
1838
  C: (f, a) => f(...a)
1802
1839
  });
@@ -1804,7 +1841,7 @@ var ControlPipeline = class {
1804
1841
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1805
1842
  log9("stopped", void 0, {
1806
1843
  F: __dxlog_file10,
1807
- L: 127,
1844
+ L: 152,
1808
1845
  S: this,
1809
1846
  C: (f, a) => f(...a)
1810
1847
  });
@@ -1817,16 +1854,31 @@ var ControlPipeline = class {
1817
1854
  } catch (err) {
1818
1855
  log9(err, void 0, {
1819
1856
  F: __dxlog_file10,
1820
- L: 136,
1857
+ L: 161,
1821
1858
  S: this,
1822
1859
  C: (f, a) => f(...a)
1823
1860
  });
1824
1861
  }
1825
1862
  }
1826
1863
  };
1864
+ _ts_decorate6([
1865
+ trace2.metricsCounter()
1866
+ ], ControlPipeline.prototype, "_usage", void 0);
1867
+ _ts_decorate6([
1868
+ trace2.metricsCounter()
1869
+ ], ControlPipeline.prototype, "_mutations", void 0);
1870
+ _ts_decorate6([
1871
+ trace2.span()
1872
+ ], ControlPipeline.prototype, "_consumePipeline", null);
1873
+ _ts_decorate6([
1874
+ trace2.span()
1875
+ ], ControlPipeline.prototype, "_processMessage", null);
1876
+ ControlPipeline = _ts_decorate6([
1877
+ trace2.resource()
1878
+ ], ControlPipeline);
1827
1879
 
1828
1880
  // packages/core/echo/echo-pipeline/src/space/space.ts
1829
- function _ts_decorate6(decorators, target, key, desc) {
1881
+ function _ts_decorate7(decorators, target, key, desc) {
1830
1882
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1831
1883
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1832
1884
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1952,7 +2004,7 @@ var Space = class Space2 {
1952
2004
  setControlFeed(feed) {
1953
2005
  invariant9(!this._controlFeed, "Control feed already set.", {
1954
2006
  F: __dxlog_file11,
1955
- L: 183,
2007
+ L: 184,
1956
2008
  S: this,
1957
2009
  A: [
1958
2010
  "!this._controlFeed",
@@ -1966,7 +2018,7 @@ var Space = class Space2 {
1966
2018
  setDataFeed(feed) {
1967
2019
  invariant9(!this._dataFeed, "Data feed already set.", {
1968
2020
  F: __dxlog_file11,
1969
- L: 190,
2021
+ L: 191,
1970
2022
  S: this,
1971
2023
  A: [
1972
2024
  "!this._dataFeed",
@@ -1992,7 +2044,7 @@ var Space = class Space2 {
1992
2044
  async open(ctx) {
1993
2045
  log10("opening...", void 0, {
1994
2046
  F: __dxlog_file11,
1995
- L: 212,
2047
+ L: 213,
1996
2048
  S: this,
1997
2049
  C: (f, a) => f(...a)
1998
2050
  });
@@ -2005,7 +2057,7 @@ var Space = class Space2 {
2005
2057
  this._isOpen = true;
2006
2058
  log10("opened", void 0, {
2007
2059
  F: __dxlog_file11,
2008
- L: 223,
2060
+ L: 224,
2009
2061
  S: this,
2010
2062
  C: (f, a) => f(...a)
2011
2063
  });
@@ -2015,7 +2067,7 @@ var Space = class Space2 {
2015
2067
  key: this._key
2016
2068
  }, {
2017
2069
  F: __dxlog_file11,
2018
- L: 228,
2070
+ L: 229,
2019
2071
  S: this,
2020
2072
  C: (f, a) => f(...a)
2021
2073
  });
@@ -2029,7 +2081,7 @@ var Space = class Space2 {
2029
2081
  this._isOpen = false;
2030
2082
  log10("closed", void 0, {
2031
2083
  F: __dxlog_file11,
2032
- L: 241,
2084
+ L: 242,
2033
2085
  S: this,
2034
2086
  C: (f, a) => f(...a)
2035
2087
  });
@@ -2037,13 +2089,13 @@ var Space = class Space2 {
2037
2089
  async initializeDataPipeline() {
2038
2090
  log10("initializeDataPipeline", void 0, {
2039
2091
  F: __dxlog_file11,
2040
- L: 246,
2092
+ L: 247,
2041
2093
  S: this,
2042
2094
  C: (f, a) => f(...a)
2043
2095
  });
2044
2096
  invariant9(this._isOpen, "Space must be open to initialize data pipeline.", {
2045
2097
  F: __dxlog_file11,
2046
- L: 247,
2098
+ L: 248,
2047
2099
  S: this,
2048
2100
  A: [
2049
2101
  "this._isOpen",
@@ -2053,22 +2105,23 @@ var Space = class Space2 {
2053
2105
  await this._dataPipeline.open();
2054
2106
  }
2055
2107
  };
2056
- _ts_decorate6([
2057
- logInfo
2108
+ _ts_decorate7([
2109
+ logInfo,
2110
+ trace3.info()
2058
2111
  ], Space.prototype, "key", null);
2059
- _ts_decorate6([
2112
+ _ts_decorate7([
2060
2113
  synchronized4,
2061
- trace.span()
2114
+ trace3.span()
2062
2115
  ], Space.prototype, "open", null);
2063
- _ts_decorate6([
2116
+ _ts_decorate7([
2064
2117
  synchronized4
2065
2118
  ], Space.prototype, "close", null);
2066
- _ts_decorate6([
2119
+ _ts_decorate7([
2067
2120
  synchronized4
2068
2121
  ], Space.prototype, "initializeDataPipeline", null);
2069
- Space = _ts_decorate6([
2122
+ Space = _ts_decorate7([
2070
2123
  trackLeaks3("open", "close"),
2071
- trace.resource()
2124
+ trace3.resource()
2072
2125
  ], Space);
2073
2126
 
2074
2127
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
@@ -2080,7 +2133,7 @@ import { Teleport } from "@dxos/teleport";
2080
2133
  import { BlobSync } from "@dxos/teleport-extension-object-sync";
2081
2134
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
2082
2135
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
2083
- function _ts_decorate7(decorators, target, key, desc) {
2136
+ function _ts_decorate8(decorators, target, key, desc) {
2084
2137
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2085
2138
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2086
2139
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2121,7 +2174,7 @@ var SpaceProtocol = class {
2121
2174
  key: feed.key
2122
2175
  }, {
2123
2176
  F: __dxlog_file12,
2124
- L: 95,
2177
+ L: 96,
2125
2178
  S: this,
2126
2179
  C: (f, a) => f(...a)
2127
2180
  });
@@ -2130,6 +2183,7 @@ var SpaceProtocol = class {
2130
2183
  session.replicator.addFeed(feed);
2131
2184
  }
2132
2185
  }
2186
+ // TODO(burdon): Rename open? Common open/close interfaces for all services?
2133
2187
  async start() {
2134
2188
  if (this._connection) {
2135
2189
  return;
@@ -2143,7 +2197,7 @@ var SpaceProtocol = class {
2143
2197
  await this.blobSync.open();
2144
2198
  log11("starting...", void 0, {
2145
2199
  F: __dxlog_file12,
2146
- L: 120,
2200
+ L: 122,
2147
2201
  S: this,
2148
2202
  C: (f, a) => f(...a)
2149
2203
  });
@@ -2153,11 +2207,11 @@ var SpaceProtocol = class {
2153
2207
  peerId: this._swarmIdentity.peerKey,
2154
2208
  topic,
2155
2209
  topology: new MMSTTopology(topologyConfig),
2156
- label: `Protocol swarm: ${topic}`
2210
+ label: `space swarm ${topic.truncate()}`
2157
2211
  });
2158
2212
  log11("started", void 0, {
2159
2213
  F: __dxlog_file12,
2160
- L: 130,
2214
+ L: 132,
2161
2215
  S: this,
2162
2216
  C: (f, a) => f(...a)
2163
2217
  });
@@ -2167,14 +2221,14 @@ var SpaceProtocol = class {
2167
2221
  if (this._connection) {
2168
2222
  log11("stopping...", void 0, {
2169
2223
  F: __dxlog_file12,
2170
- L: 137,
2224
+ L: 139,
2171
2225
  S: this,
2172
2226
  C: (f, a) => f(...a)
2173
2227
  });
2174
2228
  await this._connection.close();
2175
2229
  log11("stopped", void 0, {
2176
2230
  F: __dxlog_file12,
2177
- L: 139,
2231
+ L: 141,
2178
2232
  S: this,
2179
2233
  C: (f, a) => f(...a)
2180
2234
  });
@@ -2197,10 +2251,10 @@ var SpaceProtocol = class {
2197
2251
  };
2198
2252
  }
2199
2253
  };
2200
- _ts_decorate7([
2254
+ _ts_decorate8([
2201
2255
  logInfo2
2202
2256
  ], SpaceProtocol.prototype, "_topic", void 0);
2203
- _ts_decorate7([
2257
+ _ts_decorate8([
2204
2258
  logInfo2
2205
2259
  ], SpaceProtocol.prototype, "_ownPeerKey", null);
2206
2260
  var AuthStatus;
@@ -2241,7 +2295,7 @@ var SpaceProtocolSession = class {
2241
2295
  onAuthSuccess: () => {
2242
2296
  log11("Peer authenticated", void 0, {
2243
2297
  F: __dxlog_file12,
2244
- L: 236,
2298
+ L: 238,
2245
2299
  S: this,
2246
2300
  C: (f, a) => f(...a)
2247
2301
  });
@@ -2260,10 +2314,10 @@ var SpaceProtocolSession = class {
2260
2314
  await this._teleport.close();
2261
2315
  }
2262
2316
  };
2263
- _ts_decorate7([
2317
+ _ts_decorate8([
2264
2318
  logInfo2
2265
2319
  ], SpaceProtocolSession.prototype, "_wireParams", void 0);
2266
- _ts_decorate7([
2320
+ _ts_decorate8([
2267
2321
  logInfo2
2268
2322
  ], SpaceProtocolSession.prototype, "authStatus", null);
2269
2323
 
@@ -2272,9 +2326,9 @@ import { synchronized as synchronized5, trackLeaks as trackLeaks4 } from "@dxos/
2272
2326
  import { failUndefined as failUndefined2 } from "@dxos/debug";
2273
2327
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2274
2328
  import { log as log12 } from "@dxos/log";
2275
- import { trace as trace2 } from "@dxos/protocols";
2329
+ import { trace as trace4 } from "@dxos/protocols";
2276
2330
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
2277
- function _ts_decorate8(decorators, target, key, desc) {
2331
+ function _ts_decorate9(decorators, target, key, desc) {
2278
2332
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2279
2333
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2280
2334
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2308,7 +2362,7 @@ var SpaceManager = class SpaceManager2 {
2308
2362
  ].map((space) => space.close()));
2309
2363
  }
2310
2364
  async constructSpace({ metadata, swarmIdentity, onNetworkConnection, onAuthFailure, memberKey }) {
2311
- log12.trace("dxos.echo.space-manager.construct-space", trace2.begin({
2365
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.begin({
2312
2366
  id: this._instanceId
2313
2367
  }), {
2314
2368
  F: __dxlog_file13,
@@ -2346,24 +2400,24 @@ var SpaceManager = class SpaceManager2 {
2346
2400
  memberKey
2347
2401
  });
2348
2402
  this._spaces.set(space.key, space);
2349
- log12.trace("dxos.echo.space-manager.construct-space", trace2.end({
2403
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.end({
2350
2404
  id: this._instanceId
2351
2405
  }), {
2352
2406
  F: __dxlog_file13,
2353
- L: 125,
2407
+ L: 126,
2354
2408
  S: this,
2355
2409
  C: (f, a) => f(...a)
2356
2410
  });
2357
2411
  return space;
2358
2412
  }
2359
2413
  };
2360
- _ts_decorate8([
2414
+ _ts_decorate9([
2361
2415
  synchronized5
2362
2416
  ], SpaceManager.prototype, "open", null);
2363
- _ts_decorate8([
2417
+ _ts_decorate9([
2364
2418
  synchronized5
2365
2419
  ], SpaceManager.prototype, "close", null);
2366
- SpaceManager = _ts_decorate8([
2420
+ SpaceManager = _ts_decorate9([
2367
2421
  trackLeaks4("open", "close")
2368
2422
  ], SpaceManager);
2369
2423
 
@@ -2393,4 +2447,4 @@ export {
2393
2447
  SpaceProtocolSession,
2394
2448
  SpaceManager
2395
2449
  };
2396
- //# sourceMappingURL=chunk-M66GL5HD.mjs.map
2450
+ //# sourceMappingURL=chunk-GELWTWOW.mjs.map