All files / fabric-contract-api/lib/annotations info.js

100% Statements 16/16
100% Branches 7/7
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35            2x 2x 2x   2x 4x 4x   4x   4x   4x 2x   4x 2x     4x 4x   4x   4x        
/*
 * Copyright IBM Corp. All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
 
const Logger = require('../logger');
const logger = Logger.getLogger('./lib/annotations/info.js');
require('reflect-metadata');
 
module.exports.Info = function Info (info = {}) {
    return (target) => {
        logger.info('@Info args:', `Info -> ${info},`, 'Target ->', target.name);
 
        const data = Reflect.getMetadata('fabric:info', global) || {};
 
        logger.debug('Existing fabric:info', data);
 
        if (!info.name) {
            info.name = target.name;
        }
        if (!info.version) {
            info.version = '';
        }
 
        data[target.name] = {};
        Object.assign(data[target.name], info);
 
        Reflect.defineMetadata('fabric:info', data, global);
 
        logger.debug('Updated fabric:info', data);
    };
};