@kubb/plugin-swr 3.1.0 → 3.2.0
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/{chunk-23A6KPTG.js → chunk-4EFF327C.js} +10 -3
- package/dist/chunk-4EFF327C.js.map +1 -0
- package/dist/{chunk-ZO4CRCE6.cjs → chunk-4ZIGOWYH.cjs} +15 -8
- package/dist/chunk-4ZIGOWYH.cjs.map +1 -0
- package/dist/{chunk-HOCARL2F.js → chunk-7ELDJ4IB.js} +33 -24
- package/dist/chunk-7ELDJ4IB.js.map +1 -0
- package/dist/{chunk-442Q5BKM.cjs → chunk-DJ57MWSH.cjs} +33 -24
- package/dist/chunk-DJ57MWSH.cjs.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +15 -8
- package/dist/components.d.ts +15 -8
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-C68y96t2.d.cts → types-CwvU4w1t.d.cts} +14 -0
- package/dist/{types-C68y96t2.d.ts → types-CwvU4w1t.d.ts} +14 -0
- package/package.json +12 -12
- package/src/components/Mutation.tsx +7 -2
- package/src/components/MutationKey.tsx +5 -4
- package/src/components/Query.tsx +9 -3
- package/src/components/QueryKey.tsx +9 -6
- package/src/components/QueryOptions.tsx +8 -5
- package/src/generators/mutationGenerator.tsx +3 -0
- package/src/generators/queryGenerator.tsx +4 -0
- package/src/plugin.ts +2 -0
- package/src/types.ts +7 -0
- package/dist/chunk-23A6KPTG.js.map +0 -1
- package/dist/chunk-442Q5BKM.cjs.map +0 -1
- package/dist/chunk-HOCARL2F.js.map +0 -1
- package/dist/chunk-ZO4CRCE6.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { queryGenerator, mutationGenerator } from './chunk-
|
|
2
|
-
import { MutationKey, QueryKey } from './chunk-
|
|
1
|
+
import { queryGenerator, mutationGenerator } from './chunk-4EFF327C.js';
|
|
2
|
+
import { MutationKey, QueryKey } from './chunk-7ELDJ4IB.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
@@ -24,7 +24,8 @@ var pluginSwr = createPlugin((options) => {
|
|
|
24
24
|
pathParamsType = "inline",
|
|
25
25
|
mutationKey = MutationKey.getTransformer,
|
|
26
26
|
queryKey = QueryKey.getTransformer,
|
|
27
|
-
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
27
|
+
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
28
|
+
paramsCasing
|
|
28
29
|
} = options;
|
|
29
30
|
return {
|
|
30
31
|
name: pluginSwrName,
|
|
@@ -50,6 +51,7 @@ var pluginSwr = createPlugin((options) => {
|
|
|
50
51
|
parser,
|
|
51
52
|
paramsType,
|
|
52
53
|
pathParamsType: paramsType === "object" ? "object" : pathParamsType,
|
|
54
|
+
paramsCasing,
|
|
53
55
|
group
|
|
54
56
|
},
|
|
55
57
|
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,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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 paramsCasing,\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 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: paramsType === 'object' ? 'object' : 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 (options?.group && group) {\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(root, output.path, groupName({ group: options.group }), baseName)\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"]}
|
|
@@ -6,6 +6,7 @@ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSch
|
|
|
6
6
|
type TransformerProps$1 = {
|
|
7
7
|
operation: Operation;
|
|
8
8
|
schemas: OperationSchemas;
|
|
9
|
+
casing: 'camelcase' | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
11
12
|
type Suspense = object;
|
|
@@ -86,6 +87,11 @@ type Options$1 = {
|
|
|
86
87
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
87
88
|
*/
|
|
88
89
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
90
|
+
/**
|
|
91
|
+
* How to style your params, by default no casing is applied
|
|
92
|
+
* - 'camelcase' will use camelcase for the params names
|
|
93
|
+
*/
|
|
94
|
+
paramsCasing?: 'camelcase';
|
|
89
95
|
/**
|
|
90
96
|
* How to pass your params
|
|
91
97
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -142,6 +148,7 @@ type ResolvedOptions$1 = {
|
|
|
142
148
|
};
|
|
143
149
|
parser: Required<NonNullable<Options$1['parser']>>;
|
|
144
150
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
151
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
145
152
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
146
153
|
/**
|
|
147
154
|
* Only used of infinite
|
|
@@ -158,6 +165,7 @@ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, Re
|
|
|
158
165
|
type TransformerProps = {
|
|
159
166
|
operation: Operation;
|
|
160
167
|
schemas: OperationSchemas;
|
|
168
|
+
casing: 'camelcase' | undefined;
|
|
161
169
|
};
|
|
162
170
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
163
171
|
/**
|
|
@@ -225,6 +233,11 @@ type Options = {
|
|
|
225
233
|
query?: Query | false;
|
|
226
234
|
mutationKey?: MutationKey;
|
|
227
235
|
mutation?: Mutation | false;
|
|
236
|
+
/**
|
|
237
|
+
* How to style your params, by default no casing is applied
|
|
238
|
+
* - 'camelcase' will use camelcase for the params names
|
|
239
|
+
*/
|
|
240
|
+
paramsCasing?: 'camelcase';
|
|
228
241
|
/**
|
|
229
242
|
* How to pass your params
|
|
230
243
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -265,6 +278,7 @@ type ResolvedOptions = {
|
|
|
265
278
|
query: NonNullable<Required<Query>> | false;
|
|
266
279
|
mutationKey: MutationKey | undefined;
|
|
267
280
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
281
|
+
paramsCasing: Options['paramsCasing'];
|
|
268
282
|
paramsType: NonNullable<Options['paramsType']>;
|
|
269
283
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
270
284
|
group: Options['group'];
|
|
@@ -6,6 +6,7 @@ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSch
|
|
|
6
6
|
type TransformerProps$1 = {
|
|
7
7
|
operation: Operation;
|
|
8
8
|
schemas: OperationSchemas;
|
|
9
|
+
casing: 'camelcase' | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
11
12
|
type Suspense = object;
|
|
@@ -86,6 +87,11 @@ type Options$1 = {
|
|
|
86
87
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
87
88
|
*/
|
|
88
89
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
90
|
+
/**
|
|
91
|
+
* How to style your params, by default no casing is applied
|
|
92
|
+
* - 'camelcase' will use camelcase for the params names
|
|
93
|
+
*/
|
|
94
|
+
paramsCasing?: 'camelcase';
|
|
89
95
|
/**
|
|
90
96
|
* How to pass your params
|
|
91
97
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -142,6 +148,7 @@ type ResolvedOptions$1 = {
|
|
|
142
148
|
};
|
|
143
149
|
parser: Required<NonNullable<Options$1['parser']>>;
|
|
144
150
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
151
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
145
152
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
146
153
|
/**
|
|
147
154
|
* Only used of infinite
|
|
@@ -158,6 +165,7 @@ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, Re
|
|
|
158
165
|
type TransformerProps = {
|
|
159
166
|
operation: Operation;
|
|
160
167
|
schemas: OperationSchemas;
|
|
168
|
+
casing: 'camelcase' | undefined;
|
|
161
169
|
};
|
|
162
170
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
163
171
|
/**
|
|
@@ -225,6 +233,11 @@ type Options = {
|
|
|
225
233
|
query?: Query | false;
|
|
226
234
|
mutationKey?: MutationKey;
|
|
227
235
|
mutation?: Mutation | false;
|
|
236
|
+
/**
|
|
237
|
+
* How to style your params, by default no casing is applied
|
|
238
|
+
* - 'camelcase' will use camelcase for the params names
|
|
239
|
+
*/
|
|
240
|
+
paramsCasing?: 'camelcase';
|
|
228
241
|
/**
|
|
229
242
|
* How to pass your params
|
|
230
243
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -265,6 +278,7 @@ type ResolvedOptions = {
|
|
|
265
278
|
query: NonNullable<Required<Query>> | false;
|
|
266
279
|
mutationKey: MutationKey | undefined;
|
|
267
280
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
281
|
+
paramsCasing: Options['paramsCasing'];
|
|
268
282
|
paramsType: NonNullable<Options['paramsType']>;
|
|
269
283
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
270
284
|
group: Options['group'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-swr",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Generator plugin-swr",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -64,22 +64,22 @@
|
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"remeda": "^2.17.4",
|
|
67
|
-
"@kubb/core": "3.
|
|
68
|
-
"@kubb/fs": "3.
|
|
69
|
-
"@kubb/oas": "3.
|
|
70
|
-
"@kubb/plugin-client": "3.
|
|
71
|
-
"@kubb/plugin-oas": "3.
|
|
72
|
-
"@kubb/plugin-ts": "3.
|
|
73
|
-
"@kubb/plugin-zod": "3.
|
|
74
|
-
"@kubb/react": "3.
|
|
67
|
+
"@kubb/core": "3.2.0",
|
|
68
|
+
"@kubb/fs": "3.2.0",
|
|
69
|
+
"@kubb/oas": "3.2.0",
|
|
70
|
+
"@kubb/plugin-client": "3.2.0",
|
|
71
|
+
"@kubb/plugin-oas": "3.2.0",
|
|
72
|
+
"@kubb/plugin-ts": "3.2.0",
|
|
73
|
+
"@kubb/plugin-zod": "3.2.0",
|
|
74
|
+
"@kubb/react": "3.2.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@types/react": "^18.3.
|
|
77
|
+
"@types/react": "^18.3.16",
|
|
78
78
|
"react": "^18.3.1",
|
|
79
79
|
"tsup": "^8.3.5",
|
|
80
80
|
"typescript": "^5.7.2",
|
|
81
|
-
"@kubb/config-ts": "3.
|
|
82
|
-
"@kubb/config-tsup": "3.
|
|
81
|
+
"@kubb/config-ts": "3.2.0",
|
|
82
|
+
"@kubb/config-tsup": "3.2.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@kubb/react": "^3.0.0"
|
|
@@ -19,25 +19,27 @@ type Props = {
|
|
|
19
19
|
mutationKeyTypeName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
22
23
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
23
24
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
24
25
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type GetParamsProps = {
|
|
29
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
28
30
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
29
31
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
30
32
|
typeSchemas: OperationSchemas
|
|
31
33
|
mutationKeyTypeName: string
|
|
32
34
|
}
|
|
33
35
|
// TODO add same logic as being done for react-query mutations
|
|
34
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
|
|
36
|
+
function getParams({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
|
|
35
37
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
36
38
|
|
|
37
39
|
return FunctionParams.factory({
|
|
38
40
|
pathParams: {
|
|
39
41
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
40
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
41
43
|
},
|
|
42
44
|
params: typeSchemas.queryParams?.name
|
|
43
45
|
? {
|
|
@@ -70,6 +72,7 @@ export function Mutation({
|
|
|
70
72
|
mutationKeyName,
|
|
71
73
|
mutationKeyTypeName,
|
|
72
74
|
paramsType,
|
|
75
|
+
paramsCasing,
|
|
73
76
|
pathParamsType,
|
|
74
77
|
dataReturnType,
|
|
75
78
|
typeSchemas,
|
|
@@ -89,6 +92,7 @@ export function Mutation({
|
|
|
89
92
|
})
|
|
90
93
|
|
|
91
94
|
const params = getParams({
|
|
95
|
+
paramsCasing,
|
|
92
96
|
pathParamsType,
|
|
93
97
|
dataReturnType,
|
|
94
98
|
typeSchemas,
|
|
@@ -96,6 +100,7 @@ export function Mutation({
|
|
|
96
100
|
})
|
|
97
101
|
|
|
98
102
|
const clientParams = Client.getParams({
|
|
103
|
+
paramsCasing,
|
|
99
104
|
paramsType,
|
|
100
105
|
typeSchemas,
|
|
101
106
|
pathParamsType,
|
|
@@ -11,6 +11,7 @@ type Props = {
|
|
|
11
11
|
typeName: string
|
|
12
12
|
typeSchemas: OperationSchemas
|
|
13
13
|
operation: Operation
|
|
14
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
14
15
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
15
16
|
transformer: Transformer | undefined
|
|
16
17
|
}
|
|
@@ -24,15 +25,15 @@ function getParams({}: GetParamsProps) {
|
|
|
24
25
|
return FunctionParams.factory({})
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const getTransformer: Transformer = ({ operation }) => {
|
|
28
|
-
const path = new URLPath(operation.path)
|
|
28
|
+
const getTransformer: Transformer = ({ operation, casing }) => {
|
|
29
|
+
const path = new URLPath(operation.path, { casing })
|
|
29
30
|
|
|
30
31
|
return [JSON.stringify({ url: path.path })].filter(Boolean)
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
|
+
export function MutationKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
35
|
const params = getParams({ pathParamsType, typeSchemas })
|
|
35
|
-
const keys = transformer({ operation, schemas: typeSchemas })
|
|
36
|
+
const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing })
|
|
36
37
|
|
|
37
38
|
return (
|
|
38
39
|
<>
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,6 +18,7 @@ type Props = {
|
|
|
18
18
|
queryKeyName: string
|
|
19
19
|
queryKeyTypeName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
21
22
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
22
23
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
23
24
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
@@ -25,6 +26,7 @@ type Props = {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type GetParamsProps = {
|
|
29
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
28
30
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
29
31
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
30
32
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
@@ -32,7 +34,7 @@ type GetParamsProps = {
|
|
|
32
34
|
typeSchemas: OperationSchemas
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, queryKeyTypeName }: GetParamsProps) {
|
|
37
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, queryKeyTypeName }: GetParamsProps) {
|
|
36
38
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
37
39
|
|
|
38
40
|
if (paramsType === 'object') {
|
|
@@ -40,7 +42,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, qu
|
|
|
40
42
|
data: {
|
|
41
43
|
mode: 'object',
|
|
42
44
|
children: {
|
|
43
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
45
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
44
46
|
data: typeSchemas.request?.name
|
|
45
47
|
? {
|
|
46
48
|
type: typeSchemas.request?.name,
|
|
@@ -78,7 +80,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, qu
|
|
|
78
80
|
pathParams: typeSchemas.pathParams?.name
|
|
79
81
|
? {
|
|
80
82
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
81
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
83
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
82
84
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
83
85
|
}
|
|
84
86
|
: undefined,
|
|
@@ -122,6 +124,7 @@ export function Query({
|
|
|
122
124
|
operation,
|
|
123
125
|
dataReturnType,
|
|
124
126
|
paramsType,
|
|
127
|
+
paramsCasing,
|
|
125
128
|
pathParamsType,
|
|
126
129
|
}: Props): ReactNode {
|
|
127
130
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
@@ -130,8 +133,10 @@ export function Query({
|
|
|
130
133
|
const queryKeyParams = QueryKey.getParams({
|
|
131
134
|
pathParamsType,
|
|
132
135
|
typeSchemas,
|
|
136
|
+
paramsCasing,
|
|
133
137
|
})
|
|
134
138
|
const params = getParams({
|
|
139
|
+
paramsCasing,
|
|
135
140
|
paramsType,
|
|
136
141
|
pathParamsType,
|
|
137
142
|
dataReturnType,
|
|
@@ -140,6 +145,7 @@ export function Query({
|
|
|
140
145
|
})
|
|
141
146
|
|
|
142
147
|
const queryOptionsParams = QueryOptions.getParams({
|
|
148
|
+
paramsCasing,
|
|
143
149
|
paramsType,
|
|
144
150
|
pathParamsType,
|
|
145
151
|
typeSchemas,
|
|
@@ -12,20 +12,22 @@ type Props = {
|
|
|
12
12
|
typeName: string
|
|
13
13
|
typeSchemas: OperationSchemas
|
|
14
14
|
operation: Operation
|
|
15
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
15
16
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
16
17
|
transformer: Transformer | undefined
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
type GetParamsProps = {
|
|
21
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
20
22
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
21
23
|
typeSchemas: OperationSchemas
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
26
|
+
function getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {
|
|
25
27
|
return FunctionParams.factory({
|
|
26
28
|
pathParams: {
|
|
27
29
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
28
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
30
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
29
31
|
},
|
|
30
32
|
data: typeSchemas.request?.name
|
|
31
33
|
? {
|
|
@@ -42,8 +44,8 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
42
44
|
})
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
46
|
-
const path = new URLPath(operation.path)
|
|
47
|
+
const getTransformer: Transformer = ({ operation, schemas, casing }) => {
|
|
48
|
+
const path = new URLPath(operation.path, { casing })
|
|
47
49
|
const keys = [
|
|
48
50
|
path.toObject({
|
|
49
51
|
type: 'path',
|
|
@@ -56,11 +58,12 @@ const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
|
56
58
|
return keys
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
60
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
61
|
+
export function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
62
|
+
const params = getParams({ pathParamsType, paramsCasing, typeSchemas })
|
|
61
63
|
const keys = transformer({
|
|
62
64
|
operation,
|
|
63
65
|
schemas: typeSchemas,
|
|
66
|
+
casing: paramsCasing,
|
|
64
67
|
})
|
|
65
68
|
|
|
66
69
|
return (
|
|
@@ -12,23 +12,25 @@ type Props = {
|
|
|
12
12
|
name: string
|
|
13
13
|
clientName: string
|
|
14
14
|
typeSchemas: OperationSchemas
|
|
15
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
15
16
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
16
17
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
type GetParamsProps = {
|
|
20
21
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
22
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
21
23
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
22
24
|
typeSchemas: OperationSchemas
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
27
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
26
28
|
if (paramsType === 'object') {
|
|
27
29
|
return FunctionParams.factory({
|
|
28
30
|
data: {
|
|
29
31
|
mode: 'object',
|
|
30
32
|
children: {
|
|
31
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
33
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
32
34
|
data: typeSchemas.request?.name
|
|
33
35
|
? {
|
|
34
36
|
type: typeSchemas.request?.name,
|
|
@@ -60,7 +62,7 @@ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps)
|
|
|
60
62
|
pathParams: typeSchemas.pathParams?.name
|
|
61
63
|
? {
|
|
62
64
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
63
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
65
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
64
66
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
65
67
|
}
|
|
66
68
|
: undefined,
|
|
@@ -89,9 +91,10 @@ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps)
|
|
|
89
91
|
})
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType }: Props): ReactNode {
|
|
93
|
-
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
94
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }: Props): ReactNode {
|
|
95
|
+
const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
94
96
|
const clientParams = Client.getParams({
|
|
97
|
+
paramsCasing,
|
|
95
98
|
paramsType,
|
|
96
99
|
typeSchemas,
|
|
97
100
|
pathParamsType,
|
|
@@ -84,6 +84,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
84
84
|
operation={operation}
|
|
85
85
|
pathParamsType={options.pathParamsType}
|
|
86
86
|
typeSchemas={type.schemas}
|
|
87
|
+
paramsCasing={options.paramsCasing}
|
|
87
88
|
transformer={options.mutationKey}
|
|
88
89
|
/>
|
|
89
90
|
|
|
@@ -96,6 +97,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
96
97
|
typeSchemas={type.schemas}
|
|
97
98
|
zodSchemas={zod.schemas}
|
|
98
99
|
dataReturnType={options.client.dataReturnType}
|
|
100
|
+
paramsCasing={options.paramsCasing}
|
|
99
101
|
paramsType={options.paramsType}
|
|
100
102
|
pathParamsType={options.pathParamsType}
|
|
101
103
|
parser={options.parser}
|
|
@@ -109,6 +111,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
109
111
|
operation={operation}
|
|
110
112
|
dataReturnType={options.client.dataReturnType}
|
|
111
113
|
paramsType={options.paramsType}
|
|
114
|
+
paramsCasing={options.paramsCasing}
|
|
112
115
|
pathParamsType={options.pathParamsType}
|
|
113
116
|
mutationKeyName={mutationKey.name}
|
|
114
117
|
mutationKeyTypeName={mutationKey.typeName}
|
|
@@ -86,6 +86,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
86
86
|
operation={operation}
|
|
87
87
|
pathParamsType={options.pathParamsType}
|
|
88
88
|
typeSchemas={type.schemas}
|
|
89
|
+
paramsCasing={options.paramsCasing}
|
|
89
90
|
transformer={options.queryKey}
|
|
90
91
|
/>
|
|
91
92
|
<Client
|
|
@@ -97,6 +98,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
97
98
|
typeSchemas={type.schemas}
|
|
98
99
|
zodSchemas={zod.schemas}
|
|
99
100
|
dataReturnType={options.client.dataReturnType}
|
|
101
|
+
paramsCasing={options.paramsCasing}
|
|
100
102
|
paramsType={options.paramsType}
|
|
101
103
|
pathParamsType={options.pathParamsType}
|
|
102
104
|
parser={options.parser}
|
|
@@ -106,6 +108,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
106
108
|
clientName={client.name}
|
|
107
109
|
typeSchemas={type.schemas}
|
|
108
110
|
paramsType={options.paramsType}
|
|
111
|
+
paramsCasing={options.paramsCasing}
|
|
109
112
|
pathParamsType={options.pathParamsType}
|
|
110
113
|
/>
|
|
111
114
|
{options.query && (
|
|
@@ -121,6 +124,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
121
124
|
operation={operation}
|
|
122
125
|
dataReturnType={options.client.dataReturnType}
|
|
123
126
|
queryKeyName={queryKey.name}
|
|
127
|
+
paramsCasing={options.paramsCasing}
|
|
124
128
|
queryKeyTypeName={queryKey.typeName}
|
|
125
129
|
/>
|
|
126
130
|
</>
|
package/src/plugin.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
32
32
|
mutationKey = MutationKey.getTransformer,
|
|
33
33
|
queryKey = QueryKey.getTransformer,
|
|
34
34
|
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
35
|
+
paramsCasing,
|
|
35
36
|
} = options
|
|
36
37
|
|
|
37
38
|
return {
|
|
@@ -61,6 +62,7 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
61
62
|
parser,
|
|
62
63
|
paramsType,
|
|
63
64
|
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
|
|
65
|
+
paramsCasing,
|
|
64
66
|
group,
|
|
65
67
|
},
|
|
66
68
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { PluginReactQuery } from '@kubb/plugin-react-query'
|
|
|
7
7
|
type TransformerProps = {
|
|
8
8
|
operation: Operation
|
|
9
9
|
schemas: OperationSchemas
|
|
10
|
+
casing: 'camelcase' | undefined
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export type Transformer = (props: TransformerProps) => unknown[]
|
|
@@ -80,6 +81,11 @@ export type Options = {
|
|
|
80
81
|
query?: Query | false
|
|
81
82
|
mutationKey?: MutationKey
|
|
82
83
|
mutation?: Mutation | false
|
|
84
|
+
/**
|
|
85
|
+
* How to style your params, by default no casing is applied
|
|
86
|
+
* - 'camelcase' will use camelcase for the params names
|
|
87
|
+
*/
|
|
88
|
+
paramsCasing?: 'camelcase'
|
|
83
89
|
/**
|
|
84
90
|
* How to pass your params
|
|
85
91
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -119,6 +125,7 @@ type ResolvedOptions = {
|
|
|
119
125
|
query: NonNullable<Required<Query>> | false
|
|
120
126
|
mutationKey: MutationKey | undefined
|
|
121
127
|
mutation: NonNullable<Required<Mutation>> | false
|
|
128
|
+
paramsCasing: Options['paramsCasing']
|
|
122
129
|
paramsType: NonNullable<Options['paramsType']>
|
|
123
130
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
124
131
|
group: Options['group']
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/queryGenerator.tsx","../src/generators/mutationGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","difference","pluginTsName","pluginZodName","jsxs","File","jsx","Client"],"mappings":";;;;;;;;;;;AAYO,IAAM,iBAAiB,oBAAgC,CAAA;AAAA,EAC5D,IAAM,EAAA,WAAA;AAAA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S,CAAA,IAAA;AAAA,UACf,YAAY,MAAO,CAAA,IAAA;AAAA,UACnB,UAAU,QAAS,CAAA,QAAA;AAAA,UACnB,aAAa,IAAK,CAAA,OAAA;AAAA,UAClB,SAAA;AAAA,UACA,cAAA,EAAgB,QAAQ,MAAO,CAAA,cAAA;AAAA,UAC/B,YAAY,OAAQ,CAAA,UAAA;AAAA,UACpB,gBAAgB,OAAQ,CAAA,cAAA;AAAA,UACxB,iBAAiB,WAAY,CAAA,IAAA;AAAA,UAC7B,qBAAqB,WAAY,CAAA;AAAA;AAAA;AACnC,KAEJ,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-23A6KPTG.js","sourcesContent":["import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { Query, QueryOptions } from '../components'\nimport { QueryKey } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const queryGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-query',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(\n (method) => operation.method === method,\n )\n const importPath = options.query ? options.query.importPath : 'swr/mutation'\n\n const query = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const client = {\n name: getName(operation, { type: 'function' }),\n }\n\n const queryOptions = {\n name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),\n }\n const queryKey = {\n name: getName(operation, { type: 'const', suffix: 'QueryKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n if (!isQuery || isMutation) {\n return null\n }\n\n return (\n <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}\n\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={query.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <QueryKey\n name={queryKey.name}\n typeName={queryKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.queryKey}\n />\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n <QueryOptions\n name={queryOptions.name}\n clientName={client.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n />\n {options.query && (\n <>\n <File.Import name=\"useSWR\" path={importPath} />\n <File.Import name={['SWRResponse']} path={importPath} isTypeOnly />\n <Query\n name={query.name}\n queryOptionsName={queryOptions.name}\n typeSchemas={type.schemas}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n queryKeyName={queryKey.name}\n queryKeyTypeName={queryKey.typeName}\n />\n </>\n )}\n </File>\n )\n },\n})\n","import { pluginClientName } from '@kubb/plugin-client'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { difference } from 'remeda'\nimport { MutationKey } from '../components'\nimport { Mutation } from '../components'\nimport type { PluginSwr } from '../types'\n\nexport const mutationGenerator = createReactGenerator<PluginSwr>({\n name: 'swr-mutation',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginSwr>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)\n const isMutation =\n !isQuery &&\n difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)\n\n const importPath = options.mutation ? options.mutation.importPath : 'swr'\n\n const mutation = {\n name: getName(operation, { type: 'function', prefix: 'use' }),\n typeName: getName(operation, { type: 'type' }),\n file: getFile(operation, { prefix: 'use' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n //todo remove type?\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n const client = {\n name: getName(operation, { type: 'function' }),\n }\n\n const mutationKey = {\n name: getName(operation, { type: 'const', suffix: 'MutationKey' }),\n typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),\n }\n\n if (!isMutation) {\n return null\n }\n\n return (\n <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}\n <File.Import name=\"useSWRMutation\" path={importPath} />\n <File.Import name={['SWRMutationResponse']} path={importPath} isTypeOnly />\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mutation.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <MutationKey\n name={mutationKey.name}\n typeName={mutationKey.typeName}\n operation={operation}\n pathParamsType={options.pathParamsType}\n typeSchemas={type.schemas}\n transformer={options.mutationKey}\n />\n\n <Client\n name={client.name}\n isExportable={false}\n isIndexable={false}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={zod.schemas}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n parser={options.parser}\n />\n {options.mutation && (\n <Mutation\n name={mutation.name}\n clientName={client.name}\n typeName={mutation.typeName}\n typeSchemas={type.schemas}\n operation={operation}\n dataReturnType={options.client.dataReturnType}\n paramsType={options.paramsType}\n pathParamsType={options.pathParamsType}\n mutationKeyName={mutationKey.name}\n mutationKeyTypeName={mutationKey.typeName}\n />\n )}\n </File>\n )\n },\n})\n"]}
|