@elliemae/ds-props-helpers 3.50.1-next.9 → 3.51.0-beta.2
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/cjs/tests/globalProps/TestComponent.js +2 -3
- package/dist/cjs/tests/globalProps/TestComponent.js.map +2 -2
- package/dist/cjs/tests/xstyledProps/TestComponent.js +0 -1
- package/dist/cjs/tests/xstyledProps/TestComponent.js.map +2 -2
- package/dist/cjs/validation/typescriptValidator.js +1 -1
- package/dist/cjs/validation/typescriptValidator.js.map +2 -2
- package/dist/esm/tests/globalProps/TestComponent.js +1 -2
- package/dist/esm/tests/globalProps/TestComponent.js.map +3 -3
- package/dist/esm/tests/xstyledProps/TestComponent.js +0 -1
- package/dist/esm/tests/xstyledProps/TestComponent.js.map +3 -3
- package/dist/esm/validation/typescriptValidator.js +1 -1
- package/dist/esm/validation/typescriptValidator.js.map +2 -2
- package/package.json +10 -9
|
@@ -33,10 +33,9 @@ __export(TestComponent_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(TestComponent_exports);
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
-
var
|
|
37
|
-
var import_globalProps = require("../../globalProps");
|
|
36
|
+
var import_useGetGlobalAttributes = require("../../globalProps/useGetGlobalAttributes");
|
|
38
37
|
const TestComponent = (props) => {
|
|
39
|
-
const globalAttributes = (0,
|
|
38
|
+
const globalAttributes = (0, import_useGetGlobalAttributes.useGetGlobalAttributes)(props);
|
|
40
39
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...globalAttributes, children: "Some random div" });
|
|
41
40
|
};
|
|
42
41
|
//# sourceMappingURL=TestComponent.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tests/globalProps/TestComponent.js", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMd;
|
|
4
|
+
"sourcesContent": ["// eslint-disable-next-line import/extensions\nimport { useGetGlobalAttributes } from '../../globalProps/useGetGlobalAttributes';\n\nexport const TestComponent = (props) => {\n const globalAttributes = useGetGlobalAttributes(props);\n\n return <div {...globalAttributes}>Some random div</div>;\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMd;AALT,oCAAuC;AAEhC,MAAM,gBAAgB,CAAC,UAAU;AACtC,QAAM,uBAAmB,sDAAuB,KAAK;AAErD,SAAO,4CAAC,SAAK,GAAG,kBAAkB,6BAAe;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -33,7 +33,6 @@ __export(TestComponent_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(TestComponent_exports);
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
-
var import_react = __toESM(require("react"));
|
|
37
36
|
var import_xstyledProps = require("../../xstyledProps");
|
|
38
37
|
const TestComponent = (props) => {
|
|
39
38
|
const xstyledProps = (0, import_xstyledProps.useGetXstyledProps)(props);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tests/xstyledProps/TestComponent.js", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable react/prop-types */\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADUnB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable react/prop-types */\n// eslint-disable-next-line import/extensions\nimport { useGetXstyledProps } from '../../xstyledProps';\n\nexport const TestComponent = (props) => {\n const xstyledProps = useGetXstyledProps(props);\n\n props.signal(xstyledProps);\n\n return (\n <div {...xstyledProps} data-testid=\"xstyled-div\">\n Some random div\n </div>\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADUnB;AARJ,0BAAmC;AAE5B,MAAM,gBAAgB,CAAC,UAAU;AACtC,QAAM,mBAAe,wCAAmB,KAAK;AAE7C,QAAM,OAAO,YAAY;AAEzB,SACE,4CAAC,SAAK,GAAG,cAAc,eAAY,eAAc,6BAEjD;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -197,7 +197,7 @@ const validateTypescriptPropTypesImplementation = (props, schema, validationsMem
|
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
199
|
const useValidateTypescriptPropTypes = (props, propTypes, componentDisplayName) => {
|
|
200
|
-
if (!
|
|
200
|
+
if (!componentDisplayName) {
|
|
201
201
|
throw new Error("Provide display name for the component to use for validation");
|
|
202
202
|
}
|
|
203
203
|
const validationsMemo = (0, import_react.useRef)({});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validation/typescriptValidator.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\n\ntype ValidatorFn = (\n schemaName: string,\n key: string,\n value: unknown,\n format: string,\n validationsMemo: Record<symbol, string>,\n nextValidationsMemo: Record<symbol, string>,\n) => void;\n\n// =============================================================================\n// Atom Validators\n// =============================================================================\n\n// This functions will validate something from the data\n// and optionally recursively apply `validateValueWithFormat`\n// in smaller parts\n\nconst validateUndefined: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== undefined || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, trueKey);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObjectOf(format)) {\n validateObjectOf(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isSomethingWithParenthesis(format)) {\n validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);\n }\n};\n\nexport const validateTypescriptPropTypesImplementation = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptDocumentation,\n validationsMemo: Record<string, string> = {},\n nextValidationsMemo: Record<string, string> = {},\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!Boolean(componentDisplayName)) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAgC;AAEhC,uBAAyB;AACzB,4BAAmD;AACnD,8BAYO;AACP,+BAAuC;AAmBvC,MAAM,oBAAiC,CAAC,YAAY,KAAK,OAAO,WAAW;AACzE,MAAI,UAAU,UAAa,UAAU,aAAa;AAChD,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;AAAA,EACrF,eAAW,oCAAW,MAAM,GAAG;AAC7B,qBAAiB,YAAY,KAAK,OAAO,QAAQ,iBAAiB,mBAAmB;AAAA,EACvF,eAAW,qCAAY,MAAM,GAAG;AAC9B,sBAAkB,YAAY,KAAK,OAAO,QAAQ,iBAAiB,mBAAmB;AAAA,EACxF,eAAW,oDAA2B,MAAM,GAAG;AAC7C,4BAAwB,YAAY,KAAK,OAAO,OAAO,MAAM,GAAG,EAAE,GAAG,iBAAiB,mBAAmB;AAAA,EAC3G;AACF;AAEO,MAAM,4CAA4C,CACvD,OACA,QACA,kBAA0C,CAAC,GAC3C,sBAA8C,CAAC,MACtC;AACT,QAAM,EAAE,YAAY,MAAM,WAAW,IAAI;AAEzC,aAAW,QAAQ,CAAC,aAAa;AAC/B,UAAM,EAAE,MAAM,QAAQ,UAAU,cAAc,eAAe,IAAI;AAEjE,UAAM,wBAAwB,gBAAgB,aAAa,KAAK;AAEhE,QAAI,gBAAgB;AAClB;AAAA,IACF;AAEA,QAAI,YAAY,EAAE,QAAQ,QAAQ;AAChC,oDAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,QAAI,yBAAyB,EAAE,QAAQ,QAAQ;AAC7C,oDAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,UAAM,yBAAyB,MAAM,IAAI,MAAM,UAAa,YAAY;AAExE,QAAI,QAAQ,SAAS,UAAU,wBAAwB;AACrD,8BAAwB,YAAY,MAAM,MAAM,IAAI,GAAG,QAAQ,iBAAiB,mBAAmB;AAAA,IACrG;AAAA,EACF,CAAC;AACH;AAGO,MAAM,iCAAiC,CAC5C,OACA,WACA,yBACS;AACT,MAAI,CAAC,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\n\ntype ValidatorFn = (\n schemaName: string,\n key: string,\n value: unknown,\n format: string,\n validationsMemo: Record<symbol, string>,\n nextValidationsMemo: Record<symbol, string>,\n) => void;\n\n// =============================================================================\n// Atom Validators\n// =============================================================================\n\n// This functions will validate something from the data\n// and optionally recursively apply `validateValueWithFormat`\n// in smaller parts\n\nconst validateUndefined: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== undefined || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, trueKey);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObjectOf(format)) {\n validateObjectOf(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isSomethingWithParenthesis(format)) {\n validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);\n }\n};\n\nexport const validateTypescriptPropTypesImplementation = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptDocumentation,\n validationsMemo: Record<string, string> = {},\n nextValidationsMemo: Record<string, string> = {},\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAgC;AAEhC,uBAAyB;AACzB,4BAAmD;AACnD,8BAYO;AACP,+BAAuC;AAmB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AAM,uBAAmB,sBAAQ,MAAM;AACrC,UAAM,YAAY,MAAM;AAAA,IAAC;AAEzB,UAAM,yBAAqB,2BAAS,SAAS;AAC7C,uBAAmB,YAAY;AAC/B,uBAAmB,cAAc;AACjC,WAAO,mBAAmB,aAAa;AAAA,EAEzC,GAAG,CAAC,SAAS,CAAC;AAEd,4BAAQ,MAAM;AACZ,UAAM,sBAAsB,CAAC;AAE7B,8CAA0C,OAAO,kBAAkB,gBAAgB,SAAS,mBAAmB;AAC/G,oBAAgB,UAAU;AAC1B,WAAO;AAAA,EAET,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import
|
|
4
|
-
import { useGetGlobalAttributes } from "../../globalProps";
|
|
3
|
+
import { useGetGlobalAttributes } from "../../globalProps/useGetGlobalAttributes";
|
|
5
4
|
const TestComponent = (props) => {
|
|
6
5
|
const globalAttributes = useGetGlobalAttributes(props);
|
|
7
6
|
return /* @__PURE__ */ jsx("div", { ...globalAttributes, children: "Some random div" });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/tests/globalProps/TestComponent.js"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACMd;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "// eslint-disable-next-line import/extensions\nimport { useGetGlobalAttributes } from '../../globalProps/useGetGlobalAttributes';\n\nexport const TestComponent = (props) => {\n const globalAttributes = useGetGlobalAttributes(props);\n\n return <div {...globalAttributes}>Some random div</div>;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACMd;AALT,SAAS,8BAA8B;AAEhC,MAAM,gBAAgB,CAAC,UAAU;AACtC,QAAM,mBAAmB,uBAAuB,KAAK;AAErD,SAAO,oBAAC,SAAK,GAAG,kBAAkB,6BAAe;AACnD;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/tests/xstyledProps/TestComponent.js"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/prop-types */\
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACUnB;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/prop-types */\n// eslint-disable-next-line import/extensions\nimport { useGetXstyledProps } from '../../xstyledProps';\n\nexport const TestComponent = (props) => {\n const xstyledProps = useGetXstyledProps(props);\n\n props.signal(xstyledProps);\n\n return (\n <div {...xstyledProps} data-testid=\"xstyled-div\">\n Some random div\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACUnB;AARJ,SAAS,0BAA0B;AAE5B,MAAM,gBAAgB,CAAC,UAAU;AACtC,QAAM,eAAe,mBAAmB,KAAK;AAE7C,QAAM,OAAO,YAAY;AAEzB,SACE,oBAAC,SAAK,GAAG,cAAc,eAAY,eAAc,6BAEjD;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -175,7 +175,7 @@ const validateTypescriptPropTypesImplementation = (props, schema, validationsMem
|
|
|
175
175
|
});
|
|
176
176
|
};
|
|
177
177
|
const useValidateTypescriptPropTypes = (props, propTypes, componentDisplayName) => {
|
|
178
|
-
if (!
|
|
178
|
+
if (!componentDisplayName) {
|
|
179
179
|
throw new Error("Provide display name for the component to use for validation");
|
|
180
180
|
}
|
|
181
181
|
const validationsMemo = useRef({});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/typescriptValidator.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\n\ntype ValidatorFn = (\n schemaName: string,\n key: string,\n value: unknown,\n format: string,\n validationsMemo: Record<symbol, string>,\n nextValidationsMemo: Record<symbol, string>,\n) => void;\n\n// =============================================================================\n// Atom Validators\n// =============================================================================\n\n// This functions will validate something from the data\n// and optionally recursively apply `validateValueWithFormat`\n// in smaller parts\n\nconst validateUndefined: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== undefined || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, trueKey);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObjectOf(format)) {\n validateObjectOf(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isSomethingWithParenthesis(format)) {\n validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);\n }\n};\n\nexport const validateTypescriptPropTypesImplementation = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptDocumentation,\n validationsMemo: Record<string, string> = {},\n nextValidationsMemo: Record<string, string> = {},\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!Boolean(componentDisplayName)) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,cAAc;AAEhC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,sBAAsB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AAmBvC,MAAM,oBAAiC,CAAC,YAAY,KAAK,OAAO,WAAW;AACzE,MAAI,UAAU,UAAa,UAAU,aAAa;AAChD,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,eAA4B,CAAC,YAAY,KAAK,OAAO,WAAW;AACpE,MAAI,UAAU,QAAQ,UAAU,QAAQ;AACtC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,wBAAqC,CAAC,YAAY,KAAK,OAAO,WAAW;AAC7E,MAAI,OAAO,UAAU,QAAQ;AAC3B,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,iBAA8B,CAAC,YAAY,KAAK,OAAO,WAAW;AACtE,MAAI,UAAU,OAAO,MAAM,GAAG,EAAE,GAAG;AACjC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,gBAA6B,CAAC,YAAY,KAAK,OAAO,QAAQ,iBAAiB,wBAAwB;AAE3G,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AAGA,EAAC,MAAoB,QAAQ,CAAC,KAAK,UAAU;AAG3C;AAAA,MACE;AAA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E,QAAQ,QAAQ;AAC7C,yBAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,UAAM,yBAAyB,MAAM,IAAI,MAAM,UAAa,YAAY;AAExE,QAAI,QAAQ,SAAS,UAAU,wBAAwB;AACrD,8BAAwB,YAAY,MAAM,MAAM,IAAI,GAAG,QAAQ,iBAAiB,mBAAmB;AAAA,IACrG;AAAA,EACF,CAAC;AACH;AAGO,MAAM,iCAAiC,CAC5C,OACA,WACA,yBACS;AACT,MAAI,CAAC,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\n\ntype ValidatorFn = (\n schemaName: string,\n key: string,\n value: unknown,\n format: string,\n validationsMemo: Record<symbol, string>,\n nextValidationsMemo: Record<symbol, string>,\n) => void;\n\n// =============================================================================\n// Atom Validators\n// =============================================================================\n\n// This functions will validate something from the data\n// and optionally recursively apply `validateValueWithFormat`\n// in smaller parts\n\nconst validateUndefined: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== undefined || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, trueKey);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObjectOf(format)) {\n validateObjectOf(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isSomethingWithParenthesis(format)) {\n validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);\n }\n};\n\nexport const validateTypescriptPropTypesImplementation = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptDocumentation,\n validationsMemo: Record<string, string> = {},\n nextValidationsMemo: Record<string, string> = {},\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,cAAc;AAEhC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,sBAAsB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AAmBvC,MAAM,oBAAiC,CAAC,YAAY,KAAK,OAAO,WAAW;AACzE,MAAI,UAAU,UAAa,UAAU,aAAa;AAChD,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,eAA4B,CAAC,YAAY,KAAK,OAAO,WAAW;AACpE,MAAI,UAAU,QAAQ,UAAU,QAAQ;AACtC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,wBAAqC,CAAC,YAAY,KAAK,OAAO,WAAW;AAC7E,MAAI,OAAO,UAAU,QAAQ;AAC3B,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,iBAA8B,CAAC,YAAY,KAAK,OAAO,WAAW;AACtE,MAAI,UAAU,OAAO,MAAM,GAAG,EAAE,GAAG;AACjC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,gBAA6B,CAAC,YAAY,KAAK,OAAO,QAAQ,iBAA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BAAwB,gBAAgB,aAAa,KAAK;AAEhE,QAAI,gBAAgB;AAClB;AAAA,IACF;AAEA,QAAI,YAAY,EAAE,QAAQ,QAAQ;AAChC,yBAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,QAAI,yBAAyB,EAAE,QAAQ,QAAQ;AAC7C,yBAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,UAAM,yBAAyB,MAAM,IAAI,MAAM,UAAa,YAAY;AAExE,QAAI,QAAQ,SAAS,UAAU,wBAAwB;AACrD,8BAAwB,YAAY,MAAM,MAAM,IAAI,GAAG,QAAQ,iBAAiB,mBAAmB;AAAA,IACrG;AAAA,EACF,CAAC;AACH;AAGO,MAAM,iCAAiC,CAC5C,OACA,WACA,yBACS;AACT,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AAEA,QAAM,kBAAkB,OAA+B,CAAC,CAAC;AAEzD,QAAM,mBAAmB,QAAQ,MAAM;AACrC,UAAM,YAAY,MAAM;AAAA,IAAC;AAEzB,UAAM,qBAAqB,SAAS,SAAS;AAC7C,uBAAmB,YAAY;AAC/B,uBAAmB,cAAc;AACjC,WAAO,mBAAmB,aAAa;AAAA,EAEzC,GAAG,CAAC,SAAS,CAAC;AAEd,UAAQ,MAAM;AACZ,UAAM,sBAAsB,CAAC;AAE7B,8CAA0C,OAAO,kBAAkB,gBAAgB,SAAS,mBAAmB;AAC/G,oBAAgB,UAAU;AAC1B,WAAO;AAAA,EAET,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.51.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"files": [
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
|
-
"pnpm": ">=
|
|
26
|
-
"node": ">=
|
|
25
|
+
"pnpm": ">=9",
|
|
26
|
+
"node": ">=22"
|
|
27
27
|
},
|
|
28
28
|
"author": "ICE MT",
|
|
29
29
|
"jestSonar": {
|
|
@@ -35,18 +35,19 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"fast-deep-equal": "~3.1.3",
|
|
37
37
|
"prop-types": "~15.8.1",
|
|
38
|
-
"@elliemae/ds-system": "3.
|
|
39
|
-
"@elliemae/ds-typescript-helpers": "3.
|
|
38
|
+
"@elliemae/ds-system": "3.51.0-beta.2",
|
|
39
|
+
"@elliemae/ds-typescript-helpers": "3.51.0-beta.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@elliemae/pui-cli": "9.0.0-next.
|
|
42
|
+
"@elliemae/pui-cli": "9.0.0-next.55",
|
|
43
43
|
"jest": "~29.7.0",
|
|
44
|
-
"
|
|
44
|
+
"jest-cli": "~29.7.0",
|
|
45
|
+
"@elliemae/ds-monorepo-devops": "3.51.0-beta.2"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"lodash": "^4.17.21",
|
|
48
|
-
"react": "^
|
|
49
|
-
"react-dom": "^
|
|
49
|
+
"react": "^18.3.1",
|
|
50
|
+
"react-dom": "^18.3.1"
|
|
50
51
|
},
|
|
51
52
|
"publishConfig": {
|
|
52
53
|
"access": "public",
|