@kubb/plugin-react-query 5.0.0-beta.3 → 5.0.0-beta.30
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 +34 -83
- package/dist/{components-DTGLu4UV.js → components-CDmg-RPi.js} +275 -255
- package/dist/components-CDmg-RPi.js.map +1 -0
- package/dist/{components-dAKJEn9b.cjs → components-MPBTffPl.cjs} +299 -255
- package/dist/components-MPBTffPl.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -75
- package/dist/components.js +1 -1
- package/dist/{generators-C_fbcjpG.js → generators-Bma51Uar.js} +301 -261
- package/dist/generators-Bma51Uar.js.map +1 -0
- package/dist/{generators-CWEQsdO9.cjs → generators-BtsWNz-6.cjs} +299 -259
- package/dist/generators-BtsWNz-6.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +41 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +143 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +143 -20
- package/dist/index.js.map +1 -1
- package/dist/types-DiZPLTXl.d.ts +400 -0
- package/extension.yaml +1507 -0
- package/package.json +16 -18
- package/src/components/InfiniteQuery.tsx +19 -13
- package/src/components/InfiniteQueryOptions.tsx +29 -47
- package/src/components/Mutation.tsx +35 -15
- package/src/components/MutationOptions.tsx +14 -13
- package/src/components/Query.tsx +9 -10
- package/src/components/QueryOptions.tsx +6 -27
- package/src/components/SuspenseInfiniteQuery.tsx +19 -13
- package/src/components/SuspenseInfiniteQueryOptions.tsx +29 -47
- package/src/components/SuspenseQuery.tsx +9 -10
- package/src/generators/customHookOptionsFileGenerator.tsx +18 -14
- package/src/generators/hookOptionsGenerator.tsx +36 -33
- package/src/generators/infiniteQueryGenerator.tsx +46 -64
- package/src/generators/mutationGenerator.tsx +42 -50
- package/src/generators/queryGenerator.tsx +43 -49
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +41 -51
- package/src/generators/suspenseQueryGenerator.tsx +44 -62
- package/src/plugin.ts +42 -16
- 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
|
@@ -253,16 +253,16 @@ var URLPath = class {
|
|
|
253
253
|
get object() {
|
|
254
254
|
return this.toObject();
|
|
255
255
|
}
|
|
256
|
-
/** Returns a map of path parameter names, or `
|
|
256
|
+
/** Returns a map of path parameter names, or `null` when the path has no parameters.
|
|
257
257
|
*
|
|
258
258
|
* @example
|
|
259
259
|
* ```ts
|
|
260
260
|
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
261
|
-
* new URLPath('/pet').params //
|
|
261
|
+
* new URLPath('/pet').params // null
|
|
262
262
|
* ```
|
|
263
263
|
*/
|
|
264
264
|
get params() {
|
|
265
|
-
return this.
|
|
265
|
+
return this.toParamsObject();
|
|
266
266
|
}
|
|
267
267
|
#transformParam(raw) {
|
|
268
268
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -280,7 +280,7 @@ var URLPath = class {
|
|
|
280
280
|
toObject({ type = "path", replacer, stringify } = {}) {
|
|
281
281
|
const object = {
|
|
282
282
|
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
283
|
-
params: this.
|
|
283
|
+
params: this.toParamsObject()
|
|
284
284
|
};
|
|
285
285
|
if (stringify) {
|
|
286
286
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -296,12 +296,13 @@ var URLPath = class {
|
|
|
296
296
|
* @example
|
|
297
297
|
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
298
298
|
*/
|
|
299
|
-
toTemplateString({ prefix
|
|
300
|
-
|
|
299
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
300
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
301
301
|
if (i % 2 === 0) return part;
|
|
302
302
|
const param = this.#transformParam(part);
|
|
303
303
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
304
|
-
}).join("")
|
|
304
|
+
}).join("");
|
|
305
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
305
306
|
}
|
|
306
307
|
/**
|
|
307
308
|
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
@@ -310,17 +311,17 @@ var URLPath = class {
|
|
|
310
311
|
*
|
|
311
312
|
* @example
|
|
312
313
|
* ```ts
|
|
313
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').
|
|
314
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
314
315
|
* // { petId: 'petId', tagId: 'tagId' }
|
|
315
316
|
* ```
|
|
316
317
|
*/
|
|
317
|
-
|
|
318
|
+
toParamsObject(replacer) {
|
|
318
319
|
const params = {};
|
|
319
320
|
this.#eachParam((_raw, param) => {
|
|
320
321
|
const key = replacer ? replacer(param) : param;
|
|
321
322
|
params[key] = key;
|
|
322
323
|
});
|
|
323
|
-
return Object.keys(params).length > 0 ? params :
|
|
324
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
324
325
|
}
|
|
325
326
|
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
326
327
|
*
|
|
@@ -336,17 +337,13 @@ var URLPath = class {
|
|
|
336
337
|
//#endregion
|
|
337
338
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
338
339
|
const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
339
|
-
|
|
340
|
-
return _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
341
|
-
}
|
|
342
|
-
__name(getParams$6, "getParams");
|
|
343
|
-
const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
|
|
340
|
+
const mutationKeyTransformer = ({ node, casing }) => {
|
|
344
341
|
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
345
|
-
}
|
|
346
|
-
function MutationKey({ name, paramsCasing, node, transformer
|
|
347
|
-
const paramsNode =
|
|
342
|
+
};
|
|
343
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
344
|
+
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
348
345
|
const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
|
|
349
|
-
const keys = transformer({
|
|
346
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
350
347
|
node,
|
|
351
348
|
casing: paramsCasing
|
|
352
349
|
});
|
|
@@ -363,28 +360,141 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
363
360
|
})
|
|
364
361
|
});
|
|
365
362
|
}
|
|
366
|
-
MutationKey.getParams = getParams$6;
|
|
367
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
368
363
|
//#endregion
|
|
369
|
-
//#region ../../internals/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return
|
|
364
|
+
//#region ../../internals/shared/src/operation.ts
|
|
365
|
+
function getOperationLink(node, link) {
|
|
366
|
+
if (!link) return null;
|
|
367
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
368
|
+
if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
|
|
369
|
+
return `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`;
|
|
370
|
+
}
|
|
371
|
+
function getContentTypeInfo(node) {
|
|
372
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
373
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
374
|
+
return {
|
|
375
|
+
contentTypes,
|
|
376
|
+
isMultipleContentTypes,
|
|
377
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
378
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
379
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function buildRequestConfigType(node, resolver) {
|
|
383
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
384
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
385
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
386
|
+
}
|
|
387
|
+
function buildOperationComments(node, options = {}) {
|
|
388
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
389
|
+
const linkComment = getOperationLink(node, link);
|
|
390
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
391
|
+
node.description && `@description ${node.description}`,
|
|
392
|
+
node.summary && `@summary ${node.summary}`,
|
|
393
|
+
linkComment,
|
|
394
|
+
node.deprecated && "@deprecated"
|
|
395
|
+
] : [
|
|
375
396
|
node.description && `@description ${node.description}`,
|
|
376
397
|
node.summary && `@summary ${node.summary}`,
|
|
377
398
|
node.deprecated && "@deprecated",
|
|
378
|
-
|
|
379
|
-
].filter((
|
|
399
|
+
linkComment
|
|
400
|
+
]).filter((comment) => Boolean(comment));
|
|
401
|
+
if (!splitLines) return filteredComments;
|
|
402
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
403
|
+
}
|
|
404
|
+
function getOperationParameters(node, options = {}) {
|
|
405
|
+
const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
|
|
406
|
+
return {
|
|
407
|
+
path: params.filter((param) => param.in === "path"),
|
|
408
|
+
query: params.filter((param) => param.in === "query"),
|
|
409
|
+
header: params.filter((param) => param.in === "header"),
|
|
410
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function getStatusCodeNumber(statusCode) {
|
|
414
|
+
const code = Number(statusCode);
|
|
415
|
+
return Number.isNaN(code) ? null : code;
|
|
416
|
+
}
|
|
417
|
+
function isSuccessStatusCode(statusCode) {
|
|
418
|
+
const code = getStatusCodeNumber(statusCode);
|
|
419
|
+
return code !== null && code >= 200 && code < 300;
|
|
420
|
+
}
|
|
421
|
+
function isErrorStatusCode(statusCode) {
|
|
422
|
+
const code = getStatusCodeNumber(statusCode);
|
|
423
|
+
return code !== null && code >= 400;
|
|
424
|
+
}
|
|
425
|
+
function resolveErrorNames(node, resolver) {
|
|
426
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
427
|
+
}
|
|
428
|
+
function resolveSuccessNames(node, resolver) {
|
|
429
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
430
|
+
}
|
|
431
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
432
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
433
|
+
}
|
|
434
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
435
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
436
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
437
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
438
|
+
if (byResolver) {
|
|
439
|
+
const cached = byResolver.get(cacheKey);
|
|
440
|
+
if (cached) return cached;
|
|
441
|
+
} else {
|
|
442
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
443
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
444
|
+
}
|
|
445
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
446
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
447
|
+
const exclude = new Set(options.exclude ?? []);
|
|
448
|
+
const paramNames = [
|
|
449
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
450
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
451
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
452
|
+
];
|
|
453
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
454
|
+
const result = (options.order === "body-response-first" ? [
|
|
455
|
+
...bodyAndResponseNames,
|
|
456
|
+
...paramNames,
|
|
457
|
+
...responseStatusNames
|
|
458
|
+
] : [
|
|
459
|
+
...paramNames,
|
|
460
|
+
...bodyAndResponseNames,
|
|
461
|
+
...responseStatusNames
|
|
462
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
463
|
+
byResolver.set(cacheKey, result);
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region ../../internals/tanstack-query/src/utils.ts
|
|
468
|
+
function matchesPattern(node, ov) {
|
|
469
|
+
const { type, pattern } = ov;
|
|
470
|
+
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
471
|
+
if (type === "operationId") return matches(node.operationId);
|
|
472
|
+
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
473
|
+
if (type === "path") return matches(node.path);
|
|
474
|
+
if (type === "method") return matches(node.method);
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Resolves per-operation overrides (first matching override wins).
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* const opts = resolveOperationOverrides(node, override)
|
|
483
|
+
* const queryOpts = 'query' in opts ? opts.query : defaultQuery
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
function resolveOperationOverrides(node, override) {
|
|
487
|
+
if (!override) return {};
|
|
488
|
+
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
380
489
|
}
|
|
381
490
|
/**
|
|
382
|
-
*
|
|
491
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
492
|
+
*
|
|
493
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
383
494
|
*/
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
495
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
496
|
+
if (!zodResolver) return [];
|
|
497
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
388
498
|
}
|
|
389
499
|
/**
|
|
390
500
|
* Resolve the type for a single path parameter.
|
|
@@ -408,30 +518,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
408
518
|
}
|
|
409
519
|
/**
|
|
410
520
|
* Derive a query-params group type from the resolver.
|
|
411
|
-
* Returns `
|
|
521
|
+
* Returns `null` when no query params exist or when the group name
|
|
412
522
|
* equals the individual param name (no real group).
|
|
413
523
|
*/
|
|
414
524
|
function resolveQueryGroupType(node, params, resolver) {
|
|
415
|
-
if (!params.length) return
|
|
525
|
+
if (!params.length) return null;
|
|
416
526
|
const firstParam = params[0];
|
|
417
527
|
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
418
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return
|
|
419
|
-
return {
|
|
420
|
-
type: _kubb_core.ast.createParamsType({
|
|
421
|
-
variant: "reference",
|
|
422
|
-
name: groupName
|
|
423
|
-
}),
|
|
424
|
-
optional: params.every((p) => !p.required)
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Derive a header-params group type from the resolver.
|
|
429
|
-
*/
|
|
430
|
-
function resolveHeaderGroupType(node, params, resolver) {
|
|
431
|
-
if (!params.length) return void 0;
|
|
432
|
-
const firstParam = params[0];
|
|
433
|
-
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
434
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
528
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
435
529
|
return {
|
|
436
530
|
type: _kubb_core.ast.createParamsType({
|
|
437
531
|
variant: "reference",
|
|
@@ -481,7 +575,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
575
|
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
482
576
|
variant: "reference",
|
|
483
577
|
name: resolver.resolveDataName(node)
|
|
484
|
-
}) :
|
|
578
|
+
}) : null;
|
|
485
579
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
486
580
|
const params = [];
|
|
487
581
|
if (pathParams.length) {
|
|
@@ -505,67 +599,41 @@ function buildQueryKeyParams(node, options) {
|
|
|
505
599
|
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
506
600
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
507
601
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
519
|
-
const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
|
|
520
|
-
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
521
|
-
variant: "reference",
|
|
522
|
-
name: resolver.resolveDataName(node)
|
|
523
|
-
}) : void 0;
|
|
524
|
-
const bodyRequired = node.requestBody?.required ?? false;
|
|
525
|
-
const params = [];
|
|
526
|
-
for (const p of pathParams) params.push(_kubb_core.ast.createFunctionParameter({
|
|
527
|
-
name: p.name,
|
|
528
|
-
type: resolvePathParamType(node, p, resolver),
|
|
529
|
-
optional: !p.required
|
|
530
|
-
}));
|
|
531
|
-
if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
|
|
532
|
-
name: "data",
|
|
533
|
-
type: bodyType,
|
|
534
|
-
optional: !bodyRequired
|
|
535
|
-
}));
|
|
536
|
-
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
537
|
-
params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
|
|
538
|
-
return _kubb_core.ast.createFunctionParameters({ params });
|
|
602
|
+
function buildEnabledCheck(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.join(" && ");
|
|
539
612
|
}
|
|
540
613
|
//#endregion
|
|
541
614
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
542
615
|
const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
543
|
-
const
|
|
544
|
-
function getParams$5(node, options) {
|
|
545
|
-
return buildQueryKeyParams(node, options);
|
|
546
|
-
}
|
|
547
|
-
__name(getParams$5, "getParams");
|
|
548
|
-
const getTransformer = ({ node, casing }) => {
|
|
616
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
549
617
|
const path = new URLPath(node.path, { casing });
|
|
550
|
-
const hasQueryParams = node.
|
|
618
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
551
619
|
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
552
620
|
return [
|
|
553
621
|
path.toObject({
|
|
554
622
|
type: "path",
|
|
555
623
|
stringify: true
|
|
556
624
|
}),
|
|
557
|
-
hasQueryParams ? "...(params ? [params] : [])" :
|
|
558
|
-
hasRequestBody ? "...(data ? [data] : [])" :
|
|
625
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
626
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
559
627
|
].filter(Boolean);
|
|
560
628
|
};
|
|
561
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer
|
|
562
|
-
const paramsNode =
|
|
629
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
630
|
+
const paramsNode = buildQueryKeyParams(node, {
|
|
563
631
|
pathParamsType,
|
|
564
632
|
paramsCasing,
|
|
565
633
|
resolver: tsResolver
|
|
566
634
|
});
|
|
567
635
|
const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
|
|
568
|
-
const keys = transformer({
|
|
636
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
569
637
|
node,
|
|
570
638
|
casing: paramsCasing
|
|
571
639
|
});
|
|
@@ -589,37 +657,13 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
589
657
|
})
|
|
590
658
|
})] });
|
|
591
659
|
}
|
|
592
|
-
QueryKey.getParams = getParams$5;
|
|
593
|
-
QueryKey.getTransformer = getTransformer;
|
|
594
|
-
QueryKey.callPrinter = callPrinter$9;
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region src/utils.ts
|
|
597
|
-
function transformName(name, type, transformers) {
|
|
598
|
-
return transformers?.name?.(name, type) || name;
|
|
599
|
-
}
|
|
600
|
-
function matchesPattern(node, ov) {
|
|
601
|
-
const { type, pattern } = ov;
|
|
602
|
-
const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
|
|
603
|
-
if (type === "operationId") return matches(node.operationId);
|
|
604
|
-
if (type === "tag") return node.tags.some((t) => matches(t));
|
|
605
|
-
if (type === "path") return matches(node.path);
|
|
606
|
-
if (type === "method") return matches(node.method);
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Resolves per-operation overrides (first matching override wins), mirroring v4 OperationGenerator.getOptions().
|
|
611
|
-
*/
|
|
612
|
-
function resolveOperationOverrides(node, override) {
|
|
613
|
-
if (!override) return {};
|
|
614
|
-
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
615
|
-
}
|
|
616
660
|
//#endregion
|
|
617
661
|
//#region src/components/QueryOptions.tsx
|
|
618
662
|
const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
619
663
|
const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
620
664
|
function getQueryOptionsParams(node, options) {
|
|
621
665
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
622
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
666
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
623
667
|
return _kubb_core.ast.createOperationParams(node, {
|
|
624
668
|
paramsType,
|
|
625
669
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
@@ -635,19 +679,9 @@ function getQueryOptionsParams(node, options) {
|
|
|
635
679
|
})]
|
|
636
680
|
});
|
|
637
681
|
}
|
|
638
|
-
function buildEnabledCheck(paramsNode) {
|
|
639
|
-
const required = [];
|
|
640
|
-
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
641
|
-
const group = param;
|
|
642
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
643
|
-
} else {
|
|
644
|
-
const fp = param;
|
|
645
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
646
|
-
}
|
|
647
|
-
return required.join(" && ");
|
|
648
|
-
}
|
|
649
682
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
650
|
-
const
|
|
683
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
684
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
651
685
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
652
686
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
653
687
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -659,7 +693,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
659
693
|
});
|
|
660
694
|
const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
|
|
661
695
|
const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
662
|
-
const queryKeyParamsNode =
|
|
696
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
663
697
|
pathParamsType,
|
|
664
698
|
paramsCasing,
|
|
665
699
|
resolver: tsResolver
|
|
@@ -688,14 +722,13 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
688
722
|
})
|
|
689
723
|
});
|
|
690
724
|
}
|
|
691
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
692
725
|
//#endregion
|
|
693
726
|
//#region src/components/InfiniteQuery.tsx
|
|
694
727
|
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
695
728
|
const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
696
|
-
function
|
|
729
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
697
730
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
698
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
731
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
699
732
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
700
733
|
name: "options",
|
|
701
734
|
type: _kubb_core.ast.createParamsType({
|
|
@@ -715,9 +748,9 @@ function getParams$4(node, options) {
|
|
|
715
748
|
extraParams: [optionsParam]
|
|
716
749
|
});
|
|
717
750
|
}
|
|
718
|
-
__name(getParams$4, "getParams");
|
|
719
751
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
720
|
-
const
|
|
752
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
753
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
721
754
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
722
755
|
const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
723
756
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -726,12 +759,12 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
726
759
|
const parts = initialPageParam.split(" as ");
|
|
727
760
|
return parts[parts.length - 1] ?? "unknown";
|
|
728
761
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
729
|
-
const rawQueryParams = node
|
|
762
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
730
763
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
731
764
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
732
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
733
|
-
})() :
|
|
734
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
765
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
766
|
+
})() : null;
|
|
767
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
735
768
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
736
769
|
const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
737
770
|
const generics = [
|
|
@@ -741,7 +774,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
741
774
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
742
775
|
`TPageParam = ${pageParamType}`
|
|
743
776
|
];
|
|
744
|
-
const queryKeyParamsNode =
|
|
777
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
745
778
|
pathParamsType,
|
|
746
779
|
paramsCasing,
|
|
747
780
|
resolver: tsResolver
|
|
@@ -754,7 +787,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
754
787
|
resolver: tsResolver
|
|
755
788
|
});
|
|
756
789
|
const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
|
|
757
|
-
const paramsNode =
|
|
790
|
+
const paramsNode = buildInfiniteQueryParamsNode(node, {
|
|
758
791
|
paramsType,
|
|
759
792
|
paramsCasing,
|
|
760
793
|
pathParamsType,
|
|
@@ -773,7 +806,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
773
806
|
generics: generics.join(", "),
|
|
774
807
|
params: paramsSignature,
|
|
775
808
|
returnType: void 0,
|
|
776
|
-
JSDoc: { comments:
|
|
809
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
777
810
|
children: `
|
|
778
811
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
779
812
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -793,13 +826,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
793
826
|
})
|
|
794
827
|
});
|
|
795
828
|
}
|
|
796
|
-
InfiniteQuery.getParams = getParams$4;
|
|
797
829
|
//#endregion
|
|
798
830
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
799
831
|
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
800
832
|
const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
801
833
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
802
|
-
const
|
|
834
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
835
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
803
836
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
804
837
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
805
838
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -808,12 +841,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
808
841
|
const parts = initialPageParam.split(" as ");
|
|
809
842
|
return parts[parts.length - 1] ?? "unknown";
|
|
810
843
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
811
|
-
const rawQueryParams = node
|
|
844
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
812
845
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
813
846
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
814
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
815
|
-
})() :
|
|
816
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
847
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
848
|
+
})() : null;
|
|
849
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
817
850
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
818
851
|
const paramsNode = getQueryOptionsParams(node, {
|
|
819
852
|
paramsType,
|
|
@@ -823,7 +856,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
823
856
|
});
|
|
824
857
|
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
825
858
|
const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
826
|
-
const queryKeyParamsNode =
|
|
859
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
827
860
|
pathParamsType,
|
|
828
861
|
paramsCasing,
|
|
829
862
|
resolver: tsResolver
|
|
@@ -831,26 +864,16 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
831
864
|
const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
|
|
832
865
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
833
866
|
const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
|
|
834
|
-
const hasNewParams = nextParam
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
841
|
-
}
|
|
842
|
-
if (previousParam) {
|
|
843
|
-
const accessor = getNestedAccessor(previousParam, "firstPage");
|
|
844
|
-
if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
|
|
867
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
868
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
869
|
+
if (hasNewParams) {
|
|
870
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
871
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
872
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
845
873
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
} else {
|
|
850
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
851
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
852
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
853
|
-
}
|
|
874
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
875
|
+
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"];
|
|
876
|
+
})();
|
|
854
877
|
const queryOptionsArr = [
|
|
855
878
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
856
879
|
getNextPageParamExpr,
|
|
@@ -905,31 +928,32 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
905
928
|
})
|
|
906
929
|
});
|
|
907
930
|
}
|
|
908
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
909
931
|
//#endregion
|
|
910
932
|
//#region src/components/MutationOptions.tsx
|
|
911
933
|
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
912
934
|
const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
913
935
|
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
914
|
-
function
|
|
915
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
|
|
936
|
+
function buildMutationConfigParamsNode(node, resolver) {
|
|
916
937
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
917
938
|
name: "config",
|
|
918
939
|
type: _kubb_core.ast.createParamsType({
|
|
919
940
|
variant: "reference",
|
|
920
|
-
name:
|
|
941
|
+
name: buildRequestConfigType(node, resolver)
|
|
921
942
|
}),
|
|
922
943
|
default: "{}"
|
|
923
944
|
})] });
|
|
924
945
|
}
|
|
925
946
|
function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
|
|
926
|
-
const
|
|
947
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
948
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
927
949
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
928
950
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
929
951
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
930
|
-
const configParamsNode =
|
|
952
|
+
const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
931
953
|
const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
|
|
932
|
-
const mutationArgParamsNode =
|
|
954
|
+
const mutationArgParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
955
|
+
paramsType: "inline",
|
|
956
|
+
pathParamsType: "inline",
|
|
933
957
|
paramsCasing,
|
|
934
958
|
resolver: tsResolver
|
|
935
959
|
});
|
|
@@ -945,7 +969,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
945
969
|
name: "config",
|
|
946
970
|
type: _kubb_core.ast.createParamsType({
|
|
947
971
|
variant: "reference",
|
|
948
|
-
name: node
|
|
972
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
949
973
|
}),
|
|
950
974
|
default: "{}"
|
|
951
975
|
})]
|
|
@@ -962,7 +986,7 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
962
986
|
generics: ["TContext = unknown"],
|
|
963
987
|
children: `
|
|
964
988
|
const mutationKey = ${mutationKeyName}()
|
|
965
|
-
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "
|
|
989
|
+
return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "undefined"}, TContext>({
|
|
966
990
|
mutationKey,
|
|
967
991
|
mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
|
|
968
992
|
return ${clientName}(${clientCallStr})
|
|
@@ -972,19 +996,26 @@ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, p
|
|
|
972
996
|
})
|
|
973
997
|
});
|
|
974
998
|
}
|
|
975
|
-
MutationOptions.getParams = getConfigParam;
|
|
976
999
|
//#endregion
|
|
977
1000
|
//#region src/components/Mutation.tsx
|
|
978
1001
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
979
1002
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
980
|
-
function
|
|
1003
|
+
function createMutationArgParams(node, options) {
|
|
1004
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
1005
|
+
paramsType: "inline",
|
|
1006
|
+
pathParamsType: "inline",
|
|
1007
|
+
paramsCasing: options.paramsCasing,
|
|
1008
|
+
resolver: options.resolver
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
function buildMutationParamsNode(node, options) {
|
|
981
1012
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
982
|
-
const
|
|
983
|
-
const
|
|
1013
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1014
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
984
1015
|
const errorNames = resolveErrorNames(node, resolver);
|
|
985
1016
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
986
1017
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
987
|
-
const mutationArgParamsNode =
|
|
1018
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
988
1019
|
paramsCasing,
|
|
989
1020
|
resolver
|
|
990
1021
|
});
|
|
@@ -992,7 +1023,7 @@ function getParams$3(node, options) {
|
|
|
992
1023
|
const generics = [
|
|
993
1024
|
TData,
|
|
994
1025
|
TError,
|
|
995
|
-
TRequest ? `{${TRequest}}` : "
|
|
1026
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
996
1027
|
"TContext"
|
|
997
1028
|
].join(", ");
|
|
998
1029
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
@@ -1001,19 +1032,19 @@ function getParams$3(node, options) {
|
|
|
1001
1032
|
variant: "reference",
|
|
1002
1033
|
name: `{
|
|
1003
1034
|
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
1004
|
-
client?: ${
|
|
1035
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
1005
1036
|
}`
|
|
1006
1037
|
}),
|
|
1007
1038
|
default: "{}"
|
|
1008
1039
|
})] });
|
|
1009
1040
|
}
|
|
1010
|
-
__name(getParams$3, "getParams");
|
|
1011
1041
|
function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1012
|
-
const
|
|
1042
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1043
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1013
1044
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1014
1045
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1015
1046
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1016
|
-
const mutationArgParamsNode =
|
|
1047
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1017
1048
|
paramsCasing,
|
|
1018
1049
|
resolver: tsResolver
|
|
1019
1050
|
});
|
|
@@ -1021,13 +1052,13 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1021
1052
|
const generics = [
|
|
1022
1053
|
TData,
|
|
1023
1054
|
TError,
|
|
1024
|
-
TRequest ? `{${TRequest}}` : "
|
|
1055
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1025
1056
|
"TContext"
|
|
1026
1057
|
].join(", ");
|
|
1027
1058
|
const returnType = `UseMutationResult<${generics}>`;
|
|
1028
|
-
const mutationOptionsConfigNode =
|
|
1059
|
+
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
|
|
1029
1060
|
const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
|
|
1030
|
-
const paramsNode =
|
|
1061
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1031
1062
|
paramsCasing,
|
|
1032
1063
|
dataReturnType,
|
|
1033
1064
|
resolver: tsResolver
|
|
@@ -1041,7 +1072,7 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1041
1072
|
name,
|
|
1042
1073
|
export: true,
|
|
1043
1074
|
params: paramsSignature,
|
|
1044
|
-
JSDoc: { comments:
|
|
1075
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1045
1076
|
generics: ["TContext"],
|
|
1046
1077
|
children: `
|
|
1047
1078
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
@@ -1060,15 +1091,15 @@ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, nod
|
|
|
1060
1091
|
})
|
|
1061
1092
|
});
|
|
1062
1093
|
}
|
|
1063
|
-
Mutation.getParams = getParams$3;
|
|
1064
1094
|
//#endregion
|
|
1065
1095
|
//#region src/components/Query.tsx
|
|
1066
1096
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1067
1097
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1068
|
-
function
|
|
1098
|
+
function buildQueryParamsNode(node, options) {
|
|
1069
1099
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1070
|
-
const
|
|
1071
|
-
const
|
|
1100
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1101
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1102
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1072
1103
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1073
1104
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1074
1105
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1097,9 +1128,9 @@ function getParams$2(node, options) {
|
|
|
1097
1128
|
extraParams: [optionsParam]
|
|
1098
1129
|
});
|
|
1099
1130
|
}
|
|
1100
|
-
__name(getParams$2, "getParams");
|
|
1101
1131
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1102
|
-
const
|
|
1132
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1133
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1103
1134
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1104
1135
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1105
1136
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1108,7 +1139,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1108
1139
|
`TQueryData = ${TData}`,
|
|
1109
1140
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1110
1141
|
];
|
|
1111
|
-
const queryKeyParamsNode =
|
|
1142
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1112
1143
|
pathParamsType,
|
|
1113
1144
|
paramsCasing,
|
|
1114
1145
|
resolver: tsResolver
|
|
@@ -1121,7 +1152,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1121
1152
|
resolver: tsResolver
|
|
1122
1153
|
});
|
|
1123
1154
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
1124
|
-
const paramsNode =
|
|
1155
|
+
const paramsNode = buildQueryParamsNode(node, {
|
|
1125
1156
|
paramsType,
|
|
1126
1157
|
paramsCasing,
|
|
1127
1158
|
pathParamsType,
|
|
@@ -1139,7 +1170,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1139
1170
|
generics: generics.join(", "),
|
|
1140
1171
|
params: paramsSignature,
|
|
1141
1172
|
returnType: void 0,
|
|
1142
|
-
JSDoc: { comments:
|
|
1173
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1143
1174
|
children: `
|
|
1144
1175
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1145
1176
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1159,14 +1190,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1159
1190
|
})
|
|
1160
1191
|
});
|
|
1161
1192
|
}
|
|
1162
|
-
Query.getParams = getParams$2;
|
|
1163
1193
|
//#endregion
|
|
1164
1194
|
//#region src/components/SuspenseInfiniteQuery.tsx
|
|
1165
1195
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1166
1196
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1167
|
-
function
|
|
1197
|
+
function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
1168
1198
|
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
|
|
1169
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
1199
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1170
1200
|
const optionsParam = _kubb_core.ast.createFunctionParameter({
|
|
1171
1201
|
name: "options",
|
|
1172
1202
|
type: _kubb_core.ast.createParamsType({
|
|
@@ -1186,9 +1216,9 @@ function getParams$1(node, options) {
|
|
|
1186
1216
|
extraParams: [optionsParam]
|
|
1187
1217
|
});
|
|
1188
1218
|
}
|
|
1189
|
-
__name(getParams$1, "getParams");
|
|
1190
1219
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1191
|
-
const
|
|
1220
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1221
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1192
1222
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1193
1223
|
const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1194
1224
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1197,12 +1227,12 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1197
1227
|
const parts = initialPageParam.split(" as ");
|
|
1198
1228
|
return parts[parts.length - 1] ?? "unknown";
|
|
1199
1229
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1200
|
-
const rawQueryParams = node
|
|
1230
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1201
1231
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1202
1232
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1203
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1204
|
-
})() :
|
|
1205
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1233
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1234
|
+
})() : null;
|
|
1235
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1206
1236
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1207
1237
|
const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
|
|
1208
1238
|
const generics = [
|
|
@@ -1212,7 +1242,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1212
1242
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1213
1243
|
`TPageParam = ${pageParamType}`
|
|
1214
1244
|
];
|
|
1215
|
-
const queryKeyParamsNode =
|
|
1245
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1216
1246
|
pathParamsType,
|
|
1217
1247
|
paramsCasing,
|
|
1218
1248
|
resolver: tsResolver
|
|
@@ -1225,7 +1255,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1225
1255
|
resolver: tsResolver
|
|
1226
1256
|
});
|
|
1227
1257
|
const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
|
|
1228
|
-
const paramsNode =
|
|
1258
|
+
const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
|
|
1229
1259
|
paramsType,
|
|
1230
1260
|
paramsCasing,
|
|
1231
1261
|
pathParamsType,
|
|
@@ -1244,7 +1274,7 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1244
1274
|
generics: generics.join(", "),
|
|
1245
1275
|
params: paramsSignature,
|
|
1246
1276
|
returnType: void 0,
|
|
1247
|
-
JSDoc: { comments:
|
|
1277
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1248
1278
|
children: `
|
|
1249
1279
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1250
1280
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1264,13 +1294,13 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1264
1294
|
})
|
|
1265
1295
|
});
|
|
1266
1296
|
}
|
|
1267
|
-
SuspenseInfiniteQuery.getParams = getParams$1;
|
|
1268
1297
|
//#endregion
|
|
1269
1298
|
//#region src/components/SuspenseInfiniteQueryOptions.tsx
|
|
1270
1299
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1271
1300
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1272
1301
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
1273
|
-
const
|
|
1302
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1303
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1274
1304
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1275
1305
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1276
1306
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1279,12 +1309,12 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1279
1309
|
const parts = initialPageParam.split(" as ");
|
|
1280
1310
|
return parts[parts.length - 1] ?? "unknown";
|
|
1281
1311
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1282
|
-
const rawQueryParams = node
|
|
1312
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
1283
1313
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1284
1314
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
1285
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
1286
|
-
})() :
|
|
1287
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
1315
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
1316
|
+
})() : null;
|
|
1317
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1288
1318
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
1289
1319
|
const paramsNode = getQueryOptionsParams(node, {
|
|
1290
1320
|
paramsType,
|
|
@@ -1294,7 +1324,7 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1294
1324
|
});
|
|
1295
1325
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1296
1326
|
const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
1297
|
-
const queryKeyParamsNode =
|
|
1327
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1298
1328
|
pathParamsType,
|
|
1299
1329
|
paramsCasing,
|
|
1300
1330
|
resolver: tsResolver
|
|
@@ -1302,26 +1332,16 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1302
1332
|
const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
|
|
1303
1333
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
1304
1334
|
const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
|
|
1305
|
-
const hasNewParams = nextParam
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
1335
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
1336
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1337
|
+
if (hasNewParams) {
|
|
1338
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1339
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1340
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1312
1341
|
}
|
|
1313
|
-
if (
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
} else if (cursorParam) {
|
|
1318
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1319
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1320
|
-
} else {
|
|
1321
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
1322
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
1323
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
1324
|
-
}
|
|
1342
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
1343
|
+
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"];
|
|
1344
|
+
})();
|
|
1325
1345
|
const queryOptionsArr = [
|
|
1326
1346
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
1327
1347
|
getNextPageParamExpr,
|
|
@@ -1376,15 +1396,15 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1376
1396
|
})
|
|
1377
1397
|
});
|
|
1378
1398
|
}
|
|
1379
|
-
SuspenseInfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1380
1399
|
//#endregion
|
|
1381
1400
|
//#region src/components/SuspenseQuery.tsx
|
|
1382
1401
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1383
1402
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1384
|
-
function
|
|
1403
|
+
function buildSuspenseQueryParamsNode(node, options) {
|
|
1385
1404
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1386
|
-
const
|
|
1387
|
-
const
|
|
1405
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1406
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1407
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1388
1408
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1389
1409
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1390
1410
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1413,12 +1433,13 @@ function getParams(node, options) {
|
|
|
1413
1433
|
});
|
|
1414
1434
|
}
|
|
1415
1435
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
|
|
1416
|
-
const
|
|
1436
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1437
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1417
1438
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1418
1439
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1419
1440
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
1420
1441
|
const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
|
|
1421
|
-
const queryKeyParamsNode =
|
|
1442
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1422
1443
|
pathParamsType,
|
|
1423
1444
|
paramsCasing,
|
|
1424
1445
|
resolver: tsResolver
|
|
@@ -1431,7 +1452,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1431
1452
|
resolver: tsResolver
|
|
1432
1453
|
});
|
|
1433
1454
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1434
|
-
const paramsNode =
|
|
1455
|
+
const paramsNode = buildSuspenseQueryParamsNode(node, {
|
|
1435
1456
|
paramsType,
|
|
1436
1457
|
paramsCasing,
|
|
1437
1458
|
pathParamsType,
|
|
@@ -1449,7 +1470,7 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1449
1470
|
generics: generics.join(", "),
|
|
1450
1471
|
params: paramsSignature,
|
|
1451
1472
|
returnType: void 0,
|
|
1452
|
-
JSDoc: { comments:
|
|
1473
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1453
1474
|
children: `
|
|
1454
1475
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1455
1476
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1469,7 +1490,6 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1469
1490
|
})
|
|
1470
1491
|
});
|
|
1471
1492
|
}
|
|
1472
|
-
SuspenseQuery.getParams = getParams;
|
|
1473
1493
|
//#endregion
|
|
1474
1494
|
Object.defineProperty(exports, "InfiniteQuery", {
|
|
1475
1495
|
enumerable: true,
|
|
@@ -1555,17 +1575,41 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
1555
1575
|
return camelCase;
|
|
1556
1576
|
}
|
|
1557
1577
|
});
|
|
1578
|
+
Object.defineProperty(exports, "getOperationParameters", {
|
|
1579
|
+
enumerable: true,
|
|
1580
|
+
get: function() {
|
|
1581
|
+
return getOperationParameters;
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
Object.defineProperty(exports, "mutationKeyTransformer", {
|
|
1585
|
+
enumerable: true,
|
|
1586
|
+
get: function() {
|
|
1587
|
+
return mutationKeyTransformer;
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
Object.defineProperty(exports, "queryKeyTransformer", {
|
|
1591
|
+
enumerable: true,
|
|
1592
|
+
get: function() {
|
|
1593
|
+
return queryKeyTransformer;
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1558
1596
|
Object.defineProperty(exports, "resolveOperationOverrides", {
|
|
1559
1597
|
enumerable: true,
|
|
1560
1598
|
get: function() {
|
|
1561
1599
|
return resolveOperationOverrides;
|
|
1562
1600
|
}
|
|
1563
1601
|
});
|
|
1564
|
-
Object.defineProperty(exports, "
|
|
1602
|
+
Object.defineProperty(exports, "resolveOperationTypeNames", {
|
|
1603
|
+
enumerable: true,
|
|
1604
|
+
get: function() {
|
|
1605
|
+
return resolveOperationTypeNames;
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
1565
1609
|
enumerable: true,
|
|
1566
1610
|
get: function() {
|
|
1567
|
-
return
|
|
1611
|
+
return resolveZodSchemaNames;
|
|
1568
1612
|
}
|
|
1569
1613
|
});
|
|
1570
1614
|
|
|
1571
|
-
//# sourceMappingURL=components-
|
|
1615
|
+
//# sourceMappingURL=components-MPBTffPl.cjs.map
|