@l3dev/result 0.3.1 → 0.5.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.
- package/build/from.d.ts +15 -0
- package/build/from.js +31 -0
- package/build/from.js.map +1 -0
- package/build/fromPromise.d.ts +15 -0
- package/build/fromPromise.js +31 -0
- package/build/fromPromise.js.map +1 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/zod/v3.d.ts +46 -0
- package/build/zod/v3.js +12 -0
- package/build/zod/v3.js.map +1 -0
- package/build/zod/v4.d.ts +18 -0
- package/build/zod/v4.js +12 -0
- package/build/zod/v4.js.map +1 -0
- package/package.json +12 -4
package/build/from.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResultErrorDefinition, ReturnResult } from "./result.types.js";
|
|
2
|
+
export declare function from<TReturn, TError = Error>(wrapper: () => TReturn): ReturnResult<TReturn, ResultErrorDefinition<null, {
|
|
3
|
+
error: TError;
|
|
4
|
+
}>>;
|
|
5
|
+
export declare function from<TReturn, const TType, TContext extends object, TError = Error>(config: {
|
|
6
|
+
onError: {
|
|
7
|
+
type: TType;
|
|
8
|
+
context?: TContext;
|
|
9
|
+
};
|
|
10
|
+
}, wrapper: () => TReturn): ReturnResult<TReturn, ResultErrorDefinition<TType, TContext & {
|
|
11
|
+
error: TError;
|
|
12
|
+
}>>;
|
|
13
|
+
export declare function from<TReturn, const TType extends string, TError = Error>(errorType: TType, wrapper: () => TReturn): ReturnResult<TReturn, ResultErrorDefinition<TType, {
|
|
14
|
+
error: TError;
|
|
15
|
+
}>>;
|
package/build/from.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { err } from "./err.js";
|
|
2
|
+
import { ok } from "./ok.js";
|
|
3
|
+
export function from(configOrWrapper, wrapper) {
|
|
4
|
+
let config = null;
|
|
5
|
+
if (!wrapper && typeof configOrWrapper === "function") {
|
|
6
|
+
wrapper = configOrWrapper;
|
|
7
|
+
}
|
|
8
|
+
else if (typeof configOrWrapper !== "function") {
|
|
9
|
+
config = configOrWrapper;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const value = wrapper();
|
|
13
|
+
return ok(value);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
let type, context;
|
|
17
|
+
if (typeof config === "string") {
|
|
18
|
+
type = config;
|
|
19
|
+
context = {};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
type = (config?.onError.type ?? null);
|
|
23
|
+
context = config?.onError.context ?? {};
|
|
24
|
+
}
|
|
25
|
+
return err(type, {
|
|
26
|
+
...context,
|
|
27
|
+
error: error
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=from.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from.js","sourceRoot":"","sources":["../src/from.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAc7B,MAAM,UAAU,IAAI,CACnB,eAA4F,EAC5F,OAAuB;IAEvB,IAAI,MAAM,GAAqE,IAAI,CAAC;IACpF,IAAI,CAAC,OAAO,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;QACvD,OAAO,GAAG,eAAe,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE,CAAC;QAClD,MAAM,GAAG,eAAe,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,OAAQ,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,IAAI,EAAE,OAAO,CAAC;QAClB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,GAAG,MAAe,CAAC;YACvB,OAAO,GAAG,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,CAAU,CAAC;YAC/C,OAAO,GAAG,MAAM,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACzC,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAE;YAChB,GAAG,OAAO;YACV,KAAK,EAAE,KAAe;SACU,CAAC,CAAC;IACpC,CAAC;AACF,CAAC","sourcesContent":["import { err } from \"./err.js\";\nimport { ok } from \"./ok.js\";\nimport type { ResultErrorDefinition, ReturnResult } from \"./result.types.js\";\n\nexport function from<TReturn, TError = Error>(\n\twrapper: () => TReturn\n): ReturnResult<TReturn, ResultErrorDefinition<null, { error: TError }>>;\nexport function from<TReturn, const TType, TContext extends object, TError = Error>(\n\tconfig: { onError: { type: TType; context?: TContext } },\n\twrapper: () => TReturn\n): ReturnResult<TReturn, ResultErrorDefinition<TType, TContext & { error: TError }>>;\nexport function from<TReturn, const TType extends string, TError = Error>(\n\terrorType: TType,\n\twrapper: () => TReturn\n): ReturnResult<TReturn, ResultErrorDefinition<TType, { error: TError }>>;\nexport function from<TReturn, const TType, TContext extends object, TError = Error>(\n\tconfigOrWrapper: string | { onError: { type: TType; context?: TContext } } | (() => TReturn),\n\twrapper?: () => TReturn\n): ReturnResult<TReturn, ResultErrorDefinition<TType, TContext & { error: TError }>> {\n\tlet config: string | { onError: { type: TType; context?: TContext } } | null = null;\n\tif (!wrapper && typeof configOrWrapper === \"function\") {\n\t\twrapper = configOrWrapper;\n\t} else if (typeof configOrWrapper !== \"function\") {\n\t\tconfig = configOrWrapper;\n\t}\n\n\ttry {\n\t\tconst value = wrapper!();\n\t\treturn ok(value);\n\t} catch (error) {\n\t\tlet type, context;\n\t\tif (typeof config === \"string\") {\n\t\t\ttype = config as TType;\n\t\t\tcontext = {};\n\t\t} else {\n\t\t\ttype = (config?.onError.type ?? null) as TType;\n\t\t\tcontext = config?.onError.context ?? {};\n\t\t}\n\n\t\treturn err(type, {\n\t\t\t...context,\n\t\t\terror: error as TError\n\t\t} as TContext & { error: TError });\n\t}\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResultErrorDefinition, ReturnResult } from "./result.types.js";
|
|
2
|
+
export declare function fromPromise<TPromise extends Promise<any>, TError = Error>(promise: TPromise): Promise<ReturnResult<Awaited<TPromise>, ResultErrorDefinition<null, {
|
|
3
|
+
error: TError;
|
|
4
|
+
}>>>;
|
|
5
|
+
export declare function fromPromise<TPromise extends Promise<any>, const TType, TContext extends object, TError = Error>(config: {
|
|
6
|
+
onError: {
|
|
7
|
+
type: TType;
|
|
8
|
+
context?: TContext;
|
|
9
|
+
};
|
|
10
|
+
}, promise: TPromise): Promise<ReturnResult<Awaited<TPromise>, ResultErrorDefinition<TType, TContext & {
|
|
11
|
+
error: TError;
|
|
12
|
+
}>>>;
|
|
13
|
+
export declare function fromPromise<TPromise extends Promise<any>, const TType extends string, TError = Error>(config: TType, promise: TPromise): Promise<ReturnResult<Awaited<TPromise>, ResultErrorDefinition<TType, {
|
|
14
|
+
error: TError;
|
|
15
|
+
}>>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { err } from "./err.js";
|
|
2
|
+
import { ok } from "./ok.js";
|
|
3
|
+
export async function fromPromise(configOrPromise, promise) {
|
|
4
|
+
let config = null;
|
|
5
|
+
if (!promise && configOrPromise instanceof Promise) {
|
|
6
|
+
promise = configOrPromise;
|
|
7
|
+
}
|
|
8
|
+
else if (!(configOrPromise instanceof Promise)) {
|
|
9
|
+
config = configOrPromise;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const value = await promise;
|
|
13
|
+
return ok(value);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
let type, context;
|
|
17
|
+
if (typeof config === "string") {
|
|
18
|
+
type = config;
|
|
19
|
+
context = {};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
type = (config?.onError.type ?? null);
|
|
23
|
+
context = config?.onError.context ?? {};
|
|
24
|
+
}
|
|
25
|
+
return err(type, {
|
|
26
|
+
...context,
|
|
27
|
+
error: error
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=fromPromise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromPromise.js","sourceRoot":"","sources":["../src/fromPromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAyB7B,MAAM,CAAC,KAAK,UAAU,WAAW,CAMhC,eAAqF,EACrF,OAAkB;IAIlB,IAAI,MAAM,GAAqE,IAAI,CAAC;IACpF,IAAI,CAAC,OAAO,IAAI,eAAe,YAAY,OAAO,EAAE,CAAC;QACpD,OAAO,GAAG,eAAe,CAAC;IAC3B,CAAC;SAAM,IAAI,CAAC,CAAC,eAAe,YAAY,OAAO,CAAC,EAAE,CAAC;QAClD,MAAM,GAAG,eAAe,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,MAAM,OAAQ,CAAC;QAC7B,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,IAAI,EAAE,OAAO,CAAC;QAClB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,GAAG,MAAe,CAAC;YACvB,OAAO,GAAG,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI,CAAU,CAAC;YAC/C,OAAO,GAAG,MAAM,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACzC,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAE;YAChB,GAAG,OAAO;YACV,KAAK,EAAE,KAAe;SACU,CAAC,CAAC;IACpC,CAAC;AACF,CAAC","sourcesContent":["import { err } from \"./err.js\";\nimport { ok } from \"./ok.js\";\nimport type { ResultErrorDefinition, ReturnResult } from \"./result.types.js\";\n\nexport async function fromPromise<TPromise extends Promise<any>, TError = Error>(\n\tpromise: TPromise\n): Promise<ReturnResult<Awaited<TPromise>, ResultErrorDefinition<null, { error: TError }>>>;\nexport async function fromPromise<\n\tTPromise extends Promise<any>,\n\tconst TType,\n\tTContext extends object,\n\tTError = Error\n>(\n\tconfig: { onError: { type: TType; context?: TContext } },\n\tpromise: TPromise\n): Promise<\n\tReturnResult<Awaited<TPromise>, ResultErrorDefinition<TType, TContext & { error: TError }>>\n>;\nexport async function fromPromise<\n\tTPromise extends Promise<any>,\n\tconst TType extends string,\n\tTError = Error\n>(\n\tconfig: TType,\n\tpromise: TPromise\n): Promise<ReturnResult<Awaited<TPromise>, ResultErrorDefinition<TType, { error: TError }>>>;\nexport async function fromPromise<\n\tTPromise extends Promise<any>,\n\tconst TType,\n\tTContext extends object,\n\tTError = Error\n>(\n\tconfigOrPromise: string | { onError: { type: TType; context?: TContext } } | TPromise,\n\tpromise?: TPromise\n): Promise<\n\tReturnResult<Awaited<TPromise>, ResultErrorDefinition<TType, TContext & { error: TError }>>\n> {\n\tlet config: string | { onError: { type: TType; context?: TContext } } | null = null;\n\tif (!promise && configOrPromise instanceof Promise) {\n\t\tpromise = configOrPromise;\n\t} else if (!(configOrPromise instanceof Promise)) {\n\t\tconfig = configOrPromise;\n\t}\n\n\ttry {\n\t\tconst value = await promise!;\n\t\treturn ok(value);\n\t} catch (error) {\n\t\tlet type, context;\n\t\tif (typeof config === \"string\") {\n\t\t\ttype = config as TType;\n\t\t\tcontext = {};\n\t\t} else {\n\t\t\ttype = (config?.onError.type ?? null) as TType;\n\t\t\tcontext = config?.onError.context ?? {};\n\t\t}\n\n\t\treturn err(type, {\n\t\t\t...context,\n\t\t\terror: error as TError\n\t\t} as TContext & { error: TError });\n\t}\n}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { all, allAsync, allErrors, allSettledAsync, allValues } from "./all.js";
|
|
2
2
|
import { err, type Err } from "./err.js";
|
|
3
3
|
import { fn } from "./fn.js";
|
|
4
|
+
import { from } from "./from.js";
|
|
5
|
+
import { fromPromise } from "./fromPromise.js";
|
|
4
6
|
import { ok, type Ok } from "./ok.js";
|
|
5
7
|
import { pipe } from "./pipe.js";
|
|
6
8
|
import { pipeAsync } from "./pipeAsync.js";
|
|
7
|
-
import { fromPromise } from "./promise.js";
|
|
8
9
|
import type { ReturnResult } from "./result.types.js";
|
|
9
10
|
export * from "./ok.js";
|
|
10
11
|
export * from "./err.js";
|
|
@@ -18,6 +19,7 @@ export declare const Result: {
|
|
|
18
19
|
pipe: typeof pipe;
|
|
19
20
|
pipeAsync: typeof pipeAsync;
|
|
20
21
|
fn: typeof fn;
|
|
22
|
+
from: typeof from;
|
|
21
23
|
fromPromise: typeof fromPromise;
|
|
22
24
|
unwrapOrDefault: typeof unwrapOrDefault;
|
|
23
25
|
all: typeof all;
|
package/build/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { all, allAsync, allErrors, allSettledAsync, allValues } from "./all.js";
|
|
2
2
|
import { err } from "./err.js";
|
|
3
3
|
import { fn } from "./fn.js";
|
|
4
|
+
import { from } from "./from.js";
|
|
5
|
+
import { fromPromise } from "./fromPromise.js";
|
|
4
6
|
import { ok } from "./ok.js";
|
|
5
7
|
import { pipe } from "./pipe.js";
|
|
6
8
|
import { pipeAsync } from "./pipeAsync.js";
|
|
7
|
-
import { fromPromise } from "./promise.js";
|
|
8
9
|
export * from "./ok.js";
|
|
9
10
|
export * from "./err.js";
|
|
10
11
|
export * from "./result.types.js";
|
|
@@ -23,6 +24,7 @@ export const Result = {
|
|
|
23
24
|
pipe,
|
|
24
25
|
pipeAsync,
|
|
25
26
|
fn,
|
|
27
|
+
from,
|
|
26
28
|
fromPromise,
|
|
27
29
|
unwrapOrDefault,
|
|
28
30
|
all,
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,GAAG,EAAY,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,GAAG,EAAY,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,EAAE,EAAW,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAElC,SAAS,eAAe,CAGtB,MAAe,EAAE,YAA6B;IAC/C,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;AAChD,CAAC;AAED,SAAS,IAAI,CACZ,MAAe;IAEf,OAAO,MAAM,CAAC,EAAE,CAAC;AAClB,CAAC;AAED,SAAS,KAAK,CACb,MAAe;IAEf,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,EAAE;IACF,GAAG;IACH,IAAI;IACJ,SAAS;IACT,EAAE;IACF,IAAI;IACJ,WAAW;IACX,eAAe;IACf,GAAG;IACH,QAAQ;IACR,eAAe;IACf,SAAS;IACT,SAAS;IACT,IAAI;IACJ,KAAK;CACL,CAAC","sourcesContent":["import { all, allAsync, allErrors, allSettledAsync, allValues } from \"./all.js\";\nimport { err, type Err } from \"./err.js\";\nimport { fn } from \"./fn.js\";\nimport { from } from \"./from.js\";\nimport { fromPromise } from \"./fromPromise.js\";\nimport { ok, type Ok } from \"./ok.js\";\nimport { pipe } from \"./pipe.js\";\nimport { pipeAsync } from \"./pipeAsync.js\";\nimport type { ReturnResult } from \"./result.types.js\";\n\nexport * from \"./ok.js\";\nexport * from \"./err.js\";\nexport * from \"./result.types.js\";\n\nfunction unwrapOrDefault<\n\tTResult extends ReturnResult<any, any>,\n\tTValue = TResult extends Ok<infer TValue> ? TValue : never\n>(result: TResult, defaultValue: NoInfer<TValue>): TValue {\n\treturn result.ok ? result.value : defaultValue;\n}\n\nfunction isOk<TResult extends ReturnResult<any, any>>(\n\tresult: TResult\n): result is Extract<TResult, Ok<any>> {\n\treturn result.ok;\n}\n\nfunction isErr<TResult extends ReturnResult<any, any>>(\n\tresult: TResult\n): result is Extract<TResult, Err<any, any>> {\n\treturn !result.ok;\n}\n\nexport const Result = {\n\tok,\n\terr,\n\tpipe,\n\tpipeAsync,\n\tfn,\n\tfrom,\n\tfromPromise,\n\tunwrapOrDefault,\n\tall,\n\tallAsync,\n\tallSettledAsync,\n\tallValues,\n\tallErrors,\n\tisOk,\n\tisErr\n};\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod/v3";
|
|
2
|
+
export declare const OkSchema: z.ZodObject<{
|
|
3
|
+
ok: z.ZodLiteral<true>;
|
|
4
|
+
value: z.ZodAny;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
ok: true;
|
|
7
|
+
value?: any;
|
|
8
|
+
}, {
|
|
9
|
+
ok: true;
|
|
10
|
+
value?: any;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const ErrSchema: z.ZodObject<{
|
|
13
|
+
ok: z.ZodLiteral<false>;
|
|
14
|
+
type: z.ZodAny;
|
|
15
|
+
context: z.ZodAny;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
ok: false;
|
|
18
|
+
type?: any;
|
|
19
|
+
context?: any;
|
|
20
|
+
}, {
|
|
21
|
+
ok: false;
|
|
22
|
+
type?: any;
|
|
23
|
+
context?: any;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const ReturnResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
26
|
+
ok: z.ZodLiteral<true>;
|
|
27
|
+
value: z.ZodAny;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
ok: true;
|
|
30
|
+
value?: any;
|
|
31
|
+
}, {
|
|
32
|
+
ok: true;
|
|
33
|
+
value?: any;
|
|
34
|
+
}>, z.ZodObject<{
|
|
35
|
+
ok: z.ZodLiteral<false>;
|
|
36
|
+
type: z.ZodAny;
|
|
37
|
+
context: z.ZodAny;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
ok: false;
|
|
40
|
+
type?: any;
|
|
41
|
+
context?: any;
|
|
42
|
+
}, {
|
|
43
|
+
ok: false;
|
|
44
|
+
type?: any;
|
|
45
|
+
context?: any;
|
|
46
|
+
}>]>;
|
package/build/zod/v3.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod/v3";
|
|
2
|
+
export const OkSchema = z.object({
|
|
3
|
+
ok: z.literal(true),
|
|
4
|
+
value: z.any()
|
|
5
|
+
});
|
|
6
|
+
export const ErrSchema = z.object({
|
|
7
|
+
ok: z.literal(false),
|
|
8
|
+
type: z.any(),
|
|
9
|
+
context: z.any()
|
|
10
|
+
});
|
|
11
|
+
export const ReturnResultSchema = z.union([OkSchema, ErrSchema]);
|
|
12
|
+
//# sourceMappingURL=v3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3.js","sourceRoot":"","sources":["../../src/zod/v3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAmB,MAAM,QAAQ,CAAC;AAK5C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE;CAC8B,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE;IACb,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE;CACkC,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC","sourcesContent":["import { z, type ZodTypeAny } from \"zod/v3\";\n\nimport type { Err } from \"../err.js\";\nimport type { Ok } from \"../ok.js\";\n\nexport const OkSchema = z.object({\n\tok: z.literal(true),\n\tvalue: z.any()\n} satisfies Record<keyof Ok<any>, ZodTypeAny>);\n\nexport const ErrSchema = z.object({\n\tok: z.literal(false),\n\ttype: z.any(),\n\tcontext: z.any()\n} satisfies Record<keyof Err<any, any>, ZodTypeAny>);\n\nexport const ReturnResultSchema = z.union([OkSchema, ErrSchema]);\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const OkSchema: z.ZodObject<{
|
|
3
|
+
ok: z.ZodLiteral<true>;
|
|
4
|
+
value: z.ZodAny;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export declare const ErrSchema: z.ZodObject<{
|
|
7
|
+
ok: z.ZodLiteral<false>;
|
|
8
|
+
type: z.ZodAny;
|
|
9
|
+
context: z.ZodAny;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const ReturnResultSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
+
ok: z.ZodLiteral<true>;
|
|
13
|
+
value: z.ZodAny;
|
|
14
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
15
|
+
ok: z.ZodLiteral<false>;
|
|
16
|
+
type: z.ZodAny;
|
|
17
|
+
context: z.ZodAny;
|
|
18
|
+
}, z.core.$strip>]>;
|
package/build/zod/v4.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const OkSchema = z.object({
|
|
3
|
+
ok: z.literal(true),
|
|
4
|
+
value: z.any()
|
|
5
|
+
});
|
|
6
|
+
export const ErrSchema = z.object({
|
|
7
|
+
ok: z.literal(false),
|
|
8
|
+
type: z.any(),
|
|
9
|
+
context: z.any()
|
|
10
|
+
});
|
|
11
|
+
export const ReturnResultSchema = z.union([OkSchema, ErrSchema]);
|
|
12
|
+
//# sourceMappingURL=v4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v4.js","sourceRoot":"","sources":["../../src/zod/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE;CAC6B,CAAC,CAAC;AAE9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE;IACb,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE;CACiC,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport type { Err } from \"../err.js\";\nimport type { Ok } from \"../ok.js\";\n\nexport const OkSchema = z.object({\n\tok: z.literal(true),\n\tvalue: z.any()\n} satisfies Record<keyof Ok<any>, z.ZodType>);\n\nexport const ErrSchema = z.object({\n\tok: z.literal(false),\n\ttype: z.any(),\n\tcontext: z.any()\n} satisfies Record<keyof Err<any, any>, z.ZodType>);\n\nexport const ReturnResultSchema = z.union([OkSchema, ErrSchema]);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@l3dev/result",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Type-safe result-based error handling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -11,8 +11,16 @@
|
|
|
11
11
|
"import": "./build/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./zod": {
|
|
14
|
-
"types": "./build/zod.d.ts",
|
|
15
|
-
"import": "./build/zod.js"
|
|
14
|
+
"types": "./build/zod/v4.d.ts",
|
|
15
|
+
"import": "./build/zod/v4.js"
|
|
16
|
+
},
|
|
17
|
+
"./zod/v4": {
|
|
18
|
+
"types": "./build/zod/v4.d.ts",
|
|
19
|
+
"import": "./build/zod/v4.js"
|
|
20
|
+
},
|
|
21
|
+
"./zod/v3": {
|
|
22
|
+
"types": "./build/zod/v3.d.ts",
|
|
23
|
+
"import": "./build/zod/v3.js"
|
|
16
24
|
}
|
|
17
25
|
},
|
|
18
26
|
"files": [
|
|
@@ -26,7 +34,7 @@
|
|
|
26
34
|
"url": "https://github.com/l3dotdev/npm-packages.git"
|
|
27
35
|
},
|
|
28
36
|
"dependencies": {
|
|
29
|
-
"zod": "^
|
|
37
|
+
"zod": "^4.1.12"
|
|
30
38
|
},
|
|
31
39
|
"scripts": {
|
|
32
40
|
"build": "tsc -p tsconfig.json",
|