@kubb/plugin-react-query 3.0.0-beta.1 → 3.0.0-beta.10
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-37VO6QXJ.cjs → chunk-24SL7I66.cjs} +38 -24
- package/dist/chunk-24SL7I66.cjs.map +1 -0
- 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-LBVGJA4Q.js} +21 -7
- package/dist/chunk-LBVGJA4Q.js.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 +6 -4
- 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 +5 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-5pnOmDmM.d.cts → types-Dlwxp28D.d.cts} +33 -34
- package/dist/{types-5pnOmDmM.d.ts → types-Dlwxp28D.d.ts} +33 -34
- 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 +3 -1
- package/src/generators/mutationGenerator.tsx +2 -1
- package/src/generators/queryGenerator.tsx +3 -1
- package/src/generators/suspenseQueryGenerator.tsx +3 -0
- package/src/plugin.ts +3 -1
- package/src/types.ts +17 -21
- 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
|
/**
|
|
@@ -38,27 +38,28 @@ type Options$1 = {
|
|
|
38
38
|
importPath?: string;
|
|
39
39
|
/**
|
|
40
40
|
* ReturnType that will be used when calling the client.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `Full` will return ResponseConfig.
|
|
45
|
-
* @default `'data'`
|
|
46
|
-
* @private
|
|
41
|
+
* - 'data' will return ResponseConfig[data].
|
|
42
|
+
* - 'full' will return ResponseConfig.
|
|
43
|
+
* @default 'data'
|
|
47
44
|
*/
|
|
48
45
|
dataReturnType?: 'data' | 'full';
|
|
46
|
+
/**
|
|
47
|
+
* How to pass your params
|
|
48
|
+
* - 'object' will return the params and pathParams as an object.
|
|
49
|
+
* - 'inline' will return the params as comma separated params.
|
|
50
|
+
* @default 'inline'
|
|
51
|
+
*/
|
|
52
|
+
paramsType?: 'object' | 'inline';
|
|
49
53
|
/**
|
|
50
54
|
* How to pass your pathParams.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* `inline` will return the pathParams as comma separated params.
|
|
55
|
-
* @default `'inline'`
|
|
56
|
-
* @private
|
|
55
|
+
* - 'object' will return the pathParams as an object.
|
|
56
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
57
|
+
* @default 'inline'
|
|
57
58
|
*/
|
|
58
59
|
pathParamsType?: 'object' | 'inline';
|
|
59
60
|
/**
|
|
60
61
|
* Which parser can be used before returning the data
|
|
61
|
-
*
|
|
62
|
+
* - 'zod' will use `@kubb/plugin-zod` to parse the data.
|
|
62
63
|
* @default 'client'
|
|
63
64
|
*/
|
|
64
65
|
parser?: 'client' | 'zod';
|
|
@@ -81,6 +82,7 @@ type ResolvedOptions$1 = {
|
|
|
81
82
|
importPath: NonNullable<Options$1['importPath']>;
|
|
82
83
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
83
84
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
85
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
84
86
|
};
|
|
85
87
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
86
88
|
|
|
@@ -126,7 +128,7 @@ type Mutation = {
|
|
|
126
128
|
type Infinite = {
|
|
127
129
|
/**
|
|
128
130
|
* Specify the params key used for `pageParam`.
|
|
129
|
-
* @default
|
|
131
|
+
* @default 'id'
|
|
130
132
|
*/
|
|
131
133
|
queryParam: string;
|
|
132
134
|
/**
|
|
@@ -135,13 +137,14 @@ type Infinite = {
|
|
|
135
137
|
cursorParam?: string | undefined;
|
|
136
138
|
/**
|
|
137
139
|
* The initial value, the value of the first page.
|
|
138
|
-
* @default
|
|
140
|
+
* @default 0
|
|
139
141
|
*/
|
|
140
142
|
initialPageParam: unknown;
|
|
141
143
|
};
|
|
142
144
|
type Options = {
|
|
143
145
|
/**
|
|
144
|
-
*
|
|
146
|
+
* Specify the export location for the files and define the behavior of the output
|
|
147
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
145
148
|
*/
|
|
146
149
|
output?: Output;
|
|
147
150
|
/**
|
|
@@ -149,15 +152,6 @@ type Options = {
|
|
|
149
152
|
*/
|
|
150
153
|
group?: Group;
|
|
151
154
|
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
155
|
/**
|
|
162
156
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
163
157
|
*/
|
|
@@ -170,14 +164,18 @@ type Options = {
|
|
|
170
164
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
171
165
|
*/
|
|
172
166
|
override?: Array<Override<ResolvedOptions>>;
|
|
167
|
+
/**
|
|
168
|
+
* How to pass your params
|
|
169
|
+
* - 'object' will return the params and pathParams as an object.
|
|
170
|
+
* - 'inline' will return the params as comma separated params.
|
|
171
|
+
* @default 'inline'
|
|
172
|
+
*/
|
|
173
|
+
paramsType?: 'object' | 'inline';
|
|
173
174
|
/**
|
|
174
175
|
* How to pass your pathParams.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* `inline` will return the pathParams as comma separated params.
|
|
179
|
-
* @default `'inline'`
|
|
180
|
-
* @private
|
|
176
|
+
* - 'object' will return the pathParams as an object.
|
|
177
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
178
|
+
* @default 'inline'
|
|
181
179
|
*/
|
|
182
180
|
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
183
181
|
/**
|
|
@@ -195,9 +193,9 @@ type Options = {
|
|
|
195
193
|
/**
|
|
196
194
|
* Override some useMutation behaviours.
|
|
197
195
|
*/
|
|
198
|
-
mutation?: Mutation | false;
|
|
196
|
+
mutation?: Partial<Mutation> | false;
|
|
199
197
|
/**
|
|
200
|
-
* Which parser
|
|
198
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
201
199
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
202
200
|
*/
|
|
203
201
|
parser?: PluginClient['options']['parser'];
|
|
@@ -218,6 +216,7 @@ type ResolvedOptions = {
|
|
|
218
216
|
client: Required<NonNullable<PluginReactQuery['options']['client']>>;
|
|
219
217
|
parser: Required<NonNullable<Options['parser']>>;
|
|
220
218
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
219
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
221
220
|
/**
|
|
222
221
|
* Only used of infinite
|
|
223
222
|
*/
|
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.10",
|
|
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.10",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.10",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.10",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.10",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.10",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.10",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
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.10",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.10"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
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({
|