resultfier 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{extra → action}/action.d.ts +1 -1
  3. package/dist/action/action.js +3 -0
  4. package/dist/{extra → action}/index.d.ts +1 -1
  5. package/dist/action/index.js +3 -0
  6. package/dist/{extra → action}/index.js.map +1 -1
  7. package/dist/chunk-7CTLLC5F.js +3 -0
  8. package/dist/chunk-7CTLLC5F.js.map +1 -0
  9. package/dist/chunk-D2DM2EYA.js +7 -0
  10. package/dist/chunk-D2DM2EYA.js.map +1 -0
  11. package/dist/chunk-GGEJTXXS.js +74 -0
  12. package/dist/chunk-GGEJTXXS.js.map +1 -0
  13. package/dist/chunk-GLSQCN75.js +75 -0
  14. package/dist/chunk-GLSQCN75.js.map +1 -0
  15. package/dist/chunk-ITR7ZRJM.js +17 -0
  16. package/dist/chunk-ITR7ZRJM.js.map +1 -0
  17. package/dist/chunk-SQ4P2HRX.js +3 -0
  18. package/dist/chunk-SQ4P2HRX.js.map +1 -0
  19. package/dist/core/err.d.ts +1 -1
  20. package/dist/core/err.js +2 -73
  21. package/dist/core/err.js.map +1 -1
  22. package/dist/core/index.d.ts +169 -1
  23. package/dist/core/index.js +4 -2
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/ok.d.ts +1 -1
  26. package/dist/core/ok.js +2 -72
  27. package/dist/core/ok.js.map +1 -1
  28. package/dist/core/result.d.ts +1 -1
  29. package/dist/core/result.js +1 -5
  30. package/dist/core/result.js.map +1 -1
  31. package/dist/zod-wrapper/index.d.ts +3 -0
  32. package/dist/zod-wrapper/index.js +7 -0
  33. package/dist/zod-wrapper/index.js.map +1 -0
  34. package/dist/zod-wrapper/zod.d.ts +6 -0
  35. package/dist/zod-wrapper/zod.js +7 -0
  36. package/dist/zod-wrapper/zod.js.map +1 -0
  37. package/package.json +16 -4
  38. package/dist/extra/action.js +0 -3
  39. package/dist/extra/index.js +0 -3
  40. package/dist/index-Dy6VGmoZ.d.ts +0 -169
  41. package/eslint.config.mjs +0 -10
  42. package/mise.toml +0 -2
  43. package/pnpm-workspace.yaml +0 -2
  44. /package/dist/{extra → action}/action.js.map +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # resultfier
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2f11d84: add zod integration and reorganize the project
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import { A as AsyncResult } from '../index-Dy6VGmoZ.js';
1
+ import { AsyncResult } from '../core/index.js';
2
2
 
3
3
  type Action<TParams, TData, TError> = (params: TParams) => AsyncResult<TData, TError>;
4
4
 
@@ -0,0 +1,3 @@
1
+ import '../chunk-7CTLLC5F.js';
2
+ //# sourceMappingURL=action.js.map
3
+ //# sourceMappingURL=action.js.map
@@ -1,2 +1,2 @@
1
1
  export { Action } from './action.js';
2
- import '../index-Dy6VGmoZ.js';
2
+ import '../core/index.js';
@@ -0,0 +1,3 @@
1
+ import '../chunk-7CTLLC5F.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=chunk-7CTLLC5F.js.map
3
+ //# sourceMappingURL=chunk-7CTLLC5F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-7CTLLC5F.js"}
@@ -0,0 +1,7 @@
1
+ // src/core/result.ts
2
+ var ResultBase = class {
3
+ };
4
+
5
+ export { ResultBase };
6
+ //# sourceMappingURL=chunk-D2DM2EYA.js.map
7
+ //# sourceMappingURL=chunk-D2DM2EYA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/result.ts"],"names":[],"mappings":";AAOO,IAAe,aAAf,MAAgC;AA4DvC","file":"chunk-D2DM2EYA.js","sourcesContent":["import type { Err } from '@/core/err';\nimport type { Ok } from '@/core/ok';\n\n/**\n * Represents a Result type that can either be a success (`Ok`) or an error (`Err`).\n * This is an abstract base class that provides common functionality for both variants.\n */\nexport abstract class ResultBase<T, E> {\n /**\n * Type guard to check if the result is an `Ok` variant.\n */\n abstract readonly isOk: boolean;\n\n /**\n * Type guard to check if the result is an `Err` variant.\n */\n abstract readonly isErr: boolean;\n\n /**\n * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,\n * leaving an `Err` value untouched.\n */\n abstract map<U>(fn: (value: T) => U): Result<U, E>;\n\n /**\n * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,\n * leaving an `Ok` value untouched.\n */\n abstract mapErr<F>(fn: (error: E) => F): Result<T, F>;\n\n /**\n * Returns the contained `Ok` value, consuming the self value.\n * Throws an error if the result is `Err`.\n */\n abstract unwrap(): T;\n\n /**\n * Returns the contained `Err` value, consuming the self value.\n * Throws an error if the result is Ok.\n */\n abstract unwrapErr(): E;\n\n /**\n * Returns the contained `Ok` value or a provided default.\n */\n abstract unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Ok` value or computes it from a closure.\n */\n abstract unwrapOrElse(fn: (error: E) => T): T;\n\n /**\n * Calls the provided function with the contained value and returns the result.\n * If the result is `Err`, the function is not called and the `Err` is returned.\n */\n abstract andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;\n\n /**\n * Returns true if the result is `Ok` and the value inside of it matches a predicate.\n */\n abstract contains(value: T): boolean;\n\n /**\n * Returns true if the result is `Err` and the error inside of it matches a predicate.\n */\n abstract containsErr(error: E): boolean;\n}\n\n/**\n * Type alias for a `Result` that can be either `Ok<T>` or `Err<E>`.\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Type alias for an async `Result` (Promise-wrapped `Result`).\n */\nexport type AsyncResult<T, E> = Promise<Result<T, E>>;\n"]}
@@ -0,0 +1,74 @@
1
+ import { ResultBase } from './chunk-D2DM2EYA.js';
2
+
3
+ // src/core/ok.ts
4
+ var Ok = class _Ok extends ResultBase {
5
+ constructor(value) {
6
+ super();
7
+ this.value = value;
8
+ }
9
+ _tag = "ok";
10
+ isOk = true;
11
+ isErr = false;
12
+ /**
13
+ * Maps the contained value using the provided function.
14
+ * Since this is `Ok`, the function is always applied.
15
+ */
16
+ map(fn) {
17
+ return new _Ok(fn(this.value));
18
+ }
19
+ /**
20
+ * Maps the error type, but since this is `Ok`, it's a no-op.
21
+ */
22
+ mapErr(_fn) {
23
+ return this;
24
+ }
25
+ /**
26
+ * Returns the contained value.
27
+ */
28
+ unwrap() {
29
+ return this.value;
30
+ }
31
+ /**
32
+ * Throws an error since this is Ok, not Err.
33
+ */
34
+ unwrapErr() {
35
+ throw new Error(`Called unwrapErr() on an Ok value: ${this.value}`);
36
+ }
37
+ /**
38
+ * Returns the contained value, ignoring the default.
39
+ */
40
+ unwrapOr(_defaultValue) {
41
+ return this.value;
42
+ }
43
+ /**
44
+ * Returns the contained value, ignoring the fallback function.
45
+ */
46
+ unwrapOrElse(_fn) {
47
+ return this.value;
48
+ }
49
+ /**
50
+ * Applies the function to the contained value and returns the result.
51
+ */
52
+ andThen(fn) {
53
+ return fn(this.value);
54
+ }
55
+ /**
56
+ * Checks if the contained value matches the provided value.
57
+ */
58
+ contains(value) {
59
+ return this.value === value;
60
+ }
61
+ /**
62
+ * Always returns false since this is `Ok`, not `Err`.
63
+ */
64
+ containsErr(_error) {
65
+ return false;
66
+ }
67
+ };
68
+ function ok(value) {
69
+ return new Ok(value);
70
+ }
71
+
72
+ export { Ok, ok };
73
+ //# sourceMappingURL=chunk-GGEJTXXS.js.map
74
+ //# sourceMappingURL=chunk-GGEJTXXS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/ok.ts"],"names":[],"mappings":";;;AAMO,IAAM,EAAA,GAAN,MAAM,GAAA,SAAc,UAAA,CAAqB;AAAA,EAK5C,YAAqB,KAAA,EAAU;AAC3B,IAAA,KAAA,EAAM;AADW,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAErB;AAAA,EANS,IAAA,GAAO,IAAA;AAAA,EACP,IAAA,GAAO,IAAA;AAAA,EACP,KAAA,GAAQ,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUjB,IAAO,EAAA,EAA4B;AAC/B,IAAA,OAAO,IAAI,GAAA,CAAG,EAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAU,GAAA,EAAiC;AACvC,IAAA,OAAO,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GAAY;AACR,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAmB;AACf,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mCAAA,EAAsC,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,aAAA,EAAqB;AAC1B,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,GAAA,EAA6B;AACtC,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,EAAA,EAAsD;AAC7D,IAAA,OAAO,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,KAAA,EAAmB;AACxB,IAAA,OAAO,KAAK,KAAA,KAAU,KAAA;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKS,YAAY,MAAA,EAAsB;AACvC,IAAA,OAAO,KAAA;AAAA,EACX;AACJ;AAKO,SAAS,GAAM,KAAA,EAAiB;AACnC,EAAA,OAAO,IAAI,GAAG,KAAK,CAAA;AACvB","file":"chunk-GGEJTXXS.js","sourcesContent":["import type { Result } from '@/core/result';\nimport { ResultBase } from '@/core/result';\n\n/**\n * Represents a successful result containing a value.\n */\nexport class Ok<T> extends ResultBase<T, never> {\n readonly _tag = 'ok' as const;\n readonly isOk = true;\n readonly isErr = false;\n\n constructor(readonly value: T) {\n super();\n }\n\n /**\n * Maps the contained value using the provided function.\n * Since this is `Ok`, the function is always applied.\n */\n map<U>(fn: (value: T) => U): Ok<U> {\n return new Ok(fn(this.value));\n }\n\n /**\n * Maps the error type, but since this is `Ok`, it's a no-op.\n */\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n /**\n * Returns the contained value.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Throws an error since this is Ok, not Err.\n */\n unwrapErr(): never {\n throw new Error(`Called unwrapErr() on an Ok value: ${this.value}`);\n }\n\n /**\n * Returns the contained value, ignoring the default.\n */\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n /**\n * Returns the contained value, ignoring the fallback function.\n */\n unwrapOrElse(_fn: (error: never) => T): T {\n return this.value;\n }\n\n /**\n * Applies the function to the contained value and returns the result.\n */\n andThen<U>(fn: (value: T) => Result<U, never>): Result<U, never> {\n return fn(this.value);\n }\n\n /**\n * Checks if the contained value matches the provided value.\n */\n contains(value: T): boolean {\n return this.value === value;\n }\n\n /**\n * Always returns false since this is `Ok`, not `Err`.\n */\n override containsErr(_error: never): false {\n return false;\n }\n}\n\n/**\n * Creates a new `Ok` result with the given value.\n */\nexport function ok<T>(value: T): Ok<T> {\n return new Ok(value);\n}\n"]}
@@ -0,0 +1,75 @@
1
+ import { ResultBase } from './chunk-D2DM2EYA.js';
2
+
3
+ // src/core/err.ts
4
+ var Err = class _Err extends ResultBase {
5
+ // eslint-disable-next-line node/handle-callback-err
6
+ constructor(error) {
7
+ super();
8
+ this.error = error;
9
+ }
10
+ _tag = "err";
11
+ isOk = false;
12
+ isErr = true;
13
+ /**
14
+ * Maps the value type, but since this is `Err`, it's a no-op.
15
+ */
16
+ map(_fn) {
17
+ return this;
18
+ }
19
+ /**
20
+ * Maps the contained error using the provided function.
21
+ * Since this is `Err`, the function is always applied.
22
+ */
23
+ mapErr(fn) {
24
+ return new _Err(fn(this.error));
25
+ }
26
+ /**
27
+ * Throws an error since this is `Err`, not `Ok`.
28
+ */
29
+ unwrap() {
30
+ throw new Error(`Called unwrap() on an Err value: ${this.error}`);
31
+ }
32
+ /**
33
+ * Returns the contained error.
34
+ */
35
+ unwrapErr() {
36
+ return this.error;
37
+ }
38
+ /**
39
+ * Returns the provided default value since this is `Err`.
40
+ */
41
+ unwrapOr(defaultValue) {
42
+ return defaultValue;
43
+ }
44
+ /**
45
+ * Computes and returns the fallback value using the provided function.
46
+ */
47
+ unwrapOrElse(fn) {
48
+ return fn(this.error);
49
+ }
50
+ /**
51
+ * Returns this `Err` unchanged since there's no value to chain.
52
+ */
53
+ andThen(_fn) {
54
+ return this;
55
+ }
56
+ /**
57
+ * Always returns false since this is `Err`, not `Ok`.
58
+ */
59
+ contains(_value) {
60
+ return false;
61
+ }
62
+ /**
63
+ * Checks if the contained error matches the provided error.
64
+ */
65
+ containsErr(error) {
66
+ return this.error === error;
67
+ }
68
+ };
69
+ function err(error) {
70
+ return new Err(error);
71
+ }
72
+
73
+ export { Err, err };
74
+ //# sourceMappingURL=chunk-GLSQCN75.js.map
75
+ //# sourceMappingURL=chunk-GLSQCN75.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/err.ts"],"names":[],"mappings":";;;AAMO,IAAM,GAAA,GAAN,MAAM,IAAA,SAAe,UAAA,CAAqB;AAAA;AAAA,EAM7C,YAAqB,KAAA,EAAU;AAC3B,IAAA,KAAA,EAAM;AADW,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAErB;AAAA,EAPS,IAAA,GAAO,KAAA;AAAA,EACP,IAAA,GAAO,KAAA;AAAA,EACP,KAAA,GAAQ,IAAA;AAAA;AAAA;AAAA;AAAA,EAUjB,IAAO,GAAA,EAAkC;AACrC,IAAA,OAAO,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAU,EAAA,EAA6B;AACnC,IAAA,OAAO,IAAI,IAAA,CAAI,EAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GAAgB;AACZ,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iCAAA,EAAoC,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAe;AACX,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAY,YAAA,EAAoB;AAC5B,IAAA,OAAO,YAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,aAAgB,EAAA,EAAwB;AACpC,IAAA,OAAO,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,GAAA,EAA6C;AACpD,IAAA,OAAO,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,MAAA,EAAwB;AAC7B,IAAA,OAAO,KAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,KAAA,EAAmB;AAC3B,IAAA,OAAO,KAAK,KAAA,KAAU,KAAA;AAAA,EAC1B;AACJ;AAKO,SAAS,IAAO,KAAA,EAAkB;AACrC,EAAA,OAAO,IAAI,IAAI,KAAK,CAAA;AACxB","file":"chunk-GLSQCN75.js","sourcesContent":["import type { Result } from '@/core/result';\nimport { ResultBase } from '@/core/result';\n\n/**\n * Represents an error result containing an error value.\n */\nexport class Err<E> extends ResultBase<never, E> {\n readonly _tag = 'err' as const;\n readonly isOk = false;\n readonly isErr = true;\n\n // eslint-disable-next-line node/handle-callback-err\n constructor(readonly error: E) {\n super();\n }\n\n /**\n * Maps the value type, but since this is `Err`, it's a no-op.\n */\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n /**\n * Maps the contained error using the provided function.\n * Since this is `Err`, the function is always applied.\n */\n mapErr<F>(fn: (error: E) => F): Err<F> {\n return new Err(fn(this.error));\n }\n\n /**\n * Throws an error since this is `Err`, not `Ok`.\n */\n unwrap(): never {\n throw new Error(`Called unwrap() on an Err value: ${this.error}`);\n }\n\n /**\n * Returns the contained error.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Returns the provided default value since this is `Err`.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n /**\n * Computes and returns the fallback value using the provided function.\n */\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n\n /**\n * Returns this `Err` unchanged since there's no value to chain.\n */\n andThen<U>(_fn: (value: never) => Result<U, E>): Err<E> {\n return this;\n }\n\n /**\n * Always returns false since this is `Err`, not `Ok`.\n */\n contains(_value: never): boolean {\n return false;\n }\n\n /**\n * Checks if the contained error matches the provided error.\n */\n containsErr(error: E): boolean {\n return this.error === error;\n }\n}\n\n/**\n * Creates a new `Err` result with the given error.\n */\nexport function err<E>(error: E): Err<E> {\n return new Err(error);\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { err } from './chunk-GLSQCN75.js';
2
+ import { ok } from './chunk-GGEJTXXS.js';
3
+
4
+ // src/zod-wrapper/zod.ts
5
+ function resultHandlerFromZod(schema) {
6
+ return (value) => {
7
+ const result = schema.safeParse(value);
8
+ if (result.success) {
9
+ return ok(result.data);
10
+ }
11
+ return err(result.error);
12
+ };
13
+ }
14
+
15
+ export { resultHandlerFromZod };
16
+ //# sourceMappingURL=chunk-ITR7ZRJM.js.map
17
+ //# sourceMappingURL=chunk-ITR7ZRJM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/zod-wrapper/zod.ts"],"names":[],"mappings":";;;;AAIO,SAAS,qBAAwB,MAAA,EAAsB;AAC1D,EAAA,OAAO,CAAC,KAAA,KAA6C;AACjD,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA;AACrC,IAAA,IAAI,OAAO,OAAA,EAAS;AAChB,MAAA,OAAO,EAAA,CAAG,OAAO,IAAI,CAAA;AAAA,IACzB;AACA,IAAA,OAAO,GAAA,CAAI,OAAO,KAAK,CAAA;AAAA,EAC3B,CAAA;AACJ","file":"chunk-ITR7ZRJM.js","sourcesContent":["import type z from 'zod';\nimport type { Result } from '@/core';\nimport { err, ok } from '@/core';\n\nexport function resultHandlerFromZod<T>(schema: z.ZodType<T>) {\n return (value: unknown): Result<T, z.ZodError<T>> => {\n const result = schema.safeParse(value);\n if (result.success) {\n return ok(result.data);\n }\n return err(result.error);\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=chunk-SQ4P2HRX.js.map
3
+ //# sourceMappingURL=chunk-SQ4P2HRX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-SQ4P2HRX.js"}
@@ -1 +1 @@
1
- export { E as Err, e as err } from '../index-Dy6VGmoZ.js';
1
+ export { Err, err } from './index.js';
package/dist/core/err.js CHANGED
@@ -1,75 +1,4 @@
1
- import { ResultBase } from 'core/result';
2
-
3
- // src/core/err.ts
4
- var Err = class _Err extends ResultBase {
5
- // eslint-disable-next-line node/handle-callback-err
6
- constructor(error) {
7
- super();
8
- this.error = error;
9
- }
10
- _tag = "err";
11
- isOk = false;
12
- isErr = true;
13
- /**
14
- * Maps the value type, but since this is `Err`, it's a no-op.
15
- */
16
- map(_fn) {
17
- return this;
18
- }
19
- /**
20
- * Maps the contained error using the provided function.
21
- * Since this is `Err`, the function is always applied.
22
- */
23
- mapErr(fn) {
24
- return new _Err(fn(this.error));
25
- }
26
- /**
27
- * Throws an error since this is `Err`, not `Ok`.
28
- */
29
- unwrap() {
30
- throw new Error(`Called unwrap() on an Err value: ${this.error}`);
31
- }
32
- /**
33
- * Returns the contained error.
34
- */
35
- unwrapErr() {
36
- return this.error;
37
- }
38
- /**
39
- * Returns the provided default value since this is `Err`.
40
- */
41
- unwrapOr(defaultValue) {
42
- return defaultValue;
43
- }
44
- /**
45
- * Computes and returns the fallback value using the provided function.
46
- */
47
- unwrapOrElse(fn) {
48
- return fn(this.error);
49
- }
50
- /**
51
- * Returns this `Err` unchanged since there's no value to chain.
52
- */
53
- andThen(_fn) {
54
- return this;
55
- }
56
- /**
57
- * Always returns false since this is `Err`, not `Ok`.
58
- */
59
- contains(_value) {
60
- return false;
61
- }
62
- /**
63
- * Checks if the contained error matches the provided error.
64
- */
65
- containsErr(error) {
66
- return this.error === error;
67
- }
68
- };
69
- function err(error) {
70
- return new Err(error);
71
- }
72
-
73
- export { Err, err };
1
+ export { Err, err } from '../chunk-GLSQCN75.js';
2
+ import '../chunk-D2DM2EYA.js';
74
3
  //# sourceMappingURL=err.js.map
75
4
  //# sourceMappingURL=err.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/err.ts"],"names":[],"mappings":";;;AAMO,IAAM,GAAA,GAAN,MAAM,IAAA,SAAe,UAAA,CAAqB;AAAA;AAAA,EAM/C,YAAqB,KAAA,EAAU;AAC7B,IAAA,KAAA,EAAM;AADa,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAErB;AAAA,EAPS,IAAA,GAAO,KAAA;AAAA,EACP,IAAA,GAAO,KAAA;AAAA,EACP,KAAA,GAAQ,IAAA;AAAA;AAAA;AAAA;AAAA,EAUjB,IAAO,GAAA,EAAkC;AACvC,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAU,EAAA,EAA6B;AACrC,IAAA,OAAO,IAAI,IAAA,CAAI,EAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GAAgB;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iCAAA,EAAoC,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAe;AACb,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,SAAY,YAAA,EAAoB;AAC9B,IAAA,OAAO,YAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,aAAgB,EAAA,EAAwB;AACtC,IAAA,OAAO,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,GAAA,EAA6C;AACtD,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,MAAA,EAAwB;AAC/B,IAAA,OAAO,KAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,KAAA,EAAmB;AAC7B,IAAA,OAAO,KAAK,KAAA,KAAU,KAAA;AAAA,EACxB;AACF;AAKO,SAAS,IAAO,KAAA,EAAkB;AACvC,EAAA,OAAO,IAAI,IAAI,KAAK,CAAA;AACtB","file":"err.js","sourcesContent":["import type { Result } from 'core/result';\nimport { ResultBase } from 'core/result';\n\n/**\n * Represents an error result containing an error value.\n */\nexport class Err<E> extends ResultBase<never, E> {\n readonly _tag = 'err' as const;\n readonly isOk = false;\n readonly isErr = true;\n\n // eslint-disable-next-line node/handle-callback-err\n constructor(readonly error: E) {\n super();\n }\n\n /**\n * Maps the value type, but since this is `Err`, it's a no-op.\n */\n map<U>(_fn: (value: never) => U): Err<E> {\n return this;\n }\n\n /**\n * Maps the contained error using the provided function.\n * Since this is `Err`, the function is always applied.\n */\n mapErr<F>(fn: (error: E) => F): Err<F> {\n return new Err(fn(this.error));\n }\n\n /**\n * Throws an error since this is `Err`, not `Ok`.\n */\n unwrap(): never {\n throw new Error(`Called unwrap() on an Err value: ${this.error}`);\n }\n\n /**\n * Returns the contained error.\n */\n unwrapErr(): E {\n return this.error;\n }\n\n /**\n * Returns the provided default value since this is `Err`.\n */\n unwrapOr<T>(defaultValue: T): T {\n return defaultValue;\n }\n\n /**\n * Computes and returns the fallback value using the provided function.\n */\n unwrapOrElse<T>(fn: (error: E) => T): T {\n return fn(this.error);\n }\n\n /**\n * Returns this `Err` unchanged since there's no value to chain.\n */\n andThen<U>(_fn: (value: never) => Result<U, E>): Err<E> {\n return this;\n }\n\n /**\n * Always returns false since this is `Err`, not `Ok`.\n */\n contains(_value: never): boolean {\n return false;\n }\n\n /**\n * Checks if the contained error matches the provided error.\n */\n containsErr(error: E): boolean {\n return this.error === error;\n }\n}\n\n/**\n * Creates a new `Err` result with the given error.\n */\nexport function err<E>(error: E): Err<E> {\n return new Err(error);\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"err.js"}
@@ -1 +1,169 @@
1
- export { A as AsyncResult, E as Err, O as Ok, a as Result, e as err, o as ok } from '../index-Dy6VGmoZ.js';
1
+ /**
2
+ * Represents an error result containing an error value.
3
+ */
4
+ declare class Err<E> extends ResultBase<never, E> {
5
+ readonly error: E;
6
+ readonly _tag: "err";
7
+ readonly isOk = false;
8
+ readonly isErr = true;
9
+ constructor(error: E);
10
+ /**
11
+ * Maps the value type, but since this is `Err`, it's a no-op.
12
+ */
13
+ map<U>(_fn: (value: never) => U): Err<E>;
14
+ /**
15
+ * Maps the contained error using the provided function.
16
+ * Since this is `Err`, the function is always applied.
17
+ */
18
+ mapErr<F>(fn: (error: E) => F): Err<F>;
19
+ /**
20
+ * Throws an error since this is `Err`, not `Ok`.
21
+ */
22
+ unwrap(): never;
23
+ /**
24
+ * Returns the contained error.
25
+ */
26
+ unwrapErr(): E;
27
+ /**
28
+ * Returns the provided default value since this is `Err`.
29
+ */
30
+ unwrapOr<T>(defaultValue: T): T;
31
+ /**
32
+ * Computes and returns the fallback value using the provided function.
33
+ */
34
+ unwrapOrElse<T>(fn: (error: E) => T): T;
35
+ /**
36
+ * Returns this `Err` unchanged since there's no value to chain.
37
+ */
38
+ andThen<U>(_fn: (value: never) => Result<U, E>): Err<E>;
39
+ /**
40
+ * Always returns false since this is `Err`, not `Ok`.
41
+ */
42
+ contains(_value: never): boolean;
43
+ /**
44
+ * Checks if the contained error matches the provided error.
45
+ */
46
+ containsErr(error: E): boolean;
47
+ }
48
+ /**
49
+ * Creates a new `Err` result with the given error.
50
+ */
51
+ declare function err<E>(error: E): Err<E>;
52
+
53
+ /**
54
+ * Represents a successful result containing a value.
55
+ */
56
+ declare class Ok<T> extends ResultBase<T, never> {
57
+ readonly value: T;
58
+ readonly _tag: "ok";
59
+ readonly isOk = true;
60
+ readonly isErr = false;
61
+ constructor(value: T);
62
+ /**
63
+ * Maps the contained value using the provided function.
64
+ * Since this is `Ok`, the function is always applied.
65
+ */
66
+ map<U>(fn: (value: T) => U): Ok<U>;
67
+ /**
68
+ * Maps the error type, but since this is `Ok`, it's a no-op.
69
+ */
70
+ mapErr<F>(_fn: (error: never) => F): Ok<T>;
71
+ /**
72
+ * Returns the contained value.
73
+ */
74
+ unwrap(): T;
75
+ /**
76
+ * Throws an error since this is Ok, not Err.
77
+ */
78
+ unwrapErr(): never;
79
+ /**
80
+ * Returns the contained value, ignoring the default.
81
+ */
82
+ unwrapOr(_defaultValue: T): T;
83
+ /**
84
+ * Returns the contained value, ignoring the fallback function.
85
+ */
86
+ unwrapOrElse(_fn: (error: never) => T): T;
87
+ /**
88
+ * Applies the function to the contained value and returns the result.
89
+ */
90
+ andThen<U>(fn: (value: T) => Result<U, never>): Result<U, never>;
91
+ /**
92
+ * Checks if the contained value matches the provided value.
93
+ */
94
+ contains(value: T): boolean;
95
+ /**
96
+ * Always returns false since this is `Ok`, not `Err`.
97
+ */
98
+ containsErr(_error: never): false;
99
+ }
100
+ /**
101
+ * Creates a new `Ok` result with the given value.
102
+ */
103
+ declare function ok<T>(value: T): Ok<T>;
104
+
105
+ /**
106
+ * Represents a Result type that can either be a success (`Ok`) or an error (`Err`).
107
+ * This is an abstract base class that provides common functionality for both variants.
108
+ */
109
+ declare abstract class ResultBase<T, E> {
110
+ /**
111
+ * Type guard to check if the result is an `Ok` variant.
112
+ */
113
+ abstract readonly isOk: boolean;
114
+ /**
115
+ * Type guard to check if the result is an `Err` variant.
116
+ */
117
+ abstract readonly isErr: boolean;
118
+ /**
119
+ * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,
120
+ * leaving an `Err` value untouched.
121
+ */
122
+ abstract map<U>(fn: (value: T) => U): Result<U, E>;
123
+ /**
124
+ * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,
125
+ * leaving an `Ok` value untouched.
126
+ */
127
+ abstract mapErr<F>(fn: (error: E) => F): Result<T, F>;
128
+ /**
129
+ * Returns the contained `Ok` value, consuming the self value.
130
+ * Throws an error if the result is `Err`.
131
+ */
132
+ abstract unwrap(): T;
133
+ /**
134
+ * Returns the contained `Err` value, consuming the self value.
135
+ * Throws an error if the result is Ok.
136
+ */
137
+ abstract unwrapErr(): E;
138
+ /**
139
+ * Returns the contained `Ok` value or a provided default.
140
+ */
141
+ abstract unwrapOr(defaultValue: T): T;
142
+ /**
143
+ * Returns the contained `Ok` value or computes it from a closure.
144
+ */
145
+ abstract unwrapOrElse(fn: (error: E) => T): T;
146
+ /**
147
+ * Calls the provided function with the contained value and returns the result.
148
+ * If the result is `Err`, the function is not called and the `Err` is returned.
149
+ */
150
+ abstract andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;
151
+ /**
152
+ * Returns true if the result is `Ok` and the value inside of it matches a predicate.
153
+ */
154
+ abstract contains(value: T): boolean;
155
+ /**
156
+ * Returns true if the result is `Err` and the error inside of it matches a predicate.
157
+ */
158
+ abstract containsErr(error: E): boolean;
159
+ }
160
+ /**
161
+ * Type alias for a `Result` that can be either `Ok<T>` or `Err<E>`.
162
+ */
163
+ type Result<T, E> = Ok<T> | Err<E>;
164
+ /**
165
+ * Type alias for an async `Result` (Promise-wrapped `Result`).
166
+ */
167
+ type AsyncResult<T, E> = Promise<Result<T, E>>;
168
+
169
+ export { type AsyncResult, Err, Ok, type Result, ResultBase, err, ok };
@@ -1,4 +1,6 @@
1
- export { Err, err } from 'core/err';
2
- export { Ok, ok } from 'core/ok';
1
+ import '../chunk-SQ4P2HRX.js';
2
+ export { Err, err } from '../chunk-GLSQCN75.js';
3
+ export { Ok, ok } from '../chunk-GGEJTXXS.js';
4
+ import '../chunk-D2DM2EYA.js';
3
5
  //# sourceMappingURL=index.js.map
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/core/ok.d.ts CHANGED
@@ -1 +1 @@
1
- export { O as Ok, o as ok } from '../index-Dy6VGmoZ.js';
1
+ export { Ok, ok } from './index.js';
package/dist/core/ok.js CHANGED
@@ -1,74 +1,4 @@
1
- import { ResultBase } from 'core/result';
2
-
3
- // src/core/ok.ts
4
- var Ok = class _Ok extends ResultBase {
5
- constructor(value) {
6
- super();
7
- this.value = value;
8
- }
9
- _tag = "ok";
10
- isOk = true;
11
- isErr = false;
12
- /**
13
- * Maps the contained value using the provided function.
14
- * Since this is `Ok`, the function is always applied.
15
- */
16
- map(fn) {
17
- return new _Ok(fn(this.value));
18
- }
19
- /**
20
- * Maps the error type, but since this is `Ok`, it's a no-op.
21
- */
22
- mapErr(_fn) {
23
- return this;
24
- }
25
- /**
26
- * Returns the contained value.
27
- */
28
- unwrap() {
29
- return this.value;
30
- }
31
- /**
32
- * Throws an error since this is Ok, not Err.
33
- */
34
- unwrapErr() {
35
- throw new Error(`Called unwrapErr() on an Ok value: ${this.value}`);
36
- }
37
- /**
38
- * Returns the contained value, ignoring the default.
39
- */
40
- unwrapOr(_defaultValue) {
41
- return this.value;
42
- }
43
- /**
44
- * Returns the contained value, ignoring the fallback function.
45
- */
46
- unwrapOrElse(_fn) {
47
- return this.value;
48
- }
49
- /**
50
- * Applies the function to the contained value and returns the result.
51
- */
52
- andThen(fn) {
53
- return fn(this.value);
54
- }
55
- /**
56
- * Checks if the contained value matches the provided value.
57
- */
58
- contains(value) {
59
- return this.value === value;
60
- }
61
- /**
62
- * Always returns false since this is `Ok`, not `Err`.
63
- */
64
- containsErr(_error) {
65
- return false;
66
- }
67
- };
68
- function ok(value) {
69
- return new Ok(value);
70
- }
71
-
72
- export { Ok, ok };
1
+ export { Ok, ok } from '../chunk-GGEJTXXS.js';
2
+ import '../chunk-D2DM2EYA.js';
73
3
  //# sourceMappingURL=ok.js.map
74
4
  //# sourceMappingURL=ok.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/ok.ts"],"names":[],"mappings":";;;AAMO,IAAM,EAAA,GAAN,MAAM,GAAA,SAAc,UAAA,CAAqB;AAAA,EAK9C,YAAqB,KAAA,EAAU;AAC7B,IAAA,KAAA,EAAM;AADa,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAAA,EAErB;AAAA,EANS,IAAA,GAAO,IAAA;AAAA,EACP,IAAA,GAAO,IAAA;AAAA,EACP,KAAA,GAAQ,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUjB,IAAO,EAAA,EAA4B;AACjC,IAAA,OAAO,IAAI,GAAA,CAAG,EAAA,CAAG,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAU,GAAA,EAAiC;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,GAAY;AACV,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAAmB;AACjB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mCAAA,EAAsC,IAAA,CAAK,KAAK,CAAA,CAAE,CAAA;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,aAAA,EAAqB;AAC5B,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,GAAA,EAA6B;AACxC,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAW,EAAA,EAAsD;AAC/D,IAAA,OAAO,EAAA,CAAG,KAAK,KAAK,CAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAS,KAAA,EAAmB;AAC1B,IAAA,OAAO,KAAK,KAAA,KAAU,KAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAKS,YAAY,MAAA,EAAsB;AACzC,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAKO,SAAS,GAAM,KAAA,EAAiB;AACrC,EAAA,OAAO,IAAI,GAAG,KAAK,CAAA;AACrB","file":"ok.js","sourcesContent":["import type { Result } from 'core/result';\nimport { ResultBase } from 'core/result';\n\n/**\n * Represents a successful result containing a value.\n */\nexport class Ok<T> extends ResultBase<T, never> {\n readonly _tag = 'ok' as const;\n readonly isOk = true;\n readonly isErr = false;\n\n constructor(readonly value: T) {\n super();\n }\n\n /**\n * Maps the contained value using the provided function.\n * Since this is `Ok`, the function is always applied.\n */\n map<U>(fn: (value: T) => U): Ok<U> {\n return new Ok(fn(this.value));\n }\n\n /**\n * Maps the error type, but since this is `Ok`, it's a no-op.\n */\n mapErr<F>(_fn: (error: never) => F): Ok<T> {\n return this;\n }\n\n /**\n * Returns the contained value.\n */\n unwrap(): T {\n return this.value;\n }\n\n /**\n * Throws an error since this is Ok, not Err.\n */\n unwrapErr(): never {\n throw new Error(`Called unwrapErr() on an Ok value: ${this.value}`);\n }\n\n /**\n * Returns the contained value, ignoring the default.\n */\n unwrapOr(_defaultValue: T): T {\n return this.value;\n }\n\n /**\n * Returns the contained value, ignoring the fallback function.\n */\n unwrapOrElse(_fn: (error: never) => T): T {\n return this.value;\n }\n\n /**\n * Applies the function to the contained value and returns the result.\n */\n andThen<U>(fn: (value: T) => Result<U, never>): Result<U, never> {\n return fn(this.value);\n }\n\n /**\n * Checks if the contained value matches the provided value.\n */\n contains(value: T): boolean {\n return this.value === value;\n }\n\n /**\n * Always returns false since this is `Ok`, not `Err`.\n */\n override containsErr(_error: never): false {\n return false;\n }\n}\n\n/**\n * Creates a new `Ok` result with the given value.\n */\nexport function ok<T>(value: T): Ok<T> {\n return new Ok(value);\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ok.js"}
@@ -1 +1 @@
1
- export { A as AsyncResult, a as Result, R as ResultBase } from '../index-Dy6VGmoZ.js';
1
+ export { AsyncResult, Result, ResultBase } from './index.js';
@@ -1,7 +1,3 @@
1
- // src/core/result.ts
2
- var ResultBase = class {
3
- };
4
-
5
- export { ResultBase };
1
+ export { ResultBase } from '../chunk-D2DM2EYA.js';
6
2
  //# sourceMappingURL=result.js.map
7
3
  //# sourceMappingURL=result.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/result.ts"],"names":[],"mappings":";AAOO,IAAe,aAAf,MAAgC;AA4DvC","file":"result.js","sourcesContent":["import type { Err } from 'core/err';\nimport type { Ok } from 'core/ok';\n\n/**\n * Represents a Result type that can either be a success (`Ok`) or an error (`Err`).\n * This is an abstract base class that provides common functionality for both variants.\n */\nexport abstract class ResultBase<T, E> {\n /**\n * Type guard to check if the result is an `Ok` variant.\n */\n abstract readonly isOk: boolean;\n\n /**\n * Type guard to check if the result is an `Err` variant.\n */\n abstract readonly isErr: boolean;\n\n /**\n * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,\n * leaving an `Err` value untouched.\n */\n abstract map<U>(fn: (value: T) => U): Result<U, E>;\n\n /**\n * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,\n * leaving an `Ok` value untouched.\n */\n abstract mapErr<F>(fn: (error: E) => F): Result<T, F>;\n\n /**\n * Returns the contained `Ok` value, consuming the self value.\n * Throws an error if the result is `Err`.\n */\n abstract unwrap(): T;\n\n /**\n * Returns the contained `Err` value, consuming the self value.\n * Throws an error if the result is Ok.\n */\n abstract unwrapErr(): E;\n\n /**\n * Returns the contained `Ok` value or a provided default.\n */\n abstract unwrapOr(defaultValue: T): T;\n\n /**\n * Returns the contained `Ok` value or computes it from a closure.\n */\n abstract unwrapOrElse(fn: (error: E) => T): T;\n\n /**\n * Calls the provided function with the contained value and returns the result.\n * If the result is `Err`, the function is not called and the `Err` is returned.\n */\n abstract andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;\n\n /**\n * Returns true if the result is `Ok` and the value inside of it matches a predicate.\n */\n abstract contains(value: T): boolean;\n\n /**\n * Returns true if the result is `Err` and the error inside of it matches a predicate.\n */\n abstract containsErr(error: E): boolean;\n}\n\n/**\n * Type alias for a `Result` that can be either `Ok<T>` or `Err<E>`.\n */\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Type alias for an async `Result` (Promise-wrapped `Result`).\n */\nexport type AsyncResult<T, E> = Promise<Result<T, E>>;\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"result.js"}
@@ -0,0 +1,3 @@
1
+ export { resultHandlerFromZod } from './zod.js';
2
+ import 'zod';
3
+ import '../core/index.js';
@@ -0,0 +1,7 @@
1
+ export { resultHandlerFromZod } from '../chunk-ITR7ZRJM.js';
2
+ import '../chunk-SQ4P2HRX.js';
3
+ import '../chunk-GLSQCN75.js';
4
+ import '../chunk-GGEJTXXS.js';
5
+ import '../chunk-D2DM2EYA.js';
6
+ //# sourceMappingURL=index.js.map
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,6 @@
1
+ import z from 'zod';
2
+ import { Result } from '../core/index.js';
3
+
4
+ declare function resultHandlerFromZod<T>(schema: z.ZodType<T>): (value: unknown) => Result<T, z.ZodError<T>>;
5
+
6
+ export { resultHandlerFromZod };
@@ -0,0 +1,7 @@
1
+ export { resultHandlerFromZod } from '../chunk-ITR7ZRJM.js';
2
+ import '../chunk-SQ4P2HRX.js';
3
+ import '../chunk-GLSQCN75.js';
4
+ import '../chunk-GGEJTXXS.js';
5
+ import '../chunk-D2DM2EYA.js';
6
+ //# sourceMappingURL=zod.js.map
7
+ //# sourceMappingURL=zod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"zod.js"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "resultfier",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "description": "A TypeScript implementation of Rust-like Result type for better error handling",
6
6
  "author": "Vitor Koch <vitorgabrielkoch@gmail.com>",
7
7
  "license": "MIT",
@@ -18,14 +18,26 @@
18
18
  "types": "./dist/core/index.d.ts",
19
19
  "import": "./dist/core/index.js"
20
20
  },
21
- "./extra": {
22
- "types": "./dist/extra/index.d.ts",
23
- "import": "./dist/extra/index.js"
21
+ "./action": {
22
+ "types": "./dist/action/index.d.ts",
23
+ "import": "./dist/action/index.js"
24
+ },
25
+ "./zod": {
26
+ "types": "./dist/zod-wrapper/zod.d.ts",
27
+ "import": "./dist/zod-wrapper/zod.js"
24
28
  }
25
29
  },
26
30
  "main": "./dist/core/index.js",
27
31
  "module": "./dist/core/index.js",
28
32
  "types": "./dist/core/index.d.ts",
33
+ "peerDependencies": {
34
+ "zod": "^4.0.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "zod": {
38
+ "optional": true
39
+ }
40
+ },
29
41
  "devDependencies": {
30
42
  "@antfu/eslint-config": "^5.4.1",
31
43
  "@changesets/cli": "^2.29.7",
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=action.js.map
3
- //# sourceMappingURL=action.js.map
@@ -1,3 +0,0 @@
1
- export * from 'extra/action';
2
- //# sourceMappingURL=index.js.map
3
- //# sourceMappingURL=index.js.map
@@ -1,169 +0,0 @@
1
- /**
2
- * Represents a successful result containing a value.
3
- */
4
- declare class Ok<T> extends ResultBase<T, never> {
5
- readonly value: T;
6
- readonly _tag: "ok";
7
- readonly isOk = true;
8
- readonly isErr = false;
9
- constructor(value: T);
10
- /**
11
- * Maps the contained value using the provided function.
12
- * Since this is `Ok`, the function is always applied.
13
- */
14
- map<U>(fn: (value: T) => U): Ok<U>;
15
- /**
16
- * Maps the error type, but since this is `Ok`, it's a no-op.
17
- */
18
- mapErr<F>(_fn: (error: never) => F): Ok<T>;
19
- /**
20
- * Returns the contained value.
21
- */
22
- unwrap(): T;
23
- /**
24
- * Throws an error since this is Ok, not Err.
25
- */
26
- unwrapErr(): never;
27
- /**
28
- * Returns the contained value, ignoring the default.
29
- */
30
- unwrapOr(_defaultValue: T): T;
31
- /**
32
- * Returns the contained value, ignoring the fallback function.
33
- */
34
- unwrapOrElse(_fn: (error: never) => T): T;
35
- /**
36
- * Applies the function to the contained value and returns the result.
37
- */
38
- andThen<U>(fn: (value: T) => Result<U, never>): Result<U, never>;
39
- /**
40
- * Checks if the contained value matches the provided value.
41
- */
42
- contains(value: T): boolean;
43
- /**
44
- * Always returns false since this is `Ok`, not `Err`.
45
- */
46
- containsErr(_error: never): false;
47
- }
48
- /**
49
- * Creates a new `Ok` result with the given value.
50
- */
51
- declare function ok<T>(value: T): Ok<T>;
52
-
53
- /**
54
- * Represents a Result type that can either be a success (`Ok`) or an error (`Err`).
55
- * This is an abstract base class that provides common functionality for both variants.
56
- */
57
- declare abstract class ResultBase<T, E> {
58
- /**
59
- * Type guard to check if the result is an `Ok` variant.
60
- */
61
- abstract readonly isOk: boolean;
62
- /**
63
- * Type guard to check if the result is an `Err` variant.
64
- */
65
- abstract readonly isErr: boolean;
66
- /**
67
- * Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,
68
- * leaving an `Err` value untouched.
69
- */
70
- abstract map<U>(fn: (value: T) => U): Result<U, E>;
71
- /**
72
- * Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,
73
- * leaving an `Ok` value untouched.
74
- */
75
- abstract mapErr<F>(fn: (error: E) => F): Result<T, F>;
76
- /**
77
- * Returns the contained `Ok` value, consuming the self value.
78
- * Throws an error if the result is `Err`.
79
- */
80
- abstract unwrap(): T;
81
- /**
82
- * Returns the contained `Err` value, consuming the self value.
83
- * Throws an error if the result is Ok.
84
- */
85
- abstract unwrapErr(): E;
86
- /**
87
- * Returns the contained `Ok` value or a provided default.
88
- */
89
- abstract unwrapOr(defaultValue: T): T;
90
- /**
91
- * Returns the contained `Ok` value or computes it from a closure.
92
- */
93
- abstract unwrapOrElse(fn: (error: E) => T): T;
94
- /**
95
- * Calls the provided function with the contained value and returns the result.
96
- * If the result is `Err`, the function is not called and the `Err` is returned.
97
- */
98
- abstract andThen<U>(fn: (value: T) => Result<U, E>): Result<U, E>;
99
- /**
100
- * Returns true if the result is `Ok` and the value inside of it matches a predicate.
101
- */
102
- abstract contains(value: T): boolean;
103
- /**
104
- * Returns true if the result is `Err` and the error inside of it matches a predicate.
105
- */
106
- abstract containsErr(error: E): boolean;
107
- }
108
- /**
109
- * Type alias for a `Result` that can be either `Ok<T>` or `Err<E>`.
110
- */
111
- type Result<T, E> = Ok<T> | Err<E>;
112
- /**
113
- * Type alias for an async `Result` (Promise-wrapped `Result`).
114
- */
115
- type AsyncResult<T, E> = Promise<Result<T, E>>;
116
-
117
- /**
118
- * Represents an error result containing an error value.
119
- */
120
- declare class Err<E> extends ResultBase<never, E> {
121
- readonly error: E;
122
- readonly _tag: "err";
123
- readonly isOk = false;
124
- readonly isErr = true;
125
- constructor(error: E);
126
- /**
127
- * Maps the value type, but since this is `Err`, it's a no-op.
128
- */
129
- map<U>(_fn: (value: never) => U): Err<E>;
130
- /**
131
- * Maps the contained error using the provided function.
132
- * Since this is `Err`, the function is always applied.
133
- */
134
- mapErr<F>(fn: (error: E) => F): Err<F>;
135
- /**
136
- * Throws an error since this is `Err`, not `Ok`.
137
- */
138
- unwrap(): never;
139
- /**
140
- * Returns the contained error.
141
- */
142
- unwrapErr(): E;
143
- /**
144
- * Returns the provided default value since this is `Err`.
145
- */
146
- unwrapOr<T>(defaultValue: T): T;
147
- /**
148
- * Computes and returns the fallback value using the provided function.
149
- */
150
- unwrapOrElse<T>(fn: (error: E) => T): T;
151
- /**
152
- * Returns this `Err` unchanged since there's no value to chain.
153
- */
154
- andThen<U>(_fn: (value: never) => Result<U, E>): Err<E>;
155
- /**
156
- * Always returns false since this is `Err`, not `Ok`.
157
- */
158
- contains(_value: never): boolean;
159
- /**
160
- * Checks if the contained error matches the provided error.
161
- */
162
- containsErr(error: E): boolean;
163
- }
164
- /**
165
- * Creates a new `Err` result with the given error.
166
- */
167
- declare function err<E>(error: E): Err<E>;
168
-
169
- export { type AsyncResult as A, Err as E, Ok as O, ResultBase as R, type Result as a, err as e, ok as o };
package/eslint.config.mjs DELETED
@@ -1,10 +0,0 @@
1
- import antfu from '@antfu/eslint-config';
2
-
3
- export default antfu({
4
- type: 'lib',
5
- stylistic: {
6
- semi: true,
7
- quotes: 'single',
8
- },
9
- typescript: true,
10
- });
package/mise.toml DELETED
@@ -1,2 +0,0 @@
1
- [tools]
2
- node = "24"
@@ -1,2 +0,0 @@
1
- onlyBuiltDependencies:
2
- - esbuild
File without changes