@kubb/plugin-fetch 5.3.0-canary.20260907T133426 → 5.3.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 +71 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +23 -0
- package/dist/index.js +71 -31
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/plugin.ts +2 -0
- package/templates/fetch.ts +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-fetch",
|
|
3
|
-
"version": "5.3.0
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Generate a slim, type-safe HTTP client with Kubb based on the native Fetch api.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"registry": "https://registry.npmjs.org/"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@kubb/plugin-ts": "^5.
|
|
65
|
-
"@kubb/plugin-zod": "^5.
|
|
64
|
+
"@kubb/plugin-ts": "^5.0.1",
|
|
65
|
+
"@kubb/plugin-zod": "^5.1.4"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@internals/client": "0.
|
|
69
|
-
"@internals/shared": "0.
|
|
70
|
-
"kubb": "^5.0
|
|
68
|
+
"@internals/client": "0.0.0",
|
|
69
|
+
"@internals/shared": "0.0.0",
|
|
70
|
+
"kubb": "^5.1.0",
|
|
71
71
|
"typescript": "^6.0.3"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"kubb": "^5.0
|
|
74
|
+
"kubb": "^5.1.0"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=22"
|
package/src/plugin.ts
CHANGED
|
@@ -44,6 +44,7 @@ export const pluginFetch = definePlugin<PluginFetch>((options) => {
|
|
|
44
44
|
override = [],
|
|
45
45
|
baseURL,
|
|
46
46
|
validator = false,
|
|
47
|
+
returnType = 'full',
|
|
47
48
|
group,
|
|
48
49
|
sdk,
|
|
49
50
|
resolver: userResolver,
|
|
@@ -57,6 +58,7 @@ export const pluginFetch = definePlugin<PluginFetch>((options) => {
|
|
|
57
58
|
group: createGroupConfig(group),
|
|
58
59
|
baseURL,
|
|
59
60
|
validator,
|
|
61
|
+
returnType,
|
|
60
62
|
sdk: sdk ? { mode: sdk.mode ?? 'tag', name: sdk.name } : undefined,
|
|
61
63
|
resolver: userResolver ? Resolver.merge<ResolverClient>(resolverClient, userResolver) : resolverClient,
|
|
62
64
|
}
|
package/templates/fetch.ts
CHANGED
|
@@ -108,6 +108,27 @@ export function withUnwrap<T extends { data: unknown; error: unknown }>(promise:
|
|
|
108
108
|
return unwrappable
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
|
|
113
|
+
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
|
|
114
|
+
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
|
|
115
|
+
* failed response.
|
|
116
|
+
*/
|
|
117
|
+
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
|
|
118
|
+
? RequestResult<TResponses, true, TRequest, TResponse>['data']
|
|
119
|
+
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
|
|
123
|
+
* the error branch, the same default the runtime itself applies. Falls back to the full result for
|
|
124
|
+
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
|
|
125
|
+
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
|
|
126
|
+
* post-processing for `text/event-stream` operations.
|
|
127
|
+
*/
|
|
128
|
+
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
|
|
129
|
+
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
|
|
130
|
+
}
|
|
131
|
+
|
|
111
132
|
/**
|
|
112
133
|
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
|
|
113
134
|
*/
|