@kubb/plugin-react-query 3.0.0-beta.10 → 3.0.0-beta.12
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-BML6BZ4F.cjs → chunk-EOG7AHFO.cjs} +22 -10
- package/dist/chunk-EOG7AHFO.cjs.map +1 -0
- package/dist/{chunk-JFIGHRBM.js → chunk-EY5KE7R7.js} +22 -10
- package/dist/chunk-EY5KE7R7.js.map +1 -0
- package/dist/{chunk-24SL7I66.cjs → chunk-NBC6BPMV.cjs} +129 -112
- package/dist/chunk-NBC6BPMV.cjs.map +1 -0
- package/dist/{chunk-LBVGJA4Q.js → chunk-NZKAIPYC.js} +118 -101
- package/dist/chunk-NZKAIPYC.js.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +7 -5
- package/dist/components.d.ts +7 -5
- package/dist/components.js +1 -1
- package/dist/generators.cjs +6 -6
- 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-Dlwxp28D.d.cts → types-IuxCCG1K.d.cts} +28 -14
- package/dist/{types-Dlwxp28D.d.ts → types-IuxCCG1K.d.ts} +28 -14
- package/package.json +11 -11
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/QueryKey.tsx +17 -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 +1 -1
- 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__/findInfiniteByTags.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +1 -1
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/infiniteQueryGenerator.tsx +39 -29
- package/src/generators/mutationGenerator.tsx +24 -16
- package/src/generators/queryGenerator.tsx +22 -18
- package/src/generators/suspenseQueryGenerator.tsx +24 -17
- package/src/plugin.ts +20 -19
- package/src/types.ts +25 -13
- package/dist/chunk-24SL7I66.cjs.map +0 -1
- package/dist/chunk-BML6BZ4F.cjs.map +0 -1
- package/dist/chunk-JFIGHRBM.js.map +0 -1
- package/dist/chunk-LBVGJA4Q.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.12",
|
|
4
4
|
"description": "Generator react-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-beta.
|
|
66
|
-
"@kubb/fs": "3.0.0-beta.
|
|
67
|
-
"@kubb/oas": "3.0.0-beta.
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0-beta.
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0-beta.
|
|
70
|
-
"@kubb/plugin-zod": "3.0.0-beta.
|
|
71
|
-
"@kubb/react": "3.0.0-beta.
|
|
65
|
+
"@kubb/core": "3.0.0-beta.12",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.12",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.12",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.12",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.12",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.12",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.12"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
76
|
"tsup": "^8.3.5",
|
|
77
77
|
"typescript": "^5.6.3",
|
|
78
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
79
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
78
|
+
"@kubb/config-ts": "3.0.0-beta.12",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.12"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.12"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -4,7 +4,7 @@ import { File, Function, FunctionParams, Type } from '@kubb/react'
|
|
|
4
4
|
import type { Operation } from '@kubb/oas'
|
|
5
5
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
6
6
|
import type { ReactNode } from 'react'
|
|
7
|
-
import type { PluginReactQuery } from '../types'
|
|
7
|
+
import type { PluginReactQuery, Transformer } from '../types'
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
10
|
name: string
|
|
@@ -12,7 +12,7 @@ type Props = {
|
|
|
12
12
|
typeSchemas: OperationSchemas
|
|
13
13
|
operation: Operation
|
|
14
14
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
15
|
-
|
|
15
|
+
transformer: Transformer | undefined
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
type GetParamsProps = {
|
|
@@ -24,16 +24,21 @@ function getParams({}: GetParamsProps) {
|
|
|
24
24
|
return FunctionParams.factory({})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const getTransformer: Transformer = ({ operation }) => {
|
|
28
28
|
const path = new URLPath(operation.path)
|
|
29
|
+
|
|
30
|
+
return [JSON.stringify({ url: path.path })].filter(Boolean)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
29
34
|
const params = getParams({ pathParamsType, typeSchemas })
|
|
30
|
-
const keys =
|
|
35
|
+
const keys = transformer({ operation, schemas: typeSchemas })
|
|
31
36
|
|
|
32
37
|
return (
|
|
33
38
|
<>
|
|
34
39
|
<File.Source name={name} isExportable isIndexable>
|
|
35
40
|
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
36
|
-
{`[${
|
|
41
|
+
{`[${keys.join(', ')}] as const`}
|
|
37
42
|
</Function.Arrow>
|
|
38
43
|
</File.Source>
|
|
39
44
|
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
@@ -46,3 +51,4 @@ export function MutationKey({ name, typeSchemas, pathParamsType, operation, type
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
MutationKey.getParams = getParams
|
|
54
|
+
MutationKey.getTransformer = getTransformer
|
|
@@ -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 { PluginReactQuery } from '../types'
|
|
8
|
+
import type { PluginReactQuery, 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: PluginReactQuery['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
|
|
@@ -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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } 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, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-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, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (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, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (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, QueryObserverOptions, UseQueryResult } from "custom-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } 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
|
|
|
@@ -20,6 +20,8 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
20
20
|
const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
|
|
21
21
|
const isInfinite = isQuery && !!options.infinite
|
|
22
22
|
|
|
23
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
24
|
+
|
|
23
25
|
const query = {
|
|
24
26
|
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
|
|
25
27
|
typeName: getName(operation, { type: 'type' }),
|
|
@@ -50,15 +52,13 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
50
52
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
if (!isQuery || !isInfinite
|
|
55
|
+
if (!isQuery || !isInfinite) {
|
|
54
56
|
return null
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
return (
|
|
58
60
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
59
61
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
60
|
-
<File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
|
|
61
|
-
<File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
62
62
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
63
63
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
64
64
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -75,20 +75,19 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
75
75
|
path={type.file.path}
|
|
76
76
|
isTypeOnly
|
|
77
77
|
/>
|
|
78
|
-
|
|
79
78
|
<QueryKey
|
|
80
79
|
name={queryKey.name}
|
|
81
80
|
typeName={queryKey.typeName}
|
|
82
81
|
operation={operation}
|
|
83
82
|
pathParamsType={options.pathParamsType}
|
|
84
83
|
typeSchemas={type.schemas}
|
|
85
|
-
|
|
84
|
+
transformer={options.queryKey}
|
|
86
85
|
/>
|
|
87
86
|
<Client
|
|
88
87
|
name={client.name}
|
|
89
88
|
isExportable={false}
|
|
90
89
|
isIndexable={false}
|
|
91
|
-
baseURL={options.baseURL}
|
|
90
|
+
baseURL={options.client.baseURL}
|
|
92
91
|
operation={operation}
|
|
93
92
|
typeSchemas={type.schemas}
|
|
94
93
|
zodSchemas={zod.schemas}
|
|
@@ -97,29 +96,40 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
97
96
|
pathParamsType={options.pathParamsType}
|
|
98
97
|
parser={options.parser}
|
|
99
98
|
/>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
99
|
+
{options.infinite && (
|
|
100
|
+
<>
|
|
101
|
+
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
102
|
+
<InfiniteQueryOptions
|
|
103
|
+
name={queryOptions.name}
|
|
104
|
+
clientName={client.name}
|
|
105
|
+
queryKeyName={queryKey.name}
|
|
106
|
+
typeSchemas={type.schemas}
|
|
107
|
+
paramsType={options.paramsType}
|
|
108
|
+
pathParamsType={options.pathParamsType}
|
|
109
|
+
dataReturnType={options.client.dataReturnType}
|
|
110
|
+
cursorParam={options.infinite.cursorParam}
|
|
111
|
+
initialPageParam={options.infinite.initialPageParam}
|
|
112
|
+
queryParam={options.infinite.queryParam}
|
|
113
|
+
/>
|
|
114
|
+
</>
|
|
115
|
+
)}
|
|
116
|
+
{options.infinite && (
|
|
117
|
+
<>
|
|
118
|
+
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
119
|
+
<File.Import name={['QueryKey', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={importPath} isTypeOnly />
|
|
120
|
+
<InfiniteQuery
|
|
121
|
+
name={query.name}
|
|
122
|
+
queryOptionsName={queryOptions.name}
|
|
123
|
+
typeSchemas={type.schemas}
|
|
124
|
+
paramsType={options.paramsType}
|
|
125
|
+
pathParamsType={options.pathParamsType}
|
|
126
|
+
operation={operation}
|
|
127
|
+
dataReturnType={options.client.dataReturnType}
|
|
128
|
+
queryKeyName={queryKey.name}
|
|
129
|
+
queryKeyTypeName={queryKey.typeName}
|
|
130
|
+
/>
|
|
131
|
+
</>
|
|
132
|
+
)}
|
|
123
133
|
</File>
|
|
124
134
|
)
|
|
125
135
|
},
|
|
@@ -21,6 +21,8 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
21
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
22
22
|
const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
|
|
23
23
|
|
|
24
|
+
const importPath = options.mutation ? options.mutation.importPath : '@tanstack/react-query'
|
|
25
|
+
|
|
24
26
|
const mutation = {
|
|
25
27
|
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
26
28
|
typeName: getName(operation, { type: 'type' }),
|
|
@@ -47,15 +49,13 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
47
49
|
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
if (!isMutation
|
|
52
|
+
if (!isMutation) {
|
|
51
53
|
return null
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
return (
|
|
55
57
|
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
56
58
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
57
|
-
<File.Import name={['useMutation']} path={options.mutation.importPath} />
|
|
58
|
-
<File.Import name={['UseMutationOptions']} path={options.mutation.importPath} isTypeOnly />
|
|
59
59
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
60
60
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
61
61
|
<File.Import
|
|
@@ -71,19 +71,21 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
71
71
|
path={type.file.path}
|
|
72
72
|
isTypeOnly
|
|
73
73
|
/>
|
|
74
|
+
|
|
74
75
|
<MutationKey
|
|
75
76
|
name={mutationKey.name}
|
|
76
77
|
typeName={mutationKey.typeName}
|
|
77
78
|
operation={operation}
|
|
78
79
|
pathParamsType={options.pathParamsType}
|
|
79
80
|
typeSchemas={type.schemas}
|
|
80
|
-
|
|
81
|
+
transformer={options.mutationKey}
|
|
81
82
|
/>
|
|
83
|
+
|
|
82
84
|
<Client
|
|
83
85
|
name={client.name}
|
|
84
86
|
isExportable={false}
|
|
85
87
|
isIndexable={false}
|
|
86
|
-
baseURL={options.baseURL}
|
|
88
|
+
baseURL={options.client.baseURL}
|
|
87
89
|
operation={operation}
|
|
88
90
|
typeSchemas={type.schemas}
|
|
89
91
|
zodSchemas={zod.schemas}
|
|
@@ -92,17 +94,23 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
92
94
|
pathParamsType={options.pathParamsType}
|
|
93
95
|
parser={options.parser}
|
|
94
96
|
/>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
{options.mutation && (
|
|
98
|
+
<>
|
|
99
|
+
<File.Import name={['useMutation']} path={importPath} />
|
|
100
|
+
<File.Import name={['UseMutationOptions']} path={importPath} isTypeOnly />
|
|
101
|
+
<Mutation
|
|
102
|
+
name={mutation.name}
|
|
103
|
+
clientName={client.name}
|
|
104
|
+
typeName={mutation.typeName}
|
|
105
|
+
typeSchemas={type.schemas}
|
|
106
|
+
operation={operation}
|
|
107
|
+
dataReturnType={options.client.dataReturnType}
|
|
108
|
+
paramsType={options.paramsType}
|
|
109
|
+
pathParamsType={options.pathParamsType}
|
|
110
|
+
mutationKeyName={mutationKey.name}
|
|
111
|
+
/>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
106
114
|
</File>
|
|
107
115
|
)
|
|
108
116
|
},
|
|
@@ -19,7 +19,7 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
19
19
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
20
20
|
|
|
21
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
22
|
-
const
|
|
22
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
23
23
|
|
|
24
24
|
const query = {
|
|
25
25
|
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
@@ -51,15 +51,13 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
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={['useQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} 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,20 +74,19 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
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}
|
|
@@ -98,6 +95,7 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
98
95
|
pathParamsType={options.pathParamsType}
|
|
99
96
|
parser={options.parser}
|
|
100
97
|
/>
|
|
98
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
101
99
|
<QueryOptions
|
|
102
100
|
name={queryOptions.name}
|
|
103
101
|
clientName={client.name}
|
|
@@ -106,17 +104,23 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
106
104
|
paramsType={options.paramsType}
|
|
107
105
|
pathParamsType={options.pathParamsType}
|
|
108
106
|
/>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
107
|
+
{options.query && (
|
|
108
|
+
<>
|
|
109
|
+
<File.Import name={['useQuery']} path={importPath} />
|
|
110
|
+
<File.Import name={['QueryKey', 'QueryObserverOptions', 'UseQueryResult']} 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
|
+
)}
|
|
120
124
|
</File>
|
|
121
125
|
)
|
|
122
126
|
},
|
|
@@ -21,6 +21,8 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
21
21
|
const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
|
|
22
22
|
const isSuspense = isQuery && !!options.suspense
|
|
23
23
|
|
|
24
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
25
|
+
|
|
24
26
|
const query = {
|
|
25
27
|
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'suspense' }),
|
|
26
28
|
typeName: getName(operation, { type: 'type' }),
|
|
@@ -51,15 +53,13 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
51
53
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
if (!isQuery || !isSuspense
|
|
56
|
+
if (!isQuery || !isSuspense) {
|
|
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={['useSuspenseQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} 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,20 +76,20 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
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
|
-
|
|
85
|
+
transformer={options.queryKey}
|
|
87
86
|
/>
|
|
87
|
+
|
|
88
88
|
<Client
|
|
89
89
|
name={client.name}
|
|
90
90
|
isExportable={false}
|
|
91
91
|
isIndexable={false}
|
|
92
|
-
baseURL={options.baseURL}
|
|
92
|
+
baseURL={options.client.baseURL}
|
|
93
93
|
operation={operation}
|
|
94
94
|
typeSchemas={type.schemas}
|
|
95
95
|
zodSchemas={zod.schemas}
|
|
@@ -98,6 +98,7 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
98
98
|
pathParamsType={options.pathParamsType}
|
|
99
99
|
parser={options.parser}
|
|
100
100
|
/>
|
|
101
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
101
102
|
<QueryOptions
|
|
102
103
|
name={queryOptions.name}
|
|
103
104
|
clientName={client.name}
|
|
@@ -106,17 +107,23 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
106
107
|
paramsType={options.paramsType}
|
|
107
108
|
pathParamsType={options.pathParamsType}
|
|
108
109
|
/>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
{options.suspense && (
|
|
111
|
+
<>
|
|
112
|
+
<File.Import name={['useSuspenseQuery']} path={importPath} />
|
|
113
|
+
<File.Import name={['QueryKey', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={importPath} isTypeOnly />
|
|
114
|
+
<SuspenseQuery
|
|
115
|
+
name={query.name}
|
|
116
|
+
queryOptionsName={queryOptions.name}
|
|
117
|
+
typeSchemas={type.schemas}
|
|
118
|
+
paramsType={options.paramsType}
|
|
119
|
+
pathParamsType={options.pathParamsType}
|
|
120
|
+
operation={operation}
|
|
121
|
+
dataReturnType={options.client.dataReturnType}
|
|
122
|
+
queryKeyName={queryKey.name}
|
|
123
|
+
queryKeyTypeName={queryKey.typeName}
|
|
124
|
+
/>
|
|
125
|
+
</>
|
|
126
|
+
)}
|
|
120
127
|
</File>
|
|
121
128
|
)
|
|
122
129
|
},
|