@kubb/plugin-zod 3.16.2 → 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.
Files changed (45) 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-B13NknOz.cjs +265 -0
  10. package/dist/generators-B13NknOz.cjs.map +1 -0
  11. package/dist/generators-DcUZYcq0.js +254 -0
  12. package/dist/generators-DcUZYcq0.js.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.cjs +0 -4
  26. package/dist/utils.d.cts +18 -24
  27. package/dist/utils.d.ts +18 -24
  28. package/dist/utils.js +1 -3
  29. package/package.json +24 -30
  30. package/dist/chunk-4QMHDKCS.js +0 -453
  31. package/dist/chunk-4QMHDKCS.js.map +0 -1
  32. package/dist/chunk-6LDDO2JJ.cjs +0 -184
  33. package/dist/chunk-6LDDO2JJ.cjs.map +0 -1
  34. package/dist/chunk-FYI4GRXP.cjs +0 -460
  35. package/dist/chunk-FYI4GRXP.cjs.map +0 -1
  36. package/dist/chunk-I74P26CO.js +0 -181
  37. package/dist/chunk-I74P26CO.js.map +0 -1
  38. package/dist/components.cjs.map +0 -1
  39. package/dist/components.js.map +0 -1
  40. package/dist/generators.cjs.map +0 -1
  41. package/dist/generators.js.map +0 -1
  42. package/dist/types-BOF1ntMm.d.cts +0 -130
  43. package/dist/types-BOF1ntMm.d.ts +0 -130
  44. package/dist/utils.cjs.map +0 -1
  45. package/dist/utils.js.map +0 -1
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.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
- "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
+ "./package.json": "./package.json"
50
45
  },
51
- "main": "dist/index.cjs",
52
- "module": "dist/index.js",
53
- "types": "./dist/index.d.ts",
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.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"
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
- "tsup": "^8.5.0",
79
+ "tsdown": "^0.14.1",
85
80
  "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"
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": "tsup",
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": "tsup --watch",
101
+ "start": "tsdown --watch",
108
102
  "test": "vitest --passWithNoTests",
109
103
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
110
104
  }
@@ -1,453 +0,0 @@
1
- import { File, Const, Type } from '@kubb/react';
2
- import transformers2 from '@kubb/core/transformers';
3
- import { jsxs, Fragment, jsx } from '@kubb/react/jsx-runtime';
4
- import { SchemaGenerator, schemaKeywords, isKeyword } from '@kubb/plugin-oas';
5
-
6
- // src/components/Operations.tsx
7
- function Operations({ name, operations }) {
8
- const operationsJSON = operations.reduce(
9
- (prev, acc) => {
10
- prev[`"${acc.operation.getOperationId()}"`] = acc.data;
11
- return prev;
12
- },
13
- {}
14
- );
15
- const pathsJSON = operations.reduce(
16
- (prev, acc) => {
17
- prev[`"${acc.operation.path}"`] = {
18
- ...prev[`"${acc.operation.path}"`] || {},
19
- [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
20
- };
21
- return prev;
22
- },
23
- {}
24
- );
25
- return /* @__PURE__ */ jsxs(Fragment, { children: [
26
- /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name, asConst: true, children: `{${transformers2.stringifyObject(operationsJSON)}}` }) }),
27
- /* @__PURE__ */ jsx(File.Source, { name: "paths", isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: "paths", asConst: true, children: `{${transformers2.stringifyObject(pathsJSON)}}` }) })
28
- ] });
29
- }
30
- var zodKeywordMapper = {
31
- any: () => "z.any()",
32
- unknown: () => "z.unknown()",
33
- void: () => "z.void()",
34
- number: (coercion, min, max) => {
35
- return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
36
- },
37
- integer: (coercion, min, max, version = "3") => {
38
- return [
39
- coercion ? "z.coerce.number().int()" : version === "4" ? "z.int()" : "z.number().int()",
40
- min !== void 0 ? `.min(${min})` : void 0,
41
- max !== void 0 ? `.max(${max})` : void 0
42
- ].filter(Boolean).join("");
43
- },
44
- interface: (value, strict) => {
45
- if (strict) {
46
- return `z.strictInterface({
47
- ${value}
48
- })`;
49
- }
50
- return `z.interface({
51
- ${value}
52
- })`;
53
- },
54
- object: (value, strict, version = "3") => {
55
- if (version === "4" && strict) {
56
- return `z.strictObject({
57
- ${value}
58
- })`;
59
- }
60
- if (strict) {
61
- return `z.object({
62
- ${value}
63
- }).strict()`;
64
- }
65
- return `z.object({
66
- ${value}
67
- })`;
68
- },
69
- string: (coercion, min, max) => {
70
- return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
71
- },
72
- //support for discriminatedUnion
73
- boolean: () => "z.boolean()",
74
- undefined: () => "z.undefined()",
75
- nullable: () => ".nullable()",
76
- null: () => "z.null()",
77
- nullish: () => ".nullish()",
78
- array: (items = [], min, max, unique) => {
79
- return [
80
- `z.array(${items?.join("")})`,
81
- min !== void 0 ? `.min(${min})` : void 0,
82
- max !== void 0 ? `.max(${max})` : void 0,
83
- unique ? `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : void 0
84
- ].filter(Boolean).join("");
85
- },
86
- tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
87
- enum: (items = []) => `z.enum([${items?.join(", ")}])`,
88
- union: (items = []) => `z.union([${items?.join(", ")}])`,
89
- const: (value) => `z.literal(${value ?? ""})`,
90
- /**
91
- * ISO 8601
92
- */
93
- datetime: (offset = false, local = false, version = "3") => {
94
- if (offset) {
95
- return version === "4" ? `z.iso.datetime({ offset: ${offset} })` : `z.string().datetime({ offset: ${offset} })`;
96
- }
97
- if (local) {
98
- return version === "4" ? `z.iso.datetime({ local: ${local} })` : `z.string().datetime({ local: ${local} })`;
99
- }
100
- return "z.string().datetime()";
101
- },
102
- /**
103
- * Type `'date'` Date
104
- * Type `'string'` ISO date format (YYYY-MM-DD)
105
- * @default ISO date format (YYYY-MM-DD)
106
- */
107
- date: (type = "string", coercion, version = "3") => {
108
- if (type === "string") {
109
- return version === "4" ? "z.iso.date()" : "z.string().date()";
110
- }
111
- if (coercion) {
112
- return "z.coerce.date()";
113
- }
114
- return "z.date()";
115
- },
116
- /**
117
- * Type `'date'` Date
118
- * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
119
- * @default ISO time format (HH:mm:ss[.SSSSSS])
120
- */
121
- time: (type = "string", coercion, version = "3") => {
122
- if (type === "string") {
123
- return version === "4" ? "z.iso.time()" : "z.string().time()";
124
- }
125
- if (coercion) {
126
- return "z.coerce.date()";
127
- }
128
- return "z.date()";
129
- },
130
- uuid: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().uuid()" : "z.uuid()" : coercion ? "z.coerce.string().uuid()" : "z.string().uuid()",
131
- url: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().url()" : "z.url()" : coercion ? "z.coerce.string().url()" : "z.string().url()",
132
- default: (value) => {
133
- if (typeof value === "object") {
134
- return ".default({})";
135
- }
136
- return `.default(${value ?? ""})`;
137
- },
138
- and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
139
- describe: (value = "") => `.describe(${value})`,
140
- min: (value) => `.min(${value ?? ""})`,
141
- max: (value) => `.max(${value ?? ""})`,
142
- optional: () => ".optional()",
143
- matches: (value = "", coercion) => coercion ? `z.coerce.string().regex(${value})` : `z.string().regex(${value})`,
144
- email: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().email()" : "z.email()" : coercion ? "z.coerce.string().email()" : "z.string().email()",
145
- firstName: void 0,
146
- lastName: void 0,
147
- password: void 0,
148
- phone: void 0,
149
- readOnly: void 0,
150
- writeOnly: void 0,
151
- ref: (value, version = "3") => {
152
- if (!value) {
153
- return void 0;
154
- }
155
- return version === "4" ? value : `z.lazy(() => ${value})`;
156
- },
157
- blob: () => "z.instanceof(File)",
158
- deprecated: void 0,
159
- example: void 0,
160
- schema: void 0,
161
- catchall: (value) => value ? `.catchall(${value})` : void 0,
162
- name: void 0
163
- };
164
- function sort(items) {
165
- const order = [
166
- schemaKeywords.string,
167
- schemaKeywords.datetime,
168
- schemaKeywords.date,
169
- schemaKeywords.time,
170
- schemaKeywords.tuple,
171
- schemaKeywords.number,
172
- schemaKeywords.object,
173
- schemaKeywords.enum,
174
- schemaKeywords.url,
175
- schemaKeywords.email,
176
- schemaKeywords.firstName,
177
- schemaKeywords.lastName,
178
- schemaKeywords.password,
179
- schemaKeywords.matches,
180
- schemaKeywords.uuid,
181
- schemaKeywords.null,
182
- schemaKeywords.min,
183
- schemaKeywords.max,
184
- schemaKeywords.default,
185
- schemaKeywords.describe,
186
- schemaKeywords.optional,
187
- schemaKeywords.nullable,
188
- schemaKeywords.nullish
189
- ];
190
- if (!items) {
191
- return [];
192
- }
193
- return transformers2.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
194
- }
195
- var shouldCoerce = (coercion, type) => {
196
- if (coercion === void 0) {
197
- return false;
198
- }
199
- if (typeof coercion === "boolean") {
200
- return coercion;
201
- }
202
- return !!coercion[type];
203
- };
204
- function parse({ parent, current, name, siblings }, options) {
205
- const value = zodKeywordMapper[current.keyword];
206
- const hasMatches = siblings.some((it) => isKeyword(it, schemaKeywords.matches));
207
- const hasRef = siblings.some((it) => isKeyword(it, schemaKeywords.ref));
208
- if (hasMatches && hasRef && isKeyword(current, schemaKeywords.matches)) {
209
- return void 0;
210
- }
211
- if (!value) {
212
- return void 0;
213
- }
214
- if (isKeyword(current, schemaKeywords.union)) {
215
- if (Array.isArray(current.args) && current.args.length === 1) {
216
- return parse({ parent, name, current: current.args[0], siblings }, options);
217
- }
218
- if (Array.isArray(current.args) && !current.args.length) {
219
- return "";
220
- }
221
- return zodKeywordMapper.union(
222
- sort(current.args).map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean)
223
- );
224
- }
225
- if (isKeyword(current, schemaKeywords.and)) {
226
- const items = sort(current.args).filter((schema) => {
227
- return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword);
228
- }).map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean);
229
- return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
230
- }
231
- if (isKeyword(current, schemaKeywords.array)) {
232
- return zodKeywordMapper.array(
233
- sort(current.args.items).map((schemas, _index, siblings2) => parse({ parent: current, name, current: schemas, siblings: siblings2 }, options)).filter(Boolean),
234
- current.args.min,
235
- current.args.max,
236
- current.args.unique
237
- );
238
- }
239
- if (isKeyword(current, schemaKeywords.enum)) {
240
- if (current.args.asConst) {
241
- if (current.args.items.length === 1) {
242
- const child = {
243
- keyword: schemaKeywords.const,
244
- args: current.args.items[0]
245
- };
246
- return parse({ parent: current, name, current: child, siblings: [child] }, options);
247
- }
248
- return zodKeywordMapper.union(
249
- current.args.items.map((schema) => ({
250
- keyword: schemaKeywords.const,
251
- args: schema
252
- })).map((schema, _index, siblings2) => {
253
- return parse({ parent: current, name, current: schema, siblings: siblings2 }, options);
254
- }).filter(Boolean)
255
- );
256
- }
257
- return zodKeywordMapper.enum(
258
- current.args.items.map((schema) => {
259
- if (schema.format === "boolean") {
260
- return transformers2.stringify(schema.value);
261
- }
262
- if (schema.format === "number") {
263
- return transformers2.stringify(schema.value);
264
- }
265
- return transformers2.stringify(schema.value);
266
- })
267
- );
268
- }
269
- if (isKeyword(current, schemaKeywords.ref)) {
270
- return zodKeywordMapper.ref(current.args?.name, options.version);
271
- }
272
- if (isKeyword(current, schemaKeywords.object)) {
273
- const propertyEntries = Object.entries(current.args?.properties || {}).filter((item) => {
274
- const schema = item[1];
275
- return schema && typeof schema.map === "function";
276
- });
277
- const properties = propertyEntries.map(([name2, schemas]) => {
278
- const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
279
- const mappedName = nameSchema?.args || name2;
280
- if (options.mapper?.[mappedName]) {
281
- return `"${name2}": ${options.mapper?.[mappedName]}`;
282
- }
283
- const baseSchemaOutput = sort(schemas).map((schema) => parse({ parent: current, name: name2, current: schema, siblings: schemas }, options)).filter(Boolean).join("");
284
- const objectValue = options.wrapOutput ? options.wrapOutput({ output: baseSchemaOutput, schema: options.rawSchema?.properties?.[name2] }) || baseSchemaOutput : baseSchemaOutput;
285
- if (options.version === "4" && SchemaGenerator.find(schemas, schemaKeywords.ref)) {
286
- return `get ${name2}(){
287
- return ${objectValue}
288
- }`;
289
- }
290
- return `"${name2}": ${objectValue}`;
291
- }).join(",\n");
292
- const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean).join("") : void 0;
293
- const text = [
294
- zodKeywordMapper.object(properties, current.args?.strict, options.version),
295
- additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
296
- ].filter(Boolean);
297
- return text.join("");
298
- }
299
- if (isKeyword(current, schemaKeywords.tuple)) {
300
- return zodKeywordMapper.tuple(
301
- current.args.items.map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean)
302
- );
303
- }
304
- if (isKeyword(current, schemaKeywords.const)) {
305
- if (current.args.format === "number" && current.args.value !== void 0) {
306
- return zodKeywordMapper.const(Number(current.args.value));
307
- }
308
- if (current.args.format === "boolean" && current.args.value !== void 0) {
309
- return zodKeywordMapper.const(current.args.value);
310
- }
311
- return zodKeywordMapper.const(transformers2.stringify(current.args.value));
312
- }
313
- if (isKeyword(current, schemaKeywords.matches)) {
314
- if (current.args) {
315
- return zodKeywordMapper.matches(transformers2.toRegExpString(current.args, null), shouldCoerce(options.coercion, "strings"));
316
- }
317
- }
318
- if (isKeyword(current, schemaKeywords.default)) {
319
- if (current.args) {
320
- return zodKeywordMapper.default(current.args);
321
- }
322
- }
323
- if (isKeyword(current, schemaKeywords.describe)) {
324
- if (current.args) {
325
- return zodKeywordMapper.describe(transformers2.stringify(current.args.toString()));
326
- }
327
- }
328
- if (isKeyword(current, schemaKeywords.string)) {
329
- return zodKeywordMapper.string(shouldCoerce(options.coercion, "strings"));
330
- }
331
- if (isKeyword(current, schemaKeywords.uuid)) {
332
- return zodKeywordMapper.uuid(shouldCoerce(options.coercion, "strings"), options.version);
333
- }
334
- if (isKeyword(current, schemaKeywords.email)) {
335
- return zodKeywordMapper.email(shouldCoerce(options.coercion, "strings"), options.version);
336
- }
337
- if (isKeyword(current, schemaKeywords.url)) {
338
- return zodKeywordMapper.url(shouldCoerce(options.coercion, "strings"), options.version);
339
- }
340
- if (isKeyword(current, schemaKeywords.number)) {
341
- return zodKeywordMapper.number(shouldCoerce(options.coercion, "numbers"));
342
- }
343
- if (isKeyword(current, schemaKeywords.integer)) {
344
- return zodKeywordMapper.integer(shouldCoerce(options.coercion, "numbers"), void 0, void 0, options.version);
345
- }
346
- if (isKeyword(current, schemaKeywords.min)) {
347
- return zodKeywordMapper.min(current.args);
348
- }
349
- if (isKeyword(current, schemaKeywords.max)) {
350
- return zodKeywordMapper.max(current.args);
351
- }
352
- if (isKeyword(current, schemaKeywords.datetime)) {
353
- return zodKeywordMapper.datetime(current.args.offset, current.args.local, options.version);
354
- }
355
- if (isKeyword(current, schemaKeywords.date)) {
356
- return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
357
- }
358
- if (isKeyword(current, schemaKeywords.time)) {
359
- return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
360
- }
361
- if (current.keyword in zodKeywordMapper && "args" in current) {
362
- const value2 = zodKeywordMapper[current.keyword];
363
- return value2(current.args);
364
- }
365
- if (isKeyword(current, schemaKeywords.optional)) {
366
- if (siblings.some((schema) => isKeyword(schema, schemaKeywords.default))) return "";
367
- return value();
368
- }
369
- if (current.keyword in zodKeywordMapper) {
370
- return value();
371
- }
372
- return void 0;
373
- }
374
- function Zod({
375
- name,
376
- typeName,
377
- tree,
378
- rawSchema,
379
- inferTypeName,
380
- mapper,
381
- coercion,
382
- keysToOmit,
383
- description,
384
- wrapOutput,
385
- version,
386
- emptySchemaType
387
- }) {
388
- const hasTuple = !!SchemaGenerator.deepSearch(tree, schemaKeywords.tuple);
389
- const schemas = sort(tree).filter((item) => {
390
- if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
391
- return false;
392
- }
393
- return true;
394
- });
395
- const output = schemas.map(
396
- (schema, _index, siblings) => parse(
397
- { parent: void 0, current: schema, siblings },
398
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version }
399
- )
400
- ).filter(Boolean).join("");
401
- let suffix = "";
402
- const firstSchema = schemas.at(0);
403
- const lastSchema = schemas.at(-1);
404
- if (lastSchema && isKeyword(lastSchema, schemaKeywords.nullable)) {
405
- if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) {
406
- if (version === "3") {
407
- suffix = ".unwrap().schema.unwrap()";
408
- } else {
409
- suffix = ".unwrap().unwrap()";
410
- }
411
- } else {
412
- suffix = ".unwrap()";
413
- }
414
- } else {
415
- if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref) && version === "3") {
416
- suffix = ".schema";
417
- }
418
- }
419
- const emptyValue = parse(
420
- {
421
- parent: void 0,
422
- current: {
423
- keyword: schemaKeywords[emptySchemaType]
424
- },
425
- siblings: []
426
- },
427
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version }
428
- );
429
- const baseSchemaOutput = [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `${key}: true`).join(",")} })` : void 0].filter(Boolean).join("") || emptyValue || "";
430
- const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema: rawSchema }) || baseSchemaOutput : baseSchemaOutput;
431
- const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ToZod<${typeName}>` : wrappedSchemaOutput;
432
- return /* @__PURE__ */ jsxs(Fragment, { children: [
433
- /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
434
- Const,
435
- {
436
- export: true,
437
- name,
438
- JSDoc: {
439
- comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
440
- },
441
- children: finalOutput
442
- }
443
- ) }),
444
- inferTypeName && /* @__PURE__ */ jsxs(File.Source, { name: inferTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: [
445
- typeName && /* @__PURE__ */ jsx(Type, { export: true, name: inferTypeName, children: typeName }),
446
- !typeName && /* @__PURE__ */ jsx(Type, { export: true, name: inferTypeName, children: `z.infer<typeof ${name}>` })
447
- ] })
448
- ] });
449
- }
450
-
451
- export { Operations, Zod };
452
- //# sourceMappingURL=chunk-4QMHDKCS.js.map
453
- //# sourceMappingURL=chunk-4QMHDKCS.js.map