@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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/chunk-2KDZWGWG.js +342 -0
  4. package/dist/chunk-2KDZWGWG.js.map +1 -0
  5. package/dist/chunk-64KLXAGI.cjs +237 -0
  6. package/dist/chunk-64KLXAGI.cjs.map +1 -0
  7. package/dist/chunk-AFAHUG3Q.cjs +348 -0
  8. package/dist/chunk-AFAHUG3Q.cjs.map +1 -0
  9. package/dist/chunk-T6K6P5I7.js +234 -0
  10. package/dist/chunk-T6K6P5I7.js.map +1 -0
  11. package/dist/components.cjs +28 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +95 -0
  14. package/dist/components.d.ts +95 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +11 -0
  20. package/dist/generators.d.ts +11 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +127 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +10 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +120 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-AhGZx7jH.d.cts +272 -0
  30. package/dist/types-AhGZx7jH.d.ts +272 -0
  31. package/package.json +104 -0
  32. package/src/components/Mutation.tsx +129 -0
  33. package/src/components/MutationKey.tsx +54 -0
  34. package/src/components/Query.tsx +175 -0
  35. package/src/components/QueryKey.tsx +83 -0
  36. package/src/components/QueryOptions.tsx +116 -0
  37. package/src/components/index.ts +5 -0
  38. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +49 -0
  39. package/src/generators/__snapshots__/clientGetImportPath.ts +49 -0
  40. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  41. package/src/generators/__snapshots__/findByTags.ts +49 -0
  42. package/src/generators/__snapshots__/findByTagsObject.ts +49 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +49 -0
  44. package/src/generators/__snapshots__/findByTagsWithZod.ts +49 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
  49. package/src/generators/index.ts +2 -0
  50. package/src/generators/mutationGenerator.tsx +117 -0
  51. package/src/generators/queryGenerator.tsx +127 -0
  52. package/src/index.ts +4 -0
  53. package/src/plugin.ts +141 -0
  54. package/src/types.ts +126 -0
@@ -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 };
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "@kubb/plugin-swr",
3
+ "version": "0.0.0-canary-20241104172400",
4
+ "description": "Generator plugin-swr",
5
+ "keywords": [
6
+ "typescript",
7
+ "plugins",
8
+ "kubb",
9
+ "codegen",
10
+ "swagger",
11
+ "openapi",
12
+ "swr",
13
+ "vercel",
14
+ "nextjs",
15
+ "next",
16
+ "axios"
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git://github.com/kubb-labs/kubb.git",
21
+ "directory": "packages/plugin-swr"
22
+ },
23
+ "license": "MIT",
24
+ "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
25
+ "sideEffects": false,
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs",
31
+ "default": "./dist/index.cjs"
32
+ },
33
+ "./generators": {
34
+ "import": "./dist/generators.js",
35
+ "require": "./dist/generators.cjs",
36
+ "default": "./dist/generators.cjs"
37
+ },
38
+ "./components": {
39
+ "import": "./dist/components.js",
40
+ "require": "./dist/components.cjs",
41
+ "default": "./dist/components.cjs"
42
+ },
43
+ "./package.json": "./package.json",
44
+ "./*": "./*"
45
+ },
46
+ "main": "dist/index.cjs",
47
+ "module": "dist/index.js",
48
+ "types": "./dist/index.d.ts",
49
+ "typesVersions": {
50
+ "*": {
51
+ "components": [
52
+ "./dist/components.d.ts"
53
+ ],
54
+ "generators": [
55
+ "./dist/generators.d.ts"
56
+ ]
57
+ }
58
+ },
59
+ "files": [
60
+ "src",
61
+ "dist",
62
+ "!/**/**.test.**",
63
+ "!/**/__tests__/**"
64
+ ],
65
+ "dependencies": {
66
+ "@kubb/core": "0.0.0-canary-20241104172400",
67
+ "@kubb/fs": "0.0.0-canary-20241104172400",
68
+ "@kubb/oas": "0.0.0-canary-20241104172400",
69
+ "@kubb/plugin-client": "0.0.0-canary-20241104172400",
70
+ "@kubb/plugin-oas": "0.0.0-canary-20241104172400",
71
+ "@kubb/plugin-ts": "0.0.0-canary-20241104172400",
72
+ "@kubb/plugin-zod": "0.0.0-canary-20241104172400",
73
+ "@kubb/react": "0.0.0-canary-20241104172400"
74
+ },
75
+ "devDependencies": {
76
+ "@types/react": "^18.3.12",
77
+ "react": "^18.3.1",
78
+ "tsup": "^8.3.5",
79
+ "typescript": "^5.6.3",
80
+ "@kubb/config-ts": "0.0.0-canary-20241104172400",
81
+ "@kubb/config-tsup": "0.0.0-canary-20241104172400"
82
+ },
83
+ "peerDependencies": {
84
+ "@kubb/react": "0.0.0-canary-20241104172400"
85
+ },
86
+ "engines": {
87
+ "node": ">=20"
88
+ },
89
+ "publishConfig": {
90
+ "access": "public",
91
+ "registry": "https://registry.npmjs.org/"
92
+ },
93
+ "scripts": {
94
+ "build": "tsup",
95
+ "clean": "rimraf ./dist",
96
+ "lint": "bun biome lint .",
97
+ "lint:fix": "bun biome lint --apply-unsafe .",
98
+ "release": "pnpm publish --no-git-check",
99
+ "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
100
+ "start": "tsup --watch",
101
+ "test": "vitest --passWithNoTests",
102
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
103
+ }
104
+ }
@@ -0,0 +1,129 @@
1
+ import { File, Function, FunctionParams } from '@kubb/react'
2
+
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import { Client } from '@kubb/plugin-client/components'
5
+ import type { OperationSchemas } from '@kubb/plugin-oas'
6
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
7
+ import type { ReactNode } from 'react'
8
+ import type { PluginSwr } from '../types.ts'
9
+ import { MutationKey } from './MutationKey.tsx'
10
+
11
+ type Props = {
12
+ /**
13
+ * Name of the function
14
+ */
15
+ name: string
16
+ typeName: string
17
+ clientName: string
18
+ mutationKeyName: string
19
+ mutationKeyTypeName: string
20
+ typeSchemas: OperationSchemas
21
+ operation: Operation
22
+ paramsType: PluginSwr['resolvedOptions']['paramsType']
23
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
24
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
25
+ }
26
+
27
+ type GetParamsProps = {
28
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
29
+ dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
30
+ typeSchemas: OperationSchemas
31
+ mutationKeyTypeName: string
32
+ }
33
+ // TODO add same logic as being done for react-query mutations
34
+ function getParams({ pathParamsType, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
35
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
36
+
37
+ return FunctionParams.factory({
38
+ pathParams: {
39
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
40
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
41
+ },
42
+ params: typeSchemas.queryParams?.name
43
+ ? {
44
+ type: typeSchemas.queryParams?.name,
45
+ optional: isOptional(typeSchemas.queryParams?.schema),
46
+ }
47
+ : undefined,
48
+ headers: typeSchemas.headerParams?.name
49
+ ? {
50
+ type: typeSchemas.headerParams?.name,
51
+ optional: isOptional(typeSchemas.headerParams?.schema),
52
+ }
53
+ : undefined,
54
+ options: {
55
+ type: `
56
+ {
57
+ mutation?: Parameters<typeof useSWRMutation<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', mutationKeyTypeName, typeSchemas.request?.name].join(', ')}>>[2],
58
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},
59
+ shouldFetch?: boolean,
60
+ }
61
+ `,
62
+ default: '{}',
63
+ },
64
+ })
65
+ }
66
+
67
+ export function Mutation({
68
+ name,
69
+ clientName,
70
+ mutationKeyName,
71
+ mutationKeyTypeName,
72
+ paramsType,
73
+ pathParamsType,
74
+ dataReturnType,
75
+ typeSchemas,
76
+ operation,
77
+ }: Props): ReactNode {
78
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
79
+ const generics = [
80
+ TData,
81
+ typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error',
82
+ `${mutationKeyTypeName} | null`,
83
+ typeSchemas.request?.name, //arg: data
84
+ ].filter(Boolean)
85
+
86
+ const mutationKeyParams = MutationKey.getParams({
87
+ pathParamsType,
88
+ typeSchemas,
89
+ })
90
+
91
+ const params = getParams({
92
+ pathParamsType,
93
+ dataReturnType,
94
+ typeSchemas,
95
+ mutationKeyTypeName,
96
+ })
97
+
98
+ const clientParams = Client.getParams({
99
+ paramsType,
100
+ typeSchemas,
101
+ pathParamsType,
102
+ })
103
+
104
+ return (
105
+ <File.Source name={name} isExportable isIndexable>
106
+ <Function
107
+ name={name}
108
+ export
109
+ params={params.toConstructor()}
110
+ JSDoc={{
111
+ comments: getComments(operation),
112
+ }}
113
+ >
114
+ {`
115
+ const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
116
+ const mutationKey = ${mutationKeyName}(${mutationKeyParams.toCall()})
117
+
118
+ return useSWRMutation<${generics}>(
119
+ shouldFetch ? mutationKey : null,
120
+ async (_url${typeSchemas.request?.name ? ', { arg: data }' : ''}) => {
121
+ return ${clientName}(${clientParams.toCall()})
122
+ },
123
+ mutationOptions
124
+ )
125
+ `}
126
+ </Function>
127
+ </File.Source>
128
+ )
129
+ }
@@ -0,0 +1,54 @@
1
+ import { URLPath } from '@kubb/core/utils'
2
+ import { File, Function, FunctionParams, Type } from '@kubb/react'
3
+
4
+ import type { Operation } from '@kubb/oas'
5
+ import type { OperationSchemas } from '@kubb/plugin-oas'
6
+ import type { ReactNode } from 'react'
7
+ import type { PluginSwr, Transformer } from '../types'
8
+
9
+ type Props = {
10
+ name: string
11
+ typeName: string
12
+ typeSchemas: OperationSchemas
13
+ operation: Operation
14
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
15
+ transformer: Transformer | undefined
16
+ }
17
+
18
+ type GetParamsProps = {
19
+ pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
20
+ typeSchemas: OperationSchemas
21
+ }
22
+
23
+ function getParams({}: GetParamsProps) {
24
+ return FunctionParams.factory({})
25
+ }
26
+
27
+ const getTransformer: Transformer = ({ operation }) => {
28
+ const path = new URLPath(operation.path)
29
+
30
+ return [JSON.stringify({ url: path.path })].filter(Boolean)
31
+ }
32
+
33
+ export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
34
+ const params = getParams({ pathParamsType, typeSchemas })
35
+ const keys = transformer({ operation, schemas: typeSchemas })
36
+
37
+ return (
38
+ <>
39
+ <File.Source name={name} isExportable isIndexable>
40
+ <Function.Arrow name={name} export params={params.toConstructor()} singleLine>
41
+ {`[${keys.join(', ')}] as const`}
42
+ </Function.Arrow>
43
+ </File.Source>
44
+ <File.Source name={typeName} isExportable isIndexable isTypeOnly>
45
+ <Type name={typeName} export>
46
+ {`ReturnType<typeof ${name}>`}
47
+ </Type>
48
+ </File.Source>
49
+ </>
50
+ )
51
+ }
52
+
53
+ MutationKey.getParams = getParams
54
+ MutationKey.getTransformer = getTransformer