@kubb/plugin-swr 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/chunk-2KDZWGWG.js +342 -0
- package/dist/chunk-2KDZWGWG.js.map +1 -0
- package/dist/chunk-64KLXAGI.cjs +237 -0
- package/dist/chunk-64KLXAGI.cjs.map +1 -0
- package/dist/chunk-AFAHUG3Q.cjs +348 -0
- package/dist/chunk-AFAHUG3Q.cjs.map +1 -0
- package/dist/chunk-T6K6P5I7.js +234 -0
- package/dist/chunk-T6K6P5I7.js.map +1 -0
- package/dist/components.cjs +28 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +95 -0
- package/dist/components.d.ts +95 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +11 -0
- package/dist/generators.d.ts +11 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +127 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -0
- package/dist/types-AhGZx7jH.d.cts +272 -0
- package/dist/types-AhGZx7jH.d.ts +272 -0
- package/package.json +104 -0
- package/src/components/Mutation.tsx +129 -0
- package/src/components/MutationKey.tsx +54 -0
- package/src/components/Query.tsx +175 -0
- package/src/components/QueryKey.tsx +83 -0
- package/src/components/QueryOptions.tsx +116 -0
- package/src/components/index.ts +5 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +49 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +49 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
- package/src/generators/__snapshots__/findByTags.ts +49 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +49 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +49 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +49 -0
- package/src/generators/__snapshots__/getAsMutation.ts +34 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +32 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mutationGenerator.tsx +117 -0
- package/src/generators/queryGenerator.tsx +127 -0
- package/src/index.ts +4 -0
- package/src/plugin.ts +141 -0
- package/src/types.ts +126 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk64KLXAGI_cjs = require('./chunk-64KLXAGI.cjs');
|
|
4
|
+
var chunkAFAHUG3Q_cjs = require('./chunk-AFAHUG3Q.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers = require('@kubb/core/transformers');
|
|
8
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
9
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
10
|
+
var pluginZod = require('@kubb/plugin-zod');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
|
+
|
|
16
|
+
var pluginSwrName = "plugin-swr";
|
|
17
|
+
var pluginSwr = core.createPlugin((options) => {
|
|
18
|
+
const {
|
|
19
|
+
output = { path: "hooks", barrelType: "named" },
|
|
20
|
+
group,
|
|
21
|
+
exclude = [],
|
|
22
|
+
include,
|
|
23
|
+
override = [],
|
|
24
|
+
parser = "client",
|
|
25
|
+
transformers: transformers$1 = {},
|
|
26
|
+
query,
|
|
27
|
+
mutation,
|
|
28
|
+
client,
|
|
29
|
+
paramsType = "inline",
|
|
30
|
+
pathParamsType = "inline",
|
|
31
|
+
mutationKey = chunkAFAHUG3Q_cjs.MutationKey.getTransformer,
|
|
32
|
+
queryKey = chunkAFAHUG3Q_cjs.QueryKey.getTransformer,
|
|
33
|
+
generators = [chunk64KLXAGI_cjs.queryGenerator, chunk64KLXAGI_cjs.mutationGenerator].filter(Boolean)
|
|
34
|
+
} = options;
|
|
35
|
+
return {
|
|
36
|
+
name: pluginSwrName,
|
|
37
|
+
options: {
|
|
38
|
+
output,
|
|
39
|
+
client: {
|
|
40
|
+
importPath: "@kubb/plugin-client/client",
|
|
41
|
+
dataReturnType: "data",
|
|
42
|
+
...client
|
|
43
|
+
},
|
|
44
|
+
queryKey,
|
|
45
|
+
query: {
|
|
46
|
+
importPath: "swr",
|
|
47
|
+
methods: ["get"],
|
|
48
|
+
...query
|
|
49
|
+
},
|
|
50
|
+
mutationKey,
|
|
51
|
+
mutation: {
|
|
52
|
+
importPath: "swr/mutation",
|
|
53
|
+
methods: ["post", "put", "delete", "patch"],
|
|
54
|
+
...mutation
|
|
55
|
+
},
|
|
56
|
+
parser,
|
|
57
|
+
paramsType,
|
|
58
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType
|
|
59
|
+
},
|
|
60
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
|
|
61
|
+
resolvePath(baseName, pathMode, options2) {
|
|
62
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
63
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
64
|
+
if (options2?.tag && group?.type === "tag") {
|
|
65
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
66
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
67
|
+
}
|
|
68
|
+
if (mode === "single") {
|
|
69
|
+
return path__default.default.resolve(root, output.path);
|
|
70
|
+
}
|
|
71
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
72
|
+
},
|
|
73
|
+
resolveName(name, type) {
|
|
74
|
+
let resolvedName = transformers.camelCase(name);
|
|
75
|
+
if (type === "file" || type === "function") {
|
|
76
|
+
resolvedName = transformers.camelCase(name, {
|
|
77
|
+
isFile: type === "file"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (type === "type") {
|
|
81
|
+
resolvedName = transformers.pascalCase(name);
|
|
82
|
+
}
|
|
83
|
+
if (type) {
|
|
84
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
85
|
+
}
|
|
86
|
+
return resolvedName;
|
|
87
|
+
},
|
|
88
|
+
async buildStart() {
|
|
89
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
90
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
91
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
92
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
93
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
94
|
+
if (baseURL) {
|
|
95
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
96
|
+
}
|
|
97
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
98
|
+
oas,
|
|
99
|
+
pluginManager: this.pluginManager,
|
|
100
|
+
plugin: this.plugin,
|
|
101
|
+
contentType: swaggerPlugin.context.contentType,
|
|
102
|
+
exclude,
|
|
103
|
+
include,
|
|
104
|
+
override,
|
|
105
|
+
mode
|
|
106
|
+
});
|
|
107
|
+
const files = await operationGenerator.build(...generators);
|
|
108
|
+
await this.addFile(...files);
|
|
109
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
110
|
+
type: output.barrelType ?? "named",
|
|
111
|
+
root,
|
|
112
|
+
output,
|
|
113
|
+
files: this.fileManager.files,
|
|
114
|
+
meta: {
|
|
115
|
+
pluginKey: this.plugin.key
|
|
116
|
+
},
|
|
117
|
+
logger: this.logger
|
|
118
|
+
});
|
|
119
|
+
await this.addFile(...barrelFiles);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
exports.pluginSwr = pluginSwr;
|
|
125
|
+
exports.pluginSwrName = pluginSwrName;
|
|
126
|
+
//# sourceMappingURL=index.cjs.map
|
|
127
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,kBACTC,iBAAe,EAAC;AAAA,IAChB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAa,GAAA,QAAA;AAAA,IACb,cAAiB,GAAA,QAAA;AAAA,IACjB,cAAcC,6BAAY,CAAA,cAAA;AAAA,IAC1B,WAAWC,0BAAS,CAAA,cAAA;AAAA,IACpB,aAAa,CAACC,gCAAA,EAAgBC,mCAAiB,CAAA,CAAE,OAAO,OAAO;AAAA,GAC7D,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,4BAAA;AAAA,QACZ,cAAgB,EAAA,MAAA;AA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,CAAO,IAAI,CAAC,CAAA;AAChE,MAAA,MAAM,OAAU,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,UAAW,EAAA;AAEvD,MAAA,IAAI,OAAS,EAAA;AACX,QAAK,IAAA,CAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,CAAO,OAAU,GAAA,OAAA;AAAA;AAEvC,MAAA,MAAM,kBAAqB,GAAA,IAAIK,4BAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","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 = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query: {\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: paramsType === 'object' ? 'object' : pathParamsType,\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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: swaggerPlugin.context.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 files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginSwr } from './types-AhGZx7jH.cjs';
|
|
3
|
+
import '@kubb/oas';
|
|
4
|
+
import '@kubb/plugin-client';
|
|
5
|
+
import '@kubb/plugin-oas';
|
|
6
|
+
|
|
7
|
+
declare const pluginSwrName = "plugin-swr";
|
|
8
|
+
declare const pluginSwr: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
|
|
9
|
+
|
|
10
|
+
export { PluginSwr, pluginSwr, pluginSwrName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginSwr } from './types-AhGZx7jH.js';
|
|
3
|
+
import '@kubb/oas';
|
|
4
|
+
import '@kubb/plugin-client';
|
|
5
|
+
import '@kubb/plugin-oas';
|
|
6
|
+
|
|
7
|
+
declare const pluginSwrName = "plugin-swr";
|
|
8
|
+
declare const pluginSwr: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginSwr>;
|
|
9
|
+
|
|
10
|
+
export { PluginSwr, pluginSwr, pluginSwrName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { queryGenerator, mutationGenerator } from './chunk-T6K6P5I7.js';
|
|
2
|
+
import { MutationKey, QueryKey } from './chunk-2KDZWGWG.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
|
+
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
+
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
8
|
+
import { pluginZodName } from '@kubb/plugin-zod';
|
|
9
|
+
|
|
10
|
+
var pluginSwrName = "plugin-swr";
|
|
11
|
+
var pluginSwr = createPlugin((options) => {
|
|
12
|
+
const {
|
|
13
|
+
output = { path: "hooks", barrelType: "named" },
|
|
14
|
+
group,
|
|
15
|
+
exclude = [],
|
|
16
|
+
include,
|
|
17
|
+
override = [],
|
|
18
|
+
parser = "client",
|
|
19
|
+
transformers = {},
|
|
20
|
+
query,
|
|
21
|
+
mutation,
|
|
22
|
+
client,
|
|
23
|
+
paramsType = "inline",
|
|
24
|
+
pathParamsType = "inline",
|
|
25
|
+
mutationKey = MutationKey.getTransformer,
|
|
26
|
+
queryKey = QueryKey.getTransformer,
|
|
27
|
+
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
28
|
+
} = options;
|
|
29
|
+
return {
|
|
30
|
+
name: pluginSwrName,
|
|
31
|
+
options: {
|
|
32
|
+
output,
|
|
33
|
+
client: {
|
|
34
|
+
importPath: "@kubb/plugin-client/client",
|
|
35
|
+
dataReturnType: "data",
|
|
36
|
+
...client
|
|
37
|
+
},
|
|
38
|
+
queryKey,
|
|
39
|
+
query: {
|
|
40
|
+
importPath: "swr",
|
|
41
|
+
methods: ["get"],
|
|
42
|
+
...query
|
|
43
|
+
},
|
|
44
|
+
mutationKey,
|
|
45
|
+
mutation: {
|
|
46
|
+
importPath: "swr/mutation",
|
|
47
|
+
methods: ["post", "put", "delete", "patch"],
|
|
48
|
+
...mutation
|
|
49
|
+
},
|
|
50
|
+
parser,
|
|
51
|
+
paramsType,
|
|
52
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType
|
|
53
|
+
},
|
|
54
|
+
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
55
|
+
resolvePath(baseName, pathMode, options2) {
|
|
56
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
57
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
58
|
+
if (options2?.tag && group?.type === "tag") {
|
|
59
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
60
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
61
|
+
}
|
|
62
|
+
if (mode === "single") {
|
|
63
|
+
return path.resolve(root, output.path);
|
|
64
|
+
}
|
|
65
|
+
return path.resolve(root, output.path, baseName);
|
|
66
|
+
},
|
|
67
|
+
resolveName(name, type) {
|
|
68
|
+
let resolvedName = camelCase(name);
|
|
69
|
+
if (type === "file" || type === "function") {
|
|
70
|
+
resolvedName = camelCase(name, {
|
|
71
|
+
isFile: type === "file"
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (type === "type") {
|
|
75
|
+
resolvedName = pascalCase(name);
|
|
76
|
+
}
|
|
77
|
+
if (type) {
|
|
78
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
79
|
+
}
|
|
80
|
+
return resolvedName;
|
|
81
|
+
},
|
|
82
|
+
async buildStart() {
|
|
83
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
84
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
85
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
86
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
87
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
88
|
+
if (baseURL) {
|
|
89
|
+
this.plugin.options.client.baseURL = baseURL;
|
|
90
|
+
}
|
|
91
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
92
|
+
oas,
|
|
93
|
+
pluginManager: this.pluginManager,
|
|
94
|
+
plugin: this.plugin,
|
|
95
|
+
contentType: swaggerPlugin.context.contentType,
|
|
96
|
+
exclude,
|
|
97
|
+
include,
|
|
98
|
+
override,
|
|
99
|
+
mode
|
|
100
|
+
});
|
|
101
|
+
const files = await operationGenerator.build(...generators);
|
|
102
|
+
await this.addFile(...files);
|
|
103
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
104
|
+
type: output.barrelType ?? "named",
|
|
105
|
+
root,
|
|
106
|
+
output,
|
|
107
|
+
files: this.fileManager.files,
|
|
108
|
+
meta: {
|
|
109
|
+
pluginKey: this.plugin.key
|
|
110
|
+
},
|
|
111
|
+
logger: this.logger
|
|
112
|
+
});
|
|
113
|
+
await this.addFile(...barrelFiles);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export { pluginSwr, pluginSwrName };
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAeO,IAAM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ED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","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 = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query: {\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: paramsType === 'object' ? 'object' : pathParamsType,\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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: swaggerPlugin.context.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 files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { HttpMethod, Operation } from '@kubb/oas';
|
|
3
|
+
import { PluginClient } from '@kubb/plugin-client';
|
|
4
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
|
|
5
|
+
|
|
6
|
+
type TransformerProps$1 = {
|
|
7
|
+
operation: Operation;
|
|
8
|
+
schemas: OperationSchemas;
|
|
9
|
+
};
|
|
10
|
+
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
11
|
+
type Suspense = object;
|
|
12
|
+
/**
|
|
13
|
+
* Customize the queryKey
|
|
14
|
+
*/
|
|
15
|
+
type QueryKey$1 = Transformer$1;
|
|
16
|
+
/**
|
|
17
|
+
* Customize the mutationKey
|
|
18
|
+
*/
|
|
19
|
+
type MutationKey$1 = Transformer$1;
|
|
20
|
+
type Query$1 = {
|
|
21
|
+
/**
|
|
22
|
+
* Define which HttpMethods can be used for queries
|
|
23
|
+
* @default ['get']
|
|
24
|
+
*/
|
|
25
|
+
methods: Array<HttpMethod>;
|
|
26
|
+
/**
|
|
27
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
28
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
29
|
+
* It allows both relative and absolute path.
|
|
30
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
31
|
+
* @default '@tanstack/react-query'
|
|
32
|
+
*/
|
|
33
|
+
importPath?: string;
|
|
34
|
+
};
|
|
35
|
+
type Mutation$1 = {
|
|
36
|
+
/**
|
|
37
|
+
* Define which HttpMethods can be used for mutations
|
|
38
|
+
* @default ['post', 'put', 'delete']
|
|
39
|
+
*/
|
|
40
|
+
methods: Array<HttpMethod>;
|
|
41
|
+
/**
|
|
42
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
43
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
44
|
+
* It allows both relative and absolute path.
|
|
45
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
46
|
+
* @default '@tanstack/react-query'
|
|
47
|
+
*/
|
|
48
|
+
importPath?: string;
|
|
49
|
+
};
|
|
50
|
+
type Infinite = {
|
|
51
|
+
/**
|
|
52
|
+
* Specify the params key used for `pageParam`.
|
|
53
|
+
* @default 'id'
|
|
54
|
+
*/
|
|
55
|
+
queryParam: string;
|
|
56
|
+
/**
|
|
57
|
+
* Which field of the data will be used, set it to undefined when no cursor is known.
|
|
58
|
+
*/
|
|
59
|
+
cursorParam?: string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The initial value, the value of the first page.
|
|
62
|
+
* @default 0
|
|
63
|
+
*/
|
|
64
|
+
initialPageParam: unknown;
|
|
65
|
+
};
|
|
66
|
+
type Options$1 = {
|
|
67
|
+
/**
|
|
68
|
+
* Specify the export location for the files and define the behavior of the output
|
|
69
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
70
|
+
*/
|
|
71
|
+
output?: Output;
|
|
72
|
+
/**
|
|
73
|
+
* Group the @tanstack/query hooks based on the provided name.
|
|
74
|
+
*/
|
|
75
|
+
group?: Group;
|
|
76
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
77
|
+
/**
|
|
78
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
79
|
+
*/
|
|
80
|
+
exclude?: Array<Exclude>;
|
|
81
|
+
/**
|
|
82
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
83
|
+
*/
|
|
84
|
+
include?: Array<Include>;
|
|
85
|
+
/**
|
|
86
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
87
|
+
*/
|
|
88
|
+
override?: Array<Override<ResolvedOptions$1>>;
|
|
89
|
+
/**
|
|
90
|
+
* How to pass your params
|
|
91
|
+
* - 'object' will return the params and pathParams as an object.
|
|
92
|
+
* - 'inline' will return the params as comma separated params.
|
|
93
|
+
* @default 'inline'
|
|
94
|
+
*/
|
|
95
|
+
paramsType?: 'object' | 'inline';
|
|
96
|
+
/**
|
|
97
|
+
* How to pass your pathParams.
|
|
98
|
+
* - 'object' will return the pathParams as an object.
|
|
99
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
100
|
+
* @default 'inline'
|
|
101
|
+
*/
|
|
102
|
+
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
103
|
+
/**
|
|
104
|
+
* When set, an infiniteQuery hooks will be added.
|
|
105
|
+
*/
|
|
106
|
+
infinite?: Partial<Infinite> | false;
|
|
107
|
+
/**
|
|
108
|
+
* When set, a suspenseQuery hooks will be added.
|
|
109
|
+
*/
|
|
110
|
+
suspense?: Partial<Suspense> | false;
|
|
111
|
+
queryKey?: QueryKey$1;
|
|
112
|
+
/**
|
|
113
|
+
* Override some useQuery behaviours.
|
|
114
|
+
*/
|
|
115
|
+
query?: Partial<Query$1> | false;
|
|
116
|
+
mutationKey?: MutationKey$1;
|
|
117
|
+
/**
|
|
118
|
+
* Override some useMutation behaviours.
|
|
119
|
+
*/
|
|
120
|
+
mutation?: Partial<Mutation$1> | false;
|
|
121
|
+
/**
|
|
122
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
123
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
124
|
+
*/
|
|
125
|
+
parser?: PluginClient['options']['parser'];
|
|
126
|
+
transformers?: {
|
|
127
|
+
/**
|
|
128
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
129
|
+
*/
|
|
130
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Define some generators next to the react-query generators
|
|
134
|
+
*/
|
|
135
|
+
generators?: Array<Generator<PluginReactQuery>>;
|
|
136
|
+
};
|
|
137
|
+
type ResolvedOptions$1 = {
|
|
138
|
+
output: Output;
|
|
139
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
140
|
+
baseURL?: string;
|
|
141
|
+
};
|
|
142
|
+
parser: Required<NonNullable<Options$1['parser']>>;
|
|
143
|
+
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
144
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
145
|
+
/**
|
|
146
|
+
* Only used of infinite
|
|
147
|
+
*/
|
|
148
|
+
infinite: NonNullable<Infinite> | false;
|
|
149
|
+
suspense: Suspense | false;
|
|
150
|
+
queryKey: QueryKey$1 | undefined;
|
|
151
|
+
query: NonNullable<Required<Query$1>> | false;
|
|
152
|
+
mutationKey: MutationKey$1 | undefined;
|
|
153
|
+
mutation: NonNullable<Required<Mutation$1>> | false;
|
|
154
|
+
};
|
|
155
|
+
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
156
|
+
|
|
157
|
+
type TransformerProps = {
|
|
158
|
+
operation: Operation;
|
|
159
|
+
schemas: OperationSchemas;
|
|
160
|
+
};
|
|
161
|
+
type Transformer = (props: TransformerProps) => unknown[];
|
|
162
|
+
/**
|
|
163
|
+
* Customize the queryKey
|
|
164
|
+
*/
|
|
165
|
+
type QueryKey = Transformer;
|
|
166
|
+
/**
|
|
167
|
+
* Customize the mutationKey
|
|
168
|
+
*/
|
|
169
|
+
type MutationKey = Transformer;
|
|
170
|
+
type Query = {
|
|
171
|
+
/**
|
|
172
|
+
* Define which HttpMethods can be used for queries
|
|
173
|
+
* @default ['get']
|
|
174
|
+
*/
|
|
175
|
+
methods?: Array<HttpMethod>;
|
|
176
|
+
/**
|
|
177
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
178
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
179
|
+
* It allows both relative and absolute path.
|
|
180
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
181
|
+
* @default 'swr'
|
|
182
|
+
*/
|
|
183
|
+
importPath?: string;
|
|
184
|
+
};
|
|
185
|
+
type Mutation = {
|
|
186
|
+
/**
|
|
187
|
+
* Define which HttpMethods can be used for queries
|
|
188
|
+
* @default ['post', 'put', 'delete', 'patch']
|
|
189
|
+
*/
|
|
190
|
+
methods?: Array<HttpMethod>;
|
|
191
|
+
/**
|
|
192
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
193
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
194
|
+
* It allows both relative and absolute path.
|
|
195
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
196
|
+
* @default 'swr/mutation'
|
|
197
|
+
*/
|
|
198
|
+
importPath?: string;
|
|
199
|
+
};
|
|
200
|
+
type Options = {
|
|
201
|
+
/**
|
|
202
|
+
* Specify the export location for the files and define the behavior of the output
|
|
203
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
204
|
+
*/
|
|
205
|
+
output?: Output;
|
|
206
|
+
/**
|
|
207
|
+
* Group the SWR hooks based on the provided name.
|
|
208
|
+
*/
|
|
209
|
+
group?: Group;
|
|
210
|
+
/**
|
|
211
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
212
|
+
*/
|
|
213
|
+
exclude?: Array<Exclude>;
|
|
214
|
+
/**
|
|
215
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
216
|
+
*/
|
|
217
|
+
include?: Array<Include>;
|
|
218
|
+
/**
|
|
219
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
220
|
+
*/
|
|
221
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
222
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
223
|
+
queryKey?: QueryKey;
|
|
224
|
+
query?: Query | false;
|
|
225
|
+
mutationKey?: MutationKey;
|
|
226
|
+
mutation?: Mutation | false;
|
|
227
|
+
/**
|
|
228
|
+
* How to pass your params
|
|
229
|
+
* - 'object' will return the params and pathParams as an object.
|
|
230
|
+
* - 'inline' will return the params as comma separated params.
|
|
231
|
+
* @default 'inline'
|
|
232
|
+
*/
|
|
233
|
+
paramsType?: 'object' | 'inline';
|
|
234
|
+
/**
|
|
235
|
+
* How to pass your pathParams.
|
|
236
|
+
* - 'object' will return the pathParams as an object.
|
|
237
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
238
|
+
* @default 'inline'
|
|
239
|
+
*/
|
|
240
|
+
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
241
|
+
/**
|
|
242
|
+
* Which parser should be used before returning the data to `swr`.
|
|
243
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
244
|
+
*/
|
|
245
|
+
parser?: PluginClient['options']['parser'];
|
|
246
|
+
transformers?: {
|
|
247
|
+
/**
|
|
248
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
249
|
+
*/
|
|
250
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Define some generators next to the swr generators
|
|
254
|
+
*/
|
|
255
|
+
generators?: Array<Generator<PluginSwr>>;
|
|
256
|
+
};
|
|
257
|
+
type ResolvedOptions = {
|
|
258
|
+
output: Output;
|
|
259
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
260
|
+
baseURL?: string;
|
|
261
|
+
};
|
|
262
|
+
parser: Required<NonNullable<Options['parser']>>;
|
|
263
|
+
queryKey: QueryKey | undefined;
|
|
264
|
+
query: NonNullable<Required<Query>> | false;
|
|
265
|
+
mutationKey: MutationKey | undefined;
|
|
266
|
+
mutation: NonNullable<Required<Mutation>> | false;
|
|
267
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
268
|
+
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
269
|
+
};
|
|
270
|
+
type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
271
|
+
|
|
272
|
+
export type { Options as O, PluginSwr as P, Transformer as T };
|