Skip to content

Commit

Permalink
Merge branch 'main' into jonathan/use_modelfile_get_type
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-casey committed Nov 7, 2023
2 parents bbf51ac + b4140f6 commit 6ce4b73
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 60 deletions.
126 changes: 70 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/concerto-core/lib/decoratormanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class DecoratorManager {
this.applyDecorator(declaration.value, type, decorator);
}
}
} else if (!target.property && !target.type) {
} else if (!(target.property || target.properties || target.type)) {
this.applyDecorator(declaration, type, decorator);
} else {
// scalars are declarations but do not have properties
Expand Down
1 change: 1 addition & 0 deletions packages/concerto-core/lib/introspect/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Field extends Property {

fieldAst.name = this.ast.name;
this.scalarField = new Field(this.getParent(), fieldAst);
this.scalarField.array = this.isArray();
return this.scalarField;
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/concerto-core/test/data/decoratorcommands/test.cto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ concept Person {
o SSN ssn
o String address1
o String address2
o String city
o String country
o Integer zip
o Dictionary dictionary
}
Expand Down
48 changes: 47 additions & 1 deletion packages/concerto-core/test/data/decoratorcommands/web.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,37 @@
]
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "test",
"declaration" : "Person",
"property" : "address1"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Address",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "test",
"declaration" : "Person",
"property" : "country",
"type" : "[email protected]"
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Address",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
Expand All @@ -100,7 +131,22 @@
"namespace" : "test",
"declaration" : "Person",
"type" : "[email protected]",
"properties" : ["address1", "address2", "zip"]
"properties" : ["address2", "zip"]
},
"decorator" : {
"$class" : "[email protected]",
"name" : "Address",
"arguments" : []
}
},
{
"$class" : "[email protected]",
"type" : "UPSERT",
"target" : {
"$class" : "[email protected]",
"namespace" : "test",
"declaration" : "Person",
"properties" : ["city"]
},
"decorator" : {
"$class" : "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

namespace com.testing

scalar SSN extends String default="000-00-0000" regex=/\d{3}-\d{2}-\{4}+/

concept Persons {
o SSN[] ssnArray
}
16 changes: 14 additions & 2 deletions packages/concerto-core/test/decoratormanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,19 @@ describe('DecoratorManager', () => {
const decoratorUnversionedNamespace = bioProperty.getDecorator('UnversionedNamespace');
decoratorUnversionedNamespace.should.not.be.null;

// applied using properties
// applied using property, no type
const address1Property = decl.getProperty('address1');
address1Property.should.not.be.null;
const decoratorAddress1Property = address1Property.getDecorator('Address');
decoratorAddress1Property.should.not.be.null;

// applied using properties
// applied using property, string type
const countryProperty = decl.getProperty('country');
countryProperty.should.not.be.null;
const decoratorCountryProperty = countryProperty.getDecorator('Address');
decoratorCountryProperty.should.not.be.null;

// applied using properties, string types only
const address2Property = decl.getProperty('address2');
address2Property.should.not.be.null;
const decoratorAddress2Property = address2Property.getDecorator('Address');
Expand All @@ -174,6 +180,12 @@ describe('DecoratorManager', () => {
zipProperty.should.not.be.null;
const decoratorZipProperty = zipProperty.getDecorator('Address');
(decoratorZipProperty ===null).should.be.true;

// applied using properties, no type
const cityProperty = decl.getProperty('city');
cityProperty.should.not.be.null;
const decoratorCity2Property = cityProperty.getDecorator('Address');
decoratorCity2Property.should.not.be.null;
});

it('should decorate the specified element on the specified Map Declaration (Map Key)', async function() {
Expand Down
Loading

0 comments on commit 6ce4b73

Please sign in to comment.