@kubb/plugin-vue-query 5.0.0-beta.10 → 5.0.0-beta.101
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.
- package/README.md +22 -26
- package/dist/index.cjs +1649 -147
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +358 -6
- package/dist/index.js +1620 -145
- package/dist/index.js.map +1 -1
- package/package.json +9 -32
- package/dist/components-B6jAb2as.js +0 -1150
- package/dist/components-B6jAb2as.js.map +0 -1
- package/dist/components-X0P-3W2G.cjs +0 -1264
- package/dist/components-X0P-3W2G.cjs.map +0 -1
- package/dist/components.cjs +0 -9
- package/dist/components.d.ts +0 -187
- package/dist/components.js +0 -2
- package/dist/generators-B33PbKzu.js +0 -681
- package/dist/generators-B33PbKzu.js.map +0 -1
- package/dist/generators-BE3KD0IR.cjs +0 -698
- package/dist/generators-BE3KD0IR.cjs.map +0 -1
- package/dist/generators.cjs +0 -5
- package/dist/generators.d.ts +0 -15
- package/dist/generators.js +0 -2
- package/dist/types-Bkm7bWT3.d.ts +0 -243
- package/extension.yaml +0 -732
- package/src/components/InfiniteQuery.tsx +0 -120
- package/src/components/InfiniteQueryOptions.tsx +0 -201
- package/src/components/Mutation.tsx +0 -148
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/Query.tsx +0 -119
- package/src/components/QueryKey.tsx +0 -51
- package/src/components/QueryOptions.tsx +0 -134
- package/src/components/index.ts +0 -7
- package/src/generators/index.ts +0 -3
- package/src/generators/infiniteQueryGenerator.tsx +0 -194
- package/src/generators/mutationGenerator.tsx +0 -153
- package/src/generators/queryGenerator.tsx +0 -179
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -167
- package/src/resolvers/resolverVueQuery.ts +0 -65
- package/src/types.ts +0 -245
- package/src/utils.ts +0 -49
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/plugin.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { camelCase } from '@internals/utils'
|
|
3
|
-
import { ast, definePlugin, type Group } 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 { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
|
-
import { mutationKeyTransformer } from '@internals/tanstack-query'
|
|
11
|
-
import { queryKeyTransformer } from '@internals/tanstack-query'
|
|
12
|
-
import { infiniteQueryGenerator, mutationGenerator, queryGenerator } from './generators'
|
|
13
|
-
import { resolverVueQuery } from './resolvers/resolverVueQuery.ts'
|
|
14
|
-
import type { PluginVueQuery } from './types.ts'
|
|
15
|
-
|
|
16
|
-
export const pluginVueQueryName = 'plugin-vue-query' satisfies PluginVueQuery['name']
|
|
17
|
-
|
|
18
|
-
export const pluginVueQuery = definePlugin<PluginVueQuery>((options) => {
|
|
19
|
-
const {
|
|
20
|
-
output = { path: 'hooks', barrelType: 'named' },
|
|
21
|
-
group,
|
|
22
|
-
exclude = [],
|
|
23
|
-
include,
|
|
24
|
-
override = [],
|
|
25
|
-
parser = 'client',
|
|
26
|
-
infinite = false,
|
|
27
|
-
paramsType = 'inline',
|
|
28
|
-
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
29
|
-
mutation = {},
|
|
30
|
-
query = {},
|
|
31
|
-
mutationKey = mutationKeyTransformer,
|
|
32
|
-
queryKey = queryKeyTransformer,
|
|
33
|
-
paramsCasing,
|
|
34
|
-
client,
|
|
35
|
-
resolver: userResolver,
|
|
36
|
-
transformer: userTransformer,
|
|
37
|
-
generators: userGenerators = [],
|
|
38
|
-
} = options
|
|
39
|
-
|
|
40
|
-
const clientName = client?.client ?? 'axios'
|
|
41
|
-
const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
|
|
42
|
-
|
|
43
|
-
const selectedGenerators =
|
|
44
|
-
options.generators ??
|
|
45
|
-
[queryGenerator, infiniteQueryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))
|
|
46
|
-
|
|
47
|
-
const groupConfig = group
|
|
48
|
-
? ({
|
|
49
|
-
...group,
|
|
50
|
-
name: group.name
|
|
51
|
-
? group.name
|
|
52
|
-
: (ctx: { group: string }) => {
|
|
53
|
-
if (group.type === 'path') {
|
|
54
|
-
return `${ctx.group.split('/')[1]}`
|
|
55
|
-
}
|
|
56
|
-
return `${camelCase(ctx.group)}Controller`
|
|
57
|
-
},
|
|
58
|
-
} satisfies Group)
|
|
59
|
-
: undefined
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
name: pluginVueQueryName,
|
|
63
|
-
options,
|
|
64
|
-
dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),
|
|
65
|
-
hooks: {
|
|
66
|
-
'kubb:plugin:setup'(ctx) {
|
|
67
|
-
const resolver = userResolver ? { ...resolverVueQuery, ...userResolver } : resolverVueQuery
|
|
68
|
-
|
|
69
|
-
ctx.setOptions({
|
|
70
|
-
output,
|
|
71
|
-
client: {
|
|
72
|
-
bundle: client?.bundle,
|
|
73
|
-
baseURL: client?.baseURL,
|
|
74
|
-
client: clientName,
|
|
75
|
-
clientType: client?.clientType ?? 'function',
|
|
76
|
-
importPath: clientImportPath,
|
|
77
|
-
dataReturnType: client?.dataReturnType ?? 'data',
|
|
78
|
-
paramsCasing,
|
|
79
|
-
},
|
|
80
|
-
queryKey,
|
|
81
|
-
query:
|
|
82
|
-
query === false
|
|
83
|
-
? false
|
|
84
|
-
: {
|
|
85
|
-
importPath: '@tanstack/vue-query',
|
|
86
|
-
methods: ['get'],
|
|
87
|
-
...query,
|
|
88
|
-
},
|
|
89
|
-
mutationKey,
|
|
90
|
-
mutation:
|
|
91
|
-
mutation === false
|
|
92
|
-
? false
|
|
93
|
-
: {
|
|
94
|
-
importPath: '@tanstack/vue-query',
|
|
95
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
96
|
-
...mutation,
|
|
97
|
-
},
|
|
98
|
-
infinite: infinite
|
|
99
|
-
? {
|
|
100
|
-
queryParam: 'id',
|
|
101
|
-
initialPageParam: 0,
|
|
102
|
-
cursorParam: undefined,
|
|
103
|
-
nextParam: undefined,
|
|
104
|
-
previousParam: undefined,
|
|
105
|
-
...infinite,
|
|
106
|
-
}
|
|
107
|
-
: false,
|
|
108
|
-
parser,
|
|
109
|
-
paramsType,
|
|
110
|
-
pathParamsType,
|
|
111
|
-
paramsCasing,
|
|
112
|
-
group: groupConfig,
|
|
113
|
-
exclude,
|
|
114
|
-
include,
|
|
115
|
-
override,
|
|
116
|
-
resolver,
|
|
117
|
-
})
|
|
118
|
-
ctx.setResolver(resolver)
|
|
119
|
-
if (userTransformer) {
|
|
120
|
-
ctx.setTransformer(userTransformer)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (const gen of selectedGenerators) {
|
|
124
|
-
ctx.addGenerator(gen)
|
|
125
|
-
}
|
|
126
|
-
for (const gen of userGenerators) {
|
|
127
|
-
ctx.addGenerator(gen)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
131
|
-
const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)
|
|
132
|
-
|
|
133
|
-
if (client?.bundle && !hasClientPlugin && !clientImportPath) {
|
|
134
|
-
ctx.injectFile({
|
|
135
|
-
baseName: 'fetch.ts',
|
|
136
|
-
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
137
|
-
sources: [
|
|
138
|
-
ast.createSource({
|
|
139
|
-
name: 'fetch',
|
|
140
|
-
nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],
|
|
141
|
-
isExportable: true,
|
|
142
|
-
isIndexable: true,
|
|
143
|
-
}),
|
|
144
|
-
],
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!hasClientPlugin) {
|
|
149
|
-
ctx.injectFile({
|
|
150
|
-
baseName: 'config.ts',
|
|
151
|
-
path: path.resolve(root, '.kubb/config.ts'),
|
|
152
|
-
sources: [
|
|
153
|
-
ast.createSource({
|
|
154
|
-
name: 'config',
|
|
155
|
-
nodes: [ast.createText(configSource)],
|
|
156
|
-
isExportable: false,
|
|
157
|
-
isIndexable: false,
|
|
158
|
-
}),
|
|
159
|
-
],
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
export default pluginVueQuery
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { camelCase } from '@internals/utils'
|
|
2
|
-
import { defineResolver } from '@kubb/core'
|
|
3
|
-
import type { PluginVueQuery } from '../types.ts'
|
|
4
|
-
|
|
5
|
-
function capitalize(name: string): string {
|
|
6
|
-
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Naming convention resolver for Vue Query plugin.
|
|
11
|
-
*
|
|
12
|
-
* Provides default naming helpers using camelCase for functions and file paths.
|
|
13
|
-
*/
|
|
14
|
-
export const resolverVueQuery = defineResolver<PluginVueQuery>(() => ({
|
|
15
|
-
name: 'default',
|
|
16
|
-
pluginName: 'plugin-vue-query',
|
|
17
|
-
default(name, type) {
|
|
18
|
-
return camelCase(name, { isFile: type === 'file' })
|
|
19
|
-
},
|
|
20
|
-
resolveName(name) {
|
|
21
|
-
return this.default(name, 'function')
|
|
22
|
-
},
|
|
23
|
-
resolvePathName(name, type) {
|
|
24
|
-
return this.default(name, type)
|
|
25
|
-
},
|
|
26
|
-
resolveQueryName(node) {
|
|
27
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
28
|
-
},
|
|
29
|
-
resolveInfiniteQueryName(node) {
|
|
30
|
-
return `use${capitalize(this.resolveName(node.operationId))}Infinite`
|
|
31
|
-
},
|
|
32
|
-
resolveMutationName(node) {
|
|
33
|
-
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
34
|
-
},
|
|
35
|
-
resolveQueryOptionsName(node) {
|
|
36
|
-
return `${this.resolveName(node.operationId)}QueryOptions`
|
|
37
|
-
},
|
|
38
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
39
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`
|
|
40
|
-
},
|
|
41
|
-
resolveQueryKeyName(node) {
|
|
42
|
-
return `${this.resolveName(node.operationId)}QueryKey`
|
|
43
|
-
},
|
|
44
|
-
resolveInfiniteQueryKeyName(node) {
|
|
45
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`
|
|
46
|
-
},
|
|
47
|
-
resolveMutationKeyName(node) {
|
|
48
|
-
return `${this.resolveName(node.operationId)}MutationKey`
|
|
49
|
-
},
|
|
50
|
-
resolveQueryKeyTypeName(node) {
|
|
51
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`
|
|
52
|
-
},
|
|
53
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
54
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`
|
|
55
|
-
},
|
|
56
|
-
resolveMutationTypeName(node) {
|
|
57
|
-
return capitalize(this.resolveName(node.operationId))
|
|
58
|
-
},
|
|
59
|
-
resolveClientName(node) {
|
|
60
|
-
return this.resolveName(node.operationId)
|
|
61
|
-
},
|
|
62
|
-
resolveInfiniteClientName(node) {
|
|
63
|
-
return `${this.resolveName(node.operationId)}Infinite`
|
|
64
|
-
},
|
|
65
|
-
}))
|
package/src/types.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
|
-
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
3
|
-
|
|
4
|
-
export type Transformer = (props: { node: ast.OperationNode; casing: 'camelcase' | undefined }) => unknown[]
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resolver for Vue Query that provides naming methods for hook functions.
|
|
8
|
-
*/
|
|
9
|
-
export type ResolverVueQuery = Resolver & {
|
|
10
|
-
/**
|
|
11
|
-
* Resolves the base function name for an operation.
|
|
12
|
-
*/
|
|
13
|
-
resolveName(this: ResolverVueQuery, name: string): string
|
|
14
|
-
/**
|
|
15
|
-
* Resolves the output file name for a hook module.
|
|
16
|
-
*/
|
|
17
|
-
resolvePathName(this: ResolverVueQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a query hook function name.
|
|
20
|
-
*/
|
|
21
|
-
resolveQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
22
|
-
/**
|
|
23
|
-
* Resolves an infinite query hook function name.
|
|
24
|
-
*/
|
|
25
|
-
resolveInfiniteQueryName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
26
|
-
/**
|
|
27
|
-
* Resolves a mutation hook function name.
|
|
28
|
-
*/
|
|
29
|
-
resolveMutationName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the query options helper name.
|
|
32
|
-
*/
|
|
33
|
-
resolveQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
34
|
-
/**
|
|
35
|
-
* Resolves the infinite query options helper name.
|
|
36
|
-
*/
|
|
37
|
-
resolveInfiniteQueryOptionsName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
38
|
-
/**
|
|
39
|
-
* Resolves the query key helper name.
|
|
40
|
-
*/
|
|
41
|
-
resolveQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
42
|
-
/**
|
|
43
|
-
* Resolves the infinite query key helper name.
|
|
44
|
-
*/
|
|
45
|
-
resolveInfiniteQueryKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
46
|
-
/**
|
|
47
|
-
* Resolves the mutation key helper name.
|
|
48
|
-
*/
|
|
49
|
-
resolveMutationKeyName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
50
|
-
/**
|
|
51
|
-
* Resolves the query key type name.
|
|
52
|
-
*/
|
|
53
|
-
resolveQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
54
|
-
/**
|
|
55
|
-
* Resolves the infinite query key type name.
|
|
56
|
-
*/
|
|
57
|
-
resolveInfiniteQueryKeyTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
58
|
-
/**
|
|
59
|
-
* Resolves the mutation type name.
|
|
60
|
-
*/
|
|
61
|
-
resolveMutationTypeName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
62
|
-
/**
|
|
63
|
-
* Resolves the client function name generated inline by query hooks.
|
|
64
|
-
*/
|
|
65
|
-
resolveClientName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
66
|
-
/**
|
|
67
|
-
* Resolves the client function name generated inline by infinite query hooks.
|
|
68
|
-
*/
|
|
69
|
-
resolveInfiniteClientName(this: ResolverVueQuery, node: ast.OperationNode): string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Customize the queryKey.
|
|
74
|
-
*/
|
|
75
|
-
type QueryKey = Transformer
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Customize the mutationKey.
|
|
79
|
-
*/
|
|
80
|
-
type MutationKey = Transformer
|
|
81
|
-
|
|
82
|
-
type Query = {
|
|
83
|
-
/**
|
|
84
|
-
* HTTP methods to use for queries.
|
|
85
|
-
*
|
|
86
|
-
* @default ['get']
|
|
87
|
-
*/
|
|
88
|
-
methods?: Array<string>
|
|
89
|
-
/**
|
|
90
|
-
* Path to the useQuery hook for useQuery functionality.
|
|
91
|
-
* Used as `import { useQuery } from '${importPath}'`.
|
|
92
|
-
* Accepts relative and absolute paths.
|
|
93
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
94
|
-
* @default '@tanstack/vue-query'
|
|
95
|
-
*/
|
|
96
|
-
importPath?: string
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
type Mutation = {
|
|
100
|
-
/**
|
|
101
|
-
* HTTP methods to use for mutations.
|
|
102
|
-
*
|
|
103
|
-
* @default ['post', 'put', 'delete']
|
|
104
|
-
*/
|
|
105
|
-
methods?: Array<string>
|
|
106
|
-
/**
|
|
107
|
-
* Path to the useMutation hook for useMutation functionality.
|
|
108
|
-
* Used as `import { useMutation } from '${importPath}'`.
|
|
109
|
-
* Accepts relative and absolute paths.
|
|
110
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
111
|
-
* @default '@tanstack/vue-query'
|
|
112
|
-
*/
|
|
113
|
-
importPath?: string
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export type Infinite = {
|
|
117
|
-
/**
|
|
118
|
-
* Specify the params key used for `pageParam`.
|
|
119
|
-
* @default 'id'
|
|
120
|
-
*/
|
|
121
|
-
queryParam: string
|
|
122
|
-
/**
|
|
123
|
-
* Which field of the data is used, set it to undefined when no cursor is known.
|
|
124
|
-
* @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
|
|
125
|
-
*/
|
|
126
|
-
cursorParam?: string | undefined
|
|
127
|
-
/**
|
|
128
|
-
* Which field of the data is used to get the cursor for the next page.
|
|
129
|
-
* Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
|
|
130
|
-
*/
|
|
131
|
-
nextParam?: string | string[] | undefined
|
|
132
|
-
/**
|
|
133
|
-
* Which field of the data is used to get the cursor for the previous page.
|
|
134
|
-
* Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
|
|
135
|
-
*/
|
|
136
|
-
previousParam?: string | string[] | undefined
|
|
137
|
-
/**
|
|
138
|
-
* The initial value, the value of the first page.
|
|
139
|
-
* @default 0
|
|
140
|
-
*/
|
|
141
|
-
initialPageParam: unknown
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export type Options = {
|
|
145
|
-
/**
|
|
146
|
-
* Specify the export location for the files and define the behavior of the output
|
|
147
|
-
* @default { path: 'hooks', barrelType: 'named' }
|
|
148
|
-
*/
|
|
149
|
-
output?: Output
|
|
150
|
-
/**
|
|
151
|
-
* Group the @tanstack/query hooks based on the provided name.
|
|
152
|
-
*/
|
|
153
|
-
group?: Group
|
|
154
|
-
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
155
|
-
/**
|
|
156
|
-
* Tags, operations, or paths to exclude from generation.
|
|
157
|
-
*/
|
|
158
|
-
exclude?: Array<Exclude>
|
|
159
|
-
/**
|
|
160
|
-
* Tags, operations, or paths to include in generation.
|
|
161
|
-
*/
|
|
162
|
-
include?: Array<Include>
|
|
163
|
-
/**
|
|
164
|
-
* Override options for specific tags, operations, or paths.
|
|
165
|
-
*/
|
|
166
|
-
override?: Array<Override<ResolvedOptions>>
|
|
167
|
-
/**
|
|
168
|
-
* Apply casing to parameter names.
|
|
169
|
-
*/
|
|
170
|
-
paramsCasing?: 'camelcase'
|
|
171
|
-
/**
|
|
172
|
-
* How parameters are passed: grouped in an object or spread inline.
|
|
173
|
-
*
|
|
174
|
-
* @default 'inline'
|
|
175
|
-
*/
|
|
176
|
-
paramsType?: 'object' | 'inline'
|
|
177
|
-
/**
|
|
178
|
-
* How path parameters are passed: grouped in an object or spread inline.
|
|
179
|
-
*
|
|
180
|
-
* @default 'inline'
|
|
181
|
-
*/
|
|
182
|
-
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
183
|
-
/**
|
|
184
|
-
* Add infinite query hooks.
|
|
185
|
-
*/
|
|
186
|
-
infinite?: Partial<Infinite> | false
|
|
187
|
-
queryKey?: QueryKey
|
|
188
|
-
/**
|
|
189
|
-
* Configure useQuery behavior.
|
|
190
|
-
*/
|
|
191
|
-
query?: Partial<Query> | false
|
|
192
|
-
mutationKey?: MutationKey
|
|
193
|
-
/**
|
|
194
|
-
* Configure useMutation behavior.
|
|
195
|
-
*/
|
|
196
|
-
mutation?: Partial<Mutation> | false
|
|
197
|
-
/**
|
|
198
|
-
* Parser to use for validating response data.
|
|
199
|
-
*/
|
|
200
|
-
parser?: PluginClient['options']['parser']
|
|
201
|
-
/**
|
|
202
|
-
* Override naming conventions for function names and types.
|
|
203
|
-
*/
|
|
204
|
-
resolver?: Partial<ResolverVueQuery> & ThisType<ResolverVueQuery>
|
|
205
|
-
/**
|
|
206
|
-
* AST visitor to transform generated nodes.
|
|
207
|
-
*/
|
|
208
|
-
transformer?: ast.Visitor
|
|
209
|
-
/**
|
|
210
|
-
* Additional generators alongside the default generators.
|
|
211
|
-
*/
|
|
212
|
-
generators?: Array<Generator<PluginVueQuery>>
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
type ResolvedOptions = {
|
|
216
|
-
output: Output
|
|
217
|
-
group: Group | undefined
|
|
218
|
-
exclude: NonNullable<Options['exclude']>
|
|
219
|
-
include: Options['include']
|
|
220
|
-
override: NonNullable<Options['override']>
|
|
221
|
-
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
222
|
-
parser: Required<NonNullable<Options['parser']>>
|
|
223
|
-
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
224
|
-
paramsCasing: Options['paramsCasing']
|
|
225
|
-
paramsType: NonNullable<Options['paramsType']>
|
|
226
|
-
/**
|
|
227
|
-
* Only used for infinite
|
|
228
|
-
*/
|
|
229
|
-
infinite: NonNullable<Infinite> | false
|
|
230
|
-
queryKey: QueryKey | undefined
|
|
231
|
-
query: NonNullable<Required<Query>> | false
|
|
232
|
-
mutationKey: MutationKey | undefined
|
|
233
|
-
mutation: NonNullable<Required<Mutation>> | false
|
|
234
|
-
resolver: ResolverVueQuery
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, ResolverVueQuery>
|
|
238
|
-
|
|
239
|
-
declare global {
|
|
240
|
-
namespace Kubb {
|
|
241
|
-
interface PluginRegistry {
|
|
242
|
-
'plugin-vue-query': PluginVueQuery
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
buildGroupParam,
|
|
3
|
-
buildQueryKeyParams,
|
|
4
|
-
resolveHeaderGroupType,
|
|
5
|
-
resolveOperationOverrides,
|
|
6
|
-
resolvePathParamType,
|
|
7
|
-
resolveQueryGroupType,
|
|
8
|
-
resolveZodSchemaNames,
|
|
9
|
-
} from '@internals/tanstack-query'
|
|
10
|
-
export { buildOperationComments as getComments, buildRequestConfigType, getContentTypeInfo, resolveErrorNames, resolveStatusCodeNames } from '@internals/shared'
|
|
11
|
-
|
|
12
|
-
import { ast } from '@kubb/core'
|
|
13
|
-
|
|
14
|
-
export function printType(typeNode: ast.ParamsTypeNode | undefined): string {
|
|
15
|
-
if (!typeNode) return 'unknown'
|
|
16
|
-
if (typeNode.variant === 'reference') return typeNode.name
|
|
17
|
-
if (typeNode.variant === 'member') return `${typeNode.base}['${typeNode.key}']`
|
|
18
|
-
if (typeNode.variant === 'struct') {
|
|
19
|
-
const parts = typeNode.properties.map((p) => {
|
|
20
|
-
const typeStr = printType(p.type)
|
|
21
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name)
|
|
22
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`
|
|
23
|
-
})
|
|
24
|
-
return `{ ${parts.join('; ')} }`
|
|
25
|
-
}
|
|
26
|
-
return 'unknown'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function wrapWithMaybeRefOrGetter(paramsNode: ast.FunctionParametersNode, skip?: (name: string) => boolean): ast.FunctionParametersNode {
|
|
30
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
31
|
-
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
32
|
-
const group = param as ast.ParameterGroupNode
|
|
33
|
-
return {
|
|
34
|
-
...group,
|
|
35
|
-
properties: group.properties.map((p) => ({
|
|
36
|
-
...p,
|
|
37
|
-
type: p.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(p.type)}>` }) : p.type,
|
|
38
|
-
})),
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const fp = param as ast.FunctionParameterNode
|
|
42
|
-
if (skip?.(fp.name)) return fp
|
|
43
|
-
return {
|
|
44
|
-
...fp,
|
|
45
|
-
type: fp.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(fp.type)}>` }) : fp.type,
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
return ast.createFunctionParameters({ params: wrappedParams })
|
|
49
|
-
}
|
|
File without changes
|