@kubb/plugin-zod 5.7.0-canary.20261024T172532 → 5.7.0

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
@@ -378,10 +378,11 @@ type Options = OutputOptions & {
378
378
  */
379
379
  importPath?: 'zod' | 'zod/mini' | (string & {});
380
380
  /**
381
- * Export a `z.infer<typeof schema>` type alias next to every generated schema.
382
- * Lets the Zod schema act as the single source of truth.
381
+ * Export a type alias next to every generated schema, so the Zod schema acts as the single source of truth.
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
384
  */
384
- inferred?: boolean;
385
+ inferred?: boolean | 'direction';
385
386
  /**
386
387
  * Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
387
388
  * form data and query params where everything arrives as a string.
package/dist/index.d.ts CHANGED
@@ -378,10 +378,11 @@ type Options = OutputOptions & {
378
378
  */
379
379
  importPath?: 'zod' | 'zod/mini' | (string & {});
380
380
  /**
381
- * Export a `z.infer<typeof schema>` type alias next to every generated schema.
382
- * Lets the Zod schema act as the single source of truth.
381
+ * Export a type alias next to every generated schema, so the Zod schema acts as the single source of truth.
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
384
  */
384
- inferred?: boolean;
385
+ inferred?: boolean | 'direction';
385
386
  /**
386
387
  * Wrap schemas in `z.coerce` so input is coerced before validation. Useful for
387
388
  * form data and query params where everything arrives as a string.
package/dist/index.js CHANGED
@@ -728,7 +728,7 @@ function mapSchemaItems(node, transform) {
728
728
  }
729
729
  //#endregion
730
730
  //#region src/components/Zod.tsx
731
- function Zod({ name, node, printer, inferTypeName, typeGuards, isName, assertName, mini, cyclic, compile }) {
731
+ function Zod({ name, node, printer, inferTypeName, inferKind = "infer", typeGuards, isName, assertName, mini, cyclic, compile }) {
732
732
  const output = printer.print(node);
733
733
  const printerImports = printer.drainImports();
734
734
  if (!output) return;
@@ -770,7 +770,7 @@ function Zod({ name, node, printer, inferTypeName, typeGuards, isName, assertNam
770
770
  children: /* @__PURE__ */ jsx(Type, {
771
771
  export: true,
772
772
  name: inferTypeName,
773
- children: `z.infer<typeof ${name}>`
773
+ children: `z.${inferKind}<typeof ${name}>`
774
774
  })
775
775
  }),
776
776
  shouldGenerateIs && /* @__PURE__ */ jsx(File.Source, {
@@ -1680,6 +1680,14 @@ const printerZodMini = ast.createPrinter((options) => {
1680
1680
  });
1681
1681
  //#endregion
1682
1682
  //#region src/generators/zodGenerator.tsx
1683
+ /**
1684
+ * The helper an inferred alias is printed with. `'direction'` reads a request (encode) schema from its
1685
+ * input and a response (decode) schema from its output; `true` keeps `z.infer` for both.
1686
+ */
1687
+ function aliasKind(inferred, direction) {
1688
+ if (inferred !== "direction") return "infer";
1689
+ return direction === "encode" ? "input" : "output";
1690
+ }
1683
1691
  const zodPrinterCache = /* @__PURE__ */ new WeakMap();
1684
1692
  const zodMiniPrinterCache = /* @__PURE__ */ new WeakMap();
1685
1693
  /**
@@ -1795,7 +1803,6 @@ const zodGenerator = defineGenerator({
1795
1803
  group: group ?? void 0
1796
1804
  })
1797
1805
  };
1798
- const inferTypeName = inferred ? resolver.schema.typeName(node.name) : null;
1799
1806
  const isName = typeGuards ? resolver.schema.isName(node.name) : null;
1800
1807
  const assertName = typeGuards ? resolver.schema.assertName(node.name) : null;
1801
1808
  const stdPrinters = mini ? null : getStdPrinters(resolver, {
@@ -1854,7 +1861,8 @@ const zodGenerator = defineGenerator({
1854
1861
  name: meta.name,
1855
1862
  node,
1856
1863
  printer: schemaPrinter,
1857
- inferTypeName,
1864
+ inferTypeName: inferred ? resolver.schema.typeName(node.name) : null,
1865
+ inferKind: aliasKind(inferred, "decode"),
1858
1866
  typeGuards,
1859
1867
  isName,
1860
1868
  assertName,
@@ -1867,6 +1875,7 @@ const zodGenerator = defineGenerator({
1867
1875
  node,
1868
1876
  printer: stdPrinters.encode,
1869
1877
  inferTypeName: inferred ? resolver.schema.inputTypeName(node.name) : null,
1878
+ inferKind: aliasKind(inferred, "encode"),
1870
1879
  typeGuards,
1871
1880
  isName: typeGuards ? resolver.schema.isName(resolver.schema.inputName(node.name)) : null,
1872
1881
  assertName: typeGuards ? resolver.schema.assertName(resolver.schema.inputName(node.name)) : null,
@@ -1905,7 +1914,6 @@ const zodGenerator = defineGenerator({
1905
1914
  };
1906
1915
  function renderSchemaEntry({ schema, name, keysToOmit, direction = "decode" }) {
1907
1916
  if (!schema) return null;
1908
- const inferTypeName = inferred ? resolver.schema.type(name) : null;
1909
1917
  const directionalRefNames = direction === "encode" && !mini ? new Set(collectDirectionalRefNames({
1910
1918
  node: schema,
1911
1919
  printerOptions
@@ -1965,7 +1973,8 @@ const zodGenerator = defineGenerator({
1965
1973
  name,
1966
1974
  node: schema,
1967
1975
  printer: schemaPrinter,
1968
- inferTypeName,
1976
+ inferTypeName: inferred ? resolver.schema.type(name) : null,
1977
+ inferKind: aliasKind(inferred, direction),
1969
1978
  cyclic: false,
1970
1979
  compile
1971
1980
  })] });
@@ -2058,7 +2067,7 @@ const zodGenerator = defineGenerator({
2058
2067
  }), "encode");
2059
2068
  })();
2060
2069
  const { path, query, header } = getOperationParameters(node);
2061
- const paramGroupSchemas = inferred ? [
2070
+ const paramGroupSchemas = [
2062
2071
  {
2063
2072
  kind: "path",
2064
2073
  params: path
@@ -2083,7 +2092,7 @@ const zodGenerator = defineGenerator({
2083
2092
  }),
2084
2093
  name: resolver.param[kind](node, params[0]),
2085
2094
  direction: "encode"
2086
- })) : [];
2095
+ }));
2087
2096
  const optionsSchema = inferred ? renderSchemaEntry({
2088
2097
  schema: buildOptionsSchema(node, resolver),
2089
2098
  name: resolver.name(`${node.operationId} Options`),
@@ -2139,7 +2148,7 @@ var compatibility = {
2139
2148
  };
2140
2149
  //#endregion
2141
2150
  //#region package.json
2142
- var version = "5.7.0-canary.20261024T172532";
2151
+ var version = "5.7.0";
2143
2152
  //#endregion
2144
2153
  //#region src/resolvers/resolverZod.ts
2145
2154
  /**