@dxos/client-services 0.1.49 → 0.1.50-next.1bfebf8

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 (35) hide show
  1. package/dist/lib/browser/{chunk-YLH4UYUT.mjs → chunk-UL74TKNZ.mjs} +497 -1095
  2. package/dist/lib/browser/chunk-UL74TKNZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +601 -9
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/index.cjs +1098 -1158
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +238 -726
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/packlets/locks/browser.d.ts +16 -0
  15. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -0
  16. package/dist/types/src/packlets/locks/index.d.ts +3 -0
  17. package/dist/types/src/packlets/locks/index.d.ts.map +1 -0
  18. package/dist/types/src/packlets/locks/node.d.ts +13 -0
  19. package/dist/types/src/packlets/locks/node.d.ts.map +1 -0
  20. package/dist/types/src/packlets/locks/resource-lock.d.ts +16 -0
  21. package/dist/types/src/packlets/locks/resource-lock.d.ts.map +1 -0
  22. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  23. package/dist/types/src/packlets/vault/index.d.ts +0 -1
  24. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  25. package/package.json +33 -30
  26. package/src/index.ts +1 -0
  27. package/src/packlets/{vault/vault-resource-lock.ts → locks/browser.ts} +12 -11
  28. package/src/packlets/locks/index.ts +6 -0
  29. package/src/packlets/locks/node.ts +52 -0
  30. package/src/packlets/locks/resource-lock.ts +24 -0
  31. package/src/packlets/services/service-host.ts +13 -13
  32. package/src/packlets/vault/index.ts +0 -1
  33. package/dist/lib/browser/chunk-YLH4UYUT.mjs.map +0 -7
  34. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +0 -20
  35. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +0 -1
@@ -61,21 +61,21 @@ var createMockCredential = async ({ signer, issuer }) => (0, import_credentials.
61
61
  });
62
62
 
63
63
  // packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
64
- var import_node_assert15 = __toESM(require("node:assert"));
65
- var import_async24 = require("@dxos/async");
66
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
64
+ var import_node_assert13 = __toESM(require("node:assert"));
65
+ var import_async19 = require("@dxos/async");
66
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
67
67
 
68
68
  // packages/sdk/client-services/src/packlets/services/service-host.ts
69
- var import_node_assert14 = __toESM(require("node:assert"));
70
- var import_async23 = require("@dxos/async");
71
- var import_client_protocol9 = require("@dxos/client-protocol");
69
+ var import_node_assert12 = __toESM(require("node:assert"));
70
+ var import_async18 = require("@dxos/async");
71
+ var import_client_protocol4 = require("@dxos/client-protocol");
72
72
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
73
73
  var import_keys12 = require("@dxos/keys");
74
- var import_log19 = require("@dxos/log");
75
- var import_messaging3 = require("@dxos/messaging");
76
- var import_network_manager5 = require("@dxos/network-manager");
74
+ var import_log15 = require("@dxos/log");
75
+ var import_messaging = require("@dxos/messaging");
76
+ var import_network_manager2 = require("@dxos/network-manager");
77
77
  var import_protocols9 = require("@dxos/protocols");
78
- var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
78
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
79
79
 
80
80
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
81
81
  var import_async = require("@dxos/async");
@@ -2150,24 +2150,81 @@ var SpaceInvitationProtocol = class {
2150
2150
  }
2151
2151
  };
2152
2152
 
2153
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
2153
+ // packages/sdk/client-services/src/packlets/locks/node.ts
2154
+ var import_lockfile = __toESM(require("lockfile"));
2154
2155
  var import_async11 = require("@dxos/async");
2155
- var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2156
2156
  var import_log8 = require("@dxos/log");
2157
+ var __decorate = function(decorators, target, key, desc) {
2158
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2159
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2160
+ r = Reflect.decorate(decorators, target, key, desc);
2161
+ else
2162
+ for (var i = decorators.length - 1; i >= 0; i--)
2163
+ if (d = decorators[i])
2164
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2165
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2166
+ };
2167
+ var Lock = class {
2168
+ constructor({ lockKey: lockPath, onAcquire, onRelease }) {
2169
+ this._releaseTrigger = new import_async11.Trigger();
2170
+ this._lockPath = lockPath;
2171
+ this._onAcquire = onAcquire;
2172
+ this._onRelease = onRelease;
2173
+ }
2174
+ get lockKey() {
2175
+ return this._lockPath;
2176
+ }
2177
+ async acquire() {
2178
+ var _a;
2179
+ (0, import_log8.log)("acquiring lock...", {}, {
2180
+ file: "node.ts",
2181
+ line: 31,
2182
+ scope: this,
2183
+ callSite: (f, a) => f(...a)
2184
+ });
2185
+ if (import_lockfile.default.checkSync(this.lockKey)) {
2186
+ throw new Error(`Lock already acquired: ${this._lockPath}`);
2187
+ }
2188
+ import_lockfile.default.lockSync(this._lockPath);
2189
+ await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
2190
+ (0, import_log8.log)("acquired lock", {}, {
2191
+ file: "node.ts",
2192
+ line: 39,
2193
+ scope: this,
2194
+ callSite: (f, a) => f(...a)
2195
+ });
2196
+ }
2197
+ async release() {
2198
+ var _a;
2199
+ if (!import_lockfile.default.checkSync(this._lockPath)) {
2200
+ throw new Error(`Lock already acquired: ${this._lockPath}`);
2201
+ }
2202
+ await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
2203
+ import_lockfile.default.unlockSync(this._lockPath);
2204
+ }
2205
+ };
2206
+ __decorate([
2207
+ import_log8.logInfo
2208
+ ], Lock.prototype, "lockKey", null);
2209
+
2210
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
2211
+ var import_async12 = require("@dxos/async");
2212
+ var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2213
+ var import_log9 = require("@dxos/log");
2157
2214
  var import_util3 = require("@dxos/util");
2158
2215
  var LoggingServiceImpl = class {
2159
2216
  constructor() {
2160
- this._logs = new import_async11.Event();
2217
+ this._logs = new import_async12.Event();
2161
2218
  this._logProcessor = (_config, entry2) => {
2162
2219
  this._logs.emit(entry2);
2163
2220
  };
2164
2221
  }
2165
2222
  async open() {
2166
- import_log8.log.runtimeConfig.processors.push(this._logProcessor);
2223
+ import_log9.log.runtimeConfig.processors.push(this._logProcessor);
2167
2224
  }
2168
2225
  async close() {
2169
- const index = import_log8.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
2170
- import_log8.log.runtimeConfig.processors.splice(index, 1);
2226
+ const index = import_log9.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
2227
+ import_log9.log.runtimeConfig.processors.splice(index, 1);
2171
2228
  }
2172
2229
  queryLogs(request) {
2173
2230
  var _a;
@@ -2178,10 +2235,10 @@ var LoggingServiceImpl = class {
2178
2235
  if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
2179
2236
  return;
2180
2237
  }
2181
- if ((0, import_log8.shouldLog)(entry2, filters)) {
2238
+ if ((0, import_log9.shouldLog)(entry2, filters)) {
2182
2239
  const record = {
2183
2240
  ...entry2,
2184
- context: (0, import_util3.jsonify)((0, import_log8.getContextFromEntry)(entry2))
2241
+ context: (0, import_util3.jsonify)((0, import_log9.getContextFromEntry)(entry2))
2185
2242
  };
2186
2243
  (_b = record.meta) == null ? true : delete _b.bugcheck;
2187
2244
  (_c = record.meta) == null ? true : delete _c.scope;
@@ -2230,35 +2287,35 @@ var NetworkServiceImpl = class {
2230
2287
 
2231
2288
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2232
2289
  var import_node_assert10 = __toESM(require("node:assert"));
2233
- var import_async14 = require("@dxos/async");
2290
+ var import_async15 = require("@dxos/async");
2234
2291
  var import_context7 = require("@dxos/context");
2235
2292
  var import_credentials13 = require("@dxos/credentials");
2236
2293
  var import_keys10 = require("@dxos/keys");
2237
- var import_log11 = require("@dxos/log");
2294
+ var import_log12 = require("@dxos/log");
2238
2295
  var import_protocols6 = require("@dxos/protocols");
2239
2296
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
2240
2297
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2241
2298
  var import_util6 = require("@dxos/util");
2242
2299
 
2243
2300
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2244
- var import_async13 = require("@dxos/async");
2301
+ var import_async14 = require("@dxos/async");
2245
2302
  var import_client_protocol3 = require("@dxos/client-protocol");
2246
2303
  var import_context6 = require("@dxos/context");
2247
2304
  var import_debug3 = require("@dxos/debug");
2248
2305
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2249
2306
  var import_errors3 = require("@dxos/errors");
2250
2307
  var import_keys9 = require("@dxos/keys");
2251
- var import_log10 = require("@dxos/log");
2308
+ var import_log11 = require("@dxos/log");
2252
2309
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2253
2310
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
2254
2311
  var import_util5 = require("@dxos/util");
2255
2312
 
2256
2313
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2257
2314
  var import_node_assert9 = __toESM(require("node:assert"));
2258
- var import_async12 = require("@dxos/async");
2315
+ var import_async13 = require("@dxos/async");
2259
2316
  var import_context5 = require("@dxos/context");
2260
2317
  var import_keys8 = require("@dxos/keys");
2261
- var import_log9 = require("@dxos/log");
2318
+ var import_log10 = require("@dxos/log");
2262
2319
  var import_protocols5 = require("@dxos/protocols");
2263
2320
  var import_teleport2 = require("@dxos/teleport");
2264
2321
  var import_util4 = require("@dxos/util");
@@ -2269,7 +2326,7 @@ var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2269
2326
  var NotarizationPlugin = class {
2270
2327
  constructor() {
2271
2328
  this._ctx = new import_context5.Context();
2272
- this._extensionOpened = new import_async12.Event();
2329
+ this._extensionOpened = new import_async13.Event();
2273
2330
  this._extensions = /* @__PURE__ */ new Set();
2274
2331
  this._processedCredentials = new import_util4.ComplexSet(import_keys8.PublicKey.hash);
2275
2332
  this._processCredentialsTriggers = new import_util4.ComplexMap(import_keys8.PublicKey.hash);
@@ -2283,7 +2340,7 @@ var NotarizationPlugin = class {
2283
2340
  * Request credentials to be notarized.
2284
2341
  */
2285
2342
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2286
- (0, import_log9.log)("notarize", {
2343
+ (0, import_log10.log)("notarize", {
2287
2344
  credentials
2288
2345
  }, {
2289
2346
  file: "notarization-plugin.ts",
@@ -2292,10 +2349,10 @@ var NotarizationPlugin = class {
2292
2349
  callSite: (f, a) => f(...a)
2293
2350
  });
2294
2351
  (0, import_node_assert9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2295
- const errors = new import_async12.Trigger();
2352
+ const errors = new import_async13.Trigger();
2296
2353
  const ctx = this._ctx.derive({
2297
2354
  onError: (err) => {
2298
- import_log9.log.warn("Notarization error", {
2355
+ import_log10.log.warn("Notarization error", {
2299
2356
  err
2300
2357
  }, {
2301
2358
  file: "notarization-plugin.ts",
@@ -2309,8 +2366,8 @@ var NotarizationPlugin = class {
2309
2366
  });
2310
2367
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2311
2368
  if (timeout !== 0) {
2312
- (0, import_async12.scheduleTask)(ctx, () => {
2313
- import_log9.log.warn("Notarization timeout", {
2369
+ (0, import_async13.scheduleTask)(ctx, () => {
2370
+ import_log10.log.warn("Notarization timeout", {
2314
2371
  timeout,
2315
2372
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2316
2373
  }, {
@@ -2320,12 +2377,12 @@ var NotarizationPlugin = class {
2320
2377
  callSite: (f, a) => f(...a)
2321
2378
  });
2322
2379
  void ctx.dispose();
2323
- errors.throw(new import_async12.TimeoutError(timeout, "Notarization timed out"));
2380
+ errors.throw(new import_async13.TimeoutError(timeout, "Notarization timed out"));
2324
2381
  }, timeout);
2325
2382
  }
2326
2383
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2327
2384
  const peersTried = /* @__PURE__ */ new Set();
2328
- const notarizeTask = new import_async12.DeferredTask(ctx, async () => {
2385
+ const notarizeTask = new import_async13.DeferredTask(ctx, async () => {
2329
2386
  try {
2330
2387
  if (this._extensions.size === 0) {
2331
2388
  return;
@@ -2334,7 +2391,7 @@ var NotarizationPlugin = class {
2334
2391
  ...this._extensions
2335
2392
  ].find((peer2) => !peersTried.has(peer2));
2336
2393
  if (!peer) {
2337
- import_log9.log.warn("Exhausted all peers to notarize with", {
2394
+ import_log10.log.warn("Exhausted all peers to notarize with", {
2338
2395
  retryIn: retryTimeout
2339
2396
  }, {
2340
2397
  file: "notarization-plugin.ts",
@@ -2343,11 +2400,11 @@ var NotarizationPlugin = class {
2343
2400
  callSite: (f, a) => f(...a)
2344
2401
  });
2345
2402
  peersTried.clear();
2346
- (0, import_async12.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2403
+ (0, import_async13.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2347
2404
  return;
2348
2405
  }
2349
2406
  peersTried.add(peer);
2350
- (0, import_log9.log)("try notarizing", {
2407
+ (0, import_log10.log)("try notarizing", {
2351
2408
  peer: peer.localPeerId,
2352
2409
  credentialId: credentials.map((credential) => credential.id)
2353
2410
  }, {
@@ -2359,16 +2416,16 @@ var NotarizationPlugin = class {
2359
2416
  await peer.rpc.NotarizationService.notarize({
2360
2417
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2361
2418
  });
2362
- (0, import_log9.log)("success", {}, {
2419
+ (0, import_log10.log)("success", {}, {
2363
2420
  file: "notarization-plugin.ts",
2364
2421
  line: 144,
2365
2422
  scope: this,
2366
2423
  callSite: (f, a) => f(...a)
2367
2424
  });
2368
- await (0, import_async12.sleep)(successDelay);
2425
+ await (0, import_async13.sleep)(successDelay);
2369
2426
  } catch (err) {
2370
2427
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2371
- import_log9.log.warn("error notarizing (recoverable)", err, {
2428
+ import_log10.log.warn("error notarizing (recoverable)", err, {
2372
2429
  file: "notarization-plugin.ts",
2373
2430
  line: 148,
2374
2431
  scope: this,
@@ -2386,7 +2443,7 @@ var NotarizationPlugin = class {
2386
2443
  allNotarized,
2387
2444
  errors.wait()
2388
2445
  ]);
2389
- (0, import_log9.log)("done", {}, {
2446
+ (0, import_log10.log)("done", {}, {
2390
2447
  file: "notarization-plugin.ts",
2391
2448
  line: 159,
2392
2449
  scope: this,
@@ -2416,7 +2473,7 @@ var NotarizationPlugin = class {
2416
2473
  if (this._processedCredentials.has(id)) {
2417
2474
  return;
2418
2475
  }
2419
- await (0, import_util4.entry)(this._processCredentialsTriggers, id).orInsert(new import_async12.Trigger()).value.wait();
2476
+ await (0, import_util4.entry)(this._processCredentialsTriggers, id).orInsert(new import_async13.Trigger()).value.wait();
2420
2477
  }
2421
2478
  /**
2422
2479
  * Requests from other peers to notarize credentials.
@@ -2437,7 +2494,7 @@ var NotarizationPlugin = class {
2437
2494
  createExtension() {
2438
2495
  const extension = new NotarizationTeleportExtension({
2439
2496
  onOpen: async () => {
2440
- (0, import_log9.log)("extension opened", {
2497
+ (0, import_log10.log)("extension opened", {
2441
2498
  peer: extension.localPeerId
2442
2499
  }, {
2443
2500
  file: "notarization-plugin.ts",
@@ -2449,7 +2506,7 @@ var NotarizationPlugin = class {
2449
2506
  this._extensionOpened.emit();
2450
2507
  },
2451
2508
  onClose: async () => {
2452
- (0, import_log9.log)("extension closed", {
2509
+ (0, import_log10.log)("extension closed", {
2453
2510
  peer: extension.localPeerId
2454
2511
  }, {
2455
2512
  file: "notarization-plugin.ts",
@@ -2496,7 +2553,7 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2496
2553
  };
2497
2554
 
2498
2555
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2499
- var __decorate = function(decorators, target, key, desc) {
2556
+ var __decorate2 = function(decorators, target, key, desc) {
2500
2557
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2501
2558
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2502
2559
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2514,7 +2571,7 @@ var DataSpace = class DataSpace2 {
2514
2571
  * Error for _state === SpaceState.ERROR.
2515
2572
  */
2516
2573
  this.error = void 0;
2517
- this.stateUpdate = new import_async13.Event();
2574
+ this.stateUpdate = new import_async14.Event();
2518
2575
  this.metrics = {};
2519
2576
  var _a;
2520
2577
  this._inner = params.inner;
@@ -2585,13 +2642,13 @@ var DataSpace = class DataSpace2 {
2585
2642
  * Initialize the data pipeline in a separate task.
2586
2643
  */
2587
2644
  initializeDataPipelineAsync() {
2588
- (0, import_async13.scheduleTask)(this._ctx, async () => {
2645
+ (0, import_async14.scheduleTask)(this._ctx, async () => {
2589
2646
  try {
2590
2647
  this.metrics.pipelineInitBegin = new Date();
2591
2648
  await this.initializeDataPipeline();
2592
2649
  } catch (err) {
2593
2650
  if (err instanceof import_errors3.CancelledError) {
2594
- (0, import_log10.log)("Data pipeline initialization cancelled", err, {
2651
+ (0, import_log11.log)("Data pipeline initialization cancelled", err, {
2595
2652
  file: "data-space.ts",
2596
2653
  line: 172,
2597
2654
  scope: this,
@@ -2599,7 +2656,7 @@ var DataSpace = class DataSpace2 {
2599
2656
  });
2600
2657
  return;
2601
2658
  }
2602
- import_log10.log.error("Error initializing data pipeline", err, {
2659
+ import_log11.log.error("Error initializing data pipeline", err, {
2603
2660
  file: "data-space.ts",
2604
2661
  line: 176,
2605
2662
  scope: this,
@@ -2625,7 +2682,7 @@ var DataSpace = class DataSpace2 {
2625
2682
  });
2626
2683
  this.metrics.controlPipelineReady = new Date();
2627
2684
  await this._createWritableFeeds();
2628
- (0, import_log10.log)("Writable feeds created", {}, {
2685
+ (0, import_log11.log)("Writable feeds created", {}, {
2629
2686
  file: "data-space.ts",
2630
2687
  line: 201,
2631
2688
  scope: this,
@@ -2640,7 +2697,7 @@ var DataSpace = class DataSpace2 {
2640
2697
  await this._inner.initializeDataPipeline();
2641
2698
  this.metrics.dataPipelineOpen = new Date();
2642
2699
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2643
- (0, import_log10.log)("waiting for data pipeline to reach target timeframe", {}, {
2700
+ (0, import_log11.log)("waiting for data pipeline to reach target timeframe", {}, {
2644
2701
  file: "data-space.ts",
2645
2702
  line: 220,
2646
2703
  scope: this,
@@ -2651,7 +2708,7 @@ var DataSpace = class DataSpace2 {
2651
2708
  breakOnStall: false
2652
2709
  });
2653
2710
  this.metrics.dataPipelineReady = new Date();
2654
- (0, import_log10.log)("data pipeline ready", {}, {
2711
+ (0, import_log11.log)("data pipeline ready", {}, {
2655
2712
  file: "data-space.ts",
2656
2713
  line: 229,
2657
2714
  scope: this,
@@ -2727,11 +2784,11 @@ var DataSpace = class DataSpace2 {
2727
2784
  }
2728
2785
  }
2729
2786
  };
2730
- __decorate([
2787
+ __decorate2([
2731
2788
  (0, import_debug3.timed)(1e4)
2732
2789
  ], DataSpace.prototype, "_createWritableFeeds", null);
2733
- DataSpace = __decorate([
2734
- (0, import_async13.trackLeaks)("open", "close")
2790
+ DataSpace = __decorate2([
2791
+ (0, import_async14.trackLeaks)("open", "close")
2735
2792
  ], DataSpace);
2736
2793
 
2737
2794
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
@@ -2805,7 +2862,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2805
2862
  };
2806
2863
 
2807
2864
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2808
- var __decorate2 = function(decorators, target, key, desc) {
2865
+ var __decorate3 = function(decorators, target, key, desc) {
2809
2866
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2810
2867
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2811
2868
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2824,7 +2881,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2824
2881
  this._signingContext = _signingContext;
2825
2882
  this._feedStore = _feedStore;
2826
2883
  this._ctx = new import_context7.Context();
2827
- this.updated = new import_async14.Event();
2884
+ this.updated = new import_async15.Event();
2828
2885
  this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
2829
2886
  this._isOpen = false;
2830
2887
  this._instanceId = import_keys10.PublicKey.random().toHex();
@@ -2834,13 +2891,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2834
2891
  return this._spaces;
2835
2892
  }
2836
2893
  async open() {
2837
- (0, import_log11.log)("open", {}, {
2894
+ (0, import_log12.log)("open", {}, {
2838
2895
  file: "data-space-manager.ts",
2839
2896
  line: 80,
2840
2897
  scope: this,
2841
2898
  callSite: (f, a) => f(...a)
2842
2899
  });
2843
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.begin({
2900
+ import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.begin({
2844
2901
  id: this._instanceId
2845
2902
  }), {
2846
2903
  file: "data-space-manager.ts",
@@ -2849,7 +2906,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2849
2906
  callSite: (f, a) => f(...a)
2850
2907
  });
2851
2908
  await this._metadataStore.load();
2852
- (0, import_log11.log)("metadata loaded", {
2909
+ (0, import_log12.log)("metadata loaded", {
2853
2910
  spaces: this._metadataStore.spaces.length
2854
2911
  }, {
2855
2912
  file: "data-space-manager.ts",
@@ -2859,7 +2916,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2859
2916
  });
2860
2917
  for (const spaceMetadata of this._metadataStore.spaces) {
2861
2918
  try {
2862
- (0, import_log11.log)("load space", {
2919
+ (0, import_log12.log)("load space", {
2863
2920
  spaceMetadata
2864
2921
  }, {
2865
2922
  file: "data-space-manager.ts",
@@ -2870,7 +2927,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2870
2927
  const space = await this._constructSpace(spaceMetadata);
2871
2928
  space.initializeDataPipelineAsync();
2872
2929
  } catch (err) {
2873
- import_log11.log.error("Error loading space", {
2930
+ import_log12.log.error("Error loading space", {
2874
2931
  spaceMetadata,
2875
2932
  err
2876
2933
  }, {
@@ -2883,7 +2940,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2883
2940
  }
2884
2941
  this._isOpen = true;
2885
2942
  this.updated.emit();
2886
- import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.end({
2943
+ import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols6.trace.end({
2887
2944
  id: this._instanceId
2888
2945
  }), {
2889
2946
  file: "data-space-manager.ts",
@@ -2893,7 +2950,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2893
2950
  });
2894
2951
  }
2895
2952
  async close() {
2896
- (0, import_log11.log)("close", {}, {
2953
+ (0, import_log12.log)("close", {}, {
2897
2954
  file: "data-space-manager.ts",
2898
2955
  line: 102,
2899
2956
  scope: this,
@@ -2919,7 +2976,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2919
2976
  controlFeedKey,
2920
2977
  dataFeedKey
2921
2978
  };
2922
- (0, import_log11.log)("creating space...", {
2979
+ (0, import_log12.log)("creating space...", {
2923
2980
  spaceKey
2924
2981
  }, {
2925
2982
  file: "data-space-manager.ts",
@@ -2939,7 +2996,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2939
2996
  }
2940
2997
  // TODO(burdon): Rename join space.
2941
2998
  async acceptSpace(opts) {
2942
- (0, import_log11.log)("accept space", {
2999
+ (0, import_log12.log)("accept space", {
2943
3000
  opts
2944
3001
  }, {
2945
3002
  file: "data-space-manager.ts",
@@ -2973,7 +3030,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2973
3030
  }));
2974
3031
  }
2975
3032
  async _constructSpace(metadata) {
2976
- (0, import_log11.log)("construct space", {
3033
+ (0, import_log12.log)("construct space", {
2977
3034
  metadata
2978
3035
  }, {
2979
3036
  file: "data-space-manager.ts",
@@ -3011,7 +3068,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3011
3068
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3012
3069
  },
3013
3070
  onAuthFailure: () => {
3014
- import_log11.log.warn("auth failure", {}, {
3071
+ import_log12.log.warn("auth failure", {}, {
3015
3072
  file: "data-space-manager.ts",
3016
3073
  line: 212,
3017
3074
  scope: this,
@@ -3032,7 +3089,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3032
3089
  signingContext: this._signingContext,
3033
3090
  callbacks: {
3034
3091
  beforeReady: async () => {
3035
- (0, import_log11.log)("before space ready", {
3092
+ (0, import_log12.log)("before space ready", {
3036
3093
  space: space.key
3037
3094
  }, {
3038
3095
  file: "data-space-manager.ts",
@@ -3043,7 +3100,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3043
3100
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3044
3101
  },
3045
3102
  afterReady: async () => {
3046
- (0, import_log11.log)("after space ready", {
3103
+ (0, import_log12.log)("after space ready", {
3047
3104
  space: space.key,
3048
3105
  open: this._isOpen
3049
3106
  }, {
@@ -3070,28 +3127,28 @@ var DataSpaceManager = class DataSpaceManager2 {
3070
3127
  return dataSpace;
3071
3128
  }
3072
3129
  };
3073
- __decorate2([
3074
- import_async14.synchronized
3130
+ __decorate3([
3131
+ import_async15.synchronized
3075
3132
  ], DataSpaceManager.prototype, "open", null);
3076
- __decorate2([
3077
- import_async14.synchronized
3133
+ __decorate3([
3134
+ import_async15.synchronized
3078
3135
  ], DataSpaceManager.prototype, "close", null);
3079
- __decorate2([
3080
- import_async14.synchronized
3136
+ __decorate3([
3137
+ import_async15.synchronized
3081
3138
  ], DataSpaceManager.prototype, "createSpace", null);
3082
- __decorate2([
3083
- import_async14.synchronized
3139
+ __decorate3([
3140
+ import_async15.synchronized
3084
3141
  ], DataSpaceManager.prototype, "acceptSpace", null);
3085
- DataSpaceManager = __decorate2([
3086
- (0, import_async14.trackLeaks)("open", "close")
3142
+ DataSpaceManager = __decorate3([
3143
+ (0, import_async15.trackLeaks)("open", "close")
3087
3144
  ], DataSpaceManager);
3088
3145
 
3089
3146
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
3090
- var import_async15 = require("@dxos/async");
3147
+ var import_async16 = require("@dxos/async");
3091
3148
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
3092
3149
  var import_debug5 = require("@dxos/debug");
3093
3150
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
3094
- var import_log12 = require("@dxos/log");
3151
+ var import_log13 = require("@dxos/log");
3095
3152
  var import_protocols7 = require("@dxos/protocols");
3096
3153
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
3097
3154
  var import_util7 = require("@dxos/util");
@@ -3119,7 +3176,7 @@ var SpacesServiceImpl = class {
3119
3176
  const onUpdate = async () => {
3120
3177
  const dataSpaceManager = await this._getDataSpaceManager();
3121
3178
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
3122
- (0, import_log12.log)("update", {
3179
+ (0, import_log13.log)("update", {
3123
3180
  spaces
3124
3181
  }, {
3125
3182
  file: "spaces-service.ts",
@@ -3131,9 +3188,9 @@ var SpacesServiceImpl = class {
3131
3188
  spaces
3132
3189
  });
3133
3190
  };
3134
- (0, import_async15.scheduleTask)(ctx, async () => {
3191
+ (0, import_async16.scheduleTask)(ctx, async () => {
3135
3192
  const dataSpaceManager = await this._getDataSpaceManager();
3136
- const subscriptions = new import_async15.EventSubscriptions();
3193
+ const subscriptions = new import_async16.EventSubscriptions();
3137
3194
  ctx.onDispose(() => subscriptions.clear());
3138
3195
  const subscribeSpaces = () => {
3139
3196
  subscriptions.clear();
@@ -3168,7 +3225,7 @@ var SpacesServiceImpl = class {
3168
3225
  }
3169
3226
  subscribeMessages({ spaceKey, channel }) {
3170
3227
  return new import_codec_protobuf12.Stream(({ ctx, next }) => {
3171
- (0, import_async15.scheduleTask)(ctx, async () => {
3228
+ (0, import_async16.scheduleTask)(ctx, async () => {
3172
3229
  var _a;
3173
3230
  const dataSpaceManager = await this._getDataSpaceManager();
3174
3231
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
@@ -3189,7 +3246,7 @@ var SpacesServiceImpl = class {
3189
3246
  }
3190
3247
  });
3191
3248
  ctx.onDispose(() => processor.close());
3192
- (0, import_async15.scheduleTask)(ctx, () => processor.open());
3249
+ (0, import_async16.scheduleTask)(ctx, () => processor.open());
3193
3250
  });
3194
3251
  }
3195
3252
  async writeCredentials({ spaceKey, credentials }) {
@@ -3329,543 +3386,18 @@ var SystemServiceImpl = class {
3329
3386
  }
3330
3387
  };
3331
3388
 
3332
- // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3333
- var import_async17 = require("@dxos/async");
3334
- var import_client_protocol5 = require("@dxos/client-protocol");
3335
- var import_log13 = require("@dxos/log");
3336
- var import_messaging = require("@dxos/messaging");
3337
- var import_network_manager2 = require("@dxos/network-manager");
3338
- var import_util8 = require("@dxos/util");
3339
-
3340
- // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
3341
- var import_codec_protobuf14 = require("@dxos/codec-protobuf");
3342
- var import_debug6 = require("@dxos/debug");
3343
- var import_rpc = require("@dxos/rpc");
3344
- var ClientRpcServer = class {
3345
- constructor(params) {
3346
- this._handlerCache = /* @__PURE__ */ new Map();
3347
- const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
3348
- this._handleCall = handleCall;
3349
- this._handleStream = handleStream;
3350
- this._serviceRegistry = serviceRegistry;
3351
- this._rpcPeer = new import_rpc.RpcPeer({
3352
- ...rpcOptions,
3353
- callHandler: (method, params2) => {
3354
- const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
3355
- const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
3356
- if (this._handleCall) {
3357
- return this._handleCall(methodName, params2, handler);
3358
- } else {
3359
- return handler(methodName, params2);
3360
- }
3361
- },
3362
- streamHandler: (method, params2) => {
3363
- const [serviceName, methodName] = (0, import_rpc.parseMethodName)(method);
3364
- const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
3365
- if (this._handleStream) {
3366
- return import_codec_protobuf14.Stream.unwrapPromise(this._handleStream(methodName, params2, handler));
3367
- } else {
3368
- return handler(methodName, params2);
3369
- }
3370
- }
3371
- });
3372
- }
3373
- async open() {
3374
- await this._rpcPeer.open();
3375
- }
3376
- async close() {
3377
- await this._rpcPeer.close();
3378
- }
3379
- _getServiceHandler(serviceName) {
3380
- var _a;
3381
- if (!this._handlerCache.has(serviceName)) {
3382
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : (0, import_debug6.raise)(new Error(`Service not available: ${serviceName}`));
3383
- const service = this._serviceRegistry.services[key];
3384
- if (!service) {
3385
- throw new Error(`Service not available: ${serviceName}`);
3386
- }
3387
- this._handlerCache.set(serviceName, descriptor.createServer(service));
3388
- }
3389
- return this._handlerCache.get(serviceName);
3390
- }
3391
- };
3392
-
3393
- // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3394
- var import_node_assert11 = __toESM(require("node:assert"));
3395
- var import_async16 = require("@dxos/async");
3396
- var import_client_protocol4 = require("@dxos/client-protocol");
3397
- var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3398
- var import_rpc2 = require("@dxos/rpc");
3399
- var ShellRuntimeImpl = class {
3400
- constructor(_port) {
3401
- this._port = _port;
3402
- this.layoutUpdate = new import_async16.Event();
3403
- this._layout = import_iframe.ShellLayout.DEFAULT;
3404
- }
3405
- get layout() {
3406
- return this._layout;
3407
- }
3408
- get invitationCode() {
3409
- return this._invitationCode;
3410
- }
3411
- get spaceKey() {
3412
- return this._spaceKey;
3413
- }
3414
- setLayout(layout, options = {}) {
3415
- this._layout = layout;
3416
- this._invitationCode = options.invitationCode;
3417
- this._spaceKey = options.spaceKey;
3418
- this.layoutUpdate.emit({
3419
- layout,
3420
- ...options
3421
- });
3422
- }
3423
- async setAppContext(context) {
3424
- (0, import_node_assert11.default)(this._appRpc, "runtime not open");
3425
- await this._appRpc.rpc.AppService.setContext(context);
3426
- }
3427
- async open() {
3428
- this._appRpc = (0, import_rpc2.createProtoRpcPeer)({
3429
- requested: import_client_protocol4.appServiceBundle,
3430
- exposed: import_client_protocol4.shellServiceBundle,
3431
- handlers: {
3432
- ShellService: {
3433
- setLayout: async (request) => {
3434
- this._layout = request.layout;
3435
- this._invitationCode = request.invitationCode;
3436
- this._spaceKey = request.spaceKey;
3437
- this.layoutUpdate.emit(request);
3438
- }
3439
- }
3440
- },
3441
- port: this._port
3442
- });
3443
- await this._appRpc.open();
3444
- }
3445
- async close() {
3446
- var _a;
3447
- await ((_a = this._appRpc) == null ? void 0 : _a.close());
3448
- this._appRpc = void 0;
3449
- }
3450
- };
3451
-
3452
- // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3453
- var __decorate3 = function(decorators, target, key, desc) {
3454
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3455
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3456
- r = Reflect.decorate(decorators, target, key, desc);
3457
- else
3458
- for (var i = decorators.length - 1; i >= 0; i--)
3459
- if (d = decorators[i])
3460
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3461
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3462
- };
3463
- var LOCK_KEY = "DXOS_RESOURCE_LOCK";
3464
- var IFrameHostRuntime = class {
3465
- constructor({ config, origin, appPort, shellPort }) {
3466
- this._ready = new import_async17.Trigger();
3467
- this._configProvider = config;
3468
- this.origin = origin;
3469
- this._appPort = appPort;
3470
- this._shellPort = shellPort;
3471
- if (this._shellPort) {
3472
- this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
3473
- }
3474
- }
3475
- get services() {
3476
- return this._clientServices;
3477
- }
3478
- get shell() {
3479
- return this._shellRuntime;
3480
- }
3481
- async start() {
3482
- var _a;
3483
- (0, import_log13.log)("starting...", {}, {
3484
- file: "iframe-host-runtime.ts",
3485
- line: 70,
3486
- scope: this,
3487
- callSite: (f, a) => f(...a)
3488
- });
3489
- try {
3490
- this._config = await (0, import_util8.getAsyncValue)(this._configProvider);
3491
- this._transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
3492
- iceServers: this._config.get("runtime.services.ice")
3493
- });
3494
- const signals = this._config.get("runtime.services.signaling");
3495
- this._clientServices = new LocalClientServices({
3496
- lockKey: LOCK_KEY,
3497
- config: this._config,
3498
- signalManager: signals ? new import_messaging.WebsocketSignalManager(signals) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3499
- transportFactory: this._transportFactory
3500
- });
3501
- const middleware = {
3502
- handleCall: async (method, params, handler) => {
3503
- const error = await this._ready.wait({
3504
- timeout: import_client_protocol5.PROXY_CONNECTION_TIMEOUT
3505
- });
3506
- if (error) {
3507
- throw error;
3508
- }
3509
- return handler(method, params);
3510
- },
3511
- handleStream: async (method, params, handler) => {
3512
- const error = await this._ready.wait({
3513
- timeout: import_client_protocol5.PROXY_CONNECTION_TIMEOUT
3514
- });
3515
- if (error) {
3516
- throw error;
3517
- }
3518
- return handler(method, params);
3519
- }
3520
- };
3521
- this._clientRpc = new ClientRpcServer({
3522
- serviceRegistry: this._clientServices.host.serviceRegistry,
3523
- port: this._appPort,
3524
- ...middleware
3525
- });
3526
- await Promise.all([
3527
- this._clientServices.open(),
3528
- this._clientRpc.open(),
3529
- (_a = this._shellRuntime) == null ? void 0 : _a.open()
3530
- ]);
3531
- this._ready.wake(void 0);
3532
- (0, import_log13.log)("started", {}, {
3533
- file: "iframe-host-runtime.ts",
3534
- line: 113,
3535
- scope: this,
3536
- callSite: (f, a) => f(...a)
3537
- });
3538
- } catch (err) {
3539
- this._ready.wake(err);
3540
- import_log13.log.catch(err, {}, {
3541
- file: "iframe-host-runtime.ts",
3542
- line: 116,
3543
- scope: this,
3544
- callSite: (f, a) => f(...a)
3545
- });
3546
- }
3547
- }
3548
- async stop() {
3549
- var _a;
3550
- (0, import_log13.log)("stopping...", {}, {
3551
- file: "iframe-host-runtime.ts",
3552
- line: 121,
3553
- scope: this,
3554
- callSite: (f, a) => f(...a)
3555
- });
3556
- await this._clientRpc.close();
3557
- await this._clientServices.close();
3558
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3559
- (0, import_log13.log)("stopped", {}, {
3560
- file: "iframe-host-runtime.ts",
3561
- line: 125,
3562
- scope: this,
3563
- callSite: (f, a) => f(...a)
3564
- });
3565
- }
3566
- };
3567
- __decorate3([
3568
- import_log13.logInfo
3569
- ], IFrameHostRuntime.prototype, "origin", void 0);
3570
-
3571
- // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3572
- var import_async18 = require("@dxos/async");
3573
- var import_client_protocol6 = require("@dxos/client-protocol");
3574
- var import_errors5 = require("@dxos/errors");
3575
- var import_log14 = require("@dxos/log");
3576
- var import_network_manager3 = require("@dxos/network-manager");
3577
- var import_rpc3 = require("@dxos/rpc");
3578
- var import_util9 = require("@dxos/util");
3579
-
3580
- // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3581
- var import_async19 = require("@dxos/async");
3582
- var import_client_protocol7 = require("@dxos/client-protocol");
3583
- var import_log15 = require("@dxos/log");
3584
- var __decorate4 = function(decorators, target, key, desc) {
3585
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3586
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3587
- r = Reflect.decorate(decorators, target, key, desc);
3588
- else
3589
- for (var i = decorators.length - 1; i >= 0; i--)
3590
- if (d = decorators[i])
3591
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3592
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3593
- };
3594
- var Message;
3595
- (function(Message2) {
3596
- Message2["ACQUIRING"] = "acquiring";
3597
- })(Message || (Message = {}));
3598
- var VaultResourceLock = class {
3599
- constructor({ lockKey, onAcquire, onRelease }) {
3600
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3601
- this._releaseTrigger = new import_async19.Trigger();
3602
- this._lockKey = lockKey;
3603
- this._onAcquire = onAcquire;
3604
- this._onRelease = onRelease;
3605
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
3606
- }
3607
- get lockKey() {
3608
- return this._lockKey;
3609
- }
3610
- async acquire() {
3611
- this._broadcastChannel.postMessage({
3612
- message: Message.ACQUIRING
3613
- });
3614
- try {
3615
- (0, import_log15.log)("aquiring lock...", {}, {
3616
- file: "vault-resource-lock.ts",
3617
- line: 46,
3618
- scope: this,
3619
- callSite: (f, a) => f(...a)
3620
- });
3621
- await (0, import_async19.asyncTimeout)(this._requestLock(), import_client_protocol7.RESOURCE_LOCK_TIMEOUT);
3622
- (0, import_log15.log)("acquired lock", {}, {
3623
- file: "vault-resource-lock.ts",
3624
- line: 48,
3625
- scope: this,
3626
- callSite: (f, a) => f(...a)
3627
- });
3628
- } catch (e) {
3629
- (0, import_log15.log)("stealing lock...", {}, {
3630
- file: "vault-resource-lock.ts",
3631
- line: 50,
3632
- scope: this,
3633
- callSite: (f, a) => f(...a)
3634
- });
3635
- await this._requestLock(true);
3636
- (0, import_log15.log)("stolen lock", {}, {
3637
- file: "vault-resource-lock.ts",
3638
- line: 52,
3639
- scope: this,
3640
- callSite: (f, a) => f(...a)
3641
- });
3642
- }
3643
- }
3644
- async release() {
3645
- this._releaseTrigger.wake();
3646
- }
3647
- _onMessage(event) {
3648
- if (event.data.message === Message.ACQUIRING) {
3649
- this._releaseTrigger.wake();
3650
- }
3651
- }
3652
- async _requestLock(steal = false) {
3653
- (0, import_log15.log)("requesting lock...", {
3654
- steal
3655
- }, {
3656
- file: "vault-resource-lock.ts",
3657
- line: 67,
3658
- scope: this,
3659
- callSite: (f, a) => f(...a)
3660
- });
3661
- const acquired = new import_async19.Trigger();
3662
- void navigator.locks.request(this._lockKey, {
3663
- steal
3664
- }, async () => {
3665
- var _a, _b;
3666
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3667
- acquired.wake();
3668
- this._releaseTrigger = new import_async19.Trigger();
3669
- await this._releaseTrigger.wait();
3670
- (0, import_log15.log)("releasing lock...", {}, {
3671
- file: "vault-resource-lock.ts",
3672
- line: 76,
3673
- scope: this,
3674
- callSite: (f, a) => f(...a)
3675
- });
3676
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3677
- (0, import_log15.log)("released lock", {}, {
3678
- file: "vault-resource-lock.ts",
3679
- line: 78,
3680
- scope: this,
3681
- callSite: (f, a) => f(...a)
3682
- });
3683
- }).catch(async () => {
3684
- var _a;
3685
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3686
- });
3687
- await acquired.wait();
3688
- (0, import_log15.log)("recieved lock", {
3689
- steal
3690
- }, {
3691
- file: "vault-resource-lock.ts",
3692
- line: 85,
3693
- scope: this,
3694
- callSite: (f, a) => f(...a)
3695
- });
3696
- }
3697
- };
3698
- __decorate4([
3699
- import_log15.logInfo
3700
- ], VaultResourceLock.prototype, "lockKey", null);
3701
-
3702
- // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3703
- var import_async21 = require("@dxos/async");
3704
- var import_log17 = require("@dxos/log");
3705
- var import_messaging2 = require("@dxos/messaging");
3706
- var import_network_manager4 = require("@dxos/network-manager");
3707
-
3708
- // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3709
- var import_node_assert12 = __toESM(require("node:assert"));
3710
- var import_async20 = require("@dxos/async");
3711
- var import_client_protocol8 = require("@dxos/client-protocol");
3712
- var import_log16 = require("@dxos/log");
3713
- var import_rpc4 = require("@dxos/rpc");
3714
- var import_util10 = require("@dxos/util");
3715
- var __decorate5 = function(decorators, target, key, desc) {
3716
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3717
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3718
- r = Reflect.decorate(decorators, target, key, desc);
3719
- else
3720
- for (var i = decorators.length - 1; i >= 0; i--)
3721
- if (d = decorators[i])
3722
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3723
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3724
- };
3725
- var WorkerSession = class {
3726
- constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
3727
- this._startTrigger = new import_async20.Trigger();
3728
- this.onClose = new import_util10.Callback();
3729
- (0, import_node_assert12.default)(serviceHost);
3730
- this._serviceHost = serviceHost;
3731
- const middleware = {
3732
- handleCall: async (method, params, handler) => {
3733
- const error = await readySignal.wait({
3734
- timeout: import_client_protocol8.PROXY_CONNECTION_TIMEOUT
3735
- });
3736
- if (error) {
3737
- throw error;
3738
- }
3739
- return handler(method, params);
3740
- },
3741
- handleStream: async (method, params, handler) => {
3742
- const error = await readySignal.wait({
3743
- timeout: import_client_protocol8.PROXY_CONNECTION_TIMEOUT
3744
- });
3745
- if (error) {
3746
- throw error;
3747
- }
3748
- return handler(method, params);
3749
- }
3750
- };
3751
- this._clientRpc = new ClientRpcServer({
3752
- serviceRegistry: this._serviceHost.serviceRegistry,
3753
- port: appPort,
3754
- ...middleware
3755
- });
3756
- this._shellClientRpc = new ClientRpcServer({
3757
- serviceRegistry: this._serviceHost.serviceRegistry,
3758
- port: shellPort,
3759
- ...middleware
3760
- });
3761
- this._iframeRpc = (0, import_rpc4.createProtoRpcPeer)({
3762
- requested: import_client_protocol8.iframeServiceBundle,
3763
- exposed: import_client_protocol8.workerServiceBundle,
3764
- handlers: {
3765
- WorkerService: {
3766
- start: async (request) => {
3767
- this.origin = request.origin;
3768
- this.lockKey = request.lockKey;
3769
- this._startTrigger.wake();
3770
- },
3771
- stop: async () => {
3772
- setTimeout(async () => {
3773
- try {
3774
- await this.close();
3775
- } catch (err) {
3776
- import_log16.log.catch(err, {}, {
3777
- file: "worker-session.ts",
3778
- line: 100,
3779
- scope: this,
3780
- callSite: (f, a) => f(...a)
3781
- });
3782
- }
3783
- });
3784
- }
3785
- }
3786
- },
3787
- port: systemPort,
3788
- timeout: 1e3
3789
- });
3790
- this.bridgeService = this._iframeRpc.rpc.BridgeService;
3791
- }
3792
- async open() {
3793
- import_log16.log.info("opening..", {}, {
3794
- file: "worker-session.ts",
3795
- line: 114,
3796
- scope: this,
3797
- callSite: (f, a) => f(...a)
3798
- });
3799
- await Promise.all([
3800
- this._clientRpc.open(),
3801
- this._iframeRpc.open(),
3802
- this._maybeOpenShell()
3803
- ]);
3804
- await this._startTrigger.wait({
3805
- timeout: import_client_protocol8.PROXY_CONNECTION_TIMEOUT
3806
- });
3807
- if (this.lockKey) {
3808
- void this._afterLockReleases(this.lockKey, () => this.close());
3809
- }
3810
- }
3811
- async close() {
3812
- import_log16.log.info("closing..", {}, {
3813
- file: "worker-session.ts",
3814
- line: 124,
3815
- scope: this,
3816
- callSite: (f, a) => f(...a)
3817
- });
3818
- try {
3819
- await this.onClose.callIfSet();
3820
- } catch (err) {
3821
- import_log16.log.catch(err, {}, {
3822
- file: "worker-session.ts",
3823
- line: 128,
3824
- scope: this,
3825
- callSite: (f, a) => f(...a)
3826
- });
3827
- }
3828
- await Promise.all([
3829
- this._clientRpc.close(),
3830
- this._iframeRpc.close()
3831
- ]);
3832
- }
3833
- async _maybeOpenShell() {
3834
- try {
3835
- await (0, import_async20.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3836
- } catch (e) {
3837
- import_log16.log.info("No shell connected.", {}, {
3838
- file: "worker-session.ts",
3839
- line: 138,
3840
- scope: this,
3841
- callSite: (f, a) => f(...a)
3842
- });
3843
- }
3844
- }
3845
- _afterLockReleases(lockKey, callback) {
3846
- return navigator.locks.request(lockKey, () => {
3847
- }).then(callback);
3848
- }
3849
- };
3850
- __decorate5([
3851
- import_log16.logInfo
3852
- ], WorkerSession.prototype, "origin", void 0);
3853
- __decorate5([
3854
- import_log16.logInfo
3855
- ], WorkerSession.prototype, "lockKey", void 0);
3856
-
3857
3389
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3858
- var import_node_assert13 = __toESM(require("node:assert"));
3859
- var import_async22 = require("@dxos/async");
3390
+ var import_node_assert11 = __toESM(require("node:assert"));
3391
+ var import_async17 = require("@dxos/async");
3860
3392
  var import_credentials14 = require("@dxos/credentials");
3861
- var import_debug7 = require("@dxos/debug");
3393
+ var import_debug6 = require("@dxos/debug");
3862
3394
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
3863
3395
  var import_feed_store4 = require("@dxos/feed-store");
3864
3396
  var import_keyring = require("@dxos/keyring");
3865
3397
  var import_keys11 = require("@dxos/keys");
3866
- var import_log18 = require("@dxos/log");
3398
+ var import_log14 = require("@dxos/log");
3867
3399
  var import_protocols8 = require("@dxos/protocols");
3868
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
3400
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
3869
3401
  var ServiceContext = class {
3870
3402
  // prettier-ignore
3871
3403
  constructor(storage, networkManager, signalManager, modelFactory) {
@@ -3873,7 +3405,7 @@ var ServiceContext = class {
3873
3405
  this.networkManager = networkManager;
3874
3406
  this.signalManager = signalManager;
3875
3407
  this.modelFactory = modelFactory;
3876
- this.initialized = new import_async22.Trigger();
3408
+ this.initialized = new import_async17.Trigger();
3877
3409
  this.dataServiceSubscriptions = new import_echo_pipeline3.DataServiceSubscriptions();
3878
3410
  this._handlerFactories = /* @__PURE__ */ new Map();
3879
3411
  this._instanceId = import_keys11.PublicKey.random().toHex();
@@ -3898,13 +3430,13 @@ var ServiceContext = class {
3898
3430
  });
3899
3431
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3900
3432
  this.invitations = new InvitationsHandler(this.networkManager);
3901
- this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3433
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3902
3434
  var _a;
3903
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3435
+ return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
3904
3436
  }, this._acceptIdentity.bind(this)));
3905
3437
  }
3906
3438
  async open() {
3907
- import_log18.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.begin({
3439
+ import_log14.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.begin({
3908
3440
  id: this._instanceId
3909
3441
  }), {
3910
3442
  file: "service-context.ts",
@@ -3913,7 +3445,7 @@ var ServiceContext = class {
3913
3445
  callSite: (f, a) => f(...a)
3914
3446
  });
3915
3447
  await this._checkStorageVersion();
3916
- (0, import_log18.log)("opening...", {}, {
3448
+ (0, import_log14.log)("opening...", {}, {
3917
3449
  file: "service-context.ts",
3918
3450
  line: 123,
3919
3451
  scope: this,
@@ -3926,13 +3458,13 @@ var ServiceContext = class {
3926
3458
  if (this.identityManager.identity) {
3927
3459
  await this._initialize();
3928
3460
  }
3929
- (0, import_log18.log)("opened", {}, {
3461
+ (0, import_log14.log)("opened", {}, {
3930
3462
  file: "service-context.ts",
3931
3463
  line: 131,
3932
3464
  scope: this,
3933
3465
  callSite: (f, a) => f(...a)
3934
3466
  });
3935
- import_log18.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.end({
3467
+ import_log14.log.trace("dxos.sdk.service-context.open", import_protocols8.trace.end({
3936
3468
  id: this._instanceId
3937
3469
  }), {
3938
3470
  file: "service-context.ts",
@@ -3943,7 +3475,7 @@ var ServiceContext = class {
3943
3475
  }
3944
3476
  async close() {
3945
3477
  var _a, _b;
3946
- (0, import_log18.log)("closing...", {}, {
3478
+ (0, import_log14.log)("closing...", {}, {
3947
3479
  file: "service-context.ts",
3948
3480
  line: 136,
3949
3481
  scope: this,
@@ -3957,7 +3489,7 @@ var ServiceContext = class {
3957
3489
  await this.networkManager.close();
3958
3490
  await this.signalManager.close();
3959
3491
  this.dataServiceSubscriptions.clear();
3960
- (0, import_log18.log)("closed", {}, {
3492
+ (0, import_log14.log)("closed", {}, {
3961
3493
  file: "service-context.ts",
3962
3494
  line: 145,
3963
3495
  scope: this,
@@ -3971,7 +3503,7 @@ var ServiceContext = class {
3971
3503
  }
3972
3504
  getInvitationHandler(invitation) {
3973
3505
  const factory = this._handlerFactories.get(invitation.kind);
3974
- (0, import_node_assert13.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3506
+ (0, import_node_assert11.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3975
3507
  return factory(invitation);
3976
3508
  }
3977
3509
  async _acceptIdentity(params) {
@@ -3988,13 +3520,13 @@ var ServiceContext = class {
3988
3520
  // Called when identity is created.
3989
3521
  async _initialize() {
3990
3522
  var _a;
3991
- (0, import_log18.log)("initializing spaces...", {}, {
3523
+ (0, import_log14.log)("initializing spaces...", {}, {
3992
3524
  file: "service-context.ts",
3993
3525
  line: 178,
3994
3526
  scope: this,
3995
3527
  callSite: (f, a) => f(...a)
3996
3528
  });
3997
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3529
+ const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
3998
3530
  const signingContext = {
3999
3531
  credentialSigner: identity.getIdentityCredentialSigner(),
4000
3532
  identityKey: identity.identityKey,
@@ -4010,8 +3542,8 @@ var ServiceContext = class {
4010
3542
  };
4011
3543
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
4012
3544
  await this.dataSpaceManager.open();
4013
- this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4014
- (0, import_node_assert13.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3545
+ this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
3546
+ (0, import_node_assert11.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
4015
3547
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
4016
3548
  });
4017
3549
  this.initialized.wake();
@@ -4025,7 +3557,7 @@ var ServiceContext = class {
4025
3557
  return;
4026
3558
  }
4027
3559
  if (!this.dataSpaceManager) {
4028
- (0, import_log18.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3560
+ (0, import_log14.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4029
3561
  details: assertion
4030
3562
  }, {
4031
3563
  file: "service-context.ts",
@@ -4036,7 +3568,7 @@ var ServiceContext = class {
4036
3568
  return;
4037
3569
  }
4038
3570
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
4039
- (0, import_log18.log)("space already exists, ignoring space admission", {
3571
+ (0, import_log14.log)("space already exists, ignoring space admission", {
4040
3572
  details: assertion
4041
3573
  }, {
4042
3574
  file: "service-context.ts",
@@ -4047,7 +3579,7 @@ var ServiceContext = class {
4047
3579
  return;
4048
3580
  }
4049
3581
  try {
4050
- (0, import_log18.log)("accepting space recorded in halo", {
3582
+ (0, import_log14.log)("accepting space recorded in halo", {
4051
3583
  details: assertion
4052
3584
  }, {
4053
3585
  file: "service-context.ts",
@@ -4060,7 +3592,7 @@ var ServiceContext = class {
4060
3592
  genesisFeedKey: assertion.genesisFeedKey
4061
3593
  });
4062
3594
  } catch (err) {
4063
- import_log18.log.catch(err, {}, {
3595
+ import_log14.log.catch(err, {}, {
4064
3596
  file: "service-context.ts",
4065
3597
  line: 232,
4066
3598
  scope: this,
@@ -4101,7 +3633,7 @@ var ServiceRegistry = class {
4101
3633
  var ClientServicesHost = class {
4102
3634
  constructor({
4103
3635
  config,
4104
- modelFactory = (0, import_client_protocol9.createDefaultModelFactory)(),
3636
+ modelFactory = (0, import_client_protocol4.createDefaultModelFactory)(),
4105
3637
  // TODO(burdon): Create ApolloLink abstraction (see Client).
4106
3638
  transportFactory,
4107
3639
  signalManager,
@@ -4110,7 +3642,7 @@ var ClientServicesHost = class {
4110
3642
  // TODO(wittjosiah): Turn this on by default.
4111
3643
  lockKey
4112
3644
  } = {}) {
4113
- this._statusUpdate = new import_async23.Event();
3645
+ this._statusUpdate = new import_async18.Event();
4114
3646
  this._opening = false;
4115
3647
  this._open = false;
4116
3648
  this._storage = storage;
@@ -4122,24 +3654,26 @@ var ClientServicesHost = class {
4122
3654
  signalManager
4123
3655
  });
4124
3656
  }
4125
- this._resourceLock = lockKey ? new VaultResourceLock({
4126
- lockKey,
4127
- onAcquire: () => {
4128
- if (!this._opening) {
4129
- void this.open();
4130
- }
4131
- },
4132
- onRelease: () => this.close()
4133
- }) : void 0;
3657
+ if (lockKey) {
3658
+ this._resourceLock = new Lock({
3659
+ lockKey,
3660
+ onAcquire: () => {
3661
+ if (!this._opening) {
3662
+ void this.open();
3663
+ }
3664
+ },
3665
+ onRelease: () => this.close()
3666
+ });
3667
+ }
4134
3668
  this._systemService = new SystemServiceImpl({
4135
3669
  config: this._config,
4136
3670
  statusUpdate: this._statusUpdate,
4137
- getCurrentStatus: () => this.isOpen ? import_services13.SystemStatus.ACTIVE : import_services13.SystemStatus.INACTIVE,
3671
+ getCurrentStatus: () => this.isOpen ? import_services11.SystemStatus.ACTIVE : import_services11.SystemStatus.INACTIVE,
4138
3672
  onUpdateStatus: async (status) => {
4139
3673
  var _a, _b;
4140
- if (!this.isOpen && status === import_services13.SystemStatus.ACTIVE) {
3674
+ if (!this.isOpen && status === import_services11.SystemStatus.ACTIVE) {
4141
3675
  await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4142
- } else if (this.isOpen && status === import_services13.SystemStatus.INACTIVE) {
3676
+ } else if (this.isOpen && status === import_services11.SystemStatus.INACTIVE) {
4143
3677
  await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4144
3678
  }
4145
3679
  },
@@ -4148,7 +3682,7 @@ var ClientServicesHost = class {
4148
3682
  }
4149
3683
  });
4150
3684
  this._loggingService = new LoggingServiceImpl();
4151
- this._serviceRegistry = new ServiceRegistry(import_client_protocol9.clientServiceBundle, {
3685
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
4152
3686
  SystemService: this._systemService
4153
3687
  });
4154
3688
  }
@@ -4171,20 +3705,20 @@ var ClientServicesHost = class {
4171
3705
  */
4172
3706
  initialize({ config, ...options }) {
4173
3707
  var _a, _b, _c;
4174
- (0, import_node_assert14.default)(!this._open, "service host is open");
3708
+ (0, import_node_assert12.default)(!this._open, "service host is open");
4175
3709
  if (config) {
4176
- (0, import_node_assert14.default)(!this._config, "config already set");
3710
+ (0, import_node_assert12.default)(!this._config, "config already set");
4177
3711
  this._config = config;
4178
3712
  if (!this._storage) {
4179
3713
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4180
3714
  }
4181
3715
  }
4182
- const { connectionLog = true, transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
3716
+ const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
4183
3717
  iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4184
- }), signalManager = new import_messaging3.WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
3718
+ }), signalManager = new import_messaging.WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4185
3719
  this._signalManager = signalManager;
4186
- (0, import_node_assert14.default)(!this._networkManager, "network manager already set");
4187
- this._networkManager = new import_network_manager5.NetworkManager({
3720
+ (0, import_node_assert12.default)(!this._networkManager, "network manager already set");
3721
+ this._networkManager = new import_network_manager2.NetworkManager({
4188
3722
  log: connectionLog,
4189
3723
  transportFactory,
4190
3724
  signalManager
@@ -4196,7 +3730,7 @@ var ClientServicesHost = class {
4196
3730
  return;
4197
3731
  }
4198
3732
  const traceId = import_keys12.PublicKey.random().toHex();
4199
- import_log19.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.begin({
3733
+ import_log15.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.begin({
4200
3734
  id: traceId
4201
3735
  }), {
4202
3736
  file: "service-host.ts",
@@ -4204,12 +3738,12 @@ var ClientServicesHost = class {
4204
3738
  scope: this,
4205
3739
  callSite: (f, a) => f(...a)
4206
3740
  });
4207
- (0, import_node_assert14.default)(this._config, "config not set");
4208
- (0, import_node_assert14.default)(this._storage, "storage not set");
4209
- (0, import_node_assert14.default)(this._signalManager, "signal manager not set");
4210
- (0, import_node_assert14.default)(this._networkManager, "network manager not set");
3741
+ (0, import_node_assert12.default)(this._config, "config not set");
3742
+ (0, import_node_assert12.default)(this._storage, "storage not set");
3743
+ (0, import_node_assert12.default)(this._signalManager, "signal manager not set");
3744
+ (0, import_node_assert12.default)(this._networkManager, "network manager not set");
4211
3745
  this._opening = true;
4212
- (0, import_log19.log)("opening...", {
3746
+ (0, import_log15.log)("opening...", {
4213
3747
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4214
3748
  }, {
4215
3749
  file: "service-host.ts",
@@ -4244,7 +3778,7 @@ var ClientServicesHost = class {
4244
3778
  this._open = true;
4245
3779
  this._statusUpdate.emit();
4246
3780
  const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4247
- (0, import_log19.log)("opened", {
3781
+ (0, import_log15.log)("opened", {
4248
3782
  deviceKey
4249
3783
  }, {
4250
3784
  file: "service-host.ts",
@@ -4252,7 +3786,7 @@ var ClientServicesHost = class {
4252
3786
  scope: this,
4253
3787
  callSite: (f, a) => f(...a)
4254
3788
  });
4255
- import_log19.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.end({
3789
+ import_log15.log.trace("dxos.sdk.client-services-host.open", import_protocols9.trace.end({
4256
3790
  id: traceId
4257
3791
  }), {
4258
3792
  file: "service-host.ts",
@@ -4267,7 +3801,7 @@ var ClientServicesHost = class {
4267
3801
  return;
4268
3802
  }
4269
3803
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4270
- (0, import_log19.log)("closing...", {
3804
+ (0, import_log15.log)("closing...", {
4271
3805
  deviceKey
4272
3806
  }, {
4273
3807
  file: "service-host.ts",
@@ -4282,7 +3816,7 @@ var ClientServicesHost = class {
4282
3816
  await this._serviceContext.close();
4283
3817
  this._open = false;
4284
3818
  this._statusUpdate.emit();
4285
- (0, import_log19.log)("closed", {
3819
+ (0, import_log15.log)("closed", {
4286
3820
  deviceKey
4287
3821
  }, {
4288
3822
  file: "service-host.ts",
@@ -4294,7 +3828,7 @@ var ClientServicesHost = class {
4294
3828
  async reset() {
4295
3829
  var _a;
4296
3830
  const traceId = import_keys12.PublicKey.random().toHex();
4297
- import_log19.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.begin({
3831
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.begin({
4298
3832
  id: traceId
4299
3833
  }), {
4300
3834
  file: "service-host.ts",
@@ -4302,7 +3836,7 @@ var ClientServicesHost = class {
4302
3836
  scope: this,
4303
3837
  callSite: (f, a) => f(...a)
4304
3838
  });
4305
- (0, import_log19.log)("resetting...", {}, {
3839
+ (0, import_log15.log)("resetting...", {}, {
4306
3840
  file: "service-host.ts",
4307
3841
  line: 273,
4308
3842
  scope: this,
@@ -4310,13 +3844,13 @@ var ClientServicesHost = class {
4310
3844
  });
4311
3845
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4312
3846
  await this._storage.reset();
4313
- (0, import_log19.log)("reset", {}, {
3847
+ (0, import_log15.log)("reset", {}, {
4314
3848
  file: "service-host.ts",
4315
3849
  line: 276,
4316
3850
  scope: this,
4317
3851
  callSite: (f, a) => f(...a)
4318
3852
  });
4319
- import_log19.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.end({
3853
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.end({
4320
3854
  id: traceId
4321
3855
  }), {
4322
3856
  file: "service-host.ts",
@@ -4327,28 +3861,6 @@ var ClientServicesHost = class {
4327
3861
  }
4328
3862
  };
4329
3863
 
4330
- // packages/sdk/client-services/src/packlets/services/local-client-services.ts
4331
- var LocalClientServices = class {
4332
- constructor(params) {
4333
- this._host = new ClientServicesHost(params);
4334
- }
4335
- get descriptors() {
4336
- return this._host.descriptors;
4337
- }
4338
- get services() {
4339
- return this._host.services;
4340
- }
4341
- get host() {
4342
- return this._host;
4343
- }
4344
- async open() {
4345
- await this._host.open();
4346
- }
4347
- async close() {
4348
- await this._host.close();
4349
- }
4350
- };
4351
-
4352
3864
  // packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
4353
3865
  var sanitizeInvitation = (invitation) => {
4354
3866
  return {
@@ -4362,14 +3874,14 @@ var sanitizeInvitation = (invitation) => {
4362
3874
  };
4363
3875
  };
4364
3876
  var performInvitation = ({ host, guest, options, hooks }) => {
4365
- const hostComplete = new import_async24.Trigger();
4366
- const guestComplete = new import_async24.Trigger();
4367
- const authCode = new import_async24.Trigger();
3877
+ const hostComplete = new import_async19.Trigger();
3878
+ const guestComplete = new import_async19.Trigger();
3879
+ const authCode = new import_async19.Trigger();
4368
3880
  const hostObservable = createInvitation(host, options);
4369
3881
  hostObservable.subscribe(async (hostInvitation) => {
4370
3882
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4371
3883
  switch (hostInvitation.state) {
4372
- case import_services14.Invitation.State.CONNECTING: {
3884
+ case import_services12.Invitation.State.CONNECTING: {
4373
3885
  if ((_b = (_a = hooks == null ? void 0 : hooks.host) == null ? void 0 : _a.onConnecting) == null ? void 0 : _b.call(_a, hostObservable)) {
4374
3886
  break;
4375
3887
  }
@@ -4377,29 +3889,29 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4377
3889
  guestObservable.subscribe(async (guestInvitation) => {
4378
3890
  var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
4379
3891
  switch (guestInvitation.state) {
4380
- case import_services14.Invitation.State.CONNECTING: {
3892
+ case import_services12.Invitation.State.CONNECTING: {
4381
3893
  if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onConnecting) == null ? void 0 : _b2.call(_a2, guestObservable)) {
4382
3894
  break;
4383
3895
  }
4384
- (0, import_node_assert15.default)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey));
3896
+ (0, import_node_assert13.default)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey));
4385
3897
  break;
4386
3898
  }
4387
- case import_services14.Invitation.State.CONNECTED: {
3899
+ case import_services12.Invitation.State.CONNECTED: {
4388
3900
  (_d2 = (_c2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _c2.onConnected) == null ? void 0 : _d2.call(_c2, guestObservable);
4389
3901
  break;
4390
3902
  }
4391
- case import_services14.Invitation.State.READY_FOR_AUTHENTICATION: {
3903
+ case import_services12.Invitation.State.READY_FOR_AUTHENTICATION: {
4392
3904
  if ((_f2 = (_e2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _e2.onReady) == null ? void 0 : _f2.call(_e2, guestObservable)) {
4393
3905
  break;
4394
3906
  }
4395
3907
  await guestObservable.authenticate(await authCode.wait());
4396
3908
  break;
4397
3909
  }
4398
- case import_services14.Invitation.State.AUTHENTICATING: {
3910
+ case import_services12.Invitation.State.AUTHENTICATING: {
4399
3911
  (_h2 = (_g2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _g2.onAuthenticating) == null ? void 0 : _h2.call(_g2, guestObservable);
4400
3912
  break;
4401
3913
  }
4402
- case import_services14.Invitation.State.SUCCESS: {
3914
+ case import_services12.Invitation.State.SUCCESS: {
4403
3915
  if ((_j2 = (_i2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _i2.onSuccess) == null ? void 0 : _j2.call(_i2, guestObservable)) {
4404
3916
  break;
4405
3917
  }
@@ -4408,7 +3920,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4408
3920
  });
4409
3921
  break;
4410
3922
  }
4411
- case import_services14.Invitation.State.CANCELLED: {
3923
+ case import_services12.Invitation.State.CANCELLED: {
4412
3924
  if ((_l2 = (_k2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _k2.onCancelled) == null ? void 0 : _l2.call(_k2, guestObservable)) {
4413
3925
  break;
4414
3926
  }
@@ -4417,7 +3929,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4417
3929
  });
4418
3930
  break;
4419
3931
  }
4420
- case import_services14.Invitation.State.TIMEOUT: {
3932
+ case import_services12.Invitation.State.TIMEOUT: {
4421
3933
  if ((_n2 = (_m2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _m2.onTimeout) == null ? void 0 : _n2.call(_m2, guestObservable)) {
4422
3934
  return;
4423
3935
  }
@@ -4437,11 +3949,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4437
3949
  });
4438
3950
  break;
4439
3951
  }
4440
- case import_services14.Invitation.State.CONNECTED: {
3952
+ case import_services12.Invitation.State.CONNECTED: {
4441
3953
  (_d = (_c = hooks == null ? void 0 : hooks.host) == null ? void 0 : _c.onConnected) == null ? void 0 : _d.call(_c, hostObservable);
4442
3954
  break;
4443
3955
  }
4444
- case import_services14.Invitation.State.READY_FOR_AUTHENTICATION: {
3956
+ case import_services12.Invitation.State.READY_FOR_AUTHENTICATION: {
4445
3957
  if ((_f = (_e = hooks == null ? void 0 : hooks.host) == null ? void 0 : _e.onReady) == null ? void 0 : _f.call(_e, hostObservable)) {
4446
3958
  break;
4447
3959
  }
@@ -4450,11 +3962,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4450
3962
  }
4451
3963
  break;
4452
3964
  }
4453
- case import_services14.Invitation.State.AUTHENTICATING: {
3965
+ case import_services12.Invitation.State.AUTHENTICATING: {
4454
3966
  (_h = (_g = hooks == null ? void 0 : hooks.host) == null ? void 0 : _g.onAuthenticating) == null ? void 0 : _h.call(_g, hostObservable);
4455
3967
  break;
4456
3968
  }
4457
- case import_services14.Invitation.State.SUCCESS: {
3969
+ case import_services12.Invitation.State.SUCCESS: {
4458
3970
  if ((_j = (_i = hooks == null ? void 0 : hooks.host) == null ? void 0 : _i.onSuccess) == null ? void 0 : _j.call(_i, hostObservable)) {
4459
3971
  break;
4460
3972
  }
@@ -4463,7 +3975,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4463
3975
  });
4464
3976
  break;
4465
3977
  }
4466
- case import_services14.Invitation.State.CANCELLED: {
3978
+ case import_services12.Invitation.State.CANCELLED: {
4467
3979
  if ((_l = (_k = hooks == null ? void 0 : hooks.host) == null ? void 0 : _k.onCancelled) == null ? void 0 : _l.call(_k, hostObservable)) {
4468
3980
  break;
4469
3981
  }
@@ -4472,7 +3984,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4472
3984
  });
4473
3985
  break;
4474
3986
  }
4475
- case import_services14.Invitation.State.TIMEOUT: {
3987
+ case import_services12.Invitation.State.TIMEOUT: {
4476
3988
  if ((_n = (_m = hooks == null ? void 0 : hooks.host) == null ? void 0 : _m.onTimeout) == null ? void 0 : _n.call(_m, hostObservable)) {
4477
3989
  break;
4478
3990
  }
@@ -4498,12 +4010,12 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4498
4010
  };
4499
4011
  var createInvitation = (host, options) => {
4500
4012
  options != null ? options : options = {
4501
- authMethod: import_services14.Invitation.AuthMethod.NONE,
4013
+ authMethod: import_services12.Invitation.AuthMethod.NONE,
4502
4014
  ...options != null ? options : {}
4503
4015
  };
4504
4016
  if (host instanceof ServiceContext) {
4505
4017
  const hostHandler = host.getInvitationHandler({
4506
- kind: import_services14.Invitation.Kind.SPACE,
4018
+ kind: import_services12.Invitation.Kind.SPACE,
4507
4019
  ...options
4508
4020
  });
4509
4021
  return host.invitations.createInvitation(hostHandler, options);
@@ -4522,36 +4034,36 @@ var acceptInvitation = (guest, invitation) => {
4522
4034
  };
4523
4035
 
4524
4036
  // packages/sdk/client-services/src/packlets/testing/test-builder.ts
4525
- var import_client_protocol10 = require("@dxos/client-protocol");
4037
+ var import_client_protocol5 = require("@dxos/client-protocol");
4526
4038
  var import_context8 = require("@dxos/context");
4527
4039
  var import_credentials15 = require("@dxos/credentials");
4528
4040
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
4529
4041
  var import_testing = require("@dxos/echo-pipeline/testing");
4530
4042
  var import_feed_store5 = require("@dxos/feed-store");
4531
4043
  var import_keyring2 = require("@dxos/keyring");
4532
- var import_messaging4 = require("@dxos/messaging");
4533
- var import_network_manager6 = require("@dxos/network-manager");
4044
+ var import_messaging2 = require("@dxos/messaging");
4045
+ var import_network_manager3 = require("@dxos/network-manager");
4534
4046
  var import_random_access_storage2 = require("@dxos/random-access-storage");
4535
4047
  var createServiceHost = (config, signalManagerContext) => {
4536
4048
  return new ClientServicesHost({
4537
4049
  config,
4538
- signalManager: new import_messaging4.MemorySignalManager(signalManagerContext),
4539
- transportFactory: import_network_manager6.MemoryTransportFactory
4050
+ signalManager: new import_messaging2.MemorySignalManager(signalManagerContext),
4051
+ transportFactory: import_network_manager3.MemoryTransportFactory
4540
4052
  });
4541
4053
  };
4542
- var createServiceContext = ({ signalContext = new import_messaging4.MemorySignalManagerContext(), storage = (0, import_random_access_storage2.createStorage)({
4054
+ var createServiceContext = ({ signalContext = new import_messaging2.MemorySignalManagerContext(), storage = (0, import_random_access_storage2.createStorage)({
4543
4055
  type: import_random_access_storage2.StorageType.RAM
4544
4056
  }) } = {}) => {
4545
- const signalManager = new import_messaging4.MemorySignalManager(signalContext);
4546
- const networkManager = new import_network_manager6.NetworkManager({
4057
+ const signalManager = new import_messaging2.MemorySignalManager(signalContext);
4058
+ const networkManager = new import_network_manager3.NetworkManager({
4547
4059
  signalManager,
4548
- transportFactory: import_network_manager6.MemoryTransportFactory
4060
+ transportFactory: import_network_manager3.MemoryTransportFactory
4549
4061
  });
4550
- const modelFactory = (0, import_client_protocol10.createDefaultModelFactory)();
4062
+ const modelFactory = (0, import_client_protocol5.createDefaultModelFactory)();
4551
4063
  return new ServiceContext(storage, networkManager, signalManager, modelFactory);
4552
4064
  };
4553
4065
  var createPeers = async (numPeers) => {
4554
- const signalContext = new import_messaging4.MemorySignalManagerContext();
4066
+ const signalContext = new import_messaging2.MemorySignalManagerContext();
4555
4067
  return await Promise.all(Array.from(Array(numPeers)).map(async () => {
4556
4068
  const peer = createServiceContext({
4557
4069
  signalContext
@@ -4570,7 +4082,7 @@ var syncItemsLocal = async (db1, db2) => {
4570
4082
  };
4571
4083
  var TestBuilder = class {
4572
4084
  constructor() {
4573
- this.signalContext = new import_messaging4.MemorySignalManagerContext();
4085
+ this.signalContext = new import_messaging2.MemorySignalManagerContext();
4574
4086
  this._ctx = new import_context8.Context();
4575
4087
  }
4576
4088
  createPeer(peerOptions) {
@@ -4622,9 +4134,9 @@ var TestPeer = class {
4622
4134
  }
4623
4135
  get networkManager() {
4624
4136
  var _a, _b;
4625
- return (_b = (_a = this._props).networkManager) != null ? _b : _a.networkManager = new import_network_manager6.NetworkManager({
4626
- signalManager: new import_messaging4.MemorySignalManager(this.signalContext),
4627
- transportFactory: import_network_manager6.MemoryTransportFactory
4137
+ return (_b = (_a = this._props).networkManager) != null ? _b : _a.networkManager = new import_network_manager3.NetworkManager({
4138
+ signalManager: new import_messaging2.MemorySignalManager(this.signalContext),
4139
+ transportFactory: import_network_manager3.MemoryTransportFactory
4628
4140
  });
4629
4141
  }
4630
4142
  get spaceManager() {
@@ -4633,7 +4145,7 @@ var TestPeer = class {
4633
4145
  feedStore: this.feedStore,
4634
4146
  networkManager: this.networkManager,
4635
4147
  metadataStore: this.metadataStore,
4636
- modelFactory: (0, import_client_protocol10.createDefaultModelFactory)(),
4148
+ modelFactory: (0, import_client_protocol5.createDefaultModelFactory)(),
4637
4149
  snapshotStore: this.snapshotStore
4638
4150
  });
4639
4151
  }