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.61 to 0.0.62

2

dist/src/datetime.js

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

var r3 = /(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\,[ ]+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+\d{1,2}[ ]+\d{2}:\d{2}:\d{2}[ ]+GMT/;
var r0 = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.\d{1,3})?((?:[\+\-]\d{2}:\d{2})|Z)$/;
var r0 = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.\d+)?((?:[\+\-]\d{2}:\d{2})|Z)$/;
var DateTimeR = (function (_super) {

@@ -113,0 +113,0 @@ __extends(DateTimeR, _super);

@@ -73,3 +73,4 @@ "use strict";

new FacetPrototype(function () { return new restrictions_1.ComponentShouldBeOfType(ts.ANY); }, null),
new FacetPrototype(function () { return new restrictions_1.KnownPropertyRestriction(false); }, function (x) { return new restrictions_1.KnownPropertyRestriction(x); })
new FacetPrototype(function () { return new restrictions_1.KnownPropertyRestriction(false); }, function (x) { return new restrictions_1.KnownPropertyRestriction(x); }),
new FacetPrototype(function () { return new restrictions_1.FileTypes([""]); }, function (x) { return new restrictions_1.FileTypes(x); }),
];

@@ -76,0 +77,0 @@ this.meta = [

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

private optional;
constructor(name: string, _type: ts.AbstractType, optional: boolean);
private builtIn;
constructor(name: string, _type: ts.AbstractType, optional: boolean, builtIn?: boolean);
actualName(): string;

@@ -48,2 +49,3 @@ isOptional(): boolean;

kind(): tsInterfaces.MetaInformationKind;
isBuiltIn(): boolean;
}

@@ -50,0 +52,0 @@ export declare class CustomFacet extends MetaInfo {

@@ -143,3 +143,4 @@ "use strict";

__extends(FacetDeclaration, _super);
function FacetDeclaration(name, _type, optional) {
function FacetDeclaration(name, _type, optional, builtIn) {
if (builtIn === void 0) { builtIn = false; }
_super.call(this, name, _type, true);

@@ -149,2 +150,3 @@ this.name = name;

this.optional = optional;
this.builtIn = builtIn;
}

@@ -166,2 +168,5 @@ FacetDeclaration.prototype.actualName = function () {

};
FacetDeclaration.prototype.isBuiltIn = function () {
return this.builtIn;
};
return FacetDeclaration;

@@ -536,7 +541,12 @@ }(MetaInfo));

Default.prototype.validateSelf = function (registry) {
var _this = this;
var result = _super.prototype.validateSelf.call(this, registry);
var valOwner = this.owner().validateDirect(this.value(), true);
if (!valOwner.isOk()) {
result = ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this, { msg: valOwner.getMessage() });
ts.setValidationPath(result, { name: this.facetName() });
var c = ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this, { msg: valOwner.getMessage() });
valOwner.getErrors().forEach(function (x) {
c.addSubStatus(x);
ts.setValidationPath(x, { name: _this.facetName() });
});
result.addSubStatus(c);
}

@@ -621,4 +631,13 @@ return result;

if (i.hasOwnProperty(dName)) {
var queue = this.owner().allSubTypes().concat(this.owner());
var knownDiscriminatorValues = {};
for (var _i = 0, queue_1 = queue; _i < queue_1.length; _i++) {
var t = queue_1[_i];
var dvArr = t.metaOfType(DiscriminatorValue);
if (dvArr && dvArr.length > 0) {
dvArr.forEach(function (dv) { return knownDiscriminatorValues[dv.value()] = true; });
}
}
var adVal = i[dName];
if (adVal != dVal) {
if (!knownDiscriminatorValues[adVal]) {
var wrng = ts.error(typesystem_1.Status.CODE_INCORRECT_DISCRIMINATOR, this, {

@@ -625,0 +644,0 @@ rootType: owner.name(),

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

* @return map of fixed facet names to fixed facet values;
* @deprecated
*/

@@ -253,2 +254,8 @@ getFixedFacets(): {

*/
fixedFacets(): {
[name: string]: any;
};
/**
* @return map of facets fixed by the type and its supertypes
*/
allFixedFacets(): {

@@ -258,2 +265,14 @@ [name: string]: any;

/**
* @return map of built-in facets fixed by the type and its supertypes
*/
fixedBuiltInFacets(): {
[name: string]: any;
};
/**
* @return map of fixed built-in facet names to their values;
*/
allFixedBuiltInFacets(): {
[name: string]: any;
};
/**
* Print details of this type.

@@ -382,3 +401,3 @@ * Used mostly for debug and demosntration purposes.

/**
* return a pattern for a property name - used for a pattern properties
* return a pattern for a property name - used for pattern properties
*/

@@ -385,0 +404,0 @@ getKeyRegexp(): string;

@@ -88,3 +88,4 @@ import ti = require("./nominal-interfaces");

_requirements: ti.ValueRequirement[];
private fixedFacets;
private _fixedFacets;
private _fixedBuildInFacets;
hasArrayInHierarchy(): boolean;

@@ -96,12 +97,33 @@ arrayInHierarchy(): IArrayType;

hasUnionInHierarchy(): boolean;
fixFacet(name: string, v: any): void;
fixFacet(name: string, v: any, builtIn?: boolean): void;
protected _af: {
[name: string]: any;
};
protected _abf: {
[name: string]: any;
};
/**
* @deprecated
*/
getFixedFacets(): {
[name: string]: any;
};
fixedFacets(): {
[name: string]: any;
};
fixedBuiltInFacets(): {
[name: string]: any;
};
protected collectFixedFacets(builtIn: boolean): {
[name: string]: any;
};
allFixedFacets(): {
[name: string]: any;
};
allFixedBuiltInFacets(): {
[name: string]: any;
};
protected collectAllFixedFacets(builtIn: boolean): {
[name: string]: any;
};
protected contributeFacets(x: {

@@ -108,0 +130,0 @@ [name: string]: any;

@@ -132,3 +132,4 @@ "use strict";

this._requirements = [];
this.fixedFacets = {};
this._fixedFacets = {};
this._fixedBuildInFacets = {};
this.uc = false;

@@ -209,3 +210,3 @@ }

}
for (var x in this.getFixedFacets()) {
for (var x in this.fixedFacets()) {
delete n[x];

@@ -307,15 +308,44 @@ }

};
AbstractType.prototype.fixFacet = function (name, v) {
this.fixedFacets[name] = v;
AbstractType.prototype.fixFacet = function (name, v, builtIn) {
if (builtIn === void 0) { builtIn = false; }
if (builtIn) {
this._fixedBuildInFacets[name] = v;
}
else {
this._fixedFacets[name] = v;
}
};
/**
* @deprecated
*/
AbstractType.prototype.getFixedFacets = function () {
var mm = {};
for (var q in this.fixedFacets) {
mm[q] = this.fixedFacets[q];
return this.fixedFacets();
};
AbstractType.prototype.fixedFacets = function () {
return this.collectFixedFacets(false);
};
AbstractType.prototype.fixedBuiltInFacets = function () {
return this.collectFixedFacets(true);
};
AbstractType.prototype.collectFixedFacets = function (builtIn) {
var facetsMap = builtIn ? this._fixedBuildInFacets : this._fixedFacets;
var result = {};
for (var _i = 0, _a = Object.keys(facetsMap); _i < _a.length; _i++) {
var q = _a[_i];
result[q] = facetsMap[q];
}
this.contributeFacets(mm);
return mm;
this.contributeFacets(result);
return result;
};
AbstractType.prototype.allFixedFacets = function () {
if (this._af) {
return this.collectAllFixedFacets(false);
};
AbstractType.prototype.allFixedBuiltInFacets = function () {
return this.collectAllFixedFacets(true);
};
AbstractType.prototype.collectAllFixedFacets = function (builtIn) {
if (builtIn && this._abf) {
return this._abf;
}
else if (!builtIn && this._af) {
return this._af;

@@ -327,3 +357,3 @@ }

sp.forEach(function (x) {
var ff = x.getFixedFacets();
var ff = builtIn ? x.fixedBuiltInFacets() : x.fixedFacets();
for (var _i = 0, _a = Object.keys(ff); _i < _a.length; _i++) {

@@ -503,4 +533,8 @@ var key = _a[_i];

return true;
if (this.getFixedFacets() && Object.keys(this.getFixedFacets()).length > 0)
var facets = this.fixedFacets();
if (facets && Object.keys(facets).length > 0)
return true;
var builtInFacets = this.fixedBuiltInFacets();
if (builtInFacets && Object.keys(builtInFacets).length > 0)
return true;
return this.isTopLevel() && this.nameId() && this.nameId().length > 0;

@@ -507,0 +541,0 @@ };

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

var restrictions = require("./restrictions");
var reg = require("./facetRegistry");
var metainfo = require("./metainfo");
var _ = require("underscore");
var NOMINAL = "nominal";

@@ -117,3 +120,4 @@ var pc;

proto.properties.forEach(function (x) {
var prop = pc ? pc(x.id) : new nt.Property(x.id);
var propName = x.regExp ? "/" + x.id + "/" : x.id;
var prop = pc ? pc(propName) : new nt.Property(propName);
prop.withDomain(vs);

@@ -124,4 +128,7 @@ prop.withRange(toNominal(x.type, callback));

}
if (x.regExp) {
prop.withKeyRegexp(propName);
}
});
proto.facetDeclarations.forEach(function (x) {
proto.facetDeclarations.filter(function (x) { return !x.isBuiltIn(); }).forEach(function (x) {
var prop = pc ? pc(x.facetName()) : new nt.Property(x.facetName());

@@ -134,6 +141,42 @@ prop.withRange(toNominal(x.type(), callback));

});
var basicFacets = t.metaOfType(restrictions.FacetRestriction);
var skipped = {
"example": true,
"examples": true
};
var basicFacets = t.meta()
.filter(function (x) {
if (!(x instanceof metainfo.Discriminator) && !(x instanceof metainfo.DiscriminatorValue)) {
if (!(x instanceof restrictions.FacetRestriction)
&& !(x instanceof metainfo.MetaInfo)
&& !(x instanceof restrictions.KnownPropertyRestriction)) {
return false;
}
if (x instanceof metainfo.FacetDeclaration || x instanceof metainfo.CustomFacet) {
return false;
}
}
var rt = x.requiredType();
var trArr = rt.isUnion() ? rt.allOptions() : [rt];
if (!_.some(trArr, function (y) { return t.isSubTypeOf(y); })) {
return false;
}
var n = x.facetName();
if (skipped[n]) {
return false;
}
if (n == "discriminatorValue") {
return x.isStrict();
}
if (n == "allowedTargets") {
return true;
}
return reg.getInstance().facetPrototypeWithName(n) != null;
});
for (var _i = 0, basicFacets_1 = basicFacets; _i < basicFacets_1.length; _i++) {
var x = basicFacets_1[_i];
vs.fixFacet(x.facetName(), x.value());
var n = x.facetName();
if (n == "closed") {
n = "additionalProperties";
}
vs.fixFacet(n, x.value(), true);
}

@@ -140,0 +183,0 @@ vs.addAdapter(t);

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

}
export declare class FileTypes extends FacetRestriction<string[]> {
private _value;
constructor(_value: string[]);
facetName(): string;
requiredType(): ts.InheritedType;
check(i: any): ts.Status;
composeWith(r: ts.Constraint): ts.Constraint;
value(): string[];
checkValue(): ts.Status;
toString(): string;
}
/**

@@ -276,0 +287,0 @@ * regular expression (pattern) constraint

@@ -1184,2 +1184,45 @@ "use strict";

exports.Pattern = Pattern;
var FileTypes = (function (_super) {
__extends(FileTypes, _super);
function FileTypes(_value) {
_super.call(this);
this._value = _value;
}
FileTypes.prototype.facetName = function () { return "fileTypes"; };
FileTypes.prototype.requiredType = function () { return ts.FILE; };
FileTypes.prototype.check = function (i) {
if (!Array.isArray(i)) {
return ts.error(messageRegistry.FILE_TYPES_SHOULD_BE_AN_ARRAY, this);
}
for (var _i = 0, i_1 = i; _i < i_1.length; _i++) {
var s = i_1[_i];
if (typeof (s) != "string") {
return ts.error(messageRegistry.FILE_TYPES_SHOULD_BE_AN_ARRAY, this);
}
}
return ts.ok();
};
FileTypes.prototype.composeWith = function (r) {
if (r instanceof FileTypes) {
var v = r;
var arr = _.intersection(this._value, v._value);
if (arr.length > 0) {
return new FileTypes(arr);
}
return this.nothing(r, "no common file types");
}
return null;
};
FileTypes.prototype.value = function () {
return this._value;
};
FileTypes.prototype.checkValue = function () {
return ts.ok();
};
FileTypes.prototype.toString = function () {
return "supported file types: " + this._value.join(", ");
};
return FileTypes;
}(FacetRestriction));
exports.FileTypes = FileTypes;
/**

@@ -1186,0 +1229,0 @@ * regular expression (pattern) constraint

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

private extraElementData;
private namspacePrefix;
references: any;

@@ -50,0 +51,0 @@ constructor(schema: string, provider: IContentProvider);

@@ -18,11 +18,44 @@ /// <reference path="../typings/main.d.ts" />

var useLint = true;
var CACHE_SIZE_BARRIER = 5 * 1024 * 1024;
var ErrorsCache = (function () {
function ErrorsCache() {
this.errors = {};
this.size = 0;
}
ErrorsCache.prototype.getValue = function (key) {
return this.errors[key];
var e = this.errors[key];
if (!e) {
return null;
}
return e.value;
};
ErrorsCache.prototype.setValue = function (key, value) {
this.errors[key] = value;
var e = this.errors[key];
if (!e) {
e = {
key: key,
value: value
};
if (this.top) {
this.top.next = e;
}
this.top = e;
if (!this.last) {
this.last = e;
}
this.errors[key] = e;
this.size += key.length;
while (this.size > CACHE_SIZE_BARRIER) {
if (!this.last) {
break;
}
var k = this.last.key;
delete this.errors[k];
this.size -= k.length;
this.last = this.last.next;
}
}
else {
e.value = value;
}
};

@@ -385,5 +418,5 @@ return ErrorsCache;

doc = new DOMParser().parseFromString(xmlString);
var schema = elementChildrenByName(doc, 'xs:schema')[0];
var imports = elementChildrenByName(schema, 'xs:import');
var includes = elementChildrenByName(schema, 'xs:include');
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes = elementChildrenByName(schema, 'include', this.namspacePrefix);
var refElements = imports.concat(includes);

@@ -417,5 +450,5 @@ refElements.forEach(function (refElement) {

doc = new DOMParser().parseFromString(this.schemaString);
var schema = elementChildrenByName(doc, 'xs:schema')[0];
var imports = elementChildrenByName(schema, 'xs:import');
var includes = elementChildrenByName(schema, 'xs:include');
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes = elementChildrenByName(schema, 'include', this.namspacePrefix);
var refElements = imports.concat(includes);

@@ -436,5 +469,5 @@ var result = [];

doc = new DOMParser().parseFromString(xmlString);
var schema = elementChildrenByName(doc, 'xs:schema')[0];
var imports = elementChildrenByName(schema, 'xs:import');
var includes = elementChildrenByName(schema, 'xs:include');
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes = elementChildrenByName(schema, 'include', this.namspacePrefix);
var refElements = imports.concat(includes);

@@ -497,4 +530,5 @@ return Promise.all(refElements.map(function (refElement) {

var doc = new DOMParser().parseFromString(content);
var schema = elementChildrenByName(doc, 'xs:schema')[0];
var elements = elementChildrenByName(schema, 'xs:element');
this.namspacePrefix = extractNamespace(doc);
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var elements = elementChildrenByName(schema, 'element', this.namspacePrefix);
var element = _.find(elements, function (element) { return element.getAttribute('extraelement') === 'true'; });

@@ -596,4 +630,10 @@ if (!element) {

exports.createSchema = createSchema;
function elementChildrenByName(parent, tagName) {
var elements = parent.getElementsByTagName(tagName);
function elementChildrenByName(parent, tagName, ns) {
if (ns == null) {
ns = extractNamespace(parent);
}
if (ns.length > 0) {
ns += ":";
}
var elements = parent.getElementsByTagName(ns + tagName);
var result = [];

@@ -608,2 +648,18 @@ for (var i = 0; i < elements.length; i++) {

}
function extractNamespace(documentOrElement) {
var ns = "";
if (documentOrElement) {
var doc = documentOrElement;
if (documentOrElement.ownerDocument) {
doc = documentOrElement.ownerDocument;
}
if (doc) {
var docElement = doc.documentElement;
if (docElement) {
ns = docElement.prefix;
}
}
}
return ns;
}
//# sourceMappingURL=schemaUtil.js.map
/// <reference path="../../typings/main.d.ts" />
import { XMLValidator } from "raml-xml-validation";
export declare function getValidator(arg: string): XMLValidator;
export declare function jsonToXml(jsonObject: any): string;
export declare function jsonToXml(jsonObject: any): any;

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

var root = object[nodeName];
if (nodeName == "#text") {
return root;
}
if (!root && root !== '') {

@@ -28,0 +31,0 @@ return '';

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

it("All facets", function () {
assert.equal(facetRegistry.getInstance().allPrototypes().length, 31);
// assert.equal(facetRegistry.getInstance().allPrototypes().length,30);
assert.equal(facetRegistry.getInstance().allPrototypes().length, 32);
});

@@ -510,0 +509,0 @@ it("All object facets", function () {

@@ -1630,2 +1630,16 @@ "use strict";

});
it("datetime rfc3339 positive 4", function () {
var st = {
types: {
t1: {
type: "datetime",
example: "2016-02-28T16:41:41.090123-10:30"
},
}
};
var col = ps.parseJSONTypeCollection(st);
var t = col.getType("t1");
var val = t.validateType(ts.builtInRegistry()).isOk();
assert.isTrue(val);
});
it("datetime format rfc2616", function () {

@@ -1632,0 +1646,0 @@ var st = {

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

var nt = nm.toNominal(tp, function (x) { return null; });
assert.isTrue(nt.getFixedFacets()["rr"] == 3);
assert.isTrue(nt.fixedFacets()["rr"] == 3);
});

@@ -121,0 +121,0 @@ it("is External", function () {

@@ -540,2 +540,19 @@ "use strict";

});
it("validating - default 3", function () {
var tp = ps.parseJSONTypeCollection({
types: {
MyType: {
"properties": {
"p1": "string"
},
default: {
"p1": "stringValue",
"p2": 5,
}
}
}
});
var st = tp.getType("MyType").validateType(ts.builtInRegistry());
assert.isTrue(st.isWarning());
});
it("validating - example", function () {

@@ -889,2 +906,21 @@ var tp = ps.parseJSONTypeCollection({

});
it("validating - facet fixed by declaring type", function () {
var tp = ps.parseJSONTypeCollection({
types: {
MyNumber: {
type: "object",
properties: {
x: "number",
y: "number",
},
facets: {
"tp": "number"
},
tp: 5
}
}
});
var st = tp.getType("MyNumber").validateType(ts.builtInRegistry());
assert.isTrue(!st.isOk());
});
it("validating - redeclare builtin", function () {

@@ -891,0 +927,0 @@ var tp = ps.parseJSONTypeCollection({

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

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

"optionalDependencies": {
"raml-xml-validation": "0.0.10",
"raml-xml-validation": "0.0.11",
"raml-json-validation": "0.0.11"

@@ -28,0 +28,0 @@ },

@@ -393,3 +393,11 @@ {

"message": "Can not parse schema"
},
"FILE_TYPES_SHOULD_BE_AN_ARRAY" : {
"code" : "FILE_TYPES_SHOULD_BE_AN_ARRAY",
"message": "'fileTypes' value should be an array of strings"
},
"FACET_CAN_NOT_BE_FIXED_BY_THE_DECLARING_TYPE" : {
"code" : "FACET_CAN_NOT_BE_FIXED_BY_THE_DECLARING_TYPE",
"message": "A facet can not be fixed by the declaring type"
}
}

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

var r0=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.\d{1,3})?((?:[\+\-]\d{2}:\d{2})|Z)$/;
var r0=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.\d+)?((?:[\+\-]\d{2}:\d{2})|Z)$/;
export class DateTimeR extends ts.GenericTypeOf{

@@ -106,0 +106,0 @@ check(value:any):ts.Status {

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

PropertyIs, AdditionalPropertyIs , MapPropertyIs, HasProperty,
KnownPropertyRestriction, ComponentShouldBeOfType, Format} from "./restrictions";
KnownPropertyRestriction, ComponentShouldBeOfType, Format, FileTypes} from "./restrictions";

@@ -85,3 +85,4 @@ import {Default, Example, Description, DisplayName} from "./metainfo";

new FacetPrototype(()=>new ComponentShouldBeOfType(ts.ANY), null),//X
new FacetPrototype(()=>new KnownPropertyRestriction(false), (x)=>new KnownPropertyRestriction(<boolean>x))
new FacetPrototype(()=>new KnownPropertyRestriction(false), (x)=>new KnownPropertyRestriction(<boolean>x)),
new FacetPrototype(()=>new FileTypes([""]), (x)=>new FileTypes(x)),//X
];

@@ -88,0 +89,0 @@

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

constructor(private name: string,private _type:ts.AbstractType,private optional:boolean){
constructor(
private name: string,
private _type:ts.AbstractType,
private optional:boolean,
private builtIn = false){
super(name,_type,true)

@@ -158,2 +162,6 @@ }

}
isBuiltIn():boolean{
return this.builtIn;
}
}

@@ -560,4 +568,7 @@ export class CustomFacet extends MetaInfo{

if (!valOwner.isOk()){
result = ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this , { msg : valOwner.getMessage() });
ts.setValidationPath(result,{name:this.facetName()});
var c = ts.error(messageRegistry.INVALID_DEFAULT_VALUE, this, { msg : valOwner.getMessage() });
valOwner.getErrors().forEach(x=>{c.addSubStatus(x);
ts.setValidationPath(x,{name:this.facetName()});
});
result.addSubStatus(c);
}

@@ -640,4 +651,12 @@ return result;

if (i.hasOwnProperty(dName)) {
var queue = this.owner().allSubTypes().concat(this.owner());
var knownDiscriminatorValues:any = {};
for(var t of queue){
let dvArr = t.metaOfType(DiscriminatorValue);
if(dvArr && dvArr.length >0){
dvArr.forEach(dv=>knownDiscriminatorValues[dv.value()] = true);
}
}
var adVal = i[dName];
if (adVal != dVal) {
if (!knownDiscriminatorValues[adVal]) {
var wrng = ts.error(Status.CODE_INCORRECT_DISCRIMINATOR, this, {

@@ -644,0 +663,0 @@ rootType : owner.name(),

@@ -295,4 +295,5 @@ import tsInterfaces = require("./typesystem-interfaces")

/**
/**
* @return map of fixed facet names to fixed facet values;
* @deprecated
*/

@@ -304,5 +305,20 @@ getFixedFacets():{ [name:string]:any};

*/
fixedFacets():{ [name:string]:any};
/**
* @return map of facets fixed by the type and its supertypes
*/
allFixedFacets():{ [name:string]:any};
/**
* @return map of built-in facets fixed by the type and its supertypes
*/
fixedBuiltInFacets():{ [name:string]:any};
/**
* @return map of fixed built-in facet names to their values;
*/
allFixedBuiltInFacets():{ [name:string]:any};
/**
* Print details of this type.

@@ -448,3 +464,3 @@ * Used mostly for debug and demosntration purposes.

/**
* return a pattern for a property name - used for a pattern properties
* return a pattern for a property name - used for pattern properties
*/

@@ -451,0 +467,0 @@ getKeyRegexp():string;

@@ -230,3 +230,3 @@ import ti = require("./nominal-interfaces")

}
for (var x in this.getFixedFacets()){
for (var x in this.fixedFacets()){
delete n[x];

@@ -284,5 +284,7 @@ }

private fixedFacets:{ [name:string]:any}={}
private _fixedFacets:{ [name:string]:any}={}
private _fixedBuildInFacets:{ [name:string]:any}={}
hasArrayInHierarchy(){

@@ -348,4 +350,9 @@ var arr =_.find(this.allSuperTypes(),x=>x instanceof Array)!=null;

fixFacet(name:string,v: any){
this.fixedFacets[name]=v;
fixFacet(name:string,v: any, builtIn=false){
if(builtIn){
this._fixedBuildInFacets[name]=v;
}
else{
this._fixedFacets[name]=v;
}
}

@@ -355,13 +362,42 @@

protected _abf:{ [name:string]:any};
/**
* @deprecated
*/
getFixedFacets():{ [name:string]:any}{
var mm:{ [name:string]:any}={};
for (var q in this.fixedFacets){
mm[q]=this.fixedFacets[q];
return this.fixedFacets();
}
fixedFacets():{ [name:string]:any}{
return this.collectFixedFacets(false);
}
fixedBuiltInFacets():{ [name:string]:any}{
return this.collectFixedFacets(true);
}
protected collectFixedFacets(builtIn:boolean):{ [name:string]:any}{
var facetsMap = builtIn ? this._fixedBuildInFacets : this._fixedFacets;
var result:{ [name:string]:any}={};
for (var q of Object.keys(facetsMap)){
result[q]=facetsMap[q];
}
this.contributeFacets(mm);
return mm;
this.contributeFacets(result);
return result;
}
allFixedFacets():{ [name:string]:any}{
if (this._af){
return this.collectAllFixedFacets(false);
}
allFixedBuiltInFacets():{ [name:string]:any}{
return this.collectAllFixedFacets(true);
}
protected collectAllFixedFacets(builtIn:boolean):{ [name:string]:any}{
if (builtIn && this._abf){
return this._abf;
}
else if (!builtIn && this._af){
return this._af;

@@ -373,3 +409,3 @@ }

sp.forEach(x=>{
var ff = x.getFixedFacets();
var ff = builtIn ? x.fixedBuiltInFacets() : x.fixedFacets();
for( var key of Object.keys(ff)){

@@ -591,4 +627,8 @@ mm[key] = ff[key];

if (this.getFixedFacets() && Object.keys(this.getFixedFacets()).length > 0) return true;
var facets = this.fixedFacets();
if (facets && Object.keys(facets).length > 0) return true;
var builtInFacets = this.fixedBuiltInFacets();
if (builtInFacets && Object.keys(builtInFacets).length > 0) return true;
return this.isTopLevel()&&this.nameId()&&this.nameId().length>0;

@@ -595,0 +635,0 @@ }

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

import restrictions = require("./restrictions");
import {FacetDeclaration} from "./metainfo";
import {Description} from "./metainfo";
import {DisplayName} from "./metainfo";
import reg = require("./facetRegistry");
import metainfo = require("./metainfo");
import _ = require("underscore");

@@ -139,3 +139,4 @@ const NOMINAL="nominal"

proto.properties.forEach(x=>{
var prop=pc?pc(x.id):new nt.Property(x.id);
var propName = x.regExp ? `/${x.id}/` : x.id;
var prop=pc ? pc(propName):new nt.Property(propName);
prop.withDomain(<nt.StructuredType>vs);

@@ -146,4 +147,7 @@ prop.withRange(toNominal(x.type,callback));

}
if(x.regExp){
prop.withKeyRegexp(propName);
}
});
proto.facetDeclarations.forEach(x=>{
proto.facetDeclarations.filter(x=>!x.isBuiltIn()).forEach(x=>{
var prop=pc?pc(x.facetName()):new nt.Property(x.facetName());

@@ -157,7 +161,43 @@ prop.withRange(toNominal(x.type(),callback));

});
var basicFacets = <restrictions.FacetRestriction<any>[]>
t.metaOfType(<any>restrictions.FacetRestriction);
var skipped:any = {
"example": true,
"examples": true
};
var basicFacets = <restrictions.FacetRestriction<any>[]>t.meta()
.filter(x=> {
if (!(x instanceof metainfo.Discriminator) && !(x instanceof metainfo.DiscriminatorValue)) {
if (!(x instanceof restrictions.FacetRestriction)
&& !(x instanceof metainfo.MetaInfo)
&& !(x instanceof restrictions.KnownPropertyRestriction)) {
return false;
}
if (x instanceof metainfo.FacetDeclaration || x instanceof metainfo.CustomFacet) {
return false;
}
}
var rt = x.requiredType();
var trArr = rt.isUnion() ? (<ts.UnionType>rt).allOptions() : [rt];
if (!_.some(trArr, y=>t.isSubTypeOf(y))) {
return false;
}
var n = x.facetName();
if (skipped[n]) {
return false;
}
if (n == "discriminatorValue") {
return (<metainfo.DiscriminatorValue>x).isStrict();
}
if (n == "allowedTargets") {
return true;
}
return reg.getInstance().facetPrototypeWithName(n) != null;
});
for(var x of basicFacets){
vs.fixFacet(x.facetName(), x.value());
var n = x.facetName();
if(n == "closed"){
n = "additionalProperties";
}
vs.fixFacet(n, x.value(),true);
}

@@ -164,0 +204,0 @@ vs.addAdapter(t);

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

export class FileTypes extends FacetRestriction<string[]>{
constructor(private _value:string[]){
super();
}
facetName(){return "fileTypes"}
requiredType(){return ts.FILE}
check(i:any):ts.Status{
if (!Array.isArray(i)) {
return ts.error(messageRegistry.FILE_TYPES_SHOULD_BE_AN_ARRAY,this);
}
for(var s of i){
if(typeof(s) != "string"){
return ts.error(messageRegistry.FILE_TYPES_SHOULD_BE_AN_ARRAY,this);
}
}
return ts.ok()
}
composeWith(r:ts.Constraint):ts.Constraint{
if (r instanceof FileTypes){
var v=<FileTypes>r;
var arr = _.intersection(this._value, v._value);
if(arr.length>0){
return new FileTypes(arr);
}
return this.nothing(r,"no common file types");
}
return null;
}
value(){
return this._value;
}
checkValue():ts.Status{
return ts.ok();
}
toString(){
return "supported file types: " + this._value.join(", ");
}
}
/**

@@ -1219,0 +1264,0 @@ * regular expression (pattern) constraint

@@ -27,14 +27,60 @@ /// <reference path="../typings/main.d.ts" />

var CACHE_SIZE_BARRIER = 5*1024*1024;
class ErrorsCache {
errors: any = {};
errors:{[key:string]:ErrorsEntry} = {};
last:ErrorsEntry;
top:ErrorsEntry;
size:number = 0;
getValue(key: any): any {
return <any>this.errors[key];
var e = this.errors[key];
if(!e){
return null;
}
return e.value;
}
setValue(key: any, value: any) {
this.errors[key] = value;
var e = this.errors[key];
if(!e){
e = {
key: key,
value: value
};
if(this.top) {
this.top.next = e;
}
this.top = e;
if(!this.last){
this.last = e;
}
this.errors[key] = e;
this.size += key.length;
while(this.size > CACHE_SIZE_BARRIER){
if(!this.last){
break;
}
var k = this.last.key;
delete this.errors[k];
this.size -= k.length;
this.last = this.last.next;
}
}
else{
e.value = value;
}
}
}
interface ErrorsEntry{
value:any;
key:string;
next?:ErrorsEntry;
}
var globalCache = new ErrorsCache();

@@ -464,2 +510,4 @@

private extraElementData: any = null;
private namspacePrefix:string;

@@ -520,6 +568,6 @@ references: any = {};

var schema = elementChildrenByName(doc, 'xs:schema')[0];
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports: any[] = elementChildrenByName(schema, 'xs:import');
var includes: any[] = elementChildrenByName(schema, 'xs:include');
var imports: any[] = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes: any[] = elementChildrenByName(schema, 'include', this.namspacePrefix);

@@ -566,6 +614,6 @@ var refElements: any = imports.concat(includes);

var schema = elementChildrenByName(doc, 'xs:schema')[0];
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports: any[] = elementChildrenByName(schema, 'xs:import');
var includes: any[] = elementChildrenByName(schema, 'xs:include');
var imports: any[] = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes: any[] = elementChildrenByName(schema, 'include', this.namspacePrefix);

@@ -594,6 +642,6 @@ var refElements: any = imports.concat(includes);

var schema = elementChildrenByName(doc, 'xs:schema')[0];
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var imports: any[] = elementChildrenByName(schema, 'xs:import');
var includes: any[] = elementChildrenByName(schema, 'xs:include');
var imports: any[] = elementChildrenByName(schema, 'import', this.namspacePrefix);
var includes: any[] = elementChildrenByName(schema, 'include', this.namspacePrefix);

@@ -681,6 +729,7 @@ var refElements: any = imports.concat(includes);

var doc = new DOMParser().parseFromString(content);
this.namspacePrefix = extractNamespace(doc);
var schema = elementChildrenByName(doc, 'xs:schema')[0];
var schema = elementChildrenByName(doc, 'schema', this.namspacePrefix)[0];
var elements:any[] = elementChildrenByName(schema, 'xs:element');
var elements:any[] = elementChildrenByName(schema, 'element', this.namspacePrefix);

@@ -798,5 +847,13 @@ var element = _.find(elements, (element:any) => element.getAttribute('extraelement') === 'true');

function elementChildrenByName(parent: any, tagName: string): any[] {
var elements = parent.getElementsByTagName(tagName);
function elementChildrenByName(parent: any, tagName: string, ns:string): any[] {
if(ns==null) {
ns = extractNamespace(parent);
}
if(ns.length>0){
ns += ":";
}
var elements = parent.getElementsByTagName(ns+tagName);
var result: any[] = [];

@@ -813,2 +870,19 @@

return result;
}
function extractNamespace(documentOrElement:any){
var ns = "";
if(documentOrElement) {
var doc = documentOrElement;
if (documentOrElement.ownerDocument) {
doc = documentOrElement.ownerDocument;
}
if (doc) {
var docElement = doc.documentElement;
if (docElement) {
ns = docElement.prefix;
}
}
}
return ns;
}

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

var root = object[nodeName];
if(nodeName=="#text"){
return root;
}

@@ -36,0 +39,0 @@ if(!root && root !== '') {

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

it ("All facets",function (){
assert.equal(facetRegistry.getInstance().allPrototypes().length,31);
// assert.equal(facetRegistry.getInstance().allPrototypes().length,30);
assert.equal(facetRegistry.getInstance().allPrototypes().length,32);
});

@@ -520,0 +519,0 @@ it ("All object facets",function (){

@@ -1823,2 +1823,20 @@ import ps= require("./actualParse")

it ("datetime rfc3339 positive 4",function(){
var st={
types:{
t1:{
type:"datetime",
example: "2016-02-28T16:41:41.090123-10:30"
},
}
};
var col=ps.parseJSONTypeCollection(st);
var t=col.getType("t1");
var val= t.validateType(ts.builtInRegistry()).isOk();
assert.isTrue(val);
});
it ("datetime format rfc2616",function(){

@@ -1825,0 +1843,0 @@ var st={

@@ -123,3 +123,3 @@ import ps= require("./actualParse")

assert.isTrue(nt.getFixedFacets()["rr"]==3);
assert.isTrue(nt.fixedFacets()["rr"]==3);
});

@@ -126,0 +126,0 @@ it("is External", function () {

@@ -545,2 +545,19 @@ import ps= require("./actualParse")

});
it("validating - default 3", function () {
var tp = ps.parseJSONTypeCollection({
types: {
MyType:{
"properties" : {
"p1": "string"
},
default: {
"p1": "stringValue",
"p2": 5,
}
}
}
})
var st= tp.getType("MyType").validateType(ts.builtInRegistry());
assert.isTrue(st.isWarning());
});
it("validating - example", function () {

@@ -906,2 +923,21 @@ var tp = ps.parseJSONTypeCollection({

});
it("validating - facet fixed by declaring type", function () {
var tp = ps.parseJSONTypeCollection({
types: {
MyNumber:{
type: "object",
properties:{
x: "number",
y: "number",
},
facets: {
"tp": "number"
},
tp: 5
}
}
});
var st= tp.getType("MyNumber").validateType(ts.builtInRegistry());
assert.isTrue(!st.isOk());
});
it("validating - redeclare builtin", function () {

@@ -908,0 +944,0 @@ var tp = ps.parseJSONTypeCollection({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is 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

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