skillfit 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (882) hide show
  1. package/CHANGELOG.md +78 -4
  2. package/README.md +129 -54
  3. package/README.zh-CN.md +124 -51
  4. package/benches/README.md +1 -3
  5. package/dist/agents/accounting.js +27 -10
  6. package/dist/agents/adapters/api.js +59 -32
  7. package/dist/agents/adapters/cli.js +239 -110
  8. package/dist/agents/adapters/codex-usage.js +54 -25
  9. package/dist/agents/adapters/kimi-usage.js +28 -19
  10. package/dist/agents/call-budget.js +76 -27
  11. package/dist/agents/call-limits.js +11 -7
  12. package/dist/agents/contracts.js +2 -2
  13. package/dist/agents/environment.js +46 -22
  14. package/dist/agents/execution.js +35 -17
  15. package/dist/agents/health.js +93 -68
  16. package/dist/agents/installed-skills.js +28 -9
  17. package/dist/agents/matrix.js +5 -3
  18. package/dist/agents/mcp-probe.js +157 -146
  19. package/dist/agents/observation/model-identity.js +96 -49
  20. package/dist/agents/observation/trigger-contract.js +40 -21
  21. package/dist/agents/observation/trigger-detection.js +100 -61
  22. package/dist/agents/preflight-contract.js +40 -20
  23. package/dist/agents/preflight.js +136 -70
  24. package/dist/agents/session-observation.js +39 -29
  25. package/dist/agents/timeout.js +19 -3
  26. package/dist/bench/authoring.js +324 -201
  27. package/dist/bench/claims.js +6 -3
  28. package/dist/bench/constants.js +1 -1
  29. package/dist/bench/controls.js +123 -91
  30. package/dist/bench/diagnostics.js +57 -24
  31. package/dist/bench/draft.js +136 -68
  32. package/dist/bench/gates/check.js +79 -69
  33. package/dist/bench/gates/error.js +26 -17
  34. package/dist/bench/gates/summary.js +7 -7
  35. package/dist/bench/gates/timeout.js +2 -2
  36. package/dist/bench/gates/verifier.js +12 -5
  37. package/dist/bench/location.js +18 -10
  38. package/dist/bench/output-layout.js +5 -5
  39. package/dist/bench/read.js +74 -42
  40. package/dist/bench/scope.js +56 -34
  41. package/dist/bench/source.js +32 -20
  42. package/dist/bench/templates.js +30 -22
  43. package/dist/cli/bench-check-report.js +34 -10
  44. package/dist/cli/bench-manage.js +6 -6
  45. package/dist/cli/bench.js +51 -37
  46. package/dist/cli/confirm.js +3 -3
  47. package/dist/cli/definition.js +172 -114
  48. package/dist/cli/doctor.js +14 -14
  49. package/dist/cli/eval-cli.js +3 -3
  50. package/dist/cli/eval-component.js +21 -7
  51. package/dist/cli/eval-display.js +87 -61
  52. package/dist/cli/eval-plan.js +7 -2
  53. package/dist/cli/eval-report.js +114 -83
  54. package/dist/cli/eval-single-arm-report.js +53 -33
  55. package/dist/cli/eval.js +2 -2
  56. package/dist/cli/evaluation-host.js +5 -5
  57. package/dist/cli/evaluation-report.js +1 -1
  58. package/dist/cli/main.js +351 -205
  59. package/dist/cli/mcp.js +7 -7
  60. package/dist/cli/report.js +40 -17
  61. package/dist/cli/trigger-summary.js +23 -23
  62. package/dist/cli.js +1 -1
  63. package/dist/commands/bench-draft.test.js +226 -96
  64. package/dist/commands/bench-source.test.js +70 -53
  65. package/dist/commands/bench.js +1 -1
  66. package/dist/commands/bundle.js +1 -1
  67. package/dist/commands/eval-api-failure.test.js +61 -28
  68. package/dist/commands/eval-cli.js +1 -1
  69. package/dist/commands/eval-export.js +1 -1
  70. package/dist/commands/eval-layout.test.js +148 -70
  71. package/dist/commands/eval-single-arm-replay.js +1 -1
  72. package/dist/commands/eval.js +1 -1
  73. package/dist/commands/evaluation-report.js +1 -1
  74. package/dist/commands/install.js +1 -1
  75. package/dist/composition.js +41 -20
  76. package/dist/configuration/bundle.js +109 -89
  77. package/dist/configuration/constants.js +1 -1
  78. package/dist/configuration/install.js +184 -112
  79. package/dist/configuration/setup.js +64 -41
  80. package/dist/configuration/transaction.js +13 -11
  81. package/dist/configuration/upstream.js +61 -43
  82. package/dist/evaluation/application/calibration.js +233 -84
  83. package/dist/evaluation/application/evaluation.js +166 -56
  84. package/dist/evaluation/application/export.js +107 -67
  85. package/dist/evaluation/application/planning.js +292 -114
  86. package/dist/evaluation/application/preflight-error.js +11 -4
  87. package/dist/evaluation/application/preflight.js +54 -21
  88. package/dist/evaluation/application/read.js +1 -1
  89. package/dist/evaluation/application/request.js +45 -21
  90. package/dist/evaluation/application/self-test.js +188 -75
  91. package/dist/evaluation/execution/activation.js +99 -69
  92. package/dist/evaluation/execution/budget.js +20 -9
  93. package/dist/evaluation/execution/control-executor.js +34 -16
  94. package/dist/evaluation/execution/interrupted.js +2 -2
  95. package/dist/evaluation/execution/judge.js +55 -28
  96. package/dist/evaluation/execution/mock-executor.js +8 -8
  97. package/dist/evaluation/execution/paired.js +112 -76
  98. package/dist/evaluation/execution/prompt.js +21 -15
  99. package/dist/evaluation/measurement/acceptance.js +143 -68
  100. package/dist/evaluation/measurement/costs.js +39 -29
  101. package/dist/evaluation/measurement/efficiency.js +51 -18
  102. package/dist/evaluation/measurement/invocation-costs.js +50 -29
  103. package/dist/evaluation/measurement/judge-protocol.js +16 -18
  104. package/dist/evaluation/measurement/paired-contract.js +4 -3
  105. package/dist/evaluation/measurement/policy.js +48 -31
  106. package/dist/evaluation/measurement/report.js +51 -43
  107. package/dist/evaluation/measurement/scope.js +25 -7
  108. package/dist/evaluation/measurement/statistics.js +7 -3
  109. package/dist/evaluation/measurement/trial-summary.js +20 -12
  110. package/dist/evaluation/measurement/trigger-summary.js +1 -1
  111. package/dist/evaluation/records/assess.js +4 -2
  112. package/dist/evaluation/records/audit.js +336 -202
  113. package/dist/evaluation/records/contracts.js +44 -21
  114. package/dist/evaluation/records/formats.js +36 -19
  115. package/dist/evaluation/records/input-snapshot.js +88 -53
  116. package/dist/evaluation/records/judge-audit.js +37 -31
  117. package/dist/evaluation/records/manifest.js +302 -223
  118. package/dist/evaluation/records/model-identity.js +39 -29
  119. package/dist/evaluation/records/read.js +125 -42
  120. package/dist/evaluation/records/replay-package.js +81 -48
  121. package/dist/evaluation/records/session.js +216 -92
  122. package/dist/evaluation/records/single-arm-audit.js +313 -195
  123. package/dist/evaluation/records/single-arm-read.js +235 -112
  124. package/dist/evaluation/targets/native-diff.js +22 -13
  125. package/dist/evaluation/targets/output-layout.js +6 -6
  126. package/dist/evaluation/targets/skill.js +16 -13
  127. package/dist/evaluation/targets/workspace.js +19 -19
  128. package/dist/harness/bench-location.test.js +21 -21
  129. package/dist/harness/executors/cli.js +1 -1
  130. package/dist/harness/hash.js +1 -1
  131. package/dist/harness/interruption.js +1 -1
  132. package/dist/harness/replay-package.js +1 -1
  133. package/dist/harness/single-arm-audit.js +1 -1
  134. package/dist/harness/verifier-timeout.test.js +63 -32
  135. package/dist/matrix/agents.json +29 -6
  136. package/dist/matrix/agents.schema.json +17 -3
  137. package/dist/resources/experiment.js +18 -16
  138. package/dist/resources/frontmatter.js +6 -6
  139. package/dist/resources/installed-skill.js +32 -22
  140. package/dist/resources/skill.js +10 -10
  141. package/dist/shared/backup.js +1 -1
  142. package/dist/shared/cancellation.js +10 -4
  143. package/dist/shared/command.js +8 -7
  144. package/dist/shared/digest.js +2 -2
  145. package/dist/shared/hash.js +9 -9
  146. package/dist/shared/input-directories.js +6 -5
  147. package/dist/shared/json.js +10 -6
  148. package/dist/shared/local-files.js +8 -10
  149. package/dist/shared/output-path.js +4 -4
  150. package/dist/shared/package-root.js +7 -5
  151. package/dist/shared/process-tree.js +38 -10
  152. package/dist/shared/process.js +20 -15
  153. package/dist/shared/read-json.js +3 -3
  154. package/dist/shared/timing.js +22 -11
  155. package/dist/shared/version.js +3 -3
  156. package/dist/usage/receipts.js +41 -27
  157. package/docs/README.md +18 -31
  158. package/docs/assets/skillfit-report.svg +17 -0
  159. package/docs/guides/bench-authoring.md +9 -4
  160. package/docs/guides/experiment-workflow.md +57 -20
  161. package/docs/guides/first-real-eval.md +59 -19
  162. package/docs/guides/selectable-codex.md +0 -2
  163. package/docs/maintainers/architecture.md +184 -222
  164. package/docs/maintainers/releases.md +11 -4
  165. package/docs/reference/eval-component.md +11 -7
  166. package/docs/reference/evaluation-reports.md +75 -88
  167. package/docs/reference/metrics.md +23 -10
  168. package/docs/schemas/eval-request.schema.json +2 -2
  169. package/package.json +10 -5
  170. package/skills/skillfit/SKILL.md +46 -25
  171. package/tools/verify/recipes/0.11.0-feature-smoke.mjs +491 -140
  172. package/tools/verify/recipes/release-docs-smoke.mjs +38 -21
  173. package/tools/verify/recipes/release-feature-smoke.mjs +187 -88
  174. package/benches/contrib/README.md +0 -73
  175. package/benches/contrib/oss-lru-cache/README.md +0 -27
  176. package/benches/contrib/oss-lru-cache/bench.json +0 -37
  177. package/benches/contrib/oss-lru-cache/provenance.json +0 -62
  178. package/benches/contrib/oss-lru-cache/runtime.mjs +0 -32
  179. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/LICENSE +0 -15
  180. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/README.md +0 -3
  181. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/index.js +0 -1044
  182. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/package.json +0 -11
  183. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/runtime.mjs +0 -32
  184. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/fixture/test.mjs +0 -11
  185. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/prompt.md +0 -5
  186. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/reference/LICENSE +0 -15
  187. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/reference/answer.md +0 -11
  188. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/reference/index.js +0 -1053
  189. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/reference/oracle.mjs +0 -8
  190. package/benches/contrib/oss-lru-cache/tasks/fetch-abort/verify.mjs +0 -3
  191. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/LICENSE.md +0 -55
  192. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/README.md +0 -3
  193. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/package.json +0 -11
  194. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/runtime.mjs +0 -32
  195. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/diagnostics-channel-browser.ts +0 -11
  196. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/diagnostics-channel-cjs.cts +0 -11
  197. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/diagnostics-channel-esm.mts +0 -29
  198. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/diagnostics-channel-node.ts +0 -7
  199. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/diagnostics-channel.ts +0 -6
  200. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/index.ts +0 -3148
  201. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/src/perf.ts +0 -17
  202. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/fixture/test.mjs +0 -11
  203. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/prompt.md +0 -5
  204. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/LICENSE.md +0 -55
  205. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/answer.md +0 -11
  206. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/oracle.mjs +0 -7
  207. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/diagnostics-channel-browser.ts +0 -11
  208. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/diagnostics-channel-cjs.cts +0 -11
  209. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/diagnostics-channel-esm.mts +0 -29
  210. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/diagnostics-channel-node.ts +0 -7
  211. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/diagnostics-channel.ts +0 -6
  212. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/index.ts +0 -3174
  213. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/reference/src/perf.ts +0 -17
  214. package/benches/contrib/oss-lru-cache/tasks/fetch-lifecycle/verify.mjs +0 -3
  215. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/LICENSE +0 -15
  216. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/README.md +0 -3
  217. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/index.js +0 -1028
  218. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/package.json +0 -11
  219. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/runtime.mjs +0 -32
  220. package/benches/contrib/oss-lru-cache/tasks/fetch-size/fixture/test.mjs +0 -11
  221. package/benches/contrib/oss-lru-cache/tasks/fetch-size/prompt.md +0 -5
  222. package/benches/contrib/oss-lru-cache/tasks/fetch-size/reference/LICENSE +0 -15
  223. package/benches/contrib/oss-lru-cache/tasks/fetch-size/reference/answer.md +0 -11
  224. package/benches/contrib/oss-lru-cache/tasks/fetch-size/reference/index.js +0 -1028
  225. package/benches/contrib/oss-lru-cache/tasks/fetch-size/reference/oracle.mjs +0 -7
  226. package/benches/contrib/oss-lru-cache/tasks/fetch-size/verify.mjs +0 -3
  227. package/benches/contrib/oss-lru-cache/verifiers/cases.mjs +0 -74
  228. package/benches/contrib/oss-lru-cache/verifiers/oracle.mjs +0 -9
  229. package/benches/contrib/oss-lru-cache/verifiers/probe.mjs +0 -14
  230. package/benches/contrib/oss-lru-cache/verifiers/shared.mjs +0 -131
  231. package/benches/contrib/oss-lru-cache/verifiers/test-reporter.mjs +0 -29
  232. package/benches/contrib/oss-mcp-use-utf8/LICENSE.upstream +0 -21
  233. package/benches/contrib/oss-mcp-use-utf8/README.md +0 -57
  234. package/benches/contrib/oss-mcp-use-utf8/bench.json +0 -16
  235. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/fixture/LICENSE +0 -21
  236. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/fixture/package.json +0 -3
  237. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/fixture/src/ext-apps-bridge.js +0 -3
  238. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/fixture/src/resolve-view-resource.ts +0 -96
  239. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/fixture/test/basic.test.mjs +0 -13
  240. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/prompt.md +0 -8
  241. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/reference/README.md +0 -5
  242. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/reference/oracle.mjs +0 -11
  243. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/reference/solutions/view-utf8/src/resolve-view-resource.ts +0 -96
  244. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/reference/solutions/view-utf8/test/utf8.regression.test.mjs +0 -14
  245. package/benches/contrib/oss-mcp-use-utf8/tasks/view-utf8/verify.mjs +0 -120
  246. package/benches/contrib/oss-minipass/README.md +0 -32
  247. package/benches/contrib/oss-minipass/bench.json +0 -43
  248. package/benches/contrib/oss-minipass/provenance.json +0 -87
  249. package/benches/contrib/oss-minipass/tasks/async-end/fixture/LICENSE +0 -15
  250. package/benches/contrib/oss-minipass/tasks/async-end/fixture/README.md +0 -717
  251. package/benches/contrib/oss-minipass/tasks/async-end/fixture/UPSTREAM.package.json +0 -39
  252. package/benches/contrib/oss-minipass/tasks/async-end/fixture/index.js +0 -615
  253. package/benches/contrib/oss-minipass/tasks/async-end/fixture/package.json +0 -8
  254. package/benches/contrib/oss-minipass/tasks/async-end/fixture/runtime.cjs +0 -11
  255. package/benches/contrib/oss-minipass/tasks/async-end/fixture/test.mjs +0 -16
  256. package/benches/contrib/oss-minipass/tasks/async-end/fixture/vendor/yallist/LICENSE +0 -15
  257. package/benches/contrib/oss-minipass/tasks/async-end/fixture/vendor/yallist/README.md +0 -204
  258. package/benches/contrib/oss-minipass/tasks/async-end/fixture/vendor/yallist/iterator.js +0 -8
  259. package/benches/contrib/oss-minipass/tasks/async-end/fixture/vendor/yallist/package.json +0 -29
  260. package/benches/contrib/oss-minipass/tasks/async-end/fixture/vendor/yallist/yallist.js +0 -426
  261. package/benches/contrib/oss-minipass/tasks/async-end/prompt.md +0 -3
  262. package/benches/contrib/oss-minipass/tasks/async-end/reference/LICENSE +0 -15
  263. package/benches/contrib/oss-minipass/tasks/async-end/reference/README.md +0 -717
  264. package/benches/contrib/oss-minipass/tasks/async-end/reference/UPSTREAM.package.json +0 -39
  265. package/benches/contrib/oss-minipass/tasks/async-end/reference/index.js +0 -622
  266. package/benches/contrib/oss-minipass/tasks/async-end/reference/oracle.mjs +0 -4
  267. package/benches/contrib/oss-minipass/tasks/async-end/reference/package.json +0 -8
  268. package/benches/contrib/oss-minipass/tasks/async-end/reference/regression.test.mjs +0 -10
  269. package/benches/contrib/oss-minipass/tasks/async-end/reference/runtime.cjs +0 -11
  270. package/benches/contrib/oss-minipass/tasks/async-end/reference/test.mjs +0 -16
  271. package/benches/contrib/oss-minipass/tasks/async-end/reference/vendor/yallist/LICENSE +0 -15
  272. package/benches/contrib/oss-minipass/tasks/async-end/reference/vendor/yallist/README.md +0 -204
  273. package/benches/contrib/oss-minipass/tasks/async-end/reference/vendor/yallist/iterator.js +0 -8
  274. package/benches/contrib/oss-minipass/tasks/async-end/reference/vendor/yallist/package.json +0 -29
  275. package/benches/contrib/oss-minipass/tasks/async-end/reference/vendor/yallist/yallist.js +0 -426
  276. package/benches/contrib/oss-minipass/tasks/async-end/verify.mjs +0 -2
  277. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/LICENSE +0 -15
  278. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/README.md +0 -613
  279. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/UPSTREAM.package.json +0 -39
  280. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/index.js +0 -594
  281. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/package.json +0 -8
  282. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/runtime.cjs +0 -11
  283. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/test.mjs +0 -16
  284. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/vendor/yallist/LICENSE +0 -15
  285. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/vendor/yallist/README.md +0 -204
  286. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/vendor/yallist/iterator.js +0 -8
  287. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/vendor/yallist/package.json +0 -29
  288. package/benches/contrib/oss-minipass/tasks/buffered-readable/fixture/vendor/yallist/yallist.js +0 -426
  289. package/benches/contrib/oss-minipass/tasks/buffered-readable/prompt.md +0 -3
  290. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/LICENSE +0 -15
  291. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/README.md +0 -613
  292. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/UPSTREAM.package.json +0 -39
  293. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/index.js +0 -596
  294. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/oracle.mjs +0 -4
  295. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/package.json +0 -8
  296. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/regression.test.mjs +0 -9
  297. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/runtime.cjs +0 -11
  298. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/test.mjs +0 -16
  299. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/vendor/yallist/LICENSE +0 -15
  300. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/vendor/yallist/README.md +0 -204
  301. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/vendor/yallist/iterator.js +0 -8
  302. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/vendor/yallist/package.json +0 -29
  303. package/benches/contrib/oss-minipass/tasks/buffered-readable/reference/vendor/yallist/yallist.js +0 -426
  304. package/benches/contrib/oss-minipass/tasks/buffered-readable/verify.mjs +0 -2
  305. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/LICENSE +0 -15
  306. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/README.md +0 -205
  307. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/UPSTREAM.package.json +0 -34
  308. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/index.js +0 -415
  309. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/package.json +0 -8
  310. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/runtime.cjs +0 -11
  311. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/test.mjs +0 -16
  312. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/vendor/yallist/LICENSE +0 -15
  313. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/vendor/yallist/README.md +0 -204
  314. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/vendor/yallist/iterator.js +0 -8
  315. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/vendor/yallist/package.json +0 -29
  316. package/benches/contrib/oss-minipass/tasks/end-listeners/fixture/vendor/yallist/yallist.js +0 -426
  317. package/benches/contrib/oss-minipass/tasks/end-listeners/prompt.md +0 -3
  318. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/LICENSE +0 -15
  319. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/README.md +0 -205
  320. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/UPSTREAM.package.json +0 -34
  321. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/index.js +0 -407
  322. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/oracle.mjs +0 -4
  323. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/package.json +0 -8
  324. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/regression.test.mjs +0 -9
  325. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/runtime.cjs +0 -11
  326. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/test.mjs +0 -16
  327. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/vendor/yallist/LICENSE +0 -15
  328. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/vendor/yallist/README.md +0 -204
  329. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/vendor/yallist/iterator.js +0 -8
  330. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/vendor/yallist/package.json +0 -29
  331. package/benches/contrib/oss-minipass/tasks/end-listeners/reference/vendor/yallist/yallist.js +0 -426
  332. package/benches/contrib/oss-minipass/tasks/end-listeners/verify.mjs +0 -2
  333. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/LICENSE +0 -15
  334. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/README.md +0 -613
  335. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/UPSTREAM.package.json +0 -39
  336. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/index.js +0 -538
  337. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/package.json +0 -8
  338. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/runtime.cjs +0 -11
  339. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/test.mjs +0 -16
  340. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/vendor/yallist/LICENSE +0 -15
  341. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/vendor/yallist/README.md +0 -204
  342. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/vendor/yallist/iterator.js +0 -8
  343. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/vendor/yallist/package.json +0 -29
  344. package/benches/contrib/oss-minipass/tasks/pipeline-order/fixture/vendor/yallist/yallist.js +0 -426
  345. package/benches/contrib/oss-minipass/tasks/pipeline-order/prompt.md +0 -3
  346. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/LICENSE +0 -15
  347. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/README.md +0 -613
  348. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/UPSTREAM.package.json +0 -39
  349. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/index.js +0 -545
  350. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/oracle.mjs +0 -4
  351. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/package.json +0 -8
  352. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/regression.test.mjs +0 -19
  353. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/runtime.cjs +0 -11
  354. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/test.mjs +0 -16
  355. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/vendor/yallist/LICENSE +0 -15
  356. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/vendor/yallist/README.md +0 -204
  357. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/vendor/yallist/iterator.js +0 -8
  358. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/vendor/yallist/package.json +0 -29
  359. package/benches/contrib/oss-minipass/tasks/pipeline-order/reference/vendor/yallist/yallist.js +0 -426
  360. package/benches/contrib/oss-minipass/tasks/pipeline-order/verify.mjs +0 -2
  361. package/benches/contrib/oss-minipass/upstream/async-end.patch +0 -83
  362. package/benches/contrib/oss-minipass/upstream/buffered-readable.patch +0 -79
  363. package/benches/contrib/oss-minipass/upstream/end-listeners.patch +0 -77
  364. package/benches/contrib/oss-minipass/upstream/pipeline-order.patch +0 -173
  365. package/benches/contrib/oss-minipass/verifiers/cases.mjs +0 -88
  366. package/benches/contrib/oss-minipass/verifiers/grade.mjs +0 -35
  367. package/benches/contrib/oss-minipass/verifiers/probe.mjs +0 -10
  368. package/benches/contrib/oss-minipass/verifiers/regression-evidence.mjs +0 -98
  369. package/benches/contrib/oss-minipass/verifiers/test-reporter.mjs +0 -29
  370. package/benches/contrib/oss-normalize-url/README.md +0 -31
  371. package/benches/contrib/oss-normalize-url/bench.json +0 -16
  372. package/benches/contrib/oss-normalize-url/provenance.json +0 -41
  373. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/index.d.ts +0 -303
  374. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/index.js +0 -285
  375. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/license +0 -9
  376. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/package.json +0 -57
  377. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/readme.md +0 -312
  378. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/test.js +0 -427
  379. package/benches/contrib/oss-normalize-url/tasks/query-shape/fixture/test.mjs +0 -4
  380. package/benches/contrib/oss-normalize-url/tasks/query-shape/prompt.md +0 -7
  381. package/benches/contrib/oss-normalize-url/tasks/query-shape/reference/index.js +0 -294
  382. package/benches/contrib/oss-normalize-url/tasks/query-shape/reference/license +0 -9
  383. package/benches/contrib/oss-normalize-url/tasks/query-shape/reference/oracle.mjs +0 -7
  384. package/benches/contrib/oss-normalize-url/tasks/query-shape/reference/query-shape.md +0 -12
  385. package/benches/contrib/oss-normalize-url/tasks/query-shape/reference/query-shape.regression.test.mjs +0 -6
  386. package/benches/contrib/oss-normalize-url/tasks/query-shape/verify.mjs +0 -40
  387. package/benches/contrib/oss-normalize-url/verifiers/cases.mjs +0 -26
  388. package/benches/contrib/oss-normalize-url/verifiers/probe.mjs +0 -10
  389. package/benches/contrib/oss-normalize-url/verifiers/regression-evidence.mjs +0 -98
  390. package/benches/contrib/oss-normalize-url/verifiers/test-reporter.mjs +0 -29
  391. package/benches/contrib/oss-skill-followup/README.md +0 -54
  392. package/benches/contrib/oss-skill-followup/bench.json +0 -79
  393. package/benches/contrib/oss-skill-followup/provenance.json +0 -730
  394. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/LICENSE +0 -11
  395. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/README.md +0 -61
  396. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/index.js +0 -93
  397. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/package.json +0 -9
  398. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/test-clock.mjs +0 -64
  399. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/test.mjs +0 -22
  400. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/fixture/upstream-package.json +0 -47
  401. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/prompt.md +0 -3
  402. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/reference/index.js +0 -97
  403. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/reference/oracle.mjs +0 -1
  404. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/reference/regression.test.mjs +0 -2
  405. package/benches/contrib/oss-skill-followup/tasks/debounce-context-classes/verify.mjs +0 -1
  406. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/LICENSE +0 -21
  407. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/README.md +0 -69
  408. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/index.js +0 -70
  409. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/package.json +0 -9
  410. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/test-clock.mjs +0 -64
  411. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/test.mjs +0 -22
  412. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/fixture/upstream-package.json +0 -27
  413. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/prompt.md +0 -3
  414. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/reference/index.js +0 -72
  415. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/reference/oracle.mjs +0 -1
  416. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/reference/regression.test.mjs +0 -2
  417. package/benches/contrib/oss-skill-followup/tasks/debounce-recursive-args/verify.mjs +0 -1
  418. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/LICENSE +0 -23
  419. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/README.md +0 -46
  420. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/index.js +0 -56
  421. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/package.json +0 -9
  422. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/test-clock.mjs +0 -64
  423. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/test.mjs +0 -22
  424. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/fixture/upstream-package.json +0 -22
  425. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/prompt.md +0 -3
  426. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/reference/index.js +0 -56
  427. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/reference/oracle.mjs +0 -1
  428. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/reference/regression.test.mjs +0 -2
  429. package/benches/contrib/oss-skill-followup/tasks/debounce-timer-boundary/verify.mjs +0 -1
  430. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/LICENSE +0 -24
  431. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/README.md +0 -469
  432. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/index.js +0 -1645
  433. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/package.json +0 -9
  434. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/test-clock.mjs +0 -64
  435. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/test.mjs +0 -22
  436. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/fixture/upstream-package.json +0 -86
  437. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/prompt.md +0 -3
  438. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/reference/index.js +0 -1643
  439. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/reference/oracle.mjs +0 -1
  440. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/reference/regression.test.mjs +0 -2
  441. package/benches/contrib/oss-skill-followup/tasks/duration-large-digits/verify.mjs +0 -1
  442. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/LICENSE +0 -24
  443. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/README.md +0 -470
  444. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/index.js +0 -1676
  445. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/package.json +0 -9
  446. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/test-clock.mjs +0 -64
  447. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/test.mjs +0 -22
  448. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/fixture/upstream-package.json +0 -86
  449. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/prompt.md +0 -3
  450. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/reference/index.js +0 -1676
  451. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/reference/oracle.mjs +0 -1
  452. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/reference/regression.test.mjs +0 -2
  453. package/benches/contrib/oss-skill-followup/tasks/duration-plural-count/verify.mjs +0 -1
  454. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/LICENSE +0 -9
  455. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/README.md +0 -136
  456. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/index.js +0 -153
  457. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/package.json +0 -9
  458. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/test-clock.mjs +0 -64
  459. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/test.mjs +0 -22
  460. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/fixture/upstream-package.json +0 -53
  461. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/prompt.md +0 -3
  462. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/reference/index.js +0 -155
  463. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/reference/oracle.mjs +0 -1
  464. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/reference/regression.test.mjs +0 -2
  465. package/benches/contrib/oss-skill-followup/tasks/promise-falsy-rejection/verify.mjs +0 -1
  466. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/LICENSE +0 -9
  467. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/README.md +0 -92
  468. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/index.js +0 -57
  469. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/package.json +0 -9
  470. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/test-clock.mjs +0 -64
  471. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/test.mjs +0 -22
  472. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/fixture/upstream-package.json +0 -53
  473. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/prompt.md +0 -3
  474. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/reference/index.js +0 -57
  475. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/reference/oracle.mjs +0 -1
  476. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/reference/regression.test.mjs +0 -2
  477. package/benches/contrib/oss-skill-followup/tasks/promise-method-context/verify.mjs +0 -1
  478. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/LICENSE +0 -9
  479. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/README.md +0 -102
  480. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/index.js +0 -117
  481. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/package.json +0 -9
  482. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/test-clock.mjs +0 -64
  483. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/test.mjs +0 -22
  484. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/fixture/upstream-package.json +0 -53
  485. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/prompt.md +0 -3
  486. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/reference/index.js +0 -112
  487. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/reference/oracle.mjs +0 -1
  488. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/reference/regression.test.mjs +0 -2
  489. package/benches/contrib/oss-skill-followup/tasks/promise-overlap-results/verify.mjs +0 -1
  490. package/benches/contrib/oss-skill-followup/test-clock.mjs +0 -64
  491. package/benches/contrib/oss-skill-followup/verifiers/cases.mjs +0 -214
  492. package/benches/contrib/oss-skill-followup/verifiers/grade.mjs +0 -35
  493. package/benches/contrib/oss-skill-followup/verifiers/probe.mjs +0 -10
  494. package/benches/contrib/oss-skill-followup/verifiers/regression-evidence.mjs +0 -98
  495. package/benches/contrib/oss-skill-followup/verifiers/test-reporter.mjs +0 -29
  496. package/benches/contrib/oss-skill-independent/README.md +0 -61
  497. package/benches/contrib/oss-skill-independent/bench.json +0 -79
  498. package/benches/contrib/oss-skill-independent/provenance.json +0 -1903
  499. package/benches/contrib/oss-skill-independent/task-specs.json +0 -63
  500. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/LICENSE +0 -22
  501. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/Readme.md +0 -1015
  502. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/esm.mjs +0 -15
  503. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/index.js +0 -27
  504. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/argument.js +0 -147
  505. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/command.js +0 -1944
  506. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/error.js +0 -45
  507. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/help.js +0 -396
  508. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/option.js +0 -208
  509. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/lib/suggestSimilar.js +0 -100
  510. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/package-support.json +0 -16
  511. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/package.json +0 -63
  512. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/test-clock.mjs +0 -65
  513. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/test.mjs +0 -4
  514. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/typings/index.d.ts +0 -774
  515. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/typings/index.test-d.ts +0 -416
  516. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/fixture/upstream-package.json +0 -69
  517. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/prompt.md +0 -3
  518. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/LICENSE +0 -22
  519. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/Readme.md +0 -1015
  520. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/esm.mjs +0 -15
  521. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/index.js +0 -27
  522. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/argument.js +0 -147
  523. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/command.js +0 -1948
  524. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/error.js +0 -45
  525. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/help.js +0 -396
  526. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/option.js +0 -208
  527. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/lib/suggestSimilar.js +0 -100
  528. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/oracle.mjs +0 -1
  529. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/package-support.json +0 -16
  530. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/package.json +0 -63
  531. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/regression.test.mjs +0 -5
  532. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/test-clock.mjs +0 -65
  533. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/test.mjs +0 -4
  534. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/typings/index.d.ts +0 -774
  535. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/typings/index.test-d.ts +0 -416
  536. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/reference/upstream-package.json +0 -69
  537. package/benches/contrib/oss-skill-independent/tasks/commander-async-listener-order/verify.mjs +0 -1
  538. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/LICENSE +0 -22
  539. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/Readme.md +0 -1149
  540. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/esm.mjs +0 -16
  541. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/index.js +0 -24
  542. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/argument.js +0 -149
  543. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/command.js +0 -2662
  544. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/error.js +0 -39
  545. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/help.js +0 -713
  546. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/option.js +0 -367
  547. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/lib/suggestSimilar.js +0 -101
  548. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/package-support.json +0 -16
  549. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/package.json +0 -71
  550. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/test-clock.mjs +0 -65
  551. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/test.mjs +0 -4
  552. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/typings/esm.d.mts +0 -3
  553. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/typings/index.d.ts +0 -1045
  554. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/typings/index.test-d.ts +0 -737
  555. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/fixture/upstream-package.json +0 -82
  556. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/prompt.md +0 -3
  557. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/LICENSE +0 -22
  558. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/Readme.md +0 -1149
  559. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/esm.mjs +0 -16
  560. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/index.js +0 -24
  561. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/argument.js +0 -149
  562. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/command.js +0 -2666
  563. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/error.js +0 -39
  564. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/help.js +0 -713
  565. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/option.js +0 -367
  566. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/lib/suggestSimilar.js +0 -101
  567. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/oracle.mjs +0 -1
  568. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/package-support.json +0 -16
  569. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/package.json +0 -71
  570. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/regression.test.mjs +0 -5
  571. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/test-clock.mjs +0 -65
  572. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/test.mjs +0 -4
  573. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/typings/esm.d.mts +0 -3
  574. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/typings/index.d.ts +0 -1045
  575. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/typings/index.test-d.ts +0 -737
  576. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/reference/upstream-package.json +0 -82
  577. package/benches/contrib/oss-skill-independent/tasks/commander-output-isolation/verify.mjs +0 -1
  578. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/index.d.ts +0 -40
  579. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/index.js +0 -68
  580. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/license +0 -9
  581. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/package.json +0 -54
  582. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/readme.md +0 -99
  583. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/test-clock.mjs +0 -65
  584. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/test.mjs +0 -4
  585. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/upstream-package.json +0 -54
  586. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/vendor/yocto-queue/index.js +0 -67
  587. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/vendor/yocto-queue/license +0 -9
  588. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/fixture/vendor/yocto-queue/package.json +0 -46
  589. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/prompt.md +0 -3
  590. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/async-hooks-stub.js +0 -15
  591. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/index.d.ts +0 -40
  592. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/index.js +0 -71
  593. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/license +0 -9
  594. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/oracle.mjs +0 -1
  595. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/package.json +0 -61
  596. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/readme.md +0 -99
  597. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/regression.test.mjs +0 -6
  598. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/test-clock.mjs +0 -65
  599. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/test.mjs +0 -4
  600. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/upstream-package.json +0 -54
  601. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/vendor/yocto-queue/index.js +0 -67
  602. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/vendor/yocto-queue/license +0 -9
  603. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/reference/vendor/yocto-queue/package.json +0 -46
  604. package/benches/contrib/oss-skill-independent/tasks/limit-async-context/verify.mjs +0 -1
  605. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/index.d.ts +0 -136
  606. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/index.js +0 -132
  607. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/license +0 -9
  608. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/package.json +0 -57
  609. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/readme.md +0 -181
  610. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/test-clock.mjs +0 -65
  611. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/test.mjs +0 -4
  612. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/upstream-package.json +0 -58
  613. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/vendor/yocto-queue/index.js +0 -84
  614. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/vendor/yocto-queue/license +0 -9
  615. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/fixture/vendor/yocto-queue/package.json +0 -48
  616. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/prompt.md +0 -3
  617. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/index.d.ts +0 -136
  618. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/index.js +0 -148
  619. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/license +0 -9
  620. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/oracle.mjs +0 -1
  621. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/package.json +0 -57
  622. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/readme.md +0 -181
  623. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/regression.test.mjs +0 -5
  624. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/test-clock.mjs +0 -65
  625. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/test.mjs +0 -4
  626. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/upstream-package.json +0 -58
  627. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/vendor/yocto-queue/index.js +0 -84
  628. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/vendor/yocto-queue/license +0 -9
  629. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/reference/vendor/yocto-queue/package.json +0 -48
  630. package/benches/contrib/oss-skill-independent/tasks/limit-map-iteration-rejection/verify.mjs +0 -1
  631. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/index.d.ts +0 -136
  632. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/index.js +0 -116
  633. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/license +0 -9
  634. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/package.json +0 -60
  635. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/readme.md +0 -170
  636. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/test-clock.mjs +0 -65
  637. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/test.mjs +0 -4
  638. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/fixture/upstream-package.json +0 -60
  639. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/prompt.md +0 -3
  640. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/index.d.ts +0 -136
  641. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/index.js +0 -121
  642. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/license +0 -9
  643. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/oracle.mjs +0 -1
  644. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/package.json +0 -60
  645. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/readme.md +0 -170
  646. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/regression.test.mjs +0 -6
  647. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/test-clock.mjs +0 -65
  648. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/test.mjs +0 -4
  649. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/reference/upstream-package.json +0 -60
  650. package/benches/contrib/oss-skill-independent/tasks/throttle-sync-throw/verify.mjs +0 -1
  651. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/index.d.ts +0 -149
  652. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/index.js +0 -93
  653. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/license +0 -9
  654. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/package.json +0 -52
  655. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/readme.md +0 -192
  656. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/test-clock.mjs +0 -65
  657. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/test.mjs +0 -4
  658. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/fixture/upstream-package.json +0 -52
  659. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/prompt.md +0 -3
  660. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/index.d.ts +0 -149
  661. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/index.js +0 -95
  662. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/license +0 -9
  663. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/oracle.mjs +0 -1
  664. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/package.json +0 -52
  665. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/readme.md +0 -192
  666. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/regression.test.mjs +0 -5
  667. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/test-clock.mjs +0 -65
  668. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/test.mjs +0 -4
  669. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/reference/upstream-package.json +0 -52
  670. package/benches/contrib/oss-skill-independent/tasks/timeout-custom-timers/verify.mjs +0 -1
  671. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/index.d.ts +0 -151
  672. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/index.js +0 -114
  673. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/license +0 -9
  674. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/package.json +0 -48
  675. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/readme.md +0 -158
  676. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/test-clock.mjs +0 -65
  677. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/test.mjs +0 -4
  678. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/fixture/upstream-package.json +0 -48
  679. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/prompt.md +0 -3
  680. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/index.d.ts +0 -151
  681. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/index.js +0 -114
  682. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/license +0 -9
  683. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/oracle.mjs +0 -1
  684. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/package.json +0 -48
  685. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/readme.md +0 -158
  686. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/regression.test.mjs +0 -5
  687. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/test-clock.mjs +0 -65
  688. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/test.mjs +0 -4
  689. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/reference/upstream-package.json +0 -48
  690. package/benches/contrib/oss-skill-independent/tasks/timeout-infinity-abort/verify.mjs +0 -1
  691. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/index.d.ts +0 -151
  692. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/index.js +0 -122
  693. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/license +0 -9
  694. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/package.json +0 -50
  695. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/readme.md +0 -190
  696. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/test-clock.mjs +0 -65
  697. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/test.mjs +0 -4
  698. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/fixture/upstream-package.json +0 -50
  699. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/prompt.md +0 -3
  700. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/index.d.ts +0 -151
  701. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/index.js +0 -122
  702. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/license +0 -9
  703. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/oracle.mjs +0 -1
  704. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/package.json +0 -50
  705. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/readme.md +0 -190
  706. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/regression.test.mjs +0 -5
  707. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/test-clock.mjs +0 -65
  708. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/test.mjs +0 -4
  709. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/reference/upstream-package.json +0 -50
  710. package/benches/contrib/oss-skill-independent/tasks/timeout-rejection-listener/verify.mjs +0 -1
  711. package/benches/contrib/oss-skill-independent/test-clock.mjs +0 -65
  712. package/benches/contrib/oss-skill-independent/verifiers/cases.mjs +0 -197
  713. package/benches/contrib/oss-skill-independent/verifiers/grade.mjs +0 -48
  714. package/benches/contrib/oss-skill-independent/verifiers/probe.mjs +0 -16
  715. package/benches/contrib/oss-skill-independent/verifiers/regression-evidence.mjs +0 -105
  716. package/benches/contrib/oss-skill-independent/verifiers/test-reporter.mjs +0 -29
  717. package/benches/contrib/oss-skill-validation/README.md +0 -32
  718. package/benches/contrib/oss-skill-validation/bench.json +0 -79
  719. package/benches/contrib/oss-skill-validation/provenance.json +0 -119
  720. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/UPSTREAM.package.json +0 -57
  721. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/index.js +0 -281
  722. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/license +0 -9
  723. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/package.json +0 -8
  724. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/readme.md +0 -169
  725. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/fixture/test.mjs +0 -5
  726. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/prompt.md +0 -3
  727. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/UPSTREAM.package.json +0 -57
  728. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/index.js +0 -281
  729. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/license +0 -9
  730. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/oracle.mjs +0 -4
  731. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/package.json +0 -8
  732. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/readme.md +0 -169
  733. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/regression.test.mjs +0 -115
  734. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/reference/test.mjs +0 -5
  735. package/benches/contrib/oss-skill-validation/tasks/async-concurrency/verify.mjs +0 -2
  736. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/UPSTREAM.package.json +0 -57
  737. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/index.js +0 -661
  738. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/license +0 -9
  739. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/package.json +0 -8
  740. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/readme.md +0 -404
  741. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/fixture/test.mjs +0 -5
  742. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/prompt.md +0 -3
  743. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/UPSTREAM.package.json +0 -57
  744. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/index.js +0 -663
  745. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/license +0 -9
  746. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/oracle.mjs +0 -4
  747. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/package.json +0 -8
  748. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/readme.md +0 -404
  749. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/regression.test.mjs +0 -115
  750. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/reference/test.mjs +0 -5
  751. package/benches/contrib/oss-skill-validation/tasks/cold-thenable/verify.mjs +0 -2
  752. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/UPSTREAM.package.json +0 -57
  753. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/index.js +0 -288
  754. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/license +0 -9
  755. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/package.json +0 -8
  756. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/readme.md +0 -190
  757. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/fixture/test.mjs +0 -5
  758. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/prompt.md +0 -3
  759. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/UPSTREAM.package.json +0 -57
  760. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/index.js +0 -293
  761. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/license +0 -9
  762. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/oracle.mjs +0 -4
  763. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/package.json +0 -8
  764. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/readme.md +0 -190
  765. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/regression.test.mjs +0 -115
  766. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/reference/test.mjs +0 -5
  767. package/benches/contrib/oss-skill-validation/tasks/consumer-stop/verify.mjs +0 -2
  768. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/UPSTREAM.package.json +0 -57
  769. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/index.js +0 -283
  770. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/license +0 -9
  771. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/package.json +0 -8
  772. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/readme.md +0 -190
  773. package/benches/contrib/oss-skill-validation/tasks/mapper-index/fixture/test.mjs +0 -5
  774. package/benches/contrib/oss-skill-validation/tasks/mapper-index/prompt.md +0 -3
  775. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/UPSTREAM.package.json +0 -57
  776. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/index.js +0 -284
  777. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/license +0 -9
  778. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/oracle.mjs +0 -4
  779. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/package.json +0 -8
  780. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/readme.md +0 -190
  781. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/regression.test.mjs +0 -115
  782. package/benches/contrib/oss-skill-validation/tasks/mapper-index/reference/test.mjs +0 -5
  783. package/benches/contrib/oss-skill-validation/tasks/mapper-index/verify.mjs +0 -2
  784. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/UPSTREAM.package.json +0 -57
  785. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/index.js +0 -300
  786. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/license +0 -9
  787. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/package.json +0 -8
  788. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/readme.md +0 -190
  789. package/benches/contrib/oss-skill-validation/tasks/source-close/fixture/test.mjs +0 -5
  790. package/benches/contrib/oss-skill-validation/tasks/source-close/prompt.md +0 -3
  791. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/UPSTREAM.package.json +0 -57
  792. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/index.js +0 -310
  793. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/license +0 -9
  794. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/oracle.mjs +0 -4
  795. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/package.json +0 -8
  796. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/readme.md +0 -190
  797. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/regression.test.mjs +0 -115
  798. package/benches/contrib/oss-skill-validation/tasks/source-close/reference/test.mjs +0 -5
  799. package/benches/contrib/oss-skill-validation/tasks/source-close/verify.mjs +0 -2
  800. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/UPSTREAM.package.json +0 -57
  801. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/index.js +0 -293
  802. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/license +0 -9
  803. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/package.json +0 -8
  804. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/readme.md +0 -190
  805. package/benches/contrib/oss-skill-validation/tasks/source-error/fixture/test.mjs +0 -5
  806. package/benches/contrib/oss-skill-validation/tasks/source-error/prompt.md +0 -3
  807. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/UPSTREAM.package.json +0 -57
  808. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/index.js +0 -292
  809. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/license +0 -9
  810. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/oracle.mjs +0 -4
  811. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/package.json +0 -8
  812. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/readme.md +0 -190
  813. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/regression.test.mjs +0 -115
  814. package/benches/contrib/oss-skill-validation/tasks/source-error/reference/test.mjs +0 -5
  815. package/benches/contrib/oss-skill-validation/tasks/source-error/verify.mjs +0 -2
  816. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/UPSTREAM.package.json +0 -51
  817. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/index.js +0 -261
  818. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/license +0 -9
  819. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/package.json +0 -8
  820. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/readme.md +0 -143
  821. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/fixture/test.mjs +0 -5
  822. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/prompt.md +0 -3
  823. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/UPSTREAM.package.json +0 -51
  824. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/index.js +0 -265
  825. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/license +0 -9
  826. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/oracle.mjs +0 -4
  827. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/package.json +0 -8
  828. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/readme.md +0 -143
  829. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/regression.test.mjs +0 -115
  830. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/reference/test.mjs +0 -5
  831. package/benches/contrib/oss-skill-validation/tasks/ttl-duration/verify.mjs +0 -2
  832. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/UPSTREAM.package.json +0 -51
  833. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/index.js +0 -261
  834. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/license +0 -9
  835. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/package.json +0 -8
  836. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/readme.md +0 -143
  837. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/fixture/test.mjs +0 -5
  838. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/prompt.md +0 -3
  839. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/UPSTREAM.package.json +0 -51
  840. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/index.js +0 -261
  841. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/license +0 -9
  842. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/oracle.mjs +0 -4
  843. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/package.json +0 -8
  844. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/readme.md +0 -143
  845. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/regression.test.mjs +0 -115
  846. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/reference/test.mjs +0 -5
  847. package/benches/contrib/oss-skill-validation/tasks/ttl-refresh/verify.mjs +0 -2
  848. package/benches/contrib/oss-skill-validation/upstream/async-concurrency.patch +0 -77
  849. package/benches/contrib/oss-skill-validation/upstream/cold-thenable.patch +0 -162
  850. package/benches/contrib/oss-skill-validation/upstream/consumer-stop.patch +0 -217
  851. package/benches/contrib/oss-skill-validation/upstream/mapper-index.patch +0 -48
  852. package/benches/contrib/oss-skill-validation/upstream/source-close.patch +0 -179
  853. package/benches/contrib/oss-skill-validation/upstream/source-error.patch +0 -132
  854. package/benches/contrib/oss-skill-validation/upstream/ttl-duration.patch +0 -73
  855. package/benches/contrib/oss-skill-validation/upstream/ttl-refresh.patch +0 -41
  856. package/benches/contrib/oss-skill-validation/verifiers/cases.mjs +0 -111
  857. package/benches/contrib/oss-skill-validation/verifiers/grade.mjs +0 -35
  858. package/benches/contrib/oss-skill-validation/verifiers/probe.mjs +0 -10
  859. package/benches/contrib/oss-skill-validation/verifiers/regression-evidence.mjs +0 -98
  860. package/benches/contrib/oss-skill-validation/verifiers/test-reporter.mjs +0 -29
  861. package/benches/contrib/waza-behavior/LICENSE.upstream +0 -21
  862. package/benches/contrib/waza-behavior/README.md +0 -36
  863. package/benches/contrib/waza-behavior/bench.json +0 -34
  864. package/benches/contrib/waza-behavior/tasks/explicit-hold/fixture/README.md +0 -1
  865. package/benches/contrib/waza-behavior/tasks/explicit-hold/fixture/notes.txt +0 -1
  866. package/benches/contrib/waza-behavior/tasks/explicit-hold/prompt.md +0 -1
  867. package/benches/contrib/waza-behavior/tasks/receipt-current/fixture/README.md +0 -1
  868. package/benches/contrib/waza-behavior/tasks/receipt-current/fixture/docs/guide.md +0 -2
  869. package/benches/contrib/waza-behavior/tasks/receipt-current/fixture/notes.txt +0 -1
  870. package/benches/contrib/waza-behavior/tasks/receipt-current/fixture/scripts/check-links.mjs +0 -16
  871. package/benches/contrib/waza-behavior/tasks/receipt-current/fixture/validation-receipt.json +0 -10
  872. package/benches/contrib/waza-behavior/tasks/receipt-current/prompt.md +0 -1
  873. package/benches/contrib/waza-behavior/tasks/receipt-stale/fixture/README.md +0 -1
  874. package/benches/contrib/waza-behavior/tasks/receipt-stale/fixture/docs/guide.md +0 -3
  875. package/benches/contrib/waza-behavior/tasks/receipt-stale/fixture/notes.txt +0 -1
  876. package/benches/contrib/waza-behavior/tasks/receipt-stale/fixture/scripts/check-links.mjs +0 -16
  877. package/benches/contrib/waza-behavior/tasks/receipt-stale/fixture/validation-receipt.json +0 -10
  878. package/benches/contrib/waza-behavior/tasks/receipt-stale/prompt.md +0 -1
  879. package/benches/contrib/waza-behavior/verifiers/behavior.mjs +0 -59
  880. package/benches/contrib/waza-behavior/verifiers/oracle.mjs +0 -24
  881. package/docs/examples/documentation-policy.invalid.json +0 -40
  882. package/docs/examples/documentation-policy.valid.json +0 -40
@@ -1,3174 +0,0 @@
1
- /**
2
- * @module LRUCache
3
- */
4
-
5
- import { metrics, tracing } from './diagnostics-channel.js'
6
- import { defaultPerf } from './perf.js'
7
- import type { Perf } from './perf.js'
8
- export type { Perf } from './perf.js'
9
-
10
- const hasSubscribers = () =>
11
- metrics.hasSubscribers || tracing.hasSubscribers
12
-
13
- const warned = new Set<string>()
14
-
15
- // either a function or a class
16
- // oxlint-disable-next-line no-explicit-any
17
- type ForC = ((...a: any[]) => any) | { new (...a: any[]): any }
18
-
19
- /* c8 ignore start */
20
- const PROCESS = (
21
- typeof process === 'object' && !!process ?
22
- process
23
- : {}) as { [k: string]: unknown }
24
- /* c8 ignore stop */
25
-
26
- const emitWarning = (
27
- msg: string,
28
- type: string,
29
- code: string,
30
- fn: ForC,
31
- ) => {
32
- if (typeof PROCESS.emitWarning === 'function') {
33
- PROCESS.emitWarning(msg, type, code, fn)
34
- } else {
35
- //oxlint-disable-next-line no-console
36
- console.error(`[${code}] ${type}: ${msg}`)
37
- }
38
- }
39
- const shouldWarn = (code: string) => !warned.has(code)
40
-
41
- const TYPE = Symbol('type')
42
- export type PosInt = number & { [TYPE]: 'Positive Integer' }
43
- export type Index = number & { [TYPE]: 'LRUCache Index' }
44
-
45
- const isPosInt = (n: unknown): n is PosInt =>
46
- !!n && n === Math.floor(n as number) && n > 0 && isFinite(n)
47
-
48
- export type UintArray = Uint8Array | Uint16Array | Uint32Array
49
- export type NumberArray = UintArray | number[]
50
-
51
- // This is a little bit ridiculous, tbh.
52
- // The maximum array length is 2^32-1 or thereabouts on most JS impls.
53
- // And well before that point, you're caching the entire world, I mean,
54
- // that's ~32GB of just integers for the next/prev links, plus whatever
55
- // else to hold that many keys and values. Just filling the memory with
56
- // zeroes at init time is brutal when you get that big.
57
- // But why not be complete?
58
- // Maybe in the future, these limits will have expanded.
59
- /* c8 ignore start */
60
- const getUintArray = (max: number) =>
61
- !isPosInt(max) ? null
62
- : max <= Math.pow(2, 8) ? Uint8Array
63
- : max <= Math.pow(2, 16) ? Uint16Array
64
- : max <= Math.pow(2, 32) ? Uint32Array
65
- : max <= Number.MAX_SAFE_INTEGER ? ZeroArray
66
- : null
67
- /* c8 ignore stop */
68
-
69
- class ZeroArray extends Array<number> {
70
- constructor(size: number) {
71
- super(size)
72
- this.fill(0)
73
- }
74
- }
75
- export type { ZeroArray }
76
- export type { Stack }
77
-
78
- export type StackLike = Stack | Index[]
79
- class Stack {
80
- /* c8 ignore start - not sure why this is showing up uncovered?? */
81
- heap: NumberArray
82
- /* c8 ignore stop */
83
- length: number
84
- // private constructor
85
- static #constructing: boolean = false
86
- static create(max: number): StackLike {
87
- const HeapCls = getUintArray(max)
88
- if (!HeapCls) return []
89
- Stack.#constructing = true
90
- const s = new Stack(max, HeapCls)
91
- Stack.#constructing = false
92
- return s
93
- }
94
- constructor(max: number, HeapCls: { new (n: number): NumberArray }) {
95
- /* c8 ignore start */
96
- if (!Stack.#constructing) {
97
- throw new TypeError('instantiate Stack using Stack.create(n)')
98
- }
99
- /* c8 ignore stop */
100
- this.heap = new HeapCls(max)
101
- this.length = 0
102
- }
103
- push(n: Index) {
104
- this.heap[this.length++] = n
105
- }
106
- pop(): Index {
107
- return this.heap[--this.length] as Index
108
- }
109
- }
110
-
111
- /**
112
- * Promise representing an in-progress {@link LRUCache#fetch} call
113
- */
114
- export type BackgroundFetch<V> = Promise<V | undefined> & {
115
- __returned: BackgroundFetch<V> | undefined
116
- __abortController: AbortController
117
- __staleWhileFetching: V | undefined
118
- }
119
-
120
- export type DisposeTask<K, V> = [
121
- value: V,
122
- key: K,
123
- reason: LRUCache.DisposeReason,
124
- ]
125
-
126
- export namespace LRUCache {
127
- /**
128
- * An integer greater than 0, reflecting the calculated size of items
129
- */
130
- export type Size = number
131
-
132
- /**
133
- * Integer greater than 0, representing some number of milliseconds, or the
134
- * time at which a TTL started counting from.
135
- */
136
- export type Milliseconds = number
137
-
138
- /**
139
- * An integer greater than 0, reflecting a number of items
140
- */
141
- export type Count = number
142
-
143
- /**
144
- * The reason why an item was removed from the cache, passed
145
- * to the {@link Disposer} methods.
146
- *
147
- * - `evict`: The item was evicted because it is the least recently used,
148
- * and the cache is full.
149
- * - `set`: A new value was set, overwriting the old value being disposed.
150
- * - `delete`: The item was explicitly deleted, either by calling
151
- * {@link LRUCache#delete}, {@link LRUCache#clear}, or
152
- * {@link LRUCache#set} with an undefined value.
153
- * - `expire`: The item was removed due to exceeding its TTL.
154
- * - `fetch`: A {@link OptionsBase#fetchMethod} operation returned
155
- * `undefined` or was aborted, causing the item to be deleted.
156
- */
157
- export type DisposeReason =
158
- | 'evict'
159
- | 'set'
160
- | 'delete'
161
- | 'expire'
162
- | 'fetch'
163
- /**
164
- * A method called upon item removal, passed as the
165
- * {@link OptionsBase.dispose} and/or
166
- * {@link OptionsBase.disposeAfter} options.
167
- */
168
- export type Disposer<K, V> = (
169
- value: V,
170
- key: K,
171
- reason: DisposeReason,
172
- ) => void
173
-
174
- /**
175
- * The reason why an item was added to the cache, passed
176
- * to the {@link Inserter} methods.
177
- *
178
- * - `add`: the item was not found in the cache, and was added
179
- * - `update`: the item was in the cache, with the same value provided
180
- * - `replace`: the item was in the cache, and replaced
181
- */
182
- export type InsertReason = 'add' | 'update' | 'replace'
183
-
184
- /**
185
- * A method called upon item insertion, passed as the
186
- * {@link OptionsBase.insert}
187
- */
188
- export type Inserter<K, V> = (
189
- value: V,
190
- key: K,
191
- reason: InsertReason,
192
- ) => void
193
-
194
- /**
195
- * A function that returns the effective calculated size
196
- * of an entry in the cache.
197
- */
198
- export type SizeCalculator<K, V> = (value: V, key: K) => Size
199
-
200
- /**
201
- * Options provided to the
202
- * {@link OptionsBase.fetchMethod} function.
203
- */
204
- export interface FetcherOptions<K, V, FC = unknown> {
205
- signal: AbortSignal
206
- options: FetcherFetchOptions<K, V, FC>
207
- /**
208
- * Object provided in the {@link FetchOptions.context} option to
209
- * {@link LRUCache#fetch}
210
- */
211
- context: FC
212
- }
213
-
214
- /**
215
- * Occasionally, it may be useful to track the internal behavior of the
216
- * cache, particularly for logging, debugging, or for behavior within the
217
- * `fetchMethod`. To do this, you can pass a `status` object to the
218
- * {@link LRUCache#fetch}, {@link LRUCache#get}, {@link LRUCache#set},
219
- * {@link LRUCache#memo}, and {@link LRUCache#has} methods.
220
- *
221
- * The `status` option should be a plain JavaScript object. The following
222
- * fields will be set on it appropriately, depending on the situation.
223
- *
224
- * These objects are also the context objects passed to listeners on the
225
- * `lru-cache:metrics` diagnostic channel, and the `lru-cache` tracing
226
- * channels, in platforms that support them.
227
- */
228
- export interface Status<K, V> {
229
- /**
230
- * The operation being performed
231
- */
232
- op?: 'get' | 'set' | 'memo' | 'fetch' | 'delete' | 'has' | 'peek'
233
- /**
234
- * The status of a set() operation.
235
- *
236
- * - add: the item was not found in the cache, and was added
237
- * - update: the item was in the cache, with the same value provided
238
- * - replace: the item was in the cache, and replaced
239
- * - miss: the item was not added to the cache for some reason
240
- */
241
- set?: 'add' | 'update' | 'replace' | 'miss' | 'deleted'
242
-
243
- /**
244
- * The status of a delete() operation.
245
- */
246
- delete?: LRUCache.DisposeReason
247
-
248
- /**
249
- * The result of a peek() operation
250
- *
251
- * - hit: the item was found and returned
252
- * - stale: the item is in the cache, but past its ttl and not returned
253
- * - miss: item not in the cache
254
- */
255
- peek?: 'hit' | 'miss' | 'stale'
256
-
257
- /**
258
- * The status of a memo() operation.
259
- *
260
- * - 'hit': the item was found in the cache and returned
261
- * - 'miss': the `memoMethod` function was called
262
- */
263
- memo?: 'hit' | 'miss'
264
-
265
- /**
266
- * The `context` option provided to a memo or fetch operation
267
- *
268
- * In practice, of course, this will be the same type as the `FC`
269
- * fetch context param used to instantiate the LRUCache, but the
270
- * convolutions of threading that through would get quite complicated,
271
- * and preclude forcing/forbidding the passing of a `context` param
272
- * where it is/isn't expected, which is more valuable for error
273
- * prevention.
274
- */
275
- context?: unknown
276
-
277
- /**
278
- * the ttl stored for the item, or undefined if ttls are not used.
279
- */
280
- ttl?: Milliseconds
281
-
282
- /**
283
- * the start time for the item, or undefined if ttls are not used.
284
- */
285
- start?: Milliseconds
286
-
287
- /**
288
- * The timestamp used for TTL calculation
289
- */
290
- now?: Milliseconds
291
-
292
- /**
293
- * the remaining ttl for the item, or undefined if ttls are not used.
294
- */
295
- remainingTTL?: Milliseconds
296
-
297
- /**
298
- * The calculated size for the item, if sizes are used.
299
- */
300
- entrySize?: Size
301
-
302
- /**
303
- * The total calculated size of the cache, if sizes are used.
304
- */
305
- totalCalculatedSize?: Size
306
-
307
- /**
308
- * A flag indicating that the item was not stored, due to exceeding the
309
- * {@link OptionsBase.maxEntrySize}
310
- */
311
- maxEntrySizeExceeded?: true
312
-
313
- /**
314
- * The key that was set or retrieved
315
- */
316
- key?: K
317
-
318
- /**
319
- * The value that was set
320
- */
321
- value?: V
322
-
323
- /**
324
- * The old value, specified in the case of `set:'replace'`
325
- */
326
- oldValue?: V
327
-
328
- /**
329
- * The results of a {@link LRUCache#has} operation
330
- *
331
- * - hit: the item was found in the cache
332
- * - stale: the item was found in the cache, but is stale
333
- * - miss: the item was not found in the cache
334
- */
335
- has?: 'hit' | 'stale' | 'miss'
336
-
337
- /**
338
- * The status of a {@link LRUCache#fetch} operation.
339
- * Note that this can change as the underlying fetch() moves through
340
- * various states.
341
- *
342
- * - inflight: there is another fetch() for this key which is in process
343
- * - get: there is no {@link OptionsBase.fetchMethod}, so
344
- * {@link LRUCache#get} was called.
345
- * - miss: the item is not in cache, and will be fetched.
346
- * - hit: the item is in the cache, and was resolved immediately.
347
- * - stale: the item is in the cache, but stale.
348
- * - refresh: the item is in the cache, and not stale, but
349
- * {@link FetchOptions.forceRefresh} was specified.
350
- */
351
- fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh'
352
-
353
- /**
354
- * `forceRefresh` option was used for either a fetch or memo operation
355
- */
356
- forceRefresh?: boolean
357
-
358
- /**
359
- * The {@link OptionsBase.fetchMethod} was called
360
- */
361
- fetchDispatched?: true
362
-
363
- /**
364
- * The cached value was updated after a successful call to
365
- * {@link OptionsBase.fetchMethod}
366
- */
367
- fetchUpdated?: true
368
-
369
- /**
370
- * The reason for a fetch() rejection. Either the error raised by the
371
- * {@link OptionsBase.fetchMethod}, or the reason for an
372
- * AbortSignal.
373
- */
374
- fetchError?: Error
375
-
376
- /**
377
- * The fetch received an abort signal
378
- */
379
- fetchAborted?: true
380
-
381
- /**
382
- * The abort signal received was ignored, and the fetch was allowed to
383
- * continue in the background.
384
- */
385
- fetchAbortIgnored?: true
386
-
387
- /**
388
- * The fetchMethod promise resolved successfully
389
- */
390
- fetchResolved?: true
391
-
392
- /**
393
- * The fetchMethod promise was rejected
394
- */
395
- fetchRejected?: true
396
-
397
- /**
398
- * The status of a {@link LRUCache#get} operation.
399
- *
400
- * - fetching: The item is currently being fetched. If a previous value
401
- * is present and allowed, that will be returned.
402
- * - stale: The item is in the cache, and is stale. If it was returned,
403
- * then the `returnedStale` flag will be set.
404
- * - stale-fetching: The value is being fetched in the background, but is
405
- * currently stale. If the stale value was returned, then the
406
- * `returnedStale` flag will be set.
407
- * - hit: the item is in the cache
408
- * - miss: the item is not in the cache
409
- */
410
- get?: 'stale' | 'hit' | 'miss' | 'fetching' | 'stale-fetching'
411
-
412
- /**
413
- * A fetch or get operation returned a stale value.
414
- */
415
- returnedStale?: true
416
-
417
- /**
418
- * A tracingChannel trace was started for this operation
419
- */
420
- trace?: boolean
421
- }
422
-
423
- /**
424
- * options which override the options set in the LRUCache constructor
425
- * when calling {@link LRUCache#fetch}.
426
- *
427
- * This is the union of {@link GetOptions} and {@link SetOptions}, plus
428
- * {@link OptionsBase.noDeleteOnFetchRejection},
429
- * {@link OptionsBase.allowStaleOnFetchRejection},
430
- * {@link FetchOptions.forceRefresh}, and
431
- * {@link FetcherOptions.context}
432
- *
433
- * Any of these may be modified in the {@link OptionsBase.fetchMethod}
434
- * function, but the {@link GetOptions} fields will of course have no
435
- * effect, as the {@link LRUCache#get} call already happened by the time
436
- * the fetchMethod is called.
437
- */
438
- export interface FetcherFetchOptions<K, V, FC = unknown> extends Pick<
439
- OptionsBase<K, V, FC>,
440
- | 'allowStale'
441
- | 'updateAgeOnGet'
442
- | 'noDeleteOnStaleGet'
443
- | 'sizeCalculation'
444
- | 'ttl'
445
- | 'noDisposeOnSet'
446
- | 'noUpdateTTL'
447
- | 'noDeleteOnFetchRejection'
448
- | 'allowStaleOnFetchRejection'
449
- | 'ignoreFetchAbort'
450
- | 'allowStaleOnFetchAbort'
451
- > {
452
- status?: Status<K, V>
453
- size?: Size
454
- }
455
-
456
- /**
457
- * Options that may be passed to the {@link LRUCache#fetch} method.
458
- */
459
- export interface FetchOptions<K, V, FC> extends FetcherFetchOptions<
460
- K,
461
- V,
462
- FC
463
- > {
464
- /**
465
- * Set to true to force a re-load of the existing data, even if it
466
- * is not yet stale.
467
- */
468
- forceRefresh?: boolean
469
- /**
470
- * Context provided to the {@link OptionsBase.fetchMethod} as
471
- * the {@link FetcherOptions.context} param.
472
- *
473
- * If the FC type is specified as unknown (the default),
474
- * undefined or void, then this is optional. Otherwise, it will
475
- * be required.
476
- */
477
- context?: FC
478
- signal?: AbortSignal
479
- status?: Status<K, V>
480
- }
481
- /**
482
- * Options provided to {@link LRUCache#fetch} when the FC type is something
483
- * other than `unknown`, `undefined`, or `void`
484
- */
485
- export interface FetchOptionsWithContext<K, V, FC> extends FetchOptions<
486
- K,
487
- V,
488
- FC
489
- > {
490
- context: FC
491
- }
492
- /**
493
- * Options provided to {@link LRUCache#fetch} when the FC type is
494
- * `undefined` or `void`
495
- */
496
- export interface FetchOptionsNoContext<K, V> extends FetchOptions<
497
- K,
498
- V,
499
- undefined
500
- > {
501
- context?: undefined
502
- }
503
-
504
- export interface MemoOptions<K, V, FC = unknown> extends Pick<
505
- OptionsBase<K, V, FC>,
506
- | 'allowStale'
507
- | 'updateAgeOnGet'
508
- | 'noDeleteOnStaleGet'
509
- | 'sizeCalculation'
510
- | 'ttl'
511
- | 'noDisposeOnSet'
512
- | 'noUpdateTTL'
513
- | 'noDeleteOnFetchRejection'
514
- | 'allowStaleOnFetchRejection'
515
- | 'ignoreFetchAbort'
516
- | 'allowStaleOnFetchAbort'
517
- > {
518
- /**
519
- * Set to true to force a re-load of the existing data, even if it
520
- * is not yet stale.
521
- */
522
- forceRefresh?: boolean
523
- /**
524
- * Context provided to the {@link OptionsBase.memoMethod} as
525
- * the {@link MemoizerOptions.context} param.
526
- *
527
- * If the FC type is specified as unknown (the default),
528
- * undefined or void, then this is optional. Otherwise, it will
529
- * be required.
530
- */
531
- context?: FC
532
- status?: Status<K, V>
533
- }
534
- /**
535
- * Options provided to {@link LRUCache#memo} when the FC type is something
536
- * other than `unknown`, `undefined`, or `void`
537
- */
538
- export interface MemoOptionsWithContext<K, V, FC> extends MemoOptions<
539
- K,
540
- V,
541
- FC
542
- > {
543
- context: FC
544
- }
545
- /**
546
- * Options provided to {@link LRUCache#memo} when the FC type is
547
- * `undefined` or `void`
548
- */
549
- export interface MemoOptionsNoContext<K, V> extends MemoOptions<
550
- K,
551
- V,
552
- undefined
553
- > {
554
- context?: undefined
555
- }
556
-
557
- /**
558
- * Options provided to the
559
- * {@link OptionsBase.memoMethod} function.
560
- */
561
- export interface MemoizerOptions<K, V, FC = unknown> {
562
- options: MemoizerMemoOptions<K, V, FC>
563
- /**
564
- * Object provided in the {@link MemoOptions.context} option to
565
- * {@link LRUCache#memo}
566
- */
567
- context: FC
568
- }
569
-
570
- /**
571
- * options which override the options set in the LRUCache constructor
572
- * when calling {@link LRUCache#memo}.
573
- *
574
- * This is the union of {@link GetOptions} and {@link SetOptions}, plus
575
- * {@link MemoOptions.forceRefresh}, and
576
- * {@link MemoOptions.context}
577
- *
578
- * Any of these may be modified in the {@link OptionsBase.memoMethod}
579
- * function, but the {@link GetOptions} fields will of course have no
580
- * effect, as the {@link LRUCache#get} call already happened by the time
581
- * the memoMethod is called.
582
- */
583
- export interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<
584
- OptionsBase<K, V, FC>,
585
- | 'allowStale'
586
- | 'updateAgeOnGet'
587
- | 'noDeleteOnStaleGet'
588
- | 'sizeCalculation'
589
- | 'ttl'
590
- | 'noDisposeOnSet'
591
- | 'noUpdateTTL'
592
- > {
593
- status?: Status<K, V>
594
- size?: Size
595
- start?: Milliseconds
596
- }
597
-
598
- /**
599
- * Options that may be passed to the {@link LRUCache#has} method.
600
- */
601
- export interface HasOptions<K, V, FC> extends Pick<
602
- OptionsBase<K, V, FC>,
603
- 'updateAgeOnHas'
604
- > {
605
- status?: Status<K, V>
606
- }
607
-
608
- /**
609
- * Options that may be passed to the {@link LRUCache#get} method.
610
- */
611
- export interface GetOptions<K, V, FC> extends Pick<
612
- OptionsBase<K, V, FC>,
613
- 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet'
614
- > {
615
- status?: Status<K, V>
616
- }
617
-
618
- /**
619
- * Options that may be passed to the {@link LRUCache#peek} method.
620
- */
621
- export interface PeekOptions<K, V, FC> extends Pick<
622
- OptionsBase<K, V, FC>,
623
- 'allowStale'
624
- > {
625
- status?: Status<K, V>
626
- }
627
-
628
- /**
629
- * Options that may be passed to the {@link LRUCache#set} method.
630
- */
631
- export interface SetOptions<K, V, FC> extends Pick<
632
- OptionsBase<K, V, FC>,
633
- 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'
634
- > {
635
- /**
636
- * If size tracking is enabled, then setting an explicit size
637
- * in the {@link LRUCache#set} call will prevent calling the
638
- * {@link OptionsBase.sizeCalculation} function.
639
- */
640
- size?: Size
641
- /**
642
- * If TTL tracking is enabled, then setting an explicit start
643
- * time in the {@link LRUCache#set} call will override the
644
- * default time from `performance.now()` or `Date.now()`.
645
- *
646
- * Note that it must be a valid value for whichever time-tracking
647
- * method is in use.
648
- */
649
- start?: Milliseconds
650
- status?: Status<K, V>
651
- }
652
-
653
- /**
654
- * The type signature for the {@link OptionsBase.fetchMethod} option.
655
- */
656
- export type Fetcher<K, V, FC = unknown> = (
657
- key: K,
658
- staleValue: V | undefined,
659
- options: FetcherOptions<K, V, FC>,
660
- ) => Promise<V | undefined | void> | V | undefined | void
661
-
662
- /**
663
- * the type signature for the {@link OptionsBase.memoMethod} option.
664
- */
665
- export type Memoizer<K, V, FC = unknown> = (
666
- key: K,
667
- staleValue: V | undefined,
668
- options: MemoizerOptions<K, V, FC>,
669
- ) => V
670
-
671
- /**
672
- * Options which may be passed to the {@link LRUCache} constructor.
673
- *
674
- * Most of these may be overridden in the various options that use
675
- * them.
676
- *
677
- * Despite all being technically optional, the constructor requires that
678
- * a cache is at minimum limited by one or more of {@link OptionsBase.max},
679
- * {@link OptionsBase.ttl}, or {@link OptionsBase.maxSize}.
680
- *
681
- * If {@link OptionsBase.ttl} is used alone, then it is strongly advised
682
- * (and in fact required by the type definitions here) that the cache
683
- * also set {@link OptionsBase.ttlAutopurge}, to prevent potentially
684
- * unbounded storage.
685
- *
686
- * All options are also available on the {@link LRUCache} instance, making
687
- * it safe to pass an LRUCache instance as the options argumemnt to
688
- * make another empty cache of the same type.
689
- *
690
- * Some options are marked as read-only, because changing them after
691
- * instantiation is not safe. Changing any of the other options will of
692
- * course only have an effect on subsequent method calls.
693
- */
694
- export interface OptionsBase<K, V, FC> {
695
- /**
696
- * The maximum number of items to store in the cache before evicting
697
- * old entries. This is read-only on the {@link LRUCache} instance,
698
- * and may not be overridden.
699
- *
700
- * If set, then storage space will be pre-allocated at construction
701
- * time, and the cache will perform significantly faster.
702
- *
703
- * Note that significantly fewer items may be stored, if
704
- * {@link OptionsBase.maxSize} and/or {@link OptionsBase.ttl} are also
705
- * set.
706
- *
707
- * **It is strongly recommended to set a `max` to prevent unbounded growth
708
- * of the cache.**
709
- */
710
- max?: Count
711
-
712
- /**
713
- * Max time in milliseconds for items to live in cache before they are
714
- * considered stale. Note that stale items are NOT preemptively removed by
715
- * default, and MAY live in the cache, contributing to its LRU max, long
716
- * after they have expired, unless {@link OptionsBase.ttlAutopurge} is
717
- * set.
718
- *
719
- * If set to `0` (the default value), then that means "do not track
720
- * TTL", not "expire immediately".
721
- *
722
- * Also, as this cache is optimized for LRU/MRU operations, some of
723
- * the staleness/TTL checks will reduce performance, as they will incur
724
- * overhead by deleting items.
725
- *
726
- * This is not primarily a TTL cache, and does not make strong TTL
727
- * guarantees. There is no pre-emptive pruning of expired items, but you
728
- * _may_ set a TTL on the cache, and it will treat expired items as missing
729
- * when they are fetched, and delete them.
730
- *
731
- * Optional, but must be a non-negative integer in ms if specified.
732
- *
733
- * This may be overridden by passing an options object to `cache.set()`.
734
- *
735
- * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
736
- * positive integer if set.
737
- *
738
- * Even if ttl tracking is enabled, **it is strongly recommended to set a
739
- * `max` to prevent unbounded growth of the cache.**
740
- *
741
- * If ttl tracking is enabled, and `max` and `maxSize` are not set,
742
- * and `ttlAutopurge` is not set, then a warning will be emitted
743
- * cautioning about the potential for unbounded memory consumption.
744
- * (The TypeScript definitions will also discourage this.)
745
- */
746
- ttl?: Milliseconds
747
-
748
- /**
749
- * Minimum amount of time in ms in which to check for staleness.
750
- * Defaults to 1, which means that the current time is checked
751
- * at most once per millisecond.
752
- *
753
- * Set to 0 to check the current time every time staleness is tested.
754
- * (This reduces performance, and is theoretically unnecessary.)
755
- *
756
- * Setting this to a higher value will improve performance somewhat
757
- * while using ttl tracking, albeit at the expense of keeping stale
758
- * items around a bit longer than their TTLs would indicate.
759
- *
760
- * @default 1
761
- */
762
- ttlResolution?: Milliseconds
763
-
764
- /**
765
- * Preemptively remove stale items from the cache.
766
- *
767
- * Note that this may *significantly* degrade performance, especially if
768
- * the cache is storing a large number of items. It is almost always best
769
- * to just leave the stale items in the cache, and let them fall out as new
770
- * items are added.
771
- *
772
- * Note that this means that {@link OptionsBase.allowStale} is a bit
773
- * pointless, as stale items will be deleted almost as soon as they
774
- * expire.
775
- *
776
- * Use with caution!
777
- */
778
- ttlAutopurge?: boolean
779
-
780
- /**
781
- * When using time-expiring entries with `ttl`, setting this to `true` will
782
- * make each item's age reset to 0 whenever it is retrieved from cache with
783
- * {@link LRUCache#get}, causing it to not expire. (It can still fall out
784
- * of cache based on recency of use, of course.)
785
- *
786
- * Has no effect if {@link OptionsBase.ttl} is not set.
787
- *
788
- * This may be overridden by passing an options object to `cache.get()`.
789
- */
790
- updateAgeOnGet?: boolean
791
-
792
- /**
793
- * When using time-expiring entries with `ttl`, setting this to `true` will
794
- * make each item's age reset to 0 whenever its presence in the cache is
795
- * checked with {@link LRUCache#has}, causing it to not expire. (It can
796
- * still fall out of cache based on recency of use, of course.)
797
- *
798
- * Has no effect if {@link OptionsBase.ttl} is not set.
799
- */
800
- updateAgeOnHas?: boolean
801
-
802
- /**
803
- * Allow {@link LRUCache#get} and {@link LRUCache#fetch} calls to return
804
- * stale data, if available.
805
- *
806
- * By default, if you set `ttl`, stale items will only be deleted from the
807
- * cache when you `get(key)`. That is, it's not preemptively pruning items,
808
- * unless {@link OptionsBase.ttlAutopurge} is set.
809
- *
810
- * If you set `allowStale:true`, it'll return the stale value *as well as*
811
- * deleting it. If you don't set this, then it'll return `undefined` when
812
- * you try to get a stale entry.
813
- *
814
- * Note that when a stale entry is fetched, _even if it is returned due to
815
- * `allowStale` being set_, it is removed from the cache immediately. You
816
- * can suppress this behavior by setting
817
- * {@link OptionsBase.noDeleteOnStaleGet}, either in the constructor, or in
818
- * the options provided to {@link LRUCache#get}.
819
- *
820
- * This may be overridden by passing an options object to `cache.get()`.
821
- * The `cache.has()` method will always return `false` for stale items.
822
- *
823
- * Only relevant if a ttl is set.
824
- */
825
- allowStale?: boolean
826
-
827
- /**
828
- * Function that is called on items when they are dropped from the
829
- * cache, as `dispose(value, key, reason)`.
830
- *
831
- * This can be handy if you want to close file descriptors or do
832
- * other cleanup tasks when items are no longer stored in the cache.
833
- *
834
- * **NOTE**: It is called _before_ the item has been fully removed
835
- * from the cache, so if you want to put it right back in, you need
836
- * to wait until the next tick. If you try to add it back in during
837
- * the `dispose()` function call, it will break things in subtle and
838
- * weird ways.
839
- *
840
- * Unlike several other options, this may _not_ be overridden by
841
- * passing an option to `set()`, for performance reasons.
842
- *
843
- * The `reason` will be one of the following strings, corresponding
844
- * to the reason for the item's deletion:
845
- *
846
- * - `evict` Item was evicted to make space for a new addition
847
- * - `set` Item was overwritten by a new value
848
- * - `expire` Item expired its TTL
849
- * - `fetch` Item was deleted due to a failed or aborted fetch, or a
850
- * fetchMethod returning `undefined.
851
- * - `delete` Item was removed by explicit `cache.delete(key)`,
852
- * `cache.clear()`, or `cache.set(key, undefined)`.
853
- */
854
- dispose?: Disposer<K, V>
855
-
856
- /**
857
- * Function that is called when new items are inserted into the cache,
858
- * as `onInsert(value, key, reason)`.
859
- *
860
- * This can be useful if you need to perform actions when an item is
861
- * added, such as logging or tracking insertions.
862
- *
863
- * Unlike some other options, this may _not_ be overridden by passing
864
- * an option to `set()`, for performance and consistency reasons.
865
- */
866
- onInsert?: Inserter<K, V>
867
-
868
- /**
869
- * The same as {@link OptionsBase.dispose}, but called *after* the entry
870
- * is completely removed and the cache is once again in a clean state.
871
- *
872
- * It is safe to add an item right back into the cache at this point.
873
- * However, note that it is *very* easy to inadvertently create infinite
874
- * recursion this way.
875
- */
876
- disposeAfter?: Disposer<K, V>
877
-
878
- /**
879
- * Set to true to suppress calling the
880
- * {@link OptionsBase.dispose} function if the entry key is
881
- * still accessible within the cache.
882
- *
883
- * This may be overridden by passing an options object to
884
- * {@link LRUCache#set}.
885
- *
886
- * Only relevant if `dispose` or `disposeAfter` are set.
887
- */
888
- noDisposeOnSet?: boolean
889
-
890
- /**
891
- * Boolean flag to tell the cache to not update the TTL when setting a new
892
- * value for an existing key (ie, when updating a value rather than
893
- * inserting a new value). Note that the TTL value is _always_ set (if
894
- * provided) when adding a new entry into the cache.
895
- *
896
- * Has no effect if a {@link OptionsBase.ttl} is not set.
897
- *
898
- * May be passed as an option to {@link LRUCache#set}.
899
- */
900
- noUpdateTTL?: boolean
901
-
902
- /**
903
- * Set to a positive integer to track the sizes of items added to the
904
- * cache, and automatically evict items in order to stay below this size.
905
- * Note that this may result in fewer than `max` items being stored.
906
- *
907
- * Attempting to add an item to the cache whose calculated size is greater
908
- * that this amount will be a no-op. The item will not be cached, and no
909
- * other items will be evicted.
910
- *
911
- * Optional, must be a positive integer if provided.
912
- *
913
- * Sets `maxEntrySize` to the same value, unless a different value is
914
- * provided for `maxEntrySize`.
915
- *
916
- * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
917
- * positive integer if set.
918
- *
919
- * Even if size tracking is enabled, **it is strongly recommended to set a
920
- * `max` to prevent unbounded growth of the cache.**
921
- *
922
- * Note also that size tracking can negatively impact performance,
923
- * though for most cases, only minimally.
924
- */
925
- maxSize?: Size
926
-
927
- /**
928
- * The maximum allowed size for any single item in the cache.
929
- *
930
- * If a larger item is passed to {@link LRUCache#set} or returned by a
931
- * {@link OptionsBase.fetchMethod} or {@link OptionsBase.memoMethod}, then
932
- * it will not be stored in the cache.
933
- *
934
- * Attempting to add an item whose calculated size is greater than
935
- * this amount will not cache the item or evict any old items, but
936
- * WILL delete an existing value if one is already present.
937
- *
938
- * Optional, must be a positive integer if provided. Defaults to
939
- * the value of `maxSize` if provided.
940
- */
941
- maxEntrySize?: Size
942
-
943
- /**
944
- * A function that returns a number indicating the item's size.
945
- *
946
- * Requires {@link OptionsBase.maxSize} to be set.
947
- *
948
- * If not provided, and {@link OptionsBase.maxSize} or
949
- * {@link OptionsBase.maxEntrySize} are set, then all
950
- * {@link LRUCache#set} calls **must** provide an explicit
951
- * {@link SetOptions.size} or sizeCalculation param.
952
- */
953
- sizeCalculation?: SizeCalculator<K, V>
954
-
955
- /**
956
- * Method that provides the implementation for {@link LRUCache#fetch}
957
- *
958
- * ```ts
959
- * fetchMethod(key, staleValue, { signal, options, context })
960
- * ```
961
- *
962
- * If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent
963
- * to `Promise.resolve(cache.get(key))`.
964
- *
965
- * If at any time, `signal.aborted` is set to `true`, or if the
966
- * `signal.onabort` method is called, or if it emits an `'abort'` event
967
- * which you can listen to with `addEventListener`, then that means that
968
- * the fetch should be abandoned. This may be passed along to async
969
- * functions aware of AbortController/AbortSignal behavior.
970
- *
971
- * The `fetchMethod` should **only** return `undefined` or a Promise
972
- * resolving to `undefined` if the AbortController signaled an `abort`
973
- * event. In all other cases, it should return or resolve to a value
974
- * suitable for adding to the cache.
975
- *
976
- * The `options` object is a union of the options that may be provided to
977
- * `set()` and `get()`. If they are modified, then that will result in
978
- * modifying the settings to `cache.set()` when the value is resolved, and
979
- * in the case of
980
- * {@link OptionsBase.noDeleteOnFetchRejection} and
981
- * {@link OptionsBase.allowStaleOnFetchRejection}, the handling of
982
- * `fetchMethod` failures.
983
- *
984
- * For example, a DNS cache may update the TTL based on the value returned
985
- * from a remote DNS server by changing `options.ttl` in the `fetchMethod`.
986
- */
987
- fetchMethod?: Fetcher<K, V, FC>
988
-
989
- /**
990
- * Method that provides the implementation for {@link LRUCache#memo}
991
- */
992
- memoMethod?: Memoizer<K, V, FC>
993
-
994
- /**
995
- * Set to true to suppress the deletion of stale data when a
996
- * {@link OptionsBase.fetchMethod} returns a rejected promise.
997
- */
998
- noDeleteOnFetchRejection?: boolean
999
-
1000
- /**
1001
- * Do not delete stale items when they are retrieved with
1002
- * {@link LRUCache#get}.
1003
- *
1004
- * Note that the `get` return value will still be `undefined`
1005
- * unless {@link OptionsBase.allowStale} is true.
1006
- *
1007
- * When using time-expiring entries with `ttl`, by default stale
1008
- * items will be removed from the cache when the key is accessed
1009
- * with `cache.get()`.
1010
- *
1011
- * Setting this option will cause stale items to remain in the cache, until
1012
- * they are explicitly deleted with `cache.delete(key)`, or retrieved with
1013
- * `noDeleteOnStaleGet` set to `false`.
1014
- *
1015
- * This may be overridden by passing an options object to `cache.get()`.
1016
- *
1017
- * Only relevant if a ttl is used.
1018
- */
1019
- noDeleteOnStaleGet?: boolean
1020
-
1021
- /**
1022
- * Set to true to allow returning stale data when a
1023
- * {@link OptionsBase.fetchMethod} throws an error or returns a rejected
1024
- * promise.
1025
- *
1026
- * This differs from using {@link OptionsBase.allowStale} in that stale
1027
- * data will ONLY be returned in the case that the {@link LRUCache#fetch}
1028
- * fails, not any other times.
1029
- *
1030
- * If a `fetchMethod` fails, and there is no stale value available, the
1031
- * `fetch()` will resolve to `undefined`. Ie, all `fetchMethod` errors are
1032
- * suppressed.
1033
- *
1034
- * Implies `noDeleteOnFetchRejection`.
1035
- *
1036
- * This may be set in calls to `fetch()`, or defaulted on the constructor,
1037
- * or overridden by modifying the options object in the `fetchMethod`.
1038
- */
1039
- allowStaleOnFetchRejection?: boolean
1040
-
1041
- /**
1042
- * Set to true to return a stale value from the cache when the
1043
- * `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches
1044
- * an `'abort'` event, whether user-triggered, or due to internal cache
1045
- * behavior.
1046
- *
1047
- * Unless {@link OptionsBase.ignoreFetchAbort} is also set, the underlying
1048
- * {@link OptionsBase.fetchMethod} will still be considered canceled, and
1049
- * any value it returns will be ignored and not cached.
1050
- *
1051
- * Caveat: since fetches are aborted when a new value is explicitly
1052
- * set in the cache, this can lead to fetch returning a stale value,
1053
- * since that was the fallback value _at the moment the `fetch()` was
1054
- * initiated_, even though the new updated value is now present in
1055
- * the cache.
1056
- *
1057
- * For example:
1058
- *
1059
- * ```ts
1060
- * const cache = new LRUCache<string, any>({
1061
- * ttl: 100,
1062
- * fetchMethod: async (url, oldValue, { signal }) => {
1063
- * const res = await fetch(url, { signal })
1064
- * return await res.json()
1065
- * }
1066
- * })
1067
- * cache.set('https://example.com/', { some: 'data' })
1068
- * // 100ms go by...
1069
- * const result = cache.fetch('https://example.com/')
1070
- * cache.set('https://example.com/', { other: 'thing' })
1071
- * console.log(await result) // { some: 'data' }
1072
- * console.log(cache.get('https://example.com/')) // { other: 'thing' }
1073
- * ```
1074
- */
1075
- allowStaleOnFetchAbort?: boolean
1076
-
1077
- /**
1078
- * Set to true to ignore the `abort` event emitted by the `AbortSignal`
1079
- * object passed to {@link OptionsBase.fetchMethod}, and still cache the
1080
- * resulting resolution value, as long as it is not `undefined`.
1081
- *
1082
- * When used on its own, this means aborted {@link LRUCache#fetch} calls
1083
- * are not immediately resolved or rejected when they are aborted, and
1084
- * instead take the full time to await.
1085
- *
1086
- * When used with {@link OptionsBase.allowStaleOnFetchAbort}, aborted
1087
- * {@link LRUCache#fetch} calls will resolve immediately to their stale
1088
- * cached value or `undefined`, and will continue to process and eventually
1089
- * update the cache when they resolve, as long as the resulting value is
1090
- * not `undefined`, thus supporting a "return stale on timeout while
1091
- * refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
1092
- *
1093
- * For example:
1094
- *
1095
- * ```ts
1096
- * const c = new LRUCache({
1097
- * ttl: 100,
1098
- * ignoreFetchAbort: true,
1099
- * allowStaleOnFetchAbort: true,
1100
- * fetchMethod: async (key, oldValue, { signal }) => {
1101
- * // note: do NOT pass the signal to fetch()!
1102
- * // let's say this fetch can take a long time.
1103
- * const res = await fetch(`https://slow-backend-server/${key}`)
1104
- * return await res.json()
1105
- * },
1106
- * })
1107
- *
1108
- * // this will return the stale value after 100ms, while still
1109
- * // updating in the background for next time.
1110
- * const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
1111
- * ```
1112
- *
1113
- * **Note**: regardless of this setting, an `abort` event _is still
1114
- * emitted on the `AbortSignal` object_, so may result in invalid results
1115
- * when passed to other underlying APIs that use AbortSignals.
1116
- *
1117
- * This may be overridden in the {@link OptionsBase.fetchMethod} or the
1118
- * call to {@link LRUCache#fetch}.
1119
- */
1120
- ignoreFetchAbort?: boolean
1121
-
1122
- /**
1123
- * In some cases, you may want to swap out the performance/Date object
1124
- * used for TTL tracking. This should almost certainly NOT be done in
1125
- * production environments!
1126
- *
1127
- * This value defaults to `global.performance` if it has a `now()` method,
1128
- * or the `global.Date` object otherwise.
1129
- */
1130
- perf?: Perf
1131
- }
1132
-
1133
- export interface OptionsMaxLimit<K, V, FC> extends OptionsBase<
1134
- K,
1135
- V,
1136
- FC
1137
- > {
1138
- max: Count
1139
- }
1140
- export interface OptionsTTLLimit<K, V, FC> extends OptionsBase<
1141
- K,
1142
- V,
1143
- FC
1144
- > {
1145
- ttl: Milliseconds
1146
- ttlAutopurge: boolean
1147
- }
1148
- export interface OptionsSizeLimit<K, V, FC> extends OptionsBase<
1149
- K,
1150
- V,
1151
- FC
1152
- > {
1153
- maxSize: Size
1154
- }
1155
-
1156
- /**
1157
- * The valid safe options for the {@link LRUCache} constructor
1158
- */
1159
- export type Options<K, V, FC> =
1160
- | OptionsMaxLimit<K, V, FC>
1161
- | OptionsSizeLimit<K, V, FC>
1162
- | OptionsTTLLimit<K, V, FC>
1163
-
1164
- /**
1165
- * Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump},
1166
- * and returned by {@link LRUCache#info}.
1167
- */
1168
- export interface Entry<V> {
1169
- value: V
1170
- ttl?: Milliseconds
1171
- size?: Size
1172
- start?: Milliseconds
1173
- }
1174
- }
1175
-
1176
- /**
1177
- * Default export, the thing you're using this module to get.
1178
- *
1179
- * The `K` and `V` types define the key and value types, respectively. The
1180
- * optional `FC` type defines the type of the `context` object passed to
1181
- * `cache.fetch()` and `cache.memo()`.
1182
- *
1183
- * Keys and values **must not** be `null` or `undefined`.
1184
- *
1185
- * All properties from the options object (with the exception of `max`,
1186
- * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
1187
- * added as normal public members. (The listed options are read-only getters.)
1188
- *
1189
- * Changing any of these will alter the defaults for subsequent method calls.
1190
- */
1191
- export class LRUCache<K extends {}, V extends {}, FC = unknown> {
1192
- // options that cannot be changed without disaster
1193
- readonly #max: LRUCache.Count
1194
- readonly #maxSize: LRUCache.Size
1195
- readonly #dispose?: LRUCache.Disposer<K, V>
1196
- readonly #onInsert?: LRUCache.Inserter<K, V>
1197
- readonly #disposeAfter?: LRUCache.Disposer<K, V>
1198
- readonly #fetchMethod?: LRUCache.Fetcher<K, V, FC>
1199
- readonly #memoMethod?: LRUCache.Memoizer<K, V, FC>
1200
- readonly #perf: Perf
1201
-
1202
- /**
1203
- * {@link LRUCache.OptionsBase.perf}
1204
- */
1205
- get perf() {
1206
- return this.#perf
1207
- }
1208
-
1209
- /**
1210
- * {@link LRUCache.OptionsBase.ttl}
1211
- */
1212
- ttl: LRUCache.Milliseconds
1213
-
1214
- /**
1215
- * {@link LRUCache.OptionsBase.ttlResolution}
1216
- */
1217
- ttlResolution: LRUCache.Milliseconds
1218
- /**
1219
- * {@link LRUCache.OptionsBase.ttlAutopurge}
1220
- */
1221
- ttlAutopurge: boolean
1222
- /**
1223
- * {@link LRUCache.OptionsBase.updateAgeOnGet}
1224
- */
1225
- updateAgeOnGet: boolean
1226
- /**
1227
- * {@link LRUCache.OptionsBase.updateAgeOnHas}
1228
- */
1229
- updateAgeOnHas: boolean
1230
- /**
1231
- * {@link LRUCache.OptionsBase.allowStale}
1232
- */
1233
- allowStale: boolean
1234
-
1235
- /**
1236
- * {@link LRUCache.OptionsBase.noDisposeOnSet}
1237
- */
1238
- noDisposeOnSet: boolean
1239
- /**
1240
- * {@link LRUCache.OptionsBase.noUpdateTTL}
1241
- */
1242
- noUpdateTTL: boolean
1243
- /**
1244
- * {@link LRUCache.OptionsBase.maxEntrySize}
1245
- */
1246
- maxEntrySize: LRUCache.Size
1247
- /**
1248
- * {@link LRUCache.OptionsBase.sizeCalculation}
1249
- */
1250
- sizeCalculation?: LRUCache.SizeCalculator<K, V>
1251
- /**
1252
- * {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
1253
- */
1254
- noDeleteOnFetchRejection: boolean
1255
- /**
1256
- * {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
1257
- */
1258
- noDeleteOnStaleGet: boolean
1259
- /**
1260
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
1261
- */
1262
- allowStaleOnFetchAbort: boolean
1263
- /**
1264
- * {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
1265
- */
1266
- allowStaleOnFetchRejection: boolean
1267
- /**
1268
- * {@link LRUCache.OptionsBase.ignoreFetchAbort}
1269
- */
1270
- ignoreFetchAbort: boolean
1271
-
1272
- // computed properties
1273
- #size: LRUCache.Count
1274
- #calculatedSize: LRUCache.Size
1275
- #keyMap: Map<K, Index>
1276
- #keyList: (K | undefined)[]
1277
- #valList: (V | BackgroundFetch<V> | undefined)[]
1278
- #next: NumberArray
1279
- #prev: NumberArray
1280
- #head: Index
1281
- #tail: Index
1282
- #free: StackLike
1283
- #disposed?: DisposeTask<K, V>[]
1284
- #sizes?: ZeroArray
1285
- #starts?: ZeroArray
1286
- #ttls?: ZeroArray
1287
- #autopurgeTimers?: (undefined | ReturnType<typeof setTimeout>)[]
1288
-
1289
- #hasDispose: boolean
1290
- #hasFetchMethod: boolean
1291
- #hasDisposeAfter: boolean
1292
- #hasOnInsert: boolean
1293
-
1294
- /**
1295
- * Do not call this method unless you need to inspect the
1296
- * inner workings of the cache. If anything returned by this
1297
- * object is modified in any way, strange breakage may occur.
1298
- *
1299
- * These fields are private for a reason!
1300
- *
1301
- * @internal
1302
- */
1303
- static unsafeExposeInternals<
1304
- K extends {},
1305
- V extends {},
1306
- FC extends unknown = unknown,
1307
- >(c: LRUCache<K, V, FC>) {
1308
- return {
1309
- // properties
1310
- starts: c.#starts,
1311
- ttls: c.#ttls,
1312
- autopurgeTimers: c.#autopurgeTimers,
1313
- sizes: c.#sizes,
1314
- keyMap: c.#keyMap as Map<K, number>,
1315
- keyList: c.#keyList,
1316
- valList: c.#valList,
1317
- next: c.#next,
1318
- prev: c.#prev,
1319
- get head() {
1320
- return c.#head
1321
- },
1322
- get tail() {
1323
- return c.#tail
1324
- },
1325
- free: c.#free,
1326
- // methods
1327
- isBackgroundFetch: (p: unknown) => c.#isBackgroundFetch(p),
1328
- backgroundFetch: (
1329
- k: K,
1330
- index: number | undefined,
1331
- options: LRUCache.FetchOptions<K, V, FC>,
1332
- context: unknown,
1333
- ): BackgroundFetch<V> =>
1334
- c.#backgroundFetch(
1335
- k,
1336
- index as Index | undefined,
1337
- options,
1338
- context as FC,
1339
- ),
1340
- moveToTail: (index: number): void => c.#moveToTail(index as Index),
1341
- indexes: (options?: { allowStale: boolean }) => c.#indexes(options),
1342
- rindexes: (options?: { allowStale: boolean }) =>
1343
- c.#rindexes(options),
1344
- isStale: (index: number | undefined) => c.#isStale(index as Index),
1345
- }
1346
- }
1347
-
1348
- // Protected read-only members
1349
-
1350
- /**
1351
- * {@link LRUCache.OptionsBase.max} (read-only)
1352
- */
1353
- get max(): LRUCache.Count {
1354
- return this.#max
1355
- }
1356
- /**
1357
- * {@link LRUCache.OptionsBase.maxSize} (read-only)
1358
- */
1359
- get maxSize(): LRUCache.Count {
1360
- return this.#maxSize
1361
- }
1362
- /**
1363
- * The total computed size of items in the cache (read-only)
1364
- */
1365
- get calculatedSize(): LRUCache.Size {
1366
- return this.#calculatedSize
1367
- }
1368
- /**
1369
- * The number of items stored in the cache (read-only)
1370
- */
1371
- get size(): LRUCache.Count {
1372
- return this.#size
1373
- }
1374
- /**
1375
- * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
1376
- */
1377
- get fetchMethod(): LRUCache.Fetcher<K, V, FC> | undefined {
1378
- return this.#fetchMethod
1379
- }
1380
- get memoMethod(): LRUCache.Memoizer<K, V, FC> | undefined {
1381
- return this.#memoMethod
1382
- }
1383
- /**
1384
- * {@link LRUCache.OptionsBase.dispose} (read-only)
1385
- */
1386
- get dispose() {
1387
- return this.#dispose
1388
- }
1389
- /**
1390
- * {@link LRUCache.OptionsBase.onInsert} (read-only)
1391
- */
1392
- get onInsert() {
1393
- return this.#onInsert
1394
- }
1395
- /**
1396
- * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
1397
- */
1398
- get disposeAfter() {
1399
- return this.#disposeAfter
1400
- }
1401
-
1402
- constructor(options: LRUCache.Options<K, V, FC> | LRUCache<K, V, FC>) {
1403
- const {
1404
- max = 0,
1405
- ttl,
1406
- ttlResolution = 1,
1407
- ttlAutopurge,
1408
- updateAgeOnGet,
1409
- updateAgeOnHas,
1410
- allowStale,
1411
- dispose,
1412
- onInsert,
1413
- disposeAfter,
1414
- noDisposeOnSet,
1415
- noUpdateTTL,
1416
- maxSize = 0,
1417
- maxEntrySize = 0,
1418
- sizeCalculation,
1419
- fetchMethod,
1420
- memoMethod,
1421
- noDeleteOnFetchRejection,
1422
- noDeleteOnStaleGet,
1423
- allowStaleOnFetchRejection,
1424
- allowStaleOnFetchAbort,
1425
- ignoreFetchAbort,
1426
- perf,
1427
- } = options
1428
-
1429
- if (perf !== undefined) {
1430
- if (typeof perf?.now !== 'function') {
1431
- throw new TypeError(
1432
- 'perf option must have a now() method if specified',
1433
- )
1434
- }
1435
- }
1436
-
1437
- this.#perf = perf ?? defaultPerf
1438
-
1439
- if (max !== 0 && !isPosInt(max)) {
1440
- throw new TypeError('max option must be a nonnegative integer')
1441
- }
1442
-
1443
- const UintArray = max ? getUintArray(max) : Array
1444
- if (!UintArray) {
1445
- throw new Error('invalid max value: ' + max)
1446
- }
1447
-
1448
- this.#max = max
1449
- this.#maxSize = maxSize
1450
- this.maxEntrySize = maxEntrySize || this.#maxSize
1451
- this.sizeCalculation = sizeCalculation
1452
- if (this.sizeCalculation) {
1453
- if (!this.#maxSize && !this.maxEntrySize) {
1454
- throw new TypeError(
1455
- 'cannot set sizeCalculation without setting maxSize or maxEntrySize',
1456
- )
1457
- }
1458
- if (typeof this.sizeCalculation !== 'function') {
1459
- throw new TypeError('sizeCalculation set to non-function')
1460
- }
1461
- }
1462
-
1463
- if (memoMethod !== undefined && typeof memoMethod !== 'function') {
1464
- throw new TypeError('memoMethod must be a function if defined')
1465
- }
1466
- this.#memoMethod = memoMethod
1467
-
1468
- if (fetchMethod !== undefined && typeof fetchMethod !== 'function') {
1469
- throw new TypeError('fetchMethod must be a function if specified')
1470
- }
1471
- this.#fetchMethod = fetchMethod
1472
- this.#hasFetchMethod = !!fetchMethod
1473
-
1474
- this.#keyMap = new Map()
1475
- this.#keyList = Array.from({ length: max }).fill(undefined) as (
1476
- | K
1477
- | undefined
1478
- )[]
1479
- this.#valList = Array.from({ length: max }).fill(undefined) as (
1480
- | V
1481
- | undefined
1482
- )[]
1483
- this.#next = new UintArray(max)
1484
- this.#prev = new UintArray(max)
1485
- this.#head = 0 as Index
1486
- this.#tail = 0 as Index
1487
- this.#free = Stack.create(max)
1488
- this.#size = 0
1489
- this.#calculatedSize = 0
1490
-
1491
- if (typeof dispose === 'function') {
1492
- this.#dispose = dispose
1493
- }
1494
- if (typeof onInsert === 'function') {
1495
- this.#onInsert = onInsert
1496
- }
1497
- if (typeof disposeAfter === 'function') {
1498
- this.#disposeAfter = disposeAfter
1499
- this.#disposed = []
1500
- } else {
1501
- this.#disposeAfter = undefined
1502
- this.#disposed = undefined
1503
- }
1504
- this.#hasDispose = !!this.#dispose
1505
- this.#hasOnInsert = !!this.#onInsert
1506
- this.#hasDisposeAfter = !!this.#disposeAfter
1507
-
1508
- this.noDisposeOnSet = !!noDisposeOnSet
1509
- this.noUpdateTTL = !!noUpdateTTL
1510
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection
1511
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection
1512
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort
1513
- this.ignoreFetchAbort = !!ignoreFetchAbort
1514
-
1515
- // NB: maxEntrySize is set to maxSize if it's set
1516
- if (this.maxEntrySize !== 0) {
1517
- if (this.#maxSize !== 0) {
1518
- if (!isPosInt(this.#maxSize)) {
1519
- throw new TypeError(
1520
- 'maxSize must be a positive integer if specified',
1521
- )
1522
- }
1523
- }
1524
- if (!isPosInt(this.maxEntrySize)) {
1525
- throw new TypeError(
1526
- 'maxEntrySize must be a positive integer if specified',
1527
- )
1528
- }
1529
- this.#initializeSizeTracking()
1530
- }
1531
-
1532
- this.allowStale = !!allowStale
1533
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet
1534
- this.updateAgeOnGet = !!updateAgeOnGet
1535
- this.updateAgeOnHas = !!updateAgeOnHas
1536
- this.ttlResolution =
1537
- isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1
1538
- this.ttlAutopurge = !!ttlAutopurge
1539
- this.ttl = ttl || 0
1540
- if (this.ttl) {
1541
- if (!isPosInt(this.ttl)) {
1542
- throw new TypeError('ttl must be a positive integer if specified')
1543
- }
1544
- this.#initializeTTLTracking()
1545
- }
1546
-
1547
- // do not allow completely unbounded caches
1548
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
1549
- throw new TypeError(
1550
- 'At least one of max, maxSize, or ttl is required',
1551
- )
1552
- }
1553
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
1554
- const code = 'LRU_CACHE_UNBOUNDED'
1555
- if (shouldWarn(code)) {
1556
- warned.add(code)
1557
- const msg =
1558
- 'TTL caching without ttlAutopurge, max, or maxSize can ' +
1559
- 'result in unbounded memory consumption.'
1560
- emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache)
1561
- }
1562
- }
1563
- }
1564
-
1565
- /**
1566
- * Return the number of ms left in the item's TTL. If item is not in cache,
1567
- * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
1568
- */
1569
- getRemainingTTL(key: K) {
1570
- return this.#keyMap.has(key) ? Infinity : 0
1571
- }
1572
-
1573
- #initializeTTLTracking() {
1574
- const ttls = new ZeroArray(this.#max)
1575
- const starts = new ZeroArray(this.#max)
1576
- this.#ttls = ttls
1577
- this.#starts = starts
1578
- const purgeTimers =
1579
- this.ttlAutopurge ?
1580
- Array.from<undefined | ReturnType<typeof setTimeout>>({
1581
- length: this.#max,
1582
- })
1583
- : undefined
1584
- this.#autopurgeTimers = purgeTimers
1585
-
1586
- this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
1587
- starts[index] = ttl !== 0 ? start : 0
1588
- ttls[index] = ttl
1589
- setPurgetTimer(index, ttl)
1590
- }
1591
-
1592
- this.#updateItemAge = index => {
1593
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0
1594
- setPurgetTimer(index, ttls[index])
1595
- }
1596
-
1597
- // clear out the purge timer if we're setting TTL to 0, and
1598
- // previously had a ttl purge timer running, so it doesn't
1599
- // fire unnecessarily. Don't need to do this if we're not doing
1600
- // autopurge.
1601
- const setPurgetTimer =
1602
- !this.ttlAutopurge ?
1603
- () => {}
1604
- : (index: Index, ttl?: number) => {
1605
- if (purgeTimers?.[index]) {
1606
- clearTimeout(purgeTimers[index])
1607
- purgeTimers[index] = undefined
1608
- }
1609
- if (ttl && ttl !== 0 && purgeTimers) {
1610
- const t = setTimeout(() => {
1611
- if (this.#isStale(index)) {
1612
- this.#delete(this.#keyList[index] as K, 'expire')
1613
- }
1614
- }, ttl + 1)
1615
- // unref() not supported on all platforms
1616
- /* c8 ignore start */
1617
- if (t.unref) {
1618
- t.unref()
1619
- }
1620
- /* c8 ignore stop */
1621
- purgeTimers[index] = t
1622
- }
1623
- }
1624
-
1625
- this.#statusTTL = (status, index) => {
1626
- if (ttls[index]) {
1627
- const ttl = ttls[index]
1628
- const start = starts[index]
1629
- /* c8 ignore start */
1630
- if (!ttl || !start) {
1631
- return
1632
- }
1633
- /* c8 ignore stop */
1634
- status.ttl = ttl
1635
- status.start = start
1636
- status.now = cachedNow || getNow()
1637
- const age = status.now - start
1638
- status.remainingTTL = ttl - age
1639
- }
1640
- }
1641
-
1642
- // debounce calls to perf.now() to 1s so we're not hitting
1643
- // that costly call repeatedly.
1644
- let cachedNow = 0
1645
- const getNow = () => {
1646
- const n = this.#perf.now()
1647
- if (this.ttlResolution > 0) {
1648
- cachedNow = n
1649
- const t = setTimeout(() => (cachedNow = 0), this.ttlResolution)
1650
- // not available on all platforms
1651
- /* c8 ignore start */
1652
- if (t.unref) {
1653
- t.unref()
1654
- }
1655
- /* c8 ignore stop */
1656
- }
1657
- return n
1658
- }
1659
-
1660
- this.getRemainingTTL = key => {
1661
- const index = this.#keyMap.get(key)
1662
- if (index === undefined) {
1663
- return 0
1664
- }
1665
- const ttl = ttls[index]
1666
- const start = starts[index]
1667
- if (!ttl || !start) {
1668
- return Infinity
1669
- }
1670
- const age = (cachedNow || getNow()) - start
1671
- return ttl - age
1672
- }
1673
-
1674
- this.#isStale = index => {
1675
- const s = starts[index]
1676
- const t = ttls[index]
1677
- return !!t && !!s && (cachedNow || getNow()) - s > t
1678
- }
1679
- }
1680
-
1681
- // conditionally set private methods related to TTL
1682
- #updateItemAge: (index: Index) => void = () => {}
1683
- #statusTTL: (status: LRUCache.Status<K, V>, index: Index) => void =
1684
- () => {}
1685
- #setItemTTL: (
1686
- index: Index,
1687
- ttl: LRUCache.Milliseconds,
1688
- start?: LRUCache.Milliseconds,
1689
- // ignore because we never call this if we're not already in TTL mode
1690
- /* c8 ignore start */
1691
- ) => void = () => {}
1692
- /* c8 ignore stop */
1693
-
1694
- #isStale: (index: Index) => boolean = () => false
1695
-
1696
- #initializeSizeTracking() {
1697
- const sizes = new ZeroArray(this.#max)
1698
- this.#calculatedSize = 0
1699
- this.#sizes = sizes
1700
- this.#removeItemSize = index => {
1701
- this.#calculatedSize -= sizes[index] as number
1702
- sizes[index] = 0
1703
- }
1704
- this.#requireSize = (k, v, size, sizeCalculation) => {
1705
- // provisionally accept background fetches.
1706
- // actual value size will be checked when they return.
1707
- if (this.#isBackgroundFetch(v)) {
1708
- return 0
1709
- }
1710
- if (!isPosInt(size)) {
1711
- if (sizeCalculation) {
1712
- if (typeof sizeCalculation !== 'function') {
1713
- throw new TypeError('sizeCalculation must be a function')
1714
- }
1715
- size = sizeCalculation(v, k)
1716
- if (!isPosInt(size)) {
1717
- throw new TypeError(
1718
- 'sizeCalculation return invalid (expect positive integer)',
1719
- )
1720
- }
1721
- } else {
1722
- throw new TypeError(
1723
- 'invalid size value (must be positive integer). ' +
1724
- 'When maxSize or maxEntrySize is used, sizeCalculation ' +
1725
- 'or size must be set.',
1726
- )
1727
- }
1728
- }
1729
- return size
1730
- }
1731
-
1732
- this.#addItemSize = (
1733
- index: Index,
1734
- size: LRUCache.Size,
1735
- status?: LRUCache.Status<K, V>,
1736
- ) => {
1737
- sizes[index] = size
1738
- if (this.#maxSize) {
1739
- const maxSize = this.#maxSize - sizes[index]
1740
- while (this.#calculatedSize > maxSize) {
1741
- this.#evict(true)
1742
- }
1743
- }
1744
- this.#calculatedSize += sizes[index]
1745
- if (status) {
1746
- status.entrySize = size
1747
- status.totalCalculatedSize = this.#calculatedSize
1748
- }
1749
- }
1750
- }
1751
-
1752
- #removeItemSize: (index: Index) => void = _i => {}
1753
-
1754
- #addItemSize: (
1755
- index: Index,
1756
- size: LRUCache.Size,
1757
- status?: LRUCache.Status<K, V>,
1758
- ) => void = (_i, _s, _st) => {}
1759
-
1760
- #requireSize: (
1761
- k: K,
1762
- v: V | BackgroundFetch<V>,
1763
- size?: LRUCache.Size,
1764
- sizeCalculation?: LRUCache.SizeCalculator<K, V>,
1765
- status?: LRUCache.Status<K, V>,
1766
- ) => LRUCache.Size = (
1767
- _k: K,
1768
- _v: V | BackgroundFetch<V>,
1769
- size?: LRUCache.Size,
1770
- sizeCalculation?: LRUCache.SizeCalculator<K, V>,
1771
- ) => {
1772
- if (size || sizeCalculation) {
1773
- throw new TypeError(
1774
- 'cannot set size without setting maxSize or maxEntrySize on cache',
1775
- )
1776
- }
1777
- return 0
1778
- };
1779
-
1780
- *#indexes({ allowStale = this.allowStale } = {}) {
1781
- if (this.#size) {
1782
- for (let i = this.#tail; this.#isValidIndex(i); ) {
1783
- if (allowStale || !this.#isStale(i)) {
1784
- yield i
1785
- }
1786
- if (i === this.#head) {
1787
- break
1788
- } else {
1789
- i = this.#prev[i] as Index
1790
- }
1791
- }
1792
- }
1793
- }
1794
-
1795
- *#rindexes({ allowStale = this.allowStale } = {}) {
1796
- if (this.#size) {
1797
- for (let i = this.#head; this.#isValidIndex(i); ) {
1798
- if (allowStale || !this.#isStale(i)) {
1799
- yield i
1800
- }
1801
- if (i === this.#tail) {
1802
- break
1803
- } else {
1804
- i = this.#next[i] as Index
1805
- }
1806
- }
1807
- }
1808
- }
1809
-
1810
- #isValidIndex(index: Index) {
1811
- return (
1812
- index !== undefined &&
1813
- this.#keyMap.get(this.#keyList[index] as K) === index
1814
- )
1815
- }
1816
-
1817
- /**
1818
- * Return a generator yielding `[key, value]` pairs,
1819
- * in order from most recently used to least recently used.
1820
- */
1821
- *entries() {
1822
- for (const i of this.#indexes()) {
1823
- if (
1824
- this.#valList[i] !== undefined &&
1825
- this.#keyList[i] !== undefined &&
1826
- !this.#isBackgroundFetch(this.#valList[i])
1827
- ) {
1828
- yield [this.#keyList[i], this.#valList[i]] as [K, V]
1829
- }
1830
- }
1831
- }
1832
-
1833
- /**
1834
- * Inverse order version of {@link LRUCache.entries}
1835
- *
1836
- * Return a generator yielding `[key, value]` pairs,
1837
- * in order from least recently used to most recently used.
1838
- */
1839
- *rentries() {
1840
- for (const i of this.#rindexes()) {
1841
- if (
1842
- this.#valList[i] !== undefined &&
1843
- this.#keyList[i] !== undefined &&
1844
- !this.#isBackgroundFetch(this.#valList[i])
1845
- ) {
1846
- yield [this.#keyList[i], this.#valList[i]]
1847
- }
1848
- }
1849
- }
1850
-
1851
- /**
1852
- * Return a generator yielding the keys in the cache,
1853
- * in order from most recently used to least recently used.
1854
- */
1855
- *keys() {
1856
- for (const i of this.#indexes()) {
1857
- const k = this.#keyList[i]
1858
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
1859
- yield k
1860
- }
1861
- }
1862
- }
1863
-
1864
- /**
1865
- * Inverse order version of {@link LRUCache.keys}
1866
- *
1867
- * Return a generator yielding the keys in the cache,
1868
- * in order from least recently used to most recently used.
1869
- */
1870
- *rkeys() {
1871
- for (const i of this.#rindexes()) {
1872
- const k = this.#keyList[i]
1873
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
1874
- yield k
1875
- }
1876
- }
1877
- }
1878
-
1879
- /**
1880
- * Return a generator yielding the values in the cache,
1881
- * in order from most recently used to least recently used.
1882
- */
1883
- *values() {
1884
- for (const i of this.#indexes()) {
1885
- const v = this.#valList[i]
1886
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
1887
- yield this.#valList[i] as V
1888
- }
1889
- }
1890
- }
1891
-
1892
- /**
1893
- * Inverse order version of {@link LRUCache.values}
1894
- *
1895
- * Return a generator yielding the values in the cache,
1896
- * in order from least recently used to most recently used.
1897
- */
1898
- *rvalues() {
1899
- for (const i of this.#rindexes()) {
1900
- const v = this.#valList[i]
1901
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
1902
- yield this.#valList[i]
1903
- }
1904
- }
1905
- }
1906
-
1907
- /**
1908
- * Iterating over the cache itself yields the same results as
1909
- * {@link LRUCache.entries}
1910
- */
1911
- [Symbol.iterator]() {
1912
- return this.entries()
1913
- }
1914
-
1915
- /**
1916
- * A String value that is used in the creation of the default string
1917
- * description of an object. Called by the built-in method
1918
- * `Object.prototype.toString`.
1919
- */
1920
- [Symbol.toStringTag] = 'LRUCache'
1921
-
1922
- /**
1923
- * Find a value for which the supplied fn method returns a truthy value,
1924
- * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
1925
- */
1926
- find(
1927
- fn: (v: V, k: K, self: LRUCache<K, V, FC>) => boolean,
1928
- getOptions: LRUCache.GetOptions<K, V, FC> = {},
1929
- ) {
1930
- for (const i of this.#indexes()) {
1931
- const v = this.#valList[i]
1932
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
1933
- if (value === undefined) continue
1934
- if (fn(value, this.#keyList[i] as K, this)) {
1935
- return this.#get(this.#keyList[i] as K, getOptions)
1936
- }
1937
- }
1938
- }
1939
-
1940
- /**
1941
- * Call the supplied function on each item in the cache, in order from most
1942
- * recently used to least recently used.
1943
- *
1944
- * `fn` is called as `fn(value, key, cache)`.
1945
- *
1946
- * If `thisp` is provided, function will be called in the `this`-context of
1947
- * the provided object, or the cache if no `thisp` object is provided.
1948
- *
1949
- * Does not update age or recenty of use, or iterate over stale values.
1950
- */
1951
- forEach(
1952
- fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown,
1953
- thisp: unknown = this,
1954
- ) {
1955
- for (const i of this.#indexes()) {
1956
- const v = this.#valList[i]
1957
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
1958
- if (value === undefined) continue
1959
- fn.call(thisp, value, this.#keyList[i] as K, this)
1960
- }
1961
- }
1962
-
1963
- /**
1964
- * The same as {@link LRUCache.forEach} but items are iterated over in
1965
- * reverse order. (ie, less recently used items are iterated over first.)
1966
- */
1967
- rforEach(
1968
- fn: (v: V, k: K, self: LRUCache<K, V, FC>) => unknown,
1969
- thisp: unknown = this,
1970
- ) {
1971
- for (const i of this.#rindexes()) {
1972
- const v = this.#valList[i]
1973
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
1974
- if (value === undefined) continue
1975
- fn.call(thisp, value, this.#keyList[i] as K, this)
1976
- }
1977
- }
1978
-
1979
- /**
1980
- * Delete any stale entries. Returns true if anything was removed,
1981
- * false otherwise.
1982
- */
1983
- purgeStale() {
1984
- let deleted = false
1985
- for (const i of this.#rindexes({ allowStale: true })) {
1986
- if (this.#isStale(i)) {
1987
- this.#delete(this.#keyList[i] as K, 'expire')
1988
- deleted = true
1989
- }
1990
- }
1991
- return deleted
1992
- }
1993
-
1994
- /**
1995
- * Get the extended info about a given entry, to get its value, size, and
1996
- * TTL info simultaneously. Returns `undefined` if the key is not present.
1997
- *
1998
- * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
1999
- * serialization, the `start` value is always the current timestamp, and the
2000
- * `ttl` is a calculated remaining time to live (negative if expired).
2001
- *
2002
- * Always returns stale values, if their info is found in the cache, so be
2003
- * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
2004
- * if relevant.
2005
- */
2006
- info(key: K): LRUCache.Entry<V> | undefined {
2007
- const i = this.#keyMap.get(key)
2008
- if (i === undefined) return undefined
2009
- const v = this.#valList[i]
2010
- /* c8 ignore start - this isn't tested for the info function,
2011
- * but it's the same logic as found in other places. */
2012
- const value: V | undefined =
2013
- this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
2014
- if (value === undefined) return undefined
2015
- /* c8 ignore stop */
2016
- const entry: LRUCache.Entry<V> = { value }
2017
- if (this.#ttls && this.#starts) {
2018
- const ttl = this.#ttls[i]
2019
- const start = this.#starts[i]
2020
- if (ttl && start) {
2021
- const remain = ttl - (this.#perf.now() - start)
2022
- entry.ttl = remain
2023
- entry.start = Date.now()
2024
- }
2025
- }
2026
- if (this.#sizes) {
2027
- entry.size = this.#sizes[i]
2028
- }
2029
- return entry
2030
- }
2031
-
2032
- /**
2033
- * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
2034
- * passed to {@link LRUCache#load}.
2035
- *
2036
- * The `start` fields are calculated relative to a portable `Date.now()`
2037
- * timestamp, even if `performance.now()` is available.
2038
- *
2039
- * Stale entries are always included in the `dump`, even if
2040
- * {@link LRUCache.OptionsBase.allowStale} is false.
2041
- *
2042
- * Note: this returns an actual array, not a generator, so it can be more
2043
- * easily passed around.
2044
- */
2045
- dump() {
2046
- const arr: [K, LRUCache.Entry<V>][] = []
2047
- for (const i of this.#indexes({ allowStale: true })) {
2048
- const key = this.#keyList[i]
2049
- const v = this.#valList[i]
2050
- const value: V | undefined =
2051
- this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
2052
- if (value === undefined || key === undefined) continue
2053
- const entry: LRUCache.Entry<V> = { value }
2054
- if (this.#ttls && this.#starts) {
2055
- entry.ttl = this.#ttls[i]
2056
- // always dump the start relative to a portable timestamp
2057
- // it's ok for this to be a bit slow, it's a rare operation.
2058
- const age = this.#perf.now() - (this.#starts[i] as number)
2059
- entry.start = Math.floor(Date.now() - age)
2060
- }
2061
- if (this.#sizes) {
2062
- entry.size = this.#sizes[i]
2063
- }
2064
- arr.unshift([key, entry])
2065
- }
2066
- return arr
2067
- }
2068
-
2069
- /**
2070
- * Reset the cache and load in the items in entries in the order listed.
2071
- *
2072
- * The shape of the resulting cache may be different if the same options are
2073
- * not used in both caches.
2074
- *
2075
- * The `start` fields are assumed to be calculated relative to a portable
2076
- * `Date.now()` timestamp, even if `performance.now()` is available.
2077
- */
2078
- load(arr: [K, LRUCache.Entry<V>][]) {
2079
- this.clear()
2080
- for (const [key, entry] of arr) {
2081
- if (entry.start) {
2082
- // entry.start is a portable timestamp, but we may be using
2083
- // node's performance.now(), so calculate the offset, so that
2084
- // we get the intended remaining TTL, no matter how long it's
2085
- // been on ice.
2086
- //
2087
- // it's ok for this to be a bit slow, it's a rare operation.
2088
- const age = Date.now() - entry.start
2089
- entry.start = this.#perf.now() - age
2090
- }
2091
- this.#set(key, entry.value, entry)
2092
- }
2093
- }
2094
-
2095
- /**
2096
- * Add a value to the cache.
2097
- *
2098
- * Note: if `undefined` is specified as a value, this is an alias for
2099
- * {@link LRUCache#delete}
2100
- *
2101
- * Fields on the {@link LRUCache.SetOptions} options param will override
2102
- * their corresponding values in the constructor options for the scope
2103
- * of this single `set()` operation.
2104
- *
2105
- * If `start` is provided, then that will set the effective start
2106
- * time for the TTL calculation. Note that this must be a previous
2107
- * value of `performance.now()` if supported, or a previous value of
2108
- * `Date.now()` if not.
2109
- *
2110
- * Options object may also include `size`, which will prevent
2111
- * calling the `sizeCalculation` function and just use the specified
2112
- * number if it is a positive integer, and `noDisposeOnSet` which
2113
- * will prevent calling a `dispose` function in the case of
2114
- * overwrites.
2115
- *
2116
- * If the `size` (or return value of `sizeCalculation`) for a given
2117
- * entry is greater than `maxEntrySize`, then the item will not be
2118
- * added to the cache.
2119
- *
2120
- * Will update the recency of the entry.
2121
- *
2122
- * If the value is `undefined`, then this is an alias for
2123
- * `cache.delete(key)`. `undefined` is never stored in the cache.
2124
- */
2125
- set(
2126
- k: K,
2127
- v: V | undefined,
2128
- setOptions: LRUCache.SetOptions<K, V, FC> = {},
2129
- ) {
2130
- const { status = metrics.hasSubscribers ? {} : undefined } = setOptions
2131
- setOptions.status = status
2132
- if (status) {
2133
- status.op = 'set'
2134
- status.key = k
2135
- if (v !== undefined) status.value = v
2136
- }
2137
- const result = this.#set(k, v, setOptions)
2138
- if (status && metrics.hasSubscribers) {
2139
- metrics.publish(status)
2140
- }
2141
- return result
2142
- }
2143
-
2144
- #set(
2145
- k: K,
2146
- v: V | BackgroundFetch<V> | undefined,
2147
- setOptions: LRUCache.SetOptions<K, V, FC>,
2148
- bf?: BackgroundFetch<V>,
2149
- ) {
2150
- const {
2151
- ttl = this.ttl,
2152
- start,
2153
- noDisposeOnSet = this.noDisposeOnSet,
2154
- sizeCalculation = this.sizeCalculation,
2155
- status,
2156
- } = setOptions
2157
-
2158
- if (v === undefined) {
2159
- if (status) status.set = 'deleted'
2160
- this.delete(k)
2161
- return this
2162
- }
2163
- let { noUpdateTTL = this.noUpdateTTL } = setOptions
2164
-
2165
- const isBF = this.#isBackgroundFetch(v)
2166
- if (status && !isBF) status.value = v
2167
-
2168
- const size = this.#requireSize(
2169
- k,
2170
- v,
2171
- setOptions.size || 0,
2172
- sizeCalculation,
2173
- status,
2174
- )
2175
- // if the item doesn't fit, don't do anything
2176
- // NB: maxEntrySize set to maxSize by default
2177
- if (this.maxEntrySize && size > this.maxEntrySize) {
2178
- // have to delete, in case something is there already.
2179
- this.#delete(k, 'set')
2180
- if (status) {
2181
- status.set = 'miss'
2182
- status.maxEntrySizeExceeded = true
2183
- }
2184
- return this
2185
- }
2186
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k)
2187
- if (index === undefined) {
2188
- // addition
2189
- index = (
2190
- this.#size === 0 ? this.#tail
2191
- : this.#free.length !== 0 ? this.#free.pop()
2192
- : this.#size === this.#max ? this.#evict(false)
2193
- : this.#size) as Index
2194
- this.#keyList[index] = k
2195
- this.#valList[index] = v
2196
- this.#keyMap.set(k, index)
2197
- this.#next[this.#tail] = index
2198
- this.#prev[index] = this.#tail
2199
- this.#tail = index
2200
- this.#size++
2201
- this.#addItemSize(index, size, status)
2202
- if (status) status.set = 'add'
2203
- noUpdateTTL = false
2204
- if (this.#hasOnInsert && !isBF) {
2205
- this.#onInsert?.(v, k, 'add')
2206
- }
2207
- } else {
2208
- // update
2209
- // might be updating a background fetch!
2210
- this.#moveToTail(index)
2211
- const oldVal = this.#valList[index]!
2212
- if (v !== oldVal) {
2213
- if (!noDisposeOnSet) {
2214
- if (this.#isBackgroundFetch(oldVal)) {
2215
- if (oldVal !== bf) {
2216
- // setting over a background fetch, not merely resolving it.
2217
- oldVal.__abortController.abort(new Error('replaced'))
2218
- }
2219
- const { __staleWhileFetching: s } = oldVal
2220
- if (s !== undefined && s !== v) {
2221
- if (this.#hasDispose) {
2222
- this.#dispose?.(s, k, 'set')
2223
- }
2224
- if (this.#hasDisposeAfter) {
2225
- this.#disposed?.push([s, k, 'set'])
2226
- }
2227
- }
2228
- } else {
2229
- if (this.#hasDispose) {
2230
- this.#dispose?.(oldVal, k, 'set')
2231
- }
2232
- if (this.#hasDisposeAfter) {
2233
- this.#disposed?.push([oldVal, k, 'set'])
2234
- }
2235
- }
2236
- }
2237
- this.#removeItemSize(index)
2238
- this.#addItemSize(index, size, status)
2239
- this.#valList[index] = v
2240
- if (!isBF) {
2241
- const oldValue =
2242
- oldVal && this.#isBackgroundFetch(oldVal) ?
2243
- oldVal.__staleWhileFetching
2244
- : oldVal
2245
- const setType =
2246
- oldValue === undefined ? 'add'
2247
- : v !== oldValue ? 'replace'
2248
- : 'update'
2249
- if (status) {
2250
- status.set = setType
2251
- if (oldValue !== undefined) status.oldValue = oldValue
2252
- }
2253
- if (this.#hasOnInsert) {
2254
- this.onInsert?.(v, k, setType)
2255
- }
2256
- }
2257
- } else if (!isBF) {
2258
- if (status) {
2259
- status.set = 'update'
2260
- }
2261
- if (this.#hasOnInsert) {
2262
- this.onInsert?.(v, k, 'update')
2263
- }
2264
- }
2265
- }
2266
- if (ttl !== 0 && !this.#ttls) {
2267
- this.#initializeTTLTracking()
2268
- }
2269
- if (this.#ttls) {
2270
- if (!noUpdateTTL) {
2271
- this.#setItemTTL(index, ttl, start)
2272
- }
2273
- if (status) this.#statusTTL(status, index)
2274
- }
2275
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
2276
- const dt = this.#disposed
2277
- let task: DisposeTask<K, V> | undefined
2278
- while ((task = dt?.shift())) {
2279
- this.#disposeAfter?.(...task)
2280
- }
2281
- }
2282
- return this
2283
- }
2284
-
2285
- /**
2286
- * Evict the least recently used item, returning its value or
2287
- * `undefined` if cache is empty.
2288
- */
2289
- pop(): V | undefined {
2290
- try {
2291
- while (this.#size) {
2292
- const val = this.#valList[this.#head]
2293
- this.#evict(true)
2294
- if (this.#isBackgroundFetch(val)) {
2295
- if (val.__staleWhileFetching) {
2296
- return val.__staleWhileFetching
2297
- }
2298
- } else if (val !== undefined) {
2299
- return val
2300
- }
2301
- }
2302
- } finally {
2303
- if (this.#hasDisposeAfter && this.#disposed) {
2304
- const dt = this.#disposed
2305
- let task: DisposeTask<K, V> | undefined
2306
- while ((task = dt?.shift())) {
2307
- this.#disposeAfter?.(...task)
2308
- }
2309
- }
2310
- }
2311
- }
2312
-
2313
- #evict(free: boolean) {
2314
- const head = this.#head
2315
- const k = this.#keyList[head]!
2316
- const v = this.#valList[head]!
2317
- const isBF = this.#isBackgroundFetch(v)
2318
- if (isBF) {
2319
- v.__abortController.abort(new Error('evicted'))
2320
- }
2321
- const oldValue = isBF ? v.__staleWhileFetching : v
2322
- if (
2323
- (this.#hasDispose || this.#hasDisposeAfter) &&
2324
- oldValue !== undefined
2325
- ) {
2326
- if (this.#hasDispose) {
2327
- this.#dispose?.(oldValue, k, 'evict')
2328
- }
2329
- if (this.#hasDisposeAfter) {
2330
- this.#disposed?.push([oldValue, k, 'evict'])
2331
- }
2332
- }
2333
- this.#removeItemSize(head)
2334
- if (this.#autopurgeTimers?.[head]) {
2335
- clearTimeout(this.#autopurgeTimers[head])
2336
- this.#autopurgeTimers[head] = undefined
2337
- }
2338
- // if we aren't about to use the index, then null these out
2339
- if (free) {
2340
- this.#keyList[head] = undefined
2341
- this.#valList[head] = undefined
2342
- this.#free.push(head)
2343
- }
2344
- if (this.#size === 1) {
2345
- this.#head = this.#tail = 0 as Index
2346
- this.#free.length = 0
2347
- } else {
2348
- this.#head = this.#next[head] as Index
2349
- }
2350
- this.#keyMap.delete(k)
2351
- this.#size--
2352
- return head
2353
- }
2354
-
2355
- /**
2356
- * Check if a key is in the cache, without updating the recency of use.
2357
- * Will return false if the item is stale, even though it is technically
2358
- * in the cache.
2359
- *
2360
- * Check if a key is in the cache, without updating the recency of
2361
- * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
2362
- * to `true` in either the options or the constructor.
2363
- *
2364
- * Will return `false` if the item is stale, even though it is technically in
2365
- * the cache. The difference can be determined (if it matters) by using a
2366
- * `status` argument, and inspecting the `has` field.
2367
- *
2368
- * Will not update item age unless
2369
- * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
2370
- */
2371
- has(k: K, hasOptions: LRUCache.HasOptions<K, V, FC> = {}) {
2372
- const { status = metrics.hasSubscribers ? {} : undefined } = hasOptions
2373
- hasOptions.status = status
2374
- if (status) {
2375
- status.op = 'has'
2376
- status.key = k
2377
- }
2378
- const result = this.#has(k, hasOptions)
2379
- if (metrics.hasSubscribers) metrics.publish(status)
2380
- return result
2381
- }
2382
- #has(k: K, hasOptions: LRUCache.HasOptions<K, V, FC> = {}) {
2383
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions
2384
- const index = this.#keyMap.get(k)
2385
- if (index !== undefined) {
2386
- const v = this.#valList[index]
2387
- if (
2388
- this.#isBackgroundFetch(v) &&
2389
- v.__staleWhileFetching === undefined
2390
- ) {
2391
- return false
2392
- }
2393
- if (!this.#isStale(index)) {
2394
- if (updateAgeOnHas) {
2395
- this.#updateItemAge(index)
2396
- }
2397
- if (status) {
2398
- status.has = 'hit'
2399
- this.#statusTTL(status, index)
2400
- }
2401
- return true
2402
- } else if (status) {
2403
- status.has = 'stale'
2404
- this.#statusTTL(status, index)
2405
- }
2406
- } else if (status) {
2407
- status.has = 'miss'
2408
- }
2409
- return false
2410
- }
2411
-
2412
- /**
2413
- * Like {@link LRUCache#get} but doesn't update recency or delete stale
2414
- * items.
2415
- *
2416
- * Returns `undefined` if the item is stale, unless
2417
- * {@link LRUCache.OptionsBase.allowStale} is set.
2418
- */
2419
- peek(k: K, peekOptions: LRUCache.PeekOptions<K, V, FC> = {}) {
2420
- const { status = hasSubscribers() ? {} : undefined } = peekOptions
2421
- if (status) {
2422
- status.op = 'peek'
2423
- status.key = k
2424
- }
2425
- peekOptions.status = status
2426
- const result = this.#peek(k, peekOptions)
2427
- if (metrics.hasSubscribers) {
2428
- metrics.publish(status)
2429
- }
2430
- return result
2431
- }
2432
- #peek(k: K, peekOptions: LRUCache.PeekOptions<K, V, FC>) {
2433
- const { status, allowStale = this.allowStale } = peekOptions
2434
- const index = this.#keyMap.get(k)
2435
- if (index === undefined || (!allowStale && this.#isStale(index))) {
2436
- if (status) status.peek = index === undefined ? 'miss' : 'stale'
2437
- return undefined
2438
- }
2439
- const v = this.#valList[index]
2440
- const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v
2441
- if (status) {
2442
- if (val !== undefined) {
2443
- status.peek = 'hit'
2444
- status.value = val
2445
- } else {
2446
- status.peek = 'miss'
2447
- }
2448
- }
2449
- return val
2450
- }
2451
-
2452
- #backgroundFetch(
2453
- k: K,
2454
- index: Index | undefined,
2455
- options: LRUCache.FetchOptions<K, V, FC>,
2456
- context: FC,
2457
- ): BackgroundFetch<V> {
2458
- const v = index === undefined ? undefined : this.#valList[index]
2459
- if (this.#isBackgroundFetch(v)) {
2460
- return v
2461
- }
2462
-
2463
- const ac = new AbortController()
2464
- const { signal } = options
2465
- // when/if our AC signals, then stop listening to theirs.
2466
- signal?.addEventListener('abort', () => ac.abort(signal.reason), {
2467
- signal: ac.signal,
2468
- })
2469
-
2470
- const fetchOpts = {
2471
- signal: ac.signal,
2472
- options,
2473
- context,
2474
- }
2475
-
2476
- const cb = (v: V | undefined, updateCache = false): V | undefined => {
2477
- const { aborted } = ac.signal
2478
- const ignoreAbort = options.ignoreFetchAbort && v !== undefined
2479
- const proceed =
2480
- options.ignoreFetchAbort ||
2481
- !!(options.allowStaleOnFetchAbort && v !== undefined)
2482
- if (options.status) {
2483
- if (aborted && !updateCache) {
2484
- options.status.fetchAborted = true
2485
- options.status.fetchError = ac.signal.reason
2486
- if (ignoreAbort) options.status.fetchAbortIgnored = true
2487
- } else {
2488
- options.status.fetchResolved = true
2489
- }
2490
- }
2491
- if (aborted && !ignoreAbort && !updateCache) {
2492
- return fetchFail(ac.signal.reason, proceed)
2493
- }
2494
- // either we didn't abort, and are still here, or we did, and ignored
2495
- const bf = p as BackgroundFetch<V>
2496
- // if nothing else has been written there but we're set to update the
2497
- // cache and ignore the abort, or if it's still pending on this specific
2498
- // background request, then write it to the cache.
2499
- const vl = this.#valList[index as Index]
2500
- if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
2501
- if (v === undefined) {
2502
- if (bf.__staleWhileFetching !== undefined) {
2503
- this.#valList[index as Index] = bf.__staleWhileFetching
2504
- } else {
2505
- this.#delete(k, 'fetch')
2506
- }
2507
- } else {
2508
- if (options.status) options.status.fetchUpdated = true
2509
- this.#set(k, v, fetchOpts.options, bf)
2510
- }
2511
- }
2512
- return v
2513
- }
2514
-
2515
- const eb = (er: unknown) => {
2516
- if (options.status) {
2517
- options.status.fetchRejected = true
2518
- options.status.fetchError = er as Error
2519
- }
2520
- // do not pass go, do not collect $200
2521
- return fetchFail(er, false)
2522
- }
2523
-
2524
- const fetchFail = (er: unknown, proceed: boolean): V | undefined => {
2525
- const { aborted } = ac.signal
2526
- const allowStaleAborted = aborted && options.allowStaleOnFetchAbort
2527
- const allowStale =
2528
- allowStaleAborted || options.allowStaleOnFetchRejection
2529
- const noDelete = allowStale || options.noDeleteOnFetchRejection
2530
- const bf = p as BackgroundFetch<V>
2531
- if (this.#valList[index as Index] === p) {
2532
- // if we allow stale on fetch rejections, then we need to ensure that
2533
- // the stale value is not removed from the cache when the fetch fails.
2534
- const del =
2535
- !noDelete || (!proceed && bf.__staleWhileFetching === undefined)
2536
- if (del) {
2537
- this.#delete(k, 'fetch')
2538
- } else if (!allowStaleAborted) {
2539
- // still replace the *promise* with the stale value,
2540
- // since we are done with the promise at this point.
2541
- // leave it untouched if we're still waiting for an
2542
- // aborted background fetch that hasn't yet returned.
2543
- this.#valList[index as Index] = bf.__staleWhileFetching
2544
- }
2545
- }
2546
- if (allowStale) {
2547
- if (options.status && bf.__staleWhileFetching !== undefined) {
2548
- options.status.returnedStale = true
2549
- }
2550
- return bf.__staleWhileFetching
2551
- } else if (bf.__returned === bf) {
2552
- throw er
2553
- }
2554
- }
2555
-
2556
- const pcall = (
2557
- res: (v: V | undefined) => void,
2558
- rej: (e: unknown) => void,
2559
- ) => {
2560
- const fmp = this.#fetchMethod?.(k, v, fetchOpts)
2561
- // ignored, we go until we finish, regardless.
2562
- // defer check until we are actually aborting,
2563
- // so fetchMethod can override.
2564
- ac.signal.addEventListener('abort', () => {
2565
- if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
2566
- res(undefined)
2567
- // when it eventually resolves, update the cache.
2568
- if (options.allowStaleOnFetchAbort) {
2569
- res = v => cb(v, true)
2570
- }
2571
- }
2572
- })
2573
- if (fmp && fmp instanceof Promise) {
2574
- fmp.then(v => res(v === undefined ? undefined : v), rej)
2575
- } else if (fmp !== undefined) {
2576
- res(fmp)
2577
- }
2578
- }
2579
-
2580
- if (options.status) options.status.fetchDispatched = true
2581
- const p = new Promise(pcall).then(cb, eb)
2582
- const bf: BackgroundFetch<V> = Object.assign(p, {
2583
- __abortController: ac,
2584
- __staleWhileFetching: v,
2585
- __returned: undefined,
2586
- })
2587
-
2588
- if (index === undefined) {
2589
- // internal, don't expose status.
2590
- this.#set(k, bf, { ...fetchOpts.options, status: undefined })
2591
- index = this.#keyMap.get(k)
2592
- } else {
2593
- this.#valList[index] = bf
2594
- }
2595
- return bf
2596
- }
2597
-
2598
- #isBackgroundFetch(p: unknown): p is BackgroundFetch<V> {
2599
- if (!this.#hasFetchMethod) return false
2600
- const b = p as BackgroundFetch<V>
2601
- return (
2602
- !!b &&
2603
- b instanceof Promise &&
2604
- b.hasOwnProperty('__staleWhileFetching') &&
2605
- b.__abortController instanceof AbortController
2606
- )
2607
- }
2608
-
2609
- /**
2610
- * Make an asynchronous cached fetch using the
2611
- * {@link LRUCache.OptionsBase.fetchMethod} function.
2612
- *
2613
- * If the value is in the cache and not stale, then the returned
2614
- * Promise resolves to the value.
2615
- *
2616
- * If not in the cache, or beyond its TTL staleness, then
2617
- * `fetchMethod(key, staleValue, { options, signal, context })` is
2618
- * called, and the value returned will be added to the cache once
2619
- * resolved.
2620
- *
2621
- * If called with `allowStale`, and an asynchronous fetch is
2622
- * currently in progress to reload a stale value, then the former
2623
- * stale value will be returned.
2624
- *
2625
- * If called with `forceRefresh`, then the cached item will be
2626
- * re-fetched, even if it is not stale. However, if `allowStale` is also
2627
- * set, then the old value will still be returned. This is useful
2628
- * in cases where you want to force a reload of a cached value. If
2629
- * a background fetch is already in progress, then `forceRefresh`
2630
- * has no effect.
2631
- *
2632
- * If multiple fetches for the same key are issued, then they will all be
2633
- * coalesced into a single call to fetchMethod.
2634
- *
2635
- * Note that this means that handling options such as
2636
- * {@link LRUCache.OptionsBase.allowStaleOnFetchAbort},
2637
- * {@link LRUCache.FetchOptions.signal},
2638
- * and {@link LRUCache.OptionsBase.allowStaleOnFetchRejection} will be
2639
- * determined by the FIRST fetch() call for a given key.
2640
- *
2641
- * This is a known (fixable) shortcoming which will be addresed on when
2642
- * someone complains about it, as the fix would involve added complexity and
2643
- * may not be worth the costs for this edge case.
2644
- *
2645
- * If {@link LRUCache.OptionsBase.fetchMethod} is not specified, then this is
2646
- * effectively an alias for `Promise.resolve(cache.get(key))`.
2647
- *
2648
- * When the fetch method resolves to a value, if the fetch has not
2649
- * been aborted due to deletion, eviction, or being overwritten,
2650
- * then it is added to the cache using the options provided.
2651
- *
2652
- * If the key is evicted or deleted before the `fetchMethod`
2653
- * resolves, then the AbortSignal passed to the `fetchMethod` will
2654
- * receive an `abort` event, and the promise returned by `fetch()`
2655
- * will reject with the reason for the abort.
2656
- *
2657
- * If a `signal` is passed to the `fetch()` call, then aborting the
2658
- * signal will abort the fetch and cause the `fetch()` promise to
2659
- * reject with the reason provided.
2660
- *
2661
- * **Setting `context`**
2662
- *
2663
- * If an `FC` type is set to a type other than `unknown`, `void`, or
2664
- * `undefined` in the {@link LRUCache} constructor, then all
2665
- * calls to `cache.fetch()` _must_ provide a `context` option. If
2666
- * set to `undefined` or `void`, then calls to fetch _must not_
2667
- * provide a `context` option.
2668
- *
2669
- * The `context` param allows you to provide arbitrary data that
2670
- * might be relevant in the course of fetching the data. It is only
2671
- * relevant for the course of a single `fetch()` operation, and
2672
- * discarded afterwards.
2673
- *
2674
- * **Note: `fetch()` calls are inflight-unique**
2675
- *
2676
- * If you call `fetch()` multiple times with the same key value,
2677
- * then every call after the first will resolve on the same
2678
- * promise<sup>1</sup>,
2679
- * _even if they have different settings that would otherwise change
2680
- * the behavior of the fetch_, such as `noDeleteOnFetchRejection`
2681
- * or `ignoreFetchAbort`.
2682
- *
2683
- * In most cases, this is not a problem (in fact, only fetching
2684
- * something once is what you probably want, if you're caching in
2685
- * the first place). If you are changing the fetch() options
2686
- * dramatically between runs, there's a good chance that you might
2687
- * be trying to fit divergent semantics into a single object, and
2688
- * would be better off with multiple cache instances.
2689
- *
2690
- * **1**: Ie, they're not the "same Promise", but they resolve at
2691
- * the same time, because they're both waiting on the same
2692
- * underlying fetchMethod response.
2693
- */
2694
-
2695
- fetch(
2696
- k: K,
2697
- fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC>
2698
- : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V>
2699
- : LRUCache.FetchOptionsWithContext<K, V, FC>,
2700
- ): Promise<undefined | V>
2701
-
2702
- // this overload not allowed if context is required
2703
- fetch(
2704
- k: unknown extends FC ? K
2705
- : FC extends undefined | void ? K
2706
- : never,
2707
- fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC>
2708
- : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V>
2709
- : never,
2710
- ): Promise<undefined | V>
2711
- fetch(
2712
- k: K,
2713
- fetchOptions: LRUCache.FetchOptions<K, V, FC> = {},
2714
- ): Promise<undefined | V> {
2715
- const ths = tracing.hasSubscribers
2716
- const { status = hasSubscribers() ? {} : undefined } = fetchOptions
2717
- fetchOptions.status = status
2718
- if (status && fetchOptions.context) {
2719
- status.context = fetchOptions.context
2720
- }
2721
- const p = this.#fetch(k, fetchOptions)
2722
- if (status && ths) {
2723
- status.trace = true
2724
- tracing.tracePromise(() => p, status).catch(() => {})
2725
- }
2726
- return p
2727
- }
2728
-
2729
- async #fetch(
2730
- k: K,
2731
- fetchOptions: LRUCache.FetchOptions<K, V, FC> = {},
2732
- ): Promise<undefined | V> {
2733
- const {
2734
- // get options
2735
- allowStale = this.allowStale,
2736
- updateAgeOnGet = this.updateAgeOnGet,
2737
- noDeleteOnStaleGet = this.noDeleteOnStaleGet,
2738
- // set options
2739
- ttl = this.ttl,
2740
- noDisposeOnSet = this.noDisposeOnSet,
2741
- size = 0,
2742
- sizeCalculation = this.sizeCalculation,
2743
- noUpdateTTL = this.noUpdateTTL,
2744
- // fetch exclusive options
2745
- noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
2746
- allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
2747
- ignoreFetchAbort = this.ignoreFetchAbort,
2748
- allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
2749
- context,
2750
- forceRefresh = false,
2751
- status,
2752
- signal,
2753
- } = fetchOptions
2754
- if (status) {
2755
- status.op = 'fetch'
2756
- status.key = k
2757
- if (forceRefresh) status.forceRefresh = true
2758
- }
2759
-
2760
- if (!this.#hasFetchMethod) {
2761
- if (status) status.fetch = 'get'
2762
- return this.#get(k, {
2763
- allowStale,
2764
- updateAgeOnGet,
2765
- noDeleteOnStaleGet,
2766
- status,
2767
- })
2768
- }
2769
-
2770
- const options = {
2771
- allowStale,
2772
- updateAgeOnGet,
2773
- noDeleteOnStaleGet,
2774
- ttl,
2775
- noDisposeOnSet,
2776
- size,
2777
- sizeCalculation,
2778
- noUpdateTTL,
2779
- noDeleteOnFetchRejection,
2780
- allowStaleOnFetchRejection,
2781
- allowStaleOnFetchAbort,
2782
- ignoreFetchAbort,
2783
- status,
2784
- signal,
2785
- }
2786
-
2787
- let index = this.#keyMap.get(k)
2788
- if (index === undefined) {
2789
- if (status) status.fetch = 'miss'
2790
- const p = this.#backgroundFetch(k, index, options, context as FC)
2791
- return (p.__returned = p)
2792
- } else {
2793
- // in cache, maybe already fetching
2794
- const v = this.#valList[index]
2795
- if (this.#isBackgroundFetch(v)) {
2796
- const stale = allowStale && v.__staleWhileFetching !== undefined
2797
- if (status) {
2798
- status.fetch = 'inflight'
2799
- if (stale) status.returnedStale = true
2800
- }
2801
- return stale ? v.__staleWhileFetching : (v.__returned = v)
2802
- }
2803
-
2804
- // if we force a refresh, that means do NOT serve the cached value,
2805
- // unless we are already in the process of refreshing the cache.
2806
- const isStale = this.#isStale(index)
2807
- if (!forceRefresh && !isStale) {
2808
- if (status) status.fetch = 'hit'
2809
- this.#moveToTail(index)
2810
- if (updateAgeOnGet) {
2811
- this.#updateItemAge(index)
2812
- }
2813
- if (status) this.#statusTTL(status, index)
2814
- return v
2815
- }
2816
-
2817
- // ok, it is stale or a forced refresh, and not already fetching.
2818
- // refresh the cache.
2819
- const p = this.#backgroundFetch(k, index, options, context as FC)
2820
- const hasStale = p.__staleWhileFetching !== undefined
2821
- const staleVal = hasStale && allowStale
2822
- if (status) {
2823
- status.fetch = isStale ? 'stale' : 'refresh'
2824
- if (staleVal && isStale) status.returnedStale = true
2825
- }
2826
- return staleVal ? p.__staleWhileFetching : (p.__returned = p)
2827
- }
2828
- }
2829
-
2830
- /**
2831
- * In some cases, `cache.fetch()` may resolve to `undefined`, either because
2832
- * a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
2833
- * `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
2834
- * because `ignoreFetchAbort` was specified (either to the constructor or
2835
- * in the {@link LRUCache.FetchOptions}). Also, the
2836
- * {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
2837
- * the test even more complicated.
2838
- *
2839
- * Because inferring the cases where `undefined` might be returned are so
2840
- * cumbersome, but testing for `undefined` can also be annoying, this method
2841
- * can be used, which will reject if `this.fetch()` resolves to undefined.
2842
- */
2843
- forceFetch(
2844
- k: K,
2845
- fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC>
2846
- : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V>
2847
- : LRUCache.FetchOptionsWithContext<K, V, FC>,
2848
- ): Promise<V>
2849
- // this overload not allowed if context is required
2850
- forceFetch(
2851
- k: unknown extends FC ? K
2852
- : FC extends undefined | void ? K
2853
- : never,
2854
- fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC>
2855
- : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V>
2856
- : never,
2857
- ): Promise<V>
2858
- forceFetch(
2859
- k: K,
2860
- fetchOptions: LRUCache.FetchOptions<K, V, FC> = {},
2861
- ): Promise<V> {
2862
- const ths = tracing.hasSubscribers
2863
- const { status = hasSubscribers() ? {} : undefined } = fetchOptions
2864
- fetchOptions.status = status
2865
- if (status && fetchOptions.context) {
2866
- status.context = fetchOptions.context
2867
- }
2868
- const p = this.#forceFetch(k, fetchOptions)
2869
- if (status && ths) {
2870
- status.trace = true
2871
- tracing.tracePromise(() => p, status).catch(() => {})
2872
- }
2873
- return p
2874
- }
2875
-
2876
- async #forceFetch(
2877
- k: K,
2878
- fetchOptions: LRUCache.FetchOptions<K, V, FC> = {},
2879
- ) {
2880
- const v = await this.#fetch(
2881
- k,
2882
- fetchOptions as unknown extends FC ? LRUCache.FetchOptions<K, V, FC>
2883
- : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V>
2884
- : LRUCache.FetchOptionsWithContext<K, V, FC>,
2885
- )
2886
- if (v === undefined) throw new Error('fetch() returned undefined')
2887
- return v
2888
- }
2889
-
2890
- /**
2891
- * If the key is found in the cache, then this is equivalent to
2892
- * {@link LRUCache#get}. If not, in the cache, then calculate the value using
2893
- * the {@link LRUCache.OptionsBase.memoMethod}, and add it to the cache.
2894
- *
2895
- * If an `FC` type is set to a type other than `unknown`, `void`, or
2896
- * `undefined` in the LRUCache constructor, then all calls to `cache.memo()`
2897
- * _must_ provide a `context` option. If set to `undefined` or `void`, then
2898
- * calls to memo _must not_ provide a `context` option.
2899
- *
2900
- * The `context` param allows you to provide arbitrary data that might be
2901
- * relevant in the course of fetching the data. It is only relevant for the
2902
- * course of a single `memo()` operation, and discarded afterwards.
2903
- */
2904
- memo(
2905
- k: K,
2906
- memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC>
2907
- : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V>
2908
- : LRUCache.MemoOptionsWithContext<K, V, FC>,
2909
- ): V
2910
- // this overload not allowed if context is required
2911
- memo(
2912
- k: unknown extends FC ? K
2913
- : FC extends undefined | void ? K
2914
- : never,
2915
- memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC>
2916
- : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V>
2917
- : never,
2918
- ): V
2919
- memo(k: K, memoOptions: LRUCache.MemoOptions<K, V, FC> = {}) {
2920
- const { status = metrics.hasSubscribers ? {} : undefined } =
2921
- memoOptions
2922
- memoOptions.status = status
2923
- if (status) {
2924
- status.op = 'memo'
2925
- status.key = k
2926
- if (memoOptions.context) {
2927
- status.context = memoOptions.context
2928
- }
2929
- }
2930
- const result = this.#memo(k, memoOptions)
2931
- if (status) status.value = result
2932
- if (metrics.hasSubscribers) metrics.publish(status)
2933
- return result
2934
- }
2935
- #memo(k: K, memoOptions: LRUCache.MemoOptions<K, V, FC> = {}) {
2936
- const memoMethod = this.#memoMethod
2937
- if (!memoMethod) {
2938
- throw new Error('no memoMethod provided to constructor')
2939
- }
2940
- const { context, status, forceRefresh, ...options } = memoOptions
2941
- if (status && forceRefresh) status.forceRefresh = true
2942
- const v = this.#get(k, options)
2943
- const refresh = forceRefresh || v === undefined
2944
- if (status) {
2945
- status.memo = refresh ? 'miss' : 'hit'
2946
- if (!refresh) status.value = v
2947
- }
2948
- if (!refresh) return v
2949
- const vv = memoMethod(k, v, {
2950
- options,
2951
- context,
2952
- } as LRUCache.MemoizerOptions<K, V, FC>)
2953
- if (status) status.value = vv
2954
- this.#set(k, vv, options)
2955
- return vv
2956
- }
2957
-
2958
- /**
2959
- * Return a value from the cache. Will update the recency of the cache
2960
- * entry found.
2961
- *
2962
- * If the key is not found, get() will return `undefined`.
2963
- */
2964
- get(k: K, getOptions: LRUCache.GetOptions<K, V, FC> = {}) {
2965
- const { status = metrics.hasSubscribers ? {} : undefined } = getOptions
2966
- getOptions.status = status
2967
- if (status) {
2968
- status.op = 'get'
2969
- status.key = k
2970
- }
2971
- const result = this.#get(k, getOptions)
2972
- if (status) {
2973
- if (result !== undefined) status.value = result
2974
- if (metrics.hasSubscribers) metrics.publish(status)
2975
- }
2976
- return result
2977
- }
2978
-
2979
- #get(k: K, getOptions: LRUCache.GetOptions<K, V, FC> = {}) {
2980
- const {
2981
- allowStale = this.allowStale,
2982
- updateAgeOnGet = this.updateAgeOnGet,
2983
- noDeleteOnStaleGet = this.noDeleteOnStaleGet,
2984
- status,
2985
- } = getOptions
2986
- const index = this.#keyMap.get(k)
2987
- if (index === undefined) {
2988
- if (status) status.get = 'miss'
2989
- return undefined
2990
- }
2991
- const value = this.#valList[index]
2992
- const fetching = this.#isBackgroundFetch(value)
2993
- if (status) this.#statusTTL(status, index)
2994
- if (this.#isStale(index)) {
2995
- // delete only if not an in-flight background fetch
2996
- if (!fetching) {
2997
- if (!noDeleteOnStaleGet) {
2998
- this.#delete(k, 'expire')
2999
- }
3000
- if (status) status.get = 'stale'
3001
- if (allowStale) {
3002
- if (status) status.returnedStale = true
3003
- return value
3004
- }
3005
- return undefined
3006
- }
3007
- if (status) status.get = 'stale-fetching'
3008
- if (allowStale && value.__staleWhileFetching !== undefined) {
3009
- if (status) status.returnedStale = true
3010
- return value.__staleWhileFetching
3011
- }
3012
- return undefined
3013
- }
3014
- // not stale
3015
- if (status) status.get = fetching ? 'fetching' : 'hit'
3016
- // if we're currently fetching it, we don't actually have it yet
3017
- // it's not stale, which means this isn't a staleWhileRefetching.
3018
- // If it's not stale, and fetching, AND has a __staleWhileFetching
3019
- // value, then that means the user fetched with {forceRefresh:true},
3020
- // so it's safe to return that value.
3021
- this.#moveToTail(index)
3022
- if (updateAgeOnGet) {
3023
- this.#updateItemAge(index)
3024
- }
3025
- return fetching ? value.__staleWhileFetching : value
3026
- }
3027
-
3028
- #connect(p: Index, n: Index) {
3029
- this.#prev[n] = p
3030
- this.#next[p] = n
3031
- }
3032
-
3033
- #moveToTail(index: Index): void {
3034
- // if tail already, nothing to do
3035
- // if head, move head to next[index]
3036
- // else
3037
- // move next[prev[index]] to next[index] (head has no prev)
3038
- // move prev[next[index]] to prev[index]
3039
- // prev[index] = tail
3040
- // next[tail] = index
3041
- // tail = index
3042
- if (index !== this.#tail) {
3043
- if (index === this.#head) {
3044
- this.#head = this.#next[index] as Index
3045
- } else {
3046
- this.#connect(
3047
- this.#prev[index] as Index,
3048
- this.#next[index] as Index,
3049
- )
3050
- }
3051
- this.#connect(this.#tail, index)
3052
- this.#tail = index
3053
- }
3054
- }
3055
-
3056
- /**
3057
- * Deletes a key out of the cache.
3058
- *
3059
- * Returns true if the key was deleted, false otherwise.
3060
- */
3061
- delete(k: K) {
3062
- return this.#delete(k, 'delete')
3063
- }
3064
-
3065
- #delete(k: K, reason: LRUCache.DisposeReason) {
3066
- if (metrics.hasSubscribers) {
3067
- metrics.publish({
3068
- op: 'delete',
3069
- delete: reason,
3070
- key: k,
3071
- })
3072
- }
3073
- let deleted = false
3074
- if (this.#size !== 0) {
3075
- const index = this.#keyMap.get(k)
3076
- if (index !== undefined) {
3077
- if (this.#autopurgeTimers?.[index]) {
3078
- clearTimeout(this.#autopurgeTimers?.[index])
3079
- this.#autopurgeTimers[index] = undefined
3080
- }
3081
- deleted = true
3082
- if (this.#size === 1) {
3083
- this.#clear(reason)
3084
- } else {
3085
- this.#removeItemSize(index)
3086
- const v = this.#valList[index]
3087
- if (this.#isBackgroundFetch(v)) {
3088
- v.__abortController.abort(new Error('deleted'))
3089
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
3090
- if (this.#hasDispose) {
3091
- this.#dispose?.(v as V, k, reason)
3092
- }
3093
- if (this.#hasDisposeAfter) {
3094
- this.#disposed?.push([v as V, k, reason])
3095
- }
3096
- }
3097
- this.#keyMap.delete(k)
3098
- this.#keyList[index] = undefined
3099
- this.#valList[index] = undefined
3100
- if (index === this.#tail) {
3101
- this.#tail = this.#prev[index] as Index
3102
- } else if (index === this.#head) {
3103
- this.#head = this.#next[index] as Index
3104
- } else {
3105
- const pi = this.#prev[index] as number
3106
- this.#next[pi] = this.#next[index] as number
3107
- const ni = this.#next[index] as number
3108
- this.#prev[ni] = this.#prev[index] as number
3109
- }
3110
- this.#size--
3111
- this.#free.push(index)
3112
- }
3113
- }
3114
- }
3115
- if (this.#hasDisposeAfter && this.#disposed?.length) {
3116
- const dt = this.#disposed
3117
- let task: DisposeTask<K, V> | undefined
3118
- while ((task = dt?.shift())) {
3119
- this.#disposeAfter?.(...task)
3120
- }
3121
- }
3122
- return deleted
3123
- }
3124
-
3125
- /**
3126
- * Clear the cache entirely, throwing away all values.
3127
- */
3128
- clear() {
3129
- return this.#clear('delete')
3130
- }
3131
- #clear(reason: LRUCache.DisposeReason) {
3132
- for (const index of this.#rindexes({ allowStale: true })) {
3133
- const v = this.#valList[index]
3134
- if (this.#isBackgroundFetch(v)) {
3135
- v.__abortController.abort(new Error('deleted'))
3136
- } else {
3137
- const k = this.#keyList[index]
3138
- if (this.#hasDispose) {
3139
- this.#dispose?.(v as V, k as K, reason)
3140
- }
3141
- if (this.#hasDisposeAfter) {
3142
- this.#disposed?.push([v as V, k as K, reason])
3143
- }
3144
- }
3145
- }
3146
-
3147
- this.#keyMap.clear()
3148
- void this.#valList.fill(undefined)
3149
- this.#keyList.fill(undefined)
3150
- if (this.#ttls && this.#starts) {
3151
- this.#ttls.fill(0)
3152
- this.#starts.fill(0)
3153
- for (const t of this.#autopurgeTimers ?? []) {
3154
- if (t !== undefined) clearTimeout(t)
3155
- }
3156
- this.#autopurgeTimers?.fill(undefined)
3157
- }
3158
- if (this.#sizes) {
3159
- this.#sizes.fill(0)
3160
- }
3161
- this.#head = 0 as Index
3162
- this.#tail = 0 as Index
3163
- this.#free.length = 0
3164
- this.#calculatedSize = 0
3165
- this.#size = 0
3166
- if (this.#hasDisposeAfter && this.#disposed) {
3167
- const dt = this.#disposed
3168
- let task: DisposeTask<K, V> | undefined
3169
- while ((task = dt?.shift())) {
3170
- this.#disposeAfter?.(...task)
3171
- }
3172
- }
3173
- }
3174
- }