All files / lib/wrapper transform.js

100% Statements 15/15
75% Branches 6/8
100% Functions 2/2
100% Lines 14/14

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 289x 9x 9x               19x 19x 19x 19x 19x   44x 6x   44x   19x 19x         9x
const {Transform} = require('stream');
const {DataWrapper} = require('./data_wrapper.js');
const {Manager} = require('../manager/manager.js');
 
/**
 * Wrapper for _Transform_ streams that knows what to do with {@link DataWrapper} messages.
 * @extends Transform
 */
class TransformWrapper extends Transform {
    constructor(options) {
        options = {...options, readableObjectMode: true, writableObjectMode: true};
        super(options);
        this.options = options;
        this.__real__push = this.push;
        this.push = (payload, encoding) => {
            // console.log(payload);
            if(payload != null && this.goal) {
                payload = payload instanceof DataWrapper?payload.getChild(this):new DataWrapper(payload, this);
            }
            this.__real__push(payload, encoding);
        };
        this.type = 'Transform';
        Eif(this.options.name) Manager.set(this.type, this);
    }
 
}
 
module.exports.TransformWrapper = TransformWrapper;