@kubb/plugin-client 3.0.0-alpha.3 → 3.0.0-alpha.31

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 (64) hide show
  1. package/README.md +13 -4
  2. package/client.ts +2 -2
  3. package/dist/chunk-AM26RQMP.cjs +229 -0
  4. package/dist/chunk-AM26RQMP.cjs.map +1 -0
  5. package/dist/chunk-AXJDH3LY.js +219 -0
  6. package/dist/chunk-AXJDH3LY.js.map +1 -0
  7. package/dist/chunk-X73EA6RA.cjs +133 -0
  8. package/dist/chunk-X73EA6RA.cjs.map +1 -0
  9. package/dist/chunk-YYBNZBCI.js +130 -0
  10. package/dist/chunk-YYBNZBCI.js.map +1 -0
  11. package/dist/client.cjs +16 -7
  12. package/dist/client.cjs.map +1 -1
  13. package/dist/client.d.cts +2 -2
  14. package/dist/client.d.ts +2 -2
  15. package/dist/client.js +5 -6
  16. package/dist/client.js.map +1 -1
  17. package/dist/components.cjs +11 -4
  18. package/dist/components.cjs.map +1 -1
  19. package/dist/components.d.cts +37 -7
  20. package/dist/components.d.ts +37 -7
  21. package/dist/components.js +2 -8
  22. package/dist/components.js.map +1 -1
  23. package/dist/generators.cjs +21 -0
  24. package/dist/generators.cjs.map +1 -0
  25. package/dist/generators.d.cts +11 -0
  26. package/dist/generators.d.ts +11 -0
  27. package/dist/generators.js +4 -0
  28. package/dist/generators.js.map +1 -0
  29. package/dist/index.cjs +10 -137
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +1 -6
  32. package/dist/index.d.ts +1 -6
  33. package/dist/index.js +3 -143
  34. package/dist/index.js.map +1 -1
  35. package/dist/types-B3S8Ek-T.d.cts +83 -0
  36. package/dist/types-B3S8Ek-T.d.ts +83 -0
  37. package/package.json +22 -17
  38. package/src/components/Client.tsx +111 -212
  39. package/src/components/Operations.tsx +9 -75
  40. package/src/generators/__snapshots__/deletePet.ts +13 -0
  41. package/src/generators/__snapshots__/deletePetObject.ts +15 -0
  42. package/src/generators/__snapshots__/findByTags.ts +13 -0
  43. package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
  44. package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
  45. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
  46. package/src/generators/__snapshots__/importPath.ts +13 -0
  47. package/src/generators/__snapshots__/operations.ts +82 -0
  48. package/src/generators/__snapshots__/updatePetById.ts +12 -0
  49. package/src/generators/clientGenerator.tsx +66 -0
  50. package/src/generators/groupedClientGenerator.tsx +70 -0
  51. package/src/generators/index.ts +3 -0
  52. package/src/generators/operationsGenerator.tsx +26 -0
  53. package/src/plugin.ts +30 -51
  54. package/src/types.ts +29 -74
  55. package/dist/chunk-W57BRY5O.js +0 -201
  56. package/dist/chunk-W57BRY5O.js.map +0 -1
  57. package/dist/chunk-W7F5CMU6.cjs +0 -201
  58. package/dist/chunk-W7F5CMU6.cjs.map +0 -1
  59. package/dist/types-C14AAtNX.d.cts +0 -233
  60. package/dist/types-C14AAtNX.d.ts +0 -233
  61. package/src/OperationGenerator.tsx +0 -29
  62. package/src/components/__snapshots__/Client/showPetById.ts +0 -11
  63. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  64. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
@@ -1,233 +0,0 @@
1
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
- import * as KubbFile from '@kubb/fs/types';
3
- import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
4
- import { URLPath } from '@kubb/core/utils';
5
- import { HttpMethod, Operation } from '@kubb/oas';
6
- import { KubbNode, Params } from '@kubb/react';
7
- import { ComponentType, ComponentProps } from 'react';
8
-
9
- type TemplateProps$1 = {
10
- /**
11
- * Name of the function
12
- */
13
- name: string;
14
- /**
15
- * Parameters/options/props that need to be used
16
- */
17
- params: Params;
18
- /**
19
- * Generics that needs to be added for TypeScript
20
- */
21
- generics?: string;
22
- /**
23
- * ReturnType(see async for adding Promise type)
24
- */
25
- returnType?: string;
26
- /**
27
- * Options for JSdocs
28
- */
29
- JSDoc?: {
30
- comments: string[];
31
- };
32
- client: {
33
- baseURL: string | undefined;
34
- generics: string | string[];
35
- method: HttpMethod;
36
- path: URLPath;
37
- dataReturnType: PluginClient['options']['dataReturnType'];
38
- withQueryParams: boolean;
39
- withData: boolean;
40
- withHeaders: boolean;
41
- contentType: string;
42
- };
43
- };
44
- declare function Template$1({ name, generics, returnType, params, JSDoc, client }: TemplateProps$1): KubbNode;
45
- type RootTemplateProps$1 = {
46
- children?: React.ReactNode;
47
- };
48
- declare function RootTemplate$1({ children }: RootTemplateProps$1): JSX.Element;
49
- declare const defaultTemplates$1: {
50
- readonly default: typeof Template$1;
51
- readonly root: typeof RootTemplate$1;
52
- };
53
- type Templates$2 = Partial<typeof defaultTemplates$1>;
54
- type ClientProps = {
55
- baseURL: string | undefined;
56
- /**
57
- * This will make it possible to override the default behaviour.
58
- */
59
- Template?: ComponentType<ComponentProps<typeof Template$1>>;
60
- };
61
- declare function Client({ baseURL, Template }: ClientProps): KubbNode;
62
- declare namespace Client {
63
- var File: ({ baseURL, ...props }: FileProps$1) => KubbNode;
64
- var templates: {
65
- readonly default: typeof Template$1;
66
- readonly root: typeof RootTemplate$1;
67
- };
68
- }
69
- type FileProps$1 = {
70
- baseURL: string | undefined;
71
- /**
72
- * This will make it possible to override the default behaviour.
73
- */
74
- templates?: Templates$2;
75
- };
76
-
77
- type TemplateProps = {
78
- /**
79
- * Name of the function
80
- */
81
- name: string;
82
- operations: Operation[];
83
- baseURL: string | undefined;
84
- };
85
- declare function Template({ name, operations }: TemplateProps): KubbNode;
86
- type RootTemplateProps = {
87
- children?: React.ReactNode;
88
- };
89
- declare function RootTemplate({ children }: RootTemplateProps): JSX.Element;
90
- declare const defaultTemplates: {
91
- readonly default: typeof Template;
92
- readonly root: typeof RootTemplate;
93
- };
94
- type Templates$1 = Partial<typeof defaultTemplates>;
95
- type Props = {
96
- baseURL: string | undefined;
97
- /**
98
- * This will make it possible to override the default behaviour.
99
- */
100
- Template?: ComponentType<ComponentProps<typeof Template>>;
101
- };
102
- declare function Operations({ baseURL, Template }: Props): KubbNode;
103
- declare namespace Operations {
104
- var File: ({ baseURL, ...props }: FileProps) => KubbNode;
105
- var templates: {
106
- readonly default: typeof Template;
107
- readonly root: typeof RootTemplate;
108
- };
109
- }
110
- type FileProps = {
111
- baseURL: string | undefined;
112
- /**
113
- * This will make it possible to override the default behaviour.
114
- */
115
- templates?: Templates$1;
116
- };
117
-
118
- type Templates = {
119
- operations?: typeof Operations.templates | false;
120
- client?: typeof Client.templates | false;
121
- };
122
- type Options = {
123
- output?: {
124
- /**
125
- * Output to save the clients.
126
- * @default `"clients"``
127
- */
128
- path: string;
129
- /**
130
- * Name to be used for the `export * as {{exportAs}} from './'`
131
- */
132
- exportAs?: string;
133
- /**
134
- * Add an extension to the generated imports and exports, default it will not use an extension
135
- */
136
- extName?: KubbFile.Extname;
137
- /**
138
- * Define what needs to exported, here you can also disable the export of barrel files
139
- * @default `'barrel'`
140
- */
141
- exportType?: 'barrel' | 'barrelNamed' | false;
142
- };
143
- /**
144
- * Group the clients based on the provided name.
145
- */
146
- group?: {
147
- /**
148
- * Tag will group based on the operation tag inside the Swagger file
149
- */
150
- type: 'tag';
151
- /**
152
- * Relative path to save the grouped clients.
153
- *
154
- * `{{tag}}` will be replaced by the current tagName.
155
- * @example `${output}/{{tag}}Controller` => `clients/PetController`
156
- * @default `${output}/{{tag}}Controller`
157
- */
158
- output?: string;
159
- /**
160
- * Name to be used for the `export * as {{exportAs}} from './`
161
- * @default `"{{tag}}Service"`
162
- */
163
- exportAs?: string;
164
- };
165
- /**
166
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
167
- */
168
- exclude?: Array<Exclude>;
169
- /**
170
- * Array containing include parameters to include tags/operations/methods/paths.
171
- */
172
- include?: Array<Include>;
173
- /**
174
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
175
- */
176
- override?: Array<Override<ResolvedOptions>>;
177
- client?: {
178
- /**
179
- * Path to the client import path that will be used to do the API calls.
180
- * It will be used as `import client from '${client.importPath}'`.
181
- * It allows both relative and absolute path.
182
- * the path will be applied as is, so relative path should be based on the file being generated.
183
- * @default '@kubb/plugin-client/client'
184
- */
185
- importPath?: string;
186
- /**
187
- * Define which HttpMethods can be used for queries
188
- * @default ['get', 'post', 'put', 'delete']
189
- */
190
- methods: Array<HttpMethod>;
191
- };
192
- /**
193
- * ReturnType that needs to be used when calling client().
194
- *
195
- * `Data` will return ResponseConfig[data].
196
- *
197
- * `Full` will return ResponseConfig.
198
- * @default `'data'`
199
- * @private
200
- */
201
- dataReturnType?: 'data' | 'full';
202
- /**
203
- * How to pass your pathParams.
204
- *
205
- * `object` will return the pathParams as an object.
206
- *
207
- * `inline` will return the pathParams as comma separated params.
208
- * @default `'inline'`
209
- * @private
210
- */
211
- pathParamsType?: 'object' | 'inline';
212
- transformers?: {
213
- /**
214
- * Customize the names based on the type that is provided by the plugin.
215
- */
216
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
217
- };
218
- /**
219
- * Make it possible to override one of the templates
220
- */
221
- templates?: Partial<Templates>;
222
- };
223
- type ResolvedOptions = {
224
- extName: KubbFile.Extname | undefined;
225
- baseURL: string | undefined;
226
- client: Required<NonNullable<Options['client']>>;
227
- dataReturnType: NonNullable<Options['dataReturnType']>;
228
- pathParamsType: NonNullable<Options['pathParamsType']>;
229
- templates: NonNullable<Templates>;
230
- };
231
- type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
232
-
233
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
@@ -1,29 +0,0 @@
1
- import { createReactParser, 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 { Client, Operations } from './components/index.ts'
6
-
7
- import type { Operation } from '@kubb/oas'
8
- import type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'
9
- import type { FileMeta, PluginClient } from './types.ts'
10
-
11
- export const clientParser = createReactParser<PluginClient>({
12
- name: 'plugin-client',
13
- Operations({ options }) {
14
- if (!options.templates.operations) {
15
- return null
16
- }
17
-
18
- return <Operations.File baseURL={options.baseURL} templates={options.templates.operations} />
19
- },
20
- Operation({ options, operation }) {
21
- const isEnabled = options.client.methods.some((method) => operation.method === method)
22
-
23
- if (!options.templates.client || !isEnabled) {
24
- return null
25
- }
26
-
27
- return <Client.File baseURL={options.baseURL} templates={options.templates.client} />
28
- },
29
- })
@@ -1,11 +0,0 @@
1
- /**
2
- * @summary Info for a specific pet
3
- * @link /pets/:pet_id
4
- */
5
- export async function showPetById(
6
- { petId, testId }: { petId: ShowPetByIdPathParams['pet_id']; testId: ShowPetByIdPathParams['testId'] },
7
- options: Partial<Parameters<typeof client>[0]> = {},
8
- ): Promise<ResponseConfig<ShowPetByIdQueryResponse>['data']> {
9
- const res = await client<ShowPetByIdQueryResponse>({ method: 'get', url: `/pets/${petId}`, ...options })
10
- return res.data
11
- }
@@ -1,6 +0,0 @@
1
- export const operations = {
2
- showPetById: {
3
- path: '/pets/:pet_id',
4
- method: 'get',
5
- },
6
- } as const
@@ -1,15 +0,0 @@
1
- /**
2
- * @summary Info for a specific pet
3
- * @link /pets/:pet_id */
4
-
5
- export async function showPetById(
6
- { petId, testId }: ShowPetByIdPathParams,
7
- options: Partial<Parameters<typeof client>[0]> = {},
8
- ): Promise<ResponseConfig<ShowPetByIdQueryResponse>['data']> {
9
- const res = await client<ShowPetByIdQueryResponse>({
10
- method: 'get',
11
- url: `/pets/${petId}`,
12
- ...options,
13
- })
14
- return res.data
15
- }