cloud-config-toolkit-ajv

0.0.2 • Public • Published

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.

/cloud-config-toolkit-ajv/

    Package Sidebar

    Install

    npm i cloud-config-toolkit-ajv

    Weekly Downloads

    1

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    7.8 kB

    Total Files

    15

    Last publish

    Collaborators

    • panzerdp
    • alexoco