Skip to content

Commit

Permalink
refactor(src): babel6, ajv 3.x
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses babel 6 and ajv 3.x, which introduces json-schema 5 proposal,
allow schemas without id by passing them explicitly during walk-over
  • Loading branch information
AVVS committed Jan 2, 2016
1 parent 8f556ad commit 3dcb767
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"transform-es2015-spread",
"transform-es2015-destructuring",
"transform-strict-mode",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
"transform-object-rest-spread",
"transform-class-properties"
]
}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Validation module for amqp transport of microservices
# Validation module

[![Build Status](https://semaphoreci.com/api/v1/projects/8895d4a7-aeaa-4453-96e4-32bb4960536e/633151/badge.svg)](https://semaphoreci.com/makeomatic/ms-validation)

This is basically a wrapper of [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid) module.
What it does - is accepts a directory with schemas, reads it in an async fashion and caches validators under it's name, minus it's extension (to be completely)
honest - it strips down `.json` only. Based on the bluebird promises.
This is basically a wrapper of [ajv](https://github.com/epoberezkin/ajv) module.
What it does - is accepts a directory with schemas, reads it in an async or sync fashion based on your preference
and caches validators under it's name, minus it's extension (to be completely honest - it strips down `.json` only).
Based on the bluebird promises.

## Installation

`npm i ms-amqp-validation -S`
`npm i ms-validation -S`

## Usage

Expand Down
34 changes: 23 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "ms-validation",
"version": "0.5.7",
"description": "ajv-based validation utils for mservice architecture",
"main": "./lib/index.js",
"scripts": {
"compile": "if [[ $NODE_ENV != \"production\" ]]; then ./node_modules/.bin/babel -d ./lib --optional es7.objectRestSpread,es7.classProperties,es7.decorators ./src; fi",
"compile": "./node_modules/.bin/babel -d ./lib ./src",
"pretest": "npm run compile",
"prepublish": "npm run compile",
"test": "./node_modules/.bin/mocha --require ./test/babelhook.js --bail -R spec"
"test": "./node_modules/.bin/mocha",
"semantic-release": "./node_modules/.bin/semantic-release pre && npm publish && ./node_modules/.bin/semantic-release post"
},
"repository": {
"type": "git",
"url": "git+https://github.com/makeomatic/ms-validation.git"
},
"author": "Vitaly Aminev <v@makeomatic.me>",
"author": "Vitaly Aminev <v@makeomatic.ru>",
"contributors": [
"Dmitry Gorbunov <[email protected]> (http://tewi.tk)"
],
Expand All @@ -22,20 +23,31 @@
},
"homepage": "https://github.com/makeomatic/ms-validation#readme",
"devDependencies": {
"babel": "^5.8.34",
"babel-core": "^5.8.33",
"babel-cli": "^6.3.17",
"babel-eslint": "^4.1.6",
"babel-plugin-transform-class-properties": "^6.3.13",
"babel-plugin-transform-es2015-destructuring": "^6.3.15",
"babel-plugin-transform-es2015-parameters": "^6.3.26",
"babel-plugin-transform-es2015-shorthand-properties": "^6.3.13",
"babel-plugin-transform-es2015-spread": "^6.3.14",
"babel-plugin-transform-object-rest-spread": "^6.3.13",
"babel-plugin-transform-strict-mode": "^6.3.13",
"babel-register": "^6.3.13",
"chai": "^3.4.1",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.0.0",
"eslint-config-airbnb": "^2.1.1",
"eslint-plugin-mocha": "^1.1.0",
"mocha": "^2.3.4"
"install": "^0.4.1",
"mocha": "^2.3.4",
"semantic-release": "^4.3.5"
},
"dependencies": {
"ajv": "^2.3.0",
"ajv-i18n": "^1.1.0",
"bluebird": "^3.0.6",
"ajv": "^3.1.0",
"bluebird": "^3.1.1",
"callsite": "^1.0.0",
"common-errors": "^0.5.3"
},
"release": {
"verifyConditions": []
}
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Validator {
*/
constructor(schemaDir, filter, schemaOptions = {}) {
this.schemaDir = schemaDir;
this.schemaOptions = Object.assign({}, Validator.defaultOptions, schemaOptions);
this.schemaOptions = { ...Validator.defaultOptions, ...schemaOptions };
this.filterOpt = filter || json;
this.validators = {};

Expand Down Expand Up @@ -150,9 +150,9 @@ class Validator {
}

const _ajv = this.ajv;
filenames.forEach((filename) => {
filenames.forEach(filename => {
const schema = require(path.resolve(dir, filename));
_ajv.addSchema(schema);
_ajv.addSchema(schema, schema.id || path.basename(filename, path.extname(filename)));
});
}

Expand All @@ -178,7 +178,7 @@ class Validator {

let onlyAdditionalProperties = true;
const error = new ValidationError(`${schema} validation failed: ${readable}`);
validate.errors.forEach((err) => {
validate.errors.forEach(err => {
if (err.message !== 'should NOT have additional properties') {
onlyAdditionalProperties = false;
}
Expand Down
8 changes: 0 additions & 8 deletions test/babelhook.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const path = require('path');

describe('Validation', function validationSuite() {
const Validation = require('../src');
const Validation = require('../lib');
const CORRECT_PATH = path.resolve(__dirname, './fixtures');
const BAD_PATH = path.resolve(__dirname, './notexistant');
const EMPTY_PATH = path.resolve(__dirname, './fixtures/empty');
Expand Down
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require babel-register
-R spec

0 comments on commit 3dcb767

Please sign in to comment.