@kubb/plugin-fetch 5.9.0-canary.20261024T190549 → 5.9.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
@@ -472,7 +472,7 @@ function createGroupConfig(group) {
472
472
  function isValidatorEnabled(validator) {
473
473
  if (!validator) return false;
474
474
  if (validator === "zod") return true;
475
- return Boolean(validator.request || validator.response);
475
+ return Boolean(validator.request || validator.params || validator.response);
476
476
  }
477
477
  /**
478
478
  * Returns `'zod'` when request body parsing is enabled, `null` otherwise. The string shorthand
@@ -483,6 +483,14 @@ function resolveRequestValidator(validator) {
483
483
  return validator.request ?? null;
484
484
  }
485
485
  /**
486
+ * Returns `'zod'` when path, query, and header params parsing is enabled, `null` otherwise. Only the
487
+ * object form `{ params: 'zod' }` enables it.
488
+ */
489
+ function resolveParamsValidator(validator) {
490
+ if (!validator || validator === "zod") return null;
491
+ return validator.params ?? null;
492
+ }
493
+ /**
486
494
  * Returns `'zod'` when response parsing is enabled, `null` otherwise. The string shorthand `'zod'`
487
495
  * maps to response parsing.
488
496
  */
@@ -501,30 +509,6 @@ function buildZodErrorParse(node, zodResolver) {
501
509
  return zodResolver.response.error?.(node) || null;
502
510
  }
503
511
  //#endregion
504
- //#region ../../internals/client/src/builders/validator.ts
505
- /**
506
- * Builds the validator-hook references for one operation. Request validation runs before the send;
507
- * response validation runs on the success body only. Returns `null` references when the matching
508
- * direction is disabled or the schema is absent.
509
- */
510
- function buildValidatorHooks({ node, validator, zodResolver }) {
511
- const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
512
- const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
513
- const response = parsesResponse ? zodResolver.response.response(node) || null : null;
514
- const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
515
- const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
516
- return {
517
- request,
518
- response,
519
- error,
520
- importedZodNames: [
521
- response,
522
- error,
523
- request
524
- ].filter((name) => Boolean(name))
525
- };
526
- }
527
- //#endregion
528
512
  //#region ../../internals/client/src/builders/security.ts
529
513
  function serializeAuth(auth) {
530
514
  const parts = [`type: '${auth.type}'`];
@@ -597,6 +581,49 @@ function buildSecurityMetadata({ security }) {
597
581
  return `[${security.map(serializeAuth).join(", ")}]`;
598
582
  }
599
583
  //#endregion
584
+ //#region ../../internals/client/src/builders/validator.ts
585
+ /**
586
+ * Builds the validator-hook references for one operation. Request body and params validation run before the send.
587
+ * Response validation runs on the success body only. Returns `null` references when the matching
588
+ * direction is disabled or the schema is absent.
589
+ */
590
+ function buildValidatorHooks({ node, validator, zodResolver }) {
591
+ const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
592
+ const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
593
+ const response = parsesResponse ? zodResolver.response.response(node) || null : null;
594
+ const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
595
+ const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
596
+ const paramGroups = getOperationParameters(node);
597
+ const resolveParamsName = (kind, params) => zodResolver && resolveParamsValidator(validator) === "zod" && params.length > 0 ? zodResolver.param[kind](node, params[0]) : null;
598
+ const path = resolveParamsName("path", paramGroups.path);
599
+ const query = resolveParamsName("query", paramGroups.query);
600
+ const headers = resolveParamsName("headers", paramGroups.header);
601
+ const importedZodNames = [
602
+ response,
603
+ error,
604
+ request,
605
+ path,
606
+ query,
607
+ headers
608
+ ].filter((name) => Boolean(name));
609
+ return {
610
+ request,
611
+ path,
612
+ query,
613
+ headers: headers ? `toHeadersStandardSchema(${headers}, ${headers}.shape)` : null,
614
+ response,
615
+ error,
616
+ importedZodNames
617
+ };
618
+ }
619
+ /**
620
+ * Prints the `validator: { … }` entry of a call config from the hooks named in `keys`, or `null` when none is set.
621
+ */
622
+ function buildValidatorLiteral(hooks, keys) {
623
+ const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
624
+ return entries.length ? `validator: { ${entries.join(", ")} }` : null;
625
+ }
626
+ //#endregion
600
627
  //#region ../../internals/client/src/builders/contentType.ts
601
628
  /**
602
629
  * Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
@@ -801,12 +828,14 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
801
828
  const eventStream = isEventStream(node);
802
829
  const responseType = getResponseType(node);
803
830
  const responseTypeLiteral = responseType ? `responseType: '${responseType}'` : null;
804
- const validatorEntries = [
805
- validators.request ? `request: ${validators.request}` : null,
806
- validators.response ? `response: ${validators.response}` : null,
807
- validators.error ? `error: ${validators.error}` : null
808
- ].filter(Boolean);
809
- const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
831
+ const validatorLiteral = buildValidatorLiteral(validators, [
832
+ "request",
833
+ "path",
834
+ "query",
835
+ "headers",
836
+ "response",
837
+ "error"
838
+ ]);
810
839
  const callConfig = `{ ${[
811
840
  `method: '${node.method.toUpperCase()}'`,
812
841
  `url: '${node.path}'`,
@@ -918,14 +947,15 @@ function createClientGenerator(name, resolveClientPath) {
918
947
  const { config, driver, resolver, root } = ctx;
919
948
  const { output, validator, returnType, throwOnErrorDefault, group } = ctx.options;
920
949
  const types = resolveOperationTypes(driver, ctx.plugin.name);
921
- const pluginZod = resolveResponseValidator(validator) === "zod" || resolveRequestValidator(validator) === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
950
+ const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : null;
922
951
  const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : null;
923
952
  const importedTypeNames = [types.response.options(node), types.response.responses(node)];
924
- const importedZodNames = buildValidatorHooks({
953
+ const validatorHooks = buildValidatorHooks({
925
954
  node,
926
955
  validator,
927
956
  zodResolver
928
- }).importedZodNames;
957
+ });
958
+ const importedZodNames = validatorHooks.importedZodNames;
929
959
  const meta = {
930
960
  name: resolver.name(node.operationId),
931
961
  file: resolver.file({
@@ -957,6 +987,7 @@ function createClientGenerator(name, resolveClientPath) {
957
987
  const customClientPath = resolveClientPath?.(ctx.options, root);
958
988
  const clientPath = customClientPath ?? node_path.default.resolve(root, ".kubb/client.ts");
959
989
  const clientRoot = customClientPath === void 0 ? meta.file.path : void 0;
990
+ const standardSchemaPath = customClientPath ?? node_path.default.resolve(root, ".kubb/standardSchema.ts");
960
991
  const eventStream = isEventStream(node);
961
992
  const clientValueImports = (() => {
962
993
  if (eventStream) return ["client", "toEventStream"];
@@ -1021,6 +1052,11 @@ function createClientGenerator(name, resolveClientPath) {
1021
1052
  root: meta.file.path,
1022
1053
  path: meta.fileZod.path
1023
1054
  }),
1055
+ validatorHooks.headers && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1056
+ name: ["toHeadersStandardSchema"],
1057
+ root: clientRoot,
1058
+ path: standardSchemaPath
1059
+ }),
1024
1060
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Operation, {
1025
1061
  name: meta.name,
1026
1062
  node,
@@ -1041,14 +1077,14 @@ function createClientGenerator(name, resolveClientPath) {
1041
1077
  /**
1042
1078
  * Builds the call config literal forwarded to the contract client; the `throwOnError` fallback is applied after the `...config` spread.
1043
1079
  */
1044
- function buildCallConfig({ node, validator, zodResolver, security, throwOnErrorDefault }) {
1045
- const validators = buildValidatorHooks({
1046
- node,
1047
- validator,
1048
- zodResolver
1049
- });
1050
- const validatorEntries = [validators.request ? `request: ${validators.request}` : null, validators.response ? `response: ${validators.response}` : null].filter(Boolean);
1051
- const validatorLiteral = validatorEntries.length ? `validator: { ${validatorEntries.join(", ")} }` : null;
1080
+ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault }) {
1081
+ const validatorLiteral = buildValidatorLiteral(validatorHooks, [
1082
+ "request",
1083
+ "path",
1084
+ "query",
1085
+ "headers",
1086
+ "response"
1087
+ ]);
1052
1088
  const securityLiteral = buildSecurityMetadata({ security });
1053
1089
  const { literal: contentTypeLiteral } = buildContentType({ node });
1054
1090
  return `{ ${[
@@ -1064,7 +1100,7 @@ function buildCallConfig({ node, validator, zodResolver, security, throwOnErrorD
1064
1100
  /**
1065
1101
  * Builds one instance method of a generated SDK class; a per-call `options.client` overrides `this.client`.
1066
1102
  */
1067
- function buildSdkMethod({ node, name, types, zodResolver, validator, security, returnType, throwOnErrorDefault }) {
1103
+ function buildSdkMethod({ node, name, types, validatorHooks, security, returnType, throwOnErrorDefault }) {
1068
1104
  if (!kubb_kit.ast.isHttpOperationNode(node)) return "";
1069
1105
  const signature = buildGroupedOptionsSignature({
1070
1106
  node,
@@ -1077,8 +1113,7 @@ function buildSdkMethod({ node, name, types, zodResolver, validator, security, r
1077
1113
  types,
1078
1114
  callConfig: buildCallConfig({
1079
1115
  node,
1080
- validator,
1081
- zodResolver,
1116
+ validatorHooks,
1082
1117
  security,
1083
1118
  throwOnErrorDefault
1084
1119
  }),
@@ -1104,13 +1139,12 @@ function buildSdkMethod({ node, name, types, zodResolver, validator, security, r
1104
1139
  * instance: `const api = new PetClient({ baseURL }); api.getPetById(...)`. A per-call `client` option
1105
1140
  * still overrides the instance client for a one-off call.
1106
1141
  */
1107
- function SdkClient({ name, operations, validator, returnType, throwOnErrorDefault }) {
1108
- const methods = operations.map(({ node, name: methodName, types, zodResolver, security }) => buildSdkMethod({
1142
+ function SdkClient({ name, operations, returnType, throwOnErrorDefault }) {
1143
+ const methods = operations.map(({ node, name: methodName, types, validatorHooks, security }) => buildSdkMethod({
1109
1144
  node,
1110
1145
  name: methodName,
1111
1146
  types,
1112
- zodResolver,
1113
- validator,
1147
+ validatorHooks,
1114
1148
  security,
1115
1149
  returnType,
1116
1150
  throwOnErrorDefault
@@ -1158,9 +1192,6 @@ function SdkFacade({ name, members }) {
1158
1192
  function resolveTypeImportNames(node, types) {
1159
1193
  return [types.response.options(node), types.response.responses(node)];
1160
1194
  }
1161
- function resolveZodImportNames(node, zodResolver, validator) {
1162
- return [resolveResponseValidator(validator) === "zod" ? zodResolver.response.response(node) : null, resolveRequestValidator(validator) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null].filter((n) => Boolean(n));
1163
- }
1164
1195
  /**
1165
1196
  * Groups operations into one controller per tag. Operations without a tag fall back to a single
1166
1197
  * `Client`/`ApiClient` controller, matching the resolver's default naming.
@@ -1189,13 +1220,18 @@ function buildControllers(nodes, ctx, types) {
1189
1220
  method: node.method,
1190
1221
  path: node.path
1191
1222
  }) : void 0;
1223
+ const validatorHooks = zodResolver ? buildValidatorHooks({
1224
+ node,
1225
+ validator,
1226
+ zodResolver
1227
+ }) : null;
1192
1228
  return {
1193
1229
  node,
1194
1230
  name: resolver.name(node.operationId),
1195
1231
  types,
1196
- zodResolver,
1197
1232
  typeFile,
1198
1233
  zodFile,
1234
+ validatorHooks,
1199
1235
  security
1200
1236
  };
1201
1237
  }
@@ -1268,6 +1304,7 @@ function createSdkGenerator() {
1268
1304
  });
1269
1305
  const controllers = buildControllers(nodes, ctx, resolveOperationTypes(ctx.driver, ctx.plugin.name));
1270
1306
  const clientPath = node_path.default.resolve(root, ".kubb/client.ts");
1307
+ const standardSchemaPath = node_path.default.resolve(root, ".kubb/standardSchema.ts");
1271
1308
  const banner = (file) => resolver.default.banner(ctx.meta, {
1272
1309
  output,
1273
1310
  config,
@@ -1291,7 +1328,7 @@ function createSdkGenerator() {
1291
1328
  }));
1292
1329
  const { namesByPath: zodNamesByPath, filesByPath: zodFilesByPath } = isValidatorEnabled(validator) ? collectImportsByFile(ops, (op) => ({
1293
1330
  file: op.zodFile,
1294
- names: op.zodResolver ? resolveZodImportNames(op.node, op.zodResolver, validator) : []
1331
+ names: op.validatorHooks?.importedZodNames.filter((name) => name !== op.validatorHooks?.error) ?? []
1295
1332
  })) : {
1296
1333
  namesByPath: /* @__PURE__ */ new Map(),
1297
1334
  filesByPath: /* @__PURE__ */ new Map()
@@ -1341,10 +1378,14 @@ function createSdkGenerator() {
1341
1378
  root: file.path,
1342
1379
  path: zodFilesByPath.get(filePath).path
1343
1380
  }, filePath)),
1381
+ ops.some((op) => op.validatorHooks?.headers) && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1382
+ name: ["toHeadersStandardSchema"],
1383
+ root: file.path,
1384
+ path: standardSchemaPath
1385
+ }),
1344
1386
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SdkClient, {
1345
1387
  name: className,
1346
1388
  operations: ops,
1347
- validator,
1348
1389
  returnType,
1349
1390
  throwOnErrorDefault
1350
1391
  })
@@ -1447,7 +1488,7 @@ var compatibility = {
1447
1488
  };
1448
1489
  //#endregion
1449
1490
  //#region package.json
1450
- var version = "5.9.0-canary.20261024T190549";
1491
+ var version = "5.9.0";
1451
1492
  //#endregion
1452
1493
  //#region src/templates.ts
1453
1494
  /** Absolute path to the fetch client template, copied into `.kubb/client.ts`. */