@zuplo/cli 6.69.4 → 6.69.5

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