API reference › @evolu/common › Type › uuidToId
function uuidToId<B extends string = never>(
value: string & Brand<"Uuid">,
..._validation: IdBrandValidation<B>
): CreatedId<B>;
Defined in: packages/common/src/Type.ts:10565
Converts a Uuid to the Id with the same 16 bytes.
Use this to store records whose external keys are UUIDs. Unlike createIdFromString, the mapping is reversible with idToUuid, so the original UUID does not need its own column. A time-based UUID, such as version 1, 6, or 7, keeps its creation time in the Id.
Example
import {
assertEqual,
assertType,
idToUuid,
Uuid,
uuidToId,
type Brand,
type Id,
} from "@evolu/common";
const uuid = Uuid.orThrow("0190a6f4-8c3e-7b2a-9d41-5e6f7a8b9c0d");
const todoId = uuidToId<"Todo">(uuid);
assertEqual(todoId, "AZCm9Iw-eyqdQV5veoucDQ");
assertType<typeof todoId, Id & Brand<"Todo">>();
assertEqual(idToUuid(todoId), uuid);