@celljs/core 3.8.0 → 4.0.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 (393) hide show
  1. package/cell.remote.yml +8 -0
  2. package/cell.yml +0 -3
  3. package/esm/browser/application/frontend-application-state.d.ts +4 -0
  4. package/esm/browser/application/frontend-application-state.js +14 -0
  5. package/esm/browser/application/frontend-application-state.js.map +1 -0
  6. package/esm/browser/application/frontend-application.d.ts +30 -0
  7. package/esm/browser/application/frontend-application.js +142 -0
  8. package/esm/browser/application/frontend-application.js.map +1 -0
  9. package/esm/browser/application/index.d.ts +2 -0
  10. package/esm/browser/application/index.js +3 -0
  11. package/esm/browser/application/index.js.map +1 -0
  12. package/esm/browser/browser.d.ts +22 -0
  13. package/esm/browser/browser.js +48 -0
  14. package/esm/browser/browser.js.map +1 -0
  15. package/esm/browser/index.d.ts +3 -0
  16. package/esm/browser/index.js +4 -0
  17. package/esm/browser/index.js.map +1 -0
  18. package/esm/browser/shell/application-shell.d.ts +4 -0
  19. package/esm/browser/shell/application-shell.js +18 -0
  20. package/esm/browser/shell/application-shell.js.map +1 -0
  21. package/esm/browser/shell/index.d.ts +2 -0
  22. package/esm/browser/shell/index.js +3 -0
  23. package/esm/browser/shell/index.js.map +1 -0
  24. package/esm/browser/shell/shell-protocol.d.ts +4 -0
  25. package/esm/browser/shell/shell-protocol.js +2 -0
  26. package/esm/browser/shell/shell-protocol.js.map +1 -0
  27. package/esm/browser/static-module.d.ts +3 -0
  28. package/esm/browser/static-module.js +4 -0
  29. package/esm/browser/static-module.js.map +1 -0
  30. package/esm/common/annotation/aspect.d.ts +7 -0
  31. package/esm/common/annotation/aspect.js +10 -0
  32. package/esm/common/annotation/aspect.js.map +1 -0
  33. package/esm/common/annotation/autowired-provider.d.ts +7 -0
  34. package/esm/common/annotation/autowired-provider.js +25 -0
  35. package/esm/common/annotation/autowired-provider.js.map +1 -0
  36. package/esm/common/annotation/autowired.d.ts +22 -0
  37. package/esm/common/annotation/autowired.js +48 -0
  38. package/esm/common/annotation/autowired.js.map +1 -0
  39. package/esm/common/annotation/component.d.ts +57 -0
  40. package/esm/common/annotation/component.js +71 -0
  41. package/esm/common/annotation/component.js.map +1 -0
  42. package/esm/common/annotation/constant.d.ts +8 -0
  43. package/esm/common/annotation/constant.js +12 -0
  44. package/esm/common/annotation/constant.js.map +1 -0
  45. package/esm/common/annotation/decorate.d.ts +1 -0
  46. package/esm/common/annotation/decorate.js +2 -0
  47. package/esm/common/annotation/decorate.js.map +1 -0
  48. package/esm/common/annotation/detached/autowired-provider.d.ts +2 -0
  49. package/esm/common/annotation/detached/autowired-provider.js +12 -0
  50. package/esm/common/annotation/detached/autowired-provider.js.map +1 -0
  51. package/esm/common/annotation/detached/autowired.d.ts +2 -0
  52. package/esm/common/annotation/detached/autowired.js +9 -0
  53. package/esm/common/annotation/detached/autowired.js.map +1 -0
  54. package/esm/common/annotation/detached/index.d.ts +3 -0
  55. package/esm/common/annotation/detached/index.js +4 -0
  56. package/esm/common/annotation/detached/index.js.map +1 -0
  57. package/esm/common/annotation/detached/value.d.ts +2 -0
  58. package/esm/common/annotation/detached/value.js +9 -0
  59. package/esm/common/annotation/detached/value.js.map +1 -0
  60. package/esm/common/annotation/index.d.ts +17 -0
  61. package/esm/common/annotation/index.js +18 -0
  62. package/esm/common/annotation/index.js.map +1 -0
  63. package/esm/common/annotation/inject.d.ts +1 -0
  64. package/esm/common/annotation/inject.js +2 -0
  65. package/esm/common/annotation/inject.js.map +1 -0
  66. package/esm/common/annotation/injectable.d.ts +1 -0
  67. package/esm/common/annotation/injectable.js +2 -0
  68. package/esm/common/annotation/injectable.js.map +1 -0
  69. package/esm/common/annotation/named.d.ts +1 -0
  70. package/esm/common/annotation/named.js +2 -0
  71. package/esm/common/annotation/named.js.map +1 -0
  72. package/esm/common/annotation/optional.d.ts +1 -0
  73. package/esm/common/annotation/optional.js +2 -0
  74. package/esm/common/annotation/optional.js.map +1 -0
  75. package/esm/common/annotation/post-construct.d.ts +1 -0
  76. package/esm/common/annotation/post-construct.js +2 -0
  77. package/esm/common/annotation/post-construct.js.map +1 -0
  78. package/esm/common/annotation/pre-destroy.d.ts +1 -0
  79. package/esm/common/annotation/pre-destroy.js +2 -0
  80. package/esm/common/annotation/pre-destroy.js.map +1 -0
  81. package/esm/common/annotation/service.d.ts +4 -0
  82. package/esm/common/annotation/service.js +14 -0
  83. package/esm/common/annotation/service.js.map +1 -0
  84. package/esm/common/annotation/tagged.d.ts +1 -0
  85. package/esm/common/annotation/tagged.js +2 -0
  86. package/esm/common/annotation/tagged.js.map +1 -0
  87. package/esm/common/annotation/target-name.d.ts +1 -0
  88. package/esm/common/annotation/target-name.js +2 -0
  89. package/esm/common/annotation/target-name.js.map +1 -0
  90. package/esm/common/annotation/unmanaged.d.ts +1 -0
  91. package/esm/common/annotation/unmanaged.js +2 -0
  92. package/esm/common/annotation/unmanaged.js.map +1 -0
  93. package/esm/common/annotation/value.d.ts +15 -0
  94. package/esm/common/annotation/value.js +50 -0
  95. package/esm/common/annotation/value.js.map +1 -0
  96. package/esm/common/aop/aop-protocol.d.ts +38 -0
  97. package/esm/common/aop/aop-protocol.js +8 -0
  98. package/esm/common/aop/aop-protocol.js.map +1 -0
  99. package/esm/common/aop/aop-proxy-factory.d.ts +6 -0
  100. package/esm/common/aop/aop-proxy-factory.js +67 -0
  101. package/esm/common/aop/aop-proxy-factory.js.map +1 -0
  102. package/esm/common/aop/class-filter.d.ts +6 -0
  103. package/esm/common/aop/class-filter.js +28 -0
  104. package/esm/common/aop/class-filter.js.map +1 -0
  105. package/esm/common/aop/index.d.ts +3 -0
  106. package/esm/common/aop/index.js +4 -0
  107. package/esm/common/aop/index.js.map +1 -0
  108. package/esm/common/application/application-entry.d.ts +1 -0
  109. package/esm/common/application/application-entry.js +41 -0
  110. package/esm/common/application/application-entry.js.map +1 -0
  111. package/esm/common/application/application-error.d.ts +20 -0
  112. package/esm/common/application/application-error.js +44 -0
  113. package/esm/common/application/application-error.js.map +1 -0
  114. package/esm/common/application/application-factory.d.ts +8 -0
  115. package/esm/common/application/application-factory.js +19 -0
  116. package/esm/common/application/application-factory.js.map +1 -0
  117. package/esm/common/application/application-host.d.ts +38 -0
  118. package/esm/common/application/application-host.js +17 -0
  119. package/esm/common/application/application-host.js.map +1 -0
  120. package/esm/common/application/application-protocol.d.ts +52 -0
  121. package/esm/common/application/application-protocol.js +103 -0
  122. package/esm/common/application/application-protocol.js.map +1 -0
  123. package/esm/common/application/application-state.d.ts +3 -0
  124. package/esm/common/application/application-state.js +15 -0
  125. package/esm/common/application/application-state.js.map +1 -0
  126. package/esm/common/application/application.d.ts +6 -0
  127. package/esm/common/application/application.js +31 -0
  128. package/esm/common/application/application.js.map +1 -0
  129. package/esm/common/application/index.d.ts +3 -0
  130. package/esm/common/application/index.js +4 -0
  131. package/esm/common/application/index.js.map +1 -0
  132. package/esm/common/config/config-protocol.d.ts +4 -0
  133. package/esm/common/config/config-protocol.js +2 -0
  134. package/esm/common/config/config-protocol.js.map +1 -0
  135. package/esm/common/config/config-provider.d.ts +6 -0
  136. package/esm/common/config/config-provider.js +26 -0
  137. package/esm/common/config/config-provider.js.map +1 -0
  138. package/esm/common/config/config-util.d.ts +4 -0
  139. package/esm/common/config/config-util.js +16 -0
  140. package/esm/common/config/config-util.js.map +1 -0
  141. package/esm/common/config/dynamic-config.d.ts +3 -0
  142. package/esm/common/config/dynamic-config.js +3 -0
  143. package/esm/common/config/dynamic-config.js.map +1 -0
  144. package/esm/common/config/env-config-util.d.ts +48 -0
  145. package/esm/common/config/env-config-util.js +185 -0
  146. package/esm/common/config/env-config-util.js.map +1 -0
  147. package/esm/common/config/index.d.ts +4 -0
  148. package/esm/common/config/index.js +5 -0
  149. package/esm/common/config/index.js.map +1 -0
  150. package/esm/common/constants.d.ts +5 -0
  151. package/esm/common/constants.js +6 -0
  152. package/esm/common/constants.js.map +1 -0
  153. package/esm/common/container/auto-bind.d.ts +3 -0
  154. package/esm/common/container/auto-bind.js +98 -0
  155. package/esm/common/container/auto-bind.js.map +1 -0
  156. package/esm/common/container/container-factory.d.ts +4 -0
  157. package/esm/common/container/container-factory.js +9 -0
  158. package/esm/common/container/container-factory.js.map +1 -0
  159. package/esm/common/container/container-provider.d.ts +6 -0
  160. package/esm/common/container/container-provider.js +23 -0
  161. package/esm/common/container/container-provider.js.map +1 -0
  162. package/esm/common/container/container-util.d.ts +9 -0
  163. package/esm/common/container/container-util.js +29 -0
  164. package/esm/common/container/container-util.js.map +1 -0
  165. package/esm/common/container/dynamic-container.d.ts +2 -0
  166. package/esm/common/container/dynamic-container.js +4 -0
  167. package/esm/common/container/dynamic-container.js.map +1 -0
  168. package/esm/common/container/index.d.ts +8 -0
  169. package/esm/common/container/index.js +6 -0
  170. package/esm/common/container/index.js.map +1 -0
  171. package/esm/common/container/scope.d.ts +5 -0
  172. package/esm/common/container/scope.js +7 -0
  173. package/esm/common/container/scope.js.map +1 -0
  174. package/esm/common/el/core-context-initializer.d.ts +6 -0
  175. package/esm/common/el/core-context-initializer.js +36 -0
  176. package/esm/common/el/core-context-initializer.js.map +1 -0
  177. package/esm/common/el/expression-compiler.d.ts +19 -0
  178. package/esm/common/el/expression-compiler.js +187 -0
  179. package/esm/common/el/expression-compiler.js.map +1 -0
  180. package/esm/common/el/expression-context-provider.d.ts +9 -0
  181. package/esm/common/el/expression-context-provider.js +43 -0
  182. package/esm/common/el/expression-context-provider.js.map +1 -0
  183. package/esm/common/el/expression-handler.d.ts +11 -0
  184. package/esm/common/el/expression-handler.js +95 -0
  185. package/esm/common/el/expression-handler.js.map +1 -0
  186. package/esm/common/el/expression-protocol.d.ts +32 -0
  187. package/esm/common/el/expression-protocol.js +6 -0
  188. package/esm/common/el/expression-protocol.js.map +1 -0
  189. package/esm/common/el/index.d.ts +6 -0
  190. package/esm/common/el/index.js +7 -0
  191. package/esm/common/el/index.js.map +1 -0
  192. package/esm/common/el/jexl-engine-provider.d.ts +5 -0
  193. package/esm/common/el/jexl-engine-provider.js +22 -0
  194. package/esm/common/el/jexl-engine-provider.js.map +1 -0
  195. package/esm/common/error/custom-error.d.ts +26 -0
  196. package/esm/common/error/custom-error.js +40 -0
  197. package/esm/common/error/custom-error.js.map +1 -0
  198. package/esm/common/error/error-protocol.d.ts +3 -0
  199. package/esm/common/error/error-protocol.js +2 -0
  200. package/esm/common/error/error-protocol.js.map +1 -0
  201. package/esm/common/error/illegal-argument-error.d.ts +3 -0
  202. package/esm/common/error/illegal-argument-error.js +4 -0
  203. package/esm/common/error/illegal-argument-error.js.map +1 -0
  204. package/esm/common/error/illegal-state-error.d.ts +3 -0
  205. package/esm/common/error/illegal-state-error.js +4 -0
  206. package/esm/common/error/illegal-state-error.js.map +1 -0
  207. package/esm/common/error/index.d.ts +5 -0
  208. package/esm/common/error/index.js +6 -0
  209. package/esm/common/error/index.js.map +1 -0
  210. package/esm/common/error/invalid-mime-type-error.d.ts +5 -0
  211. package/esm/common/error/invalid-mime-type-error.js +8 -0
  212. package/esm/common/error/invalid-mime-type-error.js.map +1 -0
  213. package/esm/common/index.d.ts +12 -0
  214. package/esm/common/index.js +13 -0
  215. package/esm/common/index.js.map +1 -0
  216. package/esm/common/logger/abstract-logger.d.ts +18 -0
  217. package/esm/common/logger/abstract-logger.js +69 -0
  218. package/esm/common/logger/abstract-logger.js.map +1 -0
  219. package/esm/common/logger/index.d.ts +4 -0
  220. package/esm/common/logger/index.js +5 -0
  221. package/esm/common/logger/index.js.map +1 -0
  222. package/esm/common/logger/logger-protocol.d.ts +30 -0
  223. package/esm/common/logger/logger-protocol.js +8 -0
  224. package/esm/common/logger/logger-protocol.js.map +1 -0
  225. package/esm/common/logger/logger-service.d.ts +4 -0
  226. package/esm/common/logger/logger-service.js +18 -0
  227. package/esm/common/logger/logger-service.js.map +1 -0
  228. package/esm/common/logger/logger.d.ts +7 -0
  229. package/esm/common/logger/logger.js +35 -0
  230. package/esm/common/logger/logger.js.map +1 -0
  231. package/esm/common/provider/component-filter-registry.d.ts +11 -0
  232. package/esm/common/provider/component-filter-registry.js +66 -0
  233. package/esm/common/provider/component-filter-registry.js.map +1 -0
  234. package/esm/common/provider/index.d.ts +5 -0
  235. package/esm/common/provider/index.js +6 -0
  236. package/esm/common/provider/index.js.map +1 -0
  237. package/esm/common/provider/provider-creator.d.ts +6 -0
  238. package/esm/common/provider/provider-creator.js +19 -0
  239. package/esm/common/provider/provider-creator.js.map +1 -0
  240. package/esm/common/provider/provider-protocol.d.ts +48 -0
  241. package/esm/common/provider/provider-protocol.js +5 -0
  242. package/esm/common/provider/provider-protocol.js.map +1 -0
  243. package/esm/common/provider/provider-util.d.ts +5 -0
  244. package/esm/common/provider/provider-util.js +10 -0
  245. package/esm/common/provider/provider-util.js.map +1 -0
  246. package/esm/common/provider/provider.d.ts +13 -0
  247. package/esm/common/provider/provider.js +54 -0
  248. package/esm/common/provider/provider.js.map +1 -0
  249. package/esm/common/static-module.d.ts +3 -0
  250. package/esm/common/static-module.js +9 -0
  251. package/esm/common/static-module.js.map +1 -0
  252. package/esm/common/test/index.d.ts +1 -0
  253. package/esm/common/test/index.js +2 -0
  254. package/esm/common/test/index.js.map +1 -0
  255. package/esm/common/test/mock-logger.d.ts +14 -0
  256. package/esm/common/test/mock-logger.js +41 -0
  257. package/esm/common/test/mock-logger.js.map +1 -0
  258. package/esm/common/test/test-module.d.ts +2 -0
  259. package/esm/common/test/test-module.js +12 -0
  260. package/esm/common/test/test-module.js.map +1 -0
  261. package/esm/common/utils/annotation-util.d.ts +4 -0
  262. package/esm/common/utils/annotation-util.js +24 -0
  263. package/esm/common/utils/annotation-util.js.map +1 -0
  264. package/esm/common/utils/assert.d.ts +173 -0
  265. package/esm/common/utils/assert.js +283 -0
  266. package/esm/common/utils/assert.js.map +1 -0
  267. package/esm/common/utils/async.d.ts +367 -0
  268. package/esm/common/utils/async.js +935 -0
  269. package/esm/common/utils/async.js.map +1 -0
  270. package/esm/common/utils/byte-util.d.ts +11 -0
  271. package/esm/common/utils/byte-util.js +75 -0
  272. package/esm/common/utils/byte-util.js.map +1 -0
  273. package/esm/common/utils/cancellation.d.ts +21 -0
  274. package/esm/common/utils/cancellation.js +89 -0
  275. package/esm/common/utils/cancellation.js.map +1 -0
  276. package/esm/common/utils/class-util.d.ts +2 -0
  277. package/esm/common/utils/class-util.js +19 -0
  278. package/esm/common/utils/class-util.js.map +1 -0
  279. package/esm/common/utils/disposable.d.ts +29 -0
  280. package/esm/common/utils/disposable.js +78 -0
  281. package/esm/common/utils/disposable.js.map +1 -0
  282. package/esm/common/utils/emitter.d.ts +63 -0
  283. package/esm/common/utils/emitter.js +221 -0
  284. package/esm/common/utils/emitter.js.map +1 -0
  285. package/esm/common/utils/error-util.d.ts +19 -0
  286. package/esm/common/utils/error-util.js +35 -0
  287. package/esm/common/utils/error-util.js.map +1 -0
  288. package/esm/common/utils/event.d.ts +40 -0
  289. package/esm/common/utils/event.js +90 -0
  290. package/esm/common/utils/event.js.map +1 -0
  291. package/esm/common/utils/global-util.d.ts +1 -0
  292. package/esm/common/utils/global-util.js +16 -0
  293. package/esm/common/utils/global-util.js.map +1 -0
  294. package/esm/common/utils/index.d.ts +21 -0
  295. package/esm/common/utils/index.js +22 -0
  296. package/esm/common/utils/index.js.map +1 -0
  297. package/esm/common/utils/metadata-util.d.ts +1 -0
  298. package/esm/common/utils/metadata-util.js +25 -0
  299. package/esm/common/utils/metadata-util.js.map +1 -0
  300. package/esm/common/utils/mime-type-util.d.ts +36 -0
  301. package/esm/common/utils/mime-type-util.js +168 -0
  302. package/esm/common/utils/mime-type-util.js.map +1 -0
  303. package/esm/common/utils/mime-type.d.ts +36 -0
  304. package/esm/common/utils/mime-type.js +284 -0
  305. package/esm/common/utils/mime-type.js.map +1 -0
  306. package/esm/common/utils/os.d.ts +19 -0
  307. package/esm/common/utils/os.js +46 -0
  308. package/esm/common/utils/os.js.map +1 -0
  309. package/esm/common/utils/prioritizeable.d.ts +17 -0
  310. package/esm/common/utils/prioritizeable.js +38 -0
  311. package/esm/common/utils/prioritizeable.js.map +1 -0
  312. package/esm/common/utils/promise-util.d.ts +5 -0
  313. package/esm/common/utils/promise-util.js +9 -0
  314. package/esm/common/utils/promise-util.js.map +1 -0
  315. package/esm/common/utils/proxy-util.d.ts +4 -0
  316. package/esm/common/utils/proxy-util.js +34 -0
  317. package/esm/common/utils/proxy-util.js.map +1 -0
  318. package/esm/common/utils/types.d.ts +16 -0
  319. package/esm/common/utils/types.js +2 -0
  320. package/esm/common/utils/types.js.map +1 -0
  321. package/esm/common/utils/url-util.d.ts +3 -0
  322. package/esm/common/utils/url-util.js +56 -0
  323. package/esm/common/utils/url-util.js.map +1 -0
  324. package/esm/common/utils/uuid.d.ts +2 -0
  325. package/esm/common/utils/uuid.js +61 -0
  326. package/esm/common/utils/uuid.js.map +1 -0
  327. package/esm/node/application/backend-application-state.d.ts +4 -0
  328. package/esm/node/application/backend-application-state.js +14 -0
  329. package/esm/node/application/backend-application-state.js.map +1 -0
  330. package/esm/node/application/backend-application.d.ts +10 -0
  331. package/esm/node/application/backend-application.js +52 -0
  332. package/esm/node/application/backend-application.js.map +1 -0
  333. package/esm/node/application/index.d.ts +2 -0
  334. package/esm/node/application/index.js +3 -0
  335. package/esm/node/application/index.js.map +1 -0
  336. package/esm/node/constants.d.ts +15 -0
  337. package/esm/node/constants.js +16 -0
  338. package/esm/node/constants.js.map +1 -0
  339. package/esm/node/context/context.d.ts +15 -0
  340. package/esm/node/context/context.js +58 -0
  341. package/esm/node/context/context.js.map +1 -0
  342. package/esm/node/context/index.d.ts +1 -0
  343. package/esm/node/context/index.js +2 -0
  344. package/esm/node/context/index.js.map +1 -0
  345. package/esm/node/index.d.ts +3 -0
  346. package/esm/node/index.js +4 -0
  347. package/esm/node/index.js.map +1 -0
  348. package/esm/node/static-module.d.ts +3 -0
  349. package/esm/node/static-module.js +4 -0
  350. package/esm/node/static-module.js.map +1 -0
  351. package/esm/node/utils/crc.d.ts +1 -0
  352. package/esm/node/utils/crc.js +7 -0
  353. package/esm/node/utils/crc.js.map +1 -0
  354. package/esm/node/utils/index.d.ts +1 -0
  355. package/esm/node/utils/index.js +2 -0
  356. package/esm/node/utils/index.js.map +1 -0
  357. package/esm/package.json +3 -0
  358. package/lib/common/application/application-entry.d.ts.map +1 -1
  359. package/lib/common/application/application-entry.js +21 -3
  360. package/lib/common/application/application-entry.js.map +1 -1
  361. package/lib/common/application/application-factory.d.ts +1 -0
  362. package/lib/common/application/application-factory.d.ts.map +1 -1
  363. package/lib/common/application/application-factory.js +1 -1
  364. package/lib/common/application/application-factory.js.map +1 -1
  365. package/lib/common/application/application-host.d.ts +39 -0
  366. package/lib/common/application/application-host.d.ts.map +1 -0
  367. package/lib/common/application/application-host.js +20 -0
  368. package/lib/common/application/application-host.js.map +1 -0
  369. package/lib/common/application/index.d.ts +1 -0
  370. package/lib/common/application/index.d.ts.map +1 -1
  371. package/lib/common/application/index.js +1 -0
  372. package/lib/common/application/index.js.map +1 -1
  373. package/lib/common/config/env-config-util.d.ts +49 -0
  374. package/lib/common/config/env-config-util.d.ts.map +1 -0
  375. package/lib/common/config/env-config-util.js +188 -0
  376. package/lib/common/config/env-config-util.js.map +1 -0
  377. package/lib/common/config/env-config-util.spec.d.ts +2 -0
  378. package/lib/common/config/env-config-util.spec.d.ts.map +1 -0
  379. package/lib/common/config/env-config-util.spec.js +314 -0
  380. package/lib/common/config/env-config-util.spec.js.map +1 -0
  381. package/lib/common/config/index.d.ts +1 -0
  382. package/lib/common/config/index.d.ts.map +1 -1
  383. package/lib/common/config/index.js +1 -0
  384. package/lib/common/config/index.js.map +1 -1
  385. package/package.json +114 -5
  386. package/src/common/application/application-entry.ts +20 -4
  387. package/src/common/application/application-factory.ts +1 -1
  388. package/src/common/application/application-host.ts +46 -0
  389. package/src/common/application/index.ts +1 -0
  390. package/src/common/config/env-config-util.spec.ts +341 -0
  391. package/src/common/config/env-config-util.ts +225 -0
  392. package/src/common/config/index.ts +1 -0
  393. package/cell-remote.yml +0 -3
@@ -0,0 +1,341 @@
1
+ import { describe, it } from 'bun:test';
2
+ import * as chai from 'chai';
3
+ import { EnvConfigUtil } from './env-config-util';
4
+ const expect = chai.expect;
5
+
6
+ describe('EnvConfigUtil', () => {
7
+ const config = () => ({
8
+ cell: {
9
+ server: { path: '/', port: 3000, endpoint: 'http://localhost:${cell.server.port}' },
10
+ 'serve-static': { enabled: true },
11
+ typeorm: { ormConfig: [{ type: 'sqlite', database: 'db.sql', logging: false }] },
12
+ cors: null,
13
+ },
14
+ accounts: { title: 'Accounts', providers: ['github'] },
15
+ mode: ['production'],
16
+ });
17
+
18
+ it('sets keys under cell, matching case, underscores and dashes loosely', () => {
19
+ const target = config();
20
+ const result = EnvConfigUtil.apply(
21
+ target,
22
+ {
23
+ CELL_BACKEND__SERVER__PORT: '8080',
24
+ CELL_BACKEND__SERVE_STATIC__ENABLED: 'FALSE',
25
+ CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE: '/data/db.sql',
26
+ CELL_BACKEND__TYPEORM__ORM_CONFIG__0__LOGGING: 'true',
27
+ PATH: '/usr/bin',
28
+ },
29
+ 'backend',
30
+ );
31
+ expect(result.problems).to.deep.equal([]);
32
+ expect(result.applied).to.deep.equal([
33
+ { variable: 'CELL_BACKEND__SERVER__PORT', path: 'cell.server.port' },
34
+ { variable: 'CELL_BACKEND__SERVE_STATIC__ENABLED', path: 'cell.serve-static.enabled' },
35
+ { variable: 'CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE', path: 'cell.typeorm.ormConfig.0.database' },
36
+ { variable: 'CELL_BACKEND__TYPEORM__ORM_CONFIG__0__LOGGING', path: 'cell.typeorm.ormConfig.0.logging' },
37
+ ]);
38
+ expect(target.cell.server.port).to.equal(8080);
39
+ expect(target.cell['serve-static'].enabled).to.equal(false);
40
+ expect(target.cell.typeorm.ormConfig[0]).to.deep.equal({ type: 'sqlite', database: '/data/db.sql', logging: true });
41
+ });
42
+
43
+ it('keeps expressions of other keys for later evaluation', () => {
44
+ const target = config();
45
+ EnvConfigUtil.apply(target, { CELL_BACKEND__SERVER__PORT: '8080' }, 'backend');
46
+ expect(target.cell.server.endpoint).to.equal('http://localhost:${cell.server.port}');
47
+ });
48
+
49
+ it('reaches top-level keys outside cell from the root', () => {
50
+ const target = config();
51
+ const { applied } = EnvConfigUtil.apply(target, { CELL_BACKEND__ACCOUNTS__TITLE: 'Team', CELL_BACKEND__CELL__SERVER__PATH: '/api' }, 'backend');
52
+ expect(applied.map(a => a.path)).to.deep.equal(['accounts.title', 'cell.server.path']);
53
+ expect(target.accounts.title).to.equal('Team');
54
+ expect(target.cell.server.path).to.equal('/api');
55
+ });
56
+
57
+ it('parses objects and arrays as JSON and leaves strings as they are', () => {
58
+ const target = config();
59
+ const result = EnvConfigUtil.apply(
60
+ target,
61
+ {
62
+ CELL_BACKEND__ACCOUNTS__PROVIDERS: '["github","gitlab"]',
63
+ CELL_BACKEND__CORS: '{"origin":"*"}',
64
+ CELL_BACKEND__SERVER__ENDPOINT: '8080',
65
+ },
66
+ 'backend',
67
+ );
68
+ expect(result.problems).to.deep.equal([]);
69
+ expect(target.accounts.providers).to.deep.equal(['github', 'gitlab']);
70
+ expect(target.cell.cors).to.deep.equal({ origin: '*' });
71
+ expect(target.cell.server.endpoint).to.equal('8080');
72
+ });
73
+
74
+ it('reports variables that match no key or do not fit its type, and changes nothing for them', () => {
75
+ const target = config();
76
+ const { applied, problems } = EnvConfigUtil.apply(
77
+ target,
78
+ {
79
+ CELL_BACKEND__SERVER__PROT: '1',
80
+ CELL_BACKEND__SERVR__PORT: '1',
81
+ CELL_BACKEND__SERVER__PORT: 'abc',
82
+ CELL_BACKEND__SERVE_STATIC__ENABLED: 'yes',
83
+ CELL_BACKEND__ACCOUNTS__PROVIDERS: 'github',
84
+ CELL_BACKEND__TYPEORM__ORM_CONFIG__3__TYPE: 'mysql',
85
+ CELL_BACKEND__SERVER__PORT__X: '1',
86
+ CELL_BACKEND__SERVER____PORT: '1',
87
+ },
88
+ 'backend',
89
+ );
90
+ expect(applied).to.deep.equal([]);
91
+ expect(target).to.deep.equal(config());
92
+ const messages = Object.fromEntries(problems.map(p => [p.variable, p.message]));
93
+ expect(messages.CELL_BACKEND__SERVER__PROT).to.equal(
94
+ "no key 'PROT' under cell.server (keys: path, port, endpoint). Only keys present in cell.yml can be overridden.",
95
+ );
96
+ expect(messages.CELL_BACKEND__SERVR__PORT).to.equal(
97
+ "no key 'SERVR' at the top level (keys: cell, accounts, mode) or under cell (keys: server, serve-static, typeorm, cors). Only keys present in cell.yml can be overridden.",
98
+ );
99
+ expect(messages.CELL_BACKEND__SERVER__PORT).to.equal("cell.server.port is a number, got 'abc'. Use a decimal number such as 8080, -1 or 0.5.");
100
+ expect(messages.CELL_BACKEND__SERVE_STATIC__ENABLED).to.equal("cell.serve-static.enabled is a boolean, got 'yes'. Use true or false.");
101
+ expect(messages.CELL_BACKEND__ACCOUNTS__PROVIDERS).to.contain('accounts.providers is an array; pass it as JSON');
102
+ expect(messages.CELL_BACKEND__TYPEORM__ORM_CONFIG__3__TYPE).to.contain('(indexes 0-0)');
103
+ expect(messages.CELL_BACKEND__SERVER__PORT__X).to.equal("cell.server.port is not an object, so it has no key 'X'.");
104
+ expect(messages.CELL_BACKEND__SERVER____PORT).to.contain('empty segment');
105
+ });
106
+
107
+ it('applies the backend variables of process.env and warns about the ones that do not apply', () => {
108
+ const variables = { CELL_BACKEND__SERVER__PORT: '8080', CELL_BACKEND__SERVER__PROT: '1', CELL_FRONTEND__SERVER__PATH: '/ui' };
109
+ const warn = console.warn;
110
+ const warnings: string[] = [];
111
+ console.warn = (message: string) => warnings.push(message);
112
+ Object.assign(process.env, variables);
113
+ try {
114
+ const target = config();
115
+ const result = EnvConfigUtil.applyProcessEnv(target);
116
+ expect(result.applied).to.deep.equal([{ variable: 'CELL_BACKEND__SERVER__PORT', path: 'cell.server.port' }]);
117
+ expect(target.cell.server).to.deep.include({ port: 8080, path: '/' });
118
+ expect(warnings).to.deep.equal([
119
+ "[cell] CELL_BACKEND__SERVER__PROT is ignored: no key 'PROT' under cell.server (keys: path, port, endpoint). Only keys present in cell.yml can be overridden.",
120
+ ]);
121
+ } finally {
122
+ console.warn = warn;
123
+ for (const name of Object.keys(variables)) {
124
+ delete process.env[name];
125
+ }
126
+ }
127
+ });
128
+
129
+ it('takes finite numbers in JSON syntax only', () => {
130
+ const port = (value: string) => {
131
+ const target = config();
132
+ const { applied, problems } = EnvConfigUtil.apply(target, { CELL_BACKEND__SERVER__PORT: value }, 'backend');
133
+ return applied.length === 1 ? target.cell.server.port : problems[0].message;
134
+ };
135
+ for (const [value, expected] of [['8080', 8080], ['0', 0], ['-1', -1], ['0.5', 0.5], ['1e3', 1000], ['-2.5E-1', -0.25]] as const) {
136
+ expect(port(value), value).to.equal(expected);
137
+ }
138
+ for (const value of ['Infinity', '-Infinity', 'NaN', '1e999', '0x10', '0b1', '1_000', '+1', '08080', '.5', '5.', '', ' 8080', '8080 ']) {
139
+ expect(port(value), JSON.stringify(value)).to.equal(`cell.server.port is a number, got '${value}'. Use a decimal number such as 8080, -1 or 0.5.`);
140
+ }
141
+ });
142
+
143
+ it('follows null in cell.yml with JSON when the value is JSON, else text', () => {
144
+ const cors = (value: string) => {
145
+ const target = config();
146
+ EnvConfigUtil.apply(target, { CELL_BACKEND__CORS: value }, 'backend');
147
+ return target.cell.cors;
148
+ };
149
+ expect(cors('null')).to.equal(null);
150
+ expect(cors('5')).to.equal(5);
151
+ expect(cors('false')).to.equal(false);
152
+ expect(cors('"5"')).to.equal('5');
153
+ expect(cors('[1]')).to.deep.equal([1]);
154
+ expect(cors('*')).to.equal('*');
155
+ expect(cors('')).to.equal('');
156
+ });
157
+
158
+ it('keeps a value that is one ${...} expression for evaluation, whatever the type of the key', () => {
159
+ const target = config();
160
+ const { applied, problems } = EnvConfigUtil.apply(
161
+ target,
162
+ {
163
+ CELL_BACKEND__SERVER__PORT: '${env.PORT ?: 3000}',
164
+ CELL_BACKEND__SERVE_STATIC__ENABLED: '${env.STATIC == "on"}',
165
+ CELL_BACKEND__ACCOUNTS__PROVIDERS: '${cell.providers}',
166
+ CELL_BACKEND__SERVER__PATH: '/${env.BASE}',
167
+ },
168
+ 'backend',
169
+ );
170
+ expect(problems).to.deep.equal([]);
171
+ expect(applied).to.have.length(4);
172
+ expect(target.cell.server.port).to.equal('${env.PORT ?: 3000}');
173
+ expect(target.cell['serve-static'].enabled).to.equal('${env.STATIC == "on"}');
174
+ expect(target.accounts.providers).to.equal('${cell.providers}');
175
+ expect(target.cell.server.path).to.equal('/${env.BASE}');
176
+ });
177
+
178
+ it('rejects text around an expression where the key needs a number, boolean, object or array', () => {
179
+ const { applied, problems } = EnvConfigUtil.apply(
180
+ config(),
181
+ { CELL_BACKEND__SERVER__PORT: '80${env.X}', CELL_BACKEND__SERVE_STATIC__ENABLED: '${a} ${b}', CELL_BACKEND__ACCOUNTS__PROVIDERS: 'x${a}' },
182
+ 'backend',
183
+ );
184
+ expect(applied).to.deep.equal([]);
185
+ expect(problems.map(p => p.variable)).to.deep.equal([
186
+ 'CELL_BACKEND__ACCOUNTS__PROVIDERS',
187
+ 'CELL_BACKEND__SERVER__PORT',
188
+ 'CELL_BACKEND__SERVE_STATIC__ENABLED',
189
+ ]);
190
+ });
191
+
192
+ it('takes true and false in any case for booleans and names the value it rejects', () => {
193
+ const enabled = (value: string) => {
194
+ const target = config();
195
+ const { problems } = EnvConfigUtil.apply(target, { CELL_BACKEND__SERVE_STATIC__ENABLED: value }, 'backend');
196
+ return problems.length > 0 ? problems[0].message : target.cell['serve-static'].enabled;
197
+ };
198
+ expect(enabled('FALSE')).to.equal(false);
199
+ expect(enabled('True')).to.equal(true);
200
+ for (const value of ['yes', '1', '0', '', ' true']) {
201
+ expect(enabled(value)).to.equal(`cell.serve-static.enabled is a boolean, got '${value}'. Use true or false.`);
202
+ }
203
+ });
204
+
205
+ it('rejects integers that a number cannot hold exactly', () => {
206
+ const port = (value: string) => {
207
+ const target = config();
208
+ const { problems } = EnvConfigUtil.apply(target, { CELL_BACKEND__SERVER__PORT: value }, 'backend');
209
+ return problems.length > 0 ? problems[0].message : target.cell.server.port;
210
+ };
211
+ expect(port('9007199254740991')).to.equal(9007199254740991);
212
+ expect(port('-9007199254740991')).to.equal(-9007199254740991);
213
+ expect(port('1.5e300')).to.equal(1.5e300);
214
+ expect(port('9007199254740993')).to.equal(
215
+ "cell.server.port is a number, got '9007199254740993', which is too large to keep exactly. Use a string in cell.yml for such values.",
216
+ );
217
+ });
218
+
219
+ it('addresses array items by canonical index only', () => {
220
+ const target = config();
221
+ const { applied, problems } = EnvConfigUtil.apply(
222
+ target,
223
+ {
224
+ CELL_BACKEND__ACCOUNTS__PROVIDERS__00: 'gitlab',
225
+ CELL_BACKEND__TYPEORM__ORM_CONFIG__00__TYPE: 'mysql',
226
+ CELL_BACKEND__TYPEORM__ORM_CONFIG__0__TYPE: 'postgres',
227
+ },
228
+ 'backend',
229
+ );
230
+ expect(applied.map(a => a.path)).to.deep.equal(['cell.typeorm.ormConfig.0.type']);
231
+ expect(problems.map(p => p.variable)).to.deep.equal(['CELL_BACKEND__ACCOUNTS__PROVIDERS__00', 'CELL_BACKEND__TYPEORM__ORM_CONFIG__00__TYPE']);
232
+ expect(problems[0].message).to.equal("no key '00' under accounts.providers (indexes 0-0). Only keys present in cell.yml can be overridden.");
233
+ // '00' must not become a property of the array next to item 0.
234
+ expect(Object.keys(target.accounts.providers)).to.deep.equal(['0']);
235
+ expect(target.cell.typeorm.ormConfig[0].type).to.equal('postgres');
236
+ });
237
+
238
+ describe('keys set by more than one variable', () => {
239
+ const conflict = (env: Record<string, string>) => {
240
+ const target = config();
241
+ return { target, ...EnvConfigUtil.apply(target, env, 'backend') };
242
+ };
243
+
244
+ it('applies none of the variables that set the same key, however they spell it', () => {
245
+ const { target, applied, problems } = conflict({
246
+ CELL_BACKEND__SERVER__PORT: '1',
247
+ CELL_BACKEND__CELL__SERVER__PORT: '2',
248
+ CELL_BACKEND__SERVER__P_ORT: '3',
249
+ CELL_BACKEND__SERVER__PATH: '/api',
250
+ });
251
+ expect(applied).to.deep.equal([{ variable: 'CELL_BACKEND__SERVER__PATH', path: 'cell.server.path' }]);
252
+ expect(target.cell.server.port).to.equal(3000);
253
+ expect(problems.map(p => p.variable)).to.deep.equal(['CELL_BACKEND__CELL__SERVER__PORT', 'CELL_BACKEND__SERVER__PORT', 'CELL_BACKEND__SERVER__P_ORT']);
254
+ expect(problems[1].message).to.equal(
255
+ 'sets cell.server.port, which CELL_BACKEND__CELL__SERVER__PORT (cell.server.port), CELL_BACKEND__SERVER__P_ORT (cell.server.port) also set. Set each key with one variable; to change items of an object or array you replace, write them into its JSON.',
256
+ );
257
+ });
258
+
259
+ it('applies neither a key nor a key inside it, in either order of the names', () => {
260
+ const pairs = [
261
+ // The whole array sorts first, then the item.
262
+ ['CELL_BACKEND__TYPEORM__ORM_CONFIG', 'CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE'],
263
+ // The item sorts first: applied in order, the array would have wiped it out.
264
+ ['CELL_BACKEND__TYPEORM__ORM_CONFIG', 'CELL_BACKEND__CELL__TYPEORM__ORM_CONFIG__0__DATABASE'],
265
+ ['CELL_BACKEND__CELL__TYPEORM__ORM_CONFIG', 'CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE'],
266
+ ];
267
+ for (const [whole, item] of pairs) {
268
+ const { target, applied, problems } = conflict({ [whole]: '[{"type":"mysql"}]', [item]: 'x.sql' });
269
+ expect(applied, `${whole} + ${item}`).to.deep.equal([]);
270
+ expect(problems.map(p => p.variable).sort()).to.deep.equal([item, whole].sort());
271
+ expect(problems.find(p => p.variable === item)!.message).to.contain(`which ${whole} (cell.typeorm.ormConfig) also sets`);
272
+ expect(target.cell.typeorm.ormConfig).to.deep.equal(config().cell.typeorm.ormConfig);
273
+ }
274
+ });
275
+
276
+ it('lets variables of different keys under the same object apply', () => {
277
+ const { applied, problems } = conflict({ CELL_BACKEND__TYPEORM__ORM_CONFIG__0__TYPE: 'mysql', CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE: 'x' });
278
+ expect(problems).to.deep.equal([]);
279
+ expect(applied).to.have.length(2);
280
+ });
281
+
282
+ it('does not depend on the order of the variables in the environment', () => {
283
+ const names = ['CELL_BACKEND__TYPEORM__ORM_CONFIG__0__DATABASE', 'CELL_BACKEND__CELL__TYPEORM__ORM_CONFIG', 'CELL_BACKEND__SERVER__PORT'];
284
+ const run = (order: string[]) => {
285
+ const target = config();
286
+ const env = Object.fromEntries(order.map(name => [name, name.endsWith('ORM_CONFIG') ? '[]' : '1']));
287
+ return JSON.stringify({ result: EnvConfigUtil.apply(target, env, 'backend'), target });
288
+ };
289
+ expect(run([...names].reverse())).to.equal(run(names));
290
+ });
291
+ });
292
+
293
+ describe('top-level keys with the same name as keys under cell', () => {
294
+ const shadowed = () => ({ cell: { server: { port: 3000 }, accounts: { title: 'Inner' } }, server: { x: 1 }, accounts: { title: 'Outer', team: 't' } });
295
+
296
+ it('looks up the first key at the top level, then under cell', () => {
297
+ const target = shadowed();
298
+ const { applied, problems } = EnvConfigUtil.apply(
299
+ target,
300
+ { CELL_BACKEND__SERVER__X: '5', CELL_BACKEND__ACCOUNTS__TEAM: 'u', CELL_BACKEND__ACCOUNTS__TITLE: 'Top' },
301
+ 'backend',
302
+ );
303
+ expect(problems).to.deep.equal([]);
304
+ expect(applied).to.deep.equal([
305
+ { variable: 'CELL_BACKEND__ACCOUNTS__TEAM', path: 'accounts.team', shadows: 'cell.accounts' },
306
+ { variable: 'CELL_BACKEND__ACCOUNTS__TITLE', path: 'accounts.title', shadows: 'cell.accounts' },
307
+ { variable: 'CELL_BACKEND__SERVER__X', path: 'server.x', shadows: 'cell.server' },
308
+ ]);
309
+ expect(target).to.deep.equal({ cell: { server: { port: 3000 }, accounts: { title: 'Inner' } }, server: { x: 5 }, accounts: { title: 'Top', team: 'u' } });
310
+ });
311
+
312
+ it('reaches the keys under cell with CELL__, and reports a key missing from the top-level one', () => {
313
+ const target = shadowed();
314
+ const { applied, problems } = EnvConfigUtil.apply(
315
+ target,
316
+ { CELL_BACKEND__CELL__ACCOUNTS__TITLE: 'In', CELL_BACKEND__CELL__SERVER__PORT: '8080', CELL_BACKEND__SERVER__PORT: '1' },
317
+ 'backend',
318
+ );
319
+ expect(applied).to.deep.equal([
320
+ { variable: 'CELL_BACKEND__CELL__ACCOUNTS__TITLE', path: 'cell.accounts.title' },
321
+ { variable: 'CELL_BACKEND__CELL__SERVER__PORT', path: 'cell.server.port' },
322
+ ]);
323
+ expect(target.cell).to.deep.equal({ server: { port: 8080 }, accounts: { title: 'In' } });
324
+ expect(problems).to.deep.equal([
325
+ { variable: 'CELL_BACKEND__SERVER__PORT', message: "no key 'PORT' under server (keys: x). Only keys present in cell.yml can be overridden." },
326
+ ]);
327
+ });
328
+
329
+ it('falls back to cell when the top level has no such key', () => {
330
+ const { applied } = EnvConfigUtil.apply(config(), { CELL_BACKEND__SERVER__PORT: '1' }, 'backend');
331
+ expect(applied).to.deep.equal([{ variable: 'CELL_BACKEND__SERVER__PORT', path: 'cell.server.port' }]);
332
+ });
333
+ });
334
+
335
+ it('only reads the variables of the given target', () => {
336
+ const target = config();
337
+ const result = EnvConfigUtil.apply(target, { CELL_FRONTEND__SERVER__PORT: '1', CELL_BACKEND__SERVER__PORT: '2' }, 'frontend');
338
+ expect(result.applied).to.deep.equal([{ variable: 'CELL_FRONTEND__SERVER__PORT', path: 'cell.server.port' }]);
339
+ expect(target.cell.server.port).to.equal(1);
340
+ });
341
+ });
@@ -0,0 +1,225 @@
1
+ /** An environment variable that was applied to the configuration. */
2
+ export interface EnvOverride {
3
+ variable: string;
4
+ /** Dotted path of the overridden key, e.g. `cell.server.port`. */
5
+ path: string;
6
+ /**
7
+ * Set when the first key also exists under `cell`: the top-level key wins, and this is the path
8
+ * under `cell` that the variable does not set (reach it with `CELL_<TARGET>__CELL__...`).
9
+ */
10
+ shadows?: string;
11
+ }
12
+
13
+ /** An environment variable with the override prefix that could not be applied. */
14
+ export interface EnvOverrideProblem {
15
+ variable: string;
16
+ message: string;
17
+ }
18
+
19
+ export interface EnvOverrideResult {
20
+ applied: EnvOverride[];
21
+ problems: EnvOverrideProblem[];
22
+ }
23
+
24
+ /**
25
+ * Overrides configuration keys from environment variables: `CELL_BACKEND__SERVER__PORT=8080` sets
26
+ * `cell.server.port` of the backend. Segments are separated by `__` and matched against existing
27
+ * keys ignoring case, `_` and `-` (`ORM_CONFIG` matches `ormConfig`, `SERVE_STATIC` matches
28
+ * `serve-static`); array items are addressed by canonical index. The first key is looked up at the
29
+ * top level, then under `cell`, so `SERVER__PORT` is short for `CELL__SERVER__PORT` unless the
30
+ * project has a top-level `server` of its own; `CELL__...` always means `cell`.
31
+ *
32
+ * Only existing keys can be overridden, so a misspelled variable is reported instead of silently
33
+ * ignored. Each key is set by one variable at most: variables that set the same key, or a key and
34
+ * one inside it, are all reported and none applies, whatever their order. The value is converted to
35
+ * the type of the value it replaces (a finite number in JSON syntax, `true` / `false`, JSON for
36
+ * objects and arrays, JSON or text where cell.yml has `null`, text for strings); a value that is one
37
+ * `${...}` expression is kept and evaluated like cell.yml. Overrides land before `${...}`
38
+ * expressions are evaluated, so references such as `${cell.server.port}` see the new value. The
39
+ * backend applies its variables at startup; the frontend applies them when it is built.
40
+ */
41
+ export namespace EnvConfigUtil {
42
+
43
+ export const PREFIXES = { backend: 'CELL_BACKEND__', frontend: 'CELL_FRONTEND__' } as const;
44
+
45
+ export type Target = keyof typeof PREFIXES;
46
+
47
+ interface Resolved {
48
+ variable: string;
49
+ value: string;
50
+ /** Keys from the root, as written in the configuration. */
51
+ keys: string[];
52
+ shadows?: string;
53
+ }
54
+
55
+ /** Applies the variables of `target` in `env` to `config` in place. */
56
+ export function apply(config: Record<string, any>, env: Record<string, string | undefined>, target: Target): EnvOverrideResult {
57
+ const result: EnvOverrideResult = { applied: [], problems: [] };
58
+ const prefix = PREFIXES[target];
59
+ const resolved: Resolved[] = [];
60
+ for (const variable of Object.keys(env).filter(name => name.startsWith(prefix)).sort()) {
61
+ const value = env[variable];
62
+ if (value === undefined) {
63
+ continue;
64
+ }
65
+ try {
66
+ resolved.push({ variable, value, ...resolve(config, variable.slice(prefix.length).split('__')) });
67
+ } catch (error) {
68
+ result.problems.push({ variable, message: (error as Error).message });
69
+ }
70
+ }
71
+ // Paths are resolved against cell.yml before anything changes, so the outcome never depends on the order of the variables.
72
+ for (const entry of resolved) {
73
+ const path = entry.keys.join('.');
74
+ const others = resolved.filter(other => other !== entry && overlaps(entry.keys, other.keys));
75
+ if (others.length > 0) {
76
+ const list = others.map(other => `${other.variable} (${other.keys.join('.')})`).join(', ');
77
+ result.problems.push({ variable: entry.variable, message: `sets ${path}, which ${list} also set${others.length === 1 ? 's' : ''}. Set each key with one variable; to change items of an object or array you replace, write them into its JSON.` });
78
+ continue;
79
+ }
80
+ try {
81
+ assign(config, entry.keys, entry.value);
82
+ result.applied.push({ variable: entry.variable, path, ...(entry.shadows ? { shadows: entry.shadows } : {}) });
83
+ } catch (error) {
84
+ result.problems.push({ variable: entry.variable, message: (error as Error).message });
85
+ }
86
+ }
87
+ result.problems.sort((x, y) => (x.variable < y.variable ? -1 : x.variable > y.variable ? 1 : 0));
88
+ return result;
89
+ }
90
+
91
+ /** Applies the backend variables of `process.env` and warns about the ones that do not apply. */
92
+ export function applyProcessEnv(config: Record<string, any>): EnvOverrideResult {
93
+ const result = apply(config, process.env, 'backend');
94
+ for (const problem of result.problems) {
95
+ console.warn(`[cell] ${problem.variable} is ignored: ${problem.message}`);
96
+ }
97
+ return result;
98
+ }
99
+
100
+ /** The same key, or one inside the other. */
101
+ function overlaps(a: string[], b: string[]): boolean {
102
+ const length = Math.min(a.length, b.length);
103
+ return a.slice(0, length).every((key, i) => key === b[i]);
104
+ }
105
+
106
+ function resolve(config: Record<string, any>, segments: string[]): Pick<Resolved, 'keys' | 'shadows'> {
107
+ if (segments.some(segment => !segment)) {
108
+ throw new Error('empty segment; separate keys with exactly two underscores.');
109
+ }
110
+ const cell = config.cell && typeof config.cell === 'object' ? config.cell : undefined;
111
+ const top = find(config, segments[0]);
112
+ const inCell = cell ? find(cell, segments[0]) : undefined;
113
+ if (top === undefined && inCell === undefined) {
114
+ const cellKeys = cell ? ` or under cell (keys: ${Object.keys(cell).join(', ') || '(none)'})` : '';
115
+ throw new Error(
116
+ `no key '${segments[0]}' at the top level (keys: ${Object.keys(config).join(', ') || '(none)'})${cellKeys}. Only keys present in cell.yml can be overridden.`,
117
+ );
118
+ }
119
+ const keys: string[] = top === undefined ? ['cell'] : [];
120
+ const shadows = top !== undefined && inCell !== undefined && top !== 'cell' ? `cell.${inCell}` : undefined;
121
+ let node: any = top === undefined ? cell : config;
122
+ for (let i = 0; i < segments.length; i++) {
123
+ const key = find(node, segments[i]);
124
+ if (key === undefined) {
125
+ const where = keys.length > 0 ? keys.join('.') : 'the top level';
126
+ const available = Array.isArray(node) ? `indexes 0-${node.length - 1}` : `keys: ${Object.keys(node).join(', ') || '(none)'}`;
127
+ throw new Error(`no key '${segments[i]}' under ${where} (${available}). Only keys present in cell.yml can be overridden.`);
128
+ }
129
+ keys.push(key);
130
+ if (i < segments.length - 1) {
131
+ if (!node[key] || typeof node[key] !== 'object') {
132
+ throw new Error(`${keys.join('.')} is not an object, so it has no key '${segments[i + 1]}'.`);
133
+ }
134
+ node = node[key];
135
+ }
136
+ }
137
+ return { keys, ...(shadows ? { shadows } : {}) };
138
+ }
139
+
140
+ function assign(config: Record<string, any>, keys: string[], value: string): void {
141
+ const parent = keys.slice(0, -1).reduce((node, key) => node[key], config);
142
+ const last = keys[keys.length - 1];
143
+ parent[last] = convert(parent[last], value, keys.join('.'));
144
+ }
145
+
146
+ function find(node: any, segment: string): string | undefined {
147
+ if (Array.isArray(node)) {
148
+ // Canonical indexes only: '08' would set a property named '08', not item 8.
149
+ return /^(0|[1-9]\d*)$/.test(segment) && Number(segment) < node.length ? segment : undefined;
150
+ }
151
+ const wanted = normalize(segment);
152
+ const keys = Object.keys(node);
153
+ return keys.find(key => key === segment) ?? keys.find(key => normalize(key) === wanted);
154
+ }
155
+
156
+ function normalize(key: string): string {
157
+ return key.replace(/[-_]/g, '').toLowerCase();
158
+ }
159
+
160
+ /** JSON number syntax: `Number()` would also take '', 'Infinity', '0x10' and ' 8 '. */
161
+ const NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/;
162
+
163
+ /** A value that is one `${...}` expression and nothing else. */
164
+ function isExpression(value: string): boolean {
165
+ return value.startsWith('${') && value.endsWith('}') && value.indexOf('${', 2) === -1;
166
+ }
167
+
168
+ /**
169
+ * Converts `value` to the type of `current`, the value in cell.yml. A value that is one `${...}`
170
+ * expression is kept for evaluation, as if written in cell.yml, so its result decides the type:
171
+ * `CELL_BACKEND__SERVER__PORT='${env.PORT}'` works although the port is a number.
172
+ */
173
+ function convert(current: unknown, value: string, path: string): unknown {
174
+ if (isExpression(value)) {
175
+ return value;
176
+ }
177
+ switch (typeof current) {
178
+ case 'number':
179
+ return number(value, path);
180
+ case 'boolean':
181
+ if (!/^(true|false)$/i.test(value)) {
182
+ throw new Error(`${path} is a boolean, got '${value}'. Use true or false.`);
183
+ }
184
+ return value.toLowerCase() === 'true';
185
+ case 'object':
186
+ if (current === null) {
187
+ // No type to follow: JSON when it is JSON (null, 5, true, "x", [], {}), else the text.
188
+ const parsed = parse(value);
189
+ return parsed ? parsed.value : value;
190
+ }
191
+ return json(current, value, path);
192
+ default:
193
+ return value;
194
+ }
195
+ }
196
+
197
+ function number(value: string, path: string): number {
198
+ const result = NUMBER.test(value) ? Number(value) : NaN;
199
+ if (!Number.isFinite(result)) {
200
+ throw new Error(`${path} is a number, got '${value}'. Use a decimal number such as 8080, -1 or 0.5.`);
201
+ }
202
+ // An integer literal past 2^53 would silently become a different number.
203
+ if (/^-?\d+$/.test(value) && !Number.isSafeInteger(result)) {
204
+ throw new Error(`${path} is a number, got '${value}', which is too large to keep exactly. Use a string in cell.yml for such values.`);
205
+ }
206
+ return result;
207
+ }
208
+
209
+ function json(current: object, value: string, path: string): unknown {
210
+ const kind = Array.isArray(current) ? 'an array' : 'an object';
211
+ const parsed = parse(value)?.value;
212
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed) !== Array.isArray(current)) {
213
+ throw new Error(`${path} is ${kind}; pass it as JSON, or override its keys one by one.`);
214
+ }
215
+ return parsed;
216
+ }
217
+
218
+ function parse(value: string): { value: unknown } | undefined {
219
+ try {
220
+ return { value: JSON.parse(value) };
221
+ } catch {
222
+ return undefined;
223
+ }
224
+ }
225
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './config-protocol';
2
2
  export * from './config-provider';
3
3
  export * from './config-util';
4
+ export * from './env-config-util';
package/cell-remote.yml DELETED
@@ -1,3 +0,0 @@
1
- cell:
2
- logger:
3
- level: ${ 'info' | onTarget('backend') || 'error' }