Skip to content

API reference ​

A summary of everything Lyn exposes. Each entry links to the page that explains it.

Exports ​

ts
import { Lyn, z, logger, LynEnvError, LynDatabaseError } from "@rouret/lyn";
import { pgTable, text, eq, sql /* … */ } from "@rouret/lyn/db";
import { defineConfig } from "@rouret/lyn/config";
ExportDescription
LynThe application class
zZod 4, re-exported
loggerThe pino logger used by Lyn · Logging
LynEnvErrorThrown by new Lyn() on invalid environment variables · Environment variables
LynDatabaseErrorThrown by listen() when the database is unreachable · Database
@rouret/lyn/dbEverything from drizzle-orm and drizzle-orm/pg-core · Database
@rouret/lyn/configdefineConfig for an optional lyn.config.ts · Migrations

new Lyn(config?) ​

Creates an app. Reads and checks the environment variables right away.

OptionTypePage
envRecord<string, { name: string; type: "string" | "number" | "boolean" }>Environment variables
cors{ origin, credentials?, allowedHeaders?, exposedHeaders?, maxAge? }CORS
rateLimit{ max, windowMs?, key?, skip? }Rate limiting
database{ schema, url?, pool?, logQueries?, migrateOnStart?, statementTimeoutMs? }Database
start.hideLynLogobooleanServer
server.hostnamestring, default "127.0.0.1"Server
server.allowedHostsstring[], default loopback namesServer
server.maxBodyBytesnumber, default 1048576Server
server.requestTimeoutMsnumber, default 30000Server

Routes ​

ts
app.get(path, handler, validation?)
app.post(path, handler, validation?)
app.put(path, handler, validation?)
app.delete(path, handler, validation?)

Each returns the app, for chaining. validation is { body?, params?, query? }, with no body on get. See Routing and Validation.

Handler context ​

FieldDescription
requestThe standard Request
set.statusResponse status, defaults to the method's
set.headersResponse Headers
signalAbortSignal aborted on timeout or client disconnect
body, params, queryValidated inputs, when a schema is given
dbTyped Drizzle instance, when a database is configured

See Handlers.

App members ​

MemberDescription
listen(port?)Runs the startup checks, then serves on 127.0.0.1 (or server.hostname). Returns a promise of the app. · Server
stop()Stops the server and closes the database connection. · Server
handle(request)Runs a Request through the app without a server. Returns a promise of the Response. · Server
urlBase URL of the running server. Throws before listen().
envParsed environment variables, typed from config.env.
dbThe Drizzle instance. A type error without config.database.

Error codes ​

INVALID_HOST, VALIDATION, NO_BODY, INVALID_JSON, PAYLOAD_TOO_LARGE, REQUEST_TIMEOUT, TOO_MANY_REQUESTS, UNSUPPORTED_MEDIA_TYPE, NOT_FOUND, METHOD_NOT_ALLOWED, CONFLICT, INTERNAL_SERVER_ERROR. See Errors.

CLI ​

CommandDescription
lyn db generateWrites the SQL migrations for your schema changes. Needs drizzle-kit.
lyn db migrateApplies the pending migrations to DATABASE_URL.
lyn db studioOpens Drizzle Studio on DATABASE_URL. Needs drizzle-kit.

See Migrations.

Released under the MIT License.