@filen/utils 0.0.5 → 0.0.6
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/run.js +17 -21
- package/dist/types/run.d.ts +9 -9
- package/package.json +1 -1
package/dist/run.js
CHANGED
|
@@ -23,15 +23,14 @@ export function run(fn, options) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
|
-
|
|
27
|
-
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
26
|
+
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, e);
|
|
28
27
|
if (options === null || options === void 0 ? void 0 : options.throw) {
|
|
29
|
-
throw
|
|
28
|
+
throw e;
|
|
30
29
|
}
|
|
31
30
|
return {
|
|
32
31
|
success: false,
|
|
33
32
|
data: null,
|
|
34
|
-
error:
|
|
33
|
+
error: e
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
finally {
|
|
@@ -40,7 +39,7 @@ export function run(fn, options) {
|
|
|
40
39
|
yield ((_b = deferredFunctions[i]) === null || _b === void 0 ? void 0 : _b.call(deferredFunctions));
|
|
41
40
|
}
|
|
42
41
|
catch (e) {
|
|
43
|
-
(_c = options === null || options === void 0 ? void 0 : options.onError) === null || _c === void 0 ? void 0 : _c.call(options, e
|
|
42
|
+
(_c = options === null || options === void 0 ? void 0 : options.onError) === null || _c === void 0 ? void 0 : _c.call(options, e);
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
}
|
|
@@ -103,8 +102,8 @@ export function runAbortable(fn, options) {
|
|
|
103
102
|
}
|
|
104
103
|
resolve(result);
|
|
105
104
|
}
|
|
106
|
-
catch (
|
|
107
|
-
reject(
|
|
105
|
+
catch (e) {
|
|
106
|
+
reject(e);
|
|
108
107
|
}
|
|
109
108
|
finally {
|
|
110
109
|
signal.removeEventListener("abort", abortHandler);
|
|
@@ -132,15 +131,14 @@ export function runAbortable(fn, options) {
|
|
|
132
131
|
};
|
|
133
132
|
}
|
|
134
133
|
catch (e) {
|
|
135
|
-
|
|
136
|
-
(_e = options === null || options === void 0 ? void 0 : options.onError) === null || _e === void 0 ? void 0 : _e.call(options, error);
|
|
134
|
+
(_e = options === null || options === void 0 ? void 0 : options.onError) === null || _e === void 0 ? void 0 : _e.call(options, e);
|
|
137
135
|
if (options === null || options === void 0 ? void 0 : options.throw) {
|
|
138
|
-
throw
|
|
136
|
+
throw e;
|
|
139
137
|
}
|
|
140
138
|
return {
|
|
141
139
|
success: false,
|
|
142
140
|
data: null,
|
|
143
|
-
error:
|
|
141
|
+
error: e
|
|
144
142
|
};
|
|
145
143
|
}
|
|
146
144
|
finally {
|
|
@@ -149,7 +147,7 @@ export function runAbortable(fn, options) {
|
|
|
149
147
|
yield ((_f = deferredFunctions[i]) === null || _f === void 0 ? void 0 : _f.call(deferredFunctions));
|
|
150
148
|
}
|
|
151
149
|
catch (e) {
|
|
152
|
-
(_g = options === null || options === void 0 ? void 0 : options.onError) === null || _g === void 0 ? void 0 : _g.call(options, e
|
|
150
|
+
(_g = options === null || options === void 0 ? void 0 : options.onError) === null || _g === void 0 ? void 0 : _g.call(options, e);
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
}
|
|
@@ -168,7 +166,7 @@ export function runEffect(fn, options) {
|
|
|
168
166
|
(_a = deferredFunctions[i]) === null || _a === void 0 ? void 0 : _a.call(deferredFunctions);
|
|
169
167
|
}
|
|
170
168
|
catch (e) {
|
|
171
|
-
(_b = options === null || options === void 0 ? void 0 : options.onError) === null || _b === void 0 ? void 0 : _b.call(options, e
|
|
169
|
+
(_b = options === null || options === void 0 ? void 0 : options.onError) === null || _b === void 0 ? void 0 : _b.call(options, e);
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
};
|
|
@@ -182,15 +180,14 @@ export function runEffect(fn, options) {
|
|
|
182
180
|
};
|
|
183
181
|
}
|
|
184
182
|
catch (e) {
|
|
185
|
-
|
|
186
|
-
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
183
|
+
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, e);
|
|
187
184
|
if (options === null || options === void 0 ? void 0 : options.throw) {
|
|
188
|
-
throw
|
|
185
|
+
throw e;
|
|
189
186
|
}
|
|
190
187
|
return {
|
|
191
188
|
success: false,
|
|
192
189
|
data: null,
|
|
193
|
-
error:
|
|
190
|
+
error: e,
|
|
194
191
|
cleanup
|
|
195
192
|
};
|
|
196
193
|
}
|
|
@@ -258,15 +255,14 @@ export function runTimeout(fn, timeoutMs, options) {
|
|
|
258
255
|
return result;
|
|
259
256
|
}
|
|
260
257
|
catch (e) {
|
|
261
|
-
|
|
262
|
-
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
258
|
+
(_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, e);
|
|
263
259
|
if (options === null || options === void 0 ? void 0 : options.throw) {
|
|
264
|
-
throw
|
|
260
|
+
throw e;
|
|
265
261
|
}
|
|
266
262
|
return {
|
|
267
263
|
success: false,
|
|
268
264
|
data: null,
|
|
269
|
-
error:
|
|
265
|
+
error: e
|
|
270
266
|
};
|
|
271
267
|
}
|
|
272
268
|
});
|
package/dist/types/run.d.ts
CHANGED
|
@@ -3,21 +3,21 @@ export type Success<T> = {
|
|
|
3
3
|
data: T;
|
|
4
4
|
error: null;
|
|
5
5
|
};
|
|
6
|
-
export type Failure<E =
|
|
6
|
+
export type Failure<E = unknown> = {
|
|
7
7
|
success: false;
|
|
8
8
|
data: null;
|
|
9
9
|
error: E;
|
|
10
10
|
};
|
|
11
|
-
export type Result<T, E =
|
|
11
|
+
export type Result<T, E = unknown> = Success<T> | Failure<E>;
|
|
12
12
|
export type GenericFnResult = number | boolean | string | object | null | undefined | symbol | bigint | void | Promise<number | boolean | string | object | null | undefined | symbol | bigint | void> | Array<number | boolean | string | object | null | undefined | symbol | bigint | void>;
|
|
13
13
|
export type DeferFn = (fn: () => GenericFnResult) => void;
|
|
14
14
|
export type DeferredFunction = () => GenericFnResult;
|
|
15
15
|
export type DeferredFunctions = Array<DeferredFunction>;
|
|
16
16
|
export type Options = {
|
|
17
17
|
throw?: boolean;
|
|
18
|
-
onError?: (err:
|
|
18
|
+
onError?: (err: unknown) => void;
|
|
19
19
|
};
|
|
20
|
-
export declare function run<TResult, E =
|
|
20
|
+
export declare function run<TResult, E = unknown>(fn: (deferFn: DeferFn) => Promise<TResult> | TResult, options?: Options): Promise<Result<TResult, E>>;
|
|
21
21
|
export type AbortableFn = (abortableFn: () => GenericFnResult, opts?: {
|
|
22
22
|
signal?: AbortSignal;
|
|
23
23
|
}) => GenericFnResult;
|
|
@@ -25,7 +25,7 @@ export declare class AbortError extends Error {
|
|
|
25
25
|
constructor(message?: string);
|
|
26
26
|
}
|
|
27
27
|
export declare function abortSignalReason(signal: AbortSignal): string | undefined;
|
|
28
|
-
export declare function runAbortable<TResult, E =
|
|
28
|
+
export declare function runAbortable<TResult, E = unknown>(fn: ({ abortable, defer, signal, controller }: {
|
|
29
29
|
abortable: AbortableFn;
|
|
30
30
|
defer: DeferFn;
|
|
31
31
|
signal: AbortSignal;
|
|
@@ -34,12 +34,12 @@ export declare function runAbortable<TResult, E = Error>(fn: ({ abortable, defer
|
|
|
34
34
|
controller?: AbortController;
|
|
35
35
|
signal?: AbortSignal;
|
|
36
36
|
}): Promise<Result<TResult, E>>;
|
|
37
|
-
export declare function runEffect<TResult, E =
|
|
37
|
+
export declare function runEffect<TResult, E = unknown>(fn: (deferFn: DeferFn) => TResult, options?: Options & {
|
|
38
38
|
automaticCleanup?: boolean;
|
|
39
39
|
}): Result<TResult, E> & {
|
|
40
40
|
cleanup: () => void;
|
|
41
41
|
};
|
|
42
|
-
export declare function runRetry<TResult, E =
|
|
42
|
+
export declare function runRetry<TResult, E = unknown>(fn: (deferFn: DeferFn, attempt: number) => Promise<TResult> | TResult, options?: Options & {
|
|
43
43
|
maxAttempts?: number;
|
|
44
44
|
delayMs?: number;
|
|
45
45
|
backoff?: "linear" | "exponential";
|
|
@@ -49,6 +49,6 @@ export declare function runRetry<TResult, E = Error>(fn: (deferFn: DeferFn, atte
|
|
|
49
49
|
export declare class TimeoutError extends Error {
|
|
50
50
|
constructor(message?: string);
|
|
51
51
|
}
|
|
52
|
-
export declare function runTimeout<TResult, E =
|
|
53
|
-
export declare function runDebounced<TResult, TArgs extends unknown[]>(fn: (defer: DeferFn, ...args: TArgs) => Promise<TResult> | TResult, delayMs: number, options?: Options): (...args: TArgs) => Promise<Result<TResult,
|
|
52
|
+
export declare function runTimeout<TResult, E = unknown>(fn: (deferFn: DeferFn) => Promise<TResult> | TResult, timeoutMs: number, options?: Options): Promise<Result<TResult, E>>;
|
|
53
|
+
export declare function runDebounced<TResult, TArgs extends unknown[]>(fn: (defer: DeferFn, ...args: TArgs) => Promise<TResult> | TResult, delayMs: number, options?: Options): (...args: TArgs) => Promise<Result<TResult, unknown>>;
|
|
54
54
|
export default run;
|