UNPKG

1.48 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var common_1 = require("../common");
4var SchemaDefinition = (function () {
5 function SchemaDefinition(args) {
6 this.types = Array.isArray(args.type) ? args.type : [args.type];
7 this.def = args.def;
8 }
9 Object.defineProperty(SchemaDefinition.prototype, "isValidSchema", {
10 get: function () {
11 if (this._isValidSchema === undefined) {
12 var ajv = common_1.AJV();
13 this._isValidSchema = ajv.validateSchema(this.def);
14 }
15 return this._isValidSchema;
16 },
17 enumerable: true,
18 configurable: true
19 });
20 Object.defineProperty(SchemaDefinition.prototype, "schemaVersion", {
21 get: function () {
22 return this.def.$schema;
23 },
24 enumerable: true,
25 configurable: true
26 });
27 SchemaDefinition.prototype.validate = function (data) {
28 return this.validator(data);
29 };
30 Object.defineProperty(SchemaDefinition.prototype, "validator", {
31 get: function () {
32 if (!this._validator) {
33 var ajv = common_1.AJV();
34 this._validator = ajv.compile(this.def);
35 }
36 return this._validator;
37 },
38 enumerable: true,
39 configurable: true
40 });
41 return SchemaDefinition;
42}());
43exports.SchemaDefinition = SchemaDefinition;
44//# sourceMappingURL=SchemaDefinition.js.map
\No newline at end of file