0.1.0 • Published 6 years ago

validatedo v0.1.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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 validation
    • model.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 validation
  • options (UNDEFINED | JSON) object containing any options specific to this service. This class will focus on options defined using the key "validate"
    • options.validate (UNDEFINED | JSON) object containing any options that should be applied to the validation process.
  • 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"
    • options.validate (UNDEFINED | JSON) object containing any options that should be applied to the validation process.
  • 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 definition
    • model.params OBJECT objects that can be found the request params and their validation definition
    • model.query OBJECT objects that can be found the request query and their validation definition
    • model.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

checkValidateFunctionPromise

Checks is the validate function is a proper function and if it is a Promise

Parameters

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 validated
  • validateFunc Function Method that will perform the evaluation
    • validateFunc.input ANY Object to be validated
    • validateFunc.model ANY Validation model that is able to be interpretted by validation function
    • validateFunc.options (UNDEFINED | JSON) Options that the validation function can accept
    • validateFunc.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

  • model JSON see class definition
  • options JSON see class definition