@stackframe/stack-shared 2.8.8 → 2.8.11

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 (476) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/config/format.d.cts +39 -0
  3. package/dist/config/format.d.ts +14 -13
  4. package/dist/config/format.js +147 -206
  5. package/dist/config/format.js.map +1 -0
  6. package/dist/config/schema.d.cts +729 -0
  7. package/dist/config/schema.d.ts +59 -51
  8. package/dist/config/schema.js +232 -172
  9. package/dist/config/schema.js.map +1 -0
  10. package/dist/crud.d.cts +102 -0
  11. package/dist/crud.d.ts +15 -13
  12. package/dist/crud.js +83 -128
  13. package/dist/crud.js.map +1 -0
  14. package/dist/esm/config/format.js +135 -0
  15. package/dist/esm/config/format.js.map +1 -0
  16. package/dist/esm/config/schema.js +201 -0
  17. package/dist/esm/config/schema.js.map +1 -0
  18. package/dist/esm/crud.js +60 -0
  19. package/dist/esm/crud.js.map +1 -0
  20. package/dist/esm/global.d.js +1 -0
  21. package/dist/esm/global.d.js.map +1 -0
  22. package/dist/esm/helpers/password.js +17 -0
  23. package/dist/esm/helpers/password.js.map +1 -0
  24. package/dist/esm/helpers/production-mode.js +50 -0
  25. package/dist/esm/helpers/production-mode.js.map +1 -0
  26. package/dist/esm/hooks/use-async-callback.js +38 -0
  27. package/dist/esm/hooks/use-async-callback.js.map +1 -0
  28. package/dist/esm/hooks/use-async-external-store.js +23 -0
  29. package/dist/esm/hooks/use-async-external-store.js.map +1 -0
  30. package/dist/esm/hooks/use-hash.js +17 -0
  31. package/dist/esm/hooks/use-hash.js.map +1 -0
  32. package/dist/esm/hooks/use-strict-memo.js +61 -0
  33. package/dist/esm/hooks/use-strict-memo.js.map +1 -0
  34. package/dist/esm/index.js +22 -0
  35. package/dist/esm/index.js.map +1 -0
  36. package/dist/esm/interface/adminInterface.js +244 -0
  37. package/dist/esm/interface/adminInterface.js.map +1 -0
  38. package/dist/esm/interface/clientInterface.js +2041 -0
  39. package/dist/esm/interface/clientInterface.js.map +1 -0
  40. package/dist/esm/interface/crud/contact-channels.js +77 -0
  41. package/dist/esm/interface/crud/contact-channels.js.map +1 -0
  42. package/dist/esm/interface/crud/current-user.js +65 -0
  43. package/dist/esm/interface/crud/current-user.js.map +1 -0
  44. package/dist/esm/interface/crud/email-templates.js +52 -0
  45. package/dist/esm/interface/crud/email-templates.js.map +1 -0
  46. package/dist/esm/interface/crud/emails.js +20 -0
  47. package/dist/esm/interface/crud/emails.js.map +1 -0
  48. package/dist/esm/interface/crud/internal-api-keys.js +69 -0
  49. package/dist/esm/interface/crud/internal-api-keys.js.map +1 -0
  50. package/dist/esm/interface/crud/oauth.js +24 -0
  51. package/dist/esm/interface/crud/oauth.js.map +1 -0
  52. package/dist/esm/interface/crud/project-api-keys.js +93 -0
  53. package/dist/esm/interface/crud/project-api-keys.js.map +1 -0
  54. package/dist/esm/interface/crud/project-permissions.js +113 -0
  55. package/dist/esm/interface/crud/project-permissions.js.map +1 -0
  56. package/dist/esm/interface/crud/projects.js +180 -0
  57. package/dist/esm/interface/crud/projects.js.map +1 -0
  58. package/dist/esm/interface/crud/sessions.js +62 -0
  59. package/dist/esm/interface/crud/sessions.js.map +1 -0
  60. package/dist/esm/interface/crud/svix-token.js +22 -0
  61. package/dist/esm/interface/crud/svix-token.js.map +1 -0
  62. package/dist/esm/interface/crud/team-invitation-details.js +23 -0
  63. package/dist/esm/interface/crud/team-invitation-details.js.map +1 -0
  64. package/dist/esm/interface/crud/team-invitation.js +36 -0
  65. package/dist/esm/interface/crud/team-invitation.js.map +1 -0
  66. package/dist/esm/interface/crud/team-member-profiles.js +62 -0
  67. package/dist/esm/interface/crud/team-member-profiles.js.map +1 -0
  68. package/dist/esm/interface/crud/team-memberships.js +60 -0
  69. package/dist/esm/interface/crud/team-memberships.js.map +1 -0
  70. package/dist/esm/interface/crud/team-permissions.js +114 -0
  71. package/dist/esm/interface/crud/team-permissions.js.map +1 -0
  72. package/dist/esm/interface/crud/teams.js +143 -0
  73. package/dist/esm/interface/crud/teams.js.map +1 -0
  74. package/dist/esm/interface/crud/users.js +139 -0
  75. package/dist/esm/interface/crud/users.js.map +1 -0
  76. package/dist/esm/interface/serverInterface.js +485 -0
  77. package/dist/esm/interface/serverInterface.js.map +1 -0
  78. package/dist/esm/interface/webhooks.js +21 -0
  79. package/dist/esm/interface/webhooks.js.map +1 -0
  80. package/dist/esm/known-errors.js +1238 -0
  81. package/dist/esm/known-errors.js.map +1 -0
  82. package/dist/esm/schema-fields.js +484 -0
  83. package/dist/esm/schema-fields.js.map +1 -0
  84. package/dist/esm/sessions.js +168 -0
  85. package/dist/esm/sessions.js.map +1 -0
  86. package/dist/esm/utils/api-keys.js +79 -0
  87. package/dist/esm/utils/api-keys.js.map +1 -0
  88. package/dist/esm/utils/arrays.js +78 -0
  89. package/dist/esm/utils/arrays.js.map +1 -0
  90. package/dist/esm/utils/base64.js +18 -0
  91. package/dist/esm/utils/base64.js.map +1 -0
  92. package/dist/esm/utils/booleans.js +12 -0
  93. package/dist/esm/utils/booleans.js.map +1 -0
  94. package/dist/esm/utils/browser-compat.js +21 -0
  95. package/dist/esm/utils/browser-compat.js.map +1 -0
  96. package/dist/esm/utils/bytes.js +160 -0
  97. package/dist/esm/utils/bytes.js.map +1 -0
  98. package/dist/esm/utils/caches.js +167 -0
  99. package/dist/esm/utils/caches.js.map +1 -0
  100. package/dist/esm/utils/compile-time.js +11 -0
  101. package/dist/esm/utils/compile-time.js.map +1 -0
  102. package/dist/esm/utils/crypto.js +25 -0
  103. package/dist/esm/utils/crypto.js.map +1 -0
  104. package/dist/esm/utils/dates.js +64 -0
  105. package/dist/esm/utils/dates.js.map +1 -0
  106. package/dist/esm/utils/dom.js +11 -0
  107. package/dist/esm/utils/dom.js.map +1 -0
  108. package/dist/esm/utils/env.js +58 -0
  109. package/dist/esm/utils/env.js.map +1 -0
  110. package/dist/esm/utils/errors.js +174 -0
  111. package/dist/esm/utils/errors.js.map +1 -0
  112. package/dist/esm/utils/fs.js +37 -0
  113. package/dist/esm/utils/fs.js.map +1 -0
  114. package/dist/esm/utils/functions.js +12 -0
  115. package/dist/esm/utils/functions.js.map +1 -0
  116. package/dist/esm/utils/geo.js +15 -0
  117. package/dist/esm/utils/geo.js.map +1 -0
  118. package/dist/esm/utils/globals.js +18 -0
  119. package/dist/esm/utils/globals.js.map +1 -0
  120. package/dist/esm/utils/hashes.js +55 -0
  121. package/dist/esm/utils/hashes.js.map +1 -0
  122. package/dist/esm/utils/html.js +13 -0
  123. package/dist/esm/utils/html.js.map +1 -0
  124. package/dist/esm/utils/http.js +60 -0
  125. package/dist/esm/utils/http.js.map +1 -0
  126. package/dist/esm/utils/ips.js +15 -0
  127. package/dist/esm/utils/ips.js.map +1 -0
  128. package/dist/esm/utils/json.js +31 -0
  129. package/dist/esm/utils/json.js.map +1 -0
  130. package/dist/esm/utils/jwt.js +87 -0
  131. package/dist/esm/utils/jwt.js.map +1 -0
  132. package/dist/esm/utils/locks.js +57 -0
  133. package/dist/esm/utils/locks.js.map +1 -0
  134. package/dist/esm/utils/maps.js +181 -0
  135. package/dist/esm/utils/maps.js.map +1 -0
  136. package/dist/esm/utils/math.js +8 -0
  137. package/dist/esm/utils/math.js.map +1 -0
  138. package/dist/esm/utils/node-http.js +42 -0
  139. package/dist/esm/utils/node-http.js.map +1 -0
  140. package/dist/esm/utils/numbers.js +32 -0
  141. package/dist/esm/utils/numbers.js.map +1 -0
  142. package/dist/esm/utils/oauth.js +10 -0
  143. package/dist/esm/utils/oauth.js.map +1 -0
  144. package/dist/esm/utils/objects.js +177 -0
  145. package/dist/esm/utils/objects.js.map +1 -0
  146. package/dist/esm/utils/passkey.js +1 -0
  147. package/dist/esm/utils/passkey.js.map +1 -0
  148. package/dist/esm/utils/promises.js +233 -0
  149. package/dist/esm/utils/promises.js.map +1 -0
  150. package/dist/esm/utils/proxies.js +128 -0
  151. package/dist/esm/utils/proxies.js.map +1 -0
  152. package/dist/esm/utils/react.js +78 -0
  153. package/dist/esm/utils/react.js.map +1 -0
  154. package/dist/esm/utils/results.js +141 -0
  155. package/dist/esm/utils/results.js.map +1 -0
  156. package/dist/esm/utils/sentry.js +20 -0
  157. package/dist/esm/utils/sentry.js.map +1 -0
  158. package/dist/esm/utils/stores.js +195 -0
  159. package/dist/esm/utils/stores.js.map +1 -0
  160. package/dist/esm/utils/strings.js +295 -0
  161. package/dist/esm/utils/strings.js.map +1 -0
  162. package/dist/esm/utils/strings.nicify.test.js +222 -0
  163. package/dist/esm/utils/strings.nicify.test.js.map +1 -0
  164. package/dist/esm/utils/types.js +1 -0
  165. package/dist/esm/utils/types.js.map +1 -0
  166. package/dist/esm/utils/unicode.js +11 -0
  167. package/dist/esm/utils/unicode.js.map +1 -0
  168. package/dist/esm/utils/urls.js +53 -0
  169. package/dist/esm/utils/urls.js.map +1 -0
  170. package/dist/esm/utils/uuids.js +16 -0
  171. package/dist/esm/utils/uuids.js.map +1 -0
  172. package/dist/global.d.d.cts +1 -0
  173. package/dist/global.d.d.ts +1 -0
  174. package/dist/global.d.js +2 -0
  175. package/dist/global.d.js.map +1 -0
  176. package/dist/helpers/password.d.cts +11 -0
  177. package/dist/helpers/password.d.ts +11 -2
  178. package/dist/helpers/password.js +41 -11
  179. package/dist/helpers/password.js.map +1 -0
  180. package/dist/helpers/production-mode.d.cts +12 -0
  181. package/dist/helpers/production-mode.d.ts +9 -3
  182. package/dist/helpers/production-mode.js +72 -45
  183. package/dist/helpers/production-mode.js.map +1 -0
  184. package/dist/hooks/use-async-callback.d.cts +6 -0
  185. package/dist/hooks/use-async-callback.d.ts +6 -3
  186. package/dist/hooks/use-async-callback.js +72 -30
  187. package/dist/hooks/use-async-callback.js.map +1 -0
  188. package/dist/hooks/use-async-external-store.d.cts +7 -0
  189. package/dist/hooks/use-async-external-store.d.ts +5 -2
  190. package/dist/hooks/use-async-external-store.js +47 -19
  191. package/dist/hooks/use-async-external-store.js.map +1 -0
  192. package/dist/hooks/use-hash.d.cts +3 -0
  193. package/dist/hooks/use-hash.d.ts +3 -1
  194. package/dist/hooks/use-hash.js +41 -8
  195. package/dist/hooks/use-hash.js.map +1 -0
  196. package/dist/hooks/use-strict-memo.d.cts +8 -0
  197. package/dist/hooks/use-strict-memo.d.ts +3 -1
  198. package/dist/hooks/use-strict-memo.js +78 -131
  199. package/dist/hooks/use-strict-memo.js.map +1 -0
  200. package/dist/index.d.cts +30 -0
  201. package/dist/index.d.ts +30 -4
  202. package/dist/index.js +42 -4
  203. package/dist/index.js.map +1 -0
  204. package/dist/interface/adminInterface.d.cts +94 -0
  205. package/dist/interface/adminInterface.d.ts +38 -15
  206. package/dist/interface/adminInterface.js +269 -174
  207. package/dist/interface/adminInterface.js.map +1 -0
  208. package/dist/interface/clientInterface.d.cts +260 -0
  209. package/dist/interface/clientInterface.d.ts +25 -18
  210. package/dist/interface/clientInterface.js +2054 -995
  211. package/dist/interface/clientInterface.js.map +1 -0
  212. package/dist/interface/crud/contact-channels.d.cts +180 -0
  213. package/dist/interface/crud/contact-channels.d.ts +30 -25
  214. package/dist/interface/crud/contact-channels.js +101 -59
  215. package/dist/interface/crud/contact-channels.js.map +1 -0
  216. package/dist/interface/crud/current-user.d.cts +205 -0
  217. package/dist/interface/crud/current-user.d.ts +17 -12
  218. package/dist/interface/crud/current-user.js +86 -56
  219. package/dist/interface/crud/current-user.js.map +1 -0
  220. package/dist/interface/crud/email-templates.d.cts +84 -0
  221. package/dist/interface/crud/email-templates.d.ts +24 -19
  222. package/dist/interface/crud/email-templates.js +77 -37
  223. package/dist/interface/crud/email-templates.js.map +1 -0
  224. package/dist/interface/crud/emails.d.cts +69 -0
  225. package/dist/interface/crud/emails.d.ts +12 -7
  226. package/dist/interface/crud/emails.js +54 -12
  227. package/dist/interface/crud/emails.js.map +1 -0
  228. package/dist/interface/crud/internal-api-keys.d.cts +139 -0
  229. package/dist/interface/crud/internal-api-keys.d.ts +22 -17
  230. package/dist/interface/crud/internal-api-keys.js +92 -54
  231. package/dist/interface/crud/internal-api-keys.js.map +1 -0
  232. package/dist/interface/crud/oauth.d.cts +34 -0
  233. package/dist/interface/crud/oauth.d.ts +16 -11
  234. package/dist/interface/crud/oauth.js +48 -14
  235. package/dist/interface/crud/oauth.js.map +1 -0
  236. package/dist/interface/crud/project-api-keys.d.cts +196 -0
  237. package/dist/interface/crud/project-api-keys.d.ts +20 -12
  238. package/dist/interface/crud/project-api-keys.js +121 -74
  239. package/dist/interface/crud/project-api-keys.js.map +1 -0
  240. package/dist/interface/crud/project-permissions.d.cts +160 -0
  241. package/dist/interface/crud/project-permissions.d.ts +38 -33
  242. package/dist/interface/crud/project-permissions.js +148 -90
  243. package/dist/interface/crud/project-permissions.js.map +1 -0
  244. package/dist/interface/crud/projects.d.cts +627 -0
  245. package/dist/interface/crud/projects.d.ts +43 -51
  246. package/dist/interface/crud/projects.js +210 -156
  247. package/dist/interface/crud/projects.js.map +1 -0
  248. package/dist/interface/crud/sessions.d.cts +149 -0
  249. package/dist/interface/crud/sessions.d.ts +21 -16
  250. package/dist/interface/crud/sessions.js +86 -50
  251. package/dist/interface/crud/sessions.js.map +1 -0
  252. package/dist/interface/crud/svix-token.d.cts +26 -0
  253. package/dist/interface/crud/svix-token.d.ts +14 -9
  254. package/dist/interface/crud/svix-token.js +46 -12
  255. package/dist/interface/crud/svix-token.js.map +1 -0
  256. package/dist/interface/crud/team-invitation-details.d.cts +30 -0
  257. package/dist/interface/crud/team-invitation-details.d.ts +12 -7
  258. package/dist/interface/crud/team-invitation-details.js +57 -15
  259. package/dist/interface/crud/team-invitation-details.js.map +1 -0
  260. package/dist/interface/crud/team-invitation.d.cts +49 -0
  261. package/dist/interface/crud/team-invitation.d.ts +13 -8
  262. package/dist/interface/crud/team-invitation.js +69 -27
  263. package/dist/interface/crud/team-invitation.js.map +1 -0
  264. package/dist/interface/crud/team-member-profiles.d.cts +229 -0
  265. package/dist/interface/crud/team-member-profiles.d.ts +20 -15
  266. package/dist/interface/crud/team-member-profiles.js +95 -49
  267. package/dist/interface/crud/team-member-profiles.js.map +1 -0
  268. package/dist/interface/crud/team-memberships.d.cts +74 -0
  269. package/dist/interface/crud/team-memberships.d.ts +22 -17
  270. package/dist/interface/crud/team-memberships.js +85 -45
  271. package/dist/interface/crud/team-memberships.js.map +1 -0
  272. package/dist/interface/crud/team-permissions.d.cts +168 -0
  273. package/dist/interface/crud/team-permissions.d.ts +38 -33
  274. package/dist/interface/crud/team-permissions.js +149 -91
  275. package/dist/interface/crud/team-permissions.js.map +1 -0
  276. package/dist/interface/crud/teams.d.cts +298 -0
  277. package/dist/interface/crud/teams.d.ts +45 -40
  278. package/dist/interface/crud/teams.js +177 -119
  279. package/dist/interface/crud/teams.js.map +1 -0
  280. package/dist/interface/crud/users.d.cts +469 -0
  281. package/dist/interface/crud/users.d.ts +31 -26
  282. package/dist/interface/crud/users.js +172 -118
  283. package/dist/interface/crud/users.js.map +1 -0
  284. package/dist/interface/serverInterface.d.cts +128 -0
  285. package/dist/interface/serverInterface.d.ts +29 -17
  286. package/dist/interface/serverInterface.js +506 -339
  287. package/dist/interface/serverInterface.js.map +1 -0
  288. package/dist/interface/webhooks.d.cts +292 -0
  289. package/dist/interface/webhooks.d.ts +6 -3
  290. package/dist/interface/webhooks.js +45 -15
  291. package/dist/interface/webhooks.js.map +1 -0
  292. package/dist/known-errors.d.cts +447 -0
  293. package/dist/known-errors.d.ts +15 -9
  294. package/dist/known-errors.js +1104 -562
  295. package/dist/known-errors.js.map +1 -0
  296. package/dist/schema-fields.d.cts +163 -0
  297. package/dist/schema-fields.d.ts +116 -114
  298. package/dist/schema-fields.js +593 -427
  299. package/dist/schema-fields.js.map +1 -0
  300. package/dist/sessions.d.cts +109 -0
  301. package/dist/sessions.d.ts +6 -3
  302. package/dist/sessions.js +201 -172
  303. package/dist/sessions.js.map +1 -0
  304. package/dist/utils/api-keys.d.cts +24 -0
  305. package/dist/utils/api-keys.d.ts +5 -4
  306. package/dist/utils/api-keys.js +106 -66
  307. package/dist/utils/api-keys.js.map +1 -0
  308. package/dist/utils/arrays.d.cts +18 -0
  309. package/dist/utils/arrays.d.ts +15 -13
  310. package/dist/utils/arrays.js +101 -168
  311. package/dist/utils/arrays.js.map +1 -0
  312. package/dist/utils/base64.d.cts +4 -0
  313. package/dist/utils/base64.d.ts +4 -2
  314. package/dist/utils/base64.js +41 -20
  315. package/dist/utils/base64.js.map +1 -0
  316. package/dist/utils/booleans.d.cts +6 -0
  317. package/dist/utils/booleans.d.ts +6 -4
  318. package/dist/utils/booleans.js +35 -27
  319. package/dist/utils/booleans.js.map +1 -0
  320. package/dist/utils/browser-compat.d.cts +8 -0
  321. package/dist/utils/browser-compat.d.ts +3 -1
  322. package/dist/utils/browser-compat.js +45 -16
  323. package/dist/utils/browser-compat.js.map +1 -0
  324. package/dist/utils/bytes.d.cts +15 -0
  325. package/dist/utils/bytes.d.ts +15 -13
  326. package/dist/utils/bytes.js +182 -270
  327. package/dist/utils/bytes.js.map +1 -0
  328. package/dist/utils/caches.d.cts +98 -0
  329. package/dist/utils/caches.d.ts +17 -14
  330. package/dist/utils/caches.js +188 -193
  331. package/dist/utils/caches.js.map +1 -0
  332. package/dist/utils/compile-time.d.cts +8 -0
  333. package/dist/utils/compile-time.d.ts +3 -1
  334. package/dist/utils/compile-time.js +35 -10
  335. package/dist/utils/compile-time.js.map +1 -0
  336. package/dist/utils/crypto.d.cts +8 -0
  337. package/dist/utils/crypto.d.ts +4 -2
  338. package/dist/utils/crypto.js +49 -21
  339. package/dist/utils/crypto.js.map +1 -0
  340. package/dist/utils/dates.d.cts +15 -0
  341. package/dist/utils/dates.d.ts +6 -4
  342. package/dist/utils/dates.js +83 -105
  343. package/dist/utils/dates.js.map +1 -0
  344. package/dist/utils/dom.d.cts +3 -0
  345. package/dist/utils/dom.d.ts +3 -1
  346. package/dist/utils/dom.js +35 -7
  347. package/dist/utils/dom.js.map +1 -0
  348. package/dist/utils/env.d.cts +9 -0
  349. package/dist/utils/env.d.ts +6 -4
  350. package/dist/utils/env.js +70 -43
  351. package/dist/utils/env.js.map +1 -0
  352. package/dist/utils/errors.d.cts +223 -0
  353. package/dist/utils/errors.d.ts +14 -11
  354. package/dist/utils/errors.js +148 -126
  355. package/dist/utils/errors.js.map +1 -0
  356. package/dist/utils/fs.d.cts +7 -0
  357. package/dist/utils/fs.d.ts +5 -3
  358. package/dist/utils/fs.js +70 -27
  359. package/dist/utils/fs.js.map +1 -0
  360. package/dist/utils/functions.d.cts +4 -0
  361. package/dist/utils/functions.d.ts +4 -2
  362. package/dist/utils/functions.js +35 -18
  363. package/dist/utils/functions.js.map +1 -0
  364. package/dist/utils/geo.d.cts +22 -0
  365. package/dist/utils/geo.d.ts +6 -3
  366. package/dist/utils/geo.js +39 -9
  367. package/dist/utils/geo.js.map +1 -0
  368. package/dist/utils/globals.d.cts +5 -0
  369. package/dist/utils/globals.d.ts +4 -2
  370. package/dist/utils/globals.js +41 -14
  371. package/dist/utils/globals.js.map +1 -0
  372. package/dist/utils/hashes.d.cts +7 -0
  373. package/dist/utils/hashes.d.ts +7 -5
  374. package/dist/utils/hashes.js +87 -41
  375. package/dist/utils/hashes.js.map +1 -0
  376. package/dist/utils/html.d.cts +4 -0
  377. package/dist/utils/html.d.ts +4 -2
  378. package/dist/utils/html.js +36 -37
  379. package/dist/utils/html.js.map +1 -0
  380. package/dist/utils/http.d.cts +43 -0
  381. package/dist/utils/http.d.ts +6 -4
  382. package/dist/utils/http.js +83 -83
  383. package/dist/utils/http.js.map +1 -0
  384. package/dist/utils/ips.d.cts +6 -0
  385. package/dist/utils/ips.d.ts +6 -4
  386. package/dist/utils/ips.js +48 -35
  387. package/dist/utils/ips.js.map +1 -0
  388. package/dist/utils/json.d.cts +13 -0
  389. package/dist/utils/json.d.ts +9 -6
  390. package/dist/utils/json.js +54 -157
  391. package/dist/utils/json.js.map +1 -0
  392. package/dist/utils/jwt.d.cts +44 -0
  393. package/dist/utils/jwt.d.ts +14 -11
  394. package/dist/utils/jwt.js +119 -84
  395. package/dist/utils/jwt.js.map +1 -0
  396. package/dist/utils/locks.d.cts +15 -0
  397. package/dist/utils/locks.d.ts +3 -2
  398. package/dist/utils/locks.js +76 -56
  399. package/dist/utils/locks.js.map +1 -0
  400. package/dist/utils/maps.d.cts +59 -0
  401. package/dist/utils/maps.d.ts +6 -4
  402. package/dist/utils/maps.js +207 -343
  403. package/dist/utils/maps.js.map +1 -0
  404. package/dist/utils/math.d.cts +6 -0
  405. package/dist/utils/math.d.ts +3 -1
  406. package/dist/utils/math.js +31 -16
  407. package/dist/utils/math.js.map +1 -0
  408. package/dist/utils/node-http.d.cts +15 -0
  409. package/dist/utils/node-http.d.ts +5 -5
  410. package/dist/utils/node-http.js +65 -36
  411. package/dist/utils/node-http.js.map +1 -0
  412. package/dist/utils/numbers.d.cts +5 -0
  413. package/dist/utils/numbers.d.ts +5 -3
  414. package/dist/utils/numbers.js +53 -66
  415. package/dist/utils/numbers.js.map +1 -0
  416. package/dist/utils/oauth.d.cts +8 -0
  417. package/dist/utils/oauth.d.ts +8 -6
  418. package/dist/utils/oauth.js +37 -4
  419. package/dist/utils/oauth.js.map +1 -0
  420. package/dist/utils/objects.d.cts +69 -0
  421. package/dist/utils/objects.d.ts +37 -32
  422. package/dist/utils/objects.js +224 -374
  423. package/dist/utils/objects.js.map +1 -0
  424. package/dist/utils/passkey.d.cts +1 -0
  425. package/dist/utils/passkey.d.ts +1 -1
  426. package/dist/utils/passkey.js +19 -1
  427. package/dist/utils/passkey.js.map +1 -0
  428. package/dist/utils/promises.d.cts +74 -0
  429. package/dist/utils/promises.d.ts +20 -18
  430. package/dist/utils/promises.js +252 -393
  431. package/dist/utils/promises.js.map +1 -0
  432. package/dist/utils/proxies.d.cts +4 -0
  433. package/dist/utils/proxies.d.ts +4 -2
  434. package/dist/utils/proxies.js +150 -161
  435. package/dist/utils/proxies.js.map +1 -0
  436. package/dist/utils/react.d.cts +25 -0
  437. package/dist/utils/react.d.ts +9 -6
  438. package/dist/utils/react.js +88 -134
  439. package/dist/utils/react.js.map +1 -0
  440. package/dist/utils/results.d.cts +78 -0
  441. package/dist/utils/results.d.ts +10 -9
  442. package/dist/utils/results.js +143 -324
  443. package/dist/utils/results.js.map +1 -0
  444. package/dist/utils/sentry.d.cts +5 -0
  445. package/dist/utils/sentry.d.ts +5 -2
  446. package/dist/utils/sentry.js +44 -14
  447. package/dist/utils/sentry.js.map +1 -0
  448. package/dist/utils/stores.d.cts +102 -0
  449. package/dist/utils/stores.d.ts +12 -9
  450. package/dist/utils/stores.js +219 -189
  451. package/dist/utils/stores.js.map +1 -0
  452. package/dist/utils/strings.d.cts +72 -0
  453. package/dist/utils/strings.d.ts +22 -20
  454. package/dist/utils/strings.js +300 -580
  455. package/dist/utils/strings.js.map +1 -0
  456. package/dist/utils/strings.nicify.test.d.cts +2 -0
  457. package/dist/utils/strings.nicify.test.d.ts +2 -1
  458. package/dist/utils/strings.nicify.test.js +168 -158
  459. package/dist/utils/strings.nicify.test.js.map +1 -0
  460. package/dist/utils/types.d.cts +23 -0
  461. package/dist/utils/types.d.ts +8 -6
  462. package/dist/utils/types.js +19 -1
  463. package/dist/utils/types.js.map +1 -0
  464. package/dist/utils/unicode.d.cts +3 -0
  465. package/dist/utils/unicode.d.ts +3 -1
  466. package/dist/utils/unicode.js +34 -21
  467. package/dist/utils/unicode.js.map +1 -0
  468. package/dist/utils/urls.d.cts +20 -0
  469. package/dist/utils/urls.d.ts +10 -8
  470. package/dist/utils/urls.js +76 -165
  471. package/dist/utils/urls.js.map +1 -0
  472. package/dist/utils/uuids.d.cts +4 -0
  473. package/dist/utils/uuids.d.ts +4 -2
  474. package/dist/utils/uuids.js +39 -35
  475. package/dist/utils/uuids.js.map +1 -0
  476. package/package.json +5 -5
@@ -0,0 +1,98 @@
1
+ import { RateLimitOptions, ReactPromise } from './promises.cjs';
2
+ import './results.cjs';
3
+
4
+ /**
5
+ * Can be used to cache the result of a function call, for example for the `use` hook in React.
6
+ */
7
+ declare function cacheFunction<F extends Function>(f: F): F;
8
+ type CacheStrategy = "write-only" | "read-write" | "never";
9
+ declare class AsyncCache<D extends any[], T> {
10
+ private readonly _fetcher;
11
+ private readonly _options;
12
+ private readonly _map;
13
+ constructor(_fetcher: (dependencies: D) => Promise<T>, _options?: {
14
+ onSubscribe?: (key: D, refresh: () => void) => (() => void);
15
+ rateLimiter?: Omit<RateLimitOptions, "batchCalls">;
16
+ });
17
+ private _createKeyed;
18
+ getValueCache(dependencies: D): AsyncValueCache<T>;
19
+ refreshWhere(predicate: (dependencies: D) => boolean): Promise<void>;
20
+ readonly isCacheAvailable: (key: D) => boolean;
21
+ readonly getIfCached: (key: D) => ({
22
+ status: "error";
23
+ error: unknown;
24
+ } & {
25
+ status: "error";
26
+ }) | ({
27
+ status: "pending";
28
+ } & {
29
+ progress: void;
30
+ } & {
31
+ status: "pending";
32
+ }) | ({
33
+ status: "ok";
34
+ data: T;
35
+ } & {
36
+ status: "ok";
37
+ });
38
+ readonly getOrWait: (key: D, cacheStrategy: CacheStrategy) => ReactPromise<T>;
39
+ readonly forceSetCachedValue: (key: D, value: T) => void;
40
+ readonly forceSetCachedValueAsync: (key: D, value: Promise<T>) => ReactPromise<boolean>;
41
+ readonly refresh: (key: D) => Promise<T>;
42
+ readonly invalidate: (key: D) => void;
43
+ readonly onStateChange: (key: D, callback: (value: T, oldValue: T | undefined) => void) => {
44
+ unsubscribe: () => void;
45
+ };
46
+ }
47
+ declare class AsyncValueCache<T> {
48
+ private readonly _options;
49
+ private _store;
50
+ private _pendingPromise;
51
+ private _fetcher;
52
+ private readonly _rateLimitOptions;
53
+ private _subscriptionsCount;
54
+ private _unsubscribers;
55
+ private _mostRecentRefreshPromiseIndex;
56
+ constructor(fetcher: () => Promise<T>, _options?: {
57
+ onSubscribe?: (refresh: () => void) => (() => void);
58
+ rateLimiter?: Omit<RateLimitOptions, "batchCalls">;
59
+ });
60
+ isCacheAvailable(): boolean;
61
+ getIfCached(): ({
62
+ status: "error";
63
+ error: unknown;
64
+ } & {
65
+ status: "error";
66
+ }) | ({
67
+ status: "pending";
68
+ } & {
69
+ progress: void;
70
+ } & {
71
+ status: "pending";
72
+ }) | ({
73
+ status: "ok";
74
+ data: T;
75
+ } & {
76
+ status: "ok";
77
+ });
78
+ getOrWait(cacheStrategy: CacheStrategy): ReactPromise<T>;
79
+ private _set;
80
+ private _setAsync;
81
+ private _refetch;
82
+ forceSetCachedValue(value: T): void;
83
+ forceSetCachedValueAsync(value: Promise<T>): ReactPromise<boolean>;
84
+ /**
85
+ * Refetches the value from the fetcher, and updates the cache with it.
86
+ */
87
+ refresh(): Promise<T>;
88
+ /**
89
+ * Invalidates the cache, marking it to refresh on the next read. If anyone was listening to it, it will refresh
90
+ * immediately.
91
+ */
92
+ invalidate(): void;
93
+ onStateChange(callback: (value: T, oldValue: T | undefined) => void): {
94
+ unsubscribe: () => void;
95
+ };
96
+ }
97
+
98
+ export { AsyncCache, cacheFunction };
@@ -1,10 +1,12 @@
1
- import { RateLimitOptions, ReactPromise } from "./promises";
1
+ import { RateLimitOptions, ReactPromise } from './promises.js';
2
+ import './results.js';
3
+
2
4
  /**
3
5
  * Can be used to cache the result of a function call, for example for the `use` hook in React.
4
6
  */
5
- export declare function cacheFunction<F extends Function>(f: F): F;
7
+ declare function cacheFunction<F extends Function>(f: F): F;
6
8
  type CacheStrategy = "write-only" | "read-write" | "never";
7
- export declare class AsyncCache<D extends any[], T> {
9
+ declare class AsyncCache<D extends any[], T> {
8
10
  private readonly _fetcher;
9
11
  private readonly _options;
10
12
  private readonly _map;
@@ -17,16 +19,16 @@ export declare class AsyncCache<D extends any[], T> {
17
19
  refreshWhere(predicate: (dependencies: D) => boolean): Promise<void>;
18
20
  readonly isCacheAvailable: (key: D) => boolean;
19
21
  readonly getIfCached: (key: D) => ({
22
+ status: "error";
23
+ error: unknown;
24
+ } & {
25
+ status: "error";
26
+ }) | ({
20
27
  status: "pending";
21
28
  } & {
22
29
  progress: void;
23
30
  } & {
24
31
  status: "pending";
25
- }) | ({
26
- status: "error";
27
- error: unknown;
28
- } & {
29
- status: "error";
30
32
  }) | ({
31
33
  status: "ok";
32
34
  data: T;
@@ -57,16 +59,16 @@ declare class AsyncValueCache<T> {
57
59
  });
58
60
  isCacheAvailable(): boolean;
59
61
  getIfCached(): ({
62
+ status: "error";
63
+ error: unknown;
64
+ } & {
65
+ status: "error";
66
+ }) | ({
60
67
  status: "pending";
61
68
  } & {
62
69
  progress: void;
63
70
  } & {
64
71
  status: "pending";
65
- }) | ({
66
- status: "error";
67
- error: unknown;
68
- } & {
69
- status: "error";
70
72
  }) | ({
71
73
  status: "ok";
72
74
  data: T;
@@ -92,4 +94,5 @@ declare class AsyncValueCache<T> {
92
94
  unsubscribe: () => void;
93
95
  };
94
96
  }
95
- export {};
97
+
98
+ export { AsyncCache, cacheFunction };
@@ -1,198 +1,193 @@
1
- import { DependenciesMap } from "./maps";
2
- import { filterUndefined } from "./objects";
3
- import { pending, rateLimited, resolved, runAsynchronously, wait } from "./promises";
4
- import { AsyncStore } from "./stores";
5
- /**
6
- * Can be used to cache the result of a function call, for example for the `use` hook in React.
7
- */
8
- export function cacheFunction(f) {
9
- const dependenciesMap = new DependenciesMap();
10
- return ((...args) => {
11
- if (dependenciesMap.has(args)) {
12
- return dependenciesMap.get(args);
13
- }
14
- const value = f(...args);
15
- dependenciesMap.set(args, value);
16
- return value;
17
- });
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/caches.tsx
21
+ var caches_exports = {};
22
+ __export(caches_exports, {
23
+ AsyncCache: () => AsyncCache,
24
+ cacheFunction: () => cacheFunction
25
+ });
26
+ module.exports = __toCommonJS(caches_exports);
27
+ var import_maps = require("./maps");
28
+ var import_objects = require("./objects");
29
+ var import_promises = require("./promises");
30
+ var import_stores = require("./stores");
31
+ function cacheFunction(f) {
32
+ const dependenciesMap = new import_maps.DependenciesMap();
33
+ return (...args) => {
34
+ if (dependenciesMap.has(args)) {
35
+ return dependenciesMap.get(args);
36
+ }
37
+ const value = f(...args);
38
+ dependenciesMap.set(args, value);
39
+ return value;
40
+ };
18
41
  }
19
- import.meta.vitest?.test("cacheFunction", ({ expect }) => {
20
- // Test with a simple function
21
- let callCount = 0;
22
- const add = (a, b) => {
23
- callCount++;
24
- return a + b;
25
- };
26
- const cachedAdd = cacheFunction(add);
27
- // First call should execute the function
28
- expect(cachedAdd(1, 2)).toBe(3);
29
- expect(callCount).toBe(1);
30
- // Second call with same args should use cached result
31
- expect(cachedAdd(1, 2)).toBe(3);
32
- expect(callCount).toBe(1);
33
- // Call with different args should execute the function again
34
- expect(cachedAdd(2, 3)).toBe(5);
35
- expect(callCount).toBe(2);
36
- // Test with a function that returns objects
37
- let objectCallCount = 0;
38
- const createObject = (id) => {
39
- objectCallCount++;
40
- return { id };
42
+ var AsyncCache = class {
43
+ constructor(_fetcher, _options = {}) {
44
+ this._fetcher = _fetcher;
45
+ this._options = _options;
46
+ this._map = new import_maps.DependenciesMap();
47
+ this.isCacheAvailable = this._createKeyed("isCacheAvailable");
48
+ this.getIfCached = this._createKeyed("getIfCached");
49
+ this.getOrWait = this._createKeyed("getOrWait");
50
+ this.forceSetCachedValue = this._createKeyed("forceSetCachedValue");
51
+ this.forceSetCachedValueAsync = this._createKeyed("forceSetCachedValueAsync");
52
+ this.refresh = this._createKeyed("refresh");
53
+ this.invalidate = this._createKeyed("invalidate");
54
+ this.onStateChange = this._createKeyed("onStateChange");
55
+ }
56
+ _createKeyed(functionName) {
57
+ return (key, ...args) => {
58
+ const valueCache = this.getValueCache(key);
59
+ return valueCache[functionName].apply(valueCache, args);
41
60
  };
42
- const cachedCreateObject = cacheFunction(createObject);
43
- // First call should execute the function
44
- const obj1 = cachedCreateObject(1);
45
- expect(obj1).toEqual({ id: 1 });
46
- expect(objectCallCount).toBe(1);
47
- // Second call with same args should use cached result
48
- const obj2 = cachedCreateObject(1);
49
- expect(obj2).toBe(obj1); // Same reference
50
- expect(objectCallCount).toBe(1);
51
- });
52
- export class AsyncCache {
53
- constructor(_fetcher, _options = {}) {
54
- this._fetcher = _fetcher;
55
- this._options = _options;
56
- this._map = new DependenciesMap();
57
- this.isCacheAvailable = this._createKeyed("isCacheAvailable");
58
- this.getIfCached = this._createKeyed("getIfCached");
59
- this.getOrWait = this._createKeyed("getOrWait");
60
- this.forceSetCachedValue = this._createKeyed("forceSetCachedValue");
61
- this.forceSetCachedValueAsync = this._createKeyed("forceSetCachedValueAsync");
62
- this.refresh = this._createKeyed("refresh");
63
- this.invalidate = this._createKeyed("invalidate");
64
- this.onStateChange = this._createKeyed("onStateChange");
65
- // nothing here yet
66
- }
67
- _createKeyed(functionName) {
68
- return (key, ...args) => {
69
- const valueCache = this.getValueCache(key);
70
- return valueCache[functionName].apply(valueCache, args);
71
- };
72
- }
73
- getValueCache(dependencies) {
74
- let cache = this._map.get(dependencies);
75
- if (!cache) {
76
- cache = new AsyncValueCache(async () => await this._fetcher(dependencies), {
77
- ...this._options,
78
- onSubscribe: this._options.onSubscribe ? (cb) => this._options.onSubscribe(dependencies, cb) : undefined,
79
- });
80
- this._map.set(dependencies, cache);
61
+ }
62
+ getValueCache(dependencies) {
63
+ let cache = this._map.get(dependencies);
64
+ if (!cache) {
65
+ cache = new AsyncValueCache(
66
+ async () => await this._fetcher(dependencies),
67
+ {
68
+ ...this._options,
69
+ onSubscribe: this._options.onSubscribe ? (cb) => this._options.onSubscribe(dependencies, cb) : void 0
81
70
  }
82
- return cache;
83
- }
84
- async refreshWhere(predicate) {
85
- const promises = [];
86
- for (const [dependencies, cache] of this._map) {
87
- if (predicate(dependencies)) {
88
- promises.push(cache.refresh());
71
+ );
72
+ this._map.set(dependencies, cache);
73
+ }
74
+ return cache;
75
+ }
76
+ async refreshWhere(predicate) {
77
+ const promises = [];
78
+ for (const [dependencies, cache] of this._map) {
79
+ if (predicate(dependencies)) {
80
+ promises.push(cache.refresh());
81
+ }
82
+ }
83
+ await Promise.all(promises);
84
+ }
85
+ };
86
+ var AsyncValueCache = class {
87
+ constructor(fetcher, _options = {}) {
88
+ this._options = _options;
89
+ this._subscriptionsCount = 0;
90
+ this._unsubscribers = [];
91
+ this._mostRecentRefreshPromiseIndex = 0;
92
+ this._store = new import_stores.AsyncStore();
93
+ this._rateLimitOptions = {
94
+ concurrency: 1,
95
+ throttleMs: 300,
96
+ ...(0, import_objects.filterUndefined)(_options.rateLimiter ?? {})
97
+ };
98
+ this._fetcher = (0, import_promises.rateLimited)(fetcher, {
99
+ ...this._rateLimitOptions,
100
+ batchCalls: true
101
+ });
102
+ }
103
+ isCacheAvailable() {
104
+ return this._store.isAvailable();
105
+ }
106
+ getIfCached() {
107
+ return this._store.get();
108
+ }
109
+ getOrWait(cacheStrategy) {
110
+ const cached = this.getIfCached();
111
+ if (cacheStrategy === "read-write" && cached.status === "ok") {
112
+ return (0, import_promises.resolved)(cached.data);
113
+ }
114
+ return this._refetch(cacheStrategy);
115
+ }
116
+ _set(value) {
117
+ this._store.set(value);
118
+ }
119
+ _setAsync(value) {
120
+ const promise = (0, import_promises.pending)(value);
121
+ this._pendingPromise = promise;
122
+ return (0, import_promises.pending)(this._store.setAsync(promise));
123
+ }
124
+ _refetch(cacheStrategy) {
125
+ if (cacheStrategy === "read-write" && this._pendingPromise) {
126
+ return this._pendingPromise;
127
+ }
128
+ const promise = (0, import_promises.pending)(this._fetcher());
129
+ if (cacheStrategy === "never") {
130
+ return promise;
131
+ }
132
+ return (0, import_promises.pending)(this._setAsync(promise).then(() => promise));
133
+ }
134
+ forceSetCachedValue(value) {
135
+ this._set(value);
136
+ }
137
+ forceSetCachedValueAsync(value) {
138
+ return this._setAsync(value);
139
+ }
140
+ /**
141
+ * Refetches the value from the fetcher, and updates the cache with it.
142
+ */
143
+ async refresh() {
144
+ return await this.getOrWait("write-only");
145
+ }
146
+ /**
147
+ * Invalidates the cache, marking it to refresh on the next read. If anyone was listening to it, it will refresh
148
+ * immediately.
149
+ */
150
+ invalidate() {
151
+ this._store.setUnavailable();
152
+ this._pendingPromise = void 0;
153
+ if (this._subscriptionsCount > 0) {
154
+ (0, import_promises.runAsynchronously)(this.refresh());
155
+ }
156
+ }
157
+ onStateChange(callback) {
158
+ const storeObj = this._store.onChange(callback);
159
+ (0, import_promises.runAsynchronously)(this.getOrWait("read-write"));
160
+ if (this._subscriptionsCount++ === 0 && this._options.onSubscribe) {
161
+ const unsubscribe = this._options.onSubscribe(() => {
162
+ (0, import_promises.runAsynchronously)(this.refresh());
163
+ });
164
+ this._unsubscribers.push(unsubscribe);
165
+ }
166
+ let hasUnsubscribed = false;
167
+ return {
168
+ unsubscribe: () => {
169
+ if (hasUnsubscribed) return;
170
+ hasUnsubscribed = true;
171
+ storeObj.unsubscribe();
172
+ if (--this._subscriptionsCount === 0) {
173
+ const currentRefreshPromiseIndex = ++this._mostRecentRefreshPromiseIndex;
174
+ (0, import_promises.runAsynchronously)(async () => {
175
+ await (0, import_promises.wait)(5e3);
176
+ if (this._subscriptionsCount === 0 && currentRefreshPromiseIndex === this._mostRecentRefreshPromiseIndex) {
177
+ this.invalidate();
89
178
  }
179
+ });
180
+ for (const unsubscribe of this._unsubscribers) {
181
+ unsubscribe();
182
+ }
90
183
  }
91
- await Promise.all(promises);
92
- }
93
- }
94
- class AsyncValueCache {
95
- constructor(fetcher, _options = {}) {
96
- this._options = _options;
97
- this._subscriptionsCount = 0;
98
- this._unsubscribers = [];
99
- this._mostRecentRefreshPromiseIndex = 0;
100
- this._store = new AsyncStore();
101
- this._rateLimitOptions = {
102
- concurrency: 1,
103
- throttleMs: 300,
104
- ...filterUndefined(_options.rateLimiter ?? {}),
105
- };
106
- this._fetcher = rateLimited(fetcher, {
107
- ...this._rateLimitOptions,
108
- batchCalls: true,
109
- });
110
- }
111
- isCacheAvailable() {
112
- return this._store.isAvailable();
113
- }
114
- getIfCached() {
115
- return this._store.get();
116
- }
117
- getOrWait(cacheStrategy) {
118
- const cached = this.getIfCached();
119
- if (cacheStrategy === "read-write" && cached.status === "ok") {
120
- return resolved(cached.data);
121
- }
122
- return this._refetch(cacheStrategy);
123
- }
124
- _set(value) {
125
- this._store.set(value);
126
- }
127
- _setAsync(value) {
128
- const promise = pending(value);
129
- this._pendingPromise = promise;
130
- return pending(this._store.setAsync(promise));
131
- }
132
- _refetch(cacheStrategy) {
133
- if (cacheStrategy === "read-write" && this._pendingPromise) {
134
- return this._pendingPromise;
135
- }
136
- const promise = pending(this._fetcher());
137
- if (cacheStrategy === "never") {
138
- return promise;
139
- }
140
- return pending(this._setAsync(promise).then(() => promise));
141
- }
142
- forceSetCachedValue(value) {
143
- this._set(value);
144
- }
145
- forceSetCachedValueAsync(value) {
146
- return this._setAsync(value);
147
- }
148
- /**
149
- * Refetches the value from the fetcher, and updates the cache with it.
150
- */
151
- async refresh() {
152
- return await this.getOrWait("write-only");
153
- }
154
- /**
155
- * Invalidates the cache, marking it to refresh on the next read. If anyone was listening to it, it will refresh
156
- * immediately.
157
- */
158
- invalidate() {
159
- this._store.setUnavailable();
160
- this._pendingPromise = undefined;
161
- if (this._subscriptionsCount > 0) {
162
- runAsynchronously(this.refresh());
163
- }
164
- }
165
- onStateChange(callback) {
166
- const storeObj = this._store.onChange(callback);
167
- runAsynchronously(this.getOrWait("read-write"));
168
- if (this._subscriptionsCount++ === 0 && this._options.onSubscribe) {
169
- const unsubscribe = this._options.onSubscribe(() => {
170
- runAsynchronously(this.refresh());
171
- });
172
- this._unsubscribers.push(unsubscribe);
173
- }
174
- let hasUnsubscribed = false;
175
- return {
176
- unsubscribe: () => {
177
- if (hasUnsubscribed)
178
- return;
179
- hasUnsubscribed = true;
180
- storeObj.unsubscribe();
181
- if (--this._subscriptionsCount === 0) {
182
- const currentRefreshPromiseIndex = ++this._mostRecentRefreshPromiseIndex;
183
- runAsynchronously(async () => {
184
- // wait a few seconds; if anything changes during that time, we don't want to refresh
185
- // else we do unnecessary requests if we unsubscribe and then subscribe again immediately
186
- await wait(5000);
187
- if (this._subscriptionsCount === 0 && currentRefreshPromiseIndex === this._mostRecentRefreshPromiseIndex) {
188
- this.invalidate();
189
- }
190
- });
191
- for (const unsubscribe of this._unsubscribers) {
192
- unsubscribe();
193
- }
194
- }
195
- },
196
- };
197
- }
198
- }
184
+ }
185
+ };
186
+ }
187
+ };
188
+ // Annotate the CommonJS export names for ESM import in node:
189
+ 0 && (module.exports = {
190
+ AsyncCache,
191
+ cacheFunction
192
+ });
193
+ //# sourceMappingURL=caches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/caches.tsx"],"sourcesContent":["import { DependenciesMap } from \"./maps\";\nimport { filterUndefined } from \"./objects\";\nimport { RateLimitOptions, ReactPromise, pending, rateLimited, resolved, runAsynchronously, wait } from \"./promises\";\nimport { AsyncStore } from \"./stores\";\n\n/**\n * Can be used to cache the result of a function call, for example for the `use` hook in React.\n */\nexport function cacheFunction<F extends Function>(f: F): F {\n const dependenciesMap = new DependenciesMap<any, any>();\n\n return ((...args: any) => {\n if (dependenciesMap.has(args)) {\n return dependenciesMap.get(args);\n }\n\n const value = f(...args);\n dependenciesMap.set(args, value);\n return value;\n }) as any as F;\n}\nundefined?.test(\"cacheFunction\", ({ expect }) => {\n // Test with a simple function\n let callCount = 0;\n const add = (a: number, b: number) => {\n callCount++;\n return a + b;\n };\n\n const cachedAdd = cacheFunction(add);\n\n // First call should execute the function\n expect(cachedAdd(1, 2)).toBe(3);\n expect(callCount).toBe(1);\n\n // Second call with same args should use cached result\n expect(cachedAdd(1, 2)).toBe(3);\n expect(callCount).toBe(1);\n\n // Call with different args should execute the function again\n expect(cachedAdd(2, 3)).toBe(5);\n expect(callCount).toBe(2);\n\n // Test with a function that returns objects\n let objectCallCount = 0;\n const createObject = (id: number) => {\n objectCallCount++;\n return { id };\n };\n\n const cachedCreateObject = cacheFunction(createObject);\n\n // First call should execute the function\n const obj1 = cachedCreateObject(1);\n expect(obj1).toEqual({ id: 1 });\n expect(objectCallCount).toBe(1);\n\n // Second call with same args should use cached result\n const obj2 = cachedCreateObject(1);\n expect(obj2).toBe(obj1); // Same reference\n expect(objectCallCount).toBe(1);\n});\n\n\ntype CacheStrategy = \"write-only\" | \"read-write\" | \"never\";\n\nexport class AsyncCache<D extends any[], T> {\n private readonly _map = new DependenciesMap<D, AsyncValueCache<T>>();\n\n constructor(\n private readonly _fetcher: (dependencies: D) => Promise<T>,\n private readonly _options: {\n onSubscribe?: (key: D, refresh: () => void) => (() => void),\n rateLimiter?: Omit<RateLimitOptions, \"batchCalls\">,\n } = {},\n ) {\n // nothing here yet\n }\n\n private _createKeyed<FunctionName extends keyof AsyncValueCache<T>>(\n functionName: FunctionName,\n ): (key: D, ...args: Parameters<AsyncValueCache<T>[FunctionName]>) => ReturnType<AsyncValueCache<T>[FunctionName]> {\n return (key: D, ...args) => {\n const valueCache = this.getValueCache(key);\n return (valueCache[functionName] as any).apply(valueCache, args);\n };\n }\n\n getValueCache(dependencies: D): AsyncValueCache<T> {\n let cache = this._map.get(dependencies);\n if (!cache) {\n cache = new AsyncValueCache(\n async () => await this._fetcher(dependencies),\n {\n ...this._options,\n onSubscribe: this._options.onSubscribe ? (cb) => this._options.onSubscribe!(dependencies, cb) : undefined,\n },\n );\n this._map.set(dependencies, cache);\n }\n return cache;\n }\n\n async refreshWhere(predicate: (dependencies: D) => boolean) {\n const promises: Promise<T>[] = [];\n for (const [dependencies, cache] of this._map) {\n if (predicate(dependencies)) {\n promises.push(cache.refresh());\n }\n }\n await Promise.all(promises);\n }\n\n readonly isCacheAvailable = this._createKeyed(\"isCacheAvailable\");\n readonly getIfCached = this._createKeyed(\"getIfCached\");\n readonly getOrWait = this._createKeyed(\"getOrWait\");\n readonly forceSetCachedValue = this._createKeyed(\"forceSetCachedValue\");\n readonly forceSetCachedValueAsync = this._createKeyed(\"forceSetCachedValueAsync\");\n readonly refresh = this._createKeyed(\"refresh\");\n readonly invalidate = this._createKeyed(\"invalidate\");\n readonly onStateChange = this._createKeyed(\"onStateChange\");\n}\n\nclass AsyncValueCache<T> {\n private _store: AsyncStore<T>;\n private _pendingPromise: ReactPromise<T> | undefined;\n private _fetcher: () => Promise<T>;\n private readonly _rateLimitOptions: Omit<RateLimitOptions, \"batchCalls\">;\n private _subscriptionsCount = 0;\n private _unsubscribers: (() => void)[] = [];\n private _mostRecentRefreshPromiseIndex = 0;\n\n constructor(\n fetcher: () => Promise<T>,\n private readonly _options: {\n onSubscribe?: (refresh: () => void) => (() => void),\n rateLimiter?: Omit<RateLimitOptions, \"batchCalls\">,\n } = {},\n ) {\n this._store = new AsyncStore();\n this._rateLimitOptions = {\n concurrency: 1,\n throttleMs: 300,\n ...filterUndefined(_options.rateLimiter ?? {}),\n };\n\n\n this._fetcher = rateLimited(fetcher, {\n ...this._rateLimitOptions,\n batchCalls: true,\n });\n }\n\n isCacheAvailable(): boolean {\n return this._store.isAvailable();\n }\n\n getIfCached() {\n return this._store.get();\n }\n\n getOrWait(cacheStrategy: CacheStrategy): ReactPromise<T> {\n const cached = this.getIfCached();\n if (cacheStrategy === \"read-write\" && cached.status === \"ok\") {\n return resolved(cached.data);\n }\n\n return this._refetch(cacheStrategy);\n }\n\n private _set(value: T): void {\n this._store.set(value);\n }\n\n private _setAsync(value: Promise<T>): ReactPromise<boolean> {\n const promise = pending(value);\n this._pendingPromise = promise;\n return pending(this._store.setAsync(promise));\n }\n\n private _refetch(cacheStrategy: CacheStrategy): ReactPromise<T> {\n if (cacheStrategy === \"read-write\" && this._pendingPromise) {\n return this._pendingPromise;\n }\n const promise = pending(this._fetcher());\n if (cacheStrategy === \"never\") {\n return promise;\n }\n return pending(this._setAsync(promise).then(() => promise));\n }\n\n forceSetCachedValue(value: T): void {\n this._set(value);\n }\n\n forceSetCachedValueAsync(value: Promise<T>): ReactPromise<boolean> {\n return this._setAsync(value);\n }\n\n /**\n * Refetches the value from the fetcher, and updates the cache with it.\n */\n async refresh(): Promise<T> {\n return await this.getOrWait(\"write-only\");\n }\n\n /**\n * Invalidates the cache, marking it to refresh on the next read. If anyone was listening to it, it will refresh\n * immediately.\n */\n invalidate(): void {\n this._store.setUnavailable();\n this._pendingPromise = undefined;\n if (this._subscriptionsCount > 0) {\n runAsynchronously(this.refresh());\n }\n }\n\n onStateChange(callback: (value: T, oldValue: T | undefined) => void): { unsubscribe: () => void } {\n const storeObj = this._store.onChange(callback);\n\n runAsynchronously(this.getOrWait(\"read-write\"));\n\n if (this._subscriptionsCount++ === 0 && this._options.onSubscribe) {\n const unsubscribe = this._options.onSubscribe(() => {\n runAsynchronously(this.refresh());\n });\n this._unsubscribers.push(unsubscribe);\n }\n\n let hasUnsubscribed = false;\n return {\n unsubscribe: () => {\n if (hasUnsubscribed) return;\n hasUnsubscribed = true;\n storeObj.unsubscribe();\n if (--this._subscriptionsCount === 0) {\n const currentRefreshPromiseIndex = ++this._mostRecentRefreshPromiseIndex;\n runAsynchronously(async () => {\n // wait a few seconds; if anything changes during that time, we don't want to refresh\n // else we do unnecessary requests if we unsubscribe and then subscribe again immediately\n await wait(5000);\n if (this._subscriptionsCount === 0 && currentRefreshPromiseIndex === this._mostRecentRefreshPromiseIndex) {\n this.invalidate();\n }\n });\n\n for (const unsubscribe of this._unsubscribers) {\n unsubscribe();\n }\n }\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,wBAAwB,KAAK,+BAA+B,KAAK,gCAAgC;AACxG,mBAAK,WAAW;AAAA,YAClB;AAAA,UACF,CAAC;AAED,qBAAW,eAAe,KAAK,gBAAgB;AAC7C,wBAAY;AAAA,UACd;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the first argument passed to it, but compilers won't be able to optimize it out. This is useful in some
3
+ * cases where compiler warnings go awry; for example, when importing things that may not exist (but are guaranteed
4
+ * to exist at runtime).
5
+ */
6
+ declare function scrambleDuringCompileTime<T>(t: T): T;
7
+
8
+ export { scrambleDuringCompileTime };
@@ -3,4 +3,6 @@
3
3
  * cases where compiler warnings go awry; for example, when importing things that may not exist (but are guaranteed
4
4
  * to exist at runtime).
5
5
  */
6
- export declare function scrambleDuringCompileTime<T>(t: T): T;
6
+ declare function scrambleDuringCompileTime<T>(t: T): T;
7
+
8
+ export { scrambleDuringCompileTime };
@@ -1,11 +1,36 @@
1
- /**
2
- * Returns the first argument passed to it, but compilers won't be able to optimize it out. This is useful in some
3
- * cases where compiler warnings go awry; for example, when importing things that may not exist (but are guaranteed
4
- * to exist at runtime).
5
- */
6
- export function scrambleDuringCompileTime(t) {
7
- if (Math.random() < 0.00001 && Math.random() > 0.99999 && Math.random() < 0.00001 && Math.random() > 0.99999) {
8
- return "this will never happen";
9
- }
10
- return t;
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/compile-time.tsx
21
+ var compile_time_exports = {};
22
+ __export(compile_time_exports, {
23
+ scrambleDuringCompileTime: () => scrambleDuringCompileTime
24
+ });
25
+ module.exports = __toCommonJS(compile_time_exports);
26
+ function scrambleDuringCompileTime(t) {
27
+ if (Math.random() < 1e-5 && Math.random() > 0.99999 && Math.random() < 1e-5 && Math.random() > 0.99999) {
28
+ return "this will never happen";
29
+ }
30
+ return t;
11
31
  }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ scrambleDuringCompileTime
35
+ });
36
+ //# sourceMappingURL=compile-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/compile-time.tsx"],"sourcesContent":["/**\n * Returns the first argument passed to it, but compilers won't be able to optimize it out. This is useful in some\n * cases where compiler warnings go awry; for example, when importing things that may not exist (but are guaranteed\n * to exist at runtime).\n */\nexport function scrambleDuringCompileTime<T>(t: T): T {\n if (Math.random() < 0.00001 && Math.random() > 0.99999 && Math.random() < 0.00001 && Math.random() > 0.99999) {\n return \"this will never happen\" as any;\n }\n return t;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,0BAA6B,GAAS;AACpD,MAAI,KAAK,OAAO,IAAI,QAAW,KAAK,OAAO,IAAI,WAAW,KAAK,OAAO,IAAI,QAAW,KAAK,OAAO,IAAI,SAAS;AAC5G,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ declare function generateRandomValues(array: Uint8Array): typeof array;
2
+ /**
3
+ * Generates a secure alphanumeric string using the system's cryptographically secure
4
+ * random number generator.
5
+ */
6
+ declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
7
+
8
+ export { generateRandomValues, generateSecureRandomString };
@@ -1,6 +1,8 @@
1
- export declare function generateRandomValues(array: Uint8Array): typeof array;
1
+ declare function generateRandomValues(array: Uint8Array): typeof array;
2
2
  /**
3
3
  * Generates a secure alphanumeric string using the system's cryptographically secure
4
4
  * random number generator.
5
5
  */
6
- export declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
6
+ declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
7
+
8
+ export { generateRandomValues, generateSecureRandomString };