@openclaw/whatsapp 2026.7.1-beta.2 → 2026.7.1-beta.4

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 (516) hide show
  1. package/dist/{access-control-88UPniDc.js → access-control-DYE5dXna.js} +5 -3
  2. package/dist/{accounts-DgViSyJx.js → accounts-4YgwroRU.js} +1 -1
  3. package/dist/{action-runtime-hqza0J8B.js → action-runtime-DPahAqxV.js} +2 -2
  4. package/dist/action-runtime-api.js +1 -1
  5. package/dist/action-runtime.runtime.js +1 -1
  6. package/dist/{active-listener-CFwkn3ho.js → active-listener-B4SDebQ6.js} +1 -1
  7. package/dist/api.js +14 -13
  8. package/dist/{approval-handler.runtime-9_SV7vhc.js → approval-handler.runtime-DNWS4aYQ.js} +1 -1
  9. package/dist/auth-presence.js +1 -1
  10. package/dist/{auth-store-ECx4h57q.js → auth-store-Db-wfApd.js} +23 -13
  11. package/dist/call-tool-api.js +233 -0
  12. package/dist/{channel-fcXxWXic.js → channel-BWp7h1uY.js} +44 -18
  13. package/dist/channel-config-api.js +1 -1
  14. package/dist/channel-plugin-api.js +1 -1
  15. package/dist/{channel-react-action-Dgy9uUMl.js → channel-react-action-CKJHL_Wf.js} +3 -3
  16. package/dist/{channel.runtime-B4ThooGF.js → channel.runtime-CAssfx9p.js} +5 -5
  17. package/dist/{channel.setup-C_WEdyJR.js → channel.setup-CURc5rEt.js} +2 -2
  18. package/dist/{config-schema-CROZuhT-.js → config-schema-mBX2nmn1.js} +4 -0
  19. package/dist/{connection-controller-u-tfAFhJ.js → connection-controller-DkbrFSIn.js} +6 -5
  20. package/dist/connection-controller-registry-TSX_udJp.js +22 -0
  21. package/dist/contract-api.js +1 -1
  22. package/dist/{quoted-message-CpA_ujXK.js → group-session-key-BhC1RQOE.js} +31 -2
  23. package/dist/{identity-CmsTmkKR.js → identity-Dqft3mFA.js} +2 -1
  24. package/dist/index.js +9 -2
  25. package/dist/light-runtime-api.js +3 -3
  26. package/dist/{login-8lHwLmXj.js → login-C48y0jlx.js} +14 -7
  27. package/dist/{login-qr-BEZZqrTb.js → login-qr-BjId7dll.js} +7 -7
  28. package/dist/login-qr-runtime.js +1 -1
  29. package/dist/{monitor-BqkJ4MpT.js → monitor-DD8bXohk.js} +249 -160
  30. package/dist/runtime-api.js +9 -9
  31. package/dist/{send-i8Xk5mBQ.js → send-C5CpFcBG.js} +27 -9
  32. package/dist/{send-api-DndiBJhN.js → send-api-DLlXl8CH.js} +6 -5
  33. package/dist/{session-WU4SVP8f.js → session-DriaHt7V.js} +3 -3
  34. package/dist/{session-errors-CbsoQqoy.js → session-errors-BAj9D2La.js} +1 -22
  35. package/dist/{setup-core-KjSBbWX4.js → setup-core-DH-DFPLY.js} +4 -4
  36. package/dist/{setup-finalize-WedNP30s.js → setup-finalize-c8dl34sO.js} +3 -3
  37. package/dist/setup-plugin-api.js +1 -1
  38. package/dist/{setup-surface-IOdkbWsQ.js → setup-surface-DlWb0Z09.js} +3 -3
  39. package/dist/{socket-timing-DvMNkIge.js → socket-timing-DhbVFjah.js} +17 -5
  40. package/dist/{text-runtime-C88QkuU9.js → targets-runtime-C-GiVn6Y.js} +2 -3
  41. package/dist/text-runtime-DdX6-mC_.js +4 -0
  42. package/node_modules/@cacheable/memory/README.md +177 -0
  43. package/node_modules/@cacheable/memory/dist/index.cjs +867 -820
  44. package/node_modules/@cacheable/memory/dist/index.d.cts +382 -280
  45. package/node_modules/@cacheable/memory/dist/index.d.mts +412 -0
  46. package/node_modules/@cacheable/memory/dist/index.mjs +841 -0
  47. package/node_modules/@cacheable/memory/package.json +9 -9
  48. package/node_modules/@cacheable/utils/README.md +342 -8
  49. package/node_modules/@cacheable/utils/dist/index.cjs +1322 -619
  50. package/node_modules/@cacheable/utils/dist/index.d.cts +769 -173
  51. package/node_modules/@cacheable/utils/dist/index.d.mts +903 -0
  52. package/node_modules/@cacheable/utils/dist/index.mjs +1355 -0
  53. package/node_modules/@cacheable/utils/package.json +8 -8
  54. package/node_modules/@types/node/README.md +1 -1
  55. package/node_modules/@types/node/assert/strict.d.ts +10 -1
  56. package/node_modules/@types/node/assert.d.ts +144 -17
  57. package/node_modules/@types/node/async_hooks.d.ts +9 -9
  58. package/node_modules/@types/node/buffer.d.ts +64 -30
  59. package/node_modules/@types/node/child_process.d.ts +17 -21
  60. package/node_modules/@types/node/cluster.d.ts +13 -13
  61. package/node_modules/@types/node/console.d.ts +1 -1
  62. package/node_modules/@types/node/crypto.d.ts +471 -575
  63. package/node_modules/@types/node/diagnostics_channel.d.ts +274 -32
  64. package/node_modules/@types/node/dns.d.ts +15 -15
  65. package/node_modules/@types/node/events.d.ts +3 -3
  66. package/node_modules/@types/node/ffi.d.ts +486 -0
  67. package/node_modules/@types/node/fs/promises.d.ts +7 -4
  68. package/node_modules/@types/node/fs.d.ts +24 -18
  69. package/node_modules/@types/node/globals.d.ts +4 -4
  70. package/node_modules/@types/node/http.d.ts +30 -5
  71. package/node_modules/@types/node/http2.d.ts +5 -1
  72. package/node_modules/@types/node/index.d.ts +1 -3
  73. package/node_modules/@types/node/inspector.d.ts +1 -1
  74. package/node_modules/@types/node/module.d.ts +16 -45
  75. package/node_modules/@types/node/net.d.ts +1 -1
  76. package/node_modules/@types/node/os.d.ts +2 -2
  77. package/node_modules/@types/node/package.json +4 -4
  78. package/node_modules/@types/node/perf_hooks.d.ts +1 -9
  79. package/node_modules/@types/node/process.d.ts +25 -12
  80. package/node_modules/@types/node/quic.d.ts +92 -11
  81. package/node_modules/@types/node/readline.d.ts +12 -11
  82. package/node_modules/@types/node/repl.d.ts +10 -10
  83. package/node_modules/@types/node/sqlite.d.ts +56 -1
  84. package/node_modules/@types/node/stream/iter.d.ts +150 -0
  85. package/node_modules/@types/node/stream/promises.d.ts +2 -2
  86. package/node_modules/@types/node/stream/web.d.ts +1 -1
  87. package/node_modules/@types/node/stream.d.ts +37 -5
  88. package/node_modules/@types/node/test/reporters.d.ts +1 -1
  89. package/node_modules/@types/node/test.d.ts +120 -10
  90. package/node_modules/@types/node/tls.d.ts +1 -1
  91. package/node_modules/@types/node/ts5.6/index.d.ts +2 -4
  92. package/node_modules/@types/node/ts5.7/index.d.ts +1 -3
  93. package/node_modules/@types/node/url.d.ts +3 -3
  94. package/node_modules/@types/node/util/types.d.ts +1 -1
  95. package/node_modules/@types/node/util.d.ts +22 -22
  96. package/node_modules/@types/node/v8.d.ts +85 -3
  97. package/node_modules/@types/node/vm.d.ts +9 -9
  98. package/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
  99. package/node_modules/@types/node/worker_threads.d.ts +10 -12
  100. package/node_modules/@types/node/zlib.d.ts +3 -3
  101. package/node_modules/cacheable/README.md +309 -30
  102. package/node_modules/cacheable/dist/index.cjs +1307 -1153
  103. package/node_modules/cacheable/dist/index.d.cts +741 -469
  104. package/node_modules/cacheable/dist/index.d.mts +766 -0
  105. package/node_modules/cacheable/dist/index.mjs +1210 -0
  106. package/node_modules/cacheable/package.json +10 -10
  107. package/node_modules/content-type/README.md +32 -57
  108. package/node_modules/content-type/dist/index.d.ts +26 -0
  109. package/node_modules/content-type/dist/index.js +170 -0
  110. package/node_modules/content-type/dist/index.js.map +1 -0
  111. package/node_modules/content-type/package.json +35 -25
  112. package/node_modules/media-typer/README.md +19 -33
  113. package/node_modules/media-typer/dist/index.d.ts +29 -0
  114. package/node_modules/media-typer/dist/index.js +64 -0
  115. package/node_modules/media-typer/dist/index.js.map +1 -0
  116. package/node_modules/media-typer/package.json +37 -22
  117. package/node_modules/music-metadata/lib/id3v1/ID3v1Parser.js +2 -2
  118. package/node_modules/music-metadata/lib/mp4/AtomToken.js +65 -13
  119. package/node_modules/music-metadata/lib/wav/WaveChunk.d.ts +10 -0
  120. package/node_modules/music-metadata/lib/wav/WaveChunk.js +13 -3
  121. package/node_modules/music-metadata/lib/wav/WaveParser.d.ts +1 -0
  122. package/node_modules/music-metadata/lib/wav/WaveParser.js +6 -5
  123. package/node_modules/music-metadata/package.json +5 -5
  124. package/node_modules/typebox/build/compile/validator.d.mts +2 -7
  125. package/node_modules/typebox/build/compile/validator.mjs +6 -36
  126. package/node_modules/typebox/build/error/errors.d.mts +1 -7
  127. package/node_modules/typebox/build/format/_idna.mjs +36 -6
  128. package/node_modules/typebox/build/format/_puny.mjs +4 -1
  129. package/node_modules/typebox/build/format/uuid.d.mts +2 -2
  130. package/node_modules/typebox/build/format/uuid.mjs +3 -3
  131. package/node_modules/typebox/build/guard/emit.d.mts +0 -4
  132. package/node_modules/typebox/build/guard/emit.mjs +0 -8
  133. package/node_modules/typebox/build/guard/guard.d.mts +4 -8
  134. package/node_modules/typebox/build/guard/guard.mjs +5 -13
  135. package/node_modules/typebox/build/schema/engine/boolean.d.mts +3 -3
  136. package/node_modules/typebox/build/schema/engine/boolean.mjs +4 -4
  137. package/node_modules/typebox/build/schema/engine/index.d.mts +0 -1
  138. package/node_modules/typebox/build/schema/engine/index.mjs +0 -1
  139. package/node_modules/typebox/build/schema/engine/schema.mjs +5 -10
  140. package/node_modules/typebox/build/schema/engine/type.mjs +14 -18
  141. package/node_modules/typebox/build/schema/types/dependencies.mjs +1 -1
  142. package/node_modules/typebox/build/schema/types/index.d.mts +0 -1
  143. package/node_modules/typebox/build/schema/types/index.mjs +0 -1
  144. package/node_modules/typebox/build/schema/types/schema.d.mts +1 -1
  145. package/node_modules/typebox/build/schema/types/schema.mjs +2 -2
  146. package/node_modules/typebox/build/system/locale/ar_001.mjs +0 -1
  147. package/node_modules/typebox/build/system/locale/bn_BD.mjs +0 -1
  148. package/node_modules/typebox/build/system/locale/cs_CZ.mjs +0 -1
  149. package/node_modules/typebox/build/system/locale/de_DE.mjs +0 -1
  150. package/node_modules/typebox/build/system/locale/el_GR.mjs +0 -1
  151. package/node_modules/typebox/build/system/locale/en_US.mjs +0 -1
  152. package/node_modules/typebox/build/system/locale/es_419.mjs +0 -1
  153. package/node_modules/typebox/build/system/locale/es_AR.mjs +0 -1
  154. package/node_modules/typebox/build/system/locale/es_ES.mjs +0 -1
  155. package/node_modules/typebox/build/system/locale/es_MX.mjs +0 -1
  156. package/node_modules/typebox/build/system/locale/fa_IR.mjs +0 -1
  157. package/node_modules/typebox/build/system/locale/fil_PH.mjs +0 -1
  158. package/node_modules/typebox/build/system/locale/fr_CA.mjs +0 -1
  159. package/node_modules/typebox/build/system/locale/fr_FR.mjs +0 -1
  160. package/node_modules/typebox/build/system/locale/ha_NG.mjs +0 -1
  161. package/node_modules/typebox/build/system/locale/hi_IN.mjs +0 -1
  162. package/node_modules/typebox/build/system/locale/hu_HU.mjs +0 -1
  163. package/node_modules/typebox/build/system/locale/id_ID.mjs +0 -1
  164. package/node_modules/typebox/build/system/locale/it_IT.mjs +0 -1
  165. package/node_modules/typebox/build/system/locale/ja_JP.mjs +0 -1
  166. package/node_modules/typebox/build/system/locale/ko_KR.mjs +0 -1
  167. package/node_modules/typebox/build/system/locale/ms_MY.mjs +0 -1
  168. package/node_modules/typebox/build/system/locale/nl_NL.mjs +0 -1
  169. package/node_modules/typebox/build/system/locale/pl_PL.mjs +0 -1
  170. package/node_modules/typebox/build/system/locale/pt_BR.mjs +0 -1
  171. package/node_modules/typebox/build/system/locale/pt_PT.mjs +0 -1
  172. package/node_modules/typebox/build/system/locale/ro_RO.mjs +0 -1
  173. package/node_modules/typebox/build/system/locale/ru_RU.mjs +0 -1
  174. package/node_modules/typebox/build/system/locale/sv_SE.mjs +0 -1
  175. package/node_modules/typebox/build/system/locale/sw_TZ.mjs +0 -1
  176. package/node_modules/typebox/build/system/locale/th_TH.mjs +0 -1
  177. package/node_modules/typebox/build/system/locale/tr_TR.mjs +0 -1
  178. package/node_modules/typebox/build/system/locale/uk_UA.mjs +0 -1
  179. package/node_modules/typebox/build/system/locale/ur_PK.mjs +0 -1
  180. package/node_modules/typebox/build/system/locale/vi_VN.mjs +0 -1
  181. package/node_modules/typebox/build/system/locale/yo_NG.mjs +0 -1
  182. package/node_modules/typebox/build/system/locale/zh_Hans.mjs +0 -1
  183. package/node_modules/typebox/build/system/locale/zh_Hant.mjs +0 -1
  184. package/node_modules/typebox/build/system/memory/clone.d.mts +2 -3
  185. package/node_modules/typebox/build/system/memory/clone.mjs +73 -26
  186. package/node_modules/typebox/build/system/settings/settings.d.mts +15 -0
  187. package/node_modules/typebox/build/system/settings/settings.mjs +3 -1
  188. package/node_modules/typebox/build/type/action/_add_immutable.d.mts +11 -0
  189. package/node_modules/typebox/build/type/action/_add_immutable.mjs +11 -0
  190. package/node_modules/typebox/build/type/action/_add_optional.d.mts +11 -0
  191. package/node_modules/typebox/build/type/action/_add_optional.mjs +11 -0
  192. package/node_modules/typebox/build/type/action/_add_readonly.d.mts +11 -0
  193. package/node_modules/typebox/build/type/action/_add_readonly.mjs +11 -0
  194. package/node_modules/typebox/build/type/action/_remove_immutable.d.mts +11 -0
  195. package/node_modules/typebox/build/type/action/_remove_immutable.mjs +11 -0
  196. package/node_modules/typebox/build/type/action/_remove_optional.d.mts +11 -0
  197. package/node_modules/typebox/build/type/action/_remove_optional.mjs +11 -0
  198. package/node_modules/typebox/build/type/action/_remove_readonly.d.mts +11 -0
  199. package/node_modules/typebox/build/type/action/_remove_readonly.mjs +11 -0
  200. package/node_modules/typebox/build/type/action/conditional.d.mts +2 -3
  201. package/node_modules/typebox/build/type/action/conditional.mjs +2 -1
  202. package/node_modules/typebox/build/type/action/index.d.mts +7 -4
  203. package/node_modules/typebox/build/type/action/index.mjs +7 -4
  204. package/node_modules/typebox/build/type/action/mapped.d.mts +2 -3
  205. package/node_modules/typebox/build/type/action/mapped.mjs +2 -1
  206. package/node_modules/typebox/build/type/action/module.d.mts +8 -7
  207. package/node_modules/typebox/build/type/action/module.mjs +7 -6
  208. package/node_modules/typebox/build/type/action/readonly_object.d.mts +0 -5
  209. package/node_modules/typebox/build/type/action/readonly_object.mjs +0 -5
  210. package/node_modules/typebox/build/type/action/with.d.mts +11 -0
  211. package/node_modules/typebox/build/type/action/with.mjs +11 -0
  212. package/node_modules/typebox/build/type/engine/call/distribute_arguments.mjs +1 -1
  213. package/node_modules/typebox/build/type/engine/call/instantiate.d.mts +1 -3
  214. package/node_modules/typebox/build/type/engine/call/instantiate.mjs +3 -2
  215. package/node_modules/typebox/build/type/engine/call/resolve_arguments.mjs +2 -2
  216. package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.d.mts +3 -4
  217. package/node_modules/typebox/build/type/engine/constructor_parameters/instantiate.mjs +2 -1
  218. package/node_modules/typebox/build/type/engine/cyclic/candidates.d.mts +2 -3
  219. package/node_modules/typebox/build/type/engine/cyclic/candidates.mjs +3 -6
  220. package/node_modules/typebox/build/type/engine/cyclic/check.d.mts +6 -9
  221. package/node_modules/typebox/build/type/engine/cyclic/check.mjs +10 -16
  222. package/node_modules/typebox/build/type/engine/cyclic/dependencies.d.mts +1 -4
  223. package/node_modules/typebox/build/type/engine/cyclic/dependencies.mjs +9 -15
  224. package/node_modules/typebox/build/type/engine/cyclic/extends.d.mts +1 -4
  225. package/node_modules/typebox/build/type/engine/cyclic/extends.mjs +8 -14
  226. package/node_modules/typebox/build/type/engine/cyclic/instantiate.d.mts +2 -5
  227. package/node_modules/typebox/build/type/engine/cyclic/instantiate.mjs +3 -2
  228. package/node_modules/typebox/build/type/engine/enum/index.d.mts +0 -1
  229. package/node_modules/typebox/build/type/engine/enum/index.mjs +0 -1
  230. package/node_modules/typebox/build/type/engine/evaluate/broaden.d.mts +1 -2
  231. package/node_modules/typebox/build/type/engine/evaluate/broaden.mjs +2 -6
  232. package/node_modules/typebox/build/type/engine/evaluate/composite.d.mts +10 -6
  233. package/node_modules/typebox/build/type/engine/evaluate/composite.mjs +10 -6
  234. package/node_modules/typebox/build/type/engine/evaluate/distribute.d.mts +2 -1
  235. package/node_modules/typebox/build/type/engine/evaluate/distribute.mjs +3 -3
  236. package/node_modules/typebox/build/type/engine/evaluate/evaluate.d.mts +17 -5
  237. package/node_modules/typebox/build/type/engine/evaluate/evaluate.mjs +34 -8
  238. package/node_modules/typebox/build/type/engine/exclude/operation.d.mts +5 -6
  239. package/node_modules/typebox/build/type/engine/exclude/operation.mjs +11 -12
  240. package/node_modules/typebox/build/type/engine/extract/operation.d.mts +5 -6
  241. package/node_modules/typebox/build/type/engine/extract/operation.mjs +11 -12
  242. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.d.mts +10 -0
  243. package/node_modules/typebox/build/type/engine/immutable/instantiate_add.mjs +14 -0
  244. package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.d.mts +10 -0
  245. package/node_modules/typebox/build/type/engine/immutable/instantiate_remove.mjs +14 -0
  246. package/node_modules/typebox/build/type/engine/index.d.mts +2 -2
  247. package/node_modules/typebox/build/type/engine/index.mjs +2 -2
  248. package/node_modules/typebox/build/type/engine/indexable/from_dependent.d.mts +5 -0
  249. package/node_modules/typebox/build/type/engine/indexable/from_dependent.mjs +8 -0
  250. package/node_modules/typebox/build/type/engine/indexable/from_enum.d.mts +3 -3
  251. package/node_modules/typebox/build/type/engine/indexable/from_enum.mjs +4 -4
  252. package/node_modules/typebox/build/type/engine/indexable/from_template_literal.d.mts +2 -2
  253. package/node_modules/typebox/build/type/engine/indexable/from_template_literal.mjs +3 -3
  254. package/node_modules/typebox/build/type/engine/indexable/from_type.d.mts +3 -1
  255. package/node_modules/typebox/build/type/engine/indexable/from_type.mjs +9 -6
  256. package/node_modules/typebox/build/type/engine/indexed/instantiate.d.mts +2 -1
  257. package/node_modules/typebox/build/type/engine/indexed/instantiate.mjs +5 -2
  258. package/node_modules/typebox/build/type/engine/instantiate.d.mts +44 -31
  259. package/node_modules/typebox/build/type/engine/instantiate.mjs +82 -83
  260. package/node_modules/typebox/build/type/engine/interface/instantiate.d.mts +3 -6
  261. package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.d.mts +2 -2
  262. package/node_modules/typebox/build/type/engine/intrinsics/from_template_literal.mjs +3 -3
  263. package/node_modules/typebox/build/type/engine/keyof/instantiate.d.mts +2 -1
  264. package/node_modules/typebox/build/type/engine/keyof/instantiate.mjs +5 -1
  265. package/node_modules/typebox/build/type/engine/mapped/mapped_operation.d.mts +4 -4
  266. package/node_modules/typebox/build/type/engine/mapped/mapped_operation.mjs +3 -3
  267. package/node_modules/typebox/build/type/engine/mapped/mapped_variants.d.mts +5 -4
  268. package/node_modules/typebox/build/type/engine/mapped/mapped_variants.mjs +10 -5
  269. package/node_modules/typebox/build/type/engine/module/instantiate.d.mts +7 -9
  270. package/node_modules/typebox/build/type/engine/module/instantiate.mjs +17 -15
  271. package/node_modules/typebox/build/type/engine/object/from_dependent.d.mts +5 -0
  272. package/node_modules/typebox/build/type/engine/object/from_dependent.mjs +8 -0
  273. package/node_modules/typebox/build/type/engine/object/from_type.d.mts +3 -1
  274. package/node_modules/typebox/build/type/engine/object/from_type.mjs +8 -5
  275. package/node_modules/typebox/build/type/engine/object/from_union.mjs +2 -2
  276. package/node_modules/typebox/build/type/engine/optional/instantiate_add.d.mts +10 -0
  277. package/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs +14 -0
  278. package/node_modules/typebox/build/type/engine/optional/instantiate_remove.d.mts +10 -0
  279. package/node_modules/typebox/build/type/engine/optional/instantiate_remove.mjs +14 -0
  280. package/node_modules/typebox/build/type/engine/parameters/instantiate.d.mts +3 -4
  281. package/node_modules/typebox/build/type/engine/parameters/instantiate.mjs +2 -1
  282. package/node_modules/typebox/build/type/engine/partial/from_dependent.d.mts +5 -0
  283. package/node_modules/typebox/build/type/engine/partial/from_dependent.mjs +8 -0
  284. package/node_modules/typebox/build/type/engine/partial/from_intersect.d.mts +1 -1
  285. package/node_modules/typebox/build/type/engine/partial/from_intersect.mjs +3 -2
  286. package/node_modules/typebox/build/type/engine/partial/from_object.d.mts +2 -2
  287. package/node_modules/typebox/build/type/engine/partial/from_object.mjs +2 -2
  288. package/node_modules/typebox/build/type/engine/partial/from_type.d.mts +3 -1
  289. package/node_modules/typebox/build/type/engine/partial/from_type.mjs +7 -4
  290. package/node_modules/typebox/build/type/engine/priority/index.d.mts +1 -0
  291. package/node_modules/typebox/build/type/engine/priority/index.mjs +1 -0
  292. package/node_modules/typebox/build/type/engine/priority/priority.d.mts +20 -0
  293. package/node_modules/typebox/build/type/engine/priority/priority.mjs +28 -0
  294. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.d.mts +10 -0
  295. package/node_modules/typebox/build/type/engine/readonly/instantiate_add.mjs +14 -0
  296. package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.d.mts +10 -0
  297. package/node_modules/typebox/build/type/engine/readonly/instantiate_remove.mjs +14 -0
  298. package/node_modules/typebox/build/type/engine/readonly_object/from_array.d.mts +2 -2
  299. package/node_modules/typebox/build/type/engine/readonly_object/from_array.mjs +2 -2
  300. package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.d.mts +5 -0
  301. package/node_modules/typebox/build/type/engine/readonly_object/from_dependent.mjs +8 -0
  302. package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.d.mts +1 -1
  303. package/node_modules/typebox/build/type/engine/readonly_object/from_intersect.mjs +3 -2
  304. package/node_modules/typebox/build/type/engine/readonly_object/from_object.d.mts +2 -2
  305. package/node_modules/typebox/build/type/engine/readonly_object/from_object.mjs +2 -2
  306. package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.d.mts +2 -2
  307. package/node_modules/typebox/build/type/engine/readonly_object/from_tuple.mjs +2 -2
  308. package/node_modules/typebox/build/type/engine/readonly_object/from_type.d.mts +3 -1
  309. package/node_modules/typebox/build/type/engine/readonly_object/from_type.mjs +8 -5
  310. package/node_modules/typebox/build/type/engine/record/from_key_enum.d.mts +2 -2
  311. package/node_modules/typebox/build/type/engine/record/from_key_enum.mjs +2 -2
  312. package/node_modules/typebox/build/type/engine/record/from_key_template_literal.d.mts +2 -2
  313. package/node_modules/typebox/build/type/engine/record/from_key_template_literal.mjs +2 -2
  314. package/node_modules/typebox/build/type/engine/ref/instantiate.d.mts +3 -3
  315. package/node_modules/typebox/build/type/engine/ref/instantiate.mjs +6 -6
  316. package/node_modules/typebox/build/type/engine/required/from_dependent.d.mts +5 -0
  317. package/node_modules/typebox/build/type/engine/required/from_dependent.mjs +8 -0
  318. package/node_modules/typebox/build/type/engine/required/from_intersect.d.mts +1 -1
  319. package/node_modules/typebox/build/type/engine/required/from_intersect.mjs +3 -2
  320. package/node_modules/typebox/build/type/engine/required/from_object.d.mts +2 -2
  321. package/node_modules/typebox/build/type/engine/required/from_object.mjs +2 -2
  322. package/node_modules/typebox/build/type/engine/required/from_type.d.mts +3 -1
  323. package/node_modules/typebox/build/type/engine/required/from_type.mjs +7 -4
  324. package/node_modules/typebox/build/type/engine/template_literal/decode.mjs +3 -3
  325. package/node_modules/typebox/build/type/engine/template_literal/encode.d.mts +2 -2
  326. package/node_modules/typebox/build/type/engine/template_literal/encode.mjs +6 -6
  327. package/node_modules/typebox/build/type/engine/template_literal/is_finite.mjs +1 -1
  328. package/node_modules/typebox/build/type/engine/template_literal/is_pattern.mjs +1 -0
  329. package/node_modules/typebox/build/type/engine/this/expand_this.d.mts +1 -4
  330. package/node_modules/typebox/build/type/engine/this/expand_this.mjs +7 -13
  331. package/node_modules/typebox/build/type/engine/with/instantiate.d.mts +8 -0
  332. package/node_modules/typebox/build/type/engine/{options → with}/instantiate.mjs +5 -5
  333. package/node_modules/typebox/build/type/extends/dependent.d.mts +6 -0
  334. package/node_modules/typebox/build/type/extends/dependent.mjs +6 -0
  335. package/node_modules/typebox/build/type/extends/enum.d.mts +4 -4
  336. package/node_modules/typebox/build/type/extends/enum.mjs +3 -2
  337. package/node_modules/typebox/build/type/extends/extends_left.d.mts +5 -7
  338. package/node_modules/typebox/build/type/extends/extends_left.mjs +24 -27
  339. package/node_modules/typebox/build/type/extends/extends_right.d.mts +7 -5
  340. package/node_modules/typebox/build/type/extends/extends_right.mjs +20 -15
  341. package/node_modules/typebox/build/type/extends/inference.mjs +1 -1
  342. package/node_modules/typebox/build/type/extends/object.d.mts +8 -1
  343. package/node_modules/typebox/build/type/extends/object.mjs +25 -3
  344. package/node_modules/typebox/build/type/extends/parameters.mjs +2 -2
  345. package/node_modules/typebox/build/type/extends/record.d.mts +13 -0
  346. package/node_modules/typebox/build/type/extends/record.mjs +23 -0
  347. package/node_modules/typebox/build/type/extends/template_literal.d.mts +3 -3
  348. package/node_modules/typebox/build/type/extends/template_literal.mjs +3 -3
  349. package/node_modules/typebox/build/type/extends/tuple.d.mts +3 -6
  350. package/node_modules/typebox/build/type/extends/tuple.mjs +6 -5
  351. package/node_modules/typebox/build/type/extends/union.mjs +2 -2
  352. package/node_modules/typebox/build/type/script/mapping.d.mts +84 -99
  353. package/node_modules/typebox/build/type/script/mapping.mjs +81 -85
  354. package/node_modules/typebox/build/type/script/parser.d.mts +40 -40
  355. package/node_modules/typebox/build/type/script/parser.mjs +22 -22
  356. package/node_modules/typebox/build/type/script/script.d.mts +3 -4
  357. package/node_modules/typebox/build/type/script/script.mjs +3 -2
  358. package/node_modules/typebox/build/type/script/token/internal/guard.d.mts +1 -1
  359. package/node_modules/typebox/build/type/script/token/internal/guard.mjs +1 -1
  360. package/node_modules/typebox/build/type/script/token/internal/take.mjs +1 -1
  361. package/node_modules/typebox/build/type/script/token/until.mjs +2 -2
  362. package/node_modules/typebox/build/type/types/_codec.d.mts +12 -12
  363. package/node_modules/typebox/build/type/types/_codec.mjs +0 -1
  364. package/node_modules/typebox/build/type/types/_immutable.d.mts +2 -9
  365. package/node_modules/typebox/build/type/types/_immutable.mjs +2 -10
  366. package/node_modules/typebox/build/type/types/_optional.d.mts +2 -9
  367. package/node_modules/typebox/build/type/types/_optional.mjs +2 -11
  368. package/node_modules/typebox/build/type/types/_readonly.d.mts +2 -9
  369. package/node_modules/typebox/build/type/types/_readonly.mjs +2 -10
  370. package/node_modules/typebox/build/type/types/_refine.d.mts +8 -10
  371. package/node_modules/typebox/build/type/types/_refine.mjs +1 -2
  372. package/node_modules/typebox/build/type/types/call.d.mts +3 -3
  373. package/node_modules/typebox/build/type/types/call.mjs +3 -2
  374. package/node_modules/typebox/build/type/types/deferred.d.mts +1 -0
  375. package/node_modules/typebox/build/type/types/deferred.mjs +1 -1
  376. package/node_modules/typebox/build/type/types/dependent.d.mts +17 -0
  377. package/node_modules/typebox/build/type/types/dependent.mjs +24 -0
  378. package/node_modules/typebox/build/type/types/enum.d.mts +3 -1
  379. package/node_modules/typebox/build/type/types/enum.mjs +5 -0
  380. package/node_modules/typebox/build/type/types/index.d.mts +1 -4
  381. package/node_modules/typebox/build/type/types/index.mjs +1 -4
  382. package/node_modules/typebox/build/type/types/number.d.mts +1 -1
  383. package/node_modules/typebox/build/type/types/number.mjs +1 -1
  384. package/node_modules/typebox/build/type/types/record.d.mts +13 -7
  385. package/node_modules/typebox/build/type/types/record.mjs +15 -9
  386. package/node_modules/typebox/build/type/types/static.d.mts +2 -5
  387. package/node_modules/typebox/build/typebox.d.mts +4 -8
  388. package/node_modules/typebox/build/typebox.mjs +4 -8
  389. package/node_modules/typebox/build/value/clean/clean.mjs +4 -2
  390. package/node_modules/typebox/build/value/clean/from_intersect.mjs +2 -2
  391. package/node_modules/typebox/build/value/clean/from_type.mjs +8 -10
  392. package/node_modules/typebox/build/value/clean/from_union.d.mts +1 -1
  393. package/node_modules/typebox/build/value/clean/from_union.mjs +1 -2
  394. package/node_modules/typebox/build/value/clone/clone.mjs +2 -73
  395. package/node_modules/typebox/build/value/codec/decode.mjs +4 -2
  396. package/node_modules/typebox/build/value/codec/encode.mjs +4 -2
  397. package/node_modules/typebox/build/value/codec/from_array.mjs +1 -4
  398. package/node_modules/typebox/build/value/codec/from_object.mjs +1 -4
  399. package/node_modules/typebox/build/value/codec/from_record.mjs +2 -7
  400. package/node_modules/typebox/build/value/codec/from_tuple.mjs +1 -4
  401. package/node_modules/typebox/build/value/codec/from_union.mjs +2 -3
  402. package/node_modules/typebox/build/value/convert/from_enum.mjs +3 -4
  403. package/node_modules/typebox/build/value/convert/from_template_literal.d.mts +1 -1
  404. package/node_modules/typebox/build/value/convert/from_template_literal.mjs +2 -3
  405. package/node_modules/typebox/build/value/convert/from_type.mjs +19 -21
  406. package/node_modules/typebox/build/value/create/from_enum.mjs +2 -2
  407. package/node_modules/typebox/build/value/create/from_type.mjs +23 -31
  408. package/node_modules/typebox/build/value/default/from_object.mjs +1 -1
  409. package/node_modules/typebox/build/value/default/from_type.mjs +8 -10
  410. package/node_modules/typebox/build/value/index.d.mts +0 -1
  411. package/node_modules/typebox/build/value/index.mjs +0 -1
  412. package/node_modules/typebox/build/value/repair/from_enum.mjs +2 -3
  413. package/node_modules/typebox/build/value/repair/from_type.mjs +24 -22
  414. package/node_modules/typebox/build/value/shared/union_priority_sort.d.mts +6 -2
  415. package/node_modules/typebox/build/value/shared/union_priority_sort.mjs +62 -26
  416. package/node_modules/typebox/build/value/value.d.mts +0 -1
  417. package/node_modules/typebox/build/value/value.mjs +0 -1
  418. package/node_modules/typebox/package.json +25 -25
  419. package/node_modules/typebox/readme.md +97 -80
  420. package/node_modules/undici-types/agent.d.ts +0 -2
  421. package/node_modules/undici-types/client.d.ts +25 -19
  422. package/node_modules/undici-types/dispatcher.d.ts +7 -33
  423. package/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
  424. package/node_modules/undici-types/fetch.d.ts +24 -4
  425. package/node_modules/undici-types/h2c-client.d.ts +6 -6
  426. package/node_modules/undici-types/handlers.d.ts +1 -2
  427. package/node_modules/undici-types/header.d.ts +5 -0
  428. package/node_modules/undici-types/index.d.ts +3 -1
  429. package/node_modules/undici-types/interceptors.d.ts +1 -1
  430. package/node_modules/undici-types/package.json +1 -1
  431. package/node_modules/undici-types/pool.d.ts +0 -2
  432. package/node_modules/undici-types/proxy-agent.d.ts +2 -2
  433. package/node_modules/undici-types/round-robin-pool.d.ts +0 -2
  434. package/node_modules/undici-types/snapshot-agent.d.ts +4 -0
  435. package/node_modules/undici-types/socks5-proxy-agent.d.ts +2 -2
  436. package/node_modules/undici-types/webidl.d.ts +0 -1
  437. package/npm-shrinkwrap.json +49 -41
  438. package/openclaw.plugin.json +12 -0
  439. package/package.json +5 -5
  440. package/node_modules/@cacheable/memory/dist/index.d.ts +0 -310
  441. package/node_modules/@cacheable/memory/dist/index.js +0 -807
  442. package/node_modules/@cacheable/utils/dist/index.d.ts +0 -307
  443. package/node_modules/@cacheable/utils/dist/index.js +0 -630
  444. package/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
  445. package/node_modules/cacheable/dist/index.d.ts +0 -494
  446. package/node_modules/cacheable/dist/index.js +0 -1141
  447. package/node_modules/content-type/HISTORY.md +0 -29
  448. package/node_modules/content-type/index.js +0 -225
  449. package/node_modules/media-typer/HISTORY.md +0 -50
  450. package/node_modules/media-typer/index.js +0 -143
  451. package/node_modules/typebox/build/schema/engine/_guard.d.mts +0 -6
  452. package/node_modules/typebox/build/schema/engine/_guard.mjs +0 -26
  453. package/node_modules/typebox/build/schema/types/_guard.d.mts +0 -10
  454. package/node_modules/typebox/build/schema/types/_guard.mjs +0 -16
  455. package/node_modules/typebox/build/type/action/_optional.d.mts +0 -19
  456. package/node_modules/typebox/build/type/action/_optional.mjs +0 -40
  457. package/node_modules/typebox/build/type/action/_readonly.d.mts +0 -19
  458. package/node_modules/typebox/build/type/action/_readonly.mjs +0 -40
  459. package/node_modules/typebox/build/type/action/awaited.d.mts +0 -15
  460. package/node_modules/typebox/build/type/action/awaited.mjs +0 -15
  461. package/node_modules/typebox/build/type/action/options.d.mts +0 -11
  462. package/node_modules/typebox/build/type/action/options.mjs +0 -11
  463. package/node_modules/typebox/build/type/engine/awaited/instantiate.d.mts +0 -11
  464. package/node_modules/typebox/build/type/engine/awaited/instantiate.mjs +0 -20
  465. package/node_modules/typebox/build/type/engine/enum/enum_to_union.d.mts +0 -14
  466. package/node_modules/typebox/build/type/engine/enum/enum_to_union.mjs +0 -24
  467. package/node_modules/typebox/build/type/engine/options/index.d.mts +0 -1
  468. package/node_modules/typebox/build/type/engine/options/index.mjs +0 -1
  469. package/node_modules/typebox/build/type/engine/options/instantiate.d.mts +0 -8
  470. package/node_modules/typebox/build/type/extends/async_iterator.d.mts +0 -7
  471. package/node_modules/typebox/build/type/extends/async_iterator.mjs +0 -9
  472. package/node_modules/typebox/build/type/extends/iterator.d.mts +0 -7
  473. package/node_modules/typebox/build/type/extends/iterator.mjs +0 -9
  474. package/node_modules/typebox/build/type/extends/promise.d.mts +0 -7
  475. package/node_modules/typebox/build/type/extends/promise.mjs +0 -9
  476. package/node_modules/typebox/build/type/types/async_iterator.d.mts +0 -20
  477. package/node_modules/typebox/build/type/types/async_iterator.mjs +0 -28
  478. package/node_modules/typebox/build/type/types/base.d.mts +0 -50
  479. package/node_modules/typebox/build/type/types/base.mjs +0 -84
  480. package/node_modules/typebox/build/type/types/iterator.d.mts +0 -20
  481. package/node_modules/typebox/build/type/types/iterator.mjs +0 -28
  482. package/node_modules/typebox/build/type/types/promise.d.mts +0 -21
  483. package/node_modules/typebox/build/type/types/promise.mjs +0 -29
  484. package/node_modules/typebox/build/value/clean/from_base.d.mts +0 -2
  485. package/node_modules/typebox/build/value/clean/from_base.mjs +0 -4
  486. package/node_modules/typebox/build/value/convert/from_base.d.mts +0 -2
  487. package/node_modules/typebox/build/value/convert/from_base.mjs +0 -4
  488. package/node_modules/typebox/build/value/create/from_async_iterator.d.mts +0 -2
  489. package/node_modules/typebox/build/value/create/from_async_iterator.mjs +0 -5
  490. package/node_modules/typebox/build/value/create/from_base.d.mts +0 -2
  491. package/node_modules/typebox/build/value/create/from_base.mjs +0 -4
  492. package/node_modules/typebox/build/value/create/from_iterator.d.mts +0 -2
  493. package/node_modules/typebox/build/value/create/from_iterator.mjs +0 -5
  494. package/node_modules/typebox/build/value/create/from_promise.d.mts +0 -2
  495. package/node_modules/typebox/build/value/create/from_promise.mjs +0 -5
  496. package/node_modules/typebox/build/value/default/from_base.d.mts +0 -2
  497. package/node_modules/typebox/build/value/default/from_base.mjs +0 -5
  498. package/node_modules/typebox/build/value/mutate/error.d.mts +0 -3
  499. package/node_modules/typebox/build/value/mutate/error.mjs +0 -6
  500. package/node_modules/typebox/build/value/mutate/from_array.d.mts +0 -2
  501. package/node_modules/typebox/build/value/mutate/from_array.mjs +0 -16
  502. package/node_modules/typebox/build/value/mutate/from_object.d.mts +0 -2
  503. package/node_modules/typebox/build/value/mutate/from_object.mjs +0 -40
  504. package/node_modules/typebox/build/value/mutate/from_unknown.d.mts +0 -2
  505. package/node_modules/typebox/build/value/mutate/from_unknown.mjs +0 -7
  506. package/node_modules/typebox/build/value/mutate/from_value.d.mts +0 -2
  507. package/node_modules/typebox/build/value/mutate/from_value.mjs +0 -12
  508. package/node_modules/typebox/build/value/mutate/index.d.mts +0 -1
  509. package/node_modules/typebox/build/value/mutate/index.mjs +0 -1
  510. package/node_modules/typebox/build/value/mutate/mutate.d.mts +0 -11
  511. package/node_modules/typebox/build/value/mutate/mutate.mjs +0 -41
  512. package/node_modules/typebox/build/value/repair/from_base.d.mts +0 -2
  513. package/node_modules/typebox/build/value/repair/from_base.mjs +0 -8
  514. package/dist/{approval-resolver-e1hAVRRy.js → approval-resolver-DF-lu8k5.js} +1 -1
  515. /package/node_modules/typebox/build/type/engine/{awaited → with}/index.d.mts +0 -0
  516. /package/node_modules/typebox/build/type/engine/{awaited → with}/index.mjs +0 -0
@@ -0,0 +1,1355 @@
1
+ import { Hashery } from "hashery";
2
+ import { Keyv } from "keyv";
3
+ //#region src/shorthand-time.ts
4
+ /**
5
+ * Converts a shorthand time string or number into milliseconds.
6
+ * The shorthand can be a string like '1s', '2m', '3h', '4d', or a number representing milliseconds.
7
+ * If the input is undefined, it returns undefined.
8
+ * If the input is a string that does not match the expected format, it throws an error.
9
+ * @param shorthand - A shorthand time string or number representing milliseconds.
10
+ * @returns The equivalent time in milliseconds or undefined.
11
+ */
12
+ const shorthandToMilliseconds = (shorthand) => {
13
+ let milliseconds;
14
+ if (shorthand === void 0) return;
15
+ if (typeof shorthand === "number") milliseconds = shorthand;
16
+ else {
17
+ if (typeof shorthand !== "string") return;
18
+ shorthand = shorthand.trim();
19
+ if (Number.isNaN(Number(shorthand))) {
20
+ const match = /^([\d.]+)\s*(ms|s|m|h|hr|d)$/i.exec(shorthand);
21
+ if (!match) throw new Error(`Unsupported time format: "${shorthand}". Use 'ms', 's', 'm', 'h', 'hr', or 'd'.`);
22
+ const [, value, unit] = match;
23
+ const numericValue = Number.parseFloat(value);
24
+ switch (unit.toLowerCase()) {
25
+ case "ms":
26
+ milliseconds = numericValue;
27
+ break;
28
+ case "s":
29
+ milliseconds = numericValue * 1e3;
30
+ break;
31
+ case "m":
32
+ milliseconds = numericValue * 1e3 * 60;
33
+ break;
34
+ case "h":
35
+ milliseconds = numericValue * 1e3 * 60 * 60;
36
+ break;
37
+ case "hr":
38
+ milliseconds = numericValue * 1e3 * 60 * 60;
39
+ break;
40
+ case "d":
41
+ milliseconds = numericValue * 1e3 * 60 * 60 * 24;
42
+ break;
43
+ /* v8 ignore next -- @preserve */
44
+ default: milliseconds = Number(shorthand);
45
+ }
46
+ } else milliseconds = Number(shorthand);
47
+ }
48
+ return milliseconds;
49
+ };
50
+ /**
51
+ * Converts a shorthand time string or number into a timestamp.
52
+ * If the shorthand is undefined, it returns the current date's timestamp.
53
+ * If the shorthand is a valid time format, it adds that duration to the current date's timestamp.
54
+ * @param shorthand - A shorthand time string or number representing milliseconds.
55
+ * @param fromDate - An optional Date object to calculate from. Defaults to the current date if not provided.
56
+ * @returns The timestamp in milliseconds since epoch.
57
+ */
58
+ const shorthandToTime = (shorthand, fromDate) => {
59
+ fromDate ??= /* @__PURE__ */ new Date();
60
+ const milliseconds = shorthandToMilliseconds(shorthand);
61
+ if (milliseconds === void 0) return fromDate.getTime();
62
+ return fromDate.getTime() + milliseconds;
63
+ };
64
+ //#endregion
65
+ //#region src/cache-tags.ts
66
+ /**
67
+ * Prefix applied to every store key written by the service so its metadata cannot collide with
68
+ * user-supplied cache keys.
69
+ */
70
+ const RESERVED_PREFIX = "--cacheable--tags--";
71
+ /** Namespace used when none is supplied to the constructor. */
72
+ const DEFAULT_NAMESPACE = "default";
73
+ /**
74
+ * Provides tag-based cache invalidation on top of any {@link Keyv} store. It is store-agnostic and
75
+ * requires no adapter changes.
76
+ *
77
+ * The service uses a lazy invalidation model rather than scanning and deleting keys. Each tag has a
78
+ * monotonically increasing version counter; {@link CacheTags.invalidateTag} simply increments
79
+ * it. When a key is tagged via {@link CacheTags.setKeyTags}, a snapshot of its tags' current
80
+ * versions is stored alongside it. {@link CacheTags.isKeyFresh} compares that snapshot against
81
+ * the live versions — if any tag has been incremented since, the key is considered stale. Stale
82
+ * entries are not deleted explicitly; they are expected to fall out of the cache via their TTL.
83
+ *
84
+ * This keeps invalidation constant-time regardless of how many keys reference a tag, at the cost of
85
+ * one additional `isKeyFresh` read per cache lookup.
86
+ *
87
+ * The service can be disabled via the `enabled` option or property so integrations pay no cost for
88
+ * untagged workloads: while disabled, every method is a no-op — reads return their neutral value
89
+ * and writes are skipped. The service must be explicitly enabled to use tags; it never enables
90
+ * itself, which keeps behavior consistent across distributed instances sharing a store.
91
+ *
92
+ * All metadata is written under a reserved prefix so it cannot collide with user keys:
93
+ * - `--cacheable--tags--:<namespace>:tag:<tag>` → integer version counter (stored without TTL).
94
+ * - `--cacheable--tags--:<namespace>:key:<key>` → the {@link KeyTagEntry} snapshot.
95
+ *
96
+ * Note: the read-version-then-write-snapshot sequence in `setKeyTags` is not atomic across
97
+ * processes. A concurrent `invalidateTag` running between the read and the write can leave a freshly
98
+ * written key referencing a stale version.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const cacheTags = new CacheTags({ store: new Keyv(), namespace: 'app' });
103
+ * await cacheTags.setKeyTags('user:42', ['users', 'org:7'], { ttl: 3600000 });
104
+ * await cacheTags.isKeyFresh('user:42'); // true
105
+ * await cacheTags.invalidateTag('users');
106
+ * await cacheTags.isKeyFresh('user:42'); // false
107
+ * ```
108
+ */
109
+ var CacheTags = class {
110
+ _store;
111
+ _namespace;
112
+ _enabled;
113
+ _onError;
114
+ /**
115
+ * Creates a new tag service.
116
+ * @param {CacheTagsOptions} options - The store, optional namespace, enabled state, and
117
+ * non-blocking error handler to use.
118
+ */
119
+ constructor(options) {
120
+ this._store = options.store;
121
+ this._namespace = options.namespace ?? DEFAULT_NAMESPACE;
122
+ this._enabled = options.enabled ?? true;
123
+ this._onError = options.onError;
124
+ }
125
+ /**
126
+ * The Keyv store backing this service.
127
+ * @returns {Keyv} The store provided to the constructor.
128
+ */
129
+ get store() {
130
+ return this._store;
131
+ }
132
+ /**
133
+ * The namespace isolating this service's tags and keys within the store.
134
+ * @returns {string} The configured namespace, or `"default"` if none was provided.
135
+ */
136
+ get namespace() {
137
+ return this._namespace;
138
+ }
139
+ /**
140
+ * Whether the service is enabled. While disabled, every method is a no-op — read methods
141
+ * return their neutral value and writes are skipped — so integrations pay no extra store
142
+ * reads for untagged workloads. The service must be explicitly enabled to use tags; it never
143
+ * enables itself.
144
+ * @returns {boolean} Whether the service is enabled.
145
+ */
146
+ get enabled() {
147
+ return this._enabled;
148
+ }
149
+ /**
150
+ * Sets whether the service is enabled.
151
+ * @param {boolean} enabled Whether the service is enabled.
152
+ */
153
+ set enabled(enabled) {
154
+ this._enabled = enabled;
155
+ }
156
+ /**
157
+ * Builds the reserved store key under which a tag's version counter is stored.
158
+ * @param tag - The tag name.
159
+ * @returns {string} The namespaced store key for the tag's version.
160
+ */
161
+ tagKey(tag) {
162
+ return `${RESERVED_PREFIX}:${this._namespace}:tag:${tag}`;
163
+ }
164
+ /**
165
+ * Builds the reserved store key under which a cache key's tag snapshot is stored.
166
+ * @param key - The cache key being tagged.
167
+ * @returns {string} The namespaced store key for the key's snapshot.
168
+ */
169
+ keyEntryKey(key) {
170
+ return `${RESERVED_PREFIX}:${this._namespace}:key:${key}`;
171
+ }
172
+ /**
173
+ * Builds the common prefix shared by every key-snapshot entry in this namespace. Used to filter
174
+ * key entries when iterating the store.
175
+ * @returns {string} The namespaced key-entry prefix.
176
+ */
177
+ keyPrefix() {
178
+ return `${RESERVED_PREFIX}:${this._namespace}:key:`;
179
+ }
180
+ /**
181
+ * Reads the current version of a single tag.
182
+ * @param tag - The tag name.
183
+ * @returns {Promise<number>} The tag's version, or `0` if it has never been invalidated.
184
+ */
185
+ async getTagVersion(tag) {
186
+ const version = await this._store.get(this.tagKey(tag));
187
+ return typeof version === "number" ? version : 0;
188
+ }
189
+ /**
190
+ * Reads the current versions of multiple tags in a single batched store read.
191
+ * @param tags - The tag names to look up.
192
+ * @returns {Promise<number[]>} The versions in the same order as `tags`; entries that have never
193
+ * been invalidated resolve to `0`. Returns an empty array when `tags` is empty.
194
+ */
195
+ async getTagVersions(tags) {
196
+ if (tags.length === 0) return [];
197
+ const tagKeys = tags.map((tag) => this.tagKey(tag));
198
+ const raw = await this._store.get(tagKeys);
199
+ return tags.map((_, i) => {
200
+ const value = raw?.[i];
201
+ return typeof value === "number" ? value : 0;
202
+ });
203
+ }
204
+ /**
205
+ * Reports a fire-and-forget failure to the `onError` handler, if one was provided.
206
+ * @param error - The error raised by the non-blocking operation.
207
+ */
208
+ handleNonBlockingError(error) {
209
+ this._onError?.(error);
210
+ }
211
+ /**
212
+ * Reads the version snapshot of each tag and writes the key's tag snapshot to the store.
213
+ * @param key - The cache key to tag.
214
+ * @param tags - The tags to associate with the key.
215
+ * @param ttl - Time-to-live in milliseconds for the snapshot.
216
+ * @returns {Promise<void>} Resolves once the snapshot has been written.
217
+ */
218
+ async writeKeyTags(key, tags, ttl) {
219
+ const uniqueTags = [...new Set(tags)];
220
+ const versions = await this.getTagVersions(uniqueTags);
221
+ const snapshot = {};
222
+ for (let i = 0; i < uniqueTags.length; i++) snapshot[uniqueTags[i]] = versions[i];
223
+ const entry = { tags: snapshot };
224
+ await this._store.set(this.keyEntryKey(key), entry, ttl);
225
+ }
226
+ /**
227
+ * Associates a cache key with a set of tags by recording a snapshot of each tag's current
228
+ * version. Call this whenever you write a fresh value to the cache. Duplicate tags are ignored.
229
+ * No-op while the service is disabled.
230
+ * @param key - The cache key to tag.
231
+ * @param tags - The tags to associate with the key.
232
+ * @param {SetKeyTagsOptions} [options] - Optional settings, such as a `ttl` for the snapshot or
233
+ * `nonBlocking` to fire-and-forget the write.
234
+ * @returns {Promise<void>} Resolves once the snapshot has been written, or immediately when
235
+ * `nonBlocking` is set.
236
+ */
237
+ async setKeyTags(key, tags, options) {
238
+ if (!this._enabled) return;
239
+ const work = this.writeKeyTags(key, tags, options?.ttl);
240
+ if (options?.nonBlocking) {
241
+ work.catch((error) => {
242
+ this.handleNonBlockingError(error);
243
+ });
244
+ return;
245
+ }
246
+ await work;
247
+ }
248
+ /**
249
+ * Removes a key's tag snapshot. After this, {@link CacheTags.isKeyFresh} returns `false`
250
+ * for the key. Use when the cached value itself is deleted. No-op while the service is
251
+ * disabled.
252
+ * @param key - The cache key whose snapshot should be removed.
253
+ * @param {RemoveKeysOptions} [options] - Optional settings, such as `nonBlocking` to
254
+ * fire-and-forget the removal.
255
+ * @returns {Promise<void>} Resolves once the snapshot has been deleted, or immediately when
256
+ * `nonBlocking` is set.
257
+ */
258
+ async removeKey(key, options) {
259
+ await this.removeKeys([key], options);
260
+ }
261
+ /**
262
+ * Removes multiple keys' tag snapshots in a single batched store delete. After this,
263
+ * {@link CacheTags.isKeyFresh} returns `false` for each key. An empty list is a no-op, as is
264
+ * the entire call while the service is disabled.
265
+ * @param keys - The cache keys whose snapshots should be removed.
266
+ * @param {RemoveKeysOptions} [options] - Optional settings, such as `nonBlocking` to
267
+ * fire-and-forget the removal.
268
+ * @returns {Promise<void>} Resolves once the snapshots have been deleted, or immediately when
269
+ * `nonBlocking` is set.
270
+ */
271
+ async removeKeys(keys, options) {
272
+ if (!this._enabled || keys.length === 0) return;
273
+ const entryKeys = keys.map((key) => this.keyEntryKey(key));
274
+ const work = this._store.deleteMany(entryKeys);
275
+ if (options?.nonBlocking) {
276
+ work.catch((error) => {
277
+ this.handleNonBlockingError(error);
278
+ });
279
+ return;
280
+ }
281
+ await work;
282
+ }
283
+ /**
284
+ * Determines whether a key's cached value can still be trusted. A key is fresh only when a
285
+ * snapshot exists for it and every tag in that snapshot still has the version it had at set time.
286
+ * A key with no tags is trivially fresh. Call this before returning a value from your cache.
287
+ * Always returns `true` while the service is disabled.
288
+ * @param key - The cache key to check.
289
+ * @returns {Promise<boolean>} `true` if the key is still fresh; `false` if it is unknown or any of
290
+ * its tags has been invalidated since the snapshot was taken.
291
+ */
292
+ async isKeyFresh(key) {
293
+ if (!this._enabled) return true;
294
+ const entry = await this._store.get(this.keyEntryKey(key));
295
+ if (!entry?.tags) return false;
296
+ const tags = Object.keys(entry.tags);
297
+ const currentVersions = await this.getTagVersions(tags);
298
+ for (let i = 0; i < tags.length; i++) if (currentVersions[i] !== entry.tags[tags[i]]) return false;
299
+ return true;
300
+ }
301
+ /**
302
+ * Determines whether a key's cached value is known to be stale due to tag invalidation. This is
303
+ * the complement of {@link CacheTags.isKeyFresh} for tagged keys, but treats keys without a
304
+ * snapshot as not stale — making it safe to call for every cache lookup, including keys that were
305
+ * never tagged. Always returns `false` while the service is disabled.
306
+ * @param key - The cache key to check.
307
+ * @returns {Promise<boolean>} `true` only when a snapshot exists for the key and at least one of
308
+ * its tags has been invalidated since the snapshot was taken; `false` otherwise (including when
309
+ * the key has no snapshot).
310
+ */
311
+ async isKeyStale(key) {
312
+ if (!this._enabled) return false;
313
+ return (await this.getStaleKeys([key])).length > 0;
314
+ }
315
+ /**
316
+ * Determines which of the given keys are known to be stale due to tag invalidation, using two
317
+ * batched store reads regardless of how many keys are checked: one for the snapshots and one for
318
+ * the union of their tag versions. Keys without a snapshot are not considered stale. Returns an
319
+ * empty array while the service is disabled.
320
+ * @param keys - The cache keys to check.
321
+ * @returns {Promise<string[]>} The subset of `keys` whose snapshot references at least one tag
322
+ * that has been invalidated since the snapshot was taken.
323
+ */
324
+ async getStaleKeys(keys) {
325
+ if (!this._enabled || keys.length === 0) return [];
326
+ const entryKeys = keys.map((key) => this.keyEntryKey(key));
327
+ const entries = await this._store.get(entryKeys);
328
+ const tagSet = /* @__PURE__ */ new Set();
329
+ for (const entry of entries) if (entry?.tags) for (const tag of Object.keys(entry.tags)) tagSet.add(tag);
330
+ const tags = [...tagSet];
331
+ const versions = await this.getTagVersions(tags);
332
+ const currentVersions = /* @__PURE__ */ new Map();
333
+ for (let i = 0; i < tags.length; i++) currentVersions.set(tags[i], versions[i]);
334
+ const staleKeys = [];
335
+ for (const [i, entry] of entries.entries()) {
336
+ if (!entry?.tags) continue;
337
+ for (const [tag, version] of Object.entries(entry.tags)) if (currentVersions.get(tag) !== version) {
338
+ staleKeys.push(keys[i]);
339
+ break;
340
+ }
341
+ }
342
+ return staleKeys;
343
+ }
344
+ /**
345
+ * Returns the tags currently associated with a key. Returns `undefined` while the service is
346
+ * disabled.
347
+ * @param key - The cache key to look up.
348
+ * @returns {Promise<string[] | undefined>} The tag names from the key's snapshot, or `undefined`
349
+ * if the key has no snapshot.
350
+ */
351
+ async getTags(key) {
352
+ if (!this._enabled) return;
353
+ const entry = await this._store.get(this.keyEntryKey(key));
354
+ if (!entry?.tags) return;
355
+ return Object.keys(entry.tags);
356
+ }
357
+ /**
358
+ * Returns all cache keys whose snapshot references the given tag. This scans every key entry in
359
+ * the namespace via the Keyv iterator, making it an `O(N)` operation intended for debugging and
360
+ * tests rather than hot paths. Returns an empty array if the underlying store exposes no iterator
361
+ * or while the service is disabled.
362
+ * @param tag - The tag to search for.
363
+ * @returns {Promise<string[]>} The cache keys (with the reserved prefix stripped) referencing the tag.
364
+ */
365
+ async getKeysByTag(tag) {
366
+ const result = [];
367
+ if (!this._enabled) return result;
368
+ const prefix = this.keyPrefix();
369
+ const iterator = this._store.iterator?.(this._store.namespace);
370
+ if (!iterator) return result;
371
+ for await (const [storedKey, value] of iterator) {
372
+ if (typeof storedKey !== "string" || !storedKey.startsWith(prefix)) continue;
373
+ const entry = value;
374
+ if (entry?.tags && Object.hasOwn(entry.tags, tag)) result.push(storedKey.slice(prefix.length));
375
+ }
376
+ return result;
377
+ }
378
+ /**
379
+ * Invalidates a single tag by incrementing its version counter. Every key whose snapshot
380
+ * references this tag becomes stale immediately. Runs in constant time regardless of how many
381
+ * keys reference the tag. No-op while the service is disabled.
382
+ * @param tag - The tag to invalidate.
383
+ * @returns {Promise<string[]>} A single-element array containing the invalidated tag, or an
384
+ * empty array while the service is disabled.
385
+ */
386
+ async invalidateTag(tag) {
387
+ if (!this._enabled) return [];
388
+ const current = await this.getTagVersion(tag);
389
+ await this._store.set(this.tagKey(tag), current + 1);
390
+ return [tag];
391
+ }
392
+ /**
393
+ * Invalidates multiple tags by incrementing each of their version counters in a single batched
394
+ * store write. Duplicate tags are bumped once. An empty list is a no-op, as is the entire call
395
+ * while the service is disabled.
396
+ * @param tags - The tags to invalidate.
397
+ * @returns {Promise<string[]>} The `tags` argument as provided (including any duplicates), or
398
+ * an empty array while the service is disabled.
399
+ */
400
+ async invalidateTags(tags) {
401
+ if (!this._enabled) return [];
402
+ const uniqueTags = [...new Set(tags)];
403
+ if (uniqueTags.length === 0) return tags;
404
+ const versions = await this.getTagVersions(uniqueTags);
405
+ const kvPairs = [];
406
+ for (let i = 0; i < uniqueTags.length; i++) kvPairs.push({
407
+ key: this.tagKey(uniqueTags[i]),
408
+ value: versions[i] + 1
409
+ });
410
+ await this._store.setMany(kvPairs);
411
+ return tags;
412
+ }
413
+ };
414
+ //#endregion
415
+ //#region src/coalesce-async.ts
416
+ const callbacks = /* @__PURE__ */ new Map();
417
+ function hasKey(key) {
418
+ return callbacks.has(key);
419
+ }
420
+ function addKey(key) {
421
+ callbacks.set(key, []);
422
+ }
423
+ function removeKey(key) {
424
+ callbacks.delete(key);
425
+ }
426
+ function addCallbackToKey(key, callback) {
427
+ const stash = getCallbacksByKey(key);
428
+ stash.push(callback);
429
+ callbacks.set(key, stash);
430
+ }
431
+ function getCallbacksByKey(key) {
432
+ /* v8 ignore next -- @preserve */
433
+ return callbacks.get(key) ?? [];
434
+ }
435
+ async function enqueue(key) {
436
+ return new Promise((resolve, reject) => {
437
+ addCallbackToKey(key, {
438
+ resolve,
439
+ reject
440
+ });
441
+ });
442
+ }
443
+ function dequeue(key) {
444
+ const stash = getCallbacksByKey(key);
445
+ removeKey(key);
446
+ return stash;
447
+ }
448
+ function coalesce(options) {
449
+ const { key, error, result } = options;
450
+ for (const callback of dequeue(key))
451
+ /* c8 ignore next 1 */
452
+ if (error)
453
+ /* c8 ignore next 3 */
454
+ callback.reject(error);
455
+ else callback.resolve(result);
456
+ }
457
+ /**
458
+ * Enqueue a promise for the group identified by `key`.
459
+ *
460
+ * All requests received for the same key while a request for that key
461
+ * is already being executed will wait. Once the running request settles
462
+ * then all the waiting requests in the group will settle, too.
463
+ * This minimizes how many times the function itself runs at the same time.
464
+ * This function resolves or rejects according to the given function argument.
465
+ *
466
+ * @url https://github.com/douglascayers/promise-coalesce
467
+ */
468
+ async function coalesceAsync(key, fnc) {
469
+ if (!hasKey(key)) {
470
+ addKey(key);
471
+ try {
472
+ const result = await Promise.resolve(fnc());
473
+ coalesce({
474
+ key,
475
+ result
476
+ });
477
+ return result;
478
+ } catch (error) {
479
+ /* c8 ignore next 5 */
480
+ coalesce({
481
+ key,
482
+ error
483
+ });
484
+ throw error;
485
+ }
486
+ }
487
+ return enqueue(key);
488
+ }
489
+ //#endregion
490
+ //#region src/hash.ts
491
+ let HashAlgorithm = /* @__PURE__ */ function(HashAlgorithm) {
492
+ HashAlgorithm["SHA256"] = "SHA-256";
493
+ HashAlgorithm["SHA384"] = "SHA-384";
494
+ HashAlgorithm["SHA512"] = "SHA-512";
495
+ HashAlgorithm["DJB2"] = "djb2";
496
+ HashAlgorithm["FNV1"] = "fnv1";
497
+ HashAlgorithm["MURMER"] = "murmer";
498
+ HashAlgorithm["CRC32"] = "crc32";
499
+ return HashAlgorithm;
500
+ }({});
501
+ /**
502
+ * Hashes an object asynchronously using the specified cryptographic algorithm.
503
+ * This method should be used for cryptographic algorithms (SHA-256, SHA-384, SHA-512).
504
+ * For non-cryptographic algorithms, use hashSync() for better performance.
505
+ * @param object The object to hash
506
+ * @param options The hash options to use
507
+ * @returns {Promise<string>} The hash of the object
508
+ */
509
+ async function hash(object, options = {
510
+ algorithm: "SHA-256",
511
+ serialize: JSON.stringify
512
+ }) {
513
+ const algorithm = options?.algorithm ?? "SHA-256";
514
+ const objectString = (options?.serialize ?? JSON.stringify)(object);
515
+ return new Hashery().toHash(objectString, { algorithm });
516
+ }
517
+ /**
518
+ * Hashes an object synchronously using the specified non-cryptographic algorithm.
519
+ * This method should be used for non-cryptographic algorithms (DJB2, FNV1, MURMER, CRC32).
520
+ * For cryptographic algorithms, use hash() instead.
521
+ * @param object The object to hash
522
+ * @param options The hash options to use
523
+ * @returns {string} The hash of the object
524
+ */
525
+ function hashSync(object, options = {
526
+ algorithm: "djb2",
527
+ serialize: JSON.stringify
528
+ }) {
529
+ const algorithm = options?.algorithm ?? "djb2";
530
+ const objectString = (options?.serialize ?? JSON.stringify)(object);
531
+ return new Hashery().toHashSync(objectString, { algorithm });
532
+ }
533
+ /**
534
+ * Hashes an object asynchronously and converts it to a number within a specified range.
535
+ * This method should be used for cryptographic algorithms (SHA-256, SHA-384, SHA-512).
536
+ * For non-cryptographic algorithms, use hashToNumberSync() for better performance.
537
+ * @param object The object to hash
538
+ * @param options The hash options to use including min/max range
539
+ * @returns {Promise<number>} A number within the specified range
540
+ */
541
+ async function hashToNumber(object, options = {
542
+ min: 0,
543
+ max: 10,
544
+ algorithm: "SHA-256",
545
+ serialize: JSON.stringify
546
+ }) {
547
+ const min = options?.min ?? 0;
548
+ const max = options?.max ?? 10;
549
+ const algorithm = options?.algorithm ?? "SHA-256";
550
+ const serialize = options?.serialize ?? JSON.stringify;
551
+ const hashLength = options?.hashLength ?? 16;
552
+ if (min >= max) throw new Error(`Invalid range: min (${min}) must be less than max (${max})`);
553
+ const objectString = serialize(object);
554
+ return new Hashery().toNumber(objectString, {
555
+ algorithm,
556
+ min,
557
+ max,
558
+ hashLength
559
+ });
560
+ }
561
+ /**
562
+ * Hashes an object synchronously and converts it to a number within a specified range.
563
+ * This method should be used for non-cryptographic algorithms (DJB2, FNV1, MURMER, CRC32).
564
+ * For cryptographic algorithms, use hashToNumber() instead.
565
+ * @param object The object to hash
566
+ * @param options The hash options to use including min/max range
567
+ * @returns {number} A number within the specified range
568
+ */
569
+ function hashToNumberSync(object, options = {
570
+ min: 0,
571
+ max: 10,
572
+ algorithm: "djb2",
573
+ serialize: JSON.stringify
574
+ }) {
575
+ const min = options?.min ?? 0;
576
+ const max = options?.max ?? 10;
577
+ const algorithm = options?.algorithm ?? "djb2";
578
+ const serialize = options?.serialize ?? JSON.stringify;
579
+ const hashLength = options?.hashLength ?? 16;
580
+ if (min >= max) throw new Error(`Invalid range: min (${min}) must be less than max (${max})`);
581
+ const objectString = serialize(object);
582
+ return new Hashery().toNumberSync(objectString, {
583
+ algorithm,
584
+ min,
585
+ max,
586
+ hashLength
587
+ });
588
+ }
589
+ //#endregion
590
+ //#region src/is-keyv-instance.ts
591
+ function isKeyvInstance(keyv) {
592
+ if (keyv === null || keyv === void 0) return false;
593
+ if (keyv instanceof Keyv) return true;
594
+ return [
595
+ "generateIterator",
596
+ "get",
597
+ "getMany",
598
+ "set",
599
+ "setMany",
600
+ "delete",
601
+ "deleteMany",
602
+ "has",
603
+ "hasMany",
604
+ "clear",
605
+ "disconnect",
606
+ "serialize",
607
+ "deserialize"
608
+ ].every((method) => typeof keyv[method] === "function");
609
+ }
610
+ //#endregion
611
+ //#region src/is-object.ts
612
+ function isObject(value) {
613
+ return value !== null && typeof value === "object" && !Array.isArray(value);
614
+ }
615
+ //#endregion
616
+ //#region src/less-than.ts
617
+ function lessThan(number1, number2) {
618
+ return typeof number1 === "number" && typeof number2 === "number" ? number1 < number2 : false;
619
+ }
620
+ //#endregion
621
+ //#region src/memoize.ts
622
+ function wrapSync(function_, options) {
623
+ const { ttl, keyPrefix, cache, serialize } = options;
624
+ return (...arguments_) => {
625
+ let cacheKey = createWrapKey(function_, arguments_, {
626
+ keyPrefix,
627
+ serialize
628
+ });
629
+ if (options.createKey) cacheKey = options.createKey(function_, arguments_, options);
630
+ let value = cache.get(cacheKey);
631
+ if (value === void 0) try {
632
+ value = function_(...arguments_);
633
+ cache.set(cacheKey, value, ttl);
634
+ } catch (error) {
635
+ cache.emit("error", error);
636
+ if (options.cacheErrors) cache.set(cacheKey, error, ttl);
637
+ }
638
+ return value;
639
+ };
640
+ }
641
+ async function getOrSet(key, function_, options) {
642
+ const keyString = typeof key === "function" ? key(options) : key;
643
+ let value;
644
+ try {
645
+ value = await options.cache.get(keyString);
646
+ } catch (error) {
647
+ options.cache.emit("error", error);
648
+ if (options.throwErrors === true || options.throwErrors === "store") throw error;
649
+ }
650
+ if (value === void 0) value = await coalesceAsync(`${options.cacheId ?? "default"}::${keyString}`, async () => {
651
+ let result;
652
+ try {
653
+ try {
654
+ result = await function_();
655
+ } catch (error) {
656
+ throw new ErrorEnvelope(error, "function");
657
+ }
658
+ try {
659
+ await options.cache.set(keyString, result, options.ttl);
660
+ } catch (error) {
661
+ throw new ErrorEnvelope(error, "store");
662
+ }
663
+ return result;
664
+ } catch (caught) {
665
+ const errorType = caught instanceof ErrorEnvelope ? caught.context : void 0;
666
+ const error = caught instanceof ErrorEnvelope ? caught.error : caught;
667
+ options.cache.emit("error", error);
668
+ if (options.cacheErrors && errorType === "function") try {
669
+ await options.cache.set(keyString, error, options.ttl);
670
+ } catch (storeError) {
671
+ options.cache.emit("error", storeError);
672
+ }
673
+ if (options.throwErrors === true || options.throwErrors === errorType) throw error;
674
+ }
675
+ return result;
676
+ });
677
+ return value;
678
+ }
679
+ /**
680
+ * Synchronous counterpart to {@link getOrSet}. Reads `key` from the cache and, on a miss, computes
681
+ * the value with `function_`, stores it, and returns it.
682
+ *
683
+ * Unlike {@link getOrSet} there is no request coalescing: synchronous code runs to completion
684
+ * without interleaving, so concurrent callers cannot stampede the setter the way they can with an
685
+ * async cache.
686
+ *
687
+ * Error handling mirrors {@link getOrSet}: errors are emitted on the cache's `error` event, can be
688
+ * cached when `cacheErrors` is set, and can be rethrown selectively via `throwErrors` (`true` for
689
+ * any error, `"function"` for setter errors, `"store"` for cache read/write errors).
690
+ *
691
+ * @param key - The cache key, or a function that derives it from the resolved options.
692
+ * @param function_ - The setter invoked on a cache miss to compute the value.
693
+ * @param options - The {@link GetOrSetSyncOptions} including the target synchronous cache.
694
+ * @returns The cached or freshly computed value, or `undefined`.
695
+ */
696
+ function getOrSetSync(key, function_, options) {
697
+ const keyString = typeof key === "function" ? key(options) : key;
698
+ let value;
699
+ try {
700
+ value = options.cache.get(keyString);
701
+ } catch (error) {
702
+ options.cache.emit("error", error);
703
+ if (options.throwErrors === true || options.throwErrors === "store") throw error;
704
+ }
705
+ if (value === void 0) try {
706
+ try {
707
+ value = function_();
708
+ } catch (error) {
709
+ throw new ErrorEnvelope(error, "function");
710
+ }
711
+ try {
712
+ options.cache.set(keyString, value, options.ttl);
713
+ } catch (error) {
714
+ throw new ErrorEnvelope(error, "store");
715
+ }
716
+ } catch (caught) {
717
+ const errorType = caught instanceof ErrorEnvelope ? caught.context : void 0;
718
+ const error = caught instanceof ErrorEnvelope ? caught.error : caught;
719
+ options.cache.emit("error", error);
720
+ if (options.cacheErrors && errorType === "function") try {
721
+ options.cache.set(keyString, error, options.ttl);
722
+ } catch (storeError) {
723
+ options.cache.emit("error", storeError);
724
+ }
725
+ if (options.throwErrors === true || options.throwErrors === errorType) throw error;
726
+ }
727
+ return value;
728
+ }
729
+ function wrap(function_, options) {
730
+ const { keyPrefix, serialize } = options;
731
+ return async (...arguments_) => {
732
+ let cacheKey = createWrapKey(function_, arguments_, {
733
+ keyPrefix,
734
+ serialize
735
+ });
736
+ if (options.createKey) cacheKey = options.createKey(function_, arguments_, options);
737
+ return getOrSet(cacheKey, async () => function_(...arguments_), options);
738
+ };
739
+ }
740
+ function createWrapKey(function_, arguments_, options) {
741
+ const { keyPrefix, serialize } = options || {};
742
+ if (!keyPrefix) return `${function_.name}::${hashSync(arguments_, { serialize })}`;
743
+ return `${keyPrefix}::${function_.name}::${hashSync(arguments_, { serialize })}`;
744
+ }
745
+ var ErrorEnvelope = class {
746
+ error;
747
+ context;
748
+ constructor(error, context) {
749
+ this.error = error;
750
+ this.context = context;
751
+ }
752
+ };
753
+ //#endregion
754
+ //#region src/run-if-fn.ts
755
+ function runIfFn(valueOrFunction, ...arguments_) {
756
+ return typeof valueOrFunction === "function" ? valueOrFunction(...arguments_) : valueOrFunction;
757
+ }
758
+ //#endregion
759
+ //#region src/sleep.ts
760
+ const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
761
+ //#endregion
762
+ //#region src/stats.ts
763
+ /**
764
+ * Event map for `@cacheable/node-cache` instances. node-cache emits with
765
+ * positional arguments (e.g. `set(key, value)`), and emits each lifecycle
766
+ * event exactly once, so the counts map cleanly. `flush` clears the cache data
767
+ * and `flush_stats` resets the stats counters, mirroring node-cache's
768
+ * `flushAll()` / `flushStats()` lifecycle.
769
+ *
770
+ * Presets for `cacheable` and `cache-manager` are intentionally not provided:
771
+ * their event streams emit per-store probes (and, for cache-manager, do not
772
+ * emit an event on a normal miss), so a simple map cannot faithfully reproduce
773
+ * their imperative stats. Wire those up with a custom map or imperative calls.
774
+ */
775
+ const nodeCacheStatsEventMap = {
776
+ set: (stats, key) => {
777
+ stats.increment("sets");
778
+ if (typeof key === "string" || typeof key === "number") stats.recordKey(String(key), "sets");
779
+ },
780
+ del: (stats, key) => {
781
+ stats.increment("deletes");
782
+ if (typeof key === "string" || typeof key === "number") stats.recordKey(String(key), "deletes");
783
+ },
784
+ flush: "clears",
785
+ flush_stats: (stats) => {
786
+ stats.reset();
787
+ }
788
+ };
789
+ var Stats = class {
790
+ _counters = {
791
+ hits: 0,
792
+ misses: 0,
793
+ gets: 0,
794
+ sets: 0,
795
+ deletes: 0,
796
+ clears: 0,
797
+ count: 0
798
+ };
799
+ _vsize = 0;
800
+ _ksize = 0;
801
+ _enabled = false;
802
+ _lastUpdated;
803
+ _lastReset;
804
+ _subscriptions = [];
805
+ /** Backing store for the public {@link trackedKeys} read-only view. */
806
+ _trackedKeys = /* @__PURE__ */ new Map();
807
+ _trackKeys = false;
808
+ _maxTrackedKeys;
809
+ constructor(options) {
810
+ if (options?.enabled) this._enabled = options.enabled;
811
+ if (options?.trackKeys) this._trackKeys = options.trackKeys;
812
+ if (options?.maxTrackedKeys !== void 0) this._maxTrackedKeys = options.maxTrackedKeys;
813
+ if (options?.emitter && options?.eventMap) this.subscribe(options.emitter, options.eventMap);
814
+ }
815
+ /**
816
+ * @returns {boolean} - Whether the stats are enabled
817
+ */
818
+ get enabled() {
819
+ return this._enabled;
820
+ }
821
+ /**
822
+ * @param {boolean} enabled - Whether to enable the stats
823
+ */
824
+ set enabled(enabled) {
825
+ this._enabled = enabled;
826
+ }
827
+ /**
828
+ * @returns {boolean} - Whether per-key statistics are tracked
829
+ */
830
+ get trackKeys() {
831
+ return this._trackKeys;
832
+ }
833
+ /**
834
+ * @param {boolean} trackKeys - Whether to track per-key statistics
835
+ */
836
+ set trackKeys(trackKeys) {
837
+ this._trackKeys = trackKeys;
838
+ }
839
+ /**
840
+ * @returns {number | undefined} - The cap on unique keys tracked, or
841
+ * `undefined` when unbounded
842
+ */
843
+ get maxTrackedKeys() {
844
+ return this._maxTrackedKeys;
845
+ }
846
+ /**
847
+ * @param {number | undefined} maxTrackedKeys - The cap on unique keys
848
+ * tracked. Set `undefined` for unbounded.
849
+ */
850
+ set maxTrackedKeys(maxTrackedKeys) {
851
+ this._maxTrackedKeys = maxTrackedKeys;
852
+ }
853
+ /**
854
+ * Per-key statistics, keyed by cache key, holding each key's raw
855
+ * `hits`/`misses`/`gets`/`sets`/`deletes` counters. Populated by
856
+ * {@link recordKey} when {@link trackKeys} is enabled; read `trackedKeys.size`
857
+ * for the number of unique keys currently tracked. The returned map is a
858
+ * read-only view — mutate per-key stats via {@link recordKey} /
859
+ * {@link clearKeys} / {@link reset}.
860
+ * @returns {ReadonlyMap<string, Readonly<KeyCounters>>}
861
+ * @readonly
862
+ */
863
+ get trackedKeys() {
864
+ return this._trackedKeys;
865
+ }
866
+ /**
867
+ * @returns {number} - The number of hits
868
+ * @readonly
869
+ */
870
+ get hits() {
871
+ return this._counters.hits;
872
+ }
873
+ /**
874
+ * @returns {number} - The number of misses
875
+ * @readonly
876
+ */
877
+ get misses() {
878
+ return this._counters.misses;
879
+ }
880
+ /**
881
+ * @returns {number} - The number of gets
882
+ * @readonly
883
+ */
884
+ get gets() {
885
+ return this._counters.gets;
886
+ }
887
+ /**
888
+ * @returns {number} - The number of sets
889
+ * @readonly
890
+ */
891
+ get sets() {
892
+ return this._counters.sets;
893
+ }
894
+ /**
895
+ * @returns {number} - The number of deletes
896
+ * @readonly
897
+ */
898
+ get deletes() {
899
+ return this._counters.deletes;
900
+ }
901
+ /**
902
+ * @returns {number} - The number of clears
903
+ * @readonly
904
+ */
905
+ get clears() {
906
+ return this._counters.clears;
907
+ }
908
+ /**
909
+ * @returns {number} - The vsize (value size) of the cache instance
910
+ * @readonly
911
+ */
912
+ get vsize() {
913
+ return this._vsize;
914
+ }
915
+ /**
916
+ * @returns {number} - The ksize (key size) of the cache instance
917
+ * @readonly
918
+ */
919
+ get ksize() {
920
+ return this._ksize;
921
+ }
922
+ /**
923
+ * @returns {number} - The count of the cache instance
924
+ * @readonly
925
+ */
926
+ get count() {
927
+ return this._counters.count;
928
+ }
929
+ /**
930
+ * The ratio of hits to total lookups (hits + misses). Returns `0` when there
931
+ * have been no lookups.
932
+ * @returns {number} - A value between 0 and 1
933
+ * @readonly
934
+ */
935
+ get hitRate() {
936
+ const total = this._counters.hits + this._counters.misses;
937
+ return total === 0 ? 0 : this._counters.hits / total;
938
+ }
939
+ /**
940
+ * The ratio of misses to total lookups (hits + misses). Returns `0` when
941
+ * there have been no lookups.
942
+ * @returns {number} - A value between 0 and 1
943
+ * @readonly
944
+ */
945
+ get missRate() {
946
+ const total = this._counters.hits + this._counters.misses;
947
+ return total === 0 ? 0 : this._counters.misses / total;
948
+ }
949
+ /**
950
+ * The timestamp (ms since epoch) of the last mutation while enabled, or
951
+ * `undefined` if there have been none since the last reset.
952
+ * @returns {number | undefined}
953
+ * @readonly
954
+ */
955
+ get lastUpdated() {
956
+ return this._lastUpdated;
957
+ }
958
+ /**
959
+ * The timestamp (ms since epoch) of the last {@link reset}/{@link clear}, or
960
+ * `undefined` if it has never been reset.
961
+ * @returns {number | undefined}
962
+ * @readonly
963
+ */
964
+ get lastReset() {
965
+ return this._lastReset;
966
+ }
967
+ /**
968
+ * Increment a counter field by `amount` (default `1`). No-op when disabled.
969
+ * @param {StatField} field - The counter to increment
970
+ * @param {number} amount - The amount to add (default 1)
971
+ */
972
+ increment(field, amount = 1) {
973
+ if (!this._enabled) return;
974
+ this._counters[field] += amount;
975
+ this.touch();
976
+ }
977
+ /**
978
+ * Decrement a counter field by `amount` (default `1`). No-op when disabled.
979
+ * @param {StatField} field - The counter to decrement
980
+ * @param {number} amount - The amount to subtract (default 1)
981
+ */
982
+ decrement(field, amount = 1) {
983
+ if (!this._enabled) return;
984
+ this._counters[field] -= amount;
985
+ this.touch();
986
+ }
987
+ incrementHits(amount = 1) {
988
+ this.increment("hits", amount);
989
+ }
990
+ incrementMisses(amount = 1) {
991
+ this.increment("misses", amount);
992
+ }
993
+ incrementGets(amount = 1) {
994
+ this.increment("gets", amount);
995
+ }
996
+ incrementSets(amount = 1) {
997
+ this.increment("sets", amount);
998
+ }
999
+ incrementDeletes(amount = 1) {
1000
+ this.increment("deletes", amount);
1001
+ }
1002
+ incrementClears(amount = 1) {
1003
+ this.increment("clears", amount);
1004
+ }
1005
+ incrementVSize(value) {
1006
+ if (!this._enabled) return;
1007
+ this._vsize += this.roughSizeOfObject(value);
1008
+ this.touch();
1009
+ }
1010
+ decreaseVSize(value) {
1011
+ if (!this._enabled) return;
1012
+ this._vsize = Math.max(0, this._vsize - this.roughSizeOfObject(value));
1013
+ this.touch();
1014
+ }
1015
+ incrementKSize(key) {
1016
+ if (!this._enabled) return;
1017
+ this._ksize += this.roughSizeOfString(key);
1018
+ this.touch();
1019
+ }
1020
+ decreaseKSize(key) {
1021
+ if (!this._enabled) return;
1022
+ this._ksize = Math.max(0, this._ksize - this.roughSizeOfString(key));
1023
+ this.touch();
1024
+ }
1025
+ incrementCount(amount = 1) {
1026
+ this.increment("count", amount);
1027
+ }
1028
+ decreaseCount(amount = 1) {
1029
+ if (!this._enabled) return;
1030
+ this._counters.count = Math.max(0, this._counters.count - amount);
1031
+ this.touch();
1032
+ }
1033
+ setCount(count) {
1034
+ if (!this._enabled) return;
1035
+ this._counters.count = count;
1036
+ this.touch();
1037
+ }
1038
+ roughSizeOfString(value) {
1039
+ return value.length * 2;
1040
+ }
1041
+ roughSizeOfObject(object) {
1042
+ const objectList = [];
1043
+ const stack = [object];
1044
+ let bytes = 0;
1045
+ while (stack.length > 0) {
1046
+ const value = stack.pop();
1047
+ if (typeof value === "boolean") bytes += 4;
1048
+ else if (typeof value === "string") bytes += value.length * 2;
1049
+ else if (typeof value === "number") bytes += 8;
1050
+ else {
1051
+ if (value === null || value === void 0) {
1052
+ bytes += 4;
1053
+ continue;
1054
+ }
1055
+ if (objectList.includes(value)) continue;
1056
+ objectList.push(value);
1057
+ for (const key in value) {
1058
+ bytes += key.length * 2;
1059
+ stack.push(value[key]);
1060
+ }
1061
+ }
1062
+ }
1063
+ return bytes;
1064
+ }
1065
+ /**
1066
+ * Enable stat tracking. Equivalent to setting {@link enabled} to `true`.
1067
+ */
1068
+ enable() {
1069
+ this._enabled = true;
1070
+ }
1071
+ /**
1072
+ * Disable stat tracking. Equivalent to setting {@link enabled} to `false`.
1073
+ */
1074
+ disable() {
1075
+ this._enabled = false;
1076
+ }
1077
+ /**
1078
+ * Reset all counters to zero and record the reset timestamp. Alias of
1079
+ * {@link reset}.
1080
+ */
1081
+ clear() {
1082
+ this.reset();
1083
+ }
1084
+ reset() {
1085
+ this._counters = {
1086
+ hits: 0,
1087
+ misses: 0,
1088
+ gets: 0,
1089
+ sets: 0,
1090
+ deletes: 0,
1091
+ clears: 0,
1092
+ count: 0
1093
+ };
1094
+ this._vsize = 0;
1095
+ this._ksize = 0;
1096
+ this._trackedKeys.clear();
1097
+ this._lastReset = Date.now();
1098
+ this._lastUpdated = void 0;
1099
+ }
1100
+ resetStoreValues() {
1101
+ this._vsize = 0;
1102
+ this._ksize = 0;
1103
+ this._counters.count = 0;
1104
+ }
1105
+ /**
1106
+ * @returns {StatsSnapshot} - A plain-object snapshot of the current stats,
1107
+ * including computed `hitRate`/`missRate` and timestamps.
1108
+ */
1109
+ toJSON() {
1110
+ return {
1111
+ enabled: this._enabled,
1112
+ hits: this._counters.hits,
1113
+ misses: this._counters.misses,
1114
+ gets: this._counters.gets,
1115
+ sets: this._counters.sets,
1116
+ deletes: this._counters.deletes,
1117
+ clears: this._counters.clears,
1118
+ vsize: this._vsize,
1119
+ ksize: this._ksize,
1120
+ count: this._counters.count,
1121
+ hitRate: this.hitRate,
1122
+ missRate: this.missRate,
1123
+ trackedKeys: this._trackedKeys.size,
1124
+ lastUpdated: this._lastUpdated,
1125
+ lastReset: this._lastReset
1126
+ };
1127
+ }
1128
+ /**
1129
+ * @returns {StatsSnapshot} - A plain-object snapshot of the current stats.
1130
+ * Alias of {@link toJSON}.
1131
+ */
1132
+ snapshot() {
1133
+ return this.toJSON();
1134
+ }
1135
+ /**
1136
+ * Record an operation against a specific key for per-key statistics. No-op
1137
+ * unless both {@link enabled} and {@link trackKeys} are `true`.
1138
+ * @param {string} key - The cache key the operation touched
1139
+ * @param {KeyStatField} field - The per-key counter to increment
1140
+ * @param {number} amount - The amount to add (default 1)
1141
+ */
1142
+ recordKey(key, field, amount = 1) {
1143
+ if (!this._enabled || !this._trackKeys) return;
1144
+ let counters = this._trackedKeys.get(key);
1145
+ if (!counters) {
1146
+ counters = {
1147
+ hits: 0,
1148
+ misses: 0,
1149
+ gets: 0,
1150
+ sets: 0,
1151
+ deletes: 0
1152
+ };
1153
+ this._trackedKeys.set(key, counters);
1154
+ this.pruneTrackedKeys(key);
1155
+ }
1156
+ counters[field] += amount;
1157
+ this.touch();
1158
+ }
1159
+ /**
1160
+ * The most-used keys, sorted descending. Sorts by total recorded operations,
1161
+ * or by a single field when `field` is provided. Ties order by key.
1162
+ * @param {number} limit - Maximum entries to return (default 100)
1163
+ * @param {KeyStatField} [field] - Optionally rank by one counter (e.g. "hits")
1164
+ * @returns {StatsKeyEntry[]}
1165
+ */
1166
+ mostUsedKeys(limit = 100, field) {
1167
+ return this.sortedKeyEntries(field, "desc").slice(0, limit);
1168
+ }
1169
+ /**
1170
+ * The least-used keys, sorted ascending. Sorts by total recorded operations,
1171
+ * or by a single field when `field` is provided. Ties order by key. Note:
1172
+ * only keys that have been recorded at least once can be ranked, and when
1173
+ * {@link maxTrackedKeys} pruning has occurred the true least-used keys may
1174
+ * have been evicted.
1175
+ * @param {number} limit - Maximum entries to return (default 100)
1176
+ * @param {KeyStatField} [field] - Optionally rank by one counter (e.g. "gets")
1177
+ * @returns {StatsKeyEntry[]}
1178
+ */
1179
+ leastUsedKeys(limit = 100, field) {
1180
+ return this.sortedKeyEntries(field, "asc").slice(0, limit);
1181
+ }
1182
+ /**
1183
+ * @param {string} key - The key to look up
1184
+ * @returns {StatsKeyEntry | undefined} - The per-key statistics, or
1185
+ * `undefined` if the key has not been recorded
1186
+ */
1187
+ keyStats(key) {
1188
+ const counters = this._trackedKeys.get(key);
1189
+ return counters ? this.toKeyEntry(key, counters) : void 0;
1190
+ }
1191
+ /**
1192
+ * Clear all per-key statistics without touching the aggregate counters.
1193
+ */
1194
+ clearKeys() {
1195
+ this._trackedKeys.clear();
1196
+ }
1197
+ totalOf(counters) {
1198
+ return counters.hits + counters.misses + counters.gets + counters.sets + counters.deletes;
1199
+ }
1200
+ toKeyEntry(key, counters) {
1201
+ const lookups = counters.hits + counters.misses;
1202
+ return {
1203
+ key,
1204
+ count: this.totalOf(counters),
1205
+ hits: counters.hits,
1206
+ misses: counters.misses,
1207
+ gets: counters.gets,
1208
+ sets: counters.sets,
1209
+ deletes: counters.deletes,
1210
+ hitRate: lookups === 0 ? 0 : counters.hits / lookups
1211
+ };
1212
+ }
1213
+ sortedKeyEntries(field, direction) {
1214
+ const entries = [];
1215
+ for (const [key, counters] of this._trackedKeys) entries.push(this.toKeyEntry(key, counters));
1216
+ const sign = direction === "asc" ? 1 : -1;
1217
+ entries.sort((a, b) => {
1218
+ const valueA = field ? a[field] : a.count;
1219
+ const valueB = field ? b[field] : b.count;
1220
+ if (valueA !== valueB) return (valueA - valueB) * sign;
1221
+ return a.key < b.key ? -1 : 1;
1222
+ });
1223
+ return entries;
1224
+ }
1225
+ /**
1226
+ * When over {@link maxTrackedKeys}, prune the lowest-count keys down to 90%
1227
+ * of the cap (batched so the sort cost amortizes across inserts). The key
1228
+ * that was just recorded is never pruned.
1229
+ */
1230
+ pruneTrackedKeys(protectedKey) {
1231
+ if (this._maxTrackedKeys === void 0 || this._trackedKeys.size <= this._maxTrackedKeys) return;
1232
+ const target = Math.max(1, Math.floor(this._maxTrackedKeys * .9));
1233
+ const sorted = [...this._trackedKeys.entries()].sort((a, b) => this.totalOf(a[1]) - this.totalOf(b[1]));
1234
+ for (const [key] of sorted) {
1235
+ if (this._trackedKeys.size <= target) break;
1236
+ if (key === protectedKey) continue;
1237
+ this._trackedKeys.delete(key);
1238
+ }
1239
+ }
1240
+ /**
1241
+ * Subscribe to an emitter so that matching events automatically update the
1242
+ * stats. Counting is gated by {@link enabled}, so you may subscribe first and
1243
+ * toggle enablement later. Call {@link unsubscribe} to detach.
1244
+ * @param {StatsEmitter} emitter - The emitter to listen on
1245
+ * @param {StatsEventMap} eventMap - The event-to-stat mapping (e.g.
1246
+ * {@link nodeCacheStatsEventMap} or a custom map)
1247
+ */
1248
+ subscribe(emitter, eventMap) {
1249
+ for (const [event, action] of Object.entries(eventMap)) {
1250
+ const listener = (...args) => {
1251
+ this.applyEvent(action, args);
1252
+ };
1253
+ emitter.on(event, listener);
1254
+ this._subscriptions.push({
1255
+ emitter,
1256
+ event,
1257
+ listener
1258
+ });
1259
+ }
1260
+ }
1261
+ /**
1262
+ * Detach listeners previously attached via {@link subscribe}. When `emitter`
1263
+ * is provided, only that emitter's listeners are removed; otherwise all are.
1264
+ * @param {StatsEmitter} [emitter] - The emitter to detach from
1265
+ */
1266
+ unsubscribe(emitter) {
1267
+ const remaining = [];
1268
+ for (const sub of this._subscriptions) {
1269
+ if (emitter && sub.emitter !== emitter) {
1270
+ remaining.push(sub);
1271
+ continue;
1272
+ }
1273
+ (sub.emitter.off ?? sub.emitter.removeListener)?.call(sub.emitter, sub.event, sub.listener);
1274
+ }
1275
+ this._subscriptions = remaining;
1276
+ }
1277
+ applyEvent(action, args) {
1278
+ if (!this._enabled) return;
1279
+ if (typeof action === "function") {
1280
+ action(this, ...args);
1281
+ return;
1282
+ }
1283
+ if (Array.isArray(action)) {
1284
+ for (const field of action) this.increment(field);
1285
+ return;
1286
+ }
1287
+ this.increment(action);
1288
+ }
1289
+ touch() {
1290
+ this._lastUpdated = Date.now();
1291
+ }
1292
+ };
1293
+ //#endregion
1294
+ //#region src/ttl.ts
1295
+ /**
1296
+ * Normalizes a TTL input into per-store milliseconds. When given an object it resolves the
1297
+ * `primary` and `secondary` fields independently; when given a number or shorthand string it
1298
+ * applies the same value to both stores. Undefined fields (or undefined input) resolve to
1299
+ * `undefined` so the caller can fall back to its own default TTL.
1300
+ * @param ttl - The TTL input: a number (ms), a shorthand string, or a {@link PerStoreTtl} object.
1301
+ * @returns {{ primary?: number; secondary?: number }} The resolved per-store TTLs in milliseconds.
1302
+ */
1303
+ function resolvePerStoreTtl(ttl) {
1304
+ if (ttl === void 0 || ttl === null) return {
1305
+ primary: void 0,
1306
+ secondary: void 0
1307
+ };
1308
+ if (typeof ttl === "object") return {
1309
+ primary: shorthandToMilliseconds(ttl.primary),
1310
+ secondary: shorthandToMilliseconds(ttl.secondary)
1311
+ };
1312
+ const milliseconds = shorthandToMilliseconds(ttl);
1313
+ return {
1314
+ primary: milliseconds,
1315
+ secondary: milliseconds
1316
+ };
1317
+ }
1318
+ /**
1319
+ * Converts a exspires value to a TTL value.
1320
+ * @param expires - The expires value to convert.
1321
+ * @returns {number | undefined} The TTL value in milliseconds, or undefined if the expires value is not valid.
1322
+ */
1323
+ function getTtlFromExpires(expires) {
1324
+ if (expires === void 0 || expires === null) return;
1325
+ const now = Date.now();
1326
+ if (expires < now) return;
1327
+ return expires - now;
1328
+ }
1329
+ /**
1330
+ * Get the TTL value from the cacheableTtl, primaryTtl, and secondaryTtl values.
1331
+ * @param cacheableTtl - The cacheableTtl value to use.
1332
+ * @param primaryTtl - The primaryTtl value to use.
1333
+ * @param secondaryTtl - The secondaryTtl value to use.
1334
+ * @returns {number | undefined} The TTL value in milliseconds, or undefined if all values are undefined.
1335
+ */
1336
+ function getCascadingTtl(cacheableTtl, primaryTtl, secondaryTtl) {
1337
+ return secondaryTtl ?? primaryTtl ?? shorthandToMilliseconds(cacheableTtl);
1338
+ }
1339
+ /**
1340
+ * Calculate the TTL value from the expires value. If the ttl is undefined, it will be set to the expires value. If the
1341
+ * expires value is undefined, it will be set to the ttl value. If both values are defined, the smaller of the two will be used.
1342
+ * @param ttl
1343
+ * @param expires
1344
+ * @returns
1345
+ */
1346
+ function calculateTtlFromExpiration(ttl, expires) {
1347
+ const ttlFromExpires = getTtlFromExpires(expires);
1348
+ const expiresFromTtl = ttl ? Date.now() + ttl : void 0;
1349
+ if (ttlFromExpires === void 0) return ttl;
1350
+ if (expiresFromTtl === void 0) return ttlFromExpires;
1351
+ if (expires && expires > expiresFromTtl) return ttl;
1352
+ return ttlFromExpires;
1353
+ }
1354
+ //#endregion
1355
+ export { CacheTags, HashAlgorithm, Stats, calculateTtlFromExpiration, coalesceAsync, createWrapKey, getCascadingTtl, getOrSet, getOrSetSync, getTtlFromExpires, hash, hashSync, hashToNumber, hashToNumberSync, isKeyvInstance, isObject, lessThan, nodeCacheStatsEventMap, resolvePerStoreTtl, runIfFn, shorthandToMilliseconds, shorthandToTime, sleep, wrap, wrapSync };