@kubb/plugin-ky 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/client.d.ts +53 -0
- package/docs/guides/calling-operations.md +145 -0
- package/docs/guides/configure-requests.md +197 -0
- package/docs/guides/error-handling.md +155 -0
- package/docs/guides/serialization.md +226 -0
- package/docs/guides/server-sent-events.md +300 -0
- package/docs/guides/transport.md +92 -0
- package/docs/options.md +209 -0
- package/docs/overview.md +60 -0
- package/kubb-extension.json +236 -0
- package/package.json +107 -3
- package/src/index.ts +2 -0
- package/src/plugin.ts +47 -0
- package/src/types.ts +22 -0
- package/templates/client.ts +98 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://kubb.dev/schemas/kubb-extension.json",
|
|
3
|
+
"kind": "plugin",
|
|
4
|
+
"name": "plugin-ky",
|
|
5
|
+
"export": "pluginKy",
|
|
6
|
+
"displayName": "Ky",
|
|
7
|
+
"description": "Generates a type-safe Ky client from your OpenAPI spec, one async function per operation, so each call stays in sync with the API.",
|
|
8
|
+
"category": "client",
|
|
9
|
+
"icon": {
|
|
10
|
+
"light": "https://kubb.dev/feature/ky.svg"
|
|
11
|
+
},
|
|
12
|
+
"tags": ["api-client", "ky", "http-client", "codegen", "openapi", "validator"],
|
|
13
|
+
"docs": "https://kubb.dev/extensions/kubb-labs/plugin-ky",
|
|
14
|
+
"maintainers": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Stijn Van Hulle",
|
|
17
|
+
"github": "stijnvanhulle"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"optionalDependencies": ["plugin-ts", "plugin-zod"],
|
|
21
|
+
"compatibility": {
|
|
22
|
+
"kubb": ">=5.19.0",
|
|
23
|
+
"node": ">=22.22"
|
|
24
|
+
},
|
|
25
|
+
"role": "client",
|
|
26
|
+
"options": [
|
|
27
|
+
{
|
|
28
|
+
"key": "outputPath",
|
|
29
|
+
"path": ["output", "path"],
|
|
30
|
+
"label": "Output Path",
|
|
31
|
+
"description": "Output folder for generated files",
|
|
32
|
+
"type": "text",
|
|
33
|
+
"default": "clients"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"key": "barrel",
|
|
37
|
+
"path": ["output", "barrel"],
|
|
38
|
+
"label": "Barrel",
|
|
39
|
+
"description": "How index.ts barrel files are generated",
|
|
40
|
+
"type": "select",
|
|
41
|
+
"default": {
|
|
42
|
+
"type": "named"
|
|
43
|
+
},
|
|
44
|
+
"choices": [
|
|
45
|
+
{
|
|
46
|
+
"label": "named",
|
|
47
|
+
"value": {
|
|
48
|
+
"type": "named"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"label": "named (nested)",
|
|
53
|
+
"value": {
|
|
54
|
+
"type": "named",
|
|
55
|
+
"nested": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"label": "all",
|
|
60
|
+
"value": {
|
|
61
|
+
"type": "all"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"label": "all (nested)",
|
|
66
|
+
"value": {
|
|
67
|
+
"type": "all",
|
|
68
|
+
"nested": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"label": "false (disabled)",
|
|
73
|
+
"value": false
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"key": "outputMode",
|
|
79
|
+
"path": ["output", "mode"],
|
|
80
|
+
"label": "Output Mode",
|
|
81
|
+
"description": "How the plugin consolidates its code into files. File mode writes everything into a single file, so the output path must include a file extension and cannot be grouped.",
|
|
82
|
+
"type": "select",
|
|
83
|
+
"default": "directory",
|
|
84
|
+
"choices": [
|
|
85
|
+
{
|
|
86
|
+
"label": "directory (one file per schema)",
|
|
87
|
+
"value": "directory"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"label": "file (single file)",
|
|
91
|
+
"value": "file"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"key": "validator",
|
|
97
|
+
"path": ["validator"],
|
|
98
|
+
"label": "Validator",
|
|
99
|
+
"description": "Validate request and response bodies with schemas from @kubb/plugin-zod",
|
|
100
|
+
"type": "select",
|
|
101
|
+
"default": false,
|
|
102
|
+
"choices": [
|
|
103
|
+
{
|
|
104
|
+
"label": "false (disabled)",
|
|
105
|
+
"value": false
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"label": "zod",
|
|
109
|
+
"value": "zod"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"key": "group",
|
|
115
|
+
"path": ["group"],
|
|
116
|
+
"label": "Group",
|
|
117
|
+
"description": "Group generated operations by OpenAPI tag or path",
|
|
118
|
+
"type": "select",
|
|
119
|
+
"default": null,
|
|
120
|
+
"choices": [
|
|
121
|
+
{
|
|
122
|
+
"label": "none",
|
|
123
|
+
"value": null
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"label": "by tag",
|
|
127
|
+
"value": {
|
|
128
|
+
"type": "tag"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"label": "by path",
|
|
133
|
+
"value": {
|
|
134
|
+
"type": "path"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"key": "excludeTags",
|
|
141
|
+
"path": ["exclude"],
|
|
142
|
+
"label": "Exclude Tags",
|
|
143
|
+
"description": "Comma-separated OpenAPI tags to exclude from generation",
|
|
144
|
+
"type": "list",
|
|
145
|
+
"item": {
|
|
146
|
+
"type": "tag",
|
|
147
|
+
"pattern": "$item"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"key": "includeTags",
|
|
152
|
+
"path": ["include"],
|
|
153
|
+
"label": "Include Tags",
|
|
154
|
+
"description": "Comma-separated OpenAPI tags to include. Only operations with these tags are generated",
|
|
155
|
+
"type": "list",
|
|
156
|
+
"item": {
|
|
157
|
+
"type": "tag",
|
|
158
|
+
"pattern": "$item"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"key": "baseURL",
|
|
163
|
+
"path": ["baseURL"],
|
|
164
|
+
"label": "Base URL",
|
|
165
|
+
"description": "Custom API base URL",
|
|
166
|
+
"type": "text"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"key": "sdkMode",
|
|
170
|
+
"path": ["sdk", "mode"],
|
|
171
|
+
"label": "SDK Mode",
|
|
172
|
+
"description": "Group generated operations into an SDK client by tag or flat",
|
|
173
|
+
"type": "select",
|
|
174
|
+
"default": null,
|
|
175
|
+
"choices": [
|
|
176
|
+
{
|
|
177
|
+
"label": "off (standalone functions)",
|
|
178
|
+
"value": null
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"label": "tag",
|
|
182
|
+
"value": "tag"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"label": "flat",
|
|
186
|
+
"value": "flat"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"key": "sdkName",
|
|
192
|
+
"path": ["sdk", "name"],
|
|
193
|
+
"label": "SDK Name",
|
|
194
|
+
"description": "Root client name for the generated SDK",
|
|
195
|
+
"type": "text"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"key": "returnType",
|
|
199
|
+
"path": ["returnType"],
|
|
200
|
+
"label": "Return Type",
|
|
201
|
+
"description": "What a generated function resolves to. full is the whole result with status and error, and data is only the success body when it throws",
|
|
202
|
+
"type": "select",
|
|
203
|
+
"default": "full",
|
|
204
|
+
"choices": [
|
|
205
|
+
{
|
|
206
|
+
"value": "full"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"value": "data"
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"key": "throwOnErrorDefault",
|
|
215
|
+
"path": ["throwOnErrorDefault"],
|
|
216
|
+
"label": "Throw on Error",
|
|
217
|
+
"description": "Throw when a request fails. A per-call throwOnError overrides it",
|
|
218
|
+
"type": "boolean",
|
|
219
|
+
"default": true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"key": "banner",
|
|
223
|
+
"path": ["output", "banner"],
|
|
224
|
+
"label": "Banner",
|
|
225
|
+
"description": "Text added at the top of every generated file",
|
|
226
|
+
"type": "text"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"key": "footer",
|
|
230
|
+
"path": ["output", "footer"],
|
|
231
|
+
"label": "Footer",
|
|
232
|
+
"description": "Text added at the end of every generated file",
|
|
233
|
+
"type": "text"
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,110 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ky",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Generate a slim, type-safe HTTP client with Kubb based on Ky.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"api-client",
|
|
7
|
+
"code-generation",
|
|
8
|
+
"codegen",
|
|
9
|
+
"http-client",
|
|
10
|
+
"kubb",
|
|
11
|
+
"ky",
|
|
12
|
+
"openapi",
|
|
13
|
+
"swagger",
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://kubb.dev/extensions/kubb-labs/plugin-ky",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "stijnvanhulle",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/kubb-labs/plugins.git",
|
|
22
|
+
"directory": "packages/plugin-ky"
|
|
23
|
+
},
|
|
24
|
+
"funding": [
|
|
25
|
+
{
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/stijnvanhulle"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "opencollective",
|
|
31
|
+
"url": "https://opencollective.com/kubb"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "custom",
|
|
35
|
+
"url": "https://kubb.dev/sponsors"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"files": [
|
|
39
|
+
"src",
|
|
40
|
+
"dist",
|
|
41
|
+
"templates",
|
|
42
|
+
"!templates/config.ts",
|
|
43
|
+
"!templates/core.ts",
|
|
44
|
+
"!templates/serializers.ts",
|
|
45
|
+
"!templates/standardSchema.ts",
|
|
46
|
+
"kubb-extension.json",
|
|
47
|
+
"docs",
|
|
48
|
+
"!/**/**.test.**",
|
|
49
|
+
"!/**/__tests__/**",
|
|
50
|
+
"!/**/__snapshots__/**"
|
|
51
|
+
],
|
|
52
|
+
"type": "module",
|
|
53
|
+
"sideEffects": false,
|
|
54
|
+
"main": "./dist/index.cjs",
|
|
55
|
+
"module": "./dist/index.js",
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"typesVersions": {
|
|
58
|
+
"*": {}
|
|
59
|
+
},
|
|
60
|
+
"exports": {
|
|
61
|
+
".": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/index.d.ts",
|
|
64
|
+
"default": "./dist/index.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./dist/index.d.cts",
|
|
68
|
+
"default": "./dist/index.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json",
|
|
72
|
+
"./kubb-extension.json": "./kubb-extension.json",
|
|
73
|
+
"./templates/*.ts": {
|
|
74
|
+
"types": "./dist/templates/*.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./templates/*.js": {
|
|
77
|
+
"types": "./dist/templates/*.d.ts"
|
|
78
|
+
},
|
|
79
|
+
"./templates/*": "./templates/*"
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public",
|
|
83
|
+
"registry": "https://registry.npmjs.org/"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@kubb/kit": "^5.21.1",
|
|
87
|
+
"@kubb/plugin-client": "^6.1.1"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"ky": "^2.2.0",
|
|
91
|
+
"typescript": "^7.0.2"
|
|
92
|
+
},
|
|
93
|
+
"peerDependencies": {
|
|
94
|
+
"ky": "^2.0.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"ky": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": ">=22.22"
|
|
103
|
+
},
|
|
104
|
+
"scripts": {
|
|
105
|
+
"build": "tsdown",
|
|
106
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
107
|
+
"start": "tsdown --watch",
|
|
108
|
+
"typecheck": "tsc"
|
|
109
|
+
}
|
|
6
110
|
}
|
package/src/index.ts
ADDED
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import { defineExtension } from '@kubb/kit'
|
|
3
|
+
import { clientDependencies, resolveClientOptions, setupClient } from '@kubb/plugin-client'
|
|
4
|
+
import { compatibility } from '../kubb-extension.json'
|
|
5
|
+
import { version } from '../package.json'
|
|
6
|
+
import type { PluginKy } from './types.ts'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Canonical plugin name for `@kubb/plugin-ky`. Used for driver lookups and cross-plugin
|
|
10
|
+
* dependency references.
|
|
11
|
+
*/
|
|
12
|
+
export const pluginKyName = 'plugin-ky' satisfies PluginKy['name']
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generates a type-safe HTTP client pinned to Ky. Each operation becomes one async function
|
|
16
|
+
* that takes a single grouped `options` object and returns the shared `RequestResult` contract. The
|
|
17
|
+
* runtime is always bundled into `.kubb/client.ts`, so generated code never imports from
|
|
18
|
+
* `@kubb/plugin-ky` and the only runtime dependency is `ky`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { defineConfig } from 'kubb/config'
|
|
23
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
24
|
+
* import { pluginKy } from '@kubb/plugin-ky'
|
|
25
|
+
*
|
|
26
|
+
* export default defineConfig({
|
|
27
|
+
* input: './petStore.yaml',
|
|
28
|
+
* output: { path: './src/gen' },
|
|
29
|
+
* plugins: [
|
|
30
|
+
* pluginTs(),
|
|
31
|
+
* pluginKy({ output: { path: './clients' } }),
|
|
32
|
+
* ],
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const pluginKy = defineExtension<PluginKy>({
|
|
37
|
+
kind: 'plugin',
|
|
38
|
+
meta: { name: pluginKyName, version, compatibility },
|
|
39
|
+
dependencies: clientDependencies,
|
|
40
|
+
setup(options) {
|
|
41
|
+
const resolved = resolveClientOptions(options)
|
|
42
|
+
setupClient({ name: 'ky', resolved, macros: options.macros, client: fileURLToPath(new URL('../templates/client.ts', import.meta.url)) })
|
|
43
|
+
return resolved
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export default pluginKy
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PluginType } from '@kubb/kit'
|
|
2
|
+
import type { ClientOptions, ClientResolvedOptions as ResolvedOptions, ResolverClient } from '@kubb/plugin-client'
|
|
3
|
+
|
|
4
|
+
export type { ClientResolvedOptions as ResolvedOptions, ResolverClient } from '@kubb/plugin-client'
|
|
5
|
+
|
|
6
|
+
/** The shared client options, without `returnType: 'plain'`, which only fits a client module `@kubb/plugin-client` calls. */
|
|
7
|
+
export type Options = ClientOptions & { returnType?: 'full' | 'data' }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The plugin factory type for `@kubb/plugin-ky`. Shares the options surface, resolver, and
|
|
11
|
+
* resolved-options shape with the other client plugins; only the plugin name and transport
|
|
12
|
+
* differ.
|
|
13
|
+
*/
|
|
14
|
+
export type PluginKy = PluginType<'plugin-ky', Options, ResolvedOptions, ResolverClient>
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
namespace Kubb {
|
|
18
|
+
interface PluginRegistry {
|
|
19
|
+
'plugin-ky': PluginKy
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import ky from 'ky'
|
|
2
|
+
import type { KyInstance, Options as KyOptions } from 'ky'
|
|
3
|
+
import { createClientCore, createLazyClient, toRequestInit } from './core.ts'
|
|
4
|
+
import { defaultConfig } from './config.ts'
|
|
5
|
+
import * as core from './core.ts'
|
|
6
|
+
|
|
7
|
+
export * from './core.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The native request and response that every result and error carries.
|
|
11
|
+
*/
|
|
12
|
+
export type NativeRequest = Request
|
|
13
|
+
export type NativeResponse = Response
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Extra Ky options for a call or client, such as `retry`, `timeout`, or `hooks`. The left-out options would replace
|
|
17
|
+
* the body or URL the core built, or its status handling. The intersection keeps the options assignable to
|
|
18
|
+
* `RequestInit` under `exactOptionalPropertyTypes`.
|
|
19
|
+
*/
|
|
20
|
+
export type NativeOptions = Omit<KyOptions, 'json' | 'prefix' | 'searchParams' | 'throwHttpErrors'> & RequestInit
|
|
21
|
+
|
|
22
|
+
export type ResponseError<TError = unknown, TRequest = NativeRequest, TResponse = NativeResponse> = core.ResponseError<TError, TRequest, TResponse>
|
|
23
|
+
export const ResponseError = core.ResponseError as {
|
|
24
|
+
new <TError = unknown, TRequest = NativeRequest, TResponse = NativeResponse>(
|
|
25
|
+
config: ConstructorParameters<typeof core.ResponseError<TError, TRequest, TResponse>>[0],
|
|
26
|
+
): core.ResponseError<TError, TRequest, TResponse>
|
|
27
|
+
is: typeof core.ResponseError.is
|
|
28
|
+
// `instanceof` narrows to this type, so it carries the native request and response.
|
|
29
|
+
prototype: core.ResponseError<unknown, NativeRequest, NativeResponse>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type RequestConfig<TBody = unknown, TRequest = NativeRequest, TResponse = NativeResponse> = core.RequestConfig<TBody, TRequest, TResponse> & {
|
|
33
|
+
options?: NativeOptions
|
|
34
|
+
}
|
|
35
|
+
export type Options<TData extends core.DataShape, ThrowOnError extends boolean = true, TRequest = NativeRequest, TResponse = NativeResponse> = core.Options<
|
|
36
|
+
TData,
|
|
37
|
+
ThrowOnError,
|
|
38
|
+
TRequest,
|
|
39
|
+
TResponse
|
|
40
|
+
> & { options?: NativeOptions }
|
|
41
|
+
export type ClientConfig<TRequest = NativeRequest, TResponse = NativeResponse> = core.ClientConfig<TRequest, TResponse> & { options?: NativeOptions }
|
|
42
|
+
export type ResolvedRequest = core.ResolvedRequest & { options?: NativeOptions }
|
|
43
|
+
export type RequestResult<
|
|
44
|
+
TResponses,
|
|
45
|
+
ThrowOnError extends boolean = true,
|
|
46
|
+
TRequest = NativeRequest,
|
|
47
|
+
TResponse = NativeResponse,
|
|
48
|
+
THeaders = unknown,
|
|
49
|
+
> = core.RequestResult<TResponses, ThrowOnError, TRequest, TResponse, THeaders>
|
|
50
|
+
export type UnwrappedResult<
|
|
51
|
+
TResponses,
|
|
52
|
+
ThrowOnError extends boolean = true,
|
|
53
|
+
TRequest = NativeRequest,
|
|
54
|
+
TResponse = NativeResponse,
|
|
55
|
+
THeaders = unknown,
|
|
56
|
+
> = core.UnwrappedResult<TResponses, ThrowOnError, TRequest, TResponse, THeaders>
|
|
57
|
+
export type ResponseErrorConfig<TError = unknown> = core.ResponseError<TError, NativeRequest, NativeResponse>
|
|
58
|
+
export type TransportResult<TRequest = NativeRequest, TResponse = NativeResponse> = core.TransportResult<TRequest, TResponse>
|
|
59
|
+
export type DecodedResponse<TData = unknown, TRequest = NativeRequest, TResponse = NativeResponse> = core.DecodedResponse<TData, TRequest, TResponse>
|
|
60
|
+
export type Transport<TRequest = NativeRequest, TResponse = NativeResponse> = core.Transport<TRequest, TResponse>
|
|
61
|
+
export type Interceptors<TRequest = NativeRequest, TResponse = NativeResponse> = core.Interceptors<TRequest, TResponse>
|
|
62
|
+
export type ClientInstance<TRequest = NativeRequest, TResponse = NativeResponse> = core.ClientInstance<TRequest, TResponse>
|
|
63
|
+
export type StreamResult<
|
|
64
|
+
TResponses,
|
|
65
|
+
ThrowOnError extends boolean = true,
|
|
66
|
+
TEvent = core.ServerSentEvent<core.SuccessOf<TResponses>>,
|
|
67
|
+
TRequest = NativeRequest,
|
|
68
|
+
TResponse = NativeResponse,
|
|
69
|
+
THeaders = unknown,
|
|
70
|
+
> = core.StreamResult<TResponses, ThrowOnError, TEvent, TRequest, TResponse, THeaders>
|
|
71
|
+
export type ResponseErrorOf<TResponses, TRequest = NativeRequest, TResponse = NativeResponse, THeaders = unknown> = core.ResponseErrorOf<
|
|
72
|
+
TResponses,
|
|
73
|
+
TRequest,
|
|
74
|
+
TResponse,
|
|
75
|
+
THeaders
|
|
76
|
+
>
|
|
77
|
+
export const isResponseError = core.isResponseError as <TResponses = unknown, TRequest = NativeRequest, TResponse = NativeResponse, THeaders = unknown>(
|
|
78
|
+
error: unknown,
|
|
79
|
+
) => error is ResponseErrorOf<TResponses, TRequest, TResponse, THeaders>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Turns a Ky instance into a transport that keeps its defaults and hooks.
|
|
83
|
+
*/
|
|
84
|
+
export function createKyTransport(instance: KyInstance): Transport {
|
|
85
|
+
// The core splits success from error and reads the body, so Ky must resolve every status with the body unread.
|
|
86
|
+
return (request) => instance(request.url, { ...toRequestInit(request), throwHttpErrors: false })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Ky retries by default. The client sends each call once unless `options.retry` asks for more.
|
|
90
|
+
export const defaultTransport: Transport = createKyTransport(ky.create({ retry: 0 }))
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The client every generated operation uses unless a call passes its own. It is created on first use.
|
|
94
|
+
*/
|
|
95
|
+
export const client: ClientInstance = createLazyClient((config) => createClientCore({ defaultTransport, ...config }))
|
|
96
|
+
client.setConfig(defaultConfig)
|
|
97
|
+
|
|
98
|
+
export const createClient: ClientInstance['createClient'] = client.createClient
|