@kubb/plugin-client 5.7.0-canary.20261024T190549 → 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.js CHANGED
@@ -428,7 +428,7 @@ var compatibility = {
428
428
  };
429
429
  //#endregion
430
430
  //#region package.json
431
- var version = "5.7.0-canary.20261024T190549";
431
+ var version = "5.7.0";
432
432
  //#endregion
433
433
  //#region ../../internals/client/src/builders/validatorOptions.ts
434
434
  /**
@@ -437,7 +437,7 @@ var version = "5.7.0-canary.20261024T190549";
437
437
  function isValidatorEnabled(validator) {
438
438
  if (!validator) return false;
439
439
  if (validator === "zod") return true;
440
- return Boolean(validator.request || validator.response);
440
+ return Boolean(validator.request || validator.params || validator.response);
441
441
  }
442
442
  /**
443
443
  * Returns `'zod'` when request body parsing is enabled, `null` otherwise. The string shorthand
@@ -448,6 +448,14 @@ function resolveRequestValidator(validator) {
448
448
  return validator.request ?? null;
449
449
  }
450
450
  /**
451
+ * Returns `'zod'` when path, query, and header params parsing is enabled, `null` otherwise. Only the
452
+ * object form `{ params: 'zod' }` enables it.
453
+ */
454
+ function resolveParamsValidator(validator) {
455
+ if (!validator || validator === "zod") return null;
456
+ return validator.params ?? null;
457
+ }
458
+ /**
451
459
  * Returns `'zod'` when response parsing is enabled, `null` otherwise. The string shorthand `'zod'`
452
460
  * maps to response parsing.
453
461
  */
@@ -466,30 +474,6 @@ function buildZodErrorParse(node, zodResolver) {
466
474
  return zodResolver.response.error?.(node) || null;
467
475
  }
468
476
  //#endregion
469
- //#region ../../internals/client/src/builders/validator.ts
470
- /**
471
- * Builds the validator-hook references for one operation. Request validation runs before the send;
472
- * response validation runs on the success body only. Returns `null` references when the matching
473
- * direction is disabled or the schema is absent.
474
- */
475
- function buildValidatorHooks({ node, validator, zodResolver }) {
476
- const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
477
- const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
478
- const response = parsesResponse ? zodResolver.response.response(node) || null : null;
479
- const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
480
- const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
481
- return {
482
- request,
483
- response,
484
- error,
485
- importedZodNames: [
486
- response,
487
- error,
488
- request
489
- ].filter((name) => Boolean(name))
490
- };
491
- }
492
- //#endregion
493
477
  //#region ../../internals/client/src/builders/security.ts
494
478
  function serializeAuth(auth) {
495
479
  const parts = [`type: '${auth.type}'`];
@@ -562,6 +546,49 @@ function buildSecurityMetadata({ security }) {
562
546
  return `[${security.map(serializeAuth).join(", ")}]`;
563
547
  }
564
548
  //#endregion
549
+ //#region ../../internals/client/src/builders/validator.ts
550
+ /**
551
+ * Builds the validator-hook references for one operation. Request body and params validation run before the send.
552
+ * Response validation runs on the success body only. Returns `null` references when the matching
553
+ * direction is disabled or the schema is absent.
554
+ */
555
+ function buildValidatorHooks({ node, validator, zodResolver }) {
556
+ const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
557
+ const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
558
+ const response = parsesResponse ? zodResolver.response.response(node) || null : null;
559
+ const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
560
+ const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
561
+ const paramGroups = getOperationParameters(node);
562
+ const resolveParamsName = (kind, params) => zodResolver && resolveParamsValidator(validator) === "zod" && params.length > 0 ? zodResolver.param[kind](node, params[0]) : null;
563
+ const path = resolveParamsName("path", paramGroups.path);
564
+ const query = resolveParamsName("query", paramGroups.query);
565
+ const headers = resolveParamsName("headers", paramGroups.header);
566
+ const importedZodNames = [
567
+ response,
568
+ error,
569
+ request,
570
+ path,
571
+ query,
572
+ headers
573
+ ].filter((name) => Boolean(name));
574
+ return {
575
+ request,
576
+ path,
577
+ query,
578
+ headers: headers ? `toHeadersStandardSchema(${headers}, ${headers}.shape)` : null,
579
+ response,
580
+ error,
581
+ importedZodNames
582
+ };
583
+ }
584
+ /**
585
+ * Prints the `validator: { … }` entry of a call config from the hooks named in `keys`, or `null` when none is set.
586
+ */
587
+ function buildValidatorLiteral(hooks, keys) {
588
+ const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
589
+ return entries.length ? `validator: { ${entries.join(", ")} }` : null;
590
+ }
591
+ //#endregion
565
592
  //#region ../../internals/client/src/builders/contentType.ts
566
593
  /**
567
594
  * Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
@@ -766,12 +793,14 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
766
793
  const eventStream = isEventStream(node);
767
794
  const responseType = getResponseType(node);
768
795
  const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
769
- const validatorEntries = [
770
- validators.request ? `request: ${validators.request}` : null,
771
- validators.response ? `response: ${validators.response}` : null,
772
- validators.error ? `error: ${validators.error}` : null
773
- ].filter(Boolean);
774
- const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
796
+ const validatorLiteral = buildValidatorLiteral(validators, [
797
+ "request",
798
+ "path",
799
+ "query",
800
+ "headers",
801
+ "response",
802
+ "error"
803
+ ]);
775
804
  const callConfig = `{ ${[
776
805
  `method: '${node.method.toUpperCase()}'`,
777
806
  `url: '${node.path}'`,
@@ -883,14 +912,15 @@ function createClientGenerator(name, resolveClientPath) {
883
912
  const { config, driver, resolver, root } = ctx;
884
913
  const { output, validator, returnType, throwOnErrorDefault, group } = ctx.options;
885
914
  const types = resolveOperationTypes(driver, ctx.plugin.name);
886
- const pluginZod = resolveResponseValidator(validator) === "zod" || resolveRequestValidator(validator) === "zod" ? driver.getPlugin(pluginZodName) : null;
915
+ const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
887
916
  const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
888
917
  const importedTypeNames = [types.response.options(node), types.response.responses(node)];
889
- const importedZodNames = buildValidatorHooks({
918
+ const validatorHooks = buildValidatorHooks({
890
919
  node,
891
920
  validator,
892
921
  zodResolver
893
- }).importedZodNames;
922
+ });
923
+ const importedZodNames = validatorHooks.importedZodNames;
894
924
  const meta = {
895
925
  name: resolver.name(node.operationId),
896
926
  file: resolver.file({
@@ -922,6 +952,7 @@ function createClientGenerator(name, resolveClientPath) {
922
952
  const customClientPath = resolveClientPath?.(ctx.options, root);
923
953
  const clientPath = customClientPath ?? path.resolve(root, ".kubb/client.ts");
924
954
  const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
955
+ const standardSchemaPath = customClientPath ?? path.resolve(root, ".kubb/standardSchema.ts");
925
956
  const eventStream = isEventStream(node);
926
957
  const clientValueImports = (() => {
927
958
  if (eventStream) return ["client", "toEventStream"];
@@ -986,6 +1017,11 @@ function createClientGenerator(name, resolveClientPath) {
986
1017
  root: meta.file.path,
987
1018
  path: meta.fileZod.path
988
1019
  }),
1020
+ validatorHooks.headers && /* @__PURE__ */ jsx(File.Import, {
1021
+ name: ["toHeadersStandardSchema"],
1022
+ root: clientRoot,
1023
+ path: standardSchemaPath
1024
+ }),
989
1025
  /* @__PURE__ */ jsx(Operation, {
990
1026
  name: meta.name,
991
1027
  node,