@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,259 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ // 通过 common 入口导入:直接深导入 utils/mime-type-util 会因 error 模块的循环依赖拿到未初始化的 CustomError
4
+ import {
5
+ UrlUtil, ByteUtil, isUUID, generateUUUID, Emitter, Event, Disposable, DisposableCollection,
6
+ CancellationTokenSource, CancellationToken, cancelled, isCancelled, checkCancelled,
7
+ MimeTypeUtils, MimeType, WaitUntilEvent, InvalidMimeTypeError, IllegalArgumentError
8
+ } from '../index';
9
+
10
+ /**
11
+ * core 常用工具的约定(阶段 1.E 行为测试)。只测公开 API 的输入输出。
12
+ */
13
+ describe('core utils:UrlUtil.join', () => {
14
+ it('拼接时合并多余的斜杠,保留协议,第一个片段的开头和最后一个片段的结尾各保留一个', () => {
15
+ expect(UrlUtil.join('http://a.com/', '/api/', '/users')).to.equal('http://a.com/api/users');
16
+ expect(UrlUtil.join('/base/', 'x/')).to.equal('/base/x/');
17
+ expect(UrlUtil.join('http:', 'a.com', 'b')).to.equal('http://a.com/b');
18
+ expect(UrlUtil.join('file:///', 'tmp', 'f')).to.equal('file:///tmp/f');
19
+ expect(UrlUtil.join('a', '', 'b')).to.equal('a/b');
20
+ expect(UrlUtil.join()).to.equal('');
21
+ });
22
+
23
+ it('查询串:多个 ? 合成一个,后面的改成 &;? 前的斜杠去掉', () => {
24
+ expect(UrlUtil.join('http://a.com/', '?x=1', '?y=2')).to.equal('http://a.com?x=1&y=2');
25
+ expect(UrlUtil.join('/p/', '#hash')).to.equal('/p#hash');
26
+ });
27
+
28
+ it('不是字符串时抛 TypeError', () => {
29
+ expect(() => UrlUtil.join(1 as any)).to.throw(TypeError);
30
+ expect(() => UrlUtil.join('a', 2 as any)).to.throw(TypeError);
31
+ });
32
+ });
33
+
34
+ describe('core utils:ByteUtil 与 UUID', () => {
35
+ it('decode:字符串原样返回,Buffer/Uint8Array 按 UTF-8 解码,空值为空串', () => {
36
+ expect(ByteUtil.decode('文本')).to.equal('文本');
37
+ expect(ByteUtil.decode(Buffer.from('中文🙂'))).to.equal('中文🙂');
38
+ expect(ByteUtil.decode(new TextEncoder().encode('ok'))).to.equal('ok');
39
+ expect(ByteUtil.decode(undefined as any)).to.equal('');
40
+ expect(() => ByteUtil.decode({} as any)).to.throw(IllegalArgumentError);
41
+ });
42
+
43
+ it('base64 编解码往返', () => {
44
+ const b64 = ByteUtil.encodeBase64('héllo 世界');
45
+ expect(b64).to.equal(Buffer.from('héllo 世界').toString('base64'));
46
+ expect(ByteUtil.decode(ByteUtil.decodeBase64(b64))).to.equal('héllo 世界');
47
+ expect(ByteUtil.encodeBase64(new Uint8Array([0, 255]))).to.equal('AP8=');
48
+ expect(ByteUtil.encodeBase64('')).to.equal('');
49
+ expect(ByteUtil.decodeBase64('')).to.have.length(0);
50
+ });
51
+
52
+ it('generateUUUID 生成 v4 UUID,互不重复;isUUID 校验格式', () => {
53
+ const ids = new Set(Array.from({ length: 200 }, () => generateUUUID()));
54
+ expect(ids.size).to.equal(200);
55
+ for (const id of ids) {
56
+ expect(isUUID(id)).to.equal(true);
57
+ expect(id[14]).to.equal('4');
58
+ }
59
+ expect(isUUID('not-a-uuid')).to.equal(false);
60
+ expect(isUUID('3F2504E0-4F89-11D3-9A0C-0305E82C3301')).to.equal(true);
61
+ });
62
+ });
63
+
64
+ describe('core utils:Emitter / Event / Disposable', () => {
65
+ it('fire 通知所有监听器;dispose 后的监听器不再收到;thisArgs 生效', () => {
66
+ const emitter = new Emitter<number>();
67
+ const got: number[] = [];
68
+ const ctx = { factor: 10 };
69
+ const d1 = emitter.event(n => got.push(n));
70
+ emitter.event(function (this: typeof ctx, n: number) { got.push(n * this.factor); }, ctx);
71
+ emitter.fire(1);
72
+ d1.dispose();
73
+ d1.dispose();
74
+ emitter.fire(2);
75
+ expect(got).to.deep.equal([1, 10, 20]);
76
+ });
77
+
78
+ it('监听器抛错不影响其他监听器', () => {
79
+ const emitter = new Emitter<string>();
80
+ const got: string[] = [];
81
+ const origError = console.error;
82
+ console.error = () => { };
83
+ try {
84
+ emitter.event(() => { throw new Error('bad'); });
85
+ emitter.event(s => got.push(s));
86
+ emitter.fire('x');
87
+ } finally {
88
+ console.error = origError;
89
+ }
90
+ expect(got).to.deep.equal(['x']);
91
+ });
92
+
93
+ it('onFirstListenerAdd / onLastListenerRemove;disposables 数组会收到订阅句柄', () => {
94
+ const log: string[] = [];
95
+ const emitter = new Emitter<void>({ onFirstListenerAdd: () => log.push('first'), onLastListenerRemove: () => log.push('last') });
96
+ const bucket: Disposable[] = [];
97
+ emitter.event(() => { }, undefined, bucket);
98
+ emitter.event(() => { }, undefined, bucket);
99
+ expect(bucket).to.have.length(2);
100
+ bucket.forEach(d => d.dispose());
101
+ expect(log).to.deep.equal(['first', 'last']);
102
+ });
103
+
104
+ it('emitter.dispose 之后 fire 不再通知', () => {
105
+ const emitter = new Emitter<number>();
106
+ const got: number[] = [];
107
+ emitter.event(n => got.push(n));
108
+ emitter.dispose();
109
+ emitter.fire(1);
110
+ expect(got).to.deep.equal([]);
111
+ });
112
+
113
+ it('Event.map 转换事件值;Event.None 订阅无效果', () => {
114
+ const emitter = new Emitter<number>();
115
+ const got: string[] = [];
116
+ Event.map(emitter.event, n => `#${n}`)(s => got.push(s));
117
+ emitter.fire(7);
118
+ expect(got).to.deep.equal(['#7']);
119
+ Event.None(() => { throw new Error('never'); }).dispose();
120
+ });
121
+
122
+ it('DisposableCollection:倒序释放,只触发一次 onDispose;单个元素可单独移除', () => {
123
+ const order: string[] = [];
124
+ const coll = new DisposableCollection(Disposable.create(() => order.push('a')));
125
+ coll.push(Disposable.create(() => order.push('b')));
126
+ const removable = coll.push(Disposable.create(() => order.push('c')));
127
+ let fired = 0;
128
+ coll.onDispose(() => fired++);
129
+ removable.dispose();
130
+ expect(coll.disposed).to.equal(false);
131
+ coll.dispose();
132
+ coll.dispose();
133
+ expect(order).to.deep.equal(['b', 'a']);
134
+ expect(coll.disposed).to.equal(true);
135
+ expect(fired).to.equal(1);
136
+ expect(Disposable.is(coll)).to.equal(true);
137
+ expect(Disposable.is({})).to.equal(false);
138
+ });
139
+
140
+ it('DisposableCollection:元素自己 dispose 时从集合里移除,全部移除后触发 onDispose', () => {
141
+ const a = Disposable.create(() => { });
142
+ const coll = new DisposableCollection();
143
+ let fired = 0;
144
+ coll.onDispose(() => fired++);
145
+ coll.pushAll([a]);
146
+ a.dispose();
147
+ expect(coll.disposed).to.equal(true);
148
+ expect(fired).to.equal(1);
149
+ });
150
+ });
151
+
152
+ describe('core utils:取消', () => {
153
+ it('CancellationTokenSource:cancel 前后的状态与事件', () => {
154
+ const source = new CancellationTokenSource();
155
+ const token = source.token;
156
+ let fired = 0;
157
+ token.onCancellationRequested(() => fired++);
158
+ expect(token.isCancellationRequested).to.equal(false);
159
+ source.cancel();
160
+ source.cancel();
161
+ expect(token.isCancellationRequested).to.equal(true);
162
+ expect(fired).to.equal(1);
163
+ expect(() => checkCancelled(token)).to.throw();
164
+ expect(() => checkCancelled(CancellationToken.None)).not.to.throw();
165
+ });
166
+
167
+ it('先 cancel 再取 token 时直接得到已取消的 token;已取消的 token 订阅后异步收到通知', async () => {
168
+ const source = new CancellationTokenSource();
169
+ source.dispose();
170
+ expect(source.token).to.equal(CancellationToken.Cancelled);
171
+ const fired = await new Promise<boolean>(resolve => {
172
+ source.token.onCancellationRequested(() => resolve(true));
173
+ setTimeout(() => resolve(false), 50);
174
+ });
175
+ expect(fired).to.equal(true);
176
+ });
177
+
178
+ it('cancelled() / isCancelled()', () => {
179
+ expect(isCancelled(cancelled())).to.equal(true);
180
+ expect(isCancelled(new Error('other'))).to.equal(false);
181
+ expect(isCancelled(undefined)).to.equal(false);
182
+ });
183
+ });
184
+
185
+ describe('core utils:MimeType', () => {
186
+ it('解析类型、子类型、后缀;通配', () => {
187
+ const json = MimeTypeUtils.parseMimeType('application/vnd.api+json');
188
+ expect(json.getType()).to.equal('application');
189
+ expect(json.getSubtype()).to.equal('vnd.api+json');
190
+ expect(json.getSubtypeSuffix()).to.equal('json');
191
+ expect(MimeTypeUtils.parseMimeType('*').isWildcardType()).to.equal(true);
192
+ expect(MimeTypeUtils.parseMimeType('text/*').isWildcardSubtype()).to.equal(true);
193
+ expect(MimeTypeUtils.parseMimeType('text/plain').isConcrete()).to.equal(true);
194
+ expect(MimeType.valueOf('image/png').equals(MimeTypeUtils.IMAGE_PNG)).to.equal(true);
195
+ });
196
+
197
+ it('includes / isCompatibleWith / isMoreSpecific', () => {
198
+ const all = MimeTypeUtils.ALL;
199
+ const text = MimeTypeUtils.parseMimeType('text/*');
200
+ const html = MimeTypeUtils.TEXT_HTML;
201
+ expect(all.includes(html)).to.equal(true);
202
+ expect(text.includes(html)).to.equal(true);
203
+ expect(html.includes(text)).to.equal(false);
204
+ expect(html.isCompatibleWith(text)).to.equal(true);
205
+ expect(html.isCompatibleWith(MimeTypeUtils.APPLICATION_JSON)).to.equal(false);
206
+ expect(html.isMoreSpecific(text)).to.equal(true);
207
+ expect(html.isPresentIn([MimeTypeUtils.TEXT_PLAIN, MimeTypeUtils.TEXT_HTML])).to.equal(true);
208
+ });
209
+
210
+ it('保留参数:charset 和其他参数都能取到,toString 带上参数(F9)', () => {
211
+ const t = MimeTypeUtils.parseMimeType('text/html; charset=UTF-8; level=1');
212
+ expect(t.getCharset()).to.equal('UTF-8');
213
+ expect(t.getParameter('level')).to.equal('1');
214
+ expect(t.toString()).to.equal('text/html;charset=UTF-8;level=1');
215
+ });
216
+
217
+ it('非法输入抛 InvalidMimeTypeError', () => {
218
+ expect(() => MimeTypeUtils.parseMimeType('')).to.throw(InvalidMimeTypeError);
219
+ expect(() => MimeTypeUtils.parseMimeType('noslash')).to.throw(InvalidMimeTypeError);
220
+ expect(() => MimeTypeUtils.parseMimeType('text/')).to.throw(InvalidMimeTypeError);
221
+ });
222
+
223
+ it('tokenize 按逗号切分,引号里的逗号不切', () => {
224
+ expect(MimeTypeUtils.tokenize('a/b, c/d;x="1,2"')).to.deep.equal(['a/b', ' c/d;x="1,2"']);
225
+ expect(MimeTypeUtils.tokenize('')).to.deep.equal([]);
226
+ });
227
+
228
+ it('sortBySpecificity:具体的排在前面', () => {
229
+ const list = [MimeTypeUtils.ALL, MimeTypeUtils.parseMimeType('text/*'), MimeTypeUtils.TEXT_HTML];
230
+ MimeTypeUtils.sortBySpecificity(list);
231
+ expect(list.map(String)).to.deep.equal(['text/html', 'text/*', '*/*']);
232
+ });
233
+
234
+ it('parseMimeTypes 按逗号解析多个类型(F8)', () => {
235
+ expect(MimeTypeUtils.parseMimeTypes('text/html, application/json').map(String)).to.deep.equal(['text/html', 'application/json']);
236
+ expect(MimeTypeUtils.parseMimeTypes('')).to.deep.equal([]);
237
+ });
238
+
239
+ it('generateMultipartBoundaryString:30–40 个合法字符', () => {
240
+ const b = MimeTypeUtils.generateMultipartBoundaryString();
241
+ expect(b.length).to.be.within(30, 40);
242
+ expect(b).to.match(/^[-_0-9a-zA-Z]+$/);
243
+ });
244
+ });
245
+
246
+ describe('core utils:WaitUntilEvent', () => {
247
+ interface Ev extends WaitUntilEvent { name: string }
248
+
249
+ it('WaitUntilEvent.fire 等待所有 waitUntil 的 Promise;异步调用 waitUntil 报错', async () => {
250
+ const emitter = new Emitter<Ev>();
251
+ const log: string[] = [];
252
+ let late: Ev | undefined;
253
+ emitter.event(e => e.waitUntil(new Promise<void>(r => setTimeout(() => { log.push('slow'); r(); }, 5))));
254
+ emitter.event(e => { late = e; log.push(e.name); });
255
+ await WaitUntilEvent.fire(emitter, { name: 'go' });
256
+ expect(log).to.deep.equal(['go', 'slow']);
257
+ expect(() => late!.waitUntil(Promise.resolve())).to.throw();
258
+ });
259
+ });
@@ -0,0 +1,219 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { AttributeScope, Context } from './context';
4
+
5
+ /**
6
+ * 请求上下文的约定,与实现无关(以前是 cls-hooked,现在是 AsyncLocalStorage)。
7
+ *
8
+ * cls-hooked 下这些用例有 4 条失败(2026-11-08 在 Node 24.13 和 Bun 1.3.11 上实测):run 里设置的上下文泄漏给
9
+ * await 它的调用方;Node 下外层 await 内层 run 之后看到内层的上下文;Bun 下并发的 run 之间没有隔离(请求之间串上下文);
10
+ * Context.run 没有返回值。换成 AsyncLocalStorage 之后全部通过。同一组场景在 Node 上的结果见
11
+ * cell-refactor/stage0/context-isolation/。
12
+ */
13
+
14
+ const tick = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
15
+
16
+ /** 在 Context.run 里执行 fn,并等它完成。不依赖 run 的返回值,所以同一组用例也能验证以前没有返回值的实现。 */
17
+ function inRun<T>(fn: () => Promise<T>): Promise<T> {
18
+ return new Promise<T>((resolve, reject) => {
19
+ Context.run(async () => {
20
+ try {
21
+ resolve(await fn());
22
+ } catch (error) {
23
+ reject(error);
24
+ }
25
+ });
26
+ });
27
+ }
28
+
29
+ function named(name: string): Context {
30
+ const ctx = new Context();
31
+ ctx.name = name;
32
+ return ctx;
33
+ }
34
+
35
+ describe('Context', () => {
36
+ it('run 之外没有当前上下文', () => {
37
+ expect(Context.getCurrent()).to.equal(undefined);
38
+ });
39
+
40
+ it('run 里设置的上下文在 await、setTimeout 和 Promise 链之后仍然可见', async () => {
41
+ const ctx = named('a');
42
+ const seen = await inRun(async () => {
43
+ Context.setCurrent(ctx);
44
+ await tick();
45
+ const afterTimer = await new Promise<Context>(resolve => setTimeout(() => resolve(Context.getCurrent()), 1));
46
+ const afterChain = await Promise.resolve()
47
+ .then(() => tick())
48
+ .then(() => Context.getCurrent());
49
+ return [Context.getCurrent(), afterTimer, afterChain];
50
+ });
51
+ expect(seen).to.deep.equal([ctx, ctx, ctx]);
52
+ expect(seen.every(c => c === ctx)).to.equal(true);
53
+ });
54
+
55
+ it('run 结束后上下文不会泄漏给 await 它的调用方', async () => {
56
+ await inRun(async () => {
57
+ Context.setCurrent(named('a'));
58
+ });
59
+ expect(Context.getCurrent()).to.equal(undefined);
60
+ });
61
+
62
+ describe('嵌套', () => {
63
+ it('内层设置自己的上下文,不影响外层', async () => {
64
+ const outer = named('outer');
65
+ const inner = named('inner');
66
+ const seen = await inRun(async () => {
67
+ Context.setCurrent(outer);
68
+ const inside = await inRun(async () => {
69
+ Context.setCurrent(inner);
70
+ await tick();
71
+ return Context.getCurrent();
72
+ });
73
+ await tick();
74
+ return { inside, after: Context.getCurrent() };
75
+ });
76
+ expect(seen.inside).to.equal(inner);
77
+ expect(seen.after).to.equal(outer);
78
+ });
79
+
80
+ // 4.x 兼容语义(cls-hooked 一直如此):4.x 不改行为,AsyncLocalStorage 实现以外层的值为原型创建内层的值来保持它;5.0 再评估。
81
+ it('内层在设置自己的上下文之前继承外层的上下文', async () => {
82
+ const outer = named('outer');
83
+ const inherited = await inRun(async () => {
84
+ Context.setCurrent(outer);
85
+ return inRun(async () => Context.getCurrent());
86
+ });
87
+ expect(inherited).to.equal(outer);
88
+ });
89
+ });
90
+
91
+ it('并发的 run 互相隔离', async () => {
92
+ const contexts = Array.from({ length: 50 }, (_, i) => named(`c${i}`));
93
+ const seen = await Promise.all(
94
+ contexts.map((ctx, i) =>
95
+ inRun(async () => {
96
+ Context.setCurrent(ctx);
97
+ await tick(i % 7);
98
+ const first = Context.getCurrent();
99
+ await tick((i * 3) % 5);
100
+ return [first, Context.getCurrent()];
101
+ }),
102
+ ),
103
+ );
104
+ seen.forEach(([first, second], i) => {
105
+ expect(first).to.equal(contexts[i]);
106
+ expect(second).to.equal(contexts[i]);
107
+ });
108
+ });
109
+
110
+ it('run 之外 setCurrent 抛错', () => {
111
+ expect(() => Context.setCurrent(new Context())).to.throw('No context available');
112
+ });
113
+
114
+ it('Context.run 的 Promise 以 fn 的返回值 resolve', async () => {
115
+ expect(await Context.run(async () => 42)).to.equal(42);
116
+ expect(await Context.run(() => 'sync')).to.equal('sync');
117
+ });
118
+
119
+ it('bind 的函数在 run 结束后调用,仍然看到绑定时的上下文', async () => {
120
+ const ctx = named('bound');
121
+ const bound = await inRun(async () => {
122
+ Context.setCurrent(ctx);
123
+ return Context.bind(() => Context.getCurrent());
124
+ });
125
+ expect(bound()).to.equal(ctx);
126
+ expect(await new Promise(resolve => setTimeout(() => resolve(bound()), 1))).to.equal(ctx);
127
+ });
128
+
129
+ describe('异常', () => {
130
+ it('run 里捕获的异常不影响当前上下文', async () => {
131
+ const ctx = named('a');
132
+ const seen = await inRun(async () => {
133
+ Context.setCurrent(ctx);
134
+ try {
135
+ await tick();
136
+ throw new Error('boom');
137
+ } catch {
138
+ // 被调用方吞掉
139
+ }
140
+ return Context.getCurrent();
141
+ });
142
+ expect(seen).to.equal(ctx);
143
+ });
144
+
145
+ it('内层 run 的异常传到外层,外层上下文不变', async () => {
146
+ const outer = named('outer');
147
+ const boom = new Error('boom');
148
+ const seen = await inRun(async () => {
149
+ Context.setCurrent(outer);
150
+ let caught: unknown;
151
+ try {
152
+ await inRun(async () => {
153
+ Context.setCurrent(named('inner'));
154
+ await tick();
155
+ throw boom;
156
+ });
157
+ } catch (error) {
158
+ caught = error;
159
+ }
160
+ return { caught, after: Context.getCurrent() };
161
+ });
162
+ expect(seen.caught).to.equal(boom);
163
+ expect(seen.after).to.equal(outer);
164
+ });
165
+
166
+ it('Context.run 返回 Promise,fn 的异常让它 reject', async () => {
167
+ const boom = new Error('boom');
168
+ const result = Context.run(async () => {
169
+ throw boom;
170
+ }) as unknown;
171
+ expect(result).to.be.instanceOf(Promise);
172
+ let caught: unknown;
173
+ await (result as Promise<void>).catch(error => {
174
+ caught = error;
175
+ });
176
+ expect(caught).to.equal(boom);
177
+ });
178
+ });
179
+
180
+ describe('属性', () => {
181
+ it('Request 作用域的属性只在本次 run 里可见,App 作用域跨 run 可见', async () => {
182
+ const key = `attr-${Date.now()}`;
183
+ await inRun(async () => {
184
+ Context.setCurrent(new Context());
185
+ Context.setAttr(key, 'request');
186
+ Context.setAttr(`${key}-app`, 'app', AttributeScope.App);
187
+ expect(Context.getAttr(key, AttributeScope.Request)).to.equal('request');
188
+ });
189
+ const other = await inRun(async () => {
190
+ Context.setCurrent(new Context());
191
+ return [Context.getAttr(key, AttributeScope.Request), Context.getAttr(`${key}-app`, AttributeScope.App)];
192
+ });
193
+ expect(other).to.deep.equal([undefined, 'app']);
194
+ });
195
+
196
+ it('不指定作用域时先找 Request,再找 App', async () => {
197
+ const key = `fallback-${Date.now()}`;
198
+ Context.setAttr(key, 'app', AttributeScope.App);
199
+ const seen = await inRun(async () => {
200
+ Context.setCurrent(new Context());
201
+ const before = Context.getAttr(key);
202
+ Context.setAttr(key, 'request');
203
+ return [before, Context.getAttr(key)];
204
+ });
205
+ expect(seen).to.deep.equal(['app', 'request']);
206
+ });
207
+
208
+ it('AttributeScope.App 只读 App 作用域(App 的枚举值是 0,不能当成“不指定”)', async () => {
209
+ const key = `app-only-${Date.now()}`;
210
+ Context.setAttr(key, 'app', AttributeScope.App);
211
+ const seen = await inRun(async () => {
212
+ Context.setCurrent(new Context());
213
+ Context.setAttr(key, 'request');
214
+ return [Context.getAttr(key, AttributeScope.App), Context.getAttr(key, AttributeScope.Request)];
215
+ });
216
+ expect(seen).to.deep.equal(['app', 'request']);
217
+ });
218
+ });
219
+ });
@@ -1,4 +1,4 @@
1
- const createNamespace = require('cls-hooked').createNamespace;
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
2
 
3
3
  // eslint-disable-next-line @typescript-eslint/no-shadow
4
4
  export enum AttributeScope { App, Request, Session }
@@ -7,26 +7,51 @@ export const CURRENT_CONTEXT_REQUEST_KEY = 'CurrentContextRequest';
7
7
 
8
8
  const appAttrs = new Map<string, any>();
9
9
 
10
- const store = createNamespace('3f45efdf-383c-4152-877b-1e98a410e0da');
10
+ /** The values of one `Context.run`. */
11
+ type Store = Record<string, any>;
12
+
13
+ /**
14
+ * One storage per process, shared by every copy of this module (the CommonJS and the ES module build,
15
+ * a Vite module runner): a context set through one copy is seen through the others.
16
+ */
17
+ const STORAGE_KEY = Symbol.for('@celljs/core/context-storage');
18
+ const storage: AsyncLocalStorage<Store> = ((globalThis as Record<symbol, any>)[STORAGE_KEY] ??= new AsyncLocalStorage<Store>());
19
+
20
+ function activeStore(): Store {
21
+ const store = storage.getStore();
22
+ if (!store) {
23
+ throw new Error('No context available. Context.run() or Context.bind() must be called first.');
24
+ }
25
+ return store;
26
+ }
11
27
 
12
28
  export class Context {
13
29
 
14
30
  [key: string | symbol | number]: any;
15
31
 
16
- static run(fn: (...args: any[]) => void) {
17
- store.runPromise(async () => fn());
32
+ /**
33
+ * Runs `fn` in a new context; the returned promise settles with `fn`. A nested run starts from the
34
+ * values of the outer run (it sees the outer current context until it sets its own) and its changes
35
+ * stay inside it: the semantics of 4.x, kept from cls-hooked.
36
+ */
37
+ static run<T>(fn: (...args: any[]) => T | PromiseLike<T>): Promise<T> {
38
+ return storage.run(Object.create(storage.getStore() ?? null), async () => fn());
18
39
  }
19
40
 
20
- static bind(fn: (...args: any[]) => void, context?: any) {
21
- return store.bind(fn, context);
41
+ /** `fn` runs in `context` (the values of a run), by default the context active now. */
42
+ static bind<F extends (...args: any[]) => any>(fn: F, context?: Store): F {
43
+ const store = context ?? storage.getStore() ?? Object.create(null);
44
+ return function (this: unknown, ...args: any[]) {
45
+ return storage.run(store, () => fn.apply(this, args));
46
+ } as F;
22
47
  }
23
48
 
24
49
  static setCurrent(context: Context) {
25
- store.set(CURRENT_CONTEXT_REQUEST_KEY, context);
50
+ activeStore()[CURRENT_CONTEXT_REQUEST_KEY] = context;
26
51
  }
27
52
 
28
53
  static getCurrent<T extends Context>(): T {
29
- return store.get(CURRENT_CONTEXT_REQUEST_KEY);
54
+ return storage.getStore()?.[CURRENT_CONTEXT_REQUEST_KEY];
30
55
  }
31
56
 
32
57
  static setAttr(key: string, value: any, scope: AttributeScope = AttributeScope.Request) {
@@ -40,7 +65,7 @@ export class Context {
40
65
  }
41
66
 
42
67
  static getAttr<T>(key: string, scope?: AttributeScope): T {
43
- if (scope) {
68
+ if (scope !== undefined) {
44
69
  if (scope === AttributeScope.Request) {
45
70
  return Context.getCurrent()?.[key];
46
71
  } else if (scope === AttributeScope.Session) {
@@ -49,7 +74,7 @@ export class Context {
49
74
  return appAttrs.get(key);
50
75
  }
51
76
  } else {
52
- let value = store.get(key);
77
+ let value = storage.getStore()?.[key];
53
78
  value = value ? value : Context.getCurrent()?.[key];
54
79
  return value ? value : appAttrs.get(key);
55
80
  }
package/src/node/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './application';
2
2
  export * from './context';
3
- export * from './utils';
@@ -1 +0,0 @@
1
- export { decorate } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { decorate } from 'inversify';
2
- //# sourceMappingURL=decorate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decorate.js","sourceRoot":"","sources":["../../../src/common/annotation/decorate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- export { inject as Inject } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { inject as Inject } from 'inversify';
2
- //# sourceMappingURL=inject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/common/annotation/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- export { injectable as Injectable } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { injectable as Injectable } from 'inversify';
2
- //# sourceMappingURL=injectable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/common/annotation/injectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- export { preDestroy as PreDestroy } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { preDestroy as PreDestroy } from 'inversify';
2
- //# sourceMappingURL=pre-destroy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pre-destroy.js","sourceRoot":"","sources":["../../../src/common/annotation/pre-destroy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- export { targetName as TargetName } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { targetName as TargetName } from 'inversify';
2
- //# sourceMappingURL=target-name.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"target-name.js","sourceRoot":"","sources":["../../../src/common/annotation/target-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- export { unmanaged as Unmanaged } from 'inversify';
@@ -1,2 +0,0 @@
1
- export { unmanaged as Unmanaged } from 'inversify';
2
- //# sourceMappingURL=unmanaged.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unmanaged.js","sourceRoot":"","sources":["../../../src/common/annotation/unmanaged.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -1,4 +0,0 @@
1
- import { ContainerModule, interfaces } from 'inversify';
2
- export declare class ContainerFactory {
3
- static create(...modules: ContainerModule[]): interfaces.Container;
4
- }
@@ -1,9 +0,0 @@
1
- import { Container } from 'inversify';
2
- export class ContainerFactory {
3
- static create(...modules) {
4
- const container = new Container({ skipBaseClassChecks: true });
5
- container.load(...modules);
6
- return container;
7
- }
8
- }
9
- //# sourceMappingURL=container-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"container-factory.js","sourceRoot":"","sources":["../../../src/common/container/container-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAC;AAEnE,MAAM,OAAO,gBAAgB;IACzB,MAAM,CAAC,MAAM,CAAC,GAAG,OAA0B;QACvC,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/D,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;QAC3B,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
@@ -1,5 +0,0 @@
1
- import { JexlEngineProvider } from './expression-protocol.js';
2
- export declare class JexlEngineProviderImpl implements JexlEngineProvider<any> {
3
- protected jexlEngine: any;
4
- provide(): any;
5
- }