@ucanto/transport
Version:
ucanto transport
60 lines • 2.37 kB
TypeScript
export function open<S>({ url, method, fetch, headers }: {
url: URL;
fetch?: ((url: string, init: API.HTTPRequest) => API.Await<FetchResponse>) | undefined;
method?: string | undefined;
headers?: Record<string, string> | undefined;
}): API.Channel<S>;
export type FetchResponse = {
ok: boolean;
arrayBuffer(): API.Await<ArrayBuffer>;
headers: {
entries?: () => Iterable<[string, string]>;
} | Headers;
status?: number;
statusText?: string;
url?: string;
};
export type Fetcher = (url: string, init: API.HTTPRequest) => API.Await<FetchResponse>;
export type Options = {
status?: number;
statusText?: string;
url?: string;
};
import * as API from '@ucanto/interface';
/**
* @template {Record<string, any>} S
* @implements {API.Channel<S>}
*/
declare class Channel<S extends Record<string, any>> implements API.Channel<S> {
/**
* @param {object} options
* @param {URL} options.url
* @param {Fetcher} options.fetch
* @param {string} [options.method]
* @param {Record<string, string>} [options.headers]
*/
constructor({ url, fetch, method, headers }: {
url: URL;
fetch: Fetcher;
method?: string | undefined;
headers?: Record<string, string> | undefined;
});
fetch: Fetcher;
method: string | undefined;
url: URL;
headers: Record<string, string> | undefined;
/**
* @template {API.Tuple<API.ServiceInvocation<API.Capability, S>>} I
* @param {API.HTTPRequest<API.AgentMessage<{ In: API.InferInvocations<I>, Out: API.Tuple<API.Receipt> }>>} request
* @returns {Promise<API.HTTPResponse<API.AgentMessage<{ Out: API.InferReceipts<I, S>, In: API.Tuple<API.Invocation> }>>>}
*/
request<I extends API.Transport.Tuple<API.ServiceInvocation<API.Capability<API.Ability, `${string}:${string}`, any>, S>>>({ headers, body }: API.HTTPRequest<API.AgentMessage<{
In: API.InferInvocations<I>;
Out: API.Transport.Tuple<API.Receipt<any, any, API.Invocation<API.Capability<API.Ability, `${string}:${string}`, unknown>>, API.SigAlg>>;
}>>): Promise<API.HTTPResponse<API.AgentMessage<{
Out: API.InferReceipts<I, S>;
In: API.Transport.Tuple<API.Invocation<API.Capability<API.Ability, `${string}:${string}`, unknown>>>;
}>>>;
}
export {};
//# sourceMappingURL=http.d.ts.map