raml-typesystem
Advanced tools
Comparing version 0.0.71 to 0.0.72
@@ -12,2 +12,3 @@ "use strict"; | ||
var restrictions_1 = require("./restrictions"); | ||
var restrictions_2 = require("./restrictions"); | ||
var _ = require("underscore"); | ||
@@ -171,20 +172,3 @@ var xmlio = require("./xmlio"); | ||
FacetDeclaration.prototype.validateSelf = function (registry) { | ||
var result = ts.ok(); | ||
var st1 = _super.prototype.validateSelf.call(this, registry); | ||
if (!st1) { | ||
result.addSubStatus(st1); | ||
} | ||
var st = this._type.validateType(registry); | ||
if (!st.isOk()) { | ||
var p = ts.error(messageRegistry.ERROR_IN_RANGE, this, { | ||
propName: this.name, | ||
msg: st.getMessage() | ||
}); | ||
st.getErrors().forEach(function (y) { | ||
p.addSubStatus(y); | ||
}); | ||
ts.setValidationPath(p, { name: this.name }); | ||
result.addSubStatus(st); | ||
} | ||
return result; | ||
return restrictions_2.validatePropertyType(this._type, this.name, registry, this, false); | ||
}; | ||
@@ -191,0 +175,0 @@ return FacetDeclaration; |
@@ -51,2 +51,5 @@ import ts = require("./typesystem"); | ||
private _c; | ||
private static CLASS_IDENTIFIER_AccumulatingRegistry; | ||
getClassIdentifier(): string[]; | ||
static isInstance(instance: any): instance is AccumulatingRegistry; | ||
constructor(toParse: ParseNode, schemas: ParseNode, ts: ts.TypeRegistry, _c: TypeCollection); | ||
@@ -53,0 +56,0 @@ parsing: { |
@@ -18,2 +18,3 @@ "use strict"; | ||
var restrictions_1 = require("./restrictions"); | ||
var _ = require("underscore"); | ||
var restrictions_2 = require("./restrictions"); | ||
@@ -196,2 +197,11 @@ (function (NodeKind) { | ||
} | ||
AccumulatingRegistry.prototype.getClassIdentifier = function () { | ||
var superIdentifiers = _super.prototype.getClassIdentifier.call(this); | ||
return superIdentifiers.concat(AccumulatingRegistry.CLASS_IDENTIFIER_AccumulatingRegistry); | ||
}; | ||
AccumulatingRegistry.isInstance = function (instance) { | ||
return instance != null && instance.getClassIdentifier | ||
&& typeof (instance.getClassIdentifier) == "function" | ||
&& _.contains(instance.getClassIdentifier(), AccumulatingRegistry.CLASS_IDENTIFIER_AccumulatingRegistry); | ||
}; | ||
AccumulatingRegistry.prototype.get = function (name) { | ||
@@ -241,2 +251,3 @@ var result = _super.prototype.get.call(this, name); | ||
}; | ||
AccumulatingRegistry.CLASS_IDENTIFIER_AccumulatingRegistry = "parse.AccumulatingRegistry"; | ||
return AccumulatingRegistry; | ||
@@ -688,3 +699,3 @@ }(ts.TypeRegistry)); | ||
var res = ts.derive(name, [sp]); | ||
if (r instanceof AccumulatingRegistry) { | ||
if (AccumulatingRegistry.isInstance(r)) { | ||
res = contributeToAccumulatingRegistry(res, r); | ||
@@ -700,3 +711,3 @@ } | ||
var res = ts.derive(name, supers); | ||
if (r instanceof AccumulatingRegistry) { | ||
if (AccumulatingRegistry.isInstance(r)) { | ||
res = contributeToAccumulatingRegistry(res, r); | ||
@@ -801,3 +812,3 @@ } | ||
} | ||
if (r instanceof AccumulatingRegistry) { | ||
if (AccumulatingRegistry.isInstance(r)) { | ||
result = contributeToAccumulatingRegistry(result, r); | ||
@@ -804,0 +815,0 @@ } |
@@ -321,1 +321,2 @@ /// <reference path="../../typings/main.d.ts" /> | ||
export declare function optimize(r: ts.Constraint[]): ts.Constraint[]; | ||
export declare function validatePropertyType(_type: ts.AbstractType, propName: string, registry: ts.TypeRegistry, source: any, isFacet?: boolean): ts.Status; |
@@ -70,41 +70,3 @@ "use strict"; | ||
MatchesProperty.prototype.validateSelf = function (registry) { | ||
if (this._type.isExternal()) { | ||
var p = ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, this); | ||
ts.setValidationPath(p, { name: this.propId() }); | ||
return p; | ||
} | ||
if (this._type.isSubTypeOf(ts.UNKNOWN) || this._type.isSubTypeOf(ts.RECURRENT)) { | ||
var actualUnknown = actualUnknownType(this._type); | ||
var p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, this, { | ||
propName: this.propId(), | ||
typeName: actualUnknown.name() | ||
}); | ||
ts.setValidationPath(p, { name: this.propId(), child: { name: "type" } }); | ||
return p; | ||
} | ||
if (this._type.isAnonymous()) { | ||
var st = this._type.validateType(registry); | ||
if (!st.isOk()) { | ||
var p = ts.error(messageRegistry.ERROR_IN_RANGE, this, { | ||
propName: this.propId(), | ||
msg: st.getMessage() | ||
}); | ||
st.getErrors().forEach(function (y) { p.addSubStatus(y); }); | ||
ts.setValidationPath(p, { name: this.propId() }); | ||
return p; | ||
} | ||
return st; | ||
} | ||
if (this._type.isUnion()) { | ||
var ui = _.find(this._type.typeFamily(), function (x) { return x.isSubTypeOf(ts.UNKNOWN); }); | ||
if (ui) { | ||
var p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, this, { | ||
propName: this.propId(), | ||
typeName: ui.name() | ||
}); | ||
ts.setValidationPath(p, { name: this.propId() }); | ||
return p; | ||
} | ||
} | ||
return ts.ok(); | ||
return validatePropertyType(this._type, this.propId(), registry, this, false); | ||
}; | ||
@@ -1304,3 +1266,3 @@ return MatchesProperty; | ||
if (this.owner().isSubTypeOf(ts.INTEGER)) { | ||
allowedValues = ["int32", "int64", "int", "int16", "int8"]; | ||
allowedValues = ["int32", "int64", "int", "long", "int16", "int8"]; | ||
} | ||
@@ -1476,2 +1438,78 @@ else if (this.owner().isSubTypeOf(ts.NUMBER)) { | ||
} | ||
function validatePropertyType(_type, propName, registry, source, isFacet) { | ||
if (isFacet === void 0) { isFacet = false; } | ||
if (_type.isExternal()) { | ||
var p = void 0; | ||
if (isFacet) { | ||
p = ts.error(messageRegistry.EXTERNAL_IN_FACET_DEFINITION, source); | ||
} | ||
else { | ||
p = ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, source); | ||
} | ||
ts.setValidationPath(p, { name: propName }); | ||
return p; | ||
} | ||
if (_type.isSubTypeOf(ts.UNKNOWN) || _type.isSubTypeOf(ts.RECURRENT)) { | ||
var actualUnknown = actualUnknownType(_type); | ||
var p = void 0; | ||
if (isFacet) { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_FACET_DEFINITION, source, { | ||
facetName: propName, | ||
msg: actualUnknown.name() | ||
}); | ||
} | ||
else { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, source, { | ||
propName: propName, | ||
typeName: actualUnknown.name() | ||
}); | ||
} | ||
ts.setValidationPath(p, { name: propName, child: { name: "type" } }); | ||
return p; | ||
} | ||
if (_type.isAnonymous()) { | ||
var st = _type.validateType(registry); | ||
if (!st.isOk()) { | ||
var p_1; | ||
if (isFacet) { | ||
p_1 = ts.error(messageRegistry.ERROR_IN_FACET_RANGE, source, { | ||
facetName: propName, | ||
msg: st.getMessage() | ||
}); | ||
} | ||
else { | ||
p_1 = ts.error(messageRegistry.ERROR_IN_RANGE, source, { | ||
propName: propName, | ||
msg: st.getMessage() | ||
}); | ||
} | ||
st.getErrors().forEach(function (y) { p_1.addSubStatus(y); }); | ||
ts.setValidationPath(p_1, { name: propName }); | ||
return p_1; | ||
} | ||
return st; | ||
} | ||
if (_type.isUnion()) { | ||
var ui = _.find(_type.typeFamily(), function (x) { return x.isSubTypeOf(ts.UNKNOWN); }); | ||
if (ui) { | ||
var p = void 0; | ||
if (isFacet) { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_FACET_DEFINITION, source, { | ||
facetName: propName, | ||
msg: ui.name() | ||
}); | ||
} | ||
else { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, source, { | ||
propName: propName, | ||
typeName: ui.name() | ||
}); | ||
} | ||
ts.setValidationPath(p, { name: propName }); | ||
return p; | ||
} | ||
} | ||
return ts.ok(); | ||
} | ||
exports.validatePropertyType = validatePropertyType; | ||
//# sourceMappingURL=restrictions.js.map |
@@ -122,2 +122,5 @@ /// <reference path="../../typings/main.d.ts" /> | ||
private typeList; | ||
private static CLASS_IDENTIFIER_TypeRegistry; | ||
getClassIdentifier(): string[]; | ||
static isInstance(instance: any): instance is TypeRegistry; | ||
put(alias: string, t: AbstractType): void; | ||
@@ -124,0 +127,0 @@ addType(t: AbstractType): void; |
{ | ||
"name": "raml-typesystem", | ||
"version": "0.0.71", | ||
"version": "0.0.72", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -250,2 +250,6 @@ { | ||
}, | ||
"EXTERNAL_IN_FACET_DEFINITION" : { | ||
"code" : "EXTERNAL_IN_FACET_DEFINITION", | ||
"message": "It is not allowed to use external types in facet definitions" | ||
}, | ||
"UNKNOWN_IN_PROPERTY_DEFINITION" : { | ||
@@ -255,2 +259,6 @@ "code" : "UNKNOWN_IN_PROPERTY_DEFINITION", | ||
}, | ||
"UNKNOWN_IN_FACET_DEFINITION" : { | ||
"code" : "UNKNOWN_IN_FACET_DEFINITION", | ||
"message": "Facet '{{facetName}}' refers to unknown type '{{typeName}}'" | ||
}, | ||
"ERROR_IN_RANGE" : { | ||
@@ -260,2 +268,6 @@ "code" : "ERROR_IN_RANGE", | ||
}, | ||
"ERROR_IN_FACET_RANGE" : { | ||
"code" : "ERROR_IN_FACET_RANGE", | ||
"message": "Facet '{{facetName}}' range type has error: {{msg}}" | ||
}, | ||
"INCORRECT_SCHEMA" : { | ||
@@ -262,0 +274,0 @@ "code" : "INCORRECT_SCHEMA", |
@@ -6,2 +6,3 @@ /// <reference path="../typings/main.d.ts" /> | ||
import {PropertyIs} from "./restrictions"; | ||
import {validatePropertyType} from "./restrictions"; | ||
import _=require("underscore") | ||
@@ -168,20 +169,3 @@ import xmlio=require("./xmlio") | ||
validateSelf(registry:ts.TypeRegistry):ts.Status { | ||
let result = ts.ok(); | ||
let st1 = super.validateSelf(registry); | ||
if (!st1) { | ||
result.addSubStatus(st1); | ||
} | ||
var st = this._type.validateType(registry); | ||
if (!st.isOk()) { | ||
var p = ts.error(messageRegistry.ERROR_IN_RANGE, this, { | ||
propName: this.name, | ||
msg: st.getMessage() | ||
}); | ||
st.getErrors().forEach(y => { | ||
p.addSubStatus(y) | ||
}); | ||
ts.setValidationPath(p, {name: this.name}); | ||
result.addSubStatus(st); | ||
} | ||
return result; | ||
return validatePropertyType(this._type,this.name,registry,this,false); | ||
} | ||
@@ -188,0 +172,0 @@ } |
@@ -17,2 +17,3 @@ import ts=require("./typesystem"); | ||
import {ComponentShouldBeOfType} from "./restrictions"; | ||
import _ = require("underscore"); | ||
@@ -209,3 +210,14 @@ import su = require('./schemaUtil'); | ||
private static CLASS_IDENTIFIER_AccumulatingRegistry = "parse.AccumulatingRegistry"; | ||
public getClassIdentifier() : string[] { | ||
var superIdentifiers:string[] = super.getClassIdentifier(); | ||
return superIdentifiers.concat(AccumulatingRegistry.CLASS_IDENTIFIER_AccumulatingRegistry); | ||
} | ||
public static isInstance(instance : any) : instance is AccumulatingRegistry { | ||
return instance != null && instance.getClassIdentifier | ||
&& typeof(instance.getClassIdentifier) == "function" | ||
&& _.contains(instance.getClassIdentifier(),AccumulatingRegistry.CLASS_IDENTIFIER_AccumulatingRegistry); | ||
} | ||
constructor(private toParse:ParseNode,private schemas:ParseNode,ts:ts.TypeRegistry,private _c:TypeCollection){ | ||
@@ -750,3 +762,3 @@ super(ts) | ||
var res=ts.derive(name,[sp]); | ||
if (r instanceof AccumulatingRegistry){ | ||
if (AccumulatingRegistry.isInstance(r)){ | ||
res = contributeToAccumulatingRegistry(res, r); | ||
@@ -762,3 +774,3 @@ } | ||
var res=ts.derive(name,supers); | ||
if (r instanceof AccumulatingRegistry){ | ||
if (AccumulatingRegistry.isInstance(r)){ | ||
res = contributeToAccumulatingRegistry(res, r); | ||
@@ -863,3 +875,3 @@ } | ||
} | ||
if (r instanceof AccumulatingRegistry){ | ||
if (AccumulatingRegistry.isInstance(r)){ | ||
result = contributeToAccumulatingRegistry(result, r); | ||
@@ -866,0 +878,0 @@ } |
@@ -75,43 +75,3 @@ /// <reference path="../typings/main.d.ts" /> | ||
validateSelf(registry:ts.TypeRegistry):ts.Status { | ||
if (this._type.isExternal()){ | ||
var p=ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, this); | ||
ts.setValidationPath(p,{name: this.propId()}) | ||
return p; | ||
} | ||
if (this._type.isSubTypeOf(ts.UNKNOWN)||this._type.isSubTypeOf(ts.RECURRENT)){ | ||
var actualUnknown = actualUnknownType(this._type); | ||
var p= ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,this,{ | ||
propName: this.propId(), | ||
typeName: actualUnknown.name() | ||
}); | ||
ts.setValidationPath(p,{name: this.propId(), child: { name: "type"}}) | ||
return p; | ||
} | ||
if (this._type.isAnonymous()){ | ||
var st=this._type.validateType(registry); | ||
if (!st.isOk()){ | ||
var p= ts.error(messageRegistry.ERROR_IN_RANGE,this, { | ||
propName: this.propId(), | ||
msg: st.getMessage() | ||
}); | ||
st.getErrors().forEach(y=>{p.addSubStatus(y)}); | ||
ts.setValidationPath(p,{name: this.propId()}); | ||
return p; | ||
} | ||
return st; | ||
} | ||
if (this._type.isUnion()){ | ||
var ui= _.find(this._type.typeFamily(),x=>x.isSubTypeOf(ts.UNKNOWN)); | ||
if (ui){ | ||
var p= ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,this,{ | ||
propName: this.propId(), | ||
typeName: ui.name() | ||
}); | ||
ts.setValidationPath(p,{name: this.propId()}) | ||
return p; | ||
} | ||
} | ||
return ts.ok(); | ||
return validatePropertyType(this._type,this.propId(),registry,this,false); | ||
} | ||
@@ -1343,3 +1303,3 @@ } | ||
if (this.owner().isSubTypeOf(ts.INTEGER)) { | ||
allowedValues = ["int32", "int64", "int", "int16", "int8"]; | ||
allowedValues = ["int32", "int64", "int", "long", "int16", "int8"]; | ||
} else if (this.owner().isSubTypeOf(ts.NUMBER)) { | ||
@@ -1510,2 +1470,84 @@ allowedValues = ["int32", "int64", "int", "long", "float", "double", "int16", "int8"]; | ||
return t; | ||
} | ||
export function validatePropertyType( | ||
_type:ts.AbstractType, | ||
propName:string, | ||
registry:ts.TypeRegistry, | ||
source:any, | ||
isFacet=false):ts.Status { | ||
if (_type.isExternal()){ | ||
let p:ts.Status; | ||
if(isFacet) { | ||
p = ts.error(messageRegistry.EXTERNAL_IN_FACET_DEFINITION, source); | ||
} | ||
else { | ||
p = ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, source); | ||
} | ||
ts.setValidationPath(p,{name: propName}) | ||
return p; | ||
} | ||
if (_type.isSubTypeOf(ts.UNKNOWN)||_type.isSubTypeOf(ts.RECURRENT)){ | ||
var actualUnknown = actualUnknownType(_type); | ||
let p:ts.Status; | ||
if(isFacet) { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_FACET_DEFINITION, source, { | ||
facetName: propName, | ||
msg: actualUnknown.name() | ||
}); | ||
} | ||
else{ | ||
p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,source,{ | ||
propName: propName, | ||
typeName: actualUnknown.name() | ||
}); | ||
} | ||
ts.setValidationPath(p,{name: propName, child: { name: "type"}}) | ||
return p; | ||
} | ||
if (_type.isAnonymous()){ | ||
var st=_type.validateType(registry); | ||
if (!st.isOk()){ | ||
let p:ts.Status; | ||
if(isFacet) { | ||
p = ts.error(messageRegistry.ERROR_IN_FACET_RANGE, source, { | ||
facetName: propName, | ||
msg: st.getMessage() | ||
}); | ||
} | ||
else{ | ||
p = ts.error(messageRegistry.ERROR_IN_RANGE,source, { | ||
propName: propName, | ||
msg: st.getMessage() | ||
}); | ||
} | ||
st.getErrors().forEach(y=>{p.addSubStatus(y)}); | ||
ts.setValidationPath(p,{name: propName}); | ||
return p; | ||
} | ||
return st; | ||
} | ||
if (_type.isUnion()){ | ||
var ui= _.find(_type.typeFamily(),x=>x.isSubTypeOf(ts.UNKNOWN)); | ||
if (ui){let p:ts.Status; | ||
if(isFacet) { | ||
p = ts.error(messageRegistry.UNKNOWN_IN_FACET_DEFINITION, source, { | ||
facetName: propName, | ||
msg: ui.name() | ||
}); | ||
} | ||
else{ | ||
p= ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,source,{ | ||
propName: propName, | ||
typeName: ui.name() | ||
}); | ||
} | ||
ts.setValidationPath(p,{name: propName}) | ||
return p; | ||
} | ||
} | ||
return ts.ok(); | ||
} |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
2318618
50645