Gathering detailed insights and metrics for sequelize-validate-subfields-typed-validators
Gathering detailed insights and metrics for sequelize-validate-subfields-typed-validators
Gathering detailed insights and metrics for sequelize-validate-subfields-typed-validators
Gathering detailed insights and metrics for sequelize-validate-subfields-typed-validators
sequelize-validate-subfields adapter for typed-validators
npm install sequelize-validate-subfields-typed-validators
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
241 Commits
2 Watchers
1 Branches
2 Contributors
Updated on Nov 28, 2023
Latest Version
2.1.0
Package Id
sequelize-validate-subfields-typed-validators@2.1.0
Unpacked Size
15.41 kB
Size
4.48 kB
File Count
8
NPM Version
9.6.7
Node Version
20.3.0
Published on
Nov 28, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
use typed-validators to validate JSON attributes of Sequelize models
1npm install --save typed-validators sequelize-validate-subfields-typed-validators
1import Sequelize from 'sequelize' 2import * as t from 'typed-validators' 3import { validateWithTypedValidators } from 'sequelize-validate-subfields-typed-validators' 4import { flattenValidationErrors } from 'sequelize-validate-subfields' 5 6import sequelize from './sequelize' 7 8const UserInfoType = t.alias( 9 'User', 10 t.object({ 11 phone: t.string(), 12 address: t.object({ 13 required: { 14 line1: t.string(), 15 postalCode: t.number(), 16 state: t.string(), 17 }, 18 optional: { 19 line2: t.string(), 20 }, 21 }), 22 }) 23) 24 25const User = Sequelize.define('User', { 26 username: { 27 type: Sequelize.STRING, 28 validate: { 29 notEmpty: { 30 msg: 'required', 31 }, 32 }, 33 }, 34 info: { 35 type: Sequelize.JSON, 36 validate: validateWithTypedValidators(UserInfoType), 37 }, 38}) 39 40try { 41 User.create({ 42 username: '', 43 address: { 44 line2: 2, 45 postalCode: '76034', 46 state: 'TX', 47 }, 48 }) 49} catch (error) { 50 if (error instanceof Sequelize.ValidationError) { 51 console.error(flattenValidationErrors(error)) 52 } else { 53 console.error(error) 54 } 55}
Output:
[
{path: ['username'], message: 'required'},
{path: ['address', 'line1'], message: 'must be a string'},
{path: ['address', 'line2'], message: 'must be a string'},
{path: ['address', 'postalCode'], message: 'must be a number'},
]
convertValidationErrors(validation, [options])
validation: Validation
A typed-validators
Validation
object containing an errors
array of [path, message, type]
tuples.
options?: {reduxFormStyle?: boolean}
If reduxFormStyle
is true, validation errors on object/array fields will be yielded for the _error
subpath
under that field.
Iterable<FieldValidation>
Yields {path: Array<string | number>, message: string}
objects about validation errors, the format defined by
sequelize-validate-subfields
.
validateWithTypedValidators(typeOrValidator, [options])
A typed-validators
Type
, or a function taking an attribute value and returning a typed-validators
Validation
object or null
. Errors from applying the given function or validating against the given type will be yielded in
sequelize-validate-subfields
format.
options?: {reduxFormStyle?: boolean}
If reduxFormStyle
is true, validation errors on object/array fields will be yielded for the _error
subpath
under that field.
(value: any) => void
A Sequelize custom attribute validation function that uses the given typeOrValidator
to validate attribute values.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
9 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More