Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandSet

Contains a set of commands and events supported by a commandable object. The CommandSet supports command interceptors to extend and the command call chain.

CommandSets can be used as alternative commandable interface to a business object. It can be used to auto generate multiple external services for the business object without writing much code.

see

Command

see

Event

see

ICommandable

Example

export class MyDataCommandSet extends CommandSet {
    private _controller: IMyDataController;

    constructor(controller: IMyDataController) { // Any data controller interface
        super();
        this._controller = controller;
        this.addCommand(this.makeGetMyDataCommand());
    }

    private makeGetMyDataCommand(): ICommand {
        return new Command(
          'get_mydata',
          null,
          (correlationId: string, args: Parameters, callback: (err: any, result: any) => void) => {
              let param = args.getAsString('param');
              this._controller.getMyData(correlationId, param, callback);
          }
        );
    }
}

Hierarchy

  • CommandSet

Index

Constructors

constructor

  • Creates an empty CommandSet object.

    Returns CommandSet

Methods

addCommand

  • Adds a command to this command set.

    see

    ICommand

    Parameters

    Returns void

addCommandSet

  • Adds all of the commands and events from specified command set into this one.

    Parameters

    Returns void

addCommands

  • addCommands(commands: ICommand[]): void
  • Adds multiple commands to this command set.

    see

    ICommand

    Parameters

    • commands: ICommand[]

      the array of commands to add.

    Returns void

addEvent

  • addEvent(event: IEvent): void
  • Adds an event to this command set.

    see

    IEvent

    Parameters

    • event: IEvent

      the event to add.

    Returns void

addEvents

  • addEvents(events: IEvent[]): void
  • Adds multiple events to this command set.

    see

    IEvent

    Parameters

    • events: IEvent[]

      the array of events to add.

    Returns void

addInterceptor

addListener

  • Adds a listener to receive notifications on fired events.

    see

    IEventListener

    Parameters

    Returns void

execute

  • execute(correlationId: string, commandName: string, args: Parameters, callback: function): void
  • Executes a command specificed by its name.

    see

    ICommand

    see

    Parameters

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • commandName: string

      the name of that command that is to be executed.

    • args: Parameters

      the parameters (arguments) to pass to the command for execution.

    • callback: function

      the function that is to be called once execution is complete. If an exception is raised, then it will be called with the error (for example: a ValidationException can be thrown).

        • (err: any, result: any): void
        • Parameters

          • err: any
          • result: any

          Returns void

    Returns void

findCommand

  • findCommand(commandName: string): ICommand
  • Searches for a command by its name.

    see

    ICommand

    Parameters

    • commandName: string

      the name of the command to search for.

    Returns ICommand

    the command, whose name matches the provided name.

findEvent

  • findEvent(eventName: string): IEvent
  • Searches for an event by its name in this command set.

    see

    IEvent

    Parameters

    • eventName: string

      the name of the event to search for.

    Returns IEvent

    the event, whose name matches the provided name.

getCommands

  • Gets all commands registered in this command set.

    see

    ICommand

    Returns ICommand[]

    a list of commands.

getEvents

  • Gets all events registred in this command set.

    see

    IEvent

    Returns IEvent[]

    a list of events.

notify

  • notify(correlationId: string, eventName: string, args: Parameters): void
  • Fires event specified by its name and notifies all registered listeners

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • eventName: string

      the name of the event that is to be fired.

    • args: Parameters

      the event arguments (parameters).

    Returns void

removeListener

validate

  • Validates args for command specified by its name using defined schema. If validation schema is not defined than the methods returns no errors. It returns validation error if the command is not found.

    see

    Command

    see

    Parameters

    see

    ValidationResult

    Parameters

    • commandName: string

      the name of the command for which the 'args' must be validated.

    • args: Parameters

      the parameters (arguments) to validate.

    Returns ValidationResult[]

    an array of ValidationResults. If no command is found by the given name, then the returned array of ValidationResults will contain a single entry, whose type will be ValidationResultType.Error.

Generated using TypeDoc