API reference / @evolu/common / Type / createIdFromString
Function: createIdFromString()
function createIdFromString<B>(value): [B] extends [never] ? string & Brand<"Id"> : string & Brand<"Id"> & Brand<B>;
Defined in: packages/common/src/Type.ts:1377
Creates an Id from a string using SHA-256.
Evolu table IDs must follow a fixed 21-character NanoID format. When integrating with external systems that use different ID formats, use this function to convert external IDs into valid Evolu IDs.
In Evolu's CRDT, the ID serves as the unique identifier for conflict resolution across distributed clients. When multiple clients create records with the same external identifier, they must resolve to the same Evolu ID to ensure data consistency.
Example
// Both clients will generate the same ID
const id1 = createIdFromString("user-api-123");
const id2 = createIdFromString("user-api-123");
console.log(id1 === id2); // true
upsert("todo", {
id: createIdFromString("external-todo-456"),
title: "Synced from external system",
});
Important: This transformation is one-way. You cannot recover the original external string from the generated Id. If you need to preserve the original external ID, store it in a separate column.
Type Parameters
Type Parameter | Default type |
---|---|
B extends string | never |
Parameters
Parameter | Type |
---|---|
value | string |
Returns
[B
] extends [never
] ? string
& Brand
<"Id"
> : string
& Brand
<"Id"
> & Brand
<B
>