-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
Add support for generating UUIDv7s #62529
Description
What is the problem this feature will solve?
UUIDv7s are time-based UUIDs which can be helpful for sorting & database distribution. The standard is published here: https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7
Postgres recently shipped native support for UUIDv7 generation, and Bun has a helper Bun.randomUUIDv7();
Having to reach for a library in order to generate non-v4 UUIDs is a bummer and adds bloat for a very common workflow.
What is the feature you are proposing to solve the problem?
I'm proposing UUIDv7 generation support be included in the Crypto module.
The actual API for this could either follow Bun's path of a separate method .createRandomUUIDv7(), or add in a property to the existing createRandomUUID options parameter such as version. These are not mutually exclusive, and you could imagine the parameter & method both existing for convenience.
Examples:
const {
createRandomUUIDv7,
createRandomUUID
} = await import('node:crypto');
createRandomUUIDv7();
// => "019d45ea-151f-780b-82a6-d097b39db62a"
createRandomUUID({
version: "v7"
});
// => "019d45ea-fc8e-7792-bfa1-ae58916be0e3"What alternatives have you considered?
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status