-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dan Selman <[email protected]>
- Loading branch information
Showing
25 changed files
with
375 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ const ModelUtil = require('./modelutil'); | |
const Serializer = require('./serializer'); | ||
const TypeNotFoundException = require('./typenotfoundexception'); | ||
const { getRootModel } = require('./rootmodel'); | ||
const { getDecoratorModel } = require('./decoratormodel'); | ||
const MetamodelException = require('./metamodelexception'); | ||
|
||
// Types needed for TypeScript generation. | ||
|
@@ -63,6 +64,10 @@ const DEFAULT_DECORATOR_VALIDATION = { | |
invalidDecorator: undefined, // 'error' | 'warn' ... | ||
}; | ||
|
||
// these namespaces are internal and excluded by default by getModelFiles | ||
// and ignored by fromAst | ||
const EXCLUDE_NS = ['[email protected]', 'concerto', '[email protected]']; | ||
|
||
/** | ||
* Manages the Concerto model files. | ||
* | ||
|
@@ -102,6 +107,7 @@ class BaseModelManager { | |
this.decoratorFactories = []; | ||
this.strict = !!options?.strict; | ||
this.options = options; | ||
this.addDecoratorModel(); | ||
this.addRootModel(); | ||
this.decoratorValidation = options?.decoratorValidation ? options?.decoratorValidation : DEFAULT_DECORATOR_VALIDATION; | ||
|
||
|
@@ -166,6 +172,16 @@ class BaseModelManager { | |
} | ||
} | ||
|
||
/** | ||
* Adds decorator types | ||
* @private | ||
*/ | ||
addDecoratorModel() { | ||
const {decoratorModelAst, decoratorModelCto, decoratorModelFile} = getDecoratorModel(); | ||
const m = new ModelFile(this, decoratorModelAst, decoratorModelCto, decoratorModelFile); | ||
this.addModelFile(m, decoratorModelCto, decoratorModelFile, true); | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {Object} visitor - the visitor | ||
|
@@ -501,7 +517,7 @@ class BaseModelManager { | |
|
||
for (let n = 0; n < keys.length; n++) { | ||
const ns = keys[n]; | ||
if(includeConcertoNamespace || (ns !== '[email protected]' && ns !== 'concerto')) { | ||
if(includeConcertoNamespace || (!EXCLUDE_NS.includes(ns))) { | ||
result.push(this.modelFiles[ns]); | ||
} | ||
} | ||
|
@@ -580,6 +596,7 @@ class BaseModelManager { | |
*/ | ||
clearModelFiles() { | ||
this.modelFiles = {}; | ||
this.addDecoratorModel(); | ||
this.addRootModel(); | ||
} | ||
|
||
|
@@ -770,7 +787,7 @@ class BaseModelManager { | |
* @return {object} the resolved metamodel | ||
*/ | ||
resolveMetaModel(metaModel) { | ||
const priorModels = this.getAst(); | ||
const priorModels = this.getAst(false, true); | ||
return MetaModelUtil.resolveLocalNames(priorModels, metaModel); | ||
} | ||
|
||
|
@@ -781,25 +798,27 @@ class BaseModelManager { | |
fromAst(ast) { | ||
this.clearModelFiles(); | ||
ast.models.forEach( model => { | ||
if(model.namespace !== '[email protected]') { // excludes the Concerto namespace, already added | ||
if(!EXCLUDE_NS.includes(model.namespace)) { // excludes the internal namespaces, already added | ||
const modelFile = new ModelFile( this, model ); | ||
this.addModelFile( modelFile, null, null, true ); | ||
} | ||
}); | ||
console.log(Object.keys(this.modelFiles)); | ||
Check warning on line 806 in packages/concerto-core/lib/basemodelmanager.js GitHub Actions / Unit Tests (18.x, macos-latest)
Check warning on line 806 in packages/concerto-core/lib/basemodelmanager.js GitHub Actions / Unit Tests (18.x, ubuntu-latest)
Check warning on line 806 in packages/concerto-core/lib/basemodelmanager.js GitHub Actions / Unit Tests (20.x, macos-latest)
|
||
this.validateModelFiles(); | ||
} | ||
|
||
/** | ||
* Get the full ast (metamodel instances) for a modelmanager | ||
* @param {boolean} [resolve] - whether to resolve names | ||
* @param {boolean} [includeConcertoNamespaces] - whether to include the concerto namespaces | ||
* @returns {*} the metamodel | ||
*/ | ||
getAst(resolve) { | ||
getAst(resolve,includeConcertoNamespaces) { | ||
const result = { | ||
$class: `${MetaModelNamespace}.Models`, | ||
models: [], | ||
}; | ||
const modelFiles = this.getModelFiles(true); // includes the Concerto namespace | ||
const modelFiles = this.getModelFiles(includeConcertoNamespaces); | ||
modelFiles.forEach((thisModelFile) => { | ||
let metaModel = thisModelFile.getAst(); | ||
if (resolve) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,24 +374,20 @@ class DecoratorManager { | |
|
||
this.migrateAndValidate(modelManager, decoratorCommandSet, options?.migrate, options?.validate, options?.validateCommands); | ||
|
||
// we create synthetic imports for all decorator declarations | ||
const decoratorImports = decoratorCommandSet.commands.map(command => { | ||
return { | ||
$class: `${MetaModelNamespace}.ImportType`, | ||
name: command.decorator.name, | ||
namespace: command.decorator.namespace ? command.decorator.namespace : options.defaultNamespace | ||
namespace: command.decorator.namespace ? command.decorator.namespace : options?.defaultNamespace | ||
}; | ||
}).filter(i => i.namespace); | ||
decoratorImports.push({ | ||
$class: `${MetaModelNamespace}.ImportType`, | ||
name: 'Decorator', | ||
namespace: '[email protected]' | ||
}); | ||
|
||
const { namespaceCommandsMap, declarationCommandsMap, propertyCommandsMap, mapElementCommandsMap, typeCommandsMap } = this.getDecoratorMaps(decoratorCommandSet); | ||
const ast = modelManager.getAst(true); | ||
const ast = modelManager.getAst(true, true); | ||
const decoratedAst = JSON.parse(JSON.stringify(ast)); | ||
decoratedAst.models.forEach((model) => { | ||
model.imports = decoratorImports; | ||
// add the imports for all decorators, in case they get added below | ||
model.imports = model.imports ? model.imports.concat(decoratorImports) : decoratorImports; | ||
model.declarations.forEach((decl) => { | ||
const declarationDecoratorCommandSets = []; | ||
const { name: declarationName, $class: $classForDeclaration } = decl; | ||
|
@@ -467,7 +463,7 @@ class DecoratorManager { | |
locale:'en', | ||
...options | ||
}; | ||
const sourceAst = modelManager.getAst(true); | ||
const sourceAst = modelManager.getAst(true, true); | ||
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst, DecoratorExtractor.Action.EXTRACT_ALL); | ||
const collectionResp = decoratorExtrator.extract(); | ||
return { | ||
|
@@ -490,7 +486,7 @@ class DecoratorManager { | |
locale:'en', | ||
...options | ||
}; | ||
const sourceAst = modelManager.getAst(true); | ||
const sourceAst = modelManager.getAst(true, true); | ||
const decoratorExtrator = new DecoratorExtractor(options.removeDecoratorsFromModel, options.locale, DCS_VERSION, sourceAst, DecoratorExtractor.Action.EXTRACT_VOCAB); | ||
const collectionResp = decoratorExtrator.extract(); | ||
return { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** @type unknown */ | ||
const decoratorModelAst = require('./decoratormodel.json'); | ||
|
||
/** | ||
* Gets the decorator 'concerto.decorator' model | ||
* @returns {object} decoratorModelFile, decoratorModelCto and decoratorModelAst | ||
*/ | ||
function getDecoratorModel() { | ||
const decoratorModelFile = 'concerto_decorator_1.0.0.cto'; | ||
const decoratorModelCto = `namespace [email protected] | ||
abstract concept Decorator {} | ||
concept DotNetNamespace extends Decorator { | ||
o String namespace | ||
}`; | ||
const ast = JSON.parse(JSON.stringify(decoratorModelAst)); | ||
return { decoratorModelFile, decoratorModelCto, decoratorModelAst: ast }; | ||
} | ||
|
||
module.exports = { getDecoratorModel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$class": "[email protected]", | ||
"decorators": [], | ||
"namespace": "[email protected]", | ||
"imports": [], | ||
"declarations": [ | ||
{ | ||
"$class": "[email protected]", | ||
"name": "Decorator", | ||
"isAbstract": true, | ||
"properties": [] | ||
}, | ||
{ | ||
"$class": "[email protected]", | ||
"name": "DotNetNamespace", | ||
"superType": { | ||
"$class": "[email protected]", | ||
"name": "Decorator" | ||
}, | ||
"isAbstract": false, | ||
"properties": [ | ||
{ | ||
"$class": "[email protected]", | ||
"name": "namespace", | ||
"isArray": false, | ||
"isOptional": false | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,18 +27,16 @@ function getRootModel(versioned) { | |
const ns = versioned ? '[email protected]' : 'concerto'; | ||
const rootModelCto = `@DotNetNamespace("AccordProject.Concerto") | ||
namespace ${ns} | ||
import [email protected] | ||
abstract concept Concept {} | ||
abstract concept Asset identified {} | ||
abstract concept Participant identified {} | ||
abstract concept Transaction {} | ||
abstract concept Event {} | ||
abstract concept Decorator {} | ||
concept DotNetNamespace extends Decorator { | ||
o String namespace | ||
}`; | ||
`; | ||
const ast = JSON.parse(JSON.stringify(rootModelAst)); | ||
ast.namespace = ns; | ||
return { rootModelFile, rootModelCto, rootModelAst: ast }; | ||
} | ||
|
||
module.exports = { getRootModel }; | ||
module.exports = { getRootModel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,13 @@ | |
} | ||
], | ||
"namespace": "[email protected]", | ||
"imports": [], | ||
"imports": [ | ||
{ | ||
"$class": "[email protected]", | ||
"name": "DotNetNamespace", | ||
"namespace": "[email protected]" | ||
} | ||
], | ||
"declarations": [ | ||
{ | ||
"$class": "[email protected]", | ||
|
@@ -50,29 +56,6 @@ | |
"name": "Event", | ||
"isAbstract": true, | ||
"properties": [] | ||
}, | ||
{ | ||
"$class": "[email protected]", | ||
"name": "Decorator", | ||
"isAbstract": true, | ||
"properties": [] | ||
}, | ||
{ | ||
"$class": "[email protected]", | ||
"name": "DotNetNamespace", | ||
"superType": { | ||
"$class": "[email protected]", | ||
"name": "Decorator" | ||
}, | ||
"isAbstract": false, | ||
"properties": [ | ||
{ | ||
"$class": "[email protected]", | ||
"name": "namespace", | ||
"isArray": false, | ||
"isOptional": false | ||
} | ||
] | ||
} | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/concerto-core/test/data/decoratorcommands/decoratedTest.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
namespace [email protected] | ||
|
||
import [email protected] | ||
|
||
@Declaration() | ||
@NamespaceDeclaration() | ||
@NamespaceDeprecated() | ||
@Namespace() | ||
scalar SSN extends String | ||
|
||
@NamespaceDeprecated() | ||
@Namespace() | ||
concept Editable extends Decorator { | ||
} | ||
|
||
@NamespaceDeprecated() | ||
@Namespace() | ||
concept Custom extends Decorator { | ||
} | ||
|
||
@Editable | ||
@NamespaceDeprecated() | ||
@Namespace() | ||
|
Oops, something went wrong.