@stackframe/stack-shared 2.8.7 → 2.8.10
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 +10 -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 +724 -0
- package/dist/config/schema.d.ts +51 -48
- package/dist/config/schema.js +230 -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 +199 -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 +188 -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 +1223 -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 +153 -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 +294 -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 +18 -10
- 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 +640 -0
- package/dist/interface/crud/projects.d.ts +36 -31
- package/dist/interface/crud/projects.js +218 -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 +444 -0
- package/dist/known-errors.d.ts +12 -9
- package/dist/known-errors.js +1088 -561
- 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 +65 -0
- package/dist/utils/objects.d.ts +31 -30
- package/dist/utils/objects.js +196 -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 +299 -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
package/dist/utils/promises.js
CHANGED
|
@@ -1,412 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
resolve(42);
|
|
38
|
-
});
|
|
39
|
-
expect(resolvedPromise.status).toBe("fulfilled");
|
|
40
|
-
expect(resolvedPromise.value).toBe(42);
|
|
41
|
-
expect(await resolvedPromise).toBe(42);
|
|
42
|
-
// Test rejected promise
|
|
43
|
-
const error = new Error("Test error");
|
|
44
|
-
const rejectedPromise = createPromise((_, reject) => {
|
|
45
|
-
reject(error);
|
|
46
|
-
});
|
|
47
|
-
expect(rejectedPromise.status).toBe("rejected");
|
|
48
|
-
expect(rejectedPromise.reason).toBe(error);
|
|
49
|
-
await expect(rejectedPromise).rejects.toBe(error);
|
|
50
|
-
// Test pending promise
|
|
51
|
-
const pendingPromise = createPromise(() => {
|
|
52
|
-
// Do nothing, leave it pending
|
|
53
|
-
});
|
|
54
|
-
expect(pendingPromise.status).toBe("pending");
|
|
55
|
-
expect(pendingPromise.value).toBeUndefined();
|
|
56
|
-
expect(pendingPromise.reason).toBeUndefined();
|
|
57
|
-
// Test that resolving after already resolved does nothing
|
|
58
|
-
let resolveCount = 0;
|
|
59
|
-
const multiResolvePromise = createPromise((resolve) => {
|
|
60
|
-
resolve(1);
|
|
61
|
-
resolveCount++;
|
|
62
|
-
resolve(2);
|
|
63
|
-
resolveCount++;
|
|
64
|
-
});
|
|
65
|
-
expect(resolveCount).toBe(2); // Both resolve calls executed
|
|
66
|
-
expect(multiResolvePromise.status).toBe("fulfilled");
|
|
67
|
-
expect(multiResolvePromise.value).toBe(1); // Only first resolve took effect
|
|
68
|
-
expect(await multiResolvePromise).toBe(1);
|
|
69
|
-
});
|
|
70
|
-
let resolvedCache = null;
|
|
71
|
-
/**
|
|
72
|
-
* Like Promise.resolve(...), but also adds the status and value properties for use with React's `use` hook, and caches
|
|
73
|
-
* the value so that invoking `resolved` twice returns the same promise.
|
|
74
|
-
*/
|
|
75
|
-
export function resolved(value) {
|
|
76
|
-
resolvedCache ??= new DependenciesMap();
|
|
77
|
-
if (resolvedCache.has([value])) {
|
|
78
|
-
return resolvedCache.get([value]);
|
|
79
|
-
}
|
|
80
|
-
const res = Object.assign(Promise.resolve(value), {
|
|
81
|
-
status: "fulfilled",
|
|
82
|
-
value,
|
|
83
|
-
});
|
|
84
|
-
resolvedCache.set([value], res);
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
import.meta.vitest?.test("resolved", async ({ expect }) => {
|
|
88
|
-
// Test with primitive value
|
|
89
|
-
const promise1 = resolved(42);
|
|
90
|
-
expect(promise1.status).toBe("fulfilled");
|
|
91
|
-
// Need to use type assertion since value is only available when status is "fulfilled"
|
|
92
|
-
expect(promise1.value).toBe(42);
|
|
93
|
-
expect(await promise1).toBe(42);
|
|
94
|
-
// Test with object value
|
|
95
|
-
const obj = { test: true };
|
|
96
|
-
const promise2 = resolved(obj);
|
|
97
|
-
expect(promise2.status).toBe("fulfilled");
|
|
98
|
-
expect(promise2.value).toBe(obj);
|
|
99
|
-
expect(await promise2).toBe(obj);
|
|
100
|
-
// Test caching (same reference for same value)
|
|
101
|
-
const promise3 = resolved(42);
|
|
102
|
-
expect(promise3).toBe(promise1); // Same reference due to caching
|
|
103
|
-
// Test with different value (different reference)
|
|
104
|
-
const promise4 = resolved(43);
|
|
105
|
-
expect(promise4).not.toBe(promise1);
|
|
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/promises.tsx
|
|
21
|
+
var promises_exports = {};
|
|
22
|
+
__export(promises_exports, {
|
|
23
|
+
createPromise: () => createPromise,
|
|
24
|
+
ignoreUnhandledRejection: () => ignoreUnhandledRejection,
|
|
25
|
+
neverResolve: () => neverResolve,
|
|
26
|
+
pending: () => pending,
|
|
27
|
+
rateLimited: () => rateLimited,
|
|
28
|
+
rejected: () => rejected,
|
|
29
|
+
resolved: () => resolved,
|
|
30
|
+
runAsynchronously: () => runAsynchronously,
|
|
31
|
+
runAsynchronouslyWithAlert: () => runAsynchronouslyWithAlert,
|
|
32
|
+
throttled: () => throttled,
|
|
33
|
+
timeout: () => timeout,
|
|
34
|
+
timeoutThrow: () => timeoutThrow,
|
|
35
|
+
wait: () => wait,
|
|
36
|
+
waitUntil: () => waitUntil
|
|
106
37
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
38
|
+
module.exports = __toCommonJS(promises_exports);
|
|
39
|
+
var import__ = require("..");
|
|
40
|
+
var import_errors = require("./errors");
|
|
41
|
+
var import_maps = require("./maps");
|
|
42
|
+
var import_results = require("./results");
|
|
43
|
+
var import_uuids = require("./uuids");
|
|
44
|
+
function createPromise(callback) {
|
|
45
|
+
let status = "pending";
|
|
46
|
+
let valueOrReason = void 0;
|
|
47
|
+
let resolve = null;
|
|
48
|
+
let reject = null;
|
|
49
|
+
const promise = new Promise((res, rej) => {
|
|
50
|
+
resolve = (value) => {
|
|
51
|
+
if (status !== "pending") return;
|
|
52
|
+
status = "fulfilled";
|
|
53
|
+
valueOrReason = value;
|
|
54
|
+
res(value);
|
|
55
|
+
};
|
|
56
|
+
reject = (reason) => {
|
|
57
|
+
if (status !== "pending") return;
|
|
58
|
+
status = "rejected";
|
|
59
|
+
valueOrReason = reason;
|
|
60
|
+
rej(reason);
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
callback(resolve, reject);
|
|
64
|
+
return Object.assign(promise, {
|
|
65
|
+
status,
|
|
66
|
+
...status === "fulfilled" ? { value: valueOrReason } : {},
|
|
67
|
+
...status === "rejected" ? { reason: valueOrReason } : {}
|
|
68
|
+
});
|
|
125
69
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const promise3 = rejected(error);
|
|
139
|
-
expect(promise3).toBe(promise1); // Same reference due to caching
|
|
140
|
-
// Test with different reason (different reference)
|
|
141
|
-
const differentError = new Error("Different error");
|
|
142
|
-
const promise4 = rejected(differentError);
|
|
143
|
-
expect(promise4).not.toBe(promise1);
|
|
144
|
-
// Note: We're not using await expect(promise).rejects to avoid unhandled rejections
|
|
145
|
-
});
|
|
146
|
-
// We'll skip the rejection test for pending() since it's causing unhandled rejections
|
|
147
|
-
// The function is already well tested through other tests like rejected() and createPromise()
|
|
148
|
-
const neverResolvePromise = pending(new Promise(() => { }));
|
|
149
|
-
export function neverResolve() {
|
|
150
|
-
return neverResolvePromise;
|
|
70
|
+
var resolvedCache = null;
|
|
71
|
+
function resolved(value) {
|
|
72
|
+
resolvedCache ??= new import_maps.DependenciesMap();
|
|
73
|
+
if (resolvedCache.has([value])) {
|
|
74
|
+
return resolvedCache.get([value]);
|
|
75
|
+
}
|
|
76
|
+
const res = Object.assign(Promise.resolve(value), {
|
|
77
|
+
status: "fulfilled",
|
|
78
|
+
value
|
|
79
|
+
});
|
|
80
|
+
resolvedCache.set([value], res);
|
|
81
|
+
return res;
|
|
151
82
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}, actualReason => {
|
|
167
|
-
res.status = "rejected";
|
|
168
|
-
res.reason = actualReason;
|
|
169
|
-
throw actualReason;
|
|
170
|
-
});
|
|
171
|
-
res.status = "pending";
|
|
172
|
-
return res;
|
|
83
|
+
var rejectedCache = null;
|
|
84
|
+
function rejected(reason) {
|
|
85
|
+
rejectedCache ??= new import_maps.DependenciesMap();
|
|
86
|
+
if (rejectedCache.has([reason])) {
|
|
87
|
+
return rejectedCache.get([reason]);
|
|
88
|
+
}
|
|
89
|
+
const promise = Promise.reject(reason);
|
|
90
|
+
ignoreUnhandledRejection(promise);
|
|
91
|
+
const res = Object.assign(promise, {
|
|
92
|
+
status: "rejected",
|
|
93
|
+
reason
|
|
94
|
+
});
|
|
95
|
+
rejectedCache.set([reason], res);
|
|
96
|
+
return res;
|
|
173
97
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// Initially it should be pending
|
|
179
|
-
expect(pendingPromise.status).toBe("pending");
|
|
180
|
-
// After resolution, it should be fulfilled
|
|
181
|
-
await resolvePromise;
|
|
182
|
-
// Need to wait a tick for the then handler to execute
|
|
183
|
-
await new Promise(resolve => setTimeout(resolve, 0));
|
|
184
|
-
expect(pendingPromise.status).toBe("fulfilled");
|
|
185
|
-
expect(pendingPromise.value).toBe(42);
|
|
186
|
-
// For the rejection test, we'll use a separate test to avoid unhandled rejections
|
|
187
|
-
});
|
|
188
|
-
/**
|
|
189
|
-
* Should be used to wrap Promises that are not immediately awaited, so they don't throw an unhandled promise rejection
|
|
190
|
-
* error.
|
|
191
|
-
*
|
|
192
|
-
* Vercel kills serverless functions on unhandled promise rejection errors, so this is important.
|
|
193
|
-
*/
|
|
194
|
-
export function ignoreUnhandledRejection(promise) {
|
|
195
|
-
promise.catch(() => { });
|
|
98
|
+
var neverResolvePromise = pending(new Promise(() => {
|
|
99
|
+
}));
|
|
100
|
+
function neverResolve() {
|
|
101
|
+
return neverResolvePromise;
|
|
196
102
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
await expect(rejectPromise).rejects.toBe(error);
|
|
209
|
-
});
|
|
210
|
-
export async function wait(ms) {
|
|
211
|
-
if (!Number.isFinite(ms) || ms < 0) {
|
|
212
|
-
throw new StackAssertionError(`wait() requires a non-negative integer number of milliseconds to wait. (found: ${ms}ms)`);
|
|
213
|
-
}
|
|
214
|
-
if (ms >= 2 ** 31) {
|
|
215
|
-
throw new StackAssertionError("The maximum timeout for wait() is 2147483647ms (2**31 - 1). (found: ${ms}ms)");
|
|
103
|
+
function pending(promise, options = {}) {
|
|
104
|
+
const res = promise.then(
|
|
105
|
+
(value) => {
|
|
106
|
+
res.status = "fulfilled";
|
|
107
|
+
res.value = value;
|
|
108
|
+
return value;
|
|
109
|
+
},
|
|
110
|
+
(actualReason) => {
|
|
111
|
+
res.status = "rejected";
|
|
112
|
+
res.reason = actualReason;
|
|
113
|
+
throw actualReason;
|
|
216
114
|
}
|
|
217
|
-
|
|
115
|
+
);
|
|
116
|
+
res.status = "pending";
|
|
117
|
+
return res;
|
|
218
118
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
await wait(10);
|
|
223
|
-
const elapsed = Date.now() - start;
|
|
224
|
-
expect(elapsed).toBeGreaterThanOrEqual(5); // Allow some flexibility in timing
|
|
225
|
-
// Test with zero
|
|
226
|
-
await expect(wait(0)).resolves.toBeUndefined();
|
|
227
|
-
// Test with negative number
|
|
228
|
-
await expect(wait(-10)).rejects.toThrow("wait() requires a non-negative integer");
|
|
229
|
-
// Test with non-finite number
|
|
230
|
-
await expect(wait(NaN)).rejects.toThrow("wait() requires a non-negative integer");
|
|
231
|
-
await expect(wait(Infinity)).rejects.toThrow("wait() requires a non-negative integer");
|
|
232
|
-
// Test with too large number
|
|
233
|
-
await expect(wait(2 ** 31)).rejects.toThrow("The maximum timeout for wait()");
|
|
234
|
-
});
|
|
235
|
-
export async function waitUntil(date) {
|
|
236
|
-
return await wait(date.getTime() - Date.now());
|
|
119
|
+
function ignoreUnhandledRejection(promise) {
|
|
120
|
+
promise.catch(() => {
|
|
121
|
+
});
|
|
237
122
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
// We need to verify it throws the correct error
|
|
247
|
-
try {
|
|
248
|
-
await waitUntil(new Date(Date.now() - 1000));
|
|
249
|
-
expect.fail("Should have thrown an error");
|
|
250
|
-
}
|
|
251
|
-
catch (error) {
|
|
252
|
-
expect(error).toBeInstanceOf(StackAssertionError);
|
|
253
|
-
expect(error.message).toContain("wait() requires a non-negative integer");
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
export function runAsynchronouslyWithAlert(...args) {
|
|
257
|
-
return runAsynchronously(args[0], {
|
|
258
|
-
...args[1],
|
|
259
|
-
onError: error => {
|
|
260
|
-
if (error instanceof KnownError && process.env.NODE_ENV.includes("production")) {
|
|
261
|
-
alert(error.message);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
alert(`An unhandled error occurred. Please ${process.env.NODE_ENV === "development" ? `check the browser console for the full error.` : "report this to the developer."}\n\n${error}`);
|
|
265
|
-
}
|
|
266
|
-
args[1]?.onError?.(error);
|
|
267
|
-
},
|
|
268
|
-
}, ...args.slice(2));
|
|
123
|
+
async function wait(ms) {
|
|
124
|
+
if (!Number.isFinite(ms) || ms < 0) {
|
|
125
|
+
throw new import_errors.StackAssertionError(`wait() requires a non-negative integer number of milliseconds to wait. (found: ${ms}ms)`);
|
|
126
|
+
}
|
|
127
|
+
if (ms >= 2 ** 31) {
|
|
128
|
+
throw new import_errors.StackAssertionError("The maximum timeout for wait() is 2147483647ms (2**31 - 1). (found: ${ms}ms)");
|
|
129
|
+
}
|
|
130
|
+
return await new Promise((resolve) => setTimeout(resolve, ms));
|
|
269
131
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const duringError = new Error();
|
|
286
|
-
promiseOrFunc?.catch(error => {
|
|
287
|
-
options.onError?.(error);
|
|
288
|
-
const newError = new StackAssertionError("Uncaught error in asynchronous function: " + error.toString(), { cause: error });
|
|
289
|
-
concatStacktraces(newError, duringError);
|
|
290
|
-
if (!options.noErrorLogging) {
|
|
291
|
-
captureError("runAsynchronously", newError);
|
|
132
|
+
async function waitUntil(date) {
|
|
133
|
+
return await wait(date.getTime() - Date.now());
|
|
134
|
+
}
|
|
135
|
+
function runAsynchronouslyWithAlert(...args) {
|
|
136
|
+
return runAsynchronously(
|
|
137
|
+
args[0],
|
|
138
|
+
{
|
|
139
|
+
...args[1],
|
|
140
|
+
onError: (error) => {
|
|
141
|
+
if (error instanceof import__.KnownError && typeof process !== "undefined" && process.env.NODE_ENV?.includes("production")) {
|
|
142
|
+
alert(error.message);
|
|
143
|
+
} else {
|
|
144
|
+
alert(`An unhandled error occurred. Please ${process.env.NODE_ENV === "development" ? `check the browser console for the full error.` : "report this to the developer."}
|
|
145
|
+
|
|
146
|
+
${error}`);
|
|
292
147
|
}
|
|
293
|
-
|
|
148
|
+
args[1]?.onError?.(error);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
...args.slice(2)
|
|
152
|
+
);
|
|
294
153
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
super(`Timeout after ${ms}ms`);
|
|
310
|
-
this.ms = ms;
|
|
311
|
-
this.name = "TimeoutError";
|
|
154
|
+
function runAsynchronously(promiseOrFunc, options = {}) {
|
|
155
|
+
if (typeof promiseOrFunc === "function") {
|
|
156
|
+
promiseOrFunc = promiseOrFunc();
|
|
157
|
+
}
|
|
158
|
+
const duringError = new Error();
|
|
159
|
+
promiseOrFunc?.catch((error) => {
|
|
160
|
+
options.onError?.(error);
|
|
161
|
+
const newError = new import_errors.StackAssertionError(
|
|
162
|
+
"Uncaught error in asynchronous function: " + error.toString(),
|
|
163
|
+
{ cause: error }
|
|
164
|
+
);
|
|
165
|
+
(0, import_errors.concatStacktraces)(newError, duringError);
|
|
166
|
+
if (!options.noErrorLogging) {
|
|
167
|
+
(0, import_errors.captureError)("runAsynchronously", newError);
|
|
312
168
|
}
|
|
169
|
+
});
|
|
313
170
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
171
|
+
var TimeoutError = class extends Error {
|
|
172
|
+
constructor(ms) {
|
|
173
|
+
super(`Timeout after ${ms}ms`);
|
|
174
|
+
this.ms = ms;
|
|
175
|
+
this.name = "TimeoutError";
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
async function timeout(promise, ms) {
|
|
179
|
+
return await Promise.race([
|
|
180
|
+
promise.then((value) => import_results.Result.ok(value)),
|
|
181
|
+
wait(ms).then(() => import_results.Result.error(new TimeoutError(ms)))
|
|
182
|
+
]);
|
|
319
183
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
184
|
+
async function timeoutThrow(promise, ms) {
|
|
185
|
+
return import_results.Result.orThrow(await timeout(promise, ms));
|
|
186
|
+
}
|
|
187
|
+
function rateLimited(func, options) {
|
|
188
|
+
let waitUntil2 = performance.now();
|
|
189
|
+
let queue = [];
|
|
190
|
+
let addedToQueueCallbacks = /* @__PURE__ */ new Map();
|
|
191
|
+
const next = async () => {
|
|
192
|
+
while (true) {
|
|
193
|
+
if (waitUntil2 > performance.now()) {
|
|
194
|
+
await wait(Math.max(1, waitUntil2 - performance.now() + 1));
|
|
195
|
+
} else if (queue.length === 0) {
|
|
196
|
+
const uuid = (0, import_uuids.generateUuid)();
|
|
197
|
+
await new Promise((resolve) => {
|
|
198
|
+
addedToQueueCallbacks.set(uuid, resolve);
|
|
199
|
+
});
|
|
200
|
+
addedToQueueCallbacks.delete(uuid);
|
|
201
|
+
} else {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
327
204
|
}
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
205
|
+
const nextFuncs = options.batchCalls ? queue.splice(0, queue.length) : [queue.shift()];
|
|
206
|
+
const start = performance.now();
|
|
207
|
+
const value = await import_results.Result.fromPromise(func());
|
|
208
|
+
const end = performance.now();
|
|
209
|
+
waitUntil2 = Math.max(
|
|
210
|
+
waitUntil2,
|
|
211
|
+
start + (options.throttleMs ?? 0),
|
|
212
|
+
end + (options.gapMs ?? 0)
|
|
213
|
+
);
|
|
214
|
+
for (const nextFunc of nextFuncs) {
|
|
215
|
+
if (value.status === "ok") {
|
|
216
|
+
nextFunc[0](value.data);
|
|
217
|
+
} else {
|
|
218
|
+
nextFunc[1](value.error);
|
|
219
|
+
}
|
|
335
220
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
export function rateLimited(func, options) {
|
|
351
|
-
let waitUntil = performance.now();
|
|
352
|
-
let queue = [];
|
|
353
|
-
let addedToQueueCallbacks = new Map;
|
|
354
|
-
const next = async () => {
|
|
355
|
-
while (true) {
|
|
356
|
-
if (waitUntil > performance.now()) {
|
|
357
|
-
await wait(Math.max(1, waitUntil - performance.now() + 1));
|
|
358
|
-
}
|
|
359
|
-
else if (queue.length === 0) {
|
|
360
|
-
const uuid = generateUuid();
|
|
361
|
-
await new Promise(resolve => {
|
|
362
|
-
addedToQueueCallbacks.set(uuid, resolve);
|
|
363
|
-
});
|
|
364
|
-
addedToQueueCallbacks.delete(uuid);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const nextFuncs = options.batchCalls ? queue.splice(0, queue.length) : [queue.shift()];
|
|
371
|
-
const start = performance.now();
|
|
372
|
-
const value = await Result.fromPromise(func());
|
|
373
|
-
const end = performance.now();
|
|
374
|
-
waitUntil = Math.max(waitUntil, start + (options.throttleMs ?? 0), end + (options.gapMs ?? 0));
|
|
375
|
-
for (const nextFunc of nextFuncs) {
|
|
376
|
-
if (value.status === "ok") {
|
|
377
|
-
nextFunc[0](value.data);
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
nextFunc[1](value.error);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
runAsynchronously(async () => {
|
|
385
|
-
while (true) {
|
|
386
|
-
await next();
|
|
387
|
-
}
|
|
221
|
+
};
|
|
222
|
+
runAsynchronously(async () => {
|
|
223
|
+
while (true) {
|
|
224
|
+
await next();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return () => {
|
|
228
|
+
return new Promise((resolve, reject) => {
|
|
229
|
+
waitUntil2 = Math.max(
|
|
230
|
+
waitUntil2,
|
|
231
|
+
performance.now() + (options.debounceMs ?? 0)
|
|
232
|
+
);
|
|
233
|
+
queue.push([resolve, reject]);
|
|
234
|
+
addedToQueueCallbacks.forEach((cb) => cb());
|
|
388
235
|
});
|
|
389
|
-
|
|
390
|
-
return new Promise((resolve, reject) => {
|
|
391
|
-
waitUntil = Math.max(waitUntil, performance.now() + (options.debounceMs ?? 0));
|
|
392
|
-
queue.push([resolve, reject]);
|
|
393
|
-
addedToQueueCallbacks.forEach(cb => cb());
|
|
394
|
-
});
|
|
395
|
-
};
|
|
236
|
+
};
|
|
396
237
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
238
|
+
function throttled(func, delayMs) {
|
|
239
|
+
let timeout2 = null;
|
|
240
|
+
let nextAvailable = null;
|
|
241
|
+
return async (...args) => {
|
|
242
|
+
while (nextAvailable !== null) {
|
|
243
|
+
await nextAvailable;
|
|
244
|
+
}
|
|
245
|
+
nextAvailable = new Promise((resolve) => {
|
|
246
|
+
timeout2 = setTimeout(() => {
|
|
247
|
+
nextAvailable = null;
|
|
248
|
+
resolve(func(...args));
|
|
249
|
+
}, delayMs);
|
|
250
|
+
});
|
|
251
|
+
return await nextAvailable;
|
|
252
|
+
};
|
|
412
253
|
}
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
createPromise,
|
|
257
|
+
ignoreUnhandledRejection,
|
|
258
|
+
neverResolve,
|
|
259
|
+
pending,
|
|
260
|
+
rateLimited,
|
|
261
|
+
rejected,
|
|
262
|
+
resolved,
|
|
263
|
+
runAsynchronously,
|
|
264
|
+
runAsynchronouslyWithAlert,
|
|
265
|
+
throttled,
|
|
266
|
+
timeout,
|
|
267
|
+
timeoutThrow,
|
|
268
|
+
wait,
|
|
269
|
+
waitUntil
|
|
270
|
+
});
|
|
271
|
+
//# sourceMappingURL=promises.js.map
|