
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@fyresite/document_validator
Advanced tools
Validate and translate JSON objects for Document Databases like MongoDB or Amazon's DynamoDB.
Validate and translate JSON objects for Document Databases like MongoDB or Amazon's DynamoDB.
npm install --save @fyresite/document_validator
Validations are handled using @fyresite/object-validator and utilizes the validator node module.
module.exports = function (Types, Op) {
return {
"name": {
"first": {
"type": Types.STRING,
"required": true
},
"middle": Types.STRING,
"last": {
"type": Types.STRING,
"required": true
}
},
validateField: {
type: Types.STRING,
validate: {
"method": "matches",
"pattern": "^([a-z ])+$"
}
},
"myInt":{
type: Types.INTEGER,
"required": {
myFloat:Op.eq(4.5)
}
},
"myFloat": Types.FLOAT
"email": {
"type": Types.STRING,
"required": true
},
"phone": {
"type": Types.STRING,
"required": true
},
"dob": {
"type": Types.DATE,
"required": true
}
}
}
var { Validator } = require('@fyresite/document_validator');
var userValidator = new Validator('user');
var userValid = {
"name": {
"first": "Mike",
"middle": "T",
"last": "Jones"
},
"email": "email@example.com",
"phone": "2813308004",
"dob": new Date("1996-11-09")
};
var userInvalid = {
"name": {
"first": "Mike",
"middle": "T",
"last": "Jones"
},
"email": "email@example.com",
"phone": 344,
"dob": new Date("1996-11-09"),
"address": {
"street": "2212 S Banner St",
"street2":"Strong",
"city": "Gilbert",
"state": "AZ",
"zip": 85296
}
};
// Returns emptyObject {} signifying the document was valid
var invalidFields = userValidator.validate(userValid, 'v1');
// Returns object containing all of the validation errors that occurred
var invalidFields = userValidator.validate(userInvalid, 'v1');
var userValidator = new Validator('user', { schemaPath: 'schemas', isS3: true, bucket: 'model-schemas', profile: 'test-profile' });
var userValid = {
"name": {
"first": "Mike",
"middle": "T",
"last": "Jones"
},
"email": "email@example.com",
"phone": "2813308004",
"dob": new Date("1996-11-09"),
"_v" : 1
};
var userInvalid = {
"name": {
"first": "Mike",
"middle": "T",
"last": "Jones"
},
"email": "email@example.com",
"phone": 344,
"dob": new Date("1996-11-09"),
"address": {
"street": "2212 S Banner St",
"street2":"Strong",
"city": "Gilbert",
"state": "AZ",
"zip": 85296
},
"_v" : 1
};
userValidator.init()
.then(() => {
var invalidFields;
// Returns emptyObject {} signifying the document was valid
invalidFields = userValidator.validate(userValid, 'v1');
// Returns object containing all of the validation errors that occurred
invalidFields = userValidator.validate(userInvalid, 'v1');
})
.catch(err => {
console.error(err);
});
Class used validate and translate documents
Kind: global class
Promise
Object
Object
Object
Create a validator.
Param | Type | Default | Description |
---|---|---|---|
schemaName | string | Name of the schema to validate. | |
[config] | Object | Custom configuration options. | |
config.schemaPath | string | "APP_ROOT/schemas" | the path to the schemas folder |
config.isS3 | boolean | true | Define if schema location is a s3 bucket |
config.s3Bucket | string | Name of the s3 bucket to connect the schemas are located | |
config.awsProfile | string | The AWS Profile you want to use to connect to the bucket |
Promise
Used to fetch schema from s3, the instance validate function must be used inside .then() to guarantee that schemas are loaded before validating
Kind: instance method of Validator
Object
Validates document against specific version of the schema
Kind: instance method of Validator
Param | Type | Description |
---|---|---|
document | Object | Document to be validated |
version | string | version to be validated. |
Object
Validates keys for document against specific version of the schema
Kind: instance method of Validator
Param | Type | Description |
---|---|---|
fields | Object | Document to be validated |
version | string | version to be validated. |
Object
Translates document to version specified the documents version is automatically read through the _v property on the document
Kind: instance method of Validator
Param | Type | Description |
---|---|---|
document | Object | Document to be validated |
version | string | version to be translated to. |
Defines the validation rules that will be applied to the document using the Validator
// Export a function (Types, Op) that returns a json
module.exports = function(Types, Op) {
return {
/*
Fields can be defined by setting the ket to the field
name and the type as the value
*/
fieldName: Types.STRING
// Or pass an object for more advanced options
advancedField: {
type: Types.INTEGER, //Type of field *required*
/*
flag that tells validator to return error if field is not provided.
The value can be
*/
required: true,
//Default value to use if field is not provided
default: 0,
/*
Validation object that is used for advanced validation. Methods are based on the validator npm package by cohara87.
For further documentation refer to @fyresite/object_validator
*/
validate: {
"method": "validator method", /** String **/
"param1": value,
"param2": value
}
}
}
}
An function can be passed
module.exports = function(Types, Op) {
return {
field1 : Types.NUMBER
}
}
Class used to provide conditions to require flags
Kind: global class
function
function
function
function
function
function
function
function
function
Checks if the documents value matches any of the conditions
Kind: static method of Op
Param | Type | Description |
---|---|---|
conditions | array | Array of conditions to match on the Op functions are valid conditions |
function
Accepts Op Function and returns opposite value
Kind: static method of Op
Param | Type | Description |
---|---|---|
opFunction | function | valid Op function |
function
Checks if field is set
Kind: static method of Op
function
Checks if field equals value
Kind: static method of Op
Param | Type |
---|---|
value | number | string | boolean |
function
Checks if fields value is greater than the provided value
Kind: static method of Op
Param | Type |
---|---|
value | number |
function
Checks if fields value is greater than or equal to provided value
Kind: static method of Op
Param | Type |
---|---|
value | number |
function
Checks if fields value is less than the provided value
Kind: static method of Op
Param | Type |
---|---|
value | number |
function
Checks if fields value is less than or equal to provided value
Kind: static method of Op
Param | Type |
---|---|
value | number |
FAQs
Validate and translate JSON objects for Document Databases like MongoDB or Amazon's DynamoDB.
The npm package @fyresite/document_validator receives a total of 14 weekly downloads. As such, @fyresite/document_validator popularity was classified as not popular.
We found that @fyresite/document_validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.