import { UUIDType, uuidTypes } from "./types"; export default class StorageHandler { static instance: StorageHandler; storage: Storage; constructor() { this.storage = sessionStorage; } /** * return sessionStorage instance * * @public * @return sessionStorage instance */ static getInstance(): StorageHandler { if (!this.instance) { this.instance = new StorageHandler(); } return this.instance; } /** * sessionStorage에 uuidType이 key인 uuidValue 저장 * * @public */ set(uuidType: UUIDType, uuidValue: string): void { this.storage.setItem(uuidType, uuidValue); } /** * uuidType이 key인 value return * * @public * @return uuidValue */ get(uuidType: UUIDType): string { const uuidValue = this.storage.getItem(uuidType); if (null === uuidValue) { throw new Error("Session storage retrieval failed."); } return uuidValue; } /** * uuidType이 key인 value 삭제 * * @public */ delete(uuidType: UUIDType): void { this.storage.removeItem(uuidType); } /** * sessionStorage에 있는 값들 모두 삭제 * * @public */ clear() { uuidTypes.forEach((uuidType): void => { this.storage.removeItem(uuidType); }); } }