@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.
- package/CHANGELOG.md +14 -0
- package/dist/config/format.d.cts +39 -0
- package/dist/config/format.d.ts +14 -13
- package/dist/config/format.js +147 -206
- package/dist/config/format.js.map +1 -0
- package/dist/config/schema.d.cts +729 -0
- package/dist/config/schema.d.ts +59 -51
- package/dist/config/schema.js +232 -172
- package/dist/config/schema.js.map +1 -0
- package/dist/crud.d.cts +102 -0
- package/dist/crud.d.ts +15 -13
- package/dist/crud.js +83 -128
- package/dist/crud.js.map +1 -0
- package/dist/esm/config/format.js +135 -0
- package/dist/esm/config/format.js.map +1 -0
- package/dist/esm/config/schema.js +201 -0
- package/dist/esm/config/schema.js.map +1 -0
- package/dist/esm/crud.js +60 -0
- package/dist/esm/crud.js.map +1 -0
- package/dist/esm/global.d.js +1 -0
- package/dist/esm/global.d.js.map +1 -0
- package/dist/esm/helpers/password.js +17 -0
- package/dist/esm/helpers/password.js.map +1 -0
- package/dist/esm/helpers/production-mode.js +50 -0
- package/dist/esm/helpers/production-mode.js.map +1 -0
- package/dist/esm/hooks/use-async-callback.js +38 -0
- package/dist/esm/hooks/use-async-callback.js.map +1 -0
- package/dist/esm/hooks/use-async-external-store.js +23 -0
- package/dist/esm/hooks/use-async-external-store.js.map +1 -0
- package/dist/esm/hooks/use-hash.js +17 -0
- package/dist/esm/hooks/use-hash.js.map +1 -0
- package/dist/esm/hooks/use-strict-memo.js +61 -0
- package/dist/esm/hooks/use-strict-memo.js.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interface/adminInterface.js +244 -0
- package/dist/esm/interface/adminInterface.js.map +1 -0
- package/dist/esm/interface/clientInterface.js +2041 -0
- package/dist/esm/interface/clientInterface.js.map +1 -0
- package/dist/esm/interface/crud/contact-channels.js +77 -0
- package/dist/esm/interface/crud/contact-channels.js.map +1 -0
- package/dist/esm/interface/crud/current-user.js +65 -0
- package/dist/esm/interface/crud/current-user.js.map +1 -0
- package/dist/esm/interface/crud/email-templates.js +52 -0
- package/dist/esm/interface/crud/email-templates.js.map +1 -0
- package/dist/esm/interface/crud/emails.js +20 -0
- package/dist/esm/interface/crud/emails.js.map +1 -0
- package/dist/esm/interface/crud/internal-api-keys.js +69 -0
- package/dist/esm/interface/crud/internal-api-keys.js.map +1 -0
- package/dist/esm/interface/crud/oauth.js +24 -0
- package/dist/esm/interface/crud/oauth.js.map +1 -0
- package/dist/esm/interface/crud/project-api-keys.js +93 -0
- package/dist/esm/interface/crud/project-api-keys.js.map +1 -0
- package/dist/esm/interface/crud/project-permissions.js +113 -0
- package/dist/esm/interface/crud/project-permissions.js.map +1 -0
- package/dist/esm/interface/crud/projects.js +180 -0
- package/dist/esm/interface/crud/projects.js.map +1 -0
- package/dist/esm/interface/crud/sessions.js +62 -0
- package/dist/esm/interface/crud/sessions.js.map +1 -0
- package/dist/esm/interface/crud/svix-token.js +22 -0
- package/dist/esm/interface/crud/svix-token.js.map +1 -0
- package/dist/esm/interface/crud/team-invitation-details.js +23 -0
- package/dist/esm/interface/crud/team-invitation-details.js.map +1 -0
- package/dist/esm/interface/crud/team-invitation.js +36 -0
- package/dist/esm/interface/crud/team-invitation.js.map +1 -0
- package/dist/esm/interface/crud/team-member-profiles.js +62 -0
- package/dist/esm/interface/crud/team-member-profiles.js.map +1 -0
- package/dist/esm/interface/crud/team-memberships.js +60 -0
- package/dist/esm/interface/crud/team-memberships.js.map +1 -0
- package/dist/esm/interface/crud/team-permissions.js +114 -0
- package/dist/esm/interface/crud/team-permissions.js.map +1 -0
- package/dist/esm/interface/crud/teams.js +143 -0
- package/dist/esm/interface/crud/teams.js.map +1 -0
- package/dist/esm/interface/crud/users.js +139 -0
- package/dist/esm/interface/crud/users.js.map +1 -0
- package/dist/esm/interface/serverInterface.js +485 -0
- package/dist/esm/interface/serverInterface.js.map +1 -0
- package/dist/esm/interface/webhooks.js +21 -0
- package/dist/esm/interface/webhooks.js.map +1 -0
- package/dist/esm/known-errors.js +1238 -0
- package/dist/esm/known-errors.js.map +1 -0
- package/dist/esm/schema-fields.js +484 -0
- package/dist/esm/schema-fields.js.map +1 -0
- package/dist/esm/sessions.js +168 -0
- package/dist/esm/sessions.js.map +1 -0
- package/dist/esm/utils/api-keys.js +79 -0
- package/dist/esm/utils/api-keys.js.map +1 -0
- package/dist/esm/utils/arrays.js +78 -0
- package/dist/esm/utils/arrays.js.map +1 -0
- package/dist/esm/utils/base64.js +18 -0
- package/dist/esm/utils/base64.js.map +1 -0
- package/dist/esm/utils/booleans.js +12 -0
- package/dist/esm/utils/booleans.js.map +1 -0
- package/dist/esm/utils/browser-compat.js +21 -0
- package/dist/esm/utils/browser-compat.js.map +1 -0
- package/dist/esm/utils/bytes.js +160 -0
- package/dist/esm/utils/bytes.js.map +1 -0
- package/dist/esm/utils/caches.js +167 -0
- package/dist/esm/utils/caches.js.map +1 -0
- package/dist/esm/utils/compile-time.js +11 -0
- package/dist/esm/utils/compile-time.js.map +1 -0
- package/dist/esm/utils/crypto.js +25 -0
- package/dist/esm/utils/crypto.js.map +1 -0
- package/dist/esm/utils/dates.js +64 -0
- package/dist/esm/utils/dates.js.map +1 -0
- package/dist/esm/utils/dom.js +11 -0
- package/dist/esm/utils/dom.js.map +1 -0
- package/dist/esm/utils/env.js +58 -0
- package/dist/esm/utils/env.js.map +1 -0
- package/dist/esm/utils/errors.js +174 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/fs.js +37 -0
- package/dist/esm/utils/fs.js.map +1 -0
- package/dist/esm/utils/functions.js +12 -0
- package/dist/esm/utils/functions.js.map +1 -0
- package/dist/esm/utils/geo.js +15 -0
- package/dist/esm/utils/geo.js.map +1 -0
- package/dist/esm/utils/globals.js +18 -0
- package/dist/esm/utils/globals.js.map +1 -0
- package/dist/esm/utils/hashes.js +55 -0
- package/dist/esm/utils/hashes.js.map +1 -0
- package/dist/esm/utils/html.js +13 -0
- package/dist/esm/utils/html.js.map +1 -0
- package/dist/esm/utils/http.js +60 -0
- package/dist/esm/utils/http.js.map +1 -0
- package/dist/esm/utils/ips.js +15 -0
- package/dist/esm/utils/ips.js.map +1 -0
- package/dist/esm/utils/json.js +31 -0
- package/dist/esm/utils/json.js.map +1 -0
- package/dist/esm/utils/jwt.js +87 -0
- package/dist/esm/utils/jwt.js.map +1 -0
- package/dist/esm/utils/locks.js +57 -0
- package/dist/esm/utils/locks.js.map +1 -0
- package/dist/esm/utils/maps.js +181 -0
- package/dist/esm/utils/maps.js.map +1 -0
- package/dist/esm/utils/math.js +8 -0
- package/dist/esm/utils/math.js.map +1 -0
- package/dist/esm/utils/node-http.js +42 -0
- package/dist/esm/utils/node-http.js.map +1 -0
- package/dist/esm/utils/numbers.js +32 -0
- package/dist/esm/utils/numbers.js.map +1 -0
- package/dist/esm/utils/oauth.js +10 -0
- package/dist/esm/utils/oauth.js.map +1 -0
- package/dist/esm/utils/objects.js +177 -0
- package/dist/esm/utils/objects.js.map +1 -0
- package/dist/esm/utils/passkey.js +1 -0
- package/dist/esm/utils/passkey.js.map +1 -0
- package/dist/esm/utils/promises.js +233 -0
- package/dist/esm/utils/promises.js.map +1 -0
- package/dist/esm/utils/proxies.js +128 -0
- package/dist/esm/utils/proxies.js.map +1 -0
- package/dist/esm/utils/react.js +78 -0
- package/dist/esm/utils/react.js.map +1 -0
- package/dist/esm/utils/results.js +141 -0
- package/dist/esm/utils/results.js.map +1 -0
- package/dist/esm/utils/sentry.js +20 -0
- package/dist/esm/utils/sentry.js.map +1 -0
- package/dist/esm/utils/stores.js +195 -0
- package/dist/esm/utils/stores.js.map +1 -0
- package/dist/esm/utils/strings.js +295 -0
- package/dist/esm/utils/strings.js.map +1 -0
- package/dist/esm/utils/strings.nicify.test.js +222 -0
- package/dist/esm/utils/strings.nicify.test.js.map +1 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/utils/unicode.js +11 -0
- package/dist/esm/utils/unicode.js.map +1 -0
- package/dist/esm/utils/urls.js +53 -0
- package/dist/esm/utils/urls.js.map +1 -0
- package/dist/esm/utils/uuids.js +16 -0
- package/dist/esm/utils/uuids.js.map +1 -0
- package/dist/global.d.d.cts +1 -0
- package/dist/global.d.d.ts +1 -0
- package/dist/global.d.js +2 -0
- package/dist/global.d.js.map +1 -0
- package/dist/helpers/password.d.cts +11 -0
- package/dist/helpers/password.d.ts +11 -2
- package/dist/helpers/password.js +41 -11
- package/dist/helpers/password.js.map +1 -0
- package/dist/helpers/production-mode.d.cts +12 -0
- package/dist/helpers/production-mode.d.ts +9 -3
- package/dist/helpers/production-mode.js +72 -45
- package/dist/helpers/production-mode.js.map +1 -0
- package/dist/hooks/use-async-callback.d.cts +6 -0
- package/dist/hooks/use-async-callback.d.ts +6 -3
- package/dist/hooks/use-async-callback.js +72 -30
- package/dist/hooks/use-async-callback.js.map +1 -0
- package/dist/hooks/use-async-external-store.d.cts +7 -0
- package/dist/hooks/use-async-external-store.d.ts +5 -2
- package/dist/hooks/use-async-external-store.js +47 -19
- package/dist/hooks/use-async-external-store.js.map +1 -0
- package/dist/hooks/use-hash.d.cts +3 -0
- package/dist/hooks/use-hash.d.ts +3 -1
- package/dist/hooks/use-hash.js +41 -8
- package/dist/hooks/use-hash.js.map +1 -0
- package/dist/hooks/use-strict-memo.d.cts +8 -0
- package/dist/hooks/use-strict-memo.d.ts +3 -1
- package/dist/hooks/use-strict-memo.js +78 -131
- package/dist/hooks/use-strict-memo.js.map +1 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -4
- package/dist/index.js +42 -4
- package/dist/index.js.map +1 -0
- package/dist/interface/adminInterface.d.cts +94 -0
- package/dist/interface/adminInterface.d.ts +38 -15
- package/dist/interface/adminInterface.js +269 -174
- package/dist/interface/adminInterface.js.map +1 -0
- package/dist/interface/clientInterface.d.cts +260 -0
- package/dist/interface/clientInterface.d.ts +25 -18
- package/dist/interface/clientInterface.js +2054 -995
- package/dist/interface/clientInterface.js.map +1 -0
- package/dist/interface/crud/contact-channels.d.cts +180 -0
- package/dist/interface/crud/contact-channels.d.ts +30 -25
- package/dist/interface/crud/contact-channels.js +101 -59
- package/dist/interface/crud/contact-channels.js.map +1 -0
- package/dist/interface/crud/current-user.d.cts +205 -0
- package/dist/interface/crud/current-user.d.ts +17 -12
- package/dist/interface/crud/current-user.js +86 -56
- package/dist/interface/crud/current-user.js.map +1 -0
- package/dist/interface/crud/email-templates.d.cts +84 -0
- package/dist/interface/crud/email-templates.d.ts +24 -19
- package/dist/interface/crud/email-templates.js +77 -37
- package/dist/interface/crud/email-templates.js.map +1 -0
- package/dist/interface/crud/emails.d.cts +69 -0
- package/dist/interface/crud/emails.d.ts +12 -7
- package/dist/interface/crud/emails.js +54 -12
- package/dist/interface/crud/emails.js.map +1 -0
- package/dist/interface/crud/internal-api-keys.d.cts +139 -0
- package/dist/interface/crud/internal-api-keys.d.ts +22 -17
- package/dist/interface/crud/internal-api-keys.js +92 -54
- package/dist/interface/crud/internal-api-keys.js.map +1 -0
- package/dist/interface/crud/oauth.d.cts +34 -0
- package/dist/interface/crud/oauth.d.ts +16 -11
- package/dist/interface/crud/oauth.js +48 -14
- package/dist/interface/crud/oauth.js.map +1 -0
- package/dist/interface/crud/project-api-keys.d.cts +196 -0
- package/dist/interface/crud/project-api-keys.d.ts +20 -12
- package/dist/interface/crud/project-api-keys.js +121 -74
- package/dist/interface/crud/project-api-keys.js.map +1 -0
- package/dist/interface/crud/project-permissions.d.cts +160 -0
- package/dist/interface/crud/project-permissions.d.ts +38 -33
- package/dist/interface/crud/project-permissions.js +148 -90
- package/dist/interface/crud/project-permissions.js.map +1 -0
- package/dist/interface/crud/projects.d.cts +627 -0
- package/dist/interface/crud/projects.d.ts +43 -51
- package/dist/interface/crud/projects.js +210 -156
- package/dist/interface/crud/projects.js.map +1 -0
- package/dist/interface/crud/sessions.d.cts +149 -0
- package/dist/interface/crud/sessions.d.ts +21 -16
- package/dist/interface/crud/sessions.js +86 -50
- package/dist/interface/crud/sessions.js.map +1 -0
- package/dist/interface/crud/svix-token.d.cts +26 -0
- package/dist/interface/crud/svix-token.d.ts +14 -9
- package/dist/interface/crud/svix-token.js +46 -12
- package/dist/interface/crud/svix-token.js.map +1 -0
- package/dist/interface/crud/team-invitation-details.d.cts +30 -0
- package/dist/interface/crud/team-invitation-details.d.ts +12 -7
- package/dist/interface/crud/team-invitation-details.js +57 -15
- package/dist/interface/crud/team-invitation-details.js.map +1 -0
- package/dist/interface/crud/team-invitation.d.cts +49 -0
- package/dist/interface/crud/team-invitation.d.ts +13 -8
- package/dist/interface/crud/team-invitation.js +69 -27
- package/dist/interface/crud/team-invitation.js.map +1 -0
- package/dist/interface/crud/team-member-profiles.d.cts +229 -0
- package/dist/interface/crud/team-member-profiles.d.ts +20 -15
- package/dist/interface/crud/team-member-profiles.js +95 -49
- package/dist/interface/crud/team-member-profiles.js.map +1 -0
- package/dist/interface/crud/team-memberships.d.cts +74 -0
- package/dist/interface/crud/team-memberships.d.ts +22 -17
- package/dist/interface/crud/team-memberships.js +85 -45
- package/dist/interface/crud/team-memberships.js.map +1 -0
- package/dist/interface/crud/team-permissions.d.cts +168 -0
- package/dist/interface/crud/team-permissions.d.ts +38 -33
- package/dist/interface/crud/team-permissions.js +149 -91
- package/dist/interface/crud/team-permissions.js.map +1 -0
- package/dist/interface/crud/teams.d.cts +298 -0
- package/dist/interface/crud/teams.d.ts +45 -40
- package/dist/interface/crud/teams.js +177 -119
- package/dist/interface/crud/teams.js.map +1 -0
- package/dist/interface/crud/users.d.cts +469 -0
- package/dist/interface/crud/users.d.ts +31 -26
- package/dist/interface/crud/users.js +172 -118
- package/dist/interface/crud/users.js.map +1 -0
- package/dist/interface/serverInterface.d.cts +128 -0
- package/dist/interface/serverInterface.d.ts +29 -17
- package/dist/interface/serverInterface.js +506 -339
- package/dist/interface/serverInterface.js.map +1 -0
- package/dist/interface/webhooks.d.cts +292 -0
- package/dist/interface/webhooks.d.ts +6 -3
- package/dist/interface/webhooks.js +45 -15
- package/dist/interface/webhooks.js.map +1 -0
- package/dist/known-errors.d.cts +447 -0
- package/dist/known-errors.d.ts +15 -9
- package/dist/known-errors.js +1104 -562
- package/dist/known-errors.js.map +1 -0
- package/dist/schema-fields.d.cts +163 -0
- package/dist/schema-fields.d.ts +116 -114
- package/dist/schema-fields.js +593 -427
- package/dist/schema-fields.js.map +1 -0
- package/dist/sessions.d.cts +109 -0
- package/dist/sessions.d.ts +6 -3
- package/dist/sessions.js +201 -172
- package/dist/sessions.js.map +1 -0
- package/dist/utils/api-keys.d.cts +24 -0
- package/dist/utils/api-keys.d.ts +5 -4
- package/dist/utils/api-keys.js +106 -66
- package/dist/utils/api-keys.js.map +1 -0
- package/dist/utils/arrays.d.cts +18 -0
- package/dist/utils/arrays.d.ts +15 -13
- package/dist/utils/arrays.js +101 -168
- package/dist/utils/arrays.js.map +1 -0
- package/dist/utils/base64.d.cts +4 -0
- package/dist/utils/base64.d.ts +4 -2
- package/dist/utils/base64.js +41 -20
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/booleans.d.cts +6 -0
- package/dist/utils/booleans.d.ts +6 -4
- package/dist/utils/booleans.js +35 -27
- package/dist/utils/booleans.js.map +1 -0
- package/dist/utils/browser-compat.d.cts +8 -0
- package/dist/utils/browser-compat.d.ts +3 -1
- package/dist/utils/browser-compat.js +45 -16
- package/dist/utils/browser-compat.js.map +1 -0
- package/dist/utils/bytes.d.cts +15 -0
- package/dist/utils/bytes.d.ts +15 -13
- package/dist/utils/bytes.js +182 -270
- package/dist/utils/bytes.js.map +1 -0
- package/dist/utils/caches.d.cts +98 -0
- package/dist/utils/caches.d.ts +17 -14
- package/dist/utils/caches.js +188 -193
- package/dist/utils/caches.js.map +1 -0
- package/dist/utils/compile-time.d.cts +8 -0
- package/dist/utils/compile-time.d.ts +3 -1
- package/dist/utils/compile-time.js +35 -10
- package/dist/utils/compile-time.js.map +1 -0
- package/dist/utils/crypto.d.cts +8 -0
- package/dist/utils/crypto.d.ts +4 -2
- package/dist/utils/crypto.js +49 -21
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/dates.d.cts +15 -0
- package/dist/utils/dates.d.ts +6 -4
- package/dist/utils/dates.js +83 -105
- package/dist/utils/dates.js.map +1 -0
- package/dist/utils/dom.d.cts +3 -0
- package/dist/utils/dom.d.ts +3 -1
- package/dist/utils/dom.js +35 -7
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/env.d.cts +9 -0
- package/dist/utils/env.d.ts +6 -4
- package/dist/utils/env.js +70 -43
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/errors.d.cts +223 -0
- package/dist/utils/errors.d.ts +14 -11
- package/dist/utils/errors.js +148 -126
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/fs.d.cts +7 -0
- package/dist/utils/fs.d.ts +5 -3
- package/dist/utils/fs.js +70 -27
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/functions.d.cts +4 -0
- package/dist/utils/functions.d.ts +4 -2
- package/dist/utils/functions.js +35 -18
- package/dist/utils/functions.js.map +1 -0
- package/dist/utils/geo.d.cts +22 -0
- package/dist/utils/geo.d.ts +6 -3
- package/dist/utils/geo.js +39 -9
- package/dist/utils/geo.js.map +1 -0
- package/dist/utils/globals.d.cts +5 -0
- package/dist/utils/globals.d.ts +4 -2
- package/dist/utils/globals.js +41 -14
- package/dist/utils/globals.js.map +1 -0
- package/dist/utils/hashes.d.cts +7 -0
- package/dist/utils/hashes.d.ts +7 -5
- package/dist/utils/hashes.js +87 -41
- package/dist/utils/hashes.js.map +1 -0
- package/dist/utils/html.d.cts +4 -0
- package/dist/utils/html.d.ts +4 -2
- package/dist/utils/html.js +36 -37
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/http.d.cts +43 -0
- package/dist/utils/http.d.ts +6 -4
- package/dist/utils/http.js +83 -83
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/ips.d.cts +6 -0
- package/dist/utils/ips.d.ts +6 -4
- package/dist/utils/ips.js +48 -35
- package/dist/utils/ips.js.map +1 -0
- package/dist/utils/json.d.cts +13 -0
- package/dist/utils/json.d.ts +9 -6
- package/dist/utils/json.js +54 -157
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/jwt.d.cts +44 -0
- package/dist/utils/jwt.d.ts +14 -11
- package/dist/utils/jwt.js +119 -84
- package/dist/utils/jwt.js.map +1 -0
- package/dist/utils/locks.d.cts +15 -0
- package/dist/utils/locks.d.ts +3 -2
- package/dist/utils/locks.js +76 -56
- package/dist/utils/locks.js.map +1 -0
- package/dist/utils/maps.d.cts +59 -0
- package/dist/utils/maps.d.ts +6 -4
- package/dist/utils/maps.js +207 -343
- package/dist/utils/maps.js.map +1 -0
- package/dist/utils/math.d.cts +6 -0
- package/dist/utils/math.d.ts +3 -1
- package/dist/utils/math.js +31 -16
- package/dist/utils/math.js.map +1 -0
- package/dist/utils/node-http.d.cts +15 -0
- package/dist/utils/node-http.d.ts +5 -5
- package/dist/utils/node-http.js +65 -36
- package/dist/utils/node-http.js.map +1 -0
- package/dist/utils/numbers.d.cts +5 -0
- package/dist/utils/numbers.d.ts +5 -3
- package/dist/utils/numbers.js +53 -66
- package/dist/utils/numbers.js.map +1 -0
- package/dist/utils/oauth.d.cts +8 -0
- package/dist/utils/oauth.d.ts +8 -6
- package/dist/utils/oauth.js +37 -4
- package/dist/utils/oauth.js.map +1 -0
- package/dist/utils/objects.d.cts +69 -0
- package/dist/utils/objects.d.ts +37 -32
- package/dist/utils/objects.js +224 -374
- package/dist/utils/objects.js.map +1 -0
- package/dist/utils/passkey.d.cts +1 -0
- package/dist/utils/passkey.d.ts +1 -1
- package/dist/utils/passkey.js +19 -1
- package/dist/utils/passkey.js.map +1 -0
- package/dist/utils/promises.d.cts +74 -0
- package/dist/utils/promises.d.ts +20 -18
- package/dist/utils/promises.js +252 -393
- package/dist/utils/promises.js.map +1 -0
- package/dist/utils/proxies.d.cts +4 -0
- package/dist/utils/proxies.d.ts +4 -2
- package/dist/utils/proxies.js +150 -161
- package/dist/utils/proxies.js.map +1 -0
- package/dist/utils/react.d.cts +25 -0
- package/dist/utils/react.d.ts +9 -6
- package/dist/utils/react.js +88 -134
- package/dist/utils/react.js.map +1 -0
- package/dist/utils/results.d.cts +78 -0
- package/dist/utils/results.d.ts +10 -9
- package/dist/utils/results.js +143 -324
- package/dist/utils/results.js.map +1 -0
- package/dist/utils/sentry.d.cts +5 -0
- package/dist/utils/sentry.d.ts +5 -2
- package/dist/utils/sentry.js +44 -14
- package/dist/utils/sentry.js.map +1 -0
- package/dist/utils/stores.d.cts +102 -0
- package/dist/utils/stores.d.ts +12 -9
- package/dist/utils/stores.js +219 -189
- package/dist/utils/stores.js.map +1 -0
- package/dist/utils/strings.d.cts +72 -0
- package/dist/utils/strings.d.ts +22 -20
- package/dist/utils/strings.js +300 -580
- package/dist/utils/strings.js.map +1 -0
- package/dist/utils/strings.nicify.test.d.cts +2 -0
- package/dist/utils/strings.nicify.test.d.ts +2 -1
- package/dist/utils/strings.nicify.test.js +168 -158
- package/dist/utils/strings.nicify.test.js.map +1 -0
- package/dist/utils/types.d.cts +23 -0
- package/dist/utils/types.d.ts +8 -6
- package/dist/utils/types.js +19 -1
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/unicode.d.cts +3 -0
- package/dist/utils/unicode.d.ts +3 -1
- package/dist/utils/unicode.js +34 -21
- package/dist/utils/unicode.js.map +1 -0
- package/dist/utils/urls.d.cts +20 -0
- package/dist/utils/urls.d.ts +10 -8
- package/dist/utils/urls.js +76 -165
- package/dist/utils/urls.js.map +1 -0
- package/dist/utils/uuids.d.cts +4 -0
- package/dist/utils/uuids.d.ts +4 -2
- package/dist/utils/uuids.js +39 -35
- package/dist/utils/uuids.js.map +1 -0
- 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 };
|
package/dist/utils/caches.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { RateLimitOptions, ReactPromise } from
|
|
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
|
-
|
|
7
|
+
declare function cacheFunction<F extends Function>(f: F): F;
|
|
6
8
|
type CacheStrategy = "write-only" | "read-write" | "never";
|
|
7
|
-
|
|
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
|
-
|
|
97
|
+
|
|
98
|
+
export { AsyncCache, cacheFunction };
|
package/dist/utils/caches.js
CHANGED
|
@@ -1,198 +1,193 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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":"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","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
|
-
|
|
6
|
+
declare function scrambleDuringCompileTime<T>(t: T): T;
|
|
7
|
+
|
|
8
|
+
export { scrambleDuringCompileTime };
|
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 };
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
6
|
+
declare function generateSecureRandomString(minBitsOfEntropy?: number): string;
|
|
7
|
+
|
|
8
|
+
export { generateRandomValues, generateSecureRandomString };
|