@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,487 @@
1
+ /**
2
+ * The expression language of Cell: what `${...}` in the configuration, `@Value` and the security
3
+ * policies evaluate. Its grammar is the one of jexl 2, which Cell used before:
4
+ *
5
+ * - literals: `'text'`, `"text"`, `42`, `1.5`, `true`, `false`, `[a, b]`, `{ key: value }`;
6
+ * - names: `cell.server.port`, `list[0]`, `map['key']`, filters `users[.age > 18]` (`.age` is a
7
+ * property of each element); a missing property is `undefined`, never an error; a property of an
8
+ * array is the property of its first element;
9
+ * - operators, loosest first: `a ? b : c` and `a ?: b` (`b` when `a` is falsy), `||` and `&&` (same
10
+ * precedence, left to right), `== != > >= < <= in`, `+ -`, `* / //` (`//` rounds down), `% ^`
11
+ * (`^` is power), then `!` and `-` in front;
12
+ * - transforms `value|name(args)` and functions `name(args)`: only the ones added to the engine.
13
+ *
14
+ * Evaluation is synchronous. Expressions cannot call methods, so they only read what the context gives.
15
+ */
16
+
17
+ /** The code of an {@link ExpressionSyntaxError}. */
18
+ export type ExpressionErrorCode = 'CELL_EL_SYNTAX' | 'CELL_EL_UNKNOWN_TRANSFORM' | 'CELL_EL_UNKNOWN_FUNCTION';
19
+
20
+ /** An expression that cannot be parsed, or that uses a transform or function the engine does not have. */
21
+ export class ExpressionSyntaxError extends Error {
22
+ override readonly name = 'ExpressionSyntaxError';
23
+ readonly code: ExpressionErrorCode;
24
+ readonly hint: string;
25
+ readonly expression: string;
26
+ /** Where in `expression` parsing failed. */
27
+ readonly position?: number;
28
+
29
+ constructor(options: { code: ExpressionErrorCode, message: string, hint: string, expression: string, position?: number }) {
30
+ super(options.message);
31
+ this.code = options.code;
32
+ this.hint = options.hint;
33
+ this.expression = options.expression;
34
+ this.position = options.position;
35
+ }
36
+ }
37
+
38
+ type Evaluate = (context: any, element: any) => any;
39
+
40
+ /** A compiled expression; evaluate it as many times as needed. */
41
+ export class Expression {
42
+ constructor(readonly source: string, protected readonly run: Evaluate) { }
43
+
44
+ /** The value of the expression; names are properties of `context`. */
45
+ evaluate(context: object = {}): any {
46
+ return this.run(context, context);
47
+ }
48
+ }
49
+
50
+ /** Compiles and evaluates expressions; holds the transforms and functions they may call. */
51
+ export class ExpressionEngine {
52
+ protected static readonly CACHE_SIZE = 1000;
53
+
54
+ protected readonly transforms = new Map<string, Function>();
55
+ protected readonly functions = new Map<string, Function>();
56
+ protected readonly cache = new Map<string, Expression>();
57
+
58
+ /** `value|name(a, b)` calls `transform(value, a, b)`. */
59
+ addTransform(name: string, transform: (value: any, ...args: any[]) => any): this {
60
+ this.transforms.set(name, transform);
61
+ return this;
62
+ }
63
+
64
+ addTransforms(transforms: Record<string, (value: any, ...args: any[]) => any>): this {
65
+ for (const [name, transform] of Object.entries(transforms)) {
66
+ this.addTransform(name, transform);
67
+ }
68
+ return this;
69
+ }
70
+
71
+ /** `name(a, b)` calls `fn(a, b)`. */
72
+ addFunction(name: string, fn: (...args: any[]) => any): this {
73
+ this.functions.set(name, fn);
74
+ return this;
75
+ }
76
+
77
+ addFunctions(functions: Record<string, (...args: any[]) => any>): this {
78
+ for (const [name, fn] of Object.entries(functions)) {
79
+ this.addFunction(name, fn);
80
+ }
81
+ return this;
82
+ }
83
+
84
+ /** Compiles once per source text (the latest ones are kept). Throws an {@link ExpressionSyntaxError}. */
85
+ compile(source: string): Expression {
86
+ let expression = this.cache.get(source);
87
+ if (!expression) {
88
+ expression = new Expression(source, new ExpressionParser(source, this).parse());
89
+ if (this.cache.size >= ExpressionEngine.CACHE_SIZE) {
90
+ this.cache.clear();
91
+ }
92
+ this.cache.set(source, expression);
93
+ }
94
+ return expression;
95
+ }
96
+
97
+ evaluate(source: string, context: object = {}): any {
98
+ return this.compile(source).evaluate(context);
99
+ }
100
+
101
+ /** @internal what the compiled expressions call */
102
+ call(pool: 'transform' | 'function', name: string, args: any[], source: string): any {
103
+ const fn = (pool === 'transform' ? this.transforms : this.functions).get(name);
104
+ if (!fn) {
105
+ throw new ExpressionSyntaxError({
106
+ code: pool === 'transform' ? 'CELL_EL_UNKNOWN_TRANSFORM' : 'CELL_EL_UNKNOWN_FUNCTION',
107
+ message: `The ${pool} ${name} is not defined (in: ${source}).`,
108
+ hint: `Add it with addT${pool.slice(1)}('${name}', ...) on the ExpressionEngine of the application, or check its spelling.`,
109
+ expression: source
110
+ });
111
+ }
112
+ return fn(...args);
113
+ }
114
+ }
115
+
116
+ interface Token {
117
+ type: 'number' | 'string' | 'boolean' | 'identifier' | 'operator' | 'punctuation' | 'end';
118
+ value: any;
119
+ start: number;
120
+ }
121
+
122
+ /** Longest first, so that `//` is not `/`. */
123
+ const OPERATORS = ['//', '==', '!=', '>=', '<=', '&&', '||', '+', '-', '*', '/', '%', '^', '>', '<', '!'];
124
+ const PUNCTUATION = '.[]|{}:,()?';
125
+ const PRECEDENCE: Record<string, number> = {
126
+ '||': 10, '&&': 10,
127
+ '==': 20, '!=': 20, '>': 20, '>=': 20, '<': 20, '<=': 20, in: 20,
128
+ '+': 30, '-': 30,
129
+ '*': 40, '/': 40, '//': 40,
130
+ '%': 50, '^': 50
131
+ };
132
+ const BINARY: Record<string, (left: any, right: any) => any> = {
133
+ // eslint-disable-next-line eqeqeq
134
+ '==': (l, r) => l == r,
135
+ // eslint-disable-next-line eqeqeq
136
+ '!=': (l, r) => l != r,
137
+ '>': (l, r) => l > r,
138
+ '>=': (l, r) => l >= r,
139
+ '<': (l, r) => l < r,
140
+ '<=': (l, r) => l <= r,
141
+ in: (l, r) => typeof r === 'string' ? r.indexOf(l) !== -1 : Array.isArray(r) ? r.some(e => e === l) : false,
142
+ '+': (l, r) => l + r,
143
+ '-': (l, r) => l - r,
144
+ '*': (l, r) => l * r,
145
+ '/': (l, r) => l / r,
146
+ '//': (l, r) => Math.floor(l / r),
147
+ '%': (l, r) => l % r,
148
+ '^': (l, r) => Math.pow(l, r)
149
+ };
150
+ const IDENTIFIER_START = /[\p{L}_$]/u;
151
+ const IDENTIFIER_PART = /[\p{L}\p{N}_$]/u;
152
+
153
+ /** A recursive descent parser that compiles to closures: `(context, element) => value`. */
154
+ class ExpressionParser {
155
+ protected readonly tokens: Token[];
156
+ protected index = 0;
157
+ /** Whether the expression being parsed reads `.name`: then a filter keeps the elements it is true for. */
158
+ protected relative = false;
159
+
160
+ constructor(protected readonly source: string, protected readonly engine: ExpressionEngine) {
161
+ this.tokens = this.tokenize();
162
+ }
163
+
164
+ parse(): Evaluate {
165
+ if (this.peek().type === 'end') {
166
+ return () => undefined;
167
+ }
168
+ const evaluate = this.ternary();
169
+ if (this.peek().type !== 'end') {
170
+ throw this.unexpected();
171
+ }
172
+ return evaluate;
173
+ }
174
+
175
+ protected ternary(): Evaluate {
176
+ const test = this.binary(0);
177
+ if (!this.accept('?')) {
178
+ return test;
179
+ }
180
+ const consequent = this.accept(':') ? undefined : this.ternaryThen();
181
+ const alternate = this.ternary();
182
+ if (!consequent) {
183
+ return (c, e) => test(c, e) || alternate(c, e);
184
+ }
185
+ return (c, e) => test(c, e) ? consequent(c, e) : alternate(c, e);
186
+ }
187
+
188
+ protected ternaryThen(): Evaluate {
189
+ const consequent = this.ternary();
190
+ this.expect(':');
191
+ return consequent;
192
+ }
193
+
194
+ /** Operators of `minPrecedence` or more, left to right. */
195
+ protected binary(minPrecedence: number): Evaluate {
196
+ let left = this.unary();
197
+ for (;;) {
198
+ const token = this.peek();
199
+ const precedence = token.type === 'operator' ? PRECEDENCE[token.value] : undefined;
200
+ if (precedence === undefined || precedence < minPrecedence) {
201
+ return left;
202
+ }
203
+ this.index++;
204
+ const l = left;
205
+ const r = this.binary(precedence + 1);
206
+ if (token.value === '&&') {
207
+ left = (c, e) => l(c, e) && r(c, e);
208
+ } else if (token.value === '||') {
209
+ left = (c, e) => l(c, e) || r(c, e);
210
+ } else {
211
+ const apply = BINARY[token.value];
212
+ left = (c, e) => apply(l(c, e), r(c, e));
213
+ }
214
+ }
215
+ }
216
+
217
+ protected unary(): Evaluate {
218
+ const token = this.peek();
219
+ if (token.type === 'operator' && (token.value === '!' || token.value === '-')) {
220
+ this.index++;
221
+ const operand = this.unary();
222
+ if (token.value === '!') {
223
+ return (c, e) => !operand(c, e);
224
+ }
225
+ return (c, e) => -operand(c, e);
226
+ }
227
+ return this.postfix(this.primary());
228
+ }
229
+
230
+ protected primary(): Evaluate {
231
+ const token = this.next();
232
+ switch (token.type) {
233
+ case 'number':
234
+ case 'string':
235
+ case 'boolean': {
236
+ const value = token.value;
237
+ return () => value;
238
+ }
239
+ case 'identifier': {
240
+ const name: string = token.value;
241
+ if (this.accept('(')) {
242
+ const args = this.list(')');
243
+ const { engine, source } = this;
244
+ return (c, e) => engine.call('function', name, args.map(arg => arg(c, e)), source);
245
+ }
246
+ return c => c?.[name];
247
+ }
248
+ case 'punctuation':
249
+ switch (token.value) {
250
+ case '.': {
251
+ const name = this.identifier();
252
+ this.relative = true;
253
+ return (c, e) => e?.[name];
254
+ }
255
+ case '(': {
256
+ const inner = this.ternary();
257
+ this.expect(')');
258
+ return inner;
259
+ }
260
+ case '[': {
261
+ const items = this.list(']');
262
+ return (c, e) => items.map(item => item(c, e));
263
+ }
264
+ case '{':
265
+ return this.object();
266
+ }
267
+ }
268
+ this.index--;
269
+ throw this.unexpected();
270
+ }
271
+
272
+ protected object(): Evaluate {
273
+ const entries: [string, Evaluate][] = [];
274
+ while (!this.accept('}')) {
275
+ const key = this.next();
276
+ if (key.type !== 'identifier' && key.type !== 'string') {
277
+ this.index--;
278
+ throw this.unexpected('a key');
279
+ }
280
+ this.expect(':');
281
+ entries.push([key.value, this.ternary()]);
282
+ if (!this.accept(',')) {
283
+ this.expect('}');
284
+ break;
285
+ }
286
+ }
287
+ return (c, e) => {
288
+ const result: Record<string, any> = {};
289
+ for (const [key, value] of entries) {
290
+ result[key] = value(c, e);
291
+ }
292
+ return result;
293
+ };
294
+ }
295
+
296
+ /** `.name`, `[filter]` and `|transform(args)` after an operand. */
297
+ protected postfix(subject: Evaluate): Evaluate {
298
+ for (;;) {
299
+ if (this.accept('.')) {
300
+ const name = this.identifier();
301
+ const from = subject;
302
+ subject = (c, e) => {
303
+ let value = from(c, e);
304
+ if (value === undefined || value === null) {
305
+ return undefined;
306
+ }
307
+ if (Array.isArray(value)) {
308
+ value = value[0];
309
+ }
310
+ return value?.[name];
311
+ };
312
+ } else if (this.accept('[')) {
313
+ subject = this.filter(subject);
314
+ } else if (this.accept('|')) {
315
+ const name = this.identifier();
316
+ const args = this.accept('(') ? this.list(')') : [];
317
+ const { engine, source } = this;
318
+ const from = subject;
319
+ subject = (c, e) => engine.call('transform', name, [from(c, e), ...args.map(arg => arg(c, e))], source);
320
+ } else {
321
+ return subject;
322
+ }
323
+ }
324
+ }
325
+
326
+ /**
327
+ * `subject[.x > 1]` keeps the elements the filter is true for; any other `subject[key]` is a property
328
+ * (the subject itself or nothing when the key is a boolean).
329
+ */
330
+ protected filter(subject: Evaluate): Evaluate {
331
+ const outer = this.relative;
332
+ this.relative = false;
333
+ const expression = this.ternary();
334
+ const relative = this.relative;
335
+ this.relative = outer;
336
+ this.expect(']');
337
+ if (relative) {
338
+ return (c, e) => {
339
+ const value = subject(c, e);
340
+ const elements = Array.isArray(value) ? value : value === undefined ? [] : [value];
341
+ return elements.filter(element => expression(c, element));
342
+ };
343
+ }
344
+ return (c, e) => {
345
+ const value = subject(c, e);
346
+ const key = expression(c, e);
347
+ if (typeof key === 'boolean') {
348
+ return key ? value : undefined;
349
+ }
350
+ return value === undefined || value === null ? undefined : value[key];
351
+ };
352
+ }
353
+
354
+ /** Comma separated expressions up to `close`; empty items are skipped, like jexl did. */
355
+ protected list(close: string): Evaluate[] {
356
+ const items: Evaluate[] = [];
357
+ while (!this.accept(close)) {
358
+ if (this.accept(',')) {
359
+ continue;
360
+ }
361
+ items.push(this.ternary());
362
+ if (!this.accept(',')) {
363
+ this.expect(close);
364
+ break;
365
+ }
366
+ }
367
+ return items;
368
+ }
369
+
370
+ protected identifier(): string {
371
+ const token = this.next();
372
+ if (token.type !== 'identifier') {
373
+ this.index--;
374
+ throw this.unexpected('a name');
375
+ }
376
+ return token.value;
377
+ }
378
+
379
+ protected peek(): Token {
380
+ return this.tokens[this.index];
381
+ }
382
+
383
+ protected next(): Token {
384
+ const token = this.tokens[this.index];
385
+ if (token.type !== 'end') {
386
+ this.index++;
387
+ }
388
+ return token;
389
+ }
390
+
391
+ protected accept(punctuation: string): boolean {
392
+ const token = this.tokens[this.index];
393
+ if (token.type === 'punctuation' && token.value === punctuation) {
394
+ this.index++;
395
+ return true;
396
+ }
397
+ return false;
398
+ }
399
+
400
+ protected expect(punctuation: string): void {
401
+ if (!this.accept(punctuation)) {
402
+ throw this.unexpected(`'${punctuation}'`);
403
+ }
404
+ }
405
+
406
+ protected unexpected(expected?: string): ExpressionSyntaxError {
407
+ const token = this.peek();
408
+ const found = token.type === 'end' ? 'end of expression' : `'${this.source.slice(token.start, this.tokens[this.index + 1]?.start ?? this.source.length).trim()}'`;
409
+ return this.syntaxError(token.start, `Unexpected ${found}${expected ? `, expected ${expected}` : ''}`);
410
+ }
411
+
412
+ protected syntaxError(position: number, message: string): ExpressionSyntaxError {
413
+ return new ExpressionSyntaxError({
414
+ code: 'CELL_EL_SYNTAX',
415
+ message: `${message} at position ${position} of: ${this.source}`,
416
+ hint: 'Check quotes, brackets and operators; expressions are names, literals, operators, value|transform and function() calls.',
417
+ expression: this.source,
418
+ position
419
+ });
420
+ }
421
+
422
+ protected tokenize(): Token[] {
423
+ const source = this.source;
424
+ const tokens: Token[] = [];
425
+ const isDigit = (c: string | undefined) => c !== undefined && c >= '0' && c <= '9';
426
+ let i = 0;
427
+ while (i < source.length) {
428
+ const c = source[i];
429
+ const start = i;
430
+ if (/\s/.test(c)) {
431
+ i++;
432
+ } else if (c === '\'' || c === '"') {
433
+ // Only \<quote> and \\ are escapes; any other backslash is kept (\d stays \d).
434
+ let value = '';
435
+ i++;
436
+ while (i < source.length && source[i] !== c) {
437
+ if (source[i] === '\\' && i + 1 < source.length) {
438
+ const next = source[i + 1];
439
+ value += next === c || next === '\\' ? next : '\\' + next;
440
+ i += 2;
441
+ } else {
442
+ value += source[i++];
443
+ }
444
+ }
445
+ if (i >= source.length) {
446
+ throw this.syntaxError(start, 'Unterminated string');
447
+ }
448
+ i++;
449
+ tokens.push({ type: 'string', value, start });
450
+ } else if (isDigit(c)) {
451
+ while (isDigit(source[i])) {
452
+ i++;
453
+ }
454
+ if (source[i] === '.' && isDigit(source[i + 1])) {
455
+ i++;
456
+ while (isDigit(source[i])) {
457
+ i++;
458
+ }
459
+ }
460
+ tokens.push({ type: 'number', value: parseFloat(source.slice(start, i)), start });
461
+ } else if (IDENTIFIER_START.test(c)) {
462
+ while (i < source.length && IDENTIFIER_PART.test(source[i])) {
463
+ i++;
464
+ }
465
+ const word = source.slice(start, i);
466
+ if (word === 'true' || word === 'false') {
467
+ tokens.push({ type: 'boolean', value: word === 'true', start });
468
+ } else {
469
+ tokens.push({ type: word === 'in' ? 'operator' : 'identifier', value: word, start });
470
+ }
471
+ } else {
472
+ const operator = OPERATORS.find(op => source.startsWith(op, i));
473
+ if (operator) {
474
+ tokens.push({ type: 'operator', value: operator, start });
475
+ i += operator.length;
476
+ } else if (PUNCTUATION.includes(c)) {
477
+ tokens.push({ type: 'punctuation', value: c, start });
478
+ i++;
479
+ } else {
480
+ throw this.syntaxError(start, `Unexpected character '${c}'`);
481
+ }
482
+ }
483
+ }
484
+ tokens.push({ type: 'end', value: undefined, start: source.length });
485
+ return tokens;
486
+ }
487
+ }
@@ -0,0 +1,109 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { ExpressionCompilerImpl } from './expression-compiler';
4
+ import { ExpressionHandlerImpl } from './expression-handler';
5
+ import { ExpressionEngine } from './expression-engine';
6
+
7
+ function handler(configuration?: Record<string, unknown>): ExpressionHandlerImpl {
8
+ const engine = new ExpressionEngine();
9
+ const compiler = new ExpressionCompilerImpl();
10
+ Object.defineProperty(compiler, 'engine', { value: engine });
11
+ const instance = new ExpressionHandlerImpl();
12
+ Object.defineProperty(instance, 'expressionCompiler', { value: compiler });
13
+ Object.defineProperty(instance, 'expressionContextProvider', { value: { provide: () => configuration } });
14
+ return instance;
15
+ }
16
+
17
+ describe('ExpressionHandler', () => {
18
+ it('evaluates every string of nested objects and arrays in place', () => {
19
+ const ctx = { a: { b: 2 }, name: 'cell' };
20
+ const target = { x: '${a.b + 1}', list: ['${name}', 'plain', 7, { deep: 'hi ${name}' }], n: 1, t: true, nil: null };
21
+ const result = handler().handle(target, ctx);
22
+ expect(result).to.equal(target);
23
+ expect(target).to.deep.equal({ x: 3, list: ['cell', 'plain', 7, { deep: 'hi cell' }], n: 1, t: true, nil: null });
24
+ });
25
+
26
+ it('leaves objects marked _ignoreEl alone', () => {
27
+ const ignored = { _ignoreEl: true, value: '${name}' };
28
+ const target = { ignored, other: '${name}' };
29
+ handler().handle(target, { name: 'cell' });
30
+ expect(target.ignored).to.equal(ignored);
31
+ expect(ignored.value).to.equal('${name}');
32
+ expect(target.other).to.equal('cell');
33
+ });
34
+
35
+ it('does not walk into an object an expression evaluates to: values are not templates', () => {
36
+ const ctx = { obj: { greeting: 'hi ${name}' }, name: 'cell' };
37
+ const target = { value: '${obj}' };
38
+ handler().handle(target, ctx);
39
+ expect(target.value).to.deep.equal({ greeting: 'hi ${name}' });
40
+ });
41
+
42
+ it('stops at circular references', () => {
43
+ const target: Record<string, unknown> = { name: '${n}' };
44
+ target.self = target;
45
+ target.list = [target];
46
+ handler().handle(target, { n: 'cell' });
47
+ expect(target.name).to.equal('cell');
48
+ expect(target.self).to.equal(target);
49
+ expect((target.list as unknown[])[0]).to.equal(target);
50
+ });
51
+
52
+ it('does not assign unchanged values (frozen objects without expressions are fine)', () => {
53
+ const frozen = Object.freeze({ a: 1, b: 'text', c: Object.freeze([1, 2]) });
54
+ const target = { frozen, x: '${n}' };
55
+ handler().handle(target, { n: 2 });
56
+ expect(target.x).to.equal(2);
57
+ expect(target.frozen).to.equal(frozen);
58
+ });
59
+
60
+ describe('F6: values are text, not expressions', () => {
61
+ const secret = 'S3CRET';
62
+ const env = (x: string) => ({ X: x, _ignoreEl: true });
63
+
64
+ it('a value from the environment is not evaluated', () => {
65
+ const configuration = { cell: { secret, a: '${env.X}' }, env: env('${cell.secret}') };
66
+ expect(handler(configuration).handle('${cell.a}')).to.equal('${cell.secret}');
67
+ expect(configuration.cell.a).to.equal('${cell.secret}');
68
+ });
69
+
70
+ it('nor through another key, in either order', () => {
71
+ const configuration = { cell: { b: '${cell.a}', secret, a: '${env.X}', c: 'x-${cell.a}' }, env: env('${cell.secret}') };
72
+ const h = handler(configuration);
73
+ expect(h.handle('${cell.b}')).to.equal('${cell.secret}');
74
+ expect(h.handle('${cell.c}')).to.equal('x-${cell.secret}');
75
+ expect(configuration.cell.c).to.equal('x-${cell.secret}');
76
+ expect(configuration.cell.b).to.equal('${cell.secret}');
77
+ });
78
+
79
+ it('nor when it is part of a longer text', () => {
80
+ const configuration = { cell: { secret, url: 'http://${env.X}/path' }, env: env('${cell.secret}') };
81
+ expect(handler(configuration).handle('${cell.url}')).to.equal('http://${cell.secret}/path');
82
+ });
83
+
84
+ it('a template variable is not evaluated either (prompt templates)', () => {
85
+ const text = handler().handle('hi {name}', { name: '{secret}', secret: 'S' }, { ignoreSpecialChar: true, bracketBegin: '{', bracketEnd: '}', ignoreContextExpression: true });
86
+ expect(text).to.equal('hi {secret}');
87
+ });
88
+
89
+ it('keys still refer to each other in any order, through any depth', () => {
90
+ const configuration = { cell: { x: '${cell.y}-x', y: '${cell.deep.z}', deep: { z: 'z', n: '${cell.port * 2}' }, port: 21 } };
91
+ const h = handler(configuration);
92
+ expect(h.handle('${cell.x}')).to.equal('z-x');
93
+ expect(h.handle('${cell.deep.n}')).to.equal(42);
94
+ expect(configuration.cell.y).to.equal('z');
95
+ });
96
+
97
+ it('a circular reference fails with the keys involved', () => {
98
+ const configuration = { cell: { a: '${cell.b}', b: '${cell.a}' } };
99
+ expect(() => handler(configuration).handle('${cell.a}')).to.throw('Circular reference in the configuration: cell.a -> cell.b -> cell.a');
100
+ });
101
+
102
+ it('evaluating a value is still possible on purpose, with the eval transform', () => {
103
+ const instance = handler({ cell: { secret, a: '${env.X | eval}' }, env: env('${cell.secret}') });
104
+ const engine = (instance as unknown as { expressionCompiler: { engine: ExpressionEngine } }).expressionCompiler.engine;
105
+ engine.addTransform('eval', (text: string) => instance.handle(text));
106
+ expect(instance.handle('${cell.a}')).to.equal(secret);
107
+ });
108
+ });
109
+ });