import { Executor, Method, Manifest, Params } from './Executor'; import { JsonRpcRequest } from './JsonRpcRequest'; import { JsonRpcResponse } from './JsonRpcResponse'; import { Transport } from './Transports'; interface Notification { id: number; date: Date; subject: string; message: string; } /** * A client to a remote, out of process, `Executor`. * * Implements asynchronous, methods for `Executor` methods `call` and `notify` * which send JSON-RPC requests to a `Server` that is serving the remote `Executor`. */ export declare abstract class Client extends Executor { /** * A map of requests to which responses can be paired against * * The key is the unique id for each request. */ private requests; /** * A cached manifest from the remote executor. */ manifestCached: Manifest | undefined; /** * Notifications cache * * Intended to be consumed by by applications * e.g. by displaying them to the user. */ notifications: Notification[]; /** * Count of notifications received * * Used to give a unique, sequential, identifier to each * new notification. */ notificationsCount: number; /** * Maximum length of the notifications cache * * Used to avoid excessive memory usage for unhandled * notifications. */ notificationsLength: number; /** * Construct a `Client`. * * @param family The two letter prefix for the id of this client */ constructor(family?: string); /** * @override Override of {@link Executor.manifest} to * return the manifest of the remote executor. */ manifest(): Promise; /** * @override Override of {@link Executor.cancel} to * request the remote executor to cancel a job. */ cancel(job: string): Promise; /** * @implements Implements {@link Executor.call} by sending a * a request to the remote `Executor` that this client is connected to. */ call(method: Method, params?: Params): Promise; /** * @override Override of {@link Executor.notify} to send a notification * to the `Executor` that this client is connected to. */ notify(subject: string, message: string): Promise; /** * @override Override of {@link Executor.notified} to cache * notifications received by this client instead on just * logging them. */ notified(subject: string, message: string): void; /** * Send a request to the server. * * This method must be overridden by derived client classes to * send the request over the transport used by that class. * * @param request The JSON-RPC request */ protected abstract send(request: JsonRpcRequest): Promise; /** * Receive a response from the server. * * Usually called asynchronously via the `send` method of a derived class * when a response is returned. Uses the `id` of the response to match it to the corresponding * request and resolve it's promise. * * Logs errors, rather than throwing exceptions, if the server sends a bad * response because this method is called asynchronously when a message * is received and to avoid crashing the process. * * @param message A JSON-RPC response (to a request) or a notification. */ protected receive(message: string | JsonRpcResponse | JsonRpcRequest): void; /** * @override Override of {@link Executor.stop} that rejects * all outstanding requests. * * @description If outstanding requests are not rejected * like this then they cant `await` for ever, after the * client has stopped. This could be implemented to * have a grace period. */ stop(): Promise; } /** * Interface for a client type. */ export interface ClientType { /** * Construct a client of this type. */ new (address: any): Client; /** * Discover servers for this type of client. * * This static method should be implemented by * client classes and return an array of clients * having that type. */ discover: (address?: string) => Promise; } /** * Get the transport for a client type * * @param client The client type name, constructor or instance */ export declare function clientTypeToTransport(client: string | Function | Client): Transport | undefined; /** * Get the client type for a transport. * * @param transport The transport to translate. */ export declare function transportToClientType(transport: Transport | string): string | undefined; /** * Translate an address string into one or more clients. * * If the address is a "discovery address" e.g. `stdio://*` * then discovery for the transport will be done and zero * or more clients returns. For other addresses, a single * client will be returned, unless there is an error in the * address in which case none will be returned. * * @param addressStr Address string to translate. * @param clientTypes Array of client types available to be translated to. */ export declare function addressToClients(addressStr: string, clientTypes: ClientType[]): Promise; /** * Translate an array of address strings into an array of * clients. * * @param addresses Array of address strings to translate. * @param clientTypes Array of client types available to be translated to. */ export declare function addressesToClients(addresses: string[], clientTypes: ClientType[]): Promise; export {};