API / @aionbuilders/nabu

stampBlockUids

Function Stability: stable

Stamp every live block node of a document that has no uid, and heal duplicates (the smallest TreeID keeps the uid). Works on a bare LoroDoc: no editor needed, so an app can call it in its own migration. Deterministic (the values depend only on the TreeIDs), so peers that run it separately converge. Commits with a silent origin (never an undo step), and only if it wrote something: calling it again writes nothing.

Caveat: it COMMITS the document. Operations of the caller that are still pending (written, not committed) would be committed under the silent origin and so could not be undone. Call it on a document with nothing pending: in a migration, or before the editor opens.

Signature

TypeScript
import { stampBlockUids } from '@aionbuilders/nabu';
TypeScript
function stampBlockUids(doc: LoroDoc<Record<string, Container>>): number

Parameters

Parameters of stampBlockUids
ParameterTypeDescription
docLoroDoc<Record<string, Container>>n/a

Returns

number

the number of nodes written

Source: src/lib/blocks/uids.js:215