@kubb/plugin-vue-query 5.0.0-beta.3 → 5.0.0-beta.31
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 +26 -5
- package/dist/{components-qfOFRSoM.cjs → components-B6lPYyOP.cjs} +367 -381
- package/dist/components-B6lPYyOP.cjs.map +1 -0
- package/dist/{components-D1UhYFgY.js → components-BZqujNQv.js} +336 -380
- package/dist/components-BZqujNQv.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +3 -67
- package/dist/components.js +1 -1
- package/dist/{generators-CbnIVBgY.js → generators-C-3isXzW.js} +158 -203
- package/dist/generators-C-3isXzW.js.map +1 -0
- package/dist/{generators-C4gs_P1i.cjs → generators-QHQkbNnm.cjs} +157 -202
- package/dist/generators-QHQkbNnm.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +17 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +136 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +136 -23
- package/dist/index.js.map +1 -1
- package/dist/types-D-LjzI_Q.d.ts +270 -0
- package/extension.yaml +1273 -0
- package/package.json +16 -18
- package/src/components/InfiniteQuery.tsx +16 -48
- package/src/components/InfiniteQueryOptions.tsx +43 -58
- package/src/components/Mutation.tsx +33 -42
- package/src/components/Query.tsx +16 -49
- package/src/components/QueryKey.tsx +9 -61
- package/src/components/QueryOptions.tsx +20 -76
- package/src/generators/infiniteQueryGenerator.tsx +55 -63
- package/src/generators/mutationGenerator.tsx +50 -61
- package/src/generators/queryGenerator.tsx +52 -61
- package/src/plugin.ts +46 -30
- package/src/resolvers/resolverVueQuery.ts +61 -4
- package/src/types.ts +129 -53
- package/src/utils.ts +44 -25
- package/dist/components-D1UhYFgY.js.map +0 -1
- package/dist/components-qfOFRSoM.cjs.map +0 -1
- package/dist/generators-C4gs_P1i.cjs.map +0 -1
- package/dist/generators-CbnIVBgY.js.map +0 -1
- package/dist/types-nVDTfuS1.d.ts +0 -194
|
@@ -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
|
*
|
|
@@ -334,19 +335,138 @@ var URLPath = class {
|
|
|
334
335
|
}
|
|
335
336
|
};
|
|
336
337
|
//#endregion
|
|
337
|
-
//#region ../../internals/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
//#region ../../internals/shared/src/operation.ts
|
|
339
|
+
/**
|
|
340
|
+
* Builds the `ResolverFileParams` every operation generator passes to
|
|
341
|
+
* `resolver.resolveFile`: a file named `name`, tagged by the operation's first
|
|
342
|
+
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
343
|
+
* that was repeated at dozens of call sites across the client and query plugins.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
function operationFileEntry(node, name, extname = ".ts") {
|
|
351
|
+
return {
|
|
352
|
+
name,
|
|
353
|
+
extname,
|
|
354
|
+
tag: node.tags[0] ?? "default",
|
|
355
|
+
path: node.path
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function getOperationLink(node, link) {
|
|
359
|
+
if (!link) return null;
|
|
360
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
361
|
+
if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
|
|
362
|
+
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
363
|
+
}
|
|
364
|
+
function getContentTypeInfo(node) {
|
|
365
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
366
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
367
|
+
return {
|
|
368
|
+
contentTypes,
|
|
369
|
+
isMultipleContentTypes,
|
|
370
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
371
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
372
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function buildRequestConfigType(node, resolver) {
|
|
376
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
377
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
378
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
379
|
+
}
|
|
380
|
+
function buildOperationComments(node, options = {}) {
|
|
381
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
382
|
+
const linkComment = getOperationLink(node, link);
|
|
383
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
384
|
+
node.description && `@description ${node.description}`,
|
|
385
|
+
node.summary && `@summary ${node.summary}`,
|
|
386
|
+
linkComment,
|
|
387
|
+
node.deprecated && "@deprecated"
|
|
388
|
+
] : [
|
|
389
|
+
node.description && `@description ${node.description}`,
|
|
390
|
+
node.summary && `@summary ${node.summary}`,
|
|
391
|
+
node.deprecated && "@deprecated",
|
|
392
|
+
linkComment
|
|
393
|
+
]).filter((comment) => Boolean(comment));
|
|
394
|
+
if (!splitLines) return filteredComments;
|
|
395
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
396
|
+
}
|
|
397
|
+
function getOperationParameters(node, options = {}) {
|
|
398
|
+
const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
|
|
399
|
+
return {
|
|
400
|
+
path: params.filter((param) => param.in === "path"),
|
|
401
|
+
query: params.filter((param) => param.in === "query"),
|
|
402
|
+
header: params.filter((param) => param.in === "header"),
|
|
403
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function getStatusCodeNumber(statusCode) {
|
|
407
|
+
const code = Number(statusCode);
|
|
408
|
+
return Number.isNaN(code) ? null : code;
|
|
409
|
+
}
|
|
410
|
+
function isSuccessStatusCode(statusCode) {
|
|
411
|
+
const code = getStatusCodeNumber(statusCode);
|
|
412
|
+
return code !== null && code >= 200 && code < 300;
|
|
413
|
+
}
|
|
414
|
+
function isErrorStatusCode(statusCode) {
|
|
415
|
+
const code = getStatusCodeNumber(statusCode);
|
|
416
|
+
return code !== null && code >= 400;
|
|
417
|
+
}
|
|
418
|
+
function resolveErrorNames(node, resolver) {
|
|
419
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
420
|
+
}
|
|
421
|
+
function resolveSuccessNames(node, resolver) {
|
|
422
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
423
|
+
}
|
|
424
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
425
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
341
426
|
}
|
|
342
|
-
|
|
343
|
-
|
|
427
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
428
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
429
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
430
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
431
|
+
if (byResolver) {
|
|
432
|
+
const cached = byResolver.get(cacheKey);
|
|
433
|
+
if (cached) return cached;
|
|
434
|
+
} else {
|
|
435
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
436
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
437
|
+
}
|
|
438
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
439
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
440
|
+
const exclude = new Set(options.exclude ?? []);
|
|
441
|
+
const paramNames = [
|
|
442
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
443
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
444
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
445
|
+
];
|
|
446
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
447
|
+
const result = (options.order === "body-response-first" ? [
|
|
448
|
+
...bodyAndResponseNames,
|
|
449
|
+
...paramNames,
|
|
450
|
+
...responseStatusNames
|
|
451
|
+
] : [
|
|
452
|
+
...paramNames,
|
|
453
|
+
...bodyAndResponseNames,
|
|
454
|
+
...responseStatusNames
|
|
455
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
456
|
+
byResolver.set(cacheKey, result);
|
|
457
|
+
return result;
|
|
458
|
+
}
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
461
|
+
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
462
|
+
const mutationKeyTransformer = ({ node, casing }) => {
|
|
463
|
+
if (!node.path) return [];
|
|
344
464
|
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
345
|
-
}
|
|
346
|
-
function MutationKey({ name, paramsCasing, node, transformer
|
|
347
|
-
const paramsNode =
|
|
348
|
-
const paramsSignature = declarationPrinter$
|
|
349
|
-
const keys = transformer({
|
|
465
|
+
};
|
|
466
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
467
|
+
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
468
|
+
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
469
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
350
470
|
node,
|
|
351
471
|
casing: paramsCasing
|
|
352
472
|
});
|
|
@@ -363,28 +483,16 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
363
483
|
})
|
|
364
484
|
});
|
|
365
485
|
}
|
|
366
|
-
MutationKey.getParams = getParams$4;
|
|
367
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
368
486
|
//#endregion
|
|
369
487
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
370
488
|
/**
|
|
371
|
-
*
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return [
|
|
375
|
-
node.description && `@description ${node.description}`,
|
|
376
|
-
node.summary && `@summary ${node.summary}`,
|
|
377
|
-
node.deprecated && "@deprecated",
|
|
378
|
-
`{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`
|
|
379
|
-
].filter((x) => Boolean(x));
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Resolve error type names from operation responses.
|
|
489
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
490
|
+
*
|
|
491
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
383
492
|
*/
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
493
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
494
|
+
if (!zodResolver) return [];
|
|
495
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
388
496
|
}
|
|
389
497
|
/**
|
|
390
498
|
* Resolve the type for a single path parameter.
|
|
@@ -408,30 +516,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
408
516
|
}
|
|
409
517
|
/**
|
|
410
518
|
* Derive a query-params group type from the resolver.
|
|
411
|
-
* Returns `
|
|
519
|
+
* Returns `null` when no query params exist or when the group name
|
|
412
520
|
* equals the individual param name (no real group).
|
|
413
521
|
*/
|
|
414
522
|
function resolveQueryGroupType(node, params, resolver) {
|
|
415
|
-
if (!params.length) return
|
|
523
|
+
if (!params.length) return null;
|
|
416
524
|
const firstParam = params[0];
|
|
417
525
|
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;
|
|
526
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
435
527
|
return {
|
|
436
528
|
type: _kubb_core.ast.createParamsType({
|
|
437
529
|
variant: "reference",
|
|
@@ -481,7 +573,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
573
|
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
482
574
|
variant: "reference",
|
|
483
575
|
name: resolver.resolveDataName(node)
|
|
484
|
-
}) :
|
|
576
|
+
}) : null;
|
|
485
577
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
486
578
|
const params = [];
|
|
487
579
|
if (pathParams.length) {
|
|
@@ -506,47 +598,84 @@ function buildQueryKeyParams(node, options) {
|
|
|
506
598
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
507
599
|
}
|
|
508
600
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
601
|
+
* Collect the names of the required params (no default) that drive the `enabled`
|
|
602
|
+
* guard. These are exactly the params that should be made optional in the
|
|
603
|
+
* generated signatures so callers can pass `undefined` to reach the disabled state.
|
|
511
604
|
*/
|
|
512
|
-
function
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
605
|
+
function getEnabledParamNames(paramsNode) {
|
|
606
|
+
const required = [];
|
|
607
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
608
|
+
const group = param;
|
|
609
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
610
|
+
} else {
|
|
611
|
+
const fp = param;
|
|
612
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
613
|
+
}
|
|
614
|
+
return required;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Return a copy of `paramsNode` with the named params marked optional.
|
|
618
|
+
*
|
|
619
|
+
* Used to align signatures with the `enabled` guard: the guard already disables
|
|
620
|
+
* the query while a param is falsy, so the param should accept `undefined`. The
|
|
621
|
+
* change is type-only — the `queryFn` keeps calling the client with a non-null
|
|
622
|
+
* assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
|
|
623
|
+
*/
|
|
624
|
+
function markParamsOptional(paramsNode, names) {
|
|
625
|
+
if (names.length === 0) return paramsNode;
|
|
626
|
+
const nameSet = new Set(names);
|
|
627
|
+
const params = paramsNode.params.map((param) => {
|
|
628
|
+
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
629
|
+
const group = param;
|
|
630
|
+
return {
|
|
631
|
+
...group,
|
|
632
|
+
properties: group.properties.map((child) => nameSet.has(child.name) ? _kubb_core.ast.createFunctionParameter({
|
|
633
|
+
name: child.name,
|
|
634
|
+
type: child.type,
|
|
635
|
+
rest: child.rest,
|
|
636
|
+
optional: true
|
|
637
|
+
}) : child)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
const fp = param;
|
|
641
|
+
return nameSet.has(fp.name) ? _kubb_core.ast.createFunctionParameter({
|
|
642
|
+
name: fp.name,
|
|
643
|
+
type: fp.type,
|
|
644
|
+
rest: fp.rest,
|
|
645
|
+
optional: true
|
|
646
|
+
}) : fp;
|
|
647
|
+
});
|
|
538
648
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
539
649
|
}
|
|
650
|
+
(0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
651
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
652
|
+
if (!node.path) return [];
|
|
653
|
+
const path = new URLPath(node.path, { casing });
|
|
654
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
655
|
+
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
656
|
+
return [
|
|
657
|
+
path.toObject({
|
|
658
|
+
type: "path",
|
|
659
|
+
stringify: true
|
|
660
|
+
}),
|
|
661
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
662
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
663
|
+
].filter(Boolean);
|
|
664
|
+
};
|
|
540
665
|
//#endregion
|
|
541
666
|
//#region src/utils.ts
|
|
542
|
-
function
|
|
543
|
-
|
|
667
|
+
function printType(typeNode) {
|
|
668
|
+
if (!typeNode) return "unknown";
|
|
669
|
+
if (typeNode.variant === "reference") return typeNode.name;
|
|
670
|
+
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
671
|
+
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
672
|
+
const typeStr = printType(p.type);
|
|
673
|
+
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
674
|
+
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
675
|
+
}).join("; ")} }`;
|
|
676
|
+
return "unknown";
|
|
544
677
|
}
|
|
545
|
-
|
|
546
|
-
//#region src/components/QueryKey.tsx
|
|
547
|
-
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
548
|
-
const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
549
|
-
function wrapWithMaybeRefOrGetter(paramsNode) {
|
|
678
|
+
function wrapWithMaybeRefOrGetter(paramsNode, skip) {
|
|
550
679
|
const wrappedParams = paramsNode.params.map((param) => {
|
|
551
680
|
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
552
681
|
const group = param;
|
|
@@ -556,59 +685,38 @@ function wrapWithMaybeRefOrGetter(paramsNode) {
|
|
|
556
685
|
...p,
|
|
557
686
|
type: p.type ? _kubb_core.ast.createParamsType({
|
|
558
687
|
variant: "reference",
|
|
559
|
-
name: `MaybeRefOrGetter<${printType
|
|
688
|
+
name: `MaybeRefOrGetter<${printType(p.type)}>`
|
|
560
689
|
}) : p.type
|
|
561
690
|
}))
|
|
562
691
|
};
|
|
563
692
|
}
|
|
564
693
|
const fp = param;
|
|
694
|
+
if (skip?.(fp.name)) return fp;
|
|
565
695
|
return {
|
|
566
696
|
...fp,
|
|
567
697
|
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
568
698
|
variant: "reference",
|
|
569
|
-
name: `MaybeRefOrGetter<${printType
|
|
699
|
+
name: `MaybeRefOrGetter<${printType(fp.type)}>`
|
|
570
700
|
}) : fp.type
|
|
571
701
|
};
|
|
572
702
|
});
|
|
573
703
|
return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
|
|
574
704
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
580
|
-
const typeStr = printType$4(p.type);
|
|
581
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
582
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
583
|
-
}).join("; ")} }`;
|
|
584
|
-
return "unknown";
|
|
585
|
-
}
|
|
586
|
-
__name(printType$4, "printType");
|
|
587
|
-
function getParams$3(node, options) {
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/components/QueryKey.tsx
|
|
707
|
+
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
708
|
+
function buildQueryKeyParamsNode(node, options) {
|
|
588
709
|
return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
|
|
589
710
|
}
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
const path = new URLPath(node.path, { casing });
|
|
593
|
-
const hasQueryParams = node.parameters.some((p) => p.in === "query");
|
|
594
|
-
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
595
|
-
return [
|
|
596
|
-
path.toObject({
|
|
597
|
-
type: "path",
|
|
598
|
-
stringify: true
|
|
599
|
-
}),
|
|
600
|
-
hasQueryParams ? "...(params ? [params] : [])" : void 0,
|
|
601
|
-
hasRequestBody ? "...(data ? [data] : [])" : void 0
|
|
602
|
-
].filter(Boolean);
|
|
603
|
-
};
|
|
604
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = getTransformer }) {
|
|
605
|
-
const paramsNode = getParams$3(node, {
|
|
711
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
712
|
+
const baseParamsNode = buildQueryKeyParamsNode(node, {
|
|
606
713
|
pathParamsType,
|
|
607
714
|
paramsCasing,
|
|
608
715
|
resolver: tsResolver
|
|
609
716
|
});
|
|
717
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
|
|
610
718
|
const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
|
|
611
|
-
const keys = transformer({
|
|
719
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
612
720
|
node,
|
|
613
721
|
casing: paramsCasing
|
|
614
722
|
});
|
|
@@ -635,17 +743,14 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
635
743
|
})
|
|
636
744
|
})] });
|
|
637
745
|
}
|
|
638
|
-
QueryKey.getParams = getParams$3;
|
|
639
|
-
QueryKey.getTransformer = getTransformer;
|
|
640
|
-
QueryKey.callPrinter = callPrinter$5;
|
|
641
746
|
//#endregion
|
|
642
747
|
//#region src/components/QueryOptions.tsx
|
|
643
748
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
644
749
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
645
750
|
function getQueryOptionsParams(node, options) {
|
|
646
751
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
647
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
648
|
-
return
|
|
752
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
753
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
649
754
|
paramsType,
|
|
650
755
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
651
756
|
paramsCasing,
|
|
@@ -658,80 +763,30 @@ function getQueryOptionsParams(node, options) {
|
|
|
658
763
|
}),
|
|
659
764
|
default: "{}"
|
|
660
765
|
})]
|
|
661
|
-
}));
|
|
662
|
-
}
|
|
663
|
-
function wrapOperationParamsWithMaybeRef$2(paramsNode) {
|
|
664
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
665
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
666
|
-
const group = param;
|
|
667
|
-
return {
|
|
668
|
-
...group,
|
|
669
|
-
properties: group.properties.map((p) => ({
|
|
670
|
-
...p,
|
|
671
|
-
type: p.type ? _kubb_core.ast.createParamsType({
|
|
672
|
-
variant: "reference",
|
|
673
|
-
name: `MaybeRefOrGetter<${printType$3(p.type)}>`
|
|
674
|
-
}) : p.type
|
|
675
|
-
}))
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
const fp = param;
|
|
679
|
-
if (fp.name === "config") return fp;
|
|
680
|
-
return {
|
|
681
|
-
...fp,
|
|
682
|
-
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
683
|
-
variant: "reference",
|
|
684
|
-
name: `MaybeRefOrGetter<${printType$3(fp.type)}>`
|
|
685
|
-
}) : fp.type
|
|
686
|
-
};
|
|
687
|
-
});
|
|
688
|
-
return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
|
|
689
|
-
}
|
|
690
|
-
__name(wrapOperationParamsWithMaybeRef$2, "wrapOperationParamsWithMaybeRef");
|
|
691
|
-
function printType$3(typeNode) {
|
|
692
|
-
if (!typeNode) return "unknown";
|
|
693
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
694
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
695
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
696
|
-
const typeStr = printType$3(p.type);
|
|
697
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
698
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
699
|
-
}).join("; ")} }`;
|
|
700
|
-
return "unknown";
|
|
701
|
-
}
|
|
702
|
-
__name(printType$3, "printType");
|
|
703
|
-
function buildEnabledCheck(paramsNode) {
|
|
704
|
-
const required = [];
|
|
705
|
-
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
706
|
-
const group = param;
|
|
707
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
708
|
-
} else {
|
|
709
|
-
const fp = param;
|
|
710
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
711
|
-
}
|
|
712
|
-
return required.join(" && ");
|
|
766
|
+
}), (name) => name === "config");
|
|
713
767
|
}
|
|
714
768
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
715
|
-
const
|
|
769
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
770
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
716
771
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
717
772
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
718
773
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
719
|
-
const
|
|
774
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
775
|
+
pathParamsType,
|
|
776
|
+
paramsCasing,
|
|
777
|
+
resolver: tsResolver
|
|
778
|
+
});
|
|
779
|
+
const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
|
|
780
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
781
|
+
const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
|
|
782
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
720
783
|
paramsType,
|
|
721
784
|
paramsCasing,
|
|
722
785
|
pathParamsType,
|
|
723
786
|
resolver: tsResolver
|
|
724
|
-
});
|
|
787
|
+
}), enabledNames);
|
|
725
788
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
726
789
|
const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
727
|
-
const queryKeyParamsNode = QueryKey.getParams(node, {
|
|
728
|
-
pathParamsType,
|
|
729
|
-
paramsCasing,
|
|
730
|
-
resolver: tsResolver
|
|
731
|
-
});
|
|
732
|
-
const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
|
|
733
|
-
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
734
|
-
const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : "";
|
|
735
790
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
736
791
|
name,
|
|
737
792
|
isExportable: true,
|
|
@@ -746,7 +801,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
746
801
|
${enabledText}
|
|
747
802
|
queryKey,
|
|
748
803
|
queryFn: async ({ signal }) => {
|
|
749
|
-
return ${clientName}(${addToValueCalls$1(clientCallStr)})
|
|
804
|
+
return ${clientName}(${addToValueCalls$1(clientCallStr, enabledNames)})
|
|
750
805
|
},
|
|
751
806
|
})
|
|
752
807
|
`
|
|
@@ -760,28 +815,29 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
760
815
|
* Handles both inline params (`petId, config`) and object shorthand
|
|
761
816
|
* params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
|
|
762
817
|
*/
|
|
763
|
-
function addToValueCalls$1(callStr) {
|
|
818
|
+
function addToValueCalls$1(callStr, enabledNames = []) {
|
|
819
|
+
const optional = new Set(enabledNames);
|
|
764
820
|
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
765
821
|
if (inner.includes(":") || inner.includes("...")) return match;
|
|
766
|
-
return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
|
|
822
|
+
return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
|
|
767
823
|
});
|
|
768
824
|
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
|
|
769
825
|
if (name === "config" || name === "signal" || name === "undefined") return match;
|
|
770
826
|
if (match.includes("toValue(")) return match;
|
|
771
|
-
return `toValue(${name})`;
|
|
827
|
+
return `toValue(${optional.has(name) ? `${name}!` : name})`;
|
|
772
828
|
});
|
|
773
829
|
return result;
|
|
774
830
|
}
|
|
775
831
|
__name(addToValueCalls$1, "addToValueCalls");
|
|
776
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
777
832
|
//#endregion
|
|
778
833
|
//#region src/components/InfiniteQuery.tsx
|
|
779
834
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
780
835
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
781
|
-
function
|
|
836
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
782
837
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
783
|
-
const
|
|
784
|
-
const
|
|
838
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
839
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
840
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
785
841
|
const errorNames = resolveErrorNames(node, resolver);
|
|
786
842
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
787
843
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -802,57 +858,17 @@ function getParams$2(node, options) {
|
|
|
802
858
|
}),
|
|
803
859
|
default: "{}"
|
|
804
860
|
});
|
|
805
|
-
return
|
|
861
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
806
862
|
paramsType,
|
|
807
863
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
808
864
|
paramsCasing,
|
|
809
865
|
resolver,
|
|
810
866
|
extraParams: [optionsParam]
|
|
811
|
-
}));
|
|
867
|
+
}), (name) => name === "options");
|
|
812
868
|
}
|
|
813
|
-
__name(getParams$2, "getParams");
|
|
814
|
-
function wrapOperationParamsWithMaybeRef$1(paramsNode) {
|
|
815
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
816
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
817
|
-
const group = param;
|
|
818
|
-
return {
|
|
819
|
-
...group,
|
|
820
|
-
properties: group.properties.map((p) => ({
|
|
821
|
-
...p,
|
|
822
|
-
type: p.type ? _kubb_core.ast.createParamsType({
|
|
823
|
-
variant: "reference",
|
|
824
|
-
name: `MaybeRefOrGetter<${printType$2(p.type)}>`
|
|
825
|
-
}) : p.type
|
|
826
|
-
}))
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
const fp = param;
|
|
830
|
-
if (fp.name === "options") return fp;
|
|
831
|
-
return {
|
|
832
|
-
...fp,
|
|
833
|
-
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
834
|
-
variant: "reference",
|
|
835
|
-
name: `MaybeRefOrGetter<${printType$2(fp.type)}>`
|
|
836
|
-
}) : fp.type
|
|
837
|
-
};
|
|
838
|
-
});
|
|
839
|
-
return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
|
|
840
|
-
}
|
|
841
|
-
__name(wrapOperationParamsWithMaybeRef$1, "wrapOperationParamsWithMaybeRef");
|
|
842
|
-
function printType$2(typeNode) {
|
|
843
|
-
if (!typeNode) return "unknown";
|
|
844
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
845
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
846
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
847
|
-
const typeStr = printType$2(p.type);
|
|
848
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
849
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
850
|
-
}).join("; ")} }`;
|
|
851
|
-
return "unknown";
|
|
852
|
-
}
|
|
853
|
-
__name(printType$2, "printType");
|
|
854
869
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
855
|
-
const
|
|
870
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
871
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
856
872
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
857
873
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
858
874
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -862,12 +878,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
862
878
|
`TQueryData = ${TData}`,
|
|
863
879
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
864
880
|
];
|
|
865
|
-
const queryKeyParamsNode =
|
|
881
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
866
882
|
pathParamsType,
|
|
867
883
|
paramsCasing,
|
|
868
884
|
resolver: tsResolver
|
|
869
885
|
});
|
|
870
886
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
887
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
871
888
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
872
889
|
paramsType,
|
|
873
890
|
paramsCasing,
|
|
@@ -875,13 +892,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
875
892
|
resolver: tsResolver
|
|
876
893
|
});
|
|
877
894
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
878
|
-
const paramsNode =
|
|
895
|
+
const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
|
|
879
896
|
paramsType,
|
|
880
897
|
paramsCasing,
|
|
881
898
|
pathParamsType,
|
|
882
899
|
dataReturnType,
|
|
883
900
|
resolver: tsResolver
|
|
884
|
-
});
|
|
901
|
+
}), enabledNames);
|
|
885
902
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
886
903
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
887
904
|
name,
|
|
@@ -892,7 +909,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
892
909
|
export: true,
|
|
893
910
|
generics: generics.join(", "),
|
|
894
911
|
params: paramsSignature,
|
|
895
|
-
JSDoc: { comments:
|
|
912
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
896
913
|
children: `
|
|
897
914
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
898
915
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -911,13 +928,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
911
928
|
})
|
|
912
929
|
});
|
|
913
930
|
}
|
|
914
|
-
InfiniteQuery.getParams = getParams$2;
|
|
915
931
|
//#endregion
|
|
916
932
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
917
933
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
918
934
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
919
935
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
920
|
-
const
|
|
936
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
937
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
921
938
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
922
939
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
923
940
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -926,49 +943,39 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
926
943
|
const parts = initialPageParam.split(" as ");
|
|
927
944
|
return parts[parts.length - 1] ?? "unknown";
|
|
928
945
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
929
|
-
const rawQueryParams = node
|
|
946
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
930
947
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
931
948
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
932
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
933
|
-
})() :
|
|
934
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
949
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
950
|
+
})() : null;
|
|
951
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
935
952
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
936
|
-
const
|
|
953
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
954
|
+
pathParamsType,
|
|
955
|
+
paramsCasing,
|
|
956
|
+
resolver: tsResolver
|
|
957
|
+
});
|
|
958
|
+
const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
|
|
959
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
960
|
+
const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
|
|
961
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
|
|
937
962
|
paramsType,
|
|
938
963
|
paramsCasing,
|
|
939
964
|
pathParamsType,
|
|
940
965
|
resolver: tsResolver
|
|
941
|
-
});
|
|
966
|
+
}), enabledNames);
|
|
942
967
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
943
968
|
const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
951
|
-
const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : "";
|
|
952
|
-
const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
|
|
953
|
-
let getNextPageParamExpr;
|
|
954
|
-
let getPreviousPageParamExpr;
|
|
955
|
-
if (hasNewParams) {
|
|
956
|
-
if (nextParam) {
|
|
957
|
-
const accessor = getNestedAccessor(nextParam, "lastPage");
|
|
958
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
969
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
970
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
971
|
+
if (hasNewParams) {
|
|
972
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
973
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
974
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
959
975
|
}
|
|
960
|
-
if (
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
}
|
|
964
|
-
} else if (cursorParam) {
|
|
965
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
966
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
967
|
-
} else {
|
|
968
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
969
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
970
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
971
|
-
}
|
|
976
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
977
|
+
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"];
|
|
978
|
+
})();
|
|
972
979
|
const queryOptionsArr = [
|
|
973
980
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
974
981
|
getNextPageParamExpr,
|
|
@@ -994,7 +1001,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
994
1001
|
queryKey,
|
|
995
1002
|
queryFn: async ({ signal, pageParam }) => {
|
|
996
1003
|
${infiniteOverrideParams}
|
|
997
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
1004
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
998
1005
|
},
|
|
999
1006
|
${queryOptionsArr.join(",\n")}
|
|
1000
1007
|
})
|
|
@@ -1015,7 +1022,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1015
1022
|
${enabledText}
|
|
1016
1023
|
queryKey,
|
|
1017
1024
|
queryFn: async ({ signal }) => {
|
|
1018
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
1025
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
1019
1026
|
},
|
|
1020
1027
|
${queryOptionsArr.join(",\n")}
|
|
1021
1028
|
})
|
|
@@ -1023,45 +1030,43 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1023
1030
|
})
|
|
1024
1031
|
});
|
|
1025
1032
|
}
|
|
1026
|
-
function addToValueCalls(callStr) {
|
|
1033
|
+
function addToValueCalls(callStr, enabledNames = []) {
|
|
1034
|
+
const optional = new Set(enabledNames);
|
|
1027
1035
|
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
|
|
1028
1036
|
if (inner.includes(":") || inner.includes("...")) return match;
|
|
1029
|
-
return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
|
|
1037
|
+
return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
|
|
1030
1038
|
});
|
|
1031
1039
|
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
|
|
1032
1040
|
if (name === "config" || name === "signal" || name === "undefined") return match;
|
|
1033
1041
|
if (match.includes("toValue(")) return match;
|
|
1034
|
-
return `toValue(${name})`;
|
|
1042
|
+
return `toValue(${optional.has(name) ? `${name}!` : name})`;
|
|
1035
1043
|
});
|
|
1036
1044
|
return result;
|
|
1037
1045
|
}
|
|
1038
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1039
1046
|
//#endregion
|
|
1040
1047
|
//#region src/components/Mutation.tsx
|
|
1041
1048
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1042
1049
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1043
1050
|
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
1044
|
-
function
|
|
1051
|
+
function createMutationArgParams(node, options) {
|
|
1052
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
1053
|
+
paramsType: "inline",
|
|
1054
|
+
pathParamsType: "inline",
|
|
1055
|
+
paramsCasing: options.paramsCasing,
|
|
1056
|
+
resolver: options.resolver
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
function buildMutationParamsNode(node, options) {
|
|
1045
1060
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
1046
|
-
const
|
|
1047
|
-
const
|
|
1061
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1062
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1048
1063
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1049
1064
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1050
1065
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1051
|
-
const
|
|
1066
|
+
const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
|
|
1052
1067
|
paramsCasing,
|
|
1053
1068
|
resolver
|
|
1054
|
-
})
|
|
1055
|
-
const fp = param;
|
|
1056
|
-
return {
|
|
1057
|
-
...fp,
|
|
1058
|
-
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
1059
|
-
variant: "reference",
|
|
1060
|
-
name: `MaybeRefOrGetter<${printType$1(fp.type)}>`
|
|
1061
|
-
}) : fp.type
|
|
1062
|
-
};
|
|
1063
|
-
});
|
|
1064
|
-
const wrappedParamsNode = _kubb_core.ast.createFunctionParameters({ params: mutationArgWrapped });
|
|
1069
|
+
}));
|
|
1065
1070
|
const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
|
|
1066
1071
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
1067
1072
|
name: "options",
|
|
@@ -1071,34 +1076,22 @@ function getParams$1(node, options) {
|
|
|
1071
1076
|
mutation?: MutationObserverOptions<${[
|
|
1072
1077
|
TData,
|
|
1073
1078
|
TError,
|
|
1074
|
-
TRequestWrapped ? `{${TRequestWrapped}}` : "
|
|
1079
|
+
TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
|
|
1075
1080
|
"TContext"
|
|
1076
1081
|
].join(", ")}> & { client?: QueryClient },
|
|
1077
|
-
client?: ${
|
|
1082
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
1078
1083
|
}`
|
|
1079
1084
|
}),
|
|
1080
1085
|
default: "{}"
|
|
1081
1086
|
})] });
|
|
1082
1087
|
}
|
|
1083
|
-
__name(getParams$1, "getParams");
|
|
1084
|
-
function printType$1(typeNode) {
|
|
1085
|
-
if (!typeNode) return "unknown";
|
|
1086
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
1087
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
1088
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
1089
|
-
const typeStr = printType$1(p.type);
|
|
1090
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
1091
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
1092
|
-
}).join("; ")} }`;
|
|
1093
|
-
return "unknown";
|
|
1094
|
-
}
|
|
1095
|
-
__name(printType$1, "printType");
|
|
1096
1088
|
function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
|
|
1097
|
-
const
|
|
1089
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1090
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1098
1091
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1099
1092
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1100
1093
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1101
|
-
const mutationArgParamsNode =
|
|
1094
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1102
1095
|
paramsCasing,
|
|
1103
1096
|
resolver: tsResolver
|
|
1104
1097
|
});
|
|
@@ -1108,10 +1101,10 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1108
1101
|
const generics = [
|
|
1109
1102
|
TData,
|
|
1110
1103
|
TError,
|
|
1111
|
-
TRequest ? `{${TRequest}}` : "
|
|
1104
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1112
1105
|
"TContext"
|
|
1113
1106
|
].join(", ");
|
|
1114
|
-
const mutationKeyParamsNode =
|
|
1107
|
+
const mutationKeyParamsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
1115
1108
|
const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
|
|
1116
1109
|
const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
1117
1110
|
paramsType,
|
|
@@ -1122,13 +1115,13 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1122
1115
|
name: "config",
|
|
1123
1116
|
type: _kubb_core.ast.createParamsType({
|
|
1124
1117
|
variant: "reference",
|
|
1125
|
-
name: node
|
|
1118
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
1126
1119
|
}),
|
|
1127
1120
|
default: "{}"
|
|
1128
1121
|
})]
|
|
1129
1122
|
});
|
|
1130
1123
|
const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
|
|
1131
|
-
const paramsNode =
|
|
1124
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1132
1125
|
paramsCasing,
|
|
1133
1126
|
dataReturnType,
|
|
1134
1127
|
resolver: tsResolver
|
|
@@ -1142,7 +1135,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1142
1135
|
name,
|
|
1143
1136
|
export: true,
|
|
1144
1137
|
params: paramsSignature,
|
|
1145
|
-
JSDoc: { comments:
|
|
1138
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1146
1139
|
generics: ["TContext"],
|
|
1147
1140
|
children: `
|
|
1148
1141
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
@@ -1160,15 +1153,15 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1160
1153
|
})
|
|
1161
1154
|
});
|
|
1162
1155
|
}
|
|
1163
|
-
Mutation.getParams = getParams$1;
|
|
1164
1156
|
//#endregion
|
|
1165
1157
|
//#region src/components/Query.tsx
|
|
1166
1158
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1167
1159
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1168
|
-
function
|
|
1160
|
+
function buildQueryParamsNode(node, options) {
|
|
1169
1161
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1170
|
-
const
|
|
1171
|
-
const
|
|
1162
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1163
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1164
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1172
1165
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1173
1166
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1174
1167
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1189,54 +1182,17 @@ function getParams(node, options) {
|
|
|
1189
1182
|
}),
|
|
1190
1183
|
default: "{}"
|
|
1191
1184
|
});
|
|
1192
|
-
return
|
|
1185
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
1193
1186
|
paramsType,
|
|
1194
1187
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1195
1188
|
paramsCasing,
|
|
1196
1189
|
resolver,
|
|
1197
1190
|
extraParams: [optionsParam]
|
|
1198
|
-
}));
|
|
1199
|
-
}
|
|
1200
|
-
function wrapOperationParamsWithMaybeRef(paramsNode) {
|
|
1201
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
1202
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
1203
|
-
const group = param;
|
|
1204
|
-
return {
|
|
1205
|
-
...group,
|
|
1206
|
-
properties: group.properties.map((p) => ({
|
|
1207
|
-
...p,
|
|
1208
|
-
type: p.type ? _kubb_core.ast.createParamsType({
|
|
1209
|
-
variant: "reference",
|
|
1210
|
-
name: `MaybeRefOrGetter<${printType(p.type)}>`
|
|
1211
|
-
}) : p.type
|
|
1212
|
-
}))
|
|
1213
|
-
};
|
|
1214
|
-
}
|
|
1215
|
-
const fp = param;
|
|
1216
|
-
if (fp.name === "options") return fp;
|
|
1217
|
-
return {
|
|
1218
|
-
...fp,
|
|
1219
|
-
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
1220
|
-
variant: "reference",
|
|
1221
|
-
name: `MaybeRefOrGetter<${printType(fp.type)}>`
|
|
1222
|
-
}) : fp.type
|
|
1223
|
-
};
|
|
1224
|
-
});
|
|
1225
|
-
return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
|
|
1226
|
-
}
|
|
1227
|
-
function printType(typeNode) {
|
|
1228
|
-
if (!typeNode) return "unknown";
|
|
1229
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
1230
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
1231
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
1232
|
-
const typeStr = printType(p.type);
|
|
1233
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
1234
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
1235
|
-
}).join("; ")} }`;
|
|
1236
|
-
return "unknown";
|
|
1191
|
+
}), (name) => name === "options");
|
|
1237
1192
|
}
|
|
1238
1193
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
1239
|
-
const
|
|
1194
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1195
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1240
1196
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1241
1197
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1242
1198
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1246,12 +1202,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1246
1202
|
`TQueryData = ${TData}`,
|
|
1247
1203
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1248
1204
|
];
|
|
1249
|
-
const queryKeyParamsNode =
|
|
1205
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
1250
1206
|
pathParamsType,
|
|
1251
1207
|
paramsCasing,
|
|
1252
1208
|
resolver: tsResolver
|
|
1253
1209
|
});
|
|
1254
1210
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1211
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode);
|
|
1255
1212
|
const queryOptionsParamsNode = getQueryOptionsParams(node, {
|
|
1256
1213
|
paramsType,
|
|
1257
1214
|
paramsCasing,
|
|
@@ -1259,13 +1216,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1259
1216
|
resolver: tsResolver
|
|
1260
1217
|
});
|
|
1261
1218
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1262
|
-
const paramsNode =
|
|
1219
|
+
const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
|
|
1263
1220
|
paramsType,
|
|
1264
1221
|
paramsCasing,
|
|
1265
1222
|
pathParamsType,
|
|
1266
1223
|
dataReturnType,
|
|
1267
1224
|
resolver: tsResolver
|
|
1268
|
-
});
|
|
1225
|
+
}), enabledNames);
|
|
1269
1226
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1270
1227
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1271
1228
|
name,
|
|
@@ -1276,7 +1233,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1276
1233
|
export: true,
|
|
1277
1234
|
generics: generics.join(", "),
|
|
1278
1235
|
params: paramsSignature,
|
|
1279
|
-
JSDoc: { comments:
|
|
1236
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1280
1237
|
children: `
|
|
1281
1238
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1282
1239
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1295,7 +1252,6 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1295
1252
|
})
|
|
1296
1253
|
});
|
|
1297
1254
|
}
|
|
1298
|
-
Query.getParams = getParams;
|
|
1299
1255
|
//#endregion
|
|
1300
1256
|
Object.defineProperty(exports, "InfiniteQuery", {
|
|
1301
1257
|
enumerable: true,
|
|
@@ -1357,11 +1313,41 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
1357
1313
|
return camelCase;
|
|
1358
1314
|
}
|
|
1359
1315
|
});
|
|
1360
|
-
Object.defineProperty(exports, "
|
|
1316
|
+
Object.defineProperty(exports, "getOperationParameters", {
|
|
1317
|
+
enumerable: true,
|
|
1318
|
+
get: function() {
|
|
1319
|
+
return getOperationParameters;
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
Object.defineProperty(exports, "mutationKeyTransformer", {
|
|
1323
|
+
enumerable: true,
|
|
1324
|
+
get: function() {
|
|
1325
|
+
return mutationKeyTransformer;
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
Object.defineProperty(exports, "operationFileEntry", {
|
|
1329
|
+
enumerable: true,
|
|
1330
|
+
get: function() {
|
|
1331
|
+
return operationFileEntry;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
Object.defineProperty(exports, "queryKeyTransformer", {
|
|
1335
|
+
enumerable: true,
|
|
1336
|
+
get: function() {
|
|
1337
|
+
return queryKeyTransformer;
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
Object.defineProperty(exports, "resolveOperationTypeNames", {
|
|
1341
|
+
enumerable: true,
|
|
1342
|
+
get: function() {
|
|
1343
|
+
return resolveOperationTypeNames;
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
1361
1347
|
enumerable: true,
|
|
1362
1348
|
get: function() {
|
|
1363
|
-
return
|
|
1349
|
+
return resolveZodSchemaNames;
|
|
1364
1350
|
}
|
|
1365
1351
|
});
|
|
1366
1352
|
|
|
1367
|
-
//# sourceMappingURL=components-
|
|
1353
|
+
//# sourceMappingURL=components-B6lPYyOP.cjs.map
|