@kubb/plugin-vue-query 0.0.0-canary-20241104172400

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-A7SD37VK.cjs +584 -0
  4. package/dist/chunk-A7SD37VK.cjs.map +1 -0
  5. package/dist/chunk-DHJLKFYS.js +827 -0
  6. package/dist/chunk-DHJLKFYS.js.map +1 -0
  7. package/dist/chunk-J4RZRRHQ.cjs +837 -0
  8. package/dist/chunk-J4RZRRHQ.cjs.map +1 -0
  9. package/dist/chunk-O4EGNKUX.js +576 -0
  10. package/dist/chunk-O4EGNKUX.js.map +1 -0
  11. package/dist/components.cjs +36 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +150 -0
  14. package/dist/components.d.ts +150 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +21 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +12 -0
  20. package/dist/generators.d.ts +12 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +134 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +9 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.js +127 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-C8LfCZUP.d.cts +389 -0
  30. package/dist/types-C8LfCZUP.d.ts +389 -0
  31. package/package.json +102 -0
  32. package/src/components/InfiniteQuery.tsx +190 -0
  33. package/src/components/InfiniteQueryOptions.tsx +185 -0
  34. package/src/components/Mutation.tsx +167 -0
  35. package/src/components/MutationKey.tsx +54 -0
  36. package/src/components/Query.tsx +191 -0
  37. package/src/components/QueryKey.tsx +91 -0
  38. package/src/components/QueryOptions.tsx +152 -0
  39. package/src/components/index.ts +7 -0
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +53 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +53 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +45 -0
  43. package/src/generators/__snapshots__/findByTags.ts +53 -0
  44. package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
  45. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +53 -0
  46. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +53 -0
  47. package/src/generators/__snapshots__/findByTagsWithZod.ts +53 -0
  48. package/src/generators/__snapshots__/findInfiniteByTags.ts +58 -0
  49. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +58 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +52 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +45 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +45 -0
  53. package/src/generators/index.ts +3 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +137 -0
  55. package/src/generators/mutationGenerator.tsx +116 -0
  56. package/src/generators/queryGenerator.tsx +129 -0
  57. package/src/index.ts +2 -0
  58. package/src/plugin.ts +149 -0
  59. package/src/types.ts +159 -0
@@ -0,0 +1,58 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
4
+ import type { MaybeRef } from "vue";
5
+ import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
6
+
7
+ export const findPetsByTagsInfiniteQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
8
+
9
+ export type FindPetsByTagsInfiniteQueryKey = ReturnType<typeof findPetsByTagsInfiniteQueryKey>;
10
+
11
+ /**
12
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
13
+ * @summary Finds Pets by tags
14
+ * @link /pet/findByTags
15
+ */
16
+ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
17
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
18
+ return findPetsByTagsQueryResponse.parse(res.data);
19
+ }
20
+
21
+ export function findPetsByTagsInfiniteQueryOptions(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, config: Partial<RequestConfig> = {}) {
22
+ const queryKey = findPetsByTagsInfiniteQueryKey(params);
23
+ return infiniteQueryOptions({
24
+ queryKey,
25
+ queryFn: async ({ signal, pageParam }) => {
26
+ config.signal = signal;
27
+ if (params) {
28
+ params["pageSize"] = pageParam as unknown as FindPetsByTagsQueryParams["pageSize"];
29
+ }
30
+ return findPetsByTags(headers, params, config);
31
+ },
32
+ initialPageParam: 0,
33
+ getNextPageParam: (lastPage) => lastPage["cursor"],
34
+ getPreviousPageParam: (firstPage) => firstPage["cursor"]
35
+ });
36
+ }
37
+
38
+ /**
39
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
40
+ * @summary Finds Pets by tags
41
+ * @link /pet/findByTags
42
+ */
43
+ export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, options: {
44
+ query?: Partial<InfiniteQueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
45
+ client?: Partial<RequestConfig>;
46
+ } = {}) {
47
+ const { query: queryOptions, client: config = {} } = options ?? {};
48
+ const queryKey = queryOptions?.queryKey ?? findPetsByTagsInfiniteQueryKey(params);
49
+ const query = useInfiniteQuery({
50
+ ...findPetsByTagsInfiniteQueryOptions(headers, params, config) as unknown as InfiniteQueryObserverOptions,
51
+ queryKey: queryKey as QueryKey,
52
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
53
+ }) as UseInfiniteQueryReturnType<TData, FindPetsByTags400> & {
54
+ queryKey: TQueryKey;
55
+ };
56
+ query.queryKey = queryKey as TQueryKey;
57
+ return query;
58
+ }
@@ -0,0 +1,52 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "custom-query";
4
+ import type { MaybeRef } from "vue";
5
+ import { queryOptions, useQuery } from "custom-query";
6
+ import { unref } from "vue";
7
+
8
+ export const updatePetWithFormQueryKey = (petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>, data?: MaybeRef<UpdatePetWithFormMutationRequest>, params?: MaybeRef<UpdatePetWithFormQueryParams>) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
9
+
10
+ export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey>;
11
+
12
+ /**
13
+ * @summary Updates a pet in the store with form data
14
+ * @link /pet/:petId
15
+ */
16
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
17
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
18
+ return updatePetWithFormMutationResponse.parse(res.data);
19
+ }
20
+
21
+ export function updatePetWithFormQueryOptions(petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>, data?: MaybeRef<UpdatePetWithFormMutationRequest>, params?: MaybeRef<UpdatePetWithFormQueryParams>, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
22
+ const queryKey = updatePetWithFormQueryKey(petId, data, params);
23
+ return queryOptions({
24
+ enabled: !!(petId),
25
+ queryKey,
26
+ queryFn: async ({ signal }) => {
27
+ config.signal = signal;
28
+ return updatePetWithForm(unref(petId), unref(data), unref(params), unref(config));
29
+ },
30
+ });
31
+ }
32
+
33
+ /**
34
+ * @summary Updates a pet in the store with form data
35
+ * @link /pet/:petId
36
+ */
37
+ export function useUpdatePetWithForm<TData = UpdatePetWithFormMutationResponse, TQueryData = UpdatePetWithFormMutationResponse, TQueryKey extends QueryKey = UpdatePetWithFormQueryKey>(petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>, data?: MaybeRef<UpdatePetWithFormMutationRequest>, params?: MaybeRef<UpdatePetWithFormQueryParams>, options: {
38
+ query?: Partial<QueryObserverOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, TData, TQueryData, TQueryKey>>;
39
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
40
+ } = {}) {
41
+ const { query: queryOptions, client: config = {} } = options ?? {};
42
+ const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params);
43
+ const query = useQuery({
44
+ ...updatePetWithFormQueryOptions(petId, data, params, config) as unknown as QueryObserverOptions,
45
+ queryKey: queryKey as QueryKey,
46
+ ...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
47
+ }) as UseQueryReturnType<TData, UpdatePetWithForm405> & {
48
+ queryKey: TQueryKey;
49
+ };
50
+ query.queryKey = queryKey as TQueryKey;
51
+ return query;
52
+ }
@@ -0,0 +1,45 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { MutationObserverOptions } from "@tanstack/vue-query";
4
+ import type { MaybeRef } from "vue";
5
+ import { useMutation } from "@tanstack/vue-query";
6
+
7
+ export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
8
+
9
+ export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
10
+
11
+ /**
12
+ * @summary Updates a pet in the store with form data
13
+ * @link /pet/:petId
14
+ */
15
+ async function updatePetWithForm(petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
16
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
17
+ return updatePetWithFormMutationResponse.parse(res.data);
18
+ }
19
+
20
+ /**
21
+ * @summary Updates a pet in the store with form data
22
+ * @link /pet/:petId
23
+ */
24
+ export function useUpdatePetWithForm(options: {
25
+ mutation?: MutationObserverOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
26
+ petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>;
27
+ data?: MaybeRef<UpdatePetWithFormMutationRequest>;
28
+ params?: MaybeRef<UpdatePetWithFormQueryParams>;
29
+ }>;
30
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
31
+ } = {}) {
32
+ const { mutation: mutationOptions, client: config = {} } = options ?? {};
33
+ const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
34
+ return useMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
35
+ petId: UpdatePetWithFormPathParams["petId"];
36
+ data?: UpdatePetWithFormMutationRequest;
37
+ params?: UpdatePetWithFormQueryParams;
38
+ }>({
39
+ mutationFn: async ({ petId, data, params }) => {
40
+ return updatePetWithForm(petId, data, params, config);
41
+ },
42
+ mutationKey,
43
+ ...mutationOptions
44
+ });
45
+ }
@@ -0,0 +1,45 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { MutationObserverOptions } from "@tanstack/vue-query";
4
+ import type { MaybeRef } from "vue";
5
+ import { useMutation } from "@tanstack/vue-query";
6
+
7
+ export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
8
+
9
+ export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>;
10
+
11
+ /**
12
+ * @summary Updates a pet in the store with form data
13
+ * @link /pet/:petId
14
+ */
15
+ async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
16
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
17
+ return updatePetWithFormMutationResponse.parse(res.data);
18
+ }
19
+
20
+ /**
21
+ * @summary Updates a pet in the store with form data
22
+ * @link /pet/:petId
23
+ */
24
+ export function useUpdatePetWithForm(options: {
25
+ mutation?: MutationObserverOptions<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
26
+ petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>;
27
+ data?: MaybeRef<UpdatePetWithFormMutationRequest>;
28
+ params?: MaybeRef<UpdatePetWithFormQueryParams>;
29
+ }>;
30
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>>;
31
+ } = {}) {
32
+ const { mutation: mutationOptions, client: config = {} } = options ?? {};
33
+ const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
34
+ return useMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
35
+ petId: UpdatePetWithFormPathParams["petId"];
36
+ data?: UpdatePetWithFormMutationRequest;
37
+ params?: UpdatePetWithFormQueryParams;
38
+ }>({
39
+ mutationFn: async ({ petId, data, params }) => {
40
+ return updatePetWithForm({ petId }, data, params, config);
41
+ },
42
+ mutationKey,
43
+ ...mutationOptions
44
+ });
45
+ }
@@ -0,0 +1,3 @@
1
+ export { queryGenerator } from './queryGenerator.tsx'
2
+ export { mutationGenerator } from './mutationGenerator.tsx'
3
+ export { infiniteQueryGenerator } from './infiniteQueryGenerator.tsx'
@@ -0,0 +1,137 @@
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 { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
9
+ import type { PluginVueQuery } from '../types'
10
+
11
+ export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
12
+ name: 'vue-infinite-query',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginVueQuery>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
21
+ const isInfinite = isQuery && !!options.infinite
22
+ const importPath = options.query ? options.query.importPath : '@tanstack/vue-query'
23
+
24
+ const query = {
25
+ name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
28
+ }
29
+
30
+ const client = {
31
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
32
+ }
33
+
34
+ const queryOptions = {
35
+ name: getName(operation, { type: 'function', suffix: 'InfiniteQueryOptions' }),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'InfiniteQueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'InfiniteQueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery || !isInfinite) {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name={['unref']} path="vue" />
62
+ <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
63
+ <File.Import name={'client'} path={options.client.importPath} />
64
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
66
+ <File.Import
67
+ name={[
68
+ type.schemas.request?.name,
69
+ type.schemas.response.name,
70
+ type.schemas.pathParams?.name,
71
+ type.schemas.queryParams?.name,
72
+ type.schemas.headerParams?.name,
73
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
74
+ ].filter(Boolean)}
75
+ root={query.file.path}
76
+ path={type.file.path}
77
+ isTypeOnly
78
+ />
79
+ <QueryKey
80
+ name={queryKey.name}
81
+ typeName={queryKey.typeName}
82
+ operation={operation}
83
+ pathParamsType={options.pathParamsType}
84
+ typeSchemas={type.schemas}
85
+ transformer={options.queryKey}
86
+ />
87
+ <Client
88
+ name={client.name}
89
+ isExportable={false}
90
+ isIndexable={false}
91
+ baseURL={options.client.baseURL}
92
+ operation={operation}
93
+ typeSchemas={type.schemas}
94
+ zodSchemas={zod.schemas}
95
+ dataReturnType={options.client.dataReturnType}
96
+ paramsType={options.paramsType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ {options.infinite && (
101
+ <>
102
+ <File.Import name={['infiniteQueryOptions']} path={importPath} />
103
+ <InfiniteQueryOptions
104
+ name={queryOptions.name}
105
+ clientName={client.name}
106
+ queryKeyName={queryKey.name}
107
+ typeSchemas={type.schemas}
108
+ paramsType={options.paramsType}
109
+ pathParamsType={options.pathParamsType}
110
+ dataReturnType={options.client.dataReturnType}
111
+ cursorParam={options.infinite.cursorParam}
112
+ initialPageParam={options.infinite.initialPageParam}
113
+ queryParam={options.infinite.queryParam}
114
+ />
115
+ </>
116
+ )}
117
+ {options.infinite && (
118
+ <>
119
+ <File.Import name={['useInfiniteQuery']} path={importPath} />
120
+ <File.Import name={['QueryKey', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryReturnType']} path={importPath} isTypeOnly />
121
+ <InfiniteQuery
122
+ name={query.name}
123
+ queryOptionsName={queryOptions.name}
124
+ typeSchemas={type.schemas}
125
+ paramsType={options.paramsType}
126
+ pathParamsType={options.pathParamsType}
127
+ operation={operation}
128
+ dataReturnType={options.client.dataReturnType}
129
+ queryKeyName={queryKey.name}
130
+ queryKeyTypeName={queryKey.typeName}
131
+ />
132
+ </>
133
+ )}
134
+ </File>
135
+ )
136
+ },
137
+ })
@@ -0,0 +1,116 @@
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, MutationKey } from '../components'
9
+ import type { PluginVueQuery } from '../types'
10
+
11
+ export const mutationGenerator = createReactGenerator<PluginVueQuery>({
12
+ name: 'vue-query',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginVueQuery>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+
21
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
22
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
23
+
24
+ const importPath = options.mutation ? options.mutation.importPath : '@tanstack/vue-query'
25
+
26
+ const mutation = {
27
+ name: getName(operation, { type: 'function', prefix: 'use' }),
28
+ typeName: getName(operation, { type: 'type' }),
29
+ file: getFile(operation, { prefix: 'use' }),
30
+ }
31
+
32
+ const type = {
33
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
34
+ //todo remove type?
35
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
36
+ }
37
+
38
+ const zod = {
39
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
40
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
41
+ }
42
+
43
+ const client = {
44
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
45
+ }
46
+
47
+ const mutationKey = {
48
+ name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
49
+ typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
50
+ }
51
+
52
+ if (!isMutation) {
53
+ return null
54
+ }
55
+
56
+ return (
57
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
58
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
59
+ <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
60
+ <File.Import name={'client'} path={options.client.importPath} />
61
+ <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
62
+ <File.Import
63
+ name={[
64
+ type.schemas.request?.name,
65
+ type.schemas.response.name,
66
+ type.schemas.pathParams?.name,
67
+ type.schemas.queryParams?.name,
68
+ type.schemas.headerParams?.name,
69
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
70
+ ].filter(Boolean)}
71
+ root={mutation.file.path}
72
+ path={type.file.path}
73
+ isTypeOnly
74
+ />
75
+ <MutationKey
76
+ name={mutationKey.name}
77
+ typeName={mutationKey.typeName}
78
+ operation={operation}
79
+ pathParamsType={options.pathParamsType}
80
+ typeSchemas={type.schemas}
81
+ transformer={options.mutationKey}
82
+ />
83
+ <Client
84
+ name={client.name}
85
+ isExportable={false}
86
+ isIndexable={false}
87
+ baseURL={options.client.baseURL}
88
+ operation={operation}
89
+ typeSchemas={type.schemas}
90
+ zodSchemas={zod.schemas}
91
+ dataReturnType={options.client.dataReturnType}
92
+ paramsType={options.paramsType}
93
+ pathParamsType={options.pathParamsType}
94
+ parser={options.parser}
95
+ />
96
+ {options.mutation && (
97
+ <>
98
+ <File.Import name={['useMutation']} path={importPath} />
99
+ <File.Import name={['MutationObserverOptions']} path={importPath} isTypeOnly />
100
+ <Mutation
101
+ name={mutation.name}
102
+ clientName={client.name}
103
+ typeName={mutation.typeName}
104
+ typeSchemas={type.schemas}
105
+ operation={operation}
106
+ dataReturnType={options.client.dataReturnType}
107
+ paramsType={options.paramsType}
108
+ pathParamsType={options.pathParamsType}
109
+ mutationKeyName={mutationKey.name}
110
+ />
111
+ </>
112
+ )}
113
+ </File>
114
+ )
115
+ },
116
+ })
@@ -0,0 +1,129 @@
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 { Query, QueryKey, QueryOptions } from '../components'
9
+ import type { PluginVueQuery } from '../types'
10
+
11
+ export const queryGenerator = createReactGenerator<PluginVueQuery>({
12
+ name: 'vue-query',
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output },
17
+ },
18
+ } = useApp<PluginVueQuery>()
19
+ const { getSchemas, getName, getFile } = useOperationManager()
20
+
21
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
22
+ const importPath = options.query ? options.query.importPath : '@tanstack/vue-query'
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: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery) {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name={['unref']} path="vue" />
62
+ <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
63
+ <File.Import name={'client'} path={options.client.importPath} />
64
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
66
+ <File.Import
67
+ name={[
68
+ type.schemas.request?.name,
69
+ type.schemas.response.name,
70
+ type.schemas.pathParams?.name,
71
+ type.schemas.queryParams?.name,
72
+ type.schemas.headerParams?.name,
73
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
74
+ ].filter(Boolean)}
75
+ root={query.file.path}
76
+ path={type.file.path}
77
+ isTypeOnly
78
+ />
79
+ <QueryKey
80
+ name={queryKey.name}
81
+ typeName={queryKey.typeName}
82
+ operation={operation}
83
+ pathParamsType={options.pathParamsType}
84
+ typeSchemas={type.schemas}
85
+ transformer={options.queryKey}
86
+ />
87
+ <Client
88
+ name={client.name}
89
+ isExportable={false}
90
+ isIndexable={false}
91
+ baseURL={options.client.baseURL}
92
+ operation={operation}
93
+ typeSchemas={type.schemas}
94
+ zodSchemas={zod.schemas}
95
+ dataReturnType={options.client.dataReturnType}
96
+ paramsType={options.paramsType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ <File.Import name={['queryOptions']} path={importPath} />
101
+ <QueryOptions
102
+ name={queryOptions.name}
103
+ clientName={client.name}
104
+ queryKeyName={queryKey.name}
105
+ typeSchemas={type.schemas}
106
+ paramsType={options.paramsType}
107
+ pathParamsType={options.pathParamsType}
108
+ />
109
+ {options.query && (
110
+ <>
111
+ <File.Import name={['useQuery']} path={importPath} />
112
+ <File.Import name={['QueryKey', 'QueryObserverOptions', 'UseQueryReturnType']} path={importPath} isTypeOnly />
113
+ <Query
114
+ name={query.name}
115
+ queryOptionsName={queryOptions.name}
116
+ typeSchemas={type.schemas}
117
+ paramsType={options.paramsType}
118
+ pathParamsType={options.pathParamsType}
119
+ operation={operation}
120
+ dataReturnType={options.client.dataReturnType}
121
+ queryKeyName={queryKey.name}
122
+ queryKeyTypeName={queryKey.typeName}
123
+ />
124
+ </>
125
+ )}
126
+ </File>
127
+ )
128
+ },
129
+ })
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { pluginVueQuery, pluginVueQueryName } from './plugin.ts'
2
+ export type { PluginVueQuery } from './types.ts'