Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/advanced/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<
TResponses,
ThrowOnError extends boolean = true,
TRequest = AxiosRequestConfig,
TResponse = AxiosResponse,
> = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
24 changes: 24 additions & 0 deletions examples/axios/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<
TResponses,
ThrowOnError extends boolean = true,
TRequest = AxiosRequestConfig,
TResponse = AxiosResponse,
> = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/fetch/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
24 changes: 24 additions & 0 deletions examples/mcp/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<
TResponses,
ThrowOnError extends boolean = true,
TRequest = AxiosRequestConfig,
TResponse = AxiosResponse,
> = ThrowOnError extends true ? RequestResult<TResponses, true, TRequest, TResponse>['data'] : RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/react-query/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/sdk/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/simple-single/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/swr/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down
21 changes: 21 additions & 0 deletions examples/vue-query/src/gen/.kubb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ export type RequestResult<TResponses, ThrowOnError extends boolean = true, TRequ
? { status: number; data: undefined; error: undefined; contentType: string | undefined; request: TRequest; response: TResponse }
: ResultUnion<TResponses, TRequest, TResponse>

/**
* The shape a generated operation returns when `returnType: 'data'` is set: the bare success body
* once `throwOnError` (on by default) narrows away the error branch, falling back to the full
* `RequestResult` when a call sets `throwOnError: false` and still needs `error` to discriminate a
* failed response.
*/
export type UnwrappedResult<TResponses, ThrowOnError extends boolean = true, TRequest = Request, TResponse = Response> = ThrowOnError extends true
? RequestResult<TResponses, true, TRequest, TResponse>['data']
: RequestResult<TResponses, ThrowOnError, TRequest, TResponse>

/**
* Narrows a resolved call down to its success body once `throwOnError` (on by default) rules out
* the error branch, the same default the runtime itself applies. Falls back to the full result for
* a call that sets `throwOnError: false`, since that path still needs `error` to discriminate a
* failed response. Backs `returnType: 'data'`, mirroring how `toEventStream` centralizes the
* post-processing for `text/event-stream` operations.
*/
export function unwrapResult<T extends { data: unknown; error: unknown }>(promise: Promise<T>, throwOnError: boolean | undefined): Promise<T | T['data']> {
return promise.then((result) => ((throwOnError ?? true) ? result.data : result))
}

/**
* The data-shaped keys of the grouped options object, which `Options` re-adds typed per operation.
*/
Expand Down