@kubb/plugin-client 5.12.0-canary.20261109T125041 → 5.12.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/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/docs/options.md +24 -0
- package/package.json +5 -5
- package/src/plugin.ts +2 -1
- package/src/types.ts +13 -1
package/docs/options.md
CHANGED
|
@@ -11,6 +11,7 @@ Pass these options to `pluginClient()`. Shared options link to [Shared plugin op
|
|
|
11
11
|
| [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path: `type`, `name`. | None |
|
|
12
12
|
| [`throwOnErrorDefault`](#throwonerrordefault) | Default `throwOnError` value passed to your client. | `true` |
|
|
13
13
|
| [`validator`](#validator) | Pass Zod schemas to your client. | `false` |
|
|
14
|
+
| [`returnType`](#returntype) | Shape of the value a generated operation resolves to. | `'plain'` |
|
|
14
15
|
| [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
|
|
15
16
|
| [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
|
|
16
17
|
| [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
|
|
@@ -49,6 +50,29 @@ Default for the `throwOnError` field that every generated function passes to you
|
|
|
49
50
|
|
|
50
51
|
The setting applies to the whole plugin, so you cannot set it in `override`.
|
|
51
52
|
|
|
53
|
+
### returnType
|
|
54
|
+
|
|
55
|
+
Shape of the value a generated operation resolves to.
|
|
56
|
+
|
|
57
|
+
- `'plain'`: returns what your `client` returns.
|
|
58
|
+
- `'full'`: wraps the call in `withUnwrap`, so the caller can `await` it or call `.unwrap()`. Your module must export `withUnwrap` and the `Unwrappable` type.
|
|
59
|
+
- `'data'`: passes the call through `unwrapResult` and resolves to the body. Your module must export `unwrapResult` and the `UnwrappedResult` type.
|
|
60
|
+
|
|
61
|
+
`@kubb/plugin-client/templates/core.ts` exports all of these, so your module can re-export them from there.
|
|
62
|
+
|
|
63
|
+
| | |
|
|
64
|
+
| -------- | ----------------------------- |
|
|
65
|
+
| Type | `'plain' \| 'full' \| 'data'` |
|
|
66
|
+
| Required | `false` |
|
|
67
|
+
| Default | `'plain'` |
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
pluginClient({ importPath: '../../client', returnType: 'full' })
|
|
71
|
+
// const pet = await getPetById({ path: { petId: 1 } }).unwrap()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The setting applies to the whole plugin, so you cannot set it in `override`.
|
|
75
|
+
|
|
52
76
|
### validator
|
|
53
77
|
|
|
54
78
|
Passes Zod schemas from `@kubb/plugin-zod` to your client on `config.validator`. The plugin does not run the schemas. Your client reads `config.validator` and runs them. See [validate requests and responses](https://kubb.dev/extensions/kubb-labs/plugin-client/guides/validate-requests-and-responses).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "5.12.0
|
|
3
|
+
"version": "5.12.0",
|
|
4
4
|
"description": "Generate typed API operations against your own client module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@kubb/kit": "^5.16.0",
|
|
65
|
-
"@kubb/plugin-ts": "^5.
|
|
66
|
-
"@kubb/plugin-zod": "^5.
|
|
65
|
+
"@kubb/plugin-ts": "^5.4.2",
|
|
66
|
+
"@kubb/plugin-zod": "^5.8.3",
|
|
67
67
|
"@kubb/renderer-jsx": "^5.16.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@internals/client": "0.
|
|
71
|
-
"@internals/shared": "0.
|
|
70
|
+
"@internals/client": "0.0.0",
|
|
71
|
+
"@internals/shared": "0.0.0",
|
|
72
72
|
"typescript": "^7.0.2"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {},
|
package/src/plugin.ts
CHANGED
|
@@ -36,6 +36,7 @@ export const pluginClient = defineExtension<PluginClient>({
|
|
|
36
36
|
importPath,
|
|
37
37
|
throwOnErrorDefault = true,
|
|
38
38
|
validator = false,
|
|
39
|
+
returnType = 'plain',
|
|
39
40
|
group,
|
|
40
41
|
resolver: userResolver,
|
|
41
42
|
} = options
|
|
@@ -56,7 +57,7 @@ export const pluginClient = defineExtension<PluginClient>({
|
|
|
56
57
|
baseURL: undefined,
|
|
57
58
|
throwOnErrorDefault,
|
|
58
59
|
validator,
|
|
59
|
-
returnType
|
|
60
|
+
returnType,
|
|
60
61
|
sdk: undefined,
|
|
61
62
|
resolver,
|
|
62
63
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Override, PluginType } from '@kubb/kit'
|
|
2
|
-
import type { Options as ClientOptions, ResolvedOptions as ClientResolvedOptions, ResolverClient } from '@internals/client'
|
|
2
|
+
import type { Options as ClientOptions, ResolvedOptions as ClientResolvedOptions, ResolverClient, ReturnTypeOption } from '@internals/client'
|
|
3
3
|
|
|
4
4
|
export type { ResolverClient } from '@internals/client'
|
|
5
5
|
|
|
@@ -18,6 +18,18 @@ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K>
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export type Options = DistributiveOmit<ClientOptions, 'sdk' | 'returnType' | 'baseURL' | 'override'> & {
|
|
21
|
+
/**
|
|
22
|
+
* Shape of the value a generated operation resolves to. `'full'` and `'data'` import `withUnwrap` or `unwrapResult`
|
|
23
|
+
* and their types from your `importPath` module, so that module must export them.
|
|
24
|
+
*
|
|
25
|
+
* @default 'plain'
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* pluginClient({ importPath: '../../client', returnType: 'full' })
|
|
29
|
+
* // await getPetById({ path: { petId: 1 } }).unwrap()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
returnType?: ReturnTypeOption
|
|
21
33
|
/**
|
|
22
34
|
* Applies different options to operations that match a pattern.
|
|
23
35
|
* `sdk`, `returnType`, and `baseURL` are not available, because this plugin generates standalone operations and your client module owns the base URL.
|