@kubb/plugin-client 3.4.5 → 3.5.0

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-6IVTF2W4.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;AAAA,MACA,cAAA;AAAA,M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AA,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": "3.4.5",
3
+ "version": "3.5.0",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -78,20 +78,20 @@
78
78
  "!/**/__tests__/**"
79
79
  ],
80
80
  "dependencies": {
81
- "@kubb/core": "3.4.5",
82
- "@kubb/fs": "3.4.5",
83
- "@kubb/oas": "3.4.5",
84
- "@kubb/plugin-oas": "3.4.5",
85
- "@kubb/plugin-ts": "3.4.5",
86
- "@kubb/plugin-zod": "3.4.5",
87
- "@kubb/react": "3.4.5"
81
+ "@kubb/core": "3.5.0",
82
+ "@kubb/fs": "3.5.0",
83
+ "@kubb/oas": "3.5.0",
84
+ "@kubb/plugin-oas": "3.5.0",
85
+ "@kubb/plugin-ts": "3.5.0",
86
+ "@kubb/plugin-zod": "3.5.0",
87
+ "@kubb/react": "3.5.0"
88
88
  },
89
89
  "devDependencies": {
90
90
  "axios": "^1.7.9",
91
91
  "tsup": "^8.3.5",
92
92
  "typescript": "^5.7.3",
93
- "@kubb/config-ts": "3.4.5",
94
- "@kubb/config-tsup": "3.4.5"
93
+ "@kubb/config-ts": "3.5.0",
94
+ "@kubb/config-tsup": "3.5.0"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "@kubb/react": "^3.0.0",
@@ -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 = {
@@ -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-6IVTF2W4.js.map
256
- //# sourceMappingURL=chunk-6IVTF2W4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/generators/groupedClientGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","jsxs","File","jsx","pluginZodName","options","camelCase","baseURL"],"mappings":";;;;;;;;;;;AASO,IAAM,kBAAkB,oBAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,QAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO;AAAA;AACpB,QACE,MAAqB,EAAA;AACzB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,GAAM,GAAA;AAAA,MACV,IAAA,EAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,MAAQ,EAAA,KAAA,EAAO,MAAQ,EAAA,KAAA,EAAO,CAAA;AAAA,MAC3E,IAAA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AA,CAAK,MAAM,MAAQ,EAAA,MAAA,EAAQ,MAAQ,EAAA,MAAA,EAAQ,MAAQ,EAAA,MAAA,EACvG,0BAAAC,GAAC,CAAA,UAAA,EAAA,EAAW,IAAY,EAAA,UAAA,EAAwB,CAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-6IVTF2W4.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Url } from '../components/Url.tsx'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginClient>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const url = {\n name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n return (\n <File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={'client'} path={options.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={client.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Url\n name={url.name}\n baseURL={options.baseURL}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n />\n\n <Client\n name={client.name}\n urlName={url.name}\n baseURL={options.baseURL}\n dataReturnType={options.dataReturnType}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n parser={options.parser}\n zodSchemas={zod.schemas}\n />\n </File>\n )\n },\n})\n","import { camelCase } from '@kubb/core/transformers'\nimport type * as KubbFile from '@kubb/fs/types'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, Function, useApp } from '@kubb/react'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: { options, key: pluginKey },\n } = useApp<PluginClient>()\n const { getName, getFile, getGroup } = useOperationManager()\n\n const controllers = operations.reduce(\n (acc, operation) => {\n if (options.group?.type === 'tag') {\n const group = getGroup(operation)\n const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : undefined\n\n if (!group?.tag || !name) {\n return acc\n }\n\n const file = pluginManager.getFile({\n name,\n extname: '.ts',\n pluginKey,\n options: { group },\n })\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const previousFile = acc.find((item) => item.file.path === file.path)\n\n if (previousFile) {\n previousFile.clients.push(client)\n } else {\n acc.push({ name, file, clients: [client] })\n }\n }\n\n return acc\n },\n [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,\n )\n\n return controllers.map(({ name, file, clients }) => {\n return (\n <File key={file.path} baseName={file.baseName} path={file.path} meta={file.meta} banner={options.output?.banner} footer={options.output?.footer}>\n {clients.map((client) => (\n <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />\n ))}\n\n <File.Source name={name} isExportable isIndexable>\n <Function export name={name}>\n {`return { ${clients.map((client) => client.name).join(', ')} }`}\n </Function>\n </File.Source>\n </File>\n )\n })\n },\n})\n","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","import { pluginClientName } from '@kubb/plugin-client'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginClient>()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"]}