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.36 to 0.0.37

dist/src/typeExpressionUtil.d.ts

1

dist/src/index.d.ts
import tsInterfaces = require("./typesystem-interfaces");
export import nominalTypes = require("./nominal-types");
export import typeExpressions = require("./typeExpressionUtil");
export declare type IValidationPath = tsInterfaces.IValidationPath;

@@ -4,0 +5,0 @@ export declare type IHasExtra = tsInterfaces.IHasExtra;

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

exports.nominalTypes = require("./nominal-types");
exports.typeExpressions = require("./typeExpressionUtil");
var schemaUtil = require('./schemaUtil');

@@ -14,0 +15,0 @@ exports.TOP_LEVEL_EXTRA = tsInterfaces.TOP_LEVEL_EXTRA;

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

actualResult.addMeta(new restrictions_1.ComponentShouldBeOfType(tp));
actualResult.putExtra(tsInterfaces.HAS_ITEMS, true);
return;

@@ -680,0 +681,0 @@ }

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

var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "property " + this.propId() + " refers to unknown type " + this._type.name(), this);
p.setValidationPath({ name: this.propId() });
p.setValidationPath({ name: this.propId(), child: { name: "type" } });
return p;

@@ -86,2 +86,3 @@ }

var p = new typesystem_2.Status(typesystem_2.Status.ERROR, 0, "property " + this.propId() + " range type has error:" + st.getMessage(), this);
st.getErrors().forEach(function (y) { p.addSubStatus(y); });
p.setValidationPath({ name: this.propId() });

@@ -897,2 +898,9 @@ return p;

var ss = this.type.validate(ar[j], true);
if (!ss.isOk()) {
var t = this.type;
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);
return s;
}
}
ss.setValidationPath({ name: "" + j });

@@ -899,0 +907,0 @@ rs.addSubStatus(ss);

"use strict";
/// <reference path="../typings/main.d.ts" />
var _ = require("underscore");
var _ = require("./utils");
var xmlValidator = require('./xmlUtil');

@@ -134,2 +134,10 @@ var DOMParser = require('xmldom').DOMParser;

references.forEach(function (references) { return validator.setRemoteReference(references.reference, references.content || {}); });
var schemaUrl = null;
if (this.jsonSchema.id && typeof (this.jsonSchema.id) === "string") {
schemaUrl = this.jsonSchema.id;
var innerPos = schemaUrl.indexOf("#");
if (innerPos != -1) {
schemaUrl = schemaUrl.substr(0, innerPos);
}
}
try {

@@ -143,3 +151,8 @@ validator.validateSchema(this.jsonSchema);

var result = validator.getMissingRemoteReferences();
return normalize ? result.map(function (reference) { return _this.provider.normalizePath(reference); }) : result;
var filteredReferences = [];
if (result)
filteredReferences = _.filter(result, function (referenceUrl) {
return validator.cache[referenceUrl] == null && referenceUrl != schemaUrl;
});
return normalize ? filteredReferences.map(function (reference) { return _this.provider.normalizePath(reference); }) : filteredReferences;
};

@@ -146,0 +159,0 @@ JSONSchemaObject.prototype.getSchemaPath = function (schema, normalize) {

24

dist/src/typeExpressions.d.ts
import ts = require("./typesystem");
import schemaUtil = require('./schemaUtil');
export interface BaseNode {
type: string;
}
export interface Union extends BaseNode {
first: BaseNode;
rest: BaseNode;
}
export interface Parens extends BaseNode {
expr: BaseNode;
arr: number;
}
export interface Literal extends BaseNode {
value: string;
arr?: number;
params?: BaseNode[];
}
import typeExpressionDefs = require("./typeExpressionUtil");
export declare type BaseNode = typeExpressionDefs.BaseNode;
export declare type Union = typeExpressionDefs.Union;
export declare type Literal = typeExpressionDefs.Literal;
export declare type Parens = typeExpressionDefs.Parens;
export declare function parseToType(val: string, t: ts.TypeRegistry, contentProvider?: schemaUtil.IContentProvider): ts.AbstractType;
export declare function storeToString(t: ts.AbstractType): string;
export declare function visit(node: BaseNode, action: (n: BaseNode) => void): void;
export declare function serializeToString(node: BaseNode): string;
export declare function parse(str: string): BaseNode;

@@ -84,2 +84,42 @@ "use strict";

exports.storeToString = storeToString;
function visit(node, action) {
action(node);
if (node.type == "union") {
var union = node;
visit(union.first, action);
visit(union.rest, action);
}
else if (node.type == "parens") {
var parens = node;
visit(parens.expr, action);
}
}
exports.visit = visit;
function serializeToString(node) {
var arr = 0;
var str;
if (node.type == "name") {
var literal = node;
str = literal.value;
arr = literal.arr;
}
else if (node.type == "union") {
var union = node;
str = serializeToString(union.first) + " | " + serializeToString(union.rest);
}
else if (node.type == "parens") {
var parens = node;
str = "(" + serializeToString(parens.expr) + ")";
arr = parens.arr;
}
while (--arr >= 0) {
str += "[]";
}
return str;
}
exports.serializeToString = serializeToString;
function parse(str) {
return typeExpression.parse(str);
}
exports.parse = parse;
//# sourceMappingURL=typeExpressions.js.map

@@ -18,1 +18,2 @@ export interface IValidationPath {

export declare const HAS_FACETS: string;
export declare const HAS_ITEMS: string;

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

exports.HAS_FACETS = "HAS_FACETS";
exports.HAS_ITEMS = "HAS_ITEMS";
//# sourceMappingURL=typesystem-interfaces.js.map

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

constructor(severity: number, code: number, message: string, source: any);
addSubStatus(st: Status): void;
addSubStatus(st: Status, pathName?: string): void;
getErrors(): Status[];

@@ -25,0 +25,0 @@ getSubStatuses(): Status[];

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

});
it("validatation (unknown type path)", function () {
var tp = ps.parseJSONTypeCollection({
types: {
z: {
type: "object",
properties: {
mm: "number2"
}
},
}
});
var t = tp.getType("z");
var errors = t.validateType().getErrors();
assert.isTrue(errors.length === 1);
var path = errors[0].getValidationPathAsString();
assert.equal(path, "mm/type");
});
});
//# sourceMappingURL=instanceValidationPathTests.js.map

@@ -137,2 +137,28 @@ "use strict";

});
it("Validating array against unknown type", function () {
var tp = ps.parseJSONTypeCollection({
types: {
XX: {
type: "object",
properties: {
"x": "Likes[]"
},
example: {
x: [{ z: 2 }]
}
}
}
});
var t = tp.getType("XX");
var st = t.validateType(ts.builtInRegistry());
var f = false;
assert.isTrue(st.getErrors().length === 2);
var err = false;
st.getErrors().forEach(function (x) {
if (x.getMessage().indexOf("against") != -1) {
err = true;
}
});
assert.isTrue(err);
});
it("Validating recurrent types error count", function () {

@@ -139,0 +165,0 @@ var tp = ps.parseJSONTypeCollection({

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

@@ -5,0 +5,0 @@ "scripts": {

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

export import nominalTypes=require("./nominal-types")
export import typeExpressions=require("./typeExpressionUtil");
import schemaUtil = require('./schemaUtil');

@@ -15,0 +15,0 @@

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

actualResult.addMeta(new ComponentShouldBeOfType(tp));
actualResult.putExtra(tsInterfaces.HAS_ITEMS,true)
return;

@@ -736,0 +737,0 @@ }

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

var p= new Status(Status.ERROR,0,"property "+this.propId()+" refers to unknown type "+this._type.name(),this)
p.setValidationPath({name: this.propId()})
p.setValidationPath({name: this.propId(), child: { name: "type"}})
return p;

@@ -88,2 +88,4 @@ }

var p= new Status(Status.ERROR,0,"property "+this.propId()+" range type has error:"+st.getMessage(),this)
st.getErrors().forEach(y=>{p.addSubStatus(y)})
p.setValidationPath({name: this.propId()})

@@ -908,2 +910,9 @@ return p;

var ss=this.type.validate(ar[j],true);
if (!ss.isOk()){
var t=this.type;
if (t.isUnknown()|| t.isRecurrent()){
var s=new Status(Status.ERROR,0,"array instance is validated against unknown type:"+ t.name(),this);
return s;
}
}
ss.setValidationPath({ name:""+j})

@@ -910,0 +919,0 @@ rs.addSubStatus(ss);

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

import _ = require("underscore");
import _ = require("./utils");

@@ -181,2 +181,14 @@ import xmlValidator = require('./xmlUtil');

var schemaUrl : string = null;
if (this.jsonSchema.id && typeof(this.jsonSchema.id)==="string") {
schemaUrl = this.jsonSchema.id;
var innerPos = schemaUrl.indexOf("#");
if (innerPos != -1) {
schemaUrl = schemaUrl.substr(0, innerPos);
}
//adding reference to the schema itself
// validator.setRemoteReference(innerPos, this.jsonSchema);
}
try {

@@ -190,4 +202,8 @@ validator.validateSchema(this.jsonSchema);

var result = <any[]>validator.getMissingRemoteReferences();
var filteredReferences : string[] = [];
if (result) filteredReferences = _.filter(result, referenceUrl=>{
return validator.cache[referenceUrl] == null && referenceUrl != schemaUrl;
})
return normalize ? result.map(reference => this.provider.normalizePath(reference)) : result;
return normalize ? filteredReferences.map(reference => this.provider.normalizePath(reference)) : filteredReferences;
}

@@ -194,0 +210,0 @@

@@ -6,20 +6,10 @@ import typeExpression=require("./typeExpressionParser")

import {AdditionalPropertyIs} from "./restrictions";
export interface BaseNode{
type:string
}
export interface Union extends BaseNode{
first: BaseNode
rest: BaseNode
}
import typeExpressionDefs = require("./typeExpressionUtil")
export interface Parens extends BaseNode{
expr: BaseNode
arr: number
}
export interface Literal extends BaseNode{
value: string
arr?: number
params?:BaseNode[];
}
export type BaseNode = typeExpressionDefs.BaseNode;
export type Union = typeExpressionDefs.Union;
export type Literal = typeExpressionDefs.Literal;
export type Parens = typeExpressionDefs.Parens;
export function parseToType(val:string,t:ts.TypeRegistry, contentProvider: schemaUtil.IContentProvider = null):ts.AbstractType{

@@ -107,1 +97,39 @@ try {

export function visit(node:BaseNode,action:(n:BaseNode)=>void){
action(node);
if(node.type=="union"){
var union = <Union>node;
visit(union.first,action);
visit(union.rest,action);
}
else if(node.type=="parens"){
var parens = <Parens>node;
visit(parens.expr,action);
}
}
export function serializeToString(node:BaseNode):string{
var arr = 0;
var str:string;
if(node.type=="name"){
var literal = <Literal>node;
str = literal.value;
arr = literal.arr;
}
else if(node.type=="union"){
var union = <Union>node;
str = serializeToString(union.first) + " | " + serializeToString(union.rest);
}
else if(node.type=="parens"){
var parens = <Parens>node;
str = "("+serializeToString(parens.expr)+")";
arr = parens.arr;
}
while(--arr>=0){
str += "[]";
}
return str;
}
export function parse(str:string):BaseNode{
return typeExpression.parse(str);
}

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

export const GLOBAL_EXTRA="GLOBAL";
export const HAS_FACETS="HAS_FACETS";
export const HAS_FACETS="HAS_FACETS";
export const HAS_ITEMS="HAS_ITEMS";

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

addSubStatus(st:Status) {
addSubStatus(st:Status,pathName:string=null) {
if (pathName){
st.setValidationPath({name: pathName})
}
this.subStatus.push(st);

@@ -599,7 +602,7 @@ if (this.severity < st.severity) {

if (this.isSubTypeOf(RECURRENT)) {
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent type definition",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent type definition",this),"type")
}
if (this.isSubTypeOf(UNKNOWN)) {
rs.addSubStatus(new Status(Status.ERROR, 0, "inheriting from unknown type",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "inheriting from unknown type",this),"type")
}

@@ -609,6 +612,6 @@ if (this.isUnion()) {

if (tf.some(x=>x.isSubTypeOf(RECURRENT))) {
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent type as an option of union type",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent type as an option of union type",this),"type")
}
if (tf.some(x=>x.isSubTypeOf(UNKNOWN))) {
rs.addSubStatus(new Status(Status.ERROR, 0, "unknown type as an option of union type",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "unknown type as an option of union type",this),"type")
}

@@ -618,7 +621,10 @@ }

const fs=this.familyWithArray();
if ((fs.indexOf(this)!=-1)||fs.some(x=>x===RECURRENT)){
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent array type definition",this))
var ps= this.getExtra(tsInterfaces.HAS_ITEMS)?"items":"type";
if ((fs.indexOf(this)!=-1)||fs.some(x=>x===RECURRENT)){
rs.addSubStatus(new Status(Status.ERROR, 0, "recurrent array type definition",this),ps)
}
else if (fs.some(x=>x===UNKNOWN)){
rs.addSubStatus(new Status(Status.ERROR, 0, "referring to unknown type "+this.oneMeta(ComponentShouldBeOfType).value().name()+" as an array component type",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "referring to unknown type "+this.oneMeta(ComponentShouldBeOfType).value().name()+" as an array component type",this),ps)
}

@@ -641,3 +647,3 @@ }

if (hasExternal&&hasNotExternal){
rs.addSubStatus(new Status(Status.ERROR, 0, "It is not allowed to mix RAML types with externals",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "It is not allowed to mix RAML types with externals",this),"type")
}

@@ -648,3 +654,3 @@ if (this instanceof UnionType){

if (x.isExternal()){
rs.addSubStatus(new Status(Status.ERROR, 0, "It is not allowed to mix RAML types with externals",this))
rs.addSubStatus(new Status(Status.ERROR, 0, "It is not allowed to mix RAML types with externals",this),"type")
}

@@ -651,0 +657,0 @@ })

@@ -206,2 +206,21 @@ import ps= require("./actualParse")

});
it("validatation (unknown type path)", function () {
var tp = ps.parseJSONTypeCollection({
types:{
z: {
type: "object",
properties:{
mm: "number2"
}
},
}
});
var t=tp.getType("z");
var errors=t.validateType().getErrors();
assert.isTrue(errors.length===1);
var path=errors[0].getValidationPathAsString();
assert.equal(path,"mm/type");
});
});

@@ -149,2 +149,30 @@ import ps= require("./actualParse")

});
it("Validating array against unknown type", function () {
var tp = ps.parseJSONTypeCollection({
types:{
XX:{
type:"object",
properties:{
"x":"Likes[]"
},
example:{
x:[{z:2}]
}
}
}
});
var t=tp.getType("XX");
var st:ts.Status=t.validateType(ts.builtInRegistry());
var f=false;
assert.isTrue(st.getErrors().length===2);
var err=false;
st.getErrors().forEach(x=>{
if (x.getMessage().indexOf("against")!=-1){
err=true;
}
})
assert.isTrue(err)
});
it("Validating recurrent types error count", function () {

@@ -151,0 +179,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 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

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