2.9 KiB
schemas
(no submodules)
Purpose
Zod schemas and inferred TypeScript types for all @suaveplan/db-sqlite configuration objects. Centralising validation in one module ensures that every entry point — createBunDriver, createWasmDriver, SqliteAdapter, MigrationRunner — applies the same rules with the same error messages, rather than duplicating ad-hoc checks across modules.
All schemas use .strict() where applicable so extra unknown properties are rejected at runtime, preventing silent misconfiguration from typos in option objects.
Features
BunDriverOptionsSchema— validatesfilename(optional string) andreadonly(optional boolean, defaultfalse)WasmDriverOptionsSchema— validatesfilename(optional string) for OPFS persistenceSqliteAdapterOptionsSchema— alias forBunDriverOptionsSchema; adapter and driver share the same shapeMigrationRunnerOptionsSchema— validatesmigrationsFolder(default"./migrations"),migrationsTable(default"__sqlite_migrations"),dryRun(defaultfalse)- Inferred TypeScript types exported for all four schemas
Usage: Basic Example
import { BunDriverOptionsSchema } from "@suaveplan/db-sqlite/schemas";
const opts = BunDriverOptionsSchema.parse({ filename: ":memory:" });
// opts.readonly === false (default applied)
Usage: Advanced Example
import { MigrationRunnerOptionsSchema } from "@suaveplan/db-sqlite/schemas";
const opts = MigrationRunnerOptionsSchema.parse({
migrationsFolder: "./db/migrations",
dryRun: true,
});
// opts.migrationsTable === "__sqlite_migrations" (default applied)
// opts.dryRun === true
API Reference
BunDriverOptionsSchema
z.object({ filename?: string, readonly?: boolean }).strict() — readonly defaults to false.
WasmDriverOptionsSchema
z.object({ filename?: string }).strict() — no defaults; absence means in-memory.
SqliteAdapterOptionsSchema
Alias for BunDriverOptionsSchema. Both driver and adapter accept the same option shape.
MigrationRunnerOptionsSchema
z.object({ migrationsFolder?: string, migrationsTable?: string, dryRun?: boolean }).strict().
Defaults: migrationsFolder = "./migrations", migrationsTable = "__sqlite_migrations", dryRun = false.
Type aliases
BunDriverOptions = z.infer<typeof BunDriverOptionsSchema>WasmDriverOptions = z.infer<typeof WasmDriverOptionsSchema>SqliteAdapterOptions = BunDriverOptionsMigrationRunnerOptions = z.infer<typeof MigrationRunnerOptionsSchema>
Implementation Notes
SqliteAdapterOptions is deliberately an alias for BunDriverOptions rather than a separate schema so that passing an SqliteAdapterOptions object to createBunDriver is type-safe without casting. If the WASM adapter ever gains readonly support the alias can be split without a breaking change to the option names callers already use.