@kubb/plugin-fetch 5.2.0-canary.20260901T143318 → 5.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-fetch",
3
- "version": "5.2.0-canary.20260901T143318",
3
+ "version": "5.2.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",
@@ -60,12 +60,12 @@
60
60
  "registry": "https://registry.npmjs.org/"
61
61
  },
62
62
  "dependencies": {
63
- "@kubb/plugin-ts": "^5.1.0-canary.20260901T143314",
64
- "@kubb/plugin-zod": "^5.2.0-canary.20260901T143314"
63
+ "@kubb/plugin-ts": "^5.0.0",
64
+ "@kubb/plugin-zod": "^5.1.2"
65
65
  },
66
66
  "devDependencies": {
67
- "@internals/client": "0.1.0-canary.20260901T143315",
68
- "@internals/shared": "0.1.0-canary.20260901T143313",
67
+ "@internals/client": "0.0.0",
68
+ "@internals/shared": "0.0.0",
69
69
  "kubb": "^5.0.4",
70
70
  "typescript": "^6.0.3"
71
71
  },
@@ -82,6 +82,32 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
82
82
  ? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
83
83
  : ResultUnion<TResponses, TRequest, TResponse>
84
84
 
85
+ /**
86
+ * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body.
87
+ */
88
+ export type Unwrappable<T extends { data: unknown; error: unknown }> = Promise<T> & {
89
+ unwrap: () => Promise<Extract<T, { error: undefined }>['data']>
90
+ }
91
+
92
+ /**
93
+ * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one.
94
+ *
95
+ * @example Full result
96
+ * `const { data, error } = await getPetById({ path: { petId: 1 } })`
97
+ *
98
+ * @example Success body only
99
+ * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()`
100
+ */
101
+ export function withUnwrap<T extends { data: unknown; error: unknown }>(promise: Promise<T>): Unwrappable<T> {
102
+ const unwrappable = promise as Unwrappable<T>
103
+ unwrappable.unwrap = () =>
104
+ promise.then((result) => {
105
+ if (result.error !== undefined) throw result.error
106
+ return result.data as Extract<T, { error: undefined }>['data']
107
+ })
108
+ return unwrappable
109
+ }
110
+
85
111
  /**
86
112
  * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
87
113
  */