@kubb/plugin-client 5.5.10 → 5.5.11
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 +1 -1
- package/dist/index.js +1 -1
- package/docs/guides/write-your-client.md +12 -0
- package/docs/overview.md +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -12,6 +12,15 @@ The generated functions import your module through [`importPath`](https://kubb.d
|
|
|
12
12
|
|
|
13
13
|
If your spec has server-sent event operations, also export `toEventStream` and the `EventStreamResult` and `SuccessOf` types.
|
|
14
14
|
|
|
15
|
+
The query plugins (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, `@kubb/plugin-swr`) and `@kubb/plugin-mcp` call the generated functions with `throwOnError: true` and read `data` off the result. The query plugins also import two more types from your module:
|
|
16
|
+
|
|
17
|
+
| Export | Kind | Purpose |
|
|
18
|
+
| --------------------- | ---- | ----------------------------------------------------------------------- |
|
|
19
|
+
| `RequestConfig` | type | The per-call `client` options a hook accepts, minus the request fields. |
|
|
20
|
+
| `ResponseErrorConfig` | type | The error type of a failed hook, given the spec's error type. |
|
|
21
|
+
|
|
22
|
+
With a relative `importPath`, the hooks resolve it from the generated operation file, so one path serves both.
|
|
23
|
+
|
|
15
24
|
## What a generated function looks like
|
|
16
25
|
|
|
17
26
|
```typescript
|
|
@@ -64,6 +73,9 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true> = Thr
|
|
|
64
73
|
? { data: TResponses[keyof TResponses]; error: undefined; response: Response }
|
|
65
74
|
: { data: TResponses[keyof TResponses]; error: undefined; response: Response } | { data: undefined; error: {}; response: Response }
|
|
66
75
|
|
|
76
|
+
// Only needed by the query plugins: what a failed hook rejects with.
|
|
77
|
+
export type ResponseErrorConfig<TError = unknown> = Error & { body?: TError }
|
|
78
|
+
|
|
67
79
|
// Set this to your API host. `new URL()` needs an absolute URL.
|
|
68
80
|
export const settings = { baseURL: 'https://petstore3.swagger.io/api/v3' }
|
|
69
81
|
|
package/docs/overview.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The Client plugin turns each operation in your OpenAPI spec into a typed function that calls a client module you write. The generated code has no Fetch, axios, or Kubb runtime dependency.
|
|
4
4
|
|
|
5
|
-
Each function takes grouped `path`, `query`, `headers`, and `body` parameters and passes the operation's auth requirements to your client in a `security` list. A single call can pass its own `client` to replace the default. For a ready-made client,
|
|
5
|
+
Each function takes grouped `path`, `query`, `headers`, and `body` parameters and passes the operation's auth requirements to your client in a `security` list. A single call can pass its own `client` to replace the default. For a ready-made client, use `@kubb/plugin-fetch` or `@kubb/plugin-axios` instead. The query plugins and `@kubb/plugin-mcp` work with this plugin too, and their hooks and handlers then call your client module.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|