@kubb/plugin-client 4.5.1 → 4.5.2

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.
@@ -1,4 +1,4 @@
1
- import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-DQTXVaz_.cjs";
1
+ import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-DiIa8Yvy.cjs";
2
2
  import { FunctionParams } from "@kubb/react-fabric";
3
3
  import { KubbNode } from "@kubb/react-fabric/types";
4
4
 
@@ -1,4 +1,4 @@
1
- import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-BI2oGQis.js";
1
+ import { i as OperationSchemas, n as PluginClient, o as Operation } from "./types-DX8qQX3E.js";
2
2
  import { FunctionParams } from "@kubb/react-fabric";
3
3
  import { KubbNode } from "@kubb/react-fabric/types";
4
4
 
@@ -1,4 +1,4 @@
1
- import { n as PluginClient, r as ReactGenerator } from "./types-DQTXVaz_.cjs";
1
+ import { n as PluginClient, r as ReactGenerator } from "./types-DiIa8Yvy.cjs";
2
2
 
3
3
  //#region src/generators/clientGenerator.d.ts
4
4
  declare const clientGenerator: ReactGenerator<PluginClient>;
@@ -1,4 +1,4 @@
1
- import { n as PluginClient, r as ReactGenerator } from "./types-BI2oGQis.js";
1
+ import { n as PluginClient, r as ReactGenerator } from "./types-DX8qQX3E.js";
2
2
 
3
3
  //#region src/generators/clientGenerator.d.ts
4
4
  declare const clientGenerator: ReactGenerator<PluginClient>;
package/dist/index.cjs CHANGED
@@ -15,7 +15,7 @@ __kubb_plugin_zod = require_Operations.__toESM(__kubb_plugin_zod);
15
15
 
16
16
  //#region src/plugin.ts
17
17
  const pluginClientName = "plugin-client";
18
- const pluginClient = (0, __kubb_core.createPlugin)((options) => {
18
+ const pluginClient = (0, __kubb_core.definePlugin)((options) => {
19
19
  const { output = {
20
20
  path: "clients",
21
21
  barrelType: "named"
@@ -62,13 +62,12 @@ const pluginClient = (0, __kubb_core.createPlugin)((options) => {
62
62
  if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
63
63
  return resolvedName;
64
64
  },
65
- async buildStart() {
66
- const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
67
- const oas = await swaggerPlugin.context.getOas();
65
+ async install() {
68
66
  const root = node_path.default.resolve(this.config.root, this.config.output.path);
69
67
  const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
70
- const baseURL$1 = await swaggerPlugin.context.getBaseURL();
71
- const containsFetcher = this.fileManager.files.some((file) => file.baseName === "fetcher.ts");
68
+ const oas = await this.getOas();
69
+ const baseURL$1 = await this.getBaseURL();
70
+ const containsFetcher = this.fabric.files.some((file) => file.baseName === "fetcher.ts");
72
71
  if (!this.plugin.options.importPath && !containsFetcher) await this.addFile({
73
72
  baseName: "fetcher.ts",
74
73
  path: node_path.default.resolve(root, ".kubb/fetcher.ts"),
@@ -92,7 +91,7 @@ const pluginClient = (0, __kubb_core.createPlugin)((options) => {
92
91
  mode
93
92
  }).build(...generators);
94
93
  await this.addFile(...files);
95
- const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fileManager.files, {
94
+ const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fabric.files, {
96
95
  type: output.barrelType ?? "named",
97
96
  root,
98
97
  output,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","path","options","groupName: Group['name']","PluginManager","baseURL","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 = createPlugin<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 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 = getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n // pre add bundled fetcher\n const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.importPath && !containsFetcher) {\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\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.fileManager.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":";;;;;;;;;;;;;;;;AAYA,MAAa,mBAAmB;AAEhC,MAAa,8CAA2C,YAAY;CAClE,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;EAA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AO,KAAK;GACpE,MAAM,gCAAeA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAMI,YAAU,MAAM,cAAc,QAAQ,YAAY;GAGxD,MAAM,kBAAkB,KAAK,YAAY,MAAM,MAAM,SAAS,KAAK,aAAa,aAAa;AAE7F,OAAI,CAAC,KAAK,OAAO,QAAQ,cAAc,CAAC,gBACtC,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMJ,kBAAK,QAAQ,MAAM,mBAAmB;IAC5C,SAAS,CACP;KACE,MAAM;KACN,kDACE,KAAK,OAAO,QAAQ,WAAW,UAAU,gDAAgD,8CAC1F,CAAC;KACH,CACF;IACF,CAAC;GAuBJ,MAAM,QAAQ,MApBa,IAAIK,qCAC7BD,YACI;IACE,GAAG,KAAK,OAAO;IACf;IACD,GACD,KAAK,OAAO,SAChB;IACE,QAAQ,KAAK;IACb;IACA,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,sCAAqB,KAAK,YAAY,OAAO;IAC/D,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
+ {"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 fetcher\n const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.importPath && !containsFetcher) {\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\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,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;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GAC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c,CAAC,gBACtC,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMH,kBAAK,QAAQ,MAAM,mBAAmB;IAC5C,SAAS,CACP;KACE,MAAM;KACN,kDACE,KAAK,OAAO,QAAQ,WAAW,UAAU,gDAAgD,8CAC1F,CAAC;KACH,CACF;IACF,CAAC;GAuBJ,MAAM,QAAQ,MApBa,IAAII,qCAC7BD,YACI;IACE,GAAG,KAAK,OAAO;IACf;IACD,GACD,KAAK,OAAO,SAChB;IACE,QAAQ,KAAK;IACb;IACA,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,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-DQTXVaz_.cjs";
1
+ import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-DiIa8Yvy.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-BI2oGQis.js";
1
+ import { a as UserPluginWithLifeCycle, n as PluginClient, t as Options } from "./types-DX8qQX3E.js";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginClientName = "plugin-client";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./Operations-HWuo-D3O.js";
2
2
  import { n as groupedClientGenerator, r as clientGenerator, t as operationsGenerator } from "./generators-CQvDx6Mq.js";
3
3
  import path from "node:path";
4
- import { PluginManager, createPlugin, getBarrelFiles, getMode } from "@kubb/core";
4
+ import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
5
5
  import { camelCase } from "@kubb/core/transformers";
6
6
  import { resolveModuleSource } from "@kubb/core/utils";
7
7
  import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
@@ -9,7 +9,7 @@ import { pluginZodName } from "@kubb/plugin-zod";
9
9
 
10
10
  //#region src/plugin.ts
11
11
  const pluginClientName = "plugin-client";
12
- const pluginClient = createPlugin((options) => {
12
+ const pluginClient = definePlugin((options) => {
13
13
  const { output = {
14
14
  path: "clients",
15
15
  barrelType: "named"
@@ -56,13 +56,12 @@ const pluginClient = createPlugin((options) => {
56
56
  if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
57
57
  return resolvedName;
58
58
  },
59
- async buildStart() {
60
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
61
- const oas = await swaggerPlugin.context.getOas();
59
+ async install() {
62
60
  const root = path.resolve(this.config.root, this.config.output.path);
63
61
  const mode = getMode(path.resolve(root, output.path));
64
- const baseURL$1 = await swaggerPlugin.context.getBaseURL();
65
- const containsFetcher = this.fileManager.files.some((file) => file.baseName === "fetcher.ts");
62
+ const oas = await this.getOas();
63
+ const baseURL$1 = await this.getBaseURL();
64
+ const containsFetcher = this.fabric.files.some((file) => file.baseName === "fetcher.ts");
66
65
  if (!this.plugin.options.importPath && !containsFetcher) await this.addFile({
67
66
  baseName: "fetcher.ts",
68
67
  path: path.resolve(root, ".kubb/fetcher.ts"),
@@ -86,7 +85,7 @@ const pluginClient = createPlugin((options) => {
86
85
  mode
87
86
  }).build(...generators);
88
87
  await this.addFile(...files);
89
- const barrelFiles = await getBarrelFiles(this.fileManager.files, {
88
+ const barrelFiles = await getBarrelFiles(this.fabric.files, {
90
89
  type: output.barrelType ?? "named",
91
90
  root,
92
91
  output,
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 { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 = createPlugin<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 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 = getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n // pre add bundled fetcher\n const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.importPath && !containsFetcher) {\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\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.fileManager.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":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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 fetcher\n const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.importPath && !containsFetcher) {\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\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,EACJ,SAAS;EAAE,MAAM;EAAW,YAAY;EAAS,EACjD,OACA,UAAU,OACV,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB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OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAC/B,MAAME,YAAU,MAAM,KAAK,YAAY;GAGvC,MAAM,kBAAkB,KAAK,OAAO,MAAM,MAAM,SAAS,KAAK,aAAa,aAAa;AAExF,OAAI,CAAC,KAAK,OAAO,QAAQ,cAAc,CAAC,gBACtC,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,mBAAmB;IAC5C,SAAS,CACP;KACE,MAAM;KACN,OAAO,oBACL,KAAK,OAAO,QAAQ,WAAW,UAAU,gDAAgD,8CAC1F,CAAC;KACH,CACF;IACF,CAAC;GAuBJ,MAAM,QAAQ,MApBa,IAAI,mBAC7BA,YACI;IACE,GAAG,KAAK,OAAO;IACf;IACD,GACD,KAAK,OAAO,SAChB;IACE,QAAQ,KAAK;IACb;IACA,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,4 +1,4 @@
1
- import { Fabric, FileManager } from "@kubb/react-fabric";
1
+ import { Fabric } from "@kubb/react-fabric";
2
2
  import * as OasTypes from "oas/types";
3
3
  import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
4
4
  import { Operation, Operation as Operation$1 } from "oas/operation";
@@ -110,6 +110,21 @@ type Logger = {
110
110
  type PossiblePromise<T> = Promise<T> | T;
111
111
  //#endregion
112
112
  //#region ../core/src/types.d.ts
113
+ declare global {
114
+ namespace Kubb {
115
+ interface PluginContext {}
116
+ }
117
+ }
118
+ /**
119
+ * Config used in `kubb.config.ts`
120
+ *
121
+ * @example
122
+ * import { defineConfig } from '@kubb/core'
123
+ * export default defineConfig({
124
+ * ...
125
+ * })
126
+ */
127
+
113
128
  type InputPath = {
114
129
  /**
115
130
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
264
279
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
265
280
  */
266
281
  post?: Array<string>;
267
- } & (TOptions['context'] extends never ? {
268
- context?: never;
269
- } : {
270
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
271
- });
282
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
283
+ };
272
284
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
273
285
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
274
286
  /**
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
294
306
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
295
307
  */
296
308
  options: TOptions['resolvedOptions'];
297
- } & (TOptions['context'] extends never ? {
298
- context?: never;
299
- } : {
300
- context: TOptions['context'];
301
- });
309
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
310
+ /**
311
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
312
+ */
313
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
314
+ };
302
315
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
303
316
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
304
317
  /**
305
318
  * Start of the lifecycle of a plugin.
306
319
  * @type hookParallel
307
320
  */
308
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
321
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
309
322
  /**
310
323
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
311
324
  * Options can als be included.
312
325
  * @type hookFirst
313
326
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
314
327
  */
315
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
328
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
316
329
  /**
317
330
  * Resolve to a name based on a string.
318
331
  * Useful when converting to PascalCase or camelCase.
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
320
333
  * @example ('pet') => 'Pet'
321
334
  */
322
335
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
323
- /**
324
- * End of the plugin lifecycle.
325
- * @type hookParallel
326
- */
327
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
328
336
  };
329
337
  type PluginLifecycleHooks = keyof PluginLifecycle;
330
338
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -351,24 +359,15 @@ type ResolveNameParams = {
351
359
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
352
360
  fabric: Fabric;
353
361
  config: Config;
354
- /**
355
- * @deprecated
356
- */
357
- fileManager: FileManager;
358
362
  pluginManager: PluginManager;
359
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
360
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
361
- resolveName: (params: ResolveNameParams) => string;
363
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
362
364
  logger: Logger;
363
- /**
364
- * All plugins
365
- */
366
- plugins: Plugin[];
365
+ mode: KubbFile.Mode;
367
366
  /**
368
367
  * Current plugin
369
368
  */
370
369
  plugin: Plugin<TOptions>;
371
- };
370
+ } & Kubb.PluginContext;
372
371
  /**
373
372
  * Specify the export location for the files and define the behavior of the output
374
373
  */
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
443
442
  };
444
443
  declare class PluginManager {
445
444
  #private;
446
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
447
445
  readonly events: EventEmitter<Events>;
448
446
  readonly config: Config;
449
447
  readonly executed: Array<Executer>;
450
448
  readonly logger: Logger;
451
449
  readonly options: Options$2;
452
450
  constructor(config: Config, options: Options$2);
451
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
452
+ get plugins(): Array<Plugin>;
453
453
  getFile<TOptions = object>({
454
454
  name,
455
455
  mode,
@@ -459,7 +459,7 @@ declare class PluginManager {
459
459
  }: GetFileProps<TOptions>): KubbFile.File<{
460
460
  pluginKey: Plugin['key'];
461
461
  }>;
462
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
462
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
463
463
  resolveName: (params: ResolveNameParams) => string;
464
464
  /**
465
465
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -547,11 +547,9 @@ declare class PluginManager {
547
547
  }): Promise<void>;
548
548
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
549
549
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
550
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
551
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
552
550
  }
553
551
  //#endregion
554
- //#region ../core/src/FileManager.d.ts
552
+ //#region ../core/src/utils/getBarrelFiles.d.ts
555
553
  type FileMetaBase = {
556
554
  pluginKey?: Plugin['key'];
557
555
  };
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
669
667
  /**
670
668
  * Full qualified path.
671
669
  */
672
- path: KubbFile.OptionalPath;
670
+ path: KubbFile.Path;
673
671
  /**
674
672
  * When true `File.Import` will be used.
675
673
  * When false a reference will be used inside the current file.
@@ -774,6 +772,15 @@ type Schema = {
774
772
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
775
773
  //#endregion
776
774
  //#region ../plugin-oas/src/types.d.ts
775
+ type Context$2 = {
776
+ getOas(): Promise<Oas>;
777
+ getBaseURL(): Promise<string | undefined>;
778
+ };
779
+ declare global {
780
+ namespace Kubb {
781
+ interface PluginContext extends Context$2 {}
782
+ }
783
+ }
777
784
  type ResolvePathOptions = {
778
785
  pluginKey?: Plugin['key'];
779
786
  group?: {
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
794
801
  type Ref = {
795
802
  propertyName: string;
796
803
  originalName: string;
797
- path: KubbFile.OptionalPath;
804
+ path: KubbFile.Path;
798
805
  pluginKey?: Plugin['key'];
799
806
  };
800
807
  type Refs = Record<string, Ref>;
@@ -1107,4 +1114,4 @@ type ResolvedOptions = {
1107
1114
  type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1108
1115
  //#endregion
1109
1116
  export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options$1 as t };
1110
- //# sourceMappingURL=types-BI2oGQis.d.ts.map
1117
+ //# sourceMappingURL=types-DX8qQX3E.d.ts.map
@@ -5,7 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
5
5
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
6
6
  import BaseOas from "oas";
7
7
  import { KubbFile } from "@kubb/fabric-core/types";
8
- import { Fabric, FileManager } from "@kubb/react-fabric";
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
 
@@ -110,6 +110,21 @@ type Logger = {
110
110
  type PossiblePromise<T> = Promise<T> | T;
111
111
  //#endregion
112
112
  //#region ../core/src/types.d.ts
113
+ declare global {
114
+ namespace Kubb {
115
+ interface PluginContext {}
116
+ }
117
+ }
118
+ /**
119
+ * Config used in `kubb.config.ts`
120
+ *
121
+ * @example
122
+ * import { defineConfig } from '@kubb/core'
123
+ * export default defineConfig({
124
+ * ...
125
+ * })
126
+ */
127
+
113
128
  type InputPath = {
114
129
  /**
115
130
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -264,11 +279,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
264
279
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
265
280
  */
266
281
  post?: Array<string>;
267
- } & (TOptions['context'] extends never ? {
268
- context?: never;
269
- } : {
270
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
271
- });
282
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
283
+ };
272
284
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
273
285
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
274
286
  /**
@@ -294,25 +306,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
294
306
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
295
307
  */
296
308
  options: TOptions['resolvedOptions'];
297
- } & (TOptions['context'] extends never ? {
298
- context?: never;
299
- } : {
300
- context: TOptions['context'];
301
- });
309
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
310
+ /**
311
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
312
+ */
313
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
314
+ };
302
315
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
303
316
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
304
317
  /**
305
318
  * Start of the lifecycle of a plugin.
306
319
  * @type hookParallel
307
320
  */
308
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
321
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
309
322
  /**
310
323
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
311
324
  * Options can als be included.
312
325
  * @type hookFirst
313
326
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
314
327
  */
315
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
328
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
316
329
  /**
317
330
  * Resolve to a name based on a string.
318
331
  * Useful when converting to PascalCase or camelCase.
@@ -320,11 +333,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
320
333
  * @example ('pet') => 'Pet'
321
334
  */
322
335
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
323
- /**
324
- * End of the plugin lifecycle.
325
- * @type hookParallel
326
- */
327
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
328
336
  };
329
337
  type PluginLifecycleHooks = keyof PluginLifecycle;
330
338
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -351,24 +359,15 @@ type ResolveNameParams = {
351
359
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
352
360
  fabric: Fabric;
353
361
  config: Config;
354
- /**
355
- * @deprecated
356
- */
357
- fileManager: FileManager;
358
362
  pluginManager: PluginManager;
359
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
360
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
361
- resolveName: (params: ResolveNameParams) => string;
363
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
362
364
  logger: Logger;
363
- /**
364
- * All plugins
365
- */
366
- plugins: Plugin[];
365
+ mode: KubbFile.Mode;
367
366
  /**
368
367
  * Current plugin
369
368
  */
370
369
  plugin: Plugin<TOptions>;
371
- };
370
+ } & Kubb.PluginContext;
372
371
  /**
373
372
  * Specify the export location for the files and define the behavior of the output
374
373
  */
@@ -443,13 +442,14 @@ type GetFileProps<TOptions = object> = {
443
442
  };
444
443
  declare class PluginManager {
445
444
  #private;
446
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
447
445
  readonly events: EventEmitter<Events>;
448
446
  readonly config: Config;
449
447
  readonly executed: Array<Executer>;
450
448
  readonly logger: Logger;
451
449
  readonly options: Options$2;
452
450
  constructor(config: Config, options: Options$2);
451
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
452
+ get plugins(): Array<Plugin>;
453
453
  getFile<TOptions = object>({
454
454
  name,
455
455
  mode,
@@ -459,7 +459,7 @@ declare class PluginManager {
459
459
  }: GetFileProps<TOptions>): KubbFile.File<{
460
460
  pluginKey: Plugin['key'];
461
461
  }>;
462
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
462
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
463
463
  resolveName: (params: ResolveNameParams) => string;
464
464
  /**
465
465
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -547,11 +547,9 @@ declare class PluginManager {
547
547
  }): Promise<void>;
548
548
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
549
549
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
550
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
551
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
552
550
  }
553
551
  //#endregion
554
- //#region ../core/src/FileManager.d.ts
552
+ //#region ../core/src/utils/getBarrelFiles.d.ts
555
553
  type FileMetaBase = {
556
554
  pluginKey?: Plugin['key'];
557
555
  };
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
669
667
  /**
670
668
  * Full qualified path.
671
669
  */
672
- path: KubbFile.OptionalPath;
670
+ path: KubbFile.Path;
673
671
  /**
674
672
  * When true `File.Import` will be used.
675
673
  * When false a reference will be used inside the current file.
@@ -774,6 +772,15 @@ type Schema = {
774
772
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
775
773
  //#endregion
776
774
  //#region ../plugin-oas/src/types.d.ts
775
+ type Context$2 = {
776
+ getOas(): Promise<Oas>;
777
+ getBaseURL(): Promise<string | undefined>;
778
+ };
779
+ declare global {
780
+ namespace Kubb {
781
+ interface PluginContext extends Context$2 {}
782
+ }
783
+ }
777
784
  type ResolvePathOptions = {
778
785
  pluginKey?: Plugin['key'];
779
786
  group?: {
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
794
801
  type Ref = {
795
802
  propertyName: string;
796
803
  originalName: string;
797
- path: KubbFile.OptionalPath;
804
+ path: KubbFile.Path;
798
805
  pluginKey?: Plugin['key'];
799
806
  };
800
807
  type Refs = Record<string, Ref>;
@@ -1107,4 +1114,4 @@ type ResolvedOptions = {
1107
1114
  type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1108
1115
  //#endregion
1109
1116
  export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options$1 as t };
1110
- //# sourceMappingURL=types-DQTXVaz_.d.cts.map
1117
+ //# sourceMappingURL=types-DiIa8Yvy.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
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",
@@ -72,19 +72,19 @@
72
72
  }
73
73
  ],
74
74
  "dependencies": {
75
- "@kubb/react-fabric": "0.2.14",
75
+ "@kubb/react-fabric": "0.2.19",
76
76
  "jiti": "^2.6.1",
77
- "@kubb/core": "4.5.1",
78
- "@kubb/oas": "4.5.1",
79
- "@kubb/plugin-oas": "4.5.1",
80
- "@kubb/plugin-ts": "4.5.1",
81
- "@kubb/plugin-zod": "4.5.1"
77
+ "@kubb/core": "4.5.2",
78
+ "@kubb/oas": "4.5.2",
79
+ "@kubb/plugin-oas": "4.5.2",
80
+ "@kubb/plugin-ts": "4.5.2",
81
+ "@kubb/plugin-zod": "4.5.2"
82
82
  },
83
83
  "devDependencies": {
84
- "axios": "^1.13.1"
84
+ "axios": "^1.13.2"
85
85
  },
86
86
  "peerDependencies": {
87
- "@kubb/react-fabric": "0.2.14",
87
+ "@kubb/react-fabric": "0.2.19",
88
88
  "axios": "^1.7.2"
89
89
  },
90
90
  "peerDependenciesMeta": {
package/src/plugin.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import path from 'node:path'
2
- import { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'
2
+ import { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
3
3
  import { camelCase } from '@kubb/core/transformers'
4
4
  import { resolveModuleSource } from '@kubb/core/utils'
5
- import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
6
5
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
6
  import { pluginZodName } from '@kubb/plugin-zod'
8
7
  import { operationsGenerator } from './generators'
@@ -12,7 +11,7 @@ import type { PluginClient } from './types.ts'
12
11
 
13
12
  export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
14
13
 
15
- export const pluginClient = createPlugin<PluginClient>((options) => {
14
+ export const pluginClient = definePlugin<PluginClient>((options) => {
16
15
  const {
17
16
  output = { path: 'clients', barrelType: 'named' },
18
17
  group,
@@ -93,16 +92,14 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
93
92
 
94
93
  return resolvedName
95
94
  },
96
- async buildStart() {
97
- const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
98
-
99
- const oas = await swaggerPlugin.context.getOas()
95
+ async install() {
100
96
  const root = path.resolve(this.config.root, this.config.output.path)
101
97
  const mode = getMode(path.resolve(root, output.path))
102
- const baseURL = await swaggerPlugin.context.getBaseURL()
98
+ const oas = await this.getOas()
99
+ const baseURL = await this.getBaseURL()
103
100
 
104
101
  // pre add bundled fetcher
105
- const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')
102
+ const containsFetcher = this.fabric.files.some((file) => file.baseName === 'fetcher.ts')
106
103
 
107
104
  if (!this.plugin.options.importPath && !containsFetcher) {
108
105
  await this.addFile({
@@ -143,7 +140,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
143
140
 
144
141
  await this.addFile(...files)
145
142
 
146
- const barrelFiles = await getBarrelFiles(this.fileManager.files, {
143
+ const barrelFiles = await getBarrelFiles(this.fabric.files, {
147
144
  type: output.barrelType ?? 'named',
148
145
  root,
149
146
  output,