@orioro/util 0.1.0 → 0.3.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 (196) hide show
  1. package/dist/PromiseLikeEventEmitter/index.d.ts +10 -0
  2. package/dist/array/arrayChunk.d.ts +1 -0
  3. package/dist/array/index.d.ts +1 -0
  4. package/dist/debug/debugFn/index.d.ts +15 -0
  5. package/dist/debug/debugFn/util.d.ts +1 -0
  6. package/dist/debug/debugFn.d.ts +15 -0
  7. package/dist/debug/deepFreeze.d.ts +5 -0
  8. package/dist/debug/index.d.ts +3 -0
  9. package/dist/debug/wait.d.ts +1 -0
  10. package/dist/index.d.ts +9 -0
  11. package/dist/index.mjs +773 -763
  12. package/dist/interpolate/index.d.ts +14 -0
  13. package/dist/maybeFn.d.ts +1 -0
  14. package/dist/pickPaths/index.d.ts +4 -0
  15. package/dist/promise/batchFn.d.ts +47 -0
  16. package/dist/promise/index.d.ts +3 -0
  17. package/dist/promise/promiseReduce.d.ts +1 -0
  18. package/dist/promise/resolveNestedPromises.d.ts +14 -0
  19. package/dist/promise/types.d.ts +2 -0
  20. package/dist/resolvePaths/index.d.ts +4 -0
  21. package/dist/switchValue.d.ts +9 -0
  22. package/dist/typeOf.d.ts +7 -0
  23. package/dist/validate/async/index.d.ts +18 -0
  24. package/dist/validate/async/validateAsyncFn.d.ts +2 -0
  25. package/dist/validate/async/validators/index.d.ts +2 -0
  26. package/dist/validate/async/validators/logical.d.ts +4 -0
  27. package/dist/validate/async/validators/shape.d.ts +7 -0
  28. package/dist/validate/async/validators/tmpand.d.ts +2 -0
  29. package/dist/validate/async/validators/tmpor.d.ts +2 -0
  30. package/dist/validate/common/ValidationError.d.ts +11 -0
  31. package/dist/validate/common/util/defaultErrorMessage.d.ts +2 -0
  32. package/dist/validate/common/util/index.d.ts +3 -0
  33. package/dist/validate/common/util/parseValidatorInput.d.ts +5 -0
  34. package/dist/validate/common/util/resolveValidationResult.d.ts +6 -0
  35. package/dist/validate/common/validators/index.d.ts +1 -0
  36. package/dist/validate/common/validators/type.d.ts +9 -0
  37. package/dist/validate/index.d.ts +3 -0
  38. package/dist/validate/sync/index.d.ts +18 -0
  39. package/dist/validate/sync/validateSyncFn.d.ts +2 -0
  40. package/dist/validate/sync/validators/index.d.ts +2 -0
  41. package/dist/validate/sync/validators/logical.d.ts +4 -0
  42. package/dist/validate/sync/validators/shape.d.ts +7 -0
  43. package/dist/validate/types/async.d.ts +5 -0
  44. package/dist/validate/types/common.d.ts +27 -0
  45. package/dist/validate/types/index.d.ts +3 -0
  46. package/dist/validate/types/sync.d.ts +5 -0
  47. package/package.json +6 -2
  48. package/babel.config.cjs +0 -13
  49. package/coverage/clover.xml +0 -491
  50. package/coverage/coverage-final.json +0 -29
  51. package/coverage/lcov-report/ValidationError.ts.html +0 -184
  52. package/coverage/lcov-report/base.css +0 -224
  53. package/coverage/lcov-report/block-navigation.js +0 -87
  54. package/coverage/lcov-report/favicon.png +0 -0
  55. package/coverage/lcov-report/index.html +0 -296
  56. package/coverage/lcov-report/prettify.css +0 -1
  57. package/coverage/lcov-report/prettify.js +0 -2
  58. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  59. package/coverage/lcov-report/sorter.js +0 -196
  60. package/coverage/lcov-report/src/debug/deepFreeze.ts.html +0 -157
  61. package/coverage/lcov-report/src/debug/index.html +0 -146
  62. package/coverage/lcov-report/src/debug/index.ts.html +0 -91
  63. package/coverage/lcov-report/src/debug/wait.ts.html +0 -127
  64. package/coverage/lcov-report/src/index.html +0 -131
  65. package/coverage/lcov-report/src/interpolate/index.html +0 -116
  66. package/coverage/lcov-report/src/interpolate/index.ts.html +0 -277
  67. package/coverage/lcov-report/src/maybeFn.ts.html +0 -94
  68. package/coverage/lcov-report/src/promise/index.html +0 -146
  69. package/coverage/lcov-report/src/promise/index.ts.html +0 -91
  70. package/coverage/lcov-report/src/promise/promiseReduce.ts.html +0 -130
  71. package/coverage/lcov-report/src/promise/resolveNestedPromises.ts.html +0 -271
  72. package/coverage/lcov-report/src/switchValue.ts.html +0 -253
  73. package/coverage/lcov-report/src/typeOf.ts.html +0 -328
  74. package/coverage/lcov-report/src/validate/ValidationError.ts.html +0 -184
  75. package/coverage/lcov-report/src/validate/async/index.html +0 -131
  76. package/coverage/lcov-report/src/validate/async/index.ts.html +0 -241
  77. package/coverage/lcov-report/src/validate/async/parseValidator.ts.html +0 -136
  78. package/coverage/lcov-report/src/validate/async/validateAsyncFn.ts.html +0 -208
  79. package/coverage/lcov-report/src/validate/async/validators/and.ts.html +0 -154
  80. package/coverage/lcov-report/src/validate/async/validators/index.html +0 -146
  81. package/coverage/lcov-report/src/validate/async/validators/index.ts.html +0 -91
  82. package/coverage/lcov-report/src/validate/async/validators/logical.ts.html +0 -253
  83. package/coverage/lcov-report/src/validate/async/validators/or.ts.html +0 -151
  84. package/coverage/lcov-report/src/validate/async/validators/shape.ts.html +0 -565
  85. package/coverage/lcov-report/src/validate/common/ValidationError.ts.html +0 -184
  86. package/coverage/lcov-report/src/validate/common/index.html +0 -116
  87. package/coverage/lcov-report/src/validate/common/util/defaultErrorMessage.ts.html +0 -163
  88. package/coverage/lcov-report/src/validate/common/util/index.html +0 -161
  89. package/coverage/lcov-report/src/validate/common/util/index.ts.html +0 -94
  90. package/coverage/lcov-report/src/validate/common/util/parseValidator.ts.html +0 -316
  91. package/coverage/lcov-report/src/validate/common/util/parseValidatorInput.ts.html +0 -316
  92. package/coverage/lcov-report/src/validate/common/util/resolveValidationResult.ts.html +0 -277
  93. package/coverage/lcov-report/src/validate/common/util/validatorParser.ts.html +0 -316
  94. package/coverage/lcov-report/src/validate/common/validators/index.html +0 -131
  95. package/coverage/lcov-report/src/validate/common/validators/index.ts.html +0 -88
  96. package/coverage/lcov-report/src/validate/common/validators/type.ts.html +0 -388
  97. package/coverage/lcov-report/src/validate/fmtValidationResult.ts.html +0 -268
  98. package/coverage/lcov-report/src/validate/index.html +0 -116
  99. package/coverage/lcov-report/src/validate/index.ts.html +0 -94
  100. package/coverage/lcov-report/src/validate/makeValidate.ts.html +0 -634
  101. package/coverage/lcov-report/src/validate/specUtil/commonTests.js.html +0 -1324
  102. package/coverage/lcov-report/src/validate/specUtil/index.html +0 -116
  103. package/coverage/lcov-report/src/validate/sync/index.html +0 -131
  104. package/coverage/lcov-report/src/validate/sync/index.ts.html +0 -244
  105. package/coverage/lcov-report/src/validate/sync/parseValidator.ts.html +0 -136
  106. package/coverage/lcov-report/src/validate/sync/validateSyncFn.ts.html +0 -223
  107. package/coverage/lcov-report/src/validate/sync/validators/and.ts.html +0 -148
  108. package/coverage/lcov-report/src/validate/sync/validators/index.html +0 -146
  109. package/coverage/lcov-report/src/validate/sync/validators/index.ts.html +0 -91
  110. package/coverage/lcov-report/src/validate/sync/validators/logical.ts.html +0 -226
  111. package/coverage/lcov-report/src/validate/sync/validators/or.ts.html +0 -130
  112. package/coverage/lcov-report/src/validate/sync/validators/shape.ts.html +0 -523
  113. package/coverage/lcov-report/src/validate/sync/validators/type.ts.html +0 -154
  114. package/coverage/lcov-report/src/validate/syncValidators/and.ts.html +0 -157
  115. package/coverage/lcov-report/src/validate/syncValidators/index.html +0 -176
  116. package/coverage/lcov-report/src/validate/syncValidators/index.ts.html +0 -97
  117. package/coverage/lcov-report/src/validate/syncValidators/or.ts.html +0 -127
  118. package/coverage/lcov-report/src/validate/syncValidators/shape.ts.html +0 -559
  119. package/coverage/lcov-report/src/validate/syncValidators/string.ts.html +0 -163
  120. package/coverage/lcov-report/src/validate/syncValidators/type.ts.html +0 -154
  121. package/coverage/lcov-report/src/validate/util/defaultErrorMessage.ts.html +0 -169
  122. package/coverage/lcov-report/src/validate/util/index.html +0 -146
  123. package/coverage/lcov-report/src/validate/util/index.ts.html +0 -91
  124. package/coverage/lcov-report/src/validate/util/resolveValidationResult.ts.html +0 -253
  125. package/coverage/lcov-report/src/validate/validate.ts.html +0 -220
  126. package/coverage/lcov-report/src/validate/validateAsync.ts.html +0 -220
  127. package/coverage/lcov-report/src/validate/validators/and.ts.html +0 -157
  128. package/coverage/lcov-report/src/validate/validators/index.html +0 -176
  129. package/coverage/lcov-report/src/validate/validators/index.ts.html +0 -97
  130. package/coverage/lcov-report/src/validate/validators/or.ts.html +0 -127
  131. package/coverage/lcov-report/src/validate/validators/shape.ts.html +0 -541
  132. package/coverage/lcov-report/src/validate/validators/type.ts.html +0 -154
  133. package/coverage/lcov-report/src/validate_/ValidationError.ts.html +0 -184
  134. package/coverage/lcov-report/src/validate_/fmtValidationResult.ts.html +0 -268
  135. package/coverage/lcov-report/src/validate_/index.html +0 -161
  136. package/coverage/lcov-report/src/validate_/makeValidate.ts.html +0 -634
  137. package/coverage/lcov-report/src/validate_/validate.ts.html +0 -220
  138. package/coverage/lcov-report/switchValue.ts.html +0 -253
  139. package/coverage/lcov-report/typeOf.ts.html +0 -331
  140. package/coverage/lcov-report/validate.ts.html +0 -757
  141. package/coverage/lcov.info +0 -1056
  142. package/jest.config.js +0 -6
  143. package/rollup.config.mjs +0 -6
  144. package/src/PromiseLikeEventEmitter/index.ts +0 -35
  145. package/src/array/arrayChunk.ts +0 -7
  146. package/src/array/index.ts +0 -1
  147. package/src/debug/debugFn/index.ts +0 -48
  148. package/src/debug/debugFn/util.ts +0 -27
  149. package/src/debug/deepFreeze.ts +0 -26
  150. package/src/debug/index.ts +0 -3
  151. package/src/debug/wait.ts +0 -14
  152. package/src/index.ts +0 -8
  153. package/src/interpolate/index.spec.ts +0 -20
  154. package/src/interpolate/index.ts +0 -64
  155. package/src/maybeFn.ts +0 -3
  156. package/src/promise/batchFn.spec.ts +0 -92
  157. package/src/promise/batchFn.ts +0 -176
  158. package/src/promise/index.ts +0 -3
  159. package/src/promise/promiseReduce.ts +0 -15
  160. package/src/promise/resolveNestedPromises.spec.ts +0 -205
  161. package/src/promise/resolveNestedPromises.ts +0 -83
  162. package/src/promise/types.ts +0 -2
  163. package/src/switchValue.spec.ts +0 -30
  164. package/src/switchValue.ts +0 -59
  165. package/src/typeOf.spec.ts +0 -47
  166. package/src/typeOf.ts +0 -81
  167. package/src/validate/__snapshots__/index.spec.ts.snap +0 -9
  168. package/src/validate/async/index.spec.ts +0 -236
  169. package/src/validate/async/index.ts +0 -52
  170. package/src/validate/async/validateAsyncFn.ts +0 -41
  171. package/src/validate/async/validators/index.ts +0 -2
  172. package/src/validate/async/validators/logical.ts +0 -56
  173. package/src/validate/async/validators/shape.ts +0 -160
  174. package/src/validate/async/validators/tmpand.ts +0 -24
  175. package/src/validate/async/validators/tmpor.ts +0 -21
  176. package/src/validate/common/ValidationError.ts +0 -33
  177. package/src/validate/common/util/defaultErrorMessage.ts +0 -26
  178. package/src/validate/common/util/index.ts +0 -3
  179. package/src/validate/common/util/parseValidatorInput.ts +0 -77
  180. package/src/validate/common/util/resolveValidationResult.ts +0 -64
  181. package/src/validate/common/validators/index.ts +0 -1
  182. package/src/validate/common/validators/type.ts +0 -101
  183. package/src/validate/index.spec.ts +0 -5
  184. package/src/validate/index.ts +0 -3
  185. package/src/validate/specUtil/commonTests.js +0 -413
  186. package/src/validate/sync/index.spec.ts +0 -81
  187. package/src/validate/sync/index.ts +0 -53
  188. package/src/validate/sync/validateSyncFn.ts +0 -46
  189. package/src/validate/sync/validators/index.ts +0 -2
  190. package/src/validate/sync/validators/logical.ts +0 -47
  191. package/src/validate/sync/validators/shape.ts +0 -146
  192. package/src/validate/types/async.ts +0 -20
  193. package/src/validate/types/common.ts +0 -70
  194. package/src/validate/types/index.ts +0 -3
  195. package/src/validate/types/sync.ts +0 -20
  196. package/tsconfig.json +0 -11
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { getProperty } from 'dot-prop';
2
- import traverse from 'traverse';
3
- import copy from 'fast-copy';
4
1
  import EventEmitter from 'eventemitter3';
2
+ import copy from 'fast-copy';
3
+ import { getProperty, setProperty } from 'dot-prop';
4
+ import traverse from 'traverse';
5
5
 
6
6
  function _typeof(o) {
7
7
  "@babel/helpers - typeof";
@@ -13,340 +13,84 @@ function _typeof(o) {
13
13
  }, _typeof(o);
14
14
  }
15
15
 
16
- /*!
17
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
18
- *
19
- * Copyright (c) 2014-2017, Jon Schlinkert.
20
- * Released under the MIT License.
21
- */
22
-
23
- function isObject(o) {
24
- return Object.prototype.toString.call(o) === '[object Object]';
25
- }
26
- function isPlainObject(o) {
27
- var ctor, prot;
28
- if (isObject(o) === false) return false;
29
-
30
- // If has modified constructor
31
- ctor = o.constructor;
32
- if (ctor === undefined) return true;
33
-
34
- // If has modified prototype
35
- prot = ctor.prototype;
36
- if (isObject(prot) === false) return false;
16
+ /******************************************************************************
17
+ Copyright (c) Microsoft Corporation.
18
+
19
+ Permission to use, copy, modify, and/or distribute this software for any
20
+ purpose with or without fee is hereby granted.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
+ PERFORMANCE OF THIS SOFTWARE.
29
+ ***************************************************************************** */
30
+ /* global Reflect, Promise, SuppressedError, Symbol */
37
31
 
38
- // If constructor does not have an Object-specific method
39
- if (prot.hasOwnProperty('isPrototypeOf') === false) {
40
- return false;
32
+ var _extendStatics = function extendStatics(d, b) {
33
+ _extendStatics = Object.setPrototypeOf || {
34
+ __proto__: []
35
+ } instanceof Array && function (d, b) {
36
+ d.__proto__ = b;
37
+ } || function (d, b) {
38
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
39
+ };
40
+ return _extendStatics(d, b);
41
+ };
42
+ function __extends(d, b) {
43
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
44
+ _extendStatics(d, b);
45
+ function __() {
46
+ this.constructor = d;
41
47
  }
42
-
43
- // Most likely a plain Object
44
- return true;
45
- }
46
-
47
- //
48
- // The only role of this function is to let typescript
49
- // be aware of the available types
50
- //
51
- function typeMap(typeMap) {
52
- return typeMap;
48
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
53
49
  }
54
- function makeTypeOf(typeMap) {
55
- return function typeOf(value) {
56
- for (var typeName in typeMap) {
57
- if (typeMap[typeName](value)) {
58
- return typeName;
59
- }
50
+ var _assign = function __assign() {
51
+ _assign = Object.assign || function __assign(t) {
52
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
53
+ s = arguments[i];
54
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
60
55
  }
61
- return null;
62
- };
63
- }
64
- function basicType(typeName) {
65
- return function (value) {
66
- return _typeof(value) === typeName;
56
+ return t;
67
57
  };
68
- }
69
- var DEFAULT_TYPES = typeMap({
70
- //
71
- // Primitives
72
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values
73
- //
74
- "null": function _null(value) {
75
- return value === null;
76
- },
77
- undefined: basicType('undefined'),
78
- "boolean": basicType('boolean'),
79
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
80
- number: function number(value) {
81
- return typeof value === 'number' && !Number.isNaN(value);
82
- },
83
- bigint: basicType('bigint'),
84
- string: basicType('string'),
85
- symbol: basicType('symbol'),
86
- "function": basicType('function'),
87
- object: isPlainObject,
88
- array: function array(value) {
89
- return Array.isArray(value);
90
- },
91
- regexp: function regexp(value) {
92
- return value instanceof RegExp;
93
- },
94
- nan: function nan(value) {
95
- return Number.isNaN(value);
96
- },
97
- date: function date(value) {
98
- return value instanceof Date;
99
- },
100
- map: function map(value) {
101
- return value instanceof Map;
102
- },
103
- weakmap: function weakmap(value) {
104
- return value instanceof WeakMap;
105
- },
106
- set: function set(value) {
107
- return value instanceof Set;
108
- },
109
- weakset: function weakset(value) {
110
- return value instanceof WeakSet;
111
- },
112
- promise: function promise(value) {
113
- return value instanceof Promise;
114
- },
115
- error: function error(value) {
116
- return value instanceof Error;
117
- }
118
- });
119
- var typeOf = makeTypeOf(DEFAULT_TYPES);
120
-
121
- function testCriteria(criteria, input) {
122
- switch (_typeof(criteria)) {
123
- case 'function':
124
- {
125
- return criteria(input);
126
- }
127
- case 'object':
128
- {
129
- if (criteria instanceof RegExp) {
130
- return criteria.test(input);
131
- } else {
132
- throw new Error('Unsupported criteria');
133
- }
134
- }
135
- case 'string':
136
- case 'symbol':
137
- {
138
- return criteria === input;
139
- }
58
+ return _assign.apply(this, arguments);
59
+ };
60
+ function __rest(s, e) {
61
+ var t = {};
62
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
63
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
64
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
140
65
  }
66
+ return t;
141
67
  }
142
- function switchValue(input, cases) {
143
- if (Array.isArray(cases)) {
144
- var matching = cases.find(function (case_) {
145
- return case_.length === 1 || testCriteria(case_[0], input);
68
+ function __awaiter(thisArg, _arguments, P, generator) {
69
+ function adopt(value) {
70
+ return value instanceof P ? value : new P(function (resolve) {
71
+ resolve(value);
146
72
  });
147
- return matching ? matching.length === 1 ? matching[0] : matching[1] : undefined;
148
- } else {
149
- return cases[input] || cases["default"];
150
- }
151
- }
152
- function switchExec(input, cases) {
153
- var args = [];
154
- for (var _i = 2; _i < arguments.length; _i++) {
155
- args[_i - 2] = arguments[_i];
156
- }
157
- var fn = switchValue(input, cases);
158
- return fn.apply(void 0, args);
159
- }
160
-
161
- var TYPE_RE = /([a-z0-9]+)(\!)?$/i;
162
- var TYPE_SEPARATOR_RE = /\s*\|\s*/g;
163
- function parseSingleType(typeInput) {
164
- var match = typeInput.match(TYPE_RE);
165
- if (!match) {
166
- throw new Error("Invalid type ".concat(typeInput));
167
- } else {
168
- var typeName = match[1],
169
- requiredSignal = match[2];
170
- return {
171
- type: typeName,
172
- required: requiredSignal === '!'
173
- };
174
73
  }
175
- }
176
- function serializeExpectedTypes(expectedTypes) {
177
- return expectedTypes.map(function (expectedType) {
178
- return "".concat(expectedType.type).concat(expectedType.required ? '!' : '');
179
- }).join(' | ');
180
- }
181
- function parseExpectedTypes(expectedTypesInput) {
182
- switch (typeOf(expectedTypesInput)) {
183
- case 'string':
184
- {
185
- return expectedTypesInput.split(TYPE_SEPARATOR_RE).map(function (typeInput) {
186
- return parseSingleType(typeInput);
187
- });
188
- }
189
- case 'array':
190
- {
191
- return expectedTypesInput.map(function (expectedType) {
192
- return typeof expectedType === 'string' ? parseSingleType(expectedType) : expectedType;
193
- });
194
- }
195
- case 'object':
196
- {
197
- return [expectedTypesInput];
74
+ return new (P || (P = Promise))(function (resolve, reject) {
75
+ function fulfilled(value) {
76
+ try {
77
+ step(generator.next(value));
78
+ } catch (e) {
79
+ reject(e);
198
80
  }
199
- default:
200
- {
201
- throw new Error("Invalid expectedType ".concat(expectedTypesInput));
81
+ }
82
+ function rejected(value) {
83
+ try {
84
+ step(generator["throw"](value));
85
+ } catch (e) {
86
+ reject(e);
202
87
  }
203
- }
204
- }
205
- function typeValidator(expectedTypesInput) {
206
- var expectedTypes = parseExpectedTypes(expectedTypesInput);
207
- return function validateType(input) {
208
- var inputType = typeOf(input);
209
- var nullOrUndefined = function nullOrUndefined() {
210
- return expectedTypes.some(function (expectedType) {
211
- return expectedType.type === 'undefined' || expectedType.type === 'null' || expectedType.required === false;
212
- });
213
- };
214
- var isValid = switchExec(inputType, {
215
- "null": nullOrUndefined,
216
- undefined: nullOrUndefined,
217
- "default": function _default() {
218
- return expectedTypes.some(function (expectedType) {
219
- return expectedType.type === inputType;
220
- });
221
- }
222
- });
223
- if (isValid) {
224
- return true;
225
- } else {
226
- return {
227
- expectedTypes: serializeExpectedTypes(expectedTypes),
228
- input: input
229
- };
230
- }
231
- };
232
- }
233
-
234
- //
235
- // And operator (serial)
236
- //
237
- function and$1(validators) {
238
- return function validateAnd(input, _a) {
239
- var validateSync = _a.validateSync;
240
- var result = validators.reduce(function (acc, validator) {
241
- return acc !== true ? acc : validateSync(validator, input);
242
- }, true);
243
- if (result === true) {
244
- return true;
245
- } else {
246
- return result;
247
- }
248
- };
249
- }
250
- //
251
- // Or operator (serial)
252
- //
253
- function or$1(validators) {
254
- return function validateOr(input, _a) {
255
- var validateSync = _a.validateSync;
256
- var someIsValid = validators.some(function (validator) {
257
- return validateSync(validator, input) === true;
258
- });
259
- return someIsValid;
260
- };
261
- }
262
- //
263
- // Not
264
- //
265
- function not$1(validator) {
266
- return function validateNot(input, _a) {
267
- var validateSync = _a.validateSync;
268
- return validateSync(validator, input) !== true;
269
- };
270
- }
271
-
272
- /******************************************************************************
273
- Copyright (c) Microsoft Corporation.
274
-
275
- Permission to use, copy, modify, and/or distribute this software for any
276
- purpose with or without fee is hereby granted.
277
-
278
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
279
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
280
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
281
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
282
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
283
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
284
- PERFORMANCE OF THIS SOFTWARE.
285
- ***************************************************************************** */
286
- /* global Reflect, Promise, SuppressedError, Symbol */
287
-
288
- var _extendStatics = function extendStatics(d, b) {
289
- _extendStatics = Object.setPrototypeOf || {
290
- __proto__: []
291
- } instanceof Array && function (d, b) {
292
- d.__proto__ = b;
293
- } || function (d, b) {
294
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
295
- };
296
- return _extendStatics(d, b);
297
- };
298
- function __extends(d, b) {
299
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
300
- _extendStatics(d, b);
301
- function __() {
302
- this.constructor = d;
303
- }
304
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
305
- }
306
- var _assign = function __assign() {
307
- _assign = Object.assign || function __assign(t) {
308
- for (var s, i = 1, n = arguments.length; i < n; i++) {
309
- s = arguments[i];
310
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
311
- }
312
- return t;
313
- };
314
- return _assign.apply(this, arguments);
315
- };
316
- function __rest(s, e) {
317
- var t = {};
318
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
319
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
320
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
321
- }
322
- return t;
323
- }
324
- function __awaiter(thisArg, _arguments, P, generator) {
325
- function adopt(value) {
326
- return value instanceof P ? value : new P(function (resolve) {
327
- resolve(value);
328
- });
329
- }
330
- return new (P || (P = Promise))(function (resolve, reject) {
331
- function fulfilled(value) {
332
- try {
333
- step(generator.next(value));
334
- } catch (e) {
335
- reject(e);
336
- }
337
- }
338
- function rejected(value) {
339
- try {
340
- step(generator["throw"](value));
341
- } catch (e) {
342
- reject(e);
343
- }
344
- }
345
- function step(result) {
346
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
347
- }
348
- step((generator = generator.apply(thisArg, _arguments || [])).next());
349
- });
88
+ }
89
+ function step(result) {
90
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
91
+ }
92
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
93
+ });
350
94
  }
351
95
  function __generator(thisArg, body) {
352
96
  var _ = {
@@ -450,171 +194,121 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
450
194
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
451
195
  };
452
196
 
453
- function _shapeGeneralValidator$1(_a) {
454
- var input = _a.input,
455
- baseType = _a.baseType,
456
- collectNestedErrors = _a.collectNestedErrors,
457
- validateSync = _a.validateSync;
458
- var baseTypeValidation = validateSync(typeValidator({
459
- type: baseType,
460
- required: true
461
- }), input);
462
- if (baseTypeValidation !== true) {
463
- return baseTypeValidation;
197
+ var PromiseLikeEventEmitter = /** @class */function (_super) {
198
+ __extends(PromiseLikeEventEmitter, _super);
199
+ function PromiseLikeEventEmitter() {
200
+ var _this = _super.call(this) || this;
201
+ _this.promise = new Promise(function (resolve, reject) {
202
+ _this.resolve = resolve;
203
+ _this.reject = reject;
204
+ });
205
+ return _this;
464
206
  }
465
- var nestedErrors = collectNestedErrors();
466
- return nestedErrors.length === 0 ? true : {
467
- input: input,
468
- nestedErrors: nestedErrors
207
+ PromiseLikeEventEmitter.prototype.then = function (onFulfilled, onRejected) {
208
+ return this.promise.then(onFulfilled, onRejected);
469
209
  };
470
- }
471
- function obj$1(objShape) {
472
- return function validateObject(input, _a) {
473
- var validateSync = _a.validateSync;
474
- return _shapeGeneralValidator$1({
475
- input: input,
476
- baseType: 'object',
477
- validateSync: validateSync,
478
- collectNestedErrors: function collectNestedErrors() {
479
- return Object.entries(objShape).reduce(function (acc, _a) {
480
- var path = _a[0],
481
- pathValidator = _a[1];
482
- var pathInput = getProperty(input, path);
483
- var pathResult = validateSync(pathValidator, pathInput);
484
- return pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
485
- path: path
486
- })], false);
487
- }, []);
488
- }
489
- });
210
+ PromiseLikeEventEmitter.prototype["catch"] = function (onRejected) {
211
+ return this.promise["catch"](onRejected);
212
+ };
213
+ PromiseLikeEventEmitter.prototype["finally"] = function (onFinally) {
214
+ return this.promise["finally"](onFinally);
490
215
  };
216
+ return PromiseLikeEventEmitter;
217
+ }(EventEmitter);
218
+
219
+ function wait(ms, result) {
220
+ if (ms === void 0) {
221
+ ms = 1000;
222
+ }
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ return [2 /*return*/, new Promise(function (resolve, reject) {
226
+ setTimeout(function () {
227
+ if (result instanceof Error) {
228
+ reject(result);
229
+ } else {
230
+ resolve(result);
231
+ }
232
+ }, ms);
233
+ })];
234
+ });
235
+ });
491
236
  }
492
- function objOf$1(ofType) {
493
- return function validateObjOf(input, _a) {
494
- var validateSync = _a.validateSync;
495
- return _shapeGeneralValidator$1({
496
- input: input,
497
- baseType: 'object',
498
- validateSync: validateSync,
499
- collectNestedErrors: function collectNestedErrors() {
500
- return Object.entries(input).reduce(function (acc, _a) {
501
- var key = _a[0],
502
- keyInput = _a[1];
503
- var indexResult = validateSync(ofType, keyInput);
504
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
505
- path: key
506
- })], false);
507
- }, []);
237
+
238
+ function deepFreeze(object) {
239
+ Object.freeze(object);
240
+ if (Array.isArray(object)) {
241
+ // Handle the array case
242
+ object.forEach(function (item) {
243
+ if (item && _typeof(item) === 'object' && !Object.isFrozen(item)) {
244
+ deepFreeze(item);
508
245
  }
509
246
  });
510
- };
511
- }
512
- function tuple$1(tupleShape) {
513
- return function validateTuple(input, _a) {
514
- var validateSync = _a.validateSync;
515
- return _shapeGeneralValidator$1({
516
- input: input,
517
- baseType: 'array',
518
- validateSync: validateSync,
519
- collectNestedErrors: function collectNestedErrors() {
520
- return tupleShape.reduce(function (acc, indexValidator, index) {
521
- var indexInput = input[index];
522
- var indexResult = validateSync(indexValidator, indexInput);
523
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
524
- path: index + ''
525
- })], false);
526
- }, []);
247
+ } else {
248
+ // Handle the object case
249
+ Object.keys(object).forEach(function (key) {
250
+ var value = object[key];
251
+ if (value && _typeof(value) === 'object' && !Object.isFrozen(value)) {
252
+ deepFreeze(value);
527
253
  }
528
254
  });
529
- };
530
- }
531
- function arrayOf$1(ofType) {
532
- return function validateArrayOf(input, _a) {
533
- var validateSync = _a.validateSync;
534
- return _shapeGeneralValidator$1({
535
- input: input,
536
- baseType: 'array',
537
- validateSync: validateSync,
538
- collectNestedErrors: function collectNestedErrors() {
539
- return input.reduce(function (acc, indexInput, index) {
540
- var indexResult = validateSync(ofType, indexInput);
541
- return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
542
- path: index + ''
543
- })], false);
544
- }, []);
545
- }
546
- });
547
- };
255
+ }
256
+ return object;
548
257
  }
549
258
 
550
- function defaultErrorMessage(_a) {
551
- var input = _a.input,
552
- message = _a.message,
553
- nestedErrors = _a.nestedErrors,
554
- expectedTypes = _a.expectedTypes;
555
- if (message) {
556
- return message;
259
+ function stringifyReplacer(key, value) {
260
+ if (typeof value === 'function') {
261
+ // Convert functions to a consistent string representation
262
+ return "function:".concat(value.toString());
557
263
  }
558
- if (nestedErrors) {
559
- return "Invalid input: `".concat(JSON.stringify(input), "`.\n").concat(nestedErrors.map(function (error) {
560
- return " - ".concat(error.path, ": ").concat(error.message);
561
- }).join('\n'));
562
- } else if (expectedTypes) {
563
- var inputType = typeOf(input);
564
- return "Invalid input: '".concat(input, "'. Expected type(s) `").concat(expectedTypes, "`, but got type `").concat(inputType === null ? 'unknown' : inputType, "`");
565
- } else {
566
- return "Invalid input: '".concat(input, "'.");
264
+ return value;
265
+ }
266
+ function simpleHash(str) {
267
+ var hash = 0;
268
+ for (var i = 0; i < str.length; i++) {
269
+ var _char = str.charCodeAt(i);
270
+ hash = (hash << 5) - hash + _char;
271
+ hash |= 0; // Convert to 32bit integer
567
272
  }
273
+ // Ensure the hash is positive to avoid '-' signals
274
+ hash = Math.abs(hash);
275
+ return hash.toString(36); // Convert to base36 to ensure the result is alphanumeric
276
+ }
277
+ function generateDeterministicId(args) {
278
+ // Convert arguments to a JSON string using the custom replacer
279
+ var argsString = JSON.stringify(args, stringifyReplacer);
280
+ // Generate a simple hash of the string
281
+ return simpleHash(argsString);
568
282
  }
569
283
 
570
- function resolveValidationResult(_a) {
571
- var input = _a.input,
572
- result = _a.result,
573
- errorMessage = _a.errorMessage;
574
- if (result === true) {
575
- return true;
576
- } else {
577
- var _falseLikeResult = function _falseLikeResult() {
578
- return {
579
- message: errorMessage({
580
- input: input
581
- })
582
- };
583
- };
584
- return _assign({
585
- input: input
586
- }, switchExec(typeOf(result), {
587
- string: function string() {
588
- return {
589
- message: result
590
- };
591
- },
592
- error: function error() {
593
- return {
594
- message: result.message,
595
- error: result
596
- };
597
- },
598
- object: function object() {
599
- var result_ = result;
600
- return _assign(_assign({}, result_), {
601
- message: errorMessage(result_)
602
- });
603
- },
604
- //
605
- // Boolean result here MUST be false, as true was tested earlier
606
- //
607
- "boolean": _falseLikeResult,
608
- "null": _falseLikeResult,
609
- undefined: _falseLikeResult,
610
- //
611
- // Unsupported validation result
612
- //
613
- "default": function _default() {
614
- throw new Error("Invalid validation result: ".concat(result, " (").concat(typeOf(result), ")"));
615
- }
616
- }));
617
- }
284
+ function debugFn(fnName, fn, logCall, logResult) {
285
+ return function () {
286
+ var args = [];
287
+ for (var _i = 0; _i < arguments.length; _i++) {
288
+ args[_i] = arguments[_i];
289
+ }
290
+ var callId = generateDeterministicId(__spreadArray([fnName, fn], args, true));
291
+ if (typeof logCall === 'function') {
292
+ // Deep clone args, so that we may detect mutations later on
293
+ logCall({
294
+ type: 'call',
295
+ callId: callId,
296
+ args: copy(args),
297
+ fnName: fnName
298
+ });
299
+ }
300
+ var result = fn.apply(void 0, args);
301
+ if (typeof logResult === 'function') {
302
+ logResult({
303
+ type: 'result',
304
+ callId: callId,
305
+ args: args,
306
+ result: result,
307
+ fnName: fnName
308
+ });
309
+ }
310
+ return result;
311
+ };
618
312
  }
619
313
 
620
314
  /**
@@ -677,154 +371,43 @@ function interpolate(template, data, _a) {
677
371
  });
678
372
  }
679
373
 
680
- function parseValidatorInput(_a, validatorInput) {
681
- var objValidator = _a.objValidator;
682
- //
683
- // Parses the validator fn.
684
- // If provided with a string, will return a type validator
685
- // If provided with a function, will return the function itself
686
- //
687
- function _parseValidatorFn(fnInput) {
688
- switch (typeOf(fnInput)) {
689
- case 'string':
690
- {
691
- return typeValidator(fnInput);
692
- }
693
- case 'object':
694
- {
695
- return objValidator(fnInput);
696
- }
697
- case 'function':
698
- {
699
- return fnInput;
700
- }
701
- default:
702
- {
703
- throw new TypeError("Unsupported fnInput ".concat(fnInput));
704
- }
705
- }
706
- }
707
- function _parseValidatorErrorMessageFn(fnInput) {
708
- switch (_typeof(fnInput)) {
709
- case 'string':
710
- {
711
- return function (details) {
712
- return interpolate(fnInput, details);
713
- };
714
- }
715
- case 'function':
716
- {
717
- return fnInput;
718
- }
719
- default:
720
- {
721
- throw new TypeError("Unsupported error message input ".concat(fnInput));
722
- }
723
- }
374
+ function maybeFn(input) {
375
+ var args = [];
376
+ for (var _i = 1; _i < arguments.length; _i++) {
377
+ args[_i - 1] = arguments[_i];
724
378
  }
725
- //
726
- // Parses the validator input. For more details, see:
727
- // types/common.ts -> ValidatorSystem
728
- //
729
- // Ensures the return result is always of the following format:
730
- // [ValidatorFn, ValidatorErrorMessageInput]
731
- //
732
- var _b = Array.isArray(validatorInput) ? validatorInput : [validatorInput, defaultErrorMessage],
733
- fnInput = _b[0],
734
- errorMessageInput = _b[1];
735
- return [_parseValidatorFn(fnInput), _parseValidatorErrorMessageFn(errorMessageInput)];
379
+ return typeof input === 'function' ? input.apply(void 0, args) : input;
736
380
  }
737
381
 
738
- function validateSyncFn(validatorInput, input) {
739
- var result;
740
- var _a = parseValidatorInput({
741
- objValidator: obj$1
742
- }, validatorInput),
743
- validatorFn = _a[0],
744
- errorMessage = _a[1];
745
- try {
746
- result = validatorFn(input, {
747
- validateSync: validateSyncFn
382
+ function pickPaths(sourceObj, paths) {
383
+ return paths.reduce(function (acc, path) {
384
+ var _a = Array.isArray(path) ? path : [path, path],
385
+ targetPath = _a[0],
386
+ resolver = _a[1];
387
+ var value = typeof resolver === 'string' ? getProperty(sourceObj, resolver) : resolver(sourceObj);
388
+ return setProperty(acc, targetPath, value);
389
+ }, {});
390
+ }
391
+
392
+ function promiseReduce(inputArr, reducerFn, initial) {
393
+ return inputArr.reduce(function (prevPromise, input, index) {
394
+ return prevPromise.then(function (acc) {
395
+ return reducerFn(acc, input, index);
748
396
  });
749
- } catch (err) {
750
- result = err;
751
- }
752
- if (result instanceof Promise) {
753
- throw new Error('Promises not supported in sync validation method');
754
- }
755
- return resolveValidationResult({
756
- errorMessage: errorMessage,
757
- input: input,
758
- result: result
759
- });
397
+ }, Promise.resolve(initial));
760
398
  }
761
399
 
762
- var ValidationError = /** @class */function (_super) {
763
- __extends(ValidationError, _super);
764
- function ValidationError(_a) {
765
- var _this = this;
766
- var message = _a.message,
767
- details = __rest(_a, ["message"]);
768
- _this = _super.call(this, message || "Invalid input ".concat(details.input)) || this;
769
- _this.name = 'ValidationError';
770
- // Capture correct stack trace in V8 environments (Node.js, Google Chrome)
771
- if (Error.captureStackTrace) {
772
- Error.captureStackTrace(_this, ValidationError);
773
- }
774
- Object.assign(_this, details);
775
- return _this;
776
- }
777
- ValidationError.prototype.toJSON = function () {
778
- return {
779
- message: this.message,
780
- input: this.input,
781
- code: this.code,
782
- error: this.error,
783
- path: this.path,
784
- nestedErrors: this.nestedErrors
785
- };
786
- };
787
- return ValidationError;
788
- }(Error);
789
-
790
- function assertValidSync(validator, input) {
791
- var validationResult = validate(validator, input);
792
- if (validationResult === true) {
793
- return input;
794
- } else {
795
- throw new ValidationError(validationResult);
796
- }
797
- }
798
- var validate = validateSyncFn;
799
- validate.type = typeValidator;
800
- validate.obj = obj$1;
801
- validate.objOf = objOf$1;
802
- validate.tuple = tuple$1;
803
- validate.arrayOf = arrayOf$1;
804
- validate.and = and$1;
805
- validate.or = or$1;
806
- validate.not = not$1;
807
- validate.assertValid = assertValidSync;
808
-
809
- function promiseReduce(inputArr, reducerFn, initial) {
810
- return inputArr.reduce(function (prevPromise, input, index) {
811
- return prevPromise.then(function (acc) {
812
- return reducerFn(acc, input, index);
813
- });
814
- }, Promise.resolve(initial));
815
- }
816
-
817
- var DEFAULT_OPTIONS = {
818
- mode: 'eager',
819
- maxDepth: 30,
820
- clone: copy
821
- };
822
- function _echo(input) {
823
- return input;
824
- }
825
- function resolveNestedPromises(node, options, ctx) {
826
- if (options === void 0) {
827
- options = {};
400
+ var DEFAULT_OPTIONS = {
401
+ mode: 'eager',
402
+ maxDepth: 30,
403
+ clone: copy
404
+ };
405
+ function _echo(input) {
406
+ return input;
407
+ }
408
+ function resolveNestedPromises(node, options, ctx) {
409
+ if (options === void 0) {
410
+ options = {};
828
411
  }
829
412
  if (ctx === void 0) {
830
413
  ctx = {
@@ -893,28 +476,6 @@ function arrayChunk(array, chunkSize) {
893
476
  return chunks;
894
477
  }
895
478
 
896
- var PromiseLikeEventEmitter = /** @class */function (_super) {
897
- __extends(PromiseLikeEventEmitter, _super);
898
- function PromiseLikeEventEmitter() {
899
- var _this = _super.call(this) || this;
900
- _this.promise = new Promise(function (resolve, reject) {
901
- _this.resolve = resolve;
902
- _this.reject = reject;
903
- });
904
- return _this;
905
- }
906
- PromiseLikeEventEmitter.prototype.then = function (onFulfilled, onRejected) {
907
- return this.promise.then(onFulfilled, onRejected);
908
- };
909
- PromiseLikeEventEmitter.prototype["catch"] = function (onRejected) {
910
- return this.promise["catch"](onRejected);
911
- };
912
- PromiseLikeEventEmitter.prototype["finally"] = function (onFinally) {
913
- return this.promise["finally"](onFinally);
914
- };
915
- return PromiseLikeEventEmitter;
916
- }(EventEmitter);
917
-
918
479
  var SKIPPED = Symbol();
919
480
  function batchFn(fn, _a) {
920
481
  var _b = _a === void 0 ? {} : _a,
@@ -1021,28 +582,580 @@ function batchFn(fn, _a) {
1021
582
  return promise;
1022
583
  };
1023
584
  }
1024
- function parseBatchedResults(inputs, results) {
1025
- return results.reduce(function (acc, result, index) {
1026
- if (result === SKIPPED) {
1027
- return _assign(_assign({}, acc), {
1028
- skipped: __spreadArray(__spreadArray([], acc.skipped, true), [inputs[index]], false)
1029
- });
1030
- } else if (result instanceof Error) {
1031
- return _assign(_assign({}, acc), {
1032
- errors: __spreadArray(__spreadArray([], acc.errors, true), [result], false)
1033
- });
1034
- } else {
1035
- return _assign(_assign({}, acc), {
1036
- results: __spreadArray(__spreadArray([], acc.results, true), [result], false)
1037
- });
585
+ function parseBatchedResults(inputs, results) {
586
+ return results.reduce(function (acc, result, index) {
587
+ if (result === SKIPPED) {
588
+ return _assign(_assign({}, acc), {
589
+ skipped: __spreadArray(__spreadArray([], acc.skipped, true), [inputs[index]], false)
590
+ });
591
+ } else if (result instanceof Error) {
592
+ return _assign(_assign({}, acc), {
593
+ errors: __spreadArray(__spreadArray([], acc.errors, true), [result], false)
594
+ });
595
+ } else {
596
+ return _assign(_assign({}, acc), {
597
+ results: __spreadArray(__spreadArray([], acc.results, true), [result], false)
598
+ });
599
+ }
600
+ }, {
601
+ results: [],
602
+ errors: [],
603
+ skipped: []
604
+ });
605
+ }
606
+
607
+ function testCriteria(criteria, input) {
608
+ switch (_typeof(criteria)) {
609
+ case 'function':
610
+ {
611
+ return criteria(input);
612
+ }
613
+ case 'object':
614
+ {
615
+ if (criteria instanceof RegExp) {
616
+ return criteria.test(input);
617
+ } else {
618
+ throw new Error('Unsupported criteria');
619
+ }
620
+ }
621
+ case 'string':
622
+ case 'symbol':
623
+ {
624
+ return criteria === input;
625
+ }
626
+ }
627
+ }
628
+ function switchValue(input, cases) {
629
+ if (Array.isArray(cases)) {
630
+ var matching = cases.find(function (case_) {
631
+ return case_.length === 1 || testCriteria(case_[0], input);
632
+ });
633
+ return matching ? matching.length === 1 ? matching[0] : matching[1] : undefined;
634
+ } else {
635
+ return cases[input] || cases["default"];
636
+ }
637
+ }
638
+ function switchExec(input, cases) {
639
+ var args = [];
640
+ for (var _i = 2; _i < arguments.length; _i++) {
641
+ args[_i - 2] = arguments[_i];
642
+ }
643
+ var fn = switchValue(input, cases);
644
+ return fn.apply(void 0, args);
645
+ }
646
+
647
+ /*!
648
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
649
+ *
650
+ * Copyright (c) 2014-2017, Jon Schlinkert.
651
+ * Released under the MIT License.
652
+ */
653
+
654
+ function isObject(o) {
655
+ return Object.prototype.toString.call(o) === '[object Object]';
656
+ }
657
+ function isPlainObject(o) {
658
+ var ctor, prot;
659
+ if (isObject(o) === false) return false;
660
+
661
+ // If has modified constructor
662
+ ctor = o.constructor;
663
+ if (ctor === undefined) return true;
664
+
665
+ // If has modified prototype
666
+ prot = ctor.prototype;
667
+ if (isObject(prot) === false) return false;
668
+
669
+ // If constructor does not have an Object-specific method
670
+ if (prot.hasOwnProperty('isPrototypeOf') === false) {
671
+ return false;
672
+ }
673
+
674
+ // Most likely a plain Object
675
+ return true;
676
+ }
677
+
678
+ //
679
+ // The only role of this function is to let typescript
680
+ // be aware of the available types
681
+ //
682
+ function typeMap(typeMap) {
683
+ return typeMap;
684
+ }
685
+ function makeTypeOf(typeMap) {
686
+ return function typeOf(value) {
687
+ for (var typeName in typeMap) {
688
+ if (typeMap[typeName](value)) {
689
+ return typeName;
690
+ }
691
+ }
692
+ return null;
693
+ };
694
+ }
695
+ function basicType(typeName) {
696
+ return function (value) {
697
+ return _typeof(value) === typeName;
698
+ };
699
+ }
700
+ var DEFAULT_TYPES = typeMap({
701
+ //
702
+ // Primitives
703
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values
704
+ //
705
+ "null": function _null(value) {
706
+ return value === null;
707
+ },
708
+ undefined: basicType('undefined'),
709
+ "boolean": basicType('boolean'),
710
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
711
+ number: function number(value) {
712
+ return typeof value === 'number' && !Number.isNaN(value);
713
+ },
714
+ bigint: basicType('bigint'),
715
+ string: basicType('string'),
716
+ symbol: basicType('symbol'),
717
+ "function": basicType('function'),
718
+ object: isPlainObject,
719
+ array: function array(value) {
720
+ return Array.isArray(value);
721
+ },
722
+ regexp: function regexp(value) {
723
+ return value instanceof RegExp;
724
+ },
725
+ nan: function nan(value) {
726
+ return Number.isNaN(value);
727
+ },
728
+ date: function date(value) {
729
+ return value instanceof Date;
730
+ },
731
+ map: function map(value) {
732
+ return value instanceof Map;
733
+ },
734
+ weakmap: function weakmap(value) {
735
+ return value instanceof WeakMap;
736
+ },
737
+ set: function set(value) {
738
+ return value instanceof Set;
739
+ },
740
+ weakset: function weakset(value) {
741
+ return value instanceof WeakSet;
742
+ },
743
+ promise: function promise(value) {
744
+ return value instanceof Promise;
745
+ },
746
+ error: function error(value) {
747
+ return value instanceof Error;
748
+ }
749
+ });
750
+ var typeOf = makeTypeOf(DEFAULT_TYPES);
751
+
752
+ var TYPE_RE = /([a-z0-9]+)(\!)?$/i;
753
+ var TYPE_SEPARATOR_RE = /\s*\|\s*/g;
754
+ function parseSingleType(typeInput) {
755
+ var match = typeInput.match(TYPE_RE);
756
+ if (!match) {
757
+ throw new Error("Invalid type ".concat(typeInput));
758
+ } else {
759
+ var typeName = match[1],
760
+ requiredSignal = match[2];
761
+ return {
762
+ type: typeName,
763
+ required: requiredSignal === '!'
764
+ };
765
+ }
766
+ }
767
+ function serializeExpectedTypes(expectedTypes) {
768
+ return expectedTypes.map(function (expectedType) {
769
+ return "".concat(expectedType.type).concat(expectedType.required ? '!' : '');
770
+ }).join(' | ');
771
+ }
772
+ function parseExpectedTypes(expectedTypesInput) {
773
+ switch (typeOf(expectedTypesInput)) {
774
+ case 'string':
775
+ {
776
+ return expectedTypesInput.split(TYPE_SEPARATOR_RE).map(function (typeInput) {
777
+ return parseSingleType(typeInput);
778
+ });
779
+ }
780
+ case 'array':
781
+ {
782
+ return expectedTypesInput.map(function (expectedType) {
783
+ return typeof expectedType === 'string' ? parseSingleType(expectedType) : expectedType;
784
+ });
785
+ }
786
+ case 'object':
787
+ {
788
+ return [expectedTypesInput];
789
+ }
790
+ default:
791
+ {
792
+ throw new Error("Invalid expectedType ".concat(expectedTypesInput));
793
+ }
794
+ }
795
+ }
796
+ function typeValidator(expectedTypesInput) {
797
+ var expectedTypes = parseExpectedTypes(expectedTypesInput);
798
+ return function validateType(input) {
799
+ var inputType = typeOf(input);
800
+ var nullOrUndefined = function nullOrUndefined() {
801
+ return expectedTypes.some(function (expectedType) {
802
+ return expectedType.type === 'undefined' || expectedType.type === 'null' || expectedType.required === false;
803
+ });
804
+ };
805
+ var isValid = switchExec(inputType, {
806
+ "null": nullOrUndefined,
807
+ undefined: nullOrUndefined,
808
+ "default": function _default() {
809
+ return expectedTypes.some(function (expectedType) {
810
+ return expectedType.type === inputType;
811
+ });
812
+ }
813
+ });
814
+ if (isValid) {
815
+ return true;
816
+ } else {
817
+ return {
818
+ expectedTypes: serializeExpectedTypes(expectedTypes),
819
+ input: input
820
+ };
821
+ }
822
+ };
823
+ }
824
+
825
+ //
826
+ // And operator (serial)
827
+ //
828
+ function and$1(validators) {
829
+ return function validateAnd(input, _a) {
830
+ var validateSync = _a.validateSync;
831
+ var result = validators.reduce(function (acc, validator) {
832
+ return acc !== true ? acc : validateSync(validator, input);
833
+ }, true);
834
+ if (result === true) {
835
+ return true;
836
+ } else {
837
+ return result;
838
+ }
839
+ };
840
+ }
841
+ //
842
+ // Or operator (serial)
843
+ //
844
+ function or$1(validators) {
845
+ return function validateOr(input, _a) {
846
+ var validateSync = _a.validateSync;
847
+ var someIsValid = validators.some(function (validator) {
848
+ return validateSync(validator, input) === true;
849
+ });
850
+ return someIsValid;
851
+ };
852
+ }
853
+ //
854
+ // Not
855
+ //
856
+ function not$1(validator) {
857
+ return function validateNot(input, _a) {
858
+ var validateSync = _a.validateSync;
859
+ return validateSync(validator, input) !== true;
860
+ };
861
+ }
862
+
863
+ function _shapeGeneralValidator$1(_a) {
864
+ var input = _a.input,
865
+ baseType = _a.baseType,
866
+ collectNestedErrors = _a.collectNestedErrors,
867
+ validateSync = _a.validateSync;
868
+ var baseTypeValidation = validateSync(typeValidator({
869
+ type: baseType,
870
+ required: true
871
+ }), input);
872
+ if (baseTypeValidation !== true) {
873
+ return baseTypeValidation;
874
+ }
875
+ var nestedErrors = collectNestedErrors();
876
+ return nestedErrors.length === 0 ? true : {
877
+ input: input,
878
+ nestedErrors: nestedErrors
879
+ };
880
+ }
881
+ function obj$1(objShape) {
882
+ return function validateObject(input, _a) {
883
+ var validateSync = _a.validateSync;
884
+ return _shapeGeneralValidator$1({
885
+ input: input,
886
+ baseType: 'object',
887
+ validateSync: validateSync,
888
+ collectNestedErrors: function collectNestedErrors() {
889
+ return Object.entries(objShape).reduce(function (acc, _a) {
890
+ var path = _a[0],
891
+ pathValidator = _a[1];
892
+ var pathInput = getProperty(input, path);
893
+ var pathResult = validateSync(pathValidator, pathInput);
894
+ return pathResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, pathResult), {
895
+ path: path
896
+ })], false);
897
+ }, []);
898
+ }
899
+ });
900
+ };
901
+ }
902
+ function objOf$1(ofType) {
903
+ return function validateObjOf(input, _a) {
904
+ var validateSync = _a.validateSync;
905
+ return _shapeGeneralValidator$1({
906
+ input: input,
907
+ baseType: 'object',
908
+ validateSync: validateSync,
909
+ collectNestedErrors: function collectNestedErrors() {
910
+ return Object.entries(input).reduce(function (acc, _a) {
911
+ var key = _a[0],
912
+ keyInput = _a[1];
913
+ var indexResult = validateSync(ofType, keyInput);
914
+ return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
915
+ path: key
916
+ })], false);
917
+ }, []);
918
+ }
919
+ });
920
+ };
921
+ }
922
+ function tuple$1(tupleShape) {
923
+ return function validateTuple(input, _a) {
924
+ var validateSync = _a.validateSync;
925
+ return _shapeGeneralValidator$1({
926
+ input: input,
927
+ baseType: 'array',
928
+ validateSync: validateSync,
929
+ collectNestedErrors: function collectNestedErrors() {
930
+ return tupleShape.reduce(function (acc, indexValidator, index) {
931
+ var indexInput = input[index];
932
+ var indexResult = validateSync(indexValidator, indexInput);
933
+ return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
934
+ path: index + ''
935
+ })], false);
936
+ }, []);
937
+ }
938
+ });
939
+ };
940
+ }
941
+ function arrayOf$1(ofType) {
942
+ return function validateArrayOf(input, _a) {
943
+ var validateSync = _a.validateSync;
944
+ return _shapeGeneralValidator$1({
945
+ input: input,
946
+ baseType: 'array',
947
+ validateSync: validateSync,
948
+ collectNestedErrors: function collectNestedErrors() {
949
+ return input.reduce(function (acc, indexInput, index) {
950
+ var indexResult = validateSync(ofType, indexInput);
951
+ return indexResult === true ? acc : __spreadArray(__spreadArray([], acc, true), [_assign(_assign({}, indexResult), {
952
+ path: index + ''
953
+ })], false);
954
+ }, []);
955
+ }
956
+ });
957
+ };
958
+ }
959
+
960
+ function defaultErrorMessage(_a) {
961
+ var input = _a.input,
962
+ message = _a.message,
963
+ nestedErrors = _a.nestedErrors,
964
+ expectedTypes = _a.expectedTypes;
965
+ if (message) {
966
+ return message;
967
+ }
968
+ if (nestedErrors) {
969
+ return "Invalid input: `".concat(JSON.stringify(input), "`.\n").concat(nestedErrors.map(function (error) {
970
+ return " - ".concat(error.path, ": ").concat(error.message);
971
+ }).join('\n'));
972
+ } else if (expectedTypes) {
973
+ var inputType = typeOf(input);
974
+ return "Invalid input: '".concat(input, "'. Expected type(s) `").concat(expectedTypes, "`, but got type `").concat(inputType === null ? 'unknown' : inputType, "`");
975
+ } else {
976
+ return "Invalid input: '".concat(input, "'.");
977
+ }
978
+ }
979
+
980
+ function resolveValidationResult(_a) {
981
+ var input = _a.input,
982
+ result = _a.result,
983
+ errorMessage = _a.errorMessage;
984
+ if (result === true) {
985
+ return true;
986
+ } else {
987
+ var _falseLikeResult = function _falseLikeResult() {
988
+ return {
989
+ message: errorMessage({
990
+ input: input
991
+ })
992
+ };
993
+ };
994
+ return _assign({
995
+ input: input
996
+ }, switchExec(typeOf(result), {
997
+ string: function string() {
998
+ return {
999
+ message: result
1000
+ };
1001
+ },
1002
+ error: function error() {
1003
+ return {
1004
+ message: result.message,
1005
+ error: result
1006
+ };
1007
+ },
1008
+ object: function object() {
1009
+ var result_ = result;
1010
+ return _assign(_assign({}, result_), {
1011
+ message: errorMessage(result_)
1012
+ });
1013
+ },
1014
+ //
1015
+ // Boolean result here MUST be false, as true was tested earlier
1016
+ //
1017
+ "boolean": _falseLikeResult,
1018
+ "null": _falseLikeResult,
1019
+ undefined: _falseLikeResult,
1020
+ //
1021
+ // Unsupported validation result
1022
+ //
1023
+ "default": function _default() {
1024
+ throw new Error("Invalid validation result: ".concat(result, " (").concat(typeOf(result), ")"));
1025
+ }
1026
+ }));
1027
+ }
1028
+ }
1029
+
1030
+ function parseValidatorInput(_a, validatorInput) {
1031
+ var objValidator = _a.objValidator;
1032
+ //
1033
+ // Parses the validator fn.
1034
+ // If provided with a string, will return a type validator
1035
+ // If provided with a function, will return the function itself
1036
+ //
1037
+ function _parseValidatorFn(fnInput) {
1038
+ switch (typeOf(fnInput)) {
1039
+ case 'string':
1040
+ {
1041
+ return typeValidator(fnInput);
1042
+ }
1043
+ case 'object':
1044
+ {
1045
+ return objValidator(fnInput);
1046
+ }
1047
+ case 'function':
1048
+ {
1049
+ return fnInput;
1050
+ }
1051
+ default:
1052
+ {
1053
+ throw new TypeError("Unsupported fnInput ".concat(fnInput));
1054
+ }
1038
1055
  }
1039
- }, {
1040
- results: [],
1041
- errors: [],
1042
- skipped: []
1056
+ }
1057
+ function _parseValidatorErrorMessageFn(fnInput) {
1058
+ switch (_typeof(fnInput)) {
1059
+ case 'string':
1060
+ {
1061
+ return function (details) {
1062
+ return interpolate(fnInput, details);
1063
+ };
1064
+ }
1065
+ case 'function':
1066
+ {
1067
+ return fnInput;
1068
+ }
1069
+ default:
1070
+ {
1071
+ throw new TypeError("Unsupported error message input ".concat(fnInput));
1072
+ }
1073
+ }
1074
+ }
1075
+ //
1076
+ // Parses the validator input. For more details, see:
1077
+ // types/common.ts -> ValidatorSystem
1078
+ //
1079
+ // Ensures the return result is always of the following format:
1080
+ // [ValidatorFn, ValidatorErrorMessageInput]
1081
+ //
1082
+ var _b = Array.isArray(validatorInput) ? validatorInput : [validatorInput, defaultErrorMessage],
1083
+ fnInput = _b[0],
1084
+ errorMessageInput = _b[1];
1085
+ return [_parseValidatorFn(fnInput), _parseValidatorErrorMessageFn(errorMessageInput)];
1086
+ }
1087
+
1088
+ function validateSyncFn(validatorInput, input) {
1089
+ var result;
1090
+ var _a = parseValidatorInput({
1091
+ objValidator: obj$1
1092
+ }, validatorInput),
1093
+ validatorFn = _a[0],
1094
+ errorMessage = _a[1];
1095
+ try {
1096
+ result = validatorFn(input, {
1097
+ validateSync: validateSyncFn
1098
+ });
1099
+ } catch (err) {
1100
+ result = err;
1101
+ }
1102
+ if (result instanceof Promise) {
1103
+ throw new Error('Promises not supported in sync validation method');
1104
+ }
1105
+ return resolveValidationResult({
1106
+ errorMessage: errorMessage,
1107
+ input: input,
1108
+ result: result
1043
1109
  });
1044
1110
  }
1045
1111
 
1112
+ var ValidationError = /** @class */function (_super) {
1113
+ __extends(ValidationError, _super);
1114
+ function ValidationError(_a) {
1115
+ var _this = this;
1116
+ var message = _a.message,
1117
+ details = __rest(_a, ["message"]);
1118
+ _this = _super.call(this, message || "Invalid input ".concat(details.input)) || this;
1119
+ _this.name = 'ValidationError';
1120
+ // Capture correct stack trace in V8 environments (Node.js, Google Chrome)
1121
+ if (Error.captureStackTrace) {
1122
+ Error.captureStackTrace(_this, ValidationError);
1123
+ }
1124
+ Object.assign(_this, details);
1125
+ return _this;
1126
+ }
1127
+ ValidationError.prototype.toJSON = function () {
1128
+ return {
1129
+ message: this.message,
1130
+ input: this.input,
1131
+ code: this.code,
1132
+ error: this.error,
1133
+ path: this.path,
1134
+ nestedErrors: this.nestedErrors
1135
+ };
1136
+ };
1137
+ return ValidationError;
1138
+ }(Error);
1139
+
1140
+ function assertValidSync(validator, input) {
1141
+ var validationResult = validate(validator, input);
1142
+ if (validationResult === true) {
1143
+ return input;
1144
+ } else {
1145
+ throw new ValidationError(validationResult);
1146
+ }
1147
+ }
1148
+ var validate = validateSyncFn;
1149
+ validate.type = typeValidator;
1150
+ validate.obj = obj$1;
1151
+ validate.objOf = objOf$1;
1152
+ validate.tuple = tuple$1;
1153
+ validate.arrayOf = arrayOf$1;
1154
+ validate.and = and$1;
1155
+ validate.or = or$1;
1156
+ validate.not = not$1;
1157
+ validate.assertValid = assertValidSync;
1158
+
1046
1159
  function _shapeGeneralValidator(_a) {
1047
1160
  var input = _a.input,
1048
1161
  baseType = _a.baseType,
@@ -1359,107 +1472,4 @@ validateAsync.or = or;
1359
1472
  validateAsync.not = not;
1360
1473
  validateAsync.assertValid = assertValidAsync;
1361
1474
 
1362
- function maybeFn(input) {
1363
- var args = [];
1364
- for (var _i = 1; _i < arguments.length; _i++) {
1365
- args[_i - 1] = arguments[_i];
1366
- }
1367
- return typeof input === 'function' ? input.apply(void 0, args) : input;
1368
- }
1369
-
1370
- function wait(ms, result) {
1371
- if (ms === void 0) {
1372
- ms = 1000;
1373
- }
1374
- return __awaiter(this, void 0, void 0, function () {
1375
- return __generator(this, function (_a) {
1376
- return [2 /*return*/, new Promise(function (resolve, reject) {
1377
- setTimeout(function () {
1378
- if (result instanceof Error) {
1379
- reject(result);
1380
- } else {
1381
- resolve(result);
1382
- }
1383
- }, ms);
1384
- })];
1385
- });
1386
- });
1387
- }
1388
-
1389
- function deepFreeze(object) {
1390
- Object.freeze(object);
1391
- if (Array.isArray(object)) {
1392
- // Handle the array case
1393
- object.forEach(function (item) {
1394
- if (item && _typeof(item) === 'object' && !Object.isFrozen(item)) {
1395
- deepFreeze(item);
1396
- }
1397
- });
1398
- } else {
1399
- // Handle the object case
1400
- Object.keys(object).forEach(function (key) {
1401
- var value = object[key];
1402
- if (value && _typeof(value) === 'object' && !Object.isFrozen(value)) {
1403
- deepFreeze(value);
1404
- }
1405
- });
1406
- }
1407
- return object;
1408
- }
1409
-
1410
- function stringifyReplacer(key, value) {
1411
- if (typeof value === 'function') {
1412
- // Convert functions to a consistent string representation
1413
- return "function:".concat(value.toString());
1414
- }
1415
- return value;
1416
- }
1417
- function simpleHash(str) {
1418
- var hash = 0;
1419
- for (var i = 0; i < str.length; i++) {
1420
- var _char = str.charCodeAt(i);
1421
- hash = (hash << 5) - hash + _char;
1422
- hash |= 0; // Convert to 32bit integer
1423
- }
1424
- // Ensure the hash is positive to avoid '-' signals
1425
- hash = Math.abs(hash);
1426
- return hash.toString(36); // Convert to base36 to ensure the result is alphanumeric
1427
- }
1428
- function generateDeterministicId(args) {
1429
- // Convert arguments to a JSON string using the custom replacer
1430
- var argsString = JSON.stringify(args, stringifyReplacer);
1431
- // Generate a simple hash of the string
1432
- return simpleHash(argsString);
1433
- }
1434
-
1435
- function debugFn(fnName, fn, logCall, logResult) {
1436
- return function () {
1437
- var args = [];
1438
- for (var _i = 0; _i < arguments.length; _i++) {
1439
- args[_i] = arguments[_i];
1440
- }
1441
- var callId = generateDeterministicId(__spreadArray([fnName, fn], args, true));
1442
- if (typeof logCall === 'function') {
1443
- // Deep clone args, so that we may detect mutations later on
1444
- logCall({
1445
- type: 'call',
1446
- callId: callId,
1447
- args: copy(args),
1448
- fnName: fnName
1449
- });
1450
- }
1451
- var result = fn.apply(void 0, args);
1452
- if (typeof logResult === 'function') {
1453
- logResult({
1454
- type: 'result',
1455
- callId: callId,
1456
- args: args,
1457
- result: result,
1458
- fnName: fnName
1459
- });
1460
- }
1461
- return result;
1462
- };
1463
- }
1464
-
1465
- export { PromiseLikeEventEmitter, SKIPPED, ValidationError, batchFn, debugFn, deepFreeze, interpolate, makeTypeOf, maybeFn, parseBatchedResults, promiseReduce, resolveNestedPromises, switchExec, switchValue, typeMap, typeOf, validate, validateAsync, wait };
1475
+ export { PromiseLikeEventEmitter, SKIPPED, ValidationError, batchFn, debugFn, deepFreeze, interpolate, makeTypeOf, maybeFn, parseBatchedResults, pickPaths, promiseReduce, resolveNestedPromises, switchExec, switchValue, typeMap, typeOf, validate, validateAsync, wait };