@goodbyenjn/utils 26.3.0 → 26.4.0
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/README.md +53 -31
- package/dist/chunks/chunk-3c6f28c7.d.ts +39 -0
- package/dist/chunks/{chunk-5ed3bc8a.js → chunk-486f65b0.js} +190 -324
- package/dist/chunks/chunk-704a1835.d.ts +174 -0
- package/dist/chunks/chunk-7ffde8d4.js +43 -0
- package/dist/chunks/chunk-b61db0a7.js +27 -0
- package/dist/common.d.ts +8 -16
- package/dist/common.js +1 -1
- package/dist/fs.d.ts +2 -5
- package/dist/fs.js +239 -588
- package/dist/global-types.d.ts +89 -59
- package/dist/remeda.d.ts +10 -12288
- package/dist/remeda.js +2 -2
- package/dist/result.d.ts +2 -2
- package/dist/result.js +2 -2
- package/dist/shell.d.ts +4 -14
- package/dist/shell.js +290 -290
- package/dist/types.d.ts +3 -2
- package/package.json +14 -11
- package/dist/chunks/chunk-b970a8d0.js +0 -2782
- package/dist/chunks/chunk-d1860346.d.ts +0 -154
- package/dist/chunks/chunk-e931fe39.d.ts +0 -11978
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { jn as NonEmptyTuple, ri as AsyncFn, si as SyncFn } from "./chunk-e931fe39.js";
|
|
2
|
-
|
|
3
|
-
//#region src/result/error.d.ts
|
|
4
|
-
declare class ResultError extends Error {
|
|
5
|
-
#private;
|
|
6
|
-
static isResultError(value: unknown): value is ResultError;
|
|
7
|
-
constructor(message: string | undefined, error: unknown, contexts: string[], caller?: Function);
|
|
8
|
-
get msg(): string;
|
|
9
|
-
get ctx(): string[];
|
|
10
|
-
toString(): string;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/result/types.d.ts
|
|
14
|
-
type ExtractOkTypes<T extends readonly Result[]> = { [K in keyof T]: T[K] extends Result<infer U, unknown> ? U : never };
|
|
15
|
-
type ExtractErrTypes<T extends readonly Result[]> = { [K in keyof T]: T[K] extends Result<unknown, infer E> ? E : never };
|
|
16
|
-
type InferOkType<R$1> = R$1 extends Result<infer T, unknown> ? T : never;
|
|
17
|
-
type InferErrType<R$1> = R$1 extends Result<unknown, infer E> ? E : never;
|
|
18
|
-
type ResultAll<T extends readonly Result[]> = IsLiteralArray<T> extends 1 ? Traverse<T> : Result<ExtractOkTypes<T>, ExtractErrTypes<T>[number]>;
|
|
19
|
-
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, ...0[]];
|
|
20
|
-
type CollectResults<T, Collected extends unknown[] = [], Depth extends number = 50> = [Depth] extends [never] ? [] : T extends [infer H, ...infer Rest] ? H extends Result<infer L, infer R> ? CollectResults<Rest, [...Collected, [L, R]], Prev[Depth]> : never : Collected;
|
|
21
|
-
type Transpose<A, Transposed extends unknown[][] = [], Depth extends number = 10> = A extends [infer T, ...infer Rest] ? T extends [infer L, infer R] ? Transposed extends [infer PL, infer PR] ? PL extends unknown[] ? PR extends unknown[] ? Transpose<Rest, [[...PL, L], [...PR, R]], Prev[Depth]> : never : never : Transpose<Rest, [[L], [R]], Prev[Depth]> : Transposed : Transposed;
|
|
22
|
-
type Combine<T, Depth extends number = 5> = Transpose<CollectResults<T>, [], Depth> extends [infer L, infer R] ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>] : Transpose<CollectResults<T>, [], Depth> extends [] ? [[], []] : never;
|
|
23
|
-
type EmptyArrayToNever<T, NeverArrayToNever extends number = 0> = T extends [] ? never : NeverArrayToNever extends 1 ? T extends [never, ...infer Rest] ? [EmptyArrayToNever<Rest>] extends [never] ? never : T : T : T;
|
|
24
|
-
type UnknownMembersToNever<T> = T extends [infer H, ...infer R] ? [[unknown] extends [H] ? never : H, ...UnknownMembersToNever<R>] : T;
|
|
25
|
-
type MembersToUnion<T> = T extends unknown[] ? T[number] : never;
|
|
26
|
-
type IsLiteralArray<T> = T extends {
|
|
27
|
-
length: infer L;
|
|
28
|
-
} ? L extends number ? number extends L ? 0 : 1 : 0 : 0;
|
|
29
|
-
type Traverse<T, Depth extends number = 5> = Combine<T, Depth> extends [infer Oks, infer Errs] ? Result<EmptyArrayToNever<Oks, 1>, MembersToUnion<Errs>> : never;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/result/result.d.ts
|
|
32
|
-
type Ok<T = unknown> = Result<T, never>;
|
|
33
|
-
type Err<E = unknown> = Result<never, E>;
|
|
34
|
-
declare class Result<T = unknown, E = unknown> {
|
|
35
|
-
#private;
|
|
36
|
-
static ok(): Ok<void>;
|
|
37
|
-
static ok<T>(value: T): Ok<T>;
|
|
38
|
-
static err(): Err<void>;
|
|
39
|
-
static err<E>(error: E): Err<E>;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a `Result` from a callable that may throw or return a promise that may reject
|
|
42
|
-
*/
|
|
43
|
-
static fromCallable<T, E = unknown>(callable: SyncFn<T>): Result<T, E>;
|
|
44
|
-
static fromCallable<T>(callable: SyncFn<T>, onThrow: ErrorConstructor): Result<T, Error>;
|
|
45
|
-
static fromCallable<T, E>(callable: SyncFn<T>, onThrow: (error: unknown) => E): Result<T, E>;
|
|
46
|
-
static fromCallable<T, E = unknown>(callable: AsyncFn<T>): Promise<Result<Awaited<T>, E>>;
|
|
47
|
-
static fromCallable<T>(callable: AsyncFn<T>, onThrowOrReject: ErrorConstructor): Promise<Result<Awaited<T>, Error>>;
|
|
48
|
-
static fromCallable<T, E>(callable: AsyncFn<T>, onThrowOrReject: (error: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
49
|
-
/**
|
|
50
|
-
* Creates a safe callable that always returns a `Result`, catching any thrown errors or rejected promises
|
|
51
|
-
*/
|
|
52
|
-
static toSafeCallable<A extends any[], T, E = unknown>(callable: SyncFn<T, A>): SyncFn<Result<T, E>, A>;
|
|
53
|
-
static toSafeCallable<A extends any[], T>(callable: SyncFn<T, A>, onThrow: ErrorConstructor): SyncFn<Result<T, Error>, A>;
|
|
54
|
-
static toSafeCallable<A extends any[], T, E>(callable: SyncFn<T, A>, onThrow: (error: unknown) => E): SyncFn<Result<T, E>, A>;
|
|
55
|
-
static toSafeCallable<A extends any[], T, E = unknown>(callable: AsyncFn<T, A>): AsyncFn<Result<Awaited<T>, E>, A>;
|
|
56
|
-
static toSafeCallable<A extends any[], T>(callable: AsyncFn<T, A>, onThrowOrReject: ErrorConstructor): AsyncFn<Result<Awaited<T>, Error>, A>;
|
|
57
|
-
static toSafeCallable<A extends any[], T, E>(callable: AsyncFn<T, A>, onThrowOrReject: (error: unknown) => E): AsyncFn<Result<Awaited<T>, E>, A>;
|
|
58
|
-
/**
|
|
59
|
-
* Combines multiple `Result` instances into one `Result` containing an array of all `Ok` values,
|
|
60
|
-
* or the first `Err` encountered
|
|
61
|
-
*/
|
|
62
|
-
static all<T extends NonEmptyTuple<Result>>(results: T): ResultAll<T>;
|
|
63
|
-
static all<T extends readonly Result[]>(results: T): ResultAll<T>;
|
|
64
|
-
private constructor();
|
|
65
|
-
/**
|
|
66
|
-
* Check if `Result` is `OK`
|
|
67
|
-
*/
|
|
68
|
-
isOk(): this is Ok<T>;
|
|
69
|
-
/**
|
|
70
|
-
* Check if `Result` is `OK` and the value matches the predicate
|
|
71
|
-
*/
|
|
72
|
-
isOkAnd(predicate: (value: T) => boolean): this is Ok<T>;
|
|
73
|
-
/**
|
|
74
|
-
* Check if `Result` is `Err`
|
|
75
|
-
*/
|
|
76
|
-
isErr(): this is Err<E>;
|
|
77
|
-
/**
|
|
78
|
-
* Check if `Result` is `Err` and the error matches the predicate
|
|
79
|
-
*/
|
|
80
|
-
isErrAnd(predicate: (error: E) => boolean): this is Err<E>;
|
|
81
|
-
/**
|
|
82
|
-
* Maps `Result<T, E>` to `Result<U, E>`
|
|
83
|
-
*/
|
|
84
|
-
map<U$1>(fn: (value: T) => U$1): Result<U$1, E>;
|
|
85
|
-
/**
|
|
86
|
-
* Maps `Result<T, E>` to `Result<T, F>`
|
|
87
|
-
*/
|
|
88
|
-
mapErr<F>(fn: (error: E) => F): Result<T, F>;
|
|
89
|
-
/**
|
|
90
|
-
* Returns a new `Result` by combining the current `Result` with another `Result`
|
|
91
|
-
*/
|
|
92
|
-
and<R$1 extends Result<unknown, E>>(result: R$1): Result<InferOkType<R$1>, E>;
|
|
93
|
-
and<U$1>(result: Result<U$1, E>): Result<U$1, E>;
|
|
94
|
-
/**
|
|
95
|
-
* Maps `Result<T, E>` to `Result<U, E | F>` with a function that returns a `Result`
|
|
96
|
-
*/
|
|
97
|
-
andThen<R$1 extends Result>(fn: (value: T) => R$1): Result<InferOkType<R$1>, InferErrType<R$1> | E>;
|
|
98
|
-
andThen<U$1, F>(fn: (value: T) => Result<U$1, F>): Result<U$1, E | F>;
|
|
99
|
-
/**
|
|
100
|
-
* Returns a new `Result` by combining the current `Result` with another `Result`
|
|
101
|
-
*/
|
|
102
|
-
or<R$1 extends Result<T, unknown>>(result: R$1): Result<T, InferErrType<R$1>>;
|
|
103
|
-
or<F>(result: Result<T, F>): Result<T, F>;
|
|
104
|
-
/**
|
|
105
|
-
* Maps `Result<T, E>` to `Result<T | U, F>` with a function that returns a `Result`
|
|
106
|
-
*/
|
|
107
|
-
orElse<R$1 extends Result>(fn: (error: E) => R$1): Result<InferOkType<R$1> | T, InferErrType<R$1>>;
|
|
108
|
-
orElse<U$1, F>(fn: (error: E) => Result<U$1, F>): Result<T | U$1, F>;
|
|
109
|
-
/**
|
|
110
|
-
* Calls the function with the value if `Result` is `Ok` and returns the result unchanged
|
|
111
|
-
*/
|
|
112
|
-
inspect(fn: (value: T) => unknown): Result<T, E>;
|
|
113
|
-
/**
|
|
114
|
-
* Calls the function with the error if `Result` is `Err` and returns the result unchanged
|
|
115
|
-
*/
|
|
116
|
-
inspectErr(fn: (error: E) => unknown): Result<T, E>;
|
|
117
|
-
/**
|
|
118
|
-
* Unwrap the `Ok` value, or throw an error if `Result` is `Err`
|
|
119
|
-
*/
|
|
120
|
-
unwrap(message?: string | null): T;
|
|
121
|
-
/**
|
|
122
|
-
* Unwrap the `Err` value, or throw an error if `Result` is `Ok`
|
|
123
|
-
*/
|
|
124
|
-
unwrapErr(message?: string | null): E;
|
|
125
|
-
/**
|
|
126
|
-
* Unwrap the `Ok` value, or return the provided value if `Result` is `Err`
|
|
127
|
-
*/
|
|
128
|
-
unwrapOr(defaultValue: T): T;
|
|
129
|
-
/**
|
|
130
|
-
* Unwrap the `Ok` value, or compute it from a function if `Result` is `Err`
|
|
131
|
-
*/
|
|
132
|
-
unwrapOrElse(defaultValueGetter: (error: E) => T): T;
|
|
133
|
-
/**
|
|
134
|
-
* Matches the `Result` variant and executes the corresponding function
|
|
135
|
-
*/
|
|
136
|
-
match<U$1, F = U$1>(ok: (value: T) => U$1, err: (error: E) => F): U$1 | F;
|
|
137
|
-
/**
|
|
138
|
-
* Returns an iterable object that yields the `Ok` value and `Err` value
|
|
139
|
-
*/
|
|
140
|
-
iter(): [ok: boolean, error: E, value: T];
|
|
141
|
-
[Symbol.iterator](): Generator<Err<E>, T>;
|
|
142
|
-
context(context: string): this;
|
|
143
|
-
toString(): string;
|
|
144
|
-
}
|
|
145
|
-
declare const ok: typeof Result.ok;
|
|
146
|
-
declare const err: typeof Result.err;
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/result/helper.d.ts
|
|
149
|
-
declare function safeTry<T, E, This>(body: (this: This) => Generator<Err<E>, Result<T, E>>, self?: This): Result<T, E>;
|
|
150
|
-
declare function safeTry<YieldErr extends Err, GeneratorReturnResult extends Result, This>(body: (this: This) => Generator<YieldErr, GeneratorReturnResult>, self?: This): Result<InferOkType<GeneratorReturnResult>, InferErrType<YieldErr> | InferErrType<GeneratorReturnResult>>;
|
|
151
|
-
declare function safeTry<T, E, This>(body: (this: This) => AsyncGenerator<Err<E>, Result<T, E>>, self?: This): Promise<Result<T, E>>;
|
|
152
|
-
declare function safeTry<YieldErr extends Err, GeneratorReturnResult extends Result, This>(body: (this: This) => AsyncGenerator<YieldErr, GeneratorReturnResult>, self?: This): Promise<Result<InferOkType<GeneratorReturnResult>, InferErrType<YieldErr> | InferErrType<GeneratorReturnResult>>>;
|
|
153
|
-
//#endregion
|
|
154
|
-
export { err as a, ExtractOkTypes as c, ResultAll as d, ResultError as f, Result as i, InferErrType as l, Err as n, ok as o, Ok as r, ExtractErrTypes as s, safeTry as t, InferOkType as u };
|