Skip to content

Commit

Permalink
use single Ajv
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 27, 2023
1 parent 363510a commit 9d1ee20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const MarkdownIt = require('markdown-it');
const md = new MarkdownIt({html: true, xhtmlOut: false, linkify: true});

const { uniqBy, validator, flatten, cloneDeep } = require('../utils');
const { uniqBy, ajv, flatten, cloneDeep } = require('../utils');
const _get = require('lodash/get');
const _set = require('lodash/set');

Expand Down Expand Up @@ -130,7 +130,7 @@ class Component {
static isValid(q, logger){
let ind = q.space ? `${q.space}::${q.id}` : q.id;

let validate = validator
let validate = ajv
.getSchema('https://hetalang.github.io#/definitions/' + this.schemaName);
if (!validate) {
throw new TypeError(`The schema "${this.schemaName}" is not found.`);
Expand Down
11 changes: 3 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
// preparation of Ajv

const Ajv = require('ajv');

const ajv = new Ajv({allErrors: true}); // jsonPointers: true
require('ajv-errors')(ajv);

const schema = require('./heta.json-schema');
const validator = new Ajv({allErrors: true}) // maybe combine with previous
.addSchema(schema);
require('ajv-errors')(validator);

const ajv = new Ajv({allErrors: true, jsonPointers: true})
.addSchema(schema); // for Component instances
require('ajv-errors')(ajv);

// return array of elements by the selector
function uniqBy(array, selector = (x) => x) {
Expand Down Expand Up @@ -95,7 +91,6 @@ function cloneDeep(o) {
}

module.exports = {
validator,
ajv,
uniqBy,
intersection,
Expand Down

0 comments on commit 9d1ee20

Please sign in to comment.