Skip to content
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

feat(uuid/unstable): @std/uuid/v7 #5887

Merged
merged 31 commits into from
Sep 4, 2024
Merged

Conversation

Liam-Tait
Copy link
Contributor

@Liam-Tait Liam-Tait commented Sep 1, 2024

Adds UUID Version 7 support.

This variant provides solution for scenarios requiring both uniqueness and chronological ordering.

The same pattern as other uuid generation has been used.

import { v7 } from "@std/uuid";
import { assert } from "@std/assert";
const uuid = v7.generate();
// or
const uuid2 = v7.generate({ timestamp: 1000 }));

I have not included the optional features for sub-millisecond timestamp fraction or carefully seeded counter

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the uuid label Sep 1, 2024
@Liam-Tait Liam-Tait force-pushed the liam/uuid-v7 branch 2 times, most recently from e58b032 to 5382a7b Compare September 1, 2024 15:33
Copy link

codecov bot commented Sep 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.33%. Comparing base (6c684b8) to head (3acb89f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5887   +/-   ##
=======================================
  Coverage   96.32%   96.33%           
=======================================
  Files         483      484    +1     
  Lines       39064    39116   +52     
  Branches     5731     5733    +2     
=======================================
+ Hits        37630    37681   +51     
- Misses       1390     1391    +1     
  Partials       44       44           

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

@Liam-Tait Liam-Tait marked this pull request as ready for review September 1, 2024 16:09
@Liam-Tait Liam-Tait requested a review from kt3k as a code owner September 1, 2024 16:09
uuid/v7.ts Outdated Show resolved Hide resolved
@kt3k kt3k changed the title feat(uuid): add uuid v7 generation and validation feat(uuid/unstable): add uuid v7 generation and validation Sep 2, 2024
@Liam-Tait Liam-Tait marked this pull request as draft September 2, 2024 04:12
@Liam-Tait Liam-Tait marked this pull request as ready for review September 2, 2024 09:14
@Liam-Tait Liam-Tait requested a review from kt3k September 2, 2024 09:22
@babiabeo
Copy link
Contributor

babiabeo commented Sep 2, 2024

Should we consider supporting monotonicity?

uuid/v7.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Cleanly done so far! Nice. Few concerns.

uuid/v7.ts Outdated Show resolved Hide resolved
uuid/v7.ts Outdated Show resolved Hide resolved
uuid/v7.ts Outdated Show resolved Hide resolved
@Liam-Tait
Copy link
Contributor Author

Should we consider supporting monotonicity?

I intentionally left out the optional features, these could be added in a seperate pr as an option, for this pr I would like to start with the basic implementation

implementations MAY fill the 74 bits, jointly, with a combination of the following subfields, in this order from the most significant bits to the least, to guarantee additional monotonicity within a millisecond:

  • An OPTIONAL sub-millisecond timestamp fraction (12 bits at maximum) as per Section 6.2 (Method 3).
  • An OPTIONAL carefully seeded counter as per Section 6.2 (Method 1 or 2).
  • Random data for each new UUIDv7 generated for any remaining space.

link

@Liam-Tait Liam-Tait requested a review from iuioiua September 3, 2024 07:33
@iuioiua iuioiua changed the title feat(uuid/unstable): add uuid v7 generation and validation feat(uuid/unstable): @std/uuid/v7 Sep 3, 2024
uuid/v7.ts Show resolved Hide resolved
uuid/v7.ts Outdated Show resolved Hide resolved
uuid/mod.ts Show resolved Hide resolved
uuid/v7.ts Show resolved Hide resolved
Copy link
Contributor

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

LGTM! Only one idea for generate().

uuid/v7.ts Outdated Show resolved Hide resolved
@iuioiua iuioiua requested a review from kt3k September 3, 2024 23:23
Copy link
Contributor

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

LGTM again. Again, good work!

@iuioiua iuioiua enabled auto-merge (squash) September 4, 2024 02:55
@iuioiua iuioiua merged commit b808ee6 into denoland:main Sep 4, 2024
16 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.

5 participants