Add business logic
Purpose
Section titled “Purpose”Choose the smallest server-side mechanism that matches the behavior and keeps authorization, validation, and transactions consistent.
Audience
Section titled “Audience”Application developers and reviewers.
Prerequisites
Section titled “Prerequisites”An application with its tables, permissions, and metadata workflow defined.
Choose the mechanism
Section titled “Choose the mechanism”| Behavior | Use |
|---|---|
| Record defaults or validation | Hooks and data events |
| Pre/post lifecycle behavior | Hooks and data events |
| Explicit user operation | Function/action |
| Several related registrations | Script |
| Bounded HTTP or email integration | Async Function/action |
| Other native or reusable integration | Reviewed TypeScript |
Execute related writes inside a transaction through DataContext. A transactional Function is synchronous and atomic. An async Function may await the built-in HTTP and email services, but it must use short explicit ctx.tts() blocks for database writes. Keep validation deterministic, never await network calls inside database transactions, and enforce authorization on the server even when the client hides an action.
Testing
Section titled “Testing”Test success, rejection, rollback, unauthorized access, and concurrent behavior. See Run tests and debug.