ObjectStackObjectStack

Events Handlers

Events Handlers protocol schemas

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

PropertyTypeRequiredDescription
idstringoptionalUnique handler identifier
eventNamestringName of event to handle (supports wildcards like user.*)
handleranyHandler function
priorityintegeroptional (default: 0)Execution priority (lower numbers execute first)
asyncbooleanoptional (default: true)Execute in background (true) or block (false)
retry{ maxRetries: integer; backoffMs: integer; backoffMultiplier: number }optionalRetry policy for failed handlers
timeoutMsintegeroptionalHandler timeout in milliseconds
filteranyoptionalOptional filter to determine if handler should execute

Nested Shape: EventHandler.retry

PropertyTypeRequiredDescription
maxRetriesintegeroptional (default: 3)Maximum retry attempts
backoffMsintegeroptional (default: 1000)Initial backoff delay
backoffMultipliernumberoptional (default: 2)Backoff multiplier

EventPersistence

Properties

PropertyTypeRequiredDescription
enabledbooleanoptional (default: false)Enable event persistence
retentionDaysintegerDays to retain persisted events
retentionneveroptional[REMOVED] EventPersistence.retention was renamed to retentionDays in @objectstack/spec 17 — the unit of a duration-shaped number lives in the key name, not only in the describe prose. Rename the key to retentionDays; the value (days) is unchanged.
filteranyoptionalOptional filter function to select which events to persist
storageEnum<'database' | 'file' | 's3' | 'custom'>optional (default: "database")Storage backend for persisted events

EventRoute

Properties

PropertyTypeRequiredDescription
fromstringSource event pattern (supports wildcards, e.g., user.* or *.created)
tostring[]Target event names to route to
transformanyoptionalOptional function to transform payload

On this page