@kubb/plugin-swr 3.0.0-alpha.2 → 3.0.0-alpha.20
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-7WG6LPZJ.js +185 -0
- package/dist/chunk-7WG6LPZJ.js.map +1 -0
- package/dist/chunk-DGY6XSP2.js +187 -0
- package/dist/chunk-DGY6XSP2.js.map +1 -0
- package/dist/chunk-RMG5RYPG.cjs +189 -0
- package/dist/chunk-RMG5RYPG.cjs.map +1 -0
- package/dist/chunk-WI3XUYBA.cjs +194 -0
- package/dist/chunk-WI3XUYBA.cjs.map +1 -0
- package/dist/components.cjs +15 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +49 -6
- package/dist/components.d.ts +49 -6
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +90 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +70 -114
- package/dist/index.js.map +1 -1
- package/dist/types-BCd4p4VZ.d.cts +127 -0
- package/dist/types-BCd4p4VZ.d.ts +127 -0
- package/package.json +22 -16
- package/src/components/Mutation.tsx +82 -227
- package/src/components/Query.tsx +86 -264
- package/src/components/QueryOptions.tsx +58 -179
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +40 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +40 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +30 -0
- package/src/generators/__snapshots__/findByTags.ts +40 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +40 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +40 -0
- package/src/generators/__snapshots__/getAsMutation.ts +32 -0
- package/src/generators/__snapshots__/postAsQuery.ts +39 -0
- package/src/generators/__snapshots__/updatePetById.ts +30 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mutationGenerator.tsx +96 -0
- package/src/generators/queryGenerator.tsx +101 -0
- package/src/plugin.ts +61 -50
- package/src/types.ts +63 -55
- package/dist/chunk-ECJ346AA.js +0 -542
- package/dist/chunk-ECJ346AA.js.map +0 -1
- package/dist/chunk-H4LHXYRJ.cjs +0 -542
- package/dist/chunk-H4LHXYRJ.cjs.map +0 -1
- package/dist/index-B3C-JOIU.d.cts +0 -299
- package/dist/index-B3C-JOIU.d.ts +0 -299
- package/src/OperationGenerator.tsx +0 -75
- package/src/components/SchemaType.tsx +0 -59
- package/src/components/__snapshots__/Mutation/Pets.ts +0 -42
- package/src/components/__snapshots__/Query/showPetById.ts +0 -55
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Type, useApp } from '@kubb/react'
|
|
2
|
-
|
|
3
|
-
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import type { ReactNode } from 'react'
|
|
5
|
-
import type { PluginSwr } from '../types.ts'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
factory: {
|
|
10
|
-
name: string
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function SchemaType({ factory }: Props): ReactNode {
|
|
15
|
-
const {
|
|
16
|
-
plugin: {
|
|
17
|
-
options: { dataReturnType },
|
|
18
|
-
},
|
|
19
|
-
} = useApp<PluginSwr>()
|
|
20
|
-
const { getSchemas } = useOperationManager()
|
|
21
|
-
const operation = useOperation()
|
|
22
|
-
|
|
23
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
24
|
-
|
|
25
|
-
const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
|
|
26
|
-
schemas.response.name,
|
|
27
|
-
schemas.errors?.map((item) => item.name).join(' | ') || 'never',
|
|
28
|
-
schemas.request?.name || 'never',
|
|
29
|
-
schemas.pathParams?.name || 'never',
|
|
30
|
-
schemas.queryParams?.name || 'never',
|
|
31
|
-
schemas.headerParams?.name || 'never',
|
|
32
|
-
schemas.response.name,
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
const clientType = `${factory.name}Client`
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<>
|
|
39
|
-
<Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${TRequest}>`}</Type>
|
|
40
|
-
<Type name={factory.name}>
|
|
41
|
-
{`
|
|
42
|
-
{
|
|
43
|
-
data: ${TData}
|
|
44
|
-
error: ${TError}
|
|
45
|
-
request: ${TRequest}
|
|
46
|
-
pathParams: ${TPathParams}
|
|
47
|
-
queryParams: ${TQueryParams}
|
|
48
|
-
headerParams: ${THeaderParams}
|
|
49
|
-
response: ${dataReturnType === 'data' ? TData : `Awaited<ReturnType<${clientType}>>`}
|
|
50
|
-
client: {
|
|
51
|
-
parameters: Partial<Parameters<${clientType}>[0]>
|
|
52
|
-
return: Awaited<ReturnType<${clientType}>>
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
`}
|
|
56
|
-
</Type>
|
|
57
|
-
</>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
type CreatePets = {
|
|
3
|
-
data: CreatePetsMutationResponse
|
|
4
|
-
error: never
|
|
5
|
-
request: CreatePetsMutationRequest
|
|
6
|
-
pathParams: never
|
|
7
|
-
queryParams: never
|
|
8
|
-
headerParams: never
|
|
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
|
|
19
|
-
*/
|
|
20
|
-
export function useCreatePets(options?: {
|
|
21
|
-
mutation?: SWRMutationConfiguration<CreatePets['response'], CreatePets['error']>
|
|
22
|
-
client?: CreatePets['client']['parameters']
|
|
23
|
-
shouldFetch?: boolean
|
|
24
|
-
}): SWRMutationResponse<CreatePets['response'], CreatePets['error']> {
|
|
25
|
-
const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
|
|
26
|
-
|
|
27
|
-
const url = `/pets` as const
|
|
28
|
-
return useSWRMutation<CreatePets['response'], CreatePets['error'], typeof url | null>(
|
|
29
|
-
shouldFetch ? url : null,
|
|
30
|
-
async (_url, { arg: data }) => {
|
|
31
|
-
const res = await client<CreatePets['data'], CreatePets['error'], CreatePets['request']>({
|
|
32
|
-
method: 'post',
|
|
33
|
-
url,
|
|
34
|
-
data,
|
|
35
|
-
...clientOptions,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return res.data
|
|
39
|
-
},
|
|
40
|
-
mutationOptions,
|
|
41
|
-
)
|
|
42
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
type ShowPetByIdClient = typeof client<ShowPetByIdQueryResponse, never, never>
|
|
2
|
-
type ShowPetById = {
|
|
3
|
-
data: ShowPetByIdQueryResponse
|
|
4
|
-
error: never
|
|
5
|
-
request: never
|
|
6
|
-
pathParams: ShowPetByIdPathParams
|
|
7
|
-
queryParams: never
|
|
8
|
-
headerParams: never
|
|
9
|
-
response: ShowPetByIdQueryResponse
|
|
10
|
-
client: {
|
|
11
|
-
parameters: Partial<Parameters<ShowPetByIdClient>[0]>
|
|
12
|
-
return: Awaited<ReturnType<ShowPetByIdClient>>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function ShowPetByIdQueryOptions<TData = ShowPetById['response']>(
|
|
17
|
-
petId: ShowPetByIdPathParams['petId'],
|
|
18
|
-
testId: ShowPetByIdPathParams['testId'],
|
|
19
|
-
options: ShowPetById['client']['parameters'] = {},
|
|
20
|
-
): SWRConfiguration<TData, ShowPetById['error']> {
|
|
21
|
-
return {
|
|
22
|
-
fetcher: async () => {
|
|
23
|
-
const res = await client<TData, ShowPetById['error']>({
|
|
24
|
-
method: 'get',
|
|
25
|
-
url: `/pets/${petId}`,
|
|
26
|
-
...options,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
return res.data
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @summary Info for a specific pet
|
|
35
|
-
* @link /pets/:petId
|
|
36
|
-
*/
|
|
37
|
-
export function useShowPetById<TData = ShowPetById['response']>(
|
|
38
|
-
petId: ShowPetByIdPathParams['petId'],
|
|
39
|
-
testId: ShowPetByIdPathParams['testId'],
|
|
40
|
-
options?: {
|
|
41
|
-
query?: SWRConfiguration<TData, ShowPetById['error']>
|
|
42
|
-
client?: ShowPetById['client']['parameters']
|
|
43
|
-
shouldFetch?: boolean
|
|
44
|
-
},
|
|
45
|
-
): SWRResponse<TData, ShowPetById['error']> {
|
|
46
|
-
const { query: queryOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
|
|
47
|
-
|
|
48
|
-
const url = `/pets/${petId}`
|
|
49
|
-
const query = useSWR<TData, ShowPetById['error'], typeof url | null>(shouldFetch ? url : null, {
|
|
50
|
-
...ShowPetByIdQueryOptions<TData>(petId, testId, clientOptions),
|
|
51
|
-
...queryOptions,
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
return query
|
|
55
|
-
}
|