UNPKG

@accordproject/concerto-core

Version:

Core Implementation for the Concerto Modeling Language

234 lines (233 loc) • 12.4 kB
/** * Utility functions to work with * [DecoratorCommandSet](https://models.accordproject.org/concerto/decorators.cto) * @memberof module:concerto-core */ declare class DecoratorManager { /** * Structural validation of the decoratorCommandSet against the * Decorator Command Set model. Note that this only checks the * structural integrity of the command set, it cannot check * whether the commands are valid with respect to a model manager. * Use the options.validateCommands option with decorateModels * method to perform semantic validation. * @param {*} decoratorCommandSet the DecoratorCommandSet object * @param {ModelFile[]} [modelFiles] an optional array of model * files that are added to the validation model manager returned * @returns {ModelManager} the model manager created for validation * @throws {Error} throws an error if the decoratorCommandSet is invalid */ static validate(decoratorCommandSet: any, modelFiles?: any): any; /** * Rewrites the $class property on decoratorCommandSet classes. * @param {*} decoratorCommandSet the DecoratorCommandSet object * @param {string} version the DCS version upgrade target * @returns {object} the migrated DecoratorCommandSet object */ static migrateTo(decoratorCommandSet: any, version: any): any; /** * Checks if the supplied decoratorCommandSet can be migrated. * Migrations should only take place across minor versions of the same major version. * @param {*} decoratorCommandSet the DecoratorCommandSet object * @param {*} DCS_VERSION the DecoratorCommandSet version * @returns {boolean} returns true if major versions are equal */ static canMigrate(decoratorCommandSet: any, DCS_VERSION: any): boolean; /** * Add decorator commands set with index object to the coresponding target map * @param {*} targetMap the target map to add the command to * @param {targetKey} targetKey the target key to add the command to * @param {DcsIndexWrapper} dcsWithIndex the command to add * @private */ static addDcsWithIndexToMap(targetMap: any, targetKey: any, dcsWithIndex: any): void; /** * Creates five different maps to index decorator command sets by target type and returns them * @param {*} decoratorCommandSet the DecoratorCommandSet object * @returns {Object} object with all the decorator command maps based on the target * @private */ static getDecoratorMaps(decoratorCommandSet: any): { namespaceCommandsMap: Map<any, any>; declarationCommandsMap: Map<any, any>; propertyCommandsMap: Map<any, any>; mapElementCommandsMap: Map<any, any>; typeCommandsMap: Map<any, any>; }; /** * Migrate or validate the DecoratorCommandSet object if the options are set as true * @param {ModelManager} modelManager the input model manager * @param {*} decoratorCommandSet a DecoratorCommandSet object, or an array of DecoratorCommandSet objects * @param {boolean} shouldMigrate migrate the decoratorCommandSet $class to match the dcs model version * @param {boolean} shouldValidate validate that decorator command set is valid * with respect to to decorator command set model * @param {boolean} shouldValidateCommands validate the decorator command set targets. Note that * the validate option must also be true * @private */ static migrateAndValidate(modelManager: any, decoratorCommandSet: any, shouldMigrate: any, shouldValidate: any, shouldValidateCommands: any): void; /** * Adds decorator commands with index to the array passed * @param {DcsIndexWrapper[]} array the array to add the command to * @param {*} map the target map to add the command to * @param {key} key the target key to add the command to * @private */ static pushMapValues(array: any, map: any, key: any): void; /** * Applies all the decorator commands from the DecoratorCommandSet to the ModelManager * @param {ModelManager} modelManager the input model manager * @param {*} decoratorCommandSet the DecoratorCommandSet object, or an array of DecoratorCommandSet objects * @param {object} [options] - decorator models options * @param {boolean} [options.validate] - validate that decorator command set is valid * with respect to to decorator command set model * @param {boolean} [options.validateCommands] - validate the decorator command set targets. Note that * the validate option must also be true * @param {boolean} [options.migrate] - migrate the decoratorCommandSet $class to match the dcs model version * @param {boolean} [options.defaultNamespace] - the default namespace to use for decorator commands that include a decorator without a namespace * @param {boolean} [options.skipValidationAndResolution] - optional flag to disable both metamodel resolution and validation, only use if you are sure that the model manager has fully resolved models * @param {boolean} [options.disableMetamodelResolution] - flag to disable metamodel resolution, only use if you are sure that the model manager has fully resolved models * @param {boolean} [options.disableMetamodelValidation] - flag to disable metamodel validation, only use if you are sure that the models and decorators are already validated * @returns {ModelManager} a new model manager with the decorations applied */ static decorateModels(modelManager: any, decoratorCommandSet: any, options?: any): any; /** * @typedef ExtractDecoratorsResult * @type {object} * @property {ModelManager} modelManager - A model manager containing models stripped without decorators * @property {*} decoratorCommandSet - Stripped out decorators, formed into decorator command sets * @property {string[]} vocabularies - Stripped out vocabularies, formed into vocabulary files */ /** * Extracts all the decorator commands from all the models in modelManager * @param {ModelManager} modelManager the input model manager * @param {object} options - decorator models options * @param {boolean} options.removeDecoratorsFromModel - flag to strip out decorators from models * @param {string} options.locale - locale for extracted vocabulary set * @returns {ExtractDecoratorsResult} - a new model manager with the decorations removed and a list of extracted decorator jsons and vocab yamls */ static extractDecorators(modelManager: any, options: any): { modelManager: any; decoratorCommandSet: any; vocabularies: any; }; /** * Extracts all the vocab decorator commands from all the models in modelManager * @param {ModelManager} modelManager the input model manager * @param {object} options - decorator models options * @param {boolean} options.removeDecoratorsFromModel - flag to strip out vocab decorators from models * @param {string} options.locale - locale for extracted vocabulary set * @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and vocab yamls */ static extractVocabularies(modelManager: any, options: any): { modelManager: any; vocabularies: any; }; /** * Extracts all the non-vocab decorator commands from all the models in modelManager * @param {ModelManager} modelManager the input model manager * @param {object} options - decorator models options * @param {boolean} options.removeDecoratorsFromModel - flag to strip out non-vocab decorators from models * @param {string} options.locale - locale for extracted vocabulary set * @returns {ExtractDecoratorsResult} - a new model manager with/without the decorators and a list of extracted decorator jsons */ static extractNonVocabDecorators(modelManager: any, options: any): { modelManager: any; decoratorCommandSet: any; }; /** * Throws an error if the decoractor command is invalid * @param {ModelManager} validationModelManager the validation model manager * @param {*} command the decorator command */ static validateCommand(validationModelManager: any, command: any): void; /** * Applies a new decorator to the Map element * @private * @param {string} element the element to apply the decorator to * @param {string} target the command target * @param {*} declaration the map declaration * @param {string} type the command type * @param {*} newDecorator the decorator to add */ static applyDecoratorForMapElement(element: any, target: any, declaration: any, type: any, newDecorator: any): void; /** * Compares two arrays. If the first argument is falsy * the function returns true. * @param {string | string[] | null} test the value to test * @param {string[]} values the values to compare * @returns {Boolean} true if the test is falsy or the intersection of * the test and values arrays is not empty (i.e. they have values in common) */ static falsyOrEqual(test: any, values: any): any; /** * Applies a decorator to a decorated model element. * @param {*} decorated the type to apply the decorator to * @param {string} type the command type * @param {*} newDecorator the decorator to add */ static applyDecorator(decorated: any, type: any, newDecorator: any): void; /** * Checks for duplicate decorators added to a decorated model element. * @param {*} decoratedAst ast of the property or the declaration to apply the decorator to * @throws {IllegalModelException} if the decoratedAst has duplicate decorators * @private */ static checkForDuplicateDecorators(decoratedAst: any): void; /** * Executes a Command against a Model Namespace, adding * decorators to the Namespace. * @private * @param {*} model the model * @param {*} command the Command object from the dcs */ static executeNamespaceCommand(model: any, command: any): void; /** * Executes a Command against a Declaration, adding * decorators to the Declaration, or its properties, as required. * @param {string} namespace the namespace for the declaration * @param {*} declaration the class declaration * @param {*} command the Command object from the dcs * @param {*} [property] the property of a declaration, optional, to be passed if the command is for a property * @param {object} [options] - execute command options */ static executeCommand(namespace: any, declaration: any, command: any, property?: any, options?: any): void; /** * Executes a Command against a Property, adding * decorators to the Property as required. * @param {*} property the property * @param {*} command the Command object from the * org.accordproject.decoratorcommands model */ static executePropertyCommand(property: any, command: any): void; /** * Applies the decorator on top of the namespace or else on all declarations * within the namespace. * @private * @param {*} declaration the type to apply the decorator to * @param {string} type the command type * @param {*} decorator the decorator to add * @param {*} target the target object for the decorator */ static checkForNamespaceTargetAndApplyDecorator(declaration: any, type: any, decorator: any, target: any): void; /** * Legacy method. Kept for compatibility. Returns true. * @returns {Boolean} true */ static isNamespaceTargetEnabled(): boolean; /** * converts DCS JSON object into YAML string * validates the input DCS JSON against the DCS model * @param {object} jsonInput the DCS JSON as parsed object * @return {string} the corresponding YAML string */ static jsonToYaml(jsonInput: any): any; /** * converts DCS YAML string into JSON object * validates the output DCS JSON against the DCS model * @param {string} yamlInput the DCS JSON as parsed object * @return {object} the corresponding JSON object */ static yamlToJson(yamlInput: any): any; } export = DecoratorManager;