@kubb/plugin-react-query 3.0.0-alpha.3 → 3.0.0-alpha.31
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/README.md +13 -4
- package/dist/chunk-C2H3KPHM.cjs +658 -0
- package/dist/chunk-C2H3KPHM.cjs.map +1 -0
- package/dist/chunk-J7NSRJSY.js +661 -0
- package/dist/chunk-J7NSRJSY.js.map +1 -0
- package/dist/chunk-M5RJDPKE.cjs +670 -0
- package/dist/chunk-M5RJDPKE.cjs.map +1 -0
- package/dist/chunk-Y3DM2P6L.js +647 -0
- package/dist/chunk-Y3DM2P6L.js.map +1 -0
- package/dist/components.cjs +39 -14
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +161 -7
- package/dist/components.d.ts +161 -7
- package/dist/components.js +2 -14
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +25 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +14 -0
- package/dist/generators.d.ts +14 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +75 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +58 -145
- package/dist/index.js.map +1 -1
- package/dist/types-oaGq_oPb.d.cts +169 -0
- package/dist/types-oaGq_oPb.d.ts +169 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +130 -0
- package/src/components/Mutation.tsx +138 -322
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +91 -598
- package/src/components/QueryKey.tsx +51 -178
- package/src/components/QueryOptions.tsx +72 -466
- package/src/components/SuspenseQuery.tsx +129 -0
- package/src/components/index.ts +4 -1
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
- package/src/generators/__snapshots__/findByTags.ts +51 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +44 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +124 -0
- package/src/generators/mutationGenerator.tsx +108 -0
- package/src/generators/queryGenerator.tsx +121 -0
- package/src/generators/suspenseQueryGenerator.tsx +120 -0
- package/src/plugin.ts +58 -83
- package/src/types.ts +50 -107
- package/dist/chunk-5IL6M74X.js +0 -1504
- package/dist/chunk-5IL6M74X.js.map +0 -1
- package/dist/chunk-JFX7DCS7.cjs +0 -1504
- package/dist/chunk-JFX7DCS7.cjs.map +0 -1
- package/dist/index-C9fwRDH7.d.cts +0 -579
- package/dist/index-C9fwRDH7.d.ts +0 -579
- package/src/OperationGenerator.tsx +0 -86
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
- package/src/__snapshots__/upload/UploadFile.ts +0 -67
- package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
- package/src/components/Operations.tsx +0 -74
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -55
- package/src/components/__snapshots__/gen/showPetById.ts +0 -57
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
- package/src/utils.ts +0 -96
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
2
|
-
import { Type, useApp } from '@kubb/react'
|
|
3
|
-
|
|
4
|
-
import type { ReactNode } from 'react'
|
|
5
|
-
import type { PluginReactQuery } from '../types.ts'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
|
|
8
|
-
export function SchemaType(): ReactNode {
|
|
9
|
-
const {
|
|
10
|
-
plugin: {
|
|
11
|
-
options: { dataReturnType },
|
|
12
|
-
},
|
|
13
|
-
} = useApp<PluginReactQuery>()
|
|
14
|
-
const { getSchemas, getName } = useOperationManager()
|
|
15
|
-
const operation = useOperation()
|
|
16
|
-
|
|
17
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
18
|
-
|
|
19
|
-
const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
|
|
20
|
-
schemas.response.name,
|
|
21
|
-
schemas.errors?.map((item) => item.name).join(' | ') || 'never',
|
|
22
|
-
schemas.request?.name || 'never',
|
|
23
|
-
schemas.pathParams?.name || 'never',
|
|
24
|
-
schemas.queryParams?.name || 'never',
|
|
25
|
-
schemas.headerParams?.name || 'never',
|
|
26
|
-
schemas.response.name,
|
|
27
|
-
]
|
|
28
|
-
const factoryName = getName(operation, { type: 'type' })
|
|
29
|
-
|
|
30
|
-
const clientType = `${factoryName}Client`
|
|
31
|
-
const isFormData = operation.getContentType() === 'multipart/form-data'
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<>
|
|
35
|
-
<Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${isFormData ? 'FormData' : TRequest}>`}</Type>
|
|
36
|
-
<Type name={factoryName}>
|
|
37
|
-
{`
|
|
38
|
-
{
|
|
39
|
-
data: ${TData}
|
|
40
|
-
error: ${TError}
|
|
41
|
-
request: ${isFormData ? 'FormData' : TRequest}
|
|
42
|
-
pathParams: ${TPathParams}
|
|
43
|
-
queryParams: ${TQueryParams}
|
|
44
|
-
headerParams: ${THeaderParams}
|
|
45
|
-
response: ${dataReturnType === 'data' ? TData : `Awaited<ReturnType<${clientType}>>`}
|
|
46
|
-
client: {
|
|
47
|
-
parameters: Partial<Parameters<${clientType}>[0]>
|
|
48
|
-
return: Awaited<ReturnType<${clientType}>>
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
`}
|
|
52
|
-
</Type>
|
|
53
|
-
</>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
|
|
16
|
-
export const GetPetsUuidQueryKey = () => [{ url: '/pets/:uuid', params: { uuid: uuid } }] as const
|
|
17
|
-
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
|
-
|
|
23
|
-
return {
|
|
24
|
-
queryKey,
|
|
25
|
-
queryFn: async () => {
|
|
26
|
-
const res = await client<GetPetsUuid['data'], GetPetsUuid['error']>({
|
|
27
|
-
method: 'get',
|
|
28
|
-
url: `/pets/${uuid}`,
|
|
29
|
-
...options,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
return res.data
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @link /pets/:uuid
|
|
38
|
-
*/
|
|
39
|
-
export function useGetPetsUuid<TData = GetPetsUuid['response'], TQueryData = GetPetsUuid['response'], TQueryKey extends QueryKey = GetPetsUuidQueryKey>(
|
|
40
|
-
options: {
|
|
41
|
-
query?: Partial<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid['error'], TData, TQueryData, TQueryKey>>
|
|
42
|
-
client?: GetPetsUuid['client']['parameters']
|
|
43
|
-
} = {},
|
|
44
|
-
): UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey } {
|
|
45
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
46
|
-
const queryKey = queryOptions?.queryKey ?? GetPetsUuidQueryKey()
|
|
47
|
-
|
|
48
|
-
const query = useQuery<GetPetsUuid['data'], GetPetsUuid['error'], TData, any>({
|
|
49
|
-
...GetPetsUuidQueryOptions<TData, TQueryData>(clientOptions),
|
|
50
|
-
queryKey,
|
|
51
|
-
...queryOptions,
|
|
52
|
-
}) as UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey }
|
|
53
|
-
|
|
54
|
-
query.queryKey = queryKey as TQueryKey
|
|
55
|
-
|
|
56
|
-
return query
|
|
57
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
type CreatePets = {
|
|
3
|
-
data: CreatePetsMutationResponse
|
|
4
|
-
error: never
|
|
5
|
-
request: CreatePetsMutationRequest
|
|
6
|
-
pathParams: CreatePetsPathParams
|
|
7
|
-
queryParams: CreatePetsQueryParams
|
|
8
|
-
headerParams: CreatePetsHeaderParams
|
|
9
|
-
response: CreatePetsMutationResponse
|
|
10
|
-
client: {
|
|
11
|
-
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
12
|
-
return: Awaited<ReturnType<CreatePetsClient>>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @summary Create a pet
|
|
18
|
-
* @link /pets/:uuid
|
|
19
|
-
*/
|
|
20
|
-
export function useCreatePets(
|
|
21
|
-
uuid: CreatePetsPathParams['uuid'],
|
|
22
|
-
headers: CreatePets['headerParams'],
|
|
23
|
-
params?: CreatePets['queryParams'],
|
|
24
|
-
options: {
|
|
25
|
-
mutation?: UseMutationOptions<CreatePets['response'], CreatePets['error'], CreatePets['request']>
|
|
26
|
-
client?: CreatePets['client']['parameters']
|
|
27
|
-
} = {},
|
|
28
|
-
) {
|
|
29
|
-
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
30
|
-
|
|
31
|
-
return useMutation({
|
|
32
|
-
mutationFn: async (data) => {
|
|
33
|
-
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({
|
|
34
|
-
method: 'post',
|
|
35
|
-
url: `/pets/${uuid}`,
|
|
36
|
-
params,
|
|
37
|
-
data,
|
|
38
|
-
headers: { ...headers, ...clientOptions.headers },
|
|
39
|
-
...clientOptions,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return res.data
|
|
43
|
-
},
|
|
44
|
-
...mutationOptions,
|
|
45
|
-
})
|
|
46
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
type CreatePets = {
|
|
3
|
-
data: CreatePetsMutationResponse
|
|
4
|
-
error: never
|
|
5
|
-
request: CreatePetsMutationRequest
|
|
6
|
-
pathParams: CreatePetsPathParams
|
|
7
|
-
queryParams: CreatePetsQueryParams
|
|
8
|
-
headerParams: CreatePetsHeaderParams
|
|
9
|
-
response: CreatePetsMutationResponse
|
|
10
|
-
client: {
|
|
11
|
-
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
12
|
-
return: Awaited<ReturnType<CreatePetsClient>>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @summary Create a pet
|
|
18
|
-
* @link /pets/:uuid
|
|
19
|
-
*/
|
|
20
|
-
export function useCreatePets(
|
|
21
|
-
options: {
|
|
22
|
-
mutation?: UseMutationOptions<
|
|
23
|
-
CreatePets['response'],
|
|
24
|
-
CreatePets['error'],
|
|
25
|
-
{ uuid: CreatePetsPathParams['uuid']; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] }
|
|
26
|
-
>
|
|
27
|
-
client?: CreatePets['client']['parameters']
|
|
28
|
-
} = {},
|
|
29
|
-
) {
|
|
30
|
-
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
31
|
-
|
|
32
|
-
return useMutation({
|
|
33
|
-
mutationFn: async ({ uuid, headers, data, params }) => {
|
|
34
|
-
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({
|
|
35
|
-
method: 'post',
|
|
36
|
-
url: `/pets/${uuid}`,
|
|
37
|
-
params,
|
|
38
|
-
data,
|
|
39
|
-
headers: { ...headers, ...clientOptions.headers },
|
|
40
|
-
...clientOptions,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return res.data
|
|
44
|
-
},
|
|
45
|
-
...mutationOptions,
|
|
46
|
-
})
|
|
47
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { PackageManager } from '@kubb/core'
|
|
2
|
-
|
|
3
|
-
export const reactQueryDepRegex = /@tanstack\/(react|solid|vue|svelte)-query/
|
|
4
|
-
|
|
5
|
-
export function getImportNames() {
|
|
6
|
-
const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
mutation: {
|
|
10
|
-
react: {
|
|
11
|
-
path: '@tanstack/react-query',
|
|
12
|
-
hookName: 'useMutation',
|
|
13
|
-
optionsType: 'UseMutationOptions',
|
|
14
|
-
resultType: 'UseMutationResult',
|
|
15
|
-
},
|
|
16
|
-
solid: {
|
|
17
|
-
path: '@tanstack/solid-query',
|
|
18
|
-
hookName: 'createMutation',
|
|
19
|
-
optionsType: 'CreateMutationOptions',
|
|
20
|
-
resultType: 'CreateMutationResult',
|
|
21
|
-
},
|
|
22
|
-
svelte: {
|
|
23
|
-
path: '@tanstack/svelte-query',
|
|
24
|
-
hookName: 'createMutation',
|
|
25
|
-
optionsType: 'CreateMutationOptions',
|
|
26
|
-
resultType: 'CreateMutationResult',
|
|
27
|
-
},
|
|
28
|
-
vue: {
|
|
29
|
-
path: '@tanstack/vue-query',
|
|
30
|
-
hookName: 'useMutation',
|
|
31
|
-
optionsType: isV5 ? 'UseMutationOptions' : 'VueMutationObserverOptions',
|
|
32
|
-
resultType: 'UseMutationReturnType',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
query: {
|
|
36
|
-
react: {
|
|
37
|
-
path: '@tanstack/react-query',
|
|
38
|
-
hookName: 'useQuery',
|
|
39
|
-
optionsType: isV5 ? 'QueryObserverOptions' : 'UseBaseQueryOptions',
|
|
40
|
-
resultType: 'UseQueryResult',
|
|
41
|
-
},
|
|
42
|
-
solid: {
|
|
43
|
-
path: '@tanstack/solid-query',
|
|
44
|
-
hookName: 'createQuery',
|
|
45
|
-
optionsType: 'CreateBaseQueryOptions',
|
|
46
|
-
resultType: 'CreateQueryResult',
|
|
47
|
-
},
|
|
48
|
-
svelte: {
|
|
49
|
-
path: '@tanstack/svelte-query',
|
|
50
|
-
hookName: 'createQuery',
|
|
51
|
-
optionsType: 'CreateBaseQueryOptions',
|
|
52
|
-
resultType: 'CreateQueryResult',
|
|
53
|
-
},
|
|
54
|
-
vue: {
|
|
55
|
-
path: '@tanstack/vue-query',
|
|
56
|
-
hookName: 'useQuery',
|
|
57
|
-
optionsType: isV5 ? 'QueryObserverOptions' : 'VueQueryObserverOptions',
|
|
58
|
-
resultType: isV5 ? 'UseQueryReturnType' : 'UseQueryReturnType',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
queryInfinite: {
|
|
62
|
-
react: {
|
|
63
|
-
path: '@tanstack/react-query',
|
|
64
|
-
hookName: 'useInfiniteQuery',
|
|
65
|
-
optionsType: isV5 ? 'InfiniteQueryObserverOptions' : 'UseInfiniteQueryOptions',
|
|
66
|
-
resultType: 'UseInfiniteQueryResult',
|
|
67
|
-
},
|
|
68
|
-
solid: {
|
|
69
|
-
path: '@tanstack/solid-query',
|
|
70
|
-
hookName: 'createInfiniteQuery',
|
|
71
|
-
optionsType: 'CreateInfiniteQueryOptions',
|
|
72
|
-
resultType: 'CreateInfiniteQueryResult',
|
|
73
|
-
},
|
|
74
|
-
svelte: {
|
|
75
|
-
path: '@tanstack/svelte-query',
|
|
76
|
-
hookName: 'createInfiniteQuery',
|
|
77
|
-
optionsType: 'CreateInfiniteQueryOptions',
|
|
78
|
-
resultType: 'CreateInfiniteQueryResult',
|
|
79
|
-
},
|
|
80
|
-
vue: {
|
|
81
|
-
path: '@tanstack/vue-query',
|
|
82
|
-
hookName: 'useInfiniteQuery',
|
|
83
|
-
optionsType: isV5 ? 'UseInfiniteQueryOptions' : 'VueInfiniteQueryObserverOptions',
|
|
84
|
-
resultType: isV5 ? 'UseInfiniteQueryReturnType' : 'VueInfiniteQueryObserverOptions',
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
querySuspense: {
|
|
88
|
-
react: {
|
|
89
|
-
path: '@tanstack/react-query',
|
|
90
|
-
hookName: 'useSuspenseQuery',
|
|
91
|
-
optionsType: 'UseSuspenseQueryOptions',
|
|
92
|
-
resultType: 'UseSuspenseQueryResult',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
} as const
|
|
96
|
-
}
|