{"version":3,"file":"main.modern.mjs","sources":["../node_modules/mimic-fn/index.js","../index.ts"],"sourcesContent":["const copyProperty = (to, from, property, ignoreNonConfigurable) => {\n\t// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.\n\t// `Function#prototype` is non-writable and non-configurable so can never be modified.\n\tif (property === 'length' || property === 'prototype') {\n\t\treturn;\n\t}\n\n\t// `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.\n\tif (property === 'arguments' || property === 'caller') {\n\t\treturn;\n\t}\n\n\tconst toDescriptor = Object.getOwnPropertyDescriptor(to, property);\n\tconst fromDescriptor = Object.getOwnPropertyDescriptor(from, property);\n\n\tif (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {\n\t\treturn;\n\t}\n\n\tObject.defineProperty(to, property, fromDescriptor);\n};\n\n// `Object.defineProperty()` throws if the property exists, is not configurable and either:\n// - one its descriptors is changed\n// - it is non-writable and its value is changed\nconst canCopyProperty = function (toDescriptor, fromDescriptor) {\n\treturn toDescriptor === undefined || toDescriptor.configurable || (\n\t\ttoDescriptor.writable === fromDescriptor.writable &&\n\t\ttoDescriptor.enumerable === fromDescriptor.enumerable &&\n\t\ttoDescriptor.configurable === fromDescriptor.configurable &&\n\t\t(toDescriptor.writable || toDescriptor.value === fromDescriptor.value)\n\t);\n};\n\nconst changePrototype = (to, from) => {\n\tconst fromPrototype = Object.getPrototypeOf(from);\n\tif (fromPrototype === Object.getPrototypeOf(to)) {\n\t\treturn;\n\t}\n\n\tObject.setPrototypeOf(to, fromPrototype);\n};\n\nconst wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\\n${fromBody}`;\n\nconst toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');\nconst toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');\n\n// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.\n// We use `bind()` instead of a closure for the same reason.\n// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.\nconst changeToString = (to, from, name) => {\n\tconst withName = name === '' ? '' : `with ${name.trim()}() `;\n\tconst newToString = wrappedToString.bind(null, withName, from.toString());\n\t// Ensure `to.toString.toString` is non-enumerable and has the same `same`\n\tObject.defineProperty(newToString, 'name', toStringName);\n\tObject.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});\n};\n\nexport default function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {\n\tconst {name} = to;\n\n\tfor (const property of Reflect.ownKeys(from)) {\n\t\tcopyProperty(to, from, property, ignoreNonConfigurable);\n\t}\n\n\tchangePrototype(to, from);\n\tchangeToString(to, from, name);\n\n\treturn to;\n}\n","import mimicFn from 'mimic-fn';\nimport type {AsyncReturnType} from 'type-fest';\n\n// TODO: Use the one in `type-fest` when it's added there.\nexport type AnyAsyncFunction = (...arguments_: readonly any[]) => Promise<unknown | void>;\n\nconst cacheStore = new WeakMap<AnyAsyncFunction, CacheStorage<any, any> | false>();\n\nexport type CacheStorage<KeyType, ValueType> = {\n\thas: (key: KeyType) => Promise<boolean> | boolean;\n\tget: (key: KeyType) => Promise<ValueType | undefined> | ValueType | undefined;\n\tset: (key: KeyType, value: ValueType) => Promise<unknown> | unknown;\n\tdelete: (key: KeyType) => unknown;\n\tclear?: () => unknown;\n};\n\nexport type Options<\n\tFunctionToMemoize extends AnyAsyncFunction,\n\tCacheKeyType,\n> = {\n\t/**\n\tDetermines the cache key for storing the result based on the function arguments. By default, __only the first argument is considered__ and it only works with [primitives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).\n\n\tA `cacheKey` function can return any type supported by `Map` (or whatever structure you use in the `cache` option).\n\n\tYou can have it cache **all** the arguments by value with `JSON.stringify`, if they are compatible:\n\n\t```\n\timport pMemoize from 'p-memoize';\n\n\tpMemoize(function_, {cacheKey: JSON.stringify});\n\t```\n\n\tOr you can use a more full-featured serializer like [serialize-javascript](https://github.com/yahoo/serialize-javascript) to add support for `RegExp`, `Date` and so on.\n\n\t```\n\timport pMemoize from 'p-memoize';\n\timport serializeJavascript from 'serialize-javascript';\n\n\tpMemoize(function_, {cacheKey: serializeJavascript});\n\t```\n\n\t@default arguments_ => arguments_[0]\n\t@example arguments_ => JSON.stringify(arguments_)\n\t*/\n\treadonly cacheKey?: (arguments_: Parameters<FunctionToMemoize>) => CacheKeyType;\n\n\t/**\n\tUse a different cache storage. Must implement the following methods: `.has(key)`, `.get(key)`, `.set(key, value)`, `.delete(key)`, and optionally `.clear()`. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache. To disable caching so that only concurrent executions resolve with the same value, pass `false`.\n\n\t@default new Map()\n\t@example new WeakMap()\n\t*/\n\treadonly cache?: CacheStorage<CacheKeyType, AsyncReturnType<FunctionToMemoize>> | false;\n};\n\n/**\n[Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.\n\n@param fn - Function to be memoized.\n\n@example\n```\nimport {setTimeout as delay} from 'node:timer/promises';\nimport pMemoize from 'p-memoize';\nimport got from 'got';\n\nconst memoizedGot = pMemoize(got);\n\nawait memoizedGot('https://sindresorhus.com');\n\n// This call is cached\nawait memoizedGot('https://sindresorhus.com');\n\nawait delay(2000);\n\n// This call is not cached as the cache has expired\nawait memoizedGot('https://sindresorhus.com');\n```\n*/\nexport function pMemoize<\n\tFunctionToMemoize extends AnyAsyncFunction,\n\tCacheKeyType,\n>(\n\tfn: FunctionToMemoize,\n\t{\n\t\tcacheKey = ([firstArgument]) => firstArgument as CacheKeyType,\n\t\tcache = new Map<CacheKeyType, AsyncReturnType<FunctionToMemoize>>(),\n\t}: Options<FunctionToMemoize, CacheKeyType> = {},\n): FunctionToMemoize {\n\t// Promise objects can't be serialized so we keep track of them internally and only provide their resolved values to `cache`\n\t// `Promise<AsyncReturnType<FunctionToMemoize>>` is used instead of `ReturnType<FunctionToMemoize>` because promise properties are not kept\n\tconst promiseCache = new Map<CacheKeyType, Promise<AsyncReturnType<FunctionToMemoize>>>();\n\n\tconst memoized = function (this: any, ...arguments_: Parameters<FunctionToMemoize>): Promise<AsyncReturnType<FunctionToMemoize>> { // eslint-disable-line @typescript-eslint/promise-function-async\n\t\tconst key = cacheKey(arguments_);\n\n\t\tif (promiseCache.has(key)) {\n\t\t\treturn promiseCache.get(key)!;\n\t\t}\n\n\t\tconst promise = (async () => {\n\t\t\ttry {\n\t\t\t\tif (cache && await cache.has(key)) {\n\t\t\t\t\treturn (await cache.get(key))!;\n\t\t\t\t}\n\n\t\t\t\tconst promise = fn.apply(this, arguments_) as Promise<AsyncReturnType<FunctionToMemoize>>;\n\n\t\t\t\tconst result = await promise;\n\n\t\t\t\ttry {\n\t\t\t\t\treturn result;\n\t\t\t\t} finally {\n\t\t\t\t\tif (cache) {\n\t\t\t\t\t\tawait cache.set(key, result);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tpromiseCache.delete(key);\n\t\t\t}\n\t\t})() as Promise<AsyncReturnType<FunctionToMemoize>>;\n\n\t\tpromiseCache.set(key, promise);\n\n\t\treturn promise;\n\t} as FunctionToMemoize;\n\n\tmimicFn(memoized, fn, {\n\t\tignoreNonConfigurable: true,\n\t});\n\n\tcacheStore.set(memoized, cache);\n\n\treturn memoized;\n}\n\n/**\n- Only class methods and getters/setters can be memoized, not regular functions (they aren't part of the proposal);\n- Only [TypeScript’s decorators](https://www.typescriptlang.org/docs/handbook/decorators.html#parameter-decorators) are supported, not [Babel’s](https://babeljs.io/docs/en/babel-plugin-proposal-decorators), which use a different version of the proposal;\n- Being an experimental feature, they need to be enabled with `--experimentalDecorators`; follow TypeScript’s docs.\n\n@returns A [decorator](https://github.com/tc39/proposal-decorators) to memoize class methods or static class methods.\n\n@example\n```\nimport {pMemoizeDecorator} from 'p-memoize';\n\nclass Example {\n\tindex = 0\n\n\t@pMemoizeDecorator()\n\tasync counter() {\n\t\treturn ++this.index;\n\t}\n}\n\nclass ExampleWithOptions {\n\tindex = 0\n\n\t@pMemoizeDecorator()\n\tasync counter() {\n\t\treturn ++this.index;\n\t}\n}\n```\n*/\nexport function pMemoizeDecorator<\n\tFunctionToMemoize extends AnyAsyncFunction,\n\tCacheKeyType,\n>(\n\toptions: Options<FunctionToMemoize, CacheKeyType> = {},\n) {\n\tconst instanceMap = new WeakMap();\n\n\treturn (\n\t\ttarget: any,\n\t\tpropertyKey: string,\n\t\tdescriptor: PropertyDescriptor,\n\t): void => {\n\t\tconst input = target[propertyKey]; // eslint-disable-line @typescript-eslint/no-unsafe-assignment\n\n\t\tif (typeof input !== 'function') {\n\t\t\tthrow new TypeError('The decorated value must be a function');\n\t\t}\n\n\t\tdelete descriptor.value;\n\t\tdelete descriptor.writable;\n\n\t\tdescriptor.get = function () {\n\t\t\tif (!instanceMap.has(this)) {\n\t\t\t\tconst value = pMemoize(input, options) as FunctionToMemoize;\n\t\t\t\tinstanceMap.set(this, value);\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\treturn instanceMap.get(this) as FunctionToMemoize;\n\t\t};\n\t};\n}\n\n/**\nClear all cached data of a memoized function.\n\n@param fn - Memoized function.\n*/\nexport function pMemoizeClear(fn: AnyAsyncFunction): void {\n\tif (!cacheStore.has(fn)) {\n\t\tthrow new TypeError('Can\\'t clear a function that was not memoized!');\n\t}\n\n\tconst cache = cacheStore.get(fn);\n\n\tif (!cache) {\n\t\tthrow new TypeError('Can\\'t clear a function that doesn\\'t use a cache!');\n\t}\n\n\tif (typeof cache.clear !== 'function') {\n\t\tthrow new TypeError('The cache Map can\\'t be cleared!');\n\t}\n\n\tcache.clear();\n}\n"],"names":["cacheStore","WeakMap","pMemoize","fn","cacheKey","firstArgument","cache","Map","promiseCache","memoized","arguments_","key","has","get","promise","apply","result","set","delete","mimicFn","ignoreNonConfigurable","pMemoizeDecorator","options","instanceMap","target","propertyKey","descriptor","input","TypeError","value","writable","pMemoizeClear","clear"],"mappings":"AAAA,MAAM,Y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