import { Page } from 'puppeteer' ; export default class AllPagesCache { private pages : { [ key in string ] : Page ; } = { } ; add ( uuid , page ) { this . pages [ uuid ] = page ; } exists ( page ) { return this . findUuidByPage ( page ) != null ; } findUuidByPage ( page ) { return Object . keys ( this . pages ) . find ( uuid => this . pages [ uuid ] === page ) ; } removeByUuid ( uuid ) { delete this . pages [ uuid ] ; } returns { string } removeByPage ( page ) { const uuid = this . findUuidByPage ( page ) ; if ( uuid ) { this . removeByUuid ( uuid ) ; return uuid ; } else { return null ; } } }