@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.100

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.
Files changed (39) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -23
  3. package/dist/index.cjs +1651 -140
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +358 -6
  6. package/dist/index.js +1618 -138
  7. package/dist/index.js.map +1 -1
  8. package/package.json +48 -76
  9. package/dist/components-Yjoe78Y7.cjs +0 -1119
  10. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  11. package/dist/components-_AMBl0g-.js +0 -1029
  12. package/dist/components-_AMBl0g-.js.map +0 -1
  13. package/dist/components.cjs +0 -9
  14. package/dist/components.d.ts +0 -242
  15. package/dist/components.js +0 -2
  16. package/dist/generators-CR34GjVu.js +0 -661
  17. package/dist/generators-CR34GjVu.js.map +0 -1
  18. package/dist/generators-DH8VkK1q.cjs +0 -678
  19. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  20. package/dist/generators.cjs +0 -5
  21. package/dist/generators.d.ts +0 -511
  22. package/dist/generators.js +0 -2
  23. package/dist/types-CgDFUvfZ.d.ts +0 -211
  24. package/src/components/InfiniteQuery.tsx +0 -208
  25. package/src/components/InfiniteQueryOptions.tsx +0 -249
  26. package/src/components/Mutation.tsx +0 -185
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/Query.tsx +0 -208
  29. package/src/components/QueryKey.tsx +0 -94
  30. package/src/components/QueryOptions.tsx +0 -185
  31. package/src/components/index.ts +0 -7
  32. package/src/generators/index.ts +0 -3
  33. package/src/generators/infiniteQueryGenerator.tsx +0 -213
  34. package/src/generators/mutationGenerator.tsx +0 -176
  35. package/src/generators/queryGenerator.tsx +0 -191
  36. package/src/index.ts +0 -2
  37. package/src/plugin.ts +0 -218
  38. package/src/types.ts +0 -176
  39. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -1,185 +0,0 @@
1
- import { isOptional, type Operation } from '@kubb/oas'
2
- import { Client } from '@kubb/plugin-client/components'
3
- import type { OperationSchemas } from '@kubb/plugin-oas'
4
- import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
5
- import { File, Function, FunctionParams } from '@kubb/react-fabric'
6
- import type { FabricReactNode, Params } from '@kubb/react-fabric/types'
7
- import type { PluginVueQuery } from '../types.ts'
8
- import { MutationKey } from './MutationKey.tsx'
9
-
10
- type Props = {
11
- /**
12
- * Name of the function
13
- */
14
- name: string
15
- typeName: string
16
- clientName: string
17
- mutationKeyName: string
18
- typeSchemas: OperationSchemas
19
- operation: Operation
20
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
21
- paramsType: PluginVueQuery['resolvedOptions']['paramsType']
22
- dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
23
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
24
- }
25
-
26
- type GetParamsProps = {
27
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
28
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
29
- dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
30
- typeSchemas: OperationSchemas
31
- }
32
-
33
- function getParams({ paramsCasing, dataReturnType, typeSchemas }: GetParamsProps) {
34
- const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
35
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
36
-
37
- const mutationParams = FunctionParams.factory({
38
- ...getPathParams(typeSchemas.pathParams, {
39
- typed: true,
40
- casing: paramsCasing,
41
- override(item) {
42
- return {
43
- ...item,
44
- type: `MaybeRefOrGetter<${item.type}>`,
45
- }
46
- },
47
- }),
48
- data: typeSchemas.request?.name
49
- ? {
50
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
51
- optional: isOptional(typeSchemas.request?.schema),
52
- }
53
- : undefined,
54
- params: typeSchemas.queryParams?.name
55
- ? {
56
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
57
- optional: isOptional(typeSchemas.queryParams?.schema),
58
- }
59
- : undefined,
60
- headers: typeSchemas.headerParams?.name
61
- ? {
62
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
63
- optional: isOptional(typeSchemas.headerParams?.schema),
64
- }
65
- : undefined,
66
- })
67
- const TRequest = mutationParams.toConstructor()
68
-
69
- return FunctionParams.factory({
70
- options: {
71
- type: `
72
- {
73
- mutation?: MutationObserverOptions<${[TData, TError, TRequest ? `{${TRequest}}` : 'void', 'TContext'].join(', ')}> & { client?: QueryClient },
74
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'},
75
- }
76
- `,
77
- default: '{}',
78
- },
79
- })
80
- }
81
-
82
- export function Mutation({
83
- name,
84
- clientName,
85
- paramsCasing,
86
- paramsType,
87
- pathParamsType,
88
- dataReturnType,
89
- typeSchemas,
90
- operation,
91
- mutationKeyName,
92
- }: Props): FabricReactNode {
93
- const mutationKeyParams = MutationKey.getParams({
94
- pathParamsType,
95
- typeSchemas,
96
- })
97
-
98
- const params = getParams({
99
- paramsCasing,
100
- pathParamsType,
101
- dataReturnType,
102
- typeSchemas,
103
- })
104
-
105
- const clientParams = Client.getParams({
106
- paramsCasing,
107
- paramsType,
108
- typeSchemas,
109
- pathParamsType,
110
- isConfigurable: true,
111
- })
112
-
113
- const mutationParams = FunctionParams.factory({
114
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
115
- data: typeSchemas.request?.name
116
- ? {
117
- type: typeSchemas.request?.name,
118
- optional: isOptional(typeSchemas.request?.schema),
119
- }
120
- : undefined,
121
- params: typeSchemas.queryParams?.name
122
- ? {
123
- type: typeSchemas.queryParams?.name,
124
- optional: isOptional(typeSchemas.queryParams?.schema),
125
- }
126
- : undefined,
127
- headers: typeSchemas.headerParams?.name
128
- ? {
129
- type: typeSchemas.headerParams?.name,
130
- optional: isOptional(typeSchemas.headerParams?.schema),
131
- }
132
- : undefined,
133
- })
134
- const dataParams = FunctionParams.factory({
135
- data: {
136
- // No use of pathParams because useMutation can only take one argument in object form,
137
- // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
138
- mode: 'object',
139
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
140
- if (value) {
141
- acc[key] = {
142
- ...value,
143
- type: undefined,
144
- }
145
- }
146
-
147
- return acc
148
- }, {} as Params),
149
- },
150
- })
151
-
152
- const TRequest = mutationParams.toConstructor()
153
- const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
154
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
155
-
156
- const generics = [TData, TError, TRequest ? `{${TRequest}}` : 'void', 'TContext'].join(', ')
157
-
158
- return (
159
- <File.Source name={name} isExportable isIndexable>
160
- <Function
161
- name={name}
162
- export
163
- params={params.toConstructor()}
164
- JSDoc={{
165
- comments: getComments(operation),
166
- }}
167
- generics={['TContext']}
168
- >
169
- {`
170
- const { mutation = {}, client: config = {} } = options ?? {}
171
- const { client: queryClient, ...mutationOptions } = mutation;
172
- const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
173
-
174
- return useMutation<${generics}>({
175
- mutationFn: async(${dataParams.toConstructor()}) => {
176
- return ${clientName}(${clientParams.toCall()})
177
- },
178
- mutationKey,
179
- ...mutationOptions
180
- }, queryClient)
181
- `}
182
- </Function>
183
- </File.Source>
184
- )
185
- }
@@ -1 +0,0 @@
1
- export { MutationKey } from '@internals/tanstack-query'
@@ -1,208 +0,0 @@
1
- import { getDefaultValue, isOptional, type Operation } from '@kubb/oas'
2
- import type { OperationSchemas } from '@kubb/plugin-oas'
3
- import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
4
- import { File, Function, FunctionParams } from '@kubb/react-fabric'
5
- import type { FabricReactNode } from '@kubb/react-fabric/types'
6
- import type { PluginVueQuery } from '../types.ts'
7
- import { QueryKey } from './QueryKey.tsx'
8
- import { QueryOptions } from './QueryOptions.tsx'
9
-
10
- type Props = {
11
- /**
12
- * Name of the function
13
- */
14
- name: string
15
- queryOptionsName: string
16
- queryKeyName: string
17
- queryKeyTypeName: string
18
- typeSchemas: OperationSchemas
19
- operation: Operation
20
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
21
- paramsType: PluginVueQuery['resolvedOptions']['paramsType']
22
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
23
- dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
24
- }
25
-
26
- type GetParamsProps = {
27
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
28
- paramsType: PluginVueQuery['resolvedOptions']['paramsType']
29
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
30
- dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
31
- typeSchemas: OperationSchemas
32
- }
33
-
34
- function getParams({ paramsCasing, paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
35
- const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
36
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
37
-
38
- if (paramsType === 'object') {
39
- const pathParams = getPathParams(typeSchemas.pathParams, {
40
- typed: true,
41
- casing: paramsCasing,
42
- override(item) {
43
- return {
44
- ...item,
45
- type: `MaybeRefOrGetter<${item.type}>`,
46
- }
47
- },
48
- })
49
- const children = {
50
- ...pathParams,
51
- data: typeSchemas.request?.name
52
- ? {
53
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
54
- optional: isOptional(typeSchemas.request?.schema),
55
- }
56
- : undefined,
57
- params: typeSchemas.queryParams?.name
58
- ? {
59
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
60
- optional: isOptional(typeSchemas.queryParams?.schema),
61
- }
62
- : undefined,
63
- headers: typeSchemas.headerParams?.name
64
- ? {
65
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
66
- optional: isOptional(typeSchemas.headerParams?.schema),
67
- }
68
- : undefined,
69
- }
70
-
71
- // Check if all children are optional or undefined
72
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
73
-
74
- return FunctionParams.factory({
75
- data: {
76
- mode: 'object',
77
- children,
78
- default: allChildrenAreOptional ? '{}' : undefined,
79
- },
80
- options: {
81
- type: `
82
- {
83
- query?: Partial<UseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },
84
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
85
- }
86
- `,
87
- default: '{}',
88
- },
89
- })
90
- }
91
-
92
- return FunctionParams.factory({
93
- pathParams: typeSchemas.pathParams?.name
94
- ? {
95
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
96
- children: getPathParams(typeSchemas.pathParams, {
97
- typed: true,
98
- casing: paramsCasing,
99
- override(item) {
100
- return {
101
- ...item,
102
- type: `MaybeRefOrGetter<${item.type}>`,
103
- }
104
- },
105
- }),
106
- default: getDefaultValue(typeSchemas.pathParams?.schema),
107
- }
108
- : undefined,
109
- data: typeSchemas.request?.name
110
- ? {
111
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
112
- optional: isOptional(typeSchemas.request?.schema),
113
- }
114
- : undefined,
115
- params: typeSchemas.queryParams?.name
116
- ? {
117
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
118
- optional: isOptional(typeSchemas.queryParams?.schema),
119
- }
120
- : undefined,
121
- headers: typeSchemas.headerParams?.name
122
- ? {
123
- type: `MaybeRefOrGetter<${typeSchemas.headerParams?.name}>`,
124
- optional: isOptional(typeSchemas.headerParams?.schema),
125
- }
126
- : undefined,
127
- options: {
128
- type: `
129
- {
130
- query?: Partial<UseQueryOptions<${[TData, TError, 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>> & { client?: QueryClient },
131
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
132
- }
133
- `,
134
- default: '{}',
135
- },
136
- })
137
- }
138
-
139
- export function Query({
140
- name,
141
- queryKeyTypeName,
142
- queryOptionsName,
143
- queryKeyName,
144
- paramsType,
145
- paramsCasing,
146
- pathParamsType,
147
- dataReturnType,
148
- typeSchemas,
149
- operation,
150
- }: Props): FabricReactNode {
151
- const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
152
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
153
- const returnType = `UseQueryReturnType<${['TData', TError].join(', ')}> & { queryKey: TQueryKey }`
154
- const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
155
-
156
- const queryKeyParams = QueryKey.getParams({
157
- pathParamsType,
158
- typeSchemas,
159
- paramsCasing,
160
- })
161
- const queryOptionsParams = QueryOptions.getParams({
162
- paramsType,
163
- pathParamsType,
164
- typeSchemas,
165
- paramsCasing,
166
- })
167
- const params = getParams({
168
- paramsCasing,
169
- paramsType,
170
- pathParamsType,
171
- dataReturnType,
172
- typeSchemas,
173
- })
174
-
175
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`
176
-
177
- return (
178
- <File.Source name={name} isExportable isIndexable>
179
- <Function
180
- name={name}
181
- export
182
- generics={generics.join(', ')}
183
- params={params.toConstructor()}
184
- JSDoc={{
185
- comments: getComments(operation),
186
- }}
187
- >
188
- {`
189
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
190
- const { client: queryClient, ...resolvedOptions } = queryConfig
191
- const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParams.toCall()})
192
-
193
- const query = useQuery({
194
- ...${queryOptions},
195
- ...resolvedOptions,
196
- queryKey
197
- } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
198
-
199
- query.queryKey = queryKey as TQueryKey
200
-
201
- return query
202
- `}
203
- </Function>
204
- </File.Source>
205
- )
206
- }
207
-
208
- Query.getParams = getParams
@@ -1,94 +0,0 @@
1
- import { URLPath } from '@internals/utils'
2
- import { isOptional, type Operation } from '@kubb/oas'
3
- import type { OperationSchemas } from '@kubb/plugin-oas'
4
- import { getPathParams } from '@kubb/plugin-oas/utils'
5
- import { File, Function, FunctionParams, Type } from '@kubb/react-fabric'
6
- import type { FabricReactNode } from '@kubb/react-fabric/types'
7
- import type { PluginVueQuery, Transformer } from '../types'
8
-
9
- type Props = {
10
- name: string
11
- typeName: string
12
- typeSchemas: OperationSchemas
13
- operation: Operation
14
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
15
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
16
- transformer: Transformer | undefined
17
- }
18
-
19
- type GetParamsProps = {
20
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
21
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
22
- typeSchemas: OperationSchemas
23
- }
24
-
25
- function getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {
26
- return FunctionParams.factory({
27
- pathParams: {
28
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
29
- children: getPathParams(typeSchemas.pathParams, {
30
- typed: true,
31
- casing: paramsCasing,
32
- override(item) {
33
- return {
34
- ...item,
35
- type: `MaybeRefOrGetter<${item.type}>`,
36
- }
37
- },
38
- }),
39
- },
40
- data: typeSchemas.request?.name
41
- ? {
42
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
43
- optional: isOptional(typeSchemas.request?.schema),
44
- }
45
- : undefined,
46
- params: typeSchemas.queryParams?.name
47
- ? {
48
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
49
- optional: isOptional(typeSchemas.queryParams?.schema),
50
- }
51
- : undefined,
52
- })
53
- }
54
-
55
- const getTransformer: Transformer = ({ operation, schemas, casing }) => {
56
- const path = new URLPath(operation.path, { casing })
57
- const keys = [
58
- path.toObject({
59
- type: 'path',
60
- stringify: true,
61
- }),
62
- schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
63
- schemas.request?.name ? '...(data ? [data] : [])' : undefined,
64
- ].filter(Boolean)
65
-
66
- return keys
67
- }
68
-
69
- export function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): FabricReactNode {
70
- const params = getParams({ pathParamsType, typeSchemas, paramsCasing })
71
- const keys = transformer({
72
- operation,
73
- schemas: typeSchemas,
74
- casing: paramsCasing,
75
- })
76
-
77
- return (
78
- <>
79
- <File.Source name={name} isExportable isIndexable>
80
- <Function.Arrow name={name} export params={params.toConstructor()} singleLine>
81
- {`[${keys.join(', ')}] as const`}
82
- </Function.Arrow>
83
- </File.Source>
84
- <File.Source name={typeName} isExportable isIndexable isTypeOnly>
85
- <Type name={typeName} export>
86
- {`ReturnType<typeof ${name}>`}
87
- </Type>
88
- </File.Source>
89
- </>
90
- )
91
- }
92
-
93
- QueryKey.getParams = getParams
94
- QueryKey.getTransformer = getTransformer
@@ -1,185 +0,0 @@
1
- import { getDefaultValue, isOptional } from '@kubb/oas'
2
- import { Client } from '@kubb/plugin-client/components'
3
- import type { OperationSchemas } from '@kubb/plugin-oas'
4
- import { getPathParams } from '@kubb/plugin-oas/utils'
5
- import { File, Function, FunctionParams } from '@kubb/react-fabric'
6
- import type { FabricReactNode } from '@kubb/react-fabric/types'
7
- import type { PluginVueQuery } from '../types.ts'
8
- import { QueryKey } from './QueryKey.tsx'
9
-
10
- type Props = {
11
- name: string
12
- clientName: string
13
- queryKeyName: string
14
- typeSchemas: OperationSchemas
15
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
16
- paramsType: PluginVueQuery['resolvedOptions']['paramsType']
17
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
18
- dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
19
- }
20
-
21
- type GetParamsProps = {
22
- paramsCasing: PluginVueQuery['resolvedOptions']['paramsCasing']
23
- paramsType: PluginVueQuery['resolvedOptions']['paramsType']
24
- pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
25
- typeSchemas: OperationSchemas
26
- }
27
-
28
- function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
29
- if (paramsType === 'object') {
30
- const children = {
31
- ...getPathParams(typeSchemas.pathParams, {
32
- typed: true,
33
- casing: paramsCasing,
34
- override(item) {
35
- return {
36
- ...item,
37
- type: `MaybeRefOrGetter<${item.type}>`,
38
- }
39
- },
40
- }),
41
- data: typeSchemas.request?.name
42
- ? {
43
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
44
- optional: isOptional(typeSchemas.request?.schema),
45
- }
46
- : undefined,
47
- params: typeSchemas.queryParams?.name
48
- ? {
49
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
50
- optional: isOptional(typeSchemas.queryParams?.schema),
51
- }
52
- : undefined,
53
- headers: typeSchemas.headerParams?.name
54
- ? {
55
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
56
- optional: isOptional(typeSchemas.headerParams?.schema),
57
- }
58
- : undefined,
59
- }
60
-
61
- // Check if all children are optional or undefined
62
- const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
63
-
64
- return FunctionParams.factory({
65
- data: {
66
- mode: 'object',
67
- children,
68
- default: allChildrenAreOptional ? '{}' : undefined,
69
- },
70
- config: {
71
- type: typeSchemas.request?.name
72
- ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }`
73
- : 'Partial<RequestConfig> & { client?: Client }',
74
- default: '{}',
75
- },
76
- })
77
- }
78
-
79
- return FunctionParams.factory({
80
- pathParams: {
81
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
82
- children: getPathParams(typeSchemas.pathParams, {
83
- typed: true,
84
- casing: paramsCasing,
85
- override(item) {
86
- return {
87
- ...item,
88
- type: `MaybeRefOrGetter<${item.type}>`,
89
- }
90
- },
91
- }),
92
- default: getDefaultValue(typeSchemas.pathParams?.schema),
93
- },
94
- data: typeSchemas.request?.name
95
- ? {
96
- type: `MaybeRefOrGetter<${typeSchemas.request?.name}>`,
97
- optional: isOptional(typeSchemas.request?.schema),
98
- }
99
- : undefined,
100
- params: typeSchemas.queryParams?.name
101
- ? {
102
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
103
- optional: isOptional(typeSchemas.queryParams?.schema),
104
- }
105
- : undefined,
106
- headers: typeSchemas.headerParams?.name
107
- ? {
108
- type: `MaybeRefOrGetter<${typeSchemas.queryParams?.name}>`,
109
- optional: isOptional(typeSchemas.headerParams?.schema),
110
- }
111
- : undefined,
112
- config: {
113
- type: typeSchemas.request?.name
114
- ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }`
115
- : 'Partial<RequestConfig> & { client?: Client }',
116
- default: '{}',
117
- },
118
- })
119
- }
120
-
121
- export function QueryOptions({
122
- name,
123
- clientName,
124
- dataReturnType,
125
- typeSchemas,
126
- paramsCasing,
127
- paramsType,
128
- pathParamsType,
129
- queryKeyName,
130
- }: Props): FabricReactNode {
131
- const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
132
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
133
-
134
- const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
135
- const clientParams = Client.getParams({
136
- paramsType,
137
- paramsCasing,
138
- typeSchemas,
139
- pathParamsType,
140
- isConfigurable: true,
141
- })
142
- const queryKeyParams = QueryKey.getParams({
143
- pathParamsType,
144
- typeSchemas,
145
- paramsCasing,
146
- })
147
-
148
- const enabled = Object.entries(queryKeyParams.flatParams)
149
- .map(([key, item]) => {
150
- // Only include if the parameter exists and is NOT optional
151
- // This ensures we only check required parameters
152
- return item && !item.optional && !item.default ? key : undefined
153
- })
154
- .filter(Boolean)
155
- .join('&& ')
156
-
157
- const enabledText = enabled ? `enabled: !!(${enabled}),` : ''
158
-
159
- return (
160
- <File.Source name={name} isExportable isIndexable>
161
- <Function name={name} export params={params.toConstructor()}>
162
- {`
163
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
164
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
165
- ${enabledText}
166
- queryKey,
167
- queryFn: async ({ signal }) => {
168
- return ${clientName}(${clientParams.toCall({
169
- transformName(name) {
170
- if (name === 'config') {
171
- return '{ ...config, signal: config.signal ?? signal }'
172
- }
173
-
174
- return `toValue(${name})`
175
- },
176
- })})
177
- },
178
- })
179
- `}
180
- </Function>
181
- </File.Source>
182
- )
183
- }
184
-
185
- QueryOptions.getParams = getParams
@@ -1,7 +0,0 @@
1
- export { InfiniteQuery } from './InfiniteQuery.tsx'
2
- export { InfiniteQueryOptions } from './InfiniteQueryOptions.tsx'
3
- export { Mutation } from './Mutation.tsx'
4
- export { MutationKey } from './MutationKey.tsx'
5
- export { Query } from './Query.tsx'
6
- export { QueryKey } from './QueryKey.tsx'
7
- export { QueryOptions } from './QueryOptions.tsx'
@@ -1,3 +0,0 @@
1
- export { infiniteQueryGenerator } from './infiniteQueryGenerator.tsx'
2
- export { mutationGenerator } from './mutationGenerator.tsx'
3
- export { queryGenerator } from './queryGenerator.tsx'