| title | Hook Body |
|---|---|
| description | Hook Body protocol schemas |
{/*
Capability tokens a script body may request.
The runtime sandbox enforces these — if a body uses a ctx API that requires
a capability it did not declare, the call throws at invocation time.
-
api.read—ctx.api.object(...).find / findOne / count / aggregate -
api.write—ctx.api.object(...).insert / update / delete -
api.transaction—ctx.api.transaction(async () => \{ … \})— runs the
callback's ctx.api writes/reads inside one driver transaction, committed
on return and rolled back if the callback throws. Requires api.write
alongside it to be useful (the transaction body still needs write access).
-
crypto.uuid—ctx.crypto.randomUUID() -
crypto.hash—ctx.crypto.hash(algo, data) -
log—ctx.log.info / warn / error
http.fetch is intentionally absent — outbound calls go through Connector
recipes (separate spec) so they remain auditable and replayable.
**Source:** `packages/spec/src/data/hook-body.zod.ts`import { ExpressionBody, HookBody, HookBodyCapability, ScriptBody } from '@objectstack/spec/data';
import type { ExpressionBody, HookBody, HookBodyCapability, ScriptBody } from '@objectstack/spec/data';
// Validate data
const result = ExpressionBody.parse(data);L1 expression body — pure formula, no IO
| Property | Type | Required | Description |
|---|---|---|---|
| language | string |
✅ | |
| source | string |
✅ | Formula expression source |
Hook/Action body — expression (L1) or sandboxed JS (L2)
This schema accepts one of the following structures:
L1 expression body — pure formula, no IO
| Property | Type | Required | Description |
|---|---|---|---|
| language | string |
✅ | |
| source | string |
✅ | Formula expression source |
L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
| Property | Type | Required | Description |
|---|---|---|---|
| language | string |
✅ | |
| source | string |
✅ | Function body source |
| capabilities | Enum<'api.read' | 'api.write' | 'api.transaction' | 'crypto.uuid' | 'crypto.hash' | 'log'>[] |
✅ | Granted capability tokens |
| timeoutMs | integer |
optional | Per-invocation timeout (ms) |
| memoryMb | integer |
optional | Per-invocation memory cap (MB) |
api.readapi.writeapi.transactioncrypto.uuidcrypto.hashlog
L2 sandboxed JS body — runs inside an isolated VM with declared capabilities
| Property | Type | Required | Description |
|---|---|---|---|
| language | string |
✅ | |
| source | string |
✅ | Function body source |
| capabilities | Enum<'api.read' | 'api.write' | 'api.transaction' | 'crypto.uuid' | 'crypto.hash' | 'log'>[] |
✅ | Granted capability tokens |
| timeoutMs | integer |
optional | Per-invocation timeout (ms) |
| memoryMb | integer |
optional | Per-invocation memory cap (MB) |