@kubb/plugin-zod 5.0.0-beta.80 → 5.0.0-beta.84

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
2
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "kubb/kit";
3
3
  import { AdapterOas } from "@kubb/adapter-oas";
4
4
 
5
5
  //#region ../../internals/shared/src/operation.d.ts
@@ -55,7 +55,8 @@ type OperationParamsResolver = {
55
55
  *
56
56
  * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
57
57
  * replaces the built-in handler for that node type. Use `this.transform` to
58
- * recurse into nested schema nodes, and `this.options` to read printer options.
58
+ * recurse into nested schema nodes, `this.base` to reuse the output of the
59
+ * handler being replaced, and `this.options` to read printer options.
59
60
  *
60
61
  * @example Override the `date` handler
61
62
  * ```ts
@@ -63,7 +64,20 @@ type OperationParamsResolver = {
63
64
  * printer: {
64
65
  * nodes: {
65
66
  * date(node) {
66
- * return 'z.string().date()'
67
+ * return 'z.iso.date()'
68
+ * },
69
+ * },
70
+ * },
71
+ * })
72
+ * ```
73
+ *
74
+ * @example Wrap the built-in output
75
+ * ```ts
76
+ * pluginZod({
77
+ * printer: {
78
+ * nodes: {
79
+ * object(node) {
80
+ * return `${this.base(node)}.openapi(${JSON.stringify({ description: node.description })})`
67
81
  * },
68
82
  * },
69
83
  * },
@@ -93,10 +107,6 @@ type PrinterZodOptions = {
93
107
  * Date format in the OpenAPI spec (`'date'` or `'date-time'`).
94
108
  */
95
109
  dateType?: AdapterOas['resolvedOptions']['dateType'];
96
- /**
97
- * Hook to transform generated Zod schema before output.
98
- */
99
- wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
100
110
  /**
101
111
  * Transforms raw schema names into valid JavaScript identifiers.
102
112
  */
@@ -112,8 +122,8 @@ type PrinterZodOptions = {
112
122
  cyclicSchemas?: ReadonlySet<string>;
113
123
  /**
114
124
  * Print direction for `dateType: 'date'` fields (`Date` in TypeScript):
115
- * - `'output'` (default) decode the wire `string` into a `Date` (response bodies).
116
- * - `'input'` encode a `Date` back into the wire `string` (request bodies/params).
125
+ * - `'output'` (default): decode the wire `string` into a `Date` (response bodies).
126
+ * - `'input'`: encode a `Date` back into the wire `string` (request bodies/params).
117
127
  *
118
128
  * Diverging the directions requires the generator to emit an `${name}InputSchema`
119
129
  * variant for each date-bearing component.
@@ -154,7 +164,8 @@ declare const printerZod: (options?: PrinterZodOptions | undefined) => ast.Print
154
164
  *
155
165
  * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
156
166
  * replaces the built-in handler for that node type. Use `this.transform` to
157
- * recurse into nested schema nodes, and `this.options` to read printer options.
167
+ * recurse into nested schema nodes, `this.base` to reuse the output of the
168
+ * handler being replaced, and `this.options` to read printer options.
158
169
  *
159
170
  * @example Override the `date` handler
160
171
  * ```ts
@@ -185,10 +196,6 @@ type PrinterZodMiniOptions = {
185
196
  * @default 'literal'
186
197
  */
187
198
  regexType?: PluginZod['resolvedOptions']['regexType'];
188
- /**
189
- * Hook to transform generated Zod schema before output.
190
- */
191
- wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
192
199
  /**
193
200
  * Transforms raw schema names into valid JavaScript identifiers.
194
201
  */
@@ -218,7 +225,7 @@ type PrinterZodMiniOptions = {
218
225
  */
219
226
  type PrinterZodMiniFactory = ast.PrinterFactoryOptions<'zod-mini', PrinterZodMiniOptions, string, string>;
220
227
  /**
221
- * Zod v4 **Mini** printer built with `definePrinter`.
228
+ * Zod v4 Mini printer built with `definePrinter`.
222
229
  *
223
230
  * Converts a `SchemaNode` AST into a Zod v4 code string using the functional API
224
231
  * (`z.optional(z.string())`) for improved tree-shaking. See {@link printerZod} for the chainable API.
@@ -350,12 +357,6 @@ type Options = OutputOptions & {
350
357
  * @default mini ? 'zod/mini' : 'zod'
351
358
  */
352
359
  importPath?: 'zod' | 'zod/mini' | (string & {});
353
- /**
354
- * Tie each Zod schema to its TypeScript type from `@kubb/plugin-ts`. Requires
355
- * `@kubb/plugin-ts` in the plugins list. TypeScript fails compilation when the
356
- * schema drifts from the type.
357
- */
358
- typed?: boolean;
359
360
  /**
360
361
  * Export a `z.infer<typeof schema>` type alias next to every generated schema.
361
362
  * Lets the Zod schema act as the single source of truth.
@@ -367,6 +368,10 @@ type Options = OutputOptions & {
367
368
  * - `true` coerces strings, numbers, and dates.
368
369
  * - Object form picks per-primitive coercion.
369
370
  *
371
+ * `dates` applies to fields typed as `Date` (adapter `dateType: 'date'`): they
372
+ * validate with `z.coerce.date()` instead of the string-to-Date codec. Fields
373
+ * kept as ISO strings (`z.iso.date()`, `z.iso.datetime()`) are never coerced.
374
+ *
370
375
  * @default false
371
376
  * @see https://zod.dev/?id=coercion-for-primitives
372
377
  */
@@ -377,16 +382,16 @@ type Options = OutputOptions & {
377
382
  };
378
383
  /**
379
384
  * Validator for `format: uuid` properties.
380
- * - `'uuid'` `z.uuid()`. Standard RFC 4122.
381
- * - `'guid'` `z.guid()`. Accepts Microsoft-style GUIDs.
385
+ * - `'uuid'`: `z.uuid()`. Standard RFC 4122.
386
+ * - `'guid'`: `z.guid()`. Accepts Microsoft-style GUIDs.
382
387
  *
383
388
  * @default 'uuid'
384
389
  */
385
390
  guidType?: 'uuid' | 'guid';
386
391
  /**
387
392
  * Output form for an OpenAPI `pattern` inside `.regex(...)`.
388
- * - `'literal'` a regex literal: `.regex(/^[a-z]+$/)`.
389
- * - `'constructor'` the `RegExp` constructor: `.regex(new RegExp("^[a-z]+$"))`.
393
+ * - `'literal'`: a regex literal, `.regex(/^[a-z]+$/)`.
394
+ * - `'constructor'`: the `RegExp` constructor, `.regex(new RegExp("^[a-z]+$"))`.
390
395
  *
391
396
  * @default 'literal'
392
397
  */
@@ -399,15 +404,6 @@ type Options = OutputOptions & {
399
404
  * @beta
400
405
  */
401
406
  mini?: boolean;
402
- /**
403
- * Wrap the generated Zod schema string with extra calls. Receives the raw output
404
- * and the originating `SchemaNode`. Useful for round-tripping OpenAPI metadata
405
- * back into Zod (e.g. `.openapi(...)`).
406
- */
407
- wrapOutput?: (arg: {
408
- output: string;
409
- schema: ast.SchemaNode;
410
- }) => string | undefined;
411
407
  /**
412
408
  * Override how schema and operation names are built. Methods you omit fall back
413
409
  * to the default `resolverZod`.
@@ -431,14 +427,12 @@ type ResolvedOptions = {
431
427
  include: Array<Include> | undefined;
432
428
  override: Array<Override<ResolvedOptions>>;
433
429
  group: Group | null;
434
- typed: NonNullable<Options['typed']>;
435
430
  inferred: NonNullable<Options['inferred']>;
436
431
  importPath: NonNullable<Options['importPath']>;
437
432
  coercion: NonNullable<Options['coercion']>;
438
433
  guidType: NonNullable<Options['guidType']>;
439
434
  regexType: NonNullable<Options['regexType']>;
440
435
  mini: NonNullable<Options['mini']>;
441
- wrapOutput: Options['wrapOutput'];
442
436
  printer: Options['printer'];
443
437
  };
444
438
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, ResolverZod>;
@@ -457,7 +451,7 @@ declare global {
457
451
  * When `mini: true`, schemas use the Zod Mini functional API instead of
458
452
  * chainable methods.
459
453
  */
460
- declare const zodGenerator: import("@kubb/core").Generator<PluginZod, unknown>;
454
+ declare const zodGenerator: import("kubb/kit").Generator<PluginZod, unknown>;
461
455
  //#endregion
462
456
  //#region src/plugin.d.ts
463
457
  /**
@@ -474,7 +468,7 @@ declare const pluginZodName = "plugin-zod";
474
468
  *
475
469
  * @example
476
470
  * ```ts
477
- * import { defineConfig } from 'kubb'
471
+ * import { defineConfig } from 'kubb/config'
478
472
  * import { pluginTs } from '@kubb/plugin-ts'
479
473
  * import { pluginZod } from '@kubb/plugin-zod'
480
474
  *
@@ -485,13 +479,13 @@ declare const pluginZodName = "plugin-zod";
485
479
  * pluginTs(),
486
480
  * pluginZod({
487
481
  * output: { path: './zod' },
488
- * typed: true,
482
+ * inferred: true,
489
483
  * }),
490
484
  * ],
491
485
  * })
492
486
  * ```
493
487
  */
494
- declare const pluginZod: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginZod>;
488
+ declare const pluginZod: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginZod>;
495
489
  //#endregion
496
490
  //#region src/resolvers/resolverZod.d.ts
497
491
  /**