@dxos/echo-pipeline 0.1.53-main.52ca4e9 → 0.1.53-main.5bcfb84

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 (34) hide show
  1. package/dist/lib/browser/{chunk-SCMKAWNW.mjs → chunk-RFRZMQ5T.mjs} +95 -63
  2. package/dist/lib/browser/chunk-RFRZMQ5T.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +2 -2
  6. package/dist/lib/browser/testing/index.mjs.map +2 -2
  7. package/dist/lib/node/index.cjs +96 -64
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +102 -70
  11. package/dist/lib/node/testing/index.cjs.map +3 -3
  12. package/dist/types/src/dbhost/data-service-host.d.ts +3 -0
  13. package/dist/types/src/dbhost/data-service-host.d.ts.map +1 -1
  14. package/dist/types/src/dbhost/data-service.d.ts +2 -2
  15. package/dist/types/src/dbhost/data-service.d.ts.map +1 -1
  16. package/dist/types/src/metadata/metadata-store.d.ts +4 -0
  17. package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
  18. package/dist/types/src/pipeline/pipeline.d.ts +0 -1
  19. package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
  20. package/dist/types/src/space/data-pipeline.d.ts +3 -3
  21. package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
  22. package/dist/types/src/space/space.d.ts +0 -1
  23. package/dist/types/src/space/space.d.ts.map +1 -1
  24. package/package.json +30 -30
  25. package/src/dbhost/data-service-host.ts +14 -1
  26. package/src/dbhost/data-service.ts +6 -2
  27. package/src/metadata/metadata-store.ts +15 -2
  28. package/src/pipeline/pipeline.ts +13 -1
  29. package/src/space/data-pipeline.ts +25 -19
  30. package/src/space/space.test.ts +46 -5
  31. package/src/space/space.ts +3 -12
  32. package/src/testing/util.ts +1 -1
  33. package/src/tests/database.test.ts +1 -1
  34. package/dist/lib/browser/chunk-SCMKAWNW.mjs.map +0 -7
@@ -57,6 +57,7 @@ var import_util9 = require("@dxos/util");
57
57
  // packages/core/echo/echo-pipeline/src/dbhost/data-service-host.ts
58
58
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
59
59
  var import_codec_protobuf = require("@dxos/codec-protobuf");
60
+ var import_context = require("@dxos/context");
60
61
  var import_echo_db = require("@dxos/echo-db");
61
62
  var import_log = require("@dxos/log");
62
63
  var import_util = require("@dxos/util");
@@ -66,13 +67,20 @@ var DataServiceHost = class {
66
67
  this._itemManager = _itemManager;
67
68
  this._itemDemuxer = _itemDemuxer;
68
69
  this._writeStream = _writeStream;
70
+ this._ctx = new import_context.Context();
69
71
  this._clientTagMap = new import_util.ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
70
72
  }
73
+ async open() {
74
+ }
75
+ async close() {
76
+ await this._ctx.dispose();
77
+ }
71
78
  /**
72
79
  * Real-time subscription to data objects in a space.
73
80
  */
74
81
  subscribe() {
75
- return new import_codec_protobuf.Stream(({ next, ctx }) => {
82
+ return new import_codec_protobuf.Stream(({ next, close, ctx }) => {
83
+ ctx.onDispose(this._ctx.onDispose(close));
76
84
  const objects = Array.from(this._itemManager.entities.values()).map((entity) => entity.createSnapshot());
77
85
  next({
78
86
  batch: {
@@ -88,7 +96,7 @@ var DataServiceHost = class {
88
96
  meta
89
97
  }, {
90
98
  F: __dxlog_file,
91
- L: 51,
99
+ L: 63,
92
100
  S: this,
93
101
  C: (f, a) => f(...a)
94
102
  });
@@ -115,13 +123,14 @@ var DataServiceHost = class {
115
123
  }
116
124
  async write(request) {
117
125
  var _a, _b;
126
+ (0, import_tiny_invariant.default)(!this._ctx.disposed, "Cannot write to closed DataServiceHost");
118
127
  (0, import_tiny_invariant.default)(this._writeStream, "Cannot write mutations in readonly mode");
119
128
  (0, import_log.log)("write", {
120
129
  clientTag: request.clientTag,
121
130
  objectCount: (_b = (_a = request.batch.objects) == null ? void 0 : _a.length) != null ? _b : 0
122
131
  }, {
123
132
  F: __dxlog_file,
124
- L: 79,
133
+ L: 92,
125
134
  S: this,
126
135
  C: (f, a) => f(...a)
127
136
  });
@@ -135,7 +144,7 @@ var DataServiceHost = class {
135
144
  seq: receipt2.seq
136
145
  }, {
137
146
  F: __dxlog_file,
138
- L: 88,
147
+ L: 101,
139
148
  S: this,
140
149
  C: (f, a) => f(...a)
141
150
  });
@@ -202,7 +211,7 @@ var DatabaseHost = class {
202
211
 
203
212
  // packages/core/echo/echo-pipeline/src/dbhost/snapshot-manager.ts
204
213
  var import_async = require("@dxos/async");
205
- var import_context = require("@dxos/context");
214
+ var import_context2 = require("@dxos/context");
206
215
  var import_debug = require("@dxos/debug");
207
216
  var import_keys = require("@dxos/keys");
208
217
  var import_protocols = require("@dxos/protocols");
@@ -234,7 +243,7 @@ var SnapshotManager = class SnapshotManager2 {
234
243
  if (blobMeta && blobMeta.state === import_blob.BlobMeta.State.FULLY_PRESENT) {
235
244
  return this._getBlob(blobId);
236
245
  }
237
- const fallbackStore = await (0, import_context.cancelWithContext)(ctx, this._snapshotStore.loadSnapshot(id));
246
+ const fallbackStore = await (0, import_context2.cancelWithContext)(ctx, this._snapshotStore.loadSnapshot(id));
238
247
  if (fallbackStore) {
239
248
  return fallbackStore;
240
249
  }
@@ -313,7 +322,7 @@ var DataServiceSubscriptions = class {
313
322
  clear() {
314
323
  this._spaces.clear();
315
324
  }
316
- registerSpace(spaceKey, host) {
325
+ async registerSpace(spaceKey, host) {
317
326
  (0, import_log2.log)("Registering space", {
318
327
  spaceKey
319
328
  }, {
@@ -322,17 +331,21 @@ var DataServiceSubscriptions = class {
322
331
  S: this,
323
332
  C: (f, a) => f(...a)
324
333
  });
334
+ (0, import_tiny_invariant2.default)(!this._spaces.has(spaceKey));
335
+ await host.open();
325
336
  this._spaces.set(spaceKey, host);
326
337
  }
327
- unregisterSpace(spaceKey) {
338
+ async unregisterSpace(spaceKey) {
328
339
  (0, import_log2.log)("Unregistering space", {
329
340
  spaceKey
330
341
  }, {
331
342
  F: __dxlog_file2,
332
- L: 36,
343
+ L: 38,
333
344
  S: this,
334
345
  C: (f, a) => f(...a)
335
346
  });
347
+ const host = this._spaces.get(spaceKey);
348
+ await (host == null ? void 0 : host.close());
336
349
  this._spaces.delete(spaceKey);
337
350
  }
338
351
  getDataService(spaceKey) {
@@ -365,6 +378,7 @@ var import_async2 = require("@dxos/async");
365
378
  var import_errors = require("@dxos/errors");
366
379
  var import_log3 = require("@dxos/log");
367
380
  var import_protocols3 = require("@dxos/protocols");
381
+ var import_services = require("@dxos/protocols/proto/dxos/client/services");
368
382
  var import_util3 = require("@dxos/util");
369
383
  function _ts_decorate2(decorators, target, key, desc) {
370
384
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -383,6 +397,7 @@ var emptyEchoMetadata = () => ({
383
397
  created: new Date(),
384
398
  updated: new Date()
385
399
  });
400
+ var EchoMetadata = import_protocols3.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
386
401
  var MetadataStore = class {
387
402
  // prettier-ignore
388
403
  constructor(_directory) {
@@ -409,6 +424,7 @@ var MetadataStore = class {
409
424
  * Loads metadata from persistent storage.
410
425
  */
411
426
  async load() {
427
+ var _a;
412
428
  const file = this._directory.getOrCreateFile("EchoMetadata");
413
429
  try {
414
430
  const { size: fileLength } = await file.stat();
@@ -422,7 +438,7 @@ var MetadataStore = class {
422
438
  checksum
423
439
  }, {
424
440
  F: __dxlog_file3,
425
- L: 69,
441
+ L: 72,
426
442
  S: this,
427
443
  C: (f, a) => f(...a)
428
444
  });
@@ -434,13 +450,17 @@ var MetadataStore = class {
434
450
  if (calculatedChecksum !== checksum) {
435
451
  throw new import_errors.DataCorruptionError("Metadata checksum is invalid.");
436
452
  }
437
- this._metadata = import_protocols3.schema.getCodecForType("dxos.echo.metadata.EchoMetadata").decode(data);
453
+ this._metadata = EchoMetadata.decode(data);
454
+ (_a = this._metadata.spaces) == null ? void 0 : _a.forEach((space) => {
455
+ var _a2;
456
+ (_a2 = space.state) != null ? _a2 : space.state = import_services.SpaceState.ACTIVE;
457
+ });
438
458
  } catch (err) {
439
459
  import_log3.log.error("failed to load metadata", {
440
460
  err
441
461
  }, {
442
462
  F: __dxlog_file3,
443
- L: 84,
463
+ L: 92,
444
464
  S: this,
445
465
  C: (f, a) => f(...a)
446
466
  });
@@ -460,7 +480,7 @@ var MetadataStore = class {
460
480
  this.update.emit(data);
461
481
  const file = this._directory.getOrCreateFile("EchoMetadata");
462
482
  try {
463
- const encoded = (0, import_util3.arrayToBuffer)(import_protocols3.schema.getCodecForType("dxos.echo.metadata.EchoMetadata").encode(data));
483
+ const encoded = (0, import_util3.arrayToBuffer)(EchoMetadata.encode(data));
464
484
  const checksum = import_crc_32.default.buf(encoded);
465
485
  const result = Buffer.alloc(8 + encoded.length);
466
486
  result.writeInt32LE(encoded.length, 0);
@@ -472,7 +492,7 @@ var MetadataStore = class {
472
492
  checksum
473
493
  }, {
474
494
  F: __dxlog_file3,
475
- L: 116,
495
+ L: 124,
476
496
  S: this,
477
497
  C: (f, a) => f(...a)
478
498
  });
@@ -495,7 +515,7 @@ var MetadataStore = class {
495
515
  async clear() {
496
516
  (0, import_log3.log)("clearing all metadata", void 0, {
497
517
  F: __dxlog_file3,
498
- L: 137,
518
+ L: 145,
499
519
  S: this,
500
520
  C: (f, a) => f(...a)
501
521
  });
@@ -534,6 +554,10 @@ var MetadataStore = class {
534
554
  space.dataFeedKey = dataFeedKey;
535
555
  await this._save();
536
556
  }
557
+ async setSpaceState(spaceKey, state) {
558
+ this._getSpace(spaceKey).state = state;
559
+ await this._save();
560
+ }
537
561
  };
538
562
  _ts_decorate2([
539
563
  import_async2.synchronized
@@ -546,7 +570,7 @@ var fromBytesInt32 = (buf) => buf.readInt32LE(0);
546
570
  // packages/core/echo/echo-pipeline/src/space/auth.ts
547
571
  var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
548
572
  var import_async3 = require("@dxos/async");
549
- var import_context2 = require("@dxos/context");
573
+ var import_context3 = require("@dxos/context");
550
574
  var import_crypto2 = require("@dxos/crypto");
551
575
  var import_log4 = require("@dxos/log");
552
576
  var import_protocols4 = require("@dxos/protocols");
@@ -564,7 +588,7 @@ var AuthExtension = class extends import_teleport.RpcExtension {
564
588
  timeout: 60 * 1e3
565
589
  });
566
590
  this._authParams = _authParams;
567
- this._ctx = new import_context2.Context({
591
+ this._ctx = new import_context3.Context({
568
592
  onError: (err) => {
569
593
  import_log4.log.catch(err, void 0, {
570
594
  F: __dxlog_file4,
@@ -648,7 +672,7 @@ var import_util5 = require("@dxos/util");
648
672
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
649
673
  var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
650
674
  var import_async5 = require("@dxos/async");
651
- var import_context3 = require("@dxos/context");
675
+ var import_context4 = require("@dxos/context");
652
676
  var import_debug4 = require("@dxos/debug");
653
677
  var import_feed_store = require("@dxos/feed-store");
654
678
  var import_keys3 = require("@dxos/keys");
@@ -805,6 +829,7 @@ var PipelineState = class {
805
829
  constructor(_feeds, _timeframeClock) {
806
830
  this._feeds = _feeds;
807
831
  this._timeframeClock = _timeframeClock;
832
+ this._ctx = new import_context4.Context();
808
833
  this.timeframeUpdate = this._timeframeClock.update;
809
834
  this.stalled = new import_async5.Event();
810
835
  this._startTimeframe = new import_timeframe2.Timeframe();
@@ -848,7 +873,7 @@ var PipelineState = class {
848
873
  *
849
874
  * @param timeout Timeout in milliseconds to specify the maximum wait time.
850
875
  */
851
- async waitUntilReachedTargetTimeframe({ ctx = new import_context3.Context(), timeout, breakOnStall = true } = {}) {
876
+ async waitUntilReachedTargetTimeframe({ ctx = new import_context4.Context(), timeout, breakOnStall = true } = {}) {
852
877
  var _a;
853
878
  (0, import_log7.log)("waitUntilReachedTargetTimeframe", {
854
879
  timeout,
@@ -856,7 +881,7 @@ var PipelineState = class {
856
881
  target: this.targetTimeframe
857
882
  }, {
858
883
  F: __dxlog_file7,
859
- L: 118,
884
+ L: 126,
860
885
  S: this,
861
886
  C: (f, a) => f(...a)
862
887
  });
@@ -871,7 +896,8 @@ var PipelineState = class {
871
896
  let done = false;
872
897
  if (timeout) {
873
898
  return Promise.race([
874
- (0, import_context3.rejectOnDispose)(ctx),
899
+ (0, import_context4.rejectOnDispose)(ctx),
900
+ (0, import_context4.rejectOnDispose)(this._ctx),
875
901
  this._reachedTargetPromise.then(() => {
876
902
  done = true;
877
903
  }),
@@ -886,7 +912,7 @@ var PipelineState = class {
886
912
  dependencies: import_timeframe2.Timeframe.dependencies(this.targetTimeframe, this.timeframe)
887
913
  }, {
888
914
  F: __dxlog_file7,
889
- L: 144,
915
+ L: 153,
890
916
  S: this,
891
917
  C: (f, a) => f(...a)
892
918
  });
@@ -944,7 +970,7 @@ var Pipeline = class {
944
970
  async start() {
945
971
  (0, import_log7.log)("starting...", {}, {
946
972
  F: __dxlog_file7,
947
- L: 264,
973
+ L: 273,
948
974
  S: this,
949
975
  C: (f, a) => f(...a)
950
976
  });
@@ -952,7 +978,7 @@ var Pipeline = class {
952
978
  await this._feedSetIterator.open();
953
979
  (0, import_log7.log)("started", void 0, {
954
980
  F: __dxlog_file7,
955
- L: 267,
981
+ L: 276,
956
982
  S: this,
957
983
  C: (f, a) => f(...a)
958
984
  });
@@ -962,16 +988,19 @@ var Pipeline = class {
962
988
  var _a;
963
989
  (0, import_log7.log)("stopping...", {}, {
964
990
  F: __dxlog_file7,
965
- L: 273,
991
+ L: 282,
966
992
  S: this,
967
993
  C: (f, a) => f(...a)
968
994
  });
969
995
  this._isStopping = true;
970
996
  await ((_a = this._feedSetIterator) == null ? void 0 : _a.close());
971
997
  await this._processingTrigger.wait();
998
+ await this._state._ctx.dispose();
999
+ this._state._ctx = new import_context4.Context();
1000
+ this._state._reachedTargetPromise = void 0;
972
1001
  (0, import_log7.log)("stopped", void 0, {
973
1002
  F: __dxlog_file7,
974
- L: 277,
1003
+ L: 289,
975
1004
  S: this,
976
1005
  C: (f, a) => f(...a)
977
1006
  });
@@ -1048,7 +1077,7 @@ var Pipeline = class {
1048
1077
  feed.undownload({
1049
1078
  callback: () => (0, import_log7.log)("Undownloaded", void 0, {
1050
1079
  F: __dxlog_file7,
1051
- L: 371,
1080
+ L: 383,
1052
1081
  S: this,
1053
1082
  C: (f, a) => f(...a)
1054
1083
  })
@@ -1061,7 +1090,7 @@ var Pipeline = class {
1061
1090
  err
1062
1091
  }, {
1063
1092
  F: __dxlog_file7,
1064
- L: 374,
1093
+ L: 386,
1065
1094
  S: this,
1066
1095
  C: (f, a) => f(...a)
1067
1096
  });
@@ -1075,7 +1104,7 @@ var Pipeline = class {
1075
1104
  this._feedSetIterator.stalled.on((iterator) => {
1076
1105
  import_log7.log.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
1077
1106
  F: __dxlog_file7,
1078
- L: 384,
1107
+ L: 396,
1079
1108
  S: this,
1080
1109
  C: (f, a) => f(...a)
1081
1110
  });
@@ -1244,7 +1273,7 @@ var ControlPipeline = class {
1244
1273
  // packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
1245
1274
  var import_tiny_invariant8 = __toESM(require("tiny-invariant"));
1246
1275
  var import_async6 = require("@dxos/async");
1247
- var import_context4 = require("@dxos/context");
1276
+ var import_context5 = require("@dxos/context");
1248
1277
  var import_credentials3 = require("@dxos/credentials");
1249
1278
  var import_echo_db3 = require("@dxos/echo-db");
1250
1279
  var import_errors2 = require("@dxos/errors");
@@ -1267,11 +1296,15 @@ var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
1267
1296
  var DataPipeline = class DataPipeline2 {
1268
1297
  constructor(_params) {
1269
1298
  this._params = _params;
1270
- this._ctx = new import_context4.Context();
1299
+ this._ctx = new import_context5.Context();
1300
+ this._pipeline = void 0;
1301
+ this._targetTimeframe = void 0;
1271
1302
  this._lastAutomaticSnapshotTimeframe = new import_timeframe4.Timeframe();
1272
1303
  this._isOpen = false;
1273
1304
  this._lastTimeframeSaveTime = 0;
1274
1305
  this._lastSnapshotSaveTime = 0;
1306
+ this.currentEpoch = void 0;
1307
+ this.appliedEpoch = void 0;
1275
1308
  this._lastProcessedEpoch = -1;
1276
1309
  this.onNewEpoch = new import_async6.Event();
1277
1310
  }
@@ -1290,18 +1323,14 @@ var DataPipeline = class DataPipeline2 {
1290
1323
  this._targetTimeframe = timeframe;
1291
1324
  (_a = this._pipeline) == null ? void 0 : _a.state.setTargetTimeframe(timeframe);
1292
1325
  }
1293
- createCredentialProcessor() {
1294
- return {
1295
- process: async (credential) => {
1296
- if (!(0, import_credentials3.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
1297
- return;
1298
- }
1299
- this.currentEpoch = credential;
1300
- if (this._isOpen) {
1301
- await this._processEpochInSeparateTask(credential);
1302
- }
1303
- }
1304
- };
1326
+ async processCredential(credential) {
1327
+ if (!(0, import_credentials3.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
1328
+ return;
1329
+ }
1330
+ this.currentEpoch = credential;
1331
+ if (this._isOpen) {
1332
+ await this._processEpochInSeparateTask(credential);
1333
+ }
1305
1334
  }
1306
1335
  async open() {
1307
1336
  if (this._isOpen) {
@@ -1338,7 +1367,7 @@ var DataPipeline = class DataPipeline2 {
1338
1367
  }
1339
1368
  (0, import_log9.log)("close", void 0, {
1340
1369
  F: __dxlog_file9,
1341
- L: 174,
1370
+ L: 171,
1342
1371
  S: this,
1343
1372
  C: (f, a) => f(...a)
1344
1373
  });
@@ -1353,13 +1382,21 @@ var DataPipeline = class DataPipeline2 {
1353
1382
  } catch (err) {
1354
1383
  import_log9.log.catch(err, void 0, {
1355
1384
  F: __dxlog_file9,
1356
- L: 187,
1385
+ L: 184,
1357
1386
  S: this,
1358
1387
  C: (f, a) => f(...a)
1359
1388
  });
1360
1389
  }
1361
1390
  await ((_b = this.databaseHost) == null ? void 0 : _b.close());
1362
1391
  await ((_c = this.itemManager) == null ? void 0 : _c.destroy());
1392
+ this._ctx = new import_context5.Context();
1393
+ this._pipeline = void 0;
1394
+ this._targetTimeframe = void 0;
1395
+ this._lastAutomaticSnapshotTimeframe = new import_timeframe4.Timeframe();
1396
+ this.currentEpoch = void 0;
1397
+ this.appliedEpoch = void 0;
1398
+ this._lastProcessedEpoch = -1;
1399
+ this._epochCtx = void 0;
1363
1400
  }
1364
1401
  async _consumePipeline() {
1365
1402
  if (this.currentEpoch) {
@@ -1375,7 +1412,7 @@ var DataPipeline = class DataPipeline2 {
1375
1412
  seq
1376
1413
  }, {
1377
1414
  F: __dxlog_file9,
1378
- L: 204,
1415
+ L: 210,
1379
1416
  S: this,
1380
1417
  C: (f, a) => f(...a)
1381
1418
  });
@@ -1387,7 +1424,7 @@ var DataPipeline = class DataPipeline2 {
1387
1424
  feedKey
1388
1425
  }, {
1389
1426
  F: __dxlog_file9,
1390
- L: 210,
1427
+ L: 216,
1391
1428
  S: this,
1392
1429
  C: (f, a) => f(...a)
1393
1430
  });
@@ -1408,7 +1445,7 @@ var DataPipeline = class DataPipeline2 {
1408
1445
  spaceKey: this._params.spaceKey.toHex()
1409
1446
  }, {
1410
1447
  F: __dxlog_file9,
1411
- L: 224,
1448
+ L: 230,
1412
1449
  S: this,
1413
1450
  C: (f, a) => f(...a)
1414
1451
  });
@@ -1417,7 +1454,7 @@ var DataPipeline = class DataPipeline2 {
1417
1454
  } catch (err) {
1418
1455
  import_log9.log.catch(err, void 0, {
1419
1456
  F: __dxlog_file9,
1420
- L: 234,
1457
+ L: 240,
1421
1458
  S: this,
1422
1459
  C: (f, a) => f(...a)
1423
1460
  });
@@ -1452,7 +1489,7 @@ var DataPipeline = class DataPipeline2 {
1452
1489
  } catch (err) {
1453
1490
  import_log9.log.warn("Failed to cache properties", err, {
1454
1491
  F: __dxlog_file9,
1455
- L: 269,
1492
+ L: 275,
1456
1493
  S: this,
1457
1494
  C: (f, a) => f(...a)
1458
1495
  });
@@ -1474,19 +1511,19 @@ var DataPipeline = class DataPipeline2 {
1474
1511
  return;
1475
1512
  }
1476
1513
  await ((_a = this._epochCtx) == null ? void 0 : _a.dispose());
1477
- const ctx = new import_context4.Context({
1514
+ const ctx = new import_context5.Context({
1478
1515
  onError: (err) => {
1479
1516
  if (err instanceof import_errors2.CancelledError) {
1480
1517
  (0, import_log9.log)("Epoch processing cancelled.", void 0, {
1481
1518
  F: __dxlog_file9,
1482
- L: 301,
1519
+ L: 307,
1483
1520
  S: this,
1484
1521
  C: (f, a) => f(...a)
1485
1522
  });
1486
1523
  } else {
1487
1524
  import_log9.log.catch(err, void 0, {
1488
1525
  F: __dxlog_file9,
1489
- L: 303,
1526
+ L: 309,
1490
1527
  S: this,
1491
1528
  C: (f, a) => f(...a)
1492
1529
  });
@@ -1502,7 +1539,7 @@ var DataPipeline = class DataPipeline2 {
1502
1539
  epoch
1503
1540
  }, {
1504
1541
  F: __dxlog_file9,
1505
- L: 313,
1542
+ L: 319,
1506
1543
  S: this,
1507
1544
  C: (f, a) => f(...a)
1508
1545
  });
@@ -1519,7 +1556,7 @@ var DataPipeline = class DataPipeline2 {
1519
1556
  epoch
1520
1557
  }, {
1521
1558
  F: __dxlog_file9,
1522
- L: 327,
1559
+ L: 333,
1523
1560
  S: this,
1524
1561
  C: (f, a) => f(...a)
1525
1562
  });
@@ -1529,7 +1566,7 @@ var DataPipeline = class DataPipeline2 {
1529
1566
  }
1530
1567
  (0, import_log9.log)("restarting pipeline for epoch", void 0, {
1531
1568
  F: __dxlog_file9,
1532
- L: 335,
1569
+ L: 341,
1533
1570
  S: this,
1534
1571
  C: (f, a) => f(...a)
1535
1572
  });
@@ -1593,8 +1630,6 @@ var Space = class Space2 {
1593
1630
  this._addFeedLock = new import_async7.Lock();
1594
1631
  this.onCredentialProcessed = new import_util6.Callback();
1595
1632
  this.stateUpdate = new import_async7.Event();
1596
- // Processes epoch credentials.
1597
- this._dataPipelineCredentialConsumer = void 0;
1598
1633
  this._isOpen = false;
1599
1634
  (0, import_tiny_invariant9.default)(params.spaceKey && params.feedProvider);
1600
1635
  this._key = params.spaceKey;
@@ -1632,7 +1667,7 @@ var Space = class Space2 {
1632
1667
  credential
1633
1668
  }, {
1634
1669
  F: __dxlog_file10,
1635
- L: 110,
1670
+ L: 107,
1636
1671
  S: this,
1637
1672
  C: (f, a) => f(...a)
1638
1673
  });
@@ -1724,7 +1759,7 @@ var Space = class Space2 {
1724
1759
  async open() {
1725
1760
  (0, import_log10.log)("opening...", void 0, {
1726
1761
  F: __dxlog_file10,
1727
- L: 212,
1762
+ L: 209,
1728
1763
  S: this,
1729
1764
  C: (f, a) => f(...a)
1730
1765
  });
@@ -1733,38 +1768,35 @@ var Space = class Space2 {
1733
1768
  }
1734
1769
  await this._controlPipeline.start();
1735
1770
  await this.protocol.start();
1736
- this._dataPipelineCredentialConsumer = this._controlPipeline.spaceState.registerProcessor(this._dataPipeline.createCredentialProcessor());
1737
- await this._dataPipelineCredentialConsumer.open();
1771
+ await this._controlPipeline.spaceState.addCredentialProcessor(this._dataPipeline);
1738
1772
  this._isOpen = true;
1739
1773
  (0, import_log10.log)("opened", void 0, {
1740
1774
  F: __dxlog_file10,
1741
- L: 228,
1775
+ L: 220,
1742
1776
  S: this,
1743
1777
  C: (f, a) => f(...a)
1744
1778
  });
1745
1779
  }
1746
1780
  async close() {
1747
- var _a;
1748
1781
  (0, import_log10.log)("closing...", {
1749
1782
  key: this._key
1750
1783
  }, {
1751
1784
  F: __dxlog_file10,
1752
- L: 233,
1785
+ L: 225,
1753
1786
  S: this,
1754
1787
  C: (f, a) => f(...a)
1755
1788
  });
1756
1789
  if (!this._isOpen) {
1757
1790
  return;
1758
1791
  }
1759
- await ((_a = this._dataPipelineCredentialConsumer) == null ? void 0 : _a.close());
1760
- this._dataPipelineCredentialConsumer = void 0;
1792
+ await this._controlPipeline.spaceState.removeCredentialProcessor(this._dataPipeline);
1761
1793
  await this._dataPipeline.close();
1762
1794
  await this.protocol.stop();
1763
1795
  await this._controlPipeline.stop();
1764
1796
  this._isOpen = false;
1765
1797
  (0, import_log10.log)("closed", void 0, {
1766
1798
  F: __dxlog_file10,
1767
- L: 247,
1799
+ L: 238,
1768
1800
  S: this,
1769
1801
  C: (f, a) => f(...a)
1770
1802
  });
@@ -1772,7 +1804,7 @@ var Space = class Space2 {
1772
1804
  async initializeDataPipeline() {
1773
1805
  (0, import_log10.log)("initializeDataPipeline", void 0, {
1774
1806
  F: __dxlog_file10,
1775
- L: 252,
1807
+ L: 243,
1776
1808
  S: this,
1777
1809
  C: (f, a) => f(...a)
1778
1810
  });
@@ -2318,7 +2350,7 @@ var createRemoteDatabaseFromDataServiceHost = async (modelFactory, dataServiceHo
2318
2350
  const dataServiceSubscriptions = new DataServiceSubscriptions();
2319
2351
  const dataService = new DataServiceImpl(dataServiceSubscriptions);
2320
2352
  const spaceKey = import_keys8.PublicKey.random();
2321
- dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);
2353
+ await dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);
2322
2354
  const itemManager = new import_echo_db4.ItemManager(modelFactory);
2323
2355
  const backend = new import_echo_db4.DatabaseProxy(dataService, itemManager, spaceKey);
2324
2356
  await backend.open(new import_model_factory2.ModelFactory().registerModel(import_document_model2.DocumentModel));