UNPKG

2.32 kBTypeScriptView Raw
1/** @module commands */
2import { ICommand } from './ICommand';
3import { Parameters } from '../run/Parameters';
4import { ValidationResult } from '../validate/ValidationResult';
5/**
6 * An interface for stackable command intercepters, which can extend
7 * and modify the command call chain.
8 *
9 * This mechanism can be used for authentication, logging, and other functions.
10 *
11 * @see [[ICommand]]
12 * @see [[InterceptedCommand]]
13 */
14export interface ICommandInterceptor {
15 /**
16 * Gets the name of the wrapped command.
17 *
18 * The interceptor can use this method to override the command name.
19 * Otherwise it shall just delegate the call to the wrapped command.
20 *
21 * @param command the next command in the call chain.
22 * @returns the name of the wrapped command.
23 */
24 getName(command: ICommand): string;
25 /**
26 * Executes the wrapped command with specified arguments.
27 *
28 * The interceptor can use this method to intercept and alter the command execution.
29 * Otherwise it shall just delete the call to the wrapped command.
30 *
31 * @param correlationId (optional) transaction id to trace execution through call chain.
32 * @param command the next command in the call chain that is to be executed.
33 * @param args the parameters (arguments) to pass to the command for execution.
34 * @param callback the function that is to be called once execution is complete. If an exception is raised, then
35 * it will be called with the error.
36 *
37 * @see [[Parameters]]
38 */
39 execute(correlationId: string, command: ICommand, args: Parameters, callback: (err: any, result: any) => void): void;
40 /**
41 * Validates arguments of the wrapped command before its execution.
42 *
43 * The interceptor can use this method to intercept and alter validation of the command arguments.
44 * Otherwise it shall just delegate the call to the wrapped command.
45 *
46 * @param command the next command in the call chain to be validated against.
47 * @param args the parameters (arguments) to validate.
48 * @returns an array of ValidationResults.
49 *
50 * @see [[Parameters]]
51 * @see [[ValidationResult]]
52 */
53 validate(command: ICommand, args: Parameters): ValidationResult[];
54}