Skip to content
Merged
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
22 changes: 12 additions & 10 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
import { computeURI } from "./agents.js";
import * as Utils from "./utils.js";

export type StreamOptions = Omit<RequestOptions, "limit">;
export type StreamOptions<TOpaque = null> = Omit<RequestOptions, "limit"> & {
opaque?: TOpaque;
};

export function pipeline(
export function pipeline<TOpaque = null>(
method: HttpMethod | WebDavMethod,
uri: string | URL,
options: StreamOptions = {}
options: StreamOptions<TOpaque> = {}
): Duplex {
const computedURI = computeURI(method, uri);
if (typeof options.querystring !== "undefined") {
Expand All @@ -41,23 +43,23 @@ export function pipeline(
}, ({ body }) => body);
}

export type WritableStreamCallback = (
factory: undici.Dispatcher.StreamFactory
) => Promise<undici.Dispatcher.StreamData>;
export type WritableStreamCallback<TOpaque = null> = (
factory: undici.Dispatcher.StreamFactory<TOpaque>
) => Promise<undici.Dispatcher.StreamData<TOpaque>>;

export function stream(
export function stream<TOpaque = null>(
method: HttpMethod | WebDavMethod,
uri: string | URL,
options: StreamOptions = {}
): WritableStreamCallback {
options: StreamOptions<TOpaque> = {}
): WritableStreamCallback<TOpaque> {
const computedURI = computeURI(method, uri);

const dispatcher = options.agent ?? computedURI.agent ?? void 0;
const headers = Utils.createHeaders({ headers: options.headers, authorization: options.authorization });
const body = Utils.createBody(options.body, headers);

return (factory) => undici
.stream(
.stream<TOpaque>(
computedURI.url,
{ method: method as HttpMethod, headers, body, dispatcher },
factory
Expand Down
Loading