@kubb/plugin-swr 5.0.0-alpha.9 → 5.0.0-beta.33

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.
Files changed (44) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +33 -26
  3. package/dist/components-ByADeLZO.cjs +1029 -0
  4. package/dist/components-ByADeLZO.cjs.map +1 -0
  5. package/dist/components-CBdpiiay.js +933 -0
  6. package/dist/components-CBdpiiay.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +45 -51
  9. package/dist/components.js +1 -1
  10. package/dist/generators-Bb5wNYig.cjs +445 -0
  11. package/dist/generators-Bb5wNYig.cjs.map +1 -0
  12. package/dist/generators-D5kJZsB1.js +434 -0
  13. package/dist/generators-D5kJZsB1.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +4 -500
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +134 -113
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +130 -113
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-D9jeG3fE.d.ts +220 -0
  23. package/extension.yaml +199 -0
  24. package/package.json +57 -67
  25. package/src/components/Mutation.tsx +106 -227
  26. package/src/components/MutationKey.tsx +25 -1
  27. package/src/components/Query.tsx +75 -140
  28. package/src/components/QueryOptions.tsx +46 -95
  29. package/src/generators/mutationGenerator.tsx +113 -128
  30. package/src/generators/queryGenerator.tsx +125 -137
  31. package/src/index.ts +2 -2
  32. package/src/plugin.ts +117 -170
  33. package/src/resolvers/resolverSwr.ts +56 -0
  34. package/src/types.ts +115 -59
  35. package/src/utils.ts +10 -0
  36. package/dist/components-DRDGvgXG.js +0 -702
  37. package/dist/components-DRDGvgXG.js.map +0 -1
  38. package/dist/components-jd0l9XKn.cjs +0 -780
  39. package/dist/components-jd0l9XKn.cjs.map +0 -1
  40. package/dist/generators-CRSl6u2M.js +0 -399
  41. package/dist/generators-CRSl6u2M.js.map +0 -1
  42. package/dist/generators-D062obA7.cjs +0 -410
  43. package/dist/generators-D062obA7.cjs.map +0 -1
  44. package/dist/types-BIaGRPjD.d.ts +0 -210
package/dist/index.cjs CHANGED
@@ -1,145 +1,166 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_components = require("./components-jd0l9XKn.cjs");
3
- const require_generators = require("./generators-D062obA7.cjs");
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_components = require("./components-ByADeLZO.cjs");
6
+ const require_generators = require("./generators-Bb5wNYig.cjs");
4
7
  let node_path = require("node:path");
5
- node_path = require_components.__toESM(node_path);
8
+ node_path = require_components.__toESM(node_path, 1);
6
9
  let _kubb_core = require("@kubb/core");
7
10
  let _kubb_plugin_client = require("@kubb/plugin-client");
8
11
  let _kubb_plugin_client_templates_clients_axios_source = require("@kubb/plugin-client/templates/clients/axios.source");
9
12
  let _kubb_plugin_client_templates_clients_fetch_source = require("@kubb/plugin-client/templates/clients/fetch.source");
10
13
  let _kubb_plugin_client_templates_config_source = require("@kubb/plugin-client/templates/config.source");
11
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
12
14
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
13
15
  let _kubb_plugin_zod = require("@kubb/plugin-zod");
16
+ //#region src/resolvers/resolverSwr.ts
17
+ function capitalize(name) {
18
+ return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
19
+ }
20
+ /**
21
+ * Naming convention resolver for the SWR plugin.
22
+ *
23
+ * Provides default naming helpers using camelCase for functions and file paths.
24
+ *
25
+ * @example
26
+ * `resolverSwr.default('list pets', 'function') // → 'listPets'`
27
+ */
28
+ const resolverSwr = (0, _kubb_core.defineResolver)(() => ({
29
+ name: "default",
30
+ pluginName: "plugin-swr",
31
+ default(name, type) {
32
+ return require_components.camelCase(name, { isFile: type === "file" });
33
+ },
34
+ resolveName(name) {
35
+ return this.default(name, "function");
36
+ },
37
+ resolvePathName(name, type) {
38
+ return this.default(name, type);
39
+ },
40
+ resolveQueryName(node) {
41
+ return `use${capitalize(this.resolveName(node.operationId))}`;
42
+ },
43
+ resolveMutationName(node) {
44
+ return `use${capitalize(this.resolveName(node.operationId))}`;
45
+ },
46
+ resolveQueryOptionsName(node) {
47
+ return `${this.resolveName(node.operationId)}QueryOptions`;
48
+ },
49
+ resolveQueryKeyName(node) {
50
+ return `${this.resolveName(node.operationId)}QueryKey`;
51
+ },
52
+ resolveMutationKeyName(node) {
53
+ return `${this.resolveName(node.operationId)}MutationKey`;
54
+ },
55
+ resolveQueryKeyTypeName(node) {
56
+ return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
57
+ },
58
+ resolveMutationKeyTypeName(node) {
59
+ return `${capitalize(this.resolveName(node.operationId))}MutationKey`;
60
+ },
61
+ resolveMutationArgTypeName(node) {
62
+ return `${capitalize(this.resolveName(node.operationId))}MutationArg`;
63
+ },
64
+ resolveClientName(node) {
65
+ return this.resolveName(node.operationId);
66
+ }
67
+ }));
68
+ //#endregion
14
69
  //#region src/plugin.ts
15
70
  const pluginSwrName = "plugin-swr";
16
- const pluginSwr = (0, _kubb_core.createPlugin)((options) => {
71
+ const pluginSwr = (0, _kubb_core.definePlugin)((options) => {
17
72
  const { output = {
18
73
  path: "hooks",
19
74
  barrelType: "named"
20
- }, group, exclude = [], include, override = [], parser = "client", transformers = {}, query, mutation, client, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutationKey = require_components.MutationKey.getTransformer, queryKey = require_components.QueryKey.getTransformer, generators = [require_generators.queryGenerator, require_generators.mutationGenerator].filter(Boolean), paramsCasing, contentType } = options;
75
+ }, group, exclude = [], include, override = [], parser = false, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = require_components.mutationKeyTransformer, queryKey = require_components.queryKeyTransformer, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
21
76
  const clientName = client?.client ?? "axios";
22
77
  const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
78
+ const selectedGenerators = options.generators ?? [require_generators.queryGenerator, require_generators.mutationGenerator].filter((generator) => Boolean(generator));
79
+ const groupConfig = group ? {
80
+ ...group,
81
+ name: group.name ? group.name : (ctx) => {
82
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
83
+ return `${require_components.camelCase(ctx.group)}Controller`;
84
+ }
85
+ } : void 0;
23
86
  return {
24
87
  name: pluginSwrName,
25
- options: {
26
- output,
27
- client: {
28
- bundle: client?.bundle,
29
- baseURL: client?.baseURL,
30
- client: clientName,
31
- clientType: client?.clientType ?? "function",
32
- importPath: clientImportPath,
33
- dataReturnType: client?.dataReturnType ?? "data",
34
- paramsCasing
35
- },
36
- queryKey,
37
- query: query === false ? false : {
38
- importPath: "swr",
39
- methods: ["get"],
40
- ...query
41
- },
42
- mutationKey,
43
- mutation: mutation === false ? false : {
44
- importPath: "swr/mutation",
45
- methods: [
46
- "post",
47
- "put",
48
- "delete",
49
- "patch"
50
- ],
51
- ...mutation
52
- },
53
- parser,
54
- paramsType,
55
- pathParamsType,
56
- paramsCasing,
57
- group
58
- },
59
- pre: [
60
- _kubb_plugin_oas.pluginOasName,
61
- _kubb_plugin_ts.pluginTsName,
62
- parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0
63
- ].filter(Boolean),
64
- resolvePath(baseName, pathMode, options) {
65
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
66
- if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
67
- /**
68
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
69
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
70
- */
71
- return node_path.default.resolve(root, output.path);
72
- if (group && (options?.group?.path || options?.group?.tag)) {
73
- const groupName = group?.name ? group.name : (ctx) => {
74
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
75
- return `${require_components.camelCase(ctx.group)}Controller`;
76
- };
77
- return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
78
- }
79
- return node_path.default.resolve(root, output.path, baseName);
80
- },
81
- resolveName(name, type) {
82
- let resolvedName = require_components.camelCase(name);
83
- if (type === "file" || type === "function") resolvedName = require_components.camelCase(name, { isFile: type === "file" });
84
- if (type === "type") resolvedName = require_components.pascalCase(name);
85
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
86
- return resolvedName;
87
- },
88
- async install() {
89
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
90
- const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
91
- const oas = await this.getOas();
92
- const baseURL = await this.getBaseURL();
93
- if (baseURL) this.plugin.options.client.baseURL = baseURL;
94
- const hasClientPlugin = !!this.driver.getPluginByName(_kubb_plugin_client.pluginClientName);
95
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
96
- baseName: "fetch.ts",
97
- path: node_path.default.resolve(root, ".kubb/fetch.ts"),
98
- sources: [{
99
- name: "fetch",
100
- value: this.plugin.options.client.client === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source,
88
+ options,
89
+ dependencies: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter((dependency) => Boolean(dependency)),
90
+ hooks: { "kubb:plugin:setup"(ctx) {
91
+ const resolver = userResolver ? {
92
+ ...resolverSwr,
93
+ ...userResolver
94
+ } : resolverSwr;
95
+ ctx.setOptions({
96
+ output,
97
+ client: {
98
+ bundle: client?.bundle,
99
+ baseURL: client?.baseURL,
100
+ client: clientName,
101
+ clientType: client?.clientType ?? "function",
102
+ importPath: clientImportPath,
103
+ dataReturnType: client?.dataReturnType ?? "data",
104
+ paramsCasing
105
+ },
106
+ queryKey,
107
+ query: query === false ? false : {
108
+ importPath: "swr",
109
+ methods: ["get"],
110
+ ...query
111
+ },
112
+ mutationKey,
113
+ mutation: mutation === false ? false : {
114
+ importPath: "swr/mutation",
115
+ methods: [
116
+ "post",
117
+ "put",
118
+ "patch",
119
+ "delete"
120
+ ],
121
+ ...mutation
122
+ },
123
+ parser,
124
+ paramsType,
125
+ pathParamsType,
126
+ paramsCasing,
127
+ group: groupConfig,
128
+ exclude,
129
+ include,
130
+ override,
131
+ resolver
132
+ });
133
+ ctx.setResolver(resolver);
134
+ if (userTransformer) ctx.setTransformer(userTransformer);
135
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
136
+ for (const gen of userGenerators) ctx.addGenerator(gen);
137
+ const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
138
+ const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === _kubb_plugin_client.pluginClientName);
139
+ if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
140
+ baseName: "client.ts",
141
+ path: node_path.default.resolve(root, ".kubb/client.ts"),
142
+ sources: [_kubb_core.ast.createSource({
143
+ name: "client",
144
+ nodes: [_kubb_core.ast.createText(clientName === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source)],
101
145
  isExportable: true,
102
146
  isIndexable: true
103
- }],
104
- imports: [],
105
- exports: []
147
+ })]
106
148
  });
107
- if (!hasClientPlugin) await this.addFile({
149
+ if (!hasClientPlugin) ctx.injectFile({
108
150
  baseName: "config.ts",
109
151
  path: node_path.default.resolve(root, ".kubb/config.ts"),
110
- sources: [{
152
+ sources: [_kubb_core.ast.createSource({
111
153
  name: "config",
112
- value: _kubb_plugin_client_templates_config_source.source,
154
+ nodes: [_kubb_core.ast.createText(_kubb_plugin_client_templates_config_source.source)],
113
155
  isExportable: false,
114
156
  isIndexable: false
115
- }],
116
- imports: [],
117
- exports: []
157
+ })]
118
158
  });
119
- const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
120
- fabric: this.fabric,
121
- oas,
122
- driver: this.driver,
123
- events: this.events,
124
- plugin: this.plugin,
125
- contentType,
126
- exclude,
127
- include,
128
- override,
129
- mode
130
- }).build(...generators);
131
- await this.upsertFile(...files);
132
- const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
133
- type: output.barrelType ?? "named",
134
- root,
135
- output,
136
- meta: { pluginName: this.plugin.name }
137
- });
138
- await this.upsertFile(...barrelFiles);
139
- }
159
+ } }
140
160
  };
141
161
  });
142
162
  //#endregion
163
+ exports.default = pluginSwr;
143
164
  exports.pluginSwr = pluginSwr;
144
165
  exports.pluginSwrName = pluginSwrName;
145
166
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","path","camelCase","pascalCase","pluginClientName","fetchClientSource","axiosClientSource","configSource","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase, pascalCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\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 = createPlugin<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 clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\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 mutation === false\n ? false\n : {\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.driver.getPluginByName(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: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,\n isExportable: true,\n isIndexable: true,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n if (!hasClientPlugin) {\n await this.addFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n {\n name: 'config',\n value: configSource,\n isExportable: false,\n isIndexable: false,\n },\n ],\n imports: [],\n exports: [],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\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 pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,gBAAgB;AAE7B,MAAa,aAAA,GAAA,WAAA,eAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS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ACN,OAAO,KAAK,OAAO,QAAQ,OAAO,WAAW,UAAUI,mDAAAA,SAAoBC,mDAAAA;KAC3E,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;AAGJ,OAAI,CAAC,gBACH,OAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAML,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACP;KACE,MAAM;KACN,OAAOM,4CAAAA;KACP,cAAc;KACd,aAAa;KACd,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;GAgBJ,MAAM,QAAQ,MAba,IAAIC,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["camelCase","mutationKeyTransformer","queryKeyTransformer","queryGenerator","mutationGenerator","camelCase","pluginTsName","pluginZodName","path","pluginClientName","ast","fetchClientSource","axiosClientSource","configSource"],"sources":["../src/resolvers/resolverSwr.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginSwr } from '../types.ts'\n\nfunction capitalize(name: string): string {\n return `${name.charAt(0).toUpperCase()}${name.slice(1)}`\n}\n\n/**\n * Naming convention resolver for the SWR plugin.\n *\n * Provides default naming helpers using camelCase for functions and file paths.\n *\n * @example\n * `resolverSwr.default('list pets', 'function') // → 'listPets'`\n */\nexport const resolverSwr = defineResolver<PluginSwr>(() => ({\n name: 'default',\n pluginName: 'plugin-swr',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveQueryName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveMutationName(node) {\n return `use${capitalize(this.resolveName(node.operationId))}`\n },\n resolveQueryOptionsName(node) {\n return `${this.resolveName(node.operationId)}QueryOptions`\n },\n resolveQueryKeyName(node) {\n return `${this.resolveName(node.operationId)}QueryKey`\n },\n resolveMutationKeyName(node) {\n return `${this.resolveName(node.operationId)}MutationKey`\n },\n resolveQueryKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}QueryKey`\n },\n resolveMutationKeyTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}MutationKey`\n },\n resolveMutationArgTypeName(node) {\n return `${capitalize(this.resolveName(node.operationId))}MutationArg`\n },\n resolveClientName(node) {\n return this.resolveName(node.operationId)\n },\n}))\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { ast, definePlugin, type Group } from '@kubb/core'\nimport { pluginClientName } from '@kubb/plugin-client'\nimport { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'\nimport { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'\nimport { source as configSource } from '@kubb/plugin-client/templates/config.source'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mutationKeyTransformer, queryKeyTransformer } from '@internals/tanstack-query'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport { resolverSwr } from './resolvers/resolverSwr.ts'\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 = false,\n paramsType = 'inline',\n pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',\n mutation = {},\n query = {},\n mutationKey = mutationKeyTransformer,\n queryKey = queryKeyTransformer,\n paramsCasing,\n client,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const clientName = client?.client ?? 'axios'\n const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)\n\n const selectedGenerators =\n options.generators ?? [queryGenerator, mutationGenerator].filter((generator): generator is NonNullable<typeof generator> => Boolean(generator))\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : undefined\n\n return {\n name: pluginSwrName,\n options,\n dependencies: [pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverSwr, ...userResolver } : resolverSwr\n\n ctx.setOptions({\n output,\n client: {\n bundle: client?.bundle,\n baseURL: client?.baseURL,\n client: clientName,\n clientType: client?.clientType ?? 'function',\n importPath: clientImportPath,\n dataReturnType: client?.dataReturnType ?? 'data',\n paramsCasing,\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 mutation === false\n ? false\n : {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType,\n paramsCasing,\n group: groupConfig,\n exclude,\n include,\n override,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n for (const gen of selectedGenerators) {\n ctx.addGenerator(gen)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const hasClientPlugin = !!ctx.config.plugins?.some((p) => (p as { name?: string }).name === pluginClientName)\n\n if (client?.bundle && !hasClientPlugin && !clientImportPath) {\n ctx.injectFile({\n baseName: 'client.ts',\n path: path.resolve(root, '.kubb/client.ts'),\n sources: [\n ast.createSource({\n name: 'client',\n nodes: [ast.createText(clientName === 'fetch' ? fetchClientSource : axiosClientSource)],\n isExportable: true,\n isIndexable: true,\n }),\n ],\n })\n }\n\n if (!hasClientPlugin) {\n ctx.injectFile({\n baseName: 'config.ts',\n path: path.resolve(root, '.kubb/config.ts'),\n sources: [\n ast.createSource({\n name: 'config',\n nodes: [ast.createText(configSource)],\n isExportable: false,\n isIndexable: false,\n }),\n ],\n })\n }\n },\n },\n }\n})\n\nexport default pluginSwr\n"],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAS,WAAW,MAAsB;CACxC,OAAO,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;;;;;;;;;;AAWxD,MAAa,eAAA,GAAA,WAAA,uBAA+C;CAC1D,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,KAAK,QAAQ,MAAM,WAAW;;CAEvC,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,iBAAiB,MAAM;EACrB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,oBAAoB,MAAM;EACxB,OAAO,MAAM,WAAW,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE7D,wBAAwB,MAAM;EAC5B,OAAO,GAAG,KAAK,YAAY,KAAK,YAAY,CAAC;;CAE/C,oBAAoB,MAAM;EACxB,OAAO,GAAG,KAA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A,SAAoBC,mDAAAA,OAAkB,CAAC;KACvF,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;GAGJ,IAAI,CAAC,iBACH,IAAI,WAAW;IACb,UAAU;IACV,MAAMJ,UAAAA,QAAK,QAAQ,MAAM,kBAAkB;IAC3C,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAWG,4CAAAA,OAAa,CAAC;KACrC,cAAc;KACd,aAAa;KACd,CAAC,CACH;IACF,CAAC;KAGP;EACF;EACD"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginSwr, t as Options } from "./types-BIaGRPjD.js";
3
- import * as _kubb_core0 from "@kubb/core";
2
+ import { i as Transformer, n as PluginSwr, t as Options } from "./types-D9jeG3fE.js";
3
+ import * as _$_kubb_core0 from "@kubb/core";
4
4
 
5
5
  //#region src/plugin.d.ts
6
6
  declare const pluginSwrName = "plugin-swr";
7
- declare const pluginSwr: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginSwr>;
7
+ declare const pluginSwr: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginSwr>;
8
8
  //#endregion
9
- export { type PluginSwr, pluginSwr, pluginSwrName };
9
+ export { type PluginSwr, type Transformer, pluginSwr as default, pluginSwr, pluginSwrName };
10
10
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,144 +1,161 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { a as MutationKey, i as QueryKey, o as camelCase, s as pascalCase } from "./components-DRDGvgXG.js";
3
- import { n as mutationGenerator, t as queryGenerator } from "./generators-CRSl6u2M.js";
2
+ import { l as mutationKeyTransformer, o as queryKeyTransformer, u as camelCase } from "./components-CBdpiiay.js";
3
+ import { n as mutationGenerator, t as queryGenerator } from "./generators-D5kJZsB1.js";
4
4
  import path from "node:path";
5
- import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
5
+ import { ast, definePlugin, defineResolver } from "@kubb/core";
6
6
  import { pluginClientName } from "@kubb/plugin-client";
7
7
  import { source } from "@kubb/plugin-client/templates/clients/axios.source";
8
8
  import { source as source$1 } from "@kubb/plugin-client/templates/clients/fetch.source";
9
9
  import { source as source$2 } from "@kubb/plugin-client/templates/config.source";
10
- import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
11
10
  import { pluginTsName } from "@kubb/plugin-ts";
12
11
  import { pluginZodName } from "@kubb/plugin-zod";
12
+ //#region src/resolvers/resolverSwr.ts
13
+ function capitalize(name) {
14
+ return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
15
+ }
16
+ /**
17
+ * Naming convention resolver for the SWR plugin.
18
+ *
19
+ * Provides default naming helpers using camelCase for functions and file paths.
20
+ *
21
+ * @example
22
+ * `resolverSwr.default('list pets', 'function') // → 'listPets'`
23
+ */
24
+ const resolverSwr = defineResolver(() => ({
25
+ name: "default",
26
+ pluginName: "plugin-swr",
27
+ default(name, type) {
28
+ return camelCase(name, { isFile: type === "file" });
29
+ },
30
+ resolveName(name) {
31
+ return this.default(name, "function");
32
+ },
33
+ resolvePathName(name, type) {
34
+ return this.default(name, type);
35
+ },
36
+ resolveQueryName(node) {
37
+ return `use${capitalize(this.resolveName(node.operationId))}`;
38
+ },
39
+ resolveMutationName(node) {
40
+ return `use${capitalize(this.resolveName(node.operationId))}`;
41
+ },
42
+ resolveQueryOptionsName(node) {
43
+ return `${this.resolveName(node.operationId)}QueryOptions`;
44
+ },
45
+ resolveQueryKeyName(node) {
46
+ return `${this.resolveName(node.operationId)}QueryKey`;
47
+ },
48
+ resolveMutationKeyName(node) {
49
+ return `${this.resolveName(node.operationId)}MutationKey`;
50
+ },
51
+ resolveQueryKeyTypeName(node) {
52
+ return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
53
+ },
54
+ resolveMutationKeyTypeName(node) {
55
+ return `${capitalize(this.resolveName(node.operationId))}MutationKey`;
56
+ },
57
+ resolveMutationArgTypeName(node) {
58
+ return `${capitalize(this.resolveName(node.operationId))}MutationArg`;
59
+ },
60
+ resolveClientName(node) {
61
+ return this.resolveName(node.operationId);
62
+ }
63
+ }));
64
+ //#endregion
13
65
  //#region src/plugin.ts
14
66
  const pluginSwrName = "plugin-swr";
15
- const pluginSwr = createPlugin((options) => {
67
+ const pluginSwr = definePlugin((options) => {
16
68
  const { output = {
17
69
  path: "hooks",
18
70
  barrelType: "named"
19
- }, group, exclude = [], include, override = [], parser = "client", transformers = {}, query, mutation, client, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutationKey = MutationKey.getTransformer, queryKey = QueryKey.getTransformer, generators = [queryGenerator, mutationGenerator].filter(Boolean), paramsCasing, contentType } = options;
71
+ }, group, exclude = [], include, override = [], parser = false, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
20
72
  const clientName = client?.client ?? "axios";
21
73
  const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
74
+ const selectedGenerators = options.generators ?? [queryGenerator, mutationGenerator].filter((generator) => Boolean(generator));
75
+ const groupConfig = group ? {
76
+ ...group,
77
+ name: group.name ? group.name : (ctx) => {
78
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
79
+ return `${camelCase(ctx.group)}Controller`;
80
+ }
81
+ } : void 0;
22
82
  return {
23
83
  name: pluginSwrName,
24
- options: {
25
- output,
26
- client: {
27
- bundle: client?.bundle,
28
- baseURL: client?.baseURL,
29
- client: clientName,
30
- clientType: client?.clientType ?? "function",
31
- importPath: clientImportPath,
32
- dataReturnType: client?.dataReturnType ?? "data",
33
- paramsCasing
34
- },
35
- queryKey,
36
- query: query === false ? false : {
37
- importPath: "swr",
38
- methods: ["get"],
39
- ...query
40
- },
41
- mutationKey,
42
- mutation: mutation === false ? false : {
43
- importPath: "swr/mutation",
44
- methods: [
45
- "post",
46
- "put",
47
- "delete",
48
- "patch"
49
- ],
50
- ...mutation
51
- },
52
- parser,
53
- paramsType,
54
- pathParamsType,
55
- paramsCasing,
56
- group
57
- },
58
- pre: [
59
- pluginOasName,
60
- pluginTsName,
61
- parser === "zod" ? pluginZodName : void 0
62
- ].filter(Boolean),
63
- resolvePath(baseName, pathMode, options) {
64
- const root = path.resolve(this.config.root, this.config.output.path);
65
- if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
66
- /**
67
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
68
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
69
- */
70
- return path.resolve(root, output.path);
71
- if (group && (options?.group?.path || options?.group?.tag)) {
72
- const groupName = group?.name ? group.name : (ctx) => {
73
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
74
- return `${camelCase(ctx.group)}Controller`;
75
- };
76
- return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
77
- }
78
- return path.resolve(root, output.path, baseName);
79
- },
80
- resolveName(name, type) {
81
- let resolvedName = camelCase(name);
82
- if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
83
- if (type === "type") resolvedName = pascalCase(name);
84
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
85
- return resolvedName;
86
- },
87
- async install() {
88
- const root = path.resolve(this.config.root, this.config.output.path);
89
- const mode = getMode(path.resolve(root, output.path));
90
- const oas = await this.getOas();
91
- const baseURL = await this.getBaseURL();
92
- if (baseURL) this.plugin.options.client.baseURL = baseURL;
93
- const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName);
94
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) await this.upsertFile({
95
- baseName: "fetch.ts",
96
- path: path.resolve(root, ".kubb/fetch.ts"),
97
- sources: [{
98
- name: "fetch",
99
- value: this.plugin.options.client.client === "fetch" ? source$1 : source,
84
+ options,
85
+ dependencies: [pluginTsName, parser === "zod" ? pluginZodName : void 0].filter((dependency) => Boolean(dependency)),
86
+ hooks: { "kubb:plugin:setup"(ctx) {
87
+ const resolver = userResolver ? {
88
+ ...resolverSwr,
89
+ ...userResolver
90
+ } : resolverSwr;
91
+ ctx.setOptions({
92
+ output,
93
+ client: {
94
+ bundle: client?.bundle,
95
+ baseURL: client?.baseURL,
96
+ client: clientName,
97
+ clientType: client?.clientType ?? "function",
98
+ importPath: clientImportPath,
99
+ dataReturnType: client?.dataReturnType ?? "data",
100
+ paramsCasing
101
+ },
102
+ queryKey,
103
+ query: query === false ? false : {
104
+ importPath: "swr",
105
+ methods: ["get"],
106
+ ...query
107
+ },
108
+ mutationKey,
109
+ mutation: mutation === false ? false : {
110
+ importPath: "swr/mutation",
111
+ methods: [
112
+ "post",
113
+ "put",
114
+ "patch",
115
+ "delete"
116
+ ],
117
+ ...mutation
118
+ },
119
+ parser,
120
+ paramsType,
121
+ pathParamsType,
122
+ paramsCasing,
123
+ group: groupConfig,
124
+ exclude,
125
+ include,
126
+ override,
127
+ resolver
128
+ });
129
+ ctx.setResolver(resolver);
130
+ if (userTransformer) ctx.setTransformer(userTransformer);
131
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
132
+ for (const gen of userGenerators) ctx.addGenerator(gen);
133
+ const root = path.resolve(ctx.config.root, ctx.config.output.path);
134
+ const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === pluginClientName);
135
+ if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
136
+ baseName: "client.ts",
137
+ path: path.resolve(root, ".kubb/client.ts"),
138
+ sources: [ast.createSource({
139
+ name: "client",
140
+ nodes: [ast.createText(clientName === "fetch" ? source$1 : source)],
100
141
  isExportable: true,
101
142
  isIndexable: true
102
- }],
103
- imports: [],
104
- exports: []
143
+ })]
105
144
  });
106
- if (!hasClientPlugin) await this.addFile({
145
+ if (!hasClientPlugin) ctx.injectFile({
107
146
  baseName: "config.ts",
108
147
  path: path.resolve(root, ".kubb/config.ts"),
109
- sources: [{
148
+ sources: [ast.createSource({
110
149
  name: "config",
111
- value: source$2,
150
+ nodes: [ast.createText(source$2)],
112
151
  isExportable: false,
113
152
  isIndexable: false
114
- }],
115
- imports: [],
116
- exports: []
153
+ })]
117
154
  });
118
- const files = await new OperationGenerator(this.plugin.options, {
119
- fabric: this.fabric,
120
- oas,
121
- driver: this.driver,
122
- events: this.events,
123
- plugin: this.plugin,
124
- contentType,
125
- exclude,
126
- include,
127
- override,
128
- mode
129
- }).build(...generators);
130
- await this.upsertFile(...files);
131
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
132
- type: output.barrelType ?? "named",
133
- root,
134
- output,
135
- meta: { pluginName: this.plugin.name }
136
- });
137
- await this.upsertFile(...barrelFiles);
138
- }
155
+ } }
139
156
  };
140
157
  });
141
158
  //#endregion
142
- export { pluginSwr, pluginSwrName };
159
+ export { pluginSwr as default, pluginSwr, pluginSwrName };
143
160
 
144
161
  //# sourceMappingURL=index.js.map