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