enum ResultStatus {
Success,
Failure
}
interface CommandResult {
status: ResultStatus;
value?: any;
error?: string;
}
interface CommandHandler extends Function {}
interface SyncedCommandHandler extends CommandHandler {
(context: app.modules.ModuleContext, ...params: any[]): CommandResult;
}
interface AsyncedCommandHandler extends CommandHandler {
(context: app.modules.ModuleContext, ...params: any[]): Promise<CommandResult>;
}
interface CommandDescriptor extends ComponentDescriptor {
returns: types.TypeDefinition;
convert?: {
from: string;
converter?: string;
};
syntax: string | string[];
async?: boolean;
}
interface LocalCommandDescriptor extends CommandDescriptor {
handler: CommandHandler;
parametersForm?: "list" | "arguments" | "map" | "struct";
}
interface RemoteCommandDescriptor extends CommandDescriptor {
handler: {
endpoint: string;
method?: string;
}
}
-
status
required
ResultStatus
The status for the execution
-
value
optional
any
The result of the execution in case of success.
-
error
optional
string
An error message in case of failure.
-
returns
required
StringTypeDefinition
The type definition of the value of successful executions.
-
convert
optionl
If the command execution (locally or remotely) needs to be converted specify the type of the result (
from
) and the name of the converter to use.
The converter is optional, if not included a converter that is suited will be looked up. -
syntax
required
array
ofstring
An array of syntax rules which will be used to execute this command.
-
async
optional
boolean
Whether or not this command execution is asynced, default to
false
.
-
handler
required
function
The javascript function which will be executed per invocation of this command.
In case ofsynced
commands the handler function should return the value wrapped in aCommandResult
.
Remote command handlers need to return aPromise
to aCommandResult
. -
parametersForm
optional
string
Specify the way the javascript function receives the parameters.
The options are:- "list": the function will receive all params in an array
- "arguments": the function will receive the params as regular js named params
- "map": the function will receive the params in the fugazi
FugaziMap
type - "struct": the function will receive the params in a simple js object.
Defaults to
arguments
.
-
handler.endpoint
required
string
The url path to be added to the base url in order to make a request to this command endpoint.
-
handler.method
optional
string
The HTTP method to be used when making the request.
Possible values are the supported methods defined by the HTTP protocol (GET
,POST
,DELETE
, etc) in lower or upper case.
Defaults toGET
.