@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
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const bun_test_1 = require("bun:test");
10
+ const chai_1 = require("chai");
11
+ const application_factory_1 = require("./application-factory");
12
+ const application_protocol_1 = require("./application-protocol");
13
+ const annotation_1 = require("../annotation");
14
+ const container_util_1 = require("../container/container-util");
15
+ const scope_1 = require("../container/scope");
16
+ const logger_protocol_1 = require("../logger/logger-protocol");
17
+ const mock_logger_1 = require("../test/mock-logger");
18
+ function recordingLogger(rec) {
19
+ let RecordingLogger = class RecordingLogger extends mock_logger_1.MockLogger {
20
+ error(message) {
21
+ rec.errors.push(String(message));
22
+ }
23
+ };
24
+ RecordingLogger = __decorate([
25
+ (0, annotation_1.Component)({ id: logger_protocol_1.Logger, rebind: true, scope: scope_1.Scope.Transient })
26
+ ], RecordingLogger);
27
+ return RecordingLogger;
28
+ }
29
+ (0, bun_test_1.describe)('core 应用生命周期', () => {
30
+ (0, bun_test_1.it)('start():先调用全部 initialize,再按顺序 await 每个 onStart;stop() 调用 onStop', async () => {
31
+ const rec = { events: [], errors: [] };
32
+ recordingLogger(rec);
33
+ let First = class First {
34
+ initialize() { rec.events.push('init:first'); }
35
+ async onStart() {
36
+ await new Promise(r => setTimeout(r, 5));
37
+ rec.events.push('start:first');
38
+ }
39
+ onStop() { rec.events.push('stop:first'); }
40
+ };
41
+ First = __decorate([
42
+ (0, annotation_1.Component)(application_protocol_1.ApplicationLifecycle)
43
+ ], First);
44
+ let Second = class Second {
45
+ initialize() { rec.events.push('init:second'); }
46
+ onStart() { rec.events.push('start:second'); }
47
+ onStop() { rec.events.push('stop:second'); }
48
+ };
49
+ Second = __decorate([
50
+ (0, annotation_1.Component)(application_protocol_1.ApplicationLifecycle)
51
+ ], Second);
52
+ const app = await application_factory_1.ApplicationFactory.create({});
53
+ (0, chai_1.expect)(rec.events).to.deep.equal([]);
54
+ await app.start();
55
+ const inits = rec.events.slice(0, 2);
56
+ (0, chai_1.expect)(inits).to.have.members(['init:first', 'init:second']);
57
+ (0, chai_1.expect)(rec.events.slice(2)).to.have.members(['start:first', 'start:second']);
58
+ await app.stop();
59
+ (0, chai_1.expect)(rec.events.slice(4)).to.have.members(['stop:first', 'stop:second']);
60
+ (0, chai_1.expect)(rec.errors).to.deep.equal([]);
61
+ (0, chai_1.expect)([First, Second]).to.have.length(2);
62
+ });
63
+ (0, bun_test_1.it)('onStart 按 getAll 的顺序逐个 await(不是并发)', async () => {
64
+ const order = [];
65
+ let running = 0;
66
+ let maxRunning = 0;
67
+ for (const name of ['a', 'b', 'c']) {
68
+ let L = class L {
69
+ async onStart() {
70
+ running++;
71
+ maxRunning = Math.max(maxRunning, running);
72
+ await new Promise(r => setTimeout(r, 2));
73
+ order.push(name);
74
+ running--;
75
+ }
76
+ };
77
+ L = __decorate([
78
+ (0, annotation_1.Component)(application_protocol_1.ApplicationLifecycle)
79
+ ], L);
80
+ void L;
81
+ }
82
+ const app = await application_factory_1.ApplicationFactory.create({});
83
+ await app.start();
84
+ (0, chai_1.expect)(order).to.have.members(['a', 'b', 'c']);
85
+ (0, chai_1.expect)(maxRunning).to.equal(1);
86
+ });
87
+ (0, bun_test_1.it)('initialize / onStart / onStop 抛错只记 error 日志,不影响其他生命周期,也不让 start() 失败', async () => {
88
+ const rec = { events: [], errors: [] };
89
+ recordingLogger(rec);
90
+ let Broken = class Broken {
91
+ initialize() { throw new Error('init boom'); }
92
+ onStart() { throw new Error('start boom'); }
93
+ onStop() { throw new Error('stop boom'); }
94
+ };
95
+ Broken = __decorate([
96
+ (0, annotation_1.Component)(application_protocol_1.ApplicationLifecycle)
97
+ ], Broken);
98
+ let Healthy = class Healthy {
99
+ initialize() { rec.events.push('init'); }
100
+ onStart() { rec.events.push('start'); }
101
+ onStop() { rec.events.push('stop'); }
102
+ };
103
+ Healthy = __decorate([
104
+ (0, annotation_1.Component)(application_protocol_1.ApplicationLifecycle)
105
+ ], Healthy);
106
+ const app = await application_factory_1.ApplicationFactory.create({});
107
+ await app.start();
108
+ await app.stop();
109
+ (0, chai_1.expect)(rec.events).to.deep.equal(['init', 'start', 'stop']);
110
+ (0, chai_1.expect)(rec.errors).to.deep.equal(['Could not initialize lifecycle', 'Could not start lifecycle', 'Could not stop lifecycle']);
111
+ (0, chai_1.expect)([Broken, Healthy]).to.have.length(2);
112
+ });
113
+ (0, bun_test_1.it)('没有任何 ApplicationLifecycle 时 start / stop 正常', async () => {
114
+ const app = await application_factory_1.ApplicationFactory.create({});
115
+ await app.start();
116
+ await app.stop();
117
+ });
118
+ (0, bun_test_1.it)('状态:init → started → ready,stop 之后是 stoped;reachedState 与 onStateChanged', async () => {
119
+ const app = await application_factory_1.ApplicationFactory.create({});
120
+ const states = container_util_1.ContainerUtil.get(application_protocol_1.ApplicationStateService);
121
+ (0, chai_1.expect)(states.state).to.equal('init');
122
+ const seen = [];
123
+ states.onStateChanged(s => seen.push(s));
124
+ const ready = states.reachedState('ready');
125
+ const readyOrStopped = states.reachedAnyState('ready', 'stoped');
126
+ await app.start();
127
+ await ready;
128
+ await readyOrStopped;
129
+ (0, chai_1.expect)(states.state).to.equal('ready');
130
+ await app.stop();
131
+ (0, chai_1.expect)(states.state).to.equal('stoped');
132
+ (0, chai_1.expect)(seen).to.deep.equal(['started', 'ready', 'stoped']);
133
+ // 当前状态再等会立刻 resolve
134
+ await states.reachedState('stoped');
135
+ });
136
+ (0, bun_test_1.it)('离开一个状态之后,再 reachedState(那个状态) 立即 resolve(F7)', async () => {
137
+ const app = await application_factory_1.ApplicationFactory.create({});
138
+ const states = container_util_1.ContainerUtil.get(application_protocol_1.ApplicationStateService);
139
+ await app.start();
140
+ const race = (p) => Promise.race([p.then(() => 'resolved'), new Promise(r => setTimeout(() => r('pending'), 20))]);
141
+ (0, chai_1.expect)(await race(states.reachedState('ready'))).to.equal('resolved');
142
+ (0, chai_1.expect)(await race(states.reachedState('started'))).to.equal('resolved');
143
+ (0, chai_1.expect)(await race(states.reachedState('stoped'))).to.equal('pending');
144
+ });
145
+ (0, bun_test_1.it)('同一个状态重复设置不会重复通知', async () => {
146
+ await application_factory_1.ApplicationFactory.create({});
147
+ const states = container_util_1.ContainerUtil.get(application_protocol_1.ApplicationStateService);
148
+ const seen = [];
149
+ states.onStateChanged(s => seen.push(s));
150
+ states.state = 'started';
151
+ states.state = 'started';
152
+ (0, chai_1.expect)(seen).to.deep.equal(['started']);
153
+ });
154
+ });
155
+ //# sourceMappingURL=lifecycle.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.spec.js","sourceRoot":"","sources":["../../../src/common/application/lifecycle.spec.ts"],"names":[],"mappings":";;;;;;;;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,+DAA2D;AAC3D,iEAAsH;AACtH,8CAA0C;AAC1C,gEAA4D;AAC5D,8CAA2C;AAC3C,+DAAmD;AACnD,qDAAiD;AAOjD,SAAS,eAAe,CAAC,GAAa;IAElC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,wBAAU;QAC3B,KAAK,CAAC,OAAY;YACvB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,CAAC;KACJ,CAAA;IAJK,eAAe;QADpB,IAAA,sBAAS,EAAC,EAAE,EAAE,EAAE,wBAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,aAAK,CAAC,SAAS,EAAE,CAAC;OAC1D,eAAe,CAIpB;IACD,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,IAAA,mBAAQ,EAAC,aAAa,EAAE,GAAG,EAAE;IAEzB,IAAA,aAAE,EAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,GAAG,GAAa,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACjD,e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AC;AACP,CAAC,CAAC,CAAC"}
@@ -15,7 +15,8 @@ const annotation_1 = require("../annotation");
15
15
  const el_1 = require("../el");
16
16
  let ConfigProviderImpl = class ConfigProviderImpl {
17
17
  get(key, defaultValue) {
18
- return this.expressionHandler.handle(`\${${key}}`) || defaultValue;
18
+ var _a;
19
+ return (_a = this.expressionHandler.handle(`\${${key}}`)) !== null && _a !== void 0 ? _a : defaultValue;
19
20
  }
20
21
  };
21
22
  exports.ConfigProviderImpl = ConfigProviderImpl;
@@ -1 +1 @@
1
- {"version":3,"file":"config-provider.js","sourceRoot":"","sources":["../../../src/common/config/config-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAmD;AACnD,8CAAqD;AACrD,8BAA0C;AAGnC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAK3B,GAAG,CAAI,GAAW,EAAE,YAAgB;QAChC,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,YAAY,CAAC;IACvE,CAAC;CAEJ,CAAA;;AANsB;IADlB,IAAA,sBAAS,EAAC,sBAAiB,CAAC;;6DAC2B;6BAH/C,kBAAkB;IAD9B,IAAA,sBAAS,EAAC,gCAAc,CAAC;GACb,kBAAkB,CAS9B"}
1
+ {"version":3,"file":"config-provider.js","sourceRoot":"","sources":["../../../src/common/config/config-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAmD;AACnD,8CAAqD;AACrD,8BAA0C;AAGnC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAK3B,GAAG,CAAI,GAAW,EAAE,YAAgB;;QAChC,aAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,mCAAI,YAAY,CAAC;IACvE,CAAC;CAEJ,CAAA;;AANsB;IADlB,IAAA,sBAAS,EAAC,sBAAiB,CAAC;;6DAC2B;6BAH/C,kBAAkB;IAD9B,IAAA,sBAAS,EAAC,gCAAc,CAAC;GACb,kBAAkB,CAS9B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=assembly.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assembly.spec.d.ts","sourceRoot":"","sources":["../../../src/common/container/assembly.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,464 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const bun_test_1 = require("bun:test");
16
+ const chai_1 = require("chai");
17
+ const application_factory_1 = require("../application/application-factory");
18
+ const annotation_1 = require("../annotation");
19
+ const container_util_1 = require("./container-util");
20
+ const container_provider_1 = require("./container-provider");
21
+ const scope_1 = require("./scope");
22
+ const config_protocol_1 = require("../config/config-protocol");
23
+ const auto_bind_1 = require("./auto-bind");
24
+ /**
25
+ * 组件装配的约定(阶段 1.E 行为测试):只用公开的注解、ApplicationFactory 和 ContainerUtil 断言,
26
+ * 不碰 inversify 的 API,这样阶段 2 换容器时这些用例可以原样复用。
27
+ *
28
+ * 注意:组件元数据是全局登记的,ApplicationFactory.create() 里的 autoBind() 会把登记过的全部取走。
29
+ * 所以每个用例都在自己的函数里定义类,然后马上 create,用例之间互不影响。
30
+ */
31
+ async function boot(props = {}) {
32
+ return application_factory_1.ApplicationFactory.create(props);
33
+ }
34
+ (0, bun_test_1.describe)('core 组件装配', () => {
35
+ (0, bun_test_1.it)('@Component 不带参数时以类本身为 id,默认单例', async () => {
36
+ let Plain = class Plain {
37
+ };
38
+ Plain = __decorate([
39
+ (0, annotation_1.Component)()
40
+ ], Plain);
41
+ await boot();
42
+ const a = container_util_1.ContainerUtil.get(Plain);
43
+ (0, chai_1.expect)(a).to.be.instanceOf(Plain);
44
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Plain)).to.equal(a);
45
+ });
46
+ (0, bun_test_1.it)('@Component(id) 同时可以按类和按 id 取到,且是同一个实例', async () => {
47
+ const Greeter = Symbol('Greeter');
48
+ let GreeterImpl = class GreeterImpl {
49
+ hello() { return 'hi'; }
50
+ };
51
+ GreeterImpl = __decorate([
52
+ (0, annotation_1.Component)(Greeter)
53
+ ], GreeterImpl);
54
+ await boot();
55
+ const byId = container_util_1.ContainerUtil.get(Greeter);
56
+ (0, chai_1.expect)(byId.hello()).to.equal('hi');
57
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(GreeterImpl)).to.equal(byId);
58
+ });
59
+ (0, bun_test_1.it)('一个组件可以登记多个 id,都指向同一个实例', async () => {
60
+ const A = Symbol('A');
61
+ const B = Symbol('B');
62
+ let Both = class Both {
63
+ };
64
+ Both = __decorate([
65
+ (0, annotation_1.Component)({ id: [A, B] })
66
+ ], Both);
67
+ await boot();
68
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(A)).to.be.instanceOf(Both);
69
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(A)).to.equal(container_util_1.ContainerUtil.get(B));
70
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Both)).to.equal(container_util_1.ContainerUtil.get(A));
71
+ });
72
+ (0, bun_test_1.it)('Scope.Transient 每次取都是新实例', async () => {
73
+ let Fresh = class Fresh {
74
+ };
75
+ Fresh = __decorate([
76
+ (0, annotation_1.Component)({ scope: scope_1.Scope.Transient })
77
+ ], Fresh);
78
+ await boot();
79
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Fresh)).not.to.equal(container_util_1.ContainerUtil.get(Fresh));
80
+ });
81
+ (0, bun_test_1.it)('@Autowired 属性注入:按声明的类型,也可以显式给 id', async () => {
82
+ const Repo = Symbol('Repo');
83
+ let RepoImpl = class RepoImpl {
84
+ find() { return 'row'; }
85
+ };
86
+ RepoImpl = __decorate([
87
+ (0, annotation_1.Component)(Repo)
88
+ ], RepoImpl);
89
+ let Dep = class Dep {
90
+ };
91
+ Dep = __decorate([
92
+ (0, annotation_1.Component)()
93
+ ], Dep);
94
+ let Service = class Service {
95
+ };
96
+ __decorate([
97
+ (0, annotation_1.Autowired)(Repo),
98
+ __metadata("design:type", RepoImpl)
99
+ ], Service.prototype, "repo", void 0);
100
+ __decorate([
101
+ (0, annotation_1.Autowired)(),
102
+ __metadata("design:type", Dep)
103
+ ], Service.prototype, "dep", void 0);
104
+ Service = __decorate([
105
+ (0, annotation_1.Component)()
106
+ ], Service);
107
+ await boot();
108
+ const s = container_util_1.ContainerUtil.get(Service);
109
+ (0, chai_1.expect)(s.repo.find()).to.equal('row');
110
+ (0, chai_1.expect)(s.dep).to.equal(container_util_1.ContainerUtil.get(Dep));
111
+ });
112
+ (0, bun_test_1.it)('@Autowired 构造器参数注入', async () => {
113
+ const Clock = Symbol('Clock');
114
+ let FixedClock = class FixedClock {
115
+ now() { return 42; }
116
+ };
117
+ FixedClock = __decorate([
118
+ (0, annotation_1.Component)(Clock)
119
+ ], FixedClock);
120
+ let UsesClock = class UsesClock {
121
+ constructor(clock) {
122
+ this.clock = clock;
123
+ }
124
+ };
125
+ UsesClock = __decorate([
126
+ (0, annotation_1.Component)(),
127
+ __param(0, (0, annotation_1.Autowired)(Clock)),
128
+ __metadata("design:paramtypes", [FixedClock])
129
+ ], UsesClock);
130
+ await boot();
131
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(UsesClock).clock.now()).to.equal(42);
132
+ });
133
+ (0, bun_test_1.it)('同一 id 有多个实现时,数组类型的 @Autowired 拿到全部', async () => {
134
+ const Plugin = Symbol('Plugin');
135
+ let P1 = class P1 {
136
+ constructor() {
137
+ this.name = 'p1';
138
+ }
139
+ };
140
+ P1 = __decorate([
141
+ (0, annotation_1.Component)(Plugin)
142
+ ], P1);
143
+ let P2 = class P2 {
144
+ constructor() {
145
+ this.name = 'p2';
146
+ }
147
+ };
148
+ P2 = __decorate([
149
+ (0, annotation_1.Component)(Plugin)
150
+ ], P2);
151
+ let Host = class Host {
152
+ };
153
+ __decorate([
154
+ (0, annotation_1.Autowired)(Plugin),
155
+ __metadata("design:type", Array)
156
+ ], Host.prototype, "plugins", void 0);
157
+ Host = __decorate([
158
+ (0, annotation_1.Component)()
159
+ ], Host);
160
+ await boot();
161
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Host).plugins.map(p => p.name).sort()).to.deep.equal(['p1', 'p2']);
162
+ (0, chai_1.expect)(container_util_1.ContainerUtil.getAll(Plugin)).to.have.length(2);
163
+ (0, chai_1.expect)([P1, P2]).to.have.length(2);
164
+ });
165
+ (0, bun_test_1.it)('@Optional:没有实现时单值为 undefined,数组为 []', async () => {
166
+ const Missing = Symbol('Missing');
167
+ const MissingMany = Symbol('MissingMany');
168
+ let Tolerant = class Tolerant {
169
+ };
170
+ __decorate([
171
+ (0, annotation_1.Autowired)(Missing),
172
+ (0, annotation_1.Optional)(),
173
+ __metadata("design:type", Object)
174
+ ], Tolerant.prototype, "one", void 0);
175
+ __decorate([
176
+ (0, annotation_1.Autowired)(MissingMany),
177
+ (0, annotation_1.Optional)(),
178
+ __metadata("design:type", Array)
179
+ ], Tolerant.prototype, "many", void 0);
180
+ Tolerant = __decorate([
181
+ (0, annotation_1.Component)()
182
+ ], Tolerant);
183
+ await boot();
184
+ const t = container_util_1.ContainerUtil.get(Tolerant);
185
+ (0, chai_1.expect)(t.one).to.equal(undefined);
186
+ (0, chai_1.expect)(t.many).to.deep.equal([]);
187
+ });
188
+ (0, bun_test_1.it)('没有实现又不是 @Optional 时,取的时候报错,错误信息里有缺的 id', async () => {
189
+ const Absent = Symbol('AbsentService');
190
+ let Needy = class Needy {
191
+ };
192
+ __decorate([
193
+ (0, annotation_1.Autowired)(Absent),
194
+ __metadata("design:type", Object)
195
+ ], Needy.prototype, "absent", void 0);
196
+ Needy = __decorate([
197
+ (0, annotation_1.Component)()
198
+ ], Needy);
199
+ await boot();
200
+ (0, chai_1.expect)(() => container_util_1.ContainerUtil.get(Needy)).to.throw(/AbsentService/);
201
+ });
202
+ (0, bun_test_1.it)('@Component({ id, name / tag / default }) 按名字、标签或默认选实现,类本身仍可直接取(F1)', async () => {
203
+ const Store = Symbol('Store');
204
+ let RedisStore = class RedisStore {
205
+ constructor() {
206
+ this.kind = 'redis';
207
+ }
208
+ };
209
+ RedisStore = __decorate([
210
+ (0, annotation_1.Component)({ id: Store, name: 'redis' })
211
+ ], RedisStore);
212
+ let EuStore = class EuStore {
213
+ constructor() {
214
+ this.kind = 'eu';
215
+ }
216
+ };
217
+ EuStore = __decorate([
218
+ (0, annotation_1.Component)({ id: Store, tag: { tag: 'region', value: 'eu' } })
219
+ ], EuStore);
220
+ let MemoryStore = class MemoryStore {
221
+ constructor() {
222
+ this.kind = 'memory';
223
+ }
224
+ };
225
+ MemoryStore = __decorate([
226
+ (0, annotation_1.Component)({ id: Store, default: true })
227
+ ], MemoryStore);
228
+ let Consumer = class Consumer {
229
+ };
230
+ __decorate([
231
+ (0, annotation_1.Autowired)(Store),
232
+ (0, annotation_1.Named)('redis'),
233
+ __metadata("design:type", Object)
234
+ ], Consumer.prototype, "redis", void 0);
235
+ __decorate([
236
+ (0, annotation_1.Autowired)(Store),
237
+ (0, annotation_1.Tagged)('region', 'eu'),
238
+ __metadata("design:type", Object)
239
+ ], Consumer.prototype, "eu", void 0);
240
+ __decorate([
241
+ (0, annotation_1.Autowired)(Store),
242
+ __metadata("design:type", Object)
243
+ ], Consumer.prototype, "fallback", void 0);
244
+ Consumer = __decorate([
245
+ (0, annotation_1.Component)()
246
+ ], Consumer);
247
+ await boot();
248
+ const c = container_util_1.ContainerUtil.get(Consumer);
249
+ (0, chai_1.expect)([c.redis.kind, c.eu.kind, c.fallback.kind]).to.deep.equal(['redis', 'eu', 'memory']);
250
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Store, { name: 'redis' })).to.equal(container_util_1.ContainerUtil.get(RedisStore));
251
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Store, { tags: { region: 'eu' } })).to.equal(container_util_1.ContainerUtil.get(EuStore));
252
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Store)).to.equal(container_util_1.ContainerUtil.get(MemoryStore));
253
+ });
254
+ (0, bun_test_1.it)('rebind: true 替换先加载的模块里的实现(应用覆盖框架或其他包的组件)', async () => {
255
+ const Mailer = Symbol('Mailer');
256
+ let DefaultMailer = class DefaultMailer {
257
+ constructor() {
258
+ this.who = 'default';
259
+ }
260
+ };
261
+ DefaultMailer = __decorate([
262
+ (0, annotation_1.Component)(Mailer)
263
+ ], DefaultMailer);
264
+ const base = (0, auto_bind_1.autoBind)();
265
+ let CustomMailer = class CustomMailer {
266
+ constructor() {
267
+ this.who = 'custom';
268
+ }
269
+ };
270
+ CustomMailer = __decorate([
271
+ (0, annotation_1.Component)({ id: Mailer, rebind: true })
272
+ ], CustomMailer);
273
+ const overrides = (0, auto_bind_1.autoBind)();
274
+ await application_factory_1.ApplicationFactory.create({}, base, overrides);
275
+ (0, chai_1.expect)(container_util_1.ContainerUtil.getAll(Mailer).map(m => m.who)).to.deep.equal(['custom']);
276
+ (0, chai_1.expect)([DefaultMailer, CustomMailer]).to.have.length(2);
277
+ });
278
+ (0, bun_test_1.it)('同一批 autoBind 里也可以 rebind 本批先定义的组件(按定义顺序登记)', async () => {
279
+ const Mailer = Symbol('SameBatchMailer');
280
+ let DefaultMailer = class DefaultMailer {
281
+ constructor() {
282
+ this.who = 'default';
283
+ }
284
+ };
285
+ DefaultMailer = __decorate([
286
+ (0, annotation_1.Component)(Mailer)
287
+ ], DefaultMailer);
288
+ let CustomMailer = class CustomMailer {
289
+ constructor() {
290
+ this.who = 'custom';
291
+ }
292
+ };
293
+ CustomMailer = __decorate([
294
+ (0, annotation_1.Component)({ id: Mailer, rebind: true })
295
+ ], CustomMailer);
296
+ await boot();
297
+ (0, chai_1.expect)(container_util_1.ContainerUtil.getAll(Mailer).map(m => m.who)).to.deep.equal(['custom']);
298
+ (0, chai_1.expect)([DefaultMailer, CustomMailer]).to.have.length(2);
299
+ });
300
+ (0, bun_test_1.it)('rebind 替换框架自带组件:替换后注入点拿到的是新实现', async () => {
301
+ let FixedConfig = class FixedConfig {
302
+ get(key) { return key === 'answer' ? 42 : undefined; }
303
+ };
304
+ FixedConfig = __decorate([
305
+ (0, annotation_1.Component)({ id: config_protocol_1.ConfigProvider, rebind: true })
306
+ ], FixedConfig);
307
+ let ReadsConfig = class ReadsConfig {
308
+ };
309
+ __decorate([
310
+ (0, annotation_1.Autowired)(config_protocol_1.ConfigProvider),
311
+ __metadata("design:type", FixedConfig)
312
+ ], ReadsConfig.prototype, "config", void 0);
313
+ ReadsConfig = __decorate([
314
+ (0, annotation_1.Component)()
315
+ ], ReadsConfig);
316
+ await boot();
317
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(ReadsConfig).config).to.be.instanceOf(FixedConfig);
318
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(ReadsConfig).config.get('answer')).to.equal(42);
319
+ });
320
+ (0, bun_test_1.it)('@Constant 登记常量,多个 id 都能取到', async () => {
321
+ const Token = Symbol('Token');
322
+ const Alias = Symbol('TokenAlias');
323
+ let Holder = class Holder {
324
+ };
325
+ Holder = __decorate([
326
+ (0, annotation_1.Constant)([Token, Alias], { secret: 'abc' })
327
+ ], Holder);
328
+ await boot();
329
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Token)).to.deep.equal({ secret: 'abc' });
330
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Alias)).to.equal(container_util_1.ContainerUtil.get(Token));
331
+ (0, chai_1.expect)(Holder).to.be.a('function');
332
+ });
333
+ (0, bun_test_1.it)('@AutowiredProvider 注入 Provider:按 priority 从小到大排序(sortSync)', async () => {
334
+ const Step = Symbol('Step');
335
+ let Late = class Late {
336
+ constructor() {
337
+ this.priority = 300;
338
+ this.name = 'late';
339
+ }
340
+ };
341
+ Late = __decorate([
342
+ (0, annotation_1.Component)(Step)
343
+ ], Late);
344
+ let Early = class Early {
345
+ constructor() {
346
+ this.priority = 100;
347
+ this.name = 'early';
348
+ }
349
+ };
350
+ Early = __decorate([
351
+ (0, annotation_1.Component)(Step)
352
+ ], Early);
353
+ let Middle = class Middle {
354
+ constructor() {
355
+ this.priority = 200;
356
+ this.name = 'middle';
357
+ }
358
+ };
359
+ Middle = __decorate([
360
+ (0, annotation_1.Component)(Step)
361
+ ], Middle);
362
+ let Pipeline = class Pipeline {
363
+ };
364
+ __decorate([
365
+ (0, annotation_1.AutowiredProvider)(Step),
366
+ __metadata("design:type", Object)
367
+ ], Pipeline.prototype, "steps", void 0);
368
+ Pipeline = __decorate([
369
+ (0, annotation_1.Component)()
370
+ ], Pipeline);
371
+ await boot();
372
+ const names = container_util_1.ContainerUtil.get(Pipeline).steps.sortSync().map(s => s.name);
373
+ (0, chai_1.expect)(names).to.have.members(['early', 'middle', 'late']);
374
+ // Prioritizeable:priority 大的排前面
375
+ (0, chai_1.expect)(names).to.deep.equal(['late', 'middle', 'early']);
376
+ (0, chai_1.expect)([Late, Early, Middle]).to.have.length(3);
377
+ });
378
+ (0, bun_test_1.it)('@PostConstruct 在注入完成后调用一次,单例只调用一次', async () => {
379
+ let calls = 0;
380
+ let Dep = class Dep {
381
+ constructor() {
382
+ this.ok = true;
383
+ }
384
+ };
385
+ Dep = __decorate([
386
+ (0, annotation_1.Component)()
387
+ ], Dep);
388
+ let Init = class Init {
389
+ constructor() {
390
+ this.seenDep = false;
391
+ }
392
+ init() {
393
+ calls++;
394
+ this.seenDep = this.dep.ok;
395
+ }
396
+ };
397
+ __decorate([
398
+ (0, annotation_1.Autowired)(),
399
+ __metadata("design:type", Dep)
400
+ ], Init.prototype, "dep", void 0);
401
+ __decorate([
402
+ (0, annotation_1.PostConstruct)(),
403
+ __metadata("design:type", Function),
404
+ __metadata("design:paramtypes", []),
405
+ __metadata("design:returntype", void 0)
406
+ ], Init.prototype, "init", null);
407
+ Init = __decorate([
408
+ (0, annotation_1.Component)()
409
+ ], Init);
410
+ await boot();
411
+ (0, chai_1.expect)(container_util_1.ContainerUtil.get(Init).seenDep).to.equal(true);
412
+ container_util_1.ContainerUtil.get(Init);
413
+ (0, chai_1.expect)(calls).to.equal(1);
414
+ });
415
+ (0, bun_test_1.it)('detached 的 @Autowired:不在容器里的对象也能按需从当前容器取值', async () => {
416
+ const Clock = Symbol('DetachedClock');
417
+ let Clk = class Clk {
418
+ now() { return 7; }
419
+ };
420
+ Clk = __decorate([
421
+ (0, annotation_1.Component)(Clock)
422
+ ], Clk);
423
+ class NotAComponent {
424
+ }
425
+ __decorate([
426
+ (0, annotation_1.Autowired)({ id: Clock, detached: true }),
427
+ __metadata("design:type", Clk)
428
+ ], NotAComponent.prototype, "clock", void 0);
429
+ await boot();
430
+ (0, chai_1.expect)(new NotAComponent().clock.now()).to.equal(7);
431
+ });
432
+ (0, bun_test_1.it)('detached 不支持构造器参数,给出明确的错误', () => {
433
+ (0, chai_1.expect)(() => {
434
+ let Bad = class Bad {
435
+ constructor(x) {
436
+ this.x = x;
437
+ }
438
+ };
439
+ Bad = __decorate([
440
+ __param(0, (0, annotation_1.Autowired)({ id: Symbol('x'), detached: true })),
441
+ __metadata("design:paramtypes", [Object])
442
+ ], Bad);
443
+ return Bad;
444
+ }).to.throw(/not supported/);
445
+ });
446
+ (0, bun_test_1.it)('每次 ApplicationFactory.create 都换成新的容器,ContainerUtil 指向最新的那个', async () => {
447
+ let Counter = class Counter {
448
+ constructor() {
449
+ this.value = 0;
450
+ }
451
+ };
452
+ Counter = __decorate([
453
+ (0, annotation_1.Component)()
454
+ ], Counter);
455
+ await boot();
456
+ const first = container_provider_1.ContainerProvider.provide();
457
+ container_util_1.ContainerUtil.get(Counter).value = 5;
458
+ await boot();
459
+ (0, chai_1.expect)(container_provider_1.ContainerProvider.provide()).not.to.equal(first);
460
+ // 新容器里没有再登记 Counter(元数据已被上一次 create 取走)
461
+ (0, chai_1.expect)(() => container_util_1.ContainerUtil.get(Counter)).to.throw();
462
+ });
463
+ });
464
+ //# sourceMappingURL=assembly.spec.js.map