@kubb/plugin-react-query 5.0.0-beta.85 → 5.0.0-beta.87
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 +368 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +170 -117
- package/dist/index.js +368 -358
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
|
+
let kubb_kit = require("kubb/kit");
|
|
27
28
|
let node_path = require("node:path");
|
|
28
29
|
node_path = __toESM(node_path, 1);
|
|
29
|
-
let kubb_kit = require("kubb/kit");
|
|
30
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
31
|
let kubb_jsx = require("kubb/jsx");
|
|
32
32
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
@@ -59,31 +59,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
59
59
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
60
60
|
}
|
|
61
61
|
//#endregion
|
|
62
|
-
//#region ../../internals/utils/src/fs.ts
|
|
63
|
-
/**
|
|
64
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
65
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
66
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
67
|
-
*
|
|
68
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
69
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
70
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
71
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
72
|
-
*
|
|
73
|
-
* @example Nested path from a dotted name
|
|
74
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
75
|
-
*
|
|
76
|
-
* @example PascalCase the final segment
|
|
77
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
78
|
-
*
|
|
79
|
-
* @example Suffix applied to the final segment only
|
|
80
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
81
|
-
*/
|
|
82
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
83
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
84
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
85
|
-
}
|
|
86
|
-
//#endregion
|
|
87
62
|
//#region ../../internals/utils/src/reserved.ts
|
|
88
63
|
/**
|
|
89
64
|
* JavaScript and Java reserved words.
|
|
@@ -184,9 +159,42 @@ const reservedWords = /* @__PURE__ */ new Set([
|
|
|
184
159
|
*/
|
|
185
160
|
function isValidVarName(name) {
|
|
186
161
|
if (!name || reservedWords.has(name)) return false;
|
|
162
|
+
return isIdentifier(name);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
166
|
+
*
|
|
167
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
168
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
169
|
+
* deciding whether an object key needs quoting.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* isIdentifier('name') // true
|
|
174
|
+
* isIdentifier('x-total')// false
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
function isIdentifier(name) {
|
|
187
178
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
188
179
|
}
|
|
189
180
|
//#endregion
|
|
181
|
+
//#region ../../internals/utils/src/strings.ts
|
|
182
|
+
/**
|
|
183
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
184
|
+
* `accessor`. Returns `null` for an empty path.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
189
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
function getNestedAccessor(param, accessor) {
|
|
193
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
194
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
195
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
190
198
|
//#region ../../internals/utils/src/url.ts
|
|
191
199
|
function transformParam(raw, casing) {
|
|
192
200
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -339,13 +347,13 @@ function dedupeByCasedName(params) {
|
|
|
339
347
|
//#region ../../internals/shared/src/operation.ts
|
|
340
348
|
/**
|
|
341
349
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
342
|
-
* `resolver.
|
|
350
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
343
351
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
344
352
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
345
353
|
*
|
|
346
354
|
* @example
|
|
347
355
|
* ```ts
|
|
348
|
-
* resolver.
|
|
356
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
349
357
|
* ```
|
|
350
358
|
*/
|
|
351
359
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -362,8 +370,11 @@ function getOperationLink(node, link) {
|
|
|
362
370
|
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
363
371
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
364
372
|
}
|
|
365
|
-
|
|
366
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
375
|
+
* are present and the union, default, and form-data flags the client uses to pick one.
|
|
376
|
+
*/
|
|
377
|
+
function buildContentTypeInfo(contentTypes) {
|
|
367
378
|
const isMultipleContentTypes = contentTypes.length > 1;
|
|
368
379
|
return {
|
|
369
380
|
contentTypes,
|
|
@@ -373,20 +384,15 @@ function getContentTypeInfo(node) {
|
|
|
373
384
|
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
374
385
|
};
|
|
375
386
|
}
|
|
387
|
+
function getContentTypeInfo(node) {
|
|
388
|
+
return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
|
|
389
|
+
}
|
|
376
390
|
/**
|
|
377
391
|
* The request-body counterpart for the primary success response: the content types it documents and
|
|
378
392
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
379
393
|
*/
|
|
380
394
|
function getResponseContentTypeInfo(node) {
|
|
381
|
-
|
|
382
|
-
const isMultipleContentTypes = contentTypes.length > 1;
|
|
383
|
-
return {
|
|
384
|
-
contentTypes,
|
|
385
|
-
isMultipleContentTypes,
|
|
386
|
-
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
387
|
-
defaultContentType: contentTypes[0] ?? "application/json",
|
|
388
|
-
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
389
|
-
};
|
|
395
|
+
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
390
396
|
}
|
|
391
397
|
function buildRequestConfigType(node) {
|
|
392
398
|
const request = getContentTypeInfo(node);
|
|
@@ -483,13 +489,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
483
489
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
484
490
|
}
|
|
485
491
|
function resolveErrorNames(node, resolver) {
|
|
486
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
492
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
487
493
|
}
|
|
488
494
|
function resolveSuccessNames(node, resolver) {
|
|
489
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
495
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
490
496
|
}
|
|
491
497
|
function resolveStatusCodeNames(node, resolver) {
|
|
492
|
-
return node.responses.map((response) => resolver.
|
|
498
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
493
499
|
}
|
|
494
500
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
495
501
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -506,11 +512,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
506
512
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
507
513
|
const exclude = new Set(options.exclude ?? []);
|
|
508
514
|
const paramNames = options.includeParams === false ? [] : [
|
|
509
|
-
...path.map((param) => resolver.
|
|
510
|
-
...query.map((param) => resolver.
|
|
511
|
-
...header.map((param) => resolver.
|
|
515
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
516
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
517
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
512
518
|
];
|
|
513
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
519
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
514
520
|
const result = (options.order === "body-response-first" ? [
|
|
515
521
|
...bodyAndResponseNames,
|
|
516
522
|
...paramNames,
|
|
@@ -634,15 +640,15 @@ function resolveClientOperation(options) {
|
|
|
634
640
|
const { clientPlugin, driver, node, root, output } = options;
|
|
635
641
|
if (!clientPlugin) return null;
|
|
636
642
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
637
|
-
if (!resolver) return null;
|
|
638
643
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
639
|
-
const file = resolver.
|
|
644
|
+
const file = resolver.file({
|
|
645
|
+
...operationFileEntry(node, node.operationId),
|
|
640
646
|
root,
|
|
641
647
|
output: plugin?.options?.output ?? output,
|
|
642
648
|
group: plugin?.options?.group ?? void 0
|
|
643
649
|
});
|
|
644
650
|
return {
|
|
645
|
-
name: resolver.
|
|
651
|
+
name: resolver.name(node.operationId),
|
|
646
652
|
path: file.path,
|
|
647
653
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
648
654
|
};
|
|
@@ -692,12 +698,12 @@ function maybeValueOrGetter(type) {
|
|
|
692
698
|
/**
|
|
693
699
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
694
700
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
695
|
-
* operation's `
|
|
701
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
696
702
|
* never carries `headers`.
|
|
697
703
|
*
|
|
698
|
-
* By default the whole group is typed as the single `
|
|
704
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
699
705
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
700
|
-
* `
|
|
706
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
701
707
|
* `MaybeRefOrGetter` per group.
|
|
702
708
|
*/
|
|
703
709
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -712,13 +718,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
712
718
|
headers: hasRequiredHeader
|
|
713
719
|
};
|
|
714
720
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
715
|
-
const
|
|
721
|
+
const optionsName = resolver.response.options(node);
|
|
716
722
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
717
|
-
const
|
|
723
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
718
724
|
if (memberTypeWrapper) {
|
|
719
725
|
const members = names.map((name) => ({
|
|
720
726
|
name,
|
|
721
|
-
type: memberTypeWrapper(`${
|
|
727
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
722
728
|
optional: !requiredByGroup[name]
|
|
723
729
|
}));
|
|
724
730
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
@@ -730,7 +736,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
730
736
|
}
|
|
731
737
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
732
738
|
name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
|
|
733
|
-
type:
|
|
739
|
+
type: optionsType,
|
|
734
740
|
optional: false,
|
|
735
741
|
...isOptional ? { default: "{}" } : {}
|
|
736
742
|
});
|
|
@@ -798,7 +804,7 @@ function resolveOperationOverrides(node, override) {
|
|
|
798
804
|
}
|
|
799
805
|
/**
|
|
800
806
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
801
|
-
* typed from the operation's `
|
|
807
|
+
* typed from the operation's `Options` minus `url`. The query key transformer reads the
|
|
802
808
|
* grouped `path`/`query`/`body` bindings.
|
|
803
809
|
*/
|
|
804
810
|
function buildQueryKeyParams(node, options) {
|
|
@@ -870,19 +876,18 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
870
876
|
const { output, customOptions, query, group } = ctx.options;
|
|
871
877
|
if (!customOptions) return null;
|
|
872
878
|
const { importPath, name } = customOptions;
|
|
873
|
-
const hookOptionsName = resolver.
|
|
874
|
-
const customHookOptionsName = resolver.
|
|
879
|
+
const hookOptionsName = resolver.hook.optionsName();
|
|
880
|
+
const customHookOptionsName = resolver.hook.customOptionsName();
|
|
875
881
|
const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
|
|
876
882
|
let hookFilePath;
|
|
877
883
|
const firstNode = nodes[0];
|
|
878
884
|
if (firstNode) {
|
|
879
|
-
const hookName = resolver.
|
|
880
|
-
hookFilePath = resolver.
|
|
885
|
+
const hookName = resolver.query.name(firstNode);
|
|
886
|
+
hookFilePath = resolver.file({
|
|
881
887
|
name: hookName,
|
|
882
888
|
extname: ".ts",
|
|
883
889
|
tag: firstNode.tags[0] ?? "default",
|
|
884
|
-
path: firstNode.path
|
|
885
|
-
}, {
|
|
890
|
+
path: firstNode.path,
|
|
886
891
|
root,
|
|
887
892
|
output,
|
|
888
893
|
group: group ?? void 0
|
|
@@ -974,6 +979,59 @@ function buildResolvedRequestParams(node) {
|
|
|
974
979
|
if (names.length === 0) return null;
|
|
975
980
|
return `{ ${names.map((name) => `${name}: typeof ${name} === 'function' ? ${name}() : ${name}`).join(", ")} }`;
|
|
976
981
|
}
|
|
982
|
+
/**
|
|
983
|
+
* Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
|
|
984
|
+
* `query: false` still marks the operation as a query so the query-family generators keep matching it,
|
|
985
|
+
* and a method already claimed by `query` never counts as a mutation.
|
|
986
|
+
*/
|
|
987
|
+
function classifyOperation(node, { query, mutation }) {
|
|
988
|
+
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
989
|
+
const queryMethods = new Set(query ? query.methods : []);
|
|
990
|
+
return {
|
|
991
|
+
isQuery,
|
|
992
|
+
isMutation: mutation !== false && !isQuery && (mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
997
|
+
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
998
|
+
*/
|
|
999
|
+
function buildResponseTypes(node, resolver) {
|
|
1000
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1001
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1002
|
+
const errorNames = resolveErrorNames(node, resolver);
|
|
1003
|
+
return {
|
|
1004
|
+
TData: responseName,
|
|
1005
|
+
TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
function resolveFallbackPageParamType(initialPageParam) {
|
|
1009
|
+
if (typeof initialPageParam === "number") return "number";
|
|
1010
|
+
if (typeof initialPageParam === "boolean") return "boolean";
|
|
1011
|
+
if (typeof initialPageParam !== "string") return "unknown";
|
|
1012
|
+
if (!initialPageParam.includes(" as ")) return "string";
|
|
1013
|
+
return initialPageParam.split(" as ").at(-1) ?? "unknown";
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
|
|
1017
|
+
* configured `queryParam` on the operation's query object, and falls back to the type inferred from
|
|
1018
|
+
* `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
|
|
1019
|
+
* so callers can reuse it when rewriting the paginated request.
|
|
1020
|
+
*/
|
|
1021
|
+
function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
|
|
1022
|
+
const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
|
|
1023
|
+
const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
|
|
1024
|
+
const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
|
|
1025
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1026
|
+
if (!queryParamType) return {
|
|
1027
|
+
queryParamsTypeName,
|
|
1028
|
+
pageParamType: resolveFallbackPageParamType(initialPageParam)
|
|
1029
|
+
};
|
|
1030
|
+
return {
|
|
1031
|
+
queryParamsTypeName,
|
|
1032
|
+
pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
977
1035
|
//#endregion
|
|
978
1036
|
//#region src/generators/hookOptionsGenerator.tsx
|
|
979
1037
|
/**
|
|
@@ -989,11 +1047,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
989
1047
|
const { resolver, config, root } = ctx;
|
|
990
1048
|
const { output, customOptions, query, mutation, suspense, infinite, group, override, hooks } = ctx.options;
|
|
991
1049
|
if (!customOptions || !hooks) return null;
|
|
992
|
-
const name = resolver.
|
|
993
|
-
const resolvedFile = resolver.
|
|
1050
|
+
const name = resolver.hook.optionsName();
|
|
1051
|
+
const resolvedFile = resolver.file({
|
|
994
1052
|
name,
|
|
995
|
-
extname: ".ts"
|
|
996
|
-
}, {
|
|
1053
|
+
extname: ".ts",
|
|
997
1054
|
root,
|
|
998
1055
|
output,
|
|
999
1056
|
group: group ?? void 0
|
|
@@ -1018,9 +1075,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1018
1075
|
const isSuspenseOp = !!suspense;
|
|
1019
1076
|
const isInfiniteOp = !!nodeInfiniteOptions;
|
|
1020
1077
|
if (isQueryOp) {
|
|
1021
|
-
const queryOptionsName = resolver.
|
|
1022
|
-
const queryHookName = resolver.
|
|
1023
|
-
const queryHookFile = resolver.
|
|
1078
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
1079
|
+
const queryHookName = resolver.query.name(node);
|
|
1080
|
+
const queryHookFile = resolver.file({
|
|
1081
|
+
...operationFileEntry(node, queryHookName),
|
|
1024
1082
|
root,
|
|
1025
1083
|
output,
|
|
1026
1084
|
group: group ?? void 0
|
|
@@ -1032,9 +1090,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1032
1090
|
}));
|
|
1033
1091
|
hookOptions[queryHookName] = `Partial<ReturnType<typeof ${queryOptionsName}>>`;
|
|
1034
1092
|
if (isSuspenseOp) {
|
|
1035
|
-
const suspenseOptionsName = resolver.
|
|
1036
|
-
const suspenseHookName = resolver.
|
|
1037
|
-
const suspenseHookFile = resolver.
|
|
1093
|
+
const suspenseOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
1094
|
+
const suspenseHookName = resolver.suspenseQuery.name(node);
|
|
1095
|
+
const suspenseHookFile = resolver.file({
|
|
1096
|
+
...operationFileEntry(node, suspenseHookName),
|
|
1038
1097
|
root,
|
|
1039
1098
|
output,
|
|
1040
1099
|
group: group ?? void 0
|
|
@@ -1050,9 +1109,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1050
1109
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1051
1110
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
1052
1111
|
if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
|
|
1053
|
-
const infiniteOptionsName = resolver.
|
|
1054
|
-
const infiniteHookName = resolver.
|
|
1055
|
-
const infiniteHookFile = resolver.
|
|
1112
|
+
const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1113
|
+
const infiniteHookName = resolver.infiniteQuery.name(node);
|
|
1114
|
+
const infiniteHookFile = resolver.file({
|
|
1115
|
+
...operationFileEntry(node, infiniteHookName),
|
|
1056
1116
|
root,
|
|
1057
1117
|
output,
|
|
1058
1118
|
group: group ?? void 0
|
|
@@ -1064,9 +1124,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1064
1124
|
}));
|
|
1065
1125
|
hookOptions[infiniteHookName] = `Partial<ReturnType<typeof ${infiniteOptionsName}>>`;
|
|
1066
1126
|
if (isSuspenseOp) {
|
|
1067
|
-
const suspenseInfiniteOptionsName = resolver.
|
|
1068
|
-
const suspenseInfiniteHookName = resolver.
|
|
1069
|
-
const suspenseInfiniteHookFile = resolver.
|
|
1127
|
+
const suspenseInfiniteOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
1128
|
+
const suspenseInfiniteHookName = resolver.suspenseInfiniteQuery.name(node);
|
|
1129
|
+
const suspenseInfiniteHookFile = resolver.file({
|
|
1130
|
+
...operationFileEntry(node, suspenseInfiniteHookName),
|
|
1070
1131
|
root,
|
|
1071
1132
|
output,
|
|
1072
1133
|
group: group ?? void 0
|
|
@@ -1082,9 +1143,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1082
1143
|
}
|
|
1083
1144
|
}
|
|
1084
1145
|
if (isMutationOp) {
|
|
1085
|
-
const mutationOptionsName = resolver.
|
|
1086
|
-
const mutationHookName = resolver.
|
|
1087
|
-
const mutationHookFile = resolver.
|
|
1146
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1147
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1148
|
+
const mutationHookFile = resolver.file({
|
|
1149
|
+
...operationFileEntry(node, mutationHookName),
|
|
1088
1150
|
root,
|
|
1089
1151
|
output,
|
|
1090
1152
|
group: group ?? void 0
|
|
@@ -1101,7 +1163,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1101
1163
|
baseName: hookOptionsFile.baseName,
|
|
1102
1164
|
path: hookOptionsFile.path,
|
|
1103
1165
|
meta: hookOptionsFile.meta,
|
|
1104
|
-
banner: resolver.
|
|
1166
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1105
1167
|
output,
|
|
1106
1168
|
config,
|
|
1107
1169
|
file: {
|
|
@@ -1109,7 +1171,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1109
1171
|
baseName: hookOptionsFile.baseName
|
|
1110
1172
|
}
|
|
1111
1173
|
}),
|
|
1112
|
-
footer: resolver.
|
|
1174
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1113
1175
|
output,
|
|
1114
1176
|
config,
|
|
1115
1177
|
file: {
|
|
@@ -1150,23 +1212,12 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
1150
1212
|
}), optionsParam].filter((param) => param !== null) });
|
|
1151
1213
|
}
|
|
1152
1214
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
1160
|
-
const parts = initialPageParam.split(" as ");
|
|
1161
|
-
return parts[parts.length - 1] ?? "unknown";
|
|
1162
|
-
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1163
|
-
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1164
|
-
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1165
|
-
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1166
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1167
|
-
})() : null;
|
|
1168
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1169
|
-
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1215
|
+
const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1216
|
+
const { pageParamType } = resolvePageParamType(node, {
|
|
1217
|
+
resolver: tsResolver,
|
|
1218
|
+
initialPageParam,
|
|
1219
|
+
queryParam
|
|
1220
|
+
});
|
|
1170
1221
|
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1171
1222
|
const generics = [
|
|
1172
1223
|
`TQueryFnData = ${responseType}`,
|
|
@@ -1220,11 +1271,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
1220
1271
|
return buildQueryOptionsParams(node, options);
|
|
1221
1272
|
}
|
|
1222
1273
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
1223
|
-
const
|
|
1224
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1225
|
-
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1226
|
-
const TData = responseName;
|
|
1227
|
-
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1274
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1228
1275
|
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1229
1276
|
const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
|
|
1230
1277
|
const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
|
|
@@ -1259,22 +1306,12 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
|
1259
1306
|
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1260
1307
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1261
1308
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1262
|
-
const
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const parts = initialPageParam.split(" as ");
|
|
1269
|
-
return parts[parts.length - 1] ?? "unknown";
|
|
1270
|
-
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1271
|
-
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1272
|
-
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1273
|
-
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1274
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1275
|
-
})() : null;
|
|
1276
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1277
|
-
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1309
|
+
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1310
|
+
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
1311
|
+
resolver: tsResolver,
|
|
1312
|
+
initialPageParam,
|
|
1313
|
+
queryParam
|
|
1314
|
+
});
|
|
1278
1315
|
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1279
1316
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
1280
1317
|
const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
|
|
@@ -1287,8 +1324,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1287
1324
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1288
1325
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1289
1326
|
if (hasNewParams) {
|
|
1290
|
-
const nextAccessor = nextParam ?
|
|
1291
|
-
const prevAccessor = previousParam ?
|
|
1327
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1328
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1292
1329
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1293
1330
|
}
|
|
1294
1331
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1357,16 +1394,13 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1357
1394
|
})] });
|
|
1358
1395
|
}
|
|
1359
1396
|
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1360
|
-
const
|
|
1361
|
-
const TData = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1362
|
-
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1363
|
-
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1397
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1364
1398
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1365
1399
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
1366
1400
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1367
1401
|
const hasMutationParams = groupedParam !== null;
|
|
1368
1402
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1369
|
-
const TRequest = hasMutationParams ? tsResolver.
|
|
1403
|
+
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1370
1404
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1371
1405
|
const mutationFnBody = `const { data } = await ${buildClientCall(node, {
|
|
1372
1406
|
clientName,
|
|
@@ -1399,19 +1433,17 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1399
1433
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1400
1434
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1401
1435
|
function resolveMutationRequestType(node, resolver) {
|
|
1402
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1436
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1403
1437
|
}
|
|
1404
1438
|
function buildMutationParamsNode(node, options) {
|
|
1405
1439
|
const { resolver } = options;
|
|
1406
|
-
const
|
|
1407
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1408
|
-
const errorNames = resolveErrorNames(node, resolver);
|
|
1440
|
+
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1409
1441
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1410
1442
|
name: "options",
|
|
1411
1443
|
type: `{
|
|
1412
1444
|
mutation?: UseMutationOptions<${[
|
|
1413
|
-
|
|
1414
|
-
|
|
1445
|
+
TData,
|
|
1446
|
+
TError,
|
|
1415
1447
|
resolveMutationRequestType(node, resolver),
|
|
1416
1448
|
"TContext"
|
|
1417
1449
|
].join(", ")}> & { client?: QueryClient },
|
|
@@ -1421,12 +1453,10 @@ function buildMutationParamsNode(node, options) {
|
|
|
1421
1453
|
})] });
|
|
1422
1454
|
}
|
|
1423
1455
|
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1424
|
-
const
|
|
1425
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1426
|
-
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1456
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1427
1457
|
const generics = [
|
|
1428
|
-
|
|
1429
|
-
|
|
1458
|
+
TData,
|
|
1459
|
+
TError,
|
|
1430
1460
|
resolveMutationRequestType(node, tsResolver),
|
|
1431
1461
|
"TContext"
|
|
1432
1462
|
].join(", ");
|
|
@@ -1466,15 +1496,13 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
|
|
|
1466
1496
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1467
1497
|
function buildQueryParamsNode(node, options) {
|
|
1468
1498
|
const { resolver } = options;
|
|
1469
|
-
const
|
|
1470
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1471
|
-
const errorNames = resolveErrorNames(node, resolver);
|
|
1499
|
+
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1472
1500
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1473
1501
|
name: "options",
|
|
1474
1502
|
type: `{
|
|
1475
1503
|
query?: Partial<QueryObserverOptions<${[
|
|
1476
|
-
|
|
1477
|
-
|
|
1504
|
+
TData,
|
|
1505
|
+
TError,
|
|
1478
1506
|
"TData",
|
|
1479
1507
|
"TQueryData",
|
|
1480
1508
|
"TQueryKey"
|
|
@@ -1489,11 +1517,8 @@ function buildQueryParamsNode(node, options) {
|
|
|
1489
1517
|
}), optionsParam].filter((param) => param !== null) });
|
|
1490
1518
|
}
|
|
1491
1519
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1492
|
-
const
|
|
1493
|
-
const
|
|
1494
|
-
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1495
|
-
const TData = responseName;
|
|
1496
|
-
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1520
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1521
|
+
const returnType = `UseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
|
|
1497
1522
|
const generics = [
|
|
1498
1523
|
`TData = ${TData}`,
|
|
1499
1524
|
`TQueryData = ${TData}`,
|
|
@@ -1552,23 +1577,12 @@ function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
|
1552
1577
|
}), optionsParam].filter((param) => param !== null) });
|
|
1553
1578
|
}
|
|
1554
1579
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1555
|
-
const
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
|
|
1562
|
-
const parts = initialPageParam.split(" as ");
|
|
1563
|
-
return parts[parts.length - 1] ?? "unknown";
|
|
1564
|
-
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1565
|
-
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1566
|
-
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1567
|
-
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1568
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1569
|
-
})() : null;
|
|
1570
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1571
|
-
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1580
|
+
const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1581
|
+
const { pageParamType } = resolvePageParamType(node, {
|
|
1582
|
+
resolver: tsResolver,
|
|
1583
|
+
initialPageParam,
|
|
1584
|
+
queryParam
|
|
1585
|
+
});
|
|
1572
1586
|
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1573
1587
|
const generics = [
|
|
1574
1588
|
`TQueryFnData = ${responseType}`,
|
|
@@ -1619,22 +1633,12 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1619
1633
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1620
1634
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1621
1635
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1622
|
-
const
|
|
1623
|
-
const
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
const parts = initialPageParam.split(" as ");
|
|
1629
|
-
return parts[parts.length - 1] ?? "unknown";
|
|
1630
|
-
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1631
|
-
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1632
|
-
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1633
|
-
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1634
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1635
|
-
})() : null;
|
|
1636
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1637
|
-
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1636
|
+
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1637
|
+
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
1638
|
+
resolver: tsResolver,
|
|
1639
|
+
initialPageParam,
|
|
1640
|
+
queryParam
|
|
1641
|
+
});
|
|
1638
1642
|
const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
|
|
1639
1643
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1640
1644
|
const queryFnBody = `const { data } = await ${buildClientCall(node, {
|
|
@@ -1647,8 +1651,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1647
1651
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1648
1652
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1649
1653
|
if (hasNewParams) {
|
|
1650
|
-
const nextAccessor = nextParam ?
|
|
1651
|
-
const prevAccessor = previousParam ?
|
|
1654
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1655
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1652
1656
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1653
1657
|
}
|
|
1654
1658
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1710,15 +1714,13 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1710
1714
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1711
1715
|
function buildSuspenseQueryParamsNode(node, options) {
|
|
1712
1716
|
const { resolver } = options;
|
|
1713
|
-
const
|
|
1714
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1715
|
-
const errorNames = resolveErrorNames(node, resolver);
|
|
1717
|
+
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1716
1718
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1717
1719
|
name: "options",
|
|
1718
1720
|
type: `{
|
|
1719
1721
|
query?: Partial<UseSuspenseQueryOptions<${[
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
+
TData,
|
|
1723
|
+
TError,
|
|
1722
1724
|
"TData",
|
|
1723
1725
|
"TQueryKey"
|
|
1724
1726
|
].join(", ")}>> & { client?: QueryClient },
|
|
@@ -1732,11 +1734,8 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1732
1734
|
}), optionsParam].filter((param) => param !== null) });
|
|
1733
1735
|
}
|
|
1734
1736
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1735
|
-
const
|
|
1736
|
-
const
|
|
1737
|
-
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1738
|
-
const TData = responseName;
|
|
1739
|
-
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1737
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1738
|
+
const returnType = `UseSuspenseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
|
|
1740
1739
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1741
1740
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1742
1741
|
const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
|
|
@@ -1790,16 +1789,15 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1790
1789
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1791
1790
|
if (!pluginTs) return null;
|
|
1792
1791
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1793
|
-
const isQuery
|
|
1794
|
-
|
|
1795
|
-
|
|
1792
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1793
|
+
query,
|
|
1794
|
+
mutation
|
|
1795
|
+
});
|
|
1796
1796
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1797
1797
|
if (!isQuery || isMutation || !infiniteOptions) return null;
|
|
1798
1798
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1799
1799
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
1800
|
-
|
|
1801
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
1802
|
-
if (!hasQueryParam || !hasCursorParam) return null;
|
|
1800
|
+
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1803
1801
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1804
1802
|
const contractOp = resolveClientOperation({
|
|
1805
1803
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1809,26 +1807,28 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1809
1807
|
output
|
|
1810
1808
|
});
|
|
1811
1809
|
if (!contractOp) return null;
|
|
1812
|
-
const queryName = resolver.
|
|
1813
|
-
const queryOptionsName = resolver.
|
|
1814
|
-
const queryKeyName = resolver.
|
|
1815
|
-
const queryKeyTypeName = resolver.
|
|
1810
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1811
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1812
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1813
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1816
1814
|
const meta = {
|
|
1817
|
-
file: resolver.
|
|
1815
|
+
file: resolver.file({
|
|
1816
|
+
...operationFileEntry(node, queryName),
|
|
1818
1817
|
root,
|
|
1819
1818
|
output,
|
|
1820
1819
|
group: group ?? void 0
|
|
1821
1820
|
}),
|
|
1822
|
-
fileTs: tsResolver.
|
|
1821
|
+
fileTs: tsResolver.file({
|
|
1822
|
+
...operationFileEntry(node, node.operationId),
|
|
1823
1823
|
root,
|
|
1824
1824
|
output: pluginTs.options?.output ?? output,
|
|
1825
1825
|
group: pluginTs.options?.group ?? void 0
|
|
1826
1826
|
})
|
|
1827
1827
|
};
|
|
1828
1828
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1829
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1829
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
1830
1830
|
const importedTypeNames = [
|
|
1831
|
-
tsResolver.
|
|
1831
|
+
tsResolver.response.options(node),
|
|
1832
1832
|
queryParamsTypeName,
|
|
1833
1833
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1834
1834
|
exclude: [queryKeyTypeName],
|
|
@@ -1841,7 +1841,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1841
1841
|
baseName: meta.file.baseName,
|
|
1842
1842
|
path: meta.file.path,
|
|
1843
1843
|
meta: meta.file.meta,
|
|
1844
|
-
banner: resolver.
|
|
1844
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1845
1845
|
output,
|
|
1846
1846
|
config,
|
|
1847
1847
|
file: {
|
|
@@ -1849,7 +1849,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1849
1849
|
baseName: meta.file.baseName
|
|
1850
1850
|
}
|
|
1851
1851
|
}),
|
|
1852
|
-
footer: resolver.
|
|
1852
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1853
1853
|
output,
|
|
1854
1854
|
config,
|
|
1855
1855
|
file: {
|
|
@@ -1955,9 +1955,11 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1955
1955
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1956
1956
|
if (!pluginTs) return null;
|
|
1957
1957
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1960
|
-
|
|
1958
|
+
const { isMutation } = classifyOperation(node, {
|
|
1959
|
+
query,
|
|
1960
|
+
mutation
|
|
1961
|
+
});
|
|
1962
|
+
if (!isMutation) return null;
|
|
1961
1963
|
const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
|
|
1962
1964
|
const contractOp = resolveClientOperation({
|
|
1963
1965
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1967,23 +1969,25 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1967
1969
|
output
|
|
1968
1970
|
});
|
|
1969
1971
|
if (!contractOp) return null;
|
|
1970
|
-
const mutationHookName = resolver.
|
|
1971
|
-
const mutationTypeName = resolver.
|
|
1972
|
-
const mutationOptionsName = resolver.
|
|
1973
|
-
const mutationKeyName = resolver.
|
|
1972
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1973
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1974
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1975
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1974
1976
|
const meta = {
|
|
1975
|
-
file: resolver.
|
|
1977
|
+
file: resolver.file({
|
|
1978
|
+
...operationFileEntry(node, mutationHookName),
|
|
1976
1979
|
root,
|
|
1977
1980
|
output,
|
|
1978
1981
|
group: group ?? void 0
|
|
1979
1982
|
}),
|
|
1980
|
-
fileTs: tsResolver.
|
|
1983
|
+
fileTs: tsResolver.file({
|
|
1984
|
+
...operationFileEntry(node, node.operationId),
|
|
1981
1985
|
root,
|
|
1982
1986
|
output: pluginTs.options?.output ?? output,
|
|
1983
1987
|
group: pluginTs.options?.group ?? void 0
|
|
1984
1988
|
})
|
|
1985
1989
|
};
|
|
1986
|
-
const importedTypeNames = [tsResolver.
|
|
1990
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1987
1991
|
order: "body-response-first",
|
|
1988
1992
|
includeParams: false
|
|
1989
1993
|
})].filter((name) => Boolean(name));
|
|
@@ -1992,7 +1996,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1992
1996
|
baseName: meta.file.baseName,
|
|
1993
1997
|
path: meta.file.path,
|
|
1994
1998
|
meta: meta.file.meta,
|
|
1995
|
-
banner: resolver.
|
|
1999
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1996
2000
|
output,
|
|
1997
2001
|
config,
|
|
1998
2002
|
file: {
|
|
@@ -2000,7 +2004,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2000
2004
|
baseName: meta.file.baseName
|
|
2001
2005
|
}
|
|
2002
2006
|
}),
|
|
2003
|
-
footer: resolver.
|
|
2007
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2004
2008
|
output,
|
|
2005
2009
|
config,
|
|
2006
2010
|
file: {
|
|
@@ -2091,9 +2095,10 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2091
2095
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2092
2096
|
if (!pluginTs) return null;
|
|
2093
2097
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2094
|
-
const isQuery
|
|
2095
|
-
|
|
2096
|
-
|
|
2098
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
2099
|
+
query,
|
|
2100
|
+
mutation
|
|
2101
|
+
});
|
|
2097
2102
|
if (!isQuery || isMutation) return null;
|
|
2098
2103
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2099
2104
|
const contractOp = resolveClientOperation({
|
|
@@ -2104,23 +2109,25 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2104
2109
|
output
|
|
2105
2110
|
});
|
|
2106
2111
|
if (!contractOp) return null;
|
|
2107
|
-
const queryName = resolver.
|
|
2108
|
-
const queryOptionsName = resolver.
|
|
2109
|
-
const queryKeyName = resolver.
|
|
2110
|
-
const queryKeyTypeName = resolver.
|
|
2112
|
+
const queryName = resolver.query.name(node);
|
|
2113
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
2114
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
2115
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
2111
2116
|
const meta = {
|
|
2112
|
-
file: resolver.
|
|
2117
|
+
file: resolver.file({
|
|
2118
|
+
...operationFileEntry(node, queryName),
|
|
2113
2119
|
root,
|
|
2114
2120
|
output,
|
|
2115
2121
|
group: group ?? void 0
|
|
2116
2122
|
}),
|
|
2117
|
-
fileTs: tsResolver.
|
|
2123
|
+
fileTs: tsResolver.file({
|
|
2124
|
+
...operationFileEntry(node, node.operationId),
|
|
2118
2125
|
root,
|
|
2119
2126
|
output: pluginTs.options?.output ?? output,
|
|
2120
2127
|
group: pluginTs.options?.group ?? void 0
|
|
2121
2128
|
})
|
|
2122
2129
|
};
|
|
2123
|
-
const importedTypeNames = [tsResolver.
|
|
2130
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2124
2131
|
exclude: [queryKeyTypeName],
|
|
2125
2132
|
order: "body-response-first",
|
|
2126
2133
|
includeParams: false
|
|
@@ -2130,7 +2137,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2130
2137
|
baseName: meta.file.baseName,
|
|
2131
2138
|
path: meta.file.path,
|
|
2132
2139
|
meta: meta.file.meta,
|
|
2133
|
-
banner: resolver.
|
|
2140
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2134
2141
|
output,
|
|
2135
2142
|
config,
|
|
2136
2143
|
file: {
|
|
@@ -2138,7 +2145,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2138
2145
|
baseName: meta.file.baseName
|
|
2139
2146
|
}
|
|
2140
2147
|
}),
|
|
2141
|
-
footer: resolver.
|
|
2148
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2142
2149
|
output,
|
|
2143
2150
|
config,
|
|
2144
2151
|
file: {
|
|
@@ -2233,17 +2240,16 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2233
2240
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2234
2241
|
if (!pluginTs) return null;
|
|
2235
2242
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2236
|
-
const isQuery
|
|
2237
|
-
|
|
2238
|
-
|
|
2243
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
2244
|
+
query,
|
|
2245
|
+
mutation
|
|
2246
|
+
});
|
|
2239
2247
|
const isSuspense = !!suspense;
|
|
2240
2248
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
2241
2249
|
if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
|
|
2242
2250
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
2243
2251
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
2244
|
-
|
|
2245
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
2246
|
-
if (!hasQueryParam || !hasCursorParam) return null;
|
|
2252
|
+
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
2247
2253
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2248
2254
|
const contractOp = resolveClientOperation({
|
|
2249
2255
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -2253,26 +2259,28 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2253
2259
|
output
|
|
2254
2260
|
});
|
|
2255
2261
|
if (!contractOp) return null;
|
|
2256
|
-
const queryName = resolver.
|
|
2257
|
-
const queryOptionsName = resolver.
|
|
2258
|
-
const queryKeyName = resolver.
|
|
2259
|
-
const queryKeyTypeName = resolver.
|
|
2262
|
+
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
2263
|
+
const queryOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
2264
|
+
const queryKeyName = resolver.suspenseInfiniteQuery.keyName(node);
|
|
2265
|
+
const queryKeyTypeName = resolver.suspenseInfiniteQuery.keyTypeName(node);
|
|
2260
2266
|
const meta = {
|
|
2261
|
-
file: resolver.
|
|
2267
|
+
file: resolver.file({
|
|
2268
|
+
...operationFileEntry(node, queryName),
|
|
2262
2269
|
root,
|
|
2263
2270
|
output,
|
|
2264
2271
|
group: group ?? void 0
|
|
2265
2272
|
}),
|
|
2266
|
-
fileTs: tsResolver.
|
|
2273
|
+
fileTs: tsResolver.file({
|
|
2274
|
+
...operationFileEntry(node, node.operationId),
|
|
2267
2275
|
root,
|
|
2268
2276
|
output: pluginTs.options?.output ?? output,
|
|
2269
2277
|
group: pluginTs.options?.group ?? void 0
|
|
2270
2278
|
})
|
|
2271
2279
|
};
|
|
2272
2280
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
2273
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
2281
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
2274
2282
|
const importedTypeNames = [
|
|
2275
|
-
tsResolver.
|
|
2283
|
+
tsResolver.response.options(node),
|
|
2276
2284
|
queryParamsTypeName,
|
|
2277
2285
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
2278
2286
|
order: "body-response-first",
|
|
@@ -2284,7 +2292,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2284
2292
|
baseName: meta.file.baseName,
|
|
2285
2293
|
path: meta.file.path,
|
|
2286
2294
|
meta: meta.file.meta,
|
|
2287
|
-
banner: resolver.
|
|
2295
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2288
2296
|
output,
|
|
2289
2297
|
config,
|
|
2290
2298
|
file: {
|
|
@@ -2292,7 +2300,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2292
2300
|
baseName: meta.file.baseName
|
|
2293
2301
|
}
|
|
2294
2302
|
}),
|
|
2295
|
-
footer: resolver.
|
|
2303
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2296
2304
|
output,
|
|
2297
2305
|
config,
|
|
2298
2306
|
file: {
|
|
@@ -2399,9 +2407,10 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2399
2407
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2400
2408
|
if (!pluginTs) return null;
|
|
2401
2409
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2402
|
-
const isQuery
|
|
2403
|
-
|
|
2404
|
-
|
|
2410
|
+
const { isQuery, isMutation } = classifyOperation(node, {
|
|
2411
|
+
query,
|
|
2412
|
+
mutation
|
|
2413
|
+
});
|
|
2405
2414
|
if (!isQuery || isMutation || !!!suspense) return null;
|
|
2406
2415
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2407
2416
|
const contractOp = resolveClientOperation({
|
|
@@ -2412,23 +2421,25 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2412
2421
|
output
|
|
2413
2422
|
});
|
|
2414
2423
|
if (!contractOp) return null;
|
|
2415
|
-
const queryName = resolver.
|
|
2416
|
-
const queryOptionsName = resolver.
|
|
2417
|
-
const queryKeyName = resolver.
|
|
2418
|
-
const queryKeyTypeName = resolver.
|
|
2424
|
+
const queryName = resolver.suspenseQuery.name(node);
|
|
2425
|
+
const queryOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
2426
|
+
const queryKeyName = resolver.suspenseQuery.keyName(node);
|
|
2427
|
+
const queryKeyTypeName = resolver.suspenseQuery.keyTypeName(node);
|
|
2419
2428
|
const meta = {
|
|
2420
|
-
file: resolver.
|
|
2429
|
+
file: resolver.file({
|
|
2430
|
+
...operationFileEntry(node, queryName),
|
|
2421
2431
|
root,
|
|
2422
2432
|
output,
|
|
2423
2433
|
group: group ?? void 0
|
|
2424
2434
|
}),
|
|
2425
|
-
fileTs: tsResolver.
|
|
2435
|
+
fileTs: tsResolver.file({
|
|
2436
|
+
...operationFileEntry(node, node.operationId),
|
|
2426
2437
|
root,
|
|
2427
2438
|
output: pluginTs.options?.output ?? output,
|
|
2428
2439
|
group: pluginTs.options?.group ?? void 0
|
|
2429
2440
|
})
|
|
2430
2441
|
};
|
|
2431
|
-
const importedTypeNames = [tsResolver.
|
|
2442
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2432
2443
|
exclude: [queryKeyTypeName],
|
|
2433
2444
|
order: "body-response-first",
|
|
2434
2445
|
includeParams: false
|
|
@@ -2438,7 +2449,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2438
2449
|
baseName: meta.file.baseName,
|
|
2439
2450
|
path: meta.file.path,
|
|
2440
2451
|
meta: meta.file.meta,
|
|
2441
|
-
banner: resolver.
|
|
2452
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2442
2453
|
output,
|
|
2443
2454
|
config,
|
|
2444
2455
|
file: {
|
|
@@ -2446,7 +2457,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2446
2457
|
baseName: meta.file.baseName
|
|
2447
2458
|
}
|
|
2448
2459
|
}),
|
|
2449
|
-
footer: resolver.
|
|
2460
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2450
2461
|
output,
|
|
2451
2462
|
config,
|
|
2452
2463
|
file: {
|
|
@@ -2534,110 +2545,112 @@ function capitalize(name) {
|
|
|
2534
2545
|
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
2535
2546
|
* (`fooQueryKey`, `fooQueryOptions`).
|
|
2536
2547
|
*
|
|
2537
|
-
* Functions and files use camelCase; hooks get the `use`
|
|
2538
|
-
* infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2548
|
+
* Functions and files use the built-in camelCase casing; hooks get the `use`
|
|
2549
|
+
* prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2539
2550
|
*
|
|
2540
2551
|
* @example Resolve hook and helper names
|
|
2541
2552
|
* ```ts
|
|
2542
2553
|
* import { resolverReactQuery } from '@kubb/plugin-react-query'
|
|
2543
2554
|
*
|
|
2544
|
-
* resolverReactQuery.
|
|
2545
|
-
* resolverReactQuery.
|
|
2546
|
-
* resolverReactQuery.
|
|
2547
|
-
* resolverReactQuery.
|
|
2555
|
+
* resolverReactQuery.query.name(operationNode) // 'useGetPetById'
|
|
2556
|
+
* resolverReactQuery.mutation.name(operationNode) // 'useUpdatePet'
|
|
2557
|
+
* resolverReactQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
2558
|
+
* resolverReactQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
2548
2559
|
* ```
|
|
2549
2560
|
*/
|
|
2550
|
-
const resolverReactQuery = (0, kubb_kit.
|
|
2551
|
-
name: "default",
|
|
2561
|
+
const resolverReactQuery = (0, kubb_kit.createResolver)({
|
|
2552
2562
|
pluginName: "plugin-react-query",
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
return `use${capitalize(this.resolveName(node.operationId))}Infinite`;
|
|
2570
|
-
},
|
|
2571
|
-
resolveSuspenseInfiniteQueryName(node) {
|
|
2572
|
-
return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`;
|
|
2573
|
-
},
|
|
2574
|
-
resolveMutationName(node) {
|
|
2575
|
-
return `use${capitalize(this.resolveName(node.operationId))}`;
|
|
2576
|
-
},
|
|
2577
|
-
resolveQueryOptionsName(node) {
|
|
2578
|
-
return `${this.resolveName(node.operationId)}QueryOptions`;
|
|
2579
|
-
},
|
|
2580
|
-
resolveSuspenseQueryOptionsName(node) {
|
|
2581
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryOptions`;
|
|
2582
|
-
},
|
|
2583
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
2584
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
|
|
2585
|
-
},
|
|
2586
|
-
resolveSuspenseInfiniteQueryOptionsName(node) {
|
|
2587
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2588
|
-
},
|
|
2589
|
-
resolveMutationOptionsName(node) {
|
|
2590
|
-
return `${this.resolveName(node.operationId)}MutationOptions`;
|
|
2591
|
-
},
|
|
2592
|
-
resolveQueryKeyName(node) {
|
|
2593
|
-
return `${this.resolveName(node.operationId)}QueryKey`;
|
|
2594
|
-
},
|
|
2595
|
-
resolveSuspenseQueryKeyName(node) {
|
|
2596
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryKey`;
|
|
2597
|
-
},
|
|
2598
|
-
resolveInfiniteQueryKeyName(node) {
|
|
2599
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
|
|
2600
|
-
},
|
|
2601
|
-
resolveSuspenseInfiniteQueryKeyName(node) {
|
|
2602
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2603
|
-
},
|
|
2604
|
-
resolveMutationKeyName(node) {
|
|
2605
|
-
return `${this.resolveName(node.operationId)}MutationKey`;
|
|
2606
|
-
},
|
|
2607
|
-
resolveQueryKeyTypeName(node) {
|
|
2608
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
|
|
2609
|
-
},
|
|
2610
|
-
resolveSuspenseQueryKeyTypeName(node) {
|
|
2611
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`;
|
|
2612
|
-
},
|
|
2613
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
2614
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
|
|
2615
|
-
},
|
|
2616
|
-
resolveSuspenseInfiniteQueryKeyTypeName(node) {
|
|
2617
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2618
|
-
},
|
|
2619
|
-
resolveMutationTypeName(node) {
|
|
2620
|
-
return capitalize(this.resolveName(node.operationId));
|
|
2621
|
-
},
|
|
2622
|
-
resolveClientName(node) {
|
|
2623
|
-
return this.resolveName(node.operationId);
|
|
2563
|
+
query: {
|
|
2564
|
+
name(node) {
|
|
2565
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2566
|
+
},
|
|
2567
|
+
optionsName(node) {
|
|
2568
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
2569
|
+
},
|
|
2570
|
+
keyName(node) {
|
|
2571
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
2572
|
+
},
|
|
2573
|
+
keyTypeName(node) {
|
|
2574
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
2575
|
+
},
|
|
2576
|
+
clientName(node) {
|
|
2577
|
+
return this.name(node.operationId);
|
|
2578
|
+
}
|
|
2624
2579
|
},
|
|
2625
|
-
|
|
2626
|
-
|
|
2580
|
+
suspenseQuery: {
|
|
2581
|
+
name(node) {
|
|
2582
|
+
return `use${capitalize(this.name(node.operationId))}Suspense`;
|
|
2583
|
+
},
|
|
2584
|
+
optionsName(node) {
|
|
2585
|
+
return `${this.name(node.operationId)}SuspenseQueryOptions`;
|
|
2586
|
+
},
|
|
2587
|
+
keyName(node) {
|
|
2588
|
+
return `${this.name(node.operationId)}SuspenseQueryKey`;
|
|
2589
|
+
},
|
|
2590
|
+
keyTypeName(node) {
|
|
2591
|
+
return `${capitalize(this.name(node.operationId))}SuspenseQueryKey`;
|
|
2592
|
+
},
|
|
2593
|
+
clientName(node) {
|
|
2594
|
+
return `${this.name(node.operationId)}Suspense`;
|
|
2595
|
+
}
|
|
2627
2596
|
},
|
|
2628
|
-
|
|
2629
|
-
|
|
2597
|
+
infiniteQuery: {
|
|
2598
|
+
name(node) {
|
|
2599
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
2600
|
+
},
|
|
2601
|
+
optionsName(node) {
|
|
2602
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
2603
|
+
},
|
|
2604
|
+
keyName(node) {
|
|
2605
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
2606
|
+
},
|
|
2607
|
+
keyTypeName(node) {
|
|
2608
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
2609
|
+
},
|
|
2610
|
+
clientName(node) {
|
|
2611
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
2612
|
+
}
|
|
2630
2613
|
},
|
|
2631
|
-
|
|
2632
|
-
|
|
2614
|
+
suspenseInfiniteQuery: {
|
|
2615
|
+
name(node) {
|
|
2616
|
+
return `use${capitalize(this.name(node.operationId))}SuspenseInfinite`;
|
|
2617
|
+
},
|
|
2618
|
+
optionsName(node) {
|
|
2619
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2620
|
+
},
|
|
2621
|
+
keyName(node) {
|
|
2622
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2623
|
+
},
|
|
2624
|
+
keyTypeName(node) {
|
|
2625
|
+
return `${capitalize(this.name(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2626
|
+
},
|
|
2627
|
+
clientName(node) {
|
|
2628
|
+
return `${this.name(node.operationId)}SuspenseInfinite`;
|
|
2629
|
+
}
|
|
2633
2630
|
},
|
|
2634
|
-
|
|
2635
|
-
|
|
2631
|
+
mutation: {
|
|
2632
|
+
name(node) {
|
|
2633
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2634
|
+
},
|
|
2635
|
+
optionsName(node) {
|
|
2636
|
+
return `${this.name(node.operationId)}MutationOptions`;
|
|
2637
|
+
},
|
|
2638
|
+
keyName(node) {
|
|
2639
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
2640
|
+
},
|
|
2641
|
+
typeName(node) {
|
|
2642
|
+
return capitalize(this.name(node.operationId));
|
|
2643
|
+
}
|
|
2636
2644
|
},
|
|
2637
|
-
|
|
2638
|
-
|
|
2645
|
+
hook: {
|
|
2646
|
+
optionsName() {
|
|
2647
|
+
return "HookOptions";
|
|
2648
|
+
},
|
|
2649
|
+
customOptionsName() {
|
|
2650
|
+
return "getCustomHookOptions";
|
|
2651
|
+
}
|
|
2639
2652
|
}
|
|
2640
|
-
})
|
|
2653
|
+
});
|
|
2641
2654
|
//#endregion
|
|
2642
2655
|
//#region src/plugin.ts
|
|
2643
2656
|
/**
|
|
@@ -2683,17 +2696,14 @@ const pluginReactQuery = (0, kubb_kit.definePlugin)((options) => {
|
|
|
2683
2696
|
mutationGenerator,
|
|
2684
2697
|
hookOptionsGenerator,
|
|
2685
2698
|
customHookOptionsFileGenerator
|
|
2686
|
-
]
|
|
2699
|
+
];
|
|
2687
2700
|
const groupConfig = createGroupConfig(group);
|
|
2688
2701
|
return {
|
|
2689
2702
|
name: pluginReactQueryName,
|
|
2690
2703
|
options,
|
|
2691
2704
|
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
2692
2705
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2693
|
-
const resolver = userResolver ?
|
|
2694
|
-
...resolverReactQuery,
|
|
2695
|
-
...userResolver
|
|
2696
|
-
} : resolverReactQuery;
|
|
2706
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
|
|
2697
2707
|
const resolvedClient = resolveClient({
|
|
2698
2708
|
client,
|
|
2699
2709
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|