@kubb/plugin-react-query 3.0.0-beta.1 → 3.0.0-beta.11
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/dist/{chunk-C2H3KPHM.cjs → chunk-BML6BZ4F.cjs} +256 -36
- package/dist/chunk-BML6BZ4F.cjs.map +1 -0
- package/dist/{chunk-Y3DM2P6L.js → chunk-JFIGHRBM.js} +256 -36
- package/dist/chunk-JFIGHRBM.js.map +1 -0
- package/dist/{chunk-IRW2Y3EC.js → chunk-PQJ45MEL.js} +31 -16
- package/dist/chunk-PQJ45MEL.js.map +1 -0
- package/dist/{chunk-37VO6QXJ.cjs → chunk-SIKQARDB.cjs} +48 -33
- package/dist/chunk-SIKQARDB.cjs.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +23 -12
- package/dist/components.d.ts +23 -12
- package/dist/components.js +1 -1
- package/dist/generators.cjs +6 -6
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +19 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -20
- package/dist/index.js.map +1 -1
- package/dist/{types-5pnOmDmM.d.cts → types-DL6Qblcz.d.cts} +41 -37
- package/dist/{types-5pnOmDmM.d.ts → types-DL6Qblcz.d.ts} +41 -37
- package/package.json +14 -14
- package/src/components/InfiniteQuery.tsx +52 -5
- package/src/components/InfiniteQueryOptions.tsx +62 -7
- package/src/components/Mutation.tsx +9 -3
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryOptions.tsx +47 -7
- package/src/components/SuspenseQuery.tsx +52 -5
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/infiniteQueryGenerator.tsx +4 -2
- package/src/generators/mutationGenerator.tsx +3 -2
- package/src/generators/queryGenerator.tsx +4 -2
- package/src/generators/suspenseQueryGenerator.tsx +4 -1
- package/src/plugin.ts +17 -18
- package/src/types.ts +19 -24
- package/dist/chunk-37VO6QXJ.cjs.map +0 -1
- package/dist/chunk-C2H3KPHM.cjs.map +0 -1
- package/dist/chunk-IRW2Y3EC.js.map +0 -1
- package/dist/chunk-Y3DM2P6L.js.map +0 -1
|
@@ -26,7 +26,7 @@ type Options$1 = {
|
|
|
26
26
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
27
27
|
/**
|
|
28
28
|
* Create `operations.ts` file with all operations grouped by methods.
|
|
29
|
-
* @default
|
|
29
|
+
* @default false
|
|
30
30
|
*/
|
|
31
31
|
operations?: boolean;
|
|
32
32
|
/**
|
|
@@ -36,29 +36,34 @@ type Options$1 = {
|
|
|
36
36
|
* @default '@kubb/plugin-client/client'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Allows you to set a custom base url for all generated calls.
|
|
41
|
+
*/
|
|
42
|
+
baseURL?: string;
|
|
39
43
|
/**
|
|
40
44
|
* ReturnType that will be used when calling the client.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `Full` will return ResponseConfig.
|
|
45
|
-
* @default `'data'`
|
|
46
|
-
* @private
|
|
45
|
+
* - 'data' will return ResponseConfig[data].
|
|
46
|
+
* - 'full' will return ResponseConfig.
|
|
47
|
+
* @default 'data'
|
|
47
48
|
*/
|
|
48
49
|
dataReturnType?: 'data' | 'full';
|
|
50
|
+
/**
|
|
51
|
+
* How to pass your params
|
|
52
|
+
* - 'object' will return the params and pathParams as an object.
|
|
53
|
+
* - 'inline' will return the params as comma separated params.
|
|
54
|
+
* @default 'inline'
|
|
55
|
+
*/
|
|
56
|
+
paramsType?: 'object' | 'inline';
|
|
49
57
|
/**
|
|
50
58
|
* How to pass your pathParams.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* `inline` will return the pathParams as comma separated params.
|
|
55
|
-
* @default `'inline'`
|
|
56
|
-
* @private
|
|
59
|
+
* - 'object' will return the pathParams as an object.
|
|
60
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
61
|
+
* @default 'inline'
|
|
57
62
|
*/
|
|
58
63
|
pathParamsType?: 'object' | 'inline';
|
|
59
64
|
/**
|
|
60
65
|
* Which parser can be used before returning the data
|
|
61
|
-
*
|
|
66
|
+
* - 'zod' will use `@kubb/plugin-zod` to parse the data.
|
|
62
67
|
* @default 'client'
|
|
63
68
|
*/
|
|
64
69
|
parser?: 'client' | 'zod';
|
|
@@ -81,6 +86,7 @@ type ResolvedOptions$1 = {
|
|
|
81
86
|
importPath: NonNullable<Options$1['importPath']>;
|
|
82
87
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
83
88
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
89
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
84
90
|
};
|
|
85
91
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
86
92
|
|
|
@@ -126,7 +132,7 @@ type Mutation = {
|
|
|
126
132
|
type Infinite = {
|
|
127
133
|
/**
|
|
128
134
|
* Specify the params key used for `pageParam`.
|
|
129
|
-
* @default
|
|
135
|
+
* @default 'id'
|
|
130
136
|
*/
|
|
131
137
|
queryParam: string;
|
|
132
138
|
/**
|
|
@@ -135,29 +141,21 @@ type Infinite = {
|
|
|
135
141
|
cursorParam?: string | undefined;
|
|
136
142
|
/**
|
|
137
143
|
* The initial value, the value of the first page.
|
|
138
|
-
* @default
|
|
144
|
+
* @default 0
|
|
139
145
|
*/
|
|
140
146
|
initialPageParam: unknown;
|
|
141
147
|
};
|
|
142
148
|
type Options = {
|
|
143
149
|
/**
|
|
144
|
-
*
|
|
150
|
+
* Specify the export location for the files and define the behavior of the output
|
|
151
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
145
152
|
*/
|
|
146
153
|
output?: Output;
|
|
147
154
|
/**
|
|
148
155
|
* Group the @tanstack/query hooks based on the provided name.
|
|
149
156
|
*/
|
|
150
157
|
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
|
-
*/
|
|
158
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
161
159
|
/**
|
|
162
160
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
163
161
|
*/
|
|
@@ -170,14 +168,18 @@ type Options = {
|
|
|
170
168
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
171
169
|
*/
|
|
172
170
|
override?: Array<Override<ResolvedOptions>>;
|
|
171
|
+
/**
|
|
172
|
+
* How to pass your params
|
|
173
|
+
* - 'object' will return the params and pathParams as an object.
|
|
174
|
+
* - 'inline' will return the params as comma separated params.
|
|
175
|
+
* @default 'inline'
|
|
176
|
+
*/
|
|
177
|
+
paramsType?: 'object' | 'inline';
|
|
173
178
|
/**
|
|
174
179
|
* How to pass your pathParams.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* `inline` will return the pathParams as comma separated params.
|
|
179
|
-
* @default `'inline'`
|
|
180
|
-
* @private
|
|
180
|
+
* - 'object' will return the pathParams as an object.
|
|
181
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
182
|
+
* @default 'inline'
|
|
181
183
|
*/
|
|
182
184
|
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
183
185
|
/**
|
|
@@ -195,9 +197,9 @@ type Options = {
|
|
|
195
197
|
/**
|
|
196
198
|
* Override some useMutation behaviours.
|
|
197
199
|
*/
|
|
198
|
-
mutation?: Mutation | false;
|
|
200
|
+
mutation?: Partial<Mutation> | false;
|
|
199
201
|
/**
|
|
200
|
-
* Which parser
|
|
202
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
201
203
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
202
204
|
*/
|
|
203
205
|
parser?: PluginClient['options']['parser'];
|
|
@@ -214,10 +216,12 @@ type Options = {
|
|
|
214
216
|
};
|
|
215
217
|
type ResolvedOptions = {
|
|
216
218
|
output: Output;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
220
|
+
baseURL?: string;
|
|
221
|
+
};
|
|
219
222
|
parser: Required<NonNullable<Options['parser']>>;
|
|
220
223
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
224
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
221
225
|
/**
|
|
222
226
|
* Only used of infinite
|
|
223
227
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "Generator react-query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
"!/**/__tests__/**"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@kubb/
|
|
66
|
-
"@kubb/fs": "3.0.0-beta.
|
|
67
|
-
"@kubb/
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0-beta.
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0-beta.
|
|
70
|
-
"@kubb/
|
|
71
|
-
"@kubb/
|
|
65
|
+
"@kubb/core": "3.0.0-beta.11",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.11",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.11",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.11",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.11",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.11",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/react": "^18.3.
|
|
74
|
+
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
|
-
"tsup": "^8.3.
|
|
77
|
-
"typescript": "^5.6.
|
|
78
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
79
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
76
|
+
"tsup": "^8.3.5",
|
|
77
|
+
"typescript": "^5.6.3",
|
|
78
|
+
"@kubb/config-ts": "3.0.0-beta.11",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.11"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -18,24 +18,68 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
21
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
22
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
26
28
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
27
29
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
28
30
|
typeSchemas: OperationSchemas
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
32
34
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
33
35
|
|
|
36
|
+
if (paramsType === 'object') {
|
|
37
|
+
return FunctionParams.factory({
|
|
38
|
+
data: {
|
|
39
|
+
mode: 'object',
|
|
40
|
+
children: {
|
|
41
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
data: typeSchemas.request?.name
|
|
43
|
+
? {
|
|
44
|
+
type: typeSchemas.request?.name,
|
|
45
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
46
|
+
}
|
|
47
|
+
: undefined,
|
|
48
|
+
params: typeSchemas.queryParams?.name
|
|
49
|
+
? {
|
|
50
|
+
type: typeSchemas.queryParams?.name,
|
|
51
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
headers: typeSchemas.headerParams?.name
|
|
55
|
+
? {
|
|
56
|
+
type: typeSchemas.headerParams?.name,
|
|
57
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
type: `
|
|
64
|
+
{
|
|
65
|
+
query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
66
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
default: '{}',
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
34
74
|
return FunctionParams.factory({
|
|
35
|
-
pathParams:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
pathParams: typeSchemas.pathParams?.name
|
|
76
|
+
? {
|
|
77
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
79
|
+
type: typeSchemas.pathParams?.name,
|
|
80
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
39
83
|
data: typeSchemas.request?.name
|
|
40
84
|
? {
|
|
41
85
|
type: typeSchemas.request?.name,
|
|
@@ -71,6 +115,7 @@ export function InfiniteQuery({
|
|
|
71
115
|
queryKeyTypeName,
|
|
72
116
|
queryOptionsName,
|
|
73
117
|
queryKeyName,
|
|
118
|
+
paramsType,
|
|
74
119
|
pathParamsType,
|
|
75
120
|
dataReturnType,
|
|
76
121
|
typeSchemas,
|
|
@@ -85,10 +130,12 @@ export function InfiniteQuery({
|
|
|
85
130
|
typeSchemas,
|
|
86
131
|
})
|
|
87
132
|
const queryOptionsParams = QueryOptions.getParams({
|
|
133
|
+
paramsType,
|
|
88
134
|
pathParamsType,
|
|
89
135
|
typeSchemas,
|
|
90
136
|
})
|
|
91
137
|
const params = getParams({
|
|
138
|
+
paramsType,
|
|
92
139
|
pathParamsType,
|
|
93
140
|
dataReturnType,
|
|
94
141
|
typeSchemas,
|
|
@@ -14,6 +14,7 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
19
20
|
initialPageParam: Infinite['initialPageParam']
|
|
@@ -22,16 +23,54 @@ type Props = {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
type GetParamsProps = {
|
|
26
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
25
27
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
26
28
|
typeSchemas: OperationSchemas
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
31
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
32
|
+
if (paramsType === 'object') {
|
|
33
|
+
return FunctionParams.factory({
|
|
34
|
+
data: {
|
|
35
|
+
mode: 'object',
|
|
36
|
+
children: {
|
|
37
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
38
|
+
data: typeSchemas.request?.name
|
|
39
|
+
? {
|
|
40
|
+
type: typeSchemas.request?.name,
|
|
41
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
42
|
+
}
|
|
43
|
+
: undefined,
|
|
44
|
+
params: typeSchemas.queryParams?.name
|
|
45
|
+
? {
|
|
46
|
+
type: typeSchemas.queryParams?.name,
|
|
47
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
48
|
+
}
|
|
49
|
+
: undefined,
|
|
50
|
+
headers: typeSchemas.headerParams?.name
|
|
51
|
+
? {
|
|
52
|
+
type: typeSchemas.headerParams?.name,
|
|
53
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
54
|
+
}
|
|
55
|
+
: undefined,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
config: {
|
|
59
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
60
|
+
default: '{}',
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
30
65
|
return FunctionParams.factory({
|
|
31
|
-
pathParams:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
pathParams: typeSchemas.pathParams?.name
|
|
67
|
+
? {
|
|
68
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
69
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
70
|
+
type: typeSchemas.pathParams?.name,
|
|
71
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
72
|
+
}
|
|
73
|
+
: undefined,
|
|
35
74
|
data: typeSchemas.request?.name
|
|
36
75
|
? {
|
|
37
76
|
type: typeSchemas.request?.name,
|
|
@@ -63,14 +102,16 @@ export function InfiniteQueryOptions({
|
|
|
63
102
|
initialPageParam,
|
|
64
103
|
cursorParam,
|
|
65
104
|
typeSchemas,
|
|
105
|
+
paramsType,
|
|
66
106
|
dataReturnType,
|
|
67
107
|
pathParamsType,
|
|
68
108
|
queryParam,
|
|
69
109
|
queryKeyName,
|
|
70
110
|
}: Props): ReactNode {
|
|
71
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
111
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
72
112
|
const clientParams = Client.getParams({
|
|
73
113
|
typeSchemas,
|
|
114
|
+
paramsType,
|
|
74
115
|
pathParamsType,
|
|
75
116
|
})
|
|
76
117
|
const queryKeyParams = QueryKey.getParams({
|
|
@@ -109,7 +150,8 @@ export function InfiniteQueryOptions({
|
|
|
109
150
|
return (
|
|
110
151
|
<File.Source name={name} isExportable isIndexable>
|
|
111
152
|
<Function name={name} export params={params.toConstructor()}>
|
|
112
|
-
{
|
|
153
|
+
{infiniteOverrideParams &&
|
|
154
|
+
`
|
|
113
155
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
114
156
|
return infiniteQueryOptions({
|
|
115
157
|
${enabledText}
|
|
@@ -121,6 +163,19 @@ export function InfiniteQueryOptions({
|
|
|
121
163
|
},
|
|
122
164
|
${queryOptions.join('\n')}
|
|
123
165
|
})
|
|
166
|
+
`}
|
|
167
|
+
{!infiniteOverrideParams &&
|
|
168
|
+
`
|
|
169
|
+
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
170
|
+
return infiniteQueryOptions({
|
|
171
|
+
${enabledText}
|
|
172
|
+
queryKey,
|
|
173
|
+
queryFn: async ({ signal }) => {
|
|
174
|
+
config.signal = signal
|
|
175
|
+
return ${clientName}(${clientParams.toCall()})
|
|
176
|
+
},
|
|
177
|
+
${queryOptions.join('\n')}
|
|
178
|
+
})
|
|
124
179
|
`}
|
|
125
180
|
</Function>
|
|
126
181
|
</File.Source>
|
|
@@ -20,6 +20,7 @@ type Props = {
|
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
22
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
23
24
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -53,7 +54,9 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
53
54
|
: undefined,
|
|
54
55
|
})
|
|
55
56
|
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
56
|
-
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`]
|
|
57
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined]
|
|
58
|
+
.filter(Boolean)
|
|
59
|
+
.join(', ')
|
|
57
60
|
|
|
58
61
|
return FunctionParams.factory({
|
|
59
62
|
options: {
|
|
@@ -68,7 +71,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
68
71
|
})
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
74
|
+
export function Mutation({ name, clientName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
72
75
|
const mutationKeyParams = MutationKey.getParams({
|
|
73
76
|
pathParamsType,
|
|
74
77
|
typeSchemas,
|
|
@@ -81,6 +84,7 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
81
84
|
})
|
|
82
85
|
|
|
83
86
|
const clientParams = Client.getParams({
|
|
87
|
+
paramsType,
|
|
84
88
|
typeSchemas,
|
|
85
89
|
pathParamsType,
|
|
86
90
|
})
|
|
@@ -127,7 +131,9 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
127
131
|
|
|
128
132
|
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
129
133
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
130
|
-
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`]
|
|
134
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined]
|
|
135
|
+
.filter(Boolean)
|
|
136
|
+
.join(', ')
|
|
131
137
|
|
|
132
138
|
return (
|
|
133
139
|
<File.Source name={name} isExportable isIndexable>
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,24 +18,68 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
21
22
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
22
23
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
26
28
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
27
29
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
28
30
|
typeSchemas: OperationSchemas
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
32
34
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
33
35
|
|
|
36
|
+
if (paramsType === 'object') {
|
|
37
|
+
return FunctionParams.factory({
|
|
38
|
+
data: {
|
|
39
|
+
mode: 'object',
|
|
40
|
+
children: {
|
|
41
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
data: typeSchemas.request?.name
|
|
43
|
+
? {
|
|
44
|
+
type: typeSchemas.request?.name,
|
|
45
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
46
|
+
}
|
|
47
|
+
: undefined,
|
|
48
|
+
params: typeSchemas.queryParams?.name
|
|
49
|
+
? {
|
|
50
|
+
type: typeSchemas.queryParams?.name,
|
|
51
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
headers: typeSchemas.headerParams?.name
|
|
55
|
+
? {
|
|
56
|
+
type: typeSchemas.headerParams?.name,
|
|
57
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
type: `
|
|
64
|
+
{
|
|
65
|
+
query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
66
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
default: '{}',
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
34
74
|
return FunctionParams.factory({
|
|
35
|
-
pathParams:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
pathParams: typeSchemas.pathParams?.name
|
|
76
|
+
? {
|
|
77
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
79
|
+
type: typeSchemas.pathParams?.name,
|
|
80
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
39
83
|
data: typeSchemas.request?.name
|
|
40
84
|
? {
|
|
41
85
|
type: typeSchemas.request?.name,
|
|
@@ -66,7 +110,17 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
|
|
|
66
110
|
})
|
|
67
111
|
}
|
|
68
112
|
|
|
69
|
-
export function Query({
|
|
113
|
+
export function Query({
|
|
114
|
+
name,
|
|
115
|
+
queryKeyTypeName,
|
|
116
|
+
queryOptionsName,
|
|
117
|
+
queryKeyName,
|
|
118
|
+
paramsType,
|
|
119
|
+
pathParamsType,
|
|
120
|
+
dataReturnType,
|
|
121
|
+
typeSchemas,
|
|
122
|
+
operation,
|
|
123
|
+
}: Props): ReactNode {
|
|
70
124
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
71
125
|
const returnType = `UseQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
72
126
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
@@ -76,10 +130,12 @@ export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
76
130
|
typeSchemas,
|
|
77
131
|
})
|
|
78
132
|
const queryOptionsParams = QueryOptions.getParams({
|
|
133
|
+
paramsType,
|
|
79
134
|
pathParamsType,
|
|
80
135
|
typeSchemas,
|
|
81
136
|
})
|
|
82
137
|
const params = getParams({
|
|
138
|
+
paramsType,
|
|
83
139
|
pathParamsType,
|
|
84
140
|
dataReturnType,
|
|
85
141
|
typeSchemas,
|
|
@@ -14,20 +14,59 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
type GetParamsProps = {
|
|
22
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
21
23
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
22
24
|
typeSchemas: OperationSchemas
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
27
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
28
|
+
if (paramsType === 'object') {
|
|
29
|
+
return FunctionParams.factory({
|
|
30
|
+
data: {
|
|
31
|
+
mode: 'object',
|
|
32
|
+
children: {
|
|
33
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
34
|
+
data: typeSchemas.request?.name
|
|
35
|
+
? {
|
|
36
|
+
type: typeSchemas.request?.name,
|
|
37
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
params: typeSchemas.queryParams?.name
|
|
41
|
+
? {
|
|
42
|
+
type: typeSchemas.queryParams?.name,
|
|
43
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
46
|
+
headers: typeSchemas.headerParams?.name
|
|
47
|
+
? {
|
|
48
|
+
type: typeSchemas.headerParams?.name,
|
|
49
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
config: {
|
|
55
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
56
|
+
default: '{}',
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
26
61
|
return FunctionParams.factory({
|
|
27
|
-
pathParams:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
pathParams: typeSchemas.pathParams?.name
|
|
63
|
+
? {
|
|
64
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
65
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
66
|
+
type: typeSchemas.pathParams?.name,
|
|
67
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
31
70
|
data: typeSchemas.request?.name
|
|
32
71
|
? {
|
|
33
72
|
type: typeSchemas.request?.name,
|
|
@@ -53,10 +92,11 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
53
92
|
})
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
export function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
57
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
95
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
96
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
58
97
|
const clientParams = Client.getParams({
|
|
59
98
|
typeSchemas,
|
|
99
|
+
paramsType,
|
|
60
100
|
pathParamsType,
|
|
61
101
|
})
|
|
62
102
|
const queryKeyParams = QueryKey.getParams({
|