@kubb/plugin-react-query 5.0.0-alpha.9 → 5.0.0-beta.100

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 (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -93
  3. package/dist/index.cjs +2317 -149
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +494 -6
  6. package/dist/index.js +2283 -143
  7. package/dist/index.js.map +1 -1
  8. package/package.json +47 -75
  9. package/dist/components-BHQT9ZLc.cjs +0 -1634
  10. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  11. package/dist/components-CpyHYGOw.js +0 -1520
  12. package/dist/components-CpyHYGOw.js.map +0 -1
  13. package/dist/components.cjs +0 -13
  14. package/dist/components.d.ts +0 -398
  15. package/dist/components.js +0 -2
  16. package/dist/generators-DP07m3rH.cjs +0 -1469
  17. package/dist/generators-DP07m3rH.cjs.map +0 -1
  18. package/dist/generators-DkQwKTc2.js +0 -1427
  19. package/dist/generators-DkQwKTc2.js.map +0 -1
  20. package/dist/generators.cjs +0 -9
  21. package/dist/generators.d.ts +0 -523
  22. package/dist/generators.js +0 -2
  23. package/dist/types-D5S7Ny9r.d.ts +0 -270
  24. package/src/components/InfiniteQuery.tsx +0 -220
  25. package/src/components/InfiniteQueryOptions.tsx +0 -289
  26. package/src/components/Mutation.tsx +0 -158
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/MutationOptions.tsx +0 -122
  29. package/src/components/Query.tsx +0 -194
  30. package/src/components/QueryKey.tsx +0 -1
  31. package/src/components/QueryOptions.tsx +0 -181
  32. package/src/components/SuspenseInfiniteQuery.tsx +0 -220
  33. package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -289
  34. package/src/components/SuspenseQuery.tsx +0 -204
  35. package/src/components/index.ts +0 -11
  36. package/src/generators/customHookOptionsFileGenerator.tsx +0 -98
  37. package/src/generators/hookOptionsGenerator.tsx +0 -196
  38. package/src/generators/index.ts +0 -7
  39. package/src/generators/infiniteQueryGenerator.tsx +0 -214
  40. package/src/generators/mutationGenerator.tsx +0 -195
  41. package/src/generators/queryGenerator.tsx +0 -194
  42. package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -202
  43. package/src/generators/suspenseQueryGenerator.tsx +0 -207
  44. package/src/index.ts +0 -2
  45. package/src/plugin.ts +0 -239
  46. package/src/types.ts +0 -205
  47. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -1,270 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
3
- import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
4
- import { Exclude, Include, OperationSchemas, Override, ResolvePathOptions } from "@kubb/plugin-oas";
5
- import { HttpMethod, Oas, Operation, contentType } from "@kubb/oas";
6
- import { FunctionParams } from "@kubb/react-fabric";
7
- import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
8
- import { FabricReactNode } from "@kubb/react-fabric/types";
9
-
10
- //#region ../../internals/tanstack-query/src/types.d.ts
11
- type ParamsCasing = 'camelcase' | undefined;
12
- type PathParamsType = 'object' | 'inline';
13
- type TransformerProps = {
14
- operation: Operation;
15
- schemas: OperationSchemas;
16
- casing: ParamsCasing;
17
- };
18
- type Transformer = (props: TransformerProps) => unknown[];
19
- //#endregion
20
- //#region ../../internals/tanstack-query/src/components/MutationKey.d.ts
21
- type Props$1 = {
22
- name: string;
23
- typeName: string;
24
- typeSchemas: OperationSchemas;
25
- operation: Operation;
26
- paramsCasing: ParamsCasing;
27
- pathParamsType: PathParamsType;
28
- transformer: Transformer | undefined;
29
- };
30
- type GetParamsProps$1 = {
31
- pathParamsType: PathParamsType;
32
- typeSchemas: OperationSchemas;
33
- };
34
- declare function MutationKey$1({
35
- name,
36
- typeSchemas,
37
- pathParamsType,
38
- paramsCasing,
39
- operation,
40
- typeName,
41
- transformer
42
- }: Props$1): FabricReactNode;
43
- declare namespace MutationKey$1 {
44
- var getParams: ({}: GetParamsProps$1) => FunctionParams;
45
- var getTransformer: Transformer;
46
- }
47
- //#endregion
48
- //#region ../../internals/tanstack-query/src/components/QueryKey.d.ts
49
- type Props = {
50
- name: string;
51
- typeName: string;
52
- typeSchemas: OperationSchemas;
53
- operation: Operation;
54
- paramsCasing: ParamsCasing;
55
- pathParamsType: PathParamsType;
56
- transformer: Transformer | undefined;
57
- };
58
- type GetParamsProps = {
59
- paramsCasing: ParamsCasing;
60
- pathParamsType: PathParamsType;
61
- typeSchemas: OperationSchemas;
62
- };
63
- declare function QueryKey$1({
64
- name,
65
- typeSchemas,
66
- paramsCasing,
67
- pathParamsType,
68
- operation,
69
- typeName,
70
- transformer
71
- }: Props): FabricReactNode;
72
- declare namespace QueryKey$1 {
73
- var getParams: ({
74
- pathParamsType,
75
- paramsCasing,
76
- typeSchemas
77
- }: GetParamsProps) => FunctionParams;
78
- var getTransformer: Transformer;
79
- }
80
- //#endregion
81
- //#region src/types.d.ts
82
- type Suspense = object;
83
- /**
84
- * Customize the queryKey
85
- */
86
- type QueryKey = Transformer;
87
- /**
88
- * Customize the mutationKey
89
- */
90
- type MutationKey = Transformer;
91
- type Query = {
92
- /**
93
- * Define which HttpMethods can be used for queries
94
- * @default ['get']
95
- */
96
- methods: Array<HttpMethod>;
97
- /**
98
- * Path to the useQuery hook for useQuery functionality.
99
- * Used as `import { useQuery } from '${importPath}'`.
100
- * Accepts relative and absolute paths.
101
- * Path is used as-is; relative paths are based on the generated file location.
102
- * @default '@tanstack/react-query'
103
- */
104
- importPath?: string;
105
- };
106
- type Mutation = {
107
- /**
108
- * Define which HttpMethods can be used for mutations
109
- * @default ['post', 'put', 'delete']
110
- */
111
- methods: Array<HttpMethod>;
112
- /**
113
- * Path to the useQuery hook for useQuery functionality.
114
- * Used as `import { useQuery } from '${importPath}'`.
115
- * Accepts relative and absolute paths.
116
- * Path is used as-is; relative paths are based on the generated file location.
117
- * @default '@tanstack/react-query'
118
- */
119
- importPath?: string;
120
- };
121
- type Infinite = {
122
- /**
123
- * Specify the params key used for `pageParam`.
124
- * @default 'id'
125
- */
126
- queryParam: string;
127
- /**
128
- * Which field of the data is used, set it to undefined when no cursor is known.
129
- * @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
130
- */
131
- cursorParam?: string | undefined;
132
- /**
133
- * Which field of the data is used to get the cursor for the next page.
134
- * Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
135
- */
136
- nextParam?: string | string[] | undefined;
137
- /**
138
- * Which field of the data is used to get the cursor for the previous page.
139
- * Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
140
- */
141
- previousParam?: string | string[] | undefined;
142
- /**
143
- * The initial value, the value of the first page.
144
- * @default 0
145
- */
146
- initialPageParam: unknown;
147
- };
148
- type CustomOptions = {
149
- /**
150
- * Path to the hook that is used to customize the hook options.
151
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
152
- * It allows both relative and absolute paths but be aware that we will not change the path.
153
- */
154
- importPath: string;
155
- /**
156
- * Name of the exported hook that is used to customize the hook options.
157
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
158
- * @default 'useCustomHookOptions'
159
- */
160
- name?: string;
161
- };
162
- type Options = {
163
- /**
164
- * Specify the export location for the files and define the behavior of the output
165
- * @default { path: 'hooks', barrelType: 'named' }
166
- */
167
- output?: Output<Oas>;
168
- /**
169
- * Define which contentType should be used.
170
- * By default, the first JSON valid mediaType is used
171
- */
172
- contentType?: contentType;
173
- /**
174
- * Group the @tanstack/query hooks based on the provided name.
175
- */
176
- group?: Group;
177
- client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>;
178
- /**
179
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
180
- */
181
- exclude?: Array<Exclude>;
182
- /**
183
- * Array containing include parameters to include tags/operations/methods/paths.
184
- */
185
- include?: Array<Include>;
186
- /**
187
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
188
- */
189
- override?: Array<Override<ResolvedOptions>>;
190
- /**
191
- * How to style your params, by default no casing is applied
192
- * - 'camelcase' uses camelcase for the params names
193
- */
194
- paramsCasing?: 'camelcase';
195
- /**
196
- * How to pass your params.
197
- * - 'object' returns the params and pathParams as an object.
198
- * - 'inline' returns the params as comma separated params.
199
- * @default 'inline'
200
- */
201
- paramsType?: 'object' | 'inline';
202
- /**
203
- * How to pass your pathParams.
204
- * - 'object' returns the pathParams as an object.
205
- * - 'inline': returns the pathParams as comma separated params.
206
- * @default 'inline'
207
- */
208
- pathParamsType?: PluginClient['options']['pathParamsType'];
209
- /**
210
- * When set, an infiniteQuery hooks is added.
211
- */
212
- infinite?: Partial<Infinite> | false;
213
- /**
214
- * When set, a suspenseQuery hooks is added.
215
- */
216
- suspense?: Partial<Suspense> | false;
217
- queryKey?: QueryKey;
218
- /**
219
- * Override some useQuery behaviors.
220
- */
221
- query?: Partial<Query> | false;
222
- mutationKey?: MutationKey;
223
- /**
224
- * Override some useMutation behaviors.
225
- */
226
- mutation?: Partial<Mutation> | false;
227
- /**
228
- * When set, a custom hook is used to customize the options of the generated hooks.
229
- * It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
230
- */
231
- customOptions?: CustomOptions;
232
- /**
233
- * Which parser should be used before returning the data to `@tanstack/query`.
234
- * `'zod'` uses `@kubb/plugin-zod` to parse the data.
235
- */
236
- parser?: PluginClient['options']['parser'];
237
- transformers?: {
238
- /**
239
- * Customize the names based on the type that is provided by the plugin.
240
- */
241
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
242
- };
243
- /**
244
- * Define some generators next to the react-query generators
245
- */
246
- generators?: Array<Generator$1<PluginReactQuery>>;
247
- };
248
- type ResolvedOptions = {
249
- output: Output<Oas>;
250
- group: Options['group'];
251
- client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
252
- parser: Required<NonNullable<Options['parser']>>;
253
- pathParamsType: NonNullable<Options['pathParamsType']>;
254
- paramsCasing: Options['paramsCasing'];
255
- paramsType: NonNullable<Options['paramsType']>;
256
- /**
257
- * Only used of infinite
258
- */
259
- infinite: NonNullable<Infinite> | false;
260
- suspense: Suspense | false;
261
- queryKey: QueryKey | undefined;
262
- query: NonNullable<Required<Query>> | false;
263
- mutationKey: MutationKey | undefined;
264
- mutation: NonNullable<Required<Mutation>> | false;
265
- customOptions: NonNullable<Required<CustomOptions>> | undefined;
266
- };
267
- type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
268
- //#endregion
269
- export { MutationKey$1 as a, QueryKey$1 as i, Options as n, PluginReactQuery as r, Infinite as t };
270
- //# sourceMappingURL=types-D5S7Ny9r.d.ts.map
@@ -1,220 +0,0 @@
1
- import { isAllOptional, isOptional, type Operation } from '@kubb/oas'
2
- import type { OperationSchemas } from '@kubb/plugin-oas'
3
- import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
4
- import { File, Function, FunctionParams } from '@kubb/react-fabric'
5
- import type { FabricReactNode } from '@kubb/react-fabric/types'
6
- import type { Infinite, PluginReactQuery } from '../types.ts'
7
- import { QueryKey } from './QueryKey.tsx'
8
- import { QueryOptions } from './QueryOptions.tsx'
9
-
10
- type Props = {
11
- /**
12
- * Name of the function
13
- */
14
- name: string
15
- queryOptionsName: string
16
- queryKeyName: string
17
- queryKeyTypeName: string
18
- typeSchemas: OperationSchemas
19
- operation: Operation
20
- paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
21
- paramsType: PluginReactQuery['resolvedOptions']['paramsType']
22
- pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
23
- dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
24
- initialPageParam: Infinite['initialPageParam']
25
- queryParam?: Infinite['queryParam']
26
- customOptions: PluginReactQuery['resolvedOptions']['customOptions']
27
- }
28
-
29
- type GetParamsProps = {
30
- paramsType: PluginReactQuery['resolvedOptions']['paramsType']
31
- paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
32
- pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
33
- typeSchemas: OperationSchemas
34
- pageParamGeneric: string
35
- }
36
-
37
- function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, pageParamGeneric }: GetParamsProps) {
38
- if (paramsType === 'object') {
39
- const pathParams = getPathParams(typeSchemas.pathParams, {
40
- typed: true,
41
- casing: paramsCasing,
42
- })
43
-
44
- const children = {
45
- ...pathParams,
46
- data: typeSchemas.request?.name
47
- ? {
48
- type: typeSchemas.request?.name,
49
- optional: isOptional(typeSchemas.request?.schema),
50
- }
51
- : undefined,
52
- params: typeSchemas.queryParams?.name
53
- ? {
54
- type: typeSchemas.queryParams?.name,
55
- optional: isOptional(typeSchemas.queryParams?.schema),
56
- }
57
- : undefined,
58
- headers: typeSchemas.headerParams?.name
59
- ? {
60
- type: typeSchemas.headerParams?.name,
61
- optional: isOptional(typeSchemas.headerParams?.schema),
62
- }
63
- : undefined,
64
- }
65
-
66
- // Check if all children are optional or undefined
67
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
68
-
69
- return FunctionParams.factory({
70
- data: {
71
- mode: 'object',
72
- children,
73
- default: allChildrenAreOptional ? '{}' : undefined,
74
- },
75
- options: {
76
- type: `
77
- {
78
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
79
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
80
- }
81
- `,
82
- default: '{}',
83
- },
84
- })
85
- }
86
-
87
- return FunctionParams.factory({
88
- pathParams: typeSchemas.pathParams?.name
89
- ? {
90
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
91
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
92
- default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
93
- }
94
- : undefined,
95
- data: typeSchemas.request?.name
96
- ? {
97
- type: typeSchemas.request?.name,
98
- optional: isOptional(typeSchemas.request?.schema),
99
- }
100
- : undefined,
101
- params: typeSchemas.queryParams?.name
102
- ? {
103
- type: typeSchemas.queryParams?.name,
104
- optional: isOptional(typeSchemas.queryParams?.schema),
105
- }
106
- : undefined,
107
- headers: typeSchemas.headerParams?.name
108
- ? {
109
- type: typeSchemas.headerParams?.name,
110
- optional: isOptional(typeSchemas.headerParams?.schema),
111
- }
112
- : undefined,
113
- options: {
114
- type: `
115
- {
116
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
117
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
118
- }
119
- `,
120
- default: '{}',
121
- },
122
- })
123
- }
124
-
125
- export function InfiniteQuery({
126
- name,
127
- queryKeyTypeName,
128
- queryOptionsName,
129
- queryKeyName,
130
- paramsType,
131
- paramsCasing,
132
- pathParamsType,
133
- dataReturnType,
134
- typeSchemas,
135
- operation,
136
- initialPageParam,
137
- queryParam,
138
- customOptions,
139
- }: Props): FabricReactNode {
140
- const responseType = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
141
- const errorType = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
142
- const isInitialPageParamDefined = initialPageParam !== undefined && initialPageParam !== null
143
- const fallbackPageParamType =
144
- typeof initialPageParam === 'number'
145
- ? 'number'
146
- : typeof initialPageParam === 'string'
147
- ? initialPageParam.includes(' as ')
148
- ? (() => {
149
- const parts = initialPageParam.split(' as ')
150
- return parts[parts.length - 1] ?? 'unknown'
151
- })()
152
- : 'string'
153
- : typeof initialPageParam === 'boolean'
154
- ? 'boolean'
155
- : 'unknown'
156
- const queryParamType = queryParam && typeSchemas.queryParams?.name ? `${typeSchemas.queryParams?.name}['${queryParam}']` : undefined
157
- const pageParamType = queryParamType ? (isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType) : fallbackPageParamType
158
- const returnType = 'UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }'
159
- const generics = [
160
- `TQueryFnData = ${responseType}`,
161
- `TError = ${errorType}`,
162
- 'TData = InfiniteData<TQueryFnData>',
163
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
164
- `TPageParam = ${pageParamType}`,
165
- ]
166
-
167
- const queryKeyParams = QueryKey.getParams({
168
- pathParamsType,
169
- typeSchemas,
170
- paramsCasing,
171
- })
172
- const queryOptionsParams = QueryOptions.getParams({
173
- paramsType,
174
- pathParamsType,
175
- typeSchemas,
176
- paramsCasing,
177
- })
178
- const params = getParams({
179
- paramsCasing,
180
- paramsType,
181
- pathParamsType,
182
- typeSchemas,
183
- pageParamGeneric: 'TPageParam',
184
- })
185
-
186
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`
187
-
188
- return (
189
- <File.Source name={name} isExportable isIndexable>
190
- <Function
191
- name={name}
192
- export
193
- generics={generics.join(', ')}
194
- params={params.toConstructor()}
195
- JSDoc={{
196
- comments: getComments(operation),
197
- }}
198
- >
199
- {`
200
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
201
- const { client: queryClient, ...resolvedOptions } = queryConfig
202
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
203
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${operation.getOperationId()}' })` : ''}
204
-
205
- const query = useInfiniteQuery({
206
- ...${queryOptions},${customOptions ? '\n...customOptions,' : ''}
207
- ...resolvedOptions,
208
- queryKey,
209
- } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
210
-
211
- query.queryKey = queryKey as TQueryKey
212
-
213
- return query
214
- `}
215
- </Function>
216
- </File.Source>
217
- )
218
- }
219
-
220
- InfiniteQuery.getParams = getParams