Sequential dispatch
Matching actions run in order, each receiving config, trigger and signal
await dispatcher.dispatch({
actions: [serialize, persist, index],
trigger: 'submit',
context,
});@schema-engine/actions is the generic action core used across Schema Engine packages.
It provides:
The package is reusable across domains. It is not form-specific.
These playgrounds dispatch through ActionDispatcher. Run an action, or run the whole sequence. Interrupt or reset from the same control.
Matching actions run in order, each receiving config, trigger and signal
await dispatcher.dispatch({
actions: [serialize, persist, index],
trigger: 'submit',
context,
});An inner array runs concurrently and joins before the next entry
await dispatcher.dispatch({
actions: [[analytics, webhook, cache]],
trigger: 'submit',
context,
});Later actions run after a failure unless shouldContinue is false
return { success: false, error: 'conflict', shouldContinue: false };The dispatcher separates the caller-provided base context from the runtime context seen by action handlers.
When an action runs, the dispatcher enriches the base context with the current action config, trigger and cancellation signal before calling execute().
execute({
...context,
config: action,
trigger,
signal,
});At the call site you pass only the base context. The merged runtime shape is constructed internally.
The package has no schema-library runtime dependency. Its schema values use
the provider-neutral Standard Schema contract; applications may choose Zod Mini,
Zod, Valibot, Effect Schema, or another compatible provider.
import * as z from 'zod/mini';
type Trigger = 'submit' | 'change';
type BaseContext = {
userId: string;
metadata?: Record<string, unknown>;
};
type LogConfig = {
id: string;
$type: 'log';
message: string;
enabled?: boolean;
triggers?: readonly string[];
};
const logAction: ActionRegistration<LogConfig, BaseContext, Trigger> = {
$type: 'log',
schema: z.strictObject({
id: z.string(),
$type: z.literal('log'),
message: z.string(),
}),
metadata: {
name: 'Log Message',
description: 'Logs a message',
defaultTriggers: ['submit'],
},
execute: (context) => {
console.log(context.userId, context.trigger, context.config.message);
return { success: true };
},
};
const registry = new ActionRegistry<BaseContext, Trigger>([logAction]);
const dispatcher = new ActionDispatcher(registry);
const baseContext: BaseContext = {
userId: 'user_123',
};
await dispatcher.dispatch({
actions: [{ id: '1', $type: 'log', message: 'Hello' }],
trigger: 'submit',
context: baseContext,
});The handler still receives BaseContext & { config: LogConfig; trigger: Trigger }, but that runtime shape is injected by the dispatcher.