UNPKG

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

48 lines (47 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheEntry = void 0; const ui_control_commands_1 = require("../ui-control-commands"); const cache_entry_reference_1 = require("./cache-entry-reference"); const lib_1 = require("../../lib"); 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, ui_control_commands_1.ControlCommand.fromJson(json.controlCommand), json.reference ? cache_entry_reference_1.CacheEntryReference.fromJson(json.reference) : undefined, new Date(json.createdAt)); } catch (error) { lib_1.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; } } exports.CacheEntry = CacheEntry;