{"version":3,"file":"notification-config-cache.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/notification-config-cache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKa,QAAA,0BAA0B,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,aAAa;AAElE,MAAa,yBAAyB;IAAtC;;QACE,2CAAyC,IAAI,EAAC;QAErC,yCAAO,kCAA0B,EAAC;IA8C7C,CAAC;IAjCC,GAAG,CAAC,SAAmB;QACrB,IAAI,uBAAA,IAAI,kFAAW,MAAf,IAAI,CAAa,IAAI,CAAC,uBAAA,IAAI,wFAAiB,MAArB,IAAI,EAAkB,SAAS,CAAC,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACjC,OAAO;YACP,OAAO,EAAE,uBAAA,IAAI,wCAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK;SACjD,CAAC,CAAC,CAAC;IACN,CAAC;IAED,GAAG,CAAC,IAA6C;QAC/C,IAAI,GAAG,GAAyB,IAAI,GAAG,EAAmB,CAAC;QAE3D,kEAAkE;QAClE,IAAI,uBAAA,IAAI,wCAAO,IAAI,CAAC,uBAAA,IAAI,kFAAW,MAAf,IAAI,CAAa,EAAE,CAAC;YACtC,GAAG,GAAG,IAAI,GAAG,CAAC,uBAAA,IAAI,wCAAO,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QAED,uBAAuB;QACvB,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;YACpC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,uBAAA,IAAI,oCAAU;YACZ,IAAI,EAAE,GAAG;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,MAAA,CAAC;IACJ,CAAC;IAED,KAAK;QACH,uBAAA,IAAI,oCAAU,IAAI,MAAA,CAAC;IACrB,CAAC;CACF;AAjDD,8DAiDC;;IA3CG,OAAO,CAAC,uBAAA,IAAI,wCAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,uBAAA,IAAI,wCAAO,CAAC,SAAS,GAAG,uBAAA,IAAI,sCAAK,CAAC;AACxE,CAAC,mGAEgB,SAAmB;IAClC,IAAI,CAAC,uBAAA,IAAI,wCAAO,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,uBAAA,IAAI,wCAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC;AAqCU,QAAA,wBAAwB,GAAG,IAAI,yBAAyB,EAAE,CAAC","sourcesContent":["type NotificationConfigCache = {\n  data: Map<string, boolean>;\n  timestamp: number;\n};\n\nexport const NotificationConfigCacheTTL = 1000 * 60; // 60 seconds\n\nexport class OnChainNotificationsCache {\n  #cache: NotificationConfigCache | null = null;\n\n  readonly #ttl = NotificationConfigCacheTTL;\n\n  #isExpired(): boolean {\n    return !this.#cache || Date.now() - this.#cache.timestamp > this.#ttl;\n  }\n\n  #hasAllAddresses(addresses: string[]): boolean {\n    if (!this.#cache) {\n      return false;\n    }\n    return addresses.every((address) => this.#cache?.data.has(address));\n  }\n\n  get(addresses: string[]): { address: string; enabled: boolean }[] | null {\n    if (this.#isExpired() || !this.#hasAllAddresses(addresses)) {\n      return null;\n    }\n\n    return addresses.map((address) => ({\n      address,\n      enabled: this.#cache?.data.get(address) ?? false,\n    }));\n  }\n\n  set(data: { address: string; enabled: boolean }[]): void {\n    let map: Map<string, boolean> = new Map<string, boolean>();\n\n    // If we have existing cache, preserve it and update with new data\n    if (this.#cache && !this.#isExpired()) {\n      map = new Map(this.#cache.data);\n    }\n\n    // Update with new data\n    data.forEach(({ address, enabled }) => {\n      map.set(address, enabled);\n    });\n\n    this.#cache = {\n      data: map,\n      timestamp: Date.now(),\n    };\n  }\n\n  clear(): void {\n    this.#cache = null;\n  }\n}\n\nexport const notificationsConfigCache = new OnChainNotificationsCache();\n"]}