@pnpm/exe 11.0.6 → 11.0.8

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 (381) hide show
  1. package/dist/node-gyp-bin/node-gyp +0 -0
  2. package/dist/node-gyp-bin/node-gyp.cmd +0 -0
  3. package/dist/node_modules/node-gyp/.release-please-manifest.json +1 -1
  4. package/dist/node_modules/node-gyp/bin/node-gyp.js +0 -0
  5. package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +1 -1
  6. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +11 -3
  7. package/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +2 -3
  8. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +1 -1
  9. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2 -1
  10. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +26 -16
  11. package/dist/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +1 -1
  12. package/dist/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1 -1
  13. package/dist/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +2 -2
  14. package/dist/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +3 -20
  15. package/dist/node_modules/node-gyp/gyp/pylib/packaging/tags.py +2 -14
  16. package/dist/node_modules/node-gyp/gyp/pyproject.toml +5 -3
  17. package/dist/node_modules/node-gyp/lib/download.js +55 -8
  18. package/dist/node_modules/node-gyp/lib/find-visualstudio.js +1 -1
  19. package/dist/node_modules/node-gyp/lib/process-release.js +17 -19
  20. package/dist/node_modules/node-gyp/package.json +3 -3
  21. package/dist/node_modules/{safer-buffer → undici}/LICENSE +1 -1
  22. package/dist/node_modules/undici/index-fetch.js +35 -0
  23. package/dist/node_modules/undici/index.js +169 -0
  24. package/dist/node_modules/undici/lib/api/abort-signal.js +57 -0
  25. package/dist/node_modules/undici/lib/api/api-connect.js +108 -0
  26. package/dist/node_modules/undici/lib/api/api-pipeline.js +251 -0
  27. package/dist/node_modules/undici/lib/api/api-request.js +214 -0
  28. package/dist/node_modules/undici/lib/api/api-stream.js +220 -0
  29. package/dist/node_modules/undici/lib/api/api-upgrade.js +108 -0
  30. package/dist/node_modules/undici/lib/api/index.js +7 -0
  31. package/dist/node_modules/undici/lib/api/readable.js +385 -0
  32. package/dist/node_modules/undici/lib/api/util.js +93 -0
  33. package/dist/node_modules/undici/lib/core/connect.js +240 -0
  34. package/dist/node_modules/undici/lib/core/constants.js +118 -0
  35. package/dist/node_modules/undici/lib/core/diagnostics.js +202 -0
  36. package/dist/node_modules/undici/lib/core/errors.js +425 -0
  37. package/dist/node_modules/undici/lib/core/request.js +405 -0
  38. package/dist/node_modules/undici/lib/core/symbols.js +67 -0
  39. package/dist/node_modules/undici/lib/core/tree.js +152 -0
  40. package/dist/node_modules/undici/lib/core/util.js +719 -0
  41. package/dist/node_modules/undici/lib/dispatcher/agent.js +130 -0
  42. package/dist/node_modules/undici/lib/dispatcher/balanced-pool.js +209 -0
  43. package/dist/node_modules/undici/lib/dispatcher/client-h1.js +1370 -0
  44. package/dist/node_modules/undici/lib/dispatcher/client-h2.js +744 -0
  45. package/dist/node_modules/undici/lib/dispatcher/client.js +623 -0
  46. package/dist/node_modules/undici/lib/dispatcher/dispatcher-base.js +198 -0
  47. package/dist/node_modules/undici/lib/dispatcher/dispatcher.js +65 -0
  48. package/dist/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +160 -0
  49. package/dist/node_modules/undici/lib/dispatcher/fixed-queue.js +117 -0
  50. package/dist/node_modules/undici/lib/dispatcher/pool-base.js +194 -0
  51. package/dist/node_modules/undici/lib/dispatcher/pool-stats.js +34 -0
  52. package/dist/node_modules/undici/lib/dispatcher/pool.js +107 -0
  53. package/dist/node_modules/undici/lib/dispatcher/proxy-agent.js +274 -0
  54. package/dist/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  55. package/dist/node_modules/undici/lib/global.js +32 -0
  56. package/dist/node_modules/undici/lib/handler/decorator-handler.js +44 -0
  57. package/dist/node_modules/undici/lib/handler/redirect-handler.js +232 -0
  58. package/dist/node_modules/undici/lib/handler/retry-handler.js +374 -0
  59. package/dist/node_modules/undici/lib/interceptor/dns.js +375 -0
  60. package/dist/node_modules/undici/lib/interceptor/dump.js +123 -0
  61. package/dist/node_modules/undici/lib/interceptor/redirect-interceptor.js +21 -0
  62. package/dist/node_modules/undici/lib/interceptor/redirect.js +24 -0
  63. package/dist/node_modules/undici/lib/interceptor/response-error.js +86 -0
  64. package/dist/node_modules/undici/lib/interceptor/retry.js +19 -0
  65. package/dist/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  66. package/dist/node_modules/undici/lib/llhttp/constants.js +278 -0
  67. package/dist/node_modules/undici/lib/llhttp/llhttp-wasm.js +5 -0
  68. package/dist/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +5 -0
  69. package/dist/node_modules/undici/lib/llhttp/utils.js +15 -0
  70. package/dist/node_modules/undici/lib/mock/mock-agent.js +160 -0
  71. package/dist/node_modules/undici/lib/mock/mock-client.js +59 -0
  72. package/dist/node_modules/undici/lib/mock/mock-errors.js +28 -0
  73. package/dist/node_modules/undici/lib/mock/mock-interceptor.js +207 -0
  74. package/dist/node_modules/undici/lib/mock/mock-pool.js +59 -0
  75. package/dist/node_modules/undici/lib/mock/mock-symbols.js +23 -0
  76. package/dist/node_modules/undici/lib/mock/mock-utils.js +367 -0
  77. package/dist/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  78. package/dist/node_modules/undici/lib/mock/pluralizer.js +29 -0
  79. package/dist/node_modules/undici/lib/util/timers.js +423 -0
  80. package/dist/node_modules/undici/lib/web/cache/cache.js +859 -0
  81. package/dist/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  82. package/dist/node_modules/undici/lib/web/cache/symbols.js +5 -0
  83. package/dist/node_modules/undici/lib/web/cache/util.js +45 -0
  84. package/dist/node_modules/undici/lib/web/cookies/constants.js +12 -0
  85. package/dist/node_modules/undici/lib/web/cookies/index.js +184 -0
  86. package/dist/node_modules/undici/lib/web/cookies/parse.js +317 -0
  87. package/dist/node_modules/undici/lib/web/cookies/util.js +282 -0
  88. package/dist/node_modules/undici/lib/web/eventsource/eventsource-stream.js +398 -0
  89. package/dist/node_modules/undici/lib/web/eventsource/eventsource.js +480 -0
  90. package/dist/node_modules/undici/lib/web/eventsource/util.js +37 -0
  91. package/dist/node_modules/{@npmcli/redact → undici/lib/web/fetch}/LICENSE +1 -1
  92. package/dist/node_modules/undici/lib/web/fetch/body.js +529 -0
  93. package/dist/node_modules/undici/lib/web/fetch/constants.js +124 -0
  94. package/dist/node_modules/undici/lib/web/fetch/data-url.js +744 -0
  95. package/dist/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
  96. package/dist/node_modules/undici/lib/web/fetch/file.js +126 -0
  97. package/dist/node_modules/undici/lib/web/fetch/formdata-parser.js +474 -0
  98. package/dist/node_modules/undici/lib/web/fetch/formdata.js +252 -0
  99. package/dist/node_modules/undici/lib/web/fetch/global.js +40 -0
  100. package/dist/node_modules/undici/lib/web/fetch/headers.js +687 -0
  101. package/dist/node_modules/undici/lib/web/fetch/index.js +2272 -0
  102. package/dist/node_modules/undici/lib/web/fetch/request.js +1037 -0
  103. package/dist/node_modules/undici/lib/web/fetch/response.js +610 -0
  104. package/dist/node_modules/undici/lib/web/fetch/symbols.js +9 -0
  105. package/dist/node_modules/undici/lib/web/fetch/util.js +1632 -0
  106. package/dist/node_modules/undici/lib/web/fetch/webidl.js +695 -0
  107. package/dist/node_modules/undici/lib/web/fileapi/encoding.js +290 -0
  108. package/dist/node_modules/undici/lib/web/fileapi/filereader.js +344 -0
  109. package/dist/node_modules/undici/lib/web/fileapi/progressevent.js +78 -0
  110. package/dist/node_modules/undici/lib/web/fileapi/symbols.js +10 -0
  111. package/dist/node_modules/undici/lib/web/fileapi/util.js +391 -0
  112. package/dist/node_modules/undici/lib/web/websocket/connection.js +371 -0
  113. package/dist/node_modules/undici/lib/web/websocket/constants.js +66 -0
  114. package/dist/node_modules/undici/lib/web/websocket/events.js +329 -0
  115. package/dist/node_modules/undici/lib/web/websocket/frame.js +96 -0
  116. package/dist/node_modules/undici/lib/web/websocket/permessage-deflate.js +100 -0
  117. package/dist/node_modules/undici/lib/web/websocket/receiver.js +490 -0
  118. package/dist/node_modules/undici/lib/web/websocket/sender.js +104 -0
  119. package/dist/node_modules/undici/lib/web/websocket/symbols.js +12 -0
  120. package/dist/node_modules/undici/lib/web/websocket/util.js +322 -0
  121. package/dist/node_modules/undici/lib/web/websocket/websocket.js +592 -0
  122. package/dist/node_modules/undici/package.json +160 -0
  123. package/dist/node_modules/undici/scripts/strip-comments.js +8 -0
  124. package/dist/node_modules/yallist/package.json +51 -12
  125. package/dist/pnpm.mjs +4529 -3898
  126. package/dist/worker.js +76 -73
  127. package/package.json +21 -13
  128. package/setup.js +17 -3
  129. package/dist/node_modules/@gar/promise-retry/LICENSE +0 -20
  130. package/dist/node_modules/@gar/promise-retry/lib/index.js +0 -62
  131. package/dist/node_modules/@gar/promise-retry/lib/retry.js +0 -109
  132. package/dist/node_modules/@gar/promise-retry/package.json +0 -45
  133. package/dist/node_modules/@npmcli/agent/lib/agents.js +0 -206
  134. package/dist/node_modules/@npmcli/agent/lib/dns.js +0 -53
  135. package/dist/node_modules/@npmcli/agent/lib/errors.js +0 -61
  136. package/dist/node_modules/@npmcli/agent/lib/index.js +0 -56
  137. package/dist/node_modules/@npmcli/agent/lib/options.js +0 -86
  138. package/dist/node_modules/@npmcli/agent/lib/proxy.js +0 -88
  139. package/dist/node_modules/@npmcli/agent/package.json +0 -60
  140. package/dist/node_modules/@npmcli/fs/lib/common/get-options.js +0 -20
  141. package/dist/node_modules/@npmcli/fs/lib/common/node.js +0 -9
  142. package/dist/node_modules/@npmcli/fs/lib/cp/LICENSE +0 -15
  143. package/dist/node_modules/@npmcli/fs/lib/cp/errors.js +0 -129
  144. package/dist/node_modules/@npmcli/fs/lib/cp/index.js +0 -22
  145. package/dist/node_modules/@npmcli/fs/lib/cp/polyfill.js +0 -428
  146. package/dist/node_modules/@npmcli/fs/lib/index.js +0 -13
  147. package/dist/node_modules/@npmcli/fs/lib/move-file.js +0 -78
  148. package/dist/node_modules/@npmcli/fs/lib/readdir-scoped.js +0 -20
  149. package/dist/node_modules/@npmcli/fs/lib/with-temp-dir.js +0 -39
  150. package/dist/node_modules/@npmcli/fs/package.json +0 -54
  151. package/dist/node_modules/@npmcli/redact/lib/deep-map.js +0 -71
  152. package/dist/node_modules/@npmcli/redact/lib/error.js +0 -28
  153. package/dist/node_modules/@npmcli/redact/lib/index.js +0 -44
  154. package/dist/node_modules/@npmcli/redact/lib/matchers.js +0 -88
  155. package/dist/node_modules/@npmcli/redact/lib/server.js +0 -59
  156. package/dist/node_modules/@npmcli/redact/lib/utils.js +0 -202
  157. package/dist/node_modules/@npmcli/redact/package.json +0 -52
  158. package/dist/node_modules/agent-base/LICENSE +0 -22
  159. package/dist/node_modules/agent-base/dist/helpers.js +0 -66
  160. package/dist/node_modules/agent-base/dist/index.js +0 -178
  161. package/dist/node_modules/agent-base/package.json +0 -46
  162. package/dist/node_modules/balanced-match/dist/commonjs/index.js +0 -59
  163. package/dist/node_modules/balanced-match/dist/esm/index.js +0 -54
  164. package/dist/node_modules/balanced-match/package.json +0 -68
  165. package/dist/node_modules/brace-expansion/LICENSE +0 -23
  166. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +0 -201
  167. package/dist/node_modules/brace-expansion/dist/commonjs/package.json +0 -3
  168. package/dist/node_modules/brace-expansion/dist/esm/index.js +0 -197
  169. package/dist/node_modules/brace-expansion/dist/esm/package.json +0 -3
  170. package/dist/node_modules/brace-expansion/package.json +0 -64
  171. package/dist/node_modules/cacache/lib/content/path.js +0 -29
  172. package/dist/node_modules/cacache/lib/content/read.js +0 -165
  173. package/dist/node_modules/cacache/lib/content/rm.js +0 -18
  174. package/dist/node_modules/cacache/lib/content/write.js +0 -206
  175. package/dist/node_modules/cacache/lib/entry-index.js +0 -336
  176. package/dist/node_modules/cacache/lib/get.js +0 -170
  177. package/dist/node_modules/cacache/lib/index.js +0 -42
  178. package/dist/node_modules/cacache/lib/memoization.js +0 -72
  179. package/dist/node_modules/cacache/lib/put.js +0 -80
  180. package/dist/node_modules/cacache/lib/rm.js +0 -31
  181. package/dist/node_modules/cacache/lib/util/glob.js +0 -7
  182. package/dist/node_modules/cacache/lib/util/hash-to-segments.js +0 -7
  183. package/dist/node_modules/cacache/lib/util/tmp.js +0 -32
  184. package/dist/node_modules/cacache/lib/verify.js +0 -258
  185. package/dist/node_modules/cacache/package.json +0 -81
  186. package/dist/node_modules/debug/LICENSE +0 -20
  187. package/dist/node_modules/debug/package.json +0 -64
  188. package/dist/node_modules/debug/src/browser.js +0 -272
  189. package/dist/node_modules/debug/src/common.js +0 -292
  190. package/dist/node_modules/debug/src/index.js +0 -10
  191. package/dist/node_modules/debug/src/node.js +0 -263
  192. package/dist/node_modules/fs-minipass/LICENSE +0 -15
  193. package/dist/node_modules/fs-minipass/lib/index.js +0 -443
  194. package/dist/node_modules/fs-minipass/package.json +0 -54
  195. package/dist/node_modules/glob/dist/commonjs/glob.js +0 -248
  196. package/dist/node_modules/glob/dist/commonjs/has-magic.js +0 -27
  197. package/dist/node_modules/glob/dist/commonjs/ignore.js +0 -119
  198. package/dist/node_modules/glob/dist/commonjs/index.js +0 -68
  199. package/dist/node_modules/glob/dist/commonjs/index.min.js +0 -4
  200. package/dist/node_modules/glob/dist/commonjs/package.json +0 -3
  201. package/dist/node_modules/glob/dist/commonjs/pattern.js +0 -223
  202. package/dist/node_modules/glob/dist/commonjs/processor.js +0 -301
  203. package/dist/node_modules/glob/dist/commonjs/walker.js +0 -387
  204. package/dist/node_modules/glob/dist/esm/glob.js +0 -244
  205. package/dist/node_modules/glob/dist/esm/has-magic.js +0 -23
  206. package/dist/node_modules/glob/dist/esm/ignore.js +0 -115
  207. package/dist/node_modules/glob/dist/esm/index.js +0 -55
  208. package/dist/node_modules/glob/dist/esm/index.min.js +0 -4
  209. package/dist/node_modules/glob/dist/esm/package.json +0 -3
  210. package/dist/node_modules/glob/dist/esm/pattern.js +0 -219
  211. package/dist/node_modules/glob/dist/esm/processor.js +0 -294
  212. package/dist/node_modules/glob/dist/esm/walker.js +0 -381
  213. package/dist/node_modules/glob/package.json +0 -98
  214. package/dist/node_modules/http-cache-semantics/LICENSE +0 -9
  215. package/dist/node_modules/http-cache-semantics/index.js +0 -928
  216. package/dist/node_modules/http-cache-semantics/package.json +0 -22
  217. package/dist/node_modules/http-proxy-agent/LICENSE +0 -22
  218. package/dist/node_modules/http-proxy-agent/dist/index.js +0 -148
  219. package/dist/node_modules/http-proxy-agent/package.json +0 -47
  220. package/dist/node_modules/https-proxy-agent/LICENSE +0 -22
  221. package/dist/node_modules/https-proxy-agent/dist/index.js +0 -180
  222. package/dist/node_modules/https-proxy-agent/dist/parse-proxy-response.js +0 -101
  223. package/dist/node_modules/https-proxy-agent/package.json +0 -50
  224. package/dist/node_modules/iconv-lite/LICENSE +0 -21
  225. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -532
  226. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +0 -185
  227. package/dist/node_modules/iconv-lite/encodings/index.js +0 -23
  228. package/dist/node_modules/iconv-lite/encodings/internal.js +0 -218
  229. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -75
  230. package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
  231. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +0 -178
  232. package/dist/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
  233. package/dist/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
  234. package/dist/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
  235. package/dist/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
  236. package/dist/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
  237. package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
  238. package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
  239. package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
  240. package/dist/node_modules/iconv-lite/encodings/utf16.js +0 -187
  241. package/dist/node_modules/iconv-lite/encodings/utf32.js +0 -307
  242. package/dist/node_modules/iconv-lite/encodings/utf7.js +0 -283
  243. package/dist/node_modules/iconv-lite/lib/bom-handling.js +0 -48
  244. package/dist/node_modules/iconv-lite/lib/helpers/merge-exports.js +0 -13
  245. package/dist/node_modules/iconv-lite/lib/index.js +0 -182
  246. package/dist/node_modules/iconv-lite/lib/streams.js +0 -105
  247. package/dist/node_modules/iconv-lite/package.json +0 -70
  248. package/dist/node_modules/ip-address/LICENSE +0 -19
  249. package/dist/node_modules/ip-address/dist/address-error.js +0 -12
  250. package/dist/node_modules/ip-address/dist/common.js +0 -46
  251. package/dist/node_modules/ip-address/dist/ip-address.js +0 -35
  252. package/dist/node_modules/ip-address/dist/ipv4.js +0 -360
  253. package/dist/node_modules/ip-address/dist/ipv6.js +0 -1003
  254. package/dist/node_modules/ip-address/dist/v4/constants.js +0 -8
  255. package/dist/node_modules/ip-address/dist/v6/constants.js +0 -76
  256. package/dist/node_modules/ip-address/dist/v6/helpers.js +0 -45
  257. package/dist/node_modules/ip-address/dist/v6/regular-expressions.js +0 -95
  258. package/dist/node_modules/ip-address/package.json +0 -78
  259. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +0 -10
  260. package/dist/node_modules/lru-cache/dist/commonjs/index.js +0 -1692
  261. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +0 -2
  262. package/dist/node_modules/lru-cache/dist/commonjs/package.json +0 -3
  263. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +0 -4
  264. package/dist/node_modules/lru-cache/dist/esm/browser/index.js +0 -1688
  265. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +0 -2
  266. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +0 -19
  267. package/dist/node_modules/lru-cache/dist/esm/index.js +0 -1688
  268. package/dist/node_modules/lru-cache/dist/esm/index.min.js +0 -2
  269. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +0 -7
  270. package/dist/node_modules/lru-cache/dist/esm/node/index.js +0 -1688
  271. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +0 -2
  272. package/dist/node_modules/lru-cache/dist/esm/package.json +0 -3
  273. package/dist/node_modules/lru-cache/package.json +0 -126
  274. package/dist/node_modules/make-fetch-happen/LICENSE +0 -16
  275. package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +0 -471
  276. package/dist/node_modules/make-fetch-happen/lib/cache/errors.js +0 -11
  277. package/dist/node_modules/make-fetch-happen/lib/cache/index.js +0 -49
  278. package/dist/node_modules/make-fetch-happen/lib/cache/key.js +0 -17
  279. package/dist/node_modules/make-fetch-happen/lib/cache/policy.js +0 -161
  280. package/dist/node_modules/make-fetch-happen/lib/fetch.js +0 -118
  281. package/dist/node_modules/make-fetch-happen/lib/index.js +0 -41
  282. package/dist/node_modules/make-fetch-happen/lib/options.js +0 -59
  283. package/dist/node_modules/make-fetch-happen/lib/pipeline.js +0 -41
  284. package/dist/node_modules/make-fetch-happen/lib/remote.js +0 -134
  285. package/dist/node_modules/make-fetch-happen/package.json +0 -75
  286. package/dist/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +0 -14
  287. package/dist/node_modules/minimatch/dist/commonjs/ast.js +0 -845
  288. package/dist/node_modules/minimatch/dist/commonjs/brace-expressions.js +0 -150
  289. package/dist/node_modules/minimatch/dist/commonjs/escape.js +0 -30
  290. package/dist/node_modules/minimatch/dist/commonjs/index.js +0 -1127
  291. package/dist/node_modules/minimatch/dist/commonjs/package.json +0 -3
  292. package/dist/node_modules/minimatch/dist/commonjs/unescape.js +0 -38
  293. package/dist/node_modules/minimatch/dist/esm/assert-valid-pattern.js +0 -10
  294. package/dist/node_modules/minimatch/dist/esm/ast.js +0 -841
  295. package/dist/node_modules/minimatch/dist/esm/brace-expressions.js +0 -146
  296. package/dist/node_modules/minimatch/dist/esm/escape.js +0 -26
  297. package/dist/node_modules/minimatch/dist/esm/index.js +0 -1114
  298. package/dist/node_modules/minimatch/dist/esm/package.json +0 -3
  299. package/dist/node_modules/minimatch/dist/esm/unescape.js +0 -34
  300. package/dist/node_modules/minimatch/package.json +0 -73
  301. package/dist/node_modules/minipass-collect/LICENSE +0 -15
  302. package/dist/node_modules/minipass-collect/index.js +0 -71
  303. package/dist/node_modules/minipass-collect/package.json +0 -30
  304. package/dist/node_modules/minipass-fetch/LICENSE +0 -28
  305. package/dist/node_modules/minipass-fetch/lib/abort-error.js +0 -17
  306. package/dist/node_modules/minipass-fetch/lib/blob.js +0 -97
  307. package/dist/node_modules/minipass-fetch/lib/body.js +0 -360
  308. package/dist/node_modules/minipass-fetch/lib/fetch-error.js +0 -32
  309. package/dist/node_modules/minipass-fetch/lib/headers.js +0 -267
  310. package/dist/node_modules/minipass-fetch/lib/index.js +0 -376
  311. package/dist/node_modules/minipass-fetch/lib/request.js +0 -282
  312. package/dist/node_modules/minipass-fetch/lib/response.js +0 -90
  313. package/dist/node_modules/minipass-fetch/package.json +0 -70
  314. package/dist/node_modules/minipass-flush/index.js +0 -39
  315. package/dist/node_modules/minipass-flush/node_modules/minipass/LICENSE +0 -15
  316. package/dist/node_modules/minipass-flush/node_modules/minipass/index.js +0 -649
  317. package/dist/node_modules/minipass-flush/node_modules/minipass/package.json +0 -56
  318. package/dist/node_modules/minipass-flush/package.json +0 -42
  319. package/dist/node_modules/minipass-pipeline/LICENSE +0 -15
  320. package/dist/node_modules/minipass-pipeline/index.js +0 -128
  321. package/dist/node_modules/minipass-pipeline/node_modules/minipass/LICENSE +0 -15
  322. package/dist/node_modules/minipass-pipeline/node_modules/minipass/index.js +0 -649
  323. package/dist/node_modules/minipass-pipeline/node_modules/minipass/package.json +0 -56
  324. package/dist/node_modules/minipass-pipeline/package.json +0 -29
  325. package/dist/node_modules/minipass-sized/LICENSE +0 -15
  326. package/dist/node_modules/minipass-sized/dist/commonjs/index.js +0 -69
  327. package/dist/node_modules/minipass-sized/dist/commonjs/package.json +0 -3
  328. package/dist/node_modules/minipass-sized/dist/esm/index.js +0 -64
  329. package/dist/node_modules/minipass-sized/dist/esm/package.json +0 -3
  330. package/dist/node_modules/minipass-sized/package.json +0 -69
  331. package/dist/node_modules/ms/index.js +0 -162
  332. package/dist/node_modules/ms/package.json +0 -38
  333. package/dist/node_modules/negotiator/LICENSE +0 -24
  334. package/dist/node_modules/negotiator/index.js +0 -83
  335. package/dist/node_modules/negotiator/lib/charset.js +0 -169
  336. package/dist/node_modules/negotiator/lib/encoding.js +0 -205
  337. package/dist/node_modules/negotiator/lib/language.js +0 -179
  338. package/dist/node_modules/negotiator/lib/mediaType.js +0 -294
  339. package/dist/node_modules/negotiator/package.json +0 -43
  340. package/dist/node_modules/p-map/index.js +0 -283
  341. package/dist/node_modules/p-map/license +0 -9
  342. package/dist/node_modules/p-map/package.json +0 -57
  343. package/dist/node_modules/path-scurry/dist/commonjs/index.js +0 -2018
  344. package/dist/node_modules/path-scurry/dist/commonjs/package.json +0 -3
  345. package/dist/node_modules/path-scurry/dist/esm/index.js +0 -1983
  346. package/dist/node_modules/path-scurry/dist/esm/package.json +0 -3
  347. package/dist/node_modules/path-scurry/package.json +0 -72
  348. package/dist/node_modules/safer-buffer/dangerous.js +0 -58
  349. package/dist/node_modules/safer-buffer/package.json +0 -34
  350. package/dist/node_modules/safer-buffer/safer.js +0 -77
  351. package/dist/node_modules/safer-buffer/tests.js +0 -406
  352. package/dist/node_modules/smart-buffer/.prettierrc.yaml +0 -5
  353. package/dist/node_modules/smart-buffer/LICENSE +0 -20
  354. package/dist/node_modules/smart-buffer/build/smartbuffer.js +0 -1233
  355. package/dist/node_modules/smart-buffer/build/utils.js +0 -108
  356. package/dist/node_modules/smart-buffer/package.json +0 -79
  357. package/dist/node_modules/socks/.eslintrc.cjs +0 -11
  358. package/dist/node_modules/socks/.prettierrc.yaml +0 -7
  359. package/dist/node_modules/socks/LICENSE +0 -20
  360. package/dist/node_modules/socks/build/client/socksclient.js +0 -793
  361. package/dist/node_modules/socks/build/common/constants.js +0 -108
  362. package/dist/node_modules/socks/build/common/helpers.js +0 -167
  363. package/dist/node_modules/socks/build/common/receivebuffer.js +0 -43
  364. package/dist/node_modules/socks/build/common/util.js +0 -25
  365. package/dist/node_modules/socks/build/index.js +0 -18
  366. package/dist/node_modules/socks/package.json +0 -58
  367. package/dist/node_modules/socks-proxy-agent/LICENSE +0 -22
  368. package/dist/node_modules/socks-proxy-agent/dist/index.js +0 -195
  369. package/dist/node_modules/socks-proxy-agent/package.json +0 -142
  370. package/dist/node_modules/ssri/lib/index.js +0 -550
  371. package/dist/node_modules/ssri/package.json +0 -66
  372. package/dist/node_modules/tar/node_modules/yallist/dist/commonjs/package.json +0 -3
  373. package/dist/node_modules/tar/node_modules/yallist/dist/esm/package.json +0 -3
  374. package/dist/node_modules/tar/node_modules/yallist/package.json +0 -68
  375. package/dist/node_modules/yallist/LICENSE +0 -15
  376. package/dist/node_modules/yallist/iterator.js +0 -8
  377. package/dist/node_modules/yallist/yallist.js +0 -426
  378. /package/dist/node_modules/{tar/node_modules/yallist → yallist}/dist/commonjs/index.js +0 -0
  379. /package/dist/node_modules/{balanced-match → yallist}/dist/commonjs/package.json +0 -0
  380. /package/dist/node_modules/{tar/node_modules/yallist → yallist}/dist/esm/index.js +0 -0
  381. /package/dist/node_modules/{balanced-match → yallist}/dist/esm/package.json +0 -0
@@ -1,1688 +0,0 @@
1
- /**
2
- * @module LRUCache
3
- */
4
- import { metrics, tracing } from './diagnostics-channel.js';
5
- const hasSubscribers = () => metrics.hasSubscribers || tracing.hasSubscribers;
6
- const defaultPerf = (typeof performance === 'object' &&
7
- performance &&
8
- typeof performance.now === 'function') ?
9
- performance
10
- : Date;
11
- const warned = new Set();
12
- /* c8 ignore start */
13
- const PROCESS = (typeof process === 'object' && !!process ?
14
- process
15
- : {});
16
- /* c8 ignore stop */
17
- const emitWarning = (msg, type, code, fn) => {
18
- if (typeof PROCESS.emitWarning === 'function') {
19
- PROCESS.emitWarning(msg, type, code, fn);
20
- }
21
- else {
22
- //oxlint-disable-next-line no-console
23
- console.error(`[${code}] ${type}: ${msg}`);
24
- }
25
- };
26
- const shouldWarn = (code) => !warned.has(code);
27
- const TYPE = Symbol('type');
28
- const isPosInt = (n) => !!n && n === Math.floor(n) && n > 0 && isFinite(n);
29
- // This is a little bit ridiculous, tbh.
30
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
31
- // And well before that point, you're caching the entire world, I mean,
32
- // that's ~32GB of just integers for the next/prev links, plus whatever
33
- // else to hold that many keys and values. Just filling the memory with
34
- // zeroes at init time is brutal when you get that big.
35
- // But why not be complete?
36
- // Maybe in the future, these limits will have expanded.
37
- /* c8 ignore start */
38
- const getUintArray = (max) => !isPosInt(max) ? null
39
- : max <= Math.pow(2, 8) ? Uint8Array
40
- : max <= Math.pow(2, 16) ? Uint16Array
41
- : max <= Math.pow(2, 32) ? Uint32Array
42
- : max <= Number.MAX_SAFE_INTEGER ? ZeroArray
43
- : null;
44
- /* c8 ignore stop */
45
- class ZeroArray extends Array {
46
- constructor(size) {
47
- super(size);
48
- this.fill(0);
49
- }
50
- }
51
- class Stack {
52
- heap;
53
- length;
54
- // private constructor
55
- static #constructing = false;
56
- static create(max) {
57
- const HeapCls = getUintArray(max);
58
- if (!HeapCls)
59
- return [];
60
- Stack.#constructing = true;
61
- const s = new Stack(max, HeapCls);
62
- Stack.#constructing = false;
63
- return s;
64
- }
65
- constructor(max, HeapCls) {
66
- /* c8 ignore start */
67
- if (!Stack.#constructing) {
68
- throw new TypeError('instantiate Stack using Stack.create(n)');
69
- }
70
- /* c8 ignore stop */
71
- this.heap = new HeapCls(max);
72
- this.length = 0;
73
- }
74
- push(n) {
75
- this.heap[this.length++] = n;
76
- }
77
- pop() {
78
- return this.heap[--this.length];
79
- }
80
- }
81
- /**
82
- * Default export, the thing you're using this module to get.
83
- *
84
- * The `K` and `V` types define the key and value types, respectively. The
85
- * optional `FC` type defines the type of the `context` object passed to
86
- * `cache.fetch()` and `cache.memo()`.
87
- *
88
- * Keys and values **must not** be `null` or `undefined`.
89
- *
90
- * All properties from the options object (with the exception of `max`,
91
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
92
- * added as normal public members. (The listed options are read-only getters.)
93
- *
94
- * Changing any of these will alter the defaults for subsequent method calls.
95
- */
96
- export class LRUCache {
97
- // options that cannot be changed without disaster
98
- #max;
99
- #maxSize;
100
- #dispose;
101
- #onInsert;
102
- #disposeAfter;
103
- #fetchMethod;
104
- #memoMethod;
105
- #perf;
106
- /**
107
- * {@link LRUCache.OptionsBase.perf}
108
- */
109
- get perf() {
110
- return this.#perf;
111
- }
112
- /**
113
- * {@link LRUCache.OptionsBase.ttl}
114
- */
115
- ttl;
116
- /**
117
- * {@link LRUCache.OptionsBase.ttlResolution}
118
- */
119
- ttlResolution;
120
- /**
121
- * {@link LRUCache.OptionsBase.ttlAutopurge}
122
- */
123
- ttlAutopurge;
124
- /**
125
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
126
- */
127
- updateAgeOnGet;
128
- /**
129
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
130
- */
131
- updateAgeOnHas;
132
- /**
133
- * {@link LRUCache.OptionsBase.allowStale}
134
- */
135
- allowStale;
136
- /**
137
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
138
- */
139
- noDisposeOnSet;
140
- /**
141
- * {@link LRUCache.OptionsBase.noUpdateTTL}
142
- */
143
- noUpdateTTL;
144
- /**
145
- * {@link LRUCache.OptionsBase.maxEntrySize}
146
- */
147
- maxEntrySize;
148
- /**
149
- * {@link LRUCache.OptionsBase.sizeCalculation}
150
- */
151
- sizeCalculation;
152
- /**
153
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
154
- */
155
- noDeleteOnFetchRejection;
156
- /**
157
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
158
- */
159
- noDeleteOnStaleGet;
160
- /**
161
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
162
- */
163
- allowStaleOnFetchAbort;
164
- /**
165
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
166
- */
167
- allowStaleOnFetchRejection;
168
- /**
169
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
170
- */
171
- ignoreFetchAbort;
172
- // computed properties
173
- #size;
174
- #calculatedSize;
175
- #keyMap;
176
- #keyList;
177
- #valList;
178
- #next;
179
- #prev;
180
- #head;
181
- #tail;
182
- #free;
183
- #disposed;
184
- #sizes;
185
- #starts;
186
- #ttls;
187
- #autopurgeTimers;
188
- #hasDispose;
189
- #hasFetchMethod;
190
- #hasDisposeAfter;
191
- #hasOnInsert;
192
- /**
193
- * Do not call this method unless you need to inspect the
194
- * inner workings of the cache. If anything returned by this
195
- * object is modified in any way, strange breakage may occur.
196
- *
197
- * These fields are private for a reason!
198
- *
199
- * @internal
200
- */
201
- static unsafeExposeInternals(c) {
202
- return {
203
- // properties
204
- starts: c.#starts,
205
- ttls: c.#ttls,
206
- autopurgeTimers: c.#autopurgeTimers,
207
- sizes: c.#sizes,
208
- keyMap: c.#keyMap,
209
- keyList: c.#keyList,
210
- valList: c.#valList,
211
- next: c.#next,
212
- prev: c.#prev,
213
- get head() {
214
- return c.#head;
215
- },
216
- get tail() {
217
- return c.#tail;
218
- },
219
- free: c.#free,
220
- // methods
221
- isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
222
- backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
223
- moveToTail: (index) => c.#moveToTail(index),
224
- indexes: (options) => c.#indexes(options),
225
- rindexes: (options) => c.#rindexes(options),
226
- isStale: (index) => c.#isStale(index),
227
- };
228
- }
229
- // Protected read-only members
230
- /**
231
- * {@link LRUCache.OptionsBase.max} (read-only)
232
- */
233
- get max() {
234
- return this.#max;
235
- }
236
- /**
237
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
238
- */
239
- get maxSize() {
240
- return this.#maxSize;
241
- }
242
- /**
243
- * The total computed size of items in the cache (read-only)
244
- */
245
- get calculatedSize() {
246
- return this.#calculatedSize;
247
- }
248
- /**
249
- * The number of items stored in the cache (read-only)
250
- */
251
- get size() {
252
- return this.#size;
253
- }
254
- /**
255
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
256
- */
257
- get fetchMethod() {
258
- return this.#fetchMethod;
259
- }
260
- get memoMethod() {
261
- return this.#memoMethod;
262
- }
263
- /**
264
- * {@link LRUCache.OptionsBase.dispose} (read-only)
265
- */
266
- get dispose() {
267
- return this.#dispose;
268
- }
269
- /**
270
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
271
- */
272
- get onInsert() {
273
- return this.#onInsert;
274
- }
275
- /**
276
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
277
- */
278
- get disposeAfter() {
279
- return this.#disposeAfter;
280
- }
281
- constructor(options) {
282
- 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;
283
- if (perf !== undefined) {
284
- if (typeof perf?.now !== 'function') {
285
- throw new TypeError('perf option must have a now() method if specified');
286
- }
287
- }
288
- this.#perf = perf ?? defaultPerf;
289
- if (max !== 0 && !isPosInt(max)) {
290
- throw new TypeError('max option must be a nonnegative integer');
291
- }
292
- const UintArray = max ? getUintArray(max) : Array;
293
- if (!UintArray) {
294
- throw new Error('invalid max value: ' + max);
295
- }
296
- this.#max = max;
297
- this.#maxSize = maxSize;
298
- this.maxEntrySize = maxEntrySize || this.#maxSize;
299
- this.sizeCalculation = sizeCalculation;
300
- if (this.sizeCalculation) {
301
- if (!this.#maxSize && !this.maxEntrySize) {
302
- throw new TypeError('cannot set sizeCalculation without setting maxSize or maxEntrySize');
303
- }
304
- if (typeof this.sizeCalculation !== 'function') {
305
- throw new TypeError('sizeCalculation set to non-function');
306
- }
307
- }
308
- if (memoMethod !== undefined && typeof memoMethod !== 'function') {
309
- throw new TypeError('memoMethod must be a function if defined');
310
- }
311
- this.#memoMethod = memoMethod;
312
- if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
313
- throw new TypeError('fetchMethod must be a function if specified');
314
- }
315
- this.#fetchMethod = fetchMethod;
316
- this.#hasFetchMethod = !!fetchMethod;
317
- this.#keyMap = new Map();
318
- this.#keyList = Array.from({ length: max }).fill(undefined);
319
- this.#valList = Array.from({ length: max }).fill(undefined);
320
- this.#next = new UintArray(max);
321
- this.#prev = new UintArray(max);
322
- this.#head = 0;
323
- this.#tail = 0;
324
- this.#free = Stack.create(max);
325
- this.#size = 0;
326
- this.#calculatedSize = 0;
327
- if (typeof dispose === 'function') {
328
- this.#dispose = dispose;
329
- }
330
- if (typeof onInsert === 'function') {
331
- this.#onInsert = onInsert;
332
- }
333
- if (typeof disposeAfter === 'function') {
334
- this.#disposeAfter = disposeAfter;
335
- this.#disposed = [];
336
- }
337
- else {
338
- this.#disposeAfter = undefined;
339
- this.#disposed = undefined;
340
- }
341
- this.#hasDispose = !!this.#dispose;
342
- this.#hasOnInsert = !!this.#onInsert;
343
- this.#hasDisposeAfter = !!this.#disposeAfter;
344
- this.noDisposeOnSet = !!noDisposeOnSet;
345
- this.noUpdateTTL = !!noUpdateTTL;
346
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
347
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
348
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
349
- this.ignoreFetchAbort = !!ignoreFetchAbort;
350
- // NB: maxEntrySize is set to maxSize if it's set
351
- if (this.maxEntrySize !== 0) {
352
- if (this.#maxSize !== 0) {
353
- if (!isPosInt(this.#maxSize)) {
354
- throw new TypeError('maxSize must be a positive integer if specified');
355
- }
356
- }
357
- if (!isPosInt(this.maxEntrySize)) {
358
- throw new TypeError('maxEntrySize must be a positive integer if specified');
359
- }
360
- this.#initializeSizeTracking();
361
- }
362
- this.allowStale = !!allowStale;
363
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
364
- this.updateAgeOnGet = !!updateAgeOnGet;
365
- this.updateAgeOnHas = !!updateAgeOnHas;
366
- this.ttlResolution =
367
- isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
368
- this.ttlAutopurge = !!ttlAutopurge;
369
- this.ttl = ttl || 0;
370
- if (this.ttl) {
371
- if (!isPosInt(this.ttl)) {
372
- throw new TypeError('ttl must be a positive integer if specified');
373
- }
374
- this.#initializeTTLTracking();
375
- }
376
- // do not allow completely unbounded caches
377
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
378
- throw new TypeError('At least one of max, maxSize, or ttl is required');
379
- }
380
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
381
- const code = 'LRU_CACHE_UNBOUNDED';
382
- if (shouldWarn(code)) {
383
- warned.add(code);
384
- const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' +
385
- 'result in unbounded memory consumption.';
386
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache);
387
- }
388
- }
389
- }
390
- /**
391
- * Return the number of ms left in the item's TTL. If item is not in cache,
392
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
393
- */
394
- getRemainingTTL(key) {
395
- return this.#keyMap.has(key) ? Infinity : 0;
396
- }
397
- #initializeTTLTracking() {
398
- const ttls = new ZeroArray(this.#max);
399
- const starts = new ZeroArray(this.#max);
400
- this.#ttls = ttls;
401
- this.#starts = starts;
402
- const purgeTimers = this.ttlAutopurge ?
403
- Array.from({
404
- length: this.#max,
405
- })
406
- : undefined;
407
- this.#autopurgeTimers = purgeTimers;
408
- this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
409
- starts[index] = ttl !== 0 ? start : 0;
410
- ttls[index] = ttl;
411
- setPurgetTimer(index, ttl);
412
- };
413
- this.#updateItemAge = index => {
414
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
415
- setPurgetTimer(index, ttls[index]);
416
- };
417
- // clear out the purge timer if we're setting TTL to 0, and
418
- // previously had a ttl purge timer running, so it doesn't
419
- // fire unnecessarily. Don't need to do this if we're not doing
420
- // autopurge.
421
- const setPurgetTimer = !this.ttlAutopurge ?
422
- () => { }
423
- : (index, ttl) => {
424
- if (purgeTimers?.[index]) {
425
- clearTimeout(purgeTimers[index]);
426
- purgeTimers[index] = undefined;
427
- }
428
- if (ttl && ttl !== 0 && purgeTimers) {
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
- purgeTimers[index] = t;
441
- }
442
- };
443
- this.#statusTTL = (status, index) => {
444
- if (ttls[index]) {
445
- const ttl = ttls[index];
446
- const start = starts[index];
447
- /* c8 ignore start */
448
- if (!ttl || !start) {
449
- return;
450
- }
451
- /* c8 ignore stop */
452
- status.ttl = ttl;
453
- status.start = start;
454
- status.now = cachedNow || getNow();
455
- const age = status.now - start;
456
- status.remainingTTL = ttl - age;
457
- }
458
- };
459
- // debounce calls to perf.now() to 1s so we're not hitting
460
- // that costly call repeatedly.
461
- let cachedNow = 0;
462
- const getNow = () => {
463
- const n = this.#perf.now();
464
- if (this.ttlResolution > 0) {
465
- cachedNow = n;
466
- const t = setTimeout(() => (cachedNow = 0), this.ttlResolution);
467
- // not available on all platforms
468
- /* c8 ignore start */
469
- if (t.unref) {
470
- t.unref();
471
- }
472
- /* c8 ignore stop */
473
- }
474
- return n;
475
- };
476
- this.getRemainingTTL = key => {
477
- const index = this.#keyMap.get(key);
478
- if (index === undefined) {
479
- return 0;
480
- }
481
- const ttl = ttls[index];
482
- const start = starts[index];
483
- if (!ttl || !start) {
484
- return Infinity;
485
- }
486
- const age = (cachedNow || getNow()) - start;
487
- return ttl - age;
488
- };
489
- this.#isStale = index => {
490
- const s = starts[index];
491
- const t = ttls[index];
492
- return !!t && !!s && (cachedNow || getNow()) - s > t;
493
- };
494
- }
495
- // conditionally set private methods related to TTL
496
- #updateItemAge = () => { };
497
- #statusTTL = () => { };
498
- #setItemTTL = () => { };
499
- /* c8 ignore stop */
500
- #isStale = () => false;
501
- #initializeSizeTracking() {
502
- const sizes = new ZeroArray(this.#max);
503
- this.#calculatedSize = 0;
504
- this.#sizes = sizes;
505
- this.#removeItemSize = index => {
506
- this.#calculatedSize -= sizes[index];
507
- sizes[index] = 0;
508
- };
509
- this.#requireSize = (k, v, size, sizeCalculation) => {
510
- // provisionally accept background fetches.
511
- // actual value size will be checked when they return.
512
- if (this.#isBackgroundFetch(v)) {
513
- return 0;
514
- }
515
- if (!isPosInt(size)) {
516
- if (sizeCalculation) {
517
- if (typeof sizeCalculation !== 'function') {
518
- throw new TypeError('sizeCalculation must be a function');
519
- }
520
- size = sizeCalculation(v, k);
521
- if (!isPosInt(size)) {
522
- throw new TypeError('sizeCalculation return invalid (expect positive integer)');
523
- }
524
- }
525
- else {
526
- throw new TypeError('invalid size value (must be positive integer). ' +
527
- 'When maxSize or maxEntrySize is used, sizeCalculation ' +
528
- 'or size must be set.');
529
- }
530
- }
531
- return size;
532
- };
533
- this.#addItemSize = (index, size, status) => {
534
- sizes[index] = size;
535
- if (this.#maxSize) {
536
- const maxSize = this.#maxSize - sizes[index];
537
- while (this.#calculatedSize > maxSize) {
538
- this.#evict(true);
539
- }
540
- }
541
- this.#calculatedSize += sizes[index];
542
- if (status) {
543
- status.entrySize = size;
544
- status.totalCalculatedSize = this.#calculatedSize;
545
- }
546
- };
547
- }
548
- #removeItemSize = _i => { };
549
- #addItemSize = (_i, _s, _st) => { };
550
- #requireSize = (_k, _v, size, sizeCalculation) => {
551
- if (size || sizeCalculation) {
552
- throw new TypeError('cannot set size without setting maxSize or maxEntrySize on cache');
553
- }
554
- return 0;
555
- };
556
- *#indexes({ allowStale = this.allowStale } = {}) {
557
- if (this.#size) {
558
- for (let i = this.#tail; this.#isValidIndex(i);) {
559
- if (allowStale || !this.#isStale(i)) {
560
- yield i;
561
- }
562
- if (i === this.#head) {
563
- break;
564
- }
565
- else {
566
- i = this.#prev[i];
567
- }
568
- }
569
- }
570
- }
571
- *#rindexes({ allowStale = this.allowStale } = {}) {
572
- if (this.#size) {
573
- for (let i = this.#head; this.#isValidIndex(i);) {
574
- if (allowStale || !this.#isStale(i)) {
575
- yield i;
576
- }
577
- if (i === this.#tail) {
578
- break;
579
- }
580
- else {
581
- i = this.#next[i];
582
- }
583
- }
584
- }
585
- }
586
- #isValidIndex(index) {
587
- return (index !== undefined &&
588
- this.#keyMap.get(this.#keyList[index]) === index);
589
- }
590
- /**
591
- * Return a generator yielding `[key, value]` pairs,
592
- * in order from most recently used to least recently used.
593
- */
594
- *entries() {
595
- for (const i of this.#indexes()) {
596
- if (this.#valList[i] !== undefined &&
597
- this.#keyList[i] !== undefined &&
598
- !this.#isBackgroundFetch(this.#valList[i])) {
599
- yield [this.#keyList[i], this.#valList[i]];
600
- }
601
- }
602
- }
603
- /**
604
- * Inverse order version of {@link LRUCache.entries}
605
- *
606
- * Return a generator yielding `[key, value]` pairs,
607
- * in order from least recently used to most recently used.
608
- */
609
- *rentries() {
610
- for (const i of this.#rindexes()) {
611
- if (this.#valList[i] !== undefined &&
612
- this.#keyList[i] !== undefined &&
613
- !this.#isBackgroundFetch(this.#valList[i])) {
614
- yield [this.#keyList[i], this.#valList[i]];
615
- }
616
- }
617
- }
618
- /**
619
- * Return a generator yielding the keys in the cache,
620
- * in order from most recently used to least recently used.
621
- */
622
- *keys() {
623
- for (const i of this.#indexes()) {
624
- const k = this.#keyList[i];
625
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
626
- yield k;
627
- }
628
- }
629
- }
630
- /**
631
- * Inverse order version of {@link LRUCache.keys}
632
- *
633
- * Return a generator yielding the keys in the cache,
634
- * in order from least recently used to most recently used.
635
- */
636
- *rkeys() {
637
- for (const i of this.#rindexes()) {
638
- const k = this.#keyList[i];
639
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
640
- yield k;
641
- }
642
- }
643
- }
644
- /**
645
- * Return a generator yielding the values in the cache,
646
- * in order from most recently used to least recently used.
647
- */
648
- *values() {
649
- for (const i of this.#indexes()) {
650
- const v = this.#valList[i];
651
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
652
- yield this.#valList[i];
653
- }
654
- }
655
- }
656
- /**
657
- * Inverse order version of {@link LRUCache.values}
658
- *
659
- * Return a generator yielding the values in the cache,
660
- * in order from least recently used to most recently used.
661
- */
662
- *rvalues() {
663
- for (const i of this.#rindexes()) {
664
- const v = this.#valList[i];
665
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
666
- yield this.#valList[i];
667
- }
668
- }
669
- }
670
- /**
671
- * Iterating over the cache itself yields the same results as
672
- * {@link LRUCache.entries}
673
- */
674
- [Symbol.iterator]() {
675
- return this.entries();
676
- }
677
- /**
678
- * A String value that is used in the creation of the default string
679
- * description of an object. Called by the built-in method
680
- * `Object.prototype.toString`.
681
- */
682
- [Symbol.toStringTag] = 'LRUCache';
683
- /**
684
- * Find a value for which the supplied fn method returns a truthy value,
685
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
686
- */
687
- find(fn, getOptions = {}) {
688
- for (const i of this.#indexes()) {
689
- const v = this.#valList[i];
690
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
691
- if (value === undefined)
692
- continue;
693
- if (fn(value, this.#keyList[i], this)) {
694
- return this.#get(this.#keyList[i], getOptions);
695
- }
696
- }
697
- }
698
- /**
699
- * Call the supplied function on each item in the cache, in order from most
700
- * recently used to least recently used.
701
- *
702
- * `fn` is called as `fn(value, key, cache)`.
703
- *
704
- * If `thisp` is provided, function will be called in the `this`-context of
705
- * the provided object, or the cache if no `thisp` object is provided.
706
- *
707
- * Does not update age or recenty of use, or iterate over stale values.
708
- */
709
- forEach(fn, thisp = this) {
710
- for (const i of this.#indexes()) {
711
- const v = this.#valList[i];
712
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
713
- if (value === undefined)
714
- continue;
715
- fn.call(thisp, value, this.#keyList[i], this);
716
- }
717
- }
718
- /**
719
- * The same as {@link LRUCache.forEach} but items are iterated over in
720
- * reverse order. (ie, less recently used items are iterated over first.)
721
- */
722
- rforEach(fn, thisp = this) {
723
- for (const i of this.#rindexes()) {
724
- const v = this.#valList[i];
725
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
726
- if (value === undefined)
727
- continue;
728
- fn.call(thisp, value, this.#keyList[i], this);
729
- }
730
- }
731
- /**
732
- * Delete any stale entries. Returns true if anything was removed,
733
- * false otherwise.
734
- */
735
- purgeStale() {
736
- let deleted = false;
737
- for (const i of this.#rindexes({ allowStale: true })) {
738
- if (this.#isStale(i)) {
739
- this.#delete(this.#keyList[i], 'expire');
740
- deleted = true;
741
- }
742
- }
743
- return deleted;
744
- }
745
- /**
746
- * Get the extended info about a given entry, to get its value, size, and
747
- * TTL info simultaneously. Returns `undefined` if the key is not present.
748
- *
749
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
750
- * serialization, the `start` value is always the current timestamp, and the
751
- * `ttl` is a calculated remaining time to live (negative if expired).
752
- *
753
- * Always returns stale values, if their info is found in the cache, so be
754
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
755
- * if relevant.
756
- */
757
- info(key) {
758
- const i = this.#keyMap.get(key);
759
- if (i === undefined)
760
- return undefined;
761
- const v = this.#valList[i];
762
- /* c8 ignore start - this isn't tested for the info function,
763
- * but it's the same logic as found in other places. */
764
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
765
- if (value === undefined)
766
- return undefined;
767
- /* c8 ignore stop */
768
- const entry = { value };
769
- if (this.#ttls && this.#starts) {
770
- const ttl = this.#ttls[i];
771
- const start = this.#starts[i];
772
- if (ttl && start) {
773
- const remain = ttl - (this.#perf.now() - start);
774
- entry.ttl = remain;
775
- entry.start = Date.now();
776
- }
777
- }
778
- if (this.#sizes) {
779
- entry.size = this.#sizes[i];
780
- }
781
- return entry;
782
- }
783
- /**
784
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
785
- * passed to {@link LRUCache#load}.
786
- *
787
- * The `start` fields are calculated relative to a portable `Date.now()`
788
- * timestamp, even if `performance.now()` is available.
789
- *
790
- * Stale entries are always included in the `dump`, even if
791
- * {@link LRUCache.OptionsBase.allowStale} is false.
792
- *
793
- * Note: this returns an actual array, not a generator, so it can be more
794
- * easily passed around.
795
- */
796
- dump() {
797
- const arr = [];
798
- for (const i of this.#indexes({ allowStale: true })) {
799
- const key = this.#keyList[i];
800
- const v = this.#valList[i];
801
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
802
- if (value === undefined || key === undefined)
803
- continue;
804
- const entry = { value };
805
- if (this.#ttls && this.#starts) {
806
- entry.ttl = this.#ttls[i];
807
- // always dump the start relative to a portable timestamp
808
- // it's ok for this to be a bit slow, it's a rare operation.
809
- const age = this.#perf.now() - this.#starts[i];
810
- entry.start = Math.floor(Date.now() - age);
811
- }
812
- if (this.#sizes) {
813
- entry.size = this.#sizes[i];
814
- }
815
- arr.unshift([key, entry]);
816
- }
817
- return arr;
818
- }
819
- /**
820
- * Reset the cache and load in the items in entries in the order listed.
821
- *
822
- * The shape of the resulting cache may be different if the same options are
823
- * not used in both caches.
824
- *
825
- * The `start` fields are assumed to be calculated relative to a portable
826
- * `Date.now()` timestamp, even if `performance.now()` is available.
827
- */
828
- load(arr) {
829
- this.clear();
830
- for (const [key, entry] of arr) {
831
- if (entry.start) {
832
- // entry.start is a portable timestamp, but we may be using
833
- // node's performance.now(), so calculate the offset, so that
834
- // we get the intended remaining TTL, no matter how long it's
835
- // been on ice.
836
- //
837
- // it's ok for this to be a bit slow, it's a rare operation.
838
- const age = Date.now() - entry.start;
839
- entry.start = this.#perf.now() - age;
840
- }
841
- this.#set(key, entry.value, entry);
842
- }
843
- }
844
- /**
845
- * Add a value to the cache.
846
- *
847
- * Note: if `undefined` is specified as a value, this is an alias for
848
- * {@link LRUCache#delete}
849
- *
850
- * Fields on the {@link LRUCache.SetOptions} options param will override
851
- * their corresponding values in the constructor options for the scope
852
- * of this single `set()` operation.
853
- *
854
- * If `start` is provided, then that will set the effective start
855
- * time for the TTL calculation. Note that this must be a previous
856
- * value of `performance.now()` if supported, or a previous value of
857
- * `Date.now()` if not.
858
- *
859
- * Options object may also include `size`, which will prevent
860
- * calling the `sizeCalculation` function and just use the specified
861
- * number if it is a positive integer, and `noDisposeOnSet` which
862
- * will prevent calling a `dispose` function in the case of
863
- * overwrites.
864
- *
865
- * If the `size` (or return value of `sizeCalculation`) for a given
866
- * entry is greater than `maxEntrySize`, then the item will not be
867
- * added to the cache.
868
- *
869
- * Will update the recency of the entry.
870
- *
871
- * If the value is `undefined`, then this is an alias for
872
- * `cache.delete(key)`. `undefined` is never stored in the cache.
873
- */
874
- set(k, v, setOptions = {}) {
875
- const { status = metrics.hasSubscribers ? {} : undefined } = setOptions;
876
- setOptions.status = status;
877
- if (status) {
878
- status.op = 'set';
879
- status.key = k;
880
- if (v !== undefined)
881
- status.value = v;
882
- }
883
- const result = this.#set(k, v, setOptions);
884
- if (status && metrics.hasSubscribers) {
885
- metrics.publish(status);
886
- }
887
- return result;
888
- }
889
- #set(k, v, setOptions = {}) {
890
- const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
891
- if (v === undefined) {
892
- if (status)
893
- status.set = 'deleted';
894
- this.delete(k);
895
- return this;
896
- }
897
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
898
- if (status && !this.#isBackgroundFetch(v))
899
- status.value = v;
900
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation, status);
901
- // if the item doesn't fit, don't do anything
902
- // NB: maxEntrySize set to maxSize by default
903
- if (this.maxEntrySize && size > this.maxEntrySize) {
904
- // have to delete, in case something is there already.
905
- this.#delete(k, 'set');
906
- if (status) {
907
- status.set = 'miss';
908
- status.maxEntrySizeExceeded = true;
909
- }
910
- return this;
911
- }
912
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
913
- if (index === undefined) {
914
- // addition
915
- index = (this.#size === 0 ? this.#tail
916
- : this.#free.length !== 0 ? this.#free.pop()
917
- : this.#size === this.#max ? this.#evict(false)
918
- : this.#size);
919
- this.#keyList[index] = k;
920
- this.#valList[index] = v;
921
- this.#keyMap.set(k, index);
922
- this.#next[this.#tail] = index;
923
- this.#prev[index] = this.#tail;
924
- this.#tail = index;
925
- this.#size++;
926
- this.#addItemSize(index, size, status);
927
- if (status)
928
- status.set = 'add';
929
- noUpdateTTL = false;
930
- if (this.#hasOnInsert) {
931
- this.#onInsert?.(v, k, 'add');
932
- }
933
- }
934
- else {
935
- // update
936
- this.#moveToTail(index);
937
- const oldVal = this.#valList[index];
938
- if (v !== oldVal) {
939
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
940
- oldVal.__abortController.abort(new Error('replaced'));
941
- const { __staleWhileFetching: s } = oldVal;
942
- if (s !== undefined && !noDisposeOnSet) {
943
- if (this.#hasDispose) {
944
- this.#dispose?.(s, k, 'set');
945
- }
946
- if (this.#hasDisposeAfter) {
947
- this.#disposed?.push([s, k, 'set']);
948
- }
949
- }
950
- }
951
- else if (!noDisposeOnSet) {
952
- if (this.#hasDispose) {
953
- this.#dispose?.(oldVal, k, 'set');
954
- }
955
- if (this.#hasDisposeAfter) {
956
- this.#disposed?.push([oldVal, k, 'set']);
957
- }
958
- }
959
- this.#removeItemSize(index);
960
- this.#addItemSize(index, size, status);
961
- this.#valList[index] = v;
962
- if (status) {
963
- status.set = 'replace';
964
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ?
965
- oldVal.__staleWhileFetching
966
- : oldVal;
967
- if (oldValue !== undefined)
968
- status.oldValue = oldValue;
969
- }
970
- }
971
- else if (status) {
972
- status.set = 'update';
973
- }
974
- if (this.#hasOnInsert) {
975
- this.onInsert?.(v, k, v === oldVal ? 'update' : 'replace');
976
- }
977
- }
978
- if (ttl !== 0 && !this.#ttls) {
979
- this.#initializeTTLTracking();
980
- }
981
- if (this.#ttls) {
982
- if (!noUpdateTTL) {
983
- this.#setItemTTL(index, ttl, start);
984
- }
985
- if (status)
986
- this.#statusTTL(status, index);
987
- }
988
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
989
- const dt = this.#disposed;
990
- let task;
991
- while ((task = dt?.shift())) {
992
- this.#disposeAfter?.(...task);
993
- }
994
- }
995
- return this;
996
- }
997
- /**
998
- * Evict the least recently used item, returning its value or
999
- * `undefined` if cache is empty.
1000
- */
1001
- pop() {
1002
- try {
1003
- while (this.#size) {
1004
- const val = this.#valList[this.#head];
1005
- this.#evict(true);
1006
- if (this.#isBackgroundFetch(val)) {
1007
- if (val.__staleWhileFetching) {
1008
- return val.__staleWhileFetching;
1009
- }
1010
- }
1011
- else if (val !== undefined) {
1012
- return val;
1013
- }
1014
- }
1015
- }
1016
- finally {
1017
- if (this.#hasDisposeAfter && this.#disposed) {
1018
- const dt = this.#disposed;
1019
- let task;
1020
- while ((task = dt?.shift())) {
1021
- this.#disposeAfter?.(...task);
1022
- }
1023
- }
1024
- }
1025
- }
1026
- #evict(free) {
1027
- const head = this.#head;
1028
- const k = this.#keyList[head];
1029
- const v = this.#valList[head];
1030
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
1031
- v.__abortController.abort(new Error('evicted'));
1032
- }
1033
- else if (this.#hasDispose || this.#hasDisposeAfter) {
1034
- if (this.#hasDispose) {
1035
- this.#dispose?.(v, k, 'evict');
1036
- }
1037
- if (this.#hasDisposeAfter) {
1038
- this.#disposed?.push([v, k, 'evict']);
1039
- }
1040
- }
1041
- this.#removeItemSize(head);
1042
- if (this.#autopurgeTimers?.[head]) {
1043
- clearTimeout(this.#autopurgeTimers[head]);
1044
- this.#autopurgeTimers[head] = undefined;
1045
- }
1046
- // if we aren't about to use the index, then null these out
1047
- if (free) {
1048
- this.#keyList[head] = undefined;
1049
- this.#valList[head] = undefined;
1050
- this.#free.push(head);
1051
- }
1052
- if (this.#size === 1) {
1053
- this.#head = this.#tail = 0;
1054
- this.#free.length = 0;
1055
- }
1056
- else {
1057
- this.#head = this.#next[head];
1058
- }
1059
- this.#keyMap.delete(k);
1060
- this.#size--;
1061
- return head;
1062
- }
1063
- /**
1064
- * Check if a key is in the cache, without updating the recency of use.
1065
- * Will return false if the item is stale, even though it is technically
1066
- * in the cache.
1067
- *
1068
- * Check if a key is in the cache, without updating the recency of
1069
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
1070
- * to `true` in either the options or the constructor.
1071
- *
1072
- * Will return `false` if the item is stale, even though it is technically in
1073
- * the cache. The difference can be determined (if it matters) by using a
1074
- * `status` argument, and inspecting the `has` field.
1075
- *
1076
- * Will not update item age unless
1077
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
1078
- */
1079
- has(k, hasOptions = {}) {
1080
- const { status = metrics.hasSubscribers ? {} : undefined } = hasOptions;
1081
- hasOptions.status = status;
1082
- if (status) {
1083
- status.op = 'has';
1084
- status.key = k;
1085
- }
1086
- const result = this.#has(k, hasOptions);
1087
- if (metrics.hasSubscribers)
1088
- metrics.publish(status);
1089
- return result;
1090
- }
1091
- #has(k, hasOptions = {}) {
1092
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
1093
- const index = this.#keyMap.get(k);
1094
- if (index !== undefined) {
1095
- const v = this.#valList[index];
1096
- if (this.#isBackgroundFetch(v) &&
1097
- v.__staleWhileFetching === undefined) {
1098
- return false;
1099
- }
1100
- if (!this.#isStale(index)) {
1101
- if (updateAgeOnHas) {
1102
- this.#updateItemAge(index);
1103
- }
1104
- if (status) {
1105
- status.has = 'hit';
1106
- this.#statusTTL(status, index);
1107
- }
1108
- return true;
1109
- }
1110
- else if (status) {
1111
- status.has = 'stale';
1112
- this.#statusTTL(status, index);
1113
- }
1114
- }
1115
- else if (status) {
1116
- status.has = 'miss';
1117
- }
1118
- return false;
1119
- }
1120
- /**
1121
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
1122
- * items.
1123
- *
1124
- * Returns `undefined` if the item is stale, unless
1125
- * {@link LRUCache.OptionsBase.allowStale} is set.
1126
- */
1127
- peek(k, peekOptions = {}) {
1128
- const { status = hasSubscribers() ? {} : undefined } = peekOptions;
1129
- if (status) {
1130
- status.op = 'peek';
1131
- status.key = k;
1132
- }
1133
- peekOptions.status = status;
1134
- const result = this.#peek(k, peekOptions);
1135
- if (metrics.hasSubscribers) {
1136
- metrics.publish(status);
1137
- }
1138
- return result;
1139
- }
1140
- #peek(k, peekOptions) {
1141
- const { status, allowStale = this.allowStale } = peekOptions;
1142
- const index = this.#keyMap.get(k);
1143
- if (index === undefined || (!allowStale && this.#isStale(index))) {
1144
- if (status)
1145
- status.peek = index === undefined ? 'miss' : 'stale';
1146
- return undefined;
1147
- }
1148
- const v = this.#valList[index];
1149
- const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
1150
- if (status) {
1151
- if (val !== undefined) {
1152
- status.peek = 'hit';
1153
- status.value = val;
1154
- }
1155
- else {
1156
- status.peek = 'miss';
1157
- }
1158
- }
1159
- return val;
1160
- }
1161
- #backgroundFetch(k, index, options, context) {
1162
- const v = index === undefined ? undefined : this.#valList[index];
1163
- if (this.#isBackgroundFetch(v)) {
1164
- return v;
1165
- }
1166
- const ac = new AbortController();
1167
- const { signal } = options;
1168
- // when/if our AC signals, then stop listening to theirs.
1169
- signal?.addEventListener('abort', () => ac.abort(signal.reason), {
1170
- signal: ac.signal,
1171
- });
1172
- const fetchOpts = {
1173
- signal: ac.signal,
1174
- options,
1175
- context,
1176
- };
1177
- const cb = (v, updateCache = false) => {
1178
- const { aborted } = ac.signal;
1179
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined;
1180
- const proceed = options.ignoreFetchAbort ||
1181
- !!(options.allowStaleOnFetchAbort && v !== undefined);
1182
- if (options.status) {
1183
- if (aborted && !updateCache) {
1184
- options.status.fetchAborted = true;
1185
- options.status.fetchError = ac.signal.reason;
1186
- if (ignoreAbort)
1187
- options.status.fetchAbortIgnored = true;
1188
- }
1189
- else {
1190
- options.status.fetchResolved = true;
1191
- }
1192
- }
1193
- if (aborted && !ignoreAbort && !updateCache) {
1194
- return fetchFail(ac.signal.reason, proceed);
1195
- }
1196
- // either we didn't abort, and are still here, or we did, and ignored
1197
- const bf = p;
1198
- // if nothing else has been written there but we're set to update the
1199
- // cache and ignore the abort, or if it's still pending on this specific
1200
- // background request, then write it to the cache.
1201
- const vl = this.#valList[index];
1202
- if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
1203
- if (v === undefined) {
1204
- if (bf.__staleWhileFetching !== undefined) {
1205
- this.#valList[index] = bf.__staleWhileFetching;
1206
- }
1207
- else {
1208
- this.#delete(k, 'fetch');
1209
- }
1210
- }
1211
- else {
1212
- if (options.status)
1213
- options.status.fetchUpdated = true;
1214
- this.#set(k, v, fetchOpts.options);
1215
- }
1216
- }
1217
- return v;
1218
- };
1219
- const eb = (er) => {
1220
- if (options.status) {
1221
- options.status.fetchRejected = true;
1222
- options.status.fetchError = er;
1223
- }
1224
- // do not pass go, do not collect $200
1225
- return fetchFail(er, false);
1226
- };
1227
- const fetchFail = (er, proceed) => {
1228
- const { aborted } = ac.signal;
1229
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
1230
- const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
1231
- const noDelete = allowStale || options.noDeleteOnFetchRejection;
1232
- const bf = p;
1233
- if (this.#valList[index] === p) {
1234
- // if we allow stale on fetch rejections, then we need to ensure that
1235
- // the stale value is not removed from the cache when the fetch fails.
1236
- const del = !noDelete || (!proceed && bf.__staleWhileFetching === undefined);
1237
- if (del) {
1238
- this.#delete(k, 'fetch');
1239
- }
1240
- else if (!allowStaleAborted) {
1241
- // still replace the *promise* with the stale value,
1242
- // since we are done with the promise at this point.
1243
- // leave it untouched if we're still waiting for an
1244
- // aborted background fetch that hasn't yet returned.
1245
- this.#valList[index] = bf.__staleWhileFetching;
1246
- }
1247
- }
1248
- if (allowStale) {
1249
- if (options.status && bf.__staleWhileFetching !== undefined) {
1250
- options.status.returnedStale = true;
1251
- }
1252
- return bf.__staleWhileFetching;
1253
- }
1254
- else if (bf.__returned === bf) {
1255
- throw er;
1256
- }
1257
- };
1258
- const pcall = (res, rej) => {
1259
- const fmp = this.#fetchMethod?.(k, v, fetchOpts);
1260
- if (fmp && fmp instanceof Promise) {
1261
- fmp.then(v => res(v === undefined ? undefined : v), rej);
1262
- }
1263
- // ignored, we go until we finish, regardless.
1264
- // defer check until we are actually aborting,
1265
- // so fetchMethod can override.
1266
- ac.signal.addEventListener('abort', () => {
1267
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
1268
- res(undefined);
1269
- // when it eventually resolves, update the cache.
1270
- if (options.allowStaleOnFetchAbort) {
1271
- res = v => cb(v, true);
1272
- }
1273
- }
1274
- });
1275
- };
1276
- if (options.status)
1277
- options.status.fetchDispatched = true;
1278
- const p = new Promise(pcall).then(cb, eb);
1279
- const bf = Object.assign(p, {
1280
- __abortController: ac,
1281
- __staleWhileFetching: v,
1282
- __returned: undefined,
1283
- });
1284
- if (index === undefined) {
1285
- // internal, don't expose status.
1286
- this.#set(k, bf, { ...fetchOpts.options, status: undefined });
1287
- index = this.#keyMap.get(k);
1288
- }
1289
- else {
1290
- this.#valList[index] = bf;
1291
- }
1292
- return bf;
1293
- }
1294
- #isBackgroundFetch(p) {
1295
- if (!this.#hasFetchMethod)
1296
- return false;
1297
- const b = p;
1298
- return (!!b &&
1299
- b instanceof Promise &&
1300
- b.hasOwnProperty('__staleWhileFetching') &&
1301
- b.__abortController instanceof AbortController);
1302
- }
1303
- fetch(k, fetchOptions = {}) {
1304
- const ths = tracing.hasSubscribers;
1305
- const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
1306
- fetchOptions.status = status;
1307
- if (status && fetchOptions.context) {
1308
- status.context = fetchOptions.context;
1309
- }
1310
- const p = this.#fetch(k, fetchOptions);
1311
- if (status && hasSubscribers()) {
1312
- if (ths) {
1313
- status.trace = true;
1314
- tracing.tracePromise(() => p, status).catch(() => { });
1315
- }
1316
- }
1317
- return p;
1318
- }
1319
- async #fetch(k, fetchOptions = {}) {
1320
- const {
1321
- // get options
1322
- allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
1323
- // set options
1324
- ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
1325
- // fetch exclusive options
1326
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
1327
- if (status) {
1328
- status.op = 'fetch';
1329
- status.key = k;
1330
- if (forceRefresh)
1331
- status.forceRefresh = true;
1332
- }
1333
- if (!this.#hasFetchMethod) {
1334
- if (status)
1335
- status.fetch = 'get';
1336
- return this.#get(k, {
1337
- allowStale,
1338
- updateAgeOnGet,
1339
- noDeleteOnStaleGet,
1340
- status,
1341
- });
1342
- }
1343
- const options = {
1344
- allowStale,
1345
- updateAgeOnGet,
1346
- noDeleteOnStaleGet,
1347
- ttl,
1348
- noDisposeOnSet,
1349
- size,
1350
- sizeCalculation,
1351
- noUpdateTTL,
1352
- noDeleteOnFetchRejection,
1353
- allowStaleOnFetchRejection,
1354
- allowStaleOnFetchAbort,
1355
- ignoreFetchAbort,
1356
- status,
1357
- signal,
1358
- };
1359
- let index = this.#keyMap.get(k);
1360
- if (index === undefined) {
1361
- if (status)
1362
- status.fetch = 'miss';
1363
- const p = this.#backgroundFetch(k, index, options, context);
1364
- return (p.__returned = p);
1365
- }
1366
- else {
1367
- // in cache, maybe already fetching
1368
- const v = this.#valList[index];
1369
- if (this.#isBackgroundFetch(v)) {
1370
- const stale = allowStale && v.__staleWhileFetching !== undefined;
1371
- if (status) {
1372
- status.fetch = 'inflight';
1373
- if (stale)
1374
- status.returnedStale = true;
1375
- }
1376
- return stale ? v.__staleWhileFetching : (v.__returned = v);
1377
- }
1378
- // if we force a refresh, that means do NOT serve the cached value,
1379
- // unless we are already in the process of refreshing the cache.
1380
- const isStale = this.#isStale(index);
1381
- if (!forceRefresh && !isStale) {
1382
- if (status)
1383
- status.fetch = 'hit';
1384
- this.#moveToTail(index);
1385
- if (updateAgeOnGet) {
1386
- this.#updateItemAge(index);
1387
- }
1388
- if (status)
1389
- this.#statusTTL(status, index);
1390
- return v;
1391
- }
1392
- // ok, it is stale or a forced refresh, and not already fetching.
1393
- // refresh the cache.
1394
- const p = this.#backgroundFetch(k, index, options, context);
1395
- const hasStale = p.__staleWhileFetching !== undefined;
1396
- const staleVal = hasStale && allowStale;
1397
- if (status) {
1398
- status.fetch = isStale ? 'stale' : 'refresh';
1399
- if (staleVal && isStale)
1400
- status.returnedStale = true;
1401
- }
1402
- return staleVal ? p.__staleWhileFetching : (p.__returned = p);
1403
- }
1404
- }
1405
- forceFetch(k, fetchOptions = {}) {
1406
- const ths = tracing.hasSubscribers;
1407
- const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
1408
- fetchOptions.status = status;
1409
- if (status && fetchOptions.context) {
1410
- status.context = fetchOptions.context;
1411
- }
1412
- const p = this.#forceFetch(k, fetchOptions);
1413
- if (status && hasSubscribers()) {
1414
- if (ths) {
1415
- status.trace = true;
1416
- tracing.tracePromise(() => p, status).catch(() => { });
1417
- }
1418
- }
1419
- return p;
1420
- }
1421
- async #forceFetch(k, fetchOptions = {}) {
1422
- const v = await this.#fetch(k, fetchOptions);
1423
- if (v === undefined)
1424
- throw new Error('fetch() returned undefined');
1425
- return v;
1426
- }
1427
- memo(k, memoOptions = {}) {
1428
- const { status = metrics.hasSubscribers ? {} : undefined } = memoOptions;
1429
- memoOptions.status = status;
1430
- if (status) {
1431
- status.op = 'memo';
1432
- status.key = k;
1433
- if (memoOptions.context) {
1434
- status.context = memoOptions.context;
1435
- }
1436
- }
1437
- const result = this.#memo(k, memoOptions);
1438
- if (status)
1439
- status.value = result;
1440
- if (metrics.hasSubscribers)
1441
- metrics.publish(status);
1442
- return result;
1443
- }
1444
- #memo(k, memoOptions = {}) {
1445
- const memoMethod = this.#memoMethod;
1446
- if (!memoMethod) {
1447
- throw new Error('no memoMethod provided to constructor');
1448
- }
1449
- const { context, status, forceRefresh, ...options } = memoOptions;
1450
- if (status && forceRefresh)
1451
- status.forceRefresh = true;
1452
- const v = this.#get(k, options);
1453
- const refresh = forceRefresh || v === undefined;
1454
- if (status) {
1455
- status.memo = refresh ? 'miss' : 'hit';
1456
- if (!refresh)
1457
- status.value = v;
1458
- }
1459
- if (!refresh)
1460
- return v;
1461
- const vv = memoMethod(k, v, {
1462
- options,
1463
- context,
1464
- });
1465
- if (status)
1466
- status.value = vv;
1467
- this.#set(k, vv, options);
1468
- return vv;
1469
- }
1470
- /**
1471
- * Return a value from the cache. Will update the recency of the cache
1472
- * entry found.
1473
- *
1474
- * If the key is not found, get() will return `undefined`.
1475
- */
1476
- get(k, getOptions = {}) {
1477
- const { status = metrics.hasSubscribers ? {} : undefined } = getOptions;
1478
- getOptions.status = status;
1479
- if (status) {
1480
- status.op = 'get';
1481
- status.key = k;
1482
- }
1483
- const result = this.#get(k, getOptions);
1484
- if (status) {
1485
- if (result !== undefined)
1486
- status.value = result;
1487
- if (metrics.hasSubscribers)
1488
- metrics.publish(status);
1489
- }
1490
- return result;
1491
- }
1492
- #get(k, getOptions = {}) {
1493
- const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
1494
- const index = this.#keyMap.get(k);
1495
- if (index === undefined) {
1496
- if (status)
1497
- status.get = 'miss';
1498
- return undefined;
1499
- }
1500
- const value = this.#valList[index];
1501
- const fetching = this.#isBackgroundFetch(value);
1502
- if (status)
1503
- this.#statusTTL(status, index);
1504
- if (this.#isStale(index)) {
1505
- // delete only if not an in-flight background fetch
1506
- if (!fetching) {
1507
- if (!noDeleteOnStaleGet) {
1508
- this.#delete(k, 'expire');
1509
- }
1510
- if (status)
1511
- status.get = 'stale';
1512
- if (allowStale) {
1513
- if (status)
1514
- status.returnedStale = true;
1515
- return value;
1516
- }
1517
- return undefined;
1518
- }
1519
- if (status)
1520
- status.get = 'stale-fetching';
1521
- if (allowStale && value.__staleWhileFetching !== undefined) {
1522
- if (status)
1523
- status.returnedStale = true;
1524
- return value.__staleWhileFetching;
1525
- }
1526
- return undefined;
1527
- }
1528
- // not stale
1529
- if (status)
1530
- status.get = fetching ? 'fetching' : 'hit';
1531
- // if we're currently fetching it, we don't actually have it yet
1532
- // it's not stale, which means this isn't a staleWhileRefetching.
1533
- // If it's not stale, and fetching, AND has a __staleWhileFetching
1534
- // value, then that means the user fetched with {forceRefresh:true},
1535
- // so it's safe to return that value.
1536
- this.#moveToTail(index);
1537
- if (updateAgeOnGet) {
1538
- this.#updateItemAge(index);
1539
- }
1540
- return fetching ? value.__staleWhileFetching : value;
1541
- }
1542
- #connect(p, n) {
1543
- this.#prev[n] = p;
1544
- this.#next[p] = n;
1545
- }
1546
- #moveToTail(index) {
1547
- // if tail already, nothing to do
1548
- // if head, move head to next[index]
1549
- // else
1550
- // move next[prev[index]] to next[index] (head has no prev)
1551
- // move prev[next[index]] to prev[index]
1552
- // prev[index] = tail
1553
- // next[tail] = index
1554
- // tail = index
1555
- if (index !== this.#tail) {
1556
- if (index === this.#head) {
1557
- this.#head = this.#next[index];
1558
- }
1559
- else {
1560
- this.#connect(this.#prev[index], this.#next[index]);
1561
- }
1562
- this.#connect(this.#tail, index);
1563
- this.#tail = index;
1564
- }
1565
- }
1566
- /**
1567
- * Deletes a key out of the cache.
1568
- *
1569
- * Returns true if the key was deleted, false otherwise.
1570
- */
1571
- delete(k) {
1572
- return this.#delete(k, 'delete');
1573
- }
1574
- #delete(k, reason) {
1575
- if (metrics.hasSubscribers) {
1576
- metrics.publish({
1577
- op: 'delete',
1578
- delete: reason,
1579
- key: k,
1580
- });
1581
- }
1582
- let deleted = false;
1583
- if (this.#size !== 0) {
1584
- const index = this.#keyMap.get(k);
1585
- if (index !== undefined) {
1586
- if (this.#autopurgeTimers?.[index]) {
1587
- clearTimeout(this.#autopurgeTimers?.[index]);
1588
- this.#autopurgeTimers[index] = undefined;
1589
- }
1590
- deleted = true;
1591
- if (this.#size === 1) {
1592
- this.#clear(reason);
1593
- }
1594
- else {
1595
- this.#removeItemSize(index);
1596
- const v = this.#valList[index];
1597
- if (this.#isBackgroundFetch(v)) {
1598
- v.__abortController.abort(new Error('deleted'));
1599
- }
1600
- else if (this.#hasDispose || this.#hasDisposeAfter) {
1601
- if (this.#hasDispose) {
1602
- this.#dispose?.(v, k, reason);
1603
- }
1604
- if (this.#hasDisposeAfter) {
1605
- this.#disposed?.push([v, k, reason]);
1606
- }
1607
- }
1608
- this.#keyMap.delete(k);
1609
- this.#keyList[index] = undefined;
1610
- this.#valList[index] = undefined;
1611
- if (index === this.#tail) {
1612
- this.#tail = this.#prev[index];
1613
- }
1614
- else if (index === this.#head) {
1615
- this.#head = this.#next[index];
1616
- }
1617
- else {
1618
- const pi = this.#prev[index];
1619
- this.#next[pi] = this.#next[index];
1620
- const ni = this.#next[index];
1621
- this.#prev[ni] = this.#prev[index];
1622
- }
1623
- this.#size--;
1624
- this.#free.push(index);
1625
- }
1626
- }
1627
- }
1628
- if (this.#hasDisposeAfter && this.#disposed?.length) {
1629
- const dt = this.#disposed;
1630
- let task;
1631
- while ((task = dt?.shift())) {
1632
- this.#disposeAfter?.(...task);
1633
- }
1634
- }
1635
- return deleted;
1636
- }
1637
- /**
1638
- * Clear the cache entirely, throwing away all values.
1639
- */
1640
- clear() {
1641
- return this.#clear('delete');
1642
- }
1643
- #clear(reason) {
1644
- for (const index of this.#rindexes({ allowStale: true })) {
1645
- const v = this.#valList[index];
1646
- if (this.#isBackgroundFetch(v)) {
1647
- v.__abortController.abort(new Error('deleted'));
1648
- }
1649
- else {
1650
- const k = this.#keyList[index];
1651
- if (this.#hasDispose) {
1652
- this.#dispose?.(v, k, reason);
1653
- }
1654
- if (this.#hasDisposeAfter) {
1655
- this.#disposed?.push([v, k, reason]);
1656
- }
1657
- }
1658
- }
1659
- this.#keyMap.clear();
1660
- this.#valList.fill(undefined);
1661
- this.#keyList.fill(undefined);
1662
- if (this.#ttls && this.#starts) {
1663
- this.#ttls.fill(0);
1664
- this.#starts.fill(0);
1665
- for (const t of this.#autopurgeTimers ?? []) {
1666
- if (t !== undefined)
1667
- clearTimeout(t);
1668
- }
1669
- this.#autopurgeTimers?.fill(undefined);
1670
- }
1671
- if (this.#sizes) {
1672
- this.#sizes.fill(0);
1673
- }
1674
- this.#head = 0;
1675
- this.#tail = 0;
1676
- this.#free.length = 0;
1677
- this.#calculatedSize = 0;
1678
- this.#size = 0;
1679
- if (this.#hasDisposeAfter && this.#disposed) {
1680
- const dt = this.#disposed;
1681
- let task;
1682
- while ((task = dt?.shift())) {
1683
- this.#disposeAfter?.(...task);
1684
- }
1685
- }
1686
- }
1687
- }
1688
- //# sourceMappingURL=index.js.map