@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.10
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-24SL7I66.cjs +683 -0
- package/dist/chunk-24SL7I66.cjs.map +1 -0
- package/dist/chunk-BML6BZ4F.cjs +878 -0
- package/dist/chunk-BML6BZ4F.cjs.map +1 -0
- package/dist/chunk-JFIGHRBM.js +867 -0
- package/dist/chunk-JFIGHRBM.js.map +1 -0
- package/dist/chunk-LBVGJA4Q.js +674 -0
- package/dist/chunk-LBVGJA4Q.js.map +1 -0
- package/dist/components.cjs +39 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +172 -6
- package/dist/components.d.ts +172 -6
- package/dist/components.js +2 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +25 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +14 -0
- package/dist/generators.d.ts +14 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +80 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +63 -120
- package/dist/index.js.map +1 -1
- package/dist/types-Dlwxp28D.d.cts +230 -0
- package/dist/types-Dlwxp28D.d.ts +230 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +176 -0
- package/src/components/InfiniteQueryOptions.tsx +185 -0
- package/src/components/Mutation.tsx +142 -320
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +145 -592
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +110 -472
- package/src/components/SuspenseQuery.tsx +176 -0
- package/src/components/index.ts +4 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
- package/src/generators/__snapshots__/findByTags.ts +51 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +44 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +126 -0
- package/src/generators/mutationGenerator.tsx +109 -0
- package/src/generators/queryGenerator.tsx +123 -0
- package/src/generators/suspenseQueryGenerator.tsx +123 -0
- package/src/plugin.ts +62 -76
- package/src/types.ts +49 -126
- package/dist/chunk-7ZODZVKP.cjs +0 -1470
- package/dist/chunk-7ZODZVKP.cjs.map +0 -1
- package/dist/chunk-ZYTZV43V.js +0 -1470
- package/dist/chunk-ZYTZV43V.js.map +0 -1
- package/dist/index-5kpkk-7M.d.cts +0 -545
- package/dist/index-5kpkk-7M.d.ts +0 -545
- package/src/OperationGenerator.tsx +0 -57
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -59
- package/src/components/__snapshots__/gen/showPetById.ts +0 -67
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
- package/src/utils.ts +0 -96
|
@@ -0,0 +1,123 @@
|
|
|
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 { QueryKey, QueryOptions, SuspenseQuery } from '../components'
|
|
10
|
+
import type { PluginReactQuery } from '../types'
|
|
11
|
+
|
|
12
|
+
export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
13
|
+
name: 'react-suspense-query',
|
|
14
|
+
Operation({ options, operation }) {
|
|
15
|
+
const {
|
|
16
|
+
plugin: {
|
|
17
|
+
options: { output },
|
|
18
|
+
},
|
|
19
|
+
} = useApp<PluginReactQuery>()
|
|
20
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
|
+
const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
|
|
22
|
+
const isSuspense = isQuery && !!options.suspense
|
|
23
|
+
|
|
24
|
+
const query = {
|
|
25
|
+
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'suspense' }),
|
|
26
|
+
typeName: getName(operation, { type: 'type' }),
|
|
27
|
+
file: getFile(operation, { prefix: 'use', suffix: 'suspense' }),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const client = {
|
|
31
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const queryOptions = {
|
|
35
|
+
name: getName(operation, { type: 'function', suffix: 'SuspenseQueryOptions' }),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const queryKey = {
|
|
39
|
+
name: getName(operation, { type: 'const', suffix: 'SuspenseQueryKey' }),
|
|
40
|
+
typeName: getName(operation, { type: 'type', suffix: 'SuspenseQueryKey' }),
|
|
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 || !isSuspense || typeof options.query === 'boolean') {
|
|
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={['useSuspenseQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
+
<File.Import name={['QueryKey', 'WithRequired', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} 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
|
+
<File.Import
|
|
67
|
+
name={[
|
|
68
|
+
type.schemas.request?.name,
|
|
69
|
+
type.schemas.response.name,
|
|
70
|
+
type.schemas.pathParams?.name,
|
|
71
|
+
type.schemas.queryParams?.name,
|
|
72
|
+
type.schemas.headerParams?.name,
|
|
73
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
74
|
+
].filter(Boolean)}
|
|
75
|
+
root={query.file.path}
|
|
76
|
+
path={type.file.path}
|
|
77
|
+
isTypeOnly
|
|
78
|
+
/>
|
|
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
|
+
paramsType={options.paramsType}
|
|
98
|
+
pathParamsType={options.pathParamsType}
|
|
99
|
+
parser={options.parser}
|
|
100
|
+
/>
|
|
101
|
+
<QueryOptions
|
|
102
|
+
name={queryOptions.name}
|
|
103
|
+
clientName={client.name}
|
|
104
|
+
queryKeyName={queryKey.name}
|
|
105
|
+
typeSchemas={type.schemas}
|
|
106
|
+
paramsType={options.paramsType}
|
|
107
|
+
pathParamsType={options.pathParamsType}
|
|
108
|
+
/>
|
|
109
|
+
<SuspenseQuery
|
|
110
|
+
name={query.name}
|
|
111
|
+
queryOptionsName={queryOptions.name}
|
|
112
|
+
typeSchemas={type.schemas}
|
|
113
|
+
paramsType={options.paramsType}
|
|
114
|
+
pathParamsType={options.pathParamsType}
|
|
115
|
+
operation={operation}
|
|
116
|
+
dataReturnType={options.client.dataReturnType}
|
|
117
|
+
queryKeyName={queryKey.name}
|
|
118
|
+
queryKeyTypeName={queryKey.typeName}
|
|
119
|
+
/>
|
|
120
|
+
</File>
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
})
|
package/src/plugin.ts
CHANGED
|
@@ -1,56 +1,47 @@
|
|
|
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
|
-
import {
|
|
6
|
-
import { pluginOasName } from '@kubb/plugin-oas'
|
|
5
|
+
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
8
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
10
9
|
|
|
11
|
-
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
12
|
-
import { Mutation, Query, QueryKey, QueryOptions } from './components/index.ts'
|
|
13
|
-
|
|
14
10
|
import type { Plugin } from '@kubb/core'
|
|
15
11
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
16
|
-
import {
|
|
12
|
+
import { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'
|
|
17
13
|
import type { PluginReactQuery } from './types.ts'
|
|
18
14
|
|
|
19
15
|
export const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']
|
|
20
16
|
|
|
21
17
|
export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
22
18
|
const {
|
|
23
|
-
output = { path: 'hooks' },
|
|
19
|
+
output = { path: 'hooks', barrelType: 'named' },
|
|
24
20
|
group,
|
|
25
21
|
exclude = [],
|
|
26
22
|
include,
|
|
27
23
|
override = [],
|
|
28
|
-
parser,
|
|
24
|
+
parser = 'client',
|
|
29
25
|
suspense = {},
|
|
30
|
-
infinite,
|
|
26
|
+
infinite = false,
|
|
31
27
|
transformers = {},
|
|
32
|
-
|
|
28
|
+
paramsType = 'inline',
|
|
33
29
|
pathParamsType = 'inline',
|
|
34
|
-
|
|
30
|
+
generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
|
|
31
|
+
mutation = {},
|
|
35
32
|
query = {},
|
|
36
|
-
queryOptions = {},
|
|
37
|
-
templates,
|
|
38
33
|
} = options
|
|
39
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
40
34
|
|
|
41
35
|
return {
|
|
42
36
|
name: pluginReactQueryName,
|
|
43
|
-
output: {
|
|
44
|
-
exportType: 'barrelNamed',
|
|
45
|
-
...output,
|
|
46
|
-
},
|
|
47
37
|
options: {
|
|
38
|
+
output,
|
|
39
|
+
baseURL: undefined,
|
|
48
40
|
client: {
|
|
49
41
|
importPath: '@kubb/plugin-client/client',
|
|
42
|
+
dataReturnType: 'data',
|
|
50
43
|
...options.client,
|
|
51
44
|
},
|
|
52
|
-
dataReturnType,
|
|
53
|
-
pathParamsType,
|
|
54
45
|
infinite: infinite
|
|
55
46
|
? {
|
|
56
47
|
queryParam: 'id',
|
|
@@ -60,30 +51,20 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
60
51
|
}
|
|
61
52
|
: false,
|
|
62
53
|
suspense,
|
|
63
|
-
query:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
variablesType: 'hook',
|
|
75
|
-
methods: ['post', 'put', 'patch', 'delete'],
|
|
76
|
-
...mutate,
|
|
77
|
-
}
|
|
78
|
-
: false,
|
|
79
|
-
templates: {
|
|
80
|
-
mutation: Mutation.templates,
|
|
81
|
-
query: Query.templates,
|
|
82
|
-
queryOptions: QueryOptions.templates,
|
|
83
|
-
queryKey: QueryKey.templates,
|
|
84
|
-
queryImports: QueryImports.templates,
|
|
85
|
-
...templates,
|
|
54
|
+
query: {
|
|
55
|
+
key: (key: unknown[]) => key,
|
|
56
|
+
methods: ['get'],
|
|
57
|
+
importPath: '@tanstack/react-query',
|
|
58
|
+
...query,
|
|
59
|
+
},
|
|
60
|
+
mutation: {
|
|
61
|
+
key: (key: unknown[]) => key,
|
|
62
|
+
methods: ['post', 'put', 'patch', 'delete'],
|
|
63
|
+
importPath: '@tanstack/react-query',
|
|
64
|
+
...mutation,
|
|
86
65
|
},
|
|
66
|
+
paramsType,
|
|
67
|
+
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
|
|
87
68
|
parser,
|
|
88
69
|
},
|
|
89
70
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
@@ -91,6 +72,12 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
91
72
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
92
73
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
93
74
|
|
|
75
|
+
if (options?.tag && group?.type === 'tag') {
|
|
76
|
+
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
77
|
+
|
|
78
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
79
|
+
}
|
|
80
|
+
|
|
94
81
|
if (mode === 'single') {
|
|
95
82
|
/**
|
|
96
83
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -99,12 +86,6 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
99
86
|
return path.resolve(root, output.path)
|
|
100
87
|
}
|
|
101
88
|
|
|
102
|
-
if (options?.tag && group?.type === 'tag') {
|
|
103
|
-
const tag = camelCase(options.tag)
|
|
104
|
-
|
|
105
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
89
|
return path.resolve(root, output.path, baseName)
|
|
109
90
|
},
|
|
110
91
|
resolveName(name, type) {
|
|
@@ -112,7 +93,6 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
112
93
|
|
|
113
94
|
if (type === 'file' || type === 'function') {
|
|
114
95
|
resolvedName = camelCase(name, {
|
|
115
|
-
prefix: 'use',
|
|
116
96
|
isFile: type === 'file',
|
|
117
97
|
})
|
|
118
98
|
}
|
|
@@ -132,34 +112,40 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
132
112
|
const oas = await swaggerPlugin.context.getOas()
|
|
133
113
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
134
114
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
115
|
+
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
116
|
+
|
|
117
|
+
const operationGenerator = new OperationGenerator(
|
|
118
|
+
{
|
|
119
|
+
...this.plugin.options,
|
|
120
|
+
baseURL,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
oas,
|
|
124
|
+
pluginManager: this.pluginManager,
|
|
125
|
+
plugin: this.plugin,
|
|
126
|
+
contentType: swaggerPlugin.context.contentType,
|
|
127
|
+
exclude,
|
|
128
|
+
include,
|
|
129
|
+
override,
|
|
130
|
+
mode,
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
const files = await operationGenerator.build(...generators)
|
|
148
135
|
await this.addFile(...files)
|
|
149
136
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
137
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
138
|
+
type: output.barrelType ?? 'named',
|
|
139
|
+
root,
|
|
140
|
+
output,
|
|
141
|
+
files: this.fileManager.files,
|
|
142
|
+
meta: {
|
|
143
|
+
pluginKey: this.plugin.key,
|
|
144
|
+
},
|
|
145
|
+
logger: this.logger,
|
|
146
|
+
})
|
|
160
147
|
|
|
161
|
-
|
|
162
|
-
}
|
|
148
|
+
await this.addFile(...barrelFiles)
|
|
163
149
|
},
|
|
164
150
|
}
|
|
165
151
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type * as KubbFile from '@kubb/fs/types'
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
2
|
|
|
4
3
|
import type { HttpMethod } from '@kubb/oas'
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { Query as QueryTemplate } from './components/Query.tsx'
|
|
8
|
-
import type { QueryKey } from './components/QueryKey.tsx'
|
|
9
|
-
import type { QueryOptions as QueryOptionsTemplate } from './components/QueryOptions.tsx'
|
|
4
|
+
import type { PluginClient } from '@kubb/plugin-client'
|
|
5
|
+
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
10
6
|
|
|
11
|
-
type
|
|
12
|
-
mutation?: typeof Mutation.templates | false
|
|
13
|
-
query?: typeof QueryTemplate.templates | false
|
|
14
|
-
queryOptions?: typeof QueryOptionsTemplate.templates | false
|
|
15
|
-
queryKey?: typeof QueryKey.templates | false
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Suspense = object
|
|
7
|
+
type Suspense = object
|
|
19
8
|
|
|
20
|
-
|
|
9
|
+
type Query = {
|
|
21
10
|
/**
|
|
22
11
|
* Customize the queryKey, here you can specify a suffix.
|
|
23
12
|
*/
|
|
24
|
-
|
|
13
|
+
key: (key: unknown[]) => unknown[]
|
|
25
14
|
/**
|
|
26
15
|
* Define which HttpMethods can be used for queries
|
|
27
16
|
* @default ['get']
|
|
@@ -37,14 +26,11 @@ export type Query = {
|
|
|
37
26
|
importPath?: string
|
|
38
27
|
}
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export type Mutate = {
|
|
29
|
+
type Mutation = {
|
|
43
30
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @default `'hook'`
|
|
31
|
+
* Customize the queryKey, here you can specify a suffix.
|
|
46
32
|
*/
|
|
47
|
-
|
|
33
|
+
key: (key: unknown[]) => unknown[]
|
|
48
34
|
/**
|
|
49
35
|
* Define which HttpMethods can be used for mutations
|
|
50
36
|
* @default ['post', 'put', 'delete']
|
|
@@ -63,8 +49,7 @@ export type Mutate = {
|
|
|
63
49
|
export type Infinite = {
|
|
64
50
|
/**
|
|
65
51
|
* Specify the params key used for `pageParam`.
|
|
66
|
-
*
|
|
67
|
-
* @default `'id'`
|
|
52
|
+
* @default 'id'
|
|
68
53
|
*/
|
|
69
54
|
queryParam: string
|
|
70
55
|
/**
|
|
@@ -73,99 +58,23 @@ export type Infinite = {
|
|
|
73
58
|
cursorParam?: string | undefined
|
|
74
59
|
/**
|
|
75
60
|
* The initial value, the value of the first page.
|
|
76
|
-
* @default
|
|
61
|
+
* @default 0
|
|
77
62
|
*/
|
|
78
63
|
initialPageParam: unknown
|
|
79
64
|
}
|
|
80
65
|
|
|
81
66
|
export type Options = {
|
|
82
|
-
output?: {
|
|
83
|
-
/**
|
|
84
|
-
* Output to save the @tanstack/query hooks.
|
|
85
|
-
* @default `"hooks"`
|
|
86
|
-
*/
|
|
87
|
-
path: string
|
|
88
|
-
/**
|
|
89
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
90
|
-
*/
|
|
91
|
-
exportAs?: string
|
|
92
|
-
/**
|
|
93
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
94
|
-
*/
|
|
95
|
-
extName?: KubbFile.Extname
|
|
96
|
-
/**
|
|
97
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
98
|
-
* @default `'barrel'`
|
|
99
|
-
*/
|
|
100
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Group the @tanstack/query hooks based on the provided name.
|
|
104
|
-
*/
|
|
105
|
-
group?: {
|
|
106
|
-
/**
|
|
107
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
108
|
-
*/
|
|
109
|
-
type: 'tag'
|
|
110
|
-
/**
|
|
111
|
-
* Relative path to save the grouped @tanstack/query hooks.
|
|
112
|
-
*
|
|
113
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
114
|
-
* @example `${output}/{{tag}}Controller` => `hooks/PetController`
|
|
115
|
-
* @default `${output}/{{tag}}Controller`
|
|
116
|
-
*/
|
|
117
|
-
output?: string
|
|
118
|
-
/**
|
|
119
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
120
|
-
* @default `"{{tag}}Hooks"`
|
|
121
|
-
*/
|
|
122
|
-
exportAs?: string
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
client?: {
|
|
126
|
-
/**
|
|
127
|
-
* Path to the client that will be used to do the API calls.
|
|
128
|
-
* It will be used as `import client from '${client.importPath}'`.
|
|
129
|
-
* It allows both relative and absolute path.
|
|
130
|
-
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
131
|
-
* @default '@kubb/plugin-client/client'
|
|
132
|
-
*/
|
|
133
|
-
importPath?: string
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* ReturnType that needs to be used when calling client().
|
|
137
|
-
*
|
|
138
|
-
* `Data` will return ResponseConfig[data].
|
|
139
|
-
*
|
|
140
|
-
* `Full` will return ResponseConfig.
|
|
141
|
-
* @default `'data'`
|
|
142
|
-
* @private
|
|
143
|
-
*/
|
|
144
67
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* `Data` will return ResponseConfig[data].
|
|
148
|
-
*
|
|
149
|
-
* `Full` will return ResponseConfig.
|
|
150
|
-
* @default `'data'`
|
|
151
|
-
* @private
|
|
68
|
+
* Specify the export location for the files and define the behavior of the output
|
|
69
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
152
70
|
*/
|
|
153
|
-
|
|
71
|
+
output?: Output
|
|
154
72
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* `object` will return the pathParams as an object.
|
|
158
|
-
*
|
|
159
|
-
* `inline` will return the pathParams as comma separated params.
|
|
160
|
-
* @default `'inline'`
|
|
161
|
-
* @private
|
|
162
|
-
*/
|
|
163
|
-
pathParamsType?: 'object' | 'inline'
|
|
164
|
-
/**
|
|
165
|
-
* Which parser can be used before returning the data to `@tanstack/query`.
|
|
166
|
-
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
73
|
+
* Group the @tanstack/query hooks based on the provided name.
|
|
167
74
|
*/
|
|
168
|
-
|
|
75
|
+
group?: Group
|
|
76
|
+
|
|
77
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>
|
|
169
78
|
/**
|
|
170
79
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
171
80
|
*/
|
|
@@ -178,6 +87,21 @@ export type Options = {
|
|
|
178
87
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
179
88
|
*/
|
|
180
89
|
override?: Array<Override<ResolvedOptions>>
|
|
90
|
+
/**
|
|
91
|
+
* How to pass your params
|
|
92
|
+
* - 'object' will return the params and pathParams as an object.
|
|
93
|
+
* - 'inline' will return the params as comma separated params.
|
|
94
|
+
* @default 'inline'
|
|
95
|
+
*/
|
|
96
|
+
paramsType?: 'object' | 'inline'
|
|
97
|
+
/**
|
|
98
|
+
* How to pass your pathParams.
|
|
99
|
+
* - 'object' will return the pathParams as an object.
|
|
100
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
101
|
+
* @default 'inline'
|
|
102
|
+
*/
|
|
103
|
+
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
104
|
+
|
|
181
105
|
/**
|
|
182
106
|
* When set, an infiniteQuery hooks will be added.
|
|
183
107
|
*/
|
|
@@ -190,11 +114,15 @@ export type Options = {
|
|
|
190
114
|
* Override some useQuery behaviours.
|
|
191
115
|
*/
|
|
192
116
|
query?: Partial<Query> | false
|
|
193
|
-
queryOptions?: Partial<QueryOptions> | false
|
|
194
117
|
/**
|
|
195
118
|
* Override some useMutation behaviours.
|
|
196
119
|
*/
|
|
197
|
-
|
|
120
|
+
mutation?: Partial<Mutation> | 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']
|
|
198
126
|
transformers?: {
|
|
199
127
|
/**
|
|
200
128
|
* Customize the names based on the type that is provided by the plugin.
|
|
@@ -202,30 +130,25 @@ export type Options = {
|
|
|
202
130
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
203
131
|
}
|
|
204
132
|
/**
|
|
205
|
-
*
|
|
133
|
+
* Define some generators next to the react-query generators
|
|
206
134
|
*/
|
|
207
|
-
|
|
135
|
+
generators?: Array<Generator<PluginReactQuery>>
|
|
208
136
|
}
|
|
209
137
|
|
|
210
138
|
type ResolvedOptions = {
|
|
139
|
+
output: Output
|
|
140
|
+
baseURL: string | undefined
|
|
211
141
|
client: Required<NonNullable<PluginReactQuery['options']['client']>>
|
|
212
|
-
|
|
213
|
-
pathParamsType: NonNullable<
|
|
214
|
-
|
|
142
|
+
parser: Required<NonNullable<Options['parser']>>
|
|
143
|
+
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
144
|
+
paramsType: NonNullable<Options['paramsType']>
|
|
215
145
|
/**
|
|
216
146
|
* Only used of infinite
|
|
217
147
|
*/
|
|
218
|
-
infinite: Infinite | false
|
|
148
|
+
infinite: NonNullable<Infinite> | false
|
|
219
149
|
suspense: Suspense | false
|
|
220
|
-
query: Query | false
|
|
221
|
-
|
|
222
|
-
mutate: Mutate | false
|
|
223
|
-
templates: NonNullable<Templates>
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export type FileMeta = {
|
|
227
|
-
pluginKey?: Plugin['key']
|
|
228
|
-
tag?: string
|
|
150
|
+
query: NonNullable<Required<Query>> | false
|
|
151
|
+
mutation: NonNullable<Required<Mutation>> | false
|
|
229
152
|
}
|
|
230
153
|
|
|
231
154
|
export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>
|