@api.global/typedrequest
Version:
A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.
54 lines (53 loc) • 2.08 kB
TypeScript
import * as plugins from './plugins.js';
import { TypedRouter } from './typedrequest.classes.typedrouter.js';
export interface ICommFunctions {
sendMethod?: (sendPayload: plugins.typedRequestInterfaces.IStreamRequest) => Promise<plugins.typedRequestInterfaces.IStreamRequest>;
typedrouter?: TypedRouter;
}
/**
* 1. A VirtualStream connects over the network
* 2. It is always paired to one other VirtualStream
* on the other side with the same streamId.
* 3. It has a Readable and Writable side.
* 4. The Writable side is Readable on the other side and vice versa.
*/
export declare class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterfaces.IVirtualStream<T> {
static encodePayloadForNetwork(objectPayload: any, commFunctions: ICommFunctions, originalPayload?: any, path?: any[]): any;
static decodePayloadFromNetwork(objectPayload: any, commFunctions: ICommFunctions): any;
side: 'requesting' | 'responding';
streamId: string;
sendMethod: ICommFunctions['sendMethod'];
typedrouter: TypedRouter;
private keepAlive;
private lastKeepAliveEvent;
private sendBackpressuredArray;
private receiveBackpressuredArray;
constructor();
/**
* takes care of sending
*/
private workOnQueue;
/**
* This method handles the stream only on the responding side
* @param streamTrArg
* @returns
*/
handleStreamTr(streamTrArg: plugins.typedRequestInterfaces.IStreamRequest): Promise<plugins.typedRequestInterfaces.IStreamRequest>;
/**
* closes the virtual stream
*/
cleanup(): Promise<void>;
/**
* a keepAlive loop that works across technologies
*/
private startKeepAliveLoop;
private triggerKeepAlive;
sendData(dataArg: T): Promise<void>;
fetchData(): Promise<T>;
/**
* reads from a Readable and sends it to the other side
* @param readableStreamArg
*/
readFromWebstream(readableStreamArg: ReadableStream<T>): Promise<void>;
writeToWebstream(writableStreamArg: WritableStream<T>): Promise<void>;
}