import { SerializedError } from './error_utils'; import { ObjectMap } from './private_utils'; import { Result } from './result'; interface EventEmitterTransport { send(message: SendMessage): void; on(event: 'close', handle: () => void): this; on(event: 'message', handle: (message: ReceiveMessage) => void): this; removeListener(event: 'close', handle: () => void): this; removeListener(event: 'message', handle: (message: ReceiveMessage) => void): this; } /** * A communication link between two concurrent operations which may be * executing in separate operating system processes. */ interface Channel { send(message: TX): void; [Symbol.asyncIterator](): AsyncIterator; } interface Closeable { close(): void; } declare enum ApplicationMessageType { REQUEST = 0, RESPONSE = 1, ERROR = 2 } type Values> = R[keyof R]; type RequestArgs = Parameters>> & any[]; type RequestResults = ReturnType>> extends Promise ? P : never; type RequestMessage = [ ApplicationMessageType.REQUEST, number, CallableKeys>, RequestArgs ]; type ResponseMessage = [ApplicationMessageType.RESPONSE, number, RequestResults] | [ApplicationMessageType.ERROR, number, SerializedError]; /** * An object that receives requests to invoke methods (by receiving "request" * messages) and sends the result (by transmitting "response" and "error" * messages). */ declare class ResponseChannelImplementation Promise; }> { private _inner; private _handles; private _observer; channelClosedPromise: Promise; constructor(inner: Channel, RequestMessage>, handles: Local); private _handleRequestsAsync; [Symbol.asyncIterator](): AsyncIterator<{ method: keyof ChannelMethods; args: RequestArgs; result: Promise>>; }>; } export declare function createEventEmitterChannel(transport: EventEmitterTransport): Channel & Closeable; export declare function createRequestChannel>(inner: Channel, ResponseMessage>): RequestChannel; export declare function createResponseChannel>(inner: Channel, RequestMessage>, handles: H): ResponseChannelImplementation; /** * Values that can be sent over a channel. */ export type ChannelArg = null | boolean | number | string | ChannelArg[] | { [key: string]: ChannelArg; }; type ChannelReturn = Promise | ChannelArg | void; type Anonymize = T extends Promise ? Promise> : T extends ObjectMap ? { [key in keyof T]: Anonymize; } : T; /** * A function with argument and return types that can be sent over a channel. */ export type ChannelFunction any> = T extends (...args: infer Args) => infer Return ? (...args: Extract, [] | ChannelArg[]>) => Extract, ChannelReturn> : never; /** * Keys of an object whose values are anything except never. */ type CallableKeys = { [key in Extract]: T[key] extends (...args: any[]) => any ? T[key] extends ChannelFunction ? key : never : never; }[Extract]; /** * An object with methods that can be called over a channel. */ export type ChannelMethods = { [key in CallableKeys]: T[key]; }; /** * An object that can request the remote invocation of methods (by transmitting * "request" messages) and receive the result (by receiving "response" and * "error" messages). */ export interface RequestChannel> { requestAsync>, F extends T[N], R extends ReturnType>(method: N, ...args: Parameters): Promise ? P : never>; } export declare class RequestChannelAdapter> implements RequestChannel { private _remote; constructor(remote: T); requestAsync>, F extends T[N], R extends ReturnType>(method: N, ...args: Parameters & any[]): Promise ? P : never>; } export {};