@kubb/plugin-vue-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 +26 -5
- package/dist/{components-D1UhYFgY.js → components-B4IlVmNa.js} +244 -353
- package/dist/components-B4IlVmNa.js.map +1 -0
- package/dist/{components-qfOFRSoM.cjs → components-CIedagno.cjs} +269 -354
- package/dist/components-CIedagno.cjs.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-ClYptnDj.js} +144 -132
- package/dist/generators-ClYptnDj.js.map +1 -0
- package/dist/{generators-C4gs_P1i.cjs → generators-D7kNtBBo.cjs} +142 -130
- package/dist/generators-D7kNtBBo.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 +100 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +100 -17
- 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 +11 -48
- package/src/components/InfiniteQueryOptions.tsx +38 -50
- package/src/components/Mutation.tsx +33 -42
- package/src/components/Query.tsx +11 -49
- package/src/components/QueryKey.tsx +8 -61
- package/src/components/QueryOptions.tsx +14 -67
- package/src/generators/infiniteQueryGenerator.tsx +46 -51
- package/src/generators/mutationGenerator.tsx +41 -49
- package/src/generators/queryGenerator.tsx +43 -49
- package/src/plugin.ts +43 -15
- 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
|
*
|
|
@@ -335,18 +336,14 @@ var URLPath = class {
|
|
|
335
336
|
};
|
|
336
337
|
//#endregion
|
|
337
338
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
338
|
-
const declarationPrinter$
|
|
339
|
-
|
|
340
|
-
return _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
341
|
-
}
|
|
342
|
-
__name(getParams$4, "getParams");
|
|
343
|
-
const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
|
|
339
|
+
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
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 =
|
|
348
|
-
const paramsSignature = declarationPrinter$
|
|
349
|
-
const keys = transformer({
|
|
342
|
+
};
|
|
343
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
344
|
+
const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
345
|
+
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
346
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
350
347
|
node,
|
|
351
348
|
casing: paramsCasing
|
|
352
349
|
});
|
|
@@ -363,28 +360,119 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
363
360
|
})
|
|
364
361
|
});
|
|
365
362
|
}
|
|
366
|
-
MutationKey.getParams = getParams$4;
|
|
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;
|
|
380
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
|
|
381
468
|
/**
|
|
382
|
-
*
|
|
469
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
470
|
+
*
|
|
471
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
383
472
|
*/
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
473
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
474
|
+
if (!zodResolver) return [];
|
|
475
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
388
476
|
}
|
|
389
477
|
/**
|
|
390
478
|
* Resolve the type for a single path parameter.
|
|
@@ -408,30 +496,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
408
496
|
}
|
|
409
497
|
/**
|
|
410
498
|
* Derive a query-params group type from the resolver.
|
|
411
|
-
* Returns `
|
|
499
|
+
* Returns `null` when no query params exist or when the group name
|
|
412
500
|
* equals the individual param name (no real group).
|
|
413
501
|
*/
|
|
414
502
|
function resolveQueryGroupType(node, params, resolver) {
|
|
415
|
-
if (!params.length) return
|
|
503
|
+
if (!params.length) return null;
|
|
416
504
|
const firstParam = params[0];
|
|
417
505
|
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;
|
|
506
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
435
507
|
return {
|
|
436
508
|
type: _kubb_core.ast.createParamsType({
|
|
437
509
|
variant: "reference",
|
|
@@ -481,7 +553,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
481
553
|
const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
|
|
482
554
|
variant: "reference",
|
|
483
555
|
name: resolver.resolveDataName(node)
|
|
484
|
-
}) :
|
|
556
|
+
}) : null;
|
|
485
557
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
486
558
|
const params = [];
|
|
487
559
|
if (pathParams.length) {
|
|
@@ -505,48 +577,45 @@ function buildQueryKeyParams(node, options) {
|
|
|
505
577
|
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
506
578
|
return _kubb_core.ast.createFunctionParameters({ params });
|
|
507
579
|
}
|
|
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 });
|
|
580
|
+
function buildEnabledCheck(paramsNode) {
|
|
581
|
+
const required = [];
|
|
582
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
583
|
+
const group = param;
|
|
584
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
585
|
+
} else {
|
|
586
|
+
const fp = param;
|
|
587
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
588
|
+
}
|
|
589
|
+
return required.join(" && ");
|
|
539
590
|
}
|
|
591
|
+
(0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
592
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
593
|
+
const path = new URLPath(node.path, { casing });
|
|
594
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
595
|
+
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
596
|
+
return [
|
|
597
|
+
path.toObject({
|
|
598
|
+
type: "path",
|
|
599
|
+
stringify: true
|
|
600
|
+
}),
|
|
601
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
602
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
603
|
+
].filter(Boolean);
|
|
604
|
+
};
|
|
540
605
|
//#endregion
|
|
541
606
|
//#region src/utils.ts
|
|
542
|
-
function
|
|
543
|
-
|
|
607
|
+
function printType(typeNode) {
|
|
608
|
+
if (!typeNode) return "unknown";
|
|
609
|
+
if (typeNode.variant === "reference") return typeNode.name;
|
|
610
|
+
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
611
|
+
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
612
|
+
const typeStr = printType(p.type);
|
|
613
|
+
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
614
|
+
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
615
|
+
}).join("; ")} }`;
|
|
616
|
+
return "unknown";
|
|
544
617
|
}
|
|
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) {
|
|
618
|
+
function wrapWithMaybeRefOrGetter(paramsNode, skip) {
|
|
550
619
|
const wrappedParams = paramsNode.params.map((param) => {
|
|
551
620
|
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
552
621
|
const group = param;
|
|
@@ -556,59 +625,37 @@ function wrapWithMaybeRefOrGetter(paramsNode) {
|
|
|
556
625
|
...p,
|
|
557
626
|
type: p.type ? _kubb_core.ast.createParamsType({
|
|
558
627
|
variant: "reference",
|
|
559
|
-
name: `MaybeRefOrGetter<${printType
|
|
628
|
+
name: `MaybeRefOrGetter<${printType(p.type)}>`
|
|
560
629
|
}) : p.type
|
|
561
630
|
}))
|
|
562
631
|
};
|
|
563
632
|
}
|
|
564
633
|
const fp = param;
|
|
634
|
+
if (skip?.(fp.name)) return fp;
|
|
565
635
|
return {
|
|
566
636
|
...fp,
|
|
567
637
|
type: fp.type ? _kubb_core.ast.createParamsType({
|
|
568
638
|
variant: "reference",
|
|
569
|
-
name: `MaybeRefOrGetter<${printType
|
|
639
|
+
name: `MaybeRefOrGetter<${printType(fp.type)}>`
|
|
570
640
|
}) : fp.type
|
|
571
641
|
};
|
|
572
642
|
});
|
|
573
643
|
return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
|
|
574
644
|
}
|
|
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) {
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/components/QueryKey.tsx
|
|
647
|
+
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
648
|
+
function buildQueryKeyParamsNode(node, options) {
|
|
588
649
|
return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
|
|
589
650
|
}
|
|
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, {
|
|
651
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
652
|
+
const paramsNode = buildQueryKeyParamsNode(node, {
|
|
606
653
|
pathParamsType,
|
|
607
654
|
paramsCasing,
|
|
608
655
|
resolver: tsResolver
|
|
609
656
|
});
|
|
610
657
|
const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
|
|
611
|
-
const keys = transformer({
|
|
658
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
612
659
|
node,
|
|
613
660
|
casing: paramsCasing
|
|
614
661
|
});
|
|
@@ -635,17 +682,14 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
635
682
|
})
|
|
636
683
|
})] });
|
|
637
684
|
}
|
|
638
|
-
QueryKey.getParams = getParams$3;
|
|
639
|
-
QueryKey.getTransformer = getTransformer;
|
|
640
|
-
QueryKey.callPrinter = callPrinter$5;
|
|
641
685
|
//#endregion
|
|
642
686
|
//#region src/components/QueryOptions.tsx
|
|
643
687
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
644
688
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
645
689
|
function getQueryOptionsParams(node, options) {
|
|
646
690
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
647
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
648
|
-
return
|
|
691
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
692
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
649
693
|
paramsType,
|
|
650
694
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
651
695
|
paramsCasing,
|
|
@@ -658,61 +702,11 @@ function getQueryOptionsParams(node, options) {
|
|
|
658
702
|
}),
|
|
659
703
|
default: "{}"
|
|
660
704
|
})]
|
|
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(" && ");
|
|
705
|
+
}), (name) => name === "config");
|
|
713
706
|
}
|
|
714
707
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
715
|
-
const
|
|
708
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
709
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
716
710
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
717
711
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
718
712
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -724,14 +718,14 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
724
718
|
});
|
|
725
719
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
726
720
|
const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
727
|
-
const queryKeyParamsNode =
|
|
721
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
728
722
|
pathParamsType,
|
|
729
723
|
paramsCasing,
|
|
730
724
|
resolver: tsResolver
|
|
731
725
|
});
|
|
732
726
|
const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
|
|
733
727
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
734
|
-
const enabledText = enabledSource ? `enabled: () =>
|
|
728
|
+
const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
|
|
735
729
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
736
730
|
name,
|
|
737
731
|
isExportable: true,
|
|
@@ -773,15 +767,15 @@ function addToValueCalls$1(callStr) {
|
|
|
773
767
|
return result;
|
|
774
768
|
}
|
|
775
769
|
__name(addToValueCalls$1, "addToValueCalls");
|
|
776
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
777
770
|
//#endregion
|
|
778
771
|
//#region src/components/InfiniteQuery.tsx
|
|
779
772
|
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
780
773
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
781
|
-
function
|
|
774
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
782
775
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
783
|
-
const
|
|
784
|
-
const
|
|
776
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
777
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
778
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
785
779
|
const errorNames = resolveErrorNames(node, resolver);
|
|
786
780
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
787
781
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -802,57 +796,17 @@ function getParams$2(node, options) {
|
|
|
802
796
|
}),
|
|
803
797
|
default: "{}"
|
|
804
798
|
});
|
|
805
|
-
return
|
|
799
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
806
800
|
paramsType,
|
|
807
801
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
808
802
|
paramsCasing,
|
|
809
803
|
resolver,
|
|
810
804
|
extraParams: [optionsParam]
|
|
811
|
-
}));
|
|
805
|
+
}), (name) => name === "options");
|
|
812
806
|
}
|
|
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
807
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
855
|
-
const
|
|
808
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
809
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
856
810
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
857
811
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
858
812
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -862,7 +816,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
862
816
|
`TQueryData = ${TData}`,
|
|
863
817
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
864
818
|
];
|
|
865
|
-
const queryKeyParamsNode =
|
|
819
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
866
820
|
pathParamsType,
|
|
867
821
|
paramsCasing,
|
|
868
822
|
resolver: tsResolver
|
|
@@ -875,7 +829,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
875
829
|
resolver: tsResolver
|
|
876
830
|
});
|
|
877
831
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
878
|
-
const paramsNode =
|
|
832
|
+
const paramsNode = buildInfiniteQueryParamsNode(node, {
|
|
879
833
|
paramsType,
|
|
880
834
|
paramsCasing,
|
|
881
835
|
pathParamsType,
|
|
@@ -892,7 +846,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
892
846
|
export: true,
|
|
893
847
|
generics: generics.join(", "),
|
|
894
848
|
params: paramsSignature,
|
|
895
|
-
JSDoc: { comments:
|
|
849
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
896
850
|
children: `
|
|
897
851
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
898
852
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -911,13 +865,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
911
865
|
})
|
|
912
866
|
});
|
|
913
867
|
}
|
|
914
|
-
InfiniteQuery.getParams = getParams$2;
|
|
915
868
|
//#endregion
|
|
916
869
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
917
870
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
918
871
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
919
872
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
920
|
-
const
|
|
873
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
874
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
921
875
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
922
876
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
923
877
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -926,12 +880,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
926
880
|
const parts = initialPageParam.split(" as ");
|
|
927
881
|
return parts[parts.length - 1] ?? "unknown";
|
|
928
882
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
929
|
-
const rawQueryParams = node
|
|
883
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
930
884
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
931
885
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
932
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
933
|
-
})() :
|
|
934
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
886
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
887
|
+
})() : null;
|
|
888
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
935
889
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
936
890
|
const paramsNode = getQueryOptionsParams(node, {
|
|
937
891
|
paramsType,
|
|
@@ -941,34 +895,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
941
895
|
});
|
|
942
896
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
943
897
|
const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
944
|
-
const queryKeyParamsNode =
|
|
898
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
945
899
|
pathParamsType,
|
|
946
900
|
paramsCasing,
|
|
947
901
|
resolver: tsResolver
|
|
948
902
|
});
|
|
949
903
|
const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
|
|
950
904
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
951
|
-
const enabledText = enabledSource ? `enabled: () =>
|
|
952
|
-
const hasNewParams = nextParam
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
959
|
-
}
|
|
960
|
-
if (previousParam) {
|
|
961
|
-
const accessor = getNestedAccessor(previousParam, "firstPage");
|
|
962
|
-
if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
|
|
905
|
+
const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
|
|
906
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
907
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
908
|
+
if (hasNewParams) {
|
|
909
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
910
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
911
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
963
912
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
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
|
-
}
|
|
913
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
914
|
+
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"];
|
|
915
|
+
})();
|
|
972
916
|
const queryOptionsArr = [
|
|
973
917
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
974
918
|
getNextPageParamExpr,
|
|
@@ -1035,33 +979,30 @@ function addToValueCalls(callStr) {
|
|
|
1035
979
|
});
|
|
1036
980
|
return result;
|
|
1037
981
|
}
|
|
1038
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1039
982
|
//#endregion
|
|
1040
983
|
//#region src/components/Mutation.tsx
|
|
1041
984
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1042
985
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1043
986
|
const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
|
|
1044
|
-
function
|
|
987
|
+
function createMutationArgParams(node, options) {
|
|
988
|
+
return _kubb_core.ast.createOperationParams(node, {
|
|
989
|
+
paramsType: "inline",
|
|
990
|
+
pathParamsType: "inline",
|
|
991
|
+
paramsCasing: options.paramsCasing,
|
|
992
|
+
resolver: options.resolver
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
function buildMutationParamsNode(node, options) {
|
|
1045
996
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
1046
|
-
const
|
|
1047
|
-
const
|
|
997
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
998
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1048
999
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1049
1000
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1050
1001
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1051
|
-
const
|
|
1002
|
+
const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
|
|
1052
1003
|
paramsCasing,
|
|
1053
1004
|
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 });
|
|
1005
|
+
}));
|
|
1065
1006
|
const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
|
|
1066
1007
|
return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
|
|
1067
1008
|
name: "options",
|
|
@@ -1071,34 +1012,22 @@ function getParams$1(node, options) {
|
|
|
1071
1012
|
mutation?: MutationObserverOptions<${[
|
|
1072
1013
|
TData,
|
|
1073
1014
|
TError,
|
|
1074
|
-
TRequestWrapped ? `{${TRequestWrapped}}` : "
|
|
1015
|
+
TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
|
|
1075
1016
|
"TContext"
|
|
1076
1017
|
].join(", ")}> & { client?: QueryClient },
|
|
1077
|
-
client?: ${
|
|
1018
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
1078
1019
|
}`
|
|
1079
1020
|
}),
|
|
1080
1021
|
default: "{}"
|
|
1081
1022
|
})] });
|
|
1082
1023
|
}
|
|
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
1024
|
function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
|
|
1097
|
-
const
|
|
1025
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1026
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1098
1027
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1099
1028
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1100
1029
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1101
|
-
const mutationArgParamsNode =
|
|
1030
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1102
1031
|
paramsCasing,
|
|
1103
1032
|
resolver: tsResolver
|
|
1104
1033
|
});
|
|
@@ -1108,10 +1037,10 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1108
1037
|
const generics = [
|
|
1109
1038
|
TData,
|
|
1110
1039
|
TError,
|
|
1111
|
-
TRequest ? `{${TRequest}}` : "
|
|
1040
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1112
1041
|
"TContext"
|
|
1113
1042
|
].join(", ");
|
|
1114
|
-
const mutationKeyParamsNode =
|
|
1043
|
+
const mutationKeyParamsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
|
|
1115
1044
|
const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
|
|
1116
1045
|
const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
|
|
1117
1046
|
paramsType,
|
|
@@ -1122,13 +1051,13 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1122
1051
|
name: "config",
|
|
1123
1052
|
type: _kubb_core.ast.createParamsType({
|
|
1124
1053
|
variant: "reference",
|
|
1125
|
-
name: node
|
|
1054
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
1126
1055
|
}),
|
|
1127
1056
|
default: "{}"
|
|
1128
1057
|
})]
|
|
1129
1058
|
});
|
|
1130
1059
|
const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
|
|
1131
|
-
const paramsNode =
|
|
1060
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1132
1061
|
paramsCasing,
|
|
1133
1062
|
dataReturnType,
|
|
1134
1063
|
resolver: tsResolver
|
|
@@ -1142,7 +1071,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1142
1071
|
name,
|
|
1143
1072
|
export: true,
|
|
1144
1073
|
params: paramsSignature,
|
|
1145
|
-
JSDoc: { comments:
|
|
1074
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1146
1075
|
generics: ["TContext"],
|
|
1147
1076
|
children: `
|
|
1148
1077
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
@@ -1160,15 +1089,15 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1160
1089
|
})
|
|
1161
1090
|
});
|
|
1162
1091
|
}
|
|
1163
|
-
Mutation.getParams = getParams$1;
|
|
1164
1092
|
//#endregion
|
|
1165
1093
|
//#region src/components/Query.tsx
|
|
1166
1094
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1167
1095
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1168
|
-
function
|
|
1096
|
+
function buildQueryParamsNode(node, options) {
|
|
1169
1097
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1170
|
-
const
|
|
1171
|
-
const
|
|
1098
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1099
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1100
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1172
1101
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1173
1102
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1174
1103
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1189,54 +1118,17 @@ function getParams(node, options) {
|
|
|
1189
1118
|
}),
|
|
1190
1119
|
default: "{}"
|
|
1191
1120
|
});
|
|
1192
|
-
return
|
|
1121
|
+
return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
|
|
1193
1122
|
paramsType,
|
|
1194
1123
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1195
1124
|
paramsCasing,
|
|
1196
1125
|
resolver,
|
|
1197
1126
|
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";
|
|
1127
|
+
}), (name) => name === "options");
|
|
1237
1128
|
}
|
|
1238
1129
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
1239
|
-
const
|
|
1130
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1131
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1240
1132
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1241
1133
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1242
1134
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1246,7 +1138,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1246
1138
|
`TQueryData = ${TData}`,
|
|
1247
1139
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1248
1140
|
];
|
|
1249
|
-
const queryKeyParamsNode =
|
|
1141
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
1250
1142
|
pathParamsType,
|
|
1251
1143
|
paramsCasing,
|
|
1252
1144
|
resolver: tsResolver
|
|
@@ -1259,7 +1151,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1259
1151
|
resolver: tsResolver
|
|
1260
1152
|
});
|
|
1261
1153
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1262
|
-
const paramsNode =
|
|
1154
|
+
const paramsNode = buildQueryParamsNode(node, {
|
|
1263
1155
|
paramsType,
|
|
1264
1156
|
paramsCasing,
|
|
1265
1157
|
pathParamsType,
|
|
@@ -1276,7 +1168,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1276
1168
|
export: true,
|
|
1277
1169
|
generics: generics.join(", "),
|
|
1278
1170
|
params: paramsSignature,
|
|
1279
|
-
JSDoc: { comments:
|
|
1171
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1280
1172
|
children: `
|
|
1281
1173
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1282
1174
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1295,7 +1187,6 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1295
1187
|
})
|
|
1296
1188
|
});
|
|
1297
1189
|
}
|
|
1298
|
-
Query.getParams = getParams;
|
|
1299
1190
|
//#endregion
|
|
1300
1191
|
Object.defineProperty(exports, "InfiniteQuery", {
|
|
1301
1192
|
enumerable: true,
|
|
@@ -1357,11 +1248,35 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
1357
1248
|
return camelCase;
|
|
1358
1249
|
}
|
|
1359
1250
|
});
|
|
1360
|
-
Object.defineProperty(exports, "
|
|
1251
|
+
Object.defineProperty(exports, "getOperationParameters", {
|
|
1252
|
+
enumerable: true,
|
|
1253
|
+
get: function() {
|
|
1254
|
+
return getOperationParameters;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
Object.defineProperty(exports, "mutationKeyTransformer", {
|
|
1258
|
+
enumerable: true,
|
|
1259
|
+
get: function() {
|
|
1260
|
+
return mutationKeyTransformer;
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
Object.defineProperty(exports, "queryKeyTransformer", {
|
|
1264
|
+
enumerable: true,
|
|
1265
|
+
get: function() {
|
|
1266
|
+
return queryKeyTransformer;
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
Object.defineProperty(exports, "resolveOperationTypeNames", {
|
|
1270
|
+
enumerable: true,
|
|
1271
|
+
get: function() {
|
|
1272
|
+
return resolveOperationTypeNames;
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
Object.defineProperty(exports, "resolveZodSchemaNames", {
|
|
1361
1276
|
enumerable: true,
|
|
1362
1277
|
get: function() {
|
|
1363
|
-
return
|
|
1278
|
+
return resolveZodSchemaNames;
|
|
1364
1279
|
}
|
|
1365
1280
|
});
|
|
1366
1281
|
|
|
1367
|
-
//# sourceMappingURL=components-
|
|
1282
|
+
//# sourceMappingURL=components-CIedagno.cjs.map
|