1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
8 |
|
9 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
12 |
|
13 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var ClassMetadataStore = function () {
|
20 | function ClassMetadataStore() {
|
21 | _classCallCheck(this, ClassMetadataStore);
|
22 | }
|
23 |
|
24 | _createClass(ClassMetadataStore, [{
|
25 | key: 'init',
|
26 | value: function init(classMetadataProvider) {
|
27 | |
28 |
|
29 |
|
30 | this.classMetadata = {};
|
31 |
|
32 | |
33 |
|
34 |
|
35 | this.classMetadataProvider = classMetadataProvider;
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | this.classMetadataOnloadCallbacks = {};
|
43 | }
|
44 |
|
45 | |
46 |
|
47 |
|
48 |
|
49 | }, {
|
50 | key: 'getClassMetadata',
|
51 | value: function getClassMetadata(type, onload) {
|
52 | var _this = this;
|
53 |
|
54 | var classMeta = this.classMetadata[type];
|
55 | if (classMeta) {
|
56 | return onload(classMeta);
|
57 | }
|
58 |
|
59 | var callbacks = this.classMetadataOnloadCallbacks[type];
|
60 | if (!callbacks) {
|
61 |
|
62 |
|
63 |
|
64 | callbacks = this.classMetadataOnloadCallbacks[type] = [onload];
|
65 | this.classMetadataProvider(type, function (data) {
|
66 | classMeta = _this.classMetadata[type] = JSON.parse(JSON.stringify(data));
|
67 | classMeta.classes = classMeta.classes || [];
|
68 |
|
69 | if (classMeta.classes.indexOf(type) < 0) {
|
70 | classMeta.classes = [type].concat(_toConsumableArray(classMeta.classes));
|
71 | }
|
72 | delete _this.classMetadataOnloadCallbacks[type];
|
73 |
|
74 |
|
75 | for (var i = 0; i < callbacks.length; i++) {
|
76 | try {
|
77 | callbacks[i](classMeta);
|
78 | } catch (e) {
|
79 | console.error('Unexpected Error in ClassMetadataStore onload callback function.', e);
|
80 | }
|
81 | }
|
82 | });
|
83 | } else {
|
84 |
|
85 |
|
86 | callbacks.push(onload);
|
87 | }
|
88 | }
|
89 | }, {
|
90 | key: 'dataType',
|
91 | value: function dataType(_dataType) {
|
92 | var _this2 = this;
|
93 |
|
94 | return function (extensions, onload) {
|
95 | if (_dataType && (typeof _dataType === 'undefined' ? 'undefined' : _typeof(_dataType)) === 'object' && '_class' in _dataType) {
|
96 |
|
97 | _dataType = _dataType._class;
|
98 | }
|
99 |
|
100 | _this2.getClassMetadata(_dataType, function (currentTypeInfo) {
|
101 |
|
102 |
|
103 | var matchingExtensions = [];
|
104 | eachType: for (var typeIndex = 0; typeIndex < currentTypeInfo.classes.length; typeIndex++) {
|
105 |
|
106 |
|
107 | var type = currentTypeInfo.classes[typeIndex];
|
108 | for (var i = 0; i < extensions.length; i++) {
|
109 | var extension = extensions[i];
|
110 | if (type === extension.dataType) {
|
111 | matchingExtensions.push(extension);
|
112 | }
|
113 | }
|
114 |
|
115 |
|
116 | if (matchingExtensions.length > 0) {
|
117 | break eachType;
|
118 | }
|
119 | }
|
120 | onload(matchingExtensions);
|
121 | });
|
122 | };
|
123 | }
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 | }, {
|
130 | key: 'untyped',
|
131 | value: function untyped() {
|
132 | return function (extensions, onload) {
|
133 |
|
134 | extensions = extensions.filter(function (m) {
|
135 | return !('dataType' in m);
|
136 | });
|
137 | onload(extensions);
|
138 | };
|
139 | }
|
140 | }]);
|
141 |
|
142 | return ClassMetadataStore;
|
143 | }();
|
144 |
|
145 | exports.default = ClassMetadataStore; |
\ | No newline at end of file |