@dxos/echo-pipeline 0.1.53-main.b6f5d87 → 0.1.53-main.cb0c729

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 (49) hide show
  1. package/dist/lib/browser/{chunk-ZZV4HWSG.mjs → chunk-OJGL5427.mjs} +449 -397
  2. package/dist/lib/browser/chunk-OJGL5427.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +2 -2
  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 +3 -3
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node/index.cjs +503 -451
  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 +494 -442
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/types/src/dbhost/data-service-host.d.ts +3 -0
  14. package/dist/types/src/dbhost/data-service-host.d.ts.map +1 -1
  15. package/dist/types/src/dbhost/data-service.d.ts +2 -2
  16. package/dist/types/src/dbhost/data-service.d.ts.map +1 -1
  17. package/dist/types/src/dbhost/snapshot-manager.d.ts +2 -0
  18. package/dist/types/src/dbhost/snapshot-manager.d.ts.map +1 -1
  19. package/dist/types/src/dbhost/snapshot-store.d.ts +2 -0
  20. package/dist/types/src/dbhost/snapshot-store.d.ts.map +1 -1
  21. package/dist/types/src/metadata/metadata-store.d.ts +4 -0
  22. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  23. package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
  24. package/dist/types/src/pipeline/pipeline.d.ts +0 -1
  25. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  26. package/dist/types/src/space/data-pipeline.d.ts +3 -3
  27. package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
  28. package/dist/types/src/space/space-protocol.d.ts +3 -0
  29. package/dist/types/src/space/space-protocol.d.ts.map +1 -1
  30. package/dist/types/src/space/space.d.ts +0 -1
  31. package/dist/types/src/space/space.d.ts.map +1 -1
  32. package/package.json +31 -32
  33. package/src/common/feeds.ts +3 -3
  34. package/src/dbhost/data-service-host.ts +17 -4
  35. package/src/dbhost/data-service.ts +10 -6
  36. package/src/dbhost/snapshot-manager.ts +4 -4
  37. package/src/dbhost/snapshot-store.ts +3 -2
  38. package/src/metadata/metadata-store.ts +19 -6
  39. package/src/pipeline/message-selector.ts +3 -5
  40. package/src/pipeline/pipeline.ts +24 -12
  41. package/src/space/auth.ts +3 -3
  42. package/src/space/data-pipeline.ts +35 -29
  43. package/src/space/replication.browser.test.ts +2 -2
  44. package/src/space/space-protocol.ts +10 -4
  45. package/src/space/space.test.ts +46 -5
  46. package/src/space/space.ts +8 -17
  47. package/src/testing/util.ts +1 -1
  48. package/src/tests/database.test.ts +1 -1
  49. package/dist/lib/browser/chunk-ZZV4HWSG.mjs.map +0 -7
@@ -1,14 +1,15 @@
1
- import "@dxos/node-std/globals"
1
+ import "@dxos/node-std/globals";
2
2
 
3
3
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
4
4
  import CRC32 from "crc-32";
5
- import assert from "@dxos/node-std/assert";
5
+ import invariant from "tiny-invariant";
6
6
  import { synchronized, Event } from "@dxos/async";
7
7
  import { DataCorruptionError } from "@dxos/errors";
8
8
  import { log } from "@dxos/log";
9
9
  import { STORAGE_VERSION, schema } from "@dxos/protocols";
10
+ import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
10
11
  import { arrayToBuffer } from "@dxos/util";
11
- var __decorate = function(decorators, target, key, desc) {
12
+ function _ts_decorate(decorators, target, key, desc) {
12
13
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
14
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
14
15
  r = Reflect.decorate(decorators, target, key, desc);
@@ -17,13 +18,15 @@ var __decorate = function(decorators, target, key, desc) {
17
18
  if (d = decorators[i])
18
19
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
19
20
  return c > 3 && r && Object.defineProperty(target, key, r), r;
20
- };
21
+ }
22
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
21
23
  var emptyEchoMetadata = () => ({
22
24
  version: STORAGE_VERSION,
23
25
  spaces: [],
24
26
  created: new Date(),
25
27
  updated: new Date()
26
28
  });
29
+ var EchoMetadata = schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
27
30
  var MetadataStore = class {
28
31
  // prettier-ignore
29
32
  constructor(_directory) {
@@ -50,6 +53,7 @@ var MetadataStore = class {
50
53
  * Loads metadata from persistent storage.
51
54
  */
52
55
  async load() {
56
+ var _a;
53
57
  const file = this._directory.getOrCreateFile("EchoMetadata");
54
58
  try {
55
59
  const { size: fileLength } = await file.stat();
@@ -62,10 +66,10 @@ var MetadataStore = class {
62
66
  size: dataSize,
63
67
  checksum
64
68
  }, {
65
- file: "metadata-store.ts",
66
- line: 69,
67
- scope: this,
68
- callSite: (f, a) => f(...a)
69
+ F: __dxlog_file,
70
+ L: 72,
71
+ S: this,
72
+ C: (f, a) => f(...a)
69
73
  });
70
74
  if (fileLength < dataSize + 8) {
71
75
  throw new DataCorruptionError("Metadata size is smaller than expected.");
@@ -75,15 +79,19 @@ var MetadataStore = class {
75
79
  if (calculatedChecksum !== checksum) {
76
80
  throw new DataCorruptionError("Metadata checksum is invalid.");
77
81
  }
78
- this._metadata = schema.getCodecForType("dxos.echo.metadata.EchoMetadata").decode(data);
82
+ this._metadata = EchoMetadata.decode(data);
83
+ (_a = this._metadata.spaces) == null ? void 0 : _a.forEach((space) => {
84
+ var _a2;
85
+ (_a2 = space.state) != null ? _a2 : space.state = SpaceState.ACTIVE;
86
+ });
79
87
  } catch (err) {
80
88
  log.error("failed to load metadata", {
81
89
  err
82
90
  }, {
83
- file: "metadata-store.ts",
84
- line: 84,
85
- scope: this,
86
- callSite: (f, a) => f(...a)
91
+ F: __dxlog_file,
92
+ L: 92,
93
+ S: this,
94
+ C: (f, a) => f(...a)
87
95
  });
88
96
  this._metadata = emptyEchoMetadata();
89
97
  } finally {
@@ -101,7 +109,7 @@ var MetadataStore = class {
101
109
  this.update.emit(data);
102
110
  const file = this._directory.getOrCreateFile("EchoMetadata");
103
111
  try {
104
- const encoded = arrayToBuffer(schema.getCodecForType("dxos.echo.metadata.EchoMetadata").encode(data));
112
+ const encoded = arrayToBuffer(EchoMetadata.encode(data));
105
113
  const checksum = CRC32.buf(encoded);
106
114
  const result = Buffer.alloc(8 + encoded.length);
107
115
  result.writeInt32LE(encoded.length, 0);
@@ -112,10 +120,10 @@ var MetadataStore = class {
112
120
  size: encoded.length,
113
121
  checksum
114
122
  }, {
115
- file: "metadata-store.ts",
116
- line: 116,
117
- scope: this,
118
- callSite: (f, a) => f(...a)
123
+ F: __dxlog_file,
124
+ L: 124,
125
+ S: this,
126
+ C: (f, a) => f(...a)
119
127
  });
120
128
  } finally {
121
129
  await file.close();
@@ -127,18 +135,18 @@ var MetadataStore = class {
127
135
  return this._metadata.identity.haloSpace;
128
136
  }
129
137
  const space = this.spaces.find((space2) => space2.key === spaceKey);
130
- assert(space, "Space not found");
138
+ invariant(space, "Space not found");
131
139
  return space;
132
140
  }
133
141
  /**
134
142
  * Clears storage - doesn't work for now.
135
143
  */
136
144
  async clear() {
137
- log("clearing all metadata", {}, {
138
- file: "metadata-store.ts",
139
- line: 137,
140
- scope: this,
141
- callSite: (f, a) => f(...a)
145
+ log("clearing all metadata", void 0, {
146
+ F: __dxlog_file,
147
+ L: 145,
148
+ S: this,
149
+ C: (f, a) => f(...a)
142
150
  });
143
151
  await this._directory.delete();
144
152
  this._metadata = emptyEchoMetadata();
@@ -147,13 +155,13 @@ var MetadataStore = class {
147
155
  return this._metadata.identity;
148
156
  }
149
157
  async setIdentityRecord(record) {
150
- assert(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
158
+ invariant(!this._metadata.identity, "Cannot overwrite existing identity in metadata");
151
159
  this._metadata.identity = record;
152
160
  await this._save();
153
161
  }
154
162
  async addSpace(record) {
155
163
  var _a, _b, _c;
156
- assert(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
164
+ invariant(!((_a = this._metadata.spaces) != null ? _a : []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata");
157
165
  ((_c = (_b = this._metadata).spaces) != null ? _c : _b.spaces = []).push(record);
158
166
  await this._save();
159
167
  }
@@ -175,11 +183,15 @@ var MetadataStore = class {
175
183
  space.dataFeedKey = dataFeedKey;
176
184
  await this._save();
177
185
  }
186
+ async setSpaceState(spaceKey, state) {
187
+ this._getSpace(spaceKey).state = state;
188
+ await this._save();
189
+ }
178
190
  };
179
- __decorate([
191
+ _ts_decorate([
180
192
  synchronized
181
193
  ], MetadataStore.prototype, "load", null);
182
- __decorate([
194
+ _ts_decorate([
183
195
  synchronized
184
196
  ], MetadataStore.prototype, "_save", null);
185
197
  var fromBytesInt32 = (buf) => buf.readInt32LE(0);
@@ -191,10 +203,10 @@ var codec = schema2.getCodecForType("dxos.echo.feed.FeedMessage");
191
203
  var valueEncoding = createCodecEncoding(codec);
192
204
 
193
205
  // packages/core/echo/echo-pipeline/src/common/feeds.ts
194
- import assert2 from "@dxos/node-std/assert";
206
+ import invariant2 from "tiny-invariant";
195
207
  var createMappedFeedWriter = (mapper, writer) => {
196
- assert2(mapper);
197
- assert2(writer);
208
+ invariant2(mapper);
209
+ invariant2(writer);
198
210
  return {
199
211
  write: async (data, options) => await writer.write(await mapper(data), options)
200
212
  };
@@ -205,7 +217,7 @@ import { Event as Event2 } from "@dxos/async";
205
217
  import { timed } from "@dxos/debug";
206
218
  import { log as log2 } from "@dxos/log";
207
219
  import { Timeframe } from "@dxos/timeframe";
208
- var __decorate2 = function(decorators, target, key, desc) {
220
+ function _ts_decorate2(decorators, target, key, desc) {
209
221
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
210
222
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
211
223
  r = Reflect.decorate(decorators, target, key, desc);
@@ -214,7 +226,8 @@ var __decorate2 = function(decorators, target, key, desc) {
214
226
  if (d = decorators[i])
215
227
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
216
228
  return c > 3 && r && Object.defineProperty(target, key, r), r;
217
- };
229
+ }
230
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
218
231
  var mapTimeframeToFeedIndexes = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
219
232
  feedKey,
220
233
  index
@@ -273,10 +286,10 @@ var TimeframeClock = class {
273
286
  target,
274
287
  current: this._timeframe
275
288
  }, {
276
- file: "timeframe-clock.ts",
277
- line: 73,
278
- scope: this,
279
- callSite: (f, a) => f(...a)
289
+ F: __dxlog_file2,
290
+ L: 73,
291
+ S: this,
292
+ C: (f, a) => f(...a)
280
293
  });
281
294
  await this.update.waitForCondition(() => {
282
295
  log2("check if reached", {
@@ -284,21 +297,21 @@ var TimeframeClock = class {
284
297
  current: this._timeframe,
285
298
  deps: Timeframe.dependencies(target, this._timeframe)
286
299
  }, {
287
- file: "timeframe-clock.ts",
288
- line: 75,
289
- scope: this,
290
- callSite: (f, a) => f(...a)
300
+ F: __dxlog_file2,
301
+ L: 75,
302
+ S: this,
303
+ C: (f, a) => f(...a)
291
304
  });
292
305
  return Timeframe.dependencies(target, this._timeframe).isEmpty();
293
306
  });
294
307
  }
295
308
  };
296
- __decorate2([
309
+ _ts_decorate2([
297
310
  timed(5e3)
298
311
  ], TimeframeClock.prototype, "waitUntilReached", null);
299
312
 
300
313
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
301
- import assert4 from "@dxos/node-std/assert";
314
+ import invariant4 from "tiny-invariant";
302
315
  import { Event as Event3, sleep, synchronized as synchronized2, Trigger } from "@dxos/async";
303
316
  import { Context, rejectOnDispose } from "@dxos/context";
304
317
  import { failUndefined } from "@dxos/debug";
@@ -309,24 +322,29 @@ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
309
322
  import { ComplexMap } from "@dxos/util";
310
323
 
311
324
  // packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
312
- import debug from "debug";
313
- import assert3 from "@dxos/node-std/assert";
314
- var log3 = debug("dxos:echo-db:message-selector");
325
+ import invariant3 from "tiny-invariant";
326
+ import { log as log3 } from "@dxos/log";
327
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
315
328
  var createMessageSelector = (timeframeClock) => {
316
329
  return (messages) => {
317
330
  for (let i = 0; i < messages.length; i++) {
318
331
  const { data: { timeframe } } = messages[i];
319
- assert3(timeframe);
332
+ invariant3(timeframe);
320
333
  if (!timeframeClock.hasGaps(timeframe)) {
321
334
  return i;
322
335
  }
323
336
  }
324
- log3("Skipping...");
337
+ log3("Skipping...", void 0, {
338
+ F: __dxlog_file3,
339
+ L: 34,
340
+ S: void 0,
341
+ C: (f, a) => f(...a)
342
+ });
325
343
  };
326
344
  };
327
345
 
328
346
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
329
- var __decorate3 = function(decorators, target, key, desc) {
347
+ function _ts_decorate3(decorators, target, key, desc) {
330
348
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
331
349
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
332
350
  r = Reflect.decorate(decorators, target, key, desc);
@@ -335,12 +353,14 @@ var __decorate3 = function(decorators, target, key, desc) {
335
353
  if (d = decorators[i])
336
354
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
337
355
  return c > 3 && r && Object.defineProperty(target, key, r), r;
338
- };
356
+ }
357
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
339
358
  var PipelineState = class {
340
359
  // prettier-ignore
341
360
  constructor(_feeds, _timeframeClock) {
342
361
  this._feeds = _feeds;
343
362
  this._timeframeClock = _timeframeClock;
363
+ this._ctx = new Context();
344
364
  this.timeframeUpdate = this._timeframeClock.update;
345
365
  this.stalled = new Event3();
346
366
  this._startTimeframe = new Timeframe2();
@@ -391,10 +411,10 @@ var PipelineState = class {
391
411
  current: this.timeframe,
392
412
  target: this.targetTimeframe
393
413
  }, {
394
- file: "pipeline.ts",
395
- line: 118,
396
- scope: this,
397
- callSite: (f, a) => f(...a)
414
+ F: __dxlog_file4,
415
+ L: 126,
416
+ S: this,
417
+ C: (f, a) => f(...a)
398
418
  });
399
419
  (_a = this._reachedTargetPromise) != null ? _a : this._reachedTargetPromise = Promise.race([
400
420
  this._timeframeClock.update.waitForCondition(() => {
@@ -408,6 +428,7 @@ var PipelineState = class {
408
428
  if (timeout) {
409
429
  return Promise.race([
410
430
  rejectOnDispose(ctx),
431
+ rejectOnDispose(this._ctx),
411
432
  this._reachedTargetPromise.then(() => {
412
433
  done = true;
413
434
  }),
@@ -421,10 +442,10 @@ var PipelineState = class {
421
442
  target: this.targetTimeframe,
422
443
  dependencies: Timeframe2.dependencies(this.targetTimeframe, this.timeframe)
423
444
  }, {
424
- file: "pipeline.ts",
425
- line: 144,
426
- scope: this,
427
- callSite: (f, a) => f(...a)
445
+ F: __dxlog_file4,
446
+ L: 153,
447
+ S: this,
448
+ C: (f, a) => f(...a)
428
449
  });
429
450
  })
430
451
  ]);
@@ -451,7 +472,7 @@ var Pipeline = class {
451
472
  return this._state;
452
473
  }
453
474
  get writer() {
454
- assert4(this._writer, "Writer not set.");
475
+ invariant4(this._writer, "Writer not set.");
455
476
  return this._writer;
456
477
  }
457
478
  getFeeds() {
@@ -470,8 +491,8 @@ var Pipeline = class {
470
491
  return this._feeds.has(feedKey);
471
492
  }
472
493
  setWriteFeed(feed) {
473
- assert4(!this._writer, "Writer already set.");
474
- assert4(feed.properties.writable, "Feed must be writable.");
494
+ invariant4(!this._writer, "Writer already set.");
495
+ invariant4(feed.properties.writable, "Feed must be writable.");
475
496
  this._writer = createMappedFeedWriter((payload) => ({
476
497
  timeframe: this._timeframeClock.timeframe,
477
498
  payload
@@ -479,37 +500,40 @@ var Pipeline = class {
479
500
  }
480
501
  async start() {
481
502
  log4("starting...", {}, {
482
- file: "pipeline.ts",
483
- line: 264,
484
- scope: this,
485
- callSite: (f, a) => f(...a)
503
+ F: __dxlog_file4,
504
+ L: 273,
505
+ S: this,
506
+ C: (f, a) => f(...a)
486
507
  });
487
508
  await this._initIterator();
488
509
  await this._feedSetIterator.open();
489
- log4("started", {}, {
490
- file: "pipeline.ts",
491
- line: 267,
492
- scope: this,
493
- callSite: (f, a) => f(...a)
510
+ log4("started", void 0, {
511
+ F: __dxlog_file4,
512
+ L: 276,
513
+ S: this,
514
+ C: (f, a) => f(...a)
494
515
  });
495
516
  this._isStarted = true;
496
517
  }
497
518
  async stop() {
498
519
  var _a;
499
520
  log4("stopping...", {}, {
500
- file: "pipeline.ts",
501
- line: 273,
502
- scope: this,
503
- callSite: (f, a) => f(...a)
521
+ F: __dxlog_file4,
522
+ L: 282,
523
+ S: this,
524
+ C: (f, a) => f(...a)
504
525
  });
505
526
  this._isStopping = true;
506
527
  await ((_a = this._feedSetIterator) == null ? void 0 : _a.close());
507
528
  await this._processingTrigger.wait();
508
- log4("stopped", {}, {
509
- file: "pipeline.ts",
510
- line: 277,
511
- scope: this,
512
- callSite: (f, a) => f(...a)
529
+ await this._state._ctx.dispose();
530
+ this._state._ctx = new Context();
531
+ this._state._reachedTargetPromise = void 0;
532
+ log4("stopped", void 0, {
533
+ F: __dxlog_file4,
534
+ L: 289,
535
+ S: this,
536
+ C: (f, a) => f(...a)
513
537
  });
514
538
  this._isStarted = false;
515
539
  }
@@ -517,7 +541,7 @@ var Pipeline = class {
517
541
  * @param timeframe Timeframe of already processed messages. The pipeline will start processing messages AFTER this timeframe.
518
542
  */
519
543
  async setCursor(timeframe) {
520
- assert4(!this._isStarted || this._isPaused, "Invalid state.");
544
+ invariant4(!this._isStarted || this._isPaused, "Invalid state.");
521
545
  this._state._startTimeframe = timeframe;
522
546
  this._timeframeClock.setTimeframe(timeframe);
523
547
  for (const feed of this._feeds.values()) {
@@ -533,7 +557,7 @@ var Pipeline = class {
533
557
  * Calling pause while processing will cause a deadlock.
534
558
  */
535
559
  async pause() {
536
- assert4(this._isStarted, "Pipeline is not open.");
560
+ invariant4(this._isStarted, "Pipeline is not open.");
537
561
  if (this._isPaused) {
538
562
  return;
539
563
  }
@@ -542,8 +566,8 @@ var Pipeline = class {
542
566
  this._isPaused = true;
543
567
  }
544
568
  async unpause() {
545
- assert4(this._isStarted, "Pipeline is not open.");
546
- assert4(this._isPaused, "Pipeline is not paused.");
569
+ invariant4(this._isStarted, "Pipeline is not open.");
570
+ invariant4(this._isPaused, "Pipeline is not paused.");
547
571
  this._pauseTrigger.wake();
548
572
  this._isPaused = false;
549
573
  }
@@ -552,15 +576,15 @@ var Pipeline = class {
552
576
  * Updates the timeframe clock after the message has bee processed.
553
577
  */
554
578
  async *consume() {
555
- assert4(!this._isOpen, "Pipeline is already being consumed.");
579
+ invariant4(!this._isOpen, "Pipeline is already being consumed.");
556
580
  this._isOpen = true;
557
- assert4(this._feedSetIterator, "Iterator not initialized.");
581
+ invariant4(this._feedSetIterator, "Iterator not initialized.");
558
582
  let lastFeedSetIterator = this._feedSetIterator;
559
583
  let iterable = lastFeedSetIterator[Symbol.asyncIterator]();
560
584
  while (!this._isStopping) {
561
585
  await this._pauseTrigger.wait();
562
586
  if (lastFeedSetIterator !== this._feedSetIterator) {
563
- assert4(this._feedSetIterator, "Iterator not initialized.");
587
+ invariant4(this._feedSetIterator, "Iterator not initialized.");
564
588
  lastFeedSetIterator = this._feedSetIterator;
565
589
  iterable = lastFeedSetIterator[Symbol.asyncIterator]();
566
590
  }
@@ -582,11 +606,11 @@ var Pipeline = class {
582
606
  const timeframe = this._state._startTimeframe;
583
607
  const seq = (_a = timeframe.get(feed.key)) != null ? _a : 0;
584
608
  feed.undownload({
585
- callback: () => log4("Undownloaded", {}, {
586
- file: "pipeline.ts",
587
- line: 371,
588
- scope: this,
589
- callSite: (f, a) => f(...a)
609
+ callback: () => log4("Undownloaded", void 0, {
610
+ F: __dxlog_file4,
611
+ L: 383,
612
+ S: this,
613
+ C: (f, a) => f(...a)
590
614
  })
591
615
  });
592
616
  feed.download({
@@ -596,10 +620,10 @@ var Pipeline = class {
596
620
  log4("failed to download feed", {
597
621
  err
598
622
  }, {
599
- file: "pipeline.ts",
600
- line: 374,
601
- scope: this,
602
- callSite: (f, a) => f(...a)
623
+ F: __dxlog_file4,
624
+ L: 386,
625
+ S: this,
626
+ C: (f, a) => f(...a)
603
627
  });
604
628
  });
605
629
  }
@@ -609,11 +633,11 @@ var Pipeline = class {
609
633
  stallTimeout: 1e3
610
634
  });
611
635
  this._feedSetIterator.stalled.on((iterator) => {
612
- log4.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, {}, {
613
- file: "pipeline.ts",
614
- line: 384,
615
- scope: this,
616
- callSite: (f, a) => f(...a)
636
+ log4.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
637
+ F: __dxlog_file4,
638
+ L: 396,
639
+ S: this,
640
+ C: (f, a) => f(...a)
617
641
  });
618
642
  this._state.stalled.emit();
619
643
  });
@@ -622,30 +646,31 @@ var Pipeline = class {
622
646
  }
623
647
  }
624
648
  };
625
- __decorate3([
649
+ _ts_decorate3([
626
650
  synchronized2
627
651
  ], Pipeline.prototype, "start", null);
628
- __decorate3([
652
+ _ts_decorate3([
629
653
  synchronized2
630
654
  ], Pipeline.prototype, "stop", null);
631
- __decorate3([
655
+ _ts_decorate3([
632
656
  synchronized2
633
657
  ], Pipeline.prototype, "setCursor", null);
634
- __decorate3([
658
+ _ts_decorate3([
635
659
  synchronized2
636
660
  ], Pipeline.prototype, "pause", null);
637
- __decorate3([
661
+ _ts_decorate3([
638
662
  synchronized2
639
663
  ], Pipeline.prototype, "unpause", null);
640
664
 
641
665
  // packages/core/echo/echo-pipeline/src/space/auth.ts
642
- import assert5 from "@dxos/node-std/assert";
666
+ import invariant5 from "tiny-invariant";
643
667
  import { runInContext, scheduleTask } from "@dxos/async";
644
668
  import { Context as Context2 } from "@dxos/context";
645
669
  import { randomBytes } from "@dxos/crypto";
646
670
  import { log as log5 } from "@dxos/log";
647
671
  import { schema as schema3 } from "@dxos/protocols";
648
672
  import { RpcExtension } from "@dxos/teleport";
673
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
649
674
  var AuthExtension = class extends RpcExtension {
650
675
  constructor(_authParams) {
651
676
  super({
@@ -660,11 +685,11 @@ var AuthExtension = class extends RpcExtension {
660
685
  this._authParams = _authParams;
661
686
  this._ctx = new Context2({
662
687
  onError: (err) => {
663
- log5.catch(err, {}, {
664
- file: "auth.ts",
665
- line: 29,
666
- scope: this,
667
- callSite: (f, a) => f(...a)
688
+ log5.catch(err, void 0, {
689
+ F: __dxlog_file5,
690
+ L: 29,
691
+ S: this,
692
+ C: (f, a) => f(...a)
668
693
  });
669
694
  }
670
695
  });
@@ -683,10 +708,10 @@ var AuthExtension = class extends RpcExtension {
683
708
  };
684
709
  } catch (err) {
685
710
  log5.error("failed to generate auth credentials", err, {
686
- file: "auth.ts",
687
- line: 56,
688
- scope: this,
689
- callSite: (f, a) => f(...a)
711
+ F: __dxlog_file5,
712
+ L: 56,
713
+ S: this,
714
+ C: (f, a) => f(...a)
690
715
  });
691
716
  throw new Error("auth rejected");
692
717
  }
@@ -702,16 +727,16 @@ var AuthExtension = class extends RpcExtension {
702
727
  const { credential } = await this.rpc.AuthService.authenticate({
703
728
  challenge
704
729
  });
705
- assert5((credential == null ? void 0 : credential.length) > 0, "invalid credential");
730
+ invariant5((credential == null ? void 0 : credential.length) > 0, "invalid credential");
706
731
  const success = await this._authParams.verifier(challenge, credential);
707
- assert5(success, "credential not verified");
732
+ invariant5(success, "credential not verified");
708
733
  runInContext(this._ctx, () => this._authParams.onAuthSuccess());
709
734
  } catch (err) {
710
735
  log5("auth failed", err, {
711
- file: "auth.ts",
712
- line: 75,
713
- scope: this,
714
- callSite: (f, a) => f(...a)
736
+ F: __dxlog_file5,
737
+ L: 75,
738
+ S: this,
739
+ C: (f, a) => f(...a)
715
740
  });
716
741
  this.close();
717
742
  this._authParams.onAuthFailure();
@@ -725,23 +750,32 @@ var AuthExtension = class extends RpcExtension {
725
750
  };
726
751
 
727
752
  // packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts
728
- import assert6 from "@dxos/node-std/assert";
753
+ import invariant6 from "tiny-invariant";
729
754
  import { Stream } from "@dxos/codec-protobuf";
755
+ import { Context as Context3 } from "@dxos/context";
730
756
  import { tagMutationsInBatch, setMetadataOnObject } from "@dxos/echo-db";
731
757
  import { log as log6 } from "@dxos/log";
732
758
  import { ComplexMap as ComplexMap2 } from "@dxos/util";
759
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts";
733
760
  var DataServiceHost = class {
734
761
  constructor(_itemManager, _itemDemuxer, _writeStream) {
735
762
  this._itemManager = _itemManager;
736
763
  this._itemDemuxer = _itemDemuxer;
737
764
  this._writeStream = _writeStream;
765
+ this._ctx = new Context3();
738
766
  this._clientTagMap = new ComplexMap2(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
739
767
  }
768
+ async open() {
769
+ }
770
+ async close() {
771
+ await this._ctx.dispose();
772
+ }
740
773
  /**
741
774
  * Real-time subscription to data objects in a space.
742
775
  */
743
776
  subscribe() {
744
- return new Stream(({ next, ctx }) => {
777
+ return new Stream(({ next, close, ctx }) => {
778
+ ctx.onDispose(this._ctx.onDispose(close));
745
779
  const objects = Array.from(this._itemManager.entities.values()).map((entity) => entity.createSnapshot());
746
780
  next({
747
781
  batch: {
@@ -751,15 +785,15 @@ var DataServiceHost = class {
751
785
  this._itemDemuxer.mutation.on(ctx, (message) => {
752
786
  var _a;
753
787
  const { batch, meta } = message;
754
- assert6(!meta.clientTag, "Unexpected client tag in mutation message");
788
+ invariant6(!meta.clientTag, "Unexpected client tag in mutation message");
755
789
  log6("message", {
756
790
  batch,
757
791
  meta
758
792
  }, {
759
- file: "data-service-host.ts",
760
- line: 51,
761
- scope: this,
762
- callSite: (f, a) => f(...a)
793
+ F: __dxlog_file6,
794
+ L: 63,
795
+ S: this,
796
+ C: (f, a) => f(...a)
763
797
  });
764
798
  const clientTag = this._clientTagMap.get([
765
799
  message.meta.feedKey,
@@ -784,15 +818,16 @@ var DataServiceHost = class {
784
818
  }
785
819
  async write(request) {
786
820
  var _a, _b;
787
- assert6(this._writeStream, "Cannot write mutations in readonly mode");
821
+ invariant6(!this._ctx.disposed, "Cannot write to closed DataServiceHost");
822
+ invariant6(this._writeStream, "Cannot write mutations in readonly mode");
788
823
  log6("write", {
789
824
  clientTag: request.clientTag,
790
825
  objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
791
826
  }, {
792
- file: "data-service-host.ts",
793
- line: 79,
794
- scope: this,
795
- callSite: (f, a) => f(...a)
827
+ F: __dxlog_file6,
828
+ L: 92,
829
+ S: this,
830
+ C: (f, a) => f(...a)
796
831
  });
797
832
  const message = createDataMessage(request.batch);
798
833
  const receipt = await this._writeStream.write(message, {
@@ -803,10 +838,10 @@ var DataServiceHost = class {
803
838
  feedKey: receipt2.feedKey,
804
839
  seq: receipt2.seq
805
840
  }, {
806
- file: "data-service-host.ts",
807
- line: 88,
808
- scope: this,
809
- callSite: (f, a) => f(...a)
841
+ F: __dxlog_file6,
842
+ L: 101,
843
+ S: this,
844
+ C: (f, a) => f(...a)
810
845
  });
811
846
  this._clientTagMap.set([
812
847
  receipt2.feedKey,
@@ -876,7 +911,7 @@ import { timed as timed2 } from "@dxos/debug";
876
911
  import { PublicKey as PublicKey2 } from "@dxos/keys";
877
912
  import { schema as schema4 } from "@dxos/protocols";
878
913
  import { BlobMeta } from "@dxos/protocols/proto/dxos/echo/blob";
879
- var __decorate4 = function(decorators, target, key, desc) {
914
+ function _ts_decorate4(decorators, target, key, desc) {
880
915
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
881
916
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
882
917
  r = Reflect.decorate(decorators, target, key, desc);
@@ -885,7 +920,8 @@ var __decorate4 = function(decorators, target, key, desc) {
885
920
  if (d = decorators[i])
886
921
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
887
922
  return c > 3 && r && Object.defineProperty(target, key, r), r;
888
- };
923
+ }
924
+ var SpaceSnapshot = schema4.getCodecForType("dxos.echo.snapshot.SpaceSnapshot");
889
925
  var SnapshotManager = class SnapshotManager2 {
890
926
  // prettier-ignore
891
927
  constructor(_snapshotStore, _blobStore, _blobSync) {
@@ -895,7 +931,7 @@ var SnapshotManager = class SnapshotManager2 {
895
931
  }
896
932
  async _getBlob(blobId) {
897
933
  const blob = await this._blobStore.get(blobId);
898
- return schema4.getCodecForType("dxos.echo.snapshot.SpaceSnapshot").decode(blob);
934
+ return SpaceSnapshot.decode(blob);
899
935
  }
900
936
  async load(ctx, id) {
901
937
  const blobId = PublicKey2.fromHex(id).asUint8Array();
@@ -911,28 +947,29 @@ var SnapshotManager = class SnapshotManager2 {
911
947
  return this._getBlob(blobId);
912
948
  }
913
949
  async store(snapshot) {
914
- const { id } = await this._blobStore.set(schema4.getCodecForType("dxos.echo.snapshot.SpaceSnapshot").encode(snapshot));
950
+ const { id } = await this._blobStore.set(SpaceSnapshot.encode(snapshot));
915
951
  await this._blobSync.notifyBlobAdded(id);
916
952
  return PublicKey2.from(id).toHex();
917
953
  }
918
954
  };
919
- __decorate4([
955
+ _ts_decorate4([
920
956
  timed2(1e4)
921
957
  ], SnapshotManager.prototype, "load", null);
922
- SnapshotManager = __decorate4([
958
+ SnapshotManager = _ts_decorate4([
923
959
  trackLeaks("open", "close")
924
960
  ], SnapshotManager);
925
961
 
926
962
  // packages/core/echo/echo-pipeline/src/dbhost/snapshot-store.ts
927
963
  import { subtleCrypto } from "@dxos/crypto";
928
964
  import { schema as schema5 } from "@dxos/protocols";
965
+ var SpaceSnapshot2 = schema5.getCodecForType("dxos.echo.snapshot.SpaceSnapshot");
929
966
  var SnapshotStore = class {
930
967
  // prettier-ignore
931
968
  constructor(_directory) {
932
969
  this._directory = _directory;
933
970
  }
934
971
  async saveSnapshot(snapshot) {
935
- const encoded = schema5.getCodecForType("dxos.echo.snapshot.SpaceSnapshot").encode(snapshot);
972
+ const encoded = SpaceSnapshot2.encode(snapshot);
936
973
  const key = await subtleCrypto.digest("SHA-256", encoded);
937
974
  const keyString = Buffer.from(key).toString("hex");
938
975
  const file = await this._directory.getOrCreateFile(keyString);
@@ -951,7 +988,7 @@ var SnapshotStore = class {
951
988
  return void 0;
952
989
  }
953
990
  const buffer = await file.read(0, size);
954
- return schema5.getCodecForType("dxos.echo.snapshot.SpaceSnapshot").decode(buffer);
991
+ return SpaceSnapshot2.decode(buffer);
955
992
  } finally {
956
993
  await file.close();
957
994
  }
@@ -969,11 +1006,12 @@ var SnapshotStore = class {
969
1006
  };
970
1007
 
971
1008
  // packages/core/echo/echo-pipeline/src/dbhost/data-service.ts
972
- import assert7 from "@dxos/node-std/assert";
1009
+ import invariant7 from "tiny-invariant";
973
1010
  import { raise } from "@dxos/debug";
974
1011
  import { PublicKey as PublicKey3 } from "@dxos/keys";
975
1012
  import { log as log7 } from "@dxos/log";
976
1013
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1014
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/dbhost/data-service.ts";
977
1015
  var DataServiceSubscriptions = class {
978
1016
  constructor() {
979
1017
  this._spaces = new ComplexMap3(PublicKey3.hash);
@@ -981,26 +1019,30 @@ var DataServiceSubscriptions = class {
981
1019
  clear() {
982
1020
  this._spaces.clear();
983
1021
  }
984
- registerSpace(spaceKey, host) {
1022
+ async registerSpace(spaceKey, host) {
985
1023
  log7("Registering space", {
986
1024
  spaceKey
987
1025
  }, {
988
- file: "data-service.ts",
989
- line: 31,
990
- scope: this,
991
- callSite: (f, a) => f(...a)
1026
+ F: __dxlog_file7,
1027
+ L: 31,
1028
+ S: this,
1029
+ C: (f, a) => f(...a)
992
1030
  });
1031
+ invariant7(!this._spaces.has(spaceKey));
1032
+ await host.open();
993
1033
  this._spaces.set(spaceKey, host);
994
1034
  }
995
- unregisterSpace(spaceKey) {
1035
+ async unregisterSpace(spaceKey) {
996
1036
  log7("Unregistering space", {
997
1037
  spaceKey
998
1038
  }, {
999
- file: "data-service.ts",
1000
- line: 36,
1001
- scope: this,
1002
- callSite: (f, a) => f(...a)
1039
+ F: __dxlog_file7,
1040
+ L: 38,
1041
+ S: this,
1042
+ C: (f, a) => f(...a)
1003
1043
  });
1044
+ const host = this._spaces.get(spaceKey);
1045
+ await (host == null ? void 0 : host.close());
1004
1046
  this._spaces.delete(spaceKey);
1005
1047
  }
1006
1048
  getDataService(spaceKey) {
@@ -1013,29 +1055,29 @@ var DataServiceImpl = class {
1013
1055
  }
1014
1056
  subscribe(request) {
1015
1057
  var _a;
1016
- assert7(request.spaceKey);
1058
+ invariant7(request.spaceKey);
1017
1059
  const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
1018
1060
  return host.subscribe();
1019
1061
  }
1020
1062
  write(request) {
1021
1063
  var _a;
1022
- assert7(request.spaceKey);
1023
- assert7(request.batch);
1064
+ invariant7(request.spaceKey);
1065
+ invariant7(request.batch);
1024
1066
  const host = (_a = this._subscriptions.getDataService(request.spaceKey)) != null ? _a : raise(new Error(`space not found: ${request.spaceKey}`));
1025
1067
  return host.write(request);
1026
1068
  }
1027
1069
  };
1028
1070
 
1029
1071
  // packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
1030
- import assert8 from "@dxos/node-std/assert";
1072
+ import invariant8 from "tiny-invariant";
1031
1073
  import { Event as Event4, scheduleTask as scheduleTask2, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
1032
- import { Context as Context3 } from "@dxos/context";
1074
+ import { Context as Context4 } from "@dxos/context";
1033
1075
  import { checkCredentialType } from "@dxos/credentials";
1034
1076
  import { getStateMachineFromItem, ItemManager } from "@dxos/echo-db";
1035
1077
  import { CancelledError } from "@dxos/errors";
1036
1078
  import { log as log8 } from "@dxos/log";
1037
1079
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
1038
- var __decorate5 = function(decorators, target, key, desc) {
1080
+ function _ts_decorate5(decorators, target, key, desc) {
1039
1081
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1040
1082
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1041
1083
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1044,18 +1086,23 @@ var __decorate5 = function(decorators, target, key, desc) {
1044
1086
  if (d = decorators[i])
1045
1087
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1046
1088
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1047
- };
1089
+ }
1090
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
1048
1091
  var MESSAGES_PER_SNAPSHOT = 10;
1049
1092
  var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
1050
1093
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
1051
1094
  var DataPipeline = class DataPipeline2 {
1052
1095
  constructor(_params) {
1053
1096
  this._params = _params;
1054
- this._ctx = new Context3();
1097
+ this._ctx = new Context4();
1098
+ this._pipeline = void 0;
1099
+ this._targetTimeframe = void 0;
1055
1100
  this._lastAutomaticSnapshotTimeframe = new Timeframe3();
1056
1101
  this._isOpen = false;
1057
1102
  this._lastTimeframeSaveTime = 0;
1058
1103
  this._lastSnapshotSaveTime = 0;
1104
+ this.currentEpoch = void 0;
1105
+ this.appliedEpoch = void 0;
1059
1106
  this._lastProcessedEpoch = -1;
1060
1107
  this.onNewEpoch = new Event4();
1061
1108
  }
@@ -1074,18 +1121,14 @@ var DataPipeline = class DataPipeline2 {
1074
1121
  this._targetTimeframe = timeframe;
1075
1122
  (_a = this._pipeline) == null ? void 0 : _a.state.setTargetTimeframe(timeframe);
1076
1123
  }
1077
- createCredentialProcessor() {
1078
- return {
1079
- process: async (credential) => {
1080
- if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
1081
- return;
1082
- }
1083
- this.currentEpoch = credential;
1084
- if (this._isOpen) {
1085
- await this._processEpochInSeparateTask(credential);
1086
- }
1087
- }
1088
- };
1124
+ async processCredential(credential) {
1125
+ if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
1126
+ return;
1127
+ }
1128
+ this.currentEpoch = credential;
1129
+ if (this._isOpen) {
1130
+ await this._processEpochInSeparateTask(credential);
1131
+ }
1089
1132
  }
1090
1133
  async open() {
1091
1134
  if (this._isOpen) {
@@ -1100,8 +1143,8 @@ var DataPipeline = class DataPipeline2 {
1100
1143
  }
1101
1144
  const feedWriter = {
1102
1145
  write: (data, options) => {
1103
- assert8(this._pipeline, "Pipeline is not initialized.");
1104
- assert8(this.currentEpoch, "Epoch is not initialized.");
1146
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1147
+ invariant8(this.currentEpoch, "Epoch is not initialized.");
1105
1148
  return this._pipeline.writer.write({
1106
1149
  data
1107
1150
  }, options);
@@ -1120,11 +1163,11 @@ var DataPipeline = class DataPipeline2 {
1120
1163
  if (!this._isOpen) {
1121
1164
  return;
1122
1165
  }
1123
- log8("close", {}, {
1124
- file: "data-pipeline.ts",
1125
- line: 174,
1126
- scope: this,
1127
- callSite: (f, a) => f(...a)
1166
+ log8("close", void 0, {
1167
+ F: __dxlog_file8,
1168
+ L: 171,
1169
+ S: this,
1170
+ C: (f, a) => f(...a)
1128
1171
  });
1129
1172
  this._isOpen = false;
1130
1173
  await this._ctx.dispose();
@@ -1135,15 +1178,23 @@ var DataPipeline = class DataPipeline2 {
1135
1178
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1136
1179
  }
1137
1180
  } catch (err) {
1138
- log8.catch(err, {}, {
1139
- file: "data-pipeline.ts",
1140
- line: 187,
1141
- scope: this,
1142
- callSite: (f, a) => f(...a)
1181
+ log8.catch(err, void 0, {
1182
+ F: __dxlog_file8,
1183
+ L: 184,
1184
+ S: this,
1185
+ C: (f, a) => f(...a)
1143
1186
  });
1144
1187
  }
1145
1188
  await ((_b = this.databaseHost) == null ? void 0 : _b.close());
1146
1189
  await ((_c = this.itemManager) == null ? void 0 : _c.destroy());
1190
+ this._ctx = new Context4();
1191
+ this._pipeline = void 0;
1192
+ this._targetTimeframe = void 0;
1193
+ this._lastAutomaticSnapshotTimeframe = new Timeframe3();
1194
+ this.currentEpoch = void 0;
1195
+ this.appliedEpoch = void 0;
1196
+ this._lastProcessedEpoch = -1;
1197
+ this._epochCtx = void 0;
1147
1198
  }
1148
1199
  async _consumePipeline() {
1149
1200
  if (this.currentEpoch) {
@@ -1151,17 +1202,17 @@ var DataPipeline = class DataPipeline2 {
1151
1202
  await this._processEpochInSeparateTask(this.currentEpoch);
1152
1203
  await waitForOneEpoch;
1153
1204
  }
1154
- assert8(this._pipeline, "Pipeline is not initialized.");
1205
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1155
1206
  for await (const msg of this._pipeline.consume()) {
1156
1207
  const { feedKey, seq, data } = msg;
1157
1208
  log8("processing message", {
1158
1209
  feedKey,
1159
1210
  seq
1160
1211
  }, {
1161
- file: "data-pipeline.ts",
1162
- line: 204,
1163
- scope: this,
1164
- callSite: (f, a) => f(...a)
1212
+ F: __dxlog_file8,
1213
+ L: 210,
1214
+ S: this,
1215
+ C: (f, a) => f(...a)
1165
1216
  });
1166
1217
  try {
1167
1218
  if (data.payload.data) {
@@ -1170,10 +1221,10 @@ var DataPipeline = class DataPipeline2 {
1170
1221
  log8.error("Could not find feed.", {
1171
1222
  feedKey
1172
1223
  }, {
1173
- file: "data-pipeline.ts",
1174
- line: 210,
1175
- scope: this,
1176
- callSite: (f, a) => f(...a)
1224
+ F: __dxlog_file8,
1225
+ L: 216,
1226
+ S: this,
1227
+ C: (f, a) => f(...a)
1177
1228
  });
1178
1229
  continue;
1179
1230
  }
@@ -1191,25 +1242,25 @@ var DataPipeline = class DataPipeline2 {
1191
1242
  seq,
1192
1243
  spaceKey: this._params.spaceKey.toHex()
1193
1244
  }, {
1194
- file: "data-pipeline.ts",
1195
- line: 224,
1196
- scope: this,
1197
- callSite: (f, a) => f(...a)
1245
+ F: __dxlog_file8,
1246
+ L: 230,
1247
+ S: this,
1248
+ C: (f, a) => f(...a)
1198
1249
  });
1199
1250
  await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1200
1251
  }
1201
1252
  } catch (err) {
1202
- log8.catch(err, {}, {
1203
- file: "data-pipeline.ts",
1204
- line: 234,
1205
- scope: this,
1206
- callSite: (f, a) => f(...a)
1253
+ log8.catch(err, void 0, {
1254
+ F: __dxlog_file8,
1255
+ L: 240,
1256
+ S: this,
1257
+ C: (f, a) => f(...a)
1207
1258
  });
1208
1259
  }
1209
1260
  }
1210
1261
  }
1211
1262
  _createSnapshot() {
1212
- assert8(this.databaseHost, "Database backend is not initialized.");
1263
+ invariant8(this.databaseHost, "Database backend is not initialized.");
1213
1264
  return {
1214
1265
  spaceKey: this._params.spaceKey.asUint8Array(),
1215
1266
  timeframe: this._pipeline.state.timeframe,
@@ -1228,18 +1279,17 @@ var DataPipeline = class DataPipeline2 {
1228
1279
  try {
1229
1280
  const propertiesItem = this.itemManager.items.find((item) => {
1230
1281
  var _a2, _b;
1231
- return ((_a2 = item.modelMeta) == null ? void 0 : _a2.type) === "dxos:model/document" && // TODO(burdon): Document?
1232
- ((_b = getStateMachineFromItem(item)) == null ? void 0 : _b.snapshot().type) === "dxos.sdk.client.Properties";
1282
+ 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";
1233
1283
  });
1234
1284
  if (propertiesItem) {
1235
1285
  cache.properties = (_a = getStateMachineFromItem(propertiesItem)) == null ? void 0 : _a.snapshot();
1236
1286
  }
1237
1287
  } catch (err) {
1238
1288
  log8.warn("Failed to cache properties", err, {
1239
- file: "data-pipeline.ts",
1240
- line: 269,
1241
- scope: this,
1242
- callSite: (f, a) => f(...a)
1289
+ F: __dxlog_file8,
1290
+ L: 275,
1291
+ S: this,
1292
+ C: (f, a) => f(...a)
1243
1293
  });
1244
1294
  }
1245
1295
  await this._params.metadataStore.setCache(this._params.spaceKey, cache);
@@ -1259,21 +1309,21 @@ var DataPipeline = class DataPipeline2 {
1259
1309
  return;
1260
1310
  }
1261
1311
  await ((_a = this._epochCtx) == null ? void 0 : _a.dispose());
1262
- const ctx = new Context3({
1312
+ const ctx = new Context4({
1263
1313
  onError: (err) => {
1264
1314
  if (err instanceof CancelledError) {
1265
- log8("Epoch processing cancelled.", {}, {
1266
- file: "data-pipeline.ts",
1267
- line: 301,
1268
- scope: this,
1269
- callSite: (f, a) => f(...a)
1315
+ log8("Epoch processing cancelled.", void 0, {
1316
+ F: __dxlog_file8,
1317
+ L: 307,
1318
+ S: this,
1319
+ C: (f, a) => f(...a)
1270
1320
  });
1271
1321
  } else {
1272
- log8.catch(err, {}, {
1273
- file: "data-pipeline.ts",
1274
- line: 303,
1275
- scope: this,
1276
- callSite: (f, a) => f(...a)
1322
+ log8.catch(err, void 0, {
1323
+ F: __dxlog_file8,
1324
+ L: 309,
1325
+ S: this,
1326
+ C: (f, a) => f(...a)
1277
1327
  });
1278
1328
  }
1279
1329
  }
@@ -1286,10 +1336,10 @@ var DataPipeline = class DataPipeline2 {
1286
1336
  log8("process epoch", {
1287
1337
  epoch
1288
1338
  }, {
1289
- file: "data-pipeline.ts",
1290
- line: 313,
1291
- scope: this,
1292
- callSite: (f, a) => f(...a)
1339
+ F: __dxlog_file8,
1340
+ L: 319,
1341
+ S: this,
1342
+ C: (f, a) => f(...a)
1293
1343
  });
1294
1344
  await this._processEpoch(ctx, epoch.subject.assertion);
1295
1345
  this.appliedEpoch = epoch;
@@ -1297,38 +1347,38 @@ var DataPipeline = class DataPipeline2 {
1297
1347
  });
1298
1348
  }
1299
1349
  async _processEpoch(ctx, epoch) {
1300
- assert8(this._isOpen, "Space is closed.");
1301
- assert8(this._pipeline);
1350
+ invariant8(this._isOpen, "Space is closed.");
1351
+ invariant8(this._pipeline);
1302
1352
  this._lastProcessedEpoch = epoch.number;
1303
1353
  log8("Processing epoch", {
1304
1354
  epoch
1305
1355
  }, {
1306
- file: "data-pipeline.ts",
1307
- line: 327,
1308
- scope: this,
1309
- callSite: (f, a) => f(...a)
1356
+ F: __dxlog_file8,
1357
+ L: 333,
1358
+ S: this,
1359
+ C: (f, a) => f(...a)
1310
1360
  });
1311
1361
  if (epoch.snapshotCid) {
1312
1362
  const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
1313
1363
  this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
1314
1364
  }
1315
- log8("restarting pipeline for epoch", {}, {
1316
- file: "data-pipeline.ts",
1317
- line: 335,
1318
- scope: this,
1319
- callSite: (f, a) => f(...a)
1365
+ log8("restarting pipeline for epoch", void 0, {
1366
+ F: __dxlog_file8,
1367
+ L: 341,
1368
+ S: this,
1369
+ C: (f, a) => f(...a)
1320
1370
  });
1321
1371
  await this._pipeline.pause();
1322
1372
  await this._pipeline.setCursor(epoch.timeframe);
1323
1373
  await this._pipeline.unpause();
1324
1374
  }
1325
1375
  async waitUntilTimeframe(timeframe) {
1326
- assert8(this._pipeline, "Pipeline is not initialized.");
1376
+ invariant8(this._pipeline, "Pipeline is not initialized.");
1327
1377
  await this._pipeline.state.waitUntilTimeframe(timeframe);
1328
1378
  }
1329
1379
  async createEpoch() {
1330
- assert8(this._pipeline);
1331
- assert8(this.currentEpoch);
1380
+ invariant8(this._pipeline);
1381
+ invariant8(this.currentEpoch);
1332
1382
  await this._pipeline.pause();
1333
1383
  const snapshot = await this._createSnapshot();
1334
1384
  const snapshotCid = await this._params.snapshotManager.store(snapshot);
@@ -1345,24 +1395,24 @@ var DataPipeline = class DataPipeline2 {
1345
1395
  await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
1346
1396
  }
1347
1397
  };
1348
- __decorate5([
1398
+ _ts_decorate5([
1349
1399
  synchronized3
1350
1400
  ], DataPipeline.prototype, "open", null);
1351
- __decorate5([
1401
+ _ts_decorate5([
1352
1402
  synchronized3
1353
1403
  ], DataPipeline.prototype, "close", null);
1354
- __decorate5([
1404
+ _ts_decorate5([
1355
1405
  synchronized3
1356
1406
  ], DataPipeline.prototype, "_processEpoch", null);
1357
- __decorate5([
1407
+ _ts_decorate5([
1358
1408
  synchronized3
1359
1409
  ], DataPipeline.prototype, "createEpoch", null);
1360
- DataPipeline = __decorate5([
1410
+ DataPipeline = _ts_decorate5([
1361
1411
  trackLeaks2("open", "close")
1362
1412
  ], DataPipeline);
1363
1413
 
1364
1414
  // packages/core/echo/echo-pipeline/src/space/space.ts
1365
- import assert9 from "@dxos/node-std/assert";
1415
+ import invariant9 from "tiny-invariant";
1366
1416
  import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeaks3, Lock } from "@dxos/async";
1367
1417
  import { log as log10, logInfo } from "@dxos/log";
1368
1418
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
@@ -1375,6 +1425,7 @@ import { log as log9 } from "@dxos/log";
1375
1425
  import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
1376
1426
  import { Timeframe as Timeframe4 } from "@dxos/timeframe";
1377
1427
  import { Callback } from "@dxos/util";
1428
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
1378
1429
  var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
1379
1430
  var ControlPipeline = class {
1380
1431
  constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
@@ -1389,21 +1440,21 @@ var ControlPipeline = class {
1389
1440
  log9("feed admitted", {
1390
1441
  key: info.key
1391
1442
  }, {
1392
- file: "control-pipeline.ts",
1393
- line: 51,
1394
- scope: this,
1395
- callSite: (f, a) => f(...a)
1443
+ F: __dxlog_file9,
1444
+ L: 51,
1445
+ S: this,
1446
+ C: (f, a) => f(...a)
1396
1447
  });
1397
1448
  if (info.assertion.designation === AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
1398
1449
  try {
1399
1450
  const feed = await feedProvider(info.key);
1400
1451
  await this._pipeline.addFeed(feed);
1401
1452
  } catch (err) {
1402
- log9.catch(err, {}, {
1403
- file: "control-pipeline.ts",
1404
- line: 59,
1405
- scope: this,
1406
- callSite: (f, a) => f(...a)
1453
+ log9.catch(err, void 0, {
1454
+ F: __dxlog_file9,
1455
+ L: 59,
1456
+ S: this,
1457
+ C: (f, a) => f(...a)
1407
1458
  });
1408
1459
  }
1409
1460
  }
@@ -1422,11 +1473,11 @@ var ControlPipeline = class {
1422
1473
  this._pipeline.setWriteFeed(feed);
1423
1474
  }
1424
1475
  async start() {
1425
- log9("starting...", {}, {
1426
- file: "control-pipeline.ts",
1427
- line: 83,
1428
- scope: this,
1429
- callSite: (f, a) => f(...a)
1476
+ log9("starting...", void 0, {
1477
+ F: __dxlog_file9,
1478
+ L: 83,
1479
+ S: this,
1480
+ C: (f, a) => f(...a)
1430
1481
  });
1431
1482
  setTimeout(async () => {
1432
1483
  for await (const msg of this._pipeline.consume()) {
@@ -1435,10 +1486,10 @@ var ControlPipeline = class {
1435
1486
  key: msg.feedKey,
1436
1487
  seq: msg.seq
1437
1488
  }, {
1438
- file: "control-pipeline.ts",
1439
- line: 88,
1440
- scope: this,
1441
- callSite: (f, a) => f(...a)
1489
+ F: __dxlog_file9,
1490
+ L: 88,
1491
+ S: this,
1492
+ C: (f, a) => f(...a)
1442
1493
  });
1443
1494
  if (msg.data.payload.credential) {
1444
1495
  const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, PublicKey4.from(msg.feedKey));
@@ -1446,31 +1497,31 @@ var ControlPipeline = class {
1446
1497
  log9.warn("processing failed", {
1447
1498
  msg
1448
1499
  }, {
1449
- file: "control-pipeline.ts",
1450
- line: 95,
1451
- scope: this,
1452
- callSite: (f, a) => f(...a)
1500
+ F: __dxlog_file9,
1501
+ L: 95,
1502
+ S: this,
1503
+ C: (f, a) => f(...a)
1453
1504
  });
1454
1505
  } else {
1455
1506
  await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
1456
1507
  }
1457
1508
  }
1458
1509
  } catch (err) {
1459
- log9.catch(err, {}, {
1460
- file: "control-pipeline.ts",
1461
- line: 101,
1462
- scope: this,
1463
- callSite: (f, a) => f(...a)
1510
+ log9.catch(err, void 0, {
1511
+ F: __dxlog_file9,
1512
+ L: 101,
1513
+ S: this,
1514
+ C: (f, a) => f(...a)
1464
1515
  });
1465
1516
  }
1466
1517
  }
1467
1518
  });
1468
1519
  await this._pipeline.start();
1469
- log9("started", {}, {
1470
- file: "control-pipeline.ts",
1471
- line: 107,
1472
- scope: this,
1473
- callSite: (f, a) => f(...a)
1520
+ log9("started", void 0, {
1521
+ F: __dxlog_file9,
1522
+ L: 107,
1523
+ S: this,
1524
+ C: (f, a) => f(...a)
1474
1525
  });
1475
1526
  }
1476
1527
  async _noteTargetStateIfNeeded(timeframe) {
@@ -1480,19 +1531,19 @@ var ControlPipeline = class {
1480
1531
  }
1481
1532
  }
1482
1533
  async stop() {
1483
- log9("stopping...", {}, {
1484
- file: "control-pipeline.ts",
1485
- line: 121,
1486
- scope: this,
1487
- callSite: (f, a) => f(...a)
1534
+ log9("stopping...", void 0, {
1535
+ F: __dxlog_file9,
1536
+ L: 121,
1537
+ S: this,
1538
+ C: (f, a) => f(...a)
1488
1539
  });
1489
1540
  await this._pipeline.stop();
1490
1541
  await this._saveTargetTimeframe(this._pipeline.state.timeframe);
1491
- log9("stopped", {}, {
1492
- file: "control-pipeline.ts",
1493
- line: 124,
1494
- scope: this,
1495
- callSite: (f, a) => f(...a)
1542
+ log9("stopped", void 0, {
1543
+ F: __dxlog_file9,
1544
+ L: 124,
1545
+ S: this,
1546
+ C: (f, a) => f(...a)
1496
1547
  });
1497
1548
  }
1498
1549
  async _saveTargetTimeframe(timeframe) {
@@ -1502,18 +1553,18 @@ var ControlPipeline = class {
1502
1553
  await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
1503
1554
  this._targetTimeframe = newTimeframe;
1504
1555
  } catch (err) {
1505
- log9(err, {}, {
1506
- file: "control-pipeline.ts",
1507
- line: 133,
1508
- scope: this,
1509
- callSite: (f, a) => f(...a)
1556
+ log9(err, void 0, {
1557
+ F: __dxlog_file9,
1558
+ L: 133,
1559
+ S: this,
1560
+ C: (f, a) => f(...a)
1510
1561
  });
1511
1562
  }
1512
1563
  }
1513
1564
  };
1514
1565
 
1515
1566
  // packages/core/echo/echo-pipeline/src/space/space.ts
1516
- var __decorate6 = function(decorators, target, key, desc) {
1567
+ function _ts_decorate6(decorators, target, key, desc) {
1517
1568
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1518
1569
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1519
1570
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1522,16 +1573,15 @@ var __decorate6 = function(decorators, target, key, desc) {
1522
1573
  if (d = decorators[i])
1523
1574
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1524
1575
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1525
- };
1576
+ }
1577
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
1526
1578
  var Space = class Space2 {
1527
1579
  constructor(params) {
1528
1580
  this._addFeedLock = new Lock();
1529
1581
  this.onCredentialProcessed = new Callback2();
1530
1582
  this.stateUpdate = new Event5();
1531
- // Processes epoch credentials.
1532
- this._dataPipelineCredentialConsumer = void 0;
1533
1583
  this._isOpen = false;
1534
- assert9(params.spaceKey && params.feedProvider);
1584
+ invariant9(params.spaceKey && params.feedProvider);
1535
1585
  this._key = params.spaceKey;
1536
1586
  this._genesisFeedKey = params.genesisFeed.key;
1537
1587
  this._feedProvider = params.feedProvider;
@@ -1566,10 +1616,10 @@ var Space = class Space2 {
1566
1616
  log10("onCredentialProcessed", {
1567
1617
  credential
1568
1618
  }, {
1569
- file: "space.ts",
1570
- line: 110,
1571
- scope: this,
1572
- callSite: (f, a) => f(...a)
1619
+ F: __dxlog_file10,
1620
+ L: 107,
1621
+ S: this,
1622
+ C: (f, a) => f(...a)
1573
1623
  });
1574
1624
  this.stateUpdate.emit();
1575
1625
  });
@@ -1632,14 +1682,14 @@ var Space = class Space2 {
1632
1682
  return this._snapshotManager;
1633
1683
  }
1634
1684
  setControlFeed(feed) {
1635
- assert9(!this._controlFeed, "Control feed already set.");
1685
+ invariant9(!this._controlFeed, "Control feed already set.");
1636
1686
  this._controlFeed = feed;
1637
1687
  this._controlPipeline.setWriteFeed(feed);
1638
1688
  return this;
1639
1689
  }
1640
1690
  setDataFeed(feed) {
1641
1691
  var _a;
1642
- assert9(!this._dataFeed, "Data feed already set.");
1692
+ invariant9(!this._dataFeed, "Data feed already set.");
1643
1693
  this._dataFeed = feed;
1644
1694
  (_a = this._dataPipeline.pipeline) == null ? void 0 : _a.setWriteFeed(feed);
1645
1695
  return this;
@@ -1657,82 +1707,79 @@ var Space = class Space2 {
1657
1707
  // return this._dataPipeline?.getFeeds();
1658
1708
  // }
1659
1709
  async open() {
1660
- log10("opening...", {}, {
1661
- file: "space.ts",
1662
- line: 212,
1663
- scope: this,
1664
- callSite: (f, a) => f(...a)
1710
+ log10("opening...", void 0, {
1711
+ F: __dxlog_file10,
1712
+ L: 209,
1713
+ S: this,
1714
+ C: (f, a) => f(...a)
1665
1715
  });
1666
1716
  if (this._isOpen) {
1667
1717
  return;
1668
1718
  }
1669
1719
  await this._controlPipeline.start();
1670
1720
  await this.protocol.start();
1671
- this._dataPipelineCredentialConsumer = this._controlPipeline.spaceState.registerProcessor(this._dataPipeline.createCredentialProcessor());
1672
- await this._dataPipelineCredentialConsumer.open();
1721
+ await this._controlPipeline.spaceState.addCredentialProcessor(this._dataPipeline);
1673
1722
  this._isOpen = true;
1674
- log10("opened", {}, {
1675
- file: "space.ts",
1676
- line: 228,
1677
- scope: this,
1678
- callSite: (f, a) => f(...a)
1723
+ log10("opened", void 0, {
1724
+ F: __dxlog_file10,
1725
+ L: 220,
1726
+ S: this,
1727
+ C: (f, a) => f(...a)
1679
1728
  });
1680
1729
  }
1681
1730
  async close() {
1682
- var _a;
1683
1731
  log10("closing...", {
1684
1732
  key: this._key
1685
1733
  }, {
1686
- file: "space.ts",
1687
- line: 233,
1688
- scope: this,
1689
- callSite: (f, a) => f(...a)
1734
+ F: __dxlog_file10,
1735
+ L: 225,
1736
+ S: this,
1737
+ C: (f, a) => f(...a)
1690
1738
  });
1691
1739
  if (!this._isOpen) {
1692
1740
  return;
1693
1741
  }
1694
- await ((_a = this._dataPipelineCredentialConsumer) == null ? void 0 : _a.close());
1695
- this._dataPipelineCredentialConsumer = void 0;
1742
+ await this._controlPipeline.spaceState.removeCredentialProcessor(this._dataPipeline);
1696
1743
  await this._dataPipeline.close();
1697
1744
  await this.protocol.stop();
1698
1745
  await this._controlPipeline.stop();
1699
1746
  this._isOpen = false;
1700
- log10("closed", {}, {
1701
- file: "space.ts",
1702
- line: 247,
1703
- scope: this,
1704
- callSite: (f, a) => f(...a)
1747
+ log10("closed", void 0, {
1748
+ F: __dxlog_file10,
1749
+ L: 238,
1750
+ S: this,
1751
+ C: (f, a) => f(...a)
1705
1752
  });
1706
1753
  }
1707
1754
  async initializeDataPipeline() {
1708
- log10("initializeDataPipeline", {}, {
1709
- file: "space.ts",
1710
- line: 252,
1711
- scope: this,
1712
- callSite: (f, a) => f(...a)
1755
+ log10("initializeDataPipeline", void 0, {
1756
+ F: __dxlog_file10,
1757
+ L: 243,
1758
+ S: this,
1759
+ C: (f, a) => f(...a)
1713
1760
  });
1714
- assert9(this._isOpen, "Space must be open to initialize data pipeline.");
1761
+ invariant9(this._isOpen, "Space must be open to initialize data pipeline.");
1715
1762
  await this._dataPipeline.open();
1716
1763
  }
1717
1764
  };
1718
- __decorate6([
1765
+ _ts_decorate6([
1719
1766
  logInfo
1720
1767
  ], Space.prototype, "key", null);
1721
- __decorate6([
1768
+ _ts_decorate6([
1722
1769
  synchronized4
1723
1770
  ], Space.prototype, "open", null);
1724
- __decorate6([
1771
+ _ts_decorate6([
1725
1772
  synchronized4
1726
1773
  ], Space.prototype, "close", null);
1727
- __decorate6([
1774
+ _ts_decorate6([
1728
1775
  synchronized4
1729
1776
  ], Space.prototype, "initializeDataPipeline", null);
1730
- Space = __decorate6([
1777
+ Space = _ts_decorate6([
1731
1778
  trackLeaks3("open", "close")
1732
1779
  ], Space);
1733
1780
 
1734
1781
  // packages/core/echo/echo-pipeline/src/space/space-protocol.ts
1735
- import { discoveryKey, sha256 } from "@dxos/crypto";
1782
+ import { discoveryKey, subtleCrypto as subtleCrypto2 } from "@dxos/crypto";
1736
1783
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1737
1784
  import { log as log11, logInfo as logInfo2 } from "@dxos/log";
1738
1785
  import { MMSTTopology } from "@dxos/network-manager";
@@ -1740,7 +1787,7 @@ import { Teleport } from "@dxos/teleport";
1740
1787
  import { BlobSync } from "@dxos/teleport-extension-object-sync";
1741
1788
  import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
1742
1789
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1743
- var __decorate7 = function(decorators, target, key, desc) {
1790
+ function _ts_decorate7(decorators, target, key, desc) {
1744
1791
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1745
1792
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1746
1793
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1749,7 +1796,8 @@ var __decorate7 = function(decorators, target, key, desc) {
1749
1796
  if (d = decorators[i])
1750
1797
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1751
1798
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1752
- };
1799
+ }
1800
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
1753
1801
  var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
1754
1802
  var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
1755
1803
  var SpaceProtocol = class {
@@ -1763,7 +1811,7 @@ var SpaceProtocol = class {
1763
1811
  this.blobSync = new BlobSync({
1764
1812
  blobStore
1765
1813
  });
1766
- this._topic = PublicKey5.from(discoveryKey(sha256(topic.toHex())));
1814
+ this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey5.from);
1767
1815
  }
1768
1816
  get sessions() {
1769
1817
  return this._sessions;
@@ -1779,10 +1827,10 @@ var SpaceProtocol = class {
1779
1827
  log11("addFeed", {
1780
1828
  key: feed.key
1781
1829
  }, {
1782
- file: "space-protocol.ts",
1783
- line: 94,
1784
- scope: this,
1785
- callSite: (f, a) => f(...a)
1830
+ F: __dxlog_file11,
1831
+ L: 96,
1832
+ S: this,
1833
+ C: (f, a) => f(...a)
1786
1834
  });
1787
1835
  this._feeds.add(feed);
1788
1836
  for (const session of this._sessions.values()) {
@@ -1800,41 +1848,41 @@ var SpaceProtocol = class {
1800
1848
  sampleSize: 20
1801
1849
  };
1802
1850
  await this.blobSync.open();
1803
- log11("starting...", {}, {
1804
- file: "space-protocol.ts",
1805
- line: 119,
1806
- scope: this,
1807
- callSite: (f, a) => f(...a)
1851
+ log11("starting...", void 0, {
1852
+ F: __dxlog_file11,
1853
+ L: 121,
1854
+ S: this,
1855
+ C: (f, a) => f(...a)
1808
1856
  });
1809
1857
  this._connection = await this._networkManager.joinSwarm({
1810
1858
  protocolProvider: this._createProtocolProvider(credentials),
1811
1859
  peerId: this._swarmIdentity.peerKey,
1812
- topic: this._topic,
1860
+ topic: await this._topic,
1813
1861
  topology: new MMSTTopology(topologyConfig),
1814
1862
  label: `Protocol swarm: ${this._topic}`
1815
1863
  });
1816
- log11("started", {}, {
1817
- file: "space-protocol.ts",
1818
- line: 128,
1819
- scope: this,
1820
- callSite: (f, a) => f(...a)
1864
+ log11("started", void 0, {
1865
+ F: __dxlog_file11,
1866
+ L: 130,
1867
+ S: this,
1868
+ C: (f, a) => f(...a)
1821
1869
  });
1822
1870
  }
1823
1871
  async stop() {
1824
1872
  await this.blobSync.close();
1825
1873
  if (this._connection) {
1826
- log11("stopping...", {}, {
1827
- file: "space-protocol.ts",
1828
- line: 135,
1829
- scope: this,
1830
- callSite: (f, a) => f(...a)
1874
+ log11("stopping...", void 0, {
1875
+ F: __dxlog_file11,
1876
+ L: 137,
1877
+ S: this,
1878
+ C: (f, a) => f(...a)
1831
1879
  });
1832
1880
  await this._connection.close();
1833
- log11("stopped", {}, {
1834
- file: "space-protocol.ts",
1835
- line: 137,
1836
- scope: this,
1837
- callSite: (f, a) => f(...a)
1881
+ log11("stopped", void 0, {
1882
+ F: __dxlog_file11,
1883
+ L: 139,
1884
+ S: this,
1885
+ C: (f, a) => f(...a)
1838
1886
  });
1839
1887
  }
1840
1888
  }
@@ -1855,10 +1903,10 @@ var SpaceProtocol = class {
1855
1903
  };
1856
1904
  }
1857
1905
  };
1858
- __decorate7([
1906
+ _ts_decorate7([
1859
1907
  logInfo2
1860
1908
  ], SpaceProtocol.prototype, "_topic", void 0);
1861
- __decorate7([
1909
+ _ts_decorate7([
1862
1910
  logInfo2
1863
1911
  ], SpaceProtocol.prototype, "_ownPeerKey", null);
1864
1912
  var AuthStatus;
@@ -1885,6 +1933,9 @@ var SpaceProtocolSession = class {
1885
1933
  get authStatus() {
1886
1934
  return this._authStatus;
1887
1935
  }
1936
+ get stats() {
1937
+ return this._teleport.stats;
1938
+ }
1888
1939
  get stream() {
1889
1940
  return this._teleport.stream;
1890
1941
  }
@@ -1895,11 +1946,11 @@ var SpaceProtocolSession = class {
1895
1946
  verifier: this._swarmIdentity.credentialAuthenticator,
1896
1947
  onAuthSuccess: () => {
1897
1948
  var _a;
1898
- log11("Peer authenticated", {}, {
1899
- file: "space-protocol.ts",
1900
- line: 230,
1901
- scope: this,
1902
- callSite: (f, a) => f(...a)
1949
+ log11("Peer authenticated", void 0, {
1950
+ F: __dxlog_file11,
1951
+ L: 236,
1952
+ S: this,
1953
+ C: (f, a) => f(...a)
1903
1954
  });
1904
1955
  this._authStatus = AuthStatus.SUCCESS;
1905
1956
  (_a = this._onSessionAuth) == null ? void 0 : _a.call(this, this._teleport);
@@ -1917,10 +1968,10 @@ var SpaceProtocolSession = class {
1917
1968
  await this._teleport.close();
1918
1969
  }
1919
1970
  };
1920
- __decorate7([
1971
+ _ts_decorate7([
1921
1972
  logInfo2
1922
1973
  ], SpaceProtocolSession.prototype, "_wireParams", void 0);
1923
- __decorate7([
1974
+ _ts_decorate7([
1924
1975
  logInfo2
1925
1976
  ], SpaceProtocolSession.prototype, "authStatus", null);
1926
1977
 
@@ -1931,7 +1982,7 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
1931
1982
  import { log as log12 } from "@dxos/log";
1932
1983
  import { trace } from "@dxos/protocols";
1933
1984
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
1934
- var __decorate8 = function(decorators, target, key, desc) {
1985
+ function _ts_decorate8(decorators, target, key, desc) {
1935
1986
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1936
1987
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1937
1988
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1940,7 +1991,8 @@ var __decorate8 = function(decorators, target, key, desc) {
1940
1991
  if (d = decorators[i])
1941
1992
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1942
1993
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1943
- };
1994
+ }
1995
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
1944
1996
  var SpaceManager = class SpaceManager2 {
1945
1997
  constructor({ feedStore, networkManager, modelFactory, metadataStore, snapshotStore, blobStore }) {
1946
1998
  this._spaces = new ComplexMap5(PublicKey6.hash);
@@ -1968,18 +2020,18 @@ var SpaceManager = class SpaceManager2 {
1968
2020
  log12.trace("dxos.echo.space-manager.construct-space", trace.begin({
1969
2021
  id: this._instanceId
1970
2022
  }), {
1971
- file: "space-manager.ts",
1972
- line: 97,
1973
- scope: this,
1974
- callSite: (f, a) => f(...a)
2023
+ F: __dxlog_file12,
2024
+ L: 97,
2025
+ S: this,
2026
+ C: (f, a) => f(...a)
1975
2027
  });
1976
2028
  log12("constructing space...", {
1977
2029
  spaceKey: metadata.genesisFeedKey
1978
2030
  }, {
1979
- file: "space-manager.ts",
1980
- line: 98,
1981
- scope: this,
1982
- callSite: (f, a) => f(...a)
2031
+ F: __dxlog_file12,
2032
+ L: 98,
2033
+ S: this,
2034
+ C: (f, a) => f(...a)
1983
2035
  });
1984
2036
  const genesisFeed = await this._feedStore.openFeed((_a = metadata.genesisFeedKey) != null ? _a : failUndefined2());
1985
2037
  const spaceKey = metadata.key;
@@ -2006,21 +2058,21 @@ var SpaceManager = class SpaceManager2 {
2006
2058
  log12.trace("dxos.echo.space-manager.construct-space", trace.end({
2007
2059
  id: this._instanceId
2008
2060
  }), {
2009
- file: "space-manager.ts",
2010
- line: 125,
2011
- scope: this,
2012
- callSite: (f, a) => f(...a)
2061
+ F: __dxlog_file12,
2062
+ L: 125,
2063
+ S: this,
2064
+ C: (f, a) => f(...a)
2013
2065
  });
2014
2066
  return space;
2015
2067
  }
2016
2068
  };
2017
- __decorate8([
2069
+ _ts_decorate8([
2018
2070
  synchronized5
2019
2071
  ], SpaceManager.prototype, "open", null);
2020
- __decorate8([
2072
+ _ts_decorate8([
2021
2073
  synchronized5
2022
2074
  ], SpaceManager.prototype, "close", null);
2023
- SpaceManager = __decorate8([
2075
+ SpaceManager = _ts_decorate8([
2024
2076
  trackLeaks4("open", "close")
2025
2077
  ], SpaceManager);
2026
2078
 
@@ -2050,4 +2102,4 @@ export {
2050
2102
  SpaceProtocolSession,
2051
2103
  SpaceManager
2052
2104
  };
2053
- //# sourceMappingURL=chunk-ZZV4HWSG.mjs.map
2105
+ //# sourceMappingURL=chunk-OJGL5427.mjs.map