Skip to content

fix(core): allow 'all' as isUUID validator argument#18200

Open
cyphercodes wants to merge 3 commits into
sequelize:mainfrom
cyphercodes:fix-isuuid-type-18171
Open

fix(core): allow 'all' as isUUID validator argument#18200
cyphercodes wants to merge 3 commits into
sequelize:mainfrom
cyphercodes:fix-isuuid-type-18171

Conversation

@cyphercodes

@cyphercodes cyphercodes commented Apr 5, 2026

Copy link
Copy Markdown

Description of Changes

The isUUID field validator accepts both number (1, 2, 3, 4, 5, 7) and the string 'all' as valid arguments, but the TypeScript type definition only allowed number.

This PR updates the type to include 'all' as a valid option for both:

  • The simple form: isUUID: 'all'
  • The object form: isUUID: { msg: string; args: number | 'all' }

Issue Reference

Fixes #18171

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing

Added TypeScript type tests in test/types/validators.ts to verify that both isUUID: 4 and isUUID: 'all' are accepted by the type checker.

Checklist

  • I have read the contribution guidelines
  • This change follows the project's coding style
  • I have added tests that verify the type change works correctly

Summary by CodeRabbit

  • New Features

    • UUID validator now accepts the "all" option to validate against all UUID versions.
    • Validator supports specifying a version (numeric or "all") and providing a custom error message.
  • Tests

    • Added tests covering numeric-version, "all" string, and object-form UUID validation cases.

The isUUID field validator accepts both number (1, 2, 3, 4, 5, 7)
and the string 'all' as valid arguments, but the TypeScript type
definition only allowed number.

This fix updates the type to include 'all' as a valid option for
both the simple form (isUUID: 'all') and the object form
(isUUID: { msg: string; args: number | 'all' }).

Fixes sequelize#18171
@cyphercodes cyphercodes requested a review from a team as a code owner April 5, 2026 15:48
@cyphercodes cyphercodes requested review from ephys and sdepold April 5, 2026 15:48
@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d58bd42-9421-40f7-8a89-c827bee5053b

📥 Commits

Reviewing files that changed from the base of the PR and between b8fabfc and a0f4cd4.

📒 Files selected for processing (1)
  • packages/core/src/model.d.ts

📝 Walkthrough

Walkthrough

Column isUUID validator typing changed from numeric-only to use validator's UUIDVersion literal type (supports values like 'all' and 4), and tests add a UserWithUUID model exercising numeric, 'all' string, and object { msg, args } validator forms.

Changes

Cohort / File(s) Summary
Type Definition Update
packages/core/src/model.d.ts
Changed ColumnValidateOptions.isUUID type from `number
Test Coverage
packages/core/test/types/validators.ts
Added UserWithUUID model with three attributes validating isUUID as 4, 'all', and { msg: string; args: 'all' } to exercise new typing/usage.

Sequence Diagram(s)

(Skipped — changes are type updates and test additions without multi-component runtime control flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • sdepold
  • ephys

Poem

🐇 I hopped through types and found,
'all' and 4 on safer ground,
Tests now dance, validators sing,
A tiny rabbit fixed a thing,
🥕 code hops onward, springing round.

🚥 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 accurately and specifically describes the main change—allowing 'all' as a valid isUUID validator argument type—matching the PR's primary objective.
Linked Issues check ✅ Passed The PR successfully implements the objective from #18171 by updating ColumnValidateOptions.isUUID to accept UUIDVersion type (covering numeric versions 1-7 and 'all'), with test cases validating both numeric and 'all' forms.
Out of Scope Changes check ✅ Passed All changes are within scope—only the isUUID type definition and corresponding test cases were modified; no unrelated functionality changes were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Comment thread packages/core/src/model.d.ts Outdated
* only allow uuids
*/
isUUID?: number | { msg: string; args: number };
isUUID?: number | 'all' | { msg: string; args: number | 'all' };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we import from @types/validator?

@ephys ephys changed the title fix(types): allow 'all' as isUUID validator argument fix(core): allow 'all' as isUUID validator argument Apr 5, 2026
The isUUID field validator delegates to validator.js, whose UUIDVersion type covers numeric UUID versions as well as string versions such as 'all'.

Reuse the type from @types/validator for both the direct isUUID form and the custom message args form, and keep typings coverage for the newly supported 'all' usage.

Fixes sequelize#18171
@cyphercodes

Copy link
Copy Markdown
Author

Pushed a follow-up commit addressing the review feedback about reusing validator's own type.

Summary:

  • Updated ColumnValidateOptions.isUUID to import and use UUIDVersion from validator/lib/isUUID instead of manually spelling number | 'all'.
  • Kept the existing type coverage for numeric UUID versions, direct 'all', and { msg, args: 'all' }.
  • Updated the PR title to the semantic form: fix(core): allow 'all' as isUUID validator argument.

Local verification:

  • corepack yarn eslint packages/core/src/model.d.ts --quiet --report-unused-disable-directives
  • corepack yarn prettier --check packages/core/src/model.d.ts

Note: I avoided force-updating the branch to latest upstream because GitHub rejected the rebased push with the current OAuth token lacking workflow scope for upstream workflow changes. This commit is applied on top of the existing PR branch instead.

@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/model.d.ts (1)

9-9: Prefer the top-level 'validator' import over the deep internal path.

UUIDVersion is exported at the top level of @types/[email protected], so the idiomatic import is from 'validator'. TypeScript resolves this to the @types/validator declarations automatically; you don't import from @types/validator directly. The current deep import from 'validator/lib/isUUID' couples the public .d.ts surface to DefinitelyTyped's internal file structure and is unnecessarily fragile.

Dependencies are already correct: both validator and @types/validator are declared in dependencies of @sequelize/core, so the new public type will resolve properly for downstream consumers.

♻️ Suggested change
-import type { UUIDVersion } from 'validator/lib/isUUID';
+import type { UUIDVersion } from 'validator';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/model.d.ts` at line 9, The current type import uses a deep
path: replace the import of UUIDVersion from 'validator/lib/isUUID' with the
top-level module export from 'validator' so the public .d.ts surface doesn't
depend on DefinitelyTyped internals; update the import statement that references
UUIDVersion to import from 'validator' and ensure any other references to that
symbol (UUIDVersion) remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/model.d.ts`:
- Line 9: The current type import uses a deep path: replace the import of
UUIDVersion from 'validator/lib/isUUID' with the top-level module export from
'validator' so the public .d.ts surface doesn't depend on DefinitelyTyped
internals; update the import statement that references UUIDVersion to import
from 'validator' and ensure any other references to that symbol (UUIDVersion)
remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 30103197-235c-4399-b99d-06776a34b613

📥 Commits

Reviewing files that changed from the base of the PR and between e8baeec and b8fabfc.

📒 Files selected for processing (1)
  • packages/core/src/model.d.ts

Comment thread packages/core/src/model.d.ts Outdated
StrictRequiredBy,
} from '@sequelize/utils';
import type { SetRequired } from 'type-fest';
import type { UUIDVersion } from 'validator/lib/isUUID';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
import type { UUIDVersion } from 'validator/lib/isUUID';
import type { UUIDVersion } from 'validator';

I haven't tested it, but I think this is cleaner and coderabbit also had a nitpick comment that this is nicer. Could you see if this suggestion works?

@cyphercodes

Copy link
Copy Markdown
Author

Thanks, @WikiRik. I tested the suggestion and updated model.d.ts to import UUIDVersion from top-level validator instead of validator/lib/isUUID.

Verification (all passed):

  • yarn eslint packages/core/src/model.d.ts --quiet --report-unused-disable-directives
  • yarn prettier --check packages/core/src/model.d.ts
  • yarn tsc -p packages/core/tsconfig.json --noEmit
  • yarn tsc -b packages/core/test/tsconfig.json

I kept verification scoped to the changed file and @sequelize/core typings; I did not run a full monorepo build.

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.

Type for isUUID validator is missing support for 'all'

2 participants