@kubb/plugin-zod 5.0.0-alpha.33 → 5.0.0-alpha.35

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,9 +1,6 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _$_kubb_ast0 from "@kubb/ast";
3
- import { OperationParamsResolver } from "@kubb/ast";
4
2
  import * as _$_kubb_core0 from "@kubb/core";
5
- import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, PrinterPartial, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
6
- import { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
3
+ import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, PrinterPartial, ResolvePathOptions, Resolver, UserGroup, ast } from "@kubb/core";
7
4
 
8
5
  //#region src/printers/printerZod.d.ts
9
6
  /**
@@ -57,7 +54,7 @@ type PrinterZodFactory = PrinterFactoryOptions<'zod', PrinterZodOptions, string,
57
54
  * const code = printer.print(stringSchemaNode) // "z.string()"
58
55
  * ```
59
56
  */
60
- declare const printerZod: (options?: PrinterZodOptions | undefined) => _$_kubb_ast0.Printer<PrinterZodFactory>;
57
+ declare const printerZod: (options?: any) => ast.Printer<PrinterFactoryOptions<"zod", PrinterZodOptions, string, string>>;
61
58
  //#endregion
62
59
  //#region src/printers/printerZodMini.d.ts
63
60
  /**
@@ -111,14 +108,14 @@ type PrinterZodMiniFactory = PrinterFactoryOptions<'zod-mini', PrinterZodMiniOpt
111
108
  * const code = printer.print(optionalStringNode) // "z.optional(z.string())"
112
109
  * ```
113
110
  */
114
- declare const printerZodMini: (options?: PrinterZodMiniOptions | undefined) => _$_kubb_ast0.Printer<PrinterZodMiniFactory>;
111
+ declare const printerZodMini: (options?: any) => ast.Printer<PrinterFactoryOptions<"zod-mini", PrinterZodMiniOptions, string, string>>;
115
112
  //#endregion
116
113
  //#region src/types.d.ts
117
114
  /**
118
115
  * The concrete resolver type for `@kubb/plugin-zod`.
119
116
  * Extends the base `Resolver` with zod-specific naming helpers.
120
117
  */
121
- type ResolverZod = Resolver & OperationParamsResolver & {
118
+ type ResolverZod = Resolver & ast.OperationParamsResolver & {
122
119
  /**
123
120
  * Resolves a camelCase schema function name with a `Schema` suffix.
124
121
  */
@@ -153,42 +150,42 @@ type ResolverZod = Resolver & OperationParamsResolver & {
153
150
  * @example
154
151
  * resolver.resolveResponseStatusName(node, 200) // → 'listPetsStatus200Schema'
155
152
  */
156
- resolveResponseStatusName(this: ResolverZod, node: OperationNode, statusCode: StatusCode): string;
153
+ resolveResponseStatusName(this: ResolverZod, node: ast.OperationNode, statusCode: ast.StatusCode): string;
157
154
  /**
158
155
  * Resolves the name for the collection of all operation responses.
159
156
  *
160
157
  * @example
161
158
  * resolver.resolveResponsesName(node) // → 'listPetsResponsesSchema'
162
159
  */
163
- resolveResponsesName(this: ResolverZod, node: OperationNode): string;
160
+ resolveResponsesName(this: ResolverZod, node: ast.OperationNode): string;
164
161
  /**
165
162
  * Resolves the name for the union of all operation responses.
166
163
  *
167
164
  * @example
168
165
  * resolver.resolveResponseName(node) // → 'listPetsResponseSchema'
169
166
  */
170
- resolveResponseName(this: ResolverZod, node: OperationNode): string;
167
+ resolveResponseName(this: ResolverZod, node: ast.OperationNode): string;
171
168
  /**
172
169
  * Resolves the name for an operation's grouped path parameters type.
173
170
  *
174
171
  * @example
175
172
  * resolver.resolvePathParamsName(node, param) // → 'deletePetPathPetIdSchema'
176
173
  */
177
- resolvePathParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
174
+ resolvePathParamsName(this: ResolverZod, node: ast.OperationNode, param: ast.ParameterNode): string;
178
175
  /**
179
176
  * Resolves the name for an operation's grouped query parameters type.
180
177
  *
181
178
  * @example
182
179
  * resolver.resolveQueryParamsName(node, param) // → 'findPetsByStatusQueryStatusSchema'
183
180
  */
184
- resolveQueryParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
181
+ resolveQueryParamsName(this: ResolverZod, node: ast.OperationNode, param: ast.ParameterNode): string;
185
182
  /**
186
183
  * Resolves the name for an operation's grouped header parameters type.
187
184
  *
188
185
  * @example
189
186
  * resolver.resolveHeaderParamsName(node, param) // → 'deletePetHeaderApiKeySchema'
190
187
  */
191
- resolveHeaderParamsName(this: ResolverZod, node: OperationNode, param: ParameterNode): string;
188
+ resolveHeaderParamsName(this: ResolverZod, node: ast.OperationNode, param: ast.ParameterNode): string;
192
189
  };
193
190
  type Options = {
194
191
  /**
@@ -273,7 +270,7 @@ type Options = {
273
270
  */
274
271
  wrapOutput?: (arg: {
275
272
  output: string;
276
- schema: SchemaNode;
273
+ schema: ast.SchemaNode;
277
274
  }) => string | undefined;
278
275
  /**
279
276
  * How to style your params, by default no casing is applied
@@ -321,7 +318,7 @@ type Options = {
321
318
  * A single AST visitor applied to each SchemaNode/OperationNode before printing.
322
319
  * When a visitor method returns `null` or `undefined`, the preset transformer's result is used instead.
323
320
  */
324
- transformer?: Visitor;
321
+ transformer?: ast.Visitor;
325
322
  };
326
323
  type ResolvedOptions = {
327
324
  output: Output;
@@ -351,10 +348,10 @@ declare global {
351
348
  }
352
349
  //#endregion
353
350
  //#region src/generators/zodGenerator.d.ts
354
- declare const zodGenerator: _$_kubb_core0.Generator<PluginZod>;
351
+ declare const zodGenerator: _$_kubb_core0.Generator<PluginZod, unknown>;
355
352
  //#endregion
356
353
  //#region src/generators/zodGeneratorLegacy.d.ts
357
- declare const zodGeneratorLegacy: _$_kubb_core0.Generator<PluginZod>;
354
+ declare const zodGeneratorLegacy: _$_kubb_core0.Generator<PluginZod, unknown>;
358
355
  //#endregion
359
356
  //#region src/plugin.d.ts
360
357
  /**
@@ -377,7 +374,7 @@ declare const pluginZodName = "plugin-zod";
377
374
  * })
378
375
  * ```
379
376
  */
380
- declare const pluginZod: (options?: Options | undefined) => _$_kubb_core0.UserPluginWithLifeCycle<PluginZod>;
377
+ declare const pluginZod: (options?: Options | undefined) => _$_kubb_core0.HookStylePlugin<PluginZod>;
381
378
  //#endregion
382
379
  //#region src/resolvers/resolverZod.d.ts
383
380
  /**
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { caseParams, createProperty, createSchema, extractRefName, narrowSchema, syncSchemaRef } from "@kubb/ast";
3
- import { createPlugin, defineGenerator, definePresets, definePrinter, defineResolver, getPreset, mergeGenerators } from "@kubb/core";
4
- import { Const, File, Type } from "@kubb/renderer-jsx";
2
+ import { ast, defineGenerator, definePlugin, definePrinter, defineResolver } from "@kubb/core";
3
+ import { Const, File, Type, jsxRenderer } from "@kubb/renderer-jsx";
5
4
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
5
  //#region ../../internals/utils/src/casing.ts
7
6
  /**
@@ -372,7 +371,7 @@ function containsSelfRef(node, { schemaName, resolver, visited = /* @__PURE__ */
372
371
  if (visited.has(node)) return false;
373
372
  visited.add(node);
374
373
  if (node.type === "ref" && node.ref) {
375
- const rawName = extractRefName(node.ref) ?? node.name;
374
+ const rawName = ast.extractRefName(node.ref) ?? node.name;
376
375
  return (rawName ? resolver?.default(rawName, "function") ?? rawName : node.name) === schemaName;
377
376
  }
378
377
  if (node.type === "object") {
@@ -475,7 +474,7 @@ const printerZod = definePrinter((options) => {
475
474
  },
476
475
  ref(node) {
477
476
  if (!node.name) return void 0;
478
- const refName = node.ref ? extractRefName(node.ref) ?? node.name : node.name;
477
+ const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
479
478
  const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
480
479
  if (node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName) return `z.lazy(() => ${resolvedName})`;
481
480
  return resolvedName;
@@ -483,7 +482,7 @@ const printerZod = definePrinter((options) => {
483
482
  object(node) {
484
483
  let result = `z.object({\n ${node.properties.map((prop) => {
485
484
  const { name: propName, schema } = prop;
486
- const meta = syncSchemaRef(schema);
485
+ const meta = ast.syncSchemaRef(schema);
487
486
  const isNullable = meta.nullable;
488
487
  const isOptional = schema.optional;
489
488
  const isNullish = schema.nullish;
@@ -491,7 +490,7 @@ const printerZod = definePrinter((options) => {
491
490
  schemaName: this.options.schemaName,
492
491
  resolver: this.options.resolver
493
492
  });
494
- const baseOutput = this.transform(schema) ?? this.transform(createSchema({ type: "unknown" }));
493
+ const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: "unknown" }));
495
494
  const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName) : baseOutput;
496
495
  const value = applyModifiers({
497
496
  value: this.options.wrapOutput ? this.options.wrapOutput({
@@ -510,12 +509,12 @@ const printerZod = definePrinter((options) => {
510
509
  if (node.additionalProperties && node.additionalProperties !== true) {
511
510
  const catchallType = this.transform(node.additionalProperties);
512
511
  if (catchallType) result += `.catchall(${catchallType})`;
513
- } else if (node.additionalProperties === true) result += `.catchall(${this.transform(createSchema({ type: "unknown" }))})`;
512
+ } else if (node.additionalProperties === true) result += `.catchall(${this.transform(ast.createSchema({ type: "unknown" }))})`;
514
513
  else if (node.additionalProperties === false) result += ".strict()";
515
514
  return result;
516
515
  },
517
516
  array(node) {
518
- let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(createSchema({ type: "unknown" }))})${lengthConstraints(node)}`;
517
+ let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(ast.createSchema({ type: "unknown" }))})${lengthConstraints(node)}`;
519
518
  if (node.unique) result += `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })`;
520
519
  return result;
521
520
  },
@@ -539,19 +538,19 @@ const printerZod = definePrinter((options) => {
539
538
  if (!base) return "";
540
539
  for (const member of rest) {
541
540
  if (member.primitive === "string") {
542
- const c = lengthConstraints(narrowSchema(member, "string") ?? {});
541
+ const c = lengthConstraints(ast.narrowSchema(member, "string") ?? {});
543
542
  if (c) {
544
543
  base += c;
545
544
  continue;
546
545
  }
547
546
  } else if (member.primitive === "number" || member.primitive === "integer") {
548
- const c = numberConstraints(narrowSchema(member, "number") ?? narrowSchema(member, "integer") ?? {});
547
+ const c = numberConstraints(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {});
549
548
  if (c) {
550
549
  base += c;
551
550
  continue;
552
551
  }
553
552
  } else if (member.primitive === "array") {
554
- const c = lengthConstraints(narrowSchema(member, "array") ?? {});
553
+ const c = lengthConstraints(ast.narrowSchema(member, "array") ?? {});
555
554
  if (c) {
556
555
  base += c;
557
556
  continue;
@@ -568,7 +567,7 @@ const printerZod = definePrinter((options) => {
568
567
  const { keysToOmit } = this.options;
569
568
  let base = this.transform(node);
570
569
  if (!base) return null;
571
- const meta = syncSchemaRef(node);
570
+ const meta = ast.syncSchemaRef(node);
572
571
  if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
573
572
  return applyModifiers({
574
573
  value: base,
@@ -654,7 +653,7 @@ const printerZodMini = definePrinter((options) => {
654
653
  },
655
654
  ref(node) {
656
655
  if (!node.name) return void 0;
657
- const refName = node.ref ? extractRefName(node.ref) ?? node.name : node.name;
656
+ const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
658
657
  const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
659
658
  if (node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName) return `z.lazy(() => ${resolvedName})`;
660
659
  return resolvedName;
@@ -662,7 +661,7 @@ const printerZodMini = definePrinter((options) => {
662
661
  object(node) {
663
662
  return `z.object({\n ${node.properties.map((prop) => {
664
663
  const { name: propName, schema } = prop;
665
- const meta = syncSchemaRef(schema);
664
+ const meta = ast.syncSchemaRef(schema);
666
665
  const isNullable = meta.nullable;
667
666
  const isOptional = schema.optional;
668
667
  const isNullish = schema.nullish;
@@ -670,7 +669,7 @@ const printerZodMini = definePrinter((options) => {
670
669
  schemaName: this.options.schemaName,
671
670
  resolver: this.options.resolver
672
671
  });
673
- const baseOutput = this.transform(schema) ?? this.transform(createSchema({ type: "unknown" }));
672
+ const baseOutput = this.transform(schema) ?? this.transform(ast.createSchema({ type: "unknown" }));
674
673
  const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName) : baseOutput;
675
674
  const value = applyMiniModifiers({
676
675
  value: this.options.wrapOutput ? this.options.wrapOutput({
@@ -687,7 +686,7 @@ const printerZodMini = definePrinter((options) => {
687
686
  }).join(",\n ")}\n })`;
688
687
  },
689
688
  array(node) {
690
- let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(createSchema({ type: "unknown" }))})${lengthChecksMini(node)}`;
689
+ let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(ast.createSchema({ type: "unknown" }))})${lengthChecksMini(node)}`;
691
690
  if (node.unique) result += `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })`;
692
691
  return result;
693
692
  },
@@ -711,19 +710,19 @@ const printerZodMini = definePrinter((options) => {
711
710
  if (!base) return "";
712
711
  for (const member of rest) {
713
712
  if (member.primitive === "string") {
714
- const c = lengthChecksMini(narrowSchema(member, "string") ?? {});
713
+ const c = lengthChecksMini(ast.narrowSchema(member, "string") ?? {});
715
714
  if (c) {
716
715
  base += c;
717
716
  continue;
718
717
  }
719
718
  } else if (member.primitive === "number" || member.primitive === "integer") {
720
- const c = numberChecksMini(narrowSchema(member, "number") ?? narrowSchema(member, "integer") ?? {});
719
+ const c = numberChecksMini(ast.narrowSchema(member, "number") ?? ast.narrowSchema(member, "integer") ?? {});
721
720
  if (c) {
722
721
  base += c;
723
722
  continue;
724
723
  }
725
724
  } else if (member.primitive === "array") {
726
- const c = lengthChecksMini(narrowSchema(member, "array") ?? {});
725
+ const c = lengthChecksMini(ast.narrowSchema(member, "array") ?? {});
727
726
  if (c) {
728
727
  base += c;
729
728
  continue;
@@ -740,7 +739,7 @@ const printerZodMini = definePrinter((options) => {
740
739
  const { keysToOmit } = this.options;
741
740
  let base = this.transform(node);
742
741
  if (!base) return null;
743
- const meta = syncSchemaRef(node);
742
+ const meta = ast.syncSchemaRef(node);
744
743
  if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
745
744
  return applyMiniModifiers({
746
745
  value: base,
@@ -756,11 +755,12 @@ const printerZodMini = definePrinter((options) => {
756
755
  //#region src/generators/zodGenerator.tsx
757
756
  const zodGenerator = defineGenerator({
758
757
  name: "zod",
759
- schema(node, options) {
760
- const { adapter, config, resolver, root } = this;
761
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options;
758
+ renderer: jsxRenderer,
759
+ schema(node, ctx) {
760
+ const { adapter, config, resolver, root } = ctx;
761
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
762
762
  if (!node.name) return;
763
- const mode = this.getMode(output);
763
+ const mode = ctx.getMode(output);
764
764
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
765
765
  const imports = adapter.getImports(node, (schemaName) => ({
766
766
  name: resolver.resolveSchemaName(schemaName),
@@ -831,12 +831,12 @@ const zodGenerator = defineGenerator({
831
831
  ]
832
832
  });
833
833
  },
834
- operation(node, options) {
835
- const { adapter, config, resolver, root } = this;
836
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
837
- const mode = this.getMode(output);
834
+ operation(node, ctx) {
835
+ const { adapter, config, resolver, root } = ctx;
836
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options;
837
+ const mode = ctx.getMode(output);
838
838
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
839
- const params = caseParams(node.parameters, paramsCasing);
839
+ const params = ast.caseParams(node.parameters, paramsCasing);
840
840
  const meta = { file: resolver.resolveFile({
841
841
  name: node.operationId,
842
842
  extname: ".ts",
@@ -933,9 +933,9 @@ const zodGenerator = defineGenerator({
933
933
  ]
934
934
  });
935
935
  },
936
- operations(nodes, options) {
937
- const { adapter, config, resolver, root } = this;
938
- const { output, importPath, group, operations, paramsCasing } = options;
936
+ operations(nodes, ctx) {
937
+ const { adapter, config, resolver, root } = ctx;
938
+ const { output, importPath, group, operations, paramsCasing } = ctx.options;
939
939
  if (!operations) return;
940
940
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
941
941
  const meta = { file: resolver.resolveFile({
@@ -950,7 +950,7 @@ const zodGenerator = defineGenerator({
950
950
  return {
951
951
  node,
952
952
  data: buildSchemaNames(node, {
953
- params: caseParams(node.parameters, paramsCasing),
953
+ params: ast.caseParams(node.parameters, paramsCasing),
954
954
  resolver
955
955
  })
956
956
  };
@@ -1008,12 +1008,12 @@ const zodGenerator = defineGenerator({
1008
1008
  //#endregion
1009
1009
  //#region src/generators/zodGeneratorLegacy.tsx
1010
1010
  function buildGroupedParamsSchema({ params, optional }) {
1011
- return createSchema({
1011
+ return ast.createSchema({
1012
1012
  type: "object",
1013
1013
  optional,
1014
1014
  primitive: "object",
1015
1015
  properties: params.map((param) => {
1016
- return createProperty({
1016
+ return ast.createProperty({
1017
1017
  name: param.name,
1018
1018
  required: param.required,
1019
1019
  schema: param.schema
@@ -1028,72 +1028,72 @@ function buildLegacyResponsesSchemaNode(node, { resolver }) {
1028
1028
  return !Number.isNaN(code) && code >= 200 && code < 300;
1029
1029
  });
1030
1030
  const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
1031
- const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? createSchema({
1031
+ const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? ast.createSchema({
1032
1032
  type: "ref",
1033
1033
  name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1034
- }) : createSchema({
1034
+ }) : ast.createSchema({
1035
1035
  type: "union",
1036
- members: successResponses.map((res) => createSchema({
1036
+ members: successResponses.map((res) => ast.createSchema({
1037
1037
  type: "ref",
1038
1038
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1039
1039
  }))
1040
- }) : createSchema({ type: "any" });
1041
- const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? createSchema({
1040
+ }) : ast.createSchema({ type: "any" });
1041
+ const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? ast.createSchema({
1042
1042
  type: "ref",
1043
1043
  name: resolver.resolveResponseStatusName(node, errorResponses[0].statusCode)
1044
- }) : createSchema({
1044
+ }) : ast.createSchema({
1045
1045
  type: "union",
1046
- members: errorResponses.map((res) => createSchema({
1046
+ members: errorResponses.map((res) => ast.createSchema({
1047
1047
  type: "ref",
1048
1048
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1049
1049
  }))
1050
- }) : createSchema({ type: "any" });
1051
- const properties = [createProperty({
1050
+ }) : ast.createSchema({ type: "any" });
1051
+ const properties = [ast.createProperty({
1052
1052
  name: "Response",
1053
1053
  required: true,
1054
1054
  schema: responseSchema
1055
1055
  })];
1056
- if (!isGet && node.requestBody?.schema) properties.push(createProperty({
1056
+ if (!isGet && node.requestBody?.schema) properties.push(ast.createProperty({
1057
1057
  name: "Request",
1058
1058
  required: true,
1059
- schema: createSchema({
1059
+ schema: ast.createSchema({
1060
1060
  type: "ref",
1061
1061
  name: resolver.resolveDataName(node)
1062
1062
  })
1063
1063
  }));
1064
1064
  const queryParam = node.parameters.find((p) => p.in === "query");
1065
- if (queryParam) properties.push(createProperty({
1065
+ if (queryParam) properties.push(ast.createProperty({
1066
1066
  name: "QueryParams",
1067
1067
  required: true,
1068
- schema: createSchema({
1068
+ schema: ast.createSchema({
1069
1069
  type: "ref",
1070
1070
  name: resolver.resolveQueryParamsName(node, queryParam)
1071
1071
  })
1072
1072
  }));
1073
1073
  const pathParam = node.parameters.find((p) => p.in === "path");
1074
- if (pathParam) properties.push(createProperty({
1074
+ if (pathParam) properties.push(ast.createProperty({
1075
1075
  name: "PathParams",
1076
1076
  required: true,
1077
- schema: createSchema({
1077
+ schema: ast.createSchema({
1078
1078
  type: "ref",
1079
1079
  name: resolver.resolvePathParamsName(node, pathParam)
1080
1080
  })
1081
1081
  }));
1082
1082
  const headerParam = node.parameters.find((p) => p.in === "header");
1083
- if (headerParam) properties.push(createProperty({
1083
+ if (headerParam) properties.push(ast.createProperty({
1084
1084
  name: "HeaderParams",
1085
1085
  required: true,
1086
- schema: createSchema({
1086
+ schema: ast.createSchema({
1087
1087
  type: "ref",
1088
1088
  name: resolver.resolveHeaderParamsName(node, headerParam)
1089
1089
  })
1090
1090
  }));
1091
- properties.push(createProperty({
1091
+ properties.push(ast.createProperty({
1092
1092
  name: "Errors",
1093
1093
  required: true,
1094
1094
  schema: errorsSchema
1095
1095
  }));
1096
- return createSchema({
1096
+ return ast.createSchema({
1097
1097
  type: "object",
1098
1098
  primitive: "object",
1099
1099
  properties
@@ -1104,14 +1104,14 @@ function buildLegacyResponseUnionSchemaNode(node, { resolver }) {
1104
1104
  const code = Number(res.statusCode);
1105
1105
  return !Number.isNaN(code) && code >= 200 && code < 300;
1106
1106
  });
1107
- if (successResponses.length === 0) return createSchema({ type: "any" });
1108
- if (successResponses.length === 1) return createSchema({
1107
+ if (successResponses.length === 0) return ast.createSchema({ type: "any" });
1108
+ if (successResponses.length === 1) return ast.createSchema({
1109
1109
  type: "ref",
1110
1110
  name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1111
1111
  });
1112
- return createSchema({
1112
+ return ast.createSchema({
1113
1113
  type: "union",
1114
- members: successResponses.map((res) => createSchema({
1114
+ members: successResponses.map((res) => ast.createSchema({
1115
1115
  type: "ref",
1116
1116
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1117
1117
  }))
@@ -1145,11 +1145,12 @@ function buildLegacySchemaNames(node, params, resolver) {
1145
1145
  }
1146
1146
  const zodGeneratorLegacy = defineGenerator({
1147
1147
  name: "zod-legacy",
1148
- schema(node, options) {
1149
- const { adapter, config, resolver, root } = this;
1150
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = options;
1148
+ renderer: jsxRenderer,
1149
+ schema(node, ctx) {
1150
+ const { adapter, config, resolver, root } = ctx;
1151
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
1151
1152
  if (!node.name) return;
1152
- const mode = this.getMode(output);
1153
+ const mode = ctx.getMode(output);
1153
1154
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1154
1155
  const imports = adapter.getImports(node, (schemaName) => ({
1155
1156
  name: resolver.resolveSchemaName(schemaName),
@@ -1220,12 +1221,12 @@ const zodGeneratorLegacy = defineGenerator({
1220
1221
  ]
1221
1222
  });
1222
1223
  },
1223
- operation(node, options) {
1224
- const { adapter, config, resolver, root } = this;
1225
- const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
1226
- const mode = this.getMode(output);
1224
+ operation(node, ctx) {
1225
+ const { adapter, config, resolver, root } = ctx;
1226
+ const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options;
1227
+ const mode = ctx.getMode(output);
1227
1228
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1228
- const params = caseParams(node.parameters, paramsCasing);
1229
+ const params = ast.caseParams(node.parameters, paramsCasing);
1229
1230
  const meta = { file: resolver.resolveFile({
1230
1231
  name: node.operationId,
1231
1232
  extname: ".ts",
@@ -1360,9 +1361,9 @@ const zodGeneratorLegacy = defineGenerator({
1360
1361
  ]
1361
1362
  });
1362
1363
  },
1363
- operations(nodes, options) {
1364
- const { adapter, config, resolver, root } = this;
1365
- const { output, importPath, group, operations, paramsCasing } = options;
1364
+ operations(nodes, ctx) {
1365
+ const { adapter, config, resolver, root } = ctx;
1366
+ const { output, importPath, group, operations, paramsCasing } = ctx.options;
1366
1367
  if (!operations) return;
1367
1368
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1368
1369
  const meta = { file: resolver.resolveFile({
@@ -1376,7 +1377,7 @@ const zodGeneratorLegacy = defineGenerator({
1376
1377
  const transformedOperations = nodes.map((node) => {
1377
1378
  return {
1378
1379
  node,
1379
- data: buildLegacySchemaNames(node, caseParams(node.parameters, paramsCasing), resolver)
1380
+ data: buildLegacySchemaNames(node, ast.caseParams(node.parameters, paramsCasing), resolver)
1380
1381
  };
1381
1382
  });
1382
1383
  const imports = transformedOperations.flatMap(({ node, data }) => {
@@ -1430,9 +1431,6 @@ const zodGeneratorLegacy = defineGenerator({
1430
1431
  }
1431
1432
  });
1432
1433
  //#endregion
1433
- //#region package.json
1434
- var version = "5.0.0-alpha.33";
1435
- //#endregion
1436
1434
  //#region src/resolvers/resolverZod.ts
1437
1435
  /**
1438
1436
  * Default resolver for `@kubb/plugin-zod`.
@@ -1551,30 +1549,6 @@ const resolverZodLegacy = defineResolver(() => {
1551
1549
  };
1552
1550
  });
1553
1551
  //#endregion
1554
- //#region src/presets.ts
1555
- /**
1556
- * Built-in preset registry for `@kubb/plugin-zod`.
1557
- *
1558
- * - `default` — uses `resolverZod` and `zodGenerator` (current naming conventions).
1559
- * - `kubbV4` — uses `resolverZodLegacy` and `zodGeneratorLegacy` (Kubb v4 naming conventions).
1560
- *
1561
- * Note: `printerZodMini` is selected at runtime by the generator when `mini: true` is set.
1562
- */
1563
- const presets = definePresets({
1564
- default: {
1565
- name: "default",
1566
- resolver: resolverZod,
1567
- generators: [zodGenerator],
1568
- printer: printerZod
1569
- },
1570
- kubbV4: {
1571
- name: "kubbV4",
1572
- resolver: resolverZodLegacy,
1573
- generators: [zodGeneratorLegacy],
1574
- printer: printerZod
1575
- }
1576
- });
1577
- //#endregion
1578
1552
  //#region src/plugin.ts
1579
1553
  /**
1580
1554
  * Canonical plugin name for `@kubb/plugin-zod`, used to identify the plugin in driver lookups and warnings.
@@ -1596,43 +1570,30 @@ const pluginZodName = "plugin-zod";
1596
1570
  * })
1597
1571
  * ```
1598
1572
  */
1599
- const pluginZod = createPlugin((options) => {
1573
+ const pluginZod = definePlugin((options) => {
1600
1574
  const { output = {
1601
1575
  path: "zod",
1602
1576
  barrelType: "named"
1603
- }, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, printer, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
1604
- const preset = getPreset({
1605
- preset: compatibilityPreset,
1606
- presets,
1607
- resolver: userResolver,
1608
- transformer: userTransformer,
1609
- generators: userGenerators
1610
- });
1611
- const mergedGenerator = mergeGenerators(preset.generators ?? []);
1612
- let resolveNameWarning = false;
1613
- let resolvePathWarning = false;
1577
+ }, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, printer, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [], compatibilityPreset = "default" } = options;
1578
+ const defaultResolver = compatibilityPreset === "kubbV4" ? resolverZodLegacy : resolverZod;
1579
+ const defaultGenerator = compatibilityPreset === "kubbV4" ? zodGeneratorLegacy : zodGenerator;
1580
+ const groupConfig = group ? {
1581
+ ...group,
1582
+ name: (ctx) => {
1583
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1584
+ return `${camelCase(ctx.group)}Controller`;
1585
+ }
1586
+ } : void 0;
1614
1587
  return {
1615
1588
  name: pluginZodName,
1616
- version,
1617
- get resolver() {
1618
- return preset.resolver;
1619
- },
1620
- get transformer() {
1621
- return preset.transformer;
1622
- },
1623
- get options() {
1624
- return {
1589
+ options,
1590
+ hooks: { "kubb:plugin:setup"(ctx) {
1591
+ ctx.setOptions({
1625
1592
  output,
1626
1593
  exclude,
1627
1594
  include,
1628
1595
  override,
1629
- group: group ? {
1630
- ...group,
1631
- name: (ctx) => {
1632
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1633
- return `${camelCase(ctx.group)}Controller`;
1634
- }
1635
- } : void 0,
1596
+ group: groupConfig,
1636
1597
  dateType,
1637
1598
  typed,
1638
1599
  importPath,
@@ -1644,43 +1605,15 @@ const pluginZod = createPlugin((options) => {
1644
1605
  wrapOutput,
1645
1606
  paramsCasing,
1646
1607
  printer
1647
- };
1648
- },
1649
- resolvePath(baseName, pathMode, options) {
1650
- if (!resolvePathWarning) {
1651
- this.warn("Do not use resolvePath for pluginZod, use resolverZod.resolvePath instead");
1652
- resolvePathWarning = true;
1653
- }
1654
- return this.plugin.resolver.resolvePath({
1655
- baseName,
1656
- pathMode,
1657
- tag: options?.group?.tag,
1658
- path: options?.group?.path
1659
- }, {
1660
- root: this.root,
1661
- output,
1662
- group: this.plugin.options.group
1663
1608
  });
1664
- },
1665
- resolveName(name, type) {
1666
- if (!resolveNameWarning) {
1667
- this.warn("Do not use resolveName for pluginZod, use resolverZod.default instead");
1668
- resolveNameWarning = true;
1669
- }
1670
- return this.plugin.resolver.default(name, type);
1671
- },
1672
- async schema(node, options) {
1673
- return mergedGenerator.schema?.call(this, node, options);
1674
- },
1675
- async operation(node, options) {
1676
- return mergedGenerator.operation?.call(this, node, options);
1677
- },
1678
- async operations(nodes, options) {
1679
- return mergedGenerator.operations?.call(this, nodes, options);
1680
- },
1681
- async buildStart() {
1682
- await this.openInStudio({ ast: true });
1683
- }
1609
+ ctx.setResolver(userResolver ? {
1610
+ ...defaultResolver,
1611
+ ...userResolver
1612
+ } : defaultResolver);
1613
+ if (userTransformer) ctx.setTransformer(userTransformer);
1614
+ ctx.addGenerator(defaultGenerator);
1615
+ for (const gen of userGenerators) ctx.addGenerator(gen);
1616
+ } }
1684
1617
  };
1685
1618
  });
1686
1619
  //#endregion