@kubb/plugin-client 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (63) hide show
  1. package/README.md +13 -4
  2. package/client.ts +2 -2
  3. package/dist/chunk-54CFYFPX.js +176 -0
  4. package/dist/chunk-54CFYFPX.js.map +1 -0
  5. package/dist/chunk-HGQQGWKN.js +130 -0
  6. package/dist/chunk-HGQQGWKN.js.map +1 -0
  7. package/dist/chunk-HUIJQCWL.cjs +185 -0
  8. package/dist/chunk-HUIJQCWL.cjs.map +1 -0
  9. package/dist/chunk-NEK3OJBX.cjs +133 -0
  10. package/dist/chunk-NEK3OJBX.cjs.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 +17 -0
  24. package/dist/generators.cjs.map +1 -0
  25. package/dist/generators.d.cts +9 -0
  26. package/dist/generators.d.ts +9 -0
  27. package/dist/generators.js +4 -0
  28. package/dist/generators.js.map +1 -0
  29. package/dist/index.cjs +11 -156
  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 -161
  34. package/dist/index.js.map +1 -1
  35. package/dist/types-xPfBu1CW.d.cts +96 -0
  36. package/dist/types-xPfBu1CW.d.ts +96 -0
  37. package/package.json +21 -16
  38. package/src/components/Client.tsx +110 -211
  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 +67 -0
  50. package/src/generators/index.ts +2 -0
  51. package/src/generators/operationsGenerator.tsx +26 -0
  52. package/src/plugin.ts +23 -40
  53. package/src/types.ts +24 -50
  54. package/dist/chunk-W57BRY5O.js +0 -201
  55. package/dist/chunk-W57BRY5O.js.map +0 -1
  56. package/dist/chunk-W7F5CMU6.cjs +0 -201
  57. package/dist/chunk-W7F5CMU6.cjs.map +0 -1
  58. package/dist/types-xK4X9e5d.d.cts +0 -228
  59. package/dist/types-xK4X9e5d.d.ts +0 -228
  60. package/src/OperationGenerator.tsx +0 -65
  61. package/src/components/__snapshots__/Client/showPetById.ts +0 -11
  62. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  63. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
@@ -1,228 +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
- /**
188
- * ReturnType that needs to be used when calling client().
189
- *
190
- * `Data` will return ResponseConfig[data].
191
- *
192
- * `Full` will return ResponseConfig.
193
- * @default `'data'`
194
- * @private
195
- */
196
- dataReturnType?: 'data' | 'full';
197
- /**
198
- * How to pass your pathParams.
199
- *
200
- * `object` will return the pathParams as an object.
201
- *
202
- * `inline` will return the pathParams as comma separated params.
203
- * @default `'inline'`
204
- * @private
205
- */
206
- pathParamsType?: 'object' | 'inline';
207
- transformers?: {
208
- /**
209
- * Customize the names based on the type that is provided by the plugin.
210
- */
211
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
212
- };
213
- /**
214
- * Make it possible to override one of the templates
215
- */
216
- templates?: Partial<Templates>;
217
- };
218
- type ResolvedOptions = {
219
- extName: KubbFile.Extname | undefined;
220
- baseURL: string | undefined;
221
- client: Required<NonNullable<Options['client']>>;
222
- dataReturnType: NonNullable<Options['dataReturnType']>;
223
- pathParamsType: NonNullable<Options['pathParamsType']>;
224
- templates: NonNullable<Templates>;
225
- };
226
- type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
227
-
228
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
@@ -1,65 +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 { 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 class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {
12
- async all(operations: Operation[], _operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {
13
- const { pluginManager, oas, plugin, mode } = this.context
14
-
15
- const root = createRoot({
16
- logger: pluginManager.logger,
17
- })
18
-
19
- const templates = {
20
- operations: Operations.templates,
21
- client: Client.templates,
22
- ...this.options.templates,
23
- }
24
-
25
- root.render(
26
- <App pluginManager={pluginManager} plugin={plugin} mode={mode}>
27
- <Oas oas={oas} operations={operations} generator={this}>
28
- {templates.operations && <Operations.File baseURL={this.options.baseURL} templates={templates.operations} />}
29
- </Oas>
30
- </App>,
31
- )
32
-
33
- return root.files
34
- }
35
-
36
- async operation(operation: Operation, options: PluginClient['resolvedOptions']): OperationMethodResult<FileMeta> {
37
- const { oas, pluginManager, plugin, mode } = this.context
38
-
39
- const root = createRoot({
40
- logger: pluginManager.logger,
41
- })
42
-
43
- const templates = {
44
- operations: Operations.templates,
45
- client: Client.templates,
46
- ...options.templates,
47
- }
48
-
49
- if (!templates.client) {
50
- return []
51
- }
52
-
53
- root.render(
54
- <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
55
- <Oas oas={oas} operations={[operation]} generator={this}>
56
- <Oas.Operation operation={operation}>
57
- <Client.File baseURL={this.options.baseURL} templates={templates.client} />
58
- </Oas.Operation>
59
- </Oas>
60
- </App>,
61
- )
62
-
63
- return root.files
64
- }
65
- }
@@ -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
- }