How to use the JSV.JSV function in jsv

To help you get started, we’ve selected a few jsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / csp-logger / lib / config.js View on Github external
var fs = require('fs');
var JSV = require('JSV').JSV;
var schema = require('../conf/env.schema.json');
var demoConf = require.resolve('../conf/env.json.dist');

function processConf(config, teardown) {

  var configValidationReport = JSV.createEnvironment().validate(config, schema);

  // Validate env.json based on env.schema.json
  if (configValidationReport.errors.length > 0) {
    if (teardown) {
      console.error('env.json is invalid');
      console.error(configValidationReport.errors);
      process.exit(1);
    } else {
      throw new Error(configValidationReport.errors);
    }
github fhellwig / jsvutil / lib / jsv.js View on Github external
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

//-----------------------------------------------------------------------------
// This module provides an interface to the JSON Schema Validator (JSV).
//-----------------------------------------------------------------------------

var os = require('os');
var util = require('util');
var JSV = require('JSV').JSV;

var env = JSV.createEnvironment();

/**
 * Validates the specified instance against the specified schema.
 */
function validate(instance, schema) {
    var report = env.validate(instance, schema);
    if (report.errors.length > 0) {
        throw error('Schema validation failed.', report.errors);
    }
    return instance;
}

exports.validate = validate;
github cainus / percolator / lib / CRUDCollection.js View on Github external
var JSV = require('JSV').JSV;
var _ = require('underscore');

var CRUDCollection = function(options){

  if (!options || (!options.list && !options.collectionGET)){
    throw "the options parameter should have a list() or collectionGET() function.";
  }

  // TODO: list() array or object
  if (options.create && !options.createSchema && !!options.schema){
    options.createSchema = options.schema;
  }
  if (!options.updateSchema && !!options.schema){
    options.updateSchema = options.schema;
  }
  if (!options.update && !options.upsert){
github sockethub / sockethub / lib / protocols / dispatcher.js View on Github external
module.exports = (function() {
  var pub = {};
  var _ = {};
  var JSVlib = require('JSV').JSV; // json schema validator
  var jsv = JSVlib.createEnvironment();

  pub.init = function (protoName, connection) {
    _.protoName = protoName;
    _.connection = connection;
    var report;

    // when we get a new connection, and the protocol specified is matched to the
    // list in the config, then this dispatcher is called.
    //
    // first we do basic checking on the protocol.js file to ensure that it's
    // passes basic checks and has the right base-properties.
    try {
      proto = require("./" + protoName + "/protocol.js");
    } catch (e) {
      throw 'unable to load lib/protocols/' + protoName + "/protocol.js " + e;
github rf / nextbusjs / test / agencycache.js View on Github external
var vows       = require('vows'),
    assert     = require('assert'),
    nextbus    = require('../lib/index').client,
    jsv        = require('JSV').JSV.createEnvironment(),
    readfile   = require('fs').readFile,
    async      = require('async'),
    rutgers    = nextbus(),
    invalidnb  = nextbus(),
    dtconn     = nextbus();

var suite = vows.describe('just agency cache');

suite.addBatch({
   'rutgers' : {
      topic    : function () { rutgers.cacheAgency('rutgers', this.callback); },
      'doesnt break' : function (topic) {
         //console.dir(topic);
         assert.isObject(topic);
      }
   }
github cleancodegame / clean-code-game / gulpfile.js View on Github external
var map = require('map-stream');
var gulp = require('gulp');
var debug = require('gulp-debug');
var del = require('del');
var react = require('gulp-react');
var less = require('gulp-less');
var cson = require('gulp-cson');
var nodeunit = require('gulp-nodeunit');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var JSV = require("JSV").JSV;
var fs = require('fs');

var outputDir = 'cleancodegame.github.io/'

function handleError(err) {
  console.log(err.toString());
  console.log("\007");
  this.emit('end');
}

function toJsonp(funcName){
	
	function toJsonpOne(file, cb){
		var cont = funcName + "(" + file.contents.toString() + ");";
		file.contents = new Buffer(cont);
		cb(null, file);
github mananshah99 / graph-json / lib / graph.js View on Github external
/*global require, DirectedGraph, UndirectedGraph, nodes, edges, module*/

var util = require('util');
var fs = require('fs');
var JSV = require('JSV').JSV;
var validator = JSV.createEnvironment();
var scheme = require('./scheme.json');
var tsort = require('tsort');

function ValidationError(message, err) {
    'use strict';
    Error.call(this);
    this.err = err;
}
util.inherits(ValidationError, Error);

DirectedGraph.prototype.edgesIn = function (node) {
    'use strict';
    var t = (typeof node === 'string') ? this.getNode(node) : node;
    return (
        this.edges.filter(function (edge) {
github eirikurn / contracts / lib / schema.js View on Github external
/*!
 * Contracts - schema
 * Copyright(c) 2011 Eirikur Nilsson 
 * MIT Licensed
 */

var jsv = require('JSV').JSV;

var environment = jsv.createEnvironment("json-schema-draft-03");

/**
 * Patch JSV so it always clones instances before validation
 * so filters don't affect the original object.
 */
environment.createInstance = function(data, uri) {
  data = jsv.clone(data, true);
  return jsv.Environment.prototype.createInstance.call(this, data, uri);
};

var schemaSchema = environment.getDefaultSchema()
  , oldValidator = schemaSchema.getAttribute("validator");

schemaSchemaJson = jsv.inherits(schemaSchema, {
github cainus / percolator / lib / ContextHelpers / onJson.js View on Github external
This helper just adds an onJson function to the
 req and calls back when done.

 As a last or only parameter, the onJson function takes a 
 callback in the form:
 function(err, body){ ...
 where error is an error that may have occurred and body
 is the entire body of the request.

 An optional first parameter representing a json schema as
 an object is also allowed.  If specified it will be used 
 for validation.

 */
var _ = require('underscore');
var JSV = require('JSV').JSV;

var onJsonHelper = function(req, res, handler, cb){
  req.onJson = function(){

    var args = _.toArray(arguments);
    var schema, onBodyCB;
    switch(args.length){
      case 1:
        onBodyCB = args[0];
        break;

      case 2:
        schema = args[0];
        onBodyCB = args[1];
        break;