@kubb/plugin-swr 3.0.0-alpha.9 → 3.0.0-beta.2

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.
Files changed (61) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-4EGGCGSE.js +217 -0
  3. package/dist/chunk-4EGGCGSE.js.map +1 -0
  4. package/dist/chunk-H23WKEYP.js +243 -0
  5. package/dist/chunk-H23WKEYP.js.map +1 -0
  6. package/dist/chunk-JWGWABV5.cjs +249 -0
  7. package/dist/chunk-JWGWABV5.cjs.map +1 -0
  8. package/dist/chunk-PTOQHHST.cjs +220 -0
  9. package/dist/chunk-PTOQHHST.cjs.map +1 -0
  10. package/dist/components.cjs +23 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +88 -6
  13. package/dist/components.d.ts +88 -6
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +11 -0
  19. package/dist/generators.d.ts +11 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +93 -123
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +2 -4
  25. package/dist/index.d.ts +2 -4
  26. package/dist/index.js +77 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DaH2Sc1M.d.cts +103 -0
  29. package/dist/types-DaH2Sc1M.d.ts +103 -0
  30. package/package.json +23 -17
  31. package/src/components/Mutation.tsx +93 -227
  32. package/src/components/MutationKey.tsx +48 -0
  33. package/src/components/Query.tsx +93 -259
  34. package/src/components/QueryKey.tsx +73 -0
  35. package/src/components/QueryOptions.tsx +54 -177
  36. package/src/components/index.ts +2 -0
  37. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
  38. package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
  39. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  40. package/src/generators/__snapshots__/findByTags.ts +43 -0
  41. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
  43. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  44. package/src/generators/__snapshots__/postAsQuery.ts +41 -0
  45. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  46. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
  47. package/src/generators/index.ts +2 -0
  48. package/src/generators/mutationGenerator.tsx +109 -0
  49. package/src/generators/queryGenerator.tsx +114 -0
  50. package/src/plugin.ts +71 -52
  51. package/src/types.ts +62 -78
  52. package/dist/chunk-TGLXUPN4.cjs +0 -536
  53. package/dist/chunk-TGLXUPN4.cjs.map +0 -1
  54. package/dist/chunk-XWXMQJD6.js +0 -536
  55. package/dist/chunk-XWXMQJD6.js.map +0 -1
  56. package/dist/index-B3C-JOIU.d.cts +0 -299
  57. package/dist/index-B3C-JOIU.d.ts +0 -299
  58. package/src/OperationGenerator.tsx +0 -75
  59. package/src/components/SchemaType.tsx +0 -63
  60. package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
  61. package/src/components/__snapshots__/Query/showPetById.ts +0 -59
@@ -1,63 +0,0 @@
1
- import { File, Type, useApp } from '@kubb/react'
2
-
3
- import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
4
- import { pluginTsName } from '@kubb/plugin-ts'
5
- import type { ReactNode } from 'react'
6
- import type { PluginSwr } from '../types.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
- <File.Source name={clientType} isTypeOnly>
40
- <Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${TRequest}>`}</Type>
41
- </File.Source>
42
- <File.Source name={factory.name} isTypeOnly>
43
- <Type name={factory.name}>
44
- {`
45
- {
46
- data: ${TData}
47
- error: ${TError}
48
- request: ${TRequest}
49
- pathParams: ${TPathParams}
50
- queryParams: ${TQueryParams}
51
- headerParams: ${THeaderParams}
52
- response: ${dataReturnType === 'data' ? TData : `Awaited<ReturnType<${clientType}>>`}
53
- client: {
54
- parameters: Partial<Parameters<${clientType}>[0]>
55
- return: Awaited<ReturnType<${clientType}>>
56
- }
57
- }
58
- `}
59
- </Type>
60
- </File.Source>
61
- </>
62
- )
63
- }
@@ -1,46 +0,0 @@
1
- type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
2
-
3
- type CreatePets =
4
- {
5
- data: CreatePetsMutationResponse
6
- error: never
7
- request: CreatePetsMutationRequest
8
- pathParams: never
9
- queryParams: never
10
- headerParams: never
11
- response: CreatePetsMutationResponse
12
- client: {
13
- parameters: Partial<Parameters<CreatePetsClient>[0]>
14
- return: Awaited<ReturnType<CreatePetsClient>>
15
- }
16
- }
17
-
18
- /**
19
- * @summary Create a pet
20
- * @link /pets
21
- */
22
- export function useCreatePets(options?: {
23
- mutation?: SWRMutationConfiguration<CreatePets["response"], CreatePets["error"]>,
24
- client?: CreatePets['client']['parameters'],
25
- shouldFetch?: boolean,
26
- }): SWRMutationResponse<CreatePets["response"], CreatePets["error"]> {
27
-
28
- const { mutation: mutationOptions, client: clientOptions = {}, shouldFetch = true } = options ?? {}
29
-
30
- const url = `/pets` as const
31
- return useSWRMutation<CreatePets["response"], CreatePets["error"], typeof url | null>(
32
- shouldFetch ? url : null,
33
- async (_url, { arg: data }) => {
34
- const res = await client<CreatePets["data"], CreatePets["error"], CreatePets["request"]>({
35
- method: "post",
36
- url,
37
- data,
38
- ...clientOptions
39
- })
40
-
41
- return res.data
42
- },
43
- mutationOptions
44
- )
45
-
46
- }
@@ -1,59 +0,0 @@
1
- type ShowPetByIdClient = typeof client<ShowPetByIdQueryResponse, never, never>
2
-
3
- type ShowPetById =
4
- {
5
- data: ShowPetByIdQueryResponse
6
- error: never
7
- request: never
8
- pathParams: ShowPetByIdPathParams
9
- queryParams: never
10
- headerParams: never
11
- response: ShowPetByIdQueryResponse
12
- client: {
13
- parameters: Partial<Parameters<ShowPetByIdClient>[0]>
14
- return: Awaited<ReturnType<ShowPetByIdClient>>
15
- }
16
- }
17
-
18
- export function ShowPetByIdQueryOptions<TData = ShowPetById['response']>(petId: ShowPetByIdPathParams["petId"], testId: ShowPetByIdPathParams["testId"], options: ShowPetById['client']['parameters'] = {}): SWRConfiguration<TData, ShowPetById['error']> {
19
-
20
- return {
21
- fetcher: async () => {
22
-
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
- }
35
-
36
- /**
37
- * @summary Info for a specific pet
38
- * @link /pets/:petId
39
- */
40
- export function useShowPetById<TData = ShowPetById["response"]>(petId: ShowPetByIdPathParams["petId"], testId: ShowPetByIdPathParams["testId"], options?: {
41
- query?: SWRConfiguration<TData, ShowPetById["error"]>,
42
- client?: ShowPetById['client']['parameters'],
43
- shouldFetch?: boolean,
44
- }): SWRResponse<TData, ShowPetById["error"]> {
45
-
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>(
50
- shouldFetch ? url : null,
51
- {
52
- ...ShowPetByIdQueryOptions<TData>(petId, testId, clientOptions),
53
- ...queryOptions
54
- }
55
- )
56
-
57
- return query
58
-
59
- }