@oscarpalmer/atoms 0.147.0 → 0.149.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.
@@ -1,132 +1,133 @@
1
1
  import type { GenericCallback } from '../models';
2
+ import type { UnwrapValue } from '../result/models';
2
3
  /**
3
- * A synchronous Flow, a function that pipes values through a series of functions
4
+ * A synchronous Flow, a function that pipe a value through a series of functions
4
5
  */
5
- export type Flow<Callback extends GenericCallback, Value = ReturnType<Callback>> = (...args: Parameters<Callback>) => Value;
6
+ export type Flow<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => UnwrapValue<Value>;
6
7
  /**
7
- * An asynchronous Flow, a function that pipes values through a series of functions
8
+ * An asynchronous Flow, a function that pipes a value through a series of functions
8
9
  */
9
- export type FlowPromise<Callback extends GenericCallback, Value = ReturnType<Callback>> = (...args: Parameters<Callback>) => Promise<Awaited<Value>>;
10
+ export type FlowPromise<Callback extends GenericCallback, Value> = (...args: Parameters<Callback>) => Promise<UnwrapValue<Value>>;
10
11
  /**
11
12
  * Create an asynchronous Flow, a function that pipes values through a function
12
13
  * @returns Flow function
13
14
  */
14
- declare function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn>;
15
+ declare function asyncFlow<Fn extends GenericCallback>(fn: Fn): FlowPromise<Fn, ReturnType<Fn>>;
15
16
  /**
16
17
  * Create an asynchronous Flow, a function that pipes values through a series of functions
17
18
  * @returns Flow function
18
19
  */
19
- declare function asyncFlow<First extends GenericCallback, Second>(first: First, second: (value: Awaited<ReturnType<First>>) => Second): FlowPromise<First, Second>;
20
+ declare function asyncFlow<First extends GenericCallback, Second>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second): FlowPromise<First, Second>;
20
21
  /**
21
22
  * Create an asynchronous Flow, a function that pipes values through a series of functions
22
23
  * @returns Flow function
23
24
  */
24
- declare function asyncFlow<First extends GenericCallback, Second, Third>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third): FlowPromise<First, Third>;
25
+ declare function asyncFlow<First extends GenericCallback, Second, Third>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third): FlowPromise<First, Third>;
25
26
  /**
26
27
  * Create an asynchronous Flow, a function that pipes values through a series of functions
27
28
  * @returns Flow function
28
29
  */
29
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth): FlowPromise<First, Fourth>;
30
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth): FlowPromise<First, Fourth>;
30
31
  /**
31
32
  * Create an asynchronous Flow, a function that pipes values through a series of functions
32
33
  * @returns Flow function
33
34
  */
34
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth): FlowPromise<First, Fifth>;
35
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth): FlowPromise<First, Fifth>;
35
36
  /**
36
37
  * Create an asynchronous Flow, a function that pipes values through a series of functions
37
38
  * @returns Flow function
38
39
  */
39
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth): FlowPromise<First, Sixth>;
40
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth): FlowPromise<First, Sixth>;
40
41
  /**
41
42
  * Create an asynchronous Flow, a function that pipes values through a series of functions
42
43
  * @returns Flow function
43
44
  */
44
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh): FlowPromise<First, Seventh>;
45
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh): FlowPromise<First, Seventh>;
45
46
  /**
46
47
  * Create an asynchronous Flow, a function that pipes values through a series of functions
47
48
  * @returns Flow function
48
49
  */
49
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth): FlowPromise<First, Eighth>;
50
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth): FlowPromise<First, Eighth>;
50
51
  /**
51
52
  * Create an asynchronous Flow, a function that pipes values through a series of functions
52
53
  * @returns Flow function
53
54
  */
54
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth, ninth: (value: Awaited<Eighth>) => Ninth): FlowPromise<First, Ninth>;
55
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth): FlowPromise<First, Ninth>;
55
56
  /**
56
57
  * Create an asynchronous Flow, a function that pipes values through a series of functions
57
58
  * @returns Flow function
58
59
  */
59
- declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: Awaited<ReturnType<First>>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth, ninth: (value: Awaited<Eighth>) => Ninth, tenth: (value: Awaited<Ninth>) => Tenth): FlowPromise<First, Tenth>;
60
+ declare function asyncFlow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: Awaited<UnwrapValue<ReturnType<First>>>) => Second, third: (value: Awaited<UnwrapValue<Second>>) => Third, fourth: (value: Awaited<UnwrapValue<Third>>) => Fourth, fifth: (value: Awaited<UnwrapValue<Fourth>>) => Fifth, sixth: (value: Awaited<UnwrapValue<Fifth>>) => Sixth, seventh: (value: Awaited<UnwrapValue<Sixth>>) => Seventh, eighth: (value: Awaited<UnwrapValue<Seventh>>) => Eighth, ninth: (value: Awaited<UnwrapValue<Eighth>>) => Ninth, tenth: (value: Awaited<UnwrapValue<Ninth>>) => Tenth): FlowPromise<First, Tenth>;
60
61
  /**
61
62
  * Create an asynchronous Flow, a function that pipes values through a series of functions
62
63
  * @returns Flow function
63
64
  */
64
- declare function asyncFlow<Fn extends GenericCallback>(fn: Fn, ...fns: Array<(value: Awaited<ReturnType<Fn>>) => unknown>): FlowPromise<Fn>;
65
+ declare function asyncFlow<Fn extends GenericCallback>(fn: Fn, ...fns: Array<(value: Awaited<UnwrapValue<ReturnType<Fn>>>) => unknown>): FlowPromise<Fn, ReturnType<Fn>>;
65
66
  /**
66
67
  * Create an asynchronous Flow, a function that pipes values through a series of functions
67
68
  * @returns Flow function
68
69
  */
69
- declare function asyncFlow(...fns: Function[]): (...args: unknown[]) => Promise<unknown>;
70
+ declare function asyncFlow(...fns: GenericCallback[]): (...args: unknown[]) => Promise<unknown>;
70
71
  /**
71
72
  * Create a Flow, a function that pipes values through a function
72
73
  * @returns Flow function
73
74
  */
74
- export declare function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn>;
75
+ export declare function flow<Fn extends GenericCallback>(fn: Fn): Flow<Fn, ReturnType<Fn>>;
75
76
  /**
76
77
  * Create a Flow, a function that pipes values through a series of functions
77
78
  * @returns Flow function
78
79
  */
79
- export declare function flow<First extends GenericCallback, Second>(first: First, second: (value: ReturnType<First>) => Second): Flow<First, Second>;
80
+ export declare function flow<First extends GenericCallback, Second>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second): Flow<First, Second>;
80
81
  /**
81
82
  * Create a Flow, a function that pipes values through a series of functions
82
83
  * @returns Flow function
83
84
  */
84
- export declare function flow<First extends GenericCallback, Second, Third>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third): Flow<First, Third>;
85
+ export declare function flow<First extends GenericCallback, Second, Third>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third): Flow<First, Third>;
85
86
  /**
86
87
  * Create a Flow, a function that pipes values through a series of functions
87
88
  * @returns Flow function
88
89
  */
89
- export declare function flow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth): Flow<First, Fourth>;
90
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth): Flow<First, Fourth>;
90
91
  /**
91
92
  * Create a Flow, a function that pipes values through a series of functions
92
93
  * @returns Flow function
93
94
  */
94
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth): Flow<First, Fifth>;
95
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth): Flow<First, Fifth>;
95
96
  /**
96
97
  * Create a Flow, a function that pipes values through a series of functions
97
98
  * @returns Flow function
98
99
  */
99
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth): Flow<First, Sixth>;
100
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth): Flow<First, Sixth>;
100
101
  /**
101
102
  * Create a Flow, a function that pipes values through a series of functions
102
103
  * @returns Flow function
103
104
  */
104
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh): Flow<First, Seventh>;
105
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh): Flow<First, Seventh>;
105
106
  /**
106
107
  * Create a Flow, a function that pipes values through a series of functions
107
108
  * @returns Flow function
108
109
  */
109
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth): Flow<First, Eighth>;
110
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth): Flow<First, Eighth>;
110
111
  /**
111
112
  * Create a Flow, a function that pipes values through a series of functions
112
113
  * @returns Flow function
113
114
  */
114
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth, ninth: (value: Eighth) => Ninth): Flow<First, Ninth>;
115
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth): Flow<First, Ninth>;
115
116
  /**
116
117
  * Create a Flow, a function that pipes values through a series of functions
117
118
  * @returns Flow function
118
119
  */
119
- export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: ReturnType<First>) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth, ninth: (value: Eighth) => Ninth, tenth: (value: Ninth) => Tenth): Flow<First, Tenth>;
120
+ export declare function flow<First extends GenericCallback, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(first: First, second: (value: UnwrapValue<ReturnType<First>>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth, tenth: (value: UnwrapValue<Ninth>) => Tenth): Flow<First, Tenth>;
120
121
  /**
121
122
  * Create a Flow, a function that pipes values through a series of functions
122
123
  * @returns Flow function
123
124
  */
124
- export declare function flow<First extends GenericCallback>(first: First, ...fns: Array<(value: ReturnType<First>) => unknown>): Flow<First>;
125
+ export declare function flow<First extends GenericCallback>(first: First, ...fns: Array<(value: UnwrapValue<ReturnType<First>>) => unknown>): Flow<First, ReturnType<First>>;
125
126
  /**
126
127
  * Create a Flow, a function that pipes values through a series of functions
127
128
  * @returns Flow function
128
129
  */
129
- export declare function flow(...fns: Function[]): (...args: unknown[]) => unknown;
130
+ export declare function flow(...fns: GenericCallback[]): (...args: unknown[]) => unknown;
130
131
  export declare namespace flow {
131
132
  var async: typeof asyncFlow;
132
133
  }
@@ -135,67 +136,67 @@ export declare namespace flow {
135
136
  * @param value Initial value
136
137
  * @returns Piped result
137
138
  */
138
- declare function asyncPipe<Initial, Pipe>(value: Initial, pipe: (value: Initial) => Pipe): Promise<Awaited<Pipe>>;
139
+ declare function asyncPipe<Initial, Piped>(value: Initial, pipe: (value: UnwrapValue<Initial>) => Piped): Promise<UnwrapValue<Piped>>;
139
140
  /**
140
141
  * Pipe a value through a series of functions
141
142
  * @param value Initial value
142
143
  * @returns Piped result
143
144
  */
144
- declare function asyncPipe<Initial, First, Second>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second): Promise<Awaited<Second>>;
145
+ declare function asyncPipe<Initial, First, Second>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second): Promise<UnwrapValue<Second>>;
145
146
  /**
146
147
  * Pipe a value through a series of functions
147
148
  * @param value Initial value
148
149
  * @returns Piped result
149
150
  */
150
- declare function asyncPipe<Initial, First, Second, Third>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third): Promise<Awaited<Third>>;
151
+ declare function asyncPipe<Initial, First, Second, Third>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third): Promise<UnwrapValue<Third>>;
151
152
  /**
152
153
  * Pipe a value through a series of functions
153
154
  * @param value Initial value
154
155
  * @returns Piped result
155
156
  */
156
- declare function asyncPipe<Initial, First, Second, Third, Fourth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth): Promise<Awaited<Fourth>>;
157
+ declare function asyncPipe<Initial, First, Second, Third, Fourth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth): Promise<UnwrapValue<Fourth>>;
157
158
  /**
158
159
  * Pipe a value through a series of functions
159
160
  * @param value Initial value
160
161
  * @returns Piped result
161
162
  */
162
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth): Promise<Awaited<Fifth>>;
163
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth): Promise<UnwrapValue<Fifth>>;
163
164
  /**
164
165
  * Pipe a value through a series of functions
165
166
  * @param value Initial value
166
167
  * @returns Piped result
167
168
  */
168
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth): Promise<Awaited<Sixth>>;
169
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth): Promise<UnwrapValue<Sixth>>;
169
170
  /**
170
171
  * Pipe a value through a series of functions
171
172
  * @param value Initial value
172
173
  * @returns Piped result
173
174
  */
174
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh): Promise<Awaited<Seventh>>;
175
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh): Promise<UnwrapValue<Seventh>>;
175
176
  /**
176
177
  * Pipe a value through a series of functions
177
178
  * @param value Initial value
178
179
  * @returns Piped result
179
180
  */
180
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth): Promise<Awaited<Eighth>>;
181
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth): Promise<UnwrapValue<Eighth>>;
181
182
  /**
182
183
  * Pipe a value through a series of functions
183
184
  * @param value Initial value
184
185
  * @returns Piped result
185
186
  */
186
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth, ninth: (value: Awaited<Eighth>) => Ninth): Promise<Awaited<Ninth>>;
187
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth): Promise<UnwrapValue<Ninth>>;
187
188
  /**
188
189
  * Pipe a value through a series of functions
189
190
  * @param value Initial value
190
191
  * @returns Piped result
191
192
  */
192
- declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(value: Initial, first: (value: Initial) => First, second: (value: Awaited<First>) => Second, third: (value: Awaited<Second>) => Third, fourth: (value: Awaited<Third>) => Fourth, fifth: (value: Awaited<Fourth>) => Fifth, sixth: (value: Awaited<Fifth>) => Sixth, seventh: (value: Awaited<Sixth>) => Seventh, eighth: (value: Awaited<Seventh>) => Eighth, ninth: (value: Awaited<Eighth>) => Ninth, tenth: (value: Awaited<Ninth>) => Tenth): Promise<Awaited<Tenth>>;
193
+ declare function asyncPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth, tenth: (value: UnwrapValue<Ninth>) => Tenth): Promise<UnwrapValue<Tenth>>;
193
194
  /**
194
195
  * Pipe a value through a series of functions
195
196
  * @param value Initial value
196
197
  * @returns Piped result
197
198
  */
198
- declare function asyncPipe<Value>(value: Value, ...pipes: Array<(value: Value) => Value>): Promise<Value>;
199
+ declare function asyncPipe<Value>(value: Value, ...pipes: Array<(value: Value) => Value>): Promise<UnwrapValue<Value>>;
199
200
  /**
200
201
  * Pipe a value through a series of functions
201
202
  * @param value Initial value
@@ -207,67 +208,67 @@ declare function asyncPipe(value: unknown, ...pipes: Array<(value: unknown) => u
207
208
  * @param value Initial value
208
209
  * @returns Piped result
209
210
  */
210
- export declare function pipe<Initial, Pipe>(value: Initial, first: (value: Initial) => Pipe): Pipe;
211
+ export declare function pipe<Initial, Piped>(value: Initial, pipe: (value: UnwrapValue<Initial>) => Piped): UnwrapValue<Piped>;
211
212
  /**
212
213
  * Pipe a value through a series of functions
213
214
  * @param value Initial value
214
215
  * @returns Piped result
215
216
  */
216
- export declare function pipe<Initial, First, Second>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second): Second;
217
+ export declare function pipe<Initial, First, Second>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second): UnwrapValue<Second>;
217
218
  /**
218
219
  * Pipe a value through a series of functions
219
220
  * @param value Initial value
220
221
  * @returns Piped result
221
222
  */
222
- export declare function pipe<Initial, First, Second, Third>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third): Third;
223
+ export declare function pipe<Initial, First, Second, Third>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third): UnwrapValue<Third>;
223
224
  /**
224
225
  * Pipe a value through a series of functions
225
226
  * @param value Initial value
226
227
  * @returns Piped result
227
228
  */
228
- export declare function pipe<Initial, First, Second, Third, Fourth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth): Fourth;
229
+ export declare function pipe<Initial, First, Second, Third, Fourth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth): UnwrapValue<Fourth>;
229
230
  /**
230
231
  * Pipe a value through a series of functions
231
232
  * @param value Initial value
232
233
  * @returns Piped result
233
234
  */
234
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth): Fifth;
235
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth): UnwrapValue<Fifth>;
235
236
  /**
236
237
  * Pipe a value through a series of functions
237
238
  * @param value Initial value
238
239
  * @returns Piped result
239
240
  */
240
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth): Sixth;
241
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth): UnwrapValue<Sixth>;
241
242
  /**
242
243
  * Pipe a value through a series of functions
243
244
  * @param value Initial value
244
245
  * @returns Piped result
245
246
  */
246
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh): Seventh;
247
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh): UnwrapValue<Seventh>;
247
248
  /**
248
249
  * Pipe a value through a series of functions
249
250
  * @param value Initial value
250
251
  * @returns Piped result
251
252
  */
252
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth): Eighth;
253
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth): UnwrapValue<Eighth>;
253
254
  /**
254
255
  * Pipe a value through a series of functions
255
256
  * @param value Initial value
256
257
  * @returns Piped result
257
258
  */
258
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth, ninth: (value: Eighth) => Ninth): Ninth;
259
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth): UnwrapValue<Ninth>;
259
260
  /**
260
261
  * Pipe a value through a series of functions
261
262
  * @param value Initial value
262
263
  * @returns Piped result
263
264
  */
264
- export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(value: Initial, first: (value: Initial) => First, second: (value: First) => Second, third: (value: Second) => Third, fourth: (value: Third) => Fourth, fifth: (value: Fourth) => Fifth, sixth: (value: Fifth) => Sixth, seventh: (value: Sixth) => Seventh, eighth: (value: Seventh) => Eighth, ninth: (value: Eighth) => Ninth, tenth: (value: Ninth) => Tenth): Tenth;
265
+ export declare function pipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(value: Initial, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth, tenth: (value: UnwrapValue<Ninth>) => Tenth): UnwrapValue<Tenth>;
265
266
  /**
266
267
  * Pipe a value through a series of functions
267
268
  * @param value Initial value
268
269
  * @returns Piped result
269
270
  */
270
- export declare function pipe<Value>(value: Value, ...pipes: Array<(value: Value) => Value>): Value;
271
+ export declare function pipe<Value>(value: Value, ...pipes: Array<(value: Value) => Value>): UnwrapValue<Value>;
271
272
  /**
272
273
  * Pipe a value through a series of functions
273
274
  * @param value Initial value
package/types/index.d.ts CHANGED
@@ -36,7 +36,7 @@ export * from './promise';
36
36
  export * from './query';
37
37
  export * from './queue';
38
38
  export * from './random';
39
- export * from './result';
39
+ export * from './result/index';
40
40
  export * from './sized/map';
41
41
  export * from './sized/set';
42
42
  export { FRAME_RATE_MS };
@@ -0,0 +1,37 @@
1
+ import type { Err, ExtendedErr, Ok, Result } from '../result/models';
2
+ /**
3
+ * Is the result an extended error?
4
+ * @param result Result to check
5
+ * @returns `true` if the result is an extended error, `false` otherwise
6
+ */
7
+ export declare function isError<Value, E = Error>(value: ExtendedErr<E> | Result<Value, E>, extended: true): value is ExtendedErr<E>;
8
+ /**
9
+ * Is the result an error?
10
+ * @param result Result to check
11
+ * @returns `true` if the result is an error, `false` otherwise
12
+ */
13
+ export declare function isError<Value, E = Error>(value: Result<Value, E>): value is Err<E>;
14
+ /**
15
+ * Is the value an error?
16
+ * @param value Value to check
17
+ * @returns `true` if the value is an error, `false` otherwise
18
+ */
19
+ export declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
20
+ /**
21
+ * Is the result ok?
22
+ * @param value Result to check
23
+ * @returns `true` if the result is ok, `false` otherwise
24
+ */
25
+ export declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
26
+ /**
27
+ * Is the value ok?
28
+ * @param value Value to check
29
+ * @returns `true` if the value is ok, `false` otherwise
30
+ */
31
+ export declare function isOk(value: unknown): value is Ok<unknown>;
32
+ /**
33
+ * Is the value a result?
34
+ * @param value Value to check
35
+ * @returns `true` if the value is a result, `false` otherwise
36
+ */
37
+ export declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
@@ -1,32 +1,8 @@
1
- import { attemptPromise } from './promise';
2
- /**
3
- * An error result
4
- */
5
- export type Err<Error> = {
6
- ok: false;
7
- error: Error;
8
- };
9
- /**
10
- * An extended error result
11
- */
12
- export type ExtendedErr<E> = Err<E> & {
13
- original: Error;
14
- };
15
- /**
16
- * An extended, unknown result
17
- */
18
- export type ExtendedResult<Value, E> = ExtendedErr<E> | Ok<Value>;
19
- /**
20
- * A successful result
21
- */
22
- export type Ok<Value> = {
23
- ok: true;
24
- value: Value;
25
- };
26
- /**
27
- * An unknown result
28
- */
29
- export type Result<Value, E = Error> = Err<E> | Ok<Value>;
1
+ import { attemptPromise } from '../promise';
2
+ import { matchResult } from './match';
3
+ import type { Err, ExtendedErr, ExtendedResult, Ok, Result } from './models';
4
+ import { attemptFlow } from './work/flow';
5
+ import { attemptPipe } from './work/pipe';
30
6
  /**
31
7
  * Executes a promise, catching any errors, and returns a result
32
8
  * @param promise Promise to execute
@@ -59,7 +35,7 @@ declare function asyncAttempt<Value>(callback: () => Promise<Value>): Promise<Re
59
35
  * @param error Error value
60
36
  * @returns Callback result
61
37
  */
62
- export declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedErr<E> | Ok<Value>;
38
+ export declare function attempt<Value, E>(callback: () => Value, error: E): ExtendedResult<Value, E>;
63
39
  /**
64
40
  * Executes a callback, catching any errors, and returns a result
65
41
  * @param callback Callback to execute
@@ -68,6 +44,9 @@ export declare function attempt<Value, E>(callback: () => Value, error: E): Exte
68
44
  export declare function attempt<Value>(callback: () => Value): Result<Value, Error>;
69
45
  export declare namespace attempt {
70
46
  var async: typeof asyncAttempt;
47
+ var flow: typeof attemptFlow;
48
+ var match: typeof matchResult;
49
+ var pipe: typeof attemptPipe;
71
50
  var promise: typeof attemptPromise;
72
51
  }
73
52
  /**
@@ -83,42 +62,6 @@ export declare function error<E>(value: E, original: Error): ExtendedErr<E>;
83
62
  * @returns Error result
84
63
  */
85
64
  export declare function error<E>(value: E): Err<E>;
86
- /**
87
- * Is the result an extended error?
88
- * @param result Result to check
89
- * @returns `true` if the result is an extended error, `false` otherwise
90
- */
91
- export declare function isError<Value, E = Error>(value: ExtendedErr<E> | Result<Value, E>, extended: true): value is ExtendedErr<E>;
92
- /**
93
- * Is the result an error?
94
- * @param result Result to check
95
- * @returns `true` if the result is an error, `false` otherwise
96
- */
97
- export declare function isError<Value, E = Error>(value: Result<Value, E>): value is Err<E>;
98
- /**
99
- * Is the value an error?
100
- * @param value Value to check
101
- * @returns `true` if the value is an error, `false` otherwise
102
- */
103
- export declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
104
- /**
105
- * Is the result ok?
106
- * @param value Result to check
107
- * @returns `true` if the result is ok, `false` otherwise
108
- */
109
- export declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
110
- /**
111
- * Is the value ok?
112
- * @param value Value to check
113
- * @returns `true` if the value is ok, `false` otherwise
114
- */
115
- export declare function isOk(value: unknown): value is Ok<unknown>;
116
- /**
117
- * Is the value a result?
118
- * @param value Value to check
119
- * @returns `true` if the value is a result, `false` otherwise
120
- */
121
- export declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
122
65
  /**
123
66
  * Creates an ok result
124
67
  * @param value Value
@@ -139,4 +82,5 @@ export declare function unwrap<Value, E = Error>(value: Result<Value, E>, defaul
139
82
  * @returns Value of the result _(or the default value)_
140
83
  */
141
84
  export declare function unwrap(value: unknown, defaultValue: unknown): unknown;
142
- export {};
85
+ export { isError, isOk, isResult } from '../internal/result';
86
+ export type { Err, ExtendedErr, ExtendedResult, Ok, Result } from './models';
@@ -0,0 +1,31 @@
1
+ import type { AnyResult, ResultMatch } from './models';
2
+ /**
3
+ * Handles a result with match callbacks
4
+ * @param result Result to handle
5
+ * @param handler Match callbacks
6
+ */
7
+ declare function asyncMatchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | Promise<AnyResult<Value, E>> | (() => Promise<AnyResult<Value, E>>), handler: ResultMatch<Value, Returned, E>): Promise<Returned>;
8
+ /**
9
+ * Handles a result with match callbacks
10
+ * @param result Result to handle
11
+ * @param ok Ok callback
12
+ * @param error Error callback
13
+ */
14
+ declare function asyncMatchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | Promise<AnyResult<Value, E>> | (() => Promise<AnyResult<Value, E>>), ok: ResultMatch<Value, Returned, E>['ok'], error: ResultMatch<Value, Returned, E>['error']): Promise<Returned>;
15
+ /**
16
+ * Handles a result with match callbacks
17
+ * @param result Result to handle
18
+ * @param handler Match callbacks
19
+ */
20
+ export declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | (() => AnyResult<Value, E>), handler: ResultMatch<Value, Returned, E>): Returned;
21
+ /**
22
+ * Handles a result with match callbacks
23
+ * @param result Result to handle
24
+ * @param ok Ok callback
25
+ * @param error Error callback
26
+ */
27
+ export declare function matchResult<Value, Returned, E = Error>(result: AnyResult<Value, E> | (() => AnyResult<Value, E>), ok: ResultMatch<Value, Returned, E>['ok'], error: ResultMatch<Value, Returned, E>['error']): Returned;
28
+ export declare namespace matchResult {
29
+ var async: typeof asyncMatchResult;
30
+ }
31
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { GenericCallback } from '../models';
2
+ /**
3
+ * An unknown result
4
+ */
5
+ export type AnyResult<Value, E> = Err<E> | ExtendedErr<E> | Ok<Value>;
6
+ /**
7
+ * An error result
8
+ */
9
+ export type Err<Error> = {
10
+ ok: false;
11
+ error: Error;
12
+ };
13
+ /**
14
+ * An extended error result
15
+ */
16
+ export type ExtendedErr<E> = Err<E> & {
17
+ original: Error;
18
+ };
19
+ /**
20
+ * An extended, unknown result
21
+ */
22
+ export type ExtendedResult<Value, E> = ExtendedErr<E> | Ok<Value>;
23
+ /**
24
+ * A successful result
25
+ */
26
+ export type Ok<Value> = {
27
+ ok: true;
28
+ value: Value;
29
+ };
30
+ /**
31
+ * An unknown result
32
+ */
33
+ export type Result<Value, E = Error> = Err<E> | Ok<Value>;
34
+ /**
35
+ * Match callbacks for a result
36
+ */
37
+ export type ResultMatch<Value, Returned, E = Error> = {
38
+ /**
39
+ * Callback for error result
40
+ * @param error Error value
41
+ * @param original Original error, if available
42
+ * @returns Value to return
43
+ */
44
+ error: (error: E, original?: Error) => Returned;
45
+ /**
46
+ * Callback for ok result
47
+ * @param value Ok value
48
+ * @returns Value to return
49
+ */
50
+ ok: (value: Value) => Returned;
51
+ };
52
+ /**
53
+ * Unwrap a result value
54
+ */
55
+ type UnwrapResult<Original extends Result<unknown, unknown>> = Original extends Ok<infer Value> ? Value : never;
56
+ /**
57
+ * Unwrap any value
58
+ */
59
+ export type UnwrapValue<Original> = Original extends GenericCallback ? ReturnType<Original> extends Result<unknown, unknown> ? UnwrapResult<ReturnType<Original>> : ReturnType<Original> : Original extends Result<unknown, unknown> ? UnwrapResult<Original> : Original extends Promise<infer Value> ? Awaited<Value> : Original;
60
+ export {};