@kubb/plugin-solid-query 3.0.0-beta.8 → 3.0.0
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/dist/{chunk-5BGA4ELO.js → chunk-34VWVEUR.js} +42 -31
- package/dist/chunk-34VWVEUR.js.map +1 -0
- package/dist/{chunk-KFG7HL6L.js → chunk-36LQSNHS.js} +134 -23
- package/dist/chunk-36LQSNHS.js.map +1 -0
- package/dist/{chunk-PUTMS357.cjs → chunk-642OIIJK.cjs} +46 -35
- package/dist/chunk-642OIIJK.cjs.map +1 -0
- package/dist/{chunk-PZTHP4L4.cjs → chunk-Y6RUU6PO.cjs} +134 -23
- package/dist/chunk-Y6RUU6PO.cjs.map +1 -0
- package/dist/components.cjs +4 -4
- package/dist/components.d.cts +12 -7
- package/dist/components.d.ts +12 -7
- package/dist/components.js +1 -1
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +21 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -22
- package/dist/index.js.map +1 -1
- package/dist/types-DXL9Aw6E.d.cts +339 -0
- package/dist/types-DXL9Aw6E.d.ts +339 -0
- package/package.json +13 -13
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryKey.tsx +17 -7
- package/src/components/QueryOptions.tsx +47 -7
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +61 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/queryGenerator.tsx +24 -17
- package/src/plugin.ts +20 -20
- package/src/types.ts +28 -10
- package/dist/chunk-5BGA4ELO.js.map +0 -1
- package/dist/chunk-KFG7HL6L.js.map +0 -1
- package/dist/chunk-PUTMS357.cjs.map +0 -1
- package/dist/chunk-PZTHP4L4.cjs.map +0 -1
- package/dist/types-CqwqMOQI.d.cts +0 -160
- package/dist/types-CqwqMOQI.d.ts +0 -160
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-solid-query",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Generator solid-query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
"!/**/__tests__/**"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@kubb/core": "3.0.0
|
|
66
|
-
"@kubb/fs": "3.0.0
|
|
67
|
-
"@kubb/oas": "3.0.0
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0
|
|
70
|
-
"@kubb/plugin-zod": "3.0.0
|
|
71
|
-
"@kubb/react": "3.0.0
|
|
65
|
+
"@kubb/core": "3.0.0",
|
|
66
|
+
"@kubb/fs": "3.0.0",
|
|
67
|
+
"@kubb/oas": "3.0.0",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0",
|
|
71
|
+
"@kubb/react": "3.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/react": "^18.3.
|
|
74
|
+
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
|
-
"tsup": "^8.3.
|
|
76
|
+
"tsup": "^8.3.5",
|
|
77
77
|
"typescript": "^5.6.3",
|
|
78
|
-
"@kubb/config-ts": "3.0.0
|
|
79
|
-
"@kubb/config-tsup": "3.0.0
|
|
78
|
+
"@kubb/config-ts": "3.0.0",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0
|
|
82
|
+
"@kubb/react": "3.0.0"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,24 +18,68 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType']
|
|
21
22
|
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
|
|
22
23
|
dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType']
|
|
26
28
|
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
|
|
27
29
|
dataReturnType: PluginSolidQuery['resolvedOptions']['client']['dataReturnType']
|
|
28
30
|
typeSchemas: OperationSchemas
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
32
34
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
33
35
|
|
|
36
|
+
if (paramsType === 'object') {
|
|
37
|
+
return FunctionParams.factory({
|
|
38
|
+
data: {
|
|
39
|
+
mode: 'object',
|
|
40
|
+
children: {
|
|
41
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
data: typeSchemas.request?.name
|
|
43
|
+
? {
|
|
44
|
+
type: typeSchemas.request?.name,
|
|
45
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
46
|
+
}
|
|
47
|
+
: undefined,
|
|
48
|
+
params: typeSchemas.queryParams?.name
|
|
49
|
+
? {
|
|
50
|
+
type: typeSchemas.queryParams?.name,
|
|
51
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
headers: typeSchemas.headerParams?.name
|
|
55
|
+
? {
|
|
56
|
+
type: typeSchemas.headerParams?.name,
|
|
57
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
type: `
|
|
64
|
+
{
|
|
65
|
+
query?: Partial<CreateBaseQueryOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
66
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
default: '{}',
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
34
74
|
return FunctionParams.factory({
|
|
35
|
-
pathParams:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
pathParams: typeSchemas.pathParams?.name
|
|
76
|
+
? {
|
|
77
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
79
|
+
type: typeSchemas.pathParams?.name,
|
|
80
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
39
83
|
data: typeSchemas.request?.name
|
|
40
84
|
? {
|
|
41
85
|
type: typeSchemas.request?.name,
|
|
@@ -66,7 +110,17 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
|
|
|
66
110
|
})
|
|
67
111
|
}
|
|
68
112
|
|
|
69
|
-
export function Query({
|
|
113
|
+
export function Query({
|
|
114
|
+
name,
|
|
115
|
+
queryKeyTypeName,
|
|
116
|
+
queryOptionsName,
|
|
117
|
+
queryKeyName,
|
|
118
|
+
paramsType,
|
|
119
|
+
pathParamsType,
|
|
120
|
+
dataReturnType,
|
|
121
|
+
typeSchemas,
|
|
122
|
+
operation,
|
|
123
|
+
}: Props): ReactNode {
|
|
70
124
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
71
125
|
const returnType = `CreateQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
72
126
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
@@ -76,10 +130,12 @@ export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
76
130
|
typeSchemas,
|
|
77
131
|
})
|
|
78
132
|
const queryOptionsParams = QueryOptions.getParams({
|
|
133
|
+
paramsType,
|
|
79
134
|
pathParamsType,
|
|
80
135
|
typeSchemas,
|
|
81
136
|
})
|
|
82
137
|
const params = getParams({
|
|
138
|
+
paramsType,
|
|
83
139
|
pathParamsType,
|
|
84
140
|
dataReturnType,
|
|
85
141
|
typeSchemas,
|
|
@@ -5,7 +5,7 @@ import { File, Function, FunctionParams, Type } from '@kubb/react'
|
|
|
5
5
|
import { type Operation, isOptional } from '@kubb/oas'
|
|
6
6
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
7
7
|
import type { ReactNode } from 'react'
|
|
8
|
-
import type { PluginSolidQuery } from '../types'
|
|
8
|
+
import type { PluginSolidQuery, Transformer } from '../types'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
name: string
|
|
@@ -13,7 +13,7 @@ type Props = {
|
|
|
13
13
|
typeSchemas: OperationSchemas
|
|
14
14
|
operation: Operation
|
|
15
15
|
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
|
|
16
|
-
|
|
16
|
+
transformer: Transformer | undefined
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type GetParamsProps = {
|
|
@@ -42,23 +42,32 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
42
42
|
})
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
46
46
|
const path = new URLPath(operation.path)
|
|
47
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
48
47
|
const keys = [
|
|
49
48
|
path.toObject({
|
|
50
49
|
type: 'path',
|
|
51
50
|
stringify: true,
|
|
52
51
|
}),
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
|
|
53
|
+
schemas.request?.name ? '...(data ? [data] : [])' : undefined,
|
|
55
54
|
].filter(Boolean)
|
|
56
55
|
|
|
56
|
+
return keys
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
60
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
61
|
+
const keys = transformer({
|
|
62
|
+
operation,
|
|
63
|
+
schemas: typeSchemas,
|
|
64
|
+
})
|
|
65
|
+
|
|
57
66
|
return (
|
|
58
67
|
<>
|
|
59
68
|
<File.Source name={name} isExportable isIndexable>
|
|
60
69
|
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
61
|
-
{`[${
|
|
70
|
+
{`[${keys.join(', ')}] as const`}
|
|
62
71
|
</Function.Arrow>
|
|
63
72
|
</File.Source>
|
|
64
73
|
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
@@ -71,3 +80,4 @@ export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeNam
|
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
QueryKey.getParams = getParams
|
|
83
|
+
QueryKey.getTransformer = getTransformer
|
|
@@ -14,20 +14,59 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
type GetParamsProps = {
|
|
22
|
+
paramsType: PluginSolidQuery['resolvedOptions']['paramsType']
|
|
21
23
|
pathParamsType: PluginSolidQuery['resolvedOptions']['pathParamsType']
|
|
22
24
|
typeSchemas: OperationSchemas
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
27
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
28
|
+
if (paramsType === 'object') {
|
|
29
|
+
return FunctionParams.factory({
|
|
30
|
+
data: {
|
|
31
|
+
mode: 'object',
|
|
32
|
+
children: {
|
|
33
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
34
|
+
data: typeSchemas.request?.name
|
|
35
|
+
? {
|
|
36
|
+
type: typeSchemas.request?.name,
|
|
37
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
params: typeSchemas.queryParams?.name
|
|
41
|
+
? {
|
|
42
|
+
type: typeSchemas.queryParams?.name,
|
|
43
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
46
|
+
headers: typeSchemas.headerParams?.name
|
|
47
|
+
? {
|
|
48
|
+
type: typeSchemas.headerParams?.name,
|
|
49
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
config: {
|
|
55
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
56
|
+
default: '{}',
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
26
61
|
return FunctionParams.factory({
|
|
27
|
-
pathParams:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
pathParams: typeSchemas.pathParams?.name
|
|
63
|
+
? {
|
|
64
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
65
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
66
|
+
type: typeSchemas.pathParams?.name,
|
|
67
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
31
70
|
data: typeSchemas.request?.name
|
|
32
71
|
? {
|
|
33
72
|
type: typeSchemas.request?.name,
|
|
@@ -53,10 +92,11 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
53
92
|
})
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
export function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
57
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
95
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
96
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
58
97
|
const clientParams = Client.getParams({
|
|
59
98
|
typeSchemas,
|
|
99
|
+
paramsType,
|
|
60
100
|
pathParamsType,
|
|
61
101
|
})
|
|
62
102
|
const queryKeyParams = QueryKey.getParams({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "axios";
|
|
2
2
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
+
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
|
+
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
|
+
|
|
8
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
12
|
+
* @summary Finds Pets by tags
|
|
13
|
+
* @link /pet/findByTags
|
|
14
|
+
*/
|
|
15
|
+
async function findPetsByTags({ headers, params }: {
|
|
16
|
+
headers: FindPetsByTagsHeaderParams;
|
|
17
|
+
params?: FindPetsByTagsQueryParams;
|
|
18
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
19
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
|
|
20
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function findPetsByTagsQueryOptions({ headers, params }: {
|
|
24
|
+
headers: FindPetsByTagsHeaderParams;
|
|
25
|
+
params?: FindPetsByTagsQueryParams;
|
|
26
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
27
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
28
|
+
return queryOptions({
|
|
29
|
+
queryKey,
|
|
30
|
+
queryFn: async ({ signal }) => {
|
|
31
|
+
config.signal = signal;
|
|
32
|
+
return findPetsByTags({ headers, params }, config);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
39
|
+
* @summary Finds Pets by tags
|
|
40
|
+
* @link /pet/findByTags
|
|
41
|
+
*/
|
|
42
|
+
export function createFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>({ headers, params }: {
|
|
43
|
+
headers: FindPetsByTagsHeaderParams;
|
|
44
|
+
params?: FindPetsByTagsQueryParams;
|
|
45
|
+
}, options: {
|
|
46
|
+
query?: Partial<CreateBaseQueryOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
47
|
+
client?: Partial<RequestConfig>;
|
|
48
|
+
} = {}) {
|
|
49
|
+
const { query: queryOptions, client: config = {} } = options ?? {};
|
|
50
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
|
|
51
|
+
const query = createQuery(() => ({
|
|
52
|
+
...findPetsByTagsQueryOptions({ headers, params }, config) as unknown as CreateBaseQueryOptions,
|
|
53
|
+
queryKey,
|
|
54
|
+
initialData: null,
|
|
55
|
+
...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
|
|
56
|
+
})) as CreateQueryResult<TData, FindPetsByTags400> & {
|
|
57
|
+
queryKey: TQueryKey;
|
|
58
|
+
};
|
|
59
|
+
query.queryKey = queryKey as TQueryKey;
|
|
60
|
+
return query;
|
|
61
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
|
-
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
8
8
|
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "custom-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "custom-query";
|
|
5
5
|
|
|
6
6
|
export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
7
7
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import transformers from '@kubb/core/transformers'
|
|
2
1
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
3
2
|
import { Client } from '@kubb/plugin-client/components'
|
|
4
3
|
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
@@ -20,6 +19,7 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
|
|
|
20
19
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
20
|
|
|
22
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
22
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'
|
|
23
23
|
|
|
24
24
|
const query = {
|
|
25
25
|
name: getName(operation, { type: 'function', prefix: 'create' }),
|
|
@@ -51,15 +51,13 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
|
|
|
51
51
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if (!isQuery
|
|
54
|
+
if (!isQuery) {
|
|
55
55
|
return null
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return (
|
|
59
59
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
60
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
|
-
<File.Import name={['createQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
61
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
62
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
63
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -76,44 +74,53 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
|
|
|
76
74
|
path={type.file.path}
|
|
77
75
|
isTypeOnly
|
|
78
76
|
/>
|
|
79
|
-
|
|
80
77
|
<QueryKey
|
|
81
78
|
name={queryKey.name}
|
|
82
79
|
typeName={queryKey.typeName}
|
|
83
80
|
operation={operation}
|
|
84
81
|
pathParamsType={options.pathParamsType}
|
|
85
82
|
typeSchemas={type.schemas}
|
|
86
|
-
|
|
83
|
+
transformer={options.queryKey}
|
|
87
84
|
/>
|
|
88
85
|
<Client
|
|
89
86
|
name={client.name}
|
|
90
87
|
isExportable={false}
|
|
91
88
|
isIndexable={false}
|
|
92
|
-
baseURL={options.baseURL}
|
|
89
|
+
baseURL={options.client.baseURL}
|
|
93
90
|
operation={operation}
|
|
94
91
|
typeSchemas={type.schemas}
|
|
95
92
|
zodSchemas={zod.schemas}
|
|
96
93
|
dataReturnType={options.client.dataReturnType}
|
|
94
|
+
paramsType={options.paramsType}
|
|
97
95
|
pathParamsType={options.pathParamsType}
|
|
98
96
|
parser={options.parser}
|
|
99
97
|
/>
|
|
98
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
100
99
|
<QueryOptions
|
|
101
100
|
name={queryOptions.name}
|
|
102
101
|
clientName={client.name}
|
|
103
102
|
queryKeyName={queryKey.name}
|
|
104
103
|
typeSchemas={type.schemas}
|
|
104
|
+
paramsType={options.paramsType}
|
|
105
105
|
pathParamsType={options.pathParamsType}
|
|
106
106
|
/>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
107
|
+
{options.query && (
|
|
108
|
+
<>
|
|
109
|
+
<File.Import name={['createQuery']} path={importPath} />
|
|
110
|
+
<File.Import name={['QueryKey', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={importPath} isTypeOnly />
|
|
111
|
+
<Query
|
|
112
|
+
name={query.name}
|
|
113
|
+
queryOptionsName={queryOptions.name}
|
|
114
|
+
typeSchemas={type.schemas}
|
|
115
|
+
paramsType={options.paramsType}
|
|
116
|
+
pathParamsType={options.pathParamsType}
|
|
117
|
+
operation={operation}
|
|
118
|
+
dataReturnType={options.client.dataReturnType}
|
|
119
|
+
queryKeyName={queryKey.name}
|
|
120
|
+
queryKeyTypeName={queryKey.typeName}
|
|
121
|
+
/>
|
|
122
|
+
</>
|
|
123
|
+
)}
|
|
117
124
|
</File>
|
|
118
125
|
)
|
|
119
126
|
},
|
package/src/plugin.ts
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
|
-
import { renderTemplate } from '@kubb/core/utils'
|
|
6
5
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -10,6 +9,7 @@ import { pluginZodName } from '@kubb/plugin-zod'
|
|
|
10
9
|
|
|
11
10
|
import type { Plugin } from '@kubb/core'
|
|
12
11
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
12
|
+
import { QueryKey } from './components'
|
|
13
13
|
import { queryGenerator } from './generators'
|
|
14
14
|
import type { PluginSolidQuery } from './types.ts'
|
|
15
15
|
|
|
@@ -24,7 +24,9 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
|
|
|
24
24
|
override = [],
|
|
25
25
|
parser = 'client',
|
|
26
26
|
transformers = {},
|
|
27
|
+
paramsType = 'inline',
|
|
27
28
|
pathParamsType = 'inline',
|
|
29
|
+
queryKey = QueryKey.getTransformer,
|
|
28
30
|
generators = [queryGenerator].filter(Boolean),
|
|
29
31
|
query = {},
|
|
30
32
|
} = options
|
|
@@ -33,20 +35,20 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
|
|
|
33
35
|
name: pluginSolidQueryName,
|
|
34
36
|
options: {
|
|
35
37
|
output,
|
|
36
|
-
baseURL: undefined,
|
|
37
38
|
client: {
|
|
38
39
|
importPath: '@kubb/plugin-client/client',
|
|
39
40
|
dataReturnType: 'data',
|
|
40
41
|
pathParamsType: 'inline',
|
|
41
42
|
...options.client,
|
|
42
43
|
},
|
|
44
|
+
queryKey,
|
|
43
45
|
query: {
|
|
44
|
-
key: (key: unknown[]) => key,
|
|
45
46
|
methods: ['get'],
|
|
46
47
|
importPath: '@tanstack/solid-query',
|
|
47
48
|
...query,
|
|
48
49
|
},
|
|
49
|
-
|
|
50
|
+
paramsType,
|
|
51
|
+
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
|
|
50
52
|
parser,
|
|
51
53
|
},
|
|
52
54
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
@@ -96,22 +98,20 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
|
|
|
96
98
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
97
99
|
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
},
|
|
114
|
-
)
|
|
101
|
+
if (baseURL) {
|
|
102
|
+
this.plugin.options.client.baseURL = baseURL
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
106
|
+
oas,
|
|
107
|
+
pluginManager: this.pluginManager,
|
|
108
|
+
plugin: this.plugin,
|
|
109
|
+
contentType: swaggerPlugin.context.contentType,
|
|
110
|
+
exclude,
|
|
111
|
+
include,
|
|
112
|
+
override,
|
|
113
|
+
mode,
|
|
114
|
+
})
|
|
115
115
|
|
|
116
116
|
const files = await operationGenerator.build(...generators)
|
|
117
117
|
await this.addFile(...files)
|