@kubb/plugin-fetch 6.1.0-canary.20261109T175349 → 6.1.0-canary.20261109T175913

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
@@ -568,22 +568,19 @@ function resolveResponseValidator(validator) {
568
568
  return validator.response ?? null;
569
569
  }
570
570
  /**
571
- * Resolves the zod schema name a generated client validates an error body with on the non-throw path.
572
- * Uses the error-only `<operation>ErrorSchema` (the union of non-2xx statuses); returns `null` when the
573
- * operation documents no error responses with a schema.
571
+ * Builds the `validator.error` map of a call, one plugin-zod `<operation>StatusNNNSchema` per non-2xx response with a
572
+ * schema, such as `{ 404: getPetStatus404Schema, '5XX': getPetStatus5XXSchema }`. Returns `null` without one.
574
573
  */
575
574
  function buildZodErrorParse(node, zodResolver) {
576
- if (!getErrorStatusCodes(node).length) return null;
577
- return zodResolver.response.error?.(node) || null;
578
- }
579
- /** Prints the statuses `<operation>ErrorSchema` covers, such as `[404, '5XX']`, or `null` when a `default` response covers them all. */
580
- function buildErrorStatusLiteral(node) {
581
- const statusCodes = getErrorStatusCodes(node);
582
- if (!statusCodes.length || statusCodes.includes("default")) return null;
583
- return `[${statusCodes.map((statusCode) => /^\d+$/.test(statusCode) ? statusCode : stringify(statusCode)).join(", ")}]`;
584
- }
585
- function getErrorStatusCodes(node) {
586
- return node.responses.filter((res) => !isSuccessStatusCode(res.statusCode) && res.content?.some((entry) => entry.schema)).map((res) => String(res.statusCode));
575
+ const entries = node.responses.filter((res) => !isSuccessStatusCode(res.statusCode) && res.content?.some((entry) => entry.schema)).map((res) => ({
576
+ key: String(res.statusCode),
577
+ name: zodResolver.response.status(node, res.statusCode)
578
+ }));
579
+ if (!entries.length) return null;
580
+ return {
581
+ literal: `{ ${entries.map(({ key, name }) => `${/^\d+$/.test(key) ? key : stringify(key)}: ${name}`).join(", ")} }`,
582
+ names: entries.map(({ name }) => name)
583
+ };
587
584
  }
588
585
  // ../../internals/client/src/builders/generics.ts
589
586
  /**
@@ -788,8 +785,7 @@ function buildValidatorHooks({ node, validator, zodResolver }) {
788
785
  const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
789
786
  const parsesResponse = zodResolver && resolveResponseValidator(validator) === "zod";
790
787
  const response = parsesResponse ? zodResolver.response.response(node) || null : null;
791
- const error = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
792
- const errorStatus = error ? buildErrorStatusLiteral(node) : null;
788
+ const errorParse = parsesResponse ? buildZodErrorParse(node, zodResolver) : null;
793
789
  const request = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) || null : null;
794
790
  const paramGroups = getOperationParameters(node);
795
791
  const resolveParamsName = (kind, params) => zodResolver && resolveParamsValidator(validator) === "zod" && params.length > 0 ? zodResolver.param[kind](node, params[0]) : null;
@@ -799,7 +795,7 @@ function buildValidatorHooks({ node, validator, zodResolver }) {
799
795
  const cookies = resolveParamsName("cookies", paramGroups.cookie);
800
796
  const importedZodNames = [
801
797
  response,
802
- error,
798
+ ...errorParse?.names ?? [],
803
799
  request,
804
800
  path,
805
801
  query,
@@ -813,17 +809,17 @@ function buildValidatorHooks({ node, validator, zodResolver }) {
813
809
  headers: headers ? `toHeadersStandardSchema(${headers}, ${headers}.shape)` : null,
814
810
  cookies,
815
811
  response,
816
- error,
817
- errorStatus,
812
+ error: errorParse?.literal ?? null,
818
813
  importedZodNames
819
814
  };
820
815
  }
821
816
  /**
822
817
  * Prints the `validator: { … }` entry of a call config from the hooks named in `keys`, or `null` when none is set.
818
+ * The entry spreads `config.validator` last, so a per-call hook overrides the generated one for its key only.
823
819
  */
824
820
  function buildValidatorLiteral(hooks, keys) {
825
821
  const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
826
- return entries.length ? `validator: { ${entries.join(", ")} }` : null;
822
+ return entries.length ? `validator: { ${entries.join(", ")}, ...config.validator }` : null;
827
823
  }
828
824
  // ../../internals/client/src/builders/contentType.ts
829
825
  /**
@@ -876,13 +872,13 @@ function serializeParameter(parameter) {
876
872
  return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
877
873
  }
878
874
  /**
879
- * Serializes the `encoding` of the request body's default content type into a `{ property: { ... } }`
880
- * literal, or `null` when it carries none. Only an operation with a single request content type
875
+ * Serializes the `encoding` of the request body's default content type into `property: { ... }`
876
+ * entries, empty when it carries none. Only an operation with a single request content type
881
877
  * emits it, because the runtime applies `styles.body` to whichever type the caller selects.
882
878
  */
883
879
  function serializeBodyEncoding(node) {
884
880
  const content = node.requestBody?.content;
885
- const entries = Object.entries(content?.length === 1 ? content[0]?.encoding ?? {} : {}).map(([property, { contentType, style, explode, allowReserved }]) => {
881
+ return Object.entries(content?.length === 1 ? content[0]?.encoding ?? {} : {}).map(([property, { contentType, style, explode, allowReserved }]) => {
886
882
  const parts = [
887
883
  style && `style: ${JSON.stringify(style)}`,
888
884
  explode !== void 0 && `explode: ${explode}`,
@@ -891,7 +887,6 @@ function serializeBodyEncoding(node) {
891
887
  ].filter(Boolean);
892
888
  return `${isValidVarName(property) ? property : JSON.stringify(property)}: { ${parts.join(", ")} }`;
893
889
  });
894
- return entries.length > 0 ? `body: { ${entries.join(", ")} }` : null;
895
890
  }
896
891
  /**
897
892
  * Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
@@ -901,26 +896,31 @@ function serializeBodyEncoding(node) {
901
896
  * is unchanged. A form request body adds a `body` group keyed by property name from its `encoding`.
902
897
  * Returns `null` when nothing carries metadata.
903
898
  *
899
+ * With `merge`, the literal spreads `config.styles` per parameter, so a per-call entry overrides the generated one for
900
+ * that parameter and leaves the others in place.
901
+ *
904
902
  * @example
905
903
  * ```ts
906
904
  * // a path param with { style: 'matrix', explode: true } and a query param with { explode: false }
907
905
  * buildStyles({ node }) // "{ path: { id: { style: 'matrix', explode: true } }, query: { tags: { explode: false } } }"
908
906
  * ```
909
907
  */
910
- function buildStyles({ node }) {
908
+ function buildStyles({ node, merge }) {
911
909
  if (!ast.isHttpOperationNode(node)) return null;
912
910
  const groups = {
913
911
  path: [],
914
912
  query: [],
915
913
  header: [],
916
- cookie: []
914
+ cookie: [],
915
+ body: serializeBodyEncoding(node)
917
916
  };
918
917
  for (const [location, parameters] of Object.entries(getOperationParameters(node))) for (const parameter of parameters) {
919
918
  const literal = serializeParameter(parameter);
920
919
  if (literal) groups[location].push(`${toKey(parameter.name)}: ${literal}`);
921
920
  }
922
- const entries = [...Object.keys(groups).filter((location) => groups[location].length > 0).map((location) => `${location}: { ${groups[location].join(", ")} }`), serializeBodyEncoding(node)].filter(Boolean);
923
- return entries.length > 0 ? `{ ${entries.join(", ")} }` : null;
921
+ const entries = Object.entries(groups).filter(([, items]) => items.length > 0).map(([location, items]) => `${location}: { ${(merge ? [...items, `...config.styles?.${location}`] : items).join(", ")} }`);
922
+ if (entries.length === 0) return null;
923
+ return `{ ${(merge ? ["...config.styles", ...entries] : entries).join(", ")} }`;
924
924
  }
925
925
  // ../../internals/client/src/builders/callConfig.ts
926
926
  /**
@@ -936,7 +936,9 @@ function buildResponseTypeLiteral(node) {
936
936
  }
937
937
  /**
938
938
  * Builds the call config literal a generated operation forwards to the client, shared by the standalone
939
- * functions and the SDK methods. The `throwOnError` fallback is applied after the `...config` spread.
939
+ * functions and the SDK methods. The `validator` and `throwOnError` entries come after the `...config` spread, so a
940
+ * per-call `validator` is merged per key with the generated one instead of replacing it. `styles` is merged the same
941
+ * way, per parameter, unless `returnType` is `'plain'`.
940
942
  *
941
943
  * `mergeContentType` is `true` when the caller must destructure `contentType` from `options`, and
942
944
  * `eventStream` is `true` when the operation streams `text/event-stream` or JSON Lines. Unless `returnType` is `'plain'`, a
@@ -945,16 +947,20 @@ function buildResponseTypeLiteral(node) {
945
947
  function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault, returnType }) {
946
948
  const eventStream = isEventStream(node);
947
949
  const securityLiteral = buildSecurityMetadata({ security });
948
- const stylesLiteral = buildStyles({ node });
950
+ const ownRuntime = returnType !== "plain";
951
+ const stylesLiteral = buildStyles({
952
+ node,
953
+ merge: ownRuntime
954
+ });
955
+ const styles = stylesLiteral ? `styles: ${stylesLiteral}` : null;
949
956
  const validatorLiteral = buildValidatorLiteral(validatorHooks, [
950
957
  "request",
951
958
  "path",
952
959
  "query",
953
960
  "headers",
954
961
  "cookies",
955
- ...eventStream && returnType !== "plain" ? [] : ["response"],
956
- "error",
957
- "errorStatus"
962
+ ...eventStream && ownRuntime ? [] : ["response"],
963
+ "error"
958
964
  ]);
959
965
  const { literal: contentTypeLiteral, merge: mergeContentType } = buildContentType({ node });
960
966
  return {
@@ -962,11 +968,12 @@ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault,
962
968
  `method: '${node.method.toUpperCase()}'`,
963
969
  `url: '${node.path}'`,
964
970
  securityLiteral ? `security: ${securityLiteral}` : null,
965
- stylesLiteral ? `styles: ${stylesLiteral}` : null,
966
- validatorLiteral,
971
+ ownRuntime ? null : styles,
967
972
  contentTypeLiteral,
968
973
  buildResponseTypeLiteral(node),
969
974
  "...config",
975
+ ownRuntime ? styles : null,
976
+ validatorLiteral,
970
977
  `throwOnError: config.throwOnError ?? ${throwOnErrorDefault}`
971
978
  ].filter(Boolean).join(", ")} }`,
972
979
  mergeContentType,
@@ -1775,7 +1782,7 @@ var compatibility = {
1775
1782
  "node": ">=22.22"
1776
1783
  };
1777
1784
  // package.json
1778
- var version = "6.1.0-canary.20261109T175349";
1785
+ var version = "6.1.0-canary.20261109T175913";
1779
1786
  // src/plugin.ts
1780
1787
  /**
1781
1788
  * Canonical plugin name for `@kubb/plugin-fetch`. Used for driver lookups and cross-plugin