From 3ec0f66f3684e69a65cbc1f0fb93f96be3258ad3 Mon Sep 17 00:00:00 2001 From: Simon Stone Date: Fri, 25 Mar 2022 10:15:16 +0000 Subject: [PATCH] fix(types): typescript type generation improvements (contributes to #402) Signed-off-by: Simon Stone --- package-lock.json | 5 + packages/concerto-core/api.txt | 8 +- packages/concerto-core/changelog.txt | 2 +- packages/concerto-core/index.js | 5 +- .../concerto-core/lib/basemodelmanager.js | 21 ++- packages/concerto-core/lib/factory.js | 10 +- .../lib/introspect/assetdeclaration.js | 8 + .../lib/introspect/classdeclaration.js | 11 +- .../lib/introspect/conceptdeclaration.js | 8 + .../concerto-core/lib/introspect/decorated.js | 13 +- .../concerto-core/lib/introspect/decorator.js | 9 ++ .../lib/introspect/decoratorfactory.js | 10 ++ .../lib/introspect/enumdeclaration.js | 8 + .../lib/introspect/enumvaluedeclaration.js | 8 + .../lib/introspect/eventdeclaration.js | 8 + .../concerto-core/lib/introspect/field.js | 8 + .../lib/introspect/identifieddeclaration.js | 8 + .../lib/introspect/illegalmodelexception.js | 10 +- .../lib/introspect/introspector.js | 9 ++ .../concerto-core/lib/introspect/metamodel.js | 2 +- .../concerto-core/lib/introspect/modelfile.js | 9 ++ .../lib/introspect/numbervalidator.js | 8 + .../lib/introspect/participantdeclaration.js | 8 + .../concerto-core/lib/introspect/property.js | 10 +- .../lib/introspect/relationshipdeclaration.js | 10 +- .../lib/introspect/stringvalidator.js | 8 + .../lib/introspect/transactiondeclaration.js | 8 + .../concerto-core/lib/introspect/validator.js | 8 + .../concerto-core/lib/model/identifiable.js | 2 +- .../concerto-core/lib/model/relationship.js | 8 + packages/concerto-core/lib/model/typed.js | 13 +- packages/concerto-core/lib/rootmodel.js | 5 +- .../concerto-core/lib/securityexception.js | 2 +- packages/concerto-core/lib/serializer.js | 12 +- .../lib/typenotfoundexception.js | 4 +- packages/concerto-core/package.json | 4 +- packages/concerto-core/types/index.d.ts | 3 +- .../types/lib/basemodelmanager.d.ts | 17 ++- packages/concerto-core/types/lib/factory.d.ts | 1 + .../lib/introspect/assetdeclaration.d.ts | 1 + .../lib/introspect/classdeclaration.d.ts | 11 ++ .../types/lib/introspect/decorated.d.ts | 6 +- .../types/lib/introspect/decorator.d.ts | 8 +- .../lib/introspect/decoratorfactory.d.ts | 5 +- .../lib/introspect/eventdeclaration.d.ts | 1 + .../lib/introspect/illegalmodelexception.d.ts | 4 +- .../types/lib/introspect/introspector.d.ts | 2 + .../types/lib/introspect/modelfile.d.ts | 2 + .../introspect/participantdeclaration.d.ts | 1 + .../types/lib/introspect/property.d.ts | 5 +- .../introspect/transactiondeclaration.d.ts | 1 + .../types/lib/introspect/validator.d.ts | 1 + .../types/lib/model/identifiable.d.ts | 4 +- .../types/lib/model/relationship.d.ts | 17 +++ .../concerto-core/types/lib/model/typed.d.ts | 10 +- .../concerto-core/types/lib/rootmodel.d.ts | 2 +- .../types/lib/securityexception.d.ts | 3 +- .../concerto-core/types/lib/serializer.d.ts | 3 + .../lib/serializer/validationexception.d.ts | 10 +- .../types/lib/typenotfoundexception.d.ts | 7 +- packages/concerto-cto/index.js | 15 +- packages/concerto-cto/lib/external.js | 5 +- packages/concerto-cto/lib/parseexception.js | 2 +- packages/concerto-cto/package.json | 6 +- packages/concerto-cto/types/index.d.ts | 10 +- packages/concerto-cto/types/lib/external.d.ts | 14 +- .../types/lib/parseexception.d.ts | 2 +- .../concerto-cto/types/lib/parserMain.d.ts | 10 -- packages/concerto-metamodel/index.js | 6 +- .../concerto-metamodel/lib/metamodelutil.js | 8 +- packages/concerto-metamodel/package.json | 6 +- packages/concerto-metamodel/types/index.d.ts | 3 +- .../types/lib/metamodelutil.d.ts | 29 +++- .../concerto-tools/lib/codegen/codegen.js | 30 ++-- packages/concerto-tools/package.json | 5 +- packages/concerto-tools/types/index.d.ts | 95 +----------- .../types/lib/codegen/abstractplugin.d.ts | 34 +++++ .../types/lib/codegen/codegen.d.ts | 10 ++ .../codegen/fromcto/csharp/csharpvisitor.d.ts | 94 ++++++++++++ .../codegen/fromcto/golang/golangvisitor.d.ts | 101 +++++++++++++ .../fromcto/graphql/graphqlvisitor.d.ts | 114 +++++++++++++++ .../lib/codegen/fromcto/java/emptyplugin.d.ts | 31 ++++ .../lib/codegen/fromcto/java/javavisitor.d.ts | 108 ++++++++++++++ .../fromcto/jsonschema/jsonschemavisitor.d.ts | 137 ++++++++++++++++++ .../fromcto/jsonschema/recursionvisitor.d.ts | 55 +++++++ .../fromcto/plantuml/plantumlvisitor.d.ts | 101 +++++++++++++ .../fromcto/typescript/typescriptvisitor.d.ts | 86 +++++++++++ .../fromcto/xmlschema/xmlschemavisitor.d.ts | 85 +++++++++++ packages/concerto-util/index.js | 42 ++++-- packages/concerto-util/lib/filewriter.js | 4 +- packages/concerto-util/package.json | 6 +- packages/concerto-util/types/index.d.ts | 22 ++- .../types/lib/baseexception.d.ts | 16 ++ .../types/lib/basefileexception.d.ts | 38 +++++ .../concerto-util/types/lib/filewriter.d.ts | 44 ++++++ packages/concerto-util/types/lib/label.d.ts | 12 ++ .../concerto-util/types/lib/modelwriter.d.ts | 7 + packages/concerto-vocabulary/index.js | 9 +- packages/concerto-vocabulary/package.json | 6 +- packages/concerto-vocabulary/types/index.d.ts | 5 +- 100 files changed, 1599 insertions(+), 229 deletions(-) create mode 100644 packages/concerto-tools/types/lib/codegen/abstractplugin.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/codegen.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/csharp/csharpvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/golang/golangvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/graphql/graphqlvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/java/emptyplugin.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/java/javavisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/jsonschemavisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/recursionvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/plantuml/plantumlvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/typescript/typescriptvisitor.d.ts create mode 100644 packages/concerto-tools/types/lib/codegen/fromcto/xmlschema/xmlschemavisitor.d.ts create mode 100644 packages/concerto-util/types/lib/baseexception.d.ts create mode 100644 packages/concerto-util/types/lib/basefileexception.d.ts create mode 100644 packages/concerto-util/types/lib/filewriter.d.ts create mode 100644 packages/concerto-util/types/lib/label.d.ts create mode 100644 packages/concerto-util/types/lib/modelwriter.d.ts diff --git a/package-lock.json b/package-lock.json index d895a51618..21d1bced80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9962,6 +9962,11 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", + "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" + }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 240cd5aea9..a19e32117e 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -66,6 +66,7 @@ class AssetDeclaration extends IdentifiedDeclaration { class ClassDeclaration extends Decorated { + void constructor(ModelFile,Object) throws IllegalModelException + ClassDeclaration _resolveSuperType() + ~ void validate() throws IllegalModelException + boolean isAbstract() + string getName() + string getNamespace() @@ -167,6 +168,7 @@ class ParticipantDeclaration extends IdentifiedDeclaration { class Property extends Decorated { + void constructor(ClassDeclaration,Object) throws IllegalModelException + ClassDeclaration getParent() + ~ void validate(ClassDeclaration) throws IllegalModelException + string getName() + string getType() + boolean isOptional() @@ -179,6 +181,7 @@ class Property extends Decorated { } class RelationshipDeclaration extends Property { + void constructor(ClassDeclaration,Object) throws IllegalModelException + ~ void validate(ClassDeclaration) throws IllegalModelException + String toString() + boolean isRelationship() } @@ -187,6 +190,7 @@ class TransactionDeclaration extends IdentifiedDeclaration { + string declarationKind() } class Identifiable extends Typed { + ~ void constructor(ModelManager,ClassDeclaration,string,string,string,string) + string getTimestamp() + string getIdentifier() + void setIdentifier(string) @@ -209,12 +213,14 @@ class Resource extends Identifiable { + Object toJSON() } class Typed { + ~ void constructor(ModelManager,ClassDeclaration,string,string) + string getType() + string getFullyQualifiedType() + string getNamespace() + void setPropertyValue(string,string) + void addArrayValue(string,string) + boolean instanceOf(String) + ~ void toJSON() } class ValidatedResource extends Resource { + void setPropertyValue(string,string) throws Error @@ -239,6 +245,6 @@ class Serializer { + Resource fromJSON(Object,Object?,boolean,boolean,number?) } 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 10f9994344..0cd5a36291 100644 --- a/packages/concerto-core/changelog.txt +++ b/packages/concerto-core/changelog.txt @@ -24,7 +24,7 @@ # Note that the latest public API is documented using JSDocs and is available in api.txt. # -Version 2.0.0-alpha.1 {ee5fa0479fe2720d720ac500b1b3ead8} 2021-11-24 +Version 2.0.0-alpha.1 {4169a97a927d336f3c76f85f00725c13} 2021-11-24 - Remove custom instanceof and add methods to check runtime type - Remove support for Node 12 - Generate Typescript definitions from JSDoc diff --git a/packages/concerto-core/index.js b/packages/concerto-core/index.js index 74a7b600da..80debd15e3 100644 --- a/packages/concerto-core/index.js +++ b/packages/concerto-core/index.js @@ -14,6 +14,9 @@ 'use strict'; +const fs = require('fs'); +const path = require('path'); + /** * Concerto core module. Concerto is a framework for defining domain * specific models. @@ -89,7 +92,7 @@ const Concerto = require('./lib/concerto'); const MetaModel = require('./lib/introspect/metamodel'); // Version -const version = require('./package.json'); +const version = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8')); module.exports = { SecurityException, diff --git a/packages/concerto-core/lib/basemodelmanager.js b/packages/concerto-core/lib/basemodelmanager.js index 12c03a6bbd..78be641648 100644 --- a/packages/concerto-core/lib/basemodelmanager.js +++ b/packages/concerto-core/lib/basemodelmanager.js @@ -16,10 +16,8 @@ const fsPath = require('path'); -const DefaultFileLoader = require('@accordproject/concerto-util').DefaultFileLoader; -const FileDownloader = require('@accordproject/concerto-util').FileDownloader; -const ModelWriter = require('@accordproject/concerto-util').ModelWriter; -const MetaModelUtil = require('@accordproject/concerto-metamodel').MetaModelUtil; +const { DefaultFileLoader, FileDownloader, ModelWriter } = require('@accordproject/concerto-util'); +const { MetaModelUtil } = require('@accordproject/concerto-metamodel'); const Factory = require('./factory'); const Globalize = require('./globalize'); @@ -30,6 +28,21 @@ const Serializer = require('./serializer'); const TypeNotFoundException = require('./typenotfoundexception'); const { rootModelFile, rootModelCto, rootModelAst } = require('./rootmodel'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const AssetDeclaration = require('./introspect/assetdeclaration'); + const ClassDeclaration = require('./introspect/classdeclaration'); + const ConceptDeclaration = require('./introspect/conceptdeclaration'); + const DecoratorFactory = require('./introspect/decoratorfactory'); + const EnumDeclaration = require('./introspect/enumdeclaration'); + const EventDeclaration = require('./introspect/eventdeclaration'); + const ParticipantDeclaration = require('./introspect/participantdeclaration'); + const TransactionDeclaration = require('./introspect/transactiondeclaration'); +} +/* eslint-enable no-unused-vars */ + const debug = require('debug')('concerto:BaseModelManager'); // How to create a modelfile from the external content diff --git a/packages/concerto-core/lib/factory.js b/packages/concerto-core/lib/factory.js index a21efa0f68..270782b84c 100644 --- a/packages/concerto-core/lib/factory.js +++ b/packages/concerto-core/lib/factory.js @@ -14,7 +14,7 @@ 'use strict'; -const TypedStack = require('@accordproject/concerto-util').TypedStack; +const { TypedStack } = require('@accordproject/concerto-util'); const debug = require('debug')('concerto:Factory'); const Globalize = require('./globalize'); @@ -35,6 +35,14 @@ const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); dayjs.extend(utc); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelManager = require('./modelmanager'); +} +/* eslint-enable no-unused-vars */ + /** * Use the Factory to create instances of Resource: transactions, participants * and assets. diff --git a/packages/concerto-core/lib/introspect/assetdeclaration.js b/packages/concerto-core/lib/introspect/assetdeclaration.js index f852eb3fa6..3ea5455f45 100644 --- a/packages/concerto-core/lib/introspect/assetdeclaration.js +++ b/packages/concerto-core/lib/introspect/assetdeclaration.js @@ -16,6 +16,14 @@ const IdentifiedDeclaration = require('./identifieddeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** * AssetDeclaration defines the schema (aka model or class) for * an Asset. It extends ClassDeclaration which manages a set of diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 98aaf4e6a3..c5f6e95e8c 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -23,6 +23,15 @@ const Introspector = require('./introspector'); const ModelUtil = require('../modelutil'); const RelationshipDeclaration = require('./relationshipdeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); + const Property = require('./property'); +} +/* eslint-enable no-unused-vars */ + /** * ClassDeclaration defines the structure (model/schema) of composite data. * It is composed of a set of Properties, may have an identifying field, and may @@ -184,7 +193,7 @@ class ClassDeclaration extends Decorated { * contents/relations of fields. * * @throws {IllegalModelException} - * @private + * @protected */ validate() { super.validate(); diff --git a/packages/concerto-core/lib/introspect/conceptdeclaration.js b/packages/concerto-core/lib/introspect/conceptdeclaration.js index 99cd94d87a..4b18bc03c2 100644 --- a/packages/concerto-core/lib/introspect/conceptdeclaration.js +++ b/packages/concerto-core/lib/introspect/conceptdeclaration.js @@ -16,6 +16,14 @@ const ClassDeclaration = require('./classdeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** * ConceptDeclaration defines the schema (aka model or class) for * an Concept. It extends ClassDeclaration which manages a set of diff --git a/packages/concerto-core/lib/introspect/decorated.js b/packages/concerto-core/lib/introspect/decorated.js index 99e7bda065..26876a6ade 100644 --- a/packages/concerto-core/lib/introspect/decorated.js +++ b/packages/concerto-core/lib/introspect/decorated.js @@ -17,6 +17,14 @@ const Decorator = require('./decorator'); const IllegalModelException = require('./illegalmodelexception'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** * Decorated defines a model element that may have decorators attached. * @@ -99,10 +107,11 @@ class Decorated { * override this method to impose additional semantic constraints on the * contents/relations of fields. * + * @param {...*} args the validation arguments * @throws {IllegalModelException} - * @private + * @protected */ - validate() { + validate(...args) { for(let n=0; n < this.decorators.length; n++) { let decorator = this.decorators[n]; decorator.validate(); diff --git a/packages/concerto-core/lib/introspect/decorator.js b/packages/concerto-core/lib/introspect/decorator.js index 50b2a10763..c1e9b4a936 100644 --- a/packages/concerto-core/lib/introspect/decorator.js +++ b/packages/concerto-core/lib/introspect/decorator.js @@ -14,6 +14,15 @@ 'use strict'; +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); + const Property = require('./property'); +} +/* eslint-enable no-unused-vars */ + /** * Decorator encapsulates a decorator (annotation) on a class or property. * @class diff --git a/packages/concerto-core/lib/introspect/decoratorfactory.js b/packages/concerto-core/lib/introspect/decoratorfactory.js index 2b9a0834f4..0f8a70bb1a 100644 --- a/packages/concerto-core/lib/introspect/decoratorfactory.js +++ b/packages/concerto-core/lib/introspect/decoratorfactory.js @@ -14,6 +14,16 @@ 'use strict'; +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); + const Decorator = require('./decorator'); + const Property = require('./property'); +} +/* eslint-enable no-unused-vars */ + /** * An interface for a class that processes a decorator and returns a specific * implementation class for that decorator. diff --git a/packages/concerto-core/lib/introspect/enumdeclaration.js b/packages/concerto-core/lib/introspect/enumdeclaration.js index 43cc10eec9..431fb095c9 100644 --- a/packages/concerto-core/lib/introspect/enumdeclaration.js +++ b/packages/concerto-core/lib/introspect/enumdeclaration.js @@ -16,6 +16,14 @@ const ClassDeclaration = require('./classdeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** * EnumDeclaration defines an enumeration of static values. * diff --git a/packages/concerto-core/lib/introspect/enumvaluedeclaration.js b/packages/concerto-core/lib/introspect/enumvaluedeclaration.js index a1a58d36f4..74ad8d4d94 100644 --- a/packages/concerto-core/lib/introspect/enumvaluedeclaration.js +++ b/packages/concerto-core/lib/introspect/enumvaluedeclaration.js @@ -16,6 +16,14 @@ const Property = require('./property'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); +} +/* eslint-enable no-unused-vars */ + /** * Class representing a value from a set of enumerated values * diff --git a/packages/concerto-core/lib/introspect/eventdeclaration.js b/packages/concerto-core/lib/introspect/eventdeclaration.js index 3ac96a6003..56072d174b 100644 --- a/packages/concerto-core/lib/introspect/eventdeclaration.js +++ b/packages/concerto-core/lib/introspect/eventdeclaration.js @@ -16,6 +16,14 @@ const IdentifiedDeclaration = require('./identifieddeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** Class representing the definition of an Event. * @extends ClassDeclaration * @see See {@link ClassDeclaration} diff --git a/packages/concerto-core/lib/introspect/field.js b/packages/concerto-core/lib/introspect/field.js index 572711c47f..0d8d3f58f1 100644 --- a/packages/concerto-core/lib/introspect/field.js +++ b/packages/concerto-core/lib/introspect/field.js @@ -18,6 +18,14 @@ const Property = require('./property'); const NumberValidator = require('./numbervalidator'); const StringValidator = require('./stringvalidator'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); +} +/* eslint-enable no-unused-vars */ + /** * Class representing the definition of a Field. A Field is owned * by a ClassDeclaration and has a name, type and additional metadata diff --git a/packages/concerto-core/lib/introspect/identifieddeclaration.js b/packages/concerto-core/lib/introspect/identifieddeclaration.js index 27b129a3f5..bff83aa070 100644 --- a/packages/concerto-core/lib/introspect/identifieddeclaration.js +++ b/packages/concerto-core/lib/introspect/identifieddeclaration.js @@ -16,6 +16,14 @@ const ClassDeclaration = require('./classdeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** * IdentifiedDeclaration * diff --git a/packages/concerto-core/lib/introspect/illegalmodelexception.js b/packages/concerto-core/lib/introspect/illegalmodelexception.js index 819c059a8d..a4a72fea6f 100644 --- a/packages/concerto-core/lib/introspect/illegalmodelexception.js +++ b/packages/concerto-core/lib/introspect/illegalmodelexception.js @@ -14,7 +14,15 @@ 'use strict'; -const BaseFileException = require('@accordproject/concerto-util').BaseFileException; +const { BaseFileException } = require('@accordproject/concerto-util'); + +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ /** * Exception throws when a composer file is semantically invalid diff --git a/packages/concerto-core/lib/introspect/introspector.js b/packages/concerto-core/lib/introspect/introspector.js index 6d7aeeb1e5..e8a6a61b07 100644 --- a/packages/concerto-core/lib/introspect/introspector.js +++ b/packages/concerto-core/lib/introspect/introspector.js @@ -14,6 +14,15 @@ 'use strict'; +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); + const ModelManager = require('../modelmanager'); +} +/* eslint-enable no-unused-vars */ + /** * * Provides access to the structure of transactions, assets and participants. diff --git a/packages/concerto-core/lib/introspect/metamodel.js b/packages/concerto-core/lib/introspect/metamodel.js index 9431436588..d141f30a83 100644 --- a/packages/concerto-core/lib/introspect/metamodel.js +++ b/packages/concerto-core/lib/introspect/metamodel.js @@ -14,7 +14,7 @@ 'use strict'; -const MetaModelUtil = require('@accordproject/concerto-metamodel').MetaModelUtil; +const { MetaModelUtil } = require('@accordproject/concerto-metamodel'); const ModelManager = require('../modelmanager'); const Factory = require('../factory'); diff --git a/packages/concerto-core/lib/introspect/modelfile.js b/packages/concerto-core/lib/introspect/modelfile.js index 8becfc6afa..01ff22a7d3 100644 --- a/packages/concerto-core/lib/introspect/modelfile.js +++ b/packages/concerto-core/lib/introspect/modelfile.js @@ -26,6 +26,15 @@ const IllegalModelException = require('./illegalmodelexception'); const ModelUtil = require('../modelutil'); const Globalize = require('../globalize'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); + const ModelManager = require('../modelmanager'); +} +/* eslint-enable no-unused-vars */ + /** * Class representing a Model File. A Model File contains a single namespace * and a set of model elements: assets, transactions etc. diff --git a/packages/concerto-core/lib/introspect/numbervalidator.js b/packages/concerto-core/lib/introspect/numbervalidator.js index 7946a87612..3387aa2025 100644 --- a/packages/concerto-core/lib/introspect/numbervalidator.js +++ b/packages/concerto-core/lib/introspect/numbervalidator.js @@ -16,6 +16,14 @@ const Validator = require('./validator'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const Field = require('./field'); +} +/* eslint-enable no-unused-vars */ + /** * A Validator to enforce that non null numeric values are between two values. * @private diff --git a/packages/concerto-core/lib/introspect/participantdeclaration.js b/packages/concerto-core/lib/introspect/participantdeclaration.js index 0a8a28574b..1050fc5031 100644 --- a/packages/concerto-core/lib/introspect/participantdeclaration.js +++ b/packages/concerto-core/lib/introspect/participantdeclaration.js @@ -16,6 +16,14 @@ const IdentifiedDeclaration = require('./identifieddeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** Class representing the definition of a Participant. * @extends ClassDeclaration * @see See {@link ClassDeclaration} diff --git a/packages/concerto-core/lib/introspect/property.js b/packages/concerto-core/lib/introspect/property.js index 0fd8251c3e..434018f6a8 100644 --- a/packages/concerto-core/lib/introspect/property.js +++ b/packages/concerto-core/lib/introspect/property.js @@ -17,6 +17,14 @@ const Decorated = require('./decorated'); const ModelUtil = require('../modelutil'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); +} +/* eslint-enable no-unused-vars */ + /** * Property representing an attribute of a class declaration, * either a Field or a Relationship. @@ -97,7 +105,7 @@ class Property extends Decorated { * Validate the property * @param {ClassDeclaration} classDecl the class declaration of the property * @throws {IllegalModelException} - * @private + * @protected */ validate(classDecl) { super.validate(); diff --git a/packages/concerto-core/lib/introspect/relationshipdeclaration.js b/packages/concerto-core/lib/introspect/relationshipdeclaration.js index f2f5addfdf..02dbeb8393 100644 --- a/packages/concerto-core/lib/introspect/relationshipdeclaration.js +++ b/packages/concerto-core/lib/introspect/relationshipdeclaration.js @@ -18,6 +18,14 @@ const Property = require('./property'); const IllegalModelException = require('./illegalmodelexception'); const ModelUtil = require('../modelutil'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('./classdeclaration'); +} +/* eslint-enable no-unused-vars */ + /** * Class representing a relationship between model elements * @extends Property @@ -41,7 +49,7 @@ class RelationshipDeclaration extends Property { * Validate the property * @param {ClassDeclaration} classDecl the class declaration of the property * @throws {IllegalModelException} - * @private + * @protected */ validate(classDecl) { super.validate(classDecl); diff --git a/packages/concerto-core/lib/introspect/stringvalidator.js b/packages/concerto-core/lib/introspect/stringvalidator.js index c11c7ce934..36a106117d 100644 --- a/packages/concerto-core/lib/introspect/stringvalidator.js +++ b/packages/concerto-core/lib/introspect/stringvalidator.js @@ -16,6 +16,14 @@ const Validator = require('./validator'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const Field = require('./field'); +} +/* eslint-enable no-unused-vars */ + /** * A Validator to enforce that a string matches a regex * @private diff --git a/packages/concerto-core/lib/introspect/transactiondeclaration.js b/packages/concerto-core/lib/introspect/transactiondeclaration.js index b671574956..b7b43e46fb 100644 --- a/packages/concerto-core/lib/introspect/transactiondeclaration.js +++ b/packages/concerto-core/lib/introspect/transactiondeclaration.js @@ -16,6 +16,14 @@ const IdentifiedDeclaration = require('./identifieddeclaration'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelFile = require('./modelfile'); +} +/* eslint-enable no-unused-vars */ + /** Class representing the definition of an Transaction. * @extends ClassDeclaration * @see See {@link ClassDeclaration} diff --git a/packages/concerto-core/lib/introspect/validator.js b/packages/concerto-core/lib/introspect/validator.js index 9865a5b662..0409d71ba4 100644 --- a/packages/concerto-core/lib/introspect/validator.js +++ b/packages/concerto-core/lib/introspect/validator.js @@ -14,6 +14,14 @@ 'use strict'; +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const Field = require('./field'); +} +/* eslint-enable no-unused-vars */ + /** * An Abstract field validator. Extend this class and override the * validate method. diff --git a/packages/concerto-core/lib/model/identifiable.js b/packages/concerto-core/lib/model/identifiable.js index 8846dd218a..b842ad9dad 100644 --- a/packages/concerto-core/lib/model/identifiable.js +++ b/packages/concerto-core/lib/model/identifiable.js @@ -40,7 +40,7 @@ class Identifiable extends Typed { * @param {string} type - The type this instance. * @param {string} id - The identifier of this instance. * @param {string} timestamp - The timestamp of this instance - * @private + * @protected */ constructor(modelManager, classDeclaration, ns, type, id, timestamp) { super(modelManager, classDeclaration, ns, type); diff --git a/packages/concerto-core/lib/model/relationship.js b/packages/concerto-core/lib/model/relationship.js index 34ae4f45c9..6cdf904572 100644 --- a/packages/concerto-core/lib/model/relationship.js +++ b/packages/concerto-core/lib/model/relationship.js @@ -18,6 +18,14 @@ const Identifiable = require('./identifiable'); const ModelUtil = require('../modelutil'); const ResourceId = require('./resourceid'); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ModelManager = require('../modelmanager'); +} +/* eslint-enable no-unused-vars */ + /** * A Relationship is a typed pointer to an instance. I.e the relationship * with namespace = 'org.example', type = 'Vehicle' and id = 'ABC' creates diff --git a/packages/concerto-core/lib/model/typed.js b/packages/concerto-core/lib/model/typed.js index 0b37b473bb..5d9848a8f0 100644 --- a/packages/concerto-core/lib/model/typed.js +++ b/packages/concerto-core/lib/model/typed.js @@ -18,6 +18,15 @@ const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); dayjs.extend(utc); +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const ClassDeclaration = require('../introspect/classdeclaration'); + const ModelManager = require('../modelmanager'); +} +/* eslint-enable no-unused-vars */ + /** * Object is an instance with a namespace and a type. * @@ -38,7 +47,7 @@ class Typed { * @param {ClassDeclaration} classDeclaration - The class declaration for this instance. * @param {string} ns - The namespace this instance. * @param {string} type - The type this instance. - * @private + * @protected */ constructor(modelManager, classDeclaration, ns, type) { this.$modelManager = modelManager; @@ -187,7 +196,7 @@ class Typed { /** * Overriden to prevent people accidentally converting a resource to JSON * without using the Serializer. - * @private + * @protected */ toJSON() { throw new Error('Use Serializer.toJSON to convert resource instances to JSON objects.'); diff --git a/packages/concerto-core/lib/rootmodel.js b/packages/concerto-core/lib/rootmodel.js index c5e685fbd9..f39cf28e86 100644 --- a/packages/concerto-core/lib/rootmodel.js +++ b/packages/concerto-core/lib/rootmodel.js @@ -14,6 +14,9 @@ 'use strict'; +const fs = require('fs'); +const path = require('path'); + const rootModelFile = 'concerto.cto'; const rootModelCto = `namespace concerto abstract concept Concept {} @@ -22,6 +25,6 @@ abstract concept Participant identified {} abstract concept Transaction {} abstract concept Event {} `; -const rootModelAst = require('./rootmodel.json'); // Bootstrapped by applying the parser to the rootModelCto +const rootModelAst = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'rootmodel.json'), 'utf-8')); // Bootstrapped by applying the parser to the rootModelCto module.exports = { rootModelFile, rootModelCto, rootModelAst }; diff --git a/packages/concerto-core/lib/securityexception.js b/packages/concerto-core/lib/securityexception.js index 0b0548aac5..3fb24857f7 100644 --- a/packages/concerto-core/lib/securityexception.js +++ b/packages/concerto-core/lib/securityexception.js @@ -14,7 +14,7 @@ 'use strict'; -const BaseException = require('@accordproject/concerto-util').BaseException; +const { BaseException } = require('@accordproject/concerto-util'); /** * Class representing a security exception diff --git a/packages/concerto-core/lib/serializer.js b/packages/concerto-core/lib/serializer.js index 29f49cbbe1..1543f92d9b 100644 --- a/packages/concerto-core/lib/serializer.js +++ b/packages/concerto-core/lib/serializer.js @@ -14,7 +14,7 @@ 'use strict'; -const TypedStack = require('@accordproject/concerto-util').TypedStack; +const { TypedStack } = require('@accordproject/concerto-util'); const DateTimeUtil = require('./datetimeutil'); const Globalize = require('./globalize'); const JSONGenerator = require('./serializer/jsongenerator'); @@ -29,6 +29,16 @@ const baseDefaultOptions = { utcOffset: defaultUtcOffset, }; +// Types needed for TypeScript generation. +/* eslint-disable no-unused-vars */ +/* istanbul ignore next */ +if (global === undefined) { + const Factory = require('./factory'); + const ModelManager = require('./modelmanager'); + const Resource = require('./model/resource'); +} +/* eslint-enable no-unused-vars */ + /** * Serialize Resources instances to/from various formats for long-term storage * (e.g. on the blockchain). diff --git a/packages/concerto-core/lib/typenotfoundexception.js b/packages/concerto-core/lib/typenotfoundexception.js index ba58391d11..d478182abd 100644 --- a/packages/concerto-core/lib/typenotfoundexception.js +++ b/packages/concerto-core/lib/typenotfoundexception.js @@ -14,7 +14,7 @@ 'use strict'; -const BaseException = require('@accordproject/concerto-util').BaseException; +const { BaseException } = require('@accordproject/concerto-util'); const Globalize = require('./globalize'); /** @@ -29,7 +29,7 @@ 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|undefined} message - error message. * @param {string} component - the optional component which throws this error */ constructor(typeName, message, component) { diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index f294053be9..44d8063738 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -18,11 +18,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "node ./scripts/api-changelog.js && nyc mocha --recursive -t 10000", "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": "tsc ./lib/**/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -58,6 +59,7 @@ "sinon": "12.0.0", "sinon-chai": "3.7.0", "tmp-promise": "3.0.2", + "typescript": "4.6.3", "webpack": "5.64.2", "webpack-cli": "4.9.1", "yargs": "17.3.1" diff --git a/packages/concerto-core/types/index.d.ts b/packages/concerto-core/types/index.d.ts index 8c1770eaa6..09e42f9ccc 100644 --- a/packages/concerto-core/types/index.d.ts +++ b/packages/concerto-core/types/index.d.ts @@ -30,4 +30,5 @@ import ModelLoader = require("./lib/modelloader"); import DateTimeUtil = require("./lib/datetimeutil"); import Concerto = require("./lib/concerto"); import MetaModel = require("./lib/introspect/metamodel"); -export { SecurityException, IllegalModelException, TypeNotFoundException, Decorator, DecoratorFactory, ClassDeclaration, IdentifiedDeclaration, AssetDeclaration, ConceptDeclaration, EnumValueDeclaration, EventDeclaration, ParticipantDeclaration, TransactionDeclaration, Property, Field, EnumDeclaration, RelationshipDeclaration, Typed, Identifiable, Relationship, Resource, Factory, Globalize, Introspector, ModelFile, ModelManager, Serializer, ModelUtil, ModelLoader, DateTimeUtil, Concerto, MetaModel, version }; +export const version: any; +export { SecurityException, IllegalModelException, TypeNotFoundException, Decorator, DecoratorFactory, ClassDeclaration, IdentifiedDeclaration, AssetDeclaration, ConceptDeclaration, EnumValueDeclaration, EventDeclaration, ParticipantDeclaration, TransactionDeclaration, Property, Field, EnumDeclaration, RelationshipDeclaration, Typed, Identifiable, Relationship, Resource, Factory, Globalize, Introspector, ModelFile, ModelManager, Serializer, ModelUtil, ModelLoader, DateTimeUtil, Concerto, MetaModel }; diff --git a/packages/concerto-core/types/lib/basemodelmanager.d.ts b/packages/concerto-core/types/lib/basemodelmanager.d.ts index 37e4a9a07e..db82e80eaa 100644 --- a/packages/concerto-core/types/lib/basemodelmanager.d.ts +++ b/packages/concerto-core/types/lib/basemodelmanager.d.ts @@ -24,8 +24,8 @@ declare class BaseModelManager { constructor(options?: object, processFile?: any); processFile: any; modelFiles: {}; - factory: Factory; - serializer: Serializer; + factory: any; + serializer: any; decoratorFactories: any[]; /** * Returns true @@ -131,7 +131,7 @@ declare class BaseModelManager { * @throws {IllegalModelException} if the models fail validation * @return {Promise} a promise when the download and update operation is completed. */ - updateExternalModels(options?: any, fileDownloader?: typeof import("@accordproject/concerto-util/types/lib/filedownloader")): Promise; + updateExternalModels(options?: any, fileDownloader?: FileDownloader): Promise; /** * Write all models in this model manager to the specified path in the file system * @@ -276,6 +276,15 @@ declare class BaseModelManager { */ getAst(resolve?: boolean): any; } +import ModelFile = require("./introspect/modelfile"); +import { FileDownloader } from "@accordproject/concerto-util"; +import ClassDeclaration = require("./introspect/classdeclaration"); +import AssetDeclaration = require("./introspect/assetdeclaration"); +import TransactionDeclaration = require("./introspect/transactiondeclaration"); +import EventDeclaration = require("./introspect/eventdeclaration"); +import ParticipantDeclaration = require("./introspect/participantdeclaration"); +import EnumDeclaration = require("./introspect/enumdeclaration"); +import ConceptDeclaration = require("./introspect/conceptdeclaration"); import Factory = require("./factory"); import Serializer = require("./serializer"); -import ModelFile = require("./introspect/modelfile"); +import DecoratorFactory = require("./introspect/decoratorfactory"); diff --git a/packages/concerto-core/types/lib/factory.d.ts b/packages/concerto-core/types/lib/factory.d.ts index df3d177538..decf5e0620 100644 --- a/packages/concerto-core/types/lib/factory.d.ts +++ b/packages/concerto-core/types/lib/factory.d.ts @@ -131,5 +131,6 @@ declare class Factory { */ private parseGenerateOptions; } +import ModelManager = require("./modelmanager"); import Resource = require("./model/resource"); import Relationship = require("./model/relationship"); diff --git a/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts index 48676484da..9632315ef8 100644 --- a/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/assetdeclaration.d.ts @@ -25,3 +25,4 @@ declare class AssetDeclaration { */ declarationKind(): string; } +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts index c6ca65fe53..5f11e3347f 100644 --- a/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/classdeclaration.d.ts @@ -47,6 +47,15 @@ declare class ClassDeclaration extends Decorated { * @return {ClassDeclaration} The super type, or null if non specified. */ _resolveSuperType(): ClassDeclaration; + /** + * Semantic validation of the structure of this class. Subclasses should + * override this method to impose additional semantic constraints on the + * contents/relations of fields. + * + * @throws {IllegalModelException} + * @protected + */ + protected validate(): void; /** * Returns true if this class is declared as abstract in the model file * @@ -198,3 +207,5 @@ declare class ClassDeclaration extends Decorated { isClassDeclaration(): boolean; } import Decorated = require("./decorated"); +import Property = require("./property"); +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/decorated.d.ts b/packages/concerto-core/types/lib/introspect/decorated.d.ts index 1629320965..c08df92d91 100644 --- a/packages/concerto-core/types/lib/introspect/decorated.d.ts +++ b/packages/concerto-core/types/lib/introspect/decorated.d.ts @@ -46,10 +46,11 @@ declare class Decorated { * override this method to impose additional semantic constraints on the * contents/relations of fields. * + * @param {...*} args the validation arguments * @throws {IllegalModelException} - * @private + * @protected */ - private validate; + protected validate(...args: any[]): void; /** * Returns the decorators for this class. * @@ -63,4 +64,5 @@ declare class Decorated { */ getDecorator(name: string): Decorator; } +import ModelFile = require("./modelfile"); 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 index f42faa8500..d74f23ed31 100644 --- a/packages/concerto-core/types/lib/introspect/decorator.d.ts +++ b/packages/concerto-core/types/lib/introspect/decorator.d.ts @@ -11,9 +11,9 @@ declare class Decorator { * @param {Object} ast - The AST created by the parser * @throws {IllegalModelException} */ - constructor(parent: ClassDeclaration | Property, ast: any); + constructor(parent: Property | ClassDeclaration, ast: any); ast: any; - parent: any; + parent: Property | ClassDeclaration; arguments: any[]; /** * Visitor design pattern @@ -27,7 +27,7 @@ declare class Decorator { * Returns the owner of this property * @return {ClassDeclaration|Property} the parent class or property declaration */ - getParent(): ClassDeclaration | Property; + getParent(): Property | ClassDeclaration; /** * Process the AST and build the model * @throws {IllegalModelException} @@ -52,3 +52,5 @@ declare class Decorator { */ getArguments(): object[]; } +import Property = require("./property"); +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts b/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts index de868cd546..a272786c0a 100644 --- a/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts +++ b/packages/concerto-core/types/lib/introspect/decoratorfactory.d.ts @@ -14,5 +14,8 @@ declare class DecoratorFactory { * @param {Object} ast - The AST created by the parser * @return {Decorator} The decorator. */ - newDecorator(parent: ClassDeclaration | Property, ast: any): Decorator; + newDecorator(parent: Property | ClassDeclaration, ast: any): Decorator; } +import Property = require("./property"); +import ClassDeclaration = require("./classdeclaration"); +import Decorator = require("./decorator"); diff --git a/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts index 7e8057513f..2b369a8f40 100644 --- a/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/eventdeclaration.d.ts @@ -27,3 +27,4 @@ declare class EventDeclaration { */ declarationKind(): string; } +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts index 0400d27f9c..566557f326 100644 --- a/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts +++ b/packages/concerto-core/types/lib/introspect/illegalmodelexception.d.ts @@ -6,7 +6,7 @@ export = IllegalModelException; * @class * @memberof module:concerto-core */ -declare class IllegalModelException { +declare class IllegalModelException extends BaseFileException { /** * Create an IllegalModelException. * @param {string} message - the message for the exception @@ -20,3 +20,5 @@ declare class IllegalModelException { */ constructor(message: string, modelFile?: ModelFile, fileLocation?: any, component?: string); } +import { BaseFileException } from "@accordproject/concerto-util"; +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/introspector.d.ts b/packages/concerto-core/types/lib/introspect/introspector.d.ts index 6d20e0f9f1..5d1c40ccc6 100644 --- a/packages/concerto-core/types/lib/introspect/introspector.d.ts +++ b/packages/concerto-core/types/lib/introspect/introspector.d.ts @@ -41,3 +41,5 @@ declare class Introspector { */ private getModelManager; } +import ModelManager = require("../modelmanager"); +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/modelfile.d.ts b/packages/concerto-core/types/lib/introspect/modelfile.d.ts index 0a895bc0d4..12e159f6f2 100644 --- a/packages/concerto-core/types/lib/introspect/modelfile.d.ts +++ b/packages/concerto-core/types/lib/introspect/modelfile.d.ts @@ -250,6 +250,8 @@ declare class ModelFile { private fromAst; namespace: any; } +import ModelManager = require("../modelmanager"); +import ClassDeclaration = require("./classdeclaration"); import AssetDeclaration = require("./assetdeclaration"); import TransactionDeclaration = require("./transactiondeclaration"); import EventDeclaration = require("./eventdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts index 094277eedf..8be8c0a1ee 100644 --- a/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/participantdeclaration.d.ts @@ -21,3 +21,4 @@ declare class ParticipantDeclaration { */ declarationKind(): string; } +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/property.d.ts b/packages/concerto-core/types/lib/introspect/property.d.ts index c96ba3298e..dedec4c2fd 100644 --- a/packages/concerto-core/types/lib/introspect/property.d.ts +++ b/packages/concerto-core/types/lib/introspect/property.d.ts @@ -29,9 +29,9 @@ declare class Property extends Decorated { * Validate the property * @param {ClassDeclaration} classDecl the class declaration of the property * @throws {IllegalModelException} - * @private + * @protected */ - private validate; + protected validate(classDecl: ClassDeclaration): void; /** * Returns the name of a property * @return {string} the name of this field @@ -79,3 +79,4 @@ declare class Property extends Decorated { isPrimitive(): boolean; } import Decorated = require("./decorated"); +import ClassDeclaration = require("./classdeclaration"); diff --git a/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts index ae4d296b5e..0ac70ae4d2 100644 --- a/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts +++ b/packages/concerto-core/types/lib/introspect/transactiondeclaration.d.ts @@ -21,3 +21,4 @@ declare class TransactionDeclaration { */ declarationKind(): string; } +import ModelFile = require("./modelfile"); diff --git a/packages/concerto-core/types/lib/introspect/validator.d.ts b/packages/concerto-core/types/lib/introspect/validator.d.ts index 313e90fca3..a9d85fdd12 100644 --- a/packages/concerto-core/types/lib/introspect/validator.d.ts +++ b/packages/concerto-core/types/lib/introspect/validator.d.ts @@ -45,3 +45,4 @@ declare class Validator { */ private validate; } +import Field = require("./field"); diff --git a/packages/concerto-core/types/lib/model/identifiable.d.ts b/packages/concerto-core/types/lib/model/identifiable.d.ts index fb728c5a36..75ad9aba02 100644 --- a/packages/concerto-core/types/lib/model/identifiable.d.ts +++ b/packages/concerto-core/types/lib/model/identifiable.d.ts @@ -22,9 +22,9 @@ declare class Identifiable extends Typed { * @param {string} type - The type this instance. * @param {string} id - The identifier of this instance. * @param {string} timestamp - The timestamp of this instance - * @private + * @protected */ - private constructor(); + protected constructor(); $identifier: string; $timestamp: string; /** diff --git a/packages/concerto-core/types/lib/model/relationship.d.ts b/packages/concerto-core/types/lib/model/relationship.d.ts index b216a5b227..6fa5bc14b6 100644 --- a/packages/concerto-core/types/lib/model/relationship.d.ts +++ b/packages/concerto-core/types/lib/model/relationship.d.ts @@ -22,6 +22,23 @@ declare class Relationship extends Identifiable { * @return {Relationship} the relationship */ static fromURI(modelManager: ModelManager, uriAsString: string, defaultNamespace?: string, defaultType?: string): Relationship; + /** + * Create an asset. Use the Factory 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 + * @private + */ + private constructor(); $class: string; } import Identifiable = require("./identifiable"); +import ModelManager = require("../modelmanager"); diff --git a/packages/concerto-core/types/lib/model/typed.d.ts b/packages/concerto-core/types/lib/model/typed.d.ts index 7e42236776..e0cb14bc44 100644 --- a/packages/concerto-core/types/lib/model/typed.d.ts +++ b/packages/concerto-core/types/lib/model/typed.d.ts @@ -19,9 +19,9 @@ declare class Typed { * @param {ClassDeclaration} classDeclaration - The class declaration for this instance. * @param {string} ns - The namespace this instance. * @param {string} type - The type this instance. - * @private + * @protected */ - private constructor(); + protected constructor(); $modelManager: ModelManager; $classDeclaration: ClassDeclaration; $namespace: string; @@ -90,7 +90,9 @@ declare class Typed { /** * Overriden to prevent people accidentally converting a resource to JSON * without using the Serializer. - * @private + * @protected */ - private toJSON; + protected toJSON(): void; } +import ModelManager = require("../modelmanager"); +import ClassDeclaration = require("../introspect/classdeclaration"); diff --git a/packages/concerto-core/types/lib/rootmodel.d.ts b/packages/concerto-core/types/lib/rootmodel.d.ts index 4c27d82445..72162ebbe2 100644 --- a/packages/concerto-core/types/lib/rootmodel.d.ts +++ b/packages/concerto-core/types/lib/rootmodel.d.ts @@ -1,3 +1,3 @@ export const rootModelFile: "concerto.cto"; export const rootModelCto: "namespace concerto\nabstract concept Concept {}\nabstract concept Asset identified {}\nabstract concept Participant identified {}\nabstract concept Transaction {}\nabstract concept Event {}\n"; -export { rootModelAst }; +export const rootModelAst: any; diff --git a/packages/concerto-core/types/lib/securityexception.d.ts b/packages/concerto-core/types/lib/securityexception.d.ts index b9c2ac7d83..9cbf6d4394 100644 --- a/packages/concerto-core/types/lib/securityexception.d.ts +++ b/packages/concerto-core/types/lib/securityexception.d.ts @@ -6,10 +6,11 @@ export = SecurityException; * @class * @memberof module:concerto-core */ -declare class SecurityException { +declare class SecurityException extends BaseException { /** * Create the SecurityException. * @param {string} message - The exception message. */ constructor(message: string); } +import { BaseException } from "@accordproject/concerto-util"; diff --git a/packages/concerto-core/types/lib/serializer.d.ts b/packages/concerto-core/types/lib/serializer.d.ts index 417df09ead..0b9a2f9ab5 100644 --- a/packages/concerto-core/types/lib/serializer.d.ts +++ b/packages/concerto-core/types/lib/serializer.d.ts @@ -75,3 +75,6 @@ declare class Serializer { utcOffset?: number; }): Resource; } +import Factory = require("./factory"); +import ModelManager = require("./modelmanager"); +import Resource = require("./model/resource"); diff --git a/packages/concerto-core/types/lib/serializer/validationexception.d.ts b/packages/concerto-core/types/lib/serializer/validationexception.d.ts index f79b4bd82a..ef5846bbe9 100644 --- a/packages/concerto-core/types/lib/serializer/validationexception.d.ts +++ b/packages/concerto-core/types/lib/serializer/validationexception.d.ts @@ -7,11 +7,7 @@ export = ValidationException; * @memberof module:concerto-core * @private */ -declare class ValidationException { - /** - * Create a ValidationException - * @param {string} message - the message for the exception - * @param {string} component - the optional component which throws this error - */ - constructor(message: string, component: string); +declare class ValidationException extends BaseException { } +import BaseException_1 = require("@accordproject/concerto-util/types/lib/baseexception"); +import BaseException = BaseException_1.BaseException; diff --git a/packages/concerto-core/types/lib/typenotfoundexception.d.ts b/packages/concerto-core/types/lib/typenotfoundexception.d.ts index 8fc95d06d5..231c679315 100644 --- a/packages/concerto-core/types/lib/typenotfoundexception.d.ts +++ b/packages/concerto-core/types/lib/typenotfoundexception.d.ts @@ -6,15 +6,15 @@ export = TypeNotFoundException; * @class * @memberof module:concerto-core */ -declare class TypeNotFoundException { +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|undefined} message - error message. * @param {string} component - the optional component which throws this error */ - constructor(typeName: string, message?: string, component: string); + constructor(typeName: string, message: string | undefined, component: string); typeName: string; /** * Get the name of the type that was not found. @@ -22,3 +22,4 @@ declare class TypeNotFoundException { */ getTypeName(): string; } +import { BaseException } from "@accordproject/concerto-util"; diff --git a/packages/concerto-cto/index.js b/packages/concerto-cto/index.js index aac22fd397..4039813ce2 100644 --- a/packages/concerto-cto/index.js +++ b/packages/concerto-cto/index.js @@ -22,13 +22,20 @@ */ // Exceptions -module.exports.ParseException = require('./lib/parseexception'); +const ParseException = require('./lib/parseexception'); // Parser -module.exports.Parser = require('./lib/parserMain'); +const Parser = require('./lib/parserMain'); // Printer -module.exports.Printer = require('./lib/printer'); +const Printer = require('./lib/printer'); // External models resolution -module.exports.External = require('./lib/external'); +const External = require('./lib/external'); + +module.exports = { + ParseException, + Parser, + Printer, + External +}; diff --git a/packages/concerto-cto/lib/external.js b/packages/concerto-cto/lib/external.js index f283c795fb..5ac59cbab6 100644 --- a/packages/concerto-cto/lib/external.js +++ b/packages/concerto-cto/lib/external.js @@ -16,13 +16,12 @@ const path = require('path'); -const DefaultFileLoader = require('@accordproject/concerto-util').DefaultFileLoader; -const FileDownloader = require('@accordproject/concerto-util').FileDownloader; +const { DefaultFileLoader, FileDownloader } = require('@accordproject/concerto-util'); const debug = require('debug')('concerto:ModelManager'); const Parser = require('./parser'); -const MetaModelUtil = require('@accordproject/concerto-metamodel').MetaModelUtil; +const { MetaModelUtil } = require('@accordproject/concerto-metamodel'); /** * Update models with a new model diff --git a/packages/concerto-cto/lib/parseexception.js b/packages/concerto-cto/lib/parseexception.js index 0d1296e2be..6eca7155a6 100644 --- a/packages/concerto-cto/lib/parseexception.js +++ b/packages/concerto-cto/lib/parseexception.js @@ -14,7 +14,7 @@ 'use strict'; -const BaseFileException = require('@accordproject/concerto-util').BaseFileException; +const { BaseFileException } = require('@accordproject/concerto-util'); /** * Exception throws when a Concerto file is syntactically invalid diff --git a/packages/concerto-cto/package.json b/packages/concerto-cto/package.json index df68b1c797..703f9f8e31 100644 --- a/packages/concerto-cto/package.json +++ b/packages/concerto-cto/package.json @@ -16,11 +16,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "nyc mocha --recursive -t 10000", "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": "tsc ./lib/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -46,7 +47,8 @@ "nyc": "15.1.0", "peggy": "1.2.0", "sinon": "12.0.0", - "sinon-chai": "3.7.0" + "sinon-chai": "3.7.0", + "typescript": "4.6.3" }, "dependencies": { "@accordproject/concerto-metamodel": "2.0.0-alpha.2", diff --git a/packages/concerto-cto/types/index.d.ts b/packages/concerto-cto/types/index.d.ts index 1e99559763..a5d6fdd80e 100644 --- a/packages/concerto-cto/types/index.d.ts +++ b/packages/concerto-cto/types/index.d.ts @@ -1,5 +1,5 @@ -export var BaseException: typeof import("./lib/baseexception"); -export var BaseFileException: typeof import("./lib/basefileexception"); -export var ParseException: typeof import("./lib/parseexception"); -export var Parser: typeof import("./lib/parserMain"); -export var Printer: typeof import("./lib/printer"); +import ParseException = require("./lib/parseexception"); +import Parser = require("./lib/parserMain"); +import Printer = require("./lib/printer"); +import External = require("./lib/external"); +export { ParseException, Parser, Printer, External }; diff --git a/packages/concerto-cto/types/lib/external.d.ts b/packages/concerto-cto/types/lib/external.d.ts index 1492825606..c12eb513e6 100644 --- a/packages/concerto-cto/types/lib/external.d.ts +++ b/packages/concerto-cto/types/lib/external.d.ts @@ -1,7 +1,11 @@ /** - * Create decorator argument string from a metamodel - * @param {string} cto - the Concerto string - * @param {string} [fileName] - an optional file name - * @return {object} the string for the decorator argument + * Downloads all ModelFiles that are external dependencies and adds or + * updates them in this ModelManager. + * @param {*} models - the AST for all the known models + * @param {Object} [options] - Options object passed to ModelFileLoaders + * @param {FileDownloader} [fileDownloader] - an optional FileDownloader + * @throws {IllegalModelException} if the models fail validation + * @return {Promise} a promise when the download and update operation is completed. */ -export function parse(cto: string, fileName?: string): object; +export function resolveExternal(models: any, options?: any, fileDownloader?: FileDownloader): Promise; +import { FileDownloader } from "@accordproject/concerto-util"; diff --git a/packages/concerto-cto/types/lib/parseexception.d.ts b/packages/concerto-cto/types/lib/parseexception.d.ts index e8f583417e..00427aa29b 100644 --- a/packages/concerto-cto/types/lib/parseexception.d.ts +++ b/packages/concerto-cto/types/lib/parseexception.d.ts @@ -18,4 +18,4 @@ declare class ParseException extends BaseFileException { */ constructor(message: string, fileLocation?: string, fileName?: string, fullMessageOverride?: string, component?: string); } -import BaseFileException = require("./basefileexception"); +import { BaseFileException } from "@accordproject/concerto-util"; diff --git a/packages/concerto-cto/types/lib/parserMain.d.ts b/packages/concerto-cto/types/lib/parserMain.d.ts index 072d4bd06d..4733d7bfb6 100644 --- a/packages/concerto-cto/types/lib/parserMain.d.ts +++ b/packages/concerto-cto/types/lib/parserMain.d.ts @@ -11,13 +11,3 @@ export function parse(cto: string, fileName?: string): object; * @return {*} the AST / metamodel */ export function parseModels(files: string[]): any; -/** - * Downloads all ModelFiles that are external dependencies and adds or - * updates them in this ModelManager. - * @param {*} models - the AST for all the known models - * @param {Object} [options] - Options object passed to ModelFileLoaders - * @param {FileDownloader} [fileDownloader] - an optional FileDownloader - * @throws {IllegalModelException} if the models fail validation - * @return {Promise} a promise when the download and update operation is completed. - */ -export function resolve(models: any, options?: any, fileDownloader?: typeof import("@accordproject/concerto-util/types/lib/filedownloader")): Promise; diff --git a/packages/concerto-metamodel/index.js b/packages/concerto-metamodel/index.js index 10ef478db9..3dfc741c3c 100644 --- a/packages/concerto-metamodel/index.js +++ b/packages/concerto-metamodel/index.js @@ -22,4 +22,8 @@ */ // MetaModel handling -module.exports.MetaModelUtil = require('./lib/metamodelutil'); +const MetaModelUtil = require('./lib/metamodelutil'); + +module.exports = { + MetaModelUtil +}; diff --git a/packages/concerto-metamodel/lib/metamodelutil.js b/packages/concerto-metamodel/lib/metamodelutil.js index 0dc507a8e9..c962bf52bc 100644 --- a/packages/concerto-metamodel/lib/metamodelutil.js +++ b/packages/concerto-metamodel/lib/metamodelutil.js @@ -14,7 +14,13 @@ 'use strict'; -const metaModelAst = require('./metamodel.json'); +const fs = require('fs'); +const path = require('path'); + +/** + * The metamodel itself, as an AST. + */ +const metaModelAst = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'metamodel.json'), 'utf-8')); /** * The metamodel itself, as a CTO string diff --git a/packages/concerto-metamodel/package.json b/packages/concerto-metamodel/package.json index 6c4f528d37..24a8c485f1 100644 --- a/packages/concerto-metamodel/package.json +++ b/packages/concerto-metamodel/package.json @@ -16,11 +16,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "nyc mocha --recursive -t 10000", "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": "tsc ./lib/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -45,7 +46,8 @@ "mocha": "8.3.2", "nyc": "15.1.0", "sinon": "12.0.0", - "sinon-chai": "3.7.0" + "sinon-chai": "3.7.0", + "typescript": "4.6.3" }, "dependencies": { "@accordproject/concerto-util": "2.0.0-alpha.2" diff --git a/packages/concerto-metamodel/types/index.d.ts b/packages/concerto-metamodel/types/index.d.ts index 826e0c5eb8..6fa849b505 100644 --- a/packages/concerto-metamodel/types/index.d.ts +++ b/packages/concerto-metamodel/types/index.d.ts @@ -1 +1,2 @@ -export var MetaModelUtil: typeof import("./lib/metamodelutil"); +export { MetaModelUtil }; +import MetaModelUtil = require("./lib/metamodelutil"); diff --git a/packages/concerto-metamodel/types/lib/metamodelutil.d.ts b/packages/concerto-metamodel/types/lib/metamodelutil.d.ts index c971530475..0acac1cfe1 100644 --- a/packages/concerto-metamodel/types/lib/metamodelutil.d.ts +++ b/packages/concerto-metamodel/types/lib/metamodelutil.d.ts @@ -1,12 +1,35 @@ +/** + * The metamodel itself, as an AST. + */ +export const metaModelAst: any; /** * The metamodel itself, as a CTO string */ -export const metaModelCto: "namespace concerto.metamodel\n\nconcept Position {\n o Integer line\n o Integer column\n o Integer offset\n}\n\nconcept Range {\n o Position start\n o Position end\n o String source optional\n}\n\nconcept TypeIdentifier {\n o String name\n o String namespace optional\n}\n\nabstract concept DecoratorLiteral {\n o Range location optional\n}\n\nconcept DecoratorString extends DecoratorLiteral {\n o String value\n}\n\nconcept DecoratorNumber extends DecoratorLiteral {\n o Double value\n}\n\nconcept DecoratorBoolean extends DecoratorLiteral {\n o Boolean value\n}\n\nconcept DecoratorTypeReference extends DecoratorLiteral {\n o TypeIdentifier type\n o Boolean isArray default=false\n}\n\nconcept Decorator {\n o String name\n o DecoratorLiteral[] arguments optional\n o Range location optional\n}\n\nconcept Identified {\n}\n\nconcept IdentifiedBy extends Identified {\n o String name\n}\n\nabstract concept Declaration {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept EnumDeclaration extends Declaration {\n o EnumProperty[] properties\n}\n\nconcept EnumProperty {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept ConceptDeclaration extends Declaration {\n o Boolean isAbstract default=false\n o Identified identified optional\n o TypeIdentifier superType optional\n o Property[] properties\n}\n\nconcept AssetDeclaration extends ConceptDeclaration {\n}\n\nconcept ParticipantDeclaration extends ConceptDeclaration {\n}\n\nconcept TransactionDeclaration extends ConceptDeclaration {\n}\n\nconcept EventDeclaration extends ConceptDeclaration {\n}\n\nabstract concept Property {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Boolean isArray default=false\n o Boolean isOptional default=false\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept RelationshipProperty extends Property {\n o TypeIdentifier type\n}\n\nconcept ObjectProperty extends Property {\n o String defaultValue optional\n o TypeIdentifier type\n}\n\nconcept BooleanProperty extends Property {\n o Boolean defaultValue optional\n}\n\nconcept DateTimeProperty extends Property {\n}\n\nconcept StringProperty extends Property {\n o String defaultValue optional\n o StringRegexValidator validator optional\n}\n\nconcept StringRegexValidator {\n o String pattern\n o String flags\n}\n\nconcept DoubleProperty extends Property {\n o Double defaultValue optional\n o DoubleDomainValidator validator optional\n}\n\nconcept DoubleDomainValidator {\n o Double lower optional\n o Double upper optional\n}\n\nconcept IntegerProperty extends Property {\n o Integer defaultValue optional\n o IntegerDomainValidator validator optional\n}\n\nconcept IntegerDomainValidator {\n o Integer lower optional\n o Integer upper optional\n}\n\nconcept LongProperty extends Property {\n o Long defaultValue optional\n o LongDomainValidator validator optional\n}\n\nconcept LongDomainValidator {\n o Long lower optional\n o Long upper optional\n}\n\nabstract concept Import {\n o String namespace\n o String uri optional\n}\n\nconcept ImportAll extends Import {\n}\n\nconcept ImportType extends Import {\n o String name\n}\n\nconcept Model {\n o String namespace\n o String sourceUri optional\n o String concertoVersion optional\n o Import[] imports optional\n o Declaration[] declarations optional\n}\n\nconcept Models {\n o Model[] models\n}\n"; +export const metaModelCto: "namespace concerto.metamodel\n\nconcept Position {\n o Integer line\n o Integer column\n o Integer offset\n}\nconcept Range {\n o Position start\n o Position end\n o String source optional\n}\n\nconcept TypeIdentifier {\n o String name\n o String namespace optional\n}\n\nabstract concept DecoratorLiteral {\n o Range location optional\n}\n\nconcept DecoratorString extends DecoratorLiteral {\n o String value\n}\n\nconcept DecoratorNumber extends DecoratorLiteral {\n o Double value\n}\n\nconcept DecoratorBoolean extends DecoratorLiteral {\n o Boolean value\n}\n\nconcept DecoratorTypeReference extends DecoratorLiteral {\n o TypeIdentifier type\n o Boolean isArray default=false\n}\n\nconcept Decorator {\n o String name\n o DecoratorLiteral[] arguments optional\n o Range location optional\n}\n\nconcept Identified {\n}\n\nconcept IdentifiedBy extends Identified {\n o String name\n}\n\nabstract concept Declaration {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept EnumDeclaration extends Declaration {\n o EnumProperty[] properties\n}\n\nconcept EnumProperty {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept ConceptDeclaration extends Declaration {\n o Boolean isAbstract default=false\n o Identified identified optional\n o TypeIdentifier superType optional\n o Property[] properties\n}\n\nconcept AssetDeclaration extends ConceptDeclaration {\n}\n\nconcept ParticipantDeclaration extends ConceptDeclaration {\n}\n\nconcept TransactionDeclaration extends ConceptDeclaration {\n}\n\nconcept EventDeclaration extends ConceptDeclaration {\n}\n\nabstract concept Property {\n o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u\n o Boolean isArray default=false\n o Boolean isOptional default=false\n o Decorator[] decorators optional\n o Range location optional\n}\n\nconcept RelationshipProperty extends Property {\n o TypeIdentifier type\n}\n\nconcept ObjectProperty extends Property {\n o String defaultValue optional\n o TypeIdentifier type\n}\n\nconcept BooleanProperty extends Property {\n o Boolean defaultValue optional\n}\n\nconcept DateTimeProperty extends Property {\n}\n\nconcept StringProperty extends Property {\n o String defaultValue optional\n o StringRegexValidator validator optional\n}\n\nconcept StringRegexValidator {\n o String pattern\n o String flags\n}\n\nconcept DoubleProperty extends Property {\n o Double defaultValue optional\n o DoubleDomainValidator validator optional\n}\n\nconcept DoubleDomainValidator {\n o Double lower optional\n o Double upper optional\n}\n\nconcept IntegerProperty extends Property {\n o Integer defaultValue optional\n o IntegerDomainValidator validator optional\n}\n\nconcept IntegerDomainValidator {\n o Integer lower optional\n o Integer upper optional\n}\n\nconcept LongProperty extends Property {\n o Long defaultValue optional\n o LongDomainValidator validator optional\n}\n\nconcept LongDomainValidator {\n o Long lower optional\n o Long upper optional\n}\n\nabstract concept Import {\n o String namespace\n o String uri optional\n}\n\nconcept ImportAll extends Import {\n}\n\nconcept ImportType extends Import {\n o String name\n}\n\nconcept Model {\n o String namespace\n o String sourceUri optional\n o String concertoVersion optional\n o Import[] imports optional\n o Declaration[] declarations optional\n}\n\nconcept Models {\n o Model[] models\n}\n"; /** * Resolve the namespace for names in the metamodel * @param {*} priorModels - known models * @param {object} metaModel - the MetaModel - * @param {boolean} [validate] - whether to perform validation * @return {object} the resolved metamodel */ -export function resolveMetaModel(priorModels: any, metaModel: object): object; +export function resolveLocalNames(priorModels: any, metaModel: object): object; +/** + * Resolve the namespace for names in the metamodel + * @param {*} allModels - known models + * @return {object} the resolved metamodel + */ +export function resolveLocalNamesForAll(allModels: any): object; +/** + * Return the fully qualified name for an import + * @param {object} imp - the import + * @return {string} - the fully qualified name for that import + * @private + */ +export function importFullyQualifiedName(imp: object): string; +/** + * Returns an object that maps from the import declarations to the URIs specified + * @param {*} ast - the model ast + * @return {Object} keys are import declarations, values are URIs + * @private + */ +export function getExternalImports(ast: any): any; diff --git a/packages/concerto-tools/lib/codegen/codegen.js b/packages/concerto-tools/lib/codegen/codegen.js index 8c91cbbbc6..8d429600c4 100644 --- a/packages/concerto-tools/lib/codegen/codegen.js +++ b/packages/concerto-tools/lib/codegen/codegen.js @@ -14,13 +14,25 @@ 'use strict'; -module.exports.AbstractPlugin = require('./abstractplugin'); +const AbstractPlugin = require('./abstractplugin'); -module.exports.GoLangVisitor = require('./fromcto/golang/golangvisitor'); -module.exports.JSONSchemaVisitor = require('./fromcto/jsonschema/jsonschemavisitor'); -module.exports.XmlSchemaVisitor = require('./fromcto/xmlschema/xmlschemavisitor'); -module.exports.PlantUMLVisitor = require('./fromcto/plantuml/plantumlvisitor'); -module.exports.TypescriptVisitor = require('./fromcto/typescript/typescriptvisitor'); -module.exports.JavaVisitor = require('./fromcto/java/javavisitor'); -module.exports.GraphQLVisitor = require('./fromcto/graphql/graphqlvisitor'); -module.exports.CSharpVisitor = require('./fromcto/csharp/csharpvisitor'); +const GoLangVisitor = require('./fromcto/golang/golangvisitor'); +const JSONSchemaVisitor = require('./fromcto/jsonschema/jsonschemavisitor'); +const XmlSchemaVisitor = require('./fromcto/xmlschema/xmlschemavisitor'); +const PlantUMLVisitor = require('./fromcto/plantuml/plantumlvisitor'); +const TypescriptVisitor = require('./fromcto/typescript/typescriptvisitor'); +const JavaVisitor = require('./fromcto/java/javavisitor'); +const GraphQLVisitor = require('./fromcto/graphql/graphqlvisitor'); +const CSharpVisitor = require('./fromcto/csharp/csharpvisitor'); + +module.exports = { + AbstractPlugin, + GoLangVisitor, + JSONSchemaVisitor, + XmlSchemaVisitor, + PlantUMLVisitor, + TypescriptVisitor, + JavaVisitor, + GraphQLVisitor, + CSharpVisitor +}; diff --git a/packages/concerto-tools/package.json b/packages/concerto-tools/package.json index 552ab48297..a46a30b37d 100644 --- a/packages/concerto-tools/package.json +++ b/packages/concerto-tools/package.json @@ -17,10 +17,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "nyc mocha --recursive -t 10000", "test:watch": "nyc mocha --watch --recursive -t 10000", "mocha": "mocha --recursive -t 10000", - "nyc": "nyc mocha --recursive -t 10000" + "nyc": "nyc mocha --recursive -t 10000", + "build:types": "tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -51,6 +53,7 @@ "sinon": "12.0.0", "sinon-chai": "3.7.0", "tmp-promise": "3.0.2", + "typescript": "4.6.3", "webpack": "5.64.2", "webpack-cli": "4.9.1" }, diff --git a/packages/concerto-tools/types/index.d.ts b/packages/concerto-tools/types/index.d.ts index a8af891c79..153075fd21 100644 --- a/packages/concerto-tools/types/index.d.ts +++ b/packages/concerto-tools/types/index.d.ts @@ -1,93 +1,2 @@ -import { AssetDeclaration, ClassDeclaration, ConceptDeclaration, EnumDeclaration, EnumValueDeclaration, ModelManager, ModelFile, Field, Relationship, RelationshipDeclaration, TransactionDeclaration } from '@accordproject/concerto'; - -declare module '@accordproject/concerto-tools' { - export abstract class AbstractPlugin { - addClassImports(clazz: ClassDeclaration, parameters: any, options: any): void; - addClassAnnotations(clazz: ClassDeclaration, parameters: any, options: any): void; - addClassMethods(clazz: ClassDeclaration, parameters: any, options: any): void; - addEnumAnnotations(enumDecl: EnumDeclaration, parameters: any, options: any): void; - } - - export class GoLangVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - visitEnumDeclaration(enumDeclaration: EnumDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationship(relationship: Relationship, parameters: any): any | null; - containsDateTimeField(modelFile: ModelFile): boolean; - toGoType(type: string): string; - toGoPackageName(namespace: string): string; - } - - export class JSONSchemaVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - visitAssetDeclaration(assetDeclaration: AssetDeclaration, parameters: any): any | null; - visitTransactionDeclaration(transactionDeclaration: TransactionDeclaration, parameters: any): any | null; - visitConceptDeclaration(conceptDeclaration: ConceptDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitClassDeclarationCommon(classDeclaration: ClassDeclaration, parameters: any, jsonSchema: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationshipDeclaration(relationshipDeclaration: RelationshipDeclaration, parameters: any): any | null; - } - - export class XmlSchemaVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - visitEnumDeclaration(enumDeclaration: EnumDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationship(relationship: Relationship, parameters: any): any | null; - toXsType(type: string): string; - } - - export class PlantUMLVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - visitAssetDeclaration(assetDeclaration: AssetDeclaration, parameters: any): any | null; - visitEnumDeclaration(enumDeclaration: EnumDeclaration, parameters: any): any | null; - visitParticipantDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitTransactionDeclaration(transactionDeclaration: TransactionDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationship(relationship: Relationship, parameters: any): any | null; - } - - export class TypescriptVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - visitEnumDeclaration(enumDeclaration: EnumDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationship(relationship: Relationship, parameters: any): any | null; - toTsType(type: string): string; - } - - export class JavaVisitor { - visit(thing: any, parameters: any): any | null; - visitModelManager(modelManager: ModelManager, parameters: any): any | null; - visitModelFile(modelFile: ModelFile, parameters: any): any | null; - startClassFile(classDeclaration: ClassDeclaration, parameters: any): any | null; - endClassFile(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitEnumDeclaration(enumDeclaration: EnumDeclaration, parameters: any): any | null; - visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: any): any | null; - visitField(field: Field, parameters: any): any | null; - visitEnumValueDeclaration(enumValueDeclaration: EnumValueDeclaration, parameters: any): any | null; - visitRelationship(relationship: Relationship, parameters: any): any | null; - toJavaType(type: string): string; - capitalizeFirstLetter(s: string): string; - } - - export const version: any; -} +export var CodeGen: typeof import("./lib/codegen/codegen"); +export var version: any; diff --git a/packages/concerto-tools/types/lib/codegen/abstractplugin.d.ts b/packages/concerto-tools/types/lib/codegen/abstractplugin.d.ts new file mode 100644 index 0000000000..5995046b88 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/abstractplugin.d.ts @@ -0,0 +1,34 @@ +export = AbstractPlugin; +/** + * Simple plug-in class for code-generation. This lists functions that can be passed to extend the default code-generation behavior. + */ +declare class AbstractPlugin { + /** + * Additional imports to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + * @param {Object} options - the visitor options + */ + addClassImports(clazz: ClassDeclaration, parameters: any, options: any): void; + /** + * Additional annotations to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + * @param {Object} options - the visitor options + */ + addClassAnnotations(clazz: ClassDeclaration, parameters: any, options: any): void; + /** + * Additional methods to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + * @param {Object} options - the visitor options + */ + addClassMethods(clazz: ClassDeclaration, parameters: any, options: any): void; + /** + * Additional annotations to generate in enums + * @param {EnumDeclaration} enumDecl - the enum being visited + * @param {Object} parameters - the parameter + * @param {Object} options - the visitor options + */ + addEnumAnnotations(enumDecl: EnumDeclaration, parameters: any, options: any): void; +} diff --git a/packages/concerto-tools/types/lib/codegen/codegen.d.ts b/packages/concerto-tools/types/lib/codegen/codegen.d.ts new file mode 100644 index 0000000000..9a513bfc63 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/codegen.d.ts @@ -0,0 +1,10 @@ +import AbstractPlugin = require("./abstractplugin"); +import GoLangVisitor = require("./fromcto/golang/golangvisitor"); +import JSONSchemaVisitor = require("./fromcto/jsonschema/jsonschemavisitor"); +import XmlSchemaVisitor = require("./fromcto/xmlschema/xmlschemavisitor"); +import PlantUMLVisitor = require("./fromcto/plantuml/plantumlvisitor"); +import TypescriptVisitor = require("./fromcto/typescript/typescriptvisitor"); +import JavaVisitor = require("./fromcto/java/javavisitor"); +import GraphQLVisitor = require("./fromcto/graphql/graphqlvisitor"); +import CSharpVisitor = require("./fromcto/csharp/csharpvisitor"); +export { AbstractPlugin, GoLangVisitor, JSONSchemaVisitor, XmlSchemaVisitor, PlantUMLVisitor, TypescriptVisitor, JavaVisitor, GraphQLVisitor, CSharpVisitor }; diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/csharp/csharpvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/csharp/csharpvisitor.d.ts new file mode 100644 index 0000000000..d4795fa515 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/csharp/csharpvisitor.d.ts @@ -0,0 +1,94 @@ +export = CSharpVisitor; +/** + * Convert the contents of a ModelManager to C# code. Set a + * fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class CSharpVisitor { + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Ensures that a concerto property name is valid in CSharp + * @param {string} access the CSharp field access + * @param {string} propertyName the Concerto property name + * @param {string} propertyType the Concerto property type + * @param {string} array the array declaration + * @param {string} getset the getter and setter declaration + * @returns {string} the property declaration + */ + toCSharpProperty(access: string, propertyName: string, propertyType: string, array: string, getset: string): string; + /** + * Converts a Concerto type to a CSharp type. Primitive types are converted + * everything else is passed through unchanged. + * @param {string} type - the concerto type + * @return {string} the corresponding type in CSharp + * @private + */ + private toCSharpType; +} diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/golang/golangvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/golang/golangvisitor.d.ts new file mode 100644 index 0000000000..41d6d0d6a1 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/golang/golangvisitor.d.ts @@ -0,0 +1,101 @@ +export = GoLangVisitor; +/** + * Convert the contents of a ModelManager to Go Lang code. + * All generated code is placed into the 'main' package. Set a + * fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class GoLangVisitor { + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Returns true if the ModelFile contains a class that has a DateTime + * field. + * @param {ModelFile} modelFile - the modelFile + * @return {boolean} true if the modelFile contains a class that contains + * a field of type DateTime. + * @private + */ + private containsDateTimeField; + /** + * Converts a Concerto type to a Go Lang type. Primitive types are converted + * everything else is passed through unchanged. + * @param {string} type - the concerto type + * @return {string} the corresponding type in Go Lang + * @private + */ + private toGoType; + /** + * Converts a Concerto namespace to a Go package name. + * @param {string} namespace - the concerto type + * @return {string} the corresponding package name in Go Lang + * @private + */ + private toGoPackageName; +} diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/graphql/graphqlvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/graphql/graphqlvisitor.d.ts new file mode 100644 index 0000000000..ae0093abd9 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/graphql/graphqlvisitor.d.ts @@ -0,0 +1,114 @@ +export = GraphQLVisitor; +/** +* Convert the contents of a ModelManager to GraphQL types, based on +* the https://spec.graphql.org/June2018/ specification. +* Set a fileWriter property (instance of FileWriter) on the parameters +* object to control where the generated code is written to disk. +* +* @private +* @class +* @memberof module:concerto-tools +*/ +declare class GraphQLVisitor { + /** + * Constructor. + * @param {boolean} [namespaces] - whether or not namespaces should be used. + */ + constructor(namespaces?: boolean); + namespaces: boolean; + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Converts a Decorator to a GraphQL directive string, to be placed + * on a type or a field + * @param {Decorator} decorator - the decorator + * @param {Object} parameters - the parameters + * @return {String} the decorator as a GraphQL string + * @private + */ + private decoratorAsString; + /** + * Converts a Decorator to the definition of a directive + * that can be placed on an OBJECT or a FIELD_DEFINTION. Concerto doesn't + * have a model for Decorators, so we have to infer one from an instance. + * We use the last instance in the file to infer a model. :-/ + * @param {Decorator} decorator - the decorator + * @param {Object} parameters - the parameters + * @return {String} the decorator as a GraphQL directive string + * @private + */ + private decoratorAsDirectiveString; + /** + * @param {Decorator[]} decorators - the decorators + * @param {Object} parameters - the parameters + * @return {String} the decorators as a GraphQL string + * @private + */ + private decoratorsAsString; + /** + * Converts a Concerto type to a GraphQL type + * @param {string} type the Concerto type + * @returns {string} the GraphQL type + */ + toGraphQLType(type: string): string; + /** + * Escapes characters in a Concerto name to make them legal in GraphQL + * @param {string} name Concerto name + * @returns {string} a GraphQL legal name + */ + toGraphQLName(name: string): string; +} diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/java/emptyplugin.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/java/emptyplugin.d.ts new file mode 100644 index 0000000000..9917c18c20 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/java/emptyplugin.d.ts @@ -0,0 +1,31 @@ +export = EmptyPlugin; +/** + * Simple plug-in class for code-generation. This lists functions that can be passed to extend the default code-generation behavior. + */ +declare class EmptyPlugin extends AbstractPlugin { + /** + * Additional imports to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + */ + addClassImports(clazz: ClassDeclaration, parameters: any): void; + /** + * Additional annotations to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + */ + addClassAnnotations(clazz: ClassDeclaration, parameters: any): void; + /** + * Additional methods to generate in classes + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + */ + addClassMethods(clazz: ClassDeclaration, parameters: any): void; + /** + * Additional annotations to generate in enums + * @param {EnumDeclaration} enumDecl - the enum being visited + * @param {Object} parameters - the parameter + */ + addEnumAnnotations(enumDecl: EnumDeclaration, parameters: any): void; +} +import AbstractPlugin = require("../../abstractplugin"); diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/java/javavisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/java/javavisitor.d.ts new file mode 100644 index 0000000000..9520a942fc --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/java/javavisitor.d.ts @@ -0,0 +1,108 @@ +export = JavaVisitor; +/** + * Convert the contents of a ModelManager to Java code. + * Set a fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class JavaVisitor { + plugin: EmptyPlugin; + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * Write a Java class file header. The class file will be created in + * a file/folder based on the namespace of the class. + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + * @private + */ + private startClassFile; + /** + * Close a Java class file + * @param {ClassDeclaration} clazz - the clazz being visited + * @param {Object} parameters - the parameter + * @private + */ + private endClassFile; + /** + * 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; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Converts a Concerto type to a Java type. Primitive types are converted + * everything else is passed through unchanged. + * @param {string} type - the concerto type + * @return {string} the corresponding type in Java + * @private + */ + private toJavaType; + /** + * Capitalize the first letter of a string + * @param {string} s - the input string + * @return {string} the same string with first letter capitalized + * @private + */ + private capitalizeFirstLetter; +} +import EmptyPlugin = require("./emptyplugin"); diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/jsonschemavisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/jsonschemavisitor.d.ts new file mode 100644 index 0000000000..b96e2261e2 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/jsonschemavisitor.d.ts @@ -0,0 +1,137 @@ +export = JSONSchemaVisitor; +/** + * Convert the contents of a {@link ModelManager} to a JSON Schema, returning + * the schema for all types under the 'definitions' key. If the 'rootType' + * parameter option is set to a fully-qualified type name, then the properties + * of the type are also added to the root of the schema object. + * + * If the fileWriter parameter is set then the JSONSchema will be written to disk. + * + * Note that by default $ref is used to references types, unless + * the `inlineTypes` parameter is set, in which case types are expanded inline, + * UNLESS they contain recursive references, in which case $ref is used. + * + * The meta schema used is http://json-schema.org/draft-07/schema# + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class JSONSchemaVisitor { + /** + * Gets an object with all the decorators for a model element. The object + * is keyed by decorator name, while the values are the decorator arguments. + * @param {object} decorated a ClassDeclaration or a Property + * @returns {object} the decorators + */ + getDecorators(decorated: object): object; + /** + * Returns true if the class declaration contains recursive references. + * + * Basic example: + * concept Person { + * o Person[] children + * } + * + * @param {object} classDeclaration the class being visited + * @returns {boolean} true if the model is recursive + */ + isModelRecursive(classDeclaration: object): boolean; + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * Visitor design pattern + * @param {AssetDeclaration} assetDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitAssetDeclaration; + /** + * Visitor design pattern + * @param {TransactionDeclaration} transactionDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitTransactionDeclaration; + /** + * Visitor design pattern + * @param {ConceptDeclaration} conceptDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitConceptDeclaration; + /** + * 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 {ClassDeclaration} classDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @param {Object} jsonSchema - the base JSON Schema object to use + * @return {Object} the result of visiting or null + * @private + */ + private visitClassDeclarationCommon; + /** + * 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; + /** + * 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 {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * 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-tools/types/lib/codegen/fromcto/jsonschema/recursionvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/recursionvisitor.d.ts new file mode 100644 index 0000000000..adf9b84a48 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/jsonschema/recursionvisitor.d.ts @@ -0,0 +1,55 @@ +export = RecursionDetectionVisitor; +/** + * Detects whether ClassDeclaration contains recursive references. + * Basic example: + * concept Person { + * o Person[] children + * } + * + * parameters.stack should be initialized to [] + * @private + * @class + * @memberof module:concerto-tools + */ +declare class RecursionDetectionVisitor { + /** + * 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; + /** + * 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 {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-tools/types/lib/codegen/fromcto/plantuml/plantumlvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/plantuml/plantumlvisitor.d.ts new file mode 100644 index 0000000000..f49e91368c --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/plantuml/plantumlvisitor.d.ts @@ -0,0 +1,101 @@ +export = PlantUMLVisitor; +/** + * Convert the contents of a ModelManager + * to PlantUML format files. + * Set a fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class PlantUMLVisitor { + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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 visitAssetDeclaration; + /** + * 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 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 visitParticipantDeclaration; + /** + * 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 visitTransactionDeclaration; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; +} diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/typescript/typescriptvisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/typescript/typescriptvisitor.d.ts new file mode 100644 index 0000000000..d66c65a633 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/typescript/typescriptvisitor.d.ts @@ -0,0 +1,86 @@ +export = TypescriptVisitor; +/** + * Convert the contents of a ModelManager to TypeScript code. + * All generated code is placed into the 'main' package. Set a + * fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class TypescriptVisitor { + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Converts a Concerto type to a Typescript type. Primitive types are converted + * everything else is passed through unchanged. + * @param {string} type - the concerto type + * @param {boolean} useInterface - whether to use an interface type + * @return {string} the corresponding type in Typescript + * @private + */ + private toTsType; +} diff --git a/packages/concerto-tools/types/lib/codegen/fromcto/xmlschema/xmlschemavisitor.d.ts b/packages/concerto-tools/types/lib/codegen/fromcto/xmlschema/xmlschemavisitor.d.ts new file mode 100644 index 0000000000..8c4f1941a5 --- /dev/null +++ b/packages/concerto-tools/types/lib/codegen/fromcto/xmlschema/xmlschemavisitor.d.ts @@ -0,0 +1,85 @@ +export = XmlSchemaVisitor; +/** + * Convert the contents of a ModelManager + * to an XML Schema. + * Set a fileWriter property (instance of FileWriter) on the parameters + * object to control where the generated code is written to disk. + * + * @private + * @class + * @memberof module:concerto-tools + */ +declare class XmlSchemaVisitor { + /** + * 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 {ModelManager} modelManager - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelManager; + /** + * Visitor design pattern + * @param {ModelFile} modelFile - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitModelFile; + /** + * 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 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; + /** + * 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; + /** + * Visitor design pattern + * @param {EnumValueDeclaration} enumValueDeclaration - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitEnumValueDeclaration; + /** + * Visitor design pattern + * @param {Relationship} relationship - the object being visited + * @param {Object} parameters - the parameter + * @return {Object} the result of visiting or null + * @private + */ + private visitRelationship; + /** + * Converts a Concerto type to a XML Schema type. Primitive types are converted + * everything else is passed through unchanged. + * @param {string} type - the fully qualified concerto type name + * @return {string} the corresponding type in XML Schema + * @private + */ + private toXsType; +} diff --git a/packages/concerto-util/index.js b/packages/concerto-util/index.js index 6fae34c219..50187c7df9 100644 --- a/packages/concerto-util/index.js +++ b/packages/concerto-util/index.js @@ -22,28 +22,44 @@ */ // Exceptions -module.exports.BaseException = require('./lib/baseexception'); -module.exports.BaseFileException = require('./lib/basefileexception'); +const BaseException = require('./lib/baseexception'); +const BaseFileException = require('./lib/basefileexception'); // Transitive closure downloader -module.exports.FileDownloader = require('./lib/filedownloader'); +const FileDownloader = require('./lib/filedownloader'); // File Loaders -module.exports.CompositeFileLoader = require('./lib/loaders/compositefileloader'); -module.exports.DefaultFileLoader = require('./lib/loaders/defaultfileloader'); -module.exports.GitHubFileLoader = require('./lib/loaders/githubfileloader'); -module.exports.HTTPFileLoader = require('./lib/loaders/httpfileloader'); +const CompositeFileLoader = require('./lib/loaders/compositefileloader'); +const DefaultFileLoader = require('./lib/loaders/defaultfileloader'); +const GitHubFileLoader = require('./lib/loaders/githubfileloader'); +const HTTPFileLoader = require('./lib/loaders/httpfileloader'); // Writers -module.exports.Writer = require('./lib/writer'); -module.exports.FileWriter = require('./lib/filewriter'); -module.exports.ModelWriter = require('./lib/modelwriter'); +const Writer = require('./lib/writer'); +const FileWriter = require('./lib/filewriter'); +const ModelWriter = require('./lib/modelwriter'); // Logger -module.exports.Logger = require('./lib/logger'); +const Logger = require('./lib/logger'); // TypedStack -module.exports.TypedStack = require('./lib/typedstack'); +const TypedStack = require('./lib/typedstack'); // Label -module.exports.Label = require('./lib/label'); +const Label = require('./lib/label'); + +module.exports = { + BaseException, + BaseFileException, + FileDownloader, + CompositeFileLoader, + DefaultFileLoader, + GitHubFileLoader, + HTTPFileLoader, + Writer, + FileWriter, + ModelWriter, + Logger, + TypedStack, + Label +}; diff --git a/packages/concerto-util/lib/filewriter.js b/packages/concerto-util/lib/filewriter.js index 26031f19c5..c17ee7106d 100644 --- a/packages/concerto-util/lib/filewriter.js +++ b/packages/concerto-util/lib/filewriter.js @@ -72,7 +72,7 @@ class FileWriter extends Writer { /** * Writes text to the current open file - * @param {int} tabs - the number of tabs to use + * @param {number} tabs - the number of tabs to use * @param {string} text - the text to write */ writeLine(tabs,text) { @@ -85,7 +85,7 @@ class FileWriter extends Writer { /** * Writes text to the start of the current open file - * @param {int} tabs - the number of tabs to use + * @param {number} tabs - the number of tabs to use * @param {string} text - the text to write */ writeBeforeLine(tabs,text) { diff --git a/packages/concerto-util/package.json b/packages/concerto-util/package.json index fb63ee9372..46b9a19847 100644 --- a/packages/concerto-util/package.json +++ b/packages/concerto-util/package.json @@ -16,11 +16,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "nyc mocha --recursive -t 10000", "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": "tsc ./lib/**/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -44,7 +45,8 @@ "mocha": "8.3.2", "moxios": "0.4.0", "nyc": "15.1.0", - "tmp-promise": "3.0.2" + "tmp-promise": "3.0.2", + "typescript": "4.6.3" }, "dependencies": { "@supercharge/promise-pool": "1.7.0", diff --git a/packages/concerto-util/types/index.d.ts b/packages/concerto-util/types/index.d.ts index 3ef0ef7ba7..2d1aac4e27 100644 --- a/packages/concerto-util/types/index.d.ts +++ b/packages/concerto-util/types/index.d.ts @@ -1,8 +1,14 @@ -export var FileDownloader: typeof import("./lib/filedownloader"); -export var CompositeFileLoader: typeof import("./lib/loaders/compositefileloader"); -export var DefaultFileLoader: typeof import("./lib/loaders/defaultfileloader"); -export var GitHubFileLoader: typeof import("./lib/loaders/githubfileloader"); -export var HTTPFileLoader: typeof import("./lib/loaders/httpfileloader"); -export var Writer: typeof import("./lib/writer"); -export var Logger: typeof import("./lib/logger"); -export var TypedStack: typeof import("./lib/typedstack"); +import BaseException = require("./lib/baseexception"); +import BaseFileException = require("./lib/basefileexception"); +import FileDownloader = require("./lib/filedownloader"); +import CompositeFileLoader = require("./lib/loaders/compositefileloader"); +import DefaultFileLoader = require("./lib/loaders/defaultfileloader"); +import GitHubFileLoader = require("./lib/loaders/githubfileloader"); +import HTTPFileLoader = require("./lib/loaders/httpfileloader"); +import Writer = require("./lib/writer"); +import FileWriter = require("./lib/filewriter"); +import ModelWriter = require("./lib/modelwriter"); +import Logger = require("./lib/logger"); +import TypedStack = require("./lib/typedstack"); +import Label = require("./lib/label"); +export { BaseException, BaseFileException, FileDownloader, CompositeFileLoader, DefaultFileLoader, GitHubFileLoader, HTTPFileLoader, Writer, FileWriter, ModelWriter, Logger, TypedStack, Label }; diff --git a/packages/concerto-util/types/lib/baseexception.d.ts b/packages/concerto-util/types/lib/baseexception.d.ts new file mode 100644 index 0000000000..bdc321df80 --- /dev/null +++ b/packages/concerto-util/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-util/types/lib/basefileexception.d.ts b/packages/concerto-util/types/lib/basefileexception.d.ts new file mode 100644 index 0000000000..e0381effc7 --- /dev/null +++ b/packages/concerto-util/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-util/types/lib/filewriter.d.ts b/packages/concerto-util/types/lib/filewriter.d.ts new file mode 100644 index 0000000000..460bfa11fb --- /dev/null +++ b/packages/concerto-util/types/lib/filewriter.d.ts @@ -0,0 +1,44 @@ +export = FileWriter; +/** + * FileWriter creates text files under a directory tree. It can be used + * by code generators to create source files for example. + * Basic usage is: openFile(fileName), writeLine(...), closeFile(). + * + * @private + * @extends Writer + * @see See {@link Writer} + * @class + * @memberof module:concerto-core + */ +declare class FileWriter extends Writer { + /** + * Create a FileWriter. + * + * @param {string} outputDirectory - the path to an output directory + * that will be used to store generated files. + */ + constructor(outputDirectory: string); + outputDirectory: string; + relativeDir: string; + fileName: string; + /** + * Opens a file for writing. The file will be created in the + * root directory of this FileWriter. + * + * @param {string} fileName - the name of the file to open + */ + openFile(fileName: string): void; + /** + * Opens a file for writing, with a location relative to the + * root directory of this FileWriter. + * + * @param {string} relativeDir - the relative directory to use + * @param {string} fileName - the name of the file to open + */ + openRelativeFile(relativeDir: string, fileName: string): void; + /** + * Closes the current open file + */ + closeFile(): void; +} +import Writer = require("./writer"); diff --git a/packages/concerto-util/types/lib/label.d.ts b/packages/concerto-util/types/lib/label.d.ts new file mode 100644 index 0000000000..f6eec7c6ca --- /dev/null +++ b/packages/concerto-util/types/lib/label.d.ts @@ -0,0 +1,12 @@ +/** + * Inserts correct spacing and capitalization to a camelCase label + * @param {string} labelName - the label text to be transformed + * @returns {string} - The label text formatted for rendering + */ +export function labelToSentence(labelName?: string): string; +/** + * Create a camelCase label from a sentence + * @param {string} sentence - the sentence + * @returns {string} - The camelCase label + */ +export function sentenceToLabel(sentence?: string): string; diff --git a/packages/concerto-util/types/lib/modelwriter.d.ts b/packages/concerto-util/types/lib/modelwriter.d.ts new file mode 100644 index 0000000000..be8518af30 --- /dev/null +++ b/packages/concerto-util/types/lib/modelwriter.d.ts @@ -0,0 +1,7 @@ +/** + * Writes a set of model files to disk + * @param {*} files - the set of files to write, with names and whether they are external + * @param {string} path - a path to the directory where to write the files + * @param {*} options - a set of options + */ +export function writeModelsToFileSystem(files: any, path: string, options?: any): void; diff --git a/packages/concerto-vocabulary/index.js b/packages/concerto-vocabulary/index.js index d4488095c6..a00ffb645a 100644 --- a/packages/concerto-vocabulary/index.js +++ b/packages/concerto-vocabulary/index.js @@ -21,5 +21,10 @@ * @module concerto-vocabulary */ -module.exports.VocabularyManager = require('./lib/vocabularymanager'); -module.exports.Vocabulary = require('./lib/vocabulary'); \ No newline at end of file +const VocabularyManager = require('./lib/vocabularymanager'); +const Vocabulary = require('./lib/vocabulary'); + +module.exports = { + VocabularyManager, + Vocabulary +}; diff --git a/packages/concerto-vocabulary/package.json b/packages/concerto-vocabulary/package.json index e9f1d6c3d6..61e85e3e0e 100644 --- a/packages/concerto-vocabulary/package.json +++ b/packages/concerto-vocabulary/package.json @@ -16,11 +16,12 @@ "licchk": "license-check-and-add", "postlicchk": "npm run doc", "doc": "jsdoc --pedantic --recurse -c jsdoc.json", + "postdoc": "npm run build:types", "test": "nyc mocha --recursive -t 10000", "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": "tsc ./lib/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", @@ -44,7 +45,8 @@ "mocha": "8.3.2", "nyc": "15.1.0", "sinon": "12.0.0", - "sinon-chai": "3.7.0" + "sinon-chai": "3.7.0", + "typescript": "4.6.3" }, "dependencies": { "yaml": "2.0.0-9" diff --git a/packages/concerto-vocabulary/types/index.d.ts b/packages/concerto-vocabulary/types/index.d.ts index e6701c3c6a..77773c1c26 100644 --- a/packages/concerto-vocabulary/types/index.d.ts +++ b/packages/concerto-vocabulary/types/index.d.ts @@ -1,2 +1,3 @@ -export var VocabularyManager: typeof import("./lib/vocabularymanager"); -export var Vocabulary: typeof import("./lib/vocabulary"); +import VocabularyManager = require("./lib/vocabularymanager"); +import Vocabulary = require("./lib/vocabulary"); +export { VocabularyManager, Vocabulary };