@kubb/plugin-vue-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.
- package/LICENSE +17 -10
- package/README.md +38 -23
- package/dist/index.cjs +1651 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +358 -6
- package/dist/index.js +1618 -138
- package/dist/index.js.map +1 -1
- package/package.json +48 -76
- package/dist/components-Yjoe78Y7.cjs +0 -1119
- package/dist/components-Yjoe78Y7.cjs.map +0 -1
- package/dist/components-_AMBl0g-.js +0 -1029
- package/dist/components-_AMBl0g-.js.map +0 -1
- package/dist/components.cjs +0 -9
- package/dist/components.d.ts +0 -242
- package/dist/components.js +0 -2
- package/dist/generators-CR34GjVu.js +0 -661
- package/dist/generators-CR34GjVu.js.map +0 -1
- package/dist/generators-DH8VkK1q.cjs +0 -678
- package/dist/generators-DH8VkK1q.cjs.map +0 -1
- package/dist/generators.cjs +0 -5
- package/dist/generators.d.ts +0 -511
- package/dist/generators.js +0 -2
- package/dist/types-CgDFUvfZ.d.ts +0 -211
- package/src/components/InfiniteQuery.tsx +0 -208
- package/src/components/InfiniteQueryOptions.tsx +0 -249
- package/src/components/Mutation.tsx +0 -185
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -208
- package/src/components/QueryKey.tsx +0 -94
- package/src/components/QueryOptions.tsx +0 -185
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -213
- package/src/generators/mutationGenerator.tsx +0 -176
- package/src/generators/queryGenerator.tsx +0 -191
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -218
- package/src/types.ts +0 -176
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/types-CgDFUvfZ.d.ts
DELETED
|
@@ -1,211 +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 = {
|
|
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 = {
|
|
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): FabricReactNode;
|
|
43
|
-
declare namespace MutationKey$1 {
|
|
44
|
-
var getParams: ({}: GetParamsProps) => FunctionParams;
|
|
45
|
-
var getTransformer: Transformer;
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/types.d.ts
|
|
49
|
-
/**
|
|
50
|
-
* Customize the queryKey
|
|
51
|
-
*/
|
|
52
|
-
type QueryKey = Transformer;
|
|
53
|
-
/**
|
|
54
|
-
* Customize the mutationKey
|
|
55
|
-
*/
|
|
56
|
-
type MutationKey = Transformer;
|
|
57
|
-
type Query = {
|
|
58
|
-
/**
|
|
59
|
-
* Define which HttpMethods can be used for queries
|
|
60
|
-
* @default ['get']
|
|
61
|
-
*/
|
|
62
|
-
methods: Array<HttpMethod>;
|
|
63
|
-
/**
|
|
64
|
-
* Path to the useQuery hook for useQuery functionality.
|
|
65
|
-
* Used as `import { useQuery } from '${importPath}'`.
|
|
66
|
-
* Accepts relative and absolute paths.
|
|
67
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
68
|
-
* @default '@tanstack/react-query'
|
|
69
|
-
*/
|
|
70
|
-
importPath?: string;
|
|
71
|
-
};
|
|
72
|
-
type Mutation = {
|
|
73
|
-
/**
|
|
74
|
-
* Define which HttpMethods can be used for mutations
|
|
75
|
-
* @default ['post', 'put', 'delete']
|
|
76
|
-
*/
|
|
77
|
-
methods: Array<HttpMethod>;
|
|
78
|
-
/**
|
|
79
|
-
* Path to the useQuery hook for useQuery functionality.
|
|
80
|
-
* Used as `import { useQuery } from '${importPath}'`.
|
|
81
|
-
* Accepts relative and absolute paths.
|
|
82
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
83
|
-
* @default '@tanstack/react-query'
|
|
84
|
-
*/
|
|
85
|
-
importPath?: string;
|
|
86
|
-
};
|
|
87
|
-
type Infinite = {
|
|
88
|
-
/**
|
|
89
|
-
* Specify the params key used for `pageParam`.
|
|
90
|
-
* @default `'id'`
|
|
91
|
-
*/
|
|
92
|
-
queryParam: string;
|
|
93
|
-
/**
|
|
94
|
-
* Which field of the data is used, set it to undefined when no cursor is known.
|
|
95
|
-
* @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
|
|
96
|
-
*/
|
|
97
|
-
cursorParam?: string | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* Which field of the data is used to get the cursor for the next page.
|
|
100
|
-
* Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
|
|
101
|
-
*/
|
|
102
|
-
nextParam?: string | string[] | undefined;
|
|
103
|
-
/**
|
|
104
|
-
* Which field of the data is used to get the cursor for the previous page.
|
|
105
|
-
* Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
|
|
106
|
-
*/
|
|
107
|
-
previousParam?: string | string[] | undefined;
|
|
108
|
-
/**
|
|
109
|
-
* The initial value, the value of the first page.
|
|
110
|
-
* @default `0`
|
|
111
|
-
*/
|
|
112
|
-
initialPageParam: unknown;
|
|
113
|
-
};
|
|
114
|
-
type Options = {
|
|
115
|
-
/**
|
|
116
|
-
* Specify the export location for the files and define the behavior of the output
|
|
117
|
-
* @default { path: 'hooks', barrelType: 'named' }
|
|
118
|
-
*/
|
|
119
|
-
output?: Output<Oas>;
|
|
120
|
-
/**
|
|
121
|
-
* Define which contentType should be used.
|
|
122
|
-
* By default, the first JSON valid mediaType is used
|
|
123
|
-
*/
|
|
124
|
-
contentType?: contentType;
|
|
125
|
-
/**
|
|
126
|
-
* Group the @tanstack/query hooks based on the provided name.
|
|
127
|
-
*/
|
|
128
|
-
group?: Group;
|
|
129
|
-
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>;
|
|
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 style your params, by default no casing is applied
|
|
144
|
-
* - 'camelcase' uses camelcase for the params names
|
|
145
|
-
*/
|
|
146
|
-
paramsCasing?: 'camelcase';
|
|
147
|
-
/**
|
|
148
|
-
* How to pass your params
|
|
149
|
-
* - 'object' returns the params and pathParams as an object.
|
|
150
|
-
* - 'inline' returns the params as comma separated params.
|
|
151
|
-
* @default 'inline'
|
|
152
|
-
*/
|
|
153
|
-
paramsType?: 'object' | 'inline';
|
|
154
|
-
/**
|
|
155
|
-
* How to pass your pathParams.
|
|
156
|
-
* - 'object' returns the pathParams as an object.
|
|
157
|
-
* - 'inline': returns the pathParams as comma separated params.
|
|
158
|
-
* @default 'inline'
|
|
159
|
-
*/
|
|
160
|
-
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
161
|
-
/**
|
|
162
|
-
* When set, an infiniteQuery hooks is added.
|
|
163
|
-
*/
|
|
164
|
-
infinite?: Partial<Infinite> | false;
|
|
165
|
-
queryKey?: QueryKey;
|
|
166
|
-
/**
|
|
167
|
-
* Override some useQuery behaviors.
|
|
168
|
-
*/
|
|
169
|
-
query?: Partial<Query> | false;
|
|
170
|
-
mutationKey?: MutationKey;
|
|
171
|
-
/**
|
|
172
|
-
* Override some useMutation behaviors.
|
|
173
|
-
*/
|
|
174
|
-
mutation?: Partial<Mutation> | false;
|
|
175
|
-
/**
|
|
176
|
-
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
177
|
-
* `'zod'` uses `@kubb/plugin-zod` to parse the data.
|
|
178
|
-
*/
|
|
179
|
-
parser?: PluginClient['options']['parser'];
|
|
180
|
-
transformers?: {
|
|
181
|
-
/**
|
|
182
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
183
|
-
*/
|
|
184
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Define some generators next to the vue-query generators
|
|
188
|
-
*/
|
|
189
|
-
generators?: Array<Generator$1<PluginVueQuery>>;
|
|
190
|
-
};
|
|
191
|
-
type ResolvedOptions = {
|
|
192
|
-
output: Output<Oas>;
|
|
193
|
-
group: Options['group'];
|
|
194
|
-
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
|
|
195
|
-
parser: Required<NonNullable<Options['parser']>>;
|
|
196
|
-
paramsCasing: Options['paramsCasing'];
|
|
197
|
-
paramsType: NonNullable<Options['paramsType']>;
|
|
198
|
-
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
199
|
-
/**
|
|
200
|
-
* Only used of infinite
|
|
201
|
-
*/
|
|
202
|
-
infinite: NonNullable<Infinite> | false;
|
|
203
|
-
queryKey: QueryKey | undefined;
|
|
204
|
-
query: NonNullable<Required<Query>> | false;
|
|
205
|
-
mutationKey: MutationKey | undefined;
|
|
206
|
-
mutation: NonNullable<Required<Mutation>> | false;
|
|
207
|
-
};
|
|
208
|
-
type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
209
|
-
//#endregion
|
|
210
|
-
export { Transformer as a, MutationKey$1 as i, Options as n, PluginVueQuery as r, Infinite as t };
|
|
211
|
-
//# sourceMappingURL=types-CgDFUvfZ.d.ts.map
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { getDefaultValue, 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 { PluginVueQuery } 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: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
21
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
22
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
23
|
-
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type GetParamsProps = {
|
|
27
|
-
paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
28
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
29
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
30
|
-
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
31
|
-
typeSchemas: OperationSchemas
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
35
|
-
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
36
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
37
|
-
|
|
38
|
-
if (paramsType === 'object') {
|
|
39
|
-
const pathParams = getPathParams(typeSchemas.pathParams, {
|
|
40
|
-
typed: true,
|
|
41
|
-
casing: paramsCasing,
|
|
42
|
-
override(item) {
|
|
43
|
-
return {
|
|
44
|
-
...item,
|
|
45
|
-
type: `MaybeRefOrGetter<${item.type}>`,
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
const children = {
|
|
50
|
-
...pathParams,
|
|
51
|
-
data: typeSchemas.request?.name
|
|
52
|
-
? {
|
|
53
|
-
type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
|
|
54
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
55
|
-
}
|
|
56
|
-
: undefined,
|
|
57
|
-
params: typeSchemas.queryParams?.name
|
|
58
|
-
? {
|
|
59
|
-
type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
|
|
60
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
61
|
-
}
|
|
62
|
-
: undefined,
|
|
63
|
-
headers: typeSchemas.headerParams?.name
|
|
64
|
-
? {
|
|
65
|
-
type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
|
|
66
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
67
|
-
}
|
|
68
|
-
: undefined,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Check if all children are optional or undefined
|
|
72
|
-
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
|
|
73
|
-
|
|
74
|
-
return FunctionParams.factory({
|
|
75
|
-
data: {
|
|
76
|
-
mode: 'object',
|
|
77
|
-
children,
|
|
78
|
-
default: allChildrenAreOptional ? '{}' : undefined,
|
|
79
|
-
},
|
|
80
|
-
options: {
|
|
81
|
-
type: `
|
|
82
|
-
{
|
|
83
|
-
query?: Partial<UseInfiniteQueryOptions<${[TData, TError, 'TQueryData', 'TQueryKey', 'TQueryData'].join(', ')}>> & { client?: QueryClient },
|
|
84
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
|
|
85
|
-
}
|
|
86
|
-
`,
|
|
87
|
-
default: '{}',
|
|
88
|
-
},
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return FunctionParams.factory({
|
|
93
|
-
pathParams: typeSchemas.pathParams?.name
|
|
94
|
-
? {
|
|
95
|
-
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
96
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
97
|
-
typed: true,
|
|
98
|
-
casing: paramsCasing,
|
|
99
|
-
override(item) {
|
|
100
|
-
return {
|
|
101
|
-
...item,
|
|
102
|
-
type: `MaybeRefOrGetter<${item.type}>`,
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
}),
|
|
106
|
-
default: getDefaultValue(typeSchemas.pathParams?.schema),
|
|
107
|
-
}
|
|
108
|
-
: undefined,
|
|
109
|
-
data: typeSchemas.request?.name
|
|
110
|
-
? {
|
|
111
|
-
type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
|
|
112
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
113
|
-
}
|
|
114
|
-
: undefined,
|
|
115
|
-
params: typeSchemas.queryParams?.name
|
|
116
|
-
? {
|
|
117
|
-
type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
|
|
118
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
119
|
-
}
|
|
120
|
-
: undefined,
|
|
121
|
-
headers: typeSchemas.headerParams?.name
|
|
122
|
-
? {
|
|
123
|
-
type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
|
|
124
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
125
|
-
}
|
|
126
|
-
: undefined,
|
|
127
|
-
options: {
|
|
128
|
-
type: `
|
|
129
|
-
{
|
|
130
|
-
query?: Partial<UseInfiniteQueryOptions<${[TData, TError, 'TQueryData', 'TQueryKey', 'TQueryData'].join(', ')}>> & { client?: QueryClient },
|
|
131
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
|
|
132
|
-
}
|
|
133
|
-
`,
|
|
134
|
-
default: '{}',
|
|
135
|
-
},
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function InfiniteQuery({
|
|
140
|
-
name,
|
|
141
|
-
queryKeyTypeName,
|
|
142
|
-
queryOptionsName,
|
|
143
|
-
queryKeyName,
|
|
144
|
-
paramsType,
|
|
145
|
-
pathParamsType,
|
|
146
|
-
paramsCasing,
|
|
147
|
-
dataReturnType,
|
|
148
|
-
typeSchemas,
|
|
149
|
-
operation,
|
|
150
|
-
}: Props): FabricReactNode {
|
|
151
|
-
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
152
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
153
|
-
const returnType = `UseInfiniteQueryReturnType<${['TData', TError].join(', ')}> & { queryKey: TQueryKey }`
|
|
154
|
-
const generics = [`TData = InfiniteData<${TData}>`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
155
|
-
|
|
156
|
-
const queryKeyParams = QueryKey.getParams({
|
|
157
|
-
pathParamsType,
|
|
158
|
-
typeSchemas,
|
|
159
|
-
paramsCasing,
|
|
160
|
-
})
|
|
161
|
-
const queryOptionsParams = QueryOptions.getParams({
|
|
162
|
-
paramsType,
|
|
163
|
-
pathParamsType,
|
|
164
|
-
typeSchemas,
|
|
165
|
-
paramsCasing,
|
|
166
|
-
})
|
|
167
|
-
const params = getParams({
|
|
168
|
-
paramsCasing,
|
|
169
|
-
paramsType,
|
|
170
|
-
pathParamsType,
|
|
171
|
-
dataReturnType,
|
|
172
|
-
typeSchemas,
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<File.Source name={name} isExportable isIndexable>
|
|
179
|
-
<Function
|
|
180
|
-
name={name}
|
|
181
|
-
export
|
|
182
|
-
generics={generics.join(', ')}
|
|
183
|
-
params={params.toConstructor()}
|
|
184
|
-
JSDoc={{
|
|
185
|
-
comments: getComments(operation),
|
|
186
|
-
}}
|
|
187
|
-
>
|
|
188
|
-
{`
|
|
189
|
-
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
190
|
-
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
191
|
-
const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
|
|
192
|
-
|
|
193
|
-
const query = useInfiniteQuery({
|
|
194
|
-
...${queryOptions},
|
|
195
|
-
...resolvedOptions,
|
|
196
|
-
queryKey
|
|
197
|
-
} as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
|
|
198
|
-
|
|
199
|
-
query.queryKey = queryKey as TQueryKey
|
|
200
|
-
|
|
201
|
-
return query
|
|
202
|
-
`}
|
|
203
|
-
</Function>
|
|
204
|
-
</File.Source>
|
|
205
|
-
)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
InfiniteQuery.getParams = getParams
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { getNestedAccessor } from '@internals/utils'
|
|
2
|
-
import { getDefaultValue, isOptional } from '@kubb/oas'
|
|
3
|
-
import { Client } from '@kubb/plugin-client/components'
|
|
4
|
-
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
5
|
-
import { getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
|
-
import { File, Function, FunctionParams } from '@kubb/react-fabric'
|
|
7
|
-
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
8
|
-
import type { Infinite, PluginVueQuery } from '../types.ts'
|
|
9
|
-
import { QueryKey } from './QueryKey.tsx'
|
|
10
|
-
|
|
11
|
-
type Props = {
|
|
12
|
-
name: string
|
|
13
|
-
clientName: string
|
|
14
|
-
queryKeyName: string
|
|
15
|
-
typeSchemas: OperationSchemas
|
|
16
|
-
paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
17
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
18
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
19
|
-
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
20
|
-
initialPageParam: Infinite['initialPageParam']
|
|
21
|
-
cursorParam: Infinite['cursorParam']
|
|
22
|
-
nextParam: Infinite['nextParam']
|
|
23
|
-
previousParam: Infinite['previousParam']
|
|
24
|
-
queryParam: Infinite['queryParam']
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type GetParamsProps = {
|
|
28
|
-
paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
|
|
29
|
-
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
30
|
-
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
31
|
-
typeSchemas: OperationSchemas
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
35
|
-
if (paramsType === 'object') {
|
|
36
|
-
const children = {
|
|
37
|
-
...getPathParams(typeSchemas.pathParams, {
|
|
38
|
-
typed: true,
|
|
39
|
-
casing: paramsCasing,
|
|
40
|
-
override(item) {
|
|
41
|
-
return {
|
|
42
|
-
...item,
|
|
43
|
-
type: `MaybeRefOrGetter<${item.type}>`,
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
data: typeSchemas.request?.name
|
|
48
|
-
? {
|
|
49
|
-
type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
|
|
50
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
51
|
-
}
|
|
52
|
-
: undefined,
|
|
53
|
-
params: typeSchemas.queryParams?.name
|
|
54
|
-
? {
|
|
55
|
-
type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
|
|
56
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
57
|
-
}
|
|
58
|
-
: undefined,
|
|
59
|
-
headers: typeSchemas.headerParams?.name
|
|
60
|
-
? {
|
|
61
|
-
type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
|
|
62
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
63
|
-
}
|
|
64
|
-
: undefined,
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Check if all children are optional or undefined
|
|
68
|
-
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
|
|
69
|
-
|
|
70
|
-
return FunctionParams.factory({
|
|
71
|
-
data: {
|
|
72
|
-
mode: 'object',
|
|
73
|
-
children,
|
|
74
|
-
default: allChildrenAreOptional ? '{}' : undefined,
|
|
75
|
-
},
|
|
76
|
-
config: {
|
|
77
|
-
type: typeSchemas.request?.name
|
|
78
|
-
? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }`
|
|
79
|
-
: 'Partial<RequestConfig> & { client?: Client }',
|
|
80
|
-
default: '{}',
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return FunctionParams.factory({
|
|
86
|
-
pathParams: {
|
|
87
|
-
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
88
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
89
|
-
typed: true,
|
|
90
|
-
casing: paramsCasing,
|
|
91
|
-
override(item) {
|
|
92
|
-
return {
|
|
93
|
-
...item,
|
|
94
|
-
type: `MaybeRefOrGetter<${item.type}>`,
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
default: getDefaultValue(typeSchemas.pathParams?.schema),
|
|
99
|
-
},
|
|
100
|
-
data: typeSchemas.request?.name
|
|
101
|
-
? {
|
|
102
|
-
type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
|
|
103
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
104
|
-
}
|
|
105
|
-
: undefined,
|
|
106
|
-
params: typeSchemas.queryParams?.name
|
|
107
|
-
? {
|
|
108
|
-
type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
|
|
109
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
110
|
-
}
|
|
111
|
-
: undefined,
|
|
112
|
-
headers: typeSchemas.headerParams?.name
|
|
113
|
-
? {
|
|
114
|
-
type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
|
|
115
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
116
|
-
}
|
|
117
|
-
: undefined,
|
|
118
|
-
config: {
|
|
119
|
-
type: typeSchemas.request?.name
|
|
120
|
-
? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }`
|
|
121
|
-
: 'Partial<RequestConfig> & { client?: Client }',
|
|
122
|
-
default: '{}',
|
|
123
|
-
},
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function InfiniteQueryOptions({
|
|
128
|
-
name,
|
|
129
|
-
clientName,
|
|
130
|
-
initialPageParam,
|
|
131
|
-
cursorParam,
|
|
132
|
-
nextParam,
|
|
133
|
-
previousParam,
|
|
134
|
-
typeSchemas,
|
|
135
|
-
paramsType,
|
|
136
|
-
paramsCasing,
|
|
137
|
-
dataReturnType,
|
|
138
|
-
pathParamsType,
|
|
139
|
-
queryParam,
|
|
140
|
-
queryKeyName,
|
|
141
|
-
}: Props): FabricReactNode {
|
|
142
|
-
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
143
|
-
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
|
|
144
|
-
|
|
145
|
-
const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
146
|
-
const clientParams = Client.getParams({
|
|
147
|
-
paramsType,
|
|
148
|
-
paramsCasing,
|
|
149
|
-
typeSchemas,
|
|
150
|
-
pathParamsType,
|
|
151
|
-
isConfigurable: true,
|
|
152
|
-
})
|
|
153
|
-
const queryKeyParams = QueryKey.getParams({
|
|
154
|
-
paramsCasing,
|
|
155
|
-
pathParamsType,
|
|
156
|
-
typeSchemas,
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
// Determine if we should use the new nextParam/previousParam or fall back to legacy cursorParam behavior
|
|
160
|
-
const hasNewParams = nextParam !== undefined || previousParam !== undefined
|
|
161
|
-
|
|
162
|
-
let getNextPageParamExpr: string | undefined
|
|
163
|
-
let getPreviousPageParamExpr: string | undefined
|
|
164
|
-
|
|
165
|
-
if (hasNewParams) {
|
|
166
|
-
// Use the new nextParam and previousParam
|
|
167
|
-
if (nextParam) {
|
|
168
|
-
const accessor = getNestedAccessor(nextParam, 'lastPage')
|
|
169
|
-
if (accessor) {
|
|
170
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (previousParam) {
|
|
174
|
-
const accessor = getNestedAccessor(previousParam, 'firstPage')
|
|
175
|
-
if (accessor) {
|
|
176
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
} else if (cursorParam) {
|
|
180
|
-
// Legacy behavior: use cursorParam for both next and previous
|
|
181
|
-
getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`
|
|
182
|
-
getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`
|
|
183
|
-
} else {
|
|
184
|
-
// Fallback behavior: page-based pagination
|
|
185
|
-
if (dataReturnType === 'full') {
|
|
186
|
-
getNextPageParamExpr =
|
|
187
|
-
'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
|
|
188
|
-
} else {
|
|
189
|
-
getNextPageParamExpr =
|
|
190
|
-
'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1'
|
|
191
|
-
}
|
|
192
|
-
getPreviousPageParamExpr = 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1'
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const queryOptions = [
|
|
196
|
-
`initialPageParam: ${typeof initialPageParam === 'string' ? JSON.stringify(initialPageParam) : initialPageParam}`,
|
|
197
|
-
getNextPageParamExpr,
|
|
198
|
-
getPreviousPageParamExpr,
|
|
199
|
-
].filter(Boolean)
|
|
200
|
-
|
|
201
|
-
const infiniteOverrideParams =
|
|
202
|
-
queryParam && typeSchemas.queryParams?.name
|
|
203
|
-
? `
|
|
204
|
-
if (!params) {
|
|
205
|
-
params = { }
|
|
206
|
-
}
|
|
207
|
-
params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']`
|
|
208
|
-
: ''
|
|
209
|
-
|
|
210
|
-
const enabled = Object.entries(queryKeyParams.flatParams)
|
|
211
|
-
.map(([key, item]) => {
|
|
212
|
-
// Only include if the parameter exists and is NOT optional
|
|
213
|
-
// This ensures we only check required parameters
|
|
214
|
-
return item && !item.optional && !item.default ? key : undefined
|
|
215
|
-
})
|
|
216
|
-
.filter(Boolean)
|
|
217
|
-
.join('&& ')
|
|
218
|
-
|
|
219
|
-
const enabledText = enabled ? `enabled: !!(${enabled}),` : ''
|
|
220
|
-
|
|
221
|
-
return (
|
|
222
|
-
<File.Source name={name} isExportable isIndexable>
|
|
223
|
-
<Function name={name} export params={params.toConstructor()}>
|
|
224
|
-
{`
|
|
225
|
-
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
226
|
-
return infiniteQueryOptions<${TData}, ${TError}, ${TData}, typeof queryKey, number>({
|
|
227
|
-
${enabledText}
|
|
228
|
-
queryKey,
|
|
229
|
-
queryFn: async ({ signal, pageParam }) => {
|
|
230
|
-
${infiniteOverrideParams}
|
|
231
|
-
return ${clientName}(${clientParams.toCall({
|
|
232
|
-
transformName(name) {
|
|
233
|
-
if (name === 'config') {
|
|
234
|
-
return '{ ...config, signal: config.signal ?? signal }'
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return `toValue(${name})`
|
|
238
|
-
},
|
|
239
|
-
})})
|
|
240
|
-
},
|
|
241
|
-
${queryOptions.join(',\n')}
|
|
242
|
-
})
|
|
243
|
-
`}
|
|
244
|
-
</Function>
|
|
245
|
-
</File.Source>
|
|
246
|
-
)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
InfiniteQueryOptions.getParams = getParams
|