import * as schema from '@stencila/schema'; import { JSONSchema7Definition } from 'json-schema'; import { Addresses, Transport } from './Transports'; /** * The methods of an `Executor` class. */ export declare enum Method { manifest = "manifest", decode = "decode", encode = "encode", query = "query", compile = "compile", build = "build", execute = "execute", begin = "begin", end = "end", pipe = "pipe", cancel = "cancel" } /** * The parameters of a call to a method */ export declare type Params = { [key: string]: any; }; /** * The capabilities of an `Executor` class as * a mapping of method name to a JSON Schema object * specifying constraints for parameters. * * An executor does not need to defined a capability * for all methods. A missing capability implies no * capability for that method. */ export interface Capabilities { [key: string]: JSONSchema7Definition | JSONSchema7Definition[]; } /** * The manifest for an `Executor` class * describing it's capabilities, addresses that * can be used to connect to it etc. * * All properties are optional to reduce the * number of assumptions that need to be made * in handling manifests read from file, or received * over the network. * * Executor implementations may add other properties * to the manifest for inspection purposes * (e.g. debugging, monitoring). */ export interface Manifest { /** * The version of the manifest schema */ version: number; /** * The id of the `Executor` */ id?: string; /** * The capabilities of the executor */ capabilities?: Capabilities; /** * The addresses of servers that can be used * to communicate with the executor */ addresses?: Addresses; /** * Other properties that `Executor` * implementations may wish to add * e.g. package name and version */ [key: string]: any; } /** * Information used in some methods for * authorization (e.g. limiting the number * of users accessing a session, limiting * the resources used by a session) */ export interface Claims { user?: { id: string; }; client?: { type: Transport; id: string; }; session?: schema.SoftwareSession; [key: string]: any; } /** * Interface for `Executor` classes and their proxies. */ export declare abstract class Executor { /** * The unique id of this executor. * * Used for better tracing and to avoid duplicate * entries for an executor (e.g. due to having multiple servers * and therefore multiple addresses) */ readonly id: string; /** * Construct an executor. * * @param family A two letter code used to help * identify the type of executor */ constructor(family?: string); /** * Get the addresses of this executor. * * Derived classes can override this method * to provide addresses in their manifest. */ addresses(): Promise; /** * Get the capabilities of this executor. * * Derived classes can override this method * to provide capabilities in their manifest. */ capabilities(): Promise; /** * Get the manifest of the executor. * * @see {@link Capabilities} * @see {@link Addresses} */ manifest(): Promise; /** * Decode content to a `Node`. * * @param source The source of the content to decode * @param format The format of the content * @returns The decoded node */ decode(source: string, format?: string): Promise; /** * Encode a `Node` in a format. * * @param node The node to encode * @param dest The destination for the encoded content * @param format The format to encode * @returns The encoded content, or the destination of the content. */ encode(node: schema.Node, dest?: string, format?: string): Promise; /** * Query a `Node`. * * Currently allows for two query languages: * * - `jmp`: [JMESPath](http://jmespath.org/) (default) * - `jpo`: [JSONPointer](https://tools.ietf.org/html/rfc6901) */ query(node: schema.Node, query: string, lang: string): Promise; /** * Compile a `Node`. * * @param node The node to compile * @returns The compiled node */ compile(node: Type): Promise; /** * Build a `Node`. * * @param node The node to build * @returns The build node */ build(node: Type): Promise; /** * Execute a `Node`. * * @param node The node to execute * @param session The session that the node will be executed in * @param claims The `Claims` made for the call * @param job The unique id of the request * @returns The node, with updated properties, after it has been executed */ execute(node: Type, session?: schema.SoftwareSession, claims?: Claims, job?: string): Promise; /** * Begin running a `Node`. * * This method keeps a document "running", usually to allow it to react * to changes within it. Compare this to `execute()` which will not wait * and will simply execute all nodes in the document. * The document will keep running until the `end()` method is called on it. * * Usually this method is called with a `SoftwareSession` as the * `node` argument. However, it could also be called with another `Node` * type, e.g. an `Article`, in which case the executor may begin it's * `session` property, or default session if that property is missing. * * @param node The node to run, usually but not necessarily, a `SoftwareSession` * @param claims The `Claims` made for the call * @returns The node, with updated properties, after it has begun running */ begin(node: Type, claims?: Claims): Promise; /** * End running a `Node`. * * @param node The running node, usually but not necessarily, a `SoftwareSession` * @param claims The `Claims` made for the call * @returns The node, with updated properties, after it has ended running */ end(node: Type, claims?: Claims): Promise; /** * Call a pipeline of methods passing the result of each call as the * first argument of the next call. * * This method is a "meta" method that is used to chain together calls to other methods. * When using a remote executor, it is more efficient than chaining those calls together * "by hand" because it only involves one round trip request to the executor. * * @param node The node to pipe through methods * @param calls A list of method, parameters tuples to pipe the node through * @returns The node after it has been piped through the methods */ pipe(node: schema.Node, calls: (Method | [Method, Params])[]): Promise; /** * Cancel a previous request to call a method * * @param job The unique id of the request to be cancelled. * @returns Whether or not the request was cancelled. */ cancel(job: string): Promise; /** * Dispatch a call to one of the above methods. * * This method does run time dispatching. It is used * by classes such as `Server` (to fulfil a JSON-RPC request), * `Queuer` (to remove calls from a queue) and in `Worker` * for implementing the `pipe` method. * * It does runtime checking for the method name and * required parameters. */ dispatch(method: Method, params?: Params): Promise; /** * A fallback implementation of one of the above methods. * * Since this base executor has no capabilities, this method * simply throws a `CapabilityError`. Derived classes, may * override this method, and /or one of the methods above. * * Provided so that derived classes such as `Client`, `Delegator` * and `Queuer` can override a single method to provide their * functionality instead of having to implement each of the above methods. * * @param method The name of the method * @param params Values of parameters (i.e. arguments) * @param request The request id */ call(method: Method, params: Params): Promise; /** * Send a notification * * @param level The notification level e.g. `info`, `error` * @param message The notification message * @param node The node to which this notification relates e.g. a `SoftwareSession` * @param clients The ids of the clients to send the notification to. If missing send to all clients. */ notify(level: string, message: string, node?: schema.Node, clients?: string[]): Promise; /** * Receive a notification * * @param level The notification level e.g. `info`, `error` * @param message The notification message * @param node The node to which this notification relates e.g. a `SoftwareSession` */ notified(level: string, message: string, node?: schema.Node): void; /** * Start the executor * * Derived classes may override this method. */ start(): Promise; /** * Stop the executor * * Derived classes may override this method. */ stop(): Promise; }