export type Field = { kind: string; defaultValue?: T; default(value: T): Field; }; export type TableDefinition = { kind: "table"; fields: Record>; }; export type AuthContext = { userId: string; displayName: string; provider: "guest" | "google"; isGuest: boolean; isAuthenticated: boolean; email?: string; emailVerified?: boolean; picture?: string; }; export type LogContext = { info(message: string, data?: unknown): void; warn(message: string, data?: unknown): void; error(message: string, data?: unknown): void; }; export type QueryBuilder = { where(field: keyof T & string, value: unknown): QueryBuilder; orderBy(field: keyof T & string, direction?: "asc" | "desc"): QueryBuilder; limit(count: number): QueryBuilder; all(): Array; }; export type TableApi = QueryBuilder & { get(id: string): (T & { id: string; createdAt: string; updatedAt: string }) | null; insert(value: T): T & { id: string; createdAt: string; updatedAt: string }; update(id: string, patch: Partial): void; delete(id: string): void; }; export type DbContext = Record>>; export type ServerContext = { auth: AuthContext; db: DbContext; env: Record; log: LogContext; }; export type EndpointRoute = { method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD" | (string & {}); path: `/${string}`; }; export type EndpointHeaders = { get(name: string): string | null; has(name: string): boolean; entries(): IterableIterator<[string, string]>; }; export type EndpointRequest = { method: string; path: string; url: string; headers: EndpointHeaders; query: URLSearchParams; text(): Promise; json(): Promise; bytes(): Promise; }; export type EndpointResponse = { kind: "response"; status: number; headers?: Record; body?: string | Uint8Array | ArrayBuffer; }; export type EndpointResponseOptions = { status?: number; headers?: Record; }; export type EndpointDefinition = { kind: "endpoint"; method: string; path: string; handler: (ctx: ServerContext, req: EndpointRequest) => TResult | Promise; }; export function capsule(definition: T): T; export function query(handler: (ctx: ServerContext) => T): (ctx: ServerContext) => T; export function mutation( handler: (ctx: ServerContext, ...args: TArgs) => TResult ): (ctx: ServerContext, ...args: TArgs) => TResult; export function endpoint( route: EndpointRoute, handler: (ctx: ServerContext, req: EndpointRequest) => TResult | Promise ): EndpointDefinition; export function json(value: unknown, options?: EndpointResponseOptions): EndpointResponse; export function text(value: unknown, options?: EndpointResponseOptions): EndpointResponse; export function empty(options?: EndpointResponseOptions): EndpointResponse; export function redirect(url: string, options?: EndpointResponseOptions): EndpointResponse; export function table(fields: Record>): TableDefinition; export function string(): Field; export function boolean(): Field;