@kubb/plugin-swr 3.0.0-alpha.9 → 3.0.0-beta.2
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/README.md +14 -5
- package/dist/chunk-4EGGCGSE.js +217 -0
- package/dist/chunk-4EGGCGSE.js.map +1 -0
- package/dist/chunk-H23WKEYP.js +243 -0
- package/dist/chunk-H23WKEYP.js.map +1 -0
- package/dist/chunk-JWGWABV5.cjs +249 -0
- package/dist/chunk-JWGWABV5.cjs.map +1 -0
- package/dist/chunk-PTOQHHST.cjs +220 -0
- package/dist/chunk-PTOQHHST.cjs.map +1 -0
- package/dist/components.cjs +23 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +88 -6
- package/dist/components.d.ts +88 -6
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- 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 +93 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +77 -114
- package/dist/index.js.map +1 -1
- package/dist/types-DaH2Sc1M.d.cts +103 -0
- package/dist/types-DaH2Sc1M.d.ts +103 -0
- package/package.json +23 -17
- package/src/components/Mutation.tsx +93 -227
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +93 -259
- package/src/components/QueryKey.tsx +73 -0
- package/src/components/QueryOptions.tsx +54 -177
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +43 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +43 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
- package/src/generators/__snapshots__/findByTags.ts +43 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +43 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +43 -0
- package/src/generators/__snapshots__/getAsMutation.ts +34 -0
- package/src/generators/__snapshots__/postAsQuery.ts +41 -0
- package/src/generators/__snapshots__/updatePetById.ts +32 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +36 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mutationGenerator.tsx +109 -0
- package/src/generators/queryGenerator.tsx +114 -0
- package/src/plugin.ts +71 -52
- package/src/types.ts +62 -78
- package/dist/chunk-TGLXUPN4.cjs +0 -536
- package/dist/chunk-TGLXUPN4.cjs.map +0 -1
- package/dist/chunk-XWXMQJD6.js +0 -536
- package/dist/chunk-XWXMQJD6.js.map +0 -1
- package/dist/index-B3C-JOIU.d.cts +0 -299
- package/dist/index-B3C-JOIU.d.ts +0 -299
- package/src/OperationGenerator.tsx +0 -75
- package/src/components/SchemaType.tsx +0 -63
- package/src/components/__snapshots__/Mutation/Pets.ts +0 -46
- package/src/components/__snapshots__/Query/showPetById.ts +0 -59
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import transformers from '@kubb/core/transformers'
|
|
2
|
+
import { pluginClientName } from '@kubb/plugin-client'
|
|
3
|
+
import { Client } from '@kubb/plugin-client/components'
|
|
4
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
5
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
+
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
+
import { File, useApp } from '@kubb/react'
|
|
9
|
+
import { MutationKey } from '../components'
|
|
10
|
+
import { Mutation } from '../components'
|
|
11
|
+
import type { PluginSwr } from '../types'
|
|
12
|
+
|
|
13
|
+
export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
14
|
+
name: 'swr-mutation',
|
|
15
|
+
Operation({ options, operation }) {
|
|
16
|
+
const {
|
|
17
|
+
plugin: {
|
|
18
|
+
options: { output },
|
|
19
|
+
},
|
|
20
|
+
} = useApp<PluginSwr>()
|
|
21
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
22
|
+
|
|
23
|
+
const isMutate = typeof options.query === 'boolean' ? options.mutation : !!options.mutation.methods?.some((method) => operation.method === method)
|
|
24
|
+
|
|
25
|
+
const mutation = {
|
|
26
|
+
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
27
|
+
typeName: getName(operation, { type: 'type' }),
|
|
28
|
+
file: getFile(operation, { prefix: 'use' }),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const type = {
|
|
32
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
33
|
+
//todo remove type?
|
|
34
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const zod = {
|
|
38
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
39
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const client = {
|
|
43
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const mutationKey = {
|
|
47
|
+
name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
|
|
48
|
+
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!isMutate) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
57
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
58
|
+
<File.Import name="useSWRMutation" path={options.mutation.importPath} />
|
|
59
|
+
<File.Import name={['SWRMutationResponse']} path={options.mutation.importPath} isTypeOnly />
|
|
60
|
+
<File.Import name={'client'} path={options.client.importPath} />
|
|
61
|
+
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
62
|
+
<File.Import
|
|
63
|
+
name={[
|
|
64
|
+
type.schemas.request?.name,
|
|
65
|
+
type.schemas.response.name,
|
|
66
|
+
type.schemas.pathParams?.name,
|
|
67
|
+
type.schemas.queryParams?.name,
|
|
68
|
+
type.schemas.headerParams?.name,
|
|
69
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
70
|
+
].filter(Boolean)}
|
|
71
|
+
root={mutation.file.path}
|
|
72
|
+
path={type.file.path}
|
|
73
|
+
isTypeOnly
|
|
74
|
+
/>
|
|
75
|
+
<MutationKey
|
|
76
|
+
name={mutationKey.name}
|
|
77
|
+
typeName={mutationKey.typeName}
|
|
78
|
+
operation={operation}
|
|
79
|
+
pathParamsType={options.pathParamsType}
|
|
80
|
+
typeSchemas={type.schemas}
|
|
81
|
+
keysFn={options.mutation.key}
|
|
82
|
+
/>
|
|
83
|
+
<Client
|
|
84
|
+
name={client.name}
|
|
85
|
+
isExportable={false}
|
|
86
|
+
isIndexable={false}
|
|
87
|
+
baseURL={options.baseURL}
|
|
88
|
+
operation={operation}
|
|
89
|
+
typeSchemas={type.schemas}
|
|
90
|
+
zodSchemas={zod.schemas}
|
|
91
|
+
dataReturnType={options.client.dataReturnType}
|
|
92
|
+
pathParamsType={options.pathParamsType}
|
|
93
|
+
parser={options.parser}
|
|
94
|
+
/>
|
|
95
|
+
<Mutation
|
|
96
|
+
name={mutation.name}
|
|
97
|
+
clientName={client.name}
|
|
98
|
+
typeName={mutation.typeName}
|
|
99
|
+
typeSchemas={type.schemas}
|
|
100
|
+
operation={operation}
|
|
101
|
+
dataReturnType={options.client.dataReturnType}
|
|
102
|
+
pathParamsType={options.pathParamsType}
|
|
103
|
+
mutationKeyName={mutationKey.name}
|
|
104
|
+
mutationKeyTypeName={mutationKey.typeName}
|
|
105
|
+
/>
|
|
106
|
+
</File>
|
|
107
|
+
)
|
|
108
|
+
},
|
|
109
|
+
})
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import transformers from '@kubb/core/transformers'
|
|
2
|
+
import { pluginClientName } from '@kubb/plugin-client'
|
|
3
|
+
import { Client } from '@kubb/plugin-client/components'
|
|
4
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
5
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
+
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
+
import { File, useApp } from '@kubb/react'
|
|
9
|
+
import { Query, QueryOptions } from '../components'
|
|
10
|
+
import { QueryKey } from '../components'
|
|
11
|
+
import type { PluginSwr } from '../types'
|
|
12
|
+
|
|
13
|
+
export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
14
|
+
name: 'swr-query',
|
|
15
|
+
Operation({ options, operation }) {
|
|
16
|
+
const {
|
|
17
|
+
plugin: {
|
|
18
|
+
options: { output },
|
|
19
|
+
},
|
|
20
|
+
} = useApp<PluginSwr>()
|
|
21
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
22
|
+
|
|
23
|
+
const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
|
|
24
|
+
|
|
25
|
+
const query = {
|
|
26
|
+
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
27
|
+
typeName: getName(operation, { type: 'type' }),
|
|
28
|
+
file: getFile(operation, { prefix: 'use' }),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const client = {
|
|
32
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const queryOptions = {
|
|
36
|
+
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
37
|
+
}
|
|
38
|
+
const queryKey = {
|
|
39
|
+
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
40
|
+
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const type = {
|
|
44
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
45
|
+
//todo remove type?
|
|
46
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const zod = {
|
|
50
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
51
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!isQuery) {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
|
+
<File.Import name="useSWR" path={options.query.importPath} />
|
|
62
|
+
<File.Import name={['SWRResponse']} path={options.query.importPath} isTypeOnly />
|
|
63
|
+
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
|
+
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
|
+
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
66
|
+
|
|
67
|
+
<File.Import
|
|
68
|
+
name={[
|
|
69
|
+
type.schemas.request?.name,
|
|
70
|
+
type.schemas.response.name,
|
|
71
|
+
type.schemas.pathParams?.name,
|
|
72
|
+
type.schemas.queryParams?.name,
|
|
73
|
+
type.schemas.headerParams?.name,
|
|
74
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
75
|
+
].filter(Boolean)}
|
|
76
|
+
root={query.file.path}
|
|
77
|
+
path={type.file.path}
|
|
78
|
+
isTypeOnly
|
|
79
|
+
/>
|
|
80
|
+
<QueryKey
|
|
81
|
+
name={queryKey.name}
|
|
82
|
+
typeName={queryKey.typeName}
|
|
83
|
+
operation={operation}
|
|
84
|
+
pathParamsType={options.pathParamsType}
|
|
85
|
+
typeSchemas={type.schemas}
|
|
86
|
+
keysFn={options.query.key}
|
|
87
|
+
/>
|
|
88
|
+
<Client
|
|
89
|
+
name={client.name}
|
|
90
|
+
isExportable={false}
|
|
91
|
+
isIndexable={false}
|
|
92
|
+
baseURL={options.baseURL}
|
|
93
|
+
operation={operation}
|
|
94
|
+
typeSchemas={type.schemas}
|
|
95
|
+
zodSchemas={zod.schemas}
|
|
96
|
+
dataReturnType={options.client.dataReturnType}
|
|
97
|
+
pathParamsType={options.pathParamsType}
|
|
98
|
+
parser={options.parser}
|
|
99
|
+
/>
|
|
100
|
+
<QueryOptions name={queryOptions.name} clientName={client.name} typeSchemas={type.schemas} pathParamsType={options.pathParamsType} />
|
|
101
|
+
<Query
|
|
102
|
+
name={query.name}
|
|
103
|
+
queryOptionsName={queryOptions.name}
|
|
104
|
+
typeSchemas={type.schemas}
|
|
105
|
+
pathParamsType={options.pathParamsType}
|
|
106
|
+
operation={operation}
|
|
107
|
+
dataReturnType={options.client.dataReturnType}
|
|
108
|
+
queryKeyName={queryKey.name}
|
|
109
|
+
queryKeyTypeName={queryKey.typeName}
|
|
110
|
+
/>
|
|
111
|
+
</File>
|
|
112
|
+
)
|
|
113
|
+
},
|
|
114
|
+
})
|
package/src/plugin.ts
CHANGED
|
@@ -1,52 +1,72 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
3
|
+
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
|
-
import { pluginOasName } from '@kubb/plugin-oas'
|
|
6
|
+
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
7
|
|
|
8
8
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
9
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
10
|
|
|
11
|
-
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
12
|
-
import { Mutation, Query, QueryOptions } from './components/index.ts'
|
|
13
|
-
|
|
14
11
|
import type { Plugin } from '@kubb/core'
|
|
15
12
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
13
|
+
import { mutationGenerator, queryGenerator } from './generators'
|
|
16
14
|
import type { PluginSwr } from './types.ts'
|
|
17
15
|
|
|
18
16
|
export const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']
|
|
19
17
|
|
|
20
18
|
export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
21
|
-
const {
|
|
22
|
-
|
|
19
|
+
const {
|
|
20
|
+
output = { path: 'hooks', barrelType: 'named' },
|
|
21
|
+
group,
|
|
22
|
+
exclude = [],
|
|
23
|
+
include,
|
|
24
|
+
override = [],
|
|
25
|
+
parser = 'client',
|
|
26
|
+
transformers = {},
|
|
27
|
+
query,
|
|
28
|
+
mutation,
|
|
29
|
+
client,
|
|
30
|
+
pathParamsType = 'inline',
|
|
31
|
+
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
32
|
+
} = options
|
|
23
33
|
|
|
24
34
|
return {
|
|
25
35
|
name: pluginSwrName,
|
|
26
|
-
output: {
|
|
27
|
-
exportType: 'barrelNamed',
|
|
28
|
-
...output,
|
|
29
|
-
},
|
|
30
36
|
options: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mutation: Mutation.templates,
|
|
34
|
-
query: Query.templates,
|
|
35
|
-
queryOptions: QueryOptions.templates,
|
|
36
|
-
...templates,
|
|
37
|
-
},
|
|
37
|
+
output,
|
|
38
|
+
pathParamsType,
|
|
38
39
|
client: {
|
|
39
40
|
importPath: '@kubb/plugin-client/client',
|
|
40
|
-
|
|
41
|
+
dataReturnType: 'data',
|
|
42
|
+
...client,
|
|
43
|
+
},
|
|
44
|
+
query: {
|
|
45
|
+
key: (key: unknown[]) => key,
|
|
46
|
+
importPath: 'swr',
|
|
47
|
+
methods: ['get'],
|
|
48
|
+
...query,
|
|
49
|
+
},
|
|
50
|
+
mutation: {
|
|
51
|
+
key: (key: unknown[]) => key,
|
|
52
|
+
importPath: 'swr/mutation',
|
|
53
|
+
methods: ['post', 'put', 'delete', 'patch'],
|
|
54
|
+
...mutation,
|
|
41
55
|
},
|
|
42
|
-
dataReturnType,
|
|
43
56
|
parser,
|
|
57
|
+
baseURL: undefined,
|
|
44
58
|
},
|
|
45
59
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
46
60
|
resolvePath(baseName, pathMode, options) {
|
|
47
61
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
48
62
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
49
63
|
|
|
64
|
+
if (options?.tag && group?.type === 'tag') {
|
|
65
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
66
|
+
|
|
67
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
68
|
+
}
|
|
69
|
+
|
|
50
70
|
if (mode === 'single') {
|
|
51
71
|
/**
|
|
52
72
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -55,12 +75,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
55
75
|
return path.resolve(root, output.path)
|
|
56
76
|
}
|
|
57
77
|
|
|
58
|
-
if (options?.tag && group?.type === 'tag') {
|
|
59
|
-
const tag = camelCase(options.tag)
|
|
60
|
-
|
|
61
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
78
|
return path.resolve(root, output.path, baseName)
|
|
65
79
|
},
|
|
66
80
|
resolveName(name, type) {
|
|
@@ -68,7 +82,6 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
68
82
|
|
|
69
83
|
if (type === 'file' || type === 'function') {
|
|
70
84
|
resolvedName = camelCase(name, {
|
|
71
|
-
prefix: 'use',
|
|
72
85
|
isFile: type === 'file',
|
|
73
86
|
})
|
|
74
87
|
}
|
|
@@ -89,34 +102,40 @@ export const pluginSwr = createPlugin<PluginSwr>((options) => {
|
|
|
89
102
|
const oas = await swaggerPlugin.context.getOas()
|
|
90
103
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
91
104
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
106
|
+
|
|
107
|
+
const operationGenerator = new OperationGenerator(
|
|
108
|
+
{
|
|
109
|
+
...this.plugin.options,
|
|
110
|
+
baseURL,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
oas,
|
|
114
|
+
pluginManager: this.pluginManager,
|
|
115
|
+
plugin: this.plugin,
|
|
116
|
+
contentType: swaggerPlugin.context.contentType,
|
|
117
|
+
exclude,
|
|
118
|
+
include,
|
|
119
|
+
override,
|
|
120
|
+
mode,
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
const files = await operationGenerator.build(...generators)
|
|
105
125
|
await this.addFile(...files)
|
|
106
126
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
128
|
+
type: output.barrelType ?? 'named',
|
|
129
|
+
root,
|
|
130
|
+
output,
|
|
131
|
+
files: this.fileManager.files,
|
|
132
|
+
meta: {
|
|
133
|
+
pluginKey: this.plugin.key,
|
|
134
|
+
},
|
|
135
|
+
logger: this.logger,
|
|
136
|
+
})
|
|
117
137
|
|
|
118
|
-
|
|
119
|
-
}
|
|
138
|
+
await this.addFile(...barrelFiles)
|
|
120
139
|
},
|
|
121
140
|
}
|
|
122
141
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,59 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { Query } from './components/Query.tsx'
|
|
6
|
-
import type { QueryOptions } from './components/QueryOptions.tsx'
|
|
7
|
-
|
|
8
|
-
type Templates = {
|
|
9
|
-
mutation?: typeof Mutation.templates | false
|
|
10
|
-
query?: typeof Query.templates | false
|
|
11
|
-
queryOptions?: typeof QueryOptions.templates | false
|
|
12
|
-
}
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import type { HttpMethod } from '@kubb/oas'
|
|
3
|
+
import type { PluginClient } from '@kubb/plugin-client'
|
|
4
|
+
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
13
5
|
|
|
14
6
|
export type Options = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
path: string
|
|
21
|
-
/**
|
|
22
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
23
|
-
*/
|
|
24
|
-
exportAs?: string
|
|
25
|
-
/**
|
|
26
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
27
|
-
*/
|
|
28
|
-
extName?: KubbFile.Extname
|
|
29
|
-
/**
|
|
30
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
31
|
-
* @default `'barrel'`
|
|
32
|
-
*/
|
|
33
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
34
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* @default 'hooks'
|
|
9
|
+
*/
|
|
10
|
+
output?: Output
|
|
35
11
|
/**
|
|
36
12
|
* Group the SWR hooks based on the provided name.
|
|
37
13
|
*/
|
|
38
|
-
group?:
|
|
39
|
-
/**
|
|
40
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
41
|
-
*/
|
|
42
|
-
type: 'tag'
|
|
43
|
-
/**
|
|
44
|
-
* Relative path to save the grouped SWR hooks.
|
|
45
|
-
*
|
|
46
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
47
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
48
|
-
* @default `${output}/{{tag}}Controller`
|
|
49
|
-
*/
|
|
50
|
-
output?: string
|
|
51
|
-
/**
|
|
52
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
53
|
-
* @default `"{{tag}}SWRHooks"`
|
|
54
|
-
*/
|
|
55
|
-
exportAs?: string
|
|
56
|
-
}
|
|
14
|
+
group?: Group
|
|
57
15
|
/**
|
|
58
16
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
59
17
|
*/
|
|
@@ -66,26 +24,60 @@ export type Options = {
|
|
|
66
24
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
67
25
|
*/
|
|
68
26
|
override?: Array<Override<ResolvedOptions>>
|
|
69
|
-
client?:
|
|
27
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>
|
|
28
|
+
query?: {
|
|
70
29
|
/**
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
30
|
+
* Customize the queryKey, here you can specify a suffix.
|
|
31
|
+
*/
|
|
32
|
+
key: (key: unknown[]) => unknown[]
|
|
33
|
+
/**
|
|
34
|
+
* Define which HttpMethods can be used for queries
|
|
35
|
+
* @default ['get']
|
|
36
|
+
*/
|
|
37
|
+
methods?: Array<HttpMethod>
|
|
38
|
+
/**
|
|
39
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
40
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
41
|
+
* It allows both relative and absolute path.
|
|
42
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
43
|
+
* @default '@tanstack/react-query' if 'framework' is set to 'react'
|
|
44
|
+
*/
|
|
45
|
+
importPath?: string
|
|
46
|
+
}
|
|
47
|
+
mutation?: {
|
|
48
|
+
/**
|
|
49
|
+
* Customize the queryKey, here you can specify a suffix.
|
|
50
|
+
*/
|
|
51
|
+
key: (key: unknown[]) => unknown[]
|
|
52
|
+
/**
|
|
53
|
+
* Define which HttpMethods can be used for queries
|
|
54
|
+
* @default ['post', 'put', 'delete', 'patch']
|
|
55
|
+
*/
|
|
56
|
+
methods?: Array<HttpMethod>
|
|
57
|
+
/**
|
|
58
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
59
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
60
|
+
* It allows both relative and absolute path.
|
|
61
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
62
|
+
* @default '@tanstack/react-query' if 'framework' is set to 'react'
|
|
76
63
|
*/
|
|
77
64
|
importPath?: string
|
|
78
65
|
}
|
|
79
66
|
/**
|
|
80
|
-
*
|
|
67
|
+
* How to pass your pathParams.
|
|
81
68
|
*
|
|
82
|
-
* `
|
|
69
|
+
* `object` will return the pathParams as an object.
|
|
83
70
|
*
|
|
84
|
-
* `
|
|
85
|
-
* @default `'
|
|
71
|
+
* `inline` will return the pathParams as comma separated params.
|
|
72
|
+
* @default `'inline'`
|
|
86
73
|
* @private
|
|
87
74
|
*/
|
|
88
|
-
|
|
75
|
+
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
76
|
+
/**
|
|
77
|
+
* Which parser can be used before returning the data to `swr`.
|
|
78
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
79
|
+
*/
|
|
80
|
+
parser?: PluginClient['options']['parser']
|
|
89
81
|
transformers?: {
|
|
90
82
|
/**
|
|
91
83
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -93,27 +85,19 @@ export type Options = {
|
|
|
93
85
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
94
86
|
}
|
|
95
87
|
/**
|
|
96
|
-
*
|
|
97
|
-
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
98
|
-
*/
|
|
99
|
-
parser?: 'zod'
|
|
100
|
-
/**
|
|
101
|
-
* Make it possible to override one of the templates
|
|
88
|
+
* Define some generators next to the swr generators
|
|
102
89
|
*/
|
|
103
|
-
|
|
90
|
+
generators?: Array<Generator<PluginSwr>>
|
|
104
91
|
}
|
|
105
92
|
|
|
106
93
|
type ResolvedOptions = {
|
|
107
|
-
|
|
94
|
+
output: Output
|
|
95
|
+
baseURL: string | undefined
|
|
108
96
|
client: Required<NonNullable<Options['client']>>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
export type FileMeta = {
|
|
115
|
-
pluginKey?: Plugin['key']
|
|
116
|
-
tag?: string
|
|
97
|
+
parser: Required<NonNullable<Options['parser']>>
|
|
98
|
+
mutation: Required<NonNullable<Options['mutation']>>
|
|
99
|
+
query: Required<NonNullable<Options['query']>>
|
|
100
|
+
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
117
101
|
}
|
|
118
102
|
|
|
119
103
|
export type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>
|