@orioro/util 0.1.0 → 0.2.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.
- package/dist/index.mjs +773 -763
- package/package.json +1 -1
- package/src/index.ts +7 -6
- package/src/resolvePaths/index.spec.ts +42 -0
- package/src/resolvePaths/index.ts +21 -0
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
for (var
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function basicType(typeName) {
|
|
65
|
-
return function (value) {
|
|
66
|
-
return _typeof(value) === typeName;
|
|
56
|
+
return t;
|
|
67
57
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
81
|
+
}
|
|
82
|
+
function rejected(value) {
|
|
83
|
+
try {
|
|
84
|
+
step(generator["throw"](value));
|
|
85
|
+
} catch (e) {
|
|
86
|
+
reject(e);
|
|
202
87
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
466
|
-
|
|
467
|
-
input: input,
|
|
468
|
-
nestedErrors: nestedErrors
|
|
207
|
+
PromiseLikeEventEmitter.prototype.then = function (onFulfilled, onRejected) {
|
|
208
|
+
return this.promise.then(onFulfilled, onRejected);
|
|
469
209
|
};
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
return
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
var
|
|
564
|
-
|
|
565
|
-
|
|
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
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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,33 @@ function interpolate(template, data, _a) {
|
|
|
677
371
|
});
|
|
678
372
|
}
|
|
679
373
|
|
|
680
|
-
function
|
|
681
|
-
var
|
|
682
|
-
|
|
683
|
-
|
|
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
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}, validatorInput),
|
|
743
|
-
validatorFn = _a[0],
|
|
744
|
-
errorMessage = _a[1];
|
|
745
|
-
try {
|
|
746
|
-
result = validatorFn(input, {
|
|
747
|
-
validateSync: validateSyncFn
|
|
382
|
+
function promiseReduce(inputArr, reducerFn, initial) {
|
|
383
|
+
return inputArr.reduce(function (prevPromise, input, index) {
|
|
384
|
+
return prevPromise.then(function (acc) {
|
|
385
|
+
return reducerFn(acc, input, index);
|
|
748
386
|
});
|
|
749
|
-
}
|
|
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
|
-
});
|
|
387
|
+
}, Promise.resolve(initial));
|
|
760
388
|
}
|
|
761
389
|
|
|
762
|
-
var
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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 = {};
|
|
390
|
+
var DEFAULT_OPTIONS = {
|
|
391
|
+
mode: 'eager',
|
|
392
|
+
maxDepth: 30,
|
|
393
|
+
clone: copy
|
|
394
|
+
};
|
|
395
|
+
function _echo(input) {
|
|
396
|
+
return input;
|
|
397
|
+
}
|
|
398
|
+
function resolveNestedPromises(node, options, ctx) {
|
|
399
|
+
if (options === void 0) {
|
|
400
|
+
options = {};
|
|
828
401
|
}
|
|
829
402
|
if (ctx === void 0) {
|
|
830
403
|
ctx = {
|
|
@@ -893,28 +466,6 @@ function arrayChunk(array, chunkSize) {
|
|
|
893
466
|
return chunks;
|
|
894
467
|
}
|
|
895
468
|
|
|
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
469
|
var SKIPPED = Symbol();
|
|
919
470
|
function batchFn(fn, _a) {
|
|
920
471
|
var _b = _a === void 0 ? {} : _a,
|
|
@@ -1021,28 +572,590 @@ function batchFn(fn, _a) {
|
|
|
1021
572
|
return promise;
|
|
1022
573
|
};
|
|
1023
574
|
}
|
|
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
|
-
});
|
|
575
|
+
function parseBatchedResults(inputs, results) {
|
|
576
|
+
return results.reduce(function (acc, result, index) {
|
|
577
|
+
if (result === SKIPPED) {
|
|
578
|
+
return _assign(_assign({}, acc), {
|
|
579
|
+
skipped: __spreadArray(__spreadArray([], acc.skipped, true), [inputs[index]], false)
|
|
580
|
+
});
|
|
581
|
+
} else if (result instanceof Error) {
|
|
582
|
+
return _assign(_assign({}, acc), {
|
|
583
|
+
errors: __spreadArray(__spreadArray([], acc.errors, true), [result], false)
|
|
584
|
+
});
|
|
585
|
+
} else {
|
|
586
|
+
return _assign(_assign({}, acc), {
|
|
587
|
+
results: __spreadArray(__spreadArray([], acc.results, true), [result], false)
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}, {
|
|
591
|
+
results: [],
|
|
592
|
+
errors: [],
|
|
593
|
+
skipped: []
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function resolvePaths(sourceObj, paths) {
|
|
598
|
+
return paths.reduce(function (acc, path) {
|
|
599
|
+
var _a = Array.isArray(path) ? path : [path, path],
|
|
600
|
+
targetPath = _a[0],
|
|
601
|
+
resolver = _a[1];
|
|
602
|
+
var value = typeof resolver === 'string' ? getProperty(sourceObj, resolver) : resolver(sourceObj);
|
|
603
|
+
return setProperty(acc, targetPath, value);
|
|
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
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
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
|
-
|
|
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, promiseReduce, resolveNestedPromises, resolvePaths, switchExec, switchValue, typeMap, typeOf, validate, validateAsync, wait };
|