@l3dev/result 0.6.2 → 0.6.3
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/build/result.types.d.ts +1 -0
- package/build/result.types.js.map +1 -1
- package/build/unwrap.d.ts +1 -2
- package/build/unwrap.js.map +1 -1
- package/package.json +1 -1
package/build/result.types.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export type ResultErrorDefinition<TType, TContext> = {
|
|
|
7
7
|
export type ReturnResult<TValue, TError extends ResultErrorDefinition<any, any>> = Ok<TValue> | Err<TError["type"], TError["context"]>;
|
|
8
8
|
export type ResultFn<TInput extends any[] = any[], TResult extends ReturnResult<any, any> = ReturnResult<any, any>> = (...args: TInput) => TResult;
|
|
9
9
|
export type ResultAsyncFn<TInput extends any[] = any[], TResult extends Promise<ReturnResult<any, any>> = Promise<ReturnResult<any, any>>> = (...args: TInput) => TResult;
|
|
10
|
+
export type UnwrapResult<TResult extends ReturnResult<any, any>> = TResult extends Ok<infer TValue> ? TValue extends ReturnResult<any, any> ? 0 extends 1 & TValue ? TResult : UnwrapResult<TValue> : TResult : TResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.types.js","sourceRoot":"","sources":["../src/result.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Err } from \"./err.js\";\nimport type { Ok } from \"./ok.js\";\n\nexport type ResultErrorDefinition<TType, TContext> = {\n\ttype: TType;\n\tcontext: TContext;\n};\n\nexport type ReturnResult<TValue, TError extends ResultErrorDefinition<any, any>> =\n\t| Ok<TValue>\n\t| Err<TError[\"type\"], TError[\"context\"]>;\n\nexport type ResultFn<\n\tTInput extends any[] = any[],\n\tTResult extends ReturnResult<any, any> = ReturnResult<any, any>\n> = (...args: TInput) => TResult;\n\nexport type ResultAsyncFn<\n\tTInput extends any[] = any[],\n\tTResult extends Promise<ReturnResult<any, any>> = Promise<ReturnResult<any, any>>\n> = (...args: TInput) => TResult;\n"]}
|
|
1
|
+
{"version":3,"file":"result.types.js","sourceRoot":"","sources":["../src/result.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Err } from \"./err.js\";\nimport type { Ok } from \"./ok.js\";\n\nexport type ResultErrorDefinition<TType, TContext> = {\n\ttype: TType;\n\tcontext: TContext;\n};\n\nexport type ReturnResult<TValue, TError extends ResultErrorDefinition<any, any>> =\n\t| Ok<TValue>\n\t| Err<TError[\"type\"], TError[\"context\"]>;\n\nexport type ResultFn<\n\tTInput extends any[] = any[],\n\tTResult extends ReturnResult<any, any> = ReturnResult<any, any>\n> = (...args: TInput) => TResult;\n\nexport type ResultAsyncFn<\n\tTInput extends any[] = any[],\n\tTResult extends Promise<ReturnResult<any, any>> = Promise<ReturnResult<any, any>>\n> = (...args: TInput) => TResult;\n\nexport type UnwrapResult<TResult extends ReturnResult<any, any>> =\n\tTResult extends Ok<infer TValue>\n\t\t? TValue extends ReturnResult<any, any>\n\t\t\t? 0 extends 1 & TValue\n\t\t\t\t? TResult\n\t\t\t\t: UnwrapResult<TValue>\n\t\t\t: TResult\n\t\t: TResult;\n"]}
|
package/build/unwrap.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Ok } from "./ok";
|
|
2
|
-
import type { ReturnResult } from "./result.types";
|
|
3
|
-
export type UnwrapResult<TResult extends ReturnResult<any, any>> = TResult extends Ok<infer TValue> ? TValue extends ReturnResult<any, any> ? 0 extends 1 & TValue ? TResult : UnwrapResult<TValue> : TResult : TResult;
|
|
2
|
+
import type { ReturnResult, UnwrapResult } from "./result.types";
|
|
4
3
|
export declare function unwrap<TResult extends ReturnResult<any, any>>(result: TResult): UnwrapResult<TResult>;
|
|
5
4
|
export declare function unwrapOrDefault<TResult extends ReturnResult<any, any>, TValue = TResult extends Ok<infer TValue> ? TValue : never>(result: TResult, defaultValue: NoInfer<TValue>): TValue;
|
package/build/unwrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap.js","sourceRoot":"","sources":["../src/unwrap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unwrap.js","sourceRoot":"","sources":["../src/unwrap.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,MAAM,CACrB,MAAe;IAEf,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAC3F,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,MAA+B,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,eAAe,CAG7B,MAAe,EAAE,YAA6B;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;AACtD,CAAC","sourcesContent":["import type { Ok } from \"./ok\";\nimport type { ReturnResult, UnwrapResult } from \"./result.types\";\n\nexport function unwrap<TResult extends ReturnResult<any, any>>(\n\tresult: TResult\n): UnwrapResult<TResult> {\n\tif (result.ok && result.value && typeof result.value === \"object\" && \"ok\" in result.value) {\n\t\treturn unwrap(result.value);\n\t}\n\treturn result as UnwrapResult<TResult>;\n}\n\nexport function unwrapOrDefault<\n\tTResult extends ReturnResult<any, any>,\n\tTValue = TResult extends Ok<infer TValue> ? TValue : never\n>(result: TResult, defaultValue: NoInfer<TValue>): TValue {\n\tconst unwrapped = unwrap(result);\n\treturn unwrapped.ok ? unwrapped.value : defaultValue;\n}\n"]}
|