jsonql-params-validator
This is for use with jsonql server and client side for type validation, using the contract
as reference point.
The default export is in umd
format. There is also an cjs
version in the dist folder
named jsonql-params-validator.cjs.js
for use with node.js
For validation you can use the following methods:
validateSync
this is the only one that we need to callvalidate(args, params) = Array
validateAsync
same as above but return a promisevalidateAsync(args, params) = Promise
normalizeArgs
this is export main for use on the client sidenormalizeArgs(args, params)
isObject
this is a wrapper of ourcheckIsObject
method to check if the argument is a plain object
For detail please refer to documentation (work in progress at the moment)
If you have problem to import the module, you might need to do
jsonqlParamsValidatordefault
Utility for checking configuration
We also have several methods for checking configuration input, and make sure they are what we expected. The reason we create this is during years of development, how often you find a bug that you never come across when user is using your software - and it turns out the end user is passing a wrong configuration property that cause it? Or the wrong type of the value you expect it. And we heavily use this across our entire jsonql tool set to ensure developer are passing the right configurations, hence to eliminated potential bug.
const checkConfig // sync version checkConfigAsync // return promise constructConfig} =
TBC about how to use them
Custom Errors for checking
We also export 3 custom errors that we throw from within the validation function. And you can use them to check against your code to know what went wrong with your configuration. This will be in a separate package jsonql-errors
const JsonqlTypeError JsonqlEnumError JsonqlCheckerError } =
Example:
let appProps = importantProp: anotherProp: anythingProp: let constProps = propDontWantToChange: 'I-must-be-here!' let config = importantProp: 'ok'; // passing a string?!
NEWBRAN LTD / TO1SOURCE CN (c) 2019