import type { KyselyPlugin } from 'kysely'; /** * The kinds a column can be coerced *to* at runtime. This is the value type of * the generated `CoercionMap`, so it is a public artifact contract — a kind may * only appear here if `fromDb` below actually does something with it. * * `uuid` is deliberately absent: it is an annotation kind (it selects the `Uuid` * TypeScript type in the generated schema) but not a coercion kind, and the * codegen filters it out of `coercion.gen.ts` for exactly that reason — a UUID * is a string in both Postgres and SQLite. */ export type ColumnKind = 'date' | 'bool' | 'json'; /** * Per-table column kind map. Keys are the table names queries are written * against; inner keys are snake_case column names. * Generated into `outDir/db/coercion.gen.ts` by `pikku db migrate` from the * explicit `kind` entries in `db/annotations.ts`. */ export type CoercionMap = Record>; export interface CreateCoercionPluginOptions { map: CoercionMap; } /** * Convert values stored in a dialect's on-disk representation back into the * logical types app code expects (Date / boolean / parsed JSON). * * SQLite is what makes this necessary — it stores dates as TEXT, booleans as * INTEGER and JSON as TEXT — but the plugin is dialect-neutral: on Postgres the * driver already returns Date/boolean/object, and every branch of `fromDb` * passes a non-string, non-number value straight through. That is why it lives * in `@pikku/kysely` next to `SerializePlugin` rather than in a SQLite package: * the CLI installs it on its local Postgres database too. * * Write-side coercion (Date → ISO string, boolean → 0/1, object → JSON) is * handled in the SQLite database adapters (always-on), so this plugin is * read-only. * * Place AFTER CamelCasePlugin in the plugin array (or it handles both * orderings via the dual-keyed maps). */ export declare function createCoercionPlugin(options: CreateCoercionPluginOptions): KyselyPlugin;