@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (73) hide show
  1. package/dist/chunk-ESENIDWJ.js +608 -0
  2. package/dist/chunk-ESENIDWJ.js.map +1 -0
  3. package/dist/chunk-JQEH3UHY.cjs +618 -0
  4. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  5. package/dist/chunk-KRG2LWHM.cjs +606 -0
  6. package/dist/chunk-KRG2LWHM.cjs.map +1 -0
  7. package/dist/chunk-ME7ZFS5H.js +596 -0
  8. package/dist/chunk-ME7ZFS5H.js.map +1 -0
  9. package/dist/components.cjs +17 -5
  10. package/dist/components.d.cts +143 -5
  11. package/dist/components.d.ts +143 -5
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +25 -0
  14. package/dist/generators.cjs.map +1 -0
  15. package/dist/generators.d.cts +15 -0
  16. package/dist/generators.d.ts +15 -0
  17. package/dist/generators.js +4 -0
  18. package/dist/generators.js.map +1 -0
  19. package/dist/index.cjs +33 -76
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -4
  22. package/dist/index.d.ts +2 -4
  23. package/dist/index.js +34 -77
  24. package/dist/index.js.map +1 -1
  25. package/dist/types-DJxL-JeY.d.cts +195 -0
  26. package/dist/types-DJxL-JeY.d.ts +195 -0
  27. package/package.json +23 -15
  28. package/src/components/InfiniteQuery.tsx +129 -0
  29. package/src/components/InfiniteQueryOptions.tsx +121 -0
  30. package/src/components/Mutation.tsx +112 -304
  31. package/src/components/Query.tsx +91 -593
  32. package/src/components/QueryKey.tsx +51 -182
  33. package/src/components/QueryOptions.tsx +64 -465
  34. package/src/components/SuspenseQuery.tsx +129 -0
  35. package/src/components/index.ts +3 -0
  36. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +64 -0
  37. package/src/generators/__snapshots__/clientGetImportPath.ts +64 -0
  38. package/src/generators/__snapshots__/clientPostImportPath.ts +59 -0
  39. package/src/generators/__snapshots__/findByTags.ts +64 -0
  40. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +64 -0
  41. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +64 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +64 -0
  43. package/src/generators/__snapshots__/findInfiniteByTags.ts +74 -0
  44. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +74 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +77 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +59 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +63 -0
  49. package/src/generators/index.ts +4 -0
  50. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  51. package/src/generators/mutationGenerator.tsx +94 -0
  52. package/src/generators/queryGenerator.tsx +121 -0
  53. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  54. package/src/plugin.ts +38 -49
  55. package/src/types.ts +35 -59
  56. package/dist/chunk-AGLJPONA.cjs +0 -1423
  57. package/dist/chunk-AGLJPONA.cjs.map +0 -1
  58. package/dist/chunk-I7X4HNDR.js +0 -1413
  59. package/dist/chunk-I7X4HNDR.js.map +0 -1
  60. package/dist/index-BzoLlZve.d.cts +0 -537
  61. package/dist/index-BzoLlZve.d.ts +0 -537
  62. package/src/OperationGenerator.tsx +0 -57
  63. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  64. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  65. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  66. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  67. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  68. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  69. package/src/components/QueryImports.tsx +0 -167
  70. package/src/components/SchemaType.tsx +0 -74
  71. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  72. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  73. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
@@ -1,537 +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
- * Options for JSdocs
185
- */
186
- JSDoc?: {
187
- comments: string[];
188
- };
189
- hook: {
190
- queryKey: string;
191
- children?: string;
192
- };
193
- client: {
194
- generics: string;
195
- method: HttpMethod;
196
- path: URLPath;
197
- withQueryParams: boolean;
198
- withPathParams: boolean;
199
- withData: boolean;
200
- withHeaders: boolean;
201
- contentType: string;
202
- };
203
- infinite: Infinite | false;
204
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
205
- parser: string | undefined;
206
- };
207
- type FrameworkProps$1 = TemplateProps$1 & {
208
- context: {
209
- factory: {
210
- name: string;
211
- };
212
- queryKey: string;
213
- };
214
- };
215
- type Props$1 = {
216
- infinite: Infinite | false;
217
- suspense: Suspense | false;
218
- factory: {
219
- name: string;
220
- };
221
- resultType: string;
222
- /**
223
- * This will make it possible to override the default behaviour.
224
- */
225
- Template?: React.ComponentType<FrameworkProps$1>;
226
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
227
- };
228
- declare function QueryOptions$1({ factory, infinite, suspense, resultType, dataReturnType, Template }: Props$1): ReactNode;
229
- declare namespace QueryOptions$1 {
230
- var templates: {
231
- readonly react: (props: FrameworkProps$1) => ReactNode;
232
- readonly solid: (props: FrameworkProps$1) => ReactNode;
233
- readonly svelte: (props: FrameworkProps$1) => ReactNode;
234
- readonly vue: ({ client, context, ...rest }: FrameworkProps$1) => ReactNode;
235
- };
236
- }
237
-
238
- type TemplateProps = {
239
- /**
240
- * Name of the function
241
- */
242
- name: string;
243
- /**
244
- * Parameters/options/props that need to be used
245
- */
246
- params: string;
247
- /**
248
- * Generics that needs to be added for TypeScript
249
- */
250
- generics?: string;
251
- /**
252
- * ReturnType(see async for adding Promise type)
253
- */
254
- returnType?: string;
255
- /**
256
- * Options for JSdocs
257
- */
258
- JSDoc?: {
259
- comments: string[];
260
- };
261
- hook: {
262
- name: string;
263
- generics?: string;
264
- queryKey: string;
265
- queryOptions: string;
266
- };
267
- infinite: Infinite | false;
268
- };
269
- type FrameworkProps = TemplateProps & {
270
- context: {
271
- factory: {
272
- name: string;
273
- };
274
- queryKey: string;
275
- };
276
- };
277
- declare const defaultTemplates: {
278
- readonly react: (props: FrameworkProps) => ReactNode;
279
- readonly solid: (props: FrameworkProps) => ReactNode;
280
- readonly svelte: (props: FrameworkProps) => ReactNode;
281
- readonly vue: ({ context, hook, ...rest }: FrameworkProps) => ReactNode;
282
- };
283
- type Props = {
284
- factory: {
285
- name: string;
286
- };
287
- resultType: string;
288
- hookName: string;
289
- optionsType: string;
290
- infinite: Infinite | false;
291
- query: Query | false;
292
- queryOptions: QueryOptions | false;
293
- suspense: Suspense | false;
294
- /**
295
- * This will make it possible to override the default behaviour.
296
- */
297
- Template?: React.ComponentType<FrameworkProps>;
298
- /**
299
- * This will make it possible to override the default behaviour.
300
- */
301
- QueryKeyTemplate?: React.ComponentType<React.ComponentProps<typeof QueryKey.templates.react>>;
302
- /**
303
- * This will make it possible to override the default behaviour.
304
- */
305
- QueryOptionsTemplate?: React.ComponentType<React.ComponentProps<typeof QueryOptions$1.templates.react>>;
306
- };
307
- declare function Query$1({ factory, optionsType, hookName, resultType, Template, QueryKeyTemplate, QueryOptionsTemplate, ...props }: Props): ReactNode;
308
- declare namespace Query$1 {
309
- var File: ({ templates }: FileProps) => ReactNode;
310
- var templates: {
311
- readonly react: (props: FrameworkProps) => ReactNode;
312
- readonly solid: (props: FrameworkProps) => ReactNode;
313
- readonly svelte: (props: FrameworkProps) => ReactNode;
314
- readonly vue: ({ context, hook, ...rest }: FrameworkProps) => ReactNode;
315
- };
316
- }
317
- type FileProps = {
318
- /**
319
- * This will make it possible to override the default behaviour.
320
- */
321
- templates?: {
322
- query: typeof defaultTemplates;
323
- queryKey: typeof QueryKey.templates;
324
- queryOptions: typeof QueryOptions$1.templates;
325
- queryImports: typeof QueryImports.templates;
326
- };
327
- };
328
-
329
- type Templates = {
330
- mutation?: typeof Mutation.templates | false;
331
- query?: typeof Query$1.templates | false;
332
- queryOptions?: typeof QueryOptions$1.templates | false;
333
- queryKey?: typeof QueryKey.templates | false;
334
- };
335
- type Suspense = object;
336
- type Query = {
337
- /**
338
- * Customize the queryKey, here you can specify a suffix.
339
- */
340
- queryKey: (key: unknown[]) => unknown[];
341
- /**
342
- * Define which HttpMethods can be used for queries
343
- * @default ['get']
344
- */
345
- methods: Array<HttpMethod>;
346
- /**
347
- * Path to the useQuery that will be used to do the useQuery functionality.
348
- * It will be used as `import { useQuery } from '${importPath}'`.
349
- * It allows both relative and absolute path.
350
- * the path will be applied as is, so relative path should be based on the file being generated.
351
- * @default '@tanstack/react-query'
352
- */
353
- importPath?: string;
354
- };
355
- type QueryOptions = object;
356
- type Mutate = {
357
- /**
358
- * Define the way of passing through the queryParams, headerParams and data.
359
- * @default `'hook'`
360
- */
361
- variablesType: 'mutate' | 'hook';
362
- /**
363
- * Define which HttpMethods can be used for mutations
364
- * @default ['post', 'put', 'delete']
365
- */
366
- methods: Array<HttpMethod>;
367
- /**
368
- * Path to the useQuery that will be used to do the useQuery functionality.
369
- * It will be used as `import { useQuery } from '${importPath}'`.
370
- * It allows both relative and absolute path.
371
- * the path will be applied as is, so relative path should be based on the file being generated.
372
- * @default '@tanstack/react-query'
373
- */
374
- importPath?: string;
375
- };
376
- type Infinite = {
377
- /**
378
- * Specify the params key used for `pageParam`.
379
- * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
380
- * @default `'id'`
381
- */
382
- queryParam: string;
383
- /**
384
- * Which field of the data will be used, set it to undefined when no cursor is known.
385
- */
386
- cursorParam?: string | undefined;
387
- /**
388
- * The initial value, the value of the first page.
389
- * @default `0`
390
- */
391
- initialPageParam: unknown;
392
- };
393
- type Options = {
394
- output?: {
395
- /**
396
- * Output to save the @tanstack/query hooks.
397
- * @default `"hooks"`
398
- */
399
- path: string;
400
- /**
401
- * Name to be used for the `export * as {{exportAs}} from './'`
402
- */
403
- exportAs?: string;
404
- /**
405
- * Add an extension to the generated imports and exports, default it will not use an extension
406
- */
407
- extName?: KubbFile.Extname;
408
- /**
409
- * Define what needs to exported, here you can also disable the export of barrel files
410
- * @default `'barrel'`
411
- */
412
- exportType?: 'barrel' | 'barrelNamed' | false;
413
- };
414
- /**
415
- * Group the @tanstack/query hooks based on the provided name.
416
- */
417
- group?: {
418
- /**
419
- * Tag will group based on the operation tag inside the Swagger file
420
- */
421
- type: 'tag';
422
- /**
423
- * Relative path to save the grouped @tanstack/query hooks.
424
- *
425
- * `{{tag}}` will be replaced by the current tagName.
426
- * @example `${output}/{{tag}}Controller` => `hooks/PetController`
427
- * @default `${output}/{{tag}}Controller`
428
- */
429
- output?: string;
430
- /**
431
- * Name to be used for the `export * as {{exportAs}} from './`
432
- * @default `"{{tag}}Hooks"`
433
- */
434
- exportAs?: string;
435
- };
436
- client?: {
437
- /**
438
- * Path to the client that will be used to do the API calls.
439
- * It will be used as `import client from '${client.importPath}'`.
440
- * It allows both relative and absolute path.
441
- * the path will be applied as is, so relative path should be based on the file being generated.
442
- * @default '@kubb/plugin-client/client'
443
- */
444
- importPath?: string;
445
- };
446
- /**
447
- * ReturnType that needs to be used when calling client().
448
- *
449
- * `Data` will return ResponseConfig[data].
450
- *
451
- * `Full` will return ResponseConfig.
452
- * @default `'data'`
453
- * @private
454
- */
455
- /**
456
- * ReturnType that needs to be used when calling client().
457
- *
458
- * `Data` will return ResponseConfig[data].
459
- *
460
- * `Full` will return ResponseConfig.
461
- * @default `'data'`
462
- * @private
463
- */
464
- dataReturnType?: 'data' | 'full';
465
- /**
466
- * How to pass your pathParams.
467
- *
468
- * `object` will return the pathParams as an object.
469
- *
470
- * `inline` will return the pathParams as comma separated params.
471
- * @default `'inline'`
472
- * @private
473
- */
474
- pathParamsType?: 'object' | 'inline';
475
- /**
476
- * Which parser can be used before returning the data to `@tanstack/query`.
477
- * `'zod'` will use `@kubb/plugin-zod` to parse the data.
478
- */
479
- parser?: 'zod';
480
- /**
481
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
482
- */
483
- exclude?: Array<Exclude>;
484
- /**
485
- * Array containing include parameters to include tags/operations/methods/paths.
486
- */
487
- include?: Array<Include>;
488
- /**
489
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
490
- */
491
- override?: Array<Override<ResolvedOptions>>;
492
- /**
493
- * When set, an infiniteQuery hooks will be added.
494
- */
495
- infinite?: Partial<Infinite> | false;
496
- /**
497
- * When set, a suspenseQuery hooks will be added.
498
- */
499
- suspense?: Partial<Suspense> | false;
500
- /**
501
- * Override some useQuery behaviours.
502
- */
503
- query?: Partial<Query> | false;
504
- queryOptions?: Partial<QueryOptions> | false;
505
- /**
506
- * Override some useMutation behaviours.
507
- */
508
- mutate?: Mutate | false;
509
- transformers?: {
510
- /**
511
- * Customize the names based on the type that is provided by the plugin.
512
- */
513
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
514
- };
515
- /**
516
- * Make it possible to override one of the templates
517
- */
518
- templates?: Partial<Templates>;
519
- };
520
- type ResolvedOptions = {
521
- client: Required<NonNullable<PluginReactQuery['options']['client']>>;
522
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>;
523
- pathParamsType: NonNullable<PluginReactQuery['options']['pathParamsType']>;
524
- parser: PluginReactQuery['options']['parser'];
525
- /**
526
- * Only used of infinite
527
- */
528
- infinite: Infinite | false;
529
- suspense: Suspense | false;
530
- query: Query | false;
531
- queryOptions: QueryOptions | false;
532
- mutate: Mutate | false;
533
- templates: NonNullable<Templates>;
534
- };
535
- type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, never, ResolvePathOptions>;
536
-
537
- export { Mutation as M, type Options as O, type PluginReactQuery as P, Query$1 as Q, QueryKey as a, QueryOptions$1 as b };