@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.cjs CHANGED
@@ -454,7 +454,7 @@ var compatibility = {
454
454
  };
455
455
  //#endregion
456
456
  //#region package.json
457
- var version = "5.7.0-canary.20261024T190549";
457
+ var version = "5.7.0";
458
458
  //#endregion
459
459
  //#region ../../internals/client/src/builders/validatorOptions.ts
460
460
  /**
@@ -463,7 +463,7 @@ var version = "5.7.0-canary.20261024T190549";
463
463
  function isValidatorEnabled(validator) {
464
464
  if (!validator) return false;
465
465
  if (validator === "zod") return true;
466
- return Boolean(validator.request || validator.response);
466
+ return Boolean(validator.request || validator.params || validator.response);
467
467
  }
468
468
  /**
469
469
  * Returns `'zod'` when request body parsing is enabled, `null` otherwise. The string shorthand
@@ -474,6 +474,14 @@ function resolveRequestValidator(validator) {
474
474
  return validator.request ?? null;
475
475
  }
476
476
  /**
477
+ * Returns `'zod'` when path, query, and header params parsing is enabled, `null` otherwise. Only the
478
+ * object form `{ params: 'zod' }` enables it.
479
+ */
480
+ function resolveParamsValidator(validator) {
481
+ if (!validator || validator === "zod") return null;
482
+ return validator.params ?? null;
483
+ }
484
+ /**
477
485
  * Returns `'zod'` when response parsing is enabled, `null` otherwise. The string shorthand `'zod'`
478
486
  * maps to response parsing.
479
487
  */
@@ -492,30 +500,6 @@ function buildZodErrorParse(node, zodResolver) {
492
500
  return zodResolver.response.error?.(node) || null;
493
501
  }
494
502
  //#endregion
495
- //#region ../../internals/client/src/builders/validator.ts
496
- /**
497
- * Builds the validator-hook references for one operation. Request validation runs before the send;
498
- * response validation runs on the success body only. Returns `null` references when the matching
499
- * direction is disabled or the schema is absent.
500
- */
501
- function buildValidatorHooks({ node, validator, zodResolver }) {
502
- const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
503
- const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
504
- const response = parsesResponse ? zodResolver.response.response(node) || null : null;
505
- const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
506
- const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
507
- return {
508
- request,
509
- response,
510
- error,
511
- importedZodNames: [
512
- response,
513
- error,
514
- request
515
- ].filter((name) => Boolean(name))
516
- };
517
- }
518
- //#endregion
519
503
  //#region ../../internals/client/src/builders/security.ts
520
504
  function serializeAuth(auth) {
521
505
  const parts = [`type: '${auth.type}'`];
@@ -588,6 +572,49 @@ function buildSecurityMetadata({ security }) {
588
572
  return `[${security.map(serializeAuth).join(", ")}]`;
589
573
  }
590
574
  //#endregion
575
+ //#region ../../internals/client/src/builders/validator.ts
576
+ /**
577
+ * Builds the validator-hook references for one operation. Request body and params validation run before the send.
578
+ * Response validation runs on the success body only. Returns `null` references when the matching
579
+ * direction is disabled or the schema is absent.
580
+ */
581
+ function buildValidatorHooks({ node, validator, zodResolver }) {
582
+ const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
583
+ const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
584
+ const response = parsesResponse ? zodResolver.response.response(node) || null : null;
585
+ const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
586
+ const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
587
+ const paramGroups = getOperationParameters(node);
588
+ const resolveParamsName = (kind, params) => zodResolver && resolveParamsValidator(validator) === "zod" && params.length > 0 ? zodResolver.param[kind](node, params[0]) : null;
589
+ const path = resolveParamsName("path", paramGroups.path);
590
+ const query = resolveParamsName("query", paramGroups.query);
591
+ const headers = resolveParamsName("headers", paramGroups.header);
592
+ const importedZodNames = [
593
+ response,
594
+ error,
595
+ request,
596
+ path,
597
+ query,
598
+ headers
599
+ ].filter((name) => Boolean(name));
600
+ return {
601
+ request,
602
+ path,
603
+ query,
604
+ headers: headers ? `toHeadersStandardSchema(${headers}, ${headers}.shape)` : null,
605
+ response,
606
+ error,
607
+ importedZodNames
608
+ };
609
+ }
610
+ /**
611
+ * Prints the `validator: { … }` entry of a call config from the hooks named in `keys`, or `null` when none is set.
612
+ */
613
+ function buildValidatorLiteral(hooks, keys) {
614
+ const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
615
+ return entries.length ? `validator: { ${entries.join(", ")} }` : null;
616
+ }
617
+ //#endregion
591
618
  //#region ../../internals/client/src/builders/contentType.ts
592
619
  /**
593
620
  * Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
@@ -792,12 +819,14 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
792
819
  const eventStream = isEventStream(node);
793
820
  const responseType = getResponseType(node);
794
821
  const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
795
- const validatorEntries = [
796
- validators.request ? `request: ${validators.request}` : null,
797
- validators.response ? `response: ${validators.response}` : null,
798
- validators.error ? `error: ${validators.error}` : null
799
- ].filter(Boolean);
800
- const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
822
+ const validatorLiteral = buildValidatorLiteral(validators, [
823
+ "request",
824
+ "path",
825
+ "query",
826
+ "headers",
827
+ "response",
828
+ "error"
829
+ ]);
801
830
  const callConfig = `{ ${[
802
831
  `method: '${node.method.toUpperCase()}'`,
803
832
  `url: '${node.path}'`,
@@ -909,14 +938,15 @@ function createClientGenerator(name, resolveClientPath) {
909
938
  const { config, driver, resolver, root } = ctx;
910
939
  const { output, validator, returnType, throwOnErrorDefault, group } = ctx.options;
911
940
  const types = resolveOperationTypes(driver, ctx.plugin.name);
912
- const pluginZod = resolveResponseValidator(validator) === "zod" || resolveRequestValidator(validator) === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
941
+ const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
913
942
  const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
914
943
  const importedTypeNames = [types.response.options(node), types.response.responses(node)];
915
- const importedZodNames = buildValidatorHooks({
944
+ const validatorHooks = buildValidatorHooks({
916
945
  node,
917
946
  validator,
918
947
  zodResolver
919
- }).importedZodNames;
948
+ });
949
+ const importedZodNames = validatorHooks.importedZodNames;
920
950
  const meta = {
921
951
  name: resolver.name(node.operationId),
922
952
  file: resolver.file({
@@ -948,6 +978,7 @@ function createClientGenerator(name, resolveClientPath) {
948
978
  const customClientPath = resolveClientPath?.(ctx.options, root);
949
979
  const clientPath = customClientPath ?? node_path.default.resolve(root, ".kubb/client.ts");
950
980
  const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
981
+ const standardSchemaPath = customClientPath ?? node_path.default.resolve(root, ".kubb/standardSchema.ts");
951
982
  const eventStream = isEventStream(node);
952
983
  const clientValueImports = (() => {
953
984
  if (eventStream) return ["client", "toEventStream"];
@@ -1012,6 +1043,11 @@ function createClientGenerator(name, resolveClientPath) {
1012
1043
  root: meta.file.path,
1013
1044
  path: meta.fileZod.path
1014
1045
  }),
1046
+ validatorHooks.headers && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1047
+ name: ["toHeadersStandardSchema"],
1048
+ root: clientRoot,
1049
+ path: standardSchemaPath
1050
+ }),
1015
1051
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Operation, {
1016
1052
  name: meta.name,
1017
1053
  node,