@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (73) hide show
  1. package/dist/chunk-ESENIDWJ.js +608 -0
  2. package/dist/chunk-ESENIDWJ.js.map +1 -0
  3. package/dist/chunk-JQEH3UHY.cjs +618 -0
  4. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  5. package/dist/chunk-KRG2LWHM.cjs +606 -0
  6. package/dist/chunk-KRG2LWHM.cjs.map +1 -0
  7. package/dist/chunk-ME7ZFS5H.js +596 -0
  8. package/dist/chunk-ME7ZFS5H.js.map +1 -0
  9. package/dist/components.cjs +17 -5
  10. package/dist/components.d.cts +143 -5
  11. package/dist/components.d.ts +143 -5
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +25 -0
  14. package/dist/generators.cjs.map +1 -0
  15. package/dist/generators.d.cts +15 -0
  16. package/dist/generators.d.ts +15 -0
  17. package/dist/generators.js +4 -0
  18. package/dist/generators.js.map +1 -0
  19. package/dist/index.cjs +33 -76
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -4
  22. package/dist/index.d.ts +2 -4
  23. package/dist/index.js +34 -77
  24. package/dist/index.js.map +1 -1
  25. package/dist/types-DJxL-JeY.d.cts +195 -0
  26. package/dist/types-DJxL-JeY.d.ts +195 -0
  27. package/package.json +23 -15
  28. package/src/components/InfiniteQuery.tsx +129 -0
  29. package/src/components/InfiniteQueryOptions.tsx +121 -0
  30. package/src/components/Mutation.tsx +112 -304
  31. package/src/components/Query.tsx +91 -593
  32. package/src/components/QueryKey.tsx +51 -182
  33. package/src/components/QueryOptions.tsx +64 -465
  34. package/src/components/SuspenseQuery.tsx +129 -0
  35. package/src/components/index.ts +3 -0
  36. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +64 -0
  37. package/src/generators/__snapshots__/clientGetImportPath.ts +64 -0
  38. package/src/generators/__snapshots__/clientPostImportPath.ts +59 -0
  39. package/src/generators/__snapshots__/findByTags.ts +64 -0
  40. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +64 -0
  41. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +64 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +64 -0
  43. package/src/generators/__snapshots__/findInfiniteByTags.ts +74 -0
  44. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +74 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +77 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +59 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +63 -0
  49. package/src/generators/index.ts +4 -0
  50. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  51. package/src/generators/mutationGenerator.tsx +94 -0
  52. package/src/generators/queryGenerator.tsx +121 -0
  53. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  54. package/src/plugin.ts +38 -49
  55. package/src/types.ts +35 -59
  56. package/dist/chunk-AGLJPONA.cjs +0 -1423
  57. package/dist/chunk-AGLJPONA.cjs.map +0 -1
  58. package/dist/chunk-I7X4HNDR.js +0 -1413
  59. package/dist/chunk-I7X4HNDR.js.map +0 -1
  60. package/dist/index-BzoLlZve.d.cts +0 -537
  61. package/dist/index-BzoLlZve.d.ts +0 -537
  62. package/src/OperationGenerator.tsx +0 -57
  63. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  64. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  65. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  66. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  67. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  68. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  69. package/src/components/QueryImports.tsx +0 -167
  70. package/src/components/SchemaType.tsx +0 -74
  71. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  72. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  73. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
@@ -0,0 +1,195 @@
1
+ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
+ import * as KubbFile from '@kubb/fs/types';
3
+ import { HttpMethod } from '@kubb/oas';
4
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
+
6
+ type Suspense = object;
7
+ type Query = {
8
+ /**
9
+ * Customize the queryKey, here you can specify a suffix.
10
+ */
11
+ key: (key: unknown[]) => unknown[];
12
+ /**
13
+ * Define which HttpMethods can be used for queries
14
+ * @default ['get']
15
+ */
16
+ methods: Array<HttpMethod>;
17
+ /**
18
+ * Path to the useQuery that will be used to do the useQuery functionality.
19
+ * It will be used as `import { useQuery } from '${importPath}'`.
20
+ * It allows both relative and absolute path.
21
+ * the path will be applied as is, so relative path should be based on the file being generated.
22
+ * @default '@tanstack/react-query'
23
+ */
24
+ importPath?: string;
25
+ };
26
+ type Mutation = {
27
+ /**
28
+ * Define which HttpMethods can be used for mutations
29
+ * @default ['post', 'put', 'delete']
30
+ */
31
+ methods: Array<HttpMethod>;
32
+ /**
33
+ * Path to the useQuery that will be used to do the useQuery functionality.
34
+ * It will be used as `import { useQuery } from '${importPath}'`.
35
+ * It allows both relative and absolute path.
36
+ * the path will be applied as is, so relative path should be based on the file being generated.
37
+ * @default '@tanstack/react-query'
38
+ */
39
+ importPath?: string;
40
+ };
41
+ type Infinite = {
42
+ /**
43
+ * Specify the params key used for `pageParam`.
44
+ * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
45
+ * @default `'id'`
46
+ */
47
+ queryParam: string;
48
+ /**
49
+ * Which field of the data will be used, set it to undefined when no cursor is known.
50
+ */
51
+ cursorParam?: string | undefined;
52
+ /**
53
+ * The initial value, the value of the first page.
54
+ * @default `0`
55
+ */
56
+ initialPageParam: unknown;
57
+ };
58
+ type Options = {
59
+ output?: {
60
+ /**
61
+ * Output to save the @tanstack/query hooks.
62
+ * @default `"hooks"`
63
+ */
64
+ path: string;
65
+ /**
66
+ * Name to be used for the `export * as {{exportAs}} from './'`
67
+ */
68
+ exportAs?: string;
69
+ /**
70
+ * Add an extension to the generated imports and exports, default it will not use an extension
71
+ */
72
+ extName?: KubbFile.Extname;
73
+ /**
74
+ * Define what needs to exported, here you can also disable the export of barrel files
75
+ * @default `'barrel'`
76
+ */
77
+ exportType?: 'barrel' | 'barrelNamed' | false;
78
+ };
79
+ /**
80
+ * Group the @tanstack/query hooks based on the provided name.
81
+ */
82
+ group?: {
83
+ /**
84
+ * Tag will group based on the operation tag inside the Swagger file
85
+ */
86
+ type: 'tag';
87
+ /**
88
+ * Relative path to save the grouped @tanstack/query hooks.
89
+ *
90
+ * `{{tag}}` will be replaced by the current tagName.
91
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
92
+ * @default `${output}/{{tag}}Controller`
93
+ */
94
+ output?: string;
95
+ /**
96
+ * Name to be used for the `export * as {{exportAs}} from './`
97
+ * @default `"{{tag}}Hooks"`
98
+ */
99
+ exportAs?: string;
100
+ };
101
+ client?: {
102
+ /**
103
+ * Path to the client that will be used to do the API calls.
104
+ * It will be used as `import client from '${client.importPath}'`.
105
+ * It allows both relative and absolute path.
106
+ * the path will be applied as is, so relative path should be based on the file being generated.
107
+ * @default '@kubb/plugin-client/client'
108
+ */
109
+ importPath?: string;
110
+ /**
111
+ * ReturnType that needs to be used when calling client().
112
+ *
113
+ * `Data` will return ResponseConfig[data].
114
+ *
115
+ * `Full` will return ResponseConfig.
116
+ * @default `'data'`
117
+ * @private
118
+ */
119
+ dataReturnType?: 'data' | 'full';
120
+ };
121
+ /**
122
+ * ReturnType that needs to be used when calling client().
123
+ *
124
+ * `Data` will return ResponseConfig[data].
125
+ *
126
+ * `Full` will return ResponseConfig.
127
+ * @default `'data'`
128
+ * @private
129
+ */
130
+ /**
131
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
132
+ */
133
+ exclude?: Array<Exclude>;
134
+ /**
135
+ * Array containing include parameters to include tags/operations/methods/paths.
136
+ */
137
+ include?: Array<Include>;
138
+ /**
139
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
140
+ */
141
+ override?: Array<Override<ResolvedOptions>>;
142
+ /**
143
+ * How to pass your pathParams.
144
+ *
145
+ * `object` will return the pathParams as an object.
146
+ *
147
+ * `inline` will return the pathParams as comma separated params.
148
+ * @default `'inline'`
149
+ * @private
150
+ */
151
+ pathParamsType?: 'object' | 'inline';
152
+ /**
153
+ * When set, an infiniteQuery hooks will be added.
154
+ */
155
+ infinite?: Partial<Infinite> | false;
156
+ /**
157
+ * When set, a suspenseQuery hooks will be added.
158
+ */
159
+ suspense?: Partial<Suspense> | false;
160
+ /**
161
+ * Override some useQuery behaviours.
162
+ */
163
+ query?: Partial<Query> | false;
164
+ /**
165
+ * Override some useMutation behaviours.
166
+ */
167
+ mutation?: Mutation | false;
168
+ /**
169
+ * Which parser can be used before returning the data to `@tanstack/query`.
170
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
171
+ */
172
+ parser?: 'client' | 'zod';
173
+ transformers?: {
174
+ /**
175
+ * Customize the names based on the type that is provided by the plugin.
176
+ */
177
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
178
+ };
179
+ };
180
+ type ResolvedOptions = {
181
+ baseURL: string | undefined;
182
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
183
+ parser: Required<NonNullable<Options['parser']>>;
184
+ pathParamsType: NonNullable<Options['pathParamsType']>;
185
+ /**
186
+ * Only used of infinite
187
+ */
188
+ infinite: NonNullable<Infinite> | false;
189
+ suspense: Suspense | false;
190
+ query: NonNullable<Required<Query>> | false;
191
+ mutation: NonNullable<Required<Mutation>> | false;
192
+ };
193
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
194
+
195
+ export type { Infinite as I, Options as O, PluginReactQuery as P };
@@ -0,0 +1,195 @@
1
+ import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
+ import * as KubbFile from '@kubb/fs/types';
3
+ import { HttpMethod } from '@kubb/oas';
4
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
+
6
+ type Suspense = object;
7
+ type Query = {
8
+ /**
9
+ * Customize the queryKey, here you can specify a suffix.
10
+ */
11
+ key: (key: unknown[]) => unknown[];
12
+ /**
13
+ * Define which HttpMethods can be used for queries
14
+ * @default ['get']
15
+ */
16
+ methods: Array<HttpMethod>;
17
+ /**
18
+ * Path to the useQuery that will be used to do the useQuery functionality.
19
+ * It will be used as `import { useQuery } from '${importPath}'`.
20
+ * It allows both relative and absolute path.
21
+ * the path will be applied as is, so relative path should be based on the file being generated.
22
+ * @default '@tanstack/react-query'
23
+ */
24
+ importPath?: string;
25
+ };
26
+ type Mutation = {
27
+ /**
28
+ * Define which HttpMethods can be used for mutations
29
+ * @default ['post', 'put', 'delete']
30
+ */
31
+ methods: Array<HttpMethod>;
32
+ /**
33
+ * Path to the useQuery that will be used to do the useQuery functionality.
34
+ * It will be used as `import { useQuery } from '${importPath}'`.
35
+ * It allows both relative and absolute path.
36
+ * the path will be applied as is, so relative path should be based on the file being generated.
37
+ * @default '@tanstack/react-query'
38
+ */
39
+ importPath?: string;
40
+ };
41
+ type Infinite = {
42
+ /**
43
+ * Specify the params key used for `pageParam`.
44
+ * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
45
+ * @default `'id'`
46
+ */
47
+ queryParam: string;
48
+ /**
49
+ * Which field of the data will be used, set it to undefined when no cursor is known.
50
+ */
51
+ cursorParam?: string | undefined;
52
+ /**
53
+ * The initial value, the value of the first page.
54
+ * @default `0`
55
+ */
56
+ initialPageParam: unknown;
57
+ };
58
+ type Options = {
59
+ output?: {
60
+ /**
61
+ * Output to save the @tanstack/query hooks.
62
+ * @default `"hooks"`
63
+ */
64
+ path: string;
65
+ /**
66
+ * Name to be used for the `export * as {{exportAs}} from './'`
67
+ */
68
+ exportAs?: string;
69
+ /**
70
+ * Add an extension to the generated imports and exports, default it will not use an extension
71
+ */
72
+ extName?: KubbFile.Extname;
73
+ /**
74
+ * Define what needs to exported, here you can also disable the export of barrel files
75
+ * @default `'barrel'`
76
+ */
77
+ exportType?: 'barrel' | 'barrelNamed' | false;
78
+ };
79
+ /**
80
+ * Group the @tanstack/query hooks based on the provided name.
81
+ */
82
+ group?: {
83
+ /**
84
+ * Tag will group based on the operation tag inside the Swagger file
85
+ */
86
+ type: 'tag';
87
+ /**
88
+ * Relative path to save the grouped @tanstack/query hooks.
89
+ *
90
+ * `{{tag}}` will be replaced by the current tagName.
91
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
92
+ * @default `${output}/{{tag}}Controller`
93
+ */
94
+ output?: string;
95
+ /**
96
+ * Name to be used for the `export * as {{exportAs}} from './`
97
+ * @default `"{{tag}}Hooks"`
98
+ */
99
+ exportAs?: string;
100
+ };
101
+ client?: {
102
+ /**
103
+ * Path to the client that will be used to do the API calls.
104
+ * It will be used as `import client from '${client.importPath}'`.
105
+ * It allows both relative and absolute path.
106
+ * the path will be applied as is, so relative path should be based on the file being generated.
107
+ * @default '@kubb/plugin-client/client'
108
+ */
109
+ importPath?: string;
110
+ /**
111
+ * ReturnType that needs to be used when calling client().
112
+ *
113
+ * `Data` will return ResponseConfig[data].
114
+ *
115
+ * `Full` will return ResponseConfig.
116
+ * @default `'data'`
117
+ * @private
118
+ */
119
+ dataReturnType?: 'data' | 'full';
120
+ };
121
+ /**
122
+ * ReturnType that needs to be used when calling client().
123
+ *
124
+ * `Data` will return ResponseConfig[data].
125
+ *
126
+ * `Full` will return ResponseConfig.
127
+ * @default `'data'`
128
+ * @private
129
+ */
130
+ /**
131
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
132
+ */
133
+ exclude?: Array<Exclude>;
134
+ /**
135
+ * Array containing include parameters to include tags/operations/methods/paths.
136
+ */
137
+ include?: Array<Include>;
138
+ /**
139
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
140
+ */
141
+ override?: Array<Override<ResolvedOptions>>;
142
+ /**
143
+ * How to pass your pathParams.
144
+ *
145
+ * `object` will return the pathParams as an object.
146
+ *
147
+ * `inline` will return the pathParams as comma separated params.
148
+ * @default `'inline'`
149
+ * @private
150
+ */
151
+ pathParamsType?: 'object' | 'inline';
152
+ /**
153
+ * When set, an infiniteQuery hooks will be added.
154
+ */
155
+ infinite?: Partial<Infinite> | false;
156
+ /**
157
+ * When set, a suspenseQuery hooks will be added.
158
+ */
159
+ suspense?: Partial<Suspense> | false;
160
+ /**
161
+ * Override some useQuery behaviours.
162
+ */
163
+ query?: Partial<Query> | false;
164
+ /**
165
+ * Override some useMutation behaviours.
166
+ */
167
+ mutation?: Mutation | false;
168
+ /**
169
+ * Which parser can be used before returning the data to `@tanstack/query`.
170
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
171
+ */
172
+ parser?: 'client' | 'zod';
173
+ transformers?: {
174
+ /**
175
+ * Customize the names based on the type that is provided by the plugin.
176
+ */
177
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
178
+ };
179
+ };
180
+ type ResolvedOptions = {
181
+ baseURL: string | undefined;
182
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
183
+ parser: Required<NonNullable<Options['parser']>>;
184
+ pathParamsType: NonNullable<Options['pathParamsType']>;
185
+ /**
186
+ * Only used of infinite
187
+ */
188
+ infinite: NonNullable<Infinite> | false;
189
+ suspense: Suspense | false;
190
+ query: NonNullable<Required<Query>> | false;
191
+ mutation: NonNullable<Required<Mutation>> | false;
192
+ };
193
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
194
+
195
+ export type { Infinite as I, Options as O, PluginReactQuery as P };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "3.0.0-alpha.14",
3
+ "version": "3.0.0-alpha.16",
4
4
  "description": "Generator react-query hooks",
5
5
  "keywords": [
6
6
  "faker",
@@ -29,6 +29,11 @@
29
29
  "require": "./dist/index.cjs",
30
30
  "default": "./dist/index.cjs"
31
31
  },
32
+ "./generators": {
33
+ "import": "./dist/generators.js",
34
+ "require": "./dist/generators.cjs",
35
+ "default": "./dist/generators.cjs"
36
+ },
32
37
  "./components": {
33
38
  "import": "./dist/components.js",
34
39
  "require": "./dist/components.cjs",
@@ -44,6 +49,9 @@
44
49
  "*": {
45
50
  "components": [
46
51
  "./dist/components.d.ts"
52
+ ],
53
+ "generators": [
54
+ "./dist/generators.d.ts"
47
55
  ]
48
56
  }
49
57
  },
@@ -54,27 +62,27 @@
54
62
  "!/**/__tests__/**"
55
63
  ],
56
64
  "dependencies": {
57
- "@kubb/core": "3.0.0-alpha.14",
58
- "@kubb/fs": "3.0.0-alpha.14",
59
- "@kubb/oas": "3.0.0-alpha.14",
60
- "@kubb/parser-ts": "3.0.0-alpha.14",
61
- "@kubb/plugin-faker": "3.0.0-alpha.14",
62
- "@kubb/plugin-oas": "3.0.0-alpha.14",
63
- "@kubb/plugin-ts": "3.0.0-alpha.14",
64
- "@kubb/plugin-zod": "3.0.0-alpha.14",
65
- "@kubb/react": "3.0.0-alpha.14"
65
+ "@kubb/core": "3.0.0-alpha.16",
66
+ "@kubb/fs": "3.0.0-alpha.16",
67
+ "@kubb/oas": "3.0.0-alpha.16",
68
+ "@kubb/parser-ts": "3.0.0-alpha.16",
69
+ "@kubb/plugin-faker": "3.0.0-alpha.16",
70
+ "@kubb/plugin-oas": "3.0.0-alpha.16",
71
+ "@kubb/plugin-ts": "3.0.0-alpha.16",
72
+ "@kubb/plugin-zod": "3.0.0-alpha.16",
73
+ "@kubb/react": "3.0.0-alpha.16"
66
74
  },
67
75
  "devDependencies": {
68
76
  "@types/react": "^18.3.5",
69
77
  "react": "^18.3.1",
70
78
  "tsup": "^8.2.4",
71
- "typescript": "^5.5.4",
72
- "@kubb/config-biome": "3.0.0-alpha.14",
73
- "@kubb/config-ts": "3.0.0-alpha.14",
74
- "@kubb/config-tsup": "3.0.0-alpha.14"
79
+ "typescript": "^5.6.2",
80
+ "@kubb/config-biome": "3.0.0-alpha.16",
81
+ "@kubb/config-ts": "3.0.0-alpha.16",
82
+ "@kubb/config-tsup": "3.0.0-alpha.16"
75
83
  },
76
84
  "peerDependencies": {
77
- "@kubb/react": "3.0.0-alpha.14"
85
+ "@kubb/react": "3.0.0-alpha.16"
78
86
  },
79
87
  "engines": {
80
88
  "node": ">=20"
@@ -0,0 +1,129 @@
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 { PluginReactQuery } 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
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
22
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
23
+ }
24
+
25
+ type GetParamsProps = {
26
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
27
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
28
+ typeSchemas: OperationSchemas
29
+ }
30
+
31
+ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
32
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
33
+
34
+ return FunctionParams.factory({
35
+ pathParams: {
36
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
37
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
38
+ },
39
+ data: typeSchemas.request?.name
40
+ ? {
41
+ type: typeSchemas.request?.name,
42
+ optional: isOptional(typeSchemas.request?.schema),
43
+ }
44
+ : undefined,
45
+ params: typeSchemas.queryParams?.name
46
+ ? {
47
+ type: typeSchemas.queryParams?.name,
48
+ optional: isOptional(typeSchemas.queryParams?.schema),
49
+ }
50
+ : undefined,
51
+ headers: typeSchemas.headerParams?.name
52
+ ? {
53
+ type: typeSchemas.headerParams?.name,
54
+ optional: isOptional(typeSchemas.headerParams?.schema),
55
+ }
56
+ : undefined,
57
+ options: {
58
+ type: `
59
+ {
60
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
61
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
62
+ }
63
+ `,
64
+ default: '{}',
65
+ },
66
+ })
67
+ }
68
+
69
+ export function InfiniteQuery({
70
+ name,
71
+ queryKeyTypeName,
72
+ queryOptionsName,
73
+ queryKeyName,
74
+ pathParamsType,
75
+ dataReturnType,
76
+ typeSchemas,
77
+ operation,
78
+ }: Props): ReactNode {
79
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
80
+ const returnType = `UseInfiniteQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown'].join(', ')}> & { queryKey: TQueryKey }`
81
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
82
+
83
+ const queryKeyParams = QueryKey.getParams({
84
+ pathParamsType,
85
+ typeSchemas,
86
+ })
87
+ const queryOptionsParams = QueryOptions.getParams({
88
+ pathParamsType,
89
+ typeSchemas,
90
+ })
91
+ const params = getParams({
92
+ pathParamsType,
93
+ dataReturnType,
94
+ typeSchemas,
95
+ })
96
+
97
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as InfiniteQueryObserverOptions`
98
+
99
+ return (
100
+ <File.Source name={name} isExportable isIndexable>
101
+ <Function
102
+ name={name}
103
+ export
104
+ generics={generics.join(', ')}
105
+ params={params.toConstructor()}
106
+ JSDoc={{
107
+ comments: getComments(operation),
108
+ }}
109
+ >
110
+ {`
111
+ const { query: queryOptions, client: config = {} } = options ?? {}
112
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
113
+
114
+ const query = useInfiniteQuery({
115
+ ...${queryOptions},
116
+ queryKey,
117
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
118
+ }) as ${returnType}
119
+
120
+ query.queryKey = queryKey as TQueryKey
121
+
122
+ return query
123
+ `}
124
+ </Function>
125
+ </File.Source>
126
+ )
127
+ }
128
+
129
+ InfiniteQuery.getParams = getParams