socket/ClientServerTransaction.js

/**
 * @module flitter-socket/ClientServerTransaction
 */

const Transaction = require('./Transaction')

/**
 * Specific type of transaction where a request from the
 * client comes in to the server.
 * @extends module:flitter-socket/Transaction~Transaction
 */
class ClientServerTransaction extends Transaction {

    /**
     * Initialize the transaction from the message data.
     * @param data
     * @param cm
     */
    constructor(data, cm){
        data.incoming = data.data
        super(data, cm)

        /**
         * The socket handler's requested endpoing.
         * @type {string}
         */
        this.endpoint = data.endpoint
    }

    /**
     * Set values in the outgoing data.
     * @param key
     * @param value
     * @returns {ClientServerTransaction} - for chaining
     */
    set(key, value = null){
        if ( value && typeof this.outgoing === 'object' ) this.outgoing[key] = value
        else this.outgoing = key
        
        return this
    }
    
}

module.exports = exports = ClientServerTransaction