@elliemae/ds-props-helpers 1.55.0-next.4 → 1.55.0-next.5

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.
@@ -26,11 +26,7 @@ var useMemoCompare = function useMemoCompare(next, compare) {
26
26
  // We only update if not equal so that this hook continues to return
27
27
  // the same old value if compare keeps returning true.
28
28
 
29
- react.useEffect(function () {
30
- if (!isEqual) {
31
- previousRef.current = next;
32
- }
33
- }); // Finally, if equal then return the previous value
29
+ if (!isEqual) previousRef.current = next; // Finally, if equal then return the previous value
34
30
 
35
31
  return isEqual ? previous : next;
36
32
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1 +1 @@
1
- {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport deepequal from 'fast-deep-equal/react';\n\n// Hook\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useMemoCompare = <T = any>(next: T, compare: (prevToCompare: T, nextToCompare: T) => boolean): T => {\n // Ref for storing previous value\n const previousRef = useRef<T>();\n const previous = previousRef.current;\n // Pass previous and next value to compare function\n // to determine whether to consider them equal.\n const isEqual = compare(previous, next);\n // If not equal update previousRef to next value.\n // We only update if not equal so that this hook continues to return\n // the same old value if compare keeps returning true.\n useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\n // Finally, if equal then return the previous value\n return isEqual ? previous : next;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useMemoMergePropsWithDefault = <T = Record<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;;;;;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,YAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,eAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfT,OACe,uEADLU,6BACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaa,WAAb,EAA0BX,OAA1B,CAArB;AACD;;;;"}
1
+ {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport deepequal from 'fast-deep-equal/react';\n\n// Hook\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useMemoCompare = <T = any>(next: T, compare: (prevToCompare: T, nextToCompare: T) => boolean): T => {\n // Ref for storing previous value\n const previousRef = useRef<T>();\n const previous = previousRef.current;\n // Pass previous and next value to compare function\n // to determine whether to consider them equal.\n const isEqual = compare(previous, next);\n // If not equal update previousRef to next value.\n // We only update if not equal so that this hook continues to return\n // the same old value if compare keeps returning true.\n if (!isEqual) previousRef.current = next;\n // Finally, if equal then return the previous value\n return isEqual ? previous : next;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useMemoMergePropsWithDefault = <T = Record<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;;;;;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,YAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACA,MAAI,CAACM,OAAL,EAAcJ,WAAW,CAACG,OAAZ,GAAsBL,IAAtB,CAV0F;;AAYxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAbD;;;IAgBaO,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfR,OACe,uEADLS,6BACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOT,cAAc,CAAaY,WAAb,EAA0BV,OAA1B,CAArB;AACD;;;;"}
package/cjs/index.js CHANGED
@@ -21,4 +21,5 @@ exports.useValidatePropTypes = validation_validator.useValidatePropTypes;
21
21
  exports.throwRequiredError = validation_errorTemplates.throwRequiredError;
22
22
  exports.throwTypeError = validation_errorTemplates.throwTypeError;
23
23
  exports.useValidateTypescriptPropTypes = validation_typescriptValidator.useValidateTypescriptPropTypes;
24
+ exports.validateTypescriptPropTypesImplementation = validation_typescriptValidator.validateTypescriptPropTypesImplementation;
24
25
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
@@ -7,6 +7,7 @@ var validation_errorTemplates = require('./errorTemplates.js');
7
7
  var validation_typescriptValidator = require('./typescriptValidator.js');
8
8
  require('@babel/runtime/helpers/typeof');
9
9
  require('@babel/runtime/helpers/slicedToArray');
10
+ require('react');
10
11
  require('./typescriptGuards.js');
11
12
  require('./typescriptParsers.js');
12
13
 
@@ -16,4 +17,5 @@ exports.useValidatePropTypes = validation_validator.useValidatePropTypes;
16
17
  exports.throwRequiredError = validation_errorTemplates.throwRequiredError;
17
18
  exports.throwTypeError = validation_errorTemplates.throwTypeError;
18
19
  exports.useValidateTypescriptPropTypes = validation_typescriptValidator.useValidateTypescriptPropTypes;
20
+ exports.validateTypescriptPropTypesImplementation = validation_typescriptValidator.validateTypescriptPropTypesImplementation;
19
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -5,11 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var isPrimitiveType = function isPrimitiveType(format) {
6
6
  return ['string', 'number', 'boolean'].includes(format);
7
7
  };
8
+ var isUndefined = function isUndefined(format) {
9
+ return format === '"undefined"';
10
+ };
8
11
  var isUnion = function isUnion(format) {
9
12
  var depth = 0;
10
13
  var satisfies = false;
11
14
  format.split('').forEach(function (char) {
12
- if (char === '{') depth += 1;else if (char === '}') depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
15
+ if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
13
16
  });
14
17
  return satisfies;
15
18
  };
@@ -23,17 +26,22 @@ var isObject = function isObject(format) {
23
26
  return format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
24
27
  };
25
28
  var isFunction = function isFunction(format) {
26
- return !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
29
+ return !isUnion(format) && format === '((...args: any[]) => any)';
27
30
  };
28
31
  var isJSXorNode = function isJSXorNode(format) {
29
32
  return !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
30
33
  };
34
+ var isSomethingWithParenthesis = function isSomethingWithParenthesis(format) {
35
+ return !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
36
+ };
31
37
 
32
38
  exports.isArray = isArray;
33
39
  exports.isFunction = isFunction;
34
40
  exports.isJSXorNode = isJSXorNode;
35
41
  exports.isObject = isObject;
36
42
  exports.isPrimitiveType = isPrimitiveType;
43
+ exports.isSomethingWithParenthesis = isSomethingWithParenthesis;
37
44
  exports.isString = isString;
45
+ exports.isUndefined = isUndefined;
38
46
  exports.isUnion = isUnion;
39
47
  //# sourceMappingURL=typescriptGuards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typescriptGuards.js","sources":["../../../src/validation/typescriptGuards.ts"],"sourcesContent":["type guardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: guardFn = (format) => ['string', 'number', 'boolean'].includes(format);\n\nexport const isUnion: guardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (char === '{') depth += 1;\n else if (char === '}') depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: guardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: guardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObject: guardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: guardFn = (format) => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n\nexport const isJSXorNode: guardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n"],"names":["isPrimitiveType","format","includes","isUnion","depth","satisfies","split","forEach","char","isString","slice","isArray","isObject","isFunction","isJSXorNode"],"mappings":";;;;IAEaA,eAAwB,GAAG,SAA3BA,eAA2B,CAACC,MAAD;AAAA,SAAY,CAAC,QAAD,EAAW,QAAX,EAAqB,SAArB,EAAgCC,QAAhC,CAAyCD,MAAzC,CAAZ;AAAA;IAE3BE,OAAgB,GAAG,SAAnBA,OAAmB,CAACF,MAAD,EAAY;AAC1C,MAAIG,KAAK,GAAG,CAAZ;AACA,MAAIC,SAAS,GAAG,KAAhB;AACAJ,EAAAA,MAAM,CAACK,KAAP,CAAa,EAAb,EAAiBC,OAAjB,CAAyB,UAACC,IAAD,EAAU;AACjC,QAAIA,IAAI,KAAK,GAAb,EAAkBJ,KAAK,IAAI,CAAT,CAAlB,KACK,IAAII,IAAI,KAAK,GAAb,EAAkBJ,KAAK,IAAI,CAAT,CAAlB,KACA,IAAII,IAAI,KAAK,GAAT,IAAgBJ,KAAK,KAAK,CAA9B,EAAiCC,SAAS,GAAG,IAAZ;AACvC,GAJD;AAKA,SAAOA,SAAP;AACD;IAEYI,QAAiB,GAAG,SAApBA,QAAoB,CAACR,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACS,KAAP,CAAa,CAAC,CAAd,MAAqB,GAA1E;AAAA;IAEpBC,OAAgB,GAAG,SAAnBA,OAAmB,CAACV,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoBA,MAAM,CAACS,KAAP,CAAa,CAAC,CAAd,MAAqB,IAArD;AAAA;IAEnBE,QAAiB,GAAG,SAApBA,QAAoB,CAACX,MAAD;AAAA,SAC/BA,MAAM,KAAK,QAAX,IAAwB,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACS,KAAP,CAAa,CAAC,CAAd,MAAqB,GADvD;AAAA;IAGpBG,UAAmB,GAAG,SAAtBA,UAAsB,CAACZ,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACS,KAAP,CAAa,CAAC,CAAd,MAAqB,GAA1E;AAAA;IAEtBI,WAAoB,GAAG,SAAvBA,WAAuB,CAACb,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoB,CAAC,iBAAD,EAAoB,aAApB,EAAmCC,QAAnC,CAA4CD,MAA5C,CAAhC;AAAA;;;;;;;;;;"}
1
+ {"version":3,"file":"typescriptGuards.js","sources":["../../../src/validation/typescriptGuards.ts"],"sourcesContent":["type guardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: guardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: guardFn = (format) => format === '\"undefined\"';\nexport const isUnion: guardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: guardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: guardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObject: guardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: guardFn = (format) => !isUnion(format) && format === '((...args: any[]) => any)';\n\nexport const isJSXorNode: guardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isSomethingWithParenthesis: guardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n"],"names":["isPrimitiveType","format","includes","isUndefined","isUnion","depth","satisfies","split","forEach","char","isString","slice","isArray","isObject","isFunction","isJSXorNode","isSomethingWithParenthesis"],"mappings":";;;;IAEaA,eAAwB,GAAG,SAA3BA,eAA2B,CAACC,MAAD;AAAA,SAAY,CAAC,QAAD,EAAW,QAAX,EAAqB,SAArB,EAAgCC,QAAhC,CAAyCD,MAAzC,CAAZ;AAAA;IAC3BE,WAAoB,GAAG,SAAvBA,WAAuB,CAACF,MAAD;AAAA,SAAYA,MAAM,KAAK,aAAvB;AAAA;IACvBG,OAAgB,GAAG,SAAnBA,OAAmB,CAACH,MAAD,EAAY;AAC1C,MAAII,KAAK,GAAG,CAAZ;AACA,MAAIC,SAAS,GAAG,KAAhB;AACAL,EAAAA,MAAM,CAACM,KAAP,CAAa,EAAb,EAAiBC,OAAjB,CAAyB,UAACC,IAAD,EAAU;AACjC,QAAI,CAAC,GAAD,EAAM,GAAN,EAAWP,QAAX,CAAoBO,IAApB,CAAJ,EAA+BJ,KAAK,IAAI,CAAT,CAA/B,KACK,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWH,QAAX,CAAoBO,IAApB,CAAJ,EAA+BJ,KAAK,IAAI,CAAT,CAA/B,KACA,IAAII,IAAI,KAAK,GAAT,IAAgBJ,KAAK,KAAK,CAA9B,EAAiCC,SAAS,GAAG,IAAZ;AACvC,GAJD;AAKA,SAAOA,SAAP;AACD;IAEYI,QAAiB,GAAG,SAApBA,QAAoB,CAACT,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GAA1E;AAAA;IAEpBC,OAAgB,GAAG,SAAnBA,OAAmB,CAACX,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,IAArD;AAAA;IAEnBE,QAAiB,GAAG,SAApBA,QAAoB,CAACZ,MAAD;AAAA,SAC/BA,MAAM,KAAK,QAAX,IAAwB,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GADvD;AAAA;IAGpBG,UAAmB,GAAG,SAAtBA,UAAsB,CAACb,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,KAAK,2BAA3C;AAAA;IAEtBc,WAAoB,GAAG,SAAvBA,WAAuB,CAACd,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoB,CAAC,iBAAD,EAAoB,aAApB,EAAmCC,QAAnC,CAA4CD,MAA5C,CAAhC;AAAA;IAEvBe,0BAAmC,GAAG,SAAtCA,0BAAsC,CAACf,MAAD;AAAA,SACjD,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GADb;AAAA;;;;;;;;;;;;"}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
6
  var _typeof = require('@babel/runtime/helpers/typeof');
7
+ var react = require('react');
7
8
  var validation_errorTemplates = require('./errorTemplates.js');
8
9
  var validation_typescriptGuards = require('./typescriptGuards.js');
9
10
  var validation_typescriptParsers = require('./typescriptParsers.js');
@@ -19,6 +20,12 @@ var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
19
20
  // This functions will validate something from the data
20
21
  // and optionally recursively apply `validateValueWithFormat`
21
22
  // in smaller parts
23
+ var validateUndefined = function validateUndefined(schemaName, key, value, format) {
24
+ if (value !== undefined) {
25
+ validation_errorTemplates.throwTypeError(schemaName, key, value, format);
26
+ }
27
+ };
28
+
22
29
  var validatePrimitiveType = function validatePrimitiveType(schemaName, key, value, format) {
23
30
  if (_typeof__default['default'](value) !== format) {
24
31
  validation_errorTemplates.throwTypeError(schemaName, key, value, format);
@@ -31,7 +38,7 @@ var validateString = function validateString(schemaName, key, value, format) {
31
38
  }
32
39
  };
33
40
 
34
- var validateArray = function validateArray(schemaName, key, value, format) {
41
+ var validateArray = function validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
35
42
  // Check that we have an array
36
43
  if (!Array.isArray(value)) {
37
44
  validation_errorTemplates.throwTypeError(schemaName, key, value, format);
@@ -39,11 +46,11 @@ var validateArray = function validateArray(schemaName, key, value, format) {
39
46
 
40
47
 
41
48
  value.forEach(function (val, index) {
42
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2));
49
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
43
50
  });
44
51
  };
45
52
 
46
- var validateObject = function validateObject(schemaName, key, value, format) {
53
+ var validateObject = function validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
47
54
  // Check that we have an object
48
55
  if (_typeof__default['default'](value) !== 'object' || Array.isArray(value)) {
49
56
  validation_errorTemplates.throwTypeError(schemaName, key, value, format);
@@ -66,17 +73,17 @@ var validateObject = function validateObject(schemaName, key, value, format) {
66
73
  }
67
74
 
68
75
  if (trueKey in value) {
69
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue);
76
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
70
77
  }
71
78
  });
72
79
  };
73
80
 
74
- var validateUnion = function validateUnion(schemaName, key, value, format) {
81
+ var validateUnion = function validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
75
82
  var possibilities = format.split(' | ');
76
83
  var errors = [];
77
84
  possibilities.forEach(function (possibility) {
78
85
  try {
79
- validateValueWithFormat(schemaName, key, value, possibility);
86
+ validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
80
87
  } catch (e) {
81
88
  errors.push(e);
82
89
  }
@@ -103,25 +110,38 @@ var validateJSXorNode = function validateJSXorNode(schemaName, key, value, forma
103
110
  // =============================================================================
104
111
 
105
112
 
106
- var validateValueWithFormat = function validateValueWithFormat(schemaName, key, value, format) {
107
- if (validation_typescriptGuards.isPrimitiveType(format)) {
113
+ var validateValueWithFormat = function validateValueWithFormat(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
114
+ nextValidationsMemo[value] = format;
115
+
116
+ if (value in validationsMemo) {
117
+ // We already validated this value on this format
118
+ return;
119
+ }
120
+
121
+ if (validation_typescriptGuards.isUndefined(format)) {
122
+ validateUndefined(schemaName, key, value, format);
123
+ } else if (validation_typescriptGuards.isPrimitiveType(format)) {
108
124
  validatePrimitiveType(schemaName, key, value, format);
109
125
  } else if (validation_typescriptGuards.isUnion(format)) {
110
- validateUnion(schemaName, key, value, format);
126
+ validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
111
127
  } else if (validation_typescriptGuards.isString(format)) {
112
128
  validateString(schemaName, key, value, format);
113
129
  } else if (validation_typescriptGuards.isArray(format)) {
114
- validateArray(schemaName, key, value, format);
130
+ validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
115
131
  } else if (validation_typescriptGuards.isObject(format)) {
116
- validateObject(schemaName, key, value, format);
132
+ validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
117
133
  } else if (validation_typescriptGuards.isFunction(format)) {
118
134
  validateFunction(schemaName, key, value, format);
119
135
  } else if (validation_typescriptGuards.isJSXorNode(format)) {
120
136
  validateJSXorNode(schemaName, key, value, format);
137
+ } else if (validation_typescriptGuards.isSomethingWithParenthesis(format)) {
138
+ validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
121
139
  }
122
140
  };
123
141
 
124
- var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(props, schema) {
142
+ var validateTypescriptPropTypesImplementation = function validateTypescriptPropTypesImplementation(props, schema) {
143
+ var validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
144
+ var nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
125
145
  var properties = schema.properties,
126
146
  schemaName = schema.name;
127
147
  properties.forEach(function (property) {
@@ -133,11 +153,24 @@ var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(pro
133
153
  validation_errorTemplates.throwRequiredError(schema.name, name);
134
154
  }
135
155
 
136
- if (name in props) {
137
- validateValueWithFormat(schemaName, name, props[name], format);
156
+ if (name in props && (props[name] !== undefined || required)) {
157
+ validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
138
158
  }
139
159
  });
140
160
  };
161
+ var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(props, schema) {
162
+ var _useState = react.useState({}),
163
+ _useState2 = _slicedToArray__default['default'](_useState, 2),
164
+ validationsMemo = _useState2[0],
165
+ setValidationsMemo = _useState2[1];
166
+
167
+ react.useMemo(function () {
168
+ var nextValidationsMemo = {};
169
+ validateTypescriptPropTypesImplementation(props, schema, validationsMemo, nextValidationsMemo);
170
+ setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
171
+ }, [props]);
172
+ };
141
173
 
142
174
  exports.useValidateTypescriptPropTypes = useValidateTypescriptPropTypes;
175
+ exports.validateTypescriptPropTypesImplementation = validateTypescriptPropTypesImplementation;
143
176
  //# sourceMappingURL=typescriptValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typescriptValidator.js","sources":["../../../src/validation/typescriptValidator.ts"],"sourcesContent":["/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { PropsWithChildren } from 'react';\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\nimport { isArray, isFunction, isJSXorNode, isObject, isPrimitiveType, isString, isUnion } from './typescriptGuards';\nimport { typescriptObjectParser } from './typescriptParsers';\n\ninterface TypescriptSchema {\n description: string;\n name: string;\n properties: { name: string; description: string; defaultValue?: unknown; format: string; required?: boolean }[];\n}\n\ntype validatorFn = (schemaName: string, key: string, value: unknown, format: string) => 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 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) => {\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 validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2));\n });\n};\n\nconst validateObject: validatorFn = (schemaName, key, value, format) => {\n // Check that we have an object\n if (typeof value !== 'object' || Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\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 as Record<string, unknown>))) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in (value as Record<string, unknown>)) {\n validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue);\n }\n });\n};\n\nconst validateUnion: validatorFn = (schemaName, key, value, format) => {\n const possibilities = format.split(' | ');\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n validateValueWithFormat(schemaName, key, value, possibility);\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\nconst validateJSXorNode: validatorFn = (schemaName, key, value, format) => {\n if (format === 'JSX.Element' && (typeof value !== 'object' || !('$$typeof' in value))) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: validatorFn = (schemaName, key, value, format) => {\n if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format);\n }\n};\n\nexport const useValidateTypescriptPropTypes = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptSchema,\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required } = property;\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (name in props) {\n validateValueWithFormat(schemaName, name, props[name], format);\n }\n });\n};\n"],"names":["validatePrimitiveType","schemaName","key","value","format","_typeof","throwTypeError","validateString","slice","validateArray","Array","isArray","forEach","val","index","validateValueWithFormat","validateObject","keyValuePairs","typescriptObjectParser","objectKey","objectValue","trueKey","throwRequiredError","validateUnion","possibilities","split","errors","possibility","e","push","length","validateFunction","validateJSXorNode","isPrimitiveType","isUnion","isString","isObject","isFunction","isJSXorNode","useValidateTypescriptPropTypes","props","schema","properties","name","property","required"],"mappings":";;;;;;;;;;;;;;;AAeA;AACA;AACA;AAEA;AACA;AACA;AAEA,IAAMA,qBAAkC,GAAG,SAArCA,qBAAqC,CAACC,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AAC7E,MAAIC,4BAAOF,KAAP,MAAiBC,MAArB,EAA6B;AAC3BE,IAAAA,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAMA,IAAMG,cAA2B,GAAG,SAA9BA,cAA8B,CAACN,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACtE,MAAID,KAAK,KAAKC,MAAM,CAACI,KAAP,CAAa,CAAb,EAAgB,CAAC,CAAjB,CAAd,EAAmC;AACjCF,IAAAA,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAMA,IAAMK,aAA0B,GAAG,SAA7BA,aAA6B,CAACR,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACrE;AACA,MAAI,CAACM,KAAK,CAACC,OAAN,CAAcR,KAAd,CAAL,EAA2B;AACzBG,IAAAA,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD,GAJoE;;;AAOpED,EAAAA,KAAD,CAAqBS,OAArB,CAA6B,UAACC,GAAD,EAAMC,KAAN,EAAgB;AAC3CC,IAAAA,uBAAuB,CAACd,UAAD,YAAgBC,GAAhB,cAAuBY,KAAvB,QAAiCD,GAAjC,EAAsCT,MAAM,CAACI,KAAP,CAAa,CAAb,EAAgB,CAAC,CAAjB,CAAtC,CAAvB;AACD,GAFD;AAGD,CAVD;;AAYA,IAAMQ,cAA2B,GAAG,SAA9BA,cAA8B,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,MAAd;AAAA,QAAsByC,QAAtB,GAAmCD,QAAnC,CAAsBC,QAAtB;;AAEA,QAAIA,QAAQ,IAAI,EAAEF,IAAI,IAAIH,KAAV,CAAhB,EAAkC;AAChClB,MAAAA,4CAAkB,CAACmB,MAAM,CAACE,IAAR,EAAcA,IAAd,CAAlB;AACD;;AAED,QAAIA,IAAI,IAAIH,KAAZ,EAAmB;AACjBzB,MAAAA,uBAAuB,CAACd,UAAD,EAAa0C,IAAb,EAAmBH,KAAK,CAACG,IAAD,CAAxB,EAAgCvC,MAAhC,CAAvB;AACD;AACF,GAVD;AAWD;;;;"}
1
+ {"version":3,"file":"typescriptValidator.js","sources":["../../../src/validation/typescriptValidator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { PropsWithChildren, useMemo, useState } from 'react';\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n} from './typescriptGuards';\nimport { typescriptObjectParser } from './typescriptParsers';\n\ninterface TypescriptSchema {\n description: string;\n name: string;\n properties: { name: string; description: string; defaultValue?: unknown; format: string; required?: boolean }[];\n}\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) {\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 validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: validatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an object\n if (typeof value !== 'object' || Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\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 as Record<string, unknown>))) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in (value as Record<string, unknown>)) {\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(' | ');\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\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\nconst validateJSXorNode: validatorFn = (schemaName, key, value, format) => {\n if (format === 'JSX.Element' && (typeof value !== 'object' || !('$$typeof' in value))) {\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 (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 (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: TypescriptSchema,\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 } = property;\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (name in props && (props[name] !== undefined || required)) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\nexport const useValidateTypescriptPropTypes = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptSchema,\n): void => {\n const [validationsMemo, setValidationsMemo] = useState({});\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, schema, validationsMemo, nextValidationsMemo);\n\n setValidationsMemo(nextValidationsMemo);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],"names":["validateUndefined","schemaName","key","value","format","undefined","throwTypeError","validatePrimitiveType","_typeof","validateString","slice","validateArray","validationsMemo","nextValidationsMemo","Array","isArray","forEach","val","index","validateValueWithFormat","validateObject","keyValuePairs","typescriptObjectParser","objectKey","objectValue","trueKey","throwRequiredError","validateUnion","possibilities","split","errors","possibility","e","push","length","validateFunction","validateJSXorNode","isUndefined","isPrimitiveType","isUnion","isString","isObject","isFunction","isJSXorNode","isSomethingWithParenthesis","validateTypescriptPropTypesImplementation","props","schema","properties","name","property","required","useValidateTypescriptPropTypes","useState","setValidationsMemo","useMemo"],"mappings":";;;;;;;;;;;;;;;;AAiCA;AACA;AACA;AAEA;AACA;AACA;AAEA,IAAMA,iBAA8B,GAAG,SAAjCA,iBAAiC,CAACC,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACzE,MAAID,KAAK,KAAKE,SAAd,EAAyB;AACvBC,IAAAA,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAKA,IAAMG,qBAAkC,GAAG,SAArCA,qBAAqC,CAACN,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AAC7E,MAAII,4BAAOL,KAAP,MAAiBC,MAArB,EAA6B;AAC3BE,IAAAA,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAMA,IAAMK,cAA2B,GAAG,SAA9BA,cAA8B,CAACR,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACtE,MAAID,KAAK,KAAKC,MAAM,CA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,kBAAkB,CAACzC,mBAAD,CAAlB,CALY;AAOb,GAPM,EAOJ,CAACiC,KAAD,CAPI,CAAP;AAQD;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import { useRef, useEffect } from 'react';
2
+ import { useRef } from 'react';
3
3
  import deepequal from 'fast-deep-equal/react';
4
4
 
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
@@ -17,11 +17,7 @@ var useMemoCompare = function useMemoCompare(next, compare) {
17
17
  // We only update if not equal so that this hook continues to return
18
18
  // the same old value if compare keeps returning true.
19
19
 
20
- useEffect(function () {
21
- if (!isEqual) {
22
- previousRef.current = next;
23
- }
24
- }); // Finally, if equal then return the previous value
20
+ if (!isEqual) previousRef.current = next; // Finally, if equal then return the previous value
25
21
 
26
22
  return isEqual ? previous : next;
27
23
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1 +1 @@
1
- {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport deepequal from 'fast-deep-equal/react';\n\n// Hook\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useMemoCompare = <T = any>(next: T, compare: (prevToCompare: T, nextToCompare: T) => boolean): T => {\n // Ref for storing previous value\n const previousRef = useRef<T>();\n const previous = previousRef.current;\n // Pass previous and next value to compare function\n // to determine whether to consider them equal.\n const isEqual = compare(previous, next);\n // If not equal update previousRef to next value.\n // We only update if not equal so that this hook continues to return\n // the same old value if compare keeps returning true.\n useEffect(() => {\n if (!isEqual) {\n previousRef.current = next;\n }\n });\n // Finally, if equal then return the previous value\n return isEqual ? previous : next;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useMemoMergePropsWithDefault = <T = Record<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useEffect","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,MAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACAO,EAAAA,SAAS,CAAC,YAAM;AACd,QAAI,CAACD,OAAL,EAAc;AACZJ,MAAAA,WAAW,CAACG,OAAZ,GAAsBL,IAAtB;AACD;AACF,GAJQ,CAAT,CAVwG;;AAgBxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAjBD;;;IAoBaQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfT,OACe,uEADLU,SACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOV,cAAc,CAAaa,WAAb,EAA0BX,OAA1B,CAArB;AACD;;;;"}
1
+ {"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport deepequal from 'fast-deep-equal/react';\n\n// Hook\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useMemoCompare = <T = any>(next: T, compare: (prevToCompare: T, nextToCompare: T) => boolean): T => {\n // Ref for storing previous value\n const previousRef = useRef<T>();\n const previous = previousRef.current;\n // Pass previous and next value to compare function\n // to determine whether to consider them equal.\n const isEqual = compare(previous, next);\n // If not equal update previousRef to next value.\n // We only update if not equal so that this hook continues to return\n // the same old value if compare keeps returning true.\n if (!isEqual) previousRef.current = next;\n // Finally, if equal then return the previous value\n return isEqual ? previous : next;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useMemoMergePropsWithDefault = <T = Record<any, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): Partial<T> => {\n const mergedProps = { ...defaultProps, ...props };\n\n return useMemoCompare<Partial<T>>(mergedProps, compare);\n};\n"],"names":["useMemoCompare","next","compare","previousRef","useRef","previous","current","isEqual","useMemoMergePropsWithDefault","props","defaultProps","deepequal","mergedProps"],"mappings":";;;;;;;AAIA;;AACA,IAAMA,cAAc,GAAG,SAAjBA,cAAiB,CAAUC,IAAV,EAAmBC,OAAnB,EAAmF;AACxG;AACA,MAAMC,WAAW,GAAGC,MAAM,EAA1B;AACA,MAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;AAKxG;;AACA,MAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;AAQxG;AACA;;AACA,MAAI,CAACM,OAAL,EAAcJ,WAAW,CAACG,OAAZ,GAAsBL,IAAtB,CAV0F;;AAYxG,SAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAbD;;;IAgBaO,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;AAAA,MADfR,OACe,uEADLS,SACK;;AACf,MAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;AAEA,SAAOT,cAAc,CAAaY,WAAb,EAA0BV,OAA1B,CAArB;AACD;;;;"}
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { useMemoMergePropsWithDefault } from './defaultProps/useMemoMergePropsWithDefault.js';
2
2
  export { useValidatePropTypes } from './validation/validator.js';
3
3
  export { throwRequiredError, throwTypeError } from './validation/errorTemplates.js';
4
- export { useValidateTypescriptPropTypes } from './validation/typescriptValidator.js';
4
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './validation/typescriptValidator.js';
5
5
  import '@babel/runtime/helpers/esm/defineProperty';
6
6
  import 'react';
7
7
  import 'fast-deep-equal/react';
@@ -1,8 +1,9 @@
1
1
  export { useValidatePropTypes } from './validator.js';
2
2
  export { throwRequiredError, throwTypeError } from './errorTemplates.js';
3
- export { useValidateTypescriptPropTypes } from './typescriptValidator.js';
3
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './typescriptValidator.js';
4
4
  import '@babel/runtime/helpers/esm/typeof';
5
5
  import '@babel/runtime/helpers/esm/slicedToArray';
6
+ import 'react';
6
7
  import './typescriptGuards.js';
7
8
  import './typescriptParsers.js';
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -1,11 +1,14 @@
1
1
  var isPrimitiveType = function isPrimitiveType(format) {
2
2
  return ['string', 'number', 'boolean'].includes(format);
3
3
  };
4
+ var isUndefined = function isUndefined(format) {
5
+ return format === '"undefined"';
6
+ };
4
7
  var isUnion = function isUnion(format) {
5
8
  var depth = 0;
6
9
  var satisfies = false;
7
10
  format.split('').forEach(function (char) {
8
- if (char === '{') depth += 1;else if (char === '}') depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
11
+ if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
9
12
  });
10
13
  return satisfies;
11
14
  };
@@ -19,11 +22,14 @@ var isObject = function isObject(format) {
19
22
  return format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
20
23
  };
21
24
  var isFunction = function isFunction(format) {
22
- return !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
25
+ return !isUnion(format) && format === '((...args: any[]) => any)';
23
26
  };
24
27
  var isJSXorNode = function isJSXorNode(format) {
25
28
  return !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
26
29
  };
30
+ var isSomethingWithParenthesis = function isSomethingWithParenthesis(format) {
31
+ return !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
32
+ };
27
33
 
28
- export { isArray, isFunction, isJSXorNode, isObject, isPrimitiveType, isString, isUnion };
34
+ export { isArray, isFunction, isJSXorNode, isObject, isPrimitiveType, isSomethingWithParenthesis, isString, isUndefined, isUnion };
29
35
  //# sourceMappingURL=typescriptGuards.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typescriptGuards.js","sources":["../../../src/validation/typescriptGuards.ts"],"sourcesContent":["type guardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: guardFn = (format) => ['string', 'number', 'boolean'].includes(format);\n\nexport const isUnion: guardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (char === '{') depth += 1;\n else if (char === '}') depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: guardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: guardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObject: guardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: guardFn = (format) => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n\nexport const isJSXorNode: guardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n"],"names":["isPrimitiveType","format","includes","isUnion","depth","satisfies","split","forEach","char","isString","slice","isArray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,SAAtBA,UAAsB,CAACZ,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACS,KAAP,CAAa,CAAC,CAAd,MAAqB,GAA1E;AAAA;IAEtBI,WAAoB,GAAG,SAAvBA,WAAuB,CAACb,MAAD;AAAA,SAAY,CAACE,OAAO,CAACF,MAAD,CAAR,IAAoB,CAAC,iBAAD,EAAoB,aAApB,EAAmCC,QAAnC,CAA4CD,MAA5C,CAAhC;AAAA;;;;"}
1
+ {"version":3,"file":"typescriptGuards.js","sources":["../../../src/validation/typescriptGuards.ts"],"sourcesContent":["type guardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: guardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: guardFn = (format) => format === '\"undefined\"';\nexport const isUnion: guardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: guardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: guardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObject: guardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: guardFn = (format) => !isUnion(format) && format === '((...args: any[]) => any)';\n\nexport const isJSXorNode: guardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isSomethingWithParenthesis: guardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n"],"names":["isPrimitiveType","format","includes","isUndefined","isUnion","depth","satisfies","split","forEach","char","isString","slice","isArray","isObject","isFunction","isJSXorNode","isSomethingWithParenthesis"],"mappings":"IAEaA,eAAwB,GAAG,SAA3B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CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GADvD;AAAA;IAGpBG,UAAmB,GAAG,SAAtBA,UAAsB,CAACb,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,KAAK,2BAA3C;AAAA;IAEtBc,WAAoB,GAAG,SAAvBA,WAAuB,CAACd,MAAD;AAAA,SAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoB,CAAC,iBAAD,EAAoB,aAApB,EAAmCC,QAAnC,CAA4CD,MAA5C,CAAhC;AAAA;IAEvBe,0BAAmC,GAAG,SAAtCA,0BAAsC,CAACf,MAAD;AAAA,SACjD,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GADb;AAAA;;;;"}
@@ -1,7 +1,8 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
2
2
  import _typeof from '@babel/runtime/helpers/esm/typeof';
3
+ import { useState, useMemo } from 'react';
3
4
  import { throwRequiredError, throwTypeError } from './errorTemplates.js';
4
- import { isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode } from './typescriptGuards.js';
5
+ import { isUndefined, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
5
6
  import { typescriptObjectParser } from './typescriptParsers.js';
6
7
 
7
8
  // =============================================================================
@@ -10,6 +11,12 @@ import { typescriptObjectParser } from './typescriptParsers.js';
10
11
  // This functions will validate something from the data
11
12
  // and optionally recursively apply `validateValueWithFormat`
12
13
  // in smaller parts
14
+ var validateUndefined = function validateUndefined(schemaName, key, value, format) {
15
+ if (value !== undefined) {
16
+ throwTypeError(schemaName, key, value, format);
17
+ }
18
+ };
19
+
13
20
  var validatePrimitiveType = function validatePrimitiveType(schemaName, key, value, format) {
14
21
  if (_typeof(value) !== format) {
15
22
  throwTypeError(schemaName, key, value, format);
@@ -22,7 +29,7 @@ var validateString = function validateString(schemaName, key, value, format) {
22
29
  }
23
30
  };
24
31
 
25
- var validateArray = function validateArray(schemaName, key, value, format) {
32
+ var validateArray = function validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
26
33
  // Check that we have an array
27
34
  if (!Array.isArray(value)) {
28
35
  throwTypeError(schemaName, key, value, format);
@@ -30,11 +37,11 @@ var validateArray = function validateArray(schemaName, key, value, format) {
30
37
 
31
38
 
32
39
  value.forEach(function (val, index) {
33
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2));
40
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
34
41
  });
35
42
  };
36
43
 
37
- var validateObject = function validateObject(schemaName, key, value, format) {
44
+ var validateObject = function validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
38
45
  // Check that we have an object
39
46
  if (_typeof(value) !== 'object' || Array.isArray(value)) {
40
47
  throwTypeError(schemaName, key, value, format);
@@ -57,17 +64,17 @@ var validateObject = function validateObject(schemaName, key, value, format) {
57
64
  }
58
65
 
59
66
  if (trueKey in value) {
60
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue);
67
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
61
68
  }
62
69
  });
63
70
  };
64
71
 
65
- var validateUnion = function validateUnion(schemaName, key, value, format) {
72
+ var validateUnion = function validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
66
73
  var possibilities = format.split(' | ');
67
74
  var errors = [];
68
75
  possibilities.forEach(function (possibility) {
69
76
  try {
70
- validateValueWithFormat(schemaName, key, value, possibility);
77
+ validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
71
78
  } catch (e) {
72
79
  errors.push(e);
73
80
  }
@@ -94,25 +101,38 @@ var validateJSXorNode = function validateJSXorNode(schemaName, key, value, forma
94
101
  // =============================================================================
95
102
 
96
103
 
97
- var validateValueWithFormat = function validateValueWithFormat(schemaName, key, value, format) {
98
- if (isPrimitiveType(format)) {
104
+ var validateValueWithFormat = function validateValueWithFormat(schemaName, key, value, format, validationsMemo, nextValidationsMemo) {
105
+ nextValidationsMemo[value] = format;
106
+
107
+ if (value in validationsMemo) {
108
+ // We already validated this value on this format
109
+ return;
110
+ }
111
+
112
+ if (isUndefined(format)) {
113
+ validateUndefined(schemaName, key, value, format);
114
+ } else if (isPrimitiveType(format)) {
99
115
  validatePrimitiveType(schemaName, key, value, format);
100
116
  } else if (isUnion(format)) {
101
- validateUnion(schemaName, key, value, format);
117
+ validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
102
118
  } else if (isString(format)) {
103
119
  validateString(schemaName, key, value, format);
104
120
  } else if (isArray(format)) {
105
- validateArray(schemaName, key, value, format);
121
+ validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
106
122
  } else if (isObject(format)) {
107
- validateObject(schemaName, key, value, format);
123
+ validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
108
124
  } else if (isFunction(format)) {
109
125
  validateFunction(schemaName, key, value, format);
110
126
  } else if (isJSXorNode(format)) {
111
127
  validateJSXorNode(schemaName, key, value, format);
128
+ } else if (isSomethingWithParenthesis(format)) {
129
+ validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
112
130
  }
113
131
  };
114
132
 
115
- var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(props, schema) {
133
+ var validateTypescriptPropTypesImplementation = function validateTypescriptPropTypesImplementation(props, schema) {
134
+ var validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
135
+ var nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
116
136
  var properties = schema.properties,
117
137
  schemaName = schema.name;
118
138
  properties.forEach(function (property) {
@@ -124,11 +144,23 @@ var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(pro
124
144
  throwRequiredError(schema.name, name);
125
145
  }
126
146
 
127
- if (name in props) {
128
- validateValueWithFormat(schemaName, name, props[name], format);
147
+ if (name in props && (props[name] !== undefined || required)) {
148
+ validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
129
149
  }
130
150
  });
131
151
  };
152
+ var useValidateTypescriptPropTypes = function useValidateTypescriptPropTypes(props, schema) {
153
+ var _useState = useState({}),
154
+ _useState2 = _slicedToArray(_useState, 2),
155
+ validationsMemo = _useState2[0],
156
+ setValidationsMemo = _useState2[1];
157
+
158
+ useMemo(function () {
159
+ var nextValidationsMemo = {};
160
+ validateTypescriptPropTypesImplementation(props, schema, validationsMemo, nextValidationsMemo);
161
+ setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
162
+ }, [props]);
163
+ };
132
164
 
133
- export { useValidateTypescriptPropTypes };
165
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
134
166
  //# sourceMappingURL=typescriptValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typescriptValidator.js","sources":["../../../src/validation/typescriptValidator.ts"],"sourcesContent":["/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { PropsWithChildren } from 'react';\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\nimport { isArray, isFunction, isJSXorNode, isObject, isPrimitiveType, isString, isUnion } from './typescriptGuards';\nimport { typescriptObjectParser } from './typescriptParsers';\n\ninterface TypescriptSchema {\n description: string;\n name: string;\n properties: { name: string; description: string; defaultValue?: unknown; format: string; required?: boolean }[];\n}\n\ntype validatorFn = (schemaName: string, key: string, value: unknown, format: string) => 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 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) => {\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 validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2));\n });\n};\n\nconst validateObject: validatorFn = (schemaName, key, value, format) => {\n // Check that we have an object\n if (typeof value !== 'object' || Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\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 as Record<string, unknown>))) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in (value as Record<string, unknown>)) {\n validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue);\n }\n });\n};\n\nconst validateUnion: validatorFn = (schemaName, key, value, format) => {\n const possibilities = format.split(' | ');\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n validateValueWithFormat(schemaName, key, value, possibility);\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\nconst validateJSXorNode: validatorFn = (schemaName, key, value, format) => {\n if (format === 'JSX.Element' && (typeof value !== 'object' || !('$$typeof' in value))) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: validatorFn = (schemaName, key, value, format) => {\n if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format);\n }\n};\n\nexport const useValidateTypescriptPropTypes = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptSchema,\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required } = property;\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (name in props) {\n validateValueWithFormat(schemaName, name, props[name], format);\n }\n });\n};\n"],"names":["validatePrimitiveType","schemaName","key","value","format","throwTypeError","validateString","slice","validateArray","Array","isArray","forEach","val","index","validateValueWithFormat","validateObject","keyValuePairs","typescriptObjectParser","objectKey","objectValue","trueKey","throwRequiredError","validateUnion","possibilities","split","errors","possibility","e","push","length","validateFunction","validateJSXorNode","isPrimitiveType","isUnion","isString","isObject","isFunction","isJSXorNode","useValidateTypescriptPropTypes","props","schema","properties","name","property","required"],"mappings":";;;;;;AAeA;AACA;AACA;AAEA;AACA;AACA;AAEA,IAAMA,qBAAkC,GAAG,SAArCA,qBAAqC,CAACC,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AAC7E,MAAI,QAAOD,KAAP,MAAiBC,MAArB,EAA6B;AAC3BC,IAAAA,cAAc,CAACJ,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;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"}
1
+ {"version":3,"file":"typescriptValidator.js","sources":["../../../src/validation/typescriptValidator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { PropsWithChildren, useMemo, useState } from 'react';\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n} from './typescriptGuards';\nimport { typescriptObjectParser } from './typescriptParsers';\n\ninterface TypescriptSchema {\n description: string;\n name: string;\n properties: { name: string; description: string; defaultValue?: unknown; format: string; required?: boolean }[];\n}\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) {\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 validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\n\nconst validateObject: validatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an object\n if (typeof value !== 'object' || Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\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 as Record<string, unknown>))) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in (value as Record<string, unknown>)) {\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(' | ');\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\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\nconst validateJSXorNode: validatorFn = (schemaName, key, value, format) => {\n if (format === 'JSX.Element' && (typeof value !== 'object' || !('$$typeof' in value))) {\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 (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 (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: TypescriptSchema,\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 } = property;\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (name in props && (props[name] !== undefined || required)) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\nexport const useValidateTypescriptPropTypes = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptSchema,\n): void => {\n const [validationsMemo, setValidationsMemo] = useState({});\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, schema, validationsMemo, nextValidationsMemo);\n\n setValidationsMemo(nextValidationsMemo);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],"names":["validateUndefined","schemaName","key","value","format","undefined","throwTypeError","validatePrimitiveType","validateString","slice","validateArray","validationsMemo","nextValidationsMemo","Array","isArray","forEach","val","index","validateValueWithFormat","validateObject","keyValuePairs","typescriptObjectParser","objectKey","objectValue","trueKey","throwRequiredError","validateUnion","possibilities","split","errors","possibility","e","push","length","validateFunction","validateJSXorNode","isUndefined","isPrimitiveType","isUnion","isString","isObject","isFunction","isJSXorNode","isSomethingWithParenthesis","validateTypescriptPropTypesImplementation","props","schema","properties","name","property","required","useValidateTypescriptPropTypes","useState","setValidationsMemo","useMemo"],"mappings":";;;;;;;AAiCA;AACA;AACA;AAEA;AACA;AACA;AAEA,IAAMA,iBAA8B,GAAG,SAAjCA,iBAAiC,CAACC,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACzE,MAAID,KAAK,KAAKE,SAAd,EAAyB;AACvBC,IAAAA,cAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAKA,IAAMG,qBAAkC,GAAG,SAArCA,qBAAqC,CAACN,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AAC7E,MAAI,QAAOD,KAAP,MAAiBC,MAArB,EAA6B;AAC3BE,IAAAA,cAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAMA,IAAMI,cAA2B,GAAG,SAA9BA,cAA8B,CAACP,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;AACtE,MAAID,KAAK,KAAKC,MAAM,CAACK,KAAP,CAAa,CAAb,EAAgB,CAAC,CAAjB,CAAd,EAAmC;AACjCH,IAAAA,cAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;AACD;AACF,CAJD;;AAMA,IAAMM,aAA0B,GAAG,SAA7BA,aAA6B,CAACT,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAiCO,eAAjC,EAAkDC,mBAAlD,EAA0E;AAC3G;AACA,MAAI,CAACC,KAAK,CAACC,OAAN,CAAcX,KAAd,CAAL,EAA2B;AACzBG,IAAAA,cAAc,CAACL,UAAD,EA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B,GAAmCD,QAAnC,CAAsBC,QAAtB;;AAEA,QAAIA,QAAQ,IAAI,EAAEF,IAAI,IAAIH,KAAV,CAAhB,EAAkC;AAChCpB,MAAAA,kBAAkB,CAACqB,MAAM,CAACE,IAAR,EAAcA,IAAd,CAAlB;AACD;;AAED,QAAIA,IAAI,IAAIH,KAAR,KAAkBA,KAAK,CAACG,IAAD,CAAL,KAAgB3C,SAAhB,IAA6B6C,QAA/C,CAAJ,EAA8D;AAC5DhC,MAAAA,uBAAuB,CAACjB,UAAD,EAAa+C,IAAb,EAAmBH,KAAK,CAACG,IAAD,CAAxB,EAAgC5C,MAAhC,EAAwCO,eAAxC,EAAyDC,mBAAzD,CAAvB;AACD;AACF,GAVD;AAWD;IAEYuC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAC5CN,KAD4C,EAE5CC,MAF4C,EAGnC;AACT,kBAA8CM,QAAQ,CAAC,EAAD,CAAtD;AAAA;AAAA,MAAOzC,eAAP;AAAA,MAAwB0C,kBAAxB;;AAEAC,EAAAA,OAAO,CAAC,YAAM;AACZ,QAAM1C,mBAAmB,GAAG,EAA5B;AAEAgC,IAAAA,yCAAyC,CAACC,KAAD,EAAQC,MAAR,EAAgBnC,eAAhB,EAAiCC,mBAAjC,CAAzC;AAEAyC,IAAAA,kBAAkB,CAACzC,mBAAD,CAAlB,CALY;AAOb,GAPM,EAOJ,CAACiC,KAAD,CAPI,CAAP;AAQD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-props-helpers",
3
- "version": "1.55.0-next.4",
3
+ "version": "1.55.0-next.5",
4
4
  "license": "MIT",
5
5
  "description": "Ellie Mae - Dim Sum - Validation Helpers",
6
6
  "module": "esm/index.js",