@intlayer/design-system 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.vite/manifest.json +481 -455
- package/dist/TabSelector-BmkzVPXl.js +660 -0
- package/dist/TabSelector-BmkzVPXl.js.map +1 -0
- package/dist/TabSelector-o_NRBvPQ.cjs +659 -0
- package/dist/TabSelector-o_NRBvPQ.cjs.map +1 -0
- package/dist/components/Auth/AuthModal/index.cjs +17 -62
- package/dist/components/Auth/AuthModal/index.cjs.map +1 -1
- package/dist/components/Auth/AuthModal/index.d.ts.map +1 -1
- package/dist/components/Auth/AuthModal/index.mjs +17 -62
- package/dist/components/Auth/AuthModal/index.mjs.map +1 -1
- package/dist/components/Auth/AuthProvider/index.cjs.map +1 -1
- package/dist/components/Auth/AuthProvider/index.d.ts +3 -3
- package/dist/components/Auth/AuthProvider/index.d.ts.map +1 -1
- package/dist/components/Auth/AuthProvider/index.mjs.map +1 -1
- package/dist/components/Auth/AuthProvider/useSession.cjs +7 -8
- package/dist/components/Auth/AuthProvider/useSession.cjs.map +1 -1
- package/dist/components/Auth/AuthProvider/useSession.d.ts.map +1 -1
- package/dist/components/Auth/AuthProvider/useSession.mjs +7 -8
- package/dist/components/Auth/AuthProvider/useSession.mjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.cjs +2 -2
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.cjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.mjs +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.mjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.cjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.d.ts +2 -2
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.d.ts.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.mjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/accessValidation.cjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/accessValidation.d.ts +1 -1
- package/dist/components/Auth/AuthenticationBarrier/accessValidation.d.ts.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/accessValidation.mjs.map +1 -1
- package/dist/components/Auth/AuthenticationBarrier/index.d.ts +3 -3
- package/dist/components/Auth/AuthenticationBarrier/index.d.ts.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs +1 -0
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs +1 -0
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/index.content.d.ts +10 -10
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs +3 -2
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.d.ts.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs +3 -2
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.d.ts +5 -5
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs +1 -0
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs +1 -0
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/index.content.d.ts +7 -7
- package/dist/components/Auth/SignInForm/SignInForm.cjs +4 -3
- package/dist/components/Auth/SignInForm/SignInForm.cjs.map +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.d.ts +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.d.ts.map +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.mjs +4 -3
- package/dist/components/Auth/SignInForm/SignInForm.mjs.map +1 -1
- package/dist/components/Auth/SignInForm/index.content.d.ts +13 -13
- package/dist/components/Auth/SignUpForm/SignUpForm.cjs +3 -3
- package/dist/components/Auth/SignUpForm/SignUpForm.cjs.map +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.d.ts +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.d.ts.map +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.mjs +3 -3
- package/dist/components/Auth/SignUpForm/SignUpForm.mjs.map +1 -1
- package/dist/components/Auth/SignUpForm/index.content.d.ts +11 -11
- package/dist/components/Auth/index.cjs +2 -4
- package/dist/components/Auth/index.cjs.map +1 -1
- package/dist/components/Auth/index.d.ts +1 -1
- package/dist/components/Auth/index.d.ts.map +1 -1
- package/dist/components/Auth/index.mjs +1 -3
- package/dist/components/Auth/useAuth/index.cjs +39 -0
- package/dist/components/Auth/useAuth/index.cjs.map +1 -0
- package/dist/components/Auth/useAuth/index.d.ts +24 -0
- package/dist/components/Auth/useAuth/index.d.ts.map +1 -0
- package/dist/components/Auth/useAuth/index.mjs +39 -0
- package/dist/components/Auth/useAuth/index.mjs.map +1 -0
- package/dist/components/Auth/useAuth/useCSRF.cjs +22 -0
- package/dist/components/Auth/useAuth/useCSRF.cjs.map +1 -0
- package/dist/components/Auth/useAuth/useCSRF.d.ts +5 -0
- package/dist/components/Auth/useAuth/useCSRF.d.ts.map +1 -0
- package/dist/components/Auth/useAuth/useCSRF.mjs +22 -0
- package/dist/components/Auth/useAuth/useCSRF.mjs.map +1 -0
- package/dist/components/Auth/useAuth/useOAuth2.cjs +26 -0
- package/dist/components/Auth/useAuth/useOAuth2.cjs.map +1 -0
- package/dist/components/Auth/useAuth/useOAuth2.d.ts +4 -0
- package/dist/components/Auth/useAuth/useOAuth2.d.ts.map +1 -0
- package/dist/components/Auth/useAuth/useOAuth2.mjs +26 -0
- package/dist/components/Auth/useAuth/useOAuth2.mjs.map +1 -0
- package/dist/components/Auth/useAuth/useSession.cjs +60 -0
- package/dist/components/Auth/useAuth/useSession.cjs.map +1 -0
- package/dist/components/Auth/useAuth/useSession.d.ts +8 -0
- package/dist/components/Auth/useAuth/useSession.d.ts.map +1 -0
- package/dist/components/Auth/useAuth/useSession.mjs +60 -0
- package/dist/components/Auth/useAuth/useSession.mjs.map +1 -0
- package/dist/components/Auth/useUser/index.cjs +3 -3
- package/dist/components/Auth/useUser/index.cjs.map +1 -1
- package/dist/components/Auth/useUser/index.d.ts.map +1 -1
- package/dist/components/Auth/useUser/index.mjs +3 -3
- package/dist/components/Auth/useUser/index.mjs.map +1 -1
- package/dist/components/Badge/index.d.ts +1 -1
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.d.ts +1 -2
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/Command/index.d.ts +2 -2
- package/dist/components/Command/index.d.ts.map +1 -1
- package/dist/components/Container/index.cjs +1 -0
- package/dist/components/Container/index.cjs.map +1 -1
- package/dist/components/Container/index.d.ts +8 -8
- package/dist/components/Container/index.d.ts.map +1 -1
- package/dist/components/Container/index.mjs +1 -0
- package/dist/components/Container/index.mjs.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs +4 -17
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs +4 -17
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.cjs +0 -21
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.cjs.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.d.ts +0 -9
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.mjs +0 -21
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.cjs +3 -2
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.mjs +3 -2
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs +7 -24
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs +6 -23
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.cjs +0 -42
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.d.ts +0 -18
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.mjs +0 -42
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.d.ts +2 -2
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs +4 -36
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +3 -35
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.d.ts +4 -4
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.cjs +0 -47
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.d.ts +0 -19
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs +0 -47
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs +3 -2
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs +3 -2
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/EditorView/EditorView.cjs +3 -2
- package/dist/components/DictionaryFieldEditor/EditorView/EditorView.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/EditorView/EditorView.mjs +3 -2
- package/dist/components/DictionaryFieldEditor/EditorView/EditorView.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.cjs +2 -2
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.mjs +2 -2
- package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.cjs +2 -2
- package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.mjs +2 -2
- package/dist/components/DictionaryFieldEditor/NodeTypeSelector.cjs +2 -2
- package/dist/components/DictionaryFieldEditor/NodeTypeSelector.mjs +2 -2
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs +4 -17
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs +4 -17
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.cjs +0 -21
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.d.ts +0 -9
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.mjs +0 -21
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.mjs.map +1 -1
- package/dist/components/Form/FormBase.cjs +4 -1
- package/dist/components/Form/FormBase.cjs.map +1 -1
- package/dist/components/Form/FormBase.d.ts +1 -1
- package/dist/components/Form/FormBase.d.ts.map +1 -1
- package/dist/components/Form/FormBase.mjs +4 -1
- package/dist/components/Form/FormBase.mjs.map +1 -1
- package/dist/components/Input/Checkbox.d.ts +1 -1
- package/dist/components/Input/Input.cjs +8 -2
- package/dist/components/Input/Input.cjs.map +1 -1
- package/dist/components/Input/Input.d.ts +1 -0
- package/dist/components/Input/Input.d.ts.map +1 -1
- package/dist/components/Input/Input.mjs +8 -2
- package/dist/components/Input/Input.mjs.map +1 -1
- package/dist/components/Link/Link.d.ts +1 -1
- package/dist/components/Modal/Modal.cjs +3 -1
- package/dist/components/Modal/Modal.cjs.map +1 -1
- package/dist/components/Modal/Modal.mjs +3 -1
- package/dist/components/Modal/Modal.mjs.map +1 -1
- package/dist/components/Navbar/MobileNavbar.cjs +3 -1
- package/dist/components/Navbar/MobileNavbar.cjs.map +1 -1
- package/dist/components/Navbar/MobileNavbar.mjs +3 -1
- package/dist/components/Navbar/MobileNavbar.mjs.map +1 -1
- package/dist/components/Navbar/index.cjs +3 -1
- package/dist/components/Navbar/index.cjs.map +1 -1
- package/dist/components/Navbar/index.mjs +3 -1
- package/dist/components/Navbar/index.mjs.map +1 -1
- package/dist/components/Select/Multiselect.d.ts +1 -1
- package/dist/components/Select/Multiselect.d.ts.map +1 -1
- package/dist/components/SwitchSelector/index.cjs +3 -1
- package/dist/components/SwitchSelector/index.cjs.map +1 -1
- package/dist/components/SwitchSelector/index.d.ts +1 -1
- package/dist/components/SwitchSelector/index.mjs +3 -1
- package/dist/components/SwitchSelector/index.mjs.map +1 -1
- package/dist/components/TabSelector/TabSelector.cjs +13 -10
- package/dist/components/TabSelector/TabSelector.cjs.map +1 -1
- package/dist/components/TabSelector/TabSelector.d.ts +1 -1
- package/dist/components/TabSelector/TabSelector.d.ts.map +1 -1
- package/dist/components/TabSelector/TabSelector.mjs +13 -10
- package/dist/components/TabSelector/TabSelector.mjs.map +1 -1
- package/dist/components/Tag/index.cjs +79 -0
- package/dist/components/Tag/index.cjs.map +1 -0
- package/dist/components/Tag/index.d.ts +12 -0
- package/dist/components/Tag/index.d.ts.map +1 -0
- package/dist/components/Tag/index.mjs +79 -0
- package/dist/components/Tag/index.mjs.map +1 -0
- package/dist/components/Toaster/Toast.d.ts +1 -1
- package/dist/components/index.cjs +4 -4
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.mjs +3 -3
- package/dist/components/index.mjs.map +1 -1
- package/dist/hooks/index.cjs +4 -1
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.mjs +5 -2
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/intlayerAPIHooks.cjs +257 -126
- package/dist/hooks/intlayerAPIHooks.cjs.map +1 -1
- package/dist/hooks/intlayerAPIHooks.d.ts +43 -38
- package/dist/hooks/intlayerAPIHooks.d.ts.map +1 -1
- package/dist/hooks/intlayerAPIHooks.mjs +258 -127
- package/dist/hooks/intlayerAPIHooks.mjs.map +1 -1
- package/dist/hooks/useAsync/useAsync.cjs +142 -104
- package/dist/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/hooks/useAsync/useAsync.d.ts +0 -2
- package/dist/hooks/useAsync/useAsync.d.ts.map +1 -1
- package/dist/hooks/useAsync/useAsync.mjs +143 -105
- package/dist/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.cjs +50 -112
- package/dist/hooks/useAsync/useAsyncStateStore.cjs.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.d.ts +3 -9
- package/dist/hooks/useAsync/useAsyncStateStore.d.ts.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.mjs +50 -112
- package/dist/hooks/useAsync/useAsyncStateStore.mjs.map +1 -1
- package/dist/hooks/useAsync/useProxyState.d.ts +3 -0
- package/dist/hooks/useAsync/useProxyState.d.ts.map +1 -0
- package/dist/hooks/useIntlayerAPI.cjs +6 -5
- package/dist/hooks/useIntlayerAPI.cjs.map +1 -1
- package/dist/hooks/useIntlayerAPI.d.ts +51 -45
- package/dist/hooks/useIntlayerAPI.d.ts.map +1 -1
- package/dist/hooks/useIntlayerAPI.mjs +5 -4
- package/dist/hooks/useIntlayerAPI.mjs.map +1 -1
- package/dist/hooks/useItemSelector.cjs +11 -2
- package/dist/hooks/useItemSelector.cjs.map +1 -1
- package/dist/hooks/useItemSelector.d.ts +3 -2
- package/dist/hooks/useItemSelector.d.ts.map +1 -1
- package/dist/hooks/useItemSelector.mjs +11 -2
- package/dist/hooks/useItemSelector.mjs.map +1 -1
- package/dist/hooks/usePersistedStore.cjs +22 -0
- package/dist/hooks/usePersistedStore.cjs.map +1 -0
- package/dist/hooks/usePersistedStore.d.ts +2 -0
- package/dist/hooks/usePersistedStore.d.ts.map +1 -0
- package/dist/hooks/usePersistedStore.mjs +22 -0
- package/dist/hooks/usePersistedStore.mjs.map +1 -0
- package/dist/hooks/usePersistenceStore.cjs +22 -0
- package/dist/hooks/usePersistenceStore.cjs.map +1 -0
- package/dist/hooks/usePersistenceStore.d.ts +2 -0
- package/dist/hooks/usePersistenceStore.d.ts.map +1 -0
- package/dist/hooks/usePersistenceStore.mjs +22 -0
- package/dist/hooks/usePersistenceStore.mjs.map +1 -0
- package/dist/libs/intlayer-api/auth.cjs +14 -2
- package/dist/libs/intlayer-api/auth.cjs.map +1 -1
- package/dist/libs/intlayer-api/auth.d.ts +7 -3
- package/dist/libs/intlayer-api/auth.d.ts.map +1 -1
- package/dist/libs/intlayer-api/auth.mjs +14 -2
- package/dist/libs/intlayer-api/auth.mjs.map +1 -1
- package/dist/libs/intlayer-api/fetcher.cjs +7 -1
- package/dist/libs/intlayer-api/fetcher.cjs.map +1 -1
- package/dist/libs/intlayer-api/fetcher.d.ts.map +1 -1
- package/dist/libs/intlayer-api/fetcher.mjs +7 -1
- package/dist/libs/intlayer-api/fetcher.mjs.map +1 -1
- package/dist/libs/intlayer-api/index.cjs +3 -1
- package/dist/libs/intlayer-api/index.cjs.map +1 -1
- package/dist/libs/intlayer-api/index.d.ts +12 -2
- package/dist/libs/intlayer-api/index.d.ts.map +1 -1
- package/dist/libs/intlayer-api/index.mjs +3 -1
- package/dist/libs/intlayer-api/index.mjs.map +1 -1
- package/dist/libs/intlayer-api/stripe.cjs +22 -0
- package/dist/libs/intlayer-api/stripe.cjs.map +1 -0
- package/dist/libs/intlayer-api/stripe.d.ts +6 -0
- package/dist/libs/intlayer-api/stripe.d.ts.map +1 -0
- package/dist/libs/intlayer-api/stripe.mjs +22 -0
- package/dist/libs/intlayer-api/stripe.mjs.map +1 -0
- package/dist/stripe-BsI0lJWz.js +22 -0
- package/dist/stripe-BsI0lJWz.js.map +1 -0
- package/dist/stripe-C-u5RvGh.js +22 -0
- package/dist/stripe-C-u5RvGh.js.map +1 -0
- package/dist/stripe-CF_E65Vu.js +22 -0
- package/dist/stripe-CF_E65Vu.js.map +1 -0
- package/dist/stripe-CpGvfq6T.cjs +21 -0
- package/dist/stripe-CpGvfq6T.cjs.map +1 -0
- package/dist/stripe-DEv4DjAL.cjs +21 -0
- package/dist/stripe-DEv4DjAL.cjs.map +1 -0
- package/dist/stripe-DuG0uaEn.cjs +21 -0
- package/dist/stripe-DuG0uaEn.cjs.map +1 -0
- package/dist/tailwind.css +1 -1
- package/dist/useProxyState-D5GLrY2y.js +20 -0
- package/dist/useProxyState-D5GLrY2y.js.map +1 -0
- package/dist/useProxyState-DewdF3no.cjs +19 -0
- package/dist/useProxyState-DewdF3no.cjs.map +1 -0
- package/package.json +15 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import require$$0, { useRef as useRef$1, useCallback, useEffect } from "react";
|
|
2
|
+
import require$$0, { useRef as useRef$1, useCallback, useEffect, useMemo } from "react";
|
|
3
3
|
import { useAsyncStateStore } from "./useAsyncStateStore.mjs";
|
|
4
4
|
function shallow(objA, objB) {
|
|
5
5
|
if (Object.is(objA, objB)) {
|
|
@@ -54,7 +54,8 @@ const DEFAULT_RETRY_LIMIT = 1;
|
|
|
54
54
|
const DEFAULT_REVALIDATION_ENABLED = false;
|
|
55
55
|
const DEFAULT_REVALIDATE_TIME = 5 * 60 * 1e3;
|
|
56
56
|
const DEFAULT_RETRY_TIME = 5 * 60 * 1e3;
|
|
57
|
-
const
|
|
57
|
+
const getArgs = (args) => args ? Array.isArray(args) ? args : [args] : [];
|
|
58
|
+
const getKeyWithArgs = (key, args) => getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;
|
|
58
59
|
const useAsync = (key, asyncFunction, options) => {
|
|
59
60
|
const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;
|
|
60
61
|
const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;
|
|
@@ -64,50 +65,31 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
64
65
|
const enabled = options?.enable ?? DEFAULT_ENABLED;
|
|
65
66
|
const revalidationEnabled = options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;
|
|
66
67
|
const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;
|
|
67
|
-
const isInvalidatedProps = options?.isInvalidated ?? false;
|
|
68
68
|
const updateQueries = options?.updateQueries ?? [];
|
|
69
69
|
const invalidateQueries = options?.invalidateQueries ?? [];
|
|
70
70
|
const onSuccess = options?.onSuccess;
|
|
71
71
|
const onError = options?.onError;
|
|
72
|
-
const args = options?.args ?? [];
|
|
73
|
-
const {
|
|
74
|
-
setIsFetched,
|
|
75
|
-
setIsLoading,
|
|
76
|
-
setError,
|
|
77
|
-
setIsSuccess,
|
|
78
|
-
setData,
|
|
79
|
-
setIsInvalidated,
|
|
80
|
-
setIsEnabled,
|
|
81
|
-
incrementRetryCount,
|
|
82
|
-
resetRetryCount
|
|
83
|
-
} = useAsyncStateStore(
|
|
72
|
+
const args = getArgs(options?.args ?? []);
|
|
73
|
+
const { setQueryState, setQueriesState, makeQueryInError } = useAsyncStateStore(
|
|
84
74
|
useShallow((state) => ({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
setIsSuccess: state.setIsSuccess,
|
|
89
|
-
setIsInvalidated: state.setIsInvalidated,
|
|
90
|
-
setIsEnabled: state.setIsEnabled,
|
|
91
|
-
setData: state.setData,
|
|
92
|
-
incrementRetryCount: state.incrementRetryCount,
|
|
93
|
-
resetRetryCount: state.resetRetryCount
|
|
75
|
+
setQueryState: state.setQueryState,
|
|
76
|
+
setQueriesState: state.setQueriesState,
|
|
77
|
+
makeQueryInError: state.makeQueryInError
|
|
94
78
|
}))
|
|
95
79
|
);
|
|
96
|
-
const storedArgsRef = useRef$1(args
|
|
80
|
+
const storedArgsRef = useRef$1(args);
|
|
97
81
|
const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);
|
|
98
82
|
const {
|
|
99
83
|
isFetched,
|
|
100
84
|
fetchedDateTime,
|
|
101
85
|
isLoading,
|
|
102
|
-
isEnabled
|
|
86
|
+
isEnabled,
|
|
103
87
|
error,
|
|
104
88
|
isSuccess,
|
|
105
89
|
isInvalidated,
|
|
106
90
|
data,
|
|
107
91
|
retryCount: errorCount
|
|
108
|
-
} = useAsyncStateStore((state) => state.getStates(keyWithArgs));
|
|
109
|
-
const isEnabled = isEnabledState || enabled;
|
|
110
|
-
const isDisabled = !isEnabled;
|
|
92
|
+
} = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));
|
|
111
93
|
const fetch = useCallback(
|
|
112
94
|
async (...args2) => {
|
|
113
95
|
const keyWithArgs2 = getKeyWithArgs(key, args2);
|
|
@@ -115,83 +97,90 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
115
97
|
return pendingPromises.get(keyWithArgs2);
|
|
116
98
|
}
|
|
117
99
|
const promise = (async () => {
|
|
118
|
-
|
|
100
|
+
setQueryState(keyWithArgs2, { isLoading: true });
|
|
119
101
|
let response = null;
|
|
120
102
|
await asyncFunction(...args2).then((result) => {
|
|
121
|
-
const isResultChanged = JSON.stringify(result) !== JSON.stringify(data);
|
|
122
103
|
response = result;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
104
|
+
setQueryState(keyWithArgs2, {
|
|
105
|
+
data: result,
|
|
106
|
+
retryCount: 0,
|
|
107
|
+
isLoading: false,
|
|
108
|
+
isFetched: true,
|
|
109
|
+
isSuccess: true,
|
|
110
|
+
isInvalidated: false,
|
|
111
|
+
error: null
|
|
112
|
+
});
|
|
127
113
|
onSuccess?.(result);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
if (isResultChanged && updateQueries.length > 0) {
|
|
133
|
-
updateQueries.forEach((key2) => {
|
|
134
|
-
setData(key2, result);
|
|
114
|
+
if (invalidateQueries.length > 0) {
|
|
115
|
+
setQueriesState(invalidateQueries, {
|
|
116
|
+
isInvalidated: true
|
|
135
117
|
});
|
|
136
118
|
}
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
119
|
+
if (updateQueries.length > 0) {
|
|
120
|
+
setQueriesState(updateQueries, {
|
|
121
|
+
data: result
|
|
140
122
|
});
|
|
141
123
|
}
|
|
124
|
+
if (storeEnabled) {
|
|
125
|
+
sessionStorage.setItem(keyWithArgs2, JSON.stringify(result));
|
|
126
|
+
}
|
|
142
127
|
}).catch((error2) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
setData(keyWithArgs2, null);
|
|
146
|
-
setError(keyWithArgs2, errorMessage);
|
|
147
|
-
incrementRetryCount(keyWithArgs2);
|
|
148
|
-
onError?.(errorMessage);
|
|
128
|
+
makeQueryInError(keyWithArgs2, error2.message);
|
|
129
|
+
onError?.(error2.message);
|
|
149
130
|
}).finally(() => {
|
|
150
|
-
setIsLoading(keyWithArgs2, false);
|
|
151
|
-
setIsFetched(keyWithArgs2, true);
|
|
152
|
-
setIsInvalidated(keyWithArgs2, false);
|
|
153
131
|
pendingPromises.delete(keyWithArgs2);
|
|
154
132
|
});
|
|
155
133
|
return response;
|
|
156
134
|
})();
|
|
157
135
|
pendingPromises.set(keyWithArgs2, promise);
|
|
136
|
+
return await promise;
|
|
158
137
|
},
|
|
159
|
-
[asyncFunction, keyWithArgs]
|
|
138
|
+
[asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]
|
|
160
139
|
);
|
|
161
140
|
const execute = useCallback(
|
|
162
141
|
async (...args2) => {
|
|
163
|
-
if (
|
|
142
|
+
if (!isEnabled || !enabled) return;
|
|
164
143
|
if (isLoading) return;
|
|
165
|
-
if (isSuccess && cacheEnabled && data) return data;
|
|
144
|
+
if (!isInvalidated && isSuccess && cacheEnabled && data) return data;
|
|
166
145
|
if (args2) {
|
|
167
|
-
storedArgsRef.current = args2;
|
|
146
|
+
storedArgsRef.current = getArgs(...args2);
|
|
168
147
|
}
|
|
169
|
-
await fetch(...args2);
|
|
148
|
+
return await fetch(...args2);
|
|
170
149
|
},
|
|
171
|
-
[
|
|
150
|
+
[
|
|
151
|
+
isEnabled,
|
|
152
|
+
enabled,
|
|
153
|
+
isInvalidated,
|
|
154
|
+
cacheEnabled,
|
|
155
|
+
isSuccess,
|
|
156
|
+
data,
|
|
157
|
+
isLoading,
|
|
158
|
+
fetch
|
|
159
|
+
]
|
|
172
160
|
);
|
|
173
161
|
const revalidate = useCallback(
|
|
174
162
|
async (...args2) => {
|
|
175
|
-
if (
|
|
176
|
-
if (isSuccess) return;
|
|
177
|
-
if (isLoading) return;
|
|
163
|
+
if (!isEnabled || !enabled) return;
|
|
178
164
|
if (args2) {
|
|
179
|
-
storedArgsRef.current = args2;
|
|
165
|
+
storedArgsRef.current = getArgs(...args2);
|
|
180
166
|
}
|
|
181
|
-
await fetch(...storedArgsRef.current);
|
|
167
|
+
const result = await fetch(...storedArgsRef.current);
|
|
168
|
+
return result;
|
|
182
169
|
},
|
|
183
|
-
[
|
|
170
|
+
[isEnabled, enabled, storedArgsRef, fetch]
|
|
184
171
|
);
|
|
185
|
-
const autoRevalidate = useCallback(() => {
|
|
186
|
-
if (
|
|
187
|
-
if (isLoading
|
|
188
|
-
if (!
|
|
172
|
+
const autoRevalidate = useCallback(async () => {
|
|
173
|
+
if (!isEnabled || !enabled) return;
|
|
174
|
+
if (isLoading) return;
|
|
175
|
+
if (!(cacheEnabled || storeEnabled)) return;
|
|
176
|
+
if (!isSuccess) return;
|
|
177
|
+
if (!revalidationEnabled || revalidateTime <= 0) return;
|
|
189
178
|
if (!fetchedDateTime) return;
|
|
190
179
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
191
180
|
const lastFetchedTime = new Date(fetchedDateTime).getTime();
|
|
192
181
|
const shouldRevalidate = now - lastFetchedTime >= revalidateTime;
|
|
193
182
|
if (shouldRevalidate) {
|
|
194
|
-
fetch(...storedArgsRef.current);
|
|
183
|
+
return await fetch(...storedArgsRef.current);
|
|
195
184
|
}
|
|
196
185
|
}, [
|
|
197
186
|
cacheEnabled,
|
|
@@ -200,70 +189,119 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
200
189
|
isSuccess,
|
|
201
190
|
fetchedDateTime,
|
|
202
191
|
isLoading,
|
|
203
|
-
|
|
192
|
+
isEnabled,
|
|
193
|
+
enabled
|
|
204
194
|
]);
|
|
205
195
|
useEffect(() => {
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
if (enabled !== isEnabled) {
|
|
197
|
+
setQueryState(keyWithArgs, {
|
|
198
|
+
isEnabled
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}, [enabled, keyWithArgs]);
|
|
208
202
|
useEffect(() => {
|
|
209
203
|
if (!autoFetch) return;
|
|
210
|
-
if (
|
|
211
|
-
if (isFetched
|
|
204
|
+
if (!isEnabled || !enabled) return;
|
|
205
|
+
if (isFetched && !isInvalidated) return;
|
|
206
|
+
if (isLoading) return;
|
|
212
207
|
fetch(...storedArgsRef.current);
|
|
213
|
-
}, [
|
|
208
|
+
}, [
|
|
209
|
+
autoFetch,
|
|
210
|
+
isFetched,
|
|
211
|
+
isInvalidated,
|
|
212
|
+
isEnabled,
|
|
213
|
+
enabled,
|
|
214
|
+
isLoading,
|
|
215
|
+
fetch
|
|
216
|
+
]);
|
|
214
217
|
useEffect(() => {
|
|
215
218
|
const isRetryEnabled = errorCount > 0 && retryLimit > 0;
|
|
216
219
|
const isRetryLimitReached = errorCount >= retryLimit;
|
|
217
|
-
if (
|
|
220
|
+
if (!isEnabled || !enabled) return;
|
|
218
221
|
if (!(cacheEnabled || storeEnabled)) return;
|
|
219
222
|
if (!isRetryEnabled || isRetryLimitReached) return;
|
|
220
223
|
if (isSuccess) return;
|
|
221
224
|
if (isLoading) return;
|
|
222
225
|
const timeOut = setTimeout(() => {
|
|
223
|
-
|
|
224
|
-
execute(...storedArgsRef.current);
|
|
225
|
-
}
|
|
226
|
+
fetch(...storedArgsRef.current);
|
|
226
227
|
}, retryTime);
|
|
227
228
|
return () => clearTimeout(timeOut);
|
|
228
|
-
}, [
|
|
229
|
+
}, [
|
|
230
|
+
fetch,
|
|
231
|
+
errorCount,
|
|
232
|
+
retryLimit,
|
|
233
|
+
retryTime,
|
|
234
|
+
isSuccess,
|
|
235
|
+
isEnabled,
|
|
236
|
+
enabled,
|
|
237
|
+
isLoading,
|
|
238
|
+
cacheEnabled,
|
|
239
|
+
storeEnabled
|
|
240
|
+
]);
|
|
229
241
|
useEffect(() => {
|
|
230
242
|
const interval = setInterval(autoRevalidate, revalidateTime);
|
|
231
243
|
return () => clearInterval(interval);
|
|
232
244
|
}, [autoRevalidate, revalidateTime]);
|
|
233
245
|
useEffect(() => {
|
|
234
|
-
if (
|
|
246
|
+
if (!isEnabled || !enabled) return;
|
|
235
247
|
if (!storeEnabled) return;
|
|
236
248
|
if (isInvalidated) return;
|
|
237
249
|
if (isFetched) return;
|
|
250
|
+
if (data) return;
|
|
238
251
|
const storedData = sessionStorage.getItem(keyWithArgs);
|
|
239
|
-
if (storedData) {
|
|
240
|
-
|
|
252
|
+
if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {
|
|
253
|
+
setQueryState(keyWithArgs, {
|
|
254
|
+
data: JSON.parse(storedData)
|
|
255
|
+
});
|
|
241
256
|
}
|
|
242
|
-
}, [
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
257
|
+
}, [
|
|
258
|
+
storeEnabled,
|
|
259
|
+
keyWithArgs,
|
|
260
|
+
isFetched,
|
|
261
|
+
isInvalidated,
|
|
262
|
+
isEnabled,
|
|
263
|
+
enabled,
|
|
264
|
+
data
|
|
265
|
+
]);
|
|
247
266
|
const setDataMemo = useCallback(
|
|
248
267
|
(data2) => {
|
|
249
|
-
|
|
268
|
+
setQueryState(keyWithArgs, {
|
|
269
|
+
data: data2
|
|
270
|
+
});
|
|
250
271
|
},
|
|
251
272
|
[keyWithArgs]
|
|
252
273
|
);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
274
|
+
const memoResult = useMemo(
|
|
275
|
+
() => ({
|
|
276
|
+
isFetched,
|
|
277
|
+
isLoading,
|
|
278
|
+
isInvalidated,
|
|
279
|
+
error,
|
|
280
|
+
isSuccess,
|
|
281
|
+
data,
|
|
282
|
+
retryCount: errorCount,
|
|
283
|
+
isDisabled: !isEnabled,
|
|
284
|
+
isEnabled,
|
|
285
|
+
[key]: execute,
|
|
286
|
+
revalidate,
|
|
287
|
+
setData: setDataMemo
|
|
288
|
+
}),
|
|
289
|
+
[
|
|
290
|
+
isFetched,
|
|
291
|
+
isLoading,
|
|
292
|
+
isInvalidated,
|
|
293
|
+
error,
|
|
294
|
+
isSuccess,
|
|
295
|
+
data,
|
|
296
|
+
errorCount,
|
|
297
|
+
isEnabled,
|
|
298
|
+
key,
|
|
299
|
+
execute,
|
|
300
|
+
revalidate,
|
|
301
|
+
setDataMemo
|
|
302
|
+
]
|
|
303
|
+
);
|
|
304
|
+
return memoResult;
|
|
267
305
|
};
|
|
268
306
|
export {
|
|
269
307
|
useAsync
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.mjs","sources":["../../../../../../node_modules/.pnpm/zustand@4.5.5_@types+react@18.3.12_react@18.3.1/node_modules/zustand/esm/react/shallow.mjs","../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import ReactExports from 'react';\n\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false;\n }\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false;\n for (const [key, value] of objA) {\n if (!Object.is(value, objB.get(key))) {\n return false;\n }\n }\n return true;\n }\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false;\n for (const value of objA) {\n if (!objB.has(value)) {\n return false;\n }\n }\n return true;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (const keyA of keysA) {\n if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {\n return false;\n }\n }\n return true;\n}\n\nconst { useRef } = ReactExports;\nfunction useShallow(selector) {\n const prev = useRef();\n return (state) => {\n const next = selector(state);\n return shallow(prev.current, next) ? prev.current : prev.current = next;\n };\n}\n\nexport { useShallow };\n","'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n isInvalidated?: boolean; // Determine if the data is invalidated and should be refetched\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n args.length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [isInvalidated=false] - Determine if the data is invalidated and should be refetched.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const isInvalidatedProps = options?.isInvalidated ?? false;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = options?.args ?? [];\n\n // Using a custom hook to manage state specific to asynchronous operations\n const {\n setIsFetched,\n setIsLoading,\n setError,\n setIsSuccess,\n setData,\n setIsInvalidated,\n setIsEnabled,\n incrementRetryCount,\n resetRetryCount,\n } = useAsyncStateStore(\n useShallow((state) => ({\n setIsFetched: state.setIsFetched,\n setIsLoading: state.setIsLoading,\n setError: state.setError,\n setIsSuccess: state.setIsSuccess,\n setIsInvalidated: state.setIsInvalidated,\n setIsEnabled: state.setIsEnabled,\n setData: state.setData,\n incrementRetryCount: state.incrementRetryCount,\n resetRetryCount: state.resetRetryCount,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any>(args ?? []);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled: isEnabledState,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore((state) => state.getStates(keyWithArgs));\n\n const isEnabled = isEnabledState || enabled;\n const isDisabled = !isEnabled;\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setIsLoading(keyWithArgs, true);\n let response = null;\n let errorResponse = null;\n\n await asyncFunction(...args)\n .then((result) => {\n const isResultChanged =\n JSON.stringify(result) !== JSON.stringify(data);\n\n response = result;\n if (isResultChanged) {\n setData(keyWithArgs, result);\n }\n setIsSuccess(keyWithArgs, true);\n onSuccess?.(result);\n resetRetryCount(keyWithArgs);\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n\n // Update other queries if necessary\n if (isResultChanged && updateQueries.length > 0) {\n updateQueries.forEach((key) => {\n setData(key, result);\n });\n }\n\n // Invalidate other queries if necessary\n if (isResultChanged && invalidateQueries.length > 0) {\n invalidateQueries.forEach((key) => {\n setIsInvalidated(key, true);\n });\n }\n })\n .catch((error) => {\n const errorMessage = error.message ?? 'An error occurred';\n console.error(JSON.stringify(error));\n\n setData(keyWithArgs, null);\n setError(keyWithArgs, errorMessage);\n incrementRetryCount(keyWithArgs);\n onError?.(errorMessage);\n errorResponse = error;\n })\n .finally(() => {\n setIsLoading(keyWithArgs, false);\n setIsFetched(keyWithArgs, true);\n setIsInvalidated(keyWithArgs, false);\n\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n }) as T,\n [asyncFunction, keyWithArgs]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (isDisabled) return;\n if (isLoading) return;\n if (isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = args;\n }\n\n await fetch(...args);\n }) as T,\n [isDisabled, cacheEnabled, isSuccess, data, isLoading]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (isDisabled) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n if (args) {\n storedArgsRef.current = args;\n }\n\n await fetch(...storedArgsRef.current);\n }) as T,\n [isDisabled, storedArgsRef, isSuccess, isLoading]\n );\n\n const autoRevalidate = useCallback(() => {\n if (isDisabled) return;\n if (isLoading || !(cacheEnabled || storeEnabled)) return;\n if (!revalidationEnabled || revalidateTime <= 0 || !isSuccess) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isDisabled,\n ]);\n\n useEffect(() => {\n setIsEnabled(keyWithArgs, enabled);\n }, [enabled]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (isDisabled) return;\n if (isFetched || isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [autoFetch, isFetched, isDisabled, isLoading]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (isDisabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n if (isRetryEnabled && !isRetryLimitReached && !isSuccess) {\n execute(...storedArgsRef.current);\n }\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [execute, errorCount, retryLimit, retryTime, isSuccess]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (isDisabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData) {\n setData(keyWithArgs, JSON.parse(storedData));\n }\n }, [storeEnabled, keyWithArgs, isFetched, isInvalidated, isDisabled]);\n\n // Handle invalidation if props are changed\n useEffect(() => {\n if (!isInvalidatedProps) return;\n setIsInvalidated(keyWithArgs, isInvalidatedProps);\n }, [isInvalidatedProps]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setData(keyWithArgs, data);\n },\n [keyWithArgs]\n );\n\n // Return the hook's result, including all state and control functions\n return {\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n } as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["ReactExports","useRef","args","keyWithArgs","key","error","data"],"mappings":";;;AAEA,SAAS,QAAQ,MAAM,MAAM;AAC3B,MAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AACzB,WAAO;AAAA,EACR;AACD,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS,MAAM;AAC1F,WAAO;AAAA,EACR;AACD,MAAI,gBAAgB,OAAO,gBAAgB,KAAK;AAC9C,QAAI,KAAK,SAAS,KAAK,KAAM,QAAO;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A,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,CAAC,GAAG,GAAG;AAAA,IACP;AAAA,IACA,SAAS;AAAA,EAAA;AAEb;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"useAsync.mjs","sources":["../../../../../../node_modules/.pnpm/zustand@4.5.5_@types+react@18.3.12_react@18.3.1/node_modules/zustand/esm/react/shallow.mjs","../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import ReactExports from 'react';\n\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false;\n }\n if (objA instanceof Map && objB instanceof Map) {\n if (objA.size !== objB.size) return false;\n for (const [key, value] of objA) {\n if (!Object.is(value, objB.get(key))) {\n return false;\n }\n }\n return true;\n }\n if (objA instanceof Set && objB instanceof Set) {\n if (objA.size !== objB.size) return false;\n for (const value of objA) {\n if (!objB.has(value)) {\n return false;\n }\n }\n return true;\n }\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (const keyA of keysA) {\n if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {\n return false;\n }\n }\n return true;\n}\n\nconst { useRef } = ReactExports;\nfunction useShallow(selector) {\n const prev = useRef();\n return (state) => {\n const next = selector(state);\n return shallow(prev.current, next) ? prev.current : prev.current = next;\n };\n}\n\nexport { useShallow };\n","'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function using zustand\n store?: boolean; // Store the result of the function in session storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\n .finally(() => {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n });\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T,\n [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\n ]\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["ReactExports","useRef","args","keyWithArgs","error","data"],"mappings":";;;AAEA,SAAS,QAAQ,MAAM,MAAM;AAC3B,MAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AACzB,WAAO;AAAA,EACR;AACD,MAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS,MAAM;AAC1F,WAAO;AAAA,EACR;AACD,MAAI,gBAAgB,OAAO,gBAAg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D;AAAA,IACH;AAAA,IACA,CAAC,WAAW;AAAA,EAAA;AAGd,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAIK,SAAA;AACT;","x_google_ignoreList":[0]}
|
|
@@ -29,140 +29,78 @@ const getMatchKeys = (selectorsKeys, keysWithArgs) => {
|
|
|
29
29
|
const useAsyncStateStore = zustand.create((set, get) => ({
|
|
30
30
|
states: {},
|
|
31
31
|
getStates: (key) => get().states[key] ?? createDefaultStates(),
|
|
32
|
-
|
|
32
|
+
setQueryState: (key, value) => set((state) => ({
|
|
33
33
|
states: {
|
|
34
34
|
...state.states,
|
|
35
35
|
[key]: {
|
|
36
36
|
...state.states[key] ?? createDefaultStates(),
|
|
37
|
-
|
|
38
|
-
fetchedDateTime: /* @__PURE__ */ new Date()
|
|
37
|
+
...value
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
})),
|
|
42
|
-
|
|
41
|
+
makeQueryInError: (key, error) => set((state) => ({
|
|
43
42
|
states: {
|
|
44
43
|
...state.states,
|
|
45
44
|
[key]: {
|
|
46
45
|
...state.states[key] ?? createDefaultStates(),
|
|
47
|
-
|
|
46
|
+
error,
|
|
47
|
+
isFetched: true,
|
|
48
|
+
isSuccess: false,
|
|
49
|
+
retryCount: (state.states[key]?.retryCount ?? 0) + 1,
|
|
50
|
+
isLoading: false,
|
|
51
|
+
isInvalidated: false
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
})),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...state.states[key] ?? createDefaultStates(),
|
|
65
|
-
isSuccess: value
|
|
55
|
+
setQueriesState: (keys, value) => {
|
|
56
|
+
const keyArray = ensureArray(keys);
|
|
57
|
+
if (keyArray.length === 0) return;
|
|
58
|
+
set((state) => ({
|
|
59
|
+
states: {
|
|
60
|
+
...state.states,
|
|
61
|
+
...keyArray.reduce((acc, key) => {
|
|
62
|
+
acc[key] = {
|
|
63
|
+
...state.states[key] ?? createDefaultStates(),
|
|
64
|
+
...value
|
|
65
|
+
};
|
|
66
|
+
return acc;
|
|
67
|
+
}, {})
|
|
66
68
|
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
}));
|
|
70
|
+
},
|
|
71
|
+
resetKeyState: (keys) => {
|
|
72
|
+
const keyArray = ensureArray(keys);
|
|
73
|
+
if (keyArray.length === 0) return;
|
|
74
|
+
set((state) => {
|
|
71
75
|
const allKeys = Object.keys(state.states);
|
|
72
|
-
const matchedKeys = getMatchKeys(
|
|
73
|
-
matchedKeys.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const matchedKeys = getMatchKeys(keyArray, allKeys);
|
|
77
|
+
if (matchedKeys.length === 0) return {};
|
|
78
|
+
const resetStates = matchedKeys.reduce((acc, key) => {
|
|
79
|
+
acc[key] = createDefaultStates();
|
|
80
|
+
return acc;
|
|
81
|
+
}, {});
|
|
76
82
|
return {
|
|
77
83
|
states: {
|
|
78
84
|
...state.states,
|
|
79
|
-
|
|
80
|
-
...createDefaultStates(),
|
|
81
|
-
isInvalidated: true
|
|
82
|
-
}
|
|
85
|
+
...resetStates
|
|
83
86
|
}
|
|
84
87
|
};
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
states: {
|
|
88
|
-
...state.states,
|
|
89
|
-
[key]: {
|
|
90
|
-
...state.states[key] ?? createDefaultStates(),
|
|
91
|
-
isInvalidated: false
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}),
|
|
96
|
-
setData: (key, value) => set((state) => ({
|
|
97
|
-
states: {
|
|
98
|
-
...state.states,
|
|
99
|
-
[key]: {
|
|
100
|
-
...state.states[key] ?? createDefaultStates(),
|
|
101
|
-
data: value
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})),
|
|
105
|
-
incrementRetryCount: (key) => set((state) => {
|
|
106
|
-
const prevState = state.states[key] ?? createDefaultStates();
|
|
107
|
-
return {
|
|
108
|
-
states: {
|
|
109
|
-
...state.states,
|
|
110
|
-
[key]: {
|
|
111
|
-
...prevState,
|
|
112
|
-
retryCount: prevState.retryCount + 1
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}),
|
|
117
|
-
resetRetryCount: (key) => set((state) => {
|
|
118
|
-
const prevState = state.states[key] ?? createDefaultStates();
|
|
119
|
-
return {
|
|
120
|
-
states: {
|
|
121
|
-
...state.states,
|
|
122
|
-
[key]: {
|
|
123
|
-
...prevState,
|
|
124
|
-
retryCount: 0
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}),
|
|
129
|
-
setIsEnabled: (key, value) => set((state) => ({
|
|
130
|
-
states: {
|
|
131
|
-
...state.states,
|
|
132
|
-
[key]: {
|
|
133
|
-
...state.states[key] ?? createDefaultStates(),
|
|
134
|
-
isEnabled: value
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
})),
|
|
138
|
-
resetKeyState: (key) => set((state) => {
|
|
139
|
-
const keys = ensureArray(key);
|
|
140
|
-
const allKeys = Object.keys(state.states);
|
|
141
|
-
const matchedKeys = getMatchKeys(keys, allKeys);
|
|
142
|
-
const newStates = { ...state.states };
|
|
143
|
-
matchedKeys.forEach((k) => {
|
|
144
|
-
newStates[k] = createDefaultStates();
|
|
145
88
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}, {});
|
|
162
|
-
return {
|
|
163
|
-
states: newStates
|
|
164
|
-
};
|
|
165
|
-
})
|
|
89
|
+
},
|
|
90
|
+
resetState: (excludedKeys) => {
|
|
91
|
+
const excludeArray = ensureArray(excludedKeys);
|
|
92
|
+
const allKeys = Object.keys(get().states);
|
|
93
|
+
const matchedKeys = getMatchKeys(excludeArray, allKeys);
|
|
94
|
+
set((state) => {
|
|
95
|
+
const newStates = allKeys.reduce((acc, key) => {
|
|
96
|
+
acc[key] = matchedKeys.includes(key) ? state.states[key] : createDefaultStates();
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
return {
|
|
100
|
+
states: newStates
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
166
104
|
}));
|
|
167
105
|
exports.useAsyncStateStore = useAsyncStateStore;
|
|
168
106
|
//# sourceMappingURL=useAsyncStateStore.cjs.map
|