async-streamify
Version:
Stream and serialize nested promises and async iterables over HTTP, workers, etc
35 lines • 1.27 kB
TypeScript
/**
* Deserializes a streaming NDJSON response into its original object form,
* reconstructing promises and async iterables.
*
* @template T - The expected type of the deserialized object
* @param response - The Response object containing the serialized NDJSON stream
* @returns Promise<T> - A promise that resolves with the deserialized object
*
* @example
* ```typescript
* // Fetching and deserializing a response
* const response = await fetch("https://api.example.com/stream");
* const data = await deserializeResponse<{
* status: string;
* result: Promise<{ completed: boolean }>;
* updates: AsyncIterable<string>;
* }>(response);
*
* console.log(data.status); // "processing"
* console.log(await data.result); // { completed: true }
* for await (const update of data.updates) {
* console.log(update); // "step 1", "step 2"
* }
* ```
*/
export declare function deserializeResponse<T extends object>(response: Response, opts?: {
transformers?: ((value: any) => object)[];
}): Promise<T>;
/**
* Alias for deserializeResponse
* @template T - The expected type of the deserialized object
*/
export declare const fromResponse: typeof deserializeResponse;
export default deserializeResponse;
//# sourceMappingURL=response.d.ts.map