Skip to content

feat(uuid/unstable): implement support for UUID V6 - refs #6414 #6415

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

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

ancoron
Copy link
Contributor

@ancoron ancoron commented Feb 18, 2025

Extends the UUID package to include support for UUID version 6.

To a certain degree, this is a copy-paste from UUID v1 with minor adjustments.

@ancoron ancoron requested a review from kt3k as a code owner February 18, 2025 00:51
@CLAassistant
Copy link

CLAassistant commented Feb 18, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the uuid label Feb 18, 2025
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.79%. Comparing base (b719b19) to head (ed3a49a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6415      +/-   ##
==========================================
+ Coverage   95.77%   95.79%   +0.02%     
==========================================
  Files         574      575       +1     
  Lines       42917    42992      +75     
  Branches     6435     6447      +12     
==========================================
+ Hits        41105    41186      +81     
+ Misses       1778     1773       -5     
+ Partials       34       33       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ancoron ancoron force-pushed the feature/uuid-v6 branch 3 times, most recently from 05e4510 to 1b30fdd Compare February 18, 2025 01:04
@kt3k
Copy link
Member

kt3k commented Feb 18, 2025

Can you prefix the file path and export path with unstable_ and unstable- respectively as we have policy to accept any new feature as unstable one first https://github.com/denoland/std/blob/5273accbe942eea6ad854c1efd6abe6bc5a66021/.github/CONTRIBUTING.md#new-features-in-stable-packages-version--100

@ancoron
Copy link
Contributor Author

ancoron commented Feb 18, 2025

@kt3k Sorry, my bad.

Fixed in latest update

@ancoron ancoron force-pushed the feature/uuid-v6 branch 3 times, most recently from 6be87a2 to 185595a Compare February 19, 2025 06:42
@kt3k
Copy link
Member

kt3k commented Feb 20, 2025

This implementation keeps using the previous 'clock_seq' and 'node' values once they are set (like UUID v1), however RFC9562 says they should be reset each id generation:

The clock sequence and node bits SHOULD be reset to a pseudorandom value for each new UUIDv6 generated;

https://www.rfc-editor.org/rfc/rfc9562.html#section-5.6

I think we should generate clock_seq and node each time unless they are set explicitly in options.


Note: npm:uuid seems working like the above suggestion. Last half is fixed for v1, but random for v6:

$ cat b.js 
import * as uuid from "npm:uuid";
console.log(uuid.v1());
console.log(uuid.v1());
console.log(uuid.v1());
console.log(uuid.v1());
console.log(uuid.v6());
console.log(uuid.v6());
console.log(uuid.v6());
console.log(uuid.v6());
$ deno b.js 
bdf3cdd0-ef3d-11ef-9208-bd5755daaa64
bdf41bf0-ef3d-11ef-9208-bd5755daaa64
bdf41bf1-ef3d-11ef-9208-bd5755daaa64
bdf41bf2-ef3d-11ef-9208-bd5755daaa64
1efef3db-df41-6bf3-b780-2598bada4d30
1efef3db-df41-6bf4-8142-e079a4ba130d
1efef3db-df41-6bf5-b49b-6fadd332b448
1efef3db-df41-6bf6-8c8a-7fb7395e2c44

@kt3k kt3k changed the title feat(uuid): implement support for UUID V6 - refs #6414 feat(uuid/unstable): implement support for UUID V6 - refs #6414 Feb 20, 2025
@ancoron ancoron force-pushed the feature/uuid-v6 branch 3 times, most recently from 55a99b6 to 2b7712a Compare February 22, 2025 10:19
@ancoron
Copy link
Contributor Author

ancoron commented Feb 22, 2025

Latest adjustments add some more tests to it (apart from reusing the same tests as from V1):

  1. generate() uses provided rng function - makes sure the provided rng function is invoked as a function
  2. generate() uses provided random data - makes sure the provided random data is used as-is
  3. generate() defaults to random node and clock sequence - makes sure the default behavior follows the recommendation by simply generating actual random data for each new UUID and does not keep them around for reuse (only millisecond and nanosecond values are cached from last invocation)


for (let i = 0; i < numGenerate; i++) {
const u = generate(v6options);
assert(!uuids.includes(u), "Duplicate random data detected");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating!

Now this looks perfect. Nice work!

@kt3k kt3k merged commit 6811835 into denoland:main Mar 6, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants