@kubb/plugin-client 5.11.0-canary.20261106T171559 → 5.11.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
@@ -105,22 +105,65 @@ function getEventStream(node) {
105
105
  const content = getEventStreamContent(node);
106
106
  return content ? content.stream?.shape ?? "data" : null;
107
107
  }
108
+ function baseContentType(contentType) {
109
+ return contentType.split(";")[0].trim().toLowerCase();
110
+ }
111
+ function isJsonContentType(baseType) {
112
+ return baseType === "application/json" || baseType.endsWith("+json") || baseType === "text/json";
113
+ }
108
114
  /**
109
- * Derives the default `responseType` for an operation from its primary success response.
115
+ * Parser for one response content entry.
110
116
  *
111
- * Returns a value only when that response declares a single non-JSON content type. `text/event-stream` maps to
112
- * `'stream'`, `application/octet-stream`, `application/pdf`, `image/*`, `audio/*` and `video/*` map to `'blob'`, and
113
- * other `text/*` to `'text'`. Otherwise `undefined`, leaving the runtime client's `Content-Type` auto-detection in charge.
117
+ * JSON stays unset so the runtime detects it. `text/event-stream` is a stream. A binary schema
118
+ * (`format: binary` / `contentMediaType`) is a blob even when the media type is not a well-known
119
+ * binary type. Other `text/*` is text, and `application/octet-stream`, `application/pdf`,
120
+ * `image/*`, `audio/*`, and `video/*` are blobs.
114
121
  */
115
- function getResponseType(node) {
116
- const baseType = getPrimarySuccessContentType(node);
122
+ function responseTypeForContent(contentType, schema) {
123
+ const baseType = baseContentType(contentType);
117
124
  if (!baseType) return void 0;
118
- if (baseType === "application/json" || baseType.endsWith("+json") || baseType === "text/json") return void 0;
125
+ if (isJsonContentType(baseType)) return void 0;
119
126
  if (baseType === "text/event-stream") return "stream";
127
+ if (schema?.type === "blob") return "blob";
120
128
  if (baseType.startsWith("text/")) return "text";
121
129
  if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "blob";
122
130
  }
123
131
  /**
132
+ * Derives the default `responseType` string for an operation from its primary success response.
133
+ *
134
+ * One content type uses {@link responseTypeForContent}. Several content types that all use the same
135
+ * parser collapse to that string, so a call can keep `responseType: 'blob'`. Mixed parsers return
136
+ * `undefined`; {@link getResponseTypeMap} carries the per-type choice.
137
+ */
138
+ function getResponseType(node) {
139
+ const entries = getPrimarySuccessResponse(node)?.content ?? [];
140
+ if (entries.length === 0) return void 0;
141
+ const responseTypes = entries.map((entry) => responseTypeForContent(entry.contentType, entry.schema));
142
+ const first = responseTypes[0];
143
+ if (!first) return void 0;
144
+ if (responseTypes.every((responseType) => responseType === first)) return first;
145
+ }
146
+ /**
147
+ * Maps each base content type of a primary success response to its parser when those parsers differ.
148
+ *
149
+ * Keys are lowercased and stripped of parameters. JSON entries are kept as `'json'` so a catch-all
150
+ * entry cannot claim a JSON response. Returns `undefined` when {@link getResponseType} already
151
+ * covers the response with one string, or when no content type needs a parser other than JSON.
152
+ * The runtime matches the response `Content-Type` against this map instead of guessing from the media type.
153
+ */
154
+ function getResponseTypeMap(node) {
155
+ if (getResponseType(node)) return void 0;
156
+ const entries = getPrimarySuccessResponse(node)?.content ?? [];
157
+ if (entries.length <= 1) return void 0;
158
+ const map = {};
159
+ for (const entry of entries) {
160
+ const baseType = baseContentType(entry.contentType);
161
+ const responseType = responseTypeForContent(entry.contentType, entry.schema) ?? (isJsonContentType(baseType) ? "json" : void 0);
162
+ if (baseType && responseType) map[baseType] = responseType;
163
+ }
164
+ return Object.values(map).some((responseType) => responseType !== "json") ? map : void 0;
165
+ }
166
+ /**
124
167
  * Which of the grouped request options an operation carries.
125
168
  */
126
169
  function getRequestGroups(node) {
@@ -194,17 +237,18 @@ function spreadQuerystring(param) {
194
237
  function getOperationParameters(node) {
195
238
  const cached = operationParameterGroupsByNode.get(node);
196
239
  if (cached) return cached;
197
- const group = (location) => {
240
+ const dedupe = (params) => {
198
241
  const seen = /* @__PURE__ */ new Set();
199
- return node.parameters.filter((param) => {
200
- if (param.in !== location || seen.has(param.name)) return false;
242
+ return params.filter((param) => {
243
+ if (seen.has(param.name)) return false;
201
244
  seen.add(param.name);
202
245
  return true;
203
246
  });
204
247
  };
248
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
205
249
  const groups = {
206
250
  path: group("path"),
207
- query: [...group("query"), ...group("querystring").flatMap(spreadQuerystring)],
251
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
208
252
  header: group("header"),
209
253
  cookie: group("cookie")
210
254
  };
@@ -438,7 +482,7 @@ var compatibility = {
438
482
  "node": ">=22.22"
439
483
  };
440
484
  // package.json
441
- var version = "5.11.0-canary.20261106T171559";
485
+ var version = "5.11.0";
442
486
  // ../../internals/client/src/builders/validatorOptions.ts
443
487
  /**
444
488
  * Returns `true` when any direction of the validator uses zod (used for dependency checks).
@@ -797,6 +841,17 @@ function buildStyles({ node }) {
797
841
  }
798
842
  // ../../internals/client/src/builders/callConfig.ts
799
843
  /**
844
+ * `responseType` baked into a call. One parser is a string. Several parsers become a map from content
845
+ * type to parser so the runtime can choose from the response `Content-Type`.
846
+ */
847
+ function buildResponseTypeLiteral(node) {
848
+ const responseType = getResponseType(node);
849
+ if (responseType) return `responseType: '${responseType}'`;
850
+ const responseTypes = getResponseTypeMap(node);
851
+ if (!responseTypes) return null;
852
+ return `responseType: { ${Object.entries(responseTypes).map(([contentType, type]) => `${JSON.stringify(contentType)}: '${type}'`).join(", ")} }`;
853
+ }
854
+ /**
800
855
  * Builds the call config literal a generated operation forwards to the client, shared by the standalone
801
856
  * functions and the SDK methods. The `throwOnError` fallback is applied after the `...config` spread.
802
857
  *
@@ -823,7 +878,6 @@ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault,
823
878
  "error"
824
879
  ]);
825
880
  const { literal: contentTypeLiteral, merge: mergeContentType } = buildContentType({ node });
826
- const responseType = getResponseType(node);
827
881
  return {
828
882
  callConfig: `{ ${[
829
883
  `method: '${node.method.toUpperCase()}'`,
@@ -832,7 +886,7 @@ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault,
832
886
  stylesLiteral ? `styles: ${stylesLiteral}` : null,
833
887
  validatorLiteral,
834
888
  contentTypeLiteral,
835
- responseType ? `responseType: '${responseType}'` : null,
889
+ buildResponseTypeLiteral(node),
836
890
  "...config",
837
891
  `throwOnError: config.throwOnError ?? ${throwOnErrorDefault}`
838
892
  ].filter(Boolean).join(", ")} }`,