@kubb/plugin-client 5.11.0-canary.20261106T172015 → 5.11.1
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/{client-CiHb_Cfg.d.ts → client-BxO6Dygu.d.ts} +13 -3
- package/dist/index.cjs +64 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -11
- package/dist/index.js.map +1 -1
- package/dist/templates/client.d.ts +1 -1
- package/dist/templates/core.d.ts +2 -2
- package/dist/templates/sse.d.ts +1 -1
- package/docs/guides/write-your-client.md +3 -0
- package/package.json +5 -5
- package/templates/core.ts +30 -3
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
|
-
*
|
|
115
|
+
* Parser for one response content entry.
|
|
110
116
|
*
|
|
111
|
-
*
|
|
112
|
-
* `
|
|
113
|
-
*
|
|
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
|
|
116
|
-
const baseType =
|
|
122
|
+
function responseTypeForContent(contentType, schema) {
|
|
123
|
+
const baseType = baseContentType(contentType);
|
|
117
124
|
if (!baseType) return void 0;
|
|
118
|
-
if (
|
|
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) {
|
|
@@ -148,7 +191,7 @@ function getRequestGroupOptionality(node) {
|
|
|
148
191
|
hasRequiredPath,
|
|
149
192
|
hasRequiredQuery,
|
|
150
193
|
hasRequiredHeader,
|
|
151
|
-
isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
|
|
194
|
+
isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true)
|
|
152
195
|
};
|
|
153
196
|
}
|
|
154
197
|
function buildOperationComments(node, options = {}) {
|
|
@@ -439,7 +482,7 @@ var compatibility = {
|
|
|
439
482
|
"node": ">=22.22"
|
|
440
483
|
};
|
|
441
484
|
// package.json
|
|
442
|
-
var version = "5.11.
|
|
485
|
+
var version = "5.11.1";
|
|
443
486
|
// ../../internals/client/src/builders/validatorOptions.ts
|
|
444
487
|
/**
|
|
445
488
|
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
@@ -798,6 +841,17 @@ function buildStyles({ node }) {
|
|
|
798
841
|
}
|
|
799
842
|
// ../../internals/client/src/builders/callConfig.ts
|
|
800
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
|
+
/**
|
|
801
855
|
* Builds the call config literal a generated operation forwards to the client, shared by the standalone
|
|
802
856
|
* functions and the SDK methods. The `throwOnError` fallback is applied after the `...config` spread.
|
|
803
857
|
*
|
|
@@ -824,7 +878,6 @@ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault,
|
|
|
824
878
|
"error"
|
|
825
879
|
]);
|
|
826
880
|
const { literal: contentTypeLiteral, merge: mergeContentType } = buildContentType({ node });
|
|
827
|
-
const responseType = getResponseType(node);
|
|
828
881
|
return {
|
|
829
882
|
callConfig: `{ ${[
|
|
830
883
|
`method: '${node.method.toUpperCase()}'`,
|
|
@@ -833,7 +886,7 @@ function buildCallConfig({ node, validatorHooks, security, throwOnErrorDefault,
|
|
|
833
886
|
stylesLiteral ? `styles: ${stylesLiteral}` : null,
|
|
834
887
|
validatorLiteral,
|
|
835
888
|
contentTypeLiteral,
|
|
836
|
-
|
|
889
|
+
buildResponseTypeLiteral(node),
|
|
837
890
|
"...config",
|
|
838
891
|
`throwOnError: config.throwOnError ?? ${throwOnErrorDefault}`
|
|
839
892
|
].filter(Boolean).join(", ")} }`,
|