node-dependency-injection 3.0.0-alpha.1 → 3.0.0-alpha.12
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/README.md +34 -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 +93 -48
- package/dist/lib/Compiler.js +0 -2
- package/dist/lib/InstanceManager.js +10 -2
- 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}
|
|
@@ -145,14 +155,20 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
145
155
|
|
|
146
156
|
if (parsedFile.ext === '.ts') {
|
|
147
157
|
_this$_getClassDeclar = this._getClassDeclaration(filePath), classDeclaration = _this$_getClassDeclar.classDeclaration, body = _this$_getClassDeclar.body;
|
|
148
|
-
Class = require(filePath)["default"];
|
|
149
158
|
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
if (classDeclaration) {
|
|
160
|
+
Class = require(filePath)["default"];
|
|
161
|
+
|
|
162
|
+
if (Class) {
|
|
163
|
+
definition = this._getDefinition(classDeclaration, body, parsedFile, Class);
|
|
154
164
|
|
|
155
|
-
|
|
165
|
+
if (definition) {
|
|
166
|
+
serviceId = this._getServiceIdFromPath(filePath, Class.name);
|
|
167
|
+
this.container.setDefinition(serviceId, definition);
|
|
168
|
+
|
|
169
|
+
this._interfaceImplementations(classDeclaration, body, parsedFile, serviceId);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
156
172
|
}
|
|
157
173
|
}
|
|
158
174
|
}
|
|
@@ -181,7 +197,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
181
197
|
value: function _getClassDeclaration(filePath) {
|
|
182
198
|
var sourceCode = _fs["default"].readFileSync(filePath, 'utf8');
|
|
183
199
|
|
|
184
|
-
var body = (0,
|
|
200
|
+
var body = (0, _typescriptEstree.parse)(sourceCode).body;
|
|
185
201
|
var classDeclaration = body.find(function (declaration) {
|
|
186
202
|
return declaration.type === 'ExportDefaultDeclaration';
|
|
187
203
|
});
|
|
@@ -193,44 +209,52 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
193
209
|
}, {
|
|
194
210
|
key: "_getDefinition",
|
|
195
211
|
value: function _getDefinition(classDeclaration, body, parsedFile, ServiceClass) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
212
|
+
try {
|
|
213
|
+
var definition = new _Definition["default"](ServiceClass);
|
|
214
|
+
var constructorDeclaration = classDeclaration.declaration.body.body.find(function (method) {
|
|
215
|
+
return method.key.name === 'constructor';
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (classDeclaration.declaration["abstract"]) {
|
|
219
|
+
definition["abstract"] = true;
|
|
220
|
+
}
|
|
204
221
|
|
|
205
|
-
|
|
206
|
-
|
|
222
|
+
if (classDeclaration.declaration.superClass) {
|
|
223
|
+
var typeParent = classDeclaration.declaration.superClass.name;
|
|
207
224
|
|
|
208
|
-
|
|
225
|
+
var parentId = this._getIdentifierFromImports(typeParent, body, parsedFile);
|
|
209
226
|
|
|
210
|
-
|
|
211
|
-
|
|
227
|
+
if (parentId) {
|
|
228
|
+
definition.parent = parentId;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
212
231
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
232
|
+
if (constructorDeclaration) {
|
|
233
|
+
var _iterator3 = _createForOfIteratorHelper(constructorDeclaration.value.params),
|
|
234
|
+
_step3;
|
|
216
235
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
236
|
+
try {
|
|
237
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
238
|
+
var parameterDeclaration = _step3.value;
|
|
239
|
+
var typeNameForArgument = parameterDeclaration.parameter.typeAnnotation.typeAnnotation.typeName.name;
|
|
221
240
|
|
|
222
|
-
|
|
241
|
+
var argumentId = this._getIdentifierFromImports(typeNameForArgument, body, parsedFile);
|
|
223
242
|
|
|
224
|
-
|
|
243
|
+
if (argumentId) {
|
|
244
|
+
definition.addArgument(new _Reference["default"](argumentId), definition["abstract"]);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} catch (err) {
|
|
248
|
+
_iterator3.e(err);
|
|
249
|
+
} finally {
|
|
250
|
+
_iterator3.f();
|
|
225
251
|
}
|
|
226
|
-
} catch (err) {
|
|
227
|
-
_iterator3.e(err);
|
|
228
|
-
} finally {
|
|
229
|
-
_iterator3.f();
|
|
230
252
|
}
|
|
231
|
-
}
|
|
232
253
|
|
|
233
|
-
|
|
254
|
+
return definition;
|
|
255
|
+
} catch (e) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
234
258
|
}
|
|
235
259
|
}, {
|
|
236
260
|
key: "_interfaceImplementations",
|
|
@@ -246,7 +270,7 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
246
270
|
|
|
247
271
|
var aliasId = this._getIdentifierFromImports(interfaceType, body, parsedFile);
|
|
248
272
|
|
|
249
|
-
if (this.container.hasAlias(aliasId) === false) {
|
|
273
|
+
if (aliasId && this.container.hasAlias(aliasId) === false) {
|
|
250
274
|
this.container.setAlias(aliasId, serviceId);
|
|
251
275
|
}
|
|
252
276
|
}
|
|
@@ -260,19 +284,40 @@ var Autowire = /*#__PURE__*/function () {
|
|
|
260
284
|
}, {
|
|
261
285
|
key: "_getIdentifierFromImports",
|
|
262
286
|
value: function _getIdentifierFromImports(type, body, parsedFile) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
287
|
+
try {
|
|
288
|
+
var rootDir = parsedFile.dir;
|
|
289
|
+
var relativeImportForImplement = body.find(function (declaration) {
|
|
290
|
+
if (declaration.specifiers) {
|
|
291
|
+
return declaration.specifiers.find(function (specifier) {
|
|
292
|
+
return specifier.local.name === type;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
269
295
|
|
|
270
|
-
|
|
271
|
-
|
|
296
|
+
return null;
|
|
297
|
+
}).source.value;
|
|
298
|
+
|
|
299
|
+
if (this._tsConfigPaths) {
|
|
300
|
+
for (var pathConfig in this._tsConfigPaths) {
|
|
301
|
+
var tsConfigPath = pathConfig.replace(/\*/g, '');
|
|
302
|
+
var tsRelativePath = this._tsConfigPaths[pathConfig][0];
|
|
303
|
+
tsRelativePath = tsRelativePath.replace(/\*/g, '');
|
|
272
304
|
|
|
273
|
-
|
|
305
|
+
if (relativeImportForImplement.includes(tsConfigPath)) {
|
|
306
|
+
relativeImportForImplement = relativeImportForImplement.replace(tsConfigPath, tsRelativePath);
|
|
274
307
|
|
|
275
|
-
|
|
308
|
+
var parsedTsConfigPath = _path["default"].parse(this._tsConfigFullPath);
|
|
309
|
+
|
|
310
|
+
rootDir = parsedTsConfigPath.dir;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
var absolutePathImportForImplement = _path["default"].join(rootDir, relativeImportForImplement);
|
|
316
|
+
|
|
317
|
+
return this._getServiceIdFromPath(absolutePathImportForImplement, type);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
276
321
|
}
|
|
277
322
|
}]);
|
|
278
323
|
return Autowire;
|
package/dist/lib/Compiler.js
CHANGED
|
@@ -89,7 +89,7 @@ var InstanceManager = /*#__PURE__*/function () {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
this._containerBuilder.logger.warn("The service ".concat(id, " is not registered"));
|
|
92
|
+
this._containerBuilder.logger.warn("The service ".concat(typeof id === 'function' ? id.name : id, " is not registered"));
|
|
93
93
|
|
|
94
94
|
throw new _ServiceNotFoundException["default"](id);
|
|
95
95
|
}
|
|
@@ -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.12",
|
|
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": {
|