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(dcs): add map type support for decorator command targets #722

Merged
merged 32 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c690b3
feat(dcs): add map type support
jonathan-casey Oct 2, 2023
a074e5c
feat(dcs): add test coverage
jonathan-casey Oct 2, 2023
134c20b
add env var for test runner
jonathan-casey Oct 2, 2023
da4fdcf
feat(dcs): fix bug
jonathan-casey Oct 2, 2023
02de497
feat(dcs): add more test cases
jonathan-casey Oct 2, 2023
33c17ba
feat(dcs): add more test cov
jonathan-casey Oct 3, 2023
c57c1da
feat(dcs): rename command property to mapElement
jonathan-casey Oct 3, 2023
3c0a0c1
feat(dcs): refactor apply decorator logic
jonathan-casey Oct 3, 2023
76baa65
feat(dcs): fix typo
jonathan-casey Oct 3, 2023
ea63a5f
feat(dcs): jsdoc
jonathan-casey Oct 3, 2023
d51e5ef
restart GH check
jonathan-casey Oct 4, 2023
90ebf47
feat(dcs): refactor to use enum for target elements
jonathan-casey Oct 4, 2023
ec2a2d3
feat(dcs): remove unusued test fixture
jonathan-casey Oct 4, 2023
00b54e1
feat(dcs): reference MetaModelNamespace
jonathan-casey Oct 4, 2023
8aab804
feat(dcs): set decoratorcommands at version 0.3.0
jonathan-casey Oct 10, 2023
19efa27
Merge branch 'main' into jonathan/decorator_command_sets_map
jonathan-casey Oct 10, 2023
296ca11
feat(dcs): fix merge
jonathan-casey Oct 10, 2023
8fe1717
feat(map): auto migrates minor version
jonathan-casey Oct 16, 2023
13a4242
fix jsdoc format
jonathan-casey Oct 16, 2023
2d09e53
restart coveralls
jonathan-casey Oct 17, 2023
3bb1c25
feat(map): function rename
jonathan-casey Oct 18, 2023
3cbe91b
feat(map): function rename in test
jonathan-casey Oct 18, 2023
cf48362
feat(map): drop regex in favour of util fun
jonathan-casey Oct 18, 2023
e2cf402
feat(map): drop regex in favour of util fun
jonathan-casey Oct 18, 2023
8b799d5
feat(map): add client option to run migrate
jonathan-casey Oct 18, 2023
5f8729e
feat(map): add typedefs
jonathan-casey Oct 18, 2023
07aed29
feat(map): add changelog
jonathan-casey Oct 18, 2023
c961db4
test(map): add option to test
jonathan-casey Oct 18, 2023
3fc4aec
Merge branch 'main' into jonathan/decorator_command_sets_map
jonathan-casey Oct 18, 2023
83f01a4
chore: fix changelog
jonathan-casey Oct 18, 2023
1cb7055
feat(map): checks major version before migration
jonathan-casey Oct 19, 2023
3e856ce
feat(map): refactor conditional logic
jonathan-casey Oct 19, 2023
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
63 changes: 57 additions & 6 deletions packages/concerto-core/lib/decoratormanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ModelManager = require('./modelmanager');
const Serializer = require('./serializer');
const Factory = require('./factory');
const ModelUtil = require('./modelutil');
const { MetaModelNamespace } = require('@accordproject/concerto-metamodel');

const DCS_MODEL = `concerto version "^3.0.0"
namespace [email protected]
Expand Down Expand Up @@ -50,6 +51,16 @@ concept CommandTarget {
o String property optional
o String[] properties optional // property and properties are mutually exclusive
o String type optional
o MapElement mapElement optional
}

/**
* Map Declaration elements which might be used as a target
*/
enum MapElement {
o KEY
o VALUE
o KEY_VALUE
}

/**
Expand Down Expand Up @@ -237,6 +248,27 @@ class DecoratorManager {
}
}


/**
* Applies a new decorator to the Map element
* @private
* @param {string} element the element to apply the decorator to
* @param {string} target the command target
* @param {*} declaration the map declaration
* @param {string} type the command type
* @param {*} newDecorator the decorator to add
*/
static applyDecoratorForMapElement(element, target, declaration, type, newDecorator ) {
const decl = element === 'KEY' ? declaration.key : declaration.value;
if (target.type) {
if (this.falsyOrEqual(target.type, decl.$class)) {
this.applyDecorator(decl, type, newDecorator);
}
} else {
this.applyDecorator(decl, type, newDecorator);
}
}

/**
* Compares two arrays. If the first argument is falsy
* the function returns true.
Expand Down Expand Up @@ -296,12 +328,31 @@ class DecoratorManager {
*/
static executeCommand(namespace, declaration, command) {
const { target, decorator, type } = command;
const { name } = ModelUtil.parseNamespace(namespace);
if (
this.falsyOrEqual(target.namespace, [namespace, name]) &&
this.falsyOrEqual(target.declaration, [declaration.name])
) {
if (!target.property && !target.type) {
const { name } = ModelUtil.parseNamespace( namespace );
jonathan-casey marked this conversation as resolved.
Show resolved Hide resolved
if (this.falsyOrEqual(target.namespace, [namespace,name]) &&
this.falsyOrEqual(target.declaration, [declaration.name])) {

if (declaration.$class === `${MetaModelNamespace}.MapDeclaration`) {
if (target.mapElement) {
switch(target.mapElement) {
case 'KEY':
case 'VALUE':
this.applyDecoratorForMapElement(target.mapElement, target, declaration, type, decorator);
break;
case 'KEY_VALUE':
this.applyDecoratorForMapElement('KEY', target, declaration, type, decorator);
this.applyDecoratorForMapElement('VALUE', target, declaration, type, decorator);
break;
}
} else if (target.type) {
if (this.falsyOrEqual(target.type, declaration.key.$class)) {
this.applyDecorator(declaration.key, type, decorator);
}
if (this.falsyOrEqual(target.type, declaration.value.$class)) {
this.applyDecorator(declaration.value, type, decorator);
}
}
} else if (!target.property && !target.type) {
this.applyDecorator(declaration, type, decorator);
} else {
// scalars are declarations but do not have properties
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"$class" : "[email protected]",
"name" : "web",
"version": "1.0.0",
"commands" : [
{
"$class" : "[email protected]",
jonathan-casey marked this conversation as resolved.
Show resolved Hide resolved
"type" : "APPEND",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"type" : "[email protected]",
"declaration" : "Dictionary",
"mapElement": "KEY"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "TEST",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"type" : "[email protected]",
"mapElement": "KEY"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Foo",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"mapElement": "KEY"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Qux",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"type" : "[email protected]",
"mapElement": "VALUE"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Bar",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"mapElement": "VALUE"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Quux",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"mapElement": "KEY_VALUE"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Baz",
"arguments" : []
}
},

{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"type" : "[email protected]",
"mapElement": "KEY_VALUE"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Bazola",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"type" : "[email protected]",
"mapElement": "KEY_VALUE"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Bongo",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"type" : "[email protected]"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "DecoratesKeyByType",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"declaration" : "Dictionary",
"type" : "[email protected]"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "DecoratesValueByType",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"type" : "[email protected]"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "DecoratesAllMapKeys",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "[email protected]",
"type" : "[email protected]"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "DecoratesAllMapValues",
"arguments" : []
}
}
]
}
11 changes: 11 additions & 0 deletions packages/concerto-core/test/data/decoratorcommands/test.cto
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ concept Person {
o String address1
o String address2
o Integer zip
o Dictionary dictionary
}

map Dictionary {
o String
o String
}

map Rolodex {
o String
o String
}
Loading
Loading