Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raml-typesystem

Package Overview
Dependencies
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raml-typesystem - npm Package Compare versions

Comparing version 0.0.80 to 0.0.81

21

dist/src/exampleBuilder.js

@@ -98,2 +98,5 @@ "use strict";

}
if (typeof this._strict != "boolean") {
this._strict = false;
}
}

@@ -406,8 +409,7 @@ Example.prototype.rawValue = function () { return this._value; };

if (exampleObj != null) {
var val = exampleObj.value;
if (!val) {
val = exampleObj;
example = new Example(val, name, undefined, undefined, true, undefined, isSingle);
if (!exampleObj.hasOwnProperty("value")) {
example = new Example(exampleObj, name, undefined, undefined, true, undefined, isSingle);
}
else {
var val = exampleObj.value;
var displayName = scalarValue(exampleObj, "displayName");

@@ -501,3 +503,12 @@ var description = scalarValue(exampleObj, "description");

var te = new TSExample(e.rawValue(), e.name(), e.displayName(), e.description(), e.strict(), e.annotations(), e.isSingle(), e.isEmpty());
te._scalarsAnnotations = e.scalarsAnnotations();
if (e.scalarsAnnotations()) {
for (var _a = 0, _b = Object.keys(e.scalarsAnnotations()); _a < _b.length; _a++) {
var pName = _b[_a];
var pAnnotations = e.scalarsAnnotations()[pName];
for (var _c = 0, _d = Object.keys(pAnnotations); _c < _d.length; _c++) {
var aName = _d[_c];
te.registerScalarAnnotatoion(pAnnotations[aName], pName);
}
}
}
result.push(te);

@@ -504,0 +515,0 @@ }

@@ -9,3 +9,2 @@ "use strict";

var metainfo_2 = require("./metainfo");
var metainfo_3 = require("./metainfo");
var restrictions_2 = require("./restrictions");

@@ -83,3 +82,3 @@ var FacetPrototype = /** @class */ (function () {

new FacetPrototype(function () { return new metainfo_1.Example(""); }, function (x) { return new metainfo_1.Example(x); }),
new FacetPrototype(function () { return new metainfo_3.Required(true); }, function (x) { return new metainfo_3.Required(x); }),
new FacetPrototype(function () { return new metainfo_2.Required(true); }, function (x) { return new metainfo_2.Required(x); }),
new FacetPrototype(function () { return new ms.Examples({}); }, function (x) { return new ms.Examples(x); }),

@@ -91,2 +90,5 @@ new FacetPrototype(function () { return new metainfo_1.Description(""); }, function (x) { return new metainfo_1.Description(x); }),

new FacetPrototype(function () { return new metainfo_2.XMLInfo({}); }, function (x) { return new metainfo_2.XMLInfo(x); }),
new FacetPrototype(function () { return new metainfo_2.AllowedTargets({}); }, function (x) { return new metainfo_2.AllowedTargets(x); }),
new FacetPrototype(function () { return new metainfo_1.SourceMap({}); }, function (x) { return new metainfo_1.SourceMap(x); }),
new FacetPrototype(function () { return new metainfo_1.ParserMetadata({}); }, function (x) { return new metainfo_1.ParserMetadata(x); })
];

@@ -93,0 +95,0 @@ this.known = {};

@@ -6,3 +6,6 @@ export import tsInterfaces = require("./typesystem-interfaces");

export declare type IValidationPath = tsInterfaces.IValidationPath;
export declare type IExample = tsInterfaces.IExample;
export declare type IAnnotation = tsInterfaces.IAnnotation;
export declare type IHasExtra = tsInterfaces.IHasExtra;
export declare type ElementSourceInfo = tsInterfaces.IHasExtra;
export declare var TOP_LEVEL_EXTRA: string;

@@ -9,0 +12,0 @@ export declare var DEFINED_IN_TYPES_EXTRA: string;

@@ -18,6 +18,13 @@ import ts = require("./typesystem");

constructor(value: string);
private static CLASS_IDENTIFIER_Description;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is Description;
kind(): tsInterfaces.MetaInformationKind;
protected validateSelfIndividual(parentStatus: Status, registry: ts.TypeRegistry): Status;
}
export declare class NotScalar extends MetaInfo {
constructor();
private static CLASS_IDENTIFIER_NotScalar;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is NotScalar;
kind(): tsInterfaces.MetaInformationKind;

@@ -28,2 +35,5 @@ }

constructor(_typeName: string);
private static CLASS_IDENTIFIER_ImportedByChain;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is ImportedByChain;
kind(): tsInterfaces.MetaInformationKind;

@@ -41,3 +51,7 @@ }

constructor(value: string);
private static CLASS_IDENTIFIER_DisplayName;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is DisplayName;
kind(): tsInterfaces.MetaInformationKind;
protected validateSelfIndividual(parentStatus: Status, registry: ts.TypeRegistry): Status;
}

@@ -51,5 +65,7 @@ export declare class Usage extends MetaInfo {

protected ofExample: boolean;
constructor(name: string, value: any, path: string, ofExample?: boolean);
private _index;
constructor(name: string, value: any, path: string, ofExample?: boolean, _index?: number);
private _ownerFacet;
name(): string;
definition(): tsInterfaces.IParsedType;
validateSelfIndividual(parentStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;

@@ -59,2 +75,3 @@ kind(): tsInterfaces.MetaInformationKind;

setOwnerFacet(ownerFacet: tsInterfaces.ITypeFacet): void;
getPath(): string;
}

@@ -97,2 +114,5 @@ export declare class FacetDeclaration extends MetaInfo {

constructor();
private static CLASS_IDENTIFIER_HasPropertiesFacet;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is HasPropertiesFacet;
kind(): tsInterfaces.MetaInformationKind;

@@ -109,3 +129,2 @@ }

validateSelfIndividual(parentStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;
private checkScalarProperty(exampleObj, exampleName, y, registry, status);
kind(): tsInterfaces.MetaInformationKind;

@@ -122,2 +141,24 @@ }

}
export declare class SchemaPath extends MetaInfo {
constructor(path: string);
kind(): tsInterfaces.MetaInformationKind;
}
export declare class SourceMap extends MetaInfo {
constructor(value: Object);
private static CLASS_IDENTIFIER_SourceMap;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is SourceMap;
kind(): tsInterfaces.MetaInformationKind;
}
export declare class TypeAttributeValue extends MetaInfo {
constructor(value: any);
private static CLASS_IDENTIFIER_TypeAttributeValue;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is TypeAttributeValue;
kind(): tsInterfaces.MetaInformationKind;
}
export declare class ParserMetadata extends MetaInfo {
constructor(value: Object);
kind(): tsInterfaces.MetaInformationKind;
}
export declare class Discriminator extends ts.TypeInformation {

@@ -124,0 +165,0 @@ property: string;

@@ -61,5 +61,30 @@ "use strict";

}
Description.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(Description.CLASS_IDENTIFIER_Description);
};
Description.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), Description.CLASS_IDENTIFIER_Description);
};
Description.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.Description;
};
Description.prototype.validateSelfIndividual = function (parentStatus, registry) {
var vl = this.value();
var allowedTypes = {
"string": true,
"number": true,
"boolean": true
};
var result = ts.ok();
if (vl !== null && !allowedTypes[typeof vl]) {
result = ts.error(messageRegistry.INVALID_PROPERTY_RANGE, this, { propName: this.facetName(), range: "string" });
ts.setValidationPath(result, { name: this.facetName() });
}
parentStatus.addSubStatus(result);
return parentStatus;
};
Description.CLASS_IDENTIFIER_Description = "metainfo.Description";
return Description;

@@ -73,5 +98,15 @@ }(MetaInfo));

}
NotScalar.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(NotScalar.CLASS_IDENTIFIER_NotScalar);
};
NotScalar.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), NotScalar.CLASS_IDENTIFIER_NotScalar);
};
NotScalar.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.NotScalar;
};
NotScalar.CLASS_IDENTIFIER_NotScalar = "metainfo.NotScalar";
return NotScalar;

@@ -87,5 +122,15 @@ }(MetaInfo));

}
ImportedByChain.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(ImportedByChain.CLASS_IDENTIFIER_ImportedByChain);
};
ImportedByChain.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), ImportedByChain.CLASS_IDENTIFIER_ImportedByChain);
};
ImportedByChain.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.ImportedByChain;
};
ImportedByChain.CLASS_IDENTIFIER_ImportedByChain = "metainfo.ImportedByChain";
return ImportedByChain;

@@ -121,5 +166,30 @@ }(MetaInfo));

}
DisplayName.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(DisplayName.CLASS_IDENTIFIER_DisplayName);
};
DisplayName.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), DisplayName.CLASS_IDENTIFIER_DisplayName);
};
DisplayName.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.DisplayName;
};
DisplayName.prototype.validateSelfIndividual = function (parentStatus, registry) {
var vl = this.value();
var allowedTypes = {
"string": true,
"number": true,
"boolean": true
};
var result = ts.ok();
if (vl !== null && !allowedTypes[typeof vl]) {
result = ts.error(messageRegistry.INVALID_PROPERTY_RANGE, this, { propName: this.facetName(), range: "string" });
ts.setValidationPath(result, { name: this.facetName() });
}
parentStatus.addSubStatus(result);
return parentStatus;
};
DisplayName.CLASS_IDENTIFIER_DisplayName = "metainfo.DisplayName";
return DisplayName;

@@ -141,7 +211,9 @@ }(MetaInfo));

__extends(Annotation, _super);
function Annotation(name, value, path, ofExample) {
function Annotation(name, value, path, ofExample, _index) {
if (ofExample === void 0) { ofExample = false; }
if (_index === void 0) { _index = -1; }
var _this = _super.call(this, name, value) || this;
_this.path = path;
_this.ofExample = ofExample;
_this._index = _index;
return _this;

@@ -152,2 +224,13 @@ }

};
Annotation.prototype.definition = function () {
var owner = this.owner();
if (owner) {
var reg = owner.collection();
if (reg) {
var tp = reg.getAnnotationType(this.facetName());
return tp;
}
}
return null;
};
Annotation.prototype.validateSelfIndividual = function (parentStatus, registry) {

@@ -220,2 +303,5 @@ var tp = registry.get(this.facetName());

};
Annotation.prototype.getPath = function () {
return this.path;
};
return Annotation;

@@ -321,7 +407,2 @@ }(MetaInfo));

}
var exampleScalarProperties = [
{ propName: "strict", propType: "boolean", messageEntry: messageRegistry.STRICT_BOOLEAN },
{ propName: "displayName", propType: "string", messageEntry: messageRegistry.DISPLAY_NAME_STRING },
{ propName: "description", propType: "string", messageEntry: messageRegistry.DESCRIPTION_STRING }
];
var Example = /** @class */ (function (_super) {

@@ -349,30 +430,4 @@ __extends(Example, _super);

if (val.hasOwnProperty("value")) {
for (var _i = 0, exampleScalarProperties_1 = exampleScalarProperties; _i < exampleScalarProperties_1.length; _i++) {
var y = exampleScalarProperties_1[_i];
var propName = y.propName;
var propType = y.propType;
var propObj = val[propName];
if (propObj && typeof propObj != propType) {
if (typeof (propObj) == "object") {
Object.keys(propObj).forEach(function (key) {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes, {
name: "example",
child: { name: propName, child: { name: key } }
});
result.addSubStatus(aRes);
}
});
}
if (!propObj.value && typeof propObj.value != propType) {
var s = ts.error(y.messageEntry, this);
var vp = propObj.value ? { name: "value" } : null;
ts.setValidationPath(s, { name: "example", child: { name: propName, child: vp } });
result.addSubStatus(s);
}
}
}
if (val.strict === false || (typeof (val.strict) == "object" && val.strict.value === false)) {
checkExampleScalarProperties(val, null, registry, result, this.facetName());
if (val.strict === false || (val.strict && typeof (val.strict) == "object" && val.strict.value === false)) {
return result;

@@ -476,5 +531,15 @@ }

}
HasPropertiesFacet.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(HasPropertiesFacet.CLASS_IDENTIFIER_HasPropertiesFacet);
};
HasPropertiesFacet.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), HasPropertiesFacet.CLASS_IDENTIFIER_HasPropertiesFacet);
};
HasPropertiesFacet.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.HasPropertiesFacet;
};
HasPropertiesFacet.CLASS_IDENTIFIER_HasPropertiesFacet = "metainfo.HasPropertiesFacet";
return HasPropertiesFacet;

@@ -554,7 +619,5 @@ }(MetaInfo));

val = exampleObj.value;
for (var _i = 0, exampleScalarProperties_2 = exampleScalarProperties; _i < exampleScalarProperties_2.length; _i++) {
var y = exampleScalarProperties_2[_i];
_this.checkScalarProperty(exampleObj, x, y, registry, rs);
}
if (exampleObj.strict === false || (typeof (exampleObj.strict) == "object" && exampleObj.strict.value === false)) {
checkExampleScalarProperties(exampleObj, x, registry, rs, _this.facetName());
if (exampleObj.strict === false || (exampleObj.strict &&
typeof (exampleObj.strict) == "object" && exampleObj.strict.value === false)) {
return;

@@ -586,32 +649,2 @@ }

};
Examples.prototype.checkScalarProperty = function (exampleObj, exampleName, y, registry, status) {
var propName = y.propName;
var propType = y.propType;
var propObj = exampleObj[propName];
if (propObj && typeof propObj != propType) {
var vp = null;
if (typeof (propObj) == "object") {
vp = { name: "value" };
Object.keys(propObj).forEach(function (key) {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes, {
name: "examples",
child: { name: exampleName, child: { name: propName, child: { name: key } } }
});
status.addSubStatus(aRes);
}
});
}
if (!propObj.value && typeof (propObj.value) != propType) {
var s = ts.error(y.messageEntry, this);
ts.setValidationPath(s, {
name: "examples",
child: { name: exampleName, child: { name: propName, child: vp } }
});
status.addSubStatus(s);
}
}
};
Examples.prototype.kind = function () {

@@ -666,2 +699,66 @@ return tsInterfaces.MetaInformationKind.Examples;

exports.Default = Default;
var SchemaPath = /** @class */ (function (_super) {
__extends(SchemaPath, _super);
function SchemaPath(path) {
return _super.call(this, "schemaPath", path, true) || this;
}
SchemaPath.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.SchemaPath;
};
return SchemaPath;
}(MetaInfo));
exports.SchemaPath = SchemaPath;
var SourceMap = /** @class */ (function (_super) {
__extends(SourceMap, _super);
function SourceMap(value) {
return _super.call(this, "sourceMap", value) || this;
}
SourceMap.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(SourceMap.CLASS_IDENTIFIER_SourceMap);
};
SourceMap.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), SourceMap.CLASS_IDENTIFIER_SourceMap);
};
SourceMap.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.SourceMap;
};
SourceMap.CLASS_IDENTIFIER_SourceMap = "metainfo.SourceMap";
return SourceMap;
}(MetaInfo));
exports.SourceMap = SourceMap;
var TypeAttributeValue = /** @class */ (function (_super) {
__extends(TypeAttributeValue, _super);
function TypeAttributeValue(value) {
return _super.call(this, "typeAttributeValue", value) || this;
}
TypeAttributeValue.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(TypeAttributeValue.CLASS_IDENTIFIER_TypeAttributeValue);
};
TypeAttributeValue.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), TypeAttributeValue.CLASS_IDENTIFIER_TypeAttributeValue);
};
TypeAttributeValue.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.TypeAttributeValue;
};
TypeAttributeValue.CLASS_IDENTIFIER_TypeAttributeValue = "metainfo.TypeAttributeValue";
return TypeAttributeValue;
}(MetaInfo));
exports.TypeAttributeValue = TypeAttributeValue;
var ParserMetadata = /** @class */ (function (_super) {
__extends(ParserMetadata, _super);
function ParserMetadata(value) {
return _super.call(this, "__METADATA__", value) || this;
}
ParserMetadata.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.ParserMetadata;
};
return ParserMetadata;
}(MetaInfo));
exports.ParserMetadata = ParserMetadata;
var Discriminator = /** @class */ (function (_super) {

@@ -719,2 +816,8 @@ __extends(Discriminator, _super);

_this.strict = strict;
if (_this._value && typeof _this._value === "object") {
if (typeof _this._value.strict === "boolean") {
_this.strict = _this._value.strict;
}
_this._value = _this._value.value;
}
return _this;

@@ -826,2 +929,65 @@ }

exports.DiscriminatorValue = DiscriminatorValue;
function checkExampleScalarProperties(exampleObj, exampleName, registry, status, facetName) {
for (var _i = 0, exampleScalarProperties_1 = exampleScalarProperties; _i < exampleScalarProperties_1.length; _i++) {
var y = exampleScalarProperties_1[_i];
checkScalarProperty(exampleObj, exampleName, y, registry, status, facetName);
}
}
function checkScalarProperty(exampleObj, exampleName, y, registry, status, facetName) {
var propName = y.propName;
var propType = y.propType;
if (!exampleObj
|| (typeof exampleObj != "object")
|| !exampleObj.hasOwnProperty(propName)) {
return;
}
var propObj = exampleObj[propName];
if (propObj == null) {
var s = ts.error(y.messageEntry, this);
var vp = toExampleScalarPropertyPath(exampleName, facetName, { name: propName });
ts.setValidationPath(s, vp);
status.addSubStatus(s);
}
else if (typeof propObj != propType) {
var vp = null;
if (typeof (propObj) == "object") {
vp = toExampleScalarPropertyPath(exampleName, facetName, { name: "value" });
Object.keys(propObj).forEach(function (key) {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key], key, true);
var aRes = a.validateSelf(registry);
var vp_1 = toExampleScalarPropertyPath(exampleName, facetName, { name: propName, child: { name: key } });
ts.setValidationPath(aRes, vp_1);
status.addSubStatus(aRes);
}
});
}
if (!propObj.value && typeof (propObj.value) != propType) {
var s = ts.error(y.messageEntry, this);
ts.setValidationPath(s, {
name: "examples",
child: { name: exampleName, child: { name: propName, child: vp } }
});
status.addSubStatus(s);
}
}
}
function toExampleScalarPropertyPath(exampleName, facetName, vp) {
var p = vp;
if (exampleName) {
p = {
name: exampleName,
child: vp
};
}
return {
name: facetName,
child: p
};
}
var exampleScalarProperties = [
{ propName: "strict", propType: "boolean", messageEntry: messageRegistry.STRICT_BOOLEAN },
{ propName: "displayName", propType: "string", messageEntry: messageRegistry.DISPLAY_NAME_STRING },
{ propName: "description", propType: "string", messageEntry: messageRegistry.DESCRIPTION_STRING }
];
//# sourceMappingURL=metainfo.js.map

@@ -29,2 +29,7 @@ import ts = require("./typesystem");

type: ts.AbstractType;
annotations: {
name: string;
key: string;
value: any;
}[];
add(t: ts.AbstractType): void;

@@ -31,0 +36,0 @@ }

@@ -119,3 +119,3 @@ "use strict";

else if (this.regExp) {
matchesPropertyFacet = new rs.MapPropertyIs(this.id, this.type);
matchesPropertyFacet = new rs.MapPropertyIs(this.id, this.type, this.optional);
}

@@ -131,2 +131,10 @@ else {

}
if (this.annotations && this.annotations.length) {
for (var _i = 0, _a = this.annotations; _i < _a.length; _i++) {
var a = _a[_i];
var a1 = new meta.Annotation(a.name, a.value, a.key);
a1.setOwnerFacet(matchesPropertyFacet);
matchesPropertyFacet.addAnnotation(a1);
}
}
}

@@ -152,2 +160,3 @@ };

TypeCollection.prototype.add = function (t) {
this._types = this._types.filter(function (x) { return x.name() != t.name(); });
this._types.push(t);

@@ -379,5 +388,22 @@ this._typeMap[t.name()] = t;

var rsValue = requiredNode.value();
if (typeof rsValue == "boolean") {
if (typeof rsValue === "boolean") {
hasRequiredFacet = true;
}
else if (rsValue && typeof (rsValue) === "object" && typeof rsValue.value === "boolean") {
hasRequiredFacet = true;
var annotations = Object.keys(rsValue).filter(function (x) {
x = x.trim();
return x.length > 1 && x.charAt(0) == "(" && x.charAt(x.length - 1) == ")";
});
if (annotations.length) {
result.annotations = annotations.map(function (x) {
x = x.trim();
return {
name: x.substring(1, x.length - 1).trim(),
key: x,
value: rsValue[x]
};
});
}
}
if (rsValue === false) {

@@ -393,3 +419,3 @@ result.optional = true;

}
if (name.length == 0 || name === '/.*/') {
if (name != null && name.length == 0 || name === '/.*/') {
result.additonal = true;

@@ -498,3 +524,3 @@ }

if (x.regExp) {
nm = "/" + nm + "/";
nm = "/" + x.id + "/";
}

@@ -574,8 +600,10 @@ var vl = null;

pbean.optional = false;
pbean.id = "/.*/";
pbean.id = ".*";
pbean.additonal = true;
pbean.type = x.value();
pbean.optional = x.isOptional();
pbean.regExp = true;
pmap['/.*/'] = pbean;
}
else if (x instanceof rs.MapPropertyIs) {
else if (rs.MapPropertyIs.isInstance(x)) {
var pbean = new PropertyBean();

@@ -586,5 +614,6 @@ pbean.optional = false;

pbean.type = x.value();
pbean.optional = x.isOptional();
pmap[x.regexpValue()] = pbean;
}
else if (x instanceof rs.PropertyIs) {
else if (rs.PropertyIs.isInstance(x)) {
if (pmap.hasOwnProperty(x.propertyName())) {

@@ -601,6 +630,6 @@ pmap[x.propertyName()].type = x.value();

}
else if (x instanceof rs.KnownPropertyRestriction) {
else if (rs.KnownPropertyRestriction.isInstance(x)) {
result.additionalProperties = x.value();
}
else if (x instanceof meta.DiscriminatorValue) {
else if (meta.DiscriminatorValue.isInstance(x)) {
if (x.isStrict()) {

@@ -610,3 +639,3 @@ result.basicFacets.push(x);

}
else if (!(x instanceof meta.HasPropertiesFacet)) {
else if (!meta.HasPropertiesFacet.isInstance(x)) {
result.basicFacets.push(x);

@@ -705,12 +734,15 @@ }

function appendAnnotations(appendedInfo, childNode) {
var children = childNode.children();
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
var ch = children_1[_i];
var key = ch.key();
if (key && key.charAt(0) == "(" && key.charAt(key.length - 1) == ")") {
var aName = key.substring(1, key.length - 1);
var aInstance = new meta.Annotation(aName, ch.value(), key);
aInstance.setNode(ch);
aInstance.setOwnerFacet(appendedInfo);
appendedInfo.addAnnotation(aInstance);
var arr = childNode.kind() == NodeKind.ARRAY ? childNode.children() : [childNode];
for (var i = 0; i < arr.length; i++) {
var children = arr[i].children();
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
var ch = children_1[_i];
var key = ch.key();
if (key && key.charAt(0) == "(" && key.charAt(key.length - 1) == ")") {
var aName = key.substring(1, key.length - 1);
var aInstance = new meta.Annotation(aName, ch.value(), key, false, i);
aInstance.setOwnerFacet(appendedInfo);
aInstance._owner = appendedInfo._owner;
appendedInfo.addAnnotation(aInstance);
}
}

@@ -823,3 +855,3 @@ }

var typePropAnnotations = [];
if (!tp || ignoreTypeAttr) {
if (!tp || (!tp.children().length && !tp.value()) || ignoreTypeAttr) {
if (defaultsToAny) {

@@ -862,3 +894,4 @@ if (n.childWithKey("properties")) {

var typeAttributeContentProvider = tp.contentProvider ? tp.contentProvider() : null;
superTypes = [typeExpressions.parseToType("" + valString, r, n, typeAttributeContentProvider)];
var st = typeExpressions.parseToType("" + valString, r, n, typeAttributeContentProvider);
superTypes = [st];
}

@@ -905,2 +938,5 @@ }

var result = ts.derive(name, superTypes);
if (ignoreTypeAttr && tp) {
result.addMeta(new meta.TypeAttributeValue(tp.value()));
}
for (var i = 0; i < typePropAnnotations.length; i++) {

@@ -919,3 +955,3 @@ var aArr1 = typePropAnnotations[i];

var x = childNode;
if (key != "example" && actual) {
if (key != "example" && key != "discriminatorValue" && actual) {
x = actual;

@@ -945,41 +981,29 @@ }

var componentTypes = [];
if (x.kind() == NodeKind.SCALAR) {
var valString = x.value();
if (valString == null || valString == "Null" || valString == "NULL") {
componentTypes = [ts.STRING];
var arr = [x];
if (x.kind() == NodeKind.ARRAY) {
arr = x.children();
var err_1 = ts.error(messageRegistry.ITEMS_SHOULD_BE_REFERENCE_OR_INLINE_TYPE, actualResult);
err_1.setValidationPath({ name: "items" });
result.putExtra(tsInterfaces.PARSE_ERROR, err_1);
}
var componentTypes = arr.map(function (y) {
var actual = y.childWithKey("value");
if (actual && (actual.kind() == NodeKind.SCALAR || actual.kind() == NodeKind.MAP)) {
y = actual;
}
else {
componentTypes = [typeExpressions.parseToType("" + valString, r, n)];
checkIfSkipValidation(componentTypes[0], x);
}
}
else if (x.kind() == NodeKind.ARRAY) {
componentTypes = x.children().map(function (y) {
var actual = y.childWithKey("value");
if (actual && (actual.kind() == NodeKind.SCALAR || actual.kind() == NodeKind.ARRAY)) {
sAnnotations.push(y.children().filter(function (x) {
var key = x.key();
if (!key) {
return false;
}
return key.charAt(0) == "(" && key.charAt(key.length - 1) == ")";
}));
y = actual;
if (y.kind() == NodeKind.SCALAR) {
var valString = y.value();
if (valString == null || valString == "Null" || valString == "NULL") {
return ts.STRING;
}
else {
sAnnotations.push([]);
var res_1 = typeExpressions.parseToType("" + valString, r, n);
checkIfSkipValidation(res_1, x);
return res_1;
}
return y;
}).map(function (y) {
var result = typeExpressions.parseToType("" + y.value(), r, n);
checkIfSkipValidation(result, y);
return result;
});
var err = ts.error(messageRegistry.ITEMS_SHOULD_BE_REFERENCE_OR_INLINE_TYPE, actualResult);
err.setValidationPath({ name: "items" });
result.putExtra(tsInterfaces.PARSE_ERROR, err);
}
else if (x.kind() == NodeKind.MAP) {
componentTypes = [parse("", x, r, false, false, false)];
}
}
else if (y.kind() == NodeKind.MAP) {
return parse("", y, r, false, false, false);
}
});
var tp = componentTypes.length == 1 ? componentTypes[0] :

@@ -990,5 +1014,3 @@ ts.derive("", componentTypes);

actualResult.putExtra(tsInterfaces.HAS_ITEMS, true);
if (actual) {
appendAnnotations(appendedInfo, childNode);
}
appendAnnotations(appendedInfo, childNode);
return appendedInfo;

@@ -1018,6 +1040,6 @@ }

else {
if (annotation && key === "allowedTargets") {
result.addMeta(new meta.AllowedTargets(x.value()));
}
else {
// if (annotation && key === "allowedTargets") {
// result.addMeta(new meta.AllowedTargets(x.value()));
// }
{
var customFacet = new meta.CustomFacet(key, x.value());

@@ -1085,5 +1107,5 @@ customFacet.setNode(x);

if (result.superTypes().length == 1) {
var res_1 = result.superTypes()[0];
checkIfSkipValidation(res_1, n);
return res_1;
var res_2 = result.superTypes()[0];
checkIfSkipValidation(res_2, n);
return res_2;
}

@@ -1090,0 +1112,0 @@ }

@@ -12,8 +12,9 @@ import ts = require("./typesystem");

private _type;
protected optional: boolean;
matches(s: string): boolean;
constructor(_type: ts.AbstractType);
abstract path(): string;
constructor(_type: ts.AbstractType, optional?: boolean);
private static CLASS_IDENTIFIER_MatchesProperty;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is MatchesProperty;
abstract path(): string;
check(i: any, p: ts.IValidationPath): ts.Status;

@@ -25,2 +26,3 @@ patchPath(p: ts.IValidationPath, name: string): IValidationPath;

range(): ts.AbstractType;
isOptional(): boolean;
}

@@ -41,2 +43,5 @@ export declare class MatchToSchema extends ts.Constraint {

private _value;
private static CLASS_IDENTIFIER_KnownPropertyRestriction;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is KnownPropertyRestriction;
facetName(): string;

@@ -56,2 +61,5 @@ requiredType(): ts.InheritedType;

constructor(name: string);
private static CLASS_IDENTIFIER_HasProperty;
getClassIdentifier(): string[];
static isInstance(instance: any): instance is HasProperty;
check(i: any): ts.Status;

@@ -69,3 +77,2 @@ requiredType(): ts.InheritedType;

private type;
private optional;
constructor(name: string, type: ts.AbstractType, optional?: boolean);

@@ -84,3 +91,2 @@ private static CLASS_IDENTIFIER_PropertyIs;

composeWith(t: ts.Constraint): ts.Constraint;
isOptional(): boolean;
}

@@ -96,3 +102,3 @@ export declare function anotherRestrictionComponent(): any;

private type;
constructor(regexp: string, type: ts.AbstractType);
constructor(regexp: string, type: ts.AbstractType, optional?: boolean);
private static CLASS_IDENTIFIER_MapPropertyIs;

@@ -118,3 +124,3 @@ getClassIdentifier(): string[];

private type;
constructor(type: ts.AbstractType);
constructor(type: ts.AbstractType, optional?: boolean);
private static CLASS_IDENTIFIER_AdditionalPropertyIs;

@@ -121,0 +127,0 @@ getClassIdentifier(): string[];

@@ -28,5 +28,7 @@ "use strict";

__extends(MatchesProperty, _super);
function MatchesProperty(_type) {
function MatchesProperty(_type, optional) {
if (optional === void 0) { optional = false; }
var _this = _super.call(this) || this;
_this._type = _type;
_this.optional = optional;
return _this;

@@ -95,2 +97,5 @@ }

};
MatchesProperty.prototype.isOptional = function () {
return this.optional;
};
MatchesProperty.CLASS_IDENTIFIER_MatchesProperty = "restrictions.MatchesProperty";

@@ -203,2 +208,11 @@ return MatchesProperty;

}
KnownPropertyRestriction.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(KnownPropertyRestriction.CLASS_IDENTIFIER_KnownPropertyRestriction);
};
KnownPropertyRestriction.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), KnownPropertyRestriction.CLASS_IDENTIFIER_KnownPropertyRestriction);
};
KnownPropertyRestriction.prototype.facetName = function () {

@@ -263,2 +277,3 @@ return "closed";

};
KnownPropertyRestriction.CLASS_IDENTIFIER_KnownPropertyRestriction = "typesystem.KnownPropertyRestriction";
return KnownPropertyRestriction;

@@ -277,2 +292,11 @@ }(ts.Constraint));

}
HasProperty.prototype.getClassIdentifier = function () {
var superIdentifiers = _super.prototype.getClassIdentifier.call(this);
return superIdentifiers.concat(HasProperty.CLASS_IDENTIFIER_HasProperty);
};
HasProperty.isInstance = function (instance) {
return instance != null && instance.getClassIdentifier
&& typeof (instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), HasProperty.CLASS_IDENTIFIER_HasProperty);
};
HasProperty.prototype.check = function (i) {

@@ -305,2 +329,3 @@ if (i && typeof i == 'object' && !Array.isArray(i)) {

};
HasProperty.CLASS_IDENTIFIER_HasProperty = "restrictions.HasProperty";
return HasProperty;

@@ -316,6 +341,5 @@ }(ts.Constraint));

if (optional === void 0) { optional = false; }
var _this = _super.call(this, type) || this;
var _this = _super.call(this, type, optional) || this;
_this.name = name;
_this.type = type;
_this.optional = optional;
return _this;

@@ -392,5 +416,2 @@ }

};
PropertyIs.prototype.isOptional = function () {
return this.optional;
};
PropertyIs.CLASS_IDENTIFIER_PropertyIs = "restrictions.PropertyIs";

@@ -434,4 +455,5 @@ return PropertyIs;

__extends(MapPropertyIs, _super);
function MapPropertyIs(regexp, type) {
var _this = _super.call(this, type) || this;
function MapPropertyIs(regexp, type, optional) {
if (optional === void 0) { optional = false; }
var _this = _super.call(this, type, optional) || this;
_this.regexp = regexp;

@@ -552,4 +574,5 @@ _this.type = type;

__extends(AdditionalPropertyIs, _super);
function AdditionalPropertyIs(type) {
var _this = _super.call(this, type) || this;
function AdditionalPropertyIs(type, optional) {
if (optional === void 0) { optional = false; }
var _this = _super.call(this, type, optional) || this;
_this.type = type;

@@ -568,3 +591,3 @@ return _this;

AdditionalPropertyIs.prototype.path = function () {
return this.facetName();
return "/.*/";
};

@@ -1116,3 +1139,4 @@ AdditionalPropertyIs.prototype.matches = function (s) {

ComponentShouldBeOfType.prototype.toString = function () {
return ts.error(messageRegistry.ITEMS_SHOULD_BE_OF_TYPE, this, { type: this.type }).getMessage();
var typeName = this.type && this.type.name();
return ts.error(messageRegistry.ITEMS_SHOULD_BE_OF_TYPE, this, { type: typeName }).getMessage();
};

@@ -1161,3 +1185,5 @@ ComponentShouldBeOfType.prototype.check = function (i) {

else if (this.type.isExternal()) {
st.addSubStatus(ts.error(messageRegistry.EXTERNAL_AS_COMPONENT, this));
var itemsErr = ts.error(messageRegistry.EXTERNAL_AS_COMPONENT, this);
itemsErr.setValidationPath({ name: "items" });
st.addSubStatus(itemsErr);
}

@@ -1407,3 +1433,8 @@ else if (ts.isUnknown(this.type) || this.type.isSubTypeOf(ts.RECURRENT)) {

if (!opts.some(function (x) { return x == i; })) {
var valStr = Array.isArray(this._value) ? this._value.map(function (x) { return "'" + x + "'"; }).join(", ") : "'" + this._value + "'";
var valStr = Array.isArray(this._value) ? this._value.map(function (x) {
if (x && typeof x === "object") {
return JSON.stringify(x, null, 2);
}
return "'" + x + "'";
}).join(", ") : "'" + this._value + "'";
return ts.error(messageRegistry.ENUM_RESTRICTION, this, { values: valStr });

@@ -1410,0 +1441,0 @@ }

@@ -9,2 +9,5 @@ "use strict";

if (typeAttributeContentProvider === void 0) { typeAttributeContentProvider = null; }
if (val == null) {
return null;
}
try {

@@ -11,0 +14,0 @@ var q = val.trim();

@@ -72,21 +72,25 @@ export interface IValidationPath {

NotScalar = 1,
ImportedByChain = 2,
AcceptAllScalarsAsStrings = 3,
SkipValidation = 4,
DisplayName = 5,
Usage = 6,
Annotation = 7,
FacetDeclaration = 8,
CustomFacet = 9,
Example = 10,
Required = 11,
HasPropertiesFacet = 12,
AllowedTargets = 13,
Examples = 14,
XMLInfo = 15,
Default = 16,
Constraint = 17,
Modifier = 18,
Discriminator = 19,
DiscriminatorValue = 20,
DisplayName = 2,
Usage = 3,
Annotation = 4,
FacetDeclaration = 5,
CustomFacet = 6,
Example = 7,
Required = 8,
HasPropertiesFacet = 9,
AllowedTargets = 10,
Examples = 11,
XMLInfo = 12,
Default = 13,
Constraint = 14,
Modifier = 15,
Discriminator = 16,
DiscriminatorValue = 17,
SchemaPath = 18,
SourceMap = 19,
ParserMetadata = 20,
ImportedByChain = 21,
AcceptAllScalarsAsStrings = 22,
SkipValidation = 23,
TypeAttributeValue = 24,
}

@@ -147,2 +151,14 @@ /**

owner(): IParsedType;
/**
* Annotation name
*/
name(): string;
/**
* Annotation value
*/
value(): any;
/**
* Annotation definition type
*/
definition(): IParsedType;
}

@@ -205,3 +221,8 @@ export interface IParsedTypeCollection {

isAdditional(): boolean;
annotations(): IAnnotation[];
}
export interface IAnnotated {
annotations(): IAnnotation[];
annotation(name: string): any;
}
/**

@@ -211,3 +232,3 @@ * parsed representation of the type

*/
export interface IParsedType extends IHasExtra {
export interface IParsedType extends IAnnotated, IHasExtra {
/**

@@ -239,2 +260,8 @@ * returns list of directly declared sub types of this type

declaredAnnotations(): IAnnotation[];
scalarsAnnotations(): {
[key: string]: IAnnotation[][];
};
declaredScalarsAnnotations(): {
[key: string]: IAnnotation[][];
};
registry(): IParsedTypeCollection;

@@ -465,2 +492,4 @@ isAssignableFrom(t: IParsedType): boolean;

name(): string;
displayName(): string;
description(): string;
strict(): boolean;

@@ -495,1 +524,23 @@ value(): any;

}
export interface SourceInfo {
/**
* Path to file which contains definition
*/
path?: string;
/**
* Namespace of defining library if any
*/
namespace?: string;
}
export interface ElementSourceInfo extends SourceInfo {
/**
* Source information for fields which are defined in another file rather then their owning component.
* If all scalar fields of the component are defined in the same file, the 'scalarsSources' field is undefined.
*/
scalarsSources: {
[key: string]: SourceInfo[];
};
}
export interface HasSource {
sourceMap(): ElementSourceInfo;
}

@@ -17,21 +17,25 @@ "use strict";

MetaInformationKind[MetaInformationKind["NotScalar"] = 1] = "NotScalar";
MetaInformationKind[MetaInformationKind["ImportedByChain"] = 2] = "ImportedByChain";
MetaInformationKind[MetaInformationKind["AcceptAllScalarsAsStrings"] = 3] = "AcceptAllScalarsAsStrings";
MetaInformationKind[MetaInformationKind["SkipValidation"] = 4] = "SkipValidation";
MetaInformationKind[MetaInformationKind["DisplayName"] = 5] = "DisplayName";
MetaInformationKind[MetaInformationKind["Usage"] = 6] = "Usage";
MetaInformationKind[MetaInformationKind["Annotation"] = 7] = "Annotation";
MetaInformationKind[MetaInformationKind["FacetDeclaration"] = 8] = "FacetDeclaration";
MetaInformationKind[MetaInformationKind["CustomFacet"] = 9] = "CustomFacet";
MetaInformationKind[MetaInformationKind["Example"] = 10] = "Example";
MetaInformationKind[MetaInformationKind["Required"] = 11] = "Required";
MetaInformationKind[MetaInformationKind["HasPropertiesFacet"] = 12] = "HasPropertiesFacet";
MetaInformationKind[MetaInformationKind["AllowedTargets"] = 13] = "AllowedTargets";
MetaInformationKind[MetaInformationKind["Examples"] = 14] = "Examples";
MetaInformationKind[MetaInformationKind["XMLInfo"] = 15] = "XMLInfo";
MetaInformationKind[MetaInformationKind["Default"] = 16] = "Default";
MetaInformationKind[MetaInformationKind["Constraint"] = 17] = "Constraint";
MetaInformationKind[MetaInformationKind["Modifier"] = 18] = "Modifier";
MetaInformationKind[MetaInformationKind["Discriminator"] = 19] = "Discriminator";
MetaInformationKind[MetaInformationKind["DiscriminatorValue"] = 20] = "DiscriminatorValue";
MetaInformationKind[MetaInformationKind["DisplayName"] = 2] = "DisplayName";
MetaInformationKind[MetaInformationKind["Usage"] = 3] = "Usage";
MetaInformationKind[MetaInformationKind["Annotation"] = 4] = "Annotation";
MetaInformationKind[MetaInformationKind["FacetDeclaration"] = 5] = "FacetDeclaration";
MetaInformationKind[MetaInformationKind["CustomFacet"] = 6] = "CustomFacet";
MetaInformationKind[MetaInformationKind["Example"] = 7] = "Example";
MetaInformationKind[MetaInformationKind["Required"] = 8] = "Required";
MetaInformationKind[MetaInformationKind["HasPropertiesFacet"] = 9] = "HasPropertiesFacet";
MetaInformationKind[MetaInformationKind["AllowedTargets"] = 10] = "AllowedTargets";
MetaInformationKind[MetaInformationKind["Examples"] = 11] = "Examples";
MetaInformationKind[MetaInformationKind["XMLInfo"] = 12] = "XMLInfo";
MetaInformationKind[MetaInformationKind["Default"] = 13] = "Default";
MetaInformationKind[MetaInformationKind["Constraint"] = 14] = "Constraint";
MetaInformationKind[MetaInformationKind["Modifier"] = 15] = "Modifier";
MetaInformationKind[MetaInformationKind["Discriminator"] = 16] = "Discriminator";
MetaInformationKind[MetaInformationKind["DiscriminatorValue"] = 17] = "DiscriminatorValue";
MetaInformationKind[MetaInformationKind["SchemaPath"] = 18] = "SchemaPath";
MetaInformationKind[MetaInformationKind["SourceMap"] = 19] = "SourceMap";
MetaInformationKind[MetaInformationKind["ParserMetadata"] = 20] = "ParserMetadata";
MetaInformationKind[MetaInformationKind["ImportedByChain"] = 21] = "ImportedByChain";
MetaInformationKind[MetaInformationKind["AcceptAllScalarsAsStrings"] = 22] = "AcceptAllScalarsAsStrings";
MetaInformationKind[MetaInformationKind["SkipValidation"] = 23] = "SkipValidation";
MetaInformationKind[MetaInformationKind["TypeAttributeValue"] = 24] = "TypeAttributeValue";
})(MetaInformationKind = exports.MetaInformationKind || (exports.MetaInformationKind = {}));

@@ -38,0 +42,0 @@ /**

@@ -164,3 +164,5 @@ import su = require("./schemaUtil");

private isProp;
private isAdditionalProp;
private isFacet;
private _required;
protected _matches: restr.MatchesProperty;

@@ -175,6 +177,9 @@ protected _facetDecl: metaInfo.FacetDeclaration;

required(): boolean;
setRequired(val: boolean): void;
private property();
private mapProperty();
private additionalProperty();
annotations(): tsInterfaces.IAnnotation[];
}
export declare abstract class AbstractType implements tsInterfaces.IParsedType, tsInterfaces.IHasExtra {
export declare abstract class AbstractType implements tsInterfaces.IParsedType, tsInterfaces.IHasExtra, tsInterfaces.HasSource {
protected _name: string;

@@ -203,2 +208,3 @@ protected computeConfluent: boolean;

examples(): tsInterfaces.IExample[];
collection(): tsInterfaces.IParsedTypeCollection;
getExtra(name: string): any;

@@ -366,2 +372,9 @@ putExtra(name: string, v: any): void;

declaredAnnotations(): metaInfo.Annotation[];
scalarsAnnotations(): {
[key: string]: metaInfo.Annotation[][];
};
declaredScalarsAnnotations(): {
[key: string]: metaInfo.Annotation[][];
};
private sAnnotations(facets);
componentType(): tsInterfaces.IParsedType;

@@ -421,2 +434,3 @@ canDoAc(): Status;

hasPropertiesFacet(): boolean;
sourceMap(): tsInterfaces.ElementSourceInfo;
}

@@ -423,0 +437,0 @@ export declare abstract class Modifier extends TypeInformation {

@@ -506,9 +506,9 @@ "use strict";

it("All facets", function () {
assert.equal(facetRegistry.getInstance().allPrototypes().length, 31);
assert.equal(facetRegistry.getInstance().allPrototypes().length, 34);
});
it("All object facets", function () {
assert.equal(facetRegistry.getInstance().applyableTo(ts.OBJECT).length, 19);
assert.equal(facetRegistry.getInstance().applyableTo(ts.OBJECT).length, 22);
});
it("All meta", function () {
assert.equal(facetRegistry.getInstance().allMeta().length, 10);
assert.equal(facetRegistry.getInstance().allMeta().length, 13);
});

@@ -515,0 +515,0 @@ });

{
"name": "raml-typesystem",
"version": "0.0.80",
"version": "0.0.81",
"main": "dist/src/index.js",

@@ -27,3 +27,3 @@ "scripts": {

"raml-xml-validation": "0.0.14",
"raml-json-validation": "0.0.15"
"raml-json-validation": "0.0.16"
},

@@ -30,0 +30,0 @@ "browser": {

@@ -140,3 +140,3 @@ {

"code" : "SCALAR_EXPECTED",
"message": "scalar is expected"
"message": "Scalar is expected here"
},

@@ -203,10 +203,6 @@ "INCORRECT_DISCRIMINATOR" : {

},
"DISPLAY_NAME_STRING" : {
"code" : "DISPLAY_NAME_STRING",
"message": "'displayName' should be string"
"INVALID_PROPERTY_RANGE": {
"code" : "INVALID_PROPERTY_RANGE",
"message" : "Property '{{propName}}' must be a {{range}}"
},
"DESCRIPTION_STRING" : {
"code" : "DESCRIPTION_STRING",
"message": "'description' should be string"
},
"INVALID_EXMAPLE" : {

@@ -382,3 +378,3 @@ "code" : "INVALID_EXMAPLE",

"code" : "EXTERNAL_AS_COMPONENT",
"message": "It is not allowed to use external types in component type definitions"
"message": "It is not allowed to use external types as array component types in types and type properties declarations"
},

@@ -531,3 +527,3 @@ "PATTERN_VIOLATION" : {

"code" : "ITEMS_SHOULD_BE_OF_TYPE",
"message" : "items should be of type {{type}}"
"message" : "items should be of type '{{type}}'"
},

@@ -534,0 +530,0 @@ "RESTRICTIONS_CANNT_BE_COMPOSED" : {

@@ -92,2 +92,5 @@ import rt=require("./typesystem")

}
if(typeof this._strict != "boolean"){
this._strict = false;
}
}

@@ -475,8 +478,7 @@

if (exampleObj!=null) {
let val = exampleObj.value;
if (!val) {
val = exampleObj
example = new Example(val, name, undefined, undefined, true, undefined, isSingle);
if (!exampleObj.hasOwnProperty("value")) {
example = new Example(exampleObj, name, undefined, undefined, true, undefined, isSingle);
}
else {
let val = exampleObj.value;
let displayName = scalarValue(exampleObj, "displayName");

@@ -584,3 +586,10 @@ let description = scalarValue(exampleObj, "description");

e.isEmpty());
(<any>te)._scalarsAnnotations = e.scalarsAnnotations();
if(e.scalarsAnnotations()){
for(let pName of Object.keys(e.scalarsAnnotations())){
const pAnnotations = e.scalarsAnnotations()[pName];
for(let aName of Object.keys(pAnnotations)){
te.registerScalarAnnotatoion(pAnnotations[aName],pName);
}
}
}
result.push(te);

@@ -587,0 +596,0 @@ }

@@ -13,7 +13,5 @@ import ts=require("./typesystem")

import {Default, Example, Description, DisplayName} from "./metainfo";
import {Default, Example, Description, DisplayName, SourceMap, ParserMetadata} from "./metainfo";
import {AbstractType} from "./typesystem";
import {XMLInfo} from "./metainfo";
import {Required} from "./metainfo";
import {Usage} from "./metainfo";
import {XMLInfo,Required,AllowedTargets,HasPropertiesFacet} from "./metainfo";
import {MultipleOf} from "./restrictions";

@@ -102,2 +100,5 @@

new FacetPrototype(()=>new XMLInfo({}), (x)=>new XMLInfo(x)),
new FacetPrototype(()=>new AllowedTargets({}), (x)=>new AllowedTargets(x)),
new FacetPrototype(()=>new SourceMap({}), (x)=>new SourceMap(x)),
new FacetPrototype(()=>new ParserMetadata({}), (x)=>new ParserMetadata(x))
];

@@ -104,0 +105,0 @@

@@ -17,3 +17,6 @@ import ts=require("./typesystem")

export type IValidationPath = tsInterfaces.IValidationPath;
export type IExample = tsInterfaces.IExample;
export type IAnnotation = tsInterfaces.IAnnotation;
export type IHasExtra = tsInterfaces.IHasExtra;
export type ElementSourceInfo = tsInterfaces.IHasExtra;
export var TOP_LEVEL_EXTRA = tsInterfaces.TOP_LEVEL_EXTRA;

@@ -20,0 +23,0 @@ export var DEFINED_IN_TYPES_EXTRA = tsInterfaces.DEFINED_IN_TYPES_EXTRA;

@@ -49,8 +49,37 @@ import ts=require("./typesystem");

constructor(value:string){
super("description",value)
super("description",value);
}
private static CLASS_IDENTIFIER_Description = "metainfo.Description";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(Description.CLASS_IDENTIFIER_Description);
}
public static isInstance(instance: any): instance is Description {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), Description.CLASS_IDENTIFIER_Description);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.Description;
}
protected validateSelfIndividual(parentStatus:Status,registry:ts.TypeRegistry):Status{
let vl = this.value();
const allowedTypes:{[key:string]:boolean} = {
"string": true,
"number": true,
"boolean": true
};
let result = ts.ok();
if(vl !== null && !allowedTypes[typeof vl]){
result = ts.error(messageRegistry.INVALID_PROPERTY_RANGE, this, { propName: this.facetName(), range: "string"});
ts.setValidationPath(result,{name:this.facetName()});
}
parentStatus.addSubStatus(result);
return parentStatus;
}
}

@@ -62,2 +91,15 @@ export class NotScalar extends MetaInfo{

private static CLASS_IDENTIFIER_NotScalar = "metainfo.NotScalar";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(NotScalar.CLASS_IDENTIFIER_NotScalar);
}
public static isInstance(instance: any): instance is NotScalar {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), NotScalar.CLASS_IDENTIFIER_NotScalar);
}
kind() : tsInterfaces.MetaInformationKind {

@@ -73,2 +115,15 @@ return tsInterfaces.MetaInformationKind.NotScalar;

private static CLASS_IDENTIFIER_ImportedByChain = "metainfo.ImportedByChain";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(ImportedByChain.CLASS_IDENTIFIER_ImportedByChain);
}
public static isInstance(instance: any): instance is ImportedByChain {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), ImportedByChain.CLASS_IDENTIFIER_ImportedByChain);
}
kind() : tsInterfaces.MetaInformationKind {

@@ -103,10 +158,38 @@ return tsInterfaces.MetaInformationKind.ImportedByChain;

constructor(value:string){
super("displayName",value)
super("displayName",value);
}
private static CLASS_IDENTIFIER_DisplayName = "metainfo.DisplayName";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(DisplayName.CLASS_IDENTIFIER_DisplayName);
}
public static isInstance(instance: any): instance is DisplayName {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), DisplayName.CLASS_IDENTIFIER_DisplayName);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.DisplayName;
}
protected validateSelfIndividual(parentStatus:Status,registry:ts.TypeRegistry):Status{
let vl = this.value();
const allowedTypes:{[key:string]:boolean} = {
"string": true,
"number": true,
"boolean": true
};
let result = ts.ok();
if(vl !== null && !allowedTypes[typeof vl]){
result = ts.error(messageRegistry.INVALID_PROPERTY_RANGE, this, { propName: this.facetName(), range: "string"});
ts.setValidationPath(result,{name:this.facetName()});
}
parentStatus.addSubStatus(result);
return parentStatus;
}
}

@@ -126,3 +209,3 @@ export class Usage extends MetaInfo{

constructor(name: string,value:any,protected path:string, protected ofExample=false){
constructor(name: string,value:any,protected path:string, protected ofExample=false, private _index:number=-1){
super(name,value)

@@ -139,2 +222,14 @@ }

definition(){
var owner=this.owner();
if (owner){
var reg=owner.collection();
if (reg){
var tp=reg.getAnnotationType(this.facetName());
return tp;
}
}
return null;
}
validateSelfIndividual(parentStatus:ts.Status,registry:ts.TypeRegistry):ts.Status {

@@ -213,2 +308,6 @@ var tp=registry.get(this.facetName());

}
getPath():string{
return this.path;
}
}

@@ -322,8 +421,2 @@ export class FacetDeclaration extends MetaInfo{

var exampleScalarProperties = [
{propName: "strict", propType: "boolean", messageEntry:messageRegistry.STRICT_BOOLEAN},
{propName: "displayName", propType: "string", messageEntry:messageRegistry.DISPLAY_NAME_STRING},
{propName: "description", propType: "string", messageEntry:messageRegistry.DESCRIPTION_STRING}
];
export class Example extends MetaInfo{

@@ -352,34 +445,4 @@ constructor(value:any){

if (val.hasOwnProperty("value")){
for(var y of exampleScalarProperties) {
var propName = y.propName;
var propType = y.propType;
var propObj = val[propName];
if (propObj&&typeof propObj!=propType){
if(typeof(propObj)=="object") {
Object.keys(propObj).forEach(key=> {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes,{
name: "example",
child: {name: propName, child: {name: key}}
});
result.addSubStatus(aRes);
}
});
}
if(!propObj.value&&typeof propObj.value!=propType) {
var s = ts.error(y.messageEntry, this);
var vp = propObj.value ? {name: "value"} : null;
ts.setValidationPath(s,{name: "example", child: {name: propName, child: vp}});
result.addSubStatus(s);
}
}
}
if (val.strict===false||(typeof(val.strict)=="object"&&val.strict.value===false)){
checkExampleScalarProperties(val,null,registry,result,this.facetName());
if (val.strict===false||(val.strict && typeof(val.strict)=="object"&&val.strict.value===false)){
return result;

@@ -489,2 +552,15 @@ }

private static CLASS_IDENTIFIER_HasPropertiesFacet = "metainfo.HasPropertiesFacet";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(HasPropertiesFacet.CLASS_IDENTIFIER_HasPropertiesFacet);
}
public static isInstance(instance: any): instance is HasPropertiesFacet {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), HasPropertiesFacet.CLASS_IDENTIFIER_HasPropertiesFacet);
}
kind() : tsInterfaces.MetaInformationKind {

@@ -572,6 +648,4 @@ return tsInterfaces.MetaInformationKind.HasPropertiesFacet;

val = exampleObj.value;
for(var y of exampleScalarProperties) {
this.checkScalarProperty(exampleObj, x, y, registry,rs);
}
if (exampleObj.strict===false||(
checkExampleScalarProperties(exampleObj,x,registry,rs,this.facetName());
if (exampleObj.strict===false||(exampleObj.strict &&
typeof(exampleObj.strict)=="object" && exampleObj.strict.value === false)){

@@ -605,41 +679,2 @@ return ;

private checkScalarProperty(
exampleObj:any,
exampleName:string,
y:any,
registry:ts.TypeRegistry,
status:Status) {
var propName = y.propName;
var propType = y.propType;
var propObj = exampleObj[propName];
if (propObj && typeof propObj != propType) {
var vp:tsInterfaces.IValidationPath = null;
if (typeof(propObj) == "object") {
vp = {name: "value"};
Object.keys(propObj).forEach(key=> {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key],key,true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes,
{
name: "examples",
child: {name: exampleName, child: {name: propName, child: {name: key}}}
});
status.addSubStatus(aRes);
}
});
}
if (!propObj.value && typeof(propObj.value) != propType) {
var s = ts.error(y.messageEntry, this);
ts.setValidationPath(s,{
name: "examples",
child: {name: exampleName, child: {name: propName, child: vp}}
});
status.addSubStatus(s);
}
}
}
kind() : tsInterfaces.MetaInformationKind {

@@ -690,2 +725,70 @@ return tsInterfaces.MetaInformationKind.Examples;

}
export class SchemaPath extends MetaInfo{
constructor(path:string){
super("schemaPath",path,true);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.SchemaPath;
}
}
export class SourceMap extends MetaInfo{
constructor(value:Object){
super("sourceMap",value);
}
private static CLASS_IDENTIFIER_SourceMap = "metainfo.SourceMap";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(SourceMap.CLASS_IDENTIFIER_SourceMap);
}
public static isInstance(instance: any): instance is SourceMap {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), SourceMap.CLASS_IDENTIFIER_SourceMap);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.SourceMap;
}
}
export class TypeAttributeValue extends MetaInfo{
constructor(value:any){
super("typeAttributeValue",value);
}
private static CLASS_IDENTIFIER_TypeAttributeValue = "metainfo.TypeAttributeValue";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(TypeAttributeValue.CLASS_IDENTIFIER_TypeAttributeValue);
}
public static isInstance(instance: any): instance is TypeAttributeValue {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), TypeAttributeValue.CLASS_IDENTIFIER_TypeAttributeValue);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.TypeAttributeValue;
}
}
export class ParserMetadata extends MetaInfo{
constructor(value:Object){
super("__METADATA__",value);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.ParserMetadata;
}
}
export class Discriminator extends ts.TypeInformation{

@@ -740,2 +843,8 @@

super(false);
if(this._value && typeof this._value === "object"){
if(typeof this._value.strict === "boolean"){
this.strict = this._value.strict;
}
this._value = this._value.value;
}
}

@@ -859,1 +968,86 @@

}
function checkExampleScalarProperties(
exampleObj:any,
exampleName:string,
registry:ts.TypeRegistry,
status:Status,
facetName:string){
for(var y of exampleScalarProperties) {
checkScalarProperty(exampleObj, exampleName, y, registry,status,facetName);
}
}
function checkScalarProperty(
exampleObj:any,
exampleName:string,
y:any,
registry:ts.TypeRegistry,
status:Status,
facetName:string,) {
let propName = y.propName;
let propType = y.propType;
if(!exampleObj
||(typeof exampleObj != "object")
||!exampleObj.hasOwnProperty(propName)){
return;
}
let propObj = exampleObj[propName];
if(propObj==null){
let s = ts.error(y.messageEntry, this);
let vp:ts.IValidationPath = toExampleScalarPropertyPath(exampleName,facetName,{name: propName});
ts.setValidationPath(s,vp);
status.addSubStatus(s);
}
else if (typeof propObj != propType) {
let vp:tsInterfaces.IValidationPath = null;
if (typeof(propObj) == "object") {
vp = toExampleScalarPropertyPath(exampleName,facetName,{name: "value"});
Object.keys(propObj).forEach(key=> {
if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
let a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key],key,true);
let aRes = a.validateSelf(registry);
let vp:ts.IValidationPath = toExampleScalarPropertyPath(exampleName,facetName,{name: propName, child: {name: key}});
ts.setValidationPath(aRes,vp);
status.addSubStatus(aRes);
}
});
}
if (!propObj.value && typeof(propObj.value) != propType) {
let s = ts.error(y.messageEntry, this);
ts.setValidationPath(s,{
name: "examples",
child: {name: exampleName, child: {name: propName, child: vp}}
});
status.addSubStatus(s);
}
}
}
function toExampleScalarPropertyPath(
exampleName:string,
facetName:string,
vp:ts.IValidationPath):ts.IValidationPath{
let p = vp;
if (exampleName) {
p = {
name: exampleName,
child: vp
};
}
return {
name: facetName,
child: p
};
}
const exampleScalarProperties = [
{propName: "strict", propType: "boolean", messageEntry:messageRegistry.STRICT_BOOLEAN},
{propName: "displayName", propType: "string", messageEntry:messageRegistry.DISPLAY_NAME_STRING},
{propName: "description", propType: "string", messageEntry:messageRegistry.DESCRIPTION_STRING}
];

@@ -121,2 +121,7 @@ import ts=require("./typesystem");

type: ts.AbstractType;
annotations: {
name: string,
key: string
value: any
}[];

@@ -132,3 +137,3 @@ add(t:ts.AbstractType){

else if (this.regExp){
matchesPropertyFacet = new rs.MapPropertyIs(this.id,this.type);
matchesPropertyFacet = new rs.MapPropertyIs(this.id,this.type,this.optional);
}

@@ -144,2 +149,9 @@ else{

}
if(this.annotations && this.annotations.length){
for(let a of this.annotations){
const a1 = new meta.Annotation(a.name,a.value,a.key);
a1.setOwnerFacet(matchesPropertyFacet);
matchesPropertyFacet.addAnnotation(a1);
}
}
}

@@ -167,2 +179,3 @@ }

add(t:AbstractType){
this._types = this._types.filter(x=>x.name()!=t.name());
this._types.push(t);

@@ -413,5 +426,22 @@ this._typeMap[t.name()]=t;

var rsValue = requiredNode.value();
if (typeof rsValue=="boolean"){
if (typeof rsValue==="boolean"){
hasRequiredFacet = true;
}
else if(rsValue && typeof(rsValue)==="object" && typeof rsValue.value ==="boolean"){
hasRequiredFacet = true;
let annotations = Object.keys(rsValue).filter(x=>{
x = x.trim();
return x.length>1 && x.charAt(0)=="(" && x.charAt(x.length-1)==")";
});
if(annotations.length) {
result.annotations = annotations.map(x=>{
x = x.trim();
return {
name: x.substring(1,x.length-1).trim(),
key: x,
value: rsValue[x]
};
});
}
}
if (rsValue===false){

@@ -427,3 +457,3 @@ result.optional=true;

}
if (name.length==0||name==='/.*/'){
if (name != null && name.length==0||name==='/.*/'){
result.additonal=true;

@@ -548,3 +578,3 @@

if (x.regExp){
nm="/"+nm+"/";
nm="/"+x.id+"/";
}

@@ -624,8 +654,10 @@ var vl:any=null;

pbean.optional=false;
pbean.id= "/.*/";
pbean.id= ".*";
pbean.additonal=true;
pbean.type= x.value();
pbean.optional = x.isOptional();
pbean.regExp=true;
pmap['/.*/']=pbean;
}
else if (x instanceof rs.MapPropertyIs){
else if (rs.MapPropertyIs.isInstance(x)){
var pbean=new PropertyBean();

@@ -636,5 +668,6 @@ pbean.optional=false;

pbean.type= x.value();
pbean.optional = x.isOptional();
pmap[x.regexpValue()]=pbean;
}
else if (x instanceof rs.PropertyIs){
else if (rs.PropertyIs.isInstance(x)){
if (pmap.hasOwnProperty(x.propertyName())){

@@ -651,6 +684,6 @@ pmap[x.propertyName()].type= x.value();

}
else if (x instanceof rs.KnownPropertyRestriction) {
else if (rs.KnownPropertyRestriction.isInstance(x)) {
result.additionalProperties = x.value();
}
else if(x instanceof meta.DiscriminatorValue){
else if(meta.DiscriminatorValue.isInstance(x)){
if((<meta.DiscriminatorValue>x).isStrict()){

@@ -660,3 +693,3 @@ result.basicFacets.push(x);

}
else if(!(x instanceof meta.HasPropertiesFacet)) {
else if(!meta.HasPropertiesFacet.isInstance(x)) {
result.basicFacets.push(x);

@@ -763,11 +796,14 @@ }

function appendAnnotations(appendedInfo:ts.TypeInformation, childNode:ParseNode) {
var children = childNode.children();
for (var ch of children) {
var key = ch.key();
if (key && key.charAt(0) == "(" && key.charAt(key.length - 1) == ")") {
var aName = key.substring(1, key.length - 1);
var aInstance = new meta.Annotation(aName, ch.value(), key);
aInstance.setNode(ch);
aInstance.setOwnerFacet(appendedInfo);
appendedInfo.addAnnotation(aInstance);
let arr = childNode.kind() == NodeKind.ARRAY ? childNode.children() : [childNode];
for (let i = 0 ; i < arr.length ; i++) {
let children = arr[i].children();
for (let ch of children) {
let key = ch.key();
if (key && key.charAt(0) == "(" && key.charAt(key.length - 1) == ")") {
let aName = key.substring(1, key.length - 1);
let aInstance = new meta.Annotation(aName, ch.value(), key, false, i);
aInstance.setOwnerFacet(appendedInfo);
aInstance._owner = appendedInfo._owner;
appendedInfo.addAnnotation(aInstance);
}
}

@@ -865,3 +901,3 @@ }

supers.push(typeExpressions.parseToType(""+x.value(),r, n))
})
});
var res=ts.derive(name,supers);

@@ -887,3 +923,3 @@ if (AccumulatingRegistry.isInstance(r)){

var typePropAnnotations:tsInterfaces.IAnnotation[][] = [];
if (!tp||ignoreTypeAttr){
if (!tp||(!tp.children().length&&!tp.value())||ignoreTypeAttr){
if (defaultsToAny){

@@ -927,3 +963,4 @@ if (n.childWithKey("properties")) {

(<any>tp).contentProvider ? (<any>tp).contentProvider() : null;
superTypes=[typeExpressions.parseToType(""+valString,r, n, typeAttributeContentProvider)];
const st = typeExpressions.parseToType(""+valString,r, n, typeAttributeContentProvider);
superTypes=[st];
}

@@ -968,2 +1005,5 @@ }

var result=ts.derive(name,superTypes);
if(ignoreTypeAttr && tp){
result.addMeta(new meta.TypeAttributeValue(tp.value()));
}
for(var i = 0 ; i < typePropAnnotations.length ; i++){

@@ -984,3 +1024,3 @@ var aArr1:tsInterfaces.IAnnotation[] = typePropAnnotations[i];

var x = childNode;
if(key!="example"&&actual){
if(key!="example"&&key!="discriminatorValue"&&actual){
x = actual;

@@ -1012,43 +1052,30 @@ }

var componentTypes:ts.AbstractType[] = [];
if (x.kind()==NodeKind.SCALAR){
var valString = x.value();
if(valString==null||valString=="Null"||valString=="NULL"){
componentTypes = [ ts.STRING ];
let arr:ParseNode[] = [x];
if(x.kind()==NodeKind.ARRAY){
arr = x.children()
let err=ts.error(messageRegistry.ITEMS_SHOULD_BE_REFERENCE_OR_INLINE_TYPE,actualResult);
err.setValidationPath({ name:"items"})
result.putExtra(tsInterfaces.PARSE_ERROR,err);
}
var componentTypes:ts.AbstractType[] = arr.map(y=>{
let actual = y.childWithKey("value");
if(actual&&(actual.kind()==NodeKind.SCALAR||actual.kind()==NodeKind.MAP)){
y = actual;
}
else{
componentTypes=[typeExpressions.parseToType(""+valString,r, n)];
checkIfSkipValidation(componentTypes[0],x);
}
}
else if (x.kind()==NodeKind.ARRAY){
componentTypes=x.children().map(y=>{
var actual = y.childWithKey("value");
if(actual&&(actual.kind()==NodeKind.SCALAR||actual.kind()==NodeKind.ARRAY)){
sAnnotations.push(y.children().filter(x=>{
var key = x.key();
if(!key){
return false;
}
return key.charAt(0) == "(" && key.charAt(key.length - 1) == ")";
}));
y = actual;
if (y.kind()==NodeKind.SCALAR){
var valString = y.value();
if(valString==null||valString=="Null"||valString=="NULL"){
return ts.STRING;
}
else{
sAnnotations.push([]);
let res = typeExpressions.parseToType(""+valString,r, n);
checkIfSkipValidation(res,x);
return res;
}
return y;
}).map(y=>{
let result = typeExpressions.parseToType(""+y.value(),r, n);
checkIfSkipValidation(result,y);
return result;
});
var err=ts.error(messageRegistry.ITEMS_SHOULD_BE_REFERENCE_OR_INLINE_TYPE,actualResult);
err.setValidationPath({ name:"items"})
result.putExtra(tsInterfaces.PARSE_ERROR,err);
}
else if (x.kind()==NodeKind.MAP){
componentTypes=[parse("",x,r,false,false,false)];
}
var tp = componentTypes.length == 1 ? componentTypes[0] :
}
else if (y.kind()==NodeKind.MAP){
return parse("",y,r,false,false,false);
}
});
var tp = componentTypes.length == 1 ? componentTypes[0] :
ts.derive("",componentTypes);

@@ -1058,5 +1085,3 @@ appendedInfo = new ComponentShouldBeOfType(tp);

actualResult.putExtra(tsInterfaces.HAS_ITEMS,true)
if(actual){
appendAnnotations(appendedInfo, childNode);
}
appendAnnotations(appendedInfo, childNode);
return appendedInfo;

@@ -1087,6 +1112,6 @@ }

else {
if (annotation && key === "allowedTargets") {
result.addMeta(new meta.AllowedTargets(x.value()));
}
else {
// if (annotation && key === "allowedTargets") {
// result.addMeta(new meta.AllowedTargets(x.value()));
// }
{//else {
var customFacet = new meta.CustomFacet(key, x.value());

@@ -1093,0 +1118,0 @@ customFacet.setNode(x);

@@ -22,6 +22,4 @@ import ts=require("./typesystem");

constructor(private _type:ts.AbstractType){super()}
constructor(private _type:ts.AbstractType, protected optional=false){super()}
abstract path():string;
private static CLASS_IDENTIFIER_MatchesProperty = "restrictions.MatchesProperty";

@@ -40,2 +38,4 @@

abstract path():string;
check(i:any,p:ts.IValidationPath):ts.Status{

@@ -99,2 +99,6 @@ throw new Error(messageRegistry.SHOULD_BE_NEVER_CALLED.message);

}
isOptional():boolean{
return this.optional;
}
}

@@ -195,2 +199,15 @@

private static CLASS_IDENTIFIER_KnownPropertyRestriction = "typesystem.KnownPropertyRestriction";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(KnownPropertyRestriction.CLASS_IDENTIFIER_KnownPropertyRestriction);
}
public static isInstance(instance: any): instance is KnownPropertyRestriction {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), KnownPropertyRestriction.CLASS_IDENTIFIER_KnownPropertyRestriction);
}
facetName(){

@@ -272,2 +289,16 @@ return "closed"

}
private static CLASS_IDENTIFIER_HasProperty = "restrictions.HasProperty";
public getClassIdentifier() : string[] {
var superIdentifiers:string[] = super.getClassIdentifier();
return superIdentifiers.concat(HasProperty.CLASS_IDENTIFIER_HasProperty);
}
public static isInstance(instance: any): instance is HasProperty {
return instance != null && instance.getClassIdentifier
&& typeof(instance.getClassIdentifier) == "function"
&& _.contains(instance.getClassIdentifier(), HasProperty.CLASS_IDENTIFIER_HasProperty);
}
check(i:any):ts.Status{

@@ -312,4 +343,4 @@ if (i&&typeof i=='object'&&!Array.isArray(i)) {

constructor(private name: string,private type:ts.AbstractType, private optional:boolean=false){
super(type);
constructor(private name: string,private type:ts.AbstractType,optional=false){
super(type,optional);
}

@@ -394,6 +425,2 @@

}
isOptional():boolean{
return this.optional;
}
}

@@ -435,4 +462,4 @@

constructor(private regexp: string,private type:ts.AbstractType){
super(type);
constructor(private regexp: string,private type:ts.AbstractType,optional=false){
super(type,optional);
}

@@ -466,5 +493,5 @@

}
propId():string{
return '['+this.regexp+']'
}
propId():string{
return '['+this.regexp+']'
}

@@ -555,4 +582,4 @@ facetName(){

constructor(private type:ts.AbstractType){
super(type);
constructor(private type:ts.AbstractType,optional=false){
super(type,optional);
}

@@ -574,3 +601,3 @@

path(){
return this.facetName();
return "/.*/";
}

@@ -1137,3 +1164,4 @@ matches(s:string):boolean{

public toString() {
return ts.error(messageRegistry.ITEMS_SHOULD_BE_OF_TYPE, this, {type:this.type}).getMessage();
let typeName = this.type && this.type.name();
return ts.error(messageRegistry.ITEMS_SHOULD_BE_OF_TYPE, this, {type: typeName}).getMessage();
}

@@ -1184,3 +1212,5 @@ check(i:any):ts.Status{

else if (this.type.isExternal()){
st.addSubStatus(ts.error(messageRegistry.EXTERNAL_AS_COMPONENT,this));
let itemsErr = ts.error(messageRegistry.EXTERNAL_AS_COMPONENT,this);
itemsErr.setValidationPath({name:"items"});
st.addSubStatus(itemsErr);
}

@@ -1435,3 +1465,8 @@ else if (ts.isUnknown(this.type) || this.type.isSubTypeOf(ts.RECURRENT)) {

if (!opts.some(x=>x == i)) {
var valStr = Array.isArray(this._value) ? this._value.map(x=>`'${x}'`).join(", ") : `'${this._value}'`;
var valStr = Array.isArray(this._value) ? this._value.map(x=>{
if(x && typeof x === "object"){
return JSON.stringify(x,null,2);
}
return `'${x}'`
}).join(", ") : `'${this._value}'`;
return ts.error(messageRegistry.ENUM_RESTRICTION,this, {values: valStr});

@@ -1438,0 +1473,0 @@ }

@@ -17,2 +17,5 @@ import typeExpression=require("./typeExpressionParser")

typeAttributeContentProvider: schemaUtil.IContentProvider = null):ts.AbstractType{
if(val==null){
return null;
}
try {

@@ -19,0 +22,0 @@

@@ -91,5 +91,2 @@ export interface IValidationPath{

NotScalar,
ImportedByChain,
AcceptAllScalarsAsStrings,
SkipValidation,
DisplayName,

@@ -110,3 +107,10 @@ Usage,

Discriminator,
DiscriminatorValue
DiscriminatorValue,
SchemaPath,
SourceMap,
ParserMetadata,
ImportedByChain,
AcceptAllScalarsAsStrings,
SkipValidation,
TypeAttributeValue
}

@@ -183,2 +187,17 @@

owner():IParsedType
/**
* Annotation name
*/
name():string;
/**
* Annotation value
*/
value(): any;
/**
* Annotation definition type
*/
definition(): IParsedType;
}

@@ -258,4 +277,13 @@

isAdditional(): boolean
annotations(): IAnnotation[]
}
export interface IAnnotated {
annotations(): IAnnotation[]
annotation(name: string): any
}
/**

@@ -265,3 +293,3 @@ * parsed representation of the type

*/
export interface IParsedType extends IHasExtra {
export interface IParsedType extends IAnnotated, IHasExtra {

@@ -306,2 +334,6 @@ /**

scalarsAnnotations(): {[key:string]:IAnnotation[][]};
declaredScalarsAnnotations(): {[key:string]:IAnnotation[][]};
registry(): IParsedTypeCollection

@@ -599,2 +631,6 @@

displayName(): string
description():string
strict(): boolean

@@ -643,2 +679,31 @@

end: MarkerObject
}
export interface SourceInfo{
/**
* Path to file which contains definition
*/
path?: string
/**
* Namespace of defining library if any
*/
namespace?: string
}
export interface ElementSourceInfo extends SourceInfo{
/**
* Source information for fields which are defined in another file rather then their owning component.
* If all scalar fields of the component are defined in the same file, the 'scalarsSources' field is undefined.
*/
scalarsSources: { [key:string]:SourceInfo[] }
}
export interface HasSource {
sourceMap(): ElementSourceInfo
}

@@ -513,9 +513,9 @@ import chai = require("chai");

it ("All facets",function (){
assert.equal(facetRegistry.getInstance().allPrototypes().length,31);
assert.equal(facetRegistry.getInstance().allPrototypes().length,34);
});
it ("All object facets",function (){
assert.equal(facetRegistry.getInstance().applyableTo(ts.OBJECT).length,19);
assert.equal(facetRegistry.getInstance().applyableTo(ts.OBJECT).length,22);
});
it ("All meta",function (){
assert.equal(facetRegistry.getInstance().allMeta().length,10);
assert.equal(facetRegistry.getInstance().allMeta().length,13);
});

@@ -522,0 +522,0 @@ })

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 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc