node-dependency-injection 3.0.0-alpha.1 → 3.0.0-alpha.10
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/.nyc_output/65e34a77-efb9-4bcf-803d-282fd660b5a8.json +1 -0
- package/.nyc_output/f2f58129-8a27-4ea1-94b2-d5913ef6944d.json +1 -0
- package/.nyc_output/processinfo/65e34a77-efb9-4bcf-803d-282fd660b5a8.json +1 -0
- package/.nyc_output/processinfo/f2f58129-8a27-4ea1-94b2-d5913ef6944d.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/bin/Services/File/BaseAdapter.js.html +158 -0
- package/coverage/lcov-report/bin/Services/File/FileManager.js.html +176 -0
- package/coverage/lcov-report/bin/Services/File/JsAdapter.js.html +140 -0
- package/coverage/lcov-report/bin/Services/File/JsonAdapter.js.html +131 -0
- package/coverage/lcov-report/bin/Services/File/YamlAdapter.js.html +155 -0
- package/coverage/lcov-report/bin/Services/File/index.html +171 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +171 -0
- package/coverage/lcov-report/lib/Autowire.js.html +506 -0
- package/coverage/lcov-report/lib/Compiler.js.html +239 -0
- package/coverage/lcov-report/lib/CompilerPass/DecoratePass.js.html +248 -0
- package/coverage/lcov-report/lib/CompilerPass/OptimizePass.js.html +128 -0
- package/coverage/lcov-report/lib/CompilerPass/RemovePass.js.html +116 -0
- package/coverage/lcov-report/lib/CompilerPass/index.html +156 -0
- package/coverage/lcov-report/lib/CompilerPass/index.js.html +326 -0
- package/coverage/lcov-report/lib/ContainerBuilder.js.html +1115 -0
- package/coverage/lcov-report/lib/Definition.js.html +962 -0
- package/coverage/lcov-report/lib/Exception/AbstractServiceException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/AttributesMapException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/ConfigurationFileNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/DefinitionNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/FrozenContainerException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/LoadMethodNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/LoggerWarnMethodNotFoundException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/MethodCallEmptyException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/MethodCallNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/NotAbstractServiceException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/PrivateServiceException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/ProcessMethodNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/ServiceCircularReferenceException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/ServiceFileNotFoundException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/ServiceFileNotLoadedException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/ServiceNotFoundException.js.html +113 -0
- package/coverage/lcov-report/lib/Exception/WrongCompilerPassTypeException.js.html +110 -0
- package/coverage/lcov-report/lib/Exception/WrongDefinitionException.js.html +101 -0
- package/coverage/lcov-report/lib/Exception/index.html +366 -0
- package/coverage/lcov-report/lib/InstanceManager.js.html +839 -0
- package/coverage/lcov-report/lib/Loader/FileLoader.js.html +1034 -0
- package/coverage/lcov-report/lib/Loader/JsFileLoader.js.html +155 -0
- package/coverage/lcov-report/lib/Loader/JsonFileLoader.js.html +98 -0
- package/coverage/lcov-report/lib/Loader/YamlFileLoader.js.html +188 -0
- package/coverage/lcov-report/lib/Loader/index.html +156 -0
- package/coverage/lcov-report/lib/PackageReference.js.html +131 -0
- package/coverage/lcov-report/lib/PassConfig.js.html +230 -0
- package/coverage/lcov-report/lib/Reference.js.html +158 -0
- package/coverage/lcov-report/lib/TagReference.js.html +131 -0
- package/coverage/lcov-report/lib/index.html +231 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov.info +1516 -0
- package/dist/lib/Autowire.js +87 -45
- package/dist/lib/InstanceManager.js +9 -1
- package/dist/lib/index.js +9 -1
- package/dist/lib/types/index.d.ts +9 -1
- package/package.json +10 -5
- package/tsconfig.json +8 -1
package/dist/lib/Autowire.js
CHANGED
|
@@ -19,7 +19,9 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
19
19
|
|
|
20
20
|
var _fs = _interopRequireDefault(require("fs"));
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _json = _interopRequireDefault(require("json5"));
|
|
23
|
+
|
|
24
|
+
var _typescriptEstree = require("@typescript-eslint/typescript-estree");
|
|
23
25
|
|
|
24
26
|
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
25
27
|
|
|
@@ -33,10 +35,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
33
35
|
|
|
34
36
|
var Autowire = /*#__PURE__*/function () {
|
|
35
37
|
function Autowire(container) {
|
|
38
|
+
var tsConfigFullPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
36
39
|
(0, _classCallCheck2["default"])(this, Autowire);
|
|
37
40
|
this._interfaceImplementation = new Map();
|
|
38
41
|
this._rootDirectory = container.defaultDir;
|
|
39
42
|
this._container = container;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
this._tsConfigFullPath = tsConfigFullPath || _path["default"].join(process.cwd(), 'tsconfig.json');
|
|
46
|
+
this._tsConfigPaths = _json["default"].parse(_fs["default"].readFileSync(this._tsConfigFullPath, 'utf-8')).compilerOptions.paths;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
this._tsConfigPaths = null;
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* @return {ContainerBuilder}
|
|
@@ -120,7 +130,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
120
130
|
key: "_getServiceIdFromPath",
|
|
121
131
|
value: function _getServiceIdFromPath(path, type) {
|
|
122
132
|
var extension = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.ts';
|
|
123
|
-
return path.replace(/\//g, '_').replace(extension, '').concat("_".concat(type));
|
|
133
|
+
return path.replace(/\//g, '_').replace(extension, '').replace('@', '_').concat("_".concat(type));
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
* @returns {void}
|
|
@@ -149,10 +159,13 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
149
159
|
|
|
150
160
|
if (Class && classDeclaration) {
|
|
151
161
|
definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
152
|
-
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
153
|
-
this.container.setDefinition(serviceId, definition);
|
|
154
162
|
|
|
155
|
-
|
|
163
|
+
if (definition) {
|
|
164
|
+
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
165
|
+
this.container.setDefinition(serviceId, definition);
|
|
166
|
+
|
|
167
|
+
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
168
|
+
}
|
|
156
169
|
}
|
|
157
170
|
}
|
|
158
171
|
}
|
|
@@ -181,7 +194,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
181
194
|
value: function _getClassDeclaration(filePath) {
|
|
182
195
|
var sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
|
|
183
196
|
|
|
184
|
-
var body = (0,
|
|
197
|
+
var body = (0, _typescriptEstree.parse)(sourceCode).body;
|
|
185
198
|
var classDeclaration = body.find(function (declaration) {
|
|
186
199
|
return declaration.type === 'ExportDefaultDeclaration';
|
|
187
200
|
});
|
|
@@ -193,44 +206,52 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
193
206
|
}, {
|
|
194
207
|
key: "_getDefinition",
|
|
195
208
|
value: function _getDefinition(classDeclaration, body, parsedFile, ServiceClass) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
209
|
+
try {
|
|
210
|
+
var definition = new _Definition["default"](ServiceClass);
|
|
211
|
+
var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
|
|
212
|
+
return method.key.name === 'constructor';
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (classDeclaration.declaration["abstract"]) {
|
|
216
|
+
definition["abstract"] = true;
|
|
217
|
+
}
|
|
204
218
|
|
|
205
|
-
|
|
206
|
-
|
|
219
|
+
if (classDeclaration.declaration.superClass) {
|
|
220
|
+
var typeParent = classDeclaration.declaration.superClass.name;
|
|
207
221
|
|
|
208
|
-
|
|
222
|
+
var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
209
223
|
|
|
210
|
-
|
|
211
|
-
|
|
224
|
+
if (parentId) {
|
|
225
|
+
definition.parent = parentId;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
212
228
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
229
|
+
if (constructorDeclaration) {
|
|
230
|
+
var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
|
|
231
|
+
_step3;
|
|
216
232
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
233
|
+
try {
|
|
234
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
235
|
+
var parameterDeclaration = _step3.value;
|
|
236
|
+
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
221
237
|
|
|
222
|
-
|
|
238
|
+
var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
223
239
|
|
|
224
|
-
|
|
240
|
+
if (argumentId) {
|
|
241
|
+
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} catch (err) {
|
|
245
|
+
_iterator3.e(err);
|
|
246
|
+
} finally {
|
|
247
|
+
_iterator3.f();
|
|
225
248
|
}
|
|
226
|
-
} catch (err) {
|
|
227
|
-
_iterator3.e(err);
|
|
228
|
-
} finally {
|
|
229
|
-
_iterator3.f();
|
|
230
249
|
}
|
|
231
|
-
}
|
|
232
250
|
|
|
233
|
-
|
|
251
|
+
return definition;
|
|
252
|
+
} catch (e) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
234
255
|
}
|
|
235
256
|
}, {
|
|
236
257
|
key: "_interfaceImplementations",
|
|
@@ -246,7 +267,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
246
267
|
|
|
247
268
|
var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
248
269
|
|
|
249
|
-
if (this.container.hasAlias(aliasId) === false) {
|
|
270
|
+
if (aliasId && this.container.hasAlias(aliasId) === false) {
|
|
250
271
|
this.container.setAlias(aliasId, serviceId);
|
|
251
272
|
}
|
|
252
273
|
}
|
|
@@ -260,19 +281,40 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
260
281
|
}, {
|
|
261
282
|
key: "_getIdentifierFromImports",
|
|
262
283
|
value: function _getIdentifierFromImports(type, body, parsedFile) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
284
|
+
try {
|
|
285
|
+
var rootDir = parsedFile.dir;
|
|
286
|
+
var relativeImportForImplement = body.find(function (declaration) {
|
|
287
|
+
if (declaration.specifiers) {
|
|
288
|
+
return declaration.specifiers.find(function (specifier) {
|
|
289
|
+
return specifier.local.name === type;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
269
292
|
|
|
270
|
-
|
|
271
|
-
|
|
293
|
+
return null;
|
|
294
|
+
}).source.value;
|
|
295
|
+
|
|
296
|
+
if (this._tsConfigPaths) {
|
|
297
|
+
for (var pathConfig in this._tsConfigPaths) {
|
|
298
|
+
var tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
299
|
+
var tsRelativePath = this._tsConfigPaths[pathConfig][0];
|
|
300
|
+
tsRelativePath = tsRelativePath.replace(/\*/g, '');
|
|
301
|
+
|
|
302
|
+
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
303
|
+
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
272
304
|
|
|
273
|
-
|
|
305
|
+
var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
274
306
|
|
|
275
|
-
|
|
307
|
+
rootDir = parsedTsConfigPath.dir;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
313
|
+
|
|
314
|
+
return this._getServiceIdFromPath(absolutePathImportForImplement, type);
|
|
315
|
+
} catch (e) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
276
318
|
}
|
|
277
319
|
}]);
|
|
278
320
|
return Autowire;
|
|
@@ -183,7 +183,15 @@ var InstanceManager = /*#__PURE__*/function () {
|
|
|
183
183
|
var args = this._resolveArguments(definition.args);
|
|
184
184
|
|
|
185
185
|
if (definition.parent) {
|
|
186
|
-
|
|
186
|
+
try {
|
|
187
|
+
args = this._appendParentArgumentsFromDefinition(definition, args);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
if (e instanceof _NotAbstractServiceException["default"]) {
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
args = [];
|
|
194
|
+
}
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
var instance = (0, _construct2["default"])(definition.Object, (0, _toConsumableArray2["default"])(args));
|
package/dist/lib/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "Autowire", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _Autowire["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
Object.defineProperty(exports, "ContainerBuilder", {
|
|
9
15
|
enumerable: true,
|
|
10
16
|
get: function get() {
|
|
@@ -76,4 +82,6 @@ var _PassConfig = _interopRequireDefault(require("./PassConfig"));
|
|
|
76
82
|
|
|
77
83
|
var _Definition = _interopRequireDefault(require("./Definition"));
|
|
78
84
|
|
|
79
|
-
var _TagReference = _interopRequireDefault(require("./TagReference"));
|
|
85
|
+
var _TagReference = _interopRequireDefault(require("./TagReference"));
|
|
86
|
+
|
|
87
|
+
var _Autowire = _interopRequireDefault(require("./Autowire"));
|
|
@@ -62,7 +62,7 @@ export class ContainerBuilder {
|
|
|
62
62
|
|
|
63
63
|
findTaggedServiceIds(name: string): Map<any, any>;
|
|
64
64
|
|
|
65
|
-
get<T = any>(id: string): T;
|
|
65
|
+
get<T = any>(id: string|any): T;
|
|
66
66
|
|
|
67
67
|
getDefinition(key: string): Definition;
|
|
68
68
|
|
|
@@ -171,3 +171,11 @@ export class JsFileLoader extends FileLoader {
|
|
|
171
171
|
|
|
172
172
|
export class JsonFileLoader extends JsFileLoader {
|
|
173
173
|
}
|
|
174
|
+
|
|
175
|
+
export class Autowire {
|
|
176
|
+
constructor (container: ContainerBuilder);
|
|
177
|
+
|
|
178
|
+
get container (): ContainerBuilder;
|
|
179
|
+
|
|
180
|
+
process (): Promise<void>;
|
|
181
|
+
}
|
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.10",
|
|
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": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"ndi": "dist/bin/ndi.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "cross-env NODE_ENV=test mocha
|
|
15
|
-
"test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha",
|
|
14
|
+
"test": "cross-env NODE_ENV=test ts-mocha --paths",
|
|
15
|
+
"test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ts-mocha --paths",
|
|
16
16
|
"test:standard": "standard",
|
|
17
17
|
"test:standard:fix": "standard --fix",
|
|
18
18
|
"build:lib": "rm -rf dist/lib/* && babel lib -d dist/lib -D",
|
|
@@ -51,11 +51,13 @@
|
|
|
51
51
|
"homepage": "https://github.com/zazoomauro/node-dependency-injection#readme",
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
54
|
-
"@
|
|
54
|
+
"@babel/runtime": "^7.17.9",
|
|
55
|
+
"@typescript-eslint/typescript-estree": "^5.23.0",
|
|
55
56
|
"chalk": "^4.1.0",
|
|
56
57
|
"commander": "^8.3.0",
|
|
57
58
|
"console.table": "^0.10.0",
|
|
58
59
|
"js-yaml": "^4.0.0",
|
|
60
|
+
"json5": "^2.2.1",
|
|
59
61
|
"validate-npm-package-name": "^3.0.0"
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
@@ -64,6 +66,7 @@
|
|
|
64
66
|
"@babel/preset-env": "^7.17.10",
|
|
65
67
|
"@babel/register": "^7.17.7",
|
|
66
68
|
"@types/chai": "^4.3.1",
|
|
69
|
+
"@types/expect": "^24.3.0",
|
|
67
70
|
"@types/mocha": "^9.1.1",
|
|
68
71
|
"babel-plugin-istanbul": "^6.1.1",
|
|
69
72
|
"chai": "^4.3.6",
|
|
@@ -74,7 +77,9 @@
|
|
|
74
77
|
"nyc": "^15.1.0",
|
|
75
78
|
"sinon": "^11.1.2",
|
|
76
79
|
"standard": "^16.0.4",
|
|
80
|
+
"ts-mocha": "^10.0.0",
|
|
77
81
|
"ts-node": "^10.7.0",
|
|
82
|
+
"tsconfig-paths": "^4.0.0",
|
|
78
83
|
"typescript": "^4.6.4"
|
|
79
84
|
},
|
|
80
85
|
"babel": {
|
|
@@ -82,7 +87,7 @@
|
|
|
82
87
|
"@babel/preset-env"
|
|
83
88
|
],
|
|
84
89
|
"plugins": [
|
|
85
|
-
"@babel/
|
|
90
|
+
"@babel/transform-runtime"
|
|
86
91
|
],
|
|
87
92
|
"env": {
|
|
88
93
|
"test": {
|