Hook
Hook protocol schemas
Hook Lifecycle Events Defines the interception points in the ObjectQL execution pipeline.
Source: packages/spec/src/data/hook.zod.ts
TypeScript Usage
import { HookContextSchema, HookEvent } from '@objectstack/spec/data';
import type { HookContext } from '@objectstack/spec/data';
// Validate data
const result = HookContextSchema.parse(data);HookContext
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| id | string | optional | Unique execution ID for tracing |
| object | string | ✅ | |
| event | Enum<'beforeFind' | 'afterFind' | 'beforeInsert' | 'afterInsert' | 'beforeUpdate' | 'afterUpdate' | 'beforeDelete' | 'afterDelete'> | ✅ | |
| input | Record<string, any> | ✅ | Mutable input parameters |
| result | any | optional | Operation result (After hooks only) |
| previous | Record<string, any> | optional | Record state before operation |
| dispatch | { mode: Enum<'record' | 'per-row'>; index: integer; scope: Record<string, any> } | optional | How this hook call relates to the caller's write (engine-produced; #6966) |
| session | { userId?: string; actor?: string; organizationId?: string; accessToken?: string; … } | optional | Current session context |
| provenance | { flowRunId?: string; attributedUserId?: string } | optional | Server-stamped write provenance (never client-supplied, never an authorization input) |
| transaction | any | optional | Database transaction handle |
| ql | any | ✅ | ObjectQL Engine Reference |
| api | any | optional | Cross-object data access (IScopedContext — object(name) + transaction(cb)) |
| user | { id?: string; name?: string; email?: string; organizationId?: string } | optional | Current user info shortcut |
HookEvent
Allowed Values
beforeFindafterFindbeforeInsertafterInsertbeforeUpdateafterUpdatebeforeDeleteafterDelete