@kubb/plugin-zod 3.16.2 → 3.16.4

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 (53) hide show
  1. package/dist/components-CJ6RN1R2.js +414 -0
  2. package/dist/components-CJ6RN1R2.js.map +1 -0
  3. package/dist/components-GvkeO2ig.cjs +454 -0
  4. package/dist/components-GvkeO2ig.cjs.map +1 -0
  5. package/dist/components.cjs +3 -15
  6. package/dist/components.d.cts +56 -26
  7. package/dist/components.d.ts +56 -26
  8. package/dist/components.js +3 -3
  9. package/dist/generators-C3ALr3ph.js +254 -0
  10. package/dist/generators-C3ALr3ph.js.map +1 -0
  11. package/dist/generators-D3uH7-vO.cjs +265 -0
  12. package/dist/generators-D3uH7-vO.cjs.map +1 -0
  13. package/dist/generators.cjs +4 -16
  14. package/dist/generators.d.cts +8 -8
  15. package/dist/generators.d.ts +8 -8
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +103 -137
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -7
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +103 -131
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-B0UqdcbG.d.cts +1237 -0
  24. package/dist/types-YpNWeJUW.d.ts +1237 -0
  25. package/dist/utils/v4.cjs +0 -0
  26. package/dist/utils/v4.d.cts +38 -0
  27. package/dist/utils/v4.d.ts +38 -0
  28. package/dist/utils/v4.js +1 -0
  29. package/dist/utils.cjs +0 -4
  30. package/dist/utils.d.cts +18 -24
  31. package/dist/utils.d.ts +18 -24
  32. package/dist/utils.js +1 -3
  33. package/package.json +32 -31
  34. package/src/generators/zodGenerator.tsx +2 -2
  35. package/src/plugin.ts +2 -3
  36. package/src/utils/v4/ToZod.ts +61 -0
  37. package/src/utils/v4/index.ts +1 -0
  38. package/dist/chunk-4QMHDKCS.js +0 -453
  39. package/dist/chunk-4QMHDKCS.js.map +0 -1
  40. package/dist/chunk-6LDDO2JJ.cjs +0 -184
  41. package/dist/chunk-6LDDO2JJ.cjs.map +0 -1
  42. package/dist/chunk-FYI4GRXP.cjs +0 -460
  43. package/dist/chunk-FYI4GRXP.cjs.map +0 -1
  44. package/dist/chunk-I74P26CO.js +0 -181
  45. package/dist/chunk-I74P26CO.js.map +0 -1
  46. package/dist/components.cjs.map +0 -1
  47. package/dist/components.js.map +0 -1
  48. package/dist/generators.cjs.map +0 -1
  49. package/dist/generators.js.map +0 -1
  50. package/dist/types-BOF1ntMm.d.cts +0 -130
  51. package/dist/types-BOF1ntMm.d.ts +0 -130
  52. package/dist/utils.cjs.map +0 -1
  53. package/dist/utils.js.map +0 -1
File without changes
@@ -0,0 +1,38 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/utils/v4/ToZod.d.ts
4
+
5
+ /**
6
+ * See https://github.com/colinhacks/tozod/blob/master/src/index.ts
7
+ * Adapted based on https://github.com/colinhacks/zod/issues/372
8
+ */
9
+ type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
10
+ type nonoptional<T> = T extends undefined ? never : T;
11
+ type nonnullable<T> = T extends null ? never : T;
12
+ type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
13
+ 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 {
14
+ slice: any;
15
+ stream: any;
16
+ text: any;
17
+ } ? 'blob' : T extends {
18
+ [key: string]: any;
19
+ } ? 'object' : 'rest';
20
+ type ToZod<T> = {
21
+ any: z.ZodAny;
22
+ optional: z.ZodOptional<ToZod<nonoptional<T>>>;
23
+ nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
24
+ array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
25
+ string: z.ZodString;
26
+ file: z.ZodFile;
27
+ blob: z.ZodType<Blob, T>;
28
+ bigint: z.ZodBigInt;
29
+ number: z.ZodNumber;
30
+ boolean: z.ZodBoolean;
31
+ date: z.ZodDate;
32
+ object: z.ZodObject<ZodShape<T>, 'passthrough'>;
33
+ rest: z.ZodType<T>;
34
+ }[zodKey<T>];
35
+ type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
36
+ //#endregion
37
+ export { type ToZod, type ZodShape };
38
+ //# sourceMappingURL=v4.d.cts.map
@@ -0,0 +1,38 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/utils/v4/ToZod.d.ts
4
+
5
+ /**
6
+ * See https://github.com/colinhacks/tozod/blob/master/src/index.ts
7
+ * Adapted based on https://github.com/colinhacks/zod/issues/372
8
+ */
9
+ type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false;
10
+ type nonoptional<T> = T extends undefined ? never : T;
11
+ type nonnullable<T> = T extends null ? never : T;
12
+ type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false;
13
+ 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 {
14
+ slice: any;
15
+ stream: any;
16
+ text: any;
17
+ } ? 'blob' : T extends {
18
+ [key: string]: any;
19
+ } ? 'object' : 'rest';
20
+ type ToZod<T> = {
21
+ any: z.ZodAny;
22
+ optional: z.ZodOptional<ToZod<nonoptional<T>>>;
23
+ nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
24
+ array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
25
+ string: z.ZodString;
26
+ file: z.ZodFile;
27
+ blob: z.ZodType<Blob, T>;
28
+ bigint: z.ZodBigInt;
29
+ number: z.ZodNumber;
30
+ boolean: z.ZodBoolean;
31
+ date: z.ZodDate;
32
+ object: z.ZodObject<ZodShape<T>, 'passthrough'>;
33
+ rest: z.ZodType<T>;
34
+ }[zodKey<T>];
35
+ type ZodShape<T> = { [key in keyof T]-?: ToZod<T[key]> };
36
+ //#endregion
37
+ export { type ToZod, type ZodShape };
38
+ //# sourceMappingURL=v4.d.ts.map
@@ -0,0 +1 @@
1
+ export { };
package/dist/utils.cjs CHANGED
@@ -1,4 +0,0 @@
1
- 'use strict';
2
-
3
- //# sourceMappingURL=utils.cjs.map
4
- //# sourceMappingURL=utils.cjs.map
package/dist/utils.d.cts CHANGED
@@ -1,34 +1,28 @@
1
- import { z } from 'zod';
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
- [k: string]: any;
10
+ [k: string]: any;
14
11
  } ? 'object' : 'rest';
15
12
  type ToZod<T> = {
16
- any: z.ZodAny;
17
- optional: z.ZodOptional<ToZod<nonoptional<T>>>;
18
- nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
19
- array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
20
- string: z.ZodString;
21
- bigint: z.ZodBigInt;
22
- number: z.ZodNumber;
23
- boolean: z.ZodBoolean;
24
- date: z.ZodDate;
25
- object: z.ZodObject<{
26
- [K in keyof T]: T[K];
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
- [key in keyof T]-?: ToZod<T[key]>;
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 'zod';
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
- [k: string]: any;
10
+ [k: string]: any;
14
11
  } ? 'object' : 'rest';
15
12
  type ToZod<T> = {
16
- any: z.ZodAny;
17
- optional: z.ZodOptional<ToZod<nonoptional<T>>>;
18
- nullable: z.ZodNullable<ToZod<nonnullable<T>>>;
19
- array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never;
20
- string: z.ZodString;
21
- bigint: z.ZodBigInt;
22
- number: z.ZodNumber;
23
- boolean: z.ZodBoolean;
24
- date: z.ZodDate;
25
- object: z.ZodObject<{
26
- [K in keyof T]: T[K];
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
- [key in keyof T]-?: ToZod<T[key]>;
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
@@ -1,3 +1 @@
1
-
2
- //# sourceMappingURL=utils.js.map
3
- //# sourceMappingURL=utils.js.map
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "3.16.2",
3
+ "version": "3.16.4",
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,29 @@
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
- "default": "./dist/components.cjs"
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
+ "./utils/v4": {
45
+ "import": "./dist/utils/v4.js",
46
+ "require": "./dist/utils/v4.cjs"
47
+ },
48
+ "./package.json": "./package.json"
50
49
  },
51
- "main": "dist/index.cjs",
52
- "module": "dist/index.js",
53
- "types": "./dist/index.d.ts",
50
+ "main": "./dist/index.cjs",
51
+ "module": "./dist/index.js",
52
+ "types": "./dist/index.d.cts",
54
53
  "typesVersions": {
55
54
  "*": {
56
55
  "components": [
@@ -61,6 +60,9 @@
61
60
  ],
62
61
  "utils": [
63
62
  "./dist/utils.d.ts"
63
+ ],
64
+ "utils/v4": [
65
+ "./dist/utils/v4.d.ts"
64
66
  ]
65
67
  }
66
68
  },
@@ -71,21 +73,20 @@
71
73
  "!/**/__tests__/**"
72
74
  ],
73
75
  "dependencies": {
74
- "@kubb/core": "3.16.2",
75
- "@kubb/parser-ts": "3.16.2",
76
- "@kubb/oas": "3.16.2",
77
- "@kubb/plugin-oas": "3.16.2",
78
- "@kubb/plugin-ts": "3.16.2",
79
- "@kubb/react": "3.16.2"
76
+ "@kubb/core": "3.16.4",
77
+ "@kubb/oas": "3.16.4",
78
+ "@kubb/parser-ts": "3.16.4",
79
+ "@kubb/plugin-oas": "3.16.4",
80
+ "@kubb/plugin-ts": "3.16.4",
81
+ "@kubb/react": "3.16.4"
80
82
  },
81
83
  "devDependencies": {
82
84
  "@asteasolutions/zod-to-openapi": "^7.3.4",
83
85
  "@hono/zod-openapi": "0.19.2",
84
- "tsup": "^8.5.0",
85
- "zod": "~3.24.4",
86
- "@kubb/config-tsup": "3.16.2",
87
- "@kubb/config-ts": "3.16.2",
88
- "@kubb/plugin-oas": "3.16.2"
86
+ "tsdown": "^0.14.1",
87
+ "zod": "^3.25.67",
88
+ "@kubb/config-ts": "3.16.4",
89
+ "@kubb/plugin-oas": "3.16.4"
89
90
  },
90
91
  "peerDependencies": {
91
92
  "@kubb/react": "^3.0.0"
@@ -98,13 +99,13 @@
98
99
  "registry": "https://registry.npmjs.org/"
99
100
  },
100
101
  "scripts": {
101
- "build": "tsup",
102
+ "build": "tsdown",
102
103
  "clean": "npx rimraf ./dist",
103
104
  "lint": "bun biome lint .",
104
- "lint:fix": "bun biome lint--fix --unsafe .",
105
+ "lint:fix": "bun biome lint --fix --unsafe .",
105
106
  "release": "pnpm publish --no-git-check",
106
107
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
107
- "start": "tsup --watch",
108
+ "start": "tsdown --watch",
108
109
  "test": "vitest --passWithNoTests",
109
110
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
110
111
  }
@@ -63,7 +63,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
63
63
  return (
64
64
  <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>
65
65
  {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
66
- {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}
66
+ {typed && <File.Import isTypeOnly path={plugin.options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}
67
67
  {imports.map((imp) => (
68
68
  <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />
69
69
  ))}
@@ -133,7 +133,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
133
133
  >
134
134
  <File.Import name={['z']} path={importPath} />
135
135
  {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
136
- {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}
136
+ {typed && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}
137
137
  {imports.map((imp) => (
138
138
  <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />
139
139
  ))}
package/src/plugin.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import path from 'node:path'
2
- import type { Plugin } from '@kubb/core'
3
- import { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'
2
+ import { createPlugin, FileManager, type Group, PackageManager, type Plugin, PluginManager } from '@kubb/core'
4
3
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
4
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
6
5
  import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
@@ -25,7 +24,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
25
24
  typed = false,
26
25
  mapper = {},
27
26
  operations = false,
28
- version = '3',
27
+ version = new PackageManager().isValidSync('zod', '>=4') ? '4' : '3',
29
28
  importPath = version === '4' ? 'zod/v4' : 'zod',
30
29
  coercion = false,
31
30
  inferred = false,
@@ -0,0 +1,61 @@
1
+ import type { z } from 'zod/v4'
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
+ */
7
+
8
+ type isAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false
9
+ type nonoptional<T> = T extends undefined ? never : T
10
+ type nonnullable<T> = T extends null ? never : T
11
+ type equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false
12
+
13
+ type zodKey<T> = isAny<T> extends true
14
+ ? 'any'
15
+ : equals<T, boolean> extends true
16
+ ? 'boolean'
17
+ : [undefined] extends [T]
18
+ ? 'optional'
19
+ : [null] extends [T]
20
+ ? 'nullable'
21
+ : T extends any[]
22
+ ? 'array'
23
+ : equals<T, string> extends true
24
+ ? 'string'
25
+ : equals<T, bigint> extends true
26
+ ? 'bigint'
27
+ : equals<T, number> extends true
28
+ ? 'number'
29
+ : equals<T, Date> extends true
30
+ ? 'date'
31
+ : T extends { slice: any; stream: any; text: any }
32
+ ? 'blob'
33
+ : T extends { [key: string]: any }
34
+ ? 'object'
35
+ : 'rest'
36
+
37
+ type ToZod<T> = {
38
+ any: z.ZodAny
39
+ // @ts-expect-error Excessive stack depth comparing types
40
+ optional: z.ZodOptional<ToZod<nonoptional<T>>>
41
+ // @ts-expect-error Excessive stack depth comparing types
42
+ nullable: z.ZodNullable<ToZod<nonnullable<T>>>
43
+ // @ts-expect-error Excessive stack depth comparing types
44
+ array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never
45
+ string: z.ZodString
46
+ file: z.ZodFile
47
+ blob: z.ZodType<Blob, T>
48
+ bigint: z.ZodBigInt
49
+ number: z.ZodNumber
50
+ boolean: z.ZodBoolean
51
+ date: z.ZodDate
52
+ // @ts-expect-error Excessive stack depth comparing types
53
+ object: z.ZodObject<ZodShape<T>, 'passthrough'>
54
+ rest: z.ZodType<T>
55
+ }[zodKey<T>]
56
+
57
+ type ZodShape<T> = {
58
+ [key in keyof T]-?: ToZod<T[key]>
59
+ }
60
+
61
+ export type { ToZod, ZodShape }
@@ -0,0 +1 @@
1
+ export type { ToZod, ZodShape } from './ToZod.ts'