@kubb/plugin-zod 5.2.1 → 5.2.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.ts CHANGED
@@ -367,7 +367,9 @@ type Options = OutputOptions & {
367
367
  *
368
368
  * `dates` applies to fields typed as `Date` (adapter `dateType: 'date'`): they
369
369
  * validate with `z.coerce.date()` instead of the string-to-Date codec. Fields
370
- * kept as ISO strings (`z.iso.date()`, `z.iso.datetime()`) are never coerced.
370
+ * kept as ISO strings (`z.iso.date()`, `z.iso.datetime()`) are never coerced,
371
+ * and neither are `format: time` fields, since `new Date()` cannot parse a bare
372
+ * `HH:mm:ss` value.
371
373
  *
372
374
  * `bigint` fields (`format: int64`) always coerce, regardless of this option:
373
375
  * `JSON.parse` hands back a `number`, which a plain `z.bigint()` rejects.
package/dist/index.js CHANGED
@@ -1218,10 +1218,12 @@ function collectDirectionalRefNames({ node, printerOptions }) {
1218
1218
  * Handlers that never recurse into children, so {@link variesByDirection} can call one directly
1219
1219
  * to probe both directions without building a printer.
1220
1220
  *
1221
- * `date` is the built-in two-way conversion, decoding `string → Date` on responses and encoding
1222
- * back on requests, keeping `date` and `date-time` precision apart. Only `representation: 'date'`
1223
- * fields convert; ISO-string fields print `z.iso.date()` either way. A `printer.nodes.date`
1224
- * override replaces the whole handler, direction branch included.
1221
+ * `date` and `time` are the built-in two-way conversions, decoding `string → Date` on responses
1222
+ * and encoding back on requests. `date` keeps `date` and `date-time` precision apart. `time` has
1223
+ * no date component, so it decodes onto `1970-01-01` UTC and encodes back to `HH:mm:ss`, dropping
1224
+ * fractional seconds. Only `representation: 'date'` fields convert; ISO-string fields print the
1225
+ * matching `z.iso.*()` either way. A `printer.nodes.date` or `printer.nodes.time` override
1226
+ * replaces the whole handler, direction branch included.
1225
1227
  */
1226
1228
  const scalarNodes = {
1227
1229
  any: () => "z.any()",
@@ -1293,7 +1295,8 @@ const scalarNodes = {
1293
1295
  },
1294
1296
  time(node) {
1295
1297
  if (node.representation === "string") return "z.iso.time()";
1296
- return shouldCoerce(this.options.coercion, "dates") ? "z.coerce.date()" : "z.date()";
1298
+ if (this.options.direction === "encode") return "z.date().transform((value) => value.toISOString().slice(11, 19))";
1299
+ return "z.iso.time().transform((value) => new Date(`1970-01-01T${value}Z`))";
1297
1300
  },
1298
1301
  uuid(node) {
1299
1302
  return `${this.options.guidType === "guid" ? "z.guid()" : "z.uuid()"}${lengthConstraints({