"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../../../constants");
exports.MESSAGE_SEPERATOR = String.fromCharCode(30); // ASCII Record Seperator 1E
exports.MESSAGE_PART_SEPERATOR = String.fromCharCode(31); // ASCII Unit Separator 1F
exports.PAYLOAD_ENCODING = {
    JSON: 0x00,
    DEEPSTREAM: 0x01,
};
exports.TOPIC = {
    PARSER: { TEXT: 'X', BYTE: constants_1.TOPIC.PARSER },
    CONNECTION: { TEXT: 'C', BYTE: constants_1.TOPIC.CONNECTION },
    AUTH: { TEXT: 'A', BYTE: constants_1.TOPIC.AUTH },
    ERROR: { TEXT: 'X', BYTE: constants_1.TOPIC.ERROR },
    EVENT: { TEXT: 'E', BYTE: constants_1.TOPIC.EVENT },
    RECORD: { TEXT: 'R', BYTE: constants_1.TOPIC.RECORD },
    RPC: { TEXT: 'P', BYTE: constants_1.TOPIC.RPC },
    PRESENCE: { TEXT: 'U', BYTE: constants_1.TOPIC.PRESENCE },
};
exports.PARSER_ACTIONS = {
    UNKNOWN_TOPIC: { BYTE: constants_1.PARSER_ACTION.UNKNOWN_TOPIC },
    UNKNOWN_ACTION: { BYTE: constants_1.PARSER_ACTION.UNKNOWN_ACTION },
    INVALID_MESSAGE: { BYTE: constants_1.PARSER_ACTION.INVALID_MESSAGE },
    INVALID_META_PARAMS: { BYTE: constants_1.PARSER_ACTION.INVALID_META_PARAMS },
    MESSAGE_PARSE_ERROR: { BYTE: constants_1.PARSER_ACTION.MESSAGE_PARSE_ERROR },
    MAXIMUM_MESSAGE_SIZE_EXCEEDED: { BYTE: constants_1.PARSER_ACTION.MAXIMUM_MESSAGE_SIZE_EXCEEDED },
    ERROR: { BYTE: constants_1.PARSER_ACTION.ERROR },
};
exports.CONNECTION_ACTIONS = {
    ERROR: { TEXT: 'E', BYTE: constants_1.CONNECTION_ACTION.ERROR },
    PING: { TEXT: 'PI', BYTE: constants_1.CONNECTION_ACTION.PING },
    PONG: { TEXT: 'PO', BYTE: constants_1.CONNECTION_ACTION.PONG },
    ACCEPT: { TEXT: 'A', BYTE: constants_1.CONNECTION_ACTION.ACCEPT },
    CHALLENGE: { TEXT: 'CH', BYTE: constants_1.CONNECTION_ACTION.CHALLENGE },
    REJECTION: { TEXT: 'REJ', BYTE: constants_1.CONNECTION_ACTION.REJECT },
    REDIRECT: { TEXT: 'RED', BYTE: constants_1.CONNECTION_ACTION.REDIRECT },
    CLOSED: { BYTE: constants_1.CONNECTION_ACTION.CLOSED },
    CLOSING: { BYTE: constants_1.CONNECTION_ACTION.CLOSING },
    CONNECTION_AUTHENTICATION_TIMEOUT: { BYTE: constants_1.CONNECTION_ACTION.AUTHENTICATION_TIMEOUT },
    INVALID_MESSAGE: { BYTE: constants_1.CONNECTION_ACTION.INVALID_MESSAGE },
};
exports.AUTH_ACTIONS = {
    ERROR: { TEXT: 'E', BYTE: constants_1.AUTH_ACTION.ERROR },
    REQUEST: { TEXT: 'REQ', BYTE: constants_1.AUTH_ACTION.REQUEST },
    AUTH_SUCCESSFUL: { BYTE: constants_1.AUTH_ACTION.AUTH_SUCCESSFUL, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    AUTH_UNSUCCESSFUL: { BYTE: constants_1.AUTH_ACTION.AUTH_UNSUCCESSFUL, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    TOO_MANY_AUTH_ATTEMPTS: { BYTE: constants_1.AUTH_ACTION.TOO_MANY_AUTH_ATTEMPTS },
    // MESSAGE_PERMISSION_ERROR: { BYTE: AA.MESSAGE_PERMISSION_ERROR },
    // MESSAGE_DENIED: { BYTE: AA.MESSAGE_DENIED },
    INVALID_MESSAGE_DATA: { BYTE: constants_1.AUTH_ACTION.INVALID_MESSAGE_DATA },
    INVALID_MESSAGE: { BYTE: constants_1.AUTH_ACTION.INVALID_MESSAGE },
};
exports.EVENT_ACTIONS = {
    ERROR: { TEXT: 'E', BYTE: constants_1.EVENT_ACTION.ERROR },
    EMIT: { TEXT: 'EVT', BYTE: constants_1.EVENT_ACTION.EMIT, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    SUBSCRIBE: { TEXT: 'S', BYTE: constants_1.EVENT_ACTION.SUBSCRIBE },
    UNSUBSCRIBE: { TEXT: 'US', BYTE: constants_1.EVENT_ACTION.UNSUBSCRIBE },
    LISTEN: { TEXT: 'L', BYTE: constants_1.EVENT_ACTION.LISTEN },
    UNLISTEN: { TEXT: 'UL', BYTE: constants_1.EVENT_ACTION.UNLISTEN },
    LISTEN_ACCEPT: { TEXT: 'LA', BYTE: constants_1.EVENT_ACTION.LISTEN_ACCEPT },
    LISTEN_REJECT: { TEXT: 'LR', BYTE: constants_1.EVENT_ACTION.LISTEN_REJECT },
    SUBSCRIPTION_FOR_PATTERN_FOUND: { TEXT: 'SP', BYTE: constants_1.EVENT_ACTION.SUBSCRIPTION_FOR_PATTERN_FOUND },
    SUBSCRIPTION_FOR_PATTERN_REMOVED: { TEXT: 'SR', BYTE: constants_1.EVENT_ACTION.SUBSCRIPTION_FOR_PATTERN_REMOVED },
    MESSAGE_PERMISSION_ERROR: { BYTE: constants_1.EVENT_ACTION.MESSAGE_PERMISSION_ERROR },
    MESSAGE_DENIED: { BYTE: constants_1.EVENT_ACTION.MESSAGE_DENIED },
    INVALID_MESSAGE_DATA: { BYTE: constants_1.EVENT_ACTION.INVALID_MESSAGE_DATA },
    MULTIPLE_SUBSCRIPTIONS: { BYTE: constants_1.EVENT_ACTION.MULTIPLE_SUBSCRIPTIONS },
    NOT_SUBSCRIBED: { BYTE: constants_1.EVENT_ACTION.NOT_SUBSCRIBED },
};
exports.RECORD_ACTIONS = {
    ERROR: { TEXT: 'E', BYTE: constants_1.RECORD_ACTION.ERROR },
    CREATE: { TEXT: 'CR', BYTE: constants_1.RECORD_ACTION.CREATE },
    READ: { TEXT: 'R', BYTE: constants_1.RECORD_ACTION.READ },
    READ_RESPONSE: { BYTE: constants_1.RECORD_ACTION.READ_RESPONSE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.JSON },
    HEAD: { TEXT: 'HD', BYTE: constants_1.RECORD_ACTION.HEAD },
    HEAD_RESPONSE: { BYTE: constants_1.RECORD_ACTION.HEAD_RESPONSE },
    CREATEANDUPDATE: { TEXT: 'CU', BYTE: constants_1.RECORD_ACTION.CREATEANDUPDATE },
    CREATEANDPATCH: { BYTE: constants_1.RECORD_ACTION.CREATEANDPATCH, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    UPDATE: { TEXT: 'U', BYTE: constants_1.RECORD_ACTION.UPDATE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.JSON },
    PATCH: { TEXT: 'P', BYTE: constants_1.RECORD_ACTION.PATCH, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    ERASE: { BYTE: constants_1.RECORD_ACTION.ERASE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    WRITE_ACKNOWLEDGEMENT: { TEXT: 'WA', BYTE: constants_1.RECORD_ACTION.WRITE_ACKNOWLEDGEMENT },
    DELETE: { TEXT: 'D', BYTE: constants_1.RECORD_ACTION.DELETE },
    DELETE_SUCCESS: { BYTE: constants_1.RECORD_ACTION.DELETE_SUCCESS },
    DELETED: { BYTE: constants_1.RECORD_ACTION.DELETED },
    LISTEN_RESPONSE_TIMEOUT: { BYTE: constants_1.RECORD_ACTION.LISTEN_RESPONSE_TIMEOUT },
    SUBSCRIBEANDHEAD: { BYTE: constants_1.RECORD_ACTION.SUBSCRIBEANDHEAD },
    // SUBSCRIBEANDHEAD_RESPONSE: { BYTE: RA.SUBSCRIBEANDHEAD_RESPONSE },
    SUBSCRIBEANDREAD: { BYTE: constants_1.RECORD_ACTION.SUBSCRIBEANDREAD },
    // SUBSCRIBEANDREAD_RESPONSE: { BYTE: RA.SUBSCRIBEANDREAD_RESPONSE },
    SUBSCRIBECREATEANDREAD: { TEXT: 'CR', BYTE: constants_1.RECORD_ACTION.SUBSCRIBECREATEANDREAD },
    // SUBSCRIBECREATEANDREAD_RESPONSE: { BYTE: RA.SUBSCRIBECREATEANDREAD_RESPONSE },
    SUBSCRIBECREATEANDUPDATE: { BYTE: constants_1.RECORD_ACTION.SUBSCRIBECREATEANDUPDATE },
    // SUBSCRIBECREATEANDUPDATE_RESPONSE: { BYTE: RA.SUBSCRIBECREATEANDUPDATE_RESPONSE },
    SUBSCRIBE: { TEXT: 'S', BYTE: constants_1.RECORD_ACTION.SUBSCRIBE },
    UNSUBSCRIBE: { TEXT: 'US', BYTE: constants_1.RECORD_ACTION.UNSUBSCRIBE },
    LISTEN: { TEXT: 'L', BYTE: constants_1.RECORD_ACTION.LISTEN },
    UNLISTEN: { TEXT: 'UL', BYTE: constants_1.RECORD_ACTION.UNLISTEN },
    LISTEN_ACCEPT: { TEXT: 'LA', BYTE: constants_1.RECORD_ACTION.LISTEN_ACCEPT },
    LISTEN_REJECT: { TEXT: 'LR', BYTE: constants_1.RECORD_ACTION.LISTEN_REJECT },
    SUBSCRIPTION_HAS_PROVIDER: { TEXT: 'SH', BYTE: constants_1.RECORD_ACTION.SUBSCRIPTION_HAS_PROVIDER },
    SUBSCRIPTION_HAS_NO_PROVIDER: { BYTE: constants_1.RECORD_ACTION.SUBSCRIPTION_HAS_NO_PROVIDER },
    SUBSCRIPTION_FOR_PATTERN_FOUND: { TEXT: 'SP', BYTE: constants_1.RECORD_ACTION.SUBSCRIPTION_FOR_PATTERN_FOUND },
    SUBSCRIPTION_FOR_PATTERN_REMOVED: { TEXT: 'SR', BYTE: constants_1.RECORD_ACTION.SUBSCRIPTION_FOR_PATTERN_REMOVED },
    CACHE_RETRIEVAL_TIMEOUT: { BYTE: constants_1.RECORD_ACTION.CACHE_RETRIEVAL_TIMEOUT },
    STORAGE_RETRIEVAL_TIMEOUT: { BYTE: constants_1.RECORD_ACTION.STORAGE_RETRIEVAL_TIMEOUT },
    VERSION_EXISTS: { BYTE: constants_1.RECORD_ACTION.VERSION_EXISTS },
    // HAS: { TEXT: 'H', BYTE: RA.HAS },
    // HAS_RESPONSE: { BYTE: RA.HAS_RESPONSE },
    SNAPSHOT: { TEXT: 'SN', BYTE: constants_1.RECORD_ACTION.READ },
    RECORD_LOAD_ERROR: { BYTE: constants_1.RECORD_ACTION.RECORD_LOAD_ERROR },
    RECORD_CREATE_ERROR: { BYTE: constants_1.RECORD_ACTION.RECORD_CREATE_ERROR },
    RECORD_UPDATE_ERROR: { BYTE: constants_1.RECORD_ACTION.RECORD_UPDATE_ERROR },
    RECORD_DELETE_ERROR: { BYTE: constants_1.RECORD_ACTION.RECORD_DELETE_ERROR },
    // RECORD_READ_ERROR: { BYTE: RA.RECORD_READ_ERROR },
    RECORD_NOT_FOUND: { BYTE: constants_1.RECORD_ACTION.RECORD_NOT_FOUND },
    INVALID_VERSION: { BYTE: constants_1.RECORD_ACTION.INVALID_VERSION },
    INVALID_PATCH_ON_HOTPATH: { BYTE: constants_1.RECORD_ACTION.INVALID_PATCH_ON_HOTPATH },
    MESSAGE_PERMISSION_ERROR: { BYTE: constants_1.RECORD_ACTION.MESSAGE_PERMISSION_ERROR },
    MESSAGE_DENIED: { BYTE: constants_1.RECORD_ACTION.MESSAGE_DENIED },
    INVALID_MESSAGE_DATA: { BYTE: constants_1.RECORD_ACTION.INVALID_MESSAGE_DATA },
    MULTIPLE_SUBSCRIPTIONS: { BYTE: constants_1.RECORD_ACTION.MULTIPLE_SUBSCRIPTIONS },
    NOT_SUBSCRIBED: { BYTE: constants_1.RECORD_ACTION.NOT_SUBSCRIBED },
};
exports.RPC_ACTIONS = {
    ERROR: { BYTE: constants_1.RPC_ACTION.ERROR },
    REQUEST: { TEXT: 'REQ', BYTE: constants_1.RPC_ACTION.REQUEST, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    ACCEPT: { BYTE: constants_1.RPC_ACTION.ACCEPT },
    RESPONSE: { TEXT: 'RES', BYTE: constants_1.RPC_ACTION.RESPONSE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    REJECT: { TEXT: 'REJ', BYTE: constants_1.RPC_ACTION.REJECT },
    REQUEST_ERROR: { TEXT: 'E', BYTE: constants_1.RPC_ACTION.REQUEST_ERROR, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.DEEPSTREAM },
    PROVIDE: { TEXT: 'S', BYTE: constants_1.RPC_ACTION.PROVIDE },
    UNPROVIDE: { TEXT: 'US', BYTE: constants_1.RPC_ACTION.UNPROVIDE },
    NO_RPC_PROVIDER: { BYTE: constants_1.RPC_ACTION.NO_RPC_PROVIDER },
    RESPONSE_TIMEOUT: { BYTE: constants_1.RPC_ACTION.RESPONSE_TIMEOUT },
    ACCEPT_TIMEOUT: { BYTE: constants_1.RPC_ACTION.ACCEPT_TIMEOUT },
    MULTIPLE_ACCEPT: { BYTE: constants_1.RPC_ACTION.MULTIPLE_ACCEPT },
    MULTIPLE_RESPONSE: { BYTE: constants_1.RPC_ACTION.MULTIPLE_RESPONSE },
    INVALID_RPC_CORRELATION_ID: { BYTE: constants_1.RPC_ACTION.INVALID_RPC_CORRELATION_ID },
    MESSAGE_PERMISSION_ERROR: { BYTE: constants_1.RPC_ACTION.MESSAGE_PERMISSION_ERROR },
    MESSAGE_DENIED: { BYTE: constants_1.RPC_ACTION.MESSAGE_DENIED },
    INVALID_MESSAGE_DATA: { BYTE: constants_1.RPC_ACTION.INVALID_MESSAGE_DATA },
    MULTIPLE_PROVIDERS: { BYTE: constants_1.RPC_ACTION.MULTIPLE_PROVIDERS },
    NOT_PROVIDED: { BYTE: constants_1.RPC_ACTION.NOT_PROVIDED },
};
exports.PRESENCE_ACTIONS = {
    ERROR: { TEXT: 'E', BYTE: constants_1.PRESENCE_ACTION.ERROR },
    QUERY_ALL: { BYTE: constants_1.PRESENCE_ACTION.QUERY_ALL },
    QUERY_ALL_RESPONSE: { BYTE: constants_1.PRESENCE_ACTION.QUERY_ALL_RESPONSE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.JSON },
    QUERY: { TEXT: 'Q', BYTE: constants_1.PRESENCE_ACTION.QUERY },
    QUERY_RESPONSE: { BYTE: constants_1.PRESENCE_ACTION.QUERY_RESPONSE, PAYLOAD_ENCODING: exports.PAYLOAD_ENCODING.JSON },
    PRESENCE_JOIN: { TEXT: 'PNJ', BYTE: constants_1.PRESENCE_ACTION.PRESENCE_JOIN },
    PRESENCE_JOIN_ALL: { TEXT: 'PNJ', BYTE: constants_1.PRESENCE_ACTION.PRESENCE_JOIN_ALL },
    PRESENCE_LEAVE: { TEXT: 'PNL', BYTE: constants_1.PRESENCE_ACTION.PRESENCE_LEAVE },
    PRESENCE_LEAVE_ALL: { TEXT: 'PNL', BYTE: constants_1.PRESENCE_ACTION.PRESENCE_LEAVE_ALL },
    SUBSCRIBE: { TEXT: 'S', BYTE: constants_1.PRESENCE_ACTION.SUBSCRIBE },
    UNSUBSCRIBE: { TEXT: 'US', BYTE: constants_1.PRESENCE_ACTION.UNSUBSCRIBE },
    SUBSCRIBE_ALL: { BYTE: constants_1.PRESENCE_ACTION.SUBSCRIBE_ALL },
    UNSUBSCRIBE_ALL: { BYTE: constants_1.PRESENCE_ACTION.UNSUBSCRIBE_ALL },
    INVALID_PRESENCE_USERS: { BYTE: constants_1.PRESENCE_ACTION.INVALID_PRESENCE_USERS },
    MESSAGE_PERMISSION_ERROR: { BYTE: constants_1.PRESENCE_ACTION.MESSAGE_PERMISSION_ERROR },
    MESSAGE_DENIED: { BYTE: constants_1.PRESENCE_ACTION.MESSAGE_DENIED },
    // INVALID_MESSAGE_DATA: { BYTE: UA.INVALID_MESSAGE_DATA },
    MULTIPLE_SUBSCRIPTIONS: { BYTE: constants_1.PRESENCE_ACTION.MULTIPLE_SUBSCRIPTIONS },
    NOT_SUBSCRIBED: { BYTE: constants_1.PRESENCE_ACTION.NOT_SUBSCRIBED },
};
exports.DEEPSTREAM_TYPES = {
    STRING: 'S',
    OBJECT: 'O',
    NUMBER: 'N',
    NULL: 'L',
    TRUE: 'T',
    FALSE: 'F',
    UNDEFINED: 'U',
};
exports.TOPIC_BYTE_TO_TEXT = convertMap(exports.TOPIC, 'BYTE', 'TEXT');
exports.TOPIC_TEXT_TO_BYTE = convertMap(exports.TOPIC, 'TEXT', 'BYTE');
exports.TOPIC_TEXT_TO_KEY = reverseMap(specifyMap(exports.TOPIC, 'TEXT'));
exports.TOPIC_BYTE_TO_KEY = reverseMap(specifyMap(exports.TOPIC, 'BYTE'));
exports.TOPIC_BYTES = specifyMap(exports.TOPIC, 'BYTE');
exports.ACTIONS_BYTE_TO_PAYLOAD = {};
exports.ACTIONS_BYTE_TO_TEXT = {};
exports.ACTIONS_TEXT_TO_BYTE = {};
exports.ACTIONS_BYTES = {};
exports.ACTIONS_TEXT_TO_KEY = {};
exports.ACTIONS_BYTE_TO_KEY = {};
exports.ACTIONS = {
    [exports.TOPIC.PARSER.BYTE]: exports.PARSER_ACTIONS,
    [exports.TOPIC.CONNECTION.BYTE]: exports.CONNECTION_ACTIONS,
    [exports.TOPIC.AUTH.BYTE]: exports.AUTH_ACTIONS,
    [exports.TOPIC.EVENT.BYTE]: exports.EVENT_ACTIONS,
    [exports.TOPIC.RECORD.BYTE]: exports.RECORD_ACTIONS,
    [exports.TOPIC.RPC.BYTE]: exports.RPC_ACTIONS,
    [exports.TOPIC.PRESENCE.BYTE]: exports.PRESENCE_ACTIONS,
};
for (const key in exports.ACTIONS) {
    exports.ACTIONS_BYTE_TO_PAYLOAD[key] = convertMap(exports.ACTIONS[key], 'BYTE', 'PAYLOAD_ENCODING');
    exports.ACTIONS_BYTE_TO_TEXT[key] = convertMap(exports.ACTIONS[key], 'BYTE', 'TEXT');
    exports.ACTIONS_TEXT_TO_BYTE[key] = convertMap(exports.ACTIONS[key], 'TEXT', 'BYTE');
    exports.ACTIONS_BYTES[key] = specifyMap(exports.ACTIONS[key], 'BYTE');
    exports.ACTIONS_TEXT_TO_KEY[key] = reverseMap(specifyMap(exports.ACTIONS[key], 'TEXT'));
    exports.ACTIONS_BYTE_TO_KEY[key] = reverseMap(specifyMap(exports.ACTIONS[key], 'BYTE'));
}
/**
 * convertMap({ a: { x: 1 }, b: { x: 2 }, c: { x : 3 } }, 'x', 'y')
 *  ===
 * { a: { y: 1 }, b: { y: 2 }, c: { y : 3 } }
 */
function convertMap(map, from, to) {
    const result = {};
    for (const key in map) {
        result[map[key][from]] = map[key][to];
    }
    return result;
}
/**
 * specifyMap({ a: { x: 1 }, b: { x: 2 }, c: { x : 3 } }, 'x')
 *  ===
 * { a: 1, b: 2, c: 3 }
 */
function specifyMap(map, innerKey) {
    const result = {};
    for (const key in map) {
        result[key] = map[key][innerKey];
    }
    return result;
}
/**
 * Takes a key-value map and returns
 * a map with { value: key } of the old map
 */
function reverseMap(map) {
    const reversedMap = {};
    for (const key in map) {
        reversedMap[map[key]] = key;
    }
    return reversedMap;
}
//# sourceMappingURL=constants.js.map