UNPKG

@api.global/typedrequest

Version:

A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.

61 lines (60 loc) 2.35 kB
import * as plugins from './plugins.js'; import { TypedRouter } from './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(); workingDeferred: plugins.smartpromise.Deferred<void>; /** * 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>, closeAfterReading?: boolean): Promise<void>; writeToWebstream(writableStreamArg: WritableStream<T>): Promise<void>; /** * closes the stream * if sendClosingBitArg is true, the stream will send a closing bit * @param sendClosingBitArg */ close(sendClosingBitArg?: boolean): Promise<void>; }