inversify 6.1.4 → 6.1.5-beta.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 +11 -1
- package/README.md +6 -15
- package/es/container/container.d.ts +2 -0
- package/es/container/module_activation_store.d.ts +2 -2
- package/es/interfaces/interfaces.d.ts +2 -2
- package/es/inversify.d.ts +1 -0
- package/es/inversify.js +3 -2
- package/es/inversify.js.LICENSE.txt +14 -0
- package/lib/annotation/decorator_utils.js +31 -25
- package/lib/annotation/inject.js +20 -10
- package/lib/annotation/inject_base.js +6 -6
- package/lib/annotation/injectable.js +20 -10
- package/lib/annotation/multi_inject.js +20 -10
- package/lib/annotation/named.js +20 -10
- package/lib/annotation/optional.js +20 -10
- package/lib/annotation/post_construct.js +21 -11
- package/lib/annotation/pre_destroy.js +21 -11
- package/lib/annotation/property_event_decorator.js +4 -4
- package/lib/annotation/tagged.js +2 -2
- package/lib/annotation/target_name.js +21 -11
- package/lib/annotation/unmanaged.js +21 -11
- package/lib/bindings/binding.js +23 -10
- package/lib/constants/error_msgs.js +15 -29
- package/lib/constants/literal_types.js +3 -3
- package/lib/container/container.d.ts +2 -0
- package/lib/container/container.js +317 -566
- package/lib/container/container_module.js +11 -9
- package/lib/container/container_snapshot.js +10 -8
- package/lib/container/lookup.js +61 -56
- package/lib/container/module_activation_store.d.ts +2 -2
- package/lib/container/module_activation_store.js +21 -24
- package/lib/interfaces/interfaces.d.ts +2 -2
- package/lib/inversify.d.ts +1 -0
- package/lib/inversify.js +19 -8
- package/lib/planning/context.js +12 -9
- package/lib/planning/metadata.js +27 -16
- package/lib/planning/metadata_reader.js +29 -24
- package/lib/planning/plan.js +5 -4
- package/lib/planning/planner.js +62 -53
- package/lib/planning/queryable_string.js +16 -16
- package/lib/planning/reflection_utils.js +25 -17
- package/lib/planning/request.js +15 -8
- package/lib/resolution/instantiation.js +59 -119
- package/lib/resolution/resolver.js +89 -134
- package/lib/scope/scope.js +17 -62
- package/lib/syntax/binding_in_syntax.js +12 -12
- package/lib/syntax/binding_in_when_on_syntax.js +50 -47
- package/lib/syntax/binding_on_syntax.js +9 -9
- package/lib/syntax/binding_to_syntax.js +70 -49
- package/lib/syntax/binding_when_on_syntax.js +42 -40
- package/lib/syntax/binding_when_syntax.js +54 -76
- package/lib/syntax/constraint_helpers.js +31 -23
- package/lib/utils/async.js +1 -1
- package/lib/utils/binding_utils.js +31 -29
- package/lib/utils/exceptions.js +19 -9
- package/lib/utils/id.js +1 -1
- package/lib/utils/js.js +2 -3
- package/lib/utils/serialization.js +42 -33
- package/package.json +14 -15
- package/amd/annotation/decorator_utils.d.ts +0 -16
- package/amd/annotation/decorator_utils.js +0 -119
- package/amd/annotation/inject.d.ts +0 -5
- package/amd/annotation/inject.js +0 -31
- package/amd/annotation/inject_base.d.ts +0 -4
- package/amd/annotation/inject_base.js +0 -16
- package/amd/annotation/injectable.d.ts +0 -2
- package/amd/annotation/injectable.js +0 -40
- package/amd/annotation/lazy_service_identifier.js +0 -4
- package/amd/annotation/multi_inject.d.ts +0 -5
- package/amd/annotation/multi_inject.js +0 -31
- package/amd/annotation/named.d.ts +0 -2
- package/amd/annotation/named.js +0 -32
- package/amd/annotation/optional.d.ts +0 -2
- package/amd/annotation/optional.js +0 -32
- package/amd/annotation/post_construct.d.ts +0 -4
- package/amd/annotation/post_construct.js +0 -32
- package/amd/annotation/pre_destroy.d.ts +0 -4
- package/amd/annotation/pre_destroy.js +0 -32
- package/amd/annotation/property_event_decorator.d.ts +0 -4
- package/amd/annotation/property_event_decorator.js +0 -16
- package/amd/annotation/tagged.d.ts +0 -2
- package/amd/annotation/tagged.js +0 -8
- package/amd/annotation/target_name.d.ts +0 -3
- package/amd/annotation/target_name.js +0 -35
- package/amd/annotation/unmanaged.d.ts +0 -3
- package/amd/annotation/unmanaged.js +0 -35
- package/amd/bindings/binding.d.ts +0 -20
- package/amd/bindings/binding.js +0 -40
- package/amd/bindings/binding_count.d.ts +0 -5
- package/amd/bindings/binding_count.js +0 -11
- package/amd/constants/error_msgs.d.ts +0 -30
- package/amd/constants/error_msgs.js +0 -75
- package/amd/constants/literal_types.d.ts +0 -5
- package/amd/constants/literal_types.js +0 -28
- package/amd/constants/metadata_keys.d.ts +0 -13
- package/amd/constants/metadata_keys.js +0 -28
- package/amd/container/container.d.ts +0 -73
- package/amd/container/container.js +0 -766
- package/amd/container/container_module.d.ts +0 -11
- package/amd/container/container_module.js +0 -21
- package/amd/container/container_snapshot.d.ts +0 -10
- package/amd/container/container_snapshot.js +0 -20
- package/amd/container/lookup.d.ts +0 -17
- package/amd/container/lookup.js +0 -132
- package/amd/container/module_activation_store.d.ts +0 -10
- package/amd/container/module_activation_store.js +0 -51
- package/amd/interfaces/interfaces.d.ts +0 -269
- package/amd/interfaces/interfaces.js +0 -4
- package/amd/inversify.d.ts +0 -24
- package/amd/inversify.js +0 -57
- package/amd/planning/context.d.ts +0 -11
- package/amd/planning/context.js +0 -19
- package/amd/planning/metadata.d.ts +0 -8
- package/amd/planning/metadata.js +0 -45
- package/amd/planning/metadata_reader.d.ts +0 -6
- package/amd/planning/metadata_reader.js +0 -49
- package/amd/planning/plan.d.ts +0 -7
- package/amd/planning/plan.js +0 -13
- package/amd/planning/planner.d.ts +0 -5
- package/amd/planning/planner.js +0 -187
- package/amd/planning/queryable_string.d.ts +0 -10
- package/amd/planning/queryable_string.js +0 -33
- package/amd/planning/reflection_utils.d.ts +0 -5
- package/amd/planning/reflection_utils.js +0 -55
- package/amd/planning/request.d.ts +0 -14
- package/amd/planning/request.js +0 -24
- package/amd/planning/target.js +0 -111
- package/amd/resolution/instantiation.d.ts +0 -3
- package/amd/resolution/instantiation.js +0 -219
- package/amd/resolution/resolver.d.ts +0 -3
- package/amd/resolution/resolver.js +0 -234
- package/amd/scope/scope.d.ts +0 -3
- package/amd/scope/scope.js +0 -93
- package/amd/syntax/binding_in_syntax.d.ts +0 -9
- package/amd/syntax/binding_in_syntax.js +0 -24
- package/amd/syntax/binding_in_when_on_syntax.d.ts +0 -29
- package/amd/syntax/binding_in_when_on_syntax.js +0 -75
- package/amd/syntax/binding_on_syntax.d.ts +0 -8
- package/amd/syntax/binding_on_syntax.js +0 -20
- package/amd/syntax/binding_to_syntax.d.ts +0 -18
- package/amd/syntax/binding_to_syntax.js +0 -116
- package/amd/syntax/binding_when_on_syntax.d.ts +0 -25
- package/amd/syntax/binding_when_on_syntax.js +0 -65
- package/amd/syntax/binding_when_syntax.d.ts +0 -21
- package/amd/syntax/binding_when_syntax.js +0 -107
- package/amd/syntax/constraint_helpers.d.ts +0 -6
- package/amd/syntax/constraint_helpers.js +0 -66
- package/amd/utils/async.d.ts +0 -3
- package/amd/utils/async.js +0 -17
- package/amd/utils/binding_utils.d.ts +0 -4
- package/amd/utils/binding_utils.js +0 -86
- package/amd/utils/clonable.d.ts +0 -3
- package/amd/utils/clonable.js +0 -11
- package/amd/utils/exceptions.d.ts +0 -2
- package/amd/utils/exceptions.js +0 -46
- package/amd/utils/factory_type.d.ts +0 -5
- package/amd/utils/factory_type.js +0 -11
- package/amd/utils/id.d.ts +0 -2
- package/amd/utils/id.js +0 -9
- package/amd/utils/js.d.ts +0 -1
- package/amd/utils/js.js +0 -18
- package/amd/utils/serialization.d.ts +0 -10
- package/amd/utils/serialization.js +0 -135
- package/es6/annotation/decorator_utils.d.ts +0 -16
- package/es6/annotation/decorator_utils.js +0 -114
- package/es6/annotation/inject.d.ts +0 -5
- package/es6/annotation/inject.js +0 -30
- package/es6/annotation/inject_base.d.ts +0 -4
- package/es6/annotation/inject_base.js +0 -17
- package/es6/annotation/injectable.d.ts +0 -2
- package/es6/annotation/injectable.js +0 -38
- package/es6/annotation/lazy_service_identifier.js +0 -2
- package/es6/annotation/multi_inject.d.ts +0 -5
- package/es6/annotation/multi_inject.js +0 -30
- package/es6/annotation/named.d.ts +0 -2
- package/es6/annotation/named.js +0 -32
- package/es6/annotation/optional.d.ts +0 -2
- package/es6/annotation/optional.js +0 -32
- package/es6/annotation/post_construct.d.ts +0 -4
- package/es6/annotation/post_construct.js +0 -31
- package/es6/annotation/pre_destroy.d.ts +0 -4
- package/es6/annotation/pre_destroy.js +0 -31
- package/es6/annotation/property_event_decorator.d.ts +0 -4
- package/es6/annotation/property_event_decorator.js +0 -15
- package/es6/annotation/tagged.d.ts +0 -2
- package/es6/annotation/tagged.js +0 -8
- package/es6/annotation/target_name.d.ts +0 -3
- package/es6/annotation/target_name.js +0 -35
- package/es6/annotation/unmanaged.d.ts +0 -3
- package/es6/annotation/unmanaged.js +0 -35
- package/es6/bindings/binding.d.ts +0 -20
- package/es6/bindings/binding.js +0 -39
- package/es6/bindings/binding_count.d.ts +0 -5
- package/es6/bindings/binding_count.js +0 -9
- package/es6/constants/error_msgs.d.ts +0 -30
- package/es6/constants/error_msgs.js +0 -59
- package/es6/constants/literal_types.d.ts +0 -5
- package/es6/constants/literal_types.js +0 -26
- package/es6/constants/metadata_keys.d.ts +0 -13
- package/es6/constants/metadata_keys.js +0 -26
- package/es6/container/container.d.ts +0 -73
- package/es6/container/container.js +0 -545
- package/es6/container/container_module.d.ts +0 -11
- package/es6/container/container_module.js +0 -18
- package/es6/container/container_snapshot.d.ts +0 -10
- package/es6/container/container_snapshot.js +0 -15
- package/es6/container/lookup.d.ts +0 -17
- package/es6/container/lookup.js +0 -125
- package/es6/container/module_activation_store.d.ts +0 -10
- package/es6/container/module_activation_store.js +0 -49
- package/es6/interfaces/interfaces.d.ts +0 -269
- package/es6/interfaces/interfaces.js +0 -2
- package/es6/inversify.d.ts +0 -24
- package/es6/inversify.js +0 -76
- package/es6/planning/context.d.ts +0 -11
- package/es6/planning/context.js +0 -17
- package/es6/planning/metadata.d.ts +0 -8
- package/es6/planning/metadata.js +0 -42
- package/es6/planning/metadata_reader.d.ts +0 -6
- package/es6/planning/metadata_reader.js +0 -44
- package/es6/planning/plan.d.ts +0 -7
- package/es6/planning/plan.js +0 -10
- package/es6/planning/planner.d.ts +0 -5
- package/es6/planning/planner.js +0 -194
- package/es6/planning/queryable_string.d.ts +0 -10
- package/es6/planning/queryable_string.js +0 -30
- package/es6/planning/reflection_utils.d.ts +0 -5
- package/es6/planning/reflection_utils.js +0 -53
- package/es6/planning/request.d.ts +0 -14
- package/es6/planning/request.js +0 -22
- package/es6/planning/target.js +0 -105
- package/es6/resolution/instantiation.d.ts +0 -3
- package/es6/resolution/instantiation.js +0 -158
- package/es6/resolution/resolver.d.ts +0 -3
- package/es6/resolution/resolver.js +0 -193
- package/es6/scope/scope.d.ts +0 -3
- package/es6/scope/scope.js +0 -57
- package/es6/syntax/binding_in_syntax.d.ts +0 -9
- package/es6/syntax/binding_in_syntax.js +0 -23
- package/es6/syntax/binding_in_when_on_syntax.d.ts +0 -29
- package/es6/syntax/binding_in_when_on_syntax.js +0 -75
- package/es6/syntax/binding_on_syntax.d.ts +0 -8
- package/es6/syntax/binding_on_syntax.js +0 -18
- package/es6/syntax/binding_to_syntax.d.ts +0 -18
- package/es6/syntax/binding_to_syntax.js +0 -110
- package/es6/syntax/binding_when_on_syntax.d.ts +0 -25
- package/es6/syntax/binding_when_on_syntax.js +0 -64
- package/es6/syntax/binding_when_syntax.d.ts +0 -21
- package/es6/syntax/binding_when_syntax.js +0 -84
- package/es6/syntax/constraint_helpers.d.ts +0 -6
- package/es6/syntax/constraint_helpers.js +0 -63
- package/es6/utils/async.d.ts +0 -3
- package/es6/utils/async.js +0 -15
- package/es6/utils/binding_utils.d.ts +0 -4
- package/es6/utils/binding_utils.js +0 -79
- package/es6/utils/clonable.d.ts +0 -3
- package/es6/utils/clonable.js +0 -9
- package/es6/utils/exceptions.d.ts +0 -2
- package/es6/utils/exceptions.js +0 -44
- package/es6/utils/factory_type.d.ts +0 -5
- package/es6/utils/factory_type.js +0 -9
- package/es6/utils/id.d.ts +0 -2
- package/es6/utils/id.js +0 -7
- package/es6/utils/js.d.ts +0 -1
- package/es6/utils/js.js +0 -15
- package/es6/utils/serialization.d.ts +0 -10
- package/es6/utils/serialization.js +0 -132
|
@@ -15,95 +15,63 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
36
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
-
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;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
61
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
36
|
exports.resolve = resolve;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
var binding = bindings[0];
|
|
92
|
-
return _resolveBinding(requestScope, request, binding);
|
|
37
|
+
const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
|
|
38
|
+
const literal_types_1 = require("../constants/literal_types");
|
|
39
|
+
const planner_1 = require("../planning/planner");
|
|
40
|
+
const scope_1 = require("../scope/scope");
|
|
41
|
+
const async_1 = require("../utils/async");
|
|
42
|
+
const binding_utils_1 = require("../utils/binding_utils");
|
|
43
|
+
const exceptions_1 = require("../utils/exceptions");
|
|
44
|
+
const instantiation_1 = require("./instantiation");
|
|
45
|
+
const _resolveRequest = (requestScope) => (request) => {
|
|
46
|
+
request.parentContext.setCurrentRequest(request);
|
|
47
|
+
const bindings = request.bindings;
|
|
48
|
+
const childRequests = request.childRequests;
|
|
49
|
+
const targetIsAnArray = request.target && request.target.isArray();
|
|
50
|
+
const targetParentIsNotAnArray = !request.parentRequest ||
|
|
51
|
+
!request.parentRequest.target ||
|
|
52
|
+
!request.target ||
|
|
53
|
+
!request.parentRequest.target.matchesArray(request.target.serviceIdentifier);
|
|
54
|
+
if (targetIsAnArray && targetParentIsNotAnArray) {
|
|
55
|
+
return childRequests.map((childRequest) => {
|
|
56
|
+
const resolveRequest = _resolveRequest(requestScope);
|
|
57
|
+
return resolveRequest(childRequest);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (request.target.isOptional() && bindings.length === 0) {
|
|
62
|
+
return undefined;
|
|
93
63
|
}
|
|
94
|
-
|
|
64
|
+
const binding = bindings[0];
|
|
65
|
+
return _resolveBinding(requestScope, request, binding);
|
|
66
|
+
}
|
|
95
67
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return (0, exceptions_1.tryAndThrowErrorIfStackOverflow)(
|
|
99
|
-
return factoryDetails.factory.bind(binding)(context);
|
|
100
|
-
}, function () {
|
|
101
|
-
return new Error(ERROR_MSGS.CIRCULAR_DEPENDENCY_IN_FACTORY(factoryDetails.factoryType, context.currentRequest.serviceIdentifier.toString()));
|
|
102
|
-
});
|
|
68
|
+
const _resolveFactoryFromBinding = (binding, context) => {
|
|
69
|
+
const factoryDetails = (0, binding_utils_1.getFactoryDetails)(binding);
|
|
70
|
+
return (0, exceptions_1.tryAndThrowErrorIfStackOverflow)(() => factoryDetails.factory.bind(binding)(context), () => new Error(ERROR_MSGS.CIRCULAR_DEPENDENCY_IN_FACTORY(factoryDetails.factoryType, context.currentRequest.serviceIdentifier.toString())));
|
|
103
71
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
72
|
+
const _getResolvedFromBinding = (requestScope, request, binding) => {
|
|
73
|
+
let result;
|
|
74
|
+
const childRequests = request.childRequests;
|
|
107
75
|
(0, binding_utils_1.ensureFullyBound)(binding);
|
|
108
76
|
switch (binding.type) {
|
|
109
77
|
case literal_types_1.BindingTypeEnum.ConstantValue:
|
|
@@ -121,8 +89,8 @@ var _getResolvedFromBinding = function (requestScope, request, binding) {
|
|
|
121
89
|
}
|
|
122
90
|
return result;
|
|
123
91
|
};
|
|
124
|
-
|
|
125
|
-
|
|
92
|
+
const _resolveInScope = (requestScope, binding, resolveFromBinding) => {
|
|
93
|
+
let result = (0, scope_1.tryGetFromScope)(requestScope, binding);
|
|
126
94
|
if (result !== null) {
|
|
127
95
|
return result;
|
|
128
96
|
}
|
|
@@ -130,13 +98,11 @@ var _resolveInScope = function (requestScope, binding, resolveFromBinding) {
|
|
|
130
98
|
(0, scope_1.saveToScope)(requestScope, binding, result);
|
|
131
99
|
return result;
|
|
132
100
|
};
|
|
133
|
-
|
|
134
|
-
return _resolveInScope(requestScope, binding,
|
|
135
|
-
|
|
101
|
+
const _resolveBinding = (requestScope, request, binding) => {
|
|
102
|
+
return _resolveInScope(requestScope, binding, () => {
|
|
103
|
+
let result = _getResolvedFromBinding(requestScope, request, binding);
|
|
136
104
|
if ((0, async_1.isPromise)(result)) {
|
|
137
|
-
result = result.then(
|
|
138
|
-
return _onActivation(request, binding, resolved);
|
|
139
|
-
});
|
|
105
|
+
result = result.then((resolved) => _onActivation(request, binding, resolved));
|
|
140
106
|
}
|
|
141
107
|
else {
|
|
142
108
|
result = _onActivation(request, binding, result);
|
|
@@ -145,28 +111,28 @@ var _resolveBinding = function (requestScope, request, binding) {
|
|
|
145
111
|
});
|
|
146
112
|
};
|
|
147
113
|
function _onActivation(request, binding, resolved) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
114
|
+
let result = _bindingActivation(request.parentContext, binding, resolved);
|
|
115
|
+
const containersIterator = _getContainersIterator(request.parentContext.container);
|
|
116
|
+
let container;
|
|
117
|
+
let containersIteratorResult = containersIterator.next();
|
|
152
118
|
do {
|
|
153
119
|
container = containersIteratorResult.value;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
120
|
+
const context = request.parentContext;
|
|
121
|
+
const serviceIdentifier = request.serviceIdentifier;
|
|
122
|
+
const activationsIterator = _getContainerActivationsForService(container, serviceIdentifier);
|
|
157
123
|
if ((0, async_1.isPromise)(result)) {
|
|
158
|
-
result = _activateContainerAsync(activationsIterator,
|
|
124
|
+
result = _activateContainerAsync(activationsIterator, context, result);
|
|
159
125
|
}
|
|
160
126
|
else {
|
|
161
|
-
result = _activateContainer(activationsIterator,
|
|
127
|
+
result = _activateContainer(activationsIterator, context, result);
|
|
162
128
|
}
|
|
163
129
|
containersIteratorResult = containersIterator.next();
|
|
164
130
|
} while (containersIteratorResult.done !== true &&
|
|
165
131
|
!(0, planner_1.getBindingDictionary)(container).hasKey(request.serviceIdentifier));
|
|
166
132
|
return result;
|
|
167
133
|
}
|
|
168
|
-
|
|
169
|
-
|
|
134
|
+
const _bindingActivation = (context, binding, previousResult) => {
|
|
135
|
+
let result;
|
|
170
136
|
if (typeof binding.onActivation === 'function') {
|
|
171
137
|
result = binding.onActivation(context, previousResult);
|
|
172
138
|
}
|
|
@@ -175,8 +141,8 @@ var _bindingActivation = function (context, binding, previousResult) {
|
|
|
175
141
|
}
|
|
176
142
|
return result;
|
|
177
143
|
};
|
|
178
|
-
|
|
179
|
-
|
|
144
|
+
const _activateContainer = (activationsIterator, context, result) => {
|
|
145
|
+
let activation = activationsIterator.next();
|
|
180
146
|
while (activation.done !== true) {
|
|
181
147
|
result = activation.value(context, result);
|
|
182
148
|
if ((0, async_1.isPromise)(result)) {
|
|
@@ -186,41 +152,30 @@ var _activateContainer = function (activationsIterator, context, result) {
|
|
|
186
152
|
}
|
|
187
153
|
return result;
|
|
188
154
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return [4, activation.value(context, result)];
|
|
201
|
-
case 3:
|
|
202
|
-
result = _a.sent();
|
|
203
|
-
activation = activationsIterator.next();
|
|
204
|
-
return [3, 2];
|
|
205
|
-
case 4: return [2, result];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}); };
|
|
209
|
-
var _getContainerActivationsForService = function (container, serviceIdentifier) {
|
|
210
|
-
var activations = container._activations;
|
|
155
|
+
const _activateContainerAsync = async (activationsIterator, context, resultPromise) => {
|
|
156
|
+
let result = await resultPromise;
|
|
157
|
+
let activation = activationsIterator.next();
|
|
158
|
+
while (activation.done !== true) {
|
|
159
|
+
result = await activation.value(context, result);
|
|
160
|
+
activation = activationsIterator.next();
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
const _getContainerActivationsForService = (container, serviceIdentifier) => {
|
|
165
|
+
const activations = container._activations;
|
|
211
166
|
return activations.hasKey(serviceIdentifier)
|
|
212
167
|
? activations.get(serviceIdentifier).values()
|
|
213
168
|
: [].values();
|
|
214
169
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
170
|
+
const _getContainersIterator = (container) => {
|
|
171
|
+
const containersStack = [container];
|
|
172
|
+
let parent = container.parent;
|
|
218
173
|
while (parent !== null) {
|
|
219
174
|
containersStack.push(parent);
|
|
220
175
|
parent = parent.parent;
|
|
221
176
|
}
|
|
222
|
-
|
|
223
|
-
|
|
177
|
+
const getNextContainer = () => {
|
|
178
|
+
const nextContainer = containersStack.pop();
|
|
224
179
|
if (nextContainer !== undefined) {
|
|
225
180
|
return { done: false, value: nextContainer };
|
|
226
181
|
}
|
|
@@ -228,12 +183,12 @@ var _getContainersIterator = function (container) {
|
|
|
228
183
|
return { done: true, value: undefined };
|
|
229
184
|
}
|
|
230
185
|
};
|
|
231
|
-
|
|
186
|
+
const containersIterator = {
|
|
232
187
|
next: getNextContainer,
|
|
233
188
|
};
|
|
234
189
|
return containersIterator;
|
|
235
190
|
};
|
|
236
191
|
function resolve(context) {
|
|
237
|
-
|
|
192
|
+
const resolveRequestFunction = _resolveRequest(context.plan.rootRequest.requestScope);
|
|
238
193
|
return resolveRequestFunction(context.plan.rootRequest);
|
|
239
194
|
}
|
package/lib/scope/scope.js
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
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); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
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];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.saveToScope = exports.tryGetFromScope = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
4
|
+
const literal_types_1 = require("../constants/literal_types");
|
|
5
|
+
const async_1 = require("../utils/async");
|
|
6
|
+
const tryGetFromScope = (requestScope, binding) => {
|
|
43
7
|
if (binding.scope === literal_types_1.BindingScopeEnum.Singleton && binding.activated) {
|
|
44
8
|
return binding.cache;
|
|
45
9
|
}
|
|
@@ -50,7 +14,7 @@ var tryGetFromScope = function (requestScope, binding) {
|
|
|
50
14
|
return null;
|
|
51
15
|
};
|
|
52
16
|
exports.tryGetFromScope = tryGetFromScope;
|
|
53
|
-
|
|
17
|
+
const saveToScope = (requestScope, binding, result) => {
|
|
54
18
|
if (binding.scope === literal_types_1.BindingScopeEnum.Singleton) {
|
|
55
19
|
_saveToSingletonScope(binding, result);
|
|
56
20
|
}
|
|
@@ -59,35 +23,26 @@ var saveToScope = function (requestScope, binding, result) {
|
|
|
59
23
|
}
|
|
60
24
|
};
|
|
61
25
|
exports.saveToScope = saveToScope;
|
|
62
|
-
|
|
26
|
+
const _saveToRequestScope = (requestScope, binding, result) => {
|
|
63
27
|
if (!requestScope.has(binding.id)) {
|
|
64
28
|
requestScope.set(binding.id, result);
|
|
65
29
|
}
|
|
66
30
|
};
|
|
67
|
-
|
|
31
|
+
const _saveToSingletonScope = (binding, result) => {
|
|
68
32
|
binding.cache = result;
|
|
69
33
|
binding.activated = true;
|
|
70
34
|
if ((0, async_1.isPromise)(result)) {
|
|
71
35
|
void _saveAsyncResultToSingletonScope(binding, result);
|
|
72
36
|
}
|
|
73
37
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case 2:
|
|
86
|
-
ex_1 = _a.sent();
|
|
87
|
-
binding.cache = null;
|
|
88
|
-
binding.activated = false;
|
|
89
|
-
throw ex_1;
|
|
90
|
-
case 3: return [2];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}); };
|
|
38
|
+
const _saveAsyncResultToSingletonScope = async (binding, asyncResult) => {
|
|
39
|
+
try {
|
|
40
|
+
const result = await asyncResult;
|
|
41
|
+
binding.cache = result;
|
|
42
|
+
}
|
|
43
|
+
catch (ex) {
|
|
44
|
+
binding.cache = null;
|
|
45
|
+
binding.activated = false;
|
|
46
|
+
throw ex;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingInSyntax = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const literal_types_1 = require("../constants/literal_types");
|
|
5
|
+
const binding_when_on_syntax_1 = require("./binding_when_on_syntax");
|
|
6
|
+
class BindingInSyntax {
|
|
7
|
+
_binding;
|
|
8
|
+
constructor(binding) {
|
|
8
9
|
this._binding = binding;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
inRequestScope() {
|
|
11
12
|
this._binding.scope = literal_types_1.BindingScopeEnum.Request;
|
|
12
13
|
return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
|
|
13
|
-
}
|
|
14
|
-
|
|
14
|
+
}
|
|
15
|
+
inSingletonScope() {
|
|
15
16
|
this._binding.scope = literal_types_1.BindingScopeEnum.Singleton;
|
|
16
17
|
return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
|
|
17
|
-
}
|
|
18
|
-
|
|
18
|
+
}
|
|
19
|
+
inTransientScope() {
|
|
19
20
|
this._binding.scope = literal_types_1.BindingScopeEnum.Transient;
|
|
20
21
|
return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
24
|
exports.BindingInSyntax = BindingInSyntax;
|
|
@@ -1,76 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingInWhenOnSyntax = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const binding_in_syntax_1 = require("./binding_in_syntax");
|
|
5
|
+
const binding_on_syntax_1 = require("./binding_on_syntax");
|
|
6
|
+
const binding_when_syntax_1 = require("./binding_when_syntax");
|
|
7
|
+
class BindingInWhenOnSyntax {
|
|
8
|
+
_bindingInSyntax;
|
|
9
|
+
_bindingWhenSyntax;
|
|
10
|
+
_bindingOnSyntax;
|
|
11
|
+
_binding;
|
|
12
|
+
constructor(binding) {
|
|
9
13
|
this._binding = binding;
|
|
10
14
|
this._bindingWhenSyntax = new binding_when_syntax_1.BindingWhenSyntax(this._binding);
|
|
11
15
|
this._bindingOnSyntax = new binding_on_syntax_1.BindingOnSyntax(this._binding);
|
|
12
16
|
this._bindingInSyntax = new binding_in_syntax_1.BindingInSyntax(binding);
|
|
13
17
|
}
|
|
14
|
-
|
|
18
|
+
inRequestScope() {
|
|
15
19
|
return this._bindingInSyntax.inRequestScope();
|
|
16
|
-
}
|
|
17
|
-
|
|
20
|
+
}
|
|
21
|
+
inSingletonScope() {
|
|
18
22
|
return this._bindingInSyntax.inSingletonScope();
|
|
19
|
-
}
|
|
20
|
-
|
|
23
|
+
}
|
|
24
|
+
inTransientScope() {
|
|
21
25
|
return this._bindingInSyntax.inTransientScope();
|
|
22
|
-
}
|
|
23
|
-
|
|
26
|
+
}
|
|
27
|
+
when(constraint) {
|
|
24
28
|
return this._bindingWhenSyntax.when(constraint);
|
|
25
|
-
}
|
|
26
|
-
|
|
29
|
+
}
|
|
30
|
+
whenTargetNamed(name) {
|
|
27
31
|
return this._bindingWhenSyntax.whenTargetNamed(name);
|
|
28
|
-
}
|
|
29
|
-
|
|
32
|
+
}
|
|
33
|
+
whenTargetIsDefault() {
|
|
30
34
|
return this._bindingWhenSyntax.whenTargetIsDefault();
|
|
31
|
-
}
|
|
32
|
-
|
|
35
|
+
}
|
|
36
|
+
whenTargetTagged(tag, value) {
|
|
33
37
|
return this._bindingWhenSyntax.whenTargetTagged(tag, value);
|
|
34
|
-
}
|
|
35
|
-
|
|
38
|
+
}
|
|
39
|
+
whenInjectedInto(parent) {
|
|
36
40
|
return this._bindingWhenSyntax.whenInjectedInto(parent);
|
|
37
|
-
}
|
|
38
|
-
|
|
41
|
+
}
|
|
42
|
+
whenParentNamed(name) {
|
|
39
43
|
return this._bindingWhenSyntax.whenParentNamed(name);
|
|
40
|
-
}
|
|
41
|
-
|
|
44
|
+
}
|
|
45
|
+
whenParentTagged(tag, value) {
|
|
42
46
|
return this._bindingWhenSyntax.whenParentTagged(tag, value);
|
|
43
|
-
}
|
|
44
|
-
|
|
47
|
+
}
|
|
48
|
+
whenAnyAncestorIs(ancestor) {
|
|
45
49
|
return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor);
|
|
46
|
-
}
|
|
47
|
-
|
|
50
|
+
}
|
|
51
|
+
whenNoAncestorIs(ancestor) {
|
|
48
52
|
return this._bindingWhenSyntax.whenNoAncestorIs(ancestor);
|
|
49
|
-
}
|
|
50
|
-
|
|
53
|
+
}
|
|
54
|
+
whenAnyAncestorNamed(name) {
|
|
51
55
|
return this._bindingWhenSyntax.whenAnyAncestorNamed(name);
|
|
52
|
-
}
|
|
53
|
-
|
|
56
|
+
}
|
|
57
|
+
whenAnyAncestorTagged(tag, value) {
|
|
54
58
|
return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value);
|
|
55
|
-
}
|
|
56
|
-
|
|
59
|
+
}
|
|
60
|
+
whenNoAncestorNamed(name) {
|
|
57
61
|
return this._bindingWhenSyntax.whenNoAncestorNamed(name);
|
|
58
|
-
}
|
|
59
|
-
|
|
62
|
+
}
|
|
63
|
+
whenNoAncestorTagged(tag, value) {
|
|
60
64
|
return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value);
|
|
61
|
-
}
|
|
62
|
-
|
|
65
|
+
}
|
|
66
|
+
whenAnyAncestorMatches(constraint) {
|
|
63
67
|
return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint);
|
|
64
|
-
}
|
|
65
|
-
|
|
68
|
+
}
|
|
69
|
+
whenNoAncestorMatches(constraint) {
|
|
66
70
|
return this._bindingWhenSyntax.whenNoAncestorMatches(constraint);
|
|
67
|
-
}
|
|
68
|
-
|
|
71
|
+
}
|
|
72
|
+
onActivation(handler) {
|
|
69
73
|
return this._bindingOnSyntax.onActivation(handler);
|
|
70
|
-
}
|
|
71
|
-
|
|
74
|
+
}
|
|
75
|
+
onDeactivation(handler) {
|
|
72
76
|
return this._bindingOnSyntax.onDeactivation(handler);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
76
79
|
exports.BindingInWhenOnSyntax = BindingInWhenOnSyntax;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindingOnSyntax = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const binding_when_syntax_1 = require("./binding_when_syntax");
|
|
5
|
+
class BindingOnSyntax {
|
|
6
|
+
_binding;
|
|
7
|
+
constructor(binding) {
|
|
7
8
|
this._binding = binding;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
onActivation(handler) {
|
|
10
11
|
this._binding.onActivation = handler;
|
|
11
12
|
return new binding_when_syntax_1.BindingWhenSyntax(this._binding);
|
|
12
|
-
}
|
|
13
|
-
|
|
13
|
+
}
|
|
14
|
+
onDeactivation(handler) {
|
|
14
15
|
this._binding.onDeactivation = handler;
|
|
15
16
|
return new binding_when_syntax_1.BindingWhenSyntax(this._binding);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
19
|
exports.BindingOnSyntax = BindingOnSyntax;
|