@kubb/plugin-react-query 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-37VO6QXJ.cjs +669 -0
- package/dist/chunk-37VO6QXJ.cjs.map +1 -0
- package/dist/chunk-C2H3KPHM.cjs +658 -0
- package/dist/chunk-C2H3KPHM.cjs.map +1 -0
- package/dist/chunk-IRW2Y3EC.js +660 -0
- package/dist/chunk-IRW2Y3EC.js.map +1 -0
- package/dist/chunk-Y3DM2P6L.js +647 -0
- package/dist/chunk-Y3DM2P6L.js.map +1 -0
- package/dist/components.cjs +39 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +161 -6
- package/dist/components.d.ts +161 -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 +78 -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 +61 -120
- package/dist/index.js.map +1 -1
- package/dist/types-5pnOmDmM.d.cts +231 -0
- package/dist/types-5pnOmDmM.d.ts +231 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +130 -0
- package/src/components/Mutation.tsx +137 -321
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +91 -594
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +71 -473
- package/src/components/SuspenseQuery.tsx +129 -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__/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 +46 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +124 -0
- package/src/generators/mutationGenerator.tsx +108 -0
- package/src/generators/queryGenerator.tsx +121 -0
- package/src/generators/suspenseQueryGenerator.tsx +120 -0
- package/src/plugin.ts +60 -76
- package/src/types.ts +42 -115
- 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,124 @@
|
|
|
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 { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
10
|
+
import type { PluginReactQuery } from '../types'
|
|
11
|
+
|
|
12
|
+
export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
13
|
+
name: 'react-infinite-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 isInfinite = isQuery && !!options.infinite
|
|
23
|
+
|
|
24
|
+
const query = {
|
|
25
|
+
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
|
|
26
|
+
typeName: getName(operation, { type: 'type' }),
|
|
27
|
+
file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
|
|
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: 'InfiniteQueryOptions' }),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const queryKey = {
|
|
39
|
+
name: getName(operation, { type: 'const', suffix: 'InfiniteQueryKey' }),
|
|
40
|
+
typeName: getName(operation, { type: 'type', suffix: 'InfiniteQueryKey' }),
|
|
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 || !isInfinite || typeof options.query === 'boolean' || typeof options.infinite === '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={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
|
|
62
|
+
<File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} 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
|
+
pathParamsType={options.pathParamsType}
|
|
98
|
+
parser={options.parser}
|
|
99
|
+
/>
|
|
100
|
+
<InfiniteQueryOptions
|
|
101
|
+
name={queryOptions.name}
|
|
102
|
+
clientName={client.name}
|
|
103
|
+
queryKeyName={queryKey.name}
|
|
104
|
+
typeSchemas={type.schemas}
|
|
105
|
+
pathParamsType={options.pathParamsType}
|
|
106
|
+
dataReturnType={options.client.dataReturnType}
|
|
107
|
+
cursorParam={options.infinite.cursorParam}
|
|
108
|
+
initialPageParam={options.infinite.initialPageParam}
|
|
109
|
+
queryParam={options.infinite.queryParam}
|
|
110
|
+
/>
|
|
111
|
+
<InfiniteQuery
|
|
112
|
+
name={query.name}
|
|
113
|
+
queryOptionsName={queryOptions.name}
|
|
114
|
+
typeSchemas={type.schemas}
|
|
115
|
+
pathParamsType={options.pathParamsType}
|
|
116
|
+
operation={operation}
|
|
117
|
+
dataReturnType={options.client.dataReturnType}
|
|
118
|
+
queryKeyName={queryKey.name}
|
|
119
|
+
queryKeyTypeName={queryKey.typeName}
|
|
120
|
+
/>
|
|
121
|
+
</File>
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { Mutation, MutationKey } from '../components'
|
|
10
|
+
import type { PluginReactQuery } from '../types'
|
|
11
|
+
|
|
12
|
+
export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
13
|
+
name: 'react-query',
|
|
14
|
+
Operation({ options, operation }) {
|
|
15
|
+
const {
|
|
16
|
+
plugin: {
|
|
17
|
+
options: { output },
|
|
18
|
+
},
|
|
19
|
+
} = useApp<PluginReactQuery>()
|
|
20
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
|
+
|
|
22
|
+
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
23
|
+
const isMutation = !isQuery && 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 (!isMutation || typeof options.mutation === 'boolean') {
|
|
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={['useMutation']} path={options.mutation.importPath} />
|
|
59
|
+
<File.Import name={['UseMutationOptions']} 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
|
+
/>
|
|
105
|
+
</File>
|
|
106
|
+
)
|
|
107
|
+
},
|
|
108
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
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, QueryKey, QueryOptions } from '../components'
|
|
10
|
+
import type { PluginReactQuery } from '../types'
|
|
11
|
+
|
|
12
|
+
export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
13
|
+
name: 'react-query',
|
|
14
|
+
Operation({ options, operation }) {
|
|
15
|
+
const {
|
|
16
|
+
plugin: {
|
|
17
|
+
options: { output },
|
|
18
|
+
},
|
|
19
|
+
} = useApp<PluginReactQuery>()
|
|
20
|
+
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
|
+
|
|
22
|
+
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
23
|
+
const isMutation = !isQuery && options.mutation && options.mutation.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
|
+
|
|
39
|
+
const queryKey = {
|
|
40
|
+
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
41
|
+
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const type = {
|
|
45
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
46
|
+
//todo remove type?
|
|
47
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const zod = {
|
|
51
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
52
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!isQuery || typeof options.query === 'boolean') {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
61
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
62
|
+
<File.Import name={['useQuery', 'queryOptions']} path={options.query.importPath} />
|
|
63
|
+
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
64
|
+
<File.Import name={'client'} path={options.client.importPath} />
|
|
65
|
+
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
66
|
+
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
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
|
+
|
|
81
|
+
<QueryKey
|
|
82
|
+
name={queryKey.name}
|
|
83
|
+
typeName={queryKey.typeName}
|
|
84
|
+
operation={operation}
|
|
85
|
+
pathParamsType={options.pathParamsType}
|
|
86
|
+
typeSchemas={type.schemas}
|
|
87
|
+
keysFn={options.query.key}
|
|
88
|
+
/>
|
|
89
|
+
<Client
|
|
90
|
+
name={client.name}
|
|
91
|
+
isExportable={false}
|
|
92
|
+
isIndexable={false}
|
|
93
|
+
baseURL={options.baseURL}
|
|
94
|
+
operation={operation}
|
|
95
|
+
typeSchemas={type.schemas}
|
|
96
|
+
zodSchemas={zod.schemas}
|
|
97
|
+
dataReturnType={options.client.dataReturnType}
|
|
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
|
+
pathParamsType={options.pathParamsType}
|
|
107
|
+
/>
|
|
108
|
+
<Query
|
|
109
|
+
name={query.name}
|
|
110
|
+
queryOptionsName={queryOptions.name}
|
|
111
|
+
typeSchemas={type.schemas}
|
|
112
|
+
pathParamsType={options.pathParamsType}
|
|
113
|
+
operation={operation}
|
|
114
|
+
dataReturnType={options.client.dataReturnType}
|
|
115
|
+
queryKeyName={queryKey.name}
|
|
116
|
+
queryKeyTypeName={queryKey.typeName}
|
|
117
|
+
/>
|
|
118
|
+
</File>
|
|
119
|
+
)
|
|
120
|
+
},
|
|
121
|
+
})
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
pathParamsType={options.pathParamsType}
|
|
98
|
+
parser={options.parser}
|
|
99
|
+
/>
|
|
100
|
+
<QueryOptions
|
|
101
|
+
name={queryOptions.name}
|
|
102
|
+
clientName={client.name}
|
|
103
|
+
queryKeyName={queryKey.name}
|
|
104
|
+
typeSchemas={type.schemas}
|
|
105
|
+
pathParamsType={options.pathParamsType}
|
|
106
|
+
/>
|
|
107
|
+
<SuspenseQuery
|
|
108
|
+
name={query.name}
|
|
109
|
+
queryOptionsName={queryOptions.name}
|
|
110
|
+
typeSchemas={type.schemas}
|
|
111
|
+
pathParamsType={options.pathParamsType}
|
|
112
|
+
operation={operation}
|
|
113
|
+
dataReturnType={options.client.dataReturnType}
|
|
114
|
+
queryKeyName={queryKey.name}
|
|
115
|
+
queryKeyTypeName={queryKey.typeName}
|
|
116
|
+
/>
|
|
117
|
+
</File>
|
|
118
|
+
)
|
|
119
|
+
},
|
|
120
|
+
})
|