@tsed/di 8.11.1 → 8.11.2-rc.1
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/lib/esm/common/constants/constants.js +0 -1
- package/lib/esm/common/decorators/autoInjectable.js +0 -1
- package/lib/esm/common/decorators/configuration.js +0 -1
- package/lib/esm/common/decorators/constant.js +0 -1
- package/lib/esm/common/decorators/controller.js +0 -1
- package/lib/esm/common/decorators/inject.js +0 -1
- package/lib/esm/common/decorators/injectable.js +0 -1
- package/lib/esm/common/decorators/intercept.js +0 -1
- package/lib/esm/common/decorators/interceptor.js +0 -1
- package/lib/esm/common/decorators/lazyInject.js +0 -1
- package/lib/esm/common/decorators/module.js +0 -1
- package/lib/esm/common/decorators/opts.js +0 -1
- package/lib/esm/common/decorators/overrideProvider.js +0 -1
- package/lib/esm/common/decorators/scope.js +0 -1
- package/lib/esm/common/decorators/service.js +0 -1
- package/lib/esm/common/decorators/useOpts.js +0 -1
- package/lib/esm/common/decorators/value.js +0 -1
- package/lib/esm/common/domain/Container.js +0 -1
- package/lib/esm/common/domain/ControllerProvider.js +0 -1
- package/lib/esm/common/domain/InjectablePropertyType.js +0 -1
- package/lib/esm/common/domain/LocalsContainer.js +0 -1
- package/lib/esm/common/domain/Provider.js +0 -1
- package/lib/esm/common/domain/ProviderScope.js +0 -1
- package/lib/esm/common/domain/ProviderType.js +0 -1
- package/lib/esm/common/errors/InjectionError.js +0 -1
- package/lib/esm/common/errors/InvalidPropertyTokenError.js +0 -1
- package/lib/esm/common/fn/configuration.js +0 -1
- package/lib/esm/common/fn/constant.js +0 -1
- package/lib/esm/common/fn/inject.js +0 -1
- package/lib/esm/common/fn/injectMany.js +0 -1
- package/lib/esm/common/fn/injectable.js +0 -1
- package/lib/esm/common/fn/injector.js +0 -1
- package/lib/esm/common/fn/lazyInject.js +0 -1
- package/lib/esm/common/fn/localsContainer.js +0 -1
- package/lib/esm/common/fn/logger.js +0 -1
- package/lib/esm/common/fn/refValue.js +0 -1
- package/lib/esm/common/index.js +0 -1
- package/lib/esm/common/interfaces/DIConfigurationOptions.js +0 -1
- package/lib/esm/common/interfaces/DILogger.js +0 -1
- package/lib/esm/common/interfaces/DILoggerOptions.js +0 -1
- package/lib/esm/common/interfaces/ImportTokenProviderOpts.js +0 -1
- package/lib/esm/common/interfaces/InterceptorContext.js +0 -1
- package/lib/esm/common/interfaces/InterceptorMethods.js +0 -1
- package/lib/esm/common/interfaces/InvokeOptions.js +0 -1
- package/lib/esm/common/interfaces/OnDestroy.js +0 -1
- package/lib/esm/common/interfaces/OnInit.js +0 -1
- package/lib/esm/common/interfaces/ProviderOpts.js +0 -1
- package/lib/esm/common/interfaces/RegistrySettings.js +0 -1
- package/lib/esm/common/interfaces/ResolvedInvokeOptions.js +0 -1
- package/lib/esm/common/interfaces/TokenProvider.js +0 -1
- package/lib/esm/common/interfaces/TokenRoute.js +0 -1
- package/lib/esm/common/registries/GlobalProviders.js +0 -1
- package/lib/esm/common/registries/ProviderRegistry.js +0 -1
- package/lib/esm/common/services/DIConfiguration.js +0 -1
- package/lib/esm/common/services/DILogger.js +0 -1
- package/lib/esm/common/services/InjectorService.js +0 -1
- package/lib/esm/common/utils/colors.js +0 -1
- package/lib/esm/common/utils/createContainer.js +0 -1
- package/lib/esm/common/utils/discoverHooks.js +0 -1
- package/lib/esm/common/utils/getConfiguration.js +0 -1
- package/lib/esm/common/utils/getConstructorDependencies.js +0 -1
- package/lib/esm/common/utils/providerBuilder.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/node/decorators/injectContext.js +0 -1
- package/lib/esm/node/domain/ContextLogger.js +0 -1
- package/lib/esm/node/domain/DIContext.js +0 -1
- package/lib/esm/node/fn/context.js +0 -1
- package/lib/esm/node/fn/contextLogger.js +0 -1
- package/lib/esm/node/index.js +0 -1
- package/lib/esm/node/interfaces/AlterRunInContext.js +0 -1
- package/lib/esm/node/services/DILogger.js +0 -1
- package/lib/esm/node/services/DITest.js +0 -1
- package/lib/esm/node/utils/asyncHookContext.js +0 -1
- package/lib/esm/node/utils/attachLogger.js +0 -1
- package/lib/esm/node/utils/setLoggerConfiguration.js +0 -1
- package/lib/esm/node/utils/setLoggerFormat.js +0 -1
- package/lib/esm/node/utils/setLoggerLevel.js +0 -1
- package/package.json +12 -10
- package/.barrelsby.json +0 -5
- package/lib/browser/chunks/injectable.js +0 -65
- package/lib/browser/chunks/injectable.js.map +0 -1
- package/lib/browser/common/constants/constants.js +0 -9
- package/lib/browser/common/constants/constants.js.map +0 -1
- package/lib/browser/common/decorators/autoInjectable.js +0 -26
- package/lib/browser/common/decorators/autoInjectable.js.map +0 -1
- package/lib/browser/common/decorators/configuration.js +0 -24
- package/lib/browser/common/decorators/configuration.js.map +0 -1
- package/lib/browser/common/decorators/constant.js +0 -27
- package/lib/browser/common/decorators/constant.js.map +0 -1
- package/lib/browser/common/decorators/controller.js +0 -23
- package/lib/browser/common/decorators/controller.js.map +0 -1
- package/lib/browser/common/decorators/inject.js +0 -62
- package/lib/browser/common/decorators/inject.js.map +0 -1
- package/lib/browser/common/decorators/injectable.js +0 -14
- package/lib/browser/common/decorators/injectable.js.map +0 -1
- package/lib/browser/common/decorators/intercept.js +0 -57
- package/lib/browser/common/decorators/intercept.js.map +0 -1
- package/lib/browser/common/decorators/interceptor.js +0 -11
- package/lib/browser/common/decorators/interceptor.js.map +0 -1
- package/lib/browser/common/decorators/lazyInject.js +0 -43
- package/lib/browser/common/decorators/lazyInject.js.map +0 -1
- package/lib/browser/common/decorators/module.js +0 -22
- package/lib/browser/common/decorators/module.js.map +0 -1
- package/lib/browser/common/decorators/opts.js +0 -12
- package/lib/browser/common/decorators/opts.js.map +0 -1
- package/lib/browser/common/decorators/overrideProvider.js +0 -10
- package/lib/browser/common/decorators/overrideProvider.js.map +0 -1
- package/lib/browser/common/decorators/scope.js +0 -9
- package/lib/browser/common/decorators/scope.js.map +0 -1
- package/lib/browser/common/decorators/service.js +0 -8
- package/lib/browser/common/decorators/service.js.map +0 -1
- package/lib/browser/common/decorators/useOpts.js +0 -23
- package/lib/browser/common/decorators/useOpts.js.map +0 -1
- package/lib/browser/common/decorators/value.js +0 -23
- package/lib/browser/common/decorators/value.js.map +0 -1
- package/lib/browser/common/domain/Container.js +0 -64
- package/lib/browser/common/domain/Container.js.map +0 -1
- package/lib/browser/common/domain/ControllerProvider.js +0 -35
- package/lib/browser/common/domain/ControllerProvider.js.map +0 -1
- package/lib/browser/common/domain/InjectablePropertyType.js +0 -5
- package/lib/browser/common/domain/InjectablePropertyType.js.map +0 -1
- package/lib/browser/common/domain/LocalsContainer.js +0 -13
- package/lib/browser/common/domain/LocalsContainer.js.map +0 -1
- package/lib/browser/common/domain/Provider.js +0 -144
- package/lib/browser/common/domain/Provider.js.map +0 -1
- package/lib/browser/common/domain/ProviderScope.js +0 -5
- package/lib/browser/common/domain/ProviderScope.js.map +0 -1
- package/lib/browser/common/domain/ProviderType.js +0 -5
- package/lib/browser/common/domain/ProviderType.js.map +0 -1
- package/lib/browser/common/errors/InjectionError.js +0 -31
- package/lib/browser/common/errors/InjectionError.js.map +0 -1
- package/lib/browser/common/errors/InvalidPropertyTokenError.js +0 -17
- package/lib/browser/common/errors/InvalidPropertyTokenError.js.map +0 -1
- package/lib/browser/common/fn/configuration.js +0 -13
- package/lib/browser/common/fn/configuration.js.map +0 -1
- package/lib/browser/common/fn/constant.js +0 -8
- package/lib/browser/common/fn/constant.js.map +0 -1
- package/lib/browser/common/fn/inject.js +0 -13
- package/lib/browser/common/fn/inject.js.map +0 -1
- package/lib/browser/common/fn/injectMany.js +0 -9
- package/lib/browser/common/fn/injectMany.js.map +0 -1
- package/lib/browser/common/fn/injectable.js +0 -8
- package/lib/browser/common/fn/injectable.js.map +0 -1
- package/lib/browser/common/fn/injector.js +0 -13
- package/lib/browser/common/fn/injector.js.map +0 -1
- package/lib/browser/common/fn/lazyInject.js +0 -23
- package/lib/browser/common/fn/lazyInject.js.map +0 -1
- package/lib/browser/common/fn/localsContainer.js +0 -29
- package/lib/browser/common/fn/localsContainer.js.map +0 -1
- package/lib/browser/common/fn/logger.js +0 -8
- package/lib/browser/common/fn/logger.js.map +0 -1
- package/lib/browser/common/fn/refValue.js +0 -15
- package/lib/browser/common/fn/refValue.js.map +0 -1
- package/lib/browser/common/index.js +0 -115
- package/lib/browser/common/index.js.map +0 -1
- package/lib/browser/common/registries/GlobalProviders.js +0 -102
- package/lib/browser/common/registries/GlobalProviders.js.map +0 -1
- package/lib/browser/common/registries/ProviderRegistry.js +0 -8
- package/lib/browser/common/registries/ProviderRegistry.js.map +0 -1
- package/lib/browser/common/services/DIConfiguration.js +0 -99
- package/lib/browser/common/services/DIConfiguration.js.map +0 -1
- package/lib/browser/common/services/DILogger.js +0 -8
- package/lib/browser/common/services/DILogger.js.map +0 -1
- package/lib/browser/common/services/InjectorService.js +0 -378
- package/lib/browser/common/services/InjectorService.js.map +0 -1
- package/lib/browser/common/utils/colors.js +0 -5
- package/lib/browser/common/utils/colors.js.map +0 -1
- package/lib/browser/common/utils/createContainer.js +0 -10
- package/lib/browser/common/utils/createContainer.js.map +0 -1
- package/lib/browser/common/utils/discoverHooks.js +0 -17
- package/lib/browser/common/utils/discoverHooks.js.map +0 -1
- package/lib/browser/common/utils/getConfiguration.js +0 -20
- package/lib/browser/common/utils/getConfiguration.js.map +0 -1
- package/lib/browser/common/utils/getConstructorDependencies.js +0 -12
- package/lib/browser/common/utils/getConstructorDependencies.js.map +0 -1
- package/lib/browser/common/utils/providerBuilder.js +0 -8
- package/lib/browser/common/utils/providerBuilder.js.map +0 -1
- package/lib/esm/common/constants/constants.js.map +0 -1
- package/lib/esm/common/decorators/autoInjectable.js.map +0 -1
- package/lib/esm/common/decorators/configuration.js.map +0 -1
- package/lib/esm/common/decorators/constant.js.map +0 -1
- package/lib/esm/common/decorators/controller.js.map +0 -1
- package/lib/esm/common/decorators/inject.js.map +0 -1
- package/lib/esm/common/decorators/injectable.js.map +0 -1
- package/lib/esm/common/decorators/intercept.js.map +0 -1
- package/lib/esm/common/decorators/interceptor.js.map +0 -1
- package/lib/esm/common/decorators/lazyInject.js.map +0 -1
- package/lib/esm/common/decorators/module.js.map +0 -1
- package/lib/esm/common/decorators/opts.js.map +0 -1
- package/lib/esm/common/decorators/overrideProvider.js.map +0 -1
- package/lib/esm/common/decorators/scope.js.map +0 -1
- package/lib/esm/common/decorators/service.js.map +0 -1
- package/lib/esm/common/decorators/useOpts.js.map +0 -1
- package/lib/esm/common/decorators/value.js.map +0 -1
- package/lib/esm/common/domain/Container.js.map +0 -1
- package/lib/esm/common/domain/ControllerProvider.js.map +0 -1
- package/lib/esm/common/domain/InjectablePropertyType.js.map +0 -1
- package/lib/esm/common/domain/LocalsContainer.js.map +0 -1
- package/lib/esm/common/domain/Provider.js.map +0 -1
- package/lib/esm/common/domain/ProviderScope.js.map +0 -1
- package/lib/esm/common/domain/ProviderType.js.map +0 -1
- package/lib/esm/common/errors/InjectionError.js.map +0 -1
- package/lib/esm/common/errors/InvalidPropertyTokenError.js.map +0 -1
- package/lib/esm/common/fn/configuration.js.map +0 -1
- package/lib/esm/common/fn/constant.js.map +0 -1
- package/lib/esm/common/fn/inject.js.map +0 -1
- package/lib/esm/common/fn/injectMany.js.map +0 -1
- package/lib/esm/common/fn/injectable.js.map +0 -1
- package/lib/esm/common/fn/injector.js.map +0 -1
- package/lib/esm/common/fn/lazyInject.js.map +0 -1
- package/lib/esm/common/fn/localsContainer.js.map +0 -1
- package/lib/esm/common/fn/logger.js.map +0 -1
- package/lib/esm/common/fn/refValue.js.map +0 -1
- package/lib/esm/common/index.js.map +0 -1
- package/lib/esm/common/interfaces/DIConfigurationOptions.js.map +0 -1
- package/lib/esm/common/interfaces/DILogger.js.map +0 -1
- package/lib/esm/common/interfaces/DILoggerOptions.js.map +0 -1
- package/lib/esm/common/interfaces/ImportTokenProviderOpts.js.map +0 -1
- package/lib/esm/common/interfaces/InterceptorContext.js.map +0 -1
- package/lib/esm/common/interfaces/InterceptorMethods.js.map +0 -1
- package/lib/esm/common/interfaces/InvokeOptions.js.map +0 -1
- package/lib/esm/common/interfaces/OnDestroy.js.map +0 -1
- package/lib/esm/common/interfaces/OnInit.js.map +0 -1
- package/lib/esm/common/interfaces/ProviderOpts.js.map +0 -1
- package/lib/esm/common/interfaces/RegistrySettings.js.map +0 -1
- package/lib/esm/common/interfaces/ResolvedInvokeOptions.js.map +0 -1
- package/lib/esm/common/interfaces/TokenProvider.js.map +0 -1
- package/lib/esm/common/interfaces/TokenRoute.js.map +0 -1
- package/lib/esm/common/registries/GlobalProviders.js.map +0 -1
- package/lib/esm/common/registries/ProviderRegistry.js.map +0 -1
- package/lib/esm/common/services/DIConfiguration.js.map +0 -1
- package/lib/esm/common/services/DILogger.js.map +0 -1
- package/lib/esm/common/services/InjectorService.js.map +0 -1
- package/lib/esm/common/utils/colors.js.map +0 -1
- package/lib/esm/common/utils/createContainer.js.map +0 -1
- package/lib/esm/common/utils/discoverHooks.js.map +0 -1
- package/lib/esm/common/utils/getConfiguration.js.map +0 -1
- package/lib/esm/common/utils/getConstructorDependencies.js.map +0 -1
- package/lib/esm/common/utils/providerBuilder.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/node/decorators/injectContext.js.map +0 -1
- package/lib/esm/node/domain/ContextLogger.js.map +0 -1
- package/lib/esm/node/domain/DIContext.js.map +0 -1
- package/lib/esm/node/fn/context.js.map +0 -1
- package/lib/esm/node/fn/contextLogger.js.map +0 -1
- package/lib/esm/node/index.js.map +0 -1
- package/lib/esm/node/interfaces/AlterRunInContext.js.map +0 -1
- package/lib/esm/node/services/DILogger.js.map +0 -1
- package/lib/esm/node/services/DITest.js.map +0 -1
- package/lib/esm/node/utils/asyncHookContext.js.map +0 -1
- package/lib/esm/node/utils/attachLogger.js.map +0 -1
- package/lib/esm/node/utils/setLoggerConfiguration.js.map +0 -1
- package/lib/esm/node/utils/setLoggerFormat.js.map +0 -1
- package/lib/esm/node/utils/setLoggerLevel.js.map +0 -1
- package/src/common/constants/constants.ts +0 -5
- package/src/common/decorators/autoInjectable.spec.ts +0 -135
- package/src/common/decorators/autoInjectable.ts +0 -60
- package/src/common/decorators/configuration.spec.ts +0 -45
- package/src/common/decorators/configuration.ts +0 -36
- package/src/common/decorators/constant.spec.ts +0 -67
- package/src/common/decorators/constant.ts +0 -73
- package/src/common/decorators/controller.spec.ts +0 -43
- package/src/common/decorators/controller.ts +0 -73
- package/src/common/decorators/inject.spec.ts +0 -298
- package/src/common/decorators/inject.ts +0 -150
- package/src/common/decorators/injectable.spec.ts +0 -43
- package/src/common/decorators/injectable.ts +0 -30
- package/src/common/decorators/intercept.spec.ts +0 -150
- package/src/common/decorators/intercept.ts +0 -89
- package/src/common/decorators/interceptor.ts +0 -17
- package/src/common/decorators/lazyInject.spec.ts +0 -53
- package/src/common/decorators/lazyInject.ts +0 -92
- package/src/common/decorators/module.ts +0 -52
- package/src/common/decorators/opts.ts +0 -51
- package/src/common/decorators/overrideProvider.spec.ts +0 -30
- package/src/common/decorators/overrideProvider.ts +0 -15
- package/src/common/decorators/scope.spec.ts +0 -25
- package/src/common/decorators/scope.ts +0 -13
- package/src/common/decorators/service.ts +0 -14
- package/src/common/decorators/useOpts.spec.ts +0 -90
- package/src/common/decorators/useOpts.ts +0 -64
- package/src/common/decorators/value.spec.ts +0 -59
- package/src/common/decorators/value.ts +0 -60
- package/src/common/domain/Container.spec.ts +0 -85
- package/src/common/domain/Container.ts +0 -80
- package/src/common/domain/ControllerProvider.spec.ts +0 -55
- package/src/common/domain/ControllerProvider.ts +0 -48
- package/src/common/domain/InjectablePropertyType.ts +0 -7
- package/src/common/domain/LocalsContainer.spec.ts +0 -20
- package/src/common/domain/LocalsContainer.ts +0 -11
- package/src/common/domain/Provider.spec.ts +0 -107
- package/src/common/domain/Provider.ts +0 -218
- package/src/common/domain/ProviderScope.ts +0 -5
- package/src/common/domain/ProviderType.ts +0 -8
- package/src/common/errors/InjectionError.spec.ts +0 -17
- package/src/common/errors/InjectionError.ts +0 -71
- package/src/common/errors/InvalidPropertyTokenError.ts +0 -14
- package/src/common/fn/configuration.spec.ts +0 -42
- package/src/common/fn/configuration.ts +0 -22
- package/src/common/fn/constant.spec.ts +0 -37
- package/src/common/fn/constant.ts +0 -7
- package/src/common/fn/inject.spec.ts +0 -54
- package/src/common/fn/inject.ts +0 -32
- package/src/common/fn/injectMany.ts +0 -16
- package/src/common/fn/injectable.spec.ts +0 -88
- package/src/common/fn/injectable.ts +0 -15
- package/src/common/fn/injector.ts +0 -26
- package/src/common/fn/lazyInject.spec.ts +0 -22
- package/src/common/fn/lazyInject.ts +0 -36
- package/src/common/fn/localsContainer.ts +0 -55
- package/src/common/fn/logger.ts +0 -8
- package/src/common/fn/refValue.spec.ts +0 -47
- package/src/common/fn/refValue.ts +0 -33
- package/src/common/index.ts +0 -64
- package/src/common/integration/async-factory.spec.ts +0 -60
- package/src/common/integration/di.spec.ts +0 -153
- package/src/common/integration/imports.spec.ts +0 -39
- package/src/common/integration/request.spec.ts +0 -79
- package/src/common/integration/singleton.spec.ts +0 -125
- package/src/common/interfaces/DIConfigurationOptions.ts +0 -29
- package/src/common/interfaces/DILogger.ts +0 -13
- package/src/common/interfaces/DILoggerOptions.ts +0 -54
- package/src/common/interfaces/ImportTokenProviderOpts.ts +0 -29
- package/src/common/interfaces/InterceptorContext.ts +0 -13
- package/src/common/interfaces/InterceptorMethods.ts +0 -5
- package/src/common/interfaces/InvokeOptions.ts +0 -28
- package/src/common/interfaces/OnDestroy.ts +0 -3
- package/src/common/interfaces/OnInit.ts +0 -3
- package/src/common/interfaces/ProviderOpts.ts +0 -57
- package/src/common/interfaces/RegistrySettings.ts +0 -11
- package/src/common/interfaces/ResolvedInvokeOptions.ts +0 -14
- package/src/common/interfaces/TokenProvider.ts +0 -8
- package/src/common/interfaces/TokenRoute.ts +0 -6
- package/src/common/registries/GlobalProviders.spec.ts +0 -94
- package/src/common/registries/GlobalProviders.ts +0 -132
- package/src/common/registries/ProviderRegistry.spec.ts +0 -36
- package/src/common/registries/ProviderRegistry.ts +0 -32
- package/src/common/services/DIConfiguration.spec.ts +0 -60
- package/src/common/services/DIConfiguration.ts +0 -142
- package/src/common/services/DILogger.spec.ts +0 -22
- package/src/common/services/DILogger.ts +0 -8
- package/src/common/services/InjectorService.spec.ts +0 -793
- package/src/common/services/InjectorService.ts +0 -612
- package/src/common/utils/colors.spec.ts +0 -9
- package/src/common/utils/colors.ts +0 -11
- package/src/common/utils/createContainer.spec.ts +0 -18
- package/src/common/utils/createContainer.ts +0 -14
- package/src/common/utils/discoverHooks.ts +0 -16
- package/src/common/utils/getConfiguration.spec.ts +0 -40
- package/src/common/utils/getConfiguration.ts +0 -21
- package/src/common/utils/getConstructorDependencies.ts +0 -9
- package/src/common/utils/providerBuilder.ts +0 -95
- package/src/index.ts +0 -2
- package/src/node/decorators/injectContext.spec.ts +0 -60
- package/src/node/decorators/injectContext.ts +0 -29
- package/src/node/domain/ContextLogger.spec.ts +0 -400
- package/src/node/domain/ContextLogger.ts +0 -155
- package/src/node/domain/DIContext.spec.ts +0 -105
- package/src/node/domain/DIContext.ts +0 -115
- package/src/node/fn/context.ts +0 -24
- package/src/node/fn/contextLogger.spec.ts +0 -47
- package/src/node/fn/contextLogger.ts +0 -9
- package/src/node/index.ts +0 -16
- package/src/node/integration/async-factory-invoke.spec.ts +0 -58
- package/src/node/integration/inject-context.spec.ts +0 -29
- package/src/node/integration/invoke-oninit.spec.ts +0 -25
- package/src/node/interfaces/AlterRunInContext.ts +0 -3
- package/src/node/services/DILogger.spec.ts +0 -24
- package/src/node/services/DILogger.ts +0 -6
- package/src/node/services/DITest.spec.ts +0 -109
- package/src/node/services/DITest.ts +0 -122
- package/src/node/utils/asyncHookContext.spec.ts +0 -147
- package/src/node/utils/asyncHookContext.ts +0 -48
- package/src/node/utils/attachLogger.spec.ts +0 -14
- package/src/node/utils/attachLogger.ts +0 -7
- package/src/node/utils/setLoggerConfiguration.spec.ts +0 -43
- package/src/node/utils/setLoggerConfiguration.ts +0 -7
- package/src/node/utils/setLoggerFormat.ts +0 -33
- package/src/node/utils/setLoggerLevel.ts +0 -12
- package/vite.config.mts +0 -45
- package/vitest.config.mts +0 -21
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import {Hooks} from "@tsed/hooks";
|
|
2
|
-
import {levels, LogLevel} from "@tsed/logger";
|
|
3
|
-
|
|
4
|
-
import {DILogger, logger as injectLogger} from "../../common/index.js";
|
|
5
|
-
|
|
6
|
-
export interface ContextLoggerOptions extends Record<string, any> {
|
|
7
|
-
id: string;
|
|
8
|
-
logger?: DILogger;
|
|
9
|
-
level?: "debug" | "info" | "warn" | "error" | "off" | "all";
|
|
10
|
-
maxStackSize?: number;
|
|
11
|
-
additionalProps?: Record<any, any>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const LEVELS: Record<string, LogLevel> = levels();
|
|
15
|
-
|
|
16
|
-
export class ContextLogger {
|
|
17
|
-
readonly dateStart: Date;
|
|
18
|
-
readonly id: string;
|
|
19
|
-
readonly #additionalProps?: Record<string, unknown>;
|
|
20
|
-
|
|
21
|
-
maxStackSize: number;
|
|
22
|
-
#level: LogLevel;
|
|
23
|
-
#hooks?: Hooks;
|
|
24
|
-
#stack?: any[];
|
|
25
|
-
#logger: any;
|
|
26
|
-
|
|
27
|
-
constructor({id, logger, dateStart = new Date(), level, maxStackSize = 30, additionalProps}: ContextLoggerOptions) {
|
|
28
|
-
this.dateStart = dateStart;
|
|
29
|
-
this.id = id;
|
|
30
|
-
this.#logger = logger || injectLogger();
|
|
31
|
-
this.#additionalProps = additionalProps;
|
|
32
|
-
|
|
33
|
-
this.level = (LEVELS[(level || this.#logger.level || "").toUpperCase()] || LEVELS.ALL) as LogLevel;
|
|
34
|
-
|
|
35
|
-
this.maxStackSize = maxStackSize;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
set level(level: "debug" | "info" | "warn" | "error" | "off" | "all" | LogLevel) {
|
|
39
|
-
if (typeof level === "string") {
|
|
40
|
-
this.#level = LEVELS[level.toUpperCase()];
|
|
41
|
-
} else {
|
|
42
|
-
this.#level = level;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get level() {
|
|
47
|
-
return this.#level;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get hooks() {
|
|
51
|
-
return (this.#hooks = this.#hooks || new Hooks());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private get stack() {
|
|
55
|
-
return (this.#stack = this.#stack || []);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "all", withRequest: boolean) => any) {
|
|
59
|
-
return this.hooks.on("log", cb);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean) {
|
|
63
|
-
return this.hooks.on("ignore", cb);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
info(obj: any) {
|
|
67
|
-
this.run(levels().INFO, obj);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
debug(obj: any) {
|
|
72
|
-
this.run(levels().DEBUG, obj);
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
warn(obj: any) {
|
|
77
|
-
this.run(levels().WARN, obj);
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
error(obj: any) {
|
|
82
|
-
this.run(levels().ERROR, obj);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
fatal(obj: any) {
|
|
87
|
-
this.run(levels().FATAL, obj);
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
trace(obj: any) {
|
|
92
|
-
this.run(levels().TRACE, obj);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public flush(stream = false) {
|
|
97
|
-
if (this.stack.length) {
|
|
98
|
-
const level = this.#logger.level;
|
|
99
|
-
|
|
100
|
-
this.#logger.level = this.#level.levelStr.toLowerCase();
|
|
101
|
-
|
|
102
|
-
this.stack.forEach(({level, data}: any) => {
|
|
103
|
-
this.#logger[level](data);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
this.#logger.level = level;
|
|
107
|
-
|
|
108
|
-
this.#stack = [];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (stream) {
|
|
112
|
-
this.maxStackSize = 0;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public isLevelEnabled(otherLevel: string | LogLevel) {
|
|
117
|
-
return this.#level.isLessThanOrEqualTo(otherLevel);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
122
|
-
* @returns {number}
|
|
123
|
-
*/
|
|
124
|
-
protected getDuration(): number {
|
|
125
|
-
return new Date().getTime() - this.dateStart.getTime();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
protected getData(obj: any) {
|
|
129
|
-
if (typeof obj === "string") {
|
|
130
|
-
obj = {message: obj};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return {...this.#additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
protected run(level: LogLevel, obj: any, withRequest?: boolean) {
|
|
137
|
-
if (!this.isLevelEnabled(level)) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const ignore = this.#hooks?.alter("ignore", false, [obj]);
|
|
142
|
-
|
|
143
|
-
if (!ignore) {
|
|
144
|
-
const levelStr = level.levelStr.toLowerCase();
|
|
145
|
-
|
|
146
|
-
obj = this.hooks.alter("log", this.getData(obj), [levelStr, withRequest]);
|
|
147
|
-
|
|
148
|
-
this.stack.push({level: levelStr, data: obj});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (this.maxStackSize < this.stack.length || [levels().FATAL, levels().ERROR].includes(level)) {
|
|
152
|
-
this.flush();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {logger} from "../../common/fn/logger.js";
|
|
2
|
-
import {DITest} from "../services/DITest.js";
|
|
3
|
-
import {DIContext} from "./DIContext.js";
|
|
4
|
-
|
|
5
|
-
describe("DIContext", () => {
|
|
6
|
-
beforeEach(() => DITest.create());
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
vi.spyOn(logger(), "info").mockReturnValue(undefined);
|
|
9
|
-
});
|
|
10
|
-
afterEach(() => DITest.reset());
|
|
11
|
-
describe("constructor", () => {
|
|
12
|
-
it("should create a new Context and skip log", () => {
|
|
13
|
-
const context = new DIContext({
|
|
14
|
-
event: {
|
|
15
|
-
response: {},
|
|
16
|
-
request: {
|
|
17
|
-
url: "/admin"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
id: "id",
|
|
21
|
-
maxStackSize: 0
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
expect(context.id).toEqual("id");
|
|
25
|
-
expect(context.dateStart).toBeInstanceOf(Date);
|
|
26
|
-
expect(context.container).toBeInstanceOf(Map);
|
|
27
|
-
expect(context.env).toEqual("test");
|
|
28
|
-
expect(context.PLATFORM).toEqual("DI");
|
|
29
|
-
|
|
30
|
-
context.logger.level = "info";
|
|
31
|
-
context.logger.info("test");
|
|
32
|
-
|
|
33
|
-
expect(logger().info).toHaveBeenCalled();
|
|
34
|
-
|
|
35
|
-
context.destroy();
|
|
36
|
-
});
|
|
37
|
-
it("should create a new Context and log event", () => {
|
|
38
|
-
const context = new DIContext({
|
|
39
|
-
id: "id",
|
|
40
|
-
event: {
|
|
41
|
-
response: {},
|
|
42
|
-
request: {url: "/"}
|
|
43
|
-
},
|
|
44
|
-
maxStackSize: 0,
|
|
45
|
-
platform: "OTHER"
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
context.next = vi.fn();
|
|
49
|
-
|
|
50
|
-
expect(context.id).toEqual("id");
|
|
51
|
-
expect(context.dateStart).toBeInstanceOf(Date);
|
|
52
|
-
expect(context.container).toBeInstanceOf(Map);
|
|
53
|
-
expect(context.env).toEqual("test");
|
|
54
|
-
expect(context.PLATFORM).toEqual("OTHER");
|
|
55
|
-
|
|
56
|
-
context.next();
|
|
57
|
-
context.logger.level = "info";
|
|
58
|
-
context.logger.info("test");
|
|
59
|
-
|
|
60
|
-
expect(logger().info).toHaveBeenCalled();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("cache()", () => {
|
|
65
|
-
it("should cache data", () => {
|
|
66
|
-
const context = new DIContext({
|
|
67
|
-
event: {
|
|
68
|
-
response: {},
|
|
69
|
-
request: {url: "/admin"}
|
|
70
|
-
},
|
|
71
|
-
id: "id",
|
|
72
|
-
maxStackSize: 0,
|
|
73
|
-
ignoreUrlPatterns: ["/admin", /\/admin2/]
|
|
74
|
-
});
|
|
75
|
-
const resolver = vi.fn().mockReturnValue("test");
|
|
76
|
-
|
|
77
|
-
const result = context.cache("key", resolver);
|
|
78
|
-
const result2 = context.cache("key", resolver);
|
|
79
|
-
|
|
80
|
-
expect(result).toEqual(result2);
|
|
81
|
-
expect(resolver).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(context.delete("key")).toEqual(true);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe("cacheAsync()", () => {
|
|
86
|
-
it("should cache data", async () => {
|
|
87
|
-
const context = new DIContext({
|
|
88
|
-
event: {
|
|
89
|
-
response: {},
|
|
90
|
-
request: {url: "/admin"}
|
|
91
|
-
},
|
|
92
|
-
id: "id",
|
|
93
|
-
maxStackSize: 0,
|
|
94
|
-
ignoreUrlPatterns: ["/admin", /\/admin2/]
|
|
95
|
-
});
|
|
96
|
-
const resolver = vi.fn().mockResolvedValue("test");
|
|
97
|
-
|
|
98
|
-
const result = await context.cacheAsync("key", resolver);
|
|
99
|
-
const result2 = await context.cacheAsync("key", resolver);
|
|
100
|
-
|
|
101
|
-
expect(result).toEqual(result2);
|
|
102
|
-
expect(resolver).toHaveBeenCalledTimes(1);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {injector, InjectorService, LocalsContainer} from "../../common/index.js";
|
|
2
|
-
import {ContextLogger, ContextLoggerOptions} from "./ContextLogger.js";
|
|
3
|
-
|
|
4
|
-
export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
|
|
5
|
-
id: string;
|
|
6
|
-
platform?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class DIContext {
|
|
10
|
-
[x: string]: any;
|
|
11
|
-
|
|
12
|
-
readonly PLATFORM: string = "DI";
|
|
13
|
-
#container?: LocalsContainer;
|
|
14
|
-
#cache?: Map<any, any>;
|
|
15
|
-
#logger?: ContextLogger;
|
|
16
|
-
|
|
17
|
-
constructor(public opts: DIContextOptions) {
|
|
18
|
-
this.PLATFORM = opts.platform || this.PLATFORM;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Logger attached to the context request.
|
|
23
|
-
*/
|
|
24
|
-
get logger() {
|
|
25
|
-
this.#logger = this.#logger || new ContextLogger(this.opts);
|
|
26
|
-
return this.#logger;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Request id generated by @@contextMiddleware@@.
|
|
31
|
-
*
|
|
32
|
-
* ::: tip
|
|
33
|
-
* By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`.
|
|
34
|
-
* Dash are removed to simplify tracking logs in Kibana
|
|
35
|
-
* :::
|
|
36
|
-
*
|
|
37
|
-
* ::: tip
|
|
38
|
-
* Request id can by customized by changing the server configuration.
|
|
39
|
-
*
|
|
40
|
-
* ```typescript
|
|
41
|
-
* @Configuration({
|
|
42
|
-
* logger: {
|
|
43
|
-
* reqIdBuilder: createUniqId // give your own id generator function
|
|
44
|
-
* }
|
|
45
|
-
* })
|
|
46
|
-
* class Server {
|
|
47
|
-
*
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
* :::
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
get id() {
|
|
54
|
-
return this.opts.id;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get dateStart() {
|
|
58
|
-
return this.logger.dateStart;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get injector(): InjectorService {
|
|
62
|
-
return injector();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get env() {
|
|
66
|
-
return this.injector.settings.get("env");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
71
|
-
*/
|
|
72
|
-
get container() {
|
|
73
|
-
return (this.#container = this.#container || new LocalsContainer());
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
destroy(): Promise<any> {
|
|
77
|
-
return Promise.all([this.#container?.destroy(), this.#logger?.flush(true)]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
cache<Value = any>(key: string, cb: () => Value): Value {
|
|
81
|
-
if (!this.has(key)) {
|
|
82
|
-
this.set(key, cb());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this.get(key);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value> {
|
|
89
|
-
if (!this.has(key)) {
|
|
90
|
-
this.set(key, await cb());
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return this.get(key);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
delete(key: any): boolean {
|
|
97
|
-
return !!this.#cache?.delete(key);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get<T = any>(key: any): T {
|
|
101
|
-
return this.#cache?.get(key);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
has(key: any): boolean {
|
|
105
|
-
return !!this.#cache?.has(key);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
set(key: any, value: any): this {
|
|
109
|
-
this.#cache = this.#cache || new Map<any, any>();
|
|
110
|
-
this.#cache.set(key, value);
|
|
111
|
-
return this;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export type BaseContext = DIContext & TsED.Context;
|
package/src/node/fn/context.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {v4} from "uuid";
|
|
2
|
-
|
|
3
|
-
import {injector} from "../../common/index.js";
|
|
4
|
-
import {DIContext} from "../domain/DIContext.js";
|
|
5
|
-
import {getContext} from "../utils/asyncHookContext.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get the current DIContext instance using async hook node.js api.
|
|
9
|
-
*
|
|
10
|
-
* ::: warning
|
|
11
|
-
* This function isn't available in the browser context.
|
|
12
|
-
* :::
|
|
13
|
-
*/
|
|
14
|
-
export function context<Ctx = DIContext>(): Ctx {
|
|
15
|
-
return (
|
|
16
|
-
getContext<Ctx>() ||
|
|
17
|
-
(new DIContext({
|
|
18
|
-
id: v4(),
|
|
19
|
-
logger: injector().logger,
|
|
20
|
-
injector: injector(),
|
|
21
|
-
maxStackSize: 0
|
|
22
|
-
}) as Ctx)
|
|
23
|
-
);
|
|
24
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {Logger} from "@tsed/logger";
|
|
2
|
-
import {beforeEach} from "vitest";
|
|
3
|
-
|
|
4
|
-
import {logger} from "../../common/fn/logger.js";
|
|
5
|
-
import {inject, Injectable} from "../../common/index.js";
|
|
6
|
-
import {ContextLogger} from "../domain/ContextLogger.js";
|
|
7
|
-
import {context} from "../fn/context.js";
|
|
8
|
-
import {DITest} from "../services/DITest.js";
|
|
9
|
-
import {runInContext} from "../utils/asyncHookContext.js";
|
|
10
|
-
import {contextLogger} from "./contextLogger.js";
|
|
11
|
-
|
|
12
|
-
describe("DILogger", () => {
|
|
13
|
-
beforeEach(() => DITest.create());
|
|
14
|
-
afterEach(() => DITest.reset());
|
|
15
|
-
|
|
16
|
-
it("should inject logger in another service (decorator less)", async () => {
|
|
17
|
-
@Injectable()
|
|
18
|
-
class MyService {
|
|
19
|
-
logger = logger();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const service = inject(MyService, {rebuild: true});
|
|
23
|
-
|
|
24
|
-
expect(service.logger).toBeInstanceOf(Logger);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should inject context logger in another service", async () => {
|
|
28
|
-
@Injectable()
|
|
29
|
-
class MyService {
|
|
30
|
-
get logger() {
|
|
31
|
-
return contextLogger();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const service = inject(MyService, {rebuild: true});
|
|
36
|
-
|
|
37
|
-
expect(service.logger).toBeInstanceOf(ContextLogger);
|
|
38
|
-
|
|
39
|
-
const $ctx = context();
|
|
40
|
-
|
|
41
|
-
await runInContext($ctx, () => {
|
|
42
|
-
expect(service.logger).toEqual(context().logger);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(service.logger).not.toEqual(context().logger);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {context} from "./context.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the current logger instance. If the logger() function is invoked in Request context, it will return the logger instance attached to the request context.
|
|
5
|
-
* Otherwise, it will return the logger instance attached to the DI context.
|
|
6
|
-
*/
|
|
7
|
-
export function contextLogger() {
|
|
8
|
-
return context().logger;
|
|
9
|
-
}
|
package/src/node/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by @tsed/barrels.
|
|
3
|
-
*/
|
|
4
|
-
export * from "./decorators/injectContext.js";
|
|
5
|
-
export * from "./domain/ContextLogger.js";
|
|
6
|
-
export * from "./domain/DIContext.js";
|
|
7
|
-
export * from "./fn/context.js";
|
|
8
|
-
export * from "./fn/contextLogger.js";
|
|
9
|
-
export * from "./interfaces/AlterRunInContext.js";
|
|
10
|
-
export * from "./services/DILogger.js";
|
|
11
|
-
export * from "./services/DITest.js";
|
|
12
|
-
export * from "./utils/asyncHookContext.js";
|
|
13
|
-
export * from "./utils/attachLogger.js";
|
|
14
|
-
export * from "./utils/setLoggerConfiguration.js";
|
|
15
|
-
export * from "./utils/setLoggerFormat.js";
|
|
16
|
-
export * from "./utils/setLoggerLevel.js";
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {DITest, Inject, Injectable, registerProvider} from "../../index.js";
|
|
2
|
-
|
|
3
|
-
const PrimaryPostgresDb = Symbol.for("PrimaryPostgresDb");
|
|
4
|
-
type PrimaryPostgresDb = {id: string};
|
|
5
|
-
|
|
6
|
-
registerProvider({
|
|
7
|
-
token: PrimaryPostgresDb,
|
|
8
|
-
useAsyncFactory: () => {
|
|
9
|
-
return Promise.resolve({
|
|
10
|
-
id: "id"
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
@Injectable()
|
|
16
|
-
export class MyService {
|
|
17
|
-
@Inject(PrimaryPostgresDb)
|
|
18
|
-
protected dataSource: PrimaryPostgresDb;
|
|
19
|
-
|
|
20
|
-
me() {
|
|
21
|
-
return this.dataSource.id;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("AsyncFactory", () => {
|
|
26
|
-
beforeEach(() => DITest.create());
|
|
27
|
-
afterEach(() => DITest.reset());
|
|
28
|
-
|
|
29
|
-
it("should inject async factory and return resolve promise value (first test)", () => {
|
|
30
|
-
const service = DITest.get<MyService>(MyService);
|
|
31
|
-
|
|
32
|
-
const result = service.me();
|
|
33
|
-
|
|
34
|
-
expect(result).toEqual("id");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should inject async factory and return resolve promise value (second test)", () => {
|
|
38
|
-
const service = DITest.get<MyService>(MyService);
|
|
39
|
-
|
|
40
|
-
const result = service.me();
|
|
41
|
-
expect(result).toEqual("id");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should inject async factory and return resolve promise value (first test - invoke)", async () => {
|
|
45
|
-
const service = await DITest.invoke<MyService>(MyService, []);
|
|
46
|
-
|
|
47
|
-
const result = service.me();
|
|
48
|
-
|
|
49
|
-
expect(result).toEqual("id");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should inject async factory and return resolve promise value (second test - invoke)", async () => {
|
|
53
|
-
const service = await DITest.invoke<MyService>(MyService, []);
|
|
54
|
-
|
|
55
|
-
const result = service.me();
|
|
56
|
-
expect(result).toEqual("id");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {Injectable} from "../../common/index.js";
|
|
2
|
-
import {InjectContext} from "../decorators/injectContext.js";
|
|
3
|
-
import {DIContext} from "../domain/DIContext.js";
|
|
4
|
-
import {DITest} from "../services/DITest.js";
|
|
5
|
-
import {runInContext} from "../utils/asyncHookContext.js";
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
class MyService {
|
|
9
|
-
@InjectContext()
|
|
10
|
-
$ctx: DIContext;
|
|
11
|
-
|
|
12
|
-
get() {
|
|
13
|
-
return this.$ctx.id;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe("InjectContext", () => {
|
|
18
|
-
beforeEach(() => DITest.create());
|
|
19
|
-
afterEach(() => DITest.reset());
|
|
20
|
-
|
|
21
|
-
it("should inject context", async () => {
|
|
22
|
-
const ctx = DITest.createDIContext();
|
|
23
|
-
const service = DITest.get<MyService>(MyService);
|
|
24
|
-
|
|
25
|
-
const result = await runInContext(ctx, () => service.get());
|
|
26
|
-
|
|
27
|
-
expect(result).toEqual("id");
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {DITest, Inject, Injectable, registerProvider} from "../../index.js";
|
|
2
|
-
|
|
3
|
-
@Injectable()
|
|
4
|
-
export class MyService {
|
|
5
|
-
id = "id";
|
|
6
|
-
$onInit() {
|
|
7
|
-
return new Promise((resolve) =>
|
|
8
|
-
setTimeout(() => {
|
|
9
|
-
this.id = "id2";
|
|
10
|
-
resolve({});
|
|
11
|
-
}, 1)
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe("OnInit Invoke", () => {
|
|
17
|
-
beforeEach(() => DITest.create());
|
|
18
|
-
afterEach(() => DITest.reset());
|
|
19
|
-
|
|
20
|
-
it("should inject async factory and return resolve promise value", async () => {
|
|
21
|
-
const service = await DITest.invoke<MyService>(MyService, []);
|
|
22
|
-
|
|
23
|
-
expect(service.id).toEqual("id2");
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import "./DILogger.js";
|
|
2
|
-
|
|
3
|
-
import {Logger} from "@tsed/logger";
|
|
4
|
-
import {beforeEach} from "vitest";
|
|
5
|
-
|
|
6
|
-
import {Inject, inject, Injectable, injector} from "../../common/index.js";
|
|
7
|
-
import {DITest} from "./DITest.js";
|
|
8
|
-
|
|
9
|
-
describe("DILogger", () => {
|
|
10
|
-
beforeEach(() => DITest.create());
|
|
11
|
-
afterEach(() => DITest.reset());
|
|
12
|
-
|
|
13
|
-
it("should inject logger in another service", async () => {
|
|
14
|
-
@Injectable()
|
|
15
|
-
class MyService {
|
|
16
|
-
@Inject()
|
|
17
|
-
logger: Logger;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const service = inject(MyService, {rebuild: true});
|
|
21
|
-
|
|
22
|
-
expect(service.logger).toEqual(injector().logger);
|
|
23
|
-
});
|
|
24
|
-
});
|