@kubb/plugin-client 5.0.0-alpha.31 → 5.0.0-alpha.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "5.0.0-alpha.31",
3
+ "version": "5.0.0-alpha.32",
4
4
  "description": "API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -94,19 +94,17 @@
94
94
  }
95
95
  ],
96
96
  "dependencies": {
97
- "@kubb/fabric-core": "0.15.1",
98
97
  "@kubb/react-fabric": "0.15.1",
99
- "@kubb/ast": "5.0.0-alpha.31",
100
- "@kubb/core": "5.0.0-alpha.31",
101
- "@kubb/plugin-ts": "5.0.0-alpha.31",
102
- "@kubb/plugin-zod": "5.0.0-alpha.31"
98
+ "@kubb/ast": "5.0.0-alpha.32",
99
+ "@kubb/core": "5.0.0-alpha.32",
100
+ "@kubb/plugin-ts": "5.0.0-alpha.32",
101
+ "@kubb/plugin-zod": "5.0.0-alpha.32"
103
102
  },
104
103
  "devDependencies": {
105
104
  "axios": "^1.14.0",
106
105
  "@internals/utils": "0.0.0"
107
106
  },
108
107
  "peerDependencies": {
109
- "@kubb/fabric-core": "0.15.1",
110
108
  "@kubb/react-fabric": "0.15.1",
111
109
  "axios": "^1.7.2"
112
110
  },
@@ -1,5 +1,5 @@
1
1
  import { isValidVarName, URLPath } from '@internals/utils'
2
- import { caseParams, createFunctionParameter, createOperationParams, createTypeNode } from '@kubb/ast'
2
+ import { caseParams, createFunctionParameter, createOperationParams, createParamsType } from '@kubb/ast'
3
3
  import type { FunctionParametersNode, OperationNode } from '@kubb/ast/types'
4
4
  import type { PluginTs } from '@kubb/plugin-ts'
5
5
  import { functionPrinter } from '@kubb/plugin-ts'
@@ -53,7 +53,7 @@ function getParams({ paramsType, paramsCasing, pathParamsType, node, tsResolver,
53
53
  ? [
54
54
  createFunctionParameter({
55
55
  name: 'config',
56
- type: createTypeNode({
56
+ type: createParamsType({
57
57
  variant: 'reference',
58
58
  name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }',
59
59
  }),
@@ -1,7 +1,6 @@
1
1
  import path from 'node:path'
2
2
  import { camelCase, pascalCase } from '@internals/utils'
3
- import type { OperationNode } from '@kubb/ast/types'
4
- import type { KubbFile } from '@kubb/core'
3
+ import type { FileNode, OperationNode } from '@kubb/ast/types'
5
4
  import { defineGenerator } from '@kubb/core'
6
5
  import type { PluginTs } from '@kubb/plugin-ts'
7
6
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -17,13 +16,13 @@ type OperationData = {
17
16
  name: string
18
17
  tsResolver: PluginTs['resolver']
19
18
  zodResolver: PluginZod['resolver'] | undefined
20
- typeFile: KubbFile.File
21
- zodFile: KubbFile.File | undefined
19
+ typeFile: FileNode
20
+ zodFile: FileNode | undefined
22
21
  }
23
22
 
24
23
  type Controller = {
25
24
  name: string
26
- file: KubbFile.File
25
+ file: FileNode
27
26
  operations: Array<OperationData>
28
27
  }
29
28
 
@@ -49,7 +48,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
49
48
  operations(nodes, options) {
50
49
  const { adapter, config, driver, resolver, root } = this
51
50
  const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options
52
- const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL
51
+ const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
53
52
 
54
53
  const pluginTs = driver.getPlugin(pluginTsName)
55
54
  if (!pluginTs?.resolver) return null
@@ -118,7 +117,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
118
117
 
119
118
  function collectTypeImports(ops: Array<OperationData>) {
120
119
  const typeImportsByFile = new Map<string, Set<string>>()
121
- const typeFilesByPath = new Map<string, KubbFile.File>()
120
+ const typeFilesByPath = new Map<string, FileNode>()
122
121
 
123
122
  ops.forEach((op) => {
124
123
  const names = resolveTypeImportNames(op.node, tsResolver)
@@ -137,7 +136,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
137
136
 
138
137
  function collectZodImports(ops: Array<OperationData>) {
139
138
  const zodImportsByFile = new Map<string, Set<string>>()
140
- const zodFilesByPath = new Map<string, KubbFile.File>()
139
+ const zodFilesByPath = new Map<string, FileNode>()
141
140
 
142
141
  ops.forEach((op) => {
143
142
  if (!op.zodFile || !zodResolver) return
@@ -158,7 +157,7 @@ export const classClientGenerator = defineGenerator<PluginClient>({
158
157
  const files = controllers.map(({ name, file, operations: ops }) => {
159
158
  const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
160
159
  const { zodImportsByFile, zodFilesByPath } =
161
- parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, KubbFile.File>() }
160
+ parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, FileNode>() }
162
161
  const hasFormData = ops.some((op) => op.node.requestBody?.contentType === 'multipart/form-data')
163
162
 
164
163
  return (
@@ -167,8 +166,8 @@ export const classClientGenerator = defineGenerator<PluginClient>({
167
166
  baseName={file.baseName}
168
167
  path={file.path}
169
168
  meta={file.meta}
170
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
171
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
169
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
170
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
172
171
  >
173
172
  {importPath ? (
174
173
  <>
@@ -226,8 +225,8 @@ export const classClientGenerator = defineGenerator<PluginClient>({
226
225
  baseName={wrapperFile.baseName}
227
226
  path={wrapperFile.path}
228
227
  meta={wrapperFile.meta}
229
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
230
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
228
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
229
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
231
230
  >
232
231
  {importPath ? (
233
232
  <File.Import name={['Client', 'RequestConfig']} path={importPath} isTypeOnly />
@@ -13,7 +13,7 @@ export const clientGenerator = defineGenerator<PluginClient>({
13
13
  operation(node, options) {
14
14
  const { adapter, config, driver, resolver, root } = this
15
15
  const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options
16
- const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL
16
+ const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
17
17
 
18
18
  const pluginTs = driver.getPlugin(pluginTsName)
19
19
 
@@ -77,8 +77,8 @@ export const clientGenerator = defineGenerator<PluginClient>({
77
77
  baseName={meta.file.baseName}
78
78
  path={meta.file.path}
79
79
  meta={meta.file.meta}
80
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
81
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
80
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
81
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
82
82
  >
83
83
  {importPath ? (
84
84
  <>
@@ -1,5 +1,5 @@
1
1
  import { camelCase } from '@internals/utils'
2
- import type { KubbFile } from '@kubb/core'
2
+ import type { FileNode } from '@kubb/ast/types'
3
3
  import { defineGenerator } from '@kubb/core'
4
4
  import { File, Function } from '@kubb/react-fabric'
5
5
  import type { PluginClient } from '../types'
@@ -42,7 +42,7 @@ export const groupedClientGenerator = defineGenerator<PluginClient>({
42
42
 
43
43
  return acc
44
44
  },
45
- [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,
45
+ [] as Array<{ name: string; file: FileNode; clients: Array<{ name: string; file: FileNode }> }>,
46
46
  )
47
47
 
48
48
  return (
@@ -54,8 +54,8 @@ export const groupedClientGenerator = defineGenerator<PluginClient>({
54
54
  baseName={file.baseName}
55
55
  path={file.path}
56
56
  meta={file.meta}
57
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
58
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
57
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
58
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
59
59
  >
60
60
  {clients.map((client) => (
61
61
  <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
@@ -17,8 +17,8 @@ export const operationsGenerator = defineGenerator<PluginClient>({
17
17
  baseName={file.baseName}
18
18
  path={file.path}
19
19
  meta={file.meta}
20
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
21
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
20
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
21
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
22
22
  >
23
23
  <Operations name={name} nodes={nodes} />
24
24
  </File>
@@ -1,7 +1,6 @@
1
1
  import path from 'node:path'
2
2
  import { camelCase, pascalCase } from '@internals/utils'
3
- import type { OperationNode } from '@kubb/ast/types'
4
- import type { KubbFile } from '@kubb/core'
3
+ import type { FileNode, OperationNode } from '@kubb/ast/types'
5
4
  import { defineGenerator } from '@kubb/core'
6
5
  import type { PluginTs } from '@kubb/plugin-ts'
7
6
  import { pluginTsName } from '@kubb/plugin-ts'
@@ -16,13 +15,13 @@ type OperationData = {
16
15
  name: string
17
16
  tsResolver: PluginTs['resolver']
18
17
  zodResolver: PluginZod['resolver'] | undefined
19
- typeFile: KubbFile.File
20
- zodFile: KubbFile.File | undefined
18
+ typeFile: FileNode
19
+ zodFile: FileNode | undefined
21
20
  }
22
21
 
23
22
  type Controller = {
24
23
  name: string
25
- file: KubbFile.File
24
+ file: FileNode
26
25
  operations: Array<OperationData>
27
26
  }
28
27
 
@@ -48,7 +47,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
48
47
  operations(nodes, options) {
49
48
  const { adapter, config, driver, resolver, root } = this
50
49
  const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options
51
- const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL
50
+ const baseURL = options.baseURL ?? adapter.inputNode?.meta?.baseURL
52
51
 
53
52
  const pluginTs = driver.getPlugin(pluginTsName)
54
53
  if (!pluginTs?.resolver) return null
@@ -117,7 +116,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
117
116
 
118
117
  function collectTypeImports(ops: Array<OperationData>) {
119
118
  const typeImportsByFile = new Map<string, Set<string>>()
120
- const typeFilesByPath = new Map<string, KubbFile.File>()
119
+ const typeFilesByPath = new Map<string, FileNode>()
121
120
 
122
121
  ops.forEach((op) => {
123
122
  const names = resolveTypeImportNames(op.node, tsResolver)
@@ -136,7 +135,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
136
135
 
137
136
  function collectZodImports(ops: Array<OperationData>) {
138
137
  const zodImportsByFile = new Map<string, Set<string>>()
139
- const zodFilesByPath = new Map<string, KubbFile.File>()
138
+ const zodFilesByPath = new Map<string, FileNode>()
140
139
 
141
140
  ops.forEach((op) => {
142
141
  if (!op.zodFile || !zodResolver) return
@@ -159,7 +158,7 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
159
158
  {controllers.map(({ name, file, operations: ops }) => {
160
159
  const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops)
161
160
  const { zodImportsByFile, zodFilesByPath } =
162
- parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, KubbFile.File>() }
161
+ parser === 'zod' ? collectZodImports(ops) : { zodImportsByFile: new Map<string, Set<string>>(), zodFilesByPath: new Map<string, FileNode>() }
163
162
  const hasFormData = ops.some((op) => op.node.requestBody?.contentType === 'multipart/form-data')
164
163
 
165
164
  return (
@@ -168,8 +167,8 @@ export const staticClassClientGenerator = defineGenerator<PluginClient>({
168
167
  baseName={file.baseName}
169
168
  path={file.path}
170
169
  meta={file.meta}
171
- banner={resolver.resolveBanner(adapter.rootNode, { output, config })}
172
- footer={resolver.resolveFooter(adapter.rootNode, { output, config })}
170
+ banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
171
+ footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
173
172
  >
174
173
  {importPath ? (
175
174
  <>
package/src/plugin.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path'
2
2
  import { camelCase } from '@internals/utils'
3
+ import { createFile, createSource } from '@kubb/ast'
3
4
  import { createPlugin, type Group, getPreset, mergeGenerators } from '@kubb/core'
4
5
  import { pluginTsName } from '@kubb/plugin-ts'
5
6
  import { pluginZodName } from '@kubb/plugin-zod'
@@ -161,36 +162,36 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
161
162
 
162
163
  // pre add bundled fetch
163
164
  if (bundle && !plugin.options.importPath) {
164
- await this.addFile({
165
- baseName: 'fetch.ts',
166
- path: path.resolve(root, '.kubb/fetch.ts'),
167
- sources: [
168
- {
169
- name: 'fetch',
170
- value: plugin.options.client === 'fetch' ? fetchClientSource : axiosClientSource,
171
- isExportable: true,
172
- isIndexable: true,
173
- },
174
- ],
175
- imports: [],
176
- exports: [],
177
- })
165
+ await this.addFile(
166
+ createFile({
167
+ baseName: 'fetch.ts',
168
+ path: path.resolve(root, '.kubb/fetch.ts'),
169
+ sources: [
170
+ createSource({
171
+ name: 'fetch',
172
+ value: plugin.options.client === 'fetch' ? fetchClientSource : axiosClientSource,
173
+ isExportable: true,
174
+ isIndexable: true,
175
+ }),
176
+ ],
177
+ }),
178
+ )
178
179
  }
179
180
 
180
- await this.addFile({
181
- baseName: 'config.ts',
182
- path: path.resolve(root, '.kubb/config.ts'),
183
- sources: [
184
- {
185
- name: 'config',
186
- value: configSource,
187
- isExportable: false,
188
- isIndexable: false,
189
- },
190
- ],
191
- imports: [],
192
- exports: [],
193
- })
181
+ await this.addFile(
182
+ createFile({
183
+ baseName: 'config.ts',
184
+ path: path.resolve(root, '.kubb/config.ts'),
185
+ sources: [
186
+ createSource({
187
+ name: 'config',
188
+ value: configSource,
189
+ isExportable: false,
190
+ isIndexable: false,
191
+ }),
192
+ ],
193
+ }),
194
+ )
194
195
  },
195
196
  }
196
197
  })