diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 5e6ce68cac..be41e4b541 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -2,36 +2,36 @@ class BaseException extends Error { + void constructor(string,string) } class BaseFileException extends BaseException { - + void constructor(string,string,string,string,string) + + void constructor(string,string,string,string?,string?) + string getFileLocation() + string getShortMessage() + string getFileName() } class Concerto { - + void constructor() - + void validate(undefined) throws Error + + void constructor(modelManager) + + void validate(obj,options?) throws Error + void getModelManager() - + boolean isObject() - + void getTypeDeclaration() - + string getIdentifier() - + boolean isIdentifiable() - + boolean isRelationship() - + void setIdentifier(string) - + string getFullyQualifiedIdentifier() - + string toURI() + + boolean isObject(obj) + + void getTypeDeclaration(obj) + + string getIdentifier(obj) + + boolean isIdentifiable(obj) + + boolean isRelationship(obj) + + void setIdentifier(obj,string) + + string getFullyQualifiedIdentifier(obj) + + string toURI(obj) + void fromURI(string) throws Error - + string getType() - + string getNamespace() + + string getType(obj) + + string getNamespace(obj) } + object setCurrentTime() class Factory { + string newId() + void constructor(ModelManager) - + Resource newResource(String,String,String,Object,boolean,String,boolean) throws TypeNotFoundException - + Resource newConcept(String,String,String,Object,boolean,String,boolean) throws TypeNotFoundException + + Resource newResource(String,String,String?,Object?,boolean?,String?,boolean?) throws TypeNotFoundException + + Resource newConcept(String,String,String?,Object?,boolean?,String?,boolean?) throws TypeNotFoundException + Relationship newRelationship(String,String,String) throws TypeNotFoundException - + Resource newTransaction(String,String,String,Object,String,boolean) - + Resource newEvent(String,String,String,Object,String,boolean) + + Resource newTransaction(String,String,String?,Object?,String?,boolean?) + + Resource newEvent(String,String,String?,Object?,String?,boolean?) } class AssetDeclaration extends IdentifiedDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException @@ -69,13 +69,13 @@ class ConceptDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException } class Decorator { - + void constructor(Object) throws IllegalModelException + + void constructor(ClassDeclaration|Property,Object) throws IllegalModelException + void getParent() + string getName() + object[] getArguments() } class DecoratorFactory { - + Decorator newDecorator(Object) + + Decorator newDecorator(ClassDeclaration|Property,Object) } class EnumDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException @@ -92,7 +92,7 @@ class IdentifiedDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException } class IllegalModelException extends BaseFileException { - + void constructor(string,ModelFile,Object,number,number,number,number,string) + + void constructor(string,ModelFile?,Object?,number,number,number,number,string?) } class Introspector { + void constructor(ModelManager) @@ -101,30 +101,30 @@ class Introspector { } class ModelFileDownloader { + void constructor(ModelFileLoader,Number) - + Promise downloadExternalDependencies(ModelFile[],Object) + + Promise downloadExternalDependencies(ModelFile[],Object?) + Promise runJob(Object,Object) } class MetaModel { + void createMetaModelManager() + object validateMetaModel(object) - + object createNameTable(object) + + object createNameTable(modelManager,object) + string resolveName(string,object) + object resolveTypeNames(object,object) + object resolveMetaModel(object,object) - + object modelFileToMetaModel(object,boolean) - + object modelManagerToMetaModel(object,boolean,boolean) + + object modelFileToMetaModel(object,boolean?) + + object modelManagerToMetaModel(object,boolean?,boolean?) + string decoratorArgFromMetaModel(object) + string decoratorFromMetaModel(object) + string decoratorsFromMetaModel(object,string) + string propertyFromMetaModel(object) + string declFromMetaModel(object) - + string ctoFromMetaModel(object,boolean) - + object modelManagerFromMetaModel(object,boolean) - + object ctoToMetaModel(string,boolean) - + object ctoToMetaModelAndResolve(string,boolean) + + string ctoFromMetaModel(object,boolean?) + + object modelManagerFromMetaModel(object,boolean?) + + object ctoToMetaModel(string,boolean?) + + object ctoToMetaModelAndResolve(modelManager,string,boolean?) } class ModelFile { - + void constructor(ModelManager,string,string) throws IllegalModelException + + void constructor(ModelManager,string,string?) throws IllegalModelException + boolean isModelFile() + Boolean isSystemModelFile() + boolean isExternal() @@ -187,7 +187,7 @@ class Identifiable extends Typed { class Relationship extends Identifiable { + String toString() + boolean isRelationship() - + Relationship fromURI(ModelManager,String,String,String) + + Relationship fromURI(ModelManager,String,String?,String?) } class Resource extends Identifiable { + String toString() @@ -210,22 +210,22 @@ class ValidatedResource extends Resource { + void validate() throws Error } class ModelLoader { - + object loadModelManager(string[],object,boolean,number) - + object loadModelManagerFromModelFiles(object[],undefined,object,boolean,number) + + object loadModelManager(string[],object,boolean?,number?) + + object loadModelManagerFromModelFiles(object[],string[],object,boolean?,number?) } class ModelManager { - + void constructor(object) + + void constructor(object?) + boolean isModelManager() + Object accept(Object,Object) - + void validateModelFile(string,string) throws IllegalModelException - + Object addModelFile(string,string,boolean) throws IllegalModelException - + Object updateModelFile(string,string,boolean) throws IllegalModelException + + void validateModelFile(string,string?) throws IllegalModelException + + Object addModelFile(string|ModelFile,string,boolean?) throws IllegalModelException + + Object updateModelFile(string|ModelFile,string?,boolean?) throws IllegalModelException + void deleteModelFile(string) - + Object[] addModelFiles(object[],undefined,boolean) + + Object[] addModelFiles(|,string[],boolean?) + void validateModelFiles() - + Promise updateExternalModels(Object,ModelFileDownloader) throws IllegalModelException - + void writeModelsToFileSystem(string,Object,boolean) - + Object[] getModels(Object,boolean) + + Promise updateExternalModels(Object?,ModelFileDownloader?) throws IllegalModelException + + void writeModelsToFileSystem(string,Object?,boolean) + + Object[] getModels(Object?,boolean) + void clearModelFiles() + ModelFile getModelFile(string) + string[] getNamespaces() @@ -245,10 +245,10 @@ class SecurityException extends BaseException { + void constructor(string) } class Serializer { - + void constructor(Factory,ModelManager,object) + + void constructor(Factory,ModelManager,object?) + void setDefaultOptions(Object) - + Object toJSON(Resource,Object,boolean,boolean,boolean,boolean,boolean,number) throws Error - + Resource fromJSON(Object,Object,boolean,boolean,number) + + Object toJSON(Resource,Object?,boolean?,boolean?,boolean?,boolean?,boolean?,number?) throws Error + + Resource fromJSON(Object,Object,boolean,boolean,number?) } class TypedStack { + void constructor(Object) @@ -258,6 +258,6 @@ class TypedStack { + void clear() } class TypeNotFoundException extends BaseException { - + void constructor(string,string,string) + + void constructor(string,string?,string) + string getTypeName() } diff --git a/packages/concerto-core/changelog.txt b/packages/concerto-core/changelog.txt index 5b3fe9b9b4..18454a0b4d 100644 --- a/packages/concerto-core/changelog.txt +++ b/packages/concerto-core/changelog.txt @@ -24,9 +24,10 @@ # Note that the latest public API is documented using JSDocs and is available in api.txt. # -Version 1.2.2 {cf9d5dad911076e149b7013afe24e3dc} 2021-11-22 +Version 1.2.2 {0ed9b2150eb03a620e66b1fd6a2833b5} 2021-11-22 - Remove custom instanceof and add methods to check runtime type - Remove support for Node 12 +- Generate Typescript definitions from JSDoc - Parser directly constructs metamodel instance - Convert MetaModel to a class for Typescript + Webpack compatability - Update Acorn to latest and refactor the JavaScript parser so we can use static class members diff --git a/packages/concerto-core/lib/modelmanager.js b/packages/concerto-core/lib/modelmanager.js index f560ed84be..9f683efde2 100644 --- a/packages/concerto-core/lib/modelmanager.js +++ b/packages/concerto-core/lib/modelmanager.js @@ -132,7 +132,7 @@ abstract concept Event {} * 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 - The Concerto file as a string + * @param {string|ModelFile} modelFile - Model as a string or object * @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} @@ -167,7 +167,7 @@ abstract concept Event {} * 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 - The Concerto file as a string + * @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} @@ -206,7 +206,7 @@ abstract concept Event {} /** * Add a set of Concerto files to the model manager. - * @param {object[]} modelFiles - An array of Concerto files as strings or ModelFile objects. + * @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). diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index 79652b7933..515f95eaed 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -21,7 +21,7 @@ "test:watch": "nyc mocha --watch --recursive -t 10000", "mocha": "mocha --recursive -t 10000", "nyc": "nyc mocha --recursive -t 10000", - "build:types" : "npx -p typescript tsc lib/**/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" + "build:types" : "npx -p typescript tsc ./lib/**/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", diff --git a/packages/concerto-core/scripts/javascriptparser.js b/packages/concerto-core/scripts/javascriptparser.js index 456b654258..58717ed0ec 100644 --- a/packages/concerto-core/scripts/javascriptparser.js +++ b/packages/concerto-core/scripts/javascriptparser.js @@ -461,13 +461,55 @@ class JavaScriptParser { } } - if (tag.type.name) { - paramTypes.push(tag.type.name); - } else if (tag.type.applications) { - paramTypes.push(tag.type.applications[0].name + '[]'); - } else if (tag.type.expression) { - paramTypes.push(tag.type.expression.name); - + switch(tag.type.type) { + case 'UnionType': + if(tag?.type?.elements) { + paramTypes.push(tag.type.elements.map( e => e.name).join('|')); + } + else { + throw new Error('Malformed JSDoc comment: ' + JSON.stringify(tag)); + } + break; + case 'OptionalType': + if(tag?.type?.expression?.type === 'TypeApplication') { + paramTypes.push(`${tag.type.expression.applications[0].name}[]`); + } + else if(tag?.type.expression?.name) { + paramTypes.push(`${tag?.type.expression?.name}?`); + } + else if(tag?.name) { + paramTypes.push(`${tag?.name}?`); + } + else { + throw new Error('Malformed JSDoc comment: ' + JSON.stringify(tag)); + } + break; + case 'AllLiteral': + if(tag?.name) { + paramTypes.push(tag.name); + } + else { + throw new Error('Malformed JSDoc comment: ' + JSON.stringify(tag)); + } + break; + case 'NameExpression': + if(tag?.type?.name) { + paramTypes.push(tag.type.name); + } + else { + throw new Error('Malformed JSDoc comment: ' + JSON.stringify(tag)); + } + break; + case 'TypeApplication': + if(tag?.type?.applications) { + paramTypes.push(tag.type.applications.map(e => e.name).join(',') + '[]'); + } + else { + throw new Error('Malformed JSDoc comment: ' + JSON.stringify(tag)); + } + break; + default: + throw new Error('Unrecognized JSDoc comment: ' + JSON.stringify(tag)); } }); return paramTypes; diff --git a/packages/concerto-core/scripts/versionchecker.js b/packages/concerto-core/scripts/versionchecker.js index 70f435028f..b360c00ff4 100644 --- a/packages/concerto-core/scripts/versionchecker.js +++ b/packages/concerto-core/scripts/versionchecker.js @@ -76,7 +76,7 @@ class VersionChecker { if (digest !== md5) { throw new Error('Computed public API digest did not match the digest in the changelog for the most recent version. ' + 'Increment the version number and add a new entry to the changelog (explaining your public API change) using the digest ' + digest + - '. Run \'git diff api.txt\' to understand the pubic API changes. Please ensure that TypeScript definitions are up to date by updating packages/concerto-core/types/index.ds'); + '. Run \'git diff api.txt\' to understand the pubic API changes. Please ensure that TypeScript definitions are up to date by executing `npm run build:types`'); } // we're done here... diff --git a/packages/concerto-core/test/scripts/javascriptparser.js b/packages/concerto-core/test/scripts/javascriptparser.js index 9e14927e53..ea5fb48760 100644 --- a/packages/concerto-core/test/scripts/javascriptparser.js +++ b/packages/concerto-core/test/scripts/javascriptparser.js @@ -792,42 +792,6 @@ describe('JavascriptParser', () => { (()=>{JavascriptParser.getMethodArguments(comment);}) .should.throws(/Malformed JSDoc comment/); }); - - it('Cope with different types of tag type', () => { - const comment = ` - /** - * @returns {Animal[]} Something valid - */ - `; - sandbox.stub(doctrine,'parse').returns( - { - tags:[ - { - type: - { - applications:['somename'] - } - - }, - { - type: - { - expression: {name:'somename'} - } - - }, - { - type: - { - wibble: {name:'somename'} - } - - } - ] - }); - JavascriptParser.getMethodArguments(comment); - - }); }); describe('#getExample', () => { diff --git a/packages/concerto-core/types/lib/baseexception.d.ts b/packages/concerto-core/types/lib/baseexception.d.ts new file mode 100644 index 0000000000..bdc321df80 --- /dev/null +++ b/packages/concerto-core/types/lib/baseexception.d.ts @@ -0,0 +1,16 @@ +export = BaseException; +/** +* A base class for all Concerto exceptions +* @extends Error +* @class +* @memberof module:concerto-core +*/ +declare class BaseException extends Error { + /** + * Create the BaseException. + * @param {string} message - The exception message. + * @param {string} component - The optional component which throws this error. + */ + constructor(message: string, component: string); + component: any; +} diff --git a/packages/concerto-core/types/lib/basefileexception.d.ts b/packages/concerto-core/types/lib/basefileexception.d.ts new file mode 100644 index 0000000000..e0381effc7 --- /dev/null +++ b/packages/concerto-core/types/lib/basefileexception.d.ts @@ -0,0 +1,38 @@ +export = BaseFileException; +/** + * Exception throws when a Concerto file is semantically invalid + * @extends BaseException + * @see {@link BaseException} + * @class + * @memberof module:concerto-core + */ +declare class BaseFileException extends BaseException { + /** + * Create an BaseFileException + * @param {string} message - the message for the exception + * @param {string} fileLocation - the optional file location associated with the exception + * @param {string} fullMessage - the optional full message text + * @param {string} [fileName] - the file name + * @param {string} [component] - the component which throws this error + */ + constructor(message: string, fileLocation: string, fullMessage: string, fileName?: string, component?: string); + fileLocation: string; + shortMessage: string; + fileName: string; + /** + * Returns the file location associated with the exception or null + * @return {string} the optional location associated with the exception + */ + getFileLocation(): string; + /** + * Returns the error message without the location of the error + * @returns {string} the error message + */ + getShortMessage(): string; + /** + * Returns the fileName for the error + * @returns {string} the file name or null + */ + getFileName(): string; +} +import BaseException = require("./baseexception"); diff --git a/packages/concerto-core/types/lib/concerto.d.ts b/packages/concerto-core/types/lib/concerto.d.ts new file mode 100644 index 0000000000..f50f91f905 --- /dev/null +++ b/packages/concerto-core/types/lib/concerto.d.ts @@ -0,0 +1,101 @@ +export = Concerto; +/** + * Runtime API for Concerto. + * + * @class + * @memberof module:concerto-core + */ +declare class Concerto { + /** + * Create a Concerto instance. + * @param {*} modelManager - The this.modelManager to use for validation etc. + */ + constructor(modelManager: any); + modelManager: any; + /** + * Validates the instance against its model. + * @param {*} obj the input object + * @param {*} [options] the validation options + * @throws {Error} - if the instance if invalid with respect to the model + */ + validate(obj: any, options?: any): void; + /** + * Returns the model manager + * @returns {*} the model manager associated with this Concerto class + */ + getModelManager(): any; + /** + * Returns true if the input object is a Concerto object + * @param {*} obj the input object + * @return {boolean} true if the object has a $class attribute + */ + isObject(obj: any): boolean; + /** + * Returns the ClassDeclaration for an object, or throws an exception + * @param {*} obj the input object + * @throw {Error} an error if the object does not have a $class attribute + * @return {*} the ClassDeclaration for the type + */ + getTypeDeclaration(obj: any): any; + /** + * Gets the identifier for an object + * @param {*} obj the input object + * @return {string} The identifier for this object + */ + getIdentifier(obj: any): string; + /** + * Returns true if the object has an identifier + * @param {*} obj the input object + * @return {boolean} is the object has been defined with an identifier in the model + */ + isIdentifiable(obj: any): boolean; + /** + * Returns true if the object is a relationship. Relationships are strings + * of the form: 'resource:org.accordproject.Order#001' (a relationship) + * to the 'Order' identifiable, with the id 001. + * @param {*} obj the input object + * @return {boolean} true if the object is a relationship + */ + isRelationship(obj: any): boolean; + /** + * Set the identifier for an object. This method does *not* mutate the + * input object, use the return object. + * @param {*} obj the input object + * @param {string} id the new identifier + * @returns {*} the input object with the identifier set + */ + setIdentifier(obj: any, id: string): any; + /** + * Returns the fully qualified identifier for an object + * @param {*} obj the input object + * @returns {string} the fully qualified identifier + */ + getFullyQualifiedIdentifier(obj: any): string; + /** + * Returns a URI for an object + * @param {*} obj the input object + * @return {string} the URI for the object + */ + toURI(obj: any): string; + /** + * Parses a resource URI into typeDeclaration and id components. + * + * @param {string} uri the input URI + * @returns {*} an object with typeDeclaration and id attributes + * @throws {Error} if the URI is invalid or the type does not exist + * in the model manager + */ + fromURI(uri: string): any; + /** + * Returns the short type name + * @param {*} obj the input object + * @returns {string} the short type name + */ + getType(obj: any): string; + /** + * Returns the namespace for the object + * @param {*} obj the input object + * @returns {string} the namespace + */ + getNamespace(obj: any): string; +} diff --git a/packages/concerto-core/types/lib/config/configmediator.d.ts b/packages/concerto-core/types/lib/config/configmediator.d.ts new file mode 100644 index 0000000000..6fc2d8d7d8 --- /dev/null +++ b/packages/concerto-core/types/lib/config/configmediator.d.ts @@ -0,0 +1,17 @@ +export = ConfigMediator; +/** + * Mediates beween the NPM config module and the codebase + * Enables our isomorphic codebase to work in webpack + * + * @private + */ +declare class ConfigMediator { + /** + * Get a value with the 'name', giving back the acceptable 'init' value if the name is not present + * @param {String} name key of config value to look up, this will have the defined prefix added to it + * @param {Object} init if the config doesn't have the value (or can't be found for whatever reason) the default value to return + * + * @return {Object} supplied object or the init value if needed + */ + static get(name: string, init: any): any; +} diff --git a/packages/concerto-core/types/lib/datetimeutil.d.ts b/packages/concerto-core/types/lib/datetimeutil.d.ts new file mode 100644 index 0000000000..036a748bb9 --- /dev/null +++ b/packages/concerto-core/types/lib/datetimeutil.d.ts @@ -0,0 +1,8 @@ +/** + * Ensures there is a proper current time + * + * @param {string} [currentTime] - the definition of 'now' + * @param {number} [utcOffset] - UTC Offset for this execution + * @returns {object} if valid, the dayjs object for the current time + */ +export function setCurrentTime(currentTime?: string, utcOffset?: number): object; diff --git a/packages/concerto-core/types/lib/factory.d.ts b/packages/concerto-core/types/lib/factory.d.ts new file mode 100644 index 0000000000..df3d177538 --- /dev/null +++ b/packages/concerto-core/types/lib/factory.d.ts @@ -0,0 +1,135 @@ +export = Factory; +/** + * Use the Factory to create instances of Resource: transactions, participants + * and assets. + * + * @class + * @memberof module:concerto-core + */ +declare class Factory { + /** + * Create a new ID for an object. + * @returns {string} a new ID + */ + static newId(): string; + /** + * Create the factory. + * + * @param {ModelManager} modelManager - The ModelManager to use for this registry + */ + constructor(modelManager: ModelManager); + modelManager: ModelManager; + /** + * Create a new Resource with a given namespace, type name and id + * @param {String} ns - the namespace of the Resource + * @param {String} type - the type of the Resource + * @param {String} [id] - an optional string identifier + * @param {Object} [options] - an optional set of options + * @param {boolean} [options.disableValidation] - pass true if you want the factory to + * return a {@link Resource} instead of a {@link ValidatedResource}. Defaults to false. + * @param {String} [options.generate] - Pass one of:
+ *
sample
return a resource instance with generated sample data.
+ *
empty
return a resource instance with empty property values.
+ * @param {boolean} [options.includeOptionalFields] - if options.generate + * is specified, whether optional fields should be generated. + * @return {Resource} the new instance + * @throws {TypeNotFoundException} if the type is not registered with the ModelManager + */ + newResource(ns: string, type: string, id?: string, options?: { + disableValidation?: boolean; + generate?: string; + includeOptionalFields?: boolean; + }): Resource; + /** + * Create a new Concept with a given namespace and type name + * @param {String} ns - the namespace of the Concept + * @param {String} type - the type of the Concept + * @param {String} [id] - an optional string identifier + * @param {Object} [options] - an optional set of options + * @param {boolean} [options.disableValidation] - pass true if you want the factory to + * return a {@link Concept} instead of a {@link ValidatedConcept}. Defaults to false. + * @param {String} [options.generate] - Pass one of:
+ *
sample
return a resource instance with generated sample data.
+ *
empty
return a resource instance with empty property values.
+ * @param {boolean} [options.includeOptionalFields] - if options.generate + * is specified, whether optional fields should be generated. + * @return {Resource} the new instance + * @throws {TypeNotFoundException} if the type is not registered with the ModelManager + */ + newConcept(ns: string, type: string, id?: string, options?: { + disableValidation?: boolean; + generate?: string; + includeOptionalFields?: boolean; + }): Resource; + /** + * Create a new Relationship with a given namespace, type and identifier. + * A relationship is a typed pointer to an instance. I.e the relationship + * with `namespace = 'org.example'`, `type = 'Vehicle'` and `id = 'ABC' creates` + * a pointer that points at an instance of org.example.Vehicle with the id + * ABC. + * + * @param {String} ns - the namespace of the Resource + * @param {String} type - the type of the Resource + * @param {String} id - the identifier + * @return {Relationship} - the new relationship instance + * @throws {TypeNotFoundException} if the type is not registered with the ModelManager + */ + newRelationship(ns: string, type: string, id: string): Relationship; + /** + * Create a new transaction object. The identifier of the transaction is set to a UUID. + * @param {String} ns - the namespace of the transaction. + * @param {String} type - the type of the transaction. + * @param {String} [id] - an optional string identifier + * @param {Object} [options] - an optional set of options + * @param {String} [options.generate] - Pass one of:
+ *
sample
return a resource instance with generated sample data.
+ *
empty
return a resource instance with empty property values.
+ * @param {boolean} [options.includeOptionalFields] - if options.generate + * is specified, whether optional fields should be generated. + * @return {Resource} A resource for the new transaction. + */ + newTransaction(ns: string, type: string, id?: string, options?: { + generate?: string; + includeOptionalFields?: boolean; + }): Resource; + /** + * Create a new event object. The identifier of the event is + * set to a UUID. + * @param {String} ns - the namespace of the event. + * @param {String} type - the type of the event. + * @param {String} [id] - an optional string identifier + * @param {Object} [options] - an optional set of options + * @param {String} [options.generate] - Pass one of:
+ *
sample
return a resource instance with generated sample data.
+ *
empty
return a resource instance with empty property values.
+ * @param {boolean} [options.includeOptionalFields] - if options.generate + * is specified, whether optional fields should be generated. + * @return {Resource} A resource for the new event. + */ + newEvent(ns: string, type: string, id?: string, options?: { + generate?: string; + includeOptionalFields?: boolean; + }): Resource; + /** + * PRIVATE IMPLEMENTATION. DO NOT CALL FROM OUTSIDE THIS CLASS. + * + * Initialize the state of a newly created resource + * @private + * @param {Typed} newObject - resource to initialize. + * @param {ClassDeclaration} classDeclaration - class declaration for the resource. + * @param {Object} clientOptions - field generation options supplied by the caller. + */ + private initializeNewObject; + /** + * PRIVATE IMPLEMENTATION. DO NOT CALL FROM OUTSIDE THIS CLASS. + * + * Parse the client-supplied field generation options and return a corresponding set of InstanceGenerator + * options that can be used to initialize a resource. + * @private + * @param {Object} clientOptions - field generation options supplied by the caller. + * @return {Object} InstanceGenerator options. + */ + private parseGenerateOptions; +} +import Resource = require("./model/resource"); +import Relationship = require("./model/relationship"); diff --git a/packages/concerto-core/types/lib/globalize.d.ts b/packages/concerto-core/types/lib/globalize.d.ts new file mode 100644 index 0000000000..1e2f541aad --- /dev/null +++ b/packages/concerto-core/types/lib/globalize.d.ts @@ -0,0 +1,26 @@ +export = Globalize; +/** + * Dummy globalize replacement. + * @param {string} locale The locale. + * @return {Object} A mock globalize instance. + * @private + */ +declare function Globalize(locale: string): any; +declare namespace Globalize { + export { messageFormatter }; + export { formatMessage }; +} +/** + * Dummy globalize replacement. + * @param {string} message The message. + * @return {function} A function for formatting the message. + * @private + */ +declare function messageFormatter(message: string): Function; +/** + * Dummy globalize replacement. + * @param {string} message The message. + * @return {function} The formatted message. + * @private + */ +declare function formatMessage(message: string): Function; diff --git a/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts new file mode 100644 index 0000000000..c2787f7067 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts @@ -0,0 +1,21 @@ +export = AssetDeclaration; +/** + * AssetDeclaration defines the schema (aka model or class) for + * an Asset. It extends ClassDeclaration which manages a set of + * fields, a super-type and the specification of an + * identifying field. + * + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * @class + * @memberof module:concerto-core + */ +declare class AssetDeclaration { + /** + * Create an AssetDeclaration. + * @param {ModelFile} modelFile the ModelFile for this class + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: any); +} diff --git a/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts new file mode 100644 index 0000000000..c6ca65fe53 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts @@ -0,0 +1,200 @@ +export = ClassDeclaration; +/** + * ClassDeclaration defines the structure (model/schema) of composite data. + * It is composed of a set of Properties, may have an identifying field, and may + * have a super-type. + * A ClassDeclaration is conceptually owned by a ModelFile which + * defines all the classes that are part of a namespace. + * + * @abstract + * @class + * @memberof module:concerto-core + */ +declare class ClassDeclaration extends Decorated { + /** + * Create a ClassDeclaration from an Abstract Syntax Tree. The AST is the + * result of parsing. + * + * @param {ModelFile} modelFile - the ModelFile for this class + * @param {Object} ast - the AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: any); + name: any; + properties: any[]; + superType: any; + superTypeDeclaration: any; + idField: any; + timestamped: boolean; + abstract: boolean; + type: any; + fqn: string; + /** + * Adds a required field named 'timestamp' of type 'DateTime' if this class declaration has the 'concerto.Concept' + * super type. + * This method should only be called by system code. + * @private + */ + private addTimestampField; + /** + * Adds a required field named '$identifier' of type 'String' + * This method should only be called by system code. + * @private + */ + private addIdentifierField; + /** + * Resolve the super type on this class and store it as an internal property. + * @return {ClassDeclaration} The super type, or null if non specified. + */ + _resolveSuperType(): ClassDeclaration; + /** + * Returns true if this class is declared as abstract in the model file + * + * @return {boolean} true if the class is abstract + */ + isAbstract(): boolean; + /** + * Returns the short name of a class. This name does not include the + * namespace from the owning ModelFile. + * + * @return {string} the short name of this class + */ + getName(): string; + /** + * Return the namespace of this class. + * @return {string} namespace - a namespace. + */ + getNamespace(): string; + /** + * Returns the fully qualified name of this class. + * The name will include the namespace if present. + * + * @return {string} the fully-qualified name of this class + */ + getFullyQualifiedName(): string; + /** + * Returns true if this class declaration declares an identifying field + * (system or explicit) + * @returns {Boolean} true if the class declaration includes an identifier + */ + isIdentified(): boolean; + /** + * Returns true if this class declaration declares a system identifier + * $identifier + * @returns {Boolean} true if the class declaration includes a system identifier + */ + isSystemIdentified(): boolean; + /** + * Returns true if this class declaration declares an explicit identifier + * @returns {Boolean} true if the class declaration includes an explicit identifier + */ + isExplicitlyIdentified(): boolean; + /** + * Returns the name of the identifying field for this class. Note + * that the identifying field may come from a super type. + * + * @return {string} the name of the id field for this class or null if it does not exist + */ + getIdentifierFieldName(): string; + /** + * Returns the field with a given name or null if it does not exist. + * The field must be directly owned by this class -- the super-type is + * not introspected. + * + * @param {string} name the name of the field + * @return {Property} the field definition or null if it does not exist + */ + getOwnProperty(name: string): Property; + /** + * Returns the fields directly defined by this class. + * + * @return {Property[]} the array of fields + */ + getOwnProperties(): Property[]; + /** + * Returns the FQN of the super type for this class or null if this + * class does not have a super type. + * + * @return {string} the FQN name of the super type or null + */ + getSuperType(): string; + /** + * Get the super type class declaration for this class. + * @return {ClassDeclaration} the super type declaration, or null if there is no super type. + */ + getSuperTypeDeclaration(): ClassDeclaration; + /** + * Get the class declarations for all subclasses of this class, including this class. + * @return {ClassDeclaration[]} subclass declarations. + */ + getAssignableClassDeclarations(): ClassDeclaration[]; + /** + * Get all the super-type declarations for this type. + * @return {ClassDeclaration[]} super-type declarations. + */ + getAllSuperTypeDeclarations(): ClassDeclaration[]; + /** + * Returns the property with a given name or null if it does not exist. + * Fields defined in super-types are also introspected. + * + * @param {string} name the name of the field + * @return {Property} the field, or null if it does not exist + */ + getProperty(name: string): Property; + /** + * Returns the properties defined in this class and all super classes. + * + * @return {Property[]} the array of fields + */ + getProperties(): Property[]; + /** + * Get a nested property using a dotted property path + * @param {string} propertyPath The property name or name with nested structure e.g a.b.c + * @returns {Property} the property + * @throws {IllegalModelException} if the property path is invalid or the property does not exist + */ + getNestedProperty(propertyPath: string): Property; + /** + * Returns true if this class is the definition of an asset. + * + * @return {boolean} true if the class is an asset + */ + isAsset(): boolean; + /** + * Returns true if this class is the definition of a participant. + * + * @return {boolean} true if the class is an asset + */ + isParticipant(): boolean; + /** + * Returns true if this class is the definition of a transaction. + * + * @return {boolean} true if the class is an asset + */ + isTransaction(): boolean; + /** + * Returns true if this class is the definition of an event. + * + * @return {boolean} true if the class is an asset + */ + isEvent(): boolean; + /** + * Returns true if this class is the definition of a concept. + * + * @return {boolean} true if the class is an asset + */ + isConcept(): boolean; + /** + * Returns true if this class is the definition of a enum. + * + * @return {boolean} true if the class is an asset + */ + isEnum(): boolean; + /** + * Returns true if this class is the definition of a enum. + * + * @return {boolean} true if the class is an asset + */ + isClassDeclaration(): boolean; +} +import Decorated = require("./decorated"); diff --git a/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts new file mode 100644 index 0000000000..8ba56c64f0 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/conceptdeclaration.d.ts @@ -0,0 +1,15 @@ +export = ConceptDeclaration; +/** + * ConceptDeclaration defines the schema (aka model or class) for + * an Concept. It extends ClassDeclaration which manages a set of + * fields, a super-type and the specification of an + * identifying field. + * + * @extends ClassDeclaration + * @see {@link ClassDeclaration} + * @class + * @memberof module:concerto-core + */ +declare class ConceptDeclaration extends ClassDeclaration { +} +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/decorated.d.ts b/packages/concerto-core/types/lib/introspect/decorated.d.ts new file mode 100644 index 0000000000..1629320965 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/decorated.d.ts @@ -0,0 +1,66 @@ +export = Decorated; +/** + * Decorated defines a model element that may have decorators attached. + * + * @private + * @abstract + * @class + * @memberof module:concerto-core + */ +declare class Decorated { + /** + * Create a Decorated from an Abstract Syntax Tree. The AST is the + * result of parsing. + * + * @param {ModelFile} modelFile - the model file + * @param {string} ast - the AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: string); + modelFile: ModelFile; + ast: string; + /** + * Returns the ModelFile that defines this class. + * + * @return {ModelFile} the owning ModelFile + */ + getModelFile(): ModelFile; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Process the AST and build the model + * + * @throws {IllegalModelException} + * @private + */ + private process; + decorators: any[]; + /** + * Semantic validation of the structure of this decorated. Subclasses should + * override this method to impose additional semantic constraints on the + * contents/relations of fields. + * + * @throws {IllegalModelException} + * @private + */ + private validate; + /** + * Returns the decorators for this class. + * + * @return {Decorator[]} the decorators for the class + */ + getDecorators(): Decorator[]; + /** + * Returns the decorator for this class with a given name. + * @param {string} name - the name of the decorator + * @return {Decorator} the decorator attached to this class with the given name, or null if it does not exist. + */ + getDecorator(name: string): Decorator; +} +import Decorator = require("./decorator"); diff --git a/packages/concerto-core/types/lib/introspect/decorator.d.ts b/packages/concerto-core/types/lib/introspect/decorator.d.ts new file mode 100644 index 0000000000..f42faa8500 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/decorator.d.ts @@ -0,0 +1,54 @@ +export = Decorator; +/** + * Decorator encapsulates a decorator (annotation) on a class or property. + * @class + * @memberof module:concerto-core + */ +declare class Decorator { + /** + * Create a Decorator. + * @param {ClassDeclaration | Property} parent - the owner of this property + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(parent: ClassDeclaration | Property, ast: any); + ast: any; + parent: any; + arguments: any[]; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Returns the owner of this property + * @return {ClassDeclaration|Property} the parent class or property declaration + */ + getParent(): ClassDeclaration | Property; + /** + * Process the AST and build the model + * @throws {IllegalModelException} + * @private + */ + private process; + name: any; + /** + * Validate the property + * @throws {IllegalModelException} + * @private + */ + private validate; + /** + * Returns the name of a decorator + * @return {string} the name of this decorator + */ + getName(): string; + /** + * Returns the arguments for this decorator + * @return {object[]} the arguments for this decorator + */ + getArguments(): object[]; +} diff --git a/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts b/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts new file mode 100644 index 0000000000..de868cd546 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts @@ -0,0 +1,18 @@ +export = DecoratorFactory; +/** + * An interface for a class that processes a decorator and returns a specific + * implementation class for that decorator. + * @class + * @memberof module:concerto-core + */ +declare class DecoratorFactory { + /** + * Process the decorator, and return a specific implementation class for that + * decorator, or return null if this decorator is not handled by this processor. + * @abstract + * @param {ClassDeclaration | Property} parent - the owner of this property + * @param {Object} ast - The AST created by the parser + * @return {Decorator} The decorator. + */ + newDecorator(parent: ClassDeclaration | Property, ast: any): Decorator; +} diff --git a/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts new file mode 100644 index 0000000000..7a4cc6f9df --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/enumdeclaration.d.ts @@ -0,0 +1,12 @@ +export = EnumDeclaration; +/** + * EnumDeclaration defines an enumeration of static values. + * + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * @class + * @memberof module:concerto-core + */ +declare class EnumDeclaration extends ClassDeclaration { +} +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/enumvaluedeclaration.d.ts b/packages/concerto-core/types/lib/introspect/enumvaluedeclaration.d.ts new file mode 100644 index 0000000000..fba31273a7 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/enumvaluedeclaration.d.ts @@ -0,0 +1,18 @@ +export = EnumValueDeclaration; +/** + * Class representing a value from a set of enumerated values + * + * @extends Property + * @see See {@link Property} + * @class + * @memberof module:concerto-core + */ +declare class EnumValueDeclaration extends Property { + /** + * Returns true if this class is the definition of a enum value. + * + * @return {boolean} true if the class is an enum value + */ + isEnumValue(): boolean; +} +import Property = require("./property"); diff --git a/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts new file mode 100644 index 0000000000..4ff0dde7b6 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts @@ -0,0 +1,23 @@ +export = EventDeclaration; +/** Class representing the definition of an Event. + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * @class + * @memberof module:concerto-core + */ +declare class EventDeclaration { + /** + * Create an EventDeclaration. + * @param {ModelFile} modelFile the ModelFile for this class + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: any); + /** + * Process the AST and build the model + * + * @throws {IllegalModelException} + * @private + */ + private process; +} diff --git a/packages/concerto-core/types/lib/introspect/field.d.ts b/packages/concerto-core/types/lib/introspect/field.d.ts new file mode 100644 index 0000000000..f4b0c4bf4c --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/field.d.ts @@ -0,0 +1,34 @@ +export = Field; +/** + * Class representing the definition of a Field. A Field is owned + * by a ClassDeclaration and has a name, type and additional metadata + * (see below). + * @private + * @extends Property + * @see See {@link Property} + * @class + * @memberof module:concerto-core + */ +declare class Field extends Property { + validator: NumberValidator | StringValidator; + defaultValue: any; + /** + * Returns the validator string for this field + * @return {string} the validator for the field or null + */ + getValidator(): string; + /** + * Returns the default value for the field or null + * @return {string} the default value for the field or null + */ + getDefaultValue(): string; + /** + * Returns true if this class is the definition of a field. + * + * @return {boolean} true if the class is a field + */ + isField(): boolean; +} +import Property = require("./property"); +import NumberValidator = require("./numbervalidator"); +import StringValidator = require("./stringvalidator"); diff --git a/packages/concerto-core/types/lib/introspect/identifieddeclaration.d.ts b/packages/concerto-core/types/lib/introspect/identifieddeclaration.d.ts new file mode 100644 index 0000000000..9acaa4be9c --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/identifieddeclaration.d.ts @@ -0,0 +1,13 @@ +export = IdentifiedDeclaration; +/** + * IdentifiedDeclaration + * + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * @class + * @memberof module:concerto-core + * @abstract + */ +declare class IdentifiedDeclaration extends ClassDeclaration { +} +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts new file mode 100644 index 0000000000..7c8f67088c --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts @@ -0,0 +1,23 @@ +export = IllegalModelException; +/** + * Exception throws when a composer file is semantically invalid + * @extends BaseFileException + * @see See {@link BaseFileException} + * @class + * @memberof module:concerto-core + */ +declare class IllegalModelException extends BaseFileException { + /** + * Create an IllegalModelException. + * @param {string} message - the message for the exception + * @param {ModelFile} [modelFile] - the modelfile associated with the exception + * @param {Object} [fileLocation] - location details of the error within the model file. + * @param {number} fileLocation.start.line - start line of the error location. + * @param {number} fileLocation.start.column - start column of the error location. + * @param {number} fileLocation.end.line - end line of the error location. + * @param {number} fileLocation.end.column - end column of the error location. + * @param {string} [component] - the component which throws this error + */ + constructor(message: string, modelFile?: ModelFile, fileLocation?: any, component?: string); +} +import BaseFileException = require("../basefileexception"); diff --git a/packages/concerto-core/types/lib/introspect/introspector.d.ts b/packages/concerto-core/types/lib/introspect/introspector.d.ts new file mode 100644 index 0000000000..6d20e0f9f1 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/introspector.d.ts @@ -0,0 +1,43 @@ +export = Introspector; +/** + * + * Provides access to the structure of transactions, assets and participants. + * + * @class + * @memberof module:concerto-core + */ +declare class Introspector { + /** + * Create the Introspector. + * @param {ModelManager} modelManager - the ModelManager that backs this Introspector + */ + constructor(modelManager: ModelManager); + modelManager: ModelManager; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Returns all the class declarations for the business network. + * @return {ClassDeclaration[]} the array of class declarations + */ + getClassDeclarations(): ClassDeclaration[]; + /** + * Returns the class declaration with the given fully qualified name. + * Throws an error if the class declaration does not exist. + * @param {String} fullyQualifiedTypeName - the fully qualified name of the type + * @return {ClassDeclaration} the class declaration + * @throws {Error} if the class declaration does not exist + */ + getClassDeclaration(fullyQualifiedTypeName: string): ClassDeclaration; + /** + * Returns the backing ModelManager + * @return {ModelManager} the backing ModelManager + * @private + */ + private getModelManager; +} diff --git a/packages/concerto-core/types/lib/introspect/loaders/compositemodelfileloader.d.ts b/packages/concerto-core/types/lib/introspect/loaders/compositemodelfileloader.d.ts new file mode 100644 index 0000000000..ef9236d89b --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/loaders/compositemodelfileloader.d.ts @@ -0,0 +1,42 @@ +export = CompositeModelFileLoader; +/** + *

+ * Manages a set of model file loaders, delegating to the first model file + * loader that accepts a URL. + *

+ * @private + * @class + * @memberof module:concerto-core + */ +declare class CompositeModelFileLoader { + modelFileLoaders: any[]; + /** + * Adds a ModelFileLoader implemenetation to the ModelFileLoader + * @param {ModelFileLoader} modelFileLoader - The script to add to the ScriptManager + */ + addModelFileLoader(modelFileLoader: ModelFileLoader): void; + /** + * Get the array of ModelFileLoader instances + * @return {ModelFileLoaders[]} The ModelFileLoader registered + * @private + */ + private getModelFileLoaders; + /** + * Remove all registered ModelFileLoaders + */ + clearModelFileLoaders(): void; + /** + * Returns true if this ModelLoader can process the URL + * @param {string} url - the URL + * @return {boolean} true if this ModelLoader accepts the URL + * @abstract + */ + accepts(url: string): boolean; + /** + * Load a ModelFile from a URL and return it + * @param {string} url - the url to get + * @param {object} options - additional options + * @return {Promise} a promise to the ModelFile + */ + load(url: string, options: object): Promise; +} diff --git a/packages/concerto-core/types/lib/introspect/loaders/defaultmodelfileloader.d.ts b/packages/concerto-core/types/lib/introspect/loaders/defaultmodelfileloader.d.ts new file mode 100644 index 0000000000..0381162e75 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/loaders/defaultmodelfileloader.d.ts @@ -0,0 +1,19 @@ +export = DefaultModelFileLoader; +/** + *

+ * A default CompositeModelFileLoader implementation which supports + * github://, http:// and https:// URLs. + *

+ * @private + * @class + * @see See {@link CompositeModelFileLoader} + * @memberof module:concerto-core + */ +declare class DefaultModelFileLoader extends CompositeModelFileLoader { + /** + * Create the DefaultModelFileLoader. + * @param {ModelManager} modelManager - the model manager to use + */ + constructor(modelManager: ModelManager); +} +import CompositeModelFileLoader = require("./compositemodelfileloader"); diff --git a/packages/concerto-core/types/lib/introspect/loaders/githubmodelfileloader.d.ts b/packages/concerto-core/types/lib/introspect/loaders/githubmodelfileloader.d.ts new file mode 100644 index 0000000000..ebe836ea46 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/loaders/githubmodelfileloader.d.ts @@ -0,0 +1,11 @@ +export = GitHubModelFileLoader; +/** + * Loads ModelFiles from an external source, such as a URL. + * + * @class + * @private + * @memberof module:concerto-core + */ +declare class GitHubModelFileLoader extends HTTPModelFileLoader { +} +import HTTPModelFileLoader = require("./httpmodelfileloader"); diff --git a/packages/concerto-core/types/lib/introspect/loaders/httpmodelfileloader.d.ts b/packages/concerto-core/types/lib/introspect/loaders/httpmodelfileloader.d.ts new file mode 100644 index 0000000000..65600a0f6f --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/loaders/httpmodelfileloader.d.ts @@ -0,0 +1,30 @@ +export = HTTPModelFileLoader; +/** + * Loads ModelFiles from an HTTP(S) URL using the axios library. + * @class + * @private + * @memberof module:concerto-core + */ +declare class HTTPModelFileLoader { + /** + * Create the ModelLoader. + * @param {ModelManager} modelManager - the modelManager for the modelFile + * @private + */ + private constructor(); + modelManager: ModelManager; + /** + * Returns true if this ModelLoader can process the URL + * @param {string} url - the URL + * @return {boolean} true if this ModelLoader accepts the URL + * @abstract + */ + accepts(url: string): boolean; + /** + * Load a ModelFile from a URL and return it + * @param {string} requestUrl - the url to get + * @param {object} options - additional options + * @return {Promise} a promise to the ModelFile + */ + load(requestUrl: string, options: object): Promise; +} diff --git a/packages/concerto-core/types/lib/introspect/loaders/modelfiledownloader.d.ts b/packages/concerto-core/types/lib/introspect/loaders/modelfiledownloader.d.ts new file mode 100644 index 0000000000..43c922fca8 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/loaders/modelfiledownloader.d.ts @@ -0,0 +1,30 @@ +export = ModelFileDownloader; +/** + * Downloads the transitive closure of a set of model files. + * @class + * @memberof module:concerto-core + */ +declare class ModelFileDownloader { + /** + * Create a ModelFileDownloader and bind to a ModelFileLoader. + * @param {ModelFileLoader} modelFileLoader - the loader to use to download model files + * @param {Number} concurrency - the number of model files to download concurrently + */ + constructor(modelFileLoader: ModelFileLoader, concurrency?: number); + modelFileLoader: ModelFileLoader; + concurrency: number; + /** + * Download all external dependencies for an array of model files + * @param {ModelFile[]} modelFiles - the model files + * @param {Object} [options] - Options object passed to ModelFileLoaders + * @return {Promise} a promise that resolves to ModelFiles[] for the external model files + */ + downloadExternalDependencies(modelFiles: ModelFile[], options?: any): Promise; + /** + * Execute a Job + * @param {Object} job - the job to execute + * @param {Object} modelFileLoader - the loader to use to download model files. + * @return {Promise} a promise to the job results + */ + runJob(job: any, modelFileLoader: any): Promise; +} diff --git a/packages/concerto-core/types/lib/introspect/metamodel.d.ts b/packages/concerto-core/types/lib/introspect/metamodel.d.ts new file mode 100644 index 0000000000..5599b8afc8 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/metamodel.d.ts @@ -0,0 +1,124 @@ +export = MetaModel; +/** + * Class to work with the Concerto metamodel + */ +declare class MetaModel { + /** + * The metamodel itself, as a CTO string + */ + static metaModelCto: 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; + /** + * Create a name resolution table + * @param {*} modelManager - the model manager + * @param {object} metaModel - the metamodel (JSON) + * @return {object} mapping from a name to its namespace + */ + static createNameTable(modelManager: any, metaModel: object): object; + /** + * Resolve a name using the name table + * @param {string} name - the name of the type to resolve + * @param {object} table - the name table + * @return {string} the namespace for that name + */ + static resolveName(name: string, table: object): string; + /** + * Name resolution for metamodel + * @param {object} metaModel - the metamodel (JSON) + * @param {object} table - the name table + * @return {object} the metamodel with fully qualified names + */ + static resolveTypeNames(metaModel: object, table: object): object; + /** + * Resolve the namespace for names in the metamodel + * @param {object} modelManager - the ModelManager + * @param {object} metaModel - the MetaModel + * @return {object} the resolved metamodel + */ + static resolveMetaModel(modelManager: object, metaModel: object): 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; + /** + * Create decorator argument string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for the decorator argument + */ + static decoratorArgFromMetaModel(mm: object): string; + /** + * Create decorator string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for the decorator + */ + static decoratorFromMetaModel(mm: object): string; + /** + * Create decorators string from a metamodel + * @param {object} mm - the metamodel + * @param {string} prefix - indentation + * @return {string} the string for the decorators + */ + static decoratorsFromMetaModel(mm: object, prefix: string): string; + /** + * Create a property string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for that property + */ + static propertyFromMetaModel(mm: object): string; + /** + * Create a declaration string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for that declaration + */ + static declFromMetaModel(mm: object): string; + /** + * Create a model string from a metamodel + * @param {object} metaModel - the metamodel + * @param {boolean} [validate] - whether to perform validation + * @return {string} the string for that model + */ + static ctoFromMetaModel(metaModel: object, validate?: boolean): string; + /** + * 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 metamodel from a model string + * @param {string} model - the string for the model + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ + static ctoToMetaModel(model: string, validate?: boolean): object; + /** + * Export metamodel from a model string and resolve names + * @param {*} modelManager - the model manager + * @param {string} model - the string for the model + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ + static ctoToMetaModelAndResolve(modelManager: any, model: string, validate?: boolean): object; +} diff --git a/packages/concerto-core/types/lib/introspect/modelfile.d.ts b/packages/concerto-core/types/lib/introspect/modelfile.d.ts new file mode 100644 index 0000000000..eaafb69ce7 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/modelfile.d.ts @@ -0,0 +1,252 @@ +export = ModelFile; +/** + * Class representing a Model File. A Model File contains a single namespace + * and a set of model elements: assets, transactions etc. + * + * @class + * @memberof module:concerto-core + */ +declare class ModelFile { + /** + * Create a ModelFile. This should only be called by framework code. + * Use the ModelManager to manage ModelFiles. + * @param {ModelManager} modelManager - the ModelManager that manages this + * ModelFile + * @param {string} definitions - The DSL model as a string. + * @param {string} [fileName] - The optional filename for this modelfile + * @throws {IllegalModelException} + */ + constructor(modelManager: ModelManager, definitions: string, fileName?: string); + modelManager: ModelManager; + external: boolean; + declarations: any[]; + localTypes: Map; + imports: any[]; + importShortNames: Map; + importWildcardNamespaces: any[]; + importUriMap: {}; + fileName: string; + concertoVersion: any; + definitions: string; + ast: any; + /** + * Returns true + * @returns {boolean} true + */ + isModelFile(): boolean; + /** + * Returns true if the ModelFile is a system namespace + * @returns {Boolean} true if this is a system model file + */ + isSystemModelFile(): boolean; + /** + * Returns true if this ModelFile was downloaded from an external URI. + * @return {boolean} true iff this ModelFile was downloaded from an external URI + */ + isExternal(): boolean; + /** + * Returns the URI for an import, or null if the namespace was not associated with a URI. + * @param {string} namespace - the namespace for the import + * @return {string} the URI or null if the namespace was not associated with a URI. + * @private + */ + private getImportURI; + /** + * Returns an object that maps from the import declarations to the URIs specified + * @return {Object} keys are import declarations, values are URIs + * @private + */ + private getExternalImports; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Returns the ModelManager associated with this ModelFile + * + * @return {ModelManager} The ModelManager for this ModelFile + */ + getModelManager(): ModelManager; + /** + * Returns the types that have been imported into this ModelFile. + * + * @return {string[]} The array of imports for this ModelFile + */ + getImports(): string[]; + /** + * Validates the ModelFile. + * + * @throws {IllegalModelException} if the model is invalid + * @private + */ + private validate; + /** + * Check that the type is valid. + * @param {string} context - error reporting context + * @param {string} type - a short type name + * @param {Object} [fileLocation] - location details of the error within the model file. + * @param {String} fileLocation.start.line - start line of the error location. + * @param {String} fileLocation.start.column - start column of the error location. + * @param {String} fileLocation.end.line - end line of the error location. + * @param {String} fileLocation.end.column - end column of the error location. + * @throws {IllegalModelException} - if the type is not defined + * @private + */ + private resolveType; + /** + * Returns true if the type is defined in this namespace. + * @param {string} type - the short name of the type + * @return {boolean} - true if the type is defined in this ModelFile + * @private + */ + private isLocalType; + /** + * Returns true if the type is imported from another namespace + * @param {string} type - the short name of the type + * @return {boolean} - true if the type is imported from another namespace + * @private + */ + private isImportedType; + /** + * Returns the FQN for a type that is imported from another namespace + * @param {string} type - the short name of the type + * @return {string} - the FQN of the resolved import + * @throws {Error} - if the type is not imported + * @private + */ + private resolveImport; + /** + * Returns true if the type is defined in the model file + * @param {string} type the name of the type + * @return {boolean} true if the type (asset or transaction) is defined + */ + isDefined(type: string): boolean; + /** + * Returns the FQN of the type or null if the type could not be resolved. + * For primitive types the type name is returned. + * @param {string} type - a FQN or short type name + * @return {string | ClassDeclaration} the class declaration for the type or null. + * @private + */ + private getType; + /** + * Returns the FQN of the type or null if the type could not be resolved. + * For primitive types the short type name is returned. + * @param {string} type - a FQN or short type name + * @return {string} the FQN type name or null + * @private + */ + private getFullyQualifiedTypeName; + /** + * Returns the type with the specified name or null + * @param {string} type the short OR FQN name of the type + * @return {ClassDeclaration} the ClassDeclaration, or null if the type does not exist + */ + getLocalType(type: string): ClassDeclaration; + /** + * Get the AssetDeclarations defined in this ModelFile or null + * @param {string} name the name of the type + * @return {AssetDeclaration} the AssetDeclaration with the given short name + */ + getAssetDeclaration(name: string): AssetDeclaration; + /** + * Get the TransactionDeclaration defined in this ModelFile or null + * @param {string} name the name of the type + * @return {TransactionDeclaration} the TransactionDeclaration with the given short name + */ + getTransactionDeclaration(name: string): TransactionDeclaration; + /** + * Get the EventDeclaration defined in this ModelFile or null + * @param {string} name the name of the type + * @return {EventDeclaration} the EventDeclaration with the given short name + */ + getEventDeclaration(name: string): EventDeclaration; + /** + * Get the ParticipantDeclaration defined in this ModelFile or null + * @param {string} name the name of the type + * @return {ParticipantDeclaration} the ParticipantDeclaration with the given short name + */ + getParticipantDeclaration(name: string): ParticipantDeclaration; + /** + * Get the Namespace for this model file. + * @return {string} The Namespace for this model file + */ + getNamespace(): string; + /** + * Get the filename for this model file. Note that this may be null. + * @return {string} The filename for this model file + */ + getName(): string; + /** + * Get the AssetDeclarations defined in this ModelFile + * @return {AssetDeclaration[]} the AssetDeclarations defined in the model file + */ + getAssetDeclarations(): AssetDeclaration[]; + /** + * Get the TransactionDeclarations defined in this ModelFile + * @return {TransactionDeclaration[]} the TransactionDeclarations defined in the model file + */ + getTransactionDeclarations(): TransactionDeclaration[]; + /** + * Get the EventDeclarations defined in this ModelFile + * @return {EventDeclaration[]} the EventDeclarations defined in the model file + */ + getEventDeclarations(): EventDeclaration[]; + /** + * Get the ParticipantDeclarations defined in this ModelFile + * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model file + */ + getParticipantDeclarations(): ParticipantDeclaration[]; + /** + * Get the ConceptDeclarations defined in this ModelFile + * @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file + */ + getConceptDeclarations(): ConceptDeclaration[]; + /** + * Get the EnumDeclarations defined in this ModelFile + * @return {EnumDeclaration[]} the EnumDeclaration defined in the model file + */ + getEnumDeclarations(): EnumDeclaration[]; + /** + * Get the instances of a given type in this ModelFile + * @param {Function} type - the type of the declaration + * @return {ClassDeclaration[]} the ClassDeclaration defined in the model file + */ + getDeclarations(type: Function): ClassDeclaration[]; + /** + * Get all declarations in this ModelFile + * @return {ClassDeclaration[]} the ClassDeclarations defined in the model file + */ + getAllDeclarations(): ClassDeclaration[]; + /** + * Get the definitions for this model. + * @return {string} The definitions for this model. + */ + getDefinitions(): string; + /** + * Get the expected concerto version + * @return {string} The semver range for compatible concerto versions + */ + getConcertoVersion(): string; + /** + * Check whether this modelfile is compatible with the concerto version + */ + isCompatibleVersion(): void; + /** + * Populate from an AST + * @param {object} ast - the AST obtained from the parser + * @private + */ + private fromAst; + namespace: any; +} +import AssetDeclaration = require("./assetdeclaration"); +import TransactionDeclaration = require("./transactiondeclaration"); +import EventDeclaration = require("./eventdeclaration"); +import ParticipantDeclaration = require("./participantdeclaration"); +import ConceptDeclaration = require("./conceptdeclaration"); +import EnumDeclaration = require("./enumdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/numbervalidator.d.ts b/packages/concerto-core/types/lib/introspect/numbervalidator.d.ts new file mode 100644 index 0000000000..c753316cfa --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/numbervalidator.d.ts @@ -0,0 +1,22 @@ +export = NumberValidator; +/** + * A Validator to enforce that non null numeric values are between two values. + * @private + * @class + * @memberof module:concerto-core + */ +declare class NumberValidator extends Validator { + lowerBound: any; + upperBound: any; + /** + * Returns the lower bound for this validator, or null if not specified + * @returns {number} the lower bound or null + */ + getLowerBound(): number; + /** + * Returns the upper bound for this validator, or null if not specified + * @returns {number} the upper bound or null + */ + getUpperBound(): number; +} +import Validator = require("./validator"); diff --git a/packages/concerto-core/types/lib/introspect/parseexception.d.ts b/packages/concerto-core/types/lib/introspect/parseexception.d.ts new file mode 100644 index 0000000000..dc00643c16 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/parseexception.d.ts @@ -0,0 +1,21 @@ +export = ParseException; +/** + * Exception throws when a Concerto file is syntactically invalid + * @extends BaseFileException + * @see See {@link BaseFileException} + * @class + * @memberof module:concerto-core + * @private + */ +declare class ParseException extends BaseFileException { + /** + * Create an ParseException + * @param {string} message - the message for the exception + * @param {string} [fileLocation] - the file location associated with the exception + * @param {string} [fileName] - the file name associated with the exception + * @param {string} [fullMessageOverride] - the pre-existing full message + * @param {string} [component] - the component which throws this error + */ + constructor(message: string, fileLocation?: string, fileName?: string, fullMessageOverride?: string, component?: string); +} +import BaseFileException = require("../basefileexception"); diff --git a/packages/concerto-core/types/lib/introspect/parser.d.ts b/packages/concerto-core/types/lib/introspect/parser.d.ts new file mode 100644 index 0000000000..611c93fde8 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/parser.d.ts @@ -0,0 +1,10 @@ +declare function peg$SyntaxError(message: any, expected: any, found: any, location: any): any; +declare class peg$SyntaxError { + constructor(message: any, expected: any, found: any, location: any); + format(sources: any): string; +} +declare namespace peg$SyntaxError { + function buildMessage(expected: any, found: any): string; +} +declare function peg$parse(input: any, options: any): any; +export { peg$SyntaxError as SyntaxError, peg$parse as parse }; diff --git a/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts new file mode 100644 index 0000000000..b475aeff19 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts @@ -0,0 +1,17 @@ +export = ParticipantDeclaration; +/** Class representing the definition of a Participant. + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * + * @class + * @memberof module:concerto-core + */ +declare class ParticipantDeclaration { + /** + * Create an ParticipantDeclaration. + * @param {ModelFile} modelFile the ModelFile for this class + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: any); +} diff --git a/packages/concerto-core/types/lib/introspect/property.d.ts b/packages/concerto-core/types/lib/introspect/property.d.ts new file mode 100644 index 0000000000..79ab135cdb --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/property.d.ts @@ -0,0 +1,74 @@ +export = Property; +/** + * Property representing an attribute of a class declaration, + * either a Field or a Relationship. + * + * @class + * @memberof module:concerto-core + */ +declare class Property extends Decorated { + /** + * Create a Property. + * @param {ClassDeclaration} parent - the owner of this property + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(parent: ClassDeclaration, ast: any); + parent: ClassDeclaration; + /** + * Returns the owner of this property + * @return {ClassDeclaration} the parent class declaration + */ + getParent(): ClassDeclaration; + name: any; + decorator: any; + type: any; + array: boolean; + optional: boolean; + /** + * Returns the name of a property + * @return {string} the name of this field + */ + getName(): string; + /** + * Returns the type of a property + * @return {string} the type of this field + */ + getType(): string; + /** + * Returns true if the field is optional + * @return {boolean} true if the field is optional + */ + isOptional(): boolean; + /** + * Returns the fully qualified type name of a property + * @return {string} the fully qualified type of this property + */ + getFullyQualifiedTypeName(): string; + /** + * Returns the fully name of a property (ns + class name + property name) + * @return {string} the fully qualified name of this property + */ + getFullyQualifiedName(): string; + /** + * Returns the namespace of the parent of this property + * @return {string} the namespace of the parent of this property + */ + getNamespace(): string; + /** + * Returns true if the field is declared as an array type + * @return {boolean} true if the property is an array type + */ + isArray(): boolean; + /** + * Returns true if the field is declared as an enumerated value + * @return {boolean} true if the property is an enumerated value + */ + isTypeEnum(): boolean; + /** + * Returns true if this property is a primitive type. + * @return {boolean} true if the property is a primitive type. + */ + isPrimitive(): boolean; +} +import Decorated = require("./decorated"); diff --git a/packages/concerto-core/types/lib/introspect/relationshipdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/relationshipdeclaration.d.ts new file mode 100644 index 0000000000..1d53f00f79 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/relationshipdeclaration.d.ts @@ -0,0 +1,18 @@ +export = RelationshipDeclaration; +/** + * Class representing a relationship between model elements + * @extends Property + * @see See {@link Property} + * + * @class + * @memberof module:concerto-core + */ +declare class RelationshipDeclaration extends Property { + /** + * Returns true if this class is the definition of a relationship. + * + * @return {boolean} true if the class is a relationship + */ + isRelationship(): boolean; +} +import Property = require("./property"); diff --git a/packages/concerto-core/types/lib/introspect/stringvalidator.d.ts b/packages/concerto-core/types/lib/introspect/stringvalidator.d.ts new file mode 100644 index 0000000000..b4fc0d3aba --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/stringvalidator.d.ts @@ -0,0 +1,16 @@ +export = StringValidator; +/** + * A Validator to enforce that a string matches a regex + * @private + * @class + * @memberof module:concerto-core + */ +declare class StringValidator extends Validator { + regex: RegExp; + /** + * Returns the RegExp object associated with the string validator + * @returns {RegExp} the RegExp object + */ + getRegex(): RegExp; +} +import Validator = require("./validator"); diff --git a/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts new file mode 100644 index 0000000000..f9b3860b52 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts @@ -0,0 +1,17 @@ +export = TransactionDeclaration; +/** Class representing the definition of an Transaction. + * @extends ClassDeclaration + * @see See {@link ClassDeclaration} + * + * @class + * @memberof module:concerto-core + */ +declare class TransactionDeclaration { + /** + * Create an TransactionDeclaration. + * @param {ModelFile} modelFile the ModelFile for this class + * @param {Object} ast - The AST created by the parser + * @throws {IllegalModelException} + */ + constructor(modelFile: ModelFile, ast: any); +} diff --git a/packages/concerto-core/types/lib/introspect/validator.d.ts b/packages/concerto-core/types/lib/introspect/validator.d.ts new file mode 100644 index 0000000000..313e90fca3 --- /dev/null +++ b/packages/concerto-core/types/lib/introspect/validator.d.ts @@ -0,0 +1,47 @@ +export = Validator; +/** + * An Abstract field validator. Extend this class and override the + * validate method. + * @private + * @class + * @abstract + * @memberof module:concerto-core + */ +declare class Validator { + /** + * Create a Property. + * @param {Field} field - the field this validator is attached to + * @param {Object} validator - The validation string + * @throws {IllegalModelException} + */ + constructor(field: Field, validator: any); + validator: any; + field: Field; + /** + * @param {string} id the identifier of the instance + * @param {string} msg the exception message + * @throws {Error} throws an error to report the message + */ + reportError(id: string, msg: string): void; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Returns the field that this validator applies to + * @return {Field} the field + */ + getField(): Field; + /** + * Validate the property against a value + * @param {string} identifier the identifier of the instance being validated + * @param {Object} value the value to validate + * @throws {IllegalModelException} + * @private + */ + private validate; +} diff --git a/packages/concerto-core/types/lib/logger.d.ts b/packages/concerto-core/types/lib/logger.d.ts new file mode 100644 index 0000000000..632653c74f --- /dev/null +++ b/packages/concerto-core/types/lib/logger.d.ts @@ -0,0 +1,106 @@ +export = Logger; +/** + * A utility class with static function that print to the console + * @private + */ +declare class Logger { + /** + * A reusable function for logging at multiple levels + * @param {string} level - the required log level. e.g. error, warn, info, debug, etc. + * @param {any} obj - the input obj to prettify + * @returns {void} - + * @private + */ + private static dispatch; + /** + * Add a custom transport for logging + * @param {Object} transport - The transport object should have function for the usual logging operations e.g. error, warn, info, debug, etc. + * @returns {void} - + * @private + */ + private static add; + /** + * Write an error statement to the console. + * + * Prints to `stderr` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static error; + /** + * Write a warning statement to the console. + * + * Prints to `stderr` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static warn; + /** + * Write an info statement to the console. + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static info; + /** + * Write an info statement to the console. Alias for `logger.log` + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static log; + /** + * Write an http statement to the console. + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static http; + /** + * Write a verbose log statement to the console. + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static verbose; + /** + * Write a debug statement to the console. + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static debug; + /** + * Write a silly level statement to the console. + * + * Prints to `stdout` with newline. + * @param {any|object} data - if this is an object with properties `level` and `message` it will be flattened first + * @param {any} args - + * @returns {void} - + * @private + */ + private static silly; +} +declare namespace Logger { + const level: string; + const transports: {}[]; +} diff --git a/packages/concerto-core/types/lib/model/identifiable.d.ts b/packages/concerto-core/types/lib/model/identifiable.d.ts new file mode 100644 index 0000000000..fb728c5a36 --- /dev/null +++ b/packages/concerto-core/types/lib/model/identifiable.d.ts @@ -0,0 +1,69 @@ +export = Identifiable; +/** + * Identifiable is an entity with a namespace, type and an identifier. + * Applications should retrieve instances from {@link Factory} + * This class is abstract. + * @extends Typed + * @abstract + * @class + * @memberof module:concerto-core + */ +declare class Identifiable extends Typed { + /** + * Create an instance. + *

+ * Note: Only to be called by framework code. Applications should + * retrieve instances from {@link Factory} + *

+ * + * @param {ModelManager} modelManager - The ModelManager for this instance + * @param {ClassDeclaration} classDeclaration - The class declaration for this instance. + * @param {string} ns - The namespace this instance. + * @param {string} type - The type this instance. + * @param {string} id - The identifier of this instance. + * @param {string} timestamp - The timestamp of this instance + * @private + */ + private constructor(); + $identifier: string; + $timestamp: string; + /** + * Get the timestamp of this instance + * @return {string} The timestamp for this object + */ + getTimestamp(): string; + /** + * Get the identifier of this instance + * @return {string} The identifier for this object + */ + getIdentifier(): string; + /** + * Set the identifier of this instance + * @param {string} id - the new identifier for this object + */ + setIdentifier(id: string): void; + /** + * Get the fully qualified identifier of this instance. + * (namespace '.' type '#' identifier). + * @return {string} the fully qualified identifier of this instance + */ + getFullyQualifiedIdentifier(): string; + /** + * Determine if this identifiable is a relationship. + * @return {boolean} True if this identifiable is a relationship, + * false if not. + */ + isRelationship(): boolean; + /** + * Determine if this identifiable is a resource. + * @return {boolean} True if this identifiable is a resource, + * false if not. + */ + isResource(): boolean; + /** + * Returns a URI representation of a reference to this identifiable + * @return {String} the URI for the identifiable + */ + toURI(): string; +} +import Typed = require("./typed"); diff --git a/packages/concerto-core/types/lib/model/relationship.d.ts b/packages/concerto-core/types/lib/model/relationship.d.ts new file mode 100644 index 0000000000..b216a5b227 --- /dev/null +++ b/packages/concerto-core/types/lib/model/relationship.d.ts @@ -0,0 +1,27 @@ +export = Relationship; +/** + * A Relationship is a typed pointer to an instance. I.e the relationship + * with namespace = 'org.example', type = 'Vehicle' and id = 'ABC' creates + * a pointer that points at an instance of org.example.Vehicle with the id + * ABC. + * + * Applications should retrieve instances from {@link Factory} + * + * @extends Identifiable + * @see See {@link Identifiable} + * @class + * @memberof module:concerto-core + */ +declare class Relationship extends Identifiable { + /** + * Contructs a Relationship instance from a URI representation (created using toURI). + * @param {ModelManager} modelManager - the model manager to bind the relationship to + * @param {String} uriAsString - the URI as a string, generated using Identifiable.toURI() + * @param {String} [defaultNamespace] - default namespace to use for backwards compatability + * @param {String} [defaultType] - default type to use for backwards compatability + * @return {Relationship} the relationship + */ + static fromURI(modelManager: ModelManager, uriAsString: string, defaultNamespace?: string, defaultType?: string): Relationship; + $class: string; +} +import Identifiable = require("./identifiable"); diff --git a/packages/concerto-core/types/lib/model/resource.d.ts b/packages/concerto-core/types/lib/model/resource.d.ts new file mode 100644 index 0000000000..1f5791fb06 --- /dev/null +++ b/packages/concerto-core/types/lib/model/resource.d.ts @@ -0,0 +1,35 @@ +export = Resource; +/** + * + * Resource is an instance that has a type. The type of the resource + * specifies a set of properites (which themselves have types). + * + * + * Type information in Concerto is used to validate the structure of + * Resource instances and for serialization. + * + * + * Resources are used in Concerto to represent Assets, Participants, Transactions and + * other domain classes that can be serialized for long-term persistent storage. + * + * @extends Identifiable + * @see See {@link Resource} + * @class + * @memberof module:concerto-core + * @public + */ +declare class Resource extends Identifiable { + /** + * Determine if this identifiable is a concept. + * @return {boolean} True if this identifiable is a concept, + * false if not. + */ + isConcept(): boolean; + /** + * Determine if this object is identifiable. + * @return {boolean} True if this object has an identifiying field + * false if not. + */ + isIdentifiable(): boolean; +} +import Identifiable = require("./identifiable"); diff --git a/packages/concerto-core/types/lib/model/resourceid.d.ts b/packages/concerto-core/types/lib/model/resourceid.d.ts new file mode 100644 index 0000000000..6e8d26f1b6 --- /dev/null +++ b/packages/concerto-core/types/lib/model/resourceid.d.ts @@ -0,0 +1,44 @@ +export = ResourceId; +/** + * All the identifying properties of a resource. + * @private + * @class + * @memberof module:concerto-core + * @property {String} namespace + * @property {String} type + * @property {String} id + */ +declare class ResourceId { + /** + * Parse a URI into an identifier. + *

+ * Three formats are allowable: + *

    + *
  1. Valid resource URI argument: resource:qualifiedTypeName#ID
  2. + *
  3. Valid resource URI argument with missing URI scheme: qualifiedTypeName#ID
  4. + *
  5. URI argument containing only an ID, with legacy namespace and type arguments supplied.
  6. + *
+ * @param {String} uri - Resource URI. + * @param {String} [legacyNamespace] - Namespace to use for legacy resource identifiers. + * @param {String} [legacyType] - Type to use for legacy resource identifiers. + * @return {Identifier} - An identifier. + * @throws {Error} - On an invalid resource URI. + */ + static fromURI(uri: string, legacyNamespace?: string, legacyType?: string): Identifier; + /** + * Note: only for use by internal framework code. + * @param {String} namespace - Namespace containing the type. + * @param {String} type - Short type name. + * @param {String} id - Instance identifier. + * @private + */ + private constructor(); + namespace: string; + type: string; + id: string; + /** + * URI representation of this identifier. + * @return {String} A URI. + */ + toURI(): string; +} diff --git a/packages/concerto-core/types/lib/model/typed.d.ts b/packages/concerto-core/types/lib/model/typed.d.ts new file mode 100644 index 0000000000..7e42236776 --- /dev/null +++ b/packages/concerto-core/types/lib/model/typed.d.ts @@ -0,0 +1,96 @@ +export = Typed; +/** + * Object is an instance with a namespace and a type. + * + * This class is abstract. + * @abstract + * @class + * @memberof module:concerto-core + */ +declare class Typed { + /** + * Create an instance. + *

+ * Note: Only to be called by framework code. Applications should + * retrieve instances from {@link Factory} + *

+ * + * @param {ModelManager} modelManager - The ModelManager for this instance + * @param {ClassDeclaration} classDeclaration - The class declaration for this instance. + * @param {string} ns - The namespace this instance. + * @param {string} type - The type this instance. + * @private + */ + private constructor(); + $modelManager: ModelManager; + $classDeclaration: ClassDeclaration; + $namespace: string; + $type: string; + /** + * Visitor design pattern + * @param {Object} visitor - the visitor + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private accept; + /** + * Get the ModelManager for this instance + * @return {ModelManager} The ModelManager for this object + * @private + */ + private getModelManager; + /** + * Get the type of the instance (a short name, not including namespace). + * @return {string} The type of this object + */ + getType(): string; + /** + * Get the fully-qualified type name of the instance (including namespace). + * @return {string} The fully-qualified type name of this object + */ + getFullyQualifiedType(): string; + /** + * Get the namespace of the instance. + * @return {string} The namespace of this object + */ + getNamespace(): string; + /** + * Returns the class declaration for this instance object. + * + * @return {ClassDeclaration} - the class declaration for this instance + * @private + */ + private getClassDeclaration; + /** + * Sets a property on this Resource + * @param {string} propName - the name of the field + * @param {string} value - the value of the property + */ + setPropertyValue(propName: string, value: string): void; + /** + * Adds a value to an array property on this Resource + * @param {string} propName - the name of the field + * @param {string} value - the value of the property + */ + addArrayValue(propName: string, value: string): void; + /** + * Sets the fields to their default values, based on the model + * @private + */ + private assignFieldDefaults; + /** + * Check to see if this instance is an instance of the specified fully qualified + * type name. + * @param {String} fqt The fully qualified type name. + * @returns {boolean} True if this instance is an instance of the specified fully + * qualified type name, false otherwise. + */ + instanceOf(fqt: string): boolean; + /** + * Overriden to prevent people accidentally converting a resource to JSON + * without using the Serializer. + * @private + */ + private toJSON; +} diff --git a/packages/concerto-core/types/lib/model/validatedresource.d.ts b/packages/concerto-core/types/lib/model/validatedresource.d.ts new file mode 100644 index 0000000000..300b458de8 --- /dev/null +++ b/packages/concerto-core/types/lib/model/validatedresource.d.ts @@ -0,0 +1,38 @@ +export = ValidatedResource; +/** + * ValidatedResource is a Resource that can validate that property + * changes (or the whole instance) do not violate the structure of + * the type information associated with the instance. + * @extends Resource + * @see See {@link Resource} + * @class + * @memberof module:concerto-core + */ +declare class ValidatedResource extends Resource { + /** + * This constructor should not be called directly. + * Use the Factory class to create instances. + * + *

+ * Note: Only to be called by framework code. Applications should + * retrieve instances from {@link Factory} + *

+ * @param {ModelManager} modelManager - The ModelManager for this instance + * @param {ClassDeclaration} classDeclaration - The class declaration for this instance. + * @param {string} ns - The namespace this instance. + * @param {string} type - The type this instance. + * @param {string} id - The identifier of this instance. + * @param {string} timestamp - The timestamp of this instance + * @param {ResourceValidator} resourceValidator - The validator to use for this instance + * @private + */ + private constructor(); + $validator: ResourceValidator; + /** + * Validates the instance against its model. + * + * @throws {Error} - if the instance if invalid with respect to the model + */ + validate(): void; +} +import Resource = require("./resource"); diff --git a/packages/concerto-core/types/lib/modelloader.d.ts b/packages/concerto-core/types/lib/modelloader.d.ts new file mode 100644 index 0000000000..c8f7d3a6de --- /dev/null +++ b/packages/concerto-core/types/lib/modelloader.d.ts @@ -0,0 +1,48 @@ +export = ModelLoader; +/** + * Create a ModelManager from model files, with an optional system model. + * + * If a ctoFile is not provided, the Accord Project system model is used. + * + * @class + * @memberof module:concerto-core + */ +declare class ModelLoader { + /** + * Add model file + * + * @param {object} modelFileLoader - the model loader + * @param {object} modelManager - the model manager + * @param {string} ctoFile - the model file + * @return {object} the model manager + * @private + */ + private static addModel; + /** + * Load models in a new model manager + * + * @param {string[]} ctoFiles - the CTO files (can be local file paths or URLs) + * @param {object} options - optional parameters + * @param {boolean} [options.offline] - do not resolve external models + * @param {number} [options.utcOffset] - UTC Offset for this execution + * @return {object} the model manager + */ + static loadModelManager(ctoFiles: string[], options?: { + offline?: boolean; + utcOffset?: number; + }): object; + /** + * Load system and models in a new model manager from model files objects + * + * @param {object[]} modelFiles - An array of Concerto files as strings or ModelFile objects. + * @param {string[]} [fileNames] - An optional array of file names to associate with the model files + * @param {object} options - optional parameters + * @param {boolean} [options.offline] - do not resolve external models + * @param {number} [options.utcOffset] - UTC Offset for this execution + * @return {object} the model manager + */ + static loadModelManagerFromModelFiles(modelFiles: object[], fileNames?: string[], options?: { + offline?: boolean; + utcOffset?: number; + }): object; +} diff --git a/packages/concerto-core/types/lib/modelmanager.d.ts b/packages/concerto-core/types/lib/modelmanager.d.ts new file mode 100644 index 0000000000..6274db619a --- /dev/null +++ b/packages/concerto-core/types/lib/modelmanager.d.ts @@ -0,0 +1,252 @@ +export = ModelManager; +/** + * 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. + * + * @class + * @memberof module:concerto-core + */ +declare class ModelManager { + /** + * Create the ModelManager. + * @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 - The Concerto file as a string + * @param {string} [fileName] - a file name to associate with the model file + * @throws {IllegalModelException} + */ + validateModelFile(modelFile: string, 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 + * @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 {ModelFileDownloader} [modelFileDownloader] - an optional ModelFileDownloader + * @throws {IllegalModelException} if the models fail validation + * @return {Promise} a promise when the download and update operation is completed. + */ + updateExternalModels(options?: any, modelFileDownloader?: ModelFileDownloader): 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. + * @private + */ + private getType; + /** + * 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; +} +import Factory = require("./factory"); +import Serializer = require("./serializer"); +import ModelFile = require("./introspect/modelfile"); +import ModelFileDownloader = require("./introspect/loaders/modelfiledownloader"); diff --git a/packages/concerto-core/types/lib/modelutil.d.ts b/packages/concerto-core/types/lib/modelutil.d.ts new file mode 100644 index 0000000000..eef9f02145 --- /dev/null +++ b/packages/concerto-core/types/lib/modelutil.d.ts @@ -0,0 +1,87 @@ +export = ModelUtil; +/** + * Internal Model Utility Class + *

+ * @private + * @class + * @memberof module:concerto-core + */ +declare class ModelUtil { + /** + * Returns everything after the last dot, if present, of the source string + * @param {string} fqn - the source string + * @return {string} - the string after the last dot + * @private + */ + private static getShortName; + /** + * Returns true if the specified name is a wildcard + * @param {string} fqn - the source string + * @return {boolean} true if the specified name is a wildcard + * @private + */ + private static isWildcardName; + /** + * Returns true if the specified name is a recusive wildcard + * @param {string} fqn - the source string + * @return {boolean} true if the specified name is a recusive wildcard + * @private + */ + private static isRecursiveWildcardName; + /** + * Returns true if a type matches the required fully qualified name. The required + * name may be a wildcard or recursive wildcard + * @param {Typed} type - the type to test + * @param {string} fqn - required fully qualified name + * @return {boolean} true if the specified type and namespace match + * @private + */ + private static isMatchingType; + /** + * Returns the namespace for a the fully qualified name of a type + * @param {string} fqn - the fully qualified identifier of a type + * @return {string} - namespace of the type (everything before the last dot) + * or the empty string if there is no dot + * @private + */ + private static getNamespace; + /** + * Returns true if the type is a primitive type + * @param {string} typeName - the name of the type + * @return {boolean} - true if the type is a primitive + * @private + */ + private static isPrimitiveType; + /** + * Returns true if the type is assignable to the propertyType. + * + * @param {ModelFile} modelFile - the ModelFile that owns the Property + * @param {string} typeName - the FQN of the type we are trying to assign + * @param {Property} property - the property that we'd like to store the + * type in. + * @return {boolean} - true if the type can be assigned to the property + * @private + */ + private static isAssignableTo; + /** + * Returns the passed string with the first character capitalized + * @param {string} string - the string + * @return {string} the string with the first letter capitalized + * @private + */ + private static capitalizeFirstLetter; + /** + * Returns the true if the given field is an enumerated type + * @param {Field} field - the string + * @return {boolean} true if the field is declared as an enumeration + * @private + */ + private static isEnum; + /** + * Get the fully qualified name of a type. + * @param {string} namespace - namespace of the type. + * @param {string} type - short name of the type. + * @returns {string} the fully qualified type name. + */ + static getFullyQualifiedName(namespace: string, type: string): string; +} diff --git a/packages/concerto-core/types/lib/securityexception.d.ts b/packages/concerto-core/types/lib/securityexception.d.ts new file mode 100644 index 0000000000..fa05632374 --- /dev/null +++ b/packages/concerto-core/types/lib/securityexception.d.ts @@ -0,0 +1,16 @@ +export = SecurityException; +/** +* Class representing a security exception +* @extends BaseException +* @see See {@link BaseException} +* @class +* @memberof module:concerto-core +*/ +declare class SecurityException extends BaseException { + /** + * Create the SecurityException. + * @param {string} message - The exception message. + */ + constructor(message: string); +} +import BaseException = require("./baseexception"); diff --git a/packages/concerto-core/types/lib/serializer.d.ts b/packages/concerto-core/types/lib/serializer.d.ts new file mode 100644 index 0000000000..e2758a8445 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer.d.ts @@ -0,0 +1,77 @@ +export = Serializer; +/** + * Serialize Resources instances to/from various formats for long-term storage + * (e.g. on the blockchain). + * + * @class + * @memberof module:concerto-core + */ +declare class Serializer { + /** + * Create a Serializer. + * @param {Factory} factory - The Factory to use to create instances + * @param {ModelManager} modelManager - The ModelManager to use for validation etc. + * @param {object} [options] - Serializer options + */ + constructor(factory: Factory, modelManager: ModelManager, options?: object); + factory: Factory; + modelManager: ModelManager; + defaultOptions: any; + /** + * Set the default options for the serializer. + * @param {Object} newDefaultOptions The new default options for the serializer. + */ + setDefaultOptions(newDefaultOptions: any): void; + /** + *

+ * Convert a {@link Resource} to a JavaScript object suitable for long-term + * peristent storage. + *

+ * @param {Resource} resource - The instance to convert to JSON + * @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 + * place of relationships (serializing them as resources), false by default. + * @param {boolean} [options.deduplicateResources] - Generate $id for resources and + * if a resources appears multiple times in the object graph only the first instance is + * serialized in full, subsequent instances are replaced with a reference to the $id + * @param {boolean} [options.convertResourcesToId] - Convert resources that + * are specified for relationship fields into their id, false by default. + * @param {number} [options.utcOffset] - UTC Offset for DateTime values. + * @return {Object} - The Javascript Object that represents the resource + * @throws {Error} - throws an exception if resource is not an instance of + * Resource or fails validation. + */ + toJSON(resource: Resource, options?: { + validate?: boolean; + convertResourcesToRelationships?: boolean; + permitResourcesForRelationships?: boolean; + deduplicateResources?: boolean; + convertResourcesToId?: boolean; + utcOffset?: number; + }): any; + /** + * Create a {@link Resource} from a JavaScript Object representation. + * The JavaScript Object should have been created by calling the + * {@link Serializer#toJSON toJSON} API. + * + * The Resource is populated based on the JavaScript object. + * + * @param {Object} jsonObject The JavaScript Object for a Resource + * @param {Object} options - the optional serialization options + * @param {boolean} options.acceptResourcesForRelationships - handle JSON objects + * in the place of strings for relationships, defaults to false. + * @param {boolean} options.validate - validate the structure of the Resource + * with its model prior to serialization (default to true) + * @param {number} [options.utcOffset] - UTC Offset for DateTime values. + * @return {Resource} The new populated resource + */ + fromJSON(jsonObject: any, options: { + acceptResourcesForRelationships: boolean; + validate: boolean; + utcOffset?: number; + }): Resource; +} diff --git a/packages/concerto-core/types/lib/serializer/instancegenerator.d.ts b/packages/concerto-core/types/lib/serializer/instancegenerator.d.ts new file mode 100644 index 0000000000..f612270761 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/instancegenerator.d.ts @@ -0,0 +1,68 @@ +export = InstanceGenerator; +/** + * Generate sample instance data for the specified class declaration + * and resource instance. The specified resource instance will be + * updated with either default values or generated sample data. + * @private + * @class + * @memberof module:concerto-core + */ +declare class InstanceGenerator { + /** + * Visitor design pattern + * @param {Object} thing - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visit; + /** + * Visitor design pattern + * @param {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclaration; + /** + * Visitor design pattern + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitField; + /** + * Get a value for the specified field. + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {*} A value for the specified field. + */ + getFieldValue(field: Field, parameters: any): any; + /** + * Find a concrete type that extends the provided type. If the supplied type argument is + * not abstract then it will be returned. + * TODO: work out whether this has to be a leaf node or whether the closest type can be used + * It depends really since the closest type will satisfy the model but whether it satisfies + * any transaction code which attempts to use the generated resource is another matter. + * @param {ClassDeclaration} declaration the class declaration. + * @return {ClassDeclaration} the closest extending concrete class definition. + * @throws {Error} if no concrete subclasses exist. + */ + findConcreteSubclass(declaration: ClassDeclaration): ClassDeclaration; + /** + * Visitor design pattern + * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Relationship} the result of visiting + * @private + */ + private visitRelationshipDeclaration; + /** + * Generate a random ID for a given type. + * @private + * @param {ClassDeclaration} classDeclaration - class declaration for a type. + * @return {String} an ID. + */ + private generateRandomId; +} diff --git a/packages/concerto-core/types/lib/serializer/jsongenerator.d.ts b/packages/concerto-core/types/lib/serializer/jsongenerator.d.ts new file mode 100644 index 0000000000..c3aff1dca7 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/jsongenerator.d.ts @@ -0,0 +1,81 @@ +export = JSONGenerator; +/** + * Converts the contents of a Resource to JSON. The parameters + * object should contain the keys + * 'stack' - the TypedStack of objects being processed. It should + * start with a Resource. + * 'modelManager' - the ModelManager to use. + * @private + * @class + * @memberof module:concerto-core + */ +declare class JSONGenerator { + /** + * Constructor. + * @param {boolean} [convertResourcesToRelationships] Convert resources that + * are specified for relationship fields into relationships, false by default. + * @param {boolean} [permitResourcesForRelationships] Permit resources in the + * place of relationships (serializing them as resources), false by default. + * @param {boolean} [deduplicateResources] If resources appear several times + * in the object graph only the first instance is serialized, with only the $id + * written for subsequent instances, false by default. + * @param {boolean} [convertResourcesToId] Convert resources that + * are specified for relationship fields into their id, false by default. + * @param {boolean} [ergo] target ergo. + * @param {number} [utcOffset] UTC Offset for DateTime values. + */ + constructor(convertResourcesToRelationships?: boolean, permitResourcesForRelationships?: boolean, deduplicateResources?: boolean, convertResourcesToId?: boolean, ergo?: boolean, utcOffset?: number); + convertResourcesToRelationships: boolean; + permitResourcesForRelationships: boolean; + deduplicateResources: boolean; + convertResourcesToId: boolean; + ergo: boolean; + utcOffset: number; + /** + * Visitor design pattern + * @param {Object} thing - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visit; + /** + * Visitor design pattern + * @param {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclaration; + /** + * Visitor design pattern + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitField; + /** + * Converts to JSON safe format. + * + * @param {Field} field - the field declaration of the object + * @param {Object} obj - the object to convert to text + * @return {Object} the text JSON safe representation + */ + convertToJSON(field: Field, obj: any): any; + /** + * Visitor design pattern + * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationshipDeclaration; + /** + * Returns the persistent format for a relationship. + * @param {RelationshipDeclaration} relationshipDeclaration - the relationship being persisted + * @param {Identifiable} relationshipOrResource - the relationship or the resource + * @returns {string} the text to use to persist the relationship + */ + getRelationshipText(relationshipDeclaration: RelationshipDeclaration, relationshipOrResource: Identifiable): string; +} diff --git a/packages/concerto-core/types/lib/serializer/jsonpopulator.d.ts b/packages/concerto-core/types/lib/serializer/jsonpopulator.d.ts new file mode 100644 index 0000000000..980a01d7bb --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/jsonpopulator.d.ts @@ -0,0 +1,74 @@ +export = JSONPopulator; +/** + * Populates a Resource with data from a JSON object graph. The JSON objects + * should be the result of calling Serializer.toJSON and then JSON.parse. + * The parameters object should contain the keys + * 'stack' - the TypedStack of objects being processed. It should + * start with the root object from JSON.parse. + * 'factory' - the Factory instance to use for creating objects. + * 'modelManager' - the ModelManager instance to use to resolve classes + * @private + * @class + * @memberof module:concerto-core + */ +declare class JSONPopulator { + /** + * Constructor. + * @param {boolean} [acceptResourcesForRelationships] Permit resources in the + * place of relationships, false by default. + * @param {boolean} [ergo] target ergo. + * @param {number} [utcOffset] - UTC Offset for DateTime values. + */ + constructor(acceptResourcesForRelationships?: boolean, ergo?: boolean, utcOffset?: number); + acceptResourcesForRelationships: boolean; + ergo: boolean; + utcOffset: number; + /** + * Visitor design pattern + * @param {Object} thing - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visit; + /** + * Visitor design pattern + * @param {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclaration; + /** + * Visitor design pattern + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitField; + /** + * + * @param {Field} field - the field of the item being converted + * @param {Object} jsonItem - the JSON object of the item being converted + * @param {Object} parameters - the parameters + * @return {Object} - the populated object. + */ + convertItem(field: Field, jsonItem: any, parameters: any): any; + /** + * Converts a primtive object to JSON text. + * + * @param {Field} field - the field declaration of the object + * @param {Object} json - the JSON object to convert to a Concerto Object + * @return {string} the text representation + */ + convertToObject(field: Field, json: any): string; + /** + * Visitor design pattern + * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationshipDeclaration; +} diff --git a/packages/concerto-core/types/lib/serializer/objectvalidator.d.ts b/packages/concerto-core/types/lib/serializer/objectvalidator.d.ts new file mode 100644 index 0000000000..65cfd1377a --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/objectvalidator.d.ts @@ -0,0 +1,191 @@ +export = ObjectValidator; +/** + *

+ * 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. + *

+ * The parameters for the visit method must contain the following properties: + *
    + *
  • 'stack' - the TypedStack of objects being processed. It should + * start as [Resource] or [Field]
  • + *
  • 'rootResourceIdentifier' - the identifier of the resource being validated
  • + *
  • 'modelManager' - the ModelManager instance to use for type checking
  • + *
+ * @private + * @class + * @memberof module:concerto-core + */ +declare class ObjectValidator { + /** + * 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 + * @param {*} concerto - the concerto instance + * @throws {ValidationException} the exception + * @private + */ + private static reportFieldTypeViolation; + /** + * Throw a new error for a model violation. + * @param {string} id - the identifier of this instance. + * @param {RelationshipDeclaration} relationshipDeclaration - the declaration of the classs + * @param {Object} value - the value of the field. + * @private + */ + private static reportNotRelationshipViolation; + /** + * Throw a new error for a missing, but required field. + * @param {string} id - the identifier of this instance. + * @param {Field} field - the field/ + * @private + */ + private static reportMissingRequiredProperty; + /** + * Throw a new error for a missing, but required field. + * @param {string} id - the identifier of this instance. + * @param {Field} field - the field/ + * @private + */ + private static reportEmptyIdentifier; + /** + * 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 + */ + private static reportInvalidEnumValue; + /** + * Throw a validation exception for an abstract class + * @param {ClassDeclaration} classDeclaration - the class declaration + * @throws {ValidationException} the validation exception + * @private + */ + private static reportAbstractClass; + /** + * Throw a validation exception for an abstract class + * @param {string} resourceId - the id of the resouce 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 + */ + private static reportUndeclaredField; + /** + * Throw a validation exception for an invalid field assignment + * @param {string} resourceId - the id of the resouce 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 + */ + private static reportInvalidFieldAssignment; + /** + * ResourceValidator constructor + * @param {*} concerto - the Concerto instance used for validation + * @param {Object} [options] - the optional validation 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(concerto: any, options?: { + validate?: boolean; + convertResourcesToRelationships?: boolean; + permitResourcesForRelationships?: boolean; + }); + options: { + validate?: boolean; + convertResourcesToRelationships?: boolean; + permitResourcesForRelationships?: boolean; + }; + concerto: 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 + */ + private visit; + /** + * Visitor design pattern + * + * @param {EnumDeclaration} enumDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumDeclaration; + /** + * Visitor design pattern + * @param {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclaration; + /** + * Returns true if the property is a system property. + * System properties are not declared in the model. + * @param {String} propertyName - the name of the property + * @return {Boolean} true if the property is a system property + * @private + */ + private isSystemProperty; + /** + * Visitor design pattern + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitField; + /** + * 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 + */ + private checkEnum; + /** + * 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 + */ + private checkArray; + /** + * 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 + */ + private checkItem; + /** + * Visitor design pattern + * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationshipDeclaration; + /** + * Check a single relationship + * @param {Object} parameters - the parameter + * @param {*} relationshipDeclaration - the object being visited + * @param {Object} obj - the object being validated + * @private + */ + private checkRelationship; +} diff --git a/packages/concerto-core/types/lib/serializer/resourcevalidator.d.ts b/packages/concerto-core/types/lib/serializer/resourcevalidator.d.ts new file mode 100644 index 0000000000..001ccf58c1 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/resourcevalidator.d.ts @@ -0,0 +1,192 @@ +export = ResourceValidator; +/** + *

+ * 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. + *

+ * The parameters for the visit method must contain the following properties: + *
    + *
  • 'stack' - the TypedStack of objects being processed. It should + * start as [Resource] or [Field]
  • + *
  • 'rootResourceIdentifier' - the identifier of the resource being validated
  • + *
  • 'modelManager' - the ModelManager instance to use for type checking
  • + *
+ * @private + * @class + * @memberof module:concerto-core + */ +declare class ResourceValidator { + /** + * 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 + */ + private static reportFieldTypeViolation; + /** + * Throw a new error for a model violation. + * @param {string} id - the identifier of this instance. + * @param {classDeclaration} classDeclaration - the declaration of the classs + * @param {Object} value - the value of the field. + * @private + */ + private static reportNotResouceViolation; + /** + * Throw a new error for a model violation. + * @param {string} id - the identifier of this instance. + * @param {RelationshipDeclaration} relationshipDeclaration - the declaration of the classs + * @param {Object} value - the value of the field. + * @private + */ + private static reportNotRelationshipViolation; + /** + * Throw a new error for a missing, but required field. + * @param {string} id - the identifier of this instance. + * @param {Field} field - the field/ + * @private + */ + private static reportMissingRequiredProperty; + /** + * Throw a new error for a missing, but required field. + * @param {string} id - the identifier of this instance. + * @param {Field} field - the field/ + * @private + */ + private static reportEmptyIdentifier; + /** + * 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 + */ + private static reportInvalidEnumValue; + /** + * Throw a validation exception for an abstract class + * @param {ClassDeclaration} classDeclaration - the class declaration + * @throws {ValidationException} the validation exception + * @private + */ + private static reportAbstractClass; + /** + * Throw a validation exception for an abstract class + * @param {string} resourceId - the id of the resouce 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 + */ + private static reportUndeclaredField; + /** + * Throw a validation exception for an invalid field assignment + * @param {string} resourceId - the id of the resouce 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 + */ + private static reportInvalidFieldAssignment; + /** + * 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: { + validate: boolean; + convertResourcesToRelationships: boolean; + permitResourcesForRelationships: boolean; + }); + options: {}; + /** + * Visitor design pattern. + * + * @param {Object} thing - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visit; + /** + * Visitor design pattern + * + * @param {EnumDeclaration} enumDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumDeclaration; + /** + * Visitor design pattern + * @param {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclaration; + /** + * Returns true if the property is a system property. + * System properties are not declared in the model. + * @param {String} propertyName - the name of the property + * @return {Boolean} true if the property is a system property + * @private + */ + private isSystemProperty; + /** + * Visitor design pattern + * @param {Field} field - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitField; + /** + * 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 + */ + private checkEnum; + /** + * 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 + */ + private checkArray; + /** + * 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 + */ + private checkItem; + /** + * Visitor design pattern + * @param {RelationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationshipDeclaration; + /** + * Check a single relationship + * @param {Object} parameters - the parameter + * @param {relationshipDeclaration} relationshipDeclaration - the object being visited + * @param {Object} obj - the object being validated + * @private + */ + private checkRelationship; +} diff --git a/packages/concerto-core/types/lib/serializer/typedstack.d.ts b/packages/concerto-core/types/lib/serializer/typedstack.d.ts new file mode 100644 index 0000000000..226bcfcfe4 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/typedstack.d.ts @@ -0,0 +1,38 @@ +export = TypedStack; +/** + * Tracks a stack of typed instances. The type information is used to detect + * overflow / underflow bugs by the caller. It also performs basic sanity + * checking on push/pop to make detecting bugs easier. + * @class + * @memberof module:concerto-core + */ +declare class TypedStack { + /** + * Create the Stack with the resource at the head. + * @param {Object} resource - the resource to be put at the head of the stack + */ + constructor(resource: any); + stack: any[]; + /** + * Push a new object. + * @param {Object} obj - the object being visited + * @param {Object} expectedType - the expected type of the object being pushed + */ + push(obj: any, expectedType: any): void; + /** + * Push a new object. + * @param {Object} expectedType - the type that should be the result of pop + * @return {Object} the result of pop + */ + pop(expectedType: any): any; + /** + * Peek the top of the stack + * @param {Object} expectedType - the type that should be the result of pop + * @return {Object} the result of peek + */ + peek(expectedType: any): any; + /** + * Clears the stack + */ + clear(): void; +} diff --git a/packages/concerto-core/types/lib/serializer/validationexception.d.ts b/packages/concerto-core/types/lib/serializer/validationexception.d.ts new file mode 100644 index 0000000000..53ee2ba92b --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/validationexception.d.ts @@ -0,0 +1,12 @@ +export = ValidationException; +/** + * Exception thrown when a resource fails to model against the model + * @extends BaseException + * @see See {@link BaseException} + * @class + * @memberof module:concerto-core + * @private + */ +declare class ValidationException extends BaseException { +} +import BaseException = require("../baseexception"); diff --git a/packages/concerto-core/types/lib/serializer/valuegenerator.d.ts b/packages/concerto-core/types/lib/serializer/valuegenerator.d.ts new file mode 100644 index 0000000000..0a54ea7540 --- /dev/null +++ b/packages/concerto-core/types/lib/serializer/valuegenerator.d.ts @@ -0,0 +1,17 @@ +export = ValueGeneratorFactory; +/** + * Factory providing static methods to create ValueGenerator instances. + * @private + */ +declare class ValueGeneratorFactory { + /** + * Create a value generator that supplies empty values. + * @return {ValueGenerator} a value generator. + */ + static empty(): ValueGenerator; + /** + * Create a value generator that supplies randomly generated sample values. + * @return {ValueGenerator} a value generator. + */ + static sample(): ValueGenerator; +} diff --git a/packages/concerto-core/types/lib/typenotfoundexception.d.ts b/packages/concerto-core/types/lib/typenotfoundexception.d.ts new file mode 100644 index 0000000000..04f0974be0 --- /dev/null +++ b/packages/concerto-core/types/lib/typenotfoundexception.d.ts @@ -0,0 +1,25 @@ +export = TypeNotFoundException; +/** + * Error thrown when a Concerto type does not exist. + * @extends BaseException + * @see see {@link BaseException} + * @class + * @memberof module:concerto-core + */ +declare class TypeNotFoundException extends BaseException { + /** + * Constructor. If the optional 'message' argument is not supplied, it will be set to a default value that + * includes the type name. + * @param {string} typeName - fully qualified type name. + * @param {string} [message] - error message. + * @param {string} component - the optional component which throws this error + */ + constructor(typeName: string, message?: string, component: string); + typeName: string; + /** + * Get the name of the type that was not found. + * @returns {string} fully qualified type name. + */ + getTypeName(): string; +} +import BaseException = require("./baseexception"); diff --git a/packages/concerto-core/types/lib/util.d.ts b/packages/concerto-core/types/lib/util.d.ts new file mode 100644 index 0000000000..3f1ad2539a --- /dev/null +++ b/packages/concerto-core/types/lib/util.d.ts @@ -0,0 +1,17 @@ +export = Util; +/** + * Internal Utility Class + *

+ * @private + * @class + * @memberof module:concerto-core + */ +declare class Util { + /** + * Returns true if the typeof the object === 'undefined' or + * the object === null. + * @param {Object} obj - the object to be tested + * @returns {boolean} true if the object is null or undefined + */ + static isNull(obj: any): boolean; +} diff --git a/packages/concerto-core/types/lib/writer.d.ts b/packages/concerto-core/types/lib/writer.d.ts new file mode 100644 index 0000000000..db71a332bb --- /dev/null +++ b/packages/concerto-core/types/lib/writer.d.ts @@ -0,0 +1,52 @@ +export = Writer; +/** + * Writer buffers text to be written in memory. It handles simple + * indentation and tracks the number of lines written. + * @private + * @class + * @memberof module:concerto-core + */ +declare class Writer { + beforeBuffer: string; + buffer: string; + linesWritten: number; + /** + * Writes text to the start of the buffer + * @param {int} tabs - the number of tabs to use + * @param {string} text - the text to write + */ + writeBeforeLine(tabs: int, text: string): void; + /** + * Append text to the buffer + * @param {int} tabs - the number of tabs to use + * @param {string} text - the text to write + */ + writeLine(tabs: int, text: string): void; + /** + * Returns the number of lines that have been written to the buffer. + * @return {int} the number of lines written to the buffer. + */ + getLineCount(): int; + /** + * Append text to the buffer, prepending tabs + * @param {int} tabs - the number of tabs to use + * @param {string} text - the text to write + */ + writeIndented(tabs: int, text: string): void; + /** + * Append text to the buffer (no automatic newline). The + * text may contain newline, and these will increment the linesWritten + * counter. + * @param {string} msg - the text to write + */ + write(msg: string): void; + /** + * Returns the text that has been buffered in this Writer. + * @return {string} the buffered text. + */ + getBuffer(): string; + /** + * Empties the underyling buffer and resets the line count. + */ + clearBuffer(): void; +}