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,158 +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.resolveInstance = resolveInstance;
36
- const error_msgs_1 = require("../constants/error_msgs");
37
- const literal_types_1 = require("../constants/literal_types");
38
- const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
39
- const async_1 = require("../utils/async");
40
- function _resolveRequests(childRequests, resolveRequest) {
41
- return childRequests.reduce((resolvedRequests, childRequest) => {
42
- const injection = resolveRequest(childRequest);
43
- const targetType = childRequest.target.type;
44
- if (targetType === literal_types_1.TargetTypeEnum.ConstructorArgument) {
45
- resolvedRequests.constructorInjections.push(injection);
46
- }
47
- else {
48
- resolvedRequests.propertyRequests.push(childRequest);
49
- resolvedRequests.propertyInjections.push(injection);
50
- }
51
- if (!resolvedRequests.isAsync) {
52
- resolvedRequests.isAsync = (0, async_1.isPromiseOrContainsPromise)(injection);
53
- }
54
- return resolvedRequests;
55
- }, {
56
- constructorInjections: [],
57
- isAsync: false,
58
- propertyInjections: [],
59
- propertyRequests: [],
60
- });
61
- }
62
- function _createInstance(constr, childRequests, resolveRequest) {
63
- let result;
64
- if (childRequests.length > 0) {
65
- const resolved = _resolveRequests(childRequests, resolveRequest);
66
- const createInstanceWithInjectionsArg = Object.assign(Object.assign({}, resolved), { constr });
67
- if (resolved.isAsync) {
68
- result = createInstanceWithInjectionsAsync(createInstanceWithInjectionsArg);
69
- }
70
- else {
71
- result = createInstanceWithInjections(createInstanceWithInjectionsArg);
72
- }
73
- }
74
- else {
75
- result = new constr();
76
- }
77
- return result;
78
- }
79
- function createInstanceWithInjections(args) {
80
- const instance = new args.constr(...args.constructorInjections);
81
- args.propertyRequests.forEach((r, index) => {
82
- const property = r.target.identifier;
83
- const injection = args.propertyInjections[index];
84
- if (!r.target.isOptional() || injection !== undefined) {
85
- instance[property] = injection;
86
- }
87
- });
88
- return instance;
89
- }
90
- function createInstanceWithInjectionsAsync(args) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- const constructorInjections = yield possiblyWaitInjections(args.constructorInjections);
93
- const propertyInjections = yield possiblyWaitInjections(args.propertyInjections);
94
- return createInstanceWithInjections(Object.assign(Object.assign({}, args), { constructorInjections,
95
- propertyInjections }));
96
- });
97
- }
98
- function possiblyWaitInjections(possiblePromiseinjections) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const injections = [];
101
- for (const injection of possiblePromiseinjections) {
102
- if (Array.isArray(injection)) {
103
- injections.push(Promise.all(injection));
104
- }
105
- else {
106
- injections.push(injection);
107
- }
108
- }
109
- return Promise.all(injections);
110
- });
111
- }
112
- function _getInstanceAfterPostConstruct(constr, result) {
113
- const postConstructResult = _postConstruct(constr, result);
114
- if ((0, async_1.isPromise)(postConstructResult)) {
115
- return postConstructResult.then(() => result);
116
- }
117
- else {
118
- return result;
119
- }
120
- }
121
- function _postConstruct(constr, instance) {
122
- var _a, _b;
123
- if (Reflect.hasMetadata(METADATA_KEY.POST_CONSTRUCT, constr)) {
124
- const data = Reflect.getMetadata(METADATA_KEY.POST_CONSTRUCT, constr);
125
- try {
126
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
127
- }
128
- catch (e) {
129
- if (e instanceof Error) {
130
- throw new Error((0, error_msgs_1.POST_CONSTRUCT_ERROR)(constr.name, e.message));
131
- }
132
- }
133
- }
134
- }
135
- function _validateInstanceResolution(binding, constr) {
136
- if (binding.scope !== literal_types_1.BindingScopeEnum.Singleton) {
137
- _throwIfHandlingDeactivation(binding, constr);
138
- }
139
- }
140
- function _throwIfHandlingDeactivation(binding, constr) {
141
- const scopeErrorMessage = `Class cannot be instantiated in ${binding.scope === literal_types_1.BindingScopeEnum.Request ? 'request' : 'transient'} scope.`;
142
- if (typeof binding.onDeactivation === 'function') {
143
- throw new Error((0, error_msgs_1.ON_DEACTIVATION_ERROR)(constr.name, scopeErrorMessage));
144
- }
145
- if (Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constr)) {
146
- throw new Error((0, error_msgs_1.PRE_DESTROY_ERROR)(constr.name, scopeErrorMessage));
147
- }
148
- }
149
- function resolveInstance(binding, constr, childRequests, resolveRequest) {
150
- _validateInstanceResolution(binding, constr);
151
- const result = _createInstance(constr, childRequests, resolveRequest);
152
- if ((0, async_1.isPromise)(result)) {
153
- return result.then((resolvedResult) => _getInstanceAfterPostConstruct(constr, resolvedResult));
154
- }
155
- else {
156
- return _getInstanceAfterPostConstruct(constr, result);
157
- }
158
- }
@@ -1,3 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare function resolve<T>(context: interfaces.Context): T | Promise<T> | (T | Promise<T>)[];
3
- export { resolve };
@@ -1,193 +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.resolve = resolve;
36
- const ERROR_MSGS = __importStar(require("../constants/error_msgs"));
37
- const literal_types_1 = require("../constants/literal_types");
38
- const planner_1 = require("../planning/planner");
39
- const scope_1 = require("../scope/scope");
40
- const async_1 = require("../utils/async");
41
- const binding_utils_1 = require("../utils/binding_utils");
42
- const exceptions_1 = require("../utils/exceptions");
43
- const instantiation_1 = require("./instantiation");
44
- const _resolveRequest = (requestScope) => (request) => {
45
- request.parentContext.setCurrentRequest(request);
46
- const bindings = request.bindings;
47
- const childRequests = request.childRequests;
48
- const targetIsAnArray = request.target && request.target.isArray();
49
- const targetParentIsNotAnArray = !request.parentRequest ||
50
- !request.parentRequest.target ||
51
- !request.target ||
52
- !request.parentRequest.target.matchesArray(request.target.serviceIdentifier);
53
- if (targetIsAnArray && targetParentIsNotAnArray) {
54
- return childRequests.map((childRequest) => {
55
- const resolveRequest = _resolveRequest(requestScope);
56
- return resolveRequest(childRequest);
57
- });
58
- }
59
- else {
60
- if (request.target.isOptional() && bindings.length === 0) {
61
- return undefined;
62
- }
63
- const binding = bindings[0];
64
- return _resolveBinding(requestScope, request, binding);
65
- }
66
- };
67
- const _resolveFactoryFromBinding = (binding, context) => {
68
- const factoryDetails = (0, binding_utils_1.getFactoryDetails)(binding);
69
- return (0, exceptions_1.tryAndThrowErrorIfStackOverflow)(() => factoryDetails.factory.bind(binding)(context), () => new Error(ERROR_MSGS.CIRCULAR_DEPENDENCY_IN_FACTORY(factoryDetails.factoryType, context.currentRequest.serviceIdentifier.toString())));
70
- };
71
- const _getResolvedFromBinding = (requestScope, request, binding) => {
72
- let result;
73
- const childRequests = request.childRequests;
74
- (0, binding_utils_1.ensureFullyBound)(binding);
75
- switch (binding.type) {
76
- case literal_types_1.BindingTypeEnum.ConstantValue:
77
- case literal_types_1.BindingTypeEnum.Function:
78
- result = binding.cache;
79
- break;
80
- case literal_types_1.BindingTypeEnum.Constructor:
81
- result = binding.implementationType;
82
- break;
83
- case literal_types_1.BindingTypeEnum.Instance:
84
- result = (0, instantiation_1.resolveInstance)(binding, binding.implementationType, childRequests, _resolveRequest(requestScope));
85
- break;
86
- default:
87
- result = _resolveFactoryFromBinding(binding, request.parentContext);
88
- }
89
- return result;
90
- };
91
- const _resolveInScope = (requestScope, binding, resolveFromBinding) => {
92
- let result = (0, scope_1.tryGetFromScope)(requestScope, binding);
93
- if (result !== null) {
94
- return result;
95
- }
96
- result = resolveFromBinding();
97
- (0, scope_1.saveToScope)(requestScope, binding, result);
98
- return result;
99
- };
100
- const _resolveBinding = (requestScope, request, binding) => {
101
- return _resolveInScope(requestScope, binding, () => {
102
- let result = _getResolvedFromBinding(requestScope, request, binding);
103
- if ((0, async_1.isPromise)(result)) {
104
- result = result.then((resolved) => _onActivation(request, binding, resolved));
105
- }
106
- else {
107
- result = _onActivation(request, binding, result);
108
- }
109
- return result;
110
- });
111
- };
112
- function _onActivation(request, binding, resolved) {
113
- let result = _bindingActivation(request.parentContext, binding, resolved);
114
- const containersIterator = _getContainersIterator(request.parentContext.container);
115
- let container;
116
- let containersIteratorResult = containersIterator.next();
117
- do {
118
- container = containersIteratorResult.value;
119
- const context = request.parentContext;
120
- const serviceIdentifier = request.serviceIdentifier;
121
- const activationsIterator = _getContainerActivationsForService(container, serviceIdentifier);
122
- if ((0, async_1.isPromise)(result)) {
123
- result = _activateContainerAsync(activationsIterator, context, result);
124
- }
125
- else {
126
- result = _activateContainer(activationsIterator, context, result);
127
- }
128
- containersIteratorResult = containersIterator.next();
129
- } while (containersIteratorResult.done !== true &&
130
- !(0, planner_1.getBindingDictionary)(container).hasKey(request.serviceIdentifier));
131
- return result;
132
- }
133
- const _bindingActivation = (context, binding, previousResult) => {
134
- let result;
135
- if (typeof binding.onActivation === 'function') {
136
- result = binding.onActivation(context, previousResult);
137
- }
138
- else {
139
- result = previousResult;
140
- }
141
- return result;
142
- };
143
- const _activateContainer = (activationsIterator, context, result) => {
144
- let activation = activationsIterator.next();
145
- while (activation.done !== true) {
146
- result = activation.value(context, result);
147
- if ((0, async_1.isPromise)(result)) {
148
- return _activateContainerAsync(activationsIterator, context, result);
149
- }
150
- activation = activationsIterator.next();
151
- }
152
- return result;
153
- };
154
- const _activateContainerAsync = (activationsIterator, context, resultPromise) => __awaiter(void 0, void 0, void 0, function* () {
155
- let result = yield resultPromise;
156
- let activation = activationsIterator.next();
157
- while (activation.done !== true) {
158
- result = yield activation.value(context, result);
159
- activation = activationsIterator.next();
160
- }
161
- return result;
162
- });
163
- const _getContainerActivationsForService = (container, serviceIdentifier) => {
164
- const activations = container._activations;
165
- return activations.hasKey(serviceIdentifier)
166
- ? activations.get(serviceIdentifier).values()
167
- : [].values();
168
- };
169
- const _getContainersIterator = (container) => {
170
- const containersStack = [container];
171
- let parent = container.parent;
172
- while (parent !== null) {
173
- containersStack.push(parent);
174
- parent = parent.parent;
175
- }
176
- const getNextContainer = () => {
177
- const nextContainer = containersStack.pop();
178
- if (nextContainer !== undefined) {
179
- return { done: false, value: nextContainer };
180
- }
181
- else {
182
- return { done: true, value: undefined };
183
- }
184
- };
185
- const containersIterator = {
186
- next: getNextContainer,
187
- };
188
- return containersIterator;
189
- };
190
- function resolve(context) {
191
- const resolveRequestFunction = _resolveRequest(context.plan.rootRequest.requestScope);
192
- return resolveRequestFunction(context.plan.rootRequest);
193
- }
@@ -1,3 +0,0 @@
1
- import type { interfaces } from '../interfaces/interfaces';
2
- export declare const tryGetFromScope: <T>(requestScope: interfaces.RequestScope, binding: interfaces.Binding<T>) => T | Promise<T> | null;
3
- export declare const saveToScope: <T>(requestScope: interfaces.RequestScope, binding: interfaces.Binding<T>, result: T | Promise<T>) => void;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.saveToScope = exports.tryGetFromScope = void 0;
13
- const literal_types_1 = require("../constants/literal_types");
14
- const async_1 = require("../utils/async");
15
- const tryGetFromScope = (requestScope, binding) => {
16
- if (binding.scope === literal_types_1.BindingScopeEnum.Singleton && binding.activated) {
17
- return binding.cache;
18
- }
19
- if (binding.scope === literal_types_1.BindingScopeEnum.Request &&
20
- requestScope.has(binding.id)) {
21
- return requestScope.get(binding.id);
22
- }
23
- return null;
24
- };
25
- exports.tryGetFromScope = tryGetFromScope;
26
- const saveToScope = (requestScope, binding, result) => {
27
- if (binding.scope === literal_types_1.BindingScopeEnum.Singleton) {
28
- _saveToSingletonScope(binding, result);
29
- }
30
- if (binding.scope === literal_types_1.BindingScopeEnum.Request) {
31
- _saveToRequestScope(requestScope, binding, result);
32
- }
33
- };
34
- exports.saveToScope = saveToScope;
35
- const _saveToRequestScope = (requestScope, binding, result) => {
36
- if (!requestScope.has(binding.id)) {
37
- requestScope.set(binding.id, result);
38
- }
39
- };
40
- const _saveToSingletonScope = (binding, result) => {
41
- binding.cache = result;
42
- binding.activated = true;
43
- if ((0, async_1.isPromise)(result)) {
44
- void _saveAsyncResultToSingletonScope(binding, result);
45
- }
46
- };
47
- const _saveAsyncResultToSingletonScope = (binding, asyncResult) => __awaiter(void 0, void 0, void 0, function* () {
48
- try {
49
- const result = yield asyncResult;
50
- binding.cache = result;
51
- }
52
- catch (ex) {
53
- binding.cache = null;
54
- binding.activated = false;
55
- throw ex;
56
- }
57
- });
@@ -1,9 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare class BindingInSyntax<T> implements interfaces.BindingInSyntax<T> {
3
- private readonly _binding;
4
- constructor(binding: interfaces.Binding<T>);
5
- inRequestScope(): interfaces.BindingWhenOnSyntax<T>;
6
- inSingletonScope(): interfaces.BindingWhenOnSyntax<T>;
7
- inTransientScope(): interfaces.BindingWhenOnSyntax<T>;
8
- }
9
- export { BindingInSyntax };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BindingInSyntax = void 0;
4
- const literal_types_1 = require("../constants/literal_types");
5
- const binding_when_on_syntax_1 = require("./binding_when_on_syntax");
6
- class BindingInSyntax {
7
- constructor(binding) {
8
- this._binding = binding;
9
- }
10
- inRequestScope() {
11
- this._binding.scope = literal_types_1.BindingScopeEnum.Request;
12
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
13
- }
14
- inSingletonScope() {
15
- this._binding.scope = literal_types_1.BindingScopeEnum.Singleton;
16
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
17
- }
18
- inTransientScope() {
19
- this._binding.scope = literal_types_1.BindingScopeEnum.Transient;
20
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
21
- }
22
- }
23
- exports.BindingInSyntax = BindingInSyntax;
@@ -1,29 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare class BindingInWhenOnSyntax<T> implements interfaces.BindingInSyntax<T>, interfaces.BindingWhenSyntax<T>, interfaces.BindingOnSyntax<T> {
3
- private readonly _bindingInSyntax;
4
- private readonly _bindingWhenSyntax;
5
- private readonly _bindingOnSyntax;
6
- private readonly _binding;
7
- constructor(binding: interfaces.Binding<T>);
8
- inRequestScope(): interfaces.BindingWhenOnSyntax<T>;
9
- inSingletonScope(): interfaces.BindingWhenOnSyntax<T>;
10
- inTransientScope(): interfaces.BindingWhenOnSyntax<T>;
11
- when(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax<T>;
12
- whenTargetNamed(name: string): interfaces.BindingOnSyntax<T>;
13
- whenTargetIsDefault(): interfaces.BindingOnSyntax<T>;
14
- whenTargetTagged(tag: string, value: unknown): interfaces.BindingOnSyntax<T>;
15
- whenInjectedInto(parent: NewableFunction | string): interfaces.BindingOnSyntax<T>;
16
- whenParentNamed(name: string): interfaces.BindingOnSyntax<T>;
17
- whenParentTagged(tag: string, value: unknown): interfaces.BindingOnSyntax<T>;
18
- whenAnyAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax<T>;
19
- whenNoAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax<T>;
20
- whenAnyAncestorNamed(name: string): interfaces.BindingOnSyntax<T>;
21
- whenAnyAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax<T>;
22
- whenNoAncestorNamed(name: string): interfaces.BindingOnSyntax<T>;
23
- whenNoAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax<T>;
24
- whenAnyAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax<T>;
25
- whenNoAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax<T>;
26
- onActivation(handler: (context: interfaces.Context, injectable: T) => T | Promise<T>): interfaces.BindingWhenSyntax<T>;
27
- onDeactivation(handler: (injectable: T) => void | Promise<void>): interfaces.BindingWhenSyntax<T>;
28
- }
29
- export { BindingInWhenOnSyntax };
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BindingInWhenOnSyntax = void 0;
4
- const binding_in_syntax_1 = require("./binding_in_syntax");
5
- const binding_on_syntax_1 = require("./binding_on_syntax");
6
- const binding_when_syntax_1 = require("./binding_when_syntax");
7
- class BindingInWhenOnSyntax {
8
- constructor(binding) {
9
- this._binding = binding;
10
- this._bindingWhenSyntax = new binding_when_syntax_1.BindingWhenSyntax(this._binding);
11
- this._bindingOnSyntax = new binding_on_syntax_1.BindingOnSyntax(this._binding);
12
- this._bindingInSyntax = new binding_in_syntax_1.BindingInSyntax(binding);
13
- }
14
- inRequestScope() {
15
- return this._bindingInSyntax.inRequestScope();
16
- }
17
- inSingletonScope() {
18
- return this._bindingInSyntax.inSingletonScope();
19
- }
20
- inTransientScope() {
21
- return this._bindingInSyntax.inTransientScope();
22
- }
23
- when(constraint) {
24
- return this._bindingWhenSyntax.when(constraint);
25
- }
26
- whenTargetNamed(name) {
27
- return this._bindingWhenSyntax.whenTargetNamed(name);
28
- }
29
- whenTargetIsDefault() {
30
- return this._bindingWhenSyntax.whenTargetIsDefault();
31
- }
32
- whenTargetTagged(tag, value) {
33
- return this._bindingWhenSyntax.whenTargetTagged(tag, value);
34
- }
35
- whenInjectedInto(parent) {
36
- return this._bindingWhenSyntax.whenInjectedInto(parent);
37
- }
38
- whenParentNamed(name) {
39
- return this._bindingWhenSyntax.whenParentNamed(name);
40
- }
41
- whenParentTagged(tag, value) {
42
- return this._bindingWhenSyntax.whenParentTagged(tag, value);
43
- }
44
- whenAnyAncestorIs(ancestor) {
45
- return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor);
46
- }
47
- whenNoAncestorIs(ancestor) {
48
- return this._bindingWhenSyntax.whenNoAncestorIs(ancestor);
49
- }
50
- whenAnyAncestorNamed(name) {
51
- return this._bindingWhenSyntax.whenAnyAncestorNamed(name);
52
- }
53
- whenAnyAncestorTagged(tag, value) {
54
- return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value);
55
- }
56
- whenNoAncestorNamed(name) {
57
- return this._bindingWhenSyntax.whenNoAncestorNamed(name);
58
- }
59
- whenNoAncestorTagged(tag, value) {
60
- return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value);
61
- }
62
- whenAnyAncestorMatches(constraint) {
63
- return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint);
64
- }
65
- whenNoAncestorMatches(constraint) {
66
- return this._bindingWhenSyntax.whenNoAncestorMatches(constraint);
67
- }
68
- onActivation(handler) {
69
- return this._bindingOnSyntax.onActivation(handler);
70
- }
71
- onDeactivation(handler) {
72
- return this._bindingOnSyntax.onDeactivation(handler);
73
- }
74
- }
75
- exports.BindingInWhenOnSyntax = BindingInWhenOnSyntax;
@@ -1,8 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- declare class BindingOnSyntax<T> implements interfaces.BindingOnSyntax<T> {
3
- private readonly _binding;
4
- constructor(binding: interfaces.Binding<T>);
5
- onActivation(handler: interfaces.BindingActivation<T>): interfaces.BindingWhenSyntax<T>;
6
- onDeactivation(handler: interfaces.BindingDeactivation<T>): interfaces.BindingWhenSyntax<T>;
7
- }
8
- export { BindingOnSyntax };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BindingOnSyntax = void 0;
4
- const binding_when_syntax_1 = require("./binding_when_syntax");
5
- class BindingOnSyntax {
6
- constructor(binding) {
7
- this._binding = binding;
8
- }
9
- onActivation(handler) {
10
- this._binding.onActivation = handler;
11
- return new binding_when_syntax_1.BindingWhenSyntax(this._binding);
12
- }
13
- onDeactivation(handler) {
14
- this._binding.onDeactivation = handler;
15
- return new binding_when_syntax_1.BindingWhenSyntax(this._binding);
16
- }
17
- }
18
- exports.BindingOnSyntax = BindingOnSyntax;
@@ -1,18 +0,0 @@
1
- import { interfaces } from '../interfaces/interfaces';
2
- import { BindingWhenOnSyntax } from './binding_when_on_syntax';
3
- declare class BindingToSyntax<T> implements interfaces.BindingToSyntax<T> {
4
- private readonly _binding;
5
- constructor(binding: interfaces.Binding<T>);
6
- to(constructor: interfaces.Newable<T>): interfaces.BindingInWhenOnSyntax<T>;
7
- toSelf(): interfaces.BindingInWhenOnSyntax<T>;
8
- toConstantValue(value: T): interfaces.BindingWhenOnSyntax<T>;
9
- toDynamicValue(func: interfaces.DynamicValue<T>): interfaces.BindingInWhenOnSyntax<T>;
10
- toConstructor<T2>(constructor: interfaces.Newable<T2>): interfaces.BindingWhenOnSyntax<T>;
11
- toFactory<T2>(factory: interfaces.FactoryCreator<T2>): interfaces.BindingWhenOnSyntax<T>;
12
- toFunction(func: T): interfaces.BindingWhenOnSyntax<T>;
13
- toAutoFactory<T2>(serviceIdentifier: interfaces.ServiceIdentifier<T2>): interfaces.BindingWhenOnSyntax<T>;
14
- toAutoNamedFactory<T2>(serviceIdentifier: interfaces.ServiceIdentifier<T2>): BindingWhenOnSyntax<T>;
15
- toProvider<T2>(provider: interfaces.ProviderCreator<T2>): interfaces.BindingWhenOnSyntax<T>;
16
- toService(service: interfaces.ServiceIdentifier<T>): void;
17
- }
18
- export { BindingToSyntax };