Skip to content

feat: add @AllowNull, @AutoIncrement, @Comment, @Default, @PrimaryKey, and validation decorators - #15384

Merged
ephys merged 10 commits into
mainfrom
ephys/more-decorators
Dec 10, 2022
Merged

ephys merged 10 commits into
mainfrom
ephys/more-decorators

Conversation

@ephys

@ephys ephys commented Dec 3, 2022 •

Copy link
Copy Markdown
Member

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)

@ephys ephys mentioned this pull request Dec 3, 2022
13 of 15 tasks

@evanrittenhouse evanrittenhouse 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.

Minor comments, but wow this is some excellent code.

Comment thread src/decorators/legacy/validation.ts Resolved
Comment thread test/unit/esm-named-exports.test.js Resolved
Comment thread test/unit/decorators/attribute.test.ts Resolved

@WikiRik WikiRik left a comment

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.

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

Comment thread src/instance-validator.js Resolved
Comment thread test/unit/esm-named-exports.test.js Resolved

@fzn0x fzn0x left a comment

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.

Amazing work

@ephys

ephys commented Dec 10, 2022

Copy link
Copy Markdown
Member Author

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.

4 participants