@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2

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 (78) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-37VO6QXJ.cjs +669 -0
  3. package/dist/chunk-37VO6QXJ.cjs.map +1 -0
  4. package/dist/chunk-C2H3KPHM.cjs +658 -0
  5. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  6. package/dist/chunk-IRW2Y3EC.js +660 -0
  7. package/dist/chunk-IRW2Y3EC.js.map +1 -0
  8. package/dist/chunk-Y3DM2P6L.js +647 -0
  9. package/dist/chunk-Y3DM2P6L.js.map +1 -0
  10. package/dist/components.cjs +39 -12
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -6
  13. package/dist/components.d.ts +161 -6
  14. package/dist/components.js +2 -12
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +78 -130
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +61 -120
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-5pnOmDmM.d.cts +231 -0
  29. package/dist/types-5pnOmDmM.d.ts +231 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +130 -0
  33. package/src/components/Mutation.tsx +137 -321
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -594
  36. package/src/components/QueryKey.tsx +51 -182
  37. package/src/components/QueryOptions.tsx +71 -473
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -0
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  43. package/src/generators/__snapshots__/findByTags.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  46. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  47. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  48. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  49. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
  53. package/src/generators/index.ts +4 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  55. package/src/generators/mutationGenerator.tsx +108 -0
  56. package/src/generators/queryGenerator.tsx +121 -0
  57. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  58. package/src/plugin.ts +60 -76
  59. package/src/types.ts +42 -115
  60. package/dist/chunk-7ZODZVKP.cjs +0 -1470
  61. package/dist/chunk-7ZODZVKP.cjs.map +0 -1
  62. package/dist/chunk-ZYTZV43V.js +0 -1470
  63. package/dist/chunk-ZYTZV43V.js.map +0 -1
  64. package/dist/index-5kpkk-7M.d.cts +0 -545
  65. package/dist/index-5kpkk-7M.d.ts +0 -545
  66. package/src/OperationGenerator.tsx +0 -57
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  72. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  73. package/src/components/QueryImports.tsx +0 -167
  74. package/src/components/SchemaType.tsx +0 -59
  75. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  76. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  77. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
  78. package/src/utils.ts +0 -96
@@ -0,0 +1,231 @@
1
+ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
4
+
5
+ type Options$1 = {
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$1>>;
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
+ * ReturnType that will be used when calling the client.
41
+ *
42
+ * `Data` will return ResponseConfig[data].
43
+ *
44
+ * `Full` will return ResponseConfig.
45
+ * @default `'data'`
46
+ * @private
47
+ */
48
+ dataReturnType?: 'data' | 'full';
49
+ /**
50
+ * How to pass your pathParams.
51
+ *
52
+ * `object` will return the pathParams as an object.
53
+ *
54
+ * `inline` will return the pathParams as comma separated params.
55
+ * @default `'inline'`
56
+ * @private
57
+ */
58
+ pathParamsType?: 'object' | 'inline';
59
+ /**
60
+ * Which parser can be used before returning the data
61
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
62
+ * @default 'client'
63
+ */
64
+ parser?: 'client' | 'zod';
65
+ transformers?: {
66
+ /**
67
+ * Customize the names based on the type that is provided by the plugin.
68
+ */
69
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
70
+ };
71
+ /**
72
+ * Define some generators next to the client generators
73
+ */
74
+ generators?: Array<Generator<PluginClient>>;
75
+ };
76
+ type ResolvedOptions$1 = {
77
+ output: Output;
78
+ group?: Options$1['group'];
79
+ baseURL: string | undefined;
80
+ parser: NonNullable<Options$1['parser']>;
81
+ importPath: NonNullable<Options$1['importPath']>;
82
+ dataReturnType: NonNullable<Options$1['dataReturnType']>;
83
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
84
+ };
85
+ type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
86
+
87
+ type Suspense = object;
88
+ type Query = {
89
+ /**
90
+ * Customize the queryKey, here you can specify a suffix.
91
+ */
92
+ key: (key: unknown[]) => unknown[];
93
+ /**
94
+ * Define which HttpMethods can be used for queries
95
+ * @default ['get']
96
+ */
97
+ methods: Array<HttpMethod>;
98
+ /**
99
+ * Path to the useQuery that will be used to do the useQuery functionality.
100
+ * It will be used as `import { useQuery } from '${importPath}'`.
101
+ * It allows both relative and absolute path.
102
+ * the path will be applied as is, so relative path should be based on the file being generated.
103
+ * @default '@tanstack/react-query'
104
+ */
105
+ importPath?: string;
106
+ };
107
+ type Mutation = {
108
+ /**
109
+ * Customize the queryKey, here you can specify a suffix.
110
+ */
111
+ key: (key: unknown[]) => unknown[];
112
+ /**
113
+ * Define which HttpMethods can be used for mutations
114
+ * @default ['post', 'put', 'delete']
115
+ */
116
+ methods: Array<HttpMethod>;
117
+ /**
118
+ * Path to the useQuery that will be used to do the useQuery functionality.
119
+ * It will be used as `import { useQuery } from '${importPath}'`.
120
+ * It allows both relative and absolute path.
121
+ * the path will be applied as is, so relative path should be based on the file being generated.
122
+ * @default '@tanstack/react-query'
123
+ */
124
+ importPath?: string;
125
+ };
126
+ type Infinite = {
127
+ /**
128
+ * Specify the params key used for `pageParam`.
129
+ * @default `'id'`
130
+ */
131
+ queryParam: string;
132
+ /**
133
+ * Which field of the data will be used, set it to undefined when no cursor is known.
134
+ */
135
+ cursorParam?: string | undefined;
136
+ /**
137
+ * The initial value, the value of the first page.
138
+ * @default `0`
139
+ */
140
+ initialPageParam: unknown;
141
+ };
142
+ type Options = {
143
+ /**
144
+ * @default 'hooks'
145
+ */
146
+ output?: Output;
147
+ /**
148
+ * Group the @tanstack/query hooks based on the provided name.
149
+ */
150
+ group?: Group;
151
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
152
+ /**
153
+ * ReturnType that needs to be used when calling client().
154
+ *
155
+ * `Data` will return ResponseConfig[data].
156
+ *
157
+ * `Full` will return ResponseConfig.
158
+ * @default `'data'`
159
+ * @private
160
+ */
161
+ /**
162
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
163
+ */
164
+ exclude?: Array<Exclude>;
165
+ /**
166
+ * Array containing include parameters to include tags/operations/methods/paths.
167
+ */
168
+ include?: Array<Include>;
169
+ /**
170
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
171
+ */
172
+ override?: Array<Override<ResolvedOptions>>;
173
+ /**
174
+ * How to pass your pathParams.
175
+ *
176
+ * `object` will return the pathParams as an object.
177
+ *
178
+ * `inline` will return the pathParams as comma separated params.
179
+ * @default `'inline'`
180
+ * @private
181
+ */
182
+ pathParamsType?: PluginClient['options']['pathParamsType'];
183
+ /**
184
+ * When set, an infiniteQuery hooks will be added.
185
+ */
186
+ infinite?: Partial<Infinite> | false;
187
+ /**
188
+ * When set, a suspenseQuery hooks will be added.
189
+ */
190
+ suspense?: Partial<Suspense> | false;
191
+ /**
192
+ * Override some useQuery behaviours.
193
+ */
194
+ query?: Partial<Query> | false;
195
+ /**
196
+ * Override some useMutation behaviours.
197
+ */
198
+ mutation?: Mutation | false;
199
+ /**
200
+ * Which parser can be used before returning the data to `@tanstack/query`.
201
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
202
+ */
203
+ parser?: PluginClient['options']['parser'];
204
+ transformers?: {
205
+ /**
206
+ * Customize the names based on the type that is provided by the plugin.
207
+ */
208
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
209
+ };
210
+ /**
211
+ * Define some generators next to the react-query generators
212
+ */
213
+ generators?: Array<Generator<PluginReactQuery>>;
214
+ };
215
+ type ResolvedOptions = {
216
+ output: Output;
217
+ baseURL: string | undefined;
218
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
219
+ parser: Required<NonNullable<Options['parser']>>;
220
+ pathParamsType: NonNullable<Options['pathParamsType']>;
221
+ /**
222
+ * Only used of infinite
223
+ */
224
+ infinite: NonNullable<Infinite> | false;
225
+ suspense: Suspense | false;
226
+ query: NonNullable<Required<Query>> | false;
227
+ mutation: NonNullable<Required<Mutation>> | false;
228
+ };
229
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
230
+
231
+ export type { Infinite as I, Options as O, PluginReactQuery as P };
@@ -0,0 +1,231 @@
1
+ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
4
+
5
+ type Options$1 = {
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$1>>;
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
+ * ReturnType that will be used when calling the client.
41
+ *
42
+ * `Data` will return ResponseConfig[data].
43
+ *
44
+ * `Full` will return ResponseConfig.
45
+ * @default `'data'`
46
+ * @private
47
+ */
48
+ dataReturnType?: 'data' | 'full';
49
+ /**
50
+ * How to pass your pathParams.
51
+ *
52
+ * `object` will return the pathParams as an object.
53
+ *
54
+ * `inline` will return the pathParams as comma separated params.
55
+ * @default `'inline'`
56
+ * @private
57
+ */
58
+ pathParamsType?: 'object' | 'inline';
59
+ /**
60
+ * Which parser can be used before returning the data
61
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
62
+ * @default 'client'
63
+ */
64
+ parser?: 'client' | 'zod';
65
+ transformers?: {
66
+ /**
67
+ * Customize the names based on the type that is provided by the plugin.
68
+ */
69
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
70
+ };
71
+ /**
72
+ * Define some generators next to the client generators
73
+ */
74
+ generators?: Array<Generator<PluginClient>>;
75
+ };
76
+ type ResolvedOptions$1 = {
77
+ output: Output;
78
+ group?: Options$1['group'];
79
+ baseURL: string | undefined;
80
+ parser: NonNullable<Options$1['parser']>;
81
+ importPath: NonNullable<Options$1['importPath']>;
82
+ dataReturnType: NonNullable<Options$1['dataReturnType']>;
83
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
84
+ };
85
+ type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
86
+
87
+ type Suspense = object;
88
+ type Query = {
89
+ /**
90
+ * Customize the queryKey, here you can specify a suffix.
91
+ */
92
+ key: (key: unknown[]) => unknown[];
93
+ /**
94
+ * Define which HttpMethods can be used for queries
95
+ * @default ['get']
96
+ */
97
+ methods: Array<HttpMethod>;
98
+ /**
99
+ * Path to the useQuery that will be used to do the useQuery functionality.
100
+ * It will be used as `import { useQuery } from '${importPath}'`.
101
+ * It allows both relative and absolute path.
102
+ * the path will be applied as is, so relative path should be based on the file being generated.
103
+ * @default '@tanstack/react-query'
104
+ */
105
+ importPath?: string;
106
+ };
107
+ type Mutation = {
108
+ /**
109
+ * Customize the queryKey, here you can specify a suffix.
110
+ */
111
+ key: (key: unknown[]) => unknown[];
112
+ /**
113
+ * Define which HttpMethods can be used for mutations
114
+ * @default ['post', 'put', 'delete']
115
+ */
116
+ methods: Array<HttpMethod>;
117
+ /**
118
+ * Path to the useQuery that will be used to do the useQuery functionality.
119
+ * It will be used as `import { useQuery } from '${importPath}'`.
120
+ * It allows both relative and absolute path.
121
+ * the path will be applied as is, so relative path should be based on the file being generated.
122
+ * @default '@tanstack/react-query'
123
+ */
124
+ importPath?: string;
125
+ };
126
+ type Infinite = {
127
+ /**
128
+ * Specify the params key used for `pageParam`.
129
+ * @default `'id'`
130
+ */
131
+ queryParam: string;
132
+ /**
133
+ * Which field of the data will be used, set it to undefined when no cursor is known.
134
+ */
135
+ cursorParam?: string | undefined;
136
+ /**
137
+ * The initial value, the value of the first page.
138
+ * @default `0`
139
+ */
140
+ initialPageParam: unknown;
141
+ };
142
+ type Options = {
143
+ /**
144
+ * @default 'hooks'
145
+ */
146
+ output?: Output;
147
+ /**
148
+ * Group the @tanstack/query hooks based on the provided name.
149
+ */
150
+ group?: Group;
151
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
152
+ /**
153
+ * ReturnType that needs to be used when calling client().
154
+ *
155
+ * `Data` will return ResponseConfig[data].
156
+ *
157
+ * `Full` will return ResponseConfig.
158
+ * @default `'data'`
159
+ * @private
160
+ */
161
+ /**
162
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
163
+ */
164
+ exclude?: Array<Exclude>;
165
+ /**
166
+ * Array containing include parameters to include tags/operations/methods/paths.
167
+ */
168
+ include?: Array<Include>;
169
+ /**
170
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
171
+ */
172
+ override?: Array<Override<ResolvedOptions>>;
173
+ /**
174
+ * How to pass your pathParams.
175
+ *
176
+ * `object` will return the pathParams as an object.
177
+ *
178
+ * `inline` will return the pathParams as comma separated params.
179
+ * @default `'inline'`
180
+ * @private
181
+ */
182
+ pathParamsType?: PluginClient['options']['pathParamsType'];
183
+ /**
184
+ * When set, an infiniteQuery hooks will be added.
185
+ */
186
+ infinite?: Partial<Infinite> | false;
187
+ /**
188
+ * When set, a suspenseQuery hooks will be added.
189
+ */
190
+ suspense?: Partial<Suspense> | false;
191
+ /**
192
+ * Override some useQuery behaviours.
193
+ */
194
+ query?: Partial<Query> | false;
195
+ /**
196
+ * Override some useMutation behaviours.
197
+ */
198
+ mutation?: Mutation | false;
199
+ /**
200
+ * Which parser can be used before returning the data to `@tanstack/query`.
201
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
202
+ */
203
+ parser?: PluginClient['options']['parser'];
204
+ transformers?: {
205
+ /**
206
+ * Customize the names based on the type that is provided by the plugin.
207
+ */
208
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
209
+ };
210
+ /**
211
+ * Define some generators next to the react-query generators
212
+ */
213
+ generators?: Array<Generator<PluginReactQuery>>;
214
+ };
215
+ type ResolvedOptions = {
216
+ output: Output;
217
+ baseURL: string | undefined;
218
+ client: Required<NonNullable<PluginReactQuery['options']['client']>>;
219
+ parser: Required<NonNullable<Options['parser']>>;
220
+ pathParamsType: NonNullable<Options['pathParamsType']>;
221
+ /**
222
+ * Only used of infinite
223
+ */
224
+ infinite: NonNullable<Infinite> | false;
225
+ suspense: Suspense | false;
226
+ query: NonNullable<Required<Query>> | false;
227
+ mutation: NonNullable<Required<Mutation>> | false;
228
+ };
229
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
230
+
231
+ 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.9",
3
+ "version": "3.0.0-beta.2",
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,24 @@
54
62
  "!/**/__tests__/**"
55
63
  ],
56
64
  "dependencies": {
57
- "@kubb/core": "3.0.0-alpha.9",
58
- "@kubb/fs": "3.0.0-alpha.9",
59
- "@kubb/oas": "3.0.0-alpha.9",
60
- "@kubb/plugin-faker": "3.0.0-alpha.9",
61
- "@kubb/parser-ts": "3.0.0-alpha.9",
62
- "@kubb/plugin-oas": "3.0.0-alpha.9",
63
- "@kubb/plugin-ts": "3.0.0-alpha.9",
64
- "@kubb/plugin-zod": "3.0.0-alpha.9",
65
- "@kubb/react": "3.0.0-alpha.9"
65
+ "@kubb/core": "3.0.0-beta.2",
66
+ "@kubb/fs": "3.0.0-beta.2",
67
+ "@kubb/oas": "3.0.0-beta.2",
68
+ "@kubb/plugin-oas": "3.0.0-beta.2",
69
+ "@kubb/plugin-ts": "3.0.0-beta.2",
70
+ "@kubb/plugin-zod": "3.0.0-beta.2",
71
+ "@kubb/react": "3.0.0-beta.2"
66
72
  },
67
73
  "devDependencies": {
68
- "@types/react": "^18.3.4",
74
+ "@types/react": "^18.3.11",
69
75
  "react": "^18.3.1",
70
- "tsup": "^8.2.4",
71
- "typescript": "^5.5.4",
72
- "@kubb/config-biome": "3.0.0-alpha.9",
73
- "@kubb/config-ts": "3.0.0-alpha.9",
74
- "@kubb/config-tsup": "3.0.0-alpha.9"
76
+ "tsup": "^8.3.0",
77
+ "typescript": "^5.6.2",
78
+ "@kubb/config-ts": "3.0.0-beta.2",
79
+ "@kubb/config-tsup": "3.0.0-beta.2"
75
80
  },
76
81
  "peerDependencies": {
77
- "@kubb/react": "3.0.0-alpha.9"
82
+ "@kubb/react": "3.0.0-beta.2"
78
83
  },
79
84
  "engines": {
80
85
  "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(' | ') || 'Error', '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(' | ') || 'Error'].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