{"version":3,"file":"RunTimeDriver.mjs","names":[],"sources":["../../../../../../../cache/src/drivers/RunTimeDriver.ts"],"sourcesContent":["import { CacheDriverInterface } from \"../types\";\r\nimport BaseCacheEngine from \"./BaseCacheEngine\";\r\n\r\nexport default class RunTimeDriver\r\n  extends BaseCacheEngine\r\n  implements CacheDriverInterface\r\n{\r\n  /**\r\n   * Set the storage engine\r\n   *\r\n   * The driver is its own backend: `getItem` / `setItem` / `removeItem`\r\n   * below stay synchronous, and `BaseCacheEngine` lifts them into\r\n   * promises so this driver satisfies the async contract shared with\r\n   * IndexedDB without paying for real asynchrony.\r\n   */\r\n  public storage = this;\r\n\r\n  /**\r\n   * Data list\r\n   *\r\n   * Backed by a `Map` rather than a plain object: cache keys are\r\n   * caller-controlled, and on a plain object keys like `__proto__`,\r\n   * `constructor` or `toString` resolve through the prototype chain.\r\n   * That made `has(\"constructor\")` report `true` without anything\r\n   * being set, `set(\"__proto__\", value)` write to the store's\r\n   * prototype instead of the store, and `remove(\"__proto__\")` a silent\r\n   * no-op. A `Map` has no prototype-chain lookup, so every key is\r\n   * treated as plain data.\r\n   */\r\n  public data = new Map<string, any>();\r\n\r\n  /**\r\n   * Get item\r\n   *\r\n   * Returns `null` for missing keys (when no `defaultValue` is given)\r\n   * to match the Web Storage API contract. The previous implementation\r\n   * returned `undefined`, which broke `BaseCacheEngine.has()` — the\r\n   * base engine checks `getItem(...) !== null` and `undefined !== null`\r\n   * is `true`, so `has(missingKey)` reported `true` on this driver.\r\n   */\r\n  public getItem(key: string, defaultValue: any = null) {\r\n    const data = this.data.get(key);\r\n\r\n    if (!data) return defaultValue;\r\n\r\n    if (data.expiresAt && data.expiresAt < new Date().getTime()) {\r\n      this.removeItem(key);\r\n      return defaultValue;\r\n    }\r\n\r\n    return data.value;\r\n  }\r\n\r\n  /**\r\n   * Set item\r\n   */\r\n  public setItem(key: string, value: any, expiresAfter?: number) {\r\n    this.data.set(key, {\r\n      value,\r\n      expiresAt: expiresAfter\r\n        ? new Date().getTime() + expiresAfter * 1000\r\n        : undefined,\r\n    });\r\n  }\r\n\r\n  /**\r\n   * Remove item\r\n   */\r\n  public removeItem(key: string) {\r\n    this.data.delete(key);\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc}\r\n   */\r\n  protected convertValue(value: any) {\r\n    return value;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc}\r\n   */\r\n  protected parseValue(value: any) {\r\n    return value;\r\n  }\r\n\r\n  /**\r\n   * {@inheritDoc}\r\n   */\r\n  protected async storageKeys(): Promise<string[]> {\r\n    return [...this.data.keys()];\r\n  }\r\n\r\n  /**\r\n   * Clear the cache storage\r\n   *\r\n   * Overridden because `storage` points back at the driver itself, so\r\n   * the base implementation's `storage.clear()` fallback would recurse\r\n   * into this very method. Prefix scoping matches the base engine: with\r\n   * a prefix only the owned keys are dropped, without one the whole\r\n   * in-memory store is wiped.\r\n   */\r\n  public async clear() {\r\n    const prefix = this.getPrefixKey();\r\n\r\n    if (!prefix) {\r\n      this.data.clear();\r\n\r\n      return this;\r\n    }\r\n\r\n    for (const key of await this.storageKeys()) {\r\n      if (key.startsWith(prefix)) {\r\n        this.data.delete(key);\r\n      }\r\n    }\r\n\r\n    return this;\r\n  }\r\n}\r\n"],"mappings":";;;AAGA,IAAqB,gBAArB,cACU,gBAEV;;;iBASmB;8BAcH,IAAI,IAAiB;;;;;;;;;;;CAWnC,AAAO,QAAQ,KAAa,eAAoB,MAAM;EACpD,MAAM,OAAO,KAAK,KAAK,IAAI,GAAG;EAE9B,IAAI,CAAC,MAAM,OAAO;EAElB,IAAI,KAAK,aAAa,KAAK,6BAAY,IAAI,KAAK,EAAC,CAAC,QAAQ,GAAG;GAC3D,KAAK,WAAW,GAAG;GACnB,OAAO;EACT;EAEA,OAAO,KAAK;CACd;;;;CAKA,AAAO,QAAQ,KAAa,OAAY,cAAuB;EAC7D,KAAK,KAAK,IAAI,KAAK;GACjB;GACA,WAAW,gCACP,IAAI,KAAK,EAAC,CAAC,QAAQ,IAAI,eAAe,MACtC;EACN,CAAC;CACH;;;;CAKA,AAAO,WAAW,KAAa;EAC7B,KAAK,KAAK,OAAO,GAAG;CACtB;;;;CAKA,AAAU,aAAa,OAAY;EACjC,OAAO;CACT;;;;CAKA,AAAU,WAAW,OAAY;EAC/B,OAAO;CACT;;;;CAKA,MAAgB,cAAiC;EAC/C,OAAO,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC;CAC7B;;;;;;;;;;CAWA,MAAa,QAAQ;EACnB,MAAM,SAAS,KAAK,aAAa;EAEjC,IAAI,CAAC,QAAQ;GACX,KAAK,KAAK,MAAM;GAEhB,OAAO;EACT;EAEA,KAAK,MAAM,OAAO,MAAM,KAAK,YAAY,GACvC,IAAI,IAAI,WAAW,MAAM,GACvB,KAAK,KAAK,OAAO,GAAG;EAIxB,OAAO;CACT;AACF"}