node-dependency-injection 3.0.0-beta.7 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/Services/File/BaseAdapter.js +1 -50
- package/dist/bin/Services/File/FileManager.js +1 -55
- package/dist/bin/Services/File/JsAdapter.js +1 -62
- package/dist/bin/Services/File/JsonAdapter.js +1 -60
- package/dist/bin/Services/File/YamlAdapter.js +1 -67
- package/dist/bin/ndi-config:check.js +1 -55
- package/dist/bin/ndi-config:create.js +1 -40
- package/dist/bin/ndi-container:service.js +1 -131
- package/dist/bin/ndi.js +1 -9
- package/dist/lib/Autowire.js +1 -825
- package/dist/lib/AutowireIdentifier.js +1 -43
- package/dist/lib/Compiler.js +1 -210
- package/dist/lib/CompilerPass/DecoratePass.js +1 -180
- package/dist/lib/CompilerPass/OptimizePass.js +1 -82
- package/dist/lib/CompilerPass/RemovePass.js +1 -79
- package/dist/lib/CompilerPass/index.js +1 -179
- package/dist/lib/ContainerBuilder.js +1 -551
- package/dist/lib/Definition.js +1 -371
- package/dist/lib/Dump/Dumper.js +1 -19
- package/dist/lib/Dump/JsDumper.js +1 -77
- package/dist/lib/Dump/JsonDumper.js +1 -75
- package/dist/lib/Dump/YamlDumper.js +1 -77
- package/dist/lib/Exception/AbstractServiceException.js +1 -47
- package/dist/lib/Exception/AttributesMapException.js +1 -44
- package/dist/lib/Exception/ConfigurationFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ContainerDefaultDirMustBeSet.js +1 -47
- package/dist/lib/Exception/DefinitionNotFoundException.js +1 -47
- package/dist/lib/Exception/FrozenContainerException.js +1 -44
- package/dist/lib/Exception/LoadMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/LoggerWarnMethodNotFoundException.js +1 -44
- package/dist/lib/Exception/MethodCallEmptyException.js +1 -44
- package/dist/lib/Exception/MethodCallNotFoundException.js +1 -47
- package/dist/lib/Exception/NotAbstractServiceException.js +1 -47
- package/dist/lib/Exception/PrivateServiceException.js +1 -47
- package/dist/lib/Exception/ProcessMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/RootDirectoryMustBeAbsolute.js +1 -44
- package/dist/lib/Exception/RootDirectoryNotFound.js +1 -44
- package/dist/lib/Exception/ServiceCircularReferenceException.js +1 -44
- package/dist/lib/Exception/ServiceFileNotAbsolute.js +1 -44
- package/dist/lib/Exception/ServiceFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotLoadedException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotValidExtension.js +1 -44
- package/dist/lib/Exception/ServiceNotFoundException.js +1 -48
- package/dist/lib/Exception/UnableToGetInstanceFromId.js +1 -50
- package/dist/lib/Exception/WrongCompilerPassTypeException.js +1 -47
- package/dist/lib/Exception/WrongDefinitionException.js +1 -44
- package/dist/lib/InstanceManager.js +1 -413
- package/dist/lib/Loader/FileLoader.js +1 -626
- package/dist/lib/Loader/JsFileLoader.js +1 -101
- package/dist/lib/Loader/JsonFileLoader.js +1 -39
- package/dist/lib/Loader/YamlFileLoader.js +1 -133
- package/dist/lib/PackageReference.js +1 -37
- package/dist/lib/PassConfig.js +1 -78
- package/dist/lib/Reference.js +1 -49
- package/dist/lib/ServiceFile.js +1 -232
- package/dist/lib/TagReference.js +1 -37
- package/dist/lib/index.js +1 -95
- package/package.json +3 -3
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/bin/Services/File/BaseAdapter.js.html +0 -158
- package/coverage/lcov-report/bin/Services/File/FileManager.js.html +0 -176
- package/coverage/lcov-report/bin/Services/File/JsAdapter.js.html +0 -140
- package/coverage/lcov-report/bin/Services/File/JsonAdapter.js.html +0 -131
- package/coverage/lcov-report/bin/Services/File/YamlAdapter.js.html +0 -155
- package/coverage/lcov-report/bin/Services/File/index.html +0 -171
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -171
- package/coverage/lcov-report/lib/Autowire.js.html +0 -506
- package/coverage/lcov-report/lib/Compiler.js.html +0 -239
- package/coverage/lcov-report/lib/CompilerPass/DecoratePass.js.html +0 -248
- package/coverage/lcov-report/lib/CompilerPass/OptimizePass.js.html +0 -128
- package/coverage/lcov-report/lib/CompilerPass/RemovePass.js.html +0 -116
- package/coverage/lcov-report/lib/CompilerPass/index.html +0 -156
- package/coverage/lcov-report/lib/CompilerPass/index.js.html +0 -326
- package/coverage/lcov-report/lib/ContainerBuilder.js.html +0 -1115
- package/coverage/lcov-report/lib/Definition.js.html +0 -962
- package/coverage/lcov-report/lib/Exception/AbstractServiceException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/AttributesMapException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/ConfigurationFileNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/DefinitionNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/FrozenContainerException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/LoadMethodNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/LoggerWarnMethodNotFoundException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/MethodCallEmptyException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/MethodCallNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/NotAbstractServiceException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/PrivateServiceException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/ProcessMethodNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/ServiceCircularReferenceException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/ServiceFileNotFoundException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/ServiceFileNotLoadedException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/ServiceNotFoundException.js.html +0 -113
- package/coverage/lcov-report/lib/Exception/WrongCompilerPassTypeException.js.html +0 -110
- package/coverage/lcov-report/lib/Exception/WrongDefinitionException.js.html +0 -101
- package/coverage/lcov-report/lib/Exception/index.html +0 -366
- package/coverage/lcov-report/lib/InstanceManager.js.html +0 -839
- package/coverage/lcov-report/lib/Loader/FileLoader.js.html +0 -1034
- package/coverage/lcov-report/lib/Loader/JsFileLoader.js.html +0 -155
- package/coverage/lcov-report/lib/Loader/JsonFileLoader.js.html +0 -98
- package/coverage/lcov-report/lib/Loader/YamlFileLoader.js.html +0 -188
- package/coverage/lcov-report/lib/Loader/index.html +0 -156
- package/coverage/lcov-report/lib/PackageReference.js.html +0 -131
- package/coverage/lcov-report/lib/PassConfig.js.html +0 -230
- package/coverage/lcov-report/lib/Reference.js.html +0 -158
- package/coverage/lcov-report/lib/TagReference.js.html +0 -131
- package/coverage/lcov-report/lib/index.html +0 -231
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -1516
package/dist/lib/Autowire.js
CHANGED
|
@@ -1,825 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _path = _interopRequireDefault(require("path"));
|
|
19
|
-
|
|
20
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
21
|
-
|
|
22
|
-
var _json = _interopRequireDefault(require("json5"));
|
|
23
|
-
|
|
24
|
-
var _typescriptEstree = require("@typescript-eslint/typescript-estree");
|
|
25
|
-
|
|
26
|
-
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
27
|
-
|
|
28
|
-
var _Reference = _interopRequireDefault(require("./Reference"));
|
|
29
|
-
|
|
30
|
-
var _ServiceFile = _interopRequireDefault(require("./ServiceFile"));
|
|
31
|
-
|
|
32
|
-
var _AutowireIdentifier = _interopRequireDefault(require("./AutowireIdentifier"));
|
|
33
|
-
|
|
34
|
-
var _ContainerDefaultDirMustBeSet = _interopRequireDefault(require("./Exception/ContainerDefaultDirMustBeSet"));
|
|
35
|
-
|
|
36
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
37
|
-
|
|
38
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
39
|
-
|
|
40
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
41
|
-
|
|
42
|
-
var Autowire = /*#__PURE__*/function () {
|
|
43
|
-
/**
|
|
44
|
-
* @param {ContainerBuilder} container
|
|
45
|
-
* @param {string} tsConfigFullPath
|
|
46
|
-
*/
|
|
47
|
-
function Autowire(container) {
|
|
48
|
-
var tsConfigFullPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
49
|
-
(0, _classCallCheck2["default"])(this, Autowire);
|
|
50
|
-
|
|
51
|
-
this._ensureContainerIsValidForAutowire(container);
|
|
52
|
-
|
|
53
|
-
this._rootDirectory = container.defaultDir;
|
|
54
|
-
this._container = container;
|
|
55
|
-
this._excludedFolders = [];
|
|
56
|
-
this._serviceFile = null;
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
this._tsConfigFullPath = tsConfigFullPath || _path["default"].join(process.cwd(), 'tsconfig.json');
|
|
60
|
-
this._tsConfigPaths = _json["default"].parse(_fs["default"].readFileSync(this._tsConfigFullPath, 'utf-8')).compilerOptions.paths;
|
|
61
|
-
} catch (e) {
|
|
62
|
-
this._tsConfigPaths = null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
(0, _createClass2["default"])(Autowire, [{
|
|
67
|
-
key: "_ensureContainerIsValidForAutowire",
|
|
68
|
-
value: function _ensureContainerIsValidForAutowire(container) {
|
|
69
|
-
if (container.defaultDir === null) {
|
|
70
|
-
throw new _ContainerDefaultDirMustBeSet["default"]();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @return {ContainerBuilder}
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
}, {
|
|
78
|
-
key: "container",
|
|
79
|
-
get: function get() {
|
|
80
|
-
return this._container;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @private
|
|
84
|
-
* @param {string}
|
|
85
|
-
* @return {Iterable}
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
}, {
|
|
89
|
-
key: "_walk",
|
|
90
|
-
value:
|
|
91
|
-
/*#__PURE__*/
|
|
92
|
-
_regenerator["default"].mark(function _walk(dir) {
|
|
93
|
-
var files, _iterator, _step, file, filePath;
|
|
94
|
-
|
|
95
|
-
return _regenerator["default"].wrap(function _walk$(_context) {
|
|
96
|
-
while (1) {
|
|
97
|
-
switch (_context.prev = _context.next) {
|
|
98
|
-
case 0:
|
|
99
|
-
files = _fs["default"].readdirSync(dir, {
|
|
100
|
-
withFileTypes: true
|
|
101
|
-
});
|
|
102
|
-
_iterator = _createForOfIteratorHelper(files);
|
|
103
|
-
_context.prev = 2;
|
|
104
|
-
|
|
105
|
-
_iterator.s();
|
|
106
|
-
|
|
107
|
-
case 4:
|
|
108
|
-
if ((_step = _iterator.n()).done) {
|
|
109
|
-
_context.next = 20;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
file = _step.value;
|
|
114
|
-
|
|
115
|
-
if (!file.isDirectory()) {
|
|
116
|
-
_context.next = 9;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return _context.delegateYield(this._walk(_path["default"].join(dir, file.name)), "t0", 8);
|
|
121
|
-
|
|
122
|
-
case 8:
|
|
123
|
-
return _context.abrupt("continue", 18);
|
|
124
|
-
|
|
125
|
-
case 9:
|
|
126
|
-
filePath = _path["default"].join(dir, file.name);
|
|
127
|
-
_context.prev = 10;
|
|
128
|
-
|
|
129
|
-
this._ensureFileIsNotExcluded(filePath);
|
|
130
|
-
|
|
131
|
-
_context.next = 14;
|
|
132
|
-
return filePath;
|
|
133
|
-
|
|
134
|
-
case 14:
|
|
135
|
-
_context.next = 18;
|
|
136
|
-
break;
|
|
137
|
-
|
|
138
|
-
case 16:
|
|
139
|
-
_context.prev = 16;
|
|
140
|
-
_context.t1 = _context["catch"](10);
|
|
141
|
-
|
|
142
|
-
case 18:
|
|
143
|
-
_context.next = 4;
|
|
144
|
-
break;
|
|
145
|
-
|
|
146
|
-
case 20:
|
|
147
|
-
_context.next = 25;
|
|
148
|
-
break;
|
|
149
|
-
|
|
150
|
-
case 22:
|
|
151
|
-
_context.prev = 22;
|
|
152
|
-
_context.t2 = _context["catch"](2);
|
|
153
|
-
|
|
154
|
-
_iterator.e(_context.t2);
|
|
155
|
-
|
|
156
|
-
case 25:
|
|
157
|
-
_context.prev = 25;
|
|
158
|
-
|
|
159
|
-
_iterator.f();
|
|
160
|
-
|
|
161
|
-
return _context.finish(25);
|
|
162
|
-
|
|
163
|
-
case 28:
|
|
164
|
-
case "end":
|
|
165
|
-
return _context.stop();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}, _walk, this, [[2, 22, 25, 28], [10, 16]]);
|
|
169
|
-
})
|
|
170
|
-
/**
|
|
171
|
-
* @private
|
|
172
|
-
* @param {string} filePath
|
|
173
|
-
* @returns {void}
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
}, {
|
|
177
|
-
key: "_ensureFileIsNotExcluded",
|
|
178
|
-
value: function _ensureFileIsNotExcluded(filePath) {
|
|
179
|
-
this._excludedFolders.forEach(function (excludedFolder) {
|
|
180
|
-
if (filePath.includes(excludedFolder)) {
|
|
181
|
-
throw new Error('Excluded Folder!');
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* @param {string} path
|
|
187
|
-
*/
|
|
188
|
-
|
|
189
|
-
}, {
|
|
190
|
-
key: "addExclude",
|
|
191
|
-
value: function addExclude(relativePath) {
|
|
192
|
-
var fullPathToExclude = _path["default"].join(this._rootDirectory, relativePath);
|
|
193
|
-
|
|
194
|
-
this._excludedFolders.push(fullPathToExclude);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* @private
|
|
198
|
-
* @param {string} path
|
|
199
|
-
* @param {string} type
|
|
200
|
-
* @param {string} extension
|
|
201
|
-
* @returns {Promise}
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
}, {
|
|
205
|
-
key: "_getServiceIdFromPath",
|
|
206
|
-
value: function () {
|
|
207
|
-
var _getServiceIdFromPath2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(path, type) {
|
|
208
|
-
var extension,
|
|
209
|
-
readableId,
|
|
210
|
-
_args2 = arguments;
|
|
211
|
-
return _regenerator["default"].wrap(function _callee$(_context2) {
|
|
212
|
-
while (1) {
|
|
213
|
-
switch (_context2.prev = _context2.next) {
|
|
214
|
-
case 0:
|
|
215
|
-
extension = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : '.ts';
|
|
216
|
-
readableId = path.replace(/\//g, '__').replace(extension, '').replace('@', '__').concat("__".concat(type));
|
|
217
|
-
return _context2.abrupt("return", _AutowireIdentifier["default"].encode(readableId));
|
|
218
|
-
|
|
219
|
-
case 3:
|
|
220
|
-
case "end":
|
|
221
|
-
return _context2.stop();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}, _callee);
|
|
225
|
-
}));
|
|
226
|
-
|
|
227
|
-
function _getServiceIdFromPath(_x, _x2) {
|
|
228
|
-
return _getServiceIdFromPath2.apply(this, arguments);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return _getServiceIdFromPath;
|
|
232
|
-
}()
|
|
233
|
-
/**
|
|
234
|
-
* @return {Promise}
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
}, {
|
|
238
|
-
key: "process",
|
|
239
|
-
value: function () {
|
|
240
|
-
var _process = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
241
|
-
var promises, _iterator2, _step2, filePath;
|
|
242
|
-
|
|
243
|
-
return _regenerator["default"].wrap(function _callee2$(_context3) {
|
|
244
|
-
while (1) {
|
|
245
|
-
switch (_context3.prev = _context3.next) {
|
|
246
|
-
case 0:
|
|
247
|
-
promises = [];
|
|
248
|
-
_iterator2 = _createForOfIteratorHelper(this._walk(this._rootDirectory));
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
252
|
-
filePath = _step2.value;
|
|
253
|
-
promises.push(this._executeFilePath(filePath));
|
|
254
|
-
}
|
|
255
|
-
} catch (err) {
|
|
256
|
-
_iterator2.e(err);
|
|
257
|
-
} finally {
|
|
258
|
-
_iterator2.f();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
_context3.next = 5;
|
|
262
|
-
return Promise.all(promises);
|
|
263
|
-
|
|
264
|
-
case 5:
|
|
265
|
-
if (!(this._serviceFile instanceof _ServiceFile["default"])) {
|
|
266
|
-
_context3.next = 8;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
_context3.next = 8;
|
|
271
|
-
return this._serviceFile.generateFromContainer(this._container);
|
|
272
|
-
|
|
273
|
-
case 8:
|
|
274
|
-
case "end":
|
|
275
|
-
return _context3.stop();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}, _callee2, this);
|
|
279
|
-
}));
|
|
280
|
-
|
|
281
|
-
function process() {
|
|
282
|
-
return _process.apply(this, arguments);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return process;
|
|
286
|
-
}()
|
|
287
|
-
/**
|
|
288
|
-
* @param {string} filePath
|
|
289
|
-
* @returns {Promise}
|
|
290
|
-
* @private
|
|
291
|
-
*/
|
|
292
|
-
|
|
293
|
-
}, {
|
|
294
|
-
key: "_executeFilePath",
|
|
295
|
-
value: function () {
|
|
296
|
-
var _executeFilePath2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(filePath) {
|
|
297
|
-
var parsedFile, _yield$this$_getClass, classDeclaration, body, Class, definition, serviceId;
|
|
298
|
-
|
|
299
|
-
return _regenerator["default"].wrap(function _callee3$(_context4) {
|
|
300
|
-
while (1) {
|
|
301
|
-
switch (_context4.prev = _context4.next) {
|
|
302
|
-
case 0:
|
|
303
|
-
parsedFile = _path["default"].parse(filePath);
|
|
304
|
-
|
|
305
|
-
if (!(parsedFile.ext !== '.ts')) {
|
|
306
|
-
_context4.next = 3;
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return _context4.abrupt("return");
|
|
311
|
-
|
|
312
|
-
case 3:
|
|
313
|
-
_context4.next = 5;
|
|
314
|
-
return this._getClassDeclaration(filePath);
|
|
315
|
-
|
|
316
|
-
case 5:
|
|
317
|
-
_yield$this$_getClass = _context4.sent;
|
|
318
|
-
classDeclaration = _yield$this$_getClass.classDeclaration;
|
|
319
|
-
body = _yield$this$_getClass.body;
|
|
320
|
-
|
|
321
|
-
if (classDeclaration) {
|
|
322
|
-
_context4.next = 10;
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return _context4.abrupt("return");
|
|
327
|
-
|
|
328
|
-
case 10:
|
|
329
|
-
Class = require(filePath)["default"];
|
|
330
|
-
|
|
331
|
-
if (Class) {
|
|
332
|
-
_context4.next = 13;
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return _context4.abrupt("return");
|
|
337
|
-
|
|
338
|
-
case 13:
|
|
339
|
-
_context4.next = 15;
|
|
340
|
-
return this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
341
|
-
|
|
342
|
-
case 15:
|
|
343
|
-
definition = _context4.sent;
|
|
344
|
-
|
|
345
|
-
if (definition) {
|
|
346
|
-
_context4.next = 18;
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return _context4.abrupt("return");
|
|
351
|
-
|
|
352
|
-
case 18:
|
|
353
|
-
_context4.next = 20;
|
|
354
|
-
return this._getServiceIdFromPath(filePath, Class.name);
|
|
355
|
-
|
|
356
|
-
case 20:
|
|
357
|
-
serviceId = _context4.sent;
|
|
358
|
-
this.container.setDefinition(serviceId, definition);
|
|
359
|
-
_context4.next = 24;
|
|
360
|
-
return this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
361
|
-
|
|
362
|
-
case 24:
|
|
363
|
-
case "end":
|
|
364
|
-
return _context4.stop();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}, _callee3, this);
|
|
368
|
-
}));
|
|
369
|
-
|
|
370
|
-
function _executeFilePath(_x3) {
|
|
371
|
-
return _executeFilePath2.apply(this, arguments);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return _executeFilePath;
|
|
375
|
-
}()
|
|
376
|
-
/**
|
|
377
|
-
*
|
|
378
|
-
* @param {string} filePath
|
|
379
|
-
* @returns {Promise}
|
|
380
|
-
* @private
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
}, {
|
|
384
|
-
key: "_getClassDeclaration",
|
|
385
|
-
value: function () {
|
|
386
|
-
var _getClassDeclaration2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(filePath) {
|
|
387
|
-
var sourceCode, body, classDeclaration;
|
|
388
|
-
return _regenerator["default"].wrap(function _callee4$(_context5) {
|
|
389
|
-
while (1) {
|
|
390
|
-
switch (_context5.prev = _context5.next) {
|
|
391
|
-
case 0:
|
|
392
|
-
sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
|
|
393
|
-
body = (0, _typescriptEstree.parse)(sourceCode).body;
|
|
394
|
-
classDeclaration = body.find(function (declaration) {
|
|
395
|
-
return declaration.type === 'ExportDefaultDeclaration';
|
|
396
|
-
});
|
|
397
|
-
return _context5.abrupt("return", {
|
|
398
|
-
classDeclaration: classDeclaration,
|
|
399
|
-
body: body
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
case 4:
|
|
403
|
-
case "end":
|
|
404
|
-
return _context5.stop();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}, _callee4);
|
|
408
|
-
}));
|
|
409
|
-
|
|
410
|
-
function _getClassDeclaration(_x4) {
|
|
411
|
-
return _getClassDeclaration2.apply(this, arguments);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return _getClassDeclaration;
|
|
415
|
-
}()
|
|
416
|
-
/**
|
|
417
|
-
*
|
|
418
|
-
* @param {object} classDeclaration
|
|
419
|
-
* @param {string} body
|
|
420
|
-
* @param {any} parsedFile
|
|
421
|
-
* @param {any} ServiceClass
|
|
422
|
-
* @returns
|
|
423
|
-
* @private
|
|
424
|
-
*/
|
|
425
|
-
|
|
426
|
-
}, {
|
|
427
|
-
key: "_getDefinition",
|
|
428
|
-
value: function () {
|
|
429
|
-
var _getDefinition2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(classDeclaration, body, parsedFile, ServiceClass) {
|
|
430
|
-
var definition, constructorParams, _iterator3, _step3, parameterDeclaration, typeNameForArgument, argumentId;
|
|
431
|
-
|
|
432
|
-
return _regenerator["default"].wrap(function _callee5$(_context6) {
|
|
433
|
-
while (1) {
|
|
434
|
-
switch (_context6.prev = _context6.next) {
|
|
435
|
-
case 0:
|
|
436
|
-
_context6.prev = 0;
|
|
437
|
-
definition = new _Definition["default"](ServiceClass);
|
|
438
|
-
_context6.next = 4;
|
|
439
|
-
return this._getConstructorParamsByDefinition(definition, classDeclaration, body, parsedFile);
|
|
440
|
-
|
|
441
|
-
case 4:
|
|
442
|
-
constructorParams = _context6.sent;
|
|
443
|
-
_iterator3 = _createForOfIteratorHelper(constructorParams);
|
|
444
|
-
_context6.prev = 6;
|
|
445
|
-
|
|
446
|
-
_iterator3.s();
|
|
447
|
-
|
|
448
|
-
case 8:
|
|
449
|
-
if ((_step3 = _iterator3.n()).done) {
|
|
450
|
-
_context6.next = 19;
|
|
451
|
-
break;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
parameterDeclaration = _step3.value;
|
|
455
|
-
typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
456
|
-
_context6.next = 13;
|
|
457
|
-
return this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
458
|
-
|
|
459
|
-
case 13:
|
|
460
|
-
argumentId = _context6.sent;
|
|
461
|
-
|
|
462
|
-
if (argumentId) {
|
|
463
|
-
_context6.next = 16;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return _context6.abrupt("continue", 17);
|
|
468
|
-
|
|
469
|
-
case 16:
|
|
470
|
-
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
471
|
-
|
|
472
|
-
case 17:
|
|
473
|
-
_context6.next = 8;
|
|
474
|
-
break;
|
|
475
|
-
|
|
476
|
-
case 19:
|
|
477
|
-
_context6.next = 24;
|
|
478
|
-
break;
|
|
479
|
-
|
|
480
|
-
case 21:
|
|
481
|
-
_context6.prev = 21;
|
|
482
|
-
_context6.t0 = _context6["catch"](6);
|
|
483
|
-
|
|
484
|
-
_iterator3.e(_context6.t0);
|
|
485
|
-
|
|
486
|
-
case 24:
|
|
487
|
-
_context6.prev = 24;
|
|
488
|
-
|
|
489
|
-
_iterator3.f();
|
|
490
|
-
|
|
491
|
-
return _context6.finish(24);
|
|
492
|
-
|
|
493
|
-
case 27:
|
|
494
|
-
return _context6.abrupt("return", definition);
|
|
495
|
-
|
|
496
|
-
case 30:
|
|
497
|
-
_context6.prev = 30;
|
|
498
|
-
_context6.t1 = _context6["catch"](0);
|
|
499
|
-
|
|
500
|
-
case 32:
|
|
501
|
-
case "end":
|
|
502
|
-
return _context6.stop();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}, _callee5, this, [[0, 30], [6, 21, 24, 27]]);
|
|
506
|
-
}));
|
|
507
|
-
|
|
508
|
-
function _getDefinition(_x5, _x6, _x7, _x8) {
|
|
509
|
-
return _getDefinition2.apply(this, arguments);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
return _getDefinition;
|
|
513
|
-
}()
|
|
514
|
-
/**
|
|
515
|
-
* @private
|
|
516
|
-
* @param {Definition} definition
|
|
517
|
-
* @param {object} classDeclaration
|
|
518
|
-
* @param {any} body
|
|
519
|
-
* @param {any} parsedFile
|
|
520
|
-
* @returns
|
|
521
|
-
*/
|
|
522
|
-
|
|
523
|
-
}, {
|
|
524
|
-
key: "_getConstructorParamsByDefinition",
|
|
525
|
-
value: function () {
|
|
526
|
-
var _getConstructorParamsByDefinition2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(definition, classDeclaration, body, parsedFile) {
|
|
527
|
-
var constructorDeclaration;
|
|
528
|
-
return _regenerator["default"].wrap(function _callee6$(_context7) {
|
|
529
|
-
while (1) {
|
|
530
|
-
switch (_context7.prev = _context7.next) {
|
|
531
|
-
case 0:
|
|
532
|
-
constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
|
|
533
|
-
return method.key.name === 'constructor';
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
if (classDeclaration.declaration["abstract"]) {
|
|
537
|
-
definition["abstract"] = true;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
_context7.next = 4;
|
|
541
|
-
return this._parentDefinition(classDeclaration, body, parsedFile, definition);
|
|
542
|
-
|
|
543
|
-
case 4:
|
|
544
|
-
return _context7.abrupt("return", constructorDeclaration ? constructorDeclaration.value.params : []);
|
|
545
|
-
|
|
546
|
-
case 5:
|
|
547
|
-
case "end":
|
|
548
|
-
return _context7.stop();
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}, _callee6, this);
|
|
552
|
-
}));
|
|
553
|
-
|
|
554
|
-
function _getConstructorParamsByDefinition(_x9, _x10, _x11, _x12) {
|
|
555
|
-
return _getConstructorParamsByDefinition2.apply(this, arguments);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return _getConstructorParamsByDefinition;
|
|
559
|
-
}()
|
|
560
|
-
/**
|
|
561
|
-
* @private
|
|
562
|
-
* @param {object} classDeclaration
|
|
563
|
-
* @param {any} body
|
|
564
|
-
* @param {any} parsedFile
|
|
565
|
-
* @param {Definition} definition
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
|
-
}, {
|
|
569
|
-
key: "_parentDefinition",
|
|
570
|
-
value: function () {
|
|
571
|
-
var _parentDefinition2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(classDeclaration, body, parsedFile, definition) {
|
|
572
|
-
var typeParent, parentId;
|
|
573
|
-
return _regenerator["default"].wrap(function _callee7$(_context8) {
|
|
574
|
-
while (1) {
|
|
575
|
-
switch (_context8.prev = _context8.next) {
|
|
576
|
-
case 0:
|
|
577
|
-
if (!classDeclaration.declaration.superClass) {
|
|
578
|
-
_context8.next = 6;
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
typeParent = classDeclaration.declaration.superClass.name;
|
|
583
|
-
_context8.next = 4;
|
|
584
|
-
return this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
585
|
-
|
|
586
|
-
case 4:
|
|
587
|
-
parentId = _context8.sent;
|
|
588
|
-
|
|
589
|
-
if (parentId) {
|
|
590
|
-
definition.parent = parentId;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
case 6:
|
|
594
|
-
case "end":
|
|
595
|
-
return _context8.stop();
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}, _callee7, this);
|
|
599
|
-
}));
|
|
600
|
-
|
|
601
|
-
function _parentDefinition(_x13, _x14, _x15, _x16) {
|
|
602
|
-
return _parentDefinition2.apply(this, arguments);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
return _parentDefinition;
|
|
606
|
-
}()
|
|
607
|
-
/**
|
|
608
|
-
* @private
|
|
609
|
-
* @param {any} classDeclaration
|
|
610
|
-
* @param {any} body
|
|
611
|
-
* @param {any} parsedFile
|
|
612
|
-
* @param {string} serviceId
|
|
613
|
-
*/
|
|
614
|
-
|
|
615
|
-
}, {
|
|
616
|
-
key: "_interfaceImplementations",
|
|
617
|
-
value: function () {
|
|
618
|
-
var _interfaceImplementations2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(classDeclaration, body, parsedFile, serviceId) {
|
|
619
|
-
var _classDeclaration$dec;
|
|
620
|
-
|
|
621
|
-
var implementations, _iterator4, _step4, implement, interfaceType, aliasId;
|
|
622
|
-
|
|
623
|
-
return _regenerator["default"].wrap(function _callee8$(_context9) {
|
|
624
|
-
while (1) {
|
|
625
|
-
switch (_context9.prev = _context9.next) {
|
|
626
|
-
case 0:
|
|
627
|
-
implementations = (_classDeclaration$dec = classDeclaration.declaration["implements"]) !== null && _classDeclaration$dec !== void 0 ? _classDeclaration$dec : [];
|
|
628
|
-
_iterator4 = _createForOfIteratorHelper(implementations);
|
|
629
|
-
_context9.prev = 2;
|
|
630
|
-
|
|
631
|
-
_iterator4.s();
|
|
632
|
-
|
|
633
|
-
case 4:
|
|
634
|
-
if ((_step4 = _iterator4.n()).done) {
|
|
635
|
-
_context9.next = 15;
|
|
636
|
-
break;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
implement = _step4.value;
|
|
640
|
-
interfaceType = implement.expression.name;
|
|
641
|
-
_context9.next = 9;
|
|
642
|
-
return this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
643
|
-
|
|
644
|
-
case 9:
|
|
645
|
-
aliasId = _context9.sent;
|
|
646
|
-
|
|
647
|
-
if (!(!aliasId || this.container.hasAlias(aliasId))) {
|
|
648
|
-
_context9.next = 12;
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
return _context9.abrupt("continue", 13);
|
|
653
|
-
|
|
654
|
-
case 12:
|
|
655
|
-
this.container.setAlias(aliasId, serviceId);
|
|
656
|
-
|
|
657
|
-
case 13:
|
|
658
|
-
_context9.next = 4;
|
|
659
|
-
break;
|
|
660
|
-
|
|
661
|
-
case 15:
|
|
662
|
-
_context9.next = 20;
|
|
663
|
-
break;
|
|
664
|
-
|
|
665
|
-
case 17:
|
|
666
|
-
_context9.prev = 17;
|
|
667
|
-
_context9.t0 = _context9["catch"](2);
|
|
668
|
-
|
|
669
|
-
_iterator4.e(_context9.t0);
|
|
670
|
-
|
|
671
|
-
case 20:
|
|
672
|
-
_context9.prev = 20;
|
|
673
|
-
|
|
674
|
-
_iterator4.f();
|
|
675
|
-
|
|
676
|
-
return _context9.finish(20);
|
|
677
|
-
|
|
678
|
-
case 23:
|
|
679
|
-
case "end":
|
|
680
|
-
return _context9.stop();
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}, _callee8, this, [[2, 17, 20, 23]]);
|
|
684
|
-
}));
|
|
685
|
-
|
|
686
|
-
function _interfaceImplementations(_x17, _x18, _x19, _x20) {
|
|
687
|
-
return _interfaceImplementations2.apply(this, arguments);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
return _interfaceImplementations;
|
|
691
|
-
}()
|
|
692
|
-
/**
|
|
693
|
-
* @private
|
|
694
|
-
* @param {string} type
|
|
695
|
-
* @param {any} body
|
|
696
|
-
* @param {anty} parsedFile
|
|
697
|
-
* @returns {Promise}
|
|
698
|
-
*/
|
|
699
|
-
|
|
700
|
-
}, {
|
|
701
|
-
key: "_getIdentifierFromImports",
|
|
702
|
-
value: function () {
|
|
703
|
-
var _getIdentifierFromImports2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(type, body, parsedFile) {
|
|
704
|
-
var _this$_tsConfigPaths, rootDir, relativeImportForImplement, configPaths, pathConfig, tsConfigPath, tsRelativePath, parsedTsConfigPath, absolutePathImportForImplement;
|
|
705
|
-
|
|
706
|
-
return _regenerator["default"].wrap(function _callee9$(_context10) {
|
|
707
|
-
while (1) {
|
|
708
|
-
switch (_context10.prev = _context10.next) {
|
|
709
|
-
case 0:
|
|
710
|
-
_context10.prev = 0;
|
|
711
|
-
rootDir = parsedFile.dir;
|
|
712
|
-
_context10.next = 4;
|
|
713
|
-
return this._getRelativeImport(body, type);
|
|
714
|
-
|
|
715
|
-
case 4:
|
|
716
|
-
relativeImportForImplement = _context10.sent;
|
|
717
|
-
configPaths = (_this$_tsConfigPaths = this._tsConfigPaths) !== null && _this$_tsConfigPaths !== void 0 ? _this$_tsConfigPaths : [];
|
|
718
|
-
_context10.t0 = _regenerator["default"].keys(configPaths);
|
|
719
|
-
|
|
720
|
-
case 7:
|
|
721
|
-
if ((_context10.t1 = _context10.t0()).done) {
|
|
722
|
-
_context10.next = 18;
|
|
723
|
-
break;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
pathConfig = _context10.t1.value;
|
|
727
|
-
tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
728
|
-
tsRelativePath = this._tsConfigPaths[pathConfig][0].replace(/\*/g, '');
|
|
729
|
-
|
|
730
|
-
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
731
|
-
_context10.next = 13;
|
|
732
|
-
break;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
return _context10.abrupt("continue", 7);
|
|
736
|
-
|
|
737
|
-
case 13:
|
|
738
|
-
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
739
|
-
parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
740
|
-
rootDir = parsedTsConfigPath.dir;
|
|
741
|
-
_context10.next = 7;
|
|
742
|
-
break;
|
|
743
|
-
|
|
744
|
-
case 18:
|
|
745
|
-
absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
746
|
-
return _context10.abrupt("return", this._getServiceIdFromPath(absolutePathImportForImplement, type));
|
|
747
|
-
|
|
748
|
-
case 22:
|
|
749
|
-
_context10.prev = 22;
|
|
750
|
-
_context10.t2 = _context10["catch"](0);
|
|
751
|
-
|
|
752
|
-
case 24:
|
|
753
|
-
case "end":
|
|
754
|
-
return _context10.stop();
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}, _callee9, this, [[0, 22]]);
|
|
758
|
-
}));
|
|
759
|
-
|
|
760
|
-
function _getIdentifierFromImports(_x21, _x22, _x23) {
|
|
761
|
-
return _getIdentifierFromImports2.apply(this, arguments);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
return _getIdentifierFromImports;
|
|
765
|
-
}()
|
|
766
|
-
/**
|
|
767
|
-
* @private
|
|
768
|
-
* @param {any} body
|
|
769
|
-
* @param {string} type
|
|
770
|
-
* @returns {Promise}
|
|
771
|
-
*/
|
|
772
|
-
|
|
773
|
-
}, {
|
|
774
|
-
key: "_getRelativeImport",
|
|
775
|
-
value: function () {
|
|
776
|
-
var _getRelativeImport2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(body, type) {
|
|
777
|
-
return _regenerator["default"].wrap(function _callee10$(_context11) {
|
|
778
|
-
while (1) {
|
|
779
|
-
switch (_context11.prev = _context11.next) {
|
|
780
|
-
case 0:
|
|
781
|
-
return _context11.abrupt("return", body.find(function (declaration) {
|
|
782
|
-
if (declaration.specifiers) {
|
|
783
|
-
return declaration.specifiers.find(function (specifier) {
|
|
784
|
-
return specifier.local.name === type;
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
return null;
|
|
789
|
-
}).source.value);
|
|
790
|
-
|
|
791
|
-
case 1:
|
|
792
|
-
case "end":
|
|
793
|
-
return _context11.stop();
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}, _callee10);
|
|
797
|
-
}));
|
|
798
|
-
|
|
799
|
-
function _getRelativeImport(_x24, _x25) {
|
|
800
|
-
return _getRelativeImport2.apply(this, arguments);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
return _getRelativeImport;
|
|
804
|
-
}()
|
|
805
|
-
/**
|
|
806
|
-
* @param {ServiceFile} serviceFile
|
|
807
|
-
*/
|
|
808
|
-
|
|
809
|
-
}, {
|
|
810
|
-
key: "serviceFile",
|
|
811
|
-
get:
|
|
812
|
-
/**
|
|
813
|
-
* @returns {ServiceFile}
|
|
814
|
-
*/
|
|
815
|
-
function get() {
|
|
816
|
-
return this._serviceFile;
|
|
817
|
-
},
|
|
818
|
-
set: function set(serviceFile) {
|
|
819
|
-
this._serviceFile = serviceFile;
|
|
820
|
-
}
|
|
821
|
-
}]);
|
|
822
|
-
return Autowire;
|
|
823
|
-
}();
|
|
824
|
-
|
|
825
|
-
exports["default"] = Autowire;
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _path=_interopRequireDefault(require("path"));var _fs=_interopRequireDefault(require("fs"));var _json=_interopRequireDefault(require("json5"));var _typescriptEstree=require("@typescript-eslint/typescript-estree");var _Definition=_interopRequireDefault(require("./Definition"));var _Reference=_interopRequireDefault(require("./Reference"));var _ServiceFile=_interopRequireDefault(require("./ServiceFile"));var _AutowireIdentifier=_interopRequireDefault(require("./AutowireIdentifier"));var _ContainerDefaultDirMustBeSet=_interopRequireDefault(require("./Exception/ContainerDefaultDirMustBeSet"));function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};},e:function e(_e){throw _e;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o);},n:function n(){var step=it.next();normalCompletion=step.done;return step;},e:function e(_e2){didErr=true;err=_e2;},f:function f(){try{if(!normalCompletion&&it["return"]!=null)it["return"]();}finally{if(didErr)throw err;}}};}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}var Autowire=function(){function Autowire(container){var tsConfigFullPath=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;(0,_classCallCheck2["default"])(this,Autowire);this._ensureContainerIsValidForAutowire(container);this._rootDirectory=container.defaultDir;this._container=container;this._excludedFolders=[];this._serviceFile=null;try{this._tsConfigFullPath=tsConfigFullPath||_path["default"].join(process.cwd(),'tsconfig.json');this._tsConfigPaths=_json["default"].parse(_fs["default"].readFileSync(this._tsConfigFullPath,'utf-8')).compilerOptions.paths;}catch(e){this._tsConfigPaths=null;}}(0,_createClass2["default"])(Autowire,[{key:"_ensureContainerIsValidForAutowire",value:function _ensureContainerIsValidForAutowire(container){if(container.defaultDir===null){throw new _ContainerDefaultDirMustBeSet["default"]();}}},{key:"container",get:function get(){return this._container;}},{key:"_walk",value:_regenerator["default"].mark(function _walk(dir){var files,_iterator,_step,file,filePath;return _regenerator["default"].wrap(function _walk$(_context){while(1){switch(_context.prev=_context.next){case 0:files=_fs["default"].readdirSync(dir,{withFileTypes:true});_iterator=_createForOfIteratorHelper(files);_context.prev=2;_iterator.s();case 4:if((_step=_iterator.n()).done){_context.next=20;break;}file=_step.value;if(!file.isDirectory()){_context.next=9;break;}return _context.delegateYield(this._walk(_path["default"].join(dir,file.name)),"t0",8);case 8:return _context.abrupt("continue",18);case 9:filePath=_path["default"].join(dir,file.name);_context.prev=10;this._ensureFileIsNotExcluded(filePath);_context.next=14;return filePath;case 14:_context.next=18;break;case 16:_context.prev=16;_context.t1=_context["catch"](10);case 18:_context.next=4;break;case 20:_context.next=25;break;case 22:_context.prev=22;_context.t2=_context["catch"](2);_iterator.e(_context.t2);case 25:_context.prev=25;_iterator.f();return _context.finish(25);case 28:case"end":return _context.stop();}}},_walk,this,[[2,22,25,28],[10,16]]);})},{key:"_ensureFileIsNotExcluded",value:function _ensureFileIsNotExcluded(filePath){this._excludedFolders.forEach(function(excludedFolder){if(filePath.includes(excludedFolder)){throw new Error('Excluded Folder!');}});}},{key:"addExclude",value:function addExclude(relativePath){var fullPathToExclude=_path["default"].join(this._rootDirectory,relativePath);this._excludedFolders.push(fullPathToExclude);}},{key:"_getServiceIdFromPath",value:function(){var _getServiceIdFromPath2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(path,type){var extension,readableId,_args2=arguments;return _regenerator["default"].wrap(function _callee$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:extension=_args2.length>2&&_args2[2]!==undefined?_args2[2]:'.ts';readableId=path.replace(/\//g,'__').replace(extension,'').replace('@','__').concat("__".concat(type));return _context2.abrupt("return",_AutowireIdentifier["default"].encode(readableId));case 3:case"end":return _context2.stop();}}},_callee);}));function _getServiceIdFromPath(_x,_x2){return _getServiceIdFromPath2.apply(this,arguments);}return _getServiceIdFromPath;}()},{key:"process",value:function(){var _process=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(){var promises,_iterator2,_step2,filePath;return _regenerator["default"].wrap(function _callee2$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:promises=[];_iterator2=_createForOfIteratorHelper(this._walk(this._rootDirectory));try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){filePath=_step2.value;promises.push(this._executeFilePath(filePath));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}_context3.next=5;return Promise.all(promises);case 5:if(!(this._serviceFile instanceof _ServiceFile["default"])){_context3.next=8;break;}_context3.next=8;return this._serviceFile.generateFromContainer(this._container);case 8:case"end":return _context3.stop();}}},_callee2,this);}));function process(){return _process.apply(this,arguments);}return process;}()},{key:"_executeFilePath",value:function(){var _executeFilePath2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee3(filePath){var parsedFile,_yield$this$_getClass,classDeclaration,body,Class,definition,serviceId;return _regenerator["default"].wrap(function _callee3$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:parsedFile=_path["default"].parse(filePath);if(!(parsedFile.ext!=='.ts')){_context4.next=3;break;}return _context4.abrupt("return");case 3:_context4.next=5;return this._getClassDeclaration(filePath);case 5:_yield$this$_getClass=_context4.sent;classDeclaration=_yield$this$_getClass.classDeclaration;body=_yield$this$_getClass.body;if(classDeclaration){_context4.next=10;break;}return _context4.abrupt("return");case 10:Class=require(filePath)["default"];if(Class){_context4.next=13;break;}return _context4.abrupt("return");case 13:_context4.next=15;return this._getDefinition(classDeclaration,body,parsedFile,Class);case 15:definition=_context4.sent;if(definition){_context4.next=18;break;}return _context4.abrupt("return");case 18:_context4.next=20;return this._getServiceIdFromPath(filePath,Class.name);case 20:serviceId=_context4.sent;this.container.setDefinition(serviceId,definition);_context4.next=24;return this._interfaceImplementations(classDeclaration,body,parsedFile,serviceId);case 24:case"end":return _context4.stop();}}},_callee3,this);}));function _executeFilePath(_x3){return _executeFilePath2.apply(this,arguments);}return _executeFilePath;}()},{key:"_getClassDeclaration",value:function(){var _getClassDeclaration2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee4(filePath){var sourceCode,body,classDeclaration;return _regenerator["default"].wrap(function _callee4$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:sourceCode=_fs["default"].readFileSync(filePath,'utf8');body=(0,_typescriptEstree.parse)(sourceCode).body;classDeclaration=body.find(function(declaration){return declaration.type==='ExportDefaultDeclaration';});return _context5.abrupt("return",{classDeclaration:classDeclaration,body:body});case 4:case"end":return _context5.stop();}}},_callee4);}));function _getClassDeclaration(_x4){return _getClassDeclaration2.apply(this,arguments);}return _getClassDeclaration;}()},{key:"_getDefinition",value:function(){var _getDefinition2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee5(classDeclaration,body,parsedFile,ServiceClass){var definition,constructorParams,_iterator3,_step3,parameterDeclaration,typeNameForArgument,argumentId;return _regenerator["default"].wrap(function _callee5$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:_context6.prev=0;definition=new _Definition["default"](ServiceClass);_context6.next=4;return this._getConstructorParamsByDefinition(definition,classDeclaration,body,parsedFile);case 4:constructorParams=_context6.sent;_iterator3=_createForOfIteratorHelper(constructorParams);_context6.prev=6;_iterator3.s();case 8:if((_step3=_iterator3.n()).done){_context6.next=19;break;}parameterDeclaration=_step3.value;typeNameForArgument=parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;_context6.next=13;return this._getIdentifierFromImports(typeNameForArgument,body,parsedFile);case 13:argumentId=_context6.sent;if(argumentId){_context6.next=16;break;}return _context6.abrupt("continue",17);case 16:definition.addArgument(new _Reference["default"](argumentId),definition["abstract"]);case 17:_context6.next=8;break;case 19:_context6.next=24;break;case 21:_context6.prev=21;_context6.t0=_context6["catch"](6);_iterator3.e(_context6.t0);case 24:_context6.prev=24;_iterator3.f();return _context6.finish(24);case 27:return _context6.abrupt("return",definition);case 30:_context6.prev=30;_context6.t1=_context6["catch"](0);case 32:case"end":return _context6.stop();}}},_callee5,this,[[0,30],[6,21,24,27]]);}));function _getDefinition(_x5,_x6,_x7,_x8){return _getDefinition2.apply(this,arguments);}return _getDefinition;}()},{key:"_getConstructorParamsByDefinition",value:function(){var _getConstructorParamsByDefinition2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee6(definition,classDeclaration,body,parsedFile){var constructorDeclaration;return _regenerator["default"].wrap(function _callee6$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:constructorDeclaration=classDeclaration.declaration.body.body.find(function(method){return method.key.name==='constructor';});if(classDeclaration.declaration["abstract"]){definition["abstract"]=true;}_context7.next=4;return this._parentDefinition(classDeclaration,body,parsedFile,definition);case 4:return _context7.abrupt("return",constructorDeclaration?constructorDeclaration.value.params:[]);case 5:case"end":return _context7.stop();}}},_callee6,this);}));function _getConstructorParamsByDefinition(_x9,_x10,_x11,_x12){return _getConstructorParamsByDefinition2.apply(this,arguments);}return _getConstructorParamsByDefinition;}()},{key:"_parentDefinition",value:function(){var _parentDefinition2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee7(classDeclaration,body,parsedFile,definition){var typeParent,parentId;return _regenerator["default"].wrap(function _callee7$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:if(!classDeclaration.declaration.superClass){_context8.next=6;break;}typeParent=classDeclaration.declaration.superClass.name;_context8.next=4;return this._getIdentifierFromImports(typeParent,body,parsedFile);case 4:parentId=_context8.sent;if(parentId){definition.parent=parentId;}case 6:case"end":return _context8.stop();}}},_callee7,this);}));function _parentDefinition(_x13,_x14,_x15,_x16){return _parentDefinition2.apply(this,arguments);}return _parentDefinition;}()},{key:"_interfaceImplementations",value:function(){var _interfaceImplementations2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee8(classDeclaration,body,parsedFile,serviceId){var _classDeclaration$dec;var implementations,_iterator4,_step4,implement,interfaceType,aliasId;return _regenerator["default"].wrap(function _callee8$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:implementations=(_classDeclaration$dec=classDeclaration.declaration["implements"])!==null&&_classDeclaration$dec!==void 0?_classDeclaration$dec:[];_iterator4=_createForOfIteratorHelper(implementations);_context9.prev=2;_iterator4.s();case 4:if((_step4=_iterator4.n()).done){_context9.next=15;break;}implement=_step4.value;interfaceType=implement.expression.name;_context9.next=9;return this._getIdentifierFromImports(interfaceType,body,parsedFile);case 9:aliasId=_context9.sent;if(!(!aliasId||this.container.hasAlias(aliasId))){_context9.next=12;break;}return _context9.abrupt("continue",13);case 12:this.container.setAlias(aliasId,serviceId);case 13:_context9.next=4;break;case 15:_context9.next=20;break;case 17:_context9.prev=17;_context9.t0=_context9["catch"](2);_iterator4.e(_context9.t0);case 20:_context9.prev=20;_iterator4.f();return _context9.finish(20);case 23:case"end":return _context9.stop();}}},_callee8,this,[[2,17,20,23]]);}));function _interfaceImplementations(_x17,_x18,_x19,_x20){return _interfaceImplementations2.apply(this,arguments);}return _interfaceImplementations;}()},{key:"_getIdentifierFromImports",value:function(){var _getIdentifierFromImports2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee9(type,body,parsedFile){var _this$_tsConfigPaths,rootDir,relativeImportForImplement,configPaths,pathConfig,tsConfigPath,tsRelativePath,parsedTsConfigPath,absolutePathImportForImplement;return _regenerator["default"].wrap(function _callee9$(_context10){while(1){switch(_context10.prev=_context10.next){case 0:_context10.prev=0;rootDir=parsedFile.dir;_context10.next=4;return this._getRelativeImport(body,type);case 4:relativeImportForImplement=_context10.sent;configPaths=(_this$_tsConfigPaths=this._tsConfigPaths)!==null&&_this$_tsConfigPaths!==void 0?_this$_tsConfigPaths:[];_context10.t0=_regenerator["default"].keys(configPaths);case 7:if((_context10.t1=_context10.t0()).done){_context10.next=18;break;}pathConfig=_context10.t1.value;tsConfigPath=pathConfig.replace(/\*/g,'');tsRelativePath=this._tsConfigPaths[pathConfig][0].replace(/\*/g,'');if(relativeImportForImplement.includes(tsConfigPath)){_context10.next=13;break;}return _context10.abrupt("continue",7);case 13:relativeImportForImplement=relativeImportForImplement.replace(tsConfigPath,tsRelativePath);parsedTsConfigPath=_path["default"].parse(this._tsConfigFullPath);rootDir=parsedTsConfigPath.dir;_context10.next=7;break;case 18:absolutePathImportForImplement=_path["default"].join(rootDir,relativeImportForImplement);return _context10.abrupt("return",this._getServiceIdFromPath(absolutePathImportForImplement,type));case 22:_context10.prev=22;_context10.t2=_context10["catch"](0);case 24:case"end":return _context10.stop();}}},_callee9,this,[[0,22]]);}));function _getIdentifierFromImports(_x21,_x22,_x23){return _getIdentifierFromImports2.apply(this,arguments);}return _getIdentifierFromImports;}()},{key:"_getRelativeImport",value:function(){var _getRelativeImport2=(0,_asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee10(body,type){return _regenerator["default"].wrap(function _callee10$(_context11){while(1){switch(_context11.prev=_context11.next){case 0:return _context11.abrupt("return",body.find(function(declaration){if(declaration.specifiers){return declaration.specifiers.find(function(specifier){return specifier.local.name===type;});}return null;}).source.value);case 1:case"end":return _context11.stop();}}},_callee10);}));function _getRelativeImport(_x24,_x25){return _getRelativeImport2.apply(this,arguments);}return _getRelativeImport;}()},{key:"serviceFile",get:function get(){return this._serviceFile;},set:function set(serviceFile){this._serviceFile=serviceFile;}}]);return Autowire;}();exports["default"]=Autowire;
|