server/app_backend.ts

App backend types and factory — database initialization + auth migrations + deps.

Provides AppBackend, CreateAppBackendOptions, and create_app_backend().

Vocabulary: - AppDeps — stateless capabilities: injectable, swappable per environment - *Options — static values set at startup, per-factory configuration - Runtime state — mutable values (e.g., bootstrap_status) — NOT in deps or options

Declarations
#

3 declarations

view source

AppBackend
#

server/app_backend.ts view source

AppBackend

Result of create_app_backend() — database metadata + deps bundle.

This is the initialized backend, not the HTTP server. Pass it to create_app_server() to assemble the Hono app.

deps

type AppDeps

db_type

type DbType

db_name

type string

migration_results

Migration results from create_app_backend (auth migrations only).

type ReadonlyArray<MigrationResult>
readonly

close

Close the database connection. Bound to the actual driver.

type () => Promise<void>

create_app_backend
#

server/app_backend.ts view source

(options: CreateAppBackendOptions): Promise<AppBackend>

Initialize the backend: database + auth migrations + deps.

Calls create_dbrun_migrations (auth namespace) and bundles the result with the provided keyring and password deps.

options

keyring, password deps, and optional database URL

returns

Promise<AppBackend>

app backend with deps, database metadata, and migration results

CreateAppBackendOptions
#

server/app_backend.ts view source

CreateAppBackendOptions

Input for create_app_backend().

keyring is passed pre-validated — callers handle their own error reporting (e.g., tx uses runtime.exit(1) on invalid keys).

stat

Get file/directory stats, or null if path doesn't exist.

type (path: string) => Promise<StatResult | null>

read_file

Read a file as text.

type (path: string) => Promise<string>

delete_file

Delete a file.

type (path: string) => Promise<void>

database_url

Database connection URL (postgres://, file://, or memory://).

type string

keyring

Validated cookie signing keyring.

type Keyring

password

Password hashing implementation. Use argon2_password_deps in production.

log

Structured logger instance. Omit for default (new Logger('server')).

type Logger

on_audit_event

Called after each audit log INSERT succeeds. Use to broadcast audit events via SSE. Flows through AppDeps to all route factories automatically. Defaults to a noop.

type (event: AuditLogEvent) => void

Depends on
#