{"version":3,"file":"removable.cjs","names":["isValidTimeout","#gcTimeout","timeoutManager","isServerEnvironment"],"sources":["../../src/removable.ts"],"sourcesContent":["import { timeoutManager } from './timeoutManager'\nimport { isServer as isServerEnvironment } from './environmentManager'\nimport { isValidTimeout } from './utils'\nimport type { ManagedTimerId } from './timeoutManager'\n\nexport abstract class Removable {\n  gcTime!: number\n  #gcTimeout?: ManagedTimerId\n\n  destroy(): void {\n    this.clearGcTimeout()\n  }\n\n  protected scheduleGc(): void {\n    this.clearGcTimeout()\n\n    if (isValidTimeout(this.gcTime)) {\n      this.#gcTimeout = timeoutManager.setTimeout(() => {\n        this.optionalRemove()\n      }, this.gcTime)\n    }\n  }\n\n  protected updateGcTime(newGcTime: number | undefined): void {\n    // Default to 5 minutes (Infinity for server-side) if no gcTime is set\n    this.gcTime = Math.max(\n      this.gcTime || 0,\n      newGcTime ?? (isServerEnvironment() ? Infinity : 5 * 60 * 1000),\n    )\n  }\n\n  protected clearGcTimeout() {\n    if (this.#gcTimeout !== undefined) {\n      timeoutManager.clearTimeout(this.#gcTimeout)\n      this.#gcTimeout = undefined\n    }\n  }\n\n  protected abstract optionalRemove(): void\n}\n"],"mappings":";;;;;AAKA,IAAsB,YAAtB,MAAgC;CAE9B;CAEA,UAAgB;EACd,KAAK,eAAe;CACtB;CAEA,aAA6B;EAC3B,KAAK,eAAe;EAEpB,IAAIA,cAAAA,eAAe,KAAK,MAAM,GAC5B,KAAKC,aAAaC,uBAAAA,eAAe,iBAAiB;GAChD,KAAK,eAAe;EACtB,GAAG,KAAK,MAAM;CAElB;CAEA,aAAuB,WAAqC;EAE1D,KAAK,SAAS,KAAK,IACjB,KAAK,UAAU,GACf,cAAcC,2BAAAA,SAAoB,IAAI,WAAW,IACnD;CACF;CAEA,iBAA2B;EACzB,IAAI,KAAKF,eAAe,KAAA,GAAW;GACjC,uBAAA,eAAe,aAAa,KAAKA,UAAU;GAC3C,KAAKA,aAAa,KAAA;EACpB;CACF;AAGF"}