askui
Version:
Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on
44 lines (43 loc) • 1.69 kB
JavaScript
import { ControlCommand } from '../ui-control-commands';
import { CacheEntryReference } from './cache-entry-reference';
import { logger } from '../../lib';
export class CacheEntry {
constructor(alwaysValid, controlCommand, reference, createdAt = new Date()) {
this.alwaysValid = alwaysValid;
this.controlCommand = controlCommand;
this.reference = reference;
this.createdAt = createdAt;
}
static fromJson(json) {
try {
if (json === undefined) {
throw new Error('Cache entry is undefined');
}
if (json.controlCommand === undefined) {
throw new Error('the key "controlCommand" is required');
}
if (json.createdAt === undefined) {
throw new Error('the key "createdAt" is required');
}
if (json.alwaysValid === undefined) {
throw new Error('the key "alwaysValid" is required');
}
return new CacheEntry(json.alwaysValid, ControlCommand.fromJson(json.controlCommand), json.reference ? CacheEntryReference.fromJson(json.reference) : undefined, new Date(json.createdAt));
}
catch (error) {
logger.error(`Error deserializing cache entry: ${error}`);
return undefined;
}
}
toJson() {
const jsonObject = {
alwaysValid: this.alwaysValid,
controlCommand: this.controlCommand.toJson(),
createdAt: this.createdAt,
};
if (this.reference !== undefined) {
jsonObject['reference'] = this.reference.toJson();
}
return jsonObject;
}
}