inversify 6.0.3 → 6.1.0
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 +9 -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 +18 -4
- 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
package/amd/utils/async.js
CHANGED
|
@@ -4,8 +4,9 @@ define(["require", "exports"], function (require, exports) {
|
|
|
4
4
|
exports.isPromise = isPromise;
|
|
5
5
|
exports.isPromiseOrContainsPromise = isPromiseOrContainsPromise;
|
|
6
6
|
function isPromise(object) {
|
|
7
|
-
var isObjectOrFunction = (typeof object === 'object' && object !== null) ||
|
|
8
|
-
|
|
7
|
+
var isObjectOrFunction = (typeof object === 'object' && object !== null) ||
|
|
8
|
+
typeof object === 'function';
|
|
9
|
+
return (isObjectOrFunction && typeof object.then === 'function');
|
|
9
10
|
}
|
|
10
11
|
function isPromiseOrContainsPromise(object) {
|
|
11
12
|
if (isPromise(object)) {
|
|
@@ -21,7 +21,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
21
|
__setModuleDefault(result, mod);
|
|
22
22
|
return result;
|
|
23
23
|
};
|
|
24
|
-
define(["require", "exports", "../
|
|
24
|
+
define(["require", "exports", "../constants/error_msgs", "../constants/literal_types", "../utils/serialization", "./factory_type"], function (require, exports, ERROR_MSGS, literal_types_1, serialization_1, factory_type_1) {
|
|
25
25
|
"use strict";
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.getFactoryDetails = exports.ensureFullyBound = exports.multiBindToService = void 0;
|
|
@@ -33,7 +33,9 @@ define(["require", "exports", "../utils/serialization", "../constants/error_msgs
|
|
|
33
33
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
34
34
|
types[_i] = arguments[_i];
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
types.forEach(function (t) {
|
|
37
|
+
container.bind(t).toService(service);
|
|
38
|
+
});
|
|
37
39
|
};
|
|
38
40
|
};
|
|
39
41
|
};
|
|
@@ -72,7 +74,10 @@ define(["require", "exports", "../utils/serialization", "../constants/error_msgs
|
|
|
72
74
|
case literal_types_1.BindingTypeEnum.Provider:
|
|
73
75
|
return { factory: binding.provider, factoryType: factory_type_1.FactoryType.Provider };
|
|
74
76
|
case literal_types_1.BindingTypeEnum.DynamicValue:
|
|
75
|
-
return {
|
|
77
|
+
return {
|
|
78
|
+
factory: binding.dynamicValue,
|
|
79
|
+
factoryType: factory_type_1.FactoryType.DynamicValue,
|
|
80
|
+
};
|
|
76
81
|
default:
|
|
77
82
|
throw new Error("Unexpected factory type ".concat(binding.type));
|
|
78
83
|
}
|
package/amd/utils/clonable.js
CHANGED
|
@@ -3,9 +3,9 @@ define(["require", "exports"], function (require, exports) {
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.isClonable = isClonable;
|
|
5
5
|
function isClonable(obj) {
|
|
6
|
-
return (typeof obj === 'object'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
return (typeof obj === 'object' &&
|
|
7
|
+
obj !== null &&
|
|
8
|
+
'clone' in obj &&
|
|
9
|
+
typeof obj.clone === 'function');
|
|
10
10
|
}
|
|
11
11
|
});
|
package/amd/utils/exceptions.js
CHANGED
|
@@ -33,15 +33,13 @@ define(["require", "exports", "../constants/error_msgs"], function (require, exp
|
|
|
33
33
|
ERROR_MSGS = __importStar(ERROR_MSGS);
|
|
34
34
|
function getServiceIdentifierAsString(serviceIdentifier) {
|
|
35
35
|
if (typeof serviceIdentifier === 'function') {
|
|
36
|
-
|
|
37
|
-
return _serviceIdentifier.name;
|
|
36
|
+
return serviceIdentifier.name;
|
|
38
37
|
}
|
|
39
38
|
else if (typeof serviceIdentifier === 'symbol') {
|
|
40
39
|
return serviceIdentifier.toString();
|
|
41
40
|
}
|
|
42
41
|
else {
|
|
43
|
-
|
|
44
|
-
return _serviceIdentifier;
|
|
42
|
+
return serviceIdentifier;
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
function listRegisteredBindingsForServiceIdentifier(container, serviceIdentifier, getBindings) {
|
|
@@ -103,11 +101,11 @@ define(["require", "exports", "../constants/error_msgs"], function (require, exp
|
|
|
103
101
|
var namedTag = target.getNamedTag();
|
|
104
102
|
var otherTags = target.getCustomTags();
|
|
105
103
|
if (namedTag !== null) {
|
|
106
|
-
m_1 += namedTag
|
|
104
|
+
m_1 += stringifyMetadata(namedTag) + '\n';
|
|
107
105
|
}
|
|
108
106
|
if (otherTags !== null) {
|
|
109
107
|
otherTags.forEach(function (tag) {
|
|
110
|
-
m_1 += tag
|
|
108
|
+
m_1 += stringifyMetadata(tag) + '\n';
|
|
111
109
|
});
|
|
112
110
|
}
|
|
113
111
|
return " ".concat(serviceIdentifierString, "\n ").concat(serviceIdentifierString, " - ").concat(m_1);
|
|
@@ -117,16 +115,21 @@ define(["require", "exports", "../constants/error_msgs"], function (require, exp
|
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
function getFunctionName(func) {
|
|
120
|
-
if (func.name) {
|
|
118
|
+
if (func.name != null && func.name !== '') {
|
|
121
119
|
return func.name;
|
|
122
120
|
}
|
|
123
121
|
else {
|
|
124
122
|
var name_1 = func.toString();
|
|
125
123
|
var match = name_1.match(/^function\s*([^\s(]+)/);
|
|
126
|
-
return match
|
|
124
|
+
return match === null
|
|
125
|
+
? "Anonymous function: ".concat(name_1)
|
|
126
|
+
: match[1];
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
function getSymbolDescription(symbol) {
|
|
130
130
|
return symbol.toString().slice(7, -1);
|
|
131
131
|
}
|
|
132
|
+
function stringifyMetadata(metadata) {
|
|
133
|
+
return "{\"key\":\"".concat(metadata.key.toString(), "\",\"value\":\"").concat(metadata.value.toString(), "\"}");
|
|
134
|
+
}
|
|
132
135
|
});
|
|
@@ -72,7 +72,9 @@ function _decorate(decorators, target) {
|
|
|
72
72
|
Reflect.decorate(decorators, target);
|
|
73
73
|
}
|
|
74
74
|
function _param(paramIndex, decorator) {
|
|
75
|
-
return function (target, key) {
|
|
75
|
+
return function (target, key) {
|
|
76
|
+
decorator(target, key, paramIndex);
|
|
77
|
+
};
|
|
76
78
|
}
|
|
77
79
|
function decorate(decorator, target, parameterIndexOrProperty) {
|
|
78
80
|
if (typeof parameterIndexOrProperty === 'number') {
|
|
@@ -8,7 +8,7 @@ export function injectBase(metadataKey) {
|
|
|
8
8
|
var className = typeof target === 'function' ? target.name : target.constructor.name;
|
|
9
9
|
throw new Error(UNDEFINED_INJECT_ANNOTATION(className));
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
createTaggedDecorator(new Metadata(metadataKey, serviceIdentifier))(target, targetKey, indexOrPropertyDescriptor);
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function LazyServiceIdentifier(cb) {
|
|
3
|
-
this._cb = cb;
|
|
4
|
-
}
|
|
5
|
-
LazyServiceIdentifier.prototype.unwrap = function () {
|
|
6
|
-
return this._cb();
|
|
7
|
-
};
|
|
8
|
-
return LazyServiceIdentifier;
|
|
9
|
-
}());
|
|
10
|
-
export { LazyServiceIdentifier };
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as METADATA_KEY from
|
|
2
|
-
import { Metadata } from
|
|
3
|
-
import { tagParameter } from
|
|
1
|
+
import * as METADATA_KEY from '../constants/metadata_keys';
|
|
2
|
+
import { Metadata } from '../planning/metadata';
|
|
3
|
+
import { tagParameter } from './decorator_utils';
|
|
4
4
|
function targetName(name) {
|
|
5
5
|
return function (target, targetKey, index) {
|
|
6
6
|
var metadata = new Metadata(METADATA_KEY.NAME_TAG, name);
|
package/es/bindings/binding.js
CHANGED
|
@@ -7,7 +7,7 @@ var Binding = (function () {
|
|
|
7
7
|
this.serviceIdentifier = serviceIdentifier;
|
|
8
8
|
this.scope = scope;
|
|
9
9
|
this.type = BindingTypeEnum.Invalid;
|
|
10
|
-
this.constraint = function (
|
|
10
|
+
this.constraint = function (_request) { return true; };
|
|
11
11
|
this.implementationType = null;
|
|
12
12
|
this.cache = null;
|
|
13
13
|
this.factory = null;
|
|
@@ -18,7 +18,8 @@ var Binding = (function () {
|
|
|
18
18
|
}
|
|
19
19
|
Binding.prototype.clone = function () {
|
|
20
20
|
var clone = new Binding(this.serviceIdentifier, this.scope);
|
|
21
|
-
clone.activated =
|
|
21
|
+
clone.activated =
|
|
22
|
+
clone.scope === BindingScopeEnum.Singleton ? this.activated : false;
|
|
22
23
|
clone.implementationType = this.implementationType;
|
|
23
24
|
clone.dynamicValue = this.dynamicValue;
|
|
24
25
|
clone.scope = this.scope;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export var BindingCount
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export var BindingCount;
|
|
2
|
+
(function (BindingCount) {
|
|
3
|
+
BindingCount[BindingCount["MultipleBindingsAvailable"] = 2] = "MultipleBindingsAvailable";
|
|
4
|
+
BindingCount[BindingCount["NoBindingsAvailable"] = 0] = "NoBindingsAvailable";
|
|
5
|
+
BindingCount[BindingCount["OnlyOneBindingAvailable"] = 1] = "OnlyOneBindingAvailable";
|
|
6
|
+
})(BindingCount || (BindingCount = {}));
|
|
@@ -6,46 +6,46 @@ export var AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:';
|
|
|
6
6
|
export var CANNOT_UNBIND = 'Could not unbind serviceIdentifier:';
|
|
7
7
|
export var NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:';
|
|
8
8
|
export var MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:';
|
|
9
|
-
export var MISSING_INJECT_ANNOTATION = 'Missing required @inject or @multiInject annotation in:';
|
|
10
9
|
export var UNDEFINED_INJECT_ANNOTATION = function (name) {
|
|
11
10
|
return "@inject called with undefined this could mean that the class ".concat(name, " has ") +
|
|
12
11
|
'a circular dependency problem. You can use a LazyServiceIdentifer to ' +
|
|
13
12
|
'overcome this limitation.';
|
|
14
13
|
};
|
|
15
14
|
export var CIRCULAR_DEPENDENCY = 'Circular dependency found:';
|
|
16
|
-
export var NOT_IMPLEMENTED = 'Sorry, this feature is not fully implemented yet.';
|
|
17
15
|
export var INVALID_BINDING_TYPE = 'Invalid binding type:';
|
|
18
16
|
export var NO_MORE_SNAPSHOTS_AVAILABLE = 'No snapshot available to restore.';
|
|
19
17
|
export var INVALID_MIDDLEWARE_RETURN = 'Invalid return type in middleware. Middleware must return!';
|
|
20
18
|
export var INVALID_FUNCTION_BINDING = 'Value provided to function binding must be a function!';
|
|
21
|
-
export var LAZY_IN_SYNC = function (key) {
|
|
22
|
-
|
|
19
|
+
export var LAZY_IN_SYNC = function (key) {
|
|
20
|
+
return "You are attempting to construct ".concat(keyToString(key), " in a synchronous way ") +
|
|
21
|
+
'but it has asynchronous dependencies.';
|
|
22
|
+
};
|
|
23
23
|
export var INVALID_TO_SELF_VALUE = 'The toSelf function can only be applied when a constructor is ' +
|
|
24
24
|
'used as service identifier';
|
|
25
25
|
export var INVALID_DECORATOR_OPERATION = 'The @inject @multiInject @tagged and @named decorators ' +
|
|
26
26
|
'must be applied to the parameters of a class constructor or a class property.';
|
|
27
|
-
export var ARGUMENTS_LENGTH_MISMATCH = function () {
|
|
28
|
-
var values = [];
|
|
29
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
30
|
-
values[_i] = arguments[_i];
|
|
31
|
-
}
|
|
27
|
+
export var ARGUMENTS_LENGTH_MISMATCH = function (name) {
|
|
32
28
|
return 'The number of constructor arguments in the derived class ' +
|
|
33
|
-
"".concat(
|
|
29
|
+
"".concat(name, " must be >= than the number of constructor arguments of its base class.");
|
|
34
30
|
};
|
|
35
31
|
export var CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = 'Invalid Container constructor argument. Container options ' +
|
|
36
32
|
'must be an object.';
|
|
37
33
|
export var CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = 'Invalid Container option. Default scope must ' +
|
|
38
34
|
'be a string ("singleton" or "transient").';
|
|
39
|
-
export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = 'Invalid Container option. Auto bind injectable must ' +
|
|
40
|
-
|
|
41
|
-
export var CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = 'Invalid Container option. Skip base check must ' +
|
|
42
|
-
'be a boolean';
|
|
35
|
+
export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = 'Invalid Container option. Auto bind injectable must ' + 'be a boolean';
|
|
36
|
+
export var CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = 'Invalid Container option. Skip base check must ' + 'be a boolean';
|
|
43
37
|
export var MULTIPLE_PRE_DESTROY_METHODS = 'Cannot apply @preDestroy decorator multiple times in the same class';
|
|
44
38
|
export var MULTIPLE_POST_CONSTRUCT_METHODS = 'Cannot apply @postConstruct decorator multiple times in the same class';
|
|
45
39
|
export var ASYNC_UNBIND_REQUIRED = 'Attempting to unbind dependency with asynchronous destruction (@preDestroy or onDeactivation)';
|
|
46
|
-
export var POST_CONSTRUCT_ERROR = function (clazz, errorMessage) {
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
export var POST_CONSTRUCT_ERROR = function (clazz, errorMessage) {
|
|
41
|
+
return "@postConstruct error in class ".concat(clazz, ": ").concat(errorMessage);
|
|
42
|
+
};
|
|
43
|
+
export var PRE_DESTROY_ERROR = function (clazz, errorMessage) {
|
|
44
|
+
return "@preDestroy error in class ".concat(clazz, ": ").concat(errorMessage);
|
|
45
|
+
};
|
|
46
|
+
export var ON_DEACTIVATION_ERROR = function (clazz, errorMessage) {
|
|
47
|
+
return "onDeactivation() error in class ".concat(clazz, ": ").concat(errorMessage);
|
|
48
|
+
};
|
|
49
49
|
export var CIRCULAR_DEPENDENCY_IN_FACTORY = function (factoryType, serviceIdentifier) {
|
|
50
50
|
return "It looks like there is a circular dependency in one of the '".concat(factoryType, "' bindings. Please investigate bindings with ") +
|
|
51
51
|
"service identifier '".concat(serviceIdentifier, "'.");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var BindingScopeEnum = {
|
|
2
2
|
Request: 'Request',
|
|
3
3
|
Singleton: 'Singleton',
|
|
4
|
-
Transient: 'Transient'
|
|
4
|
+
Transient: 'Transient',
|
|
5
5
|
};
|
|
6
6
|
var BindingTypeEnum = {
|
|
7
7
|
ConstantValue: 'ConstantValue',
|
|
@@ -11,11 +11,11 @@ var BindingTypeEnum = {
|
|
|
11
11
|
Function: 'Function',
|
|
12
12
|
Instance: 'Instance',
|
|
13
13
|
Invalid: 'Invalid',
|
|
14
|
-
Provider: 'Provider'
|
|
14
|
+
Provider: 'Provider',
|
|
15
15
|
};
|
|
16
16
|
var TargetTypeEnum = {
|
|
17
17
|
ClassProperty: 'ClassProperty',
|
|
18
18
|
ConstructorArgument: 'ConstructorArgument',
|
|
19
|
-
Variable: 'Variable'
|
|
19
|
+
Variable: 'Variable',
|
|
20
20
|
};
|
|
21
21
|
export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum };
|
|
@@ -59,7 +59,7 @@ import * as ERROR_MSGS from '../constants/error_msgs';
|
|
|
59
59
|
import { BindingScopeEnum, TargetTypeEnum } from '../constants/literal_types';
|
|
60
60
|
import * as METADATA_KEY from '../constants/metadata_keys';
|
|
61
61
|
import { MetadataReader } from '../planning/metadata_reader';
|
|
62
|
-
import { createMockRequest, getBindingDictionary, plan } from '../planning/planner';
|
|
62
|
+
import { createMockRequest, getBindingDictionary, plan, } from '../planning/planner';
|
|
63
63
|
import { resolve } from '../resolution/resolver';
|
|
64
64
|
import { BindingToSyntax } from '../syntax/binding_to_syntax';
|
|
65
65
|
import { isPromise, isPromiseOrContainsPromise } from '../utils/async';
|
|
@@ -72,7 +72,7 @@ var Container = (function () {
|
|
|
72
72
|
function Container(containerOptions) {
|
|
73
73
|
var options = containerOptions || {};
|
|
74
74
|
if (typeof options !== 'object') {
|
|
75
|
-
throw new Error(
|
|
75
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
76
76
|
}
|
|
77
77
|
if (options.defaultScope === undefined) {
|
|
78
78
|
options.defaultScope = BindingScopeEnum.Transient;
|
|
@@ -80,24 +80,24 @@ var Container = (function () {
|
|
|
80
80
|
else if (options.defaultScope !== BindingScopeEnum.Singleton &&
|
|
81
81
|
options.defaultScope !== BindingScopeEnum.Transient &&
|
|
82
82
|
options.defaultScope !== BindingScopeEnum.Request) {
|
|
83
|
-
throw new Error(
|
|
83
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
84
84
|
}
|
|
85
85
|
if (options.autoBindInjectable === undefined) {
|
|
86
86
|
options.autoBindInjectable = false;
|
|
87
87
|
}
|
|
88
88
|
else if (typeof options.autoBindInjectable !== 'boolean') {
|
|
89
|
-
throw new Error(
|
|
89
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
90
90
|
}
|
|
91
91
|
if (options.skipBaseClassChecks === undefined) {
|
|
92
92
|
options.skipBaseClassChecks = false;
|
|
93
93
|
}
|
|
94
94
|
else if (typeof options.skipBaseClassChecks !== 'boolean') {
|
|
95
|
-
throw new Error(
|
|
95
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
96
96
|
}
|
|
97
97
|
this.options = {
|
|
98
98
|
autoBindInjectable: options.autoBindInjectable,
|
|
99
99
|
defaultScope: options.defaultScope,
|
|
100
|
-
skipBaseClassChecks: options.skipBaseClassChecks
|
|
100
|
+
skipBaseClassChecks: options.skipBaseClassChecks,
|
|
101
101
|
};
|
|
102
102
|
this.id = id();
|
|
103
103
|
this._bindingDictionary = new Lookup();
|
|
@@ -115,7 +115,12 @@ var Container = (function () {
|
|
|
115
115
|
containers[_i - 2] = arguments[_i];
|
|
116
116
|
}
|
|
117
117
|
var container = new Container();
|
|
118
|
-
var targetContainers = __spreadArray([
|
|
118
|
+
var targetContainers = __spreadArray([
|
|
119
|
+
container1,
|
|
120
|
+
container2
|
|
121
|
+
], containers, true).map(function (targetContainer) {
|
|
122
|
+
return getBindingDictionary(targetContainer);
|
|
123
|
+
});
|
|
119
124
|
var bindingDictionary = getBindingDictionary(container);
|
|
120
125
|
function copyDictionary(origin, destination) {
|
|
121
126
|
origin.traverse(function (_key, value) {
|
|
@@ -341,7 +346,9 @@ var Container = (function () {
|
|
|
341
346
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
342
347
|
middlewares[_i] = arguments[_i];
|
|
343
348
|
}
|
|
344
|
-
var initial =
|
|
349
|
+
var initial = this._middleware
|
|
350
|
+
? this._middleware
|
|
351
|
+
: this._planAndResolve();
|
|
345
352
|
this._middleware = middlewares.reduce(function (prev, curr) { return curr(prev); }, initial);
|
|
346
353
|
};
|
|
347
354
|
Container.prototype.applyCustomMetadataReader = function (metadataReader) {
|
|
@@ -377,29 +384,47 @@ var Container = (function () {
|
|
|
377
384
|
return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
378
385
|
};
|
|
379
386
|
Container.prototype.getNamedAsync = function (serviceIdentifier, named) {
|
|
380
|
-
return this
|
|
387
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
388
|
+
return __generator(this, function (_a) {
|
|
389
|
+
return [2, this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
|
|
390
|
+
});
|
|
391
|
+
});
|
|
381
392
|
};
|
|
382
393
|
Container.prototype.getAll = function (serviceIdentifier) {
|
|
383
394
|
var getArgs = this._getAllArgs(serviceIdentifier);
|
|
384
395
|
return this._getButThrowIfAsync(getArgs);
|
|
385
396
|
};
|
|
386
397
|
Container.prototype.getAllAsync = function (serviceIdentifier) {
|
|
387
|
-
|
|
388
|
-
|
|
398
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
399
|
+
var getArgs;
|
|
400
|
+
return __generator(this, function (_a) {
|
|
401
|
+
getArgs = this._getAllArgs(serviceIdentifier);
|
|
402
|
+
return [2, this._getAll(getArgs)];
|
|
403
|
+
});
|
|
404
|
+
});
|
|
389
405
|
};
|
|
390
406
|
Container.prototype.getAllTagged = function (serviceIdentifier, key, value) {
|
|
391
407
|
var getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
392
408
|
return this._getButThrowIfAsync(getArgs);
|
|
393
409
|
};
|
|
394
410
|
Container.prototype.getAllTaggedAsync = function (serviceIdentifier, key, value) {
|
|
395
|
-
|
|
396
|
-
|
|
411
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
412
|
+
var getArgs;
|
|
413
|
+
return __generator(this, function (_a) {
|
|
414
|
+
getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
415
|
+
return [2, this._getAll(getArgs)];
|
|
416
|
+
});
|
|
417
|
+
});
|
|
397
418
|
};
|
|
398
419
|
Container.prototype.getAllNamed = function (serviceIdentifier, named) {
|
|
399
420
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
400
421
|
};
|
|
401
422
|
Container.prototype.getAllNamedAsync = function (serviceIdentifier, named) {
|
|
402
|
-
return this
|
|
423
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
+
return __generator(this, function (_a) {
|
|
425
|
+
return [2, this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
|
|
426
|
+
});
|
|
427
|
+
});
|
|
403
428
|
};
|
|
404
429
|
Container.prototype.resolve = function (constructorFunction) {
|
|
405
430
|
var isBound = this.isBound(constructorFunction);
|
|
@@ -434,7 +459,11 @@ var Container = (function () {
|
|
|
434
459
|
if (this._deactivations.hasKey(binding.serviceIdentifier)) {
|
|
435
460
|
var result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
|
|
436
461
|
if (isPromise(result)) {
|
|
437
|
-
return this._handleDeactivationError(result.then(function () { return _this
|
|
462
|
+
return this._handleDeactivationError(result.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
463
|
+
return __generator(this, function (_a) {
|
|
464
|
+
return [2, this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)];
|
|
465
|
+
});
|
|
466
|
+
}); }), constructor);
|
|
438
467
|
}
|
|
439
468
|
}
|
|
440
469
|
var propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
|
|
@@ -473,12 +502,12 @@ var Container = (function () {
|
|
|
473
502
|
Container.prototype._deactivateContainer = function (instance, deactivationsIterator) {
|
|
474
503
|
var _this = this;
|
|
475
504
|
var deactivation = deactivationsIterator.next();
|
|
476
|
-
while (deactivation.value) {
|
|
505
|
+
while (typeof deactivation.value === 'function') {
|
|
477
506
|
var result = deactivation.value(instance);
|
|
478
507
|
if (isPromise(result)) {
|
|
479
|
-
return result.then(function () {
|
|
480
|
-
return
|
|
481
|
-
});
|
|
508
|
+
return result.then(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
509
|
+
return [2, this._deactivateContainerAsync(instance, deactivationsIterator)];
|
|
510
|
+
}); }); });
|
|
482
511
|
}
|
|
483
512
|
deactivation = deactivationsIterator.next();
|
|
484
513
|
}
|
|
@@ -492,7 +521,7 @@ var Container = (function () {
|
|
|
492
521
|
deactivation = deactivationsIterator.next();
|
|
493
522
|
_a.label = 1;
|
|
494
523
|
case 1:
|
|
495
|
-
if (!deactivation.value) return [3, 3];
|
|
524
|
+
if (!(typeof deactivation.value === 'function')) return [3, 3];
|
|
496
525
|
return [4, deactivation.value(instance)];
|
|
497
526
|
case 2:
|
|
498
527
|
_a.sent();
|
|
@@ -515,15 +544,15 @@ var Container = (function () {
|
|
|
515
544
|
return bindingToSyntax;
|
|
516
545
|
};
|
|
517
546
|
};
|
|
518
|
-
var getUnbindFunction = function () {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
};
|
|
522
|
-
};
|
|
547
|
+
var getUnbindFunction = function () { return function (serviceIdentifier) {
|
|
548
|
+
_this.unbind(serviceIdentifier);
|
|
549
|
+
}; };
|
|
523
550
|
var getUnbindAsyncFunction = function () {
|
|
524
|
-
return function (serviceIdentifier) {
|
|
525
|
-
return
|
|
526
|
-
|
|
551
|
+
return function (serviceIdentifier) { return __awaiter(_this, void 0, void 0, function () {
|
|
552
|
+
return __generator(this, function (_a) {
|
|
553
|
+
return [2, this.unbindAsync(serviceIdentifier)];
|
|
554
|
+
});
|
|
555
|
+
}); };
|
|
527
556
|
};
|
|
528
557
|
var getIsboundFunction = function () {
|
|
529
558
|
return function (serviceIdentifier) {
|
|
@@ -555,12 +584,16 @@ var Container = (function () {
|
|
|
555
584
|
onActivationFunction: getOnActivationFunction(mId),
|
|
556
585
|
onDeactivationFunction: getOnDeactivationFunction(mId),
|
|
557
586
|
rebindFunction: getRebindFunction(mId),
|
|
587
|
+
unbindAsyncFunction: getUnbindAsyncFunction(),
|
|
558
588
|
unbindFunction: getUnbindFunction(),
|
|
559
|
-
unbindAsyncFunction: getUnbindAsyncFunction()
|
|
560
589
|
}); };
|
|
561
590
|
};
|
|
562
591
|
Container.prototype._getAll = function (getArgs) {
|
|
563
|
-
return
|
|
592
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
593
|
+
return __generator(this, function (_a) {
|
|
594
|
+
return [2, Promise.all(this._get(getArgs))];
|
|
595
|
+
});
|
|
596
|
+
});
|
|
564
597
|
};
|
|
565
598
|
Container.prototype._get = function (getArgs) {
|
|
566
599
|
var planAndResolveArgs = __assign(__assign({}, getArgs), { contextInterceptor: function (context) { return context; }, targetType: TargetTypeEnum.Variable });
|
|
@@ -592,8 +625,8 @@ var Container = (function () {
|
|
|
592
625
|
var getNotAllArgs = {
|
|
593
626
|
avoidConstraints: false,
|
|
594
627
|
isMultiInject: isMultiInject,
|
|
595
|
-
serviceIdentifier: serviceIdentifier,
|
|
596
628
|
key: key,
|
|
629
|
+
serviceIdentifier: serviceIdentifier,
|
|
597
630
|
value: value,
|
|
598
631
|
};
|
|
599
632
|
return getNotAllArgs;
|
|
@@ -613,7 +646,9 @@ var Container = (function () {
|
|
|
613
646
|
return;
|
|
614
647
|
}
|
|
615
648
|
if (isPromise(binding.cache)) {
|
|
616
|
-
return binding.cache.then(function (resolved) {
|
|
649
|
+
return binding.cache.then(function (resolved) {
|
|
650
|
+
return _this._deactivate(binding, resolved);
|
|
651
|
+
});
|
|
617
652
|
}
|
|
618
653
|
return this._deactivate(binding, binding.cache);
|
|
619
654
|
};
|
|
@@ -631,7 +666,9 @@ var Container = (function () {
|
|
|
631
666
|
var _this = this;
|
|
632
667
|
return __generator(this, function (_a) {
|
|
633
668
|
switch (_a.label) {
|
|
634
|
-
case 0: return [4, Promise.all(bindings.map(function (b) { return _this
|
|
669
|
+
case 0: return [4, Promise.all(bindings.map(function (b) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
670
|
+
return [2, this._deactivateIfSingleton(b)];
|
|
671
|
+
}); }); }))];
|
|
635
672
|
case 1:
|
|
636
673
|
_a.sent();
|
|
637
674
|
return [2];
|
|
@@ -670,7 +707,7 @@ var Container = (function () {
|
|
|
670
707
|
try {
|
|
671
708
|
this._bindingDictionary.remove(serviceIdentifier);
|
|
672
709
|
}
|
|
673
|
-
catch (
|
|
710
|
+
catch (_e) {
|
|
674
711
|
throw new Error("".concat(ERROR_MSGS.CANNOT_UNBIND, " ").concat(getServiceIdentifierAsString(serviceIdentifier)));
|
|
675
712
|
}
|
|
676
713
|
};
|
|
@@ -679,7 +716,9 @@ var Container = (function () {
|
|
|
679
716
|
if (typeof binding.onDeactivation === 'function') {
|
|
680
717
|
var result = binding.onDeactivation(instance);
|
|
681
718
|
if (isPromise(result)) {
|
|
682
|
-
return result.then(function () {
|
|
719
|
+
return result.then(function () {
|
|
720
|
+
return _this._preDestroy(constructor, instance);
|
|
721
|
+
});
|
|
683
722
|
}
|
|
684
723
|
}
|
|
685
724
|
return this._preDestroy(constructor, instance);
|
package/es/container/lookup.js
CHANGED
|
@@ -8,9 +8,7 @@ var Lookup = (function () {
|
|
|
8
8
|
return this._map;
|
|
9
9
|
};
|
|
10
10
|
Lookup.prototype.add = function (serviceIdentifier, value) {
|
|
11
|
-
|
|
12
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
13
|
-
}
|
|
11
|
+
this._checkNonNulish(serviceIdentifier);
|
|
14
12
|
if (value === null || value === undefined) {
|
|
15
13
|
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
16
14
|
}
|
|
@@ -23,9 +21,7 @@ var Lookup = (function () {
|
|
|
23
21
|
}
|
|
24
22
|
};
|
|
25
23
|
Lookup.prototype.get = function (serviceIdentifier) {
|
|
26
|
-
|
|
27
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
28
|
-
}
|
|
24
|
+
this._checkNonNulish(serviceIdentifier);
|
|
29
25
|
var entry = this._map.get(serviceIdentifier);
|
|
30
26
|
if (entry !== undefined) {
|
|
31
27
|
return entry;
|
|
@@ -35,9 +31,7 @@ var Lookup = (function () {
|
|
|
35
31
|
}
|
|
36
32
|
};
|
|
37
33
|
Lookup.prototype.remove = function (serviceIdentifier) {
|
|
38
|
-
|
|
39
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
40
|
-
}
|
|
34
|
+
this._checkNonNulish(serviceIdentifier);
|
|
41
35
|
if (!this._map.delete(serviceIdentifier)) {
|
|
42
36
|
throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
|
|
43
37
|
}
|
|
@@ -45,7 +39,9 @@ var Lookup = (function () {
|
|
|
45
39
|
Lookup.prototype.removeIntersection = function (lookup) {
|
|
46
40
|
var _this = this;
|
|
47
41
|
this.traverse(function (serviceIdentifier, value) {
|
|
48
|
-
var lookupActivations = lookup.hasKey(serviceIdentifier)
|
|
42
|
+
var lookupActivations = lookup.hasKey(serviceIdentifier)
|
|
43
|
+
? lookup.get(serviceIdentifier)
|
|
44
|
+
: undefined;
|
|
49
45
|
if (lookupActivations !== undefined) {
|
|
50
46
|
var filteredValues = value.filter(function (lookupValue) {
|
|
51
47
|
return !lookupActivations.some(function (moduleActivation) { return lookupValue === moduleActivation; });
|
|
@@ -74,15 +70,15 @@ var Lookup = (function () {
|
|
|
74
70
|
return removals;
|
|
75
71
|
};
|
|
76
72
|
Lookup.prototype.hasKey = function (serviceIdentifier) {
|
|
77
|
-
|
|
78
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
79
|
-
}
|
|
73
|
+
this._checkNonNulish(serviceIdentifier);
|
|
80
74
|
return this._map.has(serviceIdentifier);
|
|
81
75
|
};
|
|
82
76
|
Lookup.prototype.clone = function () {
|
|
83
77
|
var copy = new Lookup();
|
|
84
78
|
this._map.forEach(function (value, key) {
|
|
85
|
-
value.forEach(function (b) {
|
|
79
|
+
value.forEach(function (b) {
|
|
80
|
+
copy.add(key, isClonable(b) ? b.clone() : b);
|
|
81
|
+
});
|
|
86
82
|
});
|
|
87
83
|
return copy;
|
|
88
84
|
};
|
|
@@ -91,6 +87,11 @@ var Lookup = (function () {
|
|
|
91
87
|
func(key, value);
|
|
92
88
|
});
|
|
93
89
|
};
|
|
90
|
+
Lookup.prototype._checkNonNulish = function (value) {
|
|
91
|
+
if (value == null) {
|
|
92
|
+
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
94
95
|
Lookup.prototype._setValue = function (serviceIdentifier, value) {
|
|
95
96
|
if (value.length > 0) {
|
|
96
97
|
this._map.set(serviceIdentifier, value);
|