@dxos/echo-pipeline 0.1.52 → 0.1.53-main.01c99c0

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