@kubb/plugin-react-query 3.0.0-alpha.3 → 3.0.0-alpha.30

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 (81) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-2D27Y6L5.js +618 -0
  3. package/dist/chunk-2D27Y6L5.js.map +1 -0
  4. package/dist/chunk-C2H3KPHM.cjs +658 -0
  5. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  6. package/dist/chunk-JW3GZUSC.cjs +627 -0
  7. package/dist/chunk-JW3GZUSC.cjs.map +1 -0
  8. package/dist/chunk-Y3DM2P6L.js +647 -0
  9. package/dist/chunk-Y3DM2P6L.js.map +1 -0
  10. package/dist/components.cjs +39 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -7
  13. package/dist/components.d.ts +161 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +75 -154
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +54 -140
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-rJasmoxy.d.cts +187 -0
  29. package/dist/types-rJasmoxy.d.ts +187 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +130 -0
  33. package/src/components/Mutation.tsx +138 -322
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -598
  36. package/src/components/QueryKey.tsx +51 -178
  37. package/src/components/QueryOptions.tsx +72 -466
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -1
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  43. package/src/generators/__snapshots__/findByTags.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  46. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  47. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  48. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  49. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
  53. package/src/generators/index.ts +4 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  55. package/src/generators/mutationGenerator.tsx +108 -0
  56. package/src/generators/queryGenerator.tsx +121 -0
  57. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  58. package/src/plugin.ts +51 -75
  59. package/src/types.ts +49 -88
  60. package/dist/chunk-5IL6M74X.js +0 -1504
  61. package/dist/chunk-5IL6M74X.js.map +0 -1
  62. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  63. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  64. package/dist/index-C9fwRDH7.d.cts +0 -579
  65. package/dist/index-C9fwRDH7.d.ts +0 -579
  66. package/src/OperationGenerator.tsx +0 -86
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  72. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  73. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  74. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  75. package/src/components/Operations.tsx +0 -74
  76. package/src/components/QueryImports.tsx +0 -167
  77. package/src/components/SchemaType.tsx +0 -55
  78. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  79. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  80. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  81. package/src/utils.ts +0 -96
@@ -0,0 +1,124 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
10
+ import type { PluginReactQuery } from '../types'
11
+
12
+ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
13
+ name: 'react-infinite-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginReactQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
22
+ const isInfinite = isQuery && !!options.infinite
23
+
24
+ const query = {
25
+ name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
28
+ }
29
+
30
+ const client = {
31
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
32
+ }
33
+
34
+ const queryOptions = {
35
+ name: getName(operation, { type: 'function', suffix: 'InfiniteQueryOptions' }),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'InfiniteQueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'InfiniteQueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery || !isInfinite || typeof options.query === 'boolean' || typeof options.infinite === 'boolean') {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
+ <File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
62
+ <File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={options.query.importPath} isTypeOnly />
63
+ <File.Import name={'client'} path={options.client.importPath} />
64
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
66
+ <File.Import
67
+ name={[
68
+ type.schemas.request?.name,
69
+ type.schemas.response.name,
70
+ type.schemas.pathParams?.name,
71
+ type.schemas.queryParams?.name,
72
+ type.schemas.headerParams?.name,
73
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
74
+ ].filter(Boolean)}
75
+ root={query.file.path}
76
+ path={type.file.path}
77
+ isTypeOnly
78
+ />
79
+
80
+ <QueryKey
81
+ name={queryKey.name}
82
+ typeName={queryKey.typeName}
83
+ operation={operation}
84
+ pathParamsType={options.pathParamsType}
85
+ typeSchemas={type.schemas}
86
+ keysFn={options.query.key}
87
+ />
88
+ <Client
89
+ name={client.name}
90
+ isExportable={false}
91
+ isIndexable={false}
92
+ baseURL={options.baseURL}
93
+ operation={operation}
94
+ typeSchemas={type.schemas}
95
+ zodSchemas={zod.schemas}
96
+ dataReturnType={options.client.dataReturnType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ <InfiniteQueryOptions
101
+ name={queryOptions.name}
102
+ clientName={client.name}
103
+ queryKeyName={queryKey.name}
104
+ typeSchemas={type.schemas}
105
+ pathParamsType={options.pathParamsType}
106
+ dataReturnType={options.client.dataReturnType}
107
+ cursorParam={options.infinite.cursorParam}
108
+ initialPageParam={options.infinite.initialPageParam}
109
+ queryParam={options.infinite.queryParam}
110
+ />
111
+ <InfiniteQuery
112
+ name={query.name}
113
+ queryOptionsName={queryOptions.name}
114
+ typeSchemas={type.schemas}
115
+ pathParamsType={options.pathParamsType}
116
+ operation={operation}
117
+ dataReturnType={options.client.dataReturnType}
118
+ queryKeyName={queryKey.name}
119
+ queryKeyTypeName={queryKey.typeName}
120
+ />
121
+ </File>
122
+ )
123
+ },
124
+ })
@@ -0,0 +1,108 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { Mutation, MutationKey } from '../components'
10
+ import type { PluginReactQuery } from '../types'
11
+
12
+ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
13
+ name: 'react-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginReactQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+
22
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
23
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
24
+
25
+ const mutation = {
26
+ name: getName(operation, { type: 'function', prefix: 'use' }),
27
+ typeName: getName(operation, { type: 'type' }),
28
+ file: getFile(operation, { prefix: 'use' }),
29
+ }
30
+
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
33
+ //todo remove type?
34
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
35
+ }
36
+
37
+ const zod = {
38
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
39
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
40
+ }
41
+
42
+ const client = {
43
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
44
+ }
45
+
46
+ const mutationKey = {
47
+ name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
48
+ typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
49
+ }
50
+
51
+ if (!isMutation || typeof options.mutation === 'boolean') {
52
+ return null
53
+ }
54
+
55
+ return (
56
+ <File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
57
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
58
+ <File.Import name={['useMutation']} path={options.mutation.importPath} />
59
+ <File.Import name={['UseMutationOptions']} path={options.mutation.importPath} isTypeOnly />
60
+ <File.Import name={'client'} path={options.client.importPath} />
61
+ <File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
62
+ <File.Import
63
+ name={[
64
+ type.schemas.request?.name,
65
+ type.schemas.response.name,
66
+ type.schemas.pathParams?.name,
67
+ type.schemas.queryParams?.name,
68
+ type.schemas.headerParams?.name,
69
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
70
+ ].filter(Boolean)}
71
+ root={mutation.file.path}
72
+ path={type.file.path}
73
+ isTypeOnly
74
+ />
75
+ <MutationKey
76
+ name={mutationKey.name}
77
+ typeName={mutationKey.typeName}
78
+ operation={operation}
79
+ pathParamsType={options.pathParamsType}
80
+ typeSchemas={type.schemas}
81
+ keysFn={options.mutation.key}
82
+ />
83
+ <Client
84
+ name={client.name}
85
+ isExportable={false}
86
+ isIndexable={false}
87
+ baseURL={options.baseURL}
88
+ operation={operation}
89
+ typeSchemas={type.schemas}
90
+ zodSchemas={zod.schemas}
91
+ dataReturnType={options.client.dataReturnType}
92
+ pathParamsType={options.pathParamsType}
93
+ parser={options.parser}
94
+ />
95
+ <Mutation
96
+ name={mutation.name}
97
+ clientName={client.name}
98
+ typeName={mutation.typeName}
99
+ typeSchemas={type.schemas}
100
+ operation={operation}
101
+ dataReturnType={options.client.dataReturnType}
102
+ pathParamsType={options.pathParamsType}
103
+ mutationKeyName={mutationKey.name}
104
+ />
105
+ </File>
106
+ )
107
+ },
108
+ })
@@ -0,0 +1,121 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { Query, QueryKey, QueryOptions } from '../components'
10
+ import type { PluginReactQuery } from '../types'
11
+
12
+ export const queryGenerator = createReactGenerator<PluginReactQuery>({
13
+ name: 'react-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginReactQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+
22
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
23
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
24
+
25
+ const query = {
26
+ name: getName(operation, { type: 'function', prefix: 'use' }),
27
+ typeName: getName(operation, { type: 'type' }),
28
+ file: getFile(operation, { prefix: 'use' }),
29
+ }
30
+
31
+ const client = {
32
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
33
+ }
34
+
35
+ const queryOptions = {
36
+ name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
37
+ }
38
+
39
+ const queryKey = {
40
+ name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
41
+ typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
42
+ }
43
+
44
+ const type = {
45
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
46
+ //todo remove type?
47
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
48
+ }
49
+
50
+ const zod = {
51
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
52
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
53
+ }
54
+
55
+ if (!isQuery || typeof options.query === 'boolean') {
56
+ return null
57
+ }
58
+
59
+ return (
60
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
61
+ {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
62
+ <File.Import name={['useQuery', 'queryOptions']} path={options.query.importPath} />
63
+ <File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} path={options.query.importPath} isTypeOnly />
64
+ <File.Import name={'client'} path={options.client.importPath} />
65
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
66
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
67
+ <File.Import
68
+ name={[
69
+ type.schemas.request?.name,
70
+ type.schemas.response.name,
71
+ type.schemas.pathParams?.name,
72
+ type.schemas.queryParams?.name,
73
+ type.schemas.headerParams?.name,
74
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
75
+ ].filter(Boolean)}
76
+ root={query.file.path}
77
+ path={type.file.path}
78
+ isTypeOnly
79
+ />
80
+
81
+ <QueryKey
82
+ name={queryKey.name}
83
+ typeName={queryKey.typeName}
84
+ operation={operation}
85
+ pathParamsType={options.pathParamsType}
86
+ typeSchemas={type.schemas}
87
+ keysFn={options.query.key}
88
+ />
89
+ <Client
90
+ name={client.name}
91
+ isExportable={false}
92
+ isIndexable={false}
93
+ baseURL={options.baseURL}
94
+ operation={operation}
95
+ typeSchemas={type.schemas}
96
+ zodSchemas={zod.schemas}
97
+ dataReturnType={options.client.dataReturnType}
98
+ pathParamsType={options.pathParamsType}
99
+ parser={options.parser}
100
+ />
101
+ <QueryOptions
102
+ name={queryOptions.name}
103
+ clientName={client.name}
104
+ queryKeyName={queryKey.name}
105
+ typeSchemas={type.schemas}
106
+ pathParamsType={options.pathParamsType}
107
+ />
108
+ <Query
109
+ name={query.name}
110
+ queryOptionsName={queryOptions.name}
111
+ typeSchemas={type.schemas}
112
+ pathParamsType={options.pathParamsType}
113
+ operation={operation}
114
+ dataReturnType={options.client.dataReturnType}
115
+ queryKeyName={queryKey.name}
116
+ queryKeyTypeName={queryKey.typeName}
117
+ />
118
+ </File>
119
+ )
120
+ },
121
+ })
@@ -0,0 +1,120 @@
1
+ import transformers from '@kubb/core/transformers'
2
+ import { pluginClientName } from '@kubb/plugin-client'
3
+ import { Client } from '@kubb/plugin-client/components'
4
+ import { createReactGenerator } from '@kubb/plugin-oas'
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
+ import { pluginTsName } from '@kubb/plugin-ts'
7
+ import { pluginZodName } from '@kubb/plugin-zod'
8
+ import { File, useApp } from '@kubb/react'
9
+ import { QueryKey, QueryOptions, SuspenseQuery } from '../components'
10
+ import type { PluginReactQuery } from '../types'
11
+
12
+ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
13
+ name: 'react-suspense-query',
14
+ Operation({ options, operation }) {
15
+ const {
16
+ plugin: {
17
+ options: { output },
18
+ },
19
+ } = useApp<PluginReactQuery>()
20
+ const { getSchemas, getName, getFile } = useOperationManager()
21
+ const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
22
+ const isSuspense = isQuery && !!options.suspense
23
+
24
+ const query = {
25
+ name: getName(operation, { type: 'function', prefix: 'use', suffix: 'suspense' }),
26
+ typeName: getName(operation, { type: 'type' }),
27
+ file: getFile(operation, { prefix: 'use', suffix: 'suspense' }),
28
+ }
29
+
30
+ const client = {
31
+ name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
32
+ }
33
+
34
+ const queryOptions = {
35
+ name: getName(operation, { type: 'function', suffix: 'SuspenseQueryOptions' }),
36
+ }
37
+
38
+ const queryKey = {
39
+ name: getName(operation, { type: 'const', suffix: 'SuspenseQueryKey' }),
40
+ typeName: getName(operation, { type: 'type', suffix: 'SuspenseQueryKey' }),
41
+ }
42
+
43
+ const type = {
44
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
45
+ //todo remove type?
46
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
47
+ }
48
+
49
+ const zod = {
50
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
51
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
+ }
53
+
54
+ if (!isQuery || !isSuspense || typeof options.query === 'boolean') {
55
+ return null
56
+ }
57
+
58
+ return (
59
+ <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
+ {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
+ <File.Import name={'client'} path={options.client.importPath} />
64
+ <File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
65
+ {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
66
+ <File.Import
67
+ name={[
68
+ type.schemas.request?.name,
69
+ type.schemas.response.name,
70
+ type.schemas.pathParams?.name,
71
+ type.schemas.queryParams?.name,
72
+ type.schemas.headerParams?.name,
73
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
74
+ ].filter(Boolean)}
75
+ root={query.file.path}
76
+ path={type.file.path}
77
+ isTypeOnly
78
+ />
79
+
80
+ <QueryKey
81
+ name={queryKey.name}
82
+ typeName={queryKey.typeName}
83
+ operation={operation}
84
+ pathParamsType={options.pathParamsType}
85
+ typeSchemas={type.schemas}
86
+ keysFn={options.query.key}
87
+ />
88
+ <Client
89
+ name={client.name}
90
+ isExportable={false}
91
+ isIndexable={false}
92
+ baseURL={options.baseURL}
93
+ operation={operation}
94
+ typeSchemas={type.schemas}
95
+ zodSchemas={zod.schemas}
96
+ dataReturnType={options.client.dataReturnType}
97
+ pathParamsType={options.pathParamsType}
98
+ parser={options.parser}
99
+ />
100
+ <QueryOptions
101
+ name={queryOptions.name}
102
+ clientName={client.name}
103
+ queryKeyName={queryKey.name}
104
+ typeSchemas={type.schemas}
105
+ pathParamsType={options.pathParamsType}
106
+ />
107
+ <SuspenseQuery
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
+ />
117
+ </File>
118
+ )
119
+ },
120
+ })
package/src/plugin.ts CHANGED
@@ -3,50 +3,47 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
+
8
8
  import { pluginTsName } from '@kubb/plugin-ts'
9
9
  import { pluginZodName } from '@kubb/plugin-zod'
10
10
 
11
- import { OperationGenerator } from './OperationGenerator.tsx'
12
- import { Mutation, Operations, Query, QueryKey, QueryOptions } from './components/index.ts'
13
-
14
11
  import type { Plugin } from '@kubb/core'
15
12
  import type { PluginOas } from '@kubb/plugin-oas'
16
- import { QueryImports } from './components/QueryImports.tsx'
13
+ import { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'
17
14
  import type { PluginReactQuery } from './types.ts'
18
15
 
19
16
  export const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']
20
17
 
21
18
  export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
22
19
  const {
23
- output = { path: 'hooks' },
20
+ output = { path: 'hooks', barrelType: 'named' },
24
21
  group,
25
22
  exclude = [],
26
23
  include,
27
24
  override = [],
28
- parser,
25
+ parser = 'client',
29
26
  suspense = {},
30
27
  infinite,
31
28
  transformers = {},
32
- dataReturnType = 'data',
33
29
  pathParamsType = 'inline',
34
- mutate = {},
30
+ generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
31
+ mutation = {},
35
32
  query = {},
36
- queryOptions = {},
37
- templates,
38
33
  } = options
39
34
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
40
35
 
41
36
  return {
42
37
  name: pluginReactQueryName,
43
38
  options: {
39
+ output,
40
+ baseURL: undefined,
44
41
  client: {
45
42
  importPath: '@kubb/plugin-client/client',
43
+ dataReturnType: 'data',
44
+ pathParamsType: 'inline',
46
45
  ...options.client,
47
46
  },
48
- dataReturnType,
49
- pathParamsType,
50
47
  infinite: infinite
51
48
  ? {
52
49
  queryParam: 'id',
@@ -56,31 +53,19 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
56
53
  }
57
54
  : false,
58
55
  suspense,
59
- query: query
60
- ? {
61
- queryKey: (key: unknown[]) => key,
62
- methods: ['get'],
63
- importPath: '@tanstack/react-query',
64
- ...query,
65
- }
66
- : false,
67
- queryOptions,
68
- mutate: mutate
69
- ? {
70
- variablesType: 'hook',
71
- methods: ['post', 'put', 'patch', 'delete'],
72
- ...mutate,
73
- }
74
- : false,
75
- templates: {
76
- mutation: Mutation.templates,
77
- query: Query.templates,
78
- queryOptions: QueryOptions.templates,
79
- queryKey: QueryKey.templates,
80
- queryImports: QueryImports.templates,
81
- operations: Operations.templates,
82
- ...templates,
56
+ query: {
57
+ key: (key: unknown[]) => key,
58
+ methods: ['get'],
59
+ importPath: '@tanstack/react-query',
60
+ ...query,
61
+ },
62
+ mutation: {
63
+ key: (key: unknown[]) => key,
64
+ methods: ['post', 'put', 'patch', 'delete'],
65
+ importPath: '@tanstack/react-query',
66
+ ...mutation,
83
67
  },
68
+ pathParamsType,
84
69
  parser,
85
70
  },
86
71
  pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
@@ -109,7 +94,6 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
109
94
 
110
95
  if (type === 'file' || type === 'function') {
111
96
  resolvedName = camelCase(name, {
112
- prefix: 'use',
113
97
  isFile: type === 'file',
114
98
  })
115
99
  }
@@ -129,48 +113,40 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
129
113
  const oas = await swaggerPlugin.context.getOas()
130
114
  const root = path.resolve(this.config.root, this.config.output.path)
131
115
  const mode = FileManager.getMode(path.resolve(root, output.path))
132
-
133
- const operationGenerator = new OperationGenerator(this.plugin.options, {
134
- oas,
135
- pluginManager: this.pluginManager,
136
- plugin: this.plugin,
137
- contentType: swaggerPlugin.context.contentType,
138
- exclude,
139
- include,
140
- override,
141
- mode,
142
- })
143
-
144
- const files = await operationGenerator.build()
145
- await this.addFile(...files)
146
- },
147
- async buildEnd() {
148
- if (this.config.output.write === false) {
149
- return
150
- }
151
-
152
- const root = path.resolve(this.config.root, this.config.output.path)
153
-
154
- if (group?.type === 'tag') {
155
- const rootFiles = await getGroupedByTagFiles({
156
- logger: this.logger,
157
- files: this.fileManager.files,
116
+ const baseURL = await swaggerPlugin.context.getBaseURL()
117
+
118
+ const operationGenerator = new OperationGenerator(
119
+ {
120
+ ...this.plugin.options,
121
+ baseURL,
122
+ },
123
+ {
124
+ oas,
125
+ pluginManager: this.pluginManager,
158
126
  plugin: this.plugin,
159
- template,
160
- exportAs: group.exportAs || '{{tag}}Hooks',
161
- root,
162
- output,
163
- })
164
-
165
- await this.addFile(...rootFiles)
166
- }
127
+ contentType: swaggerPlugin.context.contentType,
128
+ exclude,
129
+ include,
130
+ override,
131
+ mode,
132
+ },
133
+ )
134
+
135
+ const files = await operationGenerator.build(...generators)
136
+ await this.addFile(...files)
167
137
 
168
- await this.fileManager.addIndexes({
138
+ const barrelFiles = await this.fileManager.getBarrelFiles({
139
+ type: output.barrelType ?? 'named',
169
140
  root,
170
141
  output,
171
- meta: { pluginKey: this.plugin.key },
142
+ files: this.fileManager.files,
143
+ meta: {
144
+ pluginKey: this.plugin.key,
145
+ },
172
146
  logger: this.logger,
173
147
  })
148
+
149
+ await this.addFile(...barrelFiles)
174
150
  },
175
151
  }
176
152
  })