1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var primitiveTypes = {};
|
7 |
|
8 | var classCallCheck = function (instance, Constructor) {
|
9 | if (!(instance instanceof Constructor)) {
|
10 | throw new TypeError("Cannot call a class as a function");
|
11 | }
|
12 | };
|
13 |
|
14 | var createClass = function () {
|
15 | function defineProperties(target, props) {
|
16 | for (var i = 0; i < props.length; i++) {
|
17 | var descriptor = props[i];
|
18 | descriptor.enumerable = descriptor.enumerable || false;
|
19 | descriptor.configurable = true;
|
20 | if ("value" in descriptor) descriptor.writable = true;
|
21 | Object.defineProperty(target, descriptor.key, descriptor);
|
22 | }
|
23 | }
|
24 |
|
25 | return function (Constructor, protoProps, staticProps) {
|
26 | if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
27 | if (staticProps) defineProperties(Constructor, staticProps);
|
28 | return Constructor;
|
29 | };
|
30 | }();
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var _extends = Object.assign || function (target) {
|
39 | for (var i = 1; i < arguments.length; i++) {
|
40 | var source = arguments[i];
|
41 |
|
42 | for (var key in source) {
|
43 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
44 | target[key] = source[key];
|
45 | }
|
46 | }
|
47 | }
|
48 |
|
49 | return target;
|
50 | };
|
51 |
|
52 |
|
53 |
|
54 | var inherits = function (subClass, superClass) {
|
55 | if (typeof superClass !== "function" && superClass !== null) {
|
56 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
57 | }
|
58 |
|
59 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
60 | constructor: {
|
61 | value: subClass,
|
62 | enumerable: false,
|
63 | writable: true,
|
64 | configurable: true
|
65 | }
|
66 | });
|
67 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
68 | };
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | var objectWithoutProperties = function (obj, keys) {
|
79 | var target = {};
|
80 |
|
81 | for (var i in obj) {
|
82 | if (keys.indexOf(i) >= 0) continue;
|
83 | if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
|
84 | target[i] = obj[i];
|
85 | }
|
86 |
|
87 | return target;
|
88 | };
|
89 |
|
90 | var possibleConstructorReturn = function (self, call) {
|
91 | if (!self) {
|
92 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
93 | }
|
94 |
|
95 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
96 | };
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | var slicedToArray = function () {
|
103 | function sliceIterator(arr, i) {
|
104 | var _arr = [];
|
105 | var _n = true;
|
106 | var _d = false;
|
107 | var _e = undefined;
|
108 |
|
109 | try {
|
110 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
111 | _arr.push(_s.value);
|
112 |
|
113 | if (i && _arr.length === i) break;
|
114 | }
|
115 | } catch (err) {
|
116 | _d = true;
|
117 | _e = err;
|
118 | } finally {
|
119 | try {
|
120 | if (!_n && _i["return"]) _i["return"]();
|
121 | } finally {
|
122 | if (_d) throw _e;
|
123 | }
|
124 | }
|
125 |
|
126 | return _arr;
|
127 | }
|
128 |
|
129 | return function (arr, i) {
|
130 | if (Array.isArray(arr)) {
|
131 | return arr;
|
132 | } else if (Symbol.iterator in Object(arr)) {
|
133 | return sliceIterator(arr, i);
|
134 | } else {
|
135 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
136 | }
|
137 | };
|
138 | }();
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | var toConsumableArray = function (arr) {
|
153 | if (Array.isArray(arr)) {
|
154 | for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
155 |
|
156 | return arr2;
|
157 | } else {
|
158 | return Array.from(arr);
|
159 | }
|
160 | };
|
161 |
|
162 | function makeJSONError(validation) {
|
163 | if (!validation.hasErrors()) {
|
164 | return;
|
165 | }
|
166 | var input = validation.input,
|
167 | context = validation.context;
|
168 |
|
169 | var errors = [];
|
170 | var _iteratorNormalCompletion = true;
|
171 | var _didIteratorError = false;
|
172 | var _iteratorError = undefined;
|
173 |
|
174 | try {
|
175 | for (var _iterator = validation.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
176 | var _ref = _step.value;
|
177 |
|
178 | var _ref2 = slicedToArray(_ref, 3);
|
179 |
|
180 | var path = _ref2[0];
|
181 | var message = _ref2[1];
|
182 | var expectedType = _ref2[2];
|
183 |
|
184 | var expected = expectedType ? expectedType.toString() : null;
|
185 | var actual = context.typeOf(_resolvePath(input, path)).toString();
|
186 | var field = stringifyPath(validation.path.concat(path));
|
187 |
|
188 | var pointer = `/${ path.join('/') }`;
|
189 |
|
190 | errors.push({
|
191 | pointer,
|
192 | field,
|
193 | message,
|
194 | expected,
|
195 | actual
|
196 | });
|
197 | }
|
198 | } catch (err) {
|
199 | _didIteratorError = true;
|
200 | _iteratorError = err;
|
201 | } finally {
|
202 | try {
|
203 | if (!_iteratorNormalCompletion && _iterator.return) {
|
204 | _iterator.return();
|
205 | }
|
206 | } finally {
|
207 | if (_didIteratorError) {
|
208 | throw _iteratorError;
|
209 | }
|
210 | }
|
211 | }
|
212 |
|
213 | return errors;
|
214 | }
|
215 |
|
216 |
|
217 | var cyclicValidation = new WeakMap();
|
218 |
|
219 |
|
220 |
|
221 | var cyclicToString = new WeakSet();
|
222 |
|
223 | function inValidationCycle(type, input) {
|
224 | try {
|
225 | var tracked = cyclicValidation.get(type);
|
226 | if (!tracked) {
|
227 | return false;
|
228 | } else {
|
229 | return weakSetHas(tracked, input);
|
230 | }
|
231 | } catch (e) {
|
232 |
|
233 | return true;
|
234 | }
|
235 | }
|
236 |
|
237 | function startValidationCycle(type, input) {
|
238 | var tracked = cyclicValidation.get(type);
|
239 | if (!tracked) {
|
240 | tracked = new WeakSet();
|
241 | cyclicValidation.set(type, tracked);
|
242 | }
|
243 | weakSetAdd(tracked, input);
|
244 | }
|
245 |
|
246 | function endValidationCycle(type, input) {
|
247 | var tracked = cyclicValidation.get(type);
|
248 | if (tracked) {
|
249 | weakSetDelete(tracked, input);
|
250 | }
|
251 | }
|
252 |
|
253 | function inToStringCycle(type) {
|
254 | return cyclicToString.has(type);
|
255 | }
|
256 |
|
257 | function startToStringCycle(type) {
|
258 | cyclicToString.add(type);
|
259 | }
|
260 |
|
261 | function endToStringCycle(type) {
|
262 | cyclicToString.delete(type);
|
263 | }
|
264 |
|
265 | function weakSetHas(weakset, value) {
|
266 | try {
|
267 | return weakset.has(value);
|
268 | } catch (e) {
|
269 | return true;
|
270 | }
|
271 | }
|
272 |
|
273 | function weakSetAdd(weakset, value) {
|
274 | try {
|
275 | weakset.add(value);
|
276 | } catch (e) {}
|
277 | }
|
278 |
|
279 | function weakSetDelete(weakset, value) {
|
280 | try {
|
281 | weakset.delete(value);
|
282 | } catch (e) {}
|
283 | }
|
284 |
|
285 | var validIdentifierOrAccessor = /^[$A-Z_][0-9A-Z_$[\].]*$/i;
|
286 |
|
287 | var Validation = function () {
|
288 | function Validation(context, input) {
|
289 | classCallCheck(this, Validation);
|
290 | this.path = [];
|
291 | this.prefix = '';
|
292 | this.errors = [];
|
293 | this.cyclic = new WeakMap();
|
294 |
|
295 | this.context = context;
|
296 | this.input = input;
|
297 | }
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | createClass(Validation, [{
|
303 | key: 'inCycle',
|
304 | value: function inCycle(type, input) {
|
305 | var tracked = this.cyclic.get(type);
|
306 | if (!tracked) {
|
307 | return false;
|
308 | } else {
|
309 | return weakSetHas(tracked, input);
|
310 | }
|
311 | }
|
312 | }, {
|
313 | key: 'startCycle',
|
314 | value: function startCycle(type, input) {
|
315 | var tracked = this.cyclic.get(type);
|
316 | if (!tracked) {
|
317 | tracked = new WeakSet();
|
318 | this.cyclic.set(type, tracked);
|
319 | }
|
320 | weakSetAdd(tracked, input);
|
321 | }
|
322 | }, {
|
323 | key: 'endCycle',
|
324 | value: function endCycle(type, input) {
|
325 | var tracked = this.cyclic.get(type);
|
326 | if (tracked) {
|
327 | weakSetDelete(tracked, input);
|
328 | }
|
329 | }
|
330 | }, {
|
331 | key: 'hasErrors',
|
332 | value: function hasErrors(path) {
|
333 | if (path) {
|
334 | var _iteratorNormalCompletion = true;
|
335 | var _didIteratorError = false;
|
336 | var _iteratorError = undefined;
|
337 |
|
338 | try {
|
339 | for (var _iterator = this.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
340 | var _ref = _step.value;
|
341 |
|
342 | var _ref2 = slicedToArray(_ref, 1);
|
343 |
|
344 | var candidate = _ref2[0];
|
345 |
|
346 | if (matchPath(path, candidate)) {
|
347 | return true;
|
348 | }
|
349 | }
|
350 | } catch (err) {
|
351 | _didIteratorError = true;
|
352 | _iteratorError = err;
|
353 | } finally {
|
354 | try {
|
355 | if (!_iteratorNormalCompletion && _iterator.return) {
|
356 | _iterator.return();
|
357 | }
|
358 | } finally {
|
359 | if (_didIteratorError) {
|
360 | throw _iteratorError;
|
361 | }
|
362 | }
|
363 | }
|
364 |
|
365 | return false;
|
366 | } else {
|
367 | return this.errors.length > 0;
|
368 | }
|
369 | }
|
370 | }, {
|
371 | key: 'addError',
|
372 | value: function addError(path, expectedType, message) {
|
373 | this.errors.push([path, message, expectedType]);
|
374 | return this;
|
375 | }
|
376 | }, {
|
377 | key: 'clearError',
|
378 | value: function clearError(path) {
|
379 | var didClear = false;
|
380 | if (path) {
|
381 | var _errors = [];
|
382 | var _iteratorNormalCompletion2 = true;
|
383 | var _didIteratorError2 = false;
|
384 | var _iteratorError2 = undefined;
|
385 |
|
386 | try {
|
387 | for (var _iterator2 = this.errors[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
388 | var error = _step2.value;
|
389 |
|
390 | if (matchPath(path, error[0])) {
|
391 | didClear = true;
|
392 | } else {
|
393 | _errors.push(error);
|
394 | }
|
395 | }
|
396 | } catch (err) {
|
397 | _didIteratorError2 = true;
|
398 | _iteratorError2 = err;
|
399 | } finally {
|
400 | try {
|
401 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
402 | _iterator2.return();
|
403 | }
|
404 | } finally {
|
405 | if (_didIteratorError2) {
|
406 | throw _iteratorError2;
|
407 | }
|
408 | }
|
409 | }
|
410 |
|
411 | this.errors = _errors;
|
412 | } else {
|
413 | didClear = this.errors.length > 0;
|
414 | this.errors = [];
|
415 | }
|
416 | return didClear;
|
417 | }
|
418 | }, {
|
419 | key: 'resolvePath',
|
420 | value: function resolvePath(path) {
|
421 | return _resolvePath(this.input, path);
|
422 | }
|
423 | }, {
|
424 | key: 'toJSON',
|
425 | value: function toJSON() {
|
426 | return makeJSONError(this);
|
427 | }
|
428 | }]);
|
429 | return Validation;
|
430 | }();
|
431 |
|
432 | function stringifyPath(path) {
|
433 | if (!path.length) {
|
434 | return 'Value';
|
435 | }
|
436 | var length = path.length;
|
437 |
|
438 | var parts = new Array(length);
|
439 | for (var i = 0; i < length; i++) {
|
440 | var part = path[i];
|
441 | if (part === '[[Return Type]]') {
|
442 | parts[i] = 'Return Type';
|
443 | } else if (typeof part !== 'string' || !validIdentifierOrAccessor.test(part)) {
|
444 | parts[i] = `[${ String(part) }]`;
|
445 | } else if (i > 0) {
|
446 | parts[i] = `.${ String(part) }`;
|
447 | } else {
|
448 | parts[i] = String(part);
|
449 | }
|
450 | }
|
451 | return parts.join('');
|
452 | }
|
453 |
|
454 | function _resolvePath(input, path) {
|
455 | var subject = input;
|
456 | var length = path.length;
|
457 |
|
458 | for (var i = 0; i < length; i++) {
|
459 | if (subject == null) {
|
460 | return undefined;
|
461 | }
|
462 | var part = path[i];
|
463 | if (part === '[[Return Type]]') {
|
464 | continue;
|
465 | }
|
466 | if (subject instanceof Map) {
|
467 | subject = subject.get(part);
|
468 | } else {
|
469 | subject = subject[part];
|
470 | }
|
471 | }
|
472 | return subject;
|
473 | }
|
474 |
|
475 | function matchPath(path, candidate) {
|
476 | var length = path.length;
|
477 |
|
478 | if (length > candidate.length) {
|
479 | return false;
|
480 | }
|
481 | for (var i = 0; i < length; i++) {
|
482 | if (candidate[i] !== path[i]) {
|
483 | return false;
|
484 | }
|
485 | }
|
486 | return true;
|
487 | }
|
488 |
|
489 | var RuntimeTypeError = function (_TypeError) {
|
490 | inherits(RuntimeTypeError, _TypeError);
|
491 |
|
492 | function RuntimeTypeError() {
|
493 | var _ref;
|
494 |
|
495 | var _temp, _this, _ret;
|
496 |
|
497 | classCallCheck(this, RuntimeTypeError);
|
498 |
|
499 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
500 | args[_key] = arguments[_key];
|
501 | }
|
502 |
|
503 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = RuntimeTypeError.__proto__ || Object.getPrototypeOf(RuntimeTypeError)).call.apply(_ref, [this].concat(args))), _this), _this.name = "RuntimeTypeError", _temp), possibleConstructorReturn(_this, _ret);
|
504 | }
|
505 |
|
506 | return RuntimeTypeError;
|
507 | }(TypeError);
|
508 |
|
509 | var delimiter = '\n-------------------------------------------------\n\n';
|
510 |
|
511 | function makeTypeError(validation) {
|
512 | if (!validation.hasErrors()) {
|
513 | return;
|
514 | }
|
515 | var prefix = validation.prefix,
|
516 | input = validation.input,
|
517 | context = validation.context;
|
518 |
|
519 | var collected = [];
|
520 | var _iteratorNormalCompletion = true;
|
521 | var _didIteratorError = false;
|
522 | var _iteratorError = undefined;
|
523 |
|
524 | try {
|
525 | for (var _iterator = validation.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
526 | var _ref = _step.value;
|
527 |
|
528 | var _ref2 = slicedToArray(_ref, 3);
|
529 |
|
530 | var path = _ref2[0];
|
531 | var message = _ref2[1];
|
532 | var expectedType = _ref2[2];
|
533 |
|
534 | var expected = expectedType ? expectedType.toString() : "*";
|
535 | var actual = context.typeOf(_resolvePath(input, path)).toString();
|
536 |
|
537 | var field = stringifyPath(validation.path.concat(path));
|
538 |
|
539 | collected.push(`${ field } ${ message }\n\nExpected: ${ expected }\n\nActual: ${ actual }\n`);
|
540 | }
|
541 | } catch (err) {
|
542 | _didIteratorError = true;
|
543 | _iteratorError = err;
|
544 | } finally {
|
545 | try {
|
546 | if (!_iteratorNormalCompletion && _iterator.return) {
|
547 | _iterator.return();
|
548 | }
|
549 | } finally {
|
550 | if (_didIteratorError) {
|
551 | throw _iteratorError;
|
552 | }
|
553 | }
|
554 | }
|
555 |
|
556 | if (prefix) {
|
557 | return new RuntimeTypeError(`${ prefix.trim() } ${ collected.join(delimiter) }`);
|
558 | } else {
|
559 | return new RuntimeTypeError(collected.join(delimiter));
|
560 | }
|
561 | }
|
562 |
|
563 | function makeError(expected, input) {
|
564 | var context = expected.context;
|
565 |
|
566 | var validation = context.validate(expected, input);
|
567 | return makeTypeError(validation);
|
568 | }
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | function compareTypes(a, b) {
|
582 |
|
583 | var result = void 0;
|
584 |
|
585 | if (a === b) {
|
586 | return 0;
|
587 | }
|
588 |
|
589 | if (b instanceof TypeAlias || b instanceof TypeParameter || b instanceof TypeTDZ) {
|
590 | b = b.unwrap();
|
591 | }
|
592 |
|
593 | if (a instanceof TypeAlias) {
|
594 | result = a.compareWith(b);
|
595 | } else if (a instanceof FlowIntoType || a instanceof TypeParameter || b instanceof FlowIntoType) {
|
596 | result = a.compareWith(b);
|
597 | } else if (a instanceof AnyType || a instanceof ExistentialType || a instanceof MixedType) {
|
598 | return 1;
|
599 | } else {
|
600 | result = a.compareWith(b);
|
601 | }
|
602 |
|
603 | if (b instanceof AnyType) {
|
604 |
|
605 |
|
606 | return 1;
|
607 | } else {
|
608 | return result;
|
609 | }
|
610 | }
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 | var Type = function () {
|
618 | function Type(context) {
|
619 | classCallCheck(this, Type);
|
620 | this.typeName = 'Type';
|
621 |
|
622 | this.context = context;
|
623 | }
|
624 |
|
625 | createClass(Type, [{
|
626 | key: 'errors',
|
627 | value: function* errors(validation, path, input) {}
|
628 | }, {
|
629 | key: 'accepts',
|
630 | value: function accepts(input) {
|
631 | var validation = new Validation(this.context, input);
|
632 | var _iteratorNormalCompletion = true;
|
633 | var _didIteratorError = false;
|
634 | var _iteratorError = undefined;
|
635 |
|
636 | try {
|
637 | for (var _iterator = this.errors(validation, [], input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
638 | var error = _step.value;
|
639 |
|
640 | return false;
|
641 | }
|
642 | } catch (err) {
|
643 | _didIteratorError = true;
|
644 | _iteratorError = err;
|
645 | } finally {
|
646 | try {
|
647 | if (!_iteratorNormalCompletion && _iterator.return) {
|
648 | _iterator.return();
|
649 | }
|
650 | } finally {
|
651 | if (_didIteratorError) {
|
652 | throw _iteratorError;
|
653 | }
|
654 | }
|
655 | }
|
656 |
|
657 | return true;
|
658 | }
|
659 | }, {
|
660 | key: 'acceptsType',
|
661 | value: function acceptsType(input) {
|
662 | if (compareTypes(this, input) === -1) {
|
663 | return false;
|
664 | } else {
|
665 | return true;
|
666 | }
|
667 | }
|
668 | }, {
|
669 | key: 'compareWith',
|
670 | value: function compareWith(input) {
|
671 | return -1;
|
672 | }
|
673 | }, {
|
674 | key: 'assert',
|
675 | value: function assert(input) {
|
676 | var error = makeError(this, input);
|
677 | if (error) {
|
678 | if (typeof Error.captureStackTrace === 'function') {
|
679 | Error.captureStackTrace(error, this.assert);
|
680 | }
|
681 | throw error;
|
682 | }
|
683 | return input;
|
684 | }
|
685 |
|
686 | |
687 |
|
688 |
|
689 |
|
690 | }, {
|
691 | key: 'unwrap',
|
692 | value: function unwrap() {
|
693 | return this;
|
694 | }
|
695 | }, {
|
696 | key: 'toString',
|
697 | value: function toString() {
|
698 | return '$Type';
|
699 | }
|
700 | }, {
|
701 | key: 'toJSON',
|
702 | value: function toJSON() {
|
703 | return {
|
704 | typeName: this.typeName
|
705 | };
|
706 | }
|
707 | }]);
|
708 | return Type;
|
709 | }();
|
710 |
|
711 | var AnyType = function (_Type) {
|
712 | inherits(AnyType, _Type);
|
713 |
|
714 | function AnyType() {
|
715 | var _ref;
|
716 |
|
717 | var _temp, _this, _ret;
|
718 |
|
719 | classCallCheck(this, AnyType);
|
720 |
|
721 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
722 | args[_key] = arguments[_key];
|
723 | }
|
724 |
|
725 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = AnyType.__proto__ || Object.getPrototypeOf(AnyType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'AnyType', _temp), possibleConstructorReturn(_this, _ret);
|
726 | }
|
727 |
|
728 | createClass(AnyType, [{
|
729 | key: 'errors',
|
730 | value: function* errors(validation, path, input) {}
|
731 | }, {
|
732 | key: 'accepts',
|
733 | value: function accepts(input) {
|
734 | return true;
|
735 | }
|
736 | }, {
|
737 | key: 'compareWith',
|
738 | value: function compareWith(input) {
|
739 | return 1;
|
740 | }
|
741 | }, {
|
742 | key: 'toString',
|
743 | value: function toString() {
|
744 | return 'any';
|
745 | }
|
746 | }, {
|
747 | key: 'toJSON',
|
748 | value: function toJSON() {
|
749 | return {
|
750 | typeName: this.typeName
|
751 | };
|
752 | }
|
753 | }]);
|
754 | return AnyType;
|
755 | }(Type);
|
756 |
|
757 | var errorMessages = {
|
758 | ERR_CONSTRAINT_VIOLATION: 'violated a constraint',
|
759 | ERR_EXPECT_ARRAY: 'must be an Array',
|
760 | ERR_EXPECT_TRUE: 'must be true',
|
761 | ERR_EXPECT_FALSE: 'must be false',
|
762 | ERR_EXPECT_BOOLEAN: 'must be true or false',
|
763 | ERR_EXPECT_EMPTY: 'must be empty',
|
764 | ERR_EXPECT_EXACT_VALUE: 'must be exactly $0',
|
765 | ERR_EXPECT_CALLABLE: 'must be callable',
|
766 | ERR_EXPECT_CLASS: 'must be a Class of $0',
|
767 | ERR_EXPECT_FUNCTION: 'must be a function',
|
768 | ERR_EXPECT_GENERATOR: 'must be a generator function',
|
769 | ERR_EXPECT_ITERABLE: 'must be iterable',
|
770 | ERR_EXPECT_ARGUMENT: 'argument "$0" must be: $1',
|
771 | ERR_EXPECT_RETURN: 'expected return type of: $0',
|
772 | ERR_EXPECT_N_ARGUMENTS: 'requires $0 argument(s)',
|
773 | ERR_EXPECT_INSTANCEOF: 'must be an instance of $0',
|
774 | ERR_EXPECT_KEY_TYPE: 'keys must be: $0',
|
775 | ERR_EXPECT_NULL: 'must be null',
|
776 | ERR_EXPECT_NUMBER: 'must be a number',
|
777 | ERR_EXPECT_OBJECT: 'must be an object',
|
778 | ERR_EXPECT_PROMISE: 'must be promise of $0',
|
779 | ERR_EXPECT_STRING: 'must be a string',
|
780 | ERR_EXPECT_SYMBOL: 'must be a symbol',
|
781 | ERR_EXPECT_THIS: 'must be exactly this',
|
782 | ERR_EXPECT_VOID: 'must be undefined',
|
783 | ERR_INVALID_DATE: 'must be a valid date',
|
784 | ERR_MISSING_PROPERTY: 'does not exists on object',
|
785 | ERR_NO_INDEXER: 'is not one of the permitted indexer types',
|
786 | ERR_NO_UNION: 'must be one of: $0',
|
787 | ERR_UNKNOWN_KEY: 'should not contain the key: "$0"'
|
788 | };
|
789 |
|
790 | function getErrorMessage(key) {
|
791 | for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
792 | params[_key - 1] = arguments[_key];
|
793 | }
|
794 |
|
795 | var message = errorMessages[key];
|
796 | if (params.length > 0) {
|
797 | return message.replace(/\$(\d+)/g, function (m, i) {
|
798 | return String(params[i]);
|
799 | });
|
800 | } else {
|
801 | return message;
|
802 | }
|
803 | }
|
804 |
|
805 | var TupleType = function (_Type) {
|
806 | inherits(TupleType, _Type);
|
807 |
|
808 | function TupleType() {
|
809 | var _ref;
|
810 |
|
811 | var _temp, _this, _ret;
|
812 |
|
813 | classCallCheck(this, TupleType);
|
814 |
|
815 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
816 | args[_key] = arguments[_key];
|
817 | }
|
818 |
|
819 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TupleType.__proto__ || Object.getPrototypeOf(TupleType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TupleType', _this.types = [], _temp), possibleConstructorReturn(_this, _ret);
|
820 | }
|
821 |
|
822 | createClass(TupleType, [{
|
823 | key: 'errors',
|
824 | value: function* errors(validation, path, input) {
|
825 | var types = this.types;
|
826 | var length = types.length;
|
827 | var context = this.context;
|
828 |
|
829 | if (!context.checkPredicate('Array', input)) {
|
830 | yield [path, getErrorMessage('ERR_EXPECT_ARRAY'), this];
|
831 | return;
|
832 | }
|
833 | for (var i = 0; i < length; i++) {
|
834 | yield* types[i].errors(validation, path.concat(i), input[i]);
|
835 | }
|
836 | }
|
837 | }, {
|
838 | key: 'accepts',
|
839 | value: function accepts(input) {
|
840 | var types = this.types;
|
841 | var length = types.length;
|
842 | var context = this.context;
|
843 |
|
844 |
|
845 | if (!context.checkPredicate('Array', input) || input.length < length) {
|
846 | return false;
|
847 | }
|
848 | for (var i = 0; i < length; i++) {
|
849 | var type = types[i];
|
850 | if (!type.accepts(input[i])) {
|
851 | return false;
|
852 | }
|
853 | }
|
854 | return true;
|
855 | }
|
856 | }, {
|
857 | key: 'compareWith',
|
858 | value: function compareWith(input) {
|
859 | if (!(input instanceof TupleType)) {
|
860 | return -1;
|
861 | }
|
862 | var types = this.types;
|
863 | var inputTypes = input.types;
|
864 | if (inputTypes.length < types.length) {
|
865 | return -1;
|
866 | }
|
867 | var isGreater = false;
|
868 | for (var i = 0; i < types.length; i++) {
|
869 | var result = compareTypes(types[i], inputTypes[i]);
|
870 | if (result === 1) {
|
871 | isGreater = true;
|
872 | } else if (result === -1) {
|
873 | return -1;
|
874 | }
|
875 | }
|
876 | if (types.length < inputTypes.length) {
|
877 | return 0;
|
878 | } else if (isGreater) {
|
879 | return 1;
|
880 | } else {
|
881 | return 0;
|
882 | }
|
883 | }
|
884 | }, {
|
885 | key: 'toString',
|
886 | value: function toString() {
|
887 | return `[${ this.types.join(', ') }]`;
|
888 | }
|
889 | }, {
|
890 | key: 'toJSON',
|
891 | value: function toJSON() {
|
892 | return {
|
893 | typeName: this.typeName,
|
894 | types: this.types
|
895 | };
|
896 | }
|
897 | }]);
|
898 | return TupleType;
|
899 | }(Type);
|
900 |
|
901 | var ArrayType = function (_Type) {
|
902 | inherits(ArrayType, _Type);
|
903 |
|
904 | function ArrayType() {
|
905 | var _ref;
|
906 |
|
907 | var _temp, _this, _ret;
|
908 |
|
909 | classCallCheck(this, ArrayType);
|
910 |
|
911 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
912 | args[_key] = arguments[_key];
|
913 | }
|
914 |
|
915 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ArrayType.__proto__ || Object.getPrototypeOf(ArrayType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ArrayType', _temp), possibleConstructorReturn(_this, _ret);
|
916 | }
|
917 |
|
918 | createClass(ArrayType, [{
|
919 | key: 'errors',
|
920 | value: function* errors(validation, path, input) {
|
921 | var context = this.context;
|
922 |
|
923 | if (!context.checkPredicate('Array', input)) {
|
924 | yield [path, getErrorMessage('ERR_EXPECT_ARRAY'), this];
|
925 | return;
|
926 | }
|
927 | if (validation.inCycle(this, input)) {
|
928 | return;
|
929 | }
|
930 | validation.startCycle(this, input);
|
931 | var elementType = this.elementType;
|
932 | var length = input.length;
|
933 |
|
934 |
|
935 | for (var i = 0; i < length; i++) {
|
936 | yield* elementType.errors(validation, path.concat(i), input[i]);
|
937 | }
|
938 | validation.endCycle(this, input);
|
939 | }
|
940 | }, {
|
941 | key: 'accepts',
|
942 | value: function accepts(input) {
|
943 | var context = this.context;
|
944 |
|
945 | if (!context.checkPredicate('Array', input)) {
|
946 | return false;
|
947 | }
|
948 | if (inValidationCycle(this, input)) {
|
949 | return true;
|
950 | }
|
951 | startValidationCycle(this, input);
|
952 | var elementType = this.elementType;
|
953 | var length = input.length;
|
954 |
|
955 | for (var i = 0; i < length; i++) {
|
956 | if (!elementType.accepts(input[i])) {
|
957 | endValidationCycle(this, input);
|
958 | return false;
|
959 | }
|
960 | }
|
961 | endValidationCycle(this, input);
|
962 | return true;
|
963 | }
|
964 | }, {
|
965 | key: 'compareWith',
|
966 | value: function compareWith(input) {
|
967 | var elementType = this.elementType;
|
968 |
|
969 | if (input instanceof TupleType) {
|
970 | var types = input.types;
|
971 |
|
972 | for (var i = 0; i < types.length; i++) {
|
973 | var result = compareTypes(elementType, types[i]);
|
974 | if (result === -1) {
|
975 | return -1;
|
976 | }
|
977 | }
|
978 | return 1;
|
979 | } else if (input instanceof ArrayType) {
|
980 | return compareTypes(elementType, input.elementType);
|
981 | } else {
|
982 | return -1;
|
983 | }
|
984 | }
|
985 | }, {
|
986 | key: 'toString',
|
987 | value: function toString() {
|
988 | var elementType = this.elementType;
|
989 |
|
990 | if (inToStringCycle(this)) {
|
991 | if (typeof elementType.name === 'string') {
|
992 | return `Array<$Cycle<${ elementType.name }>>`;
|
993 | } else {
|
994 | return `Array<$Cycle<Object>>`;
|
995 | }
|
996 | }
|
997 | startToStringCycle(this);
|
998 | var output = `Array<${ elementType.toString() }>`;
|
999 | endToStringCycle(this);
|
1000 | return output;
|
1001 | }
|
1002 | }, {
|
1003 | key: 'toJSON',
|
1004 | value: function toJSON() {
|
1005 | return {
|
1006 | typeName: this.typeName,
|
1007 | elementType: this.elementType
|
1008 | };
|
1009 | }
|
1010 | }]);
|
1011 | return ArrayType;
|
1012 | }(Type);
|
1013 |
|
1014 | var BooleanLiteralType = function (_Type) {
|
1015 | inherits(BooleanLiteralType, _Type);
|
1016 |
|
1017 | function BooleanLiteralType() {
|
1018 | var _ref;
|
1019 |
|
1020 | var _temp, _this, _ret;
|
1021 |
|
1022 | classCallCheck(this, BooleanLiteralType);
|
1023 |
|
1024 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1025 | args[_key] = arguments[_key];
|
1026 | }
|
1027 |
|
1028 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = BooleanLiteralType.__proto__ || Object.getPrototypeOf(BooleanLiteralType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'BooleanLiteralType', _temp), possibleConstructorReturn(_this, _ret);
|
1029 | }
|
1030 |
|
1031 | createClass(BooleanLiteralType, [{
|
1032 | key: 'errors',
|
1033 | value: function* errors(validation, path, input) {
|
1034 | if (input !== this.value) {
|
1035 | yield [path, getErrorMessage(this.value ? 'ERR_EXPECT_TRUE' : 'ERR_EXPECT_FALSE'), this];
|
1036 | }
|
1037 | }
|
1038 | }, {
|
1039 | key: 'accepts',
|
1040 | value: function accepts(input) {
|
1041 | return input === this.value;
|
1042 | }
|
1043 | }, {
|
1044 | key: 'compareWith',
|
1045 | value: function compareWith(input) {
|
1046 | if (input instanceof BooleanLiteralType && input.value === this.value) {
|
1047 | return 0;
|
1048 | } else {
|
1049 | return -1;
|
1050 | }
|
1051 | }
|
1052 | }, {
|
1053 | key: 'toString',
|
1054 | value: function toString() {
|
1055 | return this.value ? 'true' : 'false';
|
1056 | }
|
1057 | }, {
|
1058 | key: 'toJSON',
|
1059 | value: function toJSON() {
|
1060 | return {
|
1061 | type: this.typeName,
|
1062 | value: this.value
|
1063 | };
|
1064 | }
|
1065 | }]);
|
1066 | return BooleanLiteralType;
|
1067 | }(Type);
|
1068 |
|
1069 | var BooleanType = function (_Type) {
|
1070 | inherits(BooleanType, _Type);
|
1071 |
|
1072 | function BooleanType() {
|
1073 | var _ref;
|
1074 |
|
1075 | var _temp, _this, _ret;
|
1076 |
|
1077 | classCallCheck(this, BooleanType);
|
1078 |
|
1079 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1080 | args[_key] = arguments[_key];
|
1081 | }
|
1082 |
|
1083 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = BooleanType.__proto__ || Object.getPrototypeOf(BooleanType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'BooleanType', _temp), possibleConstructorReturn(_this, _ret);
|
1084 | }
|
1085 |
|
1086 | createClass(BooleanType, [{
|
1087 | key: 'errors',
|
1088 | value: function* errors(validation, path, input) {
|
1089 | if (typeof input !== 'boolean') {
|
1090 | yield [path, getErrorMessage('ERR_EXPECT_BOOLEAN'), this];
|
1091 | }
|
1092 | }
|
1093 | }, {
|
1094 | key: 'accepts',
|
1095 | value: function accepts(input) {
|
1096 | return typeof input === 'boolean';
|
1097 | }
|
1098 | }, {
|
1099 | key: 'compareWith',
|
1100 | value: function compareWith(input) {
|
1101 | if (input instanceof BooleanLiteralType) {
|
1102 | return 1;
|
1103 | } else if (input instanceof BooleanType) {
|
1104 | return 0;
|
1105 | } else {
|
1106 | return -1;
|
1107 | }
|
1108 | }
|
1109 | }, {
|
1110 | key: 'toString',
|
1111 | value: function toString() {
|
1112 | return 'boolean';
|
1113 | }
|
1114 | }, {
|
1115 | key: 'toJSON',
|
1116 | value: function toJSON() {
|
1117 | return {
|
1118 | typeName: this.typeName
|
1119 | };
|
1120 | }
|
1121 | }]);
|
1122 | return BooleanType;
|
1123 | }(Type);
|
1124 |
|
1125 | var EmptyType = function (_Type) {
|
1126 | inherits(EmptyType, _Type);
|
1127 |
|
1128 | function EmptyType() {
|
1129 | var _ref;
|
1130 |
|
1131 | var _temp, _this, _ret;
|
1132 |
|
1133 | classCallCheck(this, EmptyType);
|
1134 |
|
1135 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1136 | args[_key] = arguments[_key];
|
1137 | }
|
1138 |
|
1139 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = EmptyType.__proto__ || Object.getPrototypeOf(EmptyType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'EmptyType', _temp), possibleConstructorReturn(_this, _ret);
|
1140 | }
|
1141 |
|
1142 | createClass(EmptyType, [{
|
1143 | key: 'errors',
|
1144 | value: function* errors(validation, path, input) {
|
1145 | yield [path, getErrorMessage('ERR_EXPECT_EMPTY'), this];
|
1146 | }
|
1147 | }, {
|
1148 | key: 'accepts',
|
1149 | value: function accepts(input) {
|
1150 | return false;
|
1151 | }
|
1152 | }, {
|
1153 | key: 'compareWith',
|
1154 | value: function compareWith(input) {
|
1155 | if (input instanceof EmptyType) {
|
1156 | return 0;
|
1157 | } else {
|
1158 | return -1;
|
1159 | }
|
1160 | }
|
1161 | }, {
|
1162 | key: 'toString',
|
1163 | value: function toString() {
|
1164 | return 'empty';
|
1165 | }
|
1166 | }, {
|
1167 | key: 'toJSON',
|
1168 | value: function toJSON() {
|
1169 | return {
|
1170 | typeName: this.typeName
|
1171 | };
|
1172 | }
|
1173 | }]);
|
1174 | return EmptyType;
|
1175 | }(Type);
|
1176 |
|
1177 | var ExistentialType = function (_Type) {
|
1178 | inherits(ExistentialType, _Type);
|
1179 |
|
1180 | function ExistentialType() {
|
1181 | var _ref;
|
1182 |
|
1183 | var _temp, _this, _ret;
|
1184 |
|
1185 | classCallCheck(this, ExistentialType);
|
1186 |
|
1187 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1188 | args[_key] = arguments[_key];
|
1189 | }
|
1190 |
|
1191 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ExistentialType.__proto__ || Object.getPrototypeOf(ExistentialType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ExistentialType', _temp), possibleConstructorReturn(_this, _ret);
|
1192 | }
|
1193 |
|
1194 | createClass(ExistentialType, [{
|
1195 | key: 'errors',
|
1196 | value: function* errors(validation, path, input) {}
|
1197 | }, {
|
1198 | key: 'accepts',
|
1199 | value: function accepts(input) {
|
1200 | return true;
|
1201 | }
|
1202 | }, {
|
1203 | key: 'compareWith',
|
1204 | value: function compareWith(input) {
|
1205 | return 1;
|
1206 | }
|
1207 | }, {
|
1208 | key: 'toString',
|
1209 | value: function toString() {
|
1210 | return '*';
|
1211 | }
|
1212 | }, {
|
1213 | key: 'toJSON',
|
1214 | value: function toJSON() {
|
1215 | return {
|
1216 | typeName: this.typeName
|
1217 | };
|
1218 | }
|
1219 | }]);
|
1220 | return ExistentialType;
|
1221 | }(Type);
|
1222 |
|
1223 | var FlowIntoSymbol = Symbol('FlowInto');
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 | var TypeParameter = function (_Type) {
|
1234 | inherits(TypeParameter, _Type);
|
1235 |
|
1236 | function TypeParameter() {
|
1237 | var _ref;
|
1238 |
|
1239 | var _temp, _this, _ret;
|
1240 |
|
1241 | classCallCheck(this, TypeParameter);
|
1242 |
|
1243 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1244 | args[_key] = arguments[_key];
|
1245 | }
|
1246 |
|
1247 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeParameter.__proto__ || Object.getPrototypeOf(TypeParameter)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeParameter', _this[FlowIntoSymbol] = null, _temp), possibleConstructorReturn(_this, _ret);
|
1248 | }
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 | createClass(TypeParameter, [{
|
1254 | key: 'errors',
|
1255 | value: function* errors(validation, path, input) {
|
1256 | var boundOrDefault = this.bound || this.default;
|
1257 | var recorded = this.recorded,
|
1258 | context = this.context;
|
1259 |
|
1260 |
|
1261 | if (boundOrDefault instanceof FlowIntoType) {
|
1262 |
|
1263 |
|
1264 | yield* boundOrDefault.errors(validation, path, input);
|
1265 | return;
|
1266 | } else if (recorded) {
|
1267 |
|
1268 | yield* recorded.errors(validation, path, input);
|
1269 | return;
|
1270 | } else if (boundOrDefault) {
|
1271 | if (boundOrDefault.typeName === 'AnyType' || boundOrDefault.typeName === 'ExistentialType') {
|
1272 | return;
|
1273 | } else {
|
1274 | var hasErrors = false;
|
1275 | var _iteratorNormalCompletion = true;
|
1276 | var _didIteratorError = false;
|
1277 | var _iteratorError = undefined;
|
1278 |
|
1279 | try {
|
1280 | for (var _iterator = boundOrDefault.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
1281 | var error = _step.value;
|
1282 |
|
1283 | hasErrors = true;
|
1284 | yield error;
|
1285 | }
|
1286 | } catch (err) {
|
1287 | _didIteratorError = true;
|
1288 | _iteratorError = err;
|
1289 | } finally {
|
1290 | try {
|
1291 | if (!_iteratorNormalCompletion && _iterator.return) {
|
1292 | _iterator.return();
|
1293 | }
|
1294 | } finally {
|
1295 | if (_didIteratorError) {
|
1296 | throw _iteratorError;
|
1297 | }
|
1298 | }
|
1299 | }
|
1300 |
|
1301 | if (hasErrors) {
|
1302 | return;
|
1303 | }
|
1304 | }
|
1305 | }
|
1306 |
|
1307 | this.recorded = context.typeOf(input);
|
1308 | }
|
1309 | }, {
|
1310 | key: 'accepts',
|
1311 | value: function accepts(input) {
|
1312 | var boundOrDefault = this.bound || this.default;
|
1313 | var recorded = this.recorded,
|
1314 | context = this.context;
|
1315 |
|
1316 | if (boundOrDefault instanceof FlowIntoType) {
|
1317 |
|
1318 |
|
1319 | return boundOrDefault.accepts(input);
|
1320 | } else if (recorded) {
|
1321 | return recorded.accepts(input);
|
1322 | } else if (boundOrDefault) {
|
1323 | if (boundOrDefault.typeName === 'AnyType' || boundOrDefault.typeName === 'ExistentialType') {
|
1324 | return true;
|
1325 | } else if (!boundOrDefault.accepts(input)) {
|
1326 | return false;
|
1327 | }
|
1328 | }
|
1329 |
|
1330 | this.recorded = context.typeOf(input);
|
1331 | return true;
|
1332 | }
|
1333 | }, {
|
1334 | key: 'compareWith',
|
1335 | value: function compareWith(input) {
|
1336 | var boundOrDefault = this.bound || this.default;
|
1337 | var recorded = this.recorded;
|
1338 |
|
1339 | if (input instanceof TypeParameter) {
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 | return 1;
|
1345 | } else if (recorded) {
|
1346 | return compareTypes(recorded, input);
|
1347 | } else if (boundOrDefault) {
|
1348 | return compareTypes(boundOrDefault, input);
|
1349 | } else {
|
1350 |
|
1351 | return 1;
|
1352 | }
|
1353 | }
|
1354 |
|
1355 | |
1356 |
|
1357 |
|
1358 |
|
1359 | }, {
|
1360 | key: 'unwrap',
|
1361 | value: function unwrap() {
|
1362 | var boundOrDefault = this.bound || this.default;
|
1363 | var recorded = this.recorded;
|
1364 |
|
1365 | if (recorded) {
|
1366 | return recorded.unwrap();
|
1367 | } else if (boundOrDefault) {
|
1368 | return boundOrDefault.unwrap();
|
1369 | } else {
|
1370 | return this;
|
1371 | }
|
1372 | }
|
1373 | }, {
|
1374 | key: 'toString',
|
1375 | value: function toString(withBinding) {
|
1376 | var id = this.id,
|
1377 | bound = this.bound,
|
1378 | defaultType = this.default;
|
1379 |
|
1380 | if (withBinding) {
|
1381 | if (defaultType) {
|
1382 | return `${ id } = ${ defaultType.toString() }`;
|
1383 | } else if (bound) {
|
1384 | return `${ id }: ${ bound.toString() }`;
|
1385 | }
|
1386 | }
|
1387 | return id;
|
1388 | }
|
1389 | }, {
|
1390 | key: 'toJSON',
|
1391 | value: function toJSON() {
|
1392 | return {
|
1393 | typeName: this.typeName,
|
1394 | id: this.id,
|
1395 | bound: this.bound,
|
1396 | recorded: this.recorded
|
1397 | };
|
1398 | }
|
1399 | }]);
|
1400 | return TypeParameter;
|
1401 | }(Type);
|
1402 |
|
1403 | function flowIntoTypeParameter(typeParameter) {
|
1404 | var existing = typeParameter[FlowIntoSymbol];
|
1405 | if (existing) {
|
1406 | return existing;
|
1407 | }
|
1408 |
|
1409 | var target = new FlowIntoType(typeParameter.context);
|
1410 | target.typeParameter = typeParameter;
|
1411 | typeParameter[FlowIntoSymbol] = target;
|
1412 | return target;
|
1413 | }
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 | var FlowIntoType = function (_Type) {
|
1423 | inherits(FlowIntoType, _Type);
|
1424 |
|
1425 | function FlowIntoType() {
|
1426 | var _ref;
|
1427 |
|
1428 | var _temp, _this, _ret;
|
1429 |
|
1430 | classCallCheck(this, FlowIntoType);
|
1431 |
|
1432 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1433 | args[_key] = arguments[_key];
|
1434 | }
|
1435 |
|
1436 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = FlowIntoType.__proto__ || Object.getPrototypeOf(FlowIntoType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'FlowIntoType', _temp), possibleConstructorReturn(_this, _ret);
|
1437 | }
|
1438 |
|
1439 | createClass(FlowIntoType, [{
|
1440 | key: 'errors',
|
1441 | value: function* errors(validation, path, input) {
|
1442 | var typeParameter = this.typeParameter,
|
1443 | context = this.context;
|
1444 | var recorded = typeParameter.recorded,
|
1445 | bound = typeParameter.bound;
|
1446 |
|
1447 |
|
1448 | if (bound instanceof FlowIntoType) {
|
1449 |
|
1450 |
|
1451 | yield* bound.errors(validation, path, input);
|
1452 | return;
|
1453 | }
|
1454 | if (recorded) {
|
1455 |
|
1456 | if (bound) {
|
1457 | var hasError = false;
|
1458 | var _iteratorNormalCompletion = true;
|
1459 | var _didIteratorError = false;
|
1460 | var _iteratorError = undefined;
|
1461 |
|
1462 | try {
|
1463 | for (var _iterator = bound.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
1464 | var error = _step.value;
|
1465 |
|
1466 | yield error;
|
1467 | hasError = true;
|
1468 | }
|
1469 | } catch (err) {
|
1470 | _didIteratorError = true;
|
1471 | _iteratorError = err;
|
1472 | } finally {
|
1473 | try {
|
1474 | if (!_iteratorNormalCompletion && _iterator.return) {
|
1475 | _iterator.return();
|
1476 | }
|
1477 | } finally {
|
1478 | if (_didIteratorError) {
|
1479 | throw _iteratorError;
|
1480 | }
|
1481 | }
|
1482 | }
|
1483 |
|
1484 | if (hasError) {
|
1485 | return;
|
1486 | }
|
1487 | } else if (recorded.accepts(input)) {
|
1488 |
|
1489 | return;
|
1490 | } else {
|
1491 |
|
1492 | typeParameter.recorded = context.union(recorded, context.typeOf(input));
|
1493 | return;
|
1494 | }
|
1495 | } else if (bound) {
|
1496 | if (bound.typeName === 'AnyType' || bound.typeName === 'ExistentialType') {
|
1497 | return;
|
1498 | } else {
|
1499 | var _hasError = false;
|
1500 | var _iteratorNormalCompletion2 = true;
|
1501 | var _didIteratorError2 = false;
|
1502 | var _iteratorError2 = undefined;
|
1503 |
|
1504 | try {
|
1505 | for (var _iterator2 = bound.errors(validation, path, input)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
1506 | var _error = _step2.value;
|
1507 |
|
1508 | yield _error;
|
1509 | _hasError = true;
|
1510 | }
|
1511 | } catch (err) {
|
1512 | _didIteratorError2 = true;
|
1513 | _iteratorError2 = err;
|
1514 | } finally {
|
1515 | try {
|
1516 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
1517 | _iterator2.return();
|
1518 | }
|
1519 | } finally {
|
1520 | if (_didIteratorError2) {
|
1521 | throw _iteratorError2;
|
1522 | }
|
1523 | }
|
1524 | }
|
1525 |
|
1526 | if (_hasError) {
|
1527 | return;
|
1528 | }
|
1529 | }
|
1530 | }
|
1531 |
|
1532 | typeParameter.recorded = context.typeOf(input);
|
1533 | }
|
1534 | }, {
|
1535 | key: 'accepts',
|
1536 | value: function accepts(input) {
|
1537 | var typeParameter = this.typeParameter,
|
1538 | context = this.context;
|
1539 | var recorded = typeParameter.recorded,
|
1540 | bound = typeParameter.bound;
|
1541 |
|
1542 |
|
1543 | if (bound instanceof FlowIntoType) {
|
1544 |
|
1545 |
|
1546 | return bound.accepts(input);
|
1547 | }
|
1548 | if (recorded) {
|
1549 |
|
1550 | if (bound && !bound.accepts(input)) {
|
1551 | return false;
|
1552 | } else if (recorded.accepts(input)) {
|
1553 |
|
1554 | return true;
|
1555 | } else {
|
1556 |
|
1557 | typeParameter.recorded = context.union(recorded, context.typeOf(input));
|
1558 | return true;
|
1559 | }
|
1560 | } else if (bound) {
|
1561 | if (bound.typeName === 'AnyType' || bound.typeName === 'ExistentialType') {
|
1562 | return true;
|
1563 | } else if (!bound.accepts(input)) {
|
1564 | return false;
|
1565 | }
|
1566 | }
|
1567 |
|
1568 | typeParameter.recorded = context.typeOf(input);
|
1569 | return true;
|
1570 | }
|
1571 | }, {
|
1572 | key: 'compareWith',
|
1573 | value: function compareWith(input) {
|
1574 | var typeParameter = this.typeParameter,
|
1575 | context = this.context;
|
1576 | var recorded = typeParameter.recorded,
|
1577 | bound = typeParameter.bound;
|
1578 |
|
1579 | if (bound instanceof FlowIntoType) {
|
1580 |
|
1581 |
|
1582 | return bound.compareWith(input);
|
1583 | }
|
1584 | if (recorded) {
|
1585 | if (bound && compareTypes(bound, input) === -1) {
|
1586 | return -1;
|
1587 | }
|
1588 | var result = compareTypes(recorded, input);
|
1589 | if (result === 0) {
|
1590 |
|
1591 | return 0;
|
1592 | }
|
1593 |
|
1594 | typeParameter.recorded = context.union(recorded, input);
|
1595 | return 1;
|
1596 | } else if (bound) {
|
1597 | if (bound.typeName === 'AnyType' || bound.typeName === 'ExistentialType') {
|
1598 | return 1;
|
1599 | }
|
1600 | var _result = compareTypes(bound, input);
|
1601 | if (_result === -1) {
|
1602 | return -1;
|
1603 | }
|
1604 | }
|
1605 |
|
1606 | typeParameter.recorded = input;
|
1607 | return 0;
|
1608 | }
|
1609 |
|
1610 | |
1611 |
|
1612 |
|
1613 |
|
1614 | }, {
|
1615 | key: 'unwrap',
|
1616 | value: function unwrap() {
|
1617 | return this.typeParameter.unwrap();
|
1618 | }
|
1619 | }, {
|
1620 | key: 'toString',
|
1621 | value: function toString(withBinding) {
|
1622 | return this.typeParameter.toString(withBinding);
|
1623 | }
|
1624 | }, {
|
1625 | key: 'toJSON',
|
1626 | value: function toJSON() {
|
1627 | return this.typeParameter.toJSON();
|
1628 | }
|
1629 | }]);
|
1630 | return FlowIntoType;
|
1631 | }(Type);
|
1632 |
|
1633 | var FunctionTypeRestParam = function (_Type) {
|
1634 | inherits(FunctionTypeRestParam, _Type);
|
1635 |
|
1636 | function FunctionTypeRestParam() {
|
1637 | var _ref;
|
1638 |
|
1639 | var _temp, _this, _ret;
|
1640 |
|
1641 | classCallCheck(this, FunctionTypeRestParam);
|
1642 |
|
1643 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1644 | args[_key] = arguments[_key];
|
1645 | }
|
1646 |
|
1647 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = FunctionTypeRestParam.__proto__ || Object.getPrototypeOf(FunctionTypeRestParam)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'FunctionTypeRestParam', _temp), possibleConstructorReturn(_this, _ret);
|
1648 | }
|
1649 |
|
1650 | createClass(FunctionTypeRestParam, [{
|
1651 | key: 'errors',
|
1652 | value: function* errors(validation, path, input) {
|
1653 | var type = this.type;
|
1654 |
|
1655 | yield* type.errors(validation, path, input);
|
1656 | }
|
1657 | }, {
|
1658 | key: 'accepts',
|
1659 | value: function accepts(input) {
|
1660 | var type = this.type;
|
1661 |
|
1662 | return type.accepts(input);
|
1663 | }
|
1664 | }, {
|
1665 | key: 'compareWith',
|
1666 | value: function compareWith(input) {
|
1667 | if (input instanceof FunctionTypeParam || input instanceof FunctionTypeRestParam) {
|
1668 | return compareTypes(this.type, input.type);
|
1669 | } else {
|
1670 | var result = compareTypes(this.type, input);
|
1671 | if (result === -1) {
|
1672 | return -1;
|
1673 | } else {
|
1674 | return 1;
|
1675 | }
|
1676 | }
|
1677 | }
|
1678 | }, {
|
1679 | key: 'toString',
|
1680 | value: function toString() {
|
1681 | var type = this.type;
|
1682 |
|
1683 | return `...${ this.name }: ${ type.toString() }`;
|
1684 | }
|
1685 | }, {
|
1686 | key: 'toJSON',
|
1687 | value: function toJSON() {
|
1688 | return {
|
1689 | typeName: this.typeName,
|
1690 | name: this.name,
|
1691 | type: this.type
|
1692 | };
|
1693 | }
|
1694 | }]);
|
1695 | return FunctionTypeRestParam;
|
1696 | }(Type);
|
1697 |
|
1698 | var FunctionTypeParam = function (_Type) {
|
1699 | inherits(FunctionTypeParam, _Type);
|
1700 |
|
1701 | function FunctionTypeParam() {
|
1702 | var _ref;
|
1703 |
|
1704 | var _temp, _this, _ret;
|
1705 |
|
1706 | classCallCheck(this, FunctionTypeParam);
|
1707 |
|
1708 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1709 | args[_key] = arguments[_key];
|
1710 | }
|
1711 |
|
1712 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = FunctionTypeParam.__proto__ || Object.getPrototypeOf(FunctionTypeParam)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'FunctionTypeParam', _temp), possibleConstructorReturn(_this, _ret);
|
1713 | }
|
1714 |
|
1715 | createClass(FunctionTypeParam, [{
|
1716 | key: 'errors',
|
1717 | value: function* errors(validation, path, input) {
|
1718 | var optional = this.optional,
|
1719 | type = this.type;
|
1720 |
|
1721 | if (optional && input === undefined) {
|
1722 | return;
|
1723 | } else {
|
1724 | yield* type.errors(validation, path, input);
|
1725 | }
|
1726 | }
|
1727 | }, {
|
1728 | key: 'accepts',
|
1729 | value: function accepts(input) {
|
1730 | var optional = this.optional,
|
1731 | type = this.type;
|
1732 |
|
1733 | if (optional && input === undefined) {
|
1734 | return true;
|
1735 | } else {
|
1736 | return type.accepts(input);
|
1737 | }
|
1738 | }
|
1739 | }, {
|
1740 | key: 'compareWith',
|
1741 | value: function compareWith(input) {
|
1742 | if (input instanceof FunctionTypeParam || input instanceof FunctionTypeRestParam) {
|
1743 | return compareTypes(this.type, input.type);
|
1744 | } else {
|
1745 | return compareTypes(this.type, input);
|
1746 | }
|
1747 | }
|
1748 | }, {
|
1749 | key: 'toString',
|
1750 | value: function toString() {
|
1751 | var optional = this.optional,
|
1752 | type = this.type;
|
1753 |
|
1754 | return `${ this.name }${ optional ? '?' : '' }: ${ type.toString() }`;
|
1755 | }
|
1756 | }, {
|
1757 | key: 'toJSON',
|
1758 | value: function toJSON() {
|
1759 | return {
|
1760 | typeName: this.typeName,
|
1761 | name: this.name,
|
1762 | optional: this.optional,
|
1763 | type: this.type
|
1764 | };
|
1765 | }
|
1766 | }]);
|
1767 | return FunctionTypeParam;
|
1768 | }(Type);
|
1769 |
|
1770 | var FunctionTypeReturn = function (_Type) {
|
1771 | inherits(FunctionTypeReturn, _Type);
|
1772 |
|
1773 | function FunctionTypeReturn() {
|
1774 | var _ref;
|
1775 |
|
1776 | var _temp, _this, _ret;
|
1777 |
|
1778 | classCallCheck(this, FunctionTypeReturn);
|
1779 |
|
1780 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1781 | args[_key] = arguments[_key];
|
1782 | }
|
1783 |
|
1784 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = FunctionTypeReturn.__proto__ || Object.getPrototypeOf(FunctionTypeReturn)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'FunctionTypeReturn', _temp), possibleConstructorReturn(_this, _ret);
|
1785 | }
|
1786 |
|
1787 | createClass(FunctionTypeReturn, [{
|
1788 | key: 'errors',
|
1789 | value: function* errors(validation, path, input) {
|
1790 | var type = this.type;
|
1791 |
|
1792 | yield* type.errors(validation, path.concat('[[Return Type]]'), input);
|
1793 | }
|
1794 | }, {
|
1795 | key: 'accepts',
|
1796 | value: function accepts(input) {
|
1797 | var type = this.type;
|
1798 |
|
1799 | return type.accepts(input);
|
1800 | }
|
1801 | }, {
|
1802 | key: 'compareWith',
|
1803 | value: function compareWith(input) {
|
1804 | if (input instanceof FunctionTypeReturn) {
|
1805 | return compareTypes(this.type, input.type);
|
1806 | } else {
|
1807 | var result = compareTypes(this.type, input);
|
1808 | if (result === -1) {
|
1809 | return -1;
|
1810 | } else {
|
1811 | return 1;
|
1812 | }
|
1813 | }
|
1814 | }
|
1815 | }, {
|
1816 | key: 'unwrap',
|
1817 | value: function unwrap() {
|
1818 | return this.type;
|
1819 | }
|
1820 | }, {
|
1821 | key: 'toString',
|
1822 | value: function toString() {
|
1823 | var type = this.type;
|
1824 |
|
1825 | return type.toString();
|
1826 | }
|
1827 | }, {
|
1828 | key: 'toJSON',
|
1829 | value: function toJSON() {
|
1830 | return {
|
1831 | typeName: this.typeName,
|
1832 | type: this.type
|
1833 | };
|
1834 | }
|
1835 | }]);
|
1836 | return FunctionTypeReturn;
|
1837 | }(Type);
|
1838 |
|
1839 | var ParentSymbol = Symbol('Parent');
|
1840 | var NameRegistrySymbol = Symbol('NameRegistry');
|
1841 | var ModuleRegistrySymbol = Symbol('ModuleRegistry');
|
1842 | var CurrentModuleSymbol = Symbol('CurrentModule');
|
1843 | var TypeConstructorRegistrySymbol = Symbol('TypeConstructorRegistry');
|
1844 | var InferrerSymbol = Symbol('Inferrer');
|
1845 |
|
1846 |
|
1847 | var TypeSymbol = Symbol('Type');
|
1848 | var TypeParametersSymbol = Symbol('TypeParameters');
|
1849 | var TypePredicateRegistrySymbol = Symbol('TypePredicateRegistry');
|
1850 |
|
1851 | var FunctionType = function (_Type) {
|
1852 | inherits(FunctionType, _Type);
|
1853 |
|
1854 | function FunctionType() {
|
1855 | var _ref;
|
1856 |
|
1857 | var _temp, _this, _ret;
|
1858 |
|
1859 | classCallCheck(this, FunctionType);
|
1860 |
|
1861 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1862 | args[_key] = arguments[_key];
|
1863 | }
|
1864 |
|
1865 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = FunctionType.__proto__ || Object.getPrototypeOf(FunctionType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'FunctionType', _this.params = [], _temp), possibleConstructorReturn(_this, _ret);
|
1866 | }
|
1867 |
|
1868 | createClass(FunctionType, [{
|
1869 | key: 'errors',
|
1870 | value: function* errors(validation, path, input) {
|
1871 | if (typeof input !== 'function') {
|
1872 | yield [path, getErrorMessage('ERR_EXPECT_FUNCTION'), this];
|
1873 | return;
|
1874 | }
|
1875 | var annotation = input[TypeSymbol];
|
1876 | var returnType = this.returnType,
|
1877 | params = this.params;
|
1878 |
|
1879 | if (annotation) {
|
1880 | if (!annotation.params) {
|
1881 | return;
|
1882 | }
|
1883 | for (var i = 0; i < params.length; i++) {
|
1884 | var param = params[i];
|
1885 | var annotationParam = annotation.params[i];
|
1886 | if (!annotationParam && !param.optional) {
|
1887 | yield [path, getErrorMessage('ERR_EXPECT_ARGUMENT', param.name, param.type.toString()), this];
|
1888 | } else if (!param.acceptsType(annotationParam)) {
|
1889 | yield [path, getErrorMessage('ERR_EXPECT_ARGUMENT', param.name, param.type.toString()), this];
|
1890 | }
|
1891 | }
|
1892 | if (!returnType.acceptsType(annotation.returnType)) {
|
1893 | yield [path, getErrorMessage('ERR_EXPECT_RETURN', returnType.toString()), this];
|
1894 | }
|
1895 | } else {
|
1896 | var context = this.context;
|
1897 |
|
1898 |
|
1899 |
|
1900 | for (var _i = 0; _i < params.length; _i++) {
|
1901 | var _param = params[_i];
|
1902 | _param.acceptsType(context.any());
|
1903 | }
|
1904 | returnType.acceptsType(context.any());
|
1905 | }
|
1906 | }
|
1907 | }, {
|
1908 | key: 'accepts',
|
1909 | value: function accepts(input) {
|
1910 | if (typeof input !== 'function') {
|
1911 | return false;
|
1912 | }
|
1913 | var returnType = this.returnType,
|
1914 | params = this.params;
|
1915 |
|
1916 | var annotation = input[TypeSymbol];
|
1917 | if (annotation) {
|
1918 | if (!annotation.params) {
|
1919 | return true;
|
1920 | }
|
1921 | for (var i = 0; i < params.length; i++) {
|
1922 | var param = params[i];
|
1923 | var annotationParam = annotation.params[i];
|
1924 | if (!annotationParam && !param.optional) {
|
1925 | return false;
|
1926 | } else if (!param.acceptsType(annotationParam)) {
|
1927 | return false;
|
1928 | }
|
1929 | }
|
1930 | if (!returnType.acceptsType(annotation.returnType)) {
|
1931 | return false;
|
1932 | }
|
1933 | return true;
|
1934 | } else {
|
1935 | var context = this.context;
|
1936 |
|
1937 |
|
1938 |
|
1939 | for (var _i2 = 0; _i2 < params.length; _i2++) {
|
1940 | var _param2 = params[_i2];
|
1941 | _param2.acceptsType(context.any());
|
1942 | }
|
1943 | returnType.acceptsType(context.any());
|
1944 | return true;
|
1945 | }
|
1946 | }
|
1947 | }, {
|
1948 | key: 'compareWith',
|
1949 | value: function compareWith(input) {
|
1950 | if (!(input instanceof FunctionType)) {
|
1951 | return -1;
|
1952 | }
|
1953 | var returnType = this.returnType;
|
1954 | var inputReturnType = input.returnType;
|
1955 | var isGreater = false;
|
1956 | var returnTypeResult = compareTypes(returnType, inputReturnType);
|
1957 | if (returnTypeResult === -1) {
|
1958 | return -1;
|
1959 | } else if (returnTypeResult === 1) {
|
1960 | isGreater = true;
|
1961 | }
|
1962 |
|
1963 | var params = this.params;
|
1964 | var inputParams = input.params;
|
1965 | for (var i = 0; i < params.length; i++) {
|
1966 | var param = params[i];
|
1967 | var inputParam = i >= inputParams.length ? input.rest : inputParams[i];
|
1968 | if (inputParam == null) {
|
1969 | return -1;
|
1970 | }
|
1971 | var result = compareTypes(param, inputParam);
|
1972 | if (result === -1) {
|
1973 | return -1;
|
1974 | } else if (result === 1) {
|
1975 | isGreater = true;
|
1976 | }
|
1977 | }
|
1978 | return isGreater ? 1 : 0;
|
1979 | }
|
1980 | }, {
|
1981 | key: 'acceptsParams',
|
1982 | value: function acceptsParams() {
|
1983 | var params = this.params,
|
1984 | rest = this.rest;
|
1985 |
|
1986 | var paramsLength = params.length;
|
1987 |
|
1988 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
1989 | args[_key2] = arguments[_key2];
|
1990 | }
|
1991 |
|
1992 | var argsLength = args.length;
|
1993 | for (var i = 0; i < paramsLength; i++) {
|
1994 | var param = params[i];
|
1995 | if (i < argsLength) {
|
1996 | if (!param.accepts(args[i])) {
|
1997 | return false;
|
1998 | }
|
1999 | } else if (!param.accepts(undefined)) {
|
2000 | return false;
|
2001 | }
|
2002 | }
|
2003 |
|
2004 | if (argsLength > paramsLength && rest) {
|
2005 | for (var _i3 = paramsLength; _i3 < argsLength; _i3++) {
|
2006 | if (!rest.accepts(args[_i3])) {
|
2007 | return false;
|
2008 | }
|
2009 | }
|
2010 | }
|
2011 |
|
2012 | return true;
|
2013 | }
|
2014 | }, {
|
2015 | key: 'acceptsReturn',
|
2016 | value: function acceptsReturn(input) {
|
2017 | return this.returnType.accepts(input);
|
2018 | }
|
2019 | }, {
|
2020 | key: 'assertParams',
|
2021 | value: function assertParams() {
|
2022 | var params = this.params,
|
2023 | rest = this.rest;
|
2024 |
|
2025 | var paramsLength = params.length;
|
2026 |
|
2027 | for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
2028 | args[_key3] = arguments[_key3];
|
2029 | }
|
2030 |
|
2031 | var argsLength = args.length;
|
2032 | for (var i = 0; i < paramsLength; i++) {
|
2033 | var param = params[i];
|
2034 | if (i < argsLength) {
|
2035 | param.assert(args[i]);
|
2036 | } else {
|
2037 | param.assert(undefined);
|
2038 | }
|
2039 | }
|
2040 |
|
2041 | if (argsLength > paramsLength && rest) {
|
2042 | for (var _i4 = paramsLength; _i4 < argsLength; _i4++) {
|
2043 | rest.assert(args[_i4]);
|
2044 | }
|
2045 | }
|
2046 |
|
2047 | return args;
|
2048 | }
|
2049 | }, {
|
2050 | key: 'assertReturn',
|
2051 | value: function assertReturn(input) {
|
2052 | this.returnType.assert(input);
|
2053 | return input;
|
2054 | }
|
2055 | }, {
|
2056 | key: 'invoke',
|
2057 | value: function invoke() {
|
2058 | var params = this.params,
|
2059 | rest = this.rest,
|
2060 | context = this.context;
|
2061 |
|
2062 | var paramsLength = params.length;
|
2063 |
|
2064 | for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
2065 | args[_key4] = arguments[_key4];
|
2066 | }
|
2067 |
|
2068 | var argsLength = args.length;
|
2069 | for (var i = 0; i < paramsLength; i++) {
|
2070 | var param = params[i];
|
2071 | if (i < argsLength) {
|
2072 | if (!param.acceptsType(args[i])) {
|
2073 | return context.empty();
|
2074 | }
|
2075 | } else if (!param.accepts(undefined)) {
|
2076 | return context.empty();
|
2077 | }
|
2078 | }
|
2079 |
|
2080 | if (argsLength > paramsLength && rest) {
|
2081 | for (var _i5 = paramsLength; _i5 < argsLength; _i5++) {
|
2082 | if (!rest.acceptsType(args[_i5])) {
|
2083 | return context.empty();
|
2084 | }
|
2085 | }
|
2086 | }
|
2087 |
|
2088 | return this.returnType.type;
|
2089 | }
|
2090 | }, {
|
2091 | key: 'toString',
|
2092 | value: function toString() {
|
2093 | var params = this.params,
|
2094 | rest = this.rest,
|
2095 | returnType = this.returnType;
|
2096 |
|
2097 | var args = [];
|
2098 | for (var i = 0; i < params.length; i++) {
|
2099 | args.push(params[i].toString());
|
2100 | }
|
2101 | if (rest) {
|
2102 | args.push(rest.toString());
|
2103 | }
|
2104 | return `(${ args.join(', ') }) => ${ returnType.toString() }`;
|
2105 | }
|
2106 | }, {
|
2107 | key: 'toJSON',
|
2108 | value: function toJSON() {
|
2109 | return {
|
2110 | typeName: this.typeName,
|
2111 | params: this.params,
|
2112 | rest: this.rest,
|
2113 | returnType: this.returnType
|
2114 | };
|
2115 | }
|
2116 | }]);
|
2117 | return FunctionType;
|
2118 | }(Type);
|
2119 |
|
2120 | var GeneratorType = function (_Type) {
|
2121 | inherits(GeneratorType, _Type);
|
2122 |
|
2123 | function GeneratorType() {
|
2124 | var _ref;
|
2125 |
|
2126 | var _temp, _this, _ret;
|
2127 |
|
2128 | classCallCheck(this, GeneratorType);
|
2129 |
|
2130 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2131 | args[_key] = arguments[_key];
|
2132 | }
|
2133 |
|
2134 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = GeneratorType.__proto__ || Object.getPrototypeOf(GeneratorType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'GeneratorType', _temp), possibleConstructorReturn(_this, _ret);
|
2135 | }
|
2136 |
|
2137 | createClass(GeneratorType, [{
|
2138 | key: 'errors',
|
2139 | value: function* errors(validation, path, input) {
|
2140 | var isValid = input && typeof input.next === 'function' && typeof input.return === 'function' && typeof input.throw === 'function';
|
2141 | if (!isValid) {
|
2142 | yield [path, getErrorMessage('ERR_EXPECT_GENERATOR'), this];
|
2143 | }
|
2144 | }
|
2145 | }, {
|
2146 | key: 'accepts',
|
2147 | value: function accepts(input) {
|
2148 | return input && typeof input.next === 'function' && typeof input.return === 'function' && typeof input.throw === 'function';
|
2149 | }
|
2150 | }, {
|
2151 | key: 'compareWith',
|
2152 | value: function compareWith(input) {
|
2153 | if (!(input instanceof GeneratorType)) {
|
2154 | var _result = compareTypes(this.yieldType, input);
|
2155 | if (_result === -1) {
|
2156 | return -1;
|
2157 | } else {
|
2158 | return 1;
|
2159 | }
|
2160 | }
|
2161 | var isGreater = false;
|
2162 | var result = compareTypes(this.yieldType, input.yieldType);
|
2163 | if (result === -1) {
|
2164 | return -1;
|
2165 | } else if (result === 1) {
|
2166 | isGreater = true;
|
2167 | }
|
2168 |
|
2169 | result = compareTypes(this.returnType, input.returnType);
|
2170 | if (result === -1) {
|
2171 | return -1;
|
2172 | } else if (result === 1) {
|
2173 | isGreater = true;
|
2174 | }
|
2175 |
|
2176 | result = compareTypes(this.nextType, input.nextType);
|
2177 | if (result === -1) {
|
2178 | return -1;
|
2179 | } else if (result === 1) {
|
2180 | isGreater = true;
|
2181 | }
|
2182 |
|
2183 | return isGreater ? 1 : 0;
|
2184 | }
|
2185 | }, {
|
2186 | key: 'acceptsYield',
|
2187 | value: function acceptsYield(input) {
|
2188 | return this.yieldType.accepts(input);
|
2189 | }
|
2190 | }, {
|
2191 | key: 'acceptsReturn',
|
2192 | value: function acceptsReturn(input) {
|
2193 | return this.returnType.accepts(input);
|
2194 | }
|
2195 | }, {
|
2196 | key: 'acceptsNext',
|
2197 | value: function acceptsNext(input) {
|
2198 | return this.nextType.accepts(input);
|
2199 | }
|
2200 | }, {
|
2201 | key: 'assertYield',
|
2202 | value: function assertYield(input) {
|
2203 | return this.yieldType.assert(input);
|
2204 | }
|
2205 | }, {
|
2206 | key: 'assertReturn',
|
2207 | value: function assertReturn(input) {
|
2208 | return this.returnType.assert(input);
|
2209 | }
|
2210 | }, {
|
2211 | key: 'assertNext',
|
2212 | value: function assertNext(input) {
|
2213 | return this.nextType.assert(input);
|
2214 | }
|
2215 | }, {
|
2216 | key: 'toString',
|
2217 | value: function toString() {
|
2218 | var yieldType = this.yieldType,
|
2219 | returnType = this.returnType,
|
2220 | nextType = this.nextType;
|
2221 |
|
2222 | return `Generator<${ yieldType.toString() }, ${ returnType.toString() }, ${ nextType.toString() }`;
|
2223 | }
|
2224 | }, {
|
2225 | key: 'toJSON',
|
2226 | value: function toJSON() {
|
2227 | return {
|
2228 | typeName: this.typeName,
|
2229 | yieldType: this.yieldType,
|
2230 | returnType: this.returnType,
|
2231 | nextType: this.nextType
|
2232 | };
|
2233 | }
|
2234 | }]);
|
2235 | return GeneratorType;
|
2236 | }(Type);
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 | var TypeParameterApplication = function (_Type) {
|
2243 | inherits(TypeParameterApplication, _Type);
|
2244 |
|
2245 | function TypeParameterApplication() {
|
2246 | var _ref;
|
2247 |
|
2248 | var _temp, _this, _ret;
|
2249 |
|
2250 | classCallCheck(this, TypeParameterApplication);
|
2251 |
|
2252 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2253 | args[_key] = arguments[_key];
|
2254 | }
|
2255 |
|
2256 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeParameterApplication.__proto__ || Object.getPrototypeOf(TypeParameterApplication)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeParameterApplication', _this.typeInstances = [], _temp), possibleConstructorReturn(_this, _ret);
|
2257 | }
|
2258 |
|
2259 | createClass(TypeParameterApplication, [{
|
2260 | key: 'errors',
|
2261 | value: function* errors(validation, path, input) {
|
2262 | var parent = this.parent,
|
2263 | typeInstances = this.typeInstances;
|
2264 |
|
2265 | yield* parent.errors.apply(parent, [validation, path, input].concat(toConsumableArray(typeInstances)));
|
2266 | }
|
2267 | }, {
|
2268 | key: 'accepts',
|
2269 | value: function accepts(input) {
|
2270 | var parent = this.parent,
|
2271 | typeInstances = this.typeInstances;
|
2272 |
|
2273 | return parent.accepts.apply(parent, [input].concat(toConsumableArray(typeInstances)));
|
2274 | }
|
2275 | }, {
|
2276 | key: 'compareWith',
|
2277 | value: function compareWith(input) {
|
2278 | var _parent;
|
2279 |
|
2280 | return (_parent = this.parent).compareWith.apply(_parent, [input].concat(toConsumableArray(this.typeInstances)));
|
2281 | }
|
2282 | }, {
|
2283 | key: 'hasProperty',
|
2284 | value: function hasProperty(name) {
|
2285 | var inner = this.parent;
|
2286 | if (inner && typeof inner.hasProperty === 'function') {
|
2287 | var _ref2;
|
2288 |
|
2289 | return (_ref2 = inner).hasProperty.apply(_ref2, [name].concat(toConsumableArray(this.typeInstances)));
|
2290 | } else {
|
2291 | return false;
|
2292 | }
|
2293 | }
|
2294 | }, {
|
2295 | key: 'getProperty',
|
2296 | value: function getProperty(name) {
|
2297 | var inner = this.parent;
|
2298 | if (inner && typeof inner.getProperty === 'function') {
|
2299 | var _ref3;
|
2300 |
|
2301 | return (_ref3 = inner).getProperty.apply(_ref3, [name].concat(toConsumableArray(this.typeInstances)));
|
2302 | }
|
2303 | }
|
2304 | }, {
|
2305 | key: 'unwrap',
|
2306 | value: function unwrap() {
|
2307 | var _parent2;
|
2308 |
|
2309 | return (_parent2 = this.parent).unwrap.apply(_parent2, toConsumableArray(this.typeInstances));
|
2310 | }
|
2311 | }, {
|
2312 | key: 'toString',
|
2313 | value: function toString() {
|
2314 | var parent = this.parent,
|
2315 | typeInstances = this.typeInstances;
|
2316 | var name = parent.name;
|
2317 |
|
2318 | if (typeInstances.length) {
|
2319 | var items = [];
|
2320 | for (var i = 0; i < typeInstances.length; i++) {
|
2321 | var typeInstance = typeInstances[i];
|
2322 | items.push(typeInstance.toString());
|
2323 | }
|
2324 | return `${ name }<${ items.join(', ') }>`;
|
2325 | } else {
|
2326 | return name;
|
2327 | }
|
2328 | }
|
2329 | }, {
|
2330 | key: 'toJSON',
|
2331 | value: function toJSON() {
|
2332 | return {
|
2333 | typeName: this.typeName,
|
2334 | typeInstances: this.typeInstances
|
2335 | };
|
2336 | }
|
2337 | }]);
|
2338 | return TypeParameterApplication;
|
2339 | }(Type);
|
2340 |
|
2341 | var warnedInstances = new WeakSet();
|
2342 |
|
2343 | var TypeConstructor = function (_Type) {
|
2344 | inherits(TypeConstructor, _Type);
|
2345 |
|
2346 | function TypeConstructor() {
|
2347 | var _ref;
|
2348 |
|
2349 | var _temp, _this, _ret;
|
2350 |
|
2351 | classCallCheck(this, TypeConstructor);
|
2352 |
|
2353 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2354 | args[_key] = arguments[_key];
|
2355 | }
|
2356 |
|
2357 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeConstructor.__proto__ || Object.getPrototypeOf(TypeConstructor)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeConstructor', _temp), possibleConstructorReturn(_this, _ret);
|
2358 | }
|
2359 |
|
2360 | createClass(TypeConstructor, [{
|
2361 | key: 'errors',
|
2362 | value: function* errors(validation, path, input) {}
|
2363 | }, {
|
2364 | key: 'accepts',
|
2365 | value: function accepts(input) {
|
2366 | var context = this.context,
|
2367 | name = this.name;
|
2368 |
|
2369 | if (!warnedInstances.has(this)) {
|
2370 | context.emitWarningMessage(`TypeConstructor ${ name } does not implement accepts().`);
|
2371 | warnedInstances.add(this);
|
2372 | }
|
2373 | return false;
|
2374 | }
|
2375 | }, {
|
2376 | key: 'compareWith',
|
2377 | value: function compareWith(input) {
|
2378 | var context = this.context,
|
2379 | name = this.name;
|
2380 |
|
2381 | if (!warnedInstances.has(this)) {
|
2382 | context.emitWarningMessage(`TypeConstructor ${ name } does not implement compareWith().`);
|
2383 | warnedInstances.add(this);
|
2384 | }
|
2385 | return -1;
|
2386 | }
|
2387 | }, {
|
2388 | key: 'inferTypeParameters',
|
2389 | value: function inferTypeParameters(input) {
|
2390 | return [];
|
2391 | }
|
2392 | }, {
|
2393 | key: 'apply',
|
2394 | value: function apply() {
|
2395 | var target = new TypeParameterApplication(this.context);
|
2396 | target.parent = this;
|
2397 |
|
2398 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
2399 | typeInstances[_key2] = arguments[_key2];
|
2400 | }
|
2401 |
|
2402 | target.typeInstances = typeInstances;
|
2403 | return target;
|
2404 | }
|
2405 |
|
2406 | |
2407 |
|
2408 |
|
2409 |
|
2410 | }, {
|
2411 | key: 'unwrap',
|
2412 | value: function unwrap() {
|
2413 | return this;
|
2414 | }
|
2415 | }, {
|
2416 | key: 'toString',
|
2417 | value: function toString() {
|
2418 | return this.name;
|
2419 | }
|
2420 | }, {
|
2421 | key: 'toJSON',
|
2422 | value: function toJSON() {
|
2423 | return {
|
2424 | typeName: this.typeName,
|
2425 | name: this.name
|
2426 | };
|
2427 | }
|
2428 | }]);
|
2429 | return TypeConstructor;
|
2430 | }(Type);
|
2431 |
|
2432 | var GenericType = function (_TypeConstructor) {
|
2433 | inherits(GenericType, _TypeConstructor);
|
2434 |
|
2435 | function GenericType() {
|
2436 | var _ref;
|
2437 |
|
2438 | var _temp, _this, _ret;
|
2439 |
|
2440 | classCallCheck(this, GenericType);
|
2441 |
|
2442 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2443 | args[_key] = arguments[_key];
|
2444 | }
|
2445 |
|
2446 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = GenericType.__proto__ || Object.getPrototypeOf(GenericType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'GenericType', _temp), possibleConstructorReturn(_this, _ret);
|
2447 | }
|
2448 |
|
2449 | createClass(GenericType, [{
|
2450 | key: 'errors',
|
2451 | value: function* errors(validation, path, input) {
|
2452 | var name = this.name,
|
2453 | impl = this.impl,
|
2454 | context = this.context;
|
2455 |
|
2456 | if (!(input instanceof impl)) {
|
2457 | var annotation = context.getAnnotation(impl);
|
2458 | if (annotation) {
|
2459 | yield* annotation.errors(validation, path, input);
|
2460 | } else {
|
2461 | yield [path, getErrorMessage('ERR_EXPECT_INSTANCEOF', name), this];
|
2462 | }
|
2463 | }
|
2464 | }
|
2465 | }, {
|
2466 | key: 'accepts',
|
2467 | value: function accepts(input) {
|
2468 | var context = this.context,
|
2469 | impl = this.impl;
|
2470 |
|
2471 | if (input instanceof impl) {
|
2472 | return true;
|
2473 | }
|
2474 | var annotation = context.getAnnotation(impl);
|
2475 | if (annotation) {
|
2476 | return annotation.accepts(input);
|
2477 | } else {
|
2478 | return false;
|
2479 | }
|
2480 | }
|
2481 | }, {
|
2482 | key: 'compareWith',
|
2483 | value: function compareWith(input) {
|
2484 | var context = this.context,
|
2485 | impl = this.impl;
|
2486 |
|
2487 | var annotation = context.getAnnotation(impl);
|
2488 | if (annotation) {
|
2489 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
2490 | typeInstances[_key2 - 1] = arguments[_key2];
|
2491 | }
|
2492 |
|
2493 | var expected = annotation.unwrap.apply(annotation, toConsumableArray(typeInstances));
|
2494 | return compareTypes(input, expected);
|
2495 | } else if (input instanceof GenericType && (input.impl === impl || impl && impl.isPrototypeOf(input.impl))) {
|
2496 | return 0;
|
2497 | } else {
|
2498 | return -1;
|
2499 | }
|
2500 | }
|
2501 | }, {
|
2502 | key: 'unwrap',
|
2503 | value: function unwrap() {
|
2504 | var context = this.context,
|
2505 | impl = this.impl;
|
2506 |
|
2507 | if (typeof impl !== 'function') {
|
2508 | return this;
|
2509 | }
|
2510 | var annotation = context.getAnnotation(impl);
|
2511 | if (annotation != null) {
|
2512 | return annotation.unwrap.apply(annotation, arguments);
|
2513 | } else {
|
2514 | return this;
|
2515 | }
|
2516 | }
|
2517 | }, {
|
2518 | key: 'inferTypeParameters',
|
2519 | value: function inferTypeParameters(input) {
|
2520 | return [];
|
2521 | }
|
2522 | }]);
|
2523 | return GenericType;
|
2524 | }(TypeConstructor);
|
2525 |
|
2526 | function invariant(input, message) {
|
2527 | if (!input) {
|
2528 | var error = new Error(message);
|
2529 | error.name = 'InvariantViolation';
|
2530 | if (typeof Error.captureStackTrace === 'function') {
|
2531 | Error.captureStackTrace(error, invariant);
|
2532 | }
|
2533 | throw error;
|
2534 | }
|
2535 | }
|
2536 |
|
2537 | var NullLiteralType = function (_Type) {
|
2538 | inherits(NullLiteralType, _Type);
|
2539 |
|
2540 | function NullLiteralType() {
|
2541 | var _ref;
|
2542 |
|
2543 | var _temp, _this, _ret;
|
2544 |
|
2545 | classCallCheck(this, NullLiteralType);
|
2546 |
|
2547 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2548 | args[_key] = arguments[_key];
|
2549 | }
|
2550 |
|
2551 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = NullLiteralType.__proto__ || Object.getPrototypeOf(NullLiteralType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'NullLiteralType', _temp), possibleConstructorReturn(_this, _ret);
|
2552 | }
|
2553 |
|
2554 | createClass(NullLiteralType, [{
|
2555 | key: 'errors',
|
2556 | value: function* errors(validation, path, input) {
|
2557 | if (input !== null) {
|
2558 | yield [path, getErrorMessage('ERR_EXPECT_NULL'), this];
|
2559 | }
|
2560 | }
|
2561 | }, {
|
2562 | key: 'accepts',
|
2563 | value: function accepts(input) {
|
2564 | return input === null;
|
2565 | }
|
2566 | }, {
|
2567 | key: 'compareWith',
|
2568 | value: function compareWith(input) {
|
2569 | if (input instanceof NullLiteralType) {
|
2570 | return 0;
|
2571 | } else {
|
2572 | return -1;
|
2573 | }
|
2574 | }
|
2575 | }, {
|
2576 | key: 'toString',
|
2577 | value: function toString() {
|
2578 | return 'null';
|
2579 | }
|
2580 | }, {
|
2581 | key: 'toJSON',
|
2582 | value: function toJSON() {
|
2583 | return {
|
2584 | typeName: this.typeName
|
2585 | };
|
2586 | }
|
2587 | }]);
|
2588 | return NullLiteralType;
|
2589 | }(Type);
|
2590 |
|
2591 | var VoidType = function (_Type) {
|
2592 | inherits(VoidType, _Type);
|
2593 |
|
2594 | function VoidType() {
|
2595 | var _ref;
|
2596 |
|
2597 | var _temp, _this, _ret;
|
2598 |
|
2599 | classCallCheck(this, VoidType);
|
2600 |
|
2601 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2602 | args[_key] = arguments[_key];
|
2603 | }
|
2604 |
|
2605 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = VoidType.__proto__ || Object.getPrototypeOf(VoidType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'VoidType', _temp), possibleConstructorReturn(_this, _ret);
|
2606 | }
|
2607 |
|
2608 | createClass(VoidType, [{
|
2609 | key: 'errors',
|
2610 | value: function* errors(validation, path, input) {
|
2611 | if (input !== undefined) {
|
2612 | yield [path, getErrorMessage('ERR_EXPECT_VOID'), this];
|
2613 | }
|
2614 | }
|
2615 | }, {
|
2616 | key: 'accepts',
|
2617 | value: function accepts(input) {
|
2618 | return input === undefined;
|
2619 | }
|
2620 | }, {
|
2621 | key: 'compareWith',
|
2622 | value: function compareWith(input) {
|
2623 | if (input instanceof VoidType) {
|
2624 | return 0;
|
2625 | } else {
|
2626 | return -1;
|
2627 | }
|
2628 | }
|
2629 | }, {
|
2630 | key: 'toString',
|
2631 | value: function toString() {
|
2632 | return 'void';
|
2633 | }
|
2634 | }, {
|
2635 | key: 'toJSON',
|
2636 | value: function toJSON() {
|
2637 | return {
|
2638 | typeName: this.typeName
|
2639 | };
|
2640 | }
|
2641 | }]);
|
2642 | return VoidType;
|
2643 | }(Type);
|
2644 |
|
2645 | var NullableType = function (_Type) {
|
2646 | inherits(NullableType, _Type);
|
2647 |
|
2648 | function NullableType() {
|
2649 | var _ref;
|
2650 |
|
2651 | var _temp, _this, _ret;
|
2652 |
|
2653 | classCallCheck(this, NullableType);
|
2654 |
|
2655 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2656 | args[_key] = arguments[_key];
|
2657 | }
|
2658 |
|
2659 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = NullableType.__proto__ || Object.getPrototypeOf(NullableType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'NullableType', _temp), possibleConstructorReturn(_this, _ret);
|
2660 | }
|
2661 |
|
2662 | createClass(NullableType, [{
|
2663 | key: 'errors',
|
2664 | value: function* errors(validation, path, input) {
|
2665 | if (input != null) {
|
2666 | yield* this.type.errors(validation, path, input);
|
2667 | }
|
2668 | }
|
2669 | }, {
|
2670 | key: 'accepts',
|
2671 | value: function accepts(input) {
|
2672 | if (input == null) {
|
2673 | return true;
|
2674 | } else {
|
2675 | return this.type.accepts(input);
|
2676 | }
|
2677 | }
|
2678 | }, {
|
2679 | key: 'compareWith',
|
2680 | value: function compareWith(input) {
|
2681 | if (input instanceof NullLiteralType || input instanceof VoidType) {
|
2682 | return 1;
|
2683 | } else if (input instanceof NullableType) {
|
2684 | return compareTypes(this.type, input.type);
|
2685 | } else {
|
2686 | var result = compareTypes(this.type, input);
|
2687 | if (result === -1) {
|
2688 | return -1;
|
2689 | } else {
|
2690 | return 1;
|
2691 | }
|
2692 | }
|
2693 | }
|
2694 |
|
2695 | |
2696 |
|
2697 |
|
2698 |
|
2699 | }, {
|
2700 | key: 'unwrap',
|
2701 | value: function unwrap() {
|
2702 | return this.type.unwrap();
|
2703 | }
|
2704 | }, {
|
2705 | key: 'toString',
|
2706 | value: function toString() {
|
2707 | return `? ${ this.type.toString() }`;
|
2708 | }
|
2709 | }, {
|
2710 | key: 'toJSON',
|
2711 | value: function toJSON() {
|
2712 | return {
|
2713 | typeName: this.typeName,
|
2714 | type: this.type
|
2715 | };
|
2716 | }
|
2717 | }]);
|
2718 | return NullableType;
|
2719 | }(Type);
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 | function addConstraints(subject) {
|
2725 | var _subject$constraints;
|
2726 |
|
2727 | for (var _len = arguments.length, constraints = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
2728 | constraints[_key - 1] = arguments[_key];
|
2729 | }
|
2730 |
|
2731 | (_subject$constraints = subject.constraints).push.apply(_subject$constraints, toConsumableArray(constraints));
|
2732 | }
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 | function* collectConstraintErrors(subject, validation, path) {
|
2740 | var constraints = subject.constraints;
|
2741 | var length = constraints.length;
|
2742 |
|
2743 | for (var _len2 = arguments.length, input = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
2744 | input[_key2 - 3] = arguments[_key2];
|
2745 | }
|
2746 |
|
2747 | for (var i = 0; i < length; i++) {
|
2748 | var constraint = constraints[i];
|
2749 | var violation = constraint.apply(undefined, toConsumableArray(input));
|
2750 | if (typeof violation === 'string') {
|
2751 | yield [path, violation, this];
|
2752 | }
|
2753 | }
|
2754 | }
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 | function constraintsAccept(subject) {
|
2760 | var constraints = subject.constraints;
|
2761 | var length = constraints.length;
|
2762 |
|
2763 | for (var _len3 = arguments.length, input = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
2764 | input[_key3 - 1] = arguments[_key3];
|
2765 | }
|
2766 |
|
2767 | for (var i = 0; i < length; i++) {
|
2768 | var constraint = constraints[i];
|
2769 | if (typeof constraint.apply(undefined, toConsumableArray(input)) === 'string') {
|
2770 | return false;
|
2771 | }
|
2772 | }
|
2773 | return true;
|
2774 | }
|
2775 |
|
2776 | var ObjectTypeProperty = function (_Type) {
|
2777 | inherits(ObjectTypeProperty, _Type);
|
2778 |
|
2779 | function ObjectTypeProperty() {
|
2780 | var _ref;
|
2781 |
|
2782 | var _temp, _this, _ret;
|
2783 |
|
2784 | classCallCheck(this, ObjectTypeProperty);
|
2785 |
|
2786 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2787 | args[_key] = arguments[_key];
|
2788 | }
|
2789 |
|
2790 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ObjectTypeProperty.__proto__ || Object.getPrototypeOf(ObjectTypeProperty)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ObjectTypeProperty', _this['static'] = false, _this.constraints = [], _temp), possibleConstructorReturn(_this, _ret);
|
2791 | }
|
2792 |
|
2793 |
|
2794 |
|
2795 | createClass(ObjectTypeProperty, [{
|
2796 | key: 'addConstraint',
|
2797 | value: function addConstraint() {
|
2798 | for (var _len2 = arguments.length, constraints = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
2799 | constraints[_key2] = arguments[_key2];
|
2800 | }
|
2801 |
|
2802 | addConstraints.apply(undefined, [this].concat(toConsumableArray(constraints)));
|
2803 | return this;
|
2804 | }
|
2805 |
|
2806 | |
2807 |
|
2808 |
|
2809 |
|
2810 | }, {
|
2811 | key: 'isNullable',
|
2812 | value: function isNullable() {
|
2813 | return this.value instanceof NullableType;
|
2814 | }
|
2815 |
|
2816 | |
2817 |
|
2818 |
|
2819 |
|
2820 | }, {
|
2821 | key: 'existsOn',
|
2822 | value: function existsOn(input) {
|
2823 |
|
2824 | var key = this.key,
|
2825 | isStatic = this.static;
|
2826 |
|
2827 | return key in (isStatic ? input.constructor : input) === true;
|
2828 | }
|
2829 | }, {
|
2830 | key: 'errors',
|
2831 | value: function* errors(validation, path, input) {
|
2832 |
|
2833 | var optional = this.optional,
|
2834 | key = this.key,
|
2835 | value = this.value,
|
2836 | isStatic = this.static;
|
2837 |
|
2838 | var target = void 0;
|
2839 | var targetPath = void 0;
|
2840 | if (isStatic) {
|
2841 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
2842 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
2843 | return;
|
2844 | }
|
2845 | targetPath = path.concat('constructor');
|
2846 | if (typeof input.constructor !== 'function') {
|
2847 | if (!optional) {
|
2848 | yield [targetPath, getErrorMessage('ERR_EXPECT_FUNCTION'), this];
|
2849 | }
|
2850 | return;
|
2851 | }
|
2852 | targetPath.push(key);
|
2853 | target = input.constructor[key];
|
2854 | } else {
|
2855 | target = input[key];
|
2856 | targetPath = path.concat(key);
|
2857 | }
|
2858 | if (optional && target === undefined) {
|
2859 | return;
|
2860 | }
|
2861 | if (this.isNullable() && !this.existsOn(input)) {
|
2862 | yield [targetPath, getErrorMessage('ERR_MISSING_PROPERTY'), this];
|
2863 | return;
|
2864 | }
|
2865 | var hasErrors = false;
|
2866 | var _iteratorNormalCompletion = true;
|
2867 | var _didIteratorError = false;
|
2868 | var _iteratorError = undefined;
|
2869 |
|
2870 | try {
|
2871 | for (var _iterator = value.errors(validation, targetPath, target)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
2872 | var error = _step.value;
|
2873 |
|
2874 | hasErrors = true;
|
2875 | yield error;
|
2876 | }
|
2877 | } catch (err) {
|
2878 | _didIteratorError = true;
|
2879 | _iteratorError = err;
|
2880 | } finally {
|
2881 | try {
|
2882 | if (!_iteratorNormalCompletion && _iterator.return) {
|
2883 | _iterator.return();
|
2884 | }
|
2885 | } finally {
|
2886 | if (_didIteratorError) {
|
2887 | throw _iteratorError;
|
2888 | }
|
2889 | }
|
2890 | }
|
2891 |
|
2892 | if (!hasErrors) {
|
2893 | yield* collectConstraintErrors(this, validation, targetPath, target);
|
2894 | }
|
2895 | }
|
2896 | }, {
|
2897 | key: 'accepts',
|
2898 | value: function accepts(input) {
|
2899 |
|
2900 | var optional = this.optional,
|
2901 | key = this.key,
|
2902 | value = this.value,
|
2903 | isStatic = this.static;
|
2904 |
|
2905 | var target = void 0;
|
2906 | if (isStatic) {
|
2907 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
2908 | return false;
|
2909 | }
|
2910 | if (typeof input.constructor !== 'function') {
|
2911 | return optional ? true : false;
|
2912 | }
|
2913 | target = input.constructor[key];
|
2914 | } else {
|
2915 | target = input[key];
|
2916 | }
|
2917 |
|
2918 | if (optional && target === undefined) {
|
2919 | return true;
|
2920 | }
|
2921 |
|
2922 | if (this.isNullable() && !this.existsOn(input)) {
|
2923 | return false;
|
2924 | }
|
2925 |
|
2926 | if (!value.accepts(target)) {
|
2927 | return false;
|
2928 | } else {
|
2929 | return constraintsAccept(this, target);
|
2930 | }
|
2931 | }
|
2932 | }, {
|
2933 | key: 'compareWith',
|
2934 | value: function compareWith(input) {
|
2935 | if (!(input instanceof ObjectTypeProperty)) {
|
2936 | return -1;
|
2937 | } else if (input.key !== this.key) {
|
2938 | return -1;
|
2939 | } else {
|
2940 | return compareTypes(this.value, input.value);
|
2941 | }
|
2942 | }
|
2943 | }, {
|
2944 | key: 'unwrap',
|
2945 | value: function unwrap() {
|
2946 | return this.value.unwrap();
|
2947 | }
|
2948 | }, {
|
2949 | key: 'toString',
|
2950 | value: function toString() {
|
2951 | var key = this.key;
|
2952 |
|
2953 | if (typeof key === 'symbol') {
|
2954 | key = `[${ key.toString() }]`;
|
2955 | }
|
2956 | if (this.static) {
|
2957 | return `static ${ key }${ this.optional ? '?' : '' }: ${ this.value.toString() };`;
|
2958 | } else {
|
2959 | return `${ key }${ this.optional ? '?' : '' }: ${ this.value.toString() };`;
|
2960 | }
|
2961 | }
|
2962 | }, {
|
2963 | key: 'toJSON',
|
2964 | value: function toJSON() {
|
2965 | return {
|
2966 | typeName: this.typeName,
|
2967 | key: this.key,
|
2968 | value: this.value,
|
2969 | optional: this.optional
|
2970 | };
|
2971 | }
|
2972 | }]);
|
2973 | return ObjectTypeProperty;
|
2974 | }(Type);
|
2975 |
|
2976 | var ObjectTypeIndexer = function (_Type) {
|
2977 | inherits(ObjectTypeIndexer, _Type);
|
2978 |
|
2979 | function ObjectTypeIndexer() {
|
2980 | var _ref;
|
2981 |
|
2982 | var _temp, _this, _ret;
|
2983 |
|
2984 | classCallCheck(this, ObjectTypeIndexer);
|
2985 |
|
2986 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2987 | args[_key] = arguments[_key];
|
2988 | }
|
2989 |
|
2990 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ObjectTypeIndexer.__proto__ || Object.getPrototypeOf(ObjectTypeIndexer)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ObjectTypeIndexer', _temp), possibleConstructorReturn(_this, _ret);
|
2991 | }
|
2992 |
|
2993 | createClass(ObjectTypeIndexer, [{
|
2994 | key: 'errors',
|
2995 | value: function* errors(validation, path, key, value) {
|
2996 |
|
2997 | if (this.key.typeName === 'NumberType' || this.key.typeName === 'NumericLiteralType') {
|
2998 | key = +key;
|
2999 | }
|
3000 |
|
3001 | yield* this.key.errors(validation, path.concat('[[Key]]'), key);
|
3002 | yield* this.value.errors(validation, path.concat(key), value);
|
3003 | }
|
3004 | }, {
|
3005 | key: 'accepts',
|
3006 | value: function accepts(value) {
|
3007 | return this.value.accepts(value);
|
3008 | }
|
3009 | }, {
|
3010 | key: 'acceptsKey',
|
3011 | value: function acceptsKey(key) {
|
3012 |
|
3013 | if (this.key.typeName === 'NumberType' || this.key.typeName === 'NumericLiteralType') {
|
3014 | key = +key;
|
3015 | }
|
3016 | return this.key.accepts(key);
|
3017 | }
|
3018 | }, {
|
3019 | key: 'acceptsValue',
|
3020 | value: function acceptsValue(value) {
|
3021 | return this.value.accepts(value);
|
3022 | }
|
3023 | }, {
|
3024 | key: 'compareWith',
|
3025 | value: function compareWith(input) {
|
3026 | if (input instanceof ObjectTypeProperty) {
|
3027 | if (!this.key.accepts(input.key)) {
|
3028 | return -1;
|
3029 | } else {
|
3030 | return compareTypes(this.value, input.value);
|
3031 | }
|
3032 | } else if (!(input instanceof ObjectTypeIndexer)) {
|
3033 | return -1;
|
3034 | }
|
3035 |
|
3036 | var keyResult = compareTypes(this.key, input.key);
|
3037 | if (keyResult === -1) {
|
3038 | return -1;
|
3039 | }
|
3040 | var valueResult = compareTypes(this.value, input.value);
|
3041 | if (valueResult === -1) {
|
3042 | return -1;
|
3043 | }
|
3044 |
|
3045 | if (keyResult === 0 && valueResult === 0) {
|
3046 | return 0;
|
3047 | } else {
|
3048 | return 1;
|
3049 | }
|
3050 | }
|
3051 | }, {
|
3052 | key: 'unwrap',
|
3053 | value: function unwrap() {
|
3054 | return this.value.unwrap();
|
3055 | }
|
3056 | }, {
|
3057 | key: 'toString',
|
3058 | value: function toString() {
|
3059 | return `[${ this.id }: ${ this.key.toString() }]: ${ this.value.toString() };`;
|
3060 | }
|
3061 | }, {
|
3062 | key: 'toJSON',
|
3063 | value: function toJSON() {
|
3064 | return {
|
3065 | typeName: this.typeName,
|
3066 | id: this.id,
|
3067 | key: this.key,
|
3068 | value: this.value
|
3069 | };
|
3070 | }
|
3071 | }]);
|
3072 | return ObjectTypeIndexer;
|
3073 | }(Type);
|
3074 |
|
3075 | var ObjectTypeCallProperty = function (_Type) {
|
3076 | inherits(ObjectTypeCallProperty, _Type);
|
3077 |
|
3078 | function ObjectTypeCallProperty() {
|
3079 | var _ref;
|
3080 |
|
3081 | var _temp, _this, _ret;
|
3082 |
|
3083 | classCallCheck(this, ObjectTypeCallProperty);
|
3084 |
|
3085 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3086 | args[_key] = arguments[_key];
|
3087 | }
|
3088 |
|
3089 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ObjectTypeCallProperty.__proto__ || Object.getPrototypeOf(ObjectTypeCallProperty)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ObjectTypeCallProperty', _this['static'] = false, _temp), possibleConstructorReturn(_this, _ret);
|
3090 | }
|
3091 |
|
3092 |
|
3093 |
|
3094 | createClass(ObjectTypeCallProperty, [{
|
3095 | key: 'errors',
|
3096 | value: function* errors(validation, path, input) {
|
3097 |
|
3098 | var value = this.value,
|
3099 | isStatic = this.static;
|
3100 |
|
3101 |
|
3102 | var target = void 0;
|
3103 | var targetPath = void 0;
|
3104 | if (isStatic) {
|
3105 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
3106 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
3107 | return;
|
3108 | }
|
3109 | targetPath = path.concat('constructor');
|
3110 | if (typeof input.constructor !== 'function') {
|
3111 | yield [targetPath, getErrorMessage('ERR_EXPECT_FUNCTION'), this];
|
3112 | return;
|
3113 | }
|
3114 | target = input.constructor;
|
3115 | } else {
|
3116 | target = input;
|
3117 | targetPath = path;
|
3118 | }
|
3119 | yield* value.errors(validation, targetPath, target);
|
3120 | }
|
3121 | }, {
|
3122 | key: 'accepts',
|
3123 | value: function accepts(input) {
|
3124 |
|
3125 | var value = this.value,
|
3126 | isStatic = this.static;
|
3127 |
|
3128 | var target = void 0;
|
3129 | if (isStatic) {
|
3130 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
3131 | return false;
|
3132 | }
|
3133 | if (typeof input.constructor !== 'function') {
|
3134 | return false;
|
3135 | }
|
3136 | target = input.constructor;
|
3137 | } else {
|
3138 | target = input;
|
3139 | }
|
3140 | return value.accepts(target);
|
3141 | }
|
3142 | }, {
|
3143 | key: 'compareWith',
|
3144 | value: function compareWith(input) {
|
3145 | if (!(input instanceof ObjectTypeCallProperty)) {
|
3146 | return -1;
|
3147 | }
|
3148 | return compareTypes(this.value, input.value);
|
3149 | }
|
3150 | }, {
|
3151 | key: 'unwrap',
|
3152 | value: function unwrap() {
|
3153 | return this.value.unwrap();
|
3154 | }
|
3155 | }, {
|
3156 | key: 'toString',
|
3157 | value: function toString() {
|
3158 | if (this.static) {
|
3159 | return `static ${ this.value.toString() };`;
|
3160 | } else {
|
3161 | return this.value.toString();
|
3162 | }
|
3163 | }
|
3164 | }, {
|
3165 | key: 'toJSON',
|
3166 | value: function toJSON() {
|
3167 | return {
|
3168 | typeName: this.typeName,
|
3169 | value: this.value
|
3170 | };
|
3171 | }
|
3172 | }]);
|
3173 | return ObjectTypeCallProperty;
|
3174 | }(Type);
|
3175 |
|
3176 | var Declaration = function (_Type) {
|
3177 | inherits(Declaration, _Type);
|
3178 |
|
3179 | function Declaration() {
|
3180 | classCallCheck(this, Declaration);
|
3181 | return possibleConstructorReturn(this, (Declaration.__proto__ || Object.getPrototypeOf(Declaration)).apply(this, arguments));
|
3182 | }
|
3183 |
|
3184 | return Declaration;
|
3185 | }(Type);
|
3186 |
|
3187 | var VarDeclaration = function (_Declaration) {
|
3188 | inherits(VarDeclaration, _Declaration);
|
3189 |
|
3190 | function VarDeclaration() {
|
3191 | var _ref;
|
3192 |
|
3193 | var _temp, _this, _ret;
|
3194 |
|
3195 | classCallCheck(this, VarDeclaration);
|
3196 |
|
3197 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3198 | args[_key] = arguments[_key];
|
3199 | }
|
3200 |
|
3201 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = VarDeclaration.__proto__ || Object.getPrototypeOf(VarDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'VarDeclaration', _this.constraints = [], _temp), possibleConstructorReturn(_this, _ret);
|
3202 | }
|
3203 |
|
3204 | createClass(VarDeclaration, [{
|
3205 | key: 'addConstraint',
|
3206 | value: function addConstraint() {
|
3207 | for (var _len2 = arguments.length, constraints = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
3208 | constraints[_key2] = arguments[_key2];
|
3209 | }
|
3210 |
|
3211 | addConstraints.apply(undefined, [this].concat(toConsumableArray(constraints)));
|
3212 | return this;
|
3213 | }
|
3214 | }, {
|
3215 | key: 'errors',
|
3216 | value: function* errors(validation, path, input) {
|
3217 | var type = this.type;
|
3218 |
|
3219 | var hasErrors = false;
|
3220 | var _iteratorNormalCompletion = true;
|
3221 | var _didIteratorError = false;
|
3222 | var _iteratorError = undefined;
|
3223 |
|
3224 | try {
|
3225 | for (var _iterator = type.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
3226 | var error = _step.value;
|
3227 |
|
3228 | hasErrors = true;
|
3229 | yield error;
|
3230 | }
|
3231 | } catch (err) {
|
3232 | _didIteratorError = true;
|
3233 | _iteratorError = err;
|
3234 | } finally {
|
3235 | try {
|
3236 | if (!_iteratorNormalCompletion && _iterator.return) {
|
3237 | _iterator.return();
|
3238 | }
|
3239 | } finally {
|
3240 | if (_didIteratorError) {
|
3241 | throw _iteratorError;
|
3242 | }
|
3243 | }
|
3244 | }
|
3245 |
|
3246 | if (!hasErrors) {
|
3247 | yield* collectConstraintErrors(this, validation, path, input);
|
3248 | }
|
3249 | }
|
3250 | }, {
|
3251 | key: 'accepts',
|
3252 | value: function accepts(input) {
|
3253 | var type = this.type;
|
3254 |
|
3255 | if (!type.accepts(input)) {
|
3256 | return false;
|
3257 | } else if (!constraintsAccept(this, input)) {
|
3258 | return false;
|
3259 | } else {
|
3260 | return true;
|
3261 | }
|
3262 | }
|
3263 | }, {
|
3264 | key: 'compareWith',
|
3265 | value: function compareWith(input) {
|
3266 | return compareTypes(this.type, input);
|
3267 | }
|
3268 | }, {
|
3269 | key: 'unwrap',
|
3270 | value: function unwrap() {
|
3271 | return this.type.unwrap();
|
3272 | }
|
3273 | }, {
|
3274 | key: 'toString',
|
3275 | value: function toString() {
|
3276 | return `declare var ${ this.name }: ${ this.type.toString() };`;
|
3277 | }
|
3278 | }]);
|
3279 | return VarDeclaration;
|
3280 | }(Declaration);
|
3281 |
|
3282 | var TypeDeclaration = function (_Declaration) {
|
3283 | inherits(TypeDeclaration, _Declaration);
|
3284 |
|
3285 | function TypeDeclaration() {
|
3286 | var _ref;
|
3287 |
|
3288 | var _temp, _this, _ret;
|
3289 |
|
3290 | classCallCheck(this, TypeDeclaration);
|
3291 |
|
3292 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3293 | args[_key] = arguments[_key];
|
3294 | }
|
3295 |
|
3296 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeDeclaration.__proto__ || Object.getPrototypeOf(TypeDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeDeclaration', _temp), possibleConstructorReturn(_this, _ret);
|
3297 | }
|
3298 |
|
3299 | createClass(TypeDeclaration, [{
|
3300 | key: 'addConstraint',
|
3301 | value: function addConstraint() {
|
3302 | var _typeAlias;
|
3303 |
|
3304 | (_typeAlias = this.typeAlias).addConstraint.apply(_typeAlias, arguments);
|
3305 | return this;
|
3306 | }
|
3307 | }, {
|
3308 | key: 'errors',
|
3309 | value: function* errors(validation, path, input) {
|
3310 | yield* this.typeAlias.errors(validation, path, input);
|
3311 | }
|
3312 | }, {
|
3313 | key: 'apply',
|
3314 | value: function apply() {
|
3315 | var _typeAlias2;
|
3316 |
|
3317 | return (_typeAlias2 = this.typeAlias).apply.apply(_typeAlias2, arguments);
|
3318 | }
|
3319 | }, {
|
3320 | key: 'accepts',
|
3321 | value: function accepts(input) {
|
3322 | return this.typeAlias.accepts(input);
|
3323 | }
|
3324 | }, {
|
3325 | key: 'compareWith',
|
3326 | value: function compareWith(input) {
|
3327 | return compareTypes(this.typeAlias, input);
|
3328 | }
|
3329 | }, {
|
3330 | key: 'hasProperty',
|
3331 | value: function hasProperty(name) {
|
3332 | var _typeAlias3;
|
3333 |
|
3334 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
3335 | typeInstances[_key2 - 1] = arguments[_key2];
|
3336 | }
|
3337 |
|
3338 | return (_typeAlias3 = this.typeAlias).hasProperty.apply(_typeAlias3, [name].concat(toConsumableArray(typeInstances)));
|
3339 | }
|
3340 | }, {
|
3341 | key: 'getProperty',
|
3342 | value: function getProperty(name) {
|
3343 | var _typeAlias4;
|
3344 |
|
3345 | for (var _len3 = arguments.length, typeInstances = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
3346 | typeInstances[_key3 - 1] = arguments[_key3];
|
3347 | }
|
3348 |
|
3349 | return (_typeAlias4 = this.typeAlias).getProperty.apply(_typeAlias4, [name].concat(toConsumableArray(typeInstances)));
|
3350 | }
|
3351 |
|
3352 | |
3353 |
|
3354 |
|
3355 |
|
3356 | }, {
|
3357 | key: 'unwrap',
|
3358 | value: function unwrap() {
|
3359 | var _typeAlias5;
|
3360 |
|
3361 | return (_typeAlias5 = this.typeAlias).unwrap.apply(_typeAlias5, arguments);
|
3362 | }
|
3363 | }, {
|
3364 | key: 'toString',
|
3365 | value: function toString() {
|
3366 | return `declare ${ this.typeAlias.toString(true) };`;
|
3367 | }
|
3368 | }, {
|
3369 | key: 'type',
|
3370 | get: function get$$1() {
|
3371 | return this.typeAlias.type;
|
3372 | }
|
3373 | }]);
|
3374 | return TypeDeclaration;
|
3375 | }(Declaration);
|
3376 |
|
3377 | var ModuleDeclaration = function (_Declaration) {
|
3378 | inherits(ModuleDeclaration, _Declaration);
|
3379 |
|
3380 | function ModuleDeclaration() {
|
3381 | var _ref;
|
3382 |
|
3383 | var _temp, _this, _ret;
|
3384 |
|
3385 | classCallCheck(this, ModuleDeclaration);
|
3386 |
|
3387 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3388 | args[_key] = arguments[_key];
|
3389 | }
|
3390 |
|
3391 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ModuleDeclaration.__proto__ || Object.getPrototypeOf(ModuleDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ModuleDeclaration', _temp), possibleConstructorReturn(_this, _ret);
|
3392 | }
|
3393 |
|
3394 | createClass(ModuleDeclaration, [{
|
3395 | key: 'get',
|
3396 | value: function get$$1(name) {
|
3397 | var moduleExports = this.moduleExports;
|
3398 |
|
3399 | if (moduleExports) {
|
3400 | var exporting = moduleExports.unwrap();
|
3401 | if (typeof exporting.getProperty === 'function') {
|
3402 | var prop = exporting.getProperty(name);
|
3403 | if (prop) {
|
3404 | return prop.unwrap();
|
3405 | }
|
3406 | }
|
3407 | } else {
|
3408 | var declaration = this.declarations[name];
|
3409 | if (declaration) {
|
3410 | return declaration.unwrap();
|
3411 | }
|
3412 | }
|
3413 | }
|
3414 | }, {
|
3415 | key: 'errors',
|
3416 | value: function* errors(validation, path, input) {
|
3417 |
|
3418 |
|
3419 | }
|
3420 | }, {
|
3421 | key: 'import',
|
3422 | value: function _import(moduleName) {
|
3423 | if (/^\.\//.test(moduleName)) {
|
3424 | moduleName = `${ this.name }${ moduleName.slice(1) }`;
|
3425 | }
|
3426 | return this.innerContext.import(moduleName);
|
3427 | }
|
3428 | }, {
|
3429 | key: 'toString',
|
3430 | value: function toString() {
|
3431 | var name = this.name,
|
3432 | declarations = this.declarations,
|
3433 | modules = this.modules,
|
3434 | moduleExports = this.moduleExports;
|
3435 |
|
3436 | var body = [];
|
3437 | for (var _name in declarations) {
|
3438 |
|
3439 | var declaration = declarations[_name];
|
3440 | body.push(declaration.toString(true));
|
3441 | }
|
3442 | if (modules) {
|
3443 | for (var _name2 in modules) {
|
3444 |
|
3445 | var module = modules[_name2];
|
3446 | body.push(module.toString());
|
3447 | }
|
3448 | }
|
3449 | if (moduleExports) {
|
3450 | body.push(moduleExports.toString());
|
3451 | }
|
3452 | return `declare module "${ name }" {\n${ indent$1(body.join('\n\n')) }}`;
|
3453 | }
|
3454 | }, {
|
3455 | key: 'moduleType',
|
3456 | get: function get$$1() {
|
3457 | if (this.moduleExports) {
|
3458 | return 'commonjs';
|
3459 | } else {
|
3460 | return 'es6';
|
3461 | }
|
3462 | }
|
3463 | }, {
|
3464 | key: 'isCommonJS',
|
3465 | get: function get$$1() {
|
3466 | return this.moduleExports ? true : false;
|
3467 | }
|
3468 | }, {
|
3469 | key: 'isES6',
|
3470 | get: function get$$1() {
|
3471 | return this.moduleExports ? false : true;
|
3472 | }
|
3473 | }, {
|
3474 | key: 'declarations',
|
3475 | get: function get$$1() {
|
3476 | var innerContext = this.innerContext;
|
3477 |
|
3478 | return innerContext[NameRegistrySymbol];
|
3479 | }
|
3480 | }, {
|
3481 | key: 'modules',
|
3482 | get: function get$$1() {
|
3483 | var innerContext = this.innerContext;
|
3484 |
|
3485 | return innerContext[ModuleRegistrySymbol];
|
3486 | }
|
3487 | }]);
|
3488 | return ModuleDeclaration;
|
3489 | }(Declaration);
|
3490 |
|
3491 | function indent$1(input) {
|
3492 | var lines = input.split('\n');
|
3493 | var length = lines.length;
|
3494 |
|
3495 | for (var i = 0; i < length; i++) {
|
3496 | lines[i] = ` ${ lines[i] }`;
|
3497 | }
|
3498 | return lines.join('\n');
|
3499 | }
|
3500 |
|
3501 | var ModuleExports = function (_Declaration) {
|
3502 | inherits(ModuleExports, _Declaration);
|
3503 |
|
3504 | function ModuleExports() {
|
3505 | var _ref;
|
3506 |
|
3507 | var _temp, _this, _ret;
|
3508 |
|
3509 | classCallCheck(this, ModuleExports);
|
3510 |
|
3511 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3512 | args[_key] = arguments[_key];
|
3513 | }
|
3514 |
|
3515 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ModuleExports.__proto__ || Object.getPrototypeOf(ModuleExports)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ModuleExports', _temp), possibleConstructorReturn(_this, _ret);
|
3516 | }
|
3517 |
|
3518 | createClass(ModuleExports, [{
|
3519 | key: 'errors',
|
3520 | value: function* errors(validation, path, input) {
|
3521 | yield* this.type.errors(validation, path, input);
|
3522 | }
|
3523 | }, {
|
3524 | key: 'unwrap',
|
3525 | value: function unwrap() {
|
3526 | return this.type.unwrap();
|
3527 | }
|
3528 | }, {
|
3529 | key: 'toString',
|
3530 | value: function toString() {
|
3531 | return `declare module.exports: ${ this.type.toString() };`;
|
3532 | }
|
3533 | }]);
|
3534 | return ModuleExports;
|
3535 | }(Declaration);
|
3536 |
|
3537 | var ClassDeclaration = function (_Declaration) {
|
3538 | inherits(ClassDeclaration, _Declaration);
|
3539 |
|
3540 | function ClassDeclaration() {
|
3541 | var _ref;
|
3542 |
|
3543 | var _temp, _this, _ret;
|
3544 |
|
3545 | classCallCheck(this, ClassDeclaration);
|
3546 |
|
3547 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3548 | args[_key] = arguments[_key];
|
3549 | }
|
3550 |
|
3551 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ClassDeclaration.__proto__ || Object.getPrototypeOf(ClassDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ClassDeclaration', _this.shapeID = Symbol(), _temp), possibleConstructorReturn(_this, _ret);
|
3552 | }
|
3553 |
|
3554 | createClass(ClassDeclaration, [{
|
3555 | key: 'errors',
|
3556 | value: function* errors(validation, path, input) {
|
3557 | var body = this.body;
|
3558 |
|
3559 | var superClass = this.superClass && this.superClass.unwrap();
|
3560 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
3561 | yield [path, getErrorMessage('ERR_EXPECT_INSTANCEOF', this.name), this];
|
3562 | return;
|
3563 | }
|
3564 | if (superClass) {
|
3565 | var _iteratorNormalCompletion = true;
|
3566 | var _didIteratorError = false;
|
3567 | var _iteratorError = undefined;
|
3568 |
|
3569 | try {
|
3570 | for (var _iterator = superClass.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
3571 | var _ref2 = _step.value;
|
3572 |
|
3573 | var _ref3 = slicedToArray(_ref2, 3);
|
3574 |
|
3575 | var errorPath = _ref3[0];
|
3576 | var errorMessage = _ref3[1];
|
3577 | var expectedType = _ref3[2];
|
3578 |
|
3579 | var propertyName = errorPath[path.length];
|
3580 | if (body.getProperty(propertyName)) {
|
3581 | continue;
|
3582 | } else {
|
3583 | yield [errorPath, errorMessage, expectedType];
|
3584 | }
|
3585 | }
|
3586 | } catch (err) {
|
3587 | _didIteratorError = true;
|
3588 | _iteratorError = err;
|
3589 | } finally {
|
3590 | try {
|
3591 | if (!_iteratorNormalCompletion && _iterator.return) {
|
3592 | _iterator.return();
|
3593 | }
|
3594 | } finally {
|
3595 | if (_didIteratorError) {
|
3596 | throw _iteratorError;
|
3597 | }
|
3598 | }
|
3599 | }
|
3600 | }
|
3601 | yield* body.errors(validation, path, input);
|
3602 | }
|
3603 | }, {
|
3604 | key: 'accepts',
|
3605 | value: function accepts(input) {
|
3606 | var body = this.body;
|
3607 |
|
3608 | var superClass = this.superClass && this.superClass.unwrap();
|
3609 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
3610 | return false;
|
3611 | } else if (superClass && !superClass.accepts(input)) {
|
3612 | return false;
|
3613 | } else if (!body.accepts(input)) {
|
3614 | return false;
|
3615 | } else {
|
3616 | return true;
|
3617 | }
|
3618 | }
|
3619 | }, {
|
3620 | key: 'compareWith',
|
3621 | value: function compareWith(input) {
|
3622 | if (input instanceof ClassDeclaration) {
|
3623 | if (input === this) {
|
3624 | return 0;
|
3625 | } else if (this.isSuperClassOf(input)) {
|
3626 | return 1;
|
3627 | } else {
|
3628 | return -1;
|
3629 | }
|
3630 | }
|
3631 | return compareTypes(this.body, input);
|
3632 | }
|
3633 |
|
3634 | |
3635 |
|
3636 |
|
3637 |
|
3638 | }, {
|
3639 | key: 'getProperty',
|
3640 | value: function getProperty(key) {
|
3641 | var body = this.body,
|
3642 | superClass = this.superClass;
|
3643 |
|
3644 | var prop = body.getProperty(key);
|
3645 | if (prop) {
|
3646 | return prop;
|
3647 | } else if (superClass && typeof superClass.getProperty === 'function') {
|
3648 | return superClass.getProperty(key);
|
3649 | }
|
3650 | }
|
3651 |
|
3652 | |
3653 |
|
3654 |
|
3655 |
|
3656 | }, {
|
3657 | key: 'hasProperty',
|
3658 | value: function hasProperty(key) {
|
3659 | var body = this.body,
|
3660 | superClass = this.superClass;
|
3661 |
|
3662 | if (body.hasProperty(key)) {
|
3663 | return true;
|
3664 | } else if (superClass && typeof superClass.hasProperty === 'function') {
|
3665 | return superClass.hasProperty(key);
|
3666 | } else {
|
3667 | return false;
|
3668 | }
|
3669 | }
|
3670 |
|
3671 | |
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 | }, {
|
3677 | key: 'isSuperClassOf',
|
3678 | value: function isSuperClassOf(candidate) {
|
3679 | var body = this.body,
|
3680 | shapeID = this.shapeID;
|
3681 |
|
3682 | var current = candidate;
|
3683 |
|
3684 | while (current != null) {
|
3685 | if (current === this || current === body || current.shapeID === shapeID) {
|
3686 | return true;
|
3687 | }
|
3688 | if (current instanceof ClassDeclaration) {
|
3689 | current = current.superClass;
|
3690 | } else {
|
3691 | current = current.unwrap();
|
3692 | }
|
3693 | }
|
3694 | return false;
|
3695 | }
|
3696 | }, {
|
3697 | key: 'apply',
|
3698 | value: function apply() {
|
3699 | var target = new TypeParameterApplication(this.context);
|
3700 | target.parent = this;
|
3701 |
|
3702 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
3703 | typeInstances[_key2] = arguments[_key2];
|
3704 | }
|
3705 |
|
3706 | target.typeInstances = typeInstances;
|
3707 | return target;
|
3708 | }
|
3709 | }, {
|
3710 | key: 'toString',
|
3711 | value: function toString(withDeclaration) {
|
3712 | var name = this.name,
|
3713 | superClass = this.superClass,
|
3714 | body = this.body;
|
3715 |
|
3716 | if (withDeclaration) {
|
3717 | var superClassName = superClass && (typeof superClass.name === 'string' && superClass.name || superClass.toString());
|
3718 | return `declare class ${ name }${ superClassName ? ` extends ${ superClassName }` : '' } ${ body.toString() }`;
|
3719 | } else {
|
3720 | return name;
|
3721 | }
|
3722 | }
|
3723 | }, {
|
3724 | key: 'properties',
|
3725 | get: function get$$1() {
|
3726 | var body = this.body,
|
3727 | superClass = this.superClass;
|
3728 |
|
3729 | if (superClass == null) {
|
3730 | return body.properties;
|
3731 | }
|
3732 | var bodyProps = body.properties;
|
3733 | var superProps = superClass.unwrap().properties;
|
3734 | var seen = {};
|
3735 | var seenStatic = {};
|
3736 | var props = [];
|
3737 | for (var i = 0; i < superProps.length; i++) {
|
3738 | var prop = superProps[i];
|
3739 | props.push(prop);
|
3740 | if (prop.static) {
|
3741 | seenStatic[prop.key] = i;
|
3742 | } else {
|
3743 | seen[prop.key] = i;
|
3744 | }
|
3745 | }
|
3746 | for (var _i = 0; _i < bodyProps.length; _i++) {
|
3747 | var _prop = bodyProps[_i];
|
3748 | if (seen[_prop.key]) {
|
3749 | props[_i] = _prop;
|
3750 | } else {
|
3751 | props.push(_prop);
|
3752 | }
|
3753 | }
|
3754 | return props;
|
3755 | }
|
3756 | }]);
|
3757 | return ClassDeclaration;
|
3758 | }(Declaration);
|
3759 |
|
3760 | var PartialType = function (_Type) {
|
3761 | inherits(PartialType, _Type);
|
3762 |
|
3763 | function PartialType() {
|
3764 | var _ref;
|
3765 |
|
3766 | var _temp, _this, _ret;
|
3767 |
|
3768 | classCallCheck(this, PartialType);
|
3769 |
|
3770 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3771 | args[_key] = arguments[_key];
|
3772 | }
|
3773 |
|
3774 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = PartialType.__proto__ || Object.getPrototypeOf(PartialType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'PartialType', _this.typeParameters = [], _temp), possibleConstructorReturn(_this, _ret);
|
3775 | }
|
3776 |
|
3777 | createClass(PartialType, [{
|
3778 | key: 'typeParameter',
|
3779 | value: function typeParameter(id, bound, defaultType) {
|
3780 | var target = new TypeParameter(this.context);
|
3781 | target.id = id;
|
3782 | target.bound = bound;
|
3783 | target.default = defaultType;
|
3784 | this.typeParameters.push(target);
|
3785 | return target;
|
3786 | }
|
3787 | }, {
|
3788 | key: 'apply',
|
3789 | value: function apply() {
|
3790 | var target = new TypeParameterApplication(this.context);
|
3791 | target.parent = this;
|
3792 |
|
3793 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
3794 | typeInstances[_key2] = arguments[_key2];
|
3795 | }
|
3796 |
|
3797 | target.typeInstances = typeInstances;
|
3798 | return target;
|
3799 | }
|
3800 | }, {
|
3801 | key: 'errors',
|
3802 | value: function* errors(validation, path, input) {
|
3803 | var constraints = this.constraints,
|
3804 | type = this.type;
|
3805 |
|
3806 | var hasErrors = false;
|
3807 | var _iteratorNormalCompletion = true;
|
3808 | var _didIteratorError = false;
|
3809 | var _iteratorError = undefined;
|
3810 |
|
3811 | try {
|
3812 | for (var _iterator = type.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
3813 | var error = _step.value;
|
3814 |
|
3815 | hasErrors = true;
|
3816 | yield error;
|
3817 | }
|
3818 | } catch (err) {
|
3819 | _didIteratorError = true;
|
3820 | _iteratorError = err;
|
3821 | } finally {
|
3822 | try {
|
3823 | if (!_iteratorNormalCompletion && _iterator.return) {
|
3824 | _iterator.return();
|
3825 | }
|
3826 | } finally {
|
3827 | if (_didIteratorError) {
|
3828 | throw _iteratorError;
|
3829 | }
|
3830 | }
|
3831 | }
|
3832 |
|
3833 | if (!hasErrors && constraints) {
|
3834 | yield* collectConstraintErrors(this, validation, path, input);
|
3835 | }
|
3836 | }
|
3837 | }, {
|
3838 | key: 'accepts',
|
3839 | value: function accepts(input) {
|
3840 | var constraints = this.constraints,
|
3841 | type = this.type;
|
3842 |
|
3843 | if (!type.accepts(input)) {
|
3844 | return false;
|
3845 | } else if (constraints && !constraintsAccept(this, input)) {
|
3846 | return false;
|
3847 | } else {
|
3848 | return true;
|
3849 | }
|
3850 | }
|
3851 | }, {
|
3852 | key: 'compareWith',
|
3853 | value: function compareWith(input) {
|
3854 | if (input === this) {
|
3855 | return 0;
|
3856 | } else {
|
3857 | return compareTypes(this.type, input);
|
3858 | }
|
3859 | }
|
3860 | }, {
|
3861 | key: 'toString',
|
3862 | value: function toString(expand) {
|
3863 | var type = this.type;
|
3864 |
|
3865 | return type.toString(expand);
|
3866 | }
|
3867 |
|
3868 | |
3869 |
|
3870 |
|
3871 |
|
3872 | }, {
|
3873 | key: 'unwrap',
|
3874 | value: function unwrap() {
|
3875 | return this.type.unwrap();
|
3876 | }
|
3877 | }, {
|
3878 | key: 'toJSON',
|
3879 | value: function toJSON() {
|
3880 | return {
|
3881 | typeName: this.typeName,
|
3882 | typeParameters: this.typeParameters,
|
3883 | type: this.type
|
3884 | };
|
3885 | }
|
3886 | }]);
|
3887 | return PartialType;
|
3888 | }(Type);
|
3889 |
|
3890 | var ParameterizedClassDeclaration = function (_Declaration) {
|
3891 | inherits(ParameterizedClassDeclaration, _Declaration);
|
3892 |
|
3893 | function ParameterizedClassDeclaration() {
|
3894 | var _ref;
|
3895 |
|
3896 | var _temp, _this, _ret;
|
3897 |
|
3898 | classCallCheck(this, ParameterizedClassDeclaration);
|
3899 |
|
3900 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
3901 | args[_key] = arguments[_key];
|
3902 | }
|
3903 |
|
3904 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ParameterizedClassDeclaration.__proto__ || Object.getPrototypeOf(ParameterizedClassDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ParameterizedClassDeclaration', _this.shapeID = Symbol(), _temp), possibleConstructorReturn(_this, _ret);
|
3905 | }
|
3906 |
|
3907 | createClass(ParameterizedClassDeclaration, [{
|
3908 | key: 'errors',
|
3909 | value: function* errors(validation, path, input) {
|
3910 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
3911 | typeInstances[_key2 - 3] = arguments[_key2];
|
3912 | }
|
3913 |
|
3914 | yield* getPartial.apply(undefined, [this].concat(toConsumableArray(typeInstances))).errors(validation, path, input);
|
3915 | }
|
3916 | }, {
|
3917 | key: 'accepts',
|
3918 | value: function accepts(input) {
|
3919 | for (var _len3 = arguments.length, typeInstances = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
3920 | typeInstances[_key3 - 1] = arguments[_key3];
|
3921 | }
|
3922 |
|
3923 | return getPartial.apply(undefined, [this].concat(toConsumableArray(typeInstances))).accepts(input);
|
3924 | }
|
3925 | }, {
|
3926 | key: 'compareWith',
|
3927 | value: function compareWith(input) {
|
3928 | return getPartial(this).compareWith(input);
|
3929 | }
|
3930 | }, {
|
3931 | key: 'unwrap',
|
3932 | value: function unwrap() {
|
3933 | for (var _len4 = arguments.length, typeInstances = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
3934 | typeInstances[_key4] = arguments[_key4];
|
3935 | }
|
3936 |
|
3937 | return getPartial.apply(undefined, [this].concat(toConsumableArray(typeInstances))).type;
|
3938 | }
|
3939 | }, {
|
3940 | key: 'isSuperClassOf',
|
3941 | value: function isSuperClassOf(candidate) {
|
3942 | return getPartial(this).type.isSuperClassOf(candidate);
|
3943 | }
|
3944 | }, {
|
3945 | key: 'apply',
|
3946 | value: function apply() {
|
3947 | var target = new TypeParameterApplication(this.context);
|
3948 | target.parent = this;
|
3949 |
|
3950 | for (var _len5 = arguments.length, typeInstances = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
3951 | typeInstances[_key5] = arguments[_key5];
|
3952 | }
|
3953 |
|
3954 | target.typeInstances = typeInstances;
|
3955 | return target;
|
3956 | }
|
3957 | }, {
|
3958 | key: 'toString',
|
3959 | value: function toString(withDeclaration) {
|
3960 | if (!withDeclaration) {
|
3961 | return this.name;
|
3962 | }
|
3963 | var partial = getPartial(this);
|
3964 | var type = partial.type,
|
3965 | typeParameters = partial.typeParameters;
|
3966 |
|
3967 | if (typeParameters.length === 0) {
|
3968 | return partial.toString(true);
|
3969 | }
|
3970 | var items = [];
|
3971 | for (var i = 0; i < typeParameters.length; i++) {
|
3972 | var typeParameter = typeParameters[i];
|
3973 | items.push(typeParameter.toString(true));
|
3974 | }
|
3975 | var superClass = type.superClass,
|
3976 | body = type.body;
|
3977 |
|
3978 | var superClassName = superClass && (typeof superClass.name === 'string' && superClass.name || superClass.toString());
|
3979 | return `declare class ${ this.name }<${ items.join(', ') }>${ superClassName ? ` extends ${ superClassName }` : '' } ${ body.toString() }`;
|
3980 | }
|
3981 | }, {
|
3982 | key: 'toJSON',
|
3983 | value: function toJSON() {
|
3984 | return getPartial(this).toJSON();
|
3985 | }
|
3986 | }, {
|
3987 | key: 'superClass',
|
3988 | get: function get$$1() {
|
3989 | return getPartial(this).type.superClass;
|
3990 | }
|
3991 | }, {
|
3992 | key: 'body',
|
3993 | get: function get$$1() {
|
3994 | return getPartial(this).type.body;
|
3995 | }
|
3996 | }, {
|
3997 | key: 'properties',
|
3998 | get: function get$$1() {
|
3999 | return getPartial(this).type.properties;
|
4000 | }
|
4001 | }, {
|
4002 | key: 'typeParameters',
|
4003 | get: function get$$1() {
|
4004 | return getPartial(this).typeParameters;
|
4005 | }
|
4006 | }]);
|
4007 | return ParameterizedClassDeclaration;
|
4008 | }(Declaration);
|
4009 |
|
4010 | function getPartial(parent) {
|
4011 | var context = parent.context,
|
4012 | bodyCreator = parent.bodyCreator;
|
4013 |
|
4014 | var partial = new PartialType(context);
|
4015 | var body = bodyCreator(partial);
|
4016 | if (Array.isArray(body)) {
|
4017 | partial.type = context.class.apply(context, [parent.name].concat(toConsumableArray(body)));
|
4018 | } else {
|
4019 | partial.type = context.class(parent.name, body);
|
4020 | }
|
4021 |
|
4022 | partial.type.shapeID = parent.shapeID;
|
4023 |
|
4024 | var typeParameters = partial.typeParameters;
|
4025 |
|
4026 | for (var _len6 = arguments.length, typeInstances = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
4027 | typeInstances[_key6 - 1] = arguments[_key6];
|
4028 | }
|
4029 |
|
4030 | var limit = Math.min(typeInstances.length, typeParameters.length);
|
4031 | for (var i = 0; i < limit; i++) {
|
4032 | var typeParameter = typeParameters[i];
|
4033 | var typeInstance = typeInstances[i];
|
4034 | if (typeParameter.bound && typeParameter.bound !== typeInstance) {
|
4035 |
|
4036 |
|
4037 | typeParameter.bound = context.intersect(typeParameter.bound, typeInstance);
|
4038 | } else {
|
4039 | typeParameter.bound = typeInstance;
|
4040 | }
|
4041 | }
|
4042 |
|
4043 | return partial;
|
4044 | }
|
4045 |
|
4046 | var ExtendsDeclaration = function (_Declaration) {
|
4047 | inherits(ExtendsDeclaration, _Declaration);
|
4048 |
|
4049 | function ExtendsDeclaration() {
|
4050 | var _ref;
|
4051 |
|
4052 | var _temp, _this, _ret;
|
4053 |
|
4054 | classCallCheck(this, ExtendsDeclaration);
|
4055 |
|
4056 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4057 | args[_key] = arguments[_key];
|
4058 | }
|
4059 |
|
4060 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ExtendsDeclaration.__proto__ || Object.getPrototypeOf(ExtendsDeclaration)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ExtendsDeclaration', _temp), possibleConstructorReturn(_this, _ret);
|
4061 | }
|
4062 |
|
4063 | createClass(ExtendsDeclaration, [{
|
4064 | key: 'errors',
|
4065 | value: function* errors(validation, path, input) {
|
4066 | yield* this.type.errors(validation, path, input);
|
4067 | }
|
4068 | }, {
|
4069 | key: 'unwrap',
|
4070 | value: function unwrap() {
|
4071 | return this.type.unwrap();
|
4072 | }
|
4073 | }, {
|
4074 | key: 'toString',
|
4075 | value: function toString(withDeclaration) {
|
4076 | var type = this.type;
|
4077 |
|
4078 | if (withDeclaration) {
|
4079 | return `extends ${ type.toString() }`;
|
4080 | } else {
|
4081 | return type.toString();
|
4082 | }
|
4083 | }
|
4084 | }]);
|
4085 | return ExtendsDeclaration;
|
4086 | }(Declaration);
|
4087 |
|
4088 | var ObjectType = function (_Type) {
|
4089 | inherits(ObjectType, _Type);
|
4090 |
|
4091 | function ObjectType() {
|
4092 | var _ref;
|
4093 |
|
4094 | var _temp, _this, _ret;
|
4095 |
|
4096 | classCallCheck(this, ObjectType);
|
4097 |
|
4098 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4099 | args[_key] = arguments[_key];
|
4100 | }
|
4101 |
|
4102 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ObjectType.__proto__ || Object.getPrototypeOf(ObjectType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ObjectType', _this.properties = [], _this.indexers = [], _this.callProperties = [], _this.exact = false, _temp), possibleConstructorReturn(_this, _ret);
|
4103 | }
|
4104 |
|
4105 | createClass(ObjectType, [{
|
4106 | key: 'getProperty',
|
4107 |
|
4108 |
|
4109 | |
4110 |
|
4111 |
|
4112 | value: function getProperty(key) {
|
4113 | var properties = this.properties;
|
4114 | var length = properties.length;
|
4115 |
|
4116 | for (var i = 0; i < length; i++) {
|
4117 | var property = properties[i];
|
4118 | if (property.key === key) {
|
4119 | return property;
|
4120 | }
|
4121 | }
|
4122 | return this.getIndexer(key);
|
4123 | }
|
4124 |
|
4125 | |
4126 |
|
4127 |
|
4128 |
|
4129 | }, {
|
4130 | key: 'hasProperty',
|
4131 | value: function hasProperty(key) {
|
4132 | var properties = this.properties;
|
4133 | var length = properties.length;
|
4134 |
|
4135 | for (var i = 0; i < length; i++) {
|
4136 | var property = properties[i];
|
4137 | if (property.key === key) {
|
4138 | return true;
|
4139 | }
|
4140 | }
|
4141 | return this.hasIndexer(key);
|
4142 | }
|
4143 |
|
4144 | |
4145 |
|
4146 |
|
4147 |
|
4148 | }, {
|
4149 | key: 'getIndexer',
|
4150 | value: function getIndexer(key) {
|
4151 | var indexers = this.indexers;
|
4152 | var length = indexers.length;
|
4153 |
|
4154 | for (var i = 0; i < length; i++) {
|
4155 | var indexer = indexers[i];
|
4156 | if (indexer.acceptsKey(key)) {
|
4157 | return indexer;
|
4158 | }
|
4159 | }
|
4160 | }
|
4161 |
|
4162 | |
4163 |
|
4164 |
|
4165 |
|
4166 | }, {
|
4167 | key: 'hasIndexer',
|
4168 | value: function hasIndexer(key) {
|
4169 | var indexers = this.indexers;
|
4170 | var length = indexers.length;
|
4171 |
|
4172 | for (var i = 0; i < length; i++) {
|
4173 | var indexer = indexers[i];
|
4174 | if (indexer.acceptsKey(key)) {
|
4175 | return true;
|
4176 | }
|
4177 | }
|
4178 | return false;
|
4179 | }
|
4180 | }, {
|
4181 | key: 'errors',
|
4182 | value: function* errors(validation, path, input) {
|
4183 | if (input === null) {
|
4184 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
4185 | return;
|
4186 | }
|
4187 |
|
4188 | var hasCallProperties = this.callProperties.length > 0;
|
4189 |
|
4190 | if (hasCallProperties) {
|
4191 | if (!acceptsCallProperties(this, input)) {
|
4192 | yield [path, getErrorMessage('ERR_EXPECT_CALLABLE'), this];
|
4193 | }
|
4194 | } else if (typeof input !== 'object') {
|
4195 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
4196 | return;
|
4197 | }
|
4198 |
|
4199 | if (validation.inCycle(this, input)) {
|
4200 | return;
|
4201 | }
|
4202 | validation.startCycle(this, input);
|
4203 |
|
4204 | if (this.indexers.length > 0) {
|
4205 | yield* collectErrorsWithIndexers(this, validation, path, input);
|
4206 | } else if (this.exact) {
|
4207 | yield* collectErrorsExact(this, validation, path, input);
|
4208 | } else {
|
4209 | yield* collectErrorsWithoutIndexers(this, validation, path, input);
|
4210 | }
|
4211 | validation.endCycle(this, input);
|
4212 | }
|
4213 | }, {
|
4214 | key: 'accepts',
|
4215 | value: function accepts(input) {
|
4216 | if (input === null) {
|
4217 | return false;
|
4218 | }
|
4219 | var hasCallProperties = this.callProperties.length > 0;
|
4220 |
|
4221 | if (hasCallProperties) {
|
4222 | if (!acceptsCallProperties(this, input)) {
|
4223 | return false;
|
4224 | }
|
4225 | } else if (typeof input !== 'object') {
|
4226 | return false;
|
4227 | }
|
4228 | if (inValidationCycle(this, input)) {
|
4229 | return true;
|
4230 | }
|
4231 | startValidationCycle(this, input);
|
4232 |
|
4233 | var result = void 0;
|
4234 | if (this.indexers.length > 0) {
|
4235 | result = acceptsWithIndexers(this, input);
|
4236 | } else if (this.exact) {
|
4237 | result = acceptsExact(this, input);
|
4238 | } else {
|
4239 | result = acceptsWithoutIndexers(this, input);
|
4240 | }
|
4241 | endValidationCycle(this, input);
|
4242 | return result;
|
4243 | }
|
4244 | }, {
|
4245 | key: 'compareWith',
|
4246 | value: function compareWith(input) {
|
4247 | if (!(input instanceof ObjectType || input instanceof ClassDeclaration || input instanceof ParameterizedClassDeclaration)) {
|
4248 | return -1;
|
4249 | }
|
4250 | var hasCallProperties = this.callProperties.length > 0;
|
4251 |
|
4252 | var isGreater = false;
|
4253 | if (hasCallProperties) {
|
4254 | var _result = compareTypeCallProperties(this, input);
|
4255 | if (_result === -1) {
|
4256 | return -1;
|
4257 | } else if (_result === 1) {
|
4258 | isGreater = true;
|
4259 | }
|
4260 | }
|
4261 |
|
4262 | var result = void 0;
|
4263 | if (this.indexers.length > 0) {
|
4264 | result = compareTypeWithIndexers(this, input);
|
4265 | } else {
|
4266 | result = compareTypeWithoutIndexers(this, input);
|
4267 | }
|
4268 |
|
4269 | if (result === -1) {
|
4270 | return -1;
|
4271 | } else if (isGreater) {
|
4272 | return 1;
|
4273 | } else {
|
4274 | return result;
|
4275 | }
|
4276 | }
|
4277 | }, {
|
4278 | key: 'toString',
|
4279 | value: function toString() {
|
4280 | var callProperties = this.callProperties,
|
4281 | properties = this.properties,
|
4282 | indexers = this.indexers;
|
4283 |
|
4284 | if (inToStringCycle(this)) {
|
4285 | return '$Cycle<Object>';
|
4286 | }
|
4287 | startToStringCycle(this);
|
4288 | var body = [];
|
4289 | for (var i = 0; i < callProperties.length; i++) {
|
4290 | body.push(callProperties[i].toString());
|
4291 | }
|
4292 | for (var _i = 0; _i < properties.length; _i++) {
|
4293 | body.push(properties[_i].toString());
|
4294 | }
|
4295 | for (var _i2 = 0; _i2 < indexers.length; _i2++) {
|
4296 | body.push(indexers[_i2].toString());
|
4297 | }
|
4298 | endToStringCycle(this);
|
4299 | if (this.exact) {
|
4300 | return `{|\n${ indent(body.join('\n')) }\n|}`;
|
4301 | } else {
|
4302 | return `{\n${ indent(body.join('\n')) }\n}`;
|
4303 | }
|
4304 | }
|
4305 | }, {
|
4306 | key: 'toJSON',
|
4307 | value: function toJSON() {
|
4308 | return {
|
4309 | typeName: this.typeName,
|
4310 | callProperties: this.callProperties,
|
4311 | properties: this.properties,
|
4312 | indexers: this.indexers,
|
4313 | exact: this.exact
|
4314 | };
|
4315 | }
|
4316 | }]);
|
4317 | return ObjectType;
|
4318 | }(Type);
|
4319 |
|
4320 | function acceptsCallProperties(type, input) {
|
4321 | var callProperties = type.callProperties;
|
4322 |
|
4323 | for (var i = 0; i < callProperties.length; i++) {
|
4324 | var callProperty = callProperties[i];
|
4325 | if (callProperty.accepts(input)) {
|
4326 | return true;
|
4327 | }
|
4328 | }
|
4329 | return false;
|
4330 | }
|
4331 |
|
4332 | function compareTypeCallProperties(type, input) {
|
4333 | var callProperties = type.callProperties;
|
4334 |
|
4335 | var inputCallProperties = input.callProperties;
|
4336 | var identicalCount = 0;
|
4337 | loop: for (var i = 0; i < callProperties.length; i++) {
|
4338 | var callProperty = callProperties[i];
|
4339 |
|
4340 | for (var j = 0; j < inputCallProperties.length; j++) {
|
4341 | var inputCallProperty = inputCallProperties[j];
|
4342 | var result = compareTypes(callProperty, inputCallProperty);
|
4343 | if (result === 0) {
|
4344 | identicalCount++;
|
4345 | continue loop;
|
4346 | } else if (result === 1) {
|
4347 | continue loop;
|
4348 | }
|
4349 | }
|
4350 |
|
4351 | return -1;
|
4352 | }
|
4353 | if (identicalCount === callProperties.length) {
|
4354 | return 0;
|
4355 | } else {
|
4356 | return 1;
|
4357 | }
|
4358 | }
|
4359 |
|
4360 | function acceptsWithIndexers(type, input) {
|
4361 | var properties = type.properties,
|
4362 | indexers = type.indexers;
|
4363 |
|
4364 | var seen = [];
|
4365 | for (var i = 0; i < properties.length; i++) {
|
4366 | var property = properties[i];
|
4367 | if (!property.accepts(input)) {
|
4368 | return false;
|
4369 | }
|
4370 | seen.push(property.key);
|
4371 | }
|
4372 | loop: for (var key in input) {
|
4373 | if (seen.indexOf(key) !== -1) {
|
4374 | continue;
|
4375 | }
|
4376 | var value = input[key];
|
4377 | for (var _i3 = 0; _i3 < indexers.length; _i3++) {
|
4378 | var indexer = indexers[_i3];
|
4379 | if (indexer.acceptsKey(key) && indexer.acceptsValue(value)) {
|
4380 | continue loop;
|
4381 | }
|
4382 | }
|
4383 |
|
4384 |
|
4385 | return false;
|
4386 | }
|
4387 | return true;
|
4388 | }
|
4389 |
|
4390 | function compareTypeWithIndexers(type, input) {
|
4391 | var indexers = type.indexers,
|
4392 | properties = type.properties;
|
4393 |
|
4394 | var inputIndexers = input.indexers;
|
4395 | var inputProperties = input.properties;
|
4396 | var isGreater = false;
|
4397 | loop: for (var i = 0; i < properties.length; i++) {
|
4398 | var property = properties[i];
|
4399 | for (var j = 0; j < inputProperties.length; j++) {
|
4400 | var inputProperty = inputProperties[j];
|
4401 | if (inputProperty.key === property.key) {
|
4402 | var result = compareTypes(property, inputProperty);
|
4403 | if (result === -1) {
|
4404 | return -1;
|
4405 | } else if (result === 1) {
|
4406 | isGreater = true;
|
4407 | }
|
4408 | continue loop;
|
4409 | }
|
4410 | }
|
4411 | }
|
4412 | loop: for (var _i4 = 0; _i4 < indexers.length; _i4++) {
|
4413 | var indexer = indexers[_i4];
|
4414 | for (var _j = 0; _j < inputIndexers.length; _j++) {
|
4415 | var inputIndexer = inputIndexers[_j];
|
4416 | var _result2 = compareTypes(indexer, inputIndexer);
|
4417 | if (_result2 === 1) {
|
4418 | isGreater = true;
|
4419 | continue loop;
|
4420 | } else if (_result2 === 0) {
|
4421 | continue loop;
|
4422 | }
|
4423 | }
|
4424 |
|
4425 | return -1;
|
4426 | }
|
4427 | return isGreater ? 1 : 0;
|
4428 | }
|
4429 |
|
4430 | function acceptsWithoutIndexers(type, input) {
|
4431 | var properties = type.properties;
|
4432 |
|
4433 | for (var i = 0; i < properties.length; i++) {
|
4434 | var property = properties[i];
|
4435 | if (!property.accepts(input)) {
|
4436 | return false;
|
4437 | }
|
4438 | }
|
4439 | return true;
|
4440 | }
|
4441 |
|
4442 | function acceptsExact(type, input) {
|
4443 | var properties = type.properties;
|
4444 | var length = properties.length;
|
4445 |
|
4446 | loop: for (var key in input) {
|
4447 |
|
4448 | for (var i = 0; i < length; i++) {
|
4449 | var property = properties[i];
|
4450 | if (property.key === key) {
|
4451 | if (!property.accepts(input)) {
|
4452 | return false;
|
4453 | }
|
4454 | continue loop;
|
4455 | }
|
4456 | }
|
4457 |
|
4458 | return false;
|
4459 | }
|
4460 | return true;
|
4461 | }
|
4462 |
|
4463 | function compareTypeWithoutIndexers(type, input) {
|
4464 | var properties = type.properties;
|
4465 |
|
4466 | var inputProperties = input.properties;
|
4467 | var isGreater = false;
|
4468 | loop: for (var i = 0; i < properties.length; i++) {
|
4469 | var property = properties[i];
|
4470 | for (var j = 0; j < inputProperties.length; j++) {
|
4471 | var inputProperty = inputProperties[j];
|
4472 | if (inputProperty.key === property.key) {
|
4473 | var result = compareTypes(property.value, inputProperty.value);
|
4474 | if (result === -1) {
|
4475 | return -1;
|
4476 | } else if (result === 1) {
|
4477 | isGreater = true;
|
4478 | }
|
4479 | continue loop;
|
4480 | }
|
4481 | }
|
4482 | return -1;
|
4483 | }
|
4484 | return isGreater ? 1 : 0;
|
4485 | }
|
4486 |
|
4487 | function* collectErrorsWithIndexers(type, validation, path, input) {
|
4488 | var properties = type.properties,
|
4489 | indexers = type.indexers;
|
4490 |
|
4491 | var seen = [];
|
4492 | for (var i = 0; i < properties.length; i++) {
|
4493 | var property = properties[i];
|
4494 | yield* property.errors(validation, path, input);
|
4495 | seen.push(property.key);
|
4496 | }
|
4497 | loop: for (var key in input) {
|
4498 | if (seen.indexOf(key) !== -1) {
|
4499 | continue;
|
4500 | }
|
4501 | var value = input[key];
|
4502 | for (var _i5 = 0; _i5 < indexers.length; _i5++) {
|
4503 | var indexer = indexers[_i5];
|
4504 | if (indexer.acceptsKey(key) && indexer.acceptsValue(value)) {
|
4505 | continue loop;
|
4506 | }
|
4507 | }
|
4508 |
|
4509 |
|
4510 | yield [path.concat(key), getErrorMessage('ERR_NO_INDEXER'), type];
|
4511 | }
|
4512 | }
|
4513 |
|
4514 | function* collectErrorsWithoutIndexers(type, validation, path, input) {
|
4515 | var properties = type.properties;
|
4516 |
|
4517 | for (var i = 0; i < properties.length; i++) {
|
4518 | var property = properties[i];
|
4519 | yield* property.errors(validation, path, input);
|
4520 | }
|
4521 | }
|
4522 |
|
4523 | function* collectErrorsExact(type, validation, path, input) {
|
4524 | var properties = type.properties;
|
4525 | var length = properties.length;
|
4526 |
|
4527 | loop: for (var key in input) {
|
4528 |
|
4529 | for (var i = 0; i < length; i++) {
|
4530 | var property = properties[i];
|
4531 | if (property.key === key) {
|
4532 | yield* property.errors(validation, path, input);
|
4533 | continue loop;
|
4534 | }
|
4535 | }
|
4536 |
|
4537 | yield [path, getErrorMessage('ERR_UNKNOWN_KEY', key), type];
|
4538 | }
|
4539 | }
|
4540 |
|
4541 | function indent(input) {
|
4542 | var lines = input.split('\n');
|
4543 | var length = lines.length;
|
4544 |
|
4545 | for (var i = 0; i < length; i++) {
|
4546 | lines[i] = ` ${ lines[i] }`;
|
4547 | }
|
4548 | return lines.join('\n');
|
4549 | }
|
4550 |
|
4551 | var IntersectionType = function (_Type) {
|
4552 | inherits(IntersectionType, _Type);
|
4553 |
|
4554 | function IntersectionType() {
|
4555 | var _ref;
|
4556 |
|
4557 | var _temp, _this, _ret;
|
4558 |
|
4559 | classCallCheck(this, IntersectionType);
|
4560 |
|
4561 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4562 | args[_key] = arguments[_key];
|
4563 | }
|
4564 |
|
4565 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = IntersectionType.__proto__ || Object.getPrototypeOf(IntersectionType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'IntersectionType', _this.types = [], _temp), possibleConstructorReturn(_this, _ret);
|
4566 | }
|
4567 |
|
4568 | createClass(IntersectionType, [{
|
4569 | key: 'errors',
|
4570 | value: function* errors(validation, path, input) {
|
4571 | var types = this.types;
|
4572 | var length = types.length;
|
4573 |
|
4574 | for (var i = 0; i < length; i++) {
|
4575 | yield* types[i].errors(validation, path, input);
|
4576 | }
|
4577 | }
|
4578 |
|
4579 | |
4580 |
|
4581 |
|
4582 |
|
4583 | }, {
|
4584 | key: 'getProperty',
|
4585 | value: function getProperty(key) {
|
4586 | var types = this.types;
|
4587 | var length = types.length;
|
4588 |
|
4589 | for (var i = length - 1; i >= 0; i--) {
|
4590 | var type = types[i];
|
4591 | if (typeof type.getProperty === 'function') {
|
4592 | var prop = type.getProperty(key);
|
4593 | if (prop) {
|
4594 | return prop;
|
4595 | }
|
4596 | }
|
4597 | }
|
4598 | }
|
4599 |
|
4600 | |
4601 |
|
4602 |
|
4603 |
|
4604 | }, {
|
4605 | key: 'hasProperty',
|
4606 | value: function hasProperty(key) {
|
4607 | var types = this.types;
|
4608 | var length = types.length;
|
4609 |
|
4610 | for (var i = 0; i < length; i++) {
|
4611 | var type = types[i];
|
4612 | if (typeof type.hasProperty === 'function' && type.hasProperty(key)) {
|
4613 | return true;
|
4614 | }
|
4615 | }
|
4616 | return false;
|
4617 | }
|
4618 | }, {
|
4619 | key: 'accepts',
|
4620 | value: function accepts(input) {
|
4621 | var types = this.types;
|
4622 | var length = types.length;
|
4623 |
|
4624 | for (var i = 0; i < length; i++) {
|
4625 | var type = types[i];
|
4626 | if (!type.accepts(input)) {
|
4627 | return false;
|
4628 | }
|
4629 | }
|
4630 | return true;
|
4631 | }
|
4632 | }, {
|
4633 | key: 'compareWith',
|
4634 | value: function compareWith(input) {
|
4635 | var types = this.types;
|
4636 | var identicalCount = 0;
|
4637 | if (input instanceof IntersectionType) {
|
4638 | var inputTypes = input.types;
|
4639 | loop: for (var i = 0; i < types.length; i++) {
|
4640 | var type = types[i];
|
4641 | for (var j = 0; j < inputTypes.length; j++) {
|
4642 | var result = compareTypes(type, inputTypes[i]);
|
4643 | if (result === 0) {
|
4644 | identicalCount++;
|
4645 | continue loop;
|
4646 | } else if (result === 1) {
|
4647 | continue loop;
|
4648 | }
|
4649 | }
|
4650 |
|
4651 | return -1;
|
4652 | }
|
4653 | return identicalCount === types.length ? 0 : 1;
|
4654 | } else {
|
4655 | for (var _i = 0; _i < types.length; _i++) {
|
4656 | var _type = types[_i];
|
4657 | var _result = compareTypes(_type, input);
|
4658 | if (_result === -1) {
|
4659 | return -1;
|
4660 | } else if (_result === 0) {
|
4661 | identicalCount++;
|
4662 | }
|
4663 | }
|
4664 | return identicalCount === types.length ? 0 : 1;
|
4665 | }
|
4666 | }
|
4667 | }, {
|
4668 | key: 'unwrap',
|
4669 | value: function unwrap() {
|
4670 | var _ref2;
|
4671 |
|
4672 | var callProperties = [];
|
4673 | var properties = [];
|
4674 | var indexers = [];
|
4675 | var types = this.types,
|
4676 | context = this.context;
|
4677 |
|
4678 | for (var i = 0; i < types.length; i++) {
|
4679 | var type = types[i].unwrap();
|
4680 | invariant(type instanceof ObjectType, 'Can only intersect object types');
|
4681 | callProperties.push.apply(callProperties, toConsumableArray(type.callProperties));
|
4682 | indexers.push.apply(indexers, toConsumableArray(type.indexers));
|
4683 | mergeProperties(properties, type.properties);
|
4684 | }
|
4685 | return (_ref2 = context).object.apply(_ref2, callProperties.concat(properties, indexers));
|
4686 | }
|
4687 | }, {
|
4688 | key: 'toString',
|
4689 | value: function toString() {
|
4690 | return this.types.join(' & ');
|
4691 | }
|
4692 | }, {
|
4693 | key: 'toJSON',
|
4694 | value: function toJSON() {
|
4695 | return {
|
4696 | typeName: this.typeName,
|
4697 | types: this.types
|
4698 | };
|
4699 | }
|
4700 | }]);
|
4701 | return IntersectionType;
|
4702 | }(Type);
|
4703 |
|
4704 | function getPropertyIndex(name, properties) {
|
4705 | for (var i = 0; i < properties.length; i++) {
|
4706 | if (properties[i].name === name) {
|
4707 | return i;
|
4708 | }
|
4709 | }
|
4710 | return -1;
|
4711 | }
|
4712 |
|
4713 | function mergeProperties(target, source) {
|
4714 | for (var i = 0; i < source.length; i++) {
|
4715 | var typeProp = source[i];
|
4716 | var index = getPropertyIndex(typeProp.key, target);
|
4717 | if (index === -1) {
|
4718 | target.push(typeProp);
|
4719 | } else {
|
4720 | target[index] = typeProp;
|
4721 | }
|
4722 | }
|
4723 | return target;
|
4724 | }
|
4725 |
|
4726 | var MixedType = function (_Type) {
|
4727 | inherits(MixedType, _Type);
|
4728 |
|
4729 | function MixedType() {
|
4730 | var _ref;
|
4731 |
|
4732 | var _temp, _this, _ret;
|
4733 |
|
4734 | classCallCheck(this, MixedType);
|
4735 |
|
4736 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4737 | args[_key] = arguments[_key];
|
4738 | }
|
4739 |
|
4740 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = MixedType.__proto__ || Object.getPrototypeOf(MixedType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'MixedType', _temp), possibleConstructorReturn(_this, _ret);
|
4741 | }
|
4742 |
|
4743 | createClass(MixedType, [{
|
4744 | key: 'errors',
|
4745 | value: function* errors(validation, path, input) {}
|
4746 | }, {
|
4747 | key: 'accepts',
|
4748 | value: function accepts(input) {
|
4749 | return true;
|
4750 | }
|
4751 | }, {
|
4752 | key: 'toString',
|
4753 | value: function toString() {
|
4754 | return 'mixed';
|
4755 | }
|
4756 | }, {
|
4757 | key: 'toJSON',
|
4758 | value: function toJSON() {
|
4759 | return {
|
4760 | typeName: this.typeName
|
4761 | };
|
4762 | }
|
4763 | }]);
|
4764 | return MixedType;
|
4765 | }(Type);
|
4766 |
|
4767 | var TypeAlias = function (_Type) {
|
4768 | inherits(TypeAlias, _Type);
|
4769 |
|
4770 | function TypeAlias() {
|
4771 | var _ref;
|
4772 |
|
4773 | var _temp, _this, _ret;
|
4774 |
|
4775 | classCallCheck(this, TypeAlias);
|
4776 |
|
4777 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4778 | args[_key] = arguments[_key];
|
4779 | }
|
4780 |
|
4781 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeAlias.__proto__ || Object.getPrototypeOf(TypeAlias)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeAlias', _this.constraints = [], _temp), possibleConstructorReturn(_this, _ret);
|
4782 | }
|
4783 |
|
4784 | createClass(TypeAlias, [{
|
4785 | key: 'addConstraint',
|
4786 | value: function addConstraint() {
|
4787 | for (var _len2 = arguments.length, constraints = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
4788 | constraints[_key2] = arguments[_key2];
|
4789 | }
|
4790 |
|
4791 | addConstraints.apply(undefined, [this].concat(toConsumableArray(constraints)));
|
4792 | return this;
|
4793 | }
|
4794 | }, {
|
4795 | key: 'errors',
|
4796 | value: function* errors(validation, path, input) {
|
4797 | var type = this.type;
|
4798 |
|
4799 | var hasErrors = false;
|
4800 | var _iteratorNormalCompletion = true;
|
4801 | var _didIteratorError = false;
|
4802 | var _iteratorError = undefined;
|
4803 |
|
4804 | try {
|
4805 | for (var _iterator = type.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
4806 | var error = _step.value;
|
4807 |
|
4808 | hasErrors = true;
|
4809 | yield error;
|
4810 | }
|
4811 | } catch (err) {
|
4812 | _didIteratorError = true;
|
4813 | _iteratorError = err;
|
4814 | } finally {
|
4815 | try {
|
4816 | if (!_iteratorNormalCompletion && _iterator.return) {
|
4817 | _iterator.return();
|
4818 | }
|
4819 | } finally {
|
4820 | if (_didIteratorError) {
|
4821 | throw _iteratorError;
|
4822 | }
|
4823 | }
|
4824 | }
|
4825 |
|
4826 | if (!hasErrors) {
|
4827 | yield* collectConstraintErrors(this, validation, path, input);
|
4828 | }
|
4829 | }
|
4830 | }, {
|
4831 | key: 'accepts',
|
4832 | value: function accepts(input) {
|
4833 | var type = this.type;
|
4834 |
|
4835 | if (!type.accepts(input)) {
|
4836 | return false;
|
4837 | } else if (!constraintsAccept(this, input)) {
|
4838 | return false;
|
4839 | } else {
|
4840 | return true;
|
4841 | }
|
4842 | }
|
4843 | }, {
|
4844 | key: 'compareWith',
|
4845 | value: function compareWith(input) {
|
4846 | if (input === this) {
|
4847 | return 0;
|
4848 | } else if (this.hasConstraints) {
|
4849 |
|
4850 | return -1;
|
4851 | } else {
|
4852 | return compareTypes(this.type, input);
|
4853 | }
|
4854 | }
|
4855 | }, {
|
4856 | key: 'apply',
|
4857 | value: function apply() {
|
4858 | var target = new TypeParameterApplication(this.context);
|
4859 | target.parent = this;
|
4860 |
|
4861 | for (var _len3 = arguments.length, typeInstances = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
4862 | typeInstances[_key3] = arguments[_key3];
|
4863 | }
|
4864 |
|
4865 | target.typeInstances = typeInstances;
|
4866 | return target;
|
4867 | }
|
4868 |
|
4869 | |
4870 |
|
4871 |
|
4872 |
|
4873 | }, {
|
4874 | key: 'unwrap',
|
4875 | value: function unwrap() {
|
4876 | return this.type.unwrap();
|
4877 | }
|
4878 | }, {
|
4879 | key: 'hasProperty',
|
4880 | value: function hasProperty(name) {
|
4881 | var inner = this.unwrap();
|
4882 | if (inner && typeof inner.hasProperty === 'function') {
|
4883 | return inner.hasProperty(name);
|
4884 | } else {
|
4885 | return false;
|
4886 | }
|
4887 | }
|
4888 | }, {
|
4889 | key: 'getProperty',
|
4890 | value: function getProperty(name) {
|
4891 | var inner = this.unwrap();
|
4892 | if (inner && typeof inner.getProperty === 'function') {
|
4893 | return inner.getProperty(name);
|
4894 | }
|
4895 | }
|
4896 | }, {
|
4897 | key: 'toString',
|
4898 | value: function toString(withDeclaration) {
|
4899 | var name = this.name,
|
4900 | type = this.type;
|
4901 |
|
4902 | if (withDeclaration) {
|
4903 | return `type ${ name } = ${ type.toString() };`;
|
4904 | } else {
|
4905 | return name;
|
4906 | }
|
4907 | }
|
4908 | }, {
|
4909 | key: 'toJSON',
|
4910 | value: function toJSON() {
|
4911 | return {
|
4912 | typeName: this.typeName,
|
4913 | name: this.name,
|
4914 | type: this.type
|
4915 | };
|
4916 | }
|
4917 | }, {
|
4918 | key: 'properties',
|
4919 | get: function get$$1() {
|
4920 | return this.type.properties;
|
4921 | }
|
4922 | }, {
|
4923 | key: 'hasConstraints',
|
4924 | get: function get$$1() {
|
4925 | return this.constraints.length > 0;
|
4926 | }
|
4927 | }]);
|
4928 | return TypeAlias;
|
4929 | }(Type);
|
4930 |
|
4931 | var NumericLiteralType = function (_Type) {
|
4932 | inherits(NumericLiteralType, _Type);
|
4933 |
|
4934 | function NumericLiteralType() {
|
4935 | var _ref;
|
4936 |
|
4937 | var _temp, _this, _ret;
|
4938 |
|
4939 | classCallCheck(this, NumericLiteralType);
|
4940 |
|
4941 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4942 | args[_key] = arguments[_key];
|
4943 | }
|
4944 |
|
4945 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = NumericLiteralType.__proto__ || Object.getPrototypeOf(NumericLiteralType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'NumericLiteralType', _temp), possibleConstructorReturn(_this, _ret);
|
4946 | }
|
4947 |
|
4948 | createClass(NumericLiteralType, [{
|
4949 | key: 'errors',
|
4950 | value: function* errors(validation, path, input) {
|
4951 | var value = this.value;
|
4952 |
|
4953 | if (input !== value) {
|
4954 | yield [path, getErrorMessage('ERR_EXPECT_EXACT_VALUE', value), this];
|
4955 | }
|
4956 | }
|
4957 | }, {
|
4958 | key: 'accepts',
|
4959 | value: function accepts(input) {
|
4960 | return input === this.value;
|
4961 | }
|
4962 | }, {
|
4963 | key: 'compareWith',
|
4964 | value: function compareWith(input) {
|
4965 | if (input instanceof NumericLiteralType && input.value === this.value) {
|
4966 | return 0;
|
4967 | } else {
|
4968 | return -1;
|
4969 | }
|
4970 | }
|
4971 | }, {
|
4972 | key: 'toString',
|
4973 | value: function toString() {
|
4974 | return `${ this.value }`;
|
4975 | }
|
4976 | }, {
|
4977 | key: 'toJSON',
|
4978 | value: function toJSON() {
|
4979 | return {
|
4980 | typeName: this.typeName,
|
4981 | value: this.value
|
4982 | };
|
4983 | }
|
4984 | }]);
|
4985 | return NumericLiteralType;
|
4986 | }(Type);
|
4987 |
|
4988 | var NumberType = function (_Type) {
|
4989 | inherits(NumberType, _Type);
|
4990 |
|
4991 | function NumberType() {
|
4992 | var _ref;
|
4993 |
|
4994 | var _temp, _this, _ret;
|
4995 |
|
4996 | classCallCheck(this, NumberType);
|
4997 |
|
4998 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
4999 | args[_key] = arguments[_key];
|
5000 | }
|
5001 |
|
5002 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = NumberType.__proto__ || Object.getPrototypeOf(NumberType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'NumberType', _temp), possibleConstructorReturn(_this, _ret);
|
5003 | }
|
5004 |
|
5005 | createClass(NumberType, [{
|
5006 | key: 'errors',
|
5007 | value: function* errors(validation, path, input) {
|
5008 | if (typeof input !== 'number') {
|
5009 | yield [path, getErrorMessage('ERR_EXPECT_NUMBER'), this];
|
5010 | }
|
5011 | }
|
5012 | }, {
|
5013 | key: 'accepts',
|
5014 | value: function accepts(input) {
|
5015 | return typeof input === 'number';
|
5016 | }
|
5017 | }, {
|
5018 | key: 'compareWith',
|
5019 | value: function compareWith(input) {
|
5020 | if (input instanceof NumberType) {
|
5021 | return 0;
|
5022 | } else if (input instanceof NumericLiteralType) {
|
5023 | return 1;
|
5024 | } else {
|
5025 | return -1;
|
5026 | }
|
5027 | }
|
5028 | }, {
|
5029 | key: 'toString',
|
5030 | value: function toString() {
|
5031 | return 'number';
|
5032 | }
|
5033 | }, {
|
5034 | key: 'toJSON',
|
5035 | value: function toJSON() {
|
5036 | return {
|
5037 | typeName: this.typeName
|
5038 | };
|
5039 | }
|
5040 | }]);
|
5041 | return NumberType;
|
5042 | }(Type);
|
5043 |
|
5044 | var ParameterizedTypeAlias = function (_TypeAlias) {
|
5045 | inherits(ParameterizedTypeAlias, _TypeAlias);
|
5046 |
|
5047 | function ParameterizedTypeAlias() {
|
5048 | var _ref;
|
5049 |
|
5050 | var _temp, _this, _ret;
|
5051 |
|
5052 | classCallCheck(this, ParameterizedTypeAlias);
|
5053 |
|
5054 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5055 | args[_key] = arguments[_key];
|
5056 | }
|
5057 |
|
5058 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ParameterizedTypeAlias.__proto__ || Object.getPrototypeOf(ParameterizedTypeAlias)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ParameterizedTypeAlias', _temp), possibleConstructorReturn(_this, _ret);
|
5059 | }
|
5060 |
|
5061 | createClass(ParameterizedTypeAlias, [{
|
5062 | key: 'errors',
|
5063 | value: function* errors(validation, path, input) {
|
5064 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
5065 | typeInstances[_key2 - 3] = arguments[_key2];
|
5066 | }
|
5067 |
|
5068 | yield* getPartial$1.apply(undefined, [this].concat(toConsumableArray(typeInstances))).errors(validation, path, input);
|
5069 | }
|
5070 | }, {
|
5071 | key: 'accepts',
|
5072 | value: function accepts(input) {
|
5073 | for (var _len3 = arguments.length, typeInstances = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
5074 | typeInstances[_key3 - 1] = arguments[_key3];
|
5075 | }
|
5076 |
|
5077 | var partial = getPartial$1.apply(undefined, [this].concat(toConsumableArray(typeInstances)));
|
5078 | if (!partial.accepts(input)) {
|
5079 | return false;
|
5080 | } else if (!constraintsAccept(this, input)) {
|
5081 | return false;
|
5082 | } else {
|
5083 | return true;
|
5084 | }
|
5085 | }
|
5086 | }, {
|
5087 | key: 'compareWith',
|
5088 | value: function compareWith(input) {
|
5089 | if (input === this) {
|
5090 | return 0;
|
5091 | } else if (this.hasConstraints) {
|
5092 |
|
5093 | return -1;
|
5094 | } else {
|
5095 | return compareTypes(getPartial$1(this), input);
|
5096 | }
|
5097 | }
|
5098 | }, {
|
5099 | key: 'hasProperty',
|
5100 | value: function hasProperty(name) {
|
5101 | for (var _len4 = arguments.length, typeInstances = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
5102 | typeInstances[_key4 - 1] = arguments[_key4];
|
5103 | }
|
5104 |
|
5105 | var inner = this.unwrap.apply(this, toConsumableArray(typeInstances));
|
5106 | if (inner && typeof inner.hasProperty === 'function') {
|
5107 | return inner.hasProperty.apply(inner, [name].concat(toConsumableArray(typeInstances)));
|
5108 | } else {
|
5109 | return false;
|
5110 | }
|
5111 | }
|
5112 | }, {
|
5113 | key: 'getProperty',
|
5114 | value: function getProperty(name) {
|
5115 | for (var _len5 = arguments.length, typeInstances = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
5116 | typeInstances[_key5 - 1] = arguments[_key5];
|
5117 | }
|
5118 |
|
5119 | var inner = this.unwrap.apply(this, toConsumableArray(typeInstances));
|
5120 | if (inner && typeof inner.getProperty === 'function') {
|
5121 | return inner.getProperty.apply(inner, [name].concat(toConsumableArray(typeInstances)));
|
5122 | }
|
5123 | }
|
5124 |
|
5125 | |
5126 |
|
5127 |
|
5128 |
|
5129 | }, {
|
5130 | key: 'unwrap',
|
5131 | value: function unwrap() {
|
5132 | for (var _len6 = arguments.length, typeInstances = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
5133 | typeInstances[_key6] = arguments[_key6];
|
5134 | }
|
5135 |
|
5136 | return getPartial$1.apply(undefined, [this].concat(toConsumableArray(typeInstances))).unwrap();
|
5137 | }
|
5138 | }, {
|
5139 | key: 'toString',
|
5140 | value: function toString(withDeclaration) {
|
5141 | var partial = getPartial$1(this);
|
5142 | var typeParameters = partial.typeParameters;
|
5143 |
|
5144 | var items = [];
|
5145 | for (var i = 0; i < typeParameters.length; i++) {
|
5146 | var typeParameter = typeParameters[i];
|
5147 | items.push(typeParameter.toString(true));
|
5148 | }
|
5149 |
|
5150 | var name = this.name;
|
5151 |
|
5152 | var identifier = typeParameters.length > 0 ? `${ name }<${ items.join(', ') }>` : name;
|
5153 |
|
5154 | if (withDeclaration) {
|
5155 | return `type ${ identifier } = ${ partial.toString() };`;
|
5156 | } else {
|
5157 | return identifier;
|
5158 | }
|
5159 | }
|
5160 | }, {
|
5161 | key: 'toJSON',
|
5162 | value: function toJSON() {
|
5163 | var partial = getPartial$1(this);
|
5164 | return partial.toJSON();
|
5165 | }
|
5166 | }, {
|
5167 | key: 'properties',
|
5168 | get: function get$$1() {
|
5169 | return getPartial$1(this).type.properties;
|
5170 | }
|
5171 | }]);
|
5172 | return ParameterizedTypeAlias;
|
5173 | }(TypeAlias);
|
5174 |
|
5175 | function getPartial$1(parent) {
|
5176 | var typeCreator = parent.typeCreator,
|
5177 | context = parent.context,
|
5178 | name = parent.name;
|
5179 |
|
5180 | var partial = new PartialType(context);
|
5181 | partial.name = name;
|
5182 | partial.type = typeCreator(partial);
|
5183 | partial.constraints = parent.constraints;
|
5184 |
|
5185 | var typeParameters = partial.typeParameters;
|
5186 |
|
5187 | for (var _len7 = arguments.length, typeInstances = Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
|
5188 | typeInstances[_key7 - 1] = arguments[_key7];
|
5189 | }
|
5190 |
|
5191 | var limit = Math.min(typeInstances.length, typeParameters.length);
|
5192 | for (var i = 0; i < limit; i++) {
|
5193 | var typeParameter = typeParameters[i];
|
5194 | var typeInstance = typeInstances[i];
|
5195 | if (typeParameter.bound && typeParameter.bound !== typeInstance) {
|
5196 |
|
5197 |
|
5198 | typeParameter.bound = context.intersect(typeParameter.bound, typeInstance);
|
5199 | } else {
|
5200 | typeParameter.bound = typeInstance;
|
5201 | }
|
5202 | }
|
5203 |
|
5204 | return partial;
|
5205 | }
|
5206 |
|
5207 | var ParameterizedFunctionType = function (_Type) {
|
5208 | inherits(ParameterizedFunctionType, _Type);
|
5209 |
|
5210 | function ParameterizedFunctionType() {
|
5211 | var _ref;
|
5212 |
|
5213 | var _temp, _this, _ret;
|
5214 |
|
5215 | classCallCheck(this, ParameterizedFunctionType);
|
5216 |
|
5217 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5218 | args[_key] = arguments[_key];
|
5219 | }
|
5220 |
|
5221 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ParameterizedFunctionType.__proto__ || Object.getPrototypeOf(ParameterizedFunctionType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ParameterizedFunctionType', _temp), possibleConstructorReturn(_this, _ret);
|
5222 | }
|
5223 |
|
5224 | createClass(ParameterizedFunctionType, [{
|
5225 | key: 'errors',
|
5226 | value: function* errors(validation, path, input) {
|
5227 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
5228 | typeInstances[_key2 - 3] = arguments[_key2];
|
5229 | }
|
5230 |
|
5231 | yield* getPartial$2.apply(undefined, [this].concat(toConsumableArray(typeInstances))).errors(validation, path, input);
|
5232 | }
|
5233 | }, {
|
5234 | key: 'accepts',
|
5235 | value: function accepts(input) {
|
5236 | for (var _len3 = arguments.length, typeInstances = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
5237 | typeInstances[_key3 - 1] = arguments[_key3];
|
5238 | }
|
5239 |
|
5240 | return getPartial$2.apply(undefined, [this].concat(toConsumableArray(typeInstances))).accepts(input);
|
5241 | }
|
5242 | }, {
|
5243 | key: 'compareWith',
|
5244 | value: function compareWith(input) {
|
5245 | return compareTypes(getPartial$2(this), input);
|
5246 | }
|
5247 | }, {
|
5248 | key: 'acceptsParams',
|
5249 | value: function acceptsParams() {
|
5250 | var _getPartial$type;
|
5251 |
|
5252 | return (_getPartial$type = getPartial$2(this).type).acceptsParams.apply(_getPartial$type, arguments);
|
5253 | }
|
5254 | }, {
|
5255 | key: 'acceptsReturn',
|
5256 | value: function acceptsReturn(input) {
|
5257 | return getPartial$2(this).type.acceptsReturn(input);
|
5258 | }
|
5259 | }, {
|
5260 | key: 'assertParams',
|
5261 | value: function assertParams() {
|
5262 | var _getPartial$type2;
|
5263 |
|
5264 | return (_getPartial$type2 = getPartial$2(this).type).assertParams.apply(_getPartial$type2, arguments);
|
5265 | }
|
5266 | }, {
|
5267 | key: 'assertReturn',
|
5268 | value: function assertReturn(input) {
|
5269 | return getPartial$2(this).type.assertReturn(input);
|
5270 | }
|
5271 |
|
5272 | |
5273 |
|
5274 |
|
5275 |
|
5276 | }, {
|
5277 | key: 'unwrap',
|
5278 | value: function unwrap() {
|
5279 | for (var _len4 = arguments.length, typeInstances = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
5280 | typeInstances[_key4] = arguments[_key4];
|
5281 | }
|
5282 |
|
5283 | return getPartial$2.apply(undefined, [this].concat(toConsumableArray(typeInstances))).unwrap();
|
5284 | }
|
5285 | }, {
|
5286 | key: 'toString',
|
5287 | value: function toString() {
|
5288 | var partial = getPartial$2(this);
|
5289 | var type = partial.type,
|
5290 | typeParameters = partial.typeParameters;
|
5291 |
|
5292 | if (typeParameters.length === 0) {
|
5293 | return type.toString();
|
5294 | }
|
5295 | var items = [];
|
5296 | for (var i = 0; i < typeParameters.length; i++) {
|
5297 | var typeParameter = typeParameters[i];
|
5298 | items.push(typeParameter.toString(true));
|
5299 | }
|
5300 | return `<${ items.join(', ') }> ${ type.toString() }`;
|
5301 | }
|
5302 | }, {
|
5303 | key: 'toJSON',
|
5304 | value: function toJSON() {
|
5305 | var partial = getPartial$2(this);
|
5306 | return partial.toJSON();
|
5307 | }
|
5308 | }, {
|
5309 | key: 'typeParameters',
|
5310 | get: function get$$1() {
|
5311 | return getPartial$2(this).typeParameters;
|
5312 | }
|
5313 | }, {
|
5314 | key: 'params',
|
5315 | get: function get$$1() {
|
5316 | return getPartial$2(this).type.params;
|
5317 | }
|
5318 | }, {
|
5319 | key: 'rest',
|
5320 | get: function get$$1() {
|
5321 | return getPartial$2(this).type.rest;
|
5322 | }
|
5323 | }, {
|
5324 | key: 'returnType',
|
5325 | get: function get$$1() {
|
5326 | return getPartial$2(this).type.returnType;
|
5327 | }
|
5328 | }]);
|
5329 | return ParameterizedFunctionType;
|
5330 | }(Type);
|
5331 |
|
5332 | function getPartial$2(parent) {
|
5333 | var context = parent.context,
|
5334 | bodyCreator = parent.bodyCreator;
|
5335 |
|
5336 | var partial = new PartialType(context);
|
5337 | var body = bodyCreator(partial);
|
5338 | partial.type = context.function.apply(context, toConsumableArray(body));
|
5339 |
|
5340 | var typeParameters = partial.typeParameters;
|
5341 |
|
5342 | for (var _len5 = arguments.length, typeInstances = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
5343 | typeInstances[_key5 - 1] = arguments[_key5];
|
5344 | }
|
5345 |
|
5346 | var limit = Math.min(typeInstances.length, typeParameters.length);
|
5347 | for (var i = 0; i < limit; i++) {
|
5348 | var typeParameter = typeParameters[i];
|
5349 | var typeInstance = typeInstances[i];
|
5350 | if (typeParameter.bound && typeParameter.bound !== typeInstance) {
|
5351 |
|
5352 |
|
5353 | typeParameter.bound = context.intersect(typeParameter.bound, typeInstance);
|
5354 | } else {
|
5355 | typeParameter.bound = typeInstance;
|
5356 | }
|
5357 | }
|
5358 |
|
5359 | return partial;
|
5360 | }
|
5361 |
|
5362 | var RefinementType = function (_Type) {
|
5363 | inherits(RefinementType, _Type);
|
5364 |
|
5365 | function RefinementType() {
|
5366 | var _ref;
|
5367 |
|
5368 | var _temp, _this, _ret;
|
5369 |
|
5370 | classCallCheck(this, RefinementType);
|
5371 |
|
5372 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5373 | args[_key] = arguments[_key];
|
5374 | }
|
5375 |
|
5376 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = RefinementType.__proto__ || Object.getPrototypeOf(RefinementType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'RefinementType', _this.constraints = [], _temp), possibleConstructorReturn(_this, _ret);
|
5377 | }
|
5378 |
|
5379 | createClass(RefinementType, [{
|
5380 | key: 'addConstraint',
|
5381 | value: function addConstraint() {
|
5382 | for (var _len2 = arguments.length, constraints = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
5383 | constraints[_key2] = arguments[_key2];
|
5384 | }
|
5385 |
|
5386 | addConstraints.apply(undefined, [this].concat(toConsumableArray(constraints)));
|
5387 | return this;
|
5388 | }
|
5389 | }, {
|
5390 | key: 'errors',
|
5391 | value: function* errors(validation, path, input) {
|
5392 | var type = this.type;
|
5393 |
|
5394 | var hasErrors = false;
|
5395 | var _iteratorNormalCompletion = true;
|
5396 | var _didIteratorError = false;
|
5397 | var _iteratorError = undefined;
|
5398 |
|
5399 | try {
|
5400 | for (var _iterator = type.errors(validation, path, input)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
5401 | var error = _step.value;
|
5402 |
|
5403 | hasErrors = true;
|
5404 | yield error;
|
5405 | }
|
5406 | } catch (err) {
|
5407 | _didIteratorError = true;
|
5408 | _iteratorError = err;
|
5409 | } finally {
|
5410 | try {
|
5411 | if (!_iteratorNormalCompletion && _iterator.return) {
|
5412 | _iterator.return();
|
5413 | }
|
5414 | } finally {
|
5415 | if (_didIteratorError) {
|
5416 | throw _iteratorError;
|
5417 | }
|
5418 | }
|
5419 | }
|
5420 |
|
5421 | if (!hasErrors) {
|
5422 | yield* collectConstraintErrors(this, validation, path, input);
|
5423 | }
|
5424 | }
|
5425 | }, {
|
5426 | key: 'accepts',
|
5427 | value: function accepts(input) {
|
5428 | var type = this.type;
|
5429 |
|
5430 | if (!type.accepts(input)) {
|
5431 | return false;
|
5432 | } else if (!constraintsAccept(this, input)) {
|
5433 | return false;
|
5434 | } else {
|
5435 | return true;
|
5436 | }
|
5437 | }
|
5438 | }, {
|
5439 | key: 'compareWith',
|
5440 | value: function compareWith(input) {
|
5441 | if (input === this) {
|
5442 | return 0;
|
5443 | } else {
|
5444 | return -1;
|
5445 | }
|
5446 | }
|
5447 | }, {
|
5448 | key: 'apply',
|
5449 | value: function apply() {
|
5450 | var target = new TypeParameterApplication(this.context);
|
5451 | target.parent = this;
|
5452 |
|
5453 | for (var _len3 = arguments.length, typeInstances = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
5454 | typeInstances[_key3] = arguments[_key3];
|
5455 | }
|
5456 |
|
5457 | target.typeInstances = typeInstances;
|
5458 | return target;
|
5459 | }
|
5460 |
|
5461 | |
5462 |
|
5463 |
|
5464 |
|
5465 | }, {
|
5466 | key: 'unwrap',
|
5467 | value: function unwrap() {
|
5468 | return this.type.unwrap();
|
5469 | }
|
5470 | }, {
|
5471 | key: 'hasProperty',
|
5472 | value: function hasProperty(name) {
|
5473 | var inner = this.unwrap();
|
5474 | if (inner && typeof inner.hasProperty === 'function') {
|
5475 | return inner.hasProperty(name);
|
5476 | } else {
|
5477 | return false;
|
5478 | }
|
5479 | }
|
5480 | }, {
|
5481 | key: 'getProperty',
|
5482 | value: function getProperty(name) {
|
5483 | var inner = this.unwrap();
|
5484 | if (inner && typeof inner.getProperty === 'function') {
|
5485 | return inner.getProperty(name);
|
5486 | }
|
5487 | }
|
5488 | }, {
|
5489 | key: 'toString',
|
5490 | value: function toString() {
|
5491 | var type = this.type;
|
5492 |
|
5493 | return `$Refinment<${ type.toString() }>`;
|
5494 | }
|
5495 | }, {
|
5496 | key: 'toJSON',
|
5497 | value: function toJSON() {
|
5498 | return {
|
5499 | typeName: this.typeName,
|
5500 | type: this.type
|
5501 | };
|
5502 | }
|
5503 | }]);
|
5504 | return RefinementType;
|
5505 | }(Type);
|
5506 |
|
5507 | var StringLiteralType = function (_Type) {
|
5508 | inherits(StringLiteralType, _Type);
|
5509 |
|
5510 | function StringLiteralType() {
|
5511 | var _ref;
|
5512 |
|
5513 | var _temp, _this, _ret;
|
5514 |
|
5515 | classCallCheck(this, StringLiteralType);
|
5516 |
|
5517 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5518 | args[_key] = arguments[_key];
|
5519 | }
|
5520 |
|
5521 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = StringLiteralType.__proto__ || Object.getPrototypeOf(StringLiteralType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'StringLiteralType', _temp), possibleConstructorReturn(_this, _ret);
|
5522 | }
|
5523 |
|
5524 | createClass(StringLiteralType, [{
|
5525 | key: 'errors',
|
5526 | value: function* errors(validation, path, input) {
|
5527 | var value = this.value;
|
5528 |
|
5529 | if (input !== value) {
|
5530 | yield [path, getErrorMessage('ERR_EXPECT_EXACT_VALUE', this.toString()), this];
|
5531 | }
|
5532 | }
|
5533 | }, {
|
5534 | key: 'accepts',
|
5535 | value: function accepts(input) {
|
5536 | return input === this.value;
|
5537 | }
|
5538 | }, {
|
5539 | key: 'compareWith',
|
5540 | value: function compareWith(input) {
|
5541 | if (input instanceof StringLiteralType && input.value === this.value) {
|
5542 | return 0;
|
5543 | } else {
|
5544 | return -1;
|
5545 | }
|
5546 | }
|
5547 | }, {
|
5548 | key: 'toString',
|
5549 | value: function toString() {
|
5550 | return JSON.stringify(this.value);
|
5551 | }
|
5552 | }, {
|
5553 | key: 'toJSON',
|
5554 | value: function toJSON() {
|
5555 | return {
|
5556 | typeName: this.typeName,
|
5557 | value: this.value
|
5558 | };
|
5559 | }
|
5560 | }]);
|
5561 | return StringLiteralType;
|
5562 | }(Type);
|
5563 |
|
5564 | var StringType = function (_Type) {
|
5565 | inherits(StringType, _Type);
|
5566 |
|
5567 | function StringType() {
|
5568 | var _ref;
|
5569 |
|
5570 | var _temp, _this, _ret;
|
5571 |
|
5572 | classCallCheck(this, StringType);
|
5573 |
|
5574 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5575 | args[_key] = arguments[_key];
|
5576 | }
|
5577 |
|
5578 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = StringType.__proto__ || Object.getPrototypeOf(StringType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'StringType', _temp), possibleConstructorReturn(_this, _ret);
|
5579 | }
|
5580 |
|
5581 | createClass(StringType, [{
|
5582 | key: 'errors',
|
5583 | value: function* errors(validation, path, input) {
|
5584 | if (typeof input !== 'string') {
|
5585 | yield [path, getErrorMessage('ERR_EXPECT_STRING'), this];
|
5586 | }
|
5587 | }
|
5588 | }, {
|
5589 | key: 'accepts',
|
5590 | value: function accepts(input) {
|
5591 | return typeof input === 'string';
|
5592 | }
|
5593 | }, {
|
5594 | key: 'compareWith',
|
5595 | value: function compareWith(input) {
|
5596 | if (input instanceof StringLiteralType) {
|
5597 | return 1;
|
5598 | } else if (input instanceof StringType) {
|
5599 | return 0;
|
5600 | } else {
|
5601 | return -1;
|
5602 | }
|
5603 | }
|
5604 | }, {
|
5605 | key: 'toString',
|
5606 | value: function toString() {
|
5607 | return 'string';
|
5608 | }
|
5609 | }, {
|
5610 | key: 'toJSON',
|
5611 | value: function toJSON() {
|
5612 | return {
|
5613 | typeName: this.typeName
|
5614 | };
|
5615 | }
|
5616 | }]);
|
5617 | return StringType;
|
5618 | }(Type);
|
5619 |
|
5620 | var SymbolLiteralType = function (_Type) {
|
5621 | inherits(SymbolLiteralType, _Type);
|
5622 |
|
5623 | function SymbolLiteralType() {
|
5624 | var _ref;
|
5625 |
|
5626 | var _temp, _this, _ret;
|
5627 |
|
5628 | classCallCheck(this, SymbolLiteralType);
|
5629 |
|
5630 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5631 | args[_key] = arguments[_key];
|
5632 | }
|
5633 |
|
5634 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = SymbolLiteralType.__proto__ || Object.getPrototypeOf(SymbolLiteralType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'SymbolLiteralType', _temp), possibleConstructorReturn(_this, _ret);
|
5635 | }
|
5636 |
|
5637 | createClass(SymbolLiteralType, [{
|
5638 | key: 'errors',
|
5639 | value: function* errors(validation, path, input) {
|
5640 | var value = this.value;
|
5641 |
|
5642 | if (input !== value) {
|
5643 | yield [path, getErrorMessage('ERR_EXPECT_EXACT_VALUE', this.toString()), this];
|
5644 | }
|
5645 | }
|
5646 | }, {
|
5647 | key: 'accepts',
|
5648 | value: function accepts(input) {
|
5649 | return input === this.value;
|
5650 | }
|
5651 | }, {
|
5652 | key: 'compareWith',
|
5653 | value: function compareWith(input) {
|
5654 | if (input instanceof SymbolLiteralType && input.value === this.value) {
|
5655 | return 0;
|
5656 | } else {
|
5657 | return -1;
|
5658 | }
|
5659 | }
|
5660 | }, {
|
5661 | key: 'toString',
|
5662 | value: function toString() {
|
5663 | return `typeof ${ String(this.value) }`;
|
5664 | }
|
5665 | }, {
|
5666 | key: 'toJSON',
|
5667 | value: function toJSON() {
|
5668 | return {
|
5669 | typeName: this.typeName,
|
5670 | value: this.value
|
5671 | };
|
5672 | }
|
5673 | }]);
|
5674 | return SymbolLiteralType;
|
5675 | }(Type);
|
5676 |
|
5677 | var SymbolType = function (_Type) {
|
5678 | inherits(SymbolType, _Type);
|
5679 |
|
5680 | function SymbolType() {
|
5681 | var _ref;
|
5682 |
|
5683 | var _temp, _this, _ret;
|
5684 |
|
5685 | classCallCheck(this, SymbolType);
|
5686 |
|
5687 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5688 | args[_key] = arguments[_key];
|
5689 | }
|
5690 |
|
5691 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = SymbolType.__proto__ || Object.getPrototypeOf(SymbolType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'SymbolType', _temp), possibleConstructorReturn(_this, _ret);
|
5692 | }
|
5693 |
|
5694 | createClass(SymbolType, [{
|
5695 | key: 'errors',
|
5696 | value: function* errors(validation, path, input) {
|
5697 |
|
5698 | if (typeof input !== 'symbol') {
|
5699 | yield [path, getErrorMessage('ERR_EXPECT_SYMBOL'), this];
|
5700 | }
|
5701 | }
|
5702 | }, {
|
5703 | key: 'accepts',
|
5704 | value: function accepts(input) {
|
5705 | return typeof input === 'symbol';
|
5706 | }
|
5707 | }, {
|
5708 | key: 'compareWith',
|
5709 | value: function compareWith(input) {
|
5710 | if (input instanceof SymbolLiteralType) {
|
5711 | return 1;
|
5712 | } else if (input instanceof SymbolType) {
|
5713 | return 0;
|
5714 | } else {
|
5715 | return -1;
|
5716 | }
|
5717 | }
|
5718 | }, {
|
5719 | key: 'toString',
|
5720 | value: function toString() {
|
5721 | return 'Symbol';
|
5722 | }
|
5723 | }, {
|
5724 | key: 'toJSON',
|
5725 | value: function toJSON() {
|
5726 | return {
|
5727 | typeName: this.typeName
|
5728 | };
|
5729 | }
|
5730 | }]);
|
5731 | return SymbolType;
|
5732 | }(Type);
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 | var ThisType = function (_Type) {
|
5742 | inherits(ThisType, _Type);
|
5743 |
|
5744 | function ThisType() {
|
5745 | var _ref;
|
5746 |
|
5747 | var _temp, _this, _ret;
|
5748 |
|
5749 | classCallCheck(this, ThisType);
|
5750 |
|
5751 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5752 | args[_key] = arguments[_key];
|
5753 | }
|
5754 |
|
5755 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ThisType.__proto__ || Object.getPrototypeOf(ThisType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ThisType', _temp), possibleConstructorReturn(_this, _ret);
|
5756 | }
|
5757 |
|
5758 | createClass(ThisType, [{
|
5759 | key: 'errors',
|
5760 | value: function* errors(validation, path, input) {
|
5761 | var recorded = this.recorded;
|
5762 |
|
5763 | if (input === recorded) {
|
5764 | return;
|
5765 | } else if (typeof recorded === 'function' && input instanceof recorded) {
|
5766 | return;
|
5767 | } else if (recorded != null) {
|
5768 | yield [path, getErrorMessage('ERR_EXPECT_THIS'), this];
|
5769 | }
|
5770 | }
|
5771 | }, {
|
5772 | key: 'accepts',
|
5773 | value: function accepts(input) {
|
5774 | var recorded = this.recorded;
|
5775 |
|
5776 | if (input === recorded) {
|
5777 | return true;
|
5778 | } else if (typeof recorded === 'function' && input instanceof recorded) {
|
5779 | return true;
|
5780 | } else if (recorded != null) {
|
5781 | return false;
|
5782 | } else {
|
5783 | return true;
|
5784 | }
|
5785 | }
|
5786 | }, {
|
5787 | key: 'compareWith',
|
5788 | value: function compareWith(input) {
|
5789 | if (!(input instanceof ThisType)) {
|
5790 | return -1;
|
5791 | } else if (input.recorded && this.recorded) {
|
5792 | return input.recorded === this.recorded ? 0 : -1;
|
5793 | } else if (this.recorded) {
|
5794 | return 0;
|
5795 | } else {
|
5796 | return 1;
|
5797 | }
|
5798 | }
|
5799 |
|
5800 | |
5801 |
|
5802 |
|
5803 |
|
5804 | }, {
|
5805 | key: 'unwrap',
|
5806 | value: function unwrap() {
|
5807 | return this;
|
5808 | }
|
5809 | }, {
|
5810 | key: 'toString',
|
5811 | value: function toString(withBinding) {
|
5812 | return 'this';
|
5813 | }
|
5814 | }, {
|
5815 | key: 'toJSON',
|
5816 | value: function toJSON() {
|
5817 | return {
|
5818 | typeName: this.typeName
|
5819 | };
|
5820 | }
|
5821 | }]);
|
5822 | return ThisType;
|
5823 | }(Type);
|
5824 |
|
5825 | var warnedInstances$1 = new WeakSet();
|
5826 |
|
5827 | var TypeBox = function (_Type) {
|
5828 | inherits(TypeBox, _Type);
|
5829 |
|
5830 | function TypeBox() {
|
5831 | var _ref;
|
5832 |
|
5833 | var _temp, _this, _ret;
|
5834 |
|
5835 | classCallCheck(this, TypeBox);
|
5836 |
|
5837 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5838 | args[_key] = arguments[_key];
|
5839 | }
|
5840 |
|
5841 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeBox.__proto__ || Object.getPrototypeOf(TypeBox)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeBox', _temp), possibleConstructorReturn(_this, _ret);
|
5842 | }
|
5843 |
|
5844 | createClass(TypeBox, [{
|
5845 | key: 'errors',
|
5846 | value: function* errors(validation, path, input) {
|
5847 | yield* this.type.errors(validation, path, input);
|
5848 | }
|
5849 | }, {
|
5850 | key: 'accepts',
|
5851 | value: function accepts(input) {
|
5852 | return this.type.accepts(input);
|
5853 | }
|
5854 | }, {
|
5855 | key: 'compareWith',
|
5856 | value: function compareWith(input) {
|
5857 | return compareTypes(this.type, input);
|
5858 | }
|
5859 | }, {
|
5860 | key: 'apply',
|
5861 | value: function apply() {
|
5862 | var target = new TypeParameterApplication(this.context);
|
5863 | target.parent = this.type;
|
5864 |
|
5865 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
5866 | typeInstances[_key2] = arguments[_key2];
|
5867 | }
|
5868 |
|
5869 | target.typeInstances = typeInstances;
|
5870 | return target;
|
5871 | }
|
5872 |
|
5873 | |
5874 |
|
5875 |
|
5876 |
|
5877 | }, {
|
5878 | key: 'unwrap',
|
5879 | value: function unwrap() {
|
5880 | return this.type.unwrap();
|
5881 | }
|
5882 | }, {
|
5883 | key: 'toString',
|
5884 | value: function toString() {
|
5885 | return this.type.toString();
|
5886 | }
|
5887 | }, {
|
5888 | key: 'toJSON',
|
5889 | value: function toJSON() {
|
5890 | return this.type.toJSON();
|
5891 | }
|
5892 | }, {
|
5893 | key: 'name',
|
5894 | get: function get$$1() {
|
5895 | return this.type.name;
|
5896 | }
|
5897 | }, {
|
5898 | key: 'type',
|
5899 | get: function get$$1() {
|
5900 | var reveal = this.reveal;
|
5901 |
|
5902 | var type = reveal();
|
5903 | if (!type) {
|
5904 | if (!warnedInstances$1.has(this)) {
|
5905 | this.context.emitWarningMessage('Failed to reveal boxed type.');
|
5906 | warnedInstances$1.add(this);
|
5907 | }
|
5908 | return this.context.mixed();
|
5909 | } else if (!(type instanceof Type)) {
|
5910 |
|
5911 | return this.context.ref(type);
|
5912 | }
|
5913 | return type;
|
5914 | }
|
5915 | }]);
|
5916 | return TypeBox;
|
5917 | }(Type);
|
5918 |
|
5919 | var warnedMissing = {};
|
5920 |
|
5921 | var TypeReference = function (_Type) {
|
5922 | inherits(TypeReference, _Type);
|
5923 |
|
5924 | function TypeReference() {
|
5925 | var _ref;
|
5926 |
|
5927 | var _temp, _this, _ret;
|
5928 |
|
5929 | classCallCheck(this, TypeReference);
|
5930 |
|
5931 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
5932 | args[_key] = arguments[_key];
|
5933 | }
|
5934 |
|
5935 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeReference.__proto__ || Object.getPrototypeOf(TypeReference)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeReference', _temp), possibleConstructorReturn(_this, _ret);
|
5936 | }
|
5937 |
|
5938 | createClass(TypeReference, [{
|
5939 | key: 'errors',
|
5940 | value: function* errors(validation, path, input) {
|
5941 | yield* this.type.errors(validation, path, input);
|
5942 | }
|
5943 | }, {
|
5944 | key: 'accepts',
|
5945 | value: function accepts(input) {
|
5946 | return this.type.accepts(input);
|
5947 | }
|
5948 | }, {
|
5949 | key: 'compareWith',
|
5950 | value: function compareWith(input) {
|
5951 | return compareTypes(this.type, input);
|
5952 | }
|
5953 | }, {
|
5954 | key: 'apply',
|
5955 | value: function apply() {
|
5956 | var target = new TypeParameterApplication(this.context);
|
5957 | target.parent = this;
|
5958 |
|
5959 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
5960 | typeInstances[_key2] = arguments[_key2];
|
5961 | }
|
5962 |
|
5963 | target.typeInstances = typeInstances;
|
5964 | return target;
|
5965 | }
|
5966 |
|
5967 | |
5968 |
|
5969 |
|
5970 |
|
5971 | }, {
|
5972 | key: 'unwrap',
|
5973 | value: function unwrap() {
|
5974 | return this.type.unwrap();
|
5975 | }
|
5976 | }, {
|
5977 | key: 'toString',
|
5978 | value: function toString() {
|
5979 | return this.name;
|
5980 | }
|
5981 | }, {
|
5982 | key: 'toJSON',
|
5983 | value: function toJSON() {
|
5984 | return {
|
5985 | typeName: this.typeName,
|
5986 | name: this.name
|
5987 | };
|
5988 | }
|
5989 | }, {
|
5990 | key: 'type',
|
5991 | get: function get$$1() {
|
5992 | var context = this.context,
|
5993 | name = this.name;
|
5994 |
|
5995 | var type = context.get(name);
|
5996 | if (!type) {
|
5997 | if (!warnedMissing[name]) {
|
5998 | context.emitWarningMessage(`Cannot resolve type: ${ name }`);
|
5999 | warnedMissing[name] = true;
|
6000 | }
|
6001 | return context.any();
|
6002 | }
|
6003 | return type;
|
6004 | }
|
6005 | }]);
|
6006 | return TypeReference;
|
6007 | }(Type);
|
6008 |
|
6009 | var warnedInstances$2 = new WeakSet();
|
6010 |
|
6011 | var RevealedName = Symbol('RevealedName');
|
6012 | var RevealedValue = Symbol('RevealedValue');
|
6013 |
|
6014 | var TypeTDZ = function (_Type) {
|
6015 | inherits(TypeTDZ, _Type);
|
6016 |
|
6017 | function TypeTDZ() {
|
6018 | var _ref;
|
6019 |
|
6020 | var _temp, _this, _ret;
|
6021 |
|
6022 | classCallCheck(this, TypeTDZ);
|
6023 |
|
6024 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
6025 | args[_key] = arguments[_key];
|
6026 | }
|
6027 |
|
6028 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = TypeTDZ.__proto__ || Object.getPrototypeOf(TypeTDZ)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'TypeTDZ', _this[RevealedName] = undefined, _this[RevealedValue] = undefined, _temp), possibleConstructorReturn(_this, _ret);
|
6029 | }
|
6030 |
|
6031 |
|
6032 |
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 | createClass(TypeTDZ, [{
|
6038 | key: 'errors',
|
6039 | value: function* errors(validation, path, input) {
|
6040 | yield* getRevealed(this).errors(validation, path, input);
|
6041 | }
|
6042 | }, {
|
6043 | key: 'accepts',
|
6044 | value: function accepts(input) {
|
6045 | return getRevealed(this).accepts(input);
|
6046 | }
|
6047 | }, {
|
6048 | key: 'compareWith',
|
6049 | value: function compareWith(input) {
|
6050 | return compareTypes(getRevealed(this), input);
|
6051 | }
|
6052 | }, {
|
6053 | key: 'apply',
|
6054 | value: function apply() {
|
6055 | var target = new TypeParameterApplication(this.context);
|
6056 | target.parent = getRevealed(this);
|
6057 |
|
6058 | for (var _len2 = arguments.length, typeInstances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
6059 | typeInstances[_key2] = arguments[_key2];
|
6060 | }
|
6061 |
|
6062 | target.typeInstances = typeInstances;
|
6063 | return target;
|
6064 | }
|
6065 |
|
6066 | |
6067 |
|
6068 |
|
6069 |
|
6070 | }, {
|
6071 | key: 'unwrap',
|
6072 | value: function unwrap() {
|
6073 | return getRevealed(this).unwrap();
|
6074 | }
|
6075 | }, {
|
6076 | key: 'hasProperty',
|
6077 | value: function hasProperty(name) {
|
6078 | var inner = this.unwrap();
|
6079 | if (inner && typeof inner.hasProperty === 'function') {
|
6080 | return inner.hasProperty(name);
|
6081 | } else {
|
6082 | return false;
|
6083 | }
|
6084 | }
|
6085 | }, {
|
6086 | key: 'getProperty',
|
6087 | value: function getProperty(name) {
|
6088 | var inner = this.unwrap();
|
6089 | if (inner && typeof inner.getProperty === 'function') {
|
6090 | return inner.getProperty(name);
|
6091 | }
|
6092 | }
|
6093 | }, {
|
6094 | key: 'toString',
|
6095 | value: function toString() {
|
6096 | return getRevealed(this).toString();
|
6097 | }
|
6098 | }, {
|
6099 | key: 'toJSON',
|
6100 | value: function toJSON() {
|
6101 | return getRevealed(this).toJSON();
|
6102 | }
|
6103 | }, {
|
6104 | key: 'name',
|
6105 | get: function get$$1() {
|
6106 | var name = this[RevealedName];
|
6107 | if (!name) {
|
6108 | name = getRevealed(this).name;
|
6109 | }
|
6110 | return name;
|
6111 | },
|
6112 | set: function set$$1(value) {
|
6113 | this[RevealedName] = value;
|
6114 | }
|
6115 | }]);
|
6116 | return TypeTDZ;
|
6117 | }(Type);
|
6118 |
|
6119 | function getRevealed(container) {
|
6120 | var existing = container[RevealedValue];
|
6121 | if (existing) {
|
6122 | return existing;
|
6123 | } else {
|
6124 | var reveal = container.reveal;
|
6125 |
|
6126 | var type = reveal();
|
6127 | if (!type) {
|
6128 | if (!warnedInstances$2.has(container)) {
|
6129 | var name = container[RevealedName];
|
6130 | if (name) {
|
6131 | container.context.emitWarningMessage(`Failed to reveal type called "${ name }" in Temporal Dead Zone.`);
|
6132 | } else {
|
6133 | container.context.emitWarningMessage('Failed to reveal unknown type in Temporal Dead Zone.');
|
6134 | }
|
6135 | warnedInstances$2.add(container);
|
6136 | }
|
6137 | return container.context.mixed();
|
6138 | } else if (!(type instanceof Type)) {
|
6139 |
|
6140 | return container.context.ref(type);
|
6141 | }
|
6142 | return type;
|
6143 | }
|
6144 | }
|
6145 |
|
6146 | var UnionType = function (_Type) {
|
6147 | inherits(UnionType, _Type);
|
6148 |
|
6149 | function UnionType() {
|
6150 | var _ref;
|
6151 |
|
6152 | var _temp, _this, _ret;
|
6153 |
|
6154 | classCallCheck(this, UnionType);
|
6155 |
|
6156 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
6157 | args[_key] = arguments[_key];
|
6158 | }
|
6159 |
|
6160 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = UnionType.__proto__ || Object.getPrototypeOf(UnionType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'UnionType', _this.types = [], _temp), possibleConstructorReturn(_this, _ret);
|
6161 | }
|
6162 |
|
6163 | createClass(UnionType, [{
|
6164 | key: 'errors',
|
6165 | value: function* errors(validation, path, input) {
|
6166 | var types = this.types;
|
6167 | var length = types.length;
|
6168 |
|
6169 | for (var i = 0; i < length; i++) {
|
6170 | var type = types[i];
|
6171 | if (type.accepts(input)) {
|
6172 | return;
|
6173 | }
|
6174 | }
|
6175 | yield [path, getErrorMessage('ERR_NO_UNION', this.toString()), this];
|
6176 | }
|
6177 | }, {
|
6178 | key: 'accepts',
|
6179 | value: function accepts(input) {
|
6180 | var types = this.types;
|
6181 | var length = types.length;
|
6182 |
|
6183 | for (var i = 0; i < length; i++) {
|
6184 | var type = types[i];
|
6185 | if (type.accepts(input)) {
|
6186 | return true;
|
6187 | }
|
6188 | }
|
6189 | return false;
|
6190 | }
|
6191 | }, {
|
6192 | key: 'compareWith',
|
6193 | value: function compareWith(input) {
|
6194 | var types = this.types;
|
6195 | if (input instanceof UnionType) {
|
6196 | var inputTypes = input.types;
|
6197 | var identicalCount = 0;
|
6198 | loop: for (var i = 0; i < types.length; i++) {
|
6199 | var type = types[i];
|
6200 | for (var j = 0; j < inputTypes.length; j++) {
|
6201 | var result = compareTypes(type, inputTypes[i]);
|
6202 | if (result === 0) {
|
6203 | identicalCount++;
|
6204 | continue loop;
|
6205 | } else if (result === 1) {
|
6206 | continue loop;
|
6207 | }
|
6208 | }
|
6209 |
|
6210 | return -1;
|
6211 | }
|
6212 |
|
6213 | if (identicalCount === types.length) {
|
6214 | return 0;
|
6215 | } else {
|
6216 | return 1;
|
6217 | }
|
6218 | } else {
|
6219 | for (var _i = 0; _i < types.length; _i++) {
|
6220 | var _type = types[_i];
|
6221 | if (compareTypes(_type, input) >= 0) {
|
6222 | return 1;
|
6223 | }
|
6224 | }
|
6225 | return -1;
|
6226 | }
|
6227 | }
|
6228 | }, {
|
6229 | key: 'toString',
|
6230 | value: function toString() {
|
6231 | var types = this.types;
|
6232 |
|
6233 | var normalized = new Array(types.length);
|
6234 | for (var i = 0; i < types.length; i++) {
|
6235 | var type = types[i];
|
6236 | if (type.typeName === 'FunctionType' || type.typeName === 'ParameterizedFunctionType') {
|
6237 | normalized[i] = `(${ type.toString() })`;
|
6238 | } else {
|
6239 | normalized[i] = type.toString();
|
6240 | }
|
6241 | }
|
6242 | return normalized.join(' | ');
|
6243 | }
|
6244 | }, {
|
6245 | key: 'toJSON',
|
6246 | value: function toJSON() {
|
6247 | return {
|
6248 | typeName: this.typeName,
|
6249 | types: this.types
|
6250 | };
|
6251 | }
|
6252 | }]);
|
6253 | return UnionType;
|
6254 | }(Type);
|
6255 |
|
6256 | function registerPrimitiveTypes(t) {
|
6257 | primitiveTypes.null = Object.freeze(new NullLiteralType(t));
|
6258 | primitiveTypes.empty = Object.freeze(new EmptyType(t));
|
6259 | primitiveTypes.number = Object.freeze(new NumberType(t));
|
6260 | primitiveTypes.boolean = Object.freeze(new BooleanType(t));
|
6261 | primitiveTypes.string = Object.freeze(new StringType(t));
|
6262 | primitiveTypes.symbol = Object.freeze(new SymbolType(t));
|
6263 | primitiveTypes.any = Object.freeze(new AnyType(t));
|
6264 | primitiveTypes.mixed = Object.freeze(new MixedType(t));
|
6265 | primitiveTypes.void = Object.freeze(new VoidType(t));
|
6266 | primitiveTypes.existential = Object.freeze(new ExistentialType(t));
|
6267 | return t;
|
6268 | }
|
6269 |
|
6270 | function registerBuiltinTypeConstructors(t) {
|
6271 |
|
6272 | t.declareTypeConstructor({
|
6273 | name: 'Date',
|
6274 | impl: Date,
|
6275 | typeName: 'DateType',
|
6276 | *errors(validation, path, input) {
|
6277 | if (!(input instanceof Date)) {
|
6278 | yield [path, getErrorMessage('ERR_EXPECT_INSTANCEOF', 'Date'), this];
|
6279 | } else if (isNaN(input.getTime())) {
|
6280 | yield [path, getErrorMessage('ERR_INVALID_DATE'), this];
|
6281 | }
|
6282 | },
|
6283 | accepts(input) {
|
6284 | return input instanceof Date && !isNaN(input.getTime());
|
6285 | },
|
6286 | inferTypeParameters(input) {
|
6287 | return [];
|
6288 | }
|
6289 | });
|
6290 |
|
6291 | t.declareTypeConstructor({
|
6292 | name: 'Promise',
|
6293 | impl: Promise,
|
6294 | typeName: 'PromiseType',
|
6295 | *errors(validation, path, input, futureType) {
|
6296 | invariant(futureType, 'Must specify type parameter for Promise.');
|
6297 | var context = this.context;
|
6298 |
|
6299 | if (!context.checkPredicate('Promise', input)) {
|
6300 | yield [path, getErrorMessage('ERR_EXPECT_PROMISE', futureType), this];
|
6301 | }
|
6302 | },
|
6303 | accepts(input) {
|
6304 | var context = this.context;
|
6305 |
|
6306 | return context.checkPredicate('Promise', input);
|
6307 | },
|
6308 | inferTypeParameters(input) {
|
6309 | return [];
|
6310 | }
|
6311 | });
|
6312 |
|
6313 | t.declareTypeConstructor({
|
6314 | name: 'Map',
|
6315 | impl: Map,
|
6316 | typeName: 'MapType',
|
6317 | *errors(validation, path, input, keyType, valueType) {
|
6318 | invariant(keyType, 'Must specify two type parameters for Map.');
|
6319 | invariant(valueType, 'Must specify two type parameters for Map.');
|
6320 | var context = this.context;
|
6321 |
|
6322 | if (!context.checkPredicate('Map', input)) {
|
6323 | yield [path, getErrorMessage('ERR_EXPECT_INSTANCEOF', 'Map'), this];
|
6324 | return;
|
6325 | }
|
6326 | var _iteratorNormalCompletion = true;
|
6327 | var _didIteratorError = false;
|
6328 | var _iteratorError = undefined;
|
6329 |
|
6330 | try {
|
6331 | for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
6332 | var _ref = _step.value;
|
6333 |
|
6334 | var _ref2 = slicedToArray(_ref, 2);
|
6335 |
|
6336 | var key = _ref2[0];
|
6337 | var value = _ref2[1];
|
6338 |
|
6339 | if (!keyType.accepts(key)) {
|
6340 | yield [path, getErrorMessage('ERR_EXPECT_KEY_TYPE', keyType), this];
|
6341 | }
|
6342 |
|
6343 | yield* valueType.errors(validation, path.concat(key), value);
|
6344 | }
|
6345 | } catch (err) {
|
6346 | _didIteratorError = true;
|
6347 | _iteratorError = err;
|
6348 | } finally {
|
6349 | try {
|
6350 | if (!_iteratorNormalCompletion && _iterator.return) {
|
6351 | _iterator.return();
|
6352 | }
|
6353 | } finally {
|
6354 | if (_didIteratorError) {
|
6355 | throw _iteratorError;
|
6356 | }
|
6357 | }
|
6358 | }
|
6359 | },
|
6360 | accepts(input, keyType, valueType) {
|
6361 | var context = this.context;
|
6362 |
|
6363 | if (!context.checkPredicate('Map', input)) {
|
6364 | return false;
|
6365 | }
|
6366 | var _iteratorNormalCompletion2 = true;
|
6367 | var _didIteratorError2 = false;
|
6368 | var _iteratorError2 = undefined;
|
6369 |
|
6370 | try {
|
6371 | for (var _iterator2 = input[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
6372 | var _ref3 = _step2.value;
|
6373 |
|
6374 | var _ref4 = slicedToArray(_ref3, 2);
|
6375 |
|
6376 | var key = _ref4[0];
|
6377 | var value = _ref4[1];
|
6378 |
|
6379 | if (!keyType.accepts(key) || !valueType.accepts(value)) {
|
6380 | return false;
|
6381 | }
|
6382 | }
|
6383 | } catch (err) {
|
6384 | _didIteratorError2 = true;
|
6385 | _iteratorError2 = err;
|
6386 | } finally {
|
6387 | try {
|
6388 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
6389 | _iterator2.return();
|
6390 | }
|
6391 | } finally {
|
6392 | if (_didIteratorError2) {
|
6393 | throw _iteratorError2;
|
6394 | }
|
6395 | }
|
6396 | }
|
6397 |
|
6398 | return true;
|
6399 | },
|
6400 | inferTypeParameters(input) {
|
6401 | var keyTypes = [];
|
6402 | var valueTypes = [];
|
6403 | var _iteratorNormalCompletion3 = true;
|
6404 | var _didIteratorError3 = false;
|
6405 | var _iteratorError3 = undefined;
|
6406 |
|
6407 | try {
|
6408 | loop: for (var _iterator3 = input[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
6409 | var _ref5 = _step3.value;
|
6410 |
|
6411 | var _ref6 = slicedToArray(_ref5, 2);
|
6412 |
|
6413 | var key = _ref6[0];
|
6414 | var value = _ref6[1];
|
6415 |
|
6416 | findKey: {
|
6417 | for (var i = 0; i < keyTypes.length; i++) {
|
6418 | var type = keyTypes[i];
|
6419 | if (type.accepts(key)) {
|
6420 | break findKey;
|
6421 | }
|
6422 | }
|
6423 | keyTypes.push(t.typeOf(key));
|
6424 | }
|
6425 |
|
6426 | for (var _i = 0; _i < valueTypes.length; _i++) {
|
6427 | var _type = valueTypes[_i];
|
6428 | if (_type.accepts(value)) {
|
6429 | continue loop;
|
6430 | }
|
6431 | }
|
6432 | valueTypes.push(t.typeOf(value));
|
6433 | }
|
6434 | } catch (err) {
|
6435 | _didIteratorError3 = true;
|
6436 | _iteratorError3 = err;
|
6437 | } finally {
|
6438 | try {
|
6439 | if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
6440 | _iterator3.return();
|
6441 | }
|
6442 | } finally {
|
6443 | if (_didIteratorError3) {
|
6444 | throw _iteratorError3;
|
6445 | }
|
6446 | }
|
6447 | }
|
6448 |
|
6449 | var typeInstances = [];
|
6450 |
|
6451 | if (keyTypes.length === 0) {
|
6452 | typeInstances.push(t.existential());
|
6453 | } else if (keyTypes.length === 1) {
|
6454 | typeInstances.push(keyTypes[0]);
|
6455 | } else {
|
6456 | typeInstances.push(t.union.apply(t, keyTypes));
|
6457 | }
|
6458 |
|
6459 | if (valueTypes.length === 0) {
|
6460 | typeInstances.push(t.existential());
|
6461 | } else if (valueTypes.length === 1) {
|
6462 | typeInstances.push(valueTypes[0]);
|
6463 | } else {
|
6464 | typeInstances.push(t.union.apply(t, valueTypes));
|
6465 | }
|
6466 |
|
6467 | return typeInstances;
|
6468 | }
|
6469 | });
|
6470 |
|
6471 | t.declareTypeConstructor({
|
6472 | name: 'Set',
|
6473 | impl: Set,
|
6474 | typeName: 'SetType',
|
6475 | *errors(validation, path, input, valueType) {
|
6476 | invariant(valueType, 'Must specify type parameter for Set.');
|
6477 | var context = this.context;
|
6478 |
|
6479 | if (!context.checkPredicate('Set', input)) {
|
6480 | yield [path, getErrorMessage('ERR_EXPECT_INSTANCEOF', 'Set'), this];
|
6481 | return;
|
6482 | }
|
6483 | var _iteratorNormalCompletion4 = true;
|
6484 | var _didIteratorError4 = false;
|
6485 | var _iteratorError4 = undefined;
|
6486 |
|
6487 | try {
|
6488 | for (var _iterator4 = input[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
6489 | var value = _step4.value;
|
6490 |
|
6491 | yield* valueType.errors(validation, path, value);
|
6492 | }
|
6493 | } catch (err) {
|
6494 | _didIteratorError4 = true;
|
6495 | _iteratorError4 = err;
|
6496 | } finally {
|
6497 | try {
|
6498 | if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
6499 | _iterator4.return();
|
6500 | }
|
6501 | } finally {
|
6502 | if (_didIteratorError4) {
|
6503 | throw _iteratorError4;
|
6504 | }
|
6505 | }
|
6506 | }
|
6507 | },
|
6508 | accepts(input, valueType) {
|
6509 | var context = this.context;
|
6510 |
|
6511 | if (!context.checkPredicate('Set', input)) {
|
6512 | return false;
|
6513 | }
|
6514 | var _iteratorNormalCompletion5 = true;
|
6515 | var _didIteratorError5 = false;
|
6516 | var _iteratorError5 = undefined;
|
6517 |
|
6518 | try {
|
6519 | for (var _iterator5 = input[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
6520 | var value = _step5.value;
|
6521 |
|
6522 | if (!valueType.accepts(value)) {
|
6523 | return false;
|
6524 | }
|
6525 | }
|
6526 | } catch (err) {
|
6527 | _didIteratorError5 = true;
|
6528 | _iteratorError5 = err;
|
6529 | } finally {
|
6530 | try {
|
6531 | if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
6532 | _iterator5.return();
|
6533 | }
|
6534 | } finally {
|
6535 | if (_didIteratorError5) {
|
6536 | throw _iteratorError5;
|
6537 | }
|
6538 | }
|
6539 | }
|
6540 |
|
6541 | return true;
|
6542 | },
|
6543 | inferTypeParameters(input) {
|
6544 | var valueTypes = [];
|
6545 | var _iteratorNormalCompletion6 = true;
|
6546 | var _didIteratorError6 = false;
|
6547 | var _iteratorError6 = undefined;
|
6548 |
|
6549 | try {
|
6550 | loop: for (var _iterator6 = input[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
6551 | var value = _step6.value;
|
6552 |
|
6553 | for (var i = 0; i < valueTypes.length; i++) {
|
6554 | var type = valueTypes[i];
|
6555 | if (type.accepts(value)) {
|
6556 | continue loop;
|
6557 | }
|
6558 | }
|
6559 | valueTypes.push(t.typeOf(value));
|
6560 | }
|
6561 | } catch (err) {
|
6562 | _didIteratorError6 = true;
|
6563 | _iteratorError6 = err;
|
6564 | } finally {
|
6565 | try {
|
6566 | if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
6567 | _iterator6.return();
|
6568 | }
|
6569 | } finally {
|
6570 | if (_didIteratorError6) {
|
6571 | throw _iteratorError6;
|
6572 | }
|
6573 | }
|
6574 | }
|
6575 |
|
6576 | if (valueTypes.length === 0) {
|
6577 | return [t.existential()];
|
6578 | } else if (valueTypes.length === 1) {
|
6579 | return [valueTypes[0]];
|
6580 | } else {
|
6581 | return [t.union.apply(t, valueTypes)];
|
6582 | }
|
6583 | }
|
6584 | });
|
6585 |
|
6586 | return t;
|
6587 | }
|
6588 |
|
6589 | function registerTypePredicates(context) {
|
6590 | context.setPredicate('Array', function (input) {
|
6591 | return Array.isArray(input);
|
6592 | });
|
6593 | context.setPredicate('Map', function (input) {
|
6594 | return input instanceof Map;
|
6595 | });
|
6596 | context.setPredicate('Set', function (input) {
|
6597 | return input instanceof Set;
|
6598 | });
|
6599 | context.setPredicate('Promise', function (input) {
|
6600 | if (input instanceof Promise) {
|
6601 | return true;
|
6602 | } else if (input !== null && typeof input === 'object' && typeof input.then === 'function') {
|
6603 | return input.then.length >= 2;
|
6604 | } else {
|
6605 | return false;
|
6606 | }
|
6607 | });
|
6608 | }
|
6609 |
|
6610 | var TypeInferer = function () {
|
6611 | function TypeInferer(context) {
|
6612 | classCallCheck(this, TypeInferer);
|
6613 |
|
6614 | this.context = context;
|
6615 | }
|
6616 |
|
6617 | createClass(TypeInferer, [{
|
6618 | key: 'infer',
|
6619 | value: function infer(input) {
|
6620 | var primitive = this.inferPrimitive(input);
|
6621 | if (primitive) {
|
6622 | return primitive;
|
6623 | }
|
6624 | var inferred = new Map();
|
6625 | return this.inferComplex(input, inferred);
|
6626 | }
|
6627 | }, {
|
6628 | key: 'inferInternal',
|
6629 | value: function inferInternal(input, inferred) {
|
6630 | var primitive = this.inferPrimitive(input);
|
6631 | if (primitive) {
|
6632 | return primitive;
|
6633 | }
|
6634 | return this.inferComplex(input, inferred);
|
6635 | }
|
6636 | }, {
|
6637 | key: 'inferPrimitive',
|
6638 | value: function inferPrimitive(input) {
|
6639 | var context = this.context;
|
6640 |
|
6641 | if (input === null) {
|
6642 | return context.null();
|
6643 | } else if (input === undefined) {
|
6644 | return context.void();
|
6645 | } else if (typeof input === 'number') {
|
6646 | return context.number();
|
6647 | } else if (typeof input === 'boolean') {
|
6648 | return context.boolean();
|
6649 | } else if (typeof input === 'string') {
|
6650 | return context.string();
|
6651 | }
|
6652 |
|
6653 | else if (typeof input === 'symbol') {
|
6654 | return context.symbol(input);
|
6655 | } else {
|
6656 | return undefined;
|
6657 | }
|
6658 | }
|
6659 | }, {
|
6660 | key: 'inferComplex',
|
6661 | value: function inferComplex(input, inferred) {
|
6662 | var context = this.context;
|
6663 |
|
6664 |
|
6665 | if (typeof input === 'function') {
|
6666 | return this.inferFunction(input, inferred);
|
6667 | } else if (input !== null && typeof input === 'object') {
|
6668 | return this.inferObject(input, inferred);
|
6669 | } else {
|
6670 | return context.any();
|
6671 | }
|
6672 | }
|
6673 | }, {
|
6674 | key: 'inferFunction',
|
6675 | value: function inferFunction(input, inferred) {
|
6676 | var context = this.context;
|
6677 | var length = input.length;
|
6678 |
|
6679 | var body = new Array(length + 1);
|
6680 | for (var i = 0; i < length; i++) {
|
6681 | body[i] = context.param(String.fromCharCode(97 + i), context.existential());
|
6682 | }
|
6683 | body[length] = context.return(context.existential());
|
6684 | return context.fn.apply(context, body);
|
6685 | }
|
6686 | }, {
|
6687 | key: 'inferObject',
|
6688 | value: function inferObject(input, inferred) {
|
6689 | var existing = inferred.get(input);
|
6690 | if (existing) {
|
6691 | return existing;
|
6692 | }
|
6693 | var context = this.context;
|
6694 |
|
6695 | var type = void 0;
|
6696 |
|
6697 |
|
6698 |
|
6699 | var box = context.box(function () {
|
6700 | return type;
|
6701 | });
|
6702 | inferred.set(input, box);
|
6703 |
|
6704 | if (context.checkPredicate('Array', input)) {
|
6705 | type = this.inferArray(input, inferred);
|
6706 | } else if (!(input instanceof Object)) {
|
6707 | type = this.inferDict(input, inferred);
|
6708 | } else if (input.constructor !== Object) {
|
6709 | var handler = context.getTypeConstructor(input.constructor);
|
6710 | if (handler) {
|
6711 | var typeParameters = handler.inferTypeParameters(input);
|
6712 | type = handler.apply.apply(handler, toConsumableArray(typeParameters));
|
6713 | } else {
|
6714 | type = context.ref(input.constructor);
|
6715 | }
|
6716 | } else {
|
6717 | var body = [];
|
6718 | for (var key in input) {
|
6719 |
|
6720 | var value = input[key];
|
6721 | body.push(context.property(key, this.inferInternal(value, inferred)));
|
6722 | }
|
6723 | type = context.object.apply(context, body);
|
6724 | }
|
6725 |
|
6726 |
|
6727 | inferred.set(input, type);
|
6728 | return type;
|
6729 | }
|
6730 | }, {
|
6731 | key: 'inferDict',
|
6732 | value: function inferDict(input, inferred) {
|
6733 | var numericIndexers = [];
|
6734 | var stringIndexers = [];
|
6735 | loop: for (var key in input) {
|
6736 |
|
6737 | var value = input[key];
|
6738 | var types = isNaN(+key) ? stringIndexers : numericIndexers;
|
6739 | for (var i = 0; i < types.length; i++) {
|
6740 | var type = types[i];
|
6741 | if (type.accepts(value)) {
|
6742 | continue loop;
|
6743 | }
|
6744 | }
|
6745 | types.push(this.inferInternal(value, inferred));
|
6746 | }
|
6747 |
|
6748 | var context = this.context;
|
6749 |
|
6750 | var body = [];
|
6751 | if (numericIndexers.length === 1) {
|
6752 | body.push(context.indexer('index', context.number(), numericIndexers[0]));
|
6753 | } else if (numericIndexers.length > 1) {
|
6754 | body.push(context.indexer('index', context.number(), context.union.apply(context, numericIndexers)));
|
6755 | }
|
6756 |
|
6757 | if (stringIndexers.length === 1) {
|
6758 | body.push(context.indexer('key', context.string(), stringIndexers[0]));
|
6759 | } else if (stringIndexers.length > 1) {
|
6760 | body.push(context.indexer('key', context.string(), context.union.apply(context, stringIndexers)));
|
6761 | }
|
6762 |
|
6763 | return context.object.apply(context, body);
|
6764 | }
|
6765 | }, {
|
6766 | key: 'inferArray',
|
6767 | value: function inferArray(input, inferred) {
|
6768 | var context = this.context;
|
6769 |
|
6770 | var types = [];
|
6771 | var values = [];
|
6772 | var length = input.length;
|
6773 |
|
6774 | loop: for (var i = 0; i < length; i++) {
|
6775 | var item = input[i];
|
6776 | var inferredType = this.inferInternal(item, inferred);
|
6777 | for (var j = 0; j < types.length; j++) {
|
6778 | var type = types[j];
|
6779 | if (type.accepts(item) && inferredType.accepts(values[j])) {
|
6780 | continue loop;
|
6781 | }
|
6782 | }
|
6783 | types.push(inferredType);
|
6784 | values.push(item);
|
6785 | }
|
6786 | if (types.length === 0) {
|
6787 | return context.array(context.any());
|
6788 | } else if (types.length === 1) {
|
6789 | return context.array(types[0]);
|
6790 | } else {
|
6791 | return context.array(context.union.apply(context, types));
|
6792 | }
|
6793 | }
|
6794 | }]);
|
6795 | return TypeInferer;
|
6796 | }();
|
6797 |
|
6798 | function makeReactPropTypes(objectType) {
|
6799 | var output = {};
|
6800 | if (!objectType.properties) {
|
6801 | return output;
|
6802 | }
|
6803 |
|
6804 | var _loop = function _loop(property) {
|
6805 | output[property.key] = function (props, propName, componentName) {
|
6806 | return makeError(property, props);
|
6807 | };
|
6808 | };
|
6809 |
|
6810 | var _iteratorNormalCompletion = true;
|
6811 | var _didIteratorError = false;
|
6812 | var _iteratorError = undefined;
|
6813 |
|
6814 | try {
|
6815 | for (var _iterator = objectType.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
6816 | var property = _step.value;
|
6817 |
|
6818 | _loop(property);
|
6819 | }
|
6820 | } catch (err) {
|
6821 | _didIteratorError = true;
|
6822 | _iteratorError = err;
|
6823 | } finally {
|
6824 | try {
|
6825 | if (!_iteratorNormalCompletion && _iterator.return) {
|
6826 | _iterator.return();
|
6827 | }
|
6828 | } finally {
|
6829 | if (_didIteratorError) {
|
6830 | throw _iteratorError;
|
6831 | }
|
6832 | }
|
6833 | }
|
6834 |
|
6835 | return output;
|
6836 | }
|
6837 |
|
6838 | var delimiter$1 = '\n-------------------------------------------------\n\n';
|
6839 |
|
6840 | function makeWarningMessage(validation) {
|
6841 | if (!validation.hasErrors()) {
|
6842 | return;
|
6843 | }
|
6844 | var input = validation.input,
|
6845 | context = validation.context;
|
6846 |
|
6847 | var collected = [];
|
6848 | var _iteratorNormalCompletion = true;
|
6849 | var _didIteratorError = false;
|
6850 | var _iteratorError = undefined;
|
6851 |
|
6852 | try {
|
6853 | for (var _iterator = validation.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
6854 | var _ref = _step.value;
|
6855 |
|
6856 | var _ref2 = slicedToArray(_ref, 3);
|
6857 |
|
6858 | var path = _ref2[0];
|
6859 | var message = _ref2[1];
|
6860 | var expectedType = _ref2[2];
|
6861 |
|
6862 | var expected = expectedType ? expectedType.toString() : "*";
|
6863 | var actual = context.typeOf(_resolvePath(input, path)).toString();
|
6864 |
|
6865 | var field = stringifyPath(validation.path.concat(path));
|
6866 |
|
6867 | collected.push(`${ field } ${ message }\n\nExpected: ${ expected }\n\nActual: ${ actual }\n`);
|
6868 | }
|
6869 | } catch (err) {
|
6870 | _didIteratorError = true;
|
6871 | _iteratorError = err;
|
6872 | } finally {
|
6873 | try {
|
6874 | if (!_iteratorNormalCompletion && _iterator.return) {
|
6875 | _iterator.return();
|
6876 | }
|
6877 | } finally {
|
6878 | if (_didIteratorError) {
|
6879 | throw _iteratorError;
|
6880 | }
|
6881 | }
|
6882 | }
|
6883 |
|
6884 | return `Warning: ${ collected.join(delimiter$1) }`;
|
6885 | }
|
6886 |
|
6887 | function makeUnion(context, types) {
|
6888 | var length = types.length;
|
6889 | var merged = [];
|
6890 | for (var i = 0; i < length; i++) {
|
6891 | var type = types[i];
|
6892 | if (type instanceof AnyType || type instanceof MixedType || type instanceof ExistentialType) {
|
6893 | return type;
|
6894 | }
|
6895 | if (type instanceof UnionType) {
|
6896 | mergeUnionTypes(merged, type.types);
|
6897 | } else {
|
6898 | merged.push(type);
|
6899 | }
|
6900 | }
|
6901 | var union = new UnionType(context);
|
6902 | union.types = merged;
|
6903 | return union;
|
6904 | }
|
6905 |
|
6906 | function mergeUnionTypes(aTypes, bTypes) {
|
6907 | loop: for (var i = 0; i < bTypes.length; i++) {
|
6908 | var bType = bTypes[i];
|
6909 | for (var j = 0; j < aTypes.length; j++) {
|
6910 | var aType = aTypes[j];
|
6911 | if (compareTypes(aType, bType) !== -1) {
|
6912 | continue loop;
|
6913 | }
|
6914 | }
|
6915 | aTypes.push(bType);
|
6916 | }
|
6917 | }
|
6918 |
|
6919 | function makePropertyDescriptor(typeSource, input, propertyName, descriptor, shouldAssert) {
|
6920 | if (typeof descriptor.get === 'function' && typeof descriptor.set === 'function') {
|
6921 | return augmentExistingAccessors(typeSource, input, propertyName, descriptor, shouldAssert);
|
6922 | } else {
|
6923 | return propertyToAccessor(typeSource, input, propertyName, descriptor, shouldAssert);
|
6924 | }
|
6925 | }
|
6926 |
|
6927 | function makePropertyName(name) {
|
6928 | return `_flowRuntime$${ name }`;
|
6929 | }
|
6930 |
|
6931 | function getClassName(input) {
|
6932 | if (typeof input === 'function') {
|
6933 | return input.name || '[Class anonymous]';
|
6934 | } else if (typeof input.constructor === 'function') {
|
6935 | return getClassName(input.constructor);
|
6936 | } else {
|
6937 | return '[Class anonymous]';
|
6938 | }
|
6939 | }
|
6940 |
|
6941 | function resolveType(receiver, typeSource) {
|
6942 | if (typeof typeSource === 'function') {
|
6943 | return typeSource.call(receiver);
|
6944 | } else {
|
6945 | return typeSource;
|
6946 | }
|
6947 | }
|
6948 |
|
6949 | function propertyToAccessor(typeSource, input, propertyName, descriptor, shouldAssert) {
|
6950 | var safeName = makePropertyName(propertyName);
|
6951 | var className = getClassName(input);
|
6952 | var initializer = descriptor.initializer,
|
6953 | writable = descriptor.writable,
|
6954 | config = objectWithoutProperties(descriptor, ['initializer', 'writable']);
|
6955 |
|
6956 | var propertyPath = [className, propertyName];
|
6957 |
|
6958 | return _extends({}, config, {
|
6959 | type: 'accessor',
|
6960 | get() {
|
6961 | if (safeName in this) {
|
6962 | return this[safeName];
|
6963 | } else if (initializer) {
|
6964 | var type = resolveType(this, typeSource);
|
6965 | var _value = initializer.call(this);
|
6966 | var context = type.context;
|
6967 | context.check(type, _value, 'Default value for property', propertyPath);
|
6968 | Object.defineProperty(this, safeName, {
|
6969 | writable: true,
|
6970 | value: _value
|
6971 | });
|
6972 | return _value;
|
6973 | } else {
|
6974 | Object.defineProperty(this, safeName, {
|
6975 | writable: true,
|
6976 | value: undefined
|
6977 | });
|
6978 | }
|
6979 | },
|
6980 | set(value) {
|
6981 | var type = resolveType(this, typeSource);
|
6982 | var context = type.context;
|
6983 | if (shouldAssert) {
|
6984 | context.assert(type, value, 'Property', propertyPath);
|
6985 | } else {
|
6986 | context.warn(type, value, 'Property', propertyPath);
|
6987 | }
|
6988 | if (safeName in this) {
|
6989 | this[safeName] = value;
|
6990 | } else {
|
6991 | Object.defineProperty(this, safeName, {
|
6992 | writable: true,
|
6993 | value: value
|
6994 | });
|
6995 | }
|
6996 | }
|
6997 | });
|
6998 | }
|
6999 |
|
7000 | function augmentExistingAccessors(typeSource, input, propertyName, descriptor, shouldAssert) {
|
7001 |
|
7002 | var className = getClassName(input);
|
7003 | var propertyPath = [className, propertyName];
|
7004 |
|
7005 | var originalSetter = descriptor.set;
|
7006 |
|
7007 | descriptor.set = function set$$1(value) {
|
7008 | var type = resolveType(this, typeSource);
|
7009 | var context = type.context;
|
7010 | if (shouldAssert) {
|
7011 | context.assert(type, value, 'Property', propertyPath);
|
7012 | } else {
|
7013 | context.warn(type, value, 'Property', propertyPath);
|
7014 | }
|
7015 | originalSetter.call(this, value);
|
7016 | };
|
7017 | }
|
7018 |
|
7019 |
|
7020 |
|
7021 | function annotateValue(input, type) {
|
7022 |
|
7023 | if (type instanceof Type) {
|
7024 | input[TypeSymbol] = type;
|
7025 | return input;
|
7026 | } else {
|
7027 | var _ret = function () {
|
7028 | var type = input;
|
7029 | return {
|
7030 | v: function v(input) {
|
7031 | input[TypeSymbol] = type;
|
7032 | return input;
|
7033 | }
|
7034 | };
|
7035 | }();
|
7036 |
|
7037 | if (typeof _ret === "object") return _ret.v;
|
7038 | }
|
7039 | }
|
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 | var $DiffType = function (_Type) {
|
7046 | inherits($DiffType, _Type);
|
7047 |
|
7048 | function $DiffType() {
|
7049 | var _ref;
|
7050 |
|
7051 | var _temp, _this, _ret;
|
7052 |
|
7053 | classCallCheck(this, $DiffType);
|
7054 |
|
7055 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7056 | args[_key] = arguments[_key];
|
7057 | }
|
7058 |
|
7059 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $DiffType.__proto__ || Object.getPrototypeOf($DiffType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$DiffType', _temp), possibleConstructorReturn(_this, _ret);
|
7060 | }
|
7061 |
|
7062 | createClass($DiffType, [{
|
7063 | key: 'errors',
|
7064 | value: function* errors(validation, path, input) {
|
7065 | var aType = this.aType,
|
7066 | bType = this.bType;
|
7067 |
|
7068 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7069 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
7070 | return;
|
7071 | }
|
7072 | aType = aType.unwrap();
|
7073 | bType = bType.unwrap();
|
7074 | invariant(aType instanceof ObjectType && bType instanceof ObjectType, 'Can only $Diff object types.');
|
7075 | var properties = aType.properties;
|
7076 | for (var i = 0; i < properties.length; i++) {
|
7077 | var property = properties[i];
|
7078 | if (bType.hasProperty(property.key)) {
|
7079 | continue;
|
7080 | }
|
7081 | yield* property.errors(validation, path.concat(property.key), input);
|
7082 | }
|
7083 | }
|
7084 | }, {
|
7085 | key: 'accepts',
|
7086 | value: function accepts(input) {
|
7087 | var aType = this.aType,
|
7088 | bType = this.bType;
|
7089 |
|
7090 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7091 | return false;
|
7092 | }
|
7093 | aType = aType.unwrap();
|
7094 | bType = bType.unwrap();
|
7095 | invariant(aType instanceof ObjectType && bType instanceof ObjectType, 'Can only $Diff object types.');
|
7096 | var properties = aType.properties;
|
7097 | for (var i = 0; i < properties.length; i++) {
|
7098 | var property = properties[i];
|
7099 | if (bType.hasProperty(property.key)) {
|
7100 | continue;
|
7101 | }
|
7102 | if (!property.accepts(input)) {
|
7103 | return false;
|
7104 | }
|
7105 | }
|
7106 | return true;
|
7107 | }
|
7108 | }, {
|
7109 | key: 'compareWith',
|
7110 | value: function compareWith(input) {
|
7111 | return compareTypes(this.unwrap(), input);
|
7112 | }
|
7113 | }, {
|
7114 | key: 'unwrap',
|
7115 | value: function unwrap() {
|
7116 | var _context;
|
7117 |
|
7118 | var aType = this.aType,
|
7119 | bType = this.bType;
|
7120 |
|
7121 | aType = aType.unwrap();
|
7122 | bType = bType.unwrap();
|
7123 | invariant(aType instanceof ObjectType && bType instanceof ObjectType, 'Can only $Diff object types.');
|
7124 | var properties = aType.properties;
|
7125 | var args = [];
|
7126 | for (var i = 0; i < properties.length; i++) {
|
7127 | var property = properties[i];
|
7128 | if (bType.hasProperty(property.key)) {
|
7129 | continue;
|
7130 | }
|
7131 | args.push(property);
|
7132 | }
|
7133 | return (_context = this.context).object.apply(_context, args);
|
7134 | }
|
7135 | }, {
|
7136 | key: 'toString',
|
7137 | value: function toString() {
|
7138 | return `$Diff<${ this.aType.toString() }, ${ this.bType.toString() }>`;
|
7139 | }
|
7140 | }, {
|
7141 | key: 'toJSON',
|
7142 | value: function toJSON() {
|
7143 | return {
|
7144 | typeName: this.typeName,
|
7145 | aType: this.aType,
|
7146 | bType: this.bType
|
7147 | };
|
7148 | }
|
7149 | }]);
|
7150 | return $DiffType;
|
7151 | }(Type);
|
7152 |
|
7153 |
|
7154 |
|
7155 | var $FlowFixMeType = function (_Type) {
|
7156 | inherits($FlowFixMeType, _Type);
|
7157 |
|
7158 | function $FlowFixMeType() {
|
7159 | var _ref;
|
7160 |
|
7161 | var _temp, _this, _ret;
|
7162 |
|
7163 | classCallCheck(this, $FlowFixMeType);
|
7164 |
|
7165 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7166 | args[_key] = arguments[_key];
|
7167 | }
|
7168 |
|
7169 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $FlowFixMeType.__proto__ || Object.getPrototypeOf($FlowFixMeType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$FlowFixMeType', _temp), possibleConstructorReturn(_this, _ret);
|
7170 | }
|
7171 |
|
7172 | createClass($FlowFixMeType, [{
|
7173 | key: 'errors',
|
7174 | value: function* errors(validation, input) {
|
7175 | var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
7176 | }
|
7177 | }, {
|
7178 | key: 'accepts',
|
7179 | value: function accepts(input) {
|
7180 | return true;
|
7181 | }
|
7182 | }, {
|
7183 | key: 'compareWith',
|
7184 | value: function compareWith(input) {
|
7185 | return 1;
|
7186 | }
|
7187 | }, {
|
7188 | key: 'unwrap',
|
7189 | value: function unwrap() {
|
7190 | return this;
|
7191 | }
|
7192 | }, {
|
7193 | key: 'toString',
|
7194 | value: function toString() {
|
7195 | return '$FlowFixMe';
|
7196 | }
|
7197 | }, {
|
7198 | key: 'toJSON',
|
7199 | value: function toJSON() {
|
7200 | return {
|
7201 | typeName: this.typeName
|
7202 | };
|
7203 | }
|
7204 | }]);
|
7205 | return $FlowFixMeType;
|
7206 | }(Type);
|
7207 |
|
7208 |
|
7209 |
|
7210 | var $KeysType = function (_Type) {
|
7211 | inherits($KeysType, _Type);
|
7212 |
|
7213 | function $KeysType() {
|
7214 | var _ref;
|
7215 |
|
7216 | var _temp, _this, _ret;
|
7217 |
|
7218 | classCallCheck(this, $KeysType);
|
7219 |
|
7220 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7221 | args[_key] = arguments[_key];
|
7222 | }
|
7223 |
|
7224 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $KeysType.__proto__ || Object.getPrototypeOf($KeysType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$KeysType', _temp), possibleConstructorReturn(_this, _ret);
|
7225 | }
|
7226 |
|
7227 | createClass($KeysType, [{
|
7228 | key: 'errors',
|
7229 | value: function* errors(validation, path, input) {
|
7230 | var type = this.type.unwrap();
|
7231 | invariant(type instanceof ObjectType, 'Can only $Keys<T> object types.');
|
7232 |
|
7233 | var properties = type.properties;
|
7234 | var length = properties.length;
|
7235 | for (var i = 0; i < length; i++) {
|
7236 | var property = properties[i];
|
7237 | if (input === property.key) {
|
7238 | return;
|
7239 | }
|
7240 | }
|
7241 | var keys = new Array(length);
|
7242 | for (var _i = 0; _i < length; _i++) {
|
7243 | keys[_i] = properties[_i].key;
|
7244 | }
|
7245 | yield [path, getErrorMessage('ERR_NO_UNION', keys.join(' | ')), this];
|
7246 | }
|
7247 | }, {
|
7248 | key: 'accepts',
|
7249 | value: function accepts(input) {
|
7250 | var type = this.type.unwrap();
|
7251 | invariant(type instanceof ObjectType, 'Can only $Keys<T> object types.');
|
7252 |
|
7253 | var properties = type.properties;
|
7254 | var length = properties.length;
|
7255 | for (var i = 0; i < length; i++) {
|
7256 | var property = properties[i];
|
7257 | if (input === property.key) {
|
7258 | return true;
|
7259 | }
|
7260 | }
|
7261 | return false;
|
7262 | }
|
7263 | }, {
|
7264 | key: 'compareWith',
|
7265 | value: function compareWith(input) {
|
7266 | return compareTypes(this.unwrap(), input);
|
7267 | }
|
7268 | }, {
|
7269 | key: 'unwrap',
|
7270 | value: function unwrap() {
|
7271 | var _context;
|
7272 |
|
7273 | var context = this.context;
|
7274 | var type = this.type.unwrap();
|
7275 | invariant(type instanceof ObjectType, 'Can only $Keys<T> object types.');
|
7276 |
|
7277 | var properties = type.properties;
|
7278 | var length = properties.length;
|
7279 | var keys = new Array(length);
|
7280 | for (var i = 0; i < length; i++) {
|
7281 | var property = properties[i];
|
7282 | keys[i] = context.literal(property.key);
|
7283 | }
|
7284 | return (_context = this.context).union.apply(_context, keys);
|
7285 | }
|
7286 | }, {
|
7287 | key: 'toString',
|
7288 | value: function toString() {
|
7289 | return `$Keys<${ this.type.toString() }>`;
|
7290 | }
|
7291 | }, {
|
7292 | key: 'toJSON',
|
7293 | value: function toJSON() {
|
7294 | return {
|
7295 | typeName: this.typeName,
|
7296 | type: this.type
|
7297 | };
|
7298 | }
|
7299 | }]);
|
7300 | return $KeysType;
|
7301 | }(Type);
|
7302 |
|
7303 |
|
7304 |
|
7305 | var $ObjMapiType = function (_Type) {
|
7306 | inherits($ObjMapiType, _Type);
|
7307 |
|
7308 | function $ObjMapiType() {
|
7309 | var _ref;
|
7310 |
|
7311 | var _temp, _this, _ret;
|
7312 |
|
7313 | classCallCheck(this, $ObjMapiType);
|
7314 |
|
7315 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7316 | args[_key] = arguments[_key];
|
7317 | }
|
7318 |
|
7319 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $ObjMapiType.__proto__ || Object.getPrototypeOf($ObjMapiType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$ObjMapiType', _temp), possibleConstructorReturn(_this, _ret);
|
7320 | }
|
7321 |
|
7322 | createClass($ObjMapiType, [{
|
7323 | key: 'errors',
|
7324 | value: function* errors(validation, path, input) {
|
7325 | var object = this.object,
|
7326 | mapper = this.mapper,
|
7327 | context = this.context;
|
7328 |
|
7329 | var target = object.unwrap();
|
7330 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7331 |
|
7332 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7333 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
7334 | return;
|
7335 | }
|
7336 |
|
7337 | var _iteratorNormalCompletion = true;
|
7338 | var _didIteratorError = false;
|
7339 | var _iteratorError = undefined;
|
7340 |
|
7341 | try {
|
7342 | for (var _iterator = target.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
7343 | var prop = _step.value;
|
7344 |
|
7345 | var applied = mapper.unwrap();
|
7346 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7347 |
|
7348 | var returnType = applied.invoke(context.literal(prop.key), prop.value);
|
7349 |
|
7350 | var value = input[prop.key];
|
7351 | yield* returnType.errors(validation, path.concat(prop.key), value);
|
7352 | }
|
7353 | } catch (err) {
|
7354 | _didIteratorError = true;
|
7355 | _iteratorError = err;
|
7356 | } finally {
|
7357 | try {
|
7358 | if (!_iteratorNormalCompletion && _iterator.return) {
|
7359 | _iterator.return();
|
7360 | }
|
7361 | } finally {
|
7362 | if (_didIteratorError) {
|
7363 | throw _iteratorError;
|
7364 | }
|
7365 | }
|
7366 | }
|
7367 | }
|
7368 | }, {
|
7369 | key: 'accepts',
|
7370 | value: function accepts(input) {
|
7371 | var object = this.object,
|
7372 | mapper = this.mapper,
|
7373 | context = this.context;
|
7374 |
|
7375 | var target = object.unwrap();
|
7376 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7377 |
|
7378 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7379 | return false;
|
7380 | }
|
7381 |
|
7382 | var _iteratorNormalCompletion2 = true;
|
7383 | var _didIteratorError2 = false;
|
7384 | var _iteratorError2 = undefined;
|
7385 |
|
7386 | try {
|
7387 | for (var _iterator2 = target.properties[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
7388 | var prop = _step2.value;
|
7389 |
|
7390 | var applied = mapper.unwrap();
|
7391 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7392 |
|
7393 | var returnType = applied.invoke(context.literal(prop.key), prop.value);
|
7394 |
|
7395 | var value = input[prop.key];
|
7396 | if (!returnType.accepts(value)) {
|
7397 | return false;
|
7398 | }
|
7399 | }
|
7400 | } catch (err) {
|
7401 | _didIteratorError2 = true;
|
7402 | _iteratorError2 = err;
|
7403 | } finally {
|
7404 | try {
|
7405 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
7406 | _iterator2.return();
|
7407 | }
|
7408 | } finally {
|
7409 | if (_didIteratorError2) {
|
7410 | throw _iteratorError2;
|
7411 | }
|
7412 | }
|
7413 | }
|
7414 |
|
7415 | return true;
|
7416 | }
|
7417 | }, {
|
7418 | key: 'compareWith',
|
7419 | value: function compareWith(input) {
|
7420 | return compareTypes(this.unwrap(), input);
|
7421 | }
|
7422 | }, {
|
7423 | key: 'unwrap',
|
7424 | value: function unwrap() {
|
7425 | var object = this.object,
|
7426 | mapper = this.mapper,
|
7427 | context = this.context;
|
7428 |
|
7429 | var target = object.unwrap();
|
7430 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7431 |
|
7432 | var args = [];
|
7433 |
|
7434 | var _iteratorNormalCompletion3 = true;
|
7435 | var _didIteratorError3 = false;
|
7436 | var _iteratorError3 = undefined;
|
7437 |
|
7438 | try {
|
7439 | for (var _iterator3 = target.properties[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
7440 | var prop = _step3.value;
|
7441 |
|
7442 | var applied = mapper.unwrap();
|
7443 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7444 |
|
7445 | args.push(context.property(prop.key, applied.invoke(context.literal(prop.key), prop.value)));
|
7446 | }
|
7447 | } catch (err) {
|
7448 | _didIteratorError3 = true;
|
7449 | _iteratorError3 = err;
|
7450 | } finally {
|
7451 | try {
|
7452 | if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
7453 | _iterator3.return();
|
7454 | }
|
7455 | } finally {
|
7456 | if (_didIteratorError3) {
|
7457 | throw _iteratorError3;
|
7458 | }
|
7459 | }
|
7460 | }
|
7461 |
|
7462 | return context.object.apply(context, args);
|
7463 | }
|
7464 | }, {
|
7465 | key: 'toString',
|
7466 | value: function toString() {
|
7467 | return `$ObjMapi<${ this.object.toString() }, ${ this.mapper.toString() }>`;
|
7468 | }
|
7469 | }, {
|
7470 | key: 'toJSON',
|
7471 | value: function toJSON() {
|
7472 | return {
|
7473 | typeName: this.typeName,
|
7474 | object: this.object,
|
7475 | mapper: this.mapper
|
7476 | };
|
7477 | }
|
7478 | }]);
|
7479 | return $ObjMapiType;
|
7480 | }(Type);
|
7481 |
|
7482 |
|
7483 |
|
7484 | var $ObjMapType = function (_Type) {
|
7485 | inherits($ObjMapType, _Type);
|
7486 |
|
7487 | function $ObjMapType() {
|
7488 | var _ref;
|
7489 |
|
7490 | var _temp, _this, _ret;
|
7491 |
|
7492 | classCallCheck(this, $ObjMapType);
|
7493 |
|
7494 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7495 | args[_key] = arguments[_key];
|
7496 | }
|
7497 |
|
7498 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $ObjMapType.__proto__ || Object.getPrototypeOf($ObjMapType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$ObjMapType', _temp), possibleConstructorReturn(_this, _ret);
|
7499 | }
|
7500 |
|
7501 | createClass($ObjMapType, [{
|
7502 | key: 'errors',
|
7503 | value: function* errors(validation, path, input) {
|
7504 | var object = this.object,
|
7505 | mapper = this.mapper,
|
7506 | context = this.context;
|
7507 |
|
7508 | var target = object.unwrap();
|
7509 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7510 |
|
7511 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7512 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
7513 | return;
|
7514 | }
|
7515 |
|
7516 | var _iteratorNormalCompletion = true;
|
7517 | var _didIteratorError = false;
|
7518 | var _iteratorError = undefined;
|
7519 |
|
7520 | try {
|
7521 | for (var _iterator = target.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
7522 | var prop = _step.value;
|
7523 |
|
7524 | var applied = mapper.unwrap();
|
7525 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7526 |
|
7527 | var returnType = applied.invoke(context.literal(prop.key));
|
7528 |
|
7529 | var value = input[prop.key];
|
7530 | yield* returnType.errors(validation, path.concat(prop.key), value);
|
7531 | }
|
7532 | } catch (err) {
|
7533 | _didIteratorError = true;
|
7534 | _iteratorError = err;
|
7535 | } finally {
|
7536 | try {
|
7537 | if (!_iteratorNormalCompletion && _iterator.return) {
|
7538 | _iterator.return();
|
7539 | }
|
7540 | } finally {
|
7541 | if (_didIteratorError) {
|
7542 | throw _iteratorError;
|
7543 | }
|
7544 | }
|
7545 | }
|
7546 | }
|
7547 | }, {
|
7548 | key: 'accepts',
|
7549 | value: function accepts(input) {
|
7550 | var object = this.object,
|
7551 | mapper = this.mapper,
|
7552 | context = this.context;
|
7553 |
|
7554 | var target = object.unwrap();
|
7555 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7556 |
|
7557 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7558 | return false;
|
7559 | }
|
7560 |
|
7561 | var _iteratorNormalCompletion2 = true;
|
7562 | var _didIteratorError2 = false;
|
7563 | var _iteratorError2 = undefined;
|
7564 |
|
7565 | try {
|
7566 | for (var _iterator2 = target.properties[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
7567 | var prop = _step2.value;
|
7568 |
|
7569 | var applied = mapper.unwrap();
|
7570 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7571 |
|
7572 | var returnType = applied.invoke(context.literal(prop.key));
|
7573 |
|
7574 | var value = input[prop.key];
|
7575 | if (!returnType.accepts(value)) {
|
7576 | return false;
|
7577 | }
|
7578 | }
|
7579 | } catch (err) {
|
7580 | _didIteratorError2 = true;
|
7581 | _iteratorError2 = err;
|
7582 | } finally {
|
7583 | try {
|
7584 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
7585 | _iterator2.return();
|
7586 | }
|
7587 | } finally {
|
7588 | if (_didIteratorError2) {
|
7589 | throw _iteratorError2;
|
7590 | }
|
7591 | }
|
7592 | }
|
7593 |
|
7594 | return true;
|
7595 | }
|
7596 | }, {
|
7597 | key: 'compareWith',
|
7598 | value: function compareWith(input) {
|
7599 | return compareTypes(this.unwrap(), input);
|
7600 | }
|
7601 | }, {
|
7602 | key: 'unwrap',
|
7603 | value: function unwrap() {
|
7604 | var object = this.object,
|
7605 | mapper = this.mapper,
|
7606 | context = this.context;
|
7607 |
|
7608 | var target = object.unwrap();
|
7609 | invariant(target instanceof ObjectType, 'Target must be an object type.');
|
7610 |
|
7611 | var args = [];
|
7612 |
|
7613 | var _iteratorNormalCompletion3 = true;
|
7614 | var _didIteratorError3 = false;
|
7615 | var _iteratorError3 = undefined;
|
7616 |
|
7617 | try {
|
7618 | for (var _iterator3 = target.properties[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
7619 | var prop = _step3.value;
|
7620 |
|
7621 | var applied = mapper.unwrap();
|
7622 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7623 |
|
7624 | args.push(context.property(prop.key, applied.invoke(context.literal(prop.key))));
|
7625 | }
|
7626 | } catch (err) {
|
7627 | _didIteratorError3 = true;
|
7628 | _iteratorError3 = err;
|
7629 | } finally {
|
7630 | try {
|
7631 | if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
7632 | _iterator3.return();
|
7633 | }
|
7634 | } finally {
|
7635 | if (_didIteratorError3) {
|
7636 | throw _iteratorError3;
|
7637 | }
|
7638 | }
|
7639 | }
|
7640 |
|
7641 | return context.object.apply(context, args);
|
7642 | }
|
7643 | }, {
|
7644 | key: 'toString',
|
7645 | value: function toString() {
|
7646 | return `$ObjMap<${ this.object.toString() }, ${ this.mapper.toString() }>`;
|
7647 | }
|
7648 | }, {
|
7649 | key: 'toJSON',
|
7650 | value: function toJSON() {
|
7651 | return {
|
7652 | typeName: this.typeName,
|
7653 | object: this.object,
|
7654 | mapper: this.mapper
|
7655 | };
|
7656 | }
|
7657 | }]);
|
7658 | return $ObjMapType;
|
7659 | }(Type);
|
7660 |
|
7661 |
|
7662 |
|
7663 | var $PropertyType = function (_Type) {
|
7664 | inherits($PropertyType, _Type);
|
7665 |
|
7666 | function $PropertyType() {
|
7667 | var _ref;
|
7668 |
|
7669 | var _temp, _this, _ret;
|
7670 |
|
7671 | classCallCheck(this, $PropertyType);
|
7672 |
|
7673 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7674 | args[_key] = arguments[_key];
|
7675 | }
|
7676 |
|
7677 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $PropertyType.__proto__ || Object.getPrototypeOf($PropertyType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$PropertyType', _temp), possibleConstructorReturn(_this, _ret);
|
7678 | }
|
7679 |
|
7680 | createClass($PropertyType, [{
|
7681 | key: 'errors',
|
7682 | value: function* errors(validation, path, input) {
|
7683 | yield* this.unwrap().errors(validation, path, input);
|
7684 | }
|
7685 | }, {
|
7686 | key: 'accepts',
|
7687 | value: function accepts(input) {
|
7688 | return this.unwrap().accepts(input);
|
7689 | }
|
7690 | }, {
|
7691 | key: 'compareWith',
|
7692 | value: function compareWith(input) {
|
7693 | return compareTypes(this.unwrap(), input);
|
7694 | }
|
7695 | }, {
|
7696 | key: 'unwrap',
|
7697 | value: function unwrap() {
|
7698 | var object = this.object,
|
7699 | property = this.property;
|
7700 |
|
7701 | var unwrapped = object.unwrap();
|
7702 | invariant(typeof unwrapped.getProperty === 'function', 'Can only use $PropertyType on Objects.');
|
7703 | return unwrapped.getProperty(property).unwrap();
|
7704 | }
|
7705 | }, {
|
7706 | key: 'toString',
|
7707 | value: function toString() {
|
7708 | return `$PropertyType<${ this.object.toString() }, ${ String(this.property) }>`;
|
7709 | }
|
7710 | }, {
|
7711 | key: 'toJSON',
|
7712 | value: function toJSON() {
|
7713 | return {
|
7714 | typeName: this.typeName,
|
7715 | object: this.object,
|
7716 | property: this.property
|
7717 | };
|
7718 | }
|
7719 | }]);
|
7720 | return $PropertyType;
|
7721 | }(Type);
|
7722 |
|
7723 |
|
7724 |
|
7725 |
|
7726 |
|
7727 | var $ShapeType = function (_Type) {
|
7728 | inherits($ShapeType, _Type);
|
7729 |
|
7730 | function $ShapeType() {
|
7731 | var _ref;
|
7732 |
|
7733 | var _temp, _this, _ret;
|
7734 |
|
7735 | classCallCheck(this, $ShapeType);
|
7736 |
|
7737 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7738 | args[_key] = arguments[_key];
|
7739 | }
|
7740 |
|
7741 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $ShapeType.__proto__ || Object.getPrototypeOf($ShapeType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$ShapeType', _temp), possibleConstructorReturn(_this, _ret);
|
7742 | }
|
7743 |
|
7744 | createClass($ShapeType, [{
|
7745 | key: 'errors',
|
7746 | value: function* errors(validation, path, input) {
|
7747 | var type = this.type;
|
7748 |
|
7749 |
|
7750 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7751 | yield [path, getErrorMessage('ERR_EXPECT_OBJECT'), this];
|
7752 | return;
|
7753 | }
|
7754 |
|
7755 | type = type.unwrap();
|
7756 | invariant(typeof type.getProperty === 'function', 'Can only $Shape<T> object types.');
|
7757 |
|
7758 | for (var key in input) {
|
7759 |
|
7760 | var property = type.getProperty(key);
|
7761 | if (!property) {
|
7762 | continue;
|
7763 | }
|
7764 | yield* property.errors(validation, path, input);
|
7765 | }
|
7766 | }
|
7767 | }, {
|
7768 | key: 'accepts',
|
7769 | value: function accepts(input) {
|
7770 | var type = this.type;
|
7771 |
|
7772 | if (input === null || typeof input !== 'object' && typeof input !== 'function') {
|
7773 | return false;
|
7774 | }
|
7775 | type = type.unwrap();
|
7776 | invariant(typeof type.getProperty === 'function', 'Can only $Shape<T> object types.');
|
7777 | for (var key in input) {
|
7778 |
|
7779 | var property = type.getProperty(key);
|
7780 | if (!property || !property.accepts(input)) {
|
7781 | return false;
|
7782 | }
|
7783 | }
|
7784 | return true;
|
7785 | }
|
7786 | }, {
|
7787 | key: 'compareWith',
|
7788 | value: function compareWith(input) {
|
7789 | return compareTypes(this.unwrap(), input);
|
7790 | }
|
7791 | }, {
|
7792 | key: 'unwrap',
|
7793 | value: function unwrap() {
|
7794 | var _context;
|
7795 |
|
7796 | var type = this.type;
|
7797 |
|
7798 | type = type.unwrap();
|
7799 | var context = this.context;
|
7800 | invariant(type instanceof ObjectType, 'Can only $Shape<T> object types.');
|
7801 | var properties = type.properties;
|
7802 | var args = new Array(properties.length);
|
7803 | for (var i = 0; i < properties.length; i++) {
|
7804 | var property = properties[i];
|
7805 | args[i] = context.property(property.key, property.value, true);
|
7806 | }
|
7807 | return (_context = this.context).object.apply(_context, args);
|
7808 | }
|
7809 | }, {
|
7810 | key: 'toString',
|
7811 | value: function toString() {
|
7812 | return `$Shape<${ this.type.toString() }>`;
|
7813 | }
|
7814 | }, {
|
7815 | key: 'toJSON',
|
7816 | value: function toJSON() {
|
7817 | return {
|
7818 | typeName: this.typeName,
|
7819 | type: this.type
|
7820 | };
|
7821 | }
|
7822 | }]);
|
7823 | return $ShapeType;
|
7824 | }(Type);
|
7825 |
|
7826 |
|
7827 |
|
7828 | var $SubType = function (_Type) {
|
7829 | inherits($SubType, _Type);
|
7830 |
|
7831 | function $SubType() {
|
7832 | var _ref;
|
7833 |
|
7834 | var _temp, _this, _ret;
|
7835 |
|
7836 | classCallCheck(this, $SubType);
|
7837 |
|
7838 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7839 | args[_key] = arguments[_key];
|
7840 | }
|
7841 |
|
7842 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $SubType.__proto__ || Object.getPrototypeOf($SubType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$SubType', _temp), possibleConstructorReturn(_this, _ret);
|
7843 | }
|
7844 |
|
7845 | createClass($SubType, [{
|
7846 | key: 'errors',
|
7847 | value: function* errors(validation, path, input) {
|
7848 | yield* this.type.errors(input, path);
|
7849 | }
|
7850 | }, {
|
7851 | key: 'accepts',
|
7852 | value: function accepts(input) {
|
7853 | return this.type.accepts(input);
|
7854 | }
|
7855 | }, {
|
7856 | key: 'compareWith',
|
7857 | value: function compareWith(input) {
|
7858 | return compareTypes(this.unwrap(), input);
|
7859 | }
|
7860 | }, {
|
7861 | key: 'unwrap',
|
7862 | value: function unwrap() {
|
7863 | return this.type;
|
7864 | }
|
7865 | }, {
|
7866 | key: 'toString',
|
7867 | value: function toString() {
|
7868 | return `$Subtype<${ this.type.toString() }>`;
|
7869 | }
|
7870 | }, {
|
7871 | key: 'toJSON',
|
7872 | value: function toJSON() {
|
7873 | return {
|
7874 | typeName: this.typeName,
|
7875 | type: this.type
|
7876 | };
|
7877 | }
|
7878 | }]);
|
7879 | return $SubType;
|
7880 | }(Type);
|
7881 |
|
7882 |
|
7883 |
|
7884 | var $SuperType = function (_Type) {
|
7885 | inherits($SuperType, _Type);
|
7886 |
|
7887 | function $SuperType() {
|
7888 | var _ref;
|
7889 |
|
7890 | var _temp, _this, _ret;
|
7891 |
|
7892 | classCallCheck(this, $SuperType);
|
7893 |
|
7894 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7895 | args[_key] = arguments[_key];
|
7896 | }
|
7897 |
|
7898 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $SuperType.__proto__ || Object.getPrototypeOf($SuperType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$SuperType', _temp), possibleConstructorReturn(_this, _ret);
|
7899 | }
|
7900 |
|
7901 | createClass($SuperType, [{
|
7902 | key: 'errors',
|
7903 | value: function* errors(validation, path, input) {
|
7904 | yield* this.type.errors(validation, path, input);
|
7905 | }
|
7906 | }, {
|
7907 | key: 'accepts',
|
7908 | value: function accepts(input) {
|
7909 | return this.type.accepts(input);
|
7910 | }
|
7911 | }, {
|
7912 | key: 'compareWith',
|
7913 | value: function compareWith(input) {
|
7914 | return compareTypes(this.unwrap(), input);
|
7915 | }
|
7916 | }, {
|
7917 | key: 'unwrap',
|
7918 | value: function unwrap() {
|
7919 | return this.type;
|
7920 | }
|
7921 | }, {
|
7922 | key: 'toString',
|
7923 | value: function toString() {
|
7924 | return `$Supertype<${ this.type.toString() }>`;
|
7925 | }
|
7926 | }, {
|
7927 | key: 'toJSON',
|
7928 | value: function toJSON() {
|
7929 | return {
|
7930 | typeName: this.typeName,
|
7931 | type: this.type
|
7932 | };
|
7933 | }
|
7934 | }]);
|
7935 | return $SuperType;
|
7936 | }(Type);
|
7937 |
|
7938 |
|
7939 |
|
7940 | var $TupleMapType = function (_Type) {
|
7941 | inherits($TupleMapType, _Type);
|
7942 |
|
7943 | function $TupleMapType() {
|
7944 | var _ref;
|
7945 |
|
7946 | var _temp, _this, _ret;
|
7947 |
|
7948 | classCallCheck(this, $TupleMapType);
|
7949 |
|
7950 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
7951 | args[_key] = arguments[_key];
|
7952 | }
|
7953 |
|
7954 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = $TupleMapType.__proto__ || Object.getPrototypeOf($TupleMapType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = '$TupleMapType', _temp), possibleConstructorReturn(_this, _ret);
|
7955 | }
|
7956 |
|
7957 | createClass($TupleMapType, [{
|
7958 | key: 'errors',
|
7959 | value: function* errors(validation, path, input) {
|
7960 | var tuple = this.tuple,
|
7961 | mapper = this.mapper,
|
7962 | context = this.context;
|
7963 |
|
7964 | var target = tuple.unwrap();
|
7965 | invariant(target instanceof TupleType, 'Target must be a tuple type.');
|
7966 |
|
7967 | if (!context.checkPredicate('Array', input)) {
|
7968 | yield [path, getErrorMessage('ERR_EXPECT_ARRAY'), this];
|
7969 | return;
|
7970 | }
|
7971 |
|
7972 | for (var i = 0; i < target.types.length; i++) {
|
7973 | var type = target.types[i];
|
7974 | var applied = mapper.unwrap();
|
7975 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
7976 |
|
7977 | var expected = applied.invoke(type);
|
7978 | var value = input[i];
|
7979 | yield* expected.errors(validation, path.concat(i), value);
|
7980 | }
|
7981 | }
|
7982 | }, {
|
7983 | key: 'accepts',
|
7984 | value: function accepts(input) {
|
7985 | var tuple = this.tuple,
|
7986 | mapper = this.mapper,
|
7987 | context = this.context;
|
7988 |
|
7989 | var target = tuple.unwrap();
|
7990 | invariant(target instanceof TupleType, 'Target must be a tuple type.');
|
7991 |
|
7992 | if (!context.checkPredicate('Array', input)) {
|
7993 | return false;
|
7994 | }
|
7995 |
|
7996 | for (var i = 0; i < target.types.length; i++) {
|
7997 | var type = target.types[i];
|
7998 | var applied = mapper.unwrap();
|
7999 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
8000 |
|
8001 | if (!applied.invoke(type).accepts(input[i])) {
|
8002 | return false;
|
8003 | }
|
8004 | }
|
8005 | return true;
|
8006 | }
|
8007 | }, {
|
8008 | key: 'compareWith',
|
8009 | value: function compareWith(input) {
|
8010 | return compareTypes(this.unwrap(), input);
|
8011 | }
|
8012 | }, {
|
8013 | key: 'unwrap',
|
8014 | value: function unwrap() {
|
8015 | var tuple = this.tuple,
|
8016 | mapper = this.mapper,
|
8017 | context = this.context;
|
8018 |
|
8019 | var target = tuple.unwrap();
|
8020 | invariant(target instanceof TupleType, 'Target must be an tuple type.');
|
8021 |
|
8022 | var args = [];
|
8023 | for (var i = 0; i < target.types.length; i++) {
|
8024 | var type = target.types[i];
|
8025 | var applied = mapper.unwrap();
|
8026 | invariant(applied instanceof FunctionType, 'Mapper must be a function type.');
|
8027 |
|
8028 | args.push(applied.invoke(type).unwrap().unwrap());
|
8029 | }
|
8030 |
|
8031 | return context.tuple.apply(context, args);
|
8032 | }
|
8033 | }, {
|
8034 | key: 'toString',
|
8035 | value: function toString() {
|
8036 | return `$TupleMap<${ this.tuple.toString() }, ${ this.mapper.toString() }>`;
|
8037 | }
|
8038 | }, {
|
8039 | key: 'toJSON',
|
8040 | value: function toJSON() {
|
8041 | return {
|
8042 | typeName: this.typeName,
|
8043 | tuple: this.tuple,
|
8044 | mapper: this.mapper
|
8045 | };
|
8046 | }
|
8047 | }]);
|
8048 | return $TupleMapType;
|
8049 | }(Type);
|
8050 |
|
8051 | function checkGenericType(context, expected, input) {
|
8052 | var impl = expected.impl;
|
8053 |
|
8054 | if (typeof impl !== 'function') {
|
8055 |
|
8056 | return true;
|
8057 | } else if (impl === input || impl.isPrototypeOf(input)) {
|
8058 | return true;
|
8059 | }
|
8060 |
|
8061 | var annotation = context.getAnnotation(impl);
|
8062 | if (annotation == null) {
|
8063 | return false;
|
8064 | } else {
|
8065 | return checkType(context, annotation, input);
|
8066 | }
|
8067 | }
|
8068 |
|
8069 | function checkType(context, expected, input) {
|
8070 | var annotation = context.getAnnotation(input);
|
8071 | if (annotation != null) {
|
8072 | var result = compareTypes(expected, annotation);
|
8073 | return result !== -1;
|
8074 | }
|
8075 | return true;
|
8076 | }
|
8077 |
|
8078 | var ClassType = function (_Type) {
|
8079 | inherits(ClassType, _Type);
|
8080 |
|
8081 | function ClassType() {
|
8082 | var _ref;
|
8083 |
|
8084 | var _temp, _this, _ret;
|
8085 |
|
8086 | classCallCheck(this, ClassType);
|
8087 |
|
8088 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
8089 | args[_key] = arguments[_key];
|
8090 | }
|
8091 |
|
8092 | return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ClassType.__proto__ || Object.getPrototypeOf(ClassType)).call.apply(_ref, [this].concat(args))), _this), _this.typeName = 'ClassType', _temp), possibleConstructorReturn(_this, _ret);
|
8093 | }
|
8094 |
|
8095 | createClass(ClassType, [{
|
8096 | key: 'errors',
|
8097 | value: function* errors(validation, path, input) {
|
8098 | var instanceType = this.instanceType,
|
8099 | context = this.context;
|
8100 |
|
8101 | if (typeof input !== 'function') {
|
8102 | yield [path, getErrorMessage('ERR_EXPECT_CLASS', instanceType.toString()), this];
|
8103 | return;
|
8104 | }
|
8105 | var expectedType = instanceType.typeName === 'ClassDeclaration' ? instanceType : instanceType.unwrap();
|
8106 | var isValid = expectedType instanceof GenericType ? checkGenericType(context, expectedType, input) : checkType(context, expectedType, input);
|
8107 | if (!isValid) {
|
8108 | yield [path, getErrorMessage('ERR_EXPECT_CLASS', instanceType.toString()), this];
|
8109 | }
|
8110 | }
|
8111 | }, {
|
8112 | key: 'accepts',
|
8113 | value: function accepts(input) {
|
8114 | var instanceType = this.instanceType,
|
8115 | context = this.context;
|
8116 |
|
8117 | if (typeof input !== 'function') {
|
8118 | return false;
|
8119 | }
|
8120 | var expectedType = instanceType.typeName === 'ClassDeclaration' ? instanceType : instanceType.unwrap();
|
8121 | if (expectedType instanceof GenericType) {
|
8122 | return checkGenericType(context, expectedType, input);
|
8123 | } else {
|
8124 | return checkType(context, expectedType, input);
|
8125 | }
|
8126 | }
|
8127 | }, {
|
8128 | key: 'compareWith',
|
8129 | value: function compareWith(input) {
|
8130 | var instanceType = this.instanceType;
|
8131 |
|
8132 | if (input instanceof ClassType) {
|
8133 | return compareTypes(instanceType, input.instanceType);
|
8134 | }
|
8135 | return -1;
|
8136 | }
|
8137 | }, {
|
8138 | key: 'toString',
|
8139 | value: function toString() {
|
8140 | return `Class<${ this.instanceType.toString() }>`;
|
8141 | }
|
8142 | }, {
|
8143 | key: 'toJSON',
|
8144 | value: function toJSON() {
|
8145 | return {
|
8146 | typeName: this.typeName,
|
8147 | instanceType: this.instanceType
|
8148 | };
|
8149 | }
|
8150 | }]);
|
8151 | return ClassType;
|
8152 | }(Type);
|
8153 |
|
8154 |
|
8155 |
|
8156 |
|
8157 |
|
8158 | var warnedInvalidReferences = new WeakSet();
|
8159 |
|
8160 | var TypeContext = function () {
|
8161 | function TypeContext() {
|
8162 | classCallCheck(this, TypeContext);
|
8163 | this.mode = 'assert';
|
8164 | this[NameRegistrySymbol] = {};
|
8165 | this[TypePredicateRegistrySymbol] = {};
|
8166 | this[TypeConstructorRegistrySymbol] = new Map();
|
8167 | this[InferrerSymbol] = new TypeInferer(this);
|
8168 | this[ModuleRegistrySymbol] = {};
|
8169 | }
|
8170 |
|
8171 | |
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 |
|
8180 |
|
8181 |
|
8182 |
|
8183 |
|
8184 |
|
8185 |
|
8186 |
|
8187 |
|
8188 |
|
8189 |
|
8190 |
|
8191 |
|
8192 |
|
8193 |
|
8194 |
|
8195 | createClass(TypeContext, [{
|
8196 | key: 'makeJSONError',
|
8197 | value: function makeJSONError$$1(validation) {
|
8198 | return makeJSONError(validation);
|
8199 | }
|
8200 | }, {
|
8201 | key: 'makeTypeError',
|
8202 | value: function makeTypeError$$1(validation) {
|
8203 | return makeTypeError(validation);
|
8204 | }
|
8205 | }, {
|
8206 | key: 'createContext',
|
8207 | value: function createContext() {
|
8208 | var context = new TypeContext();
|
8209 |
|
8210 | context[ParentSymbol] = this;
|
8211 | return context;
|
8212 | }
|
8213 | }, {
|
8214 | key: 'typeOf',
|
8215 | value: function typeOf(input) {
|
8216 |
|
8217 | var annotation = this.getAnnotation(input);
|
8218 | if (annotation) {
|
8219 | if (typeof input === 'function' && (annotation instanceof ClassDeclaration || annotation instanceof ParameterizedClassDeclaration)) {
|
8220 | return this.Class(annotation);
|
8221 | }
|
8222 | return annotation;
|
8223 | }
|
8224 |
|
8225 | var inferrer = this[InferrerSymbol];
|
8226 | inferrer;
|
8227 |
|
8228 | return inferrer.infer(input);
|
8229 | }
|
8230 | }, {
|
8231 | key: 'compareTypes',
|
8232 | value: function compareTypes$$1(a, b) {
|
8233 | return compareTypes(a, b);
|
8234 | }
|
8235 | }, {
|
8236 | key: 'get',
|
8237 | value: function get$$1(name) {
|
8238 |
|
8239 | var item = this[NameRegistrySymbol][name];
|
8240 |
|
8241 | for (var _len = arguments.length, propertyNames = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
8242 | propertyNames[_key - 1] = arguments[_key];
|
8243 | }
|
8244 |
|
8245 | if (item != null) {
|
8246 | var current = typeof item === 'function' ? new item(this) : item;
|
8247 | for (var i = 0; i < propertyNames.length; i++) {
|
8248 | var propertyName = propertyNames[i];
|
8249 | if (typeof current.getProperty !== 'function') {
|
8250 | return;
|
8251 | }
|
8252 | current = current.getProperty(propertyName);
|
8253 | if (!current) {
|
8254 | return;
|
8255 | }
|
8256 | current = current.unwrap();
|
8257 | }
|
8258 | return current;
|
8259 | }
|
8260 |
|
8261 | var parent = this[ParentSymbol];
|
8262 | if (parent) {
|
8263 | var fromParent = parent.get.apply(parent, [name].concat(toConsumableArray(propertyNames)));
|
8264 | if (fromParent) {
|
8265 | return fromParent;
|
8266 | }
|
8267 | }
|
8268 |
|
8269 |
|
8270 | if (typeof global[name] === 'function') {
|
8271 | var target = new GenericType(this);
|
8272 | target.name = name;
|
8273 | target.impl = global[name];
|
8274 |
|
8275 | this[NameRegistrySymbol][name] = target;
|
8276 | return target;
|
8277 | }
|
8278 | }
|
8279 |
|
8280 | |
8281 |
|
8282 |
|
8283 |
|
8284 |
|
8285 | }, {
|
8286 | key: 'getPredicate',
|
8287 | value: function getPredicate(name) {
|
8288 | var item = this[TypePredicateRegistrySymbol][name];
|
8289 | if (item) {
|
8290 | return item;
|
8291 | }
|
8292 | var parent = this[ParentSymbol];
|
8293 | if (parent) {
|
8294 | return parent.getPredicate(name);
|
8295 | }
|
8296 | }
|
8297 |
|
8298 | |
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 |
|
8304 | }, {
|
8305 | key: 'setPredicate',
|
8306 | value: function setPredicate(name, predicate) {
|
8307 | this[TypePredicateRegistrySymbol][name] = predicate;
|
8308 | }
|
8309 |
|
8310 | |
8311 |
|
8312 |
|
8313 |
|
8314 |
|
8315 |
|
8316 | }, {
|
8317 | key: 'checkPredicate',
|
8318 | value: function checkPredicate(name, input) {
|
8319 | var predicate = this.getPredicate(name);
|
8320 | if (predicate) {
|
8321 | return predicate(input);
|
8322 | } else {
|
8323 | return false;
|
8324 | }
|
8325 | }
|
8326 |
|
8327 | |
8328 |
|
8329 |
|
8330 |
|
8331 | }, {
|
8332 | key: 'decorate',
|
8333 | value: function decorate(type, shouldAssert) {
|
8334 | var _this2 = this;
|
8335 |
|
8336 | if (shouldAssert == null) {
|
8337 | shouldAssert = this.mode === 'assert';
|
8338 | }
|
8339 | return function (input, propertyName, descriptor) {
|
8340 | if (descriptor && typeof propertyName === 'string') {
|
8341 | return makePropertyDescriptor(type, input, propertyName, descriptor, Boolean(shouldAssert));
|
8342 | } else {
|
8343 | invariant(typeof type !== 'function', 'Cannot decorate an object or function as a method.');
|
8344 | return _this2.annotate(input, type);
|
8345 | }
|
8346 | };
|
8347 | }
|
8348 |
|
8349 | |
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 | }, {
|
8356 | key: 'annotate',
|
8357 | value: function annotate(input, type) {
|
8358 | if (type === undefined) {
|
8359 | return annotateValue(input);
|
8360 | } else {
|
8361 | return annotateValue(input, type);
|
8362 | }
|
8363 | }
|
8364 | }, {
|
8365 | key: 'getAnnotation',
|
8366 | value: function getAnnotation(input) {
|
8367 | if (input !== null && typeof input === 'object' || typeof input === 'function') {
|
8368 |
|
8369 | return input[TypeSymbol];
|
8370 | }
|
8371 | }
|
8372 | }, {
|
8373 | key: 'hasAnnotation',
|
8374 | value: function hasAnnotation(input) {
|
8375 | if (input == null) {
|
8376 | return false;
|
8377 | } else {
|
8378 | return input[TypeSymbol] ? true : false;
|
8379 | }
|
8380 | }
|
8381 | }, {
|
8382 | key: 'setAnnotation',
|
8383 | value: function setAnnotation(input, type) {
|
8384 | input[TypeSymbol] = type;
|
8385 | return input;
|
8386 | }
|
8387 | }, {
|
8388 | key: 'type',
|
8389 | value: function type(name, _type) {
|
8390 | if (typeof _type === 'function') {
|
8391 | var target = new ParameterizedTypeAlias(this);
|
8392 | target.name = name;
|
8393 | target.typeCreator = _type;
|
8394 | return target;
|
8395 | } else {
|
8396 | var _target = new TypeAlias(this);
|
8397 | _target.name = name;
|
8398 | _target.type = _type;
|
8399 | return _target;
|
8400 | }
|
8401 | }
|
8402 | }, {
|
8403 | key: 'declare',
|
8404 | value: function declare(name, type) {
|
8405 |
|
8406 | if (name instanceof Declaration) {
|
8407 | type = name;
|
8408 | name = type.name;
|
8409 | } else if (name instanceof TypeAlias) {
|
8410 | type = name;
|
8411 | name = type.name;
|
8412 | }
|
8413 | if (typeof type === 'function') {
|
8414 | type = this.type(name, type);
|
8415 | }
|
8416 | if (type instanceof ModuleDeclaration) {
|
8417 | var moduleRegistry = this[ModuleRegistrySymbol];
|
8418 | moduleRegistry[name] = type;
|
8419 | return type;
|
8420 | } else {
|
8421 | invariant(typeof name === 'string', 'Name must be a string');
|
8422 | invariant(type instanceof Type, 'Type must be supplied to declaration');
|
8423 | var nameRegistry = this[NameRegistrySymbol];
|
8424 |
|
8425 | if (type instanceof Declaration) {
|
8426 | nameRegistry[name] = type;
|
8427 | return type;
|
8428 | } else if (type instanceof TypeAlias || type instanceof ParameterizedTypeAlias) {
|
8429 | var target = new TypeDeclaration(this);
|
8430 | target.name = name;
|
8431 | target.typeAlias = type;
|
8432 | nameRegistry[name] = target;
|
8433 | return target;
|
8434 | } else {
|
8435 | var _target2 = this.var(name, type);
|
8436 | nameRegistry[name] = _target2;
|
8437 | return _target2;
|
8438 | }
|
8439 | }
|
8440 | }
|
8441 | }, {
|
8442 | key: 'declarations',
|
8443 | value: function* declarations() {
|
8444 | var nameRegistry = this[NameRegistrySymbol];
|
8445 | for (var key in nameRegistry) {
|
8446 |
|
8447 | yield [key, nameRegistry[key]];
|
8448 | }
|
8449 | }
|
8450 | }, {
|
8451 | key: 'modules',
|
8452 | value: function* modules() {
|
8453 | var moduleRegistry = this[ModuleRegistrySymbol];
|
8454 | for (var key in moduleRegistry) {
|
8455 |
|
8456 | yield moduleRegistry[key];
|
8457 | }
|
8458 | }
|
8459 | }, {
|
8460 | key: 'import',
|
8461 | value: function _import(moduleName) {
|
8462 | var moduleRegistry = this[ModuleRegistrySymbol];
|
8463 | if (moduleRegistry[moduleName]) {
|
8464 | return moduleRegistry[moduleName];
|
8465 | }
|
8466 |
|
8467 | var _moduleName$split = moduleName.split('/'),
|
8468 | _moduleName$split2 = slicedToArray(_moduleName$split, 1),
|
8469 | head = _moduleName$split2[0];
|
8470 |
|
8471 | var module = moduleRegistry[head];
|
8472 | if (module) {
|
8473 | return module.import(moduleName);
|
8474 | }
|
8475 | var parent = this[ParentSymbol];
|
8476 | if (parent) {
|
8477 | return parent.import(moduleName);
|
8478 | }
|
8479 | }
|
8480 | }, {
|
8481 | key: 'declareTypeConstructor',
|
8482 | value: function declareTypeConstructor(_ref) {
|
8483 | var name = _ref.name,
|
8484 | impl = _ref.impl,
|
8485 | typeName = _ref.typeName,
|
8486 | errors = _ref.errors,
|
8487 | accepts = _ref.accepts,
|
8488 | inferTypeParameters = _ref.inferTypeParameters;
|
8489 |
|
8490 | var nameRegistry = this[NameRegistrySymbol];
|
8491 |
|
8492 | if (nameRegistry[name]) {
|
8493 | this.emitWarningMessage(`Redeclaring type: ${ name }, this may be unintended.`);
|
8494 | }
|
8495 |
|
8496 | var target = new TypeConstructor(this);
|
8497 | target.name = name;
|
8498 | target.typeName = typeName;
|
8499 | target.impl = impl;
|
8500 | target.errors = errors;
|
8501 | target.accepts = accepts;
|
8502 | target.inferTypeParameters = inferTypeParameters;
|
8503 |
|
8504 | nameRegistry[name] = target;
|
8505 |
|
8506 | if (typeof impl === 'function') {
|
8507 |
|
8508 | var handlerRegistry = this[TypeConstructorRegistrySymbol];
|
8509 | handlerRegistry;
|
8510 |
|
8511 | if (handlerRegistry.has(impl)) {
|
8512 | this.emitWarningMessage(`A type handler already exists for the given implementation of ${ name }.`);
|
8513 | }
|
8514 | handlerRegistry.set(impl, target);
|
8515 | }
|
8516 | return target;
|
8517 | }
|
8518 | }, {
|
8519 | key: 'getTypeConstructor',
|
8520 | value: function getTypeConstructor(impl) {
|
8521 |
|
8522 | var handlerRegistry = this[TypeConstructorRegistrySymbol];
|
8523 | handlerRegistry;
|
8524 |
|
8525 | return handlerRegistry.get(impl);
|
8526 | }
|
8527 | }, {
|
8528 | key: 'literal',
|
8529 | value: function literal(input) {
|
8530 | if (input === undefined) {
|
8531 | return this.void();
|
8532 | } else if (input === null) {
|
8533 | return this.null();
|
8534 | } else if (typeof input === 'boolean') {
|
8535 | return this.boolean(input);
|
8536 | } else if (typeof input === 'number') {
|
8537 | return this.number(input);
|
8538 | } else if (typeof input === 'string') {
|
8539 | return this.string(input);
|
8540 | }
|
8541 |
|
8542 | else if (typeof input === 'symbol') {
|
8543 | return this.symbol(input);
|
8544 | } else {
|
8545 | return this.typeOf(input);
|
8546 | }
|
8547 | }
|
8548 | }, {
|
8549 | key: 'null',
|
8550 | value: function _null() {
|
8551 | return primitiveTypes.null;
|
8552 | }
|
8553 | }, {
|
8554 | key: 'nullable',
|
8555 | value: function nullable(type) {
|
8556 | var target = new NullableType(this);
|
8557 | target.type = type;
|
8558 | return target;
|
8559 | }
|
8560 | }, {
|
8561 | key: 'existential',
|
8562 | value: function existential() {
|
8563 | return primitiveTypes.existential;
|
8564 | }
|
8565 | }, {
|
8566 | key: 'empty',
|
8567 | value: function empty() {
|
8568 | return primitiveTypes.empty;
|
8569 | }
|
8570 | }, {
|
8571 | key: 'any',
|
8572 | value: function any() {
|
8573 | return primitiveTypes.any;
|
8574 | }
|
8575 | }, {
|
8576 | key: 'mixed',
|
8577 | value: function mixed() {
|
8578 | return primitiveTypes.mixed;
|
8579 | }
|
8580 | }, {
|
8581 | key: 'void',
|
8582 | value: function _void() {
|
8583 | return primitiveTypes.void;
|
8584 | }
|
8585 | }, {
|
8586 | key: 'this',
|
8587 | value: function _this(input) {
|
8588 | var target = new ThisType(this);
|
8589 | if (input !== undefined) {
|
8590 | target.recorded = input;
|
8591 | }
|
8592 | return target;
|
8593 | }
|
8594 | }, {
|
8595 | key: 'number',
|
8596 | value: function number(input) {
|
8597 | if (input !== undefined) {
|
8598 | var target = new NumericLiteralType(this);
|
8599 | target.value = input;
|
8600 | return target;
|
8601 | } else {
|
8602 | return primitiveTypes.number;
|
8603 | }
|
8604 | }
|
8605 | }, {
|
8606 | key: 'boolean',
|
8607 | value: function boolean(input) {
|
8608 | if (input !== undefined) {
|
8609 | var target = new BooleanLiteralType(this);
|
8610 | target.value = input;
|
8611 | return target;
|
8612 | } else {
|
8613 | return primitiveTypes.boolean;
|
8614 | }
|
8615 | }
|
8616 | }, {
|
8617 | key: 'string',
|
8618 | value: function string(input) {
|
8619 | if (input !== undefined) {
|
8620 | var target = new StringLiteralType(this);
|
8621 | target.value = input;
|
8622 | return target;
|
8623 | } else {
|
8624 | return primitiveTypes.string;
|
8625 | }
|
8626 | }
|
8627 | }, {
|
8628 | key: 'symbol',
|
8629 | value: function symbol(input) {
|
8630 | if (input !== undefined) {
|
8631 | var target = new SymbolLiteralType(this);
|
8632 | target.value = input;
|
8633 | return target;
|
8634 | } else {
|
8635 | return primitiveTypes.symbol;
|
8636 | }
|
8637 | }
|
8638 | }, {
|
8639 | key: 'typeParameter',
|
8640 | value: function typeParameter(id, bound, defaultType) {
|
8641 | var target = new TypeParameter(this);
|
8642 | target.id = id;
|
8643 | target.bound = bound;
|
8644 | target.default = defaultType;
|
8645 | return target;
|
8646 | }
|
8647 | }, {
|
8648 | key: 'flowInto',
|
8649 | value: function flowInto(typeParameter) {
|
8650 | return flowIntoTypeParameter(typeParameter);
|
8651 | }
|
8652 |
|
8653 | |
8654 |
|
8655 |
|
8656 |
|
8657 | }, {
|
8658 | key: 'bindTypeParameters',
|
8659 | value: function bindTypeParameters(subject) {
|
8660 | var instancePrototype = Object.getPrototypeOf(subject);
|
8661 |
|
8662 | var parentPrototype = instancePrototype && Object.getPrototypeOf(instancePrototype);
|
8663 |
|
8664 | var parentClass = parentPrototype && parentPrototype.constructor;
|
8665 |
|
8666 | if (!parentClass) {
|
8667 | this.emitWarningMessage('Could not bind type parameters for non-existent parent class.');
|
8668 | return subject;
|
8669 | }
|
8670 |
|
8671 | var typeParametersPointer = parentClass[TypeParametersSymbol];
|
8672 |
|
8673 | if (typeParametersPointer) {
|
8674 | var typeParameters = subject[typeParametersPointer];
|
8675 | var keys = Object.keys(typeParameters);
|
8676 |
|
8677 | for (var _len2 = arguments.length, typeInstances = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
8678 | typeInstances[_key2 - 1] = arguments[_key2];
|
8679 | }
|
8680 |
|
8681 | var length = Math.min(keys.length, typeInstances.length);
|
8682 | for (var i = 0; i < length; i++) {
|
8683 | var typeParam = typeParameters[keys[i]];
|
8684 | typeParam.bound = typeInstances[i];
|
8685 | }
|
8686 | }
|
8687 | return subject;
|
8688 | }
|
8689 | }, {
|
8690 | key: 'module',
|
8691 | value: function module(name, body) {
|
8692 | var target = new ModuleDeclaration(this);
|
8693 | target.name = name;
|
8694 | var innerContext = this.createContext();
|
8695 |
|
8696 | innerContext[ParentSymbol] = this;
|
8697 |
|
8698 | innerContext[CurrentModuleSymbol] = target;
|
8699 |
|
8700 | target.innerContext = innerContext;
|
8701 | body(innerContext);
|
8702 | return target;
|
8703 | }
|
8704 | }, {
|
8705 | key: 'moduleExports',
|
8706 | value: function moduleExports(type) {
|
8707 | var currentModule = this[CurrentModuleSymbol];
|
8708 | if (!currentModule) {
|
8709 | throw new Error('Cannot declare module.exports outside of a module.');
|
8710 | }
|
8711 | var target = new ModuleExports(this);
|
8712 | target.type = type;
|
8713 | currentModule.moduleExports = target;
|
8714 | return target;
|
8715 | }
|
8716 | }, {
|
8717 | key: 'var',
|
8718 | value: function _var(name, type) {
|
8719 | var target = new VarDeclaration(this);
|
8720 | target.name = name;
|
8721 | target.type = type;
|
8722 | return target;
|
8723 | }
|
8724 | }, {
|
8725 | key: 'class',
|
8726 | value: function _class(name, head) {
|
8727 | if (typeof head === 'function') {
|
8728 | var _target3 = new ParameterizedClassDeclaration(this);
|
8729 | _target3.name = name;
|
8730 | _target3.bodyCreator = head;
|
8731 | return _target3;
|
8732 | }
|
8733 | var target = new ClassDeclaration(this);
|
8734 | target.name = name;
|
8735 |
|
8736 | for (var _len3 = arguments.length, tail = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
8737 | tail[_key3 - 2] = arguments[_key3];
|
8738 | }
|
8739 |
|
8740 | if (head != null) {
|
8741 | tail.unshift(head);
|
8742 | }
|
8743 | var length = tail.length;
|
8744 |
|
8745 | var properties = [];
|
8746 | var body = void 0;
|
8747 |
|
8748 | for (var i = 0; i < length; i++) {
|
8749 | var item = tail[i];
|
8750 | if (item instanceof ObjectTypeProperty || item instanceof ObjectTypeIndexer) {
|
8751 | properties.push(item);
|
8752 | } else if (item instanceof ObjectType) {
|
8753 | invariant(!body, 'Class body must only be declared once.');
|
8754 | body = item;
|
8755 | } else if (item instanceof ExtendsDeclaration) {
|
8756 | invariant(!target.superClass, 'Classes can only have one super class.');
|
8757 | target.superClass = item;
|
8758 | } else if (item != null && typeof item === 'object' && !(item instanceof Type)) {
|
8759 | for (var propertyName in item) {
|
8760 |
|
8761 | properties.push(this.property(propertyName, item[propertyName]));
|
8762 | }
|
8763 | } else {
|
8764 | throw new Error('ClassDeclaration cannot contain the given type directly.');
|
8765 | }
|
8766 | }
|
8767 | if (!body) {
|
8768 | body = new ObjectType(this);
|
8769 | }
|
8770 | if (properties.length) {
|
8771 | var _body$properties;
|
8772 |
|
8773 | (_body$properties = body.properties).push.apply(_body$properties, properties);
|
8774 | }
|
8775 | target.body = body;
|
8776 | return target;
|
8777 | }
|
8778 | }, {
|
8779 | key: 'extends',
|
8780 | value: function _extends(subject) {
|
8781 | var target = new ExtendsDeclaration(this);
|
8782 |
|
8783 | for (var _len4 = arguments.length, typeInstances = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
8784 | typeInstances[_key4 - 1] = arguments[_key4];
|
8785 | }
|
8786 |
|
8787 | target.type = this.ref.apply(this, [subject].concat(toConsumableArray(typeInstances)));
|
8788 | return target;
|
8789 | }
|
8790 | }, {
|
8791 | key: 'fn',
|
8792 | value: function fn(head) {
|
8793 | for (var _len5 = arguments.length, tail = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
8794 | tail[_key5 - 1] = arguments[_key5];
|
8795 | }
|
8796 |
|
8797 | return this.function.apply(this, [head].concat(tail));
|
8798 | }
|
8799 | }, {
|
8800 | key: 'function',
|
8801 | value: function _function(head) {
|
8802 | if (typeof head === 'function') {
|
8803 | var _target4 = new ParameterizedFunctionType(this);
|
8804 | _target4.bodyCreator = head;
|
8805 | return _target4;
|
8806 | }
|
8807 | var target = new FunctionType(this);
|
8808 | if (head != null) {
|
8809 | for (var _len6 = arguments.length, tail = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
8810 | tail[_key6 - 1] = arguments[_key6];
|
8811 | }
|
8812 |
|
8813 | tail.unshift(head);
|
8814 | var length = tail.length;
|
8815 |
|
8816 | for (var i = 0; i < length; i++) {
|
8817 | var item = tail[i];
|
8818 | if (item instanceof FunctionTypeParam) {
|
8819 | target.params.push(item);
|
8820 | } else if (item instanceof FunctionTypeRestParam) {
|
8821 | target.rest = item;
|
8822 | } else if (item instanceof FunctionTypeReturn) {
|
8823 | target.returnType = item;
|
8824 | } else {
|
8825 | throw new Error('FunctionType cannot contain the given type directly.');
|
8826 | }
|
8827 | }
|
8828 | }
|
8829 | if (!target.returnType) {
|
8830 | target.returnType = this.any();
|
8831 | }
|
8832 | return target;
|
8833 | }
|
8834 | }, {
|
8835 | key: 'param',
|
8836 | value: function param(name, type) {
|
8837 | var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
8838 |
|
8839 | var target = new FunctionTypeParam(this);
|
8840 | target.name = name;
|
8841 | target.type = type;
|
8842 | target.optional = optional;
|
8843 | return target;
|
8844 | }
|
8845 | }, {
|
8846 | key: 'rest',
|
8847 | value: function rest(name, type) {
|
8848 | var target = new FunctionTypeRestParam(this);
|
8849 | target.name = name;
|
8850 | target.type = type;
|
8851 | return target;
|
8852 | }
|
8853 | }, {
|
8854 | key: 'return',
|
8855 | value: function _return(type) {
|
8856 | var target = new FunctionTypeReturn(this);
|
8857 | target.type = type;
|
8858 | return target;
|
8859 | }
|
8860 | }, {
|
8861 | key: 'generator',
|
8862 | value: function generator(yieldType, returnType, nextType) {
|
8863 | var target = new GeneratorType(this);
|
8864 | target.yieldType = yieldType;
|
8865 | target.returnType = returnType || this.any();
|
8866 | target.nextType = nextType || this.any();
|
8867 | return target;
|
8868 | }
|
8869 | }, {
|
8870 | key: 'object',
|
8871 | value: function object(head) {
|
8872 | var target = new ObjectType(this);
|
8873 | if (head != null && typeof head === 'object' && !(head instanceof Type)) {
|
8874 | for (var propertyName in head) {
|
8875 |
|
8876 | target.properties.push(this.property(propertyName, head[propertyName]));
|
8877 | }
|
8878 | } else {
|
8879 | var body = void 0;
|
8880 |
|
8881 | for (var _len7 = arguments.length, tail = Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
|
8882 | tail[_key7 - 1] = arguments[_key7];
|
8883 | }
|
8884 |
|
8885 | if (head) {
|
8886 | body = [head].concat(toConsumableArray(tail));
|
8887 | } else {
|
8888 | body = tail;
|
8889 | }
|
8890 | var _body = body,
|
8891 | length = _body.length;
|
8892 |
|
8893 | for (var i = 0; i < length; i++) {
|
8894 | var item = body[i];
|
8895 | if (item instanceof ObjectTypeProperty) {
|
8896 | target.properties.push(item);
|
8897 | } else if (item instanceof ObjectTypeIndexer) {
|
8898 | target.indexers.push(item);
|
8899 | } else if (item instanceof ObjectTypeCallProperty) {
|
8900 | target.callProperties.push(item);
|
8901 | } else {
|
8902 | throw new Error('ObjectType cannot contain the given type directly.');
|
8903 | }
|
8904 | }
|
8905 | }
|
8906 | return target;
|
8907 | }
|
8908 | }, {
|
8909 | key: 'exactObject',
|
8910 | value: function exactObject(head) {
|
8911 | for (var _len8 = arguments.length, tail = Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
8912 | tail[_key8 - 1] = arguments[_key8];
|
8913 | }
|
8914 |
|
8915 | var object = this.object.apply(this, [head].concat(toConsumableArray(tail)));
|
8916 | object.exact = true;
|
8917 | return object;
|
8918 | }
|
8919 | }, {
|
8920 | key: 'callProperty',
|
8921 | value: function callProperty(value) {
|
8922 | var target = new ObjectTypeCallProperty(this);
|
8923 | target.value = value;
|
8924 | return target;
|
8925 | }
|
8926 | }, {
|
8927 | key: 'property',
|
8928 | value: function property(key, value) {
|
8929 | var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
8930 |
|
8931 | var target = new ObjectTypeProperty(this);
|
8932 | target.key = key;
|
8933 | if (value instanceof Type) {
|
8934 | target.value = value;
|
8935 | } else {
|
8936 | target.value = this.object(value);
|
8937 | }
|
8938 | target.optional = optional;
|
8939 | return target;
|
8940 | }
|
8941 | }, {
|
8942 | key: 'indexer',
|
8943 | value: function indexer(id, key, value) {
|
8944 | var target = new ObjectTypeIndexer(this);
|
8945 | target.id = id;
|
8946 | target.key = key;
|
8947 | target.value = value;
|
8948 | return target;
|
8949 | }
|
8950 | }, {
|
8951 | key: 'method',
|
8952 | value: function method(name, head) {
|
8953 | var target = new ObjectTypeProperty(this);
|
8954 | target.key = name;
|
8955 |
|
8956 | for (var _len9 = arguments.length, tail = Array(_len9 > 2 ? _len9 - 2 : 0), _key9 = 2; _key9 < _len9; _key9++) {
|
8957 | tail[_key9 - 2] = arguments[_key9];
|
8958 | }
|
8959 |
|
8960 | target.value = this.function.apply(this, [head].concat(tail));
|
8961 | return target;
|
8962 | }
|
8963 | }, {
|
8964 | key: 'staticCallProperty',
|
8965 | value: function staticCallProperty(value) {
|
8966 | var prop = this.callProperty(value);
|
8967 | prop.static = true;
|
8968 | return prop;
|
8969 | }
|
8970 | }, {
|
8971 | key: 'staticProperty',
|
8972 | value: function staticProperty(key, value) {
|
8973 | var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
8974 |
|
8975 | var prop = this.property(key, value, optional);
|
8976 | prop.static = true;
|
8977 | return prop;
|
8978 | }
|
8979 | }, {
|
8980 | key: 'staticMethod',
|
8981 | value: function staticMethod(name, head) {
|
8982 | for (var _len10 = arguments.length, tail = Array(_len10 > 2 ? _len10 - 2 : 0), _key10 = 2; _key10 < _len10; _key10++) {
|
8983 | tail[_key10 - 2] = arguments[_key10];
|
8984 | }
|
8985 |
|
8986 | var prop = this.method.apply(this, [name, head].concat(tail));
|
8987 | prop.static = true;
|
8988 | return prop;
|
8989 | }
|
8990 | }, {
|
8991 | key: 'tuple',
|
8992 | value: function tuple() {
|
8993 | var target = new TupleType(this);
|
8994 |
|
8995 | for (var _len11 = arguments.length, types = Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
8996 | types[_key11] = arguments[_key11];
|
8997 | }
|
8998 |
|
8999 | target.types = types;
|
9000 | return target;
|
9001 | }
|
9002 | }, {
|
9003 | key: 'array',
|
9004 | value: function array(elementType) {
|
9005 | var target = new ArrayType(this);
|
9006 | target.elementType = elementType || this.any();
|
9007 | return target;
|
9008 | }
|
9009 | }, {
|
9010 | key: 'union',
|
9011 | value: function union() {
|
9012 | for (var _len12 = arguments.length, types = Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
|
9013 | types[_key12] = arguments[_key12];
|
9014 | }
|
9015 |
|
9016 | return makeUnion(this, types);
|
9017 | }
|
9018 | }, {
|
9019 | key: 'intersect',
|
9020 | value: function intersect() {
|
9021 | var target = new IntersectionType(this);
|
9022 |
|
9023 | for (var _len13 = arguments.length, types = Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
|
9024 | types[_key13] = arguments[_key13];
|
9025 | }
|
9026 |
|
9027 | target.types = types;
|
9028 | return target;
|
9029 | }
|
9030 | }, {
|
9031 | key: 'intersection',
|
9032 | value: function intersection() {
|
9033 | return this.intersect.apply(this, arguments);
|
9034 | }
|
9035 | }, {
|
9036 | key: 'box',
|
9037 | value: function box(reveal) {
|
9038 | var box = new TypeBox(this);
|
9039 | box.reveal = reveal;
|
9040 | return box;
|
9041 | }
|
9042 | }, {
|
9043 | key: 'tdz',
|
9044 | value: function tdz(reveal, name) {
|
9045 | var tdz = new TypeTDZ(this);
|
9046 | tdz.reveal = reveal;
|
9047 | tdz.name = name;
|
9048 | return tdz;
|
9049 | }
|
9050 | }, {
|
9051 | key: 'ref',
|
9052 | value: function ref(subject) {
|
9053 | var target = void 0;
|
9054 | if (typeof subject === 'string') {
|
9055 |
|
9056 | target = this.get(subject);
|
9057 | if (!target) {
|
9058 |
|
9059 | target = new TypeReference(this);
|
9060 | target.name = subject;
|
9061 | }
|
9062 | } else if (typeof subject === 'function') {
|
9063 |
|
9064 | var handlerRegistry = this[TypeConstructorRegistrySymbol];
|
9065 | handlerRegistry;
|
9066 |
|
9067 |
|
9068 | target = handlerRegistry.get(subject);
|
9069 |
|
9070 | if (!target) {
|
9071 |
|
9072 | target = new GenericType(this);
|
9073 | target.impl = subject;
|
9074 | target.name = subject.name;
|
9075 | }
|
9076 | } else if (subject instanceof Type) {
|
9077 | target = subject;
|
9078 | } else {
|
9079 | if (subject == null || typeof subject !== 'object') {
|
9080 | this.emitWarningMessage(`Could not reference the given type, try t.typeOf(value) instead. (got ${ String(subject) })`);
|
9081 | } else if (!warnedInvalidReferences.has(subject)) {
|
9082 | this.emitWarningMessage('Could not reference the given type, try t.typeOf(value) instead.');
|
9083 | warnedInvalidReferences.add(subject);
|
9084 | }
|
9085 | return this.any();
|
9086 | }
|
9087 |
|
9088 | for (var _len14 = arguments.length, typeInstances = Array(_len14 > 1 ? _len14 - 1 : 0), _key14 = 1; _key14 < _len14; _key14++) {
|
9089 | typeInstances[_key14 - 1] = arguments[_key14];
|
9090 | }
|
9091 |
|
9092 | if (typeInstances.length) {
|
9093 | var _target5;
|
9094 |
|
9095 | invariant(typeof target.apply === 'function', `Cannot apply non-applicable type: ${ target.typeName }.`);
|
9096 | return (_target5 = target).apply.apply(_target5, toConsumableArray(typeInstances));
|
9097 | } else {
|
9098 | return target;
|
9099 | }
|
9100 | }
|
9101 | }, {
|
9102 | key: 'validate',
|
9103 | value: function validate(type, input) {
|
9104 | var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
9105 | var path = arguments[3];
|
9106 |
|
9107 | var validation = new Validation(this, input);
|
9108 | if (path) {
|
9109 | var _validation$path;
|
9110 |
|
9111 | (_validation$path = validation.path).push.apply(_validation$path, toConsumableArray(path));
|
9112 | } else if (typeof type.name === 'string') {
|
9113 | validation.path.push(type.name);
|
9114 | }
|
9115 | validation.prefix = prefix;
|
9116 | validation.errors = Array.from(type.errors(validation, [], input));
|
9117 | return validation;
|
9118 | }
|
9119 | }, {
|
9120 | key: 'check',
|
9121 | value: function check(type, input) {
|
9122 | var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
9123 | var path = arguments[3];
|
9124 |
|
9125 | if (this.mode === 'assert') {
|
9126 | return this.assert(type, input, prefix, path);
|
9127 | } else {
|
9128 | return this.warn(type, input, prefix, path);
|
9129 | }
|
9130 | }
|
9131 | }, {
|
9132 | key: 'assert',
|
9133 | value: function assert(type, input) {
|
9134 | var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
9135 | var path = arguments[3];
|
9136 |
|
9137 | var validation = this.validate(type, input, prefix, path);
|
9138 | var error = this.makeTypeError(validation);
|
9139 | if (error) {
|
9140 | throw error;
|
9141 | }
|
9142 | return input;
|
9143 | }
|
9144 | }, {
|
9145 | key: 'warn',
|
9146 | value: function warn(type, input) {
|
9147 | var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
9148 | var path = arguments[3];
|
9149 |
|
9150 | var validation = this.validate(type, input, prefix, path);
|
9151 | var message = makeWarningMessage(validation);
|
9152 | if (typeof message === 'string') {
|
9153 | this.emitWarningMessage(message);
|
9154 | }
|
9155 | return input;
|
9156 | }
|
9157 |
|
9158 | |
9159 |
|
9160 |
|
9161 |
|
9162 | }, {
|
9163 | key: 'emitWarningMessage',
|
9164 | value: function emitWarningMessage(message) {
|
9165 | console.warn('flow-runtime:', message);
|
9166 | }
|
9167 | }, {
|
9168 | key: 'propTypes',
|
9169 | value: function propTypes(type) {
|
9170 | return makeReactPropTypes(type.unwrap());
|
9171 | }
|
9172 | }, {
|
9173 | key: 'match',
|
9174 | value: function match() {
|
9175 | for (var _len15 = arguments.length, args = Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
|
9176 | args[_key15] = arguments[_key15];
|
9177 | }
|
9178 |
|
9179 | var clauses = args.pop();
|
9180 | if (!Array.isArray(clauses)) {
|
9181 | throw new Error('Invalid pattern, last argument must be an array.');
|
9182 | }
|
9183 | clauses;
|
9184 | var pattern = this.pattern.apply(this, toConsumableArray(clauses));
|
9185 | return pattern.apply(undefined, args);
|
9186 | }
|
9187 | }, {
|
9188 | key: 'pattern',
|
9189 | value: function pattern() {
|
9190 | for (var _len16 = arguments.length, clauses = Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
|
9191 | clauses[_key16] = arguments[_key16];
|
9192 | }
|
9193 |
|
9194 | var length = clauses.length;
|
9195 |
|
9196 | var tests = new Array(length);
|
9197 | for (var i = 0; i < length; i++) {
|
9198 | var clause = clauses[i];
|
9199 | var annotation = this.getAnnotation(clause);
|
9200 | if (!annotation) {
|
9201 | if (i !== length - 1) {
|
9202 | throw new Error(`Invalid Pattern - found unannotated function in position ${ i }, default clauses must be last.`);
|
9203 | }
|
9204 | tests[i] = true;
|
9205 | } else {
|
9206 | invariant(annotation instanceof FunctionType || annotation instanceof ParameterizedFunctionType, 'Pattern clauses must be annotated functions.');
|
9207 | tests[i] = annotation;
|
9208 | }
|
9209 | }
|
9210 | return function () {
|
9211 | for (var _i = 0; _i < tests.length; _i++) {
|
9212 | var test = tests[_i];
|
9213 | var _clause = clauses[_i];
|
9214 | if (test === true) {
|
9215 | return _clause.apply(undefined, arguments);
|
9216 | } else if (test.acceptsParams.apply(test, arguments)) {
|
9217 | return _clause.apply(undefined, arguments);
|
9218 | }
|
9219 | }
|
9220 | var error = new TypeError('Value did not match any of the candidates.');
|
9221 | error.name = 'RuntimeTypeError';
|
9222 | throw error;
|
9223 | };
|
9224 | }
|
9225 | }, {
|
9226 | key: 'wrapIterator',
|
9227 | value: function wrapIterator(type) {
|
9228 | var t = this;
|
9229 | return function* wrappedIterator(input) {
|
9230 | var _iteratorNormalCompletion = true;
|
9231 | var _didIteratorError = false;
|
9232 | var _iteratorError = undefined;
|
9233 |
|
9234 | try {
|
9235 | for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
9236 | var item = _step.value;
|
9237 |
|
9238 | yield t.check(type, item);
|
9239 | }
|
9240 | } catch (err) {
|
9241 | _didIteratorError = true;
|
9242 | _iteratorError = err;
|
9243 | } finally {
|
9244 | try {
|
9245 | if (!_iteratorNormalCompletion && _iterator.return) {
|
9246 | _iterator.return();
|
9247 | }
|
9248 | } finally {
|
9249 | if (_didIteratorError) {
|
9250 | throw _iteratorError;
|
9251 | }
|
9252 | }
|
9253 | }
|
9254 | };
|
9255 | }
|
9256 | }, {
|
9257 | key: 'refinement',
|
9258 | value: function refinement(type) {
|
9259 | var target = new RefinementType(this);
|
9260 | target.type = type;
|
9261 |
|
9262 | for (var _len17 = arguments.length, constraints = Array(_len17 > 1 ? _len17 - 1 : 0), _key17 = 1; _key17 < _len17; _key17++) {
|
9263 | constraints[_key17 - 1] = arguments[_key17];
|
9264 | }
|
9265 |
|
9266 | target.addConstraint.apply(target, toConsumableArray(constraints));
|
9267 | return target;
|
9268 | }
|
9269 | }, {
|
9270 | key: '$diff',
|
9271 | value: function $diff(aType, bType) {
|
9272 | var target = new $DiffType(this);
|
9273 | target.aType = aType;
|
9274 | target.bType = bType;
|
9275 | return target;
|
9276 | }
|
9277 | }, {
|
9278 | key: '$flowFixMe',
|
9279 | value: function $flowFixMe() {
|
9280 | return new $FlowFixMeType(this);
|
9281 | }
|
9282 | }, {
|
9283 | key: '$keys',
|
9284 | value: function $keys(type) {
|
9285 | var target = new $KeysType(this);
|
9286 | target.type = type;
|
9287 | return target;
|
9288 | }
|
9289 | }, {
|
9290 | key: '$objMap',
|
9291 | value: function $objMap(object, mapper) {
|
9292 | var target = new $ObjMapType(this);
|
9293 | target.object = object;
|
9294 | target.mapper = mapper;
|
9295 | return target;
|
9296 | }
|
9297 | }, {
|
9298 | key: '$objMapi',
|
9299 | value: function $objMapi(object, mapper) {
|
9300 | var target = new $ObjMapiType(this);
|
9301 | target.object = object;
|
9302 | target.mapper = mapper;
|
9303 | return target;
|
9304 | }
|
9305 | }, {
|
9306 | key: '$propertyType',
|
9307 | value: function $propertyType(object, property) {
|
9308 | var target = new $PropertyType(this);
|
9309 | target.object = object;
|
9310 | if (property instanceof Type) {
|
9311 | var unwrapped = property.unwrap();
|
9312 | target.property = unwrapped.value;
|
9313 | } else {
|
9314 | target.property = property;
|
9315 | }
|
9316 | return target;
|
9317 | }
|
9318 | }, {
|
9319 | key: '$shape',
|
9320 | value: function $shape(type) {
|
9321 | var target = new $ShapeType(this);
|
9322 | target.type = type;
|
9323 | return target;
|
9324 | }
|
9325 | }, {
|
9326 | key: '$subtype',
|
9327 | value: function $subtype(type) {
|
9328 | var target = new $SubType(this);
|
9329 | target.type = type;
|
9330 | return target;
|
9331 | }
|
9332 | }, {
|
9333 | key: '$supertype',
|
9334 | value: function $supertype(type) {
|
9335 | var target = new $SuperType(this);
|
9336 | target.type = type;
|
9337 | return target;
|
9338 | }
|
9339 | }, {
|
9340 | key: '$tupleMap',
|
9341 | value: function $tupleMap(tuple, mapper) {
|
9342 | var target = new $TupleMapType(this);
|
9343 | target.tuple = tuple;
|
9344 | target.mapper = mapper;
|
9345 | return target;
|
9346 | }
|
9347 | }, {
|
9348 | key: 'Class',
|
9349 | value: function Class(instanceType) {
|
9350 | var target = new ClassType(this);
|
9351 | target.instanceType = instanceType;
|
9352 | return target;
|
9353 | }
|
9354 | }, {
|
9355 | key: 'TypeParametersSymbol',
|
9356 |
|
9357 |
|
9358 |
|
9359 | get: function get$$1() {
|
9360 | return TypeParametersSymbol;
|
9361 | }
|
9362 | }]);
|
9363 | return TypeContext;
|
9364 | }();
|
9365 |
|
9366 | var globalContext$1 = void 0;
|
9367 | if (typeof global !== 'undefined' && typeof global.__FLOW_RUNTIME_GLOBAL_CONTEXT_DO_NOT_USE_THIS_VARIABLE__ !== 'undefined') {
|
9368 | globalContext$1 = global.__FLOW_RUNTIME_GLOBAL_CONTEXT_DO_NOT_USE_THIS_VARIABLE__;
|
9369 | } else {
|
9370 | globalContext$1 = new TypeContext();
|
9371 | registerPrimitiveTypes(globalContext$1);
|
9372 | registerBuiltinTypeConstructors(globalContext$1);
|
9373 | registerTypePredicates(globalContext$1);
|
9374 | if (typeof global !== 'undefined') {
|
9375 | global.__FLOW_RUNTIME_GLOBAL_CONTEXT_DO_NOT_USE_THIS_VARIABLE__ = globalContext$1;
|
9376 | }
|
9377 | }
|
9378 |
|
9379 | var globalContext$2 = globalContext$1;
|
9380 |
|
9381 | export { AnyType, ArrayType, BooleanLiteralType, BooleanType, EmptyType, ExistentialType, FlowIntoType, FunctionType, FunctionTypeParam, FunctionTypeRestParam, FunctionTypeReturn, GeneratorType, GenericType, IntersectionType, MixedType, TypeAlias, NullableType, NullLiteralType, NumberType, NumericLiteralType, ObjectType, ObjectTypeCallProperty, ObjectTypeIndexer, ObjectTypeProperty, ParameterizedTypeAlias, ParameterizedFunctionType, PartialType, RefinementType, StringLiteralType, StringType, SymbolLiteralType, SymbolType, ThisType, TupleType, Type, TypeBox, TypeConstructor, TypeParameter, TypeParameterApplication, TypeReference, TypeTDZ, UnionType, VoidType, Declaration, TypeDeclaration, VarDeclaration, ModuleDeclaration, ModuleExports as ModuleExportsDeclaration, ClassDeclaration, ParameterizedClassDeclaration, ExtendsDeclaration, TypeParametersSymbol };export default globalContext$2;
|
9382 |
|