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.
Files changed (267) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +6 -15
  3. package/es/container/container.d.ts +2 -0
  4. package/es/container/module_activation_store.d.ts +2 -2
  5. package/es/interfaces/interfaces.d.ts +2 -2
  6. package/es/inversify.d.ts +1 -0
  7. package/es/inversify.js +3 -2
  8. package/es/inversify.js.LICENSE.txt +14 -0
  9. package/lib/annotation/decorator_utils.js +31 -25
  10. package/lib/annotation/inject.js +20 -10
  11. package/lib/annotation/inject_base.js +6 -6
  12. package/lib/annotation/injectable.js +20 -10
  13. package/lib/annotation/multi_inject.js +20 -10
  14. package/lib/annotation/named.js +20 -10
  15. package/lib/annotation/optional.js +20 -10
  16. package/lib/annotation/post_construct.js +21 -11
  17. package/lib/annotation/pre_destroy.js +21 -11
  18. package/lib/annotation/property_event_decorator.js +4 -4
  19. package/lib/annotation/tagged.js +2 -2
  20. package/lib/annotation/target_name.js +21 -11
  21. package/lib/annotation/unmanaged.js +21 -11
  22. package/lib/bindings/binding.js +23 -10
  23. package/lib/constants/error_msgs.js +15 -29
  24. package/lib/constants/literal_types.js +3 -3
  25. package/lib/container/container.d.ts +2 -0
  26. package/lib/container/container.js +317 -566
  27. package/lib/container/container_module.js +11 -9
  28. package/lib/container/container_snapshot.js +10 -8
  29. package/lib/container/lookup.js +61 -56
  30. package/lib/container/module_activation_store.d.ts +2 -2
  31. package/lib/container/module_activation_store.js +21 -24
  32. package/lib/interfaces/interfaces.d.ts +2 -2
  33. package/lib/inversify.d.ts +1 -0
  34. package/lib/inversify.js +19 -8
  35. package/lib/planning/context.js +12 -9
  36. package/lib/planning/metadata.js +27 -16
  37. package/lib/planning/metadata_reader.js +29 -24
  38. package/lib/planning/plan.js +5 -4
  39. package/lib/planning/planner.js +62 -53
  40. package/lib/planning/queryable_string.js +16 -16
  41. package/lib/planning/reflection_utils.js +25 -17
  42. package/lib/planning/request.js +15 -8
  43. package/lib/resolution/instantiation.js +59 -119
  44. package/lib/resolution/resolver.js +89 -134
  45. package/lib/scope/scope.js +17 -62
  46. package/lib/syntax/binding_in_syntax.js +12 -12
  47. package/lib/syntax/binding_in_when_on_syntax.js +50 -47
  48. package/lib/syntax/binding_on_syntax.js +9 -9
  49. package/lib/syntax/binding_to_syntax.js +70 -49
  50. package/lib/syntax/binding_when_on_syntax.js +42 -40
  51. package/lib/syntax/binding_when_syntax.js +54 -76
  52. package/lib/syntax/constraint_helpers.js +31 -23
  53. package/lib/utils/async.js +1 -1
  54. package/lib/utils/binding_utils.js +31 -29
  55. package/lib/utils/exceptions.js +19 -9
  56. package/lib/utils/id.js +1 -1
  57. package/lib/utils/js.js +2 -3
  58. package/lib/utils/serialization.js +42 -33
  59. package/package.json +14 -15
  60. package/amd/annotation/decorator_utils.d.ts +0 -16
  61. package/amd/annotation/decorator_utils.js +0 -119
  62. package/amd/annotation/inject.d.ts +0 -5
  63. package/amd/annotation/inject.js +0 -31
  64. package/amd/annotation/inject_base.d.ts +0 -4
  65. package/amd/annotation/inject_base.js +0 -16
  66. package/amd/annotation/injectable.d.ts +0 -2
  67. package/amd/annotation/injectable.js +0 -40
  68. package/amd/annotation/lazy_service_identifier.js +0 -4
  69. package/amd/annotation/multi_inject.d.ts +0 -5
  70. package/amd/annotation/multi_inject.js +0 -31
  71. package/amd/annotation/named.d.ts +0 -2
  72. package/amd/annotation/named.js +0 -32
  73. package/amd/annotation/optional.d.ts +0 -2
  74. package/amd/annotation/optional.js +0 -32
  75. package/amd/annotation/post_construct.d.ts +0 -4
  76. package/amd/annotation/post_construct.js +0 -32
  77. package/amd/annotation/pre_destroy.d.ts +0 -4
  78. package/amd/annotation/pre_destroy.js +0 -32
  79. package/amd/annotation/property_event_decorator.d.ts +0 -4
  80. package/amd/annotation/property_event_decorator.js +0 -16
  81. package/amd/annotation/tagged.d.ts +0 -2
  82. package/amd/annotation/tagged.js +0 -8
  83. package/amd/annotation/target_name.d.ts +0 -3
  84. package/amd/annotation/target_name.js +0 -35
  85. package/amd/annotation/unmanaged.d.ts +0 -3
  86. package/amd/annotation/unmanaged.js +0 -35
  87. package/amd/bindings/binding.d.ts +0 -20
  88. package/amd/bindings/binding.js +0 -40
  89. package/amd/bindings/binding_count.d.ts +0 -5
  90. package/amd/bindings/binding_count.js +0 -11
  91. package/amd/constants/error_msgs.d.ts +0 -30
  92. package/amd/constants/error_msgs.js +0 -75
  93. package/amd/constants/literal_types.d.ts +0 -5
  94. package/amd/constants/literal_types.js +0 -28
  95. package/amd/constants/metadata_keys.d.ts +0 -13
  96. package/amd/constants/metadata_keys.js +0 -28
  97. package/amd/container/container.d.ts +0 -73
  98. package/amd/container/container.js +0 -766
  99. package/amd/container/container_module.d.ts +0 -11
  100. package/amd/container/container_module.js +0 -21
  101. package/amd/container/container_snapshot.d.ts +0 -10
  102. package/amd/container/container_snapshot.js +0 -20
  103. package/amd/container/lookup.d.ts +0 -17
  104. package/amd/container/lookup.js +0 -132
  105. package/amd/container/module_activation_store.d.ts +0 -10
  106. package/amd/container/module_activation_store.js +0 -51
  107. package/amd/interfaces/interfaces.d.ts +0 -269
  108. package/amd/interfaces/interfaces.js +0 -4
  109. package/amd/inversify.d.ts +0 -24
  110. package/amd/inversify.js +0 -57
  111. package/amd/planning/context.d.ts +0 -11
  112. package/amd/planning/context.js +0 -19
  113. package/amd/planning/metadata.d.ts +0 -8
  114. package/amd/planning/metadata.js +0 -45
  115. package/amd/planning/metadata_reader.d.ts +0 -6
  116. package/amd/planning/metadata_reader.js +0 -49
  117. package/amd/planning/plan.d.ts +0 -7
  118. package/amd/planning/plan.js +0 -13
  119. package/amd/planning/planner.d.ts +0 -5
  120. package/amd/planning/planner.js +0 -187
  121. package/amd/planning/queryable_string.d.ts +0 -10
  122. package/amd/planning/queryable_string.js +0 -33
  123. package/amd/planning/reflection_utils.d.ts +0 -5
  124. package/amd/planning/reflection_utils.js +0 -55
  125. package/amd/planning/request.d.ts +0 -14
  126. package/amd/planning/request.js +0 -24
  127. package/amd/planning/target.js +0 -111
  128. package/amd/resolution/instantiation.d.ts +0 -3
  129. package/amd/resolution/instantiation.js +0 -219
  130. package/amd/resolution/resolver.d.ts +0 -3
  131. package/amd/resolution/resolver.js +0 -234
  132. package/amd/scope/scope.d.ts +0 -3
  133. package/amd/scope/scope.js +0 -93
  134. package/amd/syntax/binding_in_syntax.d.ts +0 -9
  135. package/amd/syntax/binding_in_syntax.js +0 -24
  136. package/amd/syntax/binding_in_when_on_syntax.d.ts +0 -29
  137. package/amd/syntax/binding_in_when_on_syntax.js +0 -75
  138. package/amd/syntax/binding_on_syntax.d.ts +0 -8
  139. package/amd/syntax/binding_on_syntax.js +0 -20
  140. package/amd/syntax/binding_to_syntax.d.ts +0 -18
  141. package/amd/syntax/binding_to_syntax.js +0 -116
  142. package/amd/syntax/binding_when_on_syntax.d.ts +0 -25
  143. package/amd/syntax/binding_when_on_syntax.js +0 -65
  144. package/amd/syntax/binding_when_syntax.d.ts +0 -21
  145. package/amd/syntax/binding_when_syntax.js +0 -107
  146. package/amd/syntax/constraint_helpers.d.ts +0 -6
  147. package/amd/syntax/constraint_helpers.js +0 -66
  148. package/amd/utils/async.d.ts +0 -3
  149. package/amd/utils/async.js +0 -17
  150. package/amd/utils/binding_utils.d.ts +0 -4
  151. package/amd/utils/binding_utils.js +0 -86
  152. package/amd/utils/clonable.d.ts +0 -3
  153. package/amd/utils/clonable.js +0 -11
  154. package/amd/utils/exceptions.d.ts +0 -2
  155. package/amd/utils/exceptions.js +0 -46
  156. package/amd/utils/factory_type.d.ts +0 -5
  157. package/amd/utils/factory_type.js +0 -11
  158. package/amd/utils/id.d.ts +0 -2
  159. package/amd/utils/id.js +0 -9
  160. package/amd/utils/js.d.ts +0 -1
  161. package/amd/utils/js.js +0 -18
  162. package/amd/utils/serialization.d.ts +0 -10
  163. package/amd/utils/serialization.js +0 -135
  164. package/es6/annotation/decorator_utils.d.ts +0 -16
  165. package/es6/annotation/decorator_utils.js +0 -114
  166. package/es6/annotation/inject.d.ts +0 -5
  167. package/es6/annotation/inject.js +0 -30
  168. package/es6/annotation/inject_base.d.ts +0 -4
  169. package/es6/annotation/inject_base.js +0 -17
  170. package/es6/annotation/injectable.d.ts +0 -2
  171. package/es6/annotation/injectable.js +0 -38
  172. package/es6/annotation/lazy_service_identifier.js +0 -2
  173. package/es6/annotation/multi_inject.d.ts +0 -5
  174. package/es6/annotation/multi_inject.js +0 -30
  175. package/es6/annotation/named.d.ts +0 -2
  176. package/es6/annotation/named.js +0 -32
  177. package/es6/annotation/optional.d.ts +0 -2
  178. package/es6/annotation/optional.js +0 -32
  179. package/es6/annotation/post_construct.d.ts +0 -4
  180. package/es6/annotation/post_construct.js +0 -31
  181. package/es6/annotation/pre_destroy.d.ts +0 -4
  182. package/es6/annotation/pre_destroy.js +0 -31
  183. package/es6/annotation/property_event_decorator.d.ts +0 -4
  184. package/es6/annotation/property_event_decorator.js +0 -15
  185. package/es6/annotation/tagged.d.ts +0 -2
  186. package/es6/annotation/tagged.js +0 -8
  187. package/es6/annotation/target_name.d.ts +0 -3
  188. package/es6/annotation/target_name.js +0 -35
  189. package/es6/annotation/unmanaged.d.ts +0 -3
  190. package/es6/annotation/unmanaged.js +0 -35
  191. package/es6/bindings/binding.d.ts +0 -20
  192. package/es6/bindings/binding.js +0 -39
  193. package/es6/bindings/binding_count.d.ts +0 -5
  194. package/es6/bindings/binding_count.js +0 -9
  195. package/es6/constants/error_msgs.d.ts +0 -30
  196. package/es6/constants/error_msgs.js +0 -59
  197. package/es6/constants/literal_types.d.ts +0 -5
  198. package/es6/constants/literal_types.js +0 -26
  199. package/es6/constants/metadata_keys.d.ts +0 -13
  200. package/es6/constants/metadata_keys.js +0 -26
  201. package/es6/container/container.d.ts +0 -73
  202. package/es6/container/container.js +0 -545
  203. package/es6/container/container_module.d.ts +0 -11
  204. package/es6/container/container_module.js +0 -18
  205. package/es6/container/container_snapshot.d.ts +0 -10
  206. package/es6/container/container_snapshot.js +0 -15
  207. package/es6/container/lookup.d.ts +0 -17
  208. package/es6/container/lookup.js +0 -125
  209. package/es6/container/module_activation_store.d.ts +0 -10
  210. package/es6/container/module_activation_store.js +0 -49
  211. package/es6/interfaces/interfaces.d.ts +0 -269
  212. package/es6/interfaces/interfaces.js +0 -2
  213. package/es6/inversify.d.ts +0 -24
  214. package/es6/inversify.js +0 -76
  215. package/es6/planning/context.d.ts +0 -11
  216. package/es6/planning/context.js +0 -17
  217. package/es6/planning/metadata.d.ts +0 -8
  218. package/es6/planning/metadata.js +0 -42
  219. package/es6/planning/metadata_reader.d.ts +0 -6
  220. package/es6/planning/metadata_reader.js +0 -44
  221. package/es6/planning/plan.d.ts +0 -7
  222. package/es6/planning/plan.js +0 -10
  223. package/es6/planning/planner.d.ts +0 -5
  224. package/es6/planning/planner.js +0 -194
  225. package/es6/planning/queryable_string.d.ts +0 -10
  226. package/es6/planning/queryable_string.js +0 -30
  227. package/es6/planning/reflection_utils.d.ts +0 -5
  228. package/es6/planning/reflection_utils.js +0 -53
  229. package/es6/planning/request.d.ts +0 -14
  230. package/es6/planning/request.js +0 -22
  231. package/es6/planning/target.js +0 -105
  232. package/es6/resolution/instantiation.d.ts +0 -3
  233. package/es6/resolution/instantiation.js +0 -158
  234. package/es6/resolution/resolver.d.ts +0 -3
  235. package/es6/resolution/resolver.js +0 -193
  236. package/es6/scope/scope.d.ts +0 -3
  237. package/es6/scope/scope.js +0 -57
  238. package/es6/syntax/binding_in_syntax.d.ts +0 -9
  239. package/es6/syntax/binding_in_syntax.js +0 -23
  240. package/es6/syntax/binding_in_when_on_syntax.d.ts +0 -29
  241. package/es6/syntax/binding_in_when_on_syntax.js +0 -75
  242. package/es6/syntax/binding_on_syntax.d.ts +0 -8
  243. package/es6/syntax/binding_on_syntax.js +0 -18
  244. package/es6/syntax/binding_to_syntax.d.ts +0 -18
  245. package/es6/syntax/binding_to_syntax.js +0 -110
  246. package/es6/syntax/binding_when_on_syntax.d.ts +0 -25
  247. package/es6/syntax/binding_when_on_syntax.js +0 -64
  248. package/es6/syntax/binding_when_syntax.d.ts +0 -21
  249. package/es6/syntax/binding_when_syntax.js +0 -84
  250. package/es6/syntax/constraint_helpers.d.ts +0 -6
  251. package/es6/syntax/constraint_helpers.js +0 -63
  252. package/es6/utils/async.d.ts +0 -3
  253. package/es6/utils/async.js +0 -15
  254. package/es6/utils/binding_utils.d.ts +0 -4
  255. package/es6/utils/binding_utils.js +0 -79
  256. package/es6/utils/clonable.d.ts +0 -3
  257. package/es6/utils/clonable.js +0 -9
  258. package/es6/utils/exceptions.d.ts +0 -2
  259. package/es6/utils/exceptions.js +0 -44
  260. package/es6/utils/factory_type.d.ts +0 -5
  261. package/es6/utils/factory_type.js +0 -9
  262. package/es6/utils/id.d.ts +0 -2
  263. package/es6/utils/id.js +0 -7
  264. package/es6/utils/js.d.ts +0 -1
  265. package/es6/utils/js.js +0 -15
  266. package/es6/utils/serialization.d.ts +0 -10
  267. package/es6/utils/serialization.js +0 -132
@@ -1,545 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Container = void 0;
36
- const binding_1 = require("../bindings/binding");
37
- const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
38
- const literal_types_1 = require("../constants/literal_types");
39
- const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
40
- const metadata_reader_1 = require("../planning/metadata_reader");
41
- const planner_1 = require("../planning/planner");
42
- const resolver_1 = require("../resolution/resolver");
43
- const binding_to_syntax_1 = require("../syntax/binding_to_syntax");
44
- const async_1 = require("../utils/async");
45
- const id_1 = require("../utils/id");
46
- const serialization_1 = require("../utils/serialization");
47
- const container_snapshot_1 = require("./container_snapshot");
48
- const lookup_1 = require("./lookup");
49
- const module_activation_store_1 = require("./module_activation_store");
50
- class Container {
51
- constructor(containerOptions) {
52
- const options = containerOptions || {};
53
- if (typeof options !== 'object') {
54
- throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT);
55
- }
56
- if (options.defaultScope === undefined) {
57
- options.defaultScope = literal_types_1.BindingScopeEnum.Transient;
58
- }
59
- else if (options.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
60
- options.defaultScope !== literal_types_1.BindingScopeEnum.Transient &&
61
- options.defaultScope !== literal_types_1.BindingScopeEnum.Request) {
62
- throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
63
- }
64
- if (options.autoBindInjectable === undefined) {
65
- options.autoBindInjectable = false;
66
- }
67
- else if (typeof options.autoBindInjectable !== 'boolean') {
68
- throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
69
- }
70
- if (options.skipBaseClassChecks === undefined) {
71
- options.skipBaseClassChecks = false;
72
- }
73
- else if (typeof options.skipBaseClassChecks !== 'boolean') {
74
- throw new Error(ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK);
75
- }
76
- this.options = {
77
- autoBindInjectable: options.autoBindInjectable,
78
- defaultScope: options.defaultScope,
79
- skipBaseClassChecks: options.skipBaseClassChecks,
80
- };
81
- this.id = (0, id_1.id)();
82
- this._bindingDictionary = new lookup_1.Lookup();
83
- this._snapshots = [];
84
- this._middleware = null;
85
- this._activations = new lookup_1.Lookup();
86
- this._deactivations = new lookup_1.Lookup();
87
- this.parent = null;
88
- this._metadataReader = new metadata_reader_1.MetadataReader();
89
- this._moduleActivationStore = new module_activation_store_1.ModuleActivationStore();
90
- }
91
- static merge(container1, container2, ...containers) {
92
- const container = new Container();
93
- const targetContainers = [
94
- container1,
95
- container2,
96
- ...containers,
97
- ].map((targetContainer) => (0, planner_1.getBindingDictionary)(targetContainer));
98
- const bindingDictionary = (0, planner_1.getBindingDictionary)(container);
99
- function copyDictionary(origin, destination) {
100
- origin.traverse((_key, value) => {
101
- value.forEach((binding) => {
102
- destination.add(binding.serviceIdentifier, binding.clone());
103
- });
104
- });
105
- }
106
- targetContainers.forEach((targetBindingDictionary) => {
107
- copyDictionary(targetBindingDictionary, bindingDictionary);
108
- });
109
- return container;
110
- }
111
- load(...modules) {
112
- const getHelpers = this._getContainerModuleHelpersFactory();
113
- for (const currentModule of modules) {
114
- const containerModuleHelpers = getHelpers(currentModule.id);
115
- currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction, containerModuleHelpers.unbindAsyncFunction, containerModuleHelpers.onActivationFunction, containerModuleHelpers.onDeactivationFunction);
116
- }
117
- }
118
- loadAsync(...modules) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- const getHelpers = this._getContainerModuleHelpersFactory();
121
- for (const currentModule of modules) {
122
- const containerModuleHelpers = getHelpers(currentModule.id);
123
- yield currentModule.registry(containerModuleHelpers.bindFunction, containerModuleHelpers.unbindFunction, containerModuleHelpers.isboundFunction, containerModuleHelpers.rebindFunction, containerModuleHelpers.unbindAsyncFunction, containerModuleHelpers.onActivationFunction, containerModuleHelpers.onDeactivationFunction);
124
- }
125
- });
126
- }
127
- unload(...modules) {
128
- modules.forEach((module) => {
129
- const deactivations = this._removeModuleBindings(module.id);
130
- this._deactivateSingletons(deactivations);
131
- this._removeModuleHandlers(module.id);
132
- });
133
- }
134
- unloadAsync(...modules) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- for (const module of modules) {
137
- const deactivations = this._removeModuleBindings(module.id);
138
- yield this._deactivateSingletonsAsync(deactivations);
139
- this._removeModuleHandlers(module.id);
140
- }
141
- });
142
- }
143
- bind(serviceIdentifier) {
144
- const scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
145
- const binding = new binding_1.Binding(serviceIdentifier, scope);
146
- this._bindingDictionary.add(serviceIdentifier, binding);
147
- return new binding_to_syntax_1.BindingToSyntax(binding);
148
- }
149
- rebind(serviceIdentifier) {
150
- this.unbind(serviceIdentifier);
151
- return this.bind(serviceIdentifier);
152
- }
153
- rebindAsync(serviceIdentifier) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- yield this.unbindAsync(serviceIdentifier);
156
- return this.bind(serviceIdentifier);
157
- });
158
- }
159
- unbind(serviceIdentifier) {
160
- if (this._bindingDictionary.hasKey(serviceIdentifier)) {
161
- const bindings = this._bindingDictionary.get(serviceIdentifier);
162
- this._deactivateSingletons(bindings);
163
- }
164
- this._removeServiceFromDictionary(serviceIdentifier);
165
- }
166
- unbindAsync(serviceIdentifier) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- if (this._bindingDictionary.hasKey(serviceIdentifier)) {
169
- const bindings = this._bindingDictionary.get(serviceIdentifier);
170
- yield this._deactivateSingletonsAsync(bindings);
171
- }
172
- this._removeServiceFromDictionary(serviceIdentifier);
173
- });
174
- }
175
- unbindAll() {
176
- this._bindingDictionary.traverse((_key, value) => {
177
- this._deactivateSingletons(value);
178
- });
179
- this._bindingDictionary = new lookup_1.Lookup();
180
- }
181
- unbindAllAsync() {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const promises = [];
184
- this._bindingDictionary.traverse((_key, value) => {
185
- promises.push(this._deactivateSingletonsAsync(value));
186
- });
187
- yield Promise.all(promises);
188
- this._bindingDictionary = new lookup_1.Lookup();
189
- });
190
- }
191
- onActivation(serviceIdentifier, onActivation) {
192
- this._activations.add(serviceIdentifier, onActivation);
193
- }
194
- onDeactivation(serviceIdentifier, onDeactivation) {
195
- this._deactivations.add(serviceIdentifier, onDeactivation);
196
- }
197
- isBound(serviceIdentifier) {
198
- let bound = this._bindingDictionary.hasKey(serviceIdentifier);
199
- if (!bound && this.parent) {
200
- bound = this.parent.isBound(serviceIdentifier);
201
- }
202
- return bound;
203
- }
204
- isCurrentBound(serviceIdentifier) {
205
- return this._bindingDictionary.hasKey(serviceIdentifier);
206
- }
207
- isBoundNamed(serviceIdentifier, named) {
208
- return this.isBoundTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
209
- }
210
- isBoundTagged(serviceIdentifier, key, value) {
211
- let bound = false;
212
- if (this._bindingDictionary.hasKey(serviceIdentifier)) {
213
- const bindings = this._bindingDictionary.get(serviceIdentifier);
214
- const request = (0, planner_1.createMockRequest)(this, serviceIdentifier, key, value);
215
- bound = bindings.some((b) => b.constraint(request));
216
- }
217
- if (!bound && this.parent) {
218
- bound = this.parent.isBoundTagged(serviceIdentifier, key, value);
219
- }
220
- return bound;
221
- }
222
- snapshot() {
223
- this._snapshots.push(container_snapshot_1.ContainerSnapshot.of(this._bindingDictionary.clone(), this._middleware, this._activations.clone(), this._deactivations.clone(), this._moduleActivationStore.clone()));
224
- }
225
- restore() {
226
- const snapshot = this._snapshots.pop();
227
- if (snapshot === undefined) {
228
- throw new Error(ERROR_MSGS.NO_MORE_SNAPSHOTS_AVAILABLE);
229
- }
230
- this._bindingDictionary = snapshot.bindings;
231
- this._activations = snapshot.activations;
232
- this._deactivations = snapshot.deactivations;
233
- this._middleware = snapshot.middleware;
234
- this._moduleActivationStore = snapshot.moduleActivationStore;
235
- }
236
- createChild(containerOptions) {
237
- const child = new Container(containerOptions || this.options);
238
- child.parent = this;
239
- return child;
240
- }
241
- applyMiddleware(...middlewares) {
242
- const initial = this._middleware
243
- ? this._middleware
244
- : this._planAndResolve();
245
- this._middleware = middlewares.reduce((prev, curr) => curr(prev), initial);
246
- }
247
- applyCustomMetadataReader(metadataReader) {
248
- this._metadataReader = metadataReader;
249
- }
250
- get(serviceIdentifier) {
251
- const getArgs = this._getNotAllArgs(serviceIdentifier, false);
252
- return this._getButThrowIfAsync(getArgs);
253
- }
254
- getAsync(serviceIdentifier) {
255
- return __awaiter(this, void 0, void 0, function* () {
256
- const getArgs = this._getNotAllArgs(serviceIdentifier, false);
257
- return this._get(getArgs);
258
- });
259
- }
260
- getTagged(serviceIdentifier, key, value) {
261
- const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
262
- return this._getButThrowIfAsync(getArgs);
263
- }
264
- getTaggedAsync(serviceIdentifier, key, value) {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);
267
- return this._get(getArgs);
268
- });
269
- }
270
- getNamed(serviceIdentifier, named) {
271
- return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
272
- }
273
- getNamedAsync(serviceIdentifier, named) {
274
- return __awaiter(this, void 0, void 0, function* () {
275
- return this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
276
- });
277
- }
278
- getAll(serviceIdentifier) {
279
- const getArgs = this._getAllArgs(serviceIdentifier);
280
- return this._getButThrowIfAsync(getArgs);
281
- }
282
- getAllAsync(serviceIdentifier) {
283
- return __awaiter(this, void 0, void 0, function* () {
284
- const getArgs = this._getAllArgs(serviceIdentifier);
285
- return this._getAll(getArgs);
286
- });
287
- }
288
- getAllTagged(serviceIdentifier, key, value) {
289
- const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
290
- return this._getButThrowIfAsync(getArgs);
291
- }
292
- getAllTaggedAsync(serviceIdentifier, key, value) {
293
- return __awaiter(this, void 0, void 0, function* () {
294
- const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value);
295
- return this._getAll(getArgs);
296
- });
297
- }
298
- getAllNamed(serviceIdentifier, named) {
299
- return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
300
- }
301
- getAllNamedAsync(serviceIdentifier, named) {
302
- return __awaiter(this, void 0, void 0, function* () {
303
- return this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named);
304
- });
305
- }
306
- resolve(constructorFunction) {
307
- const isBound = this.isBound(constructorFunction);
308
- if (!isBound) {
309
- this.bind(constructorFunction).toSelf();
310
- }
311
- const resolved = this.get(constructorFunction);
312
- if (!isBound) {
313
- this.unbind(constructorFunction);
314
- }
315
- return resolved;
316
- }
317
- _preDestroy(constructor, instance) {
318
- var _a, _b;
319
- if (constructor !== undefined &&
320
- Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) {
321
- const data = Reflect.getMetadata(METADATA_KEY.PRE_DESTROY, constructor);
322
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
323
- }
324
- }
325
- _removeModuleHandlers(moduleId) {
326
- const moduleActivationsHandlers = this._moduleActivationStore.remove(moduleId);
327
- this._activations.removeIntersection(moduleActivationsHandlers.onActivations);
328
- this._deactivations.removeIntersection(moduleActivationsHandlers.onDeactivations);
329
- }
330
- _removeModuleBindings(moduleId) {
331
- return this._bindingDictionary.removeByCondition((binding) => binding.moduleId === moduleId);
332
- }
333
- _deactivate(binding, instance) {
334
- const constructor = instance == undefined
335
- ? undefined
336
- :
337
- Object.getPrototypeOf(instance).constructor;
338
- try {
339
- if (this._deactivations.hasKey(binding.serviceIdentifier)) {
340
- const result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values());
341
- if ((0, async_1.isPromise)(result)) {
342
- return this._handleDeactivationError(result.then(() => __awaiter(this, void 0, void 0, function* () {
343
- return this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor);
344
- })), binding.serviceIdentifier);
345
- }
346
- }
347
- const propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor);
348
- if ((0, async_1.isPromise)(propagateDeactivationResult)) {
349
- return this._handleDeactivationError(propagateDeactivationResult, binding.serviceIdentifier);
350
- }
351
- }
352
- catch (ex) {
353
- if (ex instanceof Error) {
354
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(binding.serviceIdentifier), ex.message));
355
- }
356
- }
357
- }
358
- _handleDeactivationError(asyncResult, serviceIdentifier) {
359
- return __awaiter(this, void 0, void 0, function* () {
360
- try {
361
- yield asyncResult;
362
- }
363
- catch (ex) {
364
- if (ex instanceof Error) {
365
- throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR((0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier), ex.message));
366
- }
367
- }
368
- });
369
- }
370
- _deactivateContainer(instance, deactivationsIterator) {
371
- let deactivation = deactivationsIterator.next();
372
- while (typeof deactivation.value === 'function') {
373
- const result = deactivation.value(instance);
374
- if ((0, async_1.isPromise)(result)) {
375
- return result.then(() => __awaiter(this, void 0, void 0, function* () { return this._deactivateContainerAsync(instance, deactivationsIterator); }));
376
- }
377
- deactivation = deactivationsIterator.next();
378
- }
379
- }
380
- _deactivateContainerAsync(instance, deactivationsIterator) {
381
- return __awaiter(this, void 0, void 0, function* () {
382
- let deactivation = deactivationsIterator.next();
383
- while (typeof deactivation.value === 'function') {
384
- yield deactivation.value(instance);
385
- deactivation = deactivationsIterator.next();
386
- }
387
- });
388
- }
389
- _getContainerModuleHelpersFactory() {
390
- const setModuleId = (bindingToSyntax, moduleId) => {
391
- bindingToSyntax._binding.moduleId = moduleId;
392
- };
393
- const getBindFunction = (moduleId) => (serviceIdentifier) => {
394
- const bindingToSyntax = this.bind(serviceIdentifier);
395
- setModuleId(bindingToSyntax, moduleId);
396
- return bindingToSyntax;
397
- };
398
- const getUnbindFunction = () => (serviceIdentifier) => {
399
- this.unbind(serviceIdentifier);
400
- };
401
- const getUnbindAsyncFunction = () => (serviceIdentifier) => __awaiter(this, void 0, void 0, function* () {
402
- return this.unbindAsync(serviceIdentifier);
403
- });
404
- const getIsboundFunction = () => (serviceIdentifier) => {
405
- return this.isBound(serviceIdentifier);
406
- };
407
- const getRebindFunction = (moduleId) => (serviceIdentifier) => {
408
- const bindingToSyntax = this.rebind(serviceIdentifier);
409
- setModuleId(bindingToSyntax, moduleId);
410
- return bindingToSyntax;
411
- };
412
- const getOnActivationFunction = (moduleId) => (serviceIdentifier, onActivation) => {
413
- this._moduleActivationStore.addActivation(moduleId, serviceIdentifier, onActivation);
414
- this.onActivation(serviceIdentifier, onActivation);
415
- };
416
- const getOnDeactivationFunction = (moduleId) => (serviceIdentifier, onDeactivation) => {
417
- this._moduleActivationStore.addDeactivation(moduleId, serviceIdentifier, onDeactivation);
418
- this.onDeactivation(serviceIdentifier, onDeactivation);
419
- };
420
- return (mId) => ({
421
- bindFunction: getBindFunction(mId),
422
- isboundFunction: getIsboundFunction(),
423
- onActivationFunction: getOnActivationFunction(mId),
424
- onDeactivationFunction: getOnDeactivationFunction(mId),
425
- rebindFunction: getRebindFunction(mId),
426
- unbindAsyncFunction: getUnbindAsyncFunction(),
427
- unbindFunction: getUnbindFunction(),
428
- });
429
- }
430
- _getAll(getArgs) {
431
- return __awaiter(this, void 0, void 0, function* () {
432
- return Promise.all(this._get(getArgs));
433
- });
434
- }
435
- _get(getArgs) {
436
- const planAndResolveArgs = Object.assign(Object.assign({}, getArgs), { contextInterceptor: (context) => context, targetType: literal_types_1.TargetTypeEnum.Variable });
437
- if (this._middleware) {
438
- const middlewareResult = this._middleware(planAndResolveArgs);
439
- if (middlewareResult === undefined || middlewareResult === null) {
440
- throw new Error(ERROR_MSGS.INVALID_MIDDLEWARE_RETURN);
441
- }
442
- return middlewareResult;
443
- }
444
- return this._planAndResolve()(planAndResolveArgs);
445
- }
446
- _getButThrowIfAsync(getArgs) {
447
- const result = this._get(getArgs);
448
- if ((0, async_1.isPromiseOrContainsPromise)(result)) {
449
- throw new Error(ERROR_MSGS.LAZY_IN_SYNC(getArgs.serviceIdentifier));
450
- }
451
- return result;
452
- }
453
- _getAllArgs(serviceIdentifier) {
454
- const getAllArgs = {
455
- avoidConstraints: true,
456
- isMultiInject: true,
457
- serviceIdentifier,
458
- };
459
- return getAllArgs;
460
- }
461
- _getNotAllArgs(serviceIdentifier, isMultiInject, key, value) {
462
- const getNotAllArgs = {
463
- avoidConstraints: false,
464
- isMultiInject,
465
- key,
466
- serviceIdentifier,
467
- value,
468
- };
469
- return getNotAllArgs;
470
- }
471
- _planAndResolve() {
472
- return (args) => {
473
- let context = (0, planner_1.plan)(this._metadataReader, this, args.isMultiInject, args.targetType, args.serviceIdentifier, args.key, args.value, args.avoidConstraints);
474
- context = args.contextInterceptor(context);
475
- const result = (0, resolver_1.resolve)(context);
476
- return result;
477
- };
478
- }
479
- _deactivateIfSingleton(binding) {
480
- if (!binding.activated) {
481
- return;
482
- }
483
- if ((0, async_1.isPromise)(binding.cache)) {
484
- return binding.cache.then((resolved) => this._deactivate(binding, resolved));
485
- }
486
- return this._deactivate(binding, binding.cache);
487
- }
488
- _deactivateSingletons(bindings) {
489
- for (const binding of bindings) {
490
- const result = this._deactivateIfSingleton(binding);
491
- if ((0, async_1.isPromise)(result)) {
492
- throw new Error(ERROR_MSGS.ASYNC_UNBIND_REQUIRED);
493
- }
494
- }
495
- }
496
- _deactivateSingletonsAsync(bindings) {
497
- return __awaiter(this, void 0, void 0, function* () {
498
- yield Promise.all(bindings.map((b) => __awaiter(this, void 0, void 0, function* () { return this._deactivateIfSingleton(b); })));
499
- });
500
- }
501
- _propagateContainerDeactivationThenBindingAndPreDestroy(binding, instance, constructor) {
502
- if (this.parent) {
503
- return this._deactivate.bind(this.parent)(binding, instance);
504
- }
505
- else {
506
- return this._bindingDeactivationAndPreDestroy(binding, instance, constructor);
507
- }
508
- }
509
- _propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor) {
510
- return __awaiter(this, void 0, void 0, function* () {
511
- if (this.parent) {
512
- yield this._deactivate.bind(this.parent)(binding, instance);
513
- }
514
- else {
515
- yield this._bindingDeactivationAndPreDestroyAsync(binding, instance, constructor);
516
- }
517
- });
518
- }
519
- _removeServiceFromDictionary(serviceIdentifier) {
520
- try {
521
- this._bindingDictionary.remove(serviceIdentifier);
522
- }
523
- catch (_e) {
524
- throw new Error(`${ERROR_MSGS.CANNOT_UNBIND} ${(0, serialization_1.getServiceIdentifierAsString)(serviceIdentifier)}`);
525
- }
526
- }
527
- _bindingDeactivationAndPreDestroy(binding, instance, constructor) {
528
- if (typeof binding.onDeactivation === 'function') {
529
- const result = binding.onDeactivation(instance);
530
- if ((0, async_1.isPromise)(result)) {
531
- return result.then(() => this._preDestroy(constructor, instance));
532
- }
533
- }
534
- return this._preDestroy(constructor, instance);
535
- }
536
- _bindingDeactivationAndPreDestroyAsync(binding, instance, constructor) {
537
- return __awaiter(this, void 0, void 0, function* () {
538
- if (typeof binding.onDeactivation === 'function') {
539
- yield binding.onDeactivation(instance);
540
- }
541
- yield this._preDestroy(constructor, instance);
542
- });
543
- }
544
- }
545
- exports.Container = Container;
@@ -1,11 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- export declare class ContainerModule implements interfaces.ContainerModule {
3
- id: number;
4
- registry: interfaces.ContainerModuleCallBack;
5
- constructor(registry: interfaces.ContainerModuleCallBack);
6
- }
7
- export declare class AsyncContainerModule implements interfaces.AsyncContainerModule {
8
- id: number;
9
- registry: interfaces.AsyncContainerModuleCallBack;
10
- constructor(registry: interfaces.AsyncContainerModuleCallBack);
11
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsyncContainerModule = exports.ContainerModule = void 0;
4
- const id_1 = require("../utils/id");
5
- class ContainerModule {
6
- constructor(registry) {
7
- this.id = (0, id_1.id)();
8
- this.registry = registry;
9
- }
10
- }
11
- exports.ContainerModule = ContainerModule;
12
- class AsyncContainerModule {
13
- constructor(registry) {
14
- this.id = (0, id_1.id)();
15
- this.registry = registry;
16
- }
17
- }
18
- exports.AsyncContainerModule = AsyncContainerModule;
@@ -1,10 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare class ContainerSnapshot implements interfaces.ContainerSnapshot {
3
- bindings: interfaces.Lookup<interfaces.Binding<unknown>>;
4
- activations: interfaces.Lookup<interfaces.BindingActivation<unknown>>;
5
- deactivations: interfaces.Lookup<interfaces.BindingDeactivation<unknown>>;
6
- middleware: interfaces.Next | null;
7
- moduleActivationStore: interfaces.ModuleActivationStore;
8
- static of(bindings: interfaces.Lookup<interfaces.Binding<unknown>>, middleware: interfaces.Next | null, activations: interfaces.Lookup<interfaces.BindingActivation<unknown>>, deactivations: interfaces.Lookup<interfaces.BindingDeactivation<unknown>>, moduleActivationStore: interfaces.ModuleActivationStore): ContainerSnapshot;
9
- }
10
- export { ContainerSnapshot };
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContainerSnapshot = void 0;
4
- class ContainerSnapshot {
5
- static of(bindings, middleware, activations, deactivations, moduleActivationStore) {
6
- const snapshot = new ContainerSnapshot();
7
- snapshot.bindings = bindings;
8
- snapshot.middleware = middleware;
9
- snapshot.deactivations = deactivations;
10
- snapshot.activations = activations;
11
- snapshot.moduleActivationStore = moduleActivationStore;
12
- return snapshot;
13
- }
14
- }
15
- exports.ContainerSnapshot = ContainerSnapshot;
@@ -1,17 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare class Lookup<T> implements interfaces.Lookup<T> {
3
- private readonly _map;
4
- constructor();
5
- getMap(): Map<interfaces.ServiceIdentifier<unknown>, T[]>;
6
- add(serviceIdentifier: interfaces.ServiceIdentifier, value: T): void;
7
- get(serviceIdentifier: interfaces.ServiceIdentifier): T[];
8
- remove(serviceIdentifier: interfaces.ServiceIdentifier): void;
9
- removeIntersection(lookup: interfaces.Lookup<T>): void;
10
- removeByCondition(condition: (item: T) => boolean): T[];
11
- hasKey(serviceIdentifier: interfaces.ServiceIdentifier): boolean;
12
- clone(): interfaces.Lookup<T>;
13
- traverse(func: (key: interfaces.ServiceIdentifier, value: T[]) => void): void;
14
- private _checkNonNulish;
15
- private _setValue;
16
- }
17
- export { Lookup };