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.22 to 0.0.23

392

dist/src/index.d.ts

@@ -7,26 +7,94 @@ export import nominalTypes = require("./nominal-types");

export interface IStatus {
/**
* retur2ns true if status does not have errors
*/
isOk(): boolean;
/**
* return true if this status contains a warning
*/
isWarning(): boolean;
/**
* return true if this status contains a error
*/
isError(): boolean;
/**
* returns human readable message associated with this status
*/
getMessage(): string;
/**
* returns an array of nested statuses
*/
getSubStatuses(): IStatus[];
/**
* return an object which raised this status
*/
getSource(): any;
/**
* returns primitive error statuses gathered recurrently, returns warnings to.
*/
getErrors(): IStatus[];
getValidationPath(): IValidationPath;
/**
* returns path to this status
*/
getValidationPathAsString(): string;
}
/**
* this is a common super interface for restrictions and meta data
*/
export interface ITypeFacet {
/**
* name of the facet
*/
facetName(): string;
/**
* broadest type to which this facet can be added
*/
requiredType(): IParsedType;
/**
* returns a type to which this facet belongs
*/
owner(): IParsedType;
/**
* return true if this facet is inheritable
*/
isInheritable(): boolean;
/**
* validates if the facet is configured properly
* @param registry
*/
validateSelf(registry: ITypeRegistry): IStatus;
/**
* returns value associated with the facet
*/
value(): any;
}
export interface IParsedTypeCollection {
/**
* returns a type for a given name
* @param name
*/
getType(name: string): IParsedType;
/**
* adds a type to collection
* @param t
*/
add(t: IParsedType): void;
/**
* adds annotation type
* @param t
*/
addAnnotationType(t: IParsedType): void;
/**
* returns annotation type for a given name
* @param name
*/
getAnnotationType(name: string): IParsedType;
/**
* lists the types defined in this collection
*/
types(): IParsedType[];
/**
* lists annotation types defined in this collection
*/
annotationTypes(): IParsedType[];

@@ -37,11 +105,42 @@ getTypeRegistry(): ITypeRegistry;

export interface ITypeRegistry {
/**
* returns a type associated with a given name
* @param name
*/
get(name: string): IParsedType;
/**
* list all types stored in this registry
*/
types(): IParsedType[];
}
/**
* parsed representation of the type
* you should not create instances of this interfaces manually
*/
export interface IParsedType {
/**
* returns list of directly declared sub types of this type
*/
subTypes(): IParsedType[];
/**
* returns list of directly declared super types of this type
*/
superTypes(): IParsedType[];
/**
* name of the type
*/
name(): string;
/**
* returns full list of known types which inherit from this type.
* Note: built-in types does not list their not built in sub types
*/
allSubTypes(): IParsedType[];
/**
* returns full list of ancestor types
*/
allSuperTypes(): IParsedType[];
/**
* validates a potential instance of type and returns a status describing the results of validation
* @param i
*/
validate(i: any, autoClose?: boolean): IStatus;

@@ -51,62 +150,195 @@ validateType(reg?: ITypeRegistry): IStatus;

canDoAc(i: any): IStatus;
/**
* returns all meta information and restrictions associated with the type all inheritable facets from super types are included
*/
allFacets(): ITypeFacet[];
exampleObject(): any;
/**
* returns meta information and restrictions associated with the type only declared facets are included
*/
declaredFacets(): ITypeFacet[];
/**
* returns array of custom facets directly declared on this type
*/
customFacets(): ITypeFacet[];
/**
* returns array of custom facets directly declared on this type
*/
restrictions(): ITypeFacet[];
/**
* returns true if this type inherits from object type
*/
isObject(): boolean;
/**
* returns true if this type inherits from string type
*/
isString(): boolean;
/**
* returns true if this type inherits from number type
*/
isNumber(): boolean;
/**
* returns true if this type inherits from array type
*/
isArray(): boolean;
/**
* returns true if this type inherits from scalar type
*/
isScalar(): boolean;
/**
* returns true if this type is a union type
*/
isUnion(): boolean;
/**
* returns true if this type inhetits from an unknown type
*/
isUnknown(): boolean;
/**
* return true if this type inherits from a file type
*/
isFile(): boolean;
/**
* returns true if this type has recurrent definition;
*/
isRecurrent(): boolean;
}
export interface Open {
/**
* this index signature is here to specify that IType can contain unknown user defined facets and annotations
*/
[name: string]: any;
}
/**
* this interface describes basic layout of JSON type representation,
* sub interfaces contains documentation about important facets which can be specified for the types extended from related built-in types
*/
export interface IType extends Open {
/**
* type expression describing super types or in case of multiple inheritance array of type expressions
*/
type?: string | string[];
/**
* default value for the type
*/
default?: any;
/**
* example for the type
*/
example?: any;
/**
* human readable description of the type (GitHub Markdown)
*/
description?: string;
/**
* human readable short name of the type
*/
displayName?: string;
/**
* map of custom facets declarations
*/
facets?: {
[name: string]: IType;
};
/**
* enumeration of possible valid instances for the type
*/
enum?: any[];
}
/**
* this interface constains additional properties specific to object types
*/
export interface ObjectType extends IType {
/**
* minimum amount of properties which instances of the type should have
*/
minProperties?: number;
/**
* maximum amount of properties which instances of the type should have
*/
maxProperties?: number;
/**
* if set to true type is threaten as closed type
*/
closed?: boolean;
/**
* map of property signatures to the property declarations
*/
properties?: {
[name: string]: IType;
};
/**
* map of regular expressions to pattern property declarations
*/
patternProperties?: {
[name: string]: IType;
};
/**
* allows to set constraints on the type of additional properties
*/
additionalProperties?: IType;
}
/**
* this interface contains additional properties specific to array types
*/
export interface ArrayType extends IType {
/**
* minimum amount of properties which instances of the type should have
*/
minItems?: number;
/**
* maximum amount of properties which instances of the type should have
*/
maxItems?: number;
/**
* contains description of the component type
*/
items?: string | IType;
}
/**
* this interface contains additional properties specific to number types
*/
export interface NumberType extends IType {
/**
* minimum value for this type
*/
minimum?: number;
/**
* maximum value for this type
*/
maximim?: number;
/**
* value for multiple of constraint
*/
multipleOf?: number;
}
/**
* this interface contains additional properties specific to string types
*/
export interface StringType extends IType {
/**
* regular expression which all instances of the type should pass
*/
pattern?: string;
/**
* minimum length of the string
*/
minLength?: number;
/**
* maximum length of the string
*/
maxLength?: number;
}
/**
* this interface represents JSON representation of the Library
*/
export interface ITypeCollection {
/**
* map of annotation type name to annotation type description
*/
annotationTypes?: {
[name: string]: IType;
};
/**
* map of normal type name to type description
*/
types?: {

@@ -116,6 +348,30 @@ [name: string]: IType;

}
/**
* loads type collection from JSON type definition
* @param data
* @param registry - optional registry of types which ar already known (does not modified during parse)
* @returns {TypeCollection} returns a new instance of type collection with a parsed types
*/
export declare function loadTypeCollection(data: ITypeCollection, registry?: ITypeRegistry): IParsedTypeCollection;
/**
* loads type from JSON type definition
* @param data
* @returns {ts.AbstractType}
*/
export declare function loadType(data: IType): IParsedType;
/**
* parses a type or type collection definition from a JSON structure
* @param data
* @returns {any}
*/
export declare function parse(data: IType | ITypeCollection): IParsedType | IParsedTypeCollection;
/**
* parses a type from a JSON structure, uses second argument to resolve types
* @param data
* @returns {any}
*/
export declare function parseType(data: IType, collection: IParsedTypeCollection): IParsedType;
/**
* kind of the node
*/
export declare enum NodeKind {

@@ -126,28 +382,124 @@ SCALAR = 0,

}
/**
* node representing an element of abstract syntax tree
*/
export interface IParseNode {
/**
* node key
*/
key(): string;
/**
* node value
*/
value(): any;
/**
* node children
*/
children(): IParseNode[];
/**
* child with a given key
* @param k
*/
childWithKey(k: string): IParseNode;
/**
* kind of the node
*/
kind(): NodeKind;
}
/**
* parses type collection definition from a JSON structure
* @param data
* @returns {any}
*/
export declare function parseFromAST(data: IParseNode): IParsedTypeCollection;
/**
* parses type collection definition from a JSON structure
* @param data
* @returns {any}
*/
export declare function parseTypeFromAST(name: string, data: IParseNode, collection: IParsedTypeCollection, defaultsToAny?: boolean, annotation?: boolean): IParsedType;
/**
* dumps type or type collection to JSON
* @param ts
* @returns {IType|ITypeCollection}
*/
export declare function dump(ts: IParsedType | IParsedTypeCollection): ITypeCollection | IType;
/**
* validates intance against the type definition
* @param i - instance to validate
* @param t - type definition
* @returns {IStatus}
*/
export declare function validate(i: any, t: IParsedType, autoClose?: boolean): IStatus;
/***
* validates type definition
* @param t
* @param collection - collection of the types
* @returns {IStatus}
*/
export declare function validateTypeDefinition(t: IParsedType, collection: IParsedTypeCollection): IStatus;
/**
* performs automatic classification of instance against a given type
* @param i
* @param t
* @returns {IParsedType}
*/
export declare function performAC(i: any, t: IParsedType): IParsedType;
/**
* checks if the given type is suitable for automatic classification
* @param t
* @returns {Status}
*/
export declare function checkACStatus(t: IParsedType): IStatus;
export interface IFacetPrototype {
/**
*creates brand new instance of facet filled with default values
*/
newInstance(): ITypeFacet;
/**
* creates a facet filled with a passed value
* @param v
*/
createWithValue(v: any): ITypeFacet;
/**
* checks if the facet represented by this prototype can be added to the given type
* @param t
*/
isApplicable(t: IParsedType): boolean;
/**
* returns true if this facet is inheritable
*/
isInheritable(): boolean;
/**
* returns true if this facet is a constraint
*/
isConstraint(): boolean;
/**
* returns true if this facet describes a metadata
*/
isMeta(): boolean;
/**
* returns the name of the facet represented by this prototype
*/
name(): string;
}
/**
* this function allow you to get a list of all built-in facets
* @returns {FacetPrototype[]}
*/
export declare function builtInFacets(): IFacetPrototype[];
/**
* returns type registry returning all built in types
* @returns {TypeRegistry}
*/
export declare function builtInTypes(): ITypeRegistry;
/**
* creates a new type by deriving it from a list of super types
* @returns {IParsedType}
*/
export declare function derive(name: string, ...types: IParsedType[]): IParsedType;
/**
* creates a new type by unifying it from a list of possible options
* @returns {IParsedType}
*/
export declare function unify(name: string, ...types: IParsedType[]): IParsedType;

@@ -157,9 +509,49 @@ export declare class TypeConstructor {

constructor(target: IParsedType);
/**
* adds property declaration to the type
* @param name
* @param type
* @param optional
* @returns {TypeConstructor}
*/
addProperty(name: string, type: IParsedType, optional: boolean): TypeConstructor;
/**
* adds pattern property declaration to the type
* @param target
* @param regexp
* @param type
* @returns {TypeConstructor}
*/
addPatternProperty(target: IParsedType, regexp: string, type: IParsedType): TypeConstructor;
/**
* closes type
* @returns {TypeConstructor}
*/
closeType(): TypeConstructor;
/**
* adds annotation to the type
* @returns {TypeConstructor}
*/
annotate(name: string, value: any): TypeConstructor;
/**
* adds custom facet to the type
* @returns {TypeConstructor}
*/
customFacet(name: string, value: any): TypeConstructor;
/**
* adds custom facet declaration to the type
* @returns {TypeConstructor}
*/
customFacetDeclaration(name: string, value: IParsedType, optional?: boolean): TypeConstructor;
/**
* adds a built-in facet with a given name and value
* @param name
* @param value
* @returns {TypeConstructor}
*/
addSimpleFacet(name: string, value: any): TypeConstructor;
/**
* returns a constructed type instance
* @returns {IParsedType}
*/
getResult(): IParsedType;

@@ -166,0 +558,0 @@ }

@@ -18,3 +18,10 @@ export interface INamedEntity {

export interface IAnnotation extends INamedEntity, ITyped {
/***
* names of the parameters that are specified here
*/
parameterNames(): string[];
/**
* value of the parameter with name
* @param name
*/
parameter(name: string): any;

@@ -28,10 +35,47 @@ }

export interface IExpandableExample {
/**
* Returns true if the application in question does not have an example set directly.
* It is still possible that while application has no direct example, references may have
* example pieces, current example may be expanded with.
*/
isEmpty(): boolean;
/**
* Whether the original example is JSON string.
*/
isJSONString(): boolean;
/**
* Whether the original example is XML string.
*/
isXMLString(): boolean;
/**
* Whether original example is set up as YAML.
*/
isYAML(): boolean;
/**
* Returns representation of this example as a string.
* This method works for any type of example.
*/
asString(): string;
/**
* Returns representation of this example as JSON object.
* This works for examples being JSON strings and YAML objects.
* It -may- work for XML string examples, but is not guaranteed.
*/
asJSON(): any;
/**
* Returns an original example. It is string for XML and JSON strings,
* or JSON object for YAML example.
*/
original(): any;
/**
* Expands the example with what its application references can provide.
* XML examples are not guaranteed to be supported. If supported, XML is convrted into JSON.
* Returns null or expansion result as string.
*/
expandAsString(): string;
/**
* Expands the example with what its application references can provide.
* XML examples are not guaranteed to be supported. If supported, XML is convrted into JSON.
* Returns null or expansion result as JSON object.
*/
expandAsJSON(): any;

@@ -42,2 +86,7 @@ }

value: string;
/**
*
* @param name name of the property to discriminate
* @param value expected value of discriminating property
*/
constructor(name: string, value: string);

@@ -47,39 +96,163 @@ }

key(): NamedId;
/**
* list os super types
*/
superTypes(): ITypeDefinition[];
/**
* list of sub types
*/
subTypes(): ITypeDefinition[];
/**
* list of all subtypes not including this type
*/
allSubTypes(): ITypeDefinition[];
/**
* List of all super types not including this type
*/
allSuperTypes(): ITypeDefinition[];
/**
* Propertis decared in this type
*/
properties(): IProperty[];
facet(n: string): IProperty;
/**
* List off all properties (declared in this type and super types),
* did not includes properties fixed to fixed facet use facet for them
*/
allProperties(visited?: any): IProperty[];
/**
* Facets declared by the type and its supertypes
*/
allFacets(visited?: any): IProperty[];
/**
* Facets declared by the type
*/
facets(): IProperty[];
/**
* Whether this type is value type. Does not perform a search in super types.
*/
isValueType(): boolean;
/**
* true if this type is value type or one of its super types is value type.
*/
hasValueTypeInHierarchy(): boolean;
/**
* Whether this type is an array. Does not perform a search in super types.
*/
isArray(): boolean;
/**
* Whether this type is object. Performs a search in super types.
*/
isObject(): boolean;
/**
* true if this type is array or one of its super types is array.
*/
hasArrayInHierarchy(): boolean;
/**
* Casts this type to an array. Does not perform a search in super types.
*/
array(): IArrayType;
/**
* casting to nearest array type in hierarchy
*/
arrayInHierarchy(): IArrayType;
/**
* Whether this type is a union. Does not perform a search in super types.
*/
isUnion(): boolean;
/**
* true if this type is union or one of its super types is union.
*/
hasUnionInHierarchy(): boolean;
/**
* Casts this type to a union type. Does not perform a search in super types.
*/
union(): IUnionType;
/**
* Casting to nearest union type in hierarchy
*/
unionInHierarchy(): IUnionType;
isAnnotationType(): boolean;
annotationType(): IAnnotationType;
/**
* true if this type values have internal structure
*/
hasStructure(): boolean;
/**
* true if this type is external. Does not perform a search in super types.
*/
isExternal(): boolean;
/**
* true if this type is external type, or one if its super types is an external type.
*/
hasExternalInHierarchy(): boolean;
/**
* Casts this type to an external type. Does not perform a search in super types.
*/
external(): IExternalType;
/**
* Casting to nearest external type in hierarchy
*/
externalInHierarchy(): IExternalType;
/**
* List of value requirements for this type,
* used to discriminate a type from a list of subtype
*/
valueRequirements(): ValueRequirement[];
/**
* parent universe
*/
universe(): IUniverse;
/**
* return true if this type is assignable to a given type
* @param typeName
*/
isAssignableFrom(typeName: string): boolean;
/**
* return property by it name looks in super classes
* but will not return anything if property is a fixed with facet
* @param name
*/
property(name: string): IProperty;
/**
* helper method to get required properties only
*/
requiredProperties(): IProperty[];
/**
* @return map of fixed facet names to fixed facet values;
*/
getFixedFacets(): {
[name: string]: any;
};
/**
* @return map of fixed facet names to fixed facet values;
*/
allFixedFacets(): {
[name: string]: any;
};
/**
* Print details of this type.
* Used mostly for debug and demosntration purposes.
* @param indent
*/
printDetails(indent?: string, settings?: IPrintDetailsSettings): string;
/**
* Returns examples for this type.
* Returned examples should be tested for being empty and being expandable.
*/
examples(): IExpandableExample[];
/**
* Returns whether this type contain genuine user defined type in its hierarchy.
* Genuine user defined type is a type user intentionally defined and filled with
* properties or facets, or having user-defined name as opposed to a synthetic user-defined type.
*/
isGenuineUserDefinedType(): boolean;
/**
* Returns nearest genuine user-define type in the hierarchy.
* Genuine user defined type is a type user intentionally defined and filled with
* properties or facets, or having user-defined name as opposed to a synthetic user-defined type.
*/
genuineUserDefinedType(): ITypeDefinition;
kind(): string[];
}

@@ -92,2 +265,5 @@ export interface FacetValidator {

}
/**
* represent array types
*/
export interface IArrayType extends ITypeDefinition {

@@ -99,2 +275,5 @@ componentType(): ITypeDefinition;

}
/**
* represent union types
*/
export interface IUnionType extends ITypeDefinition {

@@ -104,6 +283,22 @@ leftType(): ITypeDefinition;

}
/**
* collection of types
*/
export interface IUniverse {
/**
* type for a given name
* @param name
*/
type(name: string): ITypeDefinition;
/**
* version of this universe
*/
version(): string;
/**
* All types in universe
*/
types(): ITypeDefinition[];
/**
* highlevel information about universe
*/
matched(): {

@@ -114,14 +309,55 @@ [name: string]: NamedId;

export interface IProperty extends INamedEntity {
/**
* name of the property
*/
nameId(): string;
/**
* returns true if this property matches the a given property name
* (it is important for additional and pattern properties)
* @param k
*/
matchKey(k: string): boolean;
/**
* range of the property (basically it is type)
*/
range(): ITypeDefinition;
/**
* domain of the property (basically declaring type)
*/
domain(): ITypeDefinition;
/**
* true if this property is required to fill
*/
isRequired(): boolean;
/**
* true if this property can have multiple values
*/
isMultiValue(): boolean;
/**
* true if this property range is one of built in value types
*/
isPrimitive(): boolean;
/**
* true if this property range is a value type
*/
isValueProperty(): boolean;
/**
* return a prefix for a property name - used for additional properties
*/
keyPrefix(): string;
/**
* return a pattern for a property name - used for a pattern properties
*/
getKeyRegexp(): string;
/**
* returns a default value for this property
*/
defaultValue(): any;
/**
* if this property range is constrained to a fixed set of values it will return the values
*/
enumOptions(): string[];
/**
* true if this property is a discriminator
*/
isDescriminator(): boolean;

@@ -128,0 +364,0 @@ }

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

}): IProperty[];
facets(): IProperty[];
facet(name: string): ti.IProperty;

@@ -99,2 +100,5 @@ typeId(): string;

};
allFixedFacets(): {
[name: string]: any;
};
protected contributeFacets(x: {

@@ -123,4 +127,18 @@ [name: string]: any;

private isStandardSuperclass(nameId, className);
/**
* Returns example for this type.
* Returned example should be tested for being empty and being expandable.
*/
examples(): IExpandableExample[];
/**
* Returns whether this type contain genuine user defined type in its hierarchy.
* Genuine user defined type is a type user intentionally defined and filled with
* properties or facets, or having user-defined name as opposed to a synthetic user-defined type.
*/
isGenuineUserDefinedType(): boolean;
/**
* Returns nearest genuine user-define type in the hierarchy.
* Genuine user defined type is a type user intentionally defined and filled with
* properties or facets, or having user-defined name as opposed to a synthetic user-defined type.
*/
genuineUserDefinedType(): ITypeDefinition;

@@ -137,4 +155,6 @@ customProperties(): IProperty[];

isArray(): boolean;
isObject(): boolean;
array(): IArrayType;
isValueType(): boolean;
kind(): string[];
}

@@ -147,2 +167,3 @@ export declare class ValueType extends AbstractType implements ITypeDefinition {

isUnionType(): boolean;
isObject(): boolean;
}

@@ -209,2 +230,3 @@ export declare class StructuredType extends AbstractType implements ITypeDefinition {

isUnion(): boolean;
isObject(): boolean;
hasArrayInHierarchy(): boolean;

@@ -217,2 +239,3 @@ }

isArray(): boolean;
isObject(): boolean;
arrayInHierarchy(): this;

@@ -219,0 +242,0 @@ array(): this;

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

export declare function toProto(type: AbstractType): TypeProto;
/***
* stores a type to JSON structure
* @param ts
*/
export declare function storeAsJSON(ts: AbstractType | TypeCollection): any;
/**
* parses a type from a JSON structure
* @param name
* @param n
* @param r
* @returns {any}
*/
export declare function parse(name: string, n: ParseNode, r?: ts.TypeRegistry, defaultsToAny?: boolean, annotation?: boolean): ts.AbstractType;

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

export declare type IValidationPath = ts.IValidationPath;
/**
* this class is an abstract super type for every constraint that can select properties from objects
*/
export declare abstract class MatchesProperty extends ts.Constraint {

@@ -27,2 +30,5 @@ private _type;

}
/**
* this is a constraint which checks that object has no unknown properties if at has not additional properties
*/
export declare class KnownPropertyRestriction extends ts.Constraint {

@@ -38,2 +44,5 @@ private _value;

}
/**
* this constaint checks that object has a particular property
*/
export declare class HasProperty extends ts.Constraint {

@@ -48,2 +57,5 @@ private name;

}
/**
* this constraint checks that property has a particular tyoe if exists
*/
export declare class PropertyIs extends MatchesProperty {

@@ -62,2 +74,5 @@ private name;

}
/**
* this cosnstraint checks that map property values passes to particular type if exists
*/
export declare class MapPropertyIs extends MatchesProperty {

@@ -78,2 +93,5 @@ private regexp;

}
/**
* this constraint tests that additional property
*/
export declare class AdditionalPropertyIs extends MatchesProperty {

@@ -91,2 +109,5 @@ private type;

}
/**
* common super type for a simple restrictions
*/
export declare abstract class FacetRestriction<T> extends ts.Constraint {

@@ -99,2 +120,5 @@ abstract facetName(): string;

}
/**
* abstract super type for every min max restriction
*/
export declare abstract class MinMaxRestriction extends FacetRestriction<Number> {

@@ -120,2 +144,5 @@ private _facetName;

}
/**
* maximum constraint
*/
export declare class Maximum extends MinMaxRestriction {

@@ -126,2 +153,5 @@ constructor(val: number);

}
/**
* minimum constraint
*/
export declare class Minimum extends MinMaxRestriction {

@@ -132,2 +162,5 @@ constructor(val: number);

}
/**
* max items cosntraint
*/
export declare class MaxItems extends MinMaxRestriction {

@@ -138,2 +171,5 @@ constructor(val: number);

}
/**
* min items cosntraint
*/
export declare class MinItems extends MinMaxRestriction {

@@ -144,2 +180,5 @@ constructor(val: number);

}
/**
* max length
*/
export declare class MaxLength extends MinMaxRestriction {

@@ -150,2 +189,5 @@ constructor(val: number);

}
/**
* min length
*/
export declare class MinLength extends MinMaxRestriction {

@@ -156,2 +198,5 @@ constructor(val: number);

}
/**
* max properties constraint
*/
export declare class MaxProperties extends MinMaxRestriction {

@@ -162,2 +207,5 @@ constructor(val: number);

}
/**
* min properties constraint
*/
export declare class MinProperties extends MinMaxRestriction {

@@ -168,2 +216,5 @@ constructor(val: number);

}
/**
* unique items constraint
*/
export declare class UniqueItems extends FacetRestriction<boolean> {

@@ -180,2 +231,5 @@ private _value;

}
/**
* components of array should be of type
*/
export declare class ComponentShouldBeOfType extends FacetRestriction<ts.AbstractType> {

@@ -193,2 +247,5 @@ private type;

}
/**
* regular expression (pattern) constraint
*/
export declare class Pattern extends FacetRestriction<string> {

@@ -205,2 +262,5 @@ private _value;

}
/**
* enum constraint
*/
export declare class Enum extends FacetRestriction<string[]> {

@@ -218,2 +278,7 @@ private _value;

}
/**
* this function attempts to optimize to set of restrictions
* @param r
* @returns {ts.Constraint[]}
*/
export declare function optimize(r: ts.Constraint[]): ts.Constraint[];

6

dist/src/schemaUtil.js

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

if (!(id.lastIndexOf('#') === id.length - 1)) {
return schema;
id = id + '#';
schema.id = id;
}

@@ -147,2 +148,5 @@ ;

}
if (reference.indexOf('#') === -1) {
reference = reference + '#';
}
if (!_this.provider.isAbsolutePath(reference)) {

@@ -149,0 +153,0 @@ refConatiner['$ref'] = _this.provider.resolvePath(currentPath, reference).replace(/\\/g, '/');

@@ -56,8 +56,25 @@ /// <reference path="../../typings/main.d.ts" />

nothing(c: Constraint, message?: string): NothingRestrictionWithLocation;
/**
* inner implementation of compute composed restriction from this and parameter restriction
* @param restriction
* @return composed restriction or null;
*/
composeWith(r: Constraint): Constraint;
/**
* returns optimized restiction or this
* @returns {Constraint}
*/
preoptimize(): Constraint;
protected innerOptimize(): Constraint;
/**
* performs attempt to compute composed restriction from this and parameter restriction
* @param restriction
* @return composed restriction or null;
*/
tryCompose(r: Constraint): Constraint;
}
export declare var autoCloseFlag: boolean;
/**
* Registry of the types
*/
export declare class TypeRegistry {

@@ -105,3 +122,9 @@ private _parent;

name(): string;
/**
* @return directly known sub types of a given type
*/
subTypes(): AbstractType[];
/**
* @return directly known super types of a given type
*/
superTypes(): AbstractType[];

@@ -118,26 +141,102 @@ validateType(tr?: TypeRegistry): Status;

inherit(name: string): InheritedType;
/**
*
* @return true if type is an inplace type and has no name
*/
isAnonymous(): boolean;
/**
*
* @return true if type has no associated meta information of restrictions
*/
isEmpty(): boolean;
/**
*
* @return true if type is an array or extends from an array
*/
isArray(): boolean;
propertySet(): string[];
checkConfluent(): Status;
/**
*
* @return true if type is object or inherited from object
*/
isObject(): boolean;
/**
*
* @return true if type is object or inherited from object
*/
isExternal(): boolean;
/**
*
* @return true if type is an boolean type or extends from boolean
*/
isBoolean(): boolean;
/**
*
* @return true if type is string or inherited from string
*/
isString(): boolean;
/**
*
* @return true if type is number or inherited from number
*/
isNumber(): boolean;
/**
*
* @return true if type is number or inherited from number
*/
isFile(): boolean;
/**
*
* @return true if type is scalar or inherited from scalar
*/
isScalar(): boolean;
/**
*
* @return true if type is scalar or inherited from scalar
*/
isUnknown(): boolean;
/**
*
* @return true if type is scalar or inherited from scalar
*/
isRecurrent(): boolean;
/**
*
* @return true if type is an built-in type
*/
isBuiltin(): boolean;
exampleObject(): any;
/**
*
* @return true if type is an polymorphic type
*/
isPolymorphic(): boolean;
/**
* @return all restrictions associated with type
*/
restrictions(forValidation?: boolean): Constraint[];
customFacets(): TypeInformation[];
isUnion(): boolean;
/**
* return all type information associated with type
*/
meta(): TypeInformation[];
/**
* validates object against this type without performing AC
*/
validateDirect(i: any, autoClose?: boolean, nullAllowed?: boolean, path?: IValidationPath): Status;
validate(i: any, autoClose?: boolean, nullAllowed?: boolean): Status;
/**
* declares a pattern property on this type,
* note if type is not inherited from an object type this will move
* type to inconsistent state
* @param name - regexp
* @param type - type of the property
* @return
*/
declareMapProperty(name: string, type: AbstractType): AbstractType;
/**
* make this type closed type (no unknown properties any more)
*/
closeUnknownProperties(): void;

@@ -147,8 +246,31 @@ canDoAc(): Status;

checkDiscriminator(t1: AbstractType, t2: AbstractType): Status;
/**
* performs automatic classification of the instance
* @param obj
* @returns {AbstractType}
*/
ac(obj: any): AbstractType;
/**
* adds new property declaration to this type, note if type is not inherited from an object type this will move
* type to inconsistent state
* @param name - name of the property
* @param type - type of the property
* @param optional true if property is optinal
* @return the type with property (this)
*/
declareProperty(name: string, t: AbstractType, optional: boolean): AbstractType;
private discriminate(obj, opt);
/**
* return instance of type information of particular class
* @param clazz
* @returns {any}
*/
oneMeta<T>(clazz: {
new (v: any): T;
}): T;
/**
* return all instances of meta information of particular class
* @param clazz
* @returns {any}
*/
metaOfType<T>(clazz: {

@@ -193,2 +315,6 @@ new (v: any): T;

constructor(name: string, _options: AbstractType[]);
/**
*
* @returns all possible options
*/
allOptions(): AbstractType[];

@@ -212,3 +338,14 @@ options(): AbstractType[];

export declare function intersect(name: string, t: AbstractType[]): IntersectionType;
/**
* allows you to extend a type from other types
* @param name
* @param t
* @returns {InheritedType}
*/
export declare function derive(name: string, t: AbstractType[]): InheritedType;
/**
* this function allows you to quickly derive a new type from object;
* @param name
* @returns {InheritedType}
*/
export declare function deriveObjectType(name: string): InheritedType;

@@ -283,2 +420,6 @@ export declare class NothingRestriction extends Constraint {

}
/***
*
* lets declare built in types
*/
export declare const ANY: RootType;

@@ -285,0 +426,0 @@ export declare const SCALAR: InheritedType;

@@ -290,2 +290,17 @@ "use strict";

});
it("File related facets negative test", function () {
var tp = ps.parseJSONTypeCollection({
types: {
a: {
type: "file",
fileTypes: ["applicaiton/json"],
minLength: "1",
maxLength: 2000
}
}
});
var t = tp.getType("a");
var st = t.validateType(ts.builtInRegistry());
assert.isTrue(st.getErrors().length === 1);
});
it("not required property in long syntax", function () {

@@ -292,0 +307,0 @@ var tp = ps.parseJSONTypeCollection({

2

package.json
{
"name": "raml-typesystem",
"version": "0.0.22",
"version": "0.0.23",
"main": "dist/src/index.js",

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

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

if(!(id.lastIndexOf('#') === id.length - 1)) {
return schema;
id = id + '#';
schema.id = id;
};

@@ -197,2 +199,6 @@

if(reference.indexOf('#') === -1) {
reference = reference + '#';
}
if(!this.provider.isAbsolutePath(reference)) {

@@ -199,0 +205,0 @@ refConatiner['$ref'] = this.provider.resolvePath(currentPath, reference).replace(/\\/g,'/');

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

});
it("File related facets negative test", function () {
var tp = ps.parseJSONTypeCollection({
types:{
a: {
type:"file",
fileTypes:["applicaiton/json"],
minLength:"1",
maxLength:2000
}
}
});
var t=tp.getType("a");
var st=t.validateType(ts.builtInRegistry());
assert.isTrue(st.getErrors().length===1);
});
it("not required property in long syntax", function () {

@@ -345,0 +362,0 @@ var tp = ps.parseJSONTypeCollection({

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts

@@ -3,0 +3,0 @@ // Type definitions for chai 2.0.0

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts

@@ -3,0 +3,0 @@ // Type definitions for mocha 2.2.5

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts

@@ -3,0 +3,0 @@ // Type definitions for node-xml2js

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/be0b6b394f77a59e192ad7cfec18078706e44db5/chai/chai.d.ts

@@ -3,0 +3,0 @@ // Type definitions for chai 2.0.0

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts

@@ -3,0 +3,0 @@ // Type definitions for mocha 2.2.5

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

// Compiled using typings@0.6.8
// Compiled using typings@0.5.2
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7304e0770d53762f89af7fcf14517d5f45a04cc2/xml2js/xml2js.d.ts

@@ -3,0 +3,0 @@ // Type definitions for 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 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