UNPKG

3.1 kBTypeScriptView Raw
1/** @module commands */
2import { ICommand } from './ICommand';
3import { ICommandInterceptor } from './ICommandInterceptor';
4import { Parameters } from '../run/Parameters';
5import { ValidationResult } from '../validate/ValidationResult';
6/**
7 * Implements a [[ICommand command]] wrapped by an interceptor.
8 * It allows to build command call chains. The interceptor can alter execution
9 * and delegate calls to a next command, which can be intercepted or concrete.
10 *
11 * @see [[ICommand]]
12 * @see [[ICommandInterceptor]]
13 *
14 * ### Example ###
15 *
16 * export class CommandLogger implements ICommandInterceptor {
17 *
18 * public getName(command: ICommand): string {
19 * return command.getName();
20 * }
21 *
22 * public execute(correlationId: string, command: ICommand, args: Parameters, callback: (err: any, result: any) => void): void {
23 * console.log("Executed command " + command.getName());
24 * command.execute(correlationId, args, callback);
25 * }
26 *
27 * private validate(command: ICommand, args: Parameters): ValidationResult[] {
28 * return command.validate(args);
29 * }
30 * }
31 *
32 * let logger = new CommandLogger();
33 * let loggedCommand = new InterceptedCommand(logger, command);
34 *
35 * // Each called command will output: Executed command <command name>
36 *
37 */
38export declare class InterceptedCommand implements ICommand {
39 private readonly _interceptor;
40 private readonly _next;
41 /**
42 * Creates a new InterceptedCommand, which serves as a link in an execution chain. Contains information
43 * about the interceptor that is being used and the next command in the chain.
44 *
45 * @param interceptor the interceptor that is intercepting the command.
46 * @param next (link to) the next command in the command's execution chain.
47 */
48 constructor(interceptor: ICommandInterceptor, next: ICommand);
49 /**
50 * @returns the name of the command that is being intercepted.
51 */
52 getName(): string;
53 /**
54 * Executes the next command in the execution chain using the given [[Parameters parameters]] (arguments).
55 *
56 * @param correlationId unique transaction id to trace calls across components.
57 * @param args the parameters (arguments) to pass to the command for execution.
58 * @param callback the function that is to be called once execution is complete. If an exception is raised, then
59 * it will be called with the error.
60 *
61 * @see [[Parameters]]
62 */
63 execute(correlationId: string, args: Parameters, callback: (err: any, result: any) => void): void;
64 /**
65 * Validates the [[Parameters parameters]] (arguments) that are to be passed to the command that is next
66 * in the execution chain.
67 *
68 * @param args the parameters (arguments) to validate for the next command.
69 * @returns an array of ValidationResults.
70 *
71 * @see [[Parameters]]
72 * @see [[ValidationResult]]
73 */
74 validate(args: Parameters): ValidationResult[];
75}