import { t as Id } from "./types-hGBnCpJj.mjs"; import { n as IdColumnCodec, r as IdGeneratingCodec } from "./adapter-types-B-GLKPOm.mjs"; import { n as IdsErrorCode, r as isIdsError, t as IdsError } from "./error-JLZfeGOx.mjs"; import { ColumnType, KyselyPlugin } from "kysely"; //#region src/adapters/kysely.d.ts /** * Kysely column type mapping for `Id`. * * Use this in your Kysely `Database` interface to type a column as `Id` at * the TypeScript level. Pair it with `idColumn(codec)` for runtime read/write * transformation. * * @example * ```ts * import type { IdColumnType } from "@smonn/ids/kysely"; * import type { Id } from "@smonn/ids"; * * interface Database { * users: { id: IdColumnType<"usr"> }; * } * ``` */ type IdColumnType = ColumnType, Id, Id>; /** * Kysely column type mapping for a nullable `Id` column. * * Use in your Kysely `Database` interface for optional foreign keys or any * column that can be `NULL`. Pair with `nullableIdColumn(codec)` for runtime * transformation. * * @example * ```ts * import type { NullableIdColumnType } from "@smonn/ids/kysely"; * import type { Id } from "@smonn/ids"; * * interface Database { * posts: { authorId: NullableIdColumnType<"usr"> }; * } * ``` */ type NullableIdColumnType = ColumnType | null, Id | null, Id | null>; /** * Kysely column adapter bound to a codec. * * Returns an object with `fromDriver` / `toDriver` helpers that mirror the read/write * contract of the Drizzle adapter — same error message, same strictness (safeParse on * read and write). * * **Write path:** validates the value via `codec.safeParse` and throws * `IdsError("invalid_id")` if validation fails. * * **Read path:** normalises the raw DB string via `codec.safeParse()`. Throws if * the value does not parse as a valid `Id`. * * @example * ```ts * import { idColumn } from "@smonn/ids/kysely"; * import { createTimestampId } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * const usrCol = idColumn(usr); * * // In a query result handler: * const id = usrCol.fromDriver(row.id); * ``` */ declare function idColumn(codec: IdColumnCodec): { toDriver(value: Id): string; fromDriver(value: string): Id; }; /** * Generates a fresh `Id` for use at a Kysely insert call site. * * Requires a codec variant that exposes a synchronous `generate()` — see * {@link IdGeneratingCodec}. Only the **Timestamp codec** and **Reverse * Timestamp codec** qualify; Opaque, Signed, Wrapped, and Digest codecs * are rejected at compile time. * * @example * ```ts * import { insertId } from "@smonn/ids/kysely"; * import { createTimestampId } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * * await db.insertInto("users").values({ id: insertId(usr), name: "Alice" }).execute(); * ``` */ declare function insertId(codec: IdGeneratingCodec): Id; /** * Kysely plugin that automatically transforms result columns using the provided codec map. * * **Unbranded map — callers own the key-to-column mapping.** The `map` parameter is typed as * `Record>` with no schema-level brand parameter. There is no * compile-time guarantee that map keys correspond to actual columns in your `Database` interface; * a misspelled or stale key silently matches nothing, and the column is left un-transformed. * Callers are responsible for keeping the map in sync with their schema. * * **Keys must be bare column names** (e.g. `"id"`, `"user_id"`). Qualified keys containing a * dot (e.g. `"users.id"`) are **not** supported — passing one throws a synchronous `Error` at * construction time, naming the offending key. Per-table disambiguation is not implemented. * * `transformResult` calls `readIdColumn(codec, rawValue)` for each matched column, returning * a branded `Id` on success and throwing `IdsError("invalid_id")` on parse failure. * `transformQuery` is a no-op identity pass-through. * * @example * ```ts * import { idPlugin } from "@smonn/ids/kysely"; * import { createTimestampId } from "@smonn/ids"; * import { Kysely } from "kysely"; * * const usr = createTimestampId("usr"); * * const db = new Kysely({ * // ... * plugins: [idPlugin({ id: usr })], * }); * * // result.id is automatically validated and branded as Id<"usr"> * const row = await db.selectFrom("users").selectAll().executeTakeFirstOrThrow(); * ``` */ declare function idPlugin(map: Record>): KyselyPlugin; /** * Kysely column adapter for a **nullable** `Id` column. * * Behaves like {@link idColumn} but `fromDriver` returns `null` for `null` / * `undefined` driver values and `toDriver` passes `null` through unchanged. * Use for optional foreign keys and `LEFT JOIN` results. * * @example * ```ts * import { nullableIdColumn } from "@smonn/ids/kysely"; * import { createTimestampId } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * const authorCol = nullableIdColumn(usr); * * // In a query result handler: * const authorId = authorCol.fromDriver(row.author_id); // Id<"usr"> | null * ``` */ declare function nullableIdColumn(codec: IdColumnCodec): { toDriver(value: Id | null | undefined): string | null; fromDriver(value: string | null): Id | null; }; //#endregion export { type IdColumnCodec, IdColumnType, type IdGeneratingCodec, IdsError, type IdsErrorCode, NullableIdColumnType, idColumn, idPlugin, insertId, isIdsError, nullableIdColumn }; //# sourceMappingURL=kysely.d.mts.map