@zudojs/core 0.1.0 → 1.1.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 (485) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -7
  3. package/dist/application/application.d.ts +43 -2
  4. package/dist/application/application.js +111 -13
  5. package/dist/application/applicationContext.context.d.ts +27 -1
  6. package/dist/application/applicationContext.context.js +22 -2
  7. package/dist/application/createApplication.d.ts +78 -0
  8. package/dist/application/createApplication.js +109 -0
  9. package/dist/application/index.d.ts +2 -1
  10. package/dist/application/index.js +2 -1
  11. package/dist/configuration/configurationManager.manager.d.ts +42 -0
  12. package/dist/configuration/configurationManager.manager.js +104 -7
  13. package/dist/configuration/core/configuration.d.ts +60 -15
  14. package/dist/configuration/core/configuration.js +248 -51
  15. package/dist/configuration/core/configurationKey.key.d.ts +4 -2
  16. package/dist/configuration/core/configurationKey.key.js +2 -13
  17. package/dist/configuration/core/configurationPath.path.d.ts +17 -0
  18. package/dist/configuration/core/configurationPath.path.js +33 -0
  19. package/dist/configuration/core/index.d.ts +7 -1
  20. package/dist/configuration/core/index.js +1 -0
  21. package/dist/configuration/error/configurationError.error.d.ts +11 -0
  22. package/dist/configuration/error/configurationError.error.js +29 -1
  23. package/dist/configuration/error/configurationRedactor.redactor.d.ts +16 -0
  24. package/dist/configuration/error/configurationRedactor.redactor.js +83 -5
  25. package/dist/configuration/error/index.d.ts +2 -1
  26. package/dist/configuration/error/index.js +2 -1
  27. package/dist/configuration/index.d.ts +1 -1
  28. package/dist/configuration/loader/configurationLoader.loader.d.ts +47 -9
  29. package/dist/configuration/loader/configurationLoader.loader.js +107 -26
  30. package/dist/configuration/loader/index.d.ts +1 -1
  31. package/dist/configuration/loader/index.js +1 -1
  32. package/dist/configuration/registry/configurationProvider.provider.d.ts +26 -1
  33. package/dist/configuration/registry/configurationProvider.provider.js +33 -7
  34. package/dist/configuration/registry/configurationRegistry.registry.js +2 -1
  35. package/dist/configuration/schema/configurationSchema.schema.d.ts +0 -4
  36. package/dist/configuration/schema/configurationSchema.schema.js +11 -32
  37. package/dist/configuration/schema/configurationValidation.validator.d.ts +14 -2
  38. package/dist/configuration/schema/configurationValidation.validator.js +55 -7
  39. package/dist/configuration/schema/index.d.ts +1 -1
  40. package/dist/configuration/schema/index.js +1 -1
  41. package/dist/container/container.d.ts +51 -5
  42. package/dist/container/container.js +104 -33
  43. package/dist/container/index.d.ts +1 -1
  44. package/dist/container/index.js +1 -1
  45. package/dist/container/scope.d.ts +7 -6
  46. package/dist/context/core/contextAliases.deprecated.d.ts +32 -0
  47. package/dist/context/core/contextAliases.deprecated.js +6 -0
  48. package/dist/context/core/executionContext.context.d.ts +8 -0
  49. package/dist/context/core/executionContext.context.js +38 -15
  50. package/dist/context/core/index.d.ts +2 -2
  51. package/dist/context/core/index.js +2 -2
  52. package/dist/context/index.d.ts +20 -0
  53. package/dist/context/index.js +20 -0
  54. package/dist/context/provider/contextProvider.provider.d.ts +7 -4
  55. package/dist/context/provider/contextProvider.provider.js +9 -6
  56. package/dist/context/provider/contextStorage.storage.d.ts +47 -7
  57. package/dist/context/provider/contextStorage.storage.js +54 -12
  58. package/dist/context/provider/defaultContextStorage.storage.d.ts +18 -0
  59. package/dist/context/provider/defaultContextStorage.storage.js +20 -0
  60. package/dist/context/provider/index.d.ts +2 -1
  61. package/dist/context/provider/index.js +1 -0
  62. package/dist/errors/exceptions.d.ts +22 -0
  63. package/dist/errors/exceptions.js +38 -1
  64. package/dist/errors/frameworkError.error.d.ts +6 -9
  65. package/dist/errors/index.d.ts +1 -1
  66. package/dist/errors/index.js +1 -1
  67. package/dist/index.d.ts +4 -0
  68. package/dist/index.js +14 -0
  69. package/dist/lifecycle/core/index.d.ts +1 -1
  70. package/dist/lifecycle/core/index.js +1 -1
  71. package/dist/lifecycle/core/lifecycle.d.ts +47 -2
  72. package/dist/lifecycle/core/lifecycle.js +251 -85
  73. package/dist/lifecycle/core/lifecycleRegistry.registry.d.ts +8 -0
  74. package/dist/lifecycle/core/lifecycleRegistry.registry.js +20 -1
  75. package/dist/lifecycle/manager/lifecycleManager.manager.d.ts +21 -2
  76. package/dist/lifecycle/manager/lifecycleManager.manager.js +62 -99
  77. package/dist/lifecycle/scope/lifecycleScope.scope.d.ts +22 -1
  78. package/dist/lifecycle/scope/lifecycleScope.scope.js +85 -17
  79. package/dist/logging/console/consoleLogger.logger.d.ts +20 -1
  80. package/dist/logging/console/consoleLogger.logger.js +77 -11
  81. package/dist/logging/console/loggerFactory.factory.d.ts +6 -5
  82. package/dist/logging/console/loggerFactory.factory.js +1 -7
  83. package/dist/logging/core/index.d.ts +4 -3
  84. package/dist/logging/core/index.js +4 -3
  85. package/dist/logging/core/logEntry.entry.d.ts +41 -3
  86. package/dist/logging/core/logEntry.entry.js +125 -4
  87. package/dist/logging/core/logLevel.level.d.ts +18 -0
  88. package/dist/logging/core/logLevel.level.js +25 -1
  89. package/dist/logging/core/logRedaction.redaction.d.ts +38 -0
  90. package/dist/logging/core/logRedaction.redaction.js +19 -0
  91. package/dist/logging/core/logger.d.ts +14 -11
  92. package/dist/logging/core/logger.js +31 -6
  93. package/dist/logging/core/loggerContext.context.d.ts +12 -0
  94. package/dist/logging/core/loggerContext.context.js +19 -0
  95. package/dist/logging/core/loggerOptions.options.d.ts +17 -0
  96. package/dist/modules/index.d.ts +0 -1
  97. package/dist/modules/index.js +0 -6
  98. package/dist/modules/module.d.ts +7 -1
  99. package/dist/modules/moduleContext.context.d.ts +41 -7
  100. package/dist/modules/moduleContext.context.js +31 -8
  101. package/dist/modules/moduleDefinition.definition.d.ts +11 -7
  102. package/dist/modules/moduleDefinition.definition.js +41 -8
  103. package/dist/modules/moduleDependency/index.d.ts +2 -2
  104. package/dist/modules/moduleDependency/index.js +1 -1
  105. package/dist/modules/moduleDependency/moduleDependency.graph.d.ts +19 -2
  106. package/dist/modules/moduleDependency/moduleDependency.graph.js +122 -8
  107. package/dist/modules/moduleDependency/moduleDependency.ordering.d.ts +8 -0
  108. package/dist/modules/moduleDependency/moduleDependency.ordering.js +85 -57
  109. package/dist/modules/moduleDependency/moduleDependency.type.d.ts +28 -1
  110. package/dist/modules/moduleError/index.d.ts +1 -1
  111. package/dist/modules/moduleError/index.js +1 -1
  112. package/dist/modules/moduleError/moduleError.dependency.d.ts +11 -0
  113. package/dist/modules/moduleError/moduleError.dependency.js +15 -0
  114. package/dist/modules/moduleLifecycle/index.d.ts +5 -2
  115. package/dist/modules/moduleLifecycle/index.js +4 -1
  116. package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.d.ts +73 -10
  117. package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.js +204 -19
  118. package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.d.ts +30 -5
  119. package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.js +130 -10
  120. package/dist/modules/moduleLifecycle/moduleLifecycle.type.d.ts +78 -28
  121. package/dist/modules/moduleLifecycle/moduleLifecycle.type.js +15 -4
  122. package/dist/modules/moduleLoader/moduleLoader.loader.d.ts +39 -5
  123. package/dist/modules/moduleLoader/moduleLoader.loader.js +168 -59
  124. package/dist/modules/moduleLoader/moduleLoader.type.d.ts +4 -2
  125. package/dist/modules/moduleLoader/moduleLoader.type.js +10 -3
  126. package/dist/modules/moduleMetadata.metadata.js +15 -5
  127. package/dist/modules/moduleRegistry/index.d.ts +1 -1
  128. package/dist/modules/moduleRegistry/moduleRegistry.registry.d.ts +2 -2
  129. package/dist/modules/moduleRegistry/moduleRegistry.registry.js +38 -6
  130. package/dist/modules/moduleRegistry/moduleRegistry.type.d.ts +18 -1
  131. package/dist/runtime/index.d.ts +17 -15
  132. package/dist/runtime/index.js +14 -10
  133. package/dist/runtime/runtime.d.ts +135 -33
  134. package/dist/runtime/runtime.js +344 -114
  135. package/dist/runtime/runtimeBootstrap/index.d.ts +2 -1
  136. package/dist/runtime/runtimeBootstrap/index.js +1 -1
  137. package/dist/runtime/runtimeBootstrap/pipeline/index.d.ts +2 -2
  138. package/dist/runtime/runtimeBootstrap/pipeline/index.js +1 -2
  139. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.d.ts +41 -15
  140. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.js +111 -76
  141. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.d.ts +7 -4
  142. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.js +87 -59
  143. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.d.ts +10 -4
  144. package/dist/runtime/runtimeContext/index.d.ts +3 -5
  145. package/dist/runtime/runtimeContext/index.js +2 -4
  146. package/dist/runtime/runtimeContext/runtimeContext.factory.d.ts +10 -4
  147. package/dist/runtime/runtimeContext/runtimeContext.factory.js +30 -7
  148. package/dist/runtime/runtimeContext/runtimeContext.type.d.ts +36 -47
  149. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.d.ts +5 -0
  150. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.js +6 -4
  151. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.d.ts +4 -0
  152. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.js +7 -9
  153. package/dist/runtime/runtimeEnvironment/index.d.ts +2 -2
  154. package/dist/runtime/runtimeEnvironment/index.js +1 -1
  155. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.d.ts +20 -17
  156. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.js +20 -13
  157. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.d.ts +12 -1
  158. package/dist/runtime/runtimeError/index.d.ts +3 -3
  159. package/dist/runtime/runtimeError/index.js +1 -1
  160. package/dist/runtime/runtimeError/runtimeError.base.d.ts +15 -18
  161. package/dist/runtime/runtimeError/runtimeError.base.js +38 -36
  162. package/dist/runtime/runtimeError/runtimeError.lifecycle.d.ts +23 -8
  163. package/dist/runtime/runtimeError/runtimeError.lifecycle.js +31 -7
  164. package/dist/runtime/runtimeError/runtimeError.specialized.d.ts +1 -1
  165. package/dist/runtime/runtimeError/runtimeError.specialized.js +1 -1
  166. package/dist/runtime/runtimeError/runtimeError.type.d.ts +5 -9
  167. package/dist/runtime/runtimeLogger.d.ts +2 -2
  168. package/dist/runtime/runtimeLogger.js +3 -3
  169. package/dist/runtime/runtimeOptions/index.d.ts +1 -1
  170. package/dist/runtime/runtimeOptions/runtimeOptions.defaults.d.ts +1 -1
  171. package/dist/runtime/runtimeOptions/runtimeOptions.defaults.js +2 -0
  172. package/dist/runtime/runtimeOptions/runtimeOptions.resolver.js +13 -2
  173. package/dist/runtime/runtimeOptions/runtimeOptions.type.d.ts +45 -16
  174. package/dist/runtime/runtimeOptions/runtimeOptions.validation.js +0 -1
  175. package/dist/runtime/runtimeShutdown/index.d.ts +3 -2
  176. package/dist/runtime/runtimeShutdown/index.js +2 -2
  177. package/dist/runtime/runtimeShutdown/pipeline/index.d.ts +2 -1
  178. package/dist/runtime/runtimeShutdown/pipeline/index.js +1 -1
  179. package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.d.ts +37 -7
  180. package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.js +85 -51
  181. package/dist/runtime/runtimeShutdown/runtimeShutdown.core.d.ts +8 -16
  182. package/dist/runtime/runtimeShutdown/runtimeShutdown.core.js +85 -87
  183. package/dist/runtime/runtimeShutdown/runtimeShutdown.type.d.ts +9 -5
  184. package/dist/runtime/runtimeSignals/index.d.ts +8 -0
  185. package/dist/runtime/runtimeSignals/index.js +7 -0
  186. package/dist/runtime/runtimeSignals/runtimeSignals.d.ts +93 -0
  187. package/dist/runtime/runtimeSignals/runtimeSignals.js +149 -0
  188. package/dist/runtime/runtimeState.state.d.ts +32 -14
  189. package/dist/runtime/runtimeState.state.js +34 -27
  190. package/dist/runtime/runtimeTimeout.d.ts +40 -0
  191. package/dist/runtime/runtimeTimeout.js +42 -0
  192. package/package.json +25 -15
  193. package/dist/.tsbuildinfo +0 -1
  194. package/dist/application/application.d.ts.map +0 -1
  195. package/dist/application/application.js.map +0 -1
  196. package/dist/application/applicationContext.context.d.ts.map +0 -1
  197. package/dist/application/applicationContext.context.js.map +0 -1
  198. package/dist/application/applicationState.state.d.ts.map +0 -1
  199. package/dist/application/applicationState.state.js.map +0 -1
  200. package/dist/application/index.d.ts.map +0 -1
  201. package/dist/application/index.js.map +0 -1
  202. package/dist/configuration/configurationManager.manager.d.ts.map +0 -1
  203. package/dist/configuration/configurationManager.manager.js.map +0 -1
  204. package/dist/configuration/core/configuration.d.ts.map +0 -1
  205. package/dist/configuration/core/configuration.js.map +0 -1
  206. package/dist/configuration/core/configurationKey.key.d.ts.map +0 -1
  207. package/dist/configuration/core/configurationKey.key.js.map +0 -1
  208. package/dist/configuration/core/configurationSource.source.d.ts.map +0 -1
  209. package/dist/configuration/core/configurationSource.source.js.map +0 -1
  210. package/dist/configuration/core/index.d.ts.map +0 -1
  211. package/dist/configuration/core/index.js.map +0 -1
  212. package/dist/configuration/error/configurationError.error.d.ts.map +0 -1
  213. package/dist/configuration/error/configurationError.error.js.map +0 -1
  214. package/dist/configuration/error/configurationRedactor.redactor.d.ts.map +0 -1
  215. package/dist/configuration/error/configurationRedactor.redactor.js.map +0 -1
  216. package/dist/configuration/error/index.d.ts.map +0 -1
  217. package/dist/configuration/error/index.js.map +0 -1
  218. package/dist/configuration/events/configurationEvents.events.d.ts.map +0 -1
  219. package/dist/configuration/events/configurationEvents.events.js.map +0 -1
  220. package/dist/configuration/events/index.d.ts.map +0 -1
  221. package/dist/configuration/events/index.js.map +0 -1
  222. package/dist/configuration/index.d.ts.map +0 -1
  223. package/dist/configuration/index.js.map +0 -1
  224. package/dist/configuration/loader/configurationLoader.loader.d.ts.map +0 -1
  225. package/dist/configuration/loader/configurationLoader.loader.js.map +0 -1
  226. package/dist/configuration/loader/index.d.ts.map +0 -1
  227. package/dist/configuration/loader/index.js.map +0 -1
  228. package/dist/configuration/registry/configurationProvider.provider.d.ts.map +0 -1
  229. package/dist/configuration/registry/configurationProvider.provider.js.map +0 -1
  230. package/dist/configuration/registry/configurationRegistry.registry.d.ts.map +0 -1
  231. package/dist/configuration/registry/configurationRegistry.registry.js.map +0 -1
  232. package/dist/configuration/registry/index.d.ts.map +0 -1
  233. package/dist/configuration/registry/index.js.map +0 -1
  234. package/dist/configuration/schema/configurationSchema.schema.d.ts.map +0 -1
  235. package/dist/configuration/schema/configurationSchema.schema.js.map +0 -1
  236. package/dist/configuration/schema/configurationValidation.validator.d.ts.map +0 -1
  237. package/dist/configuration/schema/configurationValidation.validator.js.map +0 -1
  238. package/dist/configuration/schema/index.d.ts.map +0 -1
  239. package/dist/configuration/schema/index.js.map +0 -1
  240. package/dist/container/container.d.ts.map +0 -1
  241. package/dist/container/container.js.map +0 -1
  242. package/dist/container/index.d.ts.map +0 -1
  243. package/dist/container/index.js.map +0 -1
  244. package/dist/container/provider.d.ts.map +0 -1
  245. package/dist/container/provider.js.map +0 -1
  246. package/dist/container/scope.d.ts.map +0 -1
  247. package/dist/container/scope.js.map +0 -1
  248. package/dist/container/token.d.ts.map +0 -1
  249. package/dist/container/token.js.map +0 -1
  250. package/dist/context/core/context.d.ts +0 -95
  251. package/dist/context/core/context.d.ts.map +0 -1
  252. package/dist/context/core/context.js +0 -103
  253. package/dist/context/core/context.js.map +0 -1
  254. package/dist/context/core/contextKey.key.d.ts.map +0 -1
  255. package/dist/context/core/contextKey.key.js.map +0 -1
  256. package/dist/context/core/executionContext.context.d.ts.map +0 -1
  257. package/dist/context/core/executionContext.context.js.map +0 -1
  258. package/dist/context/core/index.d.ts.map +0 -1
  259. package/dist/context/core/index.js.map +0 -1
  260. package/dist/context/index.d.ts.map +0 -1
  261. package/dist/context/index.js.map +0 -1
  262. package/dist/context/provider/contextProvider.provider.d.ts.map +0 -1
  263. package/dist/context/provider/contextProvider.provider.js.map +0 -1
  264. package/dist/context/provider/contextStorage.storage.d.ts.map +0 -1
  265. package/dist/context/provider/contextStorage.storage.js.map +0 -1
  266. package/dist/context/provider/index.d.ts.map +0 -1
  267. package/dist/context/provider/index.js.map +0 -1
  268. package/dist/context/snapshot/contextSnapshot.snapshot.d.ts.map +0 -1
  269. package/dist/context/snapshot/contextSnapshot.snapshot.js.map +0 -1
  270. package/dist/context/snapshot/index.d.ts.map +0 -1
  271. package/dist/context/snapshot/index.js.map +0 -1
  272. package/dist/context/values/contextValues.values.d.ts.map +0 -1
  273. package/dist/context/values/contextValues.values.js.map +0 -1
  274. package/dist/context/values/index.d.ts.map +0 -1
  275. package/dist/context/values/index.js.map +0 -1
  276. package/dist/contracts/adapter.d.ts.map +0 -1
  277. package/dist/contracts/adapter.js.map +0 -1
  278. package/dist/contracts/disposable.d.ts.map +0 -1
  279. package/dist/contracts/disposable.js.map +0 -1
  280. package/dist/contracts/handler.d.ts.map +0 -1
  281. package/dist/contracts/handler.js.map +0 -1
  282. package/dist/contracts/index.d.ts.map +0 -1
  283. package/dist/contracts/index.js.map +0 -1
  284. package/dist/errors/errorCode.code.d.ts.map +0 -1
  285. package/dist/errors/errorCode.code.js.map +0 -1
  286. package/dist/errors/exceptions.d.ts.map +0 -1
  287. package/dist/errors/exceptions.js.map +0 -1
  288. package/dist/errors/frameworkError.error.d.ts.map +0 -1
  289. package/dist/errors/frameworkError.error.js.map +0 -1
  290. package/dist/errors/index.d.ts.map +0 -1
  291. package/dist/errors/index.js.map +0 -1
  292. package/dist/index.d.ts.map +0 -1
  293. package/dist/index.js.map +0 -1
  294. package/dist/lifecycle/core/index.d.ts.map +0 -1
  295. package/dist/lifecycle/core/index.js.map +0 -1
  296. package/dist/lifecycle/core/lifecycle.d.ts.map +0 -1
  297. package/dist/lifecycle/core/lifecycle.js.map +0 -1
  298. package/dist/lifecycle/core/lifecycleHook.hook.d.ts.map +0 -1
  299. package/dist/lifecycle/core/lifecycleHook.hook.js.map +0 -1
  300. package/dist/lifecycle/core/lifecycleRegistry.registry.d.ts.map +0 -1
  301. package/dist/lifecycle/core/lifecycleRegistry.registry.js.map +0 -1
  302. package/dist/lifecycle/core/lifecycleState.state.d.ts +0 -2
  303. package/dist/lifecycle/core/lifecycleState.state.d.ts.map +0 -1
  304. package/dist/lifecycle/core/lifecycleState.state.js +0 -2
  305. package/dist/lifecycle/core/lifecycleState.state.js.map +0 -1
  306. package/dist/lifecycle/index.d.ts.map +0 -1
  307. package/dist/lifecycle/index.js.map +0 -1
  308. package/dist/lifecycle/manager/index.d.ts.map +0 -1
  309. package/dist/lifecycle/manager/index.js.map +0 -1
  310. package/dist/lifecycle/manager/lifecycleManager.manager.d.ts.map +0 -1
  311. package/dist/lifecycle/manager/lifecycleManager.manager.js.map +0 -1
  312. package/dist/lifecycle/scope/index.d.ts.map +0 -1
  313. package/dist/lifecycle/scope/index.js.map +0 -1
  314. package/dist/lifecycle/scope/lifecycleScope.scope.d.ts.map +0 -1
  315. package/dist/lifecycle/scope/lifecycleScope.scope.js.map +0 -1
  316. package/dist/logging/console/consoleLogger.logger.d.ts.map +0 -1
  317. package/dist/logging/console/consoleLogger.logger.js.map +0 -1
  318. package/dist/logging/console/index.d.ts.map +0 -1
  319. package/dist/logging/console/index.js.map +0 -1
  320. package/dist/logging/console/loggerFactory.factory.d.ts.map +0 -1
  321. package/dist/logging/console/loggerFactory.factory.js.map +0 -1
  322. package/dist/logging/core/index.d.ts.map +0 -1
  323. package/dist/logging/core/index.js.map +0 -1
  324. package/dist/logging/core/logEntry.entry.d.ts.map +0 -1
  325. package/dist/logging/core/logEntry.entry.js.map +0 -1
  326. package/dist/logging/core/logLevel.level.d.ts.map +0 -1
  327. package/dist/logging/core/logLevel.level.js.map +0 -1
  328. package/dist/logging/core/logger.d.ts.map +0 -1
  329. package/dist/logging/core/logger.js.map +0 -1
  330. package/dist/logging/core/loggerContext.context.d.ts.map +0 -1
  331. package/dist/logging/core/loggerContext.context.js.map +0 -1
  332. package/dist/logging/core/loggerOptions.options.d.ts.map +0 -1
  333. package/dist/logging/core/loggerOptions.options.js.map +0 -1
  334. package/dist/logging/index.d.ts.map +0 -1
  335. package/dist/logging/index.js.map +0 -1
  336. package/dist/modules/index.d.ts.map +0 -1
  337. package/dist/modules/index.js.map +0 -1
  338. package/dist/modules/module.d.ts.map +0 -1
  339. package/dist/modules/module.js.map +0 -1
  340. package/dist/modules/moduleContext.context.d.ts.map +0 -1
  341. package/dist/modules/moduleContext.context.js.map +0 -1
  342. package/dist/modules/moduleDefinition.definition.d.ts.map +0 -1
  343. package/dist/modules/moduleDefinition.definition.js.map +0 -1
  344. package/dist/modules/moduleDependency/index.d.ts.map +0 -1
  345. package/dist/modules/moduleDependency/index.js.map +0 -1
  346. package/dist/modules/moduleDependency/moduleDependency.graph.d.ts.map +0 -1
  347. package/dist/modules/moduleDependency/moduleDependency.graph.js.map +0 -1
  348. package/dist/modules/moduleDependency/moduleDependency.ordering.d.ts.map +0 -1
  349. package/dist/modules/moduleDependency/moduleDependency.ordering.js.map +0 -1
  350. package/dist/modules/moduleDependency/moduleDependency.type.d.ts.map +0 -1
  351. package/dist/modules/moduleDependency/moduleDependency.type.js.map +0 -1
  352. package/dist/modules/moduleError/index.d.ts.map +0 -1
  353. package/dist/modules/moduleError/index.js.map +0 -1
  354. package/dist/modules/moduleError/moduleError.base.d.ts.map +0 -1
  355. package/dist/modules/moduleError/moduleError.base.js.map +0 -1
  356. package/dist/modules/moduleError/moduleError.dependency.d.ts.map +0 -1
  357. package/dist/modules/moduleError/moduleError.dependency.js.map +0 -1
  358. package/dist/modules/moduleError/moduleError.helpers.d.ts.map +0 -1
  359. package/dist/modules/moduleError/moduleError.helpers.js.map +0 -1
  360. package/dist/modules/moduleError/moduleError.lifecycle.d.ts.map +0 -1
  361. package/dist/modules/moduleError/moduleError.lifecycle.js.map +0 -1
  362. package/dist/modules/moduleError/moduleError.registration.d.ts.map +0 -1
  363. package/dist/modules/moduleError/moduleError.registration.js.map +0 -1
  364. package/dist/modules/moduleLifecycle/index.d.ts.map +0 -1
  365. package/dist/modules/moduleLifecycle/index.js.map +0 -1
  366. package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.d.ts.map +0 -1
  367. package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.js.map +0 -1
  368. package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.d.ts.map +0 -1
  369. package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.js.map +0 -1
  370. package/dist/modules/moduleLifecycle/moduleLifecycle.type.d.ts.map +0 -1
  371. package/dist/modules/moduleLifecycle/moduleLifecycle.type.js.map +0 -1
  372. package/dist/modules/moduleLoader/index.d.ts.map +0 -1
  373. package/dist/modules/moduleLoader/index.js.map +0 -1
  374. package/dist/modules/moduleLoader/moduleLoader.loader.d.ts.map +0 -1
  375. package/dist/modules/moduleLoader/moduleLoader.loader.js.map +0 -1
  376. package/dist/modules/moduleLoader/moduleLoader.type.d.ts.map +0 -1
  377. package/dist/modules/moduleLoader/moduleLoader.type.js.map +0 -1
  378. package/dist/modules/moduleMetadata.metadata.d.ts.map +0 -1
  379. package/dist/modules/moduleMetadata.metadata.js.map +0 -1
  380. package/dist/modules/moduleRegistry/index.d.ts.map +0 -1
  381. package/dist/modules/moduleRegistry/index.js.map +0 -1
  382. package/dist/modules/moduleRegistry/moduleRegistry.registry.d.ts.map +0 -1
  383. package/dist/modules/moduleRegistry/moduleRegistry.registry.js.map +0 -1
  384. package/dist/modules/moduleRegistry/moduleRegistry.type.d.ts.map +0 -1
  385. package/dist/modules/moduleRegistry/moduleRegistry.type.js.map +0 -1
  386. package/dist/runtime/index.d.ts.map +0 -1
  387. package/dist/runtime/index.js.map +0 -1
  388. package/dist/runtime/runtime.d.ts.map +0 -1
  389. package/dist/runtime/runtime.js.map +0 -1
  390. package/dist/runtime/runtimeBootstrap/index.d.ts.map +0 -1
  391. package/dist/runtime/runtimeBootstrap/index.js.map +0 -1
  392. package/dist/runtime/runtimeBootstrap/pipeline/index.d.ts.map +0 -1
  393. package/dist/runtime/runtimeBootstrap/pipeline/index.js.map +0 -1
  394. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.d.ts +0 -6
  395. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.d.ts.map +0 -1
  396. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.js +0 -27
  397. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.js.map +0 -1
  398. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.d.ts.map +0 -1
  399. package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.js.map +0 -1
  400. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.d.ts.map +0 -1
  401. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.js.map +0 -1
  402. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.d.ts.map +0 -1
  403. package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.js.map +0 -1
  404. package/dist/runtime/runtimeContext/index.d.ts.map +0 -1
  405. package/dist/runtime/runtimeContext/index.js.map +0 -1
  406. package/dist/runtime/runtimeContext/runtimeContext.core.d.ts +0 -38
  407. package/dist/runtime/runtimeContext/runtimeContext.core.d.ts.map +0 -1
  408. package/dist/runtime/runtimeContext/runtimeContext.core.js +0 -99
  409. package/dist/runtime/runtimeContext/runtimeContext.core.js.map +0 -1
  410. package/dist/runtime/runtimeContext/runtimeContext.factory.d.ts.map +0 -1
  411. package/dist/runtime/runtimeContext/runtimeContext.factory.js.map +0 -1
  412. package/dist/runtime/runtimeContext/runtimeContext.type.d.ts.map +0 -1
  413. package/dist/runtime/runtimeContext/runtimeContext.type.js.map +0 -1
  414. package/dist/runtime/runtimeEnvironment/detection/index.d.ts.map +0 -1
  415. package/dist/runtime/runtimeEnvironment/detection/index.js.map +0 -1
  416. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.detection.d.ts.map +0 -1
  417. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.detection.js.map +0 -1
  418. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.d.ts.map +0 -1
  419. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.js.map +0 -1
  420. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.d.ts.map +0 -1
  421. package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.js.map +0 -1
  422. package/dist/runtime/runtimeEnvironment/index.d.ts.map +0 -1
  423. package/dist/runtime/runtimeEnvironment/index.js.map +0 -1
  424. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.d.ts.map +0 -1
  425. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.js.map +0 -1
  426. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.d.ts.map +0 -1
  427. package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.js.map +0 -1
  428. package/dist/runtime/runtimeError/index.d.ts.map +0 -1
  429. package/dist/runtime/runtimeError/index.js.map +0 -1
  430. package/dist/runtime/runtimeError/runtimeError.base.d.ts.map +0 -1
  431. package/dist/runtime/runtimeError/runtimeError.base.js.map +0 -1
  432. package/dist/runtime/runtimeError/runtimeError.lifecycle.d.ts.map +0 -1
  433. package/dist/runtime/runtimeError/runtimeError.lifecycle.js.map +0 -1
  434. package/dist/runtime/runtimeError/runtimeError.specialized.d.ts.map +0 -1
  435. package/dist/runtime/runtimeError/runtimeError.specialized.js.map +0 -1
  436. package/dist/runtime/runtimeError/runtimeError.type.d.ts.map +0 -1
  437. package/dist/runtime/runtimeError/runtimeError.type.js.map +0 -1
  438. package/dist/runtime/runtimeLogger.d.ts.map +0 -1
  439. package/dist/runtime/runtimeLogger.js.map +0 -1
  440. package/dist/runtime/runtimeManager/index.d.ts +0 -12
  441. package/dist/runtime/runtimeManager/index.d.ts.map +0 -1
  442. package/dist/runtime/runtimeManager/index.js +0 -11
  443. package/dist/runtime/runtimeManager/index.js.map +0 -1
  444. package/dist/runtime/runtimeManager/runtimeManager.core.d.ts +0 -31
  445. package/dist/runtime/runtimeManager/runtimeManager.core.d.ts.map +0 -1
  446. package/dist/runtime/runtimeManager/runtimeManager.core.js +0 -136
  447. package/dist/runtime/runtimeManager/runtimeManager.core.js.map +0 -1
  448. package/dist/runtime/runtimeManager/runtimeManager.error.d.ts +0 -14
  449. package/dist/runtime/runtimeManager/runtimeManager.error.d.ts.map +0 -1
  450. package/dist/runtime/runtimeManager/runtimeManager.error.js +0 -21
  451. package/dist/runtime/runtimeManager/runtimeManager.error.js.map +0 -1
  452. package/dist/runtime/runtimeManager/runtimeManager.factory.d.ts +0 -7
  453. package/dist/runtime/runtimeManager/runtimeManager.factory.d.ts.map +0 -1
  454. package/dist/runtime/runtimeManager/runtimeManager.factory.js +0 -8
  455. package/dist/runtime/runtimeManager/runtimeManager.factory.js.map +0 -1
  456. package/dist/runtime/runtimeManager/runtimeManager.lifecycle.d.ts +0 -16
  457. package/dist/runtime/runtimeManager/runtimeManager.lifecycle.d.ts.map +0 -1
  458. package/dist/runtime/runtimeManager/runtimeManager.lifecycle.js +0 -49
  459. package/dist/runtime/runtimeManager/runtimeManager.lifecycle.js.map +0 -1
  460. package/dist/runtime/runtimeManager/runtimeManager.type.d.ts +0 -54
  461. package/dist/runtime/runtimeManager/runtimeManager.type.d.ts.map +0 -1
  462. package/dist/runtime/runtimeManager/runtimeManager.type.js +0 -2
  463. package/dist/runtime/runtimeManager/runtimeManager.type.js.map +0 -1
  464. package/dist/runtime/runtimeOptions/index.d.ts.map +0 -1
  465. package/dist/runtime/runtimeOptions/index.js.map +0 -1
  466. package/dist/runtime/runtimeOptions/runtimeOptions.defaults.d.ts.map +0 -1
  467. package/dist/runtime/runtimeOptions/runtimeOptions.defaults.js.map +0 -1
  468. package/dist/runtime/runtimeOptions/runtimeOptions.resolver.d.ts.map +0 -1
  469. package/dist/runtime/runtimeOptions/runtimeOptions.resolver.js.map +0 -1
  470. package/dist/runtime/runtimeOptions/runtimeOptions.type.d.ts.map +0 -1
  471. package/dist/runtime/runtimeOptions/runtimeOptions.type.js.map +0 -1
  472. package/dist/runtime/runtimeOptions/runtimeOptions.validation.d.ts.map +0 -1
  473. package/dist/runtime/runtimeOptions/runtimeOptions.validation.js.map +0 -1
  474. package/dist/runtime/runtimeShutdown/index.d.ts.map +0 -1
  475. package/dist/runtime/runtimeShutdown/index.js.map +0 -1
  476. package/dist/runtime/runtimeShutdown/pipeline/index.d.ts.map +0 -1
  477. package/dist/runtime/runtimeShutdown/pipeline/index.js.map +0 -1
  478. package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.d.ts.map +0 -1
  479. package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.js.map +0 -1
  480. package/dist/runtime/runtimeShutdown/runtimeShutdown.core.d.ts.map +0 -1
  481. package/dist/runtime/runtimeShutdown/runtimeShutdown.core.js.map +0 -1
  482. package/dist/runtime/runtimeShutdown/runtimeShutdown.type.d.ts.map +0 -1
  483. package/dist/runtime/runtimeShutdown/runtimeShutdown.type.js.map +0 -1
  484. package/dist/runtime/runtimeState.state.d.ts.map +0 -1
  485. package/dist/runtime/runtimeState.state.js.map +0 -1
@@ -1,20 +1,29 @@
1
1
  import { hasDestroyHook, hasInitializeHook, hasStartHook, hasStopHook, } from "../core/lifecycleHook.hook.js";
2
- import { Lifecycle, LifecycleState, } from "../core/lifecycle.js";
2
+ import { Lifecycle, } from "../core/lifecycle.js";
3
3
  /**
4
4
  * Coordinates lifecycle hooks and lifecycle participants.
5
5
  * Primary API for application-level lifecycle management.
6
+ *
7
+ * Every component, whether it uses the hook interfaces (onInitialize,
8
+ * onStart, onStop, onDestroy) or the participant API (initialize,
9
+ * start, stop, dispose), is normalized into a single participant and
10
+ * driven by one Lifecycle state machine. This guarantees:
11
+ *
12
+ * - global registration order across both component kinds
13
+ * (initialize/start forward, stop/destroy reverse),
14
+ * - a component exposing both shapes runs exactly once per phase
15
+ * (the `onX` hook takes precedence),
16
+ * - state guards, retries, and concurrency rules of Lifecycle.
6
17
  */
7
18
  export class LifecycleManager {
8
19
  lifecycle;
9
20
  components = [];
10
21
  logger;
11
- continueOnShutdownError;
12
22
  constructor(options = {}) {
13
23
  this.logger = options.logger;
14
- this.continueOnShutdownError = options.continueOnShutdownError ?? true;
15
24
  this.lifecycle = new Lifecycle({
16
25
  logger: this.logger,
17
- continueOnShutdownError: this.continueOnShutdownError,
26
+ continueOnShutdownError: options.continueOnShutdownError ?? true,
18
27
  });
19
28
  }
20
29
  getState() {
@@ -23,119 +32,71 @@ export class LifecycleManager {
23
32
  getComponents() {
24
33
  return [...this.components];
25
34
  }
35
+ /**
36
+ * Registers a component. Only allowed before initialization begins.
37
+ */
26
38
  register(component) {
39
+ this.lifecycle.register(this.toParticipant(component));
27
40
  this.components.push(component);
28
- if (this.isLifecycleParticipant(component))
29
- this.lifecycle.register(component);
30
41
  }
31
42
  async initialize() {
32
- if (this.getState() !== LifecycleState.CREATED)
33
- return;
34
43
  this.logger?.debug("Lifecycle manager initialization started");
35
- try {
36
- for (const component of this.components) {
37
- if (hasInitializeHook(component))
38
- await this.runHook(component, "onInitialize", "initialize");
39
- }
40
- await this.lifecycle.initialize();
41
- this.logger?.debug("Lifecycle manager initialization completed");
42
- }
43
- catch (error) {
44
- this.logger?.error("Lifecycle manager initialization failed", error);
45
- throw error;
46
- }
44
+ await this.lifecycle.initialize();
45
+ this.logger?.debug("Lifecycle manager initialization completed");
47
46
  }
48
47
  async start() {
49
- if (this.getState() === LifecycleState.CREATED)
50
- await this.initialize();
51
48
  this.logger?.debug("Lifecycle manager startup started");
52
- try {
53
- for (const component of this.components) {
54
- if (hasStartHook(component))
55
- await this.runHook(component, "onStart", "start");
56
- }
57
- await this.lifecycle.start();
58
- this.logger?.debug("Lifecycle manager startup completed");
59
- }
60
- catch (error) {
61
- this.logger?.error("Lifecycle manager startup failed", error);
62
- throw error;
63
- }
49
+ await this.lifecycle.start();
50
+ this.logger?.debug("Lifecycle manager startup completed");
64
51
  }
65
52
  async stop() {
66
- const errors = [];
67
53
  this.logger?.debug("Lifecycle manager shutdown started");
68
- for (let i = this.components.length - 1; i >= 0; i--) {
69
- const component = this.components[i];
70
- if (!hasStopHook(component))
71
- continue;
72
- try {
73
- await this.runHook(component, "onStop", "stop");
74
- }
75
- catch (error) {
76
- errors.push(error);
77
- if (!this.continueOnShutdownError)
78
- break;
79
- }
80
- }
81
- try {
82
- await this.lifecycle.stop();
83
- }
84
- catch (error) {
85
- errors.push(error);
86
- }
87
- if (errors.length > 0)
88
- throw new AggregateError(errors, "Lifecycle shutdown completed with errors.");
54
+ await this.lifecycle.stop();
89
55
  this.logger?.debug("Lifecycle manager shutdown completed");
90
56
  }
91
57
  async destroy() {
92
- const errors = [];
93
58
  this.logger?.debug("Lifecycle manager destruction started");
94
- for (let i = this.components.length - 1; i >= 0; i--) {
95
- const component = this.components[i];
96
- if (!hasDestroyHook(component))
97
- continue;
98
- try {
99
- await this.runHook(component, "onDestroy", "destroy");
100
- }
101
- catch (error) {
102
- errors.push(error);
103
- if (!this.continueOnShutdownError)
104
- break;
105
- }
106
- }
107
- try {
108
- await this.lifecycle.dispose();
109
- }
110
- catch (error) {
111
- errors.push(error);
112
- }
113
- if (errors.length > 0)
114
- throw new AggregateError(errors, "Lifecycle destruction completed with errors.");
59
+ await this.lifecycle.dispose();
115
60
  this.logger?.debug("Lifecycle manager destruction completed");
116
61
  }
117
62
  async shutdown() {
118
- const errors = [];
119
- try {
120
- await this.stop();
121
- }
122
- catch (error) {
123
- errors.push(error);
124
- }
125
- try {
126
- await this.destroy();
127
- }
128
- catch (error) {
129
- errors.push(error);
130
- }
131
- if (errors.length > 0)
132
- throw new AggregateError(errors, "Application shutdown completed with errors.");
63
+ await this.lifecycle.shutdown();
133
64
  }
134
- async runHook(component, hook, label) {
135
- this.logger?.debug(`Running lifecycle ${label} hook`, {
136
- component: this.getComponentName(component),
137
- });
138
- await component[hook]?.();
65
+ /**
66
+ * Normalizes a component into a LifecycleParticipant. Hook methods
67
+ * (onInitialize, ...) win over participant methods (initialize, ...)
68
+ * when a component exposes both, so each phase runs once.
69
+ */
70
+ toParticipant(component) {
71
+ const name = this.getComponentName(component);
72
+ const participant = this.isLifecycleParticipant(component)
73
+ ? component
74
+ : undefined;
75
+ const initialize = hasInitializeHook(component)
76
+ ? () => this.runHook(name, "initialize", () => component.onInitialize())
77
+ : participant?.initialize
78
+ ? () => this.runHook(name, "initialize", () => participant.initialize())
79
+ : undefined;
80
+ const start = hasStartHook(component)
81
+ ? () => this.runHook(name, "start", () => component.onStart())
82
+ : participant?.start
83
+ ? () => this.runHook(name, "start", () => participant.start())
84
+ : undefined;
85
+ const stop = hasStopHook(component)
86
+ ? () => this.runHook(name, "stop", () => component.onStop())
87
+ : participant?.stop
88
+ ? () => this.runHook(name, "stop", () => participant.stop())
89
+ : undefined;
90
+ const dispose = hasDestroyHook(component)
91
+ ? () => this.runHook(name, "destroy", () => component.onDestroy())
92
+ : participant?.dispose
93
+ ? () => this.runHook(name, "destroy", () => participant.dispose())
94
+ : undefined;
95
+ return { name, initialize, start, stop, dispose };
96
+ }
97
+ async runHook(component, label, hook) {
98
+ this.logger?.debug(`Running lifecycle ${label} hook`, { component });
99
+ await hook();
139
100
  }
140
101
  isLifecycleParticipant(component) {
141
102
  return (typeof component === "object" &&
@@ -149,7 +110,9 @@ export class LifecycleManager {
149
110
  if (typeof component === "object" &&
150
111
  component !== null &&
151
112
  "constructor" in component &&
152
- typeof component.constructor === "function")
113
+ typeof component.constructor === "function" &&
114
+ component.constructor.name &&
115
+ component.constructor !== Object)
153
116
  return component.constructor.name;
154
117
  return "anonymous";
155
118
  }
@@ -9,6 +9,7 @@ export declare const LifecycleScopeState: {
9
9
  readonly RUNNING: "running";
10
10
  readonly STOPPING: "stopping";
11
11
  readonly STOPPED: "stopped";
12
+ readonly DESTROYED: "destroyed";
12
13
  readonly FAILED: "failed";
13
14
  };
14
15
  export type LifecycleScopeState = (typeof LifecycleScopeState)[keyof typeof LifecycleScopeState];
@@ -22,11 +23,15 @@ export interface LifecycleScopeOptions {
22
23
  /**
23
24
  * Represents an independently managed lifecycle boundary.
24
25
  * Can represent an Application, Module, Plugin, Worker, Service, or Feature.
26
+ *
27
+ * Children are initialized/started after the parent's own components
28
+ * and stopped/destroyed before them. A destroyed child detaches from
29
+ * its parent so it is never re-destroyed.
25
30
  */
26
31
  export declare class LifecycleScope {
27
32
  private state;
28
33
  private readonly name;
29
- private readonly parent?;
34
+ private parent?;
30
35
  private readonly logger?;
31
36
  private readonly continueOnShutdownError;
32
37
  private readonly registry;
@@ -41,9 +46,25 @@ export declare class LifecycleScope {
41
46
  unregister(id: string): boolean;
42
47
  initialize(): Promise<void>;
43
48
  start(): Promise<void>;
49
+ /**
50
+ * Stops children (reverse order) and then this scope's components
51
+ * (reverse registration order).
52
+ *
53
+ * A scope that never started transitions straight to STOPPED without
54
+ * running any stop hook. When `continueOnShutdownError` is false the
55
+ * first failure aborts the phase and leaves the scope FAILED.
56
+ */
44
57
  stop(): Promise<void>;
58
+ /**
59
+ * Destroys children (reverse order) and then this scope's
60
+ * components. Idempotent: a destroyed scope is detached from its
61
+ * parent and never destroyed again.
62
+ */
45
63
  destroy(): Promise<void>;
46
64
  shutdown(): Promise<void>;
47
65
  private addChild;
66
+ private removeChild;
67
+ private detach;
68
+ private invalidState;
48
69
  }
49
70
  //# sourceMappingURL=lifecycleScope.scope.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { LifecycleRegistry } from "../core/lifecycleRegistry.registry.js";
2
+ import { InvalidStateError } from "../../errors/exceptions.js";
2
3
  /** Lifecycle scope state. */
3
4
  export const LifecycleScopeState = {
4
5
  CREATED: "created",
@@ -8,11 +9,16 @@ export const LifecycleScopeState = {
8
9
  RUNNING: "running",
9
10
  STOPPING: "stopping",
10
11
  STOPPED: "stopped",
12
+ DESTROYED: "destroyed",
11
13
  FAILED: "failed",
12
14
  };
13
15
  /**
14
16
  * Represents an independently managed lifecycle boundary.
15
17
  * Can represent an Application, Module, Plugin, Worker, Service, or Feature.
18
+ *
19
+ * Children are initialized/started after the parent's own components
20
+ * and stopped/destroyed before them. A destroyed child detaches from
21
+ * its parent so it is never re-destroyed.
16
22
  */
17
23
  export class LifecycleScope {
18
24
  state = LifecycleScopeState.CREATED;
@@ -48,7 +54,7 @@ export class LifecycleScope {
48
54
  register(component, name) {
49
55
  if (this.state !== LifecycleScopeState.CREATED &&
50
56
  this.state !== LifecycleScopeState.INITIALIZED) {
51
- throw new Error(`Cannot register component in lifecycle scope "${this.name}" while state is "${this.state}".`);
57
+ throw new InvalidStateError(`Cannot register component in lifecycle scope "${this.name}" while state is "${this.state}".`, { scope: this.name, state: this.state });
52
58
  }
53
59
  return this.registry.register(component, name);
54
60
  }
@@ -60,7 +66,7 @@ export class LifecycleScope {
60
66
  this.state === LifecycleScopeState.RUNNING)
61
67
  return;
62
68
  if (this.state !== LifecycleScopeState.CREATED)
63
- throw new Error(`Cannot initialize lifecycle scope "${this.name}" while state is "${this.state}".`);
69
+ throw this.invalidState("initialize");
64
70
  this.state = LifecycleScopeState.INITIALIZING;
65
71
  this.logger?.debug("Initializing lifecycle scope", { scope: this.name });
66
72
  try {
@@ -75,7 +81,7 @@ export class LifecycleScope {
75
81
  await component.initialize();
76
82
  }
77
83
  }
78
- for (const child of this.children)
84
+ for (const child of [...this.children])
79
85
  await child.initialize();
80
86
  this.state = LifecycleScopeState.INITIALIZED;
81
87
  this.logger?.debug("Lifecycle scope initialized", { scope: this.name });
@@ -94,7 +100,7 @@ export class LifecycleScope {
94
100
  if (this.state === LifecycleScopeState.CREATED)
95
101
  await this.initialize();
96
102
  if (this.state !== LifecycleScopeState.INITIALIZED)
97
- throw new Error(`Cannot start lifecycle scope "${this.name}" while state is "${this.state}".`);
103
+ throw this.invalidState("start");
98
104
  this.state = LifecycleScopeState.STARTING;
99
105
  this.logger?.debug("Starting lifecycle scope", { scope: this.name });
100
106
  try {
@@ -108,7 +114,7 @@ export class LifecycleScope {
108
114
  await component.start();
109
115
  }
110
116
  }
111
- for (const child of this.children)
117
+ for (const child of [...this.children])
112
118
  await child.start();
113
119
  this.state = LifecycleScopeState.RUNNING;
114
120
  this.logger?.debug("Lifecycle scope started", { scope: this.name });
@@ -121,15 +127,36 @@ export class LifecycleScope {
121
127
  throw error;
122
128
  }
123
129
  }
130
+ /**
131
+ * Stops children (reverse order) and then this scope's components
132
+ * (reverse registration order).
133
+ *
134
+ * A scope that never started transitions straight to STOPPED without
135
+ * running any stop hook. When `continueOnShutdownError` is false the
136
+ * first failure aborts the phase and leaves the scope FAILED.
137
+ */
124
138
  async stop() {
125
- if (this.state === LifecycleScopeState.STOPPED)
126
- return;
127
- if (this.state !== LifecycleScopeState.RUNNING &&
128
- this.state !== LifecycleScopeState.FAILED) {
129
- throw new Error(`Cannot stop lifecycle scope "${this.name}" while state is "${this.state}".`);
139
+ switch (this.state) {
140
+ case LifecycleScopeState.STOPPED:
141
+ case LifecycleScopeState.DESTROYED:
142
+ return;
143
+ case LifecycleScopeState.CREATED:
144
+ case LifecycleScopeState.INITIALIZED:
145
+ // Nothing started here; cascade the state to children only.
146
+ for (let i = this.children.length - 1; i >= 0; i--) {
147
+ await this.children[i].stop();
148
+ }
149
+ this.state = LifecycleScopeState.STOPPED;
150
+ return;
151
+ case LifecycleScopeState.RUNNING:
152
+ case LifecycleScopeState.FAILED:
153
+ break;
154
+ default:
155
+ throw this.invalidState("stop");
130
156
  }
131
157
  this.state = LifecycleScopeState.STOPPING;
132
158
  const errors = [];
159
+ let aborted = false;
133
160
  this.logger?.debug("Stopping lifecycle scope", { scope: this.name });
134
161
  for (let i = this.children.length - 1; i >= 0; i--) {
135
162
  try {
@@ -137,11 +164,13 @@ export class LifecycleScope {
137
164
  }
138
165
  catch (error) {
139
166
  errors.push(error);
140
- if (!this.continueOnShutdownError)
167
+ if (!this.continueOnShutdownError) {
168
+ aborted = true;
141
169
  break;
170
+ }
142
171
  }
143
172
  }
144
- if (errors.length === 0 || this.continueOnShutdownError) {
173
+ if (!aborted) {
145
174
  for (const registration of this.registry.getReverse()) {
146
175
  const component = registration.component;
147
176
  try {
@@ -159,17 +188,33 @@ export class LifecycleScope {
159
188
  scope: this.name,
160
189
  component: registration.name,
161
190
  });
162
- if (!this.continueOnShutdownError)
191
+ if (!this.continueOnShutdownError) {
192
+ aborted = true;
163
193
  break;
194
+ }
164
195
  }
165
196
  }
166
197
  }
167
- this.state = LifecycleScopeState.STOPPED;
198
+ this.state = aborted
199
+ ? LifecycleScopeState.FAILED
200
+ : LifecycleScopeState.STOPPED;
168
201
  if (errors.length > 0)
169
202
  throw new AggregateError(errors, `Lifecycle scope "${this.name}" stopped with errors.`);
170
203
  }
204
+ /**
205
+ * Destroys children (reverse order) and then this scope's
206
+ * components. Idempotent: a destroyed scope is detached from its
207
+ * parent and never destroyed again.
208
+ */
171
209
  async destroy() {
210
+ if (this.state === LifecycleScopeState.DESTROYED)
211
+ return;
212
+ if (this.state === LifecycleScopeState.INITIALIZING ||
213
+ this.state === LifecycleScopeState.STARTING ||
214
+ this.state === LifecycleScopeState.STOPPING)
215
+ throw this.invalidState("destroy");
172
216
  const errors = [];
217
+ let aborted = false;
173
218
  this.logger?.debug("Destroying lifecycle scope", { scope: this.name });
174
219
  for (let i = this.children.length - 1; i >= 0; i--) {
175
220
  try {
@@ -177,11 +222,13 @@ export class LifecycleScope {
177
222
  }
178
223
  catch (error) {
179
224
  errors.push(error);
180
- if (!this.continueOnShutdownError)
225
+ if (!this.continueOnShutdownError) {
226
+ aborted = true;
181
227
  break;
228
+ }
182
229
  }
183
230
  }
184
- if (errors.length === 0 || this.continueOnShutdownError) {
231
+ if (!aborted) {
185
232
  for (const registration of this.registry.getReverse()) {
186
233
  const component = registration.component;
187
234
  try {
@@ -200,11 +247,20 @@ export class LifecycleScope {
200
247
  scope: this.name,
201
248
  component: registration.name,
202
249
  });
203
- if (!this.continueOnShutdownError)
250
+ if (!this.continueOnShutdownError) {
251
+ aborted = true;
204
252
  break;
253
+ }
205
254
  }
206
255
  }
207
256
  }
257
+ if (aborted) {
258
+ this.state = LifecycleScopeState.FAILED;
259
+ }
260
+ else {
261
+ this.state = LifecycleScopeState.DESTROYED;
262
+ this.detach();
263
+ }
208
264
  if (errors.length > 0)
209
265
  throw new AggregateError(errors, `Lifecycle scope "${this.name}" destroyed with errors.`);
210
266
  }
@@ -230,5 +286,17 @@ export class LifecycleScope {
230
286
  return;
231
287
  this.children.push(child);
232
288
  }
289
+ removeChild(child) {
290
+ const index = this.children.indexOf(child);
291
+ if (index !== -1)
292
+ this.children.splice(index, 1);
293
+ }
294
+ detach() {
295
+ this.parent?.removeChild(this);
296
+ this.parent = undefined;
297
+ }
298
+ invalidState(operation) {
299
+ return new InvalidStateError(`Cannot ${operation} lifecycle scope "${this.name}" while state is "${this.state}".`, { scope: this.name, operation, state: this.state });
300
+ }
233
301
  }
234
302
  //# sourceMappingURL=lifecycleScope.scope.js.map
@@ -20,15 +20,34 @@ export declare class ConsoleLogger extends BaseLogger {
20
20
  constructor(options?: LoggerOptions, context?: LoggerContext);
21
21
  /**
22
22
  * Writes a log entry to the console.
23
+ *
24
+ * The context received here has already been merged with the
25
+ * logger's persistent context by BaseLogger. Fields of the
26
+ * current execution context (when a ContextStorage is configured
27
+ * and a context is active) are merged beneath it.
23
28
  */
24
29
  protected write(level: LogLevelType, message: string, context?: LogContext, error?: unknown): void;
25
30
  /**
26
31
  * Creates a child logger that inherits the current
27
- * logger configuration and adds persistent context.
32
+ * logger configuration.
33
+ *
34
+ * The context received here is the fully merged context
35
+ * (parent persistent context plus child additions) produced
36
+ * by BaseLogger.child().
28
37
  */
29
38
  protected createChild(context: LogContext): ConsoleLogger;
39
+ /**
40
+ * Merges the ambient execution context (if any) beneath the
41
+ * supplied context. Never throws: a failing storage lookup leaves
42
+ * the context untouched.
43
+ */
44
+ private withExecutionContext;
30
45
  /**
31
46
  * Writes the log entry as JSON.
47
+ *
48
+ * Serialization is crash-safe: circular references, BigInt
49
+ * values, and throwing toJSON implementations degrade to
50
+ * placeholder strings instead of throwing.
32
51
  */
33
52
  private writeStructured;
34
53
  /**
@@ -1,5 +1,7 @@
1
- import { LogLevel, LogLevelPriority, shouldLog, } from "../core/logLevel.level.js";
2
- import { serializeLogError } from "../core/logEntry.entry.js";
1
+ import { LogLevel, LogLevelPriority, isLogLevel, shouldLog, } from "../core/logLevel.level.js";
2
+ import { InvalidArgumentError } from "../../errors/exceptions.js";
3
+ import { safeLogStringify, sanitizeLogValue, serializeLogError, } from "../core/logEntry.entry.js";
4
+ import { loggerContextFromExecution } from "../core/loggerContext.context.js";
3
5
  import { DEFAULT_LOGGER_OPTIONS, } from "../core/loggerOptions.options.js";
4
6
  import { BaseLogger } from "../core/logger.js";
5
7
  /**
@@ -22,26 +24,45 @@ export class ConsoleLogger extends BaseLogger {
22
24
  ...options.context,
23
25
  ...context,
24
26
  });
27
+ const level = options.level ?? DEFAULT_LOGGER_OPTIONS.level;
28
+ /*
29
+ * An unknown level would make every severity comparison false
30
+ * and silently disable all logging, so it is rejected at
31
+ * construction instead. Levels are case-sensitive.
32
+ */
33
+ if (!isLogLevel(level)) {
34
+ throw new InvalidArgumentError(`Unknown log level "${String(level)}". Expected one of: ${Object.keys(LogLevelPriority).join(", ")}.`, { level });
35
+ }
25
36
  this.options = {
26
37
  ...DEFAULT_LOGGER_OPTIONS,
27
38
  ...options,
39
+ level,
28
40
  };
29
41
  }
30
42
  /**
31
43
  * Writes a log entry to the console.
44
+ *
45
+ * The context received here has already been merged with the
46
+ * logger's persistent context by BaseLogger. Fields of the
47
+ * current execution context (when a ContextStorage is configured
48
+ * and a context is active) are merged beneath it.
32
49
  */
33
50
  write(level, message, context, error) {
34
51
  if (!shouldLog(level, this.options.level)) {
35
52
  return;
36
53
  }
54
+ const redact = this.options.redact;
55
+ context = this.withExecutionContext(context);
37
56
  const entry = {
38
57
  level,
39
58
  message,
40
59
  timestamp: new Date(),
41
- context,
60
+ context: context !== undefined && redact !== undefined
61
+ ? redact(sanitizeLogValue(context))
62
+ : context,
42
63
  ...(error !== undefined
43
64
  ? {
44
- error: serializeLogError(error),
65
+ error: serializeLogError(error, { redact }),
45
66
  }
46
67
  : {}),
47
68
  };
@@ -53,21 +74,61 @@ export class ConsoleLogger extends BaseLogger {
53
74
  }
54
75
  /**
55
76
  * Creates a child logger that inherits the current
56
- * logger configuration and adds persistent context.
77
+ * logger configuration.
78
+ *
79
+ * The context received here is the fully merged context
80
+ * (parent persistent context plus child additions) produced
81
+ * by BaseLogger.child().
57
82
  */
58
83
  createChild(context) {
59
- return new ConsoleLogger(this.options, {
60
- ...this.options.context,
84
+ return new ConsoleLogger({
85
+ ...this.options,
86
+ context: undefined,
87
+ }, context);
88
+ }
89
+ /**
90
+ * Merges the ambient execution context (if any) beneath the
91
+ * supplied context. Never throws: a failing storage lookup leaves
92
+ * the context untouched.
93
+ */
94
+ withExecutionContext(context) {
95
+ const storage = this.options.contextStorage;
96
+ if (!storage)
97
+ return context;
98
+ let execution;
99
+ try {
100
+ execution = storage.get();
101
+ }
102
+ catch {
103
+ return context;
104
+ }
105
+ if (!execution)
106
+ return context;
107
+ return {
108
+ ...loggerContextFromExecution(execution),
61
109
  ...context,
62
- });
110
+ };
63
111
  }
64
112
  /**
65
113
  * Writes the log entry as JSON.
114
+ *
115
+ * Serialization is crash-safe: circular references, BigInt
116
+ * values, and throwing toJSON implementations degrade to
117
+ * placeholder strings instead of throwing.
66
118
  */
67
119
  writeStructured(entry) {
68
120
  const output = {
69
121
  level: entry.level,
70
122
  message: entry.message,
123
+ ...(this.options.service !== undefined
124
+ ? { service: this.options.service }
125
+ : {}),
126
+ ...(this.options.version !== undefined
127
+ ? { version: this.options.version }
128
+ : {}),
129
+ ...(this.options.environment !== undefined
130
+ ? { environment: this.options.environment }
131
+ : {}),
71
132
  ...(this.options.timestamps
72
133
  ? {
73
134
  timestamp: entry.timestamp.toISOString(),
@@ -86,7 +147,7 @@ export class ConsoleLogger extends BaseLogger {
86
147
  }
87
148
  : {}),
88
149
  };
89
- this.writeToConsole(entry.level, JSON.stringify(output));
150
+ this.writeToConsole(entry.level, safeLogStringify(output));
90
151
  }
91
152
  /**
92
153
  * Writes a human-readable log entry.
@@ -108,7 +169,12 @@ export class ConsoleLogger extends BaseLogger {
108
169
  writeToConsole(level, message) {
109
170
  switch (level) {
110
171
  case LogLevel.TRACE:
111
- console.trace(message);
172
+ /*
173
+ * console.trace prints a stack trace for every call,
174
+ * which makes trace-level logs unreadable. Trace output
175
+ * goes through console.debug (console.log fallback).
176
+ */
177
+ (console.debug ?? console.log)(message);
112
178
  break;
113
179
  case LogLevel.DEBUG:
114
180
  console.debug(message);
@@ -170,7 +236,7 @@ export class ConsoleLogger extends BaseLogger {
170
236
  return value;
171
237
  }
172
238
  try {
173
- return JSON.stringify(value);
239
+ return JSON.stringify(sanitizeLogValue(value));
174
240
  }
175
241
  catch {
176
242
  return "[unserializable]";