@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2

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 (78) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-37VO6QXJ.cjs +669 -0
  3. package/dist/chunk-37VO6QXJ.cjs.map +1 -0
  4. package/dist/chunk-C2H3KPHM.cjs +658 -0
  5. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  6. package/dist/chunk-IRW2Y3EC.js +660 -0
  7. package/dist/chunk-IRW2Y3EC.js.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 -12
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -6
  13. package/dist/components.d.ts +161 -6
  14. package/dist/components.js +2 -12
  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 +78 -130
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +61 -120
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-5pnOmDmM.d.cts +231 -0
  29. package/dist/types-5pnOmDmM.d.ts +231 -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 +137 -321
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -594
  36. package/src/components/QueryKey.tsx +51 -182
  37. package/src/components/QueryOptions.tsx +71 -473
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -0
  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 +60 -76
  59. package/src/types.ts +42 -115
  60. package/dist/chunk-7ZODZVKP.cjs +0 -1470
  61. package/dist/chunk-7ZODZVKP.cjs.map +0 -1
  62. package/dist/chunk-ZYTZV43V.js +0 -1470
  63. package/dist/chunk-ZYTZV43V.js.map +0 -1
  64. package/dist/index-5kpkk-7M.d.cts +0 -545
  65. package/dist/index-5kpkk-7M.d.ts +0 -545
  66. package/src/OperationGenerator.tsx +0 -57
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  72. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  73. package/src/components/QueryImports.tsx +0 -167
  74. package/src/components/SchemaType.tsx +0 -59
  75. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  76. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  77. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
  78. package/src/utils.ts +0 -96
@@ -1,545 +0,0 @@
1
- import { URLPath } from '@kubb/core/utils';
2
- import { HttpMethod } from '@kubb/oas';
3
- import { ReactNode, ComponentType, ComponentProps } from 'react';
4
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
5
- import * as KubbFile from '@kubb/fs/types';
6
- import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
7
-
8
- type TemplateProps$4 = {
9
- /**
10
- * Name of the function
11
- */
12
- name: string;
13
- /**
14
- * Parameters/options/props that need to be used
15
- */
16
- params: string;
17
- mutateParams: string;
18
- /**
19
- * Options for JSdocs
20
- */
21
- JSDoc?: {
22
- comments: string[];
23
- };
24
- hook: {
25
- name: string;
26
- generics?: string;
27
- children?: string;
28
- };
29
- client: {
30
- generics: string;
31
- method: HttpMethod;
32
- path: URLPath;
33
- withQueryParams: boolean;
34
- withPathParams: boolean;
35
- withData: boolean;
36
- withHeaders: boolean;
37
- contentType: string;
38
- };
39
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
40
- };
41
- declare function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnType }: TemplateProps$4): ReactNode;
42
- type RootTemplateProps = {
43
- children?: React.ReactNode;
44
- };
45
- declare function RootTemplate({ children }: RootTemplateProps): JSX.Element;
46
- declare const defaultTemplates$1: {
47
- readonly default: typeof Template;
48
- readonly root: typeof RootTemplate;
49
- };
50
- type Templates$1 = Partial<typeof defaultTemplates$1>;
51
- type MutationProps = {
52
- /**
53
- * This will make it possible to override the default behaviour.
54
- */
55
- Template?: ComponentType<ComponentProps<typeof Template>>;
56
- };
57
- declare function Mutation({ Template }: MutationProps): ReactNode;
58
- declare namespace Mutation {
59
- var File: ({ ...props }: FileProps$1) => ReactNode;
60
- var templates: {
61
- readonly default: typeof Template;
62
- readonly root: typeof RootTemplate;
63
- };
64
- }
65
- type FileProps$1 = {
66
- /**
67
- * This will make it possible to override the default behaviour.
68
- */
69
- templates?: Templates$1;
70
- };
71
-
72
- type TemplateProps$3 = {
73
- /**
74
- * Path to @tanstack-query
75
- */
76
- path: string;
77
- /**
78
- * Override the path of 'useQuery'
79
- * @default 'path'
80
- */
81
- hookPath: string | undefined;
82
- optionsType: string;
83
- queryOptions: string | undefined;
84
- resultType: string;
85
- hookName: string;
86
- isInfinite: boolean;
87
- };
88
- type FrameworkProps$3 = Partial<TemplateProps$3> & {
89
- context: {
90
- isInfinite: boolean;
91
- isSuspense: boolean;
92
- };
93
- };
94
- type Props$3 = {
95
- hookPath: string | undefined;
96
- isInfinite: boolean;
97
- /**
98
- * Only for React and v5
99
- */
100
- isSuspense: boolean;
101
- /**
102
- * This will make it possible to override the default behaviour.
103
- */
104
- Template?: React.ComponentType<FrameworkProps$3>;
105
- };
106
- declare function QueryImports({ hookPath, isInfinite, isSuspense, Template }: Props$3): ReactNode;
107
- declare namespace QueryImports {
108
- var templates: {
109
- readonly react: ({ context, hookPath, ...rest }: FrameworkProps$3) => ReactNode;
110
- readonly solid: ({ context, hookPath, ...rest }: FrameworkProps$3) => ReactNode;
111
- readonly svelte: ({ context, hookPath, ...rest }: FrameworkProps$3) => ReactNode;
112
- readonly vue: ({ context, hookPath, ...rest }: FrameworkProps$3) => ReactNode;
113
- };
114
- }
115
-
116
- type TemplateProps$2 = {
117
- /**
118
- * Name of the function
119
- */
120
- name: string;
121
- /**
122
- * TypeName of the function in PascalCase
123
- */
124
- typeName: string;
125
- /**
126
- * Parameters/options/props that need to be used
127
- */
128
- params: string;
129
- /**
130
- * Generics that needs to be added for TypeScript
131
- */
132
- generics?: string;
133
- /**
134
- * ReturnType(see async for adding Promise type)
135
- */
136
- returnType?: string;
137
- /**
138
- * Options for JSdocs
139
- */
140
- JSDoc?: {
141
- comments: string[];
142
- };
143
- keys?: string;
144
- };
145
- type FrameworkProps$2 = TemplateProps$2 & {
146
- context: {
147
- factory: {
148
- name: string;
149
- };
150
- };
151
- };
152
- type Props$2 = {
153
- name: string;
154
- typeName: string;
155
- keysFn: (keys: unknown[]) => unknown[];
156
- factory: {
157
- name: string;
158
- };
159
- /**
160
- * This will make it possible to override the default behaviour.
161
- */
162
- Template?: React.ComponentType<FrameworkProps$2>;
163
- };
164
- declare function QueryKey({ name, typeName, factory, keysFn, Template }: Props$2): ReactNode;
165
- declare namespace QueryKey {
166
- var templates: {
167
- readonly react: (props: FrameworkProps$2) => ReactNode;
168
- readonly solid: (props: FrameworkProps$2) => ReactNode;
169
- readonly svelte: (props: FrameworkProps$2) => ReactNode;
170
- readonly vue: ({ context, ...rest }: FrameworkProps$2) => ReactNode;
171
- };
172
- }
173
-
174
- type TemplateProps$1 = {
175
- /**
176
- * Name of the function
177
- */
178
- name: string;
179
- /**
180
- * Parameters/options/props that need to be used
181
- */
182
- params: string;
183
- /**
184
- * Generics that needs to be added for TypeScript
185
- */
186
- generics?: string;
187
- /**
188
- * ReturnType(see async for adding Promise type)
189
- */
190
- returnType?: string;
191
- /**
192
- * Options for JSdocs
193
- */
194
- JSDoc?: {
195
- comments: string[];
196
- };
197
- hook: {
198
- queryKey: string;
199
- children?: string;
200
- };
201
- client: {
202
- generics: string;
203
- method: HttpMethod;
204
- path: URLPath;
205
- withQueryParams: boolean;
206
- withPathParams: boolean;
207
- withData: boolean;
208
- withHeaders: boolean;
209
- contentType: string;
210
- };
211
- infinite: Infinite | false;
212
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
213
- parser: string | undefined;
214
- };
215
- type FrameworkProps$1 = TemplateProps$1 & {
216
- context: {
217
- factory: {
218
- name: string;
219
- };
220
- queryKey: string;
221
- };
222
- };
223
- type Props$1 = {
224
- infinite: Infinite | false;
225
- suspense: Suspense | false;
226
- factory: {
227
- name: string;
228
- };
229
- resultType: string;
230
- /**
231
- * This will make it possible to override the default behaviour.
232
- */
233
- Template?: React.ComponentType<FrameworkProps$1>;
234
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
235
- };
236
- declare function QueryOptions$1({ factory, infinite, suspense, resultType, dataReturnType, Template }: Props$1): ReactNode;
237
- declare namespace QueryOptions$1 {
238
- var templates: {
239
- readonly react: (props: FrameworkProps$1) => ReactNode;
240
- readonly solid: (props: FrameworkProps$1) => ReactNode;
241
- readonly svelte: (props: FrameworkProps$1) => ReactNode;
242
- readonly vue: ({ client, context, ...rest }: FrameworkProps$1) => ReactNode;
243
- };
244
- }
245
-
246
- type TemplateProps = {
247
- /**
248
- * Name of the function
249
- */
250
- name: string;
251
- /**
252
- * Parameters/options/props that need to be used
253
- */
254
- params: string;
255
- /**
256
- * Generics that needs to be added for TypeScript
257
- */
258
- generics?: string;
259
- /**
260
- * ReturnType(see async for adding Promise type)
261
- */
262
- returnType?: string;
263
- /**
264
- * Options for JSdocs
265
- */
266
- JSDoc?: {
267
- comments: string[];
268
- };
269
- hook: {
270
- name: string;
271
- generics?: string;
272
- queryKey: string;
273
- queryOptions: string;
274
- };
275
- infinite: Infinite | false;
276
- };
277
- type FrameworkProps = TemplateProps & {
278
- context: {
279
- factory: {
280
- name: string;
281
- };
282
- queryKey: string;
283
- };
284
- };
285
- declare const defaultTemplates: {
286
- readonly react: (props: FrameworkProps) => ReactNode;
287
- readonly solid: (props: FrameworkProps) => ReactNode;
288
- readonly svelte: (props: FrameworkProps) => ReactNode;
289
- readonly vue: ({ context, hook, ...rest }: FrameworkProps) => ReactNode;
290
- };
291
- type Props = {
292
- factory: {
293
- name: string;
294
- };
295
- resultType: string;
296
- hookName: string;
297
- optionsType: string;
298
- infinite: Infinite | false;
299
- query: Query | false;
300
- queryOptions: QueryOptions | false;
301
- suspense: Suspense | false;
302
- /**
303
- * This will make it possible to override the default behaviour.
304
- */
305
- Template?: React.ComponentType<FrameworkProps>;
306
- /**
307
- * This will make it possible to override the default behaviour.
308
- */
309
- QueryKeyTemplate?: React.ComponentType<React.ComponentProps<typeof QueryKey.templates.react>>;
310
- /**
311
- * This will make it possible to override the default behaviour.
312
- */
313
- QueryOptionsTemplate?: React.ComponentType<React.ComponentProps<typeof QueryOptions$1.templates.react>>;
314
- };
315
- declare function Query$1({ factory, optionsType, hookName, resultType, Template, QueryKeyTemplate, QueryOptionsTemplate, ...props }: Props): ReactNode;
316
- declare namespace Query$1 {
317
- var File: ({ templates }: FileProps) => ReactNode;
318
- var templates: {
319
- readonly react: (props: FrameworkProps) => ReactNode;
320
- readonly solid: (props: FrameworkProps) => ReactNode;
321
- readonly svelte: (props: FrameworkProps) => ReactNode;
322
- readonly vue: ({ context, hook, ...rest }: FrameworkProps) => ReactNode;
323
- };
324
- }
325
- type FileProps = {
326
- /**
327
- * This will make it possible to override the default behaviour.
328
- */
329
- templates?: {
330
- query: typeof defaultTemplates;
331
- queryKey: typeof QueryKey.templates;
332
- queryOptions: typeof QueryOptions$1.templates;
333
- queryImports: typeof QueryImports.templates;
334
- };
335
- };
336
-
337
- type Templates = {
338
- mutation?: typeof Mutation.templates | false;
339
- query?: typeof Query$1.templates | false;
340
- queryOptions?: typeof QueryOptions$1.templates | false;
341
- queryKey?: typeof QueryKey.templates | false;
342
- };
343
- type Suspense = object;
344
- type Query = {
345
- /**
346
- * Customize the queryKey, here you can specify a suffix.
347
- */
348
- queryKey: (key: unknown[]) => unknown[];
349
- /**
350
- * Define which HttpMethods can be used for queries
351
- * @default ['get']
352
- */
353
- methods: Array<HttpMethod>;
354
- /**
355
- * Path to the useQuery that will be used to do the useQuery functionality.
356
- * It will be used as `import { useQuery } from '${importPath}'`.
357
- * It allows both relative and absolute path.
358
- * the path will be applied as is, so relative path should be based on the file being generated.
359
- * @default '@tanstack/react-query'
360
- */
361
- importPath?: string;
362
- };
363
- type QueryOptions = object;
364
- type Mutate = {
365
- /**
366
- * Define the way of passing through the queryParams, headerParams and data.
367
- * @default `'hook'`
368
- */
369
- variablesType: 'mutate' | 'hook';
370
- /**
371
- * Define which HttpMethods can be used for mutations
372
- * @default ['post', 'put', 'delete']
373
- */
374
- methods: Array<HttpMethod>;
375
- /**
376
- * Path to the useQuery that will be used to do the useQuery functionality.
377
- * It will be used as `import { useQuery } from '${importPath}'`.
378
- * It allows both relative and absolute path.
379
- * the path will be applied as is, so relative path should be based on the file being generated.
380
- * @default '@tanstack/react-query'
381
- */
382
- importPath?: string;
383
- };
384
- type Infinite = {
385
- /**
386
- * Specify the params key used for `pageParam`.
387
- * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
388
- * @default `'id'`
389
- */
390
- queryParam: string;
391
- /**
392
- * Which field of the data will be used, set it to undefined when no cursor is known.
393
- */
394
- cursorParam?: string | undefined;
395
- /**
396
- * The initial value, the value of the first page.
397
- * @default `0`
398
- */
399
- initialPageParam: unknown;
400
- };
401
- type Options = {
402
- output?: {
403
- /**
404
- * Output to save the @tanstack/query hooks.
405
- * @default `"hooks"`
406
- */
407
- path: string;
408
- /**
409
- * Name to be used for the `export * as {{exportAs}} from './'`
410
- */
411
- exportAs?: string;
412
- /**
413
- * Add an extension to the generated imports and exports, default it will not use an extension
414
- */
415
- extName?: KubbFile.Extname;
416
- /**
417
- * Define what needs to exported, here you can also disable the export of barrel files
418
- * @default `'barrel'`
419
- */
420
- exportType?: 'barrel' | 'barrelNamed' | false;
421
- };
422
- /**
423
- * Group the @tanstack/query hooks based on the provided name.
424
- */
425
- group?: {
426
- /**
427
- * Tag will group based on the operation tag inside the Swagger file
428
- */
429
- type: 'tag';
430
- /**
431
- * Relative path to save the grouped @tanstack/query hooks.
432
- *
433
- * `{{tag}}` will be replaced by the current tagName.
434
- * @example `${output}/{{tag}}Controller` => `hooks/PetController`
435
- * @default `${output}/{{tag}}Controller`
436
- */
437
- output?: string;
438
- /**
439
- * Name to be used for the `export * as {{exportAs}} from './`
440
- * @default `"{{tag}}Hooks"`
441
- */
442
- exportAs?: string;
443
- };
444
- client?: {
445
- /**
446
- * Path to the client that will be used to do the API calls.
447
- * It will be used as `import client from '${client.importPath}'`.
448
- * It allows both relative and absolute path.
449
- * the path will be applied as is, so relative path should be based on the file being generated.
450
- * @default '@kubb/plugin-client/client'
451
- */
452
- importPath?: string;
453
- };
454
- /**
455
- * ReturnType that needs to be used when calling client().
456
- *
457
- * `Data` will return ResponseConfig[data].
458
- *
459
- * `Full` will return ResponseConfig.
460
- * @default `'data'`
461
- * @private
462
- */
463
- /**
464
- * ReturnType that needs to be used when calling client().
465
- *
466
- * `Data` will return ResponseConfig[data].
467
- *
468
- * `Full` will return ResponseConfig.
469
- * @default `'data'`
470
- * @private
471
- */
472
- dataReturnType?: 'data' | 'full';
473
- /**
474
- * How to pass your pathParams.
475
- *
476
- * `object` will return the pathParams as an object.
477
- *
478
- * `inline` will return the pathParams as comma separated params.
479
- * @default `'inline'`
480
- * @private
481
- */
482
- pathParamsType?: 'object' | 'inline';
483
- /**
484
- * Which parser can be used before returning the data to `@tanstack/query`.
485
- * `'zod'` will use `@kubb/plugin-zod` to parse the data.
486
- */
487
- parser?: 'zod';
488
- /**
489
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
490
- */
491
- exclude?: Array<Exclude>;
492
- /**
493
- * Array containing include parameters to include tags/operations/methods/paths.
494
- */
495
- include?: Array<Include>;
496
- /**
497
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
498
- */
499
- override?: Array<Override<ResolvedOptions>>;
500
- /**
501
- * When set, an infiniteQuery hooks will be added.
502
- */
503
- infinite?: Partial<Infinite> | false;
504
- /**
505
- * When set, a suspenseQuery hooks will be added.
506
- */
507
- suspense?: Partial<Suspense> | false;
508
- /**
509
- * Override some useQuery behaviours.
510
- */
511
- query?: Partial<Query> | false;
512
- queryOptions?: Partial<QueryOptions> | false;
513
- /**
514
- * Override some useMutation behaviours.
515
- */
516
- mutate?: Mutate | false;
517
- transformers?: {
518
- /**
519
- * Customize the names based on the type that is provided by the plugin.
520
- */
521
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
522
- };
523
- /**
524
- * Make it possible to override one of the templates
525
- */
526
- templates?: Partial<Templates>;
527
- };
528
- type ResolvedOptions = {
529
- client: Required<NonNullable<PluginReactQuery['options']['client']>>;
530
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
531
- pathParamsType: NonNullable<PluginReactQuery['options']['pathParamsType']>;
532
- parser: PluginReactQuery['options']['parser'];
533
- /**
534
- * Only used of infinite
535
- */
536
- infinite: Infinite | false;
537
- suspense: Suspense | false;
538
- query: Query | false;
539
- queryOptions: QueryOptions | false;
540
- mutate: Mutate | false;
541
- templates: NonNullable<Templates>;
542
- };
543
- type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
544
-
545
- export { Mutation as M, type Options as O, type PluginReactQuery as P, Query$1 as Q, QueryKey as a, QueryOptions$1 as b };
@@ -1,57 +0,0 @@
1
- import { OperationGenerator as Generator } from '@kubb/plugin-oas'
2
- import { Oas } from '@kubb/plugin-oas/components'
3
- import { App, createRoot } from '@kubb/react'
4
-
5
- import { Mutation } from './components/Mutation.tsx'
6
- import { Query } from './components/Query.tsx'
7
- import { QueryKey } from './components/QueryKey.tsx'
8
- import { QueryOptions } from './components/QueryOptions.tsx'
9
-
10
- import type { Operation } from '@kubb/oas'
11
- import type { OperationMethodResult } from '@kubb/plugin-oas'
12
- import { QueryImports } from './components/QueryImports.tsx'
13
- import type { FileMeta, PluginReactQuery } from './types.ts'
14
-
15
- export class OperationGenerator extends Generator<PluginReactQuery['resolvedOptions'], PluginReactQuery, FileMeta> {
16
- async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {
17
- const { oas, pluginManager, plugin, mode } = this.context
18
-
19
- const root = createRoot({
20
- logger: pluginManager.logger,
21
- })
22
-
23
- const templates = {
24
- mutation: Mutation.templates,
25
- query: Query.templates,
26
- queryOptions: QueryOptions.templates,
27
- queryKey: QueryKey.templates,
28
- queryImports: QueryImports.templates,
29
- ...options.templates,
30
- }
31
-
32
- const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
33
- const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method)
34
-
35
- root.render(
36
- <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
37
- <Oas oas={oas} operations={[operation]} generator={this}>
38
- <Oas.Operation operation={operation}>
39
- {isMutate && templates?.mutation && <Mutation.File templates={templates.mutation} />}
40
- {isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && (
41
- <Query.File
42
- templates={{
43
- query: templates.query,
44
- queryKey: templates.queryKey,
45
- queryOptions: templates.queryOptions,
46
- queryImports: templates.queryImports,
47
- }}
48
- />
49
- )}
50
- </Oas.Operation>
51
- </Oas>
52
- </App>,
53
- )
54
-
55
- return root.files
56
- }
57
- }
@@ -1,69 +0,0 @@
1
- import client from "@kubb/plugin-client/client";
2
- import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
3
- import { useQuery } from "@tanstack/react-query";
4
-
5
- type UpdatePetWithFormClient = typeof client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>;
6
-
7
- type UpdatePetWithForm = {
8
- data: UpdatePetWithFormMutationResponse;
9
- error: UpdatePetWithForm405;
10
- request: UpdatePetWithFormMutationRequest;
11
- pathParams: UpdatePetWithFormPathParams;
12
- queryParams: UpdatePetWithFormQueryParams;
13
- headerParams: never;
14
- response: UpdatePetWithFormMutationResponse;
15
- client: {
16
- parameters: Partial<Parameters<UpdatePetWithFormClient>[0]>;
17
- return: Awaited<ReturnType<UpdatePetWithFormClient>>;
18
- };
19
- };
20
-
21
- export const updatePetWithFormQueryKey = ({ petId }: {
22
- petId: UpdatePetWithFormPathParams["petId"];
23
- }, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"]) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
24
-
25
- export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey>;
26
-
27
- export function updatePetWithFormQueryOptions<TData = UpdatePetWithForm["response"], TQueryData = UpdatePetWithForm["response"]>({ petId }: {
28
- petId: UpdatePetWithFormPathParams["petId"];
29
- }, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"], options: UpdatePetWithForm["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<UpdatePetWithForm["response"], UpdatePetWithForm["error"], TData, TQueryData>, "queryKey"> {
30
- const queryKey = updatePetWithFormQueryKey({ petId }, params, data);
31
- return {
32
- queryKey,
33
- queryFn: async () => {
34
- const res = await client<UpdatePetWithForm["data"], UpdatePetWithForm["error"]>({
35
- method: "post",
36
- url: `/pet/${petId}`,
37
- params,
38
- data,
39
- ...options
40
- });
41
- return res.data;
42
- },
43
- };
44
- }
45
-
46
- /**
47
- * @summary Updates a pet in the store with form data
48
- * @link /pet/:petId
49
- */
50
- export function updatePetWithForm<TData = UpdatePetWithForm["response"], TQueryData = UpdatePetWithForm["response"], TQueryKey extends QueryKey = UpdatePetWithFormQueryKey>({ petId }: {
51
- petId: UpdatePetWithFormPathParams["petId"];
52
- }, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"], options: {
53
- query?: Partial<UseBaseQueryOptions<UpdatePetWithForm["response"], UpdatePetWithForm["error"], TData, TQueryData, TQueryKey>>;
54
- client?: UpdatePetWithForm["client"]["parameters"];
55
- } = {}): UseQueryResult<TData, UpdatePetWithForm["error"]> & {
56
- queryKey: TQueryKey;
57
- } {
58
- const { query: queryOptions, client: clientOptions = {} } = options ?? {};
59
- const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey({ petId }, params, data);
60
- const query = useQuery<UpdatePetWithForm["data"], UpdatePetWithForm["error"], TData, any>({
61
- ...updatePetWithFormQueryOptions<TData, TQueryData>({ petId }, params, data, clientOptions),
62
- queryKey,
63
- ...queryOptions
64
- }) as UseQueryResult<TData, UpdatePetWithForm["error"]> & {
65
- queryKey: TQueryKey;
66
- };
67
- query.queryKey = queryKey as TQueryKey;
68
- return query;
69
- }