Skip to content

feat(core): add Node.js native UUIDv7 generation with fallback - #18261

Closed
vineetj12 wants to merge 2 commits into
sequelize:mainfrom
vineetj12:feat/uuidv7-native-node
Closed

vineetj12 wants to merge 2 commits into
sequelize:mainfrom
vineetj12:feat/uuidv7-native-node

Conversation

@vineetj12

@vineetj12 vineetj12 commented Jul 14, 2026 •

Copy link
Copy Markdown

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository?
  • Did you update the typescript typings accordingly (not applicable)
  • Does the description below contain a link to an existing issue or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

This PR adds runtime support for native UUIDv7 generation in Node.js.

Changes

  • Uses crypto.randomUUIDv7() when available.
  • Falls back to the uuid package's v7() implementation when the native API is unavailable.
  • Adds unit tests covering both the native implementation and fallback behavior.

This PR is focused only on the Node.js runtime support for UUIDv7 generation.

The PostgreSQL-specific UUIDv7 support has been moved to a separate PR as requested during review.

List of Breaking Changes

None.

Summary by CodeRabbit

  • New Features

    • UUID v7 generation now prefers the platform’s native UUIDv7 implementation when available, with an automatic fallback to the existing generator.
  • Bug Fixes

    • Improved reliability and compatibility for UUID v7 creation across supported runtime environments.
  • Tests

    • Added unit tests covering native UUIDv7 usage (including call count) and the fallback path with UUID format/version validation.

@vineetj12
vineetj12 requested a review from a team as a code owner July 14, 2026 17:17
@vineetj12
vineetj12 requested review from WikiRik and sdepold July 14, 2026 17:17
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4d3938d-4d02-4bc4-af52-54e65161ac81

📥 Commits

Reviewing files that changed from the base of the PR and between a7798a8 and 326d573.

📒 Files selected for processing (1)
  • packages/core/src/expression-builders/uuid.ts
💤 Files with no reviewable changes (1)
  • packages/core/src/expression-builders/uuid.ts

📝 Walkthrough

Walkthrough

UUIDv7 generation now prefers Node.js’s native crypto implementation when available and falls back to the uuid package. Unit tests cover native invocation and UUIDv7 fallback formatting.

Changes

UUIDv7 generation

Layer / File(s) Summary
Native UUIDv7 selection and fallback
packages/core/src/expression-builders/uuid.ts, packages/core/test/unit/expression-builders/uuid.test.ts
Adds runtime detection of crypto.randomUUIDv7, exposes generateUuidV7, retains the package fallback, and tests both generation paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: sdepold, wikirik

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: native Node.js UUIDv7 generation with a fallback path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/expression-builders/uuid.ts (1)

9-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid unbound method invocation.

Extracting the randomUUIDv7 method and calling it directly detaches it from the crypto object. While Node.js's crypto methods generally do not rely on this, calling it bound to its object is a safer practice. You can also simplify the type casting.

♻️ Proposed refactor
 function getNativeUuidV7(): string | undefined {
-  const nativeUuidV7 = (crypto as typeof crypto & { randomUUIDv7?: unknown }).randomUUIDv7;
-
-  return typeof nativeUuidV7 === 'function' ? nativeUuidV7() : undefined;
+  const cryptoWithV7 = crypto as typeof crypto & { randomUUIDv7?: () => string };
+  return typeof cryptoWithV7.randomUUIDv7 === 'function' ? cryptoWithV7.randomUUIDv7() : undefined;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/expression-builders/uuid.ts` around lines 9 - 13, Update
getNativeUuidV7 so randomUUIDv7 is invoked with crypto as its receiver instead
of calling an extracted method; simplify the crypto type assertion while
preserving the undefined fallback when the method is unavailable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/expression-builders/uuid.ts`:
- Around line 9-13: Update getNativeUuidV7 so randomUUIDv7 is invoked with
crypto as its receiver instead of calling an extracted method; simplify the
crypto type assertion while preserving the undefined fallback when the method is
unavailable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a8b1341-5e39-423a-8b8b-1270f4375066

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab7d48 and a7798a8.

📒 Files selected for processing (2)
  • packages/core/src/expression-builders/uuid.ts
  • packages/core/test/unit/expression-builders/uuid.test.ts

@vineetj12

Copy link
Copy Markdown
Author

Thanks for the review! Per WikiRik's clarification, this feature should
live in the same PR as the PostgreSQL support rather than as a separate
PR. Closing this in favor of #18258, which already contains both the
Node.js native detection logic and the PostgreSQL version-gated support.

@vineetj12 vineetj12 closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant