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.75 to 0.0.76

13

dist/src/exampleBuilder.js

@@ -104,4 +104,15 @@ "use strict";

Example.prototype.isJSONString = function () {
if (this._isJSONString !== undefined) {
return this._isJSONString;
}
this._isJSONString = false;
var ch = this.firstCharacter();
return ch == "{" || ch == "[";
if (ch == "{" || ch == "[") {
try {
JSON.parse(this._value);
this._isJSONString = true;
}
catch (e) { }
}
return this._isJSONString;
};

@@ -108,0 +119,0 @@ Example.prototype.isXMLString = function () {

23

dist/src/metainfo.d.ts

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

}
export declare class SkipValidation extends MetaInfo {
constructor();
kind(): tsInterfaces.MetaInformationKind;
}
export declare class DisplayName extends MetaInfo {

@@ -40,6 +44,7 @@ constructor(value: string);

protected path: string;
constructor(name: string, value: any, path: string);
protected ofExample: boolean;
constructor(name: string, value: any, path: string, ofExample?: boolean);
private _ownerFacet;
name(): string;
validateSelf(registry: ts.TypeRegistry, ofExample?: boolean): ts.Status;
validateSelfIndividual(parentStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;
kind(): tsInterfaces.MetaInformationKind;

@@ -63,3 +68,3 @@ ownerFacet(): tsInterfaces.ITypeFacet;

isBuiltIn(): boolean;
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(parentStatue: ts.Status, registry: ts.TypeRegistry): ts.Status;
}

@@ -72,3 +77,3 @@ export declare class CustomFacet extends MetaInfo {

constructor(value: any);
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(parentStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;
validateValue(registry: ts.TypeRegistry): ts.Status;

@@ -82,3 +87,3 @@ validateAnnotations(registry: ts.TypeRegistry): ts.Status;

constructor(value: any);
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(result: ts.Status, registry: ts.TypeRegistry): ts.Status;
kind(): tsInterfaces.MetaInformationKind;

@@ -98,3 +103,3 @@ }

asXMLStrings(): string[];
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(parentStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;
private checkScalarProperty(exampleObj, exampleName, y, registry, status);

@@ -109,3 +114,3 @@ kind(): tsInterfaces.MetaInformationKind;

constructor(value: any);
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(result: ts.Status, registry: ts.TypeRegistry): ts.Status;
kind(): tsInterfaces.MetaInformationKind;

@@ -119,3 +124,3 @@ }

facetName(): string;
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(result: ts.Status, registry: ts.TypeRegistry): ts.Status;
kind(): tsInterfaces.MetaInformationKind;

@@ -132,3 +137,3 @@ }

facetName(): string;
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(st: ts.Status, registry: ts.TypeRegistry): ts.Status;
requiredType(): ts.InheritedType;

@@ -135,0 +140,0 @@ value(): any;

@@ -91,2 +91,13 @@ "use strict";

exports.ImportedByChain = ImportedByChain;
var SkipValidation = /** @class */ (function (_super) {
__extends(SkipValidation, _super);
function SkipValidation() {
return _super.call(this, "skipValidation", null, true) || this;
}
SkipValidation.prototype.kind = function () {
return tsInterfaces.MetaInformationKind.SkipValidation;
};
return SkipValidation;
}(MetaInfo));
exports.SkipValidation = SkipValidation;
var DisplayName = /** @class */ (function (_super) {

@@ -116,5 +127,7 @@ __extends(DisplayName, _super);

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

@@ -125,4 +138,3 @@ }

};
Annotation.prototype.validateSelf = function (registry, ofExample) {
if (ofExample === void 0) { ofExample = false; }
Annotation.prototype.validateSelfIndividual = function (parentStatus, registry) {
var tp = registry.get(this.facetName());

@@ -148,3 +160,3 @@ if (!tp) {

var aTargets = tp.metaOfType(AllowedTargets);
var contextTarget = ofExample ? "Example" : "TypeDeclaration";
var contextTarget = this.ofExample ? "Example" : "TypeDeclaration";
if (aTargets.length > 0) {

@@ -169,3 +181,3 @@ var arr = [];

var chained = tp.metaOfType(ImportedByChain);
if (chained.length > 0 && tp.isSubTypeOf(ts.UNKNOWN) && registry.getByChain(tp.name())) {
if (chained.length > 0 && ts.isUnknown(tp) && registry.getByChain(tp.name())) {
var chainedType = chained[0].value();

@@ -237,3 +249,3 @@ res = ts.error(messageRegistry.LIBRARY_CHAINIG_IN_ANNOTATION_TYPE_SUPERTYPE, this, { typeName: this.facetName(), chainedType: chainedType });

};
FacetDeclaration.prototype.validateSelf = function (registry) {
FacetDeclaration.prototype.validateSelfIndividual = function (parentStatue, registry) {
return restrictions_2.validatePropertyType(this._type, this.name, registry, this, false);

@@ -307,3 +319,3 @@ };

}
Example.prototype.validateSelf = function (registry) {
Example.prototype.validateSelfIndividual = function (parentStatus, registry) {
var status = ts.ok();

@@ -317,2 +329,5 @@ status.addSubStatus(this.validateValue(registry));

Example.prototype.validateValue = function (registry) {
if (this.owner().oneMeta(SkipValidation)) {
return;
}
var val = this.value();

@@ -332,4 +347,4 @@ var isVal = false;

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key);
var aRes = a.validateSelf(registry, true);
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes, {

@@ -397,4 +412,4 @@ name: "example",

var aName = ua.substring(1, ua.length - 1);
var aInstance = new Annotation(aName, aValue, ua);
status.addSubStatus(aInstance.validateSelf(registry, true));
var aInstance = new Annotation(aName, aValue, ua, true);
status.addSubStatus(aInstance.validateSelf(registry));
}

@@ -433,4 +448,3 @@ }

}
Required.prototype.validateSelf = function (registry) {
var result = _super.prototype.validateSelf.call(this, registry);
Required.prototype.validateSelfIndividual = function (result, registry) {
if (typeof this.value() !== "boolean") {

@@ -506,3 +520,3 @@ result = ts.error(messageRegistry.REQUIRED_BOOLEAN, this);

};
Examples.prototype.validateSelf = function (registry) {
Examples.prototype.validateSelfIndividual = function (parentStatus, registry) {
var _this = this;

@@ -521,4 +535,4 @@ if (typeof this.value() === 'object') {

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), v[x][key], key);
var aRes = a.validateSelf(registry, true);
var a = new Annotation(key.substring(1, key.length - 1), v[x][key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes, { name: "examples", child: { name: x, child: { name: key } } });

@@ -573,4 +587,4 @@ rs.addSubStatus(aRes);

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key], key);
var aRes = a.validateSelf(registry, true);
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes, {

@@ -624,5 +638,4 @@ name: "examples",

}
Default.prototype.validateSelf = function (registry) {
Default.prototype.validateSelfIndividual = function (result, registry) {
var _this = this;
var result = _super.prototype.validateSelf.call(this, registry);
var valOwner = this.owner().validateDirect(this.value(), true);

@@ -659,5 +672,4 @@ if (!valOwner.isOk()) {

Discriminator.prototype.facetName = function () { return "discriminator"; };
Discriminator.prototype.validateSelf = function (registry) {
Discriminator.prototype.validateSelfIndividual = function (result, registry) {
var _this = this;
var result = _super.prototype.validateSelf.call(this, registry);
if (this.owner().isUnion()) {

@@ -762,4 +774,3 @@ result = ts.error(messageRegistry.DISCRIMINATOR_FOR_UNION, this);

DiscriminatorValue.prototype.facetName = function () { return "discriminatorValue"; };
DiscriminatorValue.prototype.validateSelf = function (registry) {
var st = _super.prototype.validateSelf.call(this, registry);
DiscriminatorValue.prototype.validateSelfIndividual = function (st, registry) {
if (this.strict) {

@@ -766,0 +777,0 @@ var ds = this.owner().oneMeta(Discriminator);

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

var aInstance = new meta.Annotation(aName, ch.value(), key);
aInstance.setNode(ch);
aInstance.setOwnerFacet(appendedInfo);

@@ -708,2 +709,7 @@ appendedInfo.addAnnotation(aInstance);

}
var checkIfSkipValidation = function (sp, n) {
if (n.getMeta("skipValidation")) {
sp.addMeta(new meta.SkipValidation());
}
};
/**

@@ -746,2 +752,3 @@ * parses a type from a JSON structure

if (name == null) {
checkIfSkipValidation(sp, n);
return sp;

@@ -781,2 +788,3 @@ }

}
checkIfSkipValidation(res, n);
return res;

@@ -793,2 +801,3 @@ }

}
checkIfSkipValidation(res, n);
return res;

@@ -881,2 +890,3 @@ }

var aInstance = new meta.Annotation(aName, ann.value(), key);
aInstance.setNode(ann);
aiArr.push(aInstance);

@@ -933,2 +943,3 @@ }

componentTypes = [typeExpressions.parseToType("" + valString, r, n)];
checkIfSkipValidation(componentTypes[0], x);
}

@@ -952,4 +963,8 @@ }

}
return y.value();
}).map(function (y) { return typeExpressions.parseToType("" + y, r, n); });
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);

@@ -982,3 +997,5 @@ err.setValidationPath({ name: "items" });

else if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
result.addMeta(new meta.Annotation(key.substr(1, key.length - 2), x.value(), key));
var a = new meta.Annotation(key.substr(1, key.length - 2), x.value(), key);
a.setNode(x);
result.addMeta(a);
return;

@@ -1059,3 +1076,5 @@ }

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

@@ -1072,2 +1091,3 @@ }

actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals);
checkIfSkipValidation(actualResult, n);
return actualResult;

@@ -1074,0 +1094,0 @@ }

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

import { AbstractType } from "./typesystem";
import { Status } from "./typesystem";
export declare type IValidationPath = ts.IValidationPath;

@@ -22,3 +23,3 @@ /**

abstract propId(): string;
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(st: ts.Status, registry: ts.TypeRegistry): ts.Status;
range(): ts.AbstractType;

@@ -102,3 +103,3 @@ }

regexpValue(): string;
validateSelf(t: ts.TypeRegistry): ts.Status;
validateSelfIndividual(st: Status, t: ts.TypeRegistry): ts.Status;
checkValue(): any;

@@ -144,3 +145,3 @@ composeWith(t: ts.Constraint): ts.Constraint;

private checkOwner(requiredType);
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(superStatus: ts.Status, registry: ts.TypeRegistry): ts.Status;
}

@@ -272,3 +273,3 @@ /**

check(i: any): ts.Status;
validateSelf(registry: ts.TypeRegistry): ts.Status;
validateSelfIndividual(st: ts.Status, registry: ts.TypeRegistry): ts.Status;
composeWith(t: ts.Constraint): ts.Constraint;

@@ -275,0 +276,0 @@ checkValue(): ts.Status;

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

var metainfo_1 = require("./metainfo");
var metainfo_2 = require("./metainfo");
/**

@@ -86,3 +87,3 @@ * this class is an abstract super type for every constraint that can select properties from objects

};
MatchesProperty.prototype.validateSelf = function (registry) {
MatchesProperty.prototype.validateSelfIndividual = function (st, registry) {
return validatePropertyType(this._type, this.propId(), registry, this, false);

@@ -464,3 +465,3 @@ };

};
MapPropertyIs.prototype.validateSelf = function (t) {
MapPropertyIs.prototype.validateSelfIndividual = function (st, t) {
var m = this.checkValue();

@@ -470,3 +471,3 @@ if (m) {

}
return _super.prototype.validateSelf.call(this, t);
return _super.prototype.validateSelfIndividual.call(this, st, t);
};

@@ -654,2 +655,5 @@ MapPropertyIs.prototype.checkValue = function () {

FacetRestriction.prototype.checkOwner = function (requiredType) {
if (this.owner().oneMeta(metainfo_2.SkipValidation)) {
return true;
}
var ownerIsCorrect = false;

@@ -671,5 +675,4 @@ if (requiredType.isUnion()) {

};
FacetRestriction.prototype.validateSelf = function (registry) {
FacetRestriction.prototype.validateSelfIndividual = function (superStatus, registry) {
var _this = this;
var superStatus = _super.prototype.validateSelf.call(this, registry);
var ownerIsCorrect = false;

@@ -726,8 +729,27 @@ if (this.checkOwner(this.requiredType())) {

function is_int(value) {
if ((parseFloat(value) == parseInt(value)) && !isNaN(value)) {
return true;
if (typeof Number.isInteger == "function") {
return Number.isInteger(value);
}
else {
if (typeof value != "number" || isNaN(value)) {
return false;
}
var stringValue = "" + value;
var expInd = stringValue.indexOf("e");
var exp = 0;
var mantissa = stringValue;
if (expInd > 0) {
mantissa = stringValue.substring(0, expInd);
exp = parseInt(stringValue.substring(expInd + 1));
}
var dotInd = mantissa.indexOf(".");
var mantissaFractureLength = 0;
if (dotInd >= 0) {
mantissaFractureLength = mantissa.substring(dotInd + 1).length;
}
else {
for (var i = mantissa.length - 1; i >= 0 && mantissa.charAt(i) == '0'; i--) {
mantissaFractureLength--;
}
}
return exp >= mantissaFractureLength;
}

@@ -1134,5 +1156,4 @@ /**

};
ComponentShouldBeOfType.prototype.validateSelf = function (registry) {
ComponentShouldBeOfType.prototype.validateSelfIndividual = function (st, registry) {
var _this = this;
var st = _super.prototype.validateSelf.call(this, registry);
if (this.type.isAnonymous()) {

@@ -1161,7 +1182,7 @@ var typeStatus = this.type.validateType(registry);

}
else if (this.type.isSubTypeOf(ts.UNKNOWN) || this.type.isSubTypeOf(ts.RECURRENT)) {
else if (ts.isUnknown(this.type) || this.type.isSubTypeOf(ts.RECURRENT)) {
st.addSubStatus(ts.error(messageRegistry.UNKNOWN_ARRAY_COMPONENT_TYPE, this, { componentTypeName: this.type.name() }));
}
else if (this.type.isUnion()) {
var ui = _.find(this.type.typeFamily(), function (x) { return x.isSubTypeOf(ts.UNKNOWN); });
var ui = _.find(this.type.typeFamily(), function (x) { return ts.isUnknown(x); });
if (ui) {

@@ -1512,3 +1533,3 @@ st.addSubStatus(ts.error(messageRegistry.UNKNOWN_ARRAY_COMPONENT_TYPE, this, { componentTypeName: ui.name() }));

function actualUnknownType(t) {
if (!t.isSubTypeOf(ts.UNKNOWN)) {
if (!ts.isUnknown(t)) {
return null;

@@ -1541,3 +1562,3 @@ }

}
if (_type.isSubTypeOf(ts.UNKNOWN) || _type.isSubTypeOf(ts.RECURRENT)) {
if (ts.isUnknown(_type) || _type.isSubTypeOf(ts.RECURRENT)) {
var actualUnknown = actualUnknownType(_type);

@@ -1629,3 +1650,3 @@ var p = void 0;

if (_type.isUnion()) {
var ui = _.find(_type.typeFamily(), function (x) { return x.isSubTypeOf(ts.UNKNOWN); });
var ui = _.find(_type.typeFamily(), function (x) { return ts.isUnknown(x); });
if (ui) {

@@ -1632,0 +1653,0 @@ var p = void 0;

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

var jsonUtil = require("./jsonUtil");
var DOMParser = require('xmldom').DOMParser;
///var DOMParser = require('xmldom').DOMParser;
var ts = require("./typesystem");

@@ -591,2 +591,3 @@ var typesystem_1 = require("./typesystem");

try {
tryParseJSON(cnt, true);
var jsonObject = JSON.parse(cnt);

@@ -601,2 +602,3 @@ _this.setupId(jsonObject, _this.provider.normalizePath(reference));

content.reference = reference;
throw exception;
}

@@ -665,3 +667,3 @@ return content;

}
this.schemaString = this.handleReferenceElement(schema);
this.schemaString = schema;
}

@@ -694,3 +696,3 @@ XMLSchemaObject.prototype.getType = function () {

var doc;
doc = new DOMParser(domParserOptions).parseFromString(xmlString);
doc = "";
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

@@ -726,3 +728,3 @@ var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);

var doc;
doc = new DOMParser(domParserOptions).parseFromString(this.schemaString);
doc = "";
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

@@ -745,3 +747,3 @@ var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);

var doc;
doc = new DOMParser(domParserOptions).parseFromString(xmlString);
doc = "";
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

@@ -806,3 +808,3 @@ var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);

XMLSchemaObject.prototype.handleReferenceElement = function (content) {
var doc = new DOMParser(domParserOptions).parseFromString(content);
var doc = "";
this.namspacePrefix = extractNamespace(doc);

@@ -809,0 +811,0 @@ var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

@@ -73,18 +73,19 @@ export interface IValidationPath {

ImportedByChain = 2,
DisplayName = 3,
Usage = 4,
Annotation = 5,
FacetDeclaration = 6,
CustomFacet = 7,
Example = 8,
Required = 9,
HasPropertiesFacet = 10,
AllowedTargets = 11,
Examples = 12,
XMLInfo = 13,
Default = 14,
Constraint = 15,
Modifier = 16,
Discriminator = 17,
DiscriminatorValue = 18,
SkipValidation = 3,
DisplayName = 4,
Usage = 5,
Annotation = 6,
FacetDeclaration = 7,
CustomFacet = 8,
Example = 9,
Required = 10,
HasPropertiesFacet = 11,
AllowedTargets = 12,
Examples = 13,
XMLInfo = 14,
Default = 15,
Constraint = 16,
Modifier = 17,
Discriminator = 18,
DiscriminatorValue = 19,
}

@@ -91,0 +92,0 @@ /**

@@ -18,18 +18,19 @@ "use strict";

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

@@ -36,0 +37,0 @@ /**

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

validateSelf(registry: TypeRegistry): Status;
protected validateSelfIndividual(parentStatus: Status, registry: TypeRegistry): Status;
abstract facetName(): string;

@@ -233,3 +234,3 @@ abstract value(): any;

allSuperTypes(): AbstractType[];
private fillSuperTypes(r);
private fillSuperTypes(r, forValidation?);
allSubTypes(): AbstractType[];

@@ -742,1 +743,2 @@ private fillSubTypes(r);

export declare function toValidationPath(p: string): tsInterfaces.IValidationPath;
export declare function isUnknown(t: AbstractType): boolean;

@@ -1913,2 +1913,18 @@ "use strict";

});
it("multiple of (large numbers)", function () {
var st = {
types: {
t1: {
type: "number",
multipleOf: 0.001,
example: 777777777777777777777777777777777777777.777
},
}
};
var col = ps.parseJSONTypeCollection(st);
var t = col.getType("t1");
var status = t.validateType(ts.builtInRegistry());
var val = status.isOk();
assert.isTrue(val);
});
it("inline types", function () {

@@ -1915,0 +1931,0 @@ var st = {

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

@@ -16,13 +16,13 @@ "scripts": {

"dependencies": {
"date-and-time": "^0.3.0",
"date-and-time": "^0.5.0",
"json-schema-compatibility": "^1.1.0",
"json-to-ast": "^2.0.0-alpha1.2",
"lrucache": "^1.0.0",
"json-to-ast": "^2.0.0-alpha1.3",
"lrucache": "^1.0.3",
"underscore": "^1.8.3",
"xml2js": "^0.4.16",
"xmldom": "^0.1.22"
"xml2js": "^0.4.19",
"xmldom": "^0.1.27"
},
"optionalDependencies": {
"raml-xml-validation": "0.0.12",
"raml-json-validation": "0.0.13"
"raml-xml-validation": "0.0.13",
"raml-json-validation": "0.0.14"
},

@@ -53,13 +53,13 @@ "browser": {

"@types/xml2js": "0.4.0",
"chai": "^4.0.1",
"gulp": "^3.8.11",
"gulp-typedoc": "^1.2.1",
"istanbul": "^0.4.2",
"chai": "^4.1.2",
"gulp": "^3.9.1",
"gulp-typedoc": "^2.1.0",
"istanbul": "^0.4.5",
"mocha": "^3.4.2",
"typedoc": "^0.3.12",
"typescript": "2.5.2",
"dev-env-installer": "0.0.5",
"json-loader": "^0.5.1",
"dev-env-installer": "^0.0.14",
"json-loader": "^0.5.7",
"rimraf": "*"
}
}
# RAML Data Type System
[![Build Status](https://travis-ci.org/raml-org/typesystem-ts.svg?branch=master)](https://travis-ci.org/raml-org/typesystem-ts)
[![Build Status](https://travis-ci.org/raml-org/raml-typesystem.svg?branch=master)](https://travis-ci.org/raml-org/raml-typesystem)

@@ -5,0 +5,0 @@ This module contains a lightweight implementation of the type system that was introduced with [RAML 1.0](http://raml.org).

@@ -113,5 +113,18 @@ import rt=require("./typesystem")

private _isJSONString:boolean;
isJSONString():boolean {
if(this._isJSONString !== undefined){
return this._isJSONString;
}
this._isJSONString = false;
var ch = this.firstCharacter();
return ch == "{" || ch== "[";
if(ch == "{" || ch== "["){
try {
JSON.parse(this._value);
this._isJSONString = true;
}
catch(e){}
}
return this._isJSONString;
}

@@ -118,0 +131,0 @@

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

export class SkipValidation extends MetaInfo{
constructor(){
super("skipValidation", null, true);
}
kind() : tsInterfaces.MetaInformationKind {
return tsInterfaces.MetaInformationKind.SkipValidation;
}
}
export class DisplayName extends MetaInfo{

@@ -101,3 +112,3 @@

constructor(name: string,value:any,protected path:string){
constructor(name: string,value:any,protected path:string, protected ofExample=false){
super(name,value)

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

validateSelf(registry:ts.TypeRegistry,ofExample:boolean=false):ts.Status {
validateSelfIndividual(parentStatus:ts.Status,registry:ts.TypeRegistry):ts.Status {
var tp=registry.get(this.facetName());

@@ -138,3 +149,3 @@ if (!tp){

var aTargets = tp.metaOfType(AllowedTargets);
var contextTarget = ofExample ? "Example" : "TypeDeclaration";
var contextTarget = this.ofExample ? "Example" : "TypeDeclaration";
if(aTargets.length>0) {

@@ -159,3 +170,3 @@ var arr:string[] = [];

let chained = tp.metaOfType(ImportedByChain);
if(chained.length>0 && tp.isSubTypeOf(ts.UNKNOWN) && registry.getByChain(tp.name())){
if(chained.length>0 && ts.isUnknown(tp) && registry.getByChain(tp.name())){
let chainedType = chained[0].value();

@@ -236,3 +247,3 @@ res = ts.error(messageRegistry.LIBRARY_CHAINIG_IN_ANNOTATION_TYPE_SUPERTYPE,

validateSelf(registry:ts.TypeRegistry):ts.Status {
validateSelfIndividual(parentStatue:ts.Status,registry:ts.TypeRegistry):ts.Status {
return validatePropertyType(this._type,this.name,registry,this,false);

@@ -310,6 +321,6 @@ }

validateSelf(registry:ts.TypeRegistry):ts.Status {
var status = ts.ok();
validateSelfIndividual(parentStatus:ts.Status,registry:ts.TypeRegistry):ts.Status {
let status = ts.ok();
status.addSubStatus(this.validateValue(registry));
var aStatus = this.validateAnnotations(registry);
let aStatus = this.validateAnnotations(registry);
ts.setValidationPath(aStatus,{name:this.facetName()});

@@ -321,2 +332,5 @@ status.addSubStatus(aStatus);

validateValue(registry:ts.TypeRegistry):ts.Status {
if(this.owner().oneMeta(SkipValidation)){
return;
}
var val=this.value();

@@ -337,4 +351,4 @@ var isVal=false;

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key);
var aRes = a.validateSelf(registry, true);
var a = new Annotation(key.substring(1, key.length - 1), propObj[key], key, true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes,{

@@ -407,4 +421,4 @@ name: "example",

var aName = ua.substring(1,ua.length-1);
var aInstance = new Annotation(aName,aValue,ua);
status.addSubStatus(aInstance.validateSelf(registry,true));
var aInstance = new Annotation(aName,aValue,ua,true);
status.addSubStatus(aInstance.validateSelf(registry));
}

@@ -447,4 +461,3 @@ }

validateSelf(registry:ts.TypeRegistry):ts.Status {
var result = super.validateSelf(registry);
validateSelfIndividual(result:ts.Status,registry:ts.TypeRegistry):ts.Status {
if (typeof this.value()!=="boolean"){

@@ -524,3 +537,3 @@ result = ts.error(messageRegistry.REQUIRED_BOOLEAN,this);

validateSelf(registry:ts.TypeRegistry):ts.Status {
validateSelfIndividual(parentStatus:ts.Status,registry:ts.TypeRegistry):ts.Status {
if (typeof this.value()==='object'){

@@ -539,4 +552,4 @@ var rs=new Status(Status.OK,"","",this);

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), v[x][key],key);
var aRes = a.validateSelf(registry,true);
var a = new Annotation(key.substring(1, key.length - 1), v[x][key],key,true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes,

@@ -600,4 +613,4 @@ {name:"examples",child:{name: x, child: {name: key}}});

if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key],key);
var aRes = a.validateSelf(registry, true);
var a = new Annotation(key.substring(1, key.length - 1), exampleObj[propName][key],key,true);
var aRes = a.validateSelf(registry);
ts.setValidationPath(aRes,

@@ -652,4 +665,3 @@ {

validateSelf(registry:ts.TypeRegistry):ts.Status {
var result = super.validateSelf(registry);
validateSelfIndividual(result:ts.Status,registry:ts.TypeRegistry):ts.Status {
var valOwner=this.owner().validateDirect(this.value(),true);

@@ -685,4 +697,3 @@ if (!valOwner.isOk()){

validateSelf(registry:ts.TypeRegistry):ts.Status {
var result = super.validateSelf(registry);
validateSelfIndividual(result:ts.Status,registry:ts.TypeRegistry):ts.Status {
if (this.owner().isUnion()){

@@ -788,4 +799,3 @@ result = ts.error(messageRegistry.DISCRIMINATOR_FOR_UNION, this);

validateSelf(registry:ts.TypeRegistry):ts.Status {
var st = super.validateSelf(registry);
validateSelfIndividual(st:ts.Status,registry:ts.TypeRegistry):ts.Status {
if(this.strict) {

@@ -792,0 +802,0 @@ var ds = this.owner().oneMeta(Discriminator);

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

var aInstance = new meta.Annotation(aName, ch.value(), key);
aInstance.setNode(ch);
aInstance.setOwnerFacet(appendedInfo);

@@ -764,2 +765,9 @@ appendedInfo.addAnnotation(aInstance);

}
let checkIfSkipValidation = function (sp: AbstractType, n: ParseNode) {
if (n.getMeta("skipValidation")) {
sp.addMeta(new meta.SkipValidation());
}
};
/**

@@ -806,2 +814,3 @@ * parses a type from a JSON structure

if (name==null){
checkIfSkipValidation(sp, n);
return sp;

@@ -840,2 +849,3 @@ }

}
checkIfSkipValidation(res, n);
return res;

@@ -852,2 +862,3 @@ }

}
checkIfSkipValidation(res, n);
return res;

@@ -940,2 +951,3 @@ }

var aInstance = new meta.Annotation(aName, ann.value(), key);
aInstance.setNode(ann);
aiArr.push(aInstance);

@@ -996,2 +1008,3 @@ }

componentTypes=[typeExpressions.parseToType(""+valString,r, n)];
checkIfSkipValidation(componentTypes[0],x);
}

@@ -1015,4 +1028,8 @@ }

}
return y.value();
}).map(y=>typeExpressions.parseToType(""+y,r, n));
return y;
}).map(y=>{
let result = typeExpressions.parseToType(""+y.value(),r, n);
checkIfSkipValidation(result,y);
return result;
});

@@ -1046,3 +1063,5 @@ var err=ts.error(messageRegistry.ITEMS_SHOULD_BE_REFERENCE_OR_INLINE_TYPE,actualResult);

else if (key.charAt(0) == '(' && key.charAt(key.length - 1) == ')') {
result.addMeta(new meta.Annotation(key.substr(1, key.length - 2), x.value(), key));
let a = new meta.Annotation(key.substr(1, key.length - 2), x.value(), key);
a.setNode(x);
result.addMeta(a);
return;

@@ -1126,3 +1145,5 @@ }

if (result.superTypes().length==1){
return result.superTypes()[0];
let res = result.superTypes()[0];
checkIfSkipValidation(res, n);
return res;
}

@@ -1139,3 +1160,4 @@ }

actualResult.putExtra(tsInterfaces.HAS_FACETS, hasfacetsOrOtherStuffDoesNotAllowedInExternals);
checkIfSkipValidation(actualResult, n);
return actualResult;

@@ -1142,0 +1164,0 @@ }

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

import {ImportedByChain} from "./metainfo";
import {SkipValidation} from "./metainfo";
export type IValidationPath=ts.IValidationPath;

@@ -88,3 +89,3 @@ /**

validateSelf(registry:ts.TypeRegistry):ts.Status {
validateSelfIndividual(st:ts.Status,registry:ts.TypeRegistry):ts.Status {
return validatePropertyType(this._type,this.propId(),registry,this,false);

@@ -471,3 +472,3 @@ }

}
validateSelf(t:ts.TypeRegistry):ts.Status{
validateSelfIndividual(st:Status,t:ts.TypeRegistry):ts.Status{
var m=this.checkValue();

@@ -477,3 +478,3 @@ if (m){

}
return super.validateSelf(t);
return super.validateSelfIndividual(st,t);
}

@@ -664,2 +665,5 @@ checkValue(){

private checkOwner(requiredType : ts.AbstractType) : boolean {
if(this.owner().oneMeta(SkipValidation)){
return true;
}
var ownerIsCorrect = false;

@@ -683,5 +687,3 @@

validateSelf(registry:ts.TypeRegistry):ts.Status{
var superStatus = super.validateSelf(registry);
validateSelfIndividual(superStatus:ts.Status,registry:ts.TypeRegistry):ts.Status{
var ownerIsCorrect = false;

@@ -739,7 +741,27 @@ if (this.checkOwner(this.requiredType())) {

function is_int(value:any){
if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
return true;
} else {
if(typeof (<any>Number).isInteger == "function"){
return (<any>Number).isInteger(value);
}
if(typeof value != "number" || isNaN(value)){
return false;
}
let stringValue = ""+value;
let expInd = stringValue.indexOf("e");
let exp = 0;
let mantissa = stringValue;
if(expInd>0){
mantissa = stringValue.substring(0,expInd);
exp = parseInt(stringValue.substring(expInd+1));
}
let dotInd = mantissa.indexOf(".");
let mantissaFractureLength = 0;
if(dotInd>=0){
mantissaFractureLength = mantissa.substring(dotInd+1).length;
}
else{
for(let i = mantissa.length-1; i >= 0 && mantissa.charAt(i)=='0' ; i--){
mantissaFractureLength--;
}
}
return exp >= mantissaFractureLength;
}

@@ -1157,4 +1179,3 @@ /**

}
validateSelf(registry:ts.TypeRegistry):ts.Status {
var st = super.validateSelf(registry);
validateSelfIndividual(st:ts.Status,registry:ts.TypeRegistry):ts.Status {
if (this.type.isAnonymous()) {

@@ -1184,7 +1205,7 @@ var typeStatus = this.type.validateType(registry);

}
else if (this.type.isSubTypeOf(ts.UNKNOWN) || this.type.isSubTypeOf(ts.RECURRENT)) {
else if (ts.isUnknown(this.type) || this.type.isSubTypeOf(ts.RECURRENT)) {
st.addSubStatus(ts.error(messageRegistry.UNKNOWN_ARRAY_COMPONENT_TYPE,this,{ componentTypeName: this.type.name()}));
}
else if (this.type.isUnion()) {
var ui = _.find(this.type.typeFamily(), x=>x.isSubTypeOf(ts.UNKNOWN));
var ui = _.find(this.type.typeFamily(),x=>ts.isUnknown(x));
if (ui) {

@@ -1540,3 +1561,3 @@ st.addSubStatus(

if(!t.isSubTypeOf(ts.UNKNOWN)){
if(!ts.isUnknown(t)){
return null;

@@ -1574,3 +1595,3 @@ }

}
if (_type.isSubTypeOf(ts.UNKNOWN)||_type.isSubTypeOf(ts.RECURRENT)){
if (ts.isUnknown(_type)||_type.isSubTypeOf(ts.RECURRENT)){
var actualUnknown = actualUnknownType(_type);

@@ -1664,3 +1685,3 @@ let p:ts.Status;

if (_type.isUnion()){
var ui= _.find(_type.typeFamily(),x=>x.isSubTypeOf(ts.UNKNOWN));
var ui= _.find(_type.typeFamily(),x=>ts.isUnknown(x));
if (ui){let p:ts.Status;

@@ -1667,0 +1688,0 @@ if(isFacet) {

@@ -14,3 +14,3 @@ import {XMLSchemaReference} from "raml-xml-validation";

var DOMParser = require('xmldom').DOMParser;
///var DOMParser = require('xmldom').DOMParser;
import ts = require("./typesystem");

@@ -751,2 +751,3 @@ import {messageRegistry} from "./typesystem";

try {
tryParseJSON(cnt,true);
var jsonObject = JSON.parse(cnt);

@@ -764,2 +765,3 @@

content.reference = reference;
throw exception;
}

@@ -844,3 +846,3 @@

this.schemaString = this.handleReferenceElement(schema);
this.schemaString = schema;
}

@@ -886,3 +888,3 @@

doc = new DOMParser(domParserOptions).parseFromString(xmlString);
doc = "";

@@ -932,3 +934,3 @@ var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

doc = new DOMParser(domParserOptions).parseFromString(this.schemaString);
doc = "";

@@ -960,3 +962,3 @@ var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

doc = new DOMParser(domParserOptions).parseFromString(xmlString);
doc = "";

@@ -1048,3 +1050,3 @@ var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];

private handleReferenceElement(content: string): string {
var doc = new DOMParser(domParserOptions).parseFromString(content);
var doc = "";
this.namspacePrefix = extractNamespace(doc);

@@ -1051,0 +1053,0 @@

@@ -92,2 +92,3 @@ export interface IValidationPath{

ImportedByChain,
SkipValidation,
DisplayName,

@@ -94,0 +95,0 @@ Usage,

@@ -2169,2 +2169,22 @@ import ps= require("./actualParse")

it ("multiple of (large numbers)",function(){
var st={
types:{
t1:{
type:"number",
multipleOf: 0.001,
example: 777777777777777777777777777777777777777.777
},
}
};
var col=ps.parseJSONTypeCollection(st);
var t=col.getType("t1");
var status=t.validateType(ts.builtInRegistry());
var val=status .isOk();
assert.isTrue(val);
});
it ("inline types",function(){

@@ -2171,0 +2191,0 @@ var st={

@@ -13,6 +13,4 @@ {

"exclude": [
"node_modules",
"typings",
"custom_typings"
"node_modules"
]
}

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

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