@kubb/plugin-solid-query 3.0.0-beta.9 → 3.0.1

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 (45) hide show
  1. package/dist/{chunk-KFG7HL6L.js → chunk-36LQSNHS.js} +134 -23
  2. package/dist/chunk-36LQSNHS.js.map +1 -0
  3. package/dist/{chunk-PUTMS357.cjs → chunk-FNESJJ6B.cjs} +48 -35
  4. package/dist/chunk-FNESJJ6B.cjs.map +1 -0
  5. package/dist/{chunk-5BGA4ELO.js → chunk-K4XY3P3T.js} +44 -31
  6. package/dist/chunk-K4XY3P3T.js.map +1 -0
  7. package/dist/{chunk-PZTHP4L4.cjs → chunk-Y6RUU6PO.cjs} +134 -23
  8. package/dist/chunk-Y6RUU6PO.cjs.map +1 -0
  9. package/dist/components.cjs +4 -4
  10. package/dist/components.d.cts +12 -7
  11. package/dist/components.d.ts +12 -7
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +3 -3
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +22 -24
  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 +21 -23
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-DXL9Aw6E.d.cts +339 -0
  24. package/dist/types-DXL9Aw6E.d.ts +339 -0
  25. package/package.json +13 -12
  26. package/src/components/Query.tsx +62 -6
  27. package/src/components/QueryKey.tsx +17 -7
  28. package/src/components/QueryOptions.tsx +47 -7
  29. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
  30. package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
  31. package/src/generators/__snapshots__/findByTags.ts +1 -1
  32. package/src/generators/__snapshots__/findByTagsObject.ts +61 -0
  33. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
  34. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
  35. package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
  36. package/src/generators/__snapshots__/postAsQuery.ts +1 -1
  37. package/src/generators/queryGenerator.tsx +26 -17
  38. package/src/plugin.ts +28 -25
  39. package/src/types.ts +28 -10
  40. package/dist/chunk-5BGA4ELO.js.map +0 -1
  41. package/dist/chunk-KFG7HL6L.js.map +0 -1
  42. package/dist/chunk-PUTMS357.cjs.map +0 -1
  43. package/dist/chunk-PZTHP4L4.cjs.map +0 -1
  44. package/dist/types-CqwqMOQI.d.cts +0 -160
  45. 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-beta.9",
3
+ "version": "3.0.1",
4
4
  "description": "Generator solid-query hooks",
5
5
  "keywords": [
6
6
  "faker",
@@ -62,24 +62,25 @@
62
62
  "!/**/__tests__/**"
63
63
  ],
64
64
  "dependencies": {
65
- "@kubb/core": "3.0.0-beta.9",
66
- "@kubb/fs": "3.0.0-beta.9",
67
- "@kubb/oas": "3.0.0-beta.9",
68
- "@kubb/plugin-oas": "3.0.0-beta.9",
69
- "@kubb/plugin-ts": "3.0.0-beta.9",
70
- "@kubb/plugin-zod": "3.0.0-beta.9",
71
- "@kubb/react": "3.0.0-beta.9"
65
+ "remeda": "^2.16.0",
66
+ "@kubb/core": "3.0.1",
67
+ "@kubb/fs": "3.0.1",
68
+ "@kubb/oas": "3.0.1",
69
+ "@kubb/plugin-oas": "3.0.1",
70
+ "@kubb/plugin-ts": "3.0.1",
71
+ "@kubb/plugin-zod": "3.0.1",
72
+ "@kubb/react": "3.0.1"
72
73
  },
73
74
  "devDependencies": {
74
75
  "@types/react": "^18.3.12",
75
76
  "react": "^18.3.1",
76
- "tsup": "^8.3.4",
77
+ "tsup": "^8.3.5",
77
78
  "typescript": "^5.6.3",
78
- "@kubb/config-ts": "3.0.0-beta.9",
79
- "@kubb/config-tsup": "3.0.0-beta.9"
79
+ "@kubb/config-ts": "3.0.1",
80
+ "@kubb/config-tsup": "3.0.1"
80
81
  },
81
82
  "peerDependencies": {
82
- "@kubb/react": "3.0.0-beta.9"
83
+ "@kubb/react": "3.0.1"
83
84
  },
84
85
  "engines": {
85
86
  "node": ">=20"
@@ -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
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
37
- children: getPathParams(typeSchemas.pathParams, { typed: true }),
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({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
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
- keysFn: ((keys: unknown[]) => unknown[]) | undefined
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
- export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
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
- typeSchemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
54
- typeSchemas.request?.name ? '...(data ? [data] : [])' : undefined,
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
- {`[${keysFn(keys).join(', ')}] as const`}
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
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
29
- children: getPathParams(typeSchemas.pathParams, { typed: true }),
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 { createQuery, queryOptions } from "@tanstack/svelte-query";
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 { createQuery, queryOptions } from "@tanstack/svelte-query";
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 { createQuery, queryOptions } from "@tanstack/svelte-query";
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 { createQuery, queryOptions } from "@tanstack/svelte-query";
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 { createQuery, queryOptions } from "@tanstack/react-query";
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 { createQuery, queryOptions } from "@tanstack/svelte-query";
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 { createQuery, queryOptions } from "custom-query";
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'
@@ -6,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
5
  import { pluginTsName } from '@kubb/plugin-ts'
7
6
  import { pluginZodName } from '@kubb/plugin-zod'
8
7
  import { File, useApp } from '@kubb/react'
8
+ import { difference } from 'remeda'
9
9
  import { Query, QueryKey, QueryOptions } from '../components'
10
10
  import type { PluginSolidQuery } from '../types'
11
11
 
@@ -20,6 +20,8 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
20
20
  const { getSchemas, getName, getFile } = useOperationManager()
21
21
 
22
22
  const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
23
+ const isMutation = difference(['post', 'put', 'delete', 'patch'], options.query ? options.query.methods : []).some((method) => operation.method === method)
24
+ const importPath = options.query ? options.query.importPath : '@tanstack/solid-query'
23
25
 
24
26
  const query = {
25
27
  name: getName(operation, { type: 'function', prefix: 'create' }),
@@ -51,15 +53,13 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
51
53
  schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
54
  }
53
55
 
54
- if (!isQuery || typeof options.query === 'boolean') {
56
+ if (!isQuery || isMutation) {
55
57
  return null
56
58
  }
57
59
 
58
60
  return (
59
61
  <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
62
  {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
63
  <File.Import name={'client'} path={options.client.importPath} />
64
64
  <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
65
  {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
@@ -76,44 +76,53 @@ export const queryGenerator = createReactGenerator<PluginSolidQuery>({
76
76
  path={type.file.path}
77
77
  isTypeOnly
78
78
  />
79
-
80
79
  <QueryKey
81
80
  name={queryKey.name}
82
81
  typeName={queryKey.typeName}
83
82
  operation={operation}
84
83
  pathParamsType={options.pathParamsType}
85
84
  typeSchemas={type.schemas}
86
- keysFn={options.query.key}
85
+ transformer={options.queryKey}
87
86
  />
88
87
  <Client
89
88
  name={client.name}
90
89
  isExportable={false}
91
90
  isIndexable={false}
92
- baseURL={options.baseURL}
91
+ baseURL={options.client.baseURL}
93
92
  operation={operation}
94
93
  typeSchemas={type.schemas}
95
94
  zodSchemas={zod.schemas}
96
95
  dataReturnType={options.client.dataReturnType}
96
+ paramsType={options.paramsType}
97
97
  pathParamsType={options.pathParamsType}
98
98
  parser={options.parser}
99
99
  />
100
+ <File.Import name={['queryOptions']} path={importPath} />
100
101
  <QueryOptions
101
102
  name={queryOptions.name}
102
103
  clientName={client.name}
103
104
  queryKeyName={queryKey.name}
104
105
  typeSchemas={type.schemas}
106
+ paramsType={options.paramsType}
105
107
  pathParamsType={options.pathParamsType}
106
108
  />
107
- <Query
108
- name={query.name}
109
- queryOptionsName={queryOptions.name}
110
- typeSchemas={type.schemas}
111
- pathParamsType={options.pathParamsType}
112
- operation={operation}
113
- dataReturnType={options.client.dataReturnType}
114
- queryKeyName={queryKey.name}
115
- queryKeyTypeName={queryKey.typeName}
116
- />
109
+ {options.query && (
110
+ <>
111
+ <File.Import name={['createQuery']} path={importPath} />
112
+ <File.Import name={['QueryKey', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={importPath} isTypeOnly />
113
+ <Query
114
+ name={query.name}
115
+ queryOptionsName={queryOptions.name}
116
+ typeSchemas={type.schemas}
117
+ paramsType={options.paramsType}
118
+ pathParamsType={options.pathParamsType}
119
+ operation={operation}
120
+ dataReturnType={options.client.dataReturnType}
121
+ queryKeyName={queryKey.name}
122
+ queryKeyTypeName={queryKey.typeName}
123
+ />
124
+ </>
125
+ )}
117
126
  </File>
118
127
  )
119
128
  },
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,23 @@ 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
  },
43
- query: {
44
- key: (key: unknown[]) => key,
45
- methods: ['get'],
46
- importPath: '@tanstack/solid-query',
47
- ...query,
48
- },
49
- pathParamsType,
44
+ queryKey,
45
+ query:
46
+ query === false
47
+ ? false
48
+ : {
49
+ methods: ['get'],
50
+ importPath: '@tanstack/solid-query',
51
+ ...query,
52
+ },
53
+ paramsType,
54
+ pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
50
55
  parser,
51
56
  },
52
57
  pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
@@ -96,22 +101,20 @@ export const pluginSolidQuery = createPlugin<PluginSolidQuery>((options) => {
96
101
  const mode = FileManager.getMode(path.resolve(root, output.path))
97
102
  const baseURL = await swaggerPlugin.context.getBaseURL()
98
103
 
99
- const operationGenerator = new OperationGenerator(
100
- {
101
- ...this.plugin.options,
102
- baseURL,
103
- },
104
- {
105
- oas,
106
- pluginManager: this.pluginManager,
107
- plugin: this.plugin,
108
- contentType: swaggerPlugin.context.contentType,
109
- exclude,
110
- include,
111
- override,
112
- mode,
113
- },
114
- )
104
+ if (baseURL) {
105
+ this.plugin.options.client.baseURL = baseURL
106
+ }
107
+
108
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
109
+ oas,
110
+ pluginManager: this.pluginManager,
111
+ plugin: this.plugin,
112
+ contentType: swaggerPlugin.context.contentType,
113
+ exclude,
114
+ include,
115
+ override,
116
+ mode,
117
+ })
115
118
 
116
119
  const files = await operationGenerator.build(...generators)
117
120
  await this.addFile(...files)