Code0 LogoCodeZero

Event

User-facing event (flow type) definitions and decorators

An Event is a user-facing flow type that appears in the Code0 platform UI as a trigger for flows. It is always linked to a RuntimeEvent which defines the internal behaviour.

import { Identifier, Name, Editable } from '@code0-tech/hercules';

Overview

Events follow the same two-layer pattern as functions:

  • RuntimeEvent — the internal event definition (identifier, signature, settings)
  • Event — extends the RuntimeEvent, adds public metadata, registered separately
// Internal layer
@Identifier('user_created')
@Signature('(userId: number): void')
@Name({ code: 'en-US', content: 'User Created' })
export class UserCreatedRuntimeEvent {}

// Public layer
@Identifier('user_created_event')
@Name({ code: 'en-US', content: 'On User Created' })
@Editable(false)
export class UserCreatedEvent extends UserCreatedRuntimeEvent {}

Register both with the Action:

action.registerRuntimeEventClass(UserCreatedRuntimeEvent);
action.registerEventClass(UserCreatedEvent);

The resulting descriptor stored in action.events is documented on the EventManager page.

EventClass

type EventClass<T extends RuntimeEventClass = RuntimeEventClass> = new () => InstanceType<T>;

The constructor type used when calling action.registerEventClass().

Firing an Event

await action.fire(UserCreatedRuntimeEvent, projectId, { userId: 42 });

See action.fire() for the full reference.

Decorators

DecoratorDescription
@IdentifierSets the unique runtime identifier
@NameSets the localised display name
@DescriptionSets a short localised description
@DocumentationSets long-form documentation text
@DisplayMessageSets the summary text shown in the flow UI
@AliasSets alternative search terms
@DeprecationMessageMarks the event as deprecated
@SignatureSets the TypeScript-like signature string
@DisplayIconSets the icon shown in the flow UI
@EditableControls editability in the platform UI
@EventSettingAdds a configurable setting
@OmitEventPrevents auto-generation of a public event definition

On this page