@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.
Files changed (58) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-7WG6LPZJ.js +185 -0
  3. package/dist/chunk-7WG6LPZJ.js.map +1 -0
  4. package/dist/chunk-DGY6XSP2.js +187 -0
  5. package/dist/chunk-DGY6XSP2.js.map +1 -0
  6. package/dist/chunk-RMG5RYPG.cjs +189 -0
  7. package/dist/chunk-RMG5RYPG.cjs.map +1 -0
  8. package/dist/chunk-WI3XUYBA.cjs +194 -0
  9. package/dist/chunk-WI3XUYBA.cjs.map +1 -0
  10. package/dist/components.cjs +15 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +49 -6
  13. package/dist/components.d.ts +49 -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 +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +90 -127
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +70 -114
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-BCd4p4VZ.d.cts +127 -0
  29. package/dist/types-BCd4p4VZ.d.ts +127 -0
  30. package/package.json +22 -16
  31. package/src/components/Mutation.tsx +82 -227
  32. package/src/components/Query.tsx +86 -264
  33. package/src/components/QueryOptions.tsx +58 -179
  34. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +40 -0
  35. package/src/generators/__snapshots__/clientGetImportPath.ts +40 -0
  36. package/src/generators/__snapshots__/clientPostImportPath.ts +30 -0
  37. package/src/generators/__snapshots__/findByTags.ts +40 -0
  38. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +40 -0
  39. package/src/generators/__snapshots__/findByTagsWithZod.ts +40 -0
  40. package/src/generators/__snapshots__/getAsMutation.ts +32 -0
  41. package/src/generators/__snapshots__/postAsQuery.ts +39 -0
  42. package/src/generators/__snapshots__/updatePetById.ts +30 -0
  43. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
  44. package/src/generators/index.ts +2 -0
  45. package/src/generators/mutationGenerator.tsx +96 -0
  46. package/src/generators/queryGenerator.tsx +101 -0
  47. package/src/plugin.ts +61 -50
  48. package/src/types.ts +63 -55
  49. package/dist/chunk-ECJ346AA.js +0 -542
  50. package/dist/chunk-ECJ346AA.js.map +0 -1
  51. package/dist/chunk-H4LHXYRJ.cjs +0 -542
  52. package/dist/chunk-H4LHXYRJ.cjs.map +0 -1
  53. package/dist/index-B3C-JOIU.d.cts +0 -299
  54. package/dist/index-B3C-JOIU.d.ts +0 -299
  55. package/src/OperationGenerator.tsx +0 -75
  56. package/src/components/SchemaType.tsx +0 -59
  57. package/src/components/__snapshots__/Mutation/Pets.ts +0 -42
  58. package/src/components/__snapshots__/Query/showPetById.ts +0 -55
@@ -0,0 +1,40 @@
1
+ import client from "axios";
2
+ import useSWR from "swr";
3
+ import type { RequestConfig } from "axios";
4
+ import type { Key, SWRConfiguration } from "swr";
5
+
6
+ /**
7
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
8
+ * @summary Finds Pets by tags
9
+ * @link /pet/findByTags
10
+ */
11
+ async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
17
+ return {
18
+ fetcher: async () => {
19
+ return findPetsByTags(params, config);
20
+ },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
26
+ * @summary Finds Pets by tags
27
+ * @link /pet/findByTags
28
+ */
29
+ export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
30
+ query?: SWRConfiguration<FindPetsByTagsQueryResponse, FindPetsByTags400>;
31
+ client?: Partial<RequestConfig>;
32
+ shouldFetch?: boolean;
33
+ } = {}) {
34
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
35
+ const swrKey = [`/pet/findByTags`, params] as const;
36
+ return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, Key>(shouldFetch ? swrKey : null, {
37
+ ...findPetsByTagsQueryOptions(params, config),
38
+ ...queryOptions
39
+ });
40
+ }
@@ -0,0 +1,30 @@
1
+ import client from "axios";
2
+ import useSWRMutation from "swr/mutation";
3
+ import type { RequestConfig } from "axios";
4
+ import type { Key } from "swr";
5
+ import type { SWRMutationConfiguration } from "swr/mutation";
6
+
7
+ /**
8
+ * @summary Updates a pet in the store with form data
9
+ * @link /pet/:petId
10
+ */
11
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "post", url: `/pet/${petId}`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ /**
17
+ * @summary Updates a pet in the store with form data
18
+ * @link /pet/:petId
19
+ */
20
+ export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
21
+ mutation?: SWRMutationConfiguration<UpdatePetWithFormMutationResponse, UpdatePetWithForm405>;
22
+ client?: Partial<RequestConfig>;
23
+ shouldFetch?: boolean;
24
+ } = {}) {
25
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
26
+ const swrKey = [`/pet/${petId}`, params] as const;
27
+ return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, Key>(shouldFetch ? swrKey : null, async (_url) => {
28
+ return updatePetWithForm(petId, params, config);
29
+ }, mutationOptions);
30
+ }
@@ -0,0 +1,40 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWR from "swr";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { Key, SWRConfiguration } from "swr";
5
+
6
+ /**
7
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
8
+ * @summary Finds Pets by tags
9
+ * @link /pet/findByTags
10
+ */
11
+ async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
17
+ return {
18
+ fetcher: async () => {
19
+ return findPetsByTags(params, config);
20
+ },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
26
+ * @summary Finds Pets by tags
27
+ * @link /pet/findByTags
28
+ */
29
+ export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
30
+ query?: SWRConfiguration<FindPetsByTagsQueryResponse, FindPetsByTags400>;
31
+ client?: Partial<RequestConfig>;
32
+ shouldFetch?: boolean;
33
+ } = {}) {
34
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
35
+ const swrKey = [`/pet/findByTags`, params] as const;
36
+ return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, Key>(shouldFetch ? swrKey : null, {
37
+ ...findPetsByTagsQueryOptions(params, config),
38
+ ...queryOptions
39
+ });
40
+ }
@@ -0,0 +1,40 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWR from "swr";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { Key, SWRConfiguration } from "swr";
5
+
6
+ /**
7
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
8
+ * @summary Finds Pets by tags
9
+ * @link /pet/findByTags
10
+ */
11
+ async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
17
+ return {
18
+ fetcher: async () => {
19
+ return findPetsByTags(params, config);
20
+ },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
26
+ * @summary Finds Pets by tags
27
+ * @link /pet/findByTags
28
+ */
29
+ export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
30
+ query?: SWRConfiguration<FindPetsByTagsQueryResponse, FindPetsByTags400>;
31
+ client?: Partial<RequestConfig>;
32
+ shouldFetch?: boolean;
33
+ } = {}) {
34
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
35
+ const swrKey = [`/pet/findByTags`, params] as const;
36
+ return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, Key>(shouldFetch ? swrKey : null, {
37
+ ...findPetsByTagsQueryOptions(params, config),
38
+ ...queryOptions
39
+ });
40
+ }
@@ -0,0 +1,40 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWR from "swr";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { Key, SWRConfiguration } from "swr";
5
+
6
+ /**
7
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
8
+ * @summary Finds Pets by tags
9
+ * @link /pet/findByTags
10
+ */
11
+ async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
13
+ return findPetsByTagsQueryResponse.parse(res.data);
14
+ }
15
+
16
+ export function findPetsByTagsQueryOptions(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
17
+ return {
18
+ fetcher: async () => {
19
+ return findPetsByTags(params, config);
20
+ },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
26
+ * @summary Finds Pets by tags
27
+ * @link /pet/findByTags
28
+ */
29
+ export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
30
+ query?: SWRConfiguration<FindPetsByTagsQueryResponse, FindPetsByTags400>;
31
+ client?: Partial<RequestConfig>;
32
+ shouldFetch?: boolean;
33
+ } = {}) {
34
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
35
+ const swrKey = [`/pet/findByTags`, params] as const;
36
+ return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, Key>(shouldFetch ? swrKey : null, {
37
+ ...findPetsByTagsQueryOptions(params, config),
38
+ ...queryOptions
39
+ });
40
+ }
@@ -0,0 +1,32 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWRMutation from "custom-swr/mutation";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { SWRMutationConfiguration } from "custom-swr/mutation";
5
+ import type { Key } from "swr";
6
+
7
+ /**
8
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
9
+ * @summary Finds Pets by tags
10
+ * @link /pet/findByTags
11
+ */
12
+ async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
13
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "get", url: `/pet/findByTags`, params, ...config });
14
+ return res.data;
15
+ }
16
+
17
+ /**
18
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
19
+ * @summary Finds Pets by tags
20
+ * @link /pet/findByTags
21
+ */
22
+ export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
23
+ mutation?: SWRMutationConfiguration<FindPetsByTagsQueryResponse, FindPetsByTags400>;
24
+ client?: Partial<RequestConfig>;
25
+ shouldFetch?: boolean;
26
+ } = {}) {
27
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
28
+ const swrKey = [`/pet/findByTags`, params] as const;
29
+ return useSWRMutation<FindPetsByTagsQueryResponse, FindPetsByTags400, Key>(shouldFetch ? swrKey : null, async (_url) => {
30
+ return findPetsByTags(params, config);
31
+ }, mutationOptions);
32
+ }
@@ -0,0 +1,39 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWR from "custom-swr";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { SWRConfiguration } from "custom-swr";
5
+ import type { Key } from "swr";
6
+
7
+ /**
8
+ * @summary Updates a pet in the store with form data
9
+ * @link /pet/:petId
10
+ */
11
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "post", url: `/pet/${petId}`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ export function updatePetWithFormQueryOptions(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
17
+ return {
18
+ fetcher: async () => {
19
+ return updatePetWithForm(petId, params, config);
20
+ },
21
+ };
22
+ }
23
+
24
+ /**
25
+ * @summary Updates a pet in the store with form data
26
+ * @link /pet/:petId
27
+ */
28
+ export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
29
+ query?: SWRConfiguration<UpdatePetWithFormMutationResponse, UpdatePetWithForm405>;
30
+ client?: Partial<RequestConfig>;
31
+ shouldFetch?: boolean;
32
+ } = {}) {
33
+ const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {};
34
+ const swrKey = [`/pet/${petId}`, params] as const;
35
+ return useSWR<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, Key>(shouldFetch ? swrKey : null, {
36
+ ...updatePetWithFormQueryOptions(petId, params, config),
37
+ ...queryOptions
38
+ });
39
+ }
@@ -0,0 +1,30 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWRMutation from "swr/mutation";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { Key } from "swr";
5
+ import type { SWRMutationConfiguration } from "swr/mutation";
6
+
7
+ /**
8
+ * @summary Updates a pet in the store with form data
9
+ * @link /pet/:petId
10
+ */
11
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
12
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "post", url: `/pet/${petId}`, params, ...config });
13
+ return res.data;
14
+ }
15
+
16
+ /**
17
+ * @summary Updates a pet in the store with form data
18
+ * @link /pet/:petId
19
+ */
20
+ export function useUpdatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], params?: UpdatePetWithFormQueryParams, options: {
21
+ mutation?: SWRMutationConfiguration<UpdatePetWithFormMutationResponse, UpdatePetWithForm405>;
22
+ client?: Partial<RequestConfig>;
23
+ shouldFetch?: boolean;
24
+ } = {}) {
25
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
26
+ const swrKey = [`/pet/${petId}`, params] as const;
27
+ return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, Key>(shouldFetch ? swrKey : null, async (_url) => {
28
+ return updatePetWithForm(petId, params, config);
29
+ }, mutationOptions);
30
+ }
@@ -0,0 +1,34 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import useSWRMutation from "swr/mutation";
3
+ import type { RequestConfig } from "@kubb/plugin-client/client";
4
+ import type { Key } from "swr";
5
+ import type { SWRMutationConfiguration } from "swr/mutation";
6
+
7
+ /**
8
+ * @summary Updates a pet in the store with form data
9
+ * @link /pet/:petId
10
+ */
11
+ async function updatePetWithForm({ petId }: {
12
+ petId: UpdatePetWithFormPathParams["petId"];
13
+ }, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig> = {}) {
14
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: "post", url: `/pet/${petId}`, params, ...config });
15
+ return res.data;
16
+ }
17
+
18
+ /**
19
+ * @summary Updates a pet in the store with form data
20
+ * @link /pet/:petId
21
+ */
22
+ export function useUpdatePetWithForm({ petId }: {
23
+ petId: UpdatePetWithFormPathParams["petId"];
24
+ }, params?: UpdatePetWithFormQueryParams, options: {
25
+ mutation?: SWRMutationConfiguration<UpdatePetWithFormMutationResponse, UpdatePetWithForm405>;
26
+ client?: Partial<RequestConfig>;
27
+ shouldFetch?: boolean;
28
+ } = {}) {
29
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
30
+ const swrKey = [`/pet/${petId}`, params] as const;
31
+ return useSWRMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, Key>(shouldFetch ? swrKey : null, async (_url) => {
32
+ return updatePetWithForm({ petId }, params, config);
33
+ }, mutationOptions);
34
+ }
@@ -0,0 +1,2 @@
1
+ export { queryGenerator } from './queryGenerator.tsx'
2
+ export { mutationGenerator } from './mutationGenerator.tsx'
@@ -0,0 +1,96 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { Client } from '@kubb/plugin-client/components'
3
+ import { createReactGenerator } from '@kubb/plugin-oas'
4
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { pluginTsName } from '@kubb/plugin-ts'
6
+ import { pluginZodName } from '@kubb/plugin-zod'
7
+ import { File, useApp } from '@kubb/react'
8
+ import { Mutation } from '../components'
9
+ import type { PluginSwr } from '../types'
10
+
11
+ export const mutationGenerator = createReactGenerator<PluginSwr>({
12
+ name: 'swr-mutation',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginSwr>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+
21
+ const isMutate = typeof options.query === 'boolean' ? options.mutation : !!options.mutation.methods?.some((method) => operation.method === method)
22
+
23
+ const mutation = {
24
+ name: getName(operation, { type: 'function', prefix: 'use' }),
25
+ typeName: getName(operation, { type: 'type' }),
26
+ file: getFile(operation, { prefix: 'use' }),
27
+ }
28
+
29
+ const type = {
30
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
31
+ //todo remove type?
32
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
33
+ }
34
+
35
+ const zod = {
36
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
37
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
38
+ }
39
+
40
+ const client = {
41
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
42
+ }
43
+
44
+ if (!isMutate) {
45
+ return null
46
+ }
47
+
48
+ return (
49
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
50
+ {options.parser === 'zod' && (
51
+ <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />
52
+ )}
53
+ <File.Import name={['Key']} path="swr" isTypeOnly />
54
+ <File.Import name="useSWRMutation" path={options.mutation.importPath} />
55
+ <File.Import name={['SWRMutationConfiguration', 'SWRMutationResponse']} path={options.mutation.importPath} isTypeOnly />
56
+ <File.Import name={'client'} path={options.client.importPath} />
57
+ <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
58
+ <File.Import
59
+ extName={output?.extName}
60
+ name={[
61
+ type.schemas.request?.name,
62
+ type.schemas.response.name,
63
+ type.schemas.pathParams?.name,
64
+ type.schemas.queryParams?.name,
65
+ type.schemas.headerParams?.name,
66
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
67
+ ].filter(Boolean)}
68
+ root={mutation.file.path}
69
+ path={type.file.path}
70
+ isTypeOnly
71
+ />
72
+ <Client
73
+ name={client.name}
74
+ isExportable={false}
75
+ isIndexable={false}
76
+ baseURL={options.baseURL}
77
+ operation={operation}
78
+ typeSchemas={type.schemas}
79
+ zodSchemas={zod.schemas}
80
+ dataReturnType={options.client.dataReturnType}
81
+ pathParamsType={options.pathParamsType}
82
+ parser={options.parser}
83
+ />
84
+ <Mutation
85
+ name={mutation.name}
86
+ clientName={client.name}
87
+ typeName={mutation.typeName}
88
+ typeSchemas={type.schemas}
89
+ operation={operation}
90
+ dataReturnType={options.client.dataReturnType}
91
+ pathParamsType={options.pathParamsType}
92
+ />
93
+ </File>
94
+ )
95
+ },
96
+ })
@@ -0,0 +1,101 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { Query, QueryOptions } from '../components'
10
+ import type { PluginSwr } from '../types'
11
+
12
+ export const queryGenerator = createReactGenerator<PluginSwr>({
13
+ name: 'swr-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginSwr>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+
22
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
23
+
24
+ const query = {
25
+ name: getName(operation, { type: 'function', prefix: 'use' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'use' }),
28
+ }
29
+
30
+ const client = {
31
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
32
+ }
33
+
34
+ const queryOptions = {
35
+ name: transformers.camelCase(`${operation.getOperationId()} QueryOptions`),
36
+ }
37
+
38
+ const type = {
39
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
40
+ //todo remove type?
41
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
42
+ }
43
+
44
+ const zod = {
45
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
46
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
47
+ }
48
+
49
+ if (!isQuery) {
50
+ return null
51
+ }
52
+
53
+ return (
54
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
55
+ {options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
56
+ <File.Import name={['Key']} path="swr" isTypeOnly />
57
+ <File.Import name="useSWR" path={options.query.importPath} />
58
+ <File.Import name={['SWRConfiguration', 'SWRResponse']} path={options.query.importPath} isTypeOnly />
59
+ <File.Import name={'client'} path={options.client.importPath} />
60
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
61
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
62
+
63
+ <File.Import
64
+ extName={output?.extName}
65
+ name={[
66
+ type.schemas.request?.name,
67
+ type.schemas.response.name,
68
+ type.schemas.pathParams?.name,
69
+ type.schemas.queryParams?.name,
70
+ type.schemas.headerParams?.name,
71
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
72
+ ].filter(Boolean)}
73
+ root={query.file.path}
74
+ path={type.file.path}
75
+ isTypeOnly
76
+ />
77
+ <Client
78
+ name={client.name}
79
+ isExportable={false}
80
+ isIndexable={false}
81
+ baseURL={options.baseURL}
82
+ operation={operation}
83
+ typeSchemas={type.schemas}
84
+ zodSchemas={zod.schemas}
85
+ dataReturnType={options.client.dataReturnType}
86
+ pathParamsType={options.pathParamsType}
87
+ parser={options.parser}
88
+ />
89
+ <QueryOptions name={queryOptions.name} clientName={client.name} typeSchemas={type.schemas} pathParamsType={options.pathParamsType} />
90
+ <Query
91
+ name={query.name}
92
+ queryOptionsName={queryOptions.name}
93
+ typeSchemas={type.schemas}
94
+ pathParamsType={options.pathParamsType}
95
+ operation={operation}
96
+ dataReturnType={options.client.dataReturnType}
97
+ />
98
+ </File>
99
+ )
100
+ },
101
+ })