function isMessage(val) {
    if (utils_1.isObject(val)) {
        // all messages must have the `type` prop
        if (!utils_1.hasOwnStringProperty(val, 'type')) {
            return false;
        }
        // validate other properties depending on the `type`
        switch (val.type) {
            case MessageType.ConnectionInit:
                // the connection init message can have optional payload object
                return (!utils_1.hasOwnProperty(val, 'payload') ||
                    val.payload === undefined ||
                    utils_1.isObject(val.payload));
            case MessageType.ConnectionAck:
                // the connection ack message can have optional payload object too
                return (!utils_1.hasOwnProperty(val, 'payload') ||
                    val.payload === undefined ||
                    utils_1.isObject(val.payload));
            case MessageType.Subscribe:
                return (utils_1.hasOwnStringProperty(val, 'id') &&
                    utils_1.hasOwnObjectProperty(val, 'payload') &&
                    (!utils_1.hasOwnProperty(val.payload, 'operationName') ||
                        val.payload.operationName === undefined ||
                        val.payload.operationName === null ||
                        typeof val.payload.operationName === 'string') &&
                    utils_1.hasOwnStringProperty(val.payload, 'query') &&
                    (!utils_1.hasOwnProperty(val.payload, 'variables') ||
                        val.payload.variables === undefined ||
                        val.payload.variables === null ||
                        utils_1.hasOwnObjectProperty(val.payload, 'variables')) &&
                    (!utils_1.hasOwnProperty(val.payload, 'extensions') ||
                        val.payload.extensions === undefined ||
                        val.payload.extensions === null ||
                        utils_1.hasOwnObjectProperty(val.payload, 'extensions')));
            case MessageType.Next:
                return (utils_1.hasOwnStringProperty(val, 'id') &&
                    utils_1.hasOwnObjectProperty(val, 'payload'));
            case MessageType.Error:
                return utils_1.hasOwnStringProperty(val, 'id') && utils_1.areGraphQLErrors(val.payload);
            case MessageType.Complete:
                return utils_1.hasOwnStringProperty(val, 'id');
            default:
                return false;
        }
    }
    return false;
}
/**
 * Checks if the provided value is a message.
 *
 * @category Common
 */
Checks if the provided value is a message.
@category Common
Checks if the provided value is a message . @category Common
function isMessage(val) {
    if (utils_1.isObject(val)) {
        if (!utils_1.hasOwnStringProperty(val, 'type')) {
            return false;
        }
        switch (val.type) {
            case MessageType.ConnectionInit:
                return (!utils_1.hasOwnProperty(val, 'payload') ||
                    val.payload === undefined ||
                    utils_1.isObject(val.payload));
            case MessageType.ConnectionAck:
                return (!utils_1.hasOwnProperty(val, 'payload') ||
                    val.payload === undefined ||
                    utils_1.isObject(val.payload));
            case MessageType.Subscribe:
                return (utils_1.hasOwnStringProperty(val, 'id') &&
                    utils_1.hasOwnObjectProperty(val, 'payload') &&
                    (!utils_1.hasOwnProperty(val.payload, 'operationName') ||
                        val.payload.operationName === undefined ||
                        val.payload.operationName === null ||
                        typeof val.payload.operationName === 'string') &&
                    utils_1.hasOwnStringProperty(val.payload, 'query') &&
                    (!utils_1.hasOwnProperty(val.payload, 'variables') ||
                        val.payload.variables === undefined ||
                        val.payload.variables === null ||
                        utils_1.hasOwnObjectProperty(val.payload, 'variables')) &&
                    (!utils_1.hasOwnProperty(val.payload, 'extensions') ||
                        val.payload.extensions === undefined ||
                        val.payload.extensions === null ||
                        utils_1.hasOwnObjectProperty(val.payload, 'extensions')));
            case MessageType.Next:
                return (utils_1.hasOwnStringProperty(val, 'id') &&
                    utils_1.hasOwnObjectProperty(val, 'payload'));
            case MessageType.Error:
                return utils_1.hasOwnStringProperty(val, 'id') && utils_1.areGraphQLErrors(val.payload);
            case MessageType.Complete:
                return utils_1.hasOwnStringProperty(val, 'id');
            default:
                return false;
        }
    }
    return false;
}
function isMessage ( val ) { if ( utils_1 . isObject ( val ) ) { if ( ! utils_1 . hasOwnStringProperty ( val , 'type' ) ) { return false ; } switch ( val . type ) { case MessageType . ConnectionInit : return ( ! utils_1 . hasOwnProperty ( val , 'payload' ) || val . payload === undefined || utils_1 . isObject ( val . payload ) ) ; case MessageType . ConnectionAck : return ( ! utils_1 . hasOwnProperty ( val , 'payload' ) || val . payload === undefined || utils_1 . isObject ( val . payload ) ) ; case MessageType . Subscribe : return ( utils_1 . hasOwnStringProperty ( val , 'id' ) && utils_1 . hasOwnObjectProperty ( val , 'payload' ) && ( ! utils_1 . hasOwnProperty ( val . payload , 'operationName' ) || val . payload . operationName === undefined || val . payload . operationName === null || typeof val . payload . operationName === 'string' ) && utils_1 . hasOwnStringProperty ( val . payload , 'query' ) && ( ! utils_1 . hasOwnProperty ( val . payload , 'variables' ) || val . payload . variables === undefined || val . payload . variables === null || utils_1 . hasOwnObjectProperty ( val . payload , 'variables' ) ) && ( ! utils_1 . hasOwnProperty ( val . payload , 'extensions' ) || val . payload . extensions === undefined || val . payload . extensions === null || utils_1 . hasOwnObjectProperty ( val . payload , 'extensions' ) ) ) ; case MessageType . Next : return ( utils_1 . hasOwnStringProperty ( val , 'id' ) && utils_1 . hasOwnObjectProperty ( val , 'payload' ) ) ; case MessageType . Error : return utils_1 . hasOwnStringProperty ( val , 'id' ) && utils_1 . areGraphQLErrors ( val . payload ) ; case MessageType . Complete : return utils_1 . hasOwnStringProperty ( val , 'id' ) ; default : return false ; } } return false ; }
Checks if the provided value is a message.
Checks if the provided value is a message .
// all messages must have the `type` prop // validate other properties depending on the `type` // the connection init message can have optional payload object // the connection ack message can have optional payload object too