import { Client, ClientType } from './Client'; import { Executor, Manifest, Method, Params } from './Executor'; /** * A instance of a `Executor` used as a peer * to delegate method calls to. */ export declare class Peer { /** * The client used to communicate with the peer executor */ client?: Client; /** * Classes of `Client` that can be used * to (re)connect to the peer executor. */ readonly clientTypes: ClientType[]; /** * The manifest of the peer executor. */ manifest?: Manifest; /** * Ajv validation functions for each method. * * Validation functions are just-in-time compiled * in the `capable` method. */ private validators; /** * Construct a `Peer`. * * @param executor A `Client`, `Executor`, or a executor `Manifest`. * @param clientTypes A list of classes, that extend `Client`, and are available * to reconnect to peer executors. */ constructor(executor: Executor | Manifest, clientTypes?: ClientType[]); /** * Initialize the peer. */ start(): Promise; /** * Update the peer with a new manifest. * * This method updates the manifest and resets the * capability validation functions. * * @param manifest The new manifest */ update(manifest: Manifest): void; /** * Stop the peer client. * * This is important for stopping child * processes that may have spawned by `StdioClient` * during delegation. */ stop(): Promise; /** * Test whether the peer is capable of executing the * method with the supplied parameters. * * Just-in-time compiles the JSON Schema for each capability * into a validator function that is used to "validate" * the parameters. * * @param method The method to be called * @param params The parameter values of the call */ capable(method: Method, params: { [key: string]: unknown; }): Promise; /** * Reconnect to the `Executor`. * * Finds the first client type that the peer * executor supports. */ connect(reconnect?: boolean): Promise; /** * Call a method of a remote `Executor`. * * Ensures that there is a connection to the * executor and then passes the request to it. * * @param method The name of the method * @param params Values of parameters (i.e. arguments) */ call(method: Method, params?: { [key: string]: any; }): Promise; } /** * An `Executor` class that delegates to peers. * * This executor class has no capabilities itself and * instead, delegates to other executors. If unable * to delegate to a peer, then calls a fallback function * which can be used to perform other handling. */ export declare class Delegator extends Executor { /** * Classes of `Client` that can be used * to connect to peer executors. * * This allows for dependency injection: * rather than importing clients for all transports into this module when they may * not be used (e.g. `StdioClient` in a browser hosted `Executor`). * The order of this list, defines the preference for the transport. */ protected readonly clientTypes: ClientType[]; /** * Peer executors that are delegated to depending * upon their capabilities and the particular request. */ protected readonly peers: { [key: string]: Peer; }; /** * A map of jobs to the peers that they have been delegated to. * * Used to route the cancellation of a job to the peer that * it was originally delegated to. */ protected readonly jobs: { [key: string]: Peer; }; /** * Construct a `Delegator`. */ constructor(executors?: Executor[], clientTypes?: ClientType[]); /** * @override Override of {@link Executor.manifest} to * provide additional properties for inspection. */ manifest(): Promise; /** * @override Override of {@link Executor.cancel} that passes on the * cancellation request to the peer that was delegated the job. */ cancel(job: string): Promise; /** * @override Override of {@link Executor.call} that delegates * calls to peers where possible. */ call(method: Method, params?: Params): Promise; add(executor: Executor): string; update(id: string, manifest: Manifest): void; remove(id: string): void; /** * @override Override of {@link Executor.stop} which * stops any child processes it may have started. */ stop(): Promise; }