inversify 6.0.3 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +14 -14
- package/amd/annotation/decorator_utils.js +3 -1
- package/amd/annotation/inject_base.js +1 -1
- package/amd/annotation/lazy_service_identifier.js +0 -11
- package/amd/bindings/binding.js +3 -2
- package/amd/bindings/binding_count.js +6 -5
- package/amd/constants/error_msgs.js +18 -18
- package/amd/constants/literal_types.js +3 -3
- package/amd/container/container.js +73 -34
- package/amd/container/lookup.js +15 -14
- package/amd/container/module_activation_store.js +8 -10
- package/amd/interfaces/interfaces.js +0 -5
- package/amd/inversify.js +3 -5
- package/amd/planning/metadata_reader.js +5 -3
- package/amd/planning/planner.js +31 -13
- package/amd/planning/queryable_string.js +5 -2
- package/amd/planning/reflection_utils.js +6 -112
- package/amd/planning/request.js +2 -4
- package/amd/planning/target.js +9 -3
- package/amd/resolution/instantiation.js +10 -5
- package/amd/resolution/resolver.js +19 -10
- package/amd/scope/scope.js +1 -1
- package/amd/syntax/binding_to_syntax.js +14 -7
- package/amd/syntax/binding_when_syntax.js +13 -8
- package/amd/syntax/constraint_helpers.js +4 -3
- package/amd/utils/async.js +3 -2
- package/amd/utils/binding_utils.js +8 -3
- package/amd/utils/clonable.js +4 -4
- package/amd/utils/exceptions.js +1 -1
- package/amd/utils/serialization.js +11 -8
- package/es/annotation/decorator_utils.js +3 -1
- package/es/annotation/inject_base.js +1 -1
- package/es/annotation/lazy_service_identifier.js +1 -10
- package/es/annotation/target_name.js +3 -3
- package/es/bindings/binding.js +3 -2
- package/es/bindings/binding_count.js +6 -5
- package/es/constants/error_msgs.js +17 -17
- package/es/constants/literal_types.js +3 -3
- package/es/container/container.js +74 -35
- package/es/container/lookup.js +15 -14
- package/es/container/module_activation_store.js +8 -10
- package/es/interfaces/interfaces.js +1 -5
- package/es/inversify.js +4 -6
- package/es/planning/metadata_reader.js +5 -3
- package/es/planning/planner.js +34 -16
- package/es/planning/queryable_string.js +5 -2
- package/es/planning/reflection_utils.js +6 -114
- package/es/planning/request.js +2 -4
- package/es/planning/target.js +9 -3
- package/es/resolution/instantiation.js +11 -6
- package/es/resolution/resolver.js +20 -11
- package/es/scope/scope.js +1 -1
- package/es/syntax/binding_to_syntax.js +18 -11
- package/es/syntax/binding_when_syntax.js +14 -9
- package/es/syntax/constraint_helpers.js +5 -4
- package/es/utils/async.js +3 -2
- package/es/utils/binding_utils.js +8 -3
- package/es/utils/clonable.js +4 -4
- package/es/utils/exceptions.js +1 -1
- package/es/utils/serialization.js +12 -9
- package/es6/annotation/decorator_utils.js +5 -3
- package/es6/annotation/inject_base.js +1 -1
- package/es6/annotation/lazy_service_identifier.js +0 -10
- package/es6/bindings/binding.js +3 -2
- package/es6/bindings/binding_count.js +6 -5
- package/es6/constants/error_msgs.js +5 -9
- package/es6/constants/literal_types.js +3 -3
- package/es6/container/container.js +59 -42
- package/es6/container/lookup.js +15 -14
- package/es6/container/module_activation_store.js +8 -10
- package/es6/interfaces/interfaces.js +0 -5
- package/es6/inversify.js +3 -7
- package/es6/planning/metadata_reader.js +5 -3
- package/es6/planning/planner.js +31 -13
- package/es6/planning/queryable_string.js +5 -2
- package/es6/planning/reflection_utils.js +4 -110
- package/es6/planning/request.js +2 -4
- package/es6/planning/target.js +3 -1
- package/es6/resolution/instantiation.js +9 -5
- package/es6/resolution/resolver.js +11 -8
- package/es6/scope/scope.js +1 -1
- package/es6/syntax/binding_to_syntax.js +5 -4
- package/es6/syntax/binding_when_syntax.js +13 -8
- package/es6/syntax/constraint_helpers.js +4 -3
- package/es6/utils/async.js +3 -2
- package/es6/utils/binding_utils.js +10 -3
- package/es6/utils/clonable.js +4 -4
- package/es6/utils/exceptions.js +1 -1
- package/es6/utils/serialization.js +11 -8
- package/lib/annotation/decorator_utils.d.ts +2 -2
- package/lib/annotation/decorator_utils.js +3 -1
- package/lib/annotation/inject.d.ts +4 -1
- package/lib/annotation/inject_base.d.ts +3 -2
- package/lib/annotation/inject_base.js +1 -1
- package/lib/annotation/lazy_service_identifier.d.ts +1 -5
- package/lib/annotation/lazy_service_identifier.js +0 -11
- package/lib/annotation/multi_inject.d.ts +4 -1
- package/lib/annotation/tagged.d.ts +1 -1
- package/lib/annotation/target_name.d.ts +1 -1
- package/lib/bindings/binding.js +3 -2
- package/lib/bindings/binding_count.d.ts +5 -5
- package/lib/bindings/binding_count.js +6 -5
- package/lib/constants/error_msgs.d.ts +18 -20
- package/lib/constants/error_msgs.js +18 -18
- package/lib/constants/literal_types.js +3 -3
- package/lib/constants/metadata_keys.d.ts +12 -12
- package/lib/container/container.d.ts +2 -2
- package/lib/container/container.js +73 -34
- package/lib/container/lookup.d.ts +2 -1
- package/lib/container/lookup.js +15 -14
- package/lib/container/module_activation_store.d.ts +1 -1
- package/lib/container/module_activation_store.js +8 -10
- package/lib/interfaces/interfaces.d.ts +14 -29
- package/lib/interfaces/interfaces.js +0 -5
- package/lib/inversify.d.ts +5 -6
- package/lib/inversify.js +3 -7
- package/lib/planning/metadata_reader.js +5 -3
- package/lib/planning/planner.js +31 -13
- package/lib/planning/queryable_string.d.ts +2 -3
- package/lib/planning/queryable_string.js +5 -2
- package/lib/planning/reflection_utils.js +6 -114
- package/lib/planning/request.d.ts +2 -2
- package/lib/planning/request.js +2 -4
- package/lib/planning/target.d.ts +1 -1
- package/lib/planning/target.js +9 -3
- package/lib/resolution/instantiation.js +10 -5
- package/lib/resolution/resolver.js +19 -10
- package/lib/scope/scope.js +1 -1
- package/lib/syntax/binding_in_syntax.d.ts +1 -1
- package/lib/syntax/binding_in_when_on_syntax.d.ts +7 -7
- package/lib/syntax/binding_on_syntax.d.ts +1 -1
- package/lib/syntax/binding_to_syntax.d.ts +4 -4
- package/lib/syntax/binding_to_syntax.js +14 -7
- package/lib/syntax/binding_when_on_syntax.d.ts +6 -6
- package/lib/syntax/binding_when_syntax.d.ts +4 -4
- package/lib/syntax/binding_when_syntax.js +13 -8
- package/lib/syntax/constraint_helpers.d.ts +2 -2
- package/lib/syntax/constraint_helpers.js +4 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/async.js +3 -2
- package/lib/utils/binding_utils.js +8 -3
- package/lib/utils/clonable.js +4 -4
- package/lib/utils/exceptions.js +1 -1
- package/lib/utils/serialization.d.ts +3 -3
- package/lib/utils/serialization.js +11 -8
- package/package.json +19 -5
- package/.nyc_output/c29b2307-4e95-47d0-b220-9efcfa7ee49f.json +0 -1
- package/.nyc_output/processinfo/c29b2307-4e95-47d0-b220-9efcfa7ee49f.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
|
@@ -98,7 +98,7 @@ var Container = (function () {
|
|
|
98
98
|
function Container(containerOptions) {
|
|
99
99
|
var options = containerOptions || {};
|
|
100
100
|
if (typeof options !== 'object') {
|
|
101
|
-
throw new Error(
|
|
101
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
|
|
102
102
|
}
|
|
103
103
|
if (options.defaultScope === undefined) {
|
|
104
104
|
options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
|
|
@@ -106,24 +106,24 @@ var Container = (function () {
|
|
|
106
106
|
else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
|
|
107
107
|
options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
|
|
108
108
|
options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
|
|
109
|
-
throw new Error(
|
|
109
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
|
|
110
110
|
}
|
|
111
111
|
if (options.autoBindInjectable === undefined) {
|
|
112
112
|
options.autoBindInjectable = false;
|
|
113
113
|
}
|
|
114
114
|
else if (typeof options.autoBindInjectable !== 'boolean') {
|
|
115
|
-
throw new Error(
|
|
115
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
|
|
116
116
|
}
|
|
117
117
|
if (options.skipBaseClassChecks === undefined) {
|
|
118
118
|
options.skipBaseClassChecks = false;
|
|
119
119
|
}
|
|
120
120
|
else if (typeof options.skipBaseClassChecks !== 'boolean') {
|
|
121
|
-
throw new Error(
|
|
121
|
+
throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
|
|
122
122
|
}
|
|
123
123
|
this.options = {
|
|
124
124
|
autoBindInjectable: options.autoBindInjectable,
|
|
125
125
|
defaultScope: options.defaultScope,
|
|
126
|
-
skipBaseClassChecks: options.skipBaseClassChecks
|
|
126
|
+
skipBaseClassChecks: options.skipBaseClassChecks,
|
|
127
127
|
};
|
|
128
128
|
this.id = (0, id_1.id)();
|
|
129
129
|
this._bindingDictionary = new lookup_1.Lookup();
|
|
@@ -141,7 +141,12 @@ var Container = (function () {
|
|
|
141
141
|
containers[_i - 2] = arguments[_i];
|
|
142
142
|
}
|
|
143
143
|
var container = new Container();
|
|
144
|
-
var targetContainers = __spreadArray([
|
|
144
|
+
var targetContainers = __spreadArray([
|
|
145
|
+
container1,
|
|
146
|
+
container2
|
|
147
|
+
], containers, true).map(function (targetContainer) {
|
|
148
|
+
return (0, planner_1.getBindingDictionary)(targetContainer);
|
|
149
|
+
});
|
|
145
150
|
var bindingDictionary = (0, planner_1.getBindingDictionary)(container);
|
|
146
151
|
function copyDictionary(origin, destination) {
|
|
147
152
|
origin.traverse(function (_key, value) {
|
|
@@ -367,7 +372,9 @@ var Container = (function () {
|
|
|
367
372
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
368
373
|
middlewares[_i] = arguments[_i];
|
|
369
374
|
}
|
|
370
|
-
var initial =
|
|
375
|
+
var initial = this._middleware
|
|
376
|
+
? this._middleware
|
|
377
|
+
: this._planAndResolve();
|
|
371
378
|
this._middleware = middlewares.reduce(function (prev, curr) { return curr(prev); }, initial);
|
|
372
379
|
};
|
|
373
380
|
Container.prototype.applyCustomMetadataReader = function (metadataReader) {
|
|
@@ -403,29 +410,47 @@ var Container = (function () {
|
|
|
403
410
|
return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
404
411
|
};
|
|
405
412
|
Container.prototype.getNamedAsync = function (serviceIdentifier, named) {
|
|
406
|
-
return this
|
|
413
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
414
|
+
return __generator(this, function (_a) {
|
|
415
|
+
return [2, this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
|
|
416
|
+
});
|
|
417
|
+
});
|
|
407
418
|
};
|
|
408
419
|
Container.prototype.getAll = function (serviceIdentifier) {
|
|
409
420
|
var getArgs = this._getAllArgs(serviceIdentifier);
|
|
410
421
|
return this._getButThrowIfAsync(getArgs);
|
|
411
422
|
};
|
|
412
423
|
Container.prototype.getAllAsync = function (serviceIdentifier) {
|
|
413
|
-
|
|
414
|
-
|
|
424
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
425
|
+
var getArgs;
|
|
426
|
+
return __generator(this, function (_a) {
|
|
427
|
+
getArgs = this._getAllArgs(serviceIdentifier);
|
|
428
|
+
return [2, this._getAll(getArgs)];
|
|
429
|
+
});
|
|
430
|
+
});
|
|
415
431
|
};
|
|
416
432
|
Container.prototype.getAllTagged = function (serviceIdentifier, key, value) {
|
|
417
433
|
var getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
418
434
|
return this._getButThrowIfAsync(getArgs);
|
|
419
435
|
};
|
|
420
436
|
Container.prototype.getAllTaggedAsync = function (serviceIdentifier, key, value) {
|
|
421
|
-
|
|
422
|
-
|
|
437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
+
var getArgs;
|
|
439
|
+
return __generator(this, function (_a) {
|
|
440
|
+
getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
|
|
441
|
+
return [2, this._getAll(getArgs)];
|
|
442
|
+
});
|
|
443
|
+
});
|
|
423
444
|
};
|
|
424
445
|
Container.prototype.getAllNamed = function (serviceIdentifier, named) {
|
|
425
446
|
return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
|
|
426
447
|
};
|
|
427
448
|
Container.prototype.getAllNamedAsync = function (serviceIdentifier, named) {
|
|
428
|
-
return this
|
|
449
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
450
|
+
return __generator(this, function (_a) {
|
|
451
|
+
return [2, this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named)];
|
|
452
|
+
});
|
|
453
|
+
});
|
|
429
454
|
};
|
|
430
455
|
Container.prototype.resolve = function (constructorFunction) {
|
|
431
456
|
var isBound = this.isBound(constructorFunction);
|
|
@@ -460,7 +485,11 @@ var Container = (function () {
|
|
|
460
485
|
if (this._deactivations.hasKey(binding.serviceIdentifier)) {
|
|
461
486
|
var result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
|
|
462
487
|
if ((0, async_1.isPromise)(result)) {
|
|
463
|
-
return this._handleDeactivationError(result.then(function () { return _this
|
|
488
|
+
return this._handleDeactivationError(result.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
489
|
+
return __generator(this, function (_a) {
|
|
490
|
+
return [2, this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)];
|
|
491
|
+
});
|
|
492
|
+
}); }), constructor);
|
|
464
493
|
}
|
|
465
494
|
}
|
|
466
495
|
var propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
|
|
@@ -499,12 +528,12 @@ var Container = (function () {
|
|
|
499
528
|
Container.prototype._deactivateContainer = function (instance, deactivationsIterator) {
|
|
500
529
|
var _this = this;
|
|
501
530
|
var deactivation = deactivationsIterator.next();
|
|
502
|
-
while (deactivation.value) {
|
|
531
|
+
while (typeof deactivation.value === 'function') {
|
|
503
532
|
var result = deactivation.value(instance);
|
|
504
533
|
if ((0, async_1.isPromise)(result)) {
|
|
505
|
-
return result.then(function () {
|
|
506
|
-
return
|
|
507
|
-
});
|
|
534
|
+
return result.then(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
535
|
+
return [2, this._deactivateContainerAsync(instance, deactivationsIterator)];
|
|
536
|
+
}); }); });
|
|
508
537
|
}
|
|
509
538
|
deactivation = deactivationsIterator.next();
|
|
510
539
|
}
|
|
@@ -518,7 +547,7 @@ var Container = (function () {
|
|
|
518
547
|
deactivation = deactivationsIterator.next();
|
|
519
548
|
_a.label = 1;
|
|
520
549
|
case 1:
|
|
521
|
-
if (!deactivation.value) return [3, 3];
|
|
550
|
+
if (!(typeof deactivation.value === 'function')) return [3, 3];
|
|
522
551
|
return [4, deactivation.value(instance)];
|
|
523
552
|
case 2:
|
|
524
553
|
_a.sent();
|
|
@@ -541,15 +570,15 @@ var Container = (function () {
|
|
|
541
570
|
return bindingToSyntax;
|
|
542
571
|
};
|
|
543
572
|
};
|
|
544
|
-
var getUnbindFunction = function () {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
};
|
|
548
|
-
};
|
|
573
|
+
var getUnbindFunction = function () { return function (serviceIdentifier) {
|
|
574
|
+
_this.unbind(serviceIdentifier);
|
|
575
|
+
}; };
|
|
549
576
|
var getUnbindAsyncFunction = function () {
|
|
550
|
-
return function (serviceIdentifier) {
|
|
551
|
-
return
|
|
552
|
-
|
|
577
|
+
return function (serviceIdentifier) { return __awaiter(_this, void 0, void 0, function () {
|
|
578
|
+
return __generator(this, function (_a) {
|
|
579
|
+
return [2, this.unbindAsync(serviceIdentifier)];
|
|
580
|
+
});
|
|
581
|
+
}); };
|
|
553
582
|
};
|
|
554
583
|
var getIsboundFunction = function () {
|
|
555
584
|
return function (serviceIdentifier) {
|
|
@@ -581,12 +610,16 @@ var Container = (function () {
|
|
|
581
610
|
onActivationFunction: getOnActivationFunction(mId),
|
|
582
611
|
onDeactivationFunction: getOnDeactivationFunction(mId),
|
|
583
612
|
rebindFunction: getRebindFunction(mId),
|
|
613
|
+
unbindAsyncFunction: getUnbindAsyncFunction(),
|
|
584
614
|
unbindFunction: getUnbindFunction(),
|
|
585
|
-
unbindAsyncFunction: getUnbindAsyncFunction()
|
|
586
615
|
}); };
|
|
587
616
|
};
|
|
588
617
|
Container.prototype._getAll = function (getArgs) {
|
|
589
|
-
return
|
|
618
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
619
|
+
return __generator(this, function (_a) {
|
|
620
|
+
return [2, Promise.all(this._get(getArgs))];
|
|
621
|
+
});
|
|
622
|
+
});
|
|
590
623
|
};
|
|
591
624
|
Container.prototype._get = function (getArgs) {
|
|
592
625
|
var planAndResolveArgs = __assign(__assign({}, getArgs), { contextInterceptor: function (context) { return context; }, targetType: literal_types_1.TargetTypeEnum.Variable });
|
|
@@ -618,8 +651,8 @@ var Container = (function () {
|
|
|
618
651
|
var getNotAllArgs = {
|
|
619
652
|
avoidConstraints: false,
|
|
620
653
|
isMultiInject: isMultiInject,
|
|
621
|
-
serviceIdentifier: serviceIdentifier,
|
|
622
654
|
key: key,
|
|
655
|
+
serviceIdentifier: serviceIdentifier,
|
|
623
656
|
value: value,
|
|
624
657
|
};
|
|
625
658
|
return getNotAllArgs;
|
|
@@ -639,7 +672,9 @@ var Container = (function () {
|
|
|
639
672
|
return;
|
|
640
673
|
}
|
|
641
674
|
if ((0, async_1.isPromise)(binding.cache)) {
|
|
642
|
-
return binding.cache.then(function (resolved) {
|
|
675
|
+
return binding.cache.then(function (resolved) {
|
|
676
|
+
return _this._deactivate(binding, resolved);
|
|
677
|
+
});
|
|
643
678
|
}
|
|
644
679
|
return this._deactivate(binding, binding.cache);
|
|
645
680
|
};
|
|
@@ -657,7 +692,9 @@ var Container = (function () {
|
|
|
657
692
|
var _this = this;
|
|
658
693
|
return __generator(this, function (_a) {
|
|
659
694
|
switch (_a.label) {
|
|
660
|
-
case 0: return [4, Promise.all(bindings.map(function (b) { return _this
|
|
695
|
+
case 0: return [4, Promise.all(bindings.map(function (b) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
696
|
+
return [2, this._deactivateIfSingleton(b)];
|
|
697
|
+
}); }); }))];
|
|
661
698
|
case 1:
|
|
662
699
|
_a.sent();
|
|
663
700
|
return [2];
|
|
@@ -696,7 +733,7 @@ var Container = (function () {
|
|
|
696
733
|
try {
|
|
697
734
|
this._bindingDictionary.remove(serviceIdentifier);
|
|
698
735
|
}
|
|
699
|
-
catch (
|
|
736
|
+
catch (_e) {
|
|
700
737
|
throw new Error("".concat(ERROR_MSGS.CANNOT_UNBIND, " ").concat((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)));
|
|
701
738
|
}
|
|
702
739
|
};
|
|
@@ -705,7 +742,9 @@ var Container = (function () {
|
|
|
705
742
|
if (typeof binding.onDeactivation === 'function') {
|
|
706
743
|
var result = binding.onDeactivation(instance);
|
|
707
744
|
if ((0, async_1.isPromise)(result)) {
|
|
708
|
-
return result.then(function () {
|
|
745
|
+
return result.then(function () {
|
|
746
|
+
return _this._preDestroy(constructor, instance);
|
|
747
|
+
});
|
|
709
748
|
}
|
|
710
749
|
}
|
|
711
750
|
return this._preDestroy(constructor, instance);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { interfaces } from '../interfaces/interfaces';
|
|
2
2
|
declare class Lookup<T> implements interfaces.Lookup<T> {
|
|
3
|
-
private _map;
|
|
3
|
+
private readonly _map;
|
|
4
4
|
constructor();
|
|
5
5
|
getMap(): Map<interfaces.ServiceIdentifier<unknown>, T[]>;
|
|
6
6
|
add(serviceIdentifier: interfaces.ServiceIdentifier, value: T): void;
|
|
@@ -11,6 +11,7 @@ declare class Lookup<T> implements interfaces.Lookup<T> {
|
|
|
11
11
|
hasKey(serviceIdentifier: interfaces.ServiceIdentifier): boolean;
|
|
12
12
|
clone(): interfaces.Lookup<T>;
|
|
13
13
|
traverse(func: (key: interfaces.ServiceIdentifier, value: T[]) => void): void;
|
|
14
|
+
private _checkNonNulish;
|
|
14
15
|
private _setValue;
|
|
15
16
|
}
|
|
16
17
|
export { Lookup };
|
package/lib/container/lookup.js
CHANGED
|
@@ -34,9 +34,7 @@ var Lookup = (function () {
|
|
|
34
34
|
return this._map;
|
|
35
35
|
};
|
|
36
36
|
Lookup.prototype.add = function (serviceIdentifier, value) {
|
|
37
|
-
|
|
38
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
39
|
-
}
|
|
37
|
+
this._checkNonNulish(serviceIdentifier);
|
|
40
38
|
if (value === null || value === undefined) {
|
|
41
39
|
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
42
40
|
}
|
|
@@ -49,9 +47,7 @@ var Lookup = (function () {
|
|
|
49
47
|
}
|
|
50
48
|
};
|
|
51
49
|
Lookup.prototype.get = function (serviceIdentifier) {
|
|
52
|
-
|
|
53
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
54
|
-
}
|
|
50
|
+
this._checkNonNulish(serviceIdentifier);
|
|
55
51
|
var entry = this._map.get(serviceIdentifier);
|
|
56
52
|
if (entry !== undefined) {
|
|
57
53
|
return entry;
|
|
@@ -61,9 +57,7 @@ var Lookup = (function () {
|
|
|
61
57
|
}
|
|
62
58
|
};
|
|
63
59
|
Lookup.prototype.remove = function (serviceIdentifier) {
|
|
64
|
-
|
|
65
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
66
|
-
}
|
|
60
|
+
this._checkNonNulish(serviceIdentifier);
|
|
67
61
|
if (!this._map.delete(serviceIdentifier)) {
|
|
68
62
|
throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
|
|
69
63
|
}
|
|
@@ -71,7 +65,9 @@ var Lookup = (function () {
|
|
|
71
65
|
Lookup.prototype.removeIntersection = function (lookup) {
|
|
72
66
|
var _this = this;
|
|
73
67
|
this.traverse(function (serviceIdentifier, value) {
|
|
74
|
-
var lookupActivations = lookup.hasKey(serviceIdentifier)
|
|
68
|
+
var lookupActivations = lookup.hasKey(serviceIdentifier)
|
|
69
|
+
? lookup.get(serviceIdentifier)
|
|
70
|
+
: undefined;
|
|
75
71
|
if (lookupActivations !== undefined) {
|
|
76
72
|
var filteredValues = value.filter(function (lookupValue) {
|
|
77
73
|
return !lookupActivations.some(function (moduleActivation) { return lookupValue === moduleActivation; });
|
|
@@ -100,15 +96,15 @@ var Lookup = (function () {
|
|
|
100
96
|
return removals;
|
|
101
97
|
};
|
|
102
98
|
Lookup.prototype.hasKey = function (serviceIdentifier) {
|
|
103
|
-
|
|
104
|
-
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
105
|
-
}
|
|
99
|
+
this._checkNonNulish(serviceIdentifier);
|
|
106
100
|
return this._map.has(serviceIdentifier);
|
|
107
101
|
};
|
|
108
102
|
Lookup.prototype.clone = function () {
|
|
109
103
|
var copy = new Lookup();
|
|
110
104
|
this._map.forEach(function (value, key) {
|
|
111
|
-
value.forEach(function (b) {
|
|
105
|
+
value.forEach(function (b) {
|
|
106
|
+
copy.add(key, (0, clonable_1.isClonable)(b) ? b.clone() : b);
|
|
107
|
+
});
|
|
112
108
|
});
|
|
113
109
|
return copy;
|
|
114
110
|
};
|
|
@@ -117,6 +113,11 @@ var Lookup = (function () {
|
|
|
117
113
|
func(key, value);
|
|
118
114
|
});
|
|
119
115
|
};
|
|
116
|
+
Lookup.prototype._checkNonNulish = function (value) {
|
|
117
|
+
if (value == null) {
|
|
118
|
+
throw new Error(ERROR_MSGS.NULL_ARGUMENT);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
120
121
|
Lookup.prototype._setValue = function (serviceIdentifier, value) {
|
|
121
122
|
if (value.length > 0) {
|
|
122
123
|
this._map.set(serviceIdentifier, value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { interfaces } from '../interfaces/interfaces';
|
|
2
2
|
export declare class ModuleActivationStore implements interfaces.ModuleActivationStore {
|
|
3
|
-
private _map;
|
|
3
|
+
private readonly _map;
|
|
4
4
|
remove(moduleId: number): interfaces.ModuleActivationHandlers;
|
|
5
5
|
addDeactivation(moduleId: number, serviceIdentifier: interfaces.ServiceIdentifier<unknown>, onDeactivation: interfaces.BindingDeactivation<unknown>): void;
|
|
6
6
|
addActivation(moduleId: number, serviceIdentifier: interfaces.ServiceIdentifier<unknown>, onActivation: interfaces.BindingActivation<unknown>): void;
|
|
@@ -7,20 +7,18 @@ var ModuleActivationStore = (function () {
|
|
|
7
7
|
this._map = new Map();
|
|
8
8
|
}
|
|
9
9
|
ModuleActivationStore.prototype.remove = function (moduleId) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
return handlers;
|
|
10
|
+
var handlers = this._map.get(moduleId);
|
|
11
|
+
if (handlers === undefined) {
|
|
12
|
+
return this._getEmptyHandlersStore();
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
this._map.delete(moduleId);
|
|
15
|
+
return handlers;
|
|
16
16
|
};
|
|
17
17
|
ModuleActivationStore.prototype.addDeactivation = function (moduleId, serviceIdentifier, onDeactivation) {
|
|
18
|
-
this._getModuleActivationHandlers(moduleId)
|
|
19
|
-
.onDeactivations.add(serviceIdentifier, onDeactivation);
|
|
18
|
+
this._getModuleActivationHandlers(moduleId).onDeactivations.add(serviceIdentifier, onDeactivation);
|
|
20
19
|
};
|
|
21
20
|
ModuleActivationStore.prototype.addActivation = function (moduleId, serviceIdentifier, onActivation) {
|
|
22
|
-
this._getModuleActivationHandlers(moduleId)
|
|
23
|
-
.onActivations.add(serviceIdentifier, onActivation);
|
|
21
|
+
this._getModuleActivationHandlers(moduleId).onActivations.add(serviceIdentifier, onActivation);
|
|
24
22
|
};
|
|
25
23
|
ModuleActivationStore.prototype.clone = function () {
|
|
26
24
|
var clone = new ModuleActivationStore();
|
|
@@ -43,7 +41,7 @@ var ModuleActivationStore = (function () {
|
|
|
43
41
|
ModuleActivationStore.prototype._getEmptyHandlersStore = function () {
|
|
44
42
|
var handlersStore = {
|
|
45
43
|
onActivations: new lookup_1.Lookup(),
|
|
46
|
-
onDeactivations: new lookup_1.Lookup()
|
|
44
|
+
onDeactivations: new lookup_1.Lookup(),
|
|
47
45
|
};
|
|
48
46
|
return handlersStore;
|
|
49
47
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Newable as CommonNewable, ServiceIdentifier as CommonServiceIdentifier } from '@inversifyjs/common';
|
|
2
|
+
import { LegacyTarget } from '@inversifyjs/core';
|
|
1
3
|
import { FactoryType } from '../utils/factory_type';
|
|
2
4
|
declare namespace interfaces {
|
|
3
5
|
export type DynamicValue<T> = (context: interfaces.Context) => T | Promise<T>;
|
|
@@ -26,12 +28,12 @@ declare namespace interfaces {
|
|
|
26
28
|
ClassProperty: interfaces.TargetType;
|
|
27
29
|
Variable: interfaces.TargetType;
|
|
28
30
|
}
|
|
29
|
-
export type Newable<
|
|
31
|
+
export type Newable<TInstance = unknown> = CommonNewable<TInstance>;
|
|
30
32
|
export type Instance<T> = T & Record<string, () => void>;
|
|
31
33
|
export interface Abstract<T> {
|
|
32
34
|
prototype: T;
|
|
33
35
|
}
|
|
34
|
-
export type ServiceIdentifier<T = unknown> =
|
|
36
|
+
export type ServiceIdentifier<T = unknown> = CommonServiceIdentifier<T>;
|
|
35
37
|
export interface Clonable<T> {
|
|
36
38
|
clone(): T;
|
|
37
39
|
}
|
|
@@ -64,18 +66,18 @@ declare namespace interfaces {
|
|
|
64
66
|
factoryType: FactoryType;
|
|
65
67
|
factory: FactoryTypeFunction | null;
|
|
66
68
|
}
|
|
67
|
-
export type Provider<T> = (...args: any[]) => ((
|
|
69
|
+
export type Provider<T> = (...args: any[]) => ((...args: any[]) => Promise<T>) | Promise<T>;
|
|
68
70
|
export type ProviderCreator<T> = (context: Context) => Provider<T>;
|
|
69
71
|
export interface NextArgs<T = unknown> {
|
|
70
72
|
avoidConstraints: boolean;
|
|
71
|
-
contextInterceptor: (
|
|
73
|
+
contextInterceptor: (contexts: Context) => Context;
|
|
72
74
|
isMultiInject: boolean;
|
|
73
75
|
targetType: TargetType;
|
|
74
76
|
serviceIdentifier: interfaces.ServiceIdentifier<T>;
|
|
75
77
|
key?: string | number | symbol | undefined;
|
|
76
78
|
value?: unknown;
|
|
77
79
|
}
|
|
78
|
-
export type Next = (args: NextArgs) =>
|
|
80
|
+
export type Next = (args: NextArgs) => unknown | unknown[];
|
|
79
81
|
export type Middleware = (next: Next) => Next;
|
|
80
82
|
export type ContextInterceptor = (context: interfaces.Context) => interfaces.Context;
|
|
81
83
|
export interface Context {
|
|
@@ -113,26 +115,9 @@ declare namespace interfaces {
|
|
|
113
115
|
target: Target;
|
|
114
116
|
bindings: Binding<unknown>[];
|
|
115
117
|
requestScope: RequestScope | null;
|
|
116
|
-
addChildRequest(serviceIdentifier: ServiceIdentifier, bindings:
|
|
117
|
-
}
|
|
118
|
-
export interface Target {
|
|
119
|
-
id: number;
|
|
120
|
-
serviceIdentifier: ServiceIdentifier;
|
|
121
|
-
type: TargetType;
|
|
122
|
-
name: QueryableString;
|
|
123
|
-
identifier: string | symbol;
|
|
124
|
-
metadata: Metadata[];
|
|
125
|
-
getNamedTag(): interfaces.Metadata<string> | null;
|
|
126
|
-
getCustomTags(): interfaces.Metadata[] | null;
|
|
127
|
-
hasTag(key: string | number | symbol): boolean;
|
|
128
|
-
isArray(): boolean;
|
|
129
|
-
matchesArray(name: interfaces.ServiceIdentifier): boolean;
|
|
130
|
-
isNamed(): boolean;
|
|
131
|
-
isTagged(): boolean;
|
|
132
|
-
isOptional(): boolean;
|
|
133
|
-
matchesNamedTag(name: string): boolean;
|
|
134
|
-
matchesTag(key: string | number | symbol): (value: unknown) => boolean;
|
|
118
|
+
addChildRequest(serviceIdentifier: ServiceIdentifier, bindings: Binding<unknown> | Binding<unknown>[], target: Target): Request;
|
|
135
119
|
}
|
|
120
|
+
export type Target = LegacyTarget;
|
|
136
121
|
export interface ContainerOptions {
|
|
137
122
|
autoBindInjectable?: boolean;
|
|
138
123
|
defaultScope?: BindingScope | undefined;
|
|
@@ -230,11 +215,11 @@ declare namespace interfaces {
|
|
|
230
215
|
whenTargetNamed(name: string | number | symbol): BindingOnSyntax<T>;
|
|
231
216
|
whenTargetIsDefault(): BindingOnSyntax<T>;
|
|
232
217
|
whenTargetTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
|
|
233
|
-
whenInjectedInto(parent:
|
|
218
|
+
whenInjectedInto(parent: NewableFunction | string): BindingOnSyntax<T>;
|
|
234
219
|
whenParentNamed(name: string | number | symbol): BindingOnSyntax<T>;
|
|
235
220
|
whenParentTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
|
|
236
|
-
whenAnyAncestorIs(ancestor:
|
|
237
|
-
whenNoAncestorIs(ancestor:
|
|
221
|
+
whenAnyAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax<T>;
|
|
222
|
+
whenNoAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax<T>;
|
|
238
223
|
whenAnyAncestorNamed(name: string | number | symbol): BindingOnSyntax<T>;
|
|
239
224
|
whenAnyAncestorTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
|
|
240
225
|
whenNoAncestorNamed(name: string | number | symbol): BindingOnSyntax<T>;
|
|
@@ -265,8 +250,8 @@ declare namespace interfaces {
|
|
|
265
250
|
toService(service: ServiceIdentifier<T>): void;
|
|
266
251
|
}
|
|
267
252
|
export interface ConstraintFunction {
|
|
268
|
-
metaData?: Metadata;
|
|
269
253
|
(request: Request | null): boolean;
|
|
254
|
+
metaData?: Metadata;
|
|
270
255
|
}
|
|
271
256
|
export interface MetadataReader {
|
|
272
257
|
getConstructorMetadata(constructorFunc: NewableFunction): ConstructorMetadata;
|
|
@@ -281,4 +266,4 @@ declare namespace interfaces {
|
|
|
281
266
|
}
|
|
282
267
|
export {};
|
|
283
268
|
}
|
|
284
|
-
export { interfaces };
|
|
269
|
+
export type { interfaces };
|
package/lib/inversify.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as keys from './constants/metadata_keys';
|
|
2
|
+
export { LazyServiceIdentifier } from '@inversifyjs/common';
|
|
2
3
|
export declare const METADATA_KEY: typeof keys;
|
|
3
4
|
export { Container } from './container/container';
|
|
4
|
-
export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum } from './constants/literal_types';
|
|
5
|
-
export { AsyncContainerModule, ContainerModule } from './container/container_module';
|
|
5
|
+
export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum, } from './constants/literal_types';
|
|
6
|
+
export { AsyncContainerModule, ContainerModule, } from './container/container_module';
|
|
6
7
|
export { createTaggedDecorator } from './annotation/decorator_utils';
|
|
7
8
|
export { injectable } from './annotation/injectable';
|
|
8
9
|
export { tagged } from './annotation/tagged';
|
|
9
10
|
export { named } from './annotation/named';
|
|
10
11
|
export { inject } from './annotation/inject';
|
|
11
|
-
export { LazyServiceIdentifier } from './annotation/lazy_service_identifier';
|
|
12
|
-
export { LazyServiceIdentifier as LazyServiceIdentifer } from './annotation/lazy_service_identifier';
|
|
13
12
|
export { optional } from './annotation/optional';
|
|
14
13
|
export { unmanaged } from './annotation/unmanaged';
|
|
15
14
|
export { multiInject } from './annotation/multi_inject';
|
|
@@ -18,8 +17,8 @@ export { postConstruct } from './annotation/post_construct';
|
|
|
18
17
|
export { preDestroy } from './annotation/pre_destroy';
|
|
19
18
|
export { MetadataReader } from './planning/metadata_reader';
|
|
20
19
|
export { id } from './utils/id';
|
|
21
|
-
export { interfaces } from './interfaces/interfaces';
|
|
20
|
+
export type { interfaces } from './interfaces/interfaces';
|
|
22
21
|
export { decorate } from './annotation/decorator_utils';
|
|
23
|
-
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint } from './syntax/constraint_helpers';
|
|
22
|
+
export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint, } from './syntax/constraint_helpers';
|
|
24
23
|
export { getServiceIdentifierAsString } from './utils/serialization';
|
|
25
24
|
export { multiBindToService } from './utils/binding_utils';
|
package/lib/inversify.js
CHANGED
|
@@ -23,8 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.multiBindToService = exports.getServiceIdentifierAsString = exports.typeConstraint = exports.namedConstraint = exports.taggedConstraint = exports.traverseAncerstors = exports.decorate = exports.
|
|
26
|
+
exports.multiBindToService = exports.getServiceIdentifierAsString = exports.typeConstraint = exports.namedConstraint = exports.taggedConstraint = exports.traverseAncerstors = exports.decorate = exports.id = exports.MetadataReader = exports.preDestroy = exports.postConstruct = exports.targetName = exports.multiInject = exports.unmanaged = exports.optional = exports.inject = exports.named = exports.tagged = exports.injectable = exports.createTaggedDecorator = exports.ContainerModule = exports.AsyncContainerModule = exports.TargetTypeEnum = exports.BindingTypeEnum = exports.BindingScopeEnum = exports.Container = exports.METADATA_KEY = exports.LazyServiceIdentifier = void 0;
|
|
27
27
|
var keys = __importStar(require("./constants/metadata_keys"));
|
|
28
|
+
var common_1 = require("@inversifyjs/common");
|
|
29
|
+
Object.defineProperty(exports, "LazyServiceIdentifier", { enumerable: true, get: function () { return common_1.LazyServiceIdentifier; } });
|
|
28
30
|
exports.METADATA_KEY = keys;
|
|
29
31
|
var container_1 = require("./container/container");
|
|
30
32
|
Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return container_1.Container; } });
|
|
@@ -45,10 +47,6 @@ var named_1 = require("./annotation/named");
|
|
|
45
47
|
Object.defineProperty(exports, "named", { enumerable: true, get: function () { return named_1.named; } });
|
|
46
48
|
var inject_1 = require("./annotation/inject");
|
|
47
49
|
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return inject_1.inject; } });
|
|
48
|
-
var lazy_service_identifier_1 = require("./annotation/lazy_service_identifier");
|
|
49
|
-
Object.defineProperty(exports, "LazyServiceIdentifier", { enumerable: true, get: function () { return lazy_service_identifier_1.LazyServiceIdentifier; } });
|
|
50
|
-
var lazy_service_identifier_2 = require("./annotation/lazy_service_identifier");
|
|
51
|
-
Object.defineProperty(exports, "LazyServiceIdentifer", { enumerable: true, get: function () { return lazy_service_identifier_2.LazyServiceIdentifier; } });
|
|
52
50
|
var optional_1 = require("./annotation/optional");
|
|
53
51
|
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return optional_1.optional; } });
|
|
54
52
|
var unmanaged_1 = require("./annotation/unmanaged");
|
|
@@ -65,8 +63,6 @@ var metadata_reader_1 = require("./planning/metadata_reader");
|
|
|
65
63
|
Object.defineProperty(exports, "MetadataReader", { enumerable: true, get: function () { return metadata_reader_1.MetadataReader; } });
|
|
66
64
|
var id_1 = require("./utils/id");
|
|
67
65
|
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_1.id; } });
|
|
68
|
-
var interfaces_1 = require("./interfaces/interfaces");
|
|
69
|
-
Object.defineProperty(exports, "interfaces", { enumerable: true, get: function () { return interfaces_1.interfaces; } });
|
|
70
66
|
var decorator_utils_2 = require("./annotation/decorator_utils");
|
|
71
67
|
Object.defineProperty(exports, "decorate", { enumerable: true, get: function () { return decorator_utils_2.decorate; } });
|
|
72
68
|
var constraint_helpers_1 = require("./syntax/constraint_helpers");
|
|
@@ -29,15 +29,17 @@ var MetadataReader = (function () {
|
|
|
29
29
|
function MetadataReader() {
|
|
30
30
|
}
|
|
31
31
|
MetadataReader.prototype.getConstructorMetadata = function (constructorFunc) {
|
|
32
|
-
var
|
|
32
|
+
var _a;
|
|
33
|
+
var compilerGeneratedMetadata = (_a = Reflect.getMetadata(METADATA_KEY.DESIGN_PARAM_TYPES, constructorFunc)) !== null && _a !== void 0 ? _a : [];
|
|
33
34
|
var userGeneratedMetadata = Reflect.getMetadata(METADATA_KEY.TAGGED, constructorFunc);
|
|
34
35
|
return {
|
|
35
36
|
compilerGeneratedMetadata: compilerGeneratedMetadata,
|
|
36
|
-
userGeneratedMetadata: userGeneratedMetadata
|
|
37
|
+
userGeneratedMetadata: userGeneratedMetadata !== null && userGeneratedMetadata !== void 0 ? userGeneratedMetadata : {},
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
MetadataReader.prototype.getPropertiesMetadata = function (constructorFunc) {
|
|
40
|
-
var
|
|
41
|
+
var _a;
|
|
42
|
+
var userGeneratedMetadata = (_a = Reflect.getMetadata(METADATA_KEY.TAGGED_PROP, constructorFunc)) !== null && _a !== void 0 ? _a : {};
|
|
41
43
|
return userGeneratedMetadata;
|
|
42
44
|
};
|
|
43
45
|
return MetadataReader;
|