storion 0.11.1 → 0.11.2
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.
- package/dist/async/async.d.ts +31 -0
- package/dist/async/async.d.ts.map +1 -1
- package/dist/async/index.js +8 -601
- package/dist/async/safe.d.ts +0 -12
- package/dist/async/safe.d.ts.map +1 -1
- package/dist/{effect-1beiYe_c.js → effect-BfoYEdFF.js} +686 -61
- package/dist/isPromiseLike-bFkfHAbm.js +6 -0
- package/dist/persist/index.js +1 -3
- package/dist/react/index.js +11 -11
- package/dist/storion.js +15 -15
- package/package.json +1 -1
package/dist/async/async.d.ts
CHANGED
|
@@ -2,11 +2,28 @@ import { Focus, MetaEntry, SelectorMixin } from '../types';
|
|
|
2
2
|
import { AsyncState, AsyncMode, AsyncHandler, AsyncOptions, AsyncActions, CancellablePromise, InferAsyncData, MapAsyncData, MapSettledResult, RaceResult, AsyncKey, AsyncRequestId } from './types';
|
|
3
3
|
import { Abortable } from './abortable';
|
|
4
4
|
|
|
5
|
+
interface PromiseState<T = any> {
|
|
6
|
+
status: "pending" | "fulfilled" | "rejected";
|
|
7
|
+
resolved: T | undefined;
|
|
8
|
+
rejected: any;
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* Get the pending promise for an async state (for Suspense).
|
|
7
12
|
* Returns undefined if no pending promise.
|
|
8
13
|
*/
|
|
9
14
|
export declare function getPendingPromise<T>(state: AsyncState<T, any>): Promise<T> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a value or parameterless function to a Promise.
|
|
17
|
+
* Handles: PromiseLike, sync values, functions returning either.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* toPromise(42) // Promise.resolve(42)
|
|
21
|
+
* toPromise(Promise.resolve(42)) // Promise.resolve(42)
|
|
22
|
+
* toPromise(() => 42) // Promise.resolve(42)
|
|
23
|
+
* toPromise(() => fetchData()) // fetchData() promise
|
|
24
|
+
* toPromise(thenable) // Promise wrapping thenable
|
|
25
|
+
*/
|
|
26
|
+
export declare function toPromise<T>(value: T | (() => T)): Promise<Awaited<T>>;
|
|
10
27
|
/**
|
|
11
28
|
* Wraps a synchronous or async function to always return a Promise.
|
|
12
29
|
* Ensures async execution even for synchronous functions.
|
|
@@ -183,6 +200,20 @@ export declare namespace async {
|
|
|
183
200
|
* Also considers stale data as "ready" in stale mode.
|
|
184
201
|
*/
|
|
185
202
|
function race<T extends Record<string, AsyncState<any, any>>>(states: T): RaceResult<T>;
|
|
203
|
+
/**
|
|
204
|
+
* Wraps a promise with the state of the promise.
|
|
205
|
+
* @param promise - The promise to get the state of.
|
|
206
|
+
* @returns The promise with the state attached.
|
|
207
|
+
*/
|
|
208
|
+
function withState<T>(promise: PromiseLike<T>): PromiseLike<T> & {
|
|
209
|
+
state: PromiseState<T>;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Get the state of a promise.
|
|
213
|
+
* @param promise - The promise to get the state of.
|
|
214
|
+
* @returns The state of the promise.
|
|
215
|
+
*/
|
|
216
|
+
function state<T>(promise: PromiseLike<T>): PromiseState<T>;
|
|
186
217
|
/**
|
|
187
218
|
* Returns all data if all states are ready.
|
|
188
219
|
* In stale mode, stale data counts as ready.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/async/async.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EAET,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EAET,YAAY,EACZ,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,cAAc,EAEd,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,cAAc,EAEf,MAAM,SAAS,CAAC;AAOjB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources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598 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
function createAsyncContext(abortController, isCancelledOrAborted, cancel, resolver) {
|
|
4
|
-
const safe = createSafe(
|
|
5
|
-
() => abortController.signal,
|
|
6
|
-
isCancelledOrAborted
|
|
7
|
-
);
|
|
8
|
-
return {
|
|
9
|
-
signal: abortController.signal,
|
|
10
|
-
get(specOrFactory) {
|
|
11
|
-
const instance = resolver.get(specOrFactory);
|
|
12
|
-
if (isSpec(specOrFactory)) {
|
|
13
|
-
const store2 = instance;
|
|
14
|
-
return storeTuple(store2);
|
|
15
|
-
}
|
|
16
|
-
return instance;
|
|
17
|
-
},
|
|
18
|
-
safe,
|
|
19
|
-
cancel
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const pendingPromises = /* @__PURE__ */ new WeakMap();
|
|
23
|
-
function getPendingPromise(state) {
|
|
24
|
-
if (state.status === "pending" && "__key" in state && state.__key) {
|
|
25
|
-
return pendingPromises.get(state.__key);
|
|
26
|
-
}
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
function promiseTry(fn) {
|
|
30
|
-
return new Promise((resolve) => {
|
|
31
|
-
resolve(fn());
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function createCancellablePromise(promise, cancel) {
|
|
35
|
-
const cancellable = promise;
|
|
36
|
-
cancellable.cancel = cancel;
|
|
37
|
-
return cancellable;
|
|
38
|
-
}
|
|
39
|
-
function stateToJSON() {
|
|
40
|
-
if (this.mode === "stale") {
|
|
41
|
-
return { status: "success", mode: "stale", data: this.data };
|
|
42
|
-
}
|
|
43
|
-
if (this.status === "success") {
|
|
44
|
-
return { status: "success", mode: "fresh", data: this.data };
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function wrapAbortable(fn) {
|
|
49
|
-
return (ctx, ...args) => {
|
|
50
|
-
return fn.withSignal(ctx.signal, ...args);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function asyncWithFocus(focus, handler, options) {
|
|
54
|
-
if (!focus._storeContext.isSetupPhase()) {
|
|
55
|
-
throw new SetupPhaseError(
|
|
56
|
-
"async.action",
|
|
57
|
-
"async.action() must be called during store setup phase."
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const [getState, setState] = focus;
|
|
61
|
-
const asyncKey = {};
|
|
62
|
-
let lastCancel = null;
|
|
63
|
-
let lastArgs = null;
|
|
64
|
-
let invocationCount = 0;
|
|
65
|
-
function dispatch(...args) {
|
|
66
|
-
return untrack(() => {
|
|
67
|
-
if (lastCancel && (options == null ? void 0 : options.autoCancel) !== false) {
|
|
68
|
-
lastCancel();
|
|
69
|
-
}
|
|
70
|
-
const abortController = new AbortController();
|
|
71
|
-
let isCancelled = false;
|
|
72
|
-
const requestId = {};
|
|
73
|
-
let rejectOnCancel = null;
|
|
74
|
-
const cancelPromise = new Promise((_, reject) => {
|
|
75
|
-
rejectOnCancel = reject;
|
|
76
|
-
});
|
|
77
|
-
const cancel2 = () => {
|
|
78
|
-
if (!isCancelled) {
|
|
79
|
-
isCancelled = true;
|
|
80
|
-
abortController.abort();
|
|
81
|
-
pendingPromises.delete(asyncKey);
|
|
82
|
-
rejectOnCancel == null ? void 0 : rejectOnCancel(new DOMException("Aborted", "AbortError"));
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
lastCancel = cancel2;
|
|
86
|
-
lastArgs = args;
|
|
87
|
-
invocationCount++;
|
|
88
|
-
const prevState = getState();
|
|
89
|
-
const mode = prevState.mode;
|
|
90
|
-
const staleData = mode === "stale" ? prevState.data : prevState.status === "success" ? prevState.data : void 0;
|
|
91
|
-
const autoCancel = (options == null ? void 0 : options.autoCancel) !== false;
|
|
92
|
-
const isStateExternallyModified = () => {
|
|
93
|
-
if (!autoCancel) {
|
|
94
|
-
const currentState2 = getState();
|
|
95
|
-
return currentState2.__requestId === void 0;
|
|
96
|
-
}
|
|
97
|
-
const currentState = getState();
|
|
98
|
-
return currentState.__requestId !== requestId;
|
|
99
|
-
};
|
|
100
|
-
const execute = async () => {
|
|
101
|
-
try {
|
|
102
|
-
const isCancelledOrAborted = () => isCancelled || abortController.signal.aborted;
|
|
103
|
-
const asyncContext = createAsyncContext(
|
|
104
|
-
abortController,
|
|
105
|
-
isCancelledOrAborted,
|
|
106
|
-
cancel2,
|
|
107
|
-
focus._resolver
|
|
108
|
-
);
|
|
109
|
-
const result = await promiseTry(() => handler(asyncContext, ...args));
|
|
110
|
-
if (isCancelled) {
|
|
111
|
-
throw new DOMException("Aborted", "AbortError");
|
|
112
|
-
}
|
|
113
|
-
if (isStateExternallyModified()) {
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
setState({
|
|
117
|
-
status: "success",
|
|
118
|
-
mode,
|
|
119
|
-
data: result,
|
|
120
|
-
error: void 0,
|
|
121
|
-
timestamp: Date.now(),
|
|
122
|
-
__requestId: requestId,
|
|
123
|
-
toJSON: stateToJSON
|
|
124
|
-
});
|
|
125
|
-
if (lastCancel === cancel2) {
|
|
126
|
-
lastCancel = null;
|
|
127
|
-
}
|
|
128
|
-
return result;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
if (isCancelled || abortController.signal.aborted) {
|
|
131
|
-
throw error instanceof Error ? error : new DOMException("Aborted", "AbortError");
|
|
132
|
-
}
|
|
133
|
-
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
134
|
-
if (!abortController.signal.aborted) {
|
|
135
|
-
abortController.abort();
|
|
136
|
-
}
|
|
137
|
-
if (isStateExternallyModified()) {
|
|
138
|
-
throw errorObj;
|
|
139
|
-
}
|
|
140
|
-
setState({
|
|
141
|
-
status: "error",
|
|
142
|
-
mode,
|
|
143
|
-
data: mode === "stale" ? staleData : void 0,
|
|
144
|
-
error: errorObj,
|
|
145
|
-
timestamp: void 0,
|
|
146
|
-
__requestId: requestId,
|
|
147
|
-
toJSON: stateToJSON
|
|
148
|
-
});
|
|
149
|
-
if (lastCancel === cancel2) {
|
|
150
|
-
lastCancel = null;
|
|
151
|
-
}
|
|
152
|
-
throw errorObj;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const executionPromise = execute();
|
|
156
|
-
const promise = Promise.race([executionPromise, cancelPromise]);
|
|
157
|
-
pendingPromises.set(asyncKey, executionPromise);
|
|
158
|
-
setState({
|
|
159
|
-
status: "pending",
|
|
160
|
-
mode,
|
|
161
|
-
data: mode === "stale" ? staleData : void 0,
|
|
162
|
-
error: void 0,
|
|
163
|
-
timestamp: void 0,
|
|
164
|
-
__key: asyncKey,
|
|
165
|
-
__requestId: requestId,
|
|
166
|
-
toJSON: stateToJSON
|
|
167
|
-
});
|
|
168
|
-
promise.then(
|
|
169
|
-
() => pendingPromises.delete(asyncKey),
|
|
170
|
-
() => pendingPromises.delete(asyncKey)
|
|
171
|
-
);
|
|
172
|
-
return createCancellablePromise(promise, cancel2);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function refresh() {
|
|
176
|
-
if (lastArgs === null) {
|
|
177
|
-
return void 0;
|
|
178
|
-
}
|
|
179
|
-
return dispatch(...lastArgs);
|
|
180
|
-
}
|
|
181
|
-
function cancel() {
|
|
182
|
-
if (lastCancel) {
|
|
183
|
-
lastCancel();
|
|
184
|
-
lastCancel = null;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function reset() {
|
|
188
|
-
cancel();
|
|
189
|
-
lastArgs = null;
|
|
190
|
-
const currentState = getState();
|
|
191
|
-
const mode = currentState.mode;
|
|
192
|
-
const resetRequestId = {};
|
|
193
|
-
if (mode === "stale") {
|
|
194
|
-
setState({
|
|
195
|
-
status: "idle",
|
|
196
|
-
mode: "stale",
|
|
197
|
-
data: currentState.data,
|
|
198
|
-
error: void 0,
|
|
199
|
-
timestamp: void 0,
|
|
200
|
-
__requestId: resetRequestId,
|
|
201
|
-
toJSON: stateToJSON
|
|
202
|
-
});
|
|
203
|
-
} else {
|
|
204
|
-
setState({
|
|
205
|
-
status: "idle",
|
|
206
|
-
mode: "fresh",
|
|
207
|
-
data: void 0,
|
|
208
|
-
error: void 0,
|
|
209
|
-
timestamp: void 0,
|
|
210
|
-
__requestId: resetRequestId,
|
|
211
|
-
toJSON: stateToJSON
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function last() {
|
|
216
|
-
const hasDispatched = !!lastArgs;
|
|
217
|
-
if (!hasDispatched) {
|
|
218
|
-
return void 0;
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
args: lastArgs,
|
|
222
|
-
nth: invocationCount,
|
|
223
|
-
// Read state to trigger reactivity (via focus getter) - this is the only tracked read
|
|
224
|
-
state: getState()
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
if (options == null ? void 0 : options.autoCancel) {
|
|
228
|
-
focus._storeContext.onDispose(() => {
|
|
229
|
-
cancel();
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
dispatch,
|
|
234
|
-
refresh,
|
|
235
|
-
cancel,
|
|
236
|
-
reset,
|
|
237
|
-
last
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function asyncState(mode, status, dataOrError, errorOrExtra, extra) {
|
|
241
|
-
let state;
|
|
242
|
-
if (mode === "fresh") {
|
|
243
|
-
switch (status) {
|
|
244
|
-
case "idle":
|
|
245
|
-
state = {
|
|
246
|
-
status: "idle",
|
|
247
|
-
mode: "fresh",
|
|
248
|
-
data: void 0,
|
|
249
|
-
error: void 0,
|
|
250
|
-
timestamp: void 0,
|
|
251
|
-
toJSON: stateToJSON
|
|
252
|
-
};
|
|
253
|
-
break;
|
|
254
|
-
case "pending":
|
|
255
|
-
state = {
|
|
256
|
-
status: "pending",
|
|
257
|
-
mode: "fresh",
|
|
258
|
-
data: void 0,
|
|
259
|
-
error: void 0,
|
|
260
|
-
timestamp: void 0,
|
|
261
|
-
...dataOrError,
|
|
262
|
-
toJSON: stateToJSON
|
|
263
|
-
};
|
|
264
|
-
break;
|
|
265
|
-
case "success":
|
|
266
|
-
state = {
|
|
267
|
-
status: "success",
|
|
268
|
-
mode: "fresh",
|
|
269
|
-
data: dataOrError,
|
|
270
|
-
error: void 0,
|
|
271
|
-
timestamp: Date.now(),
|
|
272
|
-
toJSON: stateToJSON
|
|
273
|
-
};
|
|
274
|
-
break;
|
|
275
|
-
case "error":
|
|
276
|
-
state = {
|
|
277
|
-
status: "error",
|
|
278
|
-
mode: "fresh",
|
|
279
|
-
data: void 0,
|
|
280
|
-
error: dataOrError,
|
|
281
|
-
timestamp: void 0,
|
|
282
|
-
...errorOrExtra,
|
|
283
|
-
toJSON: stateToJSON
|
|
284
|
-
};
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
switch (status) {
|
|
289
|
-
case "idle":
|
|
290
|
-
state = {
|
|
291
|
-
status: "idle",
|
|
292
|
-
mode: "stale",
|
|
293
|
-
data: dataOrError,
|
|
294
|
-
error: void 0,
|
|
295
|
-
timestamp: void 0,
|
|
296
|
-
toJSON: stateToJSON
|
|
297
|
-
};
|
|
298
|
-
break;
|
|
299
|
-
case "pending":
|
|
300
|
-
state = {
|
|
301
|
-
status: "pending",
|
|
302
|
-
mode: "stale",
|
|
303
|
-
data: dataOrError,
|
|
304
|
-
error: void 0,
|
|
305
|
-
timestamp: void 0,
|
|
306
|
-
...errorOrExtra,
|
|
307
|
-
toJSON: stateToJSON
|
|
308
|
-
};
|
|
309
|
-
break;
|
|
310
|
-
case "success":
|
|
311
|
-
state = {
|
|
312
|
-
status: "success",
|
|
313
|
-
mode: "stale",
|
|
314
|
-
data: dataOrError,
|
|
315
|
-
error: void 0,
|
|
316
|
-
timestamp: Date.now(),
|
|
317
|
-
toJSON: stateToJSON
|
|
318
|
-
};
|
|
319
|
-
break;
|
|
320
|
-
case "error":
|
|
321
|
-
state = {
|
|
322
|
-
status: "error",
|
|
323
|
-
mode: "stale",
|
|
324
|
-
data: dataOrError,
|
|
325
|
-
error: errorOrExtra,
|
|
326
|
-
timestamp: void 0,
|
|
327
|
-
...extra,
|
|
328
|
-
toJSON: stateToJSON
|
|
329
|
-
};
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return Object.freeze(state);
|
|
334
|
-
}
|
|
335
|
-
function asyncStateFrom(prev, status, dataOrError) {
|
|
336
|
-
const mode = prev.mode;
|
|
337
|
-
const staleData = mode === "stale" ? prev.data : void 0;
|
|
338
|
-
if (mode === "stale") {
|
|
339
|
-
switch (status) {
|
|
340
|
-
case "idle":
|
|
341
|
-
return asyncState("stale", "idle", staleData);
|
|
342
|
-
case "pending":
|
|
343
|
-
return asyncState("stale", "pending", staleData);
|
|
344
|
-
case "success":
|
|
345
|
-
return asyncState("stale", "success", dataOrError);
|
|
346
|
-
case "error":
|
|
347
|
-
return asyncState(
|
|
348
|
-
"stale",
|
|
349
|
-
"error",
|
|
350
|
-
staleData,
|
|
351
|
-
dataOrError
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
} else {
|
|
355
|
-
switch (status) {
|
|
356
|
-
case "idle":
|
|
357
|
-
return asyncState("fresh", "idle");
|
|
358
|
-
case "pending":
|
|
359
|
-
return asyncState("fresh", "pending");
|
|
360
|
-
case "success":
|
|
361
|
-
return asyncState("fresh", "success", dataOrError);
|
|
362
|
-
case "error":
|
|
363
|
-
return asyncState("fresh", "error", dataOrError);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
asyncState.from = asyncStateFrom;
|
|
368
|
-
var async;
|
|
369
|
-
((async2) => {
|
|
370
|
-
function fresh() {
|
|
371
|
-
return asyncState("fresh", "idle");
|
|
372
|
-
}
|
|
373
|
-
async2.fresh = fresh;
|
|
374
|
-
function stale(initialData) {
|
|
375
|
-
return asyncState("stale", "idle", initialData);
|
|
376
|
-
}
|
|
377
|
-
async2.stale = stale;
|
|
378
|
-
function action(focus, handlerOrAbortable, options) {
|
|
379
|
-
const handler = isAbortable(handlerOrAbortable) ? wrapAbortable(handlerOrAbortable) : handlerOrAbortable;
|
|
380
|
-
return asyncWithFocus(focus, handler, options);
|
|
381
|
-
}
|
|
382
|
-
async2.action = action;
|
|
383
|
-
function mixin(handlerOrAbortable, options) {
|
|
384
|
-
const handler = isAbortable(handlerOrAbortable) ? wrapAbortable(handlerOrAbortable) : handlerOrAbortable;
|
|
385
|
-
const initialState = (options == null ? void 0 : options.initial) ?? asyncState("fresh", "idle");
|
|
386
|
-
const asyncSpec = store({
|
|
387
|
-
name: (options == null ? void 0 : options.name) ?? `async:${handler.name || "anonymous"}`,
|
|
388
|
-
state: { result: initialState },
|
|
389
|
-
meta: options == null ? void 0 : options.meta,
|
|
390
|
-
setup(storeContext) {
|
|
391
|
-
const { focus } = storeContext;
|
|
392
|
-
const actions = asyncWithFocus(
|
|
393
|
-
focus("result"),
|
|
394
|
-
(asyncContext, ...args) => {
|
|
395
|
-
return handler(asyncContext, ...args);
|
|
396
|
-
},
|
|
397
|
-
options
|
|
398
|
-
);
|
|
399
|
-
return actions;
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
return (context) => {
|
|
403
|
-
const [state, actions] = context.scoped(asyncSpec);
|
|
404
|
-
return [state.result, actions];
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
async2.mixin = mixin;
|
|
408
|
-
function delay(ms, resolved) {
|
|
409
|
-
let timeout2;
|
|
410
|
-
return createCancellablePromise(
|
|
411
|
-
new Promise((resolve) => {
|
|
412
|
-
timeout2 = setTimeout(resolve, ms, resolved);
|
|
413
|
-
}),
|
|
414
|
-
() => {
|
|
415
|
-
clearTimeout(timeout2);
|
|
416
|
-
}
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
async2.delay = delay;
|
|
420
|
-
async2.invoke = promiseTry;
|
|
421
|
-
function wait(state) {
|
|
422
|
-
if (state.status === "success") {
|
|
423
|
-
return state.data;
|
|
424
|
-
}
|
|
425
|
-
if (state.mode === "stale" && state.data !== void 0) {
|
|
426
|
-
return state.data;
|
|
427
|
-
}
|
|
428
|
-
if (state.status === "error") {
|
|
429
|
-
throw state.error;
|
|
430
|
-
}
|
|
431
|
-
if (state.status === "pending") {
|
|
432
|
-
const promise = getPendingPromise(state);
|
|
433
|
-
if (promise) {
|
|
434
|
-
throw promise;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
const message = state.status === "idle" ? `Cannot wait: state is idle. Call dispatch() or use trigger() to start the async operation before calling async.wait().` : `Cannot wait: state is ${state.status}`;
|
|
438
|
-
throw new AsyncNotReadyError(message, state.status);
|
|
439
|
-
}
|
|
440
|
-
async2.wait = wait;
|
|
441
|
-
function race(states) {
|
|
442
|
-
for (const key in states) {
|
|
443
|
-
if (Object.prototype.hasOwnProperty.call(states, key)) {
|
|
444
|
-
const state = states[key];
|
|
445
|
-
if (state.status === "success") {
|
|
446
|
-
return [key, state.data];
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
for (const key in states) {
|
|
451
|
-
if (Object.prototype.hasOwnProperty.call(states, key)) {
|
|
452
|
-
const state = states[key];
|
|
453
|
-
if (state.mode === "stale" && state.data !== void 0) {
|
|
454
|
-
return [key, state.data];
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
for (const key in states) {
|
|
459
|
-
if (Object.prototype.hasOwnProperty.call(states, key)) {
|
|
460
|
-
const state = states[key];
|
|
461
|
-
if (state.status === "error") {
|
|
462
|
-
throw state.error;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
throw new AsyncNotReadyError(
|
|
467
|
-
"No async state has resolved successfully",
|
|
468
|
-
"pending"
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
async2.race = race;
|
|
472
|
-
function all(...states) {
|
|
473
|
-
const results = [];
|
|
474
|
-
for (let i = 0; i < states.length; i++) {
|
|
475
|
-
const state = states[i];
|
|
476
|
-
if (state.status === "success") {
|
|
477
|
-
results.push(state.data);
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
if (state.mode === "stale" && state.data !== void 0) {
|
|
481
|
-
results.push(state.data);
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
if (state.status === "error") {
|
|
485
|
-
throw state.error;
|
|
486
|
-
}
|
|
487
|
-
throw new AsyncNotReadyError(
|
|
488
|
-
`State at index ${i} is ${state.status}`,
|
|
489
|
-
state.status
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
return results;
|
|
493
|
-
}
|
|
494
|
-
async2.all = all;
|
|
495
|
-
function any(...states) {
|
|
496
|
-
const errors = [];
|
|
497
|
-
for (const state of states) {
|
|
498
|
-
if (state.status === "success") {
|
|
499
|
-
return state.data;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
for (const state of states) {
|
|
503
|
-
if (state.mode === "stale" && state.data !== void 0) {
|
|
504
|
-
return state.data;
|
|
505
|
-
}
|
|
506
|
-
if (state.status === "error") {
|
|
507
|
-
errors.push(state.error);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (errors.length === states.length) {
|
|
511
|
-
throw new AsyncAggregateError("All async states have errors", errors);
|
|
512
|
-
}
|
|
513
|
-
throw new AsyncNotReadyError(
|
|
514
|
-
"No async state has resolved successfully",
|
|
515
|
-
"pending"
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
async2.any = any;
|
|
519
|
-
function settled(...states) {
|
|
520
|
-
const results = [];
|
|
521
|
-
for (const state of states) {
|
|
522
|
-
switch (state.status) {
|
|
523
|
-
case "success":
|
|
524
|
-
results.push({ status: "success", data: state.data });
|
|
525
|
-
break;
|
|
526
|
-
case "error":
|
|
527
|
-
results.push({
|
|
528
|
-
status: "error",
|
|
529
|
-
error: state.error,
|
|
530
|
-
data: state.mode === "stale" ? state.data : void 0
|
|
531
|
-
});
|
|
532
|
-
break;
|
|
533
|
-
case "pending":
|
|
534
|
-
results.push({
|
|
535
|
-
status: "pending",
|
|
536
|
-
data: state.mode === "stale" ? state.data : void 0
|
|
537
|
-
});
|
|
538
|
-
break;
|
|
539
|
-
case "idle":
|
|
540
|
-
results.push({
|
|
541
|
-
status: "idle",
|
|
542
|
-
data: state.mode === "stale" ? state.data : void 0
|
|
543
|
-
});
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return results;
|
|
548
|
-
}
|
|
549
|
-
async2.settled = settled;
|
|
550
|
-
function hasData(state) {
|
|
551
|
-
if (state.status === "success") return true;
|
|
552
|
-
if (state.mode === "stale" && state.data !== void 0) return true;
|
|
553
|
-
return false;
|
|
554
|
-
}
|
|
555
|
-
async2.hasData = hasData;
|
|
556
|
-
function isLoading(state) {
|
|
557
|
-
return state.status === "pending";
|
|
558
|
-
}
|
|
559
|
-
async2.isLoading = isLoading;
|
|
560
|
-
function isError(state) {
|
|
561
|
-
return state.status === "error";
|
|
562
|
-
}
|
|
563
|
-
async2.isError = isError;
|
|
564
|
-
function derive(focus, computeFn) {
|
|
565
|
-
const [getState, setState] = focus;
|
|
566
|
-
let hasSetPending = false;
|
|
567
|
-
return effect((ctx) => {
|
|
568
|
-
const currentState = untrack(getState);
|
|
569
|
-
try {
|
|
570
|
-
const result = computeFn();
|
|
571
|
-
if (result !== null && result !== void 0 && typeof result.then === "function") {
|
|
572
|
-
throw new AsyncFunctionError(
|
|
573
|
-
"async.derive computeFn",
|
|
574
|
-
"Use async.wait() for async values, not async/await or returning promises."
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
hasSetPending = false;
|
|
578
|
-
setState(asyncState.from(currentState, "success", result));
|
|
579
|
-
} catch (ex) {
|
|
580
|
-
if (ex !== null && ex !== void 0 && typeof ex.then === "function") {
|
|
581
|
-
if (!hasSetPending) {
|
|
582
|
-
hasSetPending = true;
|
|
583
|
-
setState(asyncState.from(currentState, "pending"));
|
|
584
|
-
}
|
|
585
|
-
ctx.safe(ex).then(ctx.refresh, ctx.refresh);
|
|
586
|
-
} else {
|
|
587
|
-
hasSetPending = false;
|
|
588
|
-
const error = ex instanceof Error ? ex : new Error(String(ex));
|
|
589
|
-
setState(asyncState.from(currentState, "error", error));
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
async2.derive = derive;
|
|
595
|
-
})(async || (async = {}));
|
|
1
|
+
import { r as retryStrategy } from "../effect-BfoYEdFF.js";
|
|
2
|
+
import { d, A, b, a, c, i } from "../effect-BfoYEdFF.js";
|
|
596
3
|
function retry(retriesOrStrategyOrOptions) {
|
|
597
4
|
const options = typeof retriesOrStrategyOrOptions === "number" ? { retries: retriesOrStrategyOrOptions } : typeof retriesOrStrategyOrOptions === "string" ? { delay: retriesOrStrategyOrOptions } : retriesOrStrategyOrOptions ?? {};
|
|
598
5
|
const retries = options.retries ?? 3;
|
|
@@ -846,17 +253,17 @@ function map(mapper) {
|
|
|
846
253
|
};
|
|
847
254
|
}
|
|
848
255
|
export {
|
|
849
|
-
AsyncAggregateError,
|
|
850
|
-
AsyncNotReadyError,
|
|
851
|
-
|
|
852
|
-
async,
|
|
256
|
+
d as AsyncAggregateError,
|
|
257
|
+
A as AsyncNotReadyError,
|
|
258
|
+
b as abortable,
|
|
259
|
+
a as async,
|
|
853
260
|
cache,
|
|
854
261
|
catchError,
|
|
855
262
|
circuitBreaker,
|
|
856
|
-
createSafe,
|
|
263
|
+
c as createSafe,
|
|
857
264
|
debounce,
|
|
858
265
|
fallback,
|
|
859
|
-
isAbortable,
|
|
266
|
+
i as isAbortable,
|
|
860
267
|
logging,
|
|
861
268
|
map,
|
|
862
269
|
rateLimit,
|