Skip to content

Commit c751564

Browse files
committed
fix(core) Remove option on factory API
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 9aec680 commit c751564

File tree

4 files changed

+12
-37
lines changed

4 files changed

+12
-37
lines changed

packages/concerto-core/api.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Concerto {
2626
}
2727
class Factory {
2828
+ void constructor(ModelManager)
29-
+ Resource newResource(String,String,String,Object,boolean,String,boolean,boolean) throws TypeNotFoundException
29+
+ Resource newResource(String,String,String,Object,boolean,String,boolean) throws TypeNotFoundException
3030
+ Resource newConcept(String,String,String,Object,boolean,String,boolean) throws TypeNotFoundException
3131
+ Relationship newRelationship(String,String,String) throws TypeNotFoundException
32-
+ Resource newTransaction(String,String,String,Object,String,boolean,boolean)
33-
+ Resource newEvent(String,String,String,Object,String,boolean,boolean)
32+
+ Resource newTransaction(String,String,String,Object,String,boolean)
33+
+ Resource newEvent(String,String,String,Object,String,boolean)
3434
+ boolean hasInstance(object)
3535
}
3636
class AssetDeclaration extends IdentifiedDeclaration {

packages/concerto-core/changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
# Note that the latest public API is documented using JSDocs and is available in api.txt.
2525
#
2626

27-
Version 1.0.0-alpha.5 {05c2a5a3d15e05dd1e4430d0e655c9dd} 2021-04-08
27+
Version 1.0.0-alpha.5 {446997953e3ac90783ff9d492a8e7fdc} 2021-04-08
2828
- Support Concerto version pragma at the beginning of model files
29+
- Remove allowEmptyId option in factory API
2930

3031
Version 1.0.0-alpha.4 {3b7ebc06a536a5e81624225c7b0079ee} 2021-04-08
3132
- Allow optional UTC offset for validating DateTime values

packages/concerto-core/lib/factory.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class Factory {
6969
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
7070
* @param {boolean} [options.includeOptionalFields] - if <code>options.generate</code>
7171
* is specified, whether optional fields should be generated.
72-
* @param {boolean} [options.allowEmptyId] - if <code>options.allowEmptyId</code>
73-
* is specified as true, a zero length string for id is allowed (allows it to be filled in later).
7472
* @return {Resource} the new instance
7573
* @throws {TypeNotFoundException} if the type is not registered with the ModelManager
7674
*/
@@ -102,14 +100,12 @@ class Factory {
102100
}));
103101
}
104102

105-
if(!(options.allowEmptyId && id==='')) {
106-
if(id.trim().length === 0) {
107-
let formatter = Globalize.messageFormatter('factory-newinstance-missingidentifier');
108-
throw new Error(formatter({
109-
namespace: ns,
110-
type: type
111-
}));
112-
}
103+
if(id.trim().length === 0) {
104+
let formatter = Globalize.messageFormatter('factory-newinstance-missingidentifier');
105+
throw new Error(formatter({
106+
namespace: ns,
107+
type: type
108+
}));
113109
}
114110
} else if(id) {
115111
throw new Error('Type is not identifiable ' + classDecl.getFullyQualifiedName());
@@ -192,8 +188,6 @@ class Factory {
192188
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
193189
* @param {boolean} [options.includeOptionalFields] - if <code>options.generate</code>
194190
* is specified, whether optional fields should be generated.
195-
* @param {boolean} [options.allowEmptyId] - if <code>options.allowEmptyId</code>
196-
* is specified as true, a zero length string for id is allowed (allows it to be filled in later).
197191
* @return {Resource} A resource for the new transaction.
198192
*/
199193
newTransaction(ns, type, id, options) {
@@ -224,8 +218,6 @@ class Factory {
224218
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
225219
* @param {boolean} [options.includeOptionalFields] - if <code>options.generate</code>
226220
* is specified, whether optional fields should be generated.
227-
* @param {boolean} [options.allowEmptyId] - if <code>options.allowEmptyId</code>
228-
* is specified as true, a zero length string for id is allowed (allows it to be filled in later).
229221
* @return {Resource} A resource for the new event.
230222
*/
231223
newEvent(ns, type, id, options) {

packages/concerto-core/test/factory.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ describe('Factory', function() {
7373

7474
describe('#newResource', function() {
7575

76-
it('should not throw creating a new instance with a zero length string as the ID if the option to allowEmptyId is set to boolean true', function() {
77-
const resource = factory.newResource(namespace, assetName, '', {allowEmptyId: true});
78-
resource.assetId.should.equal('');
79-
});
80-
81-
it('should throw creating a new instance with a non-zero length string as the ID if the option to allowEmptyId is not set to boolean true', function() {
76+
it('should throw creating a new instance with a non-zero length string as the ID', function() {
8277
(() => {
8378
factory.newResource(namespace, assetName, ' ', {});
8479
}).should.throw(/Missing identifier/);
@@ -96,19 +91,6 @@ describe('Factory', function() {
9691
}).should.throw(/Missing identifier/);
9792
});
9893

99-
it('should throw creating a new instance with an ID that is just whitespace if the option to allowEmptyId is not set to boolean true', function() {
100-
(() => {
101-
factory.newResource(namespace, assetName, ' ', {allowEmptyId: 'true'});
102-
}).should.throw(/Missing identifier/);
103-
});
104-
105-
it('should throw creating a new instance with an ID that is just whitespace if the option to allowEmptyId is set to boolean true', function() {
106-
(() => {
107-
factory.newResource(namespace, assetName, ' ', {allowEmptyId: true});
108-
}).should.throw(/Missing identifier/);
109-
});
110-
111-
11294
it('should throw creating an abstract asset', function() {
11395
(() => {
11496
factory.newResource(namespace, 'AbstractAsset', 'MY_ID_1');

0 commit comments

Comments
 (0)