Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tools): add graph and graph search #614

Merged
merged 6 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BaseModelManager {
+ object resolveMetaModel(object)
+ void fromAst(ast)
+ void getAst(boolean?)
+ BaseModelManager filter(FilterFunction)
}
class Concerto {
+ void constructor(ModelManager)
Expand Down Expand Up @@ -71,15 +72,10 @@ class AssetDeclaration extends IdentifiedDeclaration {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ string declarationKind()
}
class ClassDeclaration extends Decorated {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ ModelFile getModelFile()
class ClassDeclaration extends Declaration {
+ ClassDeclaration _resolveSuperType()
~ void validate() throws IllegalModelException
+ boolean isAbstract()
+ string getName()
+ string getNamespace()
+ string getFullyQualifiedName()
+ Boolean isIdentified()
+ Boolean isSystemIdentified()
+ Boolean isExplicitlyIdentified()
Expand Down Expand Up @@ -107,6 +103,21 @@ class ConceptDeclaration extends ClassDeclaration {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ string declarationKind()
}
class Declaration extends Decorated {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ ModelFile getModelFile()
+ string getName()
+ string getNamespace()
+ string getFullyQualifiedName()
+ Boolean isIdentified()
+ Boolean isSystemIdentified()
+ string getIdentifierFieldName()
+ string getType()
+ String toString()
+ boolean isEnum()
+ boolean isClassDeclaration()
+ boolean isScalarDeclaration()
}
class Decorator {
+ void constructor(ClassDeclaration|Property,Object) throws IllegalModelException
+ void getParent()
Expand Down Expand Up @@ -202,31 +213,24 @@ class RelationshipDeclaration extends Property {
+ String toString()
+ boolean isRelationship()
}
class ScalarDeclaration extends Decorated {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ ModelFile getModelFile()
class ScalarDeclaration extends Declaration {
~ void validate() throws IllegalModelException
+ string getName()
+ string getNamespace()
+ string getFullyQualifiedName()
+ Boolean isIdentified()
+ Boolean isSystemIdentified()
+ void getIdentifierFieldName()
+ string getIdentifierFieldName()
+ string getType()
+ void getSuperType()
+ void getSuperTypeDeclaration()
+ string getSuperType()
+ ClassDeclaration getSuperTypeDeclaration()
+ Validator getValidator()
+ void getDefaultValue()
+ String toString()
+ boolean isAbstract()
+ boolean isScalarDeclaration()
+ boolean isAsset()
+ boolean isParticipant()
+ boolean isTransaction()
+ boolean isEvent()
+ boolean isConcept()
+ boolean isEnum()
+ boolean isClassDeclaration()
+ boolean isScalarDeclaration()
}
class TransactionDeclaration extends IdentifiedDeclaration {
+ void constructor(ModelFile,Object) throws IllegalModelException
Expand Down
3 changes: 3 additions & 0 deletions packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 3.5.0 {b419dc1b3db9662d8c941a044cd8db5a} 2023-03-07
- Introduce Declaration type. ClassDeclaration and Scalar Declaration both extend Declaration.

Version 3.0.0 {5fac664420fea3649a7a304941f190f1} 2022-08-28
- Allow client-provided RegExp engine to ModelManager
- Allow decorators to be attached to model files/namespaces
Expand Down
2 changes: 2 additions & 0 deletions packages/concerto-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const EnumValueDeclaration = require('./lib/introspect/enumvaluedeclaration');
const EventDeclaration = require('./lib/introspect/eventdeclaration');
const ParticipantDeclaration = require('./lib/introspect/participantdeclaration');
const TransactionDeclaration = require('./lib/introspect/transactiondeclaration');
const ScalarDeclaration = require('./lib/introspect/scalardeclaration');

// Properties
const Property = require('./lib/introspect/property');
Expand Down Expand Up @@ -114,6 +115,7 @@ module.exports = {
EventDeclaration,
ParticipantDeclaration,
TransactionDeclaration,
ScalarDeclaration,
Property,
Field,
EnumDeclaration,
Expand Down
27 changes: 27 additions & 0 deletions packages/concerto-core/lib/basemodelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const { getRootModel } = require('./rootmodel');
/* eslint-disable no-unused-vars */
/* istanbul ignore next */
if (global === undefined) {
const Declaration = require('./introspect/declaration');
const AssetDeclaration = require('./introspect/assetdeclaration');
const ClassDeclaration = require('./introspect/classdeclaration');
const ConceptDeclaration = require('./introspect/conceptdeclaration');
Expand Down Expand Up @@ -709,6 +710,32 @@ class BaseModelManager {
});
return result;
}


/**
* A function type definition for use as an argument to the filter function
* @callback FilterFunction
* @param {Declaration} declaration
* @returns {boolean} true, if the declaration satisfies the filter function
*/

/**
* Returns a new ModelManager with only the types for which the
* filter function returns true.
*
* ModelFiles with no declarations after filtering will be removed.
*
* @param {FilterFunction} predicate - the filter function over a Declaration object
* @returns {BaseModelManager} - the filtered ModelManager
*/
filter(predicate){
const modelManager = new BaseModelManager({...this.options}, this.processFile);
const filteredModels = Object.values(this.modelFiles)
.map((modelFile) => modelFile.filter(predicate, modelManager))
.filter(Boolean);
modelManager.addModelFiles(filteredModels);
return modelManager;
}
}

module.exports = BaseModelManager;
65 changes: 2 additions & 63 deletions packages/concerto-core/lib/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@

const { MetaModelNamespace } = require('@accordproject/concerto-metamodel');

const Decorated = require('./decorated');
const Declaration = require('./declaration');
const EnumValueDeclaration = require('./enumvaluedeclaration');
const Field = require('./field');
const Globalize = require('../globalize');
const IllegalModelException = require('./illegalmodelexception');
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 */
Expand All @@ -45,31 +43,7 @@ if (global === undefined) {
* @class
* @memberof module:concerto-core
*/
class ClassDeclaration extends Decorated {
/**
* Create a ClassDeclaration from an Abstract Syntax Tree. The AST is the
* result of parsing.
*
* @param {ModelFile} modelFile - the ModelFile for this class
* @param {Object} ast - the AST created by the parser
* @throws {IllegalModelException}
*/
constructor(modelFile, ast) {
super(ast);
this.modelFile = modelFile;
this.process();
}

/**
* Returns the ModelFile that defines this class.
*
* @public
* @return {ModelFile} the owning ModelFile
*/
getModelFile() {
return this.modelFile;
}

class ClassDeclaration extends Declaration {
/**
* Process the AST and build the model
*
Expand All @@ -79,13 +53,8 @@ class ClassDeclaration extends Decorated {
process() {
super.process();

if (!ModelUtil.isValidIdentifier(this.ast.name)){
throw new IllegalModelException(`Invalid class name '${this.ast.name}'`, this.modelFile, this.ast.location);
}

const reservedProperties = ['$class', '$identifier', '$timestamp'];

this.name = this.ast.name;
this.properties = [];
this.superType = null;
this.superTypeDeclaration = null;
Expand Down Expand Up @@ -143,8 +112,6 @@ class ClassDeclaration extends Decorated {
}
}

this.fqn = ModelUtil.getFullyQualifiedName(this.modelFile.getNamespace(), this.name);

if (this.fqn === '[email protected]' || this.fqn === '[email protected]') {
this.addTimestampField();
}
Expand Down Expand Up @@ -332,34 +299,6 @@ class ClassDeclaration extends Decorated {
return this.abstract;
}

/**
* Returns the short name of a class. This name does not include the
* namespace from the owning ModelFile.
*
* @return {string} the short name of this class
*/
getName() {
return this.name;
}

/**
* Return the namespace of this class.
* @return {string} namespace - a namespace.
*/
getNamespace() {
return this.modelFile.getNamespace();
}

/**
* Returns the fully qualified name of this class.
* The name will include the namespace if present.
*
* @return {string} the fully-qualified name of this class
*/
getFullyQualifiedName() {
return this.fqn;
}

/**
* Returns true if this class declaration declares an identifying field
* (system or explicit)
Expand Down
Loading