@dxos/client-services 0.1.52-main.d3eb45f → 0.1.52-main.e73bc9f

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.
@@ -2072,6 +2072,131 @@ var SpaceInvitationProtocol = class {
2072
2072
  }
2073
2073
  };
2074
2074
 
2075
+ // packages/sdk/client-services/src/packlets/locks/browser.ts
2076
+ import { asyncTimeout, Trigger as Trigger4 } from "@dxos/async";
2077
+ import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
2078
+ import { log as log8, logInfo } from "@dxos/log";
2079
+ var __decorate = function(decorators, target, key, desc) {
2080
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2081
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2082
+ r = Reflect.decorate(decorators, target, key, desc);
2083
+ else
2084
+ for (var i = decorators.length - 1; i >= 0; i--)
2085
+ if (d = decorators[i])
2086
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2087
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2088
+ };
2089
+ var Message;
2090
+ (function(Message2) {
2091
+ Message2["ACQUIRING"] = "acquiring";
2092
+ })(Message || (Message = {}));
2093
+ var Lock = class {
2094
+ constructor({ lockKey, onAcquire, onRelease }) {
2095
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
2096
+ this._releaseTrigger = new Trigger4();
2097
+ this._lockKey = lockKey;
2098
+ this._onAcquire = onAcquire;
2099
+ this._onRelease = onRelease;
2100
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
2101
+ }
2102
+ get lockKey() {
2103
+ return this._lockKey;
2104
+ }
2105
+ async acquire() {
2106
+ this._broadcastChannel.postMessage({
2107
+ message: Message.ACQUIRING
2108
+ });
2109
+ try {
2110
+ log8("aquiring lock...", {}, {
2111
+ file: "browser.ts",
2112
+ line: 42,
2113
+ scope: this,
2114
+ callSite: (f, a) => f(...a)
2115
+ });
2116
+ await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
2117
+ log8("acquired lock", {}, {
2118
+ file: "browser.ts",
2119
+ line: 44,
2120
+ scope: this,
2121
+ callSite: (f, a) => f(...a)
2122
+ });
2123
+ } catch (e) {
2124
+ log8("stealing lock...", {}, {
2125
+ file: "browser.ts",
2126
+ line: 46,
2127
+ scope: this,
2128
+ callSite: (f, a) => f(...a)
2129
+ });
2130
+ await this._requestLock(true);
2131
+ log8("stolen lock", {}, {
2132
+ file: "browser.ts",
2133
+ line: 48,
2134
+ scope: this,
2135
+ callSite: (f, a) => f(...a)
2136
+ });
2137
+ }
2138
+ }
2139
+ async release() {
2140
+ this._releaseTrigger.wake();
2141
+ }
2142
+ _onMessage(event) {
2143
+ if (event.data.message === Message.ACQUIRING) {
2144
+ this._releaseTrigger.wake();
2145
+ }
2146
+ }
2147
+ async _requestLock(steal = false) {
2148
+ log8("requesting lock...", {
2149
+ steal
2150
+ }, {
2151
+ file: "browser.ts",
2152
+ line: 63,
2153
+ scope: this,
2154
+ callSite: (f, a) => f(...a)
2155
+ });
2156
+ const acquired = new Trigger4();
2157
+ void navigator.locks.request(this._lockKey, {
2158
+ steal
2159
+ }, async () => {
2160
+ var _a, _b;
2161
+ await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
2162
+ acquired.wake();
2163
+ this._releaseTrigger = new Trigger4();
2164
+ await this._releaseTrigger.wait();
2165
+ log8("releasing lock...", {}, {
2166
+ file: "browser.ts",
2167
+ line: 72,
2168
+ scope: this,
2169
+ callSite: (f, a) => f(...a)
2170
+ });
2171
+ await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
2172
+ log8("released lock", {}, {
2173
+ file: "browser.ts",
2174
+ line: 74,
2175
+ scope: this,
2176
+ callSite: (f, a) => f(...a)
2177
+ });
2178
+ }).catch(async () => {
2179
+ var _a;
2180
+ await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
2181
+ });
2182
+ await acquired.wait();
2183
+ log8("recieved lock", {
2184
+ steal
2185
+ }, {
2186
+ file: "browser.ts",
2187
+ line: 81,
2188
+ scope: this,
2189
+ callSite: (f, a) => f(...a)
2190
+ });
2191
+ }
2192
+ };
2193
+ __decorate([
2194
+ logInfo
2195
+ ], Lock.prototype, "lockKey", null);
2196
+ var isLocked = (lockPath) => {
2197
+ throw new Error("Not implemented");
2198
+ };
2199
+
2075
2200
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2076
2201
  import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2077
2202
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2080,7 +2205,7 @@ import { timed } from "@dxos/debug";
2080
2205
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2081
2206
  import { CancelledError, SystemError } from "@dxos/errors";
2082
2207
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2083
- import { log as log9 } from "@dxos/log";
2208
+ import { log as log10 } from "@dxos/log";
2084
2209
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2085
2210
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2086
2211
  import { Timeframe } from "@dxos/timeframe";
@@ -2088,10 +2213,10 @@ import { ComplexSet as ComplexSet2 } from "@dxos/util";
2088
2213
 
2089
2214
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2090
2215
  import assert9 from "@dxos/node-std/assert";
2091
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2216
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
2092
2217
  import { Context as Context5, rejectOnDispose } from "@dxos/context";
2093
2218
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2094
- import { log as log8 } from "@dxos/log";
2219
+ import { log as log9 } from "@dxos/log";
2095
2220
  import { schema as schema3 } from "@dxos/protocols";
2096
2221
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2097
2222
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
@@ -2116,7 +2241,7 @@ var NotarizationPlugin = class {
2116
2241
  * Request credentials to be notarized.
2117
2242
  */
2118
2243
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2119
- log8("notarize", {
2244
+ log9("notarize", {
2120
2245
  credentials
2121
2246
  }, {
2122
2247
  file: "notarization-plugin.ts",
@@ -2125,10 +2250,10 @@ var NotarizationPlugin = class {
2125
2250
  callSite: (f, a) => f(...a)
2126
2251
  });
2127
2252
  assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2128
- const errors = new Trigger4();
2253
+ const errors = new Trigger5();
2129
2254
  const ctx = this._ctx.derive({
2130
2255
  onError: (err) => {
2131
- log8.warn("Notarization error", {
2256
+ log9.warn("Notarization error", {
2132
2257
  err
2133
2258
  }, {
2134
2259
  file: "notarization-plugin.ts",
@@ -2143,7 +2268,7 @@ var NotarizationPlugin = class {
2143
2268
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2144
2269
  if (timeout !== 0) {
2145
2270
  scheduleTask3(ctx, () => {
2146
- log8.warn("Notarization timeout", {
2271
+ log9.warn("Notarization timeout", {
2147
2272
  timeout,
2148
2273
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2149
2274
  }, {
@@ -2167,7 +2292,7 @@ var NotarizationPlugin = class {
2167
2292
  ...this._extensions
2168
2293
  ].find((peer2) => !peersTried.has(peer2));
2169
2294
  if (!peer) {
2170
- log8.warn("Exhausted all peers to notarize with", {
2295
+ log9.warn("Exhausted all peers to notarize with", {
2171
2296
  retryIn: retryTimeout
2172
2297
  }, {
2173
2298
  file: "notarization-plugin.ts",
@@ -2180,7 +2305,7 @@ var NotarizationPlugin = class {
2180
2305
  return;
2181
2306
  }
2182
2307
  peersTried.add(peer);
2183
- log8("try notarizing", {
2308
+ log9("try notarizing", {
2184
2309
  peer: peer.localPeerId,
2185
2310
  credentialId: credentials.map((credential) => credential.id)
2186
2311
  }, {
@@ -2192,7 +2317,7 @@ var NotarizationPlugin = class {
2192
2317
  await peer.rpc.NotarizationService.notarize({
2193
2318
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2194
2319
  });
2195
- log8("success", {}, {
2320
+ log9("success", {}, {
2196
2321
  file: "notarization-plugin.ts",
2197
2322
  line: 144,
2198
2323
  scope: this,
@@ -2201,7 +2326,7 @@ var NotarizationPlugin = class {
2201
2326
  await sleep(successDelay);
2202
2327
  } catch (err) {
2203
2328
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2204
- log8.warn("error notarizing (recoverable)", err, {
2329
+ log9.warn("error notarizing (recoverable)", err, {
2205
2330
  file: "notarization-plugin.ts",
2206
2331
  line: 148,
2207
2332
  scope: this,
@@ -2219,7 +2344,7 @@ var NotarizationPlugin = class {
2219
2344
  allNotarized,
2220
2345
  errors.wait()
2221
2346
  ]);
2222
- log8("done", {}, {
2347
+ log9("done", {}, {
2223
2348
  file: "notarization-plugin.ts",
2224
2349
  line: 159,
2225
2350
  scope: this,
@@ -2249,7 +2374,7 @@ var NotarizationPlugin = class {
2249
2374
  if (this._processedCredentials.has(id)) {
2250
2375
  return;
2251
2376
  }
2252
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
2377
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger5()).value.wait();
2253
2378
  }
2254
2379
  /**
2255
2380
  * Requests from other peers to notarize credentials.
@@ -2270,7 +2395,7 @@ var NotarizationPlugin = class {
2270
2395
  createExtension() {
2271
2396
  const extension = new NotarizationTeleportExtension({
2272
2397
  onOpen: async () => {
2273
- log8("extension opened", {
2398
+ log9("extension opened", {
2274
2399
  peer: extension.localPeerId
2275
2400
  }, {
2276
2401
  file: "notarization-plugin.ts",
@@ -2282,7 +2407,7 @@ var NotarizationPlugin = class {
2282
2407
  this._extensionOpened.emit();
2283
2408
  },
2284
2409
  onClose: async () => {
2285
- log8("extension closed", {
2410
+ log9("extension closed", {
2286
2411
  peer: extension.localPeerId
2287
2412
  }, {
2288
2413
  file: "notarization-plugin.ts",
@@ -2329,7 +2454,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2329
2454
  };
2330
2455
 
2331
2456
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2332
- var __decorate = function(decorators, target, key, desc) {
2457
+ var __decorate2 = function(decorators, target, key, desc) {
2333
2458
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2334
2459
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2335
2460
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2424,7 +2549,7 @@ var DataSpace = class DataSpace2 {
2424
2549
  await this.initializeDataPipeline();
2425
2550
  } catch (err) {
2426
2551
  if (err instanceof CancelledError) {
2427
- log9("Data pipeline initialization cancelled", err, {
2552
+ log10("Data pipeline initialization cancelled", err, {
2428
2553
  file: "data-space.ts",
2429
2554
  line: 173,
2430
2555
  scope: this,
@@ -2432,7 +2557,7 @@ var DataSpace = class DataSpace2 {
2432
2557
  });
2433
2558
  return;
2434
2559
  }
2435
- log9.error("Error initializing data pipeline", err, {
2560
+ log10.error("Error initializing data pipeline", err, {
2436
2561
  file: "data-space.ts",
2437
2562
  line: 177,
2438
2563
  scope: this,
@@ -2458,7 +2583,7 @@ var DataSpace = class DataSpace2 {
2458
2583
  });
2459
2584
  this.metrics.controlPipelineReady = new Date();
2460
2585
  await this._createWritableFeeds();
2461
- log9("Writable feeds created", {}, {
2586
+ log10("Writable feeds created", {}, {
2462
2587
  file: "data-space.ts",
2463
2588
  line: 201,
2464
2589
  scope: this,
@@ -2473,7 +2598,7 @@ var DataSpace = class DataSpace2 {
2473
2598
  await this._inner.initializeDataPipeline();
2474
2599
  this.metrics.dataPipelineOpen = new Date();
2475
2600
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2476
- log9("waiting for data pipeline to reach target timeframe", {}, {
2601
+ log10("waiting for data pipeline to reach target timeframe", {}, {
2477
2602
  file: "data-space.ts",
2478
2603
  line: 220,
2479
2604
  scope: this,
@@ -2484,7 +2609,7 @@ var DataSpace = class DataSpace2 {
2484
2609
  breakOnStall: false
2485
2610
  });
2486
2611
  this.metrics.dataPipelineReady = new Date();
2487
- log9("data pipeline ready", {}, {
2612
+ log10("data pipeline ready", {}, {
2488
2613
  file: "data-space.ts",
2489
2614
  line: 229,
2490
2615
  scope: this,
@@ -2567,10 +2692,10 @@ var DataSpace = class DataSpace2 {
2567
2692
  }
2568
2693
  }
2569
2694
  };
2570
- __decorate([
2695
+ __decorate2([
2571
2696
  timed(1e4)
2572
2697
  ], DataSpace.prototype, "_createWritableFeeds", null);
2573
- DataSpace = __decorate([
2698
+ DataSpace = __decorate2([
2574
2699
  trackLeaks("open", "close")
2575
2700
  ], DataSpace);
2576
2701
 
@@ -2580,7 +2705,7 @@ import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/
2580
2705
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2581
2706
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2582
2707
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2583
- import { log as log10 } from "@dxos/log";
2708
+ import { log as log11 } from "@dxos/log";
2584
2709
  import { trace as trace4 } from "@dxos/protocols";
2585
2710
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2586
2711
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
@@ -2657,7 +2782,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2657
2782
  };
2658
2783
 
2659
2784
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2660
- var __decorate2 = function(decorators, target, key, desc) {
2785
+ var __decorate3 = function(decorators, target, key, desc) {
2661
2786
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2662
2787
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2663
2788
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2686,13 +2811,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2686
2811
  return this._spaces;
2687
2812
  }
2688
2813
  async open() {
2689
- log10("open", {}, {
2814
+ log11("open", {}, {
2690
2815
  file: "data-space-manager.ts",
2691
2816
  line: 80,
2692
2817
  scope: this,
2693
2818
  callSite: (f, a) => f(...a)
2694
2819
  });
2695
- log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
2820
+ log11.trace("dxos.echo.data-space-manager.open", trace4.begin({
2696
2821
  id: this._instanceId
2697
2822
  }), {
2698
2823
  file: "data-space-manager.ts",
@@ -2701,7 +2826,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2701
2826
  callSite: (f, a) => f(...a)
2702
2827
  });
2703
2828
  await this._metadataStore.load();
2704
- log10("metadata loaded", {
2829
+ log11("metadata loaded", {
2705
2830
  spaces: this._metadataStore.spaces.length
2706
2831
  }, {
2707
2832
  file: "data-space-manager.ts",
@@ -2711,7 +2836,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2711
2836
  });
2712
2837
  for (const spaceMetadata of this._metadataStore.spaces) {
2713
2838
  try {
2714
- log10("load space", {
2839
+ log11("load space", {
2715
2840
  spaceMetadata
2716
2841
  }, {
2717
2842
  file: "data-space-manager.ts",
@@ -2722,7 +2847,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2722
2847
  const space = await this._constructSpace(spaceMetadata);
2723
2848
  space.initializeDataPipelineAsync();
2724
2849
  } catch (err) {
2725
- log10.error("Error loading space", {
2850
+ log11.error("Error loading space", {
2726
2851
  spaceMetadata,
2727
2852
  err
2728
2853
  }, {
@@ -2735,7 +2860,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2735
2860
  }
2736
2861
  this._isOpen = true;
2737
2862
  this.updated.emit();
2738
- log10.trace("dxos.echo.data-space-manager.open", trace4.end({
2863
+ log11.trace("dxos.echo.data-space-manager.open", trace4.end({
2739
2864
  id: this._instanceId
2740
2865
  }), {
2741
2866
  file: "data-space-manager.ts",
@@ -2745,7 +2870,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2745
2870
  });
2746
2871
  }
2747
2872
  async close() {
2748
- log10("close", {}, {
2873
+ log11("close", {}, {
2749
2874
  file: "data-space-manager.ts",
2750
2875
  line: 102,
2751
2876
  scope: this,
@@ -2771,7 +2896,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2771
2896
  controlFeedKey,
2772
2897
  dataFeedKey
2773
2898
  };
2774
- log10("creating space...", {
2899
+ log11("creating space...", {
2775
2900
  spaceKey
2776
2901
  }, {
2777
2902
  file: "data-space-manager.ts",
@@ -2791,7 +2916,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2791
2916
  }
2792
2917
  // TODO(burdon): Rename join space.
2793
2918
  async acceptSpace(opts) {
2794
- log10("accept space", {
2919
+ log11("accept space", {
2795
2920
  opts
2796
2921
  }, {
2797
2922
  file: "data-space-manager.ts",
@@ -2825,7 +2950,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2825
2950
  }));
2826
2951
  }
2827
2952
  async _constructSpace(metadata) {
2828
- log10("construct space", {
2953
+ log11("construct space", {
2829
2954
  metadata
2830
2955
  }, {
2831
2956
  file: "data-space-manager.ts",
@@ -2863,7 +2988,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2863
2988
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2864
2989
  },
2865
2990
  onAuthFailure: () => {
2866
- log10.warn("auth failure", {}, {
2991
+ log11.warn("auth failure", {}, {
2867
2992
  file: "data-space-manager.ts",
2868
2993
  line: 212,
2869
2994
  scope: this,
@@ -2884,7 +3009,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2884
3009
  signingContext: this._signingContext,
2885
3010
  callbacks: {
2886
3011
  beforeReady: async () => {
2887
- log10("before space ready", {
3012
+ log11("before space ready", {
2888
3013
  space: space.key
2889
3014
  }, {
2890
3015
  file: "data-space-manager.ts",
@@ -2895,7 +3020,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2895
3020
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2896
3021
  },
2897
3022
  afterReady: async () => {
2898
- log10("after space ready", {
3023
+ log11("after space ready", {
2899
3024
  space: space.key,
2900
3025
  open: this._isOpen
2901
3026
  }, {
@@ -2922,19 +3047,19 @@ var DataSpaceManager = class DataSpaceManager2 {
2922
3047
  return dataSpace;
2923
3048
  }
2924
3049
  };
2925
- __decorate2([
3050
+ __decorate3([
2926
3051
  synchronized
2927
3052
  ], DataSpaceManager.prototype, "open", null);
2928
- __decorate2([
3053
+ __decorate3([
2929
3054
  synchronized
2930
3055
  ], DataSpaceManager.prototype, "close", null);
2931
- __decorate2([
3056
+ __decorate3([
2932
3057
  synchronized
2933
3058
  ], DataSpaceManager.prototype, "createSpace", null);
2934
- __decorate2([
3059
+ __decorate3([
2935
3060
  synchronized
2936
3061
  ], DataSpaceManager.prototype, "acceptSpace", null);
2937
- DataSpaceManager = __decorate2([
3062
+ DataSpaceManager = __decorate3([
2938
3063
  trackLeaks2("open", "close")
2939
3064
  ], DataSpaceManager);
2940
3065
 
@@ -2943,7 +3068,7 @@ import { EventSubscriptions as EventSubscriptions2, scheduleTask as scheduleTask
2943
3068
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
2944
3069
  import { raise, todo as todo2 } from "@dxos/debug";
2945
3070
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
2946
- import { log as log11 } from "@dxos/log";
3071
+ import { log as log12 } from "@dxos/log";
2947
3072
  import { encodeError } from "@dxos/protocols";
2948
3073
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
2949
3074
  import { humanize } from "@dxos/util";
@@ -2971,7 +3096,7 @@ var SpacesServiceImpl = class {
2971
3096
  const onUpdate = async () => {
2972
3097
  const dataSpaceManager = await this._getDataSpaceManager();
2973
3098
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2974
- log11("update", {
3099
+ log12("update", {
2975
3100
  spaces
2976
3101
  }, {
2977
3102
  file: "spaces-service.ts",
@@ -3101,16 +3226,65 @@ var SpacesServiceImpl = class {
3101
3226
  };
3102
3227
  var getChannelId = (channel) => `user-channel/${channel}`;
3103
3228
 
3229
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
3230
+ import { DX_DATA } from "@dxos/client-protocol";
3231
+ import { InvalidConfigError } from "@dxos/errors";
3232
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
3233
+ import { createStorage, StorageType } from "@dxos/random-access-storage";
3234
+ import { isNode } from "@dxos/util";
3235
+ var StorageDriver = Runtime.Client.Storage.StorageDriver;
3236
+ var createStorageObjects = (config) => {
3237
+ const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
3238
+ if (persistent && storageType === StorageDriver.RAM) {
3239
+ throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
3240
+ }
3241
+ if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
3242
+ throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3243
+ }
3244
+ if (persistent && keyStorage === StorageDriver.RAM) {
3245
+ throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3246
+ }
3247
+ if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
3248
+ throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3249
+ }
3250
+ return {
3251
+ storage: createStorage({
3252
+ type: persistent ? toStorageType(storageType) : StorageType.RAM,
3253
+ root: `${path}/`
3254
+ })
3255
+ };
3256
+ };
3257
+ var toStorageType = (type) => {
3258
+ switch (type) {
3259
+ case void 0:
3260
+ return void 0;
3261
+ case StorageDriver.RAM:
3262
+ return StorageType.RAM;
3263
+ case StorageDriver.CHROME:
3264
+ return StorageType.CHROME;
3265
+ case StorageDriver.FIREFOX:
3266
+ return StorageType.FIREFOX;
3267
+ case StorageDriver.IDB:
3268
+ return StorageType.IDB;
3269
+ case StorageDriver.NODE:
3270
+ return StorageType.NODE;
3271
+ case StorageDriver.WEBFS:
3272
+ return StorageType.WEBFS;
3273
+ default:
3274
+ throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
3275
+ }
3276
+ };
3277
+
3104
3278
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3105
3279
  import assert11 from "@dxos/node-std/assert";
3106
- import { Trigger as Trigger5 } from "@dxos/async";
3280
+ import { Trigger as Trigger6 } from "@dxos/async";
3107
3281
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3108
3282
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3109
3283
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3110
3284
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3111
3285
  import { Keyring } from "@dxos/keyring";
3112
3286
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3113
- import { log as log12 } from "@dxos/log";
3287
+ import { log as log13 } from "@dxos/log";
3114
3288
  import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3115
3289
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3116
3290
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -3121,7 +3295,7 @@ var ServiceContext = class {
3121
3295
  this.networkManager = networkManager;
3122
3296
  this.signalManager = signalManager;
3123
3297
  this.modelFactory = modelFactory;
3124
- this.initialized = new Trigger5();
3298
+ this.initialized = new Trigger6();
3125
3299
  this.dataServiceSubscriptions = new DataServiceSubscriptions();
3126
3300
  this._handlerFactories = /* @__PURE__ */ new Map();
3127
3301
  this._instanceId = PublicKey9.random().toHex();
@@ -3154,7 +3328,7 @@ var ServiceContext = class {
3154
3328
  }, this._acceptIdentity.bind(this)));
3155
3329
  }
3156
3330
  async open() {
3157
- log12.trace("dxos.sdk.service-context.open", trace5.begin({
3331
+ log13.trace("dxos.sdk.service-context.open", trace5.begin({
3158
3332
  id: this._instanceId
3159
3333
  }), {
3160
3334
  file: "service-context.ts",
@@ -3163,7 +3337,7 @@ var ServiceContext = class {
3163
3337
  callSite: (f, a) => f(...a)
3164
3338
  });
3165
3339
  await this._checkStorageVersion();
3166
- log12("opening...", {}, {
3340
+ log13("opening...", {}, {
3167
3341
  file: "service-context.ts",
3168
3342
  line: 130,
3169
3343
  scope: this,
@@ -3176,13 +3350,13 @@ var ServiceContext = class {
3176
3350
  if (this.identityManager.identity) {
3177
3351
  await this._initialize();
3178
3352
  }
3179
- log12("opened", {}, {
3353
+ log13("opened", {}, {
3180
3354
  file: "service-context.ts",
3181
3355
  line: 138,
3182
3356
  scope: this,
3183
3357
  callSite: (f, a) => f(...a)
3184
3358
  });
3185
- log12.trace("dxos.sdk.service-context.open", trace5.end({
3359
+ log13.trace("dxos.sdk.service-context.open", trace5.end({
3186
3360
  id: this._instanceId
3187
3361
  }), {
3188
3362
  file: "service-context.ts",
@@ -3193,7 +3367,7 @@ var ServiceContext = class {
3193
3367
  }
3194
3368
  async close() {
3195
3369
  var _a, _b;
3196
- log12("closing...", {}, {
3370
+ log13("closing...", {}, {
3197
3371
  file: "service-context.ts",
3198
3372
  line: 143,
3199
3373
  scope: this,
@@ -3207,7 +3381,7 @@ var ServiceContext = class {
3207
3381
  await this.networkManager.close();
3208
3382
  await this.signalManager.close();
3209
3383
  this.dataServiceSubscriptions.clear();
3210
- log12("closed", {}, {
3384
+ log13("closed", {}, {
3211
3385
  file: "service-context.ts",
3212
3386
  line: 152,
3213
3387
  scope: this,
@@ -3238,7 +3412,7 @@ var ServiceContext = class {
3238
3412
  // Called when identity is created.
3239
3413
  async _initialize() {
3240
3414
  var _a;
3241
- log12("initializing spaces...", {}, {
3415
+ log13("initializing spaces...", {}, {
3242
3416
  file: "service-context.ts",
3243
3417
  line: 185,
3244
3418
  scope: this,
@@ -3275,7 +3449,7 @@ var ServiceContext = class {
3275
3449
  return;
3276
3450
  }
3277
3451
  if (!this.dataSpaceManager) {
3278
- log12("dataSpaceManager not initialized yet, ignoring space admission", {
3452
+ log13("dataSpaceManager not initialized yet, ignoring space admission", {
3279
3453
  details: assertion
3280
3454
  }, {
3281
3455
  file: "service-context.ts",
@@ -3286,7 +3460,7 @@ var ServiceContext = class {
3286
3460
  return;
3287
3461
  }
3288
3462
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3289
- log12("space already exists, ignoring space admission", {
3463
+ log13("space already exists, ignoring space admission", {
3290
3464
  details: assertion
3291
3465
  }, {
3292
3466
  file: "service-context.ts",
@@ -3297,7 +3471,7 @@ var ServiceContext = class {
3297
3471
  return;
3298
3472
  }
3299
3473
  try {
3300
- log12("accepting space recorded in halo", {
3474
+ log13("accepting space recorded in halo", {
3301
3475
  details: assertion
3302
3476
  }, {
3303
3477
  file: "service-context.ts",
@@ -3310,7 +3484,7 @@ var ServiceContext = class {
3310
3484
  genesisFeedKey: assertion.genesisFeedKey
3311
3485
  });
3312
3486
  } catch (err) {
3313
- log12.catch(err, {}, {
3487
+ log13.catch(err, {}, {
3314
3488
  file: "service-context.ts",
3315
3489
  line: 239,
3316
3490
  scope: this,
@@ -3323,180 +3497,6 @@ var ServiceContext = class {
3323
3497
  }
3324
3498
  };
3325
3499
 
3326
- // packages/sdk/client-services/src/packlets/locks/browser.ts
3327
- import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3328
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3329
- import { log as log13, logInfo } from "@dxos/log";
3330
- var __decorate3 = function(decorators, target, key, desc) {
3331
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3332
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3333
- r = Reflect.decorate(decorators, target, key, desc);
3334
- else
3335
- for (var i = decorators.length - 1; i >= 0; i--)
3336
- if (d = decorators[i])
3337
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3338
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3339
- };
3340
- var Message;
3341
- (function(Message2) {
3342
- Message2["ACQUIRING"] = "acquiring";
3343
- })(Message || (Message = {}));
3344
- var Lock = class {
3345
- constructor({ lockKey, onAcquire, onRelease }) {
3346
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3347
- this._releaseTrigger = new Trigger6();
3348
- this._lockKey = lockKey;
3349
- this._onAcquire = onAcquire;
3350
- this._onRelease = onRelease;
3351
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
3352
- }
3353
- get lockKey() {
3354
- return this._lockKey;
3355
- }
3356
- async acquire() {
3357
- this._broadcastChannel.postMessage({
3358
- message: Message.ACQUIRING
3359
- });
3360
- try {
3361
- log13("aquiring lock...", {}, {
3362
- file: "browser.ts",
3363
- line: 42,
3364
- scope: this,
3365
- callSite: (f, a) => f(...a)
3366
- });
3367
- await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3368
- log13("acquired lock", {}, {
3369
- file: "browser.ts",
3370
- line: 44,
3371
- scope: this,
3372
- callSite: (f, a) => f(...a)
3373
- });
3374
- } catch (e) {
3375
- log13("stealing lock...", {}, {
3376
- file: "browser.ts",
3377
- line: 46,
3378
- scope: this,
3379
- callSite: (f, a) => f(...a)
3380
- });
3381
- await this._requestLock(true);
3382
- log13("stolen lock", {}, {
3383
- file: "browser.ts",
3384
- line: 48,
3385
- scope: this,
3386
- callSite: (f, a) => f(...a)
3387
- });
3388
- }
3389
- }
3390
- async release() {
3391
- this._releaseTrigger.wake();
3392
- }
3393
- _onMessage(event) {
3394
- if (event.data.message === Message.ACQUIRING) {
3395
- this._releaseTrigger.wake();
3396
- }
3397
- }
3398
- async _requestLock(steal = false) {
3399
- log13("requesting lock...", {
3400
- steal
3401
- }, {
3402
- file: "browser.ts",
3403
- line: 63,
3404
- scope: this,
3405
- callSite: (f, a) => f(...a)
3406
- });
3407
- const acquired = new Trigger6();
3408
- void navigator.locks.request(this._lockKey, {
3409
- steal
3410
- }, async () => {
3411
- var _a, _b;
3412
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3413
- acquired.wake();
3414
- this._releaseTrigger = new Trigger6();
3415
- await this._releaseTrigger.wait();
3416
- log13("releasing lock...", {}, {
3417
- file: "browser.ts",
3418
- line: 72,
3419
- scope: this,
3420
- callSite: (f, a) => f(...a)
3421
- });
3422
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3423
- log13("released lock", {}, {
3424
- file: "browser.ts",
3425
- line: 74,
3426
- scope: this,
3427
- callSite: (f, a) => f(...a)
3428
- });
3429
- }).catch(async () => {
3430
- var _a;
3431
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3432
- });
3433
- await acquired.wait();
3434
- log13("recieved lock", {
3435
- steal
3436
- }, {
3437
- file: "browser.ts",
3438
- line: 81,
3439
- scope: this,
3440
- callSite: (f, a) => f(...a)
3441
- });
3442
- }
3443
- };
3444
- __decorate3([
3445
- logInfo
3446
- ], Lock.prototype, "lockKey", null);
3447
- var isLocked = (lockPath) => {
3448
- throw new Error("Not implemented");
3449
- };
3450
-
3451
- // packages/sdk/client-services/src/packlets/storage/storage.ts
3452
- import { DX_DATA } from "@dxos/client-protocol";
3453
- import { InvalidConfigError } from "@dxos/errors";
3454
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
3455
- import { createStorage, StorageType } from "@dxos/random-access-storage";
3456
- import { isNode } from "@dxos/util";
3457
- var StorageDriver = Runtime.Client.Storage.StorageDriver;
3458
- var createStorageObjects = (config) => {
3459
- const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
3460
- if (persistent && storageType === StorageDriver.RAM) {
3461
- throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
3462
- }
3463
- if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
3464
- throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3465
- }
3466
- if (persistent && keyStorage === StorageDriver.RAM) {
3467
- throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3468
- }
3469
- if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
3470
- throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3471
- }
3472
- return {
3473
- storage: createStorage({
3474
- type: persistent ? toStorageType(storageType) : StorageType.RAM,
3475
- root: `${path}/`
3476
- })
3477
- };
3478
- };
3479
- var toStorageType = (type) => {
3480
- switch (type) {
3481
- case void 0:
3482
- return void 0;
3483
- case StorageDriver.RAM:
3484
- return StorageType.RAM;
3485
- case StorageDriver.CHROME:
3486
- return StorageType.CHROME;
3487
- case StorageDriver.FIREFOX:
3488
- return StorageType.FIREFOX;
3489
- case StorageDriver.IDB:
3490
- return StorageType.IDB;
3491
- case StorageDriver.NODE:
3492
- return StorageType.NODE;
3493
- case StorageDriver.WEBFS:
3494
- return StorageType.WEBFS;
3495
- default:
3496
- throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
3497
- }
3498
- };
3499
-
3500
3500
  // packages/sdk/client-services/src/packlets/services/service-registry.ts
3501
3501
  var ServiceRegistry = class {
3502
3502
  // prettier-ignore
@@ -3958,6 +3958,28 @@ var ClientServicesHost = class {
3958
3958
  }
3959
3959
  };
3960
3960
 
3961
+ // packages/sdk/client-services/src/packlets/services/local-client-services.ts
3962
+ var LocalClientServices = class {
3963
+ constructor(params) {
3964
+ this._host = new ClientServicesHost(params);
3965
+ }
3966
+ get descriptors() {
3967
+ return this._host.descriptors;
3968
+ }
3969
+ get services() {
3970
+ return this._host.services;
3971
+ }
3972
+ get host() {
3973
+ return this._host;
3974
+ }
3975
+ async open() {
3976
+ await this._host.open();
3977
+ }
3978
+ async close() {
3979
+ await this._host.close();
3980
+ }
3981
+ };
3982
+
3961
3983
  export {
3962
3984
  subscribeToFeeds,
3963
3985
  subscribeToFeedBlocks,
@@ -3978,14 +4000,15 @@ export {
3978
4000
  InvitationsHandler,
3979
4001
  InvitationsServiceImpl,
3980
4002
  SpaceInvitationProtocol,
4003
+ Lock,
4004
+ isLocked,
3981
4005
  DataSpace,
3982
4006
  DataSpaceManager,
3983
4007
  SpacesServiceImpl,
3984
- ServiceContext,
3985
- Lock,
3986
- isLocked,
3987
4008
  createStorageObjects,
4009
+ ServiceContext,
3988
4010
  ServiceRegistry,
3989
- ClientServicesHost
4011
+ ClientServicesHost,
4012
+ LocalClientServices
3990
4013
  };
3991
- //# sourceMappingURL=chunk-C3SPTMW3.mjs.map
4014
+ //# sourceMappingURL=chunk-2GQ7337P.mjs.map