UNPKG

@splitsoftware/splitio-commons

Version:
32 lines (31 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateTrafficTypeExistence = void 0; var thenable_1 = require("../promise/thenable"); var constants_1 = require("../constants"); var constants_2 = require("../../logger/constants"); function logTTExistenceWarning(log, maybeTT, method) { log.warn(constants_2.WARN_NOT_EXISTENT_TT, [method, maybeTT]); } /** * Separated from the previous method since on some cases it'll be async. */ function validateTrafficTypeExistence(log, readinessManager, splitsCache, mode, maybeTT, method) { // If not ready or in localhost mode, we won't run the validation if (!readinessManager.isReady() || mode === constants_1.LOCALHOST_MODE) return true; var res = splitsCache.trafficTypeExists(maybeTT); // never rejects or throws error if ((0, thenable_1.thenable)(res)) { return res.then(function (isValid) { if (!isValid) logTTExistenceWarning(log, maybeTT, method); return isValid; // propagate result }); } else { if (!res) logTTExistenceWarning(log, maybeTT, method); return res; } } exports.validateTrafficTypeExistence = validateTrafficTypeExistence;