Home Reference Source
import CommandObject from 'ghastly/src/command/CommandObject.js'
public class | source

CommandObject

Class which wraps a command handler with additional useful data.

Static Method Summary

Static Private Methods
private static

generateHandler(handler: Function, middleware: middlewareLayer[]): Function

Applies middleware to a command handler and returns the resulting handler function.

Constructor Summary

Public Constructor
public

Constructor.

Member Summary

Public Members
public

An array of aliases for the command.

public

dependencies: StringMap

A mapping between service names and the context names they should be injected under for the command handler.

public

The description for the command.

public

The name of the group this command is part of, if any.

public

The main trigger of the command, also acting as its name.

public

An array of parameter definitions for the command.

Private Members
private

The command handler function with middleware applied to it.

private

middleware: middlewareLayer[]

The middleware applied to the handler function.

private

The original command handler function.

Method Summary

Public Methods
public

handle(context: Object): Promise<Object>

Executes the command handler.

public

linkGroup(commandGroup: CommandGroup)

Subscribes to updates from a command group.

Static Private Methods

private static generateHandler(handler: Function, middleware: middlewareLayer[]): Function source

Applies middleware to a command handler and returns the resulting handler function.

Params:

NameTypeAttributeDescription
handler Function

The command handler.

middleware middlewareLayer[]

The middleware to apply.

Return:

Function

The command handler with middleware applied to it.

Public Constructors

public constructor(configuration: CommandConfiguration) source

Constructor.

Params:

NameTypeAttributeDescription
configuration CommandConfiguration

The command configuration.

Throw:

TypeError

Thrown if the given configuration is not a plain object.

Public Members

public aliases: string[] source

An array of aliases for the command.

public dependencies: StringMap source

A mapping between service names and the context names they should be injected under for the command handler.

public description: string source

The description for the command.

public group: string source

The name of the group this command is part of, if any.

public name: string source

The main trigger of the command, also acting as its name.

public parameters: ParameterDefinition[] source

An array of parameter definitions for the command.

Private Members

private handler: Function source

The command handler function with middleware applied to it.

private middleware: middlewareLayer[] source

The middleware applied to the handler function.

private originalHandler: Function source

The original command handler function.

Public Methods

public handle(context: Object): Promise<Object> source

Executes the command handler.

Params:

NameTypeAttributeDescription
context Object

The command context.

Return:

Promise<Object>

Promise resolving to the response object.

public linkGroup(commandGroup: CommandGroup) source

Subscribes to updates from a command group.

Params:

NameTypeAttributeDescription
commandGroup CommandGroup

The command group.