Skip to content

Runtime API Reference

Runtime library API for USL-generated applications.

Storage API

Load

async function load<T>(entityType: EntityType<T>, id: string): Promise<T>

Load an entity by ID.

Store

async function store<T>(entity: T): Promise<void>

Save an entity to storage.

Delete

async function deleteEntity<T>(entity: T): Promise<void>

Delete an entity.

LoadAll

async function loadAll<T>(entityType: EntityType<T>): Promise<T[]>

Load all entities of a type.

Context API

Current User

function getCurrentUser(): User

Get the authenticated user from request context.

Request Context

interface RequestContext {
  user: User;
  timestamp: Date;
  ipAddress: string;
  headers: Record<string, string>;
}

function getContext(): RequestContext

Policy API

Check Authorization

function checkPolicy(
  policy: Policy,
  rule: string,
  ...args: any[]
): Promise<boolean>

Check if a policy rule allows an action.

Enforce

function enforce(
  policy: Policy,
  rule: string,
  ...args: any[]
): Promise<void>

Enforce a policy rule, throwing if denied.

Event API

Emit

function emit(event: Event): Promise<void>

Emit a domain event.

Subscribe

function subscribe<T extends Event>(
  eventType: EventType<T>,
  handler: (event: T) => Promise<void>
): Unsubscribe

Subscribe to domain events.

Validation API

Validate

function validate<T>(entity: T): ValidationResult

Validate entity invariants.

ValidationResult

interface ValidationResult {
  valid: boolean;
  errors: ValidationError[];
}

Back to Index