@shirudo/ddd-kit 0.9.7 → 0.9.8
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/package.json +2 -2
- package/dist/index.d.ts +0 -1309
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/result-CDTS-G0l.d.ts +0 -329
- package/dist/result.d.ts +0 -204
- package/dist/result.js +0 -2
- package/dist/result.js.map +0 -1
package/dist/result.d.ts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { R as Result } from './result-CDTS-G0l.js';
|
|
2
|
-
export { E as Err, O as Ok, a as andThen, e as err, i as isErr, b as isOk, m as map, c as mapErr, d as match, f as matchAsync, o as ok, p as pipe, t as tryCatch, g as tryCatchAsync, u as unwrapOr, h as unwrapOrElse } from './result-CDTS-G0l.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Base class for Result with method chaining support.
|
|
6
|
-
* Provides common methods for both Ok and Err classes.
|
|
7
|
-
*/
|
|
8
|
-
declare abstract class ResultBase<T, E> {
|
|
9
|
-
protected readonly _result: Result<T, E>;
|
|
10
|
-
protected constructor(result: Result<T, E>);
|
|
11
|
-
/**
|
|
12
|
-
* Returns the value if Ok, otherwise throws an error.
|
|
13
|
-
* If error is an Error instance, throws it directly.
|
|
14
|
-
* Otherwise, wraps the error in a new Error.
|
|
15
|
-
*
|
|
16
|
-
* @throws Error if the result is Err
|
|
17
|
-
*/
|
|
18
|
-
unwrap(): T;
|
|
19
|
-
/**
|
|
20
|
-
* Returns the value if Ok, otherwise returns the default value.
|
|
21
|
-
*/
|
|
22
|
-
unwrapOr(defaultValue: T): T;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the value if Ok, otherwise computes default from error.
|
|
25
|
-
*/
|
|
26
|
-
unwrapOrElse(fn: (error: E) => T): T;
|
|
27
|
-
/**
|
|
28
|
-
* Pattern matching for Result.
|
|
29
|
-
* Applies one function if Ok, another if Err.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* outcome.match(
|
|
34
|
-
* value => `Success: ${value}`,
|
|
35
|
-
* error => `Error: ${error}`
|
|
36
|
-
* );
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @example Using object syntax
|
|
40
|
-
* ```typescript
|
|
41
|
-
* outcome.match({
|
|
42
|
-
* ok: value => `Success: ${value}`,
|
|
43
|
-
* err: error => `Error: ${error}`
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
match<R>(onOk: (value: T) => R, onErr: (error: E) => R): R;
|
|
48
|
-
match<R>(handlers: {
|
|
49
|
-
ok: (value: T) => R;
|
|
50
|
-
err: (error: E) => R;
|
|
51
|
-
}): R;
|
|
52
|
-
/**
|
|
53
|
-
* Async pattern matching for Result.
|
|
54
|
-
* Applies one async function if Ok, another if Err.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* await outcome.matchAsync(
|
|
59
|
-
* async (value) => `Success: ${value}`,
|
|
60
|
-
* async (error) => `Error: ${error}`
|
|
61
|
-
* );
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @example Using object syntax
|
|
65
|
-
* ```typescript
|
|
66
|
-
* await outcome.matchAsync({
|
|
67
|
-
* ok: async (value) => `Success: ${value}`,
|
|
68
|
-
* err: async (error) => `Error: ${error}`
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
matchAsync<R>(onOk: (value: T) => Promise<R>, onErr: (error: E) => Promise<R>): Promise<R>;
|
|
73
|
-
matchAsync<R>(handlers: {
|
|
74
|
-
ok: (value: T) => Promise<R>;
|
|
75
|
-
err: (error: E) => Promise<R>;
|
|
76
|
-
}): Promise<R>;
|
|
77
|
-
/**
|
|
78
|
-
* Type guard to check if the result is Ok.
|
|
79
|
-
*/
|
|
80
|
-
isOk(): this is Success<T>;
|
|
81
|
-
/**
|
|
82
|
-
* Type guard to check if the result is Err.
|
|
83
|
-
*/
|
|
84
|
-
isErr(): this is Erroneous<E>;
|
|
85
|
-
/**
|
|
86
|
-
* Gets the underlying Result value.
|
|
87
|
-
*/
|
|
88
|
-
get result(): Result<T, E>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Class representing a successful result with method chaining support.
|
|
92
|
-
* Use this for class-based API with method chaining.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* const okResult = Ok(1);
|
|
97
|
-
* const doubled = okResult.map(x => x * 2).unwrap(); // 2
|
|
98
|
-
*
|
|
99
|
-
* const chained = Ok(5)
|
|
100
|
-
* .andThen(x => Ok(x * 2))
|
|
101
|
-
* .map(x => x + 1)
|
|
102
|
-
* .unwrap(); // 11
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
declare class Success<T> extends ResultBase<T, never> {
|
|
106
|
-
constructor(value: T);
|
|
107
|
-
/**
|
|
108
|
-
* Factory function to create an Ok instance.
|
|
109
|
-
* Can be called with or without `new`.
|
|
110
|
-
*/
|
|
111
|
-
static of<T>(value: T): Success<T>;
|
|
112
|
-
/**
|
|
113
|
-
* Chains Result operations (flatMap/bind).
|
|
114
|
-
* If the result is Ok, applies the function to the value.
|
|
115
|
-
* If Err, returns the error unchanged.
|
|
116
|
-
*/
|
|
117
|
-
andThen<U, E>(fn: (value: T) => Result<U, E>): Success<U> | Erroneous<E>;
|
|
118
|
-
/**
|
|
119
|
-
* Transforms the Ok value using a function.
|
|
120
|
-
* If the result is Err, returns the error unchanged.
|
|
121
|
-
*/
|
|
122
|
-
map<U>(fn: (value: T) => U): Success<U>;
|
|
123
|
-
/**
|
|
124
|
-
* Transforms the Err value using a function.
|
|
125
|
-
* If the result is Ok, returns the value unchanged.
|
|
126
|
-
*/
|
|
127
|
-
mapErr<F>(_fn: (error: never) => F): Success<T>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Class representing an erroneous result with method chaining support.
|
|
132
|
-
* Use this for class-based API with method chaining.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* const errResult = Err(new Error("error"));
|
|
137
|
-
* errResult.map(x => x * 2).unwrap(); // throws Error("error")
|
|
138
|
-
*
|
|
139
|
-
* const mapped = Err("original")
|
|
140
|
-
* .mapErr(e => `Error: ${e}`)
|
|
141
|
-
* .unwrap(); // throws Error("Error: original")
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
declare class Erroneous<E> extends ResultBase<never, E> {
|
|
145
|
-
constructor(error: E);
|
|
146
|
-
/**
|
|
147
|
-
* Factory function to create an Err instance.
|
|
148
|
-
* Can be called with or without `new`.
|
|
149
|
-
*/
|
|
150
|
-
static of<E>(error: E): Erroneous<E>;
|
|
151
|
-
/**
|
|
152
|
-
* Chains Result operations (flatMap/bind).
|
|
153
|
-
* If the result is Ok, applies the function to the value.
|
|
154
|
-
* If Err, returns the error unchanged.
|
|
155
|
-
*/
|
|
156
|
-
andThen<U>(_fn: (value: never) => Result<U, E>): Erroneous<E>;
|
|
157
|
-
/**
|
|
158
|
-
* Transforms the Ok value using a function.
|
|
159
|
-
* If the result is Err, returns the error unchanged.
|
|
160
|
-
*/
|
|
161
|
-
map<U>(_fn: (value: never) => U): Erroneous<E>;
|
|
162
|
-
/**
|
|
163
|
-
* Transforms the Err value using a function.
|
|
164
|
-
* If the result is Ok, returns the value unchanged.
|
|
165
|
-
*/
|
|
166
|
-
mapErr<F>(fn: (error: E) => F): Erroneous<F>;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Class-based API for Result with method chaining support.
|
|
171
|
-
* Provides an object-oriented alternative to the functional Result type.
|
|
172
|
-
* Use `Outcome.from()` to wrap an existing Result, or `Outcome.ok()` / `Outcome.err()` to create new instances.
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* // Wrap an existing Result
|
|
177
|
-
* const result = Outcome.from(ok(1));
|
|
178
|
-
* const doubled = result.map(x => x * 2).unwrap(); // 2
|
|
179
|
-
*
|
|
180
|
-
* // Create directly
|
|
181
|
-
* const outcome = Outcome.ok(42);
|
|
182
|
-
* const value = outcome.map(x => x + 1).unwrap(); // 43
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
declare class Outcome<T, E> extends ResultBase<T, E> {
|
|
186
|
-
private constructor();
|
|
187
|
-
/**
|
|
188
|
-
* Creates an Outcome from an Ok value.
|
|
189
|
-
*/
|
|
190
|
-
static ok<T>(value: T): Success<T>;
|
|
191
|
-
/**
|
|
192
|
-
* Creates an Outcome from an Err value.
|
|
193
|
-
*/
|
|
194
|
-
static err<E>(error: E): Erroneous<E>;
|
|
195
|
-
/**
|
|
196
|
-
* Creates an Outcome from a Result.
|
|
197
|
-
*/
|
|
198
|
-
static from<T, E>(result: Result<T, E>): Outcome<T, E>;
|
|
199
|
-
andThen<U>(fn: (value: T) => Result<U, E>): Outcome<U, E>;
|
|
200
|
-
map<U>(fn: (value: T) => U): Outcome<U, E>;
|
|
201
|
-
mapErr<F>(fn: (error: E) => F): Outcome<T, F>;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export { Erroneous, Outcome, Result, Success };
|
package/dist/result.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var x=Object.defineProperty;var o=(e,r)=>x(e,"name",{value:r,configurable:true});function n(e){return {ok:true,value:e}}o(n,"ok");function u(e){return {ok:false,error:e}}o(u,"err");function p(e){return e.ok===true}o(p,"isOk");function f(e){return e.ok===false}o(f,"isErr");function i(e,r){return e.ok?r(e.value):e}o(i,"andThen");function c(e,r){return e.ok?n(r(e.value)):e}o(c,"map");function a(e,r){return e.ok?e:u(r(e.error))}o(a,"mapErr");function m(e,r){return e.ok?e.value:r}o(m,"unwrapOr");function h(e,r){return e.ok?e.value:r(e.error)}o(h,"unwrapOrElse");function T(e,r,t){return typeof r=="function"?e.ok?r(e.value):t(e.error):e.ok?r.ok(e.value):r.err(e.error)}o(T,"match");async function l(e,r,t){return typeof r=="function"?e.ok?r(e.value):t(e.error):e.ok?r.ok(e.value):r.err(e.error)}o(l,"matchAsync");function w(e,...r){let t=e;for(let k of r)if(t=k(t),!t.ok)return t;return t}o(w,"pipe");function y(e,r){try{return n(e())}catch(t){return u(r?r(t):t instanceof Error?t:new Error(String(t)))}}o(y,"tryCatch");async function P(e,r){try{let t=await e();return n(t)}catch(t){return u(r?r(t):t instanceof Error?t:new Error(String(t)))}}o(P,"tryCatchAsync");var s=class{static{o(this,"ResultBase");}_result;constructor(r){this._result=r;}unwrap(){if(this._result.ok)return this._result.value;throw this._result.error instanceof Error?this._result.error:new Error(String(this._result.error))}unwrapOr(r){return m(this._result,r)}unwrapOrElse(r){return h(this._result,r)}match(r,t){return typeof r=="function"?T(this._result,r,t):T(this._result,r)}async matchAsync(r,t){return typeof r=="function"?l(this._result,r,t):l(this._result,r)}isOk(){return p(this._result)}isErr(){return f(this._result)}get result(){return this._result}},R=class e extends s{static{o(this,"Success");}constructor(r){super(n(r));}static of(r){return new e(r)}andThen(r){let t=i(this._result,r);return t.ok?new e(t.value):new E(t.error)}map(r){let t=c(this._result,r);if(t.ok)return new e(t.value);throw new Error("Unexpected error in Success.map")}mapErr(r){return this}};var E=class e extends s{static{o(this,"Erroneous");}constructor(r){super(u(r));}static of(r){return new e(r)}andThen(r){return this}map(r){return this}mapErr(r){let t=a(this._result,r);if(!t.ok)return new e(t.error);throw new Error("Unexpected ok in Erroneous.mapErr")}};var v=class e extends s{static{o(this,"Outcome");}constructor(r){super(r);}static ok(r){return new R(r)}static err(r){return new E(r)}static from(r){return new e(r)}andThen(r){return e.from(i(this._result,r))}map(r){return e.from(c(this._result,r))}mapErr(r){return e.from(a(this._result,r))}};export{E as Erroneous,v as Outcome,R as Success,i as andThen,u as err,f as isErr,p as isOk,c as map,a as mapErr,T as match,l as matchAsync,n as ok,w as pipe,y as tryCatch,P as tryCatchAsync,m as unwrapOr,h as unwrapOrElse};//# sourceMappingURL=result.js.map
|
|
2
|
-
//# sourceMappingURL=result.js.map
|
package/dist/result.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/result/result.ts","../src/core/result/outcome.ts"],"names":["ok","value","__name","err","error","isOk","result","isErr","andThen","fn","map","mapErr","unwrapOr","defaultValue","unwrapOrElse","match","onOkOrHandlers","onErr","matchAsync","pipe","initial","fns","current","tryCatch","errorMapper","tryCatchAsync","ResultBase","Success","_Success","Erroneous","_fn","_Erroneous","Outcome","_Outcome"],"mappings":"AA+BO,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,YAAA,CAAA,IAAA,CAAA,CAAA,CAAA,SAASA,EAAMC,CAAAA,CAAkB,CACvC,OAAO,CAAE,GAAI,IAAA,CAAM,KAAA,CAAOA,CAAW,CACtC,CAFgBC,CAAAA,CAAAF,CAAAA,CAAA,MA+BT,SAASG,CAAAA,CAAOC,EAAmB,CACzC,OAAO,CAAE,EAAA,CAAI,MAAO,KAAA,CAAOA,CAAW,CACvC,CAFgBF,EAAAC,CAAAA,CAAA,KAAA,CAAA,CAoBT,SAASE,CAAAA,CAAWC,EAAuC,CACjE,OAAOA,EAAO,EAAA,GAAO,IACtB,CAFgBJ,CAAAA,CAAAG,CAAAA,CAAA,MAAA,CAAA,CAoBT,SAASE,EAAYD,CAAAA,CAAwC,CACnE,OAAOA,CAAAA,CAAO,KAAO,KACtB,CAFgBJ,CAAAA,CAAAK,CAAAA,CAAA,SAqBT,SAASC,CAAAA,CACfF,EACAG,CAAAA,CACe,CACf,OAAIH,CAAAA,CAAO,EAAA,CACHG,CAAAA,CAAGH,CAAA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AAMH,CAAAA,CAASK,CAAAA,CAAO,IAAA,CAAK,OAAA,CAASF,CAAE,CAAA,CACtC,GAAI,CAACH,CAAAA,CAAO,EAAA,CACX,OAAO,IAAIyB,CAAAA,CAAUzB,CAAAA,CAAO,KAAK,EAGlC,MAAM,IAAI,MAAM,mCAAmC,CACpD,CACD,EAsCO,IAAM0B,CAAAA,CAAN,MAAMC,UAAsBP,CAAiB,CA1TpD,OA0ToDxB,EAAA,IAAA,CAAA,SAAA,EAAA,CAC3C,WAAA,CAAYI,CAAAA,CAAsB,CACzC,MAAMA,CAAM,EACb,CAKA,OAAO,EAAA,CAAML,EAAsB,CAClC,OAAO,IAAI0B,CAAAA,CAAQ1B,CAAK,CACzB,CAKA,OAAO,GAAA,CAAOG,CAAAA,CAAwB,CACrC,OAAO,IAAIyB,CAAAA,CAAUzB,CAAK,CAC3B,CAKA,OAAO,KAAWE,CAAAA,CAAqC,CACtD,OAAO,IAAI2B,CAAAA,CAAQ3B,CAAM,CAC1B,CAEA,OAAA,CAAWG,CAAAA,CAA+C,CACzD,OAAOwB,EAAQ,IAAA,CAAKzB,CAAAA,CAAQ,IAAA,CAAK,OAAA,CAASC,CAAE,CAAC,CAC9C,CAEA,GAAA,CAAOA,CAAAA,CAAoC,CAC1C,OAAOwB,CAAAA,CAAQ,IAAA,CAAKvB,CAAAA,CAAI,KAAK,OAAA,CAASD,CAAE,CAAC,CAC1C,CAEA,OAAUA,CAAAA,CAAoC,CAC7C,OAAOwB,CAAAA,CAAQ,KAAKtB,CAAAA,CAAO,IAAA,CAAK,QAASF,CAAE,CAAC,CAC7C,CACD","file":"result.js","sourcesContent":["export type Ok<T> = { ok: true; value: T };\nexport type Err<E> = { ok: false; error: E };\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Creates an Ok result with a value.\n *\n * @param value - The success value\n * @returns An Ok result containing the value\n *\n * @example\n * ```typescript\n * const result = ok(42);\n * // result is Ok<number>\n * ```\n */\nexport function ok<T>(value: T): Ok<T>;\n\n/**\n * Creates an Ok result with void (no value).\n *\n * @returns An Ok<void> result\n *\n * @example\n * ```typescript\n * const result = ok();\n * // result is Ok<void>\n * ```\n */\nexport function ok(): Ok<void>;\n\nexport function ok<T>(value?: T): Ok<T> {\n\treturn { ok: true, value: value as T };\n}\n\n/**\n * Creates an Err result with an error.\n *\n * @param error - The error value\n * @returns An Err result containing the error\n *\n * @example\n * ```typescript\n * const result = err(\"Something went wrong\");\n * // result is Err<string>\n * ```\n */\nexport function err<E>(error: E): Err<E>;\n\n/**\n * Creates an Err result with void (no error value).\n *\n * @returns An Err<void> result\n *\n * @example\n * ```typescript\n * const result = err();\n * // result is Err<void>\n * ```\n */\nexport function err(): Err<void>;\n\nexport function err<E>(error?: E): Err<E> {\n\treturn { ok: false, error: error as E };\n}\n\n/**\n * Type guard to check if a Result is Ok.\n * Narrows the type to Ok<T> when returning true.\n *\n * @param result - The result to check\n * @returns true if the result is Ok, false otherwise\n *\n * @example\n * ```typescript\n * const result = voWithValidation(data, validator);\n * if (isOk(result)) {\n * // TypeScript knows result is Ok<ValueObject<T>>\n * console.log(result.value);\n * }\n * ```\n */\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T> {\n\treturn result.ok === true;\n}\n\n/**\n * Type guard to check if a Result is Err.\n * Narrows the type to Err<E> when returning true.\n *\n * @param result - The result to check\n * @returns true if the result is Err, false otherwise\n *\n * @example\n * ```typescript\n * const result = voWithValidation(data, validator);\n * if (isErr(result)) {\n * // TypeScript knows result is Err<string>\n * console.error(result.error);\n * }\n * ```\n */\nexport function isErr<T, E>(result: Result<T, E>): result is Err<E> {\n\treturn result.ok === false;\n}\n\n/**\n * Chains Result operations (flatMap/bind).\n * If the result is Ok, applies the function to the value.\n * If Err, returns the error unchanged.\n *\n * @param result - The result to chain\n * @param fn - Function that takes the Ok value and returns a new Result\n * @returns A new Result\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"123\")\n * .andThen(userId => validateEmail(\"test@example.com\")\n * .map(email => ({ id: userId, email }))\n * );\n * ```\n */\nexport function andThen<T, E, U>(\n\tresult: Result<T, E>,\n\tfn: (value: T) => Result<U, E>,\n): Result<U, E> {\n\tif (result.ok) {\n\t\treturn fn(result.value);\n\t}\n\treturn result;\n}\n\n/**\n * Transforms the Ok value using a function.\n * If the result is Err, returns the error unchanged.\n *\n * @param result - The result to transform\n * @param fn - Function to transform the Ok value\n * @returns A new Result with transformed value\n *\n * @example\n * ```typescript\n * const result = ok(5);\n * const doubled = map(result, x => x * 2); // Ok<10>\n * ```\n */\nexport function map<T, E, U>(\n\tresult: Result<T, E>,\n\tfn: (value: T) => U,\n): Result<U, E> {\n\tif (result.ok) {\n\t\treturn ok(fn(result.value));\n\t}\n\treturn result;\n}\n\n/**\n * Transforms the Err value using a function.\n * If the result is Ok, returns the value unchanged.\n *\n * @param result - The result to transform\n * @param fn - Function to transform the Err value\n * @returns A new Result with transformed error\n *\n * @example\n * ```typescript\n * const result = err(\"not found\");\n * const mapped = mapErr(result, e => `Error: ${e}`); // Err<\"Error: not found\">\n * ```\n */\nexport function mapErr<T, E, F>(\n\tresult: Result<T, E>,\n\tfn: (error: E) => F,\n): Result<T, F> {\n\tif (result.ok) {\n\t\treturn result;\n\t}\n\treturn err(fn(result.error));\n}\n\n/**\n * Returns the value if Ok, otherwise returns the default value.\n *\n * @param result - The result to unwrap\n * @param defaultValue - Default value to return if Err\n * @returns The Ok value or the default value\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"123\");\n * const userId = unwrapOr(result, \"default-id\");\n * ```\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n\treturn result.ok ? result.value : defaultValue;\n}\n\n/**\n * Returns the value if Ok, otherwise computes default from error.\n *\n * @param result - The result to unwrap\n * @param fn - Function to compute default from error\n * @returns The Ok value or computed default\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"\");\n * const userId = unwrapOrElse(result, err => `fallback-${Date.now()}`);\n * ```\n */\nexport function unwrapOrElse<T, E>(\n\tresult: Result<T, E>,\n\tfn: (error: E) => T,\n): T {\n\treturn result.ok ? result.value : fn(result.error);\n}\n\n/**\n * Pattern matching for Result.\n * Applies one function if Ok, another if Err.\n *\n * @param result - The result to match\n * @param onOk - Function to apply if Ok\n * @param onErr - Function to apply if Err\n * @returns The result of applying the appropriate function\n *\n * @example\n * ```typescript\n * const message = match(result,\n * value => `Success: ${value}`,\n * error => `Error: ${error}`\n * );\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const message = match(result, {\n * ok: value => `Success: ${value}`,\n * err: error => `Error: ${error}`\n * });\n * ```\n */\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\tonOk: (value: T) => R,\n\tonErr: (error: E) => R,\n): R;\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\thandlers: { ok: (value: T) => R; err: (error: E) => R },\n): R;\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\tonOkOrHandlers: ((value: T) => R) | { ok: (value: T) => R; err: (error: E) => R },\n\tonErr?: (error: E) => R,\n): R {\n\tif (typeof onOkOrHandlers === \"function\") {\n\t\t// Function syntax: match(result, onOk, onErr)\n\t\treturn result.ok ? onOkOrHandlers(result.value) : onErr!(result.error);\n\t}\n\t// Object syntax: match(result, { ok: ..., err: ... })\n\treturn result.ok\n\t\t? onOkOrHandlers.ok(result.value)\n\t\t: onOkOrHandlers.err(result.error);\n}\n\n/**\n * Async pattern matching for Result.\n * Applies one async function if Ok, another if Err.\n * Both handlers must return Promises.\n *\n * @param result - The result to match\n * @param onOk - Async function to apply if Ok\n * @param onErr - Async function to apply if Err\n * @returns Promise resolving to the result of applying the appropriate function\n *\n * @example\n * ```typescript\n * const message = await matchAsync(result,\n * async (value) => `Success: ${value}`,\n * async (error) => `Error: ${error}`\n * );\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const message = await matchAsync(result, {\n * ok: async (value) => `Success: ${value}`,\n * err: async (error) => `Error: ${error}`\n * });\n * ```\n */\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\tonOk: (value: T) => Promise<R>,\n\tonErr: (error: E) => Promise<R>,\n): Promise<R>;\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\thandlers: { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n): Promise<R>;\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\tonOkOrHandlers:\n\t\t| ((value: T) => Promise<R>)\n\t\t| { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\tonErr?: (error: E) => Promise<R>,\n): Promise<R> {\n\tif (typeof onOkOrHandlers === \"function\") {\n\t\t// Function syntax: matchAsync(result, onOk, onErr)\n\t\treturn result.ok\n\t\t\t? onOkOrHandlers(result.value)\n\t\t\t: onErr!(result.error);\n\t}\n\t// Object syntax: matchAsync(result, { ok: ..., err: ... })\n\treturn result.ok\n\t\t? onOkOrHandlers.ok(result.value)\n\t\t: onOkOrHandlers.err(result.error);\n}\n\n/**\n * Pipes a Result through multiple operations.\n * Each function receives the previous Result and returns a new Result.\n * Stops on first error.\n *\n * @param initial - The initial Result value\n * @param fns - Array of functions that take the previous Result and return a new Result\n * @returns The final Result after all operations\n *\n * @example\n * ```typescript\n * // Instead of nested andThen calls:\n * andThen(\n * updateCountryCode(code),\n * () => andThen(updateCurrencyCode(currency), () => updateLanguageCode(lang))\n * )\n *\n * // Use pipe (cleaner and more readable):\n * pipe(\n * updateCountryCode(code),\n * () => updateCurrencyCode(currency),\n * () => updateLanguageCode(lang)\n * )\n * ```\n *\n * @example With void results\n * ```typescript\n * setInitialData(initialData: JobConfigProps[\"initialData\"]): Result<void, JobDomainError> {\n * return pipe(\n * this.updateCountryCode(initialData.countryCode),\n * () => this.updateCurrencyCode(initialData.currencyCode),\n * () => this.updateLanguageCode(initialData.languageCode)\n * );\n * }\n * ```\n */\nexport function pipe<T, E>(\n\tinitial: Result<T, E>,\n\t...fns: Array<(prev: Result<T, E>) => Result<T, E>>\n): Result<T, E> {\n\tlet current = initial;\n\tfor (const fn of fns) {\n\t\tcurrent = fn(current);\n\t\tif (!current.ok) {\n\t\t\treturn current;\n\t\t}\n\t}\n\treturn current;\n}\n\n/**\n * Wraps a function that may throw exceptions into a Result type.\n * Catches any thrown exceptions and converts them to Err results.\n *\n * @param fn - Function that may throw exceptions\n * @param errorMapper - Optional function to transform the caught error\n * @returns A Result containing the function's return value or error\n *\n * @example\n * ```typescript\n * function riskyOperation(): string {\n * if (Math.random() > 0.5) {\n * throw new Error(\"Something went wrong\");\n * }\n * return \"success\";\n * }\n *\n * const result = tryCatch(() => riskyOperation());\n * if (result.ok) {\n * console.log(result.value); // \"success\"\n * } else {\n * console.error(result.error.message); // \"Something went wrong\"\n * }\n * ```\n *\n * @example With custom error mapper\n * ```typescript\n * const result = tryCatch(\n * () => riskyOperation(),\n * (error) => `Custom: ${error instanceof Error ? error.message : String(error)}`\n * );\n * ```\n */\nexport function tryCatch<T, E = Error>(\n\tfn: () => T,\n\terrorMapper?: (error: unknown) => E,\n): Result<T, E> {\n\ttry {\n\t\treturn ok(fn());\n\t} catch (error) {\n\t\tif (errorMapper) {\n\t\t\treturn err(errorMapper(error));\n\t\t}\n\t\treturn err((error instanceof Error ? error : new Error(String(error))) as E);\n\t}\n}\n\n/**\n * Wraps an async function that may throw exceptions into a Promise<Result>.\n * Catches any thrown exceptions and converts them to Err results.\n *\n * @param fn - Async function that may throw exceptions\n * @param errorMapper - Optional function to transform the caught error\n * @returns A Promise resolving to a Result containing the function's return value or error\n *\n * @example\n * ```typescript\n * async function riskyAsyncOperation(): Promise<string> {\n * if (Math.random() > 0.5) {\n * throw new Error(\"Something went wrong\");\n * }\n * return \"success\";\n * }\n *\n * const result = await tryCatchAsync(() => riskyAsyncOperation());\n * if (result.ok) {\n * console.log(result.value); // \"success\"\n * } else {\n * console.error(result.error.message); // \"Something went wrong\"\n * }\n * ```\n */\nexport async function tryCatchAsync<T, E = Error>(\n\tfn: () => Promise<T>,\n\terrorMapper?: (error: unknown) => E,\n): Promise<Result<T, E>> {\n\ttry {\n\t\tconst value = await fn();\n\t\treturn ok(value);\n\t} catch (error) {\n\t\tif (errorMapper) {\n\t\t\treturn err(errorMapper(error));\n\t\t}\n\t\treturn err((error instanceof Error ? error : new Error(String(error))) as E);\n\t}\n}\n\n","import {\n andThen,\n err,\n isErr,\n isOk,\n map,\n mapErr,\n match,\n matchAsync,\n ok,\n type Result,\n unwrapOr,\n unwrapOrElse,\n} from \"./result\";\n\n/**\n * Base class for Result with method chaining support.\n * Provides common methods for both Ok and Err classes.\n */\nabstract class ResultBase<T, E> {\n\tprotected readonly _result: Result<T, E>;\n\n\tprotected constructor(result: Result<T, E>) {\n\t\tthis._result = result;\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise throws an error.\n\t * If error is an Error instance, throws it directly.\n\t * Otherwise, wraps the error in a new Error.\n\t *\n\t * @throws Error if the result is Err\n\t */\n\tunwrap(): T {\n\t\tif (this._result.ok) {\n\t\t\treturn this._result.value;\n\t\t}\n\t\tif (this._result.error instanceof Error) {\n\t\t\tthrow this._result.error;\n\t\t}\n\t\tthrow new Error(String(this._result.error));\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise returns the default value.\n\t */\n\tunwrapOr(defaultValue: T): T {\n\t\treturn unwrapOr(this._result, defaultValue);\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise computes default from error.\n\t */\n\tunwrapOrElse(fn: (error: E) => T): T {\n\t\treturn unwrapOrElse(this._result, fn);\n\t}\n\n\t/**\n\t * Pattern matching for Result.\n\t * Applies one function if Ok, another if Err.\n\t *\n\t * @example\n\t * ```typescript\n\t * outcome.match(\n\t * value => `Success: ${value}`,\n\t * error => `Error: ${error}`\n\t * );\n\t * ```\n\t *\n\t * @example Using object syntax\n\t * ```typescript\n\t * outcome.match({\n\t * ok: value => `Success: ${value}`,\n\t * err: error => `Error: ${error}`\n\t * });\n\t * ```\n\t */\n\tmatch<R>(\n\t\tonOk: (value: T) => R,\n\t\tonErr: (error: E) => R,\n\t): R;\n\tmatch<R>(\n\t\thandlers: { ok: (value: T) => R; err: (error: E) => R },\n\t): R;\n\tmatch<R>(\n\t\tonOkOrHandlers: ((value: T) => R) | { ok: (value: T) => R; err: (error: E) => R },\n\t\tonErr?: (error: E) => R,\n\t): R {\n\t\tif (typeof onOkOrHandlers === \"function\") {\n\t\t\treturn match(this._result, onOkOrHandlers, onErr!);\n\t\t}\n\t\treturn match(this._result, onOkOrHandlers);\n\t}\n\n\t/**\n\t * Async pattern matching for Result.\n\t * Applies one async function if Ok, another if Err.\n\t *\n\t * @example\n\t * ```typescript\n\t * await outcome.matchAsync(\n\t * async (value) => `Success: ${value}`,\n\t * async (error) => `Error: ${error}`\n\t * );\n\t * ```\n\t *\n\t * @example Using object syntax\n\t * ```typescript\n\t * await outcome.matchAsync({\n\t * ok: async (value) => `Success: ${value}`,\n\t * err: async (error) => `Error: ${error}`\n\t * });\n\t * ```\n\t */\n\tmatchAsync<R>(\n\t\tonOk: (value: T) => Promise<R>,\n\t\tonErr: (error: E) => Promise<R>,\n\t): Promise<R>;\n\tmatchAsync<R>(\n\t\thandlers: { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\t): Promise<R>;\n\tasync matchAsync<R>(\n\t\tonOkOrHandlers:\n\t\t\t| ((value: T) => Promise<R>)\n\t\t\t| { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\t\tonErr?: (error: E) => Promise<R>,\n\t): Promise<R> {\n\t\tif (typeof onOkOrHandlers === \"function\") {\n\t\t\treturn matchAsync(this._result, onOkOrHandlers, onErr!);\n\t\t}\n\t\treturn matchAsync(this._result, onOkOrHandlers);\n\t}\n\n\t/**\n\t * Type guard to check if the result is Ok.\n\t */\n\tisOk(): this is Success<T> {\n\t\treturn isOk(this._result);\n\t}\n\n\t/**\n\t * Type guard to check if the result is Err.\n\t */\n\tisErr(): this is Erroneous<E> {\n\t\treturn isErr(this._result);\n\t}\n\n\t/**\n\t * Gets the underlying Result value.\n\t */\n\tget result(): Result<T, E> {\n\t\treturn this._result;\n\t}\n}\n\n/**\n * Class representing a successful result with method chaining support.\n * Use this for class-based API with method chaining.\n *\n * @example\n * ```typescript\n * const okResult = Ok(1);\n * const doubled = okResult.map(x => x * 2).unwrap(); // 2\n *\n * const chained = Ok(5)\n * .andThen(x => Ok(x * 2))\n * .map(x => x + 1)\n * .unwrap(); // 11\n * ```\n */\nclass Success<T> extends ResultBase<T, never> {\n\tconstructor(value: T) {\n\t\tsuper(ok(value));\n\t}\n\n\t/**\n\t * Factory function to create an Ok instance.\n\t * Can be called with or without `new`.\n\t */\n\tstatic of<T>(value: T): Success<T> {\n\t\treturn new Success(value);\n\t}\n\n\t/**\n\t * Chains Result operations (flatMap/bind).\n\t * If the result is Ok, applies the function to the value.\n\t * If Err, returns the error unchanged.\n\t */\n\tandThen<U, E>(fn: (value: T) => Result<U, E>): Success<U> | Erroneous<E> {\n\t\tconst result = andThen(this._result, fn);\n\t\tif (result.ok) {\n\t\t\treturn new Success(result.value);\n\t\t}\n\t\treturn new Erroneous(result.error);\n\t}\n\n\t/**\n\t * Transforms the Ok value using a function.\n\t * If the result is Err, returns the error unchanged.\n\t */\n\tmap<U>(fn: (value: T) => U): Success<U> {\n\t\tconst result = map(this._result, fn);\n\t\tif (result.ok) {\n\t\t\treturn new Success(result.value);\n\t\t}\n\t\t// This should never happen for Success, but TypeScript needs it\n\t\tthrow new Error(\"Unexpected error in Success.map\");\n\t}\n\n\t/**\n\t * Transforms the Err value using a function.\n\t * If the result is Ok, returns the value unchanged.\n\t */\n\tmapErr<F>(_fn: (error: never) => F): Success<T> {\n\t\treturn this;\n\t}\n}\n\nexport { Success };\n\n/**\n * Class representing an erroneous result with method chaining support.\n * Use this for class-based API with method chaining.\n *\n * @example\n * ```typescript\n * const errResult = Err(new Error(\"error\"));\n * errResult.map(x => x * 2).unwrap(); // throws Error(\"error\")\n *\n * const mapped = Err(\"original\")\n * .mapErr(e => `Error: ${e}`)\n * .unwrap(); // throws Error(\"Error: original\")\n * ```\n */\nclass Erroneous<E> extends ResultBase<never, E> {\n\tconstructor(error: E) {\n\t\tsuper(err(error));\n\t}\n\n\t/**\n\t * Factory function to create an Err instance.\n\t * Can be called with or without `new`.\n\t */\n\tstatic of<E>(error: E): Erroneous<E> {\n\t\treturn new Erroneous(error);\n\t}\n\n\t/**\n\t * Chains Result operations (flatMap/bind).\n\t * If the result is Ok, applies the function to the value.\n\t * If Err, returns the error unchanged.\n\t */\n\tandThen<U>(_fn: (value: never) => Result<U, E>): Erroneous<E> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transforms the Ok value using a function.\n\t * If the result is Err, returns the error unchanged.\n\t */\n\tmap<U>(_fn: (value: never) => U): Erroneous<E> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transforms the Err value using a function.\n\t * If the result is Ok, returns the value unchanged.\n\t */\n\tmapErr<F>(fn: (error: E) => F): Erroneous<F> {\n\t\tconst result = mapErr(this._result, fn);\n\t\tif (!result.ok) {\n\t\t\treturn new Erroneous(result.error);\n\t\t}\n\t\t// This should never happen for Erroneous, but TypeScript needs it\n\t\tthrow new Error(\"Unexpected ok in Erroneous.mapErr\");\n\t}\n}\n\nexport { Erroneous };\n\n/**\n * Factory functions for creating Ok and Err instances.\n * These can be called without `new` for a more functional style.\n *\n * @example\n * ```typescript\n * const okResult = Ok(1);\n * const errResult = Err(\"error\");\n * ```\n */\nexport function Ok<T>(value: T): Success<T> {\n\treturn new Success(value);\n}\n\nexport function Err<E>(error: E): Erroneous<E> {\n\treturn new Erroneous(error);\n}\n\n/**\n * Class-based API for Result with method chaining support.\n * Provides an object-oriented alternative to the functional Result type.\n * Use `Outcome.from()` to wrap an existing Result, or `Outcome.ok()` / `Outcome.err()` to create new instances.\n *\n * @example\n * ```typescript\n * // Wrap an existing Result\n * const result = Outcome.from(ok(1));\n * const doubled = result.map(x => x * 2).unwrap(); // 2\n *\n * // Create directly\n * const outcome = Outcome.ok(42);\n * const value = outcome.map(x => x + 1).unwrap(); // 43\n * ```\n */\nexport class Outcome<T, E> extends ResultBase<T, E> {\n\tprivate constructor(result: Result<T, E>) {\n\t\tsuper(result);\n\t}\n\n\t/**\n\t * Creates an Outcome from an Ok value.\n\t */\n\tstatic ok<T>(value: T): Success<T> {\n\t\treturn new Success(value);\n\t}\n\n\t/**\n\t * Creates an Outcome from an Err value.\n\t */\n\tstatic err<E>(error: E): Erroneous<E> {\n\t\treturn new Erroneous(error);\n\t}\n\n\t/**\n\t * Creates an Outcome from a Result.\n\t */\n\tstatic from<T, E>(result: Result<T, E>): Outcome<T, E> {\n\t\treturn new Outcome(result);\n\t}\n\n\tandThen<U>(fn: (value: T) => Result<U, E>): Outcome<U, E> {\n\t\treturn Outcome.from(andThen(this._result, fn));\n\t}\n\n\tmap<U>(fn: (value: T) => U): Outcome<U, E> {\n\t\treturn Outcome.from(map(this._result, fn));\n\t}\n\n\tmapErr<F>(fn: (error: E) => F): Outcome<T, F> {\n\t\treturn Outcome.from(mapErr(this._result, fn));\n\t}\n}\n\n"]}
|