{"version":3,"file":"NamespacedStorage.cjs","names":[],"sources":["../../../src/utils/NamespacedStorage/NamespacedStorage.ts"],"sourcesContent":["export class NamespacedStorage implements Storage {\n  private readonly _keyPrefix: string;\n  private readonly _storage: Storage;\n\n  public constructor(namespace: string, storage: Storage) {\n    this._keyPrefix = `${namespace}_`;\n    this._storage = storage;\n  }\n\n  protected getNamespacedKeys(): string[] {\n    const keys = [];\n    for (let i = 0; i < this._storage.length; i++) {\n      const key = this._storage.key(i);\n      if (key?.startsWith(this._keyPrefix)) {\n        keys.push(key.substring(this._keyPrefix.length));\n      }\n    }\n\n    return keys;\n  }\n\n  public get length(): number {\n    return this.getNamespacedKeys().length;\n  }\n\n  public clear(): void {\n    this.getNamespacedKeys().forEach((key) => {\n      this._storage.removeItem(`${this._keyPrefix}${key}`);\n    });\n  }\n\n  public getItem(key: string): string | null {\n    return this._storage.getItem(`${this._keyPrefix}${key}`);\n  }\n\n  public key(index: number): string | null {\n    return this.getNamespacedKeys()[index] || null;\n  }\n\n  public removeItem(key: string): void {\n    this._storage.removeItem(`${this._keyPrefix}${key}`);\n  }\n\n  public setItem(key: string, value: string): void {\n    this._storage.setItem(`${this._keyPrefix}${key}`, value);\n  }\n\n  /**\n   * Returns the namespaced underlying-storage key for a logical key. Browser\n   * `storage` events fire with the underlying key, so callers that filter\n   * those events need to compare against this value rather than the logical\n   * key. Plain `Storage` instances do not expose this method; callers should\n   * fall back to the logical key in that case.\n   */\n  public getStorageEventKey(logicalKey: string): string {\n    return `${this._keyPrefix}${logicalKey}`;\n  }\n}\n"],"mappings":";;AAAA,IAAa,oBAAb,MAAkD;CAChD;CACA;CAEA,YAAmB,WAAmB,SAAkB;AACtD,OAAK,aAAa,GAAG,UAAU;AAC/B,OAAK,WAAW;;CAGlB,oBAAwC;EACtC,MAAM,OAAO,EAAE;AACf,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;GAC7C,MAAM,MAAM,KAAK,SAAS,IAAI,EAAE;AAChC,OAAI,KAAK,WAAW,KAAK,WAAW,CAClC,MAAK,KAAK,IAAI,UAAU,KAAK,WAAW,OAAO,CAAC;;AAIpD,SAAO;;CAGT,IAAW,SAAiB;AAC1B,SAAO,KAAK,mBAAmB,CAAC;;CAGlC,QAAqB;AACnB,OAAK,mBAAmB,CAAC,SAAS,QAAQ;AACxC,QAAK,SAAS,WAAW,GAAG,KAAK,aAAa,MAAM;IACpD;;CAGJ,QAAe,KAA4B;AACzC,SAAO,KAAK,SAAS,QAAQ,GAAG,KAAK,aAAa,MAAM;;CAG1D,IAAW,OAA8B;AACvC,SAAO,KAAK,mBAAmB,CAAC,UAAU;;CAG5C,WAAkB,KAAmB;AACnC,OAAK,SAAS,WAAW,GAAG,KAAK,aAAa,MAAM;;CAGtD,QAAe,KAAa,OAAqB;AAC/C,OAAK,SAAS,QAAQ,GAAG,KAAK,aAAa,OAAO,MAAM;;;;;;;;;CAU1D,mBAA0B,YAA4B;AACpD,SAAO,GAAG,KAAK,aAAa"}