@burdenoff/be-sdk 2026.1110.1 → 2026.1110.3

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 (469) hide show
  1. package/configs/eslint/index.js +1 -1
  2. package/configs/tsconfig/tsconfig.json +1 -1
  3. package/dist/EventQueueFactory-9NGZV9jl.js +1457 -0
  4. package/dist/EventQueueFactory-9NGZV9jl.js.map +1 -0
  5. package/dist/RedisStreamsConnection-CY8WySJy.js +283 -0
  6. package/dist/RedisStreamsConnection-CY8WySJy.js.map +1 -0
  7. package/dist/ai-credits/index.d.ts +2 -3
  8. package/dist/ai-credits/index.js +3 -4
  9. package/dist/ai-credits/index.js.map +1 -1
  10. package/dist/ai-credits-Ca-NNcVx.js +546 -0
  11. package/dist/ai-credits-Ca-NNcVx.js.map +1 -0
  12. package/dist/{assistant-session-CJZhF4D6.d.ts → assistant-session-DA5ZKJOr.d.ts} +4 -5
  13. package/dist/auth/index.d.ts +2 -77
  14. package/dist/auth/index.js +3 -7
  15. package/dist/auth/index.js.map +1 -1
  16. package/dist/auth-CEuBEBQN.js +228 -0
  17. package/dist/auth-CEuBEBQN.js.map +1 -0
  18. package/dist/cache/index.d.ts +2 -3
  19. package/dist/cache/index.js +3 -7
  20. package/dist/cache/index.js.map +1 -1
  21. package/dist/cache-CU0uLwcS.js +1837 -0
  22. package/dist/cache-CU0uLwcS.js.map +1 -0
  23. package/dist/captcha/index.d.ts +2 -1
  24. package/dist/captcha/index.js +3 -3
  25. package/dist/captcha/index.js.map +1 -1
  26. package/dist/captcha-BT7yh1YS.js +77 -0
  27. package/dist/captcha-BT7yh1YS.js.map +1 -0
  28. package/dist/client/internal-client.d.ts +4 -7
  29. package/dist/client/internal-client.js +172 -4
  30. package/dist/client/internal-client.js.map +1 -1
  31. package/dist/client-BgAEvDC2.d.ts +86 -0
  32. package/dist/client-DcZ3iGES.js +565 -0
  33. package/dist/client-DcZ3iGES.js.map +1 -0
  34. package/dist/collector-endpoint-iyQYeI50.js +50 -0
  35. package/dist/collector-endpoint-iyQYeI50.js.map +1 -0
  36. package/dist/context-CZnXf2yb.js +247 -0
  37. package/dist/context-CZnXf2yb.js.map +1 -0
  38. package/dist/crypto/index.d.ts +2 -1
  39. package/dist/crypto/index.js +3 -3
  40. package/dist/crypto/index.js.map +1 -1
  41. package/dist/crypto-DO9fM0FO.js +145 -0
  42. package/dist/crypto-DO9fM0FO.js.map +1 -0
  43. package/dist/database/index.d.ts +104 -108
  44. package/dist/database/index.js +468 -6
  45. package/dist/database/index.js.map +1 -1
  46. package/dist/dataloader/index.d.ts +2 -1
  47. package/dist/dataloader/index.js +3 -3
  48. package/dist/dataloader/index.js.map +1 -1
  49. package/dist/dataloader-DwpT3YoS.js +294 -0
  50. package/dist/dataloader-DwpT3YoS.js.map +1 -0
  51. package/dist/deployed-environment-p_Tdl3sT.js +38 -0
  52. package/dist/deployed-environment-p_Tdl3sT.js.map +1 -0
  53. package/dist/dist-BGKdXVy3.js +1718 -0
  54. package/dist/dist-BGKdXVy3.js.map +1 -0
  55. package/dist/env-DdaoGjIt.js +74 -0
  56. package/dist/env-DdaoGjIt.js.map +1 -0
  57. package/dist/event-queue/index.d.ts +2 -7
  58. package/dist/event-queue/index.js +7 -9
  59. package/dist/event-queue/index.js.map +1 -1
  60. package/dist/event-queue-Cw-YJPY_.js +1384 -0
  61. package/dist/event-queue-Cw-YJPY_.js.map +1 -0
  62. package/dist/{explicit-activity-scope-CCoxVwAr.d.ts → explicit-activity-scope-D8VeGGpt.d.ts} +1 -2
  63. package/dist/export/index.d.ts +2 -2
  64. package/dist/export/index.js +3 -14
  65. package/dist/export/index.js.map +1 -1
  66. package/dist/export-B6fphx8a.js +642 -0
  67. package/dist/export-B6fphx8a.js.map +1 -0
  68. package/dist/feature-flags/index.d.ts +2 -10
  69. package/dist/feature-flags/index.js +3 -6
  70. package/dist/feature-flags/index.js.map +1 -1
  71. package/dist/feature-flags-71oDkrUe.js +422 -0
  72. package/dist/feature-flags-71oDkrUe.js.map +1 -0
  73. package/dist/files/index.d.ts +2 -3
  74. package/dist/files/index.js +3 -4
  75. package/dist/files/index.js.map +1 -1
  76. package/dist/files-DjH0099H.js +830 -0
  77. package/dist/files-DjH0099H.js.map +1 -0
  78. package/dist/gateway/index.d.ts +4 -6
  79. package/dist/gateway/index.js +7 -13
  80. package/dist/gateway/index.js.map +1 -1
  81. package/dist/gateway/security/index.d.ts +2 -2
  82. package/dist/gateway/security/index.js +3 -5
  83. package/dist/gateway/security/index.js.map +1 -1
  84. package/dist/gateway-DBFmxWks.js +50 -0
  85. package/dist/gateway-DBFmxWks.js.map +1 -0
  86. package/dist/graph/index.d.ts +3 -10
  87. package/dist/graph/index.js +4 -13
  88. package/dist/graph/index.js.map +1 -1
  89. package/dist/graph-DDYgIryR.js +2152 -0
  90. package/dist/graph-DDYgIryR.js.map +1 -0
  91. package/dist/graph-emitter-CdOXP7Tn.js +621 -0
  92. package/dist/graph-emitter-CdOXP7Tn.js.map +1 -0
  93. package/dist/graphql/index.d.ts +3 -2
  94. package/dist/graphql/index.js +4 -6
  95. package/dist/graphql/index.js.map +1 -1
  96. package/dist/graphql/services/index.d.ts +2 -24
  97. package/dist/graphql/services/index.js +3 -4
  98. package/dist/graphql/services/index.js.map +1 -1
  99. package/dist/graphql-DHAHHcww.js +161 -0
  100. package/dist/graphql-DHAHHcww.js.map +1 -0
  101. package/dist/graphql-DNkMkGBZ.d.ts +21 -0
  102. package/dist/i18n/index.d.ts +3 -3
  103. package/dist/i18n/index.js +3 -4
  104. package/dist/i18n/index.js.map +1 -1
  105. package/dist/i18n-BBMYFd0P.js +860 -0
  106. package/dist/i18n-BBMYFd0P.js.map +1 -0
  107. package/dist/import-optional-peer-B82VYxeX.js +18 -0
  108. package/dist/import-optional-peer-B82VYxeX.js.map +1 -0
  109. package/dist/index-3KOZ1zN9.d.ts +233 -0
  110. package/dist/index-BBqooJ52.d.ts +45 -0
  111. package/dist/index-BGzMYJsm.d.ts +209 -0
  112. package/dist/index-BKwHQtHQ.d.ts +63 -0
  113. package/dist/index-BMIMnp6T.d.ts +8 -0
  114. package/dist/index-BQDsNAMR.d.ts +81 -0
  115. package/dist/index-BVOL7458.d.ts +10 -0
  116. package/dist/index-BcqQs-Uq.d.ts +69 -0
  117. package/dist/index-BeVtqGO-.d.ts +208 -0
  118. package/dist/index-BiTzGUZP.d.ts +114 -0
  119. package/dist/index-BqYfCQSP.d.ts +500 -0
  120. package/dist/index-C0qLquY0.d.ts +150 -0
  121. package/dist/index-C5uEKchX.d.ts +60 -0
  122. package/dist/index-CDOqxSIi.d.ts +37 -0
  123. package/dist/index-CG6wj66Y.d.ts +148 -0
  124. package/dist/index-CIgoeobA.d.ts +145 -0
  125. package/dist/index-CPQDMSFS.d.ts +103 -0
  126. package/dist/index-CSRcgkVi.d.ts +23 -0
  127. package/dist/index-CZTnQIRU.d.ts +341 -0
  128. package/dist/index-CaM9JUcc.d.ts +144 -0
  129. package/dist/index-CkT2aUr3.d.ts +704 -0
  130. package/dist/index-CliOgq6L.d.ts +203 -0
  131. package/dist/index-CnzbJZP7.d.ts +999 -0
  132. package/dist/index-D6UeLAye.d.ts +63 -0
  133. package/dist/index-DGgh9DWn.d.ts +59 -0
  134. package/dist/index-DY3dNhMN.d.ts +420 -0
  135. package/dist/index-DZC-2o9R.d.ts +207 -0
  136. package/dist/index-DqbGqfAy.d.ts +127 -0
  137. package/dist/index-Dt1HJPTX.d.ts +12 -0
  138. package/dist/index-DtI6aBtB.d.ts +22 -0
  139. package/dist/index-FKohsiex.d.ts +38 -0
  140. package/dist/index-FbXPfen7.d.ts +132 -0
  141. package/dist/index-MArCb8Aq.d.ts +306 -0
  142. package/dist/index-N-huORcj.d.ts +303 -0
  143. package/dist/index-YOShAwkq.d.ts +45 -0
  144. package/dist/index-bZKZUvBu.d.ts +646 -0
  145. package/dist/index-yBSjMY32.d.ts +24 -0
  146. package/dist/index.d.ts +501 -544
  147. package/dist/index.js +1820 -2171
  148. package/dist/index.js.map +1 -1
  149. package/dist/init/index.d.ts +2 -2
  150. package/dist/init/index.js +3 -16
  151. package/dist/init/index.js.map +1 -1
  152. package/dist/init-Dy3KhT6Y.js +325 -0
  153. package/dist/init-Dy3KhT6Y.js.map +1 -0
  154. package/dist/instrumentation/index.d.ts +3 -4
  155. package/dist/instrumentation/index.js +5 -5
  156. package/dist/instrumentation/index.js.map +1 -1
  157. package/dist/instrumentation-xkkmDgJ0.js +1678 -0
  158. package/dist/instrumentation-xkkmDgJ0.js.map +1 -0
  159. package/dist/lake/index.d.ts +50 -54
  160. package/dist/lake/index.js +169 -193
  161. package/dist/lake/index.js.map +1 -1
  162. package/dist/layer/index.d.ts +3 -2
  163. package/dist/layer/index.js +4 -5
  164. package/dist/layer/index.js.map +1 -1
  165. package/dist/layer-BZBZZWeV.d.ts +69 -0
  166. package/dist/layer-Bcix-WCl.js +105 -0
  167. package/dist/layer-Bcix-WCl.js.map +1 -0
  168. package/dist/layer-CEKy6cm8.js +252 -0
  169. package/dist/layer-CEKy6cm8.js.map +1 -0
  170. package/dist/lifecycle/index.d.ts +2 -1
  171. package/dist/lifecycle/index.js +3 -4
  172. package/dist/lifecycle/index.js.map +1 -1
  173. package/dist/lifecycle-DeoLSX0U.js +76 -0
  174. package/dist/lifecycle-DeoLSX0U.js.map +1 -0
  175. package/dist/logger/index.d.ts +2 -3
  176. package/dist/logger/index.js +3 -3
  177. package/dist/logger/index.js.map +1 -1
  178. package/dist/logger-B6rCpb7D.js +290 -0
  179. package/dist/logger-B6rCpb7D.js.map +1 -0
  180. package/dist/metrics/index.d.ts +13 -14
  181. package/dist/metrics/index.js +3 -4
  182. package/dist/metrics/index.js.map +1 -1
  183. package/dist/metrics-BrLwNUrb.js +52 -0
  184. package/dist/metrics-BrLwNUrb.js.map +1 -0
  185. package/dist/metrics-collector-C2eShrlW.js +922 -0
  186. package/dist/metrics-collector-C2eShrlW.js.map +1 -0
  187. package/dist/middleware/index.d.ts +3 -3
  188. package/dist/middleware/index.js +3 -4
  189. package/dist/middleware/index.js.map +1 -1
  190. package/dist/middleware-CUxJVUpD.js +1243 -0
  191. package/dist/middleware-CUxJVUpD.js.map +1 -0
  192. package/dist/middleware-Cq0zFMGp.js +253 -0
  193. package/dist/middleware-Cq0zFMGp.js.map +1 -0
  194. package/dist/notifications/index.d.ts +2 -5
  195. package/dist/notifications/index.js +3 -6
  196. package/dist/notifications/index.js.map +1 -1
  197. package/dist/notifications-CdETrtFK.js +869 -0
  198. package/dist/notifications-CdETrtFK.js.map +1 -0
  199. package/dist/observability/index.d.ts +2 -3
  200. package/dist/observability/index.js +3 -4
  201. package/dist/observability/index.js.map +1 -1
  202. package/dist/observability-DBDXipTU.js +272 -0
  203. package/dist/observability-DBDXipTU.js.map +1 -0
  204. package/dist/platform/index.d.ts +2 -1
  205. package/dist/platform/index.js +3 -5
  206. package/dist/platform/index.js.map +1 -1
  207. package/dist/platform-DZwczW7v.js +1510 -0
  208. package/dist/platform-DZwczW7v.js.map +1 -0
  209. package/dist/prisma/generator/index.d.ts +1 -1
  210. package/dist/prisma/generator/index.js +97 -84
  211. package/dist/prisma/generator/index.js.map +1 -1
  212. package/dist/prisma/index.d.ts +4 -7
  213. package/dist/prisma/index.js +5 -12
  214. package/dist/prisma/index.js.map +1 -1
  215. package/dist/prisma-BzOOdt79.js +863 -0
  216. package/dist/prisma-BzOOdt79.js.map +1 -0
  217. package/dist/prisma-extension-Cfl09swM.d.ts +172 -0
  218. package/dist/product-alias/index.d.ts +2 -1
  219. package/dist/product-alias/index.js +3 -3
  220. package/dist/product-alias/index.js.map +1 -1
  221. package/dist/product-alias-BPqtskMq.js +273 -0
  222. package/dist/product-alias-BPqtskMq.js.map +1 -0
  223. package/dist/rbac/index.d.ts +2 -122
  224. package/dist/rbac/index.js +3 -6
  225. package/dist/rbac/index.js.map +1 -1
  226. package/dist/rbac-BB9l9Xph.js +1486 -0
  227. package/dist/rbac-BB9l9Xph.js.map +1 -0
  228. package/dist/resource-caps/index.d.ts +66 -72
  229. package/dist/resource-caps/index.js +430 -5
  230. package/dist/resource-caps/index.js.map +1 -1
  231. package/dist/rolldown-runtime-ad2WFvuA.js +17 -0
  232. package/dist/sdk-Dju9o-sq.js +124 -0
  233. package/dist/sdk-Dju9o-sq.js.map +1 -0
  234. package/dist/security-DIG-95Ic.js +1647 -0
  235. package/dist/security-DIG-95Ic.js.map +1 -0
  236. package/dist/server/index.d.ts +7 -164
  237. package/dist/server/index.js +2000 -1507
  238. package/dist/server/index.js.map +1 -1
  239. package/dist/service-jwt-Bu-WNA_-.js +80 -0
  240. package/dist/service-jwt-Bu-WNA_-.js.map +1 -0
  241. package/dist/services-BWzfz7vG.js +102 -0
  242. package/dist/services-BWzfz7vG.js.map +1 -0
  243. package/dist/sharding/index.d.ts +41 -44
  244. package/dist/sharding/index.js +156 -137
  245. package/dist/sharding/index.js.map +1 -1
  246. package/dist/sharing/index.d.ts +2 -1
  247. package/dist/sharing/index.js +3 -4
  248. package/dist/sharing/index.js.map +1 -1
  249. package/dist/sharing-CflDsSJ-.js +911 -0
  250. package/dist/sharing-CflDsSJ-.js.map +1 -0
  251. package/dist/stub-BqwKn4eh.js +630 -0
  252. package/dist/stub-BqwKn4eh.js.map +1 -0
  253. package/dist/tags/index.d.ts +2 -3
  254. package/dist/tags/index.js +3 -4
  255. package/dist/tags/index.js.map +1 -1
  256. package/dist/tags-B5xpbgsk.js +868 -0
  257. package/dist/{chunk-PBZFAAOM.js.map → tags-B5xpbgsk.js.map} +1 -1
  258. package/dist/telemetry/index.d.ts +64 -76
  259. package/dist/telemetry/index.js +369 -201
  260. package/dist/telemetry/index.js.map +1 -1
  261. package/dist/temporal/index.d.ts +2 -148
  262. package/dist/temporal/index.js +3 -5
  263. package/dist/temporal/index.js.map +1 -1
  264. package/dist/temporal-B534uYK8.js +706 -0
  265. package/dist/temporal-B534uYK8.js.map +1 -0
  266. package/dist/tracker/index.d.ts +5 -11
  267. package/dist/tracker/index.js +5 -20
  268. package/dist/tracker/index.js.map +1 -1
  269. package/dist/tracker-BQVoEFUo.js +839 -0
  270. package/dist/tracker-BQVoEFUo.js.map +1 -0
  271. package/dist/types-BYMYND1L.js +44 -0
  272. package/dist/types-BYMYND1L.js.map +1 -0
  273. package/dist/types-C6EKaS3V.d.ts +106 -0
  274. package/dist/types-CWybW61E.d.ts +323 -0
  275. package/dist/types-C_yfu3XK.d.ts +34 -0
  276. package/dist/types-Cj2RWXbz.js +90 -0
  277. package/dist/types-Cj2RWXbz.js.map +1 -0
  278. package/dist/types-DgaQqvxo.d.ts +70 -0
  279. package/dist/usage/index.d.ts +2 -213
  280. package/dist/usage/index.js +3 -15
  281. package/dist/usage/index.js.map +1 -1
  282. package/dist/usage-BKFZiWQn.js +682 -0
  283. package/dist/usage-BKFZiWQn.js.map +1 -0
  284. package/dist/utils/index.d.ts +2 -1
  285. package/dist/utils/index.js +3 -3
  286. package/dist/utils/index.js.map +1 -1
  287. package/dist/utils-DL85Tnbn.js +500 -0
  288. package/dist/utils-DL85Tnbn.js.map +1 -0
  289. package/dist/validation/index.d.ts +2 -2
  290. package/dist/validation/index.js +3 -3
  291. package/dist/validation/index.js.map +1 -1
  292. package/dist/validation-CPUITdMk.js +762 -0
  293. package/dist/validation-CPUITdMk.js.map +1 -0
  294. package/dist/workspace-extension-COrC0dYi.js +979 -0
  295. package/dist/workspace-extension-COrC0dYi.js.map +1 -0
  296. package/dist/{workspace-extension-BGwTOV_r.d.ts → workspace-extension-DTFTdGVF.d.ts} +43 -45
  297. package/package.json +7 -10
  298. package/dist/EventQueueFactory-PP534MBQ.js +0 -8
  299. package/dist/EventQueueFactory-PP534MBQ.js.map +0 -1
  300. package/dist/chunk-4XIBXZ6J.js +0 -276
  301. package/dist/chunk-4XIBXZ6J.js.map +0 -1
  302. package/dist/chunk-554Z4C2K.js +0 -1006
  303. package/dist/chunk-554Z4C2K.js.map +0 -1
  304. package/dist/chunk-5CAFHK2Z.js +0 -107
  305. package/dist/chunk-5CAFHK2Z.js.map +0 -1
  306. package/dist/chunk-63ZXJ42X.js +0 -451
  307. package/dist/chunk-63ZXJ42X.js.map +0 -1
  308. package/dist/chunk-6XEXJATV.js +0 -304
  309. package/dist/chunk-6XEXJATV.js.map +0 -1
  310. package/dist/chunk-726AR6Q7.js +0 -1532
  311. package/dist/chunk-726AR6Q7.js.map +0 -1
  312. package/dist/chunk-7EISSMFP.js +0 -617
  313. package/dist/chunk-7EISSMFP.js.map +0 -1
  314. package/dist/chunk-A5F6Z5UE.js +0 -21
  315. package/dist/chunk-A5F6Z5UE.js.map +0 -1
  316. package/dist/chunk-A6DE32ZS.js +0 -1507
  317. package/dist/chunk-A6DE32ZS.js.map +0 -1
  318. package/dist/chunk-BJQOGOVW.js +0 -602
  319. package/dist/chunk-BJQOGOVW.js.map +0 -1
  320. package/dist/chunk-CFXWH2IS.js +0 -52
  321. package/dist/chunk-CFXWH2IS.js.map +0 -1
  322. package/dist/chunk-DIOS6L7M.js +0 -690
  323. package/dist/chunk-DIOS6L7M.js.map +0 -1
  324. package/dist/chunk-DJNHR37J.js +0 -1185
  325. package/dist/chunk-DJNHR37J.js.map +0 -1
  326. package/dist/chunk-DRWH5XCJ.js +0 -876
  327. package/dist/chunk-DRWH5XCJ.js.map +0 -1
  328. package/dist/chunk-E4QNLVY4.js +0 -909
  329. package/dist/chunk-E4QNLVY4.js.map +0 -1
  330. package/dist/chunk-E6OAFS7A.js +0 -1346
  331. package/dist/chunk-E6OAFS7A.js.map +0 -1
  332. package/dist/chunk-EBDHIL7V.js +0 -774
  333. package/dist/chunk-EBDHIL7V.js.map +0 -1
  334. package/dist/chunk-ELU7VL3E.js +0 -245
  335. package/dist/chunk-ELU7VL3E.js.map +0 -1
  336. package/dist/chunk-FZRODKIN.js +0 -31
  337. package/dist/chunk-FZRODKIN.js.map +0 -1
  338. package/dist/chunk-GCIB76AJ.js +0 -882
  339. package/dist/chunk-GCIB76AJ.js.map +0 -1
  340. package/dist/chunk-HC6MPUIH.js +0 -1571
  341. package/dist/chunk-HC6MPUIH.js.map +0 -1
  342. package/dist/chunk-I3KOWRT3.js +0 -89
  343. package/dist/chunk-I3KOWRT3.js.map +0 -1
  344. package/dist/chunk-ID3WR4JS.js +0 -509
  345. package/dist/chunk-ID3WR4JS.js.map +0 -1
  346. package/dist/chunk-JVMAQOA3.js +0 -521
  347. package/dist/chunk-JVMAQOA3.js.map +0 -1
  348. package/dist/chunk-K56L7NUR.js +0 -1444
  349. package/dist/chunk-K56L7NUR.js.map +0 -1
  350. package/dist/chunk-KH4TRQCO.js +0 -1063
  351. package/dist/chunk-KH4TRQCO.js.map +0 -1
  352. package/dist/chunk-KJOSPVB2.js +0 -57
  353. package/dist/chunk-KJOSPVB2.js.map +0 -1
  354. package/dist/chunk-KO2ZXZ7W.js +0 -61
  355. package/dist/chunk-KO2ZXZ7W.js.map +0 -1
  356. package/dist/chunk-KS2HQCJR.js +0 -56
  357. package/dist/chunk-KS2HQCJR.js.map +0 -1
  358. package/dist/chunk-LA5KPWZ2.js +0 -413
  359. package/dist/chunk-LA5KPWZ2.js.map +0 -1
  360. package/dist/chunk-MESLAC5W.js +0 -574
  361. package/dist/chunk-MESLAC5W.js.map +0 -1
  362. package/dist/chunk-MWPYA2HD.js +0 -94
  363. package/dist/chunk-MWPYA2HD.js.map +0 -1
  364. package/dist/chunk-NUB5GQTU.js +0 -270
  365. package/dist/chunk-NUB5GQTU.js.map +0 -1
  366. package/dist/chunk-O2JMZHNH.js +0 -1908
  367. package/dist/chunk-O2JMZHNH.js.map +0 -1
  368. package/dist/chunk-OBBCR6WY.js +0 -277
  369. package/dist/chunk-OBBCR6WY.js.map +0 -1
  370. package/dist/chunk-OBZQ4AJC.js +0 -272
  371. package/dist/chunk-OBZQ4AJC.js.map +0 -1
  372. package/dist/chunk-OXNCBE7P.js +0 -971
  373. package/dist/chunk-OXNCBE7P.js.map +0 -1
  374. package/dist/chunk-PBZFAAOM.js +0 -941
  375. package/dist/chunk-PYD44IHJ.js +0 -728
  376. package/dist/chunk-PYD44IHJ.js.map +0 -1
  377. package/dist/chunk-QVPIACWD.js +0 -679
  378. package/dist/chunk-QVPIACWD.js.map +0 -1
  379. package/dist/chunk-QWNNFE4P.js +0 -41
  380. package/dist/chunk-QWNNFE4P.js.map +0 -1
  381. package/dist/chunk-RU266375.js +0 -327
  382. package/dist/chunk-RU266375.js.map +0 -1
  383. package/dist/chunk-RYTSVGGA.js +0 -1624
  384. package/dist/chunk-RYTSVGGA.js.map +0 -1
  385. package/dist/chunk-RZOFS2BQ.js +0 -225
  386. package/dist/chunk-RZOFS2BQ.js.map +0 -1
  387. package/dist/chunk-SBS4S2PJ.js +0 -100
  388. package/dist/chunk-SBS4S2PJ.js.map +0 -1
  389. package/dist/chunk-SPRG6G6G.js +0 -530
  390. package/dist/chunk-SPRG6G6G.js.map +0 -1
  391. package/dist/chunk-STWFX5E2.js +0 -233
  392. package/dist/chunk-STWFX5E2.js.map +0 -1
  393. package/dist/chunk-UNASM5VJ.js +0 -419
  394. package/dist/chunk-UNASM5VJ.js.map +0 -1
  395. package/dist/chunk-VAT66FJA.js +0 -245
  396. package/dist/chunk-VAT66FJA.js.map +0 -1
  397. package/dist/chunk-VFCMR5GX.js +0 -49
  398. package/dist/chunk-VFCMR5GX.js.map +0 -1
  399. package/dist/chunk-VGAHZKNJ.js +0 -66
  400. package/dist/chunk-VGAHZKNJ.js.map +0 -1
  401. package/dist/chunk-VTJTAAXC.js +0 -627
  402. package/dist/chunk-VTJTAAXC.js.map +0 -1
  403. package/dist/chunk-VXVLKRU6.js +0 -758
  404. package/dist/chunk-VXVLKRU6.js.map +0 -1
  405. package/dist/chunk-WWUU5ETI.js +0 -163
  406. package/dist/chunk-WWUU5ETI.js.map +0 -1
  407. package/dist/chunk-XE4OXN2W.js +0 -10
  408. package/dist/chunk-XE4OXN2W.js.map +0 -1
  409. package/dist/chunk-XOJORS75.js +0 -1853
  410. package/dist/chunk-XOJORS75.js.map +0 -1
  411. package/dist/chunk-YMZEUTD2.js +0 -110
  412. package/dist/chunk-YMZEUTD2.js.map +0 -1
  413. package/dist/chunk-ZZK3WEDI.js +0 -181
  414. package/dist/chunk-ZZK3WEDI.js.map +0 -1
  415. package/dist/client-CCXpAZ2r.d.ts +0 -89
  416. package/dist/client-DSI_760t.d.ts +0 -36
  417. package/dist/client-JU6T3UPB.js +0 -11
  418. package/dist/client-JU6T3UPB.js.map +0 -1
  419. package/dist/dist-2X4Q7PJA.js +0 -1491
  420. package/dist/dist-2X4Q7PJA.js.map +0 -1
  421. package/dist/env-4UWSUS64.js +0 -4
  422. package/dist/env-4UWSUS64.js.map +0 -1
  423. package/dist/graph-emitter-r5TylDBm.d.ts +0 -47
  424. package/dist/graphql-CMHMQjvd.d.ts +0 -23
  425. package/dist/i18n-Qm2AkPC-.d.ts +0 -33
  426. package/dist/index--yvpa6ay.d.ts +0 -83
  427. package/dist/index-4gKQKZ2B.d.ts +0 -71
  428. package/dist/index-5x0XMKXN.d.ts +0 -149
  429. package/dist/index-B70b5mYS.d.ts +0 -33
  430. package/dist/index-B8KrxO4j.d.ts +0 -755
  431. package/dist/index-BOuDKnqD.d.ts +0 -201
  432. package/dist/index-BTMt4OjA.d.ts +0 -201
  433. package/dist/index-BejbszA7.d.ts +0 -39
  434. package/dist/index-BkeOYZye.d.ts +0 -198
  435. package/dist/index-BuAj5nXg.d.ts +0 -83
  436. package/dist/index-BvkVcW8I.d.ts +0 -349
  437. package/dist/index-CWmH_-RZ.d.ts +0 -247
  438. package/dist/index-CbgWNcus.d.ts +0 -258
  439. package/dist/index-CmfPeQza.d.ts +0 -166
  440. package/dist/index-CmpG-zak.d.ts +0 -607
  441. package/dist/index-CoMKgL-p.d.ts +0 -12
  442. package/dist/index-D8HGwglK.d.ts +0 -541
  443. package/dist/index-DCaVm66D.d.ts +0 -1101
  444. package/dist/index-DE2w7E0d.d.ts +0 -83
  445. package/dist/index-DSOpj8DI.d.ts +0 -17
  446. package/dist/index-DW9q22GH.d.ts +0 -75
  447. package/dist/index-DnjJ9CwI.d.ts +0 -347
  448. package/dist/index-DwMJZ8PP.d.ts +0 -317
  449. package/dist/index-PaojfSdd.d.ts +0 -71
  450. package/dist/index-aHtYvc3i.d.ts +0 -284
  451. package/dist/index-e_18DzAg.d.ts +0 -18
  452. package/dist/index-ffmipXSA.d.ts +0 -55
  453. package/dist/index-joONjwLt.d.ts +0 -33
  454. package/dist/index-kssw5ziY.d.ts +0 -250
  455. package/dist/index-lFffh5-G.d.ts +0 -125
  456. package/dist/index-pxYge_6k.d.ts +0 -79
  457. package/dist/layer-Cv9vSwBx.d.ts +0 -70
  458. package/dist/pino-logger-H4HPW5P6.js +0 -5
  459. package/dist/pino-logger-H4HPW5P6.js.map +0 -1
  460. package/dist/prisma-extension-gYhYriA0.d.ts +0 -174
  461. package/dist/sdk-L75WWUP3.js +0 -156
  462. package/dist/sdk-L75WWUP3.js.map +0 -1
  463. package/dist/shutdown-registry-CW9LryO8.d.ts +0 -10
  464. package/dist/types-Bo2wkjSP.d.ts +0 -35
  465. package/dist/types-DVpvrAhd.d.ts +0 -71
  466. package/dist/types-DgJ4lDYA.d.ts +0 -108
  467. package/dist/types-USOv09qy.d.ts +0 -327
  468. package/dist/workspace-guard-NXVYYBVJ.js +0 -5
  469. package/dist/workspace-guard-NXVYYBVJ.js.map +0 -1
@@ -1,1853 +0,0 @@
1
- import { currentEnvironment, DEPLOYED_ENVIRONMENTS } from './chunk-A5F6Z5UE.js';
2
- import { registerDisposable, unregisterDisposable } from './chunk-KO2ZXZ7W.js';
3
- import { DEFAULT_LAYER_RESOURCES } from './chunk-5CAFHK2Z.js';
4
- import { logger } from './chunk-RU266375.js';
5
- import { __export, __name } from './chunk-XE4OXN2W.js';
6
-
7
- // src/cache/index.ts
8
- var cache_exports = {};
9
- __export(cache_exports, {
10
- CacheFactory: () => CacheFactory,
11
- CacheProviderType: () => CacheProviderType,
12
- MemoryCacheProvider: () => MemoryCacheProvider,
13
- ValkeyGlideProvider: () => ValkeyGlideProvider,
14
- assertCacheEndpointConfigured: () => assertCacheEndpointConfigured,
15
- closeAllCaches: () => closeAllCaches,
16
- createCache: () => createCache,
17
- getCache: () => getCache,
18
- getValkeyClient: () => getValkeyClient,
19
- warnOnLayerDefaultEndpoint: () => warnOnLayerDefaultEndpoint
20
- });
21
-
22
- // src/cache/endpoint.ts
23
- var LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
24
- "localhost",
25
- "127.0.0.1",
26
- "::1"
27
- ]);
28
- function assertCacheEndpointConfigured(check) {
29
- const url = check.url?.trim();
30
- if (url) return;
31
- const host = check.host?.trim();
32
- if (host && !LOOPBACK_HOSTS.has(host.toLowerCase())) return;
33
- const port = check.port ?? 6379;
34
- const target = `${host || "localhost"}:${port}`;
35
- const credentials = check.password ? "a password" : "NO password";
36
- const detail = `[cache] ${check.context}: no cache endpoint is configured \u2014 none of ${check.keysTried.join(", ")} is set. Falling back to ${target} with ${credentials}. That fallback is silent at startup and surfaces later as a connect that hangs on GLIDE reconnect backoff, starving the event loop and returning 500s under load.`;
37
- const environment = currentEnvironment();
38
- if (DEPLOYED_ENVIRONMENTS.has(environment)) {
39
- throw new Error(`${detail} Refusing to continue with DEPLOY_ENV=${environment}: set VALKEY_URL (or REDIS_URL) in this service's Secrets Manager bundle, boff/${environment}/{layer}/{module}.`);
40
- }
41
- logger.error(detail);
42
- }
43
- __name(assertCacheEndpointConfigured, "assertCacheEndpointConfigured");
44
- function warnOnLayerDefaultEndpoint(context, url, layerDefault) {
45
- if (url !== layerDefault) return;
46
- const environment = currentEnvironment();
47
- if (!DEPLOYED_ENVIRONMENTS.has(environment)) return;
48
- logger.error(`[cache] ${context}: falling back to the local-dev layer default ${layerDefault} with DEPLOY_ENV=${environment}. That hostname does not resolve in a cluster. Set VALKEY_URL or REDIS_URL for this service.`);
49
- }
50
- __name(warnOnLayerDefaultEndpoint, "warnOnLayerDefaultEndpoint");
51
-
52
- // src/cache/implementations/memory/MemoryCacheProvider.ts
53
- var NO_EXPIRY = Number.POSITIVE_INFINITY;
54
- var MemoryCacheProvider = class {
55
- static {
56
- __name(this, "MemoryCacheProvider");
57
- }
58
- cache = /* @__PURE__ */ new Map();
59
- namespace;
60
- defaultTTL;
61
- maxSize;
62
- enableLogging;
63
- connected = false;
64
- // Statistics
65
- stats = {
66
- hits: 0,
67
- misses: 0,
68
- sets: 0,
69
- deletes: 0,
70
- evictions: 0
71
- };
72
- constructor(config, namespace = "default") {
73
- this.namespace = namespace;
74
- this.defaultTTL = config.defaultTTL || 300;
75
- this.maxSize = config.maxSize || 1e3;
76
- this.enableLogging = config.enableLogging ?? false;
77
- this.startCleanupInterval();
78
- }
79
- /**
80
- * Connect (no-op for memory cache)
81
- */
82
- async connect() {
83
- await Promise.resolve();
84
- this.connected = true;
85
- if (this.enableLogging) {
86
- logger.info(`[MemoryCacheProvider:${this.namespace}] Connected (in-memory)`);
87
- }
88
- }
89
- /**
90
- * Disconnect (cleanup)
91
- */
92
- async disconnect() {
93
- await Promise.resolve();
94
- this.connected = false;
95
- this.cache.clear();
96
- if (this.enableLogging) {
97
- logger.info(`[MemoryCacheProvider:${this.namespace}] Disconnected`);
98
- }
99
- }
100
- /**
101
- * Check if connected
102
- */
103
- isConnected() {
104
- return this.connected;
105
- }
106
- /**
107
- * Health check
108
- */
109
- async healthCheck() {
110
- await Promise.resolve();
111
- return {
112
- status: "healthy",
113
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
114
- connected: this.connected,
115
- latencyMs: 0,
116
- details: {
117
- provider: "memory",
118
- cacheSize: this.cache.size,
119
- maxSize: this.maxSize
120
- }
121
- };
122
- }
123
- /**
124
- * Get statistics
125
- */
126
- async getStatistics() {
127
- await Promise.resolve();
128
- const totalOperations = this.stats.hits + this.stats.misses;
129
- const hitRate = totalOperations > 0 ? this.stats.hits / totalOperations : 0;
130
- const memoryUsed = this.cache.size * 500;
131
- return {
132
- hits: this.stats.hits,
133
- misses: this.stats.misses,
134
- hitRate,
135
- keyCount: this.cache.size,
136
- memoryUsed,
137
- totalOperations,
138
- details: {
139
- sets: this.stats.sets,
140
- deletes: this.stats.deletes,
141
- evictions: this.stats.evictions,
142
- maxSize: this.maxSize
143
- }
144
- };
145
- }
146
- /**
147
- * Build cache key with namespace
148
- */
149
- buildKey(key) {
150
- return `${this.namespace}:${key}`;
151
- }
152
- /**
153
- * Check if entry is expired
154
- */
155
- isExpired(expiresAt) {
156
- return Date.now() > expiresAt;
157
- }
158
- /**
159
- * Evict LRU entry if cache is full
160
- */
161
- evictIfNeeded() {
162
- if (this.cache.size >= this.maxSize) {
163
- const firstKey = this.cache.keys().next().value;
164
- if (firstKey) {
165
- this.cache.delete(firstKey);
166
- this.stats.evictions++;
167
- }
168
- }
169
- }
170
- /**
171
- * Cleanup expired entries
172
- */
173
- cleanup() {
174
- let cleaned = 0;
175
- for (const [key, value] of this.cache.entries()) {
176
- if (this.isExpired(value.expiresAt)) {
177
- this.cache.delete(key);
178
- cleaned++;
179
- }
180
- }
181
- if (cleaned > 0 && this.enableLogging) {
182
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cleaned up ${cleaned} expired entries`);
183
- }
184
- }
185
- /**
186
- * Start cleanup interval
187
- */
188
- startCleanupInterval() {
189
- setInterval(() => this.cleanup(), 6e4);
190
- }
191
- /**
192
- * Get value from cache
193
- */
194
- async get(key, _options) {
195
- await Promise.resolve();
196
- const cacheKey = this.buildKey(key);
197
- const cached = this.cache.get(cacheKey);
198
- if (!cached) {
199
- this.stats.misses++;
200
- if (this.enableLogging) {
201
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cache miss`, {
202
- key
203
- });
204
- }
205
- return null;
206
- }
207
- if (this.isExpired(cached.expiresAt)) {
208
- this.cache.delete(cacheKey);
209
- this.stats.misses++;
210
- if (this.enableLogging) {
211
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cache miss (expired)`, {
212
- key
213
- });
214
- }
215
- return null;
216
- }
217
- this.stats.hits++;
218
- if (this.enableLogging) {
219
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cache hit`, {
220
- key
221
- });
222
- }
223
- this.cache.delete(cacheKey);
224
- this.cache.set(cacheKey, cached);
225
- return cached.entry.data;
226
- }
227
- /**
228
- * Set value in cache
229
- */
230
- async set(key, value, options) {
231
- await Promise.resolve();
232
- const cacheKey = this.buildKey(key);
233
- const ttlSeconds = options?.ttl || this.defaultTTL;
234
- this.evictIfNeeded();
235
- const entry = {
236
- data: value,
237
- timestamp: Date.now(),
238
- ttl: ttlSeconds,
239
- metadata: options?.metadata
240
- };
241
- this.cache.set(cacheKey, {
242
- entry,
243
- expiresAt: Date.now() + ttlSeconds * 1e3
244
- });
245
- this.stats.sets++;
246
- if (this.enableLogging) {
247
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cache set`, {
248
- key,
249
- ttl: ttlSeconds
250
- });
251
- }
252
- return true;
253
- }
254
- /**
255
- * Delete value from cache
256
- */
257
- async delete(key) {
258
- await Promise.resolve();
259
- const cacheKey = this.buildKey(key);
260
- const deleted = this.cache.delete(cacheKey);
261
- if (deleted) {
262
- this.stats.deletes++;
263
- if (this.enableLogging) {
264
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Cache delete`, {
265
- key
266
- });
267
- }
268
- }
269
- return deleted;
270
- }
271
- /**
272
- * Check if key exists
273
- */
274
- async has(key) {
275
- await Promise.resolve();
276
- const cacheKey = this.buildKey(key);
277
- const cached = this.cache.get(cacheKey);
278
- if (!cached) {
279
- return false;
280
- }
281
- if (this.isExpired(cached.expiresAt)) {
282
- this.cache.delete(cacheKey);
283
- return false;
284
- }
285
- return true;
286
- }
287
- /**
288
- * Get TTL for key
289
- */
290
- async ttl(key) {
291
- await Promise.resolve();
292
- const cacheKey = this.buildKey(key);
293
- const cached = this.cache.get(cacheKey);
294
- if (!cached) {
295
- return -2;
296
- }
297
- if (cached.expiresAt === NO_EXPIRY) {
298
- return -1;
299
- }
300
- const remaining = Math.floor((cached.expiresAt - Date.now()) / 1e3);
301
- if (remaining <= 0) {
302
- this.cache.delete(cacheKey);
303
- return -2;
304
- }
305
- return remaining;
306
- }
307
- /**
308
- * Update TTL for key
309
- */
310
- async expire(key, ttl) {
311
- await Promise.resolve();
312
- const cacheKey = this.buildKey(key);
313
- const cached = this.cache.get(cacheKey);
314
- if (!cached) {
315
- return false;
316
- }
317
- cached.expiresAt = Date.now() + ttl * 1e3;
318
- cached.entry.ttl = ttl;
319
- return true;
320
- }
321
- /**
322
- * Set TTL for key only if it currently has no TTL (Redis `EXPIRE key ttl NX`).
323
- * Returns true only when the expiry was applied — i.e. the key exists (and is
324
- * not expired) and had no TTL. A key that already has a TTL is left untouched.
325
- */
326
- async expireNX(key, ttlSeconds) {
327
- await Promise.resolve();
328
- const cacheKey = this.buildKey(key);
329
- const cached = this.cache.get(cacheKey);
330
- if (!cached || this.isExpired(cached.expiresAt)) {
331
- return false;
332
- }
333
- if (cached.expiresAt !== NO_EXPIRY) {
334
- return false;
335
- }
336
- cached.expiresAt = Date.now() + ttlSeconds * 1e3;
337
- cached.entry.ttl = ttlSeconds;
338
- return true;
339
- }
340
- /**
341
- * Get multiple values (batch operation)
342
- */
343
- async mget(keys, _options) {
344
- const result = /* @__PURE__ */ new Map();
345
- for (const key of keys) {
346
- const value = await this.get(key);
347
- if (value !== null) {
348
- result.set(key, value);
349
- }
350
- }
351
- return result;
352
- }
353
- /**
354
- * Set multiple values (batch operation)
355
- */
356
- async mset(entries, options) {
357
- for (const [key, value] of entries) {
358
- await this.set(key, value, options);
359
- }
360
- return true;
361
- }
362
- /**
363
- * Delete multiple keys (batch operation)
364
- */
365
- async mdel(keys) {
366
- let deleted = 0;
367
- for (const key of keys) {
368
- const result = await this.delete(key);
369
- if (result) {
370
- deleted++;
371
- }
372
- }
373
- return deleted;
374
- }
375
- /**
376
- * Match key against pattern (supports * wildcard)
377
- */
378
- matchPattern(key, pattern) {
379
- if (!pattern.includes("*")) {
380
- return key === pattern;
381
- }
382
- const parts = pattern.split("*");
383
- let position = 0;
384
- for (let i = 0; i < parts.length; i++) {
385
- const part = parts[i];
386
- if (!part || part === "") continue;
387
- const index = key.indexOf(part, position);
388
- if (index === -1) return false;
389
- if (i === 0 && index !== 0) return false;
390
- position = index + part.length;
391
- }
392
- const lastPart = parts[parts.length - 1];
393
- return !lastPart || lastPart === "" || key.endsWith(lastPart);
394
- }
395
- /**
396
- * Clear keys by pattern
397
- */
398
- async clearPattern(pattern) {
399
- await Promise.resolve();
400
- const searchPattern = this.buildKey(pattern);
401
- let deleted = 0;
402
- for (const key of this.cache.keys()) {
403
- if (this.matchPattern(key, searchPattern)) {
404
- this.cache.delete(key);
405
- deleted++;
406
- }
407
- }
408
- if (this.enableLogging) {
409
- logger.debug(`[MemoryCacheProvider:${this.namespace}] Pattern cleared`, {
410
- pattern,
411
- deleted
412
- });
413
- }
414
- return deleted;
415
- }
416
- /**
417
- * Get keys by pattern
418
- */
419
- async keys(options) {
420
- await Promise.resolve();
421
- const searchPattern = this.buildKey(options.pattern);
422
- const matchedKeys = [];
423
- const prefix = `${this.namespace}:`;
424
- for (const key of this.cache.keys()) {
425
- if (this.matchPattern(key, searchPattern)) {
426
- matchedKeys.push(key.replace(prefix, ""));
427
- }
428
- }
429
- const limitedKeys = options.limit ? matchedKeys.slice(0, options.limit) : matchedKeys;
430
- return {
431
- keys: limitedKeys,
432
- nextCursor: null,
433
- totalCount: matchedKeys.length
434
- };
435
- }
436
- /**
437
- * Clear all keys in namespace
438
- */
439
- async clear() {
440
- await Promise.resolve();
441
- const prefix = `${this.namespace}:`;
442
- let cleared = 0;
443
- for (const key of Array.from(this.cache.keys())) {
444
- if (key.startsWith(prefix)) {
445
- this.cache.delete(key);
446
- cleared++;
447
- }
448
- }
449
- if (this.enableLogging) {
450
- logger.info(`[MemoryCacheProvider:${this.namespace}] Cleared ${cleared} keys`);
451
- }
452
- return true;
453
- }
454
- /**
455
- * Increment numeric value.
456
- *
457
- * Mirrors Redis `INCRBY`: a missing key is created with NO expiry
458
- * (persistent), and an existing key's TTL is preserved (never reset). This
459
- * keeps the `increment` + `expireNX` fixed-window pattern behaving
460
- * identically to the valkey-glide provider.
461
- */
462
- async increment(key, amount = 1) {
463
- return this.applyDelta(key, amount);
464
- }
465
- /**
466
- * Decrement numeric value. Mirrors Redis `DECRBY` (see {@link increment}).
467
- */
468
- async decrement(key, amount = 1) {
469
- return this.applyDelta(key, -amount);
470
- }
471
- /**
472
- * Shared INCRBY/DECRBY core: preserve an existing key's TTL, create a missing
473
- * key with no expiry.
474
- */
475
- async applyDelta(key, delta) {
476
- await Promise.resolve();
477
- const cacheKey = this.buildKey(key);
478
- const existing = this.cache.get(cacheKey);
479
- const alive = existing && !this.isExpired(existing.expiresAt) ? existing : void 0;
480
- const parsed = alive ? Number(alive.entry.data) : 0;
481
- const base = Number.isFinite(parsed) ? parsed : 0;
482
- const newValue = base + delta;
483
- if (alive) {
484
- alive.entry.data = newValue;
485
- alive.entry.timestamp = Date.now();
486
- } else {
487
- if (existing) {
488
- this.cache.delete(cacheKey);
489
- }
490
- this.evictIfNeeded();
491
- this.cache.set(cacheKey, {
492
- entry: {
493
- data: newValue,
494
- timestamp: Date.now(),
495
- ttl: 0
496
- },
497
- expiresAt: NO_EXPIRY
498
- });
499
- }
500
- this.stats.sets++;
501
- return newValue;
502
- }
503
- /**
504
- * Get or set value
505
- */
506
- async getOrSet(key, fetcher, options) {
507
- const cached = await this.get(key, options);
508
- if (cached !== null) {
509
- return cached;
510
- }
511
- const value = await fetcher();
512
- await this.set(key, value, options);
513
- return value;
514
- }
515
- /**
516
- * Invalidate by tags
517
- */
518
- async invalidateTags(tags) {
519
- let totalDeleted = 0;
520
- for (const tag of tags) {
521
- const pattern = `*:tag:${tag}:*`;
522
- const deleted = await this.clearPattern(pattern);
523
- totalDeleted += deleted;
524
- }
525
- return totalDeleted;
526
- }
527
- };
528
-
529
- // src/cache/implementations/valkey/ValkeyGlideProvider.ts
530
- function readPositiveIntEnv(name, fallback) {
531
- const raw = process.env[name];
532
- if (!raw) return fallback;
533
- const parsed = parseInt(raw, 10);
534
- return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
535
- }
536
- __name(readPositiveIntEnv, "readPositiveIntEnv");
537
- var CONNECT_RETRY_COOLDOWN_MS = readPositiveIntEnv("VALKEY_CONNECT_RETRY_COOLDOWN_MS", 8e3);
538
- var CONNECT_ATTEMPT_TIMEOUT_MS = readPositiveIntEnv("VALKEY_CONNECT_ATTEMPT_TIMEOUT_MS", 4500);
539
- var CONNECTION_TIMEOUT_MS = readPositiveIntEnv("VALKEY_CONNECTION_TIMEOUT_MS", 4e3);
540
- var REQUEST_TIMEOUT_MS = readPositiveIntEnv("VALKEY_REQUEST_TIMEOUT_MS", 2e3);
541
- var MAX_CONSECUTIVE_OP_FAILURES = readPositiveIntEnv("VALKEY_MAX_CONSECUTIVE_OP_FAILURES", 3);
542
- var COOLDOWN_LOG_INTERVAL_MS = readPositiveIntEnv("VALKEY_COOLDOWN_LOG_INTERVAL_MS", 3e4);
543
- function isConnectionLevelError(error) {
544
- if (!(error instanceof Error)) return false;
545
- const name = error.name;
546
- if (name === "ClosingError" || name === "ConnectionError" || name === "TimeoutError") {
547
- return true;
548
- }
549
- const message = error.message.toLowerCase();
550
- if (message.includes("cooldown") || message.includes("budget")) {
551
- return false;
552
- }
553
- return /connection|closing|closed|timed out|timeout|disconnect|socket|econnreset|broken pipe|not connected/.test(message);
554
- }
555
- __name(isConnectionLevelError, "isConnectionLevelError");
556
- var ValkeyGlideProvider = class {
557
- static {
558
- __name(this, "ValkeyGlideProvider");
559
- }
560
- client = null;
561
- clusterScanCursor = null;
562
- clientIsCluster = false;
563
- connected = false;
564
- // Single in-flight connect promise so concurrent first-time `get/set` calls
565
- // share one connect attempt instead of racing into N parallel `createClient`
566
- // invocations. Reset to `null` after connect resolves/rejects so the next
567
- // call after an explicit disconnect() (or a connect failure) can retry.
568
- connectPromise = null;
569
- // Timestamp (ms) of the last failed connect attempt; 0 when the last attempt
570
- // succeeded. Drives the connect circuit-breaker in ensureConnected().
571
- lastConnectFailureAt = 0;
572
- // Count of consecutive connection-level operation failures on an already-
573
- // "connected" client, tracked across every command (any success resets it,
574
- // any op's connection error increments it). When it reaches
575
- // MAX_CONSECUTIVE_OP_FAILURES the wedged client is torn down so the next op
576
- // rebuilds a fresh one instead of reusing a socket GLIDE's internal reconnect
577
- // cannot recover. See noteOpError().
578
- consecutiveOpFailures = 0;
579
- // Timestamp (ms) of the last logged cooldown fast-fail; throttles the
580
- // per-op "connect in cooldown" logging to once per COOLDOWN_LOG_INTERVAL_MS.
581
- lastCooldownLogAt = 0;
582
- config;
583
- // Mutable: when a URL like `…/4` lands on Azure Managed Redis we fold the
584
- // DB index into the namespace at connect time to preserve per-service
585
- // isolation on the forced-DB-0 connection. Appended exactly once across the
586
- // instance's lifetime, guarded by `dbNamespaceSuffixApplied` (connect() can
587
- // run repeatedly now that the self-heal path rebuilds the client).
588
- namespace;
589
- // Set once the Azure DB-index `:db{N}` suffix has been folded into
590
- // `namespace`, so reconnects do not re-append it.
591
- dbNamespaceSuffixApplied = false;
592
- defaultTTL;
593
- enableLogging;
594
- // Statistics
595
- stats = {
596
- hits: 0,
597
- misses: 0,
598
- sets: 0,
599
- deletes: 0,
600
- errors: 0
601
- };
602
- constructor(config, namespace = "default") {
603
- this.config = config;
604
- this.namespace = namespace;
605
- this.defaultTTL = config.defaultTTL || 300;
606
- this.enableLogging = config.enableLogging ?? process.env["NODE_ENV"] === "development";
607
- }
608
- async serverReportsCluster(client) {
609
- try {
610
- const info = await client.info("cluster");
611
- return /(?:^|\n)cluster_enabled:1(?:\r?\n|$)/.test(info);
612
- } catch {
613
- return false;
614
- }
615
- }
616
- async scanClusterKeys(pattern) {
617
- if (!this.client || !this.clientIsCluster || !this.clusterScanCursor) {
618
- return [];
619
- }
620
- const clusterClient = this.client;
621
- let cursor = new this.clusterScanCursor();
622
- const keys = [];
623
- do {
624
- const [nextCursor, batch] = await clusterClient.scan(cursor, {
625
- match: pattern,
626
- count: 1e3
627
- });
628
- keys.push(...batch);
629
- cursor = nextCursor;
630
- } while (!cursor.isFinished());
631
- return keys;
632
- }
633
- async getKeys(pattern) {
634
- const client = await this.ensureConnected();
635
- if (this.clientIsCluster) {
636
- return this.scanClusterKeys(pattern);
637
- }
638
- const standaloneClient = client;
639
- let cursor = "0";
640
- const keys = /* @__PURE__ */ new Set();
641
- let pages = 0;
642
- do {
643
- const [nextCursor, batch] = await standaloneClient.scan(cursor, {
644
- match: pattern,
645
- count: 1e3,
646
- decoder: 1
647
- });
648
- for (const key of batch) {
649
- if (!key.startsWith(`${this.namespace}:`)) throw new Error("Valkey SCAN returned a key outside the namespace");
650
- keys.add(key);
651
- }
652
- pages++;
653
- if (pages > 1e4 || keys.size > 1e5) throw new Error("Valkey namespace SCAN exceeded its safety budget");
654
- cursor = nextCursor;
655
- } while (cursor !== "0");
656
- return [
657
- ...keys
658
- ];
659
- }
660
- /**
661
- * Connect to Valkey server using @valkey/valkey-glide
662
- */
663
- /**
664
- * Lazy-connect helper used by every public operation so callers can just do
665
- * `const cache = createCache('x'); await cache.set(...)` without an explicit
666
- * `await cache.connect()`. Multiple concurrent ops share the same in-flight
667
- * connect promise.
668
- */
669
- async ensureConnected() {
670
- if (!(this.connected && this.client)) {
671
- if (!this.connectPromise && this.lastConnectFailureAt > 0) {
672
- const sinceFailureMs = Date.now() - this.lastConnectFailureAt;
673
- if (sinceFailureMs < CONNECT_RETRY_COOLDOWN_MS) {
674
- throw new Error("Valkey connect in cooldown after a recent failure");
675
- }
676
- }
677
- if (!this.connectPromise) {
678
- this.connectPromise = this.connect().finally(() => {
679
- this.connectPromise = null;
680
- });
681
- }
682
- await this.connectPromise;
683
- }
684
- if (!this.client) {
685
- throw new Error("Valkey client connect failed");
686
- }
687
- return this.client;
688
- }
689
- /**
690
- * Race a GLIDE `createClient` promise against {@link CONNECT_ATTEMPT_TIMEOUT_MS}
691
- * so a stalled connect can never block the calling resolver (and the pg
692
- * connection it may be holding) longer than the budget. On timeout the
693
- * underlying connect is abandoned but not left dangling: if it later resolves
694
- * we close the orphaned client to avoid leaking a socket. The thrown error
695
- * propagates to `connect()`'s catch, which arms the circuit-breaker so
696
- * subsequent ops fast-fail (cache miss) during the cooldown.
697
- */
698
- async withConnectBudget(pending) {
699
- let timer;
700
- const timeout = new Promise((_, reject) => {
701
- timer = setTimeout(() => reject(new Error(`Valkey connect exceeded ${String(CONNECT_ATTEMPT_TIMEOUT_MS)}ms budget`)), CONNECT_ATTEMPT_TIMEOUT_MS);
702
- });
703
- try {
704
- return await Promise.race([
705
- pending,
706
- timeout
707
- ]);
708
- } catch (error) {
709
- void pending.then((client) => {
710
- void client.close().catch(() => void 0);
711
- }, () => void 0);
712
- throw error;
713
- } finally {
714
- if (timer) {
715
- clearTimeout(timer);
716
- }
717
- }
718
- }
719
- async connect() {
720
- if (this.connected && this.client) {
721
- return;
722
- }
723
- try {
724
- let glideModule;
725
- try {
726
- glideModule = await import('@valkey/valkey-glide');
727
- } catch (importError) {
728
- throw new Error(`@valkey/valkey-glide is not installed \u2014 the Valkey cache is DISABLED and every cache op degrades to a miss (import failed: ${importError instanceof Error ? importError.message : String(importError)})`);
729
- }
730
- const GlideClient = glideModule.GlideClient || glideModule.default;
731
- const GlideClusterClient = glideModule.GlideClusterClient;
732
- this.clusterScanCursor = glideModule.ClusterScanCursor ?? null;
733
- if (!GlideClient) {
734
- throw new Error("Valkey GLIDE standalone client is unavailable");
735
- }
736
- let host = this.config.host || "localhost";
737
- let port = this.config.port || 6379;
738
- let password = this.config.password;
739
- let username = this.config.username;
740
- let useTLSFromUrl;
741
- let databaseFromUrl;
742
- if (this.config.url) {
743
- const rawUrl = this.config.url;
744
- useTLSFromUrl = /^(rediss|valkeys):\/\//i.test(rawUrl);
745
- const url = new URL(rawUrl.replace(/^valkey:\/\//i, "redis://").replace(/^valkeys:\/\//i, "rediss://"));
746
- host = url.hostname;
747
- port = parseInt(url.port || "6379", 10);
748
- if (!password && url.password) {
749
- try {
750
- password = decodeURIComponent(url.password);
751
- } catch {
752
- password = url.password;
753
- }
754
- }
755
- if (!username && url.username) {
756
- try {
757
- username = decodeURIComponent(url.username);
758
- } catch {
759
- username = url.username;
760
- }
761
- }
762
- const dbMatch = /^\/(\d+)$/.exec(url.pathname);
763
- if (dbMatch && dbMatch[1]) {
764
- databaseFromUrl = parseInt(dbMatch[1], 10);
765
- const isAzureManagedRedis = /\.redis\.azure\.net$/i.test(host);
766
- if (isAzureManagedRedis && databaseFromUrl > 0) {
767
- if (!this.dbNamespaceSuffixApplied) {
768
- logger.warn(`[ValkeyGlideProvider] Azure Managed Redis only supports DB 0; ignoring /${String(databaseFromUrl)} in URL and folding it into namespace.`);
769
- this.namespace = `${this.namespace}:db${String(databaseFromUrl)}`;
770
- this.dbNamespaceSuffixApplied = true;
771
- }
772
- databaseFromUrl = 0;
773
- }
774
- }
775
- }
776
- const addresses = this.config.clusterNodes?.length ? this.config.clusterNodes : [
777
- {
778
- host,
779
- port
780
- }
781
- ];
782
- const baseClientConfig = {
783
- addresses,
784
- useTLS: this.config.useTLS ?? useTLSFromUrl,
785
- credentials: password || username ? {
786
- password,
787
- username
788
- } : void 0,
789
- clientName: this.config.name || `valkey-glide-${this.namespace}`,
790
- databaseId: this.config.db ?? databaseFromUrl,
791
- // Bound every command (incl. reconnection during the request) so a
792
- // dropped/reconnecting socket fails fast to a cache miss instead of
793
- // hanging the calling resolver. THE fix for the "glide hangs" failure.
794
- requestTimeout: REQUEST_TIMEOUT_MS,
795
- // Honour the configured reconnect tuning. Previously
796
- // maxReconnectAttempts/reconnectTimeWait were read into config but never
797
- // handed to GLIDE, so the client used its built-in default backoff. A
798
- // dropped connection now recovers on an exponential schedule seeded by
799
- // reconnectTimeWait, capped after numberOfRetries attempts.
800
- connectionBackoff: {
801
- numberOfRetries: this.config.maxReconnectAttempts && this.config.maxReconnectAttempts > 0 ? this.config.maxReconnectAttempts : 5,
802
- factor: this.config.reconnectTimeWait ?? 1e3,
803
- exponentBase: 2
804
- },
805
- readFrom: "primary",
806
- // GLIDE 2.x reads connectionTimeout from advancedConfiguration; a
807
- // top-level value is ignored. Bounds the initial connect and every
808
- // internal reconnect.
809
- advancedConfiguration: {
810
- connectionTimeout: this.config.connectionTimeout ?? CONNECTION_TIMEOUT_MS
811
- }
812
- };
813
- if (this.config.cluster === true) {
814
- if (!GlideClusterClient) {
815
- throw new Error("Valkey GLIDE cluster client is unavailable");
816
- }
817
- this.client = await this.withConnectBudget(GlideClusterClient.createClient({
818
- ...baseClientConfig,
819
- periodicChecks: {
820
- duration_in_sec: 30
821
- },
822
- advancedConfiguration: {
823
- ...baseClientConfig.advancedConfiguration,
824
- refreshTopologyFromInitialNodes: true
825
- }
826
- }));
827
- this.clientIsCluster = true;
828
- } else {
829
- const standaloneClient = await this.withConnectBudget(GlideClient.createClient(baseClientConfig));
830
- if (this.config.cluster !== false && await this.serverReportsCluster(standaloneClient)) {
831
- if (!GlideClusterClient) {
832
- throw new Error("Valkey server is clustered but GLIDE cluster client is unavailable");
833
- }
834
- await standaloneClient.close();
835
- this.client = await this.withConnectBudget(GlideClusterClient.createClient({
836
- ...baseClientConfig,
837
- periodicChecks: {
838
- duration_in_sec: 30
839
- },
840
- advancedConfiguration: {
841
- ...baseClientConfig.advancedConfiguration,
842
- refreshTopologyFromInitialNodes: true
843
- }
844
- }));
845
- this.clientIsCluster = true;
846
- } else {
847
- this.client = standaloneClient;
848
- this.clientIsCluster = false;
849
- }
850
- }
851
- this.connected = true;
852
- this.lastConnectFailureAt = 0;
853
- this.consecutiveOpFailures = 0;
854
- registerDisposable(this);
855
- if (this.enableLogging) {
856
- logger.info(`[ValkeyGlideProvider:${this.namespace}] Connected to Valkey`, {
857
- host,
858
- port,
859
- cluster: this.clientIsCluster
860
- });
861
- }
862
- } catch (error) {
863
- this.stats.errors++;
864
- this.lastConnectFailureAt = Date.now();
865
- const normalized = error instanceof Error ? error : new Error(String(error));
866
- logger.error(`[ValkeyGlideProvider:${this.namespace}] Failed to connect:`, normalized);
867
- throw normalized;
868
- }
869
- }
870
- /**
871
- * Disconnect from Valkey server
872
- */
873
- /** Label for the graceful-shutdown registry. */
874
- get shutdownName() {
875
- return `valkey-cache:${this.namespace}`;
876
- }
877
- /** Close the client on graceful shutdown. */
878
- dispose() {
879
- return this.disconnect();
880
- }
881
- async disconnect() {
882
- unregisterDisposable(this);
883
- if (this.client) {
884
- await this.client.close();
885
- this.client = null;
886
- this.clientIsCluster = false;
887
- this.connected = false;
888
- this.lastConnectFailureAt = 0;
889
- if (this.enableLogging) {
890
- logger.info(`[ValkeyGlideProvider:${this.namespace}] Disconnected`);
891
- }
892
- }
893
- }
894
- /**
895
- * A command completed — the connection is proven alive, so clear the
896
- * teardown counter. Called from every command's success path.
897
- */
898
- recordOpSuccess() {
899
- if (this.consecutiveOpFailures !== 0) {
900
- this.consecutiveOpFailures = 0;
901
- }
902
- }
903
- /**
904
- * Record an operation error and, if the client looks wedged (enough
905
- * consecutive connection-level failures), tear it down so the next op builds a
906
- * fresh one. Non-connection errors (bad command, serialization) are ignored so
907
- * they never trip the teardown.
908
- */
909
- noteOpError(error) {
910
- if (!isConnectionLevelError(error)) {
911
- return;
912
- }
913
- this.consecutiveOpFailures += 1;
914
- if (this.consecutiveOpFailures >= MAX_CONSECUTIVE_OP_FAILURES) {
915
- this.resetClientForReconnect();
916
- }
917
- }
918
- /**
919
- * Log an operation error, throttling the breaker's own cooldown fast-fail.
920
- * While the connect circuit-breaker is armed every op fails with the same
921
- * "connect in cooldown" error; those are expected (the op has already
922
- * degraded to a cache miss) and are summarized at most once per
923
- * COOLDOWN_LOG_INTERVAL_MS instead of stack-traced per call. Any other error
924
- * logs at error level unthrottled.
925
- */
926
- logOpError(what, error) {
927
- if (error instanceof Error && error.message.includes("connect in cooldown")) {
928
- const now = Date.now();
929
- if (now - this.lastCooldownLogAt < COOLDOWN_LOG_INTERVAL_MS) {
930
- return;
931
- }
932
- this.lastCooldownLogAt = now;
933
- logger.warn(`[ValkeyGlideProvider:${this.namespace}] Valkey unavailable (connect circuit-breaker armed); ops are degrading to cache misses. Further cooldown fast-fails are suppressed for ${String(COOLDOWN_LOG_INTERVAL_MS)}ms \u2014 see the preceding "Failed to connect" log for the root cause.`);
934
- return;
935
- }
936
- logger.error(`[ValkeyGlideProvider:${this.namespace}] ${what}:`, error);
937
- }
938
- /**
939
- * Drop the current client so the next ensureConnected() creates a new one.
940
- * Arms the connect circuit-breaker so ops fast-fail (cache miss) during the
941
- * cooldown rather than racing a fresh connect on every call, and closes the
942
- * dead client in the background so its socket is not leaked.
943
- */
944
- resetClientForReconnect() {
945
- const dead = this.client;
946
- this.client = null;
947
- this.connected = false;
948
- this.consecutiveOpFailures = 0;
949
- this.lastConnectFailureAt = Date.now();
950
- logger.warn(`[ValkeyGlideProvider:${this.namespace}] Tearing down wedged client after ${String(MAX_CONSECUTIVE_OP_FAILURES)} consecutive connection failures; rebuilding on next op`);
951
- if (dead) {
952
- void dead.close().catch(() => void 0);
953
- }
954
- }
955
- /**
956
- * Check if connected
957
- */
958
- isConnected() {
959
- return this.connected && this.client !== null;
960
- }
961
- /**
962
- * Health check
963
- */
964
- async healthCheck() {
965
- const startTime = Date.now();
966
- try {
967
- if (!this.client) {
968
- return {
969
- status: "unhealthy",
970
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
971
- connected: false,
972
- error: "Not connected"
973
- };
974
- }
975
- const result = await this.client.ping();
976
- const latencyMs = Date.now() - startTime;
977
- if (result === "PONG") {
978
- return {
979
- status: "healthy",
980
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
981
- connected: true,
982
- latencyMs
983
- };
984
- }
985
- return {
986
- status: "unhealthy",
987
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
988
- connected: false,
989
- error: "Unexpected ping response"
990
- };
991
- } catch (error) {
992
- return {
993
- status: "unhealthy",
994
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
995
- connected: false,
996
- error: error instanceof Error ? error.message : "Unknown error",
997
- latencyMs: Date.now() - startTime
998
- };
999
- }
1000
- }
1001
- /**
1002
- * Get statistics
1003
- */
1004
- async getStatistics() {
1005
- const totalOperations = this.stats.hits + this.stats.misses;
1006
- const hitRate = totalOperations > 0 ? this.stats.hits / totalOperations : 0;
1007
- try {
1008
- const client = await this.ensureConnected();
1009
- const info = await client.info("memory");
1010
- const memoryRegex = /used_memory:(\d+)/;
1011
- const memoryMatch = memoryRegex.exec(info);
1012
- const memoryUsed = memoryMatch && memoryMatch[1] ? parseInt(memoryMatch[1], 10) : void 0;
1013
- const keyCount = await client.dbsize();
1014
- this.recordOpSuccess();
1015
- return {
1016
- hits: this.stats.hits,
1017
- misses: this.stats.misses,
1018
- hitRate,
1019
- keyCount,
1020
- memoryUsed,
1021
- totalOperations,
1022
- details: {
1023
- sets: this.stats.sets,
1024
- deletes: this.stats.deletes,
1025
- errors: this.stats.errors
1026
- }
1027
- };
1028
- } catch (error) {
1029
- this.noteOpError(error);
1030
- this.logOpError("Failed to get statistics", error);
1031
- return {
1032
- hits: this.stats.hits,
1033
- misses: this.stats.misses,
1034
- hitRate,
1035
- totalOperations,
1036
- details: {
1037
- sets: this.stats.sets,
1038
- deletes: this.stats.deletes,
1039
- errors: this.stats.errors
1040
- }
1041
- };
1042
- }
1043
- }
1044
- /**
1045
- * Build cache key with namespace
1046
- */
1047
- buildKey(key) {
1048
- return `${this.namespace}:${key}`;
1049
- }
1050
- buildPattern(pattern) {
1051
- const namespace = this.namespace.replace(/[\\*?[\]]/g, "\\$&");
1052
- return `${namespace}:${pattern}`;
1053
- }
1054
- /**
1055
- * Get value from cache
1056
- */
1057
- async get(key, _options) {
1058
- try {
1059
- const client = await this.ensureConnected();
1060
- const cacheKey = this.buildKey(key);
1061
- const value = await client.get(cacheKey);
1062
- this.recordOpSuccess();
1063
- if (value === null) {
1064
- this.stats.misses++;
1065
- if (this.enableLogging) {
1066
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Cache miss`, {
1067
- key
1068
- });
1069
- }
1070
- return null;
1071
- }
1072
- this.stats.hits++;
1073
- if (this.enableLogging) {
1074
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Cache hit`, {
1075
- key
1076
- });
1077
- }
1078
- const entry = JSON.parse(value);
1079
- return entry.data;
1080
- } catch (error) {
1081
- this.stats.errors++;
1082
- this.noteOpError(error);
1083
- this.logOpError("Error getting cache key", error);
1084
- return null;
1085
- }
1086
- }
1087
- /**
1088
- * Set value in cache
1089
- */
1090
- async set(key, value, options) {
1091
- try {
1092
- const client = await this.ensureConnected();
1093
- const cacheKey = this.buildKey(key);
1094
- const ttlSeconds = options?.ttl || this.defaultTTL;
1095
- const entry = {
1096
- data: value,
1097
- timestamp: Date.now(),
1098
- ttl: ttlSeconds,
1099
- metadata: options?.metadata
1100
- };
1101
- await client.set(cacheKey, JSON.stringify(entry), {
1102
- expiry: {
1103
- type: "EX",
1104
- count: ttlSeconds
1105
- }
1106
- });
1107
- this.recordOpSuccess();
1108
- this.stats.sets++;
1109
- if (this.enableLogging) {
1110
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Cache set`, {
1111
- key,
1112
- ttl: ttlSeconds
1113
- });
1114
- }
1115
- return true;
1116
- } catch (error) {
1117
- this.stats.errors++;
1118
- this.noteOpError(error);
1119
- this.logOpError("Error setting cache key", error);
1120
- return false;
1121
- }
1122
- }
1123
- /**
1124
- * Delete value from cache
1125
- */
1126
- async delete(key) {
1127
- try {
1128
- const client = await this.ensureConnected();
1129
- const cacheKey = this.buildKey(key);
1130
- const result = await client.del([
1131
- cacheKey
1132
- ]);
1133
- this.recordOpSuccess();
1134
- this.stats.deletes++;
1135
- if (this.enableLogging) {
1136
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Cache delete`, {
1137
- key,
1138
- deleted: result > 0
1139
- });
1140
- }
1141
- return result > 0;
1142
- } catch (error) {
1143
- this.stats.errors++;
1144
- this.noteOpError(error);
1145
- this.logOpError("Error deleting cache key", error);
1146
- return false;
1147
- }
1148
- }
1149
- /**
1150
- * Check if key exists
1151
- */
1152
- async has(key) {
1153
- try {
1154
- const client = await this.ensureConnected();
1155
- const cacheKey = this.buildKey(key);
1156
- const exists = await client.exists([
1157
- cacheKey
1158
- ]);
1159
- this.recordOpSuccess();
1160
- return exists === 1;
1161
- } catch (error) {
1162
- this.stats.errors++;
1163
- this.noteOpError(error);
1164
- this.logOpError("Error checking cache key", error);
1165
- return false;
1166
- }
1167
- }
1168
- /**
1169
- * Get TTL for key
1170
- */
1171
- async ttl(key) {
1172
- try {
1173
- const client = await this.ensureConnected();
1174
- const cacheKey = this.buildKey(key);
1175
- const result = await client.ttl(cacheKey);
1176
- this.recordOpSuccess();
1177
- return result;
1178
- } catch (error) {
1179
- this.stats.errors++;
1180
- this.noteOpError(error);
1181
- this.logOpError("Error getting TTL", error);
1182
- return -2;
1183
- }
1184
- }
1185
- /**
1186
- * Update TTL for key
1187
- */
1188
- async expire(key, ttl) {
1189
- try {
1190
- const client = await this.ensureConnected();
1191
- const cacheKey = this.buildKey(key);
1192
- const result = await client.expire(cacheKey, ttl);
1193
- this.recordOpSuccess();
1194
- return result;
1195
- } catch (error) {
1196
- this.stats.errors++;
1197
- this.noteOpError(error);
1198
- this.logOpError("Error setting expiration", error);
1199
- return false;
1200
- }
1201
- }
1202
- /**
1203
- * Set TTL for a key only if it currently has no TTL (`EXPIRE key ttl NX`).
1204
- * Atomic server-side. Returns true only when the expiry was applied.
1205
- */
1206
- async expireNX(key, ttlSeconds) {
1207
- try {
1208
- const client = await this.ensureConnected();
1209
- const cacheKey = this.buildKey(key);
1210
- const result = await client.expire(cacheKey, ttlSeconds, {
1211
- expireOption: "NX"
1212
- });
1213
- this.recordOpSuccess();
1214
- return result === true;
1215
- } catch (error) {
1216
- this.stats.errors++;
1217
- this.noteOpError(error);
1218
- this.logOpError("Error setting NX expiration", error);
1219
- return false;
1220
- }
1221
- }
1222
- /**
1223
- * Get multiple values (batch operation)
1224
- */
1225
- async mget(keys, _options) {
1226
- const result = /* @__PURE__ */ new Map();
1227
- if (keys.length === 0) {
1228
- return result;
1229
- }
1230
- try {
1231
- const client = await this.ensureConnected();
1232
- const cacheKeys = keys.map((key) => this.buildKey(key));
1233
- const values = await client.mget(cacheKeys);
1234
- this.recordOpSuccess();
1235
- for (let i = 0; i < keys.length; i++) {
1236
- const key = keys[i];
1237
- if (!key) continue;
1238
- if (values[i] !== null) {
1239
- const entry = JSON.parse(values[i]);
1240
- result.set(key, entry.data);
1241
- this.stats.hits++;
1242
- } else {
1243
- this.stats.misses++;
1244
- }
1245
- }
1246
- if (this.enableLogging) {
1247
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Batch get`, {
1248
- requested: keys.length,
1249
- found: result.size
1250
- });
1251
- }
1252
- return result;
1253
- } catch (error) {
1254
- this.stats.errors++;
1255
- this.noteOpError(error);
1256
- this.logOpError("Error in batch get", error);
1257
- return result;
1258
- }
1259
- }
1260
- /**
1261
- * Set multiple values (batch operation)
1262
- */
1263
- async mset(entries, options) {
1264
- if (entries.size === 0) {
1265
- return true;
1266
- }
1267
- try {
1268
- const client = await this.ensureConnected();
1269
- const ttlSeconds = options?.ttl || this.defaultTTL;
1270
- const keyValuePairs = {};
1271
- for (const [key, value] of entries) {
1272
- const cacheKey = this.buildKey(key);
1273
- const entry = {
1274
- data: value,
1275
- timestamp: Date.now(),
1276
- ttl: ttlSeconds,
1277
- metadata: options?.metadata
1278
- };
1279
- keyValuePairs[cacheKey] = JSON.stringify(entry);
1280
- }
1281
- await client.mset(keyValuePairs);
1282
- this.recordOpSuccess();
1283
- for (const cacheKey of Object.keys(keyValuePairs)) {
1284
- await client.expire(cacheKey, ttlSeconds);
1285
- }
1286
- this.stats.sets += entries.size;
1287
- if (this.enableLogging) {
1288
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Batch set`, {
1289
- count: entries.size,
1290
- ttl: ttlSeconds
1291
- });
1292
- }
1293
- return true;
1294
- } catch (error) {
1295
- this.stats.errors++;
1296
- this.noteOpError(error);
1297
- this.logOpError("Error in batch set", error);
1298
- return false;
1299
- }
1300
- }
1301
- /**
1302
- * Delete multiple keys (batch operation)
1303
- */
1304
- async mdel(keys) {
1305
- if (keys.length === 0) {
1306
- return 0;
1307
- }
1308
- try {
1309
- const client = await this.ensureConnected();
1310
- const cacheKeys = keys.map((key) => this.buildKey(key));
1311
- const result = await client.del(cacheKeys);
1312
- this.recordOpSuccess();
1313
- this.stats.deletes += result;
1314
- if (this.enableLogging) {
1315
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Batch delete`, {
1316
- requested: keys.length,
1317
- deleted: result
1318
- });
1319
- }
1320
- return result;
1321
- } catch (error) {
1322
- this.stats.errors++;
1323
- this.noteOpError(error);
1324
- this.logOpError("Error in batch delete", error);
1325
- return 0;
1326
- }
1327
- }
1328
- /**
1329
- * Clear keys by pattern
1330
- */
1331
- async clearPattern(pattern) {
1332
- try {
1333
- const client = await this.ensureConnected();
1334
- const searchPattern = this.buildPattern(pattern);
1335
- const keys = await this.getKeys(searchPattern);
1336
- if (keys.length === 0) {
1337
- this.recordOpSuccess();
1338
- return 0;
1339
- }
1340
- let result = 0;
1341
- const uniqueKeys = [
1342
- ...new Set(keys)
1343
- ];
1344
- for (let offset = 0; offset < uniqueKeys.length; offset += 1e3) {
1345
- result += await client.del(uniqueKeys.slice(offset, offset + 1e3));
1346
- }
1347
- this.recordOpSuccess();
1348
- if (this.enableLogging) {
1349
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Pattern cleared`, {
1350
- pattern,
1351
- deleted: result
1352
- });
1353
- }
1354
- return result;
1355
- } catch (error) {
1356
- this.stats.errors++;
1357
- this.noteOpError(error);
1358
- this.logOpError("Error clearing pattern", error);
1359
- throw error;
1360
- }
1361
- }
1362
- /**
1363
- * Get keys by pattern
1364
- */
1365
- async keys(options) {
1366
- try {
1367
- await this.ensureConnected();
1368
- const searchPattern = this.buildPattern(options.pattern);
1369
- const keys = await this.getKeys(searchPattern);
1370
- this.recordOpSuccess();
1371
- const prefix = `${this.namespace}:`;
1372
- const cleanKeys = keys.map((key) => key.replace(prefix, ""));
1373
- const limitedKeys = options.limit ? cleanKeys.slice(0, options.limit) : cleanKeys;
1374
- return {
1375
- keys: limitedKeys,
1376
- nextCursor: null,
1377
- totalCount: cleanKeys.length
1378
- };
1379
- } catch (error) {
1380
- this.stats.errors++;
1381
- this.noteOpError(error);
1382
- this.logOpError("Error getting keys", error);
1383
- return {
1384
- keys: [],
1385
- nextCursor: null,
1386
- totalCount: 0
1387
- };
1388
- }
1389
- }
1390
- /**
1391
- * Clear all keys in namespace
1392
- */
1393
- async clear() {
1394
- try {
1395
- const client = await this.ensureConnected();
1396
- const pattern = this.buildPattern("*");
1397
- const keys = await this.getKeys(pattern);
1398
- this.recordOpSuccess();
1399
- if (keys.length > 0) {
1400
- await client.del(keys);
1401
- if (this.enableLogging) {
1402
- logger.info(`[ValkeyGlideProvider:${this.namespace}] Cleared ${keys.length} keys`);
1403
- }
1404
- }
1405
- return true;
1406
- } catch (error) {
1407
- this.stats.errors++;
1408
- this.noteOpError(error);
1409
- this.logOpError("Error clearing cache", error);
1410
- return false;
1411
- }
1412
- }
1413
- /**
1414
- * Increment numeric value
1415
- */
1416
- async increment(key, amount = 1) {
1417
- try {
1418
- const client = await this.ensureConnected();
1419
- const cacheKey = this.buildKey(key);
1420
- const result = await client.incrBy(cacheKey, amount);
1421
- this.recordOpSuccess();
1422
- return result;
1423
- } catch (error) {
1424
- this.stats.errors++;
1425
- this.noteOpError(error);
1426
- this.logOpError("Error incrementing", error);
1427
- throw error;
1428
- }
1429
- }
1430
- /**
1431
- * Decrement numeric value
1432
- */
1433
- async decrement(key, amount = 1) {
1434
- try {
1435
- const client = await this.ensureConnected();
1436
- const cacheKey = this.buildKey(key);
1437
- const result = await client.decrBy(cacheKey, amount);
1438
- this.recordOpSuccess();
1439
- return result;
1440
- } catch (error) {
1441
- this.stats.errors++;
1442
- this.noteOpError(error);
1443
- this.logOpError("Error decrementing", error);
1444
- throw error;
1445
- }
1446
- }
1447
- /**
1448
- * Get or set value
1449
- */
1450
- async getOrSet(key, fetcher, options) {
1451
- const cached = await this.get(key, options);
1452
- if (cached !== null) {
1453
- return cached;
1454
- }
1455
- const value = await fetcher();
1456
- await this.set(key, value, options);
1457
- return value;
1458
- }
1459
- /**
1460
- * Invalidate by tags
1461
- */
1462
- async invalidateTags(tags) {
1463
- try {
1464
- let totalDeleted = 0;
1465
- for (const tag of tags) {
1466
- const pattern = `*:tag:${tag}:*`;
1467
- const deleted = await this.clearPattern(pattern);
1468
- totalDeleted += deleted;
1469
- }
1470
- if (this.enableLogging) {
1471
- logger.debug(`[ValkeyGlideProvider:${this.namespace}] Tags invalidated`, {
1472
- tags,
1473
- deleted: totalDeleted
1474
- });
1475
- }
1476
- return totalDeleted;
1477
- } catch (error) {
1478
- this.stats.errors++;
1479
- this.logOpError("Error invalidating tags", error);
1480
- return 0;
1481
- }
1482
- }
1483
- };
1484
-
1485
- // src/cache/factory/CacheFactory.ts
1486
- var CacheFactory = class _CacheFactory {
1487
- static {
1488
- __name(this, "CacheFactory");
1489
- }
1490
- static instances = /* @__PURE__ */ new Map();
1491
- static parseBoolean(value) {
1492
- if (value === void 0) return void 0;
1493
- const normalized = value.trim().toLowerCase();
1494
- if ([
1495
- "1",
1496
- "true",
1497
- "yes",
1498
- "on"
1499
- ].includes(normalized)) return true;
1500
- if ([
1501
- "0",
1502
- "false",
1503
- "no",
1504
- "off"
1505
- ].includes(normalized)) return false;
1506
- return void 0;
1507
- }
1508
- static parseClusterNodes(value) {
1509
- if (!value) return void 0;
1510
- const nodes = value.split(",").map((node) => node.trim()).filter(Boolean).map((node) => {
1511
- const [host, rawPort] = node.replace(/^redis:\/\//, "").replace(/^valkey:\/\//, "").split(":");
1512
- if (!host) return null;
1513
- return {
1514
- host,
1515
- port: rawPort ? parseInt(rawPort, 10) : 6379
1516
- };
1517
- }).filter((node) => node !== null && Number.isFinite(node.port));
1518
- return nodes.length > 0 ? nodes : void 0;
1519
- }
1520
- /**
1521
- * Resolve port from multiple environment variable sources
1522
- * @param layerPort - Layer-specific port environment variable value
1523
- * @param genericPort - Generic port environment variable value
1524
- * @param defaultPort - Default port if none provided
1525
- * @returns Resolved port number
1526
- */
1527
- static resolvePort(layerPort, genericPort, defaultPort = 6379) {
1528
- if (layerPort) {
1529
- return parseInt(layerPort, 10);
1530
- }
1531
- if (genericPort) {
1532
- return parseInt(genericPort, 10);
1533
- }
1534
- return defaultPort;
1535
- }
1536
- /**
1537
- * Create a cache provider based on configuration
1538
- */
1539
- static createCache(config, namespace = "default") {
1540
- logger.info("[CacheFactory] Creating cache provider", {
1541
- type: config.type,
1542
- namespace
1543
- });
1544
- switch (config.type) {
1545
- case "valkey":
1546
- case "redis":
1547
- return new ValkeyGlideProvider({
1548
- type: "valkey-glide",
1549
- url: config.url,
1550
- host: config.host,
1551
- port: config.port,
1552
- password: config.password,
1553
- username: config.username,
1554
- db: config.db,
1555
- keyPrefix: config.keyPrefix,
1556
- defaultTTL: config.defaultTTL,
1557
- enableLogging: config.enableLogging,
1558
- maxReconnectAttempts: config.maxReconnectAttempts,
1559
- reconnectTimeWait: config.reconnectTimeWait,
1560
- connectionTimeout: config.connectionTimeout,
1561
- name: config.name,
1562
- useTLS: config.tls?.enabled,
1563
- cluster: config.cluster,
1564
- clusterNodes: config.clusterNodes
1565
- }, namespace);
1566
- case "memory":
1567
- return new MemoryCacheProvider(config, namespace);
1568
- // Future implementations can be added here
1569
- // case 'memcached':
1570
- // return new MemcachedCacheProvider(config as MemcachedCacheConfig, namespace);
1571
- default:
1572
- throw new Error(`Unsupported cache provider type: ${config.type}`);
1573
- }
1574
- }
1575
- /**
1576
- * Create a cache from environment variables
1577
- */
1578
- static createCacheFromEnv(namespace = "default") {
1579
- const envType = process.env["CACHE_PROVIDER_TYPE"];
1580
- const type = envType === "memory" ? "memory" : "valkey";
1581
- if (type === "valkey") {
1582
- assertCacheEndpointConfigured({
1583
- url: process.env["VALKEY_URL"] || process.env["REDIS_URL"],
1584
- host: process.env["VALKEY_HOST"],
1585
- password: process.env["VALKEY_PASSWORD"],
1586
- port: process.env["VALKEY_PORT"] ? parseInt(process.env["VALKEY_PORT"], 10) : void 0,
1587
- context: "CacheFactory.createCache",
1588
- keysTried: [
1589
- "VALKEY_URL",
1590
- "REDIS_URL",
1591
- "VALKEY_HOST"
1592
- ]
1593
- });
1594
- }
1595
- const config = type === "valkey" ? {
1596
- type: "valkey",
1597
- // Fall back to REDIS_URL when VALKEY_URL is unset/empty. Prod KV
1598
- // provisioning populates the canonical REDIS_URL (a `rediss://…`
1599
- // Azure Managed Redis string) for every service but has, for some
1600
- // services, left VALKEY_URL blank. Without this fallback the cache
1601
- // silently connected to localhost:6379 — a connect that hangs on
1602
- // GLIDE's reconnect backoff long enough to starve the event loop and
1603
- // saturate the pg pool (10s "connect timeout" 500s). This mirrors the
1604
- // precedence already used by gateway/security/valkey.ts.
1605
- url: process.env["VALKEY_URL"] || process.env["REDIS_URL"],
1606
- host: process.env["VALKEY_HOST"] || "localhost",
1607
- port: process.env["VALKEY_PORT"] ? parseInt(process.env["VALKEY_PORT"], 10) : 6379,
1608
- password: process.env["VALKEY_PASSWORD"],
1609
- db: process.env["VALKEY_DB"] ? parseInt(process.env["VALKEY_DB"], 10) : 0,
1610
- username: process.env["VALKEY_USERNAME"],
1611
- keyPrefix: process.env["CACHE_KEY_PREFIX"] || "cache",
1612
- defaultTTL: process.env["CACHE_DEFAULT_TTL"] ? parseInt(process.env["CACHE_DEFAULT_TTL"], 10) : 300,
1613
- enableLogging: process.env["CACHE_ENABLE_LOGGING"] === "true",
1614
- maxReconnectAttempts: process.env["VALKEY_MAX_RECONNECT_ATTEMPTS"] ? parseInt(process.env["VALKEY_MAX_RECONNECT_ATTEMPTS"], 10) : -1,
1615
- reconnectTimeWait: process.env["VALKEY_RECONNECT_TIME_WAIT"] ? parseInt(process.env["VALKEY_RECONNECT_TIME_WAIT"], 10) : 2e3,
1616
- connectionTimeout: process.env["VALKEY_CONNECTION_TIMEOUT"] ? parseInt(process.env["VALKEY_CONNECTION_TIMEOUT"], 10) : 1e4,
1617
- name: process.env["CACHE_CLIENT_NAME"] || `cache-${namespace}`,
1618
- cluster: _CacheFactory.parseBoolean(process.env["VALKEY_CLUSTER"] || process.env["CACHE_CLUSTER"]),
1619
- clusterNodes: _CacheFactory.parseClusterNodes(process.env["VALKEY_CLUSTER_NODES"] || process.env["CACHE_CLUSTER_NODES"])
1620
- } : {
1621
- type: "memory",
1622
- maxSize: process.env["CACHE_MAX_SIZE"] ? parseInt(process.env["CACHE_MAX_SIZE"], 10) : 1e3,
1623
- defaultTTL: process.env["CACHE_DEFAULT_TTL"] ? parseInt(process.env["CACHE_DEFAULT_TTL"], 10) : 300,
1624
- enableLogging: process.env["CACHE_ENABLE_LOGGING"] === "true",
1625
- keyPrefix: process.env["CACHE_KEY_PREFIX"] || "cache"
1626
- };
1627
- return _CacheFactory.createCache(config, namespace);
1628
- }
1629
- /**
1630
- * Get or create a singleton cache instance for a namespace
1631
- */
1632
- static getInstance(namespace = "default", config) {
1633
- const instanceKey = `${config?.type || "default"}:${namespace}`;
1634
- if (!_CacheFactory.instances.has(instanceKey)) {
1635
- const cache = config ? _CacheFactory.createCache(config, namespace) : _CacheFactory.createCacheFromEnv(namespace);
1636
- _CacheFactory.instances.set(instanceKey, cache);
1637
- }
1638
- return _CacheFactory.instances.get(instanceKey);
1639
- }
1640
- /**
1641
- * Close a specific cache instance
1642
- */
1643
- static async closeInstance(namespace) {
1644
- for (const [key, cache] of _CacheFactory.instances.entries()) {
1645
- if (key.endsWith(`:${namespace}`)) {
1646
- await cache.disconnect();
1647
- _CacheFactory.instances.delete(key);
1648
- logger.info("[CacheFactory] Closed cache instance", {
1649
- namespace
1650
- });
1651
- }
1652
- }
1653
- }
1654
- /**
1655
- * Close all cache instances
1656
- * Call this during application shutdown
1657
- */
1658
- static async closeAll() {
1659
- const promises = Array.from(_CacheFactory.instances.values()).map(async (cache) => cache.disconnect());
1660
- await Promise.all(promises);
1661
- _CacheFactory.instances.clear();
1662
- logger.info("[CacheFactory] All cache instances closed");
1663
- }
1664
- // ========================================================================
1665
- // Layer-Aware Factory Methods
1666
- // ========================================================================
1667
- /**
1668
- * Create a cache provider for a specific layer
1669
- *
1670
- * @param layer - Service layer ('wspace' or 'global')
1671
- * @param serviceName - Service name for identification
1672
- * @param namespace - Cache namespace (default: 'default')
1673
- * @returns Cache provider configured for the layer
1674
- *
1675
- * @example
1676
- * ```typescript
1677
- * const cache = CacheFactory.createCacheForLayer('wspace', 'wspace-tags-svc');
1678
- * await cache.connect();
1679
- * await cache.set('key', { data: 'value' });
1680
- * ```
1681
- */
1682
- static createCacheForLayer(layer, serviceName, namespace = "default") {
1683
- const envPrefix = layer.toUpperCase();
1684
- const defaults = DEFAULT_LAYER_RESOURCES[layer];
1685
- const url = process.env[`${envPrefix}_VALKEY_URL`] || process.env["VALKEY_URL"] || process.env["REDIS_URL"] || defaults.valkeyUrl;
1686
- warnOnLayerDefaultEndpoint(`CacheFactory.createCacheForLayer(${layer}, ${serviceName})`, url, defaults.valkeyUrl);
1687
- const resolvedPort = _CacheFactory.resolvePort(process.env[`${envPrefix}_VALKEY_PORT`], process.env["VALKEY_PORT"]);
1688
- const config = {
1689
- type: "valkey",
1690
- url,
1691
- host: process.env[`${envPrefix}_VALKEY_HOST`] || process.env["VALKEY_HOST"] || "localhost",
1692
- port: resolvedPort,
1693
- password: process.env["VALKEY_PASSWORD"],
1694
- db: process.env["VALKEY_DB"] ? parseInt(process.env["VALKEY_DB"], 10) : 0,
1695
- username: process.env["VALKEY_USERNAME"],
1696
- keyPrefix: process.env["CACHE_KEY_PREFIX"] || `${layer}-cache`,
1697
- defaultTTL: process.env["CACHE_DEFAULT_TTL"] ? parseInt(process.env["CACHE_DEFAULT_TTL"], 10) : 300,
1698
- enableLogging: process.env["CACHE_ENABLE_LOGGING"] === "true",
1699
- maxReconnectAttempts: process.env["VALKEY_MAX_RECONNECT_ATTEMPTS"] ? parseInt(process.env["VALKEY_MAX_RECONNECT_ATTEMPTS"], 10) : -1,
1700
- reconnectTimeWait: process.env["VALKEY_RECONNECT_TIME_WAIT"] ? parseInt(process.env["VALKEY_RECONNECT_TIME_WAIT"], 10) : 2e3,
1701
- connectionTimeout: process.env["VALKEY_CONNECTION_TIMEOUT"] ? parseInt(process.env["VALKEY_CONNECTION_TIMEOUT"], 10) : 1e4,
1702
- name: serviceName,
1703
- cluster: _CacheFactory.parseBoolean(process.env[`${envPrefix}_VALKEY_CLUSTER`] || process.env["VALKEY_CLUSTER"] || process.env["CACHE_CLUSTER"]),
1704
- clusterNodes: _CacheFactory.parseClusterNodes(process.env[`${envPrefix}_VALKEY_CLUSTER_NODES`] || process.env["VALKEY_CLUSTER_NODES"] || process.env["CACHE_CLUSTER_NODES"])
1705
- };
1706
- logger.info("[CacheFactory] Creating layer cache", {
1707
- layer,
1708
- serviceName,
1709
- namespace,
1710
- url: config.url
1711
- });
1712
- return _CacheFactory.createCache(config, namespace);
1713
- }
1714
- /**
1715
- * Get or create a singleton cache instance for a layer
1716
- *
1717
- * @param layer - Service layer ('wspace' or 'global')
1718
- * @param serviceName - Service name for identification
1719
- * @param namespace - Cache namespace (default: 'default')
1720
- * @returns Singleton cache provider for the layer
1721
- */
1722
- static getInstanceForLayer(layer, serviceName, namespace = "default") {
1723
- const instanceKey = `${layer}:${serviceName}:${namespace}`;
1724
- if (!_CacheFactory.instances.has(instanceKey)) {
1725
- const cache = _CacheFactory.createCacheForLayer(layer, serviceName, namespace);
1726
- _CacheFactory.instances.set(instanceKey, cache);
1727
- }
1728
- return _CacheFactory.instances.get(instanceKey);
1729
- }
1730
- };
1731
-
1732
- // src/cache/types/config.ts
1733
- var CacheProviderType = /* @__PURE__ */ (function(CacheProviderType2) {
1734
- CacheProviderType2["VALKEY"] = "valkey";
1735
- CacheProviderType2["MEMORY"] = "memory";
1736
- CacheProviderType2["MEMCACHED"] = "memcached";
1737
- return CacheProviderType2;
1738
- })({});
1739
-
1740
- // src/cache/index.ts
1741
- function createCache(namespace = "default") {
1742
- return CacheFactory.createCacheFromEnv(namespace);
1743
- }
1744
- __name(createCache, "createCache");
1745
- function getCache(namespace = "default", config) {
1746
- return CacheFactory.getInstance(namespace, config);
1747
- }
1748
- __name(getCache, "getCache");
1749
- var sharedValkeyClients = /* @__PURE__ */ new Map();
1750
- var sharedValkeyConnects = /* @__PURE__ */ new Map();
1751
- function envEndpointKey() {
1752
- return [
1753
- process.env["VALKEY_URL"] || process.env["REDIS_URL"] || "",
1754
- process.env["VALKEY_HOST"] || "",
1755
- process.env["VALKEY_PORT"] || "",
1756
- process.env["VALKEY_DB"] || "",
1757
- process.env["VALKEY_USERNAME"] || ""
1758
- ].join("|");
1759
- }
1760
- __name(envEndpointKey, "envEndpointKey");
1761
- async function getValkeyClient(config) {
1762
- if (config) {
1763
- return createValkeyClient(config);
1764
- }
1765
- const key = envEndpointKey();
1766
- const existing = sharedValkeyClients.get(key);
1767
- if (existing) {
1768
- return existing;
1769
- }
1770
- const inFlight = sharedValkeyConnects.get(key);
1771
- if (inFlight) {
1772
- return inFlight;
1773
- }
1774
- const pending = (async () => {
1775
- try {
1776
- const client = await createValkeyClient();
1777
- sharedValkeyClients.set(key, client);
1778
- return client;
1779
- } finally {
1780
- sharedValkeyConnects.delete(key);
1781
- }
1782
- })();
1783
- sharedValkeyConnects.set(key, pending);
1784
- return pending;
1785
- }
1786
- __name(getValkeyClient, "getValkeyClient");
1787
- async function createValkeyClient(config) {
1788
- const glideModule = await import('@valkey/valkey-glide');
1789
- const GlideClient = glideModule.GlideClient || glideModule.default;
1790
- if (!config) {
1791
- assertCacheEndpointConfigured({
1792
- url: process.env["VALKEY_URL"] || process.env["REDIS_URL"],
1793
- host: process.env["VALKEY_HOST"],
1794
- password: process.env["VALKEY_PASSWORD"],
1795
- port: process.env["VALKEY_PORT"] ? parseInt(process.env["VALKEY_PORT"], 10) : void 0,
1796
- context: "getValkeyClient",
1797
- keysTried: [
1798
- "VALKEY_URL",
1799
- "REDIS_URL",
1800
- "VALKEY_HOST"
1801
- ]
1802
- });
1803
- }
1804
- const valkeyConfig = config || {
1805
- type: CacheProviderType.VALKEY,
1806
- // Fall back to REDIS_URL when VALKEY_URL is unset/empty (see CacheFactory).
1807
- url: process.env["VALKEY_URL"] || process.env["REDIS_URL"],
1808
- host: process.env["VALKEY_HOST"] || "localhost",
1809
- port: process.env["VALKEY_PORT"] ? parseInt(process.env["VALKEY_PORT"], 10) : 6379,
1810
- password: process.env["VALKEY_PASSWORD"],
1811
- db: process.env["VALKEY_DB"] ? parseInt(process.env["VALKEY_DB"], 10) : 0,
1812
- username: process.env["VALKEY_USERNAME"]
1813
- };
1814
- let host = valkeyConfig.host || "localhost";
1815
- let port = valkeyConfig.port || 6379;
1816
- if (valkeyConfig.url) {
1817
- const url = new URL(valkeyConfig.url.replace("valkey://", "redis://"));
1818
- host = url.hostname;
1819
- port = parseInt(url.port || "6379", 10);
1820
- }
1821
- const useTLS = valkeyConfig.useTLS ?? (valkeyConfig.url ? /^(rediss|valkeys):\/\//i.test(valkeyConfig.url) : void 0);
1822
- const createClient = GlideClient;
1823
- return createClient.createClient({
1824
- addresses: [
1825
- {
1826
- host,
1827
- port
1828
- }
1829
- ],
1830
- useTLS,
1831
- credentials: valkeyConfig.password ? {
1832
- password: valkeyConfig.password,
1833
- username: valkeyConfig.username
1834
- } : void 0,
1835
- clientName: valkeyConfig.name || "valkey-glide-client",
1836
- readFrom: "primary"
1837
- });
1838
- }
1839
- __name(createValkeyClient, "createValkeyClient");
1840
- async function closeAllCaches() {
1841
- await CacheFactory.closeAll();
1842
- const shared = [
1843
- ...sharedValkeyClients.values()
1844
- ];
1845
- sharedValkeyClients.clear();
1846
- sharedValkeyConnects.clear();
1847
- await Promise.all(shared.map((client) => Promise.resolve(client.close()).catch(() => void 0)));
1848
- }
1849
- __name(closeAllCaches, "closeAllCaches");
1850
-
1851
- export { CacheFactory, CacheProviderType, MemoryCacheProvider, ValkeyGlideProvider, assertCacheEndpointConfigured, cache_exports, closeAllCaches, createCache, getCache, getValkeyClient, warnOnLayerDefaultEndpoint };
1852
- //# sourceMappingURL=chunk-XOJORS75.js.map
1853
- //# sourceMappingURL=chunk-XOJORS75.js.map