-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: add randomULID
function
#49074
Conversation
Review requested:
|
Why does this need to belong in node core? |
3ea8b1e
to
7929db6
Compare
Signed-off-by: Xavier Stouder <[email protected]>
Signed-off-by: Xavier Stouder <[email protected]>
Signed-off-by: Xavier Stouder <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution @Xstoudi!
randomUUID()
exists in core for various reasons. UUIDv4 is a very popular format, to the point where DBMS have added data types to represent it. Perhaps most importantly, randomUUID()
is standardized through the Web Cryptography API. If APIs for some other format (newer UUID formats or even ULID) were to be standardized through W3C, Node.js would likely adopt the relevant APIs as well.
Even though Node.js, Deno, Bun, and 90% of browsers have supported randomUUID()
for years, the uuid
package on npm still sees more than 90 million downloads per week. That's more than 100 times the popularity of the ulid
package despite the feature already being in core.
UUIDv4 is the most common variant of UUIDs. Not only is randomUUID()
standardized as mentioned above, but also the UUID format itself is specified in RFC 4122.
ULID has a few advantages over UUIDv4 in some scenarios, most of which are minor. However, some are significant for a certain applications. But even then, there are alternatives to ULID. The IETF draft "New UUID Formats" describes multiple new UUID formats, some of which have similar characteristics.
At this point, I don't see why ULID belongs in core. Compared to UUIDv4, its popularity is marginal at best, and there are several other candidates for standardization. Lastly, adding randomULID()
only to the node:crypto
module but not to the WebCryptoAPI crypto
object seems confusing.
If you are optimistic about this feature, I'd suggest to perhaps discuss this in an issue in the Web Crypto API repository first. Based on the little information I have about ULID, I don't expect it to be accepted there, but if it is, that would justify addition to Node.js and several other JavaScript runtimes.
Hello @tniessen , thanks a lot for your answer!
I am not really sure DBMS data type example is relevant as it is often just a sugar alias for fixed-size text or blob/binary. By that I mean that it's most of the time not needed, but nice to have.
core's That say, using this as an argument, we could argue that userland packages It leads me to think that only focusing on package popularity can be both a reason to land in core and to not do it, depending on individual opinion about the feature itself.
Yes, but I argue that
I'd be more than happy to try to propose an implementation for UUIDv7 if the draft being a draft is not fully blocking, and if current lack of popularity (as obviously it's still a draft) is not either.
Marginal popularity: agreed.
Well if I wanted to add it in Web Crypto API, I would probably have done that, but time-based UUID were already briefly noticed as not so relevant to browser in the Anyway, thanks @tniessen for taking the time to review this! |
I've got to agree with @tniessen on this. I'm -1 on landing this in core. Also, given the lack of further discussion for over a month, I think we can close this. |
I propose to land
randomULID
in thecrypto
subsystem.ULID are lexicographically sortable identifiers contaning both the time it was generated and a random part. Spec can be found here: https://github.com/ulid/spec
ULID implementation exists in userland, currently getting around 768'000 downloads per week: https://www.npmjs.com/package/ulid
Since its release, popularity constantly grew: https://npmtrends.com/ulid
I will be happy to get feedbacks on the implementation and I'm obviously open to discuss if you have reluctance to land it in Node.js.