-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsplitExistence.ts
More file actions
19 lines (17 loc) · 1.05 KB
/
splitExistence.ts
File metadata and controls
19 lines (17 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { FALLBACK_SPLIT_NOT_FOUND, SPLIT_NOT_FOUND } from '../labels';
import { IReadinessManager } from '../../readiness/types';
import { ILogger } from '../../logger/types';
import { WARN_NOT_EXISTENT_SPLIT } from '../../logger/constants';
/**
* This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
* But it's not going to run on the input validation layer. In any case, the most compeling reason to use it as we do is to avoid going to Redis and get a split twice.
*/
export function validateSplitExistence(log: ILogger, readinessManager: IReadinessManager, splitName: string, labelOrSplitObj: any, method: string): boolean {
if (readinessManager.isReady()) { // Only if it's ready we validate this, otherwise it may just be that the SDK is not ready yet.
if (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj == null || labelOrSplitObj === FALLBACK_SPLIT_NOT_FOUND) {
log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
return false;
}
}
return true;
}