ObjectStackObjectStack

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

PropertyTypeRequiredDescription
idstringoptionalUnique execution ID for tracing
objectstring
eventEnum<'beforeFind' | 'afterFind' | 'beforeInsert' | 'afterInsert' | 'beforeUpdate' | 'afterUpdate' | 'beforeDelete' | 'afterDelete'>
inputRecord<string, any>Mutable input parameters
resultanyoptionalOperation result (After hooks only)
previousRecord<string, any>optionalRecord state before operation
dispatch{ mode: Enum<'record' | 'per-row'>; index: integer; scope: Record<string, any> }optionalHow this hook call relates to the caller's write (engine-produced; #6966)
session{ userId?: string; actor?: string; organizationId?: string; accessToken?: string; … }optionalCurrent session context
provenance{ flowRunId?: string; attributedUserId?: string }optionalServer-stamped write provenance (never client-supplied, never an authorization input)
transactionanyoptionalDatabase transaction handle
qlanyObjectQL Engine Reference
apianyoptionalCross-object data access (IScopedContext — object(name) + transaction(cb))
user{ id?: string; name?: string; email?: string; organizationId?: string }optionalCurrent user info shortcut

HookEvent

Allowed Values

  • beforeFind
  • afterFind
  • beforeInsert
  • afterInsert
  • beforeUpdate
  • afterUpdate
  • beforeDelete
  • afterDelete

On this page