@kubb/plugin-react-query 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +13 -4
- package/dist/chunk-ESENIDWJ.js +608 -0
- package/dist/chunk-ESENIDWJ.js.map +1 -0
- package/dist/chunk-HAC4WPCC.js +608 -0
- package/dist/chunk-HAC4WPCC.js.map +1 -0
- package/dist/chunk-JQEH3UHY.cjs +618 -0
- package/dist/chunk-JQEH3UHY.cjs.map +1 -0
- package/dist/chunk-JYBGTT23.cjs +618 -0
- package/dist/chunk-JYBGTT23.cjs.map +1 -0
- package/dist/components.cjs +35 -14
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +143 -7
- package/dist/components.d.ts +143 -7
- package/dist/components.js +2 -14
- 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 +77 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +56 -140
- package/dist/index.js.map +1 -1
- package/dist/types-DFHc63S9.d.cts +179 -0
- package/dist/types-DFHc63S9.d.ts +179 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +121 -0
- package/src/components/Mutation.tsx +113 -321
- package/src/components/Query.tsx +91 -598
- package/src/components/QueryKey.tsx +51 -178
- package/src/components/QueryOptions.tsx +65 -468
- package/src/components/SuspenseQuery.tsx +129 -0
- package/src/components/index.ts +3 -1
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +50 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +50 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
- package/src/generators/__snapshots__/findByTags.ts +50 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +50 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +50 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +50 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +56 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +56 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +48 -0
- package/src/generators/__snapshots__/updatePetById.ts +38 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +125 -0
- package/src/generators/mutationGenerator.tsx +96 -0
- package/src/generators/queryGenerator.tsx +122 -0
- package/src/generators/suspenseQueryGenerator.tsx +121 -0
- package/src/plugin.ts +51 -73
- package/src/types.ts +43 -91
- package/dist/chunk-5IL6M74X.js +0 -1504
- package/dist/chunk-5IL6M74X.js.map +0 -1
- package/dist/chunk-JFX7DCS7.cjs +0 -1504
- package/dist/chunk-JFX7DCS7.cjs.map +0 -1
- package/dist/index-C9fwRDH7.d.cts +0 -579
- package/dist/index-C9fwRDH7.d.ts +0 -579
- package/src/OperationGenerator.tsx +0 -86
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
- package/src/__snapshots__/upload/UploadFile.ts +0 -67
- package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
- package/src/components/Operations.tsx +0 -74
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -55
- package/src/components/__snapshots__/gen/showPetById.ts +0 -57
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
- package/src/utils.ts +0 -96
|
@@ -1,200 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { getASTParams } from '@kubb/plugin-oas/utils'
|
|
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 {
|
|
5
|
+
import { type Operation, isOptional } from '@kubb/oas'
|
|
6
|
+
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
7
7
|
import type { ReactNode } from 'react'
|
|
8
8
|
import type { PluginReactQuery } from '../types'
|
|
9
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
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
|
-
<Function.Arrow name={name} export generics={generics} params={params} returnType={returnType} singleLine JSDoc={JSDoc}>
|
|
45
|
-
{`[${keys}] as const`}
|
|
46
|
-
</Function.Arrow>
|
|
47
|
-
|
|
48
|
-
<Type name={typeName} export>
|
|
49
|
-
{`ReturnType<typeof ${name}>`}
|
|
50
|
-
</Type>
|
|
51
|
-
</>
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type FrameworkProps = TemplateProps & {
|
|
56
|
-
context: {
|
|
57
|
-
factory: {
|
|
58
|
-
name: string
|
|
59
|
-
}
|
|
60
|
-
}
|
|
13
|
+
typeSchemas: OperationSchemas
|
|
14
|
+
operation: Operation
|
|
15
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
16
|
+
keysFn: ((keys: unknown[]) => unknown[]) | undefined
|
|
61
17
|
}
|
|
62
18
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return <Template {...props} />
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
get solid() {
|
|
70
|
-
return function (props: FrameworkProps): ReactNode {
|
|
71
|
-
return <Template {...props} />
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
get svelte() {
|
|
75
|
-
return function (props: FrameworkProps): ReactNode {
|
|
76
|
-
return <Template {...props} />
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
get vue() {
|
|
80
|
-
return function ({ context, ...rest }: FrameworkProps): ReactNode {
|
|
81
|
-
const { factory } = context
|
|
82
|
-
|
|
83
|
-
const {
|
|
84
|
-
plugin: {
|
|
85
|
-
options: { pathParamsType, query },
|
|
86
|
-
},
|
|
87
|
-
} = useApp<PluginReactQuery>()
|
|
88
|
-
const { getSchemas } = useOperationManager()
|
|
89
|
-
const operation = useOperation()
|
|
90
|
-
|
|
91
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
92
|
-
const path = new URLPath(operation.path)
|
|
93
|
-
const params = new FunctionParams()
|
|
94
|
-
const withQueryParams = !!schemas.queryParams?.name
|
|
95
|
-
const withRequest = !!schemas.request?.name
|
|
96
|
-
|
|
97
|
-
params.add([
|
|
98
|
-
...(pathParamsType === 'object'
|
|
99
|
-
? [
|
|
100
|
-
getASTParams(schemas.pathParams, {
|
|
101
|
-
typed: true,
|
|
102
|
-
override: (item) => ({
|
|
103
|
-
...item,
|
|
104
|
-
type: `MaybeRef<${item.type}>`,
|
|
105
|
-
}),
|
|
106
|
-
}),
|
|
107
|
-
]
|
|
108
|
-
: getASTParams(schemas.pathParams, {
|
|
109
|
-
typed: true,
|
|
110
|
-
override: (item) => ({
|
|
111
|
-
...item,
|
|
112
|
-
type: `MaybeRef<${item.type}>`,
|
|
113
|
-
}),
|
|
114
|
-
})),
|
|
115
|
-
{
|
|
116
|
-
name: 'params',
|
|
117
|
-
type: `MaybeRef<${`${factory.name}["queryParams"]`}>`,
|
|
118
|
-
enabled: withQueryParams,
|
|
119
|
-
required: isRequired(schemas.queryParams?.schema),
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: 'request',
|
|
123
|
-
type: `MaybeRef<${`${factory.name}["request"]`}>`,
|
|
124
|
-
enabled: withRequest,
|
|
125
|
-
required: isRequired(schemas.request?.schema),
|
|
126
|
-
},
|
|
127
|
-
])
|
|
128
|
-
|
|
129
|
-
const keys = [
|
|
130
|
-
path.toObject({
|
|
131
|
-
type: 'path',
|
|
132
|
-
stringify: true,
|
|
133
|
-
replacer: (pathParam) => `unref(${pathParam})`,
|
|
134
|
-
}),
|
|
135
|
-
withQueryParams ? '...(params ? [params] : [])' : undefined,
|
|
136
|
-
withRequest ? '...(request ? [request] : [])' : undefined,
|
|
137
|
-
].filter(Boolean)
|
|
138
|
-
|
|
139
|
-
return <Template {...rest} params={params.toString()} keys={keys.join(', ')} />
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
} as const
|
|
143
|
-
|
|
144
|
-
type Props = {
|
|
145
|
-
name: string
|
|
146
|
-
typeName: string
|
|
147
|
-
keysFn: (keys: unknown[]) => unknown[]
|
|
148
|
-
factory: {
|
|
149
|
-
name: string
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* This will make it possible to override the default behaviour.
|
|
153
|
-
*/
|
|
154
|
-
Template?: React.ComponentType<FrameworkProps>
|
|
19
|
+
type GetParamsProps = {
|
|
20
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
21
|
+
typeSchemas: OperationSchemas
|
|
155
22
|
}
|
|
156
23
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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 }),
|
|
161
29
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
+
}
|
|
165
44
|
|
|
166
|
-
|
|
45
|
+
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
|
|
167
46
|
const path = new URLPath(operation.path)
|
|
168
|
-
const params =
|
|
169
|
-
const withQueryParams = !!schemas.queryParams?.name
|
|
170
|
-
const withRequest = !!schemas.request?.name
|
|
171
|
-
|
|
172
|
-
params.add([
|
|
173
|
-
...(pathParamsType === 'object' ? [getASTParams(schemas.pathParams, { typed: true })] : getASTParams(schemas.pathParams, { typed: true })),
|
|
174
|
-
{
|
|
175
|
-
name: 'params',
|
|
176
|
-
type: `${factory.name}["queryParams"]`,
|
|
177
|
-
enabled: withQueryParams,
|
|
178
|
-
required: isRequired(schemas.queryParams?.schema),
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
name: 'data',
|
|
182
|
-
type: `${factory.name}["request"]`,
|
|
183
|
-
enabled: withRequest,
|
|
184
|
-
required: isRequired(schemas.request?.schema),
|
|
185
|
-
},
|
|
186
|
-
])
|
|
187
|
-
|
|
47
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
188
48
|
const keys = [
|
|
189
49
|
path.toObject({
|
|
190
50
|
type: 'path',
|
|
191
51
|
stringify: true,
|
|
192
52
|
}),
|
|
193
|
-
|
|
194
|
-
|
|
53
|
+
typeSchemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
|
|
54
|
+
typeSchemas.request?.name ? '...(data ? [data] : [])' : undefined,
|
|
195
55
|
].filter(Boolean)
|
|
196
56
|
|
|
197
|
-
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
|
+
)
|
|
198
71
|
}
|
|
199
72
|
|
|
200
|
-
QueryKey.
|
|
73
|
+
QueryKey.getParams = getParams
|