UNPKG

@accordproject/concerto-core

Version:

Core Implementation for the Concerto Modeling Language

352 lines (351 loc) • 15.7 kB
declare const ModelFile: any; import type { ModelFileSource, ModelManagerOptions } from './types'; type ModelFileInstance = InstanceType<typeof ModelFile>; type ModelFileInput = string | ModelFileInstance; /** * Manages the Concerto model files. * * The structure of {@link Resource}s (Assets, Transactions, Participants) is modelled * in a set of Concerto files. The contents of these files are managed * by the {@link ModelManager}. Each Concerto file has a single namespace and contains * a set of asset, transaction and participant type definitions. * * Concerto applications load their Concerto files and then call the {@link ModelManager#addModelFile addModelFile} * method to register the Concerto file(s) with the ModelManager. * * Use the {@link Concerto} class to validate instances. * * @memberof module:concerto-core */ declare class BaseModelManager { modelFiles: any; processFile: any; factory: any; serializer: any; decoratorFactories: any[]; options: any; decoratorValidation: any; metamodelModelFile: any; /** * Create the ModelManager. * @constructor * @param {object} [options] - ModelManager options, also passed to Serializer * @param {Object} [options.regExp] - An alternative regular expression engine. * @param {boolean} [options.metamodelValidation] - When true, modelfiles will be validated * @param {boolean} [options.addMetamodel] - When true, the Concerto metamodel is added to the model manager * @param {boolean} [options.dangerouslyAllowReservedSystemTypeNamesInUserModels] - Transitional escape hatch; when true, declarations may use reserved system type names * @param {object} [options.decoratorValidation] - the decorator validation configuration * @param {string} [options.decoratorValidation.missingDecorator] - the validation log level for missingDecorator decorators: off, warning, error * @param {string} [options.decoratorValidation.invalidDecorator] - the validation log level for invalidDecorator decorators: off, warning, error * @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager */ constructor(options?: ModelManagerOptions, processFile?: (fileName: string | null, modelInput: string | unknown) => ModelFileSource); /** * Returns true * @returns {boolean} true */ isModelManager(): boolean; /** * Adds root types * @private */ addRootModel(): void; /** * Checks if the import aliasing feature is enabled. * @returns {boolean} true */ isAliasedTypeEnabled(): boolean; /** * Visitor design pattern * @param {Object} visitor - the visitor * @param {Object} parameters - the parameter * @return {Object} the result of visiting or null */ accept(visitor: any, parameters: any): any; /** * Validates a Concerto file (as a string) to the ModelManager. * Concerto files have a single namespace. * * Note that if there are dependencies between multiple files the files * must be added in dependency order, or the addModelFiles method can be * used to add a set of files irrespective of dependencies. * @param {string|ModelFile} modelFile - The Concerto file as a string * @param {string} [fileName] - a file name to associate with the model file * @throws {IllegalModelException} */ validateModelFile(modelFile: any, fileName?: any): void; /** * Adds decorator types * @private */ /** * Adds decorator types * @private */ addDecoratorModel(): void; /** * Throws an error with details about the existing namespace. * @param {ModelFile} modelFile The model file that is trying to declare an existing namespace * @private */ _throwAlreadyExists(modelFile: any): void; /** * Adds a Concerto file (as an AST) to the ModelManager. * Concerto files have a single namespace. If a Concerto file with the * same namespace has already been added to the ModelManager then it * will be replaced. * Note that if there are dependencies between multiple files the files * must be added in dependency order, or the addModelFiles method can be * used to add a set of files irrespective of dependencies. * @param {ModelFile} modelFile - Model as a ModelFile object * @param {string} [cto] - an optional cto string * @param {string} [fileName] - an optional file name to associate with the model file * @param {boolean} [disableValidation] - If true then the model files are not validated * @throws {IllegalModelException} * @return {Object} The newly added model file (internal). */ addModelFile(modelFile: ModelFileInstance, cto?: string | null, fileName?: string | null, disableValidation?: boolean): any; /** * Check that a modelFile is valid with respect to the metamodel. * * @param {ModelFile} modelFile - Model as a ModelFile object * @throws {MetamodelException} - throws if the ModelFile is invalid * @private */ validateAst(modelFile: any): void; /** * Adds a model to the ModelManager. * Concerto files have a single namespace. If a Concerto file with the * same namespace has already been added to the ModelManager then it * will be replaced. * Note that if there are dependencies between multiple files the files * must be added in dependency order, or the addModel method can be * used to add a set of files irrespective of dependencies. * @param {*} modelInput - Model (as a string or object) * @param {string} [cto] - an optional cto string * @param {string} [fileName] - an optional file name to associate with the model file * @param {boolean} [disableValidation] - If true then the model files are not validated * @throws {IllegalModelException} * @return {ModelFile} The newly added model file (internal). */ addModel(modelInput: any, cto?: any, fileName?: any, disableValidation?: any): any; /** * Updates a Concerto file (as a string) on the ModelManager. * Concerto files have a single namespace. If a Concerto file with the * same namespace has already been added to the ModelManager then it * will be replaced. * @param {string|ModelFile} modelFile - Model as a string or object * @param {string} [fileName] - a file name to associate with the model file * @param {boolean} [disableValidation] - If true then the model files are not validated * @throws {IllegalModelException} * @returns {Object} The newly added model file (internal). */ updateModelFile(modelFile: any, fileName?: any, disableValidation?: any): any; /** * Remove the Concerto file for a given namespace * @param {string} namespace - The namespace of the model file to delete. */ deleteModelFile(namespace: any): void; /** * Add a set of Concerto files to the model manager. * @param {string[]|ModelFile[]} modelFiles - An array of models as strings or ModelFile objects. * @param {string[]} [fileNames] - A array of file names to associate with the model files * @param {boolean} [disableValidation] - If true then the model files are not validated * @returns {Object[]} The newly added model files (internal). */ addModelFiles(modelFiles: ModelFileInput[], fileNames?: string[] | null, disableValidation?: boolean): any[]; /** * Validates all models files in this model manager */ validateModelFiles(): void; /** * Downloads all ModelFiles that are external dependencies and adds or * updates them in this ModelManager. * @param {Object} [options] - Options object passed to ModelFileLoaders * @param {FileDownloader} [fileDownloader] - an optional FileDownloader * @throws {IllegalModelException} if the models fail validation * @return {Promise} a promise when the download and update operation is completed. */ updateExternalModels(options?: RequestInit, fileDownloader?: { downloadExternalDependencies(files: ModelFileInstance[], options?: RequestInit): Promise<ModelFileSource[]>; }): Promise<any[]>; /** * Write all models in this model manager to the specified path in the file system * * @param {string} path to a local directory * @param {Object} [options] - Options object * @param {boolean} options.includeExternalModels - * If true, external models are written to the file system. Defaults to true */ writeModelsToFileSystem(path: any, options?: {}): void; /** * Returns the status of the decorator validation options * @returns {object} returns an object that indicates the log levels for defined and undefined decorators */ getDecoratorValidation(): any; /** * Get the array of model file instances * @param {Boolean} [includeConcertoNamespace] - whether to include the concerto namespace * (default to false) * @return {ModelFile[]} The ModelFiles registered * @private */ getModelFiles(includeConcertoNamespace?: boolean): ModelFileInstance[]; /** * Gets all the Concerto models * @param {Object} [options] - Options object * @param {boolean} options.includeExternalModels - * If true, external models are written to the file system. Defaults to true * @return {Array<{name:string, content:string}>} the name and content of each CTO file */ getModels(options?: { includeExternalModels?: boolean; }): { name: string; content: string | null; }[]; /** * Check that the type is valid and returns the FQN of the type. * @param {string} context - error reporting context * @param {string} type - fully qualified type name * @return {string} - the resolved type name (fully qualified) * @throws {IllegalModelException} - if the type is not defined * @private */ resolveType(context: any, type: any): any; /** * Remove all registered Concerto files */ clearModelFiles(): void; /** * Get the ModelFile associated with a namespace * * @param {string} namespace - the namespace containing the ModelFile * @return {ModelFile} registered ModelFile for the namespace or null */ getModelFile(namespace: any): any; /** * Get the ModelFile associated with a file name * * @param {string} fileName - the fileName associated with the ModelFile * @return {ModelFile} registered ModelFile for the namespace or null * @private */ getModelFileByFileName(fileName: any): any; /** * Get the namespaces registered with the ModelManager. * @return {string[]} namespaces - the namespaces that have been registered. */ getNamespaces(): string[]; /** * Look up a type in all registered namespaces. * * @param {string} qualifiedName - fully qualified type name. * @return {ClassDeclaration} - the class declaration for the specified type. * @throws {TypeNotFoundException} - if the type cannot be found or is a primitive type. */ getType(qualifiedName: any): any; /** * Get the AssetDeclarations defined in this model manager * @return {AssetDeclaration[]} the AssetDeclarations defined in the model manager */ getAssetDeclarations(): any; /** * Get the TransactionDeclarations defined in this model manager * @return {TransactionDeclaration[]} the TransactionDeclarations defined in the model manager */ getTransactionDeclarations(): any; /** * Get the EventDeclarations defined in this model manager * @return {EventDeclaration[]} the EventDeclaration defined in the model manager */ getEventDeclarations(): any; /** * Get the ParticipantDeclarations defined in this model manager * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model manager */ getParticipantDeclarations(): any; /** * Get the MapDeclarations defined in this model manager * @return {MapDeclaration[]} the MapDeclaration defined in the model manager */ getMapDeclarations(): any; /** * Get the EnumDeclarations defined in this model manager * @return {EnumDeclaration[]} the EnumDeclaration defined in the model manager */ getEnumDeclarations(): any; /** * Get the Concepts defined in this model manager * @return {ConceptDeclaration[]} the ConceptDeclaration defined in the model manager */ getConceptDeclarations(): any; /** * Get a factory for creating new instances of types defined in this model manager. * @return {Factory} A factory for creating new instances of types defined in this model manager. */ getFactory(): any; /** * Get a serializer for serializing instances of types defined in this model manager. * @return {Serializer} A serializer for serializing instances of types defined in this model manager. */ getSerializer(): any; /** * Get the decorator factories for this model manager. * @return {DecoratorFactory[]} The decorator factories for this model manager. */ getDecoratorFactories(): any[]; /** * Add a decorator factory to this model manager. * @param {DecoratorFactory} factory The decorator factory to add to this model manager. */ addDecoratorFactory(factory: any): void; /** * Checks if this fully qualified type name is derived from another. * @param {string} fqt1 The fully qualified type name to check. * @param {string} fqt2 The fully qualified type name it is may be derived from. * @returns {boolean} True if this instance is an instance of the specified fully * qualified type name, false otherwise. */ derivesFrom(fqt1: any, fqt2: any): boolean; /** * Resolve the namespace for names in the metamodel * @param {object} metaModel - the MetaModel * @return {object} the resolved metamodel */ resolveMetaModel(metaModel: any): any; /** * Populates the model manager from a models metamodel AST * @param {*} ast the metamodel * @param {object} [options] - options for the from ast method * @param {object} [options.disableValidation] - option to disable metamodel validation and just fetch the models, to be used only if the metamodel is already validated */ fromAst(ast: any, options?: any): void; /** * Get the full ast (metamodel instances) for a modelmanager * @param {boolean} [resolve] - whether to resolve names * @param {boolean} [includeConcertoNamespaces] - whether to include the concerto namespaces * @returns {*} the metamodel */ getAst(resolve?: any, includeConcertoNamespaces?: any): { $class: string; models: any[]; }; /** * A function type definition for use as an argument to the filter function * @callback FilterFunction * @param {Declaration} declaration * @returns {boolean} true, if the declaration satisfies the filter function */ /** * Returns a new ModelManager with only the types for which the * filter function returns true. * * ModelFiles with no declarations after filtering will be removed. * * @param {FilterFunction} predicate - the filter function over a Declaration object * @returns {BaseModelManager} - the filtered ModelManager */ filter(predicate: any): BaseModelManager; } export = BaseModelManager;