@windrun-huaiin/backend-core 12.0.0 → 13.0.0

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 (270) hide show
  1. package/dist/_virtual/_commonjs-dynamic-modules.js +7 -0
  2. package/dist/_virtual/_commonjs-dynamic-modules.mjs +5 -0
  3. package/dist/_virtual/_commonjsHelpers.js +10 -0
  4. package/dist/_virtual/_commonjsHelpers.mjs +7 -0
  5. package/dist/_virtual/aes.js +5 -0
  6. package/dist/_virtual/aes.mjs +3 -0
  7. package/dist/_virtual/blowfish.js +5 -0
  8. package/dist/_virtual/blowfish.mjs +3 -0
  9. package/dist/_virtual/cipher-core.js +5 -0
  10. package/dist/_virtual/cipher-core.mjs +3 -0
  11. package/dist/_virtual/core.js +5 -0
  12. package/dist/_virtual/core.mjs +3 -0
  13. package/dist/_virtual/enc-base64.js +5 -0
  14. package/dist/_virtual/enc-base64.mjs +3 -0
  15. package/dist/_virtual/enc-base64url.js +5 -0
  16. package/dist/_virtual/enc-base64url.mjs +3 -0
  17. package/dist/_virtual/enc-utf16.js +5 -0
  18. package/dist/_virtual/enc-utf16.mjs +3 -0
  19. package/dist/_virtual/evpkdf.js +5 -0
  20. package/dist/_virtual/evpkdf.mjs +3 -0
  21. package/dist/_virtual/format-hex.js +5 -0
  22. package/dist/_virtual/format-hex.mjs +3 -0
  23. package/dist/_virtual/hmac.js +5 -0
  24. package/dist/_virtual/hmac.mjs +3 -0
  25. package/dist/_virtual/index.js +7 -0
  26. package/dist/_virtual/index.mjs +5 -0
  27. package/dist/_virtual/index2.js +9 -0
  28. package/dist/_virtual/index2.mjs +7 -0
  29. package/dist/_virtual/index3.js +5 -0
  30. package/dist/_virtual/index3.mjs +3 -0
  31. package/dist/_virtual/lib-typedarrays.js +5 -0
  32. package/dist/_virtual/lib-typedarrays.mjs +3 -0
  33. package/dist/_virtual/md5.js +5 -0
  34. package/dist/_virtual/md5.mjs +3 -0
  35. package/dist/_virtual/mode-cfb.js +5 -0
  36. package/dist/_virtual/mode-cfb.mjs +3 -0
  37. package/dist/_virtual/mode-ctr-gladman.js +5 -0
  38. package/dist/_virtual/mode-ctr-gladman.mjs +3 -0
  39. package/dist/_virtual/mode-ctr.js +5 -0
  40. package/dist/_virtual/mode-ctr.mjs +3 -0
  41. package/dist/_virtual/mode-ecb.js +5 -0
  42. package/dist/_virtual/mode-ecb.mjs +3 -0
  43. package/dist/_virtual/mode-ofb.js +5 -0
  44. package/dist/_virtual/mode-ofb.mjs +3 -0
  45. package/dist/_virtual/pad-ansix923.js +5 -0
  46. package/dist/_virtual/pad-ansix923.mjs +3 -0
  47. package/dist/_virtual/pad-iso10126.js +5 -0
  48. package/dist/_virtual/pad-iso10126.mjs +3 -0
  49. package/dist/_virtual/pad-iso97971.js +5 -0
  50. package/dist/_virtual/pad-iso97971.mjs +3 -0
  51. package/dist/_virtual/pad-nopadding.js +5 -0
  52. package/dist/_virtual/pad-nopadding.mjs +3 -0
  53. package/dist/_virtual/pad-zeropadding.js +5 -0
  54. package/dist/_virtual/pad-zeropadding.mjs +3 -0
  55. package/dist/_virtual/pbkdf2.js +5 -0
  56. package/dist/_virtual/pbkdf2.mjs +3 -0
  57. package/dist/_virtual/rabbit-legacy.js +5 -0
  58. package/dist/_virtual/rabbit-legacy.mjs +3 -0
  59. package/dist/_virtual/rabbit.js +5 -0
  60. package/dist/_virtual/rabbit.mjs +3 -0
  61. package/dist/_virtual/rc4.js +5 -0
  62. package/dist/_virtual/rc4.mjs +3 -0
  63. package/dist/_virtual/ripemd160.js +5 -0
  64. package/dist/_virtual/ripemd160.mjs +3 -0
  65. package/dist/_virtual/sha1.js +5 -0
  66. package/dist/_virtual/sha1.mjs +3 -0
  67. package/dist/_virtual/sha224.js +5 -0
  68. package/dist/_virtual/sha224.mjs +3 -0
  69. package/dist/_virtual/sha256.js +5 -0
  70. package/dist/_virtual/sha256.mjs +3 -0
  71. package/dist/_virtual/sha3.js +5 -0
  72. package/dist/_virtual/sha3.mjs +3 -0
  73. package/dist/_virtual/sha384.js +5 -0
  74. package/dist/_virtual/sha384.mjs +3 -0
  75. package/dist/_virtual/sha512.js +5 -0
  76. package/dist/_virtual/sha512.mjs +3 -0
  77. package/dist/_virtual/tripledes.js +5 -0
  78. package/dist/_virtual/tripledes.mjs +3 -0
  79. package/dist/_virtual/x64-core.js +5 -0
  80. package/dist/_virtual/x64-core.mjs +3 -0
  81. package/dist/index.js +46 -0
  82. package/dist/index.mjs +7 -0
  83. package/dist/lib/index.d.ts +2 -0
  84. package/dist/lib/index.d.ts.map +1 -1
  85. package/dist/lib/index.js +46 -0
  86. package/dist/lib/index.mjs +7 -0
  87. package/dist/lib/upstash/index.d.ts +7 -0
  88. package/dist/lib/upstash/index.d.ts.map +1 -0
  89. package/dist/lib/upstash/qstash.d.ts +36 -0
  90. package/dist/lib/upstash/qstash.d.ts.map +1 -0
  91. package/dist/lib/upstash/qstash.js +130 -0
  92. package/dist/lib/upstash/qstash.mjs +124 -0
  93. package/dist/lib/upstash/redis-counter.d.ts +17 -0
  94. package/dist/lib/upstash/redis-counter.d.ts.map +1 -0
  95. package/dist/lib/upstash/redis-counter.js +55 -0
  96. package/dist/lib/upstash/redis-counter.mjs +50 -0
  97. package/dist/lib/upstash/redis-favorite.d.ts +21 -0
  98. package/dist/lib/upstash/redis-favorite.d.ts.map +1 -0
  99. package/dist/lib/upstash/redis-favorite.js +74 -0
  100. package/dist/lib/upstash/redis-favorite.mjs +68 -0
  101. package/dist/lib/upstash/redis-like.d.ts +21 -0
  102. package/dist/lib/upstash/redis-like.d.ts.map +1 -0
  103. package/dist/lib/upstash/redis-like.js +74 -0
  104. package/dist/lib/upstash/redis-like.mjs +68 -0
  105. package/dist/lib/upstash/redis-lock.d.ts +13 -0
  106. package/dist/lib/upstash/redis-lock.d.ts.map +1 -0
  107. package/dist/lib/upstash/redis-lock.js +75 -0
  108. package/dist/lib/upstash/redis-lock.mjs +71 -0
  109. package/dist/lib/upstash/redis-structures.d.ts +63 -0
  110. package/dist/lib/upstash/redis-structures.d.ts.map +1 -0
  111. package/dist/lib/upstash/redis-structures.js +211 -0
  112. package/dist/lib/upstash/redis-structures.mjs +195 -0
  113. package/dist/lib/upstash-config.d.ts +11 -0
  114. package/dist/lib/upstash-config.d.ts.map +1 -0
  115. package/dist/lib/upstash-config.js +53 -0
  116. package/dist/lib/upstash-config.mjs +50 -0
  117. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.js +191 -0
  118. package/dist/node_modules/.pnpm/@upstash_lock@0.2.1_typescript@5.9.3/node_modules/@upstash/lock/dist/index.mjs +189 -0
  119. package/dist/node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js +1419 -0
  120. package/dist/node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs +1403 -0
  121. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.js +4691 -0
  122. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/chunk-LLI2WIYN.mjs +4686 -0
  123. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.js +115 -0
  124. package/dist/node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.mjs +113 -0
  125. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.js +248 -0
  126. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/aes.mjs +246 -0
  127. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.js +485 -0
  128. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/blowfish.mjs +483 -0
  129. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.js +906 -0
  130. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/cipher-core.mjs +904 -0
  131. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.js +818 -0
  132. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/core.mjs +816 -0
  133. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.js +146 -0
  134. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64.mjs +144 -0
  135. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.js +158 -0
  136. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-base64url.mjs +156 -0
  137. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.js +159 -0
  138. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/enc-utf16.mjs +157 -0
  139. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.js +146 -0
  140. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/evpkdf.mjs +144 -0
  141. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.js +77 -0
  142. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/format-hex.mjs +75 -0
  143. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.js +153 -0
  144. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/hmac.mjs +151 -0
  145. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +62 -0
  146. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.mjs +60 -0
  147. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.js +86 -0
  148. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/lib-typedarrays.mjs +84 -0
  149. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.js +278 -0
  150. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/md5.mjs +276 -0
  151. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.js +91 -0
  152. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-cfb.mjs +89 -0
  153. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.js +127 -0
  154. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr-gladman.mjs +125 -0
  155. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.js +69 -0
  156. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ctr.mjs +67 -0
  157. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.js +51 -0
  158. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ecb.mjs +49 -0
  159. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.js +65 -0
  160. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/mode-ofb.mjs +63 -0
  161. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.js +60 -0
  162. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-ansix923.mjs +58 -0
  163. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.js +55 -0
  164. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso10126.mjs +53 -0
  165. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.js +51 -0
  166. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-iso97971.mjs +49 -0
  167. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.js +41 -0
  168. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-nopadding.mjs +39 -0
  169. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.js +58 -0
  170. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pad-zeropadding.mjs +56 -0
  171. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.js +157 -0
  172. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/pbkdf2.mjs +155 -0
  173. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.js +204 -0
  174. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit-legacy.mjs +202 -0
  175. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.js +206 -0
  176. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rabbit.mjs +204 -0
  177. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.js +153 -0
  178. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/rc4.mjs +151 -0
  179. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.js +277 -0
  180. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/ripemd160.mjs +275 -0
  181. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.js +160 -0
  182. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha1.mjs +158 -0
  183. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.js +91 -0
  184. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha224.mjs +89 -0
  185. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.js +209 -0
  186. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha256.mjs +207 -0
  187. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.js +337 -0
  188. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha3.mjs +335 -0
  189. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.js +95 -0
  190. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha384.mjs +93 -0
  191. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.js +337 -0
  192. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/sha512.mjs +335 -0
  193. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.js +793 -0
  194. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/tripledes.mjs +791 -0
  195. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.js +314 -0
  196. package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/x64-core.mjs +312 -0
  197. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.js +26 -0
  198. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/compact/verify.mjs +24 -0
  199. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.js +127 -0
  200. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jws/flattened/verify.mjs +125 -0
  201. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.js +20 -0
  202. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/jwt/verify.mjs +18 -0
  203. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.js +31 -0
  204. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/key/import.mjs +29 -0
  205. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.js +18 -0
  206. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/buffer_utils.mjs +14 -0
  207. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.js +82 -0
  208. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/check_key_type.mjs +80 -0
  209. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.js +103 -0
  210. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/crypto_key.mjs +101 -0
  211. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.js +5 -0
  212. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/epoch.mjs +3 -0
  213. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.js +38 -0
  214. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/invalid_key_input.mjs +33 -0
  215. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.js +25 -0
  216. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_disjoint.mjs +23 -0
  217. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.js +21 -0
  218. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_jwk.mjs +16 -0
  219. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.js +20 -0
  220. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/is_object.mjs +18 -0
  221. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.js +109 -0
  222. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/jwt_claims_set.mjs +107 -0
  223. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.js +59 -0
  224. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/secs.mjs +57 -0
  225. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.js +14 -0
  226. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_algorithms.mjs +12 -0
  227. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.js +38 -0
  228. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/lib/validate_crit.mjs +36 -0
  229. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.js +15 -0
  230. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/base64url.mjs +13 -0
  231. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.js +21 -0
  232. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/check_key_length.mjs +19 -0
  233. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.js +28 -0
  234. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/dsa_digest.mjs +26 -0
  235. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.js +58 -0
  236. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_named_curve.mjs +56 -0
  237. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.js +33 -0
  238. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/get_sign_verify_key.mjs +31 -0
  239. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.js +18 -0
  240. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/hmac_digest.mjs +16 -0
  241. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.js +15 -0
  242. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_like.mjs +10 -0
  243. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.js +26 -0
  244. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/is_key_object.mjs +5 -0
  245. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.js +12 -0
  246. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/jwk_to_key.mjs +10 -0
  247. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.js +113 -0
  248. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/node_key.mjs +111 -0
  249. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.js +40 -0
  250. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/sign.mjs +19 -0
  251. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.js +52 -0
  252. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/verify.mjs +31 -0
  253. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.js +32 -0
  254. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/runtime/webcrypto.mjs +7 -0
  255. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.js +69 -0
  256. package/dist/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/esm/util/errors.mjs +60 -0
  257. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.js +422 -0
  258. package/dist/node_modules/.pnpm/neverthrow@7.2.0/node_modules/neverthrow/dist/index.es.mjs +415 -0
  259. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.js +6 -0
  260. package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.web.mjs +4 -0
  261. package/package.json +14 -11
  262. package/src/lib/index.ts +2 -0
  263. package/src/lib/upstash/index.ts +6 -0
  264. package/src/lib/upstash/qstash.ts +157 -0
  265. package/src/lib/upstash/redis-counter.ts +51 -0
  266. package/src/lib/upstash/redis-favorite.ts +75 -0
  267. package/src/lib/upstash/redis-like.ts +75 -0
  268. package/src/lib/upstash/redis-lock.ts +85 -0
  269. package/src/lib/upstash/redis-structures.ts +249 -0
  270. package/src/lib/upstash-config.ts +54 -0
@@ -0,0 +1,195 @@
1
+ import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
2
+ import { getRedis } from '../upstash-config.mjs';
3
+
4
+ /**
5
+ * Set a plain string value with optional TTL (seconds).
6
+ */
7
+ const setString = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
8
+ const redis = getRedis();
9
+ if (!redis) {
10
+ return false;
11
+ }
12
+ if (ttlSec && ttlSec > 0) {
13
+ yield redis.set(key, value, { ex: ttlSec });
14
+ return true;
15
+ }
16
+ yield redis.set(key, value);
17
+ return true;
18
+ });
19
+ /**
20
+ * Get a plain string value. Returns null if Redis is unavailable or key missing.
21
+ */
22
+ const getString = (key) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const redis = getRedis();
24
+ if (!redis) {
25
+ return null;
26
+ }
27
+ return redis.get(key);
28
+ });
29
+ /**
30
+ * Store an object as JSON string with optional TTL (seconds).
31
+ */
32
+ const setJson = (key, value, ttlSec) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const redis = getRedis();
34
+ if (!redis) {
35
+ return false;
36
+ }
37
+ const payload = JSON.stringify(value);
38
+ if (ttlSec && ttlSec > 0) {
39
+ yield redis.set(key, payload, { ex: ttlSec });
40
+ return true;
41
+ }
42
+ yield redis.set(key, payload);
43
+ return true;
44
+ });
45
+ /**
46
+ * Get an object stored as JSON string. Returns null if missing or invalid JSON.
47
+ */
48
+ const getJson = (key) => __awaiter(void 0, void 0, void 0, function* () {
49
+ const redis = getRedis();
50
+ if (!redis) {
51
+ return null;
52
+ }
53
+ const payload = yield redis.get(key);
54
+ if (!payload) {
55
+ return null;
56
+ }
57
+ try {
58
+ return JSON.parse(payload);
59
+ }
60
+ catch (_a) {
61
+ return null;
62
+ }
63
+ });
64
+ /**
65
+ * Delete a key. Returns false if Redis is unavailable.
66
+ */
67
+ const deleteKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
68
+ const redis = getRedis();
69
+ if (!redis) {
70
+ return false;
71
+ }
72
+ const deleted = yield redis.del(key);
73
+ return deleted > 0;
74
+ });
75
+ /**
76
+ * Set a hash field value.
77
+ */
78
+ const setHashField = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const redis = getRedis();
80
+ if (!redis) {
81
+ return false;
82
+ }
83
+ const result = yield redis.hset(key, { [field]: value });
84
+ return result > 0;
85
+ });
86
+ /**
87
+ * Get a hash field value.
88
+ */
89
+ const getHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
90
+ const redis = getRedis();
91
+ if (!redis) {
92
+ return null;
93
+ }
94
+ return redis.hget(key, field);
95
+ });
96
+ /**
97
+ * Store a hash field as JSON string.
98
+ */
99
+ const setHashJson = (key, field, value) => __awaiter(void 0, void 0, void 0, function* () {
100
+ const redis = getRedis();
101
+ if (!redis) {
102
+ return false;
103
+ }
104
+ const payload = JSON.stringify(value);
105
+ const result = yield redis.hset(key, { [field]: payload });
106
+ return result > 0;
107
+ });
108
+ /**
109
+ * Get a hash field stored as JSON string.
110
+ */
111
+ const getHashJson = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
112
+ const redis = getRedis();
113
+ if (!redis) {
114
+ return null;
115
+ }
116
+ const payload = yield redis.hget(key, field);
117
+ if (!payload) {
118
+ return null;
119
+ }
120
+ try {
121
+ return JSON.parse(payload);
122
+ }
123
+ catch (_a) {
124
+ return null;
125
+ }
126
+ });
127
+ /**
128
+ * Get all hash fields.
129
+ */
130
+ const getHashAll = (key) => __awaiter(void 0, void 0, void 0, function* () {
131
+ const redis = getRedis();
132
+ if (!redis) {
133
+ return null;
134
+ }
135
+ const result = yield redis.hgetall(key);
136
+ return result !== null && result !== void 0 ? result : {};
137
+ });
138
+ /**
139
+ * Remove a hash field.
140
+ */
141
+ const deleteHashField = (key, field) => __awaiter(void 0, void 0, void 0, function* () {
142
+ const redis = getRedis();
143
+ if (!redis) {
144
+ return false;
145
+ }
146
+ const removed = yield redis.hdel(key, field);
147
+ return removed > 0;
148
+ });
149
+ /**
150
+ * Push values to a list. Returns list length or null if Redis is unavailable.
151
+ */
152
+ const pushList = (key_1, values_1, ...args_1) => __awaiter(void 0, [key_1, values_1, ...args_1], void 0, function* (key, values, direction = 'right') {
153
+ const redis = getRedis();
154
+ if (!redis) {
155
+ return null;
156
+ }
157
+ if (values.length === 0) {
158
+ return redis.llen(key);
159
+ }
160
+ return direction === 'left'
161
+ ? redis.lpush(key, ...values)
162
+ : redis.rpush(key, ...values);
163
+ });
164
+ /**
165
+ * Pop a value from a list.
166
+ */
167
+ const popList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, direction = 'right') {
168
+ const redis = getRedis();
169
+ if (!redis) {
170
+ return null;
171
+ }
172
+ return direction === 'left' ? redis.lpop(key) : redis.rpop(key);
173
+ });
174
+ /**
175
+ * Get a range from a list.
176
+ */
177
+ const rangeList = (key_1, ...args_1) => __awaiter(void 0, [key_1, ...args_1], void 0, function* (key, start = 0, stop = -1) {
178
+ const redis = getRedis();
179
+ if (!redis) {
180
+ return null;
181
+ }
182
+ return redis.lrange(key, start, stop);
183
+ });
184
+ /**
185
+ * Get list length.
186
+ */
187
+ const listLength = (key) => __awaiter(void 0, void 0, void 0, function* () {
188
+ const redis = getRedis();
189
+ if (!redis) {
190
+ return null;
191
+ }
192
+ return redis.llen(key);
193
+ });
194
+
195
+ export { deleteHashField, deleteKey, getHashAll, getHashField, getHashJson, getJson, getString, listLength, popList, pushList, rangeList, setHashField, setHashJson, setJson, setString };
@@ -0,0 +1,11 @@
1
+ import { Redis } from '@upstash/redis';
2
+ import { Client as QstashClient } from '@upstash/qstash';
3
+ /**
4
+ * Get the Upstash Redis client. Returns null when required env vars are missing.
5
+ */
6
+ export declare const getRedis: () => Redis | null;
7
+ /**
8
+ * Get the Upstash QStash client. Returns null when required env vars are missing.
9
+ */
10
+ export declare const getQstash: () => QstashClient | null;
11
+ //# sourceMappingURL=upstash-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstash-config.d.ts","sourceRoot":"","sources":["../../src/lib/upstash-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOzD;;GAEG;AACH,eAAO,MAAM,QAAQ,QAAO,KAAK,GAAG,IAoBnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAO,YAAY,GAAG,IAiB3C,CAAC"}
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var nodejs = require('../node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.js');
4
+ var chunkRQPZUJXG = require('../node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.js');
5
+
6
+ let cachedRedis = null;
7
+ let cachedQstash = null;
8
+ let redisInitAttempted = false;
9
+ let qstashInitAttempted = false;
10
+ /**
11
+ * Get the Upstash Redis client. Returns null when required env vars are missing.
12
+ */
13
+ const getRedis = () => {
14
+ if (cachedRedis) {
15
+ return cachedRedis;
16
+ }
17
+ if (redisInitAttempted) {
18
+ return null;
19
+ }
20
+ redisInitAttempted = true;
21
+ const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
22
+ if (!UPSTASH_REDIS_REST_URL || !UPSTASH_REDIS_REST_TOKEN) {
23
+ console.warn('[Upstash Config] Redis Missed configration UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN, then disabled');
24
+ return null;
25
+ }
26
+ cachedRedis = new nodejs.Redis({
27
+ url: UPSTASH_REDIS_REST_URL,
28
+ token: UPSTASH_REDIS_REST_TOKEN,
29
+ });
30
+ return cachedRedis;
31
+ };
32
+ /**
33
+ * Get the Upstash QStash client. Returns null when required env vars are missing.
34
+ */
35
+ const getQstash = () => {
36
+ if (cachedQstash) {
37
+ return cachedQstash;
38
+ }
39
+ if (qstashInitAttempted) {
40
+ return null;
41
+ }
42
+ qstashInitAttempted = true;
43
+ const { QSTASH_TOKEN } = process.env;
44
+ if (!QSTASH_TOKEN) {
45
+ console.warn('[Upstash Config] QStash Missed configration QSTASH_TOKEN, then disabled');
46
+ return null;
47
+ }
48
+ cachedQstash = new chunkRQPZUJXG.Client({ token: QSTASH_TOKEN });
49
+ return cachedQstash;
50
+ };
51
+
52
+ exports.getQstash = getQstash;
53
+ exports.getRedis = getRedis;
@@ -0,0 +1,50 @@
1
+ import { Redis as Redis2 } from '../node_modules/.pnpm/@upstash_redis@1.36.1/node_modules/@upstash/redis/nodejs.mjs';
2
+ import { Client } from '../node_modules/.pnpm/@upstash_qstash@2.8.4/node_modules/@upstash/qstash/chunk-RQPZUJXG.mjs';
3
+
4
+ let cachedRedis = null;
5
+ let cachedQstash = null;
6
+ let redisInitAttempted = false;
7
+ let qstashInitAttempted = false;
8
+ /**
9
+ * Get the Upstash Redis client. Returns null when required env vars are missing.
10
+ */
11
+ const getRedis = () => {
12
+ if (cachedRedis) {
13
+ return cachedRedis;
14
+ }
15
+ if (redisInitAttempted) {
16
+ return null;
17
+ }
18
+ redisInitAttempted = true;
19
+ const { UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN } = process.env;
20
+ if (!UPSTASH_REDIS_REST_URL || !UPSTASH_REDIS_REST_TOKEN) {
21
+ console.warn('[Upstash Config] Redis Missed configration UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN, then disabled');
22
+ return null;
23
+ }
24
+ cachedRedis = new Redis2({
25
+ url: UPSTASH_REDIS_REST_URL,
26
+ token: UPSTASH_REDIS_REST_TOKEN,
27
+ });
28
+ return cachedRedis;
29
+ };
30
+ /**
31
+ * Get the Upstash QStash client. Returns null when required env vars are missing.
32
+ */
33
+ const getQstash = () => {
34
+ if (cachedQstash) {
35
+ return cachedQstash;
36
+ }
37
+ if (qstashInitAttempted) {
38
+ return null;
39
+ }
40
+ qstashInitAttempted = true;
41
+ const { QSTASH_TOKEN } = process.env;
42
+ if (!QSTASH_TOKEN) {
43
+ console.warn('[Upstash Config] QStash Missed configration QSTASH_TOKEN, then disabled');
44
+ return null;
45
+ }
46
+ cachedQstash = new Client({ token: QSTASH_TOKEN });
47
+ return cachedQstash;
48
+ };
49
+
50
+ export { getQstash, getRedis };
@@ -0,0 +1,191 @@
1
+ 'use strict';
2
+
3
+ var dist;
4
+ var hasRequiredDist;
5
+
6
+ function requireDist () {
7
+ if (hasRequiredDist) return dist;
8
+ hasRequiredDist = 1;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var __async = (__this, __arguments, generator) => {
27
+ return new Promise((resolve, reject) => {
28
+ var fulfilled = (value) => {
29
+ try {
30
+ step(generator.next(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var rejected = (value) => {
36
+ try {
37
+ step(generator.throw(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
43
+ step((generator = generator.apply(__this, __arguments)).next());
44
+ });
45
+ };
46
+
47
+ // src/index.ts
48
+ var src_exports = {};
49
+ __export(src_exports, {
50
+ Lock: () => Lock
51
+ });
52
+ dist = __toCommonJS(src_exports);
53
+
54
+ // src/lock.ts
55
+ var Lock = class {
56
+ constructor(config) {
57
+ this.DEFAULT_LEASE_MS = 1e4;
58
+ this.DEFAULT_RETRY_ATTEMPTS = 3;
59
+ this.DEFAULT_RETRY_DELAY_MS = 100;
60
+ var _a, _b, _c, _d, _e;
61
+ this.config = {
62
+ redis: config.redis,
63
+ id: config.id,
64
+ lease: (_a = config.lease) != null ? _a : this.DEFAULT_LEASE_MS,
65
+ UUID: null,
66
+ // set when lock is acquired
67
+ retry: {
68
+ attempts: (_c = (_b = config.retry) == null ? void 0 : _b.attempts) != null ? _c : this.DEFAULT_RETRY_ATTEMPTS,
69
+ delay: (_e = (_d = config.retry) == null ? void 0 : _d.delay) != null ? _e : this.DEFAULT_RETRY_DELAY_MS
70
+ }
71
+ };
72
+ }
73
+ /**
74
+ * Tries to acquire a lock with the given configuration.
75
+ * If initially unsuccessful, the method will retry based on the provided retry configuration.
76
+ *
77
+ * @param config - Optional configuration for the lock acquisition to override the constructor config.
78
+ * @returns {Promise<boolean>} True if the lock was acquired, otherwise false.
79
+ */
80
+ acquire(acquireConfig) {
81
+ return __async(this, null, function* () {
82
+ var _a, _b, _c, _d, _e, _f, _g;
83
+ const lease = (_a = acquireConfig == null ? void 0 : acquireConfig.lease) != null ? _a : this.config.lease;
84
+ this.config.lease = lease;
85
+ const retryAttempts = (_d = (_b = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _b.attempts) != null ? _d : (_c = this.config.retry) == null ? void 0 : _c.attempts;
86
+ const retryDelay = (_g = (_e = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _e.delay) != null ? _g : (_f = this.config.retry) == null ? void 0 : _f.delay;
87
+ let attempts = 0;
88
+ let UUID;
89
+ if (acquireConfig == null ? void 0 : acquireConfig.uuid) {
90
+ UUID = acquireConfig.uuid;
91
+ } else {
92
+ try {
93
+ UUID = crypto.randomUUID();
94
+ } catch (error) {
95
+ throw new Error("No UUID provided and crypto module is not available in this environment.");
96
+ }
97
+ }
98
+ while (attempts < retryAttempts) {
99
+ const upstashResult = yield this.config.redis.set(this.config.id, UUID, {
100
+ nx: true,
101
+ px: lease
102
+ });
103
+ if (upstashResult === "OK") {
104
+ this.config.UUID = UUID;
105
+ return true;
106
+ }
107
+ attempts += 1;
108
+ yield new Promise((resolve) => setTimeout(resolve, retryDelay));
109
+ }
110
+ this.config.UUID = null;
111
+ return false;
112
+ });
113
+ }
114
+ /**
115
+ * Safely releases the lock ensuring the UUID matches.
116
+ * This operation utilizes a Lua script to interact with Redis and
117
+ * guarantees atomicity of the unlock operation.
118
+ * @returns {Promise<boolean>} True if the lock was released, otherwise false.
119
+ */
120
+ release() {
121
+ return __async(this, null, function* () {
122
+ const script = `
123
+ -- Check if the current UUID still holds the lock
124
+ if redis.call("get", KEYS[1]) == ARGV[1] then
125
+ return redis.call("del", KEYS[1])
126
+ else
127
+ return 0
128
+ end
129
+ `;
130
+ const numReleased = yield this.config.redis.eval(script, [this.config.id], [this.config.UUID]);
131
+ return numReleased === 1;
132
+ });
133
+ }
134
+ /**
135
+ * Extends the duration for which the lock is held by a given amount of milliseconds.
136
+ * @param amt - The number of milliseconds by which the lock duration should be extended.
137
+ * @returns {Promise<boolean>} True if the lock duration was extended, otherwise false.
138
+ */
139
+ extend(amt) {
140
+ return __async(this, null, function* () {
141
+ const script = `
142
+ -- Check if the current UUID still holds the lock
143
+ if redis.call("get", KEYS[1]) ~= ARGV[1] then
144
+ return 0
145
+ end
146
+
147
+ -- Get the current TTL and extend it by the specified amount
148
+ local ttl = redis.call("ttl", KEYS[1])
149
+ if ttl > 0 then
150
+ return redis.call("expire", KEYS[1], ttl + ARGV[2])
151
+ else
152
+ return 0
153
+ end
154
+ `;
155
+ const extendBy = amt / 1e3;
156
+ const extended = yield this.config.redis.eval(
157
+ script,
158
+ [this.config.id],
159
+ [this.config.UUID, extendBy]
160
+ );
161
+ if (extended === 1) {
162
+ this.config.lease += amt;
163
+ }
164
+ return extended === 1;
165
+ });
166
+ }
167
+ get id() {
168
+ return this.config.id;
169
+ }
170
+ /**
171
+ * Gets the status of the lock, ie: ACQUIRED or FREE.
172
+ * @returns {Promise<LockStatus>} The status of the lock.
173
+ */
174
+ getStatus() {
175
+ return __async(this, null, function* () {
176
+ if (this.config.UUID === null) {
177
+ return "FREE";
178
+ }
179
+ const UUID = yield this.config.redis.get(this.config.id);
180
+ if (UUID === this.config.UUID) {
181
+ return "ACQUIRED";
182
+ }
183
+ return "FREE";
184
+ });
185
+ }
186
+ };
187
+
188
+ return dist;
189
+ }
190
+
191
+ exports.__require = requireDist;
@@ -0,0 +1,189 @@
1
+ var dist;
2
+ var hasRequiredDist;
3
+
4
+ function requireDist () {
5
+ if (hasRequiredDist) return dist;
6
+ hasRequiredDist = 1;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+
45
+ // src/index.ts
46
+ var src_exports = {};
47
+ __export(src_exports, {
48
+ Lock: () => Lock
49
+ });
50
+ dist = __toCommonJS(src_exports);
51
+
52
+ // src/lock.ts
53
+ var Lock = class {
54
+ constructor(config) {
55
+ this.DEFAULT_LEASE_MS = 1e4;
56
+ this.DEFAULT_RETRY_ATTEMPTS = 3;
57
+ this.DEFAULT_RETRY_DELAY_MS = 100;
58
+ var _a, _b, _c, _d, _e;
59
+ this.config = {
60
+ redis: config.redis,
61
+ id: config.id,
62
+ lease: (_a = config.lease) != null ? _a : this.DEFAULT_LEASE_MS,
63
+ UUID: null,
64
+ // set when lock is acquired
65
+ retry: {
66
+ attempts: (_c = (_b = config.retry) == null ? void 0 : _b.attempts) != null ? _c : this.DEFAULT_RETRY_ATTEMPTS,
67
+ delay: (_e = (_d = config.retry) == null ? void 0 : _d.delay) != null ? _e : this.DEFAULT_RETRY_DELAY_MS
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * Tries to acquire a lock with the given configuration.
73
+ * If initially unsuccessful, the method will retry based on the provided retry configuration.
74
+ *
75
+ * @param config - Optional configuration for the lock acquisition to override the constructor config.
76
+ * @returns {Promise<boolean>} True if the lock was acquired, otherwise false.
77
+ */
78
+ acquire(acquireConfig) {
79
+ return __async(this, null, function* () {
80
+ var _a, _b, _c, _d, _e, _f, _g;
81
+ const lease = (_a = acquireConfig == null ? void 0 : acquireConfig.lease) != null ? _a : this.config.lease;
82
+ this.config.lease = lease;
83
+ const retryAttempts = (_d = (_b = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _b.attempts) != null ? _d : (_c = this.config.retry) == null ? void 0 : _c.attempts;
84
+ const retryDelay = (_g = (_e = acquireConfig == null ? void 0 : acquireConfig.retry) == null ? void 0 : _e.delay) != null ? _g : (_f = this.config.retry) == null ? void 0 : _f.delay;
85
+ let attempts = 0;
86
+ let UUID;
87
+ if (acquireConfig == null ? void 0 : acquireConfig.uuid) {
88
+ UUID = acquireConfig.uuid;
89
+ } else {
90
+ try {
91
+ UUID = crypto.randomUUID();
92
+ } catch (error) {
93
+ throw new Error("No UUID provided and crypto module is not available in this environment.");
94
+ }
95
+ }
96
+ while (attempts < retryAttempts) {
97
+ const upstashResult = yield this.config.redis.set(this.config.id, UUID, {
98
+ nx: true,
99
+ px: lease
100
+ });
101
+ if (upstashResult === "OK") {
102
+ this.config.UUID = UUID;
103
+ return true;
104
+ }
105
+ attempts += 1;
106
+ yield new Promise((resolve) => setTimeout(resolve, retryDelay));
107
+ }
108
+ this.config.UUID = null;
109
+ return false;
110
+ });
111
+ }
112
+ /**
113
+ * Safely releases the lock ensuring the UUID matches.
114
+ * This operation utilizes a Lua script to interact with Redis and
115
+ * guarantees atomicity of the unlock operation.
116
+ * @returns {Promise<boolean>} True if the lock was released, otherwise false.
117
+ */
118
+ release() {
119
+ return __async(this, null, function* () {
120
+ const script = `
121
+ -- Check if the current UUID still holds the lock
122
+ if redis.call("get", KEYS[1]) == ARGV[1] then
123
+ return redis.call("del", KEYS[1])
124
+ else
125
+ return 0
126
+ end
127
+ `;
128
+ const numReleased = yield this.config.redis.eval(script, [this.config.id], [this.config.UUID]);
129
+ return numReleased === 1;
130
+ });
131
+ }
132
+ /**
133
+ * Extends the duration for which the lock is held by a given amount of milliseconds.
134
+ * @param amt - The number of milliseconds by which the lock duration should be extended.
135
+ * @returns {Promise<boolean>} True if the lock duration was extended, otherwise false.
136
+ */
137
+ extend(amt) {
138
+ return __async(this, null, function* () {
139
+ const script = `
140
+ -- Check if the current UUID still holds the lock
141
+ if redis.call("get", KEYS[1]) ~= ARGV[1] then
142
+ return 0
143
+ end
144
+
145
+ -- Get the current TTL and extend it by the specified amount
146
+ local ttl = redis.call("ttl", KEYS[1])
147
+ if ttl > 0 then
148
+ return redis.call("expire", KEYS[1], ttl + ARGV[2])
149
+ else
150
+ return 0
151
+ end
152
+ `;
153
+ const extendBy = amt / 1e3;
154
+ const extended = yield this.config.redis.eval(
155
+ script,
156
+ [this.config.id],
157
+ [this.config.UUID, extendBy]
158
+ );
159
+ if (extended === 1) {
160
+ this.config.lease += amt;
161
+ }
162
+ return extended === 1;
163
+ });
164
+ }
165
+ get id() {
166
+ return this.config.id;
167
+ }
168
+ /**
169
+ * Gets the status of the lock, ie: ACQUIRED or FREE.
170
+ * @returns {Promise<LockStatus>} The status of the lock.
171
+ */
172
+ getStatus() {
173
+ return __async(this, null, function* () {
174
+ if (this.config.UUID === null) {
175
+ return "FREE";
176
+ }
177
+ const UUID = yield this.config.redis.get(this.config.id);
178
+ if (UUID === this.config.UUID) {
179
+ return "ACQUIRED";
180
+ }
181
+ return "FREE";
182
+ });
183
+ }
184
+ };
185
+
186
+ return dist;
187
+ }
188
+
189
+ export { requireDist as __require };