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 { Type } from "@mikro-orm/core"; //#region src/adapters/mikro-orm.d.ts /** * Returns a MikroORM property option object that wires `codec.generate()` into the * `onCreate` lifecycle hook, so the field auto-fills on first persist. * * 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 cannot * be passed here. * * Pass the result as options to `@PrimaryKey()` (the typical case for auto-generated primary keys) or any other MikroORM property decorator: * * @example * ```ts * import { PrimaryKey } from "@mikro-orm/core"; * import { idField } from "@smonn/ids/mikro-orm"; * import { createTimestampId } from "@smonn/ids"; * import type { Id } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * * class User { * @PrimaryKey(idField(usr)) * id!: Id<"usr">; * } * ``` */ declare function idField(codec: IdGeneratingCodec): { type: new () => Type, string>; onCreate: () => Id; }; /** * Factory that returns a MikroORM `Type` subclass bound to a codec. * * **Write path** (`convertToDatabaseValue`): validates the value via * `codec.safeParse` and throws `IdsError("invalid_id")` if validation fails. * * **Read path** (`convertToJSValue`): normalises the raw DB value via * `codec.safeParse()`. Throws `IdsError("invalid_id")` if the stored value * does not parse as a valid `Id`. * * **Column type** (`getColumnType`): returns `"text"` by default, or the * `options.columnType` override when provided. * * @param codec - The brand-scoped codec used to parse values read from the database. * @param options - Optional column configuration. * @param options.columnType - SQL column type to use (default: `"text"`). Pass * `"varchar(30)"` or `"char(26)"` to match an existing DDL or index strategy. * The value is passed through verbatim — no validation is performed. * * @example * ```ts * import { PrimaryKey } from "@mikro-orm/core"; * import { idType } from "@smonn/ids/mikro-orm"; * import { createTimestampId } from "@smonn/ids"; * import type { Id } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * * // default: text column * class User { * @PrimaryKey({ type: idType(usr) }) * id!: Id<"usr">; * } * * // explicit varchar column * class Org { * @PrimaryKey({ type: idType(usr, { columnType: "varchar(30)" }) }) * id!: Id<"usr">; * } * ``` */ declare function idType(codec: IdColumnCodec, options?: { columnType?: string; }): new () => Type, string>; /** * Factory that returns a MikroORM `Type` subclass for a **nullable** `Id` column. * * Behaves like {@link idType} but `convertToJSValue` returns `null` for `null` / * `undefined` database values and `convertToDatabaseValue` normalises `null` and * `undefined` to `null`. Use for optional foreign keys. * * @param codec - The brand-scoped codec used to parse values read from the database. * @param options - Optional column configuration. * @param options.columnType - SQL column type to use (default: `"text"`). Pass * `"varchar(30)"` or `"char(26)"` to match an existing DDL or index strategy. * The value is passed through verbatim — no validation is performed. * * @example * ```ts * import { Property } from "@mikro-orm/core"; * import { nullableIdType } from "@smonn/ids/mikro-orm"; * import { createTimestampId } from "@smonn/ids"; * import type { Id } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * * class Post { * @Property({ type: nullableIdType(usr), nullable: true }) * authorId!: Id<"usr"> | null; * } * * // explicit varchar column * class Comment { * @Property({ type: nullableIdType(usr, { columnType: "varchar(30)" }), nullable: true }) * authorId!: Id<"usr"> | null; * } * ``` */ declare function nullableIdType(codec: IdColumnCodec, options?: { columnType?: string; }): new () => Type | null, string | null>; //#endregion export { type IdColumnCodec, type IdGeneratingCodec, IdsError, type IdsErrorCode, idField, idType, isIdsError, nullableIdType }; //# sourceMappingURL=mikro-orm.d.mts.map