mini-effect 0.0.3 → 0.0.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.
- package/dist/fetch.d.mts +8 -7
- package/dist/mini-effect.d.mts +3 -2
- package/dist/mini-effect.mjs +5 -1
- package/package.json +1 -1
package/dist/fetch.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Effect } from "./mini-effect.mjs";
|
|
2
|
-
import { FailureConstructor } from "./tag.mjs";
|
|
2
|
+
import { Failure, FailureConstructor } from "./tag.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/fetch.d.ts
|
|
5
|
+
declare const FailedToFetchError: FailureConstructor<"FailedToFetch">;
|
|
5
6
|
declare const FailedToReadError: FailureConstructor<"FailedToRead">;
|
|
6
|
-
declare const request: (input: string | URL, init?: RequestInit) => Effect<Response,
|
|
7
|
-
declare const blob: (response: Response) => Effect<
|
|
8
|
-
declare const bytes: (response: Response) => Effect<
|
|
9
|
-
declare const formData: (response: Response) => Effect<
|
|
10
|
-
declare const json: (response: Response) => Effect<unknown, typeof FailedToReadError
|
|
11
|
-
declare const text: (response: Response) => Effect<
|
|
7
|
+
declare const request: (input: string | URL, init?: RequestInit) => Effect<Response, InstanceType<typeof FailedToFetchError>>;
|
|
8
|
+
declare const blob: (response: Response) => Effect<Blob, Failure<"FailedToRead">>;
|
|
9
|
+
declare const bytes: (response: Response) => Effect<Uint8Array<ArrayBuffer>, Failure<"FailedToRead">>;
|
|
10
|
+
declare const formData: (response: Response) => Effect<FormData, Failure<"FailedToRead">>;
|
|
11
|
+
declare const json: (response: Response) => Effect<unknown, InstanceType<typeof FailedToReadError>>;
|
|
12
|
+
declare const text: (response: Response) => Effect<string, Failure<"FailedToRead">>;
|
|
12
13
|
//#endregion
|
|
13
14
|
export { blob, bytes, formData, json, request, text };
|
package/dist/mini-effect.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ declare const succeed: <R$1>(result: R$1) => Effect<R$1, never>;
|
|
|
10
10
|
declare const catchSome: <T = any, C = any, CE = any>(thunk: (cause: unknown) => Effect<T, C> | undefined) => WrapEffect<T, C, CE>;
|
|
11
11
|
declare const gen: <T extends Effect<any, any>, TReturn, TNext>(thunk: (signal: AbortSignal) => Generator<T, TReturn, TNext>) => Effect<TReturn, inferError<T>>;
|
|
12
12
|
declare const pipe: <F extends Effect, P$1 extends [Pipeable, ...Pipeable[]]>(first: F, ...pipeable: PipeReturn<[F, ...P$1]> extends never ? never : P$1) => PipeReturn<[F, ...P$1]>;
|
|
13
|
+
declare const retry: <R$1 extends number | "forever", T, C>(times: R$1, effect: Effect<T, C>) => Effect<T, R$1 extends "forever" ? never : C>;
|
|
13
14
|
declare class Effect<T = any, C = any> {
|
|
14
15
|
[RUN]?: (signal: AbortSignal) => T | PromiseLike<T>;
|
|
15
16
|
[ERROR]?: (cause: unknown) => Effect | undefined;
|
|
@@ -32,10 +33,10 @@ type inferReturn<T> = T extends WrapEffect<infer R> ? R : T extends Effect<infer
|
|
|
32
33
|
type inferError<T> = T extends PipeableThunk<any, infer E> ? E : T extends WrapEffect<any, infer E> ? E : T extends Effect<any, infer E> ? E : never;
|
|
33
34
|
type inferExclude<T> = T extends WrapEffect<any, any, infer CE> ? CE : never;
|
|
34
35
|
type Simplify<T> = T extends Effect<infer R, infer E> ? Effect<R, E> : never;
|
|
35
|
-
type PipeReturn<F extends Pipeable[]> = IsNever<CheckPipe<F>> extends true ? never : Simplify<Effect<inferReturn<CheckPipe<F>> | inferReturn<Extract<F[number], WrapEffect
|
|
36
|
+
type PipeReturn<F extends Pipeable[]> = IsNever<CheckPipe<F>> extends true ? never : Simplify<Effect<inferReturn<CheckPipe<F>> | inferReturn<Extract<F[number], WrapEffect>>, Exclude<inferError<F[number]>, inferExclude<Extract<F[number], WrapEffect>>>>>;
|
|
36
37
|
type CheckPipe<F extends Pipeable[]> = F extends [Effect, WrapEffect, ...infer R] ? R extends [Pipeable, ...Pipeable[]] ? CheckPipe<R> : F[0] : F extends [Pipeable, Pipeable, ...infer P] ? ExtendsStrict<inferReturn<F[0]>, inferInput<F[1]>> extends true ? P extends Pipeable[] ? CheckPipe<[F[1], ...P]> : never : never : F extends [WrapEffect] ? Effect<inferReturn<F[0]>> : F extends [Pipeable] ? F[0] : never;
|
|
37
38
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
38
39
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
39
40
|
type ExtendsStrict<Left, Right> = IsAny<Left | Right> extends true ? true : IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
|
|
40
41
|
//#endregion
|
|
41
|
-
export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, succeed };
|
|
42
|
+
export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, retry, succeed };
|
package/dist/mini-effect.mjs
CHANGED
|
@@ -45,6 +45,10 @@ const pipe = (first, ...pipeable) => {
|
|
|
45
45
|
return next;
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
+
const retry = (times, effect) => {
|
|
49
|
+
let step = 0;
|
|
50
|
+
return effect.pipe(catchSome((cause) => typeof times === "number" && ++step > times ? fail(cause) : effect));
|
|
51
|
+
};
|
|
48
52
|
var Effect = class {
|
|
49
53
|
[RUN];
|
|
50
54
|
[ERROR];
|
|
@@ -97,4 +101,4 @@ var WrapEffect = class {
|
|
|
97
101
|
};
|
|
98
102
|
|
|
99
103
|
//#endregion
|
|
100
|
-
export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, succeed };
|
|
104
|
+
export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, retry, succeed };
|