---
title: Hook
description: Hook protocol schemas
---

{/* ⚠️  AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs go in content/docs/guides/. */}

Hook Lifecycle Events

Defines the interception points in the ObjectQL execution pipeline.

<Callout type="info">
**Source:** `packages/spec/src/data/hook.zod.ts`
</Callout>

## TypeScript Usage

```typescript
import { HookContext, HookEvent } from '@objectstack/spec/data';
import type { HookContext, HookEvent } from '@objectstack/spec/data';

// Validate data
const result = HookContext.parse(data);
```

---

## HookContext

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **id** | `string` | optional | Unique execution ID for tracing |
| **object** | `string` | ✅ |  |
| **event** | `Enum<'beforeFind' \| 'afterFind' \| 'beforeFindOne' \| 'afterFindOne' \| 'beforeCount' \| 'afterCount' \| 'beforeAggregate' \| 'afterAggregate' \| 'beforeInsert' \| 'afterInsert' \| 'beforeUpdate' \| 'afterUpdate' \| 'beforeDelete' \| 'afterDelete' \| 'beforeUpdateMany' \| 'afterUpdateMany' \| 'beforeDeleteMany' \| 'afterDeleteMany'>` | ✅ |  |
| **input** | `Record<string, any>` | ✅ | Mutable input parameters |
| **result** | `any` | optional | Operation result (After hooks only) |
| **previous** | `Record<string, any>` | optional | Record state before operation |
| **session** | `Object` | optional | Current session context |
| **transaction** | `any` | optional | Database transaction handle |
| **ql** | `any` | ✅ | ObjectQL Engine Reference |
| **api** | `any` | optional | Cross-object data access (ScopedContext) |
| **user** | `Object` | optional | Current user info shortcut |


---

## HookEvent

### Allowed Values

* `beforeFind`
* `afterFind`
* `beforeFindOne`
* `afterFindOne`
* `beforeCount`
* `afterCount`
* `beforeAggregate`
* `afterAggregate`
* `beforeInsert`
* `afterInsert`
* `beforeUpdate`
* `afterUpdate`
* `beforeDelete`
* `afterDelete`
* `beforeUpdateMany`
* `afterUpdateMany`
* `beforeDeleteMany`
* `afterDeleteMany`


---

