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: add @AllowNull, @AutoIncrement, @Comment, @Default, @PrimaryKey, and validation decorators #15384

Merged
merged 10 commits into from Dec 10, 2022

Conversation

ephys
Copy link
Member

@ephys ephys commented Dec 3, 2022

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 (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description Of Change

I reworked our internal decorator utils to reduce duplication of code

This PR adds the following decorators:

AllowNull
AutoIncrement
ColumnName
Comment
Default
NotNull
PrimaryKey

ValidateAttribute
ModelValidator
Contains
Equals
Is
IsAfter
IsAlpha
IsAlphanumeric
IsArray
IsBefore
IsCreditCard
IsDate
IsDecimal
IsEmail
IsFloat
IsIP
IsIPv4
IsIPv6
IsIn
IsInt
IsLowercase
IsNumeric
IsUUID
IsUppercase
IsUrl
Len
Max
Min
Not
NotContains
NotEmpty
NotIn

A few differences with sequelize-typescript:

  • IsNull has been removed
  • NotNull configures the "allowNull" option instead of validation.notNull. I've marked validation.notNull and validation.isNull for future removal, as it makes no sense to have three ways to validate whether something is or isn't null
  • validation and hook decorators can be used on symbol properties ✨
  • Validate has been renamed to ValidateAttribute
  • Validator has been renamed to ModelValidator
    • Static model validators don't receive the instance to validate through "this", but as the first parameter.
    • Instance model validators remain the same: they receive it through "this"
  • I've added ColumnName as a more user friendly name than field (until we rename field to columnName)

Copy link
Member

@evanrittenhouse evanrittenhouse left a comment

Choose a reason for hiding this comment

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

Minor comments, but wow this is some excellent code.

src/decorators/legacy/validation.ts Outdated Show resolved Hide resolved
test/unit/esm-named-exports.test.js Show resolved Hide resolved
test/unit/decorators/attribute.test.ts Show resolved Hide resolved
src/decorators/legacy/attribute-utils.ts Show resolved Hide resolved
src/decorators/legacy/decorator-utils.ts Show resolved Hide resolved
src/decorators/legacy/decorator-utils.ts Show resolved Hide resolved
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Two unused imports but no further new comments from my side. Looking really good and also some nice improvements on the hook decorators!

src/instance-validator.js Outdated Show resolved Hide resolved
test/unit/esm-named-exports.test.js Outdated Show resolved Hide resolved
Copy link
Member

@fzn0x fzn0x left a comment

Choose a reason for hiding this comment

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

Amazing work

@ephys
Copy link
Member Author

ephys commented Dec 10, 2022

Thanks :)

@ephys ephys merged commit 08eb398 into main Dec 10, 2022
@ephys ephys deleted the ephys/more-decorators branch December 10, 2022 17:27
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.

None yet

4 participants