validatedo v0.1.0
Table of Contents
ValidateDo
Builds an object that is specific to a predefined model that will be used to extract arguements from the request, validate, and format a return. Accepts
Parameters
model
JSON An object that defines the location, name, and valid definition for a particular endpoint. Exclusion of any location will result in that part of the request being ignored from validationmodel.options
JSON object containing any options specific to this model. This class will focus on options defined using the key "validate"model.options.validate
JSON object containing any options that should be applied to the validation process. model.options.validate will override any options set by options.validate
options
JSON object containing any options specific to this service. This class will focus on options defined using the key "validate"
- Throws TypeError If an object, other than a JSON, was passed into either arguement during instantiation
setOptions
assert input, set default values, and combine input to determine options that will be used Options can be defined in either the model or options input. Default this.options will be set if not defined elsewhere
Parameters
model
(UNDEFINED | JSON) An object that defines the location, name, and valid definition for a particular endpoint. Exclusion of any location will result in that part of the request being ignored from validationoptions
(UNDEFINED | JSON) object containing any options specific to this service. This class will focus on options defined using the key "validate"
- Throws TypeError Model is not a JSON, yet defined
- Throws TypeError Options is not a JSON, yet defined
Returns JSON Compiled option list
getModelValidateOptions
Extracts the options, that are specific to this class, from the model
Parameters
Returns JSON Extracted Object
validateOptions
Validate that the passed options are of valid type
Parameters
options
(UNDEFINED | JSON) object containing any options specific to this service. This class will focus on options defined using the key "validate"
- Throws TypeError Options is not a JSON, yet defined
getOptionsValidateOptions
Extracts the options, that are specific to this class, from the options argument
Parameters
Returns JSON Extracted Object
parseSchemas
Parses the input model and extracts the key/value pair for any predifened key ('header', 'query', 'params', 'body') The keys will remain in the order that they were given
Parameters
model
(UNDEFINED | JSON) Object containing keys 'header', 'query', 'params', 'body' with an associated value that defines which elements are to be evaluated and the evaluation definition. The value should meet the needed criteria of the valition tool that will be used.model.header
OBJECT objects that can be found the request header and their validation definitionmodel.params
OBJECT objects that can be found the request params and their validation definitionmodel.query
OBJECT objects that can be found the request query and their validation definitionmodel.body
OBJECT objects that can be found the request body and their validation definition
Returns (UNDEFINED | JSON) object containing key/value pairs whos keys are found in the validArray list. Returns undefined if none were found
schemas
Return the validation schemas that this class is defined to use
checkValidateInput
Validate if the source object to validate is of valid type
Parameters
sourceJSON
JSON
checkValidateFunctionPromise
Checks is the validate function is a proper function and if it is a Promise
Parameters
validateFunc
Function
Returns Boolean true if it is a Promise
checkValidateCallback
Validates that the callback function, that the validation process calls, is a valid function. If nothing is passed, an internal finction is provided
Parameters
Returns Function Valid callback function
validate
base validation method that calls a provided function with the class arguments and available callback function
Parameters
source
JSON Object containing elements that will be extracted and validatedvalidateFunc
Function Method that will perform the evaluationvalidateFunc.input
ANY Object to be validatedvalidateFunc.model
ANY Validation model that is able to be interpretted by validation functionvalidateFunc.options
(UNDEFINED | JSON) Options that the validation function can acceptvalidateFunc.callback
(UNDEFINED | Function) Option callback that can be used in place of validation function returning a promise
done
(UNDEFINED | FUNCTION) Option callback that can be used in place of validation function returning a promise
init
External method call that support class instantiation without "new"
Parameters
7 years ago