0.0.2 • Published 6 years ago

cloud-config-toolkit-ajv v0.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Cloud config toolkit ajv

Cloud config toolkit ajv implements the validator and exporter interfaces required by Cloud config toolkit. It uses Ajv schema validator.

Installation

Install the package in the project:

npm install --save cloud-config-toolkit-ajv

Then use Validator and Exporter constructors in cct.conf.js:

// `cct.conf.js`
const { Validator, Exporter } = require('cloud-config-toolkit-ajv');

const schema = {
  "type": "object",
  "properties": {
    "foo": { "type": "string" },
    "bar": { "type": "integer" },
    "baz": {
      "range": [2, 4], 
      "exclusiveRange": true,
      "type": "integer"
    }
  }
};
const keywords = [{
  name: 'range',
  definition: {
    type: 'number',
    compile: function (sch, parentSchema) {
      const min = sch[0];
      const max = sch[1];

      return parentSchema.exclusiveRange === true
        ? function (data) { return data > min && data < max; }
        : function (data) { return data >= min && data <= max; }
    }
  }
}];

module.exports = {
  validator: new Validator({
    schema,
    keywords
  }),
  exporter: new Exporter({
    schema,
    keywords
  }),
  // ...
};

Configuration

Both Validator and Exporter constructors accept a configuration object with properties:

For more details check Cloud config toolkit documentation.