@kubb/plugin-zod 5.7.0 → 5.7.2

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.cts CHANGED
@@ -380,9 +380,11 @@ type Options = OutputOptions & {
380
380
  /**
381
381
  * Export a type alias next to every generated schema, so the Zod schema acts as the single source of truth.
382
382
  * - `true`: the alias is `z.infer<typeof schema>`.
383
- * - `'direction'`: request and params schemas use `z.input`, response and error schemas use `z.output`.
383
+ * - `'codec'`: request and params schemas use `z.input`, response and error schemas use `z.output`, so a
384
+ * codec types both sides with its domain value. Clients and query hooks then take their types from here.
385
+ * - `'direction'`: deprecated alias of `'codec'`.
384
386
  */
385
- inferred?: boolean | 'direction';
387
+ inferred?: boolean | 'codec' | 'direction';
386
388
  /**
387
389
  * Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
388
390
  * form data and query params where everything arrives as a string.
@@ -492,7 +494,7 @@ type ResolvedOptions = {
492
494
  include: Array<Include> | undefined;
493
495
  override: Array<Override<ResolvedOptions>>;
494
496
  group: Group | null;
495
- inferred: NonNullable<Options['inferred']>;
497
+ inferred: boolean | 'codec';
496
498
  importPath: NonNullable<Options['importPath']>;
497
499
  coercion: NonNullable<Options['coercion']>;
498
500
  guidType: NonNullable<Options['guidType']>;
package/dist/index.d.ts CHANGED
@@ -380,9 +380,11 @@ type Options = OutputOptions & {
380
380
  /**
381
381
  * Export a type alias next to every generated schema, so the Zod schema acts as the single source of truth.
382
382
  * - `true`: the alias is `z.infer<typeof schema>`.
383
- * - `'direction'`: request and params schemas use `z.input`, response and error schemas use `z.output`.
383
+ * - `'codec'`: request and params schemas use `z.input`, response and error schemas use `z.output`, so a
384
+ * codec types both sides with its domain value. Clients and query hooks then take their types from here.
385
+ * - `'direction'`: deprecated alias of `'codec'`.
384
386
  */
385
- inferred?: boolean | 'direction';
387
+ inferred?: boolean | 'codec' | 'direction';
386
388
  /**
387
389
  * Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
388
390
  * form data and query params where everything arrives as a string.
@@ -492,7 +494,7 @@ type ResolvedOptions = {
492
494
  include: Array<Include> | undefined;
493
495
  override: Array<Override<ResolvedOptions>>;
494
496
  group: Group | null;
495
- inferred: NonNullable<Options['inferred']>;
497
+ inferred: boolean | 'codec';
496
498
  importPath: NonNullable<Options['importPath']>;
497
499
  coercion: NonNullable<Options['coercion']>;
498
500
  guidType: NonNullable<Options['guidType']>;
package/dist/index.js CHANGED
@@ -809,9 +809,6 @@ function shouldCoerce(coercion, type) {
809
809
  if (coercion === true) return true;
810
810
  return !!coercion[type];
811
811
  }
812
- function propertyNamesOf(node) {
813
- return "propertyNames" in node ? node.propertyNames : void 0;
814
- }
815
812
  /**
816
813
  * Whether the schema node represents a closed or finite set of keys (e.g. enum, literal,
817
814
  * or union of enums/literals).
@@ -840,7 +837,7 @@ function isPlainInlineObject(node) {
840
837
  if (node.nullable || node.optional || node.nullish) return false;
841
838
  const hasAdditionalProperties = node.additionalProperties !== void 0;
842
839
  const hasPatternProperties = Boolean(node.patternProperties);
843
- return !hasAdditionalProperties && !hasPatternProperties && !propertyNamesOf(node);
840
+ return !hasAdditionalProperties && !hasPatternProperties && !node.propertyNames;
844
841
  }
845
842
  /**
846
843
  * Whether a node renders as a bare Zod object — one that accepts `.extend(…)` and can be a
@@ -855,7 +852,7 @@ function isObjectSchemaNode(node, cyclicSchemas) {
855
852
  const hasProperties = Boolean(node.properties?.length);
856
853
  const hasTypedAdditionalProperties = Boolean(node.additionalProperties && node.additionalProperties !== true);
857
854
  const hasPatternProperties = Boolean(node.patternProperties);
858
- return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || propertyNamesOf(node)));
855
+ return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || node.propertyNames));
859
856
  }
860
857
  if (node.type === "ref") {
861
858
  const refName = ast.resolveRefName(node);
@@ -1238,7 +1235,7 @@ function containsDirectionalNode({ node, printerOptions, seen = /* @__PURE__ */
1238
1235
  if ("items" in node && node.items) children.push(...node.items);
1239
1236
  if ("members" in node && node.members) children.push(...node.members);
1240
1237
  if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties);
1241
- const propertyNames = propertyNamesOf(node);
1238
+ const propertyNames = node.type === "object" ? node.propertyNames : void 0;
1242
1239
  if (propertyNames) children.push(propertyNames);
1243
1240
  return children.some((child) => containsDirectionalNode({
1244
1241
  node: child,
@@ -1383,7 +1380,7 @@ const printerZod = ast.createPrinter((options) => {
1383
1380
  object(node) {
1384
1381
  const entries = node.properties ?? [];
1385
1382
  const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
1386
- const propertyNamesNode = propertyNamesOf(node);
1383
+ const propertyNamesNode = node.propertyNames;
1387
1384
  const propertyNamesKeySchema = propertyNamesNode ? this.transform(propertyNamesNode) : null;
1388
1385
  const isStrict = node.additionalProperties === false && patterns.length === 0;
1389
1386
  const isLoose = node.additionalProperties === true;
@@ -1593,7 +1590,7 @@ const printerZodMini = ast.createPrinter((options) => {
1593
1590
  object(node) {
1594
1591
  const entries = node.properties ?? [];
1595
1592
  const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
1596
- const propertyNamesNode = propertyNamesOf(node);
1593
+ const propertyNamesNode = node.propertyNames;
1597
1594
  const propertyNamesKeySchema = propertyNamesNode ? this.transform(propertyNamesNode) : null;
1598
1595
  const isStrict = node.additionalProperties === false && patterns.length === 0;
1599
1596
  const isLoose = node.additionalProperties === true;
@@ -1681,11 +1678,11 @@ const printerZodMini = ast.createPrinter((options) => {
1681
1678
  //#endregion
1682
1679
  //#region src/generators/zodGenerator.tsx
1683
1680
  /**
1684
- * The helper an inferred alias is printed with. `'direction'` reads a request (encode) schema from its
1681
+ * The helper an inferred alias is printed with. `'codec'` reads a request (encode) schema from its
1685
1682
  * input and a response (decode) schema from its output; `true` keeps `z.infer` for both.
1686
1683
  */
1687
1684
  function aliasKind(inferred, direction) {
1688
- if (inferred !== "direction") return "infer";
1685
+ if (inferred !== "codec") return "infer";
1689
1686
  return direction === "encode" ? "input" : "output";
1690
1687
  }
1691
1688
  const zodPrinterCache = /* @__PURE__ */ new WeakMap();
@@ -2148,7 +2145,7 @@ var compatibility = {
2148
2145
  };
2149
2146
  //#endregion
2150
2147
  //#region package.json
2151
- var version = "5.7.0";
2148
+ var version = "5.7.2";
2152
2149
  //#endregion
2153
2150
  //#region src/resolvers/resolverZod.ts
2154
2151
  /**
@@ -2259,7 +2256,7 @@ const pluginZod = defineExtension({
2259
2256
  group: createGroupConfig(group),
2260
2257
  importPath,
2261
2258
  coercion,
2262
- inferred,
2259
+ inferred: inferred === "direction" ? "codec" : inferred,
2263
2260
  guidType,
2264
2261
  regexType,
2265
2262
  oneOfType,