@kubb/plugin-react-query 5.0.0-alpha.9 → 5.0.0-beta.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -93
  3. package/dist/index.cjs +2317 -149
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +494 -6
  6. package/dist/index.js +2283 -143
  7. package/dist/index.js.map +1 -1
  8. package/package.json +47 -75
  9. package/dist/components-BHQT9ZLc.cjs +0 -1634
  10. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  11. package/dist/components-CpyHYGOw.js +0 -1520
  12. package/dist/components-CpyHYGOw.js.map +0 -1
  13. package/dist/components.cjs +0 -13
  14. package/dist/components.d.ts +0 -398
  15. package/dist/components.js +0 -2
  16. package/dist/generators-DP07m3rH.cjs +0 -1469
  17. package/dist/generators-DP07m3rH.cjs.map +0 -1
  18. package/dist/generators-DkQwKTc2.js +0 -1427
  19. package/dist/generators-DkQwKTc2.js.map +0 -1
  20. package/dist/generators.cjs +0 -9
  21. package/dist/generators.d.ts +0 -523
  22. package/dist/generators.js +0 -2
  23. package/dist/types-D5S7Ny9r.d.ts +0 -270
  24. package/src/components/InfiniteQuery.tsx +0 -220
  25. package/src/components/InfiniteQueryOptions.tsx +0 -289
  26. package/src/components/Mutation.tsx +0 -158
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/MutationOptions.tsx +0 -122
  29. package/src/components/Query.tsx +0 -194
  30. package/src/components/QueryKey.tsx +0 -1
  31. package/src/components/QueryOptions.tsx +0 -181
  32. package/src/components/SuspenseInfiniteQuery.tsx +0 -220
  33. package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -289
  34. package/src/components/SuspenseQuery.tsx +0 -204
  35. package/src/components/index.ts +0 -11
  36. package/src/generators/customHookOptionsFileGenerator.tsx +0 -98
  37. package/src/generators/hookOptionsGenerator.tsx +0 -196
  38. package/src/generators/index.ts +0 -7
  39. package/src/generators/infiniteQueryGenerator.tsx +0 -214
  40. package/src/generators/mutationGenerator.tsx +0 -195
  41. package/src/generators/queryGenerator.tsx +0 -194
  42. package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -202
  43. package/src/generators/suspenseQueryGenerator.tsx +0 -207
  44. package/src/index.ts +0 -2
  45. package/src/plugin.ts +0 -239
  46. package/src/types.ts +0 -205
  47. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/plugin.ts DELETED
@@ -1,239 +0,0 @@
1
- import path from 'node:path'
2
- import { camelCase, pascalCase } from '@internals/utils'
3
- import { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
4
- import { pluginClientName } from '@kubb/plugin-client'
5
- import { source as axiosClientSource } from '@kubb/plugin-client/templates/clients/axios.source'
6
- import { source as fetchClientSource } from '@kubb/plugin-client/templates/clients/fetch.source'
7
- import { source as configSource } from '@kubb/plugin-client/templates/config.source'
8
- import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
9
- import { pluginTsName } from '@kubb/plugin-ts'
10
- import { pluginZodName } from '@kubb/plugin-zod'
11
- import { MutationKey } from './components'
12
- import { QueryKey } from './components/QueryKey.tsx'
13
- import {
14
- customHookOptionsFileGenerator,
15
- hookOptionsGenerator,
16
- infiniteQueryGenerator,
17
- mutationGenerator,
18
- queryGenerator,
19
- suspenseInfiniteQueryGenerator,
20
- suspenseQueryGenerator,
21
- } from './generators'
22
- import type { PluginReactQuery } from './types.ts'
23
-
24
- export const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']
25
-
26
- export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
27
- const {
28
- output = { path: 'hooks', barrelType: 'named' },
29
- group,
30
- exclude = [],
31
- include,
32
- override = [],
33
- parser = 'client',
34
- suspense = {},
35
- infinite = false,
36
- transformers = {},
37
- paramsType = 'inline',
38
- pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
39
- generators = [
40
- queryGenerator,
41
- suspenseQueryGenerator,
42
- infiniteQueryGenerator,
43
- suspenseInfiniteQueryGenerator,
44
- mutationGenerator,
45
- hookOptionsGenerator,
46
- customHookOptionsFileGenerator,
47
- ].filter(Boolean),
48
- mutation = {},
49
- query = {},
50
- mutationKey = MutationKey.getTransformer,
51
- queryKey = QueryKey.getTransformer,
52
- customOptions,
53
- paramsCasing,
54
- contentType,
55
- client,
56
- } = options
57
-
58
- const clientName = client?.client ?? 'axios'
59
- const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : undefined)
60
-
61
- return {
62
- name: pluginReactQueryName,
63
- options: {
64
- output,
65
- client: {
66
- bundle: client?.bundle,
67
- baseURL: client?.baseURL,
68
- client: clientName,
69
- clientType: client?.clientType ?? 'function',
70
- dataReturnType: client?.dataReturnType ?? 'data',
71
- pathParamsType,
72
- importPath: clientImportPath,
73
- paramsCasing,
74
- },
75
- infinite: infinite
76
- ? {
77
- queryParam: 'id',
78
- initialPageParam: 0,
79
- cursorParam: undefined,
80
- nextParam: undefined,
81
- previousParam: undefined,
82
- ...infinite,
83
- }
84
- : false,
85
- suspense,
86
- queryKey,
87
- query:
88
- query === false
89
- ? false
90
- : {
91
- methods: ['get'],
92
- importPath: '@tanstack/react-query',
93
- ...query,
94
- },
95
- mutationKey,
96
- mutation:
97
- mutation === false
98
- ? false
99
- : {
100
- methods: ['post', 'put', 'patch', 'delete'],
101
- importPath: '@tanstack/react-query',
102
- ...mutation,
103
- },
104
- customOptions: customOptions ? { name: 'useCustomHookOptions', ...customOptions } : undefined,
105
- paramsType,
106
- pathParamsType,
107
- parser,
108
- paramsCasing,
109
- group,
110
- },
111
- pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
112
- resolvePath(baseName, pathMode, options) {
113
- const root = path.resolve(this.config.root, this.config.output.path)
114
- const mode = pathMode ?? getMode(path.resolve(root, output.path))
115
-
116
- if (mode === 'single') {
117
- /**
118
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
119
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
120
- */
121
- return path.resolve(root, output.path)
122
- }
123
-
124
- if (group && (options?.group?.path || options?.group?.tag)) {
125
- const groupName: Group['name'] = group?.name
126
- ? group.name
127
- : (ctx) => {
128
- if (group?.type === 'path') {
129
- return `${ctx.group.split('/')[1]}`
130
- }
131
- return `${camelCase(ctx.group)}Controller`
132
- }
133
-
134
- return path.resolve(
135
- root,
136
- output.path,
137
- groupName({
138
- group: group.type === 'path' ? options.group.path! : options.group.tag!,
139
- }),
140
- baseName,
141
- )
142
- }
143
-
144
- return path.resolve(root, output.path, baseName)
145
- },
146
- resolveName(name, type) {
147
- let resolvedName = camelCase(name)
148
-
149
- if (type === 'file' || type === 'function') {
150
- resolvedName = camelCase(name, {
151
- isFile: type === 'file',
152
- })
153
- }
154
- if (type === 'type') {
155
- resolvedName = pascalCase(name)
156
- }
157
-
158
- if (type) {
159
- return transformers?.name?.(resolvedName, type) || resolvedName
160
- }
161
-
162
- return resolvedName
163
- },
164
- async install() {
165
- const root = path.resolve(this.config.root, this.config.output.path)
166
- const mode = getMode(path.resolve(root, output.path))
167
- const oas = await this.getOas()
168
- const baseURL = await this.getBaseURL()
169
-
170
- if (baseURL) {
171
- this.plugin.options.client.baseURL = baseURL
172
- }
173
-
174
- const hasClientPlugin = !!this.driver.getPluginByName(pluginClientName)
175
-
176
- if (this.plugin.options.client.bundle && !hasClientPlugin && !this.plugin.options.client.importPath) {
177
- // pre add bundled fetch
178
- await this.upsertFile({
179
- baseName: 'fetch.ts',
180
- path: path.resolve(root, '.kubb/fetch.ts'),
181
- sources: [
182
- {
183
- name: 'fetch',
184
- value: this.plugin.options.client.client === 'fetch' ? fetchClientSource : axiosClientSource,
185
- isExportable: true,
186
- isIndexable: true,
187
- },
188
- ],
189
- imports: [],
190
- exports: [],
191
- })
192
- }
193
-
194
- if (!hasClientPlugin) {
195
- await this.upsertFile({
196
- baseName: 'config.ts',
197
- path: path.resolve(root, '.kubb/config.ts'),
198
- sources: [
199
- {
200
- name: 'config',
201
- value: configSource,
202
- isExportable: false,
203
- isIndexable: false,
204
- },
205
- ],
206
- imports: [],
207
- exports: [],
208
- })
209
- }
210
-
211
- const operationGenerator = new OperationGenerator(this.plugin.options, {
212
- fabric: this.fabric,
213
- oas,
214
- driver: this.driver,
215
- events: this.events,
216
- plugin: this.plugin,
217
- contentType,
218
- exclude,
219
- include,
220
- override,
221
- mode,
222
- })
223
-
224
- const files = await operationGenerator.build(...generators)
225
- await this.upsertFile(...files)
226
-
227
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
228
- type: output.barrelType ?? 'named',
229
- root,
230
- output,
231
- meta: {
232
- pluginName: this.plugin.name,
233
- },
234
- })
235
-
236
- await this.upsertFile(...barrelFiles)
237
- },
238
- }
239
- })
package/src/types.ts DELETED
@@ -1,205 +0,0 @@
1
- import type { Transformer } from '@internals/tanstack-query'
2
- import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
- import type { contentType, HttpMethod, Oas } from '@kubb/oas'
4
- import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
5
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
6
- import type { Generator } from '@kubb/plugin-oas/generators'
7
-
8
- export type { Transformer } from '@internals/tanstack-query'
9
-
10
- type Suspense = object
11
-
12
- /**
13
- * Customize the queryKey
14
- */
15
- type QueryKey = Transformer
16
-
17
- /**
18
- * Customize the mutationKey
19
- */
20
- type MutationKey = Transformer
21
-
22
- type Query = {
23
- /**
24
- * Define which HttpMethods can be used for queries
25
- * @default ['get']
26
- */
27
- methods: Array<HttpMethod>
28
- /**
29
- * Path to the useQuery hook for useQuery functionality.
30
- * Used as `import { useQuery } from '${importPath}'`.
31
- * Accepts relative and absolute paths.
32
- * Path is used as-is; relative paths are based on the generated file location.
33
- * @default '@tanstack/react-query'
34
- */
35
- importPath?: string
36
- }
37
-
38
- type Mutation = {
39
- /**
40
- * Define which HttpMethods can be used for mutations
41
- * @default ['post', 'put', 'delete']
42
- */
43
- methods: Array<HttpMethod>
44
- /**
45
- * Path to the useQuery hook for useQuery functionality.
46
- * Used as `import { useQuery } from '${importPath}'`.
47
- * Accepts relative and absolute paths.
48
- * Path is used as-is; relative paths are based on the generated file location.
49
- * @default '@tanstack/react-query'
50
- */
51
- importPath?: string
52
- }
53
-
54
- export type Infinite = {
55
- /**
56
- * Specify the params key used for `pageParam`.
57
- * @default 'id'
58
- */
59
- queryParam: string
60
- /**
61
- * Which field of the data is used, set it to undefined when no cursor is known.
62
- * @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
63
- */
64
- cursorParam?: string | undefined
65
- /**
66
- * Which field of the data is used to get the cursor for the next page.
67
- * Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
68
- */
69
- nextParam?: string | string[] | undefined
70
- /**
71
- * Which field of the data is used to get the cursor for the previous page.
72
- * Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
73
- */
74
- previousParam?: string | string[] | undefined
75
- /**
76
- * The initial value, the value of the first page.
77
- * @default 0
78
- */
79
- initialPageParam: unknown
80
- }
81
-
82
- type CustomOptions = {
83
- /**
84
- * Path to the hook that is used to customize the hook options.
85
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
86
- * It allows both relative and absolute paths but be aware that we will not change the path.
87
- */
88
- importPath: string
89
- /**
90
- * Name of the exported hook that is used to customize the hook options.
91
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
92
- * @default 'useCustomHookOptions'
93
- */
94
- name?: string
95
- }
96
-
97
- export type Options = {
98
- /**
99
- * Specify the export location for the files and define the behavior of the output
100
- * @default { path: 'hooks', barrelType: 'named' }
101
- */
102
- output?: Output<Oas>
103
- /**
104
- * Define which contentType should be used.
105
- * By default, the first JSON valid mediaType is used
106
- */
107
- contentType?: contentType
108
- /**
109
- * Group the @tanstack/query hooks based on the provided name.
110
- */
111
- group?: Group
112
- client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
113
- /**
114
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
115
- */
116
- exclude?: Array<Exclude>
117
- /**
118
- * Array containing include parameters to include tags/operations/methods/paths.
119
- */
120
- include?: Array<Include>
121
- /**
122
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
123
- */
124
- override?: Array<Override<ResolvedOptions>>
125
- /**
126
- * How to style your params, by default no casing is applied
127
- * - 'camelcase' uses camelcase for the params names
128
- */
129
- paramsCasing?: 'camelcase'
130
- /**
131
- * How to pass your params.
132
- * - 'object' returns the params and pathParams as an object.
133
- * - 'inline' returns the params as comma separated params.
134
- * @default 'inline'
135
- */
136
- paramsType?: 'object' | 'inline'
137
- /**
138
- * How to pass your pathParams.
139
- * - 'object' returns the pathParams as an object.
140
- * - 'inline': returns the pathParams as comma separated params.
141
- * @default 'inline'
142
- */
143
- pathParamsType?: PluginClient['options']['pathParamsType']
144
-
145
- /**
146
- * When set, an infiniteQuery hooks is added.
147
- */
148
- infinite?: Partial<Infinite> | false
149
- /**
150
- * When set, a suspenseQuery hooks is added.
151
- */
152
- suspense?: Partial<Suspense> | false
153
- queryKey?: QueryKey
154
- /**
155
- * Override some useQuery behaviors.
156
- */
157
- query?: Partial<Query> | false
158
- mutationKey?: MutationKey
159
- /**
160
- * Override some useMutation behaviors.
161
- */
162
- mutation?: Partial<Mutation> | false
163
- /**
164
- * When set, a custom hook is used to customize the options of the generated hooks.
165
- * It will also generate a `HookOptions` type that can be used to type the custom options of each hook for type-safety.
166
- */
167
- customOptions?: CustomOptions
168
- /**
169
- * Which parser should be used before returning the data to `@tanstack/query`.
170
- * `'zod'` uses `@kubb/plugin-zod` to parse the data.
171
- */
172
- parser?: PluginClient['options']['parser']
173
- transformers?: {
174
- /**
175
- * Customize the names based on the type that is provided by the plugin.
176
- */
177
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
178
- }
179
- /**
180
- * Define some generators next to the react-query generators
181
- */
182
- generators?: Array<Generator<PluginReactQuery>>
183
- }
184
-
185
- type ResolvedOptions = {
186
- output: Output<Oas>
187
- group: Options['group']
188
- client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
189
- parser: Required<NonNullable<Options['parser']>>
190
- pathParamsType: NonNullable<Options['pathParamsType']>
191
- paramsCasing: Options['paramsCasing']
192
- paramsType: NonNullable<Options['paramsType']>
193
- /**
194
- * Only used of infinite
195
- */
196
- infinite: NonNullable<Infinite> | false
197
- suspense: Suspense | false
198
- queryKey: QueryKey | undefined
199
- query: NonNullable<Required<Query>> | false
200
- mutationKey: MutationKey | undefined
201
- mutation: NonNullable<Required<Mutation>> | false
202
- customOptions: NonNullable<Required<CustomOptions>> | undefined
203
- }
204
-
205
- export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>