@contember/schema-utils
Advanced tools
Comparing version 0.6.3 to 0.6.6
import { Schema } from '@contember/schema'; | ||
import { ValidationError } from './errors'; | ||
export declare class SchemaValidator { | ||
validate(schema: Schema): [Schema, ValidationError[]]; | ||
static validate(schema: Schema): ValidationError[]; | ||
} | ||
//# sourceMappingURL=SchemaValidator.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const AclValidator_1 = require("./AclValidator"); | ||
const ModelValidator_1 = require("./ModelValidator"); | ||
const util_1 = require("util"); | ||
class SchemaValidator { | ||
validate(schema) { | ||
static validate(schema) { | ||
const aclValidator = new AclValidator_1.AclValidator(schema.model); | ||
const [acl, aclErrors] = aclValidator.validate(schema.acl); | ||
return [{ ...schema, acl }, [...aclErrors]]; | ||
const modelValidator = new ModelValidator_1.ModelValidator(schema.model); | ||
const [model, modelErrors] = modelValidator.validate(); | ||
const validSchema = { ...schema, acl, model }; | ||
const errors = [...aclErrors, ...modelErrors]; | ||
if (errors.length === 0 && !util_1.isDeepStrictEqual(validSchema, schema)) { | ||
throw new Error('There is something wrong with a schema validator'); | ||
} | ||
return errors; | ||
} | ||
@@ -10,0 +19,0 @@ } |
{ | ||
"name": "@contember/schema-utils", | ||
"version": "0.6.3", | ||
"version": "0.6.6", | ||
"license": "Apache-2.0", | ||
@@ -9,3 +9,3 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/schema": "^0.6.3" | ||
"@contember/schema": "^0.6.6" | ||
}, | ||
@@ -16,3 +16,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "ce4b6bfeea630fa2dd2d2d06f10cf813e7cd742c" | ||
"gitHead": "6cd07fb5b509c443a1478a60b3d088abd73c8f3c" | ||
} |
import { Schema } from '@contember/schema' | ||
import { ValidationError } from './errors' | ||
import { AclValidator } from './AclValidator' | ||
import { ModelValidator } from './ModelValidator' | ||
import { isDeepStrictEqual } from 'util' | ||
export class SchemaValidator { | ||
public validate(schema: Schema): [Schema, ValidationError[]] { | ||
public static validate(schema: Schema): ValidationError[] { | ||
const aclValidator = new AclValidator(schema.model) | ||
const [acl, aclErrors] = aclValidator.validate(schema.acl) | ||
return [{ ...schema, acl }, [...aclErrors]] | ||
const modelValidator = new ModelValidator(schema.model) | ||
const [model, modelErrors] = modelValidator.validate() | ||
const validSchema = { ...schema, acl, model } | ||
const errors = [...aclErrors, ...modelErrors] | ||
if (errors.length === 0 && !isDeepStrictEqual(validSchema, schema)) { | ||
throw new Error('There is something wrong with a schema validator') | ||
} | ||
return errors | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245824
82
2245
Updated@contember/schema@^0.6.6