@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
|
@@ -1,204 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { File, Function, Type, useApp } from '@kubb/react'
|
|
1
|
+
import { URLPath } from '@kubb/core/utils'
|
|
2
|
+
import { getPathParams } from '@kubb/plugin-oas/utils'
|
|
3
|
+
import { File, Function, FunctionParams, Type } from '@kubb/react'
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { type Operation, isOptional } from '@kubb/oas'
|
|
6
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
8
7
|
import type { ReactNode } from 'react'
|
|
9
8
|
import type { PluginReactQuery } from '../types'
|
|
10
9
|
|
|
11
|
-
type
|
|
12
|
-
/**
|
|
13
|
-
* Name of the function
|
|
14
|
-
*/
|
|
10
|
+
type Props = {
|
|
15
11
|
name: string
|
|
16
|
-
/**
|
|
17
|
-
* TypeName of the function in PascalCase
|
|
18
|
-
*/
|
|
19
12
|
typeName: string
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Generics that needs to be added for TypeScript
|
|
26
|
-
*/
|
|
27
|
-
generics?: string
|
|
28
|
-
/**
|
|
29
|
-
* ReturnType(see async for adding Promise type)
|
|
30
|
-
*/
|
|
31
|
-
returnType?: string
|
|
32
|
-
/**
|
|
33
|
-
* Options for JSdocs
|
|
34
|
-
*/
|
|
35
|
-
JSDoc?: {
|
|
36
|
-
comments: string[]
|
|
37
|
-
}
|
|
38
|
-
keys?: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function Template({ name, typeName, params, generics, returnType, JSDoc, keys }: TemplateProps): ReactNode {
|
|
42
|
-
return (
|
|
43
|
-
<>
|
|
44
|
-
<File.Source name={name} isExportable isIndexable>
|
|
45
|
-
<Function.Arrow name={name} export generics={generics} params={params} returnType={returnType} singleLine JSDoc={JSDoc}>
|
|
46
|
-
{`[${keys}] as const`}
|
|
47
|
-
</Function.Arrow>
|
|
48
|
-
</File.Source>
|
|
49
|
-
|
|
50
|
-
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
51
|
-
<Type name={typeName} export>
|
|
52
|
-
{`ReturnType<typeof ${name}>`}
|
|
53
|
-
</Type>
|
|
54
|
-
</File.Source>
|
|
55
|
-
</>
|
|
56
|
-
)
|
|
13
|
+
typeSchemas: OperationSchemas
|
|
14
|
+
operation: Operation
|
|
15
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
16
|
+
keysFn: ((keys: unknown[]) => unknown[]) | undefined
|
|
57
17
|
}
|
|
58
18
|
|
|
59
|
-
type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
name: string
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const defaultTemplates = {
|
|
68
|
-
get react() {
|
|
69
|
-
return function (props: FrameworkProps): ReactNode {
|
|
70
|
-
return <Template {...props} />
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
get solid() {
|
|
74
|
-
return function (props: FrameworkProps): ReactNode {
|
|
75
|
-
return <Template {...props} />
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
get svelte() {
|
|
79
|
-
return function (props: FrameworkProps): ReactNode {
|
|
80
|
-
return <Template {...props} />
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
get vue() {
|
|
84
|
-
return function ({ context, ...rest }: FrameworkProps): ReactNode {
|
|
85
|
-
const { factory } = context
|
|
86
|
-
|
|
87
|
-
const {
|
|
88
|
-
plugin: {
|
|
89
|
-
options: { pathParamsType, query },
|
|
90
|
-
},
|
|
91
|
-
} = useApp<PluginReactQuery>()
|
|
92
|
-
const { getSchemas } = useOperationManager()
|
|
93
|
-
const operation = useOperation()
|
|
94
|
-
|
|
95
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
96
|
-
const path = new URLPath(operation.path)
|
|
97
|
-
const params = new FunctionParams()
|
|
98
|
-
const withQueryParams = !!schemas.queryParams?.name
|
|
99
|
-
const withRequest = !!schemas.request?.name
|
|
100
|
-
|
|
101
|
-
params.add([
|
|
102
|
-
...(pathParamsType === 'object'
|
|
103
|
-
? [
|
|
104
|
-
getASTParams(schemas.pathParams, {
|
|
105
|
-
typed: true,
|
|
106
|
-
override: (item) => ({
|
|
107
|
-
...item,
|
|
108
|
-
type: `MaybeRef<${item.type}>`,
|
|
109
|
-
}),
|
|
110
|
-
}),
|
|
111
|
-
]
|
|
112
|
-
: getASTParams(schemas.pathParams, {
|
|
113
|
-
typed: true,
|
|
114
|
-
override: (item) => ({
|
|
115
|
-
...item,
|
|
116
|
-
type: `MaybeRef<${item.type}>`,
|
|
117
|
-
}),
|
|
118
|
-
})),
|
|
119
|
-
{
|
|
120
|
-
name: 'params',
|
|
121
|
-
type: `MaybeRef<${`${factory.name}["queryParams"]`}>`,
|
|
122
|
-
enabled: withQueryParams,
|
|
123
|
-
required: isRequired(schemas.queryParams?.schema),
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: 'request',
|
|
127
|
-
type: `MaybeRef<${`${factory.name}["request"]`}>`,
|
|
128
|
-
enabled: withRequest,
|
|
129
|
-
required: isRequired(schemas.request?.schema),
|
|
130
|
-
},
|
|
131
|
-
])
|
|
132
|
-
|
|
133
|
-
const keys = [
|
|
134
|
-
path.toObject({
|
|
135
|
-
type: 'path',
|
|
136
|
-
stringify: true,
|
|
137
|
-
replacer: (pathParam) => `unref(${pathParam})`,
|
|
138
|
-
}),
|
|
139
|
-
withQueryParams ? '...(params ? [params] : [])' : undefined,
|
|
140
|
-
withRequest ? '...(request ? [request] : [])' : undefined,
|
|
141
|
-
].filter(Boolean)
|
|
142
|
-
|
|
143
|
-
return <Template {...rest} params={params.toString()} keys={keys.join(', ')} />
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
} as const
|
|
147
|
-
|
|
148
|
-
type Props = {
|
|
149
|
-
name: string
|
|
150
|
-
typeName: string
|
|
151
|
-
keysFn: (keys: unknown[]) => unknown[]
|
|
152
|
-
factory: {
|
|
153
|
-
name: string
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* This will make it possible to override the default behaviour.
|
|
157
|
-
*/
|
|
158
|
-
Template?: React.ComponentType<FrameworkProps>
|
|
19
|
+
type GetParamsProps = {
|
|
20
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
21
|
+
typeSchemas: OperationSchemas
|
|
159
22
|
}
|
|
160
23
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
24
|
+
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
25
|
+
return FunctionParams.factory({
|
|
26
|
+
pathParams: {
|
|
27
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
28
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
165
29
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
30
|
+
data: typeSchemas.request?.name
|
|
31
|
+
? {
|
|
32
|
+
type: typeSchemas.request?.name,
|
|
33
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
34
|
+
}
|
|
35
|
+
: undefined,
|
|
36
|
+
params: typeSchemas.queryParams?.name
|
|
37
|
+
? {
|
|
38
|
+
type: typeSchemas.queryParams?.name,
|
|
39
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
169
44
|
|
|
170
|
-
|
|
45
|
+
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
|
|
171
46
|
const path = new URLPath(operation.path)
|
|
172
|
-
const params =
|
|
173
|
-
const withQueryParams = !!schemas.queryParams?.name
|
|
174
|
-
const withRequest = !!schemas.request?.name
|
|
175
|
-
|
|
176
|
-
params.add([
|
|
177
|
-
...(pathParamsType === 'object' ? [getASTParams(schemas.pathParams, { typed: true })] : getASTParams(schemas.pathParams, { typed: true })),
|
|
178
|
-
{
|
|
179
|
-
name: 'params',
|
|
180
|
-
type: `${factory.name}["queryParams"]`,
|
|
181
|
-
enabled: withQueryParams,
|
|
182
|
-
required: isRequired(schemas.queryParams?.schema),
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
name: 'data',
|
|
186
|
-
type: `${factory.name}["request"]`,
|
|
187
|
-
enabled: withRequest,
|
|
188
|
-
required: isRequired(schemas.request?.schema),
|
|
189
|
-
},
|
|
190
|
-
])
|
|
191
|
-
|
|
47
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
192
48
|
const keys = [
|
|
193
49
|
path.toObject({
|
|
194
50
|
type: 'path',
|
|
195
51
|
stringify: true,
|
|
196
52
|
}),
|
|
197
|
-
|
|
198
|
-
|
|
53
|
+
typeSchemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
|
|
54
|
+
typeSchemas.request?.name ? '...(data ? [data] : [])' : undefined,
|
|
199
55
|
].filter(Boolean)
|
|
200
56
|
|
|
201
|
-
return
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<File.Source name={name} isExportable isIndexable>
|
|
60
|
+
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
61
|
+
{`[${keysFn(keys).join(', ')}] as const`}
|
|
62
|
+
</Function.Arrow>
|
|
63
|
+
</File.Source>
|
|
64
|
+
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
65
|
+
<Type name={typeName} export>
|
|
66
|
+
{`ReturnType<typeof ${name}>`}
|
|
67
|
+
</Type>
|
|
68
|
+
</File.Source>
|
|
69
|
+
</>
|
|
70
|
+
)
|
|
202
71
|
}
|
|
203
72
|
|
|
204
|
-
QueryKey.
|
|
73
|
+
QueryKey.getParams = getParams
|