blob: d63f5db32f3bbf3a0441dfe50b6f57a8a473e353 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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.toMschema());
if (!result.valid)
throw result.errors;
};
/**
* Return schema as an mschema object.
* Currently no difference between the two.
*/
OKSchema.prototype.toMschema = function() {
return this.spec;
};
module.exports = OKSchema;
|