@kubb/plugin-react-query 5.0.0-beta.4 → 5.0.0-beta.42
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/README.md +38 -91
- package/dist/{components-dAKJEn9b.cjs → components-DQAYLQW0.cjs} +409 -279
- package/dist/components-DQAYLQW0.cjs.map +1 -0
- package/dist/{components-DTGLu4UV.js → components-IArDg-DO.js} +379 -279
- package/dist/components-IArDg-DO.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +5 -77
- package/dist/components.js +1 -1
- package/dist/{generators-C_fbcjpG.js → generators-B86BJkmW.js} +346 -419
- package/dist/generators-B86BJkmW.js.map +1 -0
- package/dist/{generators-CWEQsdO9.cjs → generators-BqGaMUH6.cjs} +344 -417
- package/dist/generators-BqGaMUH6.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +49 -10
- package/dist/generators.js +1 -1
- package/dist/index.cjs +176 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +177 -27
- package/dist/index.js.map +1 -1
- package/dist/types-Dh4HNR9K.d.ts +400 -0
- package/extension.yaml +910 -364
- package/package.json +15 -17
- package/src/components/InfiniteQuery.tsx +24 -13
- package/src/components/InfiniteQueryOptions.tsx +37 -55
- package/src/components/Mutation.tsx +35 -15
- package/src/components/MutationOptions.tsx +14 -13
- package/src/components/Query.tsx +14 -10
- package/src/components/QueryOptions.tsx +17 -34
- package/src/components/SuspenseInfiniteQuery.tsx +19 -13
- package/src/components/SuspenseInfiniteQueryOptions.tsx +28 -52
- package/src/components/SuspenseQuery.tsx +9 -10
- package/src/generators/customHookOptionsFileGenerator.tsx +18 -14
- package/src/generators/hookOptionsGenerator.tsx +44 -51
- package/src/generators/infiniteQueryGenerator.tsx +57 -78
- package/src/generators/mutationGenerator.tsx +53 -64
- package/src/generators/queryGenerator.tsx +54 -63
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +52 -65
- package/src/generators/suspenseQueryGenerator.tsx +56 -76
- package/src/plugin.ts +45 -31
- package/src/resolvers/resolverReactQuery.ts +102 -6
- package/src/types.ts +199 -61
- package/src/utils.ts +10 -33
- package/dist/components-DTGLu4UV.js.map +0 -1
- package/dist/components-dAKJEn9b.cjs.map +0 -1
- package/dist/generators-CWEQsdO9.cjs.map +0 -1
- package/dist/generators-C_fbcjpG.js.map +0 -1
- package/dist/types-DfaFRSBf.d.ts +0 -284
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import { ast } from "@kubb/core";
|
|
3
3
|
import { functionPrinter } from "@kubb/plugin-ts";
|
|
4
4
|
import { File, Function, Type } from "@kubb/renderer-jsx";
|
|
@@ -228,16 +228,16 @@ var URLPath = class {
|
|
|
228
228
|
get object() {
|
|
229
229
|
return this.toObject();
|
|
230
230
|
}
|
|
231
|
-
/** Returns a map of path parameter names, or `
|
|
231
|
+
/** Returns a map of path parameter names, or `null` when the path has no parameters.
|
|
232
232
|
*
|
|
233
233
|
* @example
|
|
234
234
|
* ```ts
|
|
235
235
|
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
236
|
-
* new URLPath('/pet').params //
|
|
236
|
+
* new URLPath('/pet').params // null
|
|
237
237
|
* ```
|
|
238
238
|
*/
|
|
239
239
|
get params() {
|
|
240
|
-
return this.
|
|
240
|
+
return this.toParamsObject();
|
|
241
241
|
}
|
|
242
242
|
#transformParam(raw) {
|
|
243
243
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -255,7 +255,7 @@ var URLPath = class {
|
|
|
255
255
|
toObject({ type = "path", replacer, stringify } = {}) {
|
|
256
256
|
const object = {
|
|
257
257
|
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
258
|
-
params: this.
|
|
258
|
+
params: this.toParamsObject()
|
|
259
259
|
};
|
|
260
260
|
if (stringify) {
|
|
261
261
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -271,12 +271,13 @@ var URLPath = class {
|
|
|
271
271
|
* @example
|
|
272
272
|
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
273
273
|
*/
|
|
274
|
-
toTemplateString({ prefix
|
|
275
|
-
|
|
274
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
275
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
276
276
|
if (i % 2 === 0) return part;
|
|
277
277
|
const param = this.#transformParam(part);
|
|
278
278
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
279
|
-
}).join("")
|
|
279
|
+
}).join("");
|
|
280
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
280
281
|
}
|
|
281
282
|
/**
|
|
282
283
|
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
@@ -285,17 +286,17 @@ var URLPath = class {
|
|
|
285
286
|
*
|
|
286
287
|
* @example
|
|
287
288
|
* ```ts
|
|
288
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').
|
|
289
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
289
290
|
* // { petId: 'petId', tagId: 'tagId' }
|
|
290
291
|
* ```
|
|
291
292
|
*/
|
|
292
|
-
|
|
293
|
+
toParamsObject(replacer) {
|
|
293
294
|
const params = {};
|
|
294
295
|
this.#eachParam((_raw, param) => {
|
|
295
296
|
const key = replacer ? replacer(param) : param;
|
|
296
297
|
params[key] = key;
|
|
297
298
|
});
|
|
298
|
-
return Object.keys(params).length > 0 ? params :
|
|
299
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
299
300
|
}
|
|
300
301
|
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
301
302
|
*
|
|
@@ -309,19 +310,138 @@ var URLPath = class {
|
|
|
309
310
|
}
|
|
310
311
|
};
|
|
311
312
|
//#endregion
|
|
313
|
+
//#region ../../internals/shared/src/operation.ts
|
|
314
|
+
/**
|
|
315
|
+
* Builds the `ResolverFileParams` every operation generator passes to
|
|
316
|
+
* `resolver.resolveFile`: a file named `name`, tagged by the operation's first
|
|
317
|
+
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
318
|
+
* that was repeated at dozens of call sites across the client and query plugins.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
function operationFileEntry(node, name, extname = ".ts") {
|
|
326
|
+
return {
|
|
327
|
+
name,
|
|
328
|
+
extname,
|
|
329
|
+
tag: node.tags[0] ?? "default",
|
|
330
|
+
path: node.path
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function getOperationLink(node, link) {
|
|
334
|
+
if (!link) return null;
|
|
335
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
336
|
+
if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
|
|
337
|
+
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
338
|
+
}
|
|
339
|
+
function getContentTypeInfo(node) {
|
|
340
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
341
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
342
|
+
return {
|
|
343
|
+
contentTypes,
|
|
344
|
+
isMultipleContentTypes,
|
|
345
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
346
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
347
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function buildRequestConfigType(node, resolver) {
|
|
351
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
352
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
353
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
354
|
+
}
|
|
355
|
+
function buildOperationComments(node, options = {}) {
|
|
356
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
357
|
+
const linkComment = getOperationLink(node, link);
|
|
358
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
359
|
+
node.description && `@description ${node.description}`,
|
|
360
|
+
node.summary && `@summary ${node.summary}`,
|
|
361
|
+
linkComment,
|
|
362
|
+
node.deprecated && "@deprecated"
|
|
363
|
+
] : [
|
|
364
|
+
node.description && `@description ${node.description}`,
|
|
365
|
+
node.summary && `@summary ${node.summary}`,
|
|
366
|
+
node.deprecated && "@deprecated",
|
|
367
|
+
linkComment
|
|
368
|
+
]).filter((comment) => Boolean(comment));
|
|
369
|
+
if (!splitLines) return filteredComments;
|
|
370
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
371
|
+
}
|
|
372
|
+
function getOperationParameters(node, options = {}) {
|
|
373
|
+
const params = ast.caseParams(node.parameters, options.paramsCasing);
|
|
374
|
+
return {
|
|
375
|
+
path: params.filter((param) => param.in === "path"),
|
|
376
|
+
query: params.filter((param) => param.in === "query"),
|
|
377
|
+
header: params.filter((param) => param.in === "header"),
|
|
378
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function getStatusCodeNumber(statusCode) {
|
|
382
|
+
const code = Number(statusCode);
|
|
383
|
+
return Number.isNaN(code) ? null : code;
|
|
384
|
+
}
|
|
385
|
+
function isSuccessStatusCode(statusCode) {
|
|
386
|
+
const code = getStatusCodeNumber(statusCode);
|
|
387
|
+
return code !== null && code >= 200 && code < 300;
|
|
388
|
+
}
|
|
389
|
+
function isErrorStatusCode(statusCode) {
|
|
390
|
+
const code = getStatusCodeNumber(statusCode);
|
|
391
|
+
return code !== null && code >= 400;
|
|
392
|
+
}
|
|
393
|
+
function resolveErrorNames(node, resolver) {
|
|
394
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
395
|
+
}
|
|
396
|
+
function resolveSuccessNames(node, resolver) {
|
|
397
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
398
|
+
}
|
|
399
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
400
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
401
|
+
}
|
|
402
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
403
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
404
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
405
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
406
|
+
if (byResolver) {
|
|
407
|
+
const cached = byResolver.get(cacheKey);
|
|
408
|
+
if (cached) return cached;
|
|
409
|
+
} else {
|
|
410
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
411
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
412
|
+
}
|
|
413
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
414
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
415
|
+
const exclude = new Set(options.exclude ?? []);
|
|
416
|
+
const paramNames = [
|
|
417
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
418
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
419
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
420
|
+
];
|
|
421
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
422
|
+
const result = (options.order === "body-response-first" ? [
|
|
423
|
+
...bodyAndResponseNames,
|
|
424
|
+
...paramNames,
|
|
425
|
+
...responseStatusNames
|
|
426
|
+
] : [
|
|
427
|
+
...paramNames,
|
|
428
|
+
...bodyAndResponseNames,
|
|
429
|
+
...responseStatusNames
|
|
430
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
431
|
+
byResolver.set(cacheKey, result);
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
312
435
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
313
436
|
const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
__name(getParams$6, "getParams");
|
|
318
|
-
const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
|
|
437
|
+
const mutationKeyTransformer = ({ node, casing }) => {
|
|
438
|
+
if (!node.path) return [];
|
|
319
439
|
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
320
|
-
}
|
|
321
|
-
function MutationKey({ name, paramsCasing, node, transformer
|
|
322
|
-
const paramsNode =
|
|
440
|
+
};
|
|
441
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
442
|
+
const paramsNode = ast.createFunctionParameters({ params: [] });
|
|
323
443
|
const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
|
|
324
|
-
const keys = transformer({
|
|
444
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
325
445
|
node,
|
|
326
446
|
casing: paramsCasing
|
|
327
447
|
});
|
|
@@ -338,28 +458,38 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
338
458
|
})
|
|
339
459
|
});
|
|
340
460
|
}
|
|
341
|
-
MutationKey.getParams = getParams$6;
|
|
342
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
343
461
|
//#endregion
|
|
344
462
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
463
|
+
function matchesPattern(node, ov) {
|
|
464
|
+
const { type, pattern } = ov;
|
|
465
|
+
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
466
|
+
if (type === "operationId") return matches(node.operationId);
|
|
467
|
+
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
468
|
+
if (type === "path") return node.path !== void 0 && matches(node.path);
|
|
469
|
+
if (type === "method") return node.method !== void 0 && matches(node.method);
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
345
472
|
/**
|
|
346
|
-
*
|
|
473
|
+
* Resolves per-operation overrides (first matching override wins).
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* const opts = resolveOperationOverrides(node, override)
|
|
478
|
+
* const queryOpts = 'query' in opts ? opts.query : defaultQuery
|
|
479
|
+
* ```
|
|
347
480
|
*/
|
|
348
|
-
function
|
|
349
|
-
return
|
|
350
|
-
|
|
351
|
-
node.summary && `@summary ${node.summary}`,
|
|
352
|
-
node.deprecated && "@deprecated",
|
|
353
|
-
`{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`
|
|
354
|
-
].filter((x) => Boolean(x));
|
|
481
|
+
function resolveOperationOverrides(node, override) {
|
|
482
|
+
if (!override) return {};
|
|
483
|
+
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
355
484
|
}
|
|
356
485
|
/**
|
|
357
|
-
*
|
|
486
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
487
|
+
*
|
|
488
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
358
489
|
*/
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
490
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
491
|
+
if (!zodResolver) return [];
|
|
492
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
363
493
|
}
|
|
364
494
|
/**
|
|
365
495
|
* Resolve the type for a single path parameter.
|
|
@@ -383,30 +513,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
383
513
|
}
|
|
384
514
|
/**
|
|
385
515
|
* Derive a query-params group type from the resolver.
|
|
386
|
-
* Returns `
|
|
516
|
+
* Returns `null` when no query params exist or when the group name
|
|
387
517
|
* equals the individual param name (no real group).
|
|
388
518
|
*/
|
|
389
519
|
function resolveQueryGroupType(node, params, resolver) {
|
|
390
|
-
if (!params.length) return
|
|
520
|
+
if (!params.length) return null;
|
|
391
521
|
const firstParam = params[0];
|
|
392
522
|
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
393
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return
|
|
394
|
-
return {
|
|
395
|
-
type: ast.createParamsType({
|
|
396
|
-
variant: "reference",
|
|
397
|
-
name: groupName
|
|
398
|
-
}),
|
|
399
|
-
optional: params.every((p) => !p.required)
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Derive a header-params group type from the resolver.
|
|
404
|
-
*/
|
|
405
|
-
function resolveHeaderGroupType(node, params, resolver) {
|
|
406
|
-
if (!params.length) return void 0;
|
|
407
|
-
const firstParam = params[0];
|
|
408
|
-
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
409
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
523
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
410
524
|
return {
|
|
411
525
|
type: ast.createParamsType({
|
|
412
526
|
variant: "reference",
|
|
@@ -456,7 +570,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
456
570
|
const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
|
|
457
571
|
variant: "reference",
|
|
458
572
|
name: resolver.resolveDataName(node)
|
|
459
|
-
}) :
|
|
573
|
+
}) : null;
|
|
460
574
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
461
575
|
const params = [];
|
|
462
576
|
if (pathParams.length) {
|
|
@@ -481,66 +595,101 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
595
|
return ast.createFunctionParameters({ params });
|
|
482
596
|
}
|
|
483
597
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
598
|
+
* Collect the names of the required params (no default) that drive the `enabled`
|
|
599
|
+
* guard. These are exactly the params that should be made optional in the
|
|
600
|
+
* generated signatures so callers can pass `undefined` to reach the disabled state.
|
|
486
601
|
*/
|
|
487
|
-
function
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
602
|
+
function getEnabledParamNames(paramsNode) {
|
|
603
|
+
const required = [];
|
|
604
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
605
|
+
const group = param;
|
|
606
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
607
|
+
} else {
|
|
608
|
+
const fp = param;
|
|
609
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
610
|
+
}
|
|
611
|
+
return required;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Return a copy of `paramsNode` with the named params marked optional.
|
|
615
|
+
*
|
|
616
|
+
* Used to align signatures with the `enabled` guard: the guard already disables
|
|
617
|
+
* the query while a param is falsy, so the param should accept `undefined`. The
|
|
618
|
+
* change is type-only — the `queryFn` keeps calling the client with a non-null
|
|
619
|
+
* assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
|
|
620
|
+
*/
|
|
621
|
+
function markParamsOptional(paramsNode, names) {
|
|
622
|
+
if (names.length === 0) return paramsNode;
|
|
623
|
+
const nameSet = new Set(names);
|
|
624
|
+
const params = paramsNode.params.map((param) => {
|
|
625
|
+
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
626
|
+
const group = param;
|
|
627
|
+
return {
|
|
628
|
+
...group,
|
|
629
|
+
properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
|
|
630
|
+
name: child.name,
|
|
631
|
+
type: child.type,
|
|
632
|
+
rest: child.rest,
|
|
633
|
+
optional: true
|
|
634
|
+
}) : child)
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
const fp = param;
|
|
638
|
+
return nameSet.has(fp.name) ? ast.createFunctionParameter({
|
|
639
|
+
name: fp.name,
|
|
640
|
+
type: fp.type,
|
|
641
|
+
rest: fp.rest,
|
|
642
|
+
optional: true
|
|
643
|
+
}) : fp;
|
|
644
|
+
});
|
|
513
645
|
return ast.createFunctionParameters({ params });
|
|
514
646
|
}
|
|
647
|
+
/**
|
|
648
|
+
* Add a non-null assertion (`!`) to the named params inside a printed client-call
|
|
649
|
+
* string. Bridges the type gap created by `markParamsOptional` while keeping the
|
|
650
|
+
* runtime identical (the `!` is erased at compile time).
|
|
651
|
+
*
|
|
652
|
+
* Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
|
|
653
|
+
* standalone identifiers (`params` → `params!`).
|
|
654
|
+
*/
|
|
655
|
+
function injectNonNullAssertions(callStr, names) {
|
|
656
|
+
if (names.length === 0) return callStr;
|
|
657
|
+
const nameSet = new Set(names);
|
|
658
|
+
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
659
|
+
if (inner.includes(":") || inner.includes("...")) return match;
|
|
660
|
+
const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
|
|
661
|
+
if (!keys.some((k) => nameSet.has(k))) return match;
|
|
662
|
+
return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
|
|
663
|
+
});
|
|
664
|
+
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
|
|
665
|
+
return result;
|
|
666
|
+
}
|
|
515
667
|
//#endregion
|
|
516
668
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
517
669
|
const declarationPrinter$9 = functionPrinter({ mode: "declaration" });
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
return buildQueryKeyParams(node, options);
|
|
521
|
-
}
|
|
522
|
-
__name(getParams$5, "getParams");
|
|
523
|
-
const getTransformer = ({ node, casing }) => {
|
|
670
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
671
|
+
if (!node.path) return [];
|
|
524
672
|
const path = new URLPath(node.path, { casing });
|
|
525
|
-
const hasQueryParams = node.
|
|
673
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
526
674
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
527
675
|
return [
|
|
528
676
|
path.toObject({
|
|
529
677
|
type: "path",
|
|
530
678
|
stringify: true
|
|
531
679
|
}),
|
|
532
|
-
hasQueryParams ? "...(params ? [params] : [])" :
|
|
533
|
-
hasRequestBody ? "...(data ? [data] : [])" :
|
|
680
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
681
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
534
682
|
].filter(Boolean);
|
|
535
683
|
};
|
|
536
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer
|
|
537
|
-
const
|
|
684
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
685
|
+
const baseParamsNode = buildQueryKeyParams(node, {
|
|
538
686
|
pathParamsType,
|
|
539
687
|
paramsCasing,
|
|
540
688
|
resolver: tsResolver
|
|
541
689
|
});
|
|
690
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
|
|
542
691
|
const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
|
|
543
|
-
const keys = transformer({
|
|
692
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
544
693
|
node,
|
|
545
694
|
casing: paramsCasing
|
|
546
695
|
});
|
|
@@ -564,37 +713,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
564
713
|
})
|
|
565
714
|
})] });
|
|
566
715
|
}
|
|
567
|
-
QueryKey.getParams = getParams$5;
|
|
568
|
-
QueryKey.getTransformer = getTransformer;
|
|
569
|
-
QueryKey.callPrinter = callPrinter$9;
|
|
570
|
-
//#endregion
|
|
571
|
-
//#region src/utils.ts
|
|
572
|
-
function transformName(name, type, transformers) {
|
|
573
|
-
return transformers?.name?.(name, type) || name;
|
|
574
|
-
}
|
|
575
|
-
function matchesPattern(node, ov) {
|
|
576
|
-
const { type, pattern } = ov;
|
|
577
|
-
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
578
|
-
if (type === "operationId") return matches(node.operationId);
|
|
579
|
-
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
580
|
-
if (type === "path") return matches(node.path);
|
|
581
|
-
if (type === "method") return matches(node.method);
|
|
582
|
-
return false;
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Resolves per-operation overrides (first matching override wins), mirroring v4 OperationGenerator.getOptions().
|
|
586
|
-
*/
|
|
587
|
-
function resolveOperationOverrides(node, override) {
|
|
588
|
-
if (!override) return {};
|
|
589
|
-
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
590
|
-
}
|
|
591
716
|
//#endregion
|
|
592
717
|
//#region src/components/QueryOptions.tsx
|
|
593
718
|
const declarationPrinter$8 = functionPrinter({ mode: "declaration" });
|
|
594
719
|
const callPrinter$8 = functionPrinter({ mode: "call" });
|
|
595
720
|
function getQueryOptionsParams(node, options) {
|
|
596
721
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
597
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
722
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
598
723
|
return ast.createOperationParams(node, {
|
|
599
724
|
paramsType,
|
|
600
725
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
@@ -610,38 +735,29 @@ function getQueryOptionsParams(node, options) {
|
|
|
610
735
|
})]
|
|
611
736
|
});
|
|
612
737
|
}
|
|
613
|
-
function
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
const group = param;
|
|
617
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
618
|
-
} else {
|
|
619
|
-
const fp = param;
|
|
620
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
621
|
-
}
|
|
622
|
-
return required.join(" && ");
|
|
623
|
-
}
|
|
624
|
-
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
625
|
-
const responseName = tsResolver.resolveResponseName(node);
|
|
738
|
+
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
|
|
739
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
740
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
626
741
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
627
742
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
628
743
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
629
|
-
const
|
|
630
|
-
paramsType,
|
|
631
|
-
paramsCasing,
|
|
632
|
-
pathParamsType,
|
|
633
|
-
resolver: tsResolver
|
|
634
|
-
});
|
|
635
|
-
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
636
|
-
const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
637
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
744
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
638
745
|
pathParamsType,
|
|
639
746
|
paramsCasing,
|
|
640
747
|
resolver: tsResolver
|
|
641
748
|
});
|
|
642
749
|
const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
|
|
643
|
-
const
|
|
644
|
-
const
|
|
750
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
751
|
+
const optionalNames = suspense ? [] : enabledNames;
|
|
752
|
+
const enabledText = suspense ? "" : enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
753
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
754
|
+
paramsType,
|
|
755
|
+
paramsCasing,
|
|
756
|
+
pathParamsType,
|
|
757
|
+
resolver: tsResolver
|
|
758
|
+
}), optionalNames);
|
|
759
|
+
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
760
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), optionalNames);
|
|
645
761
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
646
762
|
name,
|
|
647
763
|
isExportable: true,
|
|
@@ -663,14 +779,13 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
663
779
|
})
|
|
664
780
|
});
|
|
665
781
|
}
|
|
666
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
667
782
|
//#endregion
|
|
668
783
|
//#region src/components/InfiniteQuery.tsx
|
|
669
784
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
670
785
|
const callPrinter$7 = functionPrinter({ mode: "call" });
|
|
671
|
-
function
|
|
786
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
672
787
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
673
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
788
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
674
789
|
const optionsParam = ast.createFunctionParameter({
|
|
675
790
|
name: "options",
|
|
676
791
|
type: ast.createParamsType({
|
|
@@ -690,9 +805,9 @@ function getParams$4(node, options) {
|
|
|
690
805
|
extraParams: [optionsParam]
|
|
691
806
|
});
|
|
692
807
|
}
|
|
693
|
-
__name(getParams$4, "getParams");
|
|
694
808
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
695
|
-
const
|
|
809
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
810
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
696
811
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
697
812
|
const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
698
813
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -701,12 +816,12 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
701
816
|
const parts = initialPageParam.split(" as ");
|
|
702
817
|
return parts[parts.length - 1] ?? "unknown";
|
|
703
818
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
704
|
-
const rawQueryParams = node
|
|
819
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
705
820
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
706
821
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
707
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
708
|
-
})() :
|
|
709
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
822
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
823
|
+
})() : null;
|
|
824
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
710
825
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
711
826
|
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
712
827
|
const generics = [
|
|
@@ -716,12 +831,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
716
831
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
717
832
|
`TPageParam = ${pageParamType}`
|
|
718
833
|
];
|
|
719
|
-
const queryKeyParamsNode =
|
|
834
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
720
835
|
pathParamsType,
|
|
721
836
|
paramsCasing,
|
|
722
837
|
resolver: tsResolver
|
|
723
838
|
});
|
|
724
839
|
const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
|
|
840
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
725
841
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
726
842
|
paramsType,
|
|
727
843
|
paramsCasing,
|
|
@@ -729,14 +845,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
729
845
|
resolver: tsResolver
|
|
730
846
|
});
|
|
731
847
|
const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
|
|
732
|
-
const paramsNode =
|
|
848
|
+
const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
|
|
733
849
|
paramsType,
|
|
734
850
|
paramsCasing,
|
|
735
851
|
pathParamsType,
|
|
736
852
|
dataReturnType,
|
|
737
853
|
resolver: tsResolver,
|
|
738
854
|
pageParamGeneric: "TPageParam"
|
|
739
|
-
});
|
|
855
|
+
}), enabledNames);
|
|
740
856
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
741
857
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
742
858
|
name,
|
|
@@ -748,7 +864,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
748
864
|
generics: generics.join(", "),
|
|
749
865
|
params: paramsSignature,
|
|
750
866
|
returnType: void 0,
|
|
751
|
-
JSDoc: { comments:
|
|
867
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
752
868
|
children: `
|
|
753
869
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
754
870
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -768,13 +884,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
768
884
|
})
|
|
769
885
|
});
|
|
770
886
|
}
|
|
771
|
-
InfiniteQuery.getParams = getParams$4;
|
|
772
887
|
//#endregion
|
|
773
888
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
774
889
|
const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
|
|
775
890
|
const callPrinter$6 = functionPrinter({ mode: "call" });
|
|
776
891
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
777
|
-
const
|
|
892
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
893
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
778
894
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
779
895
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
780
896
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -783,49 +899,39 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
783
899
|
const parts = initialPageParam.split(" as ");
|
|
784
900
|
return parts[parts.length - 1] ?? "unknown";
|
|
785
901
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
786
|
-
const rawQueryParams = node
|
|
902
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
787
903
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
788
904
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
789
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
790
|
-
})() :
|
|
791
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
905
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
906
|
+
})() : null;
|
|
907
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
792
908
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
793
|
-
const
|
|
794
|
-
paramsType,
|
|
795
|
-
paramsCasing,
|
|
796
|
-
pathParamsType,
|
|
797
|
-
resolver: tsResolver
|
|
798
|
-
});
|
|
799
|
-
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
800
|
-
const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
801
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
909
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
802
910
|
pathParamsType,
|
|
803
911
|
paramsCasing,
|
|
804
912
|
resolver: tsResolver
|
|
805
913
|
});
|
|
806
914
|
const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
|
|
807
|
-
const
|
|
808
|
-
const enabledText =
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
915
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
916
|
+
const enabledText = enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
|
|
917
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
918
|
+
paramsType,
|
|
919
|
+
paramsCasing,
|
|
920
|
+
pathParamsType,
|
|
921
|
+
resolver: tsResolver
|
|
922
|
+
}), enabledNames);
|
|
923
|
+
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
924
|
+
const clientCallStr = injectNonNullAssertions((callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), enabledNames);
|
|
925
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
926
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
927
|
+
if (hasNewParams) {
|
|
928
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
929
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
930
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
820
931
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
} else {
|
|
825
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
826
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
827
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
828
|
-
}
|
|
932
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
933
|
+
return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
|
|
934
|
+
})();
|
|
829
935
|
const queryOptionsArr = [
|
|
830
936
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
831
937
|
getNextPageParamExpr,
|
|
@@ -880,31 +986,32 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
880
986
|
})
|
|
881
987
|
});
|
|
882
988
|
}
|
|
883
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
884
989
|
//#endregion
|
|
885
990
|
//#region src/components/MutationOptions.tsx
|
|
886
991
|
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
887
992
|
const callPrinter$5 = functionPrinter({ mode: "call" });
|
|
888
993
|
const keysPrinter = functionPrinter({ mode: "keys" });
|
|
889
|
-
function
|
|
890
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
994
|
+
function buildMutationConfigParamsNode(node, resolver) {
|
|
891
995
|
return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
892
996
|
name: "config",
|
|
893
997
|
type: ast.createParamsType({
|
|
894
998
|
variant: "reference",
|
|
895
|
-
name:
|
|
999
|
+
name: buildRequestConfigType(node, resolver)
|
|
896
1000
|
}),
|
|
897
1001
|
default: "{}"
|
|
898
1002
|
})] });
|
|
899
1003
|
}
|
|
900
1004
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
901
|
-
const
|
|
1005
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1006
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
902
1007
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
903
1008
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
904
1009
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
905
|
-
const configParamsNode =
|
|
1010
|
+
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
906
1011
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
907
|
-
const mutationArgParamsNode =
|
|
1012
|
+
const mutationArgParamsNode = ast.createOperationParams(node, {
|
|
1013
|
+
paramsType: "inline",
|
|
1014
|
+
pathParamsType: "inline",
|
|
908
1015
|
paramsCasing,
|
|
909
1016
|
resolver: tsResolver
|
|
910
1017
|
});
|
|
@@ -920,7 +1027,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
920
1027
|
name: "config",
|
|
921
1028
|
type: ast.createParamsType({
|
|
922
1029
|
variant: "reference",
|
|
923
|
-
name: node
|
|
1030
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
924
1031
|
}),
|
|
925
1032
|
default: "{}"
|
|
926
1033
|
})]
|
|
@@ -937,7 +1044,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
937
1044
|
generics: ["TContext = unknown"],
|
|
938
1045
|
children: `
|
|
939
1046
|
const mutationKey = ${mutationKeyName}()
|
|
940
|
-
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "
|
|
1047
|
+
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "undefined"}, TContext>({
|
|
941
1048
|
mutationKey,
|
|
942
1049
|
mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
|
|
943
1050
|
return ${clientName}(${clientCallStr})
|
|
@@ -947,19 +1054,26 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
947
1054
|
})
|
|
948
1055
|
});
|
|
949
1056
|
}
|
|
950
|
-
MutationOptions.getParams = getConfigParam;
|
|
951
1057
|
//#endregion
|
|
952
1058
|
//#region src/components/Mutation.tsx
|
|
953
1059
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
954
1060
|
const callPrinter$4 = functionPrinter({ mode: "call" });
|
|
955
|
-
function
|
|
1061
|
+
function createMutationArgParams(node, options) {
|
|
1062
|
+
return ast.createOperationParams(node, {
|
|
1063
|
+
paramsType: "inline",
|
|
1064
|
+
pathParamsType: "inline",
|
|
1065
|
+
paramsCasing: options.paramsCasing,
|
|
1066
|
+
resolver: options.resolver
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
function buildMutationParamsNode(node, options) {
|
|
956
1070
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
957
|
-
const
|
|
958
|
-
const
|
|
1071
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1072
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
959
1073
|
const errorNames = resolveErrorNames(node, resolver);
|
|
960
1074
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
961
1075
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
962
|
-
const mutationArgParamsNode =
|
|
1076
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
963
1077
|
paramsCasing,
|
|
964
1078
|
resolver
|
|
965
1079
|
});
|
|
@@ -967,7 +1081,7 @@ function getParams$3(node, options) {
|
|
|
967
1081
|
const generics = [
|
|
968
1082
|
TData,
|
|
969
1083
|
TError,
|
|
970
|
-
TRequest ? `{${TRequest}}` : "
|
|
1084
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
971
1085
|
"TContext"
|
|
972
1086
|
].join(", ");
|
|
973
1087
|
return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
@@ -976,19 +1090,19 @@ function getParams$3(node, options) {
|
|
|
976
1090
|
variant: "reference",
|
|
977
1091
|
name: `{
|
|
978
1092
|
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
979
|
-
client?: ${
|
|
1093
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
980
1094
|
}`
|
|
981
1095
|
}),
|
|
982
1096
|
default: "{}"
|
|
983
1097
|
})] });
|
|
984
1098
|
}
|
|
985
|
-
__name(getParams$3, "getParams");
|
|
986
1099
|
function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
|
|
987
|
-
const
|
|
1100
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1101
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
988
1102
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
989
1103
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
990
1104
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
991
|
-
const mutationArgParamsNode =
|
|
1105
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
992
1106
|
paramsCasing,
|
|
993
1107
|
resolver: tsResolver
|
|
994
1108
|
});
|
|
@@ -996,13 +1110,13 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
996
1110
|
const generics = [
|
|
997
1111
|
TData,
|
|
998
1112
|
TError,
|
|
999
|
-
TRequest ? `{${TRequest}}` : "
|
|
1113
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1000
1114
|
"TContext"
|
|
1001
1115
|
].join(", ");
|
|
1002
1116
|
const returnType = `UseMutationResult<${generics}>`;
|
|
1003
|
-
const mutationOptionsConfigNode =
|
|
1117
|
+
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
1004
1118
|
const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
|
|
1005
|
-
const paramsNode =
|
|
1119
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1006
1120
|
paramsCasing,
|
|
1007
1121
|
dataReturnType,
|
|
1008
1122
|
resolver: tsResolver
|
|
@@ -1016,7 +1130,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1016
1130
|
name,
|
|
1017
1131
|
export: true,
|
|
1018
1132
|
params: paramsSignature,
|
|
1019
|
-
JSDoc: { comments:
|
|
1133
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1020
1134
|
generics: ["TContext"],
|
|
1021
1135
|
children: `
|
|
1022
1136
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
@@ -1035,15 +1149,15 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1035
1149
|
})
|
|
1036
1150
|
});
|
|
1037
1151
|
}
|
|
1038
|
-
Mutation.getParams = getParams$3;
|
|
1039
1152
|
//#endregion
|
|
1040
1153
|
//#region src/components/Query.tsx
|
|
1041
1154
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
1042
1155
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
1043
|
-
function
|
|
1156
|
+
function buildQueryParamsNode(node, options) {
|
|
1044
1157
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1045
|
-
const
|
|
1046
|
-
const
|
|
1158
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1159
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1160
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1047
1161
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1048
1162
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1049
1163
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1072,9 +1186,9 @@ function getParams$2(node, options) {
|
|
|
1072
1186
|
extraParams: [optionsParam]
|
|
1073
1187
|
});
|
|
1074
1188
|
}
|
|
1075
|
-
__name(getParams$2, "getParams");
|
|
1076
1189
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1077
|
-
const
|
|
1190
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1191
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1078
1192
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1079
1193
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1080
1194
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1083,12 +1197,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1083
1197
|
`TQueryData = ${TData}`,
|
|
1084
1198
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1085
1199
|
];
|
|
1086
|
-
const queryKeyParamsNode =
|
|
1200
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1087
1201
|
pathParamsType,
|
|
1088
1202
|
paramsCasing,
|
|
1089
1203
|
resolver: tsResolver
|
|
1090
1204
|
});
|
|
1091
1205
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
1206
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
1092
1207
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
1093
1208
|
paramsType,
|
|
1094
1209
|
paramsCasing,
|
|
@@ -1096,13 +1211,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1096
1211
|
resolver: tsResolver
|
|
1097
1212
|
});
|
|
1098
1213
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
1099
|
-
const paramsNode =
|
|
1214
|
+
const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
|
|
1100
1215
|
paramsType,
|
|
1101
1216
|
paramsCasing,
|
|
1102
1217
|
pathParamsType,
|
|
1103
1218
|
dataReturnType,
|
|
1104
1219
|
resolver: tsResolver
|
|
1105
|
-
});
|
|
1220
|
+
}), enabledNames);
|
|
1106
1221
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
1107
1222
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1108
1223
|
name,
|
|
@@ -1114,7 +1229,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1114
1229
|
generics: generics.join(", "),
|
|
1115
1230
|
params: paramsSignature,
|
|
1116
1231
|
returnType: void 0,
|
|
1117
|
-
JSDoc: { comments:
|
|
1232
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1118
1233
|
children: `
|
|
1119
1234
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1120
1235
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1134,14 +1249,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1134
1249
|
})
|
|
1135
1250
|
});
|
|
1136
1251
|
}
|
|
1137
|
-
Query.getParams = getParams$2;
|
|
1138
1252
|
//#endregion
|
|
1139
1253
|
//#region src/components/SuspenseInfiniteQuery.tsx
|
|
1140
1254
|
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
1141
1255
|
const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
1142
|
-
function
|
|
1256
|
+
function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
1143
1257
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
1144
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
1258
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1145
1259
|
const optionsParam = ast.createFunctionParameter({
|
|
1146
1260
|
name: "options",
|
|
1147
1261
|
type: ast.createParamsType({
|
|
@@ -1161,9 +1275,9 @@ function getParams$1(node, options) {
|
|
|
1161
1275
|
extraParams: [optionsParam]
|
|
1162
1276
|
});
|
|
1163
1277
|
}
|
|
1164
|
-
__name(getParams$1, "getParams");
|
|
1165
1278
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1166
|
-
const
|
|
1279
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1280
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1167
1281
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1168
1282
|
const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1169
1283
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1172,12 +1286,12 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1172
1286
|
const parts = initialPageParam.split(" as ");
|
|
1173
1287
|
return parts[parts.length - 1] ?? "unknown";
|
|
1174
1288
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1175
|
-
const rawQueryParams = node
|
|
1289
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1176
1290
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1177
1291
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1178
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1179
|
-
})() :
|
|
1180
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1292
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1293
|
+
})() : null;
|
|
1294
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1181
1295
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1182
1296
|
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1183
1297
|
const generics = [
|
|
@@ -1187,7 +1301,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1187
1301
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1188
1302
|
`TPageParam = ${pageParamType}`
|
|
1189
1303
|
];
|
|
1190
|
-
const queryKeyParamsNode =
|
|
1304
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1191
1305
|
pathParamsType,
|
|
1192
1306
|
paramsCasing,
|
|
1193
1307
|
resolver: tsResolver
|
|
@@ -1200,7 +1314,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1200
1314
|
resolver: tsResolver
|
|
1201
1315
|
});
|
|
1202
1316
|
const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
|
|
1203
|
-
const paramsNode =
|
|
1317
|
+
const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
|
|
1204
1318
|
paramsType,
|
|
1205
1319
|
paramsCasing,
|
|
1206
1320
|
pathParamsType,
|
|
@@ -1219,7 +1333,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1219
1333
|
generics: generics.join(", "),
|
|
1220
1334
|
params: paramsSignature,
|
|
1221
1335
|
returnType: void 0,
|
|
1222
|
-
JSDoc: { comments:
|
|
1336
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1223
1337
|
children: `
|
|
1224
1338
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1225
1339
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1239,13 +1353,13 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1239
1353
|
})
|
|
1240
1354
|
});
|
|
1241
1355
|
}
|
|
1242
|
-
SuspenseInfiniteQuery.getParams = getParams$1;
|
|
1243
1356
|
//#endregion
|
|
1244
1357
|
//#region src/components/SuspenseInfiniteQueryOptions.tsx
|
|
1245
1358
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1246
1359
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1247
1360
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1248
|
-
const
|
|
1361
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1362
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1249
1363
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1250
1364
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1251
1365
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1254,12 +1368,12 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1254
1368
|
const parts = initialPageParam.split(" as ");
|
|
1255
1369
|
return parts[parts.length - 1] ?? "unknown";
|
|
1256
1370
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1257
|
-
const rawQueryParams = node
|
|
1371
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1258
1372
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1259
1373
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1260
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1261
|
-
})() :
|
|
1262
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1374
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1375
|
+
})() : null;
|
|
1376
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1263
1377
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1264
1378
|
const paramsNode = getQueryOptionsParams(node, {
|
|
1265
1379
|
paramsType,
|
|
@@ -1269,34 +1383,22 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1269
1383
|
});
|
|
1270
1384
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1271
1385
|
const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
1272
|
-
const queryKeyParamsNode =
|
|
1386
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1273
1387
|
pathParamsType,
|
|
1274
1388
|
paramsCasing,
|
|
1275
1389
|
resolver: tsResolver
|
|
1276
1390
|
});
|
|
1277
1391
|
const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
|
|
1278
|
-
const
|
|
1279
|
-
const
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
if (nextParam) {
|
|
1285
|
-
const accessor = getNestedAccessor(nextParam, "lastPage");
|
|
1286
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
1392
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
1393
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1394
|
+
if (hasNewParams) {
|
|
1395
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1396
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1397
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1287
1398
|
}
|
|
1288
|
-
if (
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
}
|
|
1292
|
-
} else if (cursorParam) {
|
|
1293
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1294
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1295
|
-
} else {
|
|
1296
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
1297
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
1298
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
1299
|
-
}
|
|
1399
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
1400
|
+
return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
|
|
1401
|
+
})();
|
|
1300
1402
|
const queryOptionsArr = [
|
|
1301
1403
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
1302
1404
|
getNextPageParamExpr,
|
|
@@ -1318,7 +1420,6 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1318
1420
|
children: `
|
|
1319
1421
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1320
1422
|
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1321
|
-
${enabledText}
|
|
1322
1423
|
queryKey,
|
|
1323
1424
|
queryFn: async ({ signal, pageParam }) => {
|
|
1324
1425
|
${infiniteOverrideParams}
|
|
@@ -1340,7 +1441,6 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1340
1441
|
children: `
|
|
1341
1442
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1342
1443
|
return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
|
|
1343
|
-
${enabledText}
|
|
1344
1444
|
queryKey,
|
|
1345
1445
|
queryFn: async ({ signal }) => {
|
|
1346
1446
|
return ${clientName}(${clientCallStr})
|
|
@@ -1351,15 +1451,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1351
1451
|
})
|
|
1352
1452
|
});
|
|
1353
1453
|
}
|
|
1354
|
-
SuspenseInfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1355
1454
|
//#endregion
|
|
1356
1455
|
//#region src/components/SuspenseQuery.tsx
|
|
1357
1456
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1358
1457
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1359
|
-
function
|
|
1458
|
+
function buildSuspenseQueryParamsNode(node, options) {
|
|
1360
1459
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1361
|
-
const
|
|
1362
|
-
const
|
|
1460
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1461
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1462
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1363
1463
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1364
1464
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1365
1465
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1388,12 +1488,13 @@ function getParams(node, options) {
|
|
|
1388
1488
|
});
|
|
1389
1489
|
}
|
|
1390
1490
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1391
|
-
const
|
|
1491
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1492
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1392
1493
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1393
1494
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1394
1495
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1395
1496
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1396
|
-
const queryKeyParamsNode =
|
|
1497
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1397
1498
|
pathParamsType,
|
|
1398
1499
|
paramsCasing,
|
|
1399
1500
|
resolver: tsResolver
|
|
@@ -1406,7 +1507,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1406
1507
|
resolver: tsResolver
|
|
1407
1508
|
});
|
|
1408
1509
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1409
|
-
const paramsNode =
|
|
1510
|
+
const paramsNode = buildSuspenseQueryParamsNode(node, {
|
|
1410
1511
|
paramsType,
|
|
1411
1512
|
paramsCasing,
|
|
1412
1513
|
pathParamsType,
|
|
@@ -1424,7 +1525,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1424
1525
|
generics: generics.join(", "),
|
|
1425
1526
|
params: paramsSignature,
|
|
1426
1527
|
returnType: void 0,
|
|
1427
|
-
JSDoc: { comments:
|
|
1528
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1428
1529
|
children: `
|
|
1429
1530
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1430
1531
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1444,8 +1545,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1444
1545
|
})
|
|
1445
1546
|
});
|
|
1446
1547
|
}
|
|
1447
|
-
SuspenseQuery.getParams = getParams;
|
|
1448
1548
|
//#endregion
|
|
1449
|
-
export { Mutation as a, InfiniteQuery as c,
|
|
1549
|
+
export { operationFileEntry as _, Mutation as a, InfiniteQuery as c, queryKeyTransformer as d, resolveOperationOverrides as f, getOperationParameters as g, mutationKeyTransformer as h, Query as i, QueryOptions as l, MutationKey as m, SuspenseInfiniteQueryOptions as n, MutationOptions as o, resolveZodSchemaNames as p, SuspenseInfiniteQuery as r, InfiniteQueryOptions as s, SuspenseQuery as t, QueryKey as u, resolveOperationTypeNames as v, camelCase as y };
|
|
1450
1550
|
|
|
1451
|
-
//# sourceMappingURL=components-
|
|
1551
|
+
//# sourceMappingURL=components-IArDg-DO.js.map
|