TriggerSchema
Stable · since 0.1.0
TriggerSchema is the single generic parameter you pass to createTrigger. It describes the complete typed surface of a trigger — every event it reacts to, every condition it can read, and every action it can call. All three keys are optional; an empty schema ({}) is valid for triggers that have no inputs and no outputs.
Import
Section titled “Import”Definition
Section titled “Definition”Fields
Section titled “Fields”| Field | Type | Required | Description |
|---|---|---|---|
events | Record<string, unknown> | optional | Map of eventName → payloadType. Use void for events with no payload. |
conditions | Record<string, unknown> | optional | Map of conditionName → valueType. Values flow pull-only (runtime calls the getter at fire-time). |
actions | Record<string, unknown> | optional | Map of actionName → payloadType. Use void for parameter-less actions. |
Naming conventions
Section titled “Naming conventions”The library doesn’t enforce a casing convention — any string is a valid key. Common practice in the Triggery ecosystem:
- Events: kebab-case verbs scoped by domain —
'new-message','cta:click','session-expired'. - Conditions: camelCase nouns —
user,activeChannelId,featureFlags. - Actions: camelCase verbs —
showToast,playSound,setUser.
This pairs cleanly with the createNamedHooks helper, which converts kebab/camel keys to PascalCase hook names ('new-message' → useNewMessageEvent).
Examples
Section titled “Examples”Empty schema
Section titled “Empty schema”Events-only schema
Section titled “Events-only schema”Full schema with all three maps
Section titled “Full schema with all three maps”Discriminated event union
Section titled “Discriminated event union”The event field in the handler context is a discriminated union over S['events']:
Related
Section titled “Related” createTrigger The constructor that consumes this schema.
TriggerCtx The handler context — built from the schema.
Trigger anatomy guide Field-by-field walkthrough.
createNamedHooks Generate PascalCase hooks from the schema.