šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@microfleet/validation

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microfleet/validation

ajv-based validation utils for mservice architecture

8.1.2
Source
npm
Version published
Weekly downloads
31
-8.82%
Maintainers
1
Weekly downloads
Ā 
Created
Source

Microfleet Validation Module

Build Status

This is basically a wrapper of 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

yarn add @microfleet/validation

Usage

// Lets assume that we have a following file structure:
//
// .
// ./schemas/config.json
// ./schemas/ping.json
// ./index.js
//

import Errors = require('common-errors');
import Validator, { HttpStatusError } from '@microfleet/validation';
const validator = new Validator('./schemas');

// some logic here
validator.validate('config', {
  configuration: 'string'
})
.then(doc => {
  // all good
  // handle doc, which would eq { configuration: 'string' }
})
.catch(HttpStatusError, (error) => {
  // handle error here
});

const result = validator.validateSync('config', { data: true });
if (result.error) {
  // handle error!
}

// do stuff
// ...

// init filter
validator.init('./dir', null, true); // all schemas in this dir will filter out additional properties instead of throwing an error

// catches when we only have 417 errors
validator.filter('config', { conf: 'string', extra: true })
  .then(result => {
    //  { conf: 'string' }
  });

FAQs

Package last updated on 10 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts