raml-typesystem
Advanced tools
Comparing version 0.0.81 to 0.0.82
@@ -63,3 +63,3 @@ import ts = require("./typesystem"); | ||
}; | ||
get(name: string): ts.AbstractType; | ||
get(name: string, isPropertyType?: boolean): ts.AbstractType; | ||
} | ||
@@ -94,2 +94,2 @@ export declare function parseTypes(n: any, tr?: ts.TypeRegistry): TypeCollection; | ||
*/ | ||
export declare function parse(name: string, n: ParseNode, r?: ts.TypeRegistry, defaultsToAny?: boolean, annotation?: boolean, global?: boolean, ignoreTypeAttr?: boolean): ts.AbstractType; | ||
export declare function parse(name: string, n: ParseNode, r?: ts.TypeRegistry, defaultsToAny?: boolean, annotation?: boolean, global?: boolean, ignoreTypeAttr?: boolean, isPropertyType?: boolean): ts.AbstractType; |
@@ -223,4 +223,8 @@ "use strict"; | ||
}; | ||
AccumulatingRegistry.prototype.get = function (name) { | ||
AccumulatingRegistry.prototype.get = function (name, isPropertyType) { | ||
if (isPropertyType === void 0) { isPropertyType = false; } | ||
var result = _super.prototype.get.call(this, name); | ||
if (isPropertyType && result && result.isSubTypeOf(ts.REFERENCE)) { | ||
return result; | ||
} | ||
if (!result || result.isSubTypeOf(ts.REFERENCE)) { | ||
@@ -423,3 +427,3 @@ var chld = this.toParse ? this.toParse.childWithKey(name) : null; | ||
} | ||
result.type = parse(null, n, tr, false, false, false); | ||
result.type = parse(null, n, tr, false, false, false, false, true); | ||
var chainingData = n.getMeta("chaining"); | ||
@@ -754,3 +758,3 @@ if (chainingData && chainingData.length > 0) { | ||
*/ | ||
function parse(name, n, r, defaultsToAny, annotation, global, ignoreTypeAttr) { | ||
function parse(name, n, r, defaultsToAny, annotation, global, ignoreTypeAttr, isPropertyType) { | ||
if (r === void 0) { r = ts.builtInRegistry(); } | ||
@@ -761,2 +765,3 @@ if (defaultsToAny === void 0) { defaultsToAny = false; } | ||
if (ignoreTypeAttr === void 0) { ignoreTypeAttr = false; } | ||
if (isPropertyType === void 0) { isPropertyType = false; } | ||
//mentioning fragment' uses | ||
@@ -783,3 +788,3 @@ var uses = n.childWithKey("uses"); | ||
else { | ||
sp = typeExpressions.parseToType("" + valString, r, n); | ||
sp = typeExpressions.parseToType("" + valString, r, n, null, isPropertyType); | ||
} | ||
@@ -828,3 +833,3 @@ if (name == null) { | ||
n.children().forEach(function (x) { | ||
supers.push(typeExpressions.parseToType("" + x.value(), r, n)); | ||
supers.push(typeExpressions.parseToType("" + x.value(), r, n, null, isPropertyType)); | ||
}); | ||
@@ -888,3 +893,3 @@ var res = ts.derive(name, supers); | ||
var typeAttributeContentProvider = tp.contentProvider ? tp.contentProvider() : null; | ||
var st = typeExpressions.parseToType("" + valString, r, n, typeAttributeContentProvider); | ||
var st = typeExpressions.parseToType("" + valString, r, n, typeAttributeContentProvider, isPropertyType); | ||
superTypes = [st]; | ||
@@ -910,3 +915,3 @@ } | ||
return x.value(); | ||
}).map(function (y) { return typeExpressions.parseToType("" + y, r, n); }); | ||
}).map(function (y) { return typeExpressions.parseToType("" + y, r, n, null, isPropertyType); }); | ||
} | ||
@@ -1012,7 +1017,9 @@ else if (tp.kind() == NodeKind.MAP) { | ||
if (key === "facets") { | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = key; | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = [key]; | ||
return; | ||
} | ||
else if (key == "default" || key == "xml" || key == "required") { | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = key; | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals ? | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals.concat(key) : [key]; | ||
} | ||
@@ -1111,3 +1118,5 @@ else if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') { | ||
actualResult.putExtra(ts.SOURCE_EXTRA, n); | ||
actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals); | ||
if (hasfacetsOrOtherStuffDoesNotAllowedInExternals) { | ||
actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals); | ||
} | ||
checkIfSkipValidation(actualResult, n); | ||
@@ -1114,0 +1123,0 @@ if (n.getMeta("acceptAllScalarsAsStrings")) { |
@@ -1563,3 +1563,3 @@ "use strict"; | ||
} | ||
if (ts.isUnknown(_type) || _type.isSubTypeOf(ts.RECURRENT)) { | ||
if (ts.isUnknown(_type)) { | ||
var actualUnknown = actualUnknownType(_type); | ||
@@ -1628,2 +1628,8 @@ var p = void 0; | ||
} | ||
else if (_type.isSubTypeOf(ts.RECURRENT)) { | ||
st = ts.error(messageRegistry.CYCLIC_DEPENDENCY, source, { | ||
typeName: _type.name() | ||
}); | ||
return st; | ||
} | ||
if (_type.isAnonymous()) { | ||
@@ -1630,0 +1636,0 @@ var st = _type.validateType(registry); |
@@ -9,3 +9,3 @@ import ts = require("./typesystem"); | ||
export declare type Parens = typeExpressionDefs.Parens; | ||
export declare function parseToType(val: string, t: ts.TypeRegistry, contentProvidingNode?: ParseNode, typeAttributeContentProvider?: schemaUtil.IContentProvider): ts.AbstractType; | ||
export declare function parseToType(val: string, t: ts.TypeRegistry, contentProvidingNode?: ParseNode, typeAttributeContentProvider?: schemaUtil.IContentProvider, isPropertyType?: boolean): ts.AbstractType; | ||
export declare function storeToString(t: ts.AbstractType): string; | ||
@@ -12,0 +12,0 @@ export declare function visit(node: BaseNode, action: (n: BaseNode) => void): void; |
@@ -5,6 +5,8 @@ "use strict"; | ||
var ts = require("./typesystem"); | ||
var _parse = require("./parse"); | ||
var restrictions_1 = require("./restrictions"); | ||
var metainfo_1 = require("./metainfo"); | ||
function parseToType(val, t, contentProvidingNode, typeAttributeContentProvider) { | ||
function parseToType(val, t, contentProvidingNode, typeAttributeContentProvider, isPropertyType) { | ||
if (typeAttributeContentProvider === void 0) { typeAttributeContentProvider = null; } | ||
if (isPropertyType === void 0) { isPropertyType = false; } | ||
if (val == null) { | ||
@@ -28,3 +30,3 @@ return null; | ||
var node = parse(val); | ||
var result = parseNode(node, t); | ||
var result = parseNode(node, t, isPropertyType); | ||
return result; | ||
@@ -50,10 +52,10 @@ } | ||
} | ||
function parseNode(node, t) { | ||
function parseNode(node, t, isPropertyType) { | ||
if (node.type == "union") { | ||
var ut = node; | ||
return ts.union("", [parseNode(ut.first, t), parseNode(ut.rest, t)]); | ||
return ts.union("", [parseNode(ut.first, t, isPropertyType), parseNode(ut.rest, t, isPropertyType)]); | ||
} | ||
else if (node.type == "parens") { | ||
var ps = node; | ||
var rs = parseNode(ps.expr, t); | ||
var rs = parseNode(ps.expr, t, isPropertyType); | ||
return wrapArray(ps.arr, rs); | ||
@@ -64,3 +66,3 @@ } | ||
if (lit.value.charAt(lit.value.length - 1) == '?') { | ||
var result = t.get(lit.value.substr(0, lit.value.length - 1)); | ||
var result = getFromRegistry(t, lit.value.substr(0, lit.value.length - 1), isPropertyType); | ||
if (!result) { | ||
@@ -73,3 +75,3 @@ result = ts.derive(lit.value, [ts.UNKNOWN]); | ||
} | ||
var result = t.get(lit.value); | ||
var result = getFromRegistry(t, lit.value, isPropertyType); | ||
if (!result) { | ||
@@ -86,2 +88,8 @@ result = ts.derive(lit.value, [ts.UNKNOWN]); | ||
} | ||
function getFromRegistry(t, name, isPropertyType) { | ||
if (_parse.AccumulatingRegistry.isInstance(t)) { | ||
return t.get(name, isPropertyType); | ||
} | ||
return t.get(name); | ||
} | ||
function storeToString(t) { | ||
@@ -88,0 +96,0 @@ if (t.isSubTypeOf(ts.ARRAY)) { |
{ | ||
"name": "raml-typesystem", | ||
"version": "0.0.81", | ||
"version": "0.0.82", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -247,4 +247,7 @@ import ts=require("./typesystem"); | ||
get(name: string ):ts.AbstractType{ | ||
get(name: string, isPropertyType=false ):ts.AbstractType{ | ||
var result=super.get(name); | ||
if(isPropertyType&&result&&result.isSubTypeOf(ts.REFERENCE)){ | ||
return result; | ||
} | ||
@@ -461,3 +464,3 @@ if (!result||result.isSubTypeOf(ts.REFERENCE)){ | ||
} | ||
result.type=parse(null, n,tr,false,false,false); | ||
result.type=parse(null, n,tr,false,false,false, false, true); | ||
let chainingData = <meta.ChainingData[]>n.getMeta("chaining"); | ||
@@ -823,3 +826,4 @@ if(chainingData && chainingData.length>0){ | ||
global:boolean=true, | ||
ignoreTypeAttr:boolean=false):ts.AbstractType{ | ||
ignoreTypeAttr:boolean=false, | ||
isPropertyType=false):ts.AbstractType{ | ||
@@ -848,3 +852,3 @@ //mentioning fragment' uses | ||
else{ | ||
sp = typeExpressions.parseToType(""+valString,r, n) | ||
sp = typeExpressions.parseToType(""+valString,r, n,null,isPropertyType) | ||
} | ||
@@ -892,3 +896,3 @@ if (name==null){ | ||
n.children().forEach(x=>{ | ||
supers.push(typeExpressions.parseToType(""+x.value(),r, n)) | ||
supers.push(typeExpressions.parseToType(""+x.value(),r, n, null, isPropertyType)) | ||
}); | ||
@@ -954,3 +958,3 @@ var res=ts.derive(name,supers); | ||
(<any>tp).contentProvider ? (<any>tp).contentProvider() : null; | ||
const st = typeExpressions.parseToType(""+valString,r, n, typeAttributeContentProvider); | ||
const st = typeExpressions.parseToType(""+valString,r, n, typeAttributeContentProvider, isPropertyType); | ||
superTypes=[st]; | ||
@@ -976,3 +980,3 @@ } | ||
return x.value(); | ||
}).map(y=>typeExpressions.parseToType(""+y,r, n)); | ||
}).map(y=>typeExpressions.parseToType(""+y,r, n,null, isPropertyType)); | ||
} | ||
@@ -1008,3 +1012,3 @@ else if (tp.kind()==NodeKind.MAP){ | ||
var actualResult=result; | ||
var hasfacetsOrOtherStuffDoesNotAllowedInExternals:string=null; | ||
var hasfacetsOrOtherStuffDoesNotAllowedInExternals:string[]=null; | ||
@@ -1081,7 +1085,9 @@ n.children().forEach(childNode=>{ | ||
if (key === "facets") { | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = key; | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = [key]; | ||
return; | ||
} | ||
else if (key == "default" || key == "xml" || key == "required") { | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = key; | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals = | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals ? | ||
hasfacetsOrOtherStuffDoesNotAllowedInExternals.concat(key):[key]; | ||
} | ||
@@ -1183,3 +1189,5 @@ else if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') { | ||
actualResult.putExtra(ts.SOURCE_EXTRA, n); | ||
actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals); | ||
if(hasfacetsOrOtherStuffDoesNotAllowedInExternals) { | ||
actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals); | ||
} | ||
@@ -1186,0 +1194,0 @@ checkIfSkipValidation(actualResult, n); |
@@ -1600,3 +1600,3 @@ import ts=require("./typesystem"); | ||
} | ||
if (ts.isUnknown(_type)||_type.isSubTypeOf(ts.RECURRENT)){ | ||
if (ts.isUnknown(_type)){ | ||
var actualUnknown = actualUnknownType(_type); | ||
@@ -1665,2 +1665,8 @@ let p:ts.Status; | ||
} | ||
else if(_type.isSubTypeOf(ts.RECURRENT)){ | ||
st = ts.error(messageRegistry.CYCLIC_DEPENDENCY, source, { | ||
typeName: _type.name() | ||
}); | ||
return st; | ||
} | ||
if (_type.isAnonymous()){ | ||
@@ -1667,0 +1673,0 @@ var st=_type.validateType(registry); |
import typeExpression=require("./typeExpressionParser") | ||
import ts=require("./typesystem") | ||
import _parse=require("./parse"); | ||
import schemaUtil = require('./schemaUtil') | ||
@@ -16,3 +17,3 @@ import {ComponentShouldBeOfType} from "./restrictions"; | ||
export function parseToType(val:string,t:ts.TypeRegistry, contentProvidingNode?:ParseNode, | ||
typeAttributeContentProvider: schemaUtil.IContentProvider = null):ts.AbstractType{ | ||
typeAttributeContentProvider: schemaUtil.IContentProvider = null, isPropertyType=false):ts.AbstractType{ | ||
if(val==null){ | ||
@@ -44,3 +45,3 @@ return null; | ||
var node:BaseNode = parse(val); | ||
var result= parseNode(node, t); | ||
var result= parseNode(node, t, isPropertyType); | ||
return result; | ||
@@ -66,11 +67,11 @@ } else { | ||
} | ||
function parseNode(node:BaseNode,t:ts.TypeRegistry):ts.AbstractType | ||
function parseNode(node:BaseNode,t:ts.TypeRegistry, isPropertyType:boolean):ts.AbstractType | ||
{ | ||
if (node.type=="union"){ | ||
var ut=<Union>node; | ||
return ts.union("",[parseNode(ut.first,t),parseNode(ut.rest,t)]); | ||
return ts.union("",[parseNode(ut.first,t,isPropertyType),parseNode(ut.rest,t,isPropertyType)]); | ||
} | ||
else if (node.type=="parens"){ | ||
var ps=<Parens>node; | ||
var rs=parseNode(ps.expr,t); | ||
var rs=parseNode(ps.expr,t,isPropertyType); | ||
return wrapArray(ps.arr,rs); | ||
@@ -81,3 +82,3 @@ } | ||
if (lit.value.charAt(lit.value.length-1)=='?'){ | ||
var result=t.get(lit.value.substr(0,lit.value.length-1)); | ||
var result=getFromRegistry(t,lit.value.substr(0,lit.value.length-1),isPropertyType); | ||
if (!result){ | ||
@@ -90,3 +91,3 @@ result=ts.derive(lit.value,[ts.UNKNOWN]); | ||
} | ||
var result=t.get(lit.value); | ||
var result=getFromRegistry(t,lit.value,isPropertyType); | ||
if (!result){ | ||
@@ -104,2 +105,8 @@ result=ts.derive(lit.value,[ts.UNKNOWN]); | ||
function getFromRegistry(t:ts.TypeRegistry,name:string,isPropertyType:boolean):ts.AbstractType{ | ||
if(_parse.AccumulatingRegistry.isInstance(t)){ | ||
return t.get(name,isPropertyType); | ||
} | ||
return t.get(name); | ||
} | ||
@@ -106,0 +113,0 @@ export function storeToString(t:ts.AbstractType):string{ |
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
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
2062321
41313