@pnpm/exe 11.0.0-alpha.9 → 11.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/dist/node_modules/@gar/promise-retry/lib/index.js +28 -0
  2. package/dist/node_modules/@gar/promise-retry/package.json +48 -0
  3. package/dist/node_modules/@npmcli/agent/package.json +7 -7
  4. package/dist/node_modules/@npmcli/fs/package.json +4 -4
  5. package/dist/node_modules/abbrev/package.json +11 -15
  6. package/dist/node_modules/balanced-match/package.json +4 -7
  7. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +1 -1
  8. package/dist/node_modules/brace-expansion/dist/esm/index.js +1 -1
  9. package/dist/node_modules/brace-expansion/package.json +3 -3
  10. package/dist/node_modules/cacache/package.json +10 -11
  11. package/dist/node_modules/glob/dist/commonjs/glob.js +2 -1
  12. package/dist/node_modules/glob/dist/commonjs/index.min.js +4 -0
  13. package/dist/node_modules/glob/dist/commonjs/pattern.js +4 -0
  14. package/dist/node_modules/glob/dist/esm/glob.js +2 -1
  15. package/dist/node_modules/glob/dist/esm/index.min.js +4 -0
  16. package/dist/node_modules/glob/dist/esm/pattern.js +4 -0
  17. package/dist/node_modules/glob/package.json +38 -37
  18. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +460 -525
  19. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +179 -182
  20. package/dist/node_modules/iconv-lite/encodings/index.js +15 -15
  21. package/dist/node_modules/iconv-lite/encodings/internal.js +168 -148
  22. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +55 -52
  23. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +174 -175
  24. package/dist/node_modules/iconv-lite/encodings/utf16.js +121 -131
  25. package/dist/node_modules/iconv-lite/encodings/utf32.js +226 -238
  26. package/dist/node_modules/iconv-lite/encodings/utf7.js +208 -215
  27. package/dist/node_modules/iconv-lite/lib/bom-handling.js +30 -34
  28. package/dist/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
  29. package/dist/node_modules/iconv-lite/lib/index.js +125 -123
  30. package/dist/node_modules/iconv-lite/lib/streams.js +92 -96
  31. package/dist/node_modules/iconv-lite/package.json +34 -8
  32. package/dist/node_modules/isexe/package.json +65 -18
  33. package/dist/node_modules/lru-cache/dist/commonjs/index.js +134 -85
  34. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
  35. package/dist/node_modules/lru-cache/dist/esm/index.js +134 -85
  36. package/dist/node_modules/lru-cache/dist/esm/index.min.js +1 -1
  37. package/dist/node_modules/lru-cache/package.json +18 -41
  38. package/dist/node_modules/make-fetch-happen/lib/remote.js +1 -1
  39. package/dist/node_modules/make-fetch-happen/package.json +10 -10
  40. package/dist/node_modules/minimatch/dist/commonjs/ast.js +266 -21
  41. package/dist/node_modules/minimatch/dist/commonjs/index.js +178 -92
  42. package/dist/node_modules/minimatch/dist/esm/ast.js +266 -21
  43. package/dist/node_modules/minimatch/dist/esm/index.js +178 -92
  44. package/dist/node_modules/minimatch/package.json +4 -4
  45. package/dist/node_modules/minipass/dist/commonjs/index.js +13 -3
  46. package/dist/node_modules/minipass/dist/esm/index.js +3 -1
  47. package/dist/node_modules/minipass/package.json +9 -14
  48. package/dist/node_modules/minipass-fetch/lib/body.js +25 -15
  49. package/dist/node_modules/minipass-fetch/package.json +7 -7
  50. package/dist/node_modules/minipass-sized/dist/commonjs/index.js +69 -0
  51. package/dist/node_modules/minipass-sized/dist/esm/index.js +64 -0
  52. package/dist/node_modules/minipass-sized/package.json +39 -9
  53. package/dist/node_modules/node-gyp/.release-please-manifest.json +1 -1
  54. package/dist/node_modules/node-gyp/bin/node-gyp.js +7 -0
  55. package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +1 -1
  56. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +3 -3
  57. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +26 -1
  58. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +1 -1
  59. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +3 -4
  60. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +1 -1
  61. package/dist/node_modules/node-gyp/gyp/pyproject.toml +1 -1
  62. package/dist/node_modules/node-gyp/lib/build.js +2 -2
  63. package/dist/node_modules/node-gyp/lib/find-python.js +2 -8
  64. package/dist/node_modules/node-gyp/lib/find-visualstudio.js +11 -5
  65. package/dist/node_modules/node-gyp/lib/install.js +1 -1
  66. package/dist/node_modules/node-gyp/lib/process-release.js +3 -3
  67. package/dist/node_modules/node-gyp/package.json +13 -13
  68. package/dist/node_modules/nopt/package.json +5 -5
  69. package/dist/node_modules/path-scurry/package.json +8 -24
  70. package/dist/node_modules/proc-log/lib/index.js +10 -5
  71. package/dist/node_modules/proc-log/package.json +5 -5
  72. package/dist/node_modules/retry/lib/retry.js +2 -2
  73. package/dist/node_modules/retry/lib/retry_operation.js +10 -6
  74. package/dist/node_modules/retry/package.json +6 -2
  75. package/dist/node_modules/ssri/lib/index.js +33 -63
  76. package/dist/node_modules/ssri/package.json +17 -17
  77. package/dist/node_modules/tar/dist/commonjs/index.min.js +2 -2
  78. package/dist/node_modules/tar/dist/commonjs/unpack.js +4 -4
  79. package/dist/node_modules/tar/dist/esm/index.min.js +2 -2
  80. package/dist/node_modules/tar/dist/esm/unpack.js +4 -4
  81. package/dist/node_modules/tar/package.json +6 -6
  82. package/dist/node_modules/unique-filename/package.json +5 -5
  83. package/dist/node_modules/unique-slug/package.json +4 -4
  84. package/dist/node_modules/which/package.json +29 -20
  85. package/dist/pnpm.mjs +225713 -208017
  86. package/dist/worker.js +4838 -5926
  87. package/package.json +10 -10
  88. package/setup.js +12 -14
  89. package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.js +0 -16
  90. package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.js +0 -170
  91. package/dist/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.js +0 -307
  92. package/dist/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.js +0 -7
  93. package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.js +0 -322
  94. package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.min.js +0 -12
  95. package/dist/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.js +0 -49
  96. package/dist/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.js +0 -8
  97. package/dist/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.js +0 -176
  98. package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.js +0 -12
  99. package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.js +0 -167
  100. package/dist/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.js +0 -299
  101. package/dist/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.js +0 -3
  102. package/dist/node_modules/@isaacs/cliui/dist/esm/index.js +0 -317
  103. package/dist/node_modules/@isaacs/cliui/dist/esm/index.min.js +0 -12
  104. package/dist/node_modules/@isaacs/cliui/dist/esm/string-width/index.js +0 -46
  105. package/dist/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.js +0 -4
  106. package/dist/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.js +0 -172
  107. package/dist/node_modules/@isaacs/cliui/package.json +0 -163
  108. package/dist/node_modules/cross-spawn/LICENSE +0 -21
  109. package/dist/node_modules/cross-spawn/index.js +0 -39
  110. package/dist/node_modules/cross-spawn/lib/enoent.js +0 -59
  111. package/dist/node_modules/cross-spawn/lib/parse.js +0 -91
  112. package/dist/node_modules/cross-spawn/lib/util/escape.js +0 -47
  113. package/dist/node_modules/cross-spawn/lib/util/readShebang.js +0 -23
  114. package/dist/node_modules/cross-spawn/lib/util/resolveCommand.js +0 -52
  115. package/dist/node_modules/cross-spawn/package.json +0 -73
  116. package/dist/node_modules/encoding/.prettierrc.js +0 -8
  117. package/dist/node_modules/encoding/LICENSE +0 -16
  118. package/dist/node_modules/encoding/lib/encoding.js +0 -83
  119. package/dist/node_modules/encoding/package.json +0 -18
  120. package/dist/node_modules/err-code/.eslintrc.json +0 -7
  121. package/dist/node_modules/err-code/bower.json +0 -30
  122. package/dist/node_modules/err-code/index.js +0 -47
  123. package/dist/node_modules/err-code/index.umd.js +0 -51
  124. package/dist/node_modules/err-code/package.json +0 -34
  125. package/dist/node_modules/foreground-child/LICENSE +0 -15
  126. package/dist/node_modules/foreground-child/dist/commonjs/all-signals.js +0 -58
  127. package/dist/node_modules/foreground-child/dist/commonjs/index.js +0 -123
  128. package/dist/node_modules/foreground-child/dist/commonjs/proxy-signals.js +0 -38
  129. package/dist/node_modules/foreground-child/dist/commonjs/watchdog.js +0 -50
  130. package/dist/node_modules/foreground-child/dist/esm/all-signals.js +0 -52
  131. package/dist/node_modules/foreground-child/dist/esm/index.js +0 -115
  132. package/dist/node_modules/foreground-child/dist/esm/proxy-signals.js +0 -34
  133. package/dist/node_modules/foreground-child/dist/esm/watchdog.js +0 -46
  134. package/dist/node_modules/foreground-child/package.json +0 -106
  135. package/dist/node_modules/glob/dist/esm/bin.d.mts +0 -3
  136. package/dist/node_modules/glob/dist/esm/bin.mjs +0 -346
  137. package/dist/node_modules/iconv-lite/.github/dependabot.yml +0 -11
  138. package/dist/node_modules/iconv-lite/.idea/codeStyles/Project.xml +0 -47
  139. package/dist/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +0 -5
  140. package/dist/node_modules/iconv-lite/.idea/iconv-lite.iml +0 -12
  141. package/dist/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +0 -6
  142. package/dist/node_modules/iconv-lite/.idea/modules.xml +0 -8
  143. package/dist/node_modules/iconv-lite/.idea/vcs.xml +0 -6
  144. package/dist/node_modules/isexe/LICENSE +0 -15
  145. package/dist/node_modules/isexe/index.js +0 -57
  146. package/dist/node_modules/isexe/mode.js +0 -41
  147. package/dist/node_modules/isexe/windows.js +0 -42
  148. package/dist/node_modules/jackspeak/dist/commonjs/index.js +0 -944
  149. package/dist/node_modules/jackspeak/dist/commonjs/index.min.js +0 -33
  150. package/dist/node_modules/jackspeak/dist/commonjs/package.json +0 -3
  151. package/dist/node_modules/jackspeak/dist/esm/index.js +0 -936
  152. package/dist/node_modules/jackspeak/dist/esm/index.min.js +0 -33
  153. package/dist/node_modules/jackspeak/dist/esm/package.json +0 -3
  154. package/dist/node_modules/jackspeak/package.json +0 -115
  155. package/dist/node_modules/lru-cache/LICENSE +0 -15
  156. package/dist/node_modules/minipass/LICENSE +0 -15
  157. package/dist/node_modules/minipass-sized/index.js +0 -67
  158. package/dist/node_modules/minipass-sized/node_modules/minipass/LICENSE +0 -15
  159. package/dist/node_modules/minipass-sized/node_modules/minipass/index.js +0 -649
  160. package/dist/node_modules/minipass-sized/node_modules/minipass/package.json +0 -56
  161. package/dist/node_modules/minipass-sized/package-lock.json +0 -3464
  162. package/dist/node_modules/node-gyp/node_modules/isexe/dist/commonjs/package.json +0 -3
  163. package/dist/node_modules/node-gyp/node_modules/isexe/dist/esm/package.json +0 -3
  164. package/dist/node_modules/node-gyp/node_modules/isexe/package.json +0 -78
  165. package/dist/node_modules/node-gyp/node_modules/which/LICENSE +0 -15
  166. package/dist/node_modules/node-gyp/node_modules/which/package.json +0 -52
  167. package/dist/node_modules/package-json-from-dist/dist/commonjs/index.js +0 -134
  168. package/dist/node_modules/package-json-from-dist/dist/commonjs/package.json +0 -3
  169. package/dist/node_modules/package-json-from-dist/dist/esm/index.js +0 -129
  170. package/dist/node_modules/package-json-from-dist/dist/esm/package.json +0 -3
  171. package/dist/node_modules/package-json-from-dist/package.json +0 -68
  172. package/dist/node_modules/path-key/index.js +0 -16
  173. package/dist/node_modules/path-key/license +0 -9
  174. package/dist/node_modules/path-key/package.json +0 -39
  175. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +0 -1589
  176. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +0 -2
  177. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +0 -3
  178. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +0 -1585
  179. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +0 -2
  180. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +0 -3
  181. package/dist/node_modules/path-scurry/node_modules/lru-cache/package.json +0 -101
  182. package/dist/node_modules/promise-retry/index.js +0 -52
  183. package/dist/node_modules/promise-retry/package.json +0 -37
  184. package/dist/node_modules/retry/equation.gif +0 -0
  185. package/dist/node_modules/shebang-command/index.js +0 -19
  186. package/dist/node_modules/shebang-command/license +0 -9
  187. package/dist/node_modules/shebang-command/package.json +0 -34
  188. package/dist/node_modules/shebang-regex/index.js +0 -2
  189. package/dist/node_modules/shebang-regex/license +0 -9
  190. package/dist/node_modules/shebang-regex/package.json +0 -35
  191. package/dist/node_modules/signal-exit/LICENSE.txt +0 -16
  192. package/dist/node_modules/signal-exit/dist/cjs/browser.js +0 -10
  193. package/dist/node_modules/signal-exit/dist/cjs/index.js +0 -279
  194. package/dist/node_modules/signal-exit/dist/cjs/package.json +0 -3
  195. package/dist/node_modules/signal-exit/dist/cjs/signals.js +0 -42
  196. package/dist/node_modules/signal-exit/dist/mjs/browser.js +0 -4
  197. package/dist/node_modules/signal-exit/dist/mjs/index.js +0 -275
  198. package/dist/node_modules/signal-exit/dist/mjs/package.json +0 -3
  199. package/dist/node_modules/signal-exit/dist/mjs/signals.js +0 -39
  200. package/dist/node_modules/signal-exit/package.json +0 -106
  201. package/dist/node_modules/which/bin/node-which +0 -52
  202. package/dist/node_modules/which/which.js +0 -125
  203. /package/dist/node_modules/{promise-retry → @gar/promise-retry}/LICENSE +0 -0
  204. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.js +0 -0
  205. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.min.js +0 -0
  206. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/options.js +0 -0
  207. /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/commonjs/package.json +0 -0
  208. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/posix.js +0 -0
  209. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/win32.js +0 -0
  210. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.js +0 -0
  211. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.min.js +0 -0
  212. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/options.js +0 -0
  213. /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/esm/package.json +0 -0
  214. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/posix.js +0 -0
  215. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/win32.js +0 -0
  216. /package/dist/node_modules/{foreground-child → minipass-sized}/dist/commonjs/package.json +0 -0
  217. /package/dist/node_modules/{foreground-child → minipass-sized}/dist/esm/package.json +0 -0
  218. /package/dist/node_modules/{node-gyp/node_modules/which → which}/bin/which.js +0 -0
  219. /package/dist/node_modules/{node-gyp/node_modules/which → which}/lib/index.js +0 -0
@@ -1,2 +1,2 @@
1
- "use strict";var G=(l,t,e)=>{if(!t.has(l))throw TypeError("Cannot "+e)};var j=(l,t,e)=>(G(l,t,"read from private field"),e?e.call(l):t.get(l)),I=(l,t,e)=>{if(t.has(l))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(l):t.set(l,e)},x=(l,t,e,i)=>(G(l,t,"write to private field"),i?i.call(l,e):t.set(l,e),e);Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var T=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,P=new Set,U=typeof process=="object"&&process?process:{},H=(l,t,e,i)=>{typeof U.emitWarning=="function"?U.emitWarning(l,t,e,i):console.error(`[${e}] ${t}: ${l}`)},D=globalThis.AbortController,N=globalThis.AbortSignal;if(typeof D>"u"){N=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(i,s){this._onabort.push(s)}},D=class{constructor(){t()}signal=new N;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=!0;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i)}}};let l=U.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{l&&(l=!1,H("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t))}}var V=l=>!P.has(l),Y=Symbol("type"),A=l=>l&&l===Math.floor(l)&&l>0&&isFinite(l),k=l=>A(l)?l<=Math.pow(2,8)?Uint8Array:l<=Math.pow(2,16)?Uint16Array:l<=Math.pow(2,32)?Uint32Array:l<=Number.MAX_SAFE_INTEGER?E:null:null,E=class extends Array{constructor(t){super(t),this.fill(0)}},v,O=class{heap;length;static create(t){let e=k(t);if(!e)return[];x(O,v,!0);let i=new O(t,e);return x(O,v,!1),i}constructor(t,e){if(!j(O,v))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},W=O;v=new WeakMap,I(W,v,!1);var C=class{#g;#f;#p;#w;#R;#W;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#S;#s;#i;#t;#l;#c;#o;#h;#_;#r;#b;#m;#u;#y;#E;#a;static unsafeExposeInternals(t){return{starts:t.#m,ttls:t.#u,sizes:t.#b,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#l,prev:t.#c,get head(){return t.#o},get tail(){return t.#h},free:t.#_,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#x(e,i,s,n),moveToTail:e=>t.#C(e),indexes:e=>t.#A(e),rindexes:e=>t.#F(e),isStale:e=>t.#d(e)}}get max(){return this.#g}get maxSize(){return this.#f}get calculatedSize(){return this.#S}get size(){return this.#n}get fetchMethod(){return this.#R}get memoMethod(){return this.#W}get dispose(){return this.#p}get disposeAfter(){return this.#w}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:h,updateAgeOnHas:o,allowStale:r,dispose:g,disposeAfter:b,noDisposeOnSet:f,noUpdateTTL:u,maxSize:c=0,maxEntrySize:F=0,sizeCalculation:d,fetchMethod:S,memoMethod:a,noDeleteOnFetchRejection:w,noDeleteOnStaleGet:m,allowStaleOnFetchRejection:p,allowStaleOnFetchAbort:_,ignoreFetchAbort:z}=t;if(e!==0&&!A(e))throw new TypeError("max option must be a nonnegative integer");let y=e?k(e):Array;if(!y)throw new Error("invalid max value: "+e);if(this.#g=e,this.#f=c,this.maxEntrySize=F||this.#f,this.sizeCalculation=d,this.sizeCalculation){if(!this.#f&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(a!==void 0&&typeof a!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#W=a,S!==void 0&&typeof S!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#R=S,this.#E=!!S,this.#s=new Map,this.#i=new Array(e).fill(void 0),this.#t=new Array(e).fill(void 0),this.#l=new y(e),this.#c=new y(e),this.#o=0,this.#h=0,this.#_=W.create(e),this.#n=0,this.#S=0,typeof g=="function"&&(this.#p=g),typeof b=="function"?(this.#w=b,this.#r=[]):(this.#w=void 0,this.#r=void 0),this.#y=!!this.#p,this.#a=!!this.#w,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!w,this.allowStaleOnFetchRejection=!!p,this.allowStaleOnFetchAbort=!!_,this.ignoreFetchAbort=!!z,this.maxEntrySize!==0){if(this.#f!==0&&!A(this.#f))throw new TypeError("maxSize must be a positive integer if specified");if(!A(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#P()}if(this.allowStale=!!r,this.noDeleteOnStaleGet=!!m,this.updateAgeOnGet=!!h,this.updateAgeOnHas=!!o,this.ttlResolution=A(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!A(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#U()}if(this.#g===0&&this.ttl===0&&this.#f===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#g&&!this.#f){let R="LRU_CACHE_UNBOUNDED";V(R)&&(P.add(R),H("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",R,C))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#U(){let t=new E(this.#g),e=new E(this.#g);this.#u=t,this.#m=e,this.#M=(n,h,o=T.now())=>{if(e[n]=h!==0?o:0,t[n]=h,h!==0&&this.ttlAutopurge){let r=setTimeout(()=>{this.#d(n)&&this.#T(this.#i[n],"expire")},h+1);r.unref&&r.unref()}},this.#v=n=>{e[n]=t[n]!==0?T.now():0},this.#O=(n,h)=>{if(t[h]){let o=t[h],r=e[h];if(!o||!r)return;n.ttl=o,n.start=r,n.now=i||s();let g=n.now-r;n.remainingTTL=o-g}};let i=0,s=()=>{let n=T.now();if(this.ttlResolution>0){i=n;let h=setTimeout(()=>i=0,this.ttlResolution);h.unref&&h.unref()}return n};this.getRemainingTTL=n=>{let h=this.#s.get(n);if(h===void 0)return 0;let o=t[h],r=e[h];if(!o||!r)return 1/0;let g=(i||s())-r;return o-g},this.#d=n=>{let h=e[n],o=t[n];return!!o&&!!h&&(i||s())-h>o}}#v=()=>{};#O=()=>{};#M=()=>{};#d=()=>!1;#P(){let t=new E(this.#g);this.#S=0,this.#b=t,this.#z=e=>{this.#S-=t[e],t[e]=0},this.#G=(e,i,s,n)=>{if(this.#e(i))return 0;if(!A(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!A(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#D=(e,i,s)=>{if(t[e]=i,this.#f){let n=this.#f-t[e];for(;this.#S>n;)this.#L(!0)}this.#S+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#S)}}#z=t=>{};#D=(t,e,i)=>{};#G=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;!(!this.#j(e)||((t||!this.#d(e))&&(yield e),e===this.#o));)e=this.#c[e]}*#F({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#o;!(!this.#j(e)||((t||!this.#d(e))&&(yield e),e===this.#h));)e=this.#l[e]}#j(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#A())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#F())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#A()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#F()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#A())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#F())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.get(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#F()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#F({allowStale:!0}))this.#d(e)&&(this.#T(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#u&&this.#m){let h=this.#u[e],o=this.#m[e];if(h&&o){let r=h-(T.now()-o);n.ttl=r,n.start=Date.now()}}return this.#b&&(n.size=this.#b[e]),n}dump(){let t=[];for(let e of this.#A({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let h={value:n};if(this.#u&&this.#m){h.ttl=this.#u[e];let o=T.now()-this.#m[e];h.start=Math.floor(Date.now()-o)}this.#b&&(h.size=this.#b[e]),t.unshift([i,h])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=T.now()-s}this.set(e,i.value,i)}}set(t,e,i={}){if(e===void 0)return this.delete(t),this;let{ttl:s=this.ttl,start:n,noDisposeOnSet:h=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:r}=i,{noUpdateTTL:g=this.noUpdateTTL}=i,b=this.#G(t,e,i.size||0,o);if(this.maxEntrySize&&b>this.maxEntrySize)return r&&(r.set="miss",r.maxEntrySizeExceeded=!0),this.#T(t,"set"),this;let f=this.#n===0?void 0:this.#s.get(t);if(f===void 0)f=this.#n===0?this.#h:this.#_.length!==0?this.#_.pop():this.#n===this.#g?this.#L(!1):this.#n,this.#i[f]=t,this.#t[f]=e,this.#s.set(t,f),this.#l[this.#h]=f,this.#c[f]=this.#h,this.#h=f,this.#n++,this.#D(f,b,r),r&&(r.set="add"),g=!1;else{this.#C(f);let u=this.#t[f];if(e!==u){if(this.#E&&this.#e(u)){u.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:c}=u;c!==void 0&&!h&&(this.#y&&this.#p?.(c,t,"set"),this.#a&&this.#r?.push([c,t,"set"]))}else h||(this.#y&&this.#p?.(u,t,"set"),this.#a&&this.#r?.push([u,t,"set"]));if(this.#z(f),this.#D(f,b,r),this.#t[f]=e,r){r.set="replace";let c=u&&this.#e(u)?u.__staleWhileFetching:u;c!==void 0&&(r.oldValue=c)}}else r&&(r.set="update")}if(s!==0&&!this.#u&&this.#U(),this.#u&&(g||this.#M(f,s,n),r&&this.#O(r,f)),!h&&this.#a&&this.#r){let u=this.#r,c;for(;c=u?.shift();)this.#w?.(...c)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#o];if(this.#L(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#a&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#w?.(...e)}}}#L(t){let e=this.#o,i=this.#i[e],s=this.#t[e];return this.#E&&this.#e(s)?s.__abortController.abort(new Error("evicted")):(this.#y||this.#a)&&(this.#y&&this.#p?.(s,i,"evict"),this.#a&&this.#r?.push([s,i,"evict"])),this.#z(e),t&&(this.#i[e]=void 0,this.#t[e]=void 0,this.#_.push(e)),this.#n===1?(this.#o=this.#h=0,this.#_.length=0):this.#o=this.#l[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let h=this.#t[n];if(this.#e(h)&&h.__staleWhileFetching===void 0)return!1;if(this.#d(n))s&&(s.has="stale",this.#O(s,n));else return i&&this.#v(n),s&&(s.has="hit",this.#O(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{allowStale:i=this.allowStale}=e,s=this.#s.get(t);if(s===void 0||!i&&this.#d(s))return;let n=this.#t[s];return this.#e(n)?n.__staleWhileFetching:n}#x(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let h=new D,{signal:o}=i;o?.addEventListener("abort",()=>h.abort(o.reason),{signal:h.signal});let r={signal:h.signal,options:i,context:s},g=(d,S=!1)=>{let{aborted:a}=h.signal,w=i.ignoreFetchAbort&&d!==void 0;if(i.status&&(a&&!S?(i.status.fetchAborted=!0,i.status.fetchError=h.signal.reason,w&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),a&&!w&&!S)return f(h.signal.reason);let m=c;return this.#t[e]===c&&(d===void 0?m.__staleWhileFetching?this.#t[e]=m.__staleWhileFetching:this.#T(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.set(t,d,r.options))),d},b=d=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=d),f(d)),f=d=>{let{aborted:S}=h.signal,a=S&&i.allowStaleOnFetchAbort,w=a||i.allowStaleOnFetchRejection,m=w||i.noDeleteOnFetchRejection,p=c;if(this.#t[e]===c&&(!m||p.__staleWhileFetching===void 0?this.#T(t,"fetch"):a||(this.#t[e]=p.__staleWhileFetching)),w)return i.status&&p.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),p.__staleWhileFetching;if(p.__returned===p)throw d},u=(d,S)=>{let a=this.#R?.(t,n,r);a&&a instanceof Promise&&a.then(w=>d(w===void 0?void 0:w),S),h.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(d(void 0),i.allowStaleOnFetchAbort&&(d=w=>g(w,!0)))})};i.status&&(i.status.fetchDispatched=!0);let c=new Promise(u).then(g,b),F=Object.assign(c,{__abortController:h,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.set(t,F,{...r.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=F,F}#e(t){if(!this.#E)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof D}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:h=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:r=0,sizeCalculation:g=this.sizeCalculation,noUpdateTTL:b=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:c=this.ignoreFetchAbort,allowStaleOnFetchAbort:F=this.allowStaleOnFetchAbort,context:d,forceRefresh:S=!1,status:a,signal:w}=e;if(!this.#E)return a&&(a.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:a});let m={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:h,noDisposeOnSet:o,size:r,sizeCalculation:g,noUpdateTTL:b,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:F,ignoreFetchAbort:c,status:a,signal:w},p=this.#s.get(t);if(p===void 0){a&&(a.fetch="miss");let _=this.#x(t,p,m,d);return _.__returned=_}else{let _=this.#t[p];if(this.#e(_)){let M=i&&_.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",M&&(a.returnedStale=!0)),M?_.__staleWhileFetching:_.__returned=_}let z=this.#d(p);if(!S&&!z)return a&&(a.fetch="hit"),this.#C(p),s&&this.#v(p),a&&this.#O(a,p),_;let y=this.#x(t,p,m,d),L=y.__staleWhileFetching!==void 0&&i;return a&&(a.fetch=z?"stale":"refresh",L&&z&&(a.returnedStale=!0)),L?y.__staleWhileFetching:y.__returned=y}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=this.#W;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,forceRefresh:n,...h}=e,o=this.get(t,h);if(!n&&o!==void 0)return o;let r=i(t,o,{options:h,context:s});return this.set(t,r,h),r}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:h}=e,o=this.#s.get(t);if(o!==void 0){let r=this.#t[o],g=this.#e(r);return h&&this.#O(h,o),this.#d(o)?(h&&(h.get="stale"),g?(h&&i&&r.__staleWhileFetching!==void 0&&(h.returnedStale=!0),i?r.__staleWhileFetching:void 0):(n||this.#T(t,"expire"),h&&i&&(h.returnedStale=!0),i?r:void 0)):(h&&(h.get="hit"),g?r.__staleWhileFetching:(this.#C(o),s&&this.#v(o),r))}else h&&(h.get="miss")}#I(t,e){this.#c[e]=t,this.#l[t]=e}#C(t){t!==this.#h&&(t===this.#o?this.#o=this.#l[t]:this.#I(this.#c[t],this.#l[t]),this.#I(this.#h,t),this.#h=t)}delete(t){return this.#T(t,"delete")}#T(t,e){let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(i=!0,this.#n===1)this.#N(e);else{this.#z(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#y||this.#a)&&(this.#y&&this.#p?.(n,t,e),this.#a&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#c[s];else if(s===this.#o)this.#o=this.#l[s];else{let h=this.#c[s];this.#l[h]=this.#l[s];let o=this.#l[s];this.#c[o]=this.#c[s]}this.#n--,this.#_.push(s)}}if(this.#a&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#w?.(...n)}return i}clear(){return this.#N("delete")}#N(t){for(let e of this.#F({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#y&&this.#p?.(i,s,t),this.#a&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#u&&this.#m&&(this.#u.fill(0),this.#m.fill(0)),this.#b&&this.#b.fill(0),this.#o=0,this.#h=0,this.#_.length=0,this.#S=0,this.#n=0,this.#a&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#w?.(...i)}}};exports.LRUCache=C;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.LRUCache=void 0;var G=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,U=new Set,R=typeof process=="object"&&process?process:{},I=(c,t,e,i)=>{typeof R.emitWarning=="function"?R.emitWarning(c,t,e,i):console.error(`[${e}] ${t}: ${c}`)},C=globalThis.AbortController,L=globalThis.AbortSignal;if(typeof C>"u"){L=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(i,s){this._onabort.push(s)}},C=class{constructor(){t()}signal=new L;abort(i){if(!this.signal.aborted){this.signal.reason=i,this.signal.aborted=!0;for(let s of this.signal._onabort)s(i);this.signal.onabort?.(i)}}};let c=R.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",t=()=>{c&&(c=!1,I("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t))}}var x=c=>!U.has(c),H=Symbol("type"),y=c=>c&&c===Math.floor(c)&&c>0&&isFinite(c),M=c=>y(c)?c<=Math.pow(2,8)?Uint8Array:c<=Math.pow(2,16)?Uint16Array:c<=Math.pow(2,32)?Uint32Array:c<=Number.MAX_SAFE_INTEGER?z:null:null,z=class extends Array{constructor(t){super(t),this.fill(0)}},W=class c{heap;length;static#o=!1;static create(t){let e=M(t);if(!e)return[];c.#o=!0;let i=new c(t,e);return c.#o=!1,i}constructor(t,e){if(!c.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},D=class c{#o;#c;#w;#C;#S;#L;#U;#m;get perf(){return this.#m}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#_;#s;#i;#t;#a;#u;#l;#h;#b;#r;#y;#A;#d;#g;#T;#v;#f;#I;static unsafeExposeInternals(t){return{starts:t.#A,ttls:t.#d,autopurgeTimers:t.#g,sizes:t.#y,keyMap:t.#s,keyList:t.#i,valList:t.#t,next:t.#a,prev:t.#u,get head(){return t.#l},get tail(){return t.#h},free:t.#b,isBackgroundFetch:e=>t.#e(e),backgroundFetch:(e,i,s,n)=>t.#x(e,i,s,n),moveToTail:e=>t.#D(e),indexes:e=>t.#F(e),rindexes:e=>t.#O(e),isStale:e=>t.#p(e)}}get max(){return this.#o}get maxSize(){return this.#c}get calculatedSize(){return this.#_}get size(){return this.#n}get fetchMethod(){return this.#L}get memoMethod(){return this.#U}get dispose(){return this.#w}get onInsert(){return this.#C}get disposeAfter(){return this.#S}constructor(t){let{max:e=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:h,allowStale:r,dispose:a,onInsert:w,disposeAfter:f,noDisposeOnSet:d,noUpdateTTL:g,maxSize:A=0,maxEntrySize:p=0,sizeCalculation:_,fetchMethod:l,memoMethod:S,noDeleteOnFetchRejection:b,noDeleteOnStaleGet:m,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:T,ignoreFetchAbort:F,perf:v}=t;if(v!==void 0&&typeof v?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#m=v??G,e!==0&&!y(e))throw new TypeError("max option must be a nonnegative integer");let O=e?M(e):Array;if(!O)throw new Error("invalid max value: "+e);if(this.#o=e,this.#c=A,this.maxEntrySize=p||this.#c,this.sizeCalculation=_,this.sizeCalculation){if(!this.#c&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(S!==void 0&&typeof S!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#U=S,l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#L=l,this.#v=!!l,this.#s=new Map,this.#i=new Array(e).fill(void 0),this.#t=new Array(e).fill(void 0),this.#a=new O(e),this.#u=new O(e),this.#l=0,this.#h=0,this.#b=W.create(e),this.#n=0,this.#_=0,typeof a=="function"&&(this.#w=a),typeof w=="function"&&(this.#C=w),typeof f=="function"?(this.#S=f,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#w,this.#I=!!this.#C,this.#f=!!this.#S,this.noDisposeOnSet=!!d,this.noUpdateTTL=!!g,this.noDeleteOnFetchRejection=!!b,this.allowStaleOnFetchRejection=!!u,this.allowStaleOnFetchAbort=!!T,this.ignoreFetchAbort=!!F,this.maxEntrySize!==0){if(this.#c!==0&&!y(this.#c))throw new TypeError("maxSize must be a positive integer if specified");if(!y(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#B()}if(this.allowStale=!!r,this.noDeleteOnStaleGet=!!m,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!h,this.ttlResolution=y(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!y(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#j()}if(this.#o===0&&this.ttl===0&&this.#c===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#c){let E="LRU_CACHE_UNBOUNDED";x(E)&&(U.add(E),I("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",E,c))}}getRemainingTTL(t){return this.#s.has(t)?1/0:0}#j(){let t=new z(this.#o),e=new z(this.#o);this.#d=t,this.#A=e;let i=this.ttlAutopurge?new Array(this.#o):void 0;this.#g=i,this.#N=(h,r,a=this.#m.now())=>{e[h]=r!==0?a:0,t[h]=r,s(h,r)},this.#R=h=>{e[h]=t[h]!==0?this.#m.now():0,s(h,t[h])};let s=this.ttlAutopurge?(h,r)=>{if(i?.[h]&&(clearTimeout(i[h]),i[h]=void 0),r&&r!==0&&i){let a=setTimeout(()=>{this.#p(h)&&this.#E(this.#i[h],"expire")},r+1);a.unref&&a.unref(),i[h]=a}}:()=>{};this.#z=(h,r)=>{if(t[r]){let a=t[r],w=e[r];if(!a||!w)return;h.ttl=a,h.start=w,h.now=n||o();let f=h.now-w;h.remainingTTL=a-f}};let n=0,o=()=>{let h=this.#m.now();if(this.ttlResolution>0){n=h;let r=setTimeout(()=>n=0,this.ttlResolution);r.unref&&r.unref()}return h};this.getRemainingTTL=h=>{let r=this.#s.get(h);if(r===void 0)return 0;let a=t[r],w=e[r];if(!a||!w)return 1/0;let f=(n||o())-w;return a-f},this.#p=h=>{let r=e[h],a=t[h];return!!a&&!!r&&(n||o())-r>a}}#R=()=>{};#z=()=>{};#N=()=>{};#p=()=>!1;#B(){let t=new z(this.#o);this.#_=0,this.#y=t,this.#W=e=>{this.#_-=t[e],t[e]=0},this.#P=(e,i,s,n)=>{if(this.#e(i))return 0;if(!y(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,e),!y(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#M=(e,i,s)=>{if(t[e]=i,this.#c){let n=this.#c-t[e];for(;this.#_>n;)this.#G(!0)}this.#_+=t[e],s&&(s.entrySize=i,s.totalCalculatedSize=this.#_)}}#W=t=>{};#M=(t,e,i)=>{};#P=(t,e,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#F({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#h;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#l));)e=this.#u[e]}*#O({allowStale:t=this.allowStale}={}){if(this.#n)for(let e=this.#l;!(!this.#H(e)||((t||!this.#p(e))&&(yield e),e===this.#h));)e=this.#a[e]}#H(t){return t!==void 0&&this.#s.get(this.#i[t])===t}*entries(){for(let t of this.#F())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*rentries(){for(let t of this.#O())this.#t[t]!==void 0&&this.#i[t]!==void 0&&!this.#e(this.#t[t])&&(yield[this.#i[t],this.#t[t]])}*keys(){for(let t of this.#F()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*rkeys(){for(let t of this.#O()){let e=this.#i[t];e!==void 0&&!this.#e(this.#t[t])&&(yield e)}}*values(){for(let t of this.#F())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}*rvalues(){for(let t of this.#O())this.#t[t]!==void 0&&!this.#e(this.#t[t])&&(yield this.#t[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(let i of this.#F()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&t(n,this.#i[i],this))return this.get(this.#i[i],e)}}forEach(t,e=this){for(let i of this.#F()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}rforEach(t,e=this){for(let i of this.#O()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&t.call(e,n,this.#i[i],this)}}purgeStale(){let t=!1;for(let e of this.#O({allowStale:!0}))this.#p(e)&&(this.#E(this.#i[e],"expire"),t=!0);return t}info(t){let e=this.#s.get(t);if(e===void 0)return;let i=this.#t[e],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#A){let o=this.#d[e],h=this.#A[e];if(o&&h){let r=o-(this.#m.now()-h);n.ttl=r,n.start=Date.now()}}return this.#y&&(n.size=this.#y[e]),n}dump(){let t=[];for(let e of this.#F({allowStale:!0})){let i=this.#i[e],s=this.#t[e],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let o={value:n};if(this.#d&&this.#A){o.ttl=this.#d[e];let h=this.#m.now()-this.#A[e];o.start=Math.floor(Date.now()-h)}this.#y&&(o.size=this.#y[e]),t.unshift([i,o])}return t}load(t){this.clear();for(let[e,i]of t){if(i.start){let s=Date.now()-i.start;i.start=this.#m.now()-s}this.set(e,i.value,i)}}set(t,e,i={}){if(e===void 0)return this.delete(t),this;let{ttl:s=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:h=this.sizeCalculation,status:r}=i,{noUpdateTTL:a=this.noUpdateTTL}=i,w=this.#P(t,e,i.size||0,h);if(this.maxEntrySize&&w>this.maxEntrySize)return r&&(r.set="miss",r.maxEntrySizeExceeded=!0),this.#E(t,"set"),this;let f=this.#n===0?void 0:this.#s.get(t);if(f===void 0)f=this.#n===0?this.#h:this.#b.length!==0?this.#b.pop():this.#n===this.#o?this.#G(!1):this.#n,this.#i[f]=t,this.#t[f]=e,this.#s.set(t,f),this.#a[this.#h]=f,this.#u[f]=this.#h,this.#h=f,this.#n++,this.#M(f,w,r),r&&(r.set="add"),a=!1,this.#I&&this.#C?.(e,t,"add");else{this.#D(f);let d=this.#t[f];if(e!==d){if(this.#v&&this.#e(d)){d.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:g}=d;g!==void 0&&!o&&(this.#T&&this.#w?.(g,t,"set"),this.#f&&this.#r?.push([g,t,"set"]))}else o||(this.#T&&this.#w?.(d,t,"set"),this.#f&&this.#r?.push([d,t,"set"]));if(this.#W(f),this.#M(f,w,r),this.#t[f]=e,r){r.set="replace";let g=d&&this.#e(d)?d.__staleWhileFetching:d;g!==void 0&&(r.oldValue=g)}}else r&&(r.set="update");this.#I&&this.onInsert?.(e,t,e===d?"update":"replace")}if(s!==0&&!this.#d&&this.#j(),this.#d&&(a||this.#N(f,s,n),r&&this.#z(r,f)),!o&&this.#f&&this.#r){let d=this.#r,g;for(;g=d?.shift();)this.#S?.(...g)}return this}pop(){try{for(;this.#n;){let t=this.#t[this.#l];if(this.#G(!0),this.#e(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#f&&this.#r){let t=this.#r,e;for(;e=t?.shift();)this.#S?.(...e)}}}#G(t){let e=this.#l,i=this.#i[e],s=this.#t[e];return this.#v&&this.#e(s)?s.__abortController.abort(new Error("evicted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(s,i,"evict"),this.#f&&this.#r?.push([s,i,"evict"])),this.#W(e),this.#g?.[e]&&(clearTimeout(this.#g[e]),this.#g[e]=void 0),t&&(this.#i[e]=void 0,this.#t[e]=void 0,this.#b.push(e)),this.#n===1?(this.#l=this.#h=0,this.#b.length=0):this.#l=this.#a[e],this.#s.delete(i),this.#n--,e}has(t,e={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=e,n=this.#s.get(t);if(n!==void 0){let o=this.#t[n];if(this.#e(o)&&o.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#z(s,n));else return i&&this.#R(n),s&&(s.has="hit",this.#z(s,n)),!0}else s&&(s.has="miss");return!1}peek(t,e={}){let{allowStale:i=this.allowStale}=e,s=this.#s.get(t);if(s===void 0||!i&&this.#p(s))return;let n=this.#t[s];return this.#e(n)?n.__staleWhileFetching:n}#x(t,e,i,s){let n=e===void 0?void 0:this.#t[e];if(this.#e(n))return n;let o=new C,{signal:h}=i;h?.addEventListener("abort",()=>o.abort(h.reason),{signal:o.signal});let r={signal:o.signal,options:i,context:s},a=(p,_=!1)=>{let{aborted:l}=o.signal,S=i.ignoreFetchAbort&&p!==void 0,b=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&p!==void 0);if(i.status&&(l&&!_?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,S&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),l&&!S&&!_)return f(o.signal.reason,b);let m=g,u=this.#t[e];return(u===g||S&&_&&u===void 0)&&(p===void 0?m.__staleWhileFetching!==void 0?this.#t[e]=m.__staleWhileFetching:this.#E(t,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.set(t,p,r.options))),p},w=p=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=p),f(p,!1)),f=(p,_)=>{let{aborted:l}=o.signal,S=l&&i.allowStaleOnFetchAbort,b=S||i.allowStaleOnFetchRejection,m=b||i.noDeleteOnFetchRejection,u=g;if(this.#t[e]===g&&(!m||!_&&u.__staleWhileFetching===void 0?this.#E(t,"fetch"):S||(this.#t[e]=u.__staleWhileFetching)),b)return i.status&&u.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),u.__staleWhileFetching;if(u.__returned===u)throw p},d=(p,_)=>{let l=this.#L?.(t,n,r);l&&l instanceof Promise&&l.then(S=>p(S===void 0?void 0:S),_),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(p(void 0),i.allowStaleOnFetchAbort&&(p=S=>a(S,!0)))})};i.status&&(i.status.fetchDispatched=!0);let g=new Promise(d).then(a,w),A=Object.assign(g,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return e===void 0?(this.set(t,A,{...r.options,status:void 0}),e=this.#s.get(t)):this.#t[e]=A,A}#e(t){if(!this.#v)return!1;let e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof C}async fetch(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:h=this.noDisposeOnSet,size:r=0,sizeCalculation:a=this.sizeCalculation,noUpdateTTL:w=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:A=this.allowStaleOnFetchAbort,context:p,forceRefresh:_=!1,status:l,signal:S}=e;if(!this.#v)return l&&(l.fetch="get"),this.get(t,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:l});let b={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:h,size:r,sizeCalculation:a,noUpdateTTL:w,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:A,ignoreFetchAbort:g,status:l,signal:S},m=this.#s.get(t);if(m===void 0){l&&(l.fetch="miss");let u=this.#x(t,m,b,p);return u.__returned=u}else{let u=this.#t[m];if(this.#e(u)){let E=i&&u.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",E&&(l.returnedStale=!0)),E?u.__staleWhileFetching:u.__returned=u}let T=this.#p(m);if(!_&&!T)return l&&(l.fetch="hit"),this.#D(m),s&&this.#R(m),l&&this.#z(l,m),u;let F=this.#x(t,m,b,p),O=F.__staleWhileFetching!==void 0&&i;return l&&(l.fetch=T?"stale":"refresh",O&&T&&(l.returnedStale=!0)),O?F.__staleWhileFetching:F.__returned=F}}async forceFetch(t,e={}){let i=await this.fetch(t,e);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(t,e={}){let i=this.#U;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,forceRefresh:n,...o}=e,h=this.get(t,o);if(!n&&h!==void 0)return h;let r=i(t,h,{options:o,context:s});return this.set(t,r,o),r}get(t,e={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=e,h=this.#s.get(t);if(h!==void 0){let r=this.#t[h],a=this.#e(r);return o&&this.#z(o,h),this.#p(h)?(o&&(o.get="stale"),a?(o&&i&&r.__staleWhileFetching!==void 0&&(o.returnedStale=!0),i?r.__staleWhileFetching:void 0):(n||this.#E(t,"expire"),o&&i&&(o.returnedStale=!0),i?r:void 0)):(o&&(o.get="hit"),a?r.__staleWhileFetching:(this.#D(h),s&&this.#R(h),r))}else o&&(o.get="miss")}#k(t,e){this.#u[e]=t,this.#a[t]=e}#D(t){t!==this.#h&&(t===this.#l?this.#l=this.#a[t]:this.#k(this.#u[t],this.#a[t]),this.#k(this.#h,t),this.#h=t)}delete(t){return this.#E(t,"delete")}#E(t,e){let i=!1;if(this.#n!==0){let s=this.#s.get(t);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#V(e);else{this.#W(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(n,t,e),this.#f&&this.#r?.push([n,t,e])),this.#s.delete(t),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#u[s];else if(s===this.#l)this.#l=this.#a[s];else{let o=this.#u[s];this.#a[o]=this.#a[s];let h=this.#a[s];this.#u[h]=this.#u[s]}this.#n--,this.#b.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#S?.(...n)}return i}clear(){return this.#V("delete")}#V(t){for(let e of this.#O({allowStale:!0})){let i=this.#t[e];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[e];this.#T&&this.#w?.(i,s,t),this.#f&&this.#r?.push([i,s,t])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#A){this.#d.fill(0),this.#A.fill(0);for(let e of this.#g??[])e!==void 0&&clearTimeout(e);this.#g?.fill(void 0)}if(this.#y&&this.#y.fill(0),this.#l=0,this.#h=0,this.#b.length=0,this.#_=0,this.#n=0,this.#f&&this.#r){let e=this.#r,i;for(;i=e?.shift();)this.#S?.(...i)}}};exports.LRUCache=D;
2
2
  //# sourceMappingURL=index.min.js.map
@@ -1,18 +1,20 @@
1
1
  /**
2
2
  * @module LRUCache
3
3
  */
4
- const perf = typeof performance === 'object' &&
4
+ const defaultPerf = (typeof performance === 'object' &&
5
5
  performance &&
6
- typeof performance.now === 'function'
7
- ? performance
6
+ typeof performance.now === 'function') ?
7
+ performance
8
8
  : Date;
9
9
  const warned = new Set();
10
10
  /* c8 ignore start */
11
- const PROCESS = (typeof process === 'object' && !!process ? process : {});
11
+ const PROCESS = (typeof process === 'object' && !!process ?
12
+ process
13
+ : {});
12
14
  /* c8 ignore start */
13
15
  const emitWarning = (msg, type, code, fn) => {
14
- typeof PROCESS.emitWarning === 'function'
15
- ? PROCESS.emitWarning(msg, type, code, fn)
16
+ typeof PROCESS.emitWarning === 'function' ?
17
+ PROCESS.emitWarning(msg, type, code, fn)
16
18
  : console.error(`[${code}] ${type}: ${msg}`);
17
19
  };
18
20
  let AC = globalThis.AbortController;
@@ -76,16 +78,11 @@ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
76
78
  // zeroes at init time is brutal when you get that big.
77
79
  // But why not be complete?
78
80
  // Maybe in the future, these limits will have expanded.
79
- const getUintArray = (max) => !isPosInt(max)
80
- ? null
81
- : max <= Math.pow(2, 8)
82
- ? Uint8Array
83
- : max <= Math.pow(2, 16)
84
- ? Uint16Array
85
- : max <= Math.pow(2, 32)
86
- ? Uint32Array
87
- : max <= Number.MAX_SAFE_INTEGER
88
- ? ZeroArray
81
+ const getUintArray = (max) => !isPosInt(max) ? null
82
+ : max <= Math.pow(2, 8) ? Uint8Array
83
+ : max <= Math.pow(2, 16) ? Uint16Array
84
+ : max <= Math.pow(2, 32) ? Uint32Array
85
+ : max <= Number.MAX_SAFE_INTEGER ? ZeroArray
89
86
  : null;
90
87
  /* c8 ignore stop */
91
88
  class ZeroArray extends Array {
@@ -144,9 +141,17 @@ export class LRUCache {
144
141
  #max;
145
142
  #maxSize;
146
143
  #dispose;
144
+ #onInsert;
147
145
  #disposeAfter;
148
146
  #fetchMethod;
149
147
  #memoMethod;
148
+ #perf;
149
+ /**
150
+ * {@link LRUCache.OptionsBase.perf}
151
+ */
152
+ get perf() {
153
+ return this.#perf;
154
+ }
150
155
  /**
151
156
  * {@link LRUCache.OptionsBase.ttl}
152
157
  */
@@ -222,9 +227,11 @@ export class LRUCache {
222
227
  #sizes;
223
228
  #starts;
224
229
  #ttls;
230
+ #autopurgeTimers;
225
231
  #hasDispose;
226
232
  #hasFetchMethod;
227
233
  #hasDisposeAfter;
234
+ #hasOnInsert;
228
235
  /**
229
236
  * Do not call this method unless you need to inspect the
230
237
  * inner workings of the cache. If anything returned by this
@@ -239,6 +246,7 @@ export class LRUCache {
239
246
  // properties
240
247
  starts: c.#starts,
241
248
  ttls: c.#ttls,
249
+ autopurgeTimers: c.#autopurgeTimers,
242
250
  sizes: c.#sizes,
243
251
  keyMap: c.#keyMap,
244
252
  keyList: c.#keyList,
@@ -301,6 +309,12 @@ export class LRUCache {
301
309
  get dispose() {
302
310
  return this.#dispose;
303
311
  }
312
+ /**
313
+ * {@link LRUCache.OptionsBase.onInsert} (read-only)
314
+ */
315
+ get onInsert() {
316
+ return this.#onInsert;
317
+ }
304
318
  /**
305
319
  * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
306
320
  */
@@ -308,7 +322,13 @@ export class LRUCache {
308
322
  return this.#disposeAfter;
309
323
  }
310
324
  constructor(options) {
311
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, } = options;
325
+ const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf, } = options;
326
+ if (perf !== undefined) {
327
+ if (typeof perf?.now !== 'function') {
328
+ throw new TypeError('perf option must have a now() method if specified');
329
+ }
330
+ }
331
+ this.#perf = perf ?? defaultPerf;
312
332
  if (max !== 0 && !isPosInt(max)) {
313
333
  throw new TypeError('max option must be a nonnegative integer');
314
334
  }
@@ -328,13 +348,11 @@ export class LRUCache {
328
348
  throw new TypeError('sizeCalculation set to non-function');
329
349
  }
330
350
  }
331
- if (memoMethod !== undefined &&
332
- typeof memoMethod !== 'function') {
351
+ if (memoMethod !== undefined && typeof memoMethod !== 'function') {
333
352
  throw new TypeError('memoMethod must be a function if defined');
334
353
  }
335
354
  this.#memoMethod = memoMethod;
336
- if (fetchMethod !== undefined &&
337
- typeof fetchMethod !== 'function') {
355
+ if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
338
356
  throw new TypeError('fetchMethod must be a function if specified');
339
357
  }
340
358
  this.#fetchMethod = fetchMethod;
@@ -352,6 +370,9 @@ export class LRUCache {
352
370
  if (typeof dispose === 'function') {
353
371
  this.#dispose = dispose;
354
372
  }
373
+ if (typeof onInsert === 'function') {
374
+ this.#onInsert = onInsert;
375
+ }
355
376
  if (typeof disposeAfter === 'function') {
356
377
  this.#disposeAfter = disposeAfter;
357
378
  this.#disposed = [];
@@ -361,6 +382,7 @@ export class LRUCache {
361
382
  this.#disposed = undefined;
362
383
  }
363
384
  this.#hasDispose = !!this.#dispose;
385
+ this.#hasOnInsert = !!this.#onInsert;
364
386
  this.#hasDisposeAfter = !!this.#disposeAfter;
365
387
  this.noDisposeOnSet = !!noDisposeOnSet;
366
388
  this.noUpdateTTL = !!noUpdateTTL;
@@ -385,9 +407,7 @@ export class LRUCache {
385
407
  this.updateAgeOnGet = !!updateAgeOnGet;
386
408
  this.updateAgeOnHas = !!updateAgeOnHas;
387
409
  this.ttlResolution =
388
- isPosInt(ttlResolution) || ttlResolution === 0
389
- ? ttlResolution
390
- : 1;
410
+ isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
391
411
  this.ttlAutopurge = !!ttlAutopurge;
392
412
  this.ttl = ttl || 0;
393
413
  if (this.ttl) {
@@ -422,26 +442,45 @@ export class LRUCache {
422
442
  const starts = new ZeroArray(this.#max);
423
443
  this.#ttls = ttls;
424
444
  this.#starts = starts;
425
- this.#setItemTTL = (index, ttl, start = perf.now()) => {
445
+ const purgeTimers = this.ttlAutopurge ?
446
+ new Array(this.#max)
447
+ : undefined;
448
+ this.#autopurgeTimers = purgeTimers;
449
+ this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
426
450
  starts[index] = ttl !== 0 ? start : 0;
427
451
  ttls[index] = ttl;
428
- if (ttl !== 0 && this.ttlAutopurge) {
429
- const t = setTimeout(() => {
430
- if (this.#isStale(index)) {
431
- this.#delete(this.#keyList[index], 'expire');
432
- }
433
- }, ttl + 1);
434
- // unref() not supported on all platforms
435
- /* c8 ignore start */
436
- if (t.unref) {
437
- t.unref();
438
- }
439
- /* c8 ignore stop */
440
- }
452
+ setPurgetTimer(index, ttl);
441
453
  };
442
454
  this.#updateItemAge = index => {
443
- starts[index] = ttls[index] !== 0 ? perf.now() : 0;
455
+ starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
456
+ setPurgetTimer(index, ttls[index]);
444
457
  };
458
+ // clear out the purge timer if we're setting TTL to 0, and
459
+ // previously had a ttl purge timer running, so it doesn't
460
+ // fire unnecessarily. Don't need to do this if we're not doing
461
+ // autopurge.
462
+ const setPurgetTimer = !this.ttlAutopurge ?
463
+ () => { }
464
+ : (index, ttl) => {
465
+ if (purgeTimers?.[index]) {
466
+ clearTimeout(purgeTimers[index]);
467
+ purgeTimers[index] = undefined;
468
+ }
469
+ if (ttl && ttl !== 0 && purgeTimers) {
470
+ const t = setTimeout(() => {
471
+ if (this.#isStale(index)) {
472
+ this.#delete(this.#keyList[index], 'expire');
473
+ }
474
+ }, ttl + 1);
475
+ // unref() not supported on all platforms
476
+ /* c8 ignore start */
477
+ if (t.unref) {
478
+ t.unref();
479
+ }
480
+ /* c8 ignore stop */
481
+ purgeTimers[index] = t;
482
+ }
483
+ };
445
484
  this.#statusTTL = (status, index) => {
446
485
  if (ttls[index]) {
447
486
  const ttl = ttls[index];
@@ -460,7 +499,7 @@ export class LRUCache {
460
499
  // that costly call repeatedly.
461
500
  let cachedNow = 0;
462
501
  const getNow = () => {
463
- const n = perf.now();
502
+ const n = this.#perf.now();
464
503
  if (this.ttlResolution > 0) {
465
504
  cachedNow = n;
466
505
  const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
@@ -628,8 +667,7 @@ export class LRUCache {
628
667
  *keys() {
629
668
  for (const i of this.#indexes()) {
630
669
  const k = this.#keyList[i];
631
- if (k !== undefined &&
632
- !this.#isBackgroundFetch(this.#valList[i])) {
670
+ if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
633
671
  yield k;
634
672
  }
635
673
  }
@@ -643,8 +681,7 @@ export class LRUCache {
643
681
  *rkeys() {
644
682
  for (const i of this.#rindexes()) {
645
683
  const k = this.#keyList[i];
646
- if (k !== undefined &&
647
- !this.#isBackgroundFetch(this.#valList[i])) {
684
+ if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
648
685
  yield k;
649
686
  }
650
687
  }
@@ -656,8 +693,7 @@ export class LRUCache {
656
693
  *values() {
657
694
  for (const i of this.#indexes()) {
658
695
  const v = this.#valList[i];
659
- if (v !== undefined &&
660
- !this.#isBackgroundFetch(this.#valList[i])) {
696
+ if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
661
697
  yield this.#valList[i];
662
698
  }
663
699
  }
@@ -671,8 +707,7 @@ export class LRUCache {
671
707
  *rvalues() {
672
708
  for (const i of this.#rindexes()) {
673
709
  const v = this.#valList[i];
674
- if (v !== undefined &&
675
- !this.#isBackgroundFetch(this.#valList[i])) {
710
+ if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
676
711
  yield this.#valList[i];
677
712
  }
678
713
  }
@@ -697,9 +732,7 @@ export class LRUCache {
697
732
  find(fn, getOptions = {}) {
698
733
  for (const i of this.#indexes()) {
699
734
  const v = this.#valList[i];
700
- const value = this.#isBackgroundFetch(v)
701
- ? v.__staleWhileFetching
702
- : v;
735
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
703
736
  if (value === undefined)
704
737
  continue;
705
738
  if (fn(value, this.#keyList[i], this)) {
@@ -721,9 +754,7 @@ export class LRUCache {
721
754
  forEach(fn, thisp = this) {
722
755
  for (const i of this.#indexes()) {
723
756
  const v = this.#valList[i];
724
- const value = this.#isBackgroundFetch(v)
725
- ? v.__staleWhileFetching
726
- : v;
757
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
727
758
  if (value === undefined)
728
759
  continue;
729
760
  fn.call(thisp, value, this.#keyList[i], this);
@@ -736,9 +767,7 @@ export class LRUCache {
736
767
  rforEach(fn, thisp = this) {
737
768
  for (const i of this.#rindexes()) {
738
769
  const v = this.#valList[i];
739
- const value = this.#isBackgroundFetch(v)
740
- ? v.__staleWhileFetching
741
- : v;
770
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
742
771
  if (value === undefined)
743
772
  continue;
744
773
  fn.call(thisp, value, this.#keyList[i], this);
@@ -775,17 +804,18 @@ export class LRUCache {
775
804
  if (i === undefined)
776
805
  return undefined;
777
806
  const v = this.#valList[i];
778
- const value = this.#isBackgroundFetch(v)
779
- ? v.__staleWhileFetching
780
- : v;
807
+ /* c8 ignore start - this isn't tested for the info function,
808
+ * but it's the same logic as found in other places. */
809
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
781
810
  if (value === undefined)
782
811
  return undefined;
812
+ /* c8 ignore end */
783
813
  const entry = { value };
784
814
  if (this.#ttls && this.#starts) {
785
815
  const ttl = this.#ttls[i];
786
816
  const start = this.#starts[i];
787
817
  if (ttl && start) {
788
- const remain = ttl - (perf.now() - start);
818
+ const remain = ttl - (this.#perf.now() - start);
789
819
  entry.ttl = remain;
790
820
  entry.start = Date.now();
791
821
  }
@@ -797,7 +827,7 @@ export class LRUCache {
797
827
  }
798
828
  /**
799
829
  * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
800
- * passed to {@link LRLUCache#load}.
830
+ * passed to {@link LRUCache#load}.
801
831
  *
802
832
  * The `start` fields are calculated relative to a portable `Date.now()`
803
833
  * timestamp, even if `performance.now()` is available.
@@ -813,9 +843,7 @@ export class LRUCache {
813
843
  for (const i of this.#indexes({ allowStale: true })) {
814
844
  const key = this.#keyList[i];
815
845
  const v = this.#valList[i];
816
- const value = this.#isBackgroundFetch(v)
817
- ? v.__staleWhileFetching
818
- : v;
846
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
819
847
  if (value === undefined || key === undefined)
820
848
  continue;
821
849
  const entry = { value };
@@ -823,7 +851,7 @@ export class LRUCache {
823
851
  entry.ttl = this.#ttls[i];
824
852
  // always dump the start relative to a portable timestamp
825
853
  // it's ok for this to be a bit slow, it's a rare operation.
826
- const age = perf.now() - this.#starts[i];
854
+ const age = this.#perf.now() - this.#starts[i];
827
855
  entry.start = Math.floor(Date.now() - age);
828
856
  }
829
857
  if (this.#sizes) {
@@ -853,7 +881,7 @@ export class LRUCache {
853
881
  //
854
882
  // it's ok for this to be a bit slow, it's a rare operation.
855
883
  const age = Date.now() - entry.start;
856
- entry.start = perf.now() - age;
884
+ entry.start = this.#perf.now() - age;
857
885
  }
858
886
  this.set(key, entry.value, entry);
859
887
  }
@@ -910,12 +938,9 @@ export class LRUCache {
910
938
  let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
911
939
  if (index === undefined) {
912
940
  // addition
913
- index = (this.#size === 0
914
- ? this.#tail
915
- : this.#free.length !== 0
916
- ? this.#free.pop()
917
- : this.#size === this.#max
918
- ? this.#evict(false)
941
+ index = (this.#size === 0 ? this.#tail
942
+ : this.#free.length !== 0 ? this.#free.pop()
943
+ : this.#size === this.#max ? this.#evict(false)
919
944
  : this.#size);
920
945
  this.#keyList[index] = k;
921
946
  this.#valList[index] = v;
@@ -928,6 +953,9 @@ export class LRUCache {
928
953
  if (status)
929
954
  status.set = 'add';
930
955
  noUpdateTTL = false;
956
+ if (this.#hasOnInsert) {
957
+ this.#onInsert?.(v, k, 'add');
958
+ }
931
959
  }
932
960
  else {
933
961
  // update
@@ -959,8 +987,8 @@ export class LRUCache {
959
987
  this.#valList[index] = v;
960
988
  if (status) {
961
989
  status.set = 'replace';
962
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal)
963
- ? oldVal.__staleWhileFetching
990
+ const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ?
991
+ oldVal.__staleWhileFetching
964
992
  : oldVal;
965
993
  if (oldValue !== undefined)
966
994
  status.oldValue = oldValue;
@@ -969,6 +997,9 @@ export class LRUCache {
969
997
  else if (status) {
970
998
  status.set = 'update';
971
999
  }
1000
+ if (this.#hasOnInsert) {
1001
+ this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace');
1002
+ }
972
1003
  }
973
1004
  if (ttl !== 0 && !this.#ttls) {
974
1005
  this.#initializeTTLTracking();
@@ -1034,6 +1065,10 @@ export class LRUCache {
1034
1065
  }
1035
1066
  }
1036
1067
  this.#removeItemSize(head);
1068
+ if (this.#autopurgeTimers?.[head]) {
1069
+ clearTimeout(this.#autopurgeTimers[head]);
1070
+ this.#autopurgeTimers[head] = undefined;
1071
+ }
1037
1072
  // if we aren't about to use the index, then null these out
1038
1073
  if (free) {
1039
1074
  this.#keyList[head] = undefined;
@@ -1106,8 +1141,7 @@ export class LRUCache {
1106
1141
  peek(k, peekOptions = {}) {
1107
1142
  const { allowStale = this.allowStale } = peekOptions;
1108
1143
  const index = this.#keyMap.get(k);
1109
- if (index === undefined ||
1110
- (!allowStale && this.#isStale(index))) {
1144
+ if (index === undefined || (!allowStale && this.#isStale(index))) {
1111
1145
  return;
1112
1146
  }
1113
1147
  const v = this.#valList[index];
@@ -1133,6 +1167,8 @@ export class LRUCache {
1133
1167
  const cb = (v, updateCache = false) => {
1134
1168
  const { aborted } = ac.signal;
1135
1169
  const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
1170
+ const proceed = options.ignoreFetchAbort ||
1171
+ !!(options.allowStaleOnFetchAbort && v !== undefined);
1136
1172
  if (options.status) {
1137
1173
  if (aborted && !updateCache) {
1138
1174
  options.status.fetchAborted = true;
@@ -1145,13 +1181,17 @@ export class LRUCache {
1145
1181
  }
1146
1182
  }
1147
1183
  if (aborted && !ignoreAbort && !updateCache) {
1148
- return fetchFail(ac.signal.reason);
1184
+ return fetchFail(ac.signal.reason, proceed);
1149
1185
  }
1150
1186
  // either we didn't abort, and are still here, or we did, and ignored
1151
1187
  const bf = p;
1152
- if (this.#valList[index] === p) {
1188
+ // if nothing else has been written there but we're set to update the
1189
+ // cache and ignore the abort, or if it's still pending on this specific
1190
+ // background request, then write it to the cache.
1191
+ const vl = this.#valList[index];
1192
+ if (vl === p || (ignoreAbort && updateCache && vl === undefined)) {
1153
1193
  if (v === undefined) {
1154
- if (bf.__staleWhileFetching) {
1194
+ if (bf.__staleWhileFetching !== undefined) {
1155
1195
  this.#valList[index] = bf.__staleWhileFetching;
1156
1196
  }
1157
1197
  else {
@@ -1171,9 +1211,10 @@ export class LRUCache {
1171
1211
  options.status.fetchRejected = true;
1172
1212
  options.status.fetchError = er;
1173
1213
  }
1174
- return fetchFail(er);
1214
+ // do not pass go, do not collect $200
1215
+ return fetchFail(er, false);
1175
1216
  };
1176
- const fetchFail = (er) => {
1217
+ const fetchFail = (er, proceed) => {
1177
1218
  const { aborted } = ac.signal;
1178
1219
  const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
1179
1220
  const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
@@ -1182,7 +1223,7 @@ export class LRUCache {
1182
1223
  if (this.#valList[index] === p) {
1183
1224
  // if we allow stale on fetch rejections, then we need to ensure that
1184
1225
  // the stale value is not removed from the cache when the fetch fails.
1185
- const del = !noDelete || bf.__staleWhileFetching === undefined;
1226
+ const del = !noDelete || (!proceed && bf.__staleWhileFetching === undefined);
1186
1227
  if (del) {
1187
1228
  this.#delete(k, 'fetch');
1188
1229
  }
@@ -1213,8 +1254,7 @@ export class LRUCache {
1213
1254
  // defer check until we are actually aborting,
1214
1255
  // so fetchMethod can override.
1215
1256
  ac.signal.addEventListener('abort', () => {
1216
- if (!options.ignoreFetchAbort ||
1217
- options.allowStaleOnFetchAbort) {
1257
+ if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
1218
1258
  res(undefined);
1219
1259
  // when it eventually resolves, update the cache.
1220
1260
  if (options.allowStaleOnFetchAbort) {
@@ -1446,6 +1486,10 @@ export class LRUCache {
1446
1486
  if (this.#size !== 0) {
1447
1487
  const index = this.#keyMap.get(k);
1448
1488
  if (index !== undefined) {
1489
+ if (this.#autopurgeTimers?.[index]) {
1490
+ clearTimeout(this.#autopurgeTimers?.[index]);
1491
+ this.#autopurgeTimers[index] = undefined;
1492
+ }
1449
1493
  deleted = true;
1450
1494
  if (this.#size === 1) {
1451
1495
  this.#clear(reason);
@@ -1521,6 +1565,11 @@ export class LRUCache {
1521
1565
  if (this.#ttls && this.#starts) {
1522
1566
  this.#ttls.fill(0);
1523
1567
  this.#starts.fill(0);
1568
+ for (const t of this.#autopurgeTimers ?? []) {
1569
+ if (t !== undefined)
1570
+ clearTimeout(t);
1571
+ }
1572
+ this.#autopurgeTimers?.fill(undefined);
1524
1573
  }
1525
1574
  if (this.#sizes) {
1526
1575
  this.#sizes.fill(0);