Keywords & Decorators Reference
This reference catalogs every keyword and compiler decorator recognized by the Aegil TypeSpec lexer, semantic analyzer, and code generators.
Keywords
Section titled “Keywords”| Keyword | Target | Description | Example |
|---|---|---|---|
namespace |
File top-level | Groups models and operations under the package namespace. Must match namespace in aegil.yaml. |
namespace Helpdesk; |
model |
Declaration | Defines a data structure or database entity. | model Ticket { ... } |
enum |
Declaration | Defines a closed set of symbolic constants. | enum Status { Open, Closed } |
op |
Declaration | Defines an API query, mutation, or real-time stream. | op getTicket(id: uuid): Ticket; |
app |
Spec root (app.tsp) |
Defines the global application identity. | app Helpdesk; |
platform |
Spec root (platforms.tsp) |
Declares target native platform shells. | platform Helpdesk; |
Model & Entity Decorators
Section titled “Model & Entity Decorators”@entity
Section titled “@entity”Tells the compiler that a model corresponds to a persistent database table in PostgreSQL managed by Serverpod.
- Target:
model - Arguments:
{ table: string } - Example:
@entity({ table: "customers" })model Customer { ... }
Marks a field as the primary key of the database entity.
- Target: Model field
- Arguments: None
- Allowed Types:
uuid,int - Example:
@pkid: uuid;
@index
Section titled “@index”Generates a PostgreSQL B-tree index on the designated column for fast querying.
- Target: Model field
- Arguments: None
- Example:
@indexownerId: uuid;
@relation
Section titled “@relation”Declares a relational foreign key relationship to another entity.
- Target: Model field
- Arguments:
{ foreignKey: string, onDelete?: "cascade" | "setNull" | "restrict" } - Example:
@relation({ foreignKey: "departmentId", onDelete: "cascade" })department?: Department;
Data Validation Decorators
Section titled “Data Validation Decorators”@validate
Section titled “@validate”Enforces input boundaries and schema constraints on both Flutter client and Serverpod server.
- Target: Model field or operation parameter
- Arguments:
minLength?: int(Strings)maxLength?: int(Strings)min?: int | float(Numbers)max?: int | float(Numbers)pattern?: string(Regex string)
- Example:
@validate({ minLength: 3, maxLength: 100 })title: string;@validate({ min: 1, max: 1000 })quantity: int;
Access Control & State Decorators
Section titled “Access Control & State Decorators”@policy
Section titled “@policy”Attaches zero-trust row-level security expressions written in Common Expression Language (CEL).
- Target:
model - Arguments:
{ read?: string, write?: string } - Built-in context:
auth.id,auth.role,self.<field> - Example:
@policy({read: "auth.id == self.ownerId || auth.role == 'admin'",write: "auth.id == self.ownerId"})model Note { ... }
@stateMachine
Section titled “@stateMachine”Declares a finite state machine managing the transitions of an enum status field.
- Target:
model - Arguments:
{ field: string, initial: string, transitions: Transition[] } - Example:
@stateMachine({field: "status",initial: "Open",transitions: [{ from: "Open", to: "InProgress" },{ from: "InProgress", to: "Resolved" }]})model Ticket { ... }
Operation Decorators
Section titled “Operation Decorators”@autoQuery
Section titled “@autoQuery”Generates an automatic query endpoint with SQL generation, pagination, and Flutter BLoC caching.
- Target:
op - Arguments:
{ entity: string, paginate: "cursor" | "offset", filterBy: string[], sortBy: string[] } - Example:
@autoQuery({ entity: "Note", paginate: "cursor", filterBy: ["ownerId"], sortBy: ["createdAt"] })op listNotes(ownerId?: uuid, limit?: int): Page<Note>;
@autoMutation
Section titled “@autoMutation”Generates an automatic database CRUD endpoint and invalidates affected client caches.
- Target:
op - Arguments:
{ entity: string, action: "create" | "update" | "delete", touches: string[] } - Example:
@autoMutation({ entity: "Note", action: "create", touches: ["Note"] })op addNote(title: string, content: string): Note;
@autoStream
Section titled “@autoStream”Generates a real-time WebSocket stream that broadcasts entity updates directly to Flutter clients.
- Target:
op - Arguments:
{ entity: string } - Example:
@autoStream({ entity: "Ticket" })op watchTickets(): Stream<Ticket>;
@mutation
Section titled “@mutation”Declares a custom operation delegating to a hand-written Server Business Hook in hooks/.
- Target:
op - Arguments: None
- Example:
@mutationop processCheckout(cartId: uuid): OrderConfirmation;
@public
Section titled “@public”Removes session authentication requirements, allowing anonymous callers.
- Target:
op - Arguments: None
- Example:
@publicop getAppConfig(): AppConfig;
App & Platform Decorators
Section titled “App & Platform Decorators”Configures application identity, display metadata, and semver versioning.
- Target:
appdeclaration inspecs/app.tsp - Arguments:
{ id: string, displayName: string, version: string } - Example:
@app({ id: "com.acme.helpdesk", displayName: "Helpdesk App", version: "1.0.0" })app Helpdesk;
@platform
Section titled “@platform”Declares supported native platform targets.
- Target:
platformdeclaration inspecs/platforms.tsp - Arguments:
{ targets: string[] }("ios","android","macos","web") - Example:
@platform({ targets: ["ios", "android", "macos", "web"] })platform Helpdesk;
@permission
Section titled “@permission”Requests native device hardware and OS permissions in platform manifests.
- Target:
platformdeclaration inspecs/platforms.tsp - Arguments:
string(e.g."camera","location","microphone") - Example:
@permission("camera")@permission("location")platform Helpdesk;