inversify 6.1.3 → 6.1.4-beta.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 CHANGED
@@ -12,6 +12,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
 
13
13
  ### Fixed
14
14
 
15
+ ## [6.1.4-beta.1]
16
+
17
+ ### Fixed
18
+ - Updated container to allow deactivating singleton undefined values.
19
+ - Updated ESM build to be compatible with both bundler and NodeJS module resolution algorithms.
20
+
21
+ ## [6.1.4-beta.0]
22
+
23
+ ### Changed
24
+ - Updated planner with better error description when a binding can not be properly resolved.
25
+
15
26
  ## [6.1.3]
16
27
 
17
28
  ### Fixed
@@ -5,7 +5,7 @@ export declare const KEY_NOT_FOUND: string;
5
5
  export declare const AMBIGUOUS_MATCH: string;
6
6
  export declare const CANNOT_UNBIND: string;
7
7
  export declare const NOT_REGISTERED: string;
8
- export declare const MISSING_INJECTABLE_ANNOTATION: string;
8
+ export declare const TRYING_TO_RESOLVE_BINDINGS: (name: string) => string;
9
9
  export declare const UNDEFINED_INJECT_ANNOTATION: (name: string) => string;
10
10
  export declare const CIRCULAR_DEPENDENCY: string;
11
11
  export declare const INVALID_BINDING_TYPE: string;
@@ -1,7 +1,7 @@
1
1
  define(["require", "exports"], function (require, exports) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.STACK_OVERFLOW = exports.CIRCULAR_DEPENDENCY_IN_FACTORY = exports.ON_DEACTIVATION_ERROR = exports.PRE_DESTROY_ERROR = exports.POST_CONSTRUCT_ERROR = exports.ASYNC_UNBIND_REQUIRED = exports.MULTIPLE_POST_CONSTRUCT_METHODS = exports.MULTIPLE_PRE_DESTROY_METHODS = exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = exports.ARGUMENTS_LENGTH_MISMATCH = exports.INVALID_DECORATOR_OPERATION = exports.INVALID_TO_SELF_VALUE = exports.LAZY_IN_SYNC = exports.INVALID_FUNCTION_BINDING = exports.INVALID_MIDDLEWARE_RETURN = exports.NO_MORE_SNAPSHOTS_AVAILABLE = exports.INVALID_BINDING_TYPE = exports.CIRCULAR_DEPENDENCY = exports.UNDEFINED_INJECT_ANNOTATION = exports.MISSING_INJECTABLE_ANNOTATION = exports.NOT_REGISTERED = exports.CANNOT_UNBIND = exports.AMBIGUOUS_MATCH = exports.KEY_NOT_FOUND = exports.NULL_ARGUMENT = exports.DUPLICATED_METADATA = exports.DUPLICATED_INJECTABLE_DECORATOR = void 0;
4
+ exports.STACK_OVERFLOW = exports.CIRCULAR_DEPENDENCY_IN_FACTORY = exports.ON_DEACTIVATION_ERROR = exports.PRE_DESTROY_ERROR = exports.POST_CONSTRUCT_ERROR = exports.ASYNC_UNBIND_REQUIRED = exports.MULTIPLE_POST_CONSTRUCT_METHODS = exports.MULTIPLE_PRE_DESTROY_METHODS = exports.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = exports.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = exports.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = exports.ARGUMENTS_LENGTH_MISMATCH = exports.INVALID_DECORATOR_OPERATION = exports.INVALID_TO_SELF_VALUE = exports.LAZY_IN_SYNC = exports.INVALID_FUNCTION_BINDING = exports.INVALID_MIDDLEWARE_RETURN = exports.NO_MORE_SNAPSHOTS_AVAILABLE = exports.INVALID_BINDING_TYPE = exports.CIRCULAR_DEPENDENCY = exports.UNDEFINED_INJECT_ANNOTATION = exports.TRYING_TO_RESOLVE_BINDINGS = 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;
5
5
  exports.DUPLICATED_INJECTABLE_DECORATOR = 'Cannot apply @injectable decorator multiple times.';
6
6
  exports.DUPLICATED_METADATA = 'Metadata key was used more than once in a parameter:';
7
7
  exports.NULL_ARGUMENT = 'NULL argument';
@@ -9,7 +9,8 @@ define(["require", "exports"], function (require, exports) {
9
9
  exports.AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:';
10
10
  exports.CANNOT_UNBIND = 'Could not unbind serviceIdentifier:';
11
11
  exports.NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:';
12
- exports.MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:';
12
+ var TRYING_TO_RESOLVE_BINDINGS = function (name) { return "Trying to resolve bindings for \"".concat(name, "\""); };
13
+ exports.TRYING_TO_RESOLVE_BINDINGS = TRYING_TO_RESOLVE_BINDINGS;
13
14
  var UNDEFINED_INJECT_ANNOTATION = function (name) {
14
15
  return "@inject called with undefined this could mean that the class ".concat(name, " has ") +
15
16
  'a circular dependency problem. You can use a LazyServiceIdentifer to ' +
@@ -454,7 +454,8 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
454
454
  };
455
455
  Container.prototype._preDestroy = function (constructor, instance) {
456
456
  var _a, _b;
457
- if (Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
457
+ if (constructor !== undefined &&
458
+ Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
458
459
  var data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
459
460
  return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
460
461
  }
@@ -469,7 +470,10 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
469
470
  };
470
471
  Container.prototype._deactivate = function (binding, instance) {
471
472
  var _this = this;
472
- var constructor = Object.getPrototypeOf(instance).constructor;
473
+ var constructor = instance == undefined
474
+ ? undefined
475
+ :
476
+ Object.getPrototypeOf(instance).constructor;
473
477
  try {
474
478
  if (this._deactivations.hasKey(binding.serviceIdentifier)) {
475
479
  var result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
@@ -478,21 +482,21 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
478
482
  return __generator(this, function (_a) {
479
483
  return [2, this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)];
480
484
  });
481
- }); }), constructor);
485
+ }); }), binding.serviceIdentifier);
482
486
  }
483
487
  }
484
488
  var propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
485
489
  if ((0, async_1.isPromise)(propagateDeactivationResult)) {
486
- return this._handleDeactivationError(propagateDeactivationResult, constructor);
490
+ return this._handleDeactivationError(propagateDeactivationResult, binding.serviceIdentifier);
487
491
  }
488
492
  }
489
493
  catch (ex) {
490
494
  if (ex instanceof Error) {
491
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex.message));
495
+ throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(binding.serviceIdentifier), ex.message));
492
496
  }
493
497
  }
494
498
  };
495
- Container.prototype._handleDeactivationError = function (asyncResult, constructor) {
499
+ Container.prototype._handleDeactivationError = function (asyncResult, serviceIdentifier) {
496
500
  return __awaiter(this, void 0, void 0, function () {
497
501
  var ex_1;
498
502
  return __generator(this, function (_a) {
@@ -506,7 +510,7 @@ define(["require", "exports", "../bindings/binding", "../constants/error_msgs",
506
510
  case 2:
507
511
  ex_1 = _a.sent();
508
512
  if (ex_1 instanceof Error) {
509
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex_1.message));
513
+ throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier), ex_1.message));
510
514
  }
511
515
  return [3, 3];
512
516
  case 3: return [2];
@@ -61,7 +61,7 @@ define(["require", "exports", "@inversifyjs/core", "../bindings/binding_count",
61
61
  else {
62
62
  activeBindings = bindings;
63
63
  }
64
- _validateActiveBindingCount(target.serviceIdentifier, activeBindings, target, context.container);
64
+ _validateActiveBindingCount(target.serviceIdentifier, activeBindings, parentRequest, target, context.container);
65
65
  return activeBindings;
66
66
  }
67
67
  function _getTargetMetadata(isMultiInject, serviceIdentifier, key, value) {
@@ -76,7 +76,7 @@ define(["require", "exports", "@inversifyjs/core", "../bindings/binding_count",
76
76
  }
77
77
  return metadataList;
78
78
  }
79
- function _validateActiveBindingCount(serviceIdentifier, bindings, target, container) {
79
+ function _validateActiveBindingCount(serviceIdentifier, bindings, parentRequest, target, container) {
80
80
  switch (bindings.length) {
81
81
  case binding_count_1.BindingCount.NoBindingsAvailable:
82
82
  if (target.isOptional()) {
@@ -87,6 +87,9 @@ define(["require", "exports", "@inversifyjs/core", "../bindings/binding_count",
87
87
  var msg = ERROR_MSGS.NOT_REGISTERED;
88
88
  msg += (0, serialization_1.listMetadataForTarget)(serviceIdentifierString, target);
89
89
  msg += (0, serialization_1.listRegisteredBindingsForServiceIdentifier)(container, serviceIdentifierString, getBindings);
90
+ if (parentRequest !== null) {
91
+ msg += "\n".concat(ERROR_MSGS.TRYING_TO_RESOLVE_BINDINGS((0, serialization_1.getServiceIdentifierAsString)(parentRequest.serviceIdentifier)));
92
+ }
90
93
  throw new Error(msg);
91
94
  }
92
95
  case binding_count_1.BindingCount.OnlyOneBindingAvailable:
@@ -86,7 +86,7 @@ define(["require", "exports", "../constants/error_msgs"], function (require, exp
86
86
  }
87
87
  function circularDependencyToException(request) {
88
88
  request.childRequests.forEach(function (childRequest) {
89
- if (alreadyDependencyChain(childRequest, childRequest.serviceIdentifier)) {
89
+ if (alreadyDependencyChain(request, childRequest.serviceIdentifier)) {
90
90
  var services = dependencyChainToString(childRequest);
91
91
  throw new Error("".concat(ERROR_MSGS.CIRCULAR_DEPENDENCY, " ").concat(services));
92
92
  }
@@ -5,7 +5,7 @@ export declare const KEY_NOT_FOUND: string;
5
5
  export declare const AMBIGUOUS_MATCH: string;
6
6
  export declare const CANNOT_UNBIND: string;
7
7
  export declare const NOT_REGISTERED: string;
8
- export declare const MISSING_INJECTABLE_ANNOTATION: string;
8
+ export declare const TRYING_TO_RESOLVE_BINDINGS: (name: string) => string;
9
9
  export declare const UNDEFINED_INJECT_ANNOTATION: (name: string) => string;
10
10
  export declare const CIRCULAR_DEPENDENCY: string;
11
11
  export declare const INVALID_BINDING_TYPE: string;
@@ -5,7 +5,7 @@ export var KEY_NOT_FOUND = 'Key Not Found';
5
5
  export var AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:';
6
6
  export var CANNOT_UNBIND = 'Could not unbind serviceIdentifier:';
7
7
  export var NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:';
8
- export var MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:';
8
+ export var TRYING_TO_RESOLVE_BINDINGS = function (name) { return "Trying to resolve bindings for \"".concat(name, "\""); };
9
9
  export var UNDEFINED_INJECT_ANNOTATION = function (name) {
10
10
  return "@inject called with undefined this could mean that the class ".concat(name, " has ") +
11
11
  'a circular dependency problem. You can use a LazyServiceIdentifer to ' +
@@ -439,7 +439,8 @@ var Container = (function () {
439
439
  };
440
440
  Container.prototype._preDestroy = function (constructor, instance) {
441
441
  var _a, _b;
442
- if (Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
442
+ if (constructor !== undefined &&
443
+ Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
443
444
  var data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
444
445
  return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
445
446
  }
@@ -454,7 +455,10 @@ var Container = (function () {
454
455
  };
455
456
  Container.prototype._deactivate = function (binding, instance) {
456
457
  var _this = this;
457
- var constructor = Object.getPrototypeOf(instance).constructor;
458
+ var constructor = instance == undefined
459
+ ? undefined
460
+ :
461
+ Object.getPrototypeOf(instance).constructor;
458
462
  try {
459
463
  if (this._deactivations.hasKey(binding.serviceIdentifier)) {
460
464
  var result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
@@ -463,21 +467,21 @@ var Container = (function () {
463
467
  return __generator(this, function (_a) {
464
468
  return [2, this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor)];
465
469
  });
466
- }); }), constructor);
470
+ }); }), binding.serviceIdentifier);
467
471
  }
468
472
  }
469
473
  var propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
470
474
  if (isPromise(propagateDeactivationResult)) {
471
- return this._handleDeactivationError(propagateDeactivationResult, constructor);
475
+ return this._handleDeactivationError(propagateDeactivationResult, binding.serviceIdentifier);
472
476
  }
473
477
  }
474
478
  catch (ex) {
475
479
  if (ex instanceof Error) {
476
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex.message));
480
+ throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(getServiceIdentifierAsString(binding.serviceIdentifier), ex.message));
477
481
  }
478
482
  }
479
483
  };
480
- Container.prototype._handleDeactivationError = function (asyncResult, constructor) {
484
+ Container.prototype._handleDeactivationError = function (asyncResult, serviceIdentifier) {
481
485
  return __awaiter(this, void 0, void 0, function () {
482
486
  var ex_1;
483
487
  return __generator(this, function (_a) {
@@ -491,7 +495,7 @@ var Container = (function () {
491
495
  case 2:
492
496
  ex_1 = _a.sent();
493
497
  if (ex_1 instanceof Error) {
494
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex_1.message));
498
+ throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(getServiceIdentifierAsString(serviceIdentifier), ex_1.message));
495
499
  }
496
500
  return [3, 3];
497
501
  case 3: return [2];