@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.100

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 (39) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -23
  3. package/dist/index.cjs +1651 -140
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +358 -6
  6. package/dist/index.js +1618 -138
  7. package/dist/index.js.map +1 -1
  8. package/package.json +48 -76
  9. package/dist/components-Yjoe78Y7.cjs +0 -1119
  10. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  11. package/dist/components-_AMBl0g-.js +0 -1029
  12. package/dist/components-_AMBl0g-.js.map +0 -1
  13. package/dist/components.cjs +0 -9
  14. package/dist/components.d.ts +0 -242
  15. package/dist/components.js +0 -2
  16. package/dist/generators-CR34GjVu.js +0 -661
  17. package/dist/generators-CR34GjVu.js.map +0 -1
  18. package/dist/generators-DH8VkK1q.cjs +0 -678
  19. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  20. package/dist/generators.cjs +0 -5
  21. package/dist/generators.d.ts +0 -511
  22. package/dist/generators.js +0 -2
  23. package/dist/types-CgDFUvfZ.d.ts +0 -211
  24. package/src/components/InfiniteQuery.tsx +0 -208
  25. package/src/components/InfiniteQueryOptions.tsx +0 -249
  26. package/src/components/Mutation.tsx +0 -185
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/Query.tsx +0 -208
  29. package/src/components/QueryKey.tsx +0 -94
  30. package/src/components/QueryOptions.tsx +0 -185
  31. package/src/components/index.ts +0 -7
  32. package/src/generators/index.ts +0 -3
  33. package/src/generators/infiniteQueryGenerator.tsx +0 -213
  34. package/src/generators/mutationGenerator.tsx +0 -176
  35. package/src/generators/queryGenerator.tsx +0 -191
  36. package/src/index.ts +0 -2
  37. package/src/plugin.ts +0 -218
  38. package/src/types.ts +0 -176
  39. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/plugin.ts DELETED
@@ -1,218 +0,0 @@
1
- import path from 'node:path'
2
- import { camelCase, pascalCase } from '@internals/utils'
3
- import { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
4
- import { pluginClientName } from '@kubb/plugin-client'
5
- import { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'
6
- import { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'
7
- import { source as configSource } from '@kubb/plugin-client/templates/config.source'
8
- import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
9
- import { pluginTsName } from '@kubb/plugin-ts'
10
- import { pluginZodName } from '@kubb/plugin-zod'
11
- import { MutationKey, QueryKey } from './components'
12
- import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
13
- import type { PluginVueQuery } from './types.ts'
14
-
15
- export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
16
-
17
- export const pluginVueQuery = createPlugin<PluginVueQuery>((options) => {
18
- const {
19
- output = { path: 'hooks', barrelType: 'named' },
20
- group,
21
- exclude = [],
22
- include,
23
- override = [],
24
- parser = 'client',
25
- infinite,
26
- transformers = {},
27
- paramsType = 'inline',
28
- pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
29
- mutation = {},
30
- query = {},
31
- paramsCasing,
32
- mutationKey = MutationKey.getTransformer,
33
- queryKey = QueryKey.getTransformer,
34
- generators = [queryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
35
- contentType,
36
- client,
37
- } = options
38
-
39
- const clientName = client?.client ?? 'axios'
40
- const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
41
-
42
- return {
43
- name: pluginVueQueryName,
44
- options: {
45
- output,
46
- client: {
47
- bundle: client?.bundle,
48
- baseURL: client?.baseURL,
49
- client: clientName,
50
- clientType: client?.clientType ?? 'function',
51
- dataReturnType: client?.dataReturnType ?? 'data',
52
- pathParamsType,
53
- importPath: clientImportPath,
54
- paramsCasing,
55
- },
56
- infinite: infinite
57
- ? {
58
- queryParam: 'id',
59
- initialPageParam: 0,
60
- cursorParam: undefined,
61
- nextParam: undefined,
62
- previousParam: undefined,
63
- ...infinite,
64
- }
65
- : false,
66
- queryKey,
67
- query:
68
- query === false
69
- ? false
70
- : {
71
- methods: ['get'],
72
- importPath: '@tanstack/vue-query',
73
- ...query,
74
- },
75
- mutationKey,
76
- mutation:
77
- mutation === false
78
- ? false
79
- : {
80
- methods: ['post', 'put', 'patch', 'delete'],
81
- importPath: '@tanstack/vue-query',
82
- ...mutation,
83
- },
84
- paramsType,
85
- pathParamsType,
86
- parser,
87
- paramsCasing,
88
- group,
89
- },
90
- pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
91
- resolvePath(baseName, pathMode, options) {
92
- const root = path.resolve(this.config.root, this.config.output.path)
93
- const mode = pathMode ?? getMode(path.resolve(root, output.path))
94
-
95
- if (mode === 'single') {
96
- /**
97
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
98
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
99
- */
100
- return path.resolve(root, output.path)
101
- }
102
-
103
- if (group && (options?.group?.path || options?.group?.tag)) {
104
- const groupName: Group['name'] = group?.name
105
- ? group.name
106
- : (ctx) => {
107
- if (group?.type === 'path') {
108
- return `${ctx.group.split('/')[1]}`
109
- }
110
- return `${camelCase(ctx.group)}Controller`
111
- }
112
-
113
- return path.resolve(
114
- root,
115
- output.path,
116
- groupName({
117
- group: group.type === 'path' ? options.group.path! : options.group.tag!,
118
- }),
119
- baseName,
120
- )
121
- }
122
-
123
- return path.resolve(root, output.path, baseName)
124
- },
125
- resolveName(name, type) {
126
- let resolvedName = camelCase(name)
127
-
128
- if (type === 'file' || type === 'function') {
129
- resolvedName = camelCase(name, {
130
- isFile: type === 'file',
131
- })
132
- }
133
- if (type === 'type') {
134
- resolvedName = pascalCase(name)
135
- }
136
-
137
- if (type) {
138
- return transformers?.name?.(resolvedName, type) || resolvedName
139
- }
140
-
141
- return resolvedName
142
- },
143
- async install() {
144
- const root = path.resolve(this.config.root, this.config.output.path)
145
- const mode = getMode(path.resolve(root, output.path))
146
- const oas = await this.getOas()
147
- const baseURL = await this.getBaseURL()
148
-
149
- if (baseURL) {
150
- this.plugin.options.client.baseURL = baseURL
151
- }
152
-
153
- const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)
154
-
155
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {
156
- // pre add bundled
157
- await this.upsertFile({
158
- baseName: 'fetch.ts',
159
- path: path.resolve(root, '.kubb/fetch.ts'),
160
- sources: [
161
- {
162
- name: 'fetch',
163
- value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,
164
- isExportable: true,
165
- isIndexable: true,
166
- },
167
- ],
168
- imports: [],
169
- exports: [],
170
- })
171
- }
172
-
173
- if (!hasClientPlugin) {
174
- await this.addFile({
175
- baseName: 'config.ts',
176
- path: path.resolve(root, '.kubb/config.ts'),
177
- sources: [
178
- {
179
- name: 'config',
180
- value: configSource,
181
- isExportable: false,
182
- isIndexable: false,
183
- },
184
- ],
185
- imports: [],
186
- exports: [],
187
- })
188
- }
189
-
190
- const operationGenerator = new OperationGenerator(this.plugin.options, {
191
- fabric: this.fabric,
192
- oas,
193
- driver: this.driver,
194
- events: this.events,
195
- plugin: this.plugin,
196
- contentType,
197
- exclude,
198
- include,
199
- override,
200
- mode,
201
- })
202
-
203
- const files = await operationGenerator.build(...generators)
204
- await this.upsertFile(...files)
205
-
206
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
207
- type: output.barrelType ?? 'named',
208
- root,
209
- output,
210
- meta: {
211
- pluginName: this.plugin.name,
212
- },
213
- })
214
-
215
- await this.upsertFile(...barrelFiles)
216
- },
217
- }
218
- })
package/src/types.ts DELETED
@@ -1,176 +0,0 @@
1
- import type { Transformer } from '@internals/tanstack-query'
2
- import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
- import type { contentType, HttpMethod, Oas } from '@kubb/oas'
4
- import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
5
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
6
- import type { Generator } from '@kubb/plugin-oas/generators'
7
-
8
- export type { Transformer } from '@internals/tanstack-query'
9
-
10
- /**
11
- * Customize the queryKey
12
- */
13
- type QueryKey = Transformer
14
-
15
- /**
16
- * Customize the mutationKey
17
- */
18
- type MutationKey = Transformer
19
-
20
- type Query = {
21
- /**
22
- * Define which HttpMethods can be used for queries
23
- * @default ['get']
24
- */
25
- methods: Array<HttpMethod>
26
- /**
27
- * Path to the useQuery hook for useQuery functionality.
28
- * Used as `import { useQuery } from '${importPath}'`.
29
- * Accepts relative and absolute paths.
30
- * Path is used as-is; relative paths are based on the generated file location.
31
- * @default '@tanstack/react-query'
32
- */
33
- importPath?: string
34
- }
35
-
36
- type Mutation = {
37
- /**
38
- * Define which HttpMethods can be used for mutations
39
- * @default ['post', 'put', 'delete']
40
- */
41
- methods: Array<HttpMethod>
42
- /**
43
- * Path to the useQuery hook for useQuery functionality.
44
- * Used as `import { useQuery } from '${importPath}'`.
45
- * Accepts relative and absolute paths.
46
- * Path is used as-is; relative paths are based on the generated file location.
47
- * @default '@tanstack/react-query'
48
- */
49
- importPath?: string
50
- }
51
-
52
- export type Infinite = {
53
- /**
54
- * Specify the params key used for `pageParam`.
55
- * @default `'id'`
56
- */
57
- queryParam: string
58
- /**
59
- * Which field of the data is used, set it to undefined when no cursor is known.
60
- * @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
61
- */
62
- cursorParam?: string | undefined
63
- /**
64
- * Which field of the data is used to get the cursor for the next page.
65
- * Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
66
- */
67
- nextParam?: string | string[] | undefined
68
- /**
69
- * Which field of the data is used to get the cursor for the previous page.
70
- * Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
71
- */
72
- previousParam?: string | string[] | undefined
73
- /**
74
- * The initial value, the value of the first page.
75
- * @default `0`
76
- */
77
- initialPageParam: unknown
78
- }
79
-
80
- export type Options = {
81
- /**
82
- * Specify the export location for the files and define the behavior of the output
83
- * @default { path: 'hooks', barrelType: 'named' }
84
- */
85
- output?: Output<Oas>
86
- /**
87
- * Define which contentType should be used.
88
- * By default, the first JSON valid mediaType is used
89
- */
90
- contentType?: contentType
91
- /**
92
- * Group the @tanstack/query hooks based on the provided name.
93
- */
94
- group?: Group
95
- client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
96
- /**
97
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
98
- */
99
- exclude?: Array<Exclude>
100
- /**
101
- * Array containing include parameters to include tags/operations/methods/paths.
102
- */
103
- include?: Array<Include>
104
- /**
105
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
106
- */
107
- override?: Array<Override<ResolvedOptions>>
108
- /**
109
- * How to style your params, by default no casing is applied
110
- * - 'camelcase' uses camelcase for the params names
111
- */
112
- paramsCasing?: 'camelcase'
113
- /**
114
- * How to pass your params
115
- * - 'object' returns the params and pathParams as an object.
116
- * - 'inline' returns the params as comma separated params.
117
- * @default 'inline'
118
- */
119
- paramsType?: 'object' | 'inline'
120
- /**
121
- * How to pass your pathParams.
122
- * - 'object' returns the pathParams as an object.
123
- * - 'inline': returns the pathParams as comma separated params.
124
- * @default 'inline'
125
- */
126
- pathParamsType?: PluginClient['options']['pathParamsType']
127
- /**
128
- * When set, an infiniteQuery hooks is added.
129
- */
130
- infinite?: Partial<Infinite> | false
131
- queryKey?: QueryKey
132
- /**
133
- * Override some useQuery behaviors.
134
- */
135
- query?: Partial<Query> | false
136
- mutationKey?: MutationKey
137
- /**
138
- * Override some useMutation behaviors.
139
- */
140
- mutation?: Partial<Mutation> | false
141
- /**
142
- * Which parser should be used before returning the data to `@tanstack/query`.
143
- * `'zod'` uses `@kubb/plugin-zod` to parse the data.
144
- */
145
- parser?: PluginClient['options']['parser']
146
- transformers?: {
147
- /**
148
- * Customize the names based on the type that is provided by the plugin.
149
- */
150
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
151
- }
152
- /**
153
- * Define some generators next to the vue-query generators
154
- */
155
- generators?: Array<Generator<PluginVueQuery>>
156
- }
157
-
158
- type ResolvedOptions = {
159
- output: Output<Oas>
160
- group: Options['group']
161
- client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
162
- parser: Required<NonNullable<Options['parser']>>
163
- paramsCasing: Options['paramsCasing']
164
- paramsType: NonNullable<Options['paramsType']>
165
- pathParamsType: NonNullable<Options['pathParamsType']>
166
- /**
167
- * Only used of infinite
168
- */
169
- infinite: NonNullable<Infinite> | false
170
- queryKey: QueryKey | undefined
171
- query: NonNullable<Required<Query>> | false
172
- mutationKey: MutationKey | undefined
173
- mutation: NonNullable<Required<Mutation>> | false
174
- }
175
-
176
- export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>