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.56 to 0.0.57

resources/errorMessages.json

25

dist/src/datetime.js

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

var ts = require("./typesystem");
var messageRegistry = ts.messageRegistry;
function checkDate(dateStr) {

@@ -21,7 +22,7 @@ return checkDateString(dateStr, "YYYY-MM-DD");

if (!checkDate(value)) {
return new ts.Status(ts.Status.ERROR, 0, "'date-only' instance should match 'yyyy-mm-dd' pattern", this);
return ts.error(messageRegistry.INVALID_DATEONLY, this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR, 0, "'date-only' instance should match 'yyyy-mm-dd' pattern", this);
return ts.error(messageRegistry.INVALID_DATEONLY, this);
};

@@ -53,11 +54,11 @@ DateOnlyR.prototype.requiredType = function () {

if (!matches) {
return new ts.Status(ts.Status.ERROR, 0, "'time-only' instance should match 'hh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_TIMEONLY, this);
}
var hhmmssTime = matches[1];
if (!checkTime(hhmmssTime)) {
return new ts.Status(ts.Status.ERROR, 0, "'time-only' instance should match 'hh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_TIMEONLY, this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR, 0, "'time-only' instance should match 'hh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_TIMEONLY, this);
};

@@ -86,3 +87,3 @@ TimeOnlyR.prototype.requiredType = function () {

if (!matches || matches.length < 3) {
return new ts.Status(ts.Status.ERROR, 0, "'datetime-only' instance should match 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_DATETIMEONLY, this);
}

@@ -92,7 +93,7 @@ var date = matches[1];

if (!checkDate(date) || !checkTime(time)) {
return new ts.Status(ts.Status.ERROR, 0, "'datetime-only' instance should match 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_DATETIMEONLY, this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR, 0, "'datetime-only' instance should be string matching 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern", this);
return ts.error(messageRegistry.INVALID_DATETIMEONLY, this);
};

@@ -134,3 +135,3 @@ DateTimeOnlyR.prototype.requiredType = function () {

if (!rfc3339Matches || rfc3339Matches.length < 3) {
return new ts.Status(ts.Status.ERROR, 0, "Valid rfc3339 formatted string is expected", this);
return ts.error(messageRegistry.INVALID_RFC3339, this);
}

@@ -141,3 +142,3 @@ else {

if (!checkDate(date) || !checkTime(time)) {
return new ts.Status(ts.Status.ERROR, 0, "Valid rfc3339 formatted string is expected", this);
return ts.error(messageRegistry.INVALID_RFC3339, this);
}

@@ -149,3 +150,3 @@ }

if (!(value.match(r1) || value.match(r2) || value.match(r3))) {
return new ts.Status(ts.Status.ERROR, 0, "Valid rfc2616 formatted string is expected", this);
return ts.error(messageRegistry.INVALID_RFC2616, this);
}

@@ -155,3 +156,3 @@ }

}
return new ts.Status(ts.Status.ERROR, 0, "Valid datetime formatted string is expected", this);
return ts.error(messageRegistry.INVALID_DATTIME, this);
};

@@ -158,0 +159,0 @@ DateTimeR.prototype.requiredType = function () {

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

var ts = require("./typesystem");
var messageRegistry = ts.messageRegistry;
var typesystem_1 = require("./typesystem");

@@ -92,3 +93,3 @@ var restrictions_1 = require("./restrictions");

if (!tp) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Using unknown annotation type: '" + this.facetName() + "'", this);
return ts.error(messageRegistry.UNKNOWN_ANNOTATION, this, { facetName: this.facetName() });
}

@@ -117,4 +118,3 @@ var result = ts.ok();

var list = arr.map(function (x) { return ("'" + x + "'"); }).join(", ");
var msg = "Annotation '" + _super.prototype.facetName.call(this) + "' can not be placed at this location, allowed targets are: " + list;
var targetStatus = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, msg, this);
var targetStatus = ts.error(messageRegistry.INVALID_ANNOTATION_LOCATION, this, { aName: _super.prototype.facetName.call(this), aValues: list });
result.addSubStatus(targetStatus);

@@ -125,3 +125,3 @@ }

if (!valOwner.isOk()) {
var res = new typesystem_1.Status(typesystem_1.Status.OK, 0, "Invalid annotation value " + valOwner.getMessage(), this);
var res = ts.error(messageRegistry.INVALID_ANNOTATION_VALUE, this, { msg: valOwner.getMessage() });
res.addSubStatus(valOwner);

@@ -190,3 +190,3 @@ result.addSubStatus(res);

if (type.isObject() || type.isArray()) {
var c = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Can not parse JSON example: " + e.message, this);
var c = ts.error(messageRegistry.CAN_NOT_PARSE_JSON, this, { msg: e.message });
return c;

@@ -201,3 +201,3 @@ }

if (errors) {
var error = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, 'Invalid XML.', {});
var error = ts.error(messageRegistry.INVALID_XML, null);
errors.forEach(function (child) { return error.addSubStatus(child); });

@@ -240,3 +240,3 @@ return error;

if (val.strict && typeof val.strict != "boolean") {
var s = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "'strict' should be boolean", this);
var s = ts.error(messageRegistry.STRICT_BOOLEAN, this);
s.setValidationPath({ name: "example", child: { name: "strict" } });

@@ -258,3 +258,3 @@ return s;

}
var c = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Using invalid 'example': " + valOwner.getMessage(), this);
var c = ts.error(messageRegistry.INVALID_EXMAPLE, this, { msg: valOwner.getMessage() });
valOwner.getErrors().forEach(function (x) {

@@ -322,3 +322,3 @@ c.addSubStatus(x);

if (typeof this.value() !== "boolean") {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Value of required facet should be boolean", this);
return ts.error(messageRegistry.REQUIRED_BOOLEAN, this);
}

@@ -400,3 +400,3 @@ return ts.ok();

if (typeof this.value() === 'object') {
var rs = new typesystem_1.Status(typesystem_1.Status.OK, 0, "", this);
var rs = new typesystem_1.Status(typesystem_1.Status.OK, "", "", this);
var v = this.value();

@@ -416,3 +416,3 @@ if (v) {

if (v[x].strict && typeof v[x].strict != "boolean") {
var s = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "'strict' should be boolean", _this);
var s = ts.error(messageRegistry.STRICT_BOOLEAN, _this);
s.setValidationPath({ name: x, child: { name: "strict", child: { name: "strict" } } });

@@ -449,3 +449,3 @@ return s;

else {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "'examples' value should be a map", this);
return ts.error(messageRegistry.EXMAPLES_MAP, this);
}

@@ -486,3 +486,3 @@ };

if (!valOwner.isOk()) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Using invalid 'defaultValue': " + valOwner.getMessage(), this);
return ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this, { msg: valOwner.getMessage() });
}

@@ -514,9 +514,9 @@ return ts.ok();

if (this.owner().isUnion()) {
result = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You can not specify 'discriminator' for union types", this);
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_UNION, this);
}
else if (!this.owner().isSubTypeOf(ts.OBJECT)) {
result = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You only can use 'discriminator' with object types", this);
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_OBJECT, this);
}
else if (this.owner().getExtra(ts.GLOBAL) === false) {
result = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You can not specify 'discriminator' for inline type declarations", this);
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_INLINE, this);
}

@@ -526,6 +526,6 @@ else {

if (!prop) {
result = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Using unknown property '" + this.value() + "' as discriminator", this, true);
result = ts.error(messageRegistry.UNKNOWN_FOR_DISCRIMINATOR, this, { value: this.value() }, ts.Status.WARNING);
}
else if (!prop.value().isScalar()) {
result = new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "It is only allowed to use scalar properties as discriminators", this);
result = ts.error(messageRegistry.SCALAR_FOR_DISCRIMINATOR, this);
}

@@ -569,3 +569,7 @@ }

if (adVal != dVal) {
var wrng = new typesystem_1.Status(typesystem_1.Status.WARNING, typesystem_1.Status.CODE_INCORRECT_DISCRIMINATOR, "None of the '" + owner.name() + "' type known subtypes declare '" + adVal + "' as value of discriminating property '" + dName + "'.", this);
var wrng = ts.error(typesystem_1.Status.CODE_INCORRECT_DISCRIMINATOR, this, {
rootType: owner.name(),
value: adVal,
propName: dName
}, typesystem_1.Status.WARNING);
//var wrng = new Status(Status.WARNING, Status.CODE_INCORRECT_DISCRIMINATOR, dVal, this);

@@ -578,3 +582,6 @@ wrng.setValidationPath({ name: dName, child: path });

else {
var err = new typesystem_1.Status(typesystem_1.Status.ERROR, typesystem_1.Status.CODE_MISSING_DISCRIMINATOR, "Instance of '" + owner.name() + "' subtype misses value of the discriminating property '" + dName + "'.", this);
var err = ts.error(typesystem_1.Status.CODE_MISSING_DISCRIMINATOR, this, {
rootType: owner.name(),
propName: dName
});
//var err = new Status(Status.ERROR, Status.CODE_MISSING_DISCRIMINATOR, dVal, this);

@@ -592,16 +599,18 @@ err.setValidationPath(path);

if (!this.owner().isSubTypeOf(ts.OBJECT)) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You only can use 'discriminator' with object types", this);
return ts.error(messageRegistry.DISCRIMINATOR_FOR_OBJECT, this);
}
if (this.owner().getExtra(ts.GLOBAL) === false) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You only can use 'discriminator' with top level type definitions", this);
return ts.error(messageRegistry.DISCRIMINATOR_FOR_INLINE, this);
}
var ds = this.owner().oneMeta(Discriminator);
if (!ds) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "You can not use 'discriminatorValue' without declaring 'discriminator'", this);
return ts.error(messageRegistry.DISCRIMINATOR_VALUE_WITHOUT_DISCRIMINATOR, this);
}
var prop = _.find(this.owner().meta(), function (x) { return x instanceof restrictions_1.PropertyIs && x.propertyName() == ds.value(); });
var prop = _.find(this.owner().meta(), function (x) {
return x instanceof restrictions_1.PropertyIs && x.propertyName() == ds.value();
});
if (prop) {
var sm = prop.value().validate(this.value());
if (!sm.isOk()) {
return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, "Using invalid 'disciminatorValue': " + sm.getMessage(), this);
return ts.error(messageRegistry.INVALID_DISCRIMINATOR_VALUE, this, { msg: sm.getMessage() });
}

@@ -608,0 +617,0 @@ }

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

var ts = require("./typesystem");
var messageRegistry = ts.messageRegistry;
var tsInterfaces = require("./typesystem-interfaces");

@@ -812,3 +813,3 @@ var rs = require("./restrictions");

else {
var err = new ts.Status(ts.Status.ERROR, 2, "'properties' should be a map", actualResult);
var err = ts.error(messageRegistry.PROPERTIES_MAP, actualResult);
err.setValidationPath({ name: "properties" });

@@ -832,3 +833,3 @@ result.putExtra(tsInterfaces.PARSE_ERROR, err);

else {
var err = new ts.Status(ts.Status.ERROR, 2, "'facets' should be a map", actualResult);
var err = ts.error(messageRegistry.FACETS_MAP, actualResult);
err.setValidationPath({ name: "facets" });

@@ -835,0 +836,0 @@ result.putExtra(tsInterfaces.PARSE_ERROR, err);

@@ -117,3 +117,3 @@ /// <reference path="../../typings/main.d.ts" />

abstract requiredType(): ts.AbstractType;
abstract checkValue(): string;
abstract checkValue(): ts.Status;
abstract value(): T;

@@ -151,3 +151,3 @@ /**

requiredType(): ts.AbstractType;
checkValue(): string;
checkValue(): ts.Status;
composeWith(t: ts.Constraint): ts.Constraint;

@@ -166,3 +166,3 @@ abstract textMessagePart(): string;

facetName(): string;
checkValue(): string;
checkValue(): ts.Status;
requiredType(): ts.AbstractType;

@@ -245,3 +245,3 @@ }

value(): boolean;
checkValue(): string;
checkValue(): ts.Status;
toString(): string;

@@ -261,3 +261,3 @@ }

composeWith(t: ts.Constraint): ts.Constraint;
checkValue(): string;
checkValue(): ts.Status;
value(): ts.AbstractType;

@@ -276,3 +276,3 @@ }

value(): string;
checkValue(): any;
checkValue(): ts.Status;
toString(): string;

@@ -292,3 +292,3 @@ }

value(): string;
checkValue(): any;
checkValue(): ts.Status;
toString(): string;

@@ -308,3 +308,3 @@ }

value(): string[];
checkValue(): string;
checkValue(): ts.Status;
toString(): string;

@@ -311,0 +311,0 @@ }

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

var ts = require("./typesystem");
var messageRegistry = ts.messageRegistry;
var su = require("./schemaUtil");

@@ -58,7 +59,7 @@ var _ = require("underscore");

if (t.isUnknown() || t.isRecurrent()) {
var s = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Validating instance against unknown type: '" + t.name() + "'", this);
var s = ts.error(messageRegistry.VALIDATING_AGAINS_UNKNOWN, this, { typeName: t.name() });
s.setValidationPath(this.patchPath(q));
return s;
}
var s = new typesystem_2.Status(typesystem_2.Status.OK, 0, "", this);
var s = new typesystem_2.Status(typesystem_2.Status.OK, "", "", this);
st.getErrors().forEach(function (x) { return s.addSubStatus(x); });

@@ -72,3 +73,3 @@ s.setValidationPath(this.patchPath(q));

if (this._type.isExternal()) {
var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "It is not allowed to use external types in property definitions", this);
var p = ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, this);
p.setValidationPath({ name: this.propId() });

@@ -79,3 +80,6 @@ return p;

var actualUnknown = actualUnknownType(this._type);
var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Property '" + this.propId() + "' refers to unknown type '" + actualUnknown.name() + "'", this);
var p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, this, {
propName: this.propId(),
typeName: actualUnknown.name()
});
p.setValidationPath({ name: this.propId(), child: { name: "type" } });

@@ -87,3 +91,6 @@ return p;

if (!st.isOk()) {
var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, ("Property '" + this.propId() + "' range type has error: ") + st.getMessage(), this);
var p = ts.error(messageRegistry.ERROR_IN_RANGE, this, {
propName: this.propId(),
msg: st.getMessage()
});
st.getErrors().forEach(function (y) { p.addSubStatus(y); });

@@ -98,3 +105,6 @@ p.setValidationPath({ name: this.propId() });

if (ui) {
var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, ("Property '" + this.propId() + "' refers to unknown type ") + ui.name(), this);
var p = ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION, this, {
propName: this.propId(),
typeName: ui.name()
});
p.setValidationPath({ name: this.propId() });

@@ -127,3 +137,3 @@ return p;

catch (e) {
return new ts.Status(ts.Status.ERROR, 0, "Incorrect schema: " + e.message, this);
return ts.error(messageRegistry.INCORRECT_SCHEMA, this, { msg: e.message });
}

@@ -145,3 +155,3 @@ }

if (e.message == "!_PERF_!") {
return new ts.Status(ts.Status.WARNING, 0, "Unable to validate example against schema (xmllint)", this);
return ts.error(messageRegistry.UNABLE_TO_VALIDATE_XML, this, {}, ts.Status.WARNING);
}

@@ -155,5 +165,5 @@ if (e.message == "Cannot assign to read only property '__$validated' of object") {

if (e.message == "Maximum call stack size exceeded") {
return new ts.Status(ts.Status.ERROR, 0, "JSON schema contains circular references", this);
return ts.error(messageRegistry.CIRCULAR_REFS_IN_JSON_SCHEMA, this);
}
return new ts.Status(ts.Status.ERROR, 0, "Example does not conform to schema: " + e.message, this);
return ts.error(messageRegistry.EXAMPLE_SCHEMA_FAILURE, this, { msg: e.message });
}

@@ -209,5 +219,5 @@ }

if ((this.owner().hasPropertiesFacet() || mp.length > 0) && unknownPropertyNames.length > 0) {
var s = new ts.Status(ts.Status.OK, 0, "", this);
var s = new ts.Status(ts.Status.OK, "", "", this);
unknownPropertyNames.forEach(function (x) {
var err = ts.error("Unknown property: '" + x + "'", _this);
var err = ts.error(messageRegistry.UNKNOWN_PROPERTY, _this, { propName: x });
err.setValidationPath({ name: x });

@@ -258,3 +268,3 @@ s.addSubStatus(err);

}
return ts.error("Required property '" + this.name + "' is missing", this);
return ts.error(messageRegistry.REQUIRED_PROPERTY_MISSING, this, { propName: this.name });
}

@@ -425,3 +435,3 @@ return ts.ok();

if (m) {
return new typesystem_2.Status(typesystem_2.Status.ERROR, 0, m, this);
return ts.error(messageRegistry.INVALID_REGEXP, this, { msg: m });
}

@@ -474,3 +484,3 @@ return _super.prototype.validateSelf.call(this, t);

}
var rs = new ts.Status(ts.Status.OK, 0, "", this);
var rs = new ts.Status(ts.Status.OK, "", "", this);
for (var _i = 0, _a = Object.getOwnPropertyNames(i); _i < _a.length; _i++) {

@@ -565,3 +575,3 @@ var n = _a[_i];

var t = this.type;
var res = new ts.Status(ts.Status.OK, 0, "", this);
var res = new ts.Status(ts.Status.OK, "", "", this);
if (i && typeof i === "object") {

@@ -637,9 +647,11 @@ Object.getOwnPropertyNames(i).forEach(function (n) {

}
var rs = ts.error(this.facetName() + " facet can only be used with " + typeNames + " types", this);
var rs = ts.error(messageRegistry.FACET_USAGE_RESTRICTION, this, {
facetName: this.facetName(),
typeNames: typeNames
});
rs.setValidationPath({ name: this.facetName() });
return rs;
}
var m = this.checkValue();
if (m) {
var rs = ts.error(m, this, true);
var rs = this.checkValue();
if (rs) {
rs.setValidationPath({ name: this.facetName() });

@@ -704,3 +716,3 @@ return rs;

MinMaxRestriction.prototype.createError = function () {
return ts.error(this.toString(), this);
return new typesystem_2.Status(typesystem_2.Status.ERROR, messageRegistry.MINMAX_RESTRICTION_VIOLATION.code, this.toString(), this);
};

@@ -718,11 +730,14 @@ MinMaxRestriction.prototype.minValue = function () {

if (typeof this._value != "number") {
return "'" + this.facetName() + "' value should be a number";
return ts.error(messageRegistry.FACET_REQUIRE_NUMBER, this, { facetName: this.facetName() }, ts.Status.ERROR, true);
}
if (this.isIntConstraint()) {
if (!is_int(this.value())) {
return "'" + this.facetName() + "' value should be an integer";
return ts.error(messageRegistry.FACET_REQUIRE_INTEGER, this, { facetName: this.facetName() }, ts.Status.ERROR, true);
}
}
if (this.value() < this.minValue()) {
return this.facetName() + "' value should be at least " + this.minValue();
return ts.error(messageRegistry.MIN_VALUE, this, {
facetName: this.facetName(),
minValue: this.minValue()
}, ts.Status.ERROR, true);
}

@@ -802,3 +817,3 @@ };

if (!is_int(q)) {
return new ts.Status(ts.Status.ERROR, 0, "result of division of " + o + " on " + this.value() + " should be integer", this);
return ts.error(messageRegistry.EVEN_RATIO, this, { val1: o, val2: this.value() });
}

@@ -816,3 +831,3 @@ }

if (typeof this._value != "number") {
return "'" + this.facetName() + "' value should be a number";
return ts.error(messageRegistry.FACET_REQUIRE_NUMBER, this, { facetName: this.facetName() }, ts.Status.ERROR, true);
}

@@ -991,3 +1006,3 @@ return null;

if (_.unique(r).length != r.length) {
return ts.error(this.toString(), this);
return ts.error(messageRegistry.MUST_BE_UNIQUE, this);
}

@@ -1033,3 +1048,3 @@ }

ComponentShouldBeOfType.prototype.check = function (i) {
var rs = new ts.Status(ts.Status.OK, 0, "", this);
var rs = new ts.Status(ts.Status.OK, "", "", this);
if (Array.isArray(i)) {

@@ -1042,3 +1057,3 @@ var ar = i;

if (t.isUnknown() || t.isRecurrent()) {
var s = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Array instance is validated against unknown type: '" + t.name() + "'", this);
var s = ts.error(messageRegistry.ARRAY_AGAINST_UNKNOWN, this, { typeName: t.name() });
return s;

@@ -1057,3 +1072,3 @@ }

if (!st.isOk()) {
return new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Component type has error: " + st.getMessage(), this);
return ts.error(messageRegistry.INVALID_COMPONENT_TYPE, this, { msg: st.getMessage() });
}

@@ -1063,7 +1078,6 @@ return st;

if (this.type.isExternal()) {
var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "It is not allowed to use external types in component type definitions", this);
return p;
return ts.error(messageRegistry.EXTERNAL_AS_COMPONENT, this);
}
if (this.type.isSubTypeOf(ts.UNKNOWN) || this.type.isSubTypeOf(ts.RECURRENT)) {
return new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Component refers to unknown type '" + this.type.name() + "'", this);
return ts.error(messageRegistry.UNKNOWN_AS_COMPONENT, this, { typeName: this.type.name() });
}

@@ -1073,3 +1087,3 @@ if (this.type.isUnion()) {

if (ui) {
return new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "Component refers to unknown type '" + ui.name() + "'", this);
return ts.error(messageRegistry.UNKNOWN_AS_COMPONENT, this, { typeName: ui.name() });
}

@@ -1139,3 +1153,3 @@ }

if (!gotMatch) {
return new ts.Status(ts.Status.ERROR, 0, "String should match to '" + this.value() + "'", this);
return ts.error(messageRegistry.PATTERN_VIOLATION, this, { value: this.value() });
}

@@ -1166,3 +1180,3 @@ }

catch (e) {
return e.message;
return ts.error(messageRegistry.INVALID_REGEXP, this, { msg: e.message }, ts.Status.ERROR, true);
}

@@ -1226,7 +1240,9 @@ return null;

if (!found) {
return "Following format values are allowed: " + allowedValues.map(function (x) { return ("'" + x + "'"); }).join(", ");
return ts.error(messageRegistry.ALLOWED_FORMAT_VALUES, this, {
allowedValues: allowedValues.map(function (x) { return ("'" + x + "'"); }).join(", ")
}, ts.Status.ERROR, true);
}
}
catch (e) {
return e.message;
return new typesystem_2.Status(typesystem_2.Status.ERROR, "", e.message, this);
}

@@ -1259,3 +1275,4 @@ return null;

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

@@ -1282,3 +1299,5 @@ }

if (!this.owner().isSubTypeOf(this.requiredType())) {
return "'enum' facet can only be used with: " + this.requiredType().name();
return ts.error(messageRegistry.ENUM_OWNER_TYPES, this, {
typeNames: this.requiredType().name()
}, ts.Status.ERROR, true);
}

@@ -1290,7 +1309,9 @@ if (this.requiredTypes() && this.requiredTypes().length > 0) {

var typeNames = "[" + this.requiredTypes().map(function (requiredType) { return ("'" + requiredType.name() + "'"); }).join(", ") + "]";
return "'enum' facet can only be used with: " + typeNames;
return ts.error(messageRegistry.ENUM_OWNER_TYPES, this, {
typeNames: typeNames
}, ts.Status.ERROR, true);
}
}
if (!Array.isArray(this._value)) {
return "'enum' facet value must be defined by array";
return ts.error(messageRegistry.ENUM_ARRAY, this, {}, ts.Status.ERROR, true);
}

@@ -1306,3 +1327,3 @@ // if (_.uniq(this._value).length<this._value.length){

if (!res.isOk()) {
result = res.getMessage();
result = res;
}

@@ -1309,0 +1330,0 @@ });

@@ -7,2 +7,4 @@ /// <reference path="../typings/main.d.ts" />

var DOMParser = require('xmldom').DOMParser;
var ts = require("./typesystem");
var typesystem_1 = require("./typesystem");
var ValidationResult = (function () {

@@ -81,3 +83,3 @@ function ValidationResult() {

if (!schema || schema.trim().length == 0 || schema.trim().charAt(0) != '{') {
throw new Error("Invalid JSON schema content");
throw new ts.ValidationError(typesystem_1.messageRegistry.INVALID_JSON_SCHEMA);
}

@@ -89,3 +91,3 @@ var jsonSchemaObject;

catch (err) {
throw new Error("It is not JSON schema(can not parse JSON: " + err.message + ")");
throw new ts.ValidationError(typesystem_1.messageRegistry.INVALID_JSON_SCHEMA_DETAILS, { msg: err.message });
}

@@ -107,3 +109,3 @@ if (!jsonSchemaObject) {

catch (e) {
throw new Error('Can not parse schema' + schema);
throw new ts.ValidationError(typesystem_1.messageRegistry.INVALID_JSON_SCHEMA_DETAILS, { msg: e.message });
}

@@ -299,3 +301,4 @@ delete jsonSchemaObject['$schema'];

if (errors && errors.length > 0) {
var res = new Error("Content is not valid according to schema: " + errors.map(function (x) { return x.message + " " + x.params; }).join(", "));
var msg = errors.map(function (x) { return x.message + " " + x.params; }).join(", ");
var res = new ts.ValidationError(typesystem_1.messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA, { msg: msg });
res.errors = errors;

@@ -319,3 +322,3 @@ globalCache.setValue(key, res);

content: null,
error: new Error("Reference not found: '" + reference + "'")
error: new ts.ValidationError(typesystem_1.messageRegistry.REFERENCE_NOT_FOUND, { ref: reference })
});

@@ -349,3 +352,3 @@ }

if (schema.charAt(0) != '<') {
throw new Error("Invalid JSON schema");
throw new ts.ValidationError(typesystem_1.messageRegistry.INVALID_XML_SCHEMA);
}

@@ -360,8 +363,9 @@ this.schemaObj = xmlUtil.getValidator(this.handleReferenceElement(schema));

var objectName = Object.keys(object)[0];
var err = new ts.ValidationError(typesystem_1.messageRegistry.EXTERNAL_TYPE_ERROR, { typeName: this.extraElementData.requestedName, objectName: objectName });
if (!this.extraElementData.type && !this.extraElementData.originalName) {
this.acceptErrors("key", [new Error("Referenced type '" + this.extraElementData.requestedName + "' does not match '" + objectName + "' root node")], true);
this.acceptErrors("key", [err], true);
return;
}
if (this.extraElementData.originalName && objectName !== this.extraElementData.originalName) {
this.acceptErrors("key", [new Error("Referenced type '" + this.extraElementData.requestedName + "' does not match '" + objectName + "' root node")], true);
this.acceptErrors("key", [err], true);
return;

@@ -423,3 +427,4 @@ }

if (errors && errors.length > 0) {
var res = new Error("Content is not valid according to schema: " + errors.map(function (x) { return x.message; }).join(", "));
var msg = errors.map(function (x) { return x.message; }).join(", ");
var res = new ts.ValidationError(typesystem_1.messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA, { msg: msg });
res.errors = errors;

@@ -491,3 +496,3 @@ globalCache.setValue(key, res);

if (useLint) {
globalCache.setValue(key, new Error("Can not parse schema"));
globalCache.setValue(key, new ts.ValidationError(typesystem_1.messageRegistry.CAN_NOT_PARSE_SCHEMA));
}

@@ -494,0 +499,0 @@ return null;

@@ -53,2 +53,6 @@ export interface IValidationPath {

getValidationPathAsString(): string;
/**
* Unique identifier
*/
getCode(): string;
}

@@ -55,0 +59,0 @@ export declare enum MetaInformationKind {

@@ -5,2 +5,3 @@ /// <reference path="../../typings/main.d.ts" />

import { ParseNode } from "./parse";
export declare let messageRegistry: any;
export declare type IValidationPath = tsInterfaces.IValidationPath;

@@ -10,4 +11,4 @@ export declare class Status implements tsInterfaces.IStatus {

static CODE_CONFLICTING_TYPE_KIND: number;
static CODE_INCORRECT_DISCRIMINATOR: number;
static CODE_MISSING_DISCRIMINATOR: number;
static CODE_INCORRECT_DISCRIMINATOR: any;
static CODE_MISSING_DISCRIMINATOR: any;
static ERROR: number;

@@ -17,3 +18,3 @@ static INFO: number;

static WARNING: number;
protected code: number;
protected code: string;
protected message: string;

@@ -28,3 +29,3 @@ protected severity: number;

setValidationPath(_c: tsInterfaces.IValidationPath): void;
constructor(severity: number, code: number, message: string, source: any, takeNodeFromSource?: boolean);
constructor(severity: number, code: string, message: string, source: any, takeNodeFromSource?: boolean);
addSubStatus(st: Status, pathName?: string): void;

@@ -37,3 +38,4 @@ getErrors(): Status[];

getSource(): any;
getCode(): number;
getCode(): string;
setCode(code: string): void;
isWarning(): boolean;

@@ -53,3 +55,3 @@ isError(): boolean;

export declare const SOURCE_EXTRA: string;
export declare function error(message: string, source: any, takeNodeFromSource?: boolean): Status;
export declare function error(messageEntry: any, source: any, params?: any, severity?: number, takeNodeFromSource?: boolean): Status;
export declare abstract class TypeInformation implements tsInterfaces.ITypeFacet {

@@ -484,3 +486,3 @@ private _inheritable;

private _extraOptionMessage;
constructor(val: Constraint[], _extraMessage?: string, _extraOptionMessage?: string);
constructor(val: Constraint[], _extraMessage?: any, _extraOptionMessage?: any);
check(i: any, p: tsInterfaces.IValidationPath): Status;

@@ -536,1 +538,6 @@ value(): any[];

export declare function typePath(t: AbstractType): string[];
export declare class ValidationError extends Error {
messageEntry: any;
parameters: any;
constructor(messageEntry: any, parameters?: any);
}

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

}
return errors.map(function (error) { return new typesystem_1.Status(typesystem_1.Status.ERROR, 0, error, {}); });
return errors.map(function (error) { return new typesystem_1.Status(typesystem_1.Status.ERROR, "", error, {}); });
}

@@ -182,0 +182,0 @@ exports.getXmlErrors = getXmlErrors;

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

@@ -23,2 +23,6 @@ "scripts": {

},
"browser": {
"raml-json-validation": false,
"raml-xml-validation": false
},
"repository": {

@@ -25,0 +29,0 @@ "type": "git",

@@ -9,2 +9,3 @@ declare function require(path:string):any

import ts=require("./typesystem");
var messageRegistry = ts.messageRegistry;

@@ -19,7 +20,7 @@ function checkDate(dateStr : string) : boolean {

if (!checkDate(value)){
return new ts.Status(ts.Status.ERROR,0,"'date-only' instance should match 'yyyy-mm-dd' pattern",this)
return ts.error(messageRegistry.INVALID_DATEONLY,this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR,0,"'date-only' instance should match 'yyyy-mm-dd' pattern",this)
return ts.error(messageRegistry.INVALID_DATEONLY,this);
}

@@ -48,3 +49,3 @@ requiredType(){

if (!matches){
return new ts.Status(ts.Status.ERROR,0,"'time-only' instance should match 'hh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_TIMEONLY,this);
}

@@ -54,7 +55,7 @@

if (!checkTime(hhmmssTime)){
return new ts.Status(ts.Status.ERROR,0,"'time-only' instance should match 'hh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_TIMEONLY,this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR,0,"'time-only' instance should match 'hh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_TIMEONLY,this);
}

@@ -78,3 +79,3 @@ requiredType(){

if (!matches || matches.length < 3){
return new ts.Status(ts.Status.ERROR,0,"'datetime-only' instance should match 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_DATETIMEONLY,this);
}

@@ -85,7 +86,7 @@

if (!checkDate(date) || !checkTime(time)) {
return new ts.Status(ts.Status.ERROR,0,"'datetime-only' instance should match 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_DATETIMEONLY,this);
}
return ts.ok();
}
return new ts.Status(ts.Status.ERROR,0,"'datetime-only' instance should be string matching 'yyyy-mm-ddThh:mm:ss[.ff...]' pattern",this)
return ts.error(messageRegistry.INVALID_DATETIMEONLY,this);
}

@@ -126,3 +127,3 @@ requiredType(){

if (!rfc3339Matches || rfc3339Matches.length < 3){
return new ts.Status(ts.Status.ERROR,0,"Valid rfc3339 formatted string is expected",this)
return ts.error(messageRegistry.INVALID_RFC3339,this);
} else {

@@ -132,3 +133,3 @@ var date = rfc3339Matches[1];

if (!checkDate(date) || !checkTime(time)) {
return new ts.Status(ts.Status.ERROR,0,"Valid rfc3339 formatted string is expected",this)
return ts.error(messageRegistry.INVALID_RFC3339,this);
}

@@ -140,3 +141,3 @@ }

if (!(value.match(r1)||value.match(r2)||value.match(r3))){
return new ts.Status(ts.Status.ERROR,0,"Valid rfc2616 formatted string is expected",this)
return ts.error(messageRegistry.INVALID_RFC2616,this);
}

@@ -146,3 +147,3 @@ }

}
return new ts.Status(ts.Status.ERROR,0,"Valid datetime formatted string is expected",this)
return ts.error(messageRegistry.INVALID_DATTIME,this);
}

@@ -149,0 +150,0 @@ requiredType(){

/// <reference path="../typings/main.d.ts" />
import ts=require("./typesystem")
import ts=require("./typesystem");
var messageRegistry = ts.messageRegistry;
import {Status} from "./typesystem";

@@ -82,3 +83,3 @@ import {PropertyIs} from "./restrictions";

if (!tp){
return new Status(Status.ERROR,0,`Using unknown annotation type: '${this.facetName()}'`,this);
return ts.error(messageRegistry.UNKNOWN_ANNOTATION,this,{facetName: this.facetName()});
}

@@ -107,4 +108,3 @@ var result = ts.ok();

var list = arr.map(x=>`'${x}'`).join(", ");
var msg = `Annotation '${super.facetName()}' can not be placed at this location, allowed targets are: ${list}`;
var targetStatus = new Status(Status.ERROR, 0, msg, this);
var targetStatus = ts.error(messageRegistry.INVALID_ANNOTATION_LOCATION, this, { aName: super.facetName(), aValues: list });
result.addSubStatus(targetStatus);

@@ -115,3 +115,3 @@ }

if (!valOwner.isOk()){
var res=new Status(Status.OK,0,"Invalid annotation value "+valOwner.getMessage(),this);
var res = ts.error(messageRegistry.INVALID_ANNOTATION_VALUE, this, { msg: valOwner.getMessage() });
res.addSubStatus(valOwner);

@@ -176,3 +176,3 @@ result.addSubStatus(res);

if (type.isObject()||type.isArray()){
var c= new Status(Status.ERROR,0,"Can not parse JSON example: "+e.message,this);
var c = ts.error(messageRegistry.CAN_NOT_PARSE_JSON, this, { msg: e.message });
return c;

@@ -189,3 +189,3 @@ }

if(errors) {
var error = new Status(Status.ERROR, 0, 'Invalid XML.', {});
var error = ts.error(messageRegistry.INVALID_XML, null);

@@ -232,3 +232,3 @@ errors.forEach(child => error.addSubStatus(child));

if (val.strict&&typeof val.strict!="boolean"){
var s= new Status(Status.ERROR,0,"'strict' should be boolean",this);
var s= ts.error(messageRegistry.STRICT_BOOLEAN,this);
s.setValidationPath({name: "example", child: {name: "strict"}})

@@ -252,3 +252,3 @@ return s;

}
var c= new Status(Status.ERROR,0,"Using invalid 'example': "+valOwner.getMessage(),this);
var c = ts.error(messageRegistry.INVALID_EXMAPLE, this, { msg : valOwner.getMessage() });
valOwner.getErrors().forEach(x=>{c.addSubStatus(x);

@@ -320,3 +320,3 @@ if (isVal) {

if (typeof this.value()!=="boolean"){
return new Status(Status.ERROR,0,"Value of required facet should be boolean",this);
return ts.error(messageRegistry.REQUIRED_BOOLEAN,this);
}

@@ -404,3 +404,3 @@ return ts.ok();

if (typeof this.value()==='object'){
var rs=new Status(Status.OK,0,"",this);
var rs=new Status(Status.OK,"","",this);
var v=this.value();

@@ -420,3 +420,3 @@ if (v) {

if (v[x].strict&&typeof v[x].strict!="boolean"){
var s= new Status(Status.ERROR,0,"'strict' should be boolean",this);
var s= ts.error(messageRegistry.STRICT_BOOLEAN,this);
s.setValidationPath({name: x, child: {name: "strict", child: {name: "strict"}}});

@@ -453,3 +453,3 @@ return s;

else{
return new Status(Status.ERROR,0,"'examples' value should be a map",this);
return ts.error(messageRegistry.EXMAPLES_MAP,this);
}

@@ -490,3 +490,3 @@ }

if (!valOwner.isOk()){
return new Status(Status.ERROR,0,"Using invalid 'defaultValue': "+valOwner.getMessage(),this);
return ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this , { msg : valOwner.getMessage() });
}

@@ -518,9 +518,9 @@ return ts.ok();

if (this.owner().isUnion()){
result = new Status(Status.ERROR,0,"You can not specify 'discriminator' for union types",this)
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_UNION, this);
}
else if (!this.owner().isSubTypeOf(ts.OBJECT)){
result = new Status(Status.ERROR,0,"You only can use 'discriminator' with object types",this);
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_OBJECT, this)
}
else if (this.owner().getExtra(ts.GLOBAL)===false){
result = new Status(Status.ERROR,0,"You can not specify 'discriminator' for inline type declarations",this)
result = ts.error(messageRegistry.DISCRIMINATOR_FOR_INLINE, this)
}

@@ -530,6 +530,7 @@ else {

if (!prop) {
result = new Status(Status.ERROR, 0, "Using unknown property '" + this.value() + "' as discriminator", this, true);
result = ts.error(messageRegistry.UNKNOWN_FOR_DISCRIMINATOR,
this, {value: this.value()}, ts.Status.WARNING);
}
else if (!prop.value().isScalar()) {
result = new Status(Status.ERROR, 0, "It is only allowed to use scalar properties as discriminators", this);
result = ts.error(messageRegistry.SCALAR_FOR_DISCRIMINATOR, this);
}

@@ -570,4 +571,7 @@ }

if (adVal != dVal) {
var wrng = new Status(Status.WARNING, Status.CODE_INCORRECT_DISCRIMINATOR,
`None of the '${owner.name()}' type known subtypes declare '${adVal}' as value of discriminating property '${dName}'.`, this);
var wrng = ts.error(Status.CODE_INCORRECT_DISCRIMINATOR, this, {
rootType : owner.name(),
value: adVal,
propName: dName
}, Status.WARNING );
//var wrng = new Status(Status.WARNING, Status.CODE_INCORRECT_DISCRIMINATOR, dVal, this);

@@ -580,4 +584,6 @@ wrng.setValidationPath({name: dName, child: path});

else {
var err = new Status(Status.ERROR, Status.CODE_MISSING_DISCRIMINATOR,
`Instance of '${owner.name()}' subtype misses value of the discriminating property '${dName}'.`, this);
var err = ts.error(Status.CODE_MISSING_DISCRIMINATOR, this, {
rootType: owner.name(),
propName: dName
});
//var err = new Status(Status.ERROR, Status.CODE_MISSING_DISCRIMINATOR, dVal, this);

@@ -596,16 +602,18 @@ err.setValidationPath(path);

if (!this.owner().isSubTypeOf(ts.OBJECT)){
return new Status(Status.ERROR,0,"You only can use 'discriminator' with object types",this)
return ts.error(messageRegistry.DISCRIMINATOR_FOR_OBJECT, this);
}
if (this.owner().getExtra(ts.GLOBAL)===false){
return new Status(Status.ERROR,0,"You only can use 'discriminator' with top level type definitions",this)
return ts.error(messageRegistry.DISCRIMINATOR_FOR_INLINE, this);
}
var ds=this.owner().oneMeta(Discriminator);
if (!ds){
return new Status(Status.ERROR,0,"You can not use 'discriminatorValue' without declaring 'discriminator'",this)
return ts.error(messageRegistry.DISCRIMINATOR_VALUE_WITHOUT_DISCRIMINATOR, this);
}
var prop=_.find(this.owner().meta(),x=>x instanceof PropertyIs&& (<PropertyIs>x).propertyName()==ds.value());
var prop=_.find(this.owner().meta(),x=>
x instanceof PropertyIs&& (<PropertyIs>x).propertyName()==ds.value());
if (prop){
var sm=prop.value().validate(this.value());
if (!sm.isOk()){
return new Status(Status.ERROR,0,"Using invalid 'disciminatorValue': "+sm.getMessage(),this);
return ts.error(messageRegistry.INVALID_DISCRIMINATOR_VALUE,
this, { msg : sm.getMessage() });
}

@@ -612,0 +620,0 @@ }

@@ -1,2 +0,3 @@

import ts=require("./typesystem")
import ts=require("./typesystem");
var messageRegistry = ts.messageRegistry;
import tsInterfaces=require("./typesystem-interfaces")

@@ -883,3 +884,3 @@ import rs=require("./restrictions")

else{
var err=new ts.Status(ts.Status.ERROR,2,"'properties' should be a map",actualResult);
var err=ts.error(messageRegistry.PROPERTIES_MAP,actualResult);
err.setValidationPath({ name:"properties"})

@@ -904,3 +905,3 @@ result.putExtra(tsInterfaces.PARSE_ERROR,err);

else{
var err=new ts.Status(ts.Status.ERROR,2,"'facets' should be a map",actualResult);
var err=ts.error(messageRegistry.FACETS_MAP,actualResult);
err.setValidationPath({ name:"facets"})

@@ -907,0 +908,0 @@ result.putExtra(tsInterfaces.PARSE_ERROR,err);

/// <reference path="../typings/main.d.ts" />
import ts=require("./typesystem")
import ts=require("./typesystem");
var messageRegistry = ts.messageRegistry;
import su=require("./schemaUtil")

@@ -57,7 +58,8 @@ import _= require("underscore");

if (t.isUnknown()|| t.isRecurrent()){
var s=new Status(Status.ERROR,0,`Validating instance against unknown type: '${t.name()}'`,this);
var s=ts.error(messageRegistry.VALIDATING_AGAINS_UNKNOWN,
this,{typeName:t.name()});
s.setValidationPath(this.patchPath(q));
return s;
}
var s=new Status(Status.OK,0,"",this);
var s=new Status(Status.OK,"","",this);
st.getErrors().forEach(x=>s.addSubStatus(x));

@@ -75,3 +77,3 @@ s.setValidationPath(this.patchPath(q));

if (this._type.isExternal()){
var p= new Status(Status.ERROR,0,"It is not allowed to use external types in property definitions",this)
var p=ts.error(messageRegistry.EXTERNAL_IN_PROPERTY_DEFINITION, this);
p.setValidationPath({name: this.propId()})

@@ -82,3 +84,6 @@ return p;

var actualUnknown = actualUnknownType(this._type);
var p= new Status(Status.ERROR,0,`Property '${this.propId()}' refers to unknown type '${actualUnknown.name()}'`,this);
var p= ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,this,{
propName: this.propId(),
typeName: actualUnknown.name()
});
p.setValidationPath({name: this.propId(), child: { name: "type"}})

@@ -90,3 +95,6 @@ return p;

if (!st.isOk()){
var p= new Status(Status.ERROR,0,`Property '${this.propId()}' range type has error: `+st.getMessage(),this);
var p= ts.error(messageRegistry.ERROR_IN_RANGE,this, {
propName: this.propId(),
msg: st.getMessage()
});
st.getErrors().forEach(y=>{p.addSubStatus(y)});

@@ -103,3 +111,6 @@

if (ui){
var p=new Status(Status.ERROR,0,`Property '${this.propId()}' refers to unknown type `+ui.name(),this);
var p= ts.error(messageRegistry.UNKNOWN_IN_PROPERTY_DEFINITION,this,{
propName: this.propId(),
typeName: ui.name()
});
p.setValidationPath({name: this.propId()})

@@ -128,3 +139,3 @@ return p;

} catch (e){
return new ts.Status(ts.Status.ERROR,0,"Incorrect schema: "+ e.message,this);
return ts.error(messageRegistry.INCORRECT_SCHEMA,this,{msg: e.message});
}

@@ -144,3 +155,3 @@ }

if (e.message=="!_PERF_!"){
return new ts.Status(ts.Status.WARNING,0,"Unable to validate example against schema (xmllint)",this);
return ts.error(messageRegistry.UNABLE_TO_VALIDATE_XML,this,{},ts.Status.WARNING);
}

@@ -154,5 +165,6 @@ if (e.message=="Cannot assign to read only property '__$validated' of object"){

if (e.message == "Maximum call stack size exceeded"){
return new ts.Status(ts.Status.ERROR,0,"JSON schema contains circular references",this);
return ts.error(messageRegistry.CIRCULAR_REFS_IN_JSON_SCHEMA,this);
}
return new ts.Status(ts.Status.ERROR,0,"Example does not conform to schema: "+e.message,this);
return ts.error(messageRegistry.EXAMPLE_SCHEMA_FAILURE,
this, { msg : e.message });
}

@@ -214,5 +226,5 @@ //validate using classical schema;

if ((this.owner().hasPropertiesFacet()||mp.length>0) && unknownPropertyNames.length > 0) {
var s=new ts.Status(ts.Status.OK,0,"",this);
var s=new ts.Status(ts.Status.OK,"","",this);
unknownPropertyNames.forEach(x=>{
var err=ts.error(`Unknown property: '${x}'`,this);
var err=ts.error(messageRegistry.UNKNOWN_PROPERTY,this,{propName:x});
err.setValidationPath({name:x});

@@ -260,3 +272,4 @@ s.addSubStatus(err)}

}
return ts.error(`Required property '${this.name}' is missing`,this);
return ts.error(messageRegistry.REQUIRED_PROPERTY_MISSING,
this,{propName:this.name});
}

@@ -430,3 +443,3 @@ return ts.ok();

if (m){
return new Status(Status.ERROR,0,m,this);
return ts.error(messageRegistry.INVALID_REGEXP,this,{ msg: m });
}

@@ -479,3 +492,3 @@ return super.validateSelf(t);

}
var rs:ts.Status = new ts.Status(ts.Status.OK, 0, "",this);
var rs:ts.Status = new ts.Status(ts.Status.OK, "", "",this);
for(var n of Object.getOwnPropertyNames(i)){

@@ -569,3 +582,3 @@ if(fixedProperties[n]){

var t=this.type;
var res=new ts.Status(ts.Status.OK,0,"",this);
var res=new ts.Status(ts.Status.OK,"","",this);
if (i&&typeof i==="object") {

@@ -592,3 +605,3 @@ Object.getOwnPropertyNames(i).forEach(n=> {

abstract checkValue():string
abstract checkValue():ts.Status
abstract value():T;

@@ -648,3 +661,6 @@

var rs= ts.error(this.facetName()+" facet can only be used with "+ typeNames +" types",this);
var rs= ts.error(messageRegistry.FACET_USAGE_RESTRICTION,this,{
facetName: this.facetName(),
typeNames: typeNames
});

@@ -654,5 +670,4 @@ rs.setValidationPath({name:this.facetName()});

}
var m=this.checkValue();
if (m){
var rs= ts.error(m,this,true);
var rs=this.checkValue();
if (rs){
rs.setValidationPath({name:this.facetName()});

@@ -715,3 +730,3 @@ return rs;

createError():ts.Status{
return ts.error(this.toString(),this);
return new Status(Status.ERROR, messageRegistry.MINMAX_RESTRICTION_VIOLATION.code, this.toString(),this);
}

@@ -729,13 +744,18 @@

checkValue():string{
checkValue():ts.Status{
if (typeof this._value !="number"){
return `'${this.facetName()}' value should be a number`;
return ts.error(messageRegistry.FACET_REQUIRE_NUMBER,
this,{ facetName: this.facetName()},ts.Status.ERROR,true);
}
if (this.isIntConstraint()){
if (!is_int(this.value())){
return `'${this.facetName()}' value should be an integer`;
return ts.error(messageRegistry.FACET_REQUIRE_INTEGER,
this,{ facetName: this.facetName()},ts.Status.ERROR,true);
}
}
if (this.value()<this.minValue()){
return `${this.facetName()}' value should be at least ${this.minValue()}`;
return ts.error(messageRegistry.MIN_VALUE,this,{
facetName: this.facetName(),
minValue: this.minValue()
},ts.Status.ERROR,true);
}

@@ -819,5 +839,4 @@ }

if (!is_int(q)){
return new ts.Status(ts.Status.ERROR,0,"result of division of "+o+" on "+this.value()+" should be integer",this);
return ts.error(messageRegistry.EVEN_RATIO, this, { val1: o, val2 : this.value() });
}
}

@@ -834,5 +853,6 @@ return ts.ok();

checkValue():string{
checkValue():ts.Status{
if (typeof this._value !="number"){
return `'${this.facetName()}' value should be a number`;
return ts.error(messageRegistry.FACET_REQUIRE_NUMBER,
this,{ facetName: this.facetName()},ts.Status.ERROR,true);
}

@@ -1012,3 +1032,3 @@ return null;

if (_.unique(r).length!= r.length){
return ts.error(this.toString(),this);
return ts.error(messageRegistry.MUST_BE_UNIQUE,this);
}

@@ -1032,3 +1052,3 @@ }

}
checkValue():string{
checkValue():ts.Status{
return null;

@@ -1056,3 +1076,3 @@ }

var rs=new ts.Status(ts.Status.OK,0,"",this);
var rs=new ts.Status(ts.Status.OK,"","",this);
if (Array.isArray(i)){

@@ -1065,3 +1085,4 @@ var ar:any[]=i;

if (t.isUnknown()|| t.isRecurrent()){
var s=new Status(Status.ERROR,0,`Array instance is validated against unknown type: '${t.name()}'`,this);
var s=ts.error(messageRegistry.ARRAY_AGAINST_UNKNOWN,
this,{typeName:t.name()});
return s;

@@ -1080,3 +1101,4 @@ }

if (!st.isOk()) {
return new Status(Status.ERROR, 0, "Component type has error: " + st.getMessage(),this);
return ts.error(messageRegistry.INVALID_COMPONENT_TYPE,
this,{msg: st.getMessage()});
}

@@ -1086,7 +1108,6 @@ return st;

if (this.type.isExternal()){
var p= new Status(Status.ERROR,0,"It is not allowed to use external types in component type definitions",this);
return p;
return ts.error(messageRegistry.EXTERNAL_AS_COMPONENT,this);
}
if (this.type.isSubTypeOf(ts.UNKNOWN) || this.type.isSubTypeOf(ts.RECURRENT)) {
return new Status(Status.ERROR, 0, `Component refers to unknown type '${this.type.name()}'`,this);
return ts.error(messageRegistry.UNKNOWN_AS_COMPONENT,this,{ typeName: this.type.name()});
}

@@ -1096,3 +1117,3 @@ if (this.type.isUnion()) {

if (ui) {
return new Status(Status.ERROR, 0, `Component refers to unknown type '${ui.name()}'`,this)
return ts.error(messageRegistry.UNKNOWN_AS_COMPONENT,this,{ typeName: ui.name()});
}

@@ -1127,3 +1148,3 @@ }

}
checkValue():string{
checkValue():ts.Status{
return null;

@@ -1164,3 +1185,4 @@ }

if(!gotMatch){
return new ts.Status(ts.Status.ERROR, 0, `String should match to '${this.value()}'`,this);
return ts.error(messageRegistry.PATTERN_VIOLATION,
this,{value:this.value()});
}

@@ -1189,3 +1211,3 @@ }catch (e){

}
checkValue(){
checkValue():ts.Status{
try{

@@ -1195,3 +1217,4 @@ new RegExp(this._value);

catch (e){
return e.message;
return ts.error(messageRegistry.INVALID_REGEXP,
this,{msg: e.message},ts.Status.ERROR,true);
}

@@ -1241,3 +1264,3 @@ return null;

}
checkValue(){
checkValue():ts.Status{
try{

@@ -1256,7 +1279,9 @@ var allowedValues : string[] = [];

if (!found) {
return "Following format values are allowed: " + allowedValues.map(x=>`'${x}'`).join(", ");
return ts.error(messageRegistry.ALLOWED_FORMAT_VALUES,this,{
allowedValues : allowedValues.map(x=>`'${x}'`).join(", ")
}, ts.Status.ERROR, true);
}
}
catch (e){
return e.message;
return new Status(Status.ERROR, "", e.message,this);
}

@@ -1289,3 +1314,4 @@ return null;

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

@@ -1312,5 +1338,7 @@ }

}
checkValue(){
checkValue():ts.Status{
if (!this.owner().isSubTypeOf(this.requiredType())){
return "'enum' facet can only be used with: "+this.requiredType().name();
return ts.error(messageRegistry.ENUM_OWNER_TYPES,this,{
typeNames : this.requiredType().name()
}, ts.Status.ERROR, true);
}

@@ -1322,7 +1350,9 @@ if (this.requiredTypes() && this.requiredTypes().length > 0) {

var typeNames = "[" + this.requiredTypes().map(requiredType=>`'${requiredType.name()}'`).join(", ") + "]";
return "'enum' facet can only be used with: " + typeNames;
return ts.error(messageRegistry.ENUM_OWNER_TYPES,this,{
typeNames : typeNames
}, ts.Status.ERROR, true);
}
}
if(!Array.isArray(this._value)){
return "'enum' facet value must be defined by array";
return ts.error(messageRegistry.ENUM_ARRAY,this,{}, ts.Status.ERROR, true);
}

@@ -1332,3 +1362,3 @@ // if (_.uniq(this._value).length<this._value.length){

// }
var result:string=null;
var result:ts.Status=null;
this.checkStatus=true;

@@ -1339,3 +1369,3 @@ try {

if (!res.isOk()) {
result= res.getMessage();
result= res;
}

@@ -1342,0 +1372,0 @@ })

@@ -15,2 +15,4 @@ /// <reference path="../typings/main.d.ts" />

var DOMParser = require('xmldom').DOMParser;
import ts = require("./typesystem");
import {messageRegistry} from "./typesystem";

@@ -122,3 +124,3 @@ export class ValidationResult{

if(!schema||schema.trim().length==0||schema.trim().charAt(0)!='{'){
throw new Error("Invalid JSON schema content");
throw new ts.ValidationError(messageRegistry.INVALID_JSON_SCHEMA);
}

@@ -131,3 +133,3 @@

} catch(err){
throw new Error("It is not JSON schema(can not parse JSON: "+err.message+")");
throw new ts.ValidationError(messageRegistry.INVALID_JSON_SCHEMA_DETAILS,{msg:err.message});
}

@@ -151,3 +153,3 @@

} catch (e){
throw new Error('Can not parse schema'+schema)
throw new ts.ValidationError(messageRegistry.INVALID_JSON_SCHEMA_DETAILS,{msg:e.message});
}

@@ -399,12 +401,9 @@

if(errors && errors.length>0){
var res= new Error("Content is not valid according to schema: "+errors.map(x=>x.message+" "+x.params).join(", "));
var msg = errors.map(x=>x.message+" "+x.params).join(", ");
var res= new ts.ValidationError(messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA,{msg : msg});
(<any>res).errors=errors;
globalCache.setValue(key, res);
if(throwImmediately) {
throw res;
}
return;

@@ -427,3 +426,3 @@ }

content: null,
error: new Error(`Reference not found: '${reference}'`)
error: new ts.ValidationError(messageRegistry.REFERENCE_NOT_FOUND, {ref:reference})
});

@@ -469,3 +468,3 @@ }

if(schema.charAt(0)!='<'){
throw new Error("Invalid JSON schema")
throw new ts.ValidationError(messageRegistry.INVALID_XML_SCHEMA);
}

@@ -486,6 +485,7 @@

var err = new ts.ValidationError(messageRegistry.EXTERNAL_TYPE_ERROR,
{ typeName : this.extraElementData.requestedName, objectName : objectName });
if(!this.extraElementData.type && !this.extraElementData.originalName) {
this.acceptErrors("key", [new Error(
`Referenced type '${this.extraElementData.requestedName}' does not match '${objectName}' root node`)], true);
this.acceptErrors("key", [err], true);
return;

@@ -495,5 +495,3 @@ }

if(this.extraElementData.originalName && objectName !== this.extraElementData.originalName) {
this.acceptErrors("key", [new Error(
`Referenced type '${this.extraElementData.requestedName}' does not match '${objectName}' root node`)], true);
this.acceptErrors("key", [err], true);
return;

@@ -571,4 +569,4 @@ }

if(errors && errors.length>0){
var res= new Error("Content is not valid according to schema: "+errors.map(x=>x.message).join(", "));
var msg = errors.map(x=>x.message).join(", ");
var res= new ts.ValidationError(messageRegistry.CONTENT_DOES_NOT_MATCH_THE_SCHEMA,{msg : msg});
(<any>res).errors=errors;

@@ -649,3 +647,3 @@

if (useLint) {
globalCache.setValue(key, new Error("Can not parse schema"))
globalCache.setValue(key, new ts.ValidationError(messageRegistry.CAN_NOT_PARSE_SCHEMA));
}

@@ -652,0 +650,0 @@ return null;

@@ -63,2 +63,7 @@ export interface IValidationPath{

getValidationPathAsString():string;
/**
* Unique identifier
*/
getCode():string
}

@@ -65,0 +70,0 @@

@@ -244,3 +244,3 @@ /// <reference path="../typings/main.d.ts" />

return errors.map(error => new Status(Status.ERROR, 0, <string>error, {}))
return errors.map(error => new Status(Status.ERROR, "", <string>error, {}))
}

@@ -247,0 +247,0 @@

{
"ambientDependencies": {
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#315f5612ceb4de6f1f81f8cf49878084ea3f364a",
"chai": "github:DefinitelyTyped/DefinitelyTyped/chai/chai.d.ts#be0b6b394f77a59e192ad7cfec18078706e44db5",

@@ -4,0 +5,0 @@ "mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",

/// <reference path="browser/ambient/chai/chai.d.ts" />
/// <reference path="browser/ambient/jsonvalidation/jsonvalidation.d.ts" />
/// <reference path="browser/ambient/mocha/mocha.d.ts" />
/// <reference path="browser/ambient/node/node.d.ts" />
/// <reference path="browser/ambient/typescript/typescript.d.ts" />
/// <reference path="browser/ambient/underscore/underscore.d.ts" />
/// <reference path="browser/ambient/xml2js/xml2js.d.ts" />
/// <reference path="browser/ambient/xmlvalidation/xmlvalidation.d.ts" />

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts
// Type definitions for chai 2.0.0

@@ -4,0 +4,0 @@ // Project: http://chaijs.com/

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts
// Type definitions for mocha 2.2.5

@@ -4,0 +4,0 @@ // Project: http://mochajs.org/

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts
// Type definitions for node-xml2js

@@ -4,0 +4,0 @@ // Project: https://github.com/Leonidas-from-XIV/node-xml2js

/// <reference path="main/ambient/chai/chai.d.ts" />
/// <reference path="main/ambient/jsonvalidation/jsonvalidation.d.ts" />
/// <reference path="main/ambient/mocha/mocha.d.ts" />
/// <reference path="main/ambient/node/node.d.ts" />
/// <reference path="main/ambient/typescript/typescript.d.ts" />
/// <reference path="main/ambient/underscore/underscore.d.ts" />
/// <reference path="main/ambient/xml2js/xml2js.d.ts" />
/// <reference path="main/ambient/xmlvalidation/xmlvalidation.d.ts" />

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts
// Type definitions for chai 2.0.0

@@ -4,0 +4,0 @@ // Project: http://chaijs.com/

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts
// Type definitions for mocha 2.2.5

@@ -4,0 +4,0 @@ // Project: http://mochajs.org/

@@ -1,3 +0,3 @@

// Compiled using typings@0.6.10
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts
// Compiled using typings@0.3.3
// Source: https://raw.githubusercontent.com/definitelytyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts
// Type definitions for node-xml2js

@@ -4,0 +4,0 @@ // Project: https://github.com/Leonidas-from-XIV/node-xml2js

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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