@elliemae/ds-props-helpers 2.2.0-alpha.2 → 2.2.0-next.1

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.
Files changed (46) hide show
  1. package/cjs/defaultProps/index.js +9 -28
  2. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
  3. package/cjs/getProps/index.js +20 -37
  4. package/cjs/index.js +20 -30
  5. package/cjs/validation/errorTemplates.js +12 -44
  6. package/cjs/validation/index.js +15 -30
  7. package/cjs/validation/typescriptGuards.js +31 -60
  8. package/cjs/validation/typescriptParsers.js +34 -65
  9. package/cjs/validation/typescriptValidator.js +135 -99
  10. package/cjs/validation/validator.js +24 -43
  11. package/esm/defaultProps/index.js +1 -3
  12. package/esm/defaultProps/useMemoMergePropsWithDefault.js +34 -14
  13. package/esm/getProps/index.js +15 -8
  14. package/esm/index.js +5 -5
  15. package/esm/validation/errorTemplates.js +7 -15
  16. package/esm/validation/index.js +3 -5
  17. package/esm/validation/typescriptGuards.js +18 -31
  18. package/esm/validation/typescriptParsers.js +30 -36
  19. package/esm/validation/typescriptValidator.js +106 -57
  20. package/esm/validation/validator.js +18 -12
  21. package/package.json +1 -1
  22. package/types/validation/typescriptValidator.d.ts +2 -2
  23. package/cjs/defaultProps/index.js.map +0 -7
  24. package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
  25. package/cjs/getProps/index.js.map +0 -7
  26. package/cjs/index.js.map +0 -7
  27. package/cjs/tests/test.schema.js +0 -67
  28. package/cjs/tests/test.schema.js.map +0 -7
  29. package/cjs/validation/errorTemplates.js.map +0 -7
  30. package/cjs/validation/index.js.map +0 -7
  31. package/cjs/validation/typescriptGuards.js.map +0 -7
  32. package/cjs/validation/typescriptParsers.js.map +0 -7
  33. package/cjs/validation/typescriptValidator.js.map +0 -7
  34. package/cjs/validation/validator.js.map +0 -7
  35. package/esm/defaultProps/index.js.map +0 -7
  36. package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
  37. package/esm/getProps/index.js.map +0 -7
  38. package/esm/index.js.map +0 -7
  39. package/esm/tests/test.schema.js +0 -38
  40. package/esm/tests/test.schema.js.map +0 -7
  41. package/esm/validation/errorTemplates.js.map +0 -7
  42. package/esm/validation/index.js.map +0 -7
  43. package/esm/validation/typescriptGuards.js.map +0 -7
  44. package/esm/validation/typescriptParsers.js.map +0 -7
  45. package/esm/validation/typescriptValidator.js.map +0 -7
  46. package/esm/validation/validator.js.map +0 -7
@@ -1,47 +1,41 @@
1
- import * as React from "react";
2
- const typescriptObjectParser = (format) => {
3
- const keyValuePairs = [];
4
- let lastKey = "";
5
- let lastValue = "";
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+
5
+ /* eslint-disable complexity */
6
+ const typescriptObjectParser = format => {
7
+ const keyValuePairs = []; // State of the algorithm
8
+
9
+ let lastKey = '';
10
+ let lastValue = '';
6
11
  let shouldAppendToKey = true;
12
+
7
13
  const pushPair = () => {
8
- if (lastKey)
9
- keyValuePairs.push([lastKey, lastValue]);
10
- lastKey = "";
11
- lastValue = "";
14
+ if (lastKey) keyValuePairs.push([lastKey, lastValue]);
15
+ lastKey = '';
16
+ lastValue = '';
12
17
  shouldAppendToKey = true;
13
- };
18
+ }; // Complex -- but working -- logic
19
+
20
+
14
21
  let depth = 0;
15
- format.split("").forEach((char) => {
16
- if (char === "{") {
22
+ format.split('').forEach(char => {
23
+ if (char === '{') {
17
24
  depth += 1;
18
- if (depth > 1)
19
- lastValue += char;
20
- } else if (char === "}") {
21
- if (depth > 1)
22
- lastValue += char;
25
+ if (depth > 1) lastValue += char;
26
+ } else if (char === '}') {
27
+ if (depth > 1) lastValue += char;
23
28
  depth -= 1;
24
- if (depth === 1)
25
- pushPair();
26
- } else if (char === ":") {
29
+ if (depth === 1) pushPair();
30
+ } else if (char === ':') {
27
31
  shouldAppendToKey = false;
28
- if (depth > 1)
29
- lastValue += char;
30
- } else if (char === ",") {
31
- if (depth === 1)
32
- pushPair();
33
- else
34
- lastValue += char;
35
- } else if (char === " ") {
36
- } else if (shouldAppendToKey)
37
- lastKey += char;
38
- else
39
- lastValue += char;
32
+ if (depth > 1) lastValue += char;
33
+ } else if (char === ',') {
34
+ if (depth === 1) pushPair();else lastValue += char;
35
+ } else if (char === ' ') ; else if (shouldAppendToKey) lastKey += char;else lastValue += char;
40
36
  });
41
37
  pushPair();
42
38
  return keyValuePairs;
43
39
  };
44
- export {
45
- typescriptObjectParser
46
- };
47
- //# sourceMappingURL=typescriptParsers.js.map
40
+
41
+ export { typescriptObjectParser };
@@ -1,153 +1,202 @@
1
- import * as React from "react";
2
- import { describe } from "react-desc";
3
- import { useMemo, useState } from "react";
4
- import { throwRequiredError, throwTypeError } from "./errorTemplates";
5
- import {
6
- isArray,
7
- isFunction,
8
- isJSXorNode,
9
- isObject,
10
- isPrimitiveType,
11
- isSomethingWithParenthesis,
12
- isString,
13
- isUnion,
14
- isUndefined,
15
- isNull
16
- } from "./typescriptGuards";
17
- import { typescriptObjectParser } from "./typescriptParsers";
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import 'core-js/modules/web.dom-collections.iterator.js';
5
+ import { describe } from 'react-desc';
6
+ import { useState, useMemo } from 'react';
7
+ import { throwRequiredError, throwTypeError } from './errorTemplates.js';
8
+ import { isUndefined, isNull, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
9
+ import { typescriptObjectParser } from './typescriptParsers.js';
10
+
11
+ // =============================================================================
12
+ // Atom Validators
13
+ // =============================================================================
14
+ // This functions will validate something from the data
15
+ // and optionally recursively apply `validateValueWithFormat`
16
+ // in smaller parts
18
17
  const validateUndefined = (schemaName, key, value, format) => {
19
- if (value !== void 0 || value === "undefined") {
18
+ if (value !== undefined || value === 'undefined') {
20
19
  throwTypeError(schemaName, key, value, format);
21
20
  }
22
21
  };
22
+
23
23
  const validateNull = (schemaName, key, value, format) => {
24
- if (value !== null || value === "null") {
24
+ if (value !== null || value === 'null') {
25
25
  throwTypeError(schemaName, key, value, format);
26
26
  }
27
27
  };
28
+
28
29
  const validatePrimitiveType = (schemaName, key, value, format) => {
29
30
  if (typeof value !== format) {
30
31
  throwTypeError(schemaName, key, value, format);
31
32
  }
32
33
  };
34
+
33
35
  const validateString = (schemaName, key, value, format) => {
34
36
  if (value !== format.slice(1, -1)) {
35
37
  throwTypeError(schemaName, key, value, format);
36
38
  }
37
39
  };
40
+
38
41
  const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
42
+ // Check that we have an array
39
43
  if (!Array.isArray(value)) {
40
44
  throwTypeError(schemaName, key, value, format);
41
- }
45
+ } // Check that each element inside satisfies the format
46
+
47
+
42
48
  value.forEach((val, index) => {
43
- validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
49
+ // this is a recursive func, we need to invoke it before it's defined.
50
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
51
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
44
52
  });
45
53
  };
54
+
46
55
  function isObjectType(value) {
47
- return !(typeof value !== "object" || Array.isArray(value));
56
+ return !(typeof value !== 'object' || Array.isArray(value));
48
57
  }
58
+
49
59
  const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
50
- const valuesIsObject = isObjectType(value);
60
+ const valuesIsObject = isObjectType(value); // Check that we have an object
61
+
51
62
  if (!valuesIsObject) {
52
63
  throwTypeError(schemaName, key, value, format);
53
64
  return;
54
65
  }
55
- if (format === "object")
56
- return;
57
- const keyValuePairs = typescriptObjectParser(format);
58
- keyValuePairs.forEach(([objectKey, objectValue]) => {
59
- const trueKey = objectKey.slice(-1) === "?" ? objectKey.slice(0, -1) : objectKey;
66
+
67
+ if (format === 'object') return;
68
+ const keyValuePairs = typescriptObjectParser(format); // Now we have the key - value pairs
69
+ // Each key could either be required or not
70
+ // Just recursively check the object
71
+
72
+ keyValuePairs.forEach(_ref => {
73
+ let [objectKey, objectValue] = _ref;
74
+ const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
75
+
60
76
  if (trueKey === objectKey && !(trueKey in value)) {
61
77
  throwRequiredError(schemaName, key);
62
78
  }
79
+
63
80
  if (trueKey in value) {
64
- validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
81
+ // this is a recursive func, we need to invoke it before it's defined.
82
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
83
+ validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
65
84
  }
66
85
  });
67
86
  };
87
+
68
88
  const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
69
89
  const possibilities = format.split(/\s?\|\s?/);
70
90
  const errors = [];
71
- possibilities.forEach((possibility) => {
91
+ possibilities.forEach(possibility => {
72
92
  try {
93
+ // this is a recursive func, we need to invoke it before it's defined.
94
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
73
95
  validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
74
96
  } catch (e) {
75
97
  errors.push(e);
76
98
  }
77
99
  });
100
+
78
101
  if (errors.length === possibilities.length) {
79
102
  throwTypeError(schemaName, key, value, format);
80
103
  }
81
104
  };
105
+
82
106
  const validateFunction = (schemaName, key, value, format) => {
83
- if (typeof value !== "function") {
107
+ // Check that we have a function
108
+ if (typeof value !== 'function') {
84
109
  throwTypeError(schemaName, key, value, format);
85
110
  }
86
111
  };
112
+
87
113
  function isJSXElement(value) {
88
- return value === null || typeof value === "object" && value !== null && "$$typeof" in value;
114
+ return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
89
115
  }
116
+
90
117
  const validateJSXorNode = (schemaName, key, value, format) => {
91
118
  const valueIsJSX = isJSXElement(value);
92
- if (format === "JSX.Element" && !valueIsJSX) {
119
+
120
+ if (format === 'JSX.Element' && !valueIsJSX) {
93
121
  throwTypeError(schemaName, key, value, format);
94
122
  }
95
- };
123
+ }; // =============================================================================
124
+ // Schema validator
125
+ // =============================================================================
126
+
127
+
96
128
  const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
97
129
  nextValidationsMemo[value] = format;
130
+
98
131
  if (value in validationsMemo) {
132
+ // We already validated this value on this format
99
133
  return;
100
134
  }
135
+
101
136
  if (isUndefined(format)) {
102
- validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
137
+ validateUndefined(schemaName, key, value, format);
103
138
  } else if (isNull(format)) {
104
- validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
139
+ validateNull(schemaName, key, value, format);
105
140
  } else if (isPrimitiveType(format)) {
106
- validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
141
+ validatePrimitiveType(schemaName, key, value, format);
107
142
  } else if (isUnion(format)) {
108
143
  validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
109
144
  } else if (isString(format)) {
110
- validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
145
+ validateString(schemaName, key, value, format);
111
146
  } else if (isArray(format)) {
112
147
  validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
113
148
  } else if (isObject(format)) {
114
149
  validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
115
150
  } else if (isFunction(format)) {
116
- validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
151
+ validateFunction(schemaName, key, value, format);
117
152
  } else if (isJSXorNode(format)) {
118
- validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
153
+ validateJSXorNode(schemaName, key, value, format);
119
154
  } else if (isSomethingWithParenthesis(format)) {
120
155
  validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
121
156
  }
122
157
  };
123
- const validateTypescriptPropTypesImplementation = (props, schema, validationsMemo = {}, nextValidationsMemo = {}) => {
124
- const { properties, name: schemaName } = schema;
125
- properties.forEach((property) => {
126
- const { name, format, required } = property;
158
+
159
+ const validateTypescriptPropTypesImplementation = function (props, schema) {
160
+ let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
+ let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
162
+ const {
163
+ properties,
164
+ name: schemaName
165
+ } = schema;
166
+ properties.forEach(property => {
167
+ const {
168
+ name,
169
+ format,
170
+ required
171
+ } = property;
172
+
127
173
  if (required && !(name in props)) {
128
174
  throwRequiredError(schema.name, name);
129
175
  }
130
- if (name in props && (props[name] !== void 0 || required)) {
176
+
177
+ if (name in props && (props[name] !== undefined || required)) {
131
178
  validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
132
179
  }
133
180
  });
134
- };
181
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
+
135
183
  const useValidateTypescriptPropTypes = (props, propTypes) => {
136
- const [validationsMemo, setValidationsMemo] = useState({});
184
+ const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
185
+
137
186
  const ComponentWithSchema = useMemo(() => {
138
- const Component = () => {
139
- };
187
+ const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
188
+
189
+
140
190
  return describe(Component);
141
- }, []);
191
+ }, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
192
+
142
193
  ComponentWithSchema.propTypes = propTypes;
143
194
  useMemo(() => {
144
195
  const nextValidationsMemo = {};
145
- validateTypescriptPropTypesImplementation(props, ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
146
- setValidationsMemo(nextValidationsMemo);
196
+ validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
197
+ ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
198
+ setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
147
199
  }, [props]);
148
200
  };
149
- export {
150
- useValidateTypescriptPropTypes,
151
- validateTypescriptPropTypesImplementation
152
- };
153
- //# sourceMappingURL=typescriptValidator.js.map
201
+
202
+ export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
@@ -1,26 +1,32 @@
1
- import * as React from "react";
2
- import { throwRequiredError, throwTypeError } from "./errorTemplates";
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import { throwRequiredError, throwTypeError } from './errorTemplates.js';
5
+
3
6
  const useValidatePropTypes = (props, schema) => {
4
- schema.properties.forEach((property) => {
7
+ schema.properties.forEach(property => {
5
8
  const propertyName = property.name;
6
9
  const currentProp = props[propertyName];
7
- const currentPropTypeOf = typeof currentProp;
8
- const currentFormat = property.format;
9
- let isValidReactElement = false;
10
+ const currentPropTypeOf = typeof currentProp; // eslint-disable-next-line max-len
11
+
12
+ const currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
13
+
14
+ let isValidReactElement = false; // this depends on react desc definition
15
+
10
16
  if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
11
17
  throwRequiredError(schema.name, property.name);
12
18
  }
13
- if (currentPropTypeOf !== "undefined" && currentProp !== null) {
14
- if (currentPropTypeOf === "object" && Object.prototype.hasOwnProperty.call(currentProp, "$$typeof") && (currentFormat.includes("node") || currentFormat.includes("element"))) {
19
+
20
+ if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
21
+ if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
15
22
  isValidReactElement = true;
16
23
  }
24
+
17
25
  if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
18
26
  throwTypeError(schema.name, propertyName, currentProp, currentFormat);
19
27
  }
20
28
  }
21
29
  });
22
30
  };
23
- export {
24
- useValidatePropTypes
25
- };
26
- //# sourceMappingURL=validator.js.map
31
+
32
+ export { useValidatePropTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-props-helpers",
3
- "version": "2.2.0-alpha.2",
3
+ "version": "2.2.0-next.1",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Props Helpers",
6
6
  "module": "./esm/index.js",
@@ -1,4 +1,4 @@
1
- import React, { PropsWithChildren } from 'react';
1
+ import { PropsWithChildren } from 'react';
2
2
  interface TypescriptSchema {
3
3
  description: string;
4
4
  name: string;
@@ -11,5 +11,5 @@ interface TypescriptSchema {
11
11
  }[];
12
12
  }
13
13
  export declare const validateTypescriptPropTypesImplementation: (props: PropsWithChildren<Record<string, unknown>>, schema: TypescriptSchema, validationsMemo?: Record<string, string>, nextValidationsMemo?: Record<string, string>) => void;
14
- export declare const useValidateTypescriptPropTypes: <T = Record<string, any>>(props: React.PropsWithChildren<T>, propTypes: any) => void;
14
+ export declare const useValidateTypescriptPropTypes: <T = Record<string, any>>(props: PropsWithChildren<T>, propTypes: any) => void;
15
15
  export {};
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/defaultProps/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export * from './useMemoMergePropsWithDefault';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;ADAvB,iCAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/defaultProps/useMemoMergePropsWithDefault.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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(next);\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<string, any>>(\n props: Partial<T>,\n defaultProps: Partial<T>,\n compare = deepequal,\n): T => {\n const mergedProps = { ...defaultProps, ...props } as T;\n\n return useMemoCompare<T>(mergedProps, compare);\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAuB;AACvB,oBAAsB;AAItB,MAAM,iBAAiB,CAAU,MAAS,YAAgE;AAExG,QAAM,cAAc,yBAAO;AAC3B,QAAM,WAAW,YAAY;AAG7B,QAAM,UAAU,QAAQ,UAAU;AAIlC,MAAI,CAAC;AAAS,gBAAY,UAAU;AAEpC,SAAO,UAAU,WAAW;AAAA;AAIvB,MAAM,+BAA+B,CAC1C,OACA,cACA,UAAU,0BACJ;AACN,QAAM,cAAc,KAAK,iBAAiB;AAE1C,SAAO,eAAkB,aAAa;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/getProps/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAhB,MAAM,eAAe,CAAC,UAC3B,OAAO,YAAY,OAAO,QAAQ,OAAO,OAAO,CAAC,CAAC,SAAS,IAAI,SAAS;AAEnE,MAAM,eAAe,CAAC,UAC3B,OAAO,YAAY,OAAO,QAAQ,OAAO,OAAO,CAAC,CAAC,SAAS,IAAI,SAAS;",
6
- "names": []
7
- }
package/cjs/index.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts", "../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export * from './defaultProps';\nexport * from './validation';\nexport * from './getProps';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;ADAvB,wBAAc;AACd,wBAAc;AACd,wBAAc;",
6
- "names": []
7
- }
@@ -1,67 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var test_schema_exports = {};
29
- __export(test_schema_exports, {
30
- TypescriptSchema: () => TypescriptSchema
31
- });
32
- var React = __toESM(require("react"));
33
- var import_react_desc = __toESM(require("react-desc"));
34
- const TestSchema = {
35
- string: import_react_desc.PropTypes.string.description("String"),
36
- number: import_react_desc.PropTypes.number.description("Number"),
37
- boolean: import_react_desc.PropTypes.bool.description("Boolean"),
38
- any: import_react_desc.PropTypes.any.description("Any"),
39
- union: import_react_desc.PropTypes.oneOfType([import_react_desc.PropTypes.string, import_react_desc.PropTypes.number]).description("Union"),
40
- union2: import_react_desc.PropTypes.oneOf(["A", "B"]).description("Union 2"),
41
- union3: import_react_desc.PropTypes.oneOfType([
42
- import_react_desc.PropTypes.string,
43
- import_react_desc.PropTypes.arrayOf(import_react_desc.PropTypes.string),
44
- import_react_desc.PropTypes.shape({ string: import_react_desc.PropTypes.string })
45
- ]).description("Union 3"),
46
- array: import_react_desc.PropTypes.arrayOf(import_react_desc.PropTypes.string).description("Array"),
47
- object: import_react_desc.PropTypes.object.description("Object"),
48
- shape: import_react_desc.PropTypes.shape({
49
- string: import_react_desc.PropTypes.string.description("String").isRequired,
50
- number: import_react_desc.PropTypes.number.description("Number"),
51
- boolean: import_react_desc.PropTypes.bool.description("Boolean"),
52
- anotherShape: import_react_desc.PropTypes.shape({
53
- string: import_react_desc.PropTypes.string.description("String").isRequired,
54
- number: import_react_desc.PropTypes.number.description("Number"),
55
- boolean: import_react_desc.PropTypes.bool.description("Boolean")
56
- }).description("Another shape")
57
- }).description("Shape"),
58
- function: import_react_desc.PropTypes.func.description("Function"),
59
- jsx: import_react_desc.PropTypes.element.description("JSX"),
60
- node: import_react_desc.PropTypes.node.description("Node")
61
- };
62
- const TestComponent = () => null;
63
- const TestComponentWithSchema = (0, import_react_desc.describe)(TestComponent).description("Test Component");
64
- TestComponentWithSchema.propTypes = TestSchema;
65
- const TypescriptSchema = TestComponentWithSchema.toTypescript();
66
- module.exports = __toCommonJS(test_schema_exports);
67
- //# sourceMappingURL=test.schema.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/tests/test.schema.js", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,wBAAoC;AAEpC,MAAM,aAAa;AAAA,EACjB,QAAQ,4BAAU,OAAO,YAAY;AAAA,EACrC,QAAQ,4BAAU,OAAO,YAAY;AAAA,EACrC,SAAS,4BAAU,KAAK,YAAY;AAAA,EACpC,KAAK,4BAAU,IAAI,YAAY;AAAA,EAC/B,OAAO,4BAAU,UAAU,CAAC,4BAAU,QAAQ,4BAAU,SAAS,YAAY;AAAA,EAC7E,QAAQ,4BAAU,MAAM,CAAC,KAAK,MAAM,YAAY;AAAA,EAChD,QAAQ,4BAAU,UAAU;AAAA,IAC1B,4BAAU;AAAA,IACV,4BAAU,QAAQ,4BAAU;AAAA,IAC5B,4BAAU,MAAM,EAAE,QAAQ,4BAAU;AAAA,KACnC,YAAY;AAAA,EACf,OAAO,4BAAU,QAAQ,4BAAU,QAAQ,YAAY;AAAA,EACvD,QAAQ,4BAAU,OAAO,YAAY;AAAA,EACrC,OAAO,4BAAU,MAAM;AAAA,IACrB,QAAQ,4BAAU,OAAO,YAAY,UAAU;AAAA,IAC/C,QAAQ,4BAAU,OAAO,YAAY;AAAA,IACrC,SAAS,4BAAU,KAAK,YAAY;AAAA,IACpC,cAAc,4BAAU,MAAM;AAAA,MAC5B,QAAQ,4BAAU,OAAO,YAAY,UAAU;AAAA,MAC/C,QAAQ,4BAAU,OAAO,YAAY;AAAA,MACrC,SAAS,4BAAU,KAAK,YAAY;AAAA,OACnC,YAAY;AAAA,KACd,YAAY;AAAA,EACf,UAAU,4BAAU,KAAK,YAAY;AAAA,EACrC,KAAK,4BAAU,QAAQ,YAAY;AAAA,EACnC,MAAM,4BAAU,KAAK,YAAY;AAAA;AAGnC,MAAM,gBAAgB,MAAM;AAE5B,MAAM,0BAA0B,gCAAS,eAAe,YAAY;AAEpE,wBAAwB,YAAY;AAE7B,MAAM,mBAAmB,wBAAwB;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/errorTemplates.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADChB,MAAM,iBAAiB,CAC5B,eACA,cACA,aACA,gBACS;AACT,QAAM,IAAI,MACR,GAAG,uDAAuD;AAAA;AAAA;AAAA,cAGhD,gBAAgB,OAAO;AAAA,eACtB,YAAY,QAAQ,MAAM;AAAA;AAAA;AAKlC,MAAM,qBAAqB,CAAC,eAAuB,iBAA+B;AACvF,QAAM,IAAI,MACR,GAAG,wCAAwC;AAAA;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["export * from './validator';\nexport * from './errorTemplates';\nexport * from './typescriptValidator';\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;ACAA,YAAuB;ADAvB,+BAAc;AACd,+BAAc;AACd,+BAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/typescriptGuards.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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 isNull: GuardFn = (format) => format === '\"null\"';\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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEhB,MAAM,kBAA2B,CAAC,WAAW,CAAC,UAAU,UAAU,WAAW,SAAS;AACtF,MAAM,cAAuB,CAAC,WAAW,WAAW;AACpD,MAAM,SAAkB,CAAC,WAAW,WAAW;AAC/C,MAAM,UAAmB,CAAC,WAAW;AAC1C,MAAI,QAAQ;AACZ,MAAI,YAAY;AAChB,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS;AACjC,QAAI,CAAC,KAAK,KAAK,SAAS;AAAO,eAAS;AAAA,aAC/B,CAAC,KAAK,KAAK,SAAS;AAAO,eAAS;AAAA,aACpC,SAAS,OAAO,UAAU;AAAG,kBAAY;AAAA;AAEpD,SAAO;AAAA;AAGF,MAAM,WAAoB,CAAC,WAAW,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;AAEpG,MAAM,UAAmB,CAAC,WAAW,CAAC,QAAQ,WAAW,OAAO,MAAM,QAAQ;AAE9E,MAAM,WAAoB,CAAC,WAChC,WAAW,YAAa,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;AAEjF,MAAM,aAAsB,CAAC,WAAW,CAAC,QAAQ,WAAW,WAAW;AAEvE,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,WAAW,CAAC,mBAAmB,eAAe,SAAS;AAEzG,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,WAAW,OAAO,OAAO,OAAO,OAAO,MAAM,QAAQ;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/typescriptParsers.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADChB,MAAM,yBAAyB,CAAC,WAAuC;AAC5E,QAAM,gBAAoC;AAG1C,MAAI,UAAU;AACd,MAAI,YAAY;AAChB,MAAI,oBAAoB;AAExB,QAAM,WAAW,MAAM;AACrB,QAAI;AAAS,oBAAc,KAAK,CAAC,SAAS;AAC1C,cAAU;AACV,gBAAY;AACZ,wBAAoB;AAAA;AAItB,MAAI,QAAQ;AACZ,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS;AACjC,QAAI,SAAS,KAAK;AAChB,eAAS;AACT,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,QAAQ;AAAG,qBAAa;AAC5B,eAAS;AACT,UAAI,UAAU;AAAG;AAAA,eACR,SAAS,KAAK;AACvB,0BAAoB;AACpB,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,UAAU;AAAG;AAAA;AACZ,qBAAa;AAAA,eACT,SAAS,KAAK;AAAA,eAEd;AAAmB,iBAAW;AAAA;AACpC,mBAAa;AAAA;AAEpB;AAEA,SAAO;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/typescriptValidator.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { describe } from 'react-desc';\nimport React, { 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 isNull,\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 || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown | Record<string, unknown>): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown | JSX.Element): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (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\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n propTypes: any,\n): void => {\n const [validationsMemo, setValidationsMemo] = useState({});\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const ComponentWithSchema = useMemo(() => {\n const Component = () => {};\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call\n return describe(Component);\n }, []);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment\n ComponentWithSchema.propTypes = propTypes;\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(\n props,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n ComponentWithSchema.toTypescript(),\n validationsMemo,\n nextValidationsMemo,\n );\n\n setValidationsMemo(nextValidationsMemo);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": "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",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/validation/validator.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
- "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", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,4BAAmD;AAE5C,MAAM,uBAAuB,CAAC,OAAgC,WAAiB;AACpF,SAAO,WAAW,QAAQ,CAAC,aAAa;AACtC,UAAM,eAAe,SAAS;AAC9B,UAAM,cAAc,MAAM;AAC1B,UAAM,oBAAoB,OAAO;AAEjC,UAAM,gBAAgB,SAAS;AAC/B,QAAI,sBAAsB;AAE1B,QAAI,SAAS,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,OAAO,SAAS,OAAO;AACpF,oDAAmB,OAAO,MAAM,SAAS;AAAA;AAE3C,QAAI,sBAAsB,eAAe,gBAAgB,MAAM;AAC7D,UACE,sBAAsB,YACtB,OAAO,UAAU,eAAe,KAAK,aAAa,eACjD,eAAc,SAAS,WAAW,cAAc,SAAS,aAC1D;AACA,8BAAsB;AAAA;AAGxB,UAAI,CAAC,cAAc,SAAS,sBAAsB,CAAC,cAAc,SAAS,gBAAgB,CAAC,qBAAqB;AAC9G,kDAAe,OAAO,MAAM,cAAc,aAAa;AAAA;AAAA;AAAA;AAAA;",
6
- "names": []
7
- }