@celljs/core 4.0.0 → 4.2.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 (529) hide show
  1. package/README.md +49 -68
  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/application/application-protocol.js +1 -1
  46. package/esm/common/application/application-protocol.js.map +1 -1
  47. package/esm/common/config/config-provider.js +2 -1
  48. package/esm/common/config/config-provider.js.map +1 -1
  49. package/esm/common/container/auto-bind.d.ts +7 -3
  50. package/esm/common/container/auto-bind.js +54 -71
  51. package/esm/common/container/auto-bind.js.map +1 -1
  52. package/esm/common/container/container-error.d.ts +21 -0
  53. package/esm/common/container/container-error.js +22 -0
  54. package/esm/common/container/container-error.js.map +1 -0
  55. package/esm/common/container/container-provider.d.ts +5 -4
  56. package/esm/common/container/container-provider.js +2 -1
  57. package/esm/common/container/container-provider.js.map +1 -1
  58. package/esm/common/container/container-util.d.ts +5 -7
  59. package/esm/common/container/container-util.js +8 -19
  60. package/esm/common/container/container-util.js.map +1 -1
  61. package/esm/common/container/container.d.ts +104 -0
  62. package/esm/common/container/container.js +299 -0
  63. package/esm/common/container/container.js.map +1 -0
  64. package/esm/common/container/dynamic-container.d.ts +1 -1
  65. package/esm/common/container/dynamic-container.js +2 -2
  66. package/esm/common/container/dynamic-container.js.map +1 -1
  67. package/esm/common/container/index.d.ts +5 -6
  68. package/esm/common/container/index.js +5 -3
  69. package/esm/common/container/index.js.map +1 -1
  70. package/esm/common/container/injection.d.ts +40 -0
  71. package/esm/common/container/injection.js +109 -0
  72. package/esm/common/container/injection.js.map +1 -0
  73. package/esm/common/container/scope.d.ts +2 -3
  74. package/esm/common/container/scope.js +2 -3
  75. package/esm/common/container/scope.js.map +1 -1
  76. package/esm/common/el/application-expression-engine.d.ts +7 -0
  77. package/esm/common/{provider/provider-creator.js → el/application-expression-engine.js} +11 -11
  78. package/esm/common/el/application-expression-engine.js.map +1 -0
  79. package/esm/common/el/core-context-initializer.d.ts +3 -2
  80. package/esm/common/el/core-context-initializer.js +10 -8
  81. package/esm/common/el/core-context-initializer.js.map +1 -1
  82. package/esm/common/el/expression-compiler.d.ts +7 -17
  83. package/esm/common/el/expression-compiler.js +10 -166
  84. package/esm/common/el/expression-compiler.js.map +1 -1
  85. package/esm/common/el/expression-engine.d.ts +61 -0
  86. package/esm/common/el/expression-engine.js +459 -0
  87. package/esm/common/el/expression-engine.js.map +1 -0
  88. package/esm/common/el/expression-handler.d.ts +8 -4
  89. package/esm/common/el/expression-handler.js +15 -58
  90. package/esm/common/el/expression-handler.js.map +1 -1
  91. package/esm/common/el/expression-protocol.d.ts +3 -5
  92. package/esm/common/el/expression-protocol.js +0 -1
  93. package/esm/common/el/expression-protocol.js.map +1 -1
  94. package/esm/common/el/expression-util.d.ts +69 -0
  95. package/esm/common/el/expression-util.js +346 -0
  96. package/esm/common/el/expression-util.js.map +1 -0
  97. package/esm/common/el/index.d.ts +3 -1
  98. package/esm/common/el/index.js +3 -1
  99. package/esm/common/el/index.js.map +1 -1
  100. package/esm/common/logger/abstract-logger.d.ts +4 -2
  101. package/esm/common/logger/abstract-logger.js +11 -6
  102. package/esm/common/logger/abstract-logger.js.map +1 -1
  103. package/esm/common/logger/logger-protocol.d.ts +4 -0
  104. package/esm/common/logger/logger-protocol.js +2 -0
  105. package/esm/common/logger/logger-protocol.js.map +1 -1
  106. package/esm/common/logger/logger.js +7 -7
  107. package/esm/common/logger/logger.js.map +1 -1
  108. package/esm/common/provider/index.d.ts +0 -1
  109. package/esm/common/provider/index.js +0 -1
  110. package/esm/common/provider/index.js.map +1 -1
  111. package/esm/common/provider/provider-protocol.d.ts +5 -9
  112. package/esm/common/provider/provider-protocol.js +0 -1
  113. package/esm/common/provider/provider-protocol.js.map +1 -1
  114. package/esm/common/provider/provider-util.d.ts +1 -1
  115. package/esm/common/provider/provider-util.js +2 -2
  116. package/esm/common/provider/provider-util.js.map +1 -1
  117. package/esm/common/provider/provider.d.ts +7 -6
  118. package/esm/common/provider/provider.js +15 -26
  119. package/esm/common/provider/provider.js.map +1 -1
  120. package/esm/common/static-module.d.ts +1 -1
  121. package/esm/common/static-module.js +1 -1
  122. package/esm/common/static-module.js.map +1 -1
  123. package/esm/common/test/mock-logger.d.ts +1 -0
  124. package/esm/common/test/mock-logger.js +5 -13
  125. package/esm/common/test/mock-logger.js.map +1 -1
  126. package/esm/common/test/test-module.d.ts +1 -1
  127. package/esm/common/test/test-module.js +1 -1
  128. package/esm/common/test/test-module.js.map +1 -1
  129. package/esm/common/utils/annotation-util.js +2 -1
  130. package/esm/common/utils/annotation-util.js.map +1 -1
  131. package/esm/common/utils/emitter.d.ts +1 -10
  132. package/esm/common/utils/emitter.js +0 -56
  133. package/esm/common/utils/emitter.js.map +1 -1
  134. package/esm/common/utils/mime-type-util.js +1 -1
  135. package/esm/common/utils/mime-type-util.js.map +1 -1
  136. package/esm/common/utils/mime-type.js +1 -1
  137. package/esm/common/utils/mime-type.js.map +1 -1
  138. package/esm/common/utils/proxy-util.d.ts +5 -2
  139. package/esm/common/utils/proxy-util.js +10 -28
  140. package/esm/common/utils/proxy-util.js.map +1 -1
  141. package/esm/node/context/context.d.ts +11 -2
  142. package/esm/node/context/context.js +36 -12
  143. package/esm/node/context/context.js.map +1 -1
  144. package/esm/node/index.d.ts +0 -1
  145. package/esm/node/index.js +0 -1
  146. package/esm/node/index.js.map +1 -1
  147. package/esm/node/static-module.d.ts +1 -1
  148. package/lib/browser/static-module.d.ts +1 -1
  149. package/lib/common/annotation/aspect.d.ts +2 -1
  150. package/lib/common/annotation/aspect.d.ts.map +1 -1
  151. package/lib/common/annotation/aspect.js.map +1 -1
  152. package/lib/common/annotation/autowired-provider.d.ts +0 -2
  153. package/lib/common/annotation/autowired-provider.d.ts.map +1 -1
  154. package/lib/common/annotation/autowired-provider.js +4 -14
  155. package/lib/common/annotation/autowired-provider.js.map +1 -1
  156. package/lib/common/annotation/autowired.d.ts +1 -1
  157. package/lib/common/annotation/autowired.d.ts.map +1 -1
  158. package/lib/common/annotation/autowired.js +11 -3
  159. package/lib/common/annotation/autowired.js.map +1 -1
  160. package/lib/common/annotation/component.d.ts +4 -8
  161. package/lib/common/annotation/component.d.ts.map +1 -1
  162. package/lib/common/annotation/component.js +0 -6
  163. package/lib/common/annotation/component.js.map +1 -1
  164. package/lib/common/annotation/constant.d.ts +1 -1
  165. package/lib/common/annotation/constant.d.ts.map +1 -1
  166. package/lib/common/annotation/constant.js +6 -3
  167. package/lib/common/annotation/constant.js.map +1 -1
  168. package/lib/common/annotation/detached/autowired-provider.js +2 -2
  169. package/lib/common/annotation/detached/autowired-provider.js.map +1 -1
  170. package/lib/common/annotation/index.d.ts +0 -6
  171. package/lib/common/annotation/index.d.ts.map +1 -1
  172. package/lib/common/annotation/index.js +0 -6
  173. package/lib/common/annotation/index.js.map +1 -1
  174. package/lib/common/annotation/named.d.ts +2 -1
  175. package/lib/common/annotation/named.d.ts.map +1 -1
  176. package/lib/common/annotation/named.js +6 -2
  177. package/lib/common/annotation/named.js.map +1 -1
  178. package/lib/common/annotation/optional.d.ts +2 -1
  179. package/lib/common/annotation/optional.d.ts.map +1 -1
  180. package/lib/common/annotation/optional.js +6 -2
  181. package/lib/common/annotation/optional.js.map +1 -1
  182. package/lib/common/annotation/post-construct.d.ts +2 -1
  183. package/lib/common/annotation/post-construct.d.ts.map +1 -1
  184. package/lib/common/annotation/post-construct.js +6 -2
  185. package/lib/common/annotation/post-construct.js.map +1 -1
  186. package/lib/common/annotation/tagged.d.ts +2 -1
  187. package/lib/common/annotation/tagged.d.ts.map +1 -1
  188. package/lib/common/annotation/tagged.js +7 -2
  189. package/lib/common/annotation/tagged.js.map +1 -1
  190. package/lib/common/annotation/value.d.ts +3 -2
  191. package/lib/common/annotation/value.d.ts.map +1 -1
  192. package/lib/common/annotation/value.js +7 -10
  193. package/lib/common/annotation/value.js.map +1 -1
  194. package/lib/common/aop/aop-proxy-factory.d.ts +6 -2
  195. package/lib/common/aop/aop-proxy-factory.d.ts.map +1 -1
  196. package/lib/common/aop/aop-proxy-factory.js +45 -29
  197. package/lib/common/aop/aop-proxy-factory.js.map +1 -1
  198. package/lib/common/aop/aop.spec.d.ts +2 -0
  199. package/lib/common/aop/aop.spec.d.ts.map +1 -0
  200. package/lib/common/aop/aop.spec.js +170 -0
  201. package/lib/common/aop/aop.spec.js.map +1 -0
  202. package/lib/common/aop/class-filter.js +7 -7
  203. package/lib/common/aop/class-filter.js.map +1 -1
  204. package/lib/common/application/application-factory.d.ts +1 -1
  205. package/lib/common/application/application-factory.d.ts.map +1 -1
  206. package/lib/common/application/application-factory.js +4 -4
  207. package/lib/common/application/application-factory.js.map +1 -1
  208. package/lib/common/application/application-protocol.js +1 -1
  209. package/lib/common/application/application-protocol.js.map +1 -1
  210. package/lib/common/application/lifecycle.spec.d.ts +2 -0
  211. package/lib/common/application/lifecycle.spec.d.ts.map +1 -0
  212. package/lib/common/application/lifecycle.spec.js +155 -0
  213. package/lib/common/application/lifecycle.spec.js.map +1 -0
  214. package/lib/common/config/config-provider.js +2 -1
  215. package/lib/common/config/config-provider.js.map +1 -1
  216. package/lib/common/container/assembly.spec.d.ts +2 -0
  217. package/lib/common/container/assembly.spec.d.ts.map +1 -0
  218. package/lib/common/container/assembly.spec.js +464 -0
  219. package/lib/common/container/assembly.spec.js.map +1 -0
  220. package/lib/common/container/auto-bind.d.ts +7 -3
  221. package/lib/common/container/auto-bind.d.ts.map +1 -1
  222. package/lib/common/container/auto-bind.js +54 -72
  223. package/lib/common/container/auto-bind.js.map +1 -1
  224. package/lib/common/container/container-error.d.ts +22 -0
  225. package/lib/common/container/container-error.d.ts.map +1 -0
  226. package/lib/common/container/container-error.js +26 -0
  227. package/lib/common/container/container-error.js.map +1 -0
  228. package/lib/common/container/container-provider.d.ts +5 -4
  229. package/lib/common/container/container-provider.d.ts.map +1 -1
  230. package/lib/common/container/container-provider.js +3 -2
  231. package/lib/common/container/container-provider.js.map +1 -1
  232. package/lib/common/container/container-util.d.ts +5 -7
  233. package/lib/common/container/container-util.d.ts.map +1 -1
  234. package/lib/common/container/container-util.js +8 -19
  235. package/lib/common/container/container-util.js.map +1 -1
  236. package/lib/common/container/container.d.ts +105 -0
  237. package/lib/common/container/container.d.ts.map +1 -0
  238. package/lib/common/container/container.js +305 -0
  239. package/lib/common/container/container.js.map +1 -0
  240. package/lib/common/container/container.spec.d.ts +2 -0
  241. package/lib/common/container/container.spec.d.ts.map +1 -0
  242. package/lib/common/container/container.spec.js +334 -0
  243. package/lib/common/container/container.spec.js.map +1 -0
  244. package/lib/common/container/dynamic-container.d.ts +1 -1
  245. package/lib/common/container/dynamic-container.d.ts.map +1 -1
  246. package/lib/common/container/dynamic-container.js +3 -3
  247. package/lib/common/container/dynamic-container.js.map +1 -1
  248. package/lib/common/container/index.d.ts +5 -6
  249. package/lib/common/container/index.d.ts.map +1 -1
  250. package/lib/common/container/index.js +5 -3
  251. package/lib/common/container/index.js.map +1 -1
  252. package/lib/common/container/injection.d.ts +41 -0
  253. package/lib/common/container/injection.d.ts.map +1 -0
  254. package/lib/common/container/injection.js +112 -0
  255. package/lib/common/container/injection.js.map +1 -0
  256. package/lib/common/container/scope.d.ts +2 -3
  257. package/lib/common/container/scope.d.ts.map +1 -1
  258. package/lib/common/container/scope.js +2 -3
  259. package/lib/common/container/scope.js.map +1 -1
  260. package/lib/common/el/application-expression-engine.d.ts +8 -0
  261. package/lib/common/el/application-expression-engine.d.ts.map +1 -0
  262. package/lib/common/el/application-expression-engine.js +22 -0
  263. package/lib/common/el/application-expression-engine.js.map +1 -0
  264. package/lib/common/el/core-context-initializer.d.ts +3 -2
  265. package/lib/common/el/core-context-initializer.d.ts.map +1 -1
  266. package/lib/common/el/core-context-initializer.js +9 -7
  267. package/lib/common/el/core-context-initializer.js.map +1 -1
  268. package/lib/common/el/expression-compiler.d.ts +7 -17
  269. package/lib/common/el/expression-compiler.d.ts.map +1 -1
  270. package/lib/common/el/expression-compiler.js +10 -166
  271. package/lib/common/el/expression-compiler.js.map +1 -1
  272. package/lib/common/el/expression-engine.d.ts +62 -0
  273. package/lib/common/el/expression-engine.d.ts.map +1 -0
  274. package/lib/common/el/expression-engine.js +465 -0
  275. package/lib/common/el/expression-engine.js.map +1 -0
  276. package/lib/common/el/expression-engine.spec.d.ts +2 -0
  277. package/lib/common/el/expression-engine.spec.d.ts.map +1 -0
  278. package/lib/common/el/expression-engine.spec.js +100 -0
  279. package/lib/common/el/expression-engine.spec.js.map +1 -0
  280. package/lib/common/el/expression-handler.d.ts +8 -4
  281. package/lib/common/el/expression-handler.d.ts.map +1 -1
  282. package/lib/common/el/expression-handler.js +14 -60
  283. package/lib/common/el/expression-handler.js.map +1 -1
  284. package/lib/common/el/expression-handler.spec.d.ts +2 -0
  285. package/lib/common/el/expression-handler.spec.d.ts.map +1 -0
  286. package/lib/common/el/expression-handler.spec.js +98 -0
  287. package/lib/common/el/expression-handler.spec.js.map +1 -0
  288. package/lib/common/el/expression-protocol.d.ts +3 -5
  289. package/lib/common/el/expression-protocol.d.ts.map +1 -1
  290. package/lib/common/el/expression-protocol.js +1 -2
  291. package/lib/common/el/expression-protocol.js.map +1 -1
  292. package/lib/common/el/expression-util.d.ts +70 -0
  293. package/lib/common/el/expression-util.d.ts.map +1 -0
  294. package/lib/common/el/expression-util.js +351 -0
  295. package/lib/common/el/expression-util.js.map +1 -0
  296. package/lib/common/el/expression-util.spec.d.ts +2 -0
  297. package/lib/common/el/expression-util.spec.d.ts.map +1 -0
  298. package/lib/common/el/expression-util.spec.js +45 -0
  299. package/lib/common/el/expression-util.spec.js.map +1 -0
  300. package/lib/common/el/index.d.ts +3 -1
  301. package/lib/common/el/index.d.ts.map +1 -1
  302. package/lib/common/el/index.js +3 -1
  303. package/lib/common/el/index.js.map +1 -1
  304. package/lib/common/el/value-and-el.spec.d.ts +2 -0
  305. package/lib/common/el/value-and-el.spec.d.ts.map +1 -0
  306. package/lib/common/el/value-and-el.spec.js +216 -0
  307. package/lib/common/el/value-and-el.spec.js.map +1 -0
  308. package/lib/common/logger/abstract-logger.d.ts +4 -2
  309. package/lib/common/logger/abstract-logger.d.ts.map +1 -1
  310. package/lib/common/logger/abstract-logger.js +10 -5
  311. package/lib/common/logger/abstract-logger.js.map +1 -1
  312. package/lib/common/logger/logger-protocol.d.ts +4 -0
  313. package/lib/common/logger/logger-protocol.d.ts.map +1 -1
  314. package/lib/common/logger/logger-protocol.js +3 -1
  315. package/lib/common/logger/logger-protocol.js.map +1 -1
  316. package/lib/common/logger/logger.js +7 -7
  317. package/lib/common/logger/logger.js.map +1 -1
  318. package/lib/common/logger/logger.spec.d.ts +2 -0
  319. package/lib/common/logger/logger.spec.d.ts.map +1 -0
  320. package/lib/common/logger/logger.spec.js +57 -0
  321. package/lib/common/logger/logger.spec.js.map +1 -0
  322. package/lib/common/provider/index.d.ts +0 -1
  323. package/lib/common/provider/index.d.ts.map +1 -1
  324. package/lib/common/provider/index.js +0 -1
  325. package/lib/common/provider/index.js.map +1 -1
  326. package/lib/common/provider/provider-protocol.d.ts +5 -9
  327. package/lib/common/provider/provider-protocol.d.ts.map +1 -1
  328. package/lib/common/provider/provider-protocol.js +1 -2
  329. package/lib/common/provider/provider-protocol.js.map +1 -1
  330. package/lib/common/provider/provider-util.d.ts +1 -1
  331. package/lib/common/provider/provider-util.d.ts.map +1 -1
  332. package/lib/common/provider/provider-util.js +2 -2
  333. package/lib/common/provider/provider-util.js.map +1 -1
  334. package/lib/common/provider/provider.d.ts +7 -6
  335. package/lib/common/provider/provider.d.ts.map +1 -1
  336. package/lib/common/provider/provider.js +16 -26
  337. package/lib/common/provider/provider.js.map +1 -1
  338. package/lib/common/static-module.d.ts +1 -1
  339. package/lib/common/static-module.js +2 -2
  340. package/lib/common/static-module.js.map +1 -1
  341. package/lib/common/test/mock-logger.d.ts +1 -0
  342. package/lib/common/test/mock-logger.d.ts.map +1 -1
  343. package/lib/common/test/mock-logger.js +5 -12
  344. package/lib/common/test/mock-logger.js.map +1 -1
  345. package/lib/common/test/test-module.d.ts +1 -1
  346. package/lib/common/test/test-module.d.ts.map +1 -1
  347. package/lib/common/test/test-module.js +2 -2
  348. package/lib/common/test/test-module.js.map +1 -1
  349. package/lib/common/utils/annotation-util.js +2 -1
  350. package/lib/common/utils/annotation-util.js.map +1 -1
  351. package/lib/common/utils/emitter.d.ts +1 -10
  352. package/lib/common/utils/emitter.d.ts.map +1 -1
  353. package/lib/common/utils/emitter.js +1 -58
  354. package/lib/common/utils/emitter.js.map +1 -1
  355. package/lib/common/utils/mime-type-util.js +1 -1
  356. package/lib/common/utils/mime-type-util.js.map +1 -1
  357. package/lib/common/utils/mime-type.js +1 -1
  358. package/lib/common/utils/mime-type.js.map +1 -1
  359. package/lib/common/utils/proxy-util.d.ts +5 -2
  360. package/lib/common/utils/proxy-util.d.ts.map +1 -1
  361. package/lib/common/utils/proxy-util.js +12 -30
  362. package/lib/common/utils/proxy-util.js.map +1 -1
  363. package/lib/common/utils/utils-behavior.spec.d.ts +2 -0
  364. package/lib/common/utils/utils-behavior.spec.d.ts.map +1 -0
  365. package/lib/common/utils/utils-behavior.spec.js +232 -0
  366. package/lib/common/utils/utils-behavior.spec.js.map +1 -0
  367. package/lib/node/context/context.d.ts +11 -2
  368. package/lib/node/context/context.d.ts.map +1 -1
  369. package/lib/node/context/context.js +36 -10
  370. package/lib/node/context/context.js.map +1 -1
  371. package/lib/node/context/context.spec.d.ts +2 -0
  372. package/lib/node/context/context.spec.d.ts.map +1 -0
  373. package/lib/node/context/context.spec.js +202 -0
  374. package/lib/node/context/context.spec.js.map +1 -0
  375. package/lib/node/index.d.ts +0 -1
  376. package/lib/node/index.d.ts.map +1 -1
  377. package/lib/node/index.js +0 -1
  378. package/lib/node/index.js.map +1 -1
  379. package/lib/node/static-module.d.ts +1 -1
  380. package/package.json +9 -21
  381. package/src/common/annotation/aspect.ts +2 -1
  382. package/src/common/annotation/autowired-provider.ts +4 -17
  383. package/src/common/annotation/autowired.ts +14 -6
  384. package/src/common/annotation/component.ts +6 -26
  385. package/src/common/annotation/constant.ts +10 -7
  386. package/src/common/annotation/detached/autowired-provider.ts +2 -2
  387. package/src/common/annotation/index.ts +0 -6
  388. package/src/common/annotation/named.ts +7 -1
  389. package/src/common/annotation/optional.ts +6 -1
  390. package/src/common/annotation/post-construct.ts +6 -1
  391. package/src/common/annotation/tagged.ts +8 -1
  392. package/src/common/annotation/value.ts +9 -11
  393. package/src/common/aop/aop-proxy-factory.ts +52 -30
  394. package/src/common/aop/aop.spec.ts +145 -0
  395. package/src/common/aop/class-filter.ts +6 -6
  396. package/src/common/application/application-factory.ts +4 -5
  397. package/src/common/application/application-protocol.ts +1 -1
  398. package/src/common/application/lifecycle.spec.ts +148 -0
  399. package/src/common/config/config-provider.ts +1 -1
  400. package/src/common/container/assembly.spec.ts +288 -0
  401. package/src/common/container/auto-bind.ts +56 -74
  402. package/src/common/container/container-error.ts +31 -0
  403. package/src/common/container/container-provider.ts +9 -7
  404. package/src/common/container/container-util.ts +8 -19
  405. package/src/common/container/container.spec.ts +262 -0
  406. package/src/common/container/container.ts +363 -0
  407. package/src/common/container/dynamic-container.ts +2 -2
  408. package/src/common/container/index.ts +5 -7
  409. package/src/common/container/injection.ts +135 -0
  410. package/src/common/container/scope.ts +2 -1
  411. package/src/common/el/application-expression-engine.ts +9 -0
  412. package/src/common/el/core-context-initializer.ts +9 -8
  413. package/src/common/el/expression-compiler.ts +9 -168
  414. package/src/common/el/expression-engine.spec.ts +107 -0
  415. package/src/common/el/expression-engine.ts +487 -0
  416. package/src/common/el/expression-handler.spec.ts +109 -0
  417. package/src/common/el/expression-handler.ts +17 -57
  418. package/src/common/el/expression-protocol.ts +4 -8
  419. package/src/common/el/expression-util.spec.ts +45 -0
  420. package/src/common/el/expression-util.ts +362 -0
  421. package/src/common/el/index.ts +3 -1
  422. package/src/common/el/value-and-el.spec.ts +186 -0
  423. package/src/common/logger/abstract-logger.ts +12 -6
  424. package/src/common/logger/logger-protocol.ts +5 -0
  425. package/src/common/logger/logger.spec.ts +61 -0
  426. package/src/common/logger/logger.ts +7 -7
  427. package/src/common/provider/index.ts +0 -2
  428. package/src/common/provider/provider-protocol.ts +5 -11
  429. package/src/common/provider/provider-util.ts +3 -3
  430. package/src/common/provider/provider.ts +17 -29
  431. package/src/common/static-module.ts +1 -1
  432. package/src/common/test/mock-logger.ts +3 -2
  433. package/src/common/test/test-module.ts +1 -1
  434. package/src/common/utils/annotation-util.ts +2 -2
  435. package/src/common/utils/emitter.ts +1 -63
  436. package/src/common/utils/mime-type-util.ts +1 -1
  437. package/src/common/utils/mime-type.ts +1 -1
  438. package/src/common/utils/proxy-util.ts +8 -28
  439. package/src/common/utils/utils-behavior.spec.ts +259 -0
  440. package/src/node/context/context.spec.ts +219 -0
  441. package/src/node/context/context.ts +35 -10
  442. package/src/node/index.ts +0 -1
  443. package/esm/common/annotation/decorate.d.ts +0 -1
  444. package/esm/common/annotation/decorate.js +0 -2
  445. package/esm/common/annotation/decorate.js.map +0 -1
  446. package/esm/common/annotation/inject.d.ts +0 -1
  447. package/esm/common/annotation/inject.js +0 -2
  448. package/esm/common/annotation/inject.js.map +0 -1
  449. package/esm/common/annotation/injectable.d.ts +0 -1
  450. package/esm/common/annotation/injectable.js +0 -2
  451. package/esm/common/annotation/injectable.js.map +0 -1
  452. package/esm/common/annotation/pre-destroy.d.ts +0 -1
  453. package/esm/common/annotation/pre-destroy.js +0 -2
  454. package/esm/common/annotation/pre-destroy.js.map +0 -1
  455. package/esm/common/annotation/target-name.d.ts +0 -1
  456. package/esm/common/annotation/target-name.js +0 -2
  457. package/esm/common/annotation/target-name.js.map +0 -1
  458. package/esm/common/annotation/unmanaged.d.ts +0 -1
  459. package/esm/common/annotation/unmanaged.js +0 -2
  460. package/esm/common/annotation/unmanaged.js.map +0 -1
  461. package/esm/common/container/container-factory.d.ts +0 -4
  462. package/esm/common/container/container-factory.js +0 -9
  463. package/esm/common/container/container-factory.js.map +0 -1
  464. package/esm/common/el/jexl-engine-provider.d.ts +0 -5
  465. package/esm/common/el/jexl-engine-provider.js +0 -22
  466. package/esm/common/el/jexl-engine-provider.js.map +0 -1
  467. package/esm/common/provider/provider-creator.d.ts +0 -6
  468. package/esm/common/provider/provider-creator.js.map +0 -1
  469. package/esm/node/utils/crc.d.ts +0 -1
  470. package/esm/node/utils/crc.js +0 -7
  471. package/esm/node/utils/crc.js.map +0 -1
  472. package/esm/node/utils/index.d.ts +0 -1
  473. package/esm/node/utils/index.js +0 -2
  474. package/esm/node/utils/index.js.map +0 -1
  475. package/lib/common/annotation/decorate.d.ts +0 -2
  476. package/lib/common/annotation/decorate.d.ts.map +0 -1
  477. package/lib/common/annotation/decorate.js +0 -6
  478. package/lib/common/annotation/decorate.js.map +0 -1
  479. package/lib/common/annotation/inject.d.ts +0 -2
  480. package/lib/common/annotation/inject.d.ts.map +0 -1
  481. package/lib/common/annotation/inject.js +0 -6
  482. package/lib/common/annotation/inject.js.map +0 -1
  483. package/lib/common/annotation/injectable.d.ts +0 -2
  484. package/lib/common/annotation/injectable.d.ts.map +0 -1
  485. package/lib/common/annotation/injectable.js +0 -6
  486. package/lib/common/annotation/injectable.js.map +0 -1
  487. package/lib/common/annotation/pre-destroy.d.ts +0 -2
  488. package/lib/common/annotation/pre-destroy.d.ts.map +0 -1
  489. package/lib/common/annotation/pre-destroy.js +0 -6
  490. package/lib/common/annotation/pre-destroy.js.map +0 -1
  491. package/lib/common/annotation/target-name.d.ts +0 -2
  492. package/lib/common/annotation/target-name.d.ts.map +0 -1
  493. package/lib/common/annotation/target-name.js +0 -6
  494. package/lib/common/annotation/target-name.js.map +0 -1
  495. package/lib/common/annotation/unmanaged.d.ts +0 -2
  496. package/lib/common/annotation/unmanaged.d.ts.map +0 -1
  497. package/lib/common/annotation/unmanaged.js +0 -6
  498. package/lib/common/annotation/unmanaged.js.map +0 -1
  499. package/lib/common/container/container-factory.d.ts +0 -5
  500. package/lib/common/container/container-factory.d.ts.map +0 -1
  501. package/lib/common/container/container-factory.js +0 -13
  502. package/lib/common/container/container-factory.js.map +0 -1
  503. package/lib/common/el/jexl-engine-provider.d.ts +0 -6
  504. package/lib/common/el/jexl-engine-provider.d.ts.map +0 -1
  505. package/lib/common/el/jexl-engine-provider.js +0 -25
  506. package/lib/common/el/jexl-engine-provider.js.map +0 -1
  507. package/lib/common/provider/provider-creator.d.ts +0 -7
  508. package/lib/common/provider/provider-creator.d.ts.map +0 -1
  509. package/lib/common/provider/provider-creator.js +0 -22
  510. package/lib/common/provider/provider-creator.js.map +0 -1
  511. package/lib/node/utils/crc.d.ts +0 -2
  512. package/lib/node/utils/crc.d.ts.map +0 -1
  513. package/lib/node/utils/crc.js +0 -10
  514. package/lib/node/utils/crc.js.map +0 -1
  515. package/lib/node/utils/index.d.ts +0 -2
  516. package/lib/node/utils/index.d.ts.map +0 -1
  517. package/lib/node/utils/index.js +0 -18
  518. package/lib/node/utils/index.js.map +0 -1
  519. package/src/common/annotation/decorate.ts +0 -1
  520. package/src/common/annotation/inject.ts +0 -1
  521. package/src/common/annotation/injectable.ts +0 -1
  522. package/src/common/annotation/pre-destroy.ts +0 -1
  523. package/src/common/annotation/target-name.ts +0 -1
  524. package/src/common/annotation/unmanaged.ts +0 -1
  525. package/src/common/container/container-factory.ts +0 -9
  526. package/src/common/el/jexl-engine-provider.ts +0 -18
  527. package/src/common/provider/provider-creator.ts +0 -12
  528. package/src/node/utils/crc.ts +0 -7
  529. package/src/node/utils/index.ts +0 -1
@@ -6,15 +6,14 @@ import './application-state';
6
6
  import { autoBind } from '../container/auto-bind';
7
7
  import commonModule from '../static-module';
8
8
  import { currentThis } from '../utils';
9
- import { ContainerModule } from 'inversify';
10
- import { ContainerFactory } from '../container/container-factory';
9
+ import { Container, ContainerModule } from '../container/container';
11
10
 
12
11
  export class ApplicationFactory {
13
12
  static async create(applicationProps: ApplicationProps, ...modules: ContainerModule[]): Promise<Application> {
14
13
  currentThis.cellProps = applicationProps;
15
- const container = ContainerFactory.create(commonModule, autoBind(), ...modules);
14
+ const container = new Container();
15
+ container.load(commonModule, autoBind(), ...modules);
16
16
  ContainerProvider.set(container);
17
- const application = container.get<Application>(Application);
18
- return application;
17
+ return container.get<Application>(Application);
19
18
  }
20
19
  }
@@ -113,7 +113,7 @@ export abstract class AbstractApplicationStateService<T extends string> implemen
113
113
 
114
114
  set state(state: T) {
115
115
  if (state !== this._state) {
116
- this.deferred[this._state] = new Deferred();
116
+ // A state that was reached stays reached: late `reachedState()` calls resolve at once.
117
117
  this._state = state;
118
118
  if (this.deferred[state] === undefined) {
119
119
  this.deferred[state] = new Deferred();
@@ -0,0 +1,148 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { ApplicationFactory } from './application-factory';
4
+ import { ApplicationLifecycle, ApplicationStateService, ApplicationState, Application } from './application-protocol';
5
+ import { Component } from '../annotation';
6
+ import { ContainerUtil } from '../container/container-util';
7
+ import { Scope } from '../container/scope';
8
+ import { Logger } from '../logger/logger-protocol';
9
+ import { MockLogger } from '../test/mock-logger';
10
+
11
+ /**
12
+ * 应用生命周期的约定(阶段 1.E 行为测试):ApplicationLifecycle 的调用顺序、出错时的行为、状态变化。
13
+ */
14
+ interface Recorder { events: string[], errors: string[] }
15
+
16
+ function recordingLogger(rec: Recorder) {
17
+ @Component({ id: Logger, rebind: true, scope: Scope.Transient })
18
+ class RecordingLogger extends MockLogger {
19
+ override error(message: any): void {
20
+ rec.errors.push(String(message));
21
+ }
22
+ }
23
+ return RecordingLogger;
24
+ }
25
+
26
+ describe('core 应用生命周期', () => {
27
+
28
+ it('start():先调用全部 initialize,再按顺序 await 每个 onStart;stop() 调用 onStop', async () => {
29
+ const rec: Recorder = { events: [], errors: [] };
30
+ recordingLogger(rec);
31
+ @Component(ApplicationLifecycle)
32
+ class First implements ApplicationLifecycle<Application> {
33
+ initialize() { rec.events.push('init:first'); }
34
+ async onStart() {
35
+ await new Promise(r => setTimeout(r, 5));
36
+ rec.events.push('start:first');
37
+ }
38
+ onStop() { rec.events.push('stop:first'); }
39
+ }
40
+ @Component(ApplicationLifecycle)
41
+ class Second implements ApplicationLifecycle<Application> {
42
+ initialize() { rec.events.push('init:second'); }
43
+ onStart() { rec.events.push('start:second'); }
44
+ onStop() { rec.events.push('stop:second'); }
45
+ }
46
+ const app = await ApplicationFactory.create({});
47
+ expect(rec.events).to.deep.equal([]);
48
+ await app.start();
49
+ const inits = rec.events.slice(0, 2);
50
+ expect(inits).to.have.members(['init:first', 'init:second']);
51
+ expect(rec.events.slice(2)).to.have.members(['start:first', 'start:second']);
52
+ await app.stop();
53
+ expect(rec.events.slice(4)).to.have.members(['stop:first', 'stop:second']);
54
+ expect(rec.errors).to.deep.equal([]);
55
+ expect([First, Second]).to.have.length(2);
56
+ });
57
+
58
+ it('onStart 按 getAll 的顺序逐个 await(不是并发)', async () => {
59
+ const order: string[] = [];
60
+ let running = 0;
61
+ let maxRunning = 0;
62
+ for (const name of ['a', 'b', 'c']) {
63
+ @Component(ApplicationLifecycle)
64
+ class L implements ApplicationLifecycle<Application> {
65
+ async onStart() {
66
+ running++;
67
+ maxRunning = Math.max(maxRunning, running);
68
+ await new Promise(r => setTimeout(r, 2));
69
+ order.push(name);
70
+ running--;
71
+ }
72
+ }
73
+ void L;
74
+ }
75
+ const app = await ApplicationFactory.create({});
76
+ await app.start();
77
+ expect(order).to.have.members(['a', 'b', 'c']);
78
+ expect(maxRunning).to.equal(1);
79
+ });
80
+
81
+ it('initialize / onStart / onStop 抛错只记 error 日志,不影响其他生命周期,也不让 start() 失败', async () => {
82
+ const rec: Recorder = { events: [], errors: [] };
83
+ recordingLogger(rec);
84
+ @Component(ApplicationLifecycle)
85
+ class Broken implements ApplicationLifecycle<Application> {
86
+ initialize() { throw new Error('init boom'); }
87
+ onStart() { throw new Error('start boom'); }
88
+ onStop() { throw new Error('stop boom'); }
89
+ }
90
+ @Component(ApplicationLifecycle)
91
+ class Healthy implements ApplicationLifecycle<Application> {
92
+ initialize() { rec.events.push('init'); }
93
+ onStart() { rec.events.push('start'); }
94
+ onStop() { rec.events.push('stop'); }
95
+ }
96
+ const app = await ApplicationFactory.create({});
97
+ await app.start();
98
+ await app.stop();
99
+ expect(rec.events).to.deep.equal(['init', 'start', 'stop']);
100
+ expect(rec.errors).to.deep.equal(['Could not initialize lifecycle', 'Could not start lifecycle', 'Could not stop lifecycle']);
101
+ expect([Broken, Healthy]).to.have.length(2);
102
+ });
103
+
104
+ it('没有任何 ApplicationLifecycle 时 start / stop 正常', async () => {
105
+ const app = await ApplicationFactory.create({});
106
+ await app.start();
107
+ await app.stop();
108
+ });
109
+
110
+ it('状态:init → started → ready,stop 之后是 stoped;reachedState 与 onStateChanged', async () => {
111
+ const app = await ApplicationFactory.create({});
112
+ const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
113
+ expect(states.state).to.equal('init');
114
+ const seen: string[] = [];
115
+ states.onStateChanged(s => seen.push(s));
116
+ const ready = states.reachedState('ready');
117
+ const readyOrStopped = states.reachedAnyState('ready', 'stoped');
118
+ await app.start();
119
+ await ready;
120
+ await readyOrStopped;
121
+ expect(states.state).to.equal('ready');
122
+ await app.stop();
123
+ expect(states.state).to.equal('stoped');
124
+ expect(seen).to.deep.equal(['started', 'ready', 'stoped']);
125
+ // 当前状态再等会立刻 resolve
126
+ await states.reachedState('stoped');
127
+ });
128
+
129
+ it('离开一个状态之后,再 reachedState(那个状态) 立即 resolve(F7)', async () => {
130
+ const app = await ApplicationFactory.create({});
131
+ const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
132
+ await app.start();
133
+ const race = (p: Promise<void>) => Promise.race([p.then(() => 'resolved'), new Promise(r => setTimeout(() => r('pending'), 20))]);
134
+ expect(await race(states.reachedState('ready'))).to.equal('resolved');
135
+ expect(await race(states.reachedState('started'))).to.equal('resolved');
136
+ expect(await race(states.reachedState('stoped'))).to.equal('pending');
137
+ });
138
+
139
+ it('同一个状态重复设置不会重复通知', async () => {
140
+ await ApplicationFactory.create({});
141
+ const states = ContainerUtil.get<ApplicationStateService<ApplicationState>>(ApplicationStateService);
142
+ const seen: string[] = [];
143
+ states.onStateChanged(s => seen.push(s));
144
+ states.state = 'started';
145
+ states.state = 'started';
146
+ expect(seen).to.deep.equal(['started']);
147
+ });
148
+ });
@@ -9,7 +9,7 @@ export class ConfigProviderImpl implements ConfigProvider {
9
9
  protected readonly expressionHandler: ExpressionHandler;
10
10
 
11
11
  get<T>(key: string, defaultValue?: T): T {
12
- return this.expressionHandler.handle(`\${${key}}`) || defaultValue;
12
+ return this.expressionHandler.handle(`\${${key}}`) ?? defaultValue;
13
13
  }
14
14
 
15
15
  }
@@ -0,0 +1,288 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { ApplicationFactory } from '../application/application-factory';
4
+ import {
5
+ Component, Autowired, Optional, Constant, AutowiredProvider, PostConstruct, Named, Tagged
6
+ } from '../annotation';
7
+ import { ContainerUtil } from './container-util';
8
+ import { ContainerProvider } from './container-provider';
9
+ import { Scope } from './scope';
10
+ import { Provider } from '../provider';
11
+ import { ConfigProvider } from '../config/config-protocol';
12
+ import { autoBind } from './auto-bind';
13
+
14
+ /**
15
+ * 组件装配的约定(阶段 1.E 行为测试):只用公开的注解、ApplicationFactory 和 ContainerUtil 断言,
16
+ * 不碰 inversify 的 API,这样阶段 2 换容器时这些用例可以原样复用。
17
+ *
18
+ * 注意:组件元数据是全局登记的,ApplicationFactory.create() 里的 autoBind() 会把登记过的全部取走。
19
+ * 所以每个用例都在自己的函数里定义类,然后马上 create,用例之间互不影响。
20
+ */
21
+ async function boot(props: Record<string, any> = {}) {
22
+ return ApplicationFactory.create(props);
23
+ }
24
+
25
+ describe('core 组件装配', () => {
26
+
27
+ it('@Component 不带参数时以类本身为 id,默认单例', async () => {
28
+ @Component()
29
+ class Plain { }
30
+ await boot();
31
+ const a = ContainerUtil.get(Plain);
32
+ expect(a).to.be.instanceOf(Plain);
33
+ expect(ContainerUtil.get(Plain)).to.equal(a);
34
+ });
35
+
36
+ it('@Component(id) 同时可以按类和按 id 取到,且是同一个实例', async () => {
37
+ const Greeter = Symbol('Greeter');
38
+ @Component(Greeter)
39
+ class GreeterImpl { hello() { return 'hi'; } }
40
+ await boot();
41
+ const byId = ContainerUtil.get<GreeterImpl>(Greeter);
42
+ expect(byId.hello()).to.equal('hi');
43
+ expect(ContainerUtil.get(GreeterImpl)).to.equal(byId);
44
+ });
45
+
46
+ it('一个组件可以登记多个 id,都指向同一个实例', async () => {
47
+ const A = Symbol('A');
48
+ const B = Symbol('B');
49
+ @Component({ id: [A, B] })
50
+ class Both { }
51
+ await boot();
52
+ expect(ContainerUtil.get(A)).to.be.instanceOf(Both);
53
+ expect(ContainerUtil.get(A)).to.equal(ContainerUtil.get(B));
54
+ expect(ContainerUtil.get(Both)).to.equal(ContainerUtil.get(A));
55
+ });
56
+
57
+ it('Scope.Transient 每次取都是新实例', async () => {
58
+ @Component({ scope: Scope.Transient })
59
+ class Fresh { }
60
+ await boot();
61
+ expect(ContainerUtil.get(Fresh)).not.to.equal(ContainerUtil.get(Fresh));
62
+ });
63
+
64
+ it('@Autowired 属性注入:按声明的类型,也可以显式给 id', async () => {
65
+ const Repo = Symbol('Repo');
66
+ @Component(Repo)
67
+ class RepoImpl { find() { return 'row'; } }
68
+ @Component()
69
+ class Dep { }
70
+ @Component()
71
+ class Service {
72
+ @Autowired(Repo)
73
+ readonly repo: RepoImpl;
74
+ @Autowired()
75
+ readonly dep: Dep;
76
+ }
77
+ await boot();
78
+ const s = ContainerUtil.get(Service);
79
+ expect(s.repo.find()).to.equal('row');
80
+ expect(s.dep).to.equal(ContainerUtil.get(Dep));
81
+ });
82
+
83
+ it('@Autowired 构造器参数注入', async () => {
84
+ const Clock = Symbol('Clock');
85
+ @Component(Clock)
86
+ class FixedClock { now() { return 42; } }
87
+ @Component()
88
+ class UsesClock {
89
+ constructor(@Autowired(Clock) readonly clock: FixedClock) { }
90
+ }
91
+ await boot();
92
+ expect(ContainerUtil.get(UsesClock).clock.now()).to.equal(42);
93
+ });
94
+
95
+ it('同一 id 有多个实现时,数组类型的 @Autowired 拿到全部', async () => {
96
+ const Plugin = Symbol('Plugin');
97
+ @Component(Plugin)
98
+ class P1 { readonly name = 'p1'; }
99
+ @Component(Plugin)
100
+ class P2 { readonly name = 'p2'; }
101
+ @Component()
102
+ class Host {
103
+ @Autowired(Plugin)
104
+ readonly plugins: { name: string }[];
105
+ }
106
+ await boot();
107
+ expect(ContainerUtil.get(Host).plugins.map(p => p.name).sort()).to.deep.equal(['p1', 'p2']);
108
+ expect(ContainerUtil.getAll(Plugin)).to.have.length(2);
109
+ expect([P1, P2]).to.have.length(2);
110
+ });
111
+
112
+ it('@Optional:没有实现时单值为 undefined,数组为 []', async () => {
113
+ const Missing = Symbol('Missing');
114
+ const MissingMany = Symbol('MissingMany');
115
+ @Component()
116
+ class Tolerant {
117
+ @Autowired(Missing) @Optional()
118
+ readonly one?: unknown;
119
+ @Autowired(MissingMany) @Optional()
120
+ readonly many: unknown[];
121
+ }
122
+ await boot();
123
+ const t = ContainerUtil.get(Tolerant);
124
+ expect(t.one).to.equal(undefined);
125
+ expect(t.many).to.deep.equal([]);
126
+ });
127
+
128
+ it('没有实现又不是 @Optional 时,取的时候报错,错误信息里有缺的 id', async () => {
129
+ const Absent = Symbol('AbsentService');
130
+ @Component()
131
+ class Needy {
132
+ @Autowired(Absent)
133
+ readonly absent: unknown;
134
+ }
135
+ await boot();
136
+ expect(() => ContainerUtil.get(Needy)).to.throw(/AbsentService/);
137
+ });
138
+
139
+ it('@Component({ id, name / tag / default }) 按名字、标签或默认选实现,类本身仍可直接取(F1)', async () => {
140
+ const Store = Symbol('Store');
141
+ @Component({ id: Store, name: 'redis' })
142
+ class RedisStore { readonly kind = 'redis'; }
143
+ @Component({ id: Store, tag: { tag: 'region', value: 'eu' } })
144
+ class EuStore { readonly kind = 'eu'; }
145
+ @Component({ id: Store, default: true })
146
+ class MemoryStore { readonly kind = 'memory'; }
147
+ @Component()
148
+ class Consumer {
149
+ @Autowired(Store) @Named('redis')
150
+ readonly redis: { kind: string };
151
+ @Autowired(Store) @Tagged('region', 'eu')
152
+ readonly eu: { kind: string };
153
+ @Autowired(Store)
154
+ readonly fallback: { kind: string };
155
+ }
156
+ await boot();
157
+ const c = ContainerUtil.get(Consumer);
158
+ expect([c.redis.kind, c.eu.kind, c.fallback.kind]).to.deep.equal(['redis', 'eu', 'memory']);
159
+ expect(ContainerUtil.get<{ kind: string }>(Store, { name: 'redis' })).to.equal(ContainerUtil.get(RedisStore));
160
+ expect(ContainerUtil.get<{ kind: string }>(Store, { tags: { region: 'eu' } })).to.equal(ContainerUtil.get(EuStore));
161
+ expect(ContainerUtil.get(Store)).to.equal(ContainerUtil.get(MemoryStore));
162
+ });
163
+
164
+ it('rebind: true 替换先加载的模块里的实现(应用覆盖框架或其他包的组件)', async () => {
165
+ const Mailer = Symbol('Mailer');
166
+ @Component(Mailer)
167
+ class DefaultMailer { readonly who = 'default'; }
168
+ const base = autoBind();
169
+ @Component({ id: Mailer, rebind: true })
170
+ class CustomMailer { readonly who = 'custom'; }
171
+ const overrides = autoBind();
172
+ await ApplicationFactory.create({}, base, overrides);
173
+ expect(ContainerUtil.getAll<{ who: string }>(Mailer).map(m => m.who)).to.deep.equal(['custom']);
174
+ expect([DefaultMailer, CustomMailer]).to.have.length(2);
175
+ });
176
+
177
+ it('同一批 autoBind 里也可以 rebind 本批先定义的组件(按定义顺序登记)', async () => {
178
+ const Mailer = Symbol('SameBatchMailer');
179
+ @Component(Mailer)
180
+ class DefaultMailer { readonly who = 'default'; }
181
+ @Component({ id: Mailer, rebind: true })
182
+ class CustomMailer { readonly who = 'custom'; }
183
+ await boot();
184
+ expect(ContainerUtil.getAll<{ who: string }>(Mailer).map(m => m.who)).to.deep.equal(['custom']);
185
+ expect([DefaultMailer, CustomMailer]).to.have.length(2);
186
+ });
187
+
188
+ it('rebind 替换框架自带组件:替换后注入点拿到的是新实现', async () => {
189
+ @Component({ id: ConfigProvider, rebind: true })
190
+ class FixedConfig {
191
+ get(key: string) { return key === 'answer' ? 42 : undefined; }
192
+ }
193
+ @Component()
194
+ class ReadsConfig {
195
+ @Autowired(ConfigProvider)
196
+ readonly config: FixedConfig;
197
+ }
198
+ await boot();
199
+ expect(ContainerUtil.get(ReadsConfig).config).to.be.instanceOf(FixedConfig);
200
+ expect(ContainerUtil.get(ReadsConfig).config.get('answer')).to.equal(42);
201
+ });
202
+
203
+ it('@Constant 登记常量,多个 id 都能取到', async () => {
204
+ const Token = Symbol('Token');
205
+ const Alias = Symbol('TokenAlias');
206
+ @Constant([Token, Alias], { secret: 'abc' })
207
+ class Holder { }
208
+ await boot();
209
+ expect(ContainerUtil.get(Token)).to.deep.equal({ secret: 'abc' });
210
+ expect(ContainerUtil.get(Alias)).to.equal(ContainerUtil.get(Token));
211
+ expect(Holder).to.be.a('function');
212
+ });
213
+
214
+ it('@AutowiredProvider 注入 Provider:按 priority 从小到大排序(sortSync)', async () => {
215
+ const Step = Symbol('Step');
216
+ @Component(Step)
217
+ class Late { readonly priority = 300; readonly name = 'late'; }
218
+ @Component(Step)
219
+ class Early { readonly priority = 100; readonly name = 'early'; }
220
+ @Component(Step)
221
+ class Middle { readonly priority = 200; readonly name = 'middle'; }
222
+ @Component()
223
+ class Pipeline {
224
+ @AutowiredProvider(Step)
225
+ readonly steps: Provider<{ name: string, priority: number }>;
226
+ }
227
+ await boot();
228
+ const names = ContainerUtil.get(Pipeline).steps.sortSync().map(s => s.name);
229
+ expect(names).to.have.members(['early', 'middle', 'late']);
230
+ // Prioritizeable:priority 大的排前面
231
+ expect(names).to.deep.equal(['late', 'middle', 'early']);
232
+ expect([Late, Early, Middle]).to.have.length(3);
233
+ });
234
+
235
+ it('@PostConstruct 在注入完成后调用一次,单例只调用一次', async () => {
236
+ let calls = 0;
237
+ @Component()
238
+ class Dep { readonly ok = true; }
239
+ @Component()
240
+ class Init {
241
+ @Autowired()
242
+ readonly dep: Dep;
243
+ seenDep = false;
244
+ @PostConstruct()
245
+ protected init() {
246
+ calls++;
247
+ this.seenDep = this.dep.ok;
248
+ }
249
+ }
250
+ await boot();
251
+ expect(ContainerUtil.get(Init).seenDep).to.equal(true);
252
+ ContainerUtil.get(Init);
253
+ expect(calls).to.equal(1);
254
+ });
255
+
256
+ it('detached 的 @Autowired:不在容器里的对象也能按需从当前容器取值', async () => {
257
+ const Clock = Symbol('DetachedClock');
258
+ @Component(Clock)
259
+ class Clk { now() { return 7; } }
260
+ class NotAComponent {
261
+ @Autowired({ id: Clock, detached: true })
262
+ readonly clock: Clk;
263
+ }
264
+ await boot();
265
+ expect(new NotAComponent().clock.now()).to.equal(7);
266
+ });
267
+
268
+ it('detached 不支持构造器参数,给出明确的错误', () => {
269
+ expect(() => {
270
+ class Bad {
271
+ constructor(@Autowired({ id: Symbol('x'), detached: true }) readonly x: unknown) { }
272
+ }
273
+ return Bad;
274
+ }).to.throw(/not supported/);
275
+ });
276
+
277
+ it('每次 ApplicationFactory.create 都换成新的容器,ContainerUtil 指向最新的那个', async () => {
278
+ @Component()
279
+ class Counter { value = 0; }
280
+ await boot();
281
+ const first = ContainerProvider.provide();
282
+ ContainerUtil.get(Counter).value = 5;
283
+ await boot();
284
+ expect(ContainerProvider.provide()).not.to.equal(first);
285
+ // 新容器里没有再登记 Counter(元数据已被上一次 create 取走)
286
+ expect(() => ContainerUtil.get(Counter)).to.throw();
287
+ });
288
+ });
@@ -1,101 +1,83 @@
1
- import { interfaces, ContainerModule } from 'inversify';
2
1
  import { METADATA_KEY } from '../constants';
3
- import { ComponentMetadata, ConstantOption } from '../annotation';
2
+ import type { ComponentMetadata, ConstantOption } from '../annotation';
4
3
  import { ConfigUtil } from '../config/config-util';
5
4
  import { AopProxyFactory, ClassFilter } from '../aop/aop-protocol';
6
- import { ContainerUtil } from './container-util';
5
+ import { Binding, ComponentId, Container, ContainerModule, ContainerModuleRegistry } from './container';
7
6
  import { Scope } from './scope';
8
7
 
9
- export function manualBind(registry?: interfaces.ContainerModuleCallBack): interfaces.ContainerModule {
10
- return new ContainerModule((bind, unbind, isBound, rebind, ...rest) => {
11
- if (registry) {
12
- registry(bind, unbind, isBound, rebind, ...rest);
13
- }
14
- });
15
- }
8
+ type Bind = <T>(id: ComponentId<T>) => Binding<T>;
16
9
 
17
- export function autoBind(registry?: interfaces.ContainerModuleCallBack): interfaces.ContainerModule {
18
- const metadatas: ComponentMetadata[] = Reflect.getMetadata(METADATA_KEY.component, Reflect) || [];
19
- const constantMetadata: ConstantOption[] = Reflect.getMetadata(METADATA_KEY.constantValue, Reflect) || [];
10
+ /**
11
+ * A module of the components registered (`@Component`, `@Constant` and the decorators built on them)
12
+ * since the previous `autoBind()`, in the order they were defined; `registry` adds bindings by hand.
13
+ * A DI module file imports its components, then exports `autoBind()`.
14
+ */
15
+ export function autoBind(registry?: ContainerModuleRegistry): ContainerModule {
16
+ const components: ComponentMetadata[] = Reflect.getMetadata(METADATA_KEY.component, Reflect) || [];
17
+ const constants: ConstantOption[] = Reflect.getMetadata(METADATA_KEY.constantValue, Reflect) || [];
20
18
  Reflect.defineMetadata(METADATA_KEY.component, [], Reflect);
21
19
  Reflect.defineMetadata(METADATA_KEY.constantValue, [], Reflect);
22
- return new ContainerModule((bind, unbind, isBound, rebind, ...rest) => {
23
- for (let index = metadatas!.length - 1; index >= 0; index--) {
24
- const metadata = metadatas![index];
25
- resolve(metadata, bind, rebind);
20
+ return new ContainerModule((bind, unbind, isBound, rebind) => {
21
+ for (const metadata of components) {
22
+ bindComponent(metadata, bind, rebind);
26
23
  }
27
- constantMetadata!.map(metadata => resolveConstant(metadata, bind, rebind));
28
-
29
- if (registry) {
30
- registry(bind, unbind, isBound, rebind, ...rest);
24
+ for (const metadata of constants) {
25
+ bindConstant(metadata, bind, rebind);
31
26
  }
27
+ registry?.(bind, unbind, isBound, rebind);
32
28
  });
33
29
  }
34
30
 
35
- function doProxyIfNeed(metadata: ComponentMetadata, target: any) {
36
- const enabled = ConfigUtil.getRaw().cell?.aop?.enabled;
37
- if (enabled && metadata.proxy) {
38
- const classFilter = ContainerUtil.get<ClassFilter>(ClassFilter);
39
- if (target.constructor && classFilter.matches(target.constructor, metadata)) {
40
- const aopProxyFactory = ContainerUtil.get<AopProxyFactory>(AopProxyFactory);
41
- return aopProxyFactory.create({
42
- target,
43
- metadata
44
- }).getProxy();
31
+ function proxyIfNeeded(container: Container, metadata: ComponentMetadata, instance: any) {
32
+ if (ConfigUtil.getRaw().cell?.aop?.enabled && instance?.constructor) {
33
+ if (container.get<ClassFilter>(ClassFilter).matches(instance.constructor, metadata)) {
34
+ return container.get<AopProxyFactory>(AopProxyFactory).create({ target: instance, metadata }).getProxy();
45
35
  }
46
36
  }
47
-
48
- return target;
37
+ return instance;
49
38
  }
50
39
 
51
- function resolve(metadata: ComponentMetadata, bind: interfaces.Bind, rebind: interfaces.Rebind): void {
52
- let mid: any;
53
- const { ids, scope, name, tag, when, proxy, onActivation, target } = metadata;
54
- const _ids = [...ids];
55
- const id = _ids.shift()!;
56
- if (metadata.rebind) {
57
- const id2 = _ids.shift();
58
- mid = rebind(id2 || id).to(target);
59
- } else {
60
- mid = bind(id).to(target);
61
- }
40
+ /**
41
+ * The first identifier (the class itself unless the decorator says otherwise) is bound to the class,
42
+ * the others resolve to it. `rebind` replaces the bindings of the first other identifier.
43
+ */
44
+ function bindComponent(metadata: ComponentMetadata, bind: Bind, rebind: Bind): void {
45
+ const { ids: [primary, ...aliases], scope, name, tag, proxy, onActivation, target } = metadata;
46
+ const main = (metadata.rebind && aliases.length === 0 ? rebind : bind)(primary).to(target);
62
47
  if (scope === Scope.Singleton) {
63
- mid = mid.inSingletonScope();
64
- } else if (scope === Scope.Transient) {
65
- mid = mid.inTransientScope();
66
- }
67
-
68
- if (name) {
69
- mid = mid.whenTargetNamed(name);
70
- } else if (tag) {
71
- mid = mid.whenTargetTagged(tag.tag, tag.value);
72
- } else if (metadata.default) {
73
- mid = mid.whenTargetIsDefault();
74
- } else if (when) {
75
- mid = mid.when(when);
48
+ main.inSingletonScope();
76
49
  }
77
-
78
50
  if (onActivation) {
79
- mid.onActivation(onActivation);
51
+ main.onActivation(onActivation);
80
52
  } else if (proxy) {
81
- mid.onActivation((context: interfaces.Context, t: any) => doProxyIfNeed(metadata, t));
53
+ main.onActivation((context, instance) => proxyIfNeeded(context.container, metadata, instance));
82
54
  }
83
-
84
- for (const item of _ids) {
85
- bind(item).toService(id);
55
+ const constrain = (binding: Binding) => {
56
+ if (name !== undefined) {
57
+ binding.whenTargetNamed(name);
58
+ } else if (tag) {
59
+ binding.whenTargetTagged(tag.tag, tag.value);
60
+ } else if (metadata.default) {
61
+ binding.whenTargetIsDefault();
62
+ }
63
+ };
64
+ if (aliases.length === 0) {
65
+ constrain(main);
86
66
  }
67
+ aliases.forEach((alias, index) => {
68
+ const binding = (metadata.rebind && index === 0 ? rebind : bind)(alias).toService(primary);
69
+ // An alias of a singleton is that singleton: it is cached too.
70
+ if (scope === Scope.Singleton) {
71
+ binding.inSingletonScope();
72
+ }
73
+ constrain(binding);
74
+ });
87
75
  }
88
76
 
89
- function resolveConstant(metadata: ConstantOption, bind: interfaces.Bind, rebind: interfaces.Rebind): void {
90
- const ids = Array.isArray(metadata.id) ? [...metadata.id] : [ metadata.id ];
91
- const id = ids.shift();
92
- if (metadata.rebind) {
93
- rebind(id!).toConstantValue(metadata.constantValue);
94
- } else {
95
- bind(id!).toConstantValue(metadata.constantValue);
96
- }
97
-
98
- for (const item of ids) {
99
- bind(item!).toService(id!);
77
+ function bindConstant(metadata: ConstantOption, bind: Bind, rebind: Bind): void {
78
+ const [first, ...others] = Array.isArray(metadata.id) ? metadata.id : [metadata.id];
79
+ (metadata.rebind ? rebind : bind)(first).toConstantValue(metadata.constantValue);
80
+ for (const id of others) {
81
+ bind(id).toConstantValue(metadata.constantValue);
100
82
  }
101
83
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Why the container could not give a component. `code` is stable (the same codes `cell check` reports),
3
+ * `hint` says how to fix it in one sentence and `path` is the chain of identifiers being resolved,
4
+ * outermost first (docs/design/agent-first.md R5).
5
+ */
6
+ export class ContainerError extends Error {
7
+ override readonly name = 'ContainerError';
8
+ readonly code: ContainerError.Code;
9
+ readonly hint: string;
10
+ readonly path: string[];
11
+
12
+ constructor(options: { code: ContainerError.Code, message: string, hint: string, path?: string[] }) {
13
+ super(options.message);
14
+ this.code = options.code;
15
+ this.hint = options.hint;
16
+ this.path = options.path ?? [];
17
+ }
18
+ }
19
+
20
+ export namespace ContainerError {
21
+ export type Code =
22
+ | 'CELL_DI_NO_BINDING'
23
+ | 'CELL_DI_AMBIGUOUS'
24
+ | 'CELL_DI_CIRCULAR'
25
+ | 'CELL_DI_MISSING_INJECT'
26
+ | 'CELL_DI_INCOMPLETE_BINDING';
27
+
28
+ export function is(error: unknown, code?: Code): error is ContainerError {
29
+ return error instanceof ContainerError && (code === undefined || error.code === code);
30
+ }
31
+ }