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,219 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- var desc = Object.getOwnPropertyDescriptor(m, k);
15
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
- desc = { enumerable: true, get: function() { return m[k]; } };
17
- }
18
- Object.defineProperty(o, k2, desc);
19
- }) : (function(o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- }));
23
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
- Object.defineProperty(o, "default", { enumerable: true, value: v });
25
- }) : function(o, v) {
26
- o["default"] = v;
27
- });
28
- var __importStar = (this && this.__importStar) || function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
- if (ar || !(i in from)) {
74
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
- ar[i] = from[i];
76
- }
77
- }
78
- return to.concat(ar || Array.prototype.slice.call(from));
79
- };
80
- define(["require", "exports", "../constants/error_msgs", "../constants/literal_types", "../constants/metadata_keys", "../utils/async"], function (require, exports, error_msgs_1, literal_types_1, METADATA_KEY, async_1) {
81
- "use strict";
82
- Object.defineProperty(exports, "__esModule", { value: true });
83
- exports.resolveInstance = resolveInstance;
84
- METADATA_KEY = __importStar(METADATA_KEY);
85
- function _resolveRequests(childRequests, resolveRequest) {
86
- return childRequests.reduce(function (resolvedRequests, childRequest) {
87
- var injection = resolveRequest(childRequest);
88
- var targetType = childRequest.target.type;
89
- if (targetType === literal_types_1.TargetTypeEnum.ConstructorArgument) {
90
- resolvedRequests.constructorInjections.push(injection);
91
- }
92
- else {
93
- resolvedRequests.propertyRequests.push(childRequest);
94
- resolvedRequests.propertyInjections.push(injection);
95
- }
96
- if (!resolvedRequests.isAsync) {
97
- resolvedRequests.isAsync = (0, async_1.isPromiseOrContainsPromise)(injection);
98
- }
99
- return resolvedRequests;
100
- }, {
101
- constructorInjections: [],
102
- isAsync: false,
103
- propertyInjections: [],
104
- propertyRequests: [],
105
- });
106
- }
107
- function _createInstance(constr, childRequests, resolveRequest) {
108
- var result;
109
- if (childRequests.length > 0) {
110
- var resolved = _resolveRequests(childRequests, resolveRequest);
111
- var createInstanceWithInjectionsArg = __assign(__assign({}, resolved), { constr: constr });
112
- if (resolved.isAsync) {
113
- result = createInstanceWithInjectionsAsync(createInstanceWithInjectionsArg);
114
- }
115
- else {
116
- result = createInstanceWithInjections(createInstanceWithInjectionsArg);
117
- }
118
- }
119
- else {
120
- result = new constr();
121
- }
122
- return result;
123
- }
124
- function createInstanceWithInjections(args) {
125
- var _a;
126
- var instance = new ((_a = args.constr).bind.apply(_a, __spreadArray([void 0], args.constructorInjections, false)))();
127
- args.propertyRequests.forEach(function (r, index) {
128
- var property = r.target.identifier;
129
- var injection = args.propertyInjections[index];
130
- if (!r.target.isOptional() || injection !== undefined) {
131
- instance[property] = injection;
132
- }
133
- });
134
- return instance;
135
- }
136
- function createInstanceWithInjectionsAsync(args) {
137
- return __awaiter(this, void 0, void 0, function () {
138
- var constructorInjections, propertyInjections;
139
- return __generator(this, function (_a) {
140
- switch (_a.label) {
141
- case 0: return [4, possiblyWaitInjections(args.constructorInjections)];
142
- case 1:
143
- constructorInjections = _a.sent();
144
- return [4, possiblyWaitInjections(args.propertyInjections)];
145
- case 2:
146
- propertyInjections = _a.sent();
147
- return [2, createInstanceWithInjections(__assign(__assign({}, args), { constructorInjections: constructorInjections, propertyInjections: propertyInjections }))];
148
- }
149
- });
150
- });
151
- }
152
- function possiblyWaitInjections(possiblePromiseinjections) {
153
- return __awaiter(this, void 0, void 0, function () {
154
- var injections, _i, possiblePromiseinjections_1, injection;
155
- return __generator(this, function (_a) {
156
- injections = [];
157
- for (_i = 0, possiblePromiseinjections_1 = possiblePromiseinjections; _i < possiblePromiseinjections_1.length; _i++) {
158
- injection = possiblePromiseinjections_1[_i];
159
- if (Array.isArray(injection)) {
160
- injections.push(Promise.all(injection));
161
- }
162
- else {
163
- injections.push(injection);
164
- }
165
- }
166
- return [2, Promise.all(injections)];
167
- });
168
- });
169
- }
170
- function _getInstanceAfterPostConstruct(constr, result) {
171
- var postConstructResult = _postConstruct(constr, result);
172
- if ((0, async_1.isPromise)(postConstructResult)) {
173
- return postConstructResult.then(function () { return result; });
174
- }
175
- else {
176
- return result;
177
- }
178
- }
179
- function _postConstruct(constr, instance) {
180
- var _a, _b;
181
- if (Reflect.hasMetadata(METADATA_KEY.POST_CONSTRUCT, constr)) {
182
- var data = Reflect.getMetadata(METADATA_KEY.POST_CONSTRUCT, constr);
183
- try {
184
- return (_b = (_a = instance)[data.value]) === null || _b === void 0 ? void 0 : _b.call(_a);
185
- }
186
- catch (e) {
187
- if (e instanceof Error) {
188
- throw new Error((0, error_msgs_1.POST_CONSTRUCT_ERROR)(constr.name, e.message));
189
- }
190
- }
191
- }
192
- }
193
- function _validateInstanceResolution(binding, constr) {
194
- if (binding.scope !== literal_types_1.BindingScopeEnum.Singleton) {
195
- _throwIfHandlingDeactivation(binding, constr);
196
- }
197
- }
198
- function _throwIfHandlingDeactivation(binding, constr) {
199
- var scopeErrorMessage = "Class cannot be instantiated in ".concat(binding.scope === literal_types_1.BindingScopeEnum.Request ? 'request' : 'transient', " scope.");
200
- if (typeof binding.onDeactivation === 'function') {
201
- throw new Error((0, error_msgs_1.ON_DEACTIVATION_ERROR)(constr.name, scopeErrorMessage));
202
- }
203
- if (Reflect.hasMetadata(METADATA_KEY.PRE_DESTROY, constr)) {
204
- throw new Error((0, error_msgs_1.PRE_DESTROY_ERROR)(constr.name, scopeErrorMessage));
205
- }
206
- }
207
- function resolveInstance(binding, constr, childRequests, resolveRequest) {
208
- _validateInstanceResolution(binding, constr);
209
- var result = _createInstance(constr, childRequests, resolveRequest);
210
- if ((0, async_1.isPromise)(result)) {
211
- return result.then(function (resolvedResult) {
212
- return _getInstanceAfterPostConstruct(constr, resolvedResult);
213
- });
214
- }
215
- else {
216
- return _getInstanceAfterPostConstruct(constr, result);
217
- }
218
- }
219
- });
@@ -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,234 +0,0 @@
1
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
- if (k2 === undefined) k2 = k;
3
- var desc = Object.getOwnPropertyDescriptor(m, k);
4
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
- desc = { enumerable: true, get: function() { return m[k]; } };
6
- }
7
- Object.defineProperty(o, k2, desc);
8
- }) : (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- o[k2] = m[k];
11
- }));
12
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
- Object.defineProperty(o, "default", { enumerable: true, value: v });
14
- }) : function(o, v) {
15
- o["default"] = v;
16
- });
17
- var __importStar = (this && this.__importStar) || function (mod) {
18
- if (mod && mod.__esModule) return mod;
19
- var result = {};
20
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
- __setModuleDefault(result, mod);
22
- return result;
23
- };
24
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- var __generator = (this && this.__generator) || function (thisArg, body) {
34
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
35
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
36
- function verb(n) { return function (v) { return step([n, v]); }; }
37
- function step(op) {
38
- if (f) throw new TypeError("Generator is already executing.");
39
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
41
- if (y = 0, t) op = [op[0] & 2, t.value];
42
- switch (op[0]) {
43
- case 0: case 1: t = op; break;
44
- case 4: _.label++; return { value: op[1], done: false };
45
- case 5: _.label++; y = op[1]; op = [0]; continue;
46
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
47
- default:
48
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
49
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
50
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
51
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
52
- if (t[2]) _.ops.pop();
53
- _.trys.pop(); continue;
54
- }
55
- op = body.call(thisArg, _);
56
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
57
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
58
- }
59
- };
60
- define(["require", "exports", "../constants/error_msgs", "../constants/literal_types", "../planning/planner", "../scope/scope", "../utils/async", "../utils/binding_utils", "../utils/exceptions", "./instantiation"], function (require, exports, ERROR_MSGS, literal_types_1, planner_1, scope_1, async_1, binding_utils_1, exceptions_1, instantiation_1) {
61
- "use strict";
62
- Object.defineProperty(exports, "__esModule", { value: true });
63
- exports.resolve = resolve;
64
- ERROR_MSGS = __importStar(ERROR_MSGS);
65
- var _resolveRequest = function (requestScope) {
66
- return function (request) {
67
- request.parentContext.setCurrentRequest(request);
68
- var bindings = request.bindings;
69
- var childRequests = request.childRequests;
70
- var targetIsAnArray = request.target && request.target.isArray();
71
- var targetParentIsNotAnArray = !request.parentRequest ||
72
- !request.parentRequest.target ||
73
- !request.target ||
74
- !request.parentRequest.target.matchesArray(request.target.serviceIdentifier);
75
- if (targetIsAnArray && targetParentIsNotAnArray) {
76
- return childRequests.map(function (childRequest) {
77
- var resolveRequest = _resolveRequest(requestScope);
78
- return resolveRequest(childRequest);
79
- });
80
- }
81
- else {
82
- if (request.target.isOptional() && bindings.length === 0) {
83
- return undefined;
84
- }
85
- var binding = bindings[0];
86
- return _resolveBinding(requestScope, request, binding);
87
- }
88
- };
89
- };
90
- var _resolveFactoryFromBinding = function (binding, context) {
91
- var factoryDetails = (0, binding_utils_1.getFactoryDetails)(binding);
92
- return (0, exceptions_1.tryAndThrowErrorIfStackOverflow)(function () {
93
- return factoryDetails.factory.bind(binding)(context);
94
- }, function () {
95
- return new Error(ERROR_MSGS.CIRCULAR_DEPENDENCY_IN_FACTORY(factoryDetails.factoryType, context.currentRequest.serviceIdentifier.toString()));
96
- });
97
- };
98
- var _getResolvedFromBinding = function (requestScope, request, binding) {
99
- var result;
100
- var childRequests = request.childRequests;
101
- (0, binding_utils_1.ensureFullyBound)(binding);
102
- switch (binding.type) {
103
- case literal_types_1.BindingTypeEnum.ConstantValue:
104
- case literal_types_1.BindingTypeEnum.Function:
105
- result = binding.cache;
106
- break;
107
- case literal_types_1.BindingTypeEnum.Constructor:
108
- result = binding.implementationType;
109
- break;
110
- case literal_types_1.BindingTypeEnum.Instance:
111
- result = (0, instantiation_1.resolveInstance)(binding, binding.implementationType, childRequests, _resolveRequest(requestScope));
112
- break;
113
- default:
114
- result = _resolveFactoryFromBinding(binding, request.parentContext);
115
- }
116
- return result;
117
- };
118
- var _resolveInScope = function (requestScope, binding, resolveFromBinding) {
119
- var result = (0, scope_1.tryGetFromScope)(requestScope, binding);
120
- if (result !== null) {
121
- return result;
122
- }
123
- result = resolveFromBinding();
124
- (0, scope_1.saveToScope)(requestScope, binding, result);
125
- return result;
126
- };
127
- var _resolveBinding = function (requestScope, request, binding) {
128
- return _resolveInScope(requestScope, binding, function () {
129
- var result = _getResolvedFromBinding(requestScope, request, binding);
130
- if ((0, async_1.isPromise)(result)) {
131
- result = result.then(function (resolved) {
132
- return _onActivation(request, binding, resolved);
133
- });
134
- }
135
- else {
136
- result = _onActivation(request, binding, result);
137
- }
138
- return result;
139
- });
140
- };
141
- function _onActivation(request, binding, resolved) {
142
- var result = _bindingActivation(request.parentContext, binding, resolved);
143
- var containersIterator = _getContainersIterator(request.parentContext.container);
144
- var container;
145
- var containersIteratorResult = containersIterator.next();
146
- do {
147
- container = containersIteratorResult.value;
148
- var context_1 = request.parentContext;
149
- var serviceIdentifier = request.serviceIdentifier;
150
- var activationsIterator = _getContainerActivationsForService(container, serviceIdentifier);
151
- if ((0, async_1.isPromise)(result)) {
152
- result = _activateContainerAsync(activationsIterator, context_1, result);
153
- }
154
- else {
155
- result = _activateContainer(activationsIterator, context_1, result);
156
- }
157
- containersIteratorResult = containersIterator.next();
158
- } while (containersIteratorResult.done !== true &&
159
- !(0, planner_1.getBindingDictionary)(container).hasKey(request.serviceIdentifier));
160
- return result;
161
- }
162
- var _bindingActivation = function (context, binding, previousResult) {
163
- var result;
164
- if (typeof binding.onActivation === 'function') {
165
- result = binding.onActivation(context, previousResult);
166
- }
167
- else {
168
- result = previousResult;
169
- }
170
- return result;
171
- };
172
- var _activateContainer = function (activationsIterator, context, result) {
173
- var activation = activationsIterator.next();
174
- while (activation.done !== true) {
175
- result = activation.value(context, result);
176
- if ((0, async_1.isPromise)(result)) {
177
- return _activateContainerAsync(activationsIterator, context, result);
178
- }
179
- activation = activationsIterator.next();
180
- }
181
- return result;
182
- };
183
- var _activateContainerAsync = function (activationsIterator, context, resultPromise) { return __awaiter(void 0, void 0, void 0, function () {
184
- var result, activation;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0: return [4, resultPromise];
188
- case 1:
189
- result = _a.sent();
190
- activation = activationsIterator.next();
191
- _a.label = 2;
192
- case 2:
193
- if (!(activation.done !== true)) return [3, 4];
194
- return [4, activation.value(context, result)];
195
- case 3:
196
- result = _a.sent();
197
- activation = activationsIterator.next();
198
- return [3, 2];
199
- case 4: return [2, result];
200
- }
201
- });
202
- }); };
203
- var _getContainerActivationsForService = function (container, serviceIdentifier) {
204
- var activations = container._activations;
205
- return activations.hasKey(serviceIdentifier)
206
- ? activations.get(serviceIdentifier).values()
207
- : [].values();
208
- };
209
- var _getContainersIterator = function (container) {
210
- var containersStack = [container];
211
- var parent = container.parent;
212
- while (parent !== null) {
213
- containersStack.push(parent);
214
- parent = parent.parent;
215
- }
216
- var getNextContainer = function () {
217
- var nextContainer = containersStack.pop();
218
- if (nextContainer !== undefined) {
219
- return { done: false, value: nextContainer };
220
- }
221
- else {
222
- return { done: true, value: undefined };
223
- }
224
- };
225
- var containersIterator = {
226
- next: getNextContainer,
227
- };
228
- return containersIterator;
229
- };
230
- function resolve(context) {
231
- var resolveRequestFunction = _resolveRequest(context.plan.rootRequest.requestScope);
232
- return resolveRequestFunction(context.plan.rootRequest);
233
- }
234
- });
@@ -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,93 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- define(["require", "exports", "../constants/literal_types", "../utils/async"], function (require, exports, literal_types_1, async_1) {
38
- "use strict";
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.saveToScope = exports.tryGetFromScope = void 0;
41
- var tryGetFromScope = function (requestScope, binding) {
42
- if (binding.scope === literal_types_1.BindingScopeEnum.Singleton && binding.activated) {
43
- return binding.cache;
44
- }
45
- if (binding.scope === literal_types_1.BindingScopeEnum.Request &&
46
- requestScope.has(binding.id)) {
47
- return requestScope.get(binding.id);
48
- }
49
- return null;
50
- };
51
- exports.tryGetFromScope = tryGetFromScope;
52
- var saveToScope = function (requestScope, binding, result) {
53
- if (binding.scope === literal_types_1.BindingScopeEnum.Singleton) {
54
- _saveToSingletonScope(binding, result);
55
- }
56
- if (binding.scope === literal_types_1.BindingScopeEnum.Request) {
57
- _saveToRequestScope(requestScope, binding, result);
58
- }
59
- };
60
- exports.saveToScope = saveToScope;
61
- var _saveToRequestScope = function (requestScope, binding, result) {
62
- if (!requestScope.has(binding.id)) {
63
- requestScope.set(binding.id, result);
64
- }
65
- };
66
- var _saveToSingletonScope = function (binding, result) {
67
- binding.cache = result;
68
- binding.activated = true;
69
- if ((0, async_1.isPromise)(result)) {
70
- void _saveAsyncResultToSingletonScope(binding, result);
71
- }
72
- };
73
- var _saveAsyncResultToSingletonScope = function (binding, asyncResult) { return __awaiter(void 0, void 0, void 0, function () {
74
- var result, ex_1;
75
- return __generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0:
78
- _a.trys.push([0, 2, , 3]);
79
- return [4, asyncResult];
80
- case 1:
81
- result = _a.sent();
82
- binding.cache = result;
83
- return [3, 3];
84
- case 2:
85
- ex_1 = _a.sent();
86
- binding.cache = null;
87
- binding.activated = false;
88
- throw ex_1;
89
- case 3: return [2];
90
- }
91
- });
92
- }); };
93
- });
@@ -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,24 +0,0 @@
1
- define(["require", "exports", "../constants/literal_types", "./binding_when_on_syntax"], function (require, exports, literal_types_1, binding_when_on_syntax_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BindingInSyntax = void 0;
5
- var BindingInSyntax = (function () {
6
- function BindingInSyntax(binding) {
7
- this._binding = binding;
8
- }
9
- BindingInSyntax.prototype.inRequestScope = function () {
10
- this._binding.scope = literal_types_1.BindingScopeEnum.Request;
11
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
12
- };
13
- BindingInSyntax.prototype.inSingletonScope = function () {
14
- this._binding.scope = literal_types_1.BindingScopeEnum.Singleton;
15
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
16
- };
17
- BindingInSyntax.prototype.inTransientScope = function () {
18
- this._binding.scope = literal_types_1.BindingScopeEnum.Transient;
19
- return new binding_when_on_syntax_1.BindingWhenOnSyntax(this._binding);
20
- };
21
- return BindingInSyntax;
22
- }());
23
- exports.BindingInSyntax = BindingInSyntax;
24
- });
@@ -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 };