Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Specification Language

Keywords & Decorators Reference

This reference catalogs every keyword and compiler decorator recognized by the Aegil TypeSpec lexer, semantic analyzer, and code generators.

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;

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:
    @pk
    id: uuid;

Generates a PostgreSQL B-tree index on the designated column for fast querying.

  • Target: Model field
  • Arguments: None
  • Example:
    @index
    ownerId: uuid;

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;

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;

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 { ... }

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 { ... }

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>;

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;

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>;

Declares a custom operation delegating to a hand-written Server Business Hook in hooks/.

  • Target: op
  • Arguments: None
  • Example:
    @mutation
    op processCheckout(cartId: uuid): OrderConfirmation;

Removes session authentication requirements, allowing anonymous callers.

  • Target: op
  • Arguments: None
  • Example:
    @public
    op getAppConfig(): AppConfig;

Configures application identity, display metadata, and semver versioning.

  • Target: app declaration in specs/app.tsp
  • Arguments: { id: string, displayName: string, version: string }
  • Example:
    @app({ id: "com.acme.helpdesk", displayName: "Helpdesk App", version: "1.0.0" })
    app Helpdesk;

Declares supported native platform targets.

  • Target: platform declaration in specs/platforms.tsp
  • Arguments: { targets: string[] } ("ios", "android", "macos", "web")
  • Example:
    @platform({ targets: ["ios", "android", "macos", "web"] })
    platform Helpdesk;

Requests native device hardware and OS permissions in platform manifests.

  • Target: platform declaration in specs/platforms.tsp
  • Arguments: string (e.g. "camera", "location", "microphone")
  • Example:
    @permission("camera")
    @permission("location")
    platform Helpdesk;