@kubb/plugin-zod 5.0.0-alpha.25 → 5.0.0-alpha.27
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.cjs +175 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +165 -76
- package/dist/index.js +176 -192
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Zod.tsx +10 -9
- package/src/generators/zodGenerator.tsx +28 -52
- package/src/generators/zodGeneratorLegacy.tsx +27 -51
- package/src/index.ts +2 -1
- package/src/plugin.ts +9 -5
- package/src/presets.ts +7 -2
- package/src/printers/printerZod.ts +31 -4
- package/src/printers/printerZodMini.ts +32 -5
- package/src/resolvers/resolverZod.ts +12 -22
- package/src/resolvers/resolverZodLegacy.ts +8 -8
- package/src/types.ts +56 -17
- package/src/components/ZodMini.tsx +0 -41
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,118 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import * as _$_kubb_ast0 from "@kubb/ast";
|
|
2
3
|
import { OperationParamsResolver } from "@kubb/ast";
|
|
3
4
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
4
|
-
import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
|
|
5
|
+
import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, PrinterPartial, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
|
|
5
6
|
import { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
|
|
6
7
|
|
|
8
|
+
//#region src/printers/printerZod.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Partial map of node-type overrides for the Zod printer.
|
|
11
|
+
*
|
|
12
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
13
|
+
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
14
|
+
* recurse into nested schema nodes, and `this.options` to read printer options.
|
|
15
|
+
*
|
|
16
|
+
* @example Override the `date` handler
|
|
17
|
+
* ```ts
|
|
18
|
+
* pluginZod({
|
|
19
|
+
* printer: {
|
|
20
|
+
* nodes: {
|
|
21
|
+
* date(node) {
|
|
22
|
+
* return 'z.string().date()'
|
|
23
|
+
* },
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
type PrinterZodNodes = PrinterPartial<string, PrinterZodOptions>;
|
|
30
|
+
type PrinterZodOptions = {
|
|
31
|
+
coercion?: PluginZod['resolvedOptions']['coercion'];
|
|
32
|
+
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
33
|
+
wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
|
|
34
|
+
resolver?: ResolverZod;
|
|
35
|
+
schemaName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Property keys to exclude from the generated object schema via `.omit({ key: true })`.
|
|
38
|
+
*/
|
|
39
|
+
keysToOmit?: Array<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Partial map of node-type overrides. Each entry replaces the built-in handler for that node type.
|
|
42
|
+
*/
|
|
43
|
+
nodes?: PrinterZodNodes;
|
|
44
|
+
};
|
|
45
|
+
type PrinterZodFactory = PrinterFactoryOptions<'zod', PrinterZodOptions, string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Zod v4 printer built with `definePrinter`.
|
|
48
|
+
*
|
|
49
|
+
* Converts a `SchemaNode` AST into a **standard** Zod v4 code string
|
|
50
|
+
* using the chainable method API (`.optional()`, `.nullable()`, etc.).
|
|
51
|
+
*
|
|
52
|
+
* For the `zod/mini` functional API, see {@link printerZodMini}.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const printer = printerZod({ coercion: false })
|
|
57
|
+
* const code = printer.print(stringSchemaNode) // "z.string()"
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare const printerZod: (options?: PrinterZodOptions | undefined) => _$_kubb_ast0.Printer<PrinterZodFactory>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/printers/printerZodMini.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* Partial map of node-type overrides for the Zod Mini printer.
|
|
65
|
+
*
|
|
66
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
67
|
+
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
68
|
+
* recurse into nested schema nodes, and `this.options` to read printer options.
|
|
69
|
+
*
|
|
70
|
+
* @example Override the `date` handler
|
|
71
|
+
* ```ts
|
|
72
|
+
* pluginZod({
|
|
73
|
+
* mini: true,
|
|
74
|
+
* printer: {
|
|
75
|
+
* nodes: {
|
|
76
|
+
* date(node) {
|
|
77
|
+
* return 'z.iso.date()'
|
|
78
|
+
* },
|
|
79
|
+
* },
|
|
80
|
+
* },
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
type PrinterZodMiniNodes = PrinterPartial<string, PrinterZodMiniOptions>;
|
|
85
|
+
type PrinterZodMiniOptions = {
|
|
86
|
+
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
87
|
+
wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
|
|
88
|
+
resolver?: ResolverZod;
|
|
89
|
+
schemaName?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Property keys to exclude from the generated object schema via `.omit({ key: true })`.
|
|
92
|
+
*/
|
|
93
|
+
keysToOmit?: Array<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Partial map of node-type overrides. Each entry replaces the built-in handler for that node type.
|
|
96
|
+
*/
|
|
97
|
+
nodes?: PrinterZodMiniNodes;
|
|
98
|
+
};
|
|
99
|
+
type PrinterZodMiniFactory = PrinterFactoryOptions<'zod-mini', PrinterZodMiniOptions, string, string>;
|
|
100
|
+
/**
|
|
101
|
+
* Zod v4 **Mini** printer built with `definePrinter`.
|
|
102
|
+
*
|
|
103
|
+
* Converts a `SchemaNode` AST into a Zod v4 Mini code string using the
|
|
104
|
+
* functional API (`z.optional(z.string())`) for better tree-shaking.
|
|
105
|
+
*
|
|
106
|
+
* For the standard chainable API, see {@link printerZod}.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* const printer = printerZodMini({})
|
|
111
|
+
* const code = printer.print(optionalStringNode) // "z.optional(z.string())"
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare const printerZodMini: (options?: PrinterZodMiniOptions | undefined) => _$_kubb_ast0.Printer<PrinterZodMiniFactory>;
|
|
115
|
+
//#endregion
|
|
7
116
|
//#region src/types.d.ts
|
|
8
117
|
/**
|
|
9
118
|
* The concrete resolver type for `@kubb/plugin-zod`.
|
|
@@ -13,61 +122,73 @@ type ResolverZod = Resolver & OperationParamsResolver & {
|
|
|
13
122
|
/**
|
|
14
123
|
* Resolves a camelCase schema function name with a `Schema` suffix.
|
|
15
124
|
*/
|
|
16
|
-
|
|
125
|
+
resolveSchemaName(this: ResolverZod, name: string): string;
|
|
126
|
+
/**
|
|
127
|
+
* Resolves the name for a `z.infer<typeof ...>` type export.
|
|
128
|
+
* Strips the trailing `Schema` suffix (added by `resolveSchemaName`) before PascalCasing.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* resolver.resolveSchemaTypeName('pet) // → 'PetSchema'
|
|
132
|
+
* resolver.resolveSchemaTypeName('addPet200') // → 'AddPet200Schema'
|
|
133
|
+
* resolver.resolveSchemaTypeName('PetName') // → 'PetNameSchema'
|
|
134
|
+
*/
|
|
135
|
+
resolveSchemaTypeName(this: ResolverZod, name: string): string;
|
|
17
136
|
/**
|
|
18
|
-
* Resolves the name for a `z.infer<typeof ...>` type export
|
|
137
|
+
* Resolves the name for a `z.infer<typeof ...>` type export.
|
|
138
|
+
* Strips the trailing `Schema` suffix (added by `resolveSchemaName`) before PascalCasing.
|
|
19
139
|
*
|
|
20
140
|
* @example
|
|
21
|
-
* resolver.
|
|
22
|
-
* resolver.
|
|
141
|
+
* resolver.resolveTypeName('pet') // → 'Pet'
|
|
142
|
+
* resolver.resolveTypeName('addPet200') // → 'AddPet200'
|
|
143
|
+
* resolver.resolveTypeName('PetName') // → 'PetName'
|
|
23
144
|
*/
|
|
24
|
-
|
|
145
|
+
resolveTypeName(this: ResolverZod, name: string): string;
|
|
25
146
|
/**
|
|
26
147
|
* Resolves a PascalCase path/file name for the generated output.
|
|
27
148
|
*/
|
|
28
|
-
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
149
|
+
resolvePathName(this: ResolverZod, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
29
150
|
/**
|
|
30
151
|
* Resolves the name for an operation response by status code.
|
|
31
152
|
*
|
|
32
153
|
* @example
|
|
33
154
|
* resolver.resolveResponseStatusName(node, 200) // → 'listPetsStatus200Schema'
|
|
34
155
|
*/
|
|
35
|
-
resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string;
|
|
156
|
+
resolveResponseStatusName(this: ResolverZod, node: OperationNode, statusCode: StatusCode): string;
|
|
36
157
|
/**
|
|
37
158
|
* Resolves the name for the collection of all operation responses.
|
|
38
159
|
*
|
|
39
160
|
* @example
|
|
40
161
|
* resolver.resolveResponsesName(node) // → 'listPetsResponsesSchema'
|
|
41
162
|
*/
|
|
42
|
-
resolveResponsesName(node: OperationNode): string;
|
|
163
|
+
resolveResponsesName(this: ResolverZod, node: OperationNode): string;
|
|
43
164
|
/**
|
|
44
165
|
* Resolves the name for the union of all operation responses.
|
|
45
166
|
*
|
|
46
167
|
* @example
|
|
47
168
|
* resolver.resolveResponseName(node) // → 'listPetsResponseSchema'
|
|
48
169
|
*/
|
|
49
|
-
resolveResponseName(node: OperationNode): string;
|
|
170
|
+
resolveResponseName(this: ResolverZod, node: OperationNode): string;
|
|
50
171
|
/**
|
|
51
172
|
* Resolves the name for an operation's grouped path parameters type.
|
|
52
173
|
*
|
|
53
174
|
* @example
|
|
54
175
|
* resolver.resolvePathParamsName(node, param) // → 'deletePetPathPetIdSchema'
|
|
55
176
|
*/
|
|
56
|
-
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
177
|
+
resolvePathParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
|
|
57
178
|
/**
|
|
58
179
|
* Resolves the name for an operation's grouped query parameters type.
|
|
59
180
|
*
|
|
60
181
|
* @example
|
|
61
182
|
* resolver.resolveQueryParamsName(node, param) // → 'findPetsByStatusQueryStatusSchema'
|
|
62
183
|
*/
|
|
63
|
-
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
184
|
+
resolveQueryParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
|
|
64
185
|
/**
|
|
65
186
|
* Resolves the name for an operation's grouped header parameters type.
|
|
66
187
|
*
|
|
67
188
|
* @example
|
|
68
189
|
* resolver.resolveHeaderParamsName(node, param) // → 'deletePetHeaderApiKeySchema'
|
|
69
190
|
*/
|
|
70
|
-
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
191
|
+
resolveHeaderParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
|
|
71
192
|
};
|
|
72
193
|
type Options = {
|
|
73
194
|
/**
|
|
@@ -169,13 +290,38 @@ type Options = {
|
|
|
169
290
|
*/
|
|
170
291
|
compatibilityPreset?: CompatibilityPreset;
|
|
171
292
|
/**
|
|
172
|
-
*
|
|
293
|
+
* A single resolver whose methods override the default resolver's naming conventions.
|
|
294
|
+
* When a method returns `null` or `undefined`, the default resolver's result is used instead.
|
|
173
295
|
*/
|
|
174
|
-
|
|
296
|
+
resolver?: Partial<ResolverZod> & ThisType<ResolverZod>;
|
|
175
297
|
/**
|
|
176
|
-
*
|
|
298
|
+
* Override individual printer node handlers to customise rendering of specific schema types.
|
|
299
|
+
*
|
|
300
|
+
* Each key is a `SchemaType` (e.g. `'date'`, `'string'`). The function replaces the
|
|
301
|
+
* built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
|
|
302
|
+
* When `mini: true`, the overrides apply to the Zod Mini printer.
|
|
303
|
+
*
|
|
304
|
+
* @example Override the `date` node to use `z.string().date()`
|
|
305
|
+
* ```ts
|
|
306
|
+
* pluginZod({
|
|
307
|
+
* printer: {
|
|
308
|
+
* nodes: {
|
|
309
|
+
* date(node) {
|
|
310
|
+
* return 'z.string().date()'
|
|
311
|
+
* },
|
|
312
|
+
* },
|
|
313
|
+
* },
|
|
314
|
+
* })
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
printer?: {
|
|
318
|
+
nodes?: PrinterZodNodes | PrinterZodMiniNodes;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* A single AST visitor applied to each SchemaNode/OperationNode before printing.
|
|
322
|
+
* When a visitor method returns `null` or `undefined`, the preset transformer's result is used instead.
|
|
177
323
|
*/
|
|
178
|
-
|
|
324
|
+
transformer?: Visitor;
|
|
179
325
|
};
|
|
180
326
|
type ResolvedOptions = {
|
|
181
327
|
output: Output;
|
|
@@ -190,7 +336,7 @@ type ResolvedOptions = {
|
|
|
190
336
|
mini: NonNullable<Options['mini']>;
|
|
191
337
|
wrapOutput: Options['wrapOutput'];
|
|
192
338
|
paramsCasing: Options['paramsCasing'];
|
|
193
|
-
|
|
339
|
+
printer: Options['printer'];
|
|
194
340
|
};
|
|
195
341
|
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions, ResolverZod>;
|
|
196
342
|
//#endregion
|
|
@@ -223,63 +369,6 @@ declare const pluginZodName = "plugin-zod";
|
|
|
223
369
|
*/
|
|
224
370
|
declare const pluginZod: (options?: Options | undefined) => _$_kubb_core0.UserPluginWithLifeCycle<PluginZod>;
|
|
225
371
|
//#endregion
|
|
226
|
-
//#region src/printers/printerZod.d.ts
|
|
227
|
-
type ZodOptions = {
|
|
228
|
-
coercion?: PluginZod['resolvedOptions']['coercion'];
|
|
229
|
-
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
230
|
-
wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
|
|
231
|
-
resolver?: ResolverZod;
|
|
232
|
-
schemaName?: string;
|
|
233
|
-
/**
|
|
234
|
-
* Property keys to exclude from the generated object schema via `.omit({ key: true })`.
|
|
235
|
-
*/
|
|
236
|
-
keysToOmit?: Array<string>;
|
|
237
|
-
};
|
|
238
|
-
type ZodPrinterFactory = PrinterFactoryOptions<'zod', ZodOptions, string, string>;
|
|
239
|
-
/**
|
|
240
|
-
* Zod v4 printer built with `definePrinter`.
|
|
241
|
-
*
|
|
242
|
-
* Converts a `SchemaNode` AST into a **standard** Zod v4 code string
|
|
243
|
-
* using the chainable method API (`.optional()`, `.nullable()`, etc.).
|
|
244
|
-
*
|
|
245
|
-
* For the `zod/mini` functional API, see {@link printerZodMini}.
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* ```ts
|
|
249
|
-
* const printer = printerZod({ coercion: false })
|
|
250
|
-
* const code = printer.print(stringSchemaNode) // "z.string()"
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
declare const printerZod: (options?: ZodOptions | undefined) => _$_kubb_core0.Printer<ZodPrinterFactory>;
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/printers/printerZodMini.d.ts
|
|
256
|
-
type ZodMiniOptions = {
|
|
257
|
-
guidType?: PluginZod['resolvedOptions']['guidType'];
|
|
258
|
-
wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
|
|
259
|
-
resolver?: ResolverZod;
|
|
260
|
-
schemaName?: string;
|
|
261
|
-
/**
|
|
262
|
-
* Property keys to exclude from the generated object schema via `.omit({ key: true })`.
|
|
263
|
-
*/
|
|
264
|
-
keysToOmit?: Array<string>;
|
|
265
|
-
};
|
|
266
|
-
type ZodMiniPrinterFactory = PrinterFactoryOptions<'zod-mini', ZodMiniOptions, string, string>;
|
|
267
|
-
/**
|
|
268
|
-
* Zod v4 **Mini** printer built with `definePrinter`.
|
|
269
|
-
*
|
|
270
|
-
* Converts a `SchemaNode` AST into a Zod v4 Mini code string using the
|
|
271
|
-
* functional API (`z.optional(z.string())`) for better tree-shaking.
|
|
272
|
-
*
|
|
273
|
-
* For the standard chainable API, see {@link printerZod}.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```ts
|
|
277
|
-
* const printer = printerZodMini({})
|
|
278
|
-
* const code = printer.print(optionalStringNode) // "z.optional(z.string())"
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
declare const printerZodMini: (options?: ZodMiniOptions | undefined) => _$_kubb_core0.Printer<ZodMiniPrinterFactory>;
|
|
282
|
-
//#endregion
|
|
283
372
|
//#region src/resolvers/resolverZod.d.ts
|
|
284
373
|
/**
|
|
285
374
|
* Default resolver for `@kubb/plugin-zod`.
|
|
@@ -321,5 +410,5 @@ declare const resolverZod: ResolverZod;
|
|
|
321
410
|
*/
|
|
322
411
|
declare const resolverZodLegacy: ResolverZod;
|
|
323
412
|
//#endregion
|
|
324
|
-
export { type PluginZod, type ResolverZod, pluginZod, pluginZodName, printerZod, printerZodMini, resolverZod, resolverZodLegacy, zodGenerator, zodGeneratorLegacy };
|
|
413
|
+
export { type PluginZod, type PrinterZodFactory, type PrinterZodMiniFactory, type PrinterZodMiniNodes, type PrinterZodMiniOptions, type PrinterZodNodes, type PrinterZodOptions, type ResolverZod, pluginZod, pluginZodName, printerZod, printerZodMini, resolverZod, resolverZodLegacy, zodGenerator, zodGeneratorLegacy };
|
|
325
414
|
//# sourceMappingURL=index.d.ts.map
|