Events Handlers
Events Handlers protocol schemas
Event Handler Schema
Defines how to handle a specific event
Source: packages/spec/src/kernel/events/handlers.zod.ts
TypeScript Usage
import { EventHandlerSchema, EventPersistenceSchema, EventRouteSchema } from '@objectstack/spec/kernel';
import type { EventHandler, EventPersistence, EventRoute } from '@objectstack/spec/kernel';
// Validate data
const result = EventHandlerSchema.parse(data);EventHandler
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| id | string | optional | Unique handler identifier |
| eventName | string | ✅ | Name of event to handle (supports wildcards like user.*) |
| handler | any | ✅ | Handler function |
| priority | integer | ✅ | Execution priority (lower numbers execute first) |
| async | boolean | ✅ | Execute in background (true) or block (false) |
| retry | { maxRetries: integer; backoffMs: integer; backoffMultiplier: number } | optional | Retry policy for failed handlers |
| timeoutMs | integer | optional | Handler timeout in milliseconds |
| filter | any | optional | Optional filter to determine if handler should execute |
EventPersistence
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| enabled | boolean | ✅ | Enable event persistence |
| retention | integer | ✅ | Days to retain persisted events |
| filter | any | optional | Optional filter function to select which events to persist |
| storage | Enum<'database' | 'file' | 's3' | 'custom'> | ✅ | Storage backend for persisted events |
EventRoute
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| from | string | ✅ | Source event pattern (supports wildcards, e.g., user.* or *.created) |
| to | string[] | ✅ | Target event names to route to |
| transform | any | optional | Optional function to transform payload |