@securitydept/client 0.3.0-beta.3 → 0.3.0-beta.5

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 (58) hide show
  1. package/README.md +6 -0
  2. package/dist/create-Bm-XRA3G.mjs +1573 -0
  3. package/dist/create-Bm-XRA3G.mjs.map +1 -0
  4. package/dist/index-BT-u3qNI.d.mts +133 -0
  5. package/dist/index-Ch8lrE44.d.mts +625 -0
  6. package/dist/index-D5mW18cM.d.mts +1648 -0
  7. package/dist/index.d.mts +3 -353
  8. package/dist/index.mjs +1124 -362
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/router-BJ8LqNJ1.mjs +245 -0
  11. package/dist/router-BJ8LqNJ1.mjs.map +1 -0
  12. package/dist/rx/index.d.mts +69 -0
  13. package/dist/rx/index.mjs +2 -0
  14. package/dist/rx-BoB32Dzg.mjs +1106 -0
  15. package/dist/rx-BoB32Dzg.mjs.map +1 -0
  16. package/dist/server/index.d.mts +21 -0
  17. package/dist/server/index.mjs +29 -0
  18. package/dist/server/index.mjs.map +1 -0
  19. package/dist/test/index.d.mts +102 -0
  20. package/dist/test/index.mjs +270 -0
  21. package/dist/test/index.mjs.map +1 -0
  22. package/dist/uri-string-BfnIT4gJ.mjs +298 -0
  23. package/dist/uri-string-BfnIT4gJ.mjs.map +1 -0
  24. package/dist/web/index.d.mts +82 -364
  25. package/dist/web/index.mjs +329 -428
  26. package/dist/web/index.mjs.map +1 -1
  27. package/dist/webext/index.d.mts +74 -0
  28. package/dist/webext/index.mjs +229 -0
  29. package/dist/webext/index.mjs.map +1 -0
  30. package/package.json +28 -21
  31. package/dist/auth-coordination/index.d.mts +0 -198
  32. package/dist/auth-coordination/index.mjs +0 -107
  33. package/dist/auth-coordination/index.mjs.map +0 -1
  34. package/dist/client-environment-CaumNmir.mjs +0 -812
  35. package/dist/client-environment-CaumNmir.mjs.map +0 -1
  36. package/dist/client-environment-CdHtVxKW.d.mts +0 -401
  37. package/dist/events/index.d.mts +0 -2
  38. package/dist/events/index.mjs +0 -2
  39. package/dist/events-BUlfsRfl.mjs +0 -127
  40. package/dist/events-BUlfsRfl.mjs.map +0 -1
  41. package/dist/index-C4xlKhG7.d.mts +0 -102
  42. package/dist/index-COUt5x9Z.d.mts +0 -39
  43. package/dist/persistence/index.d.mts +0 -3
  44. package/dist/persistence/index.mjs +0 -2
  45. package/dist/persistence/web/index.d.mts +0 -16
  46. package/dist/persistence/web/index.mjs +0 -2
  47. package/dist/persistence-CSB8770k.mjs +0 -108
  48. package/dist/persistence-CSB8770k.mjs.map +0 -1
  49. package/dist/planner-host-BTWie0lo.mjs +0 -197
  50. package/dist/planner-host-BTWie0lo.mjs.map +0 -1
  51. package/dist/planner-host-DN9dRsQx.d.mts +0 -190
  52. package/dist/types-BJqUdH2e.d.mts +0 -32
  53. package/dist/types-BwcnUGNl.d.mts +0 -52
  54. package/dist/web-DQmMqZnR.mjs +0 -51
  55. package/dist/web-DQmMqZnR.mjs.map +0 -1
  56. package/dist/web-router/index.d.mts +0 -259
  57. package/dist/web-router/index.mjs +0 -395
  58. package/dist/web-router/index.mjs.map +0 -1
@@ -0,0 +1,1106 @@
1
+ import { BehaviorSubject, EMPTY, NEVER, Observable, ReplaySubject, Subject, animationFrameScheduler, asapScheduler, audit, auditTime, catchError, concat, concatAll, defer, distinctUntilChanged, filter, finalize, firstValueFrom, from, fromEventPattern, lastValueFrom, map, merge, of, share, shareReplay, switchMap, take, takeLast, takeUntil, takeWhile, toArray } from "rxjs";
2
+ import { AsyncAction } from "rxjs/internal/scheduler/AsyncAction";
3
+ import { AsyncScheduler } from "rxjs/internal/scheduler/AsyncScheduler";
4
+ import { BehaviorSubject as BehaviorSubject$1 } from "rxjs/internal/BehaviorSubject";
5
+ //#region src/errors/types.ts
6
+ /** Recovery actions the user might take. Aligned with server-side `UserRecovery`. */
7
+ const UserRecovery = {
8
+ None: "none",
9
+ Retry: "retry",
10
+ RestartFlow: "restart_flow",
11
+ Reauthenticate: "reauthenticate",
12
+ ContactSupport: "contact_support"
13
+ };
14
+ const ErrorPresentationTone = {
15
+ Neutral: "neutral",
16
+ Warning: "warning",
17
+ Danger: "danger"
18
+ };
19
+ /** Machine-facing error kind discriminator. */
20
+ const ClientErrorKind = {
21
+ Authorization: "authorization",
22
+ Transport: "transport",
23
+ Server: "server",
24
+ Protocol: "protocol",
25
+ Storage: "storage",
26
+ Configuration: "configuration",
27
+ Unauthenticated: "unauthenticated",
28
+ Unauthorized: "unauthorized",
29
+ Cancelled: "cancelled",
30
+ Timeout: "timeout",
31
+ Internal: "internal"
32
+ };
33
+ /** Stable source vocabulary for common client error producers. */
34
+ const ClientErrorSource = {
35
+ Transport: "transport",
36
+ Server: "server",
37
+ Client: "client"
38
+ };
39
+ //#endregion
40
+ //#region src/errors/client-error.ts
41
+ const userRecoveryValues = new Set(Object.values(UserRecovery));
42
+ function readUserRecovery(value) {
43
+ return typeof value === "string" && userRecoveryValues.has(value) ? value : void 0;
44
+ }
45
+ function mapServerErrorKind(kind, status) {
46
+ switch (kind) {
47
+ case "unauthenticated": return ClientErrorKind.Unauthenticated;
48
+ case "unauthorized": return ClientErrorKind.Unauthorized;
49
+ case "unavailable":
50
+ case "internal": return ClientErrorKind.Server;
51
+ case "invalid_request":
52
+ case "conflict": return ClientErrorKind.Protocol;
53
+ default: return status === 401 ? ClientErrorKind.Unauthenticated : status === 403 ? ClientErrorKind.Unauthorized : status === 408 ? ClientErrorKind.Timeout : status >= 500 ? ClientErrorKind.Server : ClientErrorKind.Protocol;
54
+ }
55
+ }
56
+ function readServerErrorBody(body) {
57
+ if (!body || typeof body !== "object") return;
58
+ const record = body;
59
+ const error = record.error && typeof record.error === "object" ? record.error : record;
60
+ return {
61
+ kind: typeof error.kind === "string" ? error.kind : void 0,
62
+ code: typeof error.code === "string" ? error.code : void 0,
63
+ message: typeof error.message === "string" ? error.message : void 0,
64
+ recovery: typeof error.recovery === "string" ? error.recovery : void 0,
65
+ presentation: error.presentation && typeof error.presentation === "object" ? {
66
+ code: typeof error.presentation.code === "string" ? error.presentation.code : void 0,
67
+ message: typeof error.presentation.message === "string" ? error.presentation.message : void 0,
68
+ recovery: typeof error.presentation.recovery === "string" ? error.presentation.recovery : void 0
69
+ } : void 0
70
+ };
71
+ }
72
+ /**
73
+ * Base client error carrying both machine-facing context and an optional
74
+ * user-facing presentation layer.
75
+ *
76
+ * Top-level `code` and `recovery` provide stable machine contracts for
77
+ * policy decisions without requiring callers to unwrap `presentation`.
78
+ */
79
+ var ClientError = class ClientError extends Error {
80
+ kind;
81
+ /**
82
+ * Stable machine-readable error code.
83
+ * Matches `presentation.code` when present, otherwise a default
84
+ * derived from `kind`.
85
+ */
86
+ code;
87
+ /** Recovery hint at the machine level. */
88
+ recovery;
89
+ /** Whether this error is safe to retry. */
90
+ retryable;
91
+ /** Structured user-facing error presentation from the server. */
92
+ presentation;
93
+ /** Source subsystem or component that produced the error. */
94
+ source;
95
+ constructor(options) {
96
+ super(options.message, { cause: options.cause });
97
+ this.name = "ClientError";
98
+ this.kind = options.kind;
99
+ this.code = options.code ?? options.presentation?.code ?? `client.${options.kind}`;
100
+ this.recovery = options.recovery ?? options.presentation?.recovery ?? UserRecovery.None;
101
+ this.retryable = options.retryable ?? this.recovery === UserRecovery.Retry;
102
+ this.presentation = options.presentation;
103
+ this.source = options.source;
104
+ }
105
+ /** Create a `ClientError` from a server error response body. */
106
+ static fromServerError(body, overrides) {
107
+ const rawPresentation = body.presentation;
108
+ const recovery = readUserRecovery(body.recovery) ?? readUserRecovery(rawPresentation?.recovery) ?? UserRecovery.None;
109
+ const presentation = rawPresentation?.code && rawPresentation.message ? {
110
+ code: rawPresentation.code,
111
+ message: rawPresentation.message,
112
+ recovery: readUserRecovery(rawPresentation.recovery) ?? recovery
113
+ } : void 0;
114
+ return new ClientError({
115
+ kind: overrides?.kind ?? mapServerErrorKind(body.kind, 400),
116
+ message: body.message ?? presentation?.message ?? "Unknown server error",
117
+ code: body.code ?? presentation?.code,
118
+ recovery,
119
+ retryable: recovery === UserRecovery.Retry,
120
+ presentation,
121
+ source: overrides?.source
122
+ });
123
+ }
124
+ static fromUnknown(error, options) {
125
+ if (error instanceof ClientError) return error;
126
+ return new ClientError({
127
+ kind: ClientErrorKind.Internal,
128
+ message: options.message,
129
+ code: options.code,
130
+ source: options.source,
131
+ cause: error
132
+ });
133
+ }
134
+ /**
135
+ * Create a `ClientError` from an HTTP response status and optional body.
136
+ * Used when a non-success status is unexpected.
137
+ */
138
+ static fromHttpResponse(options) {
139
+ const { status, body } = options;
140
+ const serverBody = readServerErrorBody(body);
141
+ const kind = mapServerErrorKind(serverBody?.kind, status);
142
+ const source = options.source ?? ClientErrorSource.Server;
143
+ const fallbackRecovery = kind === ClientErrorKind.Unauthenticated ? UserRecovery.Reauthenticate : status === 408 || status >= 500 ? UserRecovery.Retry : UserRecovery.None;
144
+ if (serverBody?.code && serverBody?.message) {
145
+ const recovery = readUserRecovery(serverBody.presentation?.recovery) ?? readUserRecovery(serverBody.recovery) ?? fallbackRecovery;
146
+ return ClientError.fromServerError({
147
+ ...serverBody,
148
+ recovery,
149
+ presentation: serverBody.presentation ? {
150
+ ...serverBody.presentation,
151
+ recovery
152
+ } : void 0
153
+ }, {
154
+ kind,
155
+ source
156
+ });
157
+ }
158
+ return new ClientError({
159
+ kind,
160
+ message: serverBody?.message ?? `HTTP ${status}`,
161
+ code: serverBody?.code ?? `http.${status}`,
162
+ recovery: fallbackRecovery,
163
+ retryable: status === 408 || status >= 500,
164
+ source
165
+ });
166
+ }
167
+ };
168
+ //#endregion
169
+ //#region src/compat/disposable.ts
170
+ const SYMBOL_DISPOSE = typeof Symbol !== "undefined" && Symbol.dispose ? Symbol.dispose : "@@dispose";
171
+ const SYMBOL_ASYNC_DISPOSE = typeof Symbol !== "undefined" && Symbol.asyncDispose ? Symbol.asyncDispose : "@@asyncDispose";
172
+ const SYMBOL_DISPOSABLE_STACK = "@@disposableStack";
173
+ function injectDisposableStackFrom(arg, isOptions = false) {
174
+ return isOptions && typeof arg === "object" && arg !== null ? arg[SYMBOL_DISPOSABLE_STACK] : arg;
175
+ }
176
+ var SimpleDisposableStack = class {
177
+ stack = [];
178
+ disposed = false;
179
+ use(disposable) {
180
+ if (this.disposed) throw new ReferenceError("Disposable stack is already disposed");
181
+ this.stack.push(disposable);
182
+ return disposable;
183
+ }
184
+ dispose() {
185
+ if (this.disposed) return;
186
+ this.disposed = true;
187
+ const errors = [];
188
+ for (let disposable = this.stack.pop(); disposable; disposable = this.stack.pop()) try {
189
+ disposable.dispose();
190
+ } catch (error) {
191
+ errors.push(error);
192
+ }
193
+ if (errors.length === 1) throw errors[0];
194
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to dispose disposable stack");
195
+ }
196
+ [SYMBOL_DISPOSE]() {
197
+ this.dispose();
198
+ }
199
+ };
200
+ var StdDisposableStack = class {
201
+ stack;
202
+ constructor(Stack = globalThis.DisposableStack) {
203
+ this.stack = new Stack();
204
+ }
205
+ get disposed() {
206
+ return this.stack.disposed;
207
+ }
208
+ use(disposable) {
209
+ return this.stack.use(disposable);
210
+ }
211
+ dispose() {
212
+ this.stack.dispose();
213
+ }
214
+ [SYMBOL_DISPOSE]() {
215
+ this.dispose();
216
+ }
217
+ };
218
+ function createDisposableStack() {
219
+ const Stack = globalThis.DisposableStack;
220
+ return typeof Stack === "function" ? new StdDisposableStack(Stack) : new SimpleDisposableStack();
221
+ }
222
+ function withDisposableStack(index, isOptions = false) {
223
+ return (target, _context) => function(...args) {
224
+ const disposableStack = createDisposableStack();
225
+ const injectedArgs = [...args];
226
+ if (isOptions) {
227
+ const value = injectedArgs[index];
228
+ injectedArgs[index] = Object.assign({}, typeof value === "object" && value !== null ? value : void 0, { [SYMBOL_DISPOSABLE_STACK]: disposableStack });
229
+ } else injectedArgs[index] = disposableStack;
230
+ let result;
231
+ try {
232
+ result = target.call(this, ...injectedArgs);
233
+ } catch (error) {
234
+ disposableStack.dispose();
235
+ throw error;
236
+ }
237
+ if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") return Promise.resolve(result).finally(() => {
238
+ disposableStack.dispose();
239
+ });
240
+ disposableStack.dispose();
241
+ return result;
242
+ };
243
+ }
244
+ //#endregion
245
+ //#region src/compat/observable.ts
246
+ const SYMBOL_OBSERVABLE = typeof Symbol !== "undefined" && Symbol.observable ? Symbol.observable : "@@observable";
247
+ function isInteropObservableTrait(value) {
248
+ return typeof value === "object" && value !== null && SYMBOL_OBSERVABLE in value && typeof value[SYMBOL_OBSERVABLE] === "function";
249
+ }
250
+ //#endregion
251
+ //#region src/rx/event.ts
252
+ var RxEventStream = class RxEventStream extends Observable {
253
+ constructor(source) {
254
+ super((subscriber) => {
255
+ if (typeof source === "function") return source(subscriber);
256
+ if (isInteropObservableTrait(source)) {
257
+ const subscription = source[SYMBOL_OBSERVABLE]().subscribe(subscriber);
258
+ return () => {
259
+ subscription.unsubscribe();
260
+ };
261
+ }
262
+ if (typeof source === "object" && source !== null && "subscribe" in source && typeof source.subscribe === "function") {
263
+ const subscription = source.subscribe(subscriber);
264
+ return () => {
265
+ subscription.unsubscribe();
266
+ };
267
+ }
268
+ const subscription = from(source).subscribe(subscriber);
269
+ return () => {
270
+ subscription.unsubscribe();
271
+ };
272
+ });
273
+ }
274
+ [SYMBOL_OBSERVABLE]() {
275
+ return this;
276
+ }
277
+ static fromObservableInput(input) {
278
+ if (input instanceof RxEventStream) return input;
279
+ return new RxEventStream(input);
280
+ }
281
+ pipe(...args) {
282
+ const piped = super.pipe(...args);
283
+ return RxEventStream.fromObservableInput(piped);
284
+ }
285
+ };
286
+ var RxEventSubject = class extends Subject {
287
+ [SYMBOL_OBSERVABLE]() {
288
+ return this.asObservable();
289
+ }
290
+ asObservable() {
291
+ return RxEventStream.fromObservableInput(super.asObservable());
292
+ }
293
+ };
294
+ var RxEventReplaySubject = class extends ReplaySubject {
295
+ [SYMBOL_OBSERVABLE]() {
296
+ return this.asObservable();
297
+ }
298
+ asObservable() {
299
+ return RxEventStream.fromObservableInput(super.asObservable());
300
+ }
301
+ };
302
+ //#endregion
303
+ //#region src/rx/signal.ts
304
+ function watchOptionsToAuditOperator(options) {
305
+ if (options.schedule === globalThis.queueMicrotask) return auditTime(0, asapScheduler);
306
+ if (options.schedule === globalThis.requestAnimationFrame && options.cancel === globalThis.cancelAnimationFrame) return auditTime(0, animationFrameScheduler);
307
+ return audit(() => fromEventPattern((handler) => options.schedule(() => handler()), (_handler, handle) => {
308
+ if (options.cancel) options.cancel(handle);
309
+ else if (typeof handle === "function") handle();
310
+ }));
311
+ }
312
+ var RxSignal = class {
313
+ static globalEpoch = 0;
314
+ static currentContext = null;
315
+ valueEqVersion = 0;
316
+ equals;
317
+ constructor(options) {
318
+ this.equals = options?.equals ?? Object.is;
319
+ }
320
+ watchStream(options = { schedule: globalThis.queueMicrotask }) {
321
+ return RxEventStream.fromObservableInput(this.dirtyObservable().pipe(watchOptionsToAuditOperator(options), map(() => void 0), shareReplay({
322
+ bufferSize: 1,
323
+ refCount: true
324
+ })));
325
+ }
326
+ [SYMBOL_OBSERVABLE]() {
327
+ return RxEventStream.fromObservableInput(defer(() => concat(of(this.get()), this.dirtyObservable().pipe(map(() => this.get())))));
328
+ }
329
+ };
330
+ var RxStateSignal = class RxStateSignal extends RxSignal {
331
+ dirtySubject = new Subject();
332
+ value;
333
+ constructor(initialValue, options) {
334
+ super(options);
335
+ this.value = new BehaviorSubject(initialValue);
336
+ }
337
+ set(input) {
338
+ const changed = !this.equals(this.value.getValue(), input);
339
+ this.value.next(input);
340
+ if (changed) this.valueEqVersion += 1;
341
+ RxSignal.globalEpoch += 1;
342
+ this.dirtySubject.next({
343
+ epoch: RxSignal.globalEpoch,
344
+ signal: this
345
+ });
346
+ }
347
+ static fromInitialValue(initialValue, options) {
348
+ return new RxStateSignal(initialValue, options);
349
+ }
350
+ get() {
351
+ const value = this.value.getValue();
352
+ RxSignal.currentContext?.markDependency(this);
353
+ return value;
354
+ }
355
+ validateForEpoch() {}
356
+ dirtyObservable() {
357
+ return this.dirtySubject.asObservable();
358
+ }
359
+ [SYMBOL_OBSERVABLE]() {
360
+ return RxEventStream.fromObservableInput(this.value.asObservable());
361
+ }
362
+ };
363
+ function haveSameSourceKeys(left, right) {
364
+ if (left.size !== right.size) return false;
365
+ const leftSources = left.keys();
366
+ const rightSources = right.keys();
367
+ while (true) {
368
+ const leftSource = leftSources.next();
369
+ const rightSource = rightSources.next();
370
+ if (leftSource.done || rightSource.done) return leftSource.done === rightSource.done;
371
+ if (leftSource.value !== rightSource.value) return false;
372
+ }
373
+ }
374
+ var RxComputedSignal = class RxComputedSignal extends RxSignal {
375
+ computeFn;
376
+ cacheState = { kind: "empty" };
377
+ sources = /* @__PURE__ */ new Map();
378
+ sourcesSubject = new BehaviorSubject(this.sources);
379
+ validatedEpoch = -1;
380
+ isComputing = false;
381
+ collectingSources = null;
382
+ dirty$;
383
+ constructor(computeFn, options) {
384
+ super(options);
385
+ this.computeFn = computeFn;
386
+ }
387
+ markDependency(signal) {
388
+ const source = signal;
389
+ this.collectingSources?.set(source, source.valueEqVersion);
390
+ }
391
+ cacheStatesEqual(left, right) {
392
+ if (left.kind !== right.kind) return false;
393
+ if (left.kind === "empty" || right.kind === "empty") return false;
394
+ if (left.kind === "value" && right.kind === "value") return this.equals(left.value, right.value);
395
+ if (left.kind === "error" && right.kind === "error") return Object.is(left.error, right.error);
396
+ return false;
397
+ }
398
+ recompute() {
399
+ if (this.isComputing) throw new Error("Circular computed dependency detected");
400
+ const prevContext = RxSignal.currentContext;
401
+ const prevCollectingSources = this.collectingSources;
402
+ const nextSources = /* @__PURE__ */ new Map();
403
+ RxSignal.currentContext = this;
404
+ this.collectingSources = nextSources;
405
+ this.isComputing = true;
406
+ let nextCacheState;
407
+ try {
408
+ nextCacheState = {
409
+ kind: "value",
410
+ value: this.computeFn()
411
+ };
412
+ } catch (error) {
413
+ nextCacheState = {
414
+ kind: "error",
415
+ error
416
+ };
417
+ } finally {
418
+ this.collectingSources = prevCollectingSources;
419
+ RxSignal.currentContext = prevContext;
420
+ this.isComputing = false;
421
+ }
422
+ const sourcesChanged = !haveSameSourceKeys(this.sources, nextSources);
423
+ let cacheStateChanged;
424
+ try {
425
+ cacheStateChanged = !this.cacheStatesEqual(this.cacheState, nextCacheState);
426
+ } catch (error) {
427
+ nextCacheState = {
428
+ kind: "error",
429
+ error
430
+ };
431
+ cacheStateChanged = !this.cacheStatesEqual(this.cacheState, nextCacheState);
432
+ }
433
+ if (cacheStateChanged) this.valueEqVersion += 1;
434
+ this.cacheState = nextCacheState;
435
+ this.sources = nextSources;
436
+ if (sourcesChanged) this.sourcesSubject.next(nextSources);
437
+ if (nextCacheState.kind === "error") throw nextCacheState.error;
438
+ }
439
+ validateForEpoch(epoch) {
440
+ if (this.validatedEpoch === epoch) return;
441
+ try {
442
+ if (this.cacheState.kind === "empty") {
443
+ this.recompute();
444
+ return;
445
+ }
446
+ for (const [source, version] of this.sources) {
447
+ try {
448
+ source.validateForEpoch(epoch);
449
+ } catch {
450
+ this.recompute();
451
+ break;
452
+ }
453
+ if (source.valueEqVersion !== version) {
454
+ this.recompute();
455
+ break;
456
+ }
457
+ }
458
+ } finally {
459
+ this.validatedEpoch = epoch;
460
+ }
461
+ }
462
+ get() {
463
+ this.validateForEpoch(RxSignal.globalEpoch);
464
+ RxSignal.currentContext?.markDependency(this);
465
+ switch (this.cacheState.kind) {
466
+ case "value": return this.cacheState.value;
467
+ case "error": throw this.cacheState.error;
468
+ case "empty": throw new Error("Computed signal has not been initialized");
469
+ }
470
+ }
471
+ dirtyObservable() {
472
+ if (!this.dirty$) this.dirty$ = defer(() => {
473
+ this.validateForEpoch(RxSignal.globalEpoch);
474
+ return this.sourcesSubject.asObservable().pipe(switchMap((sources) => sources.size === 0 ? EMPTY : merge(...[...sources.keys()].map((source) => source.dirtyObservable())).pipe(distinctUntilChanged((left, right) => left.epoch === right.epoch), map((dirtyDepEvent) => {
475
+ return {
476
+ epoch: dirtyDepEvent.epoch,
477
+ signal: this
478
+ };
479
+ }))));
480
+ }).pipe(share());
481
+ return this.dirty$;
482
+ }
483
+ static computed(fn, options) {
484
+ return new RxComputedSignal(fn, options);
485
+ }
486
+ };
487
+ //#endregion
488
+ //#region src/rx/command.ts
489
+ /** biome-ignore-all lint/complexity/noBannedTypes: false negative */
490
+ const CommandResponseType = {
491
+ Data: "data",
492
+ Success: "success",
493
+ Error: "error",
494
+ Cancel: "cancel",
495
+ Rejected: "rejected"
496
+ };
497
+ function createCommandCancellationError(command) {
498
+ return new ClientError({
499
+ kind: ClientErrorKind.Cancelled,
500
+ message: "Command was cancelled before completion",
501
+ cause: { command }
502
+ });
503
+ }
504
+ function createCommandRejectedError(command, reason) {
505
+ return new ClientError({
506
+ kind: ClientErrorKind.Cancelled,
507
+ message: `Command was rejected before execution: ${reason}`,
508
+ cause: {
509
+ command,
510
+ reason
511
+ }
512
+ });
513
+ }
514
+ function isCommandDataResponse(response) {
515
+ return response.type === CommandResponseType.Data;
516
+ }
517
+ function isCommandTerminalResponse(response) {
518
+ return response.type !== CommandResponseType.Data;
519
+ }
520
+ function dispatchCommand(dispatch, matches) {
521
+ return (source$) => new Observable((subscriber) => {
522
+ const subscription = source$.pipe(filter(matches), takeWhile(isCommandDataResponse, true)).subscribe(subscriber);
523
+ if (subscription.closed) return subscription;
524
+ try {
525
+ dispatch();
526
+ } catch (error) {
527
+ if (!subscription.closed) subscriber.error(error);
528
+ }
529
+ return subscription;
530
+ });
531
+ }
532
+ function unwrapCommandTerminalResponse(response) {
533
+ switch (response.type) {
534
+ case CommandResponseType.Success: return;
535
+ case CommandResponseType.Error: throw response.error;
536
+ case CommandResponseType.Cancel: throw createCommandCancellationError(response.command);
537
+ case CommandResponseType.Rejected: throw createCommandRejectedError(response.command, response.reason);
538
+ }
539
+ }
540
+ function commandResponseData() {
541
+ return (source$) => source$.pipe(filter((response) => {
542
+ if (isCommandDataResponse(response)) return true;
543
+ unwrapCommandTerminalResponse(response);
544
+ return false;
545
+ }), map((response) => response.data));
546
+ }
547
+ function dispatchCommandLocallyToStream(options) {
548
+ const command = {
549
+ payload: options.payload,
550
+ ...options.createCommandExtra?.(options.payload) ?? {}
551
+ };
552
+ return from(options.responseStream).pipe(dispatchCommand(() => {
553
+ options.requestStream.next(command);
554
+ }, (response) => response.command === command));
555
+ }
556
+ function dispatchCommandByIdToStream(options) {
557
+ const areIdsEqual = options.areIdsEqual ?? Object.is;
558
+ const commandId = options.selectCommandId(options.command);
559
+ return from(options.responseStream).pipe(dispatchCommand(() => {
560
+ options.requestStream.next(options.command);
561
+ }, (response) => areIdsEqual(options.selectCommandId(response.command), commandId)));
562
+ }
563
+ async function dispatchCommandLocallyToPromise(options) {
564
+ const [data, terminal] = await lastValueFrom(dispatchCommandLocallyToStream(options).pipe(takeLast(2), toArray()), { defaultValue: [] });
565
+ if (data === void 0) throw new ClientError({
566
+ kind: ClientErrorKind.Configuration,
567
+ message: "the executor configuration of dispatchCommandLocallyToPromise should produce a valid data response."
568
+ });
569
+ if (!isCommandDataResponse(data)) throw new ClientError({
570
+ kind: ClientErrorKind.Configuration,
571
+ message: "the executor configuration of dispatchCommandLocallyToPromise should produce a valid data response."
572
+ });
573
+ if (terminal === void 0) throw new ClientError({
574
+ kind: ClientErrorKind.Internal,
575
+ message: "the execution of dispatchCommandLocallyToPromise must produce a valid terminal response."
576
+ });
577
+ if (!isCommandTerminalResponse(terminal)) throw new ClientError({
578
+ kind: ClientErrorKind.Internal,
579
+ message: "the execution of dispatchCommandLocallyToPromise must produce a valid terminal response."
580
+ });
581
+ unwrapCommandTerminalResponse(terminal);
582
+ return data;
583
+ }
584
+ async function dispatchCommandByIdToPromise(options) {
585
+ const [data, terminal] = await lastValueFrom(dispatchCommandByIdToStream(options).pipe(takeLast(2), toArray()), { defaultValue: [] });
586
+ if (data === void 0) throw new ClientError({
587
+ kind: ClientErrorKind.Configuration,
588
+ message: "the executor configuration of dispatchCommandLocallyToPromise should produce a valid data response."
589
+ });
590
+ if (!isCommandDataResponse(data)) throw new ClientError({
591
+ kind: ClientErrorKind.Configuration,
592
+ message: "the executor configuration of dispatchCommandLocallyToPromise should produce a valid data response."
593
+ });
594
+ if (terminal === void 0) throw new ClientError({
595
+ kind: ClientErrorKind.Internal,
596
+ message: "the execution of dispatchCommandLocallyToPromise must produce a valid terminal response."
597
+ });
598
+ if (!isCommandTerminalResponse(terminal)) throw new ClientError({
599
+ kind: ClientErrorKind.Internal,
600
+ message: "the execution of dispatchCommandLocallyToPromise must produce a valid terminal response."
601
+ });
602
+ unwrapCommandTerminalResponse(terminal);
603
+ return data;
604
+ }
605
+ function createCommandExecutionStream(options) {
606
+ return new Observable((subscriber) => {
607
+ let didEmitTerminal = false;
608
+ const emitTerminal = (response) => {
609
+ if (didEmitTerminal) return;
610
+ didEmitTerminal = true;
611
+ subscriber.next(response);
612
+ subscriber.complete();
613
+ };
614
+ const subscription = from(options.execute(options.command)).subscribe({
615
+ next: (data) => {
616
+ subscriber.next({
617
+ type: CommandResponseType.Data,
618
+ command: options.command,
619
+ data
620
+ });
621
+ },
622
+ error: (error) => {
623
+ emitTerminal({
624
+ type: CommandResponseType.Error,
625
+ command: options.command,
626
+ error
627
+ });
628
+ },
629
+ complete: () => {
630
+ emitTerminal({
631
+ type: CommandResponseType.Success,
632
+ command: options.command
633
+ });
634
+ }
635
+ });
636
+ return () => {
637
+ const wasTerminalEmitted = didEmitTerminal;
638
+ subscription.unsubscribe();
639
+ options.onStateEnd?.(options.command);
640
+ if (!wasTerminalEmitted) subscriber.next({
641
+ type: CommandResponseType.Cancel,
642
+ command: options.command
643
+ });
644
+ };
645
+ });
646
+ }
647
+ function switchCommand(execute) {
648
+ return (source$) => new Observable((destination) => {
649
+ let innerSubscription = null;
650
+ let currentCommand = null;
651
+ let isComplete = false;
652
+ const checkComplete = () => {
653
+ if (isComplete && !innerSubscription) destination.complete();
654
+ };
655
+ const sourceSubscription = source$.subscribe({
656
+ next: (command) => {
657
+ const cancelledCommand = currentCommand;
658
+ innerSubscription?.unsubscribe();
659
+ innerSubscription = null;
660
+ currentCommand = null;
661
+ if (cancelledCommand) destination.next({
662
+ type: CommandResponseType.Cancel,
663
+ command: cancelledCommand
664
+ });
665
+ currentCommand = command;
666
+ let didCompleteSynchronously = false;
667
+ const nextInnerSubscription = createCommandExecutionStream({
668
+ command,
669
+ execute
670
+ }).subscribe({
671
+ next: (response) => {
672
+ destination.next(response);
673
+ },
674
+ error: (error) => {
675
+ destination.error(error);
676
+ },
677
+ complete: () => {
678
+ didCompleteSynchronously = true;
679
+ innerSubscription = null;
680
+ currentCommand = null;
681
+ checkComplete();
682
+ }
683
+ });
684
+ if (!didCompleteSynchronously) innerSubscription = nextInnerSubscription;
685
+ },
686
+ error: (error) => {
687
+ destination.error(error);
688
+ },
689
+ complete: () => {
690
+ isComplete = true;
691
+ checkComplete();
692
+ }
693
+ });
694
+ return () => {
695
+ sourceSubscription.unsubscribe();
696
+ innerSubscription?.unsubscribe();
697
+ };
698
+ });
699
+ }
700
+ function concatCommand(execute) {
701
+ return (source$) => source$.pipe(map((command) => createCommandExecutionStream({
702
+ command,
703
+ execute
704
+ })), concatAll());
705
+ }
706
+ const exhaustCommand = (execute) => (source$) => new Observable((destination) => {
707
+ let innerSubscription = null;
708
+ let isComplete = false;
709
+ const checkComplete = () => {
710
+ if (isComplete && !innerSubscription) destination.complete();
711
+ };
712
+ const sourceSubscription = source$.subscribe({
713
+ next: (command) => {
714
+ if (innerSubscription) {
715
+ destination.next({
716
+ type: CommandResponseType.Rejected,
717
+ command,
718
+ reason: "Pessimistic lock active."
719
+ });
720
+ return;
721
+ }
722
+ let didCompleteSynchronously = false;
723
+ const nextInnerSubscription = createCommandExecutionStream({
724
+ command,
725
+ execute
726
+ }).subscribe({
727
+ next: (response) => {
728
+ destination.next(response);
729
+ },
730
+ error: (error) => {
731
+ destination.error(error);
732
+ },
733
+ complete: () => {
734
+ didCompleteSynchronously = true;
735
+ innerSubscription = null;
736
+ checkComplete();
737
+ }
738
+ });
739
+ if (!didCompleteSynchronously) innerSubscription = nextInnerSubscription;
740
+ },
741
+ error: (error) => {
742
+ destination.error(error);
743
+ },
744
+ complete: () => {
745
+ isComplete = true;
746
+ checkComplete();
747
+ }
748
+ });
749
+ return () => {
750
+ sourceSubscription.unsubscribe();
751
+ innerSubscription?.unsubscribe();
752
+ };
753
+ });
754
+ //#endregion
755
+ //#region src/rx/environment.ts
756
+ function createAsyncSchedulerWithTimestampProvider(time) {
757
+ class TimeTraitAsyncAction extends AsyncAction {
758
+ requestAsyncId(scheduler, _id, delay = 0) {
759
+ return time.setTimeout(() => {
760
+ scheduler.flush(this);
761
+ }, delay);
762
+ }
763
+ recycleAsyncId(_scheduler, id, delay = 0) {
764
+ if (delay != null && this.delay === delay && this.pending === false) return id;
765
+ if (id !== void 0) time.clearTimeout(id);
766
+ }
767
+ }
768
+ return new AsyncScheduler(TimeTraitAsyncAction, time.now);
769
+ }
770
+ //#endregion
771
+ //#region src/cancellation/create.ts
772
+ var CancellationToken = class {
773
+ cancellationState = new BehaviorSubject$1(void 0);
774
+ get isCancellationRequested() {
775
+ return this.cancellationState.getValue()?.isCancelled === true;
776
+ }
777
+ get reason() {
778
+ return this.cancellationState.getValue()?.reason;
779
+ }
780
+ /** @internal — called by `CancellationTokenSource`. */
781
+ _cancel(reason) {
782
+ if (this.isCancellationRequested) return;
783
+ this.cancellationState.next({
784
+ isCancelled: true,
785
+ reason,
786
+ cancellationError: new ClientError({
787
+ kind: ClientErrorKind.Cancelled,
788
+ message: "Operation was cancelled",
789
+ code: "client.cancelled",
790
+ source: ClientErrorSource.Client,
791
+ cause: reason
792
+ })
793
+ });
794
+ }
795
+ onCancellationRequested(listener) {
796
+ const cancellationState = this.cancellationState.getValue();
797
+ if (cancellationState?.isCancelled) {
798
+ listener({
799
+ cancellationError: cancellationState.cancellationError,
800
+ reason: cancellationState.reason
801
+ });
802
+ return {
803
+ dispose() {},
804
+ [SYMBOL_DISPOSE]() {}
805
+ };
806
+ }
807
+ const subscription = this.asObservable().subscribe((errorData) => {
808
+ listener(errorData);
809
+ });
810
+ return {
811
+ dispose() {
812
+ subscription.unsubscribe();
813
+ },
814
+ [SYMBOL_DISPOSE]: () => {
815
+ subscription.unsubscribe();
816
+ }
817
+ };
818
+ }
819
+ throwIfCancellationRequested() {
820
+ const cancellationState = this.cancellationState.getValue();
821
+ if (cancellationState?.cancellationError) throw cancellationState.cancellationError;
822
+ }
823
+ get cancellationError() {
824
+ return this.cancellationState.getValue()?.cancellationError;
825
+ }
826
+ asObservable() {
827
+ return this.cancellationState.pipe(filter((state) => !!state?.isCancelled), take(1), map((state) => ({
828
+ cancellationError: state.cancellationError,
829
+ reason: state.reason
830
+ })));
831
+ }
832
+ [SYMBOL_OBSERVABLE]() {
833
+ return this.asObservable();
834
+ }
835
+ };
836
+ var CancellationTokenSource = class {
837
+ token = new CancellationToken();
838
+ cancel(reason) {
839
+ this.token._cancel(reason);
840
+ }
841
+ };
842
+ /**
843
+ * Create a `CancellationTokenSource` that produces a cooperative cancellation token.
844
+ */
845
+ function createCancellationTokenSource() {
846
+ return new CancellationTokenSource();
847
+ }
848
+ function isCancellationTokenTrait(obj) {
849
+ return typeof obj === "object" && obj !== null && typeof obj.isCancellationRequested === "boolean" && typeof obj.onCancellationRequested === "function" && typeof obj.throwIfCancellationRequested === "function" && isInteropObservableTrait(obj);
850
+ }
851
+ //#endregion
852
+ //#region src/signals/error.ts
853
+ const ResourceErrorCode = { ValueUnavailable: "resource.value_unavailable" };
854
+ var ResourceError = class ResourceError extends Error {
855
+ name = "ResourceError";
856
+ code;
857
+ status;
858
+ constructor(message, options) {
859
+ super(message);
860
+ this.code = options.code;
861
+ this.status = options.status;
862
+ }
863
+ static valueUnavailable(options) {
864
+ return new ResourceError(`Resource value is not available while status is "${options.status}".`, {
865
+ code: ResourceErrorCode.ValueUnavailable,
866
+ status: options.status
867
+ });
868
+ }
869
+ };
870
+ //#endregion
871
+ //#region src/signals/types.ts
872
+ const ResourceStatus = {
873
+ Idle: "idle",
874
+ Loading: "loading",
875
+ LoadingError: "loading_error",
876
+ Reloading: "reloading",
877
+ Resolved: "resolved",
878
+ Error: "error"
879
+ };
880
+ //#endregion
881
+ //#region src/signals/resource-snapshot.ts
882
+ async function whenResourceSnapshotValue(snapshotSignal, options) {
883
+ options?.cancellationToken?.throwIfCancellationRequested();
884
+ const staleValueWhenError = options?.staleValueWhenError ?? true;
885
+ const current = snapshotSignal.get();
886
+ if (current.status === ResourceStatus.Resolved || current.status === ResourceStatus.Reloading || current.status === ResourceStatus.Error && staleValueWhenError) return current.value;
887
+ if (current.status === ResourceStatus.LoadingError || current.status === ResourceStatus.Error) throw current.error;
888
+ const snapshot = await firstValueFrom(merge(from(snapshotSignal).pipe(filter((snapshot) => snapshot.status === ResourceStatus.Resolved || snapshot.status === ResourceStatus.Reloading || snapshot.status === ResourceStatus.LoadingError || snapshot.status === ResourceStatus.Error)), (options?.cancellationToken ? from(options.cancellationToken) : NEVER).pipe(map(({ cancellationError }) => {
889
+ throw cancellationError;
890
+ }))));
891
+ if (snapshot.status === ResourceStatus.LoadingError) throw snapshot.error;
892
+ if (snapshot.status === ResourceStatus.Error && !staleValueWhenError) throw snapshot.error;
893
+ return snapshot.value;
894
+ }
895
+ /**
896
+ * Flatten nested resource snapshots while tracking each selected snapshot signal.
897
+ * Ancestor reload and error states remain visible whenever the final snapshot has
898
+ * a value; an ancestor error without a final value becomes a loading error.
899
+ */
900
+ function flattenResourceSnapshot(sourceSnapshot, ...selectors) {
901
+ let snapshot = sourceSnapshot;
902
+ let reloading = false;
903
+ let hasError = false;
904
+ let error;
905
+ for (const select of selectors) switch (snapshot.status) {
906
+ case ResourceStatus.Idle:
907
+ case ResourceStatus.Loading: return hasError ? {
908
+ status: ResourceStatus.LoadingError,
909
+ error
910
+ } : snapshot;
911
+ case ResourceStatus.LoadingError: return hasError ? {
912
+ status: ResourceStatus.LoadingError,
913
+ error
914
+ } : snapshot;
915
+ case ResourceStatus.Reloading:
916
+ reloading = true;
917
+ snapshot = select(snapshot.value).get();
918
+ break;
919
+ case ResourceStatus.Resolved:
920
+ snapshot = select(snapshot.value).get();
921
+ break;
922
+ case ResourceStatus.Error:
923
+ if (!hasError) {
924
+ hasError = true;
925
+ error = snapshot.error;
926
+ }
927
+ snapshot = select(snapshot.value).get();
928
+ break;
929
+ }
930
+ switch (snapshot.status) {
931
+ case ResourceStatus.Idle:
932
+ case ResourceStatus.Loading:
933
+ case ResourceStatus.LoadingError: return hasError ? {
934
+ status: ResourceStatus.LoadingError,
935
+ error
936
+ } : snapshot;
937
+ case ResourceStatus.Reloading: return hasError ? {
938
+ status: ResourceStatus.Error,
939
+ value: snapshot.value,
940
+ error
941
+ } : snapshot;
942
+ case ResourceStatus.Resolved: return hasError ? {
943
+ status: ResourceStatus.Error,
944
+ value: snapshot.value,
945
+ error
946
+ } : reloading ? {
947
+ status: ResourceStatus.Reloading,
948
+ value: snapshot.value
949
+ } : snapshot;
950
+ case ResourceStatus.Error: return hasError ? {
951
+ status: ResourceStatus.Error,
952
+ value: snapshot.value,
953
+ error
954
+ } : snapshot;
955
+ }
956
+ }
957
+ const ResourceSnapshotUpdateKind = {
958
+ Load: "load",
959
+ Resolve: "resolve",
960
+ Fail: "fail",
961
+ FailWithValue: "fail_with_value"
962
+ };
963
+ function reduceResourceSnapshot(previous, update) {
964
+ switch (update.kind) {
965
+ case ResourceSnapshotUpdateKind.Load: return previous.status === ResourceStatus.Reloading || previous.status === ResourceStatus.Resolved || previous.status === ResourceStatus.Error ? {
966
+ status: ResourceStatus.Reloading,
967
+ value: previous.value
968
+ } : { status: ResourceStatus.Loading };
969
+ case ResourceSnapshotUpdateKind.Resolve: return {
970
+ status: ResourceStatus.Resolved,
971
+ value: update.value
972
+ };
973
+ case ResourceSnapshotUpdateKind.Fail: return previous.status === ResourceStatus.Reloading || previous.status === ResourceStatus.Resolved || previous.status === ResourceStatus.Error ? {
974
+ status: ResourceStatus.Error,
975
+ value: previous.value,
976
+ error: update.error
977
+ } : {
978
+ status: ResourceStatus.LoadingError,
979
+ error: update.error
980
+ };
981
+ case ResourceSnapshotUpdateKind.FailWithValue: return {
982
+ status: ResourceStatus.Error,
983
+ value: update.value,
984
+ error: update.error
985
+ };
986
+ }
987
+ }
988
+ //#endregion
989
+ //#region src/rx/resource.ts
990
+ var RxResourceBase = class {
991
+ value;
992
+ status;
993
+ error;
994
+ isLoading;
995
+ destroyed = RxStateSignal.fromInitialValue(false);
996
+ destroyed$ = from(this.destroyed).pipe(filter((value) => value), take(1));
997
+ constructor() {
998
+ this.value = RxComputedSignal.computed(() => {
999
+ const snapshot = this.snapshot.get();
1000
+ if (snapshot.status === ResourceStatus.Resolved || snapshot.status === ResourceStatus.Reloading) return snapshot.value;
1001
+ if (snapshot.status === ResourceStatus.LoadingError || snapshot.status === ResourceStatus.Error) throw snapshot.error;
1002
+ throw ResourceError.valueUnavailable({ status: snapshot.status });
1003
+ });
1004
+ this.status = RxComputedSignal.computed(() => this.snapshot.get().status);
1005
+ this.error = RxComputedSignal.computed(() => {
1006
+ const snapshot = this.snapshot.get();
1007
+ return snapshot.status === ResourceStatus.LoadingError || snapshot.status === ResourceStatus.Error ? snapshot.error : void 0;
1008
+ });
1009
+ this.isLoading = RxComputedSignal.computed(() => {
1010
+ const status = this.snapshot.get().status;
1011
+ return status === ResourceStatus.Loading || status === ResourceStatus.Reloading;
1012
+ });
1013
+ }
1014
+ hasValue() {
1015
+ const status = this.snapshot.get().status;
1016
+ return status === ResourceStatus.Resolved || status === ResourceStatus.Reloading;
1017
+ }
1018
+ async whenValue(options) {
1019
+ return whenResourceSnapshotValue(this.snapshot, options);
1020
+ }
1021
+ dispose() {
1022
+ this.destroyed.set(true);
1023
+ }
1024
+ [SYMBOL_DISPOSE]() {
1025
+ this.dispose();
1026
+ }
1027
+ [SYMBOL_OBSERVABLE]() {
1028
+ return this.snapshot[SYMBOL_OBSERVABLE]();
1029
+ }
1030
+ };
1031
+ var RxResource = class RxResource extends RxResourceBase {
1032
+ options;
1033
+ snapshot;
1034
+ constructor(options) {
1035
+ super();
1036
+ this.options = options;
1037
+ this.snapshot = RxStateSignal.fromInitialValue({ status: ResourceStatus.Idle });
1038
+ this.destroyed$.subscribe(() => {
1039
+ this.snapshot.set({ status: ResourceStatus.Idle });
1040
+ });
1041
+ this.connect();
1042
+ }
1043
+ connect() {
1044
+ const configuredRequest = this.options.request;
1045
+ const requestObservable = configuredRequest && typeof configuredRequest !== "function" ? from(configuredRequest).pipe(distinctUntilChanged(configuredRequest.equals)) : of(configuredRequest && typeof configuredRequest === "function" ? configuredRequest() : void 0);
1046
+ const requestControlsLoading = configuredRequest !== void 0;
1047
+ requestObservable.pipe(switchMap((request) => {
1048
+ if (requestControlsLoading && request === void 0) return of({ status: ResourceStatus.Idle });
1049
+ const previous = this.snapshot.get();
1050
+ const loadingSnapshot = reduceResourceSnapshot(previous, { kind: ResourceSnapshotUpdateKind.Load });
1051
+ this.snapshot.set(loadingSnapshot);
1052
+ const loadCancellation = createCancellationTokenSource();
1053
+ return from(this.options.stream({
1054
+ request,
1055
+ previous,
1056
+ cancellationToken: loadCancellation.token
1057
+ })).pipe(map((value) => reduceResourceSnapshot(loadingSnapshot, {
1058
+ kind: ResourceSnapshotUpdateKind.Resolve,
1059
+ value
1060
+ })), catchError((error) => of(reduceResourceSnapshot(loadingSnapshot, {
1061
+ kind: ResourceSnapshotUpdateKind.Fail,
1062
+ error
1063
+ }))), finalize(() => loadCancellation.cancel()));
1064
+ }), takeUntil(this.destroyed$)).subscribe((snapshot) => this.snapshot.set(snapshot));
1065
+ }
1066
+ static create(options) {
1067
+ return new RxResource(options);
1068
+ }
1069
+ };
1070
+ var RxSnapshotResource = class extends RxResourceBase {
1071
+ snapshot;
1072
+ constructor(source) {
1073
+ super();
1074
+ this.snapshot = RxComputedSignal.computed(() => this.destroyed.get() ? { status: ResourceStatus.Idle } : source());
1075
+ }
1076
+ };
1077
+ function resourceFromSnapshots(source) {
1078
+ return new RxSnapshotResource(source);
1079
+ }
1080
+ function mapResource(source, mapValue) {
1081
+ return resourceFromSnapshots(() => {
1082
+ const snapshot = source.snapshot.get();
1083
+ switch (snapshot.status) {
1084
+ case ResourceStatus.Idle:
1085
+ case ResourceStatus.Loading:
1086
+ case ResourceStatus.LoadingError: return snapshot;
1087
+ case ResourceStatus.Reloading:
1088
+ case ResourceStatus.Resolved: return {
1089
+ status: snapshot.status,
1090
+ value: mapValue(snapshot.value)
1091
+ };
1092
+ case ResourceStatus.Error: return {
1093
+ status: ResourceStatus.Error,
1094
+ value: mapValue(snapshot.value),
1095
+ error: snapshot.error
1096
+ };
1097
+ }
1098
+ });
1099
+ }
1100
+ function rxResource(options) {
1101
+ return new RxResource(options);
1102
+ }
1103
+ //#endregion
1104
+ export { RxEventSubject as A, withDisposableStack as B, exhaustCommand as C, RxStateSignal as D, RxComputedSignal as E, SYMBOL_DISPOSE as F, UserRecovery as G, ClientErrorKind as H, SimpleDisposableStack as I, StdDisposableStack as L, isInteropObservableTrait as M, SYMBOL_ASYNC_DISPOSE as N, RxEventReplaySubject as O, SYMBOL_DISPOSABLE_STACK as P, createDisposableStack as R, dispatchCommandLocallyToStream as S, unwrapCommandTerminalResponse as T, ClientErrorSource as U, ClientError as V, ErrorPresentationTone as W, commandResponseData as _, ResourceSnapshotUpdateKind as a, dispatchCommandByIdToStream as b, whenResourceSnapshotValue as c, ResourceErrorCode as d, CancellationToken as f, CommandResponseType as g, createAsyncSchedulerWithTimestampProvider as h, rxResource as i, SYMBOL_OBSERVABLE as j, RxEventStream as k, ResourceStatus as l, isCancellationTokenTrait as m, mapResource as n, flattenResourceSnapshot as o, createCancellationTokenSource as p, resourceFromSnapshots as r, reduceResourceSnapshot as s, RxResource as t, ResourceError as u, concatCommand as v, switchCommand as w, dispatchCommandLocallyToPromise as x, dispatchCommandByIdToPromise as y, injectDisposableStackFrom as z };
1105
+
1106
+ //# sourceMappingURL=rx-BoB32Dzg.mjs.map