@kubb/plugin-client 4.5.6 → 4.5.8
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/{Operations-CTvMCPaa.cjs → Operations-6d1309lt.cjs} +2 -2
- package/dist/{Operations-CTvMCPaa.cjs.map → Operations-6d1309lt.cjs.map} +1 -1
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/clients/axios.cjs +40 -0
- package/dist/clients/axios.cjs.map +1 -0
- package/dist/clients/axios.d.cts +39 -0
- package/dist/clients/axios.d.ts +39 -0
- package/dist/clients/axios.js +33 -0
- package/dist/clients/axios.js.map +1 -0
- package/dist/clients/fetch.cjs +48 -0
- package/dist/clients/fetch.cjs.map +1 -0
- package/dist/clients/fetch.d.cts +39 -0
- package/dist/clients/fetch.d.ts +39 -0
- package/dist/clients/fetch.js +43 -0
- package/dist/clients/fetch.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/{generators-CQvDx6Mq.js → generators-DXO7Q8-4.js} +4 -4
- package/dist/generators-DXO7Q8-4.js.map +1 -0
- package/dist/{generators-f5-oi9Hx.cjs → generators-NmR9v8nl.cjs} +7 -35
- package/dist/generators-NmR9v8nl.cjs.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +15 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-C8tGU2Ir.d.cts → types-B-Yse6Ey.d.ts} +9 -2
- package/dist/{types-CDBKpdup.d.ts → types-ClSTrlYq.d.cts} +9 -2
- package/package.json +20 -6
- package/src/clients/axios.ts +68 -0
- package/src/clients/fetch.ts +81 -0
- package/src/generators/clientGenerator.tsx +2 -2
- package/src/plugin.ts +13 -7
- package/src/types.ts +7 -0
- package/templates/clients/axios.ts +3 -5
- package/templates/clients/fetch.ts +4 -6
- package/dist/generators-CQvDx6Mq.js.map +0 -1
- package/dist/generators-f5-oi9Hx.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-NmR9v8nl.cjs","names":["pluginTsName","pluginZodName","File","path","Url","Client","File","Function","File","Operations"],"sources":["../src/generators/clientGenerator.tsx","../src/generators/groupedClientGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\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({ config, plugin, operation, generator }) {\n const pluginManager = usePluginManager()\n const {\n options,\n options: { output, urlType },\n } = plugin\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\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\n baseName={client.file.baseName}\n path={client.file.path}\n meta={client.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {options.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />\n </>\n ) : (\n <>\n <File.Import name={['fetch']} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={client.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}\n isTypeOnly\n />\n </>\n )}\n\n {options.parser === 'zod' && (\n <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={client.file.path} path={zod.file.path} />\n )}\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 isIndexable={urlType === 'export'}\n isExportable={urlType === 'export'}\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 { usePluginManager } from '@kubb/core/hooks'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, Function } from '@kubb/react-fabric'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations, generator, plugin }) {\n const { options, key: pluginKey } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile, getGroup } = useOperationManager(generator)\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\n key={file.path}\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\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 { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations, plugin }) {\n const {\n key: pluginKey,\n options: { output },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAa,yEAAqD;CAChE,MAAM;CACN,UAAU,EAAE,QAAQ,QAAQ,WAAW,aAAa;EAClD,MAAM,yDAAkC;EACxC,MAAM,EACJ,SACA,SAAS,EAAE,QAAQ,cACjB;EAEJ,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,6DAAgC,UAAU;EAEvE,MAAM,SAAS;GACb,MAAM,QAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;GAC9C,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAO,QAAQ;IAAO,CAAC;GAC5E,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAACA,8BAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAACA,8BAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;EAED,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW,EAAE,WAAW,CAACC,gCAAc,EAAE,CAAC;GACxD,SAAS,WAAW,WAAW;IAAE,WAAW,CAACA,gCAAc;IAAE,MAAM;IAAY,CAAC;GACjF;AAED,SACE,0DAACC;GACC,UAAU,OAAO,KAAK;GACtB,MAAM,OAAO,KAAK;GAClB,MAAM,OAAO,KAAK;GAClB,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;;IAEjC,QAAQ,aACP,iHACE,yDAACA,yBAAK;KAAO,M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M,CAAC,OAAO,KAAK;KAAE,MAAM,KAAK;KAAM,MAAM,OAAO,KAAK;OAArE,OAAO,KAAsE,CAC/F,EAEF,yDAACA,yBAAK;KAAa;KAAM;KAAa;eACpC,yDAACC;MAAS;MAAa;gBACpB,YAAY,QAAQ,KAAK,WAAW,OAAO,KAAK,CAAC,KAAK,KAAK,CAAC;OACpD;MACC;MAfT,KAAK,KAgBL;IAET;;CAEL,CAAC;;;;ACrEF,MAAa,6EAAyD;CACpE,MAAM;CACN,WAAW,EAAE,YAAY,UAAU;EACjC,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,aACT;EACJ,MAAM,yDAAkC;EAExC,MAAM,2CAAc;EAEpB,MAAM,OAAO;EACb,MAAM,OAAO,cAAc,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAW,CAAC;AAEvE,SACE,yDAACC;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;aAElC,yDAACC;IAAiB;IAAkB;KAAc;IAC7C;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
require('./
|
|
1
|
+
require('./Operations-6d1309lt.cjs');
|
|
2
|
+
const require_generators = require('./generators-NmR9v8nl.cjs');
|
|
3
3
|
|
|
4
4
|
exports.clientGenerator = require_generators.clientGenerator;
|
|
5
5
|
exports.groupedClientGenerator = require_generators.groupedClientGenerator;
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PluginClient, r as ReactGenerator } from "./types-
|
|
1
|
+
import { n as PluginClient, r as ReactGenerator } from "./types-ClSTrlYq.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/generators/clientGenerator.d.ts
|
|
4
4
|
declare const clientGenerator: ReactGenerator<PluginClient>;
|
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./Operations-HWuo-D3O.js";
|
|
2
|
-
import { n as groupedClientGenerator, r as clientGenerator, t as operationsGenerator } from "./generators-
|
|
2
|
+
import { n as groupedClientGenerator, r as clientGenerator, t as operationsGenerator } from "./generators-DXO7Q8-4.js";
|
|
3
3
|
|
|
4
4
|
export { clientGenerator, groupedClientGenerator, operationsGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
require('./Operations-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
require('./Operations-6d1309lt.cjs');
|
|
3
|
+
const require_generators = require('./generators-NmR9v8nl.cjs');
|
|
3
4
|
let node_path = require("node:path");
|
|
4
|
-
node_path =
|
|
5
|
+
node_path = require_chunk.__toESM(node_path);
|
|
5
6
|
let __kubb_core = require("@kubb/core");
|
|
6
7
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
7
8
|
let __kubb_core_utils = require("@kubb/core/utils");
|
|
@@ -11,6 +12,7 @@ let __kubb_plugin_zod = require("@kubb/plugin-zod");
|
|
|
11
12
|
//#region src/plugin.ts
|
|
12
13
|
const pluginClientName = "plugin-client";
|
|
13
14
|
const pluginClient = (0, __kubb_core.definePlugin)((options) => {
|
|
15
|
+
const bundle = options.bundle ?? false;
|
|
14
16
|
const { output = {
|
|
15
17
|
path: "clients",
|
|
16
18
|
barrelType: "named"
|
|
@@ -23,11 +25,12 @@ const pluginClient = (0, __kubb_core.definePlugin)((options) => {
|
|
|
23
25
|
name: pluginClientName,
|
|
24
26
|
options: {
|
|
25
27
|
client,
|
|
28
|
+
bundle,
|
|
26
29
|
output,
|
|
27
30
|
group,
|
|
28
31
|
parser,
|
|
29
32
|
dataReturnType,
|
|
30
|
-
importPath,
|
|
33
|
+
importPath: importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0),
|
|
31
34
|
paramsType,
|
|
32
35
|
paramsCasing,
|
|
33
36
|
pathParamsType,
|
|
@@ -62,13 +65,15 @@ const pluginClient = (0, __kubb_core.definePlugin)((options) => {
|
|
|
62
65
|
const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
63
66
|
const oas = await this.getOas();
|
|
64
67
|
const baseURL$1 = await this.getBaseURL();
|
|
65
|
-
const
|
|
66
|
-
if (!this.plugin.options.importPath && !
|
|
67
|
-
baseName: "
|
|
68
|
-
path: node_path.default.resolve(root, ".kubb/
|
|
68
|
+
const containsFetch = this.fabric.files.some((file) => file.baseName === "fetch.ts");
|
|
69
|
+
if (bundle && !this.plugin.options.importPath && !containsFetch) await this.addFile({
|
|
70
|
+
baseName: "fetch.ts",
|
|
71
|
+
path: node_path.default.resolve(root, ".kubb/fetch.ts"),
|
|
69
72
|
sources: [{
|
|
70
|
-
name: "
|
|
71
|
-
value: (0, __kubb_core_utils.resolveModuleSource)(this.plugin.options.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source
|
|
73
|
+
name: "fetch",
|
|
74
|
+
value: (0, __kubb_core_utils.resolveModuleSource)(this.plugin.options.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source,
|
|
75
|
+
isExportable: true,
|
|
76
|
+
isIndexable: true
|
|
72
77
|
}]
|
|
73
78
|
});
|
|
74
79
|
const files = await new __kubb_plugin_oas.OperationGenerator(baseURL$1 ? {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","path","options","groupName: Group['name']","baseURL","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } 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 = definePlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n urlType = false,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || '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,\n contentType,\n } = options\n\n return {\n name: pluginClientName,\n options: {\n client,\n output,\n group,\n parser,\n dataReturnType,\n importPath,\n paramsType,\n paramsCasing,\n pathParamsType,\n baseURL,\n urlType,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n // pre add bundled
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","path","options","groupName: Group['name']","baseURL","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } 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 = definePlugin<PluginClient>((options) => {\n const bundle = options.bundle ?? false\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n urlType = false,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || '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,\n contentType,\n } = options\n\n const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)\n\n return {\n name: pluginClientName,\n options: {\n client,\n bundle,\n output,\n group,\n parser,\n dataReturnType,\n importPath: resolvedImportPath,\n paramsType,\n paramsCasing,\n pathParamsType,\n baseURL,\n urlType,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n // pre add bundled fetch\n const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')\n\n if (bundle && !this.plugin.options.importPath && !containsFetch) {\n await this.addFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(\n baseURL\n ? {\n ...this.plugin.options,\n baseURL,\n }\n : this.plugin.options,\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n 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 getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,mBAAmB;AAEhC,MAAa,8CAA2C,YAAY;CAClE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,EACJ,SAAS;EAAE,MAAM;EAAW,YAAY;EAAS,EACjD,OACA,UAAU,OACV,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,iBAAiB,QACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa,OACb,SACA,cACA,aAAa;EAACA;EAAiB,QAAQC,4CAAyB;EAAW,aAAaC,yCAAsB;EAAU,CAAC,OAAO,QAAQ,EACxI,SAAS,UACT,SAAS,SACT,YACA,gBACE;AAIJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA,YAXuB,eAAe,CAAC,SAAS,+BAA+B,WAAW;GAY1F;GACA;GACA;GACA;GACA;GACD;EACD,KAAK,CAACC,iCAAe,WAAW,QAAQC,kCAAgB,OAAU,CAAC,OAAO,QAAQ;EAClF,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,O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QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-
|
|
1
|
+
import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-ClSTrlYq.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginClientName = "plugin-client";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-
|
|
1
|
+
import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-B-Yse6Ey.js";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin.d.ts
|
|
4
4
|
declare const pluginClientName = "plugin-client";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./Operations-HWuo-D3O.js";
|
|
2
|
-
import { n as groupedClientGenerator, r as clientGenerator, t as operationsGenerator } from "./generators-
|
|
2
|
+
import { n as groupedClientGenerator, r as clientGenerator, t as operationsGenerator } from "./generators-DXO7Q8-4.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase } from "@kubb/core/transformers";
|
|
@@ -10,6 +10,7 @@ import { pluginZodName } from "@kubb/plugin-zod";
|
|
|
10
10
|
//#region src/plugin.ts
|
|
11
11
|
const pluginClientName = "plugin-client";
|
|
12
12
|
const pluginClient = definePlugin((options) => {
|
|
13
|
+
const bundle = options.bundle ?? false;
|
|
13
14
|
const { output = {
|
|
14
15
|
path: "clients",
|
|
15
16
|
barrelType: "named"
|
|
@@ -22,11 +23,12 @@ const pluginClient = definePlugin((options) => {
|
|
|
22
23
|
name: pluginClientName,
|
|
23
24
|
options: {
|
|
24
25
|
client,
|
|
26
|
+
bundle,
|
|
25
27
|
output,
|
|
26
28
|
group,
|
|
27
29
|
parser,
|
|
28
30
|
dataReturnType,
|
|
29
|
-
importPath,
|
|
31
|
+
importPath: importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0),
|
|
30
32
|
paramsType,
|
|
31
33
|
paramsCasing,
|
|
32
34
|
pathParamsType,
|
|
@@ -61,13 +63,15 @@ const pluginClient = definePlugin((options) => {
|
|
|
61
63
|
const mode = getMode(path.resolve(root, output.path));
|
|
62
64
|
const oas = await this.getOas();
|
|
63
65
|
const baseURL$1 = await this.getBaseURL();
|
|
64
|
-
const
|
|
65
|
-
if (!this.plugin.options.importPath && !
|
|
66
|
-
baseName: "
|
|
67
|
-
path: path.resolve(root, ".kubb/
|
|
66
|
+
const containsFetch = this.fabric.files.some((file) => file.baseName === "fetch.ts");
|
|
67
|
+
if (bundle && !this.plugin.options.importPath && !containsFetch) await this.addFile({
|
|
68
|
+
baseName: "fetch.ts",
|
|
69
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
68
70
|
sources: [{
|
|
69
|
-
name: "
|
|
70
|
-
value: resolveModuleSource(this.plugin.options.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source
|
|
71
|
+
name: "fetch",
|
|
72
|
+
value: resolveModuleSource(this.plugin.options.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source,
|
|
73
|
+
isExportable: true,
|
|
74
|
+
isIndexable: true
|
|
71
75
|
}]
|
|
72
76
|
});
|
|
73
77
|
const files = await new OperationGenerator(baseURL$1 ? {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']","baseURL"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } 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 = definePlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n urlType = false,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || '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,\n contentType,\n } = options\n\n return {\n name: pluginClientName,\n options: {\n client,\n output,\n group,\n parser,\n dataReturnType,\n importPath,\n paramsType,\n paramsCasing,\n pathParamsType,\n baseURL,\n urlType,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n // pre add bundled
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']","baseURL"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } 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 = definePlugin<PluginClient>((options) => {\n const bundle = options.bundle ?? false\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n urlType = false,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || '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,\n contentType,\n } = options\n\n const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)\n\n return {\n name: pluginClientName,\n options: {\n client,\n bundle,\n output,\n group,\n parser,\n dataReturnType,\n importPath: resolvedImportPath,\n paramsType,\n paramsCasing,\n pathParamsType,\n baseURL,\n urlType,\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 ?? 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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n const baseURL = await this.getBaseURL()\n\n // pre add bundled fetch\n const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')\n\n if (bundle && !this.plugin.options.importPath && !containsFetch) {\n await this.addFile({\n baseName: 'fetch.ts',\n path: path.resolve(root, '.kubb/fetch.ts'),\n sources: [\n {\n name: 'fetch',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n isExportable: true,\n isIndexable: true,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(\n baseURL\n ? {\n ...this.plugin.options,\n baseURL,\n }\n : this.plugin.options,\n {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n 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 getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;AAWA,MAAa,mBAAmB;AAEhC,MAAa,eAAe,cAA4B,YAAY;CAClE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,EACJ,SAAS;EAAE,MAAM;EAAW,YAAY;EAAS,EACjD,OACA,UAAU,OACV,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,iBAAiB,QACjB,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,aAAa,OACb,SACA,cACA,aAAa;EAAC;EAAiB,QAAQ,yBAAyB;EAAW,aAAa,sBAAsB;EAAU,CAAC,OAAO,QAAQ,EACxI,SAAS,UACT,SAAS,SACT,YACA,gBACE;AAIJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA,YAXuB,eAAe,CAAC,SAAS,+BAA+B,WAAW;GAY1F;GACA;GACA;GACA;GACA;GACD;EACD,KAAK,CAAC,eAAe,WAAW,QAAQ,gBAAgB,OAAU,CAAC,OAAO,QAAQ;EAClF,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAO,KAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUA,WAAS,OAA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,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CACF,CAEsC,MAAM,GAAG,WAAW;AAE3D,SAAM,KAAK,QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
1
2
|
import * as OasTypes from "oas/types";
|
|
2
3
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
3
4
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -5,7 +6,6 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
6
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
7
|
import BaseOas from "oas";
|
|
7
8
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -1087,6 +1087,12 @@ type Options$1 = {
|
|
|
1087
1087
|
* @default 'axios'
|
|
1088
1088
|
*/
|
|
1089
1089
|
client?: 'axios' | 'fetch';
|
|
1090
|
+
/**
|
|
1091
|
+
* Bundle the selected client into the generated `.kubb` directory.
|
|
1092
|
+
* When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
|
|
1093
|
+
* @default false
|
|
1094
|
+
*/
|
|
1095
|
+
bundle?: boolean;
|
|
1090
1096
|
transformers?: {
|
|
1091
1097
|
/**
|
|
1092
1098
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -1103,6 +1109,7 @@ type ResolvedOptions = {
|
|
|
1103
1109
|
group?: Options$1['group'];
|
|
1104
1110
|
baseURL: string | undefined;
|
|
1105
1111
|
client: Options$1['client'];
|
|
1112
|
+
bundle: boolean;
|
|
1106
1113
|
parser: NonNullable<Options$1['parser']>;
|
|
1107
1114
|
urlType: NonNullable<Options$1['urlType']>;
|
|
1108
1115
|
importPath: Options$1['importPath'];
|
|
@@ -1114,4 +1121,4 @@ type ResolvedOptions = {
|
|
|
1114
1121
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1115
1122
|
//#endregion
|
|
1116
1123
|
export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options$1 as t };
|
|
1117
|
-
//# sourceMappingURL=types-
|
|
1124
|
+
//# sourceMappingURL=types-B-Yse6Ey.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
1
|
import * as OasTypes from "oas/types";
|
|
3
2
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
4
3
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -6,6 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
6
5
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
7
6
|
import BaseOas from "oas";
|
|
8
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
9
9
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
11
|
|
|
@@ -1087,6 +1087,12 @@ type Options$1 = {
|
|
|
1087
1087
|
* @default 'axios'
|
|
1088
1088
|
*/
|
|
1089
1089
|
client?: 'axios' | 'fetch';
|
|
1090
|
+
/**
|
|
1091
|
+
* Bundle the selected client into the generated `.kubb` directory.
|
|
1092
|
+
* When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
|
|
1093
|
+
* @default false
|
|
1094
|
+
*/
|
|
1095
|
+
bundle?: boolean;
|
|
1090
1096
|
transformers?: {
|
|
1091
1097
|
/**
|
|
1092
1098
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -1103,6 +1109,7 @@ type ResolvedOptions = {
|
|
|
1103
1109
|
group?: Options$1['group'];
|
|
1104
1110
|
baseURL: string | undefined;
|
|
1105
1111
|
client: Options$1['client'];
|
|
1112
|
+
bundle: boolean;
|
|
1106
1113
|
parser: NonNullable<Options$1['parser']>;
|
|
1107
1114
|
urlType: NonNullable<Options$1['urlType']>;
|
|
1108
1115
|
importPath: Options$1['importPath'];
|
|
@@ -1114,4 +1121,4 @@ type ResolvedOptions = {
|
|
|
1114
1121
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions, never, ResolvePathOptions>;
|
|
1115
1122
|
//#endregion
|
|
1116
1123
|
export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options$1 as t };
|
|
1117
|
-
//# sourceMappingURL=types-
|
|
1124
|
+
//# sourceMappingURL=types-ClSTrlYq.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.8",
|
|
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",
|
|
@@ -39,6 +39,14 @@
|
|
|
39
39
|
"import": "./dist/generators.js",
|
|
40
40
|
"require": "./dist/generators.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./clients/axios": {
|
|
43
|
+
"import": "./dist/clients/axios.js",
|
|
44
|
+
"require": "./dist/clients/axios.cjs"
|
|
45
|
+
},
|
|
46
|
+
"./clients/fetch": {
|
|
47
|
+
"import": "./dist/clients/fetch.js",
|
|
48
|
+
"require": "./dist/clients/fetch.cjs"
|
|
49
|
+
},
|
|
42
50
|
"./templates/*": "./templates/*",
|
|
43
51
|
"./package.json": "./package.json"
|
|
44
52
|
},
|
|
@@ -52,6 +60,12 @@
|
|
|
52
60
|
],
|
|
53
61
|
"generators": [
|
|
54
62
|
"./dist/generators.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"clients/axios": [
|
|
65
|
+
"./dist/clients/axios.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"clients/fetch": [
|
|
68
|
+
"./dist/clients/fetch.d.ts"
|
|
55
69
|
]
|
|
56
70
|
}
|
|
57
71
|
},
|
|
@@ -74,11 +88,11 @@
|
|
|
74
88
|
"dependencies": {
|
|
75
89
|
"@kubb/react-fabric": "0.2.19",
|
|
76
90
|
"jiti": "^2.6.1",
|
|
77
|
-
"@kubb/core": "4.5.
|
|
78
|
-
"@kubb/oas": "4.5.
|
|
79
|
-
"@kubb/plugin-oas": "4.5.
|
|
80
|
-
"@kubb/plugin-ts": "4.5.
|
|
81
|
-
"@kubb/plugin-zod": "4.5.
|
|
91
|
+
"@kubb/core": "4.5.8",
|
|
92
|
+
"@kubb/oas": "4.5.8",
|
|
93
|
+
"@kubb/plugin-oas": "4.5.8",
|
|
94
|
+
"@kubb/plugin-ts": "4.5.8",
|
|
95
|
+
"@kubb/plugin-zod": "4.5.8"
|
|
82
96
|
},
|
|
83
97
|
"devDependencies": {
|
|
84
98
|
"axios": "^1.13.2"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AxiosError, AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
|
|
4
|
+
declare const AXIOS_BASE: string
|
|
5
|
+
declare const AXIOS_HEADERS: string
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Subset of AxiosRequestConfig
|
|
9
|
+
*/
|
|
10
|
+
export type RequestConfig<TData = unknown> = {
|
|
11
|
+
baseURL?: string
|
|
12
|
+
url?: string
|
|
13
|
+
method?: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD'
|
|
14
|
+
params?: unknown
|
|
15
|
+
data?: TData | FormData
|
|
16
|
+
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
|
|
17
|
+
signal?: AbortSignal
|
|
18
|
+
validateStatus?: (status: number) => boolean
|
|
19
|
+
headers?: AxiosRequestConfig['headers']
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Subset of AxiosResponse
|
|
24
|
+
*/
|
|
25
|
+
export type ResponseConfig<TData = unknown> = {
|
|
26
|
+
data: TData
|
|
27
|
+
status: number
|
|
28
|
+
statusText: string
|
|
29
|
+
headers: AxiosResponse['headers']
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ResponseErrorConfig<TError = unknown> = AxiosError<TError>
|
|
33
|
+
|
|
34
|
+
let _config: Partial<RequestConfig> = {
|
|
35
|
+
baseURL: typeof AXIOS_BASE !== 'undefined' ? AXIOS_BASE : undefined,
|
|
36
|
+
headers: typeof AXIOS_HEADERS !== 'undefined' ? (JSON.parse(AXIOS_HEADERS) as AxiosHeaders) : undefined,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const getConfig = () => _config
|
|
40
|
+
|
|
41
|
+
export const setConfig = (config: RequestConfig) => {
|
|
42
|
+
_config = config
|
|
43
|
+
return getConfig()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const axiosInstance = axios.create(getConfig())
|
|
47
|
+
|
|
48
|
+
export const client = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
|
|
49
|
+
const globalConfig = getConfig()
|
|
50
|
+
|
|
51
|
+
return axiosInstance
|
|
52
|
+
.request<TData, ResponseConfig<TData>>({
|
|
53
|
+
...globalConfig,
|
|
54
|
+
...config,
|
|
55
|
+
headers: {
|
|
56
|
+
...globalConfig.headers,
|
|
57
|
+
...config.headers,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.catch((e: AxiosError<TError>) => {
|
|
61
|
+
throw e
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
client.getConfig = getConfig
|
|
66
|
+
client.setConfig = setConfig
|
|
67
|
+
|
|
68
|
+
export default client
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestCredentials
|
|
3
|
+
*/
|
|
4
|
+
export type RequestCredentials = 'omit' | 'same-origin' | 'include'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Subset of FetchRequestConfig
|
|
8
|
+
*/
|
|
9
|
+
export type RequestConfig<TData = unknown> = {
|
|
10
|
+
baseURL?: string
|
|
11
|
+
url?: string
|
|
12
|
+
method?: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD'
|
|
13
|
+
params?: unknown
|
|
14
|
+
data?: TData | FormData
|
|
15
|
+
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
|
|
16
|
+
signal?: AbortSignal
|
|
17
|
+
headers?: [string, string][] | Record<string, string>
|
|
18
|
+
credentials?: RequestCredentials
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Subset of FetchResponse
|
|
23
|
+
*/
|
|
24
|
+
export type ResponseConfig<TData = unknown> = {
|
|
25
|
+
data: TData
|
|
26
|
+
status: number
|
|
27
|
+
statusText: string
|
|
28
|
+
headers: Headers
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let _config: Partial<RequestConfig> = {}
|
|
32
|
+
|
|
33
|
+
export const getConfig = () => _config
|
|
34
|
+
|
|
35
|
+
export const setConfig = (config: Partial<RequestConfig>) => {
|
|
36
|
+
_config = config
|
|
37
|
+
return getConfig()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ResponseErrorConfig<TError = unknown> = TError
|
|
41
|
+
|
|
42
|
+
export const client = async <TData, _TError = unknown, TVariables = unknown>(paramsConfig: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
|
|
43
|
+
const normalizedParams = new URLSearchParams()
|
|
44
|
+
|
|
45
|
+
const globalConfig = getConfig()
|
|
46
|
+
const config = { ...globalConfig, ...paramsConfig }
|
|
47
|
+
|
|
48
|
+
Object.entries(config.params || {}).forEach(([key, value]) => {
|
|
49
|
+
if (value !== undefined) {
|
|
50
|
+
normalizedParams.append(key, value === null ? 'null' : value.toString())
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let targetUrl = [config.baseURL, config.url].filter(Boolean).join('')
|
|
55
|
+
|
|
56
|
+
if (config.params) {
|
|
57
|
+
targetUrl += `?${normalizedParams}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const response = await fetch(targetUrl, {
|
|
61
|
+
credentials: config.credentials || 'same-origin',
|
|
62
|
+
method: config.method?.toUpperCase(),
|
|
63
|
+
body: JSON.stringify(config.data),
|
|
64
|
+
signal: config.signal,
|
|
65
|
+
headers: config.headers,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const data = [204, 205, 304].includes(response.status) || !response.body ? {} : await response.json()
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
data: data as TData,
|
|
72
|
+
status: response.status,
|
|
73
|
+
statusText: response.statusText,
|
|
74
|
+
headers: response.headers as Headers,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
client.getConfig = getConfig
|
|
79
|
+
client.setConfig = setConfig
|
|
80
|
+
|
|
81
|
+
export default client
|
|
@@ -57,11 +57,11 @@ export const clientGenerator = createReactGenerator<PluginClient>({
|
|
|
57
57
|
</>
|
|
58
58
|
) : (
|
|
59
59
|
<>
|
|
60
|
-
<File.Import name={'fetch'} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/
|
|
60
|
+
<File.Import name={['fetch']} root={client.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')} />
|
|
61
61
|
<File.Import
|
|
62
62
|
name={['RequestConfig', 'ResponseErrorConfig']}
|
|
63
63
|
root={client.file.path}
|
|
64
|
-
path={path.resolve(config.root, config.output.path, '.kubb/
|
|
64
|
+
path={path.resolve(config.root, config.output.path, '.kubb/fetch.ts')}
|
|
65
65
|
isTypeOnly
|
|
66
66
|
/>
|
|
67
67
|
</>
|
package/src/plugin.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { PluginClient } from './types.ts'
|
|
|
12
12
|
export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
|
|
13
13
|
|
|
14
14
|
export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
15
|
+
const bundle = options.bundle ?? false
|
|
15
16
|
const {
|
|
16
17
|
output = { path: 'clients', barrelType: 'named' },
|
|
17
18
|
group,
|
|
@@ -33,15 +34,18 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
|
33
34
|
contentType,
|
|
34
35
|
} = options
|
|
35
36
|
|
|
37
|
+
const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : undefined)
|
|
38
|
+
|
|
36
39
|
return {
|
|
37
40
|
name: pluginClientName,
|
|
38
41
|
options: {
|
|
39
42
|
client,
|
|
43
|
+
bundle,
|
|
40
44
|
output,
|
|
41
45
|
group,
|
|
42
46
|
parser,
|
|
43
47
|
dataReturnType,
|
|
44
|
-
importPath,
|
|
48
|
+
importPath: resolvedImportPath,
|
|
45
49
|
paramsType,
|
|
46
50
|
paramsCasing,
|
|
47
51
|
pathParamsType,
|
|
@@ -98,19 +102,21 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
|
98
102
|
const oas = await this.getOas()
|
|
99
103
|
const baseURL = await this.getBaseURL()
|
|
100
104
|
|
|
101
|
-
// pre add bundled
|
|
102
|
-
const
|
|
105
|
+
// pre add bundled fetch
|
|
106
|
+
const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')
|
|
103
107
|
|
|
104
|
-
if (!this.plugin.options.importPath && !
|
|
108
|
+
if (bundle && !this.plugin.options.importPath && !containsFetch) {
|
|
105
109
|
await this.addFile({
|
|
106
|
-
baseName: '
|
|
107
|
-
path: path.resolve(root, '.kubb/
|
|
110
|
+
baseName: 'fetch.ts',
|
|
111
|
+
path: path.resolve(root, '.kubb/fetch.ts'),
|
|
108
112
|
sources: [
|
|
109
113
|
{
|
|
110
|
-
name: '
|
|
114
|
+
name: 'fetch',
|
|
111
115
|
value: resolveModuleSource(
|
|
112
116
|
this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',
|
|
113
117
|
).source,
|
|
118
|
+
isExportable: true,
|
|
119
|
+
isIndexable: true,
|
|
114
120
|
},
|
|
115
121
|
],
|
|
116
122
|
})
|
package/src/types.ts
CHANGED
|
@@ -92,6 +92,12 @@ export type Options = {
|
|
|
92
92
|
* @default 'axios'
|
|
93
93
|
*/
|
|
94
94
|
client?: 'axios' | 'fetch'
|
|
95
|
+
/**
|
|
96
|
+
* Bundle the selected client into the generated `.kubb` directory.
|
|
97
|
+
* When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
bundle?: boolean
|
|
95
101
|
transformers?: {
|
|
96
102
|
/**
|
|
97
103
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -109,6 +115,7 @@ type ResolvedOptions = {
|
|
|
109
115
|
group?: Options['group']
|
|
110
116
|
baseURL: string | undefined
|
|
111
117
|
client: Options['client']
|
|
118
|
+
bundle: boolean
|
|
112
119
|
parser: NonNullable<Options['parser']>
|
|
113
120
|
urlType: NonNullable<Options['urlType']>
|
|
114
121
|
importPath: Options['importPath']
|