Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit a828b05

Browse files
nklincolnmbwhite
authored andcommitted
make readonly flag parameterless (#4587)
Signed-off-by: nkl199@yahoo.co.uk <nkl199@yahoo.co.uk>
1 parent 5adbb35 commit a828b05

File tree

8 files changed

+40
-62
lines changed

8 files changed

+40
-62
lines changed

packages/composer-common/api.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ class ModelManager {
260260
}
261261
class ReadOnlyDecorator extends Decorator {
262262
+ void constructor(Object) throws IllegalModelException
263-
+ boolean getValue()
264263
}
265264
class ReadOnlyDecoratorFactory extends DecoratorFactory {
266265
+ Decorator newDecorator(Object)

packages/composer-common/changelog.txt

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

27+
Version 0.19.20 {308d962120667e982b2600107d0b8b13} 2019-01-29
28+
- Modify readonly decorator to be parameterless
29+
2730
Version 0.19.20 {5ff216eab17b2d990c43636c51a585b5} 2018-12-18
2831
- Add readonly decorator factory
2932

packages/composer-common/lib/readonlydecorator.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,9 @@ class ReadOnlyDecorator extends Decorator {
4040
process() {
4141
super.process();
4242
const args = this.getArguments();
43-
if (args.length !== 1) {
44-
throw new IllegalModelException(`@readonly decorator expects 1 argument, but ${args.length} arguments were specified.`, this.parent.getModelFile(), this.ast.location);
43+
if (args.length !== 0) {
44+
throw new IllegalModelException(`@readonly decorator expects 0 arguments, but ${args.length} arguments were specified.`, this.parent.getModelFile(), this.ast.location);
4545
}
46-
const arg = args[0];
47-
if (typeof arg !== 'boolean') {
48-
throw new IllegalModelException(`@readonly decorator expects a boolean argument, but an argument of type ${typeof arg} was specified.`, this.parent.getModelFile(), this.ast.location);
49-
}
50-
this.value = arg;
51-
}
52-
53-
/**
54-
* Get the value of this commit decorator.
55-
* @return {boolean} The value of this commit decorator.
56-
*/
57-
getValue() {
58-
return this.value;
5946
}
6047

6148
}

packages/composer-common/test/businessnetworkdefinition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ describe('BusinessNetworkDefinition', () => {
522522
const modelManager = bnd.getModelManager();
523523
modelManager.addModelFile(`
524524
namespace org.acme
525-
@readonly(true)
525+
@readonly
526526
transaction T{ }`);
527527
const transactionDeclaration = modelManager.getType('org.acme.T');
528528
const decorator = transactionDeclaration.getDecorator('readonly');

packages/composer-common/test/readonlydecorator.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ModelManager = require('../lib/modelmanager');
2020

2121
require('chai').should();
2222

23-
describe('RaedOnlyDecorator', () => {
23+
describe('ReadOnlyDecorator', () => {
2424

2525
let modelManager;
2626
let transactionDeclaration;
@@ -37,38 +37,12 @@ describe('RaedOnlyDecorator', () => {
3737

3838
describe('#process', () => {
3939

40-
it('should throw if no arguments are specified', () => {
41-
(() => {
42-
new ReadOnlyDecorator(transactionDeclaration, { location: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 22, line: 1, column: 23 } }, name: 'readonly', arguments: { list: [] } });
43-
}).should.throw(/@readonly decorator expects 1 argument, but 0 arguments were specified. Line 1 column 1, to line 1 column 23./);
44-
});
45-
46-
it('should throw if two arguments are specified', () => {
40+
it('should throw if arguments are specified', () => {
4741
(() => {
4842
new ReadOnlyDecorator(transactionDeclaration, { location: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 22, line: 1, column: 23 } }, name: 'readonly', arguments: { list: [ { value: true }, { value: false } ] } });
49-
}).should.throw(/@readonly decorator expects 1 argument, but 2 arguments were specified. Line 1 column 1, to line 1 column 23./);
43+
}).should.throw(/@readonly decorator expects 0 arguments, but 2 arguments were specified. Line 1 column 1, to line 1 column 23./);
5044
});
51-
52-
it('should throw if a an incorrectly typed argument is specified', () => {
53-
(() => {
54-
new ReadOnlyDecorator(transactionDeclaration, { location: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 22, line: 1, column: 23 } }, name: 'readonly', arguments: { list: [ { value: 'hello world' } ] } });
55-
}).should.throw(/@readonly decorator expects a boolean argument, but an argument of type string was specified. Line 1 column 1, to line 1 column 23./);
56-
});
57-
5845
});
5946

60-
describe('#getValue', () => {
61-
62-
it('should return true if the argument is true', () => {
63-
const decorator = new ReadOnlyDecorator(transactionDeclaration, { location: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 22, line: 1, column: 23 } }, name: 'readonly', arguments: { list: [ { value: true } ] } });
64-
decorator.getValue().should.be.true;
65-
});
66-
67-
it('should return false if the argument is false', () => {
68-
const decorator = new ReadOnlyDecorator(transactionDeclaration, { location: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 22, line: 1, column: 23 } }, name: 'readonly', arguments: { list: [ { value: false } ] } });
69-
decorator.getValue().should.be.false;
70-
});
71-
72-
});
7347

7448
});

packages/composer-common/test/readonlydecoratorfactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('ReadOnlyDecoratorDecoratorFactory', () => {
4343
});
4444

4545
it('should return a readonly decorator instance for a @readonly decorator', () => {
46-
const decorator = factory.newDecorator(transactionDeclaration, { name: 'readonly', arguments: { list: [ { value: false } ] } });
46+
const decorator = factory.newDecorator(transactionDeclaration, { name: 'readonly' });
4747
decorator.should.be.an.instanceOf(ReadOnlyDecorator);
4848
});
4949

packages/composer-runtime/lib/engine.transactions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ class EngineTransactions {
286286
// Get the type and resolved type.
287287
const transactionDeclaration = transaction.getClassDeclaration();
288288
const returnsDecorator = transactionDeclaration.getDecorator('returns');
289-
const readOnlyDecorator = transactionDeclaration.getDecorator('readonly');
290-
const readOnly = readOnlyDecorator ? readOnlyDecorator.getValue() : false;
289+
const readOnly = transactionDeclaration.getDecorator('readonly') ? true : false;
291290
const returnValueType = returnsDecorator.getType();
292291
const returnValueResolvedType = returnsDecorator.getResolvedType();
293292
const isArray = returnsDecorator.isArray();

packages/composer-runtime/test/engine.transactions.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ describe('EngineTransactions', () => {
8585
8686
}
8787
@returns(MyAsset)
88-
@readonly(true)
88+
@readonly
8989
transaction MyTransactionThatReturnsAsset {
9090
o String value
9191
}
9292
@returns(MyAsset[])
93-
@readonly(false)
93+
@readonly
9494
transaction MyTransactionThatReturnsAssetArray {
9595
o String value
9696
}
@@ -342,6 +342,17 @@ describe('EngineTransactions', () => {
342342
})]).should.be.rejectedWith(/such error/);
343343
});
344344

345+
it('should correctly identify a readonly decorator', () => {
346+
let transaction = factory.newTransaction('org.acme', 'MyTransactionThatReturnsConcept');
347+
let result = transaction.getClassDeclaration().getDecorator('readonly');
348+
should.not.exist(result);
349+
350+
transaction = factory.newTransaction('org.acme', 'MyTransactionThatReturnsAsset');
351+
result = transaction.getClassDeclaration().getDecorator('readonly');
352+
should.exist(result);
353+
result.name.should.equal('readonly');
354+
});
355+
345356
});
346357

347358
describe('#_executeTransaction', () => {
@@ -668,29 +679,34 @@ describe('EngineTransactions', () => {
668679
}]);
669680
});
670681

671-
it('should handle a readonly(true) Asset return value', () => {
682+
it('should handle a concept return value that is not readonly but contains a $original component', () => {
683+
const transaction = factory.newTransaction('org.acme', 'MyTransactionThatReturnsConcept');
684+
const concept = factory.newConcept('org.acme', 'MyConcept');
685+
concept.value = 'hello world';
686+
concept.$original = 'not to be seen';
687+
engine._processComplexReturnValue(mockContext, transaction, concept).should.deep.equal({
688+
$class: 'org.acme.MyConcept',
689+
value: 'hello world'
690+
});
691+
});
692+
693+
it('should handle a readonly Asset return value', () => {
672694
const transaction = factory.newTransaction('org.acme', 'MyTransactionThatReturnsAsset');
673695
const asset = factory.newResource('org.acme', 'MyAsset','001');
674696
asset.value = 'hello world';
675697
asset.$original = 'penguin';
676698
engine._processComplexReturnValue(mockContext, transaction, asset).should.equal('penguin');
677699
});
678700

679-
it('should handle a readonly(false) Asset[] return value', () => {
701+
it('should handle a readonly Asset[] return value', () => {
680702
const transaction = factory.newTransaction('org.acme', 'MyTransactionThatReturnsAssetArray');
681703
const asset1 = factory.newResource('org.acme', 'MyAsset','001');
682704
asset1.value = 'hello world';
705+
asset1.$original = 'penguin';
683706
const asset2 = factory.newResource('org.acme', 'MyAsset','002');
684707
asset2.value = 'hello again world';
685-
engine._processComplexReturnValue(mockContext, transaction, [asset1, asset2]).should.deep.equal([{
686-
$class: 'org.acme.MyAsset',
687-
assetId: '001',
688-
value: 'hello world'
689-
}, {
690-
$class: 'org.acme.MyAsset',
691-
assetId: '002',
692-
value: 'hello again world'
693-
}]);
708+
asset2.$original = 'power';
709+
engine._processComplexReturnValue(mockContext, transaction, [asset1, asset2]).should.deep.equal(['penguin', 'power']);
694710
});
695711

696712
it('should throw for an invalid (wrong type) concept return value', () => {

0 commit comments

Comments
 (0)