-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdefinitionExistence.ts
More file actions
19 lines (17 loc) · 1.14 KB
/
definitionExistence.ts
File metadata and controls
19 lines (17 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { FALLBACK_DEFINITION_NOT_FOUND, DEFINITION_NOT_FOUND } from '../labels';
import { IReadinessManager } from '../../readiness/types';
import { ILogger } from '../../logger/types';
import { WARN_NOT_EXISTENT_DEFINITION } 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 compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
*/
export function validateDefinitionExistence(log: ILogger, readinessManager: IReadinessManager, definitionName: string, labelOrDefinitionObj: any, method: string): boolean {
if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
if (labelOrDefinitionObj === DEFINITION_NOT_FOUND || labelOrDefinitionObj === FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
log.warn(WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
return false;
}
}
return true;
}