@kubb/plugin-client 5.12.0 → 6.0.0
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 +1 -1
- package/dist/client-Dq0z61hu.d.ts +554 -0
- package/dist/index.cjs +1378 -784
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -74
- package/dist/index.d.ts +114 -74
- package/dist/index.js +1376 -786
- package/dist/index.js.map +1 -1
- package/dist/serializers-BRgfPGr1.d.ts +119 -0
- package/dist/{standardSchema-BShJWz2i.d.ts → standardSchema-CGuiSK7F.d.ts} +15 -37
- package/dist/templates/client.d.ts +3 -2
- package/dist/templates/core.d.ts +3 -3
- package/dist/templates/mediaTypes/formData.d.ts +5 -0
- package/dist/templates/mediaTypes/urlencoded.d.ts +5 -0
- package/dist/templates/mediaTypes.d.ts +2 -0
- package/dist/templates/serializers/cookies.d.ts +5 -0
- package/dist/templates/serializers/headers.d.ts +5 -0
- package/dist/templates/serializers/path.d.ts +5 -0
- package/dist/templates/serializers/pathStyles.d.ts +5 -0
- package/dist/templates/serializers/query.d.ts +5 -0
- package/dist/templates/serializers/queryStyles.d.ts +14 -0
- package/dist/templates/serializers.d.ts +2 -2
- package/dist/templates/sse.d.ts +20 -113
- package/dist/templates/standardSchema.d.ts +1 -1
- package/docs/guides/authentication.md +9 -1
- package/docs/guides/migrate-to-v6.md +139 -0
- package/docs/guides/validate-requests-and-responses.md +8 -3
- package/docs/guides/write-your-client.md +117 -11
- package/docs/options.md +2 -2
- package/docs/overview.md +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +6 -5
- package/src/builders/callConfig.ts +80 -0
- package/src/builders/contentType.ts +35 -0
- package/src/builders/generics.ts +29 -0
- package/src/builders/operationBody.ts +43 -0
- package/src/builders/operationData.ts +64 -0
- package/src/builders/returnStatement.ts +103 -0
- package/src/builders/security.ts +125 -0
- package/src/builders/signature.ts +71 -0
- package/src/builders/styles.ts +94 -0
- package/src/builders/validator.ts +84 -0
- package/src/builders/validatorOptions.ts +53 -0
- package/src/clientTypes.ts +195 -0
- package/src/components/ClientRuntime.tsx +97 -0
- package/src/components/Operation.tsx +72 -0
- package/src/components/SdkClient.tsx +100 -0
- package/src/components/SdkFacade.tsx +35 -0
- package/src/generators/clientGenerator.tsx +91 -6
- package/src/generators/sdkGenerator.tsx +209 -0
- package/src/index.ts +3 -1
- package/src/macros.ts +9 -0
- package/src/plugin.ts +7 -8
- package/src/resolver.ts +28 -0
- package/src/setup.ts +90 -0
- package/src/types.ts +4 -2
- package/templates/client.ts +2 -1
- package/templates/core.ts +735 -286
- package/templates/mediaTypes/formData.ts +59 -0
- package/templates/mediaTypes/urlencoded.ts +33 -0
- package/templates/mediaTypes.ts +147 -0
- package/templates/serializers/cookies.ts +58 -0
- package/templates/serializers/headers.ts +35 -0
- package/templates/serializers/path.ts +19 -0
- package/templates/serializers/pathStyles.ts +27 -0
- package/templates/serializers/query.ts +21 -0
- package/templates/serializers/queryStyles.ts +107 -0
- package/templates/serializers.ts +48 -364
- package/templates/sse.ts +87 -178
- package/templates/standardSchema.ts +16 -37
- package/dist/client-BxO6Dygu.d.ts +0 -355
- package/dist/serializers-Ds8zZwOO.d.ts +0 -190
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,71 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
-
import "@kubb/plugin-zod";
|
|
3
2
|
import { ResolverTs } from "@kubb/plugin-ts";
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the value a generated operation function resolves to.
|
|
5
|
+
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
6
|
+
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
7
|
+
* so callers can inspect `error`.
|
|
8
|
+
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
9
|
+
* helper. Backs `@kubb/plugin-client`.
|
|
10
|
+
*/
|
|
11
|
+
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
12
|
+
/**
|
|
13
|
+
* The per-operation type names a generated client references: the grouped input, the per-status
|
|
14
|
+
* responses record its `RequestResult` is keyed on, and the headers each response declares.
|
|
15
|
+
*/
|
|
16
|
+
type OperationTypeNames = {
|
|
17
|
+
response: {
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the name of the operation's grouped `{ body, path, query, headers, cookies }` input type.
|
|
20
|
+
*/
|
|
21
|
+
options(node: ast.OperationNode): string;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the name of the operation's per-status responses record type.
|
|
24
|
+
*/
|
|
25
|
+
responses(node: ast.OperationNode): string;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the name of the type of the headers one response declares. Left out, results keep untyped headers.
|
|
28
|
+
*/
|
|
29
|
+
headers?(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Where a generated client sources its operation types, plus the resolver and output the file
|
|
34
|
+
* declaring them is resolved with.
|
|
35
|
+
*/
|
|
36
|
+
type OperationTypeSource = OperationTypeNames & {
|
|
37
|
+
/**
|
|
38
|
+
* `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
|
|
39
|
+
*/
|
|
40
|
+
resolver: ResolverTs;
|
|
41
|
+
/**
|
|
42
|
+
* The supplying plugin's own `output`, when it configured one.
|
|
43
|
+
*/
|
|
44
|
+
output: Output | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The supplying plugin's own `group`, when it configured one.
|
|
47
|
+
*/
|
|
48
|
+
group: Group | undefined;
|
|
49
|
+
};
|
|
50
|
+
declare global {
|
|
51
|
+
namespace Kubb {
|
|
52
|
+
interface MemoRegistry {
|
|
53
|
+
operationTypes: OperationTypeSource;
|
|
54
|
+
/**
|
|
55
|
+
* Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
|
|
56
|
+
*/
|
|
57
|
+
zodTypes: unknown;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
4
61
|
/**
|
|
5
62
|
* Validator applied to the request and response using schemas from `@kubb/plugin-zod`.
|
|
6
63
|
* - `false`: no validation.
|
|
7
|
-
* - `'zod'`: validates the success (2xx) response body, and the error body
|
|
8
|
-
*
|
|
64
|
+
* - `'zod'`: validates the success (2xx) response body, and the error body of a non-2xx call, whether it
|
|
65
|
+
* throws or returns the error.
|
|
9
66
|
* - `{ request?: 'zod'; params?: 'zod'; response?: 'zod' }`: opt in per slot. `request` encodes the
|
|
10
67
|
* request body before the call; `params` validate the path, query, and header params;
|
|
11
|
-
* `response` validates the success response body and
|
|
68
|
+
* `response` validates the success response body and the error body.
|
|
12
69
|
*/
|
|
13
70
|
type ValidatorOptions = false | 'zod' | {
|
|
14
71
|
request?: 'zod';
|
|
@@ -21,15 +78,6 @@ type ValidatorOptions = false | 'zod' | {
|
|
|
21
78
|
* - `'flat'`: one class with every operation as a direct method.
|
|
22
79
|
*/
|
|
23
80
|
type Mode = 'tag' | 'flat';
|
|
24
|
-
/**
|
|
25
|
-
* Shape of the value a generated operation function resolves to.
|
|
26
|
-
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
27
|
-
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
28
|
-
* so callers can inspect `error`.
|
|
29
|
-
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
30
|
-
* helper. Backs `@kubb/plugin-client`.
|
|
31
|
-
*/
|
|
32
|
-
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
33
81
|
/**
|
|
34
82
|
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
35
83
|
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
|
@@ -59,7 +107,7 @@ type ResolverClient = Resolver & {
|
|
|
59
107
|
* response contract and one grouped options object. Each plugin extends this with its own
|
|
60
108
|
* `transport` field.
|
|
61
109
|
*/
|
|
62
|
-
type
|
|
110
|
+
type ClientOptions = OutputOptions & {
|
|
63
111
|
/**
|
|
64
112
|
* Skip operations matching at least one entry in the list.
|
|
65
113
|
*/
|
|
@@ -71,12 +119,12 @@ type Options$1 = OutputOptions & {
|
|
|
71
119
|
/**
|
|
72
120
|
* Apply a different options object to operations matching a pattern.
|
|
73
121
|
*/
|
|
74
|
-
override?: Array<Override<Omit<
|
|
122
|
+
override?: Array<Override<Omit<ClientResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
75
123
|
/**
|
|
76
|
-
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so
|
|
77
|
-
*
|
|
78
|
-
* Values containing a `${...}` interpolation are emitted as template literals in the generated
|
|
79
|
-
*
|
|
124
|
+
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so set one at runtime with
|
|
125
|
+
* `client.setConfig({ baseURL })`. The top-level server URL is not used, but an operation with path-level or operation-level `servers` calls it.
|
|
126
|
+
* Values containing a `${...}` interpolation are emitted as template literals in the generated client config, which keeps
|
|
127
|
+
* runtime environment reads dynamic.
|
|
80
128
|
*/
|
|
81
129
|
baseURL?: string;
|
|
82
130
|
/**
|
|
@@ -118,15 +166,17 @@ type Options$1 = OutputOptions & {
|
|
|
118
166
|
* // const api = new PetClient({ baseURL: 'https://api.example.com' })
|
|
119
167
|
* // await api.getPetById({ path: { petId: 1 } })
|
|
120
168
|
* ```
|
|
121
|
-
* @example Composed root that
|
|
169
|
+
* @example Composed root that shares one client with every tag client
|
|
122
170
|
* ```ts
|
|
123
171
|
* pluginFetch({ sdk: { name: 'petStore' } })
|
|
124
172
|
* // class PetStore {
|
|
173
|
+
* // readonly client: ClientInstance
|
|
125
174
|
* // readonly pet: PetClient
|
|
126
175
|
* // readonly store: StoreClient
|
|
127
176
|
* // constructor(config = {}) { ... }
|
|
128
177
|
* // }
|
|
129
178
|
* // const api = new PetStore({ baseURL })
|
|
179
|
+
* // api.client.interceptors.request.use(...) // applies to every tag
|
|
130
180
|
* // await api.pet.getPetById({ path: { petId: 1 } })
|
|
131
181
|
* ```
|
|
132
182
|
* @example Flat class with every operation as a direct method
|
|
@@ -139,7 +189,7 @@ type Options$1 = OutputOptions & {
|
|
|
139
189
|
sdk?: {
|
|
140
190
|
/**
|
|
141
191
|
* How the SDK groups operations.
|
|
142
|
-
* - `'tag'`: one class per tag
|
|
192
|
+
* - `'tag'`: one class per tag, such as `PetClient`. With `name`, a composed root shares one client with every tag client.
|
|
143
193
|
* - `'flat'`: one class named by `name`, with every operation as a direct method.
|
|
144
194
|
*
|
|
145
195
|
* @default 'tag'
|
|
@@ -147,7 +197,7 @@ type Options$1 = OutputOptions & {
|
|
|
147
197
|
mode?: Mode;
|
|
148
198
|
/**
|
|
149
199
|
* Name of the generated entry point, also the file name. With `mode: 'tag'` it emits a
|
|
150
|
-
* composed root class that
|
|
200
|
+
* composed root class that creates one client and shares it with every tag client. With
|
|
151
201
|
* `mode: 'flat'` it names the single class.
|
|
152
202
|
*/
|
|
153
203
|
name?: string;
|
|
@@ -164,19 +214,19 @@ type Options$1 = OutputOptions & {
|
|
|
164
214
|
/**
|
|
165
215
|
* The resolved options after defaults are applied.
|
|
166
216
|
*/
|
|
167
|
-
type
|
|
217
|
+
type ClientResolvedOptions = {
|
|
168
218
|
output: Output;
|
|
169
219
|
exclude: Array<Exclude>;
|
|
170
220
|
include: Array<Include> | undefined;
|
|
171
|
-
override: Array<Override<Omit<
|
|
221
|
+
override: Array<Override<Omit<ClientResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
172
222
|
group: Group | null;
|
|
173
|
-
baseURL:
|
|
223
|
+
baseURL: ClientOptions['baseURL'];
|
|
174
224
|
/**
|
|
175
225
|
* Module the generated operations import the client runtime from, used verbatim. Unset, they import the bundled `.kubb/client.ts`.
|
|
176
226
|
*/
|
|
177
227
|
importPath?: string;
|
|
178
228
|
throwOnErrorDefault: boolean;
|
|
179
|
-
validator: NonNullable<
|
|
229
|
+
validator: NonNullable<ClientOptions['validator']>;
|
|
180
230
|
returnType: ReturnTypeOption;
|
|
181
231
|
sdk: {
|
|
182
232
|
mode: Mode;
|
|
@@ -184,51 +234,6 @@ type ResolvedOptions$1 = {
|
|
|
184
234
|
} | undefined;
|
|
185
235
|
resolver: ResolverClient;
|
|
186
236
|
};
|
|
187
|
-
/**
|
|
188
|
-
* The two per-operation type names a generated client references: the grouped input and the
|
|
189
|
-
* per-status responses record its `RequestResult` is keyed on.
|
|
190
|
-
*/
|
|
191
|
-
type OperationTypeNames = {
|
|
192
|
-
response: {
|
|
193
|
-
/**
|
|
194
|
-
* Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.
|
|
195
|
-
*/
|
|
196
|
-
options(node: ast.OperationNode): string;
|
|
197
|
-
/**
|
|
198
|
-
* Resolves the name of the operation's per-status responses record type.
|
|
199
|
-
*/
|
|
200
|
-
responses(node: ast.OperationNode): string;
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Where a generated client sources its operation types, plus the resolver and output the file
|
|
205
|
-
* declaring them is resolved with.
|
|
206
|
-
*/
|
|
207
|
-
type OperationTypeSource = OperationTypeNames & {
|
|
208
|
-
/**
|
|
209
|
-
* `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
|
|
210
|
-
*/
|
|
211
|
-
resolver: ResolverTs;
|
|
212
|
-
/**
|
|
213
|
-
* The supplying plugin's own `output`, when it configured one.
|
|
214
|
-
*/
|
|
215
|
-
output: Output | undefined;
|
|
216
|
-
/**
|
|
217
|
-
* The supplying plugin's own `group`, when it configured one.
|
|
218
|
-
*/
|
|
219
|
-
group: Group | undefined;
|
|
220
|
-
};
|
|
221
|
-
declare global {
|
|
222
|
-
namespace Kubb {
|
|
223
|
-
interface MemoRegistry {
|
|
224
|
-
operationTypes: OperationTypeSource;
|
|
225
|
-
/**
|
|
226
|
-
* Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
|
|
227
|
-
*/
|
|
228
|
-
zodTypes: unknown;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
237
|
/**
|
|
233
238
|
* Omits keys from every member of a union, where the built-in `Omit` would collapse the union into one shape.
|
|
234
239
|
*/
|
|
@@ -242,7 +247,7 @@ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K>
|
|
|
242
247
|
* pluginClient({ importPath: '../../../client' })
|
|
243
248
|
* ```
|
|
244
249
|
*/
|
|
245
|
-
type Options = DistributiveOmit<
|
|
250
|
+
type Options = DistributiveOmit<ClientOptions, 'sdk' | 'returnType' | 'baseURL' | 'override'> & {
|
|
246
251
|
/**
|
|
247
252
|
* Shape of the value a generated operation resolves to. `'full'` and `'data'` import `withUnwrap` or `unwrapResult`
|
|
248
253
|
* and their types from your `importPath` module, so that module must export them.
|
|
@@ -275,7 +280,7 @@ type Options = DistributiveOmit<Options$1, 'sdk' | 'returnType' | 'baseURL' | 'o
|
|
|
275
280
|
/**
|
|
276
281
|
* Options after `pluginClient` applies its defaults.
|
|
277
282
|
*/
|
|
278
|
-
type ResolvedOptions =
|
|
283
|
+
type ResolvedOptions = ClientResolvedOptions & {
|
|
279
284
|
importPath: string;
|
|
280
285
|
};
|
|
281
286
|
/**
|
|
@@ -304,5 +309,40 @@ export declare const pluginClientName = "plugin-client";
|
|
|
304
309
|
* ```
|
|
305
310
|
*/
|
|
306
311
|
export declare const pluginClient: import("@kubb/kit").PluginFactory<PluginClient>;
|
|
307
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Default resolver shared by the client plugins. Functions use safe camelCase identifiers and
|
|
314
|
+
* files inherit the built-in casing; classes and tag groups use PascalCase.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* resolverClient.name('show pet by id') // 'showPetById'
|
|
319
|
+
* resolverClient.groupName('pet') // 'PetClient'
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export declare const resolverClient: ResolverClient;
|
|
323
|
+
/**
|
|
324
|
+
* Applies the client option defaults and merges a user `resolver` over the built-in one.
|
|
325
|
+
*/
|
|
326
|
+
export declare function resolveClientOptions(options: ClientOptions): ClientResolvedOptions;
|
|
327
|
+
/**
|
|
328
|
+
* Wires a client plugin in its `setup`: resolver, macros, client or SDK generator, and the `.kubb/` runtime with the plugin's own `client.ts`.
|
|
329
|
+
*/
|
|
330
|
+
export declare function setupClient({ name, resolved, macros, client }: {
|
|
331
|
+
name: string;
|
|
332
|
+
resolved: ClientResolvedOptions;
|
|
333
|
+
macros?: ClientOptions['macros'];
|
|
334
|
+
client: string;
|
|
335
|
+
}): void;
|
|
336
|
+
/**
|
|
337
|
+
* Declares `plugin-ts` as optional and `plugin-zod` as required once `validator` enables a direction.
|
|
338
|
+
*/
|
|
339
|
+
export declare function clientDependencies(options: Pick<ClientOptions, 'validator'>): {
|
|
340
|
+
"plugin-ts": {
|
|
341
|
+
optional: boolean;
|
|
342
|
+
};
|
|
343
|
+
"plugin-zod": {
|
|
344
|
+
optional: boolean;
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
export { type ClientOptions, type ClientResolvedOptions, type Options, type PluginClient, type ResolvedOptions, type ResolverClient, pluginClient as default };
|
|
308
348
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,71 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
|
|
2
|
-
import "@kubb/plugin-zod";
|
|
3
2
|
import { ResolverTs } from "@kubb/plugin-ts";
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the value a generated operation function resolves to.
|
|
5
|
+
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
6
|
+
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
7
|
+
* so callers can inspect `error`.
|
|
8
|
+
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
9
|
+
* helper. Backs `@kubb/plugin-client`.
|
|
10
|
+
*/
|
|
11
|
+
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
12
|
+
/**
|
|
13
|
+
* The per-operation type names a generated client references: the grouped input, the per-status
|
|
14
|
+
* responses record its `RequestResult` is keyed on, and the headers each response declares.
|
|
15
|
+
*/
|
|
16
|
+
type OperationTypeNames = {
|
|
17
|
+
response: {
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the name of the operation's grouped `{ body, path, query, headers, cookies }` input type.
|
|
20
|
+
*/
|
|
21
|
+
options(node: ast.OperationNode): string;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the name of the operation's per-status responses record type.
|
|
24
|
+
*/
|
|
25
|
+
responses(node: ast.OperationNode): string;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves the name of the type of the headers one response declares. Left out, results keep untyped headers.
|
|
28
|
+
*/
|
|
29
|
+
headers?(node: ast.OperationNode, statusCode: ast.StatusCode): string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Where a generated client sources its operation types, plus the resolver and output the file
|
|
34
|
+
* declaring them is resolved with.
|
|
35
|
+
*/
|
|
36
|
+
type OperationTypeSource = OperationTypeNames & {
|
|
37
|
+
/**
|
|
38
|
+
* `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
|
|
39
|
+
*/
|
|
40
|
+
resolver: ResolverTs;
|
|
41
|
+
/**
|
|
42
|
+
* The supplying plugin's own `output`, when it configured one.
|
|
43
|
+
*/
|
|
44
|
+
output: Output | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The supplying plugin's own `group`, when it configured one.
|
|
47
|
+
*/
|
|
48
|
+
group: Group | undefined;
|
|
49
|
+
};
|
|
50
|
+
declare global {
|
|
51
|
+
namespace Kubb {
|
|
52
|
+
interface MemoRegistry {
|
|
53
|
+
operationTypes: OperationTypeSource;
|
|
54
|
+
/**
|
|
55
|
+
* Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
|
|
56
|
+
*/
|
|
57
|
+
zodTypes: unknown;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
4
61
|
/**
|
|
5
62
|
* Validator applied to the request and response using schemas from `@kubb/plugin-zod`.
|
|
6
63
|
* - `false`: no validation.
|
|
7
|
-
* - `'zod'`: validates the success (2xx) response body, and the error body
|
|
8
|
-
*
|
|
64
|
+
* - `'zod'`: validates the success (2xx) response body, and the error body of a non-2xx call, whether it
|
|
65
|
+
* throws or returns the error.
|
|
9
66
|
* - `{ request?: 'zod'; params?: 'zod'; response?: 'zod' }`: opt in per slot. `request` encodes the
|
|
10
67
|
* request body before the call; `params` validate the path, query, and header params;
|
|
11
|
-
* `response` validates the success response body and
|
|
68
|
+
* `response` validates the success response body and the error body.
|
|
12
69
|
*/
|
|
13
70
|
type ValidatorOptions = false | 'zod' | {
|
|
14
71
|
request?: 'zod';
|
|
@@ -21,15 +78,6 @@ type ValidatorOptions = false | 'zod' | {
|
|
|
21
78
|
* - `'flat'`: one class with every operation as a direct method.
|
|
22
79
|
*/
|
|
23
80
|
type Mode = 'tag' | 'flat';
|
|
24
|
-
/**
|
|
25
|
-
* Shape of the value a generated operation function resolves to.
|
|
26
|
-
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
27
|
-
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
28
|
-
* so callers can inspect `error`.
|
|
29
|
-
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
30
|
-
* helper. Backs `@kubb/plugin-client`.
|
|
31
|
-
*/
|
|
32
|
-
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
33
81
|
/**
|
|
34
82
|
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
35
83
|
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
|
@@ -59,7 +107,7 @@ type ResolverClient = Resolver & {
|
|
|
59
107
|
* response contract and one grouped options object. Each plugin extends this with its own
|
|
60
108
|
* `transport` field.
|
|
61
109
|
*/
|
|
62
|
-
type
|
|
110
|
+
type ClientOptions = OutputOptions & {
|
|
63
111
|
/**
|
|
64
112
|
* Skip operations matching at least one entry in the list.
|
|
65
113
|
*/
|
|
@@ -71,12 +119,12 @@ type Options$1 = OutputOptions & {
|
|
|
71
119
|
/**
|
|
72
120
|
* Apply a different options object to operations matching a pattern.
|
|
73
121
|
*/
|
|
74
|
-
override?: Array<Override<Omit<
|
|
122
|
+
override?: Array<Override<Omit<ClientResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
75
123
|
/**
|
|
76
|
-
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so
|
|
77
|
-
*
|
|
78
|
-
* Values containing a `${...}` interpolation are emitted as template literals in the generated
|
|
79
|
-
*
|
|
124
|
+
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so set one at runtime with
|
|
125
|
+
* `client.setConfig({ baseURL })`. The top-level server URL is not used, but an operation with path-level or operation-level `servers` calls it.
|
|
126
|
+
* Values containing a `${...}` interpolation are emitted as template literals in the generated client config, which keeps
|
|
127
|
+
* runtime environment reads dynamic.
|
|
80
128
|
*/
|
|
81
129
|
baseURL?: string;
|
|
82
130
|
/**
|
|
@@ -118,15 +166,17 @@ type Options$1 = OutputOptions & {
|
|
|
118
166
|
* // const api = new PetClient({ baseURL: 'https://api.example.com' })
|
|
119
167
|
* // await api.getPetById({ path: { petId: 1 } })
|
|
120
168
|
* ```
|
|
121
|
-
* @example Composed root that
|
|
169
|
+
* @example Composed root that shares one client with every tag client
|
|
122
170
|
* ```ts
|
|
123
171
|
* pluginFetch({ sdk: { name: 'petStore' } })
|
|
124
172
|
* // class PetStore {
|
|
173
|
+
* // readonly client: ClientInstance
|
|
125
174
|
* // readonly pet: PetClient
|
|
126
175
|
* // readonly store: StoreClient
|
|
127
176
|
* // constructor(config = {}) { ... }
|
|
128
177
|
* // }
|
|
129
178
|
* // const api = new PetStore({ baseURL })
|
|
179
|
+
* // api.client.interceptors.request.use(...) // applies to every tag
|
|
130
180
|
* // await api.pet.getPetById({ path: { petId: 1 } })
|
|
131
181
|
* ```
|
|
132
182
|
* @example Flat class with every operation as a direct method
|
|
@@ -139,7 +189,7 @@ type Options$1 = OutputOptions & {
|
|
|
139
189
|
sdk?: {
|
|
140
190
|
/**
|
|
141
191
|
* How the SDK groups operations.
|
|
142
|
-
* - `'tag'`: one class per tag
|
|
192
|
+
* - `'tag'`: one class per tag, such as `PetClient`. With `name`, a composed root shares one client with every tag client.
|
|
143
193
|
* - `'flat'`: one class named by `name`, with every operation as a direct method.
|
|
144
194
|
*
|
|
145
195
|
* @default 'tag'
|
|
@@ -147,7 +197,7 @@ type Options$1 = OutputOptions & {
|
|
|
147
197
|
mode?: Mode;
|
|
148
198
|
/**
|
|
149
199
|
* Name of the generated entry point, also the file name. With `mode: 'tag'` it emits a
|
|
150
|
-
* composed root class that
|
|
200
|
+
* composed root class that creates one client and shares it with every tag client. With
|
|
151
201
|
* `mode: 'flat'` it names the single class.
|
|
152
202
|
*/
|
|
153
203
|
name?: string;
|
|
@@ -164,19 +214,19 @@ type Options$1 = OutputOptions & {
|
|
|
164
214
|
/**
|
|
165
215
|
* The resolved options after defaults are applied.
|
|
166
216
|
*/
|
|
167
|
-
type
|
|
217
|
+
type ClientResolvedOptions = {
|
|
168
218
|
output: Output;
|
|
169
219
|
exclude: Array<Exclude>;
|
|
170
220
|
include: Array<Include> | undefined;
|
|
171
|
-
override: Array<Override<Omit<
|
|
221
|
+
override: Array<Override<Omit<ClientResolvedOptions, 'throwOnErrorDefault'>>>;
|
|
172
222
|
group: Group | null;
|
|
173
|
-
baseURL:
|
|
223
|
+
baseURL: ClientOptions['baseURL'];
|
|
174
224
|
/**
|
|
175
225
|
* Module the generated operations import the client runtime from, used verbatim. Unset, they import the bundled `.kubb/client.ts`.
|
|
176
226
|
*/
|
|
177
227
|
importPath?: string;
|
|
178
228
|
throwOnErrorDefault: boolean;
|
|
179
|
-
validator: NonNullable<
|
|
229
|
+
validator: NonNullable<ClientOptions['validator']>;
|
|
180
230
|
returnType: ReturnTypeOption;
|
|
181
231
|
sdk: {
|
|
182
232
|
mode: Mode;
|
|
@@ -184,51 +234,6 @@ type ResolvedOptions$1 = {
|
|
|
184
234
|
} | undefined;
|
|
185
235
|
resolver: ResolverClient;
|
|
186
236
|
};
|
|
187
|
-
/**
|
|
188
|
-
* The two per-operation type names a generated client references: the grouped input and the
|
|
189
|
-
* per-status responses record its `RequestResult` is keyed on.
|
|
190
|
-
*/
|
|
191
|
-
type OperationTypeNames = {
|
|
192
|
-
response: {
|
|
193
|
-
/**
|
|
194
|
-
* Resolves the name of the operation's grouped `{ body, path, query, headers }` input type.
|
|
195
|
-
*/
|
|
196
|
-
options(node: ast.OperationNode): string;
|
|
197
|
-
/**
|
|
198
|
-
* Resolves the name of the operation's per-status responses record type.
|
|
199
|
-
*/
|
|
200
|
-
responses(node: ast.OperationNode): string;
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Where a generated client sources its operation types, plus the resolver and output the file
|
|
205
|
-
* declaring them is resolved with.
|
|
206
|
-
*/
|
|
207
|
-
type OperationTypeSource = OperationTypeNames & {
|
|
208
|
-
/**
|
|
209
|
-
* `plugin-ts` shaped resolver of the plugin supplying the names, also used to resolve the file they are exported from.
|
|
210
|
-
*/
|
|
211
|
-
resolver: ResolverTs;
|
|
212
|
-
/**
|
|
213
|
-
* The supplying plugin's own `output`, when it configured one.
|
|
214
|
-
*/
|
|
215
|
-
output: Output | undefined;
|
|
216
|
-
/**
|
|
217
|
-
* The supplying plugin's own `group`, when it configured one.
|
|
218
|
-
*/
|
|
219
|
-
group: Group | undefined;
|
|
220
|
-
};
|
|
221
|
-
declare global {
|
|
222
|
-
namespace Kubb {
|
|
223
|
-
interface MemoRegistry {
|
|
224
|
-
operationTypes: OperationTypeSource;
|
|
225
|
-
/**
|
|
226
|
-
* Nests every key the zod-backed `ResolverTs` memoizes, so it holds each of their value types.
|
|
227
|
-
*/
|
|
228
|
-
zodTypes: unknown;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
237
|
/**
|
|
233
238
|
* Omits keys from every member of a union, where the built-in `Omit` would collapse the union into one shape.
|
|
234
239
|
*/
|
|
@@ -242,7 +247,7 @@ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K>
|
|
|
242
247
|
* pluginClient({ importPath: '../../../client' })
|
|
243
248
|
* ```
|
|
244
249
|
*/
|
|
245
|
-
type Options = DistributiveOmit<
|
|
250
|
+
type Options = DistributiveOmit<ClientOptions, 'sdk' | 'returnType' | 'baseURL' | 'override'> & {
|
|
246
251
|
/**
|
|
247
252
|
* Shape of the value a generated operation resolves to. `'full'` and `'data'` import `withUnwrap` or `unwrapResult`
|
|
248
253
|
* and their types from your `importPath` module, so that module must export them.
|
|
@@ -275,7 +280,7 @@ type Options = DistributiveOmit<Options$1, 'sdk' | 'returnType' | 'baseURL' | 'o
|
|
|
275
280
|
/**
|
|
276
281
|
* Options after `pluginClient` applies its defaults.
|
|
277
282
|
*/
|
|
278
|
-
type ResolvedOptions =
|
|
283
|
+
type ResolvedOptions = ClientResolvedOptions & {
|
|
279
284
|
importPath: string;
|
|
280
285
|
};
|
|
281
286
|
/**
|
|
@@ -304,5 +309,40 @@ export declare const pluginClientName = "plugin-client";
|
|
|
304
309
|
* ```
|
|
305
310
|
*/
|
|
306
311
|
export declare const pluginClient: import("@kubb/kit").PluginFactory<PluginClient>;
|
|
307
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Default resolver shared by the client plugins. Functions use safe camelCase identifiers and
|
|
314
|
+
* files inherit the built-in casing; classes and tag groups use PascalCase.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* resolverClient.name('show pet by id') // 'showPetById'
|
|
319
|
+
* resolverClient.groupName('pet') // 'PetClient'
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export declare const resolverClient: ResolverClient;
|
|
323
|
+
/**
|
|
324
|
+
* Applies the client option defaults and merges a user `resolver` over the built-in one.
|
|
325
|
+
*/
|
|
326
|
+
export declare function resolveClientOptions(options: ClientOptions): ClientResolvedOptions;
|
|
327
|
+
/**
|
|
328
|
+
* Wires a client plugin in its `setup`: resolver, macros, client or SDK generator, and the `.kubb/` runtime with the plugin's own `client.ts`.
|
|
329
|
+
*/
|
|
330
|
+
export declare function setupClient({ name, resolved, macros, client }: {
|
|
331
|
+
name: string;
|
|
332
|
+
resolved: ClientResolvedOptions;
|
|
333
|
+
macros?: ClientOptions['macros'];
|
|
334
|
+
client: string;
|
|
335
|
+
}): void;
|
|
336
|
+
/**
|
|
337
|
+
* Declares `plugin-ts` as optional and `plugin-zod` as required once `validator` enables a direction.
|
|
338
|
+
*/
|
|
339
|
+
export declare function clientDependencies(options: Pick<ClientOptions, 'validator'>): {
|
|
340
|
+
"plugin-ts": {
|
|
341
|
+
optional: boolean;
|
|
342
|
+
};
|
|
343
|
+
"plugin-zod": {
|
|
344
|
+
optional: boolean;
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
export { type ClientOptions, type ClientResolvedOptions, type Options, type PluginClient, type ResolvedOptions, type ResolverClient, pluginClient as default };
|
|
308
348
|
//# sourceMappingURL=index.d.ts.map
|