Action
The root class for every Hercules action
Action is the entry point of every Hercules action. It manages the gRPC connection to Aquila, holds all registered
functions, events, and data types, and emits lifecycle events you can subscribe to.
import { Action } from '@code0-tech/hercules';Constructor
new Action(
identifier: string,
version: string,
aquilaUrl: string | undefined,
author: string,
icon: string,
documentation: string,
name: Translation[],
configurationDefinitions?: ConfigurationDefinition[]
)Prop
Type
Example
const action = new Action(
'my-action',
'1.0.0',
'aquila.example.com:8081',
'my-org',
'tabler:bolt',
'Does something useful',
[{ code: 'en-US', content: 'My Action' }],
[
{
identifier: 'API_KEY',
type: 'string',
name: [{ code: 'en-US', content: 'API Key' }],
},
],
);Properties
Managers
Each manager is a key-value store backed by a Map. See BaseManager for available methods.
Prop
Type
Getters
Prop
Type
Methods
registerFunction
action.registerFunction<T extends RuntimeFunctionClass>(klass: FunctionClass<T>): voidRegisters a public-facing function definition. The class must extend a RuntimeFunctionClass.
action.registerFunction(FibonacciFunction);registerRuntimeFunction
action.registerRuntimeFunction(klass: RuntimeFunctionClass): voidRegisters a runtime function implementation. Unless @OmitRuntimeFunction() is applied, a matching FunctionProps
entry is also created automatically.
action.registerRuntimeFunction(FibonacciRuntimeFunction);registerDataTypeClass
action.registerDataTypeClass(klass: DataTypeClass): voidRegisters a custom data type.
registerEventClass
action.registerEventClass(klass: EventClass): voidRegisters a user-facing event (flow type).
registerRuntimeEventClass
action.registerRuntimeEventClass(klass: RuntimeEventClass): voidRegisters a runtime event definition. Unless @OmitEvent() is applied, a matching EventModel entry is also created
automatically.
connect
action.connect(authToken: string, aquilaUrl?: string, grpcOptions?: GrpcOptions): Promise<void>Opens the gRPC connection to Aquila, sends the module descriptor, and starts processing the incoming stream.
Prop
Type
await action.connect(process.env.AUTH_TOKEN!);fire
action.fire(
eventClass: EventClass | RuntimeEventClass,
projectId: number | bigint,
payload: PlainValue
): Promise<void>Dispatches an event to Aquila for a specific project. Throws if connect() has not been called or if the class is
missing an @Identifier decorator.
Prop
Type
await action.fire(UserCreatedRuntimeEvent, projectId, { userId: 42 });All manager properties on Action extend BaseManager.
Action extends Node.js EventEmitter — see CodeZeroEvent for all available events.