UNPKG

@accordproject/concerto-core

Version:

Core Implementation for the Concerto Modeling Language

200 lines (199 loc) • 8.22 kB
/** * <p> * Validates a Resource or Field against the models defined in the ModelManager. * This class is used with the Visitor pattern and visits the class declarations * (etc) for the model, checking that the data in a Resource / Field is consistent * with the model. * </p> * The parameters for the visit method must contain the following properties: * <ul> * <li> 'stack' - the TypedStack of objects being processed. It should * start as [Resource] or [Field]</li> * <li> 'rootResourceIdentifier' - the identifier of the resource being validated </li> * <li> 'modelManager' - the ModelManager instance to use for type checking</li> * </ul> * @private * @class * @memberof module:concerto-core */ declare class ResourceValidator { options: any; /** * ResourceValidator constructor * @param {Object} options - the optional serialization options. * @param {boolean} options.validate - validate the structure of the Resource * with its model prior to serialization (default to true) * @param {boolean} options.convertResourcesToRelationships - Convert resources that * are specified for relationship fields into relationships, false by default. * @param {boolean} options.permitResourcesForRelationships - Permit resources in the */ constructor(options: any); /** * Visitor design pattern. * * @param {Object} thing - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * @private */ visit(thing: any, parameters: any): null | undefined; /** * Visitor design pattern * * @param {EnumDeclaration} enumDeclaration - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * @private */ visitEnumDeclaration(enumDeclaration: any, parameters: any): null; /** * Check a Type that is declared as a Map Type. * @param {Object} type - the type in scope for validation, can be MapTypeKey or MapTypeValue * @param {Object} value - the object being validated * @param {Object} parameters - the parameter * @param {Map} mapDeclaration - the object being visited * @private */ checkMapType(type: any, value: any, parameters: any, mapDeclaration: any): void; /** * Visitor design pattern * * @param {MapDeclaration} mapDeclaration - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * * @private */ visitMapDeclaration(mapDeclaration: any, parameters: any): null; /** * Visitor design pattern * @param {ClassDeclaration} classDeclaration - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * @private */ visitClassDeclaration(classDeclaration: any, parameters: any): null; /** * Visitor design pattern * @param {Field} field - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * @private */ visitField(field: any, parameters: any): null; /** * Check a Field that is declared as an Array. * @param {Object} obj - the object being validated * @param {Field} field - the object being visited * @param {Object} parameters - the parameter * @private */ checkEnum(obj: any, field: any, parameters: any): void; /** * Check a Field that is declared as an Array. * @param {Object} obj - the object being validated * @param {Field} field - the object being visited * @param {Object} parameters - the parameter * @private */ checkArray(obj: any, field: any, parameters: any): void; /** * Check a single (non-array) field. * @param {Object} obj - the object being validated * @param {Field} field - the object being visited * @param {Object} parameters - the parameter * @private */ checkItem(obj: any, field: any, parameters: any): void; /** * Visitor design pattern * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null * @private */ visitRelationshipDeclaration(relationshipDeclaration: any, parameters: any): null; /** * Check a single relationship * @param {Object} parameters - the parameter * @param {relationshipDeclaration} relationshipDeclaration - the object being visited * @param {Object} obj - the object being validated * @private */ checkRelationship(parameters: any, relationshipDeclaration: any, obj: any): void; /** * Throw a new error for a model violation. * @param {string} id - the identifier of this instance. * @param {string} propName - the name of the field. * @param {*} value - the value of the field. * @param {Field} field - the field * @throws {ValidationException} the exception * @private */ static reportFieldTypeViolation(id: any, propName: any, value: any, field: any): void; /** * Throw a new error for a model violation. * @param {string} id - the identifier of this instance. * @param {ClassDeclaration} classDeclaration - the declaration of the class * @param {Object} value - the value of the field. * @private */ static reportNotResouceViolation(id: any, classDeclaration: any, value: any): void; /** * Throw a new error for a model violation. * @param {string} id - the identifier of this instance. * @param {RelationshipDeclaration} relationshipDeclaration - the declaration of the class * @param {Object} value - the value of the field. * @private */ static reportNotRelationshipViolation(id: any, relationshipDeclaration: any, value: any): void; /** * Throw a new error for a missing, but required field. * @param {string} id - the identifier of this instance. * @param {Field} field - the field/ * @private */ static reportMissingRequiredProperty(id: any, field: any): void; /** * Throw a new error for a missing, but required field. * @param {string} id - the identifier of this instance. * @param {Field} field - the field/ * @private */ static reportEmptyIdentifier(id: any): void; /** * Throw a new error for a missing, but required field. * @param {string} id - the identifier of this instance. * @param {Field} field - the field * @param {string} obj - the object value * @private */ static reportInvalidEnumValue(id: any, field: any, obj: any): void; /** * Throw a validation exception for an abstract class * @param {ClassDeclaration} classDeclaration - the class declaration * @throws {ValidationException} the validation exception * @private */ static reportAbstractClass(classDeclaration: any): void; /** * Throw a validation exception for an abstract class * @param {string} resourceId - the id of the resource being validated * @param {string} propertyName - the name of the property that is not declared * @param {string} fullyQualifiedTypeName - the fully qualified type being validated * @throws {ValidationException} the validation exception * @private */ static reportUndeclaredField(resourceId: any, propertyName: any, fullyQualifiedTypeName: any): void; /** * Throw a validation exception for an invalid field assignment * @param {string} resourceId - the id of the resource being validated * @param {string} propName - the name of the property that is being assigned * @param {*} obj - the Field * @param {Field} field - the Field * @throws {ValidationException} the validation exception * @private */ static reportInvalidFieldAssignment(resourceId: any, propName: any, obj: any, field: any): void; } export = ResourceValidator;