@elliemae/ds-props-helpers 1.61.12 → 1.61.13
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/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +1 -1
- package/cjs/getProps/index.js.map +1 -1
- package/cjs/tests/test.schema.js.map +1 -1
- package/cjs/validation/errorTemplates.js.map +1 -1
- package/cjs/validation/typescriptGuards.js.map +1 -1
- package/cjs/validation/typescriptParsers.js.map +1 -1
- package/cjs/validation/typescriptValidator.js.map +1 -1
- package/cjs/validation/validator.js.map +1 -1
- package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +1 -1
- package/esm/getProps/index.js.map +1 -1
- package/esm/tests/test.schema.js.map +1 -1
- package/esm/validation/errorTemplates.js.map +1 -1
- package/esm/validation/typescriptGuards.js.map +1 -1
- package/esm/validation/typescriptParsers.js.map +1 -1
- package/esm/validation/typescriptValidator.js.map +1 -1
- package/esm/validation/validator.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { 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
|
|
1
|
+
{"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { 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;;EAExG,IAAMC,WAAW,GAAGC,YAAM,EAA1B;EACA,IAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;;;EAMxG,IAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;;;;EAUxG,IAAI,CAACM,OAAL,EAAcJ,WAAW,CAACG,OAAZ,GAAsBL,IAAtB,CAV0F;;EAYxG,OAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAbD;;;IAgBaO,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;EAAA,IADfR,OACe,uEADLS,6BACK;;EACf,IAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;EAEA,OAAOT,cAAc,CAAaY,WAAb,EAA0BV,OAA1B,CAArB;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/getProps/index.ts"],"sourcesContent":["export const getAriaProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('aria-')));\n\nexport const getDataProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('data-')));\n"],"names":["getAriaProps","props","Object","fromEntries","entries","filter","key","includes","getDataProps"],"mappings":";;;;;;;;;;IAAaA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/getProps/index.ts"],"sourcesContent":["export const getAriaProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('aria-')));\n\nexport const getDataProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('data-')));\n"],"names":["getAriaProps","props","Object","fromEntries","entries","filter","key","includes","getDataProps"],"mappings":";;;;;;;;;;IAAaA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;EAAA,OAC1BC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeH,KAAf,EAAsBI,MAAtB,CAA6B;IAAA;QAAEC,GAAF;;IAAA,OAAWA,GAAG,CAACC,QAAJ,CAAa,OAAb,CAAX;GAA7B,CAAnB,CAD0B;AAAA;IAGfC,YAAY,GAAG,SAAfA,YAAe,CAACP,KAAD;EAAA,OAC1BC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeH,KAAf,EAAsBI,MAAtB,CAA6B;IAAA;QAAEC,GAAF;;IAAA,OAAWA,GAAG,CAACC,QAAJ,CAAa,OAAb,CAAX;GAA7B,CAAnB,CAD0B;AAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.schema.js","sources":["../../../src/tests/test.schema.js"],"sourcesContent":["import { PropTypes, describe } from 'react-desc';\n\nconst TestSchema = {\n string: PropTypes.string.description('String'),\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n any: PropTypes.any.description('Any'),\n union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Union'),\n union2: PropTypes.oneOf(['A', 'B']).description('Union 2'),\n union3: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.shape({ string: PropTypes.string }),\n ]).description('Union 3'),\n array: PropTypes.arrayOf(PropTypes.string).description('Array'),\n object: PropTypes.object.description('Object'),\n shape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n anotherShape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n }).description('Another shape'),\n }).description('Shape'),\n function: PropTypes.func.description('Function'),\n jsx: PropTypes.element.description('JSX'),\n node: PropTypes.node.description('Node'),\n};\n\nconst TestComponent = () => null;\n\nconst TestComponentWithSchema = describe(TestComponent).description('Test Component');\n\nTestComponentWithSchema.propTypes = TestSchema;\n\nexport const TypescriptSchema = TestComponentWithSchema.toTypescript();\n"],"names":["TestSchema","string","PropTypes","description","number","boolean","bool","any","union","oneOfType","union2","oneOf","union3","arrayOf","shape","array","object","isRequired","anotherShape","function","func","jsx","element","node","TestComponent","TestComponentWithSchema","describe","propTypes","TypescriptSchema","toTypescript"],"mappings":";;;;;;AAEA,IAAMA,UAAU,GAAG;
|
|
1
|
+
{"version":3,"file":"test.schema.js","sources":["../../../src/tests/test.schema.js"],"sourcesContent":["import { PropTypes, describe } from 'react-desc';\n\nconst TestSchema = {\n string: PropTypes.string.description('String'),\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n any: PropTypes.any.description('Any'),\n union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Union'),\n union2: PropTypes.oneOf(['A', 'B']).description('Union 2'),\n union3: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.shape({ string: PropTypes.string }),\n ]).description('Union 3'),\n array: PropTypes.arrayOf(PropTypes.string).description('Array'),\n object: PropTypes.object.description('Object'),\n shape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n anotherShape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n }).description('Another shape'),\n }).description('Shape'),\n function: PropTypes.func.description('Function'),\n jsx: PropTypes.element.description('JSX'),\n node: PropTypes.node.description('Node'),\n};\n\nconst TestComponent = () => null;\n\nconst TestComponentWithSchema = describe(TestComponent).description('Test Component');\n\nTestComponentWithSchema.propTypes = TestSchema;\n\nexport const TypescriptSchema = TestComponentWithSchema.toTypescript();\n"],"names":["TestSchema","string","PropTypes","description","number","boolean","bool","any","union","oneOfType","union2","oneOf","union3","arrayOf","shape","array","object","isRequired","anotherShape","function","func","jsx","element","node","TestComponent","TestComponentWithS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AACE,MAAV,CAAiBD,WAAjB,CAA6B,QAA7B,CAFa;IAGrBE,OAAO,EAAEH,mBAAS,CAACI,IAAV,CAAeH,WAAf,CAA2B,SAA3B,CAHY;IAIrBe,YAAY,EAAEhB,mBAAS,CAACY,KAAV,CAAgB;MAC5Bb,MAAM,EAAEC,mBAAS,CAACD,MAAV,CAAiBE,WAAjB,CAA6B,QAA7B,EAAuCc,UADnB;MAE5Bb,MAAM,EAAEF,mBAAS,CAACE,MAAV,CAAiBD,WAAjB,CAA6B,QAA7B,CAFoB;MAG5BE,OAAO,EAAEH,mBAAS,CAACI,IAAV,CAAeH,WAAf,CAA2B,SAA3B;KAHG,EAIXA,WAJW,CAIC,eAJD;GAJT,EASJA,WATI,CASQ,OATR,CAdU;EAwBjBgB,QAAQ,EAAEjB,mBAAS,CAACkB,IAAV,CAAejB,WAAf,CAA2B,UAA3B,CAxBO;EAyBjBkB,GAAG,EAAEnB,mBAAS,CAACoB,OAAV,CAAkBnB,WAAlB,CAA8B,KAA9B,CAzBY;EA0BjBoB,IAAI,EAAErB,mBAAS,CAACqB,IAAV,CAAepB,WAAf,CAA2B,MAA3B;AA1BW,CAAnB;;AA6BA,IAAMqB,aAAa,GAAG,SAAhBA,aAAgB;EAAA,OAAM,IAAN;AAAA,CAAtB;;AAEA,IAAMC,uBAAuB,GAAGC,kBAAQ,CAACF,aAAD,CAAR,CAAwBrB,WAAxB,CAAoC,gBAApC,CAAhC;AAEAsB,uBAAuB,CAACE,SAAxB,GAAoC3B,UAApC;IAEa4B,gBAAgB,GAAGH,uBAAuB,CAACI,YAAxB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorTemplates.js","sources":["../../../src/validation/errorTemplates.ts"],"sourcesContent":["/* eslint-disable max-params */\nexport const throwTypeError = (\n componentName: string,\n validPropKey: string,\n invalidProp: unknown,\n validFormat: string,\n): void => {\n throw new Error(\n `${componentName}:: You are trying to pass a not valid \"${validPropKey}\" property, \n please provide a valid type.\n\n Received: ${invalidProp} (${typeof invalidProp})\n Expected: (${validFormat.replace('\\n', ' or ')})\n `,\n );\n};\n\nexport const throwRequiredError = (componentName: string, validPropKey: string): void => {\n throw new Error(\n `${componentName}:: Please provide a/an \"${validPropKey}\" property to use this component. \n This property is required.\n `,\n );\n};\n"],"names":["throwTypeError","componentName","validPropKey","invalidProp","validFormat","Error","replace","throwRequiredError"],"mappings":";;;;;;;;;;AAAA;IACaA,cAAc,GAAG,SAAjBA,cAAiB,CAC5BC,aAD4B,EAE5BC,YAF4B,EAG5BC,WAH4B,EAI5BC,WAJ4B,EAKnB;
|
|
1
|
+
{"version":3,"file":"errorTemplates.js","sources":["../../../src/validation/errorTemplates.ts"],"sourcesContent":["/* eslint-disable max-params */\nexport const throwTypeError = (\n componentName: string,\n validPropKey: string,\n invalidProp: unknown,\n validFormat: string,\n): void => {\n throw new Error(\n `${componentName}:: You are trying to pass a not valid \"${validPropKey}\" property, \n please provide a valid type.\n\n Received: ${invalidProp} (${typeof invalidProp})\n Expected: (${validFormat.replace('\\n', ' or ')})\n `,\n );\n};\n\nexport const throwRequiredError = (componentName: string, validPropKey: string): void => {\n throw new Error(\n `${componentName}:: Please provide a/an \"${validPropKey}\" property to use this component. \n This property is required.\n `,\n );\n};\n"],"names":["throwTypeError","componentName","validPropKey","invalidProp","validFormat","Error","replace","throwRequiredError"],"mappings":";;;;;;;;;;AAAA;IACaA,cAAc,GAAG,SAAjBA,cAAiB,CAC5BC,aAD4B,EAE5BC,YAF4B,EAG5BC,WAH4B,EAI5BC,WAJ4B,EAKnB;EACT,MAAM,IAAIC,KAAJ,WACDJ,aADC,qDACsDC,YADtD,4EAIMC,WAJN,2CAI6BA,WAJ7B,8BAKOC,WAAW,CAACE,OAAZ,CAAoB,IAApB,EAA0B,MAA1B,CALP,WAAN;AAQD;IAEYC,kBAAkB,GAAG,SAArBA,kBAAqB,CAACN,aAAD,EAAwBC,YAAxB,EAAuD;EACvF,MAAM,IAAIG,KAAJ,WACDJ,aADC,sCACuCC,YADvC,8EAAN;AAKD;;;;;"}
|
|
@@ -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);\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;
|
|
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;EAAA,OAAY,CAAC,QAAD,EAAW,QAAX,EAAqB,SAArB,EAAgCC,QAAhC,CAAyCD,MAAzC,CAAZ;AAAA;IAC3BE,WAAoB,GAAG,SAAvBA,WAAuB,CAACF,MAAD;EAAA,OAAYA,MAAM,KAAK,aAAvB;AAAA;IACvBG,OAAgB,GAAG,SAAnBA,OAAmB,CAACH,MAAD,EAAY;EAC1C,IAAII,KAAK,GAAG,CAAZ;EACA,IAAIC,SAAS,GAAG,KAAhB;EACAL,MAAM,CAACM,KAAP,CAAa,EAAb,EAAiBC,OAAjB,CAAyB,UAACC,IAAD,EAAU;IACjC,IAAI,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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@@
|
|
|
1
|
-
{"version":3,"file":"typescriptParsers.js","sources":["../../../src/validation/typescriptParsers.ts"],"sourcesContent":["/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n"],"names":["typescriptObjectParser","format","keyValuePairs","lastKey","lastValue","shouldAppendToKey","pushPair","push","depth","split","forEach","char"],"mappings":";;;;AAAA;IACaA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,MAAD,EAAwC;
|
|
1
|
+
{"version":3,"file":"typescriptParsers.js","sources":["../../../src/validation/typescriptParsers.ts"],"sourcesContent":["/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n"],"names":["typescriptObjectParser","format","keyValuePairs","lastKey","lastValue","shouldAppendToKey","pushPair","push","depth","split","forEach","char"],"mappings":";;;;AAAA;IACaA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,MAAD,EAAwC;EAC5E,IAAMC,aAAiC,GAAG,EAA1C,CAD4E;;EAI5E,IAAIC,OAAO,GAAG,EAAd;EACA,IAAIC,SAAS,GAAG,EAAhB;EACA,IAAIC,iBAAiB,GAAG,IAAxB;;EAEA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,GAAM;IACrB,IAAIH,OAAJ,EAAaD,aAAa,CAACK,IAAd,CAAmB,CAACJ,OAAD,EAAUC,SAAV,CAAnB;IACbD,OAAO,GAAG,EAAV;IACAC,SAAS,GAAG,EAAZ;IACAC,iBAAiB,GAAG,IAApB;GAJF,CAR4E;;;EAgB5E,IAAIG,KAAK,GAAG,CAAZ;EACAP,MAAM,CAACQ,KAAP,CAAa,EAAb,EAAiBC,OAAjB,CAAyB,UAACC,IAAD,EAAU;IACjC,IAAIA,IAAI,KAAK,GAAb,EAAkB;MAChBH,KAAK,IAAI,CAAT;MACA,IAAIA,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;KAFjB,MAGO,IAAIA,IAAI,KAAK,GAAb,EAAkB;MACvB,IAAIH,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;MACfH,KAAK,IAAI,CAAT;MACA,IAAIA,KAAK,KAAK,CAAd,EAAiBF,QAAQ;KAHpB,MAIA,IAAIK,IAAI,KAAK,GAAb,EAAkB;MACvBN,iBAAiB,GAAG,KAApB;MACA,IAAIG,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;KAFV,MAGA,IAAIA,IAAI,KAAK,GAAb,EAAkB;MACvB,IAAIH,KAAK,KAAK,CAAd,EAAiBF,QAAQ,GAAzB,KACKF,SAAS,IAAIO,IAAb;KAFA,MAGA,IAAIA,IAAI,KAAK,GAAb,EAAkB,CAAlB,MAEA,IAAIN,iBAAJ,EAAuBF,OAAO,IAAIQ,IAAX,CAAvB,KACFP,SAAS,IAAIO,IAAb;GAjBP;EAmBAL,QAAQ;EAER,OAAOJ,aAAP;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
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 = <T = Record<any, any>>(\n props: PropsWithChildren<T>,\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,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;AAEAyC,IAAAA,kBAAkB,CAACzC,mBAAD,CAAlB,CALY;AAOb,GAPM,EAOJ,CAACiC,KAAD,CAPI,CAAP;AAQD;;;;;"}
|
|
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 = <T = Record<any, any>>(\n props: PropsWithChildren<T>,\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;EACzE,IAAID,KAAK,KAAKE,SAAd,EAAyB;IACvBC,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;;AAEH,CAJD;;AAKA,IAAMG,qBAAkC,GAAG,SAArCA,qBAAqC,CAACN,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;EAC7E,IAAII,4BAAOL,KAAP,MAAiBC,MAArB,EAA6B;IAC3BE,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;;AAEH,CAJD;;AAMA,IAAMK,cAA2B,GAAG,SAA9BA,cAA8B,CAACR,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;EACtE,IAAID,KAAK,KAAKC,MAAM,CAACM,KAAP,CAAa,CAAb,EAAgB,CAAC,CAAjB,CAAd,EAAmC;IACjCJ,wCAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;;AAEH,CAJD;;AAMA,IAAMO,aAA0B,GAAG,SAA7BA,aAA6B,CAACV,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAiCQ,eAAjC,EAAkDC,mBAAl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IAAI,IAAIH,KAAR,KAAkBA,KAAK,CAACG,IAAD,CAAL,KAAgB5C,SAAhB,IAA6B8C,QAA/C,CAAJ,EAA8D;MAC5DhC,uBAAuB,CAAClB,UAAD,EAAagD,IAAb,EAAmBH,KAAK,CAACG,IAAD,CAAxB,EAAgC7C,MAAhC,EAAwCQ,eAAxC,EAAyDC,mBAAzD,CAAvB;;GARJ;AAWD;IAEYuC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAC5CN,KAD4C,EAE5CC,MAF4C,EAGnC;EACT,gBAA8CM,cAAQ,CAAC,EAAD,CAAtD;;MAAOzC,eAAP;MAAwB0C,kBAAxB;;EAEAC,aAAO,CAAC,YAAM;IACZ,IAAM1C,mBAAmB,GAAG,EAA5B;IAEAgC,yCAAyC,CAACC,KAAD,EAAQC,MAAR,EAAgBnC,eAAhB,EAAiCC,mBAAjC,CAAzC;IAEAyC,kBAAkB,CAACzC,mBAAD,CAAlB,CALY;GAAP,EAOJ,CAACiC,KAAD,CAPI,CAAP;AAQD;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"],"mappings":";;;;;;;;;;;IAIaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;
|
|
1
|
+
{"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"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1 @@
|
|
|
1
|
-
{"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { 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
|
|
1
|
+
{"version":3,"file":"useMemoMergePropsWithDefault.js","sources":["../../../src/defaultProps/useMemoMergePropsWithDefault.ts"],"sourcesContent":["import { 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;;EAExG,IAAMC,WAAW,GAAGC,MAAM,EAA1B;EACA,IAAMC,QAAQ,GAAGF,WAAW,CAACG,OAA7B,CAHwG;;;EAMxG,IAAMC,OAAO,GAAGL,OAAO,CAACG,QAAD,EAAWJ,IAAX,CAAvB,CANwG;;;;EAUxG,IAAI,CAACM,OAAL,EAAcJ,WAAW,CAACG,OAAZ,GAAsBL,IAAtB,CAV0F;;EAYxG,OAAOM,OAAO,GAAGF,QAAH,GAAcJ,IAA5B;AACD,CAbD;;;IAgBaO,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,KAD0C,EAE1CC,YAF0C,EAI3B;EAAA,IADfR,OACe,uEADLS,SACK;;EACf,IAAMC,WAAW,mCAAQF,YAAR,GAAyBD,KAAzB,CAAjB;;EAEA,OAAOT,cAAc,CAAaY,WAAb,EAA0BV,OAA1B,CAArB;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/getProps/index.ts"],"sourcesContent":["export const getAriaProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('aria-')));\n\nexport const getDataProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('data-')));\n"],"names":["getAriaProps","props","Object","fromEntries","entries","filter","key","includes","getDataProps"],"mappings":";;IAAaA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/getProps/index.ts"],"sourcesContent":["export const getAriaProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('aria-')));\n\nexport const getDataProps = (props: Record<string, unknown>): Record<string, unknown> =>\n Object.fromEntries(Object.entries(props).filter(([key]) => key.includes('data-')));\n"],"names":["getAriaProps","props","Object","fromEntries","entries","filter","key","includes","getDataProps"],"mappings":";;IAAaA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD;EAAA,OAC1BC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeH,KAAf,EAAsBI,MAAtB,CAA6B;IAAA;QAAEC,GAAF;;IAAA,OAAWA,GAAG,CAACC,QAAJ,CAAa,OAAb,CAAX;GAA7B,CAAnB,CAD0B;AAAA;IAGfC,YAAY,GAAG,SAAfA,YAAe,CAACP,KAAD;EAAA,OAC1BC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeH,KAAf,EAAsBI,MAAtB,CAA6B;IAAA;QAAEC,GAAF;;IAAA,OAAWA,GAAG,CAACC,QAAJ,CAAa,OAAb,CAAX;GAA7B,CAAnB,CAD0B;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.schema.js","sources":["../../../src/tests/test.schema.js"],"sourcesContent":["import { PropTypes, describe } from 'react-desc';\n\nconst TestSchema = {\n string: PropTypes.string.description('String'),\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n any: PropTypes.any.description('Any'),\n union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Union'),\n union2: PropTypes.oneOf(['A', 'B']).description('Union 2'),\n union3: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.shape({ string: PropTypes.string }),\n ]).description('Union 3'),\n array: PropTypes.arrayOf(PropTypes.string).description('Array'),\n object: PropTypes.object.description('Object'),\n shape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n anotherShape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n }).description('Another shape'),\n }).description('Shape'),\n function: PropTypes.func.description('Function'),\n jsx: PropTypes.element.description('JSX'),\n node: PropTypes.node.description('Node'),\n};\n\nconst TestComponent = () => null;\n\nconst TestComponentWithSchema = describe(TestComponent).description('Test Component');\n\nTestComponentWithSchema.propTypes = TestSchema;\n\nexport const TypescriptSchema = TestComponentWithSchema.toTypescript();\n"],"names":["TestSchema","string","PropTypes","description","number","boolean","bool","any","union","oneOfType","union2","oneOf","union3","arrayOf","shape","array","object","isRequired","anotherShape","function","func","jsx","element","node","TestComponent","TestComponentWithSchema","describe","propTypes","TypescriptSchema","toTypescript"],"mappings":";;AAEA,IAAMA,UAAU,GAAG;
|
|
1
|
+
{"version":3,"file":"test.schema.js","sources":["../../../src/tests/test.schema.js"],"sourcesContent":["import { PropTypes, describe } from 'react-desc';\n\nconst TestSchema = {\n string: PropTypes.string.description('String'),\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n any: PropTypes.any.description('Any'),\n union: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Union'),\n union2: PropTypes.oneOf(['A', 'B']).description('Union 2'),\n union3: PropTypes.oneOfType([\n PropTypes.string,\n PropTypes.arrayOf(PropTypes.string),\n PropTypes.shape({ string: PropTypes.string }),\n ]).description('Union 3'),\n array: PropTypes.arrayOf(PropTypes.string).description('Array'),\n object: PropTypes.object.description('Object'),\n shape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n anotherShape: PropTypes.shape({\n string: PropTypes.string.description('String').isRequired,\n number: PropTypes.number.description('Number'),\n boolean: PropTypes.bool.description('Boolean'),\n }).description('Another shape'),\n }).description('Shape'),\n function: PropTypes.func.description('Function'),\n jsx: PropTypes.element.description('JSX'),\n node: PropTypes.node.description('Node'),\n};\n\nconst TestComponent = () => null;\n\nconst TestComponentWithSchema = describe(TestComponent).description('Test Component');\n\nTestComponentWithSchema.propTypes = TestSchema;\n\nexport const TypescriptSchema = TestComponentWithSchema.toTypescript();\n"],"names":["TestSchema","string","PropTypes","description","number","boolean","bool","any","union","oneOfType","union2","oneOf","union3","arrayOf","shape","array","object","isRequired","anotherShape","function","func","jsx","element","node","TestComponent","TestComponentWithSchema","describe","propTypes","TypescriptSchema","toTypescript"],"mappings":";;AAEA,IAAMA,UAAU,GAAG;EACjBC,MAAM,EAAEC,SAAS,CAACD,MAAV,CAAiBE,WAAjB,CAA6B,QAA7B,CADS;EAEjBC,MAAM,EAAEF,SAAS,CAACE,MAAV,CAAiBD,WAAjB,CAA6B,QAA7B,CAFS;EAGjBE,OAAO,EAAEH,SAAS,CAACI,IAAV,CAAeH,WAAf,CAA2B,SAA3B,CAHQ;EAIjBI,GAAG,EAAEL,SAAS,CAACK,GAAV,CAAcJ,WAAd,CAA0B,KAA1B,CAJY;EAKjBK,KAAK,EAAEN,SAAS,CAACO,SAAV,CAAoB,CAACP,SAAS,CAACD,MAAX,EAAmBC,SAAS,CAACE,MAA7B,CAApB,EAA0DD,WAA1D,CAAsE,OAAtE,CALU;EAMjBO,MAAM,EAAER,SAAS,CAACS,KAAV,CAAgB,CAAC,GAAD,EAAM,GAAN,CAAhB,EAA4BR,WAA5B,CAAwC,SAAxC,CANS;EAOjBS,MAAM,EAAEV,SAAS,CAACO,SAAV,CAAoB,CAC1BP,SAAS,CAACD,MADgB,EA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,IAAMqB,aAAa,GAAG,SAAhBA,aAAgB;EAAA,OAAM,IAAN;AAAA,CAAtB;;AAEA,IAAMC,uBAAuB,GAAGC,QAAQ,CAACF,aAAD,CAAR,CAAwBrB,WAAxB,CAAoC,gBAApC,CAAhC;AAEAsB,uBAAuB,CAACE,SAAxB,GAAoC3B,UAApC;IAEa4B,gBAAgB,GAAGH,uBAAuB,CAACI,YAAxB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorTemplates.js","sources":["../../../src/validation/errorTemplates.ts"],"sourcesContent":["/* eslint-disable max-params */\nexport const throwTypeError = (\n componentName: string,\n validPropKey: string,\n invalidProp: unknown,\n validFormat: string,\n): void => {\n throw new Error(\n `${componentName}:: You are trying to pass a not valid \"${validPropKey}\" property, \n please provide a valid type.\n\n Received: ${invalidProp} (${typeof invalidProp})\n Expected: (${validFormat.replace('\\n', ' or ')})\n `,\n );\n};\n\nexport const throwRequiredError = (componentName: string, validPropKey: string): void => {\n throw new Error(\n `${componentName}:: Please provide a/an \"${validPropKey}\" property to use this component. \n This property is required.\n `,\n );\n};\n"],"names":["throwTypeError","componentName","validPropKey","invalidProp","validFormat","Error","replace","throwRequiredError"],"mappings":";;AAAA;IACaA,cAAc,GAAG,SAAjBA,cAAiB,CAC5BC,aAD4B,EAE5BC,YAF4B,EAG5BC,WAH4B,EAI5BC,WAJ4B,EAKnB;
|
|
1
|
+
{"version":3,"file":"errorTemplates.js","sources":["../../../src/validation/errorTemplates.ts"],"sourcesContent":["/* eslint-disable max-params */\nexport const throwTypeError = (\n componentName: string,\n validPropKey: string,\n invalidProp: unknown,\n validFormat: string,\n): void => {\n throw new Error(\n `${componentName}:: You are trying to pass a not valid \"${validPropKey}\" property, \n please provide a valid type.\n\n Received: ${invalidProp} (${typeof invalidProp})\n Expected: (${validFormat.replace('\\n', ' or ')})\n `,\n );\n};\n\nexport const throwRequiredError = (componentName: string, validPropKey: string): void => {\n throw new Error(\n `${componentName}:: Please provide a/an \"${validPropKey}\" property to use this component. \n This property is required.\n `,\n );\n};\n"],"names":["throwTypeError","componentName","validPropKey","invalidProp","validFormat","Error","replace","throwRequiredError"],"mappings":";;AAAA;IACaA,cAAc,GAAG,SAAjBA,cAAiB,CAC5BC,aAD4B,EAE5BC,YAF4B,EAG5BC,WAH4B,EAI5BC,WAJ4B,EAKnB;EACT,MAAM,IAAIC,KAAJ,WACDJ,aADC,qDACsDC,YADtD,4EAIMC,WAJN,uBAI6BA,WAJ7B,8BAKOC,WAAW,CAACE,OAAZ,CAAoB,IAApB,EAA0B,MAA1B,CALP,WAAN;AAQD;IAEYC,kBAAkB,GAAG,SAArBA,kBAAqB,CAACN,aAAD,EAAwBC,YAAxB,EAAuD;EACvF,MAAM,IAAIG,KAAJ,WACDJ,aADC,sCACuCC,YADvC,8EAAN;AAKD;;;;"}
|
|
@@ -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);\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;
|
|
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;EAAA,OAAY,CAAC,QAAD,EAAW,QAAX,EAAqB,SAArB,EAAgCC,QAAhC,CAAyCD,MAAzC,CAAZ;AAAA;IAC3BE,WAAoB,GAA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AY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,KAAK,2BAA3C;AAAA;IAEtBc,WAAoB,GAAG,SAAvBA,WAAuB,CAACd,MAAD;EAAA,OAAY,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoB,CAAC,iBAAD,EAAoB,aAApB,EAAmCC,QAAnC,CAA4CD,MAA5C,CAAhC;AAAA;IAEvBe,0BAAmC,GAAG,SAAtCA,0BAAsC,CAACf,MAAD;EAAA,OACjD,CAACG,OAAO,CAACH,MAAD,CAAR,IAAoBA,MAAM,CAAC,CAAD,CAAN,KAAc,GAAlC,IAAyCA,MAAM,CAACU,KAAP,CAAa,CAAC,CAAd,MAAqB,GADb;AAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescriptParsers.js","sources":["../../../src/validation/typescriptParsers.ts"],"sourcesContent":["/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n"],"names":["typescriptObjectParser","format","keyValuePairs","lastKey","lastValue","shouldAppendToKey","pushPair","push","depth","split","forEach","char"],"mappings":"AAAA;IACaA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,MAAD,EAAwC;
|
|
1
|
+
{"version":3,"file":"typescriptParsers.js","sources":["../../../src/validation/typescriptParsers.ts"],"sourcesContent":["/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n"],"names":["typescriptObjectParser","format","keyValuePairs","lastKey","lastValue","shouldAppendToKey","pushPair","push","depth","split","forEach","char"],"mappings":"AAAA;IACaA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAACC,MAAD,EAAwC;EAC5E,IAAMC,aAAiC,GAAG,EAA1C,CAD4E;;EAI5E,IAAIC,OAAO,GAAG,EAAd;EACA,IAAIC,SAAS,GAAG,EAAhB;EACA,IAAIC,iBAAiB,GAAG,IAAxB;;EAEA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,GAAM;IACrB,IAAIH,OAAJ,EAAaD,aAAa,CAACK,IAAd,CAAmB,CAACJ,OAAD,EAAUC,SAAV,CAAnB;IACbD,OAAO,GAAG,EAAV;IACAC,SAAS,GAAG,EAAZ;IACAC,iBAAiB,GAAG,IAApB;GAJF,CAR4E;;;EAgB5E,IAAIG,KAAK,GAAG,CAAZ;EACAP,MAAM,CAACQ,KAAP,CAAa,EAAb,EAAiBC,OAAjB,CAAyB,UAACC,IAAD,EAAU;IACjC,IAAIA,IAAI,KAAK,GAAb,EAAkB;MAChBH,KAAK,IAAI,CAAT;MACA,IAAIA,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;KAFjB,MAGO,IAAIA,IAAI,KAAK,GAAb,EAAkB;MACvB,IAAIH,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;MACfH,KAAK,IAAI,CAAT;MACA,IAAIA,KAAK,KAAK,CAAd,EAAiBF,QAAQ;KAHpB,MAIA,IAAIK,IAAI,KAAK,GAAb,EAAkB;MACvBN,iBAAiB,GAAG,KAApB;MACA,IAAIG,KAAK,GAAG,CAAZ,EAAeJ,SAAS,IAAIO,IAAb;KAFV,MAGA,IAAIA,IAAI,KAAK,GAAb,EAAkB;MACvB,IAAIH,KAAK,KAAK,CAAd,EAAiBF,QAAQ,GAAzB,KACKF,SAAS,IAAIO,IAAb;KAFA,MAGA,IAAIA,IAAI,KAAK,GAAb,EAAkB,CAAlB,MAEA,IAAIN,iBAAJ,EAAuBF,OAAO,IAAIQ,IAAX,CAAvB,KACFP,SAAS,IAAIO,IAAb;GAjBP;EAmBAL,QAAQ;EAER,OAAOJ,aAAP;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
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 = <T = Record<any, any>>(\n props: PropsWithChildren<T>,\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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C,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;;;;"}
|
|
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 = <T = Record<any, any>>(\n props: PropsWithChildren<T>,\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;EACzE,IAAID,KAAK,KAAKE,SAAd,EAAyB;IACvBC,cAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;;AAEH,CAJD;;AAKA,IAAMG,qBAAkC,GAAG,SAArCA,qBAAqC,CAACN,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,EAAoC;EAC7E,IAAI,QAAOD,KAAP,MAAiBC,MAArB,EAA6B;IAC3BE,cAAc,CAACL,UAAD,EAAaC,GAAb,EAAkBC,KAAlB,EAAyBC,MAAzB,CAAd;;AAEH,CAJD;;AAMA,IAAMI,cAA2B,GAAG,SAA9BA,cAA8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AEAD,UAAU,CAAChC,OAAX,CAAmB,UAACkC,QAAD,EAAc;IAC/B,IAAQD,IAAR,GAAmCC,QAAnC,CAAQD,IAAR;QAAc5C,MAAd,GAAmC6C,QAAnC,CAAc7C,MAAd;QAAsB8C,QAAtB,GAAmCD,QAAnC,CAAsBC,QAAtB;;IAEA,IAAIA,QAAQ,IAAI,EAAEF,IAAI,IAAIH,KAAV,CAAhB,EAAkC;MAChCpB,kBAAkB,CAACqB,MAAM,CAACE,IAAR,EAAcA,IAAd,CAAlB;;;IAGF,IAAIA,IAAI,IAAIH,KAAR,KAAkBA,KAAK,CAACG,IAAD,CAAL,KAAgB3C,SAAhB,IAA6B6C,QAA/C,CAAJ,EAA8D;MAC5DhC,uBAAuB,CAACjB,UAAD,EAAa+C,IAAb,EAAmBH,KAAK,CAACG,IAAD,CAAxB,EAAgC5C,MAAhC,EAAwCO,eAAxC,EAAyDC,mBAAzD,CAAvB;;GARJ;AAWD;IAEYuC,8BAA8B,GAAG,SAAjCA,8BAAiC,CAC5CN,KAD4C,EAE5CC,MAF4C,EAGnC;EACT,gBAA8CM,QAAQ,CAAC,EAAD,CAAtD;;MAAOzC,eAAP;MAAwB0C,kBAAxB;;EAEAC,OAAO,CAAC,YAAM;IACZ,IAAM1C,mBAAmB,GAAG,EAA5B;IAEAgC,yCAAyC,CAACC,KAAD,EAAQC,MAAR,EAAgBnC,eAAhB,EAAiCC,mBAAjC,CAAzC;IAEAyC,kBAAkB,CAACzC,mBAAD,CAAlB,CALY;GAAP,EAOJ,CAACiC,KAAD,CAPI,CAAP;AAQD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"],"mappings":";;;IAIaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;
|
|
1
|
+
{"version":3,"file":"validator.js","sources":["../../../src/validation/validator.ts"],"sourcesContent":["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n"],"names":["useValidatePropTypes","props","schema","properties","forEach","property","propertyName","name","currentProp","currentPropTypeOf","currentFormat","format","isValidReactElement","required","Object","prototype","hasOwnProperty","call","throwRequiredError","includes","throwTypeError"],"mappings":";;;IAIaA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAiCC,MAAjC,EAAkD;EACpFA,MAAM,CAACC,UAAP,CAAkBC,OAAlB,CAA0B,UAACC,QAAD,EAAc;IACtC,IAAMC,YAAY,GAAGD,QAAQ,CAACE,IAA9B;IACA,IAAMC,WAAW,GAAGP,KAAK,CAACK,YAAD,CAAzB;;IACA,IAAMG,iBAAiB,WAAUD,WAAV,CAAvB,CAHsC;;;IAKtC,IAAME,aAAa,GAAGL,QAAQ,CAACM,MAA/B,CALsC;;IAMtC,IAAIC,mBAAmB,GAAG,KAA1B,CANsC;;IAQtC,IAAIP,QAAQ,CAACQ,QAAT,IAAqB,CAACC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqChB,KAArC,EAA4CI,QAAQ,CAACE,IAArD,CAA1B,EAAsF;MACpFW,kBAAkB,CAAChB,MAAM,CAACK,IAAR,EAAcF,QAAQ,CAACE,IAAvB,CAAlB;;;IAEF,IAAIE,iBAAiB,KAAK,WAAtB,IAAqCD,WAAW,KAAK,IAAzD,EAA+D;MAC7D,IACEC,iBAAiB,KAAK,QAAtB,IACAK,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCT,WAArC,EAAkD,UAAlD,CADA,KAECE,aAAa,CAACS,QAAd,CAAuB,MAAvB,KAAkCT,aAAa,CAACS,QAAd,CAAuB,SAAvB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