@kubb/plugin-swr 4.5.13 → 4.5.15

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 { a as OperationSchemas, n as PluginSwr, r as Transformer, s as Operation } from "./types-BI_YKWA-.cjs";
1
+ import { a as OperationSchemas, n as PluginSwr, r as Transformer, s as Operation } from "./types-BouR_x-R.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 { a as OperationSchemas, n as PluginSwr, r as Transformer, s as Operation } from "./types-D4VCBang.js";
1
+ import { a as OperationSchemas, n as PluginSwr, r as Transformer, s as Operation } from "./types-BcF7c9zt.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 { i as ReactGenerator, n as PluginSwr } from "./types-BI_YKWA-.cjs";
1
+ import { i as ReactGenerator, n as PluginSwr } from "./types-BouR_x-R.cjs";
2
2
 
3
3
  //#region src/generators/mutationGenerator.d.ts
4
4
  declare const mutationGenerator: ReactGenerator<PluginSwr>;
@@ -1,4 +1,4 @@
1
- import { i as ReactGenerator, n as PluginSwr } from "./types-D4VCBang.js";
1
+ import { i as ReactGenerator, n as PluginSwr } from "./types-BcF7c9zt.js";
2
2
 
3
3
  //#region src/generators/mutationGenerator.d.ts
4
4
  declare const mutationGenerator: ReactGenerator<PluginSwr>;
package/dist/index.cjs CHANGED
@@ -88,8 +88,7 @@ const pluginSwr = (0, __kubb_core.definePlugin)((options) => {
88
88
  const baseURL = await this.getBaseURL();
89
89
  if (baseURL) this.plugin.options.client.baseURL = baseURL;
90
90
  const hasClientPlugin = !!this.pluginManager.getPluginByKey([__kubb_plugin_client.pluginClientName]);
91
- const containsFetch = this.fabric.files.some((file) => file.baseName === "fetch.ts");
92
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath && !containsFetch) await this.addFile({
91
+ if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
93
92
  baseName: "fetch.ts",
94
93
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
95
94
  sources: [{
@@ -99,6 +98,16 @@ const pluginSwr = (0, __kubb_core.definePlugin)((options) => {
99
98
  isIndexable: true
100
99
  }]
101
100
  });
101
+ await this.addFile({
102
+ baseName: "config.ts",
103
+ path: node_path.default.resolve(root, ".kubb/config.ts"),
104
+ sources: [{
105
+ name: "config",
106
+ value: (0, __kubb_core_utils.resolveModuleSource)("@kubb/plugin-client/templates/config").source,
107
+ isExportable: false,
108
+ isIndexable: false
109
+ }]
110
+ });
102
111
  const files = await new __kubb_plugin_oas.OperationGenerator(this.plugin.options, {
103
112
  fabric: this.fabric,
104
113
  oas,
@@ -110,7 +119,7 @@ const pluginSwr = (0, __kubb_core.definePlugin)((options) => {
110
119
  override,
111
120
  mode
112
121
  }).build(...generators);
113
- await this.addFile(...files);
122
+ await this.upsertFile(...files);
114
123
  const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fabric.files, {
115
124
  type: output.barrelType ?? "named",
116
125
  root,
@@ -118,7 +127,7 @@ const pluginSwr = (0, __kubb_core.definePlugin)((options) => {
118
127
  meta: { pluginKey: this.plugin.key },
119
128
  logger: this.logger
120
129
  });
121
- await this.addFile(...barrelFiles);
130
+ await this.upsertFile(...barrelFiles);
122
131
  }
123
132
  };
124
133
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientType = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientType}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientType,\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, 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 let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath && !containsFetch) {\n // pre add bundled fetch\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.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(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n me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CACP;KACE,MAAM;KACN,kDACE,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAU,gDAAgD,8CACjG,CAAC;KACF,cAAc;KACd,aAAa;KACd,CACF;IACF,CAAC;GAeJ,MAAM,QAAQ,MAZa,IAAII,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,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"}
1
+ {"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","pluginClientName","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientType = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientType}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientType,\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, 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 let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\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.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 await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\n await this.upsertFile(...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.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,EAAE,EACjB,OACA,UACA,QACA,aAAa,UACb,iBA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,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,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,WAAW,GAAG,YAAY;;EAExC;EACD"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-BI_YKWA-.cjs";
1
+ import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-BouR_x-R.cjs";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginSwrName = "plugin-swr";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-D4VCBang.js";
1
+ import { n as PluginSwr, o as UserPluginWithLifeCycle, t as Options } from "./types-BcF7c9zt.js";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginSwrName = "plugin-swr";
package/dist/index.js CHANGED
@@ -87,8 +87,7 @@ const pluginSwr = definePlugin((options) => {
87
87
  const baseURL = await this.getBaseURL();
88
88
  if (baseURL) this.plugin.options.client.baseURL = baseURL;
89
89
  const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName]);
90
- const containsFetch = this.fabric.files.some((file) => file.baseName === "fetch.ts");
91
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath && !containsFetch) await this.addFile({
90
+ if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
92
91
  baseName: "fetch.ts",
93
92
  path: path.resolve(root, ".kubb/fetch.ts"),
94
93
  sources: [{
@@ -98,6 +97,16 @@ const pluginSwr = definePlugin((options) => {
98
97
  isIndexable: true
99
98
  }]
100
99
  });
100
+ await this.addFile({
101
+ baseName: "config.ts",
102
+ path: path.resolve(root, ".kubb/config.ts"),
103
+ sources: [{
104
+ name: "config",
105
+ value: resolveModuleSource("@kubb/plugin-client/templates/config").source,
106
+ isExportable: false,
107
+ isIndexable: false
108
+ }]
109
+ });
101
110
  const files = await new OperationGenerator(this.plugin.options, {
102
111
  fabric: this.fabric,
103
112
  oas,
@@ -109,7 +118,7 @@ const pluginSwr = definePlugin((options) => {
109
118
  override,
110
119
  mode
111
120
  }).build(...generators);
112
- await this.addFile(...files);
121
+ await this.upsertFile(...files);
113
122
  const barrelFiles = await getBarrelFiles(this.fabric.files, {
114
123
  type: output.barrelType ?? "named",
115
124
  root,
@@ -117,7 +126,7 @@ const pluginSwr = definePlugin((options) => {
117
126
  meta: { pluginKey: this.plugin.key },
118
127
  logger: this.logger
119
128
  });
120
- await this.addFile(...barrelFiles);
129
+ await this.upsertFile(...barrelFiles);
121
130
  }
122
131
  };
123
132
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientType = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientType}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientType,\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, 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 let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath && !containsFetch) {\n // pre add bundled fetch\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.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(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\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":";;;;;;;;;;;;AAYA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,EAAE,EACjB,OACA,UACA,QACA,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,cAA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AM,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
+ {"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = definePlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n contentType,\n } = options\n\n const clientType = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientType}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n ...options.client,\n client: clientType,\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, 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 let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])\n\n if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {\n // pre add bundled fetch\n await this.upsertFile({\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.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 await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: resolveModuleSource('@kubb/plugin-client/templates/config').source,\n isExportable: false,\n isIndexable: false,\n },\n ],\n })\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\n await this.upsertFile(...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.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,UACT,eAAe,EAAE,EACjB,OACA,UACA,QACA,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,cAAc,YAAY,gBAC1B,WAAW,SAAS,gBACpB,aAAa,CAAC,gBAAgB,kBAAkB,CAAC,OAAO,QAAQ,EAChE,cACA,gBACE;CAEJ,MAAM,aAAa,QAAQ,UAAU;CACrC,MAAM,mBAAmB,QAAQ,eAAe,CAAC,QAAQ,SAAS,+BAA+B,eAAe;AAEhH,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,QAAQ;IACN,GAAG,QAAQ;IACX,QAAQ;IACR,YAAY;IACZ,gBAAgB,QAAQ,kBAAkB;IAC3C;GACD;GACA,OACE,UAAU,QACN,QACA;IACE,YAAY;IACZ,SA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pMethods 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
 
@@ -360,7 +360,14 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
360
360
  fabric: Fabric;
361
361
  config: Config;
362
362
  pluginManager: PluginManager;
363
+ /**
364
+ * Only add when the file does not exist yet
365
+ */
363
366
  addFile: (...file: Array<KubbFile.File>) => Promise<void>;
367
+ /**
368
+ * merging multiple sources into the same output file
369
+ */
370
+ upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
364
371
  logger: Logger;
365
372
  mode: KubbFile.Mode;
366
373
  /**
@@ -1091,6 +1098,7 @@ type Options$2 = {
1091
1098
  * Bundle the selected client into the generated `.kubb` directory.
1092
1099
  * When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
1093
1100
  * @default false
1101
+ * In version 5 of Kubb this will be by default true
1094
1102
  */
1095
1103
  bundle?: boolean;
1096
1104
  transformers?: {
@@ -1248,4 +1256,4 @@ type ResolvedOptions = {
1248
1256
  type PluginSwr = PluginFactoryOptions<'plugin-swr', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1249
1257
  //#endregion
1250
1258
  export { OperationSchemas as a, ReactGenerator as i, PluginSwr as n, UserPluginWithLifeCycle as o, Transformer as r, Operation$1 as s, Options$1 as t };
1251
- //# sourceMappingURL=types-BI_YKWA-.d.cts.map
1259
+ //# sourceMappingURL=types-BcF7c9zt.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
 
@@ -360,7 +360,14 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
360
360
  fabric: Fabric;
361
361
  config: Config;
362
362
  pluginManager: PluginManager;
363
+ /**
364
+ * Only add when the file does not exist yet
365
+ */
363
366
  addFile: (...file: Array<KubbFile.File>) => Promise<void>;
367
+ /**
368
+ * merging multiple sources into the same output file
369
+ */
370
+ upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
364
371
  logger: Logger;
365
372
  mode: KubbFile.Mode;
366
373
  /**
@@ -1091,6 +1098,7 @@ type Options$2 = {
1091
1098
  * Bundle the selected client into the generated `.kubb` directory.
1092
1099
  * When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
1093
1100
  * @default false
1101
+ * In version 5 of Kubb this will be by default true
1094
1102
  */
1095
1103
  bundle?: boolean;
1096
1104
  transformers?: {
@@ -1248,4 +1256,4 @@ type ResolvedOptions = {
1248
1256
  type PluginSwr = PluginFactoryOptions<'plugin-swr', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1249
1257
  //#endregion
1250
1258
  export { OperationSchemas as a, ReactGenerator as i, PluginSwr as n, UserPluginWithLifeCycle as o, Transformer as r, Operation$1 as s, Options$1 as t };
1251
- //# sourceMappingURL=types-D4VCBang.d.ts.map
1259
+ //# sourceMappingURL=types-BouR_x-R.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-swr",
3
- "version": "4.5.13",
3
+ "version": "4.5.15",
4
4
  "description": "SWR hooks generator plugin for Kubb, creating type-safe data fetching hooks from OpenAPI specifications for React and Next.js applications.",
5
5
  "keywords": [
6
6
  "swr",
@@ -70,17 +70,17 @@
70
70
  }
71
71
  ],
72
72
  "dependencies": {
73
- "@kubb/react-fabric": "0.5.1",
73
+ "@kubb/react-fabric": "0.5.2",
74
74
  "remeda": "^2.32.0",
75
- "@kubb/core": "4.5.13",
76
- "@kubb/oas": "4.5.13",
77
- "@kubb/plugin-client": "4.5.13",
78
- "@kubb/plugin-oas": "4.5.13",
79
- "@kubb/plugin-ts": "4.5.13",
80
- "@kubb/plugin-zod": "4.5.13"
75
+ "@kubb/core": "4.5.15",
76
+ "@kubb/oas": "4.5.15",
77
+ "@kubb/plugin-client": "4.5.15",
78
+ "@kubb/plugin-oas": "4.5.15",
79
+ "@kubb/plugin-ts": "4.5.15",
80
+ "@kubb/plugin-zod": "4.5.15"
81
81
  },
82
82
  "peerDependencies": {
83
- "@kubb/react-fabric": "0.5.1"
83
+ "@kubb/react-fabric": "0.5.2"
84
84
  },
85
85
  "engines": {
86
86
  "node": ">=20"
package/src/plugin.ts CHANGED
@@ -132,11 +132,10 @@ export const pluginSwr = definePlugin<PluginSwr>((options) => {
132
132
  }
133
133
 
134
134
  const hasClientPlugin = !!this.pluginManager.getPluginByKey([pluginClientName])
135
- const containsFetch = this.fabric.files.some((file) => file.baseName === 'fetch.ts')
136
135
 
137
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath && !containsFetch) {
136
+ if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {
138
137
  // pre add bundled fetch
139
- await this.addFile({
138
+ await this.upsertFile({
140
139
  baseName: 'fetch.ts',
141
140
  path: path.resolve(root, '.kubb/fetch.ts'),
142
141
  sources: [
@@ -152,6 +151,19 @@ export const pluginSwr = definePlugin<PluginSwr>((options) => {
152
151
  })
153
152
  }
154
153
 
154
+ await this.addFile({
155
+ baseName: 'config.ts',
156
+ path: path.resolve(root, '.kubb/config.ts'),
157
+ sources: [
158
+ {
159
+ name: 'config',
160
+ value: resolveModuleSource('@kubb/plugin-client/templates/config').source,
161
+ isExportable: false,
162
+ isIndexable: false,
163
+ },
164
+ ],
165
+ })
166
+
155
167
  const operationGenerator = new OperationGenerator(this.plugin.options, {
156
168
  fabric: this.fabric,
157
169
  oas,
@@ -165,7 +177,7 @@ export const pluginSwr = definePlugin<PluginSwr>((options) => {
165
177
  })
166
178
 
167
179
  const files = await operationGenerator.build(...generators)
168
- await this.addFile(...files)
180
+ await this.upsertFile(...files)
169
181
 
170
182
  const barrelFiles = await getBarrelFiles(this.fabric.files, {
171
183
  type: output.barrelType ?? 'named',
@@ -177,7 +189,7 @@ export const pluginSwr = definePlugin<PluginSwr>((options) => {
177
189
  logger: this.logger,
178
190
  })
179
191
 
180
- await this.addFile(...barrelFiles)
192
+ await this.upsertFile(...barrelFiles)
181
193
  },
182
194
  }
183
195
  })