diff --git a/packages/concerto-core/index.js b/packages/concerto-core/index.js index ee84ba0c95..74a7b600da 100644 --- a/packages/concerto-core/index.js +++ b/packages/concerto-core/index.js @@ -22,71 +22,107 @@ */ // Exceptions -module.exports.SecurityException = require('./lib/securityexception'); -module.exports.IllegalModelException = require('./lib/introspect/illegalmodelexception'); -module.exports.TypeNotFoundException = require('./lib/typenotfoundexception'); +const SecurityException = require('./lib/securityexception'); +const IllegalModelException = require('./lib/introspect/illegalmodelexception'); +const TypeNotFoundException = require('./lib/typenotfoundexception'); // Decorated -module.exports.Decorator = require('./lib/introspect/decorator'); -module.exports.DecoratorFactory = require('./lib/introspect/decoratorfactory'); +const Decorator = require('./lib/introspect/decorator'); +const DecoratorFactory = require('./lib/introspect/decoratorfactory'); // ClassDeclarations -module.exports.ClassDeclaration = require('./lib/introspect/classdeclaration'); -module.exports.IdentifiedDeclaration = require('./lib/introspect/identifieddeclaration'); -module.exports.AssetDeclaration = require('./lib/introspect/assetdeclaration'); -module.exports.ConceptDeclaration = require('./lib/introspect/conceptdeclaration'); -module.exports.EnumValueDeclaration = require('./lib/introspect/enumvaluedeclaration'); -module.exports.EventDeclaration = require('./lib/introspect/eventdeclaration'); -module.exports.ParticipantDeclaration = require('./lib/introspect/participantdeclaration'); -module.exports.TransactionDeclaration = require('./lib/introspect/transactiondeclaration'); +const ClassDeclaration = require('./lib/introspect/classdeclaration'); +const IdentifiedDeclaration = require('./lib/introspect/identifieddeclaration'); +const AssetDeclaration = require('./lib/introspect/assetdeclaration'); +const ConceptDeclaration = require('./lib/introspect/conceptdeclaration'); +const EnumValueDeclaration = require('./lib/introspect/enumvaluedeclaration'); +const EventDeclaration = require('./lib/introspect/eventdeclaration'); +const ParticipantDeclaration = require('./lib/introspect/participantdeclaration'); +const TransactionDeclaration = require('./lib/introspect/transactiondeclaration'); // Properties -module.exports.Property = require('./lib/introspect/property'); -module.exports.Field = require('./lib/introspect/field'); -module.exports.EnumDeclaration = require('./lib/introspect/enumdeclaration'); -module.exports.RelationshipDeclaration = require('./lib/introspect/relationshipdeclaration'); +const Property = require('./lib/introspect/property'); +const Field = require('./lib/introspect/field'); +const EnumDeclaration = require('./lib/introspect/enumdeclaration'); +const RelationshipDeclaration = require('./lib/introspect/relationshipdeclaration'); // Typed -module.exports.Typed = require('./lib/model/typed'); +const Typed = require('./lib/model/typed'); // Identifiables -module.exports.Identifiable = require('./lib/model/identifiable'); -module.exports.Relationship = require('./lib/model/relationship'); -module.exports.Resource = require('./lib/model/resource'); +const Identifiable = require('./lib/model/identifiable'); +const Relationship = require('./lib/model/relationship'); +const Resource = require('./lib/model/resource'); // Factory -module.exports.Factory = require('./lib/factory'); +const Factory = require('./lib/factory'); // Globalize -module.exports.Globalize = require('./lib/globalize'); +const Globalize = require('./lib/globalize'); // Introspector -module.exports.Introspector = require('./lib/introspect/introspector'); +const Introspector = require('./lib/introspect/introspector'); // ModelFile -module.exports.ModelFile = require('./lib/introspect/modelfile'); +const ModelFile = require('./lib/introspect/modelfile'); // ModelManager -module.exports.ModelManager = require('./lib/modelmanager'); +const ModelManager = require('./lib/modelmanager'); // Serializer -module.exports.Serializer = require('./lib/serializer'); +const Serializer = require('./lib/serializer'); // ModelUtil -module.exports.ModelUtil = require('./lib/modelutil'); +const ModelUtil = require('./lib/modelutil'); // ModelLoader -module.exports.ModelLoader = require('./lib/modelloader'); +const ModelLoader = require('./lib/modelloader'); // DateTimeUtil -module.exports.DateTimeUtil = require('./lib/datetimeutil'); +const DateTimeUtil = require('./lib/datetimeutil'); // Concerto -module.exports.Concerto = require('./lib/concerto'); +const Concerto = require('./lib/concerto'); // MetaModel -module.exports.MetaModel = require('./lib/introspect/metamodel'); +const MetaModel = require('./lib/introspect/metamodel'); // Version -module.exports.version = require('./package.json'); +const version = require('./package.json'); + +module.exports = { + SecurityException, + IllegalModelException, + TypeNotFoundException, + Decorator, + DecoratorFactory, + ClassDeclaration, + IdentifiedDeclaration, + AssetDeclaration, + ConceptDeclaration, + EnumValueDeclaration, + EventDeclaration, + ParticipantDeclaration, + TransactionDeclaration, + Property, + Field, + EnumDeclaration, + RelationshipDeclaration, + Typed, + Identifiable, + Relationship, + Resource, + Factory, + Globalize, + Introspector, + ModelFile, + ModelManager, + Serializer, + ModelUtil, + ModelLoader, + DateTimeUtil, + Concerto, + MetaModel, + version +}; diff --git a/packages/concerto-core/types/index.d.ts b/packages/concerto-core/types/index.d.ts index 60ceb2d2f6..8c1770eaa6 100644 --- a/packages/concerto-core/types/index.d.ts +++ b/packages/concerto-core/types/index.d.ts @@ -1,33 +1,33 @@ -export var SecurityException: typeof import("./lib/securityexception"); -export var IllegalModelException: typeof import("./lib/introspect/illegalmodelexception"); -export var TypeNotFoundException: typeof import("./lib/typenotfoundexception"); -export var Decorator: typeof import("./lib/introspect/decorator"); -export var DecoratorFactory: typeof import("./lib/introspect/decoratorfactory"); -export var ClassDeclaration: typeof import("./lib/introspect/classdeclaration"); -export var IdentifiedDeclaration: typeof import("./lib/introspect/identifieddeclaration"); -export var AssetDeclaration: typeof import("./lib/introspect/assetdeclaration"); -export var ConceptDeclaration: typeof import("./lib/introspect/conceptdeclaration"); -export var EnumValueDeclaration: typeof import("./lib/introspect/enumvaluedeclaration"); -export var EventDeclaration: typeof import("./lib/introspect/eventdeclaration"); -export var ParticipantDeclaration: typeof import("./lib/introspect/participantdeclaration"); -export var TransactionDeclaration: typeof import("./lib/introspect/transactiondeclaration"); -export var Property: typeof import("./lib/introspect/property"); -export var Field: typeof import("./lib/introspect/field"); -export var EnumDeclaration: typeof import("./lib/introspect/enumdeclaration"); -export var RelationshipDeclaration: typeof import("./lib/introspect/relationshipdeclaration"); -export var Typed: typeof import("./lib/model/typed"); -export var Identifiable: typeof import("./lib/model/identifiable"); -export var Relationship: typeof import("./lib/model/relationship"); -export var Resource: typeof import("./lib/model/resource"); -export var Factory: typeof import("./lib/factory"); -export var Globalize: typeof import("./lib/globalize"); -export var Introspector: typeof import("./lib/introspect/introspector"); -export var ModelFile: typeof import("./lib/introspect/modelfile"); -export var ModelManager: typeof import("./lib/modelmanager"); -export var Serializer: typeof import("./lib/serializer"); -export var ModelUtil: typeof import("./lib/modelutil"); -export var ModelLoader: typeof import("./lib/modelloader"); -export var DateTimeUtil: typeof import("./lib/datetimeutil"); -export var Concerto: typeof import("./lib/concerto"); -export var MetaModel: typeof import("./lib/introspect/metamodel"); -export var version: any; +import SecurityException = require("./lib/securityexception"); +import IllegalModelException = require("./lib/introspect/illegalmodelexception"); +import TypeNotFoundException = require("./lib/typenotfoundexception"); +import Decorator = require("./lib/introspect/decorator"); +import DecoratorFactory = require("./lib/introspect/decoratorfactory"); +import ClassDeclaration = require("./lib/introspect/classdeclaration"); +import IdentifiedDeclaration = require("./lib/introspect/identifieddeclaration"); +import AssetDeclaration = require("./lib/introspect/assetdeclaration"); +import ConceptDeclaration = require("./lib/introspect/conceptdeclaration"); +import EnumValueDeclaration = require("./lib/introspect/enumvaluedeclaration"); +import EventDeclaration = require("./lib/introspect/eventdeclaration"); +import ParticipantDeclaration = require("./lib/introspect/participantdeclaration"); +import TransactionDeclaration = require("./lib/introspect/transactiondeclaration"); +import Property = require("./lib/introspect/property"); +import Field = require("./lib/introspect/field"); +import EnumDeclaration = require("./lib/introspect/enumdeclaration"); +import RelationshipDeclaration = require("./lib/introspect/relationshipdeclaration"); +import Typed = require("./lib/model/typed"); +import Identifiable = require("./lib/model/identifiable"); +import Relationship = require("./lib/model/relationship"); +import Resource = require("./lib/model/resource"); +import Factory = require("./lib/factory"); +import Globalize = require("./lib/globalize"); +import Introspector = require("./lib/introspect/introspector"); +import ModelFile = require("./lib/introspect/modelfile"); +import ModelManager = require("./lib/modelmanager"); +import Serializer = require("./lib/serializer"); +import ModelUtil = require("./lib/modelutil"); +import ModelLoader = require("./lib/modelloader"); +import DateTimeUtil = require("./lib/datetimeutil"); +import Concerto = require("./lib/concerto"); +import MetaModel = require("./lib/introspect/metamodel"); +export { SecurityException, IllegalModelException, TypeNotFoundException, Decorator, DecoratorFactory, ClassDeclaration, IdentifiedDeclaration, AssetDeclaration, ConceptDeclaration, EnumValueDeclaration, EventDeclaration, ParticipantDeclaration, TransactionDeclaration, Property, Field, EnumDeclaration, RelationshipDeclaration, Typed, Identifiable, Relationship, Resource, Factory, Globalize, Introspector, ModelFile, ModelManager, Serializer, ModelUtil, ModelLoader, DateTimeUtil, Concerto, MetaModel, version }; diff --git a/packages/concerto-core/types/lib/basemodelmanager.d.ts b/packages/concerto-core/types/lib/basemodelmanager.d.ts new file mode 100644 index 0000000000..37e4a9a07e --- /dev/null +++ b/packages/concerto-core/types/lib/basemodelmanager.d.ts @@ -0,0 +1,281 @@ +export = BaseModelManager; +/** + * 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 { + /** + * Create the ModelManager. + * @constructor + * @param {object} [options] - Serializer options + * @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager + */ + constructor(options?: object, processFile?: any); + processFile: any; + modelFiles: {}; + factory: Factory; + serializer: Serializer; + decoratorFactories: any[]; + /** + * Returns true + * @returns {boolean} true + */ + isModelManager(): boolean; + /** + * Adds root types + * @private + */ + private addRootModel; + /** + * 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: string | ModelFile, fileName?: string): 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 + */ + private _throwAlreadyExists; + /** + * 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: ModelFile, cto?: string, fileName?: string, disableValidation?: boolean): any; + /** + * 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 {Object} The newly added model file (internal). + */ + addModel(modelInput: any, cto?: string, fileName?: string, disableValidation?: boolean): 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: string | ModelFile, fileName?: string, disableValidation?: boolean): any; + /** + * Remove the Concerto file for a given namespace + * @param {string} namespace - The namespace of the model file to delete. + */ + deleteModelFile(namespace: string): 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: string[] | ModelFile[], fileNames?: string[], 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?: any, fileDownloader?: typeof import("@accordproject/concerto-util/types/lib/filedownloader")): Promise; + /** + * 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: string, options?: { + includeExternalModels: boolean; + }): void; + /** + * 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 + */ + private getModelFiles; + /** + * 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; + }): Array<{ + name: string; + content: string; + }>; + /** + * 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 + */ + private resolveType; + /** + * 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: string): ModelFile; + /** + * 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 + */ + private getModelFileByFileName; + /** + * 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: string): ClassDeclaration; + /** + * Get the AssetDeclarations defined in this model manager + * @return {AssetDeclaration[]} the AssetDeclarations defined in the model manager + */ + getAssetDeclarations(): AssetDeclaration[]; + /** + * Get the TransactionDeclarations defined in this model manager + * @return {TransactionDeclaration[]} the TransactionDeclarations defined in the model manager + */ + getTransactionDeclarations(): TransactionDeclaration[]; + /** + * Get the EventDeclarations defined in this model manager + * @return {EventDeclaration[]} the EventDeclaration defined in the model manager + */ + getEventDeclarations(): EventDeclaration[]; + /** + * Get the ParticipantDeclarations defined in this model manager + * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model manager + */ + getParticipantDeclarations(): ParticipantDeclaration[]; + /** + * Get the EnumDeclarations defined in this model manager + * @return {EnumDeclaration[]} the EnumDeclaration defined in the model manager + */ + getEnumDeclarations(): EnumDeclaration[]; + /** + * Get the Concepts defined in this model manager + * @return {ConceptDeclaration[]} the ConceptDeclaration defined in the model manager + */ + getConceptDeclarations(): ConceptDeclaration[]; + /** + * 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(): Factory; + /** + * 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(): Serializer; + /** + * Get the decorator factories for this model manager. + * @return {DecoratorFactory[]} The decorator factories for this model manager. + */ + getDecoratorFactories(): DecoratorFactory[]; + /** + * Add a decorator factory to this model manager. + * @param {DecoratorFactory} factory The decorator factory to add to this model manager. + */ + addDecoratorFactory(factory: DecoratorFactory): 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: string, fqt2: string): boolean; + /** + * Resolve the namespace for names in the metamodel + * @param {object} metaModel - the MetaModel + * @return {object} the resolved metamodel + */ + resolveMetaModel(metaModel: object): object; + /** + * Get the full ast (metamodel instances) for a modelmanager + * @param {boolean} [resolve] - whether to resolve names + * @returns {*} the metamodel + */ + getAst(resolve?: boolean): any; +} +import Factory = require("./factory"); +import Serializer = require("./serializer"); +import ModelFile = require("./introspect/modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts index c2787f7067..48676484da 100644 --- a/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts @@ -18,4 +18,10 @@ declare class AssetDeclaration { * @throws {IllegalModelException} */ constructor(modelFile: ModelFile, ast: any); + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } diff --git a/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts index 8ba56c64f0..214e22b8fe 100644 --- a/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts @@ -11,5 +11,11 @@ export = ConceptDeclaration; * @memberof module:concerto-core */ declare class ConceptDeclaration extends ClassDeclaration { + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts index 7a4cc6f9df..720effff3c 100644 --- a/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts @@ -8,5 +8,11 @@ export = EnumDeclaration; * @memberof module:concerto-core */ declare class EnumDeclaration extends ClassDeclaration { + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts index 4ff0dde7b6..7e8057513f 100644 --- a/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts @@ -20,4 +20,10 @@ declare class EventDeclaration { * @private */ private process; + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } diff --git a/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts index 9d18ca2ebf..0400d27f9c 100644 --- a/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts +++ b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts @@ -1,5 +1,4 @@ export = IllegalModelException; -declare const IllegalModelException_base: typeof import("@accordproject/concerto-cto/types/lib/basefileexception"); /** * Exception throws when a composer file is semantically invalid * @extends BaseFileException @@ -7,7 +6,7 @@ declare const IllegalModelException_base: typeof import("@accordproject/concerto * @class * @memberof module:concerto-core */ -declare class IllegalModelException extends IllegalModelException_base { +declare class IllegalModelException { /** * Create an IllegalModelException. * @param {string} message - the message for the exception diff --git a/packages/concerto-core/types/lib/introspect/metamodel.d.ts b/packages/concerto-core/types/lib/introspect/metamodel.d.ts index 8e892bae51..43932c0032 100644 --- a/packages/concerto-core/types/lib/introspect/metamodel.d.ts +++ b/packages/concerto-core/types/lib/introspect/metamodel.d.ts @@ -1,52 +1,18 @@ -export = MetaModel; /** - * Class to work with the Concerto metamodel + * Create a metamodel manager (for validation against the metamodel) + * @return {*} the metamodel manager */ -declare class MetaModel { - /** - * Returns the metamodel CTO - * @returns {string} the metamodel as a CTO string - */ - static getMetaModelCto(): string; - /** - * Create a metamodel manager (for validation against the metamodel) - * @return {*} the metamodel manager - */ - static createMetaModelManager(): any; - /** - * Validate against the metamodel - * @param {object} input - the metamodel in JSON - * @return {object} the validated metamodel in JSON - */ - static validateMetaModel(input: object): object; - /** - * Resolve the namespace for names in the metamodel - * @param {object} modelManager - the ModelManager - * @param {object} metaModel - the MetaModel - * @param {boolean} [validate] - whether to perform validation - * @return {object} the resolved metamodel - */ - static resolveMetaModel(modelManager: object, metaModel: object, validate?: boolean): object; - /** - * Export metamodel from a model file - * @param {object} modelFile - the ModelFile - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model - */ - static modelFileToMetaModel(modelFile: object, validate?: boolean): object; - /** - * Export metamodel from a model manager - * @param {object} modelManager - the ModelManager - * @param {boolean} [resolve] - whether to resolve names - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model manager - */ - static modelManagerToMetaModel(modelManager: object, resolve?: boolean, validate?: boolean): object; - /** - * Import metamodel to a model manager - * @param {object} metaModel - the metamodel - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model manager - */ - static modelManagerFromMetaModel(metaModel: object, validate?: boolean): object; -} +export function newMetaModelManager(): any; +/** + * Validate metamodel instance against the metamodel + * @param {object} input - the metamodel instance in JSON + * @return {object} the validated metamodel instance in JSON + */ +export function validateMetaModel(input: object): object; +/** + * Import metamodel to a model manager + * @param {object} metaModel - the metamodel + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model manager + */ +export function modelManagerFromMetaModel(metaModel: object, validate?: boolean): object; diff --git a/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts index b475aeff19..094277eedf 100644 --- a/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts @@ -14,4 +14,10 @@ declare class ParticipantDeclaration { * @throws {IllegalModelException} */ constructor(modelFile: ModelFile, ast: any); + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } diff --git a/packages/concerto-core/types/lib/introspect/property.d.ts b/packages/concerto-core/types/lib/introspect/property.d.ts index 79ab135cdb..c96ba3298e 100644 --- a/packages/concerto-core/types/lib/introspect/property.d.ts +++ b/packages/concerto-core/types/lib/introspect/property.d.ts @@ -25,6 +25,13 @@ declare class Property extends Decorated { type: any; array: boolean; optional: boolean; + /** + * Validate the property + * @param {ClassDeclaration} classDecl the class declaration of the property + * @throws {IllegalModelException} + * @private + */ + private validate; /** * Returns the name of a property * @return {string} the name of this field diff --git a/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts index f9b3860b52..ae4d296b5e 100644 --- a/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts @@ -14,4 +14,10 @@ declare class TransactionDeclaration { * @throws {IllegalModelException} */ constructor(modelFile: ModelFile, ast: any); + /** + * Returns the kind of declaration + * + * @return {string} what kind of declaration this is + */ + declarationKind(): string; } diff --git a/packages/concerto-core/types/lib/model/resource.d.ts b/packages/concerto-core/types/lib/model/resource.d.ts index 1f5791fb06..3b35d88f66 100644 --- a/packages/concerto-core/types/lib/model/resource.d.ts +++ b/packages/concerto-core/types/lib/model/resource.d.ts @@ -31,5 +31,12 @@ declare class Resource extends Identifiable { * false if not. */ isIdentifiable(): boolean; + /** + * Serialize this resource into a JavaScript object suitable for serialization to JSON, + * using the default options for the serializer. If you need to set additional options + * for the serializer, use the {@link Serializer#toJSON} method instead. + * @return {Object} A JavaScript object suitable for serialization to JSON. + */ + toJSON(): any; } import Identifiable = require("./identifiable"); diff --git a/packages/concerto-core/types/lib/modelmanager.d.ts b/packages/concerto-core/types/lib/modelmanager.d.ts index 9f20992947..4034622da0 100644 --- a/packages/concerto-core/types/lib/modelmanager.d.ts +++ b/packages/concerto-core/types/lib/modelmanager.d.ts @@ -1,6 +1,6 @@ export = ModelManager; /** - * Manages the Concerto model files. + * Manages the Concerto model files in CTO format. * * The structure of {@link Resource}s (Assets, Transactions, Participants) is modelled * in a set of Concerto files. The contents of these files are managed @@ -10,246 +10,24 @@ export = ModelManager; * 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 ModelManager { +declare class ModelManager extends BaseModelManager { /** * Create the ModelManager. * @constructor * @param {object} [options] - Serializer options */ constructor(options?: object); - modelFiles: {}; - factory: Factory; - serializer: Serializer; - decoratorFactories: any[]; - /** - * Returns true - * @returns {boolean} true - */ - isModelManager(): boolean; - /** - * Adds root types - * @private - */ - private addRootModel; /** - * 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: string | ModelFile, fileName?: string): 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 - */ - private _throwAlreadyExists; - /** - * Adds a Concerto file (as a string) 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 {string|ModelFile} modelFile - Model as a string or object - * @param {string} fileName - an optional file name to associate with the model file + * Adds a model in CTO format to the ModelManager. + * This is a convenience function equivalent to `addModel` but useful since it avoids having to copy the input CTO. + * @param {string} cto - a 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: string | ModelFile, fileName: string, disableValidation?: boolean): 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: string | ModelFile, fileName?: string, disableValidation?: boolean): any; - /** - * Remove the Concerto file for a given namespace - * @param {string} namespace - The namespace of the model file to delete. - */ - deleteModelFile(namespace: string): 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: string[] | ModelFile[], fileNames?: string[], 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?: any, fileDownloader?: typeof import("@accordproject/concerto-util/types/lib/filedownloader")): Promise; - /** - * 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: string, options?: { - includeExternalModels: boolean; - }): void; - /** - * 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 - */ - private getModelFiles; - /** - * 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; - }): Array<{ - name: string; - content: string; - }>; - /** - * 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 - */ - private resolveType; - /** - * 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: string): ModelFile; - /** - * 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 - */ - private getModelFileByFileName; - /** - * 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: string): ClassDeclaration; - /** - * Get the AssetDeclarations defined in this model manager - * @return {AssetDeclaration[]} the AssetDeclarations defined in the model manager - */ - getAssetDeclarations(): AssetDeclaration[]; - /** - * Get the TransactionDeclarations defined in this model manager - * @return {TransactionDeclaration[]} the TransactionDeclarations defined in the model manager - */ - getTransactionDeclarations(): TransactionDeclaration[]; - /** - * Get the EventDeclarations defined in this model manager - * @return {EventDeclaration[]} the EventDeclaration defined in the model manager - */ - getEventDeclarations(): EventDeclaration[]; - /** - * Get the ParticipantDeclarations defined in this model manager - * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model manager - */ - getParticipantDeclarations(): ParticipantDeclaration[]; - /** - * Get the EnumDeclarations defined in this model manager - * @return {EnumDeclaration[]} the EnumDeclaration defined in the model manager - */ - getEnumDeclarations(): EnumDeclaration[]; - /** - * Get the Concepts defined in this model manager - * @return {ConceptDeclaration[]} the ConceptDeclaration defined in the model manager - */ - getConceptDeclarations(): ConceptDeclaration[]; - /** - * 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(): Factory; - /** - * 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(): Serializer; - /** - * Get the decorator factories for this model manager. - * @return {DecoratorFactory[]} The decorator factories for this model manager. - */ - getDecoratorFactories(): DecoratorFactory[]; - /** - * Add a decorator factory to this model manager. - * @param {DecoratorFactory} factory The decorator factory to add to this model manager. - */ - addDecoratorFactory(factory: DecoratorFactory): 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: string, fqt2: string): boolean; - /** - * Get the full metamodel for a modelmanager - * @returns {*} the metamodel - */ - getMetaModel(): any; + addCTOModel(cto: string, fileName?: string, disableValidation?: boolean): any; } -import Factory = require("./factory"); -import Serializer = require("./serializer"); -import ModelFile = require("./introspect/modelfile"); +import BaseModelManager = require("./basemodelmanager"); diff --git a/packages/concerto-core/types/lib/rootmodel.d.ts b/packages/concerto-core/types/lib/rootmodel.d.ts new file mode 100644 index 0000000000..4c27d82445 --- /dev/null +++ b/packages/concerto-core/types/lib/rootmodel.d.ts @@ -0,0 +1,3 @@ +export const rootModelFile: "concerto.cto"; +export const rootModelCto: "namespace concerto\nabstract concept Concept {}\nabstract concept Asset identified {}\nabstract concept Participant identified {}\nabstract concept Transaction {}\nabstract concept Event {}\n"; +export { rootModelAst }; diff --git a/packages/concerto-core/types/lib/securityexception.d.ts b/packages/concerto-core/types/lib/securityexception.d.ts index eee21bbbb4..b9c2ac7d83 100644 --- a/packages/concerto-core/types/lib/securityexception.d.ts +++ b/packages/concerto-core/types/lib/securityexception.d.ts @@ -1,5 +1,4 @@ export = SecurityException; -declare const SecurityException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception"); /** * Class representing a security exception * @extends BaseException @@ -7,7 +6,7 @@ declare const SecurityException_base: typeof import("@accordproject/concerto-cto * @class * @memberof module:concerto-core */ -declare class SecurityException extends SecurityException_base { +declare class SecurityException { /** * Create the SecurityException. * @param {string} message - The exception message. diff --git a/packages/concerto-core/types/lib/serializer/validationexception.d.ts b/packages/concerto-core/types/lib/serializer/validationexception.d.ts index ab6c91657f..f79b4bd82a 100644 --- a/packages/concerto-core/types/lib/serializer/validationexception.d.ts +++ b/packages/concerto-core/types/lib/serializer/validationexception.d.ts @@ -1,5 +1,4 @@ export = ValidationException; -declare const ValidationException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception"); /** * Exception thrown when a resource fails to model against the model * @extends BaseException @@ -8,5 +7,11 @@ declare const ValidationException_base: typeof import("@accordproject/concerto-c * @memberof module:concerto-core * @private */ -declare class ValidationException extends ValidationException_base { +declare class ValidationException { + /** + * Create a ValidationException + * @param {string} message - the message for the exception + * @param {string} component - the optional component which throws this error + */ + constructor(message: string, component: string); } diff --git a/packages/concerto-core/types/lib/typenotfoundexception.d.ts b/packages/concerto-core/types/lib/typenotfoundexception.d.ts index eb8f4668e5..8fc95d06d5 100644 --- a/packages/concerto-core/types/lib/typenotfoundexception.d.ts +++ b/packages/concerto-core/types/lib/typenotfoundexception.d.ts @@ -1,5 +1,4 @@ export = TypeNotFoundException; -declare const TypeNotFoundException_base: typeof import("@accordproject/concerto-cto/types/lib/baseexception"); /** * Error thrown when a Concerto type does not exist. * @extends BaseException @@ -7,7 +6,7 @@ declare const TypeNotFoundException_base: typeof import("@accordproject/concerto * @class * @memberof module:concerto-core */ -declare class TypeNotFoundException extends TypeNotFoundException_base { +declare class TypeNotFoundException { /** * Constructor. If the optional 'message' argument is not supplied, it will be set to a default value that * includes the type name.