inversify 6.0.3 → 6.1.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/CHANGELOG.md +14 -0
- package/README.md +14 -14
- package/amd/annotation/decorator_utils.js +3 -1
- package/amd/annotation/inject_base.js +1 -1
- package/amd/annotation/lazy_service_identifier.js +0 -11
- package/amd/bindings/binding.js +3 -2
- package/amd/bindings/binding_count.js +6 -5
- package/amd/constants/error_msgs.js +18 -18
- package/amd/constants/literal_types.js +3 -3
- package/amd/container/container.js +73 -34
- package/amd/container/lookup.js +15 -14
- package/amd/container/module_activation_store.js +8 -10
- package/amd/interfaces/interfaces.js +0 -5
- package/amd/inversify.js +3 -5
- package/amd/planning/metadata_reader.js +5 -3
- package/amd/planning/planner.js +31 -13
- package/amd/planning/queryable_string.js +5 -2
- package/amd/planning/reflection_utils.js +6 -112
- package/amd/planning/request.js +2 -4
- package/amd/planning/target.js +9 -3
- package/amd/resolution/instantiation.js +10 -5
- package/amd/resolution/resolver.js +19 -10
- package/amd/scope/scope.js +1 -1
- package/amd/syntax/binding_to_syntax.js +14 -7
- package/amd/syntax/binding_when_syntax.js +13 -8
- package/amd/syntax/constraint_helpers.js +4 -3
- package/amd/utils/async.js +3 -2
- package/amd/utils/binding_utils.js +8 -3
- package/amd/utils/clonable.js +4 -4
- package/amd/utils/exceptions.js +1 -1
- package/amd/utils/serialization.js +11 -8
- package/es/annotation/decorator_utils.js +3 -1
- package/es/annotation/inject_base.js +1 -1
- package/es/annotation/lazy_service_identifier.js +1 -10
- package/es/annotation/target_name.js +3 -3
- package/es/bindings/binding.js +3 -2
- package/es/bindings/binding_count.js +6 -5
- package/es/constants/error_msgs.js +17 -17
- package/es/constants/literal_types.js +3 -3
- package/es/container/container.js +74 -35
- package/es/container/lookup.js +15 -14
- package/es/container/module_activation_store.js +8 -10
- package/es/interfaces/interfaces.js +1 -5
- package/es/inversify.js +4 -6
- package/es/planning/metadata_reader.js +5 -3
- package/es/planning/planner.js +34 -16
- package/es/planning/queryable_string.js +5 -2
- package/es/planning/reflection_utils.js +6 -114
- package/es/planning/request.js +2 -4
- package/es/planning/target.js +9 -3
- package/es/resolution/instantiation.js +11 -6
- package/es/resolution/resolver.js +20 -11
- package/es/scope/scope.js +1 -1
- package/es/syntax/binding_to_syntax.js +18 -11
- package/es/syntax/binding_when_syntax.js +14 -9
- package/es/syntax/constraint_helpers.js +5 -4
- package/es/utils/async.js +3 -2
- package/es/utils/binding_utils.js +8 -3
- package/es/utils/clonable.js +4 -4
- package/es/utils/exceptions.js +1 -1
- package/es/utils/serialization.js +12 -9
- package/es6/annotation/decorator_utils.js +5 -3
- package/es6/annotation/inject_base.js +1 -1
- package/es6/annotation/lazy_service_identifier.js +0 -10
- package/es6/bindings/binding.js +3 -2
- package/es6/bindings/binding_count.js +6 -5
- package/es6/constants/error_msgs.js +5 -9
- package/es6/constants/literal_types.js +3 -3
- package/es6/container/container.js +59 -42
- package/es6/container/lookup.js +15 -14
- package/es6/container/module_activation_store.js +8 -10
- package/es6/interfaces/interfaces.js +0 -5
- package/es6/inversify.js +3 -7
- package/es6/planning/metadata_reader.js +5 -3
- package/es6/planning/planner.js +31 -13
- package/es6/planning/queryable_string.js +5 -2
- package/es6/planning/reflection_utils.js +4 -110
- package/es6/planning/request.js +2 -4
- package/es6/planning/target.js +3 -1
- package/es6/resolution/instantiation.js +9 -5
- package/es6/resolution/resolver.js +11 -8
- package/es6/scope/scope.js +1 -1
- package/es6/syntax/binding_to_syntax.js +5 -4
- package/es6/syntax/binding_when_syntax.js +13 -8
- package/es6/syntax/constraint_helpers.js +4 -3
- package/es6/utils/async.js +3 -2
- package/es6/utils/binding_utils.js +10 -3
- package/es6/utils/clonable.js +4 -4
- package/es6/utils/exceptions.js +1 -1
- package/es6/utils/serialization.js +11 -8
- package/lib/annotation/decorator_utils.d.ts +2 -2
- package/lib/annotation/decorator_utils.js +3 -1
- package/lib/annotation/inject.d.ts +4 -1
- package/lib/annotation/inject_base.d.ts +3 -2
- package/lib/annotation/inject_base.js +1 -1
- package/lib/annotation/lazy_service_identifier.d.ts +1 -5
- package/lib/annotation/lazy_service_identifier.js +0 -11
- package/lib/annotation/multi_inject.d.ts +4 -1
- package/lib/annotation/tagged.d.ts +1 -1
- package/lib/annotation/target_name.d.ts +1 -1
- package/lib/bindings/binding.js +3 -2
- package/lib/bindings/binding_count.d.ts +5 -5
- package/lib/bindings/binding_count.js +6 -5
- package/lib/constants/error_msgs.d.ts +18 -20
- package/lib/constants/error_msgs.js +18 -18
- package/lib/constants/literal_types.js +3 -3
- package/lib/constants/metadata_keys.d.ts +12 -12
- package/lib/container/container.d.ts +2 -2
- package/lib/container/container.js +73 -34
- package/lib/container/lookup.d.ts +2 -1
- package/lib/container/lookup.js +15 -14
- package/lib/container/module_activation_store.d.ts +1 -1
- package/lib/container/module_activation_store.js +8 -10
- package/lib/interfaces/interfaces.d.ts +14 -29
- package/lib/interfaces/interfaces.js +0 -5
- package/lib/inversify.d.ts +5 -6
- package/lib/inversify.js +3 -7
- package/lib/planning/metadata_reader.js +5 -3
- package/lib/planning/planner.js +31 -13
- package/lib/planning/queryable_string.d.ts +2 -3
- package/lib/planning/queryable_string.js +5 -2
- package/lib/planning/reflection_utils.js +6 -114
- package/lib/planning/request.d.ts +2 -2
- package/lib/planning/request.js +2 -4
- package/lib/planning/target.d.ts +1 -1
- package/lib/planning/target.js +9 -3
- package/lib/resolution/instantiation.js +10 -5
- package/lib/resolution/resolver.js +19 -10
- package/lib/scope/scope.js +1 -1
- package/lib/syntax/binding_in_syntax.d.ts +1 -1
- package/lib/syntax/binding_in_when_on_syntax.d.ts +7 -7
- package/lib/syntax/binding_on_syntax.d.ts +1 -1
- package/lib/syntax/binding_to_syntax.d.ts +4 -4
- package/lib/syntax/binding_to_syntax.js +14 -7
- package/lib/syntax/binding_when_on_syntax.d.ts +6 -6
- package/lib/syntax/binding_when_syntax.d.ts +4 -4
- package/lib/syntax/binding_when_syntax.js +13 -8
- package/lib/syntax/constraint_helpers.d.ts +2 -2
- package/lib/syntax/constraint_helpers.js +4 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/async.js +3 -2
- package/lib/utils/binding_utils.js +8 -3
- package/lib/utils/clonable.js +4 -4
- package/lib/utils/exceptions.js +1 -1
- package/lib/utils/serialization.d.ts +3 -3
- package/lib/utils/serialization.js +11 -8
- package/package.json +19 -5
- package/.nyc_output/c29b2307-4e95-47d0-b220-9efcfa7ee49f.json +0 -1
- package/.nyc_output/processinfo/c29b2307-4e95-47d0-b220-9efcfa7ee49f.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BindingOnSyntax } from './binding_on_syntax';
|
|
2
|
-
import { namedConstraint, taggedConstraint, traverseAncerstors, typeConstraint } from './constraint_helpers';
|
|
2
|
+
import { namedConstraint, taggedConstraint, traverseAncerstors, typeConstraint, } from './constraint_helpers';
|
|
3
3
|
var BindingWhenSyntax = (function () {
|
|
4
4
|
function BindingWhenSyntax(binding) {
|
|
5
5
|
this._binding = binding;
|
|
@@ -17,9 +17,9 @@ var BindingWhenSyntax = (function () {
|
|
|
17
17
|
if (request === null) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
var targetIsDefault =
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var targetIsDefault = request.target !== null &&
|
|
21
|
+
!request.target.isNamed() &&
|
|
22
|
+
!request.target.isTagged();
|
|
23
23
|
return targetIsDefault;
|
|
24
24
|
};
|
|
25
25
|
return new BindingOnSyntax(this._binding);
|
|
@@ -54,7 +54,8 @@ var BindingWhenSyntax = (function () {
|
|
|
54
54
|
};
|
|
55
55
|
BindingWhenSyntax.prototype.whenNoAncestorIs = function (ancestor) {
|
|
56
56
|
this._binding.constraint = function (request) {
|
|
57
|
-
return request !== null &&
|
|
57
|
+
return request !== null &&
|
|
58
|
+
!traverseAncerstors(request, typeConstraint(ancestor));
|
|
58
59
|
};
|
|
59
60
|
return new BindingOnSyntax(this._binding);
|
|
60
61
|
};
|
|
@@ -72,25 +73,29 @@ var BindingWhenSyntax = (function () {
|
|
|
72
73
|
};
|
|
73
74
|
BindingWhenSyntax.prototype.whenAnyAncestorTagged = function (tag, value) {
|
|
74
75
|
this._binding.constraint = function (request) {
|
|
75
|
-
return request !== null &&
|
|
76
|
+
return request !== null &&
|
|
77
|
+
traverseAncerstors(request, taggedConstraint(tag)(value));
|
|
76
78
|
};
|
|
77
79
|
return new BindingOnSyntax(this._binding);
|
|
78
80
|
};
|
|
79
81
|
BindingWhenSyntax.prototype.whenNoAncestorTagged = function (tag, value) {
|
|
80
82
|
this._binding.constraint = function (request) {
|
|
81
|
-
return request !== null &&
|
|
83
|
+
return request !== null &&
|
|
84
|
+
!traverseAncerstors(request, taggedConstraint(tag)(value));
|
|
82
85
|
};
|
|
83
86
|
return new BindingOnSyntax(this._binding);
|
|
84
87
|
};
|
|
85
88
|
BindingWhenSyntax.prototype.whenAnyAncestorMatches = function (constraint) {
|
|
86
89
|
this._binding.constraint = function (request) {
|
|
87
|
-
return request !== null &&
|
|
90
|
+
return request !== null &&
|
|
91
|
+
traverseAncerstors(request, constraint);
|
|
88
92
|
};
|
|
89
93
|
return new BindingOnSyntax(this._binding);
|
|
90
94
|
};
|
|
91
95
|
BindingWhenSyntax.prototype.whenNoAncestorMatches = function (constraint) {
|
|
92
96
|
this._binding.constraint = function (request) {
|
|
93
|
-
return request !== null &&
|
|
97
|
+
return request !== null &&
|
|
98
|
+
!traverseAncerstors(request, constraint);
|
|
94
99
|
};
|
|
95
100
|
return new BindingOnSyntax(this._binding);
|
|
96
101
|
};
|
|
@@ -11,7 +11,9 @@ var traverseAncerstors = function (request, constraint) {
|
|
|
11
11
|
};
|
|
12
12
|
var taggedConstraint = function (key) { return function (value) {
|
|
13
13
|
var constraint = function (request) {
|
|
14
|
-
return request !== null &&
|
|
14
|
+
return request !== null &&
|
|
15
|
+
request.target !== null &&
|
|
16
|
+
request.target.matchesTag(key)(value);
|
|
15
17
|
};
|
|
16
18
|
constraint.metaData = new Metadata(key, value);
|
|
17
19
|
return constraint;
|
|
@@ -22,8 +24,7 @@ var typeConstraint = function (type) { return function (request) {
|
|
|
22
24
|
if (request !== null) {
|
|
23
25
|
binding = request.bindings[0];
|
|
24
26
|
if (typeof type === 'string') {
|
|
25
|
-
|
|
26
|
-
return serviceIdentifier === type;
|
|
27
|
+
return binding.serviceIdentifier === type;
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
30
|
var constructor = request.bindings[0].implementationType;
|
|
@@ -32,4 +33,4 @@ var typeConstraint = function (type) { return function (request) {
|
|
|
32
33
|
}
|
|
33
34
|
return false;
|
|
34
35
|
}; };
|
|
35
|
-
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint };
|
|
36
|
+
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint, };
|
package/es/utils/async.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
function isPromise(object) {
|
|
2
|
-
var isObjectOrFunction = (typeof object === 'object' && object !== null) ||
|
|
3
|
-
|
|
2
|
+
var isObjectOrFunction = (typeof object === 'object' && object !== null) ||
|
|
3
|
+
typeof object === 'function';
|
|
4
|
+
return (isObjectOrFunction && typeof object.then === 'function');
|
|
4
5
|
}
|
|
5
6
|
function isPromiseOrContainsPromise(object) {
|
|
6
7
|
if (isPromise(object)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getServiceIdentifierAsString } from '../utils/serialization';
|
|
2
1
|
import * as ERROR_MSGS from '../constants/error_msgs';
|
|
3
2
|
import { BindingTypeEnum } from '../constants/literal_types';
|
|
3
|
+
import { getServiceIdentifierAsString } from '../utils/serialization';
|
|
4
4
|
import { FactoryType } from './factory_type';
|
|
5
5
|
export var multiBindToService = function (container) {
|
|
6
6
|
return function (service) {
|
|
@@ -9,7 +9,9 @@ export var multiBindToService = function (container) {
|
|
|
9
9
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
10
10
|
types[_i] = arguments[_i];
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
types.forEach(function (t) {
|
|
13
|
+
container.bind(t).toService(service);
|
|
14
|
+
});
|
|
13
15
|
};
|
|
14
16
|
};
|
|
15
17
|
};
|
|
@@ -46,7 +48,10 @@ export var getFactoryDetails = function (binding) {
|
|
|
46
48
|
case BindingTypeEnum.Provider:
|
|
47
49
|
return { factory: binding.provider, factoryType: FactoryType.Provider };
|
|
48
50
|
case BindingTypeEnum.DynamicValue:
|
|
49
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
factory: binding.dynamicValue,
|
|
53
|
+
factoryType: FactoryType.DynamicValue,
|
|
54
|
+
};
|
|
50
55
|
default:
|
|
51
56
|
throw new Error("Unexpected factory type ".concat(binding.type));
|
|
52
57
|
}
|
package/es/utils/clonable.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function isClonable(obj) {
|
|
2
|
-
return (typeof obj === 'object'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
return (typeof obj === 'object' &&
|
|
3
|
+
obj !== null &&
|
|
4
|
+
'clone' in obj &&
|
|
5
|
+
typeof obj.clone === 'function');
|
|
6
6
|
}
|
|
7
7
|
export { isClonable };
|
package/es/utils/exceptions.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import * as ERROR_MSGS from '../constants/error_msgs';
|
|
2
2
|
function getServiceIdentifierAsString(serviceIdentifier) {
|
|
3
3
|
if (typeof serviceIdentifier === 'function') {
|
|
4
|
-
|
|
5
|
-
return _serviceIdentifier.name;
|
|
4
|
+
return serviceIdentifier.name;
|
|
6
5
|
}
|
|
7
6
|
else if (typeof serviceIdentifier === 'symbol') {
|
|
8
7
|
return serviceIdentifier.toString();
|
|
9
8
|
}
|
|
10
9
|
else {
|
|
11
|
-
|
|
12
|
-
return _serviceIdentifier;
|
|
10
|
+
return serviceIdentifier;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
function listRegisteredBindingsForServiceIdentifier(container, serviceIdentifier, getBindings) {
|
|
@@ -71,11 +69,11 @@ function listMetadataForTarget(serviceIdentifierString, target) {
|
|
|
71
69
|
var namedTag = target.getNamedTag();
|
|
72
70
|
var otherTags = target.getCustomTags();
|
|
73
71
|
if (namedTag !== null) {
|
|
74
|
-
m_1 += namedTag
|
|
72
|
+
m_1 += stringifyMetadata(namedTag) + '\n';
|
|
75
73
|
}
|
|
76
74
|
if (otherTags !== null) {
|
|
77
75
|
otherTags.forEach(function (tag) {
|
|
78
|
-
m_1 += tag
|
|
76
|
+
m_1 += stringifyMetadata(tag) + '\n';
|
|
79
77
|
});
|
|
80
78
|
}
|
|
81
79
|
return " ".concat(serviceIdentifierString, "\n ").concat(serviceIdentifierString, " - ").concat(m_1);
|
|
@@ -85,16 +83,21 @@ function listMetadataForTarget(serviceIdentifierString, target) {
|
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
function getFunctionName(func) {
|
|
88
|
-
if (func.name) {
|
|
86
|
+
if (func.name != null && func.name !== '') {
|
|
89
87
|
return func.name;
|
|
90
88
|
}
|
|
91
89
|
else {
|
|
92
90
|
var name_1 = func.toString();
|
|
93
91
|
var match = name_1.match(/^function\s*([^\s(]+)/);
|
|
94
|
-
return match
|
|
92
|
+
return match === null
|
|
93
|
+
? "Anonymous function: ".concat(name_1)
|
|
94
|
+
: match[1];
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
function getSymbolDescription(symbol) {
|
|
98
98
|
return symbol.toString().slice(7, -1);
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
function stringifyMetadata(metadata) {
|
|
101
|
+
return "{\"key\":\"".concat(metadata.key.toString(), "\",\"value\":\"").concat(metadata.value.toString(), "\"}");
|
|
102
|
+
}
|
|
103
|
+
export { getFunctionName, getServiceIdentifierAsString, listRegisteredBindingsForServiceIdentifier, listMetadataForTarget, circularDependencyToException, getSymbolDescription, };
|
|
@@ -52,7 +52,7 @@ function _ensureNoMetadataKeyDuplicates(metadata) {
|
|
|
52
52
|
let metadatas = [];
|
|
53
53
|
if (Array.isArray(metadata)) {
|
|
54
54
|
metadatas = metadata;
|
|
55
|
-
const duplicate = (0, js_1.getFirstArrayDuplicate)(metadatas.map(md => md.key));
|
|
55
|
+
const duplicate = (0, js_1.getFirstArrayDuplicate)(metadatas.map((md) => md.key));
|
|
56
56
|
if (duplicate !== undefined) {
|
|
57
57
|
throw new Error(`${ERROR_MSGS.DUPLICATED_METADATA} ${duplicate.toString()}`);
|
|
58
58
|
}
|
|
@@ -74,7 +74,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, key, metadata) {
|
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
76
|
for (const m of paramOrPropertyMetadata) {
|
|
77
|
-
if (metadatas.some(md => md.key === m.key)) {
|
|
77
|
+
if (metadatas.some((md) => md.key === m.key)) {
|
|
78
78
|
throw new Error(`${ERROR_MSGS.DUPLICATED_METADATA} ${m.key.toString()}`);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -97,7 +97,9 @@ function _decorate(decorators, target) {
|
|
|
97
97
|
Reflect.decorate(decorators, target);
|
|
98
98
|
}
|
|
99
99
|
function _param(paramIndex, decorator) {
|
|
100
|
-
return function (target, key) {
|
|
100
|
+
return function (target, key) {
|
|
101
|
+
decorator(target, key, paramIndex);
|
|
102
|
+
};
|
|
101
103
|
}
|
|
102
104
|
function decorate(decorator, target, parameterIndexOrProperty) {
|
|
103
105
|
if (typeof parameterIndexOrProperty === 'number') {
|
|
@@ -11,7 +11,7 @@ function injectBase(metadataKey) {
|
|
|
11
11
|
const className = typeof target === 'function' ? target.name : target.constructor.name;
|
|
12
12
|
throw new Error((0, error_msgs_1.UNDEFINED_INJECT_ANNOTATION)(className));
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
(0, decorator_utils_1.createTaggedDecorator)(new metadata_1.Metadata(metadataKey, serviceIdentifier))(target, targetKey, indexOrPropertyDescriptor);
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
}
|
|
@@ -1,12 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LazyServiceIdentifier = void 0;
|
|
4
|
-
class LazyServiceIdentifier {
|
|
5
|
-
constructor(cb) {
|
|
6
|
-
this._cb = cb;
|
|
7
|
-
}
|
|
8
|
-
unwrap() {
|
|
9
|
-
return this._cb();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.LazyServiceIdentifier = LazyServiceIdentifier;
|
package/es6/bindings/binding.js
CHANGED
|
@@ -10,7 +10,7 @@ class Binding {
|
|
|
10
10
|
this.serviceIdentifier = serviceIdentifier;
|
|
11
11
|
this.scope = scope;
|
|
12
12
|
this.type = literal_types_1.BindingTypeEnum.Invalid;
|
|
13
|
-
this.constraint = (
|
|
13
|
+
this.constraint = (_request) => true;
|
|
14
14
|
this.implementationType = null;
|
|
15
15
|
this.cache = null;
|
|
16
16
|
this.factory = null;
|
|
@@ -21,7 +21,8 @@ class Binding {
|
|
|
21
21
|
}
|
|
22
22
|
clone() {
|
|
23
23
|
const clone = new Binding(this.serviceIdentifier, this.scope);
|
|
24
|
-
clone.activated =
|
|
24
|
+
clone.activated =
|
|
25
|
+
clone.scope === literal_types_1.BindingScopeEnum.Singleton ? this.activated : false;
|
|
25
26
|
clone.implementationType = this.implementationType;
|
|
26
27
|
clone.dynamicValue = this.dynamicValue;
|
|
27
28
|
clone.scope = this.scope;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingCount = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var BindingCount;
|
|
5
|
+
(function (BindingCount) {
|
|
6
|
+
BindingCount[BindingCount["MultipleBindingsAvailable"] = 2] = "MultipleBindingsAvailable";
|
|
7
|
+
BindingCount[BindingCount["NoBindingsAvailable"] = 0] = "NoBindingsAvailable";
|
|
8
|
+
BindingCount[BindingCount["OnlyOneBindingAvailable"] = 1] = "OnlyOneBindingAvailable";
|
|
9
|
+
})(BindingCount || (exports.BindingCount = BindingCount = {}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STACK_OVERFLOW = exports.CIRCULAR_DEPENDENCY_IN_FACTORY = exports.ON_DEACTIVATION_ERROR = exports.PRE_DESTROY_ERROR = exports.POST_CONSTRUCT_ERROR = exports.ASYNC_UNBIND_REQUIRED = exports.MULTIPLE_POST_CONSTRUCT_METHODS = exports.MULTIPLE_PRE_DESTROY_METHODS = exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = exports.ARGUMENTS_LENGTH_MISMATCH = exports.INVALID_DECORATOR_OPERATION = exports.INVALID_TO_SELF_VALUE = exports.LAZY_IN_SYNC = exports.INVALID_FUNCTION_BINDING = exports.INVALID_MIDDLEWARE_RETURN = exports.NO_MORE_SNAPSHOTS_AVAILABLE = exports.INVALID_BINDING_TYPE = exports.
|
|
3
|
+
exports.STACK_OVERFLOW = exports.CIRCULAR_DEPENDENCY_IN_FACTORY = exports.ON_DEACTIVATION_ERROR = exports.PRE_DESTROY_ERROR = exports.POST_CONSTRUCT_ERROR = exports.ASYNC_UNBIND_REQUIRED = exports.MULTIPLE_POST_CONSTRUCT_METHODS = exports.MULTIPLE_PRE_DESTROY_METHODS = exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = exports.ARGUMENTS_LENGTH_MISMATCH = exports.INVALID_DECORATOR_OPERATION = exports.INVALID_TO_SELF_VALUE = exports.LAZY_IN_SYNC = exports.INVALID_FUNCTION_BINDING = exports.INVALID_MIDDLEWARE_RETURN = exports.NO_MORE_SNAPSHOTS_AVAILABLE = exports.INVALID_BINDING_TYPE = exports.CIRCULAR_DEPENDENCY = exports.UNDEFINED_INJECT_ANNOTATION = exports.MISSING_INJECTABLE_ANNOTATION = exports.NOT_REGISTERED = exports.CANNOT_UNBIND = exports.AMBIGUOUS_MATCH = exports.KEY_NOT_FOUND = exports.NULL_ARGUMENT = exports.DUPLICATED_METADATA = exports.DUPLICATED_INJECTABLE_DECORATOR = void 0;
|
|
4
4
|
exports.DUPLICATED_INJECTABLE_DECORATOR = 'Cannot apply @injectable decorator multiple times.';
|
|
5
5
|
exports.DUPLICATED_METADATA = 'Metadata key was used more than once in a parameter:';
|
|
6
6
|
exports.NULL_ARGUMENT = 'NULL argument';
|
|
@@ -9,13 +9,11 @@ exports.AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:';
|
|
|
9
9
|
exports.CANNOT_UNBIND = 'Could not unbind serviceIdentifier:';
|
|
10
10
|
exports.NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:';
|
|
11
11
|
exports.MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:';
|
|
12
|
-
exports.MISSING_INJECT_ANNOTATION = 'Missing required @inject or @multiInject annotation in:';
|
|
13
12
|
const UNDEFINED_INJECT_ANNOTATION = (name) => `@inject called with undefined this could mean that the class ${name} has ` +
|
|
14
13
|
'a circular dependency problem. You can use a LazyServiceIdentifer to ' +
|
|
15
14
|
'overcome this limitation.';
|
|
16
15
|
exports.UNDEFINED_INJECT_ANNOTATION = UNDEFINED_INJECT_ANNOTATION;
|
|
17
16
|
exports.CIRCULAR_DEPENDENCY = 'Circular dependency found:';
|
|
18
|
-
exports.NOT_IMPLEMENTED = 'Sorry, this feature is not fully implemented yet.';
|
|
19
17
|
exports.INVALID_BINDING_TYPE = 'Invalid binding type:';
|
|
20
18
|
exports.NO_MORE_SNAPSHOTS_AVAILABLE = 'No snapshot available to restore.';
|
|
21
19
|
exports.INVALID_MIDDLEWARE_RETURN = 'Invalid return type in middleware. Middleware must return!';
|
|
@@ -27,17 +25,15 @@ exports.INVALID_TO_SELF_VALUE = 'The toSelf function can only be applied when a
|
|
|
27
25
|
'used as service identifier';
|
|
28
26
|
exports.INVALID_DECORATOR_OPERATION = 'The @inject @multiInject @tagged and @named decorators ' +
|
|
29
27
|
'must be applied to the parameters of a class constructor or a class property.';
|
|
30
|
-
const ARGUMENTS_LENGTH_MISMATCH = (
|
|
31
|
-
`${
|
|
28
|
+
const ARGUMENTS_LENGTH_MISMATCH = (name) => 'The number of constructor arguments in the derived class ' +
|
|
29
|
+
`${name} must be >= than the number of constructor arguments of its base class.`;
|
|
32
30
|
exports.ARGUMENTS_LENGTH_MISMATCH = ARGUMENTS_LENGTH_MISMATCH;
|
|
33
31
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = 'Invalid Container constructor argument. Container options ' +
|
|
34
32
|
'must be an object.';
|
|
35
33
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = 'Invalid Container option. Default scope must ' +
|
|
36
34
|
'be a string ("singleton" or "transient").';
|
|
37
|
-
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = 'Invalid Container option. Auto bind injectable must ' +
|
|
38
|
-
|
|
39
|
-
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = 'Invalid Container option. Skip base check must ' +
|
|
40
|
-
'be a boolean';
|
|
35
|
+
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = 'Invalid Container option. Auto bind injectable must ' + 'be a boolean';
|
|
36
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = 'Invalid Container option. Skip base check must ' + 'be a boolean';
|
|
41
37
|
exports.MULTIPLE_PRE_DESTROY_METHODS = 'Cannot apply @preDestroy decorator multiple times in the same class';
|
|
42
38
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = 'Cannot apply @postConstruct decorator multiple times in the same class';
|
|
43
39
|
exports.ASYNC_UNBIND_REQUIRED = 'Attempting to unbind dependency with asynchronous destruction (@preDestroy or onDeactivation)';
|
|
@@ -4,7 +4,7 @@ exports.TargetTypeEnum = exports.BindingTypeEnum = exports.BindingScopeEnum = vo
|
|
|
4
4
|
const BindingScopeEnum = {
|
|
5
5
|
Request: 'Request',
|
|
6
6
|
Singleton: 'Singleton',
|
|
7
|
-
Transient: 'Transient'
|
|
7
|
+
Transient: 'Transient',
|
|
8
8
|
};
|
|
9
9
|
exports.BindingScopeEnum = BindingScopeEnum;
|
|
10
10
|
const BindingTypeEnum = {
|
|
@@ -15,12 +15,12 @@ const BindingTypeEnum = {
|
|
|
15
15
|
Function: 'Function',
|
|
16
16
|
Instance: 'Instance',
|
|
17
17
|
Invalid: 'Invalid',
|
|
18
|
-
Provider: 'Provider'
|
|
18
|
+
Provider: 'Provider',
|
|
19
19
|
};
|
|
20
20
|
exports.BindingTypeEnum = BindingTypeEnum;
|
|
21
21
|
const TargetTypeEnum = {
|
|
22
22
|
ClassProperty: 'ClassProperty',
|
|
23
23
|
ConstructorArgument: 'ConstructorArgument',
|
|
24
|
-
Variable: 'Variable'
|
|
24
|
+
Variable: 'Variable',
|
|
25
25
|
};
|
|
26
26
|
exports.TargetTypeEnum = TargetTypeEnum;
|
|
@@ -48,27 +48,10 @@ const container_snapshot_1 = require("./container_snapshot");
|
|
|
48
48
|
const lookup_1 = require("./lookup");
|
|
49
49
|
const module_activation_store_1 = require("./module_activation_store");
|
|
50
50
|
class Container {
|
|
51
|
-
static merge(container1, container2, ...containers) {
|
|
52
|
-
const container = new Container();
|
|
53
|
-
const targetContainers = [container1, container2, ...containers]
|
|
54
|
-
.map((targetContainer) => (0, planner_1.getBindingDictionary)(targetContainer));
|
|
55
|
-
const bindingDictionary = (0, planner_1.getBindingDictionary)(container);
|
|
56
|
-
function copyDictionary(origin, destination) {
|
|
57
|
-
origin.traverse((_key, value) => {
|
|
58
|
-
value.forEach((binding) => {
|
|
59
|
-
destination.add(binding.serviceIdentifier, binding.clone());
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
targetContainers.forEach((targetBindingDictionary) => {
|
|
64
|
-
copyDictionary(targetBindingDictionary, bindingDictionary);
|
|
65
|
-
});
|
|
66
|
-
return container;
|
|
67
|
-
}
|
|
68
51
|
constructor(containerOptions) {
|
|
69
52
|
const options = containerOptions || {};
|
|
70
53
|
if (typeof options !== 'object') {
|
|
71
|
-
throw new Error(
|
|
54
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
72
55
|
}
|
|
73
56
|
if (options.defaultScope === undefined) {
|
|
74
57
|
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
@@ -76,24 +59,24 @@ class Container {
|
|
|
76
59
|
else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
77
60
|
options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
78
61
|
options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
79
|
-
throw new Error(
|
|
62
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
80
63
|
}
|
|
81
64
|
if (options.autoBindInjectable === undefined) {
|
|
82
65
|
options.autoBindInjectable = false;
|
|
83
66
|
}
|
|
84
67
|
else if (typeof options.autoBindInjectable !== 'boolean') {
|
|
85
|
-
throw new Error(
|
|
68
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
86
69
|
}
|
|
87
70
|
if (options.skipBaseClassChecks === undefined) {
|
|
88
71
|
options.skipBaseClassChecks = false;
|
|
89
72
|
}
|
|
90
73
|
else if (typeof options.skipBaseClassChecks !== 'boolean') {
|
|
91
|
-
throw new Error(
|
|
74
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
92
75
|
}
|
|
93
76
|
this.options = {
|
|
94
77
|
autoBindInjectable: options.autoBindInjectable,
|
|
95
78
|
defaultScope: options.defaultScope,
|
|
96
|
-
skipBaseClassChecks: options.skipBaseClassChecks
|
|
79
|
+
skipBaseClassChecks: options.skipBaseClassChecks,
|
|
97
80
|
};
|
|
98
81
|
this.id = (0, id_1.id)();
|
|
99
82
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
@@ -105,6 +88,26 @@ class Container {
|
|
|
105
88
|
this._metadataReader = new metadata_reader_1.MetadataReader();
|
|
106
89
|
this._moduleActivationStore = new module_activation_store_1.ModuleActivationStore();
|
|
107
90
|
}
|
|
91
|
+
static merge(container1, container2, ...containers) {
|
|
92
|
+
const container = new Container();
|
|
93
|
+
const targetContainers = [
|
|
94
|
+
container1,
|
|
95
|
+
container2,
|
|
96
|
+
...containers,
|
|
97
|
+
].map((targetContainer) => (0, planner_1.getBindingDictionary)(targetContainer));
|
|
98
|
+
const bindingDictionary = (0, planner_1.getBindingDictionary)(container);
|
|
99
|
+
function copyDictionary(origin, destination) {
|
|
100
|
+
origin.traverse((_key, value) => {
|
|
101
|
+
value.forEach((binding) => {
|
|
102
|
+
destination.add(binding.serviceIdentifier, binding.clone());
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
targetContainers.forEach((targetBindingDictionary) => {
|
|
107
|
+
copyDictionary(targetBindingDictionary, bindingDictionary);
|
|
108
|
+
});
|
|
109
|
+
return container;
|
|
110
|
+
}
|
|
108
111
|
load(...modules) {
|
|
109
112
|
const getHelpers = this._getContainerModuleHelpersFactory();
|
|
110
113
|
for (const currentModule of modules) {
|
|
@@ -236,7 +239,9 @@ class Container {
|
|
|
236
239
|
return child;
|
|
237
240
|
}
|
|
238
241
|
applyMiddleware(...middlewares) {
|
|
239
|
-
const initial =
|
|
242
|
+
const initial = this._middleware
|
|
243
|
+
? this._middleware
|
|
244
|
+
: this._planAndResolve();
|
|
240
245
|
this._middleware = middlewares.reduce((prev, curr) => curr(prev), initial);
|
|
241
246
|
}
|
|
242
247
|
applyCustomMetadataReader(metadataReader) {
|
|
@@ -266,29 +271,37 @@ class Container {
|
|
|
266
271
|
return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
267
272
|
}
|
|
268
273
|
getNamedAsync(serviceIdentifier, named) {
|
|
269
|
-
return this
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
return this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
276
|
+
});
|
|
270
277
|
}
|
|
271
278
|
getAll(serviceIdentifier) {
|
|
272
279
|
const getArgs = this._getAllArgs(serviceIdentifier);
|
|
273
280
|
return this._getButThrowIfAsync(getArgs);
|
|
274
281
|
}
|
|
275
282
|
getAllAsync(serviceIdentifier) {
|
|
276
|
-
|
|
277
|
-
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
const getArgs = this._getAllArgs(serviceIdentifier);
|
|
285
|
+
return this._getAll(getArgs);
|
|
286
|
+
});
|
|
278
287
|
}
|
|
279
288
|
getAllTagged(serviceIdentifier, key, value) {
|
|
280
289
|
const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
281
290
|
return this._getButThrowIfAsync(getArgs);
|
|
282
291
|
}
|
|
283
292
|
getAllTaggedAsync(serviceIdentifier, key, value) {
|
|
284
|
-
|
|
285
|
-
|
|
293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
295
|
+
return this._getAll(getArgs);
|
|
296
|
+
});
|
|
286
297
|
}
|
|
287
298
|
getAllNamed(serviceIdentifier, named) {
|
|
288
299
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
289
300
|
}
|
|
290
301
|
getAllNamedAsync(serviceIdentifier, named) {
|
|
291
|
-
return this
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
return this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
304
|
+
});
|
|
292
305
|
}
|
|
293
306
|
resolve(constructorFunction) {
|
|
294
307
|
const isBound = this.isBound(constructorFunction);
|
|
@@ -314,7 +327,7 @@ class Container {
|
|
|
314
327
|
this._deactivations.removeIntersection(moduleActivationsHandlers.onDeactivations);
|
|
315
328
|
}
|
|
316
329
|
_removeModuleBindings(moduleId) {
|
|
317
|
-
return this._bindingDictionary.removeByCondition(binding => binding.moduleId === moduleId);
|
|
330
|
+
return this._bindingDictionary.removeByCondition((binding) => binding.moduleId === moduleId);
|
|
318
331
|
}
|
|
319
332
|
_deactivate(binding, instance) {
|
|
320
333
|
const constructor = Object.getPrototypeOf(instance).constructor;
|
|
@@ -322,7 +335,9 @@ class Container {
|
|
|
322
335
|
if (this._deactivations.hasKey(binding.serviceIdentifier)) {
|
|
323
336
|
const result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
|
|
324
337
|
if ((0, async_1.isPromise)(result)) {
|
|
325
|
-
return this._handleDeactivationError(result.then(() => this
|
|
338
|
+
return this._handleDeactivationError(result.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
339
|
+
return this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor);
|
|
340
|
+
})), constructor);
|
|
326
341
|
}
|
|
327
342
|
}
|
|
328
343
|
const propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
|
|
@@ -350,10 +365,10 @@ class Container {
|
|
|
350
365
|
}
|
|
351
366
|
_deactivateContainer(instance, deactivationsIterator) {
|
|
352
367
|
let deactivation = deactivationsIterator.next();
|
|
353
|
-
while (deactivation.value) {
|
|
368
|
+
while (typeof deactivation.value === 'function') {
|
|
354
369
|
const result = deactivation.value(instance);
|
|
355
370
|
if ((0, async_1.isPromise)(result)) {
|
|
356
|
-
return result.then(() => this._deactivateContainerAsync(instance, deactivationsIterator));
|
|
371
|
+
return result.then(() => __awaiter(this, void 0, void 0, function* () { return this._deactivateContainerAsync(instance, deactivationsIterator); }));
|
|
357
372
|
}
|
|
358
373
|
deactivation = deactivationsIterator.next();
|
|
359
374
|
}
|
|
@@ -361,7 +376,7 @@ class Container {
|
|
|
361
376
|
_deactivateContainerAsync(instance, deactivationsIterator) {
|
|
362
377
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
378
|
let deactivation = deactivationsIterator.next();
|
|
364
|
-
while (deactivation.value) {
|
|
379
|
+
while (typeof deactivation.value === 'function') {
|
|
365
380
|
yield deactivation.value(instance);
|
|
366
381
|
deactivation = deactivationsIterator.next();
|
|
367
382
|
}
|
|
@@ -377,11 +392,11 @@ class Container {
|
|
|
377
392
|
return bindingToSyntax;
|
|
378
393
|
};
|
|
379
394
|
const getUnbindFunction = () => (serviceIdentifier) => {
|
|
380
|
-
|
|
395
|
+
this.unbind(serviceIdentifier);
|
|
381
396
|
};
|
|
382
|
-
const getUnbindAsyncFunction = () => (serviceIdentifier) => {
|
|
397
|
+
const getUnbindAsyncFunction = () => (serviceIdentifier) => __awaiter(this, void 0, void 0, function* () {
|
|
383
398
|
return this.unbindAsync(serviceIdentifier);
|
|
384
|
-
};
|
|
399
|
+
});
|
|
385
400
|
const getIsboundFunction = () => (serviceIdentifier) => {
|
|
386
401
|
return this.isBound(serviceIdentifier);
|
|
387
402
|
};
|
|
@@ -404,12 +419,14 @@ class Container {
|
|
|
404
419
|
onActivationFunction: getOnActivationFunction(mId),
|
|
405
420
|
onDeactivationFunction: getOnDeactivationFunction(mId),
|
|
406
421
|
rebindFunction: getRebindFunction(mId),
|
|
422
|
+
unbindAsyncFunction: getUnbindAsyncFunction(),
|
|
407
423
|
unbindFunction: getUnbindFunction(),
|
|
408
|
-
unbindAsyncFunction: getUnbindAsyncFunction()
|
|
409
424
|
});
|
|
410
425
|
}
|
|
411
426
|
_getAll(getArgs) {
|
|
412
|
-
return
|
|
427
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
428
|
+
return Promise.all(this._get(getArgs));
|
|
429
|
+
});
|
|
413
430
|
}
|
|
414
431
|
_get(getArgs) {
|
|
415
432
|
const planAndResolveArgs = Object.assign(Object.assign({}, getArgs), { contextInterceptor: (context) => context, targetType: literal_types_1.TargetTypeEnum.Variable });
|
|
@@ -441,8 +458,8 @@ class Container {
|
|
|
441
458
|
const getNotAllArgs = {
|
|
442
459
|
avoidConstraints: false,
|
|
443
460
|
isMultiInject,
|
|
444
|
-
serviceIdentifier,
|
|
445
461
|
key,
|
|
462
|
+
serviceIdentifier,
|
|
446
463
|
value,
|
|
447
464
|
};
|
|
448
465
|
return getNotAllArgs;
|
|
@@ -474,7 +491,7 @@ class Container {
|
|
|
474
491
|
}
|
|
475
492
|
_deactivateSingletonsAsync(bindings) {
|
|
476
493
|
return __awaiter(this, void 0, void 0, function* () {
|
|
477
|
-
yield Promise.all(bindings.map(b => this._deactivateIfSingleton(b)));
|
|
494
|
+
yield Promise.all(bindings.map((b) => __awaiter(this, void 0, void 0, function* () { return this._deactivateIfSingleton(b); })));
|
|
478
495
|
});
|
|
479
496
|
}
|
|
480
497
|
_propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor) {
|
|
@@ -499,7 +516,7 @@ class Container {
|
|
|
499
516
|
try {
|
|
500
517
|
this._bindingDictionary.remove(serviceIdentifier);
|
|
501
518
|
}
|
|
502
|
-
catch (
|
|
519
|
+
catch (_e) {
|
|
503
520
|
throw new Error(`${ERROR_MSGS.CANNOT_UNBIND} ${(0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)}`);
|
|
504
521
|
}
|
|
505
522
|
}
|