Module cuid
Expand description
Generate the value for @default(cuid()) (cratestack#1209).
The id has cuid2’s default shape: 24 characters, a lowercase letter
first, then lowercase letters and digits. That is what the Cuid
scalar accepts (crate::error::parse_cuid) and what other cuid2
producers emit, so ids from either source mix in one column.
It is drawn straight from a CSPRNG rather than through the cuid2
algorithm’s hash of time, counter and host fingerprint. That keeps
the property cuid2 exists for (ids that cannot be guessed and do not
collide: about 124 random bits) without its dependencies. The cuid2
crate needs getrandom 0.3, which does not build for
wasm32-unknown-unknown without extra configuration, and the embedded
runtime runs there. The randomness comes from uuid’s v4 generator,
which every runtime already depends on and which the embedded runtime
already wires to the browser’s crypto.getRandomValues on wasm.
Functions§
- new_
cuid - A new random id in cuid2’s default shape (
[a-z][0-9a-z]{23}).