@kubb/plugin-react-query 3.0.0-alpha.1 → 3.0.0-alpha.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-JFX7DCS7.cjs → chunk-7ZODZVKP.cjs} +116 -150
- package/dist/chunk-7ZODZVKP.cjs.map +1 -0
- package/dist/{chunk-5IL6M74X.js → chunk-ZYTZV43V.js} +168 -202
- package/dist/chunk-ZYTZV43V.js.map +1 -0
- package/dist/components.cjs +2 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -2
- package/dist/components.d.ts +1 -2
- package/dist/components.js +1 -3
- package/dist/{index-C9fwRDH7.d.cts → index-5kpkk-7M.d.cts} +7 -41
- package/dist/{index-C9fwRDH7.d.ts → index-5kpkk-7M.d.ts} +7 -41
- package/dist/index.cjs +28 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +17 -53
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/src/OperationGenerator.tsx +0 -29
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +14 -9
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +14 -9
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +14 -9
- package/src/__snapshots__/queryOptions/getPetById.ts +9 -5
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +11 -7
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +6 -3
- package/src/components/Mutation.tsx +30 -30
- package/src/components/Query.tsx +74 -78
- package/src/components/QueryKey.tsx +13 -9
- package/src/components/QueryOptions.tsx +21 -13
- package/src/components/SchemaType.tsx +9 -5
- package/src/components/__snapshots__/gen/showPetById.ts +58 -48
- package/src/components/__snapshots__/gen/useCreatePets.ts +36 -36
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +36 -37
- package/src/components/index.ts +0 -1
- package/src/plugin.ts +16 -34
- package/src/types.ts +0 -3
- package/dist/chunk-5IL6M74X.js.map +0 -1
- package/dist/chunk-JFX7DCS7.cjs.map +0 -1
- package/src/__snapshots__/upload/UploadFile.ts +0 -67
- package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
- package/src/components/Operations.tsx +0 -74
|
@@ -1,57 +1,67 @@
|
|
|
1
1
|
type GetPetsUuidClient = typeof client<GetPetsUuidQueryResponse, never, never>
|
|
2
|
-
type GetPetsUuid = {
|
|
3
|
-
data: GetPetsUuidQueryResponse
|
|
4
|
-
error: never
|
|
5
|
-
request: never
|
|
6
|
-
pathParams: never
|
|
7
|
-
queryParams: never
|
|
8
|
-
headerParams: never
|
|
9
|
-
response: GetPetsUuidQueryResponse
|
|
10
|
-
client: {
|
|
11
|
-
parameters: Partial<Parameters<GetPetsUuidClient>[0]>
|
|
12
|
-
return: Awaited<ReturnType<GetPetsUuidClient>>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
2
|
|
|
16
|
-
|
|
3
|
+
type GetPetsUuid =
|
|
4
|
+
{
|
|
5
|
+
data: GetPetsUuidQueryResponse
|
|
6
|
+
error: never
|
|
7
|
+
request: never
|
|
8
|
+
pathParams: never
|
|
9
|
+
queryParams: never
|
|
10
|
+
headerParams: never
|
|
11
|
+
response: GetPetsUuidQueryResponse
|
|
12
|
+
client: {
|
|
13
|
+
parameters: Partial<Parameters<GetPetsUuidClient>[0]>
|
|
14
|
+
return: Awaited<ReturnType<GetPetsUuidClient>>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const GetPetsUuidQueryKey = () => [{ url: '/pets/:uuid', params: {uuid:uuid} }] as const
|
|
19
|
+
|
|
17
20
|
export type GetPetsUuidQueryKey = ReturnType<typeof GetPetsUuidQueryKey>
|
|
18
|
-
export function GetPetsUuidQueryOptions<TData = GetPetsUuid['response'], TQueryData = GetPetsUuid['response']>(
|
|
19
|
-
options: GetPetsUuid['client']['parameters'] = {},
|
|
20
|
-
): WithRequired<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid['error'], TData, TQueryData>, 'queryKey'> {
|
|
21
|
-
const queryKey = GetPetsUuidQueryKey()
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
export function GetPetsUuidQueryOptions<TData = GetPetsUuid["response"], TQueryData = GetPetsUuid["response"]>(options: GetPetsUuid['client']['parameters'] = {}): WithRequired<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid["error"], TData, TQueryData>, 'queryKey'> {
|
|
23
|
+
|
|
24
|
+
const queryKey = GetPetsUuidQueryKey()
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
queryKey,
|
|
28
|
+
queryFn: async () => {
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const res = await client<GetPetsUuid['data'],GetPetsUuid['error']>({
|
|
32
|
+
method: "get",
|
|
28
33
|
url: `/pets/${uuid}`,
|
|
29
|
-
...options
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
...options
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return res.data
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
35
43
|
}
|
|
44
|
+
|
|
36
45
|
/**
|
|
37
46
|
* @link /pets/:uuid
|
|
38
47
|
*/
|
|
39
|
-
export function useGetPetsUuid<TData = GetPetsUuid[
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
export function useGetPetsUuid<TData = GetPetsUuid["response"], TQueryData = GetPetsUuid["response"], TQueryKey extends QueryKey = GetPetsUuidQueryKey>(options: {
|
|
49
|
+
query?: Partial<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid['error'], TData, TQueryData, TQueryKey>>,
|
|
50
|
+
client?: GetPetsUuid['client']['parameters']
|
|
51
|
+
} = {}): UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey } {
|
|
52
|
+
|
|
53
|
+
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
54
|
+
const queryKey = queryOptions?.queryKey ?? GetPetsUuidQueryKey()
|
|
55
|
+
|
|
56
|
+
const query = useQuery<GetPetsUuid['data'], GetPetsUuid['error'], TData, any>({
|
|
57
|
+
...GetPetsUuidQueryOptions<TData, TQueryData>(clientOptions),
|
|
58
|
+
queryKey,
|
|
59
|
+
...queryOptions
|
|
60
|
+
}) as UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey }
|
|
61
|
+
|
|
62
|
+
query.queryKey = queryKey as TQueryKey
|
|
63
|
+
|
|
64
|
+
return query
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
|
|
3
|
+
type CreatePets =
|
|
4
|
+
{
|
|
5
|
+
data: CreatePetsMutationResponse
|
|
6
|
+
error: never
|
|
7
|
+
request: CreatePetsMutationRequest
|
|
8
|
+
pathParams: CreatePetsPathParams
|
|
9
|
+
queryParams: CreatePetsQueryParams
|
|
10
|
+
headerParams: CreatePetsHeaderParams
|
|
11
|
+
response: CreatePetsMutationResponse
|
|
12
|
+
client: {
|
|
13
|
+
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
14
|
+
return: Awaited<ReturnType<CreatePetsClient>>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @summary Create a pet
|
|
18
20
|
* @link /pets/:uuid
|
|
19
21
|
*/
|
|
20
|
-
export function useCreatePets(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({
|
|
34
|
-
method: 'post',
|
|
22
|
+
export function useCreatePets(uuid: CreatePetsPathParams["uuid"], headers: CreatePets['headerParams'], params?: CreatePets['queryParams'], options: {
|
|
23
|
+
mutation?: UseMutationOptions<CreatePets["response"], CreatePets["error"], CreatePets["request"]>,
|
|
24
|
+
client?: CreatePets['client']['parameters']
|
|
25
|
+
} = {}) {
|
|
26
|
+
|
|
27
|
+
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
28
|
+
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationFn: async(data) => {
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const res = await client<CreatePets["data"], CreatePets["error"], CreatePets["request"]>({
|
|
34
|
+
method: "post",
|
|
35
35
|
url: `/pets/${uuid}`,
|
|
36
36
|
params,
|
|
37
37
|
data,
|
|
38
38
|
headers: { ...headers, ...clientOptions.headers },
|
|
39
|
-
...clientOptions
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
39
|
+
...clientOptions
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return res.data
|
|
43
|
+
},
|
|
44
|
+
...mutationOptions
|
|
45
|
+
})
|
|
46
|
+
}
|
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
|
|
3
|
+
type CreatePets =
|
|
4
|
+
{
|
|
5
|
+
data: CreatePetsMutationResponse
|
|
6
|
+
error: never
|
|
7
|
+
request: CreatePetsMutationRequest
|
|
8
|
+
pathParams: CreatePetsPathParams
|
|
9
|
+
queryParams: CreatePetsQueryParams
|
|
10
|
+
headerParams: CreatePetsHeaderParams
|
|
11
|
+
response: CreatePetsMutationResponse
|
|
12
|
+
client: {
|
|
13
|
+
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
14
|
+
return: Awaited<ReturnType<CreatePetsClient>>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @summary Create a pet
|
|
18
20
|
* @link /pets/:uuid
|
|
19
21
|
*/
|
|
20
|
-
export function useCreatePets(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mutationFn: async ({ uuid, headers, data, params }) => {
|
|
34
|
-
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({
|
|
35
|
-
method: 'post',
|
|
22
|
+
export function useCreatePets(options: {
|
|
23
|
+
mutation?: UseMutationOptions<CreatePets["response"], CreatePets["error"], { uuid: CreatePetsPathParams["uuid"]; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] }>,
|
|
24
|
+
client?: CreatePets['client']['parameters']
|
|
25
|
+
} = {}) {
|
|
26
|
+
|
|
27
|
+
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
28
|
+
|
|
29
|
+
return useMutation({
|
|
30
|
+
mutationFn: async({ uuid, headers, data, params }) => {
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const res = await client<CreatePets["data"], CreatePets["error"], CreatePets["request"]>({
|
|
34
|
+
method: "post",
|
|
36
35
|
url: `/pets/${uuid}`,
|
|
37
36
|
params,
|
|
38
37
|
data,
|
|
39
38
|
headers: { ...headers, ...clientOptions.headers },
|
|
40
|
-
...clientOptions
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
39
|
+
...clientOptions
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return res.data
|
|
43
|
+
},
|
|
44
|
+
...mutationOptions
|
|
45
|
+
})
|
|
46
|
+
}
|
package/src/components/index.ts
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -4,12 +4,12 @@ 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
6
|
import { 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
11
|
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
12
|
-
import { Mutation,
|
|
12
|
+
import { Mutation, Query, QueryKey, QueryOptions } from './components/index.ts'
|
|
13
13
|
|
|
14
14
|
import type { Plugin } from '@kubb/core'
|
|
15
15
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
@@ -40,6 +40,10 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
40
40
|
|
|
41
41
|
return {
|
|
42
42
|
name: pluginReactQueryName,
|
|
43
|
+
output: {
|
|
44
|
+
exportType: 'barrelNamed',
|
|
45
|
+
...output,
|
|
46
|
+
},
|
|
43
47
|
options: {
|
|
44
48
|
client: {
|
|
45
49
|
importPath: '@kubb/plugin-client/client',
|
|
@@ -78,7 +82,6 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
78
82
|
queryOptions: QueryOptions.templates,
|
|
79
83
|
queryKey: QueryKey.templates,
|
|
80
84
|
queryImports: QueryImports.templates,
|
|
81
|
-
operations: Operations.templates,
|
|
82
85
|
...templates,
|
|
83
86
|
},
|
|
84
87
|
parser,
|
|
@@ -126,7 +129,7 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
126
129
|
async buildStart() {
|
|
127
130
|
const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
|
|
128
131
|
|
|
129
|
-
const oas = await swaggerPlugin.
|
|
132
|
+
const oas = await swaggerPlugin.context.getOas()
|
|
130
133
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
131
134
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
132
135
|
|
|
@@ -134,7 +137,7 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
134
137
|
oas,
|
|
135
138
|
pluginManager: this.pluginManager,
|
|
136
139
|
plugin: this.plugin,
|
|
137
|
-
contentType: swaggerPlugin.
|
|
140
|
+
contentType: swaggerPlugin.context.contentType,
|
|
138
141
|
exclude,
|
|
139
142
|
include,
|
|
140
143
|
override,
|
|
@@ -143,41 +146,20 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
143
146
|
|
|
144
147
|
const files = await operationGenerator.build()
|
|
145
148
|
await this.addFile(...files)
|
|
146
|
-
},
|
|
147
|
-
async writeFile(path, source) {
|
|
148
|
-
if (!path.endsWith('.ts') || !source) {
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
async buildEnd() {
|
|
155
|
-
if (this.config.output.write === false) {
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
160
|
-
|
|
161
|
-
if (group?.type === 'tag') {
|
|
162
|
-
const rootFiles = await getGroupedByTagFiles({
|
|
163
|
-
logger: this.logger,
|
|
164
|
-
files: this.fileManager.files,
|
|
165
|
-
plugin: this.plugin,
|
|
166
|
-
template,
|
|
167
|
-
exportAs: group.exportAs || '{{tag}}Hooks',
|
|
150
|
+
if (this.config.output.exportType) {
|
|
151
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
168
152
|
root,
|
|
169
153
|
output,
|
|
154
|
+
files: this.fileManager.files,
|
|
155
|
+
meta: {
|
|
156
|
+
pluginKey: this.plugin.key,
|
|
157
|
+
},
|
|
158
|
+
logger: this.logger,
|
|
170
159
|
})
|
|
171
160
|
|
|
172
|
-
await this.addFile(...
|
|
161
|
+
await this.addFile(...barrelFiles)
|
|
173
162
|
}
|
|
174
|
-
|
|
175
|
-
await this.fileManager.addIndexes({
|
|
176
|
-
root,
|
|
177
|
-
output,
|
|
178
|
-
meta: { pluginKey: this.plugin.key },
|
|
179
|
-
logger: this.logger,
|
|
180
|
-
})
|
|
181
163
|
},
|
|
182
164
|
}
|
|
183
165
|
})
|
package/src/types.ts
CHANGED
|
@@ -4,14 +4,11 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
4
4
|
import type { HttpMethod } from '@kubb/oas'
|
|
5
5
|
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
6
|
import type { Mutation } from './components/Mutation.tsx'
|
|
7
|
-
import type { Operations } from './components/Operations.tsx'
|
|
8
7
|
import type { Query as QueryTemplate } from './components/Query.tsx'
|
|
9
|
-
import type { QueryImports } from './components/QueryImports.tsx'
|
|
10
8
|
import type { QueryKey } from './components/QueryKey.tsx'
|
|
11
9
|
import type { QueryOptions as QueryOptionsTemplate } from './components/QueryOptions.tsx'
|
|
12
10
|
|
|
13
11
|
type Templates = {
|
|
14
|
-
operations?: typeof Operations.templates | false
|
|
15
12
|
mutation?: typeof Mutation.templates | false
|
|
16
13
|
query?: typeof QueryTemplate.templates | false
|
|
17
14
|
queryOptions?: typeof QueryOptionsTemplate.templates | false
|