@kubb/plugin-axios 5.2.0-canary.20260902T141305 → 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-axios",
3
- "version": "5.2.0-canary.20260902T141305",
3
+ "version": "5.2.0",
4
4
  "description": "Generate a slim, type-safe HTTP client with Kubb based on axios.",
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.20260902T141302",
64
- "@kubb/plugin-zod": "^5.2.0-canary.20260902T141302"
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.20260902T141303",
68
- "@internals/shared": "0.1.0-canary.20260902T141301",
67
+ "@internals/client": "0.0.0",
68
+ "@internals/shared": "0.0.0",
69
69
  "axios": "^1.20.0",
70
70
  "kubb": "^5.0.4",
71
71
  "typescript": "^6.0.3"
@@ -84,6 +84,32 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
84
84
  ? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
85
85
  : ResultUnion<TResponses, TRequest, TResponse>
86
86
 
87
+ /**
88
+ * A `RequestResult` promise with an extra `unwrap()` method that resolves to the success body.
89
+ */
90
+ export type Unwrappable<T extends { data: unknown; error: unknown }> = Promise<T> & {
91
+ unwrap: () => Promise<Extract<T, { error: undefined }>['data']>
92
+ }
93
+
94
+ /**
95
+ * Attaches `unwrap()` to a result promise, which rejects with `error` when the result carried one.
96
+ *
97
+ * @example Full result
98
+ * `const { data, error } = await getPetById({ path: { petId: 1 } })`
99
+ *
100
+ * @example Success body only
101
+ * `const pet = await getPetById({ path: { petId: 1 } }).unwrap()`
102
+ */
103
+ export function withUnwrap<T extends { data: unknown; error: unknown }>(promise: Promise<T>): Unwrappable<T> {
104
+ const unwrappable = promise as Unwrappable<T>
105
+ unwrappable.unwrap = () =>
106
+ promise.then((result) => {
107
+ if (result.error !== undefined) throw result.error
108
+ return result.data as Extract<T, { error: undefined }>['data']
109
+ })
110
+ return unwrappable
111
+ }
112
+
87
113
  /**
88
114
  * The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
89
115
  */