node-dependency-injection 3.0.0-alpha.5 → 3.0.0-alpha.8
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/lib/Autowire.js +68 -53
- package/package.json +1 -1
package/dist/lib/Autowire.js
CHANGED
|
@@ -157,10 +157,13 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
157
157
|
|
|
158
158
|
if (Class && classDeclaration) {
|
|
159
159
|
definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
160
|
-
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
161
|
-
this.container.setDefinition(serviceId, definition);
|
|
162
160
|
|
|
163
|
-
|
|
161
|
+
if (definition) {
|
|
162
|
+
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
163
|
+
this.container.setDefinition(serviceId, definition);
|
|
164
|
+
|
|
165
|
+
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
166
|
+
}
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
@@ -201,44 +204,52 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
201
204
|
}, {
|
|
202
205
|
key: "_getDefinition",
|
|
203
206
|
value: function _getDefinition(classDeclaration, body, parsedFile, ServiceClass) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
try {
|
|
208
|
+
var definition = new _Definition["default"](ServiceClass);
|
|
209
|
+
var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
|
|
210
|
+
return method.key.name === 'constructor';
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (classDeclaration.declaration["abstract"]) {
|
|
214
|
+
definition["abstract"] = true;
|
|
215
|
+
}
|
|
212
216
|
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
if (classDeclaration.declaration.superClass) {
|
|
218
|
+
var typeParent = classDeclaration.declaration.superClass.name;
|
|
215
219
|
|
|
216
|
-
|
|
220
|
+
var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
217
221
|
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
if (parentId) {
|
|
223
|
+
definition.parent = parentId;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
if (constructorDeclaration) {
|
|
228
|
+
var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
|
|
229
|
+
_step3;
|
|
224
230
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
231
|
+
try {
|
|
232
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
233
|
+
var parameterDeclaration = _step3.value;
|
|
234
|
+
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
229
235
|
|
|
230
|
-
|
|
236
|
+
var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
231
237
|
|
|
232
|
-
|
|
238
|
+
if (argumentId) {
|
|
239
|
+
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
} catch (err) {
|
|
243
|
+
_iterator3.e(err);
|
|
244
|
+
} finally {
|
|
245
|
+
_iterator3.f();
|
|
233
246
|
}
|
|
234
|
-
} catch (err) {
|
|
235
|
-
_iterator3.e(err);
|
|
236
|
-
} finally {
|
|
237
|
-
_iterator3.f();
|
|
238
247
|
}
|
|
239
|
-
}
|
|
240
248
|
|
|
241
|
-
|
|
249
|
+
return definition;
|
|
250
|
+
} catch (e) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
242
253
|
}
|
|
243
254
|
}, {
|
|
244
255
|
key: "_interfaceImplementations",
|
|
@@ -254,7 +265,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
254
265
|
|
|
255
266
|
var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
256
267
|
|
|
257
|
-
if (this.container.hasAlias(aliasId) === false) {
|
|
268
|
+
if (aliasId && this.container.hasAlias(aliasId) === false) {
|
|
258
269
|
this.container.setAlias(aliasId, serviceId);
|
|
259
270
|
}
|
|
260
271
|
}
|
|
@@ -268,36 +279,40 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
268
279
|
}, {
|
|
269
280
|
key: "_getIdentifierFromImports",
|
|
270
281
|
value: function _getIdentifierFromImports(type, body, parsedFile) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
282
|
+
try {
|
|
283
|
+
var rootDir = parsedFile.dir;
|
|
284
|
+
var relativeImportForImplement = body.find(function (declaration) {
|
|
285
|
+
if (declaration.specifiers) {
|
|
286
|
+
return declaration.specifiers.find(function (specifier) {
|
|
287
|
+
return specifier.local.name === type;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
278
290
|
|
|
279
|
-
|
|
280
|
-
|
|
291
|
+
return null;
|
|
292
|
+
}).source.value;
|
|
281
293
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
294
|
+
if (this._tsConfigPaths) {
|
|
295
|
+
for (var pathConfig in this._tsConfigPaths) {
|
|
296
|
+
var tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
297
|
+
var tsRelativePath = this._tsConfigPaths[pathConfig][0];
|
|
298
|
+
tsRelativePath = tsRelativePath.replace(/\*/g, '');
|
|
287
299
|
|
|
288
|
-
|
|
289
|
-
|
|
300
|
+
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
301
|
+
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
290
302
|
|
|
291
|
-
|
|
303
|
+
var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
292
304
|
|
|
293
|
-
|
|
305
|
+
rootDir = parsedTsConfigPath.dir;
|
|
306
|
+
}
|
|
294
307
|
}
|
|
295
308
|
}
|
|
296
|
-
}
|
|
297
309
|
|
|
298
|
-
|
|
310
|
+
var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
299
311
|
|
|
300
|
-
|
|
312
|
+
return this._getServiceIdFromPath(absolutePathImportForImplement, type);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
301
316
|
}
|
|
302
317
|
}]);
|
|
303
318
|
return Autowire;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-dependency-injection",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.8",
|
|
4
4
|
"description": "The NodeDependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.",
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"directories": {
|