brick.ts

API Cheatsheet

Quick reference of all public functions, classes, and types in Brick-TS.

llms.txt

A quick reference of commonly used public exports from @brickkit/core, @brickkit/crud, and @brickkit/cli. For the full surface, see packages/core/src/index.ts.

Core Primitives (@brickkit/core)

ExportKindDescription
defineService(name, options)FunctionCreates an isolated service domain with optional database, context resolver, and lifecycle.
defineAction(config)FunctionConstructs a typed action with input/output validation, error helpers, and authorization.
defineResource(service, config)FunctionBinds a Drizzle table to a service with explicit primary key identity.
createServiceProxy(serviceName)FunctionCreates a type-safe proxy for calling another service in-process with context isolation.
brick(options)FunctionInstantiates an Elysia HTTP server gateway precompiled with services and routes.
t / TypeObjectTypeBox schema builder for declaring runtime input and output data shapes.
Static<typeof Schema>TypeIncurs static TypeScript compile-time types from TypeBox runtime schemas.
validateWithSchema(schema, data)FunctionDirectly validates arbitrary data against a TypeBox schema.

Database Integration (@brickkit/core)

ExportKindDescription
defineDatabase(options)FunctionConfigures a lazy database handle for SQLite or PostgreSQL.
syncSchema(serviceOrTables, db?)FunctionExplicit development/test helper to create SQLite tables from Drizzle definitions.
ensureResourceIndexes(db, table, opts)FunctionGenerates secondary B-Tree indexes and PostgreSQL trigram search indexes.
ensureSQLiteFts(db, table, searchCols)FunctionCreates an FTS5 full-text search sidecar table with sync triggers on SQLite.
buildFtsMatchQuery(query)FunctionFormats user search queries into sanitized SQLite FTS5 MATCH expressions.
isDatabaseHandle(value)FunctionType guard checking if an object is a Brick database handle.

Errors & Builders (@brickkit/core)

ExportKindDescription
ActionExecutionErrorClassStandard domain error with HTTP status, machine error code, and optional details.
ValidationErrorClassThrown when TypeBox input (400) or output (500) validation fails.
buildErrorHelpers(errorsDef?)FunctionGenerates standard HTTP error helpers (error.NOT_FOUND, etc.) and custom action codes.

Typed Client SDK (@brickkit/core/client)

ExportKindDescription
createBrickClient(options)FunctionInstantiates an end-to-end typed HTTP client proxy from backend server types.
BrickTransportErrorClassClient error thrown when network connectivity fails, bodies are unparsable, or responses fall outside the declared contract. Aborts propagate the native AbortError unwrapped.
BrickServerErrorClassClient error thrown when the server responds with an unhandled 5xx status code.
isBrickTransportError(err)FunctionType guard for checking if an error originated from client transport failure.
isBrickServerError(err)FunctionType guard for checking if an error is an unexpected 5xx server failure.
InferActionInput<T>TypeExtracts the static TypeScript input payload type for an action.
InferActionOutput<T>TypeExtracts the static TypeScript return type for an action.
InferActionErrorCodes<T>TypeUnion of all error code strings declared by an action.

AI & Model Context Protocol (@brickkit/core)

ExportKindDescription
defineTool(config)FunctionConstructs an LLM-invocable tool. When input is present it must be an object schema.
isTool(value)FunctionType guard checking if an action is designated as an AI tool.
createMcpRegistry(options)FunctionCollects explicitly declared tools into a Model Context Protocol registry.
createMcpHandler(options)FunctionGenerates an MCP-compliant JSON-RPC 2.0 HTTP POST handler from { registry, serverInfo }. Non-POST requests return 405.
UnknownToolErrorClassError thrown when an MCP client requests an unregistered tool name.

Plugins (@brickkit/core)

ExportKindDescription
defineServicePlugin(descriptor)FunctionPackages reusable capabilities installed at service scope via service.use().
defineResourcePlugin(descriptor)FunctionPackages table-attached capabilities installed at resource scope via resource.use().
getPluginActionRoute(action, prefix)FunctionRetrieves the effective HTTP route configuration bound to a plugin action.
getPluginEndpoints(service, prefix)FunctionRetrieves raw HTTP endpoints registered by service and resource plugins.

CRUD Plugin (@brickkit/crud)

ExportKindDescription
crud(options)FunctionDeny-by-default resource plugin providing field-level operations, filtering, and hooks.
FieldPolicyInterfaceConfiguration options for column visibility (read, create, update, filter, sort, schema, scrub).
CrudOptionsInterfaceFull options object accepted by crud() (fields, access, hooks, operations, routes, limits).
FilterOperatorTypeUnion of allowed query operators (eq, ne, in, contains, between, isNull, etc.).

Secrets Management (@brickkit/core)

ExportKindDescription
secret(name, options?)FunctionDeclares a secret reference resolved lazily from environment variables or custom sources.
SecretRefClassContainer wrapping secret names with .default(), .transform(), .validate(), .url(), .value(), .require(), and .isSet() methods.
resolveSecrets(options?)FunctionEagerly validates and resolves all declared secret references.
overrideSecret(name, value)FunctionOverrides a secret value in test environments.

CLI Commands (@brickkit/cli)

CommandUsageDescription
brick devbrick dev [entry] [--port <number>]Starts development server with live reload and route banners.
brick startbrick start [entry] [--port <number>]Starts production server without file system watching.
brick buildbrick build <entry> [--outdir <dir>]Compiles a default-exported BrickApp into an AOT Bun server bundle.
brick gen openapibrick gen openapi <entry> [--output <file>]Extracts OpenAPI 3.1 JSON specification from services.
brick gen clientbrick gen client <entry> [--output <file>]Generates a typed browser client contract file (_brick/contract.ts).
brick infobrick info <entry>Exports the runtime service graph and access policies as JSON.