cloud-config-toolkit-ajv

Cloud config toolkit ajv integration

Usage no npm install needed!

<script type="module">
  import cloudConfigToolkitAjv from 'https://cdn.skypack.dev/cloud-config-toolkit-ajv';
</script>

README

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.