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

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,131 +2072,6 @@ 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
-
2200
2075
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2201
2076
  import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2202
2077
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2205,7 +2080,7 @@ import { timed } from "@dxos/debug";
2205
2080
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2206
2081
  import { CancelledError, SystemError } from "@dxos/errors";
2207
2082
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2208
- import { log as log10 } from "@dxos/log";
2083
+ import { log as log9 } from "@dxos/log";
2209
2084
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2210
2085
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2211
2086
  import { Timeframe } from "@dxos/timeframe";
@@ -2213,10 +2088,10 @@ import { ComplexSet as ComplexSet2 } from "@dxos/util";
2213
2088
 
2214
2089
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2215
2090
  import assert9 from "@dxos/node-std/assert";
2216
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
2091
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2217
2092
  import { Context as Context5, rejectOnDispose } from "@dxos/context";
2218
2093
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2219
- import { log as log9 } from "@dxos/log";
2094
+ import { log as log8 } from "@dxos/log";
2220
2095
  import { schema as schema3 } from "@dxos/protocols";
2221
2096
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2222
2097
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
@@ -2241,7 +2116,7 @@ var NotarizationPlugin = class {
2241
2116
  * Request credentials to be notarized.
2242
2117
  */
2243
2118
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2244
- log9("notarize", {
2119
+ log8("notarize", {
2245
2120
  credentials
2246
2121
  }, {
2247
2122
  file: "notarization-plugin.ts",
@@ -2250,10 +2125,10 @@ var NotarizationPlugin = class {
2250
2125
  callSite: (f, a) => f(...a)
2251
2126
  });
2252
2127
  assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2253
- const errors = new Trigger5();
2128
+ const errors = new Trigger4();
2254
2129
  const ctx = this._ctx.derive({
2255
2130
  onError: (err) => {
2256
- log9.warn("Notarization error", {
2131
+ log8.warn("Notarization error", {
2257
2132
  err
2258
2133
  }, {
2259
2134
  file: "notarization-plugin.ts",
@@ -2268,7 +2143,7 @@ var NotarizationPlugin = class {
2268
2143
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2269
2144
  if (timeout !== 0) {
2270
2145
  scheduleTask3(ctx, () => {
2271
- log9.warn("Notarization timeout", {
2146
+ log8.warn("Notarization timeout", {
2272
2147
  timeout,
2273
2148
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2274
2149
  }, {
@@ -2292,7 +2167,7 @@ var NotarizationPlugin = class {
2292
2167
  ...this._extensions
2293
2168
  ].find((peer2) => !peersTried.has(peer2));
2294
2169
  if (!peer) {
2295
- log9.warn("Exhausted all peers to notarize with", {
2170
+ log8.warn("Exhausted all peers to notarize with", {
2296
2171
  retryIn: retryTimeout
2297
2172
  }, {
2298
2173
  file: "notarization-plugin.ts",
@@ -2305,7 +2180,7 @@ var NotarizationPlugin = class {
2305
2180
  return;
2306
2181
  }
2307
2182
  peersTried.add(peer);
2308
- log9("try notarizing", {
2183
+ log8("try notarizing", {
2309
2184
  peer: peer.localPeerId,
2310
2185
  credentialId: credentials.map((credential) => credential.id)
2311
2186
  }, {
@@ -2317,7 +2192,7 @@ var NotarizationPlugin = class {
2317
2192
  await peer.rpc.NotarizationService.notarize({
2318
2193
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2319
2194
  });
2320
- log9("success", {}, {
2195
+ log8("success", {}, {
2321
2196
  file: "notarization-plugin.ts",
2322
2197
  line: 144,
2323
2198
  scope: this,
@@ -2326,7 +2201,7 @@ var NotarizationPlugin = class {
2326
2201
  await sleep(successDelay);
2327
2202
  } catch (err) {
2328
2203
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2329
- log9.warn("error notarizing (recoverable)", err, {
2204
+ log8.warn("error notarizing (recoverable)", err, {
2330
2205
  file: "notarization-plugin.ts",
2331
2206
  line: 148,
2332
2207
  scope: this,
@@ -2344,7 +2219,7 @@ var NotarizationPlugin = class {
2344
2219
  allNotarized,
2345
2220
  errors.wait()
2346
2221
  ]);
2347
- log9("done", {}, {
2222
+ log8("done", {}, {
2348
2223
  file: "notarization-plugin.ts",
2349
2224
  line: 159,
2350
2225
  scope: this,
@@ -2374,7 +2249,7 @@ var NotarizationPlugin = class {
2374
2249
  if (this._processedCredentials.has(id)) {
2375
2250
  return;
2376
2251
  }
2377
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger5()).value.wait();
2252
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
2378
2253
  }
2379
2254
  /**
2380
2255
  * Requests from other peers to notarize credentials.
@@ -2395,7 +2270,7 @@ var NotarizationPlugin = class {
2395
2270
  createExtension() {
2396
2271
  const extension = new NotarizationTeleportExtension({
2397
2272
  onOpen: async () => {
2398
- log9("extension opened", {
2273
+ log8("extension opened", {
2399
2274
  peer: extension.localPeerId
2400
2275
  }, {
2401
2276
  file: "notarization-plugin.ts",
@@ -2407,7 +2282,7 @@ var NotarizationPlugin = class {
2407
2282
  this._extensionOpened.emit();
2408
2283
  },
2409
2284
  onClose: async () => {
2410
- log9("extension closed", {
2285
+ log8("extension closed", {
2411
2286
  peer: extension.localPeerId
2412
2287
  }, {
2413
2288
  file: "notarization-plugin.ts",
@@ -2454,7 +2329,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2454
2329
  };
2455
2330
 
2456
2331
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2457
- var __decorate2 = function(decorators, target, key, desc) {
2332
+ var __decorate = function(decorators, target, key, desc) {
2458
2333
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2459
2334
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2460
2335
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2549,7 +2424,7 @@ var DataSpace = class DataSpace2 {
2549
2424
  await this.initializeDataPipeline();
2550
2425
  } catch (err) {
2551
2426
  if (err instanceof CancelledError) {
2552
- log10("Data pipeline initialization cancelled", err, {
2427
+ log9("Data pipeline initialization cancelled", err, {
2553
2428
  file: "data-space.ts",
2554
2429
  line: 173,
2555
2430
  scope: this,
@@ -2557,7 +2432,7 @@ var DataSpace = class DataSpace2 {
2557
2432
  });
2558
2433
  return;
2559
2434
  }
2560
- log10.error("Error initializing data pipeline", err, {
2435
+ log9.error("Error initializing data pipeline", err, {
2561
2436
  file: "data-space.ts",
2562
2437
  line: 177,
2563
2438
  scope: this,
@@ -2583,7 +2458,7 @@ var DataSpace = class DataSpace2 {
2583
2458
  });
2584
2459
  this.metrics.controlPipelineReady = new Date();
2585
2460
  await this._createWritableFeeds();
2586
- log10("Writable feeds created", {}, {
2461
+ log9("Writable feeds created", {}, {
2587
2462
  file: "data-space.ts",
2588
2463
  line: 201,
2589
2464
  scope: this,
@@ -2598,7 +2473,7 @@ var DataSpace = class DataSpace2 {
2598
2473
  await this._inner.initializeDataPipeline();
2599
2474
  this.metrics.dataPipelineOpen = new Date();
2600
2475
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2601
- log10("waiting for data pipeline to reach target timeframe", {}, {
2476
+ log9("waiting for data pipeline to reach target timeframe", {}, {
2602
2477
  file: "data-space.ts",
2603
2478
  line: 220,
2604
2479
  scope: this,
@@ -2609,7 +2484,7 @@ var DataSpace = class DataSpace2 {
2609
2484
  breakOnStall: false
2610
2485
  });
2611
2486
  this.metrics.dataPipelineReady = new Date();
2612
- log10("data pipeline ready", {}, {
2487
+ log9("data pipeline ready", {}, {
2613
2488
  file: "data-space.ts",
2614
2489
  line: 229,
2615
2490
  scope: this,
@@ -2692,10 +2567,10 @@ var DataSpace = class DataSpace2 {
2692
2567
  }
2693
2568
  }
2694
2569
  };
2695
- __decorate2([
2570
+ __decorate([
2696
2571
  timed(1e4)
2697
2572
  ], DataSpace.prototype, "_createWritableFeeds", null);
2698
- DataSpace = __decorate2([
2573
+ DataSpace = __decorate([
2699
2574
  trackLeaks("open", "close")
2700
2575
  ], DataSpace);
2701
2576
 
@@ -2705,7 +2580,7 @@ import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/
2705
2580
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2706
2581
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2707
2582
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2708
- import { log as log11 } from "@dxos/log";
2583
+ import { log as log10 } from "@dxos/log";
2709
2584
  import { trace as trace4 } from "@dxos/protocols";
2710
2585
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2711
2586
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
@@ -2782,7 +2657,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2782
2657
  };
2783
2658
 
2784
2659
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2785
- var __decorate3 = function(decorators, target, key, desc) {
2660
+ var __decorate2 = function(decorators, target, key, desc) {
2786
2661
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2787
2662
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2788
2663
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2811,13 +2686,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2811
2686
  return this._spaces;
2812
2687
  }
2813
2688
  async open() {
2814
- log11("open", {}, {
2689
+ log10("open", {}, {
2815
2690
  file: "data-space-manager.ts",
2816
2691
  line: 80,
2817
2692
  scope: this,
2818
2693
  callSite: (f, a) => f(...a)
2819
2694
  });
2820
- log11.trace("dxos.echo.data-space-manager.open", trace4.begin({
2695
+ log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
2821
2696
  id: this._instanceId
2822
2697
  }), {
2823
2698
  file: "data-space-manager.ts",
@@ -2826,7 +2701,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2826
2701
  callSite: (f, a) => f(...a)
2827
2702
  });
2828
2703
  await this._metadataStore.load();
2829
- log11("metadata loaded", {
2704
+ log10("metadata loaded", {
2830
2705
  spaces: this._metadataStore.spaces.length
2831
2706
  }, {
2832
2707
  file: "data-space-manager.ts",
@@ -2836,7 +2711,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2836
2711
  });
2837
2712
  for (const spaceMetadata of this._metadataStore.spaces) {
2838
2713
  try {
2839
- log11("load space", {
2714
+ log10("load space", {
2840
2715
  spaceMetadata
2841
2716
  }, {
2842
2717
  file: "data-space-manager.ts",
@@ -2847,7 +2722,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2847
2722
  const space = await this._constructSpace(spaceMetadata);
2848
2723
  space.initializeDataPipelineAsync();
2849
2724
  } catch (err) {
2850
- log11.error("Error loading space", {
2725
+ log10.error("Error loading space", {
2851
2726
  spaceMetadata,
2852
2727
  err
2853
2728
  }, {
@@ -2860,7 +2735,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2860
2735
  }
2861
2736
  this._isOpen = true;
2862
2737
  this.updated.emit();
2863
- log11.trace("dxos.echo.data-space-manager.open", trace4.end({
2738
+ log10.trace("dxos.echo.data-space-manager.open", trace4.end({
2864
2739
  id: this._instanceId
2865
2740
  }), {
2866
2741
  file: "data-space-manager.ts",
@@ -2870,7 +2745,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2870
2745
  });
2871
2746
  }
2872
2747
  async close() {
2873
- log11("close", {}, {
2748
+ log10("close", {}, {
2874
2749
  file: "data-space-manager.ts",
2875
2750
  line: 102,
2876
2751
  scope: this,
@@ -2896,7 +2771,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2896
2771
  controlFeedKey,
2897
2772
  dataFeedKey
2898
2773
  };
2899
- log11("creating space...", {
2774
+ log10("creating space...", {
2900
2775
  spaceKey
2901
2776
  }, {
2902
2777
  file: "data-space-manager.ts",
@@ -2916,7 +2791,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2916
2791
  }
2917
2792
  // TODO(burdon): Rename join space.
2918
2793
  async acceptSpace(opts) {
2919
- log11("accept space", {
2794
+ log10("accept space", {
2920
2795
  opts
2921
2796
  }, {
2922
2797
  file: "data-space-manager.ts",
@@ -2950,7 +2825,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2950
2825
  }));
2951
2826
  }
2952
2827
  async _constructSpace(metadata) {
2953
- log11("construct space", {
2828
+ log10("construct space", {
2954
2829
  metadata
2955
2830
  }, {
2956
2831
  file: "data-space-manager.ts",
@@ -2988,7 +2863,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2988
2863
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2989
2864
  },
2990
2865
  onAuthFailure: () => {
2991
- log11.warn("auth failure", {}, {
2866
+ log10.warn("auth failure", {}, {
2992
2867
  file: "data-space-manager.ts",
2993
2868
  line: 212,
2994
2869
  scope: this,
@@ -3009,7 +2884,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3009
2884
  signingContext: this._signingContext,
3010
2885
  callbacks: {
3011
2886
  beforeReady: async () => {
3012
- log11("before space ready", {
2887
+ log10("before space ready", {
3013
2888
  space: space.key
3014
2889
  }, {
3015
2890
  file: "data-space-manager.ts",
@@ -3020,7 +2895,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3020
2895
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3021
2896
  },
3022
2897
  afterReady: async () => {
3023
- log11("after space ready", {
2898
+ log10("after space ready", {
3024
2899
  space: space.key,
3025
2900
  open: this._isOpen
3026
2901
  }, {
@@ -3047,19 +2922,19 @@ var DataSpaceManager = class DataSpaceManager2 {
3047
2922
  return dataSpace;
3048
2923
  }
3049
2924
  };
3050
- __decorate3([
2925
+ __decorate2([
3051
2926
  synchronized
3052
2927
  ], DataSpaceManager.prototype, "open", null);
3053
- __decorate3([
2928
+ __decorate2([
3054
2929
  synchronized
3055
2930
  ], DataSpaceManager.prototype, "close", null);
3056
- __decorate3([
2931
+ __decorate2([
3057
2932
  synchronized
3058
2933
  ], DataSpaceManager.prototype, "createSpace", null);
3059
- __decorate3([
2934
+ __decorate2([
3060
2935
  synchronized
3061
2936
  ], DataSpaceManager.prototype, "acceptSpace", null);
3062
- DataSpaceManager = __decorate3([
2937
+ DataSpaceManager = __decorate2([
3063
2938
  trackLeaks2("open", "close")
3064
2939
  ], DataSpaceManager);
3065
2940
 
@@ -3068,7 +2943,7 @@ import { EventSubscriptions as EventSubscriptions2, scheduleTask as scheduleTask
3068
2943
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
3069
2944
  import { raise, todo as todo2 } from "@dxos/debug";
3070
2945
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
3071
- import { log as log12 } from "@dxos/log";
2946
+ import { log as log11 } from "@dxos/log";
3072
2947
  import { encodeError } from "@dxos/protocols";
3073
2948
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
3074
2949
  import { humanize } from "@dxos/util";
@@ -3096,7 +2971,7 @@ var SpacesServiceImpl = class {
3096
2971
  const onUpdate = async () => {
3097
2972
  const dataSpaceManager = await this._getDataSpaceManager();
3098
2973
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
3099
- log12("update", {
2974
+ log11("update", {
3100
2975
  spaces
3101
2976
  }, {
3102
2977
  file: "spaces-service.ts",
@@ -3226,65 +3101,16 @@ var SpacesServiceImpl = class {
3226
3101
  };
3227
3102
  var getChannelId = (channel) => `user-channel/${channel}`;
3228
3103
 
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
-
3278
3104
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3279
3105
  import assert11 from "@dxos/node-std/assert";
3280
- import { Trigger as Trigger6 } from "@dxos/async";
3106
+ import { Trigger as Trigger5 } from "@dxos/async";
3281
3107
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3282
3108
  import { failUndefined as failUndefined3 } from "@dxos/debug";
3283
3109
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3284
3110
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3285
3111
  import { Keyring } from "@dxos/keyring";
3286
3112
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3287
- import { log as log13 } from "@dxos/log";
3113
+ import { log as log12 } from "@dxos/log";
3288
3114
  import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3289
3115
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3290
3116
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -3295,7 +3121,7 @@ var ServiceContext = class {
3295
3121
  this.networkManager = networkManager;
3296
3122
  this.signalManager = signalManager;
3297
3123
  this.modelFactory = modelFactory;
3298
- this.initialized = new Trigger6();
3124
+ this.initialized = new Trigger5();
3299
3125
  this.dataServiceSubscriptions = new DataServiceSubscriptions();
3300
3126
  this._handlerFactories = /* @__PURE__ */ new Map();
3301
3127
  this._instanceId = PublicKey9.random().toHex();
@@ -3328,7 +3154,7 @@ var ServiceContext = class {
3328
3154
  }, this._acceptIdentity.bind(this)));
3329
3155
  }
3330
3156
  async open() {
3331
- log13.trace("dxos.sdk.service-context.open", trace5.begin({
3157
+ log12.trace("dxos.sdk.service-context.open", trace5.begin({
3332
3158
  id: this._instanceId
3333
3159
  }), {
3334
3160
  file: "service-context.ts",
@@ -3337,7 +3163,7 @@ var ServiceContext = class {
3337
3163
  callSite: (f, a) => f(...a)
3338
3164
  });
3339
3165
  await this._checkStorageVersion();
3340
- log13("opening...", {}, {
3166
+ log12("opening...", {}, {
3341
3167
  file: "service-context.ts",
3342
3168
  line: 130,
3343
3169
  scope: this,
@@ -3350,13 +3176,13 @@ var ServiceContext = class {
3350
3176
  if (this.identityManager.identity) {
3351
3177
  await this._initialize();
3352
3178
  }
3353
- log13("opened", {}, {
3179
+ log12("opened", {}, {
3354
3180
  file: "service-context.ts",
3355
3181
  line: 138,
3356
3182
  scope: this,
3357
3183
  callSite: (f, a) => f(...a)
3358
3184
  });
3359
- log13.trace("dxos.sdk.service-context.open", trace5.end({
3185
+ log12.trace("dxos.sdk.service-context.open", trace5.end({
3360
3186
  id: this._instanceId
3361
3187
  }), {
3362
3188
  file: "service-context.ts",
@@ -3367,7 +3193,7 @@ var ServiceContext = class {
3367
3193
  }
3368
3194
  async close() {
3369
3195
  var _a, _b;
3370
- log13("closing...", {}, {
3196
+ log12("closing...", {}, {
3371
3197
  file: "service-context.ts",
3372
3198
  line: 143,
3373
3199
  scope: this,
@@ -3381,7 +3207,7 @@ var ServiceContext = class {
3381
3207
  await this.networkManager.close();
3382
3208
  await this.signalManager.close();
3383
3209
  this.dataServiceSubscriptions.clear();
3384
- log13("closed", {}, {
3210
+ log12("closed", {}, {
3385
3211
  file: "service-context.ts",
3386
3212
  line: 152,
3387
3213
  scope: this,
@@ -3412,7 +3238,7 @@ var ServiceContext = class {
3412
3238
  // Called when identity is created.
3413
3239
  async _initialize() {
3414
3240
  var _a;
3415
- log13("initializing spaces...", {}, {
3241
+ log12("initializing spaces...", {}, {
3416
3242
  file: "service-context.ts",
3417
3243
  line: 185,
3418
3244
  scope: this,
@@ -3449,7 +3275,7 @@ var ServiceContext = class {
3449
3275
  return;
3450
3276
  }
3451
3277
  if (!this.dataSpaceManager) {
3452
- log13("dataSpaceManager not initialized yet, ignoring space admission", {
3278
+ log12("dataSpaceManager not initialized yet, ignoring space admission", {
3453
3279
  details: assertion
3454
3280
  }, {
3455
3281
  file: "service-context.ts",
@@ -3460,7 +3286,7 @@ var ServiceContext = class {
3460
3286
  return;
3461
3287
  }
3462
3288
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3463
- log13("space already exists, ignoring space admission", {
3289
+ log12("space already exists, ignoring space admission", {
3464
3290
  details: assertion
3465
3291
  }, {
3466
3292
  file: "service-context.ts",
@@ -3471,7 +3297,7 @@ var ServiceContext = class {
3471
3297
  return;
3472
3298
  }
3473
3299
  try {
3474
- log13("accepting space recorded in halo", {
3300
+ log12("accepting space recorded in halo", {
3475
3301
  details: assertion
3476
3302
  }, {
3477
3303
  file: "service-context.ts",
@@ -3484,7 +3310,7 @@ var ServiceContext = class {
3484
3310
  genesisFeedKey: assertion.genesisFeedKey
3485
3311
  });
3486
3312
  } catch (err) {
3487
- log13.catch(err, {}, {
3313
+ log12.catch(err, {}, {
3488
3314
  file: "service-context.ts",
3489
3315
  line: 239,
3490
3316
  scope: this,
@@ -3497,6 +3323,180 @@ var ServiceContext = class {
3497
3323
  }
3498
3324
  };
3499
3325
 
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,28 +3958,6 @@ 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
-
3983
3961
  export {
3984
3962
  subscribeToFeeds,
3985
3963
  subscribeToFeedBlocks,
@@ -4000,15 +3978,14 @@ export {
4000
3978
  InvitationsHandler,
4001
3979
  InvitationsServiceImpl,
4002
3980
  SpaceInvitationProtocol,
4003
- Lock,
4004
- isLocked,
4005
3981
  DataSpace,
4006
3982
  DataSpaceManager,
4007
3983
  SpacesServiceImpl,
4008
- createStorageObjects,
4009
3984
  ServiceContext,
3985
+ Lock,
3986
+ isLocked,
3987
+ createStorageObjects,
4010
3988
  ServiceRegistry,
4011
- ClientServicesHost,
4012
- LocalClientServices
3989
+ ClientServicesHost
4013
3990
  };
4014
- //# sourceMappingURL=chunk-2GQ7337P.mjs.map
3991
+ //# sourceMappingURL=chunk-C3SPTMW3.mjs.map