@elliemae/ds-props-helpers 2.3.0-next.3 → 3.0.0-alpha.0

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 (174) hide show
  1. package/dist/cjs/defaultProps/index.js +28 -0
  2. package/dist/cjs/defaultProps/index.js.map +7 -0
  3. package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js +48 -0
  4. package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  5. package/dist/cjs/getProps/index.js +37 -0
  6. package/dist/cjs/getProps/index.js.map +7 -0
  7. package/dist/cjs/globalProps/constants.js +398 -0
  8. package/dist/cjs/globalProps/constants.js.map +7 -0
  9. package/dist/cjs/globalProps/globalAttributesPropTypes.js +398 -0
  10. package/dist/cjs/globalProps/globalAttributesPropTypes.js.map +7 -0
  11. package/dist/cjs/globalProps/index.js +29 -0
  12. package/dist/cjs/globalProps/index.js.map +7 -0
  13. package/dist/cjs/globalProps/useGetGlobalAttributes.js +56 -0
  14. package/dist/cjs/globalProps/useGetGlobalAttributes.js.map +7 -0
  15. package/dist/cjs/index.js +32 -0
  16. package/dist/cjs/index.js.map +7 -0
  17. package/dist/cjs/propTypes/PropTypes.js +136 -0
  18. package/dist/cjs/propTypes/PropTypes.js.map +7 -0
  19. package/dist/cjs/propTypes/customPropTypes.js +38 -0
  20. package/dist/cjs/propTypes/customPropTypes.js.map +7 -0
  21. package/dist/cjs/propTypes/describe.js +81 -0
  22. package/dist/cjs/propTypes/describe.js.map +7 -0
  23. package/dist/cjs/propTypes/describeConversions.js +96 -0
  24. package/dist/cjs/propTypes/describeConversions.js.map +7 -0
  25. package/dist/cjs/propTypes/describeGuards.js +49 -0
  26. package/dist/cjs/propTypes/describeGuards.js.map +7 -0
  27. package/dist/cjs/propTypes/index.js +37 -0
  28. package/dist/cjs/propTypes/index.js.map +7 -0
  29. package/dist/cjs/propTypes/toTypescript.js +139 -0
  30. package/dist/cjs/propTypes/toTypescript.js.map +7 -0
  31. package/dist/cjs/propTypes/types.js +27 -0
  32. package/dist/cjs/propTypes/types.js.map +7 -0
  33. package/dist/cjs/tests/globalProps/TestComponent.js +42 -0
  34. package/dist/cjs/tests/globalProps/TestComponent.js.map +7 -0
  35. package/dist/cjs/tests/validation/test.schema.js +67 -0
  36. package/dist/cjs/tests/validation/test.schema.js.map +7 -0
  37. package/dist/cjs/validation/errorTemplates.js +48 -0
  38. package/dist/cjs/validation/errorTemplates.js.map +7 -0
  39. package/dist/cjs/validation/index.js +30 -0
  40. package/dist/cjs/validation/index.js.map +7 -0
  41. package/dist/cjs/validation/typescriptGuards.js +65 -0
  42. package/dist/cjs/validation/typescriptGuards.js.map +7 -0
  43. package/dist/cjs/validation/typescriptParsers.js +76 -0
  44. package/dist/cjs/validation/typescriptParsers.js.map +7 -0
  45. package/dist/cjs/validation/typescriptValidator.js +171 -0
  46. package/dist/cjs/validation/typescriptValidator.js.map +7 -0
  47. package/dist/cjs/validation/validator.js +55 -0
  48. package/dist/cjs/validation/validator.js.map +7 -0
  49. package/dist/esm/defaultProps/index.js +3 -0
  50. package/dist/esm/defaultProps/index.js.map +7 -0
  51. package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js +19 -0
  52. package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  53. package/dist/esm/getProps/index.js +8 -0
  54. package/dist/esm/getProps/index.js.map +7 -0
  55. package/dist/esm/globalProps/constants.js +369 -0
  56. package/dist/esm/globalProps/constants.js.map +7 -0
  57. package/{esm → dist/esm}/globalProps/globalAttributesPropTypes.js +58 -67
  58. package/dist/esm/globalProps/globalAttributesPropTypes.js.map +7 -0
  59. package/dist/esm/globalProps/index.js +4 -0
  60. package/dist/esm/globalProps/index.js.map +7 -0
  61. package/dist/esm/globalProps/useGetGlobalAttributes.js +27 -0
  62. package/dist/esm/globalProps/useGetGlobalAttributes.js.map +7 -0
  63. package/dist/esm/index.js +7 -0
  64. package/dist/esm/index.js.map +7 -0
  65. package/dist/esm/propTypes/PropTypes.js +107 -0
  66. package/dist/esm/propTypes/PropTypes.js.map +7 -0
  67. package/dist/esm/propTypes/customPropTypes.js +9 -0
  68. package/dist/esm/propTypes/customPropTypes.js.map +7 -0
  69. package/dist/esm/propTypes/describe.js +52 -0
  70. package/dist/esm/propTypes/describe.js.map +7 -0
  71. package/dist/esm/propTypes/describeConversions.js +76 -0
  72. package/dist/esm/propTypes/describeConversions.js.map +7 -0
  73. package/dist/esm/propTypes/describeGuards.js +20 -0
  74. package/dist/esm/propTypes/describeGuards.js.map +7 -0
  75. package/dist/esm/propTypes/index.js +8 -0
  76. package/dist/esm/propTypes/index.js.map +7 -0
  77. package/dist/esm/propTypes/toTypescript.js +110 -0
  78. package/dist/esm/propTypes/toTypescript.js.map +7 -0
  79. package/dist/esm/propTypes/types.js +2 -0
  80. package/dist/esm/propTypes/types.js.map +7 -0
  81. package/dist/esm/tests/globalProps/TestComponent.js +13 -0
  82. package/dist/esm/tests/globalProps/TestComponent.js.map +7 -0
  83. package/dist/esm/tests/validation/test.schema.js +38 -0
  84. package/dist/esm/tests/validation/test.schema.js.map +7 -0
  85. package/dist/esm/validation/errorTemplates.js +19 -0
  86. package/dist/esm/validation/errorTemplates.js.map +7 -0
  87. package/dist/esm/validation/index.js +5 -0
  88. package/dist/esm/validation/index.js.map +7 -0
  89. package/dist/esm/validation/typescriptGuards.js +36 -0
  90. package/dist/esm/validation/typescriptGuards.js.map +7 -0
  91. package/dist/esm/validation/typescriptParsers.js +47 -0
  92. package/dist/esm/validation/typescriptParsers.js.map +7 -0
  93. package/dist/esm/validation/typescriptValidator.js +153 -0
  94. package/dist/esm/validation/typescriptValidator.js.map +7 -0
  95. package/dist/esm/validation/validator.js +26 -0
  96. package/dist/esm/validation/validator.js.map +7 -0
  97. package/{types → dist/types}/defaultProps/index.d.ts +0 -0
  98. package/{types → dist/types}/defaultProps/useMemoMergePropsWithDefault.d.ts +0 -0
  99. package/{types → dist/types}/getProps/index.d.ts +0 -0
  100. package/{types → dist/types}/globalProps/constants.d.ts +0 -0
  101. package/{types → dist/types}/globalProps/globalAttributesPropTypes.d.ts +0 -0
  102. package/{types → dist/types}/globalProps/index.d.ts +0 -0
  103. package/{types → dist/types}/globalProps/useGetGlobalAttributes.d.ts +0 -0
  104. package/{types → dist/types}/index.d.ts +0 -0
  105. package/{types → dist/types}/propTypes/PropTypes.d.ts +0 -0
  106. package/{types → dist/types}/propTypes/customPropTypes.d.ts +0 -0
  107. package/{types → dist/types}/propTypes/describe.d.ts +0 -0
  108. package/{types → dist/types}/propTypes/describeConversions.d.ts +0 -0
  109. package/{types → dist/types}/propTypes/describeGuards.d.ts +0 -0
  110. package/{types → dist/types}/propTypes/index.d.ts +0 -0
  111. package/{types → dist/types}/propTypes/toTypescript.d.ts +0 -0
  112. package/{types → dist/types}/propTypes/types.d.ts +1 -1
  113. package/{types → dist/types}/tests/globalProps/TestComponent.d.ts +0 -0
  114. package/{types → dist/types}/tests/globalProps/globalAttributes.test.d.ts +0 -0
  115. package/{types → dist/types}/tests/validation/any.validation.test.d.ts +0 -0
  116. package/{types → dist/types}/tests/validation/array.validation.test.d.ts +0 -0
  117. package/{types → dist/types}/tests/validation/boolean.validation.test.d.ts +0 -0
  118. package/{types → dist/types}/tests/validation/function.validation.test.d.ts +0 -0
  119. package/{types → dist/types}/tests/validation/number.validation.test.d.ts +0 -0
  120. package/{types → dist/types}/tests/validation/object.validation.test.d.ts +0 -0
  121. package/{types → dist/types}/tests/validation/schema.validation.test.d.ts +0 -0
  122. package/{types → dist/types}/tests/validation/string.validation.test.d.ts +0 -0
  123. package/{types → dist/types}/tests/validation/test.schema.d.ts +0 -0
  124. package/{types → dist/types}/tests/validation/union.validation.test.d.ts +0 -0
  125. package/{types → dist/types}/validation/errorTemplates.d.ts +0 -0
  126. package/{types → dist/types}/validation/index.d.ts +0 -0
  127. package/{types → dist/types}/validation/typescriptGuards.d.ts +0 -0
  128. package/{types → dist/types}/validation/typescriptParsers.d.ts +0 -0
  129. package/{types → dist/types}/validation/typescriptValidator.d.ts +0 -0
  130. package/{types → dist/types}/validation/validator.d.ts +0 -0
  131. package/package.json +71 -62
  132. package/cjs/defaultProps/index.js +0 -9
  133. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +0 -48
  134. package/cjs/getProps/index.js +0 -20
  135. package/cjs/globalProps/constants.js +0 -15
  136. package/cjs/globalProps/globalAttributesPropTypes.js +0 -382
  137. package/cjs/globalProps/index.js +0 -11
  138. package/cjs/globalProps/useGetGlobalAttributes.js +0 -36
  139. package/cjs/index.js +0 -28
  140. package/cjs/propTypes/PropTypes.js +0 -130
  141. package/cjs/propTypes/customPropTypes.js +0 -21
  142. package/cjs/propTypes/describe.js +0 -64
  143. package/cjs/propTypes/describeConversions.js +0 -104
  144. package/cjs/propTypes/describeGuards.js +0 -21
  145. package/cjs/propTypes/index.js +0 -11
  146. package/cjs/propTypes/toTypescript.js +0 -160
  147. package/cjs/propTypes/types.js +0 -2
  148. package/cjs/validation/errorTemplates.js +0 -16
  149. package/cjs/validation/index.js +0 -15
  150. package/cjs/validation/typescriptGuards.js +0 -36
  151. package/cjs/validation/typescriptParsers.js +0 -45
  152. package/cjs/validation/typescriptValidator.js +0 -208
  153. package/cjs/validation/validator.js +0 -36
  154. package/esm/defaultProps/index.js +0 -1
  155. package/esm/defaultProps/useMemoMergePropsWithDefault.js +0 -39
  156. package/esm/getProps/index.js +0 -15
  157. package/esm/globalProps/constants.js +0 -11
  158. package/esm/globalProps/index.js +0 -2
  159. package/esm/globalProps/useGetGlobalAttributes.js +0 -32
  160. package/esm/index.js +0 -9
  161. package/esm/propTypes/PropTypes.js +0 -124
  162. package/esm/propTypes/customPropTypes.js +0 -17
  163. package/esm/propTypes/describe.js +0 -62
  164. package/esm/propTypes/describeConversions.js +0 -96
  165. package/esm/propTypes/describeGuards.js +0 -10
  166. package/esm/propTypes/index.js +0 -2
  167. package/esm/propTypes/toTypescript.js +0 -154
  168. package/esm/propTypes/types.js +0 -1
  169. package/esm/validation/errorTemplates.js +0 -11
  170. package/esm/validation/index.js +0 -3
  171. package/esm/validation/typescriptGuards.js +0 -23
  172. package/esm/validation/typescriptParsers.js +0 -41
  173. package/esm/validation/typescriptValidator.js +0 -203
  174. package/esm/validation/validator.js +0 -32
@@ -1,41 +0,0 @@
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 = '';
11
- let shouldAppendToKey = true;
12
-
13
- const pushPair = () => {
14
- if (lastKey) keyValuePairs.push([lastKey, lastValue]);
15
- lastKey = '';
16
- lastValue = '';
17
- shouldAppendToKey = true;
18
- }; // Complex -- but working -- logic
19
-
20
-
21
- let depth = 0;
22
- format.split('').forEach(char => {
23
- if (char === '{') {
24
- depth += 1;
25
- if (depth > 1) lastValue += char;
26
- } else if (char === '}') {
27
- if (depth > 1) lastValue += char;
28
- depth -= 1;
29
- if (depth === 1) pushPair();
30
- } else if (char === ':') {
31
- shouldAppendToKey = false;
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;
36
- });
37
- pushPair();
38
- return keyValuePairs;
39
- };
40
-
41
- export { typescriptObjectParser };
@@ -1,203 +0,0 @@
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 { useState, useMemo } from 'react';
6
- import '../propTypes/PropTypes.js';
7
- import describe from '../propTypes/describe.js';
8
- import { throwRequiredError, throwTypeError } from './errorTemplates.js';
9
- import { isUndefined, isNull, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
10
- import { typescriptObjectParser } from './typescriptParsers.js';
11
-
12
- // =============================================================================
13
- // Atom Validators
14
- // =============================================================================
15
- // This functions will validate something from the data
16
- // and optionally recursively apply `validateValueWithFormat`
17
- // in smaller parts
18
- const validateUndefined = (schemaName, key, value, format) => {
19
- if (value !== undefined || value === 'undefined') {
20
- throwTypeError(schemaName, key, value, format);
21
- }
22
- };
23
-
24
- const validateNull = (schemaName, key, value, format) => {
25
- if (value !== null || value === 'null') {
26
- throwTypeError(schemaName, key, value, format);
27
- }
28
- };
29
-
30
- const validatePrimitiveType = (schemaName, key, value, format) => {
31
- if (typeof value !== format) {
32
- throwTypeError(schemaName, key, value, format);
33
- }
34
- };
35
-
36
- const validateString = (schemaName, key, value, format) => {
37
- if (value !== format.slice(1, -1)) {
38
- throwTypeError(schemaName, key, value, format);
39
- }
40
- };
41
-
42
- const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
43
- // Check that we have an array
44
- if (!Array.isArray(value)) {
45
- throwTypeError(schemaName, key, value, format);
46
- } // Check that each element inside satisfies the format
47
-
48
-
49
- value.forEach((val, index) => {
50
- // this is a recursive func, we need to invoke it before it's defined.
51
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
52
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
53
- });
54
- };
55
-
56
- function isObjectType(value) {
57
- return !(typeof value !== 'object' || Array.isArray(value));
58
- }
59
-
60
- const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
61
- const valuesIsObject = isObjectType(value); // Check that we have an object
62
-
63
- if (!valuesIsObject) {
64
- throwTypeError(schemaName, key, value, format);
65
- return;
66
- }
67
-
68
- if (format === 'object') return;
69
- const keyValuePairs = typescriptObjectParser(format); // Now we have the key - value pairs
70
- // Each key could either be required or not
71
- // Just recursively check the object
72
-
73
- keyValuePairs.forEach(_ref => {
74
- let [objectKey, objectValue] = _ref;
75
- const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
76
-
77
- if (trueKey === objectKey && !(trueKey in value)) {
78
- throwRequiredError(schemaName, key);
79
- }
80
-
81
- if (trueKey in value) {
82
- // this is a recursive func, we need to invoke it before it's defined.
83
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
84
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
85
- }
86
- });
87
- };
88
-
89
- const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
90
- const possibilities = format.split(/\s?\|\s?/);
91
- const errors = [];
92
- possibilities.forEach(possibility => {
93
- try {
94
- // this is a recursive func, we need to invoke it before it's defined.
95
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
96
- validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
97
- } catch (e) {
98
- errors.push(e);
99
- }
100
- });
101
-
102
- if (errors.length === possibilities.length) {
103
- throwTypeError(schemaName, key, value, format);
104
- }
105
- };
106
-
107
- const validateFunction = (schemaName, key, value, format) => {
108
- // Check that we have a function
109
- if (typeof value !== 'function') {
110
- throwTypeError(schemaName, key, value, format);
111
- }
112
- };
113
-
114
- function isJSXElement(value) {
115
- return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
116
- }
117
-
118
- const validateJSXorNode = (schemaName, key, value, format) => {
119
- const valueIsJSX = isJSXElement(value);
120
-
121
- if (format === 'JSX.Element' && !valueIsJSX) {
122
- throwTypeError(schemaName, key, value, format);
123
- }
124
- }; // =============================================================================
125
- // Schema validator
126
- // =============================================================================
127
-
128
-
129
- const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
130
- nextValidationsMemo[value] = format;
131
-
132
- if (value in validationsMemo) {
133
- // We already validated this value on this format
134
- return;
135
- }
136
-
137
- if (isUndefined(format)) {
138
- validateUndefined(schemaName, key, value, format);
139
- } else if (isNull(format)) {
140
- validateNull(schemaName, key, value, format);
141
- } else if (isPrimitiveType(format)) {
142
- validatePrimitiveType(schemaName, key, value, format);
143
- } else if (isUnion(format)) {
144
- validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
145
- } else if (isString(format)) {
146
- validateString(schemaName, key, value, format);
147
- } else if (isArray(format)) {
148
- validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
149
- } else if (isObject(format)) {
150
- validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
151
- } else if (isFunction(format)) {
152
- validateFunction(schemaName, key, value, format);
153
- } else if (isJSXorNode(format)) {
154
- validateJSXorNode(schemaName, key, value, format);
155
- } else if (isSomethingWithParenthesis(format)) {
156
- validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
157
- }
158
- };
159
-
160
- const validateTypescriptPropTypesImplementation = function (props, schema) {
161
- let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
162
- let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
163
- const {
164
- properties,
165
- name: schemaName
166
- } = schema;
167
- properties.forEach(property => {
168
- const {
169
- name,
170
- format,
171
- required
172
- } = property;
173
-
174
- if (required && !(name in props)) {
175
- throwRequiredError(schema.name, name);
176
- }
177
-
178
- if (name in props && (props[name] !== undefined || required)) {
179
- validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
180
- }
181
- });
182
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
-
184
- const useValidateTypescriptPropTypes = (props, propTypes) => {
185
- const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
186
-
187
- const ComponentWithSchema = useMemo(() => {
188
- const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
189
-
190
-
191
- return describe(Component);
192
- }, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
193
-
194
- ComponentWithSchema.propTypes = propTypes;
195
- useMemo(() => {
196
- const nextValidationsMemo = {};
197
- validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
198
- ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
199
- setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
200
- }, [props]);
201
- };
202
-
203
- export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
@@ -1,32 +0,0 @@
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
-
6
- const useValidatePropTypes = (props, schema) => {
7
- schema.properties.forEach(property => {
8
- const propertyName = property.name;
9
- const currentProp = props[propertyName];
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
-
16
- if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
17
- throwRequiredError(schema.name, property.name);
18
- }
19
-
20
- if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
21
- if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
22
- isValidReactElement = true;
23
- }
24
-
25
- if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
26
- throwTypeError(schema.name, propertyName, currentProp, currentFormat);
27
- }
28
- }
29
- });
30
- };
31
-
32
- export { useValidatePropTypes };