@boomerang-io/carbon-addons-boomerang-react 4.6.11-beta.27 → 4.6.11-beta.29
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/README.md +162 -162
- package/dist/cjs/components/AboutPlatform/AboutPlatform.js +50 -50
- package/dist/cjs/components/AdvantageSideNav/AdvantageSideNav.js +222 -211
- package/dist/cjs/components/AutoSuggest/AutoSuggest.js +101 -101
- package/dist/cjs/components/Avatar/Avatar.js +18 -18
- package/dist/cjs/components/CheckboxList/CheckboxList.js +34 -34
- package/dist/cjs/components/ComboBox/ComboBox.js +103 -103
- package/dist/cjs/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
- package/dist/cjs/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
- package/dist/cjs/components/ComposedModal/ComposedModal.js +80 -80
- package/dist/cjs/components/ConfirmModal/ConfirmModal.js +43 -43
- package/dist/cjs/components/Creatable/Creatable.js +137 -137
- package/dist/cjs/components/DataDrivenInput/DataDrivenInput.js +226 -226
- package/dist/cjs/components/DateInput/DateInput.js +35 -35
- package/dist/cjs/components/DecisionButtons/DecisionButtons.js +61 -61
- package/dist/cjs/components/DelayedRender/DelayedRender.js +17 -17
- package/dist/cjs/components/DynamicFormik/DynamicFormik.js +578 -578
- package/dist/cjs/components/Error403/Error403.js +13 -13
- package/dist/cjs/components/Error403/ForbiddenErrorBackground.js +113 -113
- package/dist/cjs/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
- package/dist/cjs/components/Error404/Error404.js +13 -13
- package/dist/cjs/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
- package/dist/cjs/components/Error404/NotFoundErrorBackground.js +129 -129
- package/dist/cjs/components/ErrorBoundary/ErrorBoundary.js +32 -32
- package/dist/cjs/components/ErrorDragon/ErrorDragon.js +13 -13
- package/dist/cjs/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
- package/dist/cjs/components/ErrorFullPage/ErrorFullPage.js +10 -10
- package/dist/cjs/components/ErrorMessage/ErrorMessage.js +22 -22
- package/dist/cjs/components/ErrorPage/ErrorPage.js +11 -11
- package/dist/cjs/components/ErrorPageCore/ErrorPageCore.js +15 -15
- package/dist/cjs/components/ErrorPageCore/GenericErrorBackground.js +124 -124
- package/dist/cjs/components/FeatureHeader/FeatureHeader.js +29 -29
- package/dist/cjs/components/FeatureNavTab/FeatureNavTab.js +12 -12
- package/dist/cjs/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
- package/dist/cjs/components/FeatureSideNav/FeatureSideNav.js +12 -12
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
- package/dist/cjs/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
- package/dist/cjs/components/Feedback/Feedback.js +40 -40
- package/dist/cjs/components/FlowModal/FlowModal.js +141 -141
- package/dist/cjs/components/FlowModal/FlowModalForm.js +12 -12
- package/dist/cjs/components/Header/Header.js +179 -179
- package/dist/cjs/components/Header/HeaderAppSwitcher.js +94 -94
- package/dist/cjs/components/Header/HeaderMenu.js +7 -7
- package/dist/cjs/components/Header/HeaderMenuItem.js +52 -52
- package/dist/cjs/components/Header/HeaderTeamSwitcher.js +304 -304
- package/dist/cjs/components/Header/UserRequests.js +29 -29
- package/dist/cjs/components/ImageModal/ImageModal.js +17 -17
- package/dist/cjs/components/Loading/Loading.js +8 -8
- package/dist/cjs/components/MemberBar/MemberBar.js +20 -20
- package/dist/cjs/components/Modal/Modal.js +20 -20
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
- package/dist/cjs/components/ModalForm/ModalForm.js +9 -9
- package/dist/cjs/components/Notifications/NotificationsContainer.js +22 -22
- package/dist/cjs/components/Notifications/ToastNotification.js +21 -21
- package/dist/cjs/components/Notifications/notify.js +17 -17
- package/dist/cjs/components/PlatformBanner/PlatformBanner.js +8 -8
- package/dist/cjs/components/PlatformNotifications/PlatformNotification.js +17 -17
- package/dist/cjs/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
- package/dist/cjs/components/Portal/Portal.js +14 -14
- package/dist/cjs/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
- package/dist/cjs/components/PrivacyStatement/PrivacyStatement.js +90 -90
- package/dist/cjs/components/ProfileSettings/ProfileSettings.js +124 -124
- package/dist/cjs/components/ProtectedRoute/ProtectedRoute.js +13 -13
- package/dist/cjs/components/RadioGroup/RadioGroup.js +33 -33
- package/dist/cjs/components/RichTextArea/RichTextArea.js +142 -142
- package/dist/cjs/components/SignOut/SignOut.js +27 -27
- package/dist/cjs/components/SupportCenter/SupportCenter.js +65 -65
- package/dist/cjs/components/TextArea/TextArea.js +16 -16
- package/dist/cjs/components/TextInput/TextInput.js +13 -13
- package/dist/cjs/components/Toggle/Toggle.js +22 -22
- package/dist/cjs/components/TooltipHover/TooltipHover.js +39 -39
- package/dist/cjs/components/UIShell/UIShell.js +94 -94
- package/dist/cjs/config/servicesConfig.js +21 -21
- package/dist/cjs/constants/DataDrivenInputTypes.js +74 -74
- package/dist/cjs/constants/UserType.js +13 -13
- package/dist/cjs/hooks/useHeaderMenu.js +49 -49
- package/dist/cjs/hooks/usePortal.js +74 -74
- package/dist/cjs/hooks/useWindowSize.js +33 -33
- package/dist/cjs/internal/ListBox/ListBox.js +41 -41
- package/dist/cjs/internal/ListBox/ListBoxField.js +19 -19
- package/dist/cjs/internal/ListBox/ListBoxMenu.js +19 -19
- package/dist/cjs/internal/ListBox/ListBoxMenuIcon.js +31 -31
- package/dist/cjs/internal/ListBox/ListBoxMenuItem.js +38 -38
- package/dist/cjs/internal/ListBox/ListBoxSelection.js +64 -64
- package/dist/cjs/internal/ListBox/index.js +10 -10
- package/dist/cjs/internal/keyboard/keys.js +16 -16
- package/dist/cjs/internal/keyboard/match.js +67 -67
- package/dist/cjs/internal/settings.js +5 -5
- package/dist/cjs/tools/accessibility.js +13 -13
- package/dist/cjs/tools/createPropAdapter.js +44 -44
- package/dist/cjs/tools/isUrl.js +39 -39
- package/dist/cjs/tools/setupGetInstanceId.js +20 -20
- package/dist/cjs/tools/useSetState.js +12 -12
- package/dist/cjs/tools/yupAst/astGenerator.js +212 -212
- package/dist/cjs/tools/yupAst/customValidators.js +17 -17
- package/dist/esm/components/AboutPlatform/AboutPlatform.js +50 -50
- package/dist/esm/components/AdvantageSideNav/AdvantageSideNav.js +222 -211
- package/dist/esm/components/AutoSuggest/AutoSuggest.js +101 -101
- package/dist/esm/components/Avatar/Avatar.js +18 -18
- package/dist/esm/components/CheckboxList/CheckboxList.js +34 -34
- package/dist/esm/components/ComboBox/ComboBox.js +103 -103
- package/dist/esm/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
- package/dist/esm/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
- package/dist/esm/components/ComposedModal/ComposedModal.js +80 -80
- package/dist/esm/components/ConfirmModal/ConfirmModal.js +43 -43
- package/dist/esm/components/Creatable/Creatable.js +137 -137
- package/dist/esm/components/DataDrivenInput/DataDrivenInput.js +226 -226
- package/dist/esm/components/DateInput/DateInput.js +35 -35
- package/dist/esm/components/DecisionButtons/DecisionButtons.js +61 -61
- package/dist/esm/components/DelayedRender/DelayedRender.js +17 -17
- package/dist/esm/components/DynamicFormik/DynamicFormik.js +578 -578
- package/dist/esm/components/Error403/Error403.js +13 -13
- package/dist/esm/components/Error403/ForbiddenErrorBackground.js +113 -113
- package/dist/esm/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
- package/dist/esm/components/Error404/Error404.js +13 -13
- package/dist/esm/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
- package/dist/esm/components/Error404/NotFoundErrorBackground.js +129 -129
- package/dist/esm/components/ErrorBoundary/ErrorBoundary.js +32 -32
- package/dist/esm/components/ErrorDragon/ErrorDragon.js +13 -13
- package/dist/esm/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
- package/dist/esm/components/ErrorFullPage/ErrorFullPage.js +10 -10
- package/dist/esm/components/ErrorMessage/ErrorMessage.js +22 -22
- package/dist/esm/components/ErrorPage/ErrorPage.js +11 -11
- package/dist/esm/components/ErrorPageCore/ErrorPageCore.js +15 -15
- package/dist/esm/components/ErrorPageCore/GenericErrorBackground.js +124 -124
- package/dist/esm/components/FeatureHeader/FeatureHeader.js +29 -29
- package/dist/esm/components/FeatureNavTab/FeatureNavTab.js +12 -12
- package/dist/esm/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
- package/dist/esm/components/FeatureSideNav/FeatureSideNav.js +12 -12
- package/dist/esm/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
- package/dist/esm/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
- package/dist/esm/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
- package/dist/esm/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
- package/dist/esm/components/Feedback/Feedback.js +40 -40
- package/dist/esm/components/FlowModal/FlowModal.js +141 -141
- package/dist/esm/components/FlowModal/FlowModalForm.js +12 -12
- package/dist/esm/components/Header/Header.js +179 -179
- package/dist/esm/components/Header/HeaderAppSwitcher.js +94 -94
- package/dist/esm/components/Header/HeaderMenu.js +7 -7
- package/dist/esm/components/Header/HeaderMenuItem.js +52 -52
- package/dist/esm/components/Header/HeaderTeamSwitcher.js +304 -304
- package/dist/esm/components/Header/UserRequests.js +29 -29
- package/dist/esm/components/ImageModal/ImageModal.js +17 -17
- package/dist/esm/components/Loading/Loading.js +8 -8
- package/dist/esm/components/MemberBar/MemberBar.js +20 -20
- package/dist/esm/components/Modal/Modal.js +20 -20
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
- package/dist/esm/components/ModalForm/ModalForm.js +9 -9
- package/dist/esm/components/Notifications/NotificationsContainer.js +22 -22
- package/dist/esm/components/Notifications/ToastNotification.js +21 -21
- package/dist/esm/components/Notifications/notify.js +17 -17
- package/dist/esm/components/PlatformBanner/PlatformBanner.js +8 -8
- package/dist/esm/components/PlatformNotifications/PlatformNotification.js +17 -17
- package/dist/esm/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
- package/dist/esm/components/Portal/Portal.js +14 -14
- package/dist/esm/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
- package/dist/esm/components/PrivacyStatement/PrivacyStatement.js +90 -90
- package/dist/esm/components/ProfileSettings/ProfileSettings.js +124 -124
- package/dist/esm/components/ProtectedRoute/ProtectedRoute.js +13 -13
- package/dist/esm/components/RadioGroup/RadioGroup.js +33 -33
- package/dist/esm/components/RichTextArea/RichTextArea.js +142 -142
- package/dist/esm/components/SignOut/SignOut.js +27 -27
- package/dist/esm/components/SupportCenter/SupportCenter.js +65 -65
- package/dist/esm/components/TextArea/TextArea.js +16 -16
- package/dist/esm/components/TextInput/TextInput.js +13 -13
- package/dist/esm/components/Toggle/Toggle.js +22 -22
- package/dist/esm/components/TooltipHover/TooltipHover.js +39 -39
- package/dist/esm/components/UIShell/UIShell.js +94 -94
- package/dist/esm/config/servicesConfig.js +21 -21
- package/dist/esm/constants/DataDrivenInputTypes.js +74 -74
- package/dist/esm/constants/UserType.js +13 -13
- package/dist/esm/hooks/useHeaderMenu.js +49 -49
- package/dist/esm/hooks/usePortal.js +74 -74
- package/dist/esm/hooks/useWindowSize.js +33 -33
- package/dist/esm/internal/ListBox/ListBox.js +41 -41
- package/dist/esm/internal/ListBox/ListBoxField.js +19 -19
- package/dist/esm/internal/ListBox/ListBoxMenu.js +19 -19
- package/dist/esm/internal/ListBox/ListBoxMenuIcon.js +31 -31
- package/dist/esm/internal/ListBox/ListBoxMenuItem.js +38 -38
- package/dist/esm/internal/ListBox/ListBoxSelection.js +64 -64
- package/dist/esm/internal/ListBox/index.js +10 -10
- package/dist/esm/internal/keyboard/keys.js +16 -16
- package/dist/esm/internal/keyboard/match.js +67 -67
- package/dist/esm/internal/settings.js +5 -5
- package/dist/esm/tools/accessibility.js +13 -13
- package/dist/esm/tools/createPropAdapter.js +44 -44
- package/dist/esm/tools/isUrl.js +39 -39
- package/dist/esm/tools/setupGetInstanceId.js +20 -20
- package/dist/esm/tools/useSetState.js +12 -12
- package/dist/esm/tools/yupAst/astGenerator.js +212 -212
- package/dist/esm/tools/yupAst/customValidators.js +17 -17
- package/dist/types/index.d.ts +1335 -1420
- package/package.json +167 -167
- package/scss/components/AboutPlatform/_aboutPlatform.scss +139 -139
- package/scss/components/AdvantageSideNav/_advantageSideNav.scss +261 -261
- package/scss/components/AutoSuggest/_autoSuggest.scss +62 -62
- package/scss/components/Avatar/_avatar.scss +32 -32
- package/scss/components/CheckboxList/_checkboxList.scss +26 -26
- package/scss/components/ComboBox/_combobox.scss +23 -23
- package/scss/components/ComboBoxMultiSelect/_comboBoxMultiSelect.scss +53 -53
- package/scss/components/ConfirmModal/_confirmModal.scss +12 -12
- package/scss/components/Creatable/_creatable.scss +48 -48
- package/scss/components/DateInput/_dateInput.scss +36 -36
- package/scss/components/DecisionButtons/_decisionButtons.scss +132 -132
- package/scss/components/DynamicFormik/_dynamicFormik.scss +17 -17
- package/scss/components/ErrorBoundary/_errorBoundary.scss +12 -12
- package/scss/components/ErrorDragon/_errorDragon.scss +55 -55
- package/scss/components/ErrorMessage/_errorMessage.scss +43 -43
- package/scss/components/ErrorPage/_errorPage.scss +66 -66
- package/scss/components/ErrorPageCore/_errorPageCore.scss +73 -73
- package/scss/components/FeatureHeader/_featureHeader.scss +67 -67
- package/scss/components/FeatureNavTab/_featureNavTab.scss +27 -27
- package/scss/components/FeatureSideNav/_featureSideNav.scss +76 -76
- package/scss/components/FeatureSideNavLink/_featureSideNavLink.scss +49 -49
- package/scss/components/Feedback/_feedback.scss +46 -46
- package/scss/components/Header/_header.scss +179 -179
- package/scss/components/Header/_headerAppSwitcher.scss +117 -117
- package/scss/components/Header/_headerMenu.scss +30 -30
- package/scss/components/Header/_headerMenuItem.scss +65 -65
- package/scss/components/Header/_headerTeamSwitcher.scss +195 -195
- package/scss/components/Header/_userRequests.scss +36 -36
- package/scss/components/ImageModal/_imageModal.scss +51 -51
- package/scss/components/MemberBar/_memberBar.scss +99 -99
- package/scss/components/Modal/_modal.scss +163 -163
- package/scss/components/ModalConfirmEdit/_modalConfirmEdit.scss +113 -113
- package/scss/components/Notifications/_notifications.scss +57 -57
- package/scss/components/PlatformBanner/_platformBanner.scss +30 -30
- package/scss/components/PlatformNotifications/_platformNotifications.scss +230 -230
- package/scss/components/PrivacyRedirect/_privacyRedirect.scss +43 -43
- package/scss/components/PrivacyStatement/_privacyStatement.scss +137 -137
- package/scss/components/ProfileSettings/_profileSettings.scss +117 -117
- package/scss/components/ProtectedRoute/_protectedRoute.scss +32 -32
- package/scss/components/RadioGroup/_radioGroup.scss +46 -46
- package/scss/components/RichTextArea/_richTextArea.scss +82 -82
- package/scss/components/SignOut/_signOut.scss +51 -51
- package/scss/components/SupportCenter/_supportCenter.scss +16 -16
- package/scss/components/TextArea/_textArea.scss +19 -19
- package/scss/components/TextInput/_textInput.scss +26 -26
- package/scss/components/Toggle/_toggle.scss +80 -80
- package/scss/components/TooltipHover/_tooltip.scss +48 -48
- package/scss/global/_config.scss +14 -14
- package/scss/global/_tippy.scss +49 -49
- package/scss/global/index.scss +401 -401
- package/scss/global/themes/_boomerang.scss +184 -184
- package/scss/global/themes/_default.scss +79 -79
- package/scss/global/themes/_shell-tokens.scss +42 -42
- package/scss/global/utils/_animations.scss +15 -15
- package/scss/global/utils/_mixins.scss +67 -67
- package/scss/global/utils/index.scss +10 -10
|
@@ -1,218 +1,218 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
2
|
import { getCustomValidator } from './customValidators.js';
|
|
3
3
|
|
|
4
|
-
/*
|
|
5
|
-
IBM Confidential
|
|
6
|
-
694970X, 69497O0
|
|
7
|
-
© Copyright IBM Corp. 2022, 2024
|
|
8
|
-
*/
|
|
9
|
-
// @ts-nocheck
|
|
10
|
-
class ValidationError {
|
|
11
|
-
message;
|
|
12
|
-
constructor(message) {
|
|
13
|
-
this.message = message;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Searches for {substring} in {string}.
|
|
18
|
-
* If found, returns the {string}, sliced after substring.
|
|
19
|
-
*
|
|
20
|
-
* @param {string} string - String to be sliced.
|
|
21
|
-
* @param {string} substring - String to search for.
|
|
22
|
-
* @returns {string|null} Null if no match found.
|
|
23
|
-
*/
|
|
24
|
-
function getSubString(string, substring) {
|
|
25
|
-
if (!string)
|
|
26
|
-
return null;
|
|
27
|
-
const testedIndex = string.indexOf(substring);
|
|
28
|
-
if (testedIndex > -1) {
|
|
29
|
-
return string.slice(testedIndex + substring.length);
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns a function from yup, by passing in a function name from our schema.
|
|
35
|
-
* @param {string} functionName - The string to search for a function.
|
|
36
|
-
* @param {Object} previousInstance - Object from previous validator result or yup itself.
|
|
37
|
-
* @returns {Function} Either the found yup function or the default validator.
|
|
38
|
-
*/
|
|
39
|
-
function getYupFunction(functionName, previousInstance = yup) {
|
|
40
|
-
// Make sure we're dealing with a string
|
|
41
|
-
if (functionName instanceof Array) {
|
|
42
|
-
functionName = functionName[0];
|
|
43
|
-
}
|
|
44
|
-
// Attempt to retrieve any custom validators first
|
|
45
|
-
const customValidator = getCustomValidator(functionName);
|
|
46
|
-
if (customValidator) {
|
|
47
|
-
return customValidator;
|
|
48
|
-
}
|
|
49
|
-
const yupName = getSubString(functionName, "yup.");
|
|
50
|
-
if (yupName && previousInstance[yupName] instanceof Function) {
|
|
51
|
-
return previousInstance[yupName].bind(previousInstance);
|
|
52
|
-
}
|
|
53
|
-
if (yupName && yup[yupName] instanceof Function) {
|
|
54
|
-
return yup[yupName].bind(yup);
|
|
55
|
-
}
|
|
56
|
-
throw new ValidationError(`Could not find validator ${functionName}`);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Here we check to see if a passed array could be a prefix notation function.
|
|
60
|
-
* @param {Array} item - Item to be checked.
|
|
61
|
-
* @param {any} item.functionName - We'll check this, and perhaps it's a prefix function name.
|
|
62
|
-
* @returns {boolean} True if we are actually looking at prefix notation.
|
|
63
|
-
*/
|
|
64
|
-
function isPrefixNotation([functionName]) {
|
|
65
|
-
if (functionName instanceof Array) {
|
|
66
|
-
if (isPrefixNotation(functionName))
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
if (typeof functionName !== "string")
|
|
70
|
-
return false;
|
|
71
|
-
if (functionName.indexOf("yup.") < 0)
|
|
72
|
-
return false;
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Ensure that the argument passed is an array.
|
|
77
|
-
* @param {Any} maybeArray - To be checked.
|
|
78
|
-
* @returns {Array} forced to array.
|
|
79
|
-
*/
|
|
80
|
-
function ensureArray(maybeArray) {
|
|
81
|
-
if (maybeArray instanceof Array === false) {
|
|
82
|
-
return [maybeArray];
|
|
83
|
-
}
|
|
84
|
-
return maybeArray;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns true if the passed item is a yup.Schema
|
|
88
|
-
* @param {maybeSchema} item - Item to check
|
|
89
|
-
*/
|
|
90
|
-
function isSchema(item) {
|
|
91
|
-
return [
|
|
92
|
-
// All possible yup schema types
|
|
93
|
-
yup.mixed,
|
|
94
|
-
yup.date,
|
|
95
|
-
yup.array,
|
|
96
|
-
yup.string,
|
|
97
|
-
yup.number,
|
|
98
|
-
yup.object,
|
|
99
|
-
yup.bool,
|
|
100
|
-
].some((schemaType) => item instanceof schemaType);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Converts an array of ['yup.number'] to yup.number().
|
|
104
|
-
* @param {[Any]} arrayArgument - The validation array.
|
|
105
|
-
* @param {Object} previousInstance - The result of a call to yup.number()
|
|
106
|
-
* i.e. an object schema validation set
|
|
107
|
-
* @returns {Function} generated yup validator
|
|
108
|
-
*/
|
|
109
|
-
function convertArray(arrayArgument, previousInstance = yup) {
|
|
110
|
-
const [functionName, ...argsToPass] = ensureArray(arrayArgument);
|
|
111
|
-
// Handle the case when we have a previous instance
|
|
112
|
-
// but we don't want to use it for this transformation
|
|
113
|
-
// [['yup.array'], ['yup.of', [['yup.object'], ['yup.shape'] ...]]]
|
|
114
|
-
if (functionName instanceof Array) {
|
|
115
|
-
return transformArray(arrayArgument);
|
|
116
|
-
}
|
|
117
|
-
const gotFunc = getYupFunction(functionName, previousInstance);
|
|
118
|
-
// Here we'll actually call the function
|
|
119
|
-
// This might be something like yup.number().min(5)
|
|
120
|
-
// We could be passing different types of arguments here
|
|
121
|
-
// so we'll try to transform them before calling the function
|
|
122
|
-
// yup.object().shape({ test: yup.string()}) should also be transformed
|
|
123
|
-
const convertedArguments = transformAll(argsToPass, previousInstance);
|
|
124
|
-
// Handle the case when we've got an array of empty elements
|
|
125
|
-
if (convertedArguments instanceof Array) {
|
|
126
|
-
if (convertedArguments.filter((i) => i).length < 1) {
|
|
127
|
-
if (typeof gotFunc === "function") {
|
|
128
|
-
return gotFunc();
|
|
129
|
-
}
|
|
130
|
-
if (isSchema(gotFunc)) {
|
|
131
|
-
return gotFunc;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Spread the array over the function
|
|
135
|
-
return gotFunc(...convertedArguments);
|
|
136
|
-
}
|
|
137
|
-
// Handle the case when we're passing another validator
|
|
138
|
-
return gotFunc(convertedArguments);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Transforms an array JSON schema to yup array schema.
|
|
142
|
-
*
|
|
143
|
-
* @param {Array} jsonArray - array in JSON to be transformed.
|
|
144
|
-
* @returns {Array} Array with same keys, but values as yup validators.
|
|
145
|
-
*/
|
|
146
|
-
function transformArray(jsonArray, previousInstance = yup) {
|
|
147
|
-
let toReturn = convertArray(jsonArray[0]);
|
|
148
|
-
jsonArray.slice(1).forEach((item) => {
|
|
149
|
-
// Found an array, move to prefix extraction
|
|
150
|
-
if (item instanceof Array) {
|
|
151
|
-
toReturn = convertArray(item, toReturn);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
// Found an object, move to object extraction
|
|
155
|
-
if (item instanceof Object) {
|
|
156
|
-
toReturn = transformObject(item, previousInstance);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
// Handle an edge case where we have something like
|
|
160
|
-
// [['yup.ref', 'linkName'], 'custom error'], and we don't want
|
|
161
|
-
// to consume 'custom error as a variable yet'
|
|
162
|
-
if (toReturn instanceof Array) {
|
|
163
|
-
toReturn = toReturn.concat(item);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
toReturn = [toReturn, item];
|
|
167
|
-
});
|
|
168
|
-
return toReturn;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Transforms an object JSON schema to yup object schema.
|
|
172
|
-
*
|
|
173
|
-
* @param {Object} jsonObject - Object in JSON to be transformed.
|
|
174
|
-
* @returns {Object} Object with same keys, but values as yup validators.
|
|
175
|
-
*/
|
|
176
|
-
function transformObject(jsonObject, previousInstance = yup) {
|
|
177
|
-
const toReturn = {};
|
|
178
|
-
Object.entries(jsonObject).forEach(([key, value]) => {
|
|
179
|
-
// Found an array move to array extraction
|
|
180
|
-
if (value instanceof Array) {
|
|
181
|
-
toReturn[key] = transformArray(value, previousInstance);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
// Found an object recursive extraction
|
|
185
|
-
if (value instanceof Object) {
|
|
186
|
-
toReturn[key] = transformObject(value, previousInstance);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
toReturn[key] = value;
|
|
190
|
-
});
|
|
191
|
-
return toReturn;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Steps into arrays and objects and resolve the items inside to yup validators.
|
|
195
|
-
* @param {Any} jsonObjectOrArray - Object to be transformed.
|
|
196
|
-
* @returns {yup.Validator}
|
|
197
|
-
*/
|
|
198
|
-
function transformAll(jsonObjectOrArray, previousInstance = yup) {
|
|
199
|
-
// We're dealing with an array
|
|
200
|
-
// This could be a prefix notation function
|
|
201
|
-
// If so, we'll call the converter
|
|
202
|
-
if (jsonObjectOrArray instanceof Array) {
|
|
203
|
-
if (isPrefixNotation(jsonObjectOrArray)) {
|
|
204
|
-
return transformArray(jsonObjectOrArray, previousInstance);
|
|
205
|
-
}
|
|
206
|
-
return jsonObjectOrArray.map((i) => transformAll(i, previousInstance));
|
|
207
|
-
}
|
|
208
|
-
// If we're dealing with an object
|
|
209
|
-
// we should check each of the values for that object.
|
|
210
|
-
// Some of them may also be prefix notation functiosn
|
|
211
|
-
if (jsonObjectOrArray instanceof Object) {
|
|
212
|
-
return transformObject(jsonObjectOrArray, previousInstance);
|
|
213
|
-
}
|
|
214
|
-
// No case here, just return anything else
|
|
215
|
-
return jsonObjectOrArray;
|
|
4
|
+
/*
|
|
5
|
+
IBM Confidential
|
|
6
|
+
694970X, 69497O0
|
|
7
|
+
© Copyright IBM Corp. 2022, 2024
|
|
8
|
+
*/
|
|
9
|
+
// @ts-nocheck
|
|
10
|
+
class ValidationError {
|
|
11
|
+
message;
|
|
12
|
+
constructor(message) {
|
|
13
|
+
this.message = message;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Searches for {substring} in {string}.
|
|
18
|
+
* If found, returns the {string}, sliced after substring.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} string - String to be sliced.
|
|
21
|
+
* @param {string} substring - String to search for.
|
|
22
|
+
* @returns {string|null} Null if no match found.
|
|
23
|
+
*/
|
|
24
|
+
function getSubString(string, substring) {
|
|
25
|
+
if (!string)
|
|
26
|
+
return null;
|
|
27
|
+
const testedIndex = string.indexOf(substring);
|
|
28
|
+
if (testedIndex > -1) {
|
|
29
|
+
return string.slice(testedIndex + substring.length);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a function from yup, by passing in a function name from our schema.
|
|
35
|
+
* @param {string} functionName - The string to search for a function.
|
|
36
|
+
* @param {Object} previousInstance - Object from previous validator result or yup itself.
|
|
37
|
+
* @returns {Function} Either the found yup function or the default validator.
|
|
38
|
+
*/
|
|
39
|
+
function getYupFunction(functionName, previousInstance = yup) {
|
|
40
|
+
// Make sure we're dealing with a string
|
|
41
|
+
if (functionName instanceof Array) {
|
|
42
|
+
functionName = functionName[0];
|
|
43
|
+
}
|
|
44
|
+
// Attempt to retrieve any custom validators first
|
|
45
|
+
const customValidator = getCustomValidator(functionName);
|
|
46
|
+
if (customValidator) {
|
|
47
|
+
return customValidator;
|
|
48
|
+
}
|
|
49
|
+
const yupName = getSubString(functionName, "yup.");
|
|
50
|
+
if (yupName && previousInstance[yupName] instanceof Function) {
|
|
51
|
+
return previousInstance[yupName].bind(previousInstance);
|
|
52
|
+
}
|
|
53
|
+
if (yupName && yup[yupName] instanceof Function) {
|
|
54
|
+
return yup[yupName].bind(yup);
|
|
55
|
+
}
|
|
56
|
+
throw new ValidationError(`Could not find validator ${functionName}`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Here we check to see if a passed array could be a prefix notation function.
|
|
60
|
+
* @param {Array} item - Item to be checked.
|
|
61
|
+
* @param {any} item.functionName - We'll check this, and perhaps it's a prefix function name.
|
|
62
|
+
* @returns {boolean} True if we are actually looking at prefix notation.
|
|
63
|
+
*/
|
|
64
|
+
function isPrefixNotation([functionName]) {
|
|
65
|
+
if (functionName instanceof Array) {
|
|
66
|
+
if (isPrefixNotation(functionName))
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (typeof functionName !== "string")
|
|
70
|
+
return false;
|
|
71
|
+
if (functionName.indexOf("yup.") < 0)
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ensure that the argument passed is an array.
|
|
77
|
+
* @param {Any} maybeArray - To be checked.
|
|
78
|
+
* @returns {Array} forced to array.
|
|
79
|
+
*/
|
|
80
|
+
function ensureArray(maybeArray) {
|
|
81
|
+
if (maybeArray instanceof Array === false) {
|
|
82
|
+
return [maybeArray];
|
|
83
|
+
}
|
|
84
|
+
return maybeArray;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns true if the passed item is a yup.Schema
|
|
88
|
+
* @param {maybeSchema} item - Item to check
|
|
89
|
+
*/
|
|
90
|
+
function isSchema(item) {
|
|
91
|
+
return [
|
|
92
|
+
// All possible yup schema types
|
|
93
|
+
yup.mixed,
|
|
94
|
+
yup.date,
|
|
95
|
+
yup.array,
|
|
96
|
+
yup.string,
|
|
97
|
+
yup.number,
|
|
98
|
+
yup.object,
|
|
99
|
+
yup.bool,
|
|
100
|
+
].some((schemaType) => item instanceof schemaType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Converts an array of ['yup.number'] to yup.number().
|
|
104
|
+
* @param {[Any]} arrayArgument - The validation array.
|
|
105
|
+
* @param {Object} previousInstance - The result of a call to yup.number()
|
|
106
|
+
* i.e. an object schema validation set
|
|
107
|
+
* @returns {Function} generated yup validator
|
|
108
|
+
*/
|
|
109
|
+
function convertArray(arrayArgument, previousInstance = yup) {
|
|
110
|
+
const [functionName, ...argsToPass] = ensureArray(arrayArgument);
|
|
111
|
+
// Handle the case when we have a previous instance
|
|
112
|
+
// but we don't want to use it for this transformation
|
|
113
|
+
// [['yup.array'], ['yup.of', [['yup.object'], ['yup.shape'] ...]]]
|
|
114
|
+
if (functionName instanceof Array) {
|
|
115
|
+
return transformArray(arrayArgument);
|
|
116
|
+
}
|
|
117
|
+
const gotFunc = getYupFunction(functionName, previousInstance);
|
|
118
|
+
// Here we'll actually call the function
|
|
119
|
+
// This might be something like yup.number().min(5)
|
|
120
|
+
// We could be passing different types of arguments here
|
|
121
|
+
// so we'll try to transform them before calling the function
|
|
122
|
+
// yup.object().shape({ test: yup.string()}) should also be transformed
|
|
123
|
+
const convertedArguments = transformAll(argsToPass, previousInstance);
|
|
124
|
+
// Handle the case when we've got an array of empty elements
|
|
125
|
+
if (convertedArguments instanceof Array) {
|
|
126
|
+
if (convertedArguments.filter((i) => i).length < 1) {
|
|
127
|
+
if (typeof gotFunc === "function") {
|
|
128
|
+
return gotFunc();
|
|
129
|
+
}
|
|
130
|
+
if (isSchema(gotFunc)) {
|
|
131
|
+
return gotFunc;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Spread the array over the function
|
|
135
|
+
return gotFunc(...convertedArguments);
|
|
136
|
+
}
|
|
137
|
+
// Handle the case when we're passing another validator
|
|
138
|
+
return gotFunc(convertedArguments);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Transforms an array JSON schema to yup array schema.
|
|
142
|
+
*
|
|
143
|
+
* @param {Array} jsonArray - array in JSON to be transformed.
|
|
144
|
+
* @returns {Array} Array with same keys, but values as yup validators.
|
|
145
|
+
*/
|
|
146
|
+
function transformArray(jsonArray, previousInstance = yup) {
|
|
147
|
+
let toReturn = convertArray(jsonArray[0]);
|
|
148
|
+
jsonArray.slice(1).forEach((item) => {
|
|
149
|
+
// Found an array, move to prefix extraction
|
|
150
|
+
if (item instanceof Array) {
|
|
151
|
+
toReturn = convertArray(item, toReturn);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// Found an object, move to object extraction
|
|
155
|
+
if (item instanceof Object) {
|
|
156
|
+
toReturn = transformObject(item, previousInstance);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Handle an edge case where we have something like
|
|
160
|
+
// [['yup.ref', 'linkName'], 'custom error'], and we don't want
|
|
161
|
+
// to consume 'custom error as a variable yet'
|
|
162
|
+
if (toReturn instanceof Array) {
|
|
163
|
+
toReturn = toReturn.concat(item);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
toReturn = [toReturn, item];
|
|
167
|
+
});
|
|
168
|
+
return toReturn;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Transforms an object JSON schema to yup object schema.
|
|
172
|
+
*
|
|
173
|
+
* @param {Object} jsonObject - Object in JSON to be transformed.
|
|
174
|
+
* @returns {Object} Object with same keys, but values as yup validators.
|
|
175
|
+
*/
|
|
176
|
+
function transformObject(jsonObject, previousInstance = yup) {
|
|
177
|
+
const toReturn = {};
|
|
178
|
+
Object.entries(jsonObject).forEach(([key, value]) => {
|
|
179
|
+
// Found an array move to array extraction
|
|
180
|
+
if (value instanceof Array) {
|
|
181
|
+
toReturn[key] = transformArray(value, previousInstance);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Found an object recursive extraction
|
|
185
|
+
if (value instanceof Object) {
|
|
186
|
+
toReturn[key] = transformObject(value, previousInstance);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
toReturn[key] = value;
|
|
190
|
+
});
|
|
191
|
+
return toReturn;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Steps into arrays and objects and resolve the items inside to yup validators.
|
|
195
|
+
* @param {Any} jsonObjectOrArray - Object to be transformed.
|
|
196
|
+
* @returns {yup.Validator}
|
|
197
|
+
*/
|
|
198
|
+
function transformAll(jsonObjectOrArray, previousInstance = yup) {
|
|
199
|
+
// We're dealing with an array
|
|
200
|
+
// This could be a prefix notation function
|
|
201
|
+
// If so, we'll call the converter
|
|
202
|
+
if (jsonObjectOrArray instanceof Array) {
|
|
203
|
+
if (isPrefixNotation(jsonObjectOrArray)) {
|
|
204
|
+
return transformArray(jsonObjectOrArray, previousInstance);
|
|
205
|
+
}
|
|
206
|
+
return jsonObjectOrArray.map((i) => transformAll(i, previousInstance));
|
|
207
|
+
}
|
|
208
|
+
// If we're dealing with an object
|
|
209
|
+
// we should check each of the values for that object.
|
|
210
|
+
// Some of them may also be prefix notation functiosn
|
|
211
|
+
if (jsonObjectOrArray instanceof Object) {
|
|
212
|
+
return transformObject(jsonObjectOrArray, previousInstance);
|
|
213
|
+
}
|
|
214
|
+
// No case here, just return anything else
|
|
215
|
+
return jsonObjectOrArray;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export { transformAll, transformObject };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { object } from 'yup';
|
|
2
2
|
|
|
3
|
-
/*
|
|
4
|
-
IBM Confidential
|
|
5
|
-
694970X, 69497O0
|
|
6
|
-
© Copyright IBM Corp. 2022, 2024
|
|
7
|
-
*/
|
|
8
|
-
const CUSTOM_VALIDATORS = {};
|
|
9
|
-
function addCustomValidator(name, validator, binding = false) {
|
|
10
|
-
if (binding !== false) {
|
|
11
|
-
validator = validator.bind(binding);
|
|
12
|
-
}
|
|
13
|
-
CUSTOM_VALIDATORS[name] = validator;
|
|
14
|
-
}
|
|
15
|
-
function getCustomValidator(name) {
|
|
16
|
-
return CUSTOM_VALIDATORS[name];
|
|
17
|
-
}
|
|
18
|
-
// Handle the case when we have an array of objects
|
|
19
|
-
// but the previous instance of yup.shape is the yup.array
|
|
3
|
+
/*
|
|
4
|
+
IBM Confidential
|
|
5
|
+
694970X, 69497O0
|
|
6
|
+
© Copyright IBM Corp. 2022, 2024
|
|
7
|
+
*/
|
|
8
|
+
const CUSTOM_VALIDATORS = {};
|
|
9
|
+
function addCustomValidator(name, validator, binding = false) {
|
|
10
|
+
if (binding !== false) {
|
|
11
|
+
validator = validator.bind(binding);
|
|
12
|
+
}
|
|
13
|
+
CUSTOM_VALIDATORS[name] = validator;
|
|
14
|
+
}
|
|
15
|
+
function getCustomValidator(name) {
|
|
16
|
+
return CUSTOM_VALIDATORS[name];
|
|
17
|
+
}
|
|
18
|
+
// Handle the case when we have an array of objects
|
|
19
|
+
// but the previous instance of yup.shape is the yup.array
|
|
20
20
|
addCustomValidator("yup.shape", object().shape, object());
|
|
21
21
|
|
|
22
22
|
export { addCustomValidator, getCustomValidator };
|