@kubb/plugin-vue-query 0.0.0-canary-20241104172400

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-A7SD37VK.cjs +584 -0
  4. package/dist/chunk-A7SD37VK.cjs.map +1 -0
  5. package/dist/chunk-DHJLKFYS.js +827 -0
  6. package/dist/chunk-DHJLKFYS.js.map +1 -0
  7. package/dist/chunk-J4RZRRHQ.cjs +837 -0
  8. package/dist/chunk-J4RZRRHQ.cjs.map +1 -0
  9. package/dist/chunk-O4EGNKUX.js +576 -0
  10. package/dist/chunk-O4EGNKUX.js.map +1 -0
  11. package/dist/components.cjs +36 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +150 -0
  14. package/dist/components.d.ts +150 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +21 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +12 -0
  20. package/dist/generators.d.ts +12 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +134 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +127 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-C8LfCZUP.d.cts +389 -0
  30. package/dist/types-C8LfCZUP.d.ts +389 -0
  31. package/package.json +102 -0
  32. package/src/components/InfiniteQuery.tsx +190 -0
  33. package/src/components/InfiniteQueryOptions.tsx +185 -0
  34. package/src/components/Mutation.tsx +167 -0
  35. package/src/components/MutationKey.tsx +54 -0
  36. package/src/components/Query.tsx +191 -0
  37. package/src/components/QueryKey.tsx +91 -0
  38. package/src/components/QueryOptions.tsx +152 -0
  39. package/src/components/index.ts +7 -0
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +53 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +53 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +45 -0
  43. package/src/generators/__snapshots__/findByTags.ts +53 -0
  44. package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
  45. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +53 -0
  46. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +53 -0
  47. package/src/generators/__snapshots__/findByTagsWithZod.ts +53 -0
  48. package/src/generators/__snapshots__/findInfiniteByTags.ts +58 -0
  49. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +58 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +52 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +45 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +45 -0
  53. package/src/generators/index.ts +3 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +137 -0
  55. package/src/generators/mutationGenerator.tsx +116 -0
  56. package/src/generators/queryGenerator.tsx +129 -0
  57. package/src/index.ts +2 -0
  58. package/src/plugin.ts +149 -0
  59. package/src/types.ts +159 -0
@@ -0,0 +1,389 @@
1
+ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod, Operation } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
4
+
5
+ type Options$2 = {
6
+ /**
7
+ * Specify the export location for the files and define the behavior of the output
8
+ * @default { path: 'clients', barrelType: 'named' }
9
+ */
10
+ output?: Output;
11
+ /**
12
+ * Group the clients based on the provided name.
13
+ */
14
+ group?: Group;
15
+ /**
16
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
17
+ */
18
+ exclude?: Array<Exclude>;
19
+ /**
20
+ * Array containing include parameters to include tags/operations/methods/paths.
21
+ */
22
+ include?: Array<Include>;
23
+ /**
24
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
25
+ */
26
+ override?: Array<Override<ResolvedOptions$2>>;
27
+ /**
28
+ * Create `operations.ts` file with all operations grouped by methods.
29
+ * @default false
30
+ */
31
+ operations?: boolean;
32
+ /**
33
+ * Path to the client import path that will be used to do the API calls.
34
+ * It will be used as `import client from '${client.importPath}'`.
35
+ * It allows both relative and absolute path but be aware that we will not change the path.
36
+ * @default '@kubb/plugin-client/client'
37
+ */
38
+ importPath?: string;
39
+ /**
40
+ * Allows you to set a custom base url for all generated calls.
41
+ */
42
+ baseURL?: string;
43
+ /**
44
+ * ReturnType that will be used when calling the client.
45
+ * - 'data' will return ResponseConfig[data].
46
+ * - 'full' will return ResponseConfig.
47
+ * @default 'data'
48
+ */
49
+ dataReturnType?: 'data' | 'full';
50
+ /**
51
+ * How to pass your params
52
+ * - 'object' will return the params and pathParams as an object.
53
+ * - 'inline' will return the params as comma separated params.
54
+ * @default 'inline'
55
+ */
56
+ paramsType?: 'object' | 'inline';
57
+ /**
58
+ * How to pass your pathParams.
59
+ * - 'object' will return the pathParams as an object.
60
+ * - 'inline' will return the pathParams as comma separated params.
61
+ * @default 'inline'
62
+ */
63
+ pathParamsType?: 'object' | 'inline';
64
+ /**
65
+ * Which parser can be used before returning the data
66
+ * - 'zod' will use `@kubb/plugin-zod` to parse the data.
67
+ * @default 'client'
68
+ */
69
+ parser?: 'client' | 'zod';
70
+ transformers?: {
71
+ /**
72
+ * Customize the names based on the type that is provided by the plugin.
73
+ */
74
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
75
+ };
76
+ /**
77
+ * Define some generators next to the client generators
78
+ */
79
+ generators?: Array<Generator<PluginClient>>;
80
+ };
81
+ type ResolvedOptions$2 = {
82
+ output: Output;
83
+ group?: Options$2['group'];
84
+ baseURL: string | undefined;
85
+ parser: NonNullable<Options$2['parser']>;
86
+ importPath: NonNullable<Options$2['importPath']>;
87
+ dataReturnType: NonNullable<Options$2['dataReturnType']>;
88
+ pathParamsType: NonNullable<Options$2['pathParamsType']>;
89
+ paramsType: NonNullable<Options$2['paramsType']>;
90
+ };
91
+ type PluginClient = PluginFactoryOptions<'plugin-client', Options$2, ResolvedOptions$2, never, ResolvePathOptions>;
92
+
93
+ type TransformerProps$1 = {
94
+ operation: Operation;
95
+ schemas: OperationSchemas;
96
+ };
97
+ type Transformer$1 = (props: TransformerProps$1) => unknown[];
98
+ type Suspense = object;
99
+ /**
100
+ * Customize the queryKey
101
+ */
102
+ type QueryKey$1 = Transformer$1;
103
+ /**
104
+ * Customize the mutationKey
105
+ */
106
+ type MutationKey$1 = Transformer$1;
107
+ type Query$1 = {
108
+ /**
109
+ * Define which HttpMethods can be used for queries
110
+ * @default ['get']
111
+ */
112
+ methods: Array<HttpMethod>;
113
+ /**
114
+ * Path to the useQuery that will be used to do the useQuery functionality.
115
+ * It will be used as `import { useQuery } from '${importPath}'`.
116
+ * It allows both relative and absolute path.
117
+ * the path will be applied as is, so relative path should be based on the file being generated.
118
+ * @default '@tanstack/react-query'
119
+ */
120
+ importPath?: string;
121
+ };
122
+ type Mutation$1 = {
123
+ /**
124
+ * Define which HttpMethods can be used for mutations
125
+ * @default ['post', 'put', 'delete']
126
+ */
127
+ methods: Array<HttpMethod>;
128
+ /**
129
+ * Path to the useQuery that will be used to do the useQuery functionality.
130
+ * It will be used as `import { useQuery } from '${importPath}'`.
131
+ * It allows both relative and absolute path.
132
+ * the path will be applied as is, so relative path should be based on the file being generated.
133
+ * @default '@tanstack/react-query'
134
+ */
135
+ importPath?: string;
136
+ };
137
+ type Infinite$1 = {
138
+ /**
139
+ * Specify the params key used for `pageParam`.
140
+ * @default 'id'
141
+ */
142
+ queryParam: string;
143
+ /**
144
+ * Which field of the data will be used, set it to undefined when no cursor is known.
145
+ */
146
+ cursorParam?: string | undefined;
147
+ /**
148
+ * The initial value, the value of the first page.
149
+ * @default 0
150
+ */
151
+ initialPageParam: unknown;
152
+ };
153
+ type Options$1 = {
154
+ /**
155
+ * Specify the export location for the files and define the behavior of the output
156
+ * @default { path: 'hooks', barrelType: 'named' }
157
+ */
158
+ output?: Output;
159
+ /**
160
+ * Group the @tanstack/query hooks based on the provided name.
161
+ */
162
+ group?: Group;
163
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
164
+ /**
165
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
166
+ */
167
+ exclude?: Array<Exclude>;
168
+ /**
169
+ * Array containing include parameters to include tags/operations/methods/paths.
170
+ */
171
+ include?: Array<Include>;
172
+ /**
173
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
174
+ */
175
+ override?: Array<Override<ResolvedOptions$1>>;
176
+ /**
177
+ * How to pass your params
178
+ * - 'object' will return the params and pathParams as an object.
179
+ * - 'inline' will return the params as comma separated params.
180
+ * @default 'inline'
181
+ */
182
+ paramsType?: 'object' | 'inline';
183
+ /**
184
+ * How to pass your pathParams.
185
+ * - 'object' will return the pathParams as an object.
186
+ * - 'inline' will return the pathParams as comma separated params.
187
+ * @default 'inline'
188
+ */
189
+ pathParamsType?: PluginClient['options']['pathParamsType'];
190
+ /**
191
+ * When set, an infiniteQuery hooks will be added.
192
+ */
193
+ infinite?: Partial<Infinite$1> | false;
194
+ /**
195
+ * When set, a suspenseQuery hooks will be added.
196
+ */
197
+ suspense?: Partial<Suspense> | false;
198
+ queryKey?: QueryKey$1;
199
+ /**
200
+ * Override some useQuery behaviours.
201
+ */
202
+ query?: Partial<Query$1> | false;
203
+ mutationKey?: MutationKey$1;
204
+ /**
205
+ * Override some useMutation behaviours.
206
+ */
207
+ mutation?: Partial<Mutation$1> | false;
208
+ /**
209
+ * Which parser should be used before returning the data to `@tanstack/query`.
210
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
211
+ */
212
+ parser?: PluginClient['options']['parser'];
213
+ transformers?: {
214
+ /**
215
+ * Customize the names based on the type that is provided by the plugin.
216
+ */
217
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
218
+ };
219
+ /**
220
+ * Define some generators next to the react-query generators
221
+ */
222
+ generators?: Array<Generator<PluginReactQuery>>;
223
+ };
224
+ type ResolvedOptions$1 = {
225
+ output: Output;
226
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
227
+ baseURL?: string;
228
+ };
229
+ parser: Required<NonNullable<Options$1['parser']>>;
230
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
231
+ paramsType: NonNullable<Options$1['paramsType']>;
232
+ /**
233
+ * Only used of infinite
234
+ */
235
+ infinite: NonNullable<Infinite$1> | false;
236
+ suspense: Suspense | false;
237
+ queryKey: QueryKey$1 | undefined;
238
+ query: NonNullable<Required<Query$1>> | false;
239
+ mutationKey: MutationKey$1 | undefined;
240
+ mutation: NonNullable<Required<Mutation$1>> | false;
241
+ };
242
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
243
+
244
+ type TransformerProps = {
245
+ operation: Operation;
246
+ schemas: OperationSchemas;
247
+ };
248
+ type Transformer = (props: TransformerProps) => unknown[];
249
+ /**
250
+ * Customize the queryKey
251
+ */
252
+ type QueryKey = Transformer;
253
+ /**
254
+ * Customize the mutationKey
255
+ */
256
+ type MutationKey = Transformer;
257
+ type Query = {
258
+ /**
259
+ * Define which HttpMethods can be used for queries
260
+ * @default ['get']
261
+ */
262
+ methods: Array<HttpMethod>;
263
+ /**
264
+ * Path to the useQuery that will be used to do the useQuery functionality.
265
+ * It will be used as `import { useQuery } from '${importPath}'`.
266
+ * It allows both relative and absolute path.
267
+ * the path will be applied as is, so relative path should be based on the file being generated.
268
+ * @default '@tanstack/react-query'
269
+ */
270
+ importPath?: string;
271
+ };
272
+ type Mutation = {
273
+ /**
274
+ * Define which HttpMethods can be used for mutations
275
+ * @default ['post', 'put', 'delete']
276
+ */
277
+ methods: Array<HttpMethod>;
278
+ /**
279
+ * Path to the useQuery that will be used to do the useQuery functionality.
280
+ * It will be used as `import { useQuery } from '${importPath}'`.
281
+ * It allows both relative and absolute path.
282
+ * the path will be applied as is, so relative path should be based on the file being generated.
283
+ * @default '@tanstack/react-query'
284
+ */
285
+ importPath?: string;
286
+ };
287
+ type Infinite = {
288
+ /**
289
+ * Specify the params key used for `pageParam`.
290
+ * @default `'id'`
291
+ */
292
+ queryParam: string;
293
+ /**
294
+ * Which field of the data will be used, set it to undefined when no cursor is known.
295
+ */
296
+ cursorParam?: string | undefined;
297
+ /**
298
+ * The initial value, the value of the first page.
299
+ * @default `0`
300
+ */
301
+ initialPageParam: unknown;
302
+ };
303
+ type Options = {
304
+ /**
305
+ * Specify the export location for the files and define the behavior of the output
306
+ * @default { path: 'hooks', barrelType: 'named' }
307
+ */
308
+ output?: Output;
309
+ /**
310
+ * Group the @tanstack/query hooks based on the provided name.
311
+ */
312
+ group?: Group;
313
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
314
+ /**
315
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
316
+ */
317
+ exclude?: Array<Exclude>;
318
+ /**
319
+ * Array containing include parameters to include tags/operations/methods/paths.
320
+ */
321
+ include?: Array<Include>;
322
+ /**
323
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
324
+ */
325
+ override?: Array<Override<ResolvedOptions>>;
326
+ /**
327
+ * How to pass your params
328
+ * - 'object' will return the params and pathParams as an object.
329
+ * - 'inline' will return the params as comma separated params.
330
+ * @default 'inline'
331
+ */
332
+ paramsType?: 'object' | 'inline';
333
+ /**
334
+ * How to pass your pathParams.
335
+ * - 'object' will return the pathParams as an object.
336
+ * - 'inline' will return the pathParams as comma separated params.
337
+ * @default 'inline'
338
+ */
339
+ pathParamsType?: PluginClient['options']['pathParamsType'];
340
+ /**
341
+ * When set, an infiniteQuery hooks will be added.
342
+ */
343
+ infinite?: Partial<Infinite> | false;
344
+ queryKey?: QueryKey;
345
+ /**
346
+ * Override some useQuery behaviours.
347
+ */
348
+ query?: Partial<Query> | false;
349
+ mutationKey?: MutationKey;
350
+ /**
351
+ * Override some useMutation behaviours.
352
+ */
353
+ mutation?: Mutation | false;
354
+ /**
355
+ * Which parser should be used before returning the data to `@tanstack/query`.
356
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
357
+ */
358
+ parser?: PluginClient['options']['parser'];
359
+ transformers?: {
360
+ /**
361
+ * Customize the names based on the type that is provided by the plugin.
362
+ */
363
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
364
+ };
365
+ /**
366
+ * Define some generators next to the vue-query generators
367
+ */
368
+ generators?: Array<Generator<PluginVueQuery>>;
369
+ };
370
+ type ResolvedOptions = {
371
+ output: Output;
372
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
373
+ baseURL?: string;
374
+ };
375
+ parser: Required<NonNullable<Options['parser']>>;
376
+ paramsType: NonNullable<Options['paramsType']>;
377
+ pathParamsType: NonNullable<Options['pathParamsType']>;
378
+ /**
379
+ * Only used of infinite
380
+ */
381
+ infinite: NonNullable<Infinite> | false;
382
+ queryKey: QueryKey | undefined;
383
+ query: NonNullable<Required<Query>> | false;
384
+ mutationKey: MutationKey | undefined;
385
+ mutation: NonNullable<Required<Mutation>> | false;
386
+ };
387
+ type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>;
388
+
389
+ export type { Infinite as I, Options as O, PluginVueQuery as P, Transformer as T };
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@kubb/plugin-vue-query",
3
+ "version": "0.0.0-canary-20241104172400",
4
+ "description": "Generator vue-query hooks",
5
+ "keywords": [
6
+ "faker",
7
+ "faker.js",
8
+ "msw",
9
+ "mock",
10
+ "mocking",
11
+ "plugins",
12
+ "kubb",
13
+ "codegen",
14
+ "swagger",
15
+ "openapi"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git://github.com/kubb-labs/kubb.git",
20
+ "directory": "packages/plugin-vue-query"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
24
+ "sideEffects": false,
25
+ "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.js",
29
+ "require": "./dist/index.cjs",
30
+ "default": "./dist/index.cjs"
31
+ },
32
+ "./generators": {
33
+ "import": "./dist/generators.js",
34
+ "require": "./dist/generators.cjs",
35
+ "default": "./dist/generators.cjs"
36
+ },
37
+ "./components": {
38
+ "import": "./dist/components.js",
39
+ "require": "./dist/components.cjs",
40
+ "default": "./dist/components.cjs"
41
+ },
42
+ "./package.json": "./package.json",
43
+ "./*": "./*"
44
+ },
45
+ "main": "dist/index.cjs",
46
+ "module": "dist/index.js",
47
+ "types": "./dist/index.d.ts",
48
+ "typesVersions": {
49
+ "*": {
50
+ "components": [
51
+ "./dist/components.d.ts"
52
+ ],
53
+ "generators": [
54
+ "./dist/generators.d.ts"
55
+ ]
56
+ }
57
+ },
58
+ "files": [
59
+ "src",
60
+ "dist",
61
+ "!/**/**.test.**",
62
+ "!/**/__tests__/**"
63
+ ],
64
+ "dependencies": {
65
+ "@kubb/core": "0.0.0-canary-20241104172400",
66
+ "@kubb/fs": "0.0.0-canary-20241104172400",
67
+ "@kubb/oas": "0.0.0-canary-20241104172400",
68
+ "@kubb/plugin-oas": "0.0.0-canary-20241104172400",
69
+ "@kubb/plugin-ts": "0.0.0-canary-20241104172400",
70
+ "@kubb/plugin-zod": "0.0.0-canary-20241104172400",
71
+ "@kubb/react": "0.0.0-canary-20241104172400"
72
+ },
73
+ "devDependencies": {
74
+ "@types/react": "^18.3.12",
75
+ "react": "^18.3.1",
76
+ "tsup": "^8.3.5",
77
+ "typescript": "^5.6.3",
78
+ "@kubb/config-ts": "0.0.0-canary-20241104172400",
79
+ "@kubb/config-tsup": "0.0.0-canary-20241104172400"
80
+ },
81
+ "peerDependencies": {
82
+ "@kubb/react": "0.0.0-canary-20241104172400"
83
+ },
84
+ "engines": {
85
+ "node": ">=20"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public",
89
+ "registry": "https://registry.npmjs.org/"
90
+ },
91
+ "scripts": {
92
+ "build": "tsup",
93
+ "clean": "npx rimraf ./dist",
94
+ "lint": "bun biome lint .",
95
+ "lint:fix": "bun biome lint --apply-unsafe .",
96
+ "release": "pnpm publish --no-git-check",
97
+ "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
98
+ "start": "tsup --watch",
99
+ "test": "vitest --passWithNoTests",
100
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
101
+ }
102
+ }
@@ -0,0 +1,190 @@
1
+ import { File, Function, FunctionParams } from '@kubb/react'
2
+
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import type { OperationSchemas } from '@kubb/plugin-oas'
5
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
+ import type { ReactNode } from 'react'
7
+ import type { PluginVueQuery } from '../types.ts'
8
+ import { QueryKey } from './QueryKey.tsx'
9
+ import { QueryOptions } from './QueryOptions.tsx'
10
+
11
+ type Props = {
12
+ /**
13
+ * Name of the function
14
+ */
15
+ name: string
16
+ queryOptionsName: string
17
+ queryKeyName: string
18
+ queryKeyTypeName: string
19
+ typeSchemas: OperationSchemas
20
+ operation: Operation
21
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
22
+ pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
23
+ dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
24
+ }
25
+
26
+ type GetParamsProps = {
27
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
28
+ pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
29
+ dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
30
+ typeSchemas: OperationSchemas
31
+ }
32
+
33
+ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
34
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
35
+
36
+ if (paramsType === 'object') {
37
+ return FunctionParams.factory({
38
+ data: {
39
+ mode: 'object',
40
+ children: {
41
+ ...getPathParams(typeSchemas.pathParams, {
42
+ typed: true,
43
+ override(item) {
44
+ return {
45
+ ...item,
46
+ type: `MaybeRef<${item.type}>`,
47
+ }
48
+ },
49
+ }),
50
+ data: typeSchemas.request?.name
51
+ ? {
52
+ type: `MaybeRef<${typeSchemas.request?.name}>`,
53
+ optional: isOptional(typeSchemas.request?.schema),
54
+ }
55
+ : undefined,
56
+ params: typeSchemas.queryParams?.name
57
+ ? {
58
+ type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
59
+ optional: isOptional(typeSchemas.queryParams?.schema),
60
+ }
61
+ : undefined,
62
+ headers: typeSchemas.headerParams?.name
63
+ ? {
64
+ type: `MaybeRef<${typeSchemas.headerParams?.name}>`,
65
+ optional: isOptional(typeSchemas.headerParams?.schema),
66
+ }
67
+ : undefined,
68
+ },
69
+ },
70
+ options: {
71
+ type: `
72
+ {
73
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
74
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
75
+ }
76
+ `,
77
+ default: '{}',
78
+ },
79
+ })
80
+ }
81
+
82
+ return FunctionParams.factory({
83
+ pathParams: {
84
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
85
+ type: typeSchemas.pathParams?.name,
86
+ optional: isOptional(typeSchemas.pathParams?.schema),
87
+ children: getPathParams(typeSchemas.pathParams, {
88
+ typed: true,
89
+ override(item) {
90
+ return {
91
+ ...item,
92
+ type: `MaybeRef<${item.type}>`,
93
+ }
94
+ },
95
+ }),
96
+ },
97
+ data: typeSchemas.request?.name
98
+ ? {
99
+ type: `MaybeRef<${typeSchemas.request?.name}>`,
100
+ optional: isOptional(typeSchemas.request?.schema),
101
+ }
102
+ : undefined,
103
+ params: typeSchemas.queryParams?.name
104
+ ? {
105
+ type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
106
+ optional: isOptional(typeSchemas.queryParams?.schema),
107
+ }
108
+ : undefined,
109
+ headers: typeSchemas.headerParams?.name
110
+ ? {
111
+ type: `MaybeRef<${typeSchemas.headerParams?.name}>`,
112
+ optional: isOptional(typeSchemas.headerParams?.schema),
113
+ }
114
+ : undefined,
115
+ options: {
116
+ type: `
117
+ {
118
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
119
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
120
+ }
121
+ `,
122
+ default: '{}',
123
+ },
124
+ })
125
+ }
126
+
127
+ export function InfiniteQuery({
128
+ name,
129
+ queryKeyTypeName,
130
+ queryOptionsName,
131
+ queryKeyName,
132
+ paramsType,
133
+ pathParamsType,
134
+ dataReturnType,
135
+ typeSchemas,
136
+ operation,
137
+ }: Props): ReactNode {
138
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
139
+ const returnType = `UseInfiniteQueryReturnType<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
140
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
141
+
142
+ const queryKeyParams = QueryKey.getParams({
143
+ pathParamsType,
144
+ typeSchemas,
145
+ })
146
+ const queryOptionsParams = QueryOptions.getParams({
147
+ paramsType,
148
+ pathParamsType,
149
+ typeSchemas,
150
+ })
151
+ const params = getParams({
152
+ paramsType,
153
+ pathParamsType,
154
+ dataReturnType,
155
+ typeSchemas,
156
+ })
157
+
158
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as InfiniteQueryObserverOptions`
159
+
160
+ return (
161
+ <File.Source name={name} isExportable isIndexable>
162
+ <Function
163
+ name={name}
164
+ export
165
+ generics={generics.join(', ')}
166
+ params={params.toConstructor()}
167
+ JSDoc={{
168
+ comments: getComments(operation),
169
+ }}
170
+ >
171
+ {`
172
+ const { query: queryOptions, client: config = {} } = options ?? {}
173
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
174
+
175
+ const query = useInfiniteQuery({
176
+ ...${queryOptions},
177
+ queryKey: queryKey as QueryKey,
178
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
179
+ }) as ${returnType}
180
+
181
+ query.queryKey = queryKey as TQueryKey
182
+
183
+ return query
184
+ `}
185
+ </Function>
186
+ </File.Source>
187
+ )
188
+ }
189
+
190
+ InfiniteQuery.getParams = getParams