@zudojs/core 0.0.1 → 1.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.
- package/LICENSE +21 -0
- package/README.md +141 -7
- package/dist/application/application.d.ts +43 -2
- package/dist/application/application.js +111 -13
- package/dist/application/applicationContext.context.d.ts +15 -0
- package/dist/application/applicationContext.context.js +12 -0
- package/dist/application/createApplication.d.ts +78 -0
- package/dist/application/createApplication.js +104 -0
- package/dist/application/index.d.ts +2 -1
- package/dist/application/index.js +2 -1
- package/dist/configuration/configurationManager.manager.d.ts +32 -0
- package/dist/configuration/configurationManager.manager.js +86 -7
- package/dist/configuration/core/configuration.d.ts +60 -15
- package/dist/configuration/core/configuration.js +248 -51
- package/dist/configuration/core/configurationKey.key.d.ts +4 -2
- package/dist/configuration/core/configurationKey.key.js +2 -13
- package/dist/configuration/core/configurationPath.path.d.ts +17 -0
- package/dist/configuration/core/configurationPath.path.js +33 -0
- package/dist/configuration/core/index.d.ts +7 -1
- package/dist/configuration/core/index.js +1 -0
- package/dist/configuration/error/configurationError.error.d.ts +11 -0
- package/dist/configuration/error/configurationError.error.js +29 -1
- package/dist/configuration/error/configurationRedactor.redactor.d.ts +16 -0
- package/dist/configuration/error/configurationRedactor.redactor.js +83 -5
- package/dist/configuration/error/index.d.ts +2 -1
- package/dist/configuration/error/index.js +2 -1
- package/dist/configuration/index.d.ts +1 -1
- package/dist/configuration/loader/configurationLoader.loader.d.ts +47 -9
- package/dist/configuration/loader/configurationLoader.loader.js +107 -26
- package/dist/configuration/loader/index.d.ts +1 -1
- package/dist/configuration/loader/index.js +1 -1
- package/dist/configuration/registry/configurationProvider.provider.d.ts +26 -1
- package/dist/configuration/registry/configurationProvider.provider.js +33 -7
- package/dist/configuration/registry/configurationRegistry.registry.js +2 -1
- package/dist/configuration/schema/configurationSchema.schema.d.ts +0 -4
- package/dist/configuration/schema/configurationSchema.schema.js +11 -32
- package/dist/configuration/schema/configurationValidation.validator.d.ts +14 -2
- package/dist/configuration/schema/configurationValidation.validator.js +55 -7
- package/dist/configuration/schema/index.d.ts +1 -1
- package/dist/configuration/schema/index.js +1 -1
- package/dist/container/container.d.ts +52 -5
- package/dist/container/container.js +110 -33
- package/dist/container/index.d.ts +1 -1
- package/dist/container/index.js +1 -1
- package/dist/container/scope.d.ts +7 -6
- package/dist/context/core/contextAliases.deprecated.d.ts +32 -0
- package/dist/context/core/contextAliases.deprecated.js +6 -0
- package/dist/context/core/executionContext.context.d.ts +8 -0
- package/dist/context/core/executionContext.context.js +38 -15
- package/dist/context/core/index.d.ts +2 -2
- package/dist/context/core/index.js +2 -2
- package/dist/context/index.d.ts +20 -0
- package/dist/context/index.js +20 -0
- package/dist/context/provider/contextProvider.provider.d.ts +7 -4
- package/dist/context/provider/contextProvider.provider.js +9 -6
- package/dist/context/provider/contextStorage.storage.d.ts +47 -7
- package/dist/context/provider/contextStorage.storage.js +54 -12
- package/dist/context/provider/defaultContextStorage.storage.d.ts +18 -0
- package/dist/context/provider/defaultContextStorage.storage.js +20 -0
- package/dist/context/provider/index.d.ts +2 -1
- package/dist/context/provider/index.js +1 -0
- package/dist/errors/exceptions.d.ts +22 -0
- package/dist/errors/exceptions.js +38 -1
- package/dist/errors/frameworkError.error.d.ts +6 -9
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -0
- package/dist/lifecycle/core/index.d.ts +1 -1
- package/dist/lifecycle/core/index.js +1 -1
- package/dist/lifecycle/core/lifecycle.d.ts +47 -2
- package/dist/lifecycle/core/lifecycle.js +251 -85
- package/dist/lifecycle/core/lifecycleRegistry.registry.d.ts +8 -0
- package/dist/lifecycle/core/lifecycleRegistry.registry.js +20 -1
- package/dist/lifecycle/manager/lifecycleManager.manager.d.ts +21 -2
- package/dist/lifecycle/manager/lifecycleManager.manager.js +62 -99
- package/dist/lifecycle/scope/lifecycleScope.scope.d.ts +22 -1
- package/dist/lifecycle/scope/lifecycleScope.scope.js +85 -17
- package/dist/logging/console/consoleLogger.logger.d.ts +20 -1
- package/dist/logging/console/consoleLogger.logger.js +77 -11
- package/dist/logging/console/loggerFactory.factory.d.ts +6 -5
- package/dist/logging/console/loggerFactory.factory.js +1 -7
- package/dist/logging/core/index.d.ts +4 -3
- package/dist/logging/core/index.js +4 -3
- package/dist/logging/core/logEntry.entry.d.ts +41 -3
- package/dist/logging/core/logEntry.entry.js +114 -4
- package/dist/logging/core/logLevel.level.d.ts +18 -0
- package/dist/logging/core/logLevel.level.js +25 -1
- package/dist/logging/core/logRedaction.redaction.d.ts +38 -0
- package/dist/logging/core/logRedaction.redaction.js +19 -0
- package/dist/logging/core/logger.d.ts +14 -11
- package/dist/logging/core/logger.js +31 -6
- package/dist/logging/core/loggerContext.context.d.ts +12 -0
- package/dist/logging/core/loggerContext.context.js +19 -0
- package/dist/logging/core/loggerOptions.options.d.ts +17 -0
- package/dist/modules/index.d.ts +0 -1
- package/dist/modules/index.js +0 -6
- package/dist/modules/module.d.ts +7 -1
- package/dist/modules/moduleContext.context.d.ts +41 -7
- package/dist/modules/moduleContext.context.js +31 -8
- package/dist/modules/moduleDefinition.definition.d.ts +11 -7
- package/dist/modules/moduleDefinition.definition.js +41 -8
- package/dist/modules/moduleDependency/index.d.ts +2 -2
- package/dist/modules/moduleDependency/index.js +1 -1
- package/dist/modules/moduleDependency/moduleDependency.graph.d.ts +19 -2
- package/dist/modules/moduleDependency/moduleDependency.graph.js +122 -8
- package/dist/modules/moduleDependency/moduleDependency.ordering.d.ts +8 -0
- package/dist/modules/moduleDependency/moduleDependency.ordering.js +85 -57
- package/dist/modules/moduleDependency/moduleDependency.type.d.ts +28 -1
- package/dist/modules/moduleError/index.d.ts +1 -1
- package/dist/modules/moduleError/index.js +1 -1
- package/dist/modules/moduleError/moduleError.dependency.d.ts +11 -0
- package/dist/modules/moduleError/moduleError.dependency.js +15 -0
- package/dist/modules/moduleLifecycle/index.d.ts +5 -2
- package/dist/modules/moduleLifecycle/index.js +4 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.d.ts +44 -6
- package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.js +153 -9
- package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.d.ts +30 -5
- package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.js +130 -10
- package/dist/modules/moduleLifecycle/moduleLifecycle.type.d.ts +65 -28
- package/dist/modules/moduleLifecycle/moduleLifecycle.type.js +15 -4
- package/dist/modules/moduleLoader/moduleLoader.loader.d.ts +39 -5
- package/dist/modules/moduleLoader/moduleLoader.loader.js +123 -50
- package/dist/modules/moduleLoader/moduleLoader.type.d.ts +4 -2
- package/dist/modules/moduleLoader/moduleLoader.type.js +10 -3
- package/dist/modules/moduleMetadata.metadata.js +15 -5
- package/dist/modules/moduleRegistry/index.d.ts +1 -1
- package/dist/modules/moduleRegistry/moduleRegistry.registry.d.ts +2 -2
- package/dist/modules/moduleRegistry/moduleRegistry.registry.js +38 -6
- package/dist/modules/moduleRegistry/moduleRegistry.type.d.ts +18 -1
- package/dist/runtime/index.d.ts +17 -15
- package/dist/runtime/index.js +14 -10
- package/dist/runtime/runtime.d.ts +135 -33
- package/dist/runtime/runtime.js +344 -114
- package/dist/runtime/runtimeBootstrap/index.d.ts +2 -1
- package/dist/runtime/runtimeBootstrap/index.js +1 -1
- package/dist/runtime/runtimeBootstrap/pipeline/index.d.ts +2 -2
- package/dist/runtime/runtimeBootstrap/pipeline/index.js +1 -2
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.d.ts +41 -15
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.js +98 -76
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.d.ts +7 -4
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.js +87 -59
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.d.ts +10 -4
- package/dist/runtime/runtimeContext/index.d.ts +3 -5
- package/dist/runtime/runtimeContext/index.js +2 -4
- package/dist/runtime/runtimeContext/runtimeContext.factory.d.ts +10 -4
- package/dist/runtime/runtimeContext/runtimeContext.factory.js +30 -7
- package/dist/runtime/runtimeContext/runtimeContext.type.d.ts +36 -47
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.d.ts +5 -0
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.js +6 -4
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.d.ts +4 -0
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.js +7 -9
- package/dist/runtime/runtimeEnvironment/index.d.ts +2 -2
- package/dist/runtime/runtimeEnvironment/index.js +1 -1
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.d.ts +20 -17
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.js +20 -13
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.d.ts +12 -1
- package/dist/runtime/runtimeError/index.d.ts +3 -3
- package/dist/runtime/runtimeError/index.js +1 -1
- package/dist/runtime/runtimeError/runtimeError.base.d.ts +15 -18
- package/dist/runtime/runtimeError/runtimeError.base.js +38 -36
- package/dist/runtime/runtimeError/runtimeError.lifecycle.d.ts +23 -8
- package/dist/runtime/runtimeError/runtimeError.lifecycle.js +31 -7
- package/dist/runtime/runtimeError/runtimeError.specialized.d.ts +1 -1
- package/dist/runtime/runtimeError/runtimeError.specialized.js +1 -1
- package/dist/runtime/runtimeError/runtimeError.type.d.ts +5 -9
- package/dist/runtime/runtimeLogger.d.ts +2 -2
- package/dist/runtime/runtimeLogger.js +3 -3
- package/dist/runtime/runtimeOptions/index.d.ts +1 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.defaults.d.ts +1 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.defaults.js +2 -0
- package/dist/runtime/runtimeOptions/runtimeOptions.resolver.js +5 -2
- package/dist/runtime/runtimeOptions/runtimeOptions.type.d.ts +45 -16
- package/dist/runtime/runtimeOptions/runtimeOptions.validation.js +0 -1
- package/dist/runtime/runtimeShutdown/index.d.ts +3 -2
- package/dist/runtime/runtimeShutdown/index.js +2 -2
- package/dist/runtime/runtimeShutdown/pipeline/index.d.ts +2 -1
- package/dist/runtime/runtimeShutdown/pipeline/index.js +1 -1
- package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.d.ts +37 -7
- package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.js +77 -51
- package/dist/runtime/runtimeShutdown/runtimeShutdown.core.d.ts +8 -16
- package/dist/runtime/runtimeShutdown/runtimeShutdown.core.js +85 -87
- package/dist/runtime/runtimeShutdown/runtimeShutdown.type.d.ts +9 -5
- package/dist/runtime/runtimeSignals/index.d.ts +8 -0
- package/dist/runtime/runtimeSignals/index.js +7 -0
- package/dist/runtime/runtimeSignals/runtimeSignals.d.ts +93 -0
- package/dist/runtime/runtimeSignals/runtimeSignals.js +149 -0
- package/dist/runtime/runtimeState.state.d.ts +32 -14
- package/dist/runtime/runtimeState.state.js +34 -27
- package/dist/runtime/runtimeTimeout.d.ts +40 -0
- package/dist/runtime/runtimeTimeout.js +42 -0
- package/package.json +21 -15
- package/dist/.tsbuildinfo +0 -1
- package/dist/application/application.d.ts.map +0 -1
- package/dist/application/application.js.map +0 -1
- package/dist/application/applicationContext.context.d.ts.map +0 -1
- package/dist/application/applicationContext.context.js.map +0 -1
- package/dist/application/applicationState.state.d.ts.map +0 -1
- package/dist/application/applicationState.state.js.map +0 -1
- package/dist/application/index.d.ts.map +0 -1
- package/dist/application/index.js.map +0 -1
- package/dist/configuration/configurationManager.manager.d.ts.map +0 -1
- package/dist/configuration/configurationManager.manager.js.map +0 -1
- package/dist/configuration/core/configuration.d.ts.map +0 -1
- package/dist/configuration/core/configuration.js.map +0 -1
- package/dist/configuration/core/configurationKey.key.d.ts.map +0 -1
- package/dist/configuration/core/configurationKey.key.js.map +0 -1
- package/dist/configuration/core/configurationSource.source.d.ts.map +0 -1
- package/dist/configuration/core/configurationSource.source.js.map +0 -1
- package/dist/configuration/core/index.d.ts.map +0 -1
- package/dist/configuration/core/index.js.map +0 -1
- package/dist/configuration/error/configurationError.error.d.ts.map +0 -1
- package/dist/configuration/error/configurationError.error.js.map +0 -1
- package/dist/configuration/error/configurationRedactor.redactor.d.ts.map +0 -1
- package/dist/configuration/error/configurationRedactor.redactor.js.map +0 -1
- package/dist/configuration/error/index.d.ts.map +0 -1
- package/dist/configuration/error/index.js.map +0 -1
- package/dist/configuration/events/configurationEvents.events.d.ts.map +0 -1
- package/dist/configuration/events/configurationEvents.events.js.map +0 -1
- package/dist/configuration/events/index.d.ts.map +0 -1
- package/dist/configuration/events/index.js.map +0 -1
- package/dist/configuration/index.d.ts.map +0 -1
- package/dist/configuration/index.js.map +0 -1
- package/dist/configuration/loader/configurationLoader.loader.d.ts.map +0 -1
- package/dist/configuration/loader/configurationLoader.loader.js.map +0 -1
- package/dist/configuration/loader/index.d.ts.map +0 -1
- package/dist/configuration/loader/index.js.map +0 -1
- package/dist/configuration/registry/configurationProvider.provider.d.ts.map +0 -1
- package/dist/configuration/registry/configurationProvider.provider.js.map +0 -1
- package/dist/configuration/registry/configurationRegistry.registry.d.ts.map +0 -1
- package/dist/configuration/registry/configurationRegistry.registry.js.map +0 -1
- package/dist/configuration/registry/index.d.ts.map +0 -1
- package/dist/configuration/registry/index.js.map +0 -1
- package/dist/configuration/schema/configurationSchema.schema.d.ts.map +0 -1
- package/dist/configuration/schema/configurationSchema.schema.js.map +0 -1
- package/dist/configuration/schema/configurationValidation.validator.d.ts.map +0 -1
- package/dist/configuration/schema/configurationValidation.validator.js.map +0 -1
- package/dist/configuration/schema/index.d.ts.map +0 -1
- package/dist/configuration/schema/index.js.map +0 -1
- package/dist/container/container.d.ts.map +0 -1
- package/dist/container/container.js.map +0 -1
- package/dist/container/index.d.ts.map +0 -1
- package/dist/container/index.js.map +0 -1
- package/dist/container/provider.d.ts.map +0 -1
- package/dist/container/provider.js.map +0 -1
- package/dist/container/scope.d.ts.map +0 -1
- package/dist/container/scope.js.map +0 -1
- package/dist/container/token.d.ts.map +0 -1
- package/dist/container/token.js.map +0 -1
- package/dist/context/core/context.d.ts +0 -95
- package/dist/context/core/context.d.ts.map +0 -1
- package/dist/context/core/context.js +0 -103
- package/dist/context/core/context.js.map +0 -1
- package/dist/context/core/contextKey.key.d.ts.map +0 -1
- package/dist/context/core/contextKey.key.js.map +0 -1
- package/dist/context/core/executionContext.context.d.ts.map +0 -1
- package/dist/context/core/executionContext.context.js.map +0 -1
- package/dist/context/core/index.d.ts.map +0 -1
- package/dist/context/core/index.js.map +0 -1
- package/dist/context/index.d.ts.map +0 -1
- package/dist/context/index.js.map +0 -1
- package/dist/context/provider/contextProvider.provider.d.ts.map +0 -1
- package/dist/context/provider/contextProvider.provider.js.map +0 -1
- package/dist/context/provider/contextStorage.storage.d.ts.map +0 -1
- package/dist/context/provider/contextStorage.storage.js.map +0 -1
- package/dist/context/provider/index.d.ts.map +0 -1
- package/dist/context/provider/index.js.map +0 -1
- package/dist/context/snapshot/contextSnapshot.snapshot.d.ts.map +0 -1
- package/dist/context/snapshot/contextSnapshot.snapshot.js.map +0 -1
- package/dist/context/snapshot/index.d.ts.map +0 -1
- package/dist/context/snapshot/index.js.map +0 -1
- package/dist/context/values/contextValues.values.d.ts.map +0 -1
- package/dist/context/values/contextValues.values.js.map +0 -1
- package/dist/context/values/index.d.ts.map +0 -1
- package/dist/context/values/index.js.map +0 -1
- package/dist/contracts/adapter.d.ts.map +0 -1
- package/dist/contracts/adapter.js.map +0 -1
- package/dist/contracts/disposable.d.ts.map +0 -1
- package/dist/contracts/disposable.js.map +0 -1
- package/dist/contracts/handler.d.ts.map +0 -1
- package/dist/contracts/handler.js.map +0 -1
- package/dist/contracts/index.d.ts.map +0 -1
- package/dist/contracts/index.js.map +0 -1
- package/dist/errors/errorCode.code.d.ts.map +0 -1
- package/dist/errors/errorCode.code.js.map +0 -1
- package/dist/errors/exceptions.d.ts.map +0 -1
- package/dist/errors/exceptions.js.map +0 -1
- package/dist/errors/frameworkError.error.d.ts.map +0 -1
- package/dist/errors/frameworkError.error.js.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lifecycle/core/index.d.ts.map +0 -1
- package/dist/lifecycle/core/index.js.map +0 -1
- package/dist/lifecycle/core/lifecycle.d.ts.map +0 -1
- package/dist/lifecycle/core/lifecycle.js.map +0 -1
- package/dist/lifecycle/core/lifecycleHook.hook.d.ts.map +0 -1
- package/dist/lifecycle/core/lifecycleHook.hook.js.map +0 -1
- package/dist/lifecycle/core/lifecycleRegistry.registry.d.ts.map +0 -1
- package/dist/lifecycle/core/lifecycleRegistry.registry.js.map +0 -1
- package/dist/lifecycle/core/lifecycleState.state.d.ts +0 -2
- package/dist/lifecycle/core/lifecycleState.state.d.ts.map +0 -1
- package/dist/lifecycle/core/lifecycleState.state.js +0 -2
- package/dist/lifecycle/core/lifecycleState.state.js.map +0 -1
- package/dist/lifecycle/index.d.ts.map +0 -1
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/lifecycle/manager/index.d.ts.map +0 -1
- package/dist/lifecycle/manager/index.js.map +0 -1
- package/dist/lifecycle/manager/lifecycleManager.manager.d.ts.map +0 -1
- package/dist/lifecycle/manager/lifecycleManager.manager.js.map +0 -1
- package/dist/lifecycle/scope/index.d.ts.map +0 -1
- package/dist/lifecycle/scope/index.js.map +0 -1
- package/dist/lifecycle/scope/lifecycleScope.scope.d.ts.map +0 -1
- package/dist/lifecycle/scope/lifecycleScope.scope.js.map +0 -1
- package/dist/logging/console/consoleLogger.logger.d.ts.map +0 -1
- package/dist/logging/console/consoleLogger.logger.js.map +0 -1
- package/dist/logging/console/index.d.ts.map +0 -1
- package/dist/logging/console/index.js.map +0 -1
- package/dist/logging/console/loggerFactory.factory.d.ts.map +0 -1
- package/dist/logging/console/loggerFactory.factory.js.map +0 -1
- package/dist/logging/core/index.d.ts.map +0 -1
- package/dist/logging/core/index.js.map +0 -1
- package/dist/logging/core/logEntry.entry.d.ts.map +0 -1
- package/dist/logging/core/logEntry.entry.js.map +0 -1
- package/dist/logging/core/logLevel.level.d.ts.map +0 -1
- package/dist/logging/core/logLevel.level.js.map +0 -1
- package/dist/logging/core/logger.d.ts.map +0 -1
- package/dist/logging/core/logger.js.map +0 -1
- package/dist/logging/core/loggerContext.context.d.ts.map +0 -1
- package/dist/logging/core/loggerContext.context.js.map +0 -1
- package/dist/logging/core/loggerOptions.options.d.ts.map +0 -1
- package/dist/logging/core/loggerOptions.options.js.map +0 -1
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/logging/index.js.map +0 -1
- package/dist/modules/index.d.ts.map +0 -1
- package/dist/modules/index.js.map +0 -1
- package/dist/modules/module.d.ts.map +0 -1
- package/dist/modules/module.js.map +0 -1
- package/dist/modules/moduleContext.context.d.ts.map +0 -1
- package/dist/modules/moduleContext.context.js.map +0 -1
- package/dist/modules/moduleDefinition.definition.d.ts.map +0 -1
- package/dist/modules/moduleDefinition.definition.js.map +0 -1
- package/dist/modules/moduleDependency/index.d.ts.map +0 -1
- package/dist/modules/moduleDependency/index.js.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.graph.d.ts.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.graph.js.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.ordering.d.ts.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.ordering.js.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.type.d.ts.map +0 -1
- package/dist/modules/moduleDependency/moduleDependency.type.js.map +0 -1
- package/dist/modules/moduleError/index.d.ts.map +0 -1
- package/dist/modules/moduleError/index.js.map +0 -1
- package/dist/modules/moduleError/moduleError.base.d.ts.map +0 -1
- package/dist/modules/moduleError/moduleError.base.js.map +0 -1
- package/dist/modules/moduleError/moduleError.dependency.d.ts.map +0 -1
- package/dist/modules/moduleError/moduleError.dependency.js.map +0 -1
- package/dist/modules/moduleError/moduleError.helpers.d.ts.map +0 -1
- package/dist/modules/moduleError/moduleError.helpers.js.map +0 -1
- package/dist/modules/moduleError/moduleError.lifecycle.d.ts.map +0 -1
- package/dist/modules/moduleError/moduleError.lifecycle.js.map +0 -1
- package/dist/modules/moduleError/moduleError.registration.d.ts.map +0 -1
- package/dist/modules/moduleError/moduleError.registration.js.map +0 -1
- package/dist/modules/moduleLifecycle/index.d.ts.map +0 -1
- package/dist/modules/moduleLifecycle/index.js.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.d.ts.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.lifecycle.js.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.d.ts.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.stateMachine.js.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.type.d.ts.map +0 -1
- package/dist/modules/moduleLifecycle/moduleLifecycle.type.js.map +0 -1
- package/dist/modules/moduleLoader/index.d.ts.map +0 -1
- package/dist/modules/moduleLoader/index.js.map +0 -1
- package/dist/modules/moduleLoader/moduleLoader.loader.d.ts.map +0 -1
- package/dist/modules/moduleLoader/moduleLoader.loader.js.map +0 -1
- package/dist/modules/moduleLoader/moduleLoader.type.d.ts.map +0 -1
- package/dist/modules/moduleLoader/moduleLoader.type.js.map +0 -1
- package/dist/modules/moduleMetadata.metadata.d.ts.map +0 -1
- package/dist/modules/moduleMetadata.metadata.js.map +0 -1
- package/dist/modules/moduleRegistry/index.d.ts.map +0 -1
- package/dist/modules/moduleRegistry/index.js.map +0 -1
- package/dist/modules/moduleRegistry/moduleRegistry.registry.d.ts.map +0 -1
- package/dist/modules/moduleRegistry/moduleRegistry.registry.js.map +0 -1
- package/dist/modules/moduleRegistry/moduleRegistry.type.d.ts.map +0 -1
- package/dist/modules/moduleRegistry/moduleRegistry.type.js.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/runtime.d.ts.map +0 -1
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/index.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/index.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/index.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/index.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.d.ts +0 -6
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.js +0 -27
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.invoke.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/pipeline/runtimeBootstrap.pipeline.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.core.js.map +0 -1
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.d.ts.map +0 -1
- package/dist/runtime/runtimeBootstrap/runtimeBootstrap.type.js.map +0 -1
- package/dist/runtime/runtimeContext/index.d.ts.map +0 -1
- package/dist/runtime/runtimeContext/index.js.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.core.d.ts +0 -38
- package/dist/runtime/runtimeContext/runtimeContext.core.d.ts.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.core.js +0 -99
- package/dist/runtime/runtimeContext/runtimeContext.core.js.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.factory.d.ts.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.factory.js.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.type.d.ts.map +0 -1
- package/dist/runtime/runtimeContext/runtimeContext.type.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/index.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/index.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.detection.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.detection.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.env.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/detection/runtimeEnvironment.os.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/index.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/index.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.core.js.map +0 -1
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.d.ts.map +0 -1
- package/dist/runtime/runtimeEnvironment/runtimeEnvironment.type.js.map +0 -1
- package/dist/runtime/runtimeError/index.d.ts.map +0 -1
- package/dist/runtime/runtimeError/index.js.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.base.d.ts.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.base.js.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.lifecycle.d.ts.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.lifecycle.js.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.specialized.d.ts.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.specialized.js.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.type.d.ts.map +0 -1
- package/dist/runtime/runtimeError/runtimeError.type.js.map +0 -1
- package/dist/runtime/runtimeLogger.d.ts.map +0 -1
- package/dist/runtime/runtimeLogger.js.map +0 -1
- package/dist/runtime/runtimeManager/index.d.ts +0 -12
- package/dist/runtime/runtimeManager/index.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/index.js +0 -11
- package/dist/runtime/runtimeManager/index.js.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.core.d.ts +0 -31
- package/dist/runtime/runtimeManager/runtimeManager.core.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.core.js +0 -136
- package/dist/runtime/runtimeManager/runtimeManager.core.js.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.error.d.ts +0 -14
- package/dist/runtime/runtimeManager/runtimeManager.error.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.error.js +0 -21
- package/dist/runtime/runtimeManager/runtimeManager.error.js.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.factory.d.ts +0 -7
- package/dist/runtime/runtimeManager/runtimeManager.factory.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.factory.js +0 -8
- package/dist/runtime/runtimeManager/runtimeManager.factory.js.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.lifecycle.d.ts +0 -16
- package/dist/runtime/runtimeManager/runtimeManager.lifecycle.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.lifecycle.js +0 -49
- package/dist/runtime/runtimeManager/runtimeManager.lifecycle.js.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.type.d.ts +0 -54
- package/dist/runtime/runtimeManager/runtimeManager.type.d.ts.map +0 -1
- package/dist/runtime/runtimeManager/runtimeManager.type.js +0 -2
- package/dist/runtime/runtimeManager/runtimeManager.type.js.map +0 -1
- package/dist/runtime/runtimeOptions/index.d.ts.map +0 -1
- package/dist/runtime/runtimeOptions/index.js.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.defaults.d.ts.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.defaults.js.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.resolver.d.ts.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.resolver.js.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.type.d.ts.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.type.js.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.validation.d.ts.map +0 -1
- package/dist/runtime/runtimeOptions/runtimeOptions.validation.js.map +0 -1
- package/dist/runtime/runtimeShutdown/index.d.ts.map +0 -1
- package/dist/runtime/runtimeShutdown/index.js.map +0 -1
- package/dist/runtime/runtimeShutdown/pipeline/index.d.ts.map +0 -1
- package/dist/runtime/runtimeShutdown/pipeline/index.js.map +0 -1
- package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.d.ts.map +0 -1
- package/dist/runtime/runtimeShutdown/pipeline/runtimeShutdown.pipeline.js.map +0 -1
- package/dist/runtime/runtimeShutdown/runtimeShutdown.core.d.ts.map +0 -1
- package/dist/runtime/runtimeShutdown/runtimeShutdown.core.js.map +0 -1
- package/dist/runtime/runtimeShutdown/runtimeShutdown.type.d.ts.map +0 -1
- package/dist/runtime/runtimeShutdown/runtimeShutdown.type.js.map +0 -1
- package/dist/runtime/runtimeState.state.d.ts.map +0 -1
- package/dist/runtime/runtimeState.state.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InvalidStateError } from "../../errors/exceptions.js";
|
|
1
2
|
/** Lifecycle states supported by the Zudojs application runtime. */
|
|
2
3
|
export const LifecycleState = {
|
|
3
4
|
CREATED: "created",
|
|
@@ -9,12 +10,32 @@ export const LifecycleState = {
|
|
|
9
10
|
STOPPED: "stopped",
|
|
10
11
|
FAILED: "failed",
|
|
11
12
|
};
|
|
12
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Coordinates initialization, startup, shutdown, and disposal of
|
|
15
|
+
* application resources.
|
|
16
|
+
*
|
|
17
|
+
* State machine:
|
|
18
|
+
*
|
|
19
|
+
* CREATED → INITIALIZING → INITIALIZED → STARTING → RUNNING
|
|
20
|
+
* RUNNING → STOPPING → STOPPED → (STARTING → RUNNING) restart
|
|
21
|
+
* any phase failure → FAILED; initialize()/start() retry from FAILED
|
|
22
|
+
* resume with the participant that failed; stop() from FAILED unwinds
|
|
23
|
+
* whatever started.
|
|
24
|
+
*
|
|
25
|
+
* Concurrent callers of the same phase share the in-flight promise.
|
|
26
|
+
*/
|
|
13
27
|
export class Lifecycle {
|
|
14
28
|
state = LifecycleState.CREATED;
|
|
15
29
|
participants = [];
|
|
16
30
|
logger;
|
|
17
31
|
continueOnShutdownError;
|
|
32
|
+
initializedCount = 0;
|
|
33
|
+
startedCount = 0;
|
|
34
|
+
disposed = false;
|
|
35
|
+
failedPhase;
|
|
36
|
+
initializePromise;
|
|
37
|
+
startPromise;
|
|
38
|
+
stopPromise;
|
|
18
39
|
constructor(options = {}) {
|
|
19
40
|
this.logger = options.logger;
|
|
20
41
|
this.continueOnShutdownError = options.continueOnShutdownError ?? true;
|
|
@@ -25,11 +46,20 @@ export class Lifecycle {
|
|
|
25
46
|
getParticipants() {
|
|
26
47
|
return [...this.participants];
|
|
27
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether dispose() has run. A disposed lifecycle cannot be
|
|
51
|
+
* restarted.
|
|
52
|
+
*/
|
|
53
|
+
isDisposed() {
|
|
54
|
+
return this.disposed;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Registers a participant. Only allowed before initialization
|
|
58
|
+
* begins so every participant goes through every phase.
|
|
59
|
+
*/
|
|
28
60
|
register(participant) {
|
|
29
|
-
if (this.state !== LifecycleState.CREATED
|
|
30
|
-
this.state
|
|
31
|
-
this.state !== LifecycleState.INITIALIZED) {
|
|
32
|
-
throw new Error(`Cannot register lifecycle participant "${participant.name}" while application is "${this.state}".`);
|
|
61
|
+
if (this.state !== LifecycleState.CREATED) {
|
|
62
|
+
throw new InvalidStateError(`Cannot register lifecycle participant "${participant.name}" while application is "${this.state}".`, { participant: participant.name, state: this.state });
|
|
33
63
|
}
|
|
34
64
|
this.participants.push(participant);
|
|
35
65
|
this.logger?.debug("Lifecycle participant registered", {
|
|
@@ -37,101 +67,132 @@ export class Lifecycle {
|
|
|
37
67
|
});
|
|
38
68
|
}
|
|
39
69
|
async initialize() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
switch (this.state) {
|
|
71
|
+
case LifecycleState.INITIALIZED:
|
|
72
|
+
case LifecycleState.STARTING:
|
|
73
|
+
case LifecycleState.RUNNING:
|
|
74
|
+
return;
|
|
75
|
+
case LifecycleState.INITIALIZING:
|
|
76
|
+
return this.initializePromise;
|
|
77
|
+
case LifecycleState.FAILED:
|
|
78
|
+
if (this.failedPhase !== "initialize") {
|
|
79
|
+
if (this.failedPhase === "start")
|
|
80
|
+
return;
|
|
81
|
+
throw this.invalidState("initialize");
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case LifecycleState.STOPPED:
|
|
85
|
+
// A lifecycle stopped after a failed initialization resumes
|
|
86
|
+
// the pending participants; a fully initialized one is done.
|
|
87
|
+
if (this.disposed)
|
|
88
|
+
throw this.invalidState("initialize");
|
|
89
|
+
if (this.initializedCount >= this.participants.length)
|
|
90
|
+
return;
|
|
91
|
+
break;
|
|
92
|
+
case LifecycleState.CREATED:
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
throw this.invalidState("initialize");
|
|
96
|
+
}
|
|
97
|
+
this.initializePromise = this.runInitialize();
|
|
48
98
|
try {
|
|
49
|
-
|
|
50
|
-
this.logger?.debug("Initializing lifecycle participant", {
|
|
51
|
-
participant: participant.name,
|
|
52
|
-
});
|
|
53
|
-
await participant.initialize?.();
|
|
54
|
-
}
|
|
55
|
-
this.state = LifecycleState.INITIALIZED;
|
|
56
|
-
this.logger?.info("Application initialization completed");
|
|
99
|
+
await this.initializePromise;
|
|
57
100
|
}
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
this.logger?.error("Application initialization failed", error);
|
|
61
|
-
throw error;
|
|
101
|
+
finally {
|
|
102
|
+
this.initializePromise = undefined;
|
|
62
103
|
}
|
|
63
104
|
}
|
|
64
105
|
async start() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
switch (this.state) {
|
|
107
|
+
case LifecycleState.RUNNING:
|
|
108
|
+
return;
|
|
109
|
+
case LifecycleState.STARTING:
|
|
110
|
+
return this.startPromise;
|
|
111
|
+
case LifecycleState.INITIALIZING:
|
|
112
|
+
await this.initializePromise;
|
|
113
|
+
return this.start();
|
|
114
|
+
case LifecycleState.CREATED:
|
|
115
|
+
await this.initialize();
|
|
116
|
+
return this.start();
|
|
117
|
+
case LifecycleState.FAILED:
|
|
118
|
+
if (this.failedPhase === "initialize") {
|
|
119
|
+
await this.initialize();
|
|
120
|
+
return this.start();
|
|
121
|
+
}
|
|
122
|
+
if (this.failedPhase !== "start") {
|
|
123
|
+
throw this.invalidState("start");
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case LifecycleState.STOPPED:
|
|
127
|
+
if (this.disposed)
|
|
128
|
+
throw this.invalidState("start");
|
|
129
|
+
if (this.initializedCount < this.participants.length) {
|
|
130
|
+
await this.initialize();
|
|
131
|
+
return this.start();
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case LifecycleState.INITIALIZED:
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
throw this.invalidState("start");
|
|
138
|
+
}
|
|
139
|
+
this.startPromise = this.runStart();
|
|
76
140
|
try {
|
|
77
|
-
|
|
78
|
-
this.logger?.debug("Starting lifecycle participant", {
|
|
79
|
-
participant: participant.name,
|
|
80
|
-
});
|
|
81
|
-
await participant.start?.();
|
|
82
|
-
}
|
|
83
|
-
this.state = LifecycleState.RUNNING;
|
|
84
|
-
this.logger?.info("Application startup completed");
|
|
141
|
+
await this.startPromise;
|
|
85
142
|
}
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
this.logger?.error("Application startup failed", error);
|
|
89
|
-
throw error;
|
|
143
|
+
finally {
|
|
144
|
+
this.startPromise = undefined;
|
|
90
145
|
}
|
|
91
146
|
}
|
|
92
|
-
async
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.state === LifecycleState.FAILED)
|
|
147
|
+
async stop() {
|
|
148
|
+
switch (this.state) {
|
|
149
|
+
case LifecycleState.STOPPED:
|
|
96
150
|
return;
|
|
97
|
-
|
|
151
|
+
case LifecycleState.STOPPING:
|
|
152
|
+
return this.stopPromise;
|
|
153
|
+
case LifecycleState.INITIALIZING:
|
|
154
|
+
await this.initializePromise?.catch(() => undefined);
|
|
155
|
+
return this.stop();
|
|
156
|
+
case LifecycleState.STARTING:
|
|
157
|
+
await this.startPromise?.catch(() => undefined);
|
|
158
|
+
return this.stop();
|
|
159
|
+
case LifecycleState.CREATED:
|
|
160
|
+
case LifecycleState.INITIALIZED:
|
|
161
|
+
// Nothing has started; no stop hooks to run.
|
|
162
|
+
this.state = LifecycleState.STOPPED;
|
|
98
163
|
return;
|
|
99
|
-
|
|
164
|
+
case LifecycleState.FAILED:
|
|
165
|
+
if (this.failedPhase === "dispose")
|
|
166
|
+
throw this.invalidState("stop");
|
|
167
|
+
break;
|
|
168
|
+
case LifecycleState.RUNNING:
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
throw this.invalidState("stop");
|
|
100
172
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.state !== LifecycleState.FAILED)
|
|
108
|
-
throw new Error(`Cannot stop application while state is "${this.state}".`);
|
|
109
|
-
this.state = LifecycleState.STOPPING;
|
|
110
|
-
this.logger?.debug("Application shutdown started");
|
|
111
|
-
const errors = [];
|
|
112
|
-
for (let i = this.participants.length - 1; i >= 0; i--) {
|
|
113
|
-
const participant = this.participants[i];
|
|
114
|
-
try {
|
|
115
|
-
this.logger?.debug("Stopping lifecycle participant", {
|
|
116
|
-
participant: participant.name,
|
|
117
|
-
});
|
|
118
|
-
await participant.stop?.();
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
errors.push(error);
|
|
122
|
-
this.logger?.error("Failed to stop lifecycle participant", error, {
|
|
123
|
-
participant: participant.name,
|
|
124
|
-
});
|
|
125
|
-
if (!this.continueOnShutdownError)
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
173
|
+
this.stopPromise = this.runStop();
|
|
174
|
+
try {
|
|
175
|
+
await this.stopPromise;
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
this.stopPromise = undefined;
|
|
128
179
|
}
|
|
129
|
-
this.state = LifecycleState.STOPPED;
|
|
130
|
-
this.logger?.info("Application shutdown completed");
|
|
131
|
-
if (errors.length > 0)
|
|
132
|
-
throw new AggregateError(errors, "One or more lifecycle participants failed to stop.");
|
|
133
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Disposes every participant in reverse registration order.
|
|
183
|
+
*
|
|
184
|
+
* Idempotent. Participants that are still running are not stopped
|
|
185
|
+
* first; use shutdown() for stop-then-dispose.
|
|
186
|
+
*/
|
|
134
187
|
async dispose() {
|
|
188
|
+
if (this.disposed)
|
|
189
|
+
return;
|
|
190
|
+
if (this.state === LifecycleState.STOPPING ||
|
|
191
|
+
this.state === LifecycleState.STARTING ||
|
|
192
|
+
this.state === LifecycleState.INITIALIZING) {
|
|
193
|
+
throw this.invalidState("dispose");
|
|
194
|
+
}
|
|
195
|
+
this.disposed = true;
|
|
135
196
|
const errors = [];
|
|
136
197
|
for (let i = this.participants.length - 1; i >= 0; i--) {
|
|
137
198
|
const participant = this.participants[i];
|
|
@@ -150,6 +211,15 @@ export class Lifecycle {
|
|
|
150
211
|
break;
|
|
151
212
|
}
|
|
152
213
|
}
|
|
214
|
+
this.initializedCount = 0;
|
|
215
|
+
this.startedCount = 0;
|
|
216
|
+
if (errors.length > 0 && !this.continueOnShutdownError) {
|
|
217
|
+
this.state = LifecycleState.FAILED;
|
|
218
|
+
this.failedPhase = "dispose";
|
|
219
|
+
}
|
|
220
|
+
else if (this.state !== LifecycleState.FAILED) {
|
|
221
|
+
this.state = LifecycleState.STOPPED;
|
|
222
|
+
}
|
|
153
223
|
if (errors.length > 0)
|
|
154
224
|
throw new AggregateError(errors, "One or more lifecycle participants failed to dispose.");
|
|
155
225
|
}
|
|
@@ -175,5 +245,101 @@ export class Lifecycle {
|
|
|
175
245
|
if (disposeError)
|
|
176
246
|
throw disposeError;
|
|
177
247
|
}
|
|
248
|
+
async runInitialize() {
|
|
249
|
+
this.state = LifecycleState.INITIALIZING;
|
|
250
|
+
this.failedPhase = undefined;
|
|
251
|
+
this.logger?.debug("Application initialization started");
|
|
252
|
+
try {
|
|
253
|
+
for (let i = this.initializedCount; i < this.participants.length; i++) {
|
|
254
|
+
const participant = this.participants[i];
|
|
255
|
+
this.logger?.debug("Initializing lifecycle participant", {
|
|
256
|
+
participant: participant.name,
|
|
257
|
+
});
|
|
258
|
+
await participant.initialize?.();
|
|
259
|
+
this.initializedCount = i + 1;
|
|
260
|
+
}
|
|
261
|
+
this.state = LifecycleState.INITIALIZED;
|
|
262
|
+
this.logger?.info("Application initialization completed");
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
this.state = LifecycleState.FAILED;
|
|
266
|
+
this.failedPhase = "initialize";
|
|
267
|
+
this.logger?.error("Application initialization failed", error);
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async runStart() {
|
|
272
|
+
this.state = LifecycleState.STARTING;
|
|
273
|
+
this.failedPhase = undefined;
|
|
274
|
+
this.logger?.debug("Application startup started");
|
|
275
|
+
try {
|
|
276
|
+
for (let i = this.startedCount; i < this.participants.length; i++) {
|
|
277
|
+
const participant = this.participants[i];
|
|
278
|
+
this.logger?.debug("Starting lifecycle participant", {
|
|
279
|
+
participant: participant.name,
|
|
280
|
+
});
|
|
281
|
+
await participant.start?.();
|
|
282
|
+
this.startedCount = i + 1;
|
|
283
|
+
}
|
|
284
|
+
this.state = LifecycleState.RUNNING;
|
|
285
|
+
this.logger?.info("Application startup completed");
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
this.state = LifecycleState.FAILED;
|
|
289
|
+
this.failedPhase = "start";
|
|
290
|
+
this.logger?.error("Application startup failed", error);
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async runStop() {
|
|
295
|
+
this.state = LifecycleState.STOPPING;
|
|
296
|
+
this.failedPhase = undefined;
|
|
297
|
+
this.logger?.debug("Application shutdown started");
|
|
298
|
+
const errors = [];
|
|
299
|
+
let aborted = false;
|
|
300
|
+
// Only participants whose start() completed are stopped.
|
|
301
|
+
for (let i = this.startedCount - 1; i >= 0; i--) {
|
|
302
|
+
const participant = this.participants[i];
|
|
303
|
+
try {
|
|
304
|
+
this.logger?.debug("Stopping lifecycle participant", {
|
|
305
|
+
participant: participant.name,
|
|
306
|
+
});
|
|
307
|
+
await participant.stop?.();
|
|
308
|
+
this.startedCount = i;
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
errors.push(error);
|
|
312
|
+
this.logger?.error("Failed to stop lifecycle participant", error, {
|
|
313
|
+
participant: participant.name,
|
|
314
|
+
});
|
|
315
|
+
if (!this.continueOnShutdownError) {
|
|
316
|
+
aborted = true;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
this.startedCount = i;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (aborted) {
|
|
323
|
+
this.state = LifecycleState.FAILED;
|
|
324
|
+
this.failedPhase = "stop";
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
this.startedCount = 0;
|
|
328
|
+
this.state = LifecycleState.STOPPED;
|
|
329
|
+
this.logger?.info("Application shutdown completed");
|
|
330
|
+
}
|
|
331
|
+
if (errors.length > 0)
|
|
332
|
+
throw new AggregateError(errors, "One or more lifecycle participants failed to stop.");
|
|
333
|
+
}
|
|
334
|
+
invalidState(operation) {
|
|
335
|
+
const label = operation === "initialize"
|
|
336
|
+
? "initialize"
|
|
337
|
+
: operation === "start"
|
|
338
|
+
? "start"
|
|
339
|
+
: operation === "stop"
|
|
340
|
+
? "stop"
|
|
341
|
+
: "dispose";
|
|
342
|
+
return new InvalidStateError(`Cannot ${label} application while state is "${this.state}".`, { operation, state: this.state });
|
|
343
|
+
}
|
|
178
344
|
}
|
|
179
345
|
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -50,6 +50,10 @@ export declare class LifecycleRegistry {
|
|
|
50
50
|
*
|
|
51
51
|
* Components are executed in reverse registration order
|
|
52
52
|
* during stopping and destruction.
|
|
53
|
+
*
|
|
54
|
+
* Names are unique within a registry: an explicit duplicate name is
|
|
55
|
+
* rejected, while derived names (constructor names) are made unique
|
|
56
|
+
* with a numeric suffix so getByName() is unambiguous.
|
|
53
57
|
*/
|
|
54
58
|
register(component: LifecycleComponent, name?: string): LifecycleRegistration;
|
|
55
59
|
/**
|
|
@@ -84,6 +88,10 @@ export declare class LifecycleRegistry {
|
|
|
84
88
|
* Removes all registrations.
|
|
85
89
|
*/
|
|
86
90
|
clear(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Suffixes a derived name until it is unique within the registry.
|
|
93
|
+
*/
|
|
94
|
+
private uniqueName;
|
|
87
95
|
/**
|
|
88
96
|
* Creates a stable registration ID.
|
|
89
97
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "../../errors/exceptions.js";
|
|
1
2
|
/**
|
|
2
3
|
* Registry responsible for lifecycle component registration
|
|
3
4
|
* and deterministic ordering.
|
|
@@ -13,11 +14,18 @@ export class LifecycleRegistry {
|
|
|
13
14
|
*
|
|
14
15
|
* Components are executed in reverse registration order
|
|
15
16
|
* during stopping and destruction.
|
|
17
|
+
*
|
|
18
|
+
* Names are unique within a registry: an explicit duplicate name is
|
|
19
|
+
* rejected, while derived names (constructor names) are made unique
|
|
20
|
+
* with a numeric suffix so getByName() is unambiguous.
|
|
16
21
|
*/
|
|
17
22
|
register(component, name) {
|
|
23
|
+
if (name !== undefined && this.getByName(name)) {
|
|
24
|
+
throw new InvalidArgumentError(`A lifecycle component named "${name}" is already registered.`, { name });
|
|
25
|
+
}
|
|
18
26
|
const registration = {
|
|
19
27
|
id: this.createId(),
|
|
20
|
-
name: name ?? this.resolveComponentName(component),
|
|
28
|
+
name: name ?? this.uniqueName(this.resolveComponentName(component)),
|
|
21
29
|
component,
|
|
22
30
|
order: this.sequence,
|
|
23
31
|
isParticipant: this.isLifecycleParticipant(component),
|
|
@@ -79,6 +87,17 @@ export class LifecycleRegistry {
|
|
|
79
87
|
clear() {
|
|
80
88
|
this.registrations.length = 0;
|
|
81
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Suffixes a derived name until it is unique within the registry.
|
|
92
|
+
*/
|
|
93
|
+
uniqueName(base) {
|
|
94
|
+
if (!this.getByName(base))
|
|
95
|
+
return base;
|
|
96
|
+
let index = 2;
|
|
97
|
+
while (this.getByName(`${base}#${index}`))
|
|
98
|
+
index += 1;
|
|
99
|
+
return `${base}#${index}`;
|
|
100
|
+
}
|
|
82
101
|
/**
|
|
83
102
|
* Creates a stable registration ID.
|
|
84
103
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from "../../logging/core/logger.js";
|
|
2
2
|
import { type LifecycleHook } from "../core/lifecycleHook.hook.js";
|
|
3
|
-
import { LifecycleState, type LifecycleParticipant } from "../core/lifecycle.js";
|
|
3
|
+
import { type LifecycleState, type LifecycleParticipant } from "../core/lifecycle.js";
|
|
4
4
|
/** Anything that can participate in the managed application lifecycle. */
|
|
5
5
|
export type ManagedLifecycleComponent = LifecycleParticipant | LifecycleHook;
|
|
6
6
|
/** Options for LifecycleManager. */
|
|
@@ -11,21 +11,40 @@ export interface LifecycleManagerOptions {
|
|
|
11
11
|
/**
|
|
12
12
|
* Coordinates lifecycle hooks and lifecycle participants.
|
|
13
13
|
* Primary API for application-level lifecycle management.
|
|
14
|
+
*
|
|
15
|
+
* Every component, whether it uses the hook interfaces (onInitialize,
|
|
16
|
+
* onStart, onStop, onDestroy) or the participant API (initialize,
|
|
17
|
+
* start, stop, dispose), is normalized into a single participant and
|
|
18
|
+
* driven by one Lifecycle state machine. This guarantees:
|
|
19
|
+
*
|
|
20
|
+
* - global registration order across both component kinds
|
|
21
|
+
* (initialize/start forward, stop/destroy reverse),
|
|
22
|
+
* - a component exposing both shapes runs exactly once per phase
|
|
23
|
+
* (the `onX` hook takes precedence),
|
|
24
|
+
* - state guards, retries, and concurrency rules of Lifecycle.
|
|
14
25
|
*/
|
|
15
26
|
export declare class LifecycleManager {
|
|
16
27
|
private readonly lifecycle;
|
|
17
28
|
private readonly components;
|
|
18
29
|
private readonly logger?;
|
|
19
|
-
private readonly continueOnShutdownError;
|
|
20
30
|
constructor(options?: LifecycleManagerOptions);
|
|
21
31
|
getState(): LifecycleState;
|
|
22
32
|
getComponents(): readonly ManagedLifecycleComponent[];
|
|
33
|
+
/**
|
|
34
|
+
* Registers a component. Only allowed before initialization begins.
|
|
35
|
+
*/
|
|
23
36
|
register(component: ManagedLifecycleComponent): void;
|
|
24
37
|
initialize(): Promise<void>;
|
|
25
38
|
start(): Promise<void>;
|
|
26
39
|
stop(): Promise<void>;
|
|
27
40
|
destroy(): Promise<void>;
|
|
28
41
|
shutdown(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Normalizes a component into a LifecycleParticipant. Hook methods
|
|
44
|
+
* (onInitialize, ...) win over participant methods (initialize, ...)
|
|
45
|
+
* when a component exposes both, so each phase runs once.
|
|
46
|
+
*/
|
|
47
|
+
private toParticipant;
|
|
29
48
|
private runHook;
|
|
30
49
|
private isLifecycleParticipant;
|
|
31
50
|
private getComponentName;
|