@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16
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-ESENIDWJ.js +608 -0
- package/dist/chunk-ESENIDWJ.js.map +1 -0
- package/dist/chunk-JQEH3UHY.cjs +618 -0
- package/dist/chunk-JQEH3UHY.cjs.map +1 -0
- package/dist/chunk-KRG2LWHM.cjs +606 -0
- package/dist/chunk-KRG2LWHM.cjs.map +1 -0
- package/dist/chunk-ME7ZFS5H.js +596 -0
- package/dist/chunk-ME7ZFS5H.js.map +1 -0
- package/dist/components.cjs +17 -5
- package/dist/components.d.cts +143 -5
- package/dist/components.d.ts +143 -5
- package/dist/components.js +1 -1
- package/dist/generators.cjs +25 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +15 -0
- package/dist/generators.d.ts +15 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +33 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +34 -77
- package/dist/index.js.map +1 -1
- package/dist/types-DJxL-JeY.d.cts +195 -0
- package/dist/types-DJxL-JeY.d.ts +195 -0
- package/package.json +23 -15
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +121 -0
- package/src/components/Mutation.tsx +112 -304
- package/src/components/Query.tsx +91 -593
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +64 -465
- package/src/components/SuspenseQuery.tsx +129 -0
- package/src/components/index.ts +3 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +64 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +64 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +59 -0
- package/src/generators/__snapshots__/findByTags.ts +64 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +64 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +64 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +64 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +74 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +74 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +77 -0
- package/src/generators/__snapshots__/updatePetById.ts +59 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +63 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +124 -0
- package/src/generators/mutationGenerator.tsx +94 -0
- package/src/generators/queryGenerator.tsx +121 -0
- package/src/generators/suspenseQueryGenerator.tsx +120 -0
- package/src/plugin.ts +38 -49
- package/src/types.ts +35 -59
- package/dist/chunk-AGLJPONA.cjs +0 -1423
- package/dist/chunk-AGLJPONA.cjs.map +0 -1
- package/dist/chunk-I7X4HNDR.js +0 -1413
- package/dist/chunk-I7X4HNDR.js.map +0 -1
- package/dist/index-BzoLlZve.d.cts +0 -537
- package/dist/index-BzoLlZve.d.ts +0 -537
- package/src/OperationGenerator.tsx +0 -57
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -74
- package/src/components/__snapshots__/gen/showPetById.ts +0 -67
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
package/src/plugin.ts
CHANGED
|
@@ -3,17 +3,14 @@ import path from 'node:path'
|
|
|
3
3
|
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
|
-
import { pluginOasName } from '@kubb/plugin-oas'
|
|
6
|
+
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
7
|
|
|
8
8
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
9
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
10
|
|
|
11
|
-
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
12
|
-
import { Mutation, Query, QueryKey, QueryOptions } from './components/index.ts'
|
|
13
|
-
|
|
14
11
|
import type { Plugin } from '@kubb/core'
|
|
15
12
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
16
|
-
import {
|
|
13
|
+
import { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'
|
|
17
14
|
import type { PluginReactQuery } from './types.ts'
|
|
18
15
|
|
|
19
16
|
export const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']
|
|
@@ -25,16 +22,13 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
25
22
|
exclude = [],
|
|
26
23
|
include,
|
|
27
24
|
override = [],
|
|
28
|
-
parser,
|
|
25
|
+
parser = 'client',
|
|
29
26
|
suspense = {},
|
|
30
27
|
infinite,
|
|
31
28
|
transformers = {},
|
|
32
|
-
dataReturnType = 'data',
|
|
33
29
|
pathParamsType = 'inline',
|
|
34
|
-
|
|
30
|
+
mutation = {},
|
|
35
31
|
query = {},
|
|
36
|
-
queryOptions = {},
|
|
37
|
-
templates,
|
|
38
32
|
} = options
|
|
39
33
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
40
34
|
|
|
@@ -45,12 +39,13 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
45
39
|
...output,
|
|
46
40
|
},
|
|
47
41
|
options: {
|
|
42
|
+
baseURL: undefined,
|
|
48
43
|
client: {
|
|
49
44
|
importPath: '@kubb/plugin-client/client',
|
|
45
|
+
dataReturnType: 'data',
|
|
46
|
+
pathParamsType: 'inline',
|
|
50
47
|
...options.client,
|
|
51
48
|
},
|
|
52
|
-
dataReturnType,
|
|
53
|
-
pathParamsType,
|
|
54
49
|
infinite: infinite
|
|
55
50
|
? {
|
|
56
51
|
queryParam: 'id',
|
|
@@ -60,30 +55,18 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
60
55
|
}
|
|
61
56
|
: false,
|
|
62
57
|
suspense,
|
|
63
|
-
query:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
? {
|
|
74
|
-
variablesType: 'hook',
|
|
75
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
76
|
-
...mutate,
|
|
77
|
-
}
|
|
78
|
-
: false,
|
|
79
|
-
templates: {
|
|
80
|
-
mutation: Mutation.templates,
|
|
81
|
-
query: Query.templates,
|
|
82
|
-
queryOptions: QueryOptions.templates,
|
|
83
|
-
queryKey: QueryKey.templates,
|
|
84
|
-
queryImports: QueryImports.templates,
|
|
85
|
-
...templates,
|
|
58
|
+
query: {
|
|
59
|
+
key: (key: unknown[]) => key,
|
|
60
|
+
methods: ['get'],
|
|
61
|
+
importPath: '@tanstack/react-query',
|
|
62
|
+
...query,
|
|
63
|
+
},
|
|
64
|
+
mutation: {
|
|
65
|
+
methods: ['post', 'put', 'patch', 'delete'],
|
|
66
|
+
importPath: '@tanstack/react-query',
|
|
67
|
+
...mutation,
|
|
86
68
|
},
|
|
69
|
+
pathParamsType,
|
|
87
70
|
parser,
|
|
88
71
|
},
|
|
89
72
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
@@ -112,7 +95,6 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
112
95
|
|
|
113
96
|
if (type === 'file' || type === 'function') {
|
|
114
97
|
resolvedName = camelCase(name, {
|
|
115
|
-
prefix: 'use',
|
|
116
98
|
isFile: type === 'file',
|
|
117
99
|
})
|
|
118
100
|
}
|
|
@@ -132,19 +114,26 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
132
114
|
const oas = await swaggerPlugin.context.getOas()
|
|
133
115
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
134
116
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
117
|
+
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
118
|
+
|
|
119
|
+
const operationGenerator = new OperationGenerator(
|
|
120
|
+
{
|
|
121
|
+
...this.plugin.options,
|
|
122
|
+
baseURL,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
oas,
|
|
126
|
+
pluginManager: this.pluginManager,
|
|
127
|
+
plugin: this.plugin,
|
|
128
|
+
contentType: swaggerPlugin.context.contentType,
|
|
129
|
+
exclude,
|
|
130
|
+
include,
|
|
131
|
+
override,
|
|
132
|
+
mode,
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
const files = await operationGenerator.build(queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator)
|
|
148
137
|
await this.addFile(...files)
|
|
149
138
|
|
|
150
139
|
if (this.config.output.exportType) {
|
package/src/types.ts
CHANGED
|
@@ -3,17 +3,6 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
3
3
|
|
|
4
4
|
import type { HttpMethod } from '@kubb/oas'
|
|
5
5
|
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
-
import type { Mutation } from './components/Mutation.tsx'
|
|
7
|
-
import type { Query as QueryTemplate } from './components/Query.tsx'
|
|
8
|
-
import type { QueryKey } from './components/QueryKey.tsx'
|
|
9
|
-
import type { QueryOptions as QueryOptionsTemplate } from './components/QueryOptions.tsx'
|
|
10
|
-
|
|
11
|
-
type Templates = {
|
|
12
|
-
mutation?: typeof Mutation.templates | false
|
|
13
|
-
query?: typeof QueryTemplate.templates | false
|
|
14
|
-
queryOptions?: typeof QueryOptionsTemplate.templates | false
|
|
15
|
-
queryKey?: typeof QueryKey.templates | false
|
|
16
|
-
}
|
|
17
6
|
|
|
18
7
|
export type Suspense = object
|
|
19
8
|
|
|
@@ -21,7 +10,7 @@ export type Query = {
|
|
|
21
10
|
/**
|
|
22
11
|
* Customize the queryKey, here you can specify a suffix.
|
|
23
12
|
*/
|
|
24
|
-
|
|
13
|
+
key: (key: unknown[]) => unknown[]
|
|
25
14
|
/**
|
|
26
15
|
* Define which HttpMethods can be used for queries
|
|
27
16
|
* @default ['get']
|
|
@@ -37,14 +26,7 @@ export type Query = {
|
|
|
37
26
|
importPath?: string
|
|
38
27
|
}
|
|
39
28
|
|
|
40
|
-
export type
|
|
41
|
-
|
|
42
|
-
export type Mutate = {
|
|
43
|
-
/**
|
|
44
|
-
* Define the way of passing through the queryParams, headerParams and data.
|
|
45
|
-
* @default `'hook'`
|
|
46
|
-
*/
|
|
47
|
-
variablesType: 'mutate' | 'hook'
|
|
29
|
+
export type Mutation = {
|
|
48
30
|
/**
|
|
49
31
|
* Define which HttpMethods can be used for mutations
|
|
50
32
|
* @default ['post', 'put', 'delete']
|
|
@@ -131,6 +113,16 @@ export type Options = {
|
|
|
131
113
|
* @default '@kubb/plugin-client/client'
|
|
132
114
|
*/
|
|
133
115
|
importPath?: string
|
|
116
|
+
/**
|
|
117
|
+
* ReturnType that needs to be used when calling client().
|
|
118
|
+
*
|
|
119
|
+
* `Data` will return ResponseConfig[data].
|
|
120
|
+
*
|
|
121
|
+
* `Full` will return ResponseConfig.
|
|
122
|
+
* @default `'data'`
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
dataReturnType?: 'data' | 'full'
|
|
134
126
|
}
|
|
135
127
|
/**
|
|
136
128
|
* ReturnType that needs to be used when calling client().
|
|
@@ -141,31 +133,7 @@ export type Options = {
|
|
|
141
133
|
* @default `'data'`
|
|
142
134
|
* @private
|
|
143
135
|
*/
|
|
144
|
-
|
|
145
|
-
* ReturnType that needs to be used when calling client().
|
|
146
|
-
*
|
|
147
|
-
* `Data` will return ResponseConfig[data].
|
|
148
|
-
*
|
|
149
|
-
* `Full` will return ResponseConfig.
|
|
150
|
-
* @default `'data'`
|
|
151
|
-
* @private
|
|
152
|
-
*/
|
|
153
|
-
dataReturnType?: 'data' | 'full'
|
|
154
|
-
/**
|
|
155
|
-
* How to pass your pathParams.
|
|
156
|
-
*
|
|
157
|
-
* `object` will return the pathParams as an object.
|
|
158
|
-
*
|
|
159
|
-
* `inline` will return the pathParams as comma separated params.
|
|
160
|
-
* @default `'inline'`
|
|
161
|
-
* @private
|
|
162
|
-
*/
|
|
163
|
-
pathParamsType?: 'object' | 'inline'
|
|
164
|
-
/**
|
|
165
|
-
* Which parser can be used before returning the data to `@tanstack/query`.
|
|
166
|
-
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
167
|
-
*/
|
|
168
|
-
parser?: 'zod'
|
|
136
|
+
|
|
169
137
|
/**
|
|
170
138
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
171
139
|
*/
|
|
@@ -178,6 +146,16 @@ export type Options = {
|
|
|
178
146
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
179
147
|
*/
|
|
180
148
|
override?: Array<Override<ResolvedOptions>>
|
|
149
|
+
/**
|
|
150
|
+
* How to pass your pathParams.
|
|
151
|
+
*
|
|
152
|
+
* `object` will return the pathParams as an object.
|
|
153
|
+
*
|
|
154
|
+
* `inline` will return the pathParams as comma separated params.
|
|
155
|
+
* @default `'inline'`
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
pathParamsType?: 'object' | 'inline'
|
|
181
159
|
/**
|
|
182
160
|
* When set, an infiniteQuery hooks will be added.
|
|
183
161
|
*/
|
|
@@ -190,37 +168,35 @@ export type Options = {
|
|
|
190
168
|
* Override some useQuery behaviours.
|
|
191
169
|
*/
|
|
192
170
|
query?: Partial<Query> | false
|
|
193
|
-
queryOptions?: Partial<QueryOptions> | false
|
|
194
171
|
/**
|
|
195
172
|
* Override some useMutation behaviours.
|
|
196
173
|
*/
|
|
197
|
-
|
|
174
|
+
mutation?: Mutation | false
|
|
175
|
+
/**
|
|
176
|
+
* Which parser can be used before returning the data to `@tanstack/query`.
|
|
177
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
178
|
+
*/
|
|
179
|
+
parser?: 'client' | 'zod'
|
|
198
180
|
transformers?: {
|
|
199
181
|
/**
|
|
200
182
|
* Customize the names based on the type that is provided by the plugin.
|
|
201
183
|
*/
|
|
202
184
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
203
185
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Make it possible to override one of the templates
|
|
206
|
-
*/
|
|
207
|
-
templates?: Partial<Templates>
|
|
208
186
|
}
|
|
209
187
|
|
|
210
188
|
type ResolvedOptions = {
|
|
189
|
+
baseURL: string | undefined
|
|
211
190
|
client: Required<NonNullable<PluginReactQuery['options']['client']>>
|
|
212
|
-
|
|
213
|
-
pathParamsType: NonNullable<
|
|
214
|
-
parser: PluginReactQuery['options']['parser']
|
|
191
|
+
parser: Required<NonNullable<Options['parser']>>
|
|
192
|
+
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
215
193
|
/**
|
|
216
194
|
* Only used of infinite
|
|
217
195
|
*/
|
|
218
|
-
infinite: Infinite | false
|
|
196
|
+
infinite: NonNullable<Infinite> | false
|
|
219
197
|
suspense: Suspense | false
|
|
220
|
-
query: Query | false
|
|
221
|
-
|
|
222
|
-
mutate: Mutate | false
|
|
223
|
-
templates: NonNullable<Templates>
|
|
198
|
+
query: NonNullable<Required<Query>> | false
|
|
199
|
+
mutation: NonNullable<Required<Mutation>> | false
|
|
224
200
|
}
|
|
225
201
|
|
|
226
202
|
export type FileMeta = {
|