@celljs/core 4.1.0 → 4.3.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 (410) hide show
  1. package/README.md +49 -62
  2. package/esm/browser/static-module.d.ts +1 -1
  3. package/esm/common/annotation/aspect.d.ts +2 -1
  4. package/esm/common/annotation/aspect.js.map +1 -1
  5. package/esm/common/annotation/autowired-provider.d.ts +0 -2
  6. package/esm/common/annotation/autowired-provider.js +4 -13
  7. package/esm/common/annotation/autowired-provider.js.map +1 -1
  8. package/esm/common/annotation/autowired.d.ts +1 -1
  9. package/esm/common/annotation/autowired.js +11 -3
  10. package/esm/common/annotation/autowired.js.map +1 -1
  11. package/esm/common/annotation/component.d.ts +4 -8
  12. package/esm/common/annotation/component.js +0 -6
  13. package/esm/common/annotation/component.js.map +1 -1
  14. package/esm/common/annotation/constant.d.ts +1 -1
  15. package/esm/common/annotation/constant.js +6 -3
  16. package/esm/common/annotation/constant.js.map +1 -1
  17. package/esm/common/annotation/detached/autowired-provider.js +2 -2
  18. package/esm/common/annotation/detached/autowired-provider.js.map +1 -1
  19. package/esm/common/annotation/index.d.ts +0 -6
  20. package/esm/common/annotation/index.js +0 -6
  21. package/esm/common/annotation/index.js.map +1 -1
  22. package/esm/common/annotation/named.d.ts +2 -1
  23. package/esm/common/annotation/named.js +5 -1
  24. package/esm/common/annotation/named.js.map +1 -1
  25. package/esm/common/annotation/optional.d.ts +2 -1
  26. package/esm/common/annotation/optional.js +5 -1
  27. package/esm/common/annotation/optional.js.map +1 -1
  28. package/esm/common/annotation/post-construct.d.ts +2 -1
  29. package/esm/common/annotation/post-construct.js +5 -1
  30. package/esm/common/annotation/post-construct.js.map +1 -1
  31. package/esm/common/annotation/tagged.d.ts +2 -1
  32. package/esm/common/annotation/tagged.js +6 -1
  33. package/esm/common/annotation/tagged.js.map +1 -1
  34. package/esm/common/annotation/value.d.ts +3 -2
  35. package/esm/common/annotation/value.js +7 -10
  36. package/esm/common/annotation/value.js.map +1 -1
  37. package/esm/common/aop/aop-proxy-factory.d.ts +6 -2
  38. package/esm/common/aop/aop-proxy-factory.js +44 -28
  39. package/esm/common/aop/aop-proxy-factory.js.map +1 -1
  40. package/esm/common/aop/class-filter.js +6 -6
  41. package/esm/common/aop/class-filter.js.map +1 -1
  42. package/esm/common/application/application-factory.d.ts +1 -1
  43. package/esm/common/application/application-factory.js +4 -4
  44. package/esm/common/application/application-factory.js.map +1 -1
  45. package/esm/common/container/auto-bind.d.ts +7 -3
  46. package/esm/common/container/auto-bind.js +49 -80
  47. package/esm/common/container/auto-bind.js.map +1 -1
  48. package/esm/common/container/container-error.d.ts +21 -0
  49. package/esm/common/container/container-error.js +22 -0
  50. package/esm/common/container/container-error.js.map +1 -0
  51. package/esm/common/container/container-provider.d.ts +5 -4
  52. package/esm/common/container/container-provider.js +2 -1
  53. package/esm/common/container/container-provider.js.map +1 -1
  54. package/esm/common/container/container-util.d.ts +5 -7
  55. package/esm/common/container/container-util.js +8 -19
  56. package/esm/common/container/container-util.js.map +1 -1
  57. package/esm/common/container/container.d.ts +104 -0
  58. package/esm/common/container/container.js +299 -0
  59. package/esm/common/container/container.js.map +1 -0
  60. package/esm/common/container/dynamic-container.d.ts +1 -1
  61. package/esm/common/container/dynamic-container.js +2 -2
  62. package/esm/common/container/dynamic-container.js.map +1 -1
  63. package/esm/common/container/index.d.ts +5 -6
  64. package/esm/common/container/index.js +5 -3
  65. package/esm/common/container/index.js.map +1 -1
  66. package/esm/common/container/injection.d.ts +40 -0
  67. package/esm/common/container/injection.js +109 -0
  68. package/esm/common/container/injection.js.map +1 -0
  69. package/esm/common/container/scope.d.ts +2 -3
  70. package/esm/common/container/scope.js +2 -3
  71. package/esm/common/container/scope.js.map +1 -1
  72. package/esm/common/el/application-expression-engine.d.ts +7 -0
  73. package/esm/common/{provider/provider-creator.js → el/application-expression-engine.js} +11 -11
  74. package/esm/common/el/application-expression-engine.js.map +1 -0
  75. package/esm/common/el/core-context-initializer.d.ts +3 -2
  76. package/esm/common/el/core-context-initializer.js +10 -8
  77. package/esm/common/el/core-context-initializer.js.map +1 -1
  78. package/esm/common/el/expression-compiler.d.ts +5 -4
  79. package/esm/common/el/expression-compiler.js +7 -6
  80. package/esm/common/el/expression-compiler.js.map +1 -1
  81. package/esm/common/el/expression-engine.d.ts +61 -0
  82. package/esm/common/el/expression-engine.js +459 -0
  83. package/esm/common/el/expression-engine.js.map +1 -0
  84. package/esm/common/el/expression-handler.d.ts +1 -2
  85. package/esm/common/el/expression-handler.js +1 -5
  86. package/esm/common/el/expression-handler.js.map +1 -1
  87. package/esm/common/el/expression-protocol.d.ts +3 -5
  88. package/esm/common/el/expression-protocol.js +0 -1
  89. package/esm/common/el/expression-protocol.js.map +1 -1
  90. package/esm/common/el/expression-util.d.ts +9 -8
  91. package/esm/common/el/expression-util.js +8 -9
  92. package/esm/common/el/expression-util.js.map +1 -1
  93. package/esm/common/el/index.d.ts +2 -1
  94. package/esm/common/el/index.js +2 -1
  95. package/esm/common/el/index.js.map +1 -1
  96. package/esm/common/provider/index.d.ts +0 -1
  97. package/esm/common/provider/index.js +0 -1
  98. package/esm/common/provider/index.js.map +1 -1
  99. package/esm/common/provider/provider-protocol.d.ts +5 -9
  100. package/esm/common/provider/provider-protocol.js +0 -1
  101. package/esm/common/provider/provider-protocol.js.map +1 -1
  102. package/esm/common/provider/provider-util.d.ts +1 -1
  103. package/esm/common/provider/provider-util.js +2 -2
  104. package/esm/common/provider/provider-util.js.map +1 -1
  105. package/esm/common/provider/provider.d.ts +7 -6
  106. package/esm/common/provider/provider.js +15 -26
  107. package/esm/common/provider/provider.js.map +1 -1
  108. package/esm/common/static-module.d.ts +1 -1
  109. package/esm/common/static-module.js +1 -1
  110. package/esm/common/static-module.js.map +1 -1
  111. package/esm/common/test/mock-logger.js +2 -13
  112. package/esm/common/test/mock-logger.js.map +1 -1
  113. package/esm/common/test/test-module.d.ts +1 -1
  114. package/esm/common/test/test-module.js +1 -1
  115. package/esm/common/test/test-module.js.map +1 -1
  116. package/esm/common/utils/annotation-util.js +2 -1
  117. package/esm/common/utils/annotation-util.js.map +1 -1
  118. package/esm/common/utils/proxy-util.d.ts +5 -2
  119. package/esm/common/utils/proxy-util.js +10 -28
  120. package/esm/common/utils/proxy-util.js.map +1 -1
  121. package/esm/node/static-module.d.ts +1 -1
  122. package/lib/browser/static-module.d.ts +1 -1
  123. package/lib/common/annotation/aspect.d.ts +2 -1
  124. package/lib/common/annotation/aspect.d.ts.map +1 -1
  125. package/lib/common/annotation/aspect.js.map +1 -1
  126. package/lib/common/annotation/autowired-provider.d.ts +0 -2
  127. package/lib/common/annotation/autowired-provider.d.ts.map +1 -1
  128. package/lib/common/annotation/autowired-provider.js +4 -14
  129. package/lib/common/annotation/autowired-provider.js.map +1 -1
  130. package/lib/common/annotation/autowired.d.ts +1 -1
  131. package/lib/common/annotation/autowired.d.ts.map +1 -1
  132. package/lib/common/annotation/autowired.js +11 -3
  133. package/lib/common/annotation/autowired.js.map +1 -1
  134. package/lib/common/annotation/component.d.ts +4 -8
  135. package/lib/common/annotation/component.d.ts.map +1 -1
  136. package/lib/common/annotation/component.js +0 -6
  137. package/lib/common/annotation/component.js.map +1 -1
  138. package/lib/common/annotation/constant.d.ts +1 -1
  139. package/lib/common/annotation/constant.d.ts.map +1 -1
  140. package/lib/common/annotation/constant.js +6 -3
  141. package/lib/common/annotation/constant.js.map +1 -1
  142. package/lib/common/annotation/detached/autowired-provider.js +2 -2
  143. package/lib/common/annotation/detached/autowired-provider.js.map +1 -1
  144. package/lib/common/annotation/index.d.ts +0 -6
  145. package/lib/common/annotation/index.d.ts.map +1 -1
  146. package/lib/common/annotation/index.js +0 -6
  147. package/lib/common/annotation/index.js.map +1 -1
  148. package/lib/common/annotation/named.d.ts +2 -1
  149. package/lib/common/annotation/named.d.ts.map +1 -1
  150. package/lib/common/annotation/named.js +6 -2
  151. package/lib/common/annotation/named.js.map +1 -1
  152. package/lib/common/annotation/optional.d.ts +2 -1
  153. package/lib/common/annotation/optional.d.ts.map +1 -1
  154. package/lib/common/annotation/optional.js +6 -2
  155. package/lib/common/annotation/optional.js.map +1 -1
  156. package/lib/common/annotation/post-construct.d.ts +2 -1
  157. package/lib/common/annotation/post-construct.d.ts.map +1 -1
  158. package/lib/common/annotation/post-construct.js +6 -2
  159. package/lib/common/annotation/post-construct.js.map +1 -1
  160. package/lib/common/annotation/tagged.d.ts +2 -1
  161. package/lib/common/annotation/tagged.d.ts.map +1 -1
  162. package/lib/common/annotation/tagged.js +7 -2
  163. package/lib/common/annotation/tagged.js.map +1 -1
  164. package/lib/common/annotation/value.d.ts +3 -2
  165. package/lib/common/annotation/value.d.ts.map +1 -1
  166. package/lib/common/annotation/value.js +7 -10
  167. package/lib/common/annotation/value.js.map +1 -1
  168. package/lib/common/aop/aop-proxy-factory.d.ts +6 -2
  169. package/lib/common/aop/aop-proxy-factory.d.ts.map +1 -1
  170. package/lib/common/aop/aop-proxy-factory.js +45 -29
  171. package/lib/common/aop/aop-proxy-factory.js.map +1 -1
  172. package/lib/common/aop/class-filter.js +7 -7
  173. package/lib/common/aop/class-filter.js.map +1 -1
  174. package/lib/common/application/application-factory.d.ts +1 -1
  175. package/lib/common/application/application-factory.d.ts.map +1 -1
  176. package/lib/common/application/application-factory.js +4 -4
  177. package/lib/common/application/application-factory.js.map +1 -1
  178. package/lib/common/container/assembly.spec.js +11 -11
  179. package/lib/common/container/assembly.spec.js.map +1 -1
  180. package/lib/common/container/auto-bind.d.ts +7 -3
  181. package/lib/common/container/auto-bind.d.ts.map +1 -1
  182. package/lib/common/container/auto-bind.js +49 -81
  183. package/lib/common/container/auto-bind.js.map +1 -1
  184. package/lib/common/container/container-error.d.ts +22 -0
  185. package/lib/common/container/container-error.d.ts.map +1 -0
  186. package/lib/common/container/container-error.js +26 -0
  187. package/lib/common/container/container-error.js.map +1 -0
  188. package/lib/common/container/container-provider.d.ts +5 -4
  189. package/lib/common/container/container-provider.d.ts.map +1 -1
  190. package/lib/common/container/container-provider.js +3 -2
  191. package/lib/common/container/container-provider.js.map +1 -1
  192. package/lib/common/container/container-util.d.ts +5 -7
  193. package/lib/common/container/container-util.d.ts.map +1 -1
  194. package/lib/common/container/container-util.js +8 -19
  195. package/lib/common/container/container-util.js.map +1 -1
  196. package/lib/common/container/container.d.ts +105 -0
  197. package/lib/common/container/container.d.ts.map +1 -0
  198. package/lib/common/container/container.js +305 -0
  199. package/lib/common/container/container.js.map +1 -0
  200. package/lib/common/container/container.spec.d.ts +2 -0
  201. package/lib/common/container/container.spec.d.ts.map +1 -0
  202. package/lib/common/container/container.spec.js +334 -0
  203. package/lib/common/container/container.spec.js.map +1 -0
  204. package/lib/common/container/dynamic-container.d.ts +1 -1
  205. package/lib/common/container/dynamic-container.d.ts.map +1 -1
  206. package/lib/common/container/dynamic-container.js +3 -3
  207. package/lib/common/container/dynamic-container.js.map +1 -1
  208. package/lib/common/container/index.d.ts +5 -6
  209. package/lib/common/container/index.d.ts.map +1 -1
  210. package/lib/common/container/index.js +5 -3
  211. package/lib/common/container/index.js.map +1 -1
  212. package/lib/common/container/injection.d.ts +41 -0
  213. package/lib/common/container/injection.d.ts.map +1 -0
  214. package/lib/common/container/injection.js +112 -0
  215. package/lib/common/container/injection.js.map +1 -0
  216. package/lib/common/container/scope.d.ts +2 -3
  217. package/lib/common/container/scope.d.ts.map +1 -1
  218. package/lib/common/container/scope.js +2 -3
  219. package/lib/common/container/scope.js.map +1 -1
  220. package/lib/common/el/application-expression-engine.d.ts +8 -0
  221. package/lib/common/el/application-expression-engine.d.ts.map +1 -0
  222. package/lib/common/el/application-expression-engine.js +22 -0
  223. package/lib/common/el/application-expression-engine.js.map +1 -0
  224. package/lib/common/el/core-context-initializer.d.ts +3 -2
  225. package/lib/common/el/core-context-initializer.d.ts.map +1 -1
  226. package/lib/common/el/core-context-initializer.js +9 -7
  227. package/lib/common/el/core-context-initializer.js.map +1 -1
  228. package/lib/common/el/expression-compiler.d.ts +5 -4
  229. package/lib/common/el/expression-compiler.d.ts.map +1 -1
  230. package/lib/common/el/expression-compiler.js +6 -5
  231. package/lib/common/el/expression-compiler.js.map +1 -1
  232. package/lib/common/el/expression-engine.d.ts +62 -0
  233. package/lib/common/el/expression-engine.d.ts.map +1 -0
  234. package/lib/common/el/expression-engine.js +465 -0
  235. package/lib/common/el/expression-engine.js.map +1 -0
  236. package/lib/common/el/expression-engine.spec.d.ts +2 -0
  237. package/lib/common/el/expression-engine.spec.d.ts.map +1 -0
  238. package/lib/common/el/expression-engine.spec.js +100 -0
  239. package/lib/common/el/expression-engine.spec.js.map +1 -0
  240. package/lib/common/el/expression-handler.d.ts +1 -2
  241. package/lib/common/el/expression-handler.d.ts.map +1 -1
  242. package/lib/common/el/expression-handler.js +0 -4
  243. package/lib/common/el/expression-handler.js.map +1 -1
  244. package/lib/common/el/expression-handler.spec.js +5 -6
  245. package/lib/common/el/expression-handler.spec.js.map +1 -1
  246. package/lib/common/el/expression-protocol.d.ts +3 -5
  247. package/lib/common/el/expression-protocol.d.ts.map +1 -1
  248. package/lib/common/el/expression-protocol.js +1 -2
  249. package/lib/common/el/expression-protocol.js.map +1 -1
  250. package/lib/common/el/expression-util.d.ts +9 -8
  251. package/lib/common/el/expression-util.d.ts.map +1 -1
  252. package/lib/common/el/expression-util.js +8 -9
  253. package/lib/common/el/expression-util.js.map +1 -1
  254. package/lib/common/el/index.d.ts +2 -1
  255. package/lib/common/el/index.d.ts.map +1 -1
  256. package/lib/common/el/index.js +2 -1
  257. package/lib/common/el/index.js.map +1 -1
  258. package/lib/common/el/value-and-el.spec.js +2 -2
  259. package/lib/common/el/value-and-el.spec.js.map +1 -1
  260. package/lib/common/provider/index.d.ts +0 -1
  261. package/lib/common/provider/index.d.ts.map +1 -1
  262. package/lib/common/provider/index.js +0 -1
  263. package/lib/common/provider/index.js.map +1 -1
  264. package/lib/common/provider/provider-protocol.d.ts +5 -9
  265. package/lib/common/provider/provider-protocol.d.ts.map +1 -1
  266. package/lib/common/provider/provider-protocol.js +1 -2
  267. package/lib/common/provider/provider-protocol.js.map +1 -1
  268. package/lib/common/provider/provider-util.d.ts +1 -1
  269. package/lib/common/provider/provider-util.d.ts.map +1 -1
  270. package/lib/common/provider/provider-util.js +2 -2
  271. package/lib/common/provider/provider-util.js.map +1 -1
  272. package/lib/common/provider/provider.d.ts +7 -6
  273. package/lib/common/provider/provider.d.ts.map +1 -1
  274. package/lib/common/provider/provider.js +16 -26
  275. package/lib/common/provider/provider.js.map +1 -1
  276. package/lib/common/static-module.d.ts +1 -1
  277. package/lib/common/static-module.js +2 -2
  278. package/lib/common/static-module.js.map +1 -1
  279. package/lib/common/test/mock-logger.d.ts.map +1 -1
  280. package/lib/common/test/mock-logger.js +2 -12
  281. package/lib/common/test/mock-logger.js.map +1 -1
  282. package/lib/common/test/test-module.d.ts +1 -1
  283. package/lib/common/test/test-module.d.ts.map +1 -1
  284. package/lib/common/test/test-module.js +2 -2
  285. package/lib/common/test/test-module.js.map +1 -1
  286. package/lib/common/utils/annotation-util.js +2 -1
  287. package/lib/common/utils/annotation-util.js.map +1 -1
  288. package/lib/common/utils/proxy-util.d.ts +5 -2
  289. package/lib/common/utils/proxy-util.d.ts.map +1 -1
  290. package/lib/common/utils/proxy-util.js +12 -30
  291. package/lib/common/utils/proxy-util.js.map +1 -1
  292. package/lib/node/static-module.d.ts +1 -1
  293. package/package.json +4 -6
  294. package/src/common/annotation/aspect.ts +2 -1
  295. package/src/common/annotation/autowired-provider.ts +4 -17
  296. package/src/common/annotation/autowired.ts +14 -6
  297. package/src/common/annotation/component.ts +6 -26
  298. package/src/common/annotation/constant.ts +10 -7
  299. package/src/common/annotation/detached/autowired-provider.ts +2 -2
  300. package/src/common/annotation/index.ts +0 -6
  301. package/src/common/annotation/named.ts +7 -1
  302. package/src/common/annotation/optional.ts +6 -1
  303. package/src/common/annotation/post-construct.ts +6 -1
  304. package/src/common/annotation/tagged.ts +8 -1
  305. package/src/common/annotation/value.ts +9 -11
  306. package/src/common/aop/aop-proxy-factory.ts +52 -30
  307. package/src/common/aop/class-filter.ts +6 -6
  308. package/src/common/application/application-factory.ts +4 -5
  309. package/src/common/container/assembly.spec.ts +7 -12
  310. package/src/common/container/auto-bind.ts +54 -85
  311. package/src/common/container/container-error.ts +31 -0
  312. package/src/common/container/container-provider.ts +9 -7
  313. package/src/common/container/container-util.ts +8 -19
  314. package/src/common/container/container.spec.ts +262 -0
  315. package/src/common/container/container.ts +363 -0
  316. package/src/common/container/dynamic-container.ts +2 -2
  317. package/src/common/container/index.ts +5 -7
  318. package/src/common/container/injection.ts +135 -0
  319. package/src/common/container/scope.ts +2 -1
  320. package/src/common/el/application-expression-engine.ts +9 -0
  321. package/src/common/el/core-context-initializer.ts +9 -8
  322. package/src/common/el/expression-compiler.ts +7 -6
  323. package/src/common/el/expression-engine.spec.ts +107 -0
  324. package/src/common/el/expression-engine.ts +487 -0
  325. package/src/common/el/expression-handler.spec.ts +6 -7
  326. package/src/common/el/expression-handler.ts +2 -5
  327. package/src/common/el/expression-protocol.ts +4 -8
  328. package/src/common/el/expression-util.ts +12 -13
  329. package/src/common/el/index.ts +3 -2
  330. package/src/common/el/value-and-el.spec.ts +2 -2
  331. package/src/common/provider/index.ts +0 -2
  332. package/src/common/provider/provider-protocol.ts +5 -11
  333. package/src/common/provider/provider-util.ts +3 -3
  334. package/src/common/provider/provider.ts +17 -29
  335. package/src/common/static-module.ts +1 -1
  336. package/src/common/test/mock-logger.ts +0 -2
  337. package/src/common/test/test-module.ts +1 -1
  338. package/src/common/utils/annotation-util.ts +2 -2
  339. package/src/common/utils/proxy-util.ts +8 -28
  340. package/esm/common/annotation/decorate.d.ts +0 -1
  341. package/esm/common/annotation/decorate.js +0 -2
  342. package/esm/common/annotation/decorate.js.map +0 -1
  343. package/esm/common/annotation/inject.d.ts +0 -1
  344. package/esm/common/annotation/inject.js +0 -2
  345. package/esm/common/annotation/inject.js.map +0 -1
  346. package/esm/common/annotation/injectable.d.ts +0 -1
  347. package/esm/common/annotation/injectable.js +0 -2
  348. package/esm/common/annotation/injectable.js.map +0 -1
  349. package/esm/common/annotation/pre-destroy.d.ts +0 -1
  350. package/esm/common/annotation/pre-destroy.js +0 -2
  351. package/esm/common/annotation/pre-destroy.js.map +0 -1
  352. package/esm/common/annotation/target-name.d.ts +0 -1
  353. package/esm/common/annotation/target-name.js +0 -2
  354. package/esm/common/annotation/target-name.js.map +0 -1
  355. package/esm/common/annotation/unmanaged.d.ts +0 -1
  356. package/esm/common/annotation/unmanaged.js +0 -2
  357. package/esm/common/annotation/unmanaged.js.map +0 -1
  358. package/esm/common/container/container-factory.d.ts +0 -4
  359. package/esm/common/container/container-factory.js +0 -9
  360. package/esm/common/container/container-factory.js.map +0 -1
  361. package/esm/common/el/jexl-engine-provider.d.ts +0 -5
  362. package/esm/common/el/jexl-engine-provider.js +0 -22
  363. package/esm/common/el/jexl-engine-provider.js.map +0 -1
  364. package/esm/common/provider/provider-creator.d.ts +0 -6
  365. package/esm/common/provider/provider-creator.js.map +0 -1
  366. package/lib/common/annotation/decorate.d.ts +0 -2
  367. package/lib/common/annotation/decorate.d.ts.map +0 -1
  368. package/lib/common/annotation/decorate.js +0 -6
  369. package/lib/common/annotation/decorate.js.map +0 -1
  370. package/lib/common/annotation/inject.d.ts +0 -2
  371. package/lib/common/annotation/inject.d.ts.map +0 -1
  372. package/lib/common/annotation/inject.js +0 -6
  373. package/lib/common/annotation/inject.js.map +0 -1
  374. package/lib/common/annotation/injectable.d.ts +0 -2
  375. package/lib/common/annotation/injectable.d.ts.map +0 -1
  376. package/lib/common/annotation/injectable.js +0 -6
  377. package/lib/common/annotation/injectable.js.map +0 -1
  378. package/lib/common/annotation/pre-destroy.d.ts +0 -2
  379. package/lib/common/annotation/pre-destroy.d.ts.map +0 -1
  380. package/lib/common/annotation/pre-destroy.js +0 -6
  381. package/lib/common/annotation/pre-destroy.js.map +0 -1
  382. package/lib/common/annotation/target-name.d.ts +0 -2
  383. package/lib/common/annotation/target-name.d.ts.map +0 -1
  384. package/lib/common/annotation/target-name.js +0 -6
  385. package/lib/common/annotation/target-name.js.map +0 -1
  386. package/lib/common/annotation/unmanaged.d.ts +0 -2
  387. package/lib/common/annotation/unmanaged.d.ts.map +0 -1
  388. package/lib/common/annotation/unmanaged.js +0 -6
  389. package/lib/common/annotation/unmanaged.js.map +0 -1
  390. package/lib/common/container/container-factory.d.ts +0 -5
  391. package/lib/common/container/container-factory.d.ts.map +0 -1
  392. package/lib/common/container/container-factory.js +0 -13
  393. package/lib/common/container/container-factory.js.map +0 -1
  394. package/lib/common/el/jexl-engine-provider.d.ts +0 -6
  395. package/lib/common/el/jexl-engine-provider.d.ts.map +0 -1
  396. package/lib/common/el/jexl-engine-provider.js +0 -25
  397. package/lib/common/el/jexl-engine-provider.js.map +0 -1
  398. package/lib/common/provider/provider-creator.d.ts +0 -7
  399. package/lib/common/provider/provider-creator.d.ts.map +0 -1
  400. package/lib/common/provider/provider-creator.js +0 -22
  401. package/lib/common/provider/provider-creator.js.map +0 -1
  402. package/src/common/annotation/decorate.ts +0 -1
  403. package/src/common/annotation/inject.ts +0 -1
  404. package/src/common/annotation/injectable.ts +0 -1
  405. package/src/common/annotation/pre-destroy.ts +0 -1
  406. package/src/common/annotation/target-name.ts +0 -1
  407. package/src/common/annotation/unmanaged.ts +0 -1
  408. package/src/common/container/container-factory.ts +0 -9
  409. package/src/common/el/jexl-engine-provider.ts +0 -18
  410. package/src/common/provider/provider-creator.ts +0 -12
@@ -0,0 +1,262 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { Container, ContainerModule } from './container';
4
+ import { ContainerError } from './container-error';
5
+ import { Autowired, Named, Optional, PostConstruct, Tagged, Value, VALUE } from '../annotation';
6
+ import { Scope } from './scope';
7
+
8
+ /**
9
+ * The container on its own: bindings, constraints, injection by the decorators and its errors.
10
+ * The decorators only describe classes, so every test binds what it needs by hand.
11
+ */
12
+ function errorOf(fn: () => unknown): ContainerError {
13
+ try {
14
+ fn();
15
+ } catch (error) {
16
+ expect(error).to.be.instanceOf(ContainerError);
17
+ return error as ContainerError;
18
+ }
19
+ throw new Error('expected a ContainerError');
20
+ }
21
+
22
+ describe('Container', () => {
23
+
24
+ it('binds a class, a constant, a factory and an alias; transient unless told otherwise', () => {
25
+ class A { }
26
+ const Value1 = Symbol('Value1');
27
+ const Made = Symbol('Made');
28
+ const Alias = Symbol('Alias');
29
+ const c = new Container();
30
+ c.bind(A).to(A);
31
+ c.bind(Value1).toConstantValue(42);
32
+ let made = 0;
33
+ c.bind(Made).toDynamicValue(() => ++made).inSingletonScope();
34
+ c.bind(Alias).toService(Value1);
35
+ expect(c.get(A)).to.be.instanceOf(A);
36
+ expect(c.get(A)).not.to.equal(c.get(A));
37
+ expect(c.get(Value1)).to.equal(42);
38
+ expect([c.get(Made), c.get(Made)]).to.deep.equal([1, 1]);
39
+ expect(c.get(Alias)).to.equal(42);
40
+ });
41
+
42
+ it('loads modules: bind, unbind, isBound and rebind', () => {
43
+ const Id = Symbol('Id');
44
+ const c = new Container(new ContainerModule((bind, unbind, isBound, rebind) => {
45
+ bind(Id).toConstantValue('a');
46
+ expect(isBound(Id)).to.equal(true);
47
+ rebind(Id).toConstantValue('b');
48
+ }));
49
+ expect(c.getAll(Id)).to.deep.equal(['b']);
50
+ c.unbind(Id);
51
+ expect(c.isBound(Id)).to.equal(false);
52
+ });
53
+
54
+ it('selects bindings by name and tag; unconstrained bindings match any query, default ones only plain requests', () => {
55
+ const Store = Symbol('Store');
56
+ const c = new Container();
57
+ c.bind(Store).toConstantValue('redis').whenTargetNamed('redis');
58
+ c.bind(Store).toConstantValue('eu').whenTargetTagged('region', 'eu');
59
+ c.bind(Store).toConstantValue('memory').whenTargetIsDefault();
60
+ expect(c.get(Store)).to.equal('memory');
61
+ expect(c.get(Store, { name: 'redis' })).to.equal('redis');
62
+ expect(c.get(Store, { tags: { region: 'eu' } })).to.equal('eu');
63
+ expect(c.isBound(Store, { name: 'mongo' })).to.equal(false);
64
+ // Without a query, getAll and isBound take every binding, whatever its constraint.
65
+ expect(c.getAll(Store)).to.deep.equal(['redis', 'eu', 'memory']);
66
+ expect(c.isBound(Store)).to.equal(true);
67
+ c.bind(Store).toConstantValue('any');
68
+ expect(c.getAll(Store, { name: 'redis' })).to.deep.equal(['redis', 'any']);
69
+ });
70
+
71
+ it('injects constructor parameters, properties and @Value, then calls @PostConstruct once', () => {
72
+ const Clock = Symbol('Clock');
73
+ const calls: string[] = [];
74
+ class Service {
75
+ @Autowired(Clock)
76
+ readonly clock: number;
77
+ @Value('answer')
78
+ readonly answer: number;
79
+ constructor(@Autowired(Clock) readonly first: number) { }
80
+ @PostConstruct()
81
+ protected init() {
82
+ calls.push(`init ${this.first} ${this.clock} ${this.answer}`);
83
+ }
84
+ }
85
+ const c = new Container();
86
+ c.bind(Clock).toConstantValue(7);
87
+ c.bind(VALUE).toDynamicValue(({ target }) => target.name === 'answer' ? 42 : undefined);
88
+ c.bind(Service).to(Service).inSingletonScope();
89
+ c.get(Service);
90
+ c.get(Service);
91
+ expect(calls).to.deep.equal(['init 7 7 42']);
92
+ });
93
+
94
+ it('takes constructor parameters without @Autowired from their declared class', () => {
95
+ class Dep { }
96
+ class Uses {
97
+ constructor(readonly dep: Dep) { }
98
+ }
99
+ Reflect.defineMetadata('design:paramtypes', [Dep], Uses);
100
+ const c = new Container();
101
+ c.bind(Dep).to(Dep).inSingletonScope();
102
+ c.bind(Uses).to(Uses);
103
+ expect(c.get(Uses).dep).to.equal(c.get(Dep));
104
+ });
105
+
106
+ it('subclasses inherit injected properties, @PostConstruct and the constructor of their parent', () => {
107
+ const Dep = Symbol('Dep');
108
+ class Base {
109
+ @Autowired(Dep)
110
+ readonly fromBase: string;
111
+ constructor(@Autowired(Dep) readonly fromConstructor: string) { }
112
+ initialized = false;
113
+ @PostConstruct()
114
+ protected init() {
115
+ this.initialized = true;
116
+ }
117
+ }
118
+ class Derived extends Base {
119
+ @Autowired(Dep) @Named('other')
120
+ readonly own: string;
121
+ }
122
+ const c = new Container();
123
+ c.bind(Dep).toConstantValue('plain').whenTargetIsDefault();
124
+ c.bind(Dep).toConstantValue('other').whenTargetNamed('other');
125
+ c.bind(Derived).to(Derived);
126
+ const d = c.get(Derived);
127
+ expect([d.fromBase, d.fromConstructor, d.own, d.initialized]).to.deep.equal(['plain', 'plain', 'other', true]);
128
+ });
129
+
130
+ it('@Optional: undefined or [] when nothing is bound; an optional property keeps its initial value', () => {
131
+ const Missing = Symbol('Missing');
132
+ class Tolerant {
133
+ @Autowired(Missing) @Optional()
134
+ readonly one?: string = 'initial';
135
+ @Autowired({ id: Missing, multi: true }) @Optional()
136
+ readonly many: string[];
137
+ constructor(@Autowired(Missing) @Optional() readonly param = 'default') { }
138
+ }
139
+ const c = new Container();
140
+ c.bind(Tolerant).to(Tolerant);
141
+ const t = c.get(Tolerant);
142
+ expect([t.one, t.many, t.param]).to.deep.equal(['initial', [], 'default']);
143
+ });
144
+
145
+ it('@Tagged on an injection point', () => {
146
+ const Store = Symbol('TaggedStore');
147
+ class Consumer {
148
+ @Autowired(Store) @Tagged('region', 'eu')
149
+ readonly store: string;
150
+ }
151
+ const c = new Container();
152
+ c.bind(Store).toConstantValue('us').whenTargetTagged('region', 'us');
153
+ c.bind(Store).toConstantValue('eu').whenTargetTagged('region', 'eu');
154
+ c.bind(Consumer).to(Consumer);
155
+ expect(c.get(Consumer).store).to.equal('eu');
156
+ });
157
+
158
+ it('gives factories and activation handlers the injection point', () => {
159
+ const Logger = Symbol('Logger');
160
+ class Owner {
161
+ @Autowired(Logger)
162
+ readonly logger: string;
163
+ }
164
+ const c = new Container();
165
+ c.bind(Logger).toDynamicValue(({ target }) => `logger of ${target.owner?.name}.${String(target.key)}`);
166
+ c.bind(Owner).to(Owner).onActivation((context, instance) => Object.assign(instance, { activated: context.target.id === Owner }));
167
+ const o = c.get(Owner) as Owner & { activated: boolean };
168
+ expect(o.logger).to.equal('logger of Owner.logger');
169
+ expect(o.activated).to.equal(true);
170
+ });
171
+
172
+ it('lists its bindings for tools', () => {
173
+ class A { }
174
+ const Named1 = Symbol('Named1');
175
+ const c = new Container();
176
+ c.bind(A).to(A).inSingletonScope();
177
+ c.bind(Named1).toService(A).whenTargetNamed('x');
178
+ const rows = [...c.bindings()].flatMap(([id, bindings]) => bindings.map(b => [Container.idName(id), b.type, b.scope, b.condition]));
179
+ expect(rows).to.deep.equal([['A', 'class', Scope.Singleton, undefined], ['Symbol(Named1)', 'service', Scope.Transient, 'named x']]);
180
+ });
181
+
182
+ describe('errors', () => {
183
+
184
+ it('CELL_DI_NO_BINDING names the identifier, who needs it and the chain', () => {
185
+ const Mailer = Symbol('Mailer');
186
+ class Signup {
187
+ @Autowired(Mailer)
188
+ readonly mailer: unknown;
189
+ }
190
+ class Controller {
191
+ constructor(@Autowired(Signup) readonly signup: Signup) { }
192
+ }
193
+ const c = new Container();
194
+ c.bind(Signup).to(Signup);
195
+ c.bind(Controller).to(Controller);
196
+ const error = errorOf(() => c.get(Controller));
197
+ expect(error.code).to.equal('CELL_DI_NO_BINDING');
198
+ expect(error.message).to.equal('No binding for Symbol(Mailer), needed by Signup.mailer (Controller → Signup → Symbol(Mailer)).');
199
+ expect(error.path).to.deep.equal(['Controller', 'Signup', 'Symbol(Mailer)']);
200
+ expect(error.hint).to.contain('@Optional()');
201
+ });
202
+
203
+ it('CELL_DI_NO_BINDING lists the bindings that do not match, or a second identifier with the same name', () => {
204
+ const Store = Symbol('Store');
205
+ const c = new Container();
206
+ c.bind(Store).toConstantValue('redis').whenTargetNamed('redis');
207
+ expect(errorOf(() => c.get(Store, { name: 'mongo' })).message)
208
+ .to.equal('No binding for Symbol(Store) named mongo. The bindings of Symbol(Store) do not match: constant [named redis].');
209
+ c.bind(Symbol('Twin')).toConstantValue(1);
210
+ expect(errorOf(() => c.get(Symbol('Twin'))).message).to.contain('two copies of the module that declares it are loaded');
211
+ });
212
+
213
+ it('CELL_DI_AMBIGUOUS lists the candidates', () => {
214
+ const Plugin = Symbol('Plugin');
215
+ class P1 { }
216
+ class P2 { }
217
+ const c = new Container();
218
+ c.bind(Plugin).to(P1);
219
+ c.bind(Plugin).to(P2);
220
+ const error = errorOf(() => c.get(Plugin));
221
+ expect(error.code).to.equal('CELL_DI_AMBIGUOUS');
222
+ expect(error.message).to.equal('2 bindings match Symbol(Plugin): P1, P2.');
223
+ expect(c.getAll(Plugin)).to.have.length(2);
224
+ });
225
+
226
+ it('CELL_DI_CIRCULAR shows the cycle, and the container still works afterwards', () => {
227
+ class A {
228
+ @Autowired({ id: 'B' })
229
+ readonly b: unknown;
230
+ }
231
+ class B {
232
+ constructor(@Autowired(A) readonly a: A) { }
233
+ }
234
+ const c = new Container();
235
+ c.bind(A).to(A).inSingletonScope();
236
+ c.bind('B').to(B).inSingletonScope();
237
+ const error = errorOf(() => c.get(A));
238
+ expect(error.code).to.equal('CELL_DI_CIRCULAR');
239
+ expect(error.message).to.equal('Circular dependency: A → B → A.');
240
+ c.rebind('B').toConstantValue('b');
241
+ expect(c.get(A).b).to.equal('b');
242
+ });
243
+
244
+ it('CELL_DI_MISSING_INJECT for a parameter that names no identifier', () => {
245
+ class NoId {
246
+ constructor(readonly options: object) { }
247
+ }
248
+ Reflect.defineMetadata('design:paramtypes', [Object], NoId);
249
+ const c = new Container();
250
+ c.bind(NoId).to(NoId);
251
+ const error = errorOf(() => c.get(NoId));
252
+ expect(error.code).to.equal('CELL_DI_MISSING_INJECT');
253
+ expect(error.message).to.contain('NoId constructor parameter #0');
254
+ });
255
+
256
+ it('CELL_DI_INCOMPLETE_BINDING for bind() without a target', () => {
257
+ const c = new Container();
258
+ c.bind('nothing');
259
+ expect(errorOf(() => c.get('nothing')).code).to.equal('CELL_DI_INCOMPLETE_BINDING');
260
+ });
261
+ });
262
+ });
@@ -0,0 +1,363 @@
1
+ import type { Abstract, Newable } from '../utils/types';
2
+ import { ContainerError } from './container-error';
3
+ import { InjectionTarget, InjectionUtil } from './injection';
4
+ import { Scope } from './scope';
5
+
6
+ /** What identifies a component: a class, or a symbol or string that stands for an interface. */
7
+ export type ComponentId<T = any> = string | symbol | Newable<T> | Abstract<T>;
8
+
9
+ /** What a dynamic value, a service alias or an activation handler gets. */
10
+ export interface ResolveContext {
11
+ readonly container: Container;
12
+ /** What is being resolved; with `owner` and `key` when it is injected into a class. */
13
+ readonly target: InjectionTarget;
14
+ }
15
+
16
+ /** Selects a binding among those of an identifier: `{ name }` for `@Named`, `{ tags }` for `@Tagged`. */
17
+ export interface BindingQuery {
18
+ name?: string | number | symbol;
19
+ tags?: Record<string | number | symbol, unknown>;
20
+ }
21
+
22
+ export type BindingConstraint = (target: InjectionTarget) => boolean;
23
+
24
+ export type ActivationHandler<T = any> = (context: ResolveContext, instance: T) => T;
25
+
26
+ /** How an identifier is resolved: a class, a constant, a factory or another identifier. */
27
+ export class Binding<T = any> {
28
+ type?: 'class' | 'constant' | 'factory' | 'service';
29
+ implementation?: Newable<T>;
30
+ factory?: (context: ResolveContext) => T;
31
+ /** The identifier a `service` binding resolves to. */
32
+ service?: ComponentId;
33
+ scope = Scope.Transient;
34
+ constraint?: BindingConstraint;
35
+ /** The constraint for people and tools: `named redis`, `tagged region=eu`, `default`. */
36
+ condition?: string;
37
+ activation?: ActivationHandler<T>;
38
+ /** Singletons and constants once created. */
39
+ resolved = false;
40
+ value?: T;
41
+
42
+ constructor(readonly id: ComponentId<T>) { }
43
+
44
+ to(implementation: Newable<T>): this {
45
+ this.type = 'class';
46
+ this.implementation = implementation;
47
+ return this;
48
+ }
49
+
50
+ toConstantValue(value: T): this {
51
+ this.type = 'constant';
52
+ this.value = value;
53
+ this.resolved = true;
54
+ this.scope = Scope.Singleton;
55
+ return this;
56
+ }
57
+
58
+ toDynamicValue(factory: (context: ResolveContext) => T): this {
59
+ this.type = 'factory';
60
+ this.factory = factory;
61
+ return this;
62
+ }
63
+
64
+ /** Resolves another identifier: an alias, the same instance when that one is a singleton. */
65
+ toService(id: ComponentId<T>): this {
66
+ this.type = 'service';
67
+ this.service = id;
68
+ this.factory = context => context.container.get(id);
69
+ return this;
70
+ }
71
+
72
+ inSingletonScope(): this {
73
+ this.scope = Scope.Singleton;
74
+ return this;
75
+ }
76
+
77
+ inTransientScope(): this {
78
+ this.scope = Scope.Transient;
79
+ return this;
80
+ }
81
+
82
+ when(constraint: BindingConstraint, condition = 'when'): this {
83
+ this.constraint = constraint;
84
+ this.condition = condition;
85
+ return this;
86
+ }
87
+
88
+ whenTargetNamed(name: string | number | symbol): this {
89
+ return this.when(target => target.name === name, `named ${String(name)}`);
90
+ }
91
+
92
+ whenTargetTagged(key: string | number | symbol, value: unknown): this {
93
+ return this.when(target => target.tags !== undefined && target.tags[key] === value, `tagged ${String(key)}=${String(value)}`);
94
+ }
95
+
96
+ /** Only where nothing is asked for by name or tag. */
97
+ whenTargetIsDefault(): this {
98
+ return this.when(target => target.name === undefined && target.tags === undefined, 'default');
99
+ }
100
+
101
+ /** Called with each new instance (once for singletons); returns the instance to use, e.g. a proxy. */
102
+ onActivation(handler: ActivationHandler<T>): this {
103
+ this.activation = handler;
104
+ return this;
105
+ }
106
+ }
107
+
108
+ export type ContainerModuleRegistry = (
109
+ bind: <T>(id: ComponentId<T>) => Binding<T>,
110
+ unbind: (id: ComponentId) => void,
111
+ isBound: (id: ComponentId, query?: BindingQuery) => boolean,
112
+ rebind: <T>(id: ComponentId<T>) => Binding<T>
113
+ ) => void;
114
+
115
+ /** A set of bindings that {@link Container.load} adds; what a DI module file exports by default. */
116
+ export class ContainerModule {
117
+ constructor(readonly registry: ContainerModuleRegistry) { }
118
+ }
119
+
120
+ const EMPTY: readonly Binding[] = [];
121
+
122
+ /**
123
+ * The dependency injection container: bindings by identifier, resolved synchronously. Classes get their
124
+ * constructor parameters and properties from the decorators (`@Autowired`, `@Value`, `@Optional`,
125
+ * `@Named`, `@Tagged`) and `@PostConstruct` is called once they are injected.
126
+ */
127
+ export class Container {
128
+ protected readonly map = new Map<ComponentId, Binding[]>();
129
+ /** The bindings being resolved and what asked for them, outermost first; for cycles and error messages. */
130
+ protected readonly resolving: Binding[] = [];
131
+ protected readonly requests: InjectionTarget[] = [];
132
+
133
+ constructor(...modules: ContainerModule[]) {
134
+ this.load(...modules);
135
+ }
136
+
137
+ load(...modules: ContainerModule[]): void {
138
+ const bind = <T>(id: ComponentId<T>) => this.bind(id);
139
+ const unbind = (id: ComponentId) => this.unbind(id);
140
+ const isBound = (id: ComponentId, query?: BindingQuery) => this.isBound(id, query);
141
+ const rebind = <T>(id: ComponentId<T>) => this.rebind(id);
142
+ for (const module of modules) {
143
+ module.registry(bind, unbind, isBound, rebind);
144
+ }
145
+ }
146
+
147
+ bind<T>(id: ComponentId<T>): Binding<T> {
148
+ const binding = new Binding<T>(id);
149
+ const bindings = this.map.get(id);
150
+ if (bindings) {
151
+ bindings.push(binding);
152
+ } else {
153
+ this.map.set(id, [binding]);
154
+ }
155
+ return binding;
156
+ }
157
+
158
+ /** Replaces the bindings of the identifier. */
159
+ rebind<T>(id: ComponentId<T>): Binding<T> {
160
+ this.unbind(id);
161
+ return this.bind(id);
162
+ }
163
+
164
+ unbind(id: ComponentId): void {
165
+ this.map.delete(id);
166
+ }
167
+
168
+ /** Whether the identifier has a binding; with a query, one that matches it. */
169
+ isBound(id: ComponentId, query?: BindingQuery): boolean {
170
+ return query ? this.matching({ ...query, id }).length > 0 : this.map.has(id);
171
+ }
172
+
173
+ /** The one binding of the identifier that matches the query; throws when there is none or more than one. */
174
+ get<T>(id: ComponentId<T>, query?: BindingQuery): T {
175
+ return this.resolve(query ? { ...query, id } : { id });
176
+ }
177
+
178
+ /**
179
+ * Every binding of the identifier, whatever its constraint; with a query, the ones that match it.
180
+ * Throws when there is none.
181
+ */
182
+ getAll<T>(id: ComponentId<T>, query?: BindingQuery): T[] {
183
+ return this.resolveAll(query ? { ...query, id } : { id }, !query);
184
+ }
185
+
186
+ /** Resolves an injection point: one instance, all of them (`multi`), or none when it is `optional`. */
187
+ resolve<T>(target: InjectionTarget): T {
188
+ if (target.multi) {
189
+ return this.resolveAll(target) as T;
190
+ }
191
+ const bindings = this.matching(target);
192
+ if (bindings.length === 1) {
193
+ return this.instance(bindings[0], target);
194
+ }
195
+ if (bindings.length === 0 && target.optional) {
196
+ return undefined as T;
197
+ }
198
+ throw bindings.length === 0 ? this.noBinding(target) : this.ambiguous(target, bindings);
199
+ }
200
+
201
+ /** Every binding by identifier, in the order they were bound; for tools (`cell check`, the dev MCP endpoint). */
202
+ bindings(): ReadonlyMap<ComponentId, readonly Binding[]> {
203
+ return this.map;
204
+ }
205
+
206
+ protected resolveAll<T>(target: InjectionTarget, unconstrained = false): T[] {
207
+ const bindings = unconstrained ? this.map.get(target.id) ?? EMPTY : this.matching(target);
208
+ if (bindings.length === 0 && !target.optional) {
209
+ throw this.noBinding(target);
210
+ }
211
+ const instances = new Array<T>(bindings.length);
212
+ for (let i = 0; i < bindings.length; i++) {
213
+ instances[i] = this.instance(bindings[i], target);
214
+ }
215
+ return instances;
216
+ }
217
+
218
+ protected matching(target: InjectionTarget): readonly Binding[] {
219
+ const bindings = this.map.get(target.id);
220
+ if (!bindings) {
221
+ return EMPTY;
222
+ }
223
+ for (const binding of bindings) {
224
+ if (binding.constraint && !binding.constraint(target)) {
225
+ return bindings.filter(b => !b.constraint || b.constraint(target));
226
+ }
227
+ }
228
+ return bindings;
229
+ }
230
+
231
+ protected instance<T>(binding: Binding<T>, target: InjectionTarget): T {
232
+ if (binding.resolved) {
233
+ return binding.value as T;
234
+ }
235
+ if (this.resolving.includes(binding)) {
236
+ throw this.circular(target);
237
+ }
238
+ this.resolving.push(binding);
239
+ this.requests.push(target);
240
+ try {
241
+ const context: ResolveContext = { container: this, target };
242
+ let value: T;
243
+ if (binding.type === 'class') {
244
+ value = this.construct(binding.implementation!);
245
+ } else if (binding.factory) {
246
+ value = binding.factory(context);
247
+ } else {
248
+ throw new ContainerError({
249
+ code: 'CELL_DI_INCOMPLETE_BINDING',
250
+ message: `The binding of ${Container.idName(binding.id)} says nothing to resolve it to.`,
251
+ hint: 'Complete bind(id) with .to(Class), .toConstantValue(value), .toDynamicValue(factory) or .toService(id).',
252
+ path: this.path()
253
+ });
254
+ }
255
+ if (binding.activation) {
256
+ value = binding.activation(context, value);
257
+ }
258
+ if (binding.scope === Scope.Singleton) {
259
+ binding.value = value;
260
+ binding.resolved = true;
261
+ }
262
+ return value;
263
+ } finally {
264
+ this.resolving.pop();
265
+ this.requests.pop();
266
+ }
267
+ }
268
+
269
+ protected construct<T>(type: Newable<T>): T {
270
+ const plan = InjectionUtil.plan(type);
271
+ const parameters = plan.parameters;
272
+ const args = new Array(parameters.length);
273
+ for (let i = 0; i < parameters.length; i++) {
274
+ args[i] = this.resolve(parameters[i]);
275
+ }
276
+ const instance: any = new type(...args);
277
+ for (const property of plan.properties) {
278
+ const value = this.resolve(property);
279
+ // Like a default parameter: an optional property that nothing is bound to keeps its initial value.
280
+ if (value !== undefined || !property.optional) {
281
+ instance[property.key!] = value;
282
+ }
283
+ }
284
+ if (plan.postConstruct !== undefined) {
285
+ instance[plan.postConstruct]();
286
+ }
287
+ return instance;
288
+ }
289
+
290
+ /** The identifiers being resolved, outermost first, then the one of `target`. */
291
+ protected path(target?: InjectionTarget): string[] {
292
+ const path = this.requests.map(request => Container.idName(request.id));
293
+ return target ? [...path, Container.idName(target.id)] : path;
294
+ }
295
+
296
+ protected neededBy(target: InjectionTarget): string {
297
+ return target.owner ? `, needed by ${InjectionUtil.describe(target)}` : '';
298
+ }
299
+
300
+ protected noBinding(target: InjectionTarget): ContainerError {
301
+ const path = this.path(target);
302
+ const name = Container.idName(target.id);
303
+ const bound = this.map.get(target.id) ?? [];
304
+ let candidates = '';
305
+ if (bound.length > 0) {
306
+ candidates = ` The bindings of ${name} do not match: ${bound.map(Container.describe).join(', ')}.`;
307
+ } else if ([...this.map.keys()].some(id => id !== target.id && Container.idName(id) === name)) {
308
+ candidates = ` Another identifier is also named ${name}: two copies of the module that declares it are loaded.`;
309
+ }
310
+ return new ContainerError({
311
+ code: 'CELL_DI_NO_BINDING',
312
+ message: `No binding for ${Container.describe({ id: target.id, ...Container.query(target) })}${this.neededBy(target)}${Container.chain(path)}.${candidates}`,
313
+ hint: 'Bind the identifier in a DI module (@Component(<id>) in a file the module imports), or mark the injection @Optional().',
314
+ path
315
+ });
316
+ }
317
+
318
+ protected ambiguous(target: InjectionTarget, bindings: readonly Binding[]): ContainerError {
319
+ const path = this.path(target);
320
+ return new ContainerError({
321
+ code: 'CELL_DI_AMBIGUOUS',
322
+ message: `${bindings.length} bindings match ${Container.idName(target.id)}${this.neededBy(target)}${Container.chain(path)}: ${bindings.map(Container.describe).join(', ')}.`,
323
+ hint: 'Inject all of them with @Autowired on an array, give one rebind: true to replace the others, or select one with @Named / @Tagged.',
324
+ path
325
+ });
326
+ }
327
+
328
+ protected circular(target: InjectionTarget): ContainerError {
329
+ const path = this.path(target);
330
+ return new ContainerError({
331
+ code: 'CELL_DI_CIRCULAR',
332
+ message: `Circular dependency: ${path.join(' → ')}.`,
333
+ hint: 'Break the cycle: get one side lazily (a Provider, or @Autowired({ detached: true }) on a property), or move the shared part into another component.',
334
+ path
335
+ });
336
+ }
337
+
338
+ protected static chain(path: string[]): string {
339
+ return path.length > 1 ? ` (${path.join(' → ')})` : '';
340
+ }
341
+
342
+ protected static query(target: InjectionTarget): BindingQuery {
343
+ return { name: target.name, tags: target.tags };
344
+ }
345
+
346
+ /** `RedisStore [named redis]`, `Symbol(Store) named redis`. */
347
+ static describe(binding: Binding | (BindingQuery & { id: ComponentId })): string {
348
+ if (binding instanceof Binding) {
349
+ const what = binding.type === 'class' ? binding.implementation!.name || '(anonymous class)'
350
+ : binding.type === 'service' ? `→ ${Container.idName(binding.service)}` : (binding.type ?? 'incomplete');
351
+ return binding.condition ? `${what} [${binding.condition}]` : what;
352
+ }
353
+ const tags = binding.tags ? Reflect.ownKeys(binding.tags).map(key => ` tagged ${String(key)}=${String(binding.tags![key])}`).join('') : '';
354
+ return `${Container.idName(binding.id)}${binding.name !== undefined ? ` named ${String(binding.name)}` : ''}${tags}`;
355
+ }
356
+
357
+ static idName(id: unknown): string {
358
+ if (typeof id === 'function') {
359
+ return id.name || '(anonymous class)';
360
+ }
361
+ return String(id);
362
+ }
363
+ }
@@ -1,4 +1,4 @@
1
- import { Container } from 'inversify';
1
+ import { Container } from './container';
2
2
 
3
- // dynamic loading component module at compile time
3
+ // The toolchain replaces this file with the DI modules of the application (@celljs/vite ContainerGenerator).
4
4
  export const container: Promise<Container> = Promise.resolve(new Container());
@@ -1,9 +1,7 @@
1
- export * from './container-provider';
1
+ export * from './container';
2
+ export * from './container-error';
3
+ export * from './injection';
4
+ export * from './scope';
2
5
  export * from './auto-bind';
6
+ export * from './container-provider';
3
7
  export * from './container-util';
4
- export * from './scope';
5
- export * from './container-factory';
6
- import { interfaces } from 'inversify';
7
- export type Container = interfaces.Container;
8
- export type ContainerModule = interfaces.ContainerModule;
9
-