@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.3

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.
Files changed (46) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-D1UhYFgY.js +1277 -0
  4. package/dist/components-D1UhYFgY.js.map +1 -0
  5. package/dist/components-qfOFRSoM.cjs +1367 -0
  6. package/dist/components-qfOFRSoM.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +118 -109
  9. package/dist/components.js +1 -1
  10. package/dist/generators-C4gs_P1i.cjs +726 -0
  11. package/dist/generators-C4gs_P1i.cjs.map +1 -0
  12. package/dist/generators-CbnIVBgY.js +709 -0
  13. package/dist/generators-CbnIVBgY.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -501
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +106 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +102 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-nVDTfuS1.d.ts +194 -0
  23. package/package.json +61 -64
  24. package/src/components/InfiniteQuery.tsx +104 -153
  25. package/src/components/InfiniteQueryOptions.tsx +122 -162
  26. package/src/components/Mutation.tsx +110 -136
  27. package/src/components/Query.tsx +102 -151
  28. package/src/components/QueryKey.tsx +68 -58
  29. package/src/components/QueryOptions.tsx +147 -139
  30. package/src/generators/infiniteQueryGenerator.tsx +165 -170
  31. package/src/generators/mutationGenerator.tsx +117 -124
  32. package/src/generators/queryGenerator.tsx +138 -136
  33. package/src/index.ts +1 -1
  34. package/src/plugin.ts +124 -175
  35. package/src/resolvers/resolverVueQuery.ts +19 -0
  36. package/src/types.ts +68 -48
  37. package/src/utils.ts +37 -0
  38. package/dist/components-Yjoe78Y7.cjs +0 -1119
  39. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  40. package/dist/components-_AMBl0g-.js +0 -1029
  41. package/dist/components-_AMBl0g-.js.map +0 -1
  42. package/dist/generators-CR34GjVu.js +0 -661
  43. package/dist/generators-CR34GjVu.js.map +0 -1
  44. package/dist/generators-DH8VkK1q.cjs +0 -678
  45. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  46. package/dist/types-CgDFUvfZ.d.ts +0 -211
@@ -1,1029 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { getDefaultValue, isOptional } from "@kubb/oas";
3
- import { getComments, getPathParams } from "@kubb/plugin-oas/utils";
4
- import { File, Function as Function$1, FunctionParams, Type } from "@kubb/react-fabric";
5
- import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
6
- import { Client } from "@kubb/plugin-client/components";
7
- //#region ../../internals/utils/src/casing.ts
8
- /**
9
- * Shared implementation for camelCase and PascalCase conversion.
10
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
11
- * and capitalizes each word according to `pascal`.
12
- *
13
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
14
- */
15
- function toCamelOrPascal(text, pascal) {
16
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
17
- if (word.length > 1 && word === word.toUpperCase()) return word;
18
- if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
19
- return word.charAt(0).toUpperCase() + word.slice(1);
20
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
21
- }
22
- /**
23
- * Splits `text` on `.` and applies `transformPart` to each segment.
24
- * The last segment receives `isLast = true`, all earlier segments receive `false`.
25
- * Segments are joined with `/` to form a file path.
26
- */
27
- function applyToFileParts(text, transformPart) {
28
- const parts = text.split(".");
29
- return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
30
- }
31
- /**
32
- * Converts `text` to camelCase.
33
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
34
- *
35
- * @example
36
- * camelCase('hello-world') // 'helloWorld'
37
- * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
38
- */
39
- function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
40
- if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
41
- prefix,
42
- suffix
43
- } : {}));
44
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
45
- }
46
- /**
47
- * Converts `text` to PascalCase.
48
- * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
49
- *
50
- * @example
51
- * pascalCase('hello-world') // 'HelloWorld'
52
- * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
53
- */
54
- function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
55
- if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
56
- prefix,
57
- suffix
58
- }) : camelCase(part));
59
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
60
- }
61
- //#endregion
62
- //#region ../../internals/utils/src/object.ts
63
- /**
64
- * Converts a dot-notation path or string array into an optional-chaining accessor expression.
65
- *
66
- * @example
67
- * getNestedAccessor('pagination.next.id', 'lastPage')
68
- * // → "lastPage?.['pagination']?.['next']?.['id']"
69
- */
70
- function getNestedAccessor(param, accessor) {
71
- const parts = Array.isArray(param) ? param : param.split(".");
72
- if (parts.length === 0 || parts.length === 1 && parts[0] === "") return void 0;
73
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
74
- }
75
- //#endregion
76
- //#region ../../internals/utils/src/reserved.ts
77
- /**
78
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
79
- */
80
- function isValidVarName(name) {
81
- try {
82
- new Function(`var ${name}`);
83
- } catch {
84
- return false;
85
- }
86
- return true;
87
- }
88
- //#endregion
89
- //#region ../../internals/utils/src/urlPath.ts
90
- /**
91
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
92
- *
93
- * @example
94
- * const p = new URLPath('/pet/{petId}')
95
- * p.URL // '/pet/:petId'
96
- * p.template // '`/pet/${petId}`'
97
- */
98
- var URLPath = class {
99
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
100
- path;
101
- #options;
102
- constructor(path, options = {}) {
103
- this.path = path;
104
- this.#options = options;
105
- }
106
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
107
- get URL() {
108
- return this.toURLPath();
109
- }
110
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
111
- get isURL() {
112
- try {
113
- return !!new URL(this.path).href;
114
- } catch {
115
- return false;
116
- }
117
- }
118
- /**
119
- * Converts the OpenAPI path to a TypeScript template literal string.
120
- *
121
- * @example
122
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
123
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
124
- */
125
- get template() {
126
- return this.toTemplateString();
127
- }
128
- /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
129
- get object() {
130
- return this.toObject();
131
- }
132
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
133
- get params() {
134
- return this.getParams();
135
- }
136
- #transformParam(raw) {
137
- const param = isValidVarName(raw) ? raw : camelCase(raw);
138
- return this.#options.casing === "camelcase" ? camelCase(param) : param;
139
- }
140
- /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
141
- #eachParam(fn) {
142
- for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
143
- const raw = match[1];
144
- fn(raw, this.#transformParam(raw));
145
- }
146
- }
147
- toObject({ type = "path", replacer, stringify } = {}) {
148
- const object = {
149
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
150
- params: this.getParams()
151
- };
152
- if (stringify) {
153
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
154
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
155
- return `{ url: '${object.url}' }`;
156
- }
157
- return object;
158
- }
159
- /**
160
- * Converts the OpenAPI path to a TypeScript template literal string.
161
- * An optional `replacer` can transform each extracted parameter name before interpolation.
162
- *
163
- * @example
164
- * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
165
- */
166
- toTemplateString({ prefix = "", replacer } = {}) {
167
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
168
- if (i % 2 === 0) return part;
169
- const param = this.#transformParam(part);
170
- return `\${${replacer ? replacer(param) : param}}`;
171
- }).join("")}\``;
172
- }
173
- /**
174
- * Extracts all `{param}` segments from the path and returns them as a key-value map.
175
- * An optional `replacer` transforms each parameter name in both key and value positions.
176
- * Returns `undefined` when no path parameters are found.
177
- */
178
- getParams(replacer) {
179
- const params = {};
180
- this.#eachParam((_raw, param) => {
181
- const key = replacer ? replacer(param) : param;
182
- params[key] = key;
183
- });
184
- return Object.keys(params).length > 0 ? params : void 0;
185
- }
186
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
187
- toURLPath() {
188
- return this.path.replace(/\{([^}]+)\}/g, ":$1");
189
- }
190
- };
191
- //#endregion
192
- //#region src/components/QueryKey.tsx
193
- function getParams$6({ pathParamsType, paramsCasing, typeSchemas }) {
194
- return FunctionParams.factory({
195
- pathParams: {
196
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
197
- children: getPathParams(typeSchemas.pathParams, {
198
- typed: true,
199
- casing: paramsCasing,
200
- override(item) {
201
- return {
202
- ...item,
203
- type: `MaybeRefOrGetter<${item.type}>`
204
- };
205
- }
206
- })
207
- },
208
- data: typeSchemas.request?.name ? {
209
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
210
- optional: isOptional(typeSchemas.request?.schema)
211
- } : void 0,
212
- params: typeSchemas.queryParams?.name ? {
213
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
214
- optional: isOptional(typeSchemas.queryParams?.schema)
215
- } : void 0
216
- });
217
- }
218
- __name(getParams$6, "getParams");
219
- const getTransformer$1 = /* @__PURE__ */ __name(({ operation, schemas, casing }) => {
220
- return [
221
- new URLPath(operation.path, { casing }).toObject({
222
- type: "path",
223
- stringify: true
224
- }),
225
- schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
226
- schemas.request?.name ? "...(data ? [data] : [])" : void 0
227
- ].filter(Boolean);
228
- }, "getTransformer");
229
- function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer$1 }) {
230
- const params = getParams$6({
231
- pathParamsType,
232
- typeSchemas,
233
- paramsCasing
234
- });
235
- const keys = transformer({
236
- operation,
237
- schemas: typeSchemas,
238
- casing: paramsCasing
239
- });
240
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
241
- name,
242
- isExportable: true,
243
- isIndexable: true,
244
- children: /* @__PURE__ */ jsx(Function$1.Arrow, {
245
- name,
246
- export: true,
247
- params: params.toConstructor(),
248
- singleLine: true,
249
- children: `[${keys.join(", ")}] as const`
250
- })
251
- }), /* @__PURE__ */ jsx(File.Source, {
252
- name: typeName,
253
- isExportable: true,
254
- isIndexable: true,
255
- isTypeOnly: true,
256
- children: /* @__PURE__ */ jsx(Type, {
257
- name: typeName,
258
- export: true,
259
- children: `ReturnType<typeof ${name}>`
260
- })
261
- })] });
262
- }
263
- QueryKey.getParams = getParams$6;
264
- QueryKey.getTransformer = getTransformer$1;
265
- //#endregion
266
- //#region src/components/QueryOptions.tsx
267
- function getParams$5({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
268
- if (paramsType === "object") {
269
- const children = {
270
- ...getPathParams(typeSchemas.pathParams, {
271
- typed: true,
272
- casing: paramsCasing,
273
- override(item) {
274
- return {
275
- ...item,
276
- type: `MaybeRefOrGetter<${item.type}>`
277
- };
278
- }
279
- }),
280
- data: typeSchemas.request?.name ? {
281
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
282
- optional: isOptional(typeSchemas.request?.schema)
283
- } : void 0,
284
- params: typeSchemas.queryParams?.name ? {
285
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
286
- optional: isOptional(typeSchemas.queryParams?.schema)
287
- } : void 0,
288
- headers: typeSchemas.headerParams?.name ? {
289
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
290
- optional: isOptional(typeSchemas.headerParams?.schema)
291
- } : void 0
292
- };
293
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
294
- return FunctionParams.factory({
295
- data: {
296
- mode: "object",
297
- children,
298
- default: allChildrenAreOptional ? "{}" : void 0
299
- },
300
- config: {
301
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
302
- default: "{}"
303
- }
304
- });
305
- }
306
- return FunctionParams.factory({
307
- pathParams: {
308
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
309
- children: getPathParams(typeSchemas.pathParams, {
310
- typed: true,
311
- casing: paramsCasing,
312
- override(item) {
313
- return {
314
- ...item,
315
- type: `MaybeRefOrGetter<${item.type}>`
316
- };
317
- }
318
- }),
319
- default: getDefaultValue(typeSchemas.pathParams?.schema)
320
- },
321
- data: typeSchemas.request?.name ? {
322
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
323
- optional: isOptional(typeSchemas.request?.schema)
324
- } : void 0,
325
- params: typeSchemas.queryParams?.name ? {
326
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
327
- optional: isOptional(typeSchemas.queryParams?.schema)
328
- } : void 0,
329
- headers: typeSchemas.headerParams?.name ? {
330
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
331
- optional: isOptional(typeSchemas.headerParams?.schema)
332
- } : void 0,
333
- config: {
334
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
335
- default: "{}"
336
- }
337
- });
338
- }
339
- __name(getParams$5, "getParams");
340
- function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
341
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
342
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
343
- const params = getParams$5({
344
- paramsType,
345
- paramsCasing,
346
- pathParamsType,
347
- typeSchemas
348
- });
349
- const clientParams = Client.getParams({
350
- paramsType,
351
- paramsCasing,
352
- typeSchemas,
353
- pathParamsType,
354
- isConfigurable: true
355
- });
356
- const queryKeyParams = QueryKey.getParams({
357
- pathParamsType,
358
- typeSchemas,
359
- paramsCasing
360
- });
361
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
362
- return item && !item.optional && !item.default ? key : void 0;
363
- }).filter(Boolean).join("&& ");
364
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
365
- return /* @__PURE__ */ jsx(File.Source, {
366
- name,
367
- isExportable: true,
368
- isIndexable: true,
369
- children: /* @__PURE__ */ jsx(Function$1, {
370
- name,
371
- export: true,
372
- params: params.toConstructor(),
373
- children: `
374
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
375
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
376
- ${enabledText}
377
- queryKey,
378
- queryFn: async ({ signal }) => {
379
- return ${clientName}(${clientParams.toCall({ transformName(name) {
380
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
381
- return `toValue(${name})`;
382
- } })})
383
- },
384
- })
385
- `
386
- })
387
- });
388
- }
389
- QueryOptions.getParams = getParams$5;
390
- //#endregion
391
- //#region src/components/InfiniteQuery.tsx
392
- function getParams$4({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
393
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
394
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
395
- if (paramsType === "object") {
396
- const children = {
397
- ...getPathParams(typeSchemas.pathParams, {
398
- typed: true,
399
- casing: paramsCasing,
400
- override(item) {
401
- return {
402
- ...item,
403
- type: `MaybeRefOrGetter<${item.type}>`
404
- };
405
- }
406
- }),
407
- data: typeSchemas.request?.name ? {
408
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
409
- optional: isOptional(typeSchemas.request?.schema)
410
- } : void 0,
411
- params: typeSchemas.queryParams?.name ? {
412
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
413
- optional: isOptional(typeSchemas.queryParams?.schema)
414
- } : void 0,
415
- headers: typeSchemas.headerParams?.name ? {
416
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
417
- optional: isOptional(typeSchemas.headerParams?.schema)
418
- } : void 0
419
- };
420
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
421
- return FunctionParams.factory({
422
- data: {
423
- mode: "object",
424
- children,
425
- default: allChildrenAreOptional ? "{}" : void 0
426
- },
427
- options: {
428
- type: `
429
- {
430
- query?: Partial<UseInfiniteQueryOptions<${[
431
- TData,
432
- TError,
433
- "TQueryData",
434
- "TQueryKey",
435
- "TQueryData"
436
- ].join(", ")}>> & { client?: QueryClient },
437
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
438
- }
439
- `,
440
- default: "{}"
441
- }
442
- });
443
- }
444
- return FunctionParams.factory({
445
- pathParams: typeSchemas.pathParams?.name ? {
446
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
447
- children: getPathParams(typeSchemas.pathParams, {
448
- typed: true,
449
- casing: paramsCasing,
450
- override(item) {
451
- return {
452
- ...item,
453
- type: `MaybeRefOrGetter<${item.type}>`
454
- };
455
- }
456
- }),
457
- default: getDefaultValue(typeSchemas.pathParams?.schema)
458
- } : void 0,
459
- data: typeSchemas.request?.name ? {
460
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
461
- optional: isOptional(typeSchemas.request?.schema)
462
- } : void 0,
463
- params: typeSchemas.queryParams?.name ? {
464
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
465
- optional: isOptional(typeSchemas.queryParams?.schema)
466
- } : void 0,
467
- headers: typeSchemas.headerParams?.name ? {
468
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
469
- optional: isOptional(typeSchemas.headerParams?.schema)
470
- } : void 0,
471
- options: {
472
- type: `
473
- {
474
- query?: Partial<UseInfiniteQueryOptions<${[
475
- TData,
476
- TError,
477
- "TQueryData",
478
- "TQueryKey",
479
- "TQueryData"
480
- ].join(", ")}>> & { client?: QueryClient },
481
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
482
- }
483
- `,
484
- default: "{}"
485
- }
486
- });
487
- }
488
- __name(getParams$4, "getParams");
489
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, pathParamsType, paramsCasing, dataReturnType, typeSchemas, operation }) {
490
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
491
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
492
- const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
493
- const generics = [
494
- `TData = InfiniteData<${TData}>`,
495
- `TQueryData = ${TData}`,
496
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
497
- ];
498
- const queryKeyParams = QueryKey.getParams({
499
- pathParamsType,
500
- typeSchemas,
501
- paramsCasing
502
- });
503
- const queryOptionsParams = QueryOptions.getParams({
504
- paramsType,
505
- pathParamsType,
506
- typeSchemas,
507
- paramsCasing
508
- });
509
- const params = getParams$4({
510
- paramsCasing,
511
- paramsType,
512
- pathParamsType,
513
- dataReturnType,
514
- typeSchemas
515
- });
516
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
517
- return /* @__PURE__ */ jsx(File.Source, {
518
- name,
519
- isExportable: true,
520
- isIndexable: true,
521
- children: /* @__PURE__ */ jsx(Function$1, {
522
- name,
523
- export: true,
524
- generics: generics.join(", "),
525
- params: params.toConstructor(),
526
- JSDoc: { comments: getComments(operation) },
527
- children: `
528
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
529
- const { client: queryClient, ...resolvedOptions } = queryConfig
530
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
531
-
532
- const query = useInfiniteQuery({
533
- ...${queryOptions},
534
- ...resolvedOptions,
535
- queryKey
536
- } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
537
-
538
- query.queryKey = queryKey as TQueryKey
539
-
540
- return query
541
- `
542
- })
543
- });
544
- }
545
- InfiniteQuery.getParams = getParams$4;
546
- //#endregion
547
- //#region src/components/InfiniteQueryOptions.tsx
548
- function getParams$3({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
549
- if (paramsType === "object") {
550
- const children = {
551
- ...getPathParams(typeSchemas.pathParams, {
552
- typed: true,
553
- casing: paramsCasing,
554
- override(item) {
555
- return {
556
- ...item,
557
- type: `MaybeRefOrGetter<${item.type}>`
558
- };
559
- }
560
- }),
561
- data: typeSchemas.request?.name ? {
562
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
563
- optional: isOptional(typeSchemas.request?.schema)
564
- } : void 0,
565
- params: typeSchemas.queryParams?.name ? {
566
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
567
- optional: isOptional(typeSchemas.queryParams?.schema)
568
- } : void 0,
569
- headers: typeSchemas.headerParams?.name ? {
570
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
571
- optional: isOptional(typeSchemas.headerParams?.schema)
572
- } : void 0
573
- };
574
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
575
- return FunctionParams.factory({
576
- data: {
577
- mode: "object",
578
- children,
579
- default: allChildrenAreOptional ? "{}" : void 0
580
- },
581
- config: {
582
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
583
- default: "{}"
584
- }
585
- });
586
- }
587
- return FunctionParams.factory({
588
- pathParams: {
589
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
590
- children: getPathParams(typeSchemas.pathParams, {
591
- typed: true,
592
- casing: paramsCasing,
593
- override(item) {
594
- return {
595
- ...item,
596
- type: `MaybeRefOrGetter<${item.type}>`
597
- };
598
- }
599
- }),
600
- default: getDefaultValue(typeSchemas.pathParams?.schema)
601
- },
602
- data: typeSchemas.request?.name ? {
603
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
604
- optional: isOptional(typeSchemas.request?.schema)
605
- } : void 0,
606
- params: typeSchemas.queryParams?.name ? {
607
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
608
- optional: isOptional(typeSchemas.queryParams?.schema)
609
- } : void 0,
610
- headers: typeSchemas.headerParams?.name ? {
611
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
612
- optional: isOptional(typeSchemas.headerParams?.schema)
613
- } : void 0,
614
- config: {
615
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
616
- default: "{}"
617
- }
618
- });
619
- }
620
- __name(getParams$3, "getParams");
621
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, typeSchemas, paramsType, paramsCasing, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
622
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
623
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
624
- const params = getParams$3({
625
- paramsType,
626
- paramsCasing,
627
- pathParamsType,
628
- typeSchemas
629
- });
630
- const clientParams = Client.getParams({
631
- paramsType,
632
- paramsCasing,
633
- typeSchemas,
634
- pathParamsType,
635
- isConfigurable: true
636
- });
637
- const queryKeyParams = QueryKey.getParams({
638
- paramsCasing,
639
- pathParamsType,
640
- typeSchemas
641
- });
642
- const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
643
- let getNextPageParamExpr;
644
- let getPreviousPageParamExpr;
645
- if (hasNewParams) {
646
- if (nextParam) {
647
- const accessor = getNestedAccessor(nextParam, "lastPage");
648
- if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
649
- }
650
- if (previousParam) {
651
- const accessor = getNestedAccessor(previousParam, "firstPage");
652
- if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
653
- }
654
- } else if (cursorParam) {
655
- getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
656
- getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
657
- } else {
658
- if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
659
- else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
660
- getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
661
- }
662
- const queryOptions = [
663
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
664
- getNextPageParamExpr,
665
- getPreviousPageParamExpr
666
- ].filter(Boolean);
667
- const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
668
- if (!params) {
669
- params = { }
670
- }
671
- params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']` : "";
672
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => {
673
- return item && !item.optional && !item.default ? key : void 0;
674
- }).filter(Boolean).join("&& ");
675
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
676
- return /* @__PURE__ */ jsx(File.Source, {
677
- name,
678
- isExportable: true,
679
- isIndexable: true,
680
- children: /* @__PURE__ */ jsx(Function$1, {
681
- name,
682
- export: true,
683
- params: params.toConstructor(),
684
- children: `
685
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
686
- return infiniteQueryOptions<${TData}, ${TError}, ${TData}, typeof queryKey, number>({
687
- ${enabledText}
688
- queryKey,
689
- queryFn: async ({ signal, pageParam }) => {
690
- ${infiniteOverrideParams}
691
- return ${clientName}(${clientParams.toCall({ transformName(name) {
692
- if (name === "config") return "{ ...config, signal: config.signal ?? signal }";
693
- return `toValue(${name})`;
694
- } })})
695
- },
696
- ${queryOptions.join(",\n")}
697
- })
698
- `
699
- })
700
- });
701
- }
702
- InfiniteQueryOptions.getParams = getParams$3;
703
- //#endregion
704
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
705
- function getParams$2({}) {
706
- return FunctionParams.factory({});
707
- }
708
- __name(getParams$2, "getParams");
709
- const getTransformer = ({ operation, casing }) => {
710
- return [`{ url: '${new URLPath(operation.path, { casing }).toURLPath()}' }`];
711
- };
712
- function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
713
- const params = getParams$2({
714
- pathParamsType,
715
- typeSchemas
716
- });
717
- const keys = transformer({
718
- operation,
719
- schemas: typeSchemas,
720
- casing: paramsCasing
721
- });
722
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
723
- name,
724
- isExportable: true,
725
- isIndexable: true,
726
- children: /* @__PURE__ */ jsx(Function$1.Arrow, {
727
- name,
728
- export: true,
729
- params: params.toConstructor(),
730
- singleLine: true,
731
- children: `[${keys.join(", ")}] as const`
732
- })
733
- }), /* @__PURE__ */ jsx(File.Source, {
734
- name: typeName,
735
- isExportable: true,
736
- isIndexable: true,
737
- isTypeOnly: true,
738
- children: /* @__PURE__ */ jsx(Type, {
739
- name: typeName,
740
- export: true,
741
- children: `ReturnType<typeof ${name}>`
742
- })
743
- })] });
744
- }
745
- MutationKey.getParams = getParams$2;
746
- MutationKey.getTransformer = getTransformer;
747
- //#endregion
748
- //#region src/components/Mutation.tsx
749
- function getParams$1({ paramsCasing, dataReturnType, typeSchemas }) {
750
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
751
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
752
- const TRequest = FunctionParams.factory({
753
- ...getPathParams(typeSchemas.pathParams, {
754
- typed: true,
755
- casing: paramsCasing,
756
- override(item) {
757
- return {
758
- ...item,
759
- type: `MaybeRefOrGetter<${item.type}>`
760
- };
761
- }
762
- }),
763
- data: typeSchemas.request?.name ? {
764
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
765
- optional: isOptional(typeSchemas.request?.schema)
766
- } : void 0,
767
- params: typeSchemas.queryParams?.name ? {
768
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
769
- optional: isOptional(typeSchemas.queryParams?.schema)
770
- } : void 0,
771
- headers: typeSchemas.headerParams?.name ? {
772
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
773
- optional: isOptional(typeSchemas.headerParams?.schema)
774
- } : void 0
775
- }).toConstructor();
776
- return FunctionParams.factory({ options: {
777
- type: `
778
- {
779
- mutation?: MutationObserverOptions<${[
780
- TData,
781
- TError,
782
- TRequest ? `{${TRequest}}` : "void",
783
- "TContext"
784
- ].join(", ")}> & { client?: QueryClient },
785
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
786
- }
787
- `,
788
- default: "{}"
789
- } });
790
- }
791
- __name(getParams$1, "getParams");
792
- function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
793
- const mutationKeyParams = MutationKey.getParams({
794
- pathParamsType,
795
- typeSchemas
796
- });
797
- const params = getParams$1({
798
- paramsCasing,
799
- pathParamsType,
800
- dataReturnType,
801
- typeSchemas
802
- });
803
- const clientParams = Client.getParams({
804
- paramsCasing,
805
- paramsType,
806
- typeSchemas,
807
- pathParamsType,
808
- isConfigurable: true
809
- });
810
- const mutationParams = FunctionParams.factory({
811
- ...getPathParams(typeSchemas.pathParams, {
812
- typed: true,
813
- casing: paramsCasing
814
- }),
815
- data: typeSchemas.request?.name ? {
816
- type: typeSchemas.request?.name,
817
- optional: isOptional(typeSchemas.request?.schema)
818
- } : void 0,
819
- params: typeSchemas.queryParams?.name ? {
820
- type: typeSchemas.queryParams?.name,
821
- optional: isOptional(typeSchemas.queryParams?.schema)
822
- } : void 0,
823
- headers: typeSchemas.headerParams?.name ? {
824
- type: typeSchemas.headerParams?.name,
825
- optional: isOptional(typeSchemas.headerParams?.schema)
826
- } : void 0
827
- });
828
- const dataParams = FunctionParams.factory({ data: {
829
- mode: "object",
830
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
831
- if (value) acc[key] = {
832
- ...value,
833
- type: void 0
834
- };
835
- return acc;
836
- }, {})
837
- } });
838
- const TRequest = mutationParams.toConstructor();
839
- const generics = [
840
- dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`,
841
- `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`,
842
- TRequest ? `{${TRequest}}` : "void",
843
- "TContext"
844
- ].join(", ");
845
- return /* @__PURE__ */ jsx(File.Source, {
846
- name,
847
- isExportable: true,
848
- isIndexable: true,
849
- children: /* @__PURE__ */ jsx(Function$1, {
850
- name,
851
- export: true,
852
- params: params.toConstructor(),
853
- JSDoc: { comments: getComments(operation) },
854
- generics: ["TContext"],
855
- children: `
856
- const { mutation = {}, client: config = {} } = options ?? {}
857
- const { client: queryClient, ...mutationOptions } = mutation;
858
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
859
-
860
- return useMutation<${generics}>({
861
- mutationFn: async(${dataParams.toConstructor()}) => {
862
- return ${clientName}(${clientParams.toCall()})
863
- },
864
- mutationKey,
865
- ...mutationOptions
866
- }, queryClient)
867
- `
868
- })
869
- });
870
- }
871
- //#endregion
872
- //#region src/components/Query.tsx
873
- function getParams({ paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas }) {
874
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
875
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
876
- if (paramsType === "object") {
877
- const children = {
878
- ...getPathParams(typeSchemas.pathParams, {
879
- typed: true,
880
- casing: paramsCasing,
881
- override(item) {
882
- return {
883
- ...item,
884
- type: `MaybeRefOrGetter<${item.type}>`
885
- };
886
- }
887
- }),
888
- data: typeSchemas.request?.name ? {
889
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
890
- optional: isOptional(typeSchemas.request?.schema)
891
- } : void 0,
892
- params: typeSchemas.queryParams?.name ? {
893
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
894
- optional: isOptional(typeSchemas.queryParams?.schema)
895
- } : void 0,
896
- headers: typeSchemas.headerParams?.name ? {
897
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
898
- optional: isOptional(typeSchemas.headerParams?.schema)
899
- } : void 0
900
- };
901
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
902
- return FunctionParams.factory({
903
- data: {
904
- mode: "object",
905
- children,
906
- default: allChildrenAreOptional ? "{}" : void 0
907
- },
908
- options: {
909
- type: `
910
- {
911
- query?: Partial<UseQueryOptions<${[
912
- TData,
913
- TError,
914
- "TData",
915
- "TQueryData",
916
- "TQueryKey"
917
- ].join(", ")}>> & { client?: QueryClient },
918
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
919
- }
920
- `,
921
- default: "{}"
922
- }
923
- });
924
- }
925
- return FunctionParams.factory({
926
- pathParams: typeSchemas.pathParams?.name ? {
927
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
928
- children: getPathParams(typeSchemas.pathParams, {
929
- typed: true,
930
- casing: paramsCasing,
931
- override(item) {
932
- return {
933
- ...item,
934
- type: `MaybeRefOrGetter<${item.type}>`
935
- };
936
- }
937
- }),
938
- default: getDefaultValue(typeSchemas.pathParams?.schema)
939
- } : void 0,
940
- data: typeSchemas.request?.name ? {
941
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
942
- optional: isOptional(typeSchemas.request?.schema)
943
- } : void 0,
944
- params: typeSchemas.queryParams?.name ? {
945
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
946
- optional: isOptional(typeSchemas.queryParams?.schema)
947
- } : void 0,
948
- headers: typeSchemas.headerParams?.name ? {
949
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
950
- optional: isOptional(typeSchemas.headerParams?.schema)
951
- } : void 0,
952
- options: {
953
- type: `
954
- {
955
- query?: Partial<UseQueryOptions<${[
956
- TData,
957
- TError,
958
- "TData",
959
- "TQueryData",
960
- "TQueryKey"
961
- ].join(", ")}>> & { client?: QueryClient },
962
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
963
- }
964
- `,
965
- default: "{}"
966
- }
967
- });
968
- }
969
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, operation }) {
970
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
971
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
972
- const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
973
- const generics = [
974
- `TData = ${TData}`,
975
- `TQueryData = ${TData}`,
976
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`
977
- ];
978
- const queryKeyParams = QueryKey.getParams({
979
- pathParamsType,
980
- typeSchemas,
981
- paramsCasing
982
- });
983
- const queryOptionsParams = QueryOptions.getParams({
984
- paramsType,
985
- pathParamsType,
986
- typeSchemas,
987
- paramsCasing
988
- });
989
- const params = getParams({
990
- paramsCasing,
991
- paramsType,
992
- pathParamsType,
993
- dataReturnType,
994
- typeSchemas
995
- });
996
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
997
- return /* @__PURE__ */ jsx(File.Source, {
998
- name,
999
- isExportable: true,
1000
- isIndexable: true,
1001
- children: /* @__PURE__ */ jsx(Function$1, {
1002
- name,
1003
- export: true,
1004
- generics: generics.join(", "),
1005
- params: params.toConstructor(),
1006
- JSDoc: { comments: getComments(operation) },
1007
- children: `
1008
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1009
- const { client: queryClient, ...resolvedOptions } = queryConfig
1010
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
1011
-
1012
- const query = useQuery({
1013
- ...${queryOptions},
1014
- ...resolvedOptions,
1015
- queryKey
1016
- } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1017
-
1018
- query.queryKey = queryKey as TQueryKey
1019
-
1020
- return query
1021
- `
1022
- })
1023
- });
1024
- }
1025
- Query.getParams = getParams;
1026
- //#endregion
1027
- export { InfiniteQuery as a, camelCase as c, InfiniteQueryOptions as i, pascalCase as l, Mutation as n, QueryOptions as o, MutationKey as r, QueryKey as s, Query as t };
1028
-
1029
- //# sourceMappingURL=components-_AMBl0g-.js.map