var mschema = require('mschema'); /** * OKSchema! * Meant as a thin wrapper around some existing schema validation * module, mostly to allow for the extension of types. */ function OKSchema(spec) { if (!(this instanceof OKSchema)) return new OKSchema(spec); if (!spec) throw new Error('No spec provided to OKSchema'); Object.defineProperty(this, 'spec', { value: spec, writable: false }); } OKSchema.prototype.assertValid = function(data) { var result = mschema.validate(data, this._spec); if (!result.valid) throw result.errors; }; OKSchema.prototype.getMschema = function() { return this._spec; }; module.exports = OKSchema;