Skip to content

Commit

Permalink
feat(map): get type from model file
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Casey <[email protected]>
  • Loading branch information
jonathan-casey committed Oct 20, 2023
1 parent cff5d76 commit 4579396
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/concerto-core/lib/introspect/mapkeytype.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class MapKeyType extends Decorated {
validate() {

if (!ModelUtil.isPrimitiveType(this.type)) {
const decl = ModelUtil.getTypeDeclaration(this.ast.type.name, this.modelFile);

const decl = this.modelFile.getType(this.ast.type.name);

if (!ModelUtil.isValidMapKeyScalar(decl)) {
throw new IllegalModelException(
Expand Down
3 changes: 2 additions & 1 deletion packages/concerto-core/lib/introspect/mapvaluetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class MapValueType extends Decorated {
*/
validate() {
if (!ModelUtil.isPrimitiveType(this.type)) {
const decl = ModelUtil.getTypeDeclaration(this.ast.type.name, this.modelFile);

const decl = this.modelFile.getType(this.ast.type.name);

// All declarations, with the exception of MapDeclarations, are valid Values.
if(decl.isMapDeclaration?.()) {
Expand Down
15 changes: 0 additions & 15 deletions packages/concerto-core/lib/modelutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,6 @@ class ModelUtil {
`${MetaModelNamespace}.ObjectMapValueType`
].includes(value.$class);
}

/**
* Returns the corresponding ClassDeclaration representation of the Map Type
* @param {string} type - the Type of the Map Value
* @param {ModelFile} modelFile - the ModelFile that owns the Property
* @return {Object} the corresponding ClassDeclaration representation
*/
static getTypeDeclaration(type, modelFile) {
if (modelFile.isLocalType(type)) {
return modelFile.getAllDeclarations().find(d => d.name === type);
} else {
const fqn = modelFile.resolveImport(type);
return modelFile.getModelManager().getType(fqn);
}
}
}

module.exports = ModelUtil;
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*/
namespace [email protected]

participant Customer identified by email {
participant CustomerParticipant identified by email {
o String email
}

map Customer {
o String
o Customer
o CustomerParticipant
}

0 comments on commit 4579396

Please sign in to comment.