@expressots/core 2.16.2 → 3.0.0-beta.1
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/README.md +2 -2
- package/lib/CHANGELOG.md +312 -322
- package/lib/README.md +2 -2
- package/lib/cjs/application/application-container.js +18 -21
- package/lib/cjs/application/application-factory.js +4 -5
- package/lib/cjs/{common/server-env.types.js → application/application.types.js} +1 -0
- package/lib/cjs/application/index.js +3 -1
- package/lib/cjs/console/console.js +8 -20
- package/lib/cjs/container-module/container-module.js +10 -18
- package/lib/cjs/decorator/scope-binding.js +12 -11
- package/lib/cjs/di/annotation/decorator_utils.js +121 -0
- package/lib/cjs/di/annotation/inject.js +44 -0
- package/lib/cjs/di/annotation/inject_base.js +17 -0
- package/lib/cjs/di/annotation/injectable.js +43 -0
- package/lib/cjs/di/annotation/lazy_service_identifier.js +12 -0
- package/lib/cjs/di/annotation/multi_inject.js +30 -0
- package/lib/cjs/di/annotation/named.js +34 -0
- package/lib/cjs/di/annotation/optional.js +32 -0
- package/lib/cjs/di/annotation/post_construct.js +31 -0
- package/lib/cjs/di/annotation/pre_destroy.js +31 -0
- package/lib/cjs/di/annotation/property_event_decorator.js +15 -0
- package/lib/cjs/di/annotation/tagged.js +9 -0
- package/lib/cjs/di/annotation/target_name.js +35 -0
- package/lib/cjs/di/annotation/unmanaged.js +35 -0
- package/lib/cjs/di/binding-decorator/constants.js +7 -0
- package/lib/cjs/di/binding-decorator/decorator/fluent_provide.js +20 -0
- package/lib/cjs/di/binding-decorator/decorator/provide.js +37 -0
- package/lib/cjs/di/binding-decorator/factory/module_factory.js +17 -0
- package/lib/cjs/di/binding-decorator/index.js +14 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_done_syntax.js +42 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_syntax.js +33 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_when_on_syntax.js +64 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_on_syntax.js +22 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_on_syntax.js +57 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_syntax.js +89 -0
- package/lib/cjs/di/binding-decorator/utils/auto_wire.js +18 -0
- package/lib/cjs/di/bindings/binding.js +40 -0
- package/lib/cjs/di/bindings/binding_count.js +8 -0
- package/lib/cjs/di/constants/error_msgs.js +60 -0
- package/lib/cjs/di/constants/literal_types.js +26 -0
- package/lib/cjs/di/constants/metadata_keys.js +38 -0
- package/lib/cjs/di/container/container.js +521 -0
- package/lib/cjs/di/container/container_module.js +18 -0
- package/lib/cjs/di/container/container_snapshot.js +15 -0
- package/lib/cjs/di/container/lookup.js +132 -0
- package/lib/cjs/di/container/module_activation_store.js +49 -0
- package/lib/cjs/di/interfaces/interfaces.js +2 -0
- package/lib/cjs/di/inversify.js +78 -0
- package/lib/cjs/di/planning/context.js +17 -0
- package/lib/cjs/di/planning/metadata.js +42 -0
- package/lib/cjs/di/planning/metadata_reader.js +45 -0
- package/lib/cjs/di/planning/plan.js +10 -0
- package/lib/cjs/di/planning/planner.js +186 -0
- package/lib/cjs/di/planning/queryable_string.js +27 -0
- package/lib/cjs/di/planning/reflection_utils.js +178 -0
- package/lib/cjs/di/planning/request.js +23 -0
- package/lib/cjs/di/planning/target.js +108 -0
- package/lib/cjs/di/resolution/instantiation.js +150 -0
- package/lib/cjs/di/resolution/resolver.js +188 -0
- package/lib/cjs/di/scope/scope.js +50 -0
- package/lib/cjs/di/syntax/binding_in_syntax.js +23 -0
- package/lib/cjs/di/syntax/binding_in_when_on_syntax.js +75 -0
- package/lib/cjs/di/syntax/binding_on_syntax.js +18 -0
- package/lib/cjs/di/syntax/binding_to_syntax.js +111 -0
- package/lib/cjs/di/syntax/binding_when_on_syntax.js +64 -0
- package/lib/cjs/di/syntax/binding_when_syntax.js +84 -0
- package/lib/cjs/di/syntax/constraint_helpers.js +68 -0
- package/lib/cjs/di/utils/async.js +15 -0
- package/lib/cjs/di/utils/binding_utils.js +77 -0
- package/lib/cjs/di/utils/clonable.js +9 -0
- package/lib/cjs/di/utils/exceptions.js +46 -0
- package/lib/cjs/di/utils/factory_type.js +9 -0
- package/lib/cjs/di/utils/id.js +7 -0
- package/lib/cjs/di/utils/js.js +15 -0
- package/lib/cjs/di/utils/serialization.js +132 -0
- package/lib/cjs/error/app-error.js +5 -2
- package/lib/cjs/error/report.js +24 -15
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/middleware/middleware-interface.js +2 -0
- package/lib/cjs/middleware/middleware-service.js +9 -24
- package/lib/cjs/provider/db-in-memory/base-repo.repository.js +3 -8
- package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +8 -5
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +4 -4
- package/lib/cjs/provider/dto-validator/package-resolver.js +56 -0
- package/lib/cjs/provider/environment/env-validator.provider.js +14 -12
- package/lib/cjs/provider/logger/logger.provider.js +10 -5
- package/lib/cjs/provider/provider-manager.js +21 -17
- package/lib/cjs/types/application/application-container.d.ts +12 -25
- package/lib/cjs/types/application/application-factory.d.ts +10 -7
- package/lib/cjs/types/{common/server-env.types.d.ts → application/application.types.d.ts} +1 -0
- package/lib/cjs/types/application/index.d.ts +1 -0
- package/lib/cjs/types/console/console.d.ts +3 -10
- package/lib/cjs/types/console/index.d.ts +2 -1
- package/lib/cjs/types/container-module/container-module.d.ts +3 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +9 -9
- package/lib/cjs/types/di/annotation/decorator_utils.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject_base.d.ts +3 -0
- package/lib/cjs/types/di/annotation/injectable.d.ts +7 -0
- package/lib/cjs/types/di/annotation/lazy_service_identifier.d.ts +7 -0
- package/lib/cjs/types/di/annotation/multi_inject.d.ts +2 -0
- package/lib/cjs/types/di/annotation/named.d.ts +2 -0
- package/lib/cjs/types/di/annotation/optional.d.ts +2 -0
- package/lib/cjs/types/di/annotation/post_construct.d.ts +4 -0
- package/lib/cjs/types/di/annotation/pre_destroy.d.ts +4 -0
- package/lib/cjs/types/di/annotation/property_event_decorator.d.ts +4 -0
- package/lib/cjs/types/di/annotation/tagged.d.ts +2 -0
- package/lib/cjs/types/di/annotation/target_name.d.ts +3 -0
- package/lib/cjs/types/di/annotation/unmanaged.d.ts +3 -0
- package/lib/cjs/types/di/binding-decorator/constants.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/fluent_provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/factory/module_factory.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/index.d.ts +8 -0
- package/lib/cjs/types/di/binding-decorator/interfaces/interfaces.d.ts +39 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_done_syntax.d.ts +7 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_syntax.d.ts +11 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_when_on_syntax.d.ts +27 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_on_syntax.d.ts +10 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_on_syntax.d.ts +24 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_syntax.d.ts +23 -0
- package/lib/cjs/types/di/binding-decorator/utils/auto_wire.d.ts +3 -0
- package/lib/cjs/types/di/bindings/binding.d.ts +20 -0
- package/lib/cjs/types/di/bindings/binding_count.d.ts +5 -0
- package/lib/cjs/types/di/constants/error_msgs.d.ts +32 -0
- package/lib/cjs/types/di/constants/literal_types.d.ts +5 -0
- package/lib/cjs/types/di/constants/metadata_keys.d.ts +13 -0
- package/lib/cjs/types/di/container/container.d.ts +73 -0
- package/lib/cjs/types/di/container/container_module.d.ts +11 -0
- package/lib/cjs/types/di/container/container_snapshot.d.ts +10 -0
- package/lib/cjs/types/di/container/lookup.d.ts +16 -0
- package/lib/cjs/types/di/container/module_activation_store.d.ts +10 -0
- package/lib/cjs/types/di/interfaces/interfaces.d.ts +299 -0
- package/lib/cjs/types/di/inversify.d.ts +25 -0
- package/lib/cjs/types/di/planning/context.d.ts +11 -0
- package/lib/cjs/types/di/planning/metadata.d.ts +8 -0
- package/lib/cjs/types/di/planning/metadata_reader.d.ts +6 -0
- package/lib/cjs/types/di/planning/plan.d.ts +7 -0
- package/lib/cjs/types/di/planning/planner.d.ts +5 -0
- package/lib/cjs/types/di/planning/queryable_string.d.ts +11 -0
- package/lib/cjs/types/di/planning/reflection_utils.d.ts +5 -0
- package/lib/cjs/types/di/planning/request.d.ts +14 -0
- package/lib/cjs/types/di/planning/target.d.ts +23 -0
- package/lib/cjs/types/di/resolution/instantiation.d.ts +3 -0
- package/lib/cjs/types/di/resolution/resolver.d.ts +3 -0
- package/lib/cjs/types/di/scope/scope.d.ts +3 -0
- package/lib/cjs/types/di/syntax/binding_in_syntax.d.ts +9 -0
- package/lib/cjs/types/di/syntax/binding_in_when_on_syntax.d.ts +29 -0
- package/lib/cjs/types/di/syntax/binding_on_syntax.d.ts +8 -0
- package/lib/cjs/types/di/syntax/binding_to_syntax.d.ts +18 -0
- package/lib/cjs/types/di/syntax/binding_when_on_syntax.d.ts +25 -0
- package/lib/cjs/types/di/syntax/binding_when_syntax.d.ts +21 -0
- package/lib/cjs/types/di/syntax/constraint_helpers.d.ts +6 -0
- package/lib/cjs/types/di/utils/async.d.ts +3 -0
- package/lib/cjs/types/di/utils/binding_utils.d.ts +4 -0
- package/lib/cjs/types/di/utils/clonable.d.ts +3 -0
- package/lib/cjs/types/di/utils/exceptions.d.ts +2 -0
- package/lib/cjs/types/di/utils/factory_type.d.ts +5 -0
- package/lib/cjs/types/di/utils/id.d.ts +2 -0
- package/lib/cjs/types/di/utils/js.d.ts +1 -0
- package/lib/cjs/types/di/utils/serialization.d.ts +10 -0
- package/lib/cjs/types/error/report.d.ts +7 -5
- package/lib/cjs/types/index.d.ts +1 -2
- package/lib/cjs/types/middleware/index.d.ts +2 -1
- package/lib/cjs/types/middleware/middleware-interface.d.ts +185 -0
- package/lib/cjs/types/middleware/middleware-service.d.ts +11 -163
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +4 -0
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +2 -3
- package/lib/cjs/types/{common → provider/dto-validator}/package-resolver.d.ts +1 -2
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +7 -3
- package/lib/cjs/types/provider/logger/logger.provider.d.ts +5 -0
- package/lib/cjs/types/provider/provider-manager.d.ts +22 -2
- package/lib/package.json +9 -15
- package/package.json +9 -15
- package/lib/cjs/common/index.js +0 -5
- package/lib/cjs/common/package-resolver.js +0 -34
- package/lib/cjs/controller/base-controller.js +0 -63
- package/lib/cjs/controller/index.js +0 -5
- package/lib/cjs/types/common/index.d.ts +0 -2
- package/lib/cjs/types/common/project-config.d.ts +0 -56
- package/lib/cjs/types/controller/base-controller.d.ts +0 -32
- package/lib/cjs/types/controller/index.d.ts +0 -1
- /package/lib/cjs/{common → console}/color-codes.js +0 -0
- /package/lib/cjs/{common/project-config.js → di/binding-decorator/interfaces/interfaces.js} +0 -0
- /package/lib/cjs/types/{common → console}/color-codes.d.ts +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleActivationStore = void 0;
|
|
4
|
+
const lookup_1 = require("./lookup");
|
|
5
|
+
class ModuleActivationStore {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._map = new Map();
|
|
8
|
+
}
|
|
9
|
+
remove(moduleId) {
|
|
10
|
+
if (this._map.has(moduleId)) {
|
|
11
|
+
const handlers = this._map.get(moduleId);
|
|
12
|
+
this._map.delete(moduleId);
|
|
13
|
+
return handlers;
|
|
14
|
+
}
|
|
15
|
+
return this._getEmptyHandlersStore();
|
|
16
|
+
}
|
|
17
|
+
addDeactivation(moduleId, serviceIdentifier, onDeactivation) {
|
|
18
|
+
this._getModuleActivationHandlers(moduleId).onDeactivations.add(serviceIdentifier, onDeactivation);
|
|
19
|
+
}
|
|
20
|
+
addActivation(moduleId, serviceIdentifier, onActivation) {
|
|
21
|
+
this._getModuleActivationHandlers(moduleId).onActivations.add(serviceIdentifier, onActivation);
|
|
22
|
+
}
|
|
23
|
+
clone() {
|
|
24
|
+
const clone = new ModuleActivationStore();
|
|
25
|
+
this._map.forEach((handlersStore, moduleId) => {
|
|
26
|
+
clone._map.set(moduleId, {
|
|
27
|
+
onActivations: handlersStore.onActivations.clone(),
|
|
28
|
+
onDeactivations: handlersStore.onDeactivations.clone(),
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return clone;
|
|
32
|
+
}
|
|
33
|
+
_getModuleActivationHandlers(moduleId) {
|
|
34
|
+
let moduleActivationHandlers = this._map.get(moduleId);
|
|
35
|
+
if (moduleActivationHandlers === undefined) {
|
|
36
|
+
moduleActivationHandlers = this._getEmptyHandlersStore();
|
|
37
|
+
this._map.set(moduleId, moduleActivationHandlers);
|
|
38
|
+
}
|
|
39
|
+
return moduleActivationHandlers;
|
|
40
|
+
}
|
|
41
|
+
_getEmptyHandlersStore() {
|
|
42
|
+
const handlersStore = {
|
|
43
|
+
onActivations: new lookup_1.Lookup(),
|
|
44
|
+
onDeactivations: new lookup_1.Lookup(),
|
|
45
|
+
};
|
|
46
|
+
return handlersStore;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ModuleActivationStore = ModuleActivationStore;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.multiBindToService = exports.getServiceIdentifierAsString = exports.typeConstraint = exports.namedConstraint = exports.taggedConstraint = exports.traverseAncerstors = exports.decorate = exports.id = exports.MetadataReader = exports.preDestroy = exports.postConstruct = exports.targetName = exports.multiInject = exports.unmanaged = exports.optional = exports.LazyServiceIdentifer = exports.LazyServiceIdentifier = exports.inject = exports.named = exports.tagged = exports.injectable = exports.createTaggedDecorator = exports.ContainerModule = exports.AsyncContainerModule = exports.TargetTypeEnum = exports.BindingTypeEnum = exports.BindingScopeEnum = exports.Container = exports.METADATA_KEY = void 0;
|
|
27
|
+
const keys = __importStar(require("./constants/metadata_keys"));
|
|
28
|
+
exports.METADATA_KEY = keys;
|
|
29
|
+
var container_1 = require("./container/container");
|
|
30
|
+
Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return container_1.Container; } });
|
|
31
|
+
var literal_types_1 = require("./constants/literal_types");
|
|
32
|
+
Object.defineProperty(exports, "BindingScopeEnum", { enumerable: true, get: function () { return literal_types_1.BindingScopeEnum; } });
|
|
33
|
+
Object.defineProperty(exports, "BindingTypeEnum", { enumerable: true, get: function () { return literal_types_1.BindingTypeEnum; } });
|
|
34
|
+
Object.defineProperty(exports, "TargetTypeEnum", { enumerable: true, get: function () { return literal_types_1.TargetTypeEnum; } });
|
|
35
|
+
var container_module_1 = require("./container/container_module");
|
|
36
|
+
Object.defineProperty(exports, "AsyncContainerModule", { enumerable: true, get: function () { return container_module_1.AsyncContainerModule; } });
|
|
37
|
+
Object.defineProperty(exports, "ContainerModule", { enumerable: true, get: function () { return container_module_1.ContainerModule; } });
|
|
38
|
+
var decorator_utils_1 = require("./annotation/decorator_utils");
|
|
39
|
+
Object.defineProperty(exports, "createTaggedDecorator", { enumerable: true, get: function () { return decorator_utils_1.createTaggedDecorator; } });
|
|
40
|
+
var injectable_1 = require("./annotation/injectable");
|
|
41
|
+
Object.defineProperty(exports, "injectable", { enumerable: true, get: function () { return injectable_1.injectable; } });
|
|
42
|
+
var tagged_1 = require("./annotation/tagged");
|
|
43
|
+
Object.defineProperty(exports, "tagged", { enumerable: true, get: function () { return tagged_1.tagged; } });
|
|
44
|
+
var named_1 = require("./annotation/named");
|
|
45
|
+
Object.defineProperty(exports, "named", { enumerable: true, get: function () { return named_1.named; } });
|
|
46
|
+
var inject_1 = require("./annotation/inject");
|
|
47
|
+
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.inject; } });
|
|
48
|
+
var lazy_service_identifier_1 = require("./annotation/lazy_service_identifier");
|
|
49
|
+
Object.defineProperty(exports, "LazyServiceIdentifier", { enumerable: true, get: function () { return lazy_service_identifier_1.LazyServiceIdentifier; } });
|
|
50
|
+
var lazy_service_identifier_2 = require("./annotation/lazy_service_identifier");
|
|
51
|
+
Object.defineProperty(exports, "LazyServiceIdentifer", { enumerable: true, get: function () { return lazy_service_identifier_2.LazyServiceIdentifier; } });
|
|
52
|
+
var optional_1 = require("./annotation/optional");
|
|
53
|
+
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return optional_1.optional; } });
|
|
54
|
+
var unmanaged_1 = require("./annotation/unmanaged");
|
|
55
|
+
Object.defineProperty(exports, "unmanaged", { enumerable: true, get: function () { return unmanaged_1.unmanaged; } });
|
|
56
|
+
var multi_inject_1 = require("./annotation/multi_inject");
|
|
57
|
+
Object.defineProperty(exports, "multiInject", { enumerable: true, get: function () { return multi_inject_1.multiInject; } });
|
|
58
|
+
var target_name_1 = require("./annotation/target_name");
|
|
59
|
+
Object.defineProperty(exports, "targetName", { enumerable: true, get: function () { return target_name_1.targetName; } });
|
|
60
|
+
var post_construct_1 = require("./annotation/post_construct");
|
|
61
|
+
Object.defineProperty(exports, "postConstruct", { enumerable: true, get: function () { return post_construct_1.postConstruct; } });
|
|
62
|
+
var pre_destroy_1 = require("./annotation/pre_destroy");
|
|
63
|
+
Object.defineProperty(exports, "preDestroy", { enumerable: true, get: function () { return pre_destroy_1.preDestroy; } });
|
|
64
|
+
var metadata_reader_1 = require("./planning/metadata_reader");
|
|
65
|
+
Object.defineProperty(exports, "MetadataReader", { enumerable: true, get: function () { return metadata_reader_1.MetadataReader; } });
|
|
66
|
+
var id_1 = require("./utils/id");
|
|
67
|
+
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_1.id; } });
|
|
68
|
+
var decorator_utils_2 = require("./annotation/decorator_utils");
|
|
69
|
+
Object.defineProperty(exports, "decorate", { enumerable: true, get: function () { return decorator_utils_2.decorate; } });
|
|
70
|
+
var constraint_helpers_1 = require("./syntax/constraint_helpers");
|
|
71
|
+
Object.defineProperty(exports, "traverseAncerstors", { enumerable: true, get: function () { return constraint_helpers_1.traverseAncerstors; } });
|
|
72
|
+
Object.defineProperty(exports, "taggedConstraint", { enumerable: true, get: function () { return constraint_helpers_1.taggedConstraint; } });
|
|
73
|
+
Object.defineProperty(exports, "namedConstraint", { enumerable: true, get: function () { return constraint_helpers_1.namedConstraint; } });
|
|
74
|
+
Object.defineProperty(exports, "typeConstraint", { enumerable: true, get: function () { return constraint_helpers_1.typeConstraint; } });
|
|
75
|
+
var serialization_1 = require("./utils/serialization");
|
|
76
|
+
Object.defineProperty(exports, "getServiceIdentifierAsString", { enumerable: true, get: function () { return serialization_1.getServiceIdentifierAsString; } });
|
|
77
|
+
var binding_utils_1 = require("./utils/binding_utils");
|
|
78
|
+
Object.defineProperty(exports, "multiBindToService", { enumerable: true, get: function () { return binding_utils_1.multiBindToService; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = void 0;
|
|
4
|
+
const id_1 = require("../utils/id");
|
|
5
|
+
class Context {
|
|
6
|
+
constructor(container) {
|
|
7
|
+
this.id = (0, id_1.id)();
|
|
8
|
+
this.container = container;
|
|
9
|
+
}
|
|
10
|
+
addPlan(plan) {
|
|
11
|
+
this.plan = plan;
|
|
12
|
+
}
|
|
13
|
+
setCurrentRequest(currentRequest) {
|
|
14
|
+
this.currentRequest = currentRequest;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Context = Context;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Metadata = void 0;
|
|
27
|
+
const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
|
|
28
|
+
class Metadata {
|
|
29
|
+
constructor(key, value) {
|
|
30
|
+
this.key = key;
|
|
31
|
+
this.value = value;
|
|
32
|
+
}
|
|
33
|
+
toString() {
|
|
34
|
+
if (this.key === METADATA_KEY.NAMED_TAG) {
|
|
35
|
+
return `named: ${String(this.value).toString()} `;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return `tagged: { key:${this.key.toString()}, value: ${String(this.value)} }`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Metadata = Metadata;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.MetadataReader = void 0;
|
|
27
|
+
const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
|
|
28
|
+
class MetadataReader {
|
|
29
|
+
getConstructorMetadata(constructorFunc) {
|
|
30
|
+
// TypeScript compiler generated annotations
|
|
31
|
+
const compilerGeneratedMetadata = Reflect.getMetadata(METADATA_KEY.PARAM_TYPES, constructorFunc);
|
|
32
|
+
// User generated constructor annotations
|
|
33
|
+
const userGeneratedMetadata = Reflect.getMetadata(METADATA_KEY.TAGGED, constructorFunc);
|
|
34
|
+
return {
|
|
35
|
+
compilerGeneratedMetadata,
|
|
36
|
+
userGeneratedMetadata: userGeneratedMetadata || {},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
getPropertiesMetadata(constructorFunc) {
|
|
40
|
+
// User generated properties annotations
|
|
41
|
+
const userGeneratedMetadata = Reflect.getMetadata(METADATA_KEY.TAGGED_PROP, constructorFunc) || [];
|
|
42
|
+
return userGeneratedMetadata;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MetadataReader = MetadataReader;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Plan = void 0;
|
|
4
|
+
class Plan {
|
|
5
|
+
constructor(parentContext, rootRequest) {
|
|
6
|
+
this.parentContext = parentContext;
|
|
7
|
+
this.rootRequest = rootRequest;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Plan = Plan;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.plan = plan;
|
|
27
|
+
exports.createMockRequest = createMockRequest;
|
|
28
|
+
exports.getBindingDictionary = getBindingDictionary;
|
|
29
|
+
const binding_count_1 = require("../bindings/binding_count");
|
|
30
|
+
const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
|
|
31
|
+
const literal_types_1 = require("../constants/literal_types");
|
|
32
|
+
const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
|
|
33
|
+
const exceptions_1 = require("../utils/exceptions");
|
|
34
|
+
const serialization_1 = require("../utils/serialization");
|
|
35
|
+
const context_1 = require("./context");
|
|
36
|
+
const metadata_1 = require("./metadata");
|
|
37
|
+
const plan_1 = require("./plan");
|
|
38
|
+
const reflection_utils_1 = require("./reflection_utils");
|
|
39
|
+
const request_1 = require("./request");
|
|
40
|
+
const target_1 = require("./target");
|
|
41
|
+
function getBindingDictionary(cntnr) {
|
|
42
|
+
return cntnr._bindingDictionary;
|
|
43
|
+
}
|
|
44
|
+
function _createTarget(isMultiInject, targetType, serviceIdentifier, name, key, value) {
|
|
45
|
+
const metadataKey = isMultiInject
|
|
46
|
+
? METADATA_KEY.MULTI_INJECT_TAG
|
|
47
|
+
: METADATA_KEY.INJECT_TAG;
|
|
48
|
+
const injectMetadata = new metadata_1.Metadata(metadataKey, serviceIdentifier);
|
|
49
|
+
const target = new target_1.Target(targetType, name, serviceIdentifier, injectMetadata);
|
|
50
|
+
if (key !== undefined) {
|
|
51
|
+
const tagMetadata = new metadata_1.Metadata(key, value);
|
|
52
|
+
target.metadata.push(tagMetadata);
|
|
53
|
+
}
|
|
54
|
+
return target;
|
|
55
|
+
}
|
|
56
|
+
function _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target) {
|
|
57
|
+
let bindings = getBindings(context.container, target.serviceIdentifier);
|
|
58
|
+
let activeBindings = [];
|
|
59
|
+
// automatic binding
|
|
60
|
+
if (bindings.length === binding_count_1.BindingCount.NoBindingsAvailable &&
|
|
61
|
+
context.container.options.autoBindInjectable &&
|
|
62
|
+
typeof target.serviceIdentifier === "function" &&
|
|
63
|
+
metadataReader.getConstructorMetadata(target.serviceIdentifier)
|
|
64
|
+
.compilerGeneratedMetadata) {
|
|
65
|
+
context.container.bind(target.serviceIdentifier).toSelf();
|
|
66
|
+
bindings = getBindings(context.container, target.serviceIdentifier);
|
|
67
|
+
}
|
|
68
|
+
// multiple bindings available
|
|
69
|
+
if (!avoidConstraints) {
|
|
70
|
+
// apply constraints if available to reduce the number of active bindings
|
|
71
|
+
activeBindings = bindings.filter((binding) => {
|
|
72
|
+
const request = new request_1.Request(binding.serviceIdentifier, context, parentRequest, binding, target);
|
|
73
|
+
return binding.constraint(request);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// simple injection or multi-injection without constraints
|
|
78
|
+
activeBindings = bindings;
|
|
79
|
+
}
|
|
80
|
+
// validate active bindings
|
|
81
|
+
_validateActiveBindingCount(target.serviceIdentifier, activeBindings, target, context.container);
|
|
82
|
+
return activeBindings;
|
|
83
|
+
}
|
|
84
|
+
function _validateActiveBindingCount(serviceIdentifier, bindings, target, container) {
|
|
85
|
+
switch (bindings.length) {
|
|
86
|
+
case binding_count_1.BindingCount.NoBindingsAvailable:
|
|
87
|
+
if (target.isOptional()) {
|
|
88
|
+
return bindings;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const serviceIdentifierString = (0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier);
|
|
92
|
+
let msg = ERROR_MSGS.NOT_REGISTERED;
|
|
93
|
+
msg += (0, serialization_1.listMetadataForTarget)(serviceIdentifierString, target);
|
|
94
|
+
msg += (0, serialization_1.listRegisteredBindingsForServiceIdentifier)(container, serviceIdentifierString, getBindings);
|
|
95
|
+
throw new Error(msg);
|
|
96
|
+
}
|
|
97
|
+
case binding_count_1.BindingCount.OnlyOneBindingAvailable:
|
|
98
|
+
return bindings;
|
|
99
|
+
case binding_count_1.BindingCount.MultipleBindingsAvailable:
|
|
100
|
+
default:
|
|
101
|
+
if (!target.isArray()) {
|
|
102
|
+
const serviceIdentifierString = (0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier);
|
|
103
|
+
let msg = `${ERROR_MSGS.AMBIGUOUS_MATCH} ${serviceIdentifierString}`;
|
|
104
|
+
msg += (0, serialization_1.listRegisteredBindingsForServiceIdentifier)(container, serviceIdentifierString, getBindings);
|
|
105
|
+
throw new Error(msg);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return bindings;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, parentRequest, target) {
|
|
113
|
+
let activeBindings;
|
|
114
|
+
let childRequest;
|
|
115
|
+
if (parentRequest === null) {
|
|
116
|
+
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target);
|
|
117
|
+
childRequest = new request_1.Request(serviceIdentifier, context, null, activeBindings, target);
|
|
118
|
+
const thePlan = new plan_1.Plan(context, childRequest);
|
|
119
|
+
context.addPlan(thePlan);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target);
|
|
123
|
+
childRequest = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target);
|
|
124
|
+
}
|
|
125
|
+
activeBindings.forEach((binding) => {
|
|
126
|
+
let subChildRequest = null;
|
|
127
|
+
if (target.isArray()) {
|
|
128
|
+
subChildRequest = childRequest.addChildRequest(binding.serviceIdentifier, binding, target);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (binding.cache) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
subChildRequest = childRequest;
|
|
135
|
+
}
|
|
136
|
+
if (binding.type === literal_types_1.BindingTypeEnum.Instance &&
|
|
137
|
+
binding.implementationType !== null) {
|
|
138
|
+
const dependencies = (0, reflection_utils_1.getDependencies)(metadataReader, binding.implementationType);
|
|
139
|
+
if (!context.container.options.skipBaseClassChecks) {
|
|
140
|
+
// Throw if a derived class does not implement its constructor explicitly
|
|
141
|
+
// We do this to prevent errors when a base class (parent) has dependencies
|
|
142
|
+
// and one of the derived classes (children) has no dependencies
|
|
143
|
+
const baseClassDependencyCount = (0, reflection_utils_1.getBaseClassDependencyCount)(metadataReader, binding.implementationType);
|
|
144
|
+
if (dependencies.length < baseClassDependencyCount) {
|
|
145
|
+
const error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH((0, reflection_utils_1.getFunctionName)(binding.implementationType));
|
|
146
|
+
throw new Error(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
dependencies.forEach((dependency) => {
|
|
150
|
+
_createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function getBindings(container, serviceIdentifier) {
|
|
156
|
+
let bindings = [];
|
|
157
|
+
const bindingDictionary = getBindingDictionary(container);
|
|
158
|
+
if (bindingDictionary.hasKey(serviceIdentifier)) {
|
|
159
|
+
bindings = bindingDictionary.get(serviceIdentifier);
|
|
160
|
+
}
|
|
161
|
+
else if (container.parent !== null) {
|
|
162
|
+
// recursively try to get bindings from parent container
|
|
163
|
+
bindings = getBindings(container.parent, serviceIdentifier);
|
|
164
|
+
}
|
|
165
|
+
return bindings;
|
|
166
|
+
}
|
|
167
|
+
function plan(metadataReader, container, isMultiInject, targetType, serviceIdentifier, key, value, avoidConstraints = false) {
|
|
168
|
+
const context = new context_1.Context(container);
|
|
169
|
+
const target = _createTarget(isMultiInject, targetType, serviceIdentifier, "", key, value);
|
|
170
|
+
try {
|
|
171
|
+
_createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, null, target);
|
|
172
|
+
return context;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if ((0, exceptions_1.isStackOverflowExeption)(error)) {
|
|
176
|
+
(0, serialization_1.circularDependencyToException)(context.plan.rootRequest);
|
|
177
|
+
}
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function createMockRequest(container, serviceIdentifier, key, value) {
|
|
182
|
+
const target = new target_1.Target(literal_types_1.TargetTypeEnum.Variable, "", serviceIdentifier, new metadata_1.Metadata(key, value));
|
|
183
|
+
const context = new context_1.Context(container);
|
|
184
|
+
const request = new request_1.Request(serviceIdentifier, context, null, [], target);
|
|
185
|
+
return request;
|
|
186
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryableString = void 0;
|
|
4
|
+
class QueryableString {
|
|
5
|
+
constructor(str) {
|
|
6
|
+
this.str = str;
|
|
7
|
+
}
|
|
8
|
+
startsWith(searchString) {
|
|
9
|
+
return this.str.indexOf(searchString) === 0;
|
|
10
|
+
}
|
|
11
|
+
endsWith(searchString) {
|
|
12
|
+
let reverseString = "";
|
|
13
|
+
const reverseSearchString = searchString.split("").reverse().join("");
|
|
14
|
+
reverseString = this.str.split("").reverse().join("");
|
|
15
|
+
return this.startsWith.call({ str: reverseString }, reverseSearchString);
|
|
16
|
+
}
|
|
17
|
+
contains(searchString) {
|
|
18
|
+
return this.str.indexOf(searchString) !== -1;
|
|
19
|
+
}
|
|
20
|
+
equals(compareString) {
|
|
21
|
+
return this.str === compareString;
|
|
22
|
+
}
|
|
23
|
+
value() {
|
|
24
|
+
return this.str;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.QueryableString = QueryableString;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getFunctionName = void 0;
|
|
27
|
+
exports.getDependencies = getDependencies;
|
|
28
|
+
exports.getBaseClassDependencyCount = getBaseClassDependencyCount;
|
|
29
|
+
const lazy_service_identifier_1 = require("../annotation/lazy_service_identifier");
|
|
30
|
+
const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
|
|
31
|
+
const literal_types_1 = require("../constants/literal_types");
|
|
32
|
+
const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
|
|
33
|
+
const serialization_1 = require("../utils/serialization");
|
|
34
|
+
Object.defineProperty(exports, "getFunctionName", { enumerable: true, get: function () { return serialization_1.getFunctionName; } });
|
|
35
|
+
const target_1 = require("./target");
|
|
36
|
+
function getDependencies(metadataReader, func) {
|
|
37
|
+
const constructorName = (0, serialization_1.getFunctionName)(func);
|
|
38
|
+
return getTargets(metadataReader, constructorName, func, false);
|
|
39
|
+
}
|
|
40
|
+
function getTargets(metadataReader, constructorName, func, isBaseClass) {
|
|
41
|
+
const metadata = metadataReader.getConstructorMetadata(func);
|
|
42
|
+
// TypeScript compiler generated annotations
|
|
43
|
+
const serviceIdentifiers = metadata.compilerGeneratedMetadata;
|
|
44
|
+
// All types resolved must be annotated with @injectable
|
|
45
|
+
if (serviceIdentifiers === undefined) {
|
|
46
|
+
const msg = `${ERROR_MSGS.MISSING_INJECTABLE_ANNOTATION} ${constructorName}.`;
|
|
47
|
+
throw new Error(msg);
|
|
48
|
+
}
|
|
49
|
+
// User generated annotations
|
|
50
|
+
const constructorArgsMetadata = metadata.userGeneratedMetadata;
|
|
51
|
+
const keys = Object.keys(constructorArgsMetadata);
|
|
52
|
+
const hasUserDeclaredUnknownInjections = func.length === 0 && keys.length > 0;
|
|
53
|
+
const hasOptionalParameters = keys.length > func.length;
|
|
54
|
+
const iterations = hasUserDeclaredUnknownInjections || hasOptionalParameters
|
|
55
|
+
? keys.length
|
|
56
|
+
: func.length;
|
|
57
|
+
// Target instances that represent constructor arguments to be injected
|
|
58
|
+
const constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
59
|
+
// Target instances that represent properties to be injected
|
|
60
|
+
const propertyTargets = getClassPropsAsTargets(metadataReader, func, constructorName);
|
|
61
|
+
const targets = [...constructorTargets, ...propertyTargets];
|
|
62
|
+
return targets;
|
|
63
|
+
}
|
|
64
|
+
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
65
|
+
// Create map from array of metadata for faster access to metadata
|
|
66
|
+
const targetMetadata = constructorArgsMetadata[index.toString()] || [];
|
|
67
|
+
const metadata = formatTargetMetadata(targetMetadata);
|
|
68
|
+
const isManaged = metadata.unmanaged !== true;
|
|
69
|
+
// Take types to be injected from user-generated metadata
|
|
70
|
+
// if not available use compiler-generated metadata
|
|
71
|
+
let serviceIdentifier = serviceIdentifiers[index];
|
|
72
|
+
const injectIdentifier = metadata.inject || metadata.multiInject;
|
|
73
|
+
serviceIdentifier = (injectIdentifier ? injectIdentifier : serviceIdentifier);
|
|
74
|
+
// we unwrap LazyServiceIdentifier wrappers to allow circular dependencies on symbols
|
|
75
|
+
if (serviceIdentifier instanceof lazy_service_identifier_1.LazyServiceIdentifier) {
|
|
76
|
+
serviceIdentifier = serviceIdentifier.unwrap();
|
|
77
|
+
}
|
|
78
|
+
// Types Object and Function are too ambiguous to be resolved
|
|
79
|
+
// user needs to generate metadata manually for those
|
|
80
|
+
if (isManaged) {
|
|
81
|
+
const isObject = serviceIdentifier === Object;
|
|
82
|
+
const isFunction = serviceIdentifier === Function;
|
|
83
|
+
const isUndefined = serviceIdentifier === undefined;
|
|
84
|
+
const isUnknownType = isObject || isFunction || isUndefined;
|
|
85
|
+
if (!isBaseClass && isUnknownType) {
|
|
86
|
+
const msg = `${ERROR_MSGS.MISSING_INJECT_ANNOTATION} argument ${index} in class ${constructorName}.`;
|
|
87
|
+
throw new Error(msg);
|
|
88
|
+
}
|
|
89
|
+
const target = new target_1.Target(literal_types_1.TargetTypeEnum.ConstructorArgument, metadata.targetName, serviceIdentifier);
|
|
90
|
+
target.metadata = targetMetadata;
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
function getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations) {
|
|
96
|
+
const targets = [];
|
|
97
|
+
for (let i = 0; i < iterations; i++) {
|
|
98
|
+
const index = i;
|
|
99
|
+
const target = getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata);
|
|
100
|
+
if (target !== null) {
|
|
101
|
+
targets.push(target);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return targets;
|
|
105
|
+
}
|
|
106
|
+
function _getServiceIdentifierForProperty(inject, multiInject, propertyName, className) {
|
|
107
|
+
const serviceIdentifier = inject || multiInject;
|
|
108
|
+
if (serviceIdentifier === undefined) {
|
|
109
|
+
const msg = `${ERROR_MSGS.MISSING_INJECTABLE_ANNOTATION} for property ${String(propertyName)} in class ${className}.`;
|
|
110
|
+
throw new Error(msg);
|
|
111
|
+
}
|
|
112
|
+
return serviceIdentifier;
|
|
113
|
+
}
|
|
114
|
+
function getClassPropsAsTargets(metadataReader, constructorFunc, constructorName) {
|
|
115
|
+
const classPropsMetadata = metadataReader.getPropertiesMetadata(constructorFunc);
|
|
116
|
+
let targets = [];
|
|
117
|
+
const symbolKeys = Object.getOwnPropertySymbols(classPropsMetadata);
|
|
118
|
+
const stringKeys = Object.keys(classPropsMetadata);
|
|
119
|
+
const keys = stringKeys.concat(symbolKeys);
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
// the metadata for the property being injected
|
|
122
|
+
const targetMetadata = classPropsMetadata[key];
|
|
123
|
+
// the metadata formatted for easier access
|
|
124
|
+
const metadata = formatTargetMetadata(targetMetadata);
|
|
125
|
+
const identifier = metadata.targetName || key;
|
|
126
|
+
// Take types to be injected from user-generated metadata
|
|
127
|
+
const serviceIdentifier = _getServiceIdentifierForProperty(metadata.inject, metadata.multiInject, key, constructorName);
|
|
128
|
+
// The property target
|
|
129
|
+
const target = new target_1.Target(literal_types_1.TargetTypeEnum.ClassProperty, identifier, serviceIdentifier);
|
|
130
|
+
target.metadata = targetMetadata;
|
|
131
|
+
targets.push(target);
|
|
132
|
+
}
|
|
133
|
+
// Check if base class has injected properties
|
|
134
|
+
const baseConstructor = Object.getPrototypeOf(constructorFunc.prototype).constructor;
|
|
135
|
+
if (baseConstructor !== Object) {
|
|
136
|
+
const baseTargets = getClassPropsAsTargets(metadataReader, baseConstructor, constructorName);
|
|
137
|
+
targets = [...targets, ...baseTargets];
|
|
138
|
+
}
|
|
139
|
+
return targets;
|
|
140
|
+
}
|
|
141
|
+
function getBaseClassDependencyCount(metadataReader, func) {
|
|
142
|
+
const baseConstructor = Object.getPrototypeOf(func.prototype).constructor;
|
|
143
|
+
if (baseConstructor !== Object) {
|
|
144
|
+
// get targets for base class
|
|
145
|
+
const baseConstructorName = (0, serialization_1.getFunctionName)(baseConstructor);
|
|
146
|
+
const targets = getTargets(metadataReader, baseConstructorName, baseConstructor, true);
|
|
147
|
+
// get unmanaged metadata
|
|
148
|
+
const metadata = targets.map((t) => t.metadata.filter((m) => m.key === METADATA_KEY.UNMANAGED_TAG));
|
|
149
|
+
// Compare the number of constructor arguments with the number of
|
|
150
|
+
// unmanaged dependencies unmanaged dependencies are not required
|
|
151
|
+
const unmanagedCount = [].concat.apply([], metadata).length;
|
|
152
|
+
const dependencyCount = targets.length - unmanagedCount;
|
|
153
|
+
if (dependencyCount > 0) {
|
|
154
|
+
return dependencyCount;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return getBaseClassDependencyCount(metadataReader, baseConstructor);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
165
|
+
function formatTargetMetadata(targetMetadata) {
|
|
166
|
+
// Create map from array of metadata for faster access to metadata
|
|
167
|
+
const targetMetadataMap = {};
|
|
168
|
+
targetMetadata.forEach((m) => {
|
|
169
|
+
targetMetadataMap[m.key.toString()] = m.value;
|
|
170
|
+
});
|
|
171
|
+
// user generated metadata
|
|
172
|
+
return {
|
|
173
|
+
inject: targetMetadataMap[METADATA_KEY.INJECT_TAG],
|
|
174
|
+
multiInject: targetMetadataMap[METADATA_KEY.MULTI_INJECT_TAG],
|
|
175
|
+
targetName: targetMetadataMap[METADATA_KEY.NAME_TAG],
|
|
176
|
+
unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG],
|
|
177
|
+
};
|
|
178
|
+
}
|