@tsed/di 8.11.0 → 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,36 +0,0 @@
|
|
|
1
|
-
import {DecoratorParameters} from "@tsed/core/types/DecoratorParameters.js";
|
|
2
|
-
import {DecoratorTypes} from "@tsed/core/types/DecoratorTypes.js";
|
|
3
|
-
import {decoratorTypeOf} from "@tsed/core/utils/decoratorTypeOf.js";
|
|
4
|
-
|
|
5
|
-
import {configuration} from "../fn/configuration.js";
|
|
6
|
-
import {injectable} from "../fn/injectable.js";
|
|
7
|
-
import {injector} from "../fn/injector.js";
|
|
8
|
-
import {DIConfiguration} from "../services/DIConfiguration.js";
|
|
9
|
-
import {Inject} from "./inject.js";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get or set Configuration on a class.
|
|
13
|
-
*
|
|
14
|
-
* @decorator
|
|
15
|
-
*/
|
|
16
|
-
export function Configuration(): any;
|
|
17
|
-
export function Configuration(settings: Partial<TsED.Configuration>): ClassDecorator;
|
|
18
|
-
export function Configuration(settings: Partial<TsED.Configuration> = {}): Function {
|
|
19
|
-
return (...args: DecoratorParameters) => {
|
|
20
|
-
switch (decoratorTypeOf(args)) {
|
|
21
|
-
case DecoratorTypes.CLASS:
|
|
22
|
-
configuration(args[0], settings);
|
|
23
|
-
|
|
24
|
-
break;
|
|
25
|
-
default:
|
|
26
|
-
case DecoratorTypes.PARAM_CTOR:
|
|
27
|
-
return Inject(DIConfiguration)(args[0], args[1], args[2] as number);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type Configuration = TsED.DIConfiguration & DIConfiguration;
|
|
33
|
-
|
|
34
|
-
// To maintain compatibility with the previous implementation, we need to declare Configuration as
|
|
35
|
-
// injectable token.
|
|
36
|
-
injectable(Configuration).factory(() => injector().settings);
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {DITest} from "../../node/index.js";
|
|
2
|
-
import {Constant} from "./constant.js";
|
|
3
|
-
|
|
4
|
-
describe("@Constant()", () => {
|
|
5
|
-
beforeEach(() =>
|
|
6
|
-
DITest.create({
|
|
7
|
-
logger: {
|
|
8
|
-
level: "off"
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
);
|
|
12
|
-
afterEach(() => DITest.reset());
|
|
13
|
-
it("should create a getter", async () => {
|
|
14
|
-
// WHEN
|
|
15
|
-
class Test {
|
|
16
|
-
@Constant("logger.level", "default value")
|
|
17
|
-
test: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// THEN
|
|
21
|
-
|
|
22
|
-
const test = await DITest.invoke<Test>(Test);
|
|
23
|
-
|
|
24
|
-
expect(test.test).toEqual("off");
|
|
25
|
-
});
|
|
26
|
-
it("should create a getter with default value", async () => {
|
|
27
|
-
// WHEN
|
|
28
|
-
class Test {
|
|
29
|
-
@Constant("logger.test", "default value")
|
|
30
|
-
test: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// THEN
|
|
34
|
-
|
|
35
|
-
const test = await DITest.invoke<Test>(Test);
|
|
36
|
-
|
|
37
|
-
expect(test.test).toEqual("default value");
|
|
38
|
-
});
|
|
39
|
-
it("shouldn't be possible to modify injected value from injector.settings", async () => {
|
|
40
|
-
// WHEN
|
|
41
|
-
class Test {
|
|
42
|
-
@Constant("logger.level")
|
|
43
|
-
test: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// THEN
|
|
47
|
-
|
|
48
|
-
const test = await DITest.invoke<Test>(Test);
|
|
49
|
-
|
|
50
|
-
test.test = "new value";
|
|
51
|
-
|
|
52
|
-
expect(test.test).toEqual("off");
|
|
53
|
-
});
|
|
54
|
-
it("should create a getter with native default value", async () => {
|
|
55
|
-
// WHEN
|
|
56
|
-
class Test {
|
|
57
|
-
@Constant("logger.test")
|
|
58
|
-
test: string = "default prop";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// THEN
|
|
62
|
-
|
|
63
|
-
const test = await DITest.invoke<Test>(Test);
|
|
64
|
-
|
|
65
|
-
expect(test.test).toEqual("default prop");
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {catchError} from "@tsed/core/utils/catchError.js";
|
|
2
|
-
import {deepClone} from "@tsed/core/utils/deepClone.js";
|
|
3
|
-
|
|
4
|
-
import {constant} from "../fn/constant.js";
|
|
5
|
-
|
|
6
|
-
export function bindConstant(target: any, propertyKey: string | symbol, expression: string, defaultValue?: any) {
|
|
7
|
-
const symbol = Symbol();
|
|
8
|
-
|
|
9
|
-
catchError(() => Reflect.deleteProperty(target, propertyKey));
|
|
10
|
-
Reflect.defineProperty(target, propertyKey, {
|
|
11
|
-
get() {
|
|
12
|
-
if (this[symbol] !== undefined) {
|
|
13
|
-
return this[symbol];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const value = constant(expression, defaultValue);
|
|
17
|
-
|
|
18
|
-
this[symbol] = Object.freeze(deepClone(value));
|
|
19
|
-
|
|
20
|
-
return this[symbol];
|
|
21
|
-
},
|
|
22
|
-
set(value: unknown) {
|
|
23
|
-
const bean = constant(expression, defaultValue) || this[symbol];
|
|
24
|
-
|
|
25
|
-
if (bean === undefined && value !== undefined) {
|
|
26
|
-
this[symbol] = value;
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Return value from Configuration.
|
|
36
|
-
*
|
|
37
|
-
* ## Example
|
|
38
|
-
*
|
|
39
|
-
* ```typescript
|
|
40
|
-
* import {Env} from "@tsed/core/domain/Env.js";
|
|
41
|
-
* import {Constant, Value} from "@tsed/di";
|
|
42
|
-
*
|
|
43
|
-
* export class MyClass {
|
|
44
|
-
*
|
|
45
|
-
* @Constant("env")
|
|
46
|
-
* env: Env;
|
|
47
|
-
*
|
|
48
|
-
* @Value("swagger.path")
|
|
49
|
-
* swaggerPath: string;
|
|
50
|
-
*
|
|
51
|
-
* @Value("swagger.path", "defaultValue")
|
|
52
|
-
* swaggerPath: string;
|
|
53
|
-
*
|
|
54
|
-
* constructor() {
|
|
55
|
-
* console.log(this.swaggerPath) // undefined. Not available on constructor
|
|
56
|
-
* }
|
|
57
|
-
*
|
|
58
|
-
* $onInit() {
|
|
59
|
-
* console.log(this.swaggerPath) // something
|
|
60
|
-
* }
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @param {string} expression
|
|
65
|
-
* @param defaultValue
|
|
66
|
-
* @returns {(targetClass: any, attributeName: string) => any}
|
|
67
|
-
* @decorator
|
|
68
|
-
*/
|
|
69
|
-
export function Constant<Type = unknown>(expression: string, defaultValue?: Type): PropertyDecorator {
|
|
70
|
-
return (target, propertyKey) => {
|
|
71
|
-
return bindConstant(target, propertyKey, expression, defaultValue);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {ProviderScope} from "../domain/ProviderScope.js";
|
|
2
|
-
import {ProviderType} from "../domain/ProviderType.js";
|
|
3
|
-
import {GlobalProviders} from "../registries/GlobalProviders.js";
|
|
4
|
-
import {Controller} from "./controller.js";
|
|
5
|
-
|
|
6
|
-
class Test {}
|
|
7
|
-
|
|
8
|
-
class Dep {}
|
|
9
|
-
|
|
10
|
-
describe("@Controller", () => {
|
|
11
|
-
afterAll(() => {
|
|
12
|
-
GlobalProviders.delete(Test);
|
|
13
|
-
});
|
|
14
|
-
it("should register a controller with his path and Dependency", () => {
|
|
15
|
-
// WHEN
|
|
16
|
-
Controller("/test")(Test);
|
|
17
|
-
|
|
18
|
-
// THEN
|
|
19
|
-
const provider = GlobalProviders.get(Test)!;
|
|
20
|
-
|
|
21
|
-
// THEN
|
|
22
|
-
expect(provider.type).toEqual(ProviderType.CONTROLLER);
|
|
23
|
-
expect(provider.path).toEqual("/test");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should register a controller with customer provider options", () => {
|
|
27
|
-
// WHEN
|
|
28
|
-
Controller({
|
|
29
|
-
path: "/test",
|
|
30
|
-
children: [Dep],
|
|
31
|
-
scope: ProviderScope.REQUEST
|
|
32
|
-
})(Test);
|
|
33
|
-
|
|
34
|
-
// THEN
|
|
35
|
-
const provider = GlobalProviders.get(Test)!;
|
|
36
|
-
|
|
37
|
-
// THEN
|
|
38
|
-
expect(provider.type).toEqual(ProviderType.CONTROLLER);
|
|
39
|
-
expect(provider.scope).toEqual(ProviderScope.REQUEST);
|
|
40
|
-
expect(provider.path).toEqual("/test");
|
|
41
|
-
expect(provider.children).toEqual([Dep]);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core/types/Store.js";
|
|
2
|
-
import {Type} from "@tsed/core/types/Type.js";
|
|
3
|
-
import {classOf} from "@tsed/core/utils/classOf.js";
|
|
4
|
-
import {isArrayOrArrayClass} from "@tsed/core/utils/isArray.js";
|
|
5
|
-
import {useDecorators} from "@tsed/core/utils/useDecorators.js";
|
|
6
|
-
|
|
7
|
-
import type {ControllerMiddlewares} from "../domain/ControllerProvider.js";
|
|
8
|
-
import {controller} from "../fn/injectable.js";
|
|
9
|
-
import {ProviderOpts} from "../interfaces/ProviderOpts.js";
|
|
10
|
-
|
|
11
|
-
export type PathType = string | RegExp | (string | RegExp)[];
|
|
12
|
-
|
|
13
|
-
export interface ControllerOptions extends Partial<ProviderOpts<any>> {
|
|
14
|
-
path?: PathType;
|
|
15
|
-
children?: Type<any>[];
|
|
16
|
-
middlewares?: Partial<ControllerMiddlewares>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function mapOptions(options: any): ControllerOptions {
|
|
20
|
-
if (typeof options === "string" || options instanceof RegExp || isArrayOrArrayClass(options)) {
|
|
21
|
-
return {
|
|
22
|
-
path: options
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return options;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
|
|
31
|
-
* This routing listing will be built with the `express.Router` object.
|
|
32
|
-
*
|
|
33
|
-
* ::: tip
|
|
34
|
-
* See [Controllers](/docs/controllers.md) section for more details
|
|
35
|
-
* :::
|
|
36
|
-
*
|
|
37
|
-
* ```typescript
|
|
38
|
-
* @Controller("/calendars")
|
|
39
|
-
* export class CalendarCtrl {
|
|
40
|
-
*
|
|
41
|
-
* @Get("/:id")
|
|
42
|
-
* public get(
|
|
43
|
-
* @Req() request: Req,
|
|
44
|
-
* @Res() response: Res,
|
|
45
|
-
* @Next() next: Next
|
|
46
|
-
* ): void {
|
|
47
|
-
*
|
|
48
|
-
* }
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param options
|
|
53
|
-
* @controller
|
|
54
|
-
* @decorator
|
|
55
|
-
* @classDecorator
|
|
56
|
-
*/
|
|
57
|
-
export function Controller(options: PathType | ControllerOptions): ClassDecorator {
|
|
58
|
-
const {children = [], path, ...opts} = mapOptions(options);
|
|
59
|
-
|
|
60
|
-
return useDecorators((target: Type) => {
|
|
61
|
-
const factory = controller(target, opts);
|
|
62
|
-
|
|
63
|
-
if (path) {
|
|
64
|
-
factory.store().set("path", path);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
factory.store().set("childrenControllers", children);
|
|
68
|
-
|
|
69
|
-
children.forEach((childToken) => {
|
|
70
|
-
Store.from(childToken).set("parentController", classOf(target));
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import {catchAsyncError} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {DITest} from "../../node/index.js";
|
|
4
|
-
import {inject} from "../fn/inject.js";
|
|
5
|
-
import {injector} from "../fn/injector.js";
|
|
6
|
-
import {registerProvider} from "../registries/ProviderRegistry.js";
|
|
7
|
-
import {InjectorService} from "../services/InjectorService.js";
|
|
8
|
-
import {Inject} from "./inject.js";
|
|
9
|
-
import {Injectable} from "./injectable.js";
|
|
10
|
-
|
|
11
|
-
@Injectable()
|
|
12
|
-
class ProvidersList extends Map<string, string> {}
|
|
13
|
-
|
|
14
|
-
@Injectable()
|
|
15
|
-
class MyService {
|
|
16
|
-
@Inject(ProvidersList)
|
|
17
|
-
providersList: ProvidersList;
|
|
18
|
-
|
|
19
|
-
getValue() {
|
|
20
|
-
return this.providersList.get("key");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe("@Inject()", () => {
|
|
25
|
-
beforeEach(() => DITest.create());
|
|
26
|
-
afterEach(() => DITest.reset());
|
|
27
|
-
|
|
28
|
-
describe("when the decorator used on property", () => {
|
|
29
|
-
it("should inject service", async () => {
|
|
30
|
-
// GIVEN
|
|
31
|
-
@Injectable()
|
|
32
|
-
class Test {
|
|
33
|
-
@Inject()
|
|
34
|
-
test: InjectorService;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const instance = inject<Test>(Test);
|
|
38
|
-
|
|
39
|
-
expect(instance).toBeInstanceOf(Test);
|
|
40
|
-
expect(instance.test).toBeInstanceOf(InjectorService);
|
|
41
|
-
});
|
|
42
|
-
it("should inject service and async factory", async () => {
|
|
43
|
-
// GIVEN
|
|
44
|
-
class Test {
|
|
45
|
-
constructor(public type: string) {}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const TokenAsync = Symbol.for("MyService");
|
|
49
|
-
|
|
50
|
-
registerProvider<Test>({
|
|
51
|
-
token: TokenAsync,
|
|
52
|
-
type: "test:async",
|
|
53
|
-
deps: [],
|
|
54
|
-
useAsyncFactory() {
|
|
55
|
-
return Promise.resolve(new Test("async"));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
@Injectable()
|
|
60
|
-
class Parent1 {
|
|
61
|
-
@Inject(TokenAsync)
|
|
62
|
-
test: Test;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@Injectable()
|
|
66
|
-
class Parent2 {
|
|
67
|
-
@Inject(TokenAsync)
|
|
68
|
-
test: Test;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
await injector().load();
|
|
72
|
-
|
|
73
|
-
const parent1 = inject<Parent1>(Parent1);
|
|
74
|
-
const parent2 = inject<Parent2>(Parent2);
|
|
75
|
-
|
|
76
|
-
expect(parent1.test).toBeInstanceOf(Test);
|
|
77
|
-
expect(parent2.test).toBeInstanceOf(Test);
|
|
78
|
-
});
|
|
79
|
-
it("should inject service and use onGet option to transform injected service", async () => {
|
|
80
|
-
// GIVEN
|
|
81
|
-
@Injectable()
|
|
82
|
-
class Test {
|
|
83
|
-
@Inject(InjectorService, {transform: (instance) => instance.get(InjectorService)})
|
|
84
|
-
test: InjectorService;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const instance = inject(Test);
|
|
88
|
-
|
|
89
|
-
expect(instance).toBeInstanceOf(Test);
|
|
90
|
-
expect(instance.test).toBeInstanceOf(InjectorService);
|
|
91
|
-
});
|
|
92
|
-
it("should inject service and use onGet option to transform injected service (legacy)", async () => {
|
|
93
|
-
// GIVEN
|
|
94
|
-
@Injectable()
|
|
95
|
-
class Test {
|
|
96
|
-
@Inject(InjectorService, (instance) => instance.get(InjectorService))
|
|
97
|
-
test: InjectorService;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const instance = inject<Test>(Test);
|
|
101
|
-
|
|
102
|
-
expect(instance).toBeInstanceOf(Test);
|
|
103
|
-
expect(instance.test).toBeInstanceOf(InjectorService);
|
|
104
|
-
});
|
|
105
|
-
it("should inject many services", async () => {
|
|
106
|
-
const TOKEN_GROUPS = Symbol.for("groups:1");
|
|
107
|
-
|
|
108
|
-
interface InterfaceGroup {
|
|
109
|
-
type: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Injectable({
|
|
113
|
-
type: TOKEN_GROUPS
|
|
114
|
-
})
|
|
115
|
-
class MyService1 implements InterfaceGroup {
|
|
116
|
-
readonly type: string = "service1";
|
|
117
|
-
|
|
118
|
-
constructor(@Inject(InjectorService) readonly injector: any) {}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@Injectable({
|
|
122
|
-
type: TOKEN_GROUPS
|
|
123
|
-
})
|
|
124
|
-
class MyService2 implements InterfaceGroup {
|
|
125
|
-
readonly type: string = "service2";
|
|
126
|
-
|
|
127
|
-
constructor(@Inject(InjectorService) readonly injector: any) {}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const TokenAsync = Symbol.for("MyService2");
|
|
131
|
-
|
|
132
|
-
registerProvider({
|
|
133
|
-
token: TokenAsync,
|
|
134
|
-
type: TOKEN_GROUPS,
|
|
135
|
-
deps: [],
|
|
136
|
-
useAsyncFactory() {
|
|
137
|
-
return Promise.resolve({
|
|
138
|
-
type: "async"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
@Injectable()
|
|
144
|
-
class MyInjectable {
|
|
145
|
-
@Inject(TOKEN_GROUPS)
|
|
146
|
-
instances: InterfaceGroup[];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
await injector().load();
|
|
150
|
-
|
|
151
|
-
const instance = inject<MyInjectable>(MyInjectable);
|
|
152
|
-
|
|
153
|
-
expect(instance.instances).toBeInstanceOf(Array);
|
|
154
|
-
expect(instance.instances).toHaveLength(3);
|
|
155
|
-
expect(instance.instances[0].type).toEqual("service1");
|
|
156
|
-
expect(instance.instances[1].type).toEqual("service2");
|
|
157
|
-
expect(instance.instances[2].type).toEqual("async");
|
|
158
|
-
});
|
|
159
|
-
it("should throw error", () => {
|
|
160
|
-
try {
|
|
161
|
-
// GIVEN
|
|
162
|
-
@Injectable()
|
|
163
|
-
class Test {
|
|
164
|
-
@Inject()
|
|
165
|
-
test: Object;
|
|
166
|
-
}
|
|
167
|
-
} catch (er) {
|
|
168
|
-
expect(er.message).toContain("Object isn't a valid token. Please check the token set on Test.test");
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
it("should inject service and use mock", async () => {
|
|
172
|
-
@Injectable()
|
|
173
|
-
class Nested {
|
|
174
|
-
get cache() {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
@Injectable()
|
|
180
|
-
class Test {
|
|
181
|
-
@Inject()
|
|
182
|
-
nested: Nested;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const instance = await DITest.invoke(Test, [
|
|
186
|
-
{
|
|
187
|
-
token: Nested,
|
|
188
|
-
use: {
|
|
189
|
-
cache: false
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
]);
|
|
193
|
-
|
|
194
|
-
expect(instance.nested.cache).toEqual(false);
|
|
195
|
-
|
|
196
|
-
const instance2 = await DITest.invoke(Test, []);
|
|
197
|
-
expect(instance2.nested.cache).toEqual(true);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
describe("when the decorator is used on constructor parameter", () => {
|
|
201
|
-
describe("when token is given on constructor", () => {
|
|
202
|
-
it("should inject the expected provider", async () => {
|
|
203
|
-
@Injectable()
|
|
204
|
-
class MyInjectable {
|
|
205
|
-
constructor(@Inject(InjectorService) readonly injector: InjectorService) {}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const instance = inject(MyInjectable);
|
|
209
|
-
|
|
210
|
-
expect(instance.injector).toBeInstanceOf(InjectorService);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("when a group token is given on constructor", () => {
|
|
215
|
-
it("should inject the expected provider", async () => {
|
|
216
|
-
const TOKEN_GROUPS = Symbol.for("groups:2");
|
|
217
|
-
|
|
218
|
-
interface InterfaceGroup {
|
|
219
|
-
type: string;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
@Injectable({
|
|
223
|
-
type: TOKEN_GROUPS
|
|
224
|
-
})
|
|
225
|
-
class MyService1 implements InterfaceGroup {
|
|
226
|
-
readonly type: string = "service1";
|
|
227
|
-
|
|
228
|
-
constructor(@Inject(InjectorService) readonly injector: InjectorService) {}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
@Injectable({
|
|
232
|
-
type: TOKEN_GROUPS
|
|
233
|
-
})
|
|
234
|
-
class MyService2 implements InterfaceGroup {
|
|
235
|
-
readonly type: string = "service2";
|
|
236
|
-
|
|
237
|
-
constructor(@Inject(InjectorService) readonly injector: InjectorService) {}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const TokenAsync = Symbol.for("MyService1");
|
|
241
|
-
|
|
242
|
-
registerProvider({
|
|
243
|
-
token: TokenAsync,
|
|
244
|
-
type: TOKEN_GROUPS,
|
|
245
|
-
deps: [],
|
|
246
|
-
useAsyncFactory() {
|
|
247
|
-
return Promise.resolve({
|
|
248
|
-
type: "async"
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
@Injectable()
|
|
254
|
-
class MyInjectable {
|
|
255
|
-
constructor(@Inject(TOKEN_GROUPS) readonly instances: InterfaceGroup[]) {}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
await injector().load();
|
|
259
|
-
|
|
260
|
-
const instance = inject(MyInjectable);
|
|
261
|
-
|
|
262
|
-
expect(instance.instances).toBeInstanceOf(Array);
|
|
263
|
-
expect(instance.instances).toHaveLength(3);
|
|
264
|
-
expect(instance.instances[0].type).toEqual("service1");
|
|
265
|
-
expect(instance.instances[1].type).toEqual("service2");
|
|
266
|
-
expect(instance.instances[2].type).toEqual("async");
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
describe("when token is Object", () => {
|
|
271
|
-
it("should throw error", async () => {
|
|
272
|
-
class Test {
|
|
273
|
-
@Inject()
|
|
274
|
-
test: any;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const error = await catchAsyncError(async () => {
|
|
278
|
-
const instance = await DITest.invoke(Test);
|
|
279
|
-
|
|
280
|
-
return instance.test;
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
expect(error?.message).toContain("Object isn't a valid token. Please check the token set on Test.test");
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
it("should rebuild all dependencies using invoke", async () => {
|
|
287
|
-
const providersList = inject(ProvidersList);
|
|
288
|
-
const myService = inject(MyService);
|
|
289
|
-
providersList.set("key", "value");
|
|
290
|
-
|
|
291
|
-
expect(inject(ProvidersList).get("key")).toEqual("value");
|
|
292
|
-
expect(myService.getValue()).toEqual("value");
|
|
293
|
-
|
|
294
|
-
const newMyService = await DITest.invoke(MyService, []);
|
|
295
|
-
expect(newMyService.getValue()).toEqual(undefined);
|
|
296
|
-
expect(myService.getValue()).toEqual("value");
|
|
297
|
-
});
|
|
298
|
-
});
|