phecda-zod 2.0.7 → 3.0.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/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +4 -21
- package/dist/index.mjs +5 -21
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,5 @@ import { ZodTypeDef, ZodSchema, z } from 'zod';
|
|
|
3
3
|
declare function zodToClass<TOutput = any, TDef extends ZodTypeDef = ZodTypeDef, TInput = TOutput>(zod: ZodSchema<TOutput, TDef, TInput>): (new (data?: Partial<z.infer<ZodSchema<TOutput, TDef, TInput>>>) => z.infer<ZodSchema<TOutput, TDef, TInput>>) & {
|
|
4
4
|
schema: ZodSchema<TOutput, TDef, TInput>;
|
|
5
5
|
};
|
|
6
|
-
declare function parse<Construct extends ReturnType<typeof zodToClass>>(C: Construct, data: ConstructorParameters<Construct>[0]): z.SafeParseReturnType<any, any>;
|
|
7
6
|
|
|
8
|
-
export {
|
|
7
|
+
export { zodToClass };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ import { ZodTypeDef, ZodSchema, z } from 'zod';
|
|
|
3
3
|
declare function zodToClass<TOutput = any, TDef extends ZodTypeDef = ZodTypeDef, TInput = TOutput>(zod: ZodSchema<TOutput, TDef, TInput>): (new (data?: Partial<z.infer<ZodSchema<TOutput, TDef, TInput>>>) => z.infer<ZodSchema<TOutput, TDef, TInput>>) & {
|
|
4
4
|
schema: ZodSchema<TOutput, TDef, TInput>;
|
|
5
5
|
};
|
|
6
|
-
declare function parse<Construct extends ReturnType<typeof zodToClass>>(C: Construct, data: ConstructorParameters<Construct>[0]): z.SafeParseReturnType<any, any>;
|
|
7
6
|
|
|
8
|
-
export {
|
|
7
|
+
export { zodToClass };
|
package/dist/index.js
CHANGED
|
@@ -21,41 +21,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
-
parse: () => parse,
|
|
25
24
|
zodToClass: () => zodToClass
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(index_exports);
|
|
28
27
|
var import_phecda_core = require("phecda-core");
|
|
29
|
-
function ZodTo(zod) {
|
|
30
|
-
return (proto) => {
|
|
31
|
-
(0, import_phecda_core.setMeta)(proto, void 0, void 0, {
|
|
32
|
-
zod
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
__name(ZodTo, "ZodTo");
|
|
37
28
|
function zodToClass(zod) {
|
|
38
29
|
let Z = class Z {
|
|
39
30
|
static {
|
|
40
31
|
__name(this, "Z");
|
|
41
32
|
}
|
|
42
|
-
constructor(data) {
|
|
43
|
-
Object.assign(this, data);
|
|
44
|
-
}
|
|
45
|
-
static schema = zod;
|
|
46
33
|
};
|
|
47
|
-
(0, import_phecda_core.addDecoToClass)(Z, void 0,
|
|
34
|
+
(0, import_phecda_core.addDecoToClass)(Z, void 0, (0, import_phecda_core.Rule)(({ value }) => {
|
|
35
|
+
const { success, error } = zod.safeParse(value);
|
|
36
|
+
if (!success) return error;
|
|
37
|
+
}));
|
|
48
38
|
return Z;
|
|
49
39
|
}
|
|
50
40
|
__name(zodToClass, "zodToClass");
|
|
51
|
-
function parse(C, data) {
|
|
52
|
-
const meta = (0, import_phecda_core.getMeta)(C);
|
|
53
|
-
const zod = meta.find((item) => !!item.zod).zod;
|
|
54
|
-
return zod.safeParse(data);
|
|
55
|
-
}
|
|
56
|
-
__name(parse, "parse");
|
|
57
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
42
|
0 && (module.exports = {
|
|
59
|
-
parse,
|
|
60
43
|
zodToClass
|
|
61
44
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,36 +2,20 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
import {
|
|
6
|
-
function ZodTo(zod) {
|
|
7
|
-
return (proto) => {
|
|
8
|
-
setMeta(proto, void 0, void 0, {
|
|
9
|
-
zod
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
__name(ZodTo, "ZodTo");
|
|
5
|
+
import { Rule, addDecoToClass } from "phecda-core";
|
|
14
6
|
function zodToClass(zod) {
|
|
15
7
|
let Z = class Z {
|
|
16
8
|
static {
|
|
17
9
|
__name(this, "Z");
|
|
18
10
|
}
|
|
19
|
-
constructor(data) {
|
|
20
|
-
Object.assign(this, data);
|
|
21
|
-
}
|
|
22
|
-
static schema = zod;
|
|
23
11
|
};
|
|
24
|
-
addDecoToClass(Z, void 0,
|
|
12
|
+
addDecoToClass(Z, void 0, Rule(({ value }) => {
|
|
13
|
+
const { success, error } = zod.safeParse(value);
|
|
14
|
+
if (!success) return error;
|
|
15
|
+
}));
|
|
25
16
|
return Z;
|
|
26
17
|
}
|
|
27
18
|
__name(zodToClass, "zodToClass");
|
|
28
|
-
function parse(C, data) {
|
|
29
|
-
const meta = getMeta(C);
|
|
30
|
-
const zod = meta.find((item) => !!item.zod).zod;
|
|
31
|
-
return zod.safeParse(data);
|
|
32
|
-
}
|
|
33
|
-
__name(parse, "parse");
|
|
34
19
|
export {
|
|
35
|
-
parse,
|
|
36
20
|
zodToClass
|
|
37
21
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-zod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "use zod instead of decorator/reflect-metadata",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"tsup": "^8.1.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"phecda-core": "
|
|
18
|
+
"phecda-core": "5.0.0",
|
|
19
19
|
"zod": "^3.23.5"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|