@kubb/plugin-swr 3.16.1 → 3.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-BQIcQmn3.js +435 -0
- package/dist/components-BQIcQmn3.js.map +1 -0
- package/dist/components-Zv6v8ZAm.cjs +493 -0
- package/dist/components-Zv6v8ZAm.cjs.map +1 -0
- package/dist/components.cjs +6 -27
- package/dist/components.d.cts +177 -78
- package/dist/components.d.ts +177 -78
- package/dist/components.js +3 -3
- package/dist/generators-B-fWjDXL.js +328 -0
- package/dist/generators-B-fWjDXL.js.map +1 -0
- package/dist/generators-ByyKDjyt.cjs +339 -0
- package/dist/generators-ByyKDjyt.cjs.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +8 -9
- package/dist/generators.d.ts +8 -9
- package/dist/generators.js +4 -4
- package/dist/index.cjs +107 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +107 -130
- package/dist/index.js.map +1 -1
- package/dist/types-CSnGy9Uj.d.ts +1355 -0
- package/dist/types-CjDGkyWH.d.cts +1355 -0
- package/package.json +25 -30
- package/dist/chunk-2N4Q32XH.cjs +0 -285
- package/dist/chunk-2N4Q32XH.cjs.map +0 -1
- package/dist/chunk-GWLPXHRE.js +0 -282
- package/dist/chunk-GWLPXHRE.js.map +0 -1
- package/dist/chunk-MNOTKHSE.cjs +0 -367
- package/dist/chunk-MNOTKHSE.cjs.map +0 -1
- package/dist/chunk-RZTUH4QW.js +0 -361
- package/dist/chunk-RZTUH4QW.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-DVQ2siUx.d.cts +0 -134
- package/dist/types-DVQ2siUx.d.ts +0 -134
package/dist/index.cjs
CHANGED
|
@@ -1,142 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
const require_components = require('./components-Zv6v8ZAm.cjs');
|
|
2
|
+
const require_generators = require('./generators-ByyKDjyt.cjs');
|
|
3
|
+
const node_path = require_components.__toESM(require("node:path"));
|
|
4
|
+
const __kubb_core = require_components.__toESM(require("@kubb/core"));
|
|
5
|
+
const __kubb_core_transformers = require_components.__toESM(require("@kubb/core/transformers"));
|
|
6
|
+
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
7
|
+
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
8
|
+
const __kubb_plugin_zod = require_components.__toESM(require("@kubb/plugin-zod"));
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
return resolvedName;
|
|
103
|
-
},
|
|
104
|
-
async buildStart() {
|
|
105
|
-
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
106
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
107
|
-
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
108
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
109
|
-
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
110
|
-
if (baseURL) {
|
|
111
|
-
this.plugin.options.client.baseURL = baseURL;
|
|
112
|
-
}
|
|
113
|
-
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
114
|
-
oas,
|
|
115
|
-
pluginManager: this.pluginManager,
|
|
116
|
-
plugin: this.plugin,
|
|
117
|
-
contentType,
|
|
118
|
-
exclude,
|
|
119
|
-
include,
|
|
120
|
-
override,
|
|
121
|
-
mode
|
|
122
|
-
});
|
|
123
|
-
const files = await operationGenerator.build(...generators);
|
|
124
|
-
await this.addFile(...files);
|
|
125
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
126
|
-
type: output.barrelType ?? "named",
|
|
127
|
-
root,
|
|
128
|
-
output,
|
|
129
|
-
meta: {
|
|
130
|
-
pluginKey: this.plugin.key
|
|
131
|
-
},
|
|
132
|
-
logger: this.logger
|
|
133
|
-
});
|
|
134
|
-
await this.addFile(...barrelFiles);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
10
|
+
//#region src/plugin.ts
|
|
11
|
+
const pluginSwrName = "plugin-swr";
|
|
12
|
+
const pluginSwr = (0, __kubb_core.createPlugin)((options) => {
|
|
13
|
+
const { output = {
|
|
14
|
+
path: "hooks",
|
|
15
|
+
barrelType: "named"
|
|
16
|
+
}, 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;
|
|
17
|
+
return {
|
|
18
|
+
name: pluginSwrName,
|
|
19
|
+
options: {
|
|
20
|
+
output,
|
|
21
|
+
client: {
|
|
22
|
+
importPath: "@kubb/plugin-client/clients/axios",
|
|
23
|
+
dataReturnType: "data",
|
|
24
|
+
...client
|
|
25
|
+
},
|
|
26
|
+
queryKey,
|
|
27
|
+
query: query === false ? false : {
|
|
28
|
+
importPath: "swr",
|
|
29
|
+
methods: ["get"],
|
|
30
|
+
...query
|
|
31
|
+
},
|
|
32
|
+
mutationKey,
|
|
33
|
+
mutation: {
|
|
34
|
+
importPath: "swr/mutation",
|
|
35
|
+
methods: [
|
|
36
|
+
"post",
|
|
37
|
+
"put",
|
|
38
|
+
"delete",
|
|
39
|
+
"patch"
|
|
40
|
+
],
|
|
41
|
+
...mutation
|
|
42
|
+
},
|
|
43
|
+
parser,
|
|
44
|
+
paramsType,
|
|
45
|
+
pathParamsType,
|
|
46
|
+
paramsCasing,
|
|
47
|
+
group
|
|
48
|
+
},
|
|
49
|
+
pre: [
|
|
50
|
+
__kubb_plugin_oas.pluginOasName,
|
|
51
|
+
__kubb_plugin_ts.pluginTsName,
|
|
52
|
+
parser === "zod" ? __kubb_plugin_zod.pluginZodName : void 0
|
|
53
|
+
].filter(Boolean),
|
|
54
|
+
resolvePath(baseName, pathMode, options$1) {
|
|
55
|
+
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
56
|
+
const mode = pathMode ?? __kubb_core.FileManager.getMode(node_path.default.resolve(root, output.path));
|
|
57
|
+
if (mode === "single")
|
|
58
|
+
/**
|
|
59
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
60
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
61
|
+
*/
|
|
62
|
+
return node_path.default.resolve(root, output.path);
|
|
63
|
+
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
64
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
65
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
66
|
+
return `${(0, __kubb_core_transformers.camelCase)(ctx.group)}Controller`;
|
|
67
|
+
};
|
|
68
|
+
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
69
|
+
}
|
|
70
|
+
return node_path.default.resolve(root, output.path, baseName);
|
|
71
|
+
},
|
|
72
|
+
resolveName(name, type) {
|
|
73
|
+
let resolvedName = (0, __kubb_core_transformers.camelCase)(name);
|
|
74
|
+
if (type === "file" || type === "function") resolvedName = (0, __kubb_core_transformers.camelCase)(name, { isFile: type === "file" });
|
|
75
|
+
if (type === "type") resolvedName = (0, __kubb_core_transformers.pascalCase)(name);
|
|
76
|
+
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
77
|
+
return resolvedName;
|
|
78
|
+
},
|
|
79
|
+
async buildStart() {
|
|
80
|
+
const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
|
|
81
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
82
|
+
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
83
|
+
const mode = __kubb_core.FileManager.getMode(node_path.default.resolve(root, output.path));
|
|
84
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
85
|
+
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
86
|
+
const operationGenerator = new __kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
87
|
+
oas,
|
|
88
|
+
pluginManager: this.pluginManager,
|
|
89
|
+
plugin: this.plugin,
|
|
90
|
+
contentType,
|
|
91
|
+
exclude,
|
|
92
|
+
include,
|
|
93
|
+
override,
|
|
94
|
+
mode
|
|
95
|
+
});
|
|
96
|
+
const files = await operationGenerator.build(...generators);
|
|
97
|
+
await this.addFile(...files);
|
|
98
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
99
|
+
type: output.barrelType ?? "named",
|
|
100
|
+
root,
|
|
101
|
+
output,
|
|
102
|
+
meta: { pluginKey: this.plugin.key },
|
|
103
|
+
logger: this.logger
|
|
104
|
+
});
|
|
105
|
+
await this.addFile(...barrelFiles);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
137
108
|
});
|
|
138
109
|
|
|
110
|
+
//#endregion
|
|
139
111
|
exports.pluginSwr = pluginSwr;
|
|
140
112
|
exports.pluginSwrName = pluginSwrName;
|
|
141
|
-
//# sourceMappingURL=index.cjs.map
|
|
142
113
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","groupName: Group['name']","PluginManager","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/clients/axios',\n dataReturnType: 'data',\n ...client,\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 ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n 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 buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 this.fileManager.getBarrelFiles({\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":";;;;;;;;;;AAeA,MAAa,gBAAgB;AAE7B,MAAa,0CAAoC,CAAC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;CAAS,GAC/C,OACA,UAAU,CAAE,GACZ,SACA,WAAW,CAAE,GACb,SAAS,UACT,eAAe,CAAE,GACjB,OACA,UACA,QACA,aAAa,UACb,iBAAiB,eAAe,WAAW,WAAW,QAAQ,kBAAkB,UAChF,cAAcA,+BAAY,gBAC1B,WAAWC,4BAAS,gBACpB,aAAa,CAACC,mCAAgBC,oCAAkB,EAAC,OAAO,QAAQ,EAChE,cACA,a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,QACX,wDAA0B,KAAK;AAGjC,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;EACR;EACD,MAAM,aAAa;GACjB,MAAM,CAAC,cAA8C,GAAGG,0BAAc,mBAAyC,KAAK,SAAS,CAACP,+BAAc,EAAC;GAE7I,MAAM,MAAM,MAAM,cAAc,QAAQ,QAAQ;GAChD,MAAM,OAAOI,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAOC,wBAAY,QAAQD,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACjE,MAAM,UAAU,MAAM,cAAc,QAAQ,YAAY;AAExD,OAAI,SACF,KAAK,OAAO,QAAQ,OAAO,UAAU;GAEvC,MAAM,qBAAqB,IAAII,qCAAmB,KAAK,OAAO,SAAS;IACrE;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;GACD;GAED,MAAM,QAAQ,MAAM,mBAAmB,MAAM,GAAG,WAAW;GAC3D,MAAM,KAAK,QAAQ,GAAG,MAAM;GAE5B,MAAM,cAAc,MAAM,KAAK,YAAY,eAAe;IACxD,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,IACxB;IACD,QAAQ,KAAK;GACd,EAAC;GAEF,MAAM,KAAK,QAAQ,GAAG,YAAY;EACnC;CACF;AACF,EAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { O as Options, P as PluginSwr } from './types-DVQ2siUx.cjs';
|
|
3
|
-
import '@kubb/oas';
|
|
4
|
-
import '@kubb/plugin-client';
|
|
5
|
-
import '@kubb/plugin-oas';
|
|
1
|
+
import { Options, PluginSwr, UserPluginWithLifeCycle } from "./types-CjDGkyWH.cjs";
|
|
6
2
|
|
|
3
|
+
//#region src/plugin.d.ts
|
|
7
4
|
declare const pluginSwrName = "plugin-swr";
|
|
8
|
-
declare const pluginSwr: (options?: Options | undefined) =>
|
|
9
|
-
|
|
10
|
-
export { PluginSwr, pluginSwr, pluginSwrName };
|
|
5
|
+
declare const pluginSwr: (options?: Options | undefined) => UserPluginWithLifeCycle<PluginSwr>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type PluginSwr, pluginSwr, pluginSwrName };
|
|
8
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { O as Options, P as PluginSwr } from './types-DVQ2siUx.js';
|
|
3
|
-
import '@kubb/oas';
|
|
4
|
-
import '@kubb/plugin-client';
|
|
5
|
-
import '@kubb/plugin-oas';
|
|
1
|
+
import { Options, PluginSwr, UserPluginWithLifeCycle } from "./types-CSnGy9Uj.js";
|
|
6
2
|
|
|
3
|
+
//#region src/plugin.d.ts
|
|
7
4
|
declare const pluginSwrName = "plugin-swr";
|
|
8
|
-
declare const pluginSwr: (options?: Options | undefined) =>
|
|
9
|
-
|
|
10
|
-
export { PluginSwr, pluginSwr, pluginSwrName };
|
|
5
|
+
declare const pluginSwr: (options?: Options | undefined) => UserPluginWithLifeCycle<PluginSwr>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type PluginSwr, pluginSwr, pluginSwrName };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,135 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import path from
|
|
4
|
-
import {
|
|
5
|
-
import { camelCase, pascalCase } from
|
|
6
|
-
import {
|
|
7
|
-
import { pluginTsName } from
|
|
8
|
-
import { pluginZodName } from
|
|
1
|
+
import { MutationKey, QueryKey } from "./components-BQIcQmn3.js";
|
|
2
|
+
import { mutationGenerator, queryGenerator } from "./generators-B-fWjDXL.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
5
|
+
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
6
|
+
import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
7
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
8
|
+
import { pluginZodName } from "@kubb/plugin-zod";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
oas,
|
|
109
|
-
pluginManager: this.pluginManager,
|
|
110
|
-
plugin: this.plugin,
|
|
111
|
-
contentType,
|
|
112
|
-
exclude,
|
|
113
|
-
include,
|
|
114
|
-
override,
|
|
115
|
-
mode
|
|
116
|
-
});
|
|
117
|
-
const files = await operationGenerator.build(...generators);
|
|
118
|
-
await this.addFile(...files);
|
|
119
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
120
|
-
type: output.barrelType ?? "named",
|
|
121
|
-
root,
|
|
122
|
-
output,
|
|
123
|
-
meta: {
|
|
124
|
-
pluginKey: this.plugin.key
|
|
125
|
-
},
|
|
126
|
-
logger: this.logger
|
|
127
|
-
});
|
|
128
|
-
await this.addFile(...barrelFiles);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
10
|
+
//#region src/plugin.ts
|
|
11
|
+
const pluginSwrName = "plugin-swr";
|
|
12
|
+
const pluginSwr = createPlugin((options) => {
|
|
13
|
+
const { output = {
|
|
14
|
+
path: "hooks",
|
|
15
|
+
barrelType: "named"
|
|
16
|
+
}, 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;
|
|
17
|
+
return {
|
|
18
|
+
name: pluginSwrName,
|
|
19
|
+
options: {
|
|
20
|
+
output,
|
|
21
|
+
client: {
|
|
22
|
+
importPath: "@kubb/plugin-client/clients/axios",
|
|
23
|
+
dataReturnType: "data",
|
|
24
|
+
...client
|
|
25
|
+
},
|
|
26
|
+
queryKey,
|
|
27
|
+
query: query === false ? false : {
|
|
28
|
+
importPath: "swr",
|
|
29
|
+
methods: ["get"],
|
|
30
|
+
...query
|
|
31
|
+
},
|
|
32
|
+
mutationKey,
|
|
33
|
+
mutation: {
|
|
34
|
+
importPath: "swr/mutation",
|
|
35
|
+
methods: [
|
|
36
|
+
"post",
|
|
37
|
+
"put",
|
|
38
|
+
"delete",
|
|
39
|
+
"patch"
|
|
40
|
+
],
|
|
41
|
+
...mutation
|
|
42
|
+
},
|
|
43
|
+
parser,
|
|
44
|
+
paramsType,
|
|
45
|
+
pathParamsType,
|
|
46
|
+
paramsCasing,
|
|
47
|
+
group
|
|
48
|
+
},
|
|
49
|
+
pre: [
|
|
50
|
+
pluginOasName,
|
|
51
|
+
pluginTsName,
|
|
52
|
+
parser === "zod" ? pluginZodName : void 0
|
|
53
|
+
].filter(Boolean),
|
|
54
|
+
resolvePath(baseName, pathMode, options$1) {
|
|
55
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
56
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
57
|
+
if (mode === "single")
|
|
58
|
+
/**
|
|
59
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
60
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
61
|
+
*/
|
|
62
|
+
return path.resolve(root, output.path);
|
|
63
|
+
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
64
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
65
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
66
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
67
|
+
};
|
|
68
|
+
return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
69
|
+
}
|
|
70
|
+
return path.resolve(root, output.path, baseName);
|
|
71
|
+
},
|
|
72
|
+
resolveName(name, type) {
|
|
73
|
+
let resolvedName = camelCase(name);
|
|
74
|
+
if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
|
|
75
|
+
if (type === "type") resolvedName = pascalCase(name);
|
|
76
|
+
if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
77
|
+
return resolvedName;
|
|
78
|
+
},
|
|
79
|
+
async buildStart() {
|
|
80
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
81
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
82
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
83
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
84
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
85
|
+
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
86
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
87
|
+
oas,
|
|
88
|
+
pluginManager: this.pluginManager,
|
|
89
|
+
plugin: this.plugin,
|
|
90
|
+
contentType,
|
|
91
|
+
exclude,
|
|
92
|
+
include,
|
|
93
|
+
override,
|
|
94
|
+
mode
|
|
95
|
+
});
|
|
96
|
+
const files = await operationGenerator.build(...generators);
|
|
97
|
+
await this.addFile(...files);
|
|
98
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
99
|
+
type: output.barrelType ?? "named",
|
|
100
|
+
root,
|
|
101
|
+
output,
|
|
102
|
+
meta: { pluginKey: this.plugin.key },
|
|
103
|
+
logger: this.logger
|
|
104
|
+
});
|
|
105
|
+
await this.addFile(...barrelFiles);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
131
108
|
});
|
|
132
109
|
|
|
110
|
+
//#endregion
|
|
133
111
|
export { pluginSwr, pluginSwrName };
|
|
134
|
-
//# sourceMappingURL=index.js.map
|
|
135
112
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/clients/axios',\n dataReturnType: 'data',\n ...client,\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 ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n 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 buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 this.fileManager.getBarrelFiles({\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":";;;;;;;;;;AAeA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,aAAwB,CAAC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;CAAS,GAC/C,OACA,UAAU,CAAE,GACZ,SACA,WAAW,CAAE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