@refinedev/core 4.47.2 → 4.48.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/CHANGELOG.md +2944 -2919
- package/dist/components/authenticated/index.d.ts.map +1 -1
- package/dist/components/autoSaveIndicator/index.d.ts.map +1 -1
- package/dist/components/canAccess/index.d.ts.map +1 -1
- package/dist/components/containers/refine/index.d.ts.map +1 -1
- package/dist/components/layoutWrapper/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/index.d.ts.map +1 -1
- package/dist/components/pages/config-error/index.d.ts.map +1 -1
- package/dist/components/pages/config-success/index.d.ts.map +1 -1
- package/dist/components/pages/login/index.d.ts.map +1 -1
- package/dist/components/pages/ready/index.d.ts.map +1 -1
- package/dist/components/undoableQueue/index.d.ts.map +1 -1
- package/dist/contexts/accessControl/IAccessControlContext.d.ts.map +1 -1
- package/dist/contexts/accessControl/index.d.ts.map +1 -1
- package/dist/contexts/auditLog/IAuditLogContext.d.ts.map +1 -1
- package/dist/contexts/auditLog/index.d.ts.map +1 -1
- package/dist/contexts/auth/IAuthContext.d.ts +1 -1
- package/dist/contexts/auth/IAuthContext.d.ts.map +1 -1
- package/dist/contexts/auth/index.d.ts.map +1 -1
- package/dist/contexts/data/IDataContext.d.ts.map +1 -1
- package/dist/contexts/data/index.d.ts.map +1 -1
- package/dist/contexts/legacy-router/IRouterContext.d.ts.map +1 -1
- package/dist/contexts/legacy-router/index.d.ts.map +1 -1
- package/dist/contexts/live/ILiveContext.d.ts.map +1 -1
- package/dist/contexts/live/index.d.ts.map +1 -1
- package/dist/contexts/notification/INotificationContext.d.ts.map +1 -1
- package/dist/contexts/notification/index.d.ts.map +1 -1
- package/dist/contexts/refine/IRefineContext.d.ts.map +1 -1
- package/dist/contexts/refine/index.d.ts.map +1 -1
- package/dist/contexts/resource/IResourceContext.d.ts.map +1 -1
- package/dist/contexts/resource/index.d.ts.map +1 -1
- package/dist/contexts/router/index.d.ts.map +1 -1
- package/dist/contexts/translation/ITranslationContext.d.ts.map +1 -1
- package/dist/contexts/translation/index.d.ts.map +1 -1
- package/dist/contexts/undoableQueue/IUndoableQueueContext.d.ts.map +1 -1
- package/dist/contexts/undoableQueue/actionTypes.d.ts.map +1 -1
- package/dist/contexts/undoableQueue/index.d.ts.map +1 -1
- package/dist/contexts/undoableQueue/undoableQueueContext.d.ts.map +1 -1
- package/dist/contexts/unsavedWarn/IUnsavedWarnContext.d.ts.map +1 -1
- package/dist/definitions/helpers/check-router-prop-misuse/index.d.ts.map +1 -1
- package/dist/definitions/helpers/downloadInBrowser/index.d.ts.map +1 -1
- package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -1
- package/dist/definitions/helpers/generateDocumentTitle/index.d.ts.map +1 -1
- package/dist/definitions/helpers/handlePaginationParams/index.d.ts.map +1 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
- package/dist/definitions/helpers/hasPermission/index.d.ts.map +1 -1
- package/dist/definitions/helpers/importCSVMapper/index.d.ts.map +1 -1
- package/dist/definitions/helpers/index.d.ts.map +1 -1
- package/dist/definitions/helpers/keys/index.d.ts +0 -11
- package/dist/definitions/helpers/keys/index.d.ts.map +1 -1
- package/dist/definitions/helpers/legacy-resource-transform/index.d.ts.map +1 -1
- package/dist/definitions/helpers/menu/create-resource-key.d.ts.map +1 -1
- package/dist/definitions/helpers/menu/create-tree.d.ts.map +1 -1
- package/dist/definitions/helpers/pick-resource/index.d.ts.map +1 -1
- package/dist/definitions/helpers/pickDataProvider/index.d.ts.map +1 -1
- package/dist/definitions/helpers/queryKeys/index.d.ts.map +1 -1
- package/dist/definitions/helpers/redirectPage/index.d.ts.map +1 -1
- package/dist/definitions/helpers/routeGenerator/index.d.ts.map +1 -1
- package/dist/definitions/helpers/router/compose-route.d.ts.map +1 -1
- package/dist/definitions/helpers/router/get-action-routes-from-resource.d.ts.map +1 -1
- package/dist/definitions/helpers/router/get-default-action-path.d.ts.map +1 -1
- package/dist/definitions/helpers/router/get-parent-prefix-for-resource.d.ts.map +1 -1
- package/dist/definitions/helpers/router/get-parent-resource.d.ts.map +1 -1
- package/dist/definitions/helpers/router/match-resource-from-route.d.ts.map +1 -1
- package/dist/definitions/helpers/router/pick-matched-route.d.ts.map +1 -1
- package/dist/definitions/helpers/router/prepare-route-params.d.ts.map +1 -1
- package/dist/definitions/helpers/safe-translate/index.d.ts.map +1 -1
- package/dist/definitions/helpers/sanitize-resource/index.d.ts.map +1 -1
- package/dist/definitions/helpers/sequentialPromises/index.d.ts.map +1 -1
- package/dist/definitions/helpers/treeView/createTreeView/index.d.ts.map +1 -1
- package/dist/definitions/helpers/useActiveAuthProvider/index.d.ts +2 -2
- package/dist/definitions/helpers/useUserFriendlyName/index.d.ts.map +1 -1
- package/dist/definitions/helpers/userFriendlyResourceName/index.d.ts.map +1 -1
- package/dist/definitions/table/index.d.ts.map +1 -1
- package/dist/esm/index.js +18 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
- package/dist/hooks/accessControl/useCanWithoutCache.d.ts.map +1 -1
- package/dist/hooks/auditLog/useLog/index.d.ts.map +1 -1
- package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
- package/dist/hooks/auth/useForgotPassword/index.d.ts.map +1 -1
- package/dist/hooks/auth/useGetIdentity/index.d.ts.map +1 -1
- package/dist/hooks/auth/useIsAuthenticated/index.d.ts.map +1 -1
- package/dist/hooks/auth/useLogin/index.d.ts.map +1 -1
- package/dist/hooks/auth/useLogout/index.d.ts.map +1 -1
- package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
- package/dist/hooks/auth/usePermissions/index.d.ts +9 -6
- package/dist/hooks/auth/usePermissions/index.d.ts.map +1 -1
- package/dist/hooks/auth/useRegister/index.d.ts.map +1 -1
- package/dist/hooks/auth/useUpdatePassword/index.d.ts.map +1 -1
- package/dist/hooks/breadcrumb/index.d.ts.map +1 -1
- package/dist/hooks/data/useApiUrl.d.ts.map +1 -1
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
- package/dist/hooks/data/useDataProvider.d.ts.map +1 -1
- package/dist/hooks/data/useDelete.d.ts.map +1 -1
- package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/export/csvDownload.interface.d.ts.map +1 -1
- package/dist/hooks/export/index.d.ts +1 -1
- package/dist/hooks/export/index.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/import/index.d.ts.map +1 -1
- package/dist/hooks/invalidate/index.d.ts.map +1 -1
- package/dist/hooks/live/useLiveMode/index.d.ts.map +1 -1
- package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
- package/dist/hooks/live/useSubscription/index.d.ts.map +1 -1
- package/dist/hooks/menu/useMenu.d.ts.map +1 -1
- package/dist/hooks/modal/useModal/index.d.ts.map +1 -1
- package/dist/hooks/navigation/index.d.ts.map +1 -1
- package/dist/hooks/notification/useCancelNotification/index.d.ts.map +1 -1
- package/dist/hooks/notification/useHandleNotification/index.d.ts.map +1 -1
- package/dist/hooks/redirection/index.d.ts.map +1 -1
- package/dist/hooks/refine/useMutationMode.d.ts.map +1 -1
- package/dist/hooks/refine/useSyncWithLocation.d.ts.map +1 -1
- package/dist/hooks/refine/useWarnAboutChange/index.d.ts.map +1 -1
- package/dist/hooks/resource/useResource/index.d.ts.map +1 -1
- package/dist/hooks/router/use-get-to-path/index.d.ts.map +1 -1
- package/dist/hooks/router/use-go/index.d.ts.map +1 -1
- package/dist/hooks/router/use-link/index.d.ts.map +1 -1
- package/dist/hooks/router/use-parse/index.d.ts.map +1 -1
- package/dist/hooks/router/use-to-path/index.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/translate/useSetLocale.d.ts.map +1 -1
- package/dist/hooks/translate/useTranslate.d.ts.map +1 -1
- package/dist/hooks/useLoadingOvertime/index.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.ts +18 -4
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/iife/index.js +18 -18
- package/dist/iife/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/interfaces/actions.d.ts.map +1 -1
- package/dist/interfaces/auditLog/logData.d.ts.map +1 -1
- package/dist/interfaces/auth.d.ts.map +1 -1
- package/dist/interfaces/autoSave.d.ts.map +1 -1
- package/dist/interfaces/bindings/access-control.d.ts.map +1 -1
- package/dist/interfaces/bindings/auth.d.ts +1 -1
- package/dist/interfaces/bindings/auth.d.ts.map +1 -1
- package/dist/interfaces/bindings/data.d.ts.map +1 -1
- package/dist/interfaces/bindings/i18n.d.ts.map +1 -1
- package/dist/interfaces/bindings/index.d.ts.map +1 -1
- package/dist/interfaces/bindings/live.d.ts.map +1 -1
- package/dist/interfaces/bindings/notifications.d.ts.map +1 -1
- package/dist/interfaces/bindings/resource.d.ts.map +1 -1
- package/dist/interfaces/bindings/router.d.ts.map +1 -1
- package/dist/interfaces/customComponents.d.ts.map +1 -1
- package/dist/interfaces/errors/HttpError.d.ts.map +1 -1
- package/dist/interfaces/form-url-params.d.ts.map +1 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/live/LiveEvent.d.ts.map +1 -1
- package/dist/interfaces/live/LiveModeProps.d.ts.map +1 -1
- package/dist/interfaces/mapDataFn.d.ts.map +1 -1
- package/dist/interfaces/metaData/graphqlQueryOptions.d.ts.map +1 -1
- package/dist/interfaces/metaData/metaDataQuery.d.ts.map +1 -1
- package/dist/interfaces/metaData/metaQuery.d.ts.map +1 -1
- package/dist/interfaces/metaData/nestedField.d.ts.map +1 -1
- package/dist/interfaces/metaData/queryBuilderOptions.d.ts.map +1 -1
- package/dist/interfaces/metaData/variableOptions.d.ts.map +1 -1
- package/dist/interfaces/mutationMode.d.ts.map +1 -1
- package/dist/interfaces/notification.d.ts.map +1 -1
- package/dist/interfaces/optimistic-update-map.d.ts.map +1 -1
- package/dist/interfaces/prettify.d.ts.map +1 -1
- package/dist/interfaces/queryKey.d.ts.map +1 -1
- package/dist/interfaces/resourceErrorRouterParams.d.ts.map +1 -1
- package/dist/interfaces/resourceRouterParams.d.ts.map +1 -1
- package/dist/interfaces/successErrorNotification.d.ts +4 -4
- package/dist/interfaces/successErrorNotification.d.ts.map +1 -1
- package/dist/interfaces/telemetry.d.ts.map +1 -1
- package/dist/interfaces/textTransformers.d.ts.map +1 -1
- package/package.json +2 -2
- package/refine.config.js +99 -102
- package/src/components/authenticated/index.tsx +157 -159
- package/src/components/autoSaveIndicator/index.tsx +23 -27
- package/src/components/canAccess/index.tsx +93 -93
- package/src/components/containers/refine/index.tsx +312 -353
- package/src/components/gh-banner/index.tsx +235 -242
- package/src/components/gh-banner/styles.ts +5 -5
- package/src/components/layoutWrapper/defaultLayout/index.tsx +1 -1
- package/src/components/layoutWrapper/index.tsx +87 -87
- package/src/components/pages/auth/components/forgotPassword/index.tsx +87 -96
- package/src/components/pages/auth/components/login/index.tsx +166 -181
- package/src/components/pages/auth/components/register/index.tsx +141 -159
- package/src/components/pages/auth/components/updatePassword/index.tsx +81 -87
- package/src/components/pages/auth/index.tsx +28 -28
- package/src/components/pages/config-error/index.tsx +422 -422
- package/src/components/pages/config-success/index.tsx +249 -260
- package/src/components/pages/error/index.tsx +48 -48
- package/src/components/pages/login/index.tsx +59 -73
- package/src/components/pages/ready/index.tsx +21 -29
- package/src/components/pages/welcome/index.tsx +7 -7
- package/src/components/routeChangeHandler/index.tsx +7 -7
- package/src/components/telemetry/index.tsx +31 -31
- package/src/components/undoableQueue/index.tsx +49 -49
- package/src/contexts/accessControl/IAccessControlContext.ts +34 -34
- package/src/contexts/accessControl/index.tsx +35 -35
- package/src/contexts/auditLog/IAuditLogContext.ts +22 -22
- package/src/contexts/auditLog/index.tsx +8 -8
- package/src/contexts/auth/IAuthContext.ts +10 -10
- package/src/contexts/auth/index.tsx +169 -169
- package/src/contexts/data/IDataContext.ts +203 -203
- package/src/contexts/data/index.tsx +18 -18
- package/src/contexts/legacy-router/IRouterContext.ts +23 -27
- package/src/contexts/legacy-router/index.tsx +30 -30
- package/src/contexts/live/ILiveContext.ts +49 -49
- package/src/contexts/live/index.tsx +5 -7
- package/src/contexts/notification/INotificationContext.ts +8 -8
- package/src/contexts/notification/index.tsx +8 -8
- package/src/contexts/refine/IRefineContext.ts +119 -119
- package/src/contexts/refine/index.tsx +80 -80
- package/src/contexts/resource/IResourceContext.ts +35 -35
- package/src/contexts/resource/index.tsx +16 -16
- package/src/contexts/router/index.tsx +7 -7
- package/src/contexts/router-picker/index.tsx +2 -2
- package/src/contexts/translation/ITranslationContext.ts +7 -7
- package/src/contexts/translation/index.tsx +12 -12
- package/src/contexts/undoableQueue/IUndoableQueueContext.ts +2 -2
- package/src/contexts/undoableQueue/actionTypes.ts +3 -3
- package/src/contexts/undoableQueue/index.ts +2 -2
- package/src/contexts/undoableQueue/undoableQueueContext.tsx +59 -60
- package/src/contexts/unsavedWarn/IUnsavedWarnContext.ts +2 -2
- package/src/contexts/unsavedWarn/index.tsx +7 -7
- package/src/definitions/helpers/check-router-prop-misuse/index.ts +20 -20
- package/src/definitions/helpers/downloadInBrowser/index.ts +19 -20
- package/src/definitions/helpers/flatten-object-keys/index.ts +26 -29
- package/src/definitions/helpers/generateDocumentTitle/index.ts +39 -45
- package/src/definitions/helpers/handleMultiple/index.ts +4 -4
- package/src/definitions/helpers/handlePaginationParams/index.ts +17 -18
- package/src/definitions/helpers/handleRefineOptions/index.ts +88 -90
- package/src/definitions/helpers/handleUseParams/index.tsx +7 -7
- package/src/definitions/helpers/hasPermission/index.ts +6 -6
- package/src/definitions/helpers/humanizeString/index.ts +9 -9
- package/src/definitions/helpers/importCSVMapper/index.ts +8 -8
- package/src/definitions/helpers/index.ts +2 -2
- package/src/definitions/helpers/keys/index.ts +205 -258
- package/src/definitions/helpers/legacy-resource-transform/index.ts +14 -14
- package/src/definitions/helpers/menu/create-resource-key.ts +20 -23
- package/src/definitions/helpers/menu/create-tree.ts +61 -63
- package/src/definitions/helpers/pick-resource/index.ts +25 -25
- package/src/definitions/helpers/pickDataProvider/index.ts +15 -15
- package/src/definitions/helpers/pickNotDeprecated/index.ts +2 -2
- package/src/definitions/helpers/property-path-to-array/index.ts +3 -3
- package/src/definitions/helpers/queryKeys/index.ts +92 -92
- package/src/definitions/helpers/redirectPage/index.ts +19 -19
- package/src/definitions/helpers/routeGenerator/index.ts +15 -15
- package/src/definitions/helpers/router/__tests__/check-by-segments.ts +12 -15
- package/src/definitions/helpers/router/__tests__/compose-route.ts +48 -48
- package/src/definitions/helpers/router/__tests__/get-action-routes-from-resource.ts +152 -152
- package/src/definitions/helpers/router/__tests__/get-default-action-path.ts +39 -41
- package/src/definitions/helpers/router/__tests__/get-parent-prefix-for-resource.ts +69 -73
- package/src/definitions/helpers/router/__tests__/get-parent-resource.ts +40 -40
- package/src/definitions/helpers/router/__tests__/is-segment-counts-same.ts +11 -14
- package/src/definitions/helpers/router/__tests__/match-resource-from-route.ts +55 -55
- package/src/definitions/helpers/router/__tests__/pick-matched-route.ts +74 -74
- package/src/definitions/helpers/router/__tests__/pick-route-params.ts +12 -12
- package/src/definitions/helpers/router/__tests__/prepare-route-params.ts +18 -18
- package/src/definitions/helpers/router/__tests__/remove-leading-trailing-slashes.ts +9 -9
- package/src/definitions/helpers/router/__tests__/split-to-segments.ts +9 -9
- package/src/definitions/helpers/router/check-by-segments.ts +12 -12
- package/src/definitions/helpers/router/compose-route.ts +25 -27
- package/src/definitions/helpers/router/get-action-routes-from-resource.ts +41 -47
- package/src/definitions/helpers/router/get-default-action-path.ts +19 -19
- package/src/definitions/helpers/router/get-parent-prefix-for-resource.ts +22 -24
- package/src/definitions/helpers/router/get-parent-resource.ts +18 -18
- package/src/definitions/helpers/router/is-parameter.ts +1 -1
- package/src/definitions/helpers/router/is-segment-counts-same.ts +3 -3
- package/src/definitions/helpers/router/match-resource-from-route.ts +19 -19
- package/src/definitions/helpers/router/pick-matched-route.ts +44 -44
- package/src/definitions/helpers/router/pick-route-params.ts +7 -7
- package/src/definitions/helpers/router/prepare-route-params.ts +13 -10
- package/src/definitions/helpers/router/remove-leading-trailing-slashes.ts +1 -1
- package/src/definitions/helpers/router/split-to-segments.ts +2 -2
- package/src/definitions/helpers/safe-translate/index.ts +12 -12
- package/src/definitions/helpers/sanitize-resource/index.ts +26 -27
- package/src/definitions/helpers/sequentialPromises/index.ts +21 -21
- package/src/definitions/helpers/treeView/createTreeView/index.ts +33 -33
- package/src/definitions/helpers/useActiveAuthProvider/index.ts +18 -18
- package/src/definitions/helpers/useInfinitePagination/index.ts +16 -16
- package/src/definitions/helpers/useMediaQuery/index.ts +11 -11
- package/src/definitions/helpers/useUserFriendlyName/index.ts +11 -14
- package/src/definitions/helpers/userFriendlyResourceName/index.ts +7 -7
- package/src/definitions/helpers/userFriendlySeconds/index.ts +1 -1
- package/src/definitions/table/index.ts +127 -130
- package/src/definitions/upload/file2Base64/index.ts +15 -15
- package/src/hooks/accessControl/useCan/index.ts +52 -54
- package/src/hooks/accessControl/useCanWithoutCache.ts +25 -26
- package/src/hooks/auditLog/useLog/index.ts +114 -114
- package/src/hooks/auditLog/useLogList/index.ts +44 -44
- package/src/hooks/auth/useForgotPassword/index.ts +158 -163
- package/src/hooks/auth/useGetIdentity/index.ts +55 -57
- package/src/hooks/auth/useInvalidateAuthStore/index.ts +12 -12
- package/src/hooks/auth/useIsAuthenticated/index.ts +44 -48
- package/src/hooks/auth/useIsExistAuthentication/index.ts +3 -3
- package/src/hooks/auth/useLogin/index.ts +181 -194
- package/src/hooks/auth/useLogout/index.ts +175 -177
- package/src/hooks/auth/useOnError/index.ts +76 -76
- package/src/hooks/auth/usePermissions/index.ts +94 -61
- package/src/hooks/auth/useRegister/index.ts +166 -178
- package/src/hooks/auth/useUpdatePassword/index.ts +183 -194
- package/src/hooks/breadcrumb/index.ts +99 -106
- package/src/hooks/data/useApiUrl.ts +7 -8
- package/src/hooks/data/useCreate.ts +241 -241
- package/src/hooks/data/useCreateMany.ts +219 -226
- package/src/hooks/data/useCustom.ts +181 -182
- package/src/hooks/data/useCustomMutation.ts +174 -174
- package/src/hooks/data/useDataProvider.tsx +27 -29
- package/src/hooks/data/useDelete.ts +447 -454
- package/src/hooks/data/useDeleteMany.ts +475 -484
- package/src/hooks/data/useInfiniteList.ts +280 -280
- package/src/hooks/data/useList.ts +280 -283
- package/src/hooks/data/useMany.ts +215 -216
- package/src/hooks/data/useOne.ts +210 -211
- package/src/hooks/data/useUpdate.ts +529 -556
- package/src/hooks/data/useUpdateMany.ts +556 -584
- package/src/hooks/deepMemo/index.tsx +5 -5
- package/src/hooks/export/csvDownload.interface.ts +13 -13
- package/src/hooks/export/index.ts +223 -217
- package/src/hooks/form/useForm.ts +543 -560
- package/src/hooks/import/index.tsx +254 -260
- package/src/hooks/invalidate/index.tsx +75 -75
- package/src/hooks/legacy-router/useRouterContext.ts +11 -11
- package/src/hooks/live/useLiveMode/index.ts +4 -4
- package/src/hooks/live/usePublish/index.ts +2 -2
- package/src/hooks/live/useResourceSubscription/index.ts +103 -103
- package/src/hooks/live/useSubscription/index.ts +77 -77
- package/src/hooks/memoized/index.tsx +6 -6
- package/src/hooks/menu/useMenu.tsx +113 -120
- package/src/hooks/modal/useModal/index.tsx +16 -16
- package/src/hooks/navigation/index.ts +362 -392
- package/src/hooks/notification/useCancelNotification/index.tsx +5 -5
- package/src/hooks/notification/useHandleNotification/index.ts +17 -17
- package/src/hooks/notification/useNotification/index.ts +2 -2
- package/src/hooks/redirection/index.ts +45 -46
- package/src/hooks/refine/useMutationMode.ts +4 -4
- package/src/hooks/refine/useRefineContext.ts +36 -36
- package/src/hooks/refine/useSyncWithLocation.ts +3 -3
- package/src/hooks/refine/useTitle.tsx +2 -2
- package/src/hooks/refine/useWarnAboutChange/index.ts +12 -12
- package/src/hooks/resource/useResource/index.ts +141 -146
- package/src/hooks/resource/useResourceWithRoute/index.ts +12 -12
- package/src/hooks/router/use-back/index.tsx +7 -7
- package/src/hooks/router/use-get-to-path/index.ts +35 -35
- package/src/hooks/router/use-go/index.tsx +66 -66
- package/src/hooks/router/use-link/index.tsx +8 -9
- package/src/hooks/router/use-parse/index.tsx +13 -13
- package/src/hooks/router/use-parsed/index.tsx +4 -4
- package/src/hooks/router/use-router-misuse-warning/index.ts +10 -10
- package/src/hooks/router/use-to-path/index.ts +10 -10
- package/src/hooks/show/useShow.ts +135 -135
- package/src/hooks/translate/useGetLocale.ts +2 -2
- package/src/hooks/translate/useSetLocale.ts +2 -2
- package/src/hooks/translate/useTranslate.ts +24 -25
- package/src/hooks/useKeys/index.tsx +7 -7
- package/src/hooks/useLoadingOvertime/index.ts +74 -76
- package/src/hooks/useMeta/index.ts +20 -20
- package/src/hooks/useSelect/index.ts +317 -277
- package/src/hooks/useTable/index.ts +483 -507
- package/src/hooks/useTelemetryData/index.ts +48 -48
- package/src/index.tsx +125 -125
- package/src/interfaces/actions.ts +2 -2
- package/src/interfaces/auditLog/logData.ts +9 -9
- package/src/interfaces/auth.tsx +176 -176
- package/src/interfaces/autoSave.ts +37 -37
- package/src/interfaces/bindings/access-control.ts +21 -21
- package/src/interfaces/bindings/auth.ts +27 -25
- package/src/interfaces/bindings/data.ts +2 -2
- package/src/interfaces/bindings/i18n.ts +8 -8
- package/src/interfaces/bindings/index.ts +15 -15
- package/src/interfaces/bindings/live.ts +28 -28
- package/src/interfaces/bindings/notifications.ts +8 -8
- package/src/interfaces/bindings/resource.ts +127 -127
- package/src/interfaces/bindings/router.ts +26 -26
- package/src/interfaces/customComponents.ts +17 -17
- package/src/interfaces/errors/HttpError.ts +8 -8
- package/src/interfaces/form-url-params.ts +6 -6
- package/src/interfaces/index.ts +8 -10
- package/src/interfaces/live/LiveEvent.ts +10 -10
- package/src/interfaces/live/LiveModeProps.ts +21 -21
- package/src/interfaces/mapDataFn.ts +1 -1
- package/src/interfaces/metaData/graphqlQueryOptions.ts +49 -49
- package/src/interfaces/metaData/metaDataQuery.ts +2 -2
- package/src/interfaces/metaData/metaQuery.ts +3 -3
- package/src/interfaces/metaData/nestedField.ts +3 -3
- package/src/interfaces/metaData/queryBuilderOptions.ts +3 -3
- package/src/interfaces/metaData/variableOptions.ts +8 -8
- package/src/interfaces/mutationMode.ts +14 -14
- package/src/interfaces/notification.ts +7 -7
- package/src/interfaces/optimistic-update-map.ts +42 -42
- package/src/interfaces/prettify.ts +1 -1
- package/src/interfaces/queryKey.ts +16 -16
- package/src/interfaces/resourceErrorRouterParams.ts +2 -2
- package/src/interfaces/resourceRouterParams.ts +3 -3
- package/src/interfaces/successErrorNotification.ts +24 -24
- package/src/interfaces/telemetry.ts +13 -13
- package/src/interfaces/textTransformers.ts +18 -18
- package/tsconfig.json +26 -26
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { removeLeadingTrailingSlashes } from "../remove-leading-trailing-slashes";
|
|
2
2
|
|
|
3
3
|
describe("removeLeadingTrailingSlashes", () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
it("should remove leading and trailing slashes", () => {
|
|
5
|
+
expect(removeLeadingTrailingSlashes("/a/b/c")).toEqual("a/b/c");
|
|
6
|
+
});
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
it("should remove leading and trailing slashes", () => {
|
|
9
|
+
expect(removeLeadingTrailingSlashes("a/b/c")).toEqual("a/b/c");
|
|
10
|
+
});
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
it("should remove leading and trailing slashes", () => {
|
|
13
|
+
expect(removeLeadingTrailingSlashes("/a/b/c/")).toEqual("a/b/c");
|
|
14
|
+
});
|
|
15
15
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { splitToSegments } from "../split-to-segments";
|
|
2
2
|
|
|
3
3
|
describe("splitToSegments", () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
it("should split a path to segments", () => {
|
|
5
|
+
expect(splitToSegments("/a/b/c")).toEqual(["a", "b", "c"]);
|
|
6
|
+
});
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
it("should split a path to segments", () => {
|
|
9
|
+
expect(splitToSegments("a/b/c")).toEqual(["a", "b", "c"]);
|
|
10
|
+
});
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
it("should split a path to segments", () => {
|
|
13
|
+
expect(splitToSegments("/a/b/c/")).toEqual(["a", "b", "c"]);
|
|
14
|
+
});
|
|
15
15
|
});
|
|
@@ -11,18 +11,18 @@ import { splitToSegments } from "./split-to-segments";
|
|
|
11
11
|
* - If all segments match, the function returns true, otherwise false
|
|
12
12
|
*/
|
|
13
13
|
export const checkBySegments = (route: string, resourceRoute: string) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const stdRoute = removeLeadingTrailingSlashes(route);
|
|
15
|
+
const stdResourceRoute = removeLeadingTrailingSlashes(resourceRoute);
|
|
16
|
+
// we need to check if the route and resourceRoute have the same number of segments
|
|
17
|
+
// if not, we can't match them
|
|
18
|
+
if (!isSegmentCountsSame(stdRoute, stdResourceRoute)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const routeSegments = splitToSegments(stdRoute);
|
|
23
|
+
const resourceRouteSegments = splitToSegments(stdResourceRoute);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
return resourceRouteSegments.every((segment, index) => {
|
|
26
|
+
return isParameter(segment) || segment === routeSegments[index];
|
|
27
|
+
});
|
|
28
28
|
};
|
|
@@ -10,32 +10,30 @@ import { prepareRouteParams } from "./prepare-route-params";
|
|
|
10
10
|
* - Then we replace the route params with the prepared route params (eg: /users/1)
|
|
11
11
|
*/
|
|
12
12
|
export const composeRoute = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
designatedRoute: string,
|
|
14
|
+
resourceMeta: MetaQuery = {},
|
|
15
|
+
parsed: ParseResponse = {},
|
|
16
|
+
meta: Record<string, unknown> = {},
|
|
17
17
|
): string => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return match;
|
|
40
|
-
});
|
|
18
|
+
// pickRouteParams (from the route)
|
|
19
|
+
const routeParams = pickRouteParams(designatedRoute);
|
|
20
|
+
// prepareRouteParams (from route params, params and meta)
|
|
21
|
+
const preparedRouteParams = prepareRouteParams(routeParams, {
|
|
22
|
+
...resourceMeta,
|
|
23
|
+
...(typeof parsed?.id !== "undefined" ? { id: parsed.id } : {}),
|
|
24
|
+
...(typeof parsed?.action !== "undefined" ? { action: parsed.action } : {}),
|
|
25
|
+
...(typeof parsed?.resource !== "undefined"
|
|
26
|
+
? { resource: parsed.resource }
|
|
27
|
+
: {}),
|
|
28
|
+
...parsed?.params,
|
|
29
|
+
...meta,
|
|
30
|
+
});
|
|
31
|
+
// replace route params with prepared route params
|
|
32
|
+
return designatedRoute.replace(/:([^\/]+)/g, (match, key) => {
|
|
33
|
+
const fromParams = preparedRouteParams[key];
|
|
34
|
+
if (typeof fromParams !== "undefined") {
|
|
35
|
+
return `${fromParams}`;
|
|
36
|
+
}
|
|
37
|
+
return match;
|
|
38
|
+
});
|
|
41
39
|
};
|
|
@@ -3,9 +3,9 @@ import { getDefaultActionPath } from "./get-default-action-path";
|
|
|
3
3
|
import { getParentPrefixForResource } from "./get-parent-prefix-for-resource";
|
|
4
4
|
|
|
5
5
|
export type ResourceActionRoute = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
action: Action;
|
|
7
|
+
resource: IResourceItem;
|
|
8
|
+
route: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -16,56 +16,50 @@ export type ResourceActionRoute = {
|
|
|
16
16
|
* - It will return an array of objects with the action, the resource and the route
|
|
17
17
|
*/
|
|
18
18
|
export const getActionRoutesFromResource = (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
resource: IResourceItem,
|
|
20
|
+
resources: IResourceItem[],
|
|
21
|
+
/**
|
|
22
|
+
* Uses legacy route if true (`options.route`)
|
|
23
|
+
*/
|
|
24
|
+
legacy?: boolean,
|
|
25
25
|
) => {
|
|
26
|
-
|
|
26
|
+
const actions: ResourceActionRoute[] = [];
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const actionList: Action[] = ["list", "show", "edit", "create", "clone"];
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
resource,
|
|
32
|
-
resources,
|
|
33
|
-
legacy,
|
|
34
|
-
);
|
|
30
|
+
const parentPrefix = getParentPrefixForResource(resource, resources, legacy);
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
actionList.forEach((action) => {
|
|
33
|
+
const item =
|
|
34
|
+
legacy && action === "clone" ? resource.create : resource[action];
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
let route: string | undefined = undefined;
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
route = item.path;
|
|
59
|
-
}
|
|
38
|
+
if (typeof item === "function" || legacy) {
|
|
39
|
+
// means we're fallbacking to default path for the action
|
|
40
|
+
route = getDefaultActionPath(
|
|
41
|
+
legacy
|
|
42
|
+
? resource.meta?.route ?? resource.options?.route ?? resource.name
|
|
43
|
+
: resource.name,
|
|
44
|
+
action,
|
|
45
|
+
legacy ? parentPrefix : undefined,
|
|
46
|
+
);
|
|
47
|
+
} else if (typeof item === "string") {
|
|
48
|
+
// means we don't have the component, but we have the route
|
|
49
|
+
route = item;
|
|
50
|
+
} else if (typeof item === "object") {
|
|
51
|
+
// means we have the component and the route
|
|
52
|
+
route = item.path;
|
|
53
|
+
}
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
if (route) {
|
|
56
|
+
actions.push({
|
|
57
|
+
action,
|
|
58
|
+
resource,
|
|
59
|
+
route: `/${route.replace(/^\//, "")}`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
return actions;
|
|
71
65
|
};
|
|
@@ -7,27 +7,27 @@ import { removeLeadingTrailingSlashes } from "./remove-leading-trailing-slashes"
|
|
|
7
7
|
* This is used by the legacy router and the new router if the resource doesn't provide a custom path.
|
|
8
8
|
*/
|
|
9
9
|
export const getDefaultActionPath = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
resourceName: string,
|
|
11
|
+
action: Action,
|
|
12
|
+
parentPrefix?: string,
|
|
13
13
|
): string => {
|
|
14
|
-
|
|
14
|
+
const cleanParentPrefix = removeLeadingTrailingSlashes(parentPrefix || "");
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let path = `${cleanParentPrefix}${
|
|
17
|
+
cleanParentPrefix ? "/" : ""
|
|
18
|
+
}${resourceName}`;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
if (action === "list") {
|
|
21
|
+
path = `${path}`;
|
|
22
|
+
} else if (action === "create") {
|
|
23
|
+
path = `${path}/create`;
|
|
24
|
+
} else if (action === "edit") {
|
|
25
|
+
path = `${path}/edit/:id`;
|
|
26
|
+
} else if (action === "show") {
|
|
27
|
+
path = `${path}/show/:id`;
|
|
28
|
+
} else if (action === "clone") {
|
|
29
|
+
path = `${path}/clone/:id`;
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
return `/${path.replace(/^\//, "")}`;
|
|
33
33
|
};
|
|
@@ -7,33 +7,31 @@ import { removeLeadingTrailingSlashes } from "./remove-leading-trailing-slashes"
|
|
|
7
7
|
* - If `legacy` is provided, the computation is based on the `route` option of the resource
|
|
8
8
|
*/
|
|
9
9
|
export const getParentPrefixForResource = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
resource: ResourceProps,
|
|
11
|
+
resources: ResourceProps[],
|
|
12
|
+
/**
|
|
13
|
+
* Uses legacy route if true (`options.route`)
|
|
14
|
+
*/
|
|
15
|
+
legacy?: boolean,
|
|
16
16
|
): string | undefined => {
|
|
17
|
-
|
|
17
|
+
const parents: ResourceProps[] = [];
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
let parent = getParentResource(resource, resources);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
while (parent) {
|
|
22
|
+
parents.push(parent);
|
|
23
|
+
parent = getParentResource(parent, resources);
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (parents.length === 0) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
.join("/")}`;
|
|
30
|
+
return `/${parents
|
|
31
|
+
.reverse()
|
|
32
|
+
.map((parent) => {
|
|
33
|
+
const v = legacy ? parent.options?.route ?? parent.name : parent.name;
|
|
34
|
+
return removeLeadingTrailingSlashes(v);
|
|
35
|
+
})
|
|
36
|
+
.join("/")}`;
|
|
39
37
|
};
|
|
@@ -6,26 +6,26 @@ import { pickNotDeprecated } from "../pickNotDeprecated";
|
|
|
6
6
|
* Works both with the deprecated `parentName` and the new `parent` property.
|
|
7
7
|
*/
|
|
8
8
|
export const getParentResource = (
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
resource: IResourceItem,
|
|
10
|
+
resources: IResourceItem[],
|
|
11
11
|
): IResourceItem | undefined => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const parentName = pickNotDeprecated(
|
|
13
|
+
resource.meta?.parent,
|
|
14
|
+
resource.options?.parent,
|
|
15
|
+
resource.parentName,
|
|
16
|
+
);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (!parentName) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const parentResource = resources.find(
|
|
23
|
+
(resource) => (resource.identifier ?? resource.name) === parentName,
|
|
24
|
+
);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/**
|
|
27
|
+
* If the parent resource is not found, we return a resource object with the name of the parent resource.
|
|
28
|
+
* Because we still want to have nesting and prefixing for the resource even if the parent is not explicitly defined.
|
|
29
|
+
*/
|
|
30
|
+
return parentResource ?? { name: parentName };
|
|
31
31
|
};
|
|
@@ -4,8 +4,8 @@ import { splitToSegments } from "./split-to-segments";
|
|
|
4
4
|
* Checks if the both routes have the same number of segments.
|
|
5
5
|
*/
|
|
6
6
|
export const isSegmentCountsSame = (route: string, resourceRoute: string) => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const routeSegments = splitToSegments(route);
|
|
8
|
+
const resourceRouteSegments = splitToSegments(resourceRoute);
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
return routeSegments.length === resourceRouteSegments.length;
|
|
11
11
|
};
|
|
@@ -10,28 +10,28 @@ import { pickMatchedRoute } from "./pick-matched-route";
|
|
|
10
10
|
* - It will return the most eligible resource and action
|
|
11
11
|
*/
|
|
12
12
|
export const matchResourceFromRoute = (
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
route: string,
|
|
14
|
+
resources: IResourceItem[],
|
|
15
15
|
): {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
found: boolean;
|
|
17
|
+
resource?: IResourceItem;
|
|
18
|
+
action?: Action;
|
|
19
|
+
matchedRoute?: string;
|
|
20
20
|
} => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const allActionRoutes = resources.flatMap((resource) => {
|
|
22
|
+
return getActionRoutesFromResource(resource, resources);
|
|
23
|
+
});
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const allFound = allActionRoutes.filter((actionRoute) => {
|
|
26
|
+
return checkBySegments(route, actionRoute.route);
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
const mostEligible = pickMatchedRoute(allFound);
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
return {
|
|
32
|
+
found: !!mostEligible,
|
|
33
|
+
resource: mostEligible?.resource,
|
|
34
|
+
action: mostEligible?.action,
|
|
35
|
+
matchedRoute: mostEligible?.route,
|
|
36
|
+
};
|
|
37
37
|
};
|
|
@@ -9,53 +9,53 @@ import { splitToSegments } from "./split-to-segments";
|
|
|
9
9
|
* - If there's more than one route, it picks the best non-greedy match.
|
|
10
10
|
*/
|
|
11
11
|
export const pickMatchedRoute = (
|
|
12
|
-
|
|
12
|
+
routes: ResourceActionRoute[],
|
|
13
13
|
): ResourceActionRoute | undefined => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// these routes are all matched, we should pick the least parametrized one
|
|
15
|
+
|
|
16
|
+
// no routes, no match
|
|
17
|
+
if (routes.length === 0) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// no need to calculate the route segments if there's only one route
|
|
22
|
+
if (routes.length === 1) {
|
|
23
|
+
return routes[0];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// remove trailing and leading slashes
|
|
27
|
+
// split them to segments
|
|
28
|
+
const sanitizedRoutes = routes.map((route) => ({
|
|
29
|
+
...route,
|
|
30
|
+
splitted: splitToSegments(removeLeadingTrailingSlashes(route.route)),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
// at this point, before calling this function, we already checked for segment lenghts and expect all of them to be the same
|
|
34
|
+
const segmentsCount = sanitizedRoutes[0]?.splitted.length ?? 0;
|
|
35
|
+
|
|
36
|
+
let eligibleRoutes: Array<(typeof sanitizedRoutes)[number]> = [
|
|
37
|
+
...sanitizedRoutes,
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// loop through the segments
|
|
41
|
+
for (let i = 0; i < segmentsCount; i++) {
|
|
42
|
+
const nonParametrizedRoutes = eligibleRoutes.filter(
|
|
43
|
+
(route) => !isParameter(route.splitted[i]),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (nonParametrizedRoutes.length === 0) {
|
|
47
|
+
// keep the eligible routes as they are
|
|
48
|
+
continue;
|
|
19
49
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
50
|
+
if (nonParametrizedRoutes.length === 1) {
|
|
51
|
+
// no need to continue, we found the route
|
|
52
|
+
eligibleRoutes = nonParametrizedRoutes;
|
|
53
|
+
break;
|
|
24
54
|
}
|
|
25
55
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
...route,
|
|
30
|
-
splitted: splitToSegments(removeLeadingTrailingSlashes(route.route)),
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
// at this point, before calling this function, we already checked for segment lenghts and expect all of them to be the same
|
|
34
|
-
const segmentsCount = sanitizedRoutes[0]?.splitted.length ?? 0;
|
|
35
|
-
|
|
36
|
-
let eligibleRoutes: Array<(typeof sanitizedRoutes)[number]> = [
|
|
37
|
-
...sanitizedRoutes,
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
// loop through the segments
|
|
41
|
-
for (let i = 0; i < segmentsCount; i++) {
|
|
42
|
-
const nonParametrizedRoutes = eligibleRoutes.filter(
|
|
43
|
-
(route) => !isParameter(route.splitted[i]),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (nonParametrizedRoutes.length === 0) {
|
|
47
|
-
// keep the eligible routes as they are
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (nonParametrizedRoutes.length === 1) {
|
|
51
|
-
// no need to continue, we found the route
|
|
52
|
-
eligibleRoutes = nonParametrizedRoutes;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// we have more than one non-parametrized route, we need to check the next segment
|
|
57
|
-
eligibleRoutes = nonParametrizedRoutes;
|
|
58
|
-
}
|
|
56
|
+
// we have more than one non-parametrized route, we need to check the next segment
|
|
57
|
+
eligibleRoutes = nonParametrizedRoutes;
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
return eligibleRoutes[0];
|
|
61
61
|
};
|
|
@@ -7,13 +7,13 @@ import { isParameter } from "./is-parameter";
|
|
|
7
7
|
* (e.g. /users/:id/posts/:postId => ['id', 'postId'])
|
|
8
8
|
*/
|
|
9
9
|
export const pickRouteParams = (route: string) => {
|
|
10
|
-
|
|
10
|
+
const segments = splitToSegments(removeLeadingTrailingSlashes(route));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return segments.flatMap((s) => {
|
|
13
|
+
if (isParameter(s)) {
|
|
14
|
+
return [s.slice(1)];
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return [];
|
|
18
|
+
});
|
|
19
19
|
};
|
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
* This means, we can use `meta` for user supplied params (both manually or from the query string)
|
|
6
6
|
*/
|
|
7
7
|
export const prepareRouteParams = <
|
|
8
|
-
|
|
8
|
+
TRouteParams extends Record<string, unknown> = Record<string, unknown>,
|
|
9
9
|
>(
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
routeParams: (keyof TRouteParams)[],
|
|
11
|
+
meta: Record<string, unknown> = {},
|
|
12
12
|
): Partial<TRouteParams> => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
return routeParams.reduce(
|
|
14
|
+
(acc, key) => {
|
|
15
|
+
const value = meta[key as string];
|
|
16
|
+
if (typeof value !== "undefined") {
|
|
17
|
+
acc[key] = value as TRouteParams[keyof TRouteParams];
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
},
|
|
21
|
+
{} as Partial<TRouteParams>,
|
|
22
|
+
);
|
|
20
23
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Split a path to segments.
|
|
3
3
|
*/
|
|
4
4
|
export const splitToSegments = (path: string) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const segments = path.split("/").filter((segment) => segment !== "");
|
|
6
|
+
return segments;
|
|
7
7
|
};
|