inversify 4.11.1 → 5.0.5
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/.auditignore +2 -0
- package/.nyc_output/24cbca0e-b065-453e-9d1e-2a381e69663d.json +1 -0
- package/.nyc_output/processinfo/24cbca0e-b065-453e-9d1e-2a381e69663d.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/CHANGELOG.md +24 -0
- package/README.md +8 -8
- package/amd/annotation/decorator_utils.js +2 -1
- package/amd/annotation/inject.js +1 -0
- package/amd/annotation/injectable.js +1 -0
- package/amd/annotation/multi_inject.js +1 -0
- package/amd/annotation/named.js +1 -0
- package/amd/annotation/optional.js +1 -0
- package/amd/annotation/post_construct.js +1 -0
- package/amd/annotation/tagged.js +1 -0
- package/amd/annotation/target_name.js +1 -0
- package/amd/annotation/unmanaged.js +1 -0
- package/amd/bindings/binding.js +3 -2
- package/amd/bindings/binding_count.js +1 -0
- package/amd/constants/error_msgs.js +11 -2
- package/amd/constants/literal_types.js +1 -0
- package/amd/constants/metadata_keys.js +1 -0
- package/amd/container/container.js +40 -37
- package/amd/container/container_module.js +4 -3
- package/amd/container/container_snapshot.js +1 -0
- package/amd/container/lookup.js +1 -0
- package/amd/inversify.js +27 -26
- package/amd/planning/context.js +3 -2
- package/amd/planning/metadata.js +1 -0
- package/amd/planning/metadata_reader.js +1 -0
- package/amd/planning/plan.js +1 -0
- package/amd/planning/planner.js +8 -0
- package/amd/planning/queryable_string.js +1 -0
- package/amd/planning/reflection_utils.js +12 -8
- package/amd/planning/request.js +3 -2
- package/amd/planning/target.js +3 -2
- package/amd/resolution/instantiation.js +9 -1
- package/amd/resolution/resolver.js +5 -4
- package/amd/syntax/binding_in_syntax.js +1 -0
- package/amd/syntax/binding_in_when_on_syntax.js +1 -0
- package/amd/syntax/binding_on_syntax.js +1 -0
- package/amd/syntax/binding_to_syntax.js +1 -0
- package/amd/syntax/binding_when_on_syntax.js +1 -0
- package/amd/syntax/binding_when_syntax.js +1 -0
- package/amd/syntax/constraint_helpers.js +1 -0
- package/amd/utils/binding_utils.js +1 -0
- package/amd/utils/exceptions.js +1 -0
- package/amd/utils/id.js +10 -0
- package/amd/utils/serialization.js +1 -0
- package/dts/annotation/inject.d.ts +1 -1
- package/dts/bindings/binding.d.ts +1 -1
- package/dts/constants/error_msgs.d.ts +2 -2
- package/dts/container/container.d.ts +5 -5
- package/dts/container/container_module.d.ts +2 -2
- package/dts/container/lookup.d.ts +1 -1
- package/dts/interfaces/interfaces.d.ts +12 -13
- package/dts/inversify.d.ts +1 -1
- package/dts/planning/context.d.ts +1 -1
- package/dts/planning/reflection_utils.d.ts +3 -1
- package/dts/planning/request.d.ts +1 -1
- package/dts/planning/target.d.ts +1 -1
- package/dts/syntax/binding_to_syntax.d.ts +1 -3
- package/dts/syntax/constraint_helpers.d.ts +2 -2
- package/dts/utils/binding_utils.d.ts +1 -1
- package/dts/utils/cat.d.ts +5 -0
- package/dts/utils/dog.d.ts +3 -0
- package/dts/utils/id.d.ts +2 -0
- package/es/annotation/decorator_utils.js +1 -1
- package/es/bindings/binding.js +2 -2
- package/es/constants/error_msgs.js +10 -2
- package/es/container/container.js +39 -37
- package/es/container/container_module.js +3 -3
- package/es/inversify.js +1 -1
- package/es/planning/context.js +2 -2
- package/es/planning/planner.js +8 -1
- package/es/planning/reflection_utils.js +10 -9
- package/es/planning/request.js +2 -2
- package/es/planning/target.js +2 -2
- package/es/resolution/instantiation.js +8 -1
- package/es/resolution/resolver.js +4 -4
- package/es/utils/id.js +5 -0
- package/lib/annotation/decorator_utils.js +2 -1
- package/lib/annotation/inject.js +1 -0
- package/lib/annotation/injectable.js +1 -0
- package/lib/annotation/multi_inject.js +1 -0
- package/lib/annotation/named.js +1 -0
- package/lib/annotation/optional.js +1 -0
- package/lib/annotation/post_construct.js +1 -0
- package/lib/annotation/tagged.js +1 -0
- package/lib/annotation/target_name.js +1 -0
- package/lib/annotation/unmanaged.js +1 -0
- package/lib/bindings/binding.js +3 -2
- package/lib/bindings/binding_count.js +1 -0
- package/lib/constants/error_msgs.js +11 -2
- package/lib/constants/literal_types.js +1 -0
- package/lib/constants/metadata_keys.js +1 -0
- package/lib/container/container.js +40 -37
- package/lib/container/container_module.js +4 -3
- package/lib/container/container_snapshot.js +1 -0
- package/lib/container/lookup.js +1 -0
- package/lib/inversify.js +27 -26
- package/lib/planning/context.js +3 -2
- package/lib/planning/metadata.js +1 -0
- package/lib/planning/metadata_reader.js +1 -0
- package/lib/planning/plan.js +1 -0
- package/lib/planning/planner.js +8 -0
- package/lib/planning/queryable_string.js +1 -0
- package/lib/planning/reflection_utils.js +12 -8
- package/lib/planning/request.js +3 -2
- package/lib/planning/target.js +3 -2
- package/lib/resolution/instantiation.js +9 -1
- package/lib/resolution/resolver.js +5 -4
- package/lib/syntax/binding_in_syntax.js +1 -0
- package/lib/syntax/binding_in_when_on_syntax.js +1 -0
- package/lib/syntax/binding_on_syntax.js +1 -0
- package/lib/syntax/binding_to_syntax.js +1 -0
- package/lib/syntax/binding_when_on_syntax.js +1 -0
- package/lib/syntax/binding_when_syntax.js +1 -0
- package/lib/syntax/constraint_helpers.js +1 -0
- package/lib/utils/binding_utils.js +1 -0
- package/lib/utils/exceptions.js +1 -0
- package/lib/utils/id.js +8 -0
- package/lib/utils/serialization.js +1 -0
- package/mocha.opts +3 -0
- package/package.json +39 -33
- package/amd/utils/guid.js +0 -14
- package/appveyor.yml +0 -34
- package/dts/utils/guid.d.ts +0 -2
- package/es/utils/guid.js +0 -10
- package/lib/utils/guid.js +0 -12
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3
4
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4
5
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
5
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
6
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
7
8
|
});
|
|
8
9
|
};
|
|
@@ -13,8 +14,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
13
14
|
function step(op) {
|
|
14
15
|
if (f) throw new TypeError("Generator is already executing.");
|
|
15
16
|
while (_) try {
|
|
16
|
-
if (f = 1, y && (t =
|
|
17
|
-
if (y = 0, t) op = [0, t.value];
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
18
19
|
switch (op[0]) {
|
|
19
20
|
case 0: case 1: t = op; break;
|
|
20
21
|
case 4: _.label++; return { value: op[1], done: false };
|
|
@@ -41,40 +42,42 @@ import { MetadataReader } from "../planning/metadata_reader";
|
|
|
41
42
|
import { createMockRequest, getBindingDictionary, plan } from "../planning/planner";
|
|
42
43
|
import { resolve } from "../resolution/resolver";
|
|
43
44
|
import { BindingToSyntax } from "../syntax/binding_to_syntax";
|
|
44
|
-
import {
|
|
45
|
+
import { id } from "../utils/id";
|
|
45
46
|
import { getServiceIdentifierAsString } from "../utils/serialization";
|
|
46
47
|
import { ContainerSnapshot } from "./container_snapshot";
|
|
47
48
|
import { Lookup } from "./lookup";
|
|
48
49
|
var Container = (function () {
|
|
49
50
|
function Container(containerOptions) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
56
|
-
containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
|
|
57
|
-
containerOptions.defaultScope !== BindingScopeEnum.Transient &&
|
|
58
|
-
containerOptions.defaultScope !== BindingScopeEnum.Request) {
|
|
59
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
60
|
-
}
|
|
61
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
62
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
63
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.options = {
|
|
67
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
68
|
-
defaultScope: containerOptions.defaultScope
|
|
69
|
-
};
|
|
51
|
+
var options = containerOptions || {};
|
|
52
|
+
if (typeof options !== "object") {
|
|
53
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
70
54
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
autoBindInjectable: false,
|
|
74
|
-
defaultScope: BindingScopeEnum.Transient
|
|
75
|
-
};
|
|
55
|
+
if (options.defaultScope === undefined) {
|
|
56
|
+
options.defaultScope = BindingScopeEnum.Transient;
|
|
76
57
|
}
|
|
77
|
-
|
|
58
|
+
else if (options.defaultScope !== BindingScopeEnum.Singleton &&
|
|
59
|
+
options.defaultScope !== BindingScopeEnum.Transient &&
|
|
60
|
+
options.defaultScope !== BindingScopeEnum.Request) {
|
|
61
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
62
|
+
}
|
|
63
|
+
if (options.autoBindInjectable === undefined) {
|
|
64
|
+
options.autoBindInjectable = false;
|
|
65
|
+
}
|
|
66
|
+
else if (typeof options.autoBindInjectable !== "boolean") {
|
|
67
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
68
|
+
}
|
|
69
|
+
if (options.skipBaseClassChecks === undefined) {
|
|
70
|
+
options.skipBaseClassChecks = false;
|
|
71
|
+
}
|
|
72
|
+
else if (typeof options.skipBaseClassChecks !== "boolean") {
|
|
73
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
74
|
+
}
|
|
75
|
+
this.options = {
|
|
76
|
+
autoBindInjectable: options.autoBindInjectable,
|
|
77
|
+
defaultScope: options.defaultScope,
|
|
78
|
+
skipBaseClassChecks: options.skipBaseClassChecks
|
|
79
|
+
};
|
|
80
|
+
this.id = id();
|
|
78
81
|
this._bindingDictionary = new Lookup();
|
|
79
82
|
this._snapshots = [];
|
|
80
83
|
this._middleware = null;
|
|
@@ -105,7 +108,7 @@ var Container = (function () {
|
|
|
105
108
|
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
106
109
|
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
107
110
|
var currentModule = modules_1[_a];
|
|
108
|
-
var containerModuleHelpers = getHelpers(currentModule.
|
|
111
|
+
var containerModuleHelpers = getHelpers(currentModule.id);
|
|
109
112
|
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
110
113
|
}
|
|
111
114
|
};
|
|
@@ -125,7 +128,7 @@ var Container = (function () {
|
|
|
125
128
|
case 1:
|
|
126
129
|
if (!(_a < modules_2.length)) return [3, 4];
|
|
127
130
|
currentModule = modules_2[_a];
|
|
128
|
-
containerModuleHelpers = getHelpers(currentModule.
|
|
131
|
+
containerModuleHelpers = getHelpers(currentModule.id);
|
|
129
132
|
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
130
133
|
case 2:
|
|
131
134
|
_b.sent();
|
|
@@ -148,7 +151,7 @@ var Container = (function () {
|
|
|
148
151
|
return item.moduleId === expected;
|
|
149
152
|
}; };
|
|
150
153
|
modules.forEach(function (module) {
|
|
151
|
-
var condition = conditionFactory(module.
|
|
154
|
+
var condition = conditionFactory(module.id);
|
|
152
155
|
_this._bindingDictionary.removeByCondition(condition);
|
|
153
156
|
});
|
|
154
157
|
};
|
|
@@ -206,8 +209,8 @@ var Container = (function () {
|
|
|
206
209
|
this._bindingDictionary = snapshot.bindings;
|
|
207
210
|
this._middleware = snapshot.middleware;
|
|
208
211
|
};
|
|
209
|
-
Container.prototype.createChild = function () {
|
|
210
|
-
var child = new Container();
|
|
212
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
213
|
+
var child = new Container(containerOptions || this.options);
|
|
211
214
|
child.parent = this;
|
|
212
215
|
return child;
|
|
213
216
|
};
|
|
@@ -241,9 +244,8 @@ var Container = (function () {
|
|
|
241
244
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
242
245
|
};
|
|
243
246
|
Container.prototype.resolve = function (constructorFunction) {
|
|
244
|
-
var tempContainer =
|
|
247
|
+
var tempContainer = this.createChild();
|
|
245
248
|
tempContainer.bind(constructorFunction).toSelf();
|
|
246
|
-
tempContainer.parent = this;
|
|
247
249
|
return tempContainer.get(constructorFunction);
|
|
248
250
|
};
|
|
249
251
|
Container.prototype._getContainerModuleHelpersFactory = function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id } from "../utils/id";
|
|
2
2
|
var ContainerModule = (function () {
|
|
3
3
|
function ContainerModule(registry) {
|
|
4
|
-
this.
|
|
4
|
+
this.id = id();
|
|
5
5
|
this.registry = registry;
|
|
6
6
|
}
|
|
7
7
|
return ContainerModule;
|
|
@@ -9,7 +9,7 @@ var ContainerModule = (function () {
|
|
|
9
9
|
export { ContainerModule };
|
|
10
10
|
var AsyncContainerModule = (function () {
|
|
11
11
|
function AsyncContainerModule(registry) {
|
|
12
|
-
this.
|
|
12
|
+
this.id = id();
|
|
13
13
|
this.registry = registry;
|
|
14
14
|
}
|
|
15
15
|
return AsyncContainerModule;
|
package/es/inversify.js
CHANGED
|
@@ -13,7 +13,7 @@ export { multiInject } from "./annotation/multi_inject";
|
|
|
13
13
|
export { targetName } from "./annotation/target_name";
|
|
14
14
|
export { postConstruct } from "./annotation/post_construct";
|
|
15
15
|
export { MetadataReader } from "./planning/metadata_reader";
|
|
16
|
-
export {
|
|
16
|
+
export { id } from "./utils/id";
|
|
17
17
|
export { decorate } from "./annotation/decorator_utils";
|
|
18
18
|
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint } from "./syntax/constraint_helpers";
|
|
19
19
|
export { getServiceIdentifierAsString } from "./utils/serialization";
|
package/es/planning/context.js
CHANGED
package/es/planning/planner.js
CHANGED
|
@@ -7,7 +7,7 @@ import { circularDependencyToException, getServiceIdentifierAsString, listMetada
|
|
|
7
7
|
import { Context } from "./context";
|
|
8
8
|
import { Metadata } from "./metadata";
|
|
9
9
|
import { Plan } from "./plan";
|
|
10
|
-
import { getDependencies } from "./reflection_utils";
|
|
10
|
+
import { getBaseClassDependencyCount, getDependencies, getFunctionName } from "./reflection_utils";
|
|
11
11
|
import { Request } from "./request";
|
|
12
12
|
import { Target } from "./target";
|
|
13
13
|
function getBindingDictionary(cntnr) {
|
|
@@ -101,6 +101,13 @@ function _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier,
|
|
|
101
101
|
}
|
|
102
102
|
if (binding.type === BindingTypeEnum.Instance && binding.implementationType !== null) {
|
|
103
103
|
var dependencies = getDependencies(metadataReader, binding.implementationType);
|
|
104
|
+
if (!context.container.options.skipBaseClassChecks) {
|
|
105
|
+
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, binding.implementationType);
|
|
106
|
+
if (dependencies.length < baseClassDependencyCount) {
|
|
107
|
+
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH(getFunctionName(binding.implementationType));
|
|
108
|
+
throw new Error(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
104
111
|
dependencies.forEach(function (dependency) {
|
|
105
112
|
_createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency);
|
|
106
113
|
});
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
2
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
5
|
+
r[k] = a[j];
|
|
6
|
+
return r;
|
|
7
|
+
};
|
|
1
8
|
import { LazyServiceIdentifer } from "../annotation/inject";
|
|
2
9
|
import * as ERROR_MSGS from "../constants/error_msgs";
|
|
3
10
|
import { TargetTypeEnum } from "../constants/literal_types";
|
|
@@ -22,13 +29,7 @@ function getTargets(metadataReader, constructorName, func, isBaseClass) {
|
|
|
22
29
|
var iterations = (hasUserDeclaredUnknownInjections) ? keys.length : func.length;
|
|
23
30
|
var constructorTargets = getConstructorArgsAsTargets(isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata, iterations);
|
|
24
31
|
var propertyTargets = getClassPropsAsTargets(metadataReader, func);
|
|
25
|
-
var targets = constructorTargets
|
|
26
|
-
var baseClassDependencyCount = getBaseClassDependencyCount(metadataReader, func);
|
|
27
|
-
if (targets.length < baseClassDependencyCount) {
|
|
28
|
-
var error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_1 +
|
|
29
|
-
constructorName + ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH_2;
|
|
30
|
-
throw new Error(error);
|
|
31
|
-
}
|
|
32
|
+
var targets = __spreadArrays(constructorTargets, propertyTargets);
|
|
32
33
|
return targets;
|
|
33
34
|
}
|
|
34
35
|
function getConstructorArgsAsTarget(index, isBaseClass, constructorName, serviceIdentifiers, constructorArgsMetadata) {
|
|
@@ -84,7 +85,7 @@ function getClassPropsAsTargets(metadataReader, constructorFunc) {
|
|
|
84
85
|
var baseConstructor = Object.getPrototypeOf(constructorFunc.prototype).constructor;
|
|
85
86
|
if (baseConstructor !== Object) {
|
|
86
87
|
var baseTargets = getClassPropsAsTargets(metadataReader, baseConstructor);
|
|
87
|
-
targets = targets
|
|
88
|
+
targets = __spreadArrays(targets, baseTargets);
|
|
88
89
|
}
|
|
89
90
|
return targets;
|
|
90
91
|
}
|
|
@@ -123,4 +124,4 @@ function formatTargetMetadata(targetMetadata) {
|
|
|
123
124
|
unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG]
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
|
-
export { getDependencies };
|
|
127
|
+
export { getDependencies, getBaseClassDependencyCount, getFunctionName };
|
package/es/planning/request.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id } from "../utils/id";
|
|
2
2
|
var Request = (function () {
|
|
3
3
|
function Request(serviceIdentifier, parentContext, parentRequest, bindings, target) {
|
|
4
|
-
this.
|
|
4
|
+
this.id = id();
|
|
5
5
|
this.serviceIdentifier = serviceIdentifier;
|
|
6
6
|
this.parentContext = parentContext;
|
|
7
7
|
this.parentRequest = parentRequest;
|
package/es/planning/target.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as METADATA_KEY from "../constants/metadata_keys";
|
|
2
|
-
import {
|
|
2
|
+
import { id } from "../utils/id";
|
|
3
3
|
import { Metadata } from "./metadata";
|
|
4
4
|
import { QueryableString } from "./queryable_string";
|
|
5
5
|
var Target = (function () {
|
|
6
6
|
function Target(type, name, serviceIdentifier, namedOrTagged) {
|
|
7
|
-
this.
|
|
7
|
+
this.id = id();
|
|
8
8
|
this.type = type;
|
|
9
9
|
this.serviceIdentifier = serviceIdentifier;
|
|
10
10
|
this.name = new QueryableString(name || "");
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
2
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
5
|
+
r[k] = a[j];
|
|
6
|
+
return r;
|
|
7
|
+
};
|
|
1
8
|
import { POST_CONSTRUCT_ERROR } from "../constants/error_msgs";
|
|
2
9
|
import { TargetTypeEnum } from "../constants/literal_types";
|
|
3
10
|
import * as METADATA_KEY from "../constants/metadata_keys";
|
|
@@ -16,7 +23,7 @@ function _injectProperties(instance, childRequests, resolveRequest) {
|
|
|
16
23
|
return instance;
|
|
17
24
|
}
|
|
18
25
|
function _createInstance(Func, injections) {
|
|
19
|
-
return new (Func.bind.apply(Func, [void 0]
|
|
26
|
+
return new (Func.bind.apply(Func, __spreadArrays([void 0], injections)))();
|
|
20
27
|
}
|
|
21
28
|
function _postConstruct(constr, result) {
|
|
22
29
|
if (Reflect.hasMetadata(METADATA_KEY.POST_CONSTRUCT, constr)) {
|
|
@@ -45,8 +45,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
45
45
|
}
|
|
46
46
|
if (isRequestSingleton &&
|
|
47
47
|
requestScope !== null &&
|
|
48
|
-
requestScope.has(binding_1.
|
|
49
|
-
return requestScope.get(binding_1.
|
|
48
|
+
requestScope.has(binding_1.id)) {
|
|
49
|
+
return requestScope.get(binding_1.id);
|
|
50
50
|
}
|
|
51
51
|
if (binding_1.type === BindingTypeEnum.ConstantValue) {
|
|
52
52
|
result = binding_1.cache;
|
|
@@ -82,8 +82,8 @@ var _resolveRequest = function (requestScope) {
|
|
|
82
82
|
}
|
|
83
83
|
if (isRequestSingleton &&
|
|
84
84
|
requestScope !== null &&
|
|
85
|
-
!requestScope.has(binding_1.
|
|
86
|
-
requestScope.set(binding_1.
|
|
85
|
+
!requestScope.has(binding_1.id)) {
|
|
86
|
+
requestScope.set(binding_1.id, result);
|
|
87
87
|
}
|
|
88
88
|
return result;
|
|
89
89
|
}
|
package/es/utils/id.js
ADDED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tagProperty = exports.tagParameter = exports.decorate = void 0;
|
|
3
4
|
var ERROR_MSGS = require("../constants/error_msgs");
|
|
4
5
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
5
6
|
function tagParameter(annotationTarget, propertyName, parameterIndex, metadata) {
|
|
@@ -30,7 +31,7 @@ function _tagParameterOrProperty(metadataKey, annotationTarget, propertyName, me
|
|
|
30
31
|
for (var _i = 0, paramOrPropertyMetadata_1 = paramOrPropertyMetadata; _i < paramOrPropertyMetadata_1.length; _i++) {
|
|
31
32
|
var m = paramOrPropertyMetadata_1[_i];
|
|
32
33
|
if (m.key === metadata.key) {
|
|
33
|
-
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key);
|
|
34
|
+
throw new Error(ERROR_MSGS.DUPLICATED_METADATA + " " + m.key.toString());
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
package/lib/annotation/inject.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inject = exports.LazyServiceIdentifer = void 0;
|
|
3
4
|
var error_msgs_1 = require("../constants/error_msgs");
|
|
4
5
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
5
6
|
var metadata_1 = require("../planning/metadata");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.multiInject = void 0;
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
package/lib/annotation/named.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.named = void 0;
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.optional = void 0;
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postConstruct = void 0;
|
|
3
4
|
var ERRORS_MSGS = require("../constants/error_msgs");
|
|
4
5
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
5
6
|
var metadata_1 = require("../planning/metadata");
|
package/lib/annotation/tagged.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.targetName = void 0;
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unmanaged = void 0;
|
|
3
4
|
var METADATA_KEY = require("../constants/metadata_keys");
|
|
4
5
|
var metadata_1 = require("../planning/metadata");
|
|
5
6
|
var decorator_utils_1 = require("./decorator_utils");
|
package/lib/bindings/binding.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Binding = void 0;
|
|
3
4
|
var literal_types_1 = require("../constants/literal_types");
|
|
4
|
-
var
|
|
5
|
+
var id_1 = require("../utils/id");
|
|
5
6
|
var Binding = (function () {
|
|
6
7
|
function Binding(serviceIdentifier, scope) {
|
|
7
|
-
this.
|
|
8
|
+
this.id = id_1.id();
|
|
8
9
|
this.activated = false;
|
|
9
10
|
this.serviceIdentifier = serviceIdentifier;
|
|
10
11
|
this.scope = scope;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STACK_OVERFLOW = exports.CIRCULAR_DEPENDENCY_IN_FACTORY = exports.POST_CONSTRUCT_ERROR = exports.MULTIPLE_POST_CONSTRUCT_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.INVALID_FUNCTION_BINDING = exports.INVALID_MIDDLEWARE_RETURN = exports.NO_MORE_SNAPSHOTS_AVAILABLE = exports.INVALID_BINDING_TYPE = exports.NOT_IMPLEMENTED = exports.CIRCULAR_DEPENDENCY = exports.UNDEFINED_INJECT_ANNOTATION = exports.MISSING_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;
|
|
3
4
|
exports.DUPLICATED_INJECTABLE_DECORATOR = "Cannot apply @injectable decorator multiple times.";
|
|
4
5
|
exports.DUPLICATED_METADATA = "Metadata key was used more than once in a parameter:";
|
|
5
6
|
exports.NULL_ARGUMENT = "NULL argument";
|
|
@@ -24,14 +25,22 @@ exports.INVALID_TO_SELF_VALUE = "The toSelf function can only be applied when a
|
|
|
24
25
|
"used as service identifier";
|
|
25
26
|
exports.INVALID_DECORATOR_OPERATION = "The @inject @multiInject @tagged and @named decorators " +
|
|
26
27
|
"must be applied to the parameters of a class constructor or a class property.";
|
|
27
|
-
exports.
|
|
28
|
-
|
|
28
|
+
exports.ARGUMENTS_LENGTH_MISMATCH = function () {
|
|
29
|
+
var values = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
values[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
return "The number of constructor arguments in the derived class " +
|
|
34
|
+
(values[0] + " must be >= than the number of constructor arguments of its base class.");
|
|
35
|
+
};
|
|
29
36
|
exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = "Invalid Container constructor argument. Container options " +
|
|
30
37
|
"must be an object.";
|
|
31
38
|
exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = "Invalid Container option. Default scope must " +
|
|
32
39
|
"be a string ('singleton' or 'transient').";
|
|
33
40
|
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
|
|
34
41
|
"be a boolean";
|
|
42
|
+
exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = "Invalid Container option. Skip base check must " +
|
|
43
|
+
"be a boolean";
|
|
35
44
|
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
|
|
36
45
|
exports.POST_CONSTRUCT_ERROR = function () {
|
|
37
46
|
var values = [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POST_CONSTRUCT = exports.DESIGN_PARAM_TYPES = exports.PARAM_TYPES = exports.TAGGED_PROP = exports.TAGGED = exports.MULTI_INJECT_TAG = exports.INJECT_TAG = exports.OPTIONAL_TAG = exports.UNMANAGED_TAG = exports.NAME_TAG = exports.NAMED_TAG = void 0;
|
|
3
4
|
exports.NAMED_TAG = "named";
|
|
4
5
|
exports.NAME_TAG = "name";
|
|
5
6
|
exports.UNMANAGED_TAG = "unmanaged";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
@@ -14,8 +15,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
15
|
function step(op) {
|
|
15
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
16
17
|
while (_) try {
|
|
17
|
-
if (f = 1, y && (t =
|
|
18
|
-
if (y = 0, t) op = [0, t.value];
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
20
|
switch (op[0]) {
|
|
20
21
|
case 0: case 1: t = op; break;
|
|
21
22
|
case 4: _.label++; return { value: op[1], done: false };
|
|
@@ -35,6 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Container = void 0;
|
|
38
40
|
var binding_1 = require("../bindings/binding");
|
|
39
41
|
var ERROR_MSGS = require("../constants/error_msgs");
|
|
40
42
|
var literal_types_1 = require("../constants/literal_types");
|
|
@@ -43,40 +45,42 @@ var metadata_reader_1 = require("../planning/metadata_reader");
|
|
|
43
45
|
var planner_1 = require("../planning/planner");
|
|
44
46
|
var resolver_1 = require("../resolution/resolver");
|
|
45
47
|
var binding_to_syntax_1 = require("../syntax/binding_to_syntax");
|
|
46
|
-
var
|
|
48
|
+
var id_1 = require("../utils/id");
|
|
47
49
|
var serialization_1 = require("../utils/serialization");
|
|
48
50
|
var container_snapshot_1 = require("./container_snapshot");
|
|
49
51
|
var lookup_1 = require("./lookup");
|
|
50
52
|
var Container = (function () {
|
|
51
53
|
function Container(containerOptions) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
if (containerOptions.defaultScope !== undefined &&
|
|
58
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
59
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
60
|
-
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
61
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
62
|
-
}
|
|
63
|
-
if (containerOptions.autoBindInjectable !== undefined &&
|
|
64
|
-
typeof containerOptions.autoBindInjectable !== "boolean") {
|
|
65
|
-
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this.options = {
|
|
69
|
-
autoBindInjectable: containerOptions.autoBindInjectable,
|
|
70
|
-
defaultScope: containerOptions.defaultScope
|
|
71
|
-
};
|
|
54
|
+
var options = containerOptions || {};
|
|
55
|
+
if (typeof options !== "object") {
|
|
56
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
72
57
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
autoBindInjectable: false,
|
|
76
|
-
defaultScope: literal_types_1.BindingScopeEnum.Transient
|
|
77
|
-
};
|
|
58
|
+
if (options.defaultScope === undefined) {
|
|
59
|
+
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
78
60
|
}
|
|
79
|
-
|
|
61
|
+
else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
62
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
63
|
+
options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
64
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
65
|
+
}
|
|
66
|
+
if (options.autoBindInjectable === undefined) {
|
|
67
|
+
options.autoBindInjectable = false;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof options.autoBindInjectable !== "boolean") {
|
|
70
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
71
|
+
}
|
|
72
|
+
if (options.skipBaseClassChecks === undefined) {
|
|
73
|
+
options.skipBaseClassChecks = false;
|
|
74
|
+
}
|
|
75
|
+
else if (typeof options.skipBaseClassChecks !== "boolean") {
|
|
76
|
+
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
77
|
+
}
|
|
78
|
+
this.options = {
|
|
79
|
+
autoBindInjectable: options.autoBindInjectable,
|
|
80
|
+
defaultScope: options.defaultScope,
|
|
81
|
+
skipBaseClassChecks: options.skipBaseClassChecks
|
|
82
|
+
};
|
|
83
|
+
this.id = id_1.id();
|
|
80
84
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
81
85
|
this._snapshots = [];
|
|
82
86
|
this._middleware = null;
|
|
@@ -107,7 +111,7 @@ var Container = (function () {
|
|
|
107
111
|
var getHelpers = this._getContainerModuleHelpersFactory();
|
|
108
112
|
for (var _a = 0, modules_1 = modules; _a < modules_1.length; _a++) {
|
|
109
113
|
var currentModule = modules_1[_a];
|
|
110
|
-
var containerModuleHelpers = getHelpers(currentModule.
|
|
114
|
+
var containerModuleHelpers = getHelpers(currentModule.id);
|
|
111
115
|
currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction);
|
|
112
116
|
}
|
|
113
117
|
};
|
|
@@ -127,7 +131,7 @@ var Container = (function () {
|
|
|
127
131
|
case 1:
|
|
128
132
|
if (!(_a < modules_2.length)) return [3, 4];
|
|
129
133
|
currentModule = modules_2[_a];
|
|
130
|
-
containerModuleHelpers = getHelpers(currentModule.
|
|
134
|
+
containerModuleHelpers = getHelpers(currentModule.id);
|
|
131
135
|
return [4, currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction)];
|
|
132
136
|
case 2:
|
|
133
137
|
_b.sent();
|
|
@@ -150,7 +154,7 @@ var Container = (function () {
|
|
|
150
154
|
return item.moduleId === expected;
|
|
151
155
|
}; };
|
|
152
156
|
modules.forEach(function (module) {
|
|
153
|
-
var condition = conditionFactory(module.
|
|
157
|
+
var condition = conditionFactory(module.id);
|
|
154
158
|
_this._bindingDictionary.removeByCondition(condition);
|
|
155
159
|
});
|
|
156
160
|
};
|
|
@@ -208,8 +212,8 @@ var Container = (function () {
|
|
|
208
212
|
this._bindingDictionary = snapshot.bindings;
|
|
209
213
|
this._middleware = snapshot.middleware;
|
|
210
214
|
};
|
|
211
|
-
Container.prototype.createChild = function () {
|
|
212
|
-
var child = new Container();
|
|
215
|
+
Container.prototype.createChild = function (containerOptions) {
|
|
216
|
+
var child = new Container(containerOptions || this.options);
|
|
213
217
|
child.parent = this;
|
|
214
218
|
return child;
|
|
215
219
|
};
|
|
@@ -243,9 +247,8 @@ var Container = (function () {
|
|
|
243
247
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
244
248
|
};
|
|
245
249
|
Container.prototype.resolve = function (constructorFunction) {
|
|
246
|
-
var tempContainer =
|
|
250
|
+
var tempContainer = this.createChild();
|
|
247
251
|
tempContainer.bind(constructorFunction).toSelf();
|
|
248
|
-
tempContainer.parent = this;
|
|
249
252
|
return tempContainer.get(constructorFunction);
|
|
250
253
|
};
|
|
251
254
|
Container.prototype._getContainerModuleHelpersFactory = function () {
|