UNPKG

2.29 kBJavaScriptView Raw
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15'use strict';
16
17const ClassDeclaration = require('./classdeclaration');
18
19/** Class representing the definition of an Transaction.
20 * @extends ClassDeclaration
21 * @see See {@link ClassDeclaration}
22 *
23 * @class
24 * @memberof module:concerto-core
25 */
26class TransactionDeclaration extends ClassDeclaration {
27 /**
28 * Create an TransactionDeclaration.
29 * @param {ModelFile} modelFile the ModelFile for this class
30 * @param {Object} ast - The AST created by the parser
31 * @throws {IllegalModelException}
32 */
33 constructor(modelFile, ast) {
34 super(modelFile, ast);
35 this._isTransactionDeclaration = true;
36 }
37
38 /**
39 * Process the AST and build the model
40 *
41 * @throws {IllegalModelException}
42 * @private
43 */
44 process() {
45 super.process();
46 this.addTimestampField();
47 }
48
49 /**
50 * Returns the base system type for Transactions from the system namespace
51 *
52 * @return {string} the short name of the base system type
53 */
54 getSystemType() {
55 let systemType = this.modelFile.getModelManager().getSystemModelTable().get('Transaction');
56 return systemType !== undefined ? systemType : null;
57 }
58
59 /**
60 * Alternative instanceof that is reliable across different module instances
61 * @see https://github.com/hyperledger/composer-concerto/issues/47
62 *
63 * @param {object} object - The object to test against
64 * @returns {boolean} - True, if the object is an instance of a TransactionDeclaration
65 */
66 static [Symbol.hasInstance](object){
67 return typeof object !== 'undefined' && object !== null && Boolean(object._isTransactionDeclaration);
68 }
69}
70
71module.exports = TransactionDeclaration;