@kubb/plugin-client 3.0.0-alpha.3 → 3.0.0-alpha.30
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.
- package/README.md +13 -4
- package/client.ts +2 -2
- package/dist/chunk-ELPE4OER.cjs +183 -0
- package/dist/chunk-ELPE4OER.cjs.map +1 -0
- package/dist/chunk-RQSMSP6A.js +174 -0
- package/dist/chunk-RQSMSP6A.js.map +1 -0
- package/dist/chunk-X73EA6RA.cjs +133 -0
- package/dist/chunk-X73EA6RA.cjs.map +1 -0
- package/dist/chunk-YYBNZBCI.js +130 -0
- package/dist/chunk-YYBNZBCI.js.map +1 -0
- package/dist/client.cjs +16 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +5 -6
- package/dist/client.js.map +1 -1
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +37 -7
- package/dist/components.d.ts +37 -7
- package/dist/components.js +2 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +10 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +3 -143
- package/dist/index.js.map +1 -1
- package/dist/types-Bc-y9yTU.d.cts +100 -0
- package/dist/types-Bc-y9yTU.d.ts +100 -0
- package/package.json +22 -17
- package/src/components/Client.tsx +111 -212
- package/src/components/Operations.tsx +9 -75
- package/src/generators/__snapshots__/deletePet.ts +13 -0
- package/src/generators/__snapshots__/deletePetObject.ts +15 -0
- package/src/generators/__snapshots__/findByTags.ts +13 -0
- package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
- package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
- package/src/generators/__snapshots__/importPath.ts +13 -0
- package/src/generators/__snapshots__/operations.ts +82 -0
- package/src/generators/__snapshots__/updatePetById.ts +12 -0
- package/src/generators/clientGenerator.tsx +66 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +26 -0
- package/src/plugin.ts +23 -42
- package/src/types.ts +27 -55
- package/dist/chunk-W57BRY5O.js +0 -201
- package/dist/chunk-W57BRY5O.js.map +0 -1
- package/dist/chunk-W7F5CMU6.cjs +0 -201
- package/dist/chunk-W7F5CMU6.cjs.map +0 -1
- package/dist/types-C14AAtNX.d.cts +0 -233
- package/dist/types-C14AAtNX.d.ts +0 -233
- package/src/OperationGenerator.tsx +0 -29
- package/src/components/__snapshots__/Client/showPetById.ts +0 -11
- package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
- package/src/components/__snapshots__/Query/showPetById.ts +0 -15
package/dist/types-C14AAtNX.d.ts
DELETED
|
@@ -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,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
|
-
}
|