@dxos/client-services 0.1.53-next.63b0547 → 0.1.53-next.e9dc2bc

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 (42) hide show
  1. package/dist/lib/browser/{chunk-RKD47ENR.mjs → chunk-3EI4PM2V.mjs} +194 -110
  2. package/dist/lib/browser/chunk-3EI4PM2V.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -2
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +19 -2
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +196 -106
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +203 -103
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  14. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  15. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-host.d.ts +6 -1
  17. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/data-space.d.ts +11 -2
  20. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +2 -1
  22. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  24. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -1
  26. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  27. package/package.json +32 -32
  28. package/src/packlets/identity/authenticator.ts +4 -2
  29. package/src/packlets/identity/identity.ts +21 -26
  30. package/src/packlets/services/service-context.ts +9 -7
  31. package/src/packlets/services/service-host.test.ts +50 -2
  32. package/src/packlets/services/service-host.ts +9 -0
  33. package/src/packlets/spaces/data-space-manager.test.ts +75 -119
  34. package/src/packlets/spaces/data-space-manager.ts +13 -3
  35. package/src/packlets/spaces/data-space.ts +66 -20
  36. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  37. package/src/packlets/spaces/notarization-plugin.ts +5 -1
  38. package/src/packlets/spaces/spaces-service.test.ts +5 -3
  39. package/src/packlets/spaces/spaces-service.ts +26 -8
  40. package/src/packlets/testing/test-builder.ts +35 -2
  41. package/src/packlets/vault/worker-runtime.ts +1 -1
  42. package/dist/lib/browser/chunk-RKD47ENR.mjs.map +0 -7
@@ -353,6 +353,7 @@ import { verifyCredential } from "@dxos/credentials";
353
353
  import { log } from "@dxos/log";
354
354
  import { schema } from "@dxos/protocols";
355
355
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
356
+ var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
356
357
  var createAuthProvider = (signer) => async (nonce) => {
357
358
  const credential = await signer.createCredential({
358
359
  assertion: {
@@ -361,7 +362,7 @@ var createAuthProvider = (signer) => async (nonce) => {
361
362
  subject: signer.getIssuer(),
362
363
  nonce
363
364
  });
364
- return schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
365
+ return Credential.encode(credential);
365
366
  };
366
367
  var TrustedKeySetAuthVerifier = class {
367
368
  // prettier-ignore
@@ -374,12 +375,12 @@ var TrustedKeySetAuthVerifier = class {
374
375
  }
375
376
  get verifier() {
376
377
  return async (nonce, auth) => {
377
- const credential = schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
378
+ const credential = Credential.decode(auth);
378
379
  log("authenticating...", {
379
380
  credential
380
381
  }, {
381
382
  F: __dxlog_file,
382
- L: 57,
383
+ L: 59,
383
384
  S: this,
384
385
  C: (f, a) => f(...a)
385
386
  });
@@ -389,7 +390,7 @@ var TrustedKeySetAuthVerifier = class {
389
390
  result
390
391
  }, {
391
392
  F: __dxlog_file,
392
- L: 61,
393
+ L: 63,
393
394
  S: this,
394
395
  C: (f, a) => f(...a)
395
396
  });
@@ -401,7 +402,7 @@ var TrustedKeySetAuthVerifier = class {
401
402
  credential
402
403
  }, {
403
404
  F: __dxlog_file,
404
- L: 66,
405
+ L: 68,
405
406
  S: this,
406
407
  C: (f, a) => f(...a)
407
408
  });
@@ -412,7 +413,7 @@ var TrustedKeySetAuthVerifier = class {
412
413
  key: credential.issuer
413
414
  }, {
414
415
  F: __dxlog_file,
415
- L: 71,
416
+ L: 73,
416
417
  S: this,
417
418
  C: (f, a) => f(...a)
418
419
  });
@@ -428,7 +429,7 @@ var TrustedKeySetAuthVerifier = class {
428
429
  key: credential.issuer
429
430
  }, {
430
431
  F: __dxlog_file,
431
- L: 82,
432
+ L: 84,
432
433
  S: this,
433
434
  C: (f, a) => f(...a)
434
435
  });
@@ -438,7 +439,7 @@ var TrustedKeySetAuthVerifier = class {
438
439
  key: credential.issuer
439
440
  }, {
440
441
  F: __dxlog_file,
441
- L: 85,
442
+ L: 87,
442
443
  S: this,
443
444
  C: (f, a) => f(...a)
444
445
  });
@@ -478,15 +479,15 @@ var Identity = class {
478
479
  this._signer = signer;
479
480
  this.identityKey = identityKey;
480
481
  this.deviceKey = deviceKey;
481
- this._deviceStateMachine = this.space.spaceState.registerProcessor(new DeviceStateMachine({
482
+ this._deviceStateMachine = new DeviceStateMachine({
482
483
  identityKey: this.identityKey,
483
484
  deviceKey: this.deviceKey,
484
485
  onUpdate: () => this.stateUpdate.emit()
485
- }));
486
- this._profileStateMachine = this.space.spaceState.registerProcessor(new ProfileStateMachine({
486
+ });
487
+ this._profileStateMachine = new ProfileStateMachine({
487
488
  identityKey: this.identityKey,
488
489
  onUpdate: () => this.stateUpdate.emit()
489
- }));
490
+ });
490
491
  this.authVerifier = new TrustedKeySetAuthVerifier({
491
492
  trustedKeysProvider: () => this.authorizedDeviceKeys,
492
493
  update: this.stateUpdate,
@@ -495,27 +496,27 @@ var Identity = class {
495
496
  }
496
497
  // TODO(burdon): Expose state object?
497
498
  get authorizedDeviceKeys() {
498
- return this._deviceStateMachine.processor.authorizedDeviceKeys;
499
+ return this._deviceStateMachine.authorizedDeviceKeys;
499
500
  }
500
501
  async open() {
501
- await this._deviceStateMachine.open();
502
- await this._profileStateMachine.open();
502
+ await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
503
+ await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
503
504
  await this.space.open();
504
505
  }
505
506
  async close() {
506
507
  await this.authVerifier.close();
507
- await this._deviceStateMachine.close();
508
- await this._profileStateMachine.close();
508
+ await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
509
+ await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
509
510
  await this.space.close();
510
511
  }
511
512
  async ready() {
512
- await this._deviceStateMachine.processor.deviceChainReady.wait();
513
+ await this._deviceStateMachine.deviceChainReady.wait();
513
514
  await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
514
515
  timeout: LOAD_CONTROL_FEEDS_TIMEOUT
515
516
  });
516
517
  }
517
518
  get profileDocument() {
518
- return this._profileStateMachine.processor.profile;
519
+ return this._profileStateMachine.profile;
519
520
  }
520
521
  /**
521
522
  * @test-only
@@ -530,7 +531,7 @@ var Identity = class {
530
531
  return this.space.genesisFeedKey;
531
532
  }
532
533
  get deviceCredentialChain() {
533
- return this._deviceStateMachine.processor.deviceCredentialChain;
534
+ return this._deviceStateMachine.deviceCredentialChain;
534
535
  }
535
536
  getAdmissionCredentials() {
536
537
  var _a, _b;
@@ -545,8 +546,8 @@ var Identity = class {
545
546
  * Requires identity to be ready.
546
547
  */
547
548
  getIdentityCredentialSigner() {
548
- invariant(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
549
- return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
549
+ invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
550
+ return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
550
551
  }
551
552
  /**
552
553
  * Issues credentials as device.
@@ -563,7 +564,7 @@ var Identity = class {
563
564
  dataFeedKey
564
565
  }, {
565
566
  F: __dxlog_file2,
566
- L: 156,
567
+ L: 151,
567
568
  S: this,
568
569
  C: (f, a) => f(...a)
569
570
  });
@@ -2082,7 +2083,7 @@ var SpaceInvitationProtocol = class {
2082
2083
  };
2083
2084
 
2084
2085
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2085
- import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2086
+ import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2086
2087
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2087
2088
  import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2088
2089
  import { timed } from "@dxos/debug";
@@ -2117,6 +2118,9 @@ var NotarizationPlugin = class {
2117
2118
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
2118
2119
  this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2119
2120
  }
2121
+ get hasWriter() {
2122
+ return !!this._writer;
2123
+ }
2120
2124
  async open() {
2121
2125
  }
2122
2126
  async close() {
@@ -2130,7 +2134,7 @@ var NotarizationPlugin = class {
2130
2134
  credentials
2131
2135
  }, {
2132
2136
  F: __dxlog_file8,
2133
- L: 87,
2137
+ L: 91,
2134
2138
  S: this,
2135
2139
  C: (f, a) => f(...a)
2136
2140
  });
@@ -2142,7 +2146,7 @@ var NotarizationPlugin = class {
2142
2146
  err
2143
2147
  }, {
2144
2148
  F: __dxlog_file8,
2145
- L: 96,
2149
+ L: 100,
2146
2150
  S: this,
2147
2151
  C: (f, a) => f(...a)
2148
2152
  });
@@ -2158,7 +2162,7 @@ var NotarizationPlugin = class {
2158
2162
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2159
2163
  }, {
2160
2164
  F: __dxlog_file8,
2161
- L: 108,
2165
+ L: 112,
2162
2166
  S: this,
2163
2167
  C: (f, a) => f(...a)
2164
2168
  });
@@ -2181,7 +2185,7 @@ var NotarizationPlugin = class {
2181
2185
  retryIn: retryTimeout
2182
2186
  }, {
2183
2187
  F: __dxlog_file8,
2184
- L: 133,
2188
+ L: 137,
2185
2189
  S: this,
2186
2190
  C: (f, a) => f(...a)
2187
2191
  });
@@ -2195,7 +2199,7 @@ var NotarizationPlugin = class {
2195
2199
  credentialId: credentials.map((credential) => credential.id)
2196
2200
  }, {
2197
2201
  F: __dxlog_file8,
2198
- L: 140,
2202
+ L: 144,
2199
2203
  S: this,
2200
2204
  C: (f, a) => f(...a)
2201
2205
  });
@@ -2204,7 +2208,7 @@ var NotarizationPlugin = class {
2204
2208
  });
2205
2209
  log8("success", void 0, {
2206
2210
  F: __dxlog_file8,
2207
- L: 144,
2211
+ L: 148,
2208
2212
  S: this,
2209
2213
  C: (f, a) => f(...a)
2210
2214
  });
@@ -2213,7 +2217,7 @@ var NotarizationPlugin = class {
2213
2217
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2214
2218
  log8.warn("error notarizing (recoverable)", err, {
2215
2219
  F: __dxlog_file8,
2216
- L: 148,
2220
+ L: 152,
2217
2221
  S: this,
2218
2222
  C: (f, a) => f(...a)
2219
2223
  });
@@ -2231,7 +2235,7 @@ var NotarizationPlugin = class {
2231
2235
  ]);
2232
2236
  log8("done", void 0, {
2233
2237
  F: __dxlog_file8,
2234
- L: 159,
2238
+ L: 163,
2235
2239
  S: this,
2236
2240
  C: (f, a) => f(...a)
2237
2241
  });
@@ -2242,7 +2246,7 @@ var NotarizationPlugin = class {
2242
2246
  /**
2243
2247
  * Called with credentials arriving from the control pipeline.
2244
2248
  */
2245
- async process(credential) {
2249
+ async processCredential(credential) {
2246
2250
  var _a;
2247
2251
  if (!credential.id) {
2248
2252
  return;
@@ -2284,7 +2288,7 @@ var NotarizationPlugin = class {
2284
2288
  peer: extension.localPeerId
2285
2289
  }, {
2286
2290
  F: __dxlog_file8,
2287
- L: 208,
2291
+ L: 212,
2288
2292
  S: this,
2289
2293
  C: (f, a) => f(...a)
2290
2294
  });
@@ -2296,7 +2300,7 @@ var NotarizationPlugin = class {
2296
2300
  peer: extension.localPeerId
2297
2301
  }, {
2298
2302
  F: __dxlog_file8,
2299
- L: 213,
2303
+ L: 217,
2300
2304
  S: this,
2301
2305
  C: (f, a) => f(...a)
2302
2306
  });
@@ -2353,6 +2357,7 @@ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/sr
2353
2357
  var DataSpace = class DataSpace2 {
2354
2358
  constructor(params) {
2355
2359
  this._ctx = new Context6();
2360
+ this._notarizationPlugin = new NotarizationPlugin();
2356
2361
  this._state = SpaceState.CLOSED;
2357
2362
  /**
2358
2363
  * Error for _state === SpaceState.ERROR.
@@ -2375,8 +2380,8 @@ var DataSpace = class DataSpace2 {
2375
2380
  update: this._inner.stateUpdate,
2376
2381
  authTimeout: AUTH_TIMEOUT2
2377
2382
  });
2378
- this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2379
2383
  this._cache = params.cache;
2384
+ this._state = params.initialState;
2380
2385
  }
2381
2386
  get key() {
2382
2387
  return this._inner.key;
@@ -2398,25 +2403,36 @@ var DataSpace = class DataSpace2 {
2398
2403
  return this._presence;
2399
2404
  }
2400
2405
  get notarizationPlugin() {
2401
- return this._notarizationPluginConsumer.processor;
2406
+ return this._notarizationPlugin;
2402
2407
  }
2403
2408
  get cache() {
2404
2409
  return this._cache;
2405
2410
  }
2406
2411
  async open() {
2407
- await this.notarizationPlugin.open();
2408
- await this._notarizationPluginConsumer.open();
2412
+ await this._open();
2413
+ }
2414
+ async _open() {
2415
+ await this._notarizationPlugin.open();
2416
+ await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2409
2417
  await this._inner.open();
2410
- this._state = SpaceState.INACTIVE;
2418
+ this._state = SpaceState.CONTROL_ONLY;
2419
+ this.stateUpdate.emit();
2420
+ this.metrics = {};
2411
2421
  this.metrics.open = new Date();
2412
2422
  }
2413
2423
  async close() {
2424
+ await this._close();
2425
+ }
2426
+ async _close() {
2427
+ var _a, _b;
2428
+ await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2414
2429
  this._state = SpaceState.CLOSED;
2415
2430
  await this._ctx.dispose();
2431
+ this._ctx = new Context6();
2416
2432
  await this.authVerifier.close();
2417
2433
  await this._inner.close();
2418
- await this._notarizationPluginConsumer.close();
2419
- await this.notarizationPlugin.close();
2434
+ await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
2435
+ await this._notarizationPlugin.close();
2420
2436
  await this._presence.destroy();
2421
2437
  }
2422
2438
  async postMessage(channel, message) {
@@ -2437,7 +2453,7 @@ var DataSpace = class DataSpace2 {
2437
2453
  if (err instanceof CancelledError) {
2438
2454
  log9("Data pipeline initialization cancelled", err, {
2439
2455
  F: __dxlog_file9,
2440
- L: 173,
2456
+ L: 193,
2441
2457
  S: this,
2442
2458
  C: (f, a) => f(...a)
2443
2459
  });
@@ -2445,7 +2461,7 @@ var DataSpace = class DataSpace2 {
2445
2461
  }
2446
2462
  log9.error("Error initializing data pipeline", err, {
2447
2463
  F: __dxlog_file9,
2448
- L: 177,
2464
+ L: 197,
2449
2465
  S: this,
2450
2466
  C: (f, a) => f(...a)
2451
2467
  });
@@ -2459,7 +2475,7 @@ var DataSpace = class DataSpace2 {
2459
2475
  }
2460
2476
  async initializeDataPipeline() {
2461
2477
  var _a, _b, _c, _d;
2462
- if (this._state !== SpaceState.INACTIVE) {
2478
+ if (this._state !== SpaceState.CONTROL_ONLY) {
2463
2479
  throw new SystemError("Invalid operation");
2464
2480
  }
2465
2481
  this._state = SpaceState.INITIALIZING;
@@ -2471,22 +2487,24 @@ var DataSpace = class DataSpace2 {
2471
2487
  await this._createWritableFeeds();
2472
2488
  log9("Writable feeds created", void 0, {
2473
2489
  F: __dxlog_file9,
2474
- L: 201,
2490
+ L: 221,
2475
2491
  S: this,
2476
2492
  C: (f, a) => f(...a)
2477
2493
  });
2478
2494
  this.stateUpdate.emit();
2479
- this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2480
- credential: {
2481
- credential
2482
- }
2483
- }), this._inner.controlPipeline.writer));
2495
+ if (!this.notarizationPlugin.hasWriter) {
2496
+ this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2497
+ credential: {
2498
+ credential
2499
+ }
2500
+ }), this._inner.controlPipeline.writer));
2501
+ }
2484
2502
  await this._inner.initializeDataPipeline();
2485
2503
  this.metrics.dataPipelineOpen = new Date();
2486
2504
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2487
2505
  log9("waiting for data pipeline to reach target timeframe", void 0, {
2488
2506
  F: __dxlog_file9,
2489
- L: 220,
2507
+ L: 242,
2490
2508
  S: this,
2491
2509
  C: (f, a) => f(...a)
2492
2510
  });
@@ -2497,7 +2515,7 @@ var DataSpace = class DataSpace2 {
2497
2515
  this.metrics.dataPipelineReady = new Date();
2498
2516
  log9("data pipeline ready", void 0, {
2499
2517
  F: __dxlog_file9,
2500
- L: 229,
2518
+ L: 251,
2501
2519
  S: this,
2502
2520
  C: (f, a) => f(...a)
2503
2521
  });
@@ -2577,17 +2595,46 @@ var DataSpace = class DataSpace2 {
2577
2595
  }
2578
2596
  }
2579
2597
  }
2598
+ async activate() {
2599
+ if (this._state !== SpaceState.INACTIVE) {
2600
+ throw new SystemError("Invalid operation");
2601
+ }
2602
+ await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
2603
+ await this._open();
2604
+ this.initializeDataPipelineAsync();
2605
+ }
2606
+ async deactivate() {
2607
+ if (this._state === SpaceState.INACTIVE) {
2608
+ throw new SystemError("Invalid operation");
2609
+ }
2610
+ await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
2611
+ await this._close();
2612
+ this._state = SpaceState.INACTIVE;
2613
+ this.stateUpdate.emit();
2614
+ }
2580
2615
  };
2616
+ _ts_decorate([
2617
+ synchronized
2618
+ ], DataSpace.prototype, "open", null);
2619
+ _ts_decorate([
2620
+ synchronized
2621
+ ], DataSpace.prototype, "close", null);
2581
2622
  _ts_decorate([
2582
2623
  timed(1e4)
2583
2624
  ], DataSpace.prototype, "_createWritableFeeds", null);
2625
+ _ts_decorate([
2626
+ synchronized
2627
+ ], DataSpace.prototype, "activate", null);
2628
+ _ts_decorate([
2629
+ synchronized
2630
+ ], DataSpace.prototype, "deactivate", null);
2584
2631
  DataSpace = _ts_decorate([
2585
2632
  trackLeaks("open", "close")
2586
2633
  ], DataSpace);
2587
2634
 
2588
2635
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2589
2636
  import invariant10 from "tiny-invariant";
2590
- import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2637
+ import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2591
2638
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2592
2639
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2593
2640
  import { PublicKey as PublicKey8 } from "@dxos/keys";
@@ -2732,14 +2779,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2732
2779
  C: (f, a) => f(...a)
2733
2780
  });
2734
2781
  const space = await this._constructSpace(spaceMetadata);
2735
- space.initializeDataPipelineAsync();
2782
+ if (spaceMetadata.state !== SpaceState2.INACTIVE) {
2783
+ space.initializeDataPipelineAsync();
2784
+ }
2736
2785
  } catch (err) {
2737
2786
  log10.error("Error loading space", {
2738
2787
  spaceMetadata,
2739
2788
  err
2740
2789
  }, {
2741
2790
  F: __dxlog_file10,
2742
- L: 91,
2791
+ L: 93,
2743
2792
  S: this,
2744
2793
  C: (f, a) => f(...a)
2745
2794
  });
@@ -2751,7 +2800,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2751
2800
  id: this._instanceId
2752
2801
  }), {
2753
2802
  F: __dxlog_file10,
2754
- L: 97,
2803
+ L: 99,
2755
2804
  S: this,
2756
2805
  C: (f, a) => f(...a)
2757
2806
  });
@@ -2759,7 +2808,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2759
2808
  async close() {
2760
2809
  log10("close", void 0, {
2761
2810
  F: __dxlog_file10,
2762
- L: 102,
2811
+ L: 104,
2763
2812
  S: this,
2764
2813
  C: (f, a) => f(...a)
2765
2814
  });
@@ -2781,13 +2830,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2781
2830
  key: spaceKey,
2782
2831
  genesisFeedKey: controlFeedKey,
2783
2832
  controlFeedKey,
2784
- dataFeedKey
2833
+ dataFeedKey,
2834
+ state: SpaceState2.ACTIVE
2785
2835
  };
2786
2836
  log10("creating space...", {
2787
2837
  spaceKey
2788
2838
  }, {
2789
2839
  F: __dxlog_file10,
2790
- L: 126,
2840
+ L: 129,
2791
2841
  S: this,
2792
2842
  C: (f, a) => f(...a)
2793
2843
  });
@@ -2807,7 +2857,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2807
2857
  opts
2808
2858
  }, {
2809
2859
  F: __dxlog_file10,
2810
- L: 145,
2860
+ L: 148,
2811
2861
  S: this,
2812
2862
  C: (f, a) => f(...a)
2813
2863
  });
@@ -2841,7 +2891,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2841
2891
  metadata
2842
2892
  }, {
2843
2893
  F: __dxlog_file10,
2844
- L: 180,
2894
+ L: 183,
2845
2895
  S: this,
2846
2896
  C: (f, a) => f(...a)
2847
2897
  });
@@ -2877,7 +2927,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2877
2927
  onAuthFailure: () => {
2878
2928
  log10.warn("auth failure", void 0, {
2879
2929
  F: __dxlog_file10,
2880
- L: 211,
2930
+ L: 214,
2881
2931
  S: this,
2882
2932
  C: (f, a) => f(...a)
2883
2933
  });
@@ -2888,6 +2938,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2888
2938
  dataFeed && space.setDataFeed(dataFeed);
2889
2939
  const dataSpace = new DataSpace({
2890
2940
  inner: space,
2941
+ initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
2891
2942
  metadataStore: this._metadataStore,
2892
2943
  gossip,
2893
2944
  presence,
@@ -2900,11 +2951,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2900
2951
  space: space.key
2901
2952
  }, {
2902
2953
  F: __dxlog_file10,
2903
- L: 228,
2954
+ L: 232,
2904
2955
  S: this,
2905
2956
  C: (f, a) => f(...a)
2906
2957
  });
2907
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2958
+ await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2908
2959
  },
2909
2960
  afterReady: async () => {
2910
2961
  log10("after space ready", {
@@ -2912,18 +2963,31 @@ var DataSpaceManager = class DataSpaceManager2 {
2912
2963
  open: this._isOpen
2913
2964
  }, {
2914
2965
  F: __dxlog_file10,
2915
- L: 235,
2966
+ L: 239,
2916
2967
  S: this,
2917
2968
  C: (f, a) => f(...a)
2918
2969
  });
2919
2970
  if (this._isOpen) {
2920
2971
  this.updated.emit();
2921
2972
  }
2973
+ },
2974
+ beforeClose: async () => {
2975
+ log10("before space close", {
2976
+ space: space.key
2977
+ }, {
2978
+ F: __dxlog_file10,
2979
+ L: 245,
2980
+ S: this,
2981
+ C: (f, a) => f(...a)
2982
+ });
2983
+ await this._dataServiceSubscriptions.unregisterSpace(space.key);
2922
2984
  }
2923
2985
  },
2924
2986
  cache: metadata.cache
2925
2987
  });
2926
- await dataSpace.open();
2988
+ if (metadata.state !== SpaceState2.INACTIVE) {
2989
+ await dataSpace.open();
2990
+ }
2927
2991
  if (metadata.controlTimeframe) {
2928
2992
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
2929
2993
  }
@@ -2935,16 +2999,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2935
2999
  }
2936
3000
  };
2937
3001
  _ts_decorate2([
2938
- synchronized
3002
+ synchronized2
2939
3003
  ], DataSpaceManager.prototype, "open", null);
2940
3004
  _ts_decorate2([
2941
- synchronized
3005
+ synchronized2
2942
3006
  ], DataSpaceManager.prototype, "close", null);
2943
3007
  _ts_decorate2([
2944
- synchronized
3008
+ synchronized2
2945
3009
  ], DataSpaceManager.prototype, "createSpace", null);
2946
3010
  _ts_decorate2([
2947
- synchronized
3011
+ synchronized2
2948
3012
  ], DataSpaceManager.prototype, "acceptSpace", null);
2949
3013
  DataSpaceManager = _ts_decorate2([
2950
3014
  trackLeaks2("open", "close")
@@ -2953,11 +3017,12 @@ DataSpaceManager = _ts_decorate2([
2953
3017
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2954
3018
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
2955
3019
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
2956
- import { raise, todo as todo2 } from "@dxos/debug";
3020
+ import { raise } from "@dxos/debug";
2957
3021
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3022
+ import { ApiError } from "@dxos/errors";
2958
3023
  import { log as log11 } from "@dxos/log";
2959
3024
  import { encodeError } from "@dxos/protocols";
2960
- import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
3025
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
2961
3026
  import { humanize } from "@dxos/util";
2962
3027
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
2963
3028
  var SpacesServiceImpl = class {
@@ -2975,8 +3040,22 @@ var SpacesServiceImpl = class {
2975
3040
  const space = await dataSpaceManager.createSpace();
2976
3041
  return this._serializeSpace(space);
2977
3042
  }
2978
- async updateSpace(request) {
2979
- todo2();
3043
+ async updateSpace({ spaceKey, state }) {
3044
+ var _a;
3045
+ const dataSpaceManager = await this._getDataSpaceManager();
3046
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3047
+ if (state) {
3048
+ switch (state) {
3049
+ case SpaceState3.ACTIVE:
3050
+ await space.activate();
3051
+ break;
3052
+ case SpaceState3.INACTIVE:
3053
+ await space.deactivate();
3054
+ break;
3055
+ default:
3056
+ throw new ApiError("Invalid space state");
3057
+ }
3058
+ }
2980
3059
  }
2981
3060
  querySpaces() {
2982
3061
  return new Stream9(({ next, ctx }) => {
@@ -2987,7 +3066,7 @@ var SpacesServiceImpl = class {
2987
3066
  spaces
2988
3067
  }, {
2989
3068
  F: __dxlog_file11,
2990
- L: 60,
3069
+ L: 78,
2991
3070
  S: this,
2992
3071
  C: (f, a) => f(...a)
2993
3072
  });
@@ -3050,13 +3129,13 @@ var SpacesServiceImpl = class {
3050
3129
  return new Stream9(({ ctx, next }) => {
3051
3130
  var _a;
3052
3131
  const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3053
- const processor = space.spaceState.registerProcessor({
3054
- process: async (credential) => {
3132
+ const processor = {
3133
+ processCredential: async (credential) => {
3055
3134
  next(credential);
3056
3135
  }
3057
- });
3058
- ctx.onDispose(() => processor.close());
3059
- scheduleTask5(ctx, () => processor.open());
3136
+ };
3137
+ ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
3138
+ scheduleTask5(ctx, () => space.spaceState.addCredentialProcessor(processor));
3060
3139
  });
3061
3140
  }
3062
3141
  async writeCredentials({ spaceKey, credentials }) {
@@ -3207,15 +3286,17 @@ var ServiceContext = class {
3207
3286
  });
3208
3287
  }
3209
3288
  async close() {
3210
- var _a, _b;
3289
+ var _a;
3211
3290
  log12("closing...", void 0, {
3212
3291
  F: __dxlog_file12,
3213
3292
  L: 143,
3214
3293
  S: this,
3215
3294
  C: (f, a) => f(...a)
3216
3295
  });
3217
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3218
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3296
+ if (this._deviceSpaceSync && this.identityManager.identity) {
3297
+ await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3298
+ }
3299
+ await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3219
3300
  await this.identityManager.close();
3220
3301
  await this.spaceManager.close();
3221
3302
  await this.feedStore.close();
@@ -3224,7 +3305,7 @@ var ServiceContext = class {
3224
3305
  this.dataServiceSubscriptions.clear();
3225
3306
  log12("closed", void 0, {
3226
3307
  F: __dxlog_file12,
3227
- L: 152,
3308
+ L: 154,
3228
3309
  S: this,
3229
3310
  C: (f, a) => f(...a)
3230
3311
  });
@@ -3255,7 +3336,7 @@ var ServiceContext = class {
3255
3336
  var _a;
3256
3337
  log12("initializing spaces...", void 0, {
3257
3338
  F: __dxlog_file12,
3258
- L: 185,
3339
+ L: 187,
3259
3340
  S: this,
3260
3341
  C: (f, a) => f(...a)
3261
3342
  });
@@ -3280,8 +3361,8 @@ var ServiceContext = class {
3280
3361
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3281
3362
  });
3282
3363
  this.initialized.wake();
3283
- this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3284
- process: async (credential) => {
3364
+ this._deviceSpaceSync = {
3365
+ processCredential: async (credential) => {
3285
3366
  const assertion = getCredentialAssertion3(credential);
3286
3367
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3287
3368
  return;
@@ -3294,7 +3375,7 @@ var ServiceContext = class {
3294
3375
  details: assertion
3295
3376
  }, {
3296
3377
  F: __dxlog_file12,
3297
- L: 224,
3378
+ L: 226,
3298
3379
  S: this,
3299
3380
  C: (f, a) => f(...a)
3300
3381
  });
@@ -3305,7 +3386,7 @@ var ServiceContext = class {
3305
3386
  details: assertion
3306
3387
  }, {
3307
3388
  F: __dxlog_file12,
3308
- L: 228,
3389
+ L: 230,
3309
3390
  S: this,
3310
3391
  C: (f, a) => f(...a)
3311
3392
  });
@@ -3316,7 +3397,7 @@ var ServiceContext = class {
3316
3397
  details: assertion
3317
3398
  }, {
3318
3399
  F: __dxlog_file12,
3319
- L: 233,
3400
+ L: 235,
3320
3401
  S: this,
3321
3402
  C: (f, a) => f(...a)
3322
3403
  });
@@ -3327,14 +3408,14 @@ var ServiceContext = class {
3327
3408
  } catch (err) {
3328
3409
  log12.catch(err, void 0, {
3329
3410
  F: __dxlog_file12,
3330
- L: 239,
3411
+ L: 241,
3331
3412
  S: this,
3332
3413
  C: (f, a) => f(...a)
3333
3414
  });
3334
3415
  }
3335
3416
  }
3336
- });
3337
- await this._deviceSpaceSync.open();
3417
+ };
3418
+ await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3338
3419
  }
3339
3420
  };
3340
3421
 
@@ -3539,7 +3620,7 @@ var ServiceRegistry = class {
3539
3620
 
3540
3621
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3541
3622
  import invariant12 from "tiny-invariant";
3542
- import { Event as Event8, synchronized as synchronized2 } from "@dxos/async";
3623
+ import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
3543
3624
  import { clientServiceBundle } from "@dxos/client-protocol";
3544
3625
  import { DocumentModel } from "@dxos/document-model";
3545
3626
  import { DataServiceImpl } from "@dxos/echo-pipeline";
@@ -3770,13 +3851,15 @@ var ClientServicesHost = class {
3770
3851
  connectionLog,
3771
3852
  storage,
3772
3853
  // TODO(wittjosiah): Turn this on by default.
3773
- lockKey
3854
+ lockKey,
3855
+ callbacks
3774
3856
  } = {}) {
3775
3857
  this._statusUpdate = new Event8();
3776
3858
  this._opening = false;
3777
3859
  this._open = false;
3778
3860
  this._storage = storage;
3779
3861
  this._modelFactory = modelFactory;
3862
+ this._callbacks = callbacks;
3780
3863
  if (config) {
3781
3864
  this.initialize({
3782
3865
  config,
@@ -3864,7 +3947,7 @@ var ClientServicesHost = class {
3864
3947
  id: traceId
3865
3948
  }), {
3866
3949
  F: __dxlog_file14,
3867
- L: 195,
3950
+ L: 203,
3868
3951
  S: this,
3869
3952
  C: (f, a) => f(...a)
3870
3953
  });
@@ -3877,7 +3960,7 @@ var ClientServicesHost = class {
3877
3960
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3878
3961
  }, {
3879
3962
  F: __dxlog_file14,
3880
- L: 203,
3963
+ L: 211,
3881
3964
  S: this,
3882
3965
  C: (f, a) => f(...a)
3883
3966
  });
@@ -3912,7 +3995,7 @@ var ClientServicesHost = class {
3912
3995
  deviceKey
3913
3996
  }, {
3914
3997
  F: __dxlog_file14,
3915
- L: 258,
3998
+ L: 266,
3916
3999
  S: this,
3917
4000
  C: (f, a) => f(...a)
3918
4001
  });
@@ -3920,7 +4003,7 @@ var ClientServicesHost = class {
3920
4003
  id: traceId
3921
4004
  }), {
3922
4005
  F: __dxlog_file14,
3923
- L: 259,
4006
+ L: 267,
3924
4007
  S: this,
3925
4008
  C: (f, a) => f(...a)
3926
4009
  });
@@ -3935,7 +4018,7 @@ var ClientServicesHost = class {
3935
4018
  deviceKey
3936
4019
  }, {
3937
4020
  F: __dxlog_file14,
3938
- L: 269,
4021
+ L: 277,
3939
4022
  S: this,
3940
4023
  C: (f, a) => f(...a)
3941
4024
  });
@@ -3950,25 +4033,25 @@ var ClientServicesHost = class {
3950
4033
  deviceKey
3951
4034
  }, {
3952
4035
  F: __dxlog_file14,
3953
- L: 275,
4036
+ L: 283,
3954
4037
  S: this,
3955
4038
  C: (f, a) => f(...a)
3956
4039
  });
3957
4040
  }
3958
4041
  async reset() {
3959
- var _a;
4042
+ var _a, _b, _c;
3960
4043
  const traceId = PublicKey10.random().toHex();
3961
4044
  log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
3962
4045
  id: traceId
3963
4046
  }), {
3964
4047
  F: __dxlog_file14,
3965
- L: 280,
4048
+ L: 288,
3966
4049
  S: this,
3967
4050
  C: (f, a) => f(...a)
3968
4051
  });
3969
4052
  log15("resetting...", void 0, {
3970
4053
  F: __dxlog_file14,
3971
- L: 282,
4054
+ L: 290,
3972
4055
  S: this,
3973
4056
  C: (f, a) => f(...a)
3974
4057
  });
@@ -3976,7 +4059,7 @@ var ClientServicesHost = class {
3976
4059
  await this._storage.reset();
3977
4060
  log15("reset", void 0, {
3978
4061
  F: __dxlog_file14,
3979
- L: 285,
4062
+ L: 293,
3980
4063
  S: this,
3981
4064
  C: (f, a) => f(...a)
3982
4065
  });
@@ -3984,17 +4067,18 @@ var ClientServicesHost = class {
3984
4067
  id: traceId
3985
4068
  }), {
3986
4069
  F: __dxlog_file14,
3987
- L: 286,
4070
+ L: 294,
3988
4071
  S: this,
3989
4072
  C: (f, a) => f(...a)
3990
4073
  });
4074
+ await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
3991
4075
  }
3992
4076
  };
3993
4077
  _ts_decorate4([
3994
- synchronized2
4078
+ synchronized3
3995
4079
  ], ClientServicesHost.prototype, "open", null);
3996
4080
  _ts_decorate4([
3997
- synchronized2
4081
+ synchronized3
3998
4082
  ], ClientServicesHost.prototype, "close", null);
3999
4083
 
4000
4084
  export {
@@ -4028,4 +4112,4 @@ export {
4028
4112
  createDefaultModelFactory,
4029
4113
  ClientServicesHost
4030
4114
  };
4031
- //# sourceMappingURL=chunk-RKD47ENR.mjs.map
4115
+ //# sourceMappingURL=chunk-3EI4PM2V.mjs.map