@kubb/plugin-vue-query 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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/chunk-3HD4DCDR.js +505 -0
  4. package/dist/chunk-3HD4DCDR.js.map +1 -0
  5. package/dist/chunk-4YY5DUPV.cjs +514 -0
  6. package/dist/chunk-4YY5DUPV.cjs.map +1 -0
  7. package/dist/chunk-BKYBSBUA.js +567 -0
  8. package/dist/chunk-BKYBSBUA.js.map +1 -0
  9. package/dist/chunk-FRKJLBA5.cjs +576 -0
  10. package/dist/chunk-FRKJLBA5.cjs.map +1 -0
  11. package/dist/components.cjs +32 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +121 -0
  14. package/dist/components.d.ts +121 -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 +138 -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 +131 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-CmetQDTc.d.cts +173 -0
  30. package/dist/types-CmetQDTc.d.ts +173 -0
  31. package/package.json +102 -0
  32. package/src/components/InfiniteQuery.tsx +137 -0
  33. package/src/components/InfiniteQueryOptions.tsx +129 -0
  34. package/src/components/Mutation.tsx +141 -0
  35. package/src/components/Query.tsx +128 -0
  36. package/src/components/QueryKey.tsx +81 -0
  37. package/src/components/QueryOptions.tsx +88 -0
  38. package/src/components/index.ts +6 -0
  39. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +52 -0
  40. package/src/generators/__snapshots__/clientGetImportPath.ts +52 -0
  41. package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
  42. package/src/generators/__snapshots__/findByTags.ts +52 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +52 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +52 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +52 -0
  46. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  47. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  48. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  49. package/src/generators/__snapshots__/updatePetById.ts +38 -0
  50. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
  51. package/src/generators/index.ts +3 -0
  52. package/src/generators/infiniteQueryGenerator.tsx +131 -0
  53. package/src/generators/mutationGenerator.tsx +96 -0
  54. package/src/generators/queryGenerator.tsx +124 -0
  55. package/src/index.ts +2 -0
  56. package/src/plugin.ts +152 -0
  57. package/src/types.ts +179 -0
@@ -0,0 +1,131 @@
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 { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
10
+ import type { PluginVueQuery } from '../types'
11
+
12
+ export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
13
+ name: 'vue-infinite-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginVueQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
22
+ const isInfinite = isQuery && !!options.infinite
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: transformers.camelCase(`${operation.getOperationId()} InfiniteQueryOptions`),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: transformers.camelCase(`${operation.getOperationId()} InfiniteQueryKey`),
40
+ typeName: transformers.pascalCase(`${operation.getOperationId()} 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 || typeof options.query === 'boolean' || typeof options.infinite === 'boolean') {
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 extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
62
+ <File.Import
63
+ name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryReturnType']}
64
+ path={options.query.importPath}
65
+ isTypeOnly
66
+ />
67
+ <File.Import name={['unref']} path="vue" />
68
+ <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
69
+ <File.Import name={'client'} path={options.client.importPath} />
70
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
71
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
72
+ <File.Import
73
+ extName={output?.extName}
74
+ name={[
75
+ type.schemas.request?.name,
76
+ type.schemas.response.name,
77
+ type.schemas.pathParams?.name,
78
+ type.schemas.queryParams?.name,
79
+ type.schemas.headerParams?.name,
80
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
81
+ ].filter(Boolean)}
82
+ root={query.file.path}
83
+ path={type.file.path}
84
+ isTypeOnly
85
+ />
86
+
87
+ <QueryKey
88
+ name={queryKey.name}
89
+ typeName={queryKey.typeName}
90
+ operation={operation}
91
+ pathParamsType={options.pathParamsType}
92
+ typeSchemas={type.schemas}
93
+ keysFn={options.query.key}
94
+ />
95
+ <Client
96
+ name={client.name}
97
+ isExportable={false}
98
+ isIndexable={false}
99
+ baseURL={options.baseURL}
100
+ operation={operation}
101
+ typeSchemas={type.schemas}
102
+ zodSchemas={zod.schemas}
103
+ dataReturnType={options.client.dataReturnType}
104
+ pathParamsType={options.pathParamsType}
105
+ parser={options.parser}
106
+ />
107
+ <InfiniteQueryOptions
108
+ name={queryOptions.name}
109
+ clientName={client.name}
110
+ queryKeyName={queryKey.name}
111
+ typeSchemas={type.schemas}
112
+ pathParamsType={options.pathParamsType}
113
+ dataReturnType={options.client.dataReturnType}
114
+ cursorParam={options.infinite.cursorParam}
115
+ initialPageParam={options.infinite.initialPageParam}
116
+ queryParam={options.infinite.queryParam}
117
+ />
118
+ <InfiniteQuery
119
+ name={query.name}
120
+ queryOptionsName={queryOptions.name}
121
+ typeSchemas={type.schemas}
122
+ pathParamsType={options.pathParamsType}
123
+ operation={operation}
124
+ dataReturnType={options.client.dataReturnType}
125
+ queryKeyName={queryKey.name}
126
+ queryKeyTypeName={queryKey.typeName}
127
+ />
128
+ </File>
129
+ )
130
+ },
131
+ })
@@ -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 { 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 mutation = {
25
+ name: getName(operation, { type: 'function', prefix: 'use' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'use' }),
28
+ }
29
+
30
+ const type = {
31
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
32
+ //todo remove type?
33
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
34
+ }
35
+
36
+ const zod = {
37
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
38
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
39
+ }
40
+
41
+ const client = {
42
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
43
+ }
44
+
45
+ if (!isMutation || typeof options.mutation === 'boolean') {
46
+ return null
47
+ }
48
+
49
+ return (
50
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
51
+ {options.parser === 'zod' && (
52
+ <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />
53
+ )}
54
+ <File.Import name={['useMutation']} path={options.mutation.importPath} />
55
+ <File.Import name={['UseMutationOptions']} 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,124 @@
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, QueryKey, QueryOptions } from '../components'
10
+ import type { PluginVueQuery } from '../types'
11
+
12
+ export const queryGenerator = createReactGenerator<PluginVueQuery>({
13
+ name: 'vue-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginVueQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+
22
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
23
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
24
+
25
+ const query = {
26
+ name: getName(operation, { type: 'function', prefix: 'use' }),
27
+ typeName: getName(operation, { type: 'type' }),
28
+ file: getFile(operation, { prefix: 'use' }),
29
+ }
30
+
31
+ const client = {
32
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
33
+ }
34
+
35
+ const queryOptions = {
36
+ name: transformers.camelCase(`${operation.getOperationId()} QueryOptions`),
37
+ }
38
+
39
+ const queryKey = {
40
+ name: transformers.camelCase(`${operation.getOperationId()} QueryKey`),
41
+ typeName: transformers.pascalCase(`${operation.getOperationId()} QueryKey`),
42
+ }
43
+
44
+ const type = {
45
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
46
+ //todo remove type?
47
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
48
+ }
49
+
50
+ const zod = {
51
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
52
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
53
+ }
54
+
55
+ if (!isQuery || typeof options.query === 'boolean') {
56
+ return null
57
+ }
58
+
59
+ return (
60
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
61
+ {options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
62
+ <File.Import name={['useQuery', 'queryOptions']} path={options.query.importPath} />
63
+ <File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryReturnType']} path={options.query.importPath} isTypeOnly />
64
+ <File.Import name={['unref']} path="vue" />
65
+ <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
66
+ <File.Import name={'client'} path={options.client.importPath} />
67
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
68
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
69
+ <File.Import
70
+ extName={output?.extName}
71
+ name={[
72
+ type.schemas.request?.name,
73
+ type.schemas.response.name,
74
+ type.schemas.pathParams?.name,
75
+ type.schemas.queryParams?.name,
76
+ type.schemas.headerParams?.name,
77
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
78
+ ].filter(Boolean)}
79
+ root={query.file.path}
80
+ path={type.file.path}
81
+ isTypeOnly
82
+ />
83
+
84
+ <QueryKey
85
+ name={queryKey.name}
86
+ typeName={queryKey.typeName}
87
+ operation={operation}
88
+ pathParamsType={options.pathParamsType}
89
+ typeSchemas={type.schemas}
90
+ keysFn={options.query.key}
91
+ />
92
+ <Client
93
+ name={client.name}
94
+ isExportable={false}
95
+ isIndexable={false}
96
+ baseURL={options.baseURL}
97
+ operation={operation}
98
+ typeSchemas={type.schemas}
99
+ zodSchemas={zod.schemas}
100
+ dataReturnType={options.client.dataReturnType}
101
+ pathParamsType={options.pathParamsType}
102
+ parser={options.parser}
103
+ />
104
+ <QueryOptions
105
+ name={queryOptions.name}
106
+ clientName={client.name}
107
+ queryKeyName={queryKey.name}
108
+ typeSchemas={type.schemas}
109
+ pathParamsType={options.pathParamsType}
110
+ />
111
+ <Query
112
+ name={query.name}
113
+ queryOptionsName={queryOptions.name}
114
+ typeSchemas={type.schemas}
115
+ pathParamsType={options.pathParamsType}
116
+ operation={operation}
117
+ dataReturnType={options.client.dataReturnType}
118
+ queryKeyName={queryKey.name}
119
+ queryKeyTypeName={queryKey.typeName}
120
+ />
121
+ </File>
122
+ )
123
+ },
124
+ })
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { pluginVueQuery, pluginVueQueryName } from './plugin.ts'
2
+ export type { PluginVueQuery } from './types.ts'
package/src/plugin.ts ADDED
@@ -0,0 +1,152 @@
1
+ import path from 'node:path'
2
+
3
+ import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
+ import { camelCase, pascalCase } from '@kubb/core/transformers'
5
+ import { renderTemplate } from '@kubb/core/utils'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
+
8
+ import { pluginTsName } from '@kubb/plugin-ts'
9
+ import { pluginZodName } from '@kubb/plugin-zod'
10
+
11
+ import type { Plugin } from '@kubb/core'
12
+ import type { PluginOas } from '@kubb/plugin-oas'
13
+ import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
14
+ import type { PluginVueQuery } from './types.ts'
15
+
16
+ export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
17
+
18
+ export const pluginVueQuery = createPlugin<PluginVueQuery>((options) => {
19
+ const {
20
+ output = { path: 'hooks' },
21
+ group,
22
+ exclude = [],
23
+ include,
24
+ override = [],
25
+ parser = 'client',
26
+ infinite,
27
+ transformers = {},
28
+ pathParamsType = 'inline',
29
+ mutation = {},
30
+ query = {},
31
+ } = options
32
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
33
+
34
+ return {
35
+ name: pluginVueQueryName,
36
+ options: {
37
+ output: {
38
+ exportType: 'barrelNamed',
39
+ ...output,
40
+ },
41
+ baseURL: undefined,
42
+ client: {
43
+ importPath: '@kubb/plugin-client/client',
44
+ dataReturnType: 'data',
45
+ pathParamsType: 'inline',
46
+ ...options.client,
47
+ },
48
+ infinite: infinite
49
+ ? {
50
+ queryParam: 'id',
51
+ initialPageParam: 0,
52
+ cursorParam: undefined,
53
+ ...infinite,
54
+ }
55
+ : false,
56
+ query: {
57
+ key: (key: unknown[]) => key,
58
+ methods: ['get'],
59
+ importPath: '@tanstack/vue-query',
60
+ ...query,
61
+ },
62
+ mutation: {
63
+ methods: ['post', 'put', 'patch', 'delete'],
64
+ importPath: '@tanstack/vue-query',
65
+ ...mutation,
66
+ },
67
+ pathParamsType,
68
+ parser,
69
+ },
70
+ pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
71
+ resolvePath(baseName, pathMode, options) {
72
+ const root = path.resolve(this.config.root, this.config.output.path)
73
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
74
+
75
+ if (mode === 'single') {
76
+ /**
77
+ * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
78
+ * Other plugins then need to call addOrAppend instead of just add from the fileManager class
79
+ */
80
+ return path.resolve(root, output.path)
81
+ }
82
+
83
+ if (options?.tag && group?.type === 'tag') {
84
+ const tag = camelCase(options.tag)
85
+
86
+ return path.resolve(root, renderTemplate(template, { tag }), baseName)
87
+ }
88
+
89
+ return path.resolve(root, output.path, baseName)
90
+ },
91
+ resolveName(name, type) {
92
+ let resolvedName = camelCase(name)
93
+
94
+ if (type === 'file' || type === 'function') {
95
+ resolvedName = camelCase(name, {
96
+ isFile: type === 'file',
97
+ })
98
+ }
99
+ if (type === 'type') {
100
+ resolvedName = pascalCase(name)
101
+ }
102
+
103
+ if (type) {
104
+ return transformers?.name?.(resolvedName, type) || resolvedName
105
+ }
106
+
107
+ return resolvedName
108
+ },
109
+ async buildStart() {
110
+ const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
111
+
112
+ const oas = await swaggerPlugin.context.getOas()
113
+ const root = path.resolve(this.config.root, this.config.output.path)
114
+ const mode = FileManager.getMode(path.resolve(root, output.path))
115
+ const baseURL = await swaggerPlugin.context.getBaseURL()
116
+
117
+ const operationGenerator = new OperationGenerator(
118
+ {
119
+ ...this.plugin.options,
120
+ baseURL,
121
+ },
122
+ {
123
+ oas,
124
+ pluginManager: this.pluginManager,
125
+ plugin: this.plugin,
126
+ contentType: swaggerPlugin.context.contentType,
127
+ exclude,
128
+ include,
129
+ override,
130
+ mode,
131
+ },
132
+ )
133
+
134
+ const files = await operationGenerator.build(queryGenerator, infiniteQueryGenerator, mutationGenerator)
135
+ await this.addFile(...files)
136
+
137
+ if (this.config.output.exportType) {
138
+ const barrelFiles = await this.fileManager.getBarrelFiles({
139
+ root,
140
+ output,
141
+ files: this.fileManager.files,
142
+ meta: {
143
+ pluginKey: this.plugin.key,
144
+ },
145
+ logger: this.logger,
146
+ })
147
+
148
+ await this.addFile(...barrelFiles)
149
+ }
150
+ },
151
+ }
152
+ })
package/src/types.ts ADDED
@@ -0,0 +1,179 @@
1
+ import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
+
3
+ import type { HttpMethod } from '@kubb/oas'
4
+ import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
+
6
+ type Query = {
7
+ /**
8
+ * Customize the queryKey, here you can specify a suffix.
9
+ */
10
+ key: (key: unknown[]) => unknown[]
11
+ /**
12
+ * Define which HttpMethods can be used for queries
13
+ * @default ['get']
14
+ */
15
+ methods: Array<HttpMethod>
16
+ /**
17
+ * Path to the useQuery that will be used to do the useQuery functionality.
18
+ * It will be used as `import { useQuery } from '${importPath}'`.
19
+ * It allows both relative and absolute path.
20
+ * the path will be applied as is, so relative path should be based on the file being generated.
21
+ * @default '@tanstack/react-query'
22
+ */
23
+ importPath?: string
24
+ }
25
+
26
+ type Mutation = {
27
+ /**
28
+ * Define which HttpMethods can be used for mutations
29
+ * @default ['post', 'put', 'delete']
30
+ */
31
+ methods: Array<HttpMethod>
32
+ /**
33
+ * Path to the useQuery that will be used to do the useQuery functionality.
34
+ * It will be used as `import { useQuery } from '${importPath}'`.
35
+ * It allows both relative and absolute path.
36
+ * the path will be applied as is, so relative path should be based on the file being generated.
37
+ * @default '@tanstack/react-query'
38
+ */
39
+ importPath?: string
40
+ }
41
+
42
+ export type Infinite = {
43
+ /**
44
+ * Specify the params key used for `pageParam`.
45
+ * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
46
+ * @default `'id'`
47
+ */
48
+ queryParam: string
49
+ /**
50
+ * Which field of the data will be used, set it to undefined when no cursor is known.
51
+ */
52
+ cursorParam?: string | undefined
53
+ /**
54
+ * The initial value, the value of the first page.
55
+ * @default `0`
56
+ */
57
+ initialPageParam: unknown
58
+ }
59
+
60
+ export type Options = {
61
+ /**
62
+ * @default 'hooks'
63
+ */
64
+ output?: Output
65
+ /**
66
+ * Group the @tanstack/query hooks based on the provided name.
67
+ */
68
+ group?: {
69
+ /**
70
+ * Tag will group based on the operation tag inside the Swagger file
71
+ */
72
+ type: 'tag'
73
+ /**
74
+ * Relative path to save the grouped @tanstack/query hooks.
75
+ *
76
+ * `{{tag}}` will be replaced by the current tagName.
77
+ * @example `${output}/{{tag}}Controller` => `hooks/PetController`
78
+ * @default `${output}/{{tag}}Controller`
79
+ */
80
+ output?: string
81
+ /**
82
+ * Name to be used for the `export * as {{exportAs}} from './`
83
+ * @default `"{{tag}}Hooks"`
84
+ */
85
+ exportAs?: string
86
+ }
87
+
88
+ client?: {
89
+ /**
90
+ * Path to the client that will be used to do the API calls.
91
+ * It will be used as `import client from '${client.importPath}'`.
92
+ * It allows both relative and absolute path.
93
+ * the path will be applied as is, so relative path should be based on the file being generated.
94
+ * @default '@kubb/plugin-client/client'
95
+ */
96
+ importPath?: string
97
+ /**
98
+ * ReturnType that needs to be used when calling client().
99
+ *
100
+ * `Data` will return ResponseConfig[data].
101
+ *
102
+ * `Full` will return ResponseConfig.
103
+ * @default `'data'`
104
+ * @private
105
+ */
106
+ dataReturnType?: 'data' | 'full'
107
+ }
108
+ /**
109
+ * ReturnType that needs to be used when calling client().
110
+ *
111
+ * `Data` will return ResponseConfig[data].
112
+ *
113
+ * `Full` will return ResponseConfig.
114
+ * @default `'data'`
115
+ * @private
116
+ */
117
+
118
+ /**
119
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
120
+ */
121
+ exclude?: Array<Exclude>
122
+ /**
123
+ * Array containing include parameters to include tags/operations/methods/paths.
124
+ */
125
+ include?: Array<Include>
126
+ /**
127
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
128
+ */
129
+ override?: Array<Override<ResolvedOptions>>
130
+ /**
131
+ * How to pass your pathParams.
132
+ *
133
+ * `object` will return the pathParams as an object.
134
+ *
135
+ * `inline` will return the pathParams as comma separated params.
136
+ * @default `'inline'`
137
+ * @private
138
+ */
139
+ pathParamsType?: 'object' | 'inline'
140
+ /**
141
+ * When set, an infiniteQuery hooks will be added.
142
+ */
143
+ infinite?: Partial<Infinite> | false
144
+ /**
145
+ * Override some useQuery behaviours.
146
+ */
147
+ query?: Partial<Query> | false
148
+ /**
149
+ * Override some useMutation behaviours.
150
+ */
151
+ mutation?: Mutation | false
152
+ /**
153
+ * Which parser can be used before returning the data to `@tanstack/query`.
154
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
155
+ */
156
+ parser?: 'client' | 'zod'
157
+ transformers?: {
158
+ /**
159
+ * Customize the names based on the type that is provided by the plugin.
160
+ */
161
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
162
+ }
163
+ }
164
+
165
+ type ResolvedOptions = {
166
+ output: Output
167
+ baseURL: string | undefined
168
+ client: Required<NonNullable<PluginVueQuery['options']['client']>>
169
+ parser: Required<NonNullable<Options['parser']>>
170
+ pathParamsType: NonNullable<Options['pathParamsType']>
171
+ /**
172
+ * Only used of infinite
173
+ */
174
+ infinite: NonNullable<Infinite> | false
175
+ query: NonNullable<Required<Query>> | false
176
+ mutation: NonNullable<Required<Mutation>> | false
177
+ }
178
+
179
+ export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>