{"version":3,"file":"index.cjs","sources":["../../../src/CacheEventEmitter.ts","../../../src/maxArgs.ts","../../../src/serialize.ts","../../../src/utils.ts","../../../src/Cache.ts","../../../src/expires.ts","../../../src/stats.ts","../../../src/index.ts"],"sourcesContent":["import type { Cache } from './Cache.js';\nimport type { CacheEventListener, CacheEventType, CacheNode } from './internalTypes.js';\n\ntype ListenerMap<Fn extends (...args: any[]) => any> = Partial<\n  Record<string, Set<CacheEventListener<CacheEventType, Fn>>>\n>;\n\nexport class CacheEventEmitter<Fn extends (...args: any[]) => any> {\n  /**\n   * The list of [l]isteners for the given [t]ype.\n   */\n  l: ListenerMap<Fn> = {};\n\n  /**\n   * The [c]ache the emitter is associated with.\n   */\n  private c: Cache<Fn>;\n\n  constructor(cache: Cache<Fn>) {\n    this.c = cache;\n  }\n\n  /**\n   * Method to [a]dd a listener for the given cache change event.\n   */\n  a<Type extends CacheEventType>(type: Type, listener: CacheEventListener<Type, Fn>): void {\n    const listeners = this.l[type];\n\n    if (!listeners) {\n      this.l[type] = new Set([listener]);\n    } else if (!listeners.has(listener)) {\n      listeners.add(listener);\n    }\n  }\n\n  /**\n   * Method to [n]otify all listeners for the given cache change event.\n   */\n  n(type: CacheEventType, node: CacheNode<Fn>, reason?: string): void {\n    const listeners = this.l[type];\n\n    if (!listeners) {\n      return;\n    }\n\n    listeners.forEach((listener) => {\n      listener({\n        cache: this.c,\n        key: node.k,\n        reason,\n        value: node.v,\n        type,\n      });\n    });\n  }\n\n  /**\n   * Method to [r]emove a listener for the given cache change event.\n   */\n  r<Type extends CacheEventType>(type: Type, listener: CacheEventListener<Type, Fn>): void {\n    const listeners = this.l[type];\n\n    if (!listeners) {\n      return;\n    }\n\n    listeners.delete(listener);\n\n    if (!listeners.size) {\n      this.l[type] = undefined;\n    }\n  }\n}\n","import type { Key, TransformKey } from './internalTypes.js';\n\n/**\n * Create a method that takes the first N number of items from the array (faster than slice).\n */\nexport function getMaxArgsTransformKey<Fn extends (...args: any[]) => any>(\n  maxArgs: number,\n): TransformKey<Fn> | undefined {\n  if (maxArgs === 1) {\n    return (args: Key) => (maxArgs >= args.length ? args : [args[0]]);\n  }\n\n  if (maxArgs === 2) {\n    return (args: Key) => (maxArgs >= args.length ? args : [args[0], args[1]]);\n  }\n\n  return (args: Key) => {\n    if (maxArgs >= args.length) {\n      return args;\n    }\n\n    const clone = new Array(maxArgs);\n\n    for (let index = 0; index < maxArgs; ++index) {\n      clone[index] = args[index];\n    }\n\n    return clone;\n  };\n}\n","import { stringify } from 'fast-stringify';\nimport type { Key } from './internalTypes.js';\n\n/**\n * Default replacer used when stringifying to ensure values that would normally be\n * ignored are respected.\n */\nfunction replacer(_key: string, value: any): any {\n  const type = typeof value;\n\n  return type === 'function' || type === 'symbol' ? value.toString() : value;\n}\n\n/**\n * Default serializer used when `serialize` option set to `true`.\n */\nexport function transformKeySerialized<Fn extends (...args: any[]) => any>(args: Parameters<Fn>): [string] {\n  return [stringify(args, { replacer })];\n}\n\n/**\n * Determines whether the serialized keys are equal to one another.\n */\nexport function isSerializedKeyEqual(prevKey: Key, nextKey: Key): boolean {\n  return prevKey[0] === nextKey[0];\n}\n","import type { Memoized, Options } from './internalTypes.js';\n\n/**\n * Whether the value passed is a memoized function via `micro-memoize`.\n */\nexport function isMemoized<Fn extends (...args: any) => any, Opts extends Options<Fn>>(\n  fn: any,\n): fn is Memoized<Fn, Opts> {\n  return typeof fn === 'function' && fn.isMemoized;\n}\n\n/**\n * Determine whether the value passed is a numeric value for usage in common contexts.\n * This is a positive, finite integer.\n */\nexport function isNumericValueValid(value: any): value is number {\n  return typeof value === 'number' && value >= 0 && Number.isFinite(value);\n}\n","import { deepEqual, shallowEqual } from 'fast-equals';\nimport { CacheEventEmitter } from './CacheEventEmitter.js';\nimport type {\n  CacheEntry,\n  CacheEventType,\n  CacheEventListener,\n  CacheNode,\n  CacheSnapshot,\n  Key,\n  Options,\n  IsKeyEqual,\n  TransformKey,\n} from './internalTypes.js';\nimport { getMaxArgsTransformKey } from './maxArgs.js';\nimport { isSerializedKeyEqual, transformKeySerialized } from './serialize.js';\nimport { isNumericValueValid } from './utils.js';\n\nexport class Cache<Fn extends (...args: any[]) => any> {\n  /**\n   * The current [c]ount of entries in the cache.\n   */\n  c = 0;\n  /**\n   * Whether the entire key is [e]qual to an existing key in cache.\n   */\n  e: IsKeyEqual;\n  /**\n   * The [h]ead of the cache linked list.\n   */\n  h: CacheNode<Fn> | undefined;\n  /**\n   * The transformer for the [k]ey stored in cache.\n   */\n  k: Options<Fn>['transformKey'] | undefined;\n  /**\n   * Event emitter for `[o]`n events.\n   */\n  o: CacheEventEmitter<Fn> | undefined;\n  /**\n   * Whether to await the [p]romise returned by the function.\n   */\n  p: Options<Fn>['async'];\n  /**\n   * The maximum [s]ize of the cache.\n   */\n  s: number;\n  /**\n   * The [t]ail of the cache linked list.\n   */\n  t: CacheNode<Fn> | undefined;\n\n  constructor(options: Options<Fn>) {\n    const { async, maxSize } = options;\n\n    this.e = getIsKeyEqual(options);\n    this.k = getTransformKey(options);\n    this.p = typeof async === 'boolean' && async;\n    this.s = isNumericValueValid(maxSize) ? maxSize : 1;\n  }\n\n  /**\n   * The size of the populated cache.\n   */\n  get size(): number {\n    return this.c;\n  }\n\n  /**\n   * The [key, value] pairs for the existing entries in cache.\n   */\n  get snapshot(): CacheSnapshot<Fn> {\n    const entries: Array<CacheEntry<Fn>> = [];\n    const keys: Key[] = [];\n    const values: Array<ReturnType<Fn>> = [];\n\n    let node = this.h;\n    let size = 0;\n\n    while (node != null) {\n      keys.push(node.k);\n      values.push(node.v);\n      entries.push([node.k, node.v]);\n      ++size;\n\n      node = node.n;\n    }\n\n    return { entries, keys, size, values };\n  }\n\n  /**\n   * Clear the cache.\n   */\n  clear(reason = 'explicit clear'): void {\n    if (!this.h) {\n      return;\n    }\n\n    const emitter = this.o;\n\n    let nodes: Array<CacheNode<Fn>> | undefined;\n\n    if (emitter) {\n      nodes = [];\n\n      let node: CacheNode<Fn> | undefined = this.h;\n\n      while (node != null) {\n        nodes.push(node);\n        node = node.n;\n      }\n    }\n\n    this.h = this.t = undefined;\n    this.c = 0;\n\n    if (emitter && nodes) {\n      for (let index = 0; index < nodes.length; ++index) {\n        emitter.n('delete', nodes[index]!, reason);\n      }\n    }\n  }\n\n  /**\n   * Delete the entry for the key based on the given `args` in cache.\n   */\n  delete(args: Parameters<Fn>, reason = 'explicit delete'): boolean {\n    const node = this.g(this.k ? this.k(args) : args);\n\n    if (node) {\n      this.d(node, reason);\n\n      return true;\n    }\n\n    return false;\n  }\n\n  /**\n   * Get the value in cache based on the given `args`.\n   */\n  get(args: Parameters<Fn>, reason = 'explicit get'): ReturnType<Fn> | undefined {\n    const node = this.g(this.k ? this.k(args) : args);\n\n    if (node) {\n      if (node !== this.h) {\n        this.u(node, reason, true);\n      } else if (this.o) {\n        this.o.n('hit', node, reason);\n      }\n\n      return node.v;\n    }\n  }\n\n  /**\n   * Determine whether the given `args` have a related entry in the cache.\n   */\n  has(args: Parameters<Fn>): boolean {\n    return !!this.g(this.k ? this.k(args) : args);\n  }\n\n  /**\n   * Remove the given `listener` for the given `type` of cache event.\n   */\n  off<Type extends CacheEventType>(type: Type, listener: CacheEventListener<Type, Fn>): void {\n    this.o && this.o.r(type, listener);\n  }\n\n  /**\n   * Add the given `listener` for the given `type` of cache event.\n   */\n  on<Type extends CacheEventType>(type: Type, listener: CacheEventListener<Type, Fn>): void {\n    if (!this.o) {\n      this.o = new CacheEventEmitter<Fn>(this);\n    }\n\n    this.o.a(type, listener);\n  }\n\n  /**\n   * Add or update the cache entry for the given `key`.\n   */\n  set(key: Parameters<Fn>, value: ReturnType<Fn>, reason = 'explicit set'): void {\n    const normalizedKey = this.k ? this.k(key) : key;\n\n    let node = this.g(normalizedKey);\n\n    if (node) {\n      const prevValue = node.v;\n\n      node.v = value;\n\n      if (this.p && value !== prevValue) {\n        node.v = this.w(node);\n      }\n\n      node !== this.h && this.u(node, reason, false);\n    } else {\n      node = this.n(normalizedKey, value);\n    }\n  }\n\n  /**\n   * Method to [d]elete the given `node` from the cache.\n   */\n  d(node: CacheNode<Fn>, reason: string): void {\n    const next = node.n;\n    const prev = node.p;\n\n    if (next) {\n      next.p = prev;\n    } else {\n      this.t = prev;\n    }\n\n    if (prev) {\n      prev.n = next;\n    } else {\n      this.h = next;\n    }\n\n    --this.c;\n\n    node.r = true;\n\n    this.o && this.o.n('delete', node, reason);\n  }\n\n  /**\n   * Method to [g]et an existing node from cache based on the given `key`.\n   */\n  g(key: Key): CacheNode<Fn> | undefined {\n    let node = this.h;\n\n    if (!node || node.r) {\n      return;\n    }\n\n    if (this.e(node.k, key)) {\n      return node;\n    }\n\n    if (this.h === this.t) {\n      return;\n    }\n\n    node = node.n;\n\n    while (node) {\n      if (node.r) {\n        return;\n      }\n\n      if (this.e(node.k, key)) {\n        return node;\n      }\n\n      node = node.n;\n    }\n  }\n\n  /**\n   * Method to create a new [n]ode and set it at the head of the linked list.\n   */\n  n(key: Key, value: ReturnType<Fn>, reason?: string): CacheNode<Fn> {\n    const prevHead = this.h;\n    const prevTail = this.t;\n    const node = { k: key, n: prevHead, p: undefined, v: value };\n\n    if (this.p) {\n      node.v = this.w(node);\n    }\n\n    this.h = node;\n\n    if (prevHead) {\n      prevHead.p = node;\n    } else {\n      this.t = node;\n    }\n\n    if (++this.c > this.s && prevTail) {\n      this.d(prevTail, 'evicted');\n    }\n\n    this.o && this.o.n('add', node, reason);\n\n    return node;\n  }\n\n  /**\n   * Method to [u]date the location of the given `node` in cache.\n   */\n  u(node: CacheNode<Fn>, reason: string | undefined, hit: boolean): void {\n    const next = node.n;\n    const prev = node.p;\n\n    if (next) {\n      next.p = prev;\n    }\n\n    if (prev) {\n      prev.n = next;\n    }\n\n    if (this.h) {\n      this.h.p = node;\n    }\n\n    node.n = this.h;\n    node.p = undefined;\n\n    this.h = node;\n\n    if (node === this.t) {\n      this.t = prev;\n    }\n\n    if (this.o) {\n      hit && this.o.n('hit', node, reason);\n      this.o.n('update', node, reason);\n    }\n  }\n\n  /**\n   * Method to [w]rap the promise in a handler to automatically delete the\n   * entry if it rejects.\n   */\n  w(node: CacheNode<Fn>): ReturnType<Fn> {\n    const { v: value } = node;\n\n    // If the method does not return a promise for some reason, just keep the\n    // original value.\n    if (value == null || typeof value.then !== 'function') {\n      return value;\n    }\n\n    return value.then(\n      (value: any) => {\n        !node.r && this.o && this.o.n('update', node, 'resolved');\n\n        return value;\n      },\n      (error: unknown) => {\n        !node.r && this.d(node, 'rejected');\n\n        throw error;\n      },\n    );\n  }\n}\n\nfunction getIsKeyEqual<Fn extends (...args: any[]) => any>({\n  isKeyEqual,\n  isKeyItemEqual,\n  serialize,\n}: Options<Fn>): IsKeyEqual {\n  if (typeof isKeyEqual === 'function') {\n    return isKeyEqual;\n  }\n\n  if (serialize) {\n    return isSerializedKeyEqual;\n  }\n\n  const isItemEqual =\n    typeof isKeyItemEqual === 'function'\n      ? isKeyItemEqual\n      : isKeyItemEqual === 'deep'\n        ? deepEqual\n        : isKeyItemEqual === 'shallow'\n          ? shallowEqual\n          : Object.is;\n\n  return function isKeyEqual(prevKey: Key, nextKey: Key): boolean {\n    const length = nextKey.length;\n\n    if (prevKey.length !== length) {\n      return false;\n    }\n\n    if (length === 1) {\n      return isItemEqual(prevKey[0], nextKey[0], 0);\n    }\n\n    for (let index = 0; index < length; ++index) {\n      if (!isItemEqual(prevKey[index], nextKey[index], index)) {\n        return false;\n      }\n    }\n\n    return true;\n  };\n}\n\n/**\n * Get the `transformKey` option based on the options provided.\n */\nfunction getTransformKey<Fn extends (...args: any[]) => any>(options: Options<Fn>): TransformKey<Fn> | undefined {\n  const { maxArgs, serialize, transformKey } = options;\n\n  const transformers = [\n    serialize ? (typeof serialize === 'function' ? serialize : transformKeySerialized) : undefined,\n    isNumericValueValid(maxArgs) ? getMaxArgsTransformKey(maxArgs) : undefined,\n    typeof transformKey === 'function' ? transformKey : undefined,\n  ].filter(Boolean) as Array<(...args: any[]) => any>;\n\n  return transformers.length\n    ? transformers.reduce(\n        (f, g) =>\n          (...args) =>\n            // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n            f(g(...args)),\n      )\n    : undefined;\n}\n","import type { Cache } from './Cache.js';\nimport type {\n  CacheEventListener,\n  GetExpires,\n  Key,\n  Options,\n  ShouldPersist,\n  ShouldRemoveOnExpire,\n} from './internalTypes.js';\nimport { isNumericValueValid } from './utils.js';\n\nexport class ExpirationManager<Fn extends (...args: any[]) => any> {\n  /**\n   * The [c]ache being monitored.\n   */\n  c: Cache<Fn>;\n  /**\n   * Map of [e]xpiration timeouts.\n   */\n  e = new Map<Key, ReturnType<typeof setTimeout>>();\n  /**\n   * Whether the entry in cache should [p]ersist, and therefore not\n   * have any expiration.\n   */\n  p: ShouldPersist<Fn> | undefined;\n  /**\n   * Whether the entry in cache should be [r]emoved on expiration.\n   */\n  r: ShouldRemoveOnExpire<Fn> | undefined;\n  /**\n   * The [t]ime to wait before expiring, or a method that determines that time.\n   */\n  t: number | GetExpires<Fn>;\n  /**\n   * Whether the expiration should [u]pdate when the cache entry is hit.\n   */\n  u: boolean;\n\n  constructor(cache: Cache<Fn>, expires: Required<Options<Fn>>['expires']) {\n    this.c = cache;\n\n    if (typeof expires === 'object') {\n      this.t = expires.after;\n      this.p = expires.shouldPersist;\n      this.r = expires.shouldRemove;\n      this.u = !!expires.update;\n    } else {\n      this.t = expires;\n      this.u = false;\n    }\n\n    this.c.on('add', ({ key, value }) => {\n      this.a(key, value) && this.s(key, value);\n    });\n\n    if (this.u) {\n      // Set up a `hit` listener if we care about updating the expiration.\n      this.c.on('hit', ({ key, value }) => {\n        this.a(key, value) && this.s(key, value);\n      });\n\n      if (this.c.p) {\n        const onResolved: CacheEventListener<'update', Fn> = ({ key, reason, value }) => {\n          if (reason === 'resolved' && this.a(key, value)) {\n            this.s(key, value);\n            // Automatically remove the listener to avoid unnecessary work on updates after\n            // the item is resolved, as that can only ever happen once.\n            this.c.off('update', onResolved);\n          }\n        };\n\n        // If the method is also async, then when the value resolved update the expiration cache.\n        this.c.on('update', onResolved);\n      }\n    }\n\n    this.c.on('delete', ({ key }) => {\n      this.e.has(key) && this.d(key);\n    });\n  }\n\n  get size(): number {\n    return this.e.size;\n  }\n\n  /**\n   * Whether the cache expiration should be set [a]gain, generally after some cache change.\n   */\n  a(key: Key, value: ReturnType<Fn>): boolean {\n    return !!(this.c.g(key) && !this.p?.(key, value, this.c));\n  }\n\n  /**\n   * Method to [d]elete the expiration.\n   */\n  d(key: Key): void {\n    const expiration = this.e.get(key);\n\n    if (expiration) {\n      clearTimeout(expiration);\n      this.e.delete(key);\n    }\n  }\n\n  /**\n   * Method to [s]et the new expiration. If one is present for the given `key`, it will delete\n   * the existing expiration before creating the new one.\n   */\n  s(key: Key, value: ReturnType<Fn>): void {\n    if (this.e.has(key)) {\n      this.d(key);\n    }\n\n    const cache = this.c;\n    const time = typeof this.t === 'function' ? this.t(key, value, cache) : this.t;\n\n    if (!isNumericValueValid(time)) {\n      throw new TypeError(`The expiration time must be a finite, non-negative number; received ${time as string}`);\n    }\n\n    const timeout = setTimeout(() => {\n      this.d(key);\n\n      const node = cache.g(key);\n\n      if (!node) {\n        return;\n      }\n\n      if (typeof this.r === 'function' && !this.r(key, node.v, time, cache)) {\n        if (node !== cache.h) {\n          cache.u(node, 'expiration reset', false);\n        } else if (cache.o) {\n          // Always notify, even if at the top of the cache.\n          cache.o.n('update', node, 'expiration reset');\n        }\n\n        this.s(key, node.v);\n      } else {\n        cache.d(node, 'expired');\n      }\n    }, time);\n\n    if (typeof timeout.unref === 'function') {\n      // If done in NodeJS, the timeout should have its reference removed to avoid\n      // hanging timers if collected while running.\n      timeout.unref();\n    }\n\n    this.e.set(key, timeout);\n  }\n}\n","import { Cache } from './Cache.js';\nimport type { GlobalStats, ProfileStats } from './internalTypes.js';\n\ninterface ProfileCounts {\n  c: number;\n  h: number;\n}\n\nconst nameToProfile = new Map<string, StatsManager<any>>();\n\nlet active = false;\n\nexport class StatsManager<Fn extends (...args: any[]) => any> {\n  /**\n   * The [c]ache listened to when collecting counts.\n   */\n  c: Cache<Fn>;\n  /**\n   * Method to [d]elete existing cache listeners.\n   */\n  d: (() => void) | undefined;\n  /**\n   * The [n]ame of the profile to manage in stats.\n   */\n  n: string;\n  /**\n   * The counts for the stats [p]rofile.\n   */\n  p: ProfileCounts = { c: 0, h: 0 };\n\n  constructor(cache: Cache<Fn>, statsName: string) {\n    this.c = cache;\n    this.n = statsName;\n\n    nameToProfile.set(statsName, this);\n\n    if (active) {\n      this.s();\n    }\n  }\n\n  /**\n   * Method to compute the [m]etrics for the profile stats.\n   */\n  m(): ProfileStats {\n    const { c: calls, h: hits } = this.p;\n    const usage = calls ? `${((hits / calls) * 100).toFixed(4)}%` : '0.0000%';\n\n    return { calls, hits, name: this.n, usage };\n  }\n\n  /**\n   * Method to [r]eset the counts.\n   */\n  r() {\n    this.p = { c: 0, h: 0 };\n  }\n\n  /**\n   * Method to [s]tart the collection of stats for the given profile.\n   */\n  s() {\n    const onAdd = () => {\n      ++this.p.c;\n    };\n    const onHit = () => {\n      ++this.p.c;\n      ++this.p.h;\n    };\n\n    this.d = () => {\n      this.c.off('add', onAdd);\n      this.c.off('hit', onHit);\n\n      this.d = undefined;\n\n      this.p.c = this.p.h = 0;\n    };\n\n    this.c.on('add', onAdd);\n    this.c.on('hit', onHit);\n  }\n}\n\n/**\n * Clear all existing stats stored, either of the specific profile whose name is passed,\n * or globally if no name is passed.\n */\nexport function clearStats(statsName?: string) {\n  if (!active) {\n    return;\n  }\n\n  if (statsName) {\n    const statsManager = nameToProfile.get(statsName);\n\n    if (statsManager) {\n      statsManager.r();\n    }\n  } else {\n    nameToProfile.clear();\n  }\n}\n\n/**\n * Get the stats of a given profile, or global stats if no `statsName` is given.\n */\nexport function getStats<Name extends string | undefined>(\n  statsName?: Name,\n): undefined extends Name ? GlobalStats | undefined : ProfileStats | undefined {\n  if (!active) {\n    console.warn('Stats are not being collected; please run \"startCollectingStats()\" to collect them.');\n    return;\n  }\n\n  if (statsName != null) {\n    const statsManager = nameToProfile.get(statsName);\n\n    const profileStats: ProfileStats = statsManager?.p.c\n      ? statsManager.m()\n      : {\n          calls: 0,\n          hits: 0,\n          name: statsName,\n          usage: getUsagePercentage(0, 0),\n        };\n    // @ts-expect-error - Conditional returns can be tricky.\n    return profileStats;\n  }\n\n  let calls = 0;\n  let hits = 0;\n\n  const profiles: Record<string, ProfileStats> = {};\n\n  nameToProfile.forEach((profile, statsName) => {\n    profiles[statsName] = profile.m();\n\n    calls += profile.p.c;\n    hits += profile.p.h;\n  });\n\n  const globalStats: GlobalStats = {\n    calls,\n    hits,\n    profiles,\n    usage: getUsagePercentage(calls, hits),\n  };\n\n  // @ts-expect-error - Conditional returns can be tricky.\n  return globalStats;\n}\n\n/**\n * Get the usage percentage based on the number of hits and total calls.\n */\nfunction getUsagePercentage(calls: number, hits: number): string {\n  return calls ? `${((hits / calls) * 100).toFixed(4)}%` : '0.0000%';\n}\n\n/**\n * Whether stats are currently being collected.\n */\nexport function isCollectingStats(): boolean {\n  return active;\n}\n\n/**\n * Start collecting stats.\n */\nexport function startCollectingStats(): void {\n  if (!active) {\n    active = true;\n\n    nameToProfile.forEach((profile) => {\n      profile.s();\n    });\n  }\n}\n\n/**\n * Stop collecting stats.\n */\nexport function stopCollectingStats(): void {\n  if (active) {\n    nameToProfile.forEach((profile) => {\n      profile.d?.();\n    });\n\n    active = false;\n  }\n}\n","import { Cache } from './Cache.js';\nimport { ExpirationManager } from './expires.js';\nimport type { Key, Memoize, Memoized, Options } from './internalTypes.js';\nimport { StatsManager } from './stats.js';\nimport { isMemoized } from './utils.js';\n\nexport type * from './internalTypes.js';\n\nexport const memoize: Memoize = function memoize<Fn extends (...args: any[]) => any, Opts extends Options<Fn>>(\n  fn: Fn | Memoized<Fn, Opts>,\n  options: Opts = {} as Opts,\n): Memoized<Fn, Opts> {\n  if (isMemoized(fn)) {\n    return memoize(fn.fn, Object.assign({}, fn.options, options));\n  }\n\n  if (typeof fn !== 'function') {\n    throw new TypeError(`Expected first parameter to be function; received ${typeof fn}`);\n  }\n\n  const cache = new Cache(options);\n  const memoized = createMemoizedMethod<Fn, Opts>(fn, cache, options.forceUpdate);\n\n  const { expires, statsName } = options;\n\n  memoized.cache = cache;\n  memoized.expirationManager = expires != null ? new ExpirationManager(cache, expires) : null;\n  memoized.fn = fn;\n  memoized.isMemoized = true;\n  memoized.options = options;\n  memoized.statsManager = statsName != null ? new StatsManager(cache, statsName) : null;\n\n  return memoized;\n};\n\nfunction createMemoizedMethod<Fn extends (...args: any) => any, Opts extends Options<Fn>>(\n  fn: Fn,\n  cache: Cache<Fn>,\n  forceUpdate: Opts['forceUpdate'],\n): Memoized<Fn, Opts> {\n  const memoized = function memoized(this: any, ...args: Parameters<Fn>): ReturnType<Fn> {\n    const key: Key = cache.k ? cache.k(args) : args;\n\n    let node = cache.g(key);\n\n    if (!node) {\n      node = cache.n(key, fn.apply(this, args) as ReturnType<Fn>);\n    } else if (node !== cache.h) {\n      cache.u(node, undefined, true);\n    } else if (cache.o) {\n      cache.o.n('hit', node);\n    }\n\n    return node.v;\n  } as Memoized<Fn, Opts>;\n\n  if (!forceUpdate) {\n    return memoized;\n  }\n\n  return function wrappedMemoized(this: any, ...args: Parameters<Fn>): ReturnType<Fn> {\n    if (!forceUpdate(args) || !cache.has(args)) {\n      return memoized.apply(this, args);\n    }\n\n    const value: ReturnType<Fn> = fn.apply(this, args);\n\n    cache.set(args, value, 'forced');\n\n    return value;\n  } as Memoized<Fn, Opts>;\n}\n\nexport { clearStats, isCollectingStats, getStats, startCollectingStats, stopCollectingStats } from './stats.js';\n"],"names":["stringify","deepEqual","shallowEqual"],"mappings":";;;;;MAOa,iBAAiB,CAAA;AAW5B,IAAA,WAAA,CAAY,KAAgB,EAAA;AAV5B;;AAEG;QACH,IAAA,CAAA,CAAC,GAAoB,EAAE;AAQrB,QAAA,IAAI,CAAC,CAAC,GAAG,KAAK;IAChB;AAEA;;AAEG;IACH,CAAC,CAA8B,IAAU,E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