@kubb/plugin-zod 3.16.1 → 3.16.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/dist/components-CJ6RN1R2.js +414 -0
- package/dist/components-CJ6RN1R2.js.map +1 -0
- package/dist/components-GvkeO2ig.cjs +454 -0
- package/dist/components-GvkeO2ig.cjs.map +1 -0
- package/dist/components.cjs +3 -15
- package/dist/components.d.cts +56 -26
- package/dist/components.d.ts +56 -26
- package/dist/components.js +3 -3
- package/dist/generators-B13NknOz.cjs +265 -0
- package/dist/generators-B13NknOz.cjs.map +1 -0
- package/dist/generators-DcUZYcq0.js +254 -0
- package/dist/generators-DcUZYcq0.js.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +8 -8
- package/dist/generators.d.ts +8 -8
- package/dist/generators.js +4 -4
- package/dist/index.cjs +103 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +103 -131
- package/dist/index.js.map +1 -1
- package/dist/types-B0UqdcbG.d.cts +1237 -0
- package/dist/types-YpNWeJUW.d.ts +1237 -0
- package/dist/utils.cjs +0 -4
- package/dist/utils.d.cts +18 -24
- package/dist/utils.d.ts +18 -24
- package/dist/utils.js +1 -3
- package/package.json +24 -30
- package/src/components/Zod.tsx +3 -2
- package/src/parser.ts +8 -0
- package/dist/chunk-AHCG4FYY.js +0 -448
- package/dist/chunk-AHCG4FYY.js.map +0 -1
- package/dist/chunk-QNMY34G2.cjs +0 -455
- package/dist/chunk-QNMY34G2.cjs.map +0 -1
- package/dist/chunk-RQAEGENA.cjs +0 -184
- package/dist/chunk-RQAEGENA.cjs.map +0 -1
- package/dist/chunk-Z6ERLJH7.js +0 -181
- package/dist/chunk-Z6ERLJH7.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-BOF1ntMm.d.cts +0 -130
- package/dist/types-BOF1ntMm.d.ts +0 -130
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/utils.cjs
CHANGED
package/dist/utils.d.cts
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
5
|
-
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
6
|
-
*/
|
|
3
|
+
//#region src/utils/ToZod.d.ts
|
|
7
4
|
|
|
8
5
|
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
9
6
|
type nonoptional<T> = T extends undefined ? never : T;
|
|
10
7
|
type nonnullable<T> = T extends null ? never : T;
|
|
11
8
|
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
12
9
|
type zodKey<T> = isAny<T> extends true ? 'any' : equals<T, boolean> extends true ? 'boolean' : [undefined] extends [T] ? 'optional' : [null] extends [T] ? 'nullable' : T extends any[] ? 'array' : equals<T, string> extends true ? 'string' : equals<T, bigint> extends true ? 'bigint' : equals<T, number> extends true ? 'number' : equals<T, Date> extends true ? 'date' : T extends {
|
|
13
|
-
|
|
10
|
+
[k: string]: any;
|
|
14
11
|
} ? 'object' : 'rest';
|
|
15
12
|
type ToZod<T> = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, 'passthrough', unknown, T>;
|
|
28
|
-
rest: z.ZodType<T>;
|
|
13
|
+
any: z.ZodAny;
|
|
14
|
+
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
15
|
+
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
16
|
+
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
17
|
+
string: z.ZodString;
|
|
18
|
+
bigint: z.ZodBigInt;
|
|
19
|
+
number: z.ZodNumber;
|
|
20
|
+
boolean: z.ZodBoolean;
|
|
21
|
+
date: z.ZodDate;
|
|
22
|
+
object: z.ZodObject<{ [K in keyof T]: T[K] }, 'passthrough', unknown, T>;
|
|
23
|
+
rest: z.ZodType<T>;
|
|
29
24
|
}[zodKey<T>];
|
|
30
|
-
type ZodShape<T> = {
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type { ToZod, ZodShape };
|
|
25
|
+
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
26
|
+
//#endregion
|
|
27
|
+
export { type ToZod, type ZodShape };
|
|
28
|
+
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
5
|
-
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
6
|
-
*/
|
|
3
|
+
//#region src/utils/ToZod.d.ts
|
|
7
4
|
|
|
8
5
|
type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
|
|
9
6
|
type nonoptional<T> = T extends undefined ? never : T;
|
|
10
7
|
type nonnullable<T> = T extends null ? never : T;
|
|
11
8
|
type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
|
|
12
9
|
type zodKey<T> = isAny<T> extends true ? 'any' : equals<T, boolean> extends true ? 'boolean' : [undefined] extends [T] ? 'optional' : [null] extends [T] ? 'nullable' : T extends any[] ? 'array' : equals<T, string> extends true ? 'string' : equals<T, bigint> extends true ? 'bigint' : equals<T, number> extends true ? 'number' : equals<T, Date> extends true ? 'date' : T extends {
|
|
13
|
-
|
|
10
|
+
[k: string]: any;
|
|
14
11
|
} ? 'object' : 'rest';
|
|
15
12
|
type ToZod<T> = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, 'passthrough', unknown, T>;
|
|
28
|
-
rest: z.ZodType<T>;
|
|
13
|
+
any: z.ZodAny;
|
|
14
|
+
optional: z.ZodOptional<ToZod<nonoptional<T>>>;
|
|
15
|
+
nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
|
|
16
|
+
array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
|
|
17
|
+
string: z.ZodString;
|
|
18
|
+
bigint: z.ZodBigInt;
|
|
19
|
+
number: z.ZodNumber;
|
|
20
|
+
boolean: z.ZodBoolean;
|
|
21
|
+
date: z.ZodDate;
|
|
22
|
+
object: z.ZodObject<{ [K in keyof T]: T[K] }, 'passthrough', unknown, T>;
|
|
23
|
+
rest: z.ZodType<T>;
|
|
29
24
|
}[zodKey<T>];
|
|
30
|
-
type ZodShape<T> = {
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type { ToZod, ZodShape };
|
|
25
|
+
type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
|
|
26
|
+
//#endregion
|
|
27
|
+
export { type ToZod, type ZodShape };
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.3",
|
|
4
4
|
"description": "Zod schema generator plugin for Kubb, creating type-safe validation schemas from OpenAPI specifications for runtime data validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -27,30 +27,25 @@
|
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"import": "./dist/index.js",
|
|
30
|
-
"require": "./dist/index.cjs"
|
|
31
|
-
"default": "./dist/index.cjs"
|
|
32
|
-
},
|
|
33
|
-
"./generators": {
|
|
34
|
-
"import": "./dist/generators.js",
|
|
35
|
-
"require": "./dist/generators.cjs",
|
|
36
|
-
"default": "./dist/generators.cjs"
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
37
31
|
},
|
|
38
32
|
"./components": {
|
|
39
33
|
"import": "./dist/components.js",
|
|
40
|
-
"require": "./dist/components.cjs"
|
|
41
|
-
|
|
34
|
+
"require": "./dist/components.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./generators": {
|
|
37
|
+
"import": "./dist/generators.js",
|
|
38
|
+
"require": "./dist/generators.cjs"
|
|
42
39
|
},
|
|
43
40
|
"./utils": {
|
|
44
41
|
"import": "./dist/utils.js",
|
|
45
|
-
"require": "./dist/utils.cjs"
|
|
46
|
-
"default": "./dist/utils.cjs"
|
|
42
|
+
"require": "./dist/utils.cjs"
|
|
47
43
|
},
|
|
48
|
-
"./package.json": "./package.json"
|
|
49
|
-
"./*": "./*"
|
|
44
|
+
"./package.json": "./package.json"
|
|
50
45
|
},
|
|
51
|
-
"main": "dist/index.cjs",
|
|
52
|
-
"module": "dist/index.js",
|
|
53
|
-
"types": "./dist/index.d.
|
|
46
|
+
"main": "./dist/index.cjs",
|
|
47
|
+
"module": "./dist/index.js",
|
|
48
|
+
"types": "./dist/index.d.cts",
|
|
54
49
|
"typesVersions": {
|
|
55
50
|
"*": {
|
|
56
51
|
"components": [
|
|
@@ -71,21 +66,20 @@
|
|
|
71
66
|
"!/**/__tests__/**"
|
|
72
67
|
],
|
|
73
68
|
"dependencies": {
|
|
74
|
-
"@kubb/core": "3.16.
|
|
75
|
-
"@kubb/oas": "3.16.
|
|
76
|
-
"@kubb/parser-ts": "3.16.
|
|
77
|
-
"@kubb/plugin-
|
|
78
|
-
"@kubb/plugin-
|
|
79
|
-
"@kubb/react": "3.16.
|
|
69
|
+
"@kubb/core": "3.16.3",
|
|
70
|
+
"@kubb/oas": "3.16.3",
|
|
71
|
+
"@kubb/parser-ts": "3.16.3",
|
|
72
|
+
"@kubb/plugin-oas": "3.16.3",
|
|
73
|
+
"@kubb/plugin-ts": "3.16.3",
|
|
74
|
+
"@kubb/react": "3.16.3"
|
|
80
75
|
},
|
|
81
76
|
"devDependencies": {
|
|
82
77
|
"@asteasolutions/zod-to-openapi": "^7.3.4",
|
|
83
78
|
"@hono/zod-openapi": "0.19.2",
|
|
84
|
-
"
|
|
79
|
+
"tsdown": "^0.14.1",
|
|
85
80
|
"zod": "~3.24.4",
|
|
86
|
-
"@kubb/config-ts": "3.16.
|
|
87
|
-
"@kubb/
|
|
88
|
-
"@kubb/plugin-oas": "3.16.1"
|
|
81
|
+
"@kubb/config-ts": "3.16.3",
|
|
82
|
+
"@kubb/plugin-oas": "3.16.3"
|
|
89
83
|
},
|
|
90
84
|
"peerDependencies": {
|
|
91
85
|
"@kubb/react": "^3.0.0"
|
|
@@ -98,13 +92,13 @@
|
|
|
98
92
|
"registry": "https://registry.npmjs.org/"
|
|
99
93
|
},
|
|
100
94
|
"scripts": {
|
|
101
|
-
"build": "
|
|
95
|
+
"build": "tsdown",
|
|
102
96
|
"clean": "npx rimraf ./dist",
|
|
103
97
|
"lint": "bun biome lint .",
|
|
104
|
-
"lint:fix": "bun biome lint--fix --unsafe .",
|
|
98
|
+
"lint:fix": "bun biome lint --fix --unsafe .",
|
|
105
99
|
"release": "pnpm publish --no-git-check",
|
|
106
100
|
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
107
|
-
"start": "
|
|
101
|
+
"start": "tsdown --watch",
|
|
108
102
|
"test": "vitest --passWithNoTests",
|
|
109
103
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
110
104
|
}
|
package/src/components/Zod.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import transformers from '@kubb/core/transformers'
|
|
2
2
|
import type { SchemaObject } from '@kubb/oas'
|
|
3
|
-
import { isKeyword, type Schema, schemaKeywords } from '@kubb/plugin-oas'
|
|
3
|
+
import { isKeyword, type Schema, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
4
4
|
import { Const, File, Type } from '@kubb/react'
|
|
5
5
|
import * as parserZod from '../parser.ts'
|
|
6
6
|
import type { PluginZod } from '../types.ts'
|
|
@@ -34,7 +34,8 @@ export function Zod({
|
|
|
34
34
|
version,
|
|
35
35
|
emptySchemaType,
|
|
36
36
|
}: Props) {
|
|
37
|
-
const hasTuple =
|
|
37
|
+
const hasTuple = !!SchemaGenerator.deepSearch(tree, schemaKeywords.tuple)
|
|
38
|
+
|
|
38
39
|
const schemas = parserZod.sort(tree).filter((item) => {
|
|
39
40
|
if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
|
|
40
41
|
return false
|
package/src/parser.ts
CHANGED
|
@@ -223,6 +223,14 @@ type ParserOptions = {
|
|
|
223
223
|
export function parse({ parent, current, name, siblings }: SchemaTree, options: ParserOptions): string | undefined {
|
|
224
224
|
const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]
|
|
225
225
|
|
|
226
|
+
// Early exit: if siblings contain both matches and ref → skip matches entirely
|
|
227
|
+
const hasMatches = siblings.some((it) => isKeyword(it, schemaKeywords.matches))
|
|
228
|
+
const hasRef = siblings.some((it) => isKeyword(it, schemaKeywords.ref))
|
|
229
|
+
|
|
230
|
+
if (hasMatches && hasRef && isKeyword(current, schemaKeywords.matches)) {
|
|
231
|
+
return undefined // strip matches
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
if (!value) {
|
|
227
235
|
return undefined
|
|
228
236
|
}
|