@kubb/plugin-swr 0.0.0-canary-20241104172400

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/chunk-2KDZWGWG.js +342 -0
  4. package/dist/chunk-2KDZWGWG.js.map +1 -0
  5. package/dist/chunk-64KLXAGI.cjs +237 -0
  6. package/dist/chunk-64KLXAGI.cjs.map +1 -0
  7. package/dist/chunk-AFAHUG3Q.cjs +348 -0
  8. package/dist/chunk-AFAHUG3Q.cjs.map +1 -0
  9. package/dist/chunk-T6K6P5I7.js +234 -0
  10. package/dist/chunk-T6K6P5I7.js.map +1 -0
  11. package/dist/components.cjs +28 -0
  12. package/dist/components.cjs.map +1 -0
  13. package/dist/components.d.cts +95 -0
  14. package/dist/components.d.ts +95 -0
  15. package/dist/components.js +3 -0
  16. package/dist/components.js.map +1 -0
  17. package/dist/generators.cjs +17 -0
  18. package/dist/generators.cjs.map +1 -0
  19. package/dist/generators.d.cts +11 -0
  20. package/dist/generators.d.ts +11 -0
  21. package/dist/generators.js +4 -0
  22. package/dist/generators.js.map +1 -0
  23. package/dist/index.cjs +127 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +10 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +120 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/types-AhGZx7jH.d.cts +272 -0
  30. package/dist/types-AhGZx7jH.d.ts +272 -0
  31. package/package.json +104 -0
  32. package/src/components/Mutation.tsx +129 -0
  33. package/src/components/MutationKey.tsx +54 -0
  34. package/src/components/Query.tsx +175 -0
  35. package/src/components/QueryKey.tsx +83 -0
  36. package/src/components/QueryOptions.tsx +116 -0
  37. package/src/components/index.ts +5 -0
  38. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +49 -0
  39. package/src/generators/__snapshots__/clientGetImportPath.ts +49 -0
  40. package/src/generators/__snapshots__/clientPostImportPath.ts +32 -0
  41. package/src/generators/__snapshots__/findByTags.ts +49 -0
  42. package/src/generators/__snapshots__/findByTagsObject.ts +49 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +49 -0
  44. package/src/generators/__snapshots__/findByTagsWithZod.ts +49 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +34 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +32 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +34 -0
  49. package/src/generators/index.ts +2 -0
  50. package/src/generators/mutationGenerator.tsx +117 -0
  51. package/src/generators/queryGenerator.tsx +127 -0
  52. package/src/index.ts +4 -0
  53. package/src/plugin.ts +141 -0
  54. package/src/types.ts +126 -0
package/src/types.ts ADDED
@@ -0,0 +1,126 @@
1
+ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
+ import type { HttpMethod, Operation } from '@kubb/oas'
3
+ import type { PluginClient } from '@kubb/plugin-client'
4
+ import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
+ import type { PluginReactQuery } from '@kubb/plugin-react-query'
6
+
7
+ type TransformerProps = {
8
+ operation: Operation
9
+ schemas: OperationSchemas
10
+ }
11
+
12
+ export type Transformer = (props: TransformerProps) => unknown[]
13
+
14
+ /**
15
+ * Customize the queryKey
16
+ */
17
+ type QueryKey = Transformer
18
+
19
+ /**
20
+ * Customize the mutationKey
21
+ */
22
+ type MutationKey = Transformer
23
+
24
+ type Query = {
25
+ /**
26
+ * Define which HttpMethods can be used for queries
27
+ * @default ['get']
28
+ */
29
+ methods?: Array<HttpMethod>
30
+ /**
31
+ * Path to the useQuery that will be used to do the useQuery functionality.
32
+ * It will be used as `import { useQuery } from '${importPath}'`.
33
+ * It allows both relative and absolute path.
34
+ * the path will be applied as is, so relative path should be based on the file being generated.
35
+ * @default 'swr'
36
+ */
37
+ importPath?: string
38
+ }
39
+
40
+ type Mutation = {
41
+ /**
42
+ * Define which HttpMethods can be used for queries
43
+ * @default ['post', 'put', 'delete', 'patch']
44
+ */
45
+ methods?: Array<HttpMethod>
46
+ /**
47
+ * Path to the useQuery that will be used to do the useQuery functionality.
48
+ * It will be used as `import { useQuery } from '${importPath}'`.
49
+ * It allows both relative and absolute path.
50
+ * the path will be applied as is, so relative path should be based on the file being generated.
51
+ * @default 'swr/mutation'
52
+ */
53
+ importPath?: string
54
+ }
55
+
56
+ export type Options = {
57
+ /**
58
+ * Specify the export location for the files and define the behavior of the output
59
+ * @default { path: 'hooks', barrelType: 'named' }
60
+ */
61
+ output?: Output
62
+ /**
63
+ * Group the SWR hooks based on the provided name.
64
+ */
65
+ group?: Group
66
+ /**
67
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
68
+ */
69
+ exclude?: Array<Exclude>
70
+ /**
71
+ * Array containing include parameters to include tags/operations/methods/paths.
72
+ */
73
+ include?: Array<Include>
74
+ /**
75
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
76
+ */
77
+ override?: Array<Override<ResolvedOptions>>
78
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>
79
+ queryKey?: QueryKey
80
+ query?: Query | false
81
+ mutationKey?: MutationKey
82
+ mutation?: Mutation | false
83
+ /**
84
+ * How to pass your params
85
+ * - 'object' will return the params and pathParams as an object.
86
+ * - 'inline' will return the params as comma separated params.
87
+ * @default 'inline'
88
+ */
89
+ paramsType?: 'object' | 'inline'
90
+ /**
91
+ * How to pass your pathParams.
92
+ * - 'object' will return the pathParams as an object.
93
+ * - 'inline' will return the pathParams as comma separated params.
94
+ * @default 'inline'
95
+ */
96
+ pathParamsType?: PluginClient['options']['pathParamsType']
97
+ /**
98
+ * Which parser should be used before returning the data to `swr`.
99
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
100
+ */
101
+ parser?: PluginClient['options']['parser']
102
+ transformers?: {
103
+ /**
104
+ * Customize the names based on the type that is provided by the plugin.
105
+ */
106
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
107
+ }
108
+ /**
109
+ * Define some generators next to the swr generators
110
+ */
111
+ generators?: Array<Generator<PluginSwr>>
112
+ }
113
+
114
+ type ResolvedOptions = {
115
+ output: Output
116
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & { baseURL?: string }
117
+ parser: Required<NonNullable<Options['parser']>>
118
+ queryKey: QueryKey | undefined
119
+ query: NonNullable<Required<Query>> | false
120
+ mutationKey: MutationKey | undefined
121
+ mutation: NonNullable<Required<Mutation>> | false
122
+ paramsType: NonNullable<Options['paramsType']>
123
+ pathParamsType: NonNullable<Options['pathParamsType']>
124
+ }
125
+
126
+ export type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>