@l3dev/result 0.6.0 → 0.6.2

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/unwrap.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Ok } from "./ok";
2
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> ? UnwrapResult<TValue> : TResult : TResult;
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;
4
4
  export declare function unwrap<TResult extends ReturnResult<any, any>>(result: TResult): UnwrapResult<TResult>;
5
5
  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 CHANGED
@@ -1,5 +1,5 @@
1
1
  export function unwrap(result) {
2
- if (result.ok && typeof result.value === "object" && "ok" in result.value) {
2
+ if (result.ok && result.value && typeof result.value === "object" && "ok" in result.value) {
3
3
  return unwrap(result.value);
4
4
  }
5
5
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"unwrap.js","sourceRoot":"","sources":["../src/unwrap.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,MAAM,CACrB,MAAe;IAEf,IAAI,MAAM,CAAC,EAAE,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAC3E,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 } from \"./result.types\";\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? UnwrapResult<TValue>\n\t\t\t: TResult\n\t\t: TResult;\n\nexport function unwrap<TResult extends ReturnResult<any, any>>(\n\tresult: TResult\n): UnwrapResult<TResult> {\n\tif (result.ok && 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"]}
1
+ {"version":3,"file":"unwrap.js","sourceRoot":"","sources":["../src/unwrap.ts"],"names":[],"mappings":"AAYA,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 } from \"./result.types\";\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\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@l3dev/result",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Type-safe result-based error handling",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",