@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
|
@@ -228,16 +228,16 @@ var URLPath = class {
|
|
|
228
228
|
get object() {
|
|
229
229
|
return this.toObject();
|
|
230
230
|
}
|
|
231
|
-
/** Returns a map of path parameter names, or `
|
|
231
|
+
/** Returns a map of path parameter names, or `null` when the path has no parameters.
|
|
232
232
|
*
|
|
233
233
|
* @example
|
|
234
234
|
* ```ts
|
|
235
235
|
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
236
|
-
* new URLPath('/pet').params //
|
|
236
|
+
* new URLPath('/pet').params // null
|
|
237
237
|
* ```
|
|
238
238
|
*/
|
|
239
239
|
get params() {
|
|
240
|
-
return this.
|
|
240
|
+
return this.toParamsObject();
|
|
241
241
|
}
|
|
242
242
|
#transformParam(raw) {
|
|
243
243
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -255,7 +255,7 @@ var URLPath = class {
|
|
|
255
255
|
toObject({ type = "path", replacer, stringify } = {}) {
|
|
256
256
|
const object = {
|
|
257
257
|
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
258
|
-
params: this.
|
|
258
|
+
params: this.toParamsObject()
|
|
259
259
|
};
|
|
260
260
|
if (stringify) {
|
|
261
261
|
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
@@ -271,12 +271,13 @@ var URLPath = class {
|
|
|
271
271
|
* @example
|
|
272
272
|
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
273
273
|
*/
|
|
274
|
-
toTemplateString({ prefix
|
|
275
|
-
|
|
274
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
275
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
276
276
|
if (i % 2 === 0) return part;
|
|
277
277
|
const param = this.#transformParam(part);
|
|
278
278
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
279
|
-
}).join("")
|
|
279
|
+
}).join("");
|
|
280
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
280
281
|
}
|
|
281
282
|
/**
|
|
282
283
|
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
@@ -285,17 +286,17 @@ var URLPath = class {
|
|
|
285
286
|
*
|
|
286
287
|
* @example
|
|
287
288
|
* ```ts
|
|
288
|
-
* new URLPath('/pet/{petId}/tag/{tagId}').
|
|
289
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
289
290
|
* // { petId: 'petId', tagId: 'tagId' }
|
|
290
291
|
* ```
|
|
291
292
|
*/
|
|
292
|
-
|
|
293
|
+
toParamsObject(replacer) {
|
|
293
294
|
const params = {};
|
|
294
295
|
this.#eachParam((_raw, param) => {
|
|
295
296
|
const key = replacer ? replacer(param) : param;
|
|
296
297
|
params[key] = key;
|
|
297
298
|
});
|
|
298
|
-
return Object.keys(params).length > 0 ? params :
|
|
299
|
+
return Object.keys(params).length > 0 ? params : null;
|
|
299
300
|
}
|
|
300
301
|
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
301
302
|
*
|
|
@@ -310,18 +311,14 @@ var URLPath = class {
|
|
|
310
311
|
};
|
|
311
312
|
//#endregion
|
|
312
313
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
313
|
-
const declarationPrinter$
|
|
314
|
-
|
|
315
|
-
return ast.createFunctionParameters({ params: [] });
|
|
316
|
-
}
|
|
317
|
-
__name(getParams$4, "getParams");
|
|
318
|
-
const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
|
|
314
|
+
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
315
|
+
const mutationKeyTransformer = ({ node, casing }) => {
|
|
319
316
|
return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
|
|
320
|
-
}
|
|
321
|
-
function MutationKey({ name, paramsCasing, node, transformer
|
|
322
|
-
const paramsNode =
|
|
323
|
-
const paramsSignature = declarationPrinter$
|
|
324
|
-
const keys = transformer({
|
|
317
|
+
};
|
|
318
|
+
function MutationKey({ name, paramsCasing, node, transformer }) {
|
|
319
|
+
const paramsNode = ast.createFunctionParameters({ params: [] });
|
|
320
|
+
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
321
|
+
const keys = (transformer ?? mutationKeyTransformer)({
|
|
325
322
|
node,
|
|
326
323
|
casing: paramsCasing
|
|
327
324
|
});
|
|
@@ -338,28 +335,119 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
|
|
|
338
335
|
})
|
|
339
336
|
});
|
|
340
337
|
}
|
|
341
|
-
MutationKey.getParams = getParams$4;
|
|
342
|
-
MutationKey.getTransformer = getTransformer$1;
|
|
343
338
|
//#endregion
|
|
344
|
-
//#region ../../internals/
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return
|
|
339
|
+
//#region ../../internals/shared/src/operation.ts
|
|
340
|
+
function getOperationLink(node, link) {
|
|
341
|
+
if (!link) return null;
|
|
342
|
+
if (typeof link === "function") return link(node) ?? null;
|
|
343
|
+
if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
|
|
344
|
+
return `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`;
|
|
345
|
+
}
|
|
346
|
+
function getContentTypeInfo(node) {
|
|
347
|
+
const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
|
|
348
|
+
const isMultipleContentTypes = contentTypes.length > 1;
|
|
349
|
+
return {
|
|
350
|
+
contentTypes,
|
|
351
|
+
isMultipleContentTypes,
|
|
352
|
+
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
353
|
+
defaultContentType: contentTypes[0] ?? "application/json",
|
|
354
|
+
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function buildRequestConfigType(node, resolver) {
|
|
358
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
359
|
+
const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
|
|
360
|
+
return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
|
|
361
|
+
}
|
|
362
|
+
function buildOperationComments(node, options = {}) {
|
|
363
|
+
const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
|
|
364
|
+
const linkComment = getOperationLink(node, link);
|
|
365
|
+
const filteredComments = (linkPosition === "beforeDeprecated" ? [
|
|
366
|
+
node.description && `@description ${node.description}`,
|
|
367
|
+
node.summary && `@summary ${node.summary}`,
|
|
368
|
+
linkComment,
|
|
369
|
+
node.deprecated && "@deprecated"
|
|
370
|
+
] : [
|
|
350
371
|
node.description && `@description ${node.description}`,
|
|
351
372
|
node.summary && `@summary ${node.summary}`,
|
|
352
373
|
node.deprecated && "@deprecated",
|
|
353
|
-
|
|
354
|
-
].filter((
|
|
374
|
+
linkComment
|
|
375
|
+
]).filter((comment) => Boolean(comment));
|
|
376
|
+
if (!splitLines) return filteredComments;
|
|
377
|
+
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
378
|
+
}
|
|
379
|
+
function getOperationParameters(node, options = {}) {
|
|
380
|
+
const params = ast.caseParams(node.parameters, options.paramsCasing);
|
|
381
|
+
return {
|
|
382
|
+
path: params.filter((param) => param.in === "path"),
|
|
383
|
+
query: params.filter((param) => param.in === "query"),
|
|
384
|
+
header: params.filter((param) => param.in === "header"),
|
|
385
|
+
cookie: params.filter((param) => param.in === "cookie")
|
|
386
|
+
};
|
|
355
387
|
}
|
|
388
|
+
function getStatusCodeNumber(statusCode) {
|
|
389
|
+
const code = Number(statusCode);
|
|
390
|
+
return Number.isNaN(code) ? null : code;
|
|
391
|
+
}
|
|
392
|
+
function isSuccessStatusCode(statusCode) {
|
|
393
|
+
const code = getStatusCodeNumber(statusCode);
|
|
394
|
+
return code !== null && code >= 200 && code < 300;
|
|
395
|
+
}
|
|
396
|
+
function isErrorStatusCode(statusCode) {
|
|
397
|
+
const code = getStatusCodeNumber(statusCode);
|
|
398
|
+
return code !== null && code >= 400;
|
|
399
|
+
}
|
|
400
|
+
function resolveErrorNames(node, resolver) {
|
|
401
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
402
|
+
}
|
|
403
|
+
function resolveSuccessNames(node, resolver) {
|
|
404
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
405
|
+
}
|
|
406
|
+
function resolveStatusCodeNames(node, resolver) {
|
|
407
|
+
return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
|
|
408
|
+
}
|
|
409
|
+
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
410
|
+
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
411
|
+
const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
|
|
412
|
+
let byResolver = typeNamesByResolver.get(resolver);
|
|
413
|
+
if (byResolver) {
|
|
414
|
+
const cached = byResolver.get(cacheKey);
|
|
415
|
+
if (cached) return cached;
|
|
416
|
+
} else {
|
|
417
|
+
byResolver = /* @__PURE__ */ new Map();
|
|
418
|
+
typeNamesByResolver.set(resolver, byResolver);
|
|
419
|
+
}
|
|
420
|
+
const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
|
|
421
|
+
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
422
|
+
const exclude = new Set(options.exclude ?? []);
|
|
423
|
+
const paramNames = [
|
|
424
|
+
...path.map((param) => resolver.resolvePathParamsName(node, param)),
|
|
425
|
+
...query.map((param) => resolver.resolveQueryParamsName(node, param)),
|
|
426
|
+
...header.map((param) => resolver.resolveHeaderParamsName(node, param))
|
|
427
|
+
];
|
|
428
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
|
|
429
|
+
const result = (options.order === "body-response-first" ? [
|
|
430
|
+
...bodyAndResponseNames,
|
|
431
|
+
...paramNames,
|
|
432
|
+
...responseStatusNames
|
|
433
|
+
] : [
|
|
434
|
+
...paramNames,
|
|
435
|
+
...bodyAndResponseNames,
|
|
436
|
+
...responseStatusNames
|
|
437
|
+
]).filter((name) => Boolean(name) && !exclude.has(name));
|
|
438
|
+
byResolver.set(cacheKey, result);
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region ../../internals/tanstack-query/src/utils.ts
|
|
356
443
|
/**
|
|
357
|
-
*
|
|
444
|
+
* Collects the Zod schema import names for an operation (response + request body).
|
|
445
|
+
*
|
|
446
|
+
* Returns an empty array when no resolver is provided or the operation has no request body schema.
|
|
358
447
|
*/
|
|
359
|
-
function
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
|
|
448
|
+
function resolveZodSchemaNames(node, zodResolver) {
|
|
449
|
+
if (!zodResolver) return [];
|
|
450
|
+
return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
|
|
363
451
|
}
|
|
364
452
|
/**
|
|
365
453
|
* Resolve the type for a single path parameter.
|
|
@@ -383,30 +471,14 @@ function resolvePathParamType(node, param, resolver) {
|
|
|
383
471
|
}
|
|
384
472
|
/**
|
|
385
473
|
* Derive a query-params group type from the resolver.
|
|
386
|
-
* Returns `
|
|
474
|
+
* Returns `null` when no query params exist or when the group name
|
|
387
475
|
* equals the individual param name (no real group).
|
|
388
476
|
*/
|
|
389
477
|
function resolveQueryGroupType(node, params, resolver) {
|
|
390
|
-
if (!params.length) return
|
|
478
|
+
if (!params.length) return null;
|
|
391
479
|
const firstParam = params[0];
|
|
392
480
|
const groupName = resolver.resolveQueryParamsName(node, firstParam);
|
|
393
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return
|
|
394
|
-
return {
|
|
395
|
-
type: ast.createParamsType({
|
|
396
|
-
variant: "reference",
|
|
397
|
-
name: groupName
|
|
398
|
-
}),
|
|
399
|
-
optional: params.every((p) => !p.required)
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Derive a header-params group type from the resolver.
|
|
404
|
-
*/
|
|
405
|
-
function resolveHeaderGroupType(node, params, resolver) {
|
|
406
|
-
if (!params.length) return void 0;
|
|
407
|
-
const firstParam = params[0];
|
|
408
|
-
const groupName = resolver.resolveHeaderParamsName(node, firstParam);
|
|
409
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
|
|
481
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
410
482
|
return {
|
|
411
483
|
type: ast.createParamsType({
|
|
412
484
|
variant: "reference",
|
|
@@ -456,7 +528,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
456
528
|
const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
|
|
457
529
|
variant: "reference",
|
|
458
530
|
name: resolver.resolveDataName(node)
|
|
459
|
-
}) :
|
|
531
|
+
}) : null;
|
|
460
532
|
const bodyRequired = node.requestBody?.required ?? false;
|
|
461
533
|
const params = [];
|
|
462
534
|
if (pathParams.length) {
|
|
@@ -480,48 +552,45 @@ function buildQueryKeyParams(node, options) {
|
|
|
480
552
|
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
481
553
|
return ast.createFunctionParameters({ params });
|
|
482
554
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
|
|
494
|
-
const headerGroupType = resolveHeaderGroupType(node, headerParams, resolver);
|
|
495
|
-
const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
|
|
496
|
-
variant: "reference",
|
|
497
|
-
name: resolver.resolveDataName(node)
|
|
498
|
-
}) : void 0;
|
|
499
|
-
const bodyRequired = node.requestBody?.required ?? false;
|
|
500
|
-
const params = [];
|
|
501
|
-
for (const p of pathParams) params.push(ast.createFunctionParameter({
|
|
502
|
-
name: p.name,
|
|
503
|
-
type: resolvePathParamType(node, p, resolver),
|
|
504
|
-
optional: !p.required
|
|
505
|
-
}));
|
|
506
|
-
if (bodyType) params.push(ast.createFunctionParameter({
|
|
507
|
-
name: "data",
|
|
508
|
-
type: bodyType,
|
|
509
|
-
optional: !bodyRequired
|
|
510
|
-
}));
|
|
511
|
-
params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
|
|
512
|
-
params.push(...buildGroupParam("headers", node, headerParams, headerGroupType, resolver));
|
|
513
|
-
return ast.createFunctionParameters({ params });
|
|
555
|
+
function buildEnabledCheck(paramsNode) {
|
|
556
|
+
const required = [];
|
|
557
|
+
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
558
|
+
const group = param;
|
|
559
|
+
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
560
|
+
} else {
|
|
561
|
+
const fp = param;
|
|
562
|
+
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
563
|
+
}
|
|
564
|
+
return required.join(" && ");
|
|
514
565
|
}
|
|
566
|
+
functionPrinter({ mode: "declaration" });
|
|
567
|
+
const queryKeyTransformer = ({ node, casing }) => {
|
|
568
|
+
const path = new URLPath(node.path, { casing });
|
|
569
|
+
const hasQueryParams = getOperationParameters(node).query.length > 0;
|
|
570
|
+
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
571
|
+
return [
|
|
572
|
+
path.toObject({
|
|
573
|
+
type: "path",
|
|
574
|
+
stringify: true
|
|
575
|
+
}),
|
|
576
|
+
hasQueryParams ? "...(params ? [params] : [])" : null,
|
|
577
|
+
hasRequestBody ? "...(data ? [data] : [])" : null
|
|
578
|
+
].filter(Boolean);
|
|
579
|
+
};
|
|
515
580
|
//#endregion
|
|
516
581
|
//#region src/utils.ts
|
|
517
|
-
function
|
|
518
|
-
|
|
582
|
+
function printType(typeNode) {
|
|
583
|
+
if (!typeNode) return "unknown";
|
|
584
|
+
if (typeNode.variant === "reference") return typeNode.name;
|
|
585
|
+
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
586
|
+
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
587
|
+
const typeStr = printType(p.type);
|
|
588
|
+
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
589
|
+
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
590
|
+
}).join("; ")} }`;
|
|
591
|
+
return "unknown";
|
|
519
592
|
}
|
|
520
|
-
|
|
521
|
-
//#region src/components/QueryKey.tsx
|
|
522
|
-
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
523
|
-
const callPrinter$5 = functionPrinter({ mode: "call" });
|
|
524
|
-
function wrapWithMaybeRefOrGetter(paramsNode) {
|
|
593
|
+
function wrapWithMaybeRefOrGetter(paramsNode, skip) {
|
|
525
594
|
const wrappedParams = paramsNode.params.map((param) => {
|
|
526
595
|
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
527
596
|
const group = param;
|
|
@@ -531,59 +600,37 @@ function wrapWithMaybeRefOrGetter(paramsNode) {
|
|
|
531
600
|
...p,
|
|
532
601
|
type: p.type ? ast.createParamsType({
|
|
533
602
|
variant: "reference",
|
|
534
|
-
name: `MaybeRefOrGetter<${printType
|
|
603
|
+
name: `MaybeRefOrGetter<${printType(p.type)}>`
|
|
535
604
|
}) : p.type
|
|
536
605
|
}))
|
|
537
606
|
};
|
|
538
607
|
}
|
|
539
608
|
const fp = param;
|
|
609
|
+
if (skip?.(fp.name)) return fp;
|
|
540
610
|
return {
|
|
541
611
|
...fp,
|
|
542
612
|
type: fp.type ? ast.createParamsType({
|
|
543
613
|
variant: "reference",
|
|
544
|
-
name: `MaybeRefOrGetter<${printType
|
|
614
|
+
name: `MaybeRefOrGetter<${printType(fp.type)}>`
|
|
545
615
|
}) : fp.type
|
|
546
616
|
};
|
|
547
617
|
});
|
|
548
618
|
return ast.createFunctionParameters({ params: wrappedParams });
|
|
549
619
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
555
|
-
const typeStr = printType$4(p.type);
|
|
556
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
557
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
558
|
-
}).join("; ")} }`;
|
|
559
|
-
return "unknown";
|
|
560
|
-
}
|
|
561
|
-
__name(printType$4, "printType");
|
|
562
|
-
function getParams$3(node, options) {
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/components/QueryKey.tsx
|
|
622
|
+
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
623
|
+
function buildQueryKeyParamsNode(node, options) {
|
|
563
624
|
return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
|
|
564
625
|
}
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
const path = new URLPath(node.path, { casing });
|
|
568
|
-
const hasQueryParams = node.parameters.some((p) => p.in === "query");
|
|
569
|
-
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
|
|
570
|
-
return [
|
|
571
|
-
path.toObject({
|
|
572
|
-
type: "path",
|
|
573
|
-
stringify: true
|
|
574
|
-
}),
|
|
575
|
-
hasQueryParams ? "...(params ? [params] : [])" : void 0,
|
|
576
|
-
hasRequestBody ? "...(data ? [data] : [])" : void 0
|
|
577
|
-
].filter(Boolean);
|
|
578
|
-
};
|
|
579
|
-
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = getTransformer }) {
|
|
580
|
-
const paramsNode = getParams$3(node, {
|
|
626
|
+
function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
|
|
627
|
+
const paramsNode = buildQueryKeyParamsNode(node, {
|
|
581
628
|
pathParamsType,
|
|
582
629
|
paramsCasing,
|
|
583
630
|
resolver: tsResolver
|
|
584
631
|
});
|
|
585
632
|
const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
|
|
586
|
-
const keys = transformer({
|
|
633
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
587
634
|
node,
|
|
588
635
|
casing: paramsCasing
|
|
589
636
|
});
|
|
@@ -610,17 +657,14 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
|
|
|
610
657
|
})
|
|
611
658
|
})] });
|
|
612
659
|
}
|
|
613
|
-
QueryKey.getParams = getParams$3;
|
|
614
|
-
QueryKey.getTransformer = getTransformer;
|
|
615
|
-
QueryKey.callPrinter = callPrinter$5;
|
|
616
660
|
//#endregion
|
|
617
661
|
//#region src/components/QueryOptions.tsx
|
|
618
662
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
619
663
|
const callPrinter$4 = functionPrinter({ mode: "call" });
|
|
620
664
|
function getQueryOptionsParams(node, options) {
|
|
621
665
|
const { paramsType, paramsCasing, pathParamsType, resolver } = options;
|
|
622
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) :
|
|
623
|
-
return
|
|
666
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
667
|
+
return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
|
|
624
668
|
paramsType,
|
|
625
669
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
626
670
|
paramsCasing,
|
|
@@ -633,61 +677,11 @@ function getQueryOptionsParams(node, options) {
|
|
|
633
677
|
}),
|
|
634
678
|
default: "{}"
|
|
635
679
|
})]
|
|
636
|
-
}));
|
|
637
|
-
}
|
|
638
|
-
function wrapOperationParamsWithMaybeRef$2(paramsNode) {
|
|
639
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
640
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
641
|
-
const group = param;
|
|
642
|
-
return {
|
|
643
|
-
...group,
|
|
644
|
-
properties: group.properties.map((p) => ({
|
|
645
|
-
...p,
|
|
646
|
-
type: p.type ? ast.createParamsType({
|
|
647
|
-
variant: "reference",
|
|
648
|
-
name: `MaybeRefOrGetter<${printType$3(p.type)}>`
|
|
649
|
-
}) : p.type
|
|
650
|
-
}))
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
const fp = param;
|
|
654
|
-
if (fp.name === "config") return fp;
|
|
655
|
-
return {
|
|
656
|
-
...fp,
|
|
657
|
-
type: fp.type ? ast.createParamsType({
|
|
658
|
-
variant: "reference",
|
|
659
|
-
name: `MaybeRefOrGetter<${printType$3(fp.type)}>`
|
|
660
|
-
}) : fp.type
|
|
661
|
-
};
|
|
662
|
-
});
|
|
663
|
-
return ast.createFunctionParameters({ params: wrappedParams });
|
|
664
|
-
}
|
|
665
|
-
__name(wrapOperationParamsWithMaybeRef$2, "wrapOperationParamsWithMaybeRef");
|
|
666
|
-
function printType$3(typeNode) {
|
|
667
|
-
if (!typeNode) return "unknown";
|
|
668
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
669
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
670
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
671
|
-
const typeStr = printType$3(p.type);
|
|
672
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
673
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
674
|
-
}).join("; ")} }`;
|
|
675
|
-
return "unknown";
|
|
676
|
-
}
|
|
677
|
-
__name(printType$3, "printType");
|
|
678
|
-
function buildEnabledCheck(paramsNode) {
|
|
679
|
-
const required = [];
|
|
680
|
-
for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
|
|
681
|
-
const group = param;
|
|
682
|
-
for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
|
|
683
|
-
} else {
|
|
684
|
-
const fp = param;
|
|
685
|
-
if (!fp.optional && fp.default === void 0) required.push(fp.name);
|
|
686
|
-
}
|
|
687
|
-
return required.join(" && ");
|
|
680
|
+
}), (name) => name === "config");
|
|
688
681
|
}
|
|
689
682
|
function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
|
|
690
|
-
const
|
|
683
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
684
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
691
685
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
692
686
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
693
687
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -699,14 +693,14 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
|
|
|
699
693
|
});
|
|
700
694
|
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
701
695
|
const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
702
|
-
const queryKeyParamsNode =
|
|
696
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
703
697
|
pathParamsType,
|
|
704
698
|
paramsCasing,
|
|
705
699
|
resolver: tsResolver
|
|
706
700
|
});
|
|
707
701
|
const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
|
|
708
702
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
709
|
-
const enabledText = enabledSource ? `enabled: () =>
|
|
703
|
+
const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
|
|
710
704
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
711
705
|
name,
|
|
712
706
|
isExportable: true,
|
|
@@ -748,15 +742,15 @@ function addToValueCalls$1(callStr) {
|
|
|
748
742
|
return result;
|
|
749
743
|
}
|
|
750
744
|
__name(addToValueCalls$1, "addToValueCalls");
|
|
751
|
-
QueryOptions.getParams = getQueryOptionsParams;
|
|
752
745
|
//#endregion
|
|
753
746
|
//#region src/components/InfiniteQuery.tsx
|
|
754
747
|
const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
755
748
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
756
|
-
function
|
|
749
|
+
function buildInfiniteQueryParamsNode(node, options) {
|
|
757
750
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
758
|
-
const
|
|
759
|
-
const
|
|
751
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
752
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
753
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
760
754
|
const errorNames = resolveErrorNames(node, resolver);
|
|
761
755
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
762
756
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -777,57 +771,17 @@ function getParams$2(node, options) {
|
|
|
777
771
|
}),
|
|
778
772
|
default: "{}"
|
|
779
773
|
});
|
|
780
|
-
return
|
|
774
|
+
return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
|
|
781
775
|
paramsType,
|
|
782
776
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
783
777
|
paramsCasing,
|
|
784
778
|
resolver,
|
|
785
779
|
extraParams: [optionsParam]
|
|
786
|
-
}));
|
|
787
|
-
}
|
|
788
|
-
__name(getParams$2, "getParams");
|
|
789
|
-
function wrapOperationParamsWithMaybeRef$1(paramsNode) {
|
|
790
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
791
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
792
|
-
const group = param;
|
|
793
|
-
return {
|
|
794
|
-
...group,
|
|
795
|
-
properties: group.properties.map((p) => ({
|
|
796
|
-
...p,
|
|
797
|
-
type: p.type ? ast.createParamsType({
|
|
798
|
-
variant: "reference",
|
|
799
|
-
name: `MaybeRefOrGetter<${printType$2(p.type)}>`
|
|
800
|
-
}) : p.type
|
|
801
|
-
}))
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
const fp = param;
|
|
805
|
-
if (fp.name === "options") return fp;
|
|
806
|
-
return {
|
|
807
|
-
...fp,
|
|
808
|
-
type: fp.type ? ast.createParamsType({
|
|
809
|
-
variant: "reference",
|
|
810
|
-
name: `MaybeRefOrGetter<${printType$2(fp.type)}>`
|
|
811
|
-
}) : fp.type
|
|
812
|
-
};
|
|
813
|
-
});
|
|
814
|
-
return ast.createFunctionParameters({ params: wrappedParams });
|
|
815
|
-
}
|
|
816
|
-
__name(wrapOperationParamsWithMaybeRef$1, "wrapOperationParamsWithMaybeRef");
|
|
817
|
-
function printType$2(typeNode) {
|
|
818
|
-
if (!typeNode) return "unknown";
|
|
819
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
820
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
821
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
822
|
-
const typeStr = printType$2(p.type);
|
|
823
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
824
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
825
|
-
}).join("; ")} }`;
|
|
826
|
-
return "unknown";
|
|
780
|
+
}), (name) => name === "options");
|
|
827
781
|
}
|
|
828
|
-
__name(printType$2, "printType");
|
|
829
782
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
830
|
-
const
|
|
783
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
784
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
831
785
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
832
786
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
833
787
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -837,7 +791,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
837
791
|
`TQueryData = ${TData}`,
|
|
838
792
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
839
793
|
];
|
|
840
|
-
const queryKeyParamsNode =
|
|
794
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
841
795
|
pathParamsType,
|
|
842
796
|
paramsCasing,
|
|
843
797
|
resolver: tsResolver
|
|
@@ -850,7 +804,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
850
804
|
resolver: tsResolver
|
|
851
805
|
});
|
|
852
806
|
const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
|
|
853
|
-
const paramsNode =
|
|
807
|
+
const paramsNode = buildInfiniteQueryParamsNode(node, {
|
|
854
808
|
paramsType,
|
|
855
809
|
paramsCasing,
|
|
856
810
|
pathParamsType,
|
|
@@ -867,7 +821,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
867
821
|
export: true,
|
|
868
822
|
generics: generics.join(", "),
|
|
869
823
|
params: paramsSignature,
|
|
870
|
-
JSDoc: { comments:
|
|
824
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
871
825
|
children: `
|
|
872
826
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
873
827
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -886,13 +840,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
886
840
|
})
|
|
887
841
|
});
|
|
888
842
|
}
|
|
889
|
-
InfiniteQuery.getParams = getParams$2;
|
|
890
843
|
//#endregion
|
|
891
844
|
//#region src/components/InfiniteQueryOptions.tsx
|
|
892
845
|
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
893
846
|
const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
894
847
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
|
|
895
|
-
const
|
|
848
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
849
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
896
850
|
const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
897
851
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
898
852
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -901,12 +855,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
901
855
|
const parts = initialPageParam.split(" as ");
|
|
902
856
|
return parts[parts.length - 1] ?? "unknown";
|
|
903
857
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
904
|
-
const rawQueryParams = node
|
|
858
|
+
const rawQueryParams = getOperationParameters(node).query;
|
|
905
859
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
906
860
|
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
|
|
907
|
-
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName :
|
|
908
|
-
})() :
|
|
909
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` :
|
|
861
|
+
return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
|
|
862
|
+
})() : null;
|
|
863
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
910
864
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
911
865
|
const paramsNode = getQueryOptionsParams(node, {
|
|
912
866
|
paramsType,
|
|
@@ -916,34 +870,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
916
870
|
});
|
|
917
871
|
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
918
872
|
const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
|
|
919
|
-
const queryKeyParamsNode =
|
|
873
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
920
874
|
pathParamsType,
|
|
921
875
|
paramsCasing,
|
|
922
876
|
resolver: tsResolver
|
|
923
877
|
});
|
|
924
878
|
const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
|
|
925
879
|
const enabledSource = buildEnabledCheck(queryKeyParamsNode);
|
|
926
|
-
const enabledText = enabledSource ? `enabled: () =>
|
|
927
|
-
const hasNewParams = nextParam
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
|
|
934
|
-
}
|
|
935
|
-
if (previousParam) {
|
|
936
|
-
const accessor = getNestedAccessor(previousParam, "firstPage");
|
|
937
|
-
if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
|
|
880
|
+
const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
|
|
881
|
+
const hasNewParams = nextParam != null || previousParam != null;
|
|
882
|
+
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
883
|
+
if (hasNewParams) {
|
|
884
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
885
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
886
|
+
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
938
887
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
} else {
|
|
943
|
-
if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
|
|
944
|
-
else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
|
|
945
|
-
getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
|
|
946
|
-
}
|
|
888
|
+
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
889
|
+
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"];
|
|
890
|
+
})();
|
|
947
891
|
const queryOptionsArr = [
|
|
948
892
|
`initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
949
893
|
getNextPageParamExpr,
|
|
@@ -1010,33 +954,30 @@ function addToValueCalls(callStr) {
|
|
|
1010
954
|
});
|
|
1011
955
|
return result;
|
|
1012
956
|
}
|
|
1013
|
-
InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
|
|
1014
957
|
//#endregion
|
|
1015
958
|
//#region src/components/Mutation.tsx
|
|
1016
959
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1017
960
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1018
961
|
const keysPrinter = functionPrinter({ mode: "keys" });
|
|
1019
|
-
function
|
|
962
|
+
function createMutationArgParams(node, options) {
|
|
963
|
+
return ast.createOperationParams(node, {
|
|
964
|
+
paramsType: "inline",
|
|
965
|
+
pathParamsType: "inline",
|
|
966
|
+
paramsCasing: options.paramsCasing,
|
|
967
|
+
resolver: options.resolver
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
function buildMutationParamsNode(node, options) {
|
|
1020
971
|
const { paramsCasing, dataReturnType, resolver } = options;
|
|
1021
|
-
const
|
|
1022
|
-
const
|
|
972
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
973
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1023
974
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1024
975
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1025
976
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1026
|
-
const
|
|
977
|
+
const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
|
|
1027
978
|
paramsCasing,
|
|
1028
979
|
resolver
|
|
1029
|
-
})
|
|
1030
|
-
const fp = param;
|
|
1031
|
-
return {
|
|
1032
|
-
...fp,
|
|
1033
|
-
type: fp.type ? ast.createParamsType({
|
|
1034
|
-
variant: "reference",
|
|
1035
|
-
name: `MaybeRefOrGetter<${printType$1(fp.type)}>`
|
|
1036
|
-
}) : fp.type
|
|
1037
|
-
};
|
|
1038
|
-
});
|
|
1039
|
-
const wrappedParamsNode = ast.createFunctionParameters({ params: mutationArgWrapped });
|
|
980
|
+
}));
|
|
1040
981
|
const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
|
|
1041
982
|
return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
1042
983
|
name: "options",
|
|
@@ -1046,34 +987,22 @@ function getParams$1(node, options) {
|
|
|
1046
987
|
mutation?: MutationObserverOptions<${[
|
|
1047
988
|
TData,
|
|
1048
989
|
TError,
|
|
1049
|
-
TRequestWrapped ? `{${TRequestWrapped}}` : "
|
|
990
|
+
TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
|
|
1050
991
|
"TContext"
|
|
1051
992
|
].join(", ")}> & { client?: QueryClient },
|
|
1052
|
-
client?: ${
|
|
993
|
+
client?: ${buildRequestConfigType(node, resolver)},
|
|
1053
994
|
}`
|
|
1054
995
|
}),
|
|
1055
996
|
default: "{}"
|
|
1056
997
|
})] });
|
|
1057
998
|
}
|
|
1058
|
-
__name(getParams$1, "getParams");
|
|
1059
|
-
function printType$1(typeNode) {
|
|
1060
|
-
if (!typeNode) return "unknown";
|
|
1061
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
1062
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
1063
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
1064
|
-
const typeStr = printType$1(p.type);
|
|
1065
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
1066
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
1067
|
-
}).join("; ")} }`;
|
|
1068
|
-
return "unknown";
|
|
1069
|
-
}
|
|
1070
|
-
__name(printType$1, "printType");
|
|
1071
999
|
function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
|
|
1072
|
-
const
|
|
1000
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1001
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1073
1002
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1074
1003
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1075
1004
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1076
|
-
const mutationArgParamsNode =
|
|
1005
|
+
const mutationArgParamsNode = createMutationArgParams(node, {
|
|
1077
1006
|
paramsCasing,
|
|
1078
1007
|
resolver: tsResolver
|
|
1079
1008
|
});
|
|
@@ -1083,10 +1012,10 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1083
1012
|
const generics = [
|
|
1084
1013
|
TData,
|
|
1085
1014
|
TError,
|
|
1086
|
-
TRequest ? `{${TRequest}}` : "
|
|
1015
|
+
TRequest ? `{${TRequest}}` : "undefined",
|
|
1087
1016
|
"TContext"
|
|
1088
1017
|
].join(", ");
|
|
1089
|
-
const mutationKeyParamsNode =
|
|
1018
|
+
const mutationKeyParamsNode = ast.createFunctionParameters({ params: [] });
|
|
1090
1019
|
const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
|
|
1091
1020
|
const clientCallParamsNode = ast.createOperationParams(node, {
|
|
1092
1021
|
paramsType,
|
|
@@ -1097,13 +1026,13 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1097
1026
|
name: "config",
|
|
1098
1027
|
type: ast.createParamsType({
|
|
1099
1028
|
variant: "reference",
|
|
1100
|
-
name: node
|
|
1029
|
+
name: buildRequestConfigType(node, tsResolver)
|
|
1101
1030
|
}),
|
|
1102
1031
|
default: "{}"
|
|
1103
1032
|
})]
|
|
1104
1033
|
});
|
|
1105
1034
|
const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
|
|
1106
|
-
const paramsNode =
|
|
1035
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1107
1036
|
paramsCasing,
|
|
1108
1037
|
dataReturnType,
|
|
1109
1038
|
resolver: tsResolver
|
|
@@ -1117,7 +1046,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1117
1046
|
name,
|
|
1118
1047
|
export: true,
|
|
1119
1048
|
params: paramsSignature,
|
|
1120
|
-
JSDoc: { comments:
|
|
1049
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1121
1050
|
generics: ["TContext"],
|
|
1122
1051
|
children: `
|
|
1123
1052
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
@@ -1135,15 +1064,15 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
|
|
|
1135
1064
|
})
|
|
1136
1065
|
});
|
|
1137
1066
|
}
|
|
1138
|
-
Mutation.getParams = getParams$1;
|
|
1139
1067
|
//#endregion
|
|
1140
1068
|
//#region src/components/Query.tsx
|
|
1141
1069
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1142
1070
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1143
|
-
function
|
|
1071
|
+
function buildQueryParamsNode(node, options) {
|
|
1144
1072
|
const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
|
|
1145
|
-
const
|
|
1146
|
-
const
|
|
1073
|
+
const successNames = resolveSuccessNames(node, resolver);
|
|
1074
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
|
|
1075
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
|
|
1147
1076
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1148
1077
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1149
1078
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1164,54 +1093,17 @@ function getParams(node, options) {
|
|
|
1164
1093
|
}),
|
|
1165
1094
|
default: "{}"
|
|
1166
1095
|
});
|
|
1167
|
-
return
|
|
1096
|
+
return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
|
|
1168
1097
|
paramsType,
|
|
1169
1098
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
|
|
1170
1099
|
paramsCasing,
|
|
1171
1100
|
resolver,
|
|
1172
1101
|
extraParams: [optionsParam]
|
|
1173
|
-
}));
|
|
1174
|
-
}
|
|
1175
|
-
function wrapOperationParamsWithMaybeRef(paramsNode) {
|
|
1176
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
1177
|
-
if ("kind" in param && param.kind === "ParameterGroup") {
|
|
1178
|
-
const group = param;
|
|
1179
|
-
return {
|
|
1180
|
-
...group,
|
|
1181
|
-
properties: group.properties.map((p) => ({
|
|
1182
|
-
...p,
|
|
1183
|
-
type: p.type ? ast.createParamsType({
|
|
1184
|
-
variant: "reference",
|
|
1185
|
-
name: `MaybeRefOrGetter<${printType(p.type)}>`
|
|
1186
|
-
}) : p.type
|
|
1187
|
-
}))
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
|
-
const fp = param;
|
|
1191
|
-
if (fp.name === "options") return fp;
|
|
1192
|
-
return {
|
|
1193
|
-
...fp,
|
|
1194
|
-
type: fp.type ? ast.createParamsType({
|
|
1195
|
-
variant: "reference",
|
|
1196
|
-
name: `MaybeRefOrGetter<${printType(fp.type)}>`
|
|
1197
|
-
}) : fp.type
|
|
1198
|
-
};
|
|
1199
|
-
});
|
|
1200
|
-
return ast.createFunctionParameters({ params: wrappedParams });
|
|
1201
|
-
}
|
|
1202
|
-
function printType(typeNode) {
|
|
1203
|
-
if (!typeNode) return "unknown";
|
|
1204
|
-
if (typeNode.variant === "reference") return typeNode.name;
|
|
1205
|
-
if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
|
|
1206
|
-
if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
|
|
1207
|
-
const typeStr = printType(p.type);
|
|
1208
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
|
|
1209
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
|
|
1210
|
-
}).join("; ")} }`;
|
|
1211
|
-
return "unknown";
|
|
1102
|
+
}), (name) => name === "options");
|
|
1212
1103
|
}
|
|
1213
1104
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
|
|
1214
|
-
const
|
|
1105
|
+
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1106
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
|
|
1215
1107
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1216
1108
|
const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
|
|
1217
1109
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1221,7 +1113,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1221
1113
|
`TQueryData = ${TData}`,
|
|
1222
1114
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1223
1115
|
];
|
|
1224
|
-
const queryKeyParamsNode =
|
|
1116
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
|
|
1225
1117
|
pathParamsType,
|
|
1226
1118
|
paramsCasing,
|
|
1227
1119
|
resolver: tsResolver
|
|
@@ -1234,7 +1126,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1234
1126
|
resolver: tsResolver
|
|
1235
1127
|
});
|
|
1236
1128
|
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
|
|
1237
|
-
const paramsNode =
|
|
1129
|
+
const paramsNode = buildQueryParamsNode(node, {
|
|
1238
1130
|
paramsType,
|
|
1239
1131
|
paramsCasing,
|
|
1240
1132
|
pathParamsType,
|
|
@@ -1251,7 +1143,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1251
1143
|
export: true,
|
|
1252
1144
|
generics: generics.join(", "),
|
|
1253
1145
|
params: paramsSignature,
|
|
1254
|
-
JSDoc: { comments:
|
|
1146
|
+
JSDoc: { comments: buildOperationComments(node) },
|
|
1255
1147
|
children: `
|
|
1256
1148
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1257
1149
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
@@ -1270,8 +1162,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
|
|
|
1270
1162
|
})
|
|
1271
1163
|
});
|
|
1272
1164
|
}
|
|
1273
|
-
Query.getParams = getParams;
|
|
1274
1165
|
//#endregion
|
|
1275
|
-
export { QueryOptions as a,
|
|
1166
|
+
export { QueryOptions as a, resolveZodSchemaNames as c, MutationKey as d, mutationKeyTransformer as f, InfiniteQuery as i, getOperationParameters as l, Mutation as n, QueryKey as o, camelCase as p, InfiniteQueryOptions as r, queryKeyTransformer as s, Query as t, resolveOperationTypeNames as u };
|
|
1276
1167
|
|
|
1277
|
-
//# sourceMappingURL=components-
|
|
1168
|
+
//# sourceMappingURL=components-B4IlVmNa.js.map
|