@kubb/plugin-client 5.0.0-alpha.29 → 5.0.0-alpha.30
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/dist/index.cjs +91 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.js +93 -123
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/generators/classClientGenerator.tsx +14 -27
- package/src/generators/clientGenerator.tsx +24 -37
- package/src/generators/groupedClientGenerator.tsx +29 -30
- package/src/generators/operationsGenerator.tsx +2 -4
- package/src/generators/staticClassClientGenerator.tsx +77 -76
- package/src/plugin.ts +22 -44
- package/src/types.ts +11 -0
package/src/plugin.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { camelCase } from '@internals/utils'
|
|
3
|
-
import {
|
|
4
|
-
import type { OperationNode } from '@kubb/ast/types'
|
|
5
|
-
import { createPlugin, type Group, getBarrelFiles, getPreset, runGeneratorOperation, runGeneratorOperations } from '@kubb/core'
|
|
3
|
+
import { createPlugin, type Group, getPreset, mergeGenerators } from '@kubb/core'
|
|
6
4
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
5
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
6
|
+
import { version } from '../package.json'
|
|
8
7
|
import { classClientGenerator } from './generators/classClientGenerator.tsx'
|
|
9
8
|
import { clientGenerator } from './generators/clientGenerator.tsx'
|
|
10
9
|
import { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'
|
|
@@ -42,10 +41,10 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
42
41
|
const {
|
|
43
42
|
output = { path: 'clients', barrelType: 'named' },
|
|
44
43
|
group,
|
|
45
|
-
urlType = false,
|
|
46
44
|
exclude = [],
|
|
47
45
|
include,
|
|
48
46
|
override = [],
|
|
47
|
+
urlType = false,
|
|
49
48
|
dataReturnType = 'data',
|
|
50
49
|
paramsType = 'inline',
|
|
51
50
|
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
@@ -81,11 +80,15 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
81
80
|
generators: selectedGenerators,
|
|
82
81
|
})
|
|
83
82
|
|
|
83
|
+
const generators = preset.generators ?? []
|
|
84
|
+
const mergedGenerator = mergeGenerators(generators)
|
|
85
|
+
|
|
84
86
|
let resolveNameWarning = false
|
|
85
87
|
let resolvePathWarning = false
|
|
86
88
|
|
|
87
89
|
return {
|
|
88
90
|
name: pluginClientName,
|
|
91
|
+
version,
|
|
89
92
|
get resolver() {
|
|
90
93
|
return preset.resolver
|
|
91
94
|
},
|
|
@@ -98,6 +101,9 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
98
101
|
clientType,
|
|
99
102
|
bundle,
|
|
100
103
|
output,
|
|
104
|
+
exclude,
|
|
105
|
+
include,
|
|
106
|
+
override,
|
|
101
107
|
group: group
|
|
102
108
|
? ({
|
|
103
109
|
...group,
|
|
@@ -126,31 +132,32 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
126
132
|
pre: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
127
133
|
resolvePath(baseName, pathMode, options) {
|
|
128
134
|
if (!resolvePathWarning) {
|
|
129
|
-
this.
|
|
135
|
+
this.warn('Do not use resolvePath for pluginClient, use resolverClient.resolvePath instead')
|
|
130
136
|
resolvePathWarning = true
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
return this.plugin.resolver.resolvePath(
|
|
134
140
|
{ baseName, pathMode, tag: options?.group?.tag, path: options?.group?.path },
|
|
135
|
-
{ root:
|
|
141
|
+
{ root: this.root, output, group: this.plugin.options.group },
|
|
136
142
|
)
|
|
137
143
|
},
|
|
138
144
|
resolveName(name, type) {
|
|
139
145
|
if (!resolveNameWarning) {
|
|
140
|
-
this.
|
|
146
|
+
this.warn('Do not use resolveName for pluginClient, use resolverClient.default instead')
|
|
141
147
|
resolveNameWarning = true
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
return this.plugin.resolver.default(name, type)
|
|
145
151
|
},
|
|
146
|
-
async
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
152
|
+
async operation(node, options) {
|
|
153
|
+
return mergedGenerator.operation?.call(this, node, options)
|
|
154
|
+
},
|
|
155
|
+
async operations(nodes, options) {
|
|
156
|
+
return mergedGenerator.operations?.call(this, nodes, options)
|
|
157
|
+
},
|
|
158
|
+
async buildStart() {
|
|
159
|
+
const { plugin } = this
|
|
160
|
+
const root = this.root
|
|
154
161
|
|
|
155
162
|
// pre add bundled fetch
|
|
156
163
|
if (bundle && !plugin.options.importPath) {
|
|
@@ -184,35 +191,6 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
|
|
|
184
191
|
imports: [],
|
|
185
192
|
exports: [],
|
|
186
193
|
})
|
|
187
|
-
|
|
188
|
-
const collectedOperations: Array<OperationNode> = []
|
|
189
|
-
const generatorContext = { generators: preset.generators, plugin, resolver, exclude, include, override, fabric, adapter, config, driver }
|
|
190
|
-
|
|
191
|
-
await walk(rootNode, {
|
|
192
|
-
depth: 'shallow',
|
|
193
|
-
async operation(operationNode) {
|
|
194
|
-
const baseOptions = resolver.resolveOptions(operationNode, { options: plugin.options, exclude, include, override })
|
|
195
|
-
|
|
196
|
-
if (baseOptions !== null) {
|
|
197
|
-
collectedOperations.push(operationNode)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
await runGeneratorOperation(operationNode, generatorContext)
|
|
201
|
-
},
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
await runGeneratorOperations(collectedOperations, generatorContext)
|
|
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
194
|
},
|
|
217
195
|
}
|
|
218
196
|
})
|
package/src/types.ts
CHANGED
|
@@ -205,6 +205,9 @@ export type Options = {
|
|
|
205
205
|
|
|
206
206
|
type ResolvedOptions = {
|
|
207
207
|
output: Output
|
|
208
|
+
exclude: Array<Exclude>
|
|
209
|
+
include: Array<Include> | undefined
|
|
210
|
+
override: Array<Override<ResolvedOptions>>
|
|
208
211
|
group: Group | undefined
|
|
209
212
|
client: Options['client']
|
|
210
213
|
clientType: NonNullable<Options['clientType']>
|
|
@@ -222,3 +225,11 @@ type ResolvedOptions = {
|
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
export type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions, ResolverClient>
|
|
228
|
+
|
|
229
|
+
declare global {
|
|
230
|
+
namespace Kubb {
|
|
231
|
+
interface PluginRegistry {
|
|
232
|
+
'plugin-client': PluginClient
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|