/** * A nominal type brand. Attach this to a string type to create a distinct * branded string that is not assignable from plain `string`. * * @example * type UserId = Brand; */ type Brand = T & { readonly __brand: B; }; /** * A branded string type for an entity named `T`. * Equivalent to `Brand`, but more ergonomic for ID types. * * @example * type UserId = IdOf<"User">; * type PostId = IdOf<"Post">; */ type IdOf = Brand; /** * Casts a plain string to a branded `IdOf`. * * This is a type-only operation at runtime — no validation is performed. * Use `assertValidId` from `"sigilid/validate"` first if you need runtime safety. * * @example * import { castId } from "sigilid/typed"; * const id = castId<"User">("usr_abc123"); */ declare function castId(value: string): IdOf; /** * Returns a factory function that generates cryptographically secure branded IDs. * * The type parameter `T` sets the brand. If a prefix is provided, the format * is `{prefix}_{id}`, otherwise it is a plain random string. * * Validation happens at factory creation, not per-call. * * @param prefix - Optional alphanumeric prefix. * @param length - Length of the random portion (1–255). Defaults to 21. * @returns A zero-argument function returning `IdOf`. * * @example * import { createTypedGenerator } from "sigilid/typed"; * const userId = createTypedGenerator<"User">("usr"); * const id = userId(); // IdOf<"User"> = "usr_K7gkJ_q3vR2nL8xH5eM0w" */ declare function createTypedGenerator(prefix?: string, length?: number): () => IdOf; export { type Brand, type IdOf, castId, createTypedGenerator };