@dxos/client-services 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 (33) hide show
  1. package/dist/lib/browser/{chunk-PWZ2J6KS.mjs → chunk-EYXOVYW5.mjs} +170 -90
  2. package/dist/lib/browser/chunk-EYXOVYW5.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/packlets/testing/index.mjs +19 -2
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +165 -85
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +179 -83
  11. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  12. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  13. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  14. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/spaces/data-space.d.ts +11 -2
  16. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +2 -1
  18. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  20. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -1
  22. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  23. package/package.json +32 -32
  24. package/src/packlets/identity/identity.ts +21 -26
  25. package/src/packlets/services/service-context.ts +9 -7
  26. package/src/packlets/spaces/data-space-manager.test.ts +72 -118
  27. package/src/packlets/spaces/data-space-manager.ts +13 -3
  28. package/src/packlets/spaces/data-space.ts +66 -20
  29. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  30. package/src/packlets/spaces/notarization-plugin.ts +5 -1
  31. package/src/packlets/spaces/spaces-service.ts +26 -8
  32. package/src/packlets/testing/test-builder.ts +35 -2
  33. package/dist/lib/browser/chunk-PWZ2J6KS.mjs.map +0 -7
@@ -478,15 +478,15 @@ var Identity = class {
478
478
  this._signer = signer;
479
479
  this.identityKey = identityKey;
480
480
  this.deviceKey = deviceKey;
481
- this._deviceStateMachine = this.space.spaceState.registerProcessor(new DeviceStateMachine({
481
+ this._deviceStateMachine = new DeviceStateMachine({
482
482
  identityKey: this.identityKey,
483
483
  deviceKey: this.deviceKey,
484
484
  onUpdate: () => this.stateUpdate.emit()
485
- }));
486
- this._profileStateMachine = this.space.spaceState.registerProcessor(new ProfileStateMachine({
485
+ });
486
+ this._profileStateMachine = new ProfileStateMachine({
487
487
  identityKey: this.identityKey,
488
488
  onUpdate: () => this.stateUpdate.emit()
489
- }));
489
+ });
490
490
  this.authVerifier = new TrustedKeySetAuthVerifier({
491
491
  trustedKeysProvider: () => this.authorizedDeviceKeys,
492
492
  update: this.stateUpdate,
@@ -495,27 +495,27 @@ var Identity = class {
495
495
  }
496
496
  // TODO(burdon): Expose state object?
497
497
  get authorizedDeviceKeys() {
498
- return this._deviceStateMachine.processor.authorizedDeviceKeys;
498
+ return this._deviceStateMachine.authorizedDeviceKeys;
499
499
  }
500
500
  async open() {
501
- await this._deviceStateMachine.open();
502
- await this._profileStateMachine.open();
501
+ await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
502
+ await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
503
503
  await this.space.open();
504
504
  }
505
505
  async close() {
506
506
  await this.authVerifier.close();
507
- await this._deviceStateMachine.close();
508
- await this._profileStateMachine.close();
507
+ await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
508
+ await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
509
509
  await this.space.close();
510
510
  }
511
511
  async ready() {
512
- await this._deviceStateMachine.processor.deviceChainReady.wait();
512
+ await this._deviceStateMachine.deviceChainReady.wait();
513
513
  await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
514
514
  timeout: LOAD_CONTROL_FEEDS_TIMEOUT
515
515
  });
516
516
  }
517
517
  get profileDocument() {
518
- return this._profileStateMachine.processor.profile;
518
+ return this._profileStateMachine.profile;
519
519
  }
520
520
  /**
521
521
  * @test-only
@@ -530,7 +530,7 @@ var Identity = class {
530
530
  return this.space.genesisFeedKey;
531
531
  }
532
532
  get deviceCredentialChain() {
533
- return this._deviceStateMachine.processor.deviceCredentialChain;
533
+ return this._deviceStateMachine.deviceCredentialChain;
534
534
  }
535
535
  getAdmissionCredentials() {
536
536
  var _a, _b;
@@ -545,8 +545,8 @@ var Identity = class {
545
545
  * Requires identity to be ready.
546
546
  */
547
547
  getIdentityCredentialSigner() {
548
- invariant(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
549
- return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
548
+ invariant(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
549
+ return createCredentialSignerWithChain(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
550
550
  }
551
551
  /**
552
552
  * Issues credentials as device.
@@ -563,7 +563,7 @@ var Identity = class {
563
563
  dataFeedKey
564
564
  }, {
565
565
  F: __dxlog_file2,
566
- L: 156,
566
+ L: 151,
567
567
  S: this,
568
568
  C: (f, a) => f(...a)
569
569
  });
@@ -2082,7 +2082,7 @@ var SpaceInvitationProtocol = class {
2082
2082
  };
2083
2083
 
2084
2084
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2085
- import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2085
+ import { Event as Event5, scheduleTask as scheduleTask4, synchronized, trackLeaks } from "@dxos/async";
2086
2086
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2087
2087
  import { cancelWithContext as cancelWithContext2, Context as Context6 } from "@dxos/context";
2088
2088
  import { timed } from "@dxos/debug";
@@ -2117,6 +2117,9 @@ var NotarizationPlugin = class {
2117
2117
  this._processedCredentials = new ComplexSet(PublicKey6.hash);
2118
2118
  this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
2119
2119
  }
2120
+ get hasWriter() {
2121
+ return !!this._writer;
2122
+ }
2120
2123
  async open() {
2121
2124
  }
2122
2125
  async close() {
@@ -2130,7 +2133,7 @@ var NotarizationPlugin = class {
2130
2133
  credentials
2131
2134
  }, {
2132
2135
  F: __dxlog_file8,
2133
- L: 87,
2136
+ L: 91,
2134
2137
  S: this,
2135
2138
  C: (f, a) => f(...a)
2136
2139
  });
@@ -2142,7 +2145,7 @@ var NotarizationPlugin = class {
2142
2145
  err
2143
2146
  }, {
2144
2147
  F: __dxlog_file8,
2145
- L: 96,
2148
+ L: 100,
2146
2149
  S: this,
2147
2150
  C: (f, a) => f(...a)
2148
2151
  });
@@ -2158,7 +2161,7 @@ var NotarizationPlugin = class {
2158
2161
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2159
2162
  }, {
2160
2163
  F: __dxlog_file8,
2161
- L: 108,
2164
+ L: 112,
2162
2165
  S: this,
2163
2166
  C: (f, a) => f(...a)
2164
2167
  });
@@ -2181,7 +2184,7 @@ var NotarizationPlugin = class {
2181
2184
  retryIn: retryTimeout
2182
2185
  }, {
2183
2186
  F: __dxlog_file8,
2184
- L: 133,
2187
+ L: 137,
2185
2188
  S: this,
2186
2189
  C: (f, a) => f(...a)
2187
2190
  });
@@ -2195,7 +2198,7 @@ var NotarizationPlugin = class {
2195
2198
  credentialId: credentials.map((credential) => credential.id)
2196
2199
  }, {
2197
2200
  F: __dxlog_file8,
2198
- L: 140,
2201
+ L: 144,
2199
2202
  S: this,
2200
2203
  C: (f, a) => f(...a)
2201
2204
  });
@@ -2204,7 +2207,7 @@ var NotarizationPlugin = class {
2204
2207
  });
2205
2208
  log8("success", void 0, {
2206
2209
  F: __dxlog_file8,
2207
- L: 144,
2210
+ L: 148,
2208
2211
  S: this,
2209
2212
  C: (f, a) => f(...a)
2210
2213
  });
@@ -2213,7 +2216,7 @@ var NotarizationPlugin = class {
2213
2216
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2214
2217
  log8.warn("error notarizing (recoverable)", err, {
2215
2218
  F: __dxlog_file8,
2216
- L: 148,
2219
+ L: 152,
2217
2220
  S: this,
2218
2221
  C: (f, a) => f(...a)
2219
2222
  });
@@ -2231,7 +2234,7 @@ var NotarizationPlugin = class {
2231
2234
  ]);
2232
2235
  log8("done", void 0, {
2233
2236
  F: __dxlog_file8,
2234
- L: 159,
2237
+ L: 163,
2235
2238
  S: this,
2236
2239
  C: (f, a) => f(...a)
2237
2240
  });
@@ -2242,7 +2245,7 @@ var NotarizationPlugin = class {
2242
2245
  /**
2243
2246
  * Called with credentials arriving from the control pipeline.
2244
2247
  */
2245
- async process(credential) {
2248
+ async processCredential(credential) {
2246
2249
  var _a;
2247
2250
  if (!credential.id) {
2248
2251
  return;
@@ -2284,7 +2287,7 @@ var NotarizationPlugin = class {
2284
2287
  peer: extension.localPeerId
2285
2288
  }, {
2286
2289
  F: __dxlog_file8,
2287
- L: 208,
2290
+ L: 212,
2288
2291
  S: this,
2289
2292
  C: (f, a) => f(...a)
2290
2293
  });
@@ -2296,7 +2299,7 @@ var NotarizationPlugin = class {
2296
2299
  peer: extension.localPeerId
2297
2300
  }, {
2298
2301
  F: __dxlog_file8,
2299
- L: 213,
2302
+ L: 217,
2300
2303
  S: this,
2301
2304
  C: (f, a) => f(...a)
2302
2305
  });
@@ -2353,6 +2356,7 @@ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/sr
2353
2356
  var DataSpace = class DataSpace2 {
2354
2357
  constructor(params) {
2355
2358
  this._ctx = new Context6();
2359
+ this._notarizationPlugin = new NotarizationPlugin();
2356
2360
  this._state = SpaceState.CLOSED;
2357
2361
  /**
2358
2362
  * Error for _state === SpaceState.ERROR.
@@ -2375,8 +2379,8 @@ var DataSpace = class DataSpace2 {
2375
2379
  update: this._inner.stateUpdate,
2376
2380
  authTimeout: AUTH_TIMEOUT2
2377
2381
  });
2378
- this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2379
2382
  this._cache = params.cache;
2383
+ this._state = params.initialState;
2380
2384
  }
2381
2385
  get key() {
2382
2386
  return this._inner.key;
@@ -2398,25 +2402,36 @@ var DataSpace = class DataSpace2 {
2398
2402
  return this._presence;
2399
2403
  }
2400
2404
  get notarizationPlugin() {
2401
- return this._notarizationPluginConsumer.processor;
2405
+ return this._notarizationPlugin;
2402
2406
  }
2403
2407
  get cache() {
2404
2408
  return this._cache;
2405
2409
  }
2406
2410
  async open() {
2407
- await this.notarizationPlugin.open();
2408
- await this._notarizationPluginConsumer.open();
2411
+ await this._open();
2412
+ }
2413
+ async _open() {
2414
+ await this._notarizationPlugin.open();
2415
+ await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2409
2416
  await this._inner.open();
2410
- this._state = SpaceState.INACTIVE;
2417
+ this._state = SpaceState.CONTROL_ONLY;
2418
+ this.stateUpdate.emit();
2419
+ this.metrics = {};
2411
2420
  this.metrics.open = new Date();
2412
2421
  }
2413
2422
  async close() {
2423
+ await this._close();
2424
+ }
2425
+ async _close() {
2426
+ var _a, _b;
2427
+ await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2414
2428
  this._state = SpaceState.CLOSED;
2415
2429
  await this._ctx.dispose();
2430
+ this._ctx = new Context6();
2416
2431
  await this.authVerifier.close();
2417
2432
  await this._inner.close();
2418
- await this._notarizationPluginConsumer.close();
2419
- await this.notarizationPlugin.close();
2433
+ await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
2434
+ await this._notarizationPlugin.close();
2420
2435
  await this._presence.destroy();
2421
2436
  }
2422
2437
  async postMessage(channel, message) {
@@ -2437,7 +2452,7 @@ var DataSpace = class DataSpace2 {
2437
2452
  if (err instanceof CancelledError) {
2438
2453
  log9("Data pipeline initialization cancelled", err, {
2439
2454
  F: __dxlog_file9,
2440
- L: 173,
2455
+ L: 193,
2441
2456
  S: this,
2442
2457
  C: (f, a) => f(...a)
2443
2458
  });
@@ -2445,7 +2460,7 @@ var DataSpace = class DataSpace2 {
2445
2460
  }
2446
2461
  log9.error("Error initializing data pipeline", err, {
2447
2462
  F: __dxlog_file9,
2448
- L: 177,
2463
+ L: 197,
2449
2464
  S: this,
2450
2465
  C: (f, a) => f(...a)
2451
2466
  });
@@ -2459,7 +2474,7 @@ var DataSpace = class DataSpace2 {
2459
2474
  }
2460
2475
  async initializeDataPipeline() {
2461
2476
  var _a, _b, _c, _d;
2462
- if (this._state !== SpaceState.INACTIVE) {
2477
+ if (this._state !== SpaceState.CONTROL_ONLY) {
2463
2478
  throw new SystemError("Invalid operation");
2464
2479
  }
2465
2480
  this._state = SpaceState.INITIALIZING;
@@ -2471,22 +2486,24 @@ var DataSpace = class DataSpace2 {
2471
2486
  await this._createWritableFeeds();
2472
2487
  log9("Writable feeds created", void 0, {
2473
2488
  F: __dxlog_file9,
2474
- L: 201,
2489
+ L: 221,
2475
2490
  S: this,
2476
2491
  C: (f, a) => f(...a)
2477
2492
  });
2478
2493
  this.stateUpdate.emit();
2479
- this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2480
- credential: {
2481
- credential
2482
- }
2483
- }), this._inner.controlPipeline.writer));
2494
+ if (!this.notarizationPlugin.hasWriter) {
2495
+ this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2496
+ credential: {
2497
+ credential
2498
+ }
2499
+ }), this._inner.controlPipeline.writer));
2500
+ }
2484
2501
  await this._inner.initializeDataPipeline();
2485
2502
  this.metrics.dataPipelineOpen = new Date();
2486
2503
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2487
2504
  log9("waiting for data pipeline to reach target timeframe", void 0, {
2488
2505
  F: __dxlog_file9,
2489
- L: 220,
2506
+ L: 242,
2490
2507
  S: this,
2491
2508
  C: (f, a) => f(...a)
2492
2509
  });
@@ -2497,7 +2514,7 @@ var DataSpace = class DataSpace2 {
2497
2514
  this.metrics.dataPipelineReady = new Date();
2498
2515
  log9("data pipeline ready", void 0, {
2499
2516
  F: __dxlog_file9,
2500
- L: 229,
2517
+ L: 251,
2501
2518
  S: this,
2502
2519
  C: (f, a) => f(...a)
2503
2520
  });
@@ -2577,17 +2594,46 @@ var DataSpace = class DataSpace2 {
2577
2594
  }
2578
2595
  }
2579
2596
  }
2597
+ async activate() {
2598
+ if (this._state !== SpaceState.INACTIVE) {
2599
+ throw new SystemError("Invalid operation");
2600
+ }
2601
+ await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
2602
+ await this._open();
2603
+ this.initializeDataPipelineAsync();
2604
+ }
2605
+ async deactivate() {
2606
+ if (this._state === SpaceState.INACTIVE) {
2607
+ throw new SystemError("Invalid operation");
2608
+ }
2609
+ await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
2610
+ await this._close();
2611
+ this._state = SpaceState.INACTIVE;
2612
+ this.stateUpdate.emit();
2613
+ }
2580
2614
  };
2615
+ _ts_decorate([
2616
+ synchronized
2617
+ ], DataSpace.prototype, "open", null);
2618
+ _ts_decorate([
2619
+ synchronized
2620
+ ], DataSpace.prototype, "close", null);
2581
2621
  _ts_decorate([
2582
2622
  timed(1e4)
2583
2623
  ], DataSpace.prototype, "_createWritableFeeds", null);
2624
+ _ts_decorate([
2625
+ synchronized
2626
+ ], DataSpace.prototype, "activate", null);
2627
+ _ts_decorate([
2628
+ synchronized
2629
+ ], DataSpace.prototype, "deactivate", null);
2584
2630
  DataSpace = _ts_decorate([
2585
2631
  trackLeaks("open", "close")
2586
2632
  ], DataSpace);
2587
2633
 
2588
2634
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2589
2635
  import invariant10 from "tiny-invariant";
2590
- import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2636
+ import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
2591
2637
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2592
2638
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2593
2639
  import { PublicKey as PublicKey8 } from "@dxos/keys";
@@ -2732,14 +2778,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2732
2778
  C: (f, a) => f(...a)
2733
2779
  });
2734
2780
  const space = await this._constructSpace(spaceMetadata);
2735
- space.initializeDataPipelineAsync();
2781
+ if (spaceMetadata.state !== SpaceState2.INACTIVE) {
2782
+ space.initializeDataPipelineAsync();
2783
+ }
2736
2784
  } catch (err) {
2737
2785
  log10.error("Error loading space", {
2738
2786
  spaceMetadata,
2739
2787
  err
2740
2788
  }, {
2741
2789
  F: __dxlog_file10,
2742
- L: 91,
2790
+ L: 93,
2743
2791
  S: this,
2744
2792
  C: (f, a) => f(...a)
2745
2793
  });
@@ -2751,7 +2799,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2751
2799
  id: this._instanceId
2752
2800
  }), {
2753
2801
  F: __dxlog_file10,
2754
- L: 97,
2802
+ L: 99,
2755
2803
  S: this,
2756
2804
  C: (f, a) => f(...a)
2757
2805
  });
@@ -2759,7 +2807,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2759
2807
  async close() {
2760
2808
  log10("close", void 0, {
2761
2809
  F: __dxlog_file10,
2762
- L: 102,
2810
+ L: 104,
2763
2811
  S: this,
2764
2812
  C: (f, a) => f(...a)
2765
2813
  });
@@ -2781,13 +2829,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2781
2829
  key: spaceKey,
2782
2830
  genesisFeedKey: controlFeedKey,
2783
2831
  controlFeedKey,
2784
- dataFeedKey
2832
+ dataFeedKey,
2833
+ state: SpaceState2.ACTIVE
2785
2834
  };
2786
2835
  log10("creating space...", {
2787
2836
  spaceKey
2788
2837
  }, {
2789
2838
  F: __dxlog_file10,
2790
- L: 126,
2839
+ L: 129,
2791
2840
  S: this,
2792
2841
  C: (f, a) => f(...a)
2793
2842
  });
@@ -2807,7 +2856,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2807
2856
  opts
2808
2857
  }, {
2809
2858
  F: __dxlog_file10,
2810
- L: 145,
2859
+ L: 148,
2811
2860
  S: this,
2812
2861
  C: (f, a) => f(...a)
2813
2862
  });
@@ -2841,7 +2890,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2841
2890
  metadata
2842
2891
  }, {
2843
2892
  F: __dxlog_file10,
2844
- L: 180,
2893
+ L: 183,
2845
2894
  S: this,
2846
2895
  C: (f, a) => f(...a)
2847
2896
  });
@@ -2877,7 +2926,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2877
2926
  onAuthFailure: () => {
2878
2927
  log10.warn("auth failure", void 0, {
2879
2928
  F: __dxlog_file10,
2880
- L: 211,
2929
+ L: 214,
2881
2930
  S: this,
2882
2931
  C: (f, a) => f(...a)
2883
2932
  });
@@ -2888,6 +2937,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2888
2937
  dataFeed && space.setDataFeed(dataFeed);
2889
2938
  const dataSpace = new DataSpace({
2890
2939
  inner: space,
2940
+ initialState: metadata.state === SpaceState2.INACTIVE ? SpaceState2.INACTIVE : SpaceState2.CLOSED,
2891
2941
  metadataStore: this._metadataStore,
2892
2942
  gossip,
2893
2943
  presence,
@@ -2900,11 +2950,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2900
2950
  space: space.key
2901
2951
  }, {
2902
2952
  F: __dxlog_file10,
2903
- L: 228,
2953
+ L: 232,
2904
2954
  S: this,
2905
2955
  C: (f, a) => f(...a)
2906
2956
  });
2907
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2957
+ await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2908
2958
  },
2909
2959
  afterReady: async () => {
2910
2960
  log10("after space ready", {
@@ -2912,18 +2962,31 @@ var DataSpaceManager = class DataSpaceManager2 {
2912
2962
  open: this._isOpen
2913
2963
  }, {
2914
2964
  F: __dxlog_file10,
2915
- L: 235,
2965
+ L: 239,
2916
2966
  S: this,
2917
2967
  C: (f, a) => f(...a)
2918
2968
  });
2919
2969
  if (this._isOpen) {
2920
2970
  this.updated.emit();
2921
2971
  }
2972
+ },
2973
+ beforeClose: async () => {
2974
+ log10("before space close", {
2975
+ space: space.key
2976
+ }, {
2977
+ F: __dxlog_file10,
2978
+ L: 245,
2979
+ S: this,
2980
+ C: (f, a) => f(...a)
2981
+ });
2982
+ await this._dataServiceSubscriptions.unregisterSpace(space.key);
2922
2983
  }
2923
2984
  },
2924
2985
  cache: metadata.cache
2925
2986
  });
2926
- await dataSpace.open();
2987
+ if (metadata.state !== SpaceState2.INACTIVE) {
2988
+ await dataSpace.open();
2989
+ }
2927
2990
  if (metadata.controlTimeframe) {
2928
2991
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
2929
2992
  }
@@ -2935,16 +2998,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2935
2998
  }
2936
2999
  };
2937
3000
  _ts_decorate2([
2938
- synchronized
3001
+ synchronized2
2939
3002
  ], DataSpaceManager.prototype, "open", null);
2940
3003
  _ts_decorate2([
2941
- synchronized
3004
+ synchronized2
2942
3005
  ], DataSpaceManager.prototype, "close", null);
2943
3006
  _ts_decorate2([
2944
- synchronized
3007
+ synchronized2
2945
3008
  ], DataSpaceManager.prototype, "createSpace", null);
2946
3009
  _ts_decorate2([
2947
- synchronized
3010
+ synchronized2
2948
3011
  ], DataSpaceManager.prototype, "acceptSpace", null);
2949
3012
  DataSpaceManager = _ts_decorate2([
2950
3013
  trackLeaks2("open", "close")
@@ -2953,11 +3016,12 @@ DataSpaceManager = _ts_decorate2([
2953
3016
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2954
3017
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
2955
3018
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
2956
- import { raise, todo as todo2 } from "@dxos/debug";
3019
+ import { raise } from "@dxos/debug";
2957
3020
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3021
+ import { ApiError } from "@dxos/errors";
2958
3022
  import { log as log11 } from "@dxos/log";
2959
3023
  import { encodeError } from "@dxos/protocols";
2960
- import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
3024
+ import { SpaceMember as SpaceMember2, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
2961
3025
  import { humanize } from "@dxos/util";
2962
3026
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
2963
3027
  var SpacesServiceImpl = class {
@@ -2975,8 +3039,22 @@ var SpacesServiceImpl = class {
2975
3039
  const space = await dataSpaceManager.createSpace();
2976
3040
  return this._serializeSpace(space);
2977
3041
  }
2978
- async updateSpace(request) {
2979
- todo2();
3042
+ async updateSpace({ spaceKey, state }) {
3043
+ var _a;
3044
+ const dataSpaceManager = await this._getDataSpaceManager();
3045
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3046
+ if (state) {
3047
+ switch (state) {
3048
+ case SpaceState3.ACTIVE:
3049
+ await space.activate();
3050
+ break;
3051
+ case SpaceState3.INACTIVE:
3052
+ await space.deactivate();
3053
+ break;
3054
+ default:
3055
+ throw new ApiError("Invalid space state");
3056
+ }
3057
+ }
2980
3058
  }
2981
3059
  querySpaces() {
2982
3060
  return new Stream9(({ next, ctx }) => {
@@ -2987,7 +3065,7 @@ var SpacesServiceImpl = class {
2987
3065
  spaces
2988
3066
  }, {
2989
3067
  F: __dxlog_file11,
2990
- L: 60,
3068
+ L: 78,
2991
3069
  S: this,
2992
3070
  C: (f, a) => f(...a)
2993
3071
  });
@@ -3050,13 +3128,13 @@ var SpacesServiceImpl = class {
3050
3128
  return new Stream9(({ ctx, next }) => {
3051
3129
  var _a;
3052
3130
  const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
3053
- const processor = space.spaceState.registerProcessor({
3054
- process: async (credential) => {
3131
+ const processor = {
3132
+ processCredential: async (credential) => {
3055
3133
  next(credential);
3056
3134
  }
3057
- });
3058
- ctx.onDispose(() => processor.close());
3059
- scheduleTask5(ctx, () => processor.open());
3135
+ };
3136
+ ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
3137
+ scheduleTask5(ctx, () => space.spaceState.addCredentialProcessor(processor));
3060
3138
  });
3061
3139
  }
3062
3140
  async writeCredentials({ spaceKey, credentials }) {
@@ -3207,15 +3285,17 @@ var ServiceContext = class {
3207
3285
  });
3208
3286
  }
3209
3287
  async close() {
3210
- var _a, _b;
3288
+ var _a;
3211
3289
  log12("closing...", void 0, {
3212
3290
  F: __dxlog_file12,
3213
3291
  L: 143,
3214
3292
  S: this,
3215
3293
  C: (f, a) => f(...a)
3216
3294
  });
3217
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3218
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3295
+ if (this._deviceSpaceSync && this.identityManager.identity) {
3296
+ await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3297
+ }
3298
+ await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3219
3299
  await this.identityManager.close();
3220
3300
  await this.spaceManager.close();
3221
3301
  await this.feedStore.close();
@@ -3224,7 +3304,7 @@ var ServiceContext = class {
3224
3304
  this.dataServiceSubscriptions.clear();
3225
3305
  log12("closed", void 0, {
3226
3306
  F: __dxlog_file12,
3227
- L: 152,
3307
+ L: 154,
3228
3308
  S: this,
3229
3309
  C: (f, a) => f(...a)
3230
3310
  });
@@ -3255,7 +3335,7 @@ var ServiceContext = class {
3255
3335
  var _a;
3256
3336
  log12("initializing spaces...", void 0, {
3257
3337
  F: __dxlog_file12,
3258
- L: 185,
3338
+ L: 187,
3259
3339
  S: this,
3260
3340
  C: (f, a) => f(...a)
3261
3341
  });
@@ -3280,8 +3360,8 @@ var ServiceContext = class {
3280
3360
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3281
3361
  });
3282
3362
  this.initialized.wake();
3283
- this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3284
- process: async (credential) => {
3363
+ this._deviceSpaceSync = {
3364
+ processCredential: async (credential) => {
3285
3365
  const assertion = getCredentialAssertion3(credential);
3286
3366
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3287
3367
  return;
@@ -3294,7 +3374,7 @@ var ServiceContext = class {
3294
3374
  details: assertion
3295
3375
  }, {
3296
3376
  F: __dxlog_file12,
3297
- L: 224,
3377
+ L: 226,
3298
3378
  S: this,
3299
3379
  C: (f, a) => f(...a)
3300
3380
  });
@@ -3305,7 +3385,7 @@ var ServiceContext = class {
3305
3385
  details: assertion
3306
3386
  }, {
3307
3387
  F: __dxlog_file12,
3308
- L: 228,
3388
+ L: 230,
3309
3389
  S: this,
3310
3390
  C: (f, a) => f(...a)
3311
3391
  });
@@ -3316,7 +3396,7 @@ var ServiceContext = class {
3316
3396
  details: assertion
3317
3397
  }, {
3318
3398
  F: __dxlog_file12,
3319
- L: 233,
3399
+ L: 235,
3320
3400
  S: this,
3321
3401
  C: (f, a) => f(...a)
3322
3402
  });
@@ -3327,14 +3407,14 @@ var ServiceContext = class {
3327
3407
  } catch (err) {
3328
3408
  log12.catch(err, void 0, {
3329
3409
  F: __dxlog_file12,
3330
- L: 239,
3410
+ L: 241,
3331
3411
  S: this,
3332
3412
  C: (f, a) => f(...a)
3333
3413
  });
3334
3414
  }
3335
3415
  }
3336
- });
3337
- await this._deviceSpaceSync.open();
3416
+ };
3417
+ await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3338
3418
  }
3339
3419
  };
3340
3420
 
@@ -3539,7 +3619,7 @@ var ServiceRegistry = class {
3539
3619
 
3540
3620
  // packages/sdk/client-services/src/packlets/services/service-host.ts
3541
3621
  import invariant12 from "tiny-invariant";
3542
- import { Event as Event8, synchronized as synchronized2 } from "@dxos/async";
3622
+ import { Event as Event8, synchronized as synchronized3 } from "@dxos/async";
3543
3623
  import { clientServiceBundle } from "@dxos/client-protocol";
3544
3624
  import { DocumentModel } from "@dxos/document-model";
3545
3625
  import { DataServiceImpl } from "@dxos/echo-pipeline";
@@ -3994,10 +4074,10 @@ var ClientServicesHost = class {
3994
4074
  }
3995
4075
  };
3996
4076
  _ts_decorate4([
3997
- synchronized2
4077
+ synchronized3
3998
4078
  ], ClientServicesHost.prototype, "open", null);
3999
4079
  _ts_decorate4([
4000
- synchronized2
4080
+ synchronized3
4001
4081
  ], ClientServicesHost.prototype, "close", null);
4002
4082
 
4003
4083
  export {
@@ -4031,4 +4111,4 @@ export {
4031
4111
  createDefaultModelFactory,
4032
4112
  ClientServicesHost
4033
4113
  };
4034
- //# sourceMappingURL=chunk-PWZ2J6KS.mjs.map
4114
+ //# sourceMappingURL=chunk-EYXOVYW5.mjs.map