import{isTtlCorrect as n}from"../../../utils/is-ttl-correct.js";import{PluginStorageLocalRepository as a}from"../repositories/plugin-storage-local-repository.js";class s{static#e;#t;constructor(t){this.#t=t}static async#s(t){const e=await a.getInstance(t),r=new s(e);s.#e=r}static async getInstance(t){return t.removeExisting===void 0&&(t.removeExisting=!1),s.#e||await s.#s(t),s.#e}async get(t){const e=await this.#t.get(t.key);return e?e.value:null}async set(t){if(this.#r(t.value),!n(t.ttlInSeconds))throw new Error("TTL must be null or a positive number");return await this.#t.set(t)}async delete(t){return await this.#t.delete(t)}async clear(){return await this.#t.clearAll()}#r(t){try{JSON.stringify(t)}catch(e){const r=e instanceof Error?e.message:"Unknown error";throw new Error(`Value is not JSON serializable: ${r}`)}}}export{s as PluginStorageService};
