@kubb/plugin-client 0.0.0-canary-20250109143608 → 0.0.0-canary-20250109230602

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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-P398e_Yv.js';
2
+ import { O as Options, P as PluginClient } from './types-CP1y6jDc.js';
3
+ import '@kubb/oas';
3
4
  import '@kubb/plugin-oas';
4
5
 
5
6
  declare const pluginClientName = "plugin-client";
package/dist/index.js CHANGED
@@ -1,4 +1,115 @@
1
- export { pluginClient, pluginClientName } from './chunk-7JWZVEC4.js';
1
+ import { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-HMHER7HU.js';
2
2
  import './chunk-HVZSAZQR.js';
3
+ import path from 'node:path';
4
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
5
+ import { camelCase } from '@kubb/core/transformers';
6
+ import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
7
+ import { pluginZodName } from '@kubb/plugin-zod';
8
+
9
+ var pluginClientName = "plugin-client";
10
+ var pluginClient = createPlugin((options) => {
11
+ const {
12
+ output = { path: "clients", barrelType: "named" },
13
+ group,
14
+ exclude = [],
15
+ include,
16
+ override = [],
17
+ transformers = {},
18
+ dataReturnType = "data",
19
+ pathParamsType = "inline",
20
+ paramsType = "inline",
21
+ operations = false,
22
+ baseURL,
23
+ paramsCasing,
24
+ generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
25
+ parser = "client",
26
+ client = "axios",
27
+ importPath = client === "fetch" ? "@kubb/plugin-client/clients/fetch" : "@kubb/plugin-client/clients/axios"
28
+ } = options;
29
+ return {
30
+ name: pluginClientName,
31
+ options: {
32
+ output,
33
+ group,
34
+ parser,
35
+ dataReturnType,
36
+ importPath,
37
+ paramsType,
38
+ paramsCasing,
39
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType,
40
+ baseURL
41
+ },
42
+ pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
43
+ resolvePath(baseName, pathMode, options2) {
44
+ const root = path.resolve(this.config.root, this.config.output.path);
45
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
46
+ if (mode === "single") {
47
+ return path.resolve(root, output.path);
48
+ }
49
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
50
+ const groupName = group?.name ? group.name : (ctx) => {
51
+ if (group?.type === "path") {
52
+ return `${ctx.group.split("/")[1]}`;
53
+ }
54
+ return `${camelCase(ctx.group)}Controller`;
55
+ };
56
+ return path.resolve(
57
+ root,
58
+ output.path,
59
+ groupName({
60
+ group: group.type === "path" ? options2.group.path : options2.group.tag
61
+ }),
62
+ baseName
63
+ );
64
+ }
65
+ return path.resolve(root, output.path, baseName);
66
+ },
67
+ resolveName(name, type) {
68
+ const resolvedName = camelCase(name, { isFile: type === "file" });
69
+ if (type) {
70
+ return transformers?.name?.(resolvedName, type) || resolvedName;
71
+ }
72
+ return resolvedName;
73
+ },
74
+ async buildStart() {
75
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
76
+ const oas = await swaggerPlugin.context.getOas();
77
+ const root = path.resolve(this.config.root, this.config.output.path);
78
+ const mode = FileManager.getMode(path.resolve(root, output.path));
79
+ const baseURL2 = await swaggerPlugin.context.getBaseURL();
80
+ const operationGenerator = new OperationGenerator(
81
+ baseURL2 ? {
82
+ ...this.plugin.options,
83
+ baseURL: baseURL2
84
+ } : this.plugin.options,
85
+ {
86
+ oas,
87
+ pluginManager: this.pluginManager,
88
+ plugin: this.plugin,
89
+ contentType: swaggerPlugin.context.contentType,
90
+ exclude,
91
+ include,
92
+ override,
93
+ mode
94
+ }
95
+ );
96
+ const files = await operationGenerator.build(...generators);
97
+ await this.addFile(...files);
98
+ const barrelFiles = await this.fileManager.getBarrelFiles({
99
+ type: output.barrelType ?? "named",
100
+ root,
101
+ output,
102
+ files: this.fileManager.files,
103
+ meta: {
104
+ pluginKey: this.plugin.key
105
+ },
106
+ logger: this.logger
107
+ });
108
+ await this.addFile(...barrelFiles);
109
+ }
110
+ };
111
+ });
112
+
113
+ export { pluginClient, pluginClientName };
3
114
  //# sourceMappingURL=index.js.map
4
115
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["options","baseURL"],"mappings":";;;;;;;;AAcO,IAAM,gBAAmB,GAAA;AAEnB,IAAA,YAAA,GAAe,YAA2B,CAAA,CAAC,OAAY,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,SAAA,EAAW,YAAY,OAAQ,EAAA;AAAA,IAChD,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,MAAA;AAAA,IACjB,cAAiB,GAAA,QAAA;AAAA,IACjB,UAAa,GAAA,QAAA;AAAA,IACb,UAAa,GAAA,KAAA;AAAA,IACb,OAAA;AAAA,IACA,YAAA;AAAA,IACA,UAAA,GAAa,CAAC,eAAA,EAAiB,KAAQ,GAAA,sBAAA,GAAyB,KAAW,CAAA,EAAA,UAAA,GAAa,mBAAsB,GAAA,KAAA,CAAS,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,IACvI,MAAS,GAAA,QAAA;AAAA,IACT,MAAS,GAAA,OAAA;AAAA,IACT,UAAA,GAAa,MAAW,KAAA,OAAA,GAAU,mCAAsC,GAAA;AAAA,GACtE,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,gBAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,KAAA;AAAA,MACA,MAAA;AA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F,GACA,KAAK,MAAO,CAAA,OAAA;AAAA,QAChB;AAAA,UACE,GAAA;AAAA,UACA,eAAe,IAAK,CAAA,aAAA;AAAA,UACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,UACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA;AAAA;AACF,OACF;AAEA,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAE1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.tsx'\nimport { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n paramsType = 'inline',\n operations = false,\n baseURL,\n paramsCasing,\n generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),\n parser = 'client',\n client = 'axios',\n importPath = client === 'fetch' ? '@kubb/plugin-client/clients/fetch' : '@kubb/plugin-client/clients/axios',\n } = options\n\n return {\n name: pluginClientName,\n options: {\n output,\n group,\n parser,\n dataReturnType,\n importPath,\n paramsType,\n paramsCasing,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n baseURL,\n },\n pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n baseURL\n ? {\n ...this.plugin.options,\n baseURL,\n }\n : this.plugin.options,\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(...generators)\n\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
@@ -1,4 +1,5 @@
1
1
  import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { Oas } from '@kubb/oas';
2
3
  import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
3
4
 
4
5
  type Options = {
@@ -6,7 +7,7 @@ type Options = {
6
7
  * Specify the export location for the files and define the behavior of the output
7
8
  * @default { path: 'clients', barrelType: 'named' }
8
9
  */
9
- output?: Output;
10
+ output?: Output<Oas>;
10
11
  /**
11
12
  * Group the clients based on the provided name.
12
13
  */
@@ -90,7 +91,7 @@ type Options = {
90
91
  generators?: Array<Generator<PluginClient>>;
91
92
  };
92
93
  type ResolvedOptions = {
93
- output: Output;
94
+ output: Output<Oas>;
94
95
  group?: Options['group'];
95
96
  baseURL: string | undefined;
96
97
  parser: NonNullable<Options['parser']>;
@@ -1,4 +1,5 @@
1
1
  import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { Oas } from '@kubb/oas';
2
3
  import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
3
4
 
4
5
  type Options = {
@@ -6,7 +7,7 @@ type Options = {
6
7
  * Specify the export location for the files and define the behavior of the output
7
8
  * @default { path: 'clients', barrelType: 'named' }
8
9
  */
9
- output?: Output;
10
+ output?: Output<Oas>;
10
11
  /**
11
12
  * Group the clients based on the provided name.
12
13
  */
@@ -90,7 +91,7 @@ type Options = {
90
91
  generators?: Array<Generator<PluginClient>>;
91
92
  };
92
93
  type ResolvedOptions = {
93
- output: Output;
94
+ output: Output<Oas>;
94
95
  group?: Options['group'];
95
96
  baseURL: string | undefined;
96
97
  parser: NonNullable<Options['parser']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "0.0.0-canary-20250109143608",
3
+ "version": "0.0.0-canary-20250109230602",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -78,23 +78,23 @@
78
78
  "!/**/__tests__/**"
79
79
  ],
80
80
  "dependencies": {
81
- "@kubb/core": "0.0.0-canary-20250109143608",
82
- "@kubb/fs": "0.0.0-canary-20250109143608",
83
- "@kubb/oas": "0.0.0-canary-20250109143608",
84
- "@kubb/plugin-oas": "0.0.0-canary-20250109143608",
85
- "@kubb/plugin-ts": "0.0.0-canary-20250109143608",
86
- "@kubb/plugin-zod": "0.0.0-canary-20250109143608",
87
- "@kubb/react": "0.0.0-canary-20250109143608"
81
+ "@kubb/core": "0.0.0-canary-20250109230602",
82
+ "@kubb/fs": "0.0.0-canary-20250109230602",
83
+ "@kubb/oas": "0.0.0-canary-20250109230602",
84
+ "@kubb/plugin-oas": "0.0.0-canary-20250109230602",
85
+ "@kubb/plugin-ts": "0.0.0-canary-20250109230602",
86
+ "@kubb/plugin-zod": "0.0.0-canary-20250109230602",
87
+ "@kubb/react": "0.0.0-canary-20250109230602"
88
88
  },
89
89
  "devDependencies": {
90
90
  "axios": "^1.7.9",
91
91
  "tsup": "^8.3.5",
92
- "typescript": "^5.7.2",
93
- "@kubb/config-ts": "0.0.0-canary-20250109143608",
94
- "@kubb/config-tsup": "0.0.0-canary-20250109143608"
92
+ "typescript": "^5.7.3",
93
+ "@kubb/config-ts": "0.0.0-canary-20250109230602",
94
+ "@kubb/config-tsup": "0.0.0-canary-20250109230602"
95
95
  },
96
96
  "peerDependencies": {
97
- "@kubb/react": "0.0.0-canary-20250109143608",
97
+ "@kubb/react": "0.0.0-canary-20250109230602",
98
98
  "axios": "^1.7.2"
99
99
  },
100
100
  "peerDependenciesMeta": {
@@ -1,5 +1,6 @@
1
1
  import { createReactGenerator } from '@kubb/plugin-oas'
2
- import { useOperationManager } from '@kubb/plugin-oas/hooks'
2
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
3
4
  import { pluginTsName } from '@kubb/plugin-ts'
4
5
  import { pluginZodName } from '@kubb/plugin-zod'
5
6
  import { File, useApp } from '@kubb/react'
@@ -15,6 +16,7 @@ export const clientGenerator = createReactGenerator<PluginClient>({
15
16
  options: { output },
16
17
  },
17
18
  } = useApp<PluginClient>()
19
+ const oas = useOas()
18
20
  const { getSchemas, getName, getFile } = useOperationManager()
19
21
 
20
22
  const client = {
@@ -23,7 +25,7 @@ export const clientGenerator = createReactGenerator<PluginClient>({
23
25
  }
24
26
 
25
27
  const url = {
26
- name: getName(operation, { type: 'function', suffix: 'URL', prefix: 'get' }),
28
+ name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }),
27
29
  file: getFile(operation),
28
30
  }
29
31
 
@@ -38,7 +40,13 @@ export const clientGenerator = createReactGenerator<PluginClient>({
38
40
  }
39
41
 
40
42
  return (
41
- <File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>
43
+ <File
44
+ baseName={client.file.baseName}
45
+ path={client.file.path}
46
+ meta={client.file.meta}
47
+ banner={getBanner({ oas, output })}
48
+ footer={getFooter({ oas, output })}
49
+ >
42
50
  <File.Import name={'client'} path={options.importPath} />
43
51
  <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />
44
52
  {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}
@@ -1,8 +1,9 @@
1
1
  import { camelCase } from '@kubb/core/transformers'
2
2
  import type * as KubbFile from '@kubb/fs/types'
3
- import { pluginClientName } from '@kubb/plugin-client'
3
+
4
4
  import { createReactGenerator } from '@kubb/plugin-oas'
5
- import { useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
6
7
  import { File, Function, useApp } from '@kubb/react'
7
8
  import type { PluginClient } from '../types'
8
9
 
@@ -13,6 +14,7 @@ export const groupedClientGenerator = createReactGenerator<PluginClient>({
13
14
  pluginManager,
14
15
  plugin: { options, key: pluginKey },
15
16
  } = useApp<PluginClient>()
17
+ const oas = useOas()
16
18
  const { getName, getFile, getGroup } = useOperationManager()
17
19
 
18
20
  const controllers = operations.reduce(
@@ -53,7 +55,14 @@ export const groupedClientGenerator = createReactGenerator<PluginClient>({
53
55
 
54
56
  return controllers.map(({ name, file, clients }) => {
55
57
  return (
56
- <File key={file.path} baseName={file.baseName} path={file.path} meta={file.meta} banner={options.output?.banner} footer={options.output?.footer}>
58
+ <File
59
+ key={file.path}
60
+ baseName={file.baseName}
61
+ path={file.path}
62
+ meta={file.meta}
63
+ banner={getBanner({ oas, output: options.output })}
64
+ footer={getFooter({ oas, output: options.output })}
65
+ >
57
66
  {clients.map((client) => (
58
67
  <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />
59
68
  ))}
@@ -1,5 +1,6 @@
1
- import { pluginClientName } from '@kubb/plugin-client'
2
1
  import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOas } from '@kubb/plugin-oas/hooks'
3
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
3
4
  import { File, useApp } from '@kubb/react'
4
5
  import { Operations } from '../components/Operations'
5
6
  import type { PluginClient } from '../types'
@@ -14,12 +15,13 @@ export const operationsGenerator = createReactGenerator<PluginClient>({
14
15
  options: { output },
15
16
  },
16
17
  } = useApp<PluginClient>()
18
+ const oas = useOas()
17
19
 
18
20
  const name = 'operations'
19
21
  const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })
20
22
 
21
23
  return (
22
- <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
24
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>
23
25
  <Operations name={name} operations={operations} />
24
26
  </File>
25
27
  )
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
 
3
+ import type { Oas } from '@kubb/oas'
3
4
  import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
4
5
 
5
6
  export type Options = {
@@ -7,7 +8,7 @@ export type Options = {
7
8
  * Specify the export location for the files and define the behavior of the output
8
9
  * @default { path: 'clients', barrelType: 'named' }
9
10
  */
10
- output?: Output
11
+ output?: Output<Oas>
11
12
  /**
12
13
  * Group the clients based on the provided name.
13
14
  */
@@ -92,7 +93,7 @@ export type Options = {
92
93
  }
93
94
 
94
95
  type ResolvedOptions = {
95
- output: Output
96
+ output: Output<Oas>
96
97
  group?: Options['group']
97
98
  baseURL: string | undefined
98
99
  parser: NonNullable<Options['parser']>
@@ -1,256 +0,0 @@
1
- import { Url, Client, Operations } from './chunk-HVZSAZQR.js';
2
- import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
3
- import { useOperationManager } from '@kubb/plugin-oas/hooks';
4
- import { pluginTsName } from '@kubb/plugin-ts';
5
- import { pluginZodName } from '@kubb/plugin-zod';
6
- import { useApp, File, Function } from '@kubb/react';
7
- import { jsxs, jsx } from '@kubb/react/jsx-runtime';
8
- import path from 'node:path';
9
- import { createPlugin, FileManager, PluginManager } from '@kubb/core';
10
- import { camelCase } from '@kubb/core/transformers';
11
-
12
- var clientGenerator = createReactGenerator({
13
- name: "client",
14
- Operation({ options, operation }) {
15
- const {
16
- plugin: {
17
- options: { output }
18
- }
19
- } = useApp();
20
- const { getSchemas, getName, getFile } = useOperationManager();
21
- const client = {
22
- name: getName(operation, { type: "function" }),
23
- file: getFile(operation)
24
- };
25
- const url = {
26
- name: getName(operation, { type: "function", suffix: "URL", prefix: "get" }),
27
- file: getFile(operation)
28
- };
29
- const type = {
30
- file: getFile(operation, { pluginKey: [pluginTsName] }),
31
- schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
32
- };
33
- const zod = {
34
- file: getFile(operation, { pluginKey: [pluginZodName] }),
35
- schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
36
- };
37
- return /* @__PURE__ */ jsxs(File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
38
- /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath }),
39
- /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseErrorConfig"], path: options.importPath, isTypeOnly: true }),
40
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
41
- /* @__PURE__ */ jsx(
42
- File.Import,
43
- {
44
- name: [
45
- type.schemas.request?.name,
46
- type.schemas.response.name,
47
- type.schemas.pathParams?.name,
48
- type.schemas.queryParams?.name,
49
- type.schemas.headerParams?.name,
50
- ...type.schemas.statusCodes?.map((item) => item.name) || []
51
- ].filter(Boolean),
52
- root: client.file.path,
53
- path: type.file.path,
54
- isTypeOnly: true
55
- }
56
- ),
57
- /* @__PURE__ */ jsx(
58
- Url,
59
- {
60
- name: url.name,
61
- baseURL: options.baseURL,
62
- pathParamsType: options.pathParamsType,
63
- paramsCasing: options.paramsCasing,
64
- paramsType: options.paramsType,
65
- typeSchemas: type.schemas,
66
- operation
67
- }
68
- ),
69
- /* @__PURE__ */ jsx(
70
- Client,
71
- {
72
- name: client.name,
73
- urlName: url.name,
74
- baseURL: options.baseURL,
75
- dataReturnType: options.dataReturnType,
76
- pathParamsType: options.pathParamsType,
77
- paramsCasing: options.paramsCasing,
78
- paramsType: options.paramsType,
79
- typeSchemas: type.schemas,
80
- operation,
81
- parser: options.parser,
82
- zodSchemas: zod.schemas
83
- }
84
- )
85
- ] });
86
- }
87
- });
88
- var groupedClientGenerator = createReactGenerator({
89
- name: "groupedClient",
90
- Operations({ operations }) {
91
- const {
92
- pluginManager,
93
- plugin: { options, key: pluginKey }
94
- } = useApp();
95
- const { getName, getFile, getGroup } = useOperationManager();
96
- const controllers = operations.reduce(
97
- (acc, operation) => {
98
- if (options.group?.type === "tag") {
99
- const group = getGroup(operation);
100
- const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : void 0;
101
- if (!group?.tag || !name) {
102
- return acc;
103
- }
104
- const file = pluginManager.getFile({
105
- name,
106
- extname: ".ts",
107
- pluginKey,
108
- options: { group }
109
- });
110
- const client = {
111
- name: getName(operation, { type: "function" }),
112
- file: getFile(operation)
113
- };
114
- const previousFile = acc.find((item) => item.file.path === file.path);
115
- if (previousFile) {
116
- previousFile.clients.push(client);
117
- } else {
118
- acc.push({ name, file, clients: [client] });
119
- }
120
- }
121
- return acc;
122
- },
123
- []
124
- );
125
- return controllers.map(({ name, file, clients }) => {
126
- return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
127
- clients.map((client) => /* @__PURE__ */ jsx(File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
128
- /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
129
- ] }, file.path);
130
- });
131
- }
132
- });
133
-
134
- // src/plugin.ts
135
- var pluginClientName = "plugin-client";
136
- var pluginClient = createPlugin((options) => {
137
- const {
138
- output = { path: "clients", barrelType: "named" },
139
- group,
140
- exclude = [],
141
- include,
142
- override = [],
143
- transformers = {},
144
- dataReturnType = "data",
145
- pathParamsType = "inline",
146
- paramsType = "inline",
147
- operations = false,
148
- baseURL,
149
- paramsCasing,
150
- generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
151
- parser = "client",
152
- client = "axios",
153
- importPath = client === "fetch" ? "@kubb/plugin-client/clients/fetch" : "@kubb/plugin-client/clients/axios"
154
- } = options;
155
- return {
156
- name: pluginClientName,
157
- options: {
158
- output,
159
- group,
160
- parser,
161
- dataReturnType,
162
- importPath,
163
- paramsType,
164
- paramsCasing,
165
- pathParamsType: paramsType === "object" ? "object" : pathParamsType,
166
- baseURL
167
- },
168
- pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
169
- resolvePath(baseName, pathMode, options2) {
170
- const root = path.resolve(this.config.root, this.config.output.path);
171
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
172
- if (mode === "single") {
173
- return path.resolve(root, output.path);
174
- }
175
- if (group && (options2?.group?.path || options2?.group?.tag)) {
176
- const groupName = group?.name ? group.name : (ctx) => {
177
- if (group?.type === "path") {
178
- return `${ctx.group.split("/")[1]}`;
179
- }
180
- return `${camelCase(ctx.group)}Controller`;
181
- };
182
- return path.resolve(
183
- root,
184
- output.path,
185
- groupName({
186
- group: group.type === "path" ? options2.group.path : options2.group.tag
187
- }),
188
- baseName
189
- );
190
- }
191
- return path.resolve(root, output.path, baseName);
192
- },
193
- resolveName(name, type) {
194
- const resolvedName = camelCase(name, { isFile: type === "file" });
195
- if (type) {
196
- return transformers?.name?.(resolvedName, type) || resolvedName;
197
- }
198
- return resolvedName;
199
- },
200
- async buildStart() {
201
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
202
- const oas = await swaggerPlugin.context.getOas();
203
- const root = path.resolve(this.config.root, this.config.output.path);
204
- const mode = FileManager.getMode(path.resolve(root, output.path));
205
- const baseURL2 = await swaggerPlugin.context.getBaseURL();
206
- const operationGenerator = new OperationGenerator(
207
- baseURL2 ? {
208
- ...this.plugin.options,
209
- baseURL: baseURL2
210
- } : this.plugin.options,
211
- {
212
- oas,
213
- pluginManager: this.pluginManager,
214
- plugin: this.plugin,
215
- contentType: swaggerPlugin.context.contentType,
216
- exclude,
217
- include,
218
- override,
219
- mode
220
- }
221
- );
222
- const files = await operationGenerator.build(...generators);
223
- await this.addFile(...files);
224
- const barrelFiles = await this.fileManager.getBarrelFiles({
225
- type: output.barrelType ?? "named",
226
- root,
227
- output,
228
- files: this.fileManager.files,
229
- meta: {
230
- pluginKey: this.plugin.key
231
- },
232
- logger: this.logger
233
- });
234
- await this.addFile(...barrelFiles);
235
- }
236
- };
237
- });
238
- var operationsGenerator = createReactGenerator({
239
- name: "client",
240
- Operations({ operations }) {
241
- const {
242
- pluginManager,
243
- plugin: {
244
- key: pluginKey,
245
- options: { output }
246
- }
247
- } = useApp();
248
- const name = "operations";
249
- const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
250
- return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
251
- }
252
- });
253
-
254
- export { clientGenerator, groupedClientGenerator, operationsGenerator, pluginClient, pluginClientName };
255
- //# sourceMappingURL=chunk-7JWZVEC4.js.map
256
- //# sourceMappingURL=chunk-7JWZVEC4.js.map