@kubb/plugin-solid-query 3.18.3 → 4.0.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.
Files changed (47) hide show
  1. package/dist/{components-CCkbce4B.cjs → components-CrpQqUQQ.cjs} +194 -14
  2. package/dist/components-CrpQqUQQ.cjs.map +1 -0
  3. package/dist/{components-DteoGXDw.js → components-JN6XAKh3.js} +172 -10
  4. package/dist/components-JN6XAKh3.js.map +1 -0
  5. package/dist/components.cjs +3 -1
  6. package/dist/components.d.cts +58 -2
  7. package/dist/components.d.ts +58 -2
  8. package/dist/components.js +2 -2
  9. package/dist/generators-CUcA3_rk.cjs +365 -0
  10. package/dist/generators-CUcA3_rk.cjs.map +1 -0
  11. package/dist/{generators-D4zsCZ8Y.js → generators-DRX-ix2A.js} +155 -5
  12. package/dist/generators-DRX-ix2A.js.map +1 -0
  13. package/dist/generators.cjs +3 -2
  14. package/dist/generators.d.cts +5 -2
  15. package/dist/generators.d.ts +5 -2
  16. package/dist/generators.js +3 -3
  17. package/dist/index.cjs +29 -14
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +17 -8
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-BcAT9UxT.d.cts → types-BI1GJc6y.d.cts} +27 -1
  24. package/dist/{types-B5mFPIGb.d.ts → types-fv5KLGsJ.d.ts} +27 -1
  25. package/package.json +11 -12
  26. package/src/components/Mutation.tsx +177 -0
  27. package/src/components/MutationKey.tsx +54 -0
  28. package/src/components/Query.tsx +1 -1
  29. package/src/components/index.ts +2 -0
  30. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +2 -2
  31. package/src/generators/__snapshots__/clientGetImportPath.ts +2 -2
  32. package/src/generators/__snapshots__/findByTags.ts +2 -2
  33. package/src/generators/__snapshots__/findByTagsObject.ts +2 -2
  34. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +2 -2
  35. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
  36. package/src/generators/__snapshots__/findByTagsWithZod.ts +2 -2
  37. package/src/generators/__snapshots__/postAsQuery.ts +2 -2
  38. package/src/generators/index.ts +1 -0
  39. package/src/generators/mutationGenerator.tsx +144 -0
  40. package/src/generators/queryGenerator.tsx +1 -1
  41. package/src/plugin.ts +14 -9
  42. package/src/types.ts +28 -0
  43. package/dist/components-CCkbce4B.cjs.map +0 -1
  44. package/dist/components-DteoGXDw.js.map +0 -1
  45. package/dist/generators-D4zsCZ8Y.js.map +0 -1
  46. package/dist/generators-yp4-76zC.cjs +0 -199
  47. package/dist/generators-yp4-76zC.cjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-solid-query",
3
- "version": "3.18.3",
3
+ "version": "4.0.2",
4
4
  "description": "Solid Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for Solid.js applications.",
5
5
  "keywords": [
6
6
  "solid-query",
@@ -61,24 +61,23 @@
61
61
  "!/**/__tests__/**"
62
62
  ],
63
63
  "dependencies": {
64
- "remeda": "^2.30.0",
65
- "@kubb/core": "3.18.3",
66
- "@kubb/oas": "3.18.3",
67
- "@kubb/plugin-client": "3.18.3",
68
- "@kubb/plugin-oas": "3.18.3",
69
- "@kubb/plugin-ts": "3.18.3",
70
- "@kubb/plugin-zod": "3.18.3",
71
- "@kubb/react": "3.18.3"
64
+ "remeda": "^2.32.0",
65
+ "@kubb/core": "4.0.2",
66
+ "@kubb/oas": "4.0.2",
67
+ "@kubb/plugin-client": "4.0.2",
68
+ "@kubb/plugin-oas": "4.0.2",
69
+ "@kubb/plugin-ts": "4.0.2",
70
+ "@kubb/plugin-zod": "4.0.2",
71
+ "@kubb/react": "4.0.2"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@types/react": "^18.3.24",
75
75
  "react": "^18.3.1",
76
76
  "tsdown": "^0.14.2",
77
- "typescript": "^5.9.2",
78
- "@kubb/config-ts": "3.18.3"
77
+ "typescript": "^5.9.2"
79
78
  },
80
79
  "peerDependencies": {
81
- "@kubb/react": "^3.0.0"
80
+ "@kubb/react": "^4.0.0"
82
81
  },
83
82
  "engines": {
84
83
  "node": ">=20"
@@ -0,0 +1,177 @@
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'
6
+ import type { Params } from '@kubb/react/types'
7
+ import type { ReactNode } from 'react'
8
+ import type { PluginSolidQuery } from '../types.ts'
9
+ import { MutationKey } from './MutationKey.tsx'
10
+
11
+ type Props = {
12
+ /**
13
+ * Name of the function
14
+ */
15
+ name: string
16
+ typeName: string
17
+ clientName: string
18
+ mutationKeyName: string
19
+ typeSchemas: OperationSchemas
20
+ operation: Operation
21
+ dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']
22
+ paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']
23
+ paramsType: PluginSolidQuery['resolvedOptions']['paramsType']
24
+ pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
25
+ }
26
+
27
+ type GetParamsProps = {
28
+ paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']
29
+ pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
30
+ dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']
31
+ typeSchemas: OperationSchemas
32
+ }
33
+
34
+ function getParams({ paramsCasing, dataReturnType, typeSchemas }: GetParamsProps) {
35
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
36
+ const mutationParams = FunctionParams.factory({
37
+ ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
38
+ data: typeSchemas.request?.name
39
+ ? {
40
+ type: typeSchemas.request?.name,
41
+ optional: isOptional(typeSchemas.request?.schema),
42
+ }
43
+ : undefined,
44
+ params: typeSchemas.queryParams?.name
45
+ ? {
46
+ type: typeSchemas.queryParams?.name,
47
+ optional: isOptional(typeSchemas.queryParams?.schema),
48
+ }
49
+ : undefined,
50
+ headers: typeSchemas.headerParams?.name
51
+ ? {
52
+ type: typeSchemas.headerParams?.name,
53
+ optional: isOptional(typeSchemas.headerParams?.schema),
54
+ }
55
+ : undefined,
56
+ })
57
+ const TRequest = mutationParams.toConstructor()
58
+ const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
59
+ const generics = [TData, TError, TRequest ? `{${TRequest}}` : 'void', 'TContext'].join(', ')
60
+
61
+ return FunctionParams.factory({
62
+ options: {
63
+ type: `
64
+ {
65
+ mutation?: ReturnType<UseMutationOptions<${generics}>> & { client?: QueryClient },
66
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : 'Partial<RequestConfig> & { client?: typeof fetch }'},
67
+ }
68
+ `,
69
+ default: '{}',
70
+ },
71
+ })
72
+ }
73
+
74
+ export function Mutation({
75
+ name,
76
+ clientName,
77
+ paramsCasing,
78
+ paramsType,
79
+ pathParamsType,
80
+ dataReturnType,
81
+ typeSchemas,
82
+ operation,
83
+ mutationKeyName,
84
+ }: Props): ReactNode {
85
+ const mutationKeyParams = MutationKey.getParams({
86
+ pathParamsType,
87
+ typeSchemas,
88
+ })
89
+
90
+ const params = getParams({
91
+ paramsCasing,
92
+ pathParamsType,
93
+ dataReturnType,
94
+ typeSchemas,
95
+ })
96
+
97
+ const clientParams = Client.getParams({
98
+ paramsCasing,
99
+ paramsType,
100
+ typeSchemas,
101
+ pathParamsType,
102
+ isConfigurable: true,
103
+ })
104
+
105
+ const mutationParams = FunctionParams.factory({
106
+ ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
107
+ data: typeSchemas.request?.name
108
+ ? {
109
+ type: typeSchemas.request?.name,
110
+ optional: isOptional(typeSchemas.request?.schema),
111
+ }
112
+ : undefined,
113
+ params: typeSchemas.queryParams?.name
114
+ ? {
115
+ type: typeSchemas.queryParams?.name,
116
+ optional: isOptional(typeSchemas.queryParams?.schema),
117
+ }
118
+ : undefined,
119
+ headers: typeSchemas.headerParams?.name
120
+ ? {
121
+ type: typeSchemas.headerParams?.name,
122
+ optional: isOptional(typeSchemas.headerParams?.schema),
123
+ }
124
+ : undefined,
125
+ })
126
+
127
+ const dataParams = FunctionParams.factory({
128
+ data: {
129
+ // No use of pathParams because useMutation can only take one argument in object form,
130
+ // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
131
+ mode: 'object',
132
+ children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
133
+ if (value) {
134
+ acc[key] = {
135
+ ...value,
136
+ type: undefined,
137
+ }
138
+ }
139
+
140
+ return acc
141
+ }, {} as Params),
142
+ },
143
+ })
144
+
145
+ const TRequest = mutationParams.toConstructor()
146
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
147
+ const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`
148
+ const generics = [TData, TError, TRequest ? `{${TRequest}}` : 'void', 'TContext'].join(', ')
149
+
150
+ return (
151
+ <File.Source name={name} isExportable isIndexable>
152
+ <Function
153
+ name={name}
154
+ export
155
+ params={params.toConstructor()}
156
+ JSDoc={{
157
+ comments: getComments(operation),
158
+ }}
159
+ generics={['TContext']}
160
+ >
161
+ {`
162
+ const { mutation = {}, client: config = {} } = options ?? {}
163
+ const { client: queryClient, ...mutationOptions } = mutation;
164
+ const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
165
+
166
+ return useMutation<${generics}>(()=> ({
167
+ mutationFn: async(${dataParams.toConstructor()}) => {
168
+ return ${clientName}(${clientParams.toCall()})
169
+ },
170
+ mutationKey,
171
+ ...mutationOptions
172
+ }), queryClient? () => queryClient: undefined)
173
+ `}
174
+ </Function>
175
+ </File.Source>
176
+ )
177
+ }
@@ -0,0 +1,54 @@
1
+ import { URLPath } from '@kubb/core/utils'
2
+ import type { Operation } from '@kubb/oas'
3
+ import type { OperationSchemas } from '@kubb/plugin-oas'
4
+ import { File, Function, FunctionParams, Type } from '@kubb/react'
5
+ import type { ReactNode } from 'react'
6
+ import type { PluginSolidQuery, Transformer } from '../types'
7
+
8
+ type Props = {
9
+ name: string
10
+ typeName: string
11
+ typeSchemas: OperationSchemas
12
+ operation: Operation
13
+ paramsCasing: PluginSolidQuery['resolvedOptions']['paramsCasing']
14
+ pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
15
+ transformer: Transformer | undefined
16
+ }
17
+
18
+ type GetParamsProps = {
19
+ pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
20
+ typeSchemas: OperationSchemas
21
+ }
22
+
23
+ function getParams({}: GetParamsProps) {
24
+ return FunctionParams.factory({})
25
+ }
26
+
27
+ const getTransformer: Transformer = ({ operation, casing }) => {
28
+ const path = new URLPath(operation.path, { casing })
29
+
30
+ return [`{ url: '${path.toURLPath()}' }`]
31
+ }
32
+
33
+ export function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }: Props): ReactNode {
34
+ const params = getParams({ pathParamsType, typeSchemas })
35
+ const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing })
36
+
37
+ return (
38
+ <>
39
+ <File.Source name={name} isExportable isIndexable>
40
+ <Function.Arrow name={name} export params={params.toConstructor()} singleLine>
41
+ {`[${keys.join(', ')}] as const`}
42
+ </Function.Arrow>
43
+ </File.Source>
44
+ <File.Source name={typeName} isExportable isIndexable isTypeOnly>
45
+ <Type name={typeName} export>
46
+ {`ReturnType<typeof ${name}>`}
47
+ </Type>
48
+ </File.Source>
49
+ </>
50
+ )
51
+ }
52
+
53
+ MutationKey.getParams = getParams
54
+ MutationKey.getTransformer = getTransformer
@@ -165,7 +165,7 @@ export function Query({
165
165
  const { client: queryClient, ...queryOptions } = queryConfig
166
166
  const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
167
167
 
168
- const query = createQuery(() => ({
168
+ const query = useQuery(() => ({
169
169
  ...${queryOptions},
170
170
  queryKey,
171
171
  initialData: null,
@@ -1,3 +1,5 @@
1
+ export { Mutation } from './Mutation.tsx'
2
+ export { MutationKey } from './MutationKey.tsx'
1
3
  export { Query } from './Query.tsx'
2
4
  export { QueryKey } from './QueryKey.tsx'
3
5
  export { QueryOptions } from './QueryOptions.tsx'
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig, ResponseConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -76,7 +76,7 @@ export function createFindPetsByTags<
76
76
  const { client: queryClient, ...queryOptions } = queryConfig
77
77
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
78
78
 
79
- const query = createQuery(
79
+ const query = useQuery(
80
80
  () => ({
81
81
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
82
82
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from 'axios'
6
6
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
7
7
  import type { RequestConfig, ResponseErrorConfig } from 'axios'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -71,7 +71,7 @@ export function createFindPetsByTags<
71
71
  const { client: queryClient, ...queryOptions } = queryConfig
72
72
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
73
73
 
74
- const query = createQuery(
74
+ const query = useQuery(
75
75
  () => ({
76
76
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
77
77
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -71,7 +71,7 @@ export function createFindPetsByTags<
71
71
  const { client: queryClient, ...queryOptions } = queryConfig
72
72
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
73
73
 
74
- const query = createQuery(
74
+ const query = useQuery(
75
75
  () => ({
76
76
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
77
77
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -68,7 +68,7 @@ export function createFindPetsByTags<
68
68
  const { client: queryClient, ...queryOptions } = queryConfig
69
69
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
70
70
 
71
- const query = createQuery(
71
+ const query = useQuery(
72
72
  () => ({
73
73
  ...(findPetsByTagsQueryOptions({ headers, params }, config) as unknown as UseBaseQueryOptions),
74
74
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -71,7 +71,7 @@ export function createFindPetsByTags<
71
71
  const { client: queryClient, ...queryOptions } = queryConfig
72
72
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
73
73
 
74
- const query = createQuery(
74
+ const query = useQuery(
75
75
  () => ({
76
76
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
77
77
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/react-query'
8
- import { queryOptions, createQuery } from '@tanstack/react-query'
8
+ import { queryOptions, useQuery } from '@tanstack/react-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => ['test', { url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -71,7 +71,7 @@ export function createFindPetsByTags<
71
71
  const { client: queryClient, ...queryOptions } = queryConfig
72
72
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
73
73
 
74
- const query = createQuery(
74
+ const query = useQuery(
75
75
  () => ({
76
76
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
77
77
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/svelte-query'
8
- import { queryOptions, createQuery } from '@tanstack/svelte-query'
8
+ import { queryOptions, useQuery } from '@tanstack/svelte-query'
9
9
 
10
10
  export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
11
11
 
@@ -71,7 +71,7 @@ export function createFindPetsByTags<
71
71
  const { client: queryClient, ...queryOptions } = queryConfig
72
72
  const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
73
73
 
74
- const query = createQuery(
74
+ const query = useQuery(
75
75
  () => ({
76
76
  ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions),
77
77
  queryKey,
@@ -5,7 +5,7 @@
5
5
  import fetch from '@kubb/plugin-client/clients/axios'
6
6
  import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
7
7
  import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from 'custom-query'
8
- import { queryOptions, createQuery } from 'custom-query'
8
+ import { queryOptions, useQuery } from 'custom-query'
9
9
 
10
10
  export const updatePetWithFormQueryKey = (
11
11
  petId: UpdatePetWithFormPathParams['petId'],
@@ -79,7 +79,7 @@ export function createUpdatePetWithForm<
79
79
  const { client: queryClient, ...queryOptions } = queryConfig
80
80
  const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params)
81
81
 
82
- const query = createQuery(
82
+ const query = useQuery(
83
83
  () => ({
84
84
  ...(updatePetWithFormQueryOptions(petId, data, params, config) as unknown as UseBaseQueryOptions),
85
85
  queryKey,
@@ -1 +1,2 @@
1
+ export { mutationGenerator } from './mutationGenerator.tsx'
1
2
  export { queryGenerator } from './queryGenerator.tsx'
@@ -0,0 +1,144 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { Client } from '@kubb/plugin-client/components'
3
+ import { createReactGenerator } from '@kubb/plugin-oas'
4
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { difference } from 'remeda'
10
+ import { Mutation, MutationKey } from '../components'
11
+ import type { PluginSolidQuery } from '../types'
12
+
13
+ export const mutationGenerator = createReactGenerator<PluginSolidQuery>({
14
+ name: 'solid-query',
15
+ Operation({ options, operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output },
19
+ },
20
+ pluginManager,
21
+ } = useApp<PluginSolidQuery>()
22
+ const oas = useOas()
23
+ const { getSchemas, getName, getFile } = useOperationManager()
24
+
25
+ const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)
26
+ const isMutation =
27
+ !isQuery &&
28
+ difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)
29
+
30
+ const importPath = options.mutation ? options.mutation.importPath : '@tanstack/solid-query'
31
+
32
+ const mutation = {
33
+ name: getName(operation, { type: 'function', prefix: 'use' }),
34
+ typeName: getName(operation, { type: 'type' }),
35
+ file: getFile(operation, { prefix: 'use' }),
36
+ }
37
+
38
+ const type = {
39
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
40
+ //todo remove type?
41
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
42
+ }
43
+
44
+ const zod = {
45
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
46
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
47
+ }
48
+
49
+ const hasClientPlugin = !!pluginManager.getPluginByKey([pluginClientName])
50
+ const client = {
51
+ name: hasClientPlugin
52
+ ? getName(operation, {
53
+ type: 'function',
54
+ pluginKey: [pluginClientName],
55
+ })
56
+ : getName(operation, {
57
+ type: 'function',
58
+ }),
59
+ file: getFile(operation, { pluginKey: [pluginClientName] }),
60
+ }
61
+
62
+ const mutationKey = {
63
+ name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
64
+ typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
65
+ }
66
+
67
+ if (!isMutation) {
68
+ return null
69
+ }
70
+
71
+ return (
72
+ <File
73
+ baseName={mutation.file.baseName}
74
+ path={mutation.file.path}
75
+ meta={mutation.file.meta}
76
+ banner={getBanner({ oas, output, config: pluginManager.config })}
77
+ footer={getFooter({ oas, output })}
78
+ >
79
+ {options.parser === 'zod' && (
80
+ <File.Import name={[zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean)} root={mutation.file.path} path={zod.file.path} />
81
+ )}
82
+ <File.Import name={'fetch'} path={options.client.importPath} />
83
+ {!!hasClientPlugin && <File.Import name={[client.name]} root={mutation.file.path} path={client.file.path} />}
84
+ <File.Import name={['RequestConfig', 'ResponseConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />
85
+ <File.Import
86
+ name={[
87
+ type.schemas.request?.name,
88
+ type.schemas.response.name,
89
+ type.schemas.pathParams?.name,
90
+ type.schemas.queryParams?.name,
91
+ type.schemas.headerParams?.name,
92
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
93
+ ].filter(Boolean)}
94
+ root={mutation.file.path}
95
+ path={type.file.path}
96
+ isTypeOnly
97
+ />
98
+
99
+ <MutationKey
100
+ name={mutationKey.name}
101
+ typeName={mutationKey.typeName}
102
+ operation={operation}
103
+ pathParamsType={options.pathParamsType}
104
+ typeSchemas={type.schemas}
105
+ paramsCasing={options.paramsCasing}
106
+ transformer={options.mutationKey}
107
+ />
108
+
109
+ {!hasClientPlugin && (
110
+ <Client
111
+ name={client.name}
112
+ baseURL={options.client.baseURL}
113
+ operation={operation}
114
+ typeSchemas={type.schemas}
115
+ zodSchemas={zod.schemas}
116
+ dataReturnType={options.client.dataReturnType}
117
+ paramsCasing={options.paramsCasing}
118
+ paramsType={options.paramsType}
119
+ pathParamsType={options.pathParamsType}
120
+ parser={options.parser}
121
+ />
122
+ )}
123
+ {options.mutation && (
124
+ <>
125
+ <File.Import name={['useMutation']} path={importPath} />
126
+ <File.Import name={['UseMutationOptions', 'QueryClient']} path={importPath} isTypeOnly />
127
+ <Mutation
128
+ name={mutation.name}
129
+ clientName={client.name}
130
+ typeName={mutation.typeName}
131
+ typeSchemas={type.schemas}
132
+ operation={operation}
133
+ dataReturnType={options.client.dataReturnType}
134
+ paramsCasing={options.paramsCasing}
135
+ paramsType={options.paramsType}
136
+ pathParamsType={options.pathParamsType}
137
+ mutationKeyName={mutationKey.name}
138
+ />
139
+ </>
140
+ )}
141
+ </File>
142
+ )
143
+ },
144
+ })
@@ -133,7 +133,7 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
133
133
  />
134
134
  {options.query && (
135
135
  <>
136
- <File.Import name={['createQuery']} path={importPath} />
136
+ <File.Import name={['useQuery']} path={importPath} />
137
137
  <File.Import name={['QueryKey', 'QueryClient', 'UseBaseQueryOptions', 'UseQueryResult']} path={importPath} isTypeOnly />
138
138
  <Query
139
139
  name={query.name}
package/src/plugin.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  import path from 'node:path'
2
-
3
- import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
2
+ import type { Plugin } from '@kubb/core'
3
+ import { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'
4
4
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
+ import type { PluginOas } from '@kubb/plugin-oas'
5
6
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
6
-
7
7
  import { pluginTsName } from '@kubb/plugin-ts'
8
8
  import { pluginZodName } from '@kubb/plugin-zod'
9
-
10
- import type { Plugin } from '@kubb/core'
11
- import type { PluginOas } from '@kubb/plugin-oas'
12
- import { QueryKey } from './components'
13
- import { queryGenerator } from './generators'
9
+ import { MutationKey, QueryKey } from './components'
10
+ import { mutationGenerator, queryGenerator } from './generators'
14
11
  import type { PluginSolidQuery } from './types.ts'
15
12
 
16
13
  export const pluginSolidQueryName = 'plugin-solid-query' satisfies PluginSolidQuery['name']
@@ -27,8 +24,10 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
27
24
  paramsType = 'inline',
28
25
  pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
29
26
  queryKey = QueryKey.getTransformer,
30
- generators = [queryGenerator].filter(Boolean),
27
+ generators = [queryGenerator, mutationGenerator].filter(Boolean),
28
+ mutation = {},
31
29
  query = {},
30
+ mutationKey = MutationKey.getTransformer,
32
31
  paramsCasing,
33
32
  contentType,
34
33
  } = options
@@ -52,6 +51,12 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
52
51
  importPath: '@tanstack/solid-query',
53
52
  ...query,
54
53
  },
54
+ mutationKey,
55
+ mutation: {
56
+ methods: ['post', 'put', 'patch', 'delete'],
57
+ importPath: '@tanstack/solid-query',
58
+ ...mutation,
59
+ },
55
60
  paramsType,
56
61
  pathParamsType,
57
62
  parser,