idTransformer
idTransformer<
Brand>(codec):ValueTransformer
Defined in: src/adapters/typeorm.ts:49
TypeORM column transformer for Id<Brand>.
Returns a ValueTransformer object suitable for use in a TypeORM @Column
decorator’s transformer option.
Write path (to): validates the value via codec.safeParse and throws
IdsError("invalid_id") if validation fails.
Read path (from): normalises the raw database value via codec.safeParse().
Throws IdsError with code "invalid_id" if the value does not parse as a valid
Id<Brand>.
TypeORM branding caveat: TypeORM cannot brand a generated entity field type at
the schema level. Annotate the entity field explicitly: id!: Id<"usr">.
Type Parameters
Section titled “Type Parameters”Brand extends string
Parameters
Section titled “Parameters”IdColumnCodec<Brand>
Returns
Section titled “Returns”ValueTransformer
Example
Section titled “Example”import { idTransformer } from "@smonn/ids/typeorm";import { createTimestampId } from "@smonn/ids";import type { Id } from "@smonn/ids";import { Column, Entity } from "typeorm";
const usr = createTimestampId("usr");
@Entity()class User { @Column({ type: "text", transformer: idTransformer(usr) }) id!: Id<"usr">;}