@kubb/plugin-react-query 5.10.0-canary.20261109T201601 → 5.11.0-canary.20261109T211530
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 +62 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -53
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
let _kubb_kit = require("@kubb/kit");
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
|
-
let _kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
30
29
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
31
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
31
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
@@ -72,10 +71,11 @@ function resolveDependencyOperationFile(options) {
|
|
|
72
71
|
group: group ?? void 0
|
|
73
72
|
}));
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
|
|
76
|
+
*/
|
|
77
|
+
function getOperationRequestLine(node) {
|
|
78
|
+
return _kubb_kit.ast.isHttpOperationNode(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
@@ -137,19 +137,31 @@ function isEventStream(node) {
|
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
140
|
-
* `useInfiniteQuery`, `useSWR`, ...)
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
140
|
+
* `useInfiniteQuery`, `useSWR`, ...): `RequestConfig` minus what the
|
|
141
|
+
* hook fills in, which is every request group and `throwOnError`. Unlike {@link buildRequestConfigType},
|
|
142
|
+
* it never narrows `contentType`: query hooks wrap GET operations, which carry no request body to select
|
|
143
|
+
* a content type for.
|
|
144
144
|
*/
|
|
145
|
-
function buildClientOptionType(
|
|
146
|
-
return `Partial<Omit<RequestConfig,
|
|
145
|
+
function buildClientOptionType(options = {}) {
|
|
146
|
+
return `Partial<Omit<RequestConfig, ${[
|
|
147
|
+
...requestGroupOrder,
|
|
148
|
+
"url",
|
|
149
|
+
...options.omit ?? [],
|
|
150
|
+
"throwOnError"
|
|
151
|
+
].map((key) => `'${key}'`).join(" | ")}>>`;
|
|
147
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The `client?:` option type of a mutation hook. When the operation has a request content type choice,
|
|
155
|
+
* the mutation variables carry `contentType`, so the config leaves it out. Otherwise the ambiguous side is
|
|
156
|
+
* narrowed to the operation's media types; a single-type side has nothing to pick, so it stays baked in the
|
|
157
|
+
* generated call.
|
|
158
|
+
*/
|
|
148
159
|
function buildRequestConfigType(node) {
|
|
160
|
+
if (hasRequestContentTypeChoice(node)) return buildClientOptionType({ omit: ["contentType"] });
|
|
149
161
|
const request = getContentTypeInfo(node);
|
|
150
162
|
const response = getResponseContentTypeInfo(node);
|
|
151
163
|
const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
|
|
152
|
-
const base = buildClientOptionType(
|
|
164
|
+
const base = buildClientOptionType();
|
|
153
165
|
return members.length ? `${base} & { contentType?: { ${members.join("; ")} } }` : base;
|
|
154
166
|
}
|
|
155
167
|
/** The grouped request options, in the order generated signatures and calls list them. */
|
|
@@ -193,19 +205,13 @@ function getRequestGroupOptionality(node) {
|
|
|
193
205
|
};
|
|
194
206
|
}
|
|
195
207
|
function buildOperationComments(node, options = {}) {
|
|
196
|
-
const {
|
|
197
|
-
const
|
|
198
|
-
|
|
208
|
+
const { splitLines = false } = options;
|
|
209
|
+
const filteredComments = [
|
|
210
|
+
getOperationRequestLine(node),
|
|
199
211
|
node.description && `@description ${node.description}`,
|
|
200
212
|
node.summary && `@summary ${node.summary}`,
|
|
201
|
-
linkComment,
|
|
202
213
|
node.deprecated && "@deprecated"
|
|
203
|
-
]
|
|
204
|
-
node.description && `@description ${node.description}`,
|
|
205
|
-
node.summary && `@summary ${node.summary}`,
|
|
206
|
-
node.deprecated && "@deprecated",
|
|
207
|
-
linkComment
|
|
208
|
-
]).filter((comment) => Boolean(comment));
|
|
214
|
+
].filter((comment) => Boolean(comment));
|
|
209
215
|
if (!splitLines) return filteredComments;
|
|
210
216
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
211
217
|
}
|
|
@@ -259,12 +265,6 @@ function getOperationParameters(node) {
|
|
|
259
265
|
function hasRequestContentTypeChoice(node) {
|
|
260
266
|
return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
|
|
261
267
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
|
|
264
|
-
*/
|
|
265
|
-
function castToClientOptions(callArg, clientName, returnType = "full") {
|
|
266
|
-
return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
|
|
267
|
-
}
|
|
268
268
|
function getStatusCodeNumber(statusCode) {
|
|
269
269
|
const code = Number(statusCode);
|
|
270
270
|
return Number.isNaN(code) ? null : code;
|
|
@@ -550,8 +550,9 @@ var compatibility = {
|
|
|
550
550
|
"node": ">=22.22"
|
|
551
551
|
};
|
|
552
552
|
// package.json
|
|
553
|
-
var version = "5.
|
|
553
|
+
var version = "5.11.0-canary.20261109T211530";
|
|
554
554
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
555
|
+
const pluginZodName = "plugin-zod";
|
|
555
556
|
/**
|
|
556
557
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
557
558
|
* exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
|
|
@@ -594,7 +595,7 @@ function toZodTypeResolver(resolver) {
|
|
|
594
595
|
function resolveOperationTypes(driver, pluginName) {
|
|
595
596
|
return driver.memo(`operationTypes:${pluginName}`, () => {
|
|
596
597
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
597
|
-
const pluginZod = driver.getPlugin(
|
|
598
|
+
const pluginZod = driver.getPlugin(pluginZodName);
|
|
598
599
|
if (pluginTs && pluginZod?.options?.inferred !== "codec") {
|
|
599
600
|
const resolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
600
601
|
return {
|
|
@@ -612,7 +613,7 @@ function resolveOperationTypes(driver, pluginName) {
|
|
|
612
613
|
location: { kind: "config" },
|
|
613
614
|
plugin: pluginName
|
|
614
615
|
});
|
|
615
|
-
const resolver = toZodTypeResolver(driver.getResolver(
|
|
616
|
+
const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
|
|
616
617
|
return {
|
|
617
618
|
response: resolver.response,
|
|
618
619
|
resolver,
|
|
@@ -956,8 +957,8 @@ function buildGroupedRequestParam(node, options) {
|
|
|
956
957
|
/**
|
|
957
958
|
* Builds the shared `({ path, query, body, headers, cookies }, config = {})` parameter list for a
|
|
958
959
|
* TanStack query-options function. The leading parameter mirrors the client signature, and the
|
|
959
|
-
* trailing `config` is
|
|
960
|
-
*
|
|
960
|
+
* trailing `config` is the client's `Options` minus the request groups and `throwOnError`, which the
|
|
961
|
+
* hook passes itself. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
|
|
961
962
|
*/
|
|
962
963
|
function buildQueryOptionsParams(node, options) {
|
|
963
964
|
const { resolver, memberTypeWrapper } = options;
|
|
@@ -967,7 +968,7 @@ function buildQueryOptionsParams(node, options) {
|
|
|
967
968
|
});
|
|
968
969
|
const configParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
969
970
|
name: "config",
|
|
970
|
-
type: buildClientOptionType(
|
|
971
|
+
type: buildClientOptionType(),
|
|
971
972
|
default: "{}"
|
|
972
973
|
});
|
|
973
974
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, configParam].filter((param) => param !== null) });
|
|
@@ -979,26 +980,30 @@ function buildQueryOptionsParams(node, options) {
|
|
|
979
980
|
* can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
|
|
980
981
|
*
|
|
981
982
|
* When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
|
|
982
|
-
* used by vue-query to resolve refs and getters with `toValue(...)` at call time.
|
|
983
|
+
* used by vue-query to resolve refs and getters with `toValue(...)` at call time. `pageParam` names the
|
|
984
|
+
* query parameter an infinite query sets from TanStack's `pageParam`.
|
|
983
985
|
*
|
|
984
986
|
* @example
|
|
985
987
|
* ```ts
|
|
986
988
|
* buildClientCall(node, { clientName: 'getPetById', signal: true })
|
|
987
|
-
* // getPetById({
|
|
989
|
+
* // getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true })
|
|
988
990
|
* ```
|
|
989
991
|
*/
|
|
990
992
|
function buildClientCall(node, options) {
|
|
991
|
-
const { clientName, signal = false, unwrapName, withContentType = false,
|
|
993
|
+
const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
|
|
992
994
|
const { groups } = getRequestGroupOptionality(node);
|
|
993
995
|
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
994
|
-
const
|
|
996
|
+
const member = (name) => {
|
|
997
|
+
const value = unwrapName ? unwrapName(name) : name;
|
|
998
|
+
if (name === "query" && pageParam) return `query: { ...${value}, ${JSON.stringify(pageParam)}: pageParam }`;
|
|
999
|
+
return unwrapName ? `${name}: ${value}` : name;
|
|
1000
|
+
};
|
|
1001
|
+
return `${clientName}({ ${[
|
|
995
1002
|
"...config",
|
|
996
|
-
...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(
|
|
1003
|
+
...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(member),
|
|
997
1004
|
signal ? "signal: config.signal ?? signal" : null,
|
|
998
1005
|
"throwOnError: true"
|
|
999
|
-
].filter((part) => part !== null)
|
|
1000
|
-
if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
|
|
1001
|
-
return `${clientName}({ ${args.join(", ")} })`;
|
|
1006
|
+
].filter((part) => part !== null).join(", ")} })`;
|
|
1002
1007
|
}
|
|
1003
1008
|
/**
|
|
1004
1009
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
@@ -1247,9 +1252,15 @@ function buildHookParams(node, options) {
|
|
|
1247
1252
|
}
|
|
1248
1253
|
/**
|
|
1249
1254
|
* The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
|
|
1255
|
+
* When the variables carry the request media type and the response has several, `contentType` can pick the
|
|
1256
|
+
* response one too, as `{ request, response }`.
|
|
1250
1257
|
*/
|
|
1251
1258
|
function resolveMutationRequestType(node, resolver) {
|
|
1252
|
-
|
|
1259
|
+
if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
|
|
1260
|
+
const optionsName = resolver.response.options(node);
|
|
1261
|
+
const response = getResponseContentTypeInfo(node);
|
|
1262
|
+
if (!hasRequestContentTypeChoice(node) || !response.isMultipleContentTypes) return optionsName;
|
|
1263
|
+
return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
|
|
1253
1264
|
}
|
|
1254
1265
|
/**
|
|
1255
1266
|
* Builds the object literal that unwraps each request group's getter before it reaches `queryKey`/`queryOptions`; `null` without a request group.
|
|
@@ -1283,10 +1294,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1283
1294
|
memberTypeWrapper
|
|
1284
1295
|
});
|
|
1285
1296
|
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
1297
|
+
const pageParam = queryParam && queryParamsTypeName ? queryParam : void 0;
|
|
1286
1298
|
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1287
1299
|
clientName,
|
|
1288
1300
|
signal: true,
|
|
1289
|
-
unwrapName
|
|
1301
|
+
unwrapName,
|
|
1302
|
+
pageParam
|
|
1290
1303
|
}), {
|
|
1291
1304
|
clientReturnType,
|
|
1292
1305
|
returnType
|
|
@@ -1313,12 +1326,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1313
1326
|
getNextPageParamExpr,
|
|
1314
1327
|
getPreviousPageParamExpr
|
|
1315
1328
|
].filter(Boolean);
|
|
1316
|
-
const
|
|
1317
|
-
...(query ?? {}),
|
|
1318
|
-
['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
|
|
1319
|
-
} as ${queryParamsTypeName}` : "";
|
|
1320
|
-
const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
|
|
1321
|
-
const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
|
|
1329
|
+
const queryFnArgs = pageParam ? "{ signal, pageParam }" : "{ signal }";
|
|
1322
1330
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1323
1331
|
name,
|
|
1324
1332
|
isExportable: true,
|
|
@@ -1332,7 +1340,7 @@ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
|
1332
1340
|
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
|
|
1333
1341
|
queryKey,
|
|
1334
1342
|
queryFn: async (${queryFnArgs}) => {
|
|
1335
|
-
${
|
|
1343
|
+
${queryFnBody}
|
|
1336
1344
|
},
|
|
1337
1345
|
${queryOptionsArr.join(",\n ")}
|
|
1338
1346
|
})
|
|
@@ -1793,7 +1801,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1793
1801
|
memberTypeWrapper: maybeValueOrGetter,
|
|
1794
1802
|
optionsType: `{
|
|
1795
1803
|
query?: Partial<${observerOptionsType}> & { client?: QueryClient },
|
|
1796
|
-
client?: ${buildClientOptionType(
|
|
1804
|
+
client?: ${buildClientOptionType()}
|
|
1797
1805
|
}`
|
|
1798
1806
|
});
|
|
1799
1807
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
@@ -2057,13 +2065,12 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
2057
2065
|
});
|
|
2058
2066
|
const hasMutationParams = groupedParam !== null;
|
|
2059
2067
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
2060
|
-
const TRequest =
|
|
2068
|
+
const TRequest = resolveMutationRequestType(node, tsResolver);
|
|
2061
2069
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "_";
|
|
2062
2070
|
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
2063
2071
|
clientName,
|
|
2064
2072
|
signal: false,
|
|
2065
|
-
withContentType: true
|
|
2066
|
-
returnType: clientReturnType
|
|
2073
|
+
withContentType: true
|
|
2067
2074
|
}), {
|
|
2068
2075
|
clientReturnType,
|
|
2069
2076
|
returnType
|