@dxos/echo-pipeline 0.1.56-main.e47dfd1 → 0.1.56-main.e79d64a

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 (55) hide show
  1. package/dist/lib/browser/{chunk-7U2NXI2P.mjs → chunk-GDF4DQU2.mjs} +692 -355
  2. package/dist/lib/browser/chunk-GDF4DQU2.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +14 -18
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +699 -362
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +696 -363
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/types/src/common/feeds.d.ts.map +1 -1
  14. package/dist/types/src/db-host/data-service-host.d.ts.map +1 -1
  15. package/dist/types/src/db-host/data-service.d.ts.map +1 -1
  16. package/dist/types/src/db-host/snapshot-manager.d.ts.map +1 -1
  17. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  18. package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
  19. package/dist/types/src/pipeline/pipeline-stress.test.d.ts +2 -0
  20. package/dist/types/src/pipeline/pipeline-stress.test.d.ts.map +1 -0
  21. package/dist/types/src/pipeline/pipeline.d.ts +4 -3
  22. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  23. package/dist/types/src/space/auth.d.ts.map +1 -1
  24. package/dist/types/src/space/control-pipeline.d.ts +4 -0
  25. package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
  26. package/dist/types/src/space/data-pipeline.d.ts +2 -0
  27. package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
  28. package/dist/types/src/space/space-manager.d.ts.map +1 -1
  29. package/dist/types/src/space/space-protocol.d.ts.map +1 -1
  30. package/dist/types/src/space/space.d.ts +2 -1
  31. package/dist/types/src/space/space.d.ts.map +1 -1
  32. package/dist/types/src/testing/database-test-rig.d.ts +4 -1
  33. package/dist/types/src/testing/database-test-rig.d.ts.map +1 -1
  34. package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
  35. package/package.json +32 -31
  36. package/src/common/feeds.ts +1 -2
  37. package/src/db-host/data-service-host.ts +10 -4
  38. package/src/db-host/data-service.ts +1 -2
  39. package/src/db-host/snapshot-manager.ts +0 -2
  40. package/src/metadata/metadata-store.ts +2 -2
  41. package/src/pipeline/message-selector.ts +1 -2
  42. package/src/pipeline/pipeline-stress.test.ts +226 -0
  43. package/src/pipeline/pipeline.test.ts +30 -206
  44. package/src/pipeline/pipeline.ts +50 -24
  45. package/src/space/auth.ts +1 -2
  46. package/src/space/control-pipeline.ts +47 -22
  47. package/src/space/data-pipeline.ts +21 -12
  48. package/src/space/space-manager.ts +1 -0
  49. package/src/space/space-protocol.ts +3 -1
  50. package/src/space/space.test.ts +18 -17
  51. package/src/space/space.ts +7 -3
  52. package/src/testing/database-test-rig.ts +27 -2
  53. package/src/testing/test-agent-builder.ts +2 -1
  54. package/src/tests/database-unit.test.ts +39 -0
  55. package/dist/lib/browser/chunk-7U2NXI2P.mjs.map +0 -7
@@ -7,23 +7,41 @@ var codec = schema.getCodecForType("dxos.echo.feed.FeedMessage");
7
7
  var valueEncoding = createCodecEncoding(codec);
8
8
 
9
9
  // packages/core/echo/echo-pipeline/src/common/feeds.ts
10
- import invariant from "tiny-invariant";
10
+ import { invariant } from "@dxos/invariant";
11
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/common/feeds.ts";
11
12
  var createMappedFeedWriter = (mapper, writer) => {
12
- invariant(mapper);
13
- invariant(writer);
13
+ invariant(mapper, void 0, {
14
+ F: __dxlog_file,
15
+ L: 16,
16
+ S: void 0,
17
+ A: [
18
+ "mapper",
19
+ ""
20
+ ]
21
+ });
22
+ invariant(writer, void 0, {
23
+ F: __dxlog_file,
24
+ L: 17,
25
+ S: void 0,
26
+ A: [
27
+ "writer",
28
+ ""
29
+ ]
30
+ });
14
31
  return {
15
32
  write: async (data, options) => await writer.write(await mapper(data), options)
16
33
  };
17
34
  };
18
35
 
19
36
  // packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts
20
- import invariant2 from "tiny-invariant";
21
37
  import { Stream } from "@dxos/codec-protobuf";
22
38
  import { Context } from "@dxos/context";
23
39
  import { tagMutationsInBatch, setMetadataOnObject } from "@dxos/echo-db";
40
+ import { invariant as invariant2 } from "@dxos/invariant";
24
41
  import { log } from "@dxos/log";
42
+ import { EchoEvent } from "@dxos/protocols/proto/dxos/echo/service";
25
43
  import { ComplexMap } from "@dxos/util";
26
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
44
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
27
45
  var DataServiceHost = class {
28
46
  constructor(_itemManager, _itemDemuxer, _writeStream) {
29
47
  this._itemManager = _itemManager;
@@ -49,16 +67,31 @@ var DataServiceHost = class {
49
67
  objects
50
68
  }
51
69
  });
70
+ this._itemDemuxer.snapshot.on(ctx, (snapshot) => {
71
+ next({
72
+ action: EchoEvent.DatabaseAction.RESET,
73
+ batch: {
74
+ objects: snapshot.items
75
+ }
76
+ });
77
+ });
52
78
  this._itemDemuxer.mutation.on(ctx, (message) => {
53
- var _a;
54
79
  const { batch, meta } = message;
55
- invariant2(!meta.clientTag, "Unexpected client tag in mutation message");
80
+ invariant2(!meta.clientTag, "Unexpected client tag in mutation message", {
81
+ F: __dxlog_file2,
82
+ L: 68,
83
+ S: this,
84
+ A: [
85
+ "!(meta as any).clientTag",
86
+ "'Unexpected client tag in mutation message'"
87
+ ]
88
+ });
56
89
  log("message", {
57
- batch,
90
+ batch: batch.objects?.length,
58
91
  meta
59
92
  }, {
60
- F: __dxlog_file,
61
- L: 63,
93
+ F: __dxlog_file2,
94
+ L: 69,
62
95
  S: this,
63
96
  C: (f, a) => f(...a)
64
97
  });
@@ -66,7 +99,7 @@ var DataServiceHost = class {
66
99
  message.meta.feedKey,
67
100
  message.meta.seq
68
101
  ]);
69
- (_a = batch.objects) == null ? void 0 : _a.forEach((object) => {
102
+ batch.objects?.forEach((object) => {
70
103
  setMetadataOnObject(object, {
71
104
  ...meta
72
105
  });
@@ -84,15 +117,30 @@ var DataServiceHost = class {
84
117
  });
85
118
  }
86
119
  async write(request) {
87
- var _a, _b;
88
- invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost");
89
- invariant2(this._writeStream, "Cannot write mutations in readonly mode");
120
+ invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
121
+ F: __dxlog_file2,
122
+ L: 95,
123
+ S: this,
124
+ A: [
125
+ "!this._ctx.disposed",
126
+ "'Cannot write to closed DataServiceHost'"
127
+ ]
128
+ });
129
+ invariant2(this._writeStream, "Cannot write mutations in readonly mode", {
130
+ F: __dxlog_file2,
131
+ L: 96,
132
+ S: this,
133
+ A: [
134
+ "this._writeStream",
135
+ "'Cannot write mutations in readonly mode'"
136
+ ]
137
+ });
90
138
  log("write", {
91
139
  clientTag: request.clientTag,
92
- objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
140
+ objectCount: request.batch.objects?.length ?? 0
93
141
  }, {
94
- F: __dxlog_file,
95
- L: 92,
142
+ F: __dxlog_file2,
143
+ L: 98,
96
144
  S: this,
97
145
  C: (f, a) => f(...a)
98
146
  });
@@ -105,8 +153,8 @@ var DataServiceHost = class {
105
153
  feedKey: receipt2.feedKey,
106
154
  seq: receipt2.seq
107
155
  }, {
108
- F: __dxlog_file,
109
- L: 101,
156
+ F: __dxlog_file2,
157
+ L: 107,
110
158
  S: this,
111
159
  C: (f, a) => f(...a)
112
160
  });
@@ -120,24 +168,18 @@ var DataServiceHost = class {
120
168
  return receipt;
121
169
  }
122
170
  };
123
- var createDataMessage = (batch) => {
124
- var _a;
125
- return {
126
- batch: {
127
- objects: (_a = batch.objects) == null ? void 0 : _a.map((object) => {
128
- var _a2;
129
- return {
130
- ...object,
131
- mutations: (_a2 = object.mutations) == null ? void 0 : _a2.map((mutation) => ({
132
- ...mutation,
133
- meta: void 0
134
- })),
135
- meta: void 0
136
- };
137
- })
138
- }
139
- };
140
- };
171
+ var createDataMessage = (batch) => ({
172
+ batch: {
173
+ objects: batch.objects?.map((object) => ({
174
+ ...object,
175
+ mutations: object.mutations?.map((mutation) => ({
176
+ ...mutation,
177
+ meta: void 0
178
+ })),
179
+ meta: void 0
180
+ }))
181
+ }
182
+ });
141
183
 
142
184
  // packages/core/echo/echo-pipeline/src/db-host/database-host.ts
143
185
  import { ItemDemuxer } from "@dxos/echo-db";
@@ -166,15 +208,13 @@ var DatabaseHost = class {
166
208
  return this._itemDemuxer.createSnapshot();
167
209
  }
168
210
  createDataServiceHost() {
169
- var _a;
170
- return new DataServiceHost(this._itemManager, this._itemDemuxer, (_a = this._outboundStream) != null ? _a : void 0);
211
+ return new DataServiceHost(this._itemManager, this._itemDemuxer, this._outboundStream ?? void 0);
171
212
  }
172
213
  };
173
214
 
174
215
  // packages/core/echo/echo-pipeline/src/db-host/snapshot-manager.ts
175
216
  import { trackLeaks } from "@dxos/async";
176
217
  import { cancelWithContext } from "@dxos/context";
177
- import { timed } from "@dxos/debug";
178
218
  import { PublicKey } from "@dxos/keys";
179
219
  import { schema as schema2 } from "@dxos/protocols";
180
220
  import { BlobMeta } from "@dxos/protocols/proto/dxos/echo/blob";
@@ -219,9 +259,6 @@ var SnapshotManager = class SnapshotManager2 {
219
259
  return PublicKey.from(id).toHex();
220
260
  }
221
261
  };
222
- _ts_decorate([
223
- timed(1e4)
224
- ], SnapshotManager.prototype, "load", null);
225
262
  SnapshotManager = _ts_decorate([
226
263
  trackLeaks("open", "close")
227
264
  ], SnapshotManager);
@@ -273,12 +310,12 @@ var SnapshotStore = class {
273
310
  };
274
311
 
275
312
  // packages/core/echo/echo-pipeline/src/db-host/data-service.ts
276
- import invariant3 from "tiny-invariant";
277
313
  import { raise } from "@dxos/debug";
314
+ import { invariant as invariant3 } from "@dxos/invariant";
278
315
  import { PublicKey as PublicKey2 } from "@dxos/keys";
279
316
  import { log as log2 } from "@dxos/log";
280
317
  import { ComplexMap as ComplexMap2 } from "@dxos/util";
281
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
318
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
282
319
  var DataServiceSubscriptions = class {
283
320
  constructor() {
284
321
  this._spaces = new ComplexMap2(PublicKey2.hash);
@@ -290,12 +327,20 @@ var DataServiceSubscriptions = class {
290
327
  log2("Registering space", {
291
328
  spaceKey
292
329
  }, {
293
- F: __dxlog_file2,
294
- L: 31,
330
+ F: __dxlog_file3,
331
+ L: 30,
295
332
  S: this,
296
333
  C: (f, a) => f(...a)
297
334
  });
298
- invariant3(!this._spaces.has(spaceKey));
335
+ invariant3(!this._spaces.has(spaceKey), void 0, {
336
+ F: __dxlog_file3,
337
+ L: 31,
338
+ S: this,
339
+ A: [
340
+ "!this._spaces.has(spaceKey)",
341
+ ""
342
+ ]
343
+ });
299
344
  await host.open();
300
345
  this._spaces.set(spaceKey, host);
301
346
  }
@@ -303,13 +348,13 @@ var DataServiceSubscriptions = class {
303
348
  log2("Unregistering space", {
304
349
  spaceKey
305
350
  }, {
306
- F: __dxlog_file2,
307
- L: 38,
351
+ F: __dxlog_file3,
352
+ L: 37,
308
353
  S: this,
309
354
  C: (f, a) => f(...a)
310
355
  });
311
356
  const host = this._spaces.get(spaceKey);
312
- await (host == null ? void 0 : host.close());
357
+ await host?.close();
313
358
  this._spaces.delete(spaceKey);
314
359
  }
315
360
  getDataService(spaceKey) {
@@ -321,25 +366,47 @@ var DataServiceImpl = class {
321
366
  this._subscriptions = _subscriptions;
322
367
  }
323
368
  subscribe(request) {
324
- var _a;
325
- invariant3(request.spaceKey);
326
- const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
369
+ invariant3(request.spaceKey, void 0, {
370
+ F: __dxlog_file3,
371
+ L: 56,
372
+ S: this,
373
+ A: [
374
+ "request.spaceKey",
375
+ ""
376
+ ]
377
+ });
378
+ const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
327
379
  return host.subscribe();
328
380
  }
329
381
  write(request) {
330
- var _a;
331
- invariant3(request.spaceKey);
332
- invariant3(request.batch);
333
- const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
382
+ invariant3(request.spaceKey, void 0, {
383
+ F: __dxlog_file3,
384
+ L: 63,
385
+ S: this,
386
+ A: [
387
+ "request.spaceKey",
388
+ ""
389
+ ]
390
+ });
391
+ invariant3(request.batch, void 0, {
392
+ F: __dxlog_file3,
393
+ L: 64,
394
+ S: this,
395
+ A: [
396
+ "request.batch",
397
+ ""
398
+ ]
399
+ });
400
+ const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
334
401
  return host.write(request);
335
402
  }
336
403
  };
337
404
 
338
405
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
339
406
  import CRC32 from "crc-32";
340
- import invariant4 from "tiny-invariant";
341
407
  import { synchronized, Event } from "@dxos/async";
342
408
  import { DataCorruptionError } from "@dxos/errors";
409
+ import { invariant as invariant4 } from "@dxos/invariant";
343
410
  import { log as log3 } from "@dxos/log";
344
411
  import { STORAGE_VERSION, schema as schema4 } from "@dxos/protocols";
345
412
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
@@ -354,12 +421,12 @@ function _ts_decorate2(decorators, target, key, desc) {
354
421
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
355
422
  return c > 3 && r && Object.defineProperty(target, key, r), r;
356
423
  }
357
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
424
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
358
425
  var emptyEchoMetadata = () => ({
359
426
  version: STORAGE_VERSION,
360
427
  spaces: [],
361
- created: new Date(),
362
- updated: new Date()
428
+ created: /* @__PURE__ */ new Date(),
429
+ updated: /* @__PURE__ */ new Date()
363
430
  });
364
431
  var EchoMetadata = schema4.getCodecForType("dxos.echo.metadata.EchoMetadata");
365
432
  var MetadataStore = class {
@@ -373,22 +440,19 @@ var MetadataStore = class {
373
440
  return this._metadata;
374
441
  }
375
442
  get version() {
376
- var _a;
377
- return (_a = this._metadata.version) != null ? _a : 0;
443
+ return this._metadata.version ?? 0;
378
444
  }
379
445
  /**
380
446
  * Returns a list of currently saved spaces. The list and objects in it can be modified addSpace and
381
447
  * addSpaceFeed functions.
382
448
  */
383
449
  get spaces() {
384
- var _a;
385
- return (_a = this._metadata.spaces) != null ? _a : [];
450
+ return this._metadata.spaces ?? [];
386
451
  }
387
452
  /**
388
453
  * Loads metadata from persistent storage.
389
454
  */
390
455
  async load() {
391
- var _a;
392
456
  const file = this._directory.getOrCreateFile("EchoMetadata");
393
457
  try {
394
458
  const { size: fileLength } = await file.stat();
@@ -401,13 +465,16 @@ var MetadataStore = class {
401
465
  size: dataSize,
402
466
  checksum
403
467
  }, {
404
- F: __dxlog_file3,
468
+ F: __dxlog_file4,
405
469
  L: 72,
406
470
  S: this,
407
471
  C: (f, a) => f(...a)
408
472
  });
409
473
  if (fileLength < dataSize + 8) {
410
- throw new DataCorruptionError("Metadata size is smaller than expected.");
474
+ throw new DataCorruptionError("Metadata size is smaller than expected.", {
475
+ fileLength,
476
+ dataSize
477
+ });
411
478
  }
412
479
  const data = await file.read(8, dataSize);
413
480
  const calculatedChecksum = CRC32.buf(data);
@@ -415,15 +482,14 @@ var MetadataStore = class {
415
482
  throw new DataCorruptionError("Metadata checksum is invalid.");
416
483
  }
417
484
  this._metadata = EchoMetadata.decode(data);
418
- (_a = this._metadata.spaces) == null ? void 0 : _a.forEach((space) => {
419
- var _a2;
420
- (_a2 = space.state) != null ? _a2 : space.state = SpaceState.ACTIVE;
485
+ this._metadata.spaces?.forEach((space) => {
486
+ space.state ??= SpaceState.ACTIVE;
421
487
  });
422
488
  } catch (err) {
423
489
  log3.error("failed to load metadata", {
424
490
  err
425
491
  }, {
426
- F: __dxlog_file3,
492
+ F: __dxlog_file4,
427
493
  L: 92,
428
494
  S: this,
429
495
  C: (f, a) => f(...a)
@@ -434,12 +500,11 @@ var MetadataStore = class {
434
500
  }
435
501
  }
436
502
  async _save() {
437
- var _a;
438
503
  const data = {
439
504
  ...this._metadata,
440
505
  version: STORAGE_VERSION,
441
- created: (_a = this._metadata.created) != null ? _a : new Date(),
442
- updated: new Date()
506
+ created: this._metadata.created ?? /* @__PURE__ */ new Date(),
507
+ updated: /* @__PURE__ */ new Date()
443
508
  };
444
509
  this.update.emit(data);
445
510
  const file = this._directory.getOrCreateFile("EchoMetadata");
@@ -455,7 +520,7 @@ var MetadataStore = class {
455
520
  size: encoded.length,
456
521
  checksum
457
522
  }, {
458
- F: __dxlog_file3,
523
+ F: __dxlog_file4,
459
524
  L: 124,
460
525
  S: this,
461
526
  C: (f, a) => f(...a)
@@ -465,12 +530,19 @@ var MetadataStore = class {
465
530
  }
466
531
  }
467
532
  _getSpace(spaceKey) {
468
- var _a;
469
- if ((_a = this._metadata.identity) == null ? void 0 : _a.haloSpace.key.equals(spaceKey)) {
533
+ if (this._metadata.identity?.haloSpace.key.equals(spaceKey)) {
470
534
  return this._metadata.identity.haloSpace;
471
535
  }
472
536
  const space = this.spaces.find((space2) => space2.key === spaceKey);
473
- invariant4(space, "Space not found");
537
+ invariant4(space, "Space not found", {
538
+ F: __dxlog_file4,
539
+ L: 137,
540
+ S: this,
541
+ A: [
542
+ "space",
543
+ "'Space not found'"
544
+ ]
545
+ });
474
546
  return space;
475
547
  }
476
548
  /**
@@ -478,7 +550,7 @@ var MetadataStore = class {
478
550
  */
479
551
  async clear() {
480
552
  log3("clearing all metadata", void 0, {
481
- F: __dxlog_file3,
553
+ F: __dxlog_file4,
482
554
  L: 145,
483
555
  S: this,
484
556
  C: (f, a) => f(...a)
@@ -490,14 +562,29 @@ var MetadataStore = class {
490
562
  return this._metadata.identity;
491
563
  }
492
564
  async setIdentityRecord(record) {
493
- invariant4(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
565
+ invariant4(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
566
+ F: __dxlog_file4,
567
+ L: 155,
568
+ S: this,
569
+ A: [
570
+ "!this._metadata.identity",
571
+ "'Cannot overwrite existing identity in metadata'"
572
+ ]
573
+ });
494
574
  this._metadata.identity = record;
495
575
  await this._save();
496
576
  }
497
577
  async addSpace(record) {
498
- var _a, _b, _c;
499
- invariant4(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
500
- ((_c = (_b = this._metadata).spaces) != null ? _c : _b.spaces = []).push(record);
578
+ invariant4(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
579
+ F: __dxlog_file4,
580
+ L: 162,
581
+ S: this,
582
+ A: [
583
+ "!(this._metadata.spaces ?? []).find((space) => space.key === record.key)",
584
+ "'Cannot overwrite existing space in metadata'"
585
+ ]
586
+ });
587
+ (this._metadata.spaces ??= []).push(record);
501
588
  await this._save();
502
589
  }
503
590
  async setSpaceDataLatestTimeframe(spaceKey, timeframe) {
@@ -533,7 +620,7 @@ var fromBytesInt32 = (buf) => buf.readInt32LE(0);
533
620
 
534
621
  // packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts
535
622
  import { Event as Event2 } from "@dxos/async";
536
- import { timed as timed2 } from "@dxos/debug";
623
+ import { timed } from "@dxos/debug";
537
624
  import { log as log4 } from "@dxos/log";
538
625
  import { Timeframe } from "@dxos/timeframe";
539
626
  function _ts_decorate3(decorators, target, key, desc) {
@@ -546,7 +633,7 @@ function _ts_decorate3(decorators, target, key, desc) {
546
633
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
547
634
  return c > 3 && r && Object.defineProperty(target, key, r), r;
548
635
  }
549
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
636
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
550
637
  var mapTimeframeToFeedIndexes = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
551
638
  feedKey,
552
639
  index
@@ -605,7 +692,7 @@ var TimeframeClock = class {
605
692
  target,
606
693
  current: this._timeframe
607
694
  }, {
608
- F: __dxlog_file4,
695
+ F: __dxlog_file5,
609
696
  L: 73,
610
697
  S: this,
611
698
  C: (f, a) => f(...a)
@@ -616,7 +703,7 @@ var TimeframeClock = class {
616
703
  current: this._timeframe,
617
704
  deps: Timeframe.dependencies(target, this._timeframe)
618
705
  }, {
619
- F: __dxlog_file4,
706
+ F: __dxlog_file5,
620
707
  L: 75,
621
708
  S: this,
622
709
  C: (f, a) => f(...a)
@@ -626,36 +713,44 @@ var TimeframeClock = class {
626
713
  }
627
714
  };
628
715
  _ts_decorate3([
629
- timed2(5e3)
716
+ timed(5e3)
630
717
  ], TimeframeClock.prototype, "waitUntilReached", null);
631
718
 
632
719
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
633
- import invariant6 from "tiny-invariant";
634
720
  import { Event as Event3, sleep, synchronized as synchronized2, Trigger } from "@dxos/async";
635
721
  import { Context as Context2, rejectOnDispose } from "@dxos/context";
636
722
  import { failUndefined } from "@dxos/debug";
637
723
  import { FeedSetIterator } from "@dxos/feed-store";
724
+ import { invariant as invariant6 } from "@dxos/invariant";
638
725
  import { PublicKey as PublicKey3 } from "@dxos/keys";
639
726
  import { log as log6 } from "@dxos/log";
640
727
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
641
728
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
642
729
 
643
730
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
644
- import invariant5 from "tiny-invariant";
731
+ import { invariant as invariant5 } from "@dxos/invariant";
645
732
  import { log as log5 } from "@dxos/log";
646
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
733
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
647
734
  var createMessageSelector = (timeframeClock) => {
648
735
  return (messages) => {
649
736
  for (let i = 0; i < messages.length; i++) {
650
737
  const { data: { timeframe } } = messages[i];
651
- invariant5(timeframe);
738
+ invariant5(timeframe, void 0, {
739
+ F: __dxlog_file6,
740
+ L: 25,
741
+ S: void 0,
742
+ A: [
743
+ "timeframe",
744
+ ""
745
+ ]
746
+ });
652
747
  if (!timeframeClock.hasGaps(timeframe)) {
653
748
  return i;
654
749
  }
655
750
  }
656
751
  log5("Skipping...", void 0, {
657
- F: __dxlog_file5,
658
- L: 34,
752
+ F: __dxlog_file6,
753
+ L: 33,
659
754
  S: void 0,
660
755
  C: (f, a) => f(...a)
661
756
  });
@@ -673,7 +768,7 @@ function _ts_decorate4(decorators, target, key, desc) {
673
768
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
674
769
  return c > 3 && r && Object.defineProperty(target, key, r), r;
675
770
  }
676
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
771
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
677
772
  var PipelineState = class {
678
773
  // prettier-ignore
679
774
  constructor(_feeds, _timeframeClock) {
@@ -724,18 +819,17 @@ var PipelineState = class {
724
819
  * @param timeout Timeout in milliseconds to specify the maximum wait time.
725
820
  */
726
821
  async waitUntilReachedTargetTimeframe({ ctx = new Context2(), timeout, breakOnStall = true } = {}) {
727
- var _a;
728
822
  log6("waitUntilReachedTargetTimeframe", {
729
823
  timeout,
730
824
  current: this.timeframe,
731
825
  target: this.targetTimeframe
732
826
  }, {
733
- F: __dxlog_file6,
734
- L: 126,
827
+ F: __dxlog_file7,
828
+ L: 125,
735
829
  S: this,
736
830
  C: (f, a) => f(...a)
737
831
  });
738
- (_a = this._reachedTargetPromise) != null ? _a : this._reachedTargetPromise = Promise.race([
832
+ this._reachedTargetPromise ??= Promise.race([
739
833
  this._timeframeClock.update.waitForCondition(() => {
740
834
  return Timeframe2.dependencies(this.targetTimeframe, this.timeframe).isEmpty();
741
835
  }),
@@ -761,8 +855,8 @@ var PipelineState = class {
761
855
  target: this.targetTimeframe,
762
856
  dependencies: Timeframe2.dependencies(this.targetTimeframe, this.timeframe)
763
857
  }, {
764
- F: __dxlog_file6,
765
- L: 153,
858
+ F: __dxlog_file7,
859
+ L: 152,
766
860
  S: this,
767
861
  C: (f, a) => f(...a)
768
862
  });
@@ -782,16 +876,26 @@ var Pipeline = class {
782
876
  // Waits for the message consumer to process the message and yield control back to the pipeline.
783
877
  this._processingTrigger = new Trigger().wake();
784
878
  this._pauseTrigger = new Trigger().wake();
879
+ // Pending downloads.
880
+ this._downloads = new ComplexMap3((value) => PublicKey3.hash(value.key));
785
881
  this._isStopping = false;
786
882
  this._isStarted = false;
787
- this._isOpen = false;
883
+ this._isBeingConsumed = false;
788
884
  this._isPaused = false;
789
885
  }
790
886
  get state() {
791
887
  return this._state;
792
888
  }
793
889
  get writer() {
794
- invariant6(this._writer, "Writer not set.");
890
+ invariant6(this._writer, "Writer not set.", {
891
+ F: __dxlog_file7,
892
+ L: 233,
893
+ S: this,
894
+ A: [
895
+ "this._writer",
896
+ "'Writer not set.'"
897
+ ]
898
+ });
795
899
  return this._writer;
796
900
  }
797
901
  hasFeed(feedKey) {
@@ -807,20 +911,47 @@ var Pipeline = class {
807
911
  if (this._feedSetIterator) {
808
912
  await this._feedSetIterator.addFeed(feed);
809
913
  }
810
- this._setFeedDownloadState(feed);
914
+ if (this._isStarted && !this._isPaused) {
915
+ this._setFeedDownloadState(feed);
916
+ }
811
917
  }
812
918
  setWriteFeed(feed) {
813
- invariant6(!this._writer, "Writer already set.");
814
- invariant6(feed.properties.writable, "Feed must be writable.");
919
+ invariant6(!this._writer, "Writer already set.", {
920
+ F: __dxlog_file7,
921
+ L: 260,
922
+ S: this,
923
+ A: [
924
+ "!this._writer",
925
+ "'Writer already set.'"
926
+ ]
927
+ });
928
+ invariant6(feed.properties.writable, "Feed must be writable.", {
929
+ F: __dxlog_file7,
930
+ L: 261,
931
+ S: this,
932
+ A: [
933
+ "feed.properties.writable",
934
+ "'Feed must be writable.'"
935
+ ]
936
+ });
815
937
  this._writer = createMappedFeedWriter((payload) => ({
816
938
  timeframe: this._timeframeClock.timeframe,
817
939
  payload
818
940
  }), feed.createFeedWriter());
819
941
  }
820
942
  async start() {
943
+ invariant6(!this._isStarted, "Pipeline is already started.", {
944
+ F: __dxlog_file7,
945
+ L: 274,
946
+ S: this,
947
+ A: [
948
+ "!this._isStarted",
949
+ "'Pipeline is already started.'"
950
+ ]
951
+ });
821
952
  log6("starting...", void 0, {
822
- F: __dxlog_file6,
823
- L: 268,
953
+ F: __dxlog_file7,
954
+ L: 275,
824
955
  S: this,
825
956
  C: (f, a) => f(...a)
826
957
  });
@@ -828,30 +959,38 @@ var Pipeline = class {
828
959
  await this._feedSetIterator.open();
829
960
  this._isStarted = true;
830
961
  log6("started", void 0, {
831
- F: __dxlog_file6,
832
- L: 272,
962
+ F: __dxlog_file7,
963
+ L: 279,
833
964
  S: this,
834
965
  C: (f, a) => f(...a)
835
966
  });
967
+ if (!this._isPaused) {
968
+ for (const feed of this._feeds.values()) {
969
+ this._setFeedDownloadState(feed);
970
+ }
971
+ }
836
972
  }
837
973
  async stop() {
838
- var _a;
839
974
  log6("stopping...", void 0, {
840
- F: __dxlog_file6,
841
- L: 277,
975
+ F: __dxlog_file7,
976
+ L: 290,
842
977
  S: this,
843
978
  C: (f, a) => f(...a)
844
979
  });
845
980
  this._isStopping = true;
846
- await ((_a = this._feedSetIterator) == null ? void 0 : _a.close());
981
+ for (const [feed, handle] of this._downloads.entries()) {
982
+ feed.undownload(handle);
983
+ }
984
+ this._downloads.clear();
985
+ await this._feedSetIterator?.close();
847
986
  await this._processingTrigger.wait();
848
987
  await this._state._ctx.dispose();
849
988
  this._state._ctx = new Context2();
850
989
  this._state._reachedTargetPromise = void 0;
851
990
  this._isStarted = false;
852
991
  log6("stopped", void 0, {
853
- F: __dxlog_file6,
854
- L: 285,
992
+ F: __dxlog_file7,
993
+ L: 302,
855
994
  S: this,
856
995
  C: (f, a) => f(...a)
857
996
  });
@@ -861,12 +1000,17 @@ var Pipeline = class {
861
1000
  * The pipeline will start processing messages AFTER this timeframe.
862
1001
  */
863
1002
  async setCursor(timeframe) {
864
- invariant6(!this._isStarted || this._isPaused, "Invalid state.");
1003
+ invariant6(!this._isStarted || this._isPaused, "Invalid state.", {
1004
+ F: __dxlog_file7,
1005
+ L: 311,
1006
+ S: this,
1007
+ A: [
1008
+ "!this._isStarted || this._isPaused",
1009
+ "'Invalid state.'"
1010
+ ]
1011
+ });
865
1012
  this._state._startTimeframe = timeframe;
866
1013
  this._timeframeClock.setTimeframe(timeframe);
867
- for (const feed of this._feeds.values()) {
868
- this._setFeedDownloadState(feed);
869
- }
870
1014
  if (this._feedSetIterator) {
871
1015
  await this._feedSetIterator.close();
872
1016
  await this._initIterator();
@@ -877,7 +1021,6 @@ var Pipeline = class {
877
1021
  * Calling pause while processing will cause a deadlock.
878
1022
  */
879
1023
  async pause() {
880
- invariant6(this._isStarted, "Pipeline is not open.");
881
1024
  if (this._isPaused) {
882
1025
  return;
883
1026
  }
@@ -886,31 +1029,65 @@ var Pipeline = class {
886
1029
  this._isPaused = true;
887
1030
  }
888
1031
  async unpause() {
889
- invariant6(this._isStarted, "Pipeline is not open.");
890
- invariant6(this._isPaused, "Pipeline is not paused.");
1032
+ invariant6(this._isPaused, "Pipeline is not paused.", {
1033
+ F: __dxlog_file7,
1034
+ L: 340,
1035
+ S: this,
1036
+ A: [
1037
+ "this._isPaused",
1038
+ "'Pipeline is not paused.'"
1039
+ ]
1040
+ });
891
1041
  this._pauseTrigger.wake();
892
1042
  this._isPaused = false;
1043
+ for (const feed of this._feeds.values()) {
1044
+ this._setFeedDownloadState(feed);
1045
+ }
893
1046
  }
894
1047
  /**
895
1048
  * Starts to iterate over the ordered messages from the added feeds.
896
1049
  * Updates the timeframe clock after the message has bee processed.
897
1050
  */
898
1051
  async *consume() {
899
- invariant6(!this._isOpen, "Pipeline is already being consumed.");
900
- this._isOpen = true;
901
- invariant6(this._feedSetIterator, "Iterator not initialized.");
1052
+ invariant6(!this._isBeingConsumed, "Pipeline is already being consumed.", {
1053
+ F: __dxlog_file7,
1054
+ L: 355,
1055
+ S: this,
1056
+ A: [
1057
+ "!this._isBeingConsumed",
1058
+ "'Pipeline is already being consumed.'"
1059
+ ]
1060
+ });
1061
+ this._isBeingConsumed = true;
1062
+ invariant6(this._feedSetIterator, "Iterator not initialized.", {
1063
+ F: __dxlog_file7,
1064
+ L: 358,
1065
+ S: this,
1066
+ A: [
1067
+ "this._feedSetIterator",
1068
+ "'Iterator not initialized.'"
1069
+ ]
1070
+ });
902
1071
  let lastFeedSetIterator = this._feedSetIterator;
903
1072
  let iterable = lastFeedSetIterator[Symbol.asyncIterator]();
904
1073
  while (!this._isStopping) {
905
1074
  await this._pauseTrigger.wait();
906
1075
  if (lastFeedSetIterator !== this._feedSetIterator) {
907
- invariant6(this._feedSetIterator, "Iterator not initialized.");
1076
+ invariant6(this._feedSetIterator, "Iterator not initialized.", {
1077
+ F: __dxlog_file7,
1078
+ L: 367,
1079
+ S: this,
1080
+ A: [
1081
+ "this._feedSetIterator",
1082
+ "'Iterator not initialized.'"
1083
+ ]
1084
+ });
908
1085
  lastFeedSetIterator = this._feedSetIterator;
909
1086
  iterable = lastFeedSetIterator[Symbol.asyncIterator]();
910
1087
  }
911
1088
  const { done, value } = await iterable.next();
912
1089
  if (!done) {
913
- const block = value != null ? value : failUndefined();
1090
+ const block = value ?? failUndefined();
914
1091
  this._processingTrigger.reset();
915
1092
  this._timeframeClock.updatePendingTimeframe(PublicKey3.from(block.feedKey), block.seq);
916
1093
  yield block;
@@ -918,33 +1095,40 @@ var Pipeline = class {
918
1095
  this._timeframeClock.updateTimeframe();
919
1096
  }
920
1097
  }
921
- this._isOpen = false;
1098
+ this._isBeingConsumed = false;
922
1099
  }
923
1100
  _setFeedDownloadState(feed) {
924
- var _a;
1101
+ let handle = this._downloads.get(feed);
1102
+ if (handle) {
1103
+ feed.undownload(handle);
1104
+ }
925
1105
  const timeframe = this._state._startTimeframe;
926
- const seq = (_a = timeframe.get(feed.key)) != null ? _a : 0;
927
- feed.undownload({
928
- callback: () => log6("undownload", void 0, {
929
- F: __dxlog_file6,
930
- L: 376,
931
- S: this,
932
- C: (f, a) => f(...a)
933
- })
1106
+ const seq = timeframe.get(feed.key) ?? -1;
1107
+ log6.info("download", {
1108
+ feed: feed.key.truncate(),
1109
+ seq,
1110
+ length: feed.length
1111
+ }, {
1112
+ F: __dxlog_file7,
1113
+ L: 396,
1114
+ S: this,
1115
+ C: (f, a) => f(...a)
934
1116
  });
935
- feed.download({
1117
+ handle = feed.download({
936
1118
  start: seq + 1,
937
1119
  linear: true
938
- }).catch((err) => {
939
- log6("failed to download feed", {
940
- err
941
- }, {
942
- F: __dxlog_file6,
943
- L: 378,
944
- S: this,
945
- C: (f, a) => f(...a)
946
- });
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
+ }
947
1130
  });
1131
+ this._downloads.set(feed, handle);
948
1132
  }
949
1133
  async _initIterator() {
950
1134
  this._feedSetIterator = new FeedSetIterator(createMessageSelector(this._timeframeClock), {
@@ -953,8 +1137,8 @@ var Pipeline = class {
953
1137
  });
954
1138
  this._feedSetIterator.stalled.on((iterator) => {
955
1139
  log6.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
956
- F: __dxlog_file6,
957
- L: 389,
1140
+ F: __dxlog_file7,
1141
+ L: 415,
958
1142
  S: this,
959
1143
  C: (f, a) => f(...a)
960
1144
  });
@@ -982,14 +1166,14 @@ _ts_decorate4([
982
1166
  ], Pipeline.prototype, "unpause", null);
983
1167
 
984
1168
  // packages/core/echo/echo-pipeline/src/space/auth.ts
985
- import invariant7 from "tiny-invariant";
986
1169
  import { runInContext, scheduleTask } from "@dxos/async";
987
1170
  import { Context as Context3 } from "@dxos/context";
988
1171
  import { randomBytes } from "@dxos/crypto";
1172
+ import { invariant as invariant7 } from "@dxos/invariant";
989
1173
  import { log as log7 } from "@dxos/log";
990
1174
  import { schema as schema5 } from "@dxos/protocols";
991
1175
  import { RpcExtension } from "@dxos/teleport";
992
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
1176
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
993
1177
  var AuthExtension = class extends RpcExtension {
994
1178
  constructor(_authParams) {
995
1179
  super({
@@ -1005,8 +1189,8 @@ var AuthExtension = class extends RpcExtension {
1005
1189
  this._ctx = new Context3({
1006
1190
  onError: (err) => {
1007
1191
  log7.catch(err, void 0, {
1008
- F: __dxlog_file7,
1009
- L: 29,
1192
+ F: __dxlog_file8,
1193
+ L: 28,
1010
1194
  S: this,
1011
1195
  C: (f, a) => f(...a)
1012
1196
  });
@@ -1027,8 +1211,8 @@ var AuthExtension = class extends RpcExtension {
1027
1211
  };
1028
1212
  } catch (err) {
1029
1213
  log7.error("failed to generate auth credentials", err, {
1030
- F: __dxlog_file7,
1031
- L: 56,
1214
+ F: __dxlog_file8,
1215
+ L: 55,
1032
1216
  S: this,
1033
1217
  C: (f, a) => f(...a)
1034
1218
  });
@@ -1046,14 +1230,30 @@ var AuthExtension = class extends RpcExtension {
1046
1230
  const { credential } = await this.rpc.AuthService.authenticate({
1047
1231
  challenge
1048
1232
  });
1049
- invariant7((credential == null ? void 0 : credential.length) > 0, "invalid credential");
1233
+ invariant7(credential?.length > 0, "invalid credential", {
1234
+ F: __dxlog_file8,
1235
+ L: 69,
1236
+ S: this,
1237
+ A: [
1238
+ "credential?.length > 0",
1239
+ "'invalid credential'"
1240
+ ]
1241
+ });
1050
1242
  const success = await this._authParams.verifier(challenge, credential);
1051
- invariant7(success, "credential not verified");
1243
+ invariant7(success, "credential not verified", {
1244
+ F: __dxlog_file8,
1245
+ L: 71,
1246
+ S: this,
1247
+ A: [
1248
+ "success",
1249
+ "'credential not verified'"
1250
+ ]
1251
+ });
1052
1252
  runInContext(this._ctx, () => this._authParams.onAuthSuccess());
1053
1253
  } catch (err) {
1054
1254
  log7("auth failed", err, {
1055
- F: __dxlog_file7,
1056
- L: 75,
1255
+ F: __dxlog_file8,
1256
+ L: 74,
1057
1257
  S: this,
1058
1258
  C: (f, a) => f(...a)
1059
1259
  });
@@ -1069,14 +1269,15 @@ var AuthExtension = class extends RpcExtension {
1069
1269
  };
1070
1270
 
1071
1271
  // packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
1072
- import invariant8 from "tiny-invariant";
1073
1272
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1074
1273
  import { Context as Context4 } from "@dxos/context";
1075
1274
  import { checkCredentialType } from "@dxos/credentials";
1076
- import { getStateMachineFromItem, ItemManager } from "@dxos/echo-db";
1275
+ import { getStateMachineFromItem, ItemManager, TYPE_PROPERTIES } from "@dxos/echo-db";
1077
1276
  import { CancelledError } from "@dxos/errors";
1078
- import { log as log8 } from "@dxos/log";
1277
+ import { invariant as invariant8 } from "@dxos/invariant";
1278
+ import { log as log8, omit } from "@dxos/log";
1079
1279
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1280
+ import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
1080
1281
  import { tracer } from "@dxos/util";
1081
1282
  function _ts_decorate5(decorators, target, key, desc) {
1082
1283
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1088,7 +1289,7 @@ function _ts_decorate5(decorators, target, key, desc) {
1088
1289
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1089
1290
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1090
1291
  }
1091
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
1292
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
1092
1293
  var MESSAGES_PER_SNAPSHOT = 10;
1093
1294
  var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
1094
1295
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
@@ -1103,6 +1304,8 @@ var DataPipeline = class DataPipeline2 {
1103
1304
  this._lastTimeframeSaveTime = 0;
1104
1305
  this._lastSnapshotSaveTime = 0;
1105
1306
  this._lastProcessedEpoch = -1;
1307
+ this._usage = new TimeUsageCounter();
1308
+ this._mutations = new TimeSeriesCounter();
1106
1309
  this.currentEpoch = void 0;
1107
1310
  this.appliedEpoch = void 0;
1108
1311
  this.onNewEpoch = new Event4();
@@ -1114,13 +1317,11 @@ var DataPipeline = class DataPipeline2 {
1114
1317
  return this._pipeline;
1115
1318
  }
1116
1319
  get pipelineState() {
1117
- var _a;
1118
- return (_a = this._pipeline) == null ? void 0 : _a.state;
1320
+ return this._pipeline?.state;
1119
1321
  }
1120
1322
  setTargetTimeframe(timeframe) {
1121
- var _a;
1122
1323
  this._targetTimeframe = timeframe;
1123
- (_a = this._pipeline) == null ? void 0 : _a.state.setTargetTimeframe(timeframe);
1324
+ this._pipeline?.state.setTargetTimeframe(timeframe);
1124
1325
  }
1125
1326
  async processCredential(credential) {
1126
1327
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
@@ -1137,15 +1338,31 @@ var DataPipeline = class DataPipeline2 {
1137
1338
  }
1138
1339
  this._pipeline = new Pipeline();
1139
1340
  await this._params.onPipelineCreated(this._pipeline);
1140
- await this._pipeline.start();
1141
1341
  await this._pipeline.pause();
1342
+ await this._pipeline.start();
1142
1343
  if (this._targetTimeframe) {
1143
1344
  this._pipeline.state.setTargetTimeframe(this._targetTimeframe);
1144
1345
  }
1145
1346
  const feedWriter = {
1146
1347
  write: (data, options) => {
1147
- invariant8(this._pipeline, "Pipeline is not initialized.");
1148
- invariant8(this.currentEpoch, "Epoch is not initialized.");
1348
+ invariant8(this._pipeline, "Pipeline is not initialized.", {
1349
+ F: __dxlog_file9,
1350
+ L: 154,
1351
+ S: this,
1352
+ A: [
1353
+ "this._pipeline",
1354
+ "'Pipeline is not initialized.'"
1355
+ ]
1356
+ });
1357
+ invariant8(this.currentEpoch, "Epoch is not initialized.", {
1358
+ F: __dxlog_file9,
1359
+ L: 155,
1360
+ S: this,
1361
+ A: [
1362
+ "this.currentEpoch",
1363
+ "'Epoch is not initialized.'"
1364
+ ]
1365
+ });
1149
1366
  return this._pipeline.writer.write({
1150
1367
  data
1151
1368
  }, options);
@@ -1160,19 +1377,18 @@ var DataPipeline = class DataPipeline2 {
1160
1377
  this._isOpen = true;
1161
1378
  }
1162
1379
  async close() {
1163
- var _a, _b, _c;
1164
1380
  if (!this._isOpen) {
1165
1381
  return;
1166
1382
  }
1167
1383
  log8("close", void 0, {
1168
- F: __dxlog_file8,
1169
- L: 171,
1384
+ F: __dxlog_file9,
1385
+ L: 179,
1170
1386
  S: this,
1171
1387
  C: (f, a) => f(...a)
1172
1388
  });
1173
1389
  this._isOpen = false;
1174
1390
  await this._ctx.dispose();
1175
- await ((_a = this._pipeline) == null ? void 0 : _a.stop());
1391
+ await this._pipeline?.stop();
1176
1392
  try {
1177
1393
  await this._saveCache();
1178
1394
  if (this._pipeline) {
@@ -1180,14 +1396,14 @@ var DataPipeline = class DataPipeline2 {
1180
1396
  }
1181
1397
  } catch (err) {
1182
1398
  log8.catch(err, void 0, {
1183
- F: __dxlog_file8,
1184
- L: 184,
1399
+ F: __dxlog_file9,
1400
+ L: 192,
1185
1401
  S: this,
1186
1402
  C: (f, a) => f(...a)
1187
1403
  });
1188
1404
  }
1189
- await ((_b = this.databaseHost) == null ? void 0 : _b.close());
1190
- await ((_c = this.itemManager) == null ? void 0 : _c.destroy());
1405
+ await this.databaseHost?.close();
1406
+ await this.itemManager?.destroy();
1191
1407
  this._ctx = new Context4();
1192
1408
  this._pipeline = void 0;
1193
1409
  this._targetTimeframe = void 0;
@@ -1203,15 +1419,25 @@ var DataPipeline = class DataPipeline2 {
1203
1419
  await this._processEpochInSeparateTask(this.currentEpoch);
1204
1420
  await waitForOneEpoch;
1205
1421
  }
1206
- invariant8(this._pipeline, "Pipeline is not initialized.");
1422
+ invariant8(this._pipeline, "Pipeline is not initialized.", {
1423
+ F: __dxlog_file9,
1424
+ L: 215,
1425
+ S: this,
1426
+ A: [
1427
+ "this._pipeline",
1428
+ "'Pipeline is not initialized.'"
1429
+ ]
1430
+ });
1207
1431
  for await (const msg of this._pipeline.consume()) {
1432
+ const span = this._usage.beginRecording();
1433
+ this._mutations.inc();
1208
1434
  const { feedKey, seq, data } = msg;
1209
1435
  log8("processing message", {
1210
1436
  feedKey,
1211
1437
  seq
1212
1438
  }, {
1213
- F: __dxlog_file8,
1214
- L: 210,
1439
+ F: __dxlog_file9,
1440
+ L: 221,
1215
1441
  S: this,
1216
1442
  C: (f, a) => f(...a)
1217
1443
  });
@@ -1222,8 +1448,8 @@ var DataPipeline = class DataPipeline2 {
1222
1448
  log8.warn("Could not find feed", {
1223
1449
  feedKey
1224
1450
  }, {
1225
- F: __dxlog_file8,
1226
- L: 216,
1451
+ F: __dxlog_file9,
1452
+ L: 227,
1227
1453
  S: this,
1228
1454
  C: (f, a) => f(...a)
1229
1455
  });
@@ -1245,8 +1471,8 @@ var DataPipeline = class DataPipeline2 {
1245
1471
  seq,
1246
1472
  spaceKey: this._params.spaceKey.toHex()
1247
1473
  }, {
1248
- F: __dxlog_file8,
1249
- L: 233,
1474
+ F: __dxlog_file9,
1475
+ L: 244,
1250
1476
  S: this,
1251
1477
  C: (f, a) => f(...a)
1252
1478
  });
@@ -1254,16 +1480,25 @@ var DataPipeline = class DataPipeline2 {
1254
1480
  }
1255
1481
  } catch (err) {
1256
1482
  log8.catch(err, void 0, {
1257
- F: __dxlog_file8,
1258
- L: 243,
1483
+ F: __dxlog_file9,
1484
+ L: 254,
1259
1485
  S: this,
1260
1486
  C: (f, a) => f(...a)
1261
1487
  });
1262
1488
  }
1489
+ span.end();
1263
1490
  }
1264
1491
  }
1265
1492
  _createSnapshot() {
1266
- invariant8(this.databaseHost, "Database backend is not initialized.");
1493
+ invariant8(this.databaseHost, "Database backend is not initialized.", {
1494
+ F: __dxlog_file9,
1495
+ L: 262,
1496
+ S: this,
1497
+ A: [
1498
+ "this.databaseHost",
1499
+ "'Database backend is not initialized.'"
1500
+ ]
1501
+ });
1267
1502
  return {
1268
1503
  spaceKey: this._params.spaceKey.asUint8Array(),
1269
1504
  timeframe: this._pipeline.state.timeframe,
@@ -1271,26 +1506,22 @@ var DataPipeline = class DataPipeline2 {
1271
1506
  };
1272
1507
  }
1273
1508
  async _saveTargetTimeframe(timeframe) {
1274
- var _a;
1275
- const newTimeframe = Timeframe3.merge((_a = this._targetTimeframe) != null ? _a : new Timeframe3(), timeframe);
1509
+ const newTimeframe = Timeframe3.merge(this._targetTimeframe ?? new Timeframe3(), timeframe);
1276
1510
  await this._params.metadataStore.setSpaceDataLatestTimeframe(this._params.spaceKey, newTimeframe);
1277
1511
  this._targetTimeframe = newTimeframe;
1278
1512
  }
1279
1513
  async _saveCache() {
1280
- var _a;
1281
1514
  const cache = {};
1282
1515
  try {
1283
- const propertiesItem = this.itemManager.items.find((item) => {
1284
- var _a2, _b;
1285
- return ((_a2 = item.modelMeta) == null ? void 0 : _a2.type) === "dxos:model/document" && ((_b = getStateMachineFromItem(item)) == null ? void 0 : _b.snapshot()).type === "dxos.sdk.client.Properties";
1286
- });
1516
+ const propertiesItem = this.itemManager.items.find((item) => item.modelMeta?.type === "dxos:model/document" && // TODO(burdon): Document?
1517
+ (getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
1287
1518
  if (propertiesItem) {
1288
- cache.properties = (_a = getStateMachineFromItem(propertiesItem)) == null ? void 0 : _a.snapshot();
1519
+ cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
1289
1520
  }
1290
1521
  } catch (err) {
1291
1522
  log8.warn("Failed to cache properties", err, {
1292
- F: __dxlog_file8,
1293
- L: 278,
1523
+ F: __dxlog_file9,
1524
+ L: 291,
1294
1525
  S: this,
1295
1526
  C: (f, a) => f(...a)
1296
1527
  });
@@ -1307,24 +1538,23 @@ var DataPipeline = class DataPipeline2 {
1307
1538
  }
1308
1539
  }
1309
1540
  async _processEpochInSeparateTask(epoch) {
1310
- var _a;
1311
1541
  if (epoch.subject.assertion.number <= this._lastProcessedEpoch) {
1312
1542
  return;
1313
1543
  }
1314
- await ((_a = this._epochCtx) == null ? void 0 : _a.dispose());
1544
+ await this._epochCtx?.dispose();
1315
1545
  const ctx = new Context4({
1316
1546
  onError: (err) => {
1317
1547
  if (err instanceof CancelledError) {
1318
1548
  log8("Epoch processing cancelled.", void 0, {
1319
- F: __dxlog_file8,
1320
- L: 310,
1549
+ F: __dxlog_file9,
1550
+ L: 323,
1321
1551
  S: this,
1322
1552
  C: (f, a) => f(...a)
1323
1553
  });
1324
1554
  } else {
1325
1555
  log8.catch(err, void 0, {
1326
- F: __dxlog_file8,
1327
- L: 312,
1556
+ F: __dxlog_file9,
1557
+ L: 325,
1328
1558
  S: this,
1329
1559
  C: (f, a) => f(...a)
1330
1560
  });
@@ -1336,28 +1566,36 @@ var DataPipeline = class DataPipeline2 {
1336
1566
  if (!this._isOpen) {
1337
1567
  return;
1338
1568
  }
1339
- log8("process epoch", {
1340
- epoch
1341
- }, {
1342
- F: __dxlog_file8,
1343
- L: 322,
1344
- S: this,
1345
- C: (f, a) => f(...a)
1346
- });
1347
1569
  await this._processEpoch(ctx, epoch.subject.assertion);
1348
1570
  this.appliedEpoch = epoch;
1349
1571
  this.onNewEpoch.emit(epoch);
1350
1572
  });
1351
1573
  }
1352
1574
  async _processEpoch(ctx, epoch) {
1353
- invariant8(this._isOpen, "Space is closed.");
1354
- invariant8(this._pipeline);
1575
+ invariant8(this._isOpen, "Space is closed.", {
1576
+ F: __dxlog_file9,
1577
+ L: 344,
1578
+ S: this,
1579
+ A: [
1580
+ "this._isOpen",
1581
+ "'Space is closed.'"
1582
+ ]
1583
+ });
1584
+ invariant8(this._pipeline, void 0, {
1585
+ F: __dxlog_file9,
1586
+ L: 345,
1587
+ S: this,
1588
+ A: [
1589
+ "this._pipeline",
1590
+ ""
1591
+ ]
1592
+ });
1355
1593
  this._lastProcessedEpoch = epoch.number;
1356
- log8("Processing epoch", {
1357
- epoch
1594
+ log8("processing", {
1595
+ epoch: omit(epoch, "proof")
1358
1596
  }, {
1359
- F: __dxlog_file8,
1360
- L: 336,
1597
+ F: __dxlog_file9,
1598
+ L: 348,
1361
1599
  S: this,
1362
1600
  C: (f, a) => f(...a)
1363
1601
  });
@@ -1365,9 +1603,9 @@ var DataPipeline = class DataPipeline2 {
1365
1603
  const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
1366
1604
  this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
1367
1605
  }
1368
- log8("restarting pipeline for epoch", void 0, {
1369
- F: __dxlog_file8,
1370
- L: 344,
1606
+ log8("restarting pipeline from epoch", void 0, {
1607
+ F: __dxlog_file9,
1608
+ L: 354,
1371
1609
  S: this,
1372
1610
  C: (f, a) => f(...a)
1373
1611
  });
@@ -1376,12 +1614,36 @@ var DataPipeline = class DataPipeline2 {
1376
1614
  await this._pipeline.unpause();
1377
1615
  }
1378
1616
  async waitUntilTimeframe(timeframe) {
1379
- invariant8(this._pipeline, "Pipeline is not initialized.");
1617
+ invariant8(this._pipeline, "Pipeline is not initialized.", {
1618
+ F: __dxlog_file9,
1619
+ L: 361,
1620
+ S: this,
1621
+ A: [
1622
+ "this._pipeline",
1623
+ "'Pipeline is not initialized.'"
1624
+ ]
1625
+ });
1380
1626
  await this._pipeline.state.waitUntilTimeframe(timeframe);
1381
1627
  }
1382
1628
  async createEpoch() {
1383
- invariant8(this._pipeline);
1384
- invariant8(this.currentEpoch);
1629
+ invariant8(this._pipeline, void 0, {
1630
+ F: __dxlog_file9,
1631
+ L: 367,
1632
+ S: this,
1633
+ A: [
1634
+ "this._pipeline",
1635
+ ""
1636
+ ]
1637
+ });
1638
+ invariant8(this.currentEpoch, void 0, {
1639
+ F: __dxlog_file9,
1640
+ L: 368,
1641
+ S: this,
1642
+ A: [
1643
+ "this.currentEpoch",
1644
+ ""
1645
+ ]
1646
+ });
1385
1647
  await this._pipeline.pause();
1386
1648
  const snapshot = await this._createSnapshot();
1387
1649
  const snapshotCid = await this._params.snapshotManager.store(snapshot);
@@ -1398,6 +1660,12 @@ var DataPipeline = class DataPipeline2 {
1398
1660
  await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
1399
1661
  }
1400
1662
  };
1663
+ _ts_decorate5([
1664
+ trace.metricsCounter()
1665
+ ], DataPipeline.prototype, "_usage", void 0);
1666
+ _ts_decorate5([
1667
+ trace.metricsCounter()
1668
+ ], DataPipeline.prototype, "_mutations", void 0);
1401
1669
  _ts_decorate5([
1402
1670
  synchronized3
1403
1671
  ], DataPipeline.prototype, "open", null);
@@ -1411,29 +1679,45 @@ _ts_decorate5([
1411
1679
  synchronized3
1412
1680
  ], DataPipeline.prototype, "createEpoch", null);
1413
1681
  DataPipeline = _ts_decorate5([
1414
- trackLeaks2("open", "close")
1682
+ trackLeaks2("open", "close"),
1683
+ trace.resource()
1415
1684
  ], DataPipeline);
1416
1685
 
1417
1686
  // packages/core/echo/echo-pipeline/src/space/space.ts
1418
- import invariant9 from "tiny-invariant";
1419
1687
  import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeaks3, Lock } from "@dxos/async";
1688
+ import { invariant as invariant9 } from "@dxos/invariant";
1420
1689
  import { log as log10, logInfo } from "@dxos/log";
1421
1690
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
1691
+ import { trace as trace3 } from "@dxos/tracing";
1422
1692
  import { Callback as Callback2 } from "@dxos/util";
1423
1693
 
1424
1694
  // packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
1695
+ import { Context as Context5 } from "@dxos/context";
1425
1696
  import { SpaceStateMachine } from "@dxos/credentials";
1426
1697
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1427
1698
  import { log as log9 } from "@dxos/log";
1428
1699
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1429
1700
  import { Timeframe as Timeframe4 } from "@dxos/timeframe";
1701
+ import { TimeSeriesCounter as TimeSeriesCounter2, TimeUsageCounter as TimeUsageCounter2, trace as trace2 } from "@dxos/tracing";
1430
1702
  import { Callback, tracer as tracer2 } from "@dxos/util";
1431
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1703
+ function _ts_decorate6(decorators, target, key, desc) {
1704
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1705
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1706
+ r = Reflect.decorate(decorators, target, key, desc);
1707
+ else
1708
+ for (var i = decorators.length - 1; i >= 0; i--)
1709
+ if (d = decorators[i])
1710
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1711
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1712
+ }
1713
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1432
1714
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
1433
- var ControlPipeline = class {
1715
+ var ControlPipeline = class ControlPipeline2 {
1434
1716
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
1435
1717
  this._lastTimeframeSaveTime = Date.now();
1436
1718
  this.onFeedAdmitted = new Callback();
1719
+ this._usage = new TimeUsageCounter2();
1720
+ this._mutations = new TimeSeriesCounter2();
1437
1721
  this._spaceKey = spaceKey;
1438
1722
  this._metadata = metadataStore;
1439
1723
  this._pipeline = new Pipeline();
@@ -1443,8 +1727,8 @@ var ControlPipeline = class {
1443
1727
  log9("feed admitted", {
1444
1728
  key: info.key
1445
1729
  }, {
1446
- F: __dxlog_file9,
1447
- L: 51,
1730
+ F: __dxlog_file10,
1731
+ L: 61,
1448
1732
  S: this,
1449
1733
  C: (f, a) => f(...a)
1450
1734
  });
@@ -1454,8 +1738,8 @@ var ControlPipeline = class {
1454
1738
  await this._pipeline.addFeed(feed);
1455
1739
  } catch (err) {
1456
1740
  log9.catch(err, void 0, {
1457
- F: __dxlog_file9,
1458
- L: 59,
1741
+ F: __dxlog_file10,
1742
+ L: 69,
1459
1743
  S: this,
1460
1744
  C: (f, a) => f(...a)
1461
1745
  });
@@ -1477,58 +1761,67 @@ var ControlPipeline = class {
1477
1761
  }
1478
1762
  async start() {
1479
1763
  log9("starting...", void 0, {
1480
- F: __dxlog_file9,
1481
- L: 83,
1764
+ F: __dxlog_file10,
1765
+ L: 93,
1482
1766
  S: this,
1483
1767
  C: (f, a) => f(...a)
1484
1768
  });
1485
1769
  setTimeout(async () => {
1486
- for await (const msg of this._pipeline.consume()) {
1487
- try {
1488
- log9("processing", {
1489
- key: msg.feedKey,
1490
- seq: msg.seq
1491
- }, {
1492
- F: __dxlog_file9,
1493
- L: 88,
1494
- S: this,
1495
- C: (f, a) => f(...a)
1496
- });
1497
- if (msg.data.payload.credential) {
1498
- const timer = tracer2.mark("dxos.echo.pipeline.control");
1499
- const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1500
- timer.end();
1501
- if (!result) {
1502
- log9.warn("processing failed", {
1503
- msg
1504
- }, {
1505
- F: __dxlog_file9,
1506
- L: 98,
1507
- S: this,
1508
- C: (f, a) => f(...a)
1509
- });
1510
- } else {
1511
- await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1512
- }
1513
- }
1514
- } catch (err) {
1515
- log9.catch(err, void 0, {
1516
- F: __dxlog_file9,
1517
- L: 104,
1518
- S: this,
1519
- C: (f, a) => f(...a)
1520
- });
1521
- }
1522
- }
1770
+ void this._consumePipeline(new Context5());
1523
1771
  });
1524
1772
  await this._pipeline.start();
1525
1773
  log9("started", void 0, {
1526
- F: __dxlog_file9,
1527
- L: 110,
1774
+ F: __dxlog_file10,
1775
+ L: 99,
1528
1776
  S: this,
1529
1777
  C: (f, a) => f(...a)
1530
1778
  });
1531
1779
  }
1780
+ async _consumePipeline(ctx) {
1781
+ for await (const msg of this._pipeline.consume()) {
1782
+ const span = this._usage.beginRecording();
1783
+ this._mutations.inc();
1784
+ try {
1785
+ await this._processMessage(ctx, msg);
1786
+ } catch (err) {
1787
+ log9.catch(err, void 0, {
1788
+ F: __dxlog_file10,
1789
+ L: 111,
1790
+ S: this,
1791
+ C: (f, a) => f(...a)
1792
+ });
1793
+ }
1794
+ span.end();
1795
+ }
1796
+ }
1797
+ async _processMessage(ctx, msg) {
1798
+ log9("processing", {
1799
+ key: msg.feedKey,
1800
+ seq: msg.seq
1801
+ }, {
1802
+ F: __dxlog_file10,
1803
+ L: 121,
1804
+ S: this,
1805
+ C: (f, a) => f(...a)
1806
+ });
1807
+ if (msg.data.payload.credential) {
1808
+ const timer = tracer2.mark("dxos.echo.pipeline.control");
1809
+ const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
1810
+ timer.end();
1811
+ if (!result) {
1812
+ log9.warn("processing failed", {
1813
+ msg
1814
+ }, {
1815
+ F: __dxlog_file10,
1816
+ L: 131,
1817
+ S: this,
1818
+ C: (f, a) => f(...a)
1819
+ });
1820
+ } else {
1821
+ await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1822
+ }
1823
+ }
1824
+ }
1532
1825
  async _noteTargetStateIfNeeded(timeframe) {
1533
1826
  if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2) {
1534
1827
  this._lastTimeframeSaveTime = Date.now();
@@ -1537,39 +1830,53 @@ var ControlPipeline = class {
1537
1830
  }
1538
1831
  async stop() {
1539
1832
  log9("stopping...", void 0, {
1540
- F: __dxlog_file9,
1541
- L: 124,
1833
+ F: __dxlog_file10,
1834
+ L: 149,
1542
1835
  S: this,
1543
1836
  C: (f, a) => f(...a)
1544
1837
  });
1545
1838
  await this._pipeline.stop();
1546
1839
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1547
1840
  log9("stopped", void 0, {
1548
- F: __dxlog_file9,
1549
- L: 127,
1841
+ F: __dxlog_file10,
1842
+ L: 152,
1550
1843
  S: this,
1551
1844
  C: (f, a) => f(...a)
1552
1845
  });
1553
1846
  }
1554
1847
  async _saveTargetTimeframe(timeframe) {
1555
- var _a;
1556
1848
  try {
1557
- const newTimeframe = Timeframe4.merge((_a = this._targetTimeframe) != null ? _a : new Timeframe4(), timeframe);
1849
+ const newTimeframe = Timeframe4.merge(this._targetTimeframe ?? new Timeframe4(), timeframe);
1558
1850
  await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
1559
1851
  this._targetTimeframe = newTimeframe;
1560
1852
  } catch (err) {
1561
1853
  log9(err, void 0, {
1562
- F: __dxlog_file9,
1563
- L: 136,
1854
+ F: __dxlog_file10,
1855
+ L: 161,
1564
1856
  S: this,
1565
1857
  C: (f, a) => f(...a)
1566
1858
  });
1567
1859
  }
1568
1860
  }
1569
1861
  };
1862
+ _ts_decorate6([
1863
+ trace2.metricsCounter()
1864
+ ], ControlPipeline.prototype, "_usage", void 0);
1865
+ _ts_decorate6([
1866
+ trace2.metricsCounter()
1867
+ ], ControlPipeline.prototype, "_mutations", void 0);
1868
+ _ts_decorate6([
1869
+ trace2.span()
1870
+ ], ControlPipeline.prototype, "_consumePipeline", null);
1871
+ _ts_decorate6([
1872
+ trace2.span()
1873
+ ], ControlPipeline.prototype, "_processMessage", null);
1874
+ ControlPipeline = _ts_decorate6([
1875
+ trace2.resource()
1876
+ ], ControlPipeline);
1570
1877
 
1571
1878
  // packages/core/echo/echo-pipeline/src/space/space.ts
1572
- function _ts_decorate6(decorators, target, key, desc) {
1879
+ function _ts_decorate7(decorators, target, key, desc) {
1573
1880
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1574
1881
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1575
1882
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1579,14 +1886,22 @@ function _ts_decorate6(decorators, target, key, desc) {
1579
1886
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1580
1887
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1581
1888
  }
1582
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
1889
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
1583
1890
  var Space = class Space2 {
1584
1891
  constructor(params) {
1585
1892
  this._addFeedLock = new Lock();
1586
1893
  this.onCredentialProcessed = new Callback2();
1587
1894
  this.stateUpdate = new Event5();
1588
1895
  this._isOpen = false;
1589
- invariant9(params.spaceKey && params.feedProvider);
1896
+ invariant9(params.spaceKey && params.feedProvider, void 0, {
1897
+ F: __dxlog_file11,
1898
+ L: 73,
1899
+ S: this,
1900
+ A: [
1901
+ "params.spaceKey && params.feedProvider",
1902
+ ""
1903
+ ]
1904
+ });
1590
1905
  this._key = params.spaceKey;
1591
1906
  this._genesisFeedKey = params.genesisFeed.key;
1592
1907
  this._feedProvider = params.feedProvider;
@@ -1621,8 +1936,8 @@ var Space = class Space2 {
1621
1936
  log10("onCredentialProcessed", {
1622
1937
  credential
1623
1938
  }, {
1624
- F: __dxlog_file10,
1625
- L: 107,
1939
+ F: __dxlog_file11,
1940
+ L: 109,
1626
1941
  S: this,
1627
1942
  C: (f, a) => f(...a)
1628
1943
  });
@@ -1664,12 +1979,10 @@ var Space = class Space2 {
1664
1979
  return this._genesisFeedKey;
1665
1980
  }
1666
1981
  get controlFeedKey() {
1667
- var _a;
1668
- return (_a = this._controlFeed) == null ? void 0 : _a.key;
1982
+ return this._controlFeed?.key;
1669
1983
  }
1670
1984
  get dataFeedKey() {
1671
- var _a;
1672
- return (_a = this._dataFeed) == null ? void 0 : _a.key;
1985
+ return this._dataFeed?.key;
1673
1986
  }
1674
1987
  get spaceState() {
1675
1988
  return this._controlPipeline.spaceState;
@@ -1687,16 +2000,31 @@ var Space = class Space2 {
1687
2000
  return this._snapshotManager;
1688
2001
  }
1689
2002
  setControlFeed(feed) {
1690
- invariant9(!this._controlFeed, "Control feed already set.");
2003
+ invariant9(!this._controlFeed, "Control feed already set.", {
2004
+ F: __dxlog_file11,
2005
+ L: 184,
2006
+ S: this,
2007
+ A: [
2008
+ "!this._controlFeed",
2009
+ "'Control feed already set.'"
2010
+ ]
2011
+ });
1691
2012
  this._controlFeed = feed;
1692
2013
  this._controlPipeline.setWriteFeed(feed);
1693
2014
  return this;
1694
2015
  }
1695
2016
  setDataFeed(feed) {
1696
- var _a;
1697
- invariant9(!this._dataFeed, "Data feed already set.");
2017
+ invariant9(!this._dataFeed, "Data feed already set.", {
2018
+ F: __dxlog_file11,
2019
+ L: 191,
2020
+ S: this,
2021
+ A: [
2022
+ "!this._dataFeed",
2023
+ "'Data feed already set.'"
2024
+ ]
2025
+ });
1698
2026
  this._dataFeed = feed;
1699
- (_a = this._dataPipeline.pipeline) == null ? void 0 : _a.setWriteFeed(feed);
2027
+ this._dataPipeline.pipeline?.setWriteFeed(feed);
1700
2028
  return this;
1701
2029
  }
1702
2030
  /**
@@ -1711,10 +2039,10 @@ var Space = class Space2 {
1711
2039
  // getDataFeeds(): FeedInfo[] {
1712
2040
  // return this._dataPipeline?.getFeeds();
1713
2041
  // }
1714
- async open() {
2042
+ async open(ctx) {
1715
2043
  log10("opening...", void 0, {
1716
- F: __dxlog_file10,
1717
- L: 209,
2044
+ F: __dxlog_file11,
2045
+ L: 213,
1718
2046
  S: this,
1719
2047
  C: (f, a) => f(...a)
1720
2048
  });
@@ -1726,8 +2054,8 @@ var Space = class Space2 {
1726
2054
  await this._controlPipeline.spaceState.addCredentialProcessor(this._dataPipeline);
1727
2055
  this._isOpen = true;
1728
2056
  log10("opened", void 0, {
1729
- F: __dxlog_file10,
1730
- L: 220,
2057
+ F: __dxlog_file11,
2058
+ L: 224,
1731
2059
  S: this,
1732
2060
  C: (f, a) => f(...a)
1733
2061
  });
@@ -1736,8 +2064,8 @@ var Space = class Space2 {
1736
2064
  log10("closing...", {
1737
2065
  key: this._key
1738
2066
  }, {
1739
- F: __dxlog_file10,
1740
- L: 225,
2067
+ F: __dxlog_file11,
2068
+ L: 229,
1741
2069
  S: this,
1742
2070
  C: (f, a) => f(...a)
1743
2071
  });
@@ -1750,37 +2078,48 @@ var Space = class Space2 {
1750
2078
  await this._controlPipeline.stop();
1751
2079
  this._isOpen = false;
1752
2080
  log10("closed", void 0, {
1753
- F: __dxlog_file10,
1754
- L: 238,
2081
+ F: __dxlog_file11,
2082
+ L: 242,
1755
2083
  S: this,
1756
2084
  C: (f, a) => f(...a)
1757
2085
  });
1758
2086
  }
1759
2087
  async initializeDataPipeline() {
1760
2088
  log10("initializeDataPipeline", void 0, {
1761
- F: __dxlog_file10,
1762
- L: 243,
2089
+ F: __dxlog_file11,
2090
+ L: 247,
1763
2091
  S: this,
1764
2092
  C: (f, a) => f(...a)
1765
2093
  });
1766
- invariant9(this._isOpen, "Space must be open to initialize data pipeline.");
2094
+ invariant9(this._isOpen, "Space must be open to initialize data pipeline.", {
2095
+ F: __dxlog_file11,
2096
+ L: 248,
2097
+ S: this,
2098
+ A: [
2099
+ "this._isOpen",
2100
+ "'Space must be open to initialize data pipeline.'"
2101
+ ]
2102
+ });
1767
2103
  await this._dataPipeline.open();
1768
2104
  }
1769
2105
  };
1770
- _ts_decorate6([
1771
- logInfo
2106
+ _ts_decorate7([
2107
+ logInfo,
2108
+ trace3.info()
1772
2109
  ], Space.prototype, "key", null);
1773
- _ts_decorate6([
1774
- synchronized4
2110
+ _ts_decorate7([
2111
+ synchronized4,
2112
+ trace3.span()
1775
2113
  ], Space.prototype, "open", null);
1776
- _ts_decorate6([
2114
+ _ts_decorate7([
1777
2115
  synchronized4
1778
2116
  ], Space.prototype, "close", null);
1779
- _ts_decorate6([
2117
+ _ts_decorate7([
1780
2118
  synchronized4
1781
2119
  ], Space.prototype, "initializeDataPipeline", null);
1782
- Space = _ts_decorate6([
1783
- trackLeaks3("open", "close")
2120
+ Space = _ts_decorate7([
2121
+ trackLeaks3("open", "close"),
2122
+ trace3.resource()
1784
2123
  ], Space);
1785
2124
 
1786
2125
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
@@ -1792,7 +2131,7 @@ import { Teleport } from "@dxos/teleport";
1792
2131
  import { BlobSync } from "@dxos/teleport-extension-object-sync";
1793
2132
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
1794
2133
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1795
- function _ts_decorate7(decorators, target, key, desc) {
2134
+ function _ts_decorate8(decorators, target, key, desc) {
1796
2135
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1797
2136
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1798
2137
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1802,7 +2141,7 @@ function _ts_decorate7(decorators, target, key, desc) {
1802
2141
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1803
2142
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1804
2143
  }
1805
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
2144
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1806
2145
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1807
2146
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1808
2147
  var SpaceProtocol = class {
@@ -1832,8 +2171,8 @@ var SpaceProtocol = class {
1832
2171
  log11("addFeed", {
1833
2172
  key: feed.key
1834
2173
  }, {
1835
- F: __dxlog_file11,
1836
- L: 95,
2174
+ F: __dxlog_file12,
2175
+ L: 96,
1837
2176
  S: this,
1838
2177
  C: (f, a) => f(...a)
1839
2178
  });
@@ -1842,6 +2181,7 @@ var SpaceProtocol = class {
1842
2181
  session.replicator.addFeed(feed);
1843
2182
  }
1844
2183
  }
2184
+ // TODO(burdon): Rename open? Common open/close interfaces for all services?
1845
2185
  async start() {
1846
2186
  if (this._connection) {
1847
2187
  return;
@@ -1854,8 +2194,8 @@ var SpaceProtocol = class {
1854
2194
  };
1855
2195
  await this.blobSync.open();
1856
2196
  log11("starting...", void 0, {
1857
- F: __dxlog_file11,
1858
- L: 120,
2197
+ F: __dxlog_file12,
2198
+ L: 122,
1859
2199
  S: this,
1860
2200
  C: (f, a) => f(...a)
1861
2201
  });
@@ -1865,11 +2205,11 @@ var SpaceProtocol = class {
1865
2205
  peerId: this._swarmIdentity.peerKey,
1866
2206
  topic,
1867
2207
  topology: new MMSTTopology(topologyConfig),
1868
- label: `Protocol swarm: ${topic}`
2208
+ label: `space swarm ${topic.truncate()}`
1869
2209
  });
1870
2210
  log11("started", void 0, {
1871
- F: __dxlog_file11,
1872
- L: 130,
2211
+ F: __dxlog_file12,
2212
+ L: 132,
1873
2213
  S: this,
1874
2214
  C: (f, a) => f(...a)
1875
2215
  });
@@ -1878,15 +2218,15 @@ var SpaceProtocol = class {
1878
2218
  await this.blobSync.close();
1879
2219
  if (this._connection) {
1880
2220
  log11("stopping...", void 0, {
1881
- F: __dxlog_file11,
1882
- L: 137,
2221
+ F: __dxlog_file12,
2222
+ L: 139,
1883
2223
  S: this,
1884
2224
  C: (f, a) => f(...a)
1885
2225
  });
1886
2226
  await this._connection.close();
1887
2227
  log11("stopped", void 0, {
1888
- F: __dxlog_file11,
1889
- L: 139,
2228
+ F: __dxlog_file12,
2229
+ L: 141,
1890
2230
  S: this,
1891
2231
  C: (f, a) => f(...a)
1892
2232
  });
@@ -1909,10 +2249,10 @@ var SpaceProtocol = class {
1909
2249
  };
1910
2250
  }
1911
2251
  };
1912
- _ts_decorate7([
2252
+ _ts_decorate8([
1913
2253
  logInfo2
1914
2254
  ], SpaceProtocol.prototype, "_topic", void 0);
1915
- _ts_decorate7([
2255
+ _ts_decorate8([
1916
2256
  logInfo2
1917
2257
  ], SpaceProtocol.prototype, "_ownPeerKey", null);
1918
2258
  var AuthStatus;
@@ -1951,20 +2291,18 @@ var SpaceProtocolSession = class {
1951
2291
  provider: this._swarmIdentity.credentialProvider,
1952
2292
  verifier: this._swarmIdentity.credentialAuthenticator,
1953
2293
  onAuthSuccess: () => {
1954
- var _a;
1955
2294
  log11("Peer authenticated", void 0, {
1956
- F: __dxlog_file11,
1957
- L: 236,
2295
+ F: __dxlog_file12,
2296
+ L: 238,
1958
2297
  S: this,
1959
2298
  C: (f, a) => f(...a)
1960
2299
  });
1961
2300
  this._authStatus = AuthStatus.SUCCESS;
1962
- (_a = this._onSessionAuth) == null ? void 0 : _a.call(this, this._teleport);
2301
+ this._onSessionAuth?.(this._teleport);
1963
2302
  },
1964
2303
  onAuthFailure: () => {
1965
- var _a;
1966
2304
  this._authStatus = AuthStatus.FAILURE;
1967
- (_a = this._onAuthFailure) == null ? void 0 : _a.call(this, this._teleport);
2305
+ this._onAuthFailure?.(this._teleport);
1968
2306
  }
1969
2307
  }));
1970
2308
  this._teleport.addExtension("dxos.mesh.teleport.replicator", this.replicator);
@@ -1974,10 +2312,10 @@ var SpaceProtocolSession = class {
1974
2312
  await this._teleport.close();
1975
2313
  }
1976
2314
  };
1977
- _ts_decorate7([
2315
+ _ts_decorate8([
1978
2316
  logInfo2
1979
2317
  ], SpaceProtocolSession.prototype, "_wireParams", void 0);
1980
- _ts_decorate7([
2318
+ _ts_decorate8([
1981
2319
  logInfo2
1982
2320
  ], SpaceProtocolSession.prototype, "authStatus", null);
1983
2321
 
@@ -1986,9 +2324,9 @@ import { synchronized as synchronized5, trackLeaks as trackLeaks4 } from "@dxos/
1986
2324
  import { failUndefined as failUndefined2 } from "@dxos/debug";
1987
2325
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1988
2326
  import { log as log12 } from "@dxos/log";
1989
- import { trace } from "@dxos/protocols";
2327
+ import { trace as trace4 } from "@dxos/protocols";
1990
2328
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
1991
- function _ts_decorate8(decorators, target, key, desc) {
2329
+ function _ts_decorate9(decorators, target, key, desc) {
1992
2330
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1993
2331
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1994
2332
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1998,7 +2336,7 @@ function _ts_decorate8(decorators, target, key, desc) {
1998
2336
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1999
2337
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2000
2338
  }
2001
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
2339
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
2002
2340
  var SpaceManager = class SpaceManager2 {
2003
2341
  constructor({ feedStore, networkManager, modelFactory, metadataStore, snapshotStore, blobStore }) {
2004
2342
  this._spaces = new ComplexMap5(PublicKey6.hash);
@@ -2022,11 +2360,10 @@ var SpaceManager = class SpaceManager2 {
2022
2360
  ].map((space) => space.close()));
2023
2361
  }
2024
2362
  async constructSpace({ metadata, swarmIdentity, onNetworkConnection, onAuthFailure, memberKey }) {
2025
- var _a;
2026
- log12.trace("dxos.echo.space-manager.construct-space", trace.begin({
2363
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.begin({
2027
2364
  id: this._instanceId
2028
2365
  }), {
2029
- F: __dxlog_file12,
2366
+ F: __dxlog_file13,
2030
2367
  L: 97,
2031
2368
  S: this,
2032
2369
  C: (f, a) => f(...a)
@@ -2034,12 +2371,12 @@ var SpaceManager = class SpaceManager2 {
2034
2371
  log12("constructing space...", {
2035
2372
  spaceKey: metadata.genesisFeedKey
2036
2373
  }, {
2037
- F: __dxlog_file12,
2374
+ F: __dxlog_file13,
2038
2375
  L: 98,
2039
2376
  S: this,
2040
2377
  C: (f, a) => f(...a)
2041
2378
  });
2042
- const genesisFeed = await this._feedStore.openFeed((_a = metadata.genesisFeedKey) != null ? _a : failUndefined2());
2379
+ const genesisFeed = await this._feedStore.openFeed(metadata.genesisFeedKey ?? failUndefined2());
2043
2380
  const spaceKey = metadata.key;
2044
2381
  const protocol = new SpaceProtocol({
2045
2382
  topic: spaceKey,
@@ -2061,24 +2398,24 @@ var SpaceManager = class SpaceManager2 {
2061
2398
  memberKey
2062
2399
  });
2063
2400
  this._spaces.set(space.key, space);
2064
- log12.trace("dxos.echo.space-manager.construct-space", trace.end({
2401
+ log12.trace("dxos.echo.space-manager.construct-space", trace4.end({
2065
2402
  id: this._instanceId
2066
2403
  }), {
2067
- F: __dxlog_file12,
2068
- L: 125,
2404
+ F: __dxlog_file13,
2405
+ L: 126,
2069
2406
  S: this,
2070
2407
  C: (f, a) => f(...a)
2071
2408
  });
2072
2409
  return space;
2073
2410
  }
2074
2411
  };
2075
- _ts_decorate8([
2412
+ _ts_decorate9([
2076
2413
  synchronized5
2077
2414
  ], SpaceManager.prototype, "open", null);
2078
- _ts_decorate8([
2415
+ _ts_decorate9([
2079
2416
  synchronized5
2080
2417
  ], SpaceManager.prototype, "close", null);
2081
- SpaceManager = _ts_decorate8([
2418
+ SpaceManager = _ts_decorate9([
2082
2419
  trackLeaks4("open", "close")
2083
2420
  ], SpaceManager);
2084
2421
 
@@ -2108,4 +2445,4 @@ export {
2108
2445
  SpaceProtocolSession,
2109
2446
  SpaceManager
2110
2447
  };
2111
- //# sourceMappingURL=chunk-7U2NXI2P.mjs.map
2448
+ //# sourceMappingURL=chunk-GDF4DQU2.mjs.map