@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,186 @@
1
+ import { describe, it, afterAll } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { ApplicationFactory } from '../application/application-factory';
4
+ import { Component, Value } from '../annotation';
5
+ import { ContainerUtil } from '../container/container-util';
6
+ import { ConfigUtil } from '../config/config-util';
7
+ import { ExpressionHandler } from './expression-protocol';
8
+
9
+ /**
10
+ * @Value、ConfigUtil 与 EL(${...},ExpressionEngine)的约定(阶段 1.E 行为测试)。
11
+ * 配置就是 ApplicationFactory.create() 的第一个参数(CLI 生成的入口会把合并后的 cell.yml 传进来)。
12
+ */
13
+ const boot = (props: Record<string, any>) => ApplicationFactory.create(props);
14
+ const el = () => ContainerUtil.get<ExpressionHandler>(ExpressionHandler);
15
+
16
+ describe('core @Value 与配置', () => {
17
+
18
+ it('@Value(key) 读配置;@Value() 不带参数时以属性名为 key', async () => {
19
+ @Component()
20
+ class Settings {
21
+ @Value('cell.name')
22
+ readonly name: string;
23
+ @Value()
24
+ readonly port: number;
25
+ }
26
+ await boot({ cell: { name: 'demo' }, port: 8080 });
27
+ const s = ContainerUtil.get(Settings);
28
+ expect(s.name).to.equal('demo');
29
+ expect(s.port).to.equal(8080);
30
+ });
31
+
32
+ it('值里的 ${...} 会求值,可以引用其他配置,多层引用也会继续求值', async () => {
33
+ @Component()
34
+ class Urls {
35
+ @Value('cell.url')
36
+ readonly url: string;
37
+ @Value('cell.chain')
38
+ readonly chain: string;
39
+ }
40
+ await boot({ cell: { host: 'example.com', url: 'https://${cell.host}:443/api', chain: '${cell.url}', } });
41
+ const u = ContainerUtil.get(Urls);
42
+ expect(u.url).to.equal('https://example.com:443/api');
43
+ expect(u.chain).to.equal('https://example.com:443/api');
44
+ });
45
+
46
+ it('取对象时,对象里的字符串也会求值;取不到的 key 为 undefined', async () => {
47
+ @Component()
48
+ class Db {
49
+ @Value('cell.db')
50
+ readonly db: { host: string, port: number, hosts: string[] };
51
+ @Value('cell.missing.deep')
52
+ readonly missing?: unknown;
53
+ }
54
+ await boot({ cell: { region: 'eu', db: { host: 'db.${cell.region}.local', port: 5432, hosts: ['a.${cell.region}', 'b'] } } });
55
+ const d = ContainerUtil.get(Db);
56
+ expect(d.db).to.deep.equal({ host: 'db.eu.local', port: 5432, hosts: ['a.eu', 'b'] });
57
+ expect(d.missing).to.equal(undefined);
58
+ });
59
+
60
+ it('构造器参数也能用 @Value', async () => {
61
+ @Component()
62
+ class WithCtor {
63
+ constructor(@Value('cell.size') readonly size: number) { }
64
+ }
65
+ await boot({ cell: { size: 3 } });
66
+ expect(ContainerUtil.get(WithCtor).size).to.equal(3);
67
+ });
68
+
69
+ it('detached 的 @Value:不在容器里的对象每次读取都取当前容器的配置', async () => {
70
+ class Plain {
71
+ @Value({ el: 'cell.mode', detached: true })
72
+ readonly mode: string;
73
+ }
74
+ const p = new Plain();
75
+ await boot({ cell: { mode: 'a' } });
76
+ expect(p.mode).to.equal('a');
77
+ await boot({ cell: { mode: 'b' } });
78
+ expect(p.mode).to.equal('b');
79
+ });
80
+
81
+ it('ConfigUtil.get:取值、默认值', async () => {
82
+ await boot({ cell: { a: 1, ref: '${cell.a}' } });
83
+ expect(ConfigUtil.get('cell.a')).to.equal(1);
84
+ expect(ConfigUtil.get('cell.ref')).to.equal(1);
85
+ expect(ConfigUtil.get('cell.none', 'dflt')).to.equal('dflt');
86
+ });
87
+
88
+ it('现状:create() 过程中第一次求值就会就地改写传入的配置对象,getRaw() 拿到的也是求值后的结果', async () => {
89
+ // expression-handler.ts getContext():第一次拿到上下文时 this.handle(c, c),把整份配置原地求值;
90
+ // 创建 Application 时注入的组件(如 Logger)读配置,这一步在 create() 返回前就发生了
91
+ const props = { cell: { a: 1, ref: '${cell.a}' as unknown, nested: ['${cell.a}'] as unknown[] } };
92
+ await boot(props);
93
+ expect(ConfigUtil.getRaw()).to.equal(props);
94
+ expect(props.cell.ref).to.equal(1);
95
+ expect(props.cell.nested[0]).to.equal(1);
96
+ });
97
+
98
+ it('false、0、空串都是有效的值:@Value 拿得到,ConfigUtil.get 只在值为 undefined 时用默认值(F3)', async () => {
99
+ @Component()
100
+ class Flags {
101
+ @Value('cell.enabled')
102
+ readonly enabled: boolean;
103
+ @Value('cell.retries')
104
+ readonly retries: number;
105
+ @Value('cell.prefix')
106
+ readonly prefix: string;
107
+ }
108
+ await boot({ cell: { enabled: false, retries: 0, prefix: '' } });
109
+ const f = ContainerUtil.get(Flags);
110
+ expect(f.enabled).to.equal(false);
111
+ expect(f.retries).to.equal(0);
112
+ expect(f.prefix).to.equal('');
113
+ expect(ConfigUtil.get('cell.retries', 3)).to.equal(0);
114
+ expect(ConfigUtil.get('cell.enabled', true)).to.equal(false);
115
+ expect(ConfigUtil.get('cell.missing', 3)).to.equal(3);
116
+ });
117
+ });
118
+
119
+ describe('core EL(ExpressionHandler)', () => {
120
+ const ENV_KEY = 'CELL_T13_EL_PROBE';
121
+ afterAll(() => {
122
+ delete process.env[ENV_KEY];
123
+ });
124
+
125
+ it('没有 ${ 的文本原样返回;只有一个表达式时保留类型,混排时拼成字符串', async () => {
126
+ await boot({ cell: { n: 2 } });
127
+ expect(el().handle('plain text')).to.equal('plain text');
128
+ expect(el().handle('${cell.n + 1}')).to.equal(3);
129
+ expect(el().handle('${cell.n > 1}')).to.equal(true);
130
+ expect(el().handle('n=${cell.n}, n2=${cell.n * cell.n}')).to.equal('n=2, n2=4');
131
+ });
132
+
133
+ it('表达式的运算、三元、字符串里的 } 都能正确切分', async () => {
134
+ await boot({ cell: { port: 3000, name: 'x' } });
135
+ expect(el().handle('${cell.port > 1000 ? "high" : "low"}')).to.equal('high');
136
+ expect(el().handle('${"a}b" + cell.name}')).to.equal('a}bx');
137
+ expect(el().handle('[${cell.name}]')).to.equal('[x]');
138
+ });
139
+
140
+ it('现状:反斜杠转义只阻止求值,反斜杠本身留在结果里', async () => {
141
+ await boot({ cell: { name: 'x' } });
142
+ expect(el().handle('cost \\${cell.name}')).to.equal('cost \\${cell.name}');
143
+ });
144
+
145
+ it.todo('期望:\\${...} 得到字面量 ${...}(去掉转义符),否则配置里无法写出 ${', () => { });
146
+
147
+ it('内置 transform:replace、regexp、eval', async () => {
148
+ await boot({ cell: { name: 'svc', tpl: '${cell.name}-v1' } });
149
+ expect(el().handle('${"a-b-c"|replace("-", "_")}')).to.equal('a_b_c');
150
+ const re = el().handle('${"^ab+$"|regexp("i")}');
151
+ expect(re).to.be.instanceOf(RegExp);
152
+ expect(re.test('ABBB')).to.equal(true);
153
+ expect(el().handle('${"${cell.name}"|eval}')).to.equal('svc');
154
+ });
155
+
156
+ it('可以传入自己的上下文;未定义的变量为 undefined', async () => {
157
+ await boot({});
158
+ expect(el().handle('${a.b * 2}', { a: { b: 21 } })).to.equal(42);
159
+ expect(el().handle('${nothing.here}', {})).to.equal(undefined);
160
+ });
161
+
162
+ it('处理对象时就地求值;带 _ignoreEl 的子对象不求值', async () => {
163
+ await boot({ cell: { v: 'ok' } });
164
+ const obj = { a: '${cell.v}', nested: { b: ['${cell.v}!'] }, raw: { _ignoreEl: true, c: '${cell.v}' } };
165
+ const out = el().handle(obj);
166
+ expect(out).to.equal(obj);
167
+ expect(obj.a).to.equal('ok');
168
+ expect(obj.nested.b[0]).to.equal('ok!');
169
+ expect(obj.raw.c).to.equal('${cell.v}');
170
+ });
171
+
172
+ it('env 是进程环境变量(遍历整份配置时 env 子树带 _ignoreEl,不会被就地求值)', async () => {
173
+ process.env[ENV_KEY] = 'plain-value';
174
+ await boot({ cell: {} });
175
+ expect(el().handle(`\${env.${ENV_KEY}}`)).to.equal('plain-value');
176
+ expect(ConfigUtil.getRaw().env?.[ENV_KEY]).to.equal('plain-value');
177
+ });
178
+
179
+ it('来自 env 的字符串不再求值,经配置间接引用时也一样(F6)', async () => {
180
+ process.env[ENV_KEY] = '${cell.other}';
181
+ await boot({ cell: { other: 'from-config', viaEnv: `\${env.${ENV_KEY}}`, viaKey: '${cell.viaEnv}' } });
182
+ expect(el().handle(`\${env.${ENV_KEY}}`)).to.equal('${cell.other}');
183
+ expect(el().handle('${cell.viaEnv}')).to.equal('${cell.other}');
184
+ expect(el().handle('${cell.viaKey}')).to.equal('${cell.other}');
185
+ });
186
+ });
@@ -1,5 +1,5 @@
1
1
  import { Autowired, Optional, Value } from '../annotation';
2
- import { Logger, LOGGER_LEVEL, LogLevel, onLogEmitter, TraceIdProvider } from './logger-protocol';
2
+ import { Logger, LOGGER_LEVEL, LOG_LEVELS, LogLevel, onLogEmitter, TraceIdProvider } from './logger-protocol';
3
3
 
4
4
  export abstract class AbstractLogger implements Logger {
5
5
  protected instance: Logger;
@@ -24,18 +24,24 @@ export abstract class AbstractLogger implements Logger {
24
24
  return context ? `[${context}] ` : '';
25
25
  }
26
26
 
27
- protected resolvePrefix(): string {
27
+ isEnabled(level: LogLevel): boolean {
28
+ const configured = LOG_LEVELS.indexOf(this.level);
29
+ return LOG_LEVELS.indexOf(level) >= (configured < 0 ? LOG_LEVELS.indexOf('info') : configured);
30
+ }
31
+
32
+ /** `level` is the level of the message, not the configured one. */
33
+ protected resolvePrefix(level: LogLevel): string {
28
34
  const time = new Date().toISOString();
29
- return `${time} [${this.level}]`;
35
+ return `${time} [${level}]`;
30
36
  }
31
37
 
32
- protected log(message: any, context?: string, logFn: (...args: any[]) => void = console.info): void {
38
+ protected log(message: any, context?: string, logFn: (...args: any[]) => void = console.info, level: LogLevel = 'info'): void {
33
39
  const traceId = this.traceIdProvider?.provide();
34
40
  const traceStr = traceId ? ` [trace: ${traceId}]` : '';
35
41
  const contextStr = this.resolveContextString(context);
36
- logFn(`${this.resolvePrefix()}${traceStr}${contextStr}${message}`);
42
+ logFn(`${this.resolvePrefix(level)}${traceStr}${contextStr}${message}`);
37
43
  onLogEmitter.fire({
38
- level: this.level,
44
+ level,
39
45
  traceId,
40
46
  rootContext: this.context,
41
47
  context,
@@ -7,6 +7,9 @@ export const TraceIdProvider = Symbol('TraceIdProvider');
7
7
  export const LoggerService = Symbol('LoggerService');
8
8
 
9
9
  export type LogLevel = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
10
+
11
+ /** Levels from the most to the least verbose: a logger at a level writes that level and the ones after it. */
12
+ export const LOG_LEVELS: readonly LogLevel[] = ['verbose', 'debug', 'info', 'warn', 'error'];
10
13
  export interface LogMessage {
11
14
  level: LogLevel;
12
15
  traceId?: string;
@@ -25,6 +28,8 @@ export interface Logger {
25
28
  error(message: any, context?: string): void;
26
29
  warn(message: any, context?: string): void;
27
30
  debug(message: any, context?: string): void;
31
+ /** Whether messages of `level` are written; check it before building an expensive message. */
32
+ isEnabled(level: LogLevel): boolean;
28
33
  time(label: string): void;
29
34
  timeEnd(label: string, context?: string): number | undefined;
30
35
 
@@ -0,0 +1,61 @@
1
+ import { afterEach, describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { LoggerImpl } from './logger';
4
+ import { LogLevel, LogMessage, onLogEmitter } from './logger-protocol';
5
+
6
+ const consoleFns = ['info', 'warn', 'error', 'debug'] as const;
7
+ const originals = Object.fromEntries(consoleFns.map(name => [name, console[name]]));
8
+
9
+ function capture(level: LogLevel) {
10
+ const lines: { fn: string; text: string }[] = [];
11
+ for (const name of consoleFns) {
12
+ console[name] = (text: string) => lines.push({ fn: name, text });
13
+ }
14
+ const logger = new LoggerImpl();
15
+ Object.assign(logger, { level });
16
+ return { logger, lines };
17
+ }
18
+
19
+ afterEach(() => Object.assign(console, originals));
20
+
21
+ describe('LoggerImpl', () => {
22
+ it('labels each line with the level of the message, not the configured one', () => {
23
+ const { logger, lines } = capture('debug');
24
+ logger.debug('d');
25
+ logger.info('i');
26
+ logger.warn('w');
27
+ logger.error('e');
28
+ expect(lines.map(l => [l.fn, /\[(\w+)\]/.exec(l.text)?.[1], l.text.slice(-1)])).to.deep.equal([
29
+ ['debug', 'debug', 'd'],
30
+ ['info', 'info', 'i'],
31
+ ['warn', 'warn', 'w'],
32
+ ['error', 'error', 'e'],
33
+ ]);
34
+ });
35
+
36
+ it('writes the configured level and the ones after it', () => {
37
+ const { logger, lines } = capture('warn');
38
+ logger.debug('d');
39
+ logger.info('i');
40
+ logger.warn('w');
41
+ logger.error('e');
42
+ expect(lines.map(l => l.fn)).to.deep.equal(['warn', 'error']);
43
+ expect([logger.isEnabled('verbose'), logger.isEnabled('debug'), logger.isEnabled('info'), logger.isEnabled('warn'), logger.isEnabled('error')])
44
+ .to.deep.equal([false, false, false, true, true]);
45
+ });
46
+
47
+ it('treats an unknown configured level as info', () => {
48
+ const { logger } = capture('loud' as LogLevel);
49
+ expect(logger.isEnabled('debug')).to.equal(false);
50
+ expect(logger.isEnabled('info')).to.equal(true);
51
+ });
52
+
53
+ it('reports the level of the message to onLog', () => {
54
+ const { logger } = capture('info');
55
+ const seen: LogMessage[] = [];
56
+ const listener = onLogEmitter.event(m => seen.push(m));
57
+ logger.warn('w');
58
+ listener.dispose();
59
+ expect(seen.map(m => [m.level, m.message])).to.deep.equal([['warn', 'w']]);
60
+ });
61
+ });
@@ -7,24 +7,24 @@ import { Logger } from './logger-protocol';
7
7
  export class LoggerImpl extends AbstractLogger {
8
8
 
9
9
  error(message: any, context?: string): void {
10
- this.log(message, context, console.error.bind(console));
10
+ this.log(message, context, console.error.bind(console), 'error');
11
11
  }
12
12
 
13
13
  info(message: any, context?: string): void {
14
- if (['info', 'debug'].includes(this.level)) {
15
- this.log(message, context);
14
+ if (this.isEnabled('info')) {
15
+ this.log(message, context, console.info.bind(console), 'info');
16
16
  }
17
17
  }
18
18
 
19
19
  warn(message: any, context?: string): void {
20
- if (['info', 'debug', 'warn'].includes(this.level)) {
21
- this.log(message, context, console.warn.bind(console));
20
+ if (this.isEnabled('warn')) {
21
+ this.log(message, context, console.warn.bind(console), 'warn');
22
22
  }
23
23
  }
24
24
 
25
25
  debug(message: any, context?: string): void {
26
- if (this.level === 'debug') {
27
- this.log(message, context, console.debug.bind(console));
26
+ if (this.isEnabled('debug')) {
27
+ this.log(message, context, console.debug.bind(console), 'debug');
28
28
  }
29
29
  }
30
30
 
@@ -1,6 +1,4 @@
1
1
  export * from './component-filter-registry';
2
2
  export * from './provider';
3
- export * from './provider-creator';
4
3
  export * from './provider-protocol';
5
4
  export * from './provider-util';
6
-
@@ -1,20 +1,15 @@
1
- import { ComponentId } from '../annotation/component';
2
- import { Container } from '../container';
1
+ import type { ComponentId } from '../container/container';
3
2
  import { Prioritizeable } from '../utils/prioritizeable';
4
3
 
5
- export const ProviderCreator = Symbol('ProviderCreator');
6
4
  export const ComponentFilter = Symbol('ComponentFilter');
7
5
  export const ComponentFilterRegistry = Symbol('ComponentFilterRegistry');
8
6
  export const ComponentFilterContribution = Symbol('ComponentFilterContribution');
9
7
 
8
+ /** The components of an identifier, created when first asked for; what `@AutowiredProvider` injects. */
10
9
  export interface Provider<T extends object> {
11
- get(recursive?: boolean): T[];
12
- sortSync(getPriority?: Prioritizeable.GetPrioritySync<T>, recursive?: boolean): T[];
13
- sort(getPriority?: Prioritizeable.GetPriority<T> , recursive?: boolean): Promise<T[]>;
14
- }
15
-
16
- export interface ProviderCreator<T extends object> {
17
- create(id: ComponentId, container: Container): Provider<T>;
10
+ get(): T[];
11
+ sortSync(getPriority?: Prioritizeable.GetPrioritySync<T>): T[];
12
+ sort(getPriority?: Prioritizeable.GetPriority<T>): Promise<T[]>;
18
13
  }
19
14
 
20
15
  /**
@@ -23,7 +18,6 @@ export interface ProviderCreator<T extends object> {
23
18
  */
24
19
  export type ComponentFilter<T extends Object> = (toTest: T) => boolean;
25
20
 
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
21
  export type ComponentType = ComponentId;
28
22
 
29
23
  export interface ComponentFilterRegistry {
@@ -1,10 +1,10 @@
1
1
  import { PROVIDER, ID_KEY } from '../annotation/autowired-provider';
2
- import { ComponentId } from '../annotation/component';
3
- import { ContainerUtil } from '../container';
2
+ import type { ComponentId } from '../container/container';
3
+ import { ContainerUtil } from '../container/container-util';
4
4
  import { Provider } from './provider-protocol';
5
5
 
6
6
  export namespace ProviderUtil {
7
7
  export function get<T extends Object>(componentId: ComponentId<T>): Provider<T> {
8
- return ContainerUtil.getTagged(PROVIDER, ID_KEY, componentId);
8
+ return ContainerUtil.get(PROVIDER, { tags: { [ID_KEY]: componentId } });
9
9
  }
10
10
  }
@@ -1,7 +1,7 @@
1
- import { ComponentId } from '../annotation/component';
1
+ import type { Binding, ComponentId, Container } from '../container/container';
2
2
  import { Provider, ComponentFilterRegistry } from './provider-protocol';
3
- import { Container } from '../container';
4
- import { Prioritizeable } from '../utils';
3
+ import { Prioritizeable } from '../utils/prioritizeable';
4
+ import { ID_KEY, PROVIDER } from '../annotation/autowired-provider';
5
5
 
6
6
  const DEFAULT_GET_PRIORITY: Prioritizeable.GetPrioritySync<any> = value => {
7
7
  if (value) {
@@ -23,41 +23,29 @@ export class ContainerBasedProvider<T extends object> implements Provider<T> {
23
23
  protected readonly container: Container
24
24
  ) { }
25
25
 
26
- get(recursive?: boolean): T[] {
26
+ get(): T[] {
27
27
  if (this.components === undefined) {
28
- const currentComponents: T[] = [];
29
- let filterRegistry: ComponentFilterRegistry | undefined;
30
- let currentContainer: Container | null = this.container;
31
- // eslint-disable-next-line no-null/no-null
32
- while (currentContainer !== null) {
33
- if (currentContainer.isBound(this.componentId)) {
34
- try {
35
- currentComponents.push(...currentContainer.getAll(this.componentId));
36
- } catch (error) {
37
- console.error(error);
38
- }
39
- }
40
- if (filterRegistry === undefined && currentContainer.isBound(ComponentFilterRegistry)) {
41
- filterRegistry = currentContainer.get(ComponentFilterRegistry);
42
- }
43
- // eslint-disable-next-line no-null/no-null
44
- currentContainer = recursive === true ? currentContainer.parent : null;
45
- }
46
-
47
- this.components = filterRegistry ? filterRegistry.applyFilters(currentComponents, this.componentId) : currentComponents;
48
-
28
+ const components = this.container.isBound(this.componentId) ? this.container.getAll<T>(this.componentId) : [];
29
+ const filterRegistry = this.container.isBound(ComponentFilterRegistry)
30
+ ? this.container.get<ComponentFilterRegistry>(ComponentFilterRegistry) : undefined;
31
+ this.components = filterRegistry ? filterRegistry.applyFilters(components, this.componentId) : components;
49
32
  }
50
33
  return this.components;
51
34
  }
52
35
 
53
- sortSync(getPriority: Prioritizeable.GetPrioritySync<T> = DEFAULT_GET_PRIORITY, recursive?: boolean): T[] {
54
- this.components = Prioritizeable.prioritizeAllSync<T>(this.get(recursive), getPriority).map(c => c.value);
36
+ sortSync(getPriority: Prioritizeable.GetPrioritySync<T> = DEFAULT_GET_PRIORITY): T[] {
37
+ this.components = Prioritizeable.prioritizeAllSync<T>(this.get(), getPriority).map(c => c.value);
55
38
  return this.components;
56
39
  }
57
40
 
58
- async sort(getPriority: Prioritizeable.GetPriority<T> = DEFAULT_GET_PRIORITY, recursive?: boolean): Promise<T[]> {
59
- const result = await Prioritizeable.prioritizeAll<T>(this.get(recursive), getPriority);
41
+ async sort(getPriority: Prioritizeable.GetPriority<T> = DEFAULT_GET_PRIORITY): Promise<T[]> {
42
+ const result = await Prioritizeable.prioritizeAll<T>(this.get(), getPriority);
60
43
  this.components = result.map<T>(c => c.value);
61
44
  return this.components;
62
45
  }
63
46
  }
47
+
48
+ /** `@AutowiredProvider(id)` is an injection of `PROVIDER` tagged with the id: a provider of its components. */
49
+ export function bindAutowiredProvider(bind: <B>(id: ComponentId<B>) => Binding<B>): void {
50
+ bind(PROVIDER).toDynamicValue(ctx => new ContainerBasedProvider(ctx.target.tags![ID_KEY] as ComponentId<object>, ctx.container));
51
+ }
@@ -1,6 +1,6 @@
1
1
  import './index';
2
2
  import { bindValue } from './annotation/value';
3
- import { bindAutowiredProvider } from './annotation/autowired-provider';
3
+ import { bindAutowiredProvider } from './provider/provider';
4
4
  import { autoBind } from './container/auto-bind';
5
5
 
6
6
  export default autoBind(bind => {
@@ -1,8 +1,6 @@
1
- import { Injectable } from '../annotation';
2
1
  import { Logger, LogLevel, LogMessage } from '../logger/logger-protocol';
3
2
  import { Emitter } from '../utils';
4
3
 
5
- @Injectable()
6
4
  export class MockLogger implements Logger {
7
5
  level: LogLevel = 'info';
8
6
  protected readonly onLogEmitter = new Emitter<LogMessage>();
@@ -28,4 +26,7 @@ export class MockLogger implements Logger {
28
26
  debug(message: any, context?: string): void {
29
27
  // do nothing
30
28
  }
29
+ isEnabled(level: LogLevel): boolean {
30
+ return false;
31
+ }
31
32
  }
@@ -1,5 +1,5 @@
1
- import { bindAutowiredProvider } from '../annotation/autowired-provider';
2
1
  import { bindValue } from '../annotation/value';
2
+ import { bindAutowiredProvider } from '../provider/provider';
3
3
  import { autoBind } from '../container';
4
4
  import { Logger } from '../logger';
5
5
  import { MockLogger } from './mock-logger';
@@ -12,10 +12,10 @@ export namespace AnnotationUtil {
12
12
 
13
13
  export function getType(target: any, targetKey: string | symbol, index?: number) {
14
14
  if (index !== undefined) {
15
- return Reflect.getMetadata('design:paramtypes', target, targetKey)[index];
15
+ return Reflect.getMetadata('design:paramtypes', target, targetKey)?.[index];
16
16
  } else {
17
17
  return Reflect.getMetadata('design:type', target, targetKey);
18
18
  }
19
19
  }
20
20
 
21
- }
21
+ }
@@ -1,4 +1,4 @@
1
- import { Event, Callback, CallbackList } from './event';
1
+ import { Event, CallbackList } from './event';
2
2
  import { Disposable } from './disposable';
3
3
  import { MaybePromise } from './prioritizeable';
4
4
 
@@ -204,65 +204,3 @@ export namespace WaitUntilEvent {
204
204
  }
205
205
  }
206
206
  }
207
-
208
- import { CancellationToken } from './cancellation';
209
-
210
- export class AsyncEmitter<T extends WaitUntilEvent> extends Emitter<T> {
211
-
212
- protected deliveryQueue: Promise<void> | undefined;
213
-
214
- /**
215
- * Fire listeners async one after another.
216
- */
217
- override fire(event: Omit<T, 'waitUntil'>, token: CancellationToken = CancellationToken.None,
218
- promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void> {
219
- const callbacks = this._callbacks;
220
- if (!callbacks) {
221
- return Promise.resolve();
222
- }
223
- const listeners = [...callbacks];
224
- if (this.deliveryQueue) {
225
- return this.deliveryQueue = this.deliveryQueue.then(() => this.deliver(listeners, event, token, promiseJoin));
226
- }
227
- return this.deliveryQueue = this.deliver(listeners, event, token, promiseJoin);
228
- }
229
-
230
- protected async deliver(listeners: Callback[], event: Omit<T, 'waitUntil'>, token: CancellationToken,
231
- promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void> {
232
- for (const listener of listeners) {
233
- if (token.isCancellationRequested) {
234
- return;
235
- }
236
- const waitables: Promise<void>[] = [];
237
- const asyncEvent = Object.assign(event, {
238
- waitUntil: (thenable: Promise<any>) => {
239
- if (Object.isFrozen(waitables)) {
240
- throw new Error('waitUntil cannot be called asynchronously.');
241
- }
242
- if (promiseJoin) {
243
- thenable = promiseJoin(thenable, listener);
244
- }
245
- waitables.push(thenable);
246
- }
247
- }) as T;
248
- try {
249
- listener(event);
250
- // Asynchronous calls to `waitUntil` should fail.
251
- Object.freeze(waitables);
252
- } catch (e) {
253
- console.error(e);
254
- } finally {
255
- delete (asyncEvent as any)['waitUntil'];
256
- }
257
- if (!waitables.length) {
258
- return;
259
- }
260
- try {
261
- await Promise.all(waitables);
262
- } catch (e) {
263
- console.error(e);
264
- }
265
- }
266
- }
267
-
268
- }
@@ -110,7 +110,7 @@ export abstract class MimeTypeUtils {
110
110
  if (!mimeTypes) {
111
111
  return [];
112
112
  }
113
- return this.tokenize(mimeTypes).filter(mimeType => !!mimeType).map(this.parseMimeType);
113
+ return this.tokenize(mimeTypes).filter(mimeType => !!mimeType).map(mimeType => this.parseMimeType(mimeType));
114
114
  }
115
115
 
116
116
  static tokenize(mimeTypes: string): string[] {
@@ -57,7 +57,7 @@ export class MimeType {
57
57
  this.subtype = subtype.toLowerCase();
58
58
  if (parameters) {
59
59
  const map: Map<string, string> = new Map();
60
- for (const [key, value] of Object.entries(parameters)) {
60
+ for (const [key, value] of parameters.entries()) {
61
61
  this.checkParameters(key, value);
62
62
  map.set(key.toLowerCase(), value);
63
63
  }
@@ -1,36 +1,16 @@
1
- let resolveMode = false;
1
+ /** What a proxy of a component (AOP) answers with the object it wraps. */
2
+ export const PROXY_TARGET = Symbol.for('@celljs/core/proxy-target');
2
3
 
3
- export function isResolveMode(): boolean {
4
- return resolveMode;
4
+ /** The object behind a component proxy, or the object itself. */
5
+ export function getTarget(obj: any): any {
6
+ return obj?.[PROXY_TARGET] ?? obj;
5
7
  }
6
8
 
9
+ /** The class of the object behind a component proxy, or of the object itself. */
7
10
  export function getTargetClass(obj: any): any {
8
- try {
9
- resolveMode = true;
10
- const target = obj.target;
11
- return target ? target.constructor : obj.constructor;
12
-
13
- } finally {
14
- resolveMode = false;
15
- }
16
- }
17
-
18
- export function getTarget(obj: any): any {
19
- try {
20
- resolveMode = true;
21
- const target = obj.target;
22
- return target || obj;
23
-
24
- } finally {
25
- resolveMode = false;
26
- }
11
+ return getTarget(obj)?.constructor;
27
12
  }
28
13
 
29
14
  export function isProxy(obj: any): boolean {
30
- try {
31
- resolveMode = true;
32
- return !!obj.target;
33
- } finally {
34
- resolveMode = false;
35
- }
15
+ return obj?.[PROXY_TARGET] !== undefined;
36
16
  }