@nest-omni/core 2.0.1-0 → 2.0.1-10
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/{dist/decorators → decorators}/user.decorator.js +1 -1
- package/package.json +11 -4
- package/{dist/setup → setup}/bootstrap.setup.js +57 -22
- package/{dist/shared → shared}/serviceRegistryModule.js +11 -34
- package/tsconfig.tsbuildinfo +1 -0
- package/.history/src/common/boilerplate.polyfill_20250521135408.ts +0 -202
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +0 -291
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +0 -317
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +0 -319
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +0 -289
- package/README.md +0 -16
- package/build.sh +0 -45
- package/dist/package.json +0 -71
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/yarn.lock +0 -644
- package/src/.hygen.js +0 -116
- package/src/common/abstract-client.service.ts +0 -56
- package/src/common/abstract.entity.ts +0 -82
- package/src/common/boilerplate.polyfill.ts +0 -202
- package/src/common/dto/abstract.dto.ts +0 -61
- package/src/common/dto/bulk-id.dto.ts +0 -13
- package/src/common/dto/create-translation.dto.ts +0 -10
- package/src/common/dto/index.ts +0 -6
- package/src/common/dto/page-meta.dto.ts +0 -37
- package/src/common/dto/page-options.dto.ts +0 -35
- package/src/common/dto/page.dto.ts +0 -36
- package/src/common/index.ts +0 -7
- package/src/common/snake-naming.strategy.ts +0 -64
- package/src/common/types.ts +0 -44
- package/src/common/utils.ts +0 -45
- package/src/constants/index.ts +0 -2
- package/src/constants/language-code.ts +0 -7
- package/src/constants/order.ts +0 -4
- package/src/decorators/api-page-ok-response.decorator.ts +0 -32
- package/src/decorators/auth-user.decorator.ts +0 -16
- package/src/decorators/controller.decorator.ts +0 -8
- package/src/decorators/field.decorators.ts +0 -856
- package/src/decorators/http.decorators.ts +0 -10
- package/src/decorators/index.ts +0 -12
- package/src/decorators/operation.decorator.ts +0 -4
- package/src/decorators/property.decorators.ts +0 -62
- package/src/decorators/public-route.decorator.ts +0 -8
- package/src/decorators/swagger.schema.ts +0 -117
- package/src/decorators/timestamp-column.decorator.ts +0 -29
- package/src/decorators/transform.decorators.ts +0 -159
- package/src/decorators/translate.decorator.ts +0 -19
- package/src/decorators/use-dto.decorator.ts +0 -11
- package/src/decorators/user-check.decorator.ts +0 -30
- package/src/decorators/user.decorator.ts +0 -59
- package/src/decorators/user_auth.decorator.ts +0 -15
- package/src/decorators/validator.decorators.ts +0 -98
- package/src/exceptions/file-not-image.exception.ts +0 -7
- package/src/exceptions/index.ts +0 -2
- package/src/exceptions/page-type.exception.ts +0 -7
- package/src/exceptions/user-not-found.exception.ts +0 -7
- package/src/filters/bad-request.filter.ts +0 -77
- package/src/filters/constraint-errors.ts +0 -5
- package/src/filters/index.ts +0 -3
- package/src/filters/query-failed.filter.ts +0 -32
- package/src/health-checker/health-checker.controller.ts +0 -51
- package/src/health-checker/health-checker.module.ts +0 -13
- package/src/health-checker/health-indicators/service.indicator.ts +0 -44
- package/src/helpers/common.helper.ts +0 -49
- package/src/helpers/date.helper.ts +0 -64
- package/src/helpers/index.ts +0 -2
- package/src/i18n/en_US/validation.json +0 -41
- package/src/i18n/zh_CN/validation.json +0 -41
- package/src/index.ts +0 -11
- package/src/interceptors/index.ts +0 -2
- package/src/interceptors/language-interceptor.service.ts +0 -28
- package/src/interceptors/translation-interceptor.service.ts +0 -43
- package/src/interfaces/IApiFile.ts +0 -4
- package/src/interfaces/IFile.ts +0 -8
- package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
- package/src/interfaces/index.ts +0 -3
- package/src/interfaces/response.ts +0 -37
- package/src/middlewares/index.ts +0 -4
- package/src/middlewares/omni-auth.middleware.ts +0 -10
- package/src/middlewares/powerby.middleware.ts +0 -6
- package/src/middlewares/request-id.middleware.ts +0 -28
- package/src/middlewares/xml.middleware.ts +0 -14
- package/src/providers/context.provider.ts +0 -109
- package/src/providers/generator.provider.ts +0 -66
- package/src/providers/index.ts +0 -2
- package/src/setup/bootstrap.setup.ts +0 -254
- package/src/setup/index.ts +0 -1
- package/src/shared/index.ts +0 -2
- package/src/shared/serviceRegistryModule.ts +0 -135
- package/src/shared/services/api-config.service.ts +0 -336
- package/src/shared/services/generator.service.ts +0 -13
- package/src/shared/services/index.ts +0 -4
- package/src/shared/services/translation.service.ts +0 -59
- package/src/shared/services/validator.service.ts +0 -10
- package/src/validator-json/decorators.ts +0 -63
- package/src/validator-json/default.ts +0 -257
- package/src/validator-json/defaultConverters.ts +0 -402
- package/src/validator-json/index.ts +0 -4
- package/src/validator-json/options.ts +0 -50
- package/src/validators/file-mimetype.validator.ts +0 -34
- package/src/validators/index.ts +0 -6
- package/src/validators/is-exists.validator.ts +0 -60
- package/src/validators/is-unique.validator.ts +0 -93
- package/src/validators/phone-country-code.validator.ts +0 -36
- package/src/validators/same-as.validator.ts +0 -27
- package/src/validators/skip-empty.validator.ts +0 -25
- package/tsconfig.json +0 -31
- package/tsconfig.lib.json +0 -16
- /package/{dist/.hygen → .hygen}/new/crud/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create-command.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/get-query.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/module/repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{dist/.hygen.js → .hygen.js} +0 -0
- /package/{dist/common → common}/abstract-client.service.d.ts +0 -0
- /package/{dist/common → common}/abstract-client.service.js +0 -0
- /package/{dist/common → common}/abstract.entity.d.ts +0 -0
- /package/{dist/common → common}/abstract.entity.js +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.d.ts +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.js +0 -0
- /package/{dist/common → common}/dto/abstract.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/abstract.dto.js +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.js +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.js +0 -0
- /package/{dist/common → common}/dto/index.d.ts +0 -0
- /package/{dist/common → common}/dto/index.js +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.js +0 -0
- /package/{dist/common → common}/dto/page-options.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-options.dto.js +0 -0
- /package/{dist/common → common}/dto/page.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page.dto.js +0 -0
- /package/{dist/common → common}/index.d.ts +0 -0
- /package/{dist/common → common}/index.js +0 -0
- /package/{dist/common → common}/snake-naming.strategy.d.ts +0 -0
- /package/{dist/common → common}/snake-naming.strategy.js +0 -0
- /package/{dist/common → common}/types.d.ts +0 -0
- /package/{dist/common → common}/types.js +0 -0
- /package/{dist/common → common}/utils.d.ts +0 -0
- /package/{dist/common → common}/utils.js +0 -0
- /package/{dist/constants → constants}/index.d.ts +0 -0
- /package/{dist/constants → constants}/index.js +0 -0
- /package/{dist/constants → constants}/language-code.d.ts +0 -0
- /package/{dist/constants → constants}/language-code.js +0 -0
- /package/{dist/constants → constants}/order.d.ts +0 -0
- /package/{dist/constants → constants}/order.js +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.js +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.js +0 -0
- /package/{dist/decorators → decorators}/field.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/field.decorators.js +0 -0
- /package/{dist/decorators → decorators}/http.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/http.decorators.js +0 -0
- /package/{dist/decorators → decorators}/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/index.js +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.js +0 -0
- /package/{dist/decorators → decorators}/property.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/property.decorators.js +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.js +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.d.ts +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.js +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.js +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.js +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.js +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.js +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.js +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/index.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/index.js +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.js +0 -0
- /package/{dist/filters → filters}/bad-request.filter.d.ts +0 -0
- /package/{dist/filters → filters}/bad-request.filter.js +0 -0
- /package/{dist/filters → filters}/constraint-errors.d.ts +0 -0
- /package/{dist/filters → filters}/constraint-errors.js +0 -0
- /package/{dist/filters → filters}/index.d.ts +0 -0
- /package/{dist/filters → filters}/index.js +0 -0
- /package/{dist/filters → filters}/query-failed.filter.d.ts +0 -0
- /package/{dist/filters → filters}/query-failed.filter.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.js +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{dist/helpers → helpers}/common.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/common.helper.js +0 -0
- /package/{dist/helpers → helpers}/date.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/date.helper.js +0 -0
- /package/{dist/helpers → helpers}/index.d.ts +0 -0
- /package/{dist/helpers → helpers}/index.js +0 -0
- /package/{dist/i18n → i18n}/en_US/validation.json +0 -0
- /package/{dist/i18n → i18n}/zh_CN/validation.json +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/interceptors → interceptors}/index.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/index.js +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.js +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.js +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.js +0 -0
- /package/{dist/interfaces → interfaces}/IFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IFile.js +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{dist/interfaces → interfaces}/index.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/index.js +0 -0
- /package/{dist/interfaces → interfaces}/response.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/response.js +0 -0
- /package/{dist/middlewares → middlewares}/index.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/index.js +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.js +0 -0
- /package/{dist/providers → providers}/context.provider.d.ts +0 -0
- /package/{dist/providers → providers}/context.provider.js +0 -0
- /package/{dist/providers → providers}/generator.provider.d.ts +0 -0
- /package/{dist/providers → providers}/generator.provider.js +0 -0
- /package/{dist/providers → providers}/index.d.ts +0 -0
- /package/{dist/providers → providers}/index.js +0 -0
- /package/{dist/setup → setup}/bootstrap.setup.d.ts +0 -0
- /package/{dist/setup → setup}/index.d.ts +0 -0
- /package/{dist/setup → setup}/index.js +0 -0
- /package/{dist/shared → shared}/index.d.ts +0 -0
- /package/{dist/shared → shared}/index.js +0 -0
- /package/{dist/shared → shared}/serviceRegistryModule.d.ts +0 -0
- /package/{dist/shared → shared}/services/api-config.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/api-config.service.js +0 -0
- /package/{dist/shared → shared}/services/generator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/generator.service.js +0 -0
- /package/{dist/shared → shared}/services/index.d.ts +0 -0
- /package/{dist/shared → shared}/services/index.js +0 -0
- /package/{dist/shared → shared}/services/translation.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/translation.service.js +0 -0
- /package/{dist/shared → shared}/services/validator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/validator.service.js +0 -0
- /package/{dist/validator-json → validator-json}/decorators.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/decorators.js +0 -0
- /package/{dist/validator-json → validator-json}/default.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/default.js +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.js +0 -0
- /package/{dist/validator-json → validator-json}/index.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/index.js +0 -0
- /package/{dist/validator-json → validator-json}/options.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/options.js +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.d.ts +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.js +0 -0
- /package/{dist/validators → validators}/index.d.ts +0 -0
- /package/{dist/validators → validators}/index.js +0 -0
- /package/{dist/validators → validators}/is-exists.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-exists.validator.js +0 -0
- /package/{dist/validators → validators}/is-unique.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-unique.validator.js +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.d.ts +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.js +0 -0
- /package/{dist/validators → validators}/same-as.validator.d.ts +0 -0
- /package/{dist/validators → validators}/same-as.validator.js +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.d.ts +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.js +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { ClsServiceManager } from 'nestjs-cls';
|
|
2
|
-
import { IUser } from '../decorators/user.decorator';
|
|
3
|
-
import { BadGatewayException } from '@nestjs/common';
|
|
4
|
-
|
|
5
|
-
export class ContextProvider {
|
|
6
|
-
private static readonly nameSpace = 'request';
|
|
7
|
-
|
|
8
|
-
private static readonly authUserKey = 'user_key';
|
|
9
|
-
|
|
10
|
-
private static readonly routerKey = 'router_key';
|
|
11
|
-
|
|
12
|
-
private static readonly languageKey = 'language_key';
|
|
13
|
-
|
|
14
|
-
private static readonly requestKey = 'request_key';
|
|
15
|
-
|
|
16
|
-
static get<T>(key: string) {
|
|
17
|
-
const store = ClsServiceManager.getClsService();
|
|
18
|
-
|
|
19
|
-
return store.get<T>(ContextProvider.getKeyWithNamespace(key));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
-
static set(key: string, value: any): void {
|
|
24
|
-
const store = ClsServiceManager.getClsService();
|
|
25
|
-
|
|
26
|
-
store.set(ContextProvider.getKeyWithNamespace(key), value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static getKeyWithNamespace(key: string): string {
|
|
30
|
-
return `${ContextProvider.nameSpace}.${key}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static setRouter(user: any): void {
|
|
34
|
-
ContextProvider.set(ContextProvider.routerKey, user);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static getCanLog(): boolean {
|
|
38
|
-
return ContextProvider.getRouter().canLog;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static getRouter(): {
|
|
42
|
-
action: { feature: string; action: string };
|
|
43
|
-
id: string;
|
|
44
|
-
method: object;
|
|
45
|
-
ip: string;
|
|
46
|
-
canLog: boolean;
|
|
47
|
-
} {
|
|
48
|
-
const value = ContextProvider.get(ContextProvider.routerKey);
|
|
49
|
-
if (value) {
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
action: { feature: '', action: '' },
|
|
55
|
-
id: '',
|
|
56
|
-
method: {},
|
|
57
|
-
ip: '',
|
|
58
|
-
canLog: false,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static setRequestId(id: string): void {
|
|
63
|
-
ContextProvider.set(ContextProvider.requestKey, id);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static getRequestId(): string {
|
|
67
|
-
return ContextProvider.get(ContextProvider.requestKey);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static setAuthUser(user: IUser): void {
|
|
71
|
-
ContextProvider.set(ContextProvider.authUserKey, user);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static setLanguage(language: string): void {
|
|
75
|
-
ContextProvider.set(ContextProvider.languageKey, language);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static getLanguage(): string {
|
|
79
|
-
return ContextProvider.get(ContextProvider.languageKey);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static getAuthUserField<T extends keyof IUser>(field?: T): IUser[T] {
|
|
83
|
-
return ContextProvider.getAuthUser()[field];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static getAuthUser(): IUser {
|
|
87
|
-
const auth = ContextProvider.get(ContextProvider.authUserKey) as IUser;
|
|
88
|
-
if (!auth) {
|
|
89
|
-
throw new BadGatewayException('User information not found.');
|
|
90
|
-
}
|
|
91
|
-
return auth;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static getAppId(): string {
|
|
95
|
-
return ContextProvider.getAuthUserField('appId');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
static getRole(): string {
|
|
99
|
-
return ContextProvider.getAuthUserField('role');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static getAdmin(): boolean {
|
|
103
|
-
return ContextProvider.getAuthUserField('admin');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static getTenantId(): string {
|
|
107
|
-
return ContextProvider.getAuthUserField('tenantId');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { v1 as uuid } from 'uuid';
|
|
2
|
-
|
|
3
|
-
export class GeneratorProvider {
|
|
4
|
-
static uuid(): string {
|
|
5
|
-
return uuid();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
static fileName(ext: string): string {
|
|
9
|
-
return GeneratorProvider.uuid() + '.' + ext;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static getS3PublicUrl(key: string): string {
|
|
13
|
-
if (!key) {
|
|
14
|
-
throw new TypeError('key is required');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return `https://s3.${process.env.AWS_S3_BUCKET_NAME_REGION}.amazonaws.com/${process.env.AWS_S3_BUCKET_NAME}/${key}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static getS3Key(publicUrl: string): string {
|
|
21
|
-
if (!publicUrl) {
|
|
22
|
-
throw new TypeError('key is required');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const exec = new RegExp(
|
|
26
|
-
`(?<=https://s3.${process.env.AWS_S3_BUCKET_NAME_REGION}.amazonaws.com/${process.env.AWS_S3_BUCKET_NAME}/).*`,
|
|
27
|
-
).exec(publicUrl);
|
|
28
|
-
|
|
29
|
-
if (!exec) {
|
|
30
|
-
throw new TypeError('publicUrl is invalid');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return exec[0];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static generateVerificationCode(): string {
|
|
37
|
-
return Math.floor(1000 + Math.random() * 9000).toString();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static generatePassword(): string {
|
|
41
|
-
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
|
|
42
|
-
const uppercase = lowercase.toUpperCase();
|
|
43
|
-
const numbers = '0123456789';
|
|
44
|
-
|
|
45
|
-
let text = '';
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < 12; i++) {
|
|
48
|
-
text += uppercase.charAt(Math.floor(Math.random() * uppercase.length));
|
|
49
|
-
text += lowercase.charAt(Math.floor(Math.random() * lowercase.length));
|
|
50
|
-
text += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return text;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* generate random string
|
|
58
|
-
* @param length
|
|
59
|
-
*/
|
|
60
|
-
static generateRandomString(length: number): string {
|
|
61
|
-
return Math.random()
|
|
62
|
-
.toString(36)
|
|
63
|
-
.replace(/[^\dA-Za-z]+/g, '')
|
|
64
|
-
.slice(0, Math.max(0, length));
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/providers/index.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import * as Sentry from '@sentry/nestjs';
|
|
2
|
-
import { nodeProfilingIntegration } from '@sentry/profiling-node';
|
|
3
|
-
import * as dotenv from 'dotenv';
|
|
4
|
-
import { existsSync } from 'fs';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
const possibleRootPaths = [process.cwd(), __dirname];
|
|
7
|
-
const path0 = join(possibleRootPaths[0], 'config/base.env');
|
|
8
|
-
const path1 = join(possibleRootPaths[1], 'config/base.env');
|
|
9
|
-
if (existsSync(path0)) {
|
|
10
|
-
dotenv.config({ path: path0 });
|
|
11
|
-
} else if (existsSync(path1)) {
|
|
12
|
-
dotenv.config({ path: path1 });
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`No valid base.env file: ${path0} or ${path1}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const requiredEnvVars = ['SENTRY_DSN', 'API_VERSION', 'NODE_ENV'];
|
|
18
|
-
requiredEnvVars.forEach((envVar) => {
|
|
19
|
-
if (!process.env[envVar]) {
|
|
20
|
-
throw new Error(`Missing required environment variable: ${envVar}`);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
Sentry.init({
|
|
24
|
-
dsn: process.env.SENTRY_DSN || '',
|
|
25
|
-
release: process.env.API_VERSION || '',
|
|
26
|
-
environment: process.env.NODE_ENV || 'unkown',
|
|
27
|
-
debug: process.env.NODE_ENV === 'dev',
|
|
28
|
-
tracesSampleRate: 1.0,
|
|
29
|
-
profileSessionSampleRate: 1.0,
|
|
30
|
-
profileLifecycle: 'trace',
|
|
31
|
-
sendDefaultPii: true,
|
|
32
|
-
integrations: [nodeProfilingIntegration],
|
|
33
|
-
});
|
|
34
|
-
import { CrudConfigService } from '@dataui/crud';
|
|
35
|
-
|
|
36
|
-
CrudConfigService.load({
|
|
37
|
-
auth: {
|
|
38
|
-
property: 'user',
|
|
39
|
-
},
|
|
40
|
-
params: {
|
|
41
|
-
id: {
|
|
42
|
-
field: 'id',
|
|
43
|
-
type: 'string',
|
|
44
|
-
primary: true,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
query: {
|
|
48
|
-
limit: 10,
|
|
49
|
-
alwaysPaginate: true,
|
|
50
|
-
},
|
|
51
|
-
routes: {
|
|
52
|
-
updateOneBase: {
|
|
53
|
-
allowParamsOverride: false,
|
|
54
|
-
},
|
|
55
|
-
deleteOneBase: {
|
|
56
|
-
returnDeleted: false,
|
|
57
|
-
},
|
|
58
|
-
createOneBase: {
|
|
59
|
-
returnShallow: false,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
import { NestFactory, Reflector } from '@nestjs/core';
|
|
64
|
-
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
65
|
-
import { initializeTransactionalContext } from 'typeorm-transactional';
|
|
66
|
-
import { Logger, LoggerErrorInterceptor } from 'nestjs-pino';
|
|
67
|
-
import * as session from 'express-session';
|
|
68
|
-
import * as bodyParse from 'body-parser';
|
|
69
|
-
import {
|
|
70
|
-
ApiConfigService,
|
|
71
|
-
HttpExceptionFilter,
|
|
72
|
-
LanguageInterceptor,
|
|
73
|
-
OmniAuthMiddleware,
|
|
74
|
-
PowerByMiddleware,
|
|
75
|
-
QueryFailedFilter,
|
|
76
|
-
RequestIdMiddleware,
|
|
77
|
-
ServiceRegistryModule,
|
|
78
|
-
TranslationInterceptor,
|
|
79
|
-
} from '../';
|
|
80
|
-
import { HttpStatus } from '@nestjs/common';
|
|
81
|
-
import { I18nValidationPipe } from 'nestjs-i18n';
|
|
82
|
-
import { ClsMiddleware } from 'nestjs-cls';
|
|
83
|
-
import { SentryGlobalFilter } from '@sentry/nestjs/setup';
|
|
84
|
-
|
|
85
|
-
/* 优化点2:封装进程异常处理 */
|
|
86
|
-
const setupProcessHandlers = (app: NestExpressApplication) => {
|
|
87
|
-
const logger = app.get(Logger);
|
|
88
|
-
|
|
89
|
-
process.on('uncaughtException', (error) => {
|
|
90
|
-
logger.fatal(
|
|
91
|
-
{ error, stack: error.stack, pid: process.pid },
|
|
92
|
-
'Uncaught Exception',
|
|
93
|
-
);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
process.on('unhandledRejection', (reason: Error, promise) => {
|
|
98
|
-
logger.error(
|
|
99
|
-
{
|
|
100
|
-
reason: {
|
|
101
|
-
message: reason.message,
|
|
102
|
-
stack: reason.stack,
|
|
103
|
-
name: reason.name,
|
|
104
|
-
},
|
|
105
|
-
promise,
|
|
106
|
-
pid: process.pid,
|
|
107
|
-
},
|
|
108
|
-
'Unhandled Rejection',
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// 新增退出码监听
|
|
113
|
-
process.on('exit', (code) => {
|
|
114
|
-
logger.warn(`Process exiting with code ${code}`, {
|
|
115
|
-
uptime: process.uptime(),
|
|
116
|
-
memoryUsage: process.memoryUsage(),
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/* 优化点3:优雅关闭封装 */
|
|
122
|
-
const setupGracefulShutdown = (app: NestExpressApplication) => {
|
|
123
|
-
const logger = app.get(Logger);
|
|
124
|
-
|
|
125
|
-
const shutdown = async (signal: string) => {
|
|
126
|
-
try {
|
|
127
|
-
logger.warn(`Received ${signal}, starting graceful shutdown...`, {
|
|
128
|
-
uptime: process.uptime(),
|
|
129
|
-
connections: app.getHttpServer()?.address(),
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// 增加关闭超时保护
|
|
133
|
-
await Promise.race([
|
|
134
|
-
app.close(),
|
|
135
|
-
new Promise((_, reject) =>
|
|
136
|
-
setTimeout(
|
|
137
|
-
() => reject(new Error('Shutdown timeout exceeded')),
|
|
138
|
-
15000,
|
|
139
|
-
),
|
|
140
|
-
),
|
|
141
|
-
]);
|
|
142
|
-
|
|
143
|
-
logger.log('Application successfully closed', {
|
|
144
|
-
resourcesReleased: true,
|
|
145
|
-
pid: process.pid,
|
|
146
|
-
});
|
|
147
|
-
process.exit(0);
|
|
148
|
-
} catch (err) {
|
|
149
|
-
logger.error('Graceful shutdown failed', {
|
|
150
|
-
error: {
|
|
151
|
-
message: err.message,
|
|
152
|
-
stack: err.stack,
|
|
153
|
-
name: err.name,
|
|
154
|
-
},
|
|
155
|
-
critical: true,
|
|
156
|
-
pid: process.pid,
|
|
157
|
-
});
|
|
158
|
-
process.exit(1);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// 新增异常关闭信号监听
|
|
163
|
-
process.on('SIGQUIT', () => shutdown('SIGQUIT'));
|
|
164
|
-
process.on('SIGHUP', () => shutdown('SIGHUP'));
|
|
165
|
-
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
166
|
-
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export async function bootstrapSetup(AppModule, SetupSwagger) {
|
|
170
|
-
// 初始化配置
|
|
171
|
-
initializeTransactionalContext();
|
|
172
|
-
|
|
173
|
-
// 创建应用实例
|
|
174
|
-
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
175
|
-
bufferLogs: true,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// 获取核心服务
|
|
179
|
-
const configService = app.select(ServiceRegistryModule).get(ApiConfigService);
|
|
180
|
-
const logger = app.get(Logger);
|
|
181
|
-
|
|
182
|
-
// 设置进程监控
|
|
183
|
-
setupProcessHandlers(app);
|
|
184
|
-
app.enableShutdownHooks();
|
|
185
|
-
setupGracefulShutdown(app);
|
|
186
|
-
|
|
187
|
-
// 基础配置
|
|
188
|
-
app.enableVersioning();
|
|
189
|
-
app.enable('trust proxy');
|
|
190
|
-
|
|
191
|
-
// 中间件配置
|
|
192
|
-
app.use(
|
|
193
|
-
bodyParse.json({ limit: '50mb' }),
|
|
194
|
-
new ClsMiddleware({}).use,
|
|
195
|
-
RequestIdMiddleware(),
|
|
196
|
-
PowerByMiddleware(),
|
|
197
|
-
OmniAuthMiddleware(),
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
// 全局过滤器
|
|
201
|
-
const reflector = app.get(Reflector);
|
|
202
|
-
app.useGlobalFilters(
|
|
203
|
-
new SentryGlobalFilter(),
|
|
204
|
-
new HttpExceptionFilter(),
|
|
205
|
-
new QueryFailedFilter(reflector),
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
// 全局拦截器
|
|
209
|
-
app.useGlobalInterceptors(
|
|
210
|
-
new LanguageInterceptor(),
|
|
211
|
-
new TranslationInterceptor(),
|
|
212
|
-
new LoggerErrorInterceptor(),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
// 全局管道
|
|
216
|
-
app.useGlobalPipes(
|
|
217
|
-
new I18nValidationPipe({
|
|
218
|
-
whitelist: true,
|
|
219
|
-
errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
220
|
-
transform: true,
|
|
221
|
-
stopAtFirstError: true,
|
|
222
|
-
validationError: { target: false, value: false },
|
|
223
|
-
}),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
// 可选功能模块
|
|
227
|
-
if (configService.documentationEnabled && SetupSwagger) {
|
|
228
|
-
SetupSwagger(app, configService.documentationPath);
|
|
229
|
-
logger.log(`Swagger docs available at ${configService.documentationPath}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (configService.viewsEnabled) {
|
|
233
|
-
app.setBaseViewsDir(join(ApiConfigService.rootPath, 'views'));
|
|
234
|
-
app.setViewEngine('ejs');
|
|
235
|
-
logger.log('View engine initialized');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (configService.sessionEnabled) {
|
|
239
|
-
app.use(session(configService.sessionConfig));
|
|
240
|
-
logger.log('Session middleware enabled');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (configService.corsEnabled) {
|
|
244
|
-
app.enableCors(configService.corsConfig);
|
|
245
|
-
logger.log('CORS configuration applied');
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// 启动服务
|
|
249
|
-
const port = configService.appConfig.port;
|
|
250
|
-
await app.listen(port);
|
|
251
|
-
logger.log(`Server running on ${await app.getUrl()}`);
|
|
252
|
-
|
|
253
|
-
return app;
|
|
254
|
-
}
|
package/src/setup/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './bootstrap.setup';
|
package/src/shared/index.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as process from 'process';
|
|
3
|
-
import { DataSource } from 'typeorm';
|
|
4
|
-
import { BullModule } from '@nestjs/bull';
|
|
5
|
-
import { LoggerModule } from 'nestjs-pino';
|
|
6
|
-
import { ConfigModule } from '@nestjs/config';
|
|
7
|
-
import type { Provider } from '@nestjs/common';
|
|
8
|
-
import { Global, Module } from '@nestjs/common';
|
|
9
|
-
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
10
|
-
import { ScheduleModule } from '@nestjs/schedule';
|
|
11
|
-
import { SentryModule } from '@sentry/nestjs/setup';
|
|
12
|
-
import { CacheModule } from '@nestjs/cache-manager';
|
|
13
|
-
import { addTransactionalDataSource } from 'typeorm-transactional';
|
|
14
|
-
import { AcceptLanguageResolver, I18nModule, QueryResolver } from 'nestjs-i18n';
|
|
15
|
-
import { HealthCheckerModule } from '../health-checker/health-checker.module';
|
|
16
|
-
import {
|
|
17
|
-
ApiConfigService,
|
|
18
|
-
GeneratorService,
|
|
19
|
-
TranslationService,
|
|
20
|
-
ValidatorService,
|
|
21
|
-
} from './services';
|
|
22
|
-
import { existsSync } from 'fs';
|
|
23
|
-
import { join } from 'path';
|
|
24
|
-
|
|
25
|
-
const providers: Provider[] = [
|
|
26
|
-
ApiConfigService,
|
|
27
|
-
ValidatorService,
|
|
28
|
-
GeneratorService,
|
|
29
|
-
TranslationService,
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const isTest = process.env.NODE_ENV === 'test';
|
|
33
|
-
|
|
34
|
-
function findValidRootPath() {
|
|
35
|
-
const possibleRootPaths = [process.cwd(), __dirname];
|
|
36
|
-
const envFile = `${process.env.NODE_ENV || ''}.env`;
|
|
37
|
-
let envFilePath = '';
|
|
38
|
-
|
|
39
|
-
for (const rootPath of possibleRootPaths) {
|
|
40
|
-
const configPath = join(rootPath, 'config');
|
|
41
|
-
const baseEnvFilePath = join(configPath, 'base.env');
|
|
42
|
-
|
|
43
|
-
if (isTest) {
|
|
44
|
-
envFilePath = join(configPath, 'test.env');
|
|
45
|
-
if (existsSync(envFilePath)) {
|
|
46
|
-
return { rootPath, baseEnvFilePath, envFilePath };
|
|
47
|
-
} else {
|
|
48
|
-
envFilePath = join(configPath, 'dev.env');
|
|
49
|
-
if (existsSync(envFilePath)) {
|
|
50
|
-
return { rootPath, baseEnvFilePath, envFilePath };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
envFilePath = join(configPath, envFile);
|
|
55
|
-
if (existsSync(envFilePath)) {
|
|
56
|
-
return { rootPath, baseEnvFilePath, envFilePath };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
throw new Error(`No valid .env file: ${envFilePath}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const { envFilePath, rootPath, baseEnvFilePath } = findValidRootPath();
|
|
65
|
-
ApiConfigService.rootPath = rootPath;
|
|
66
|
-
|
|
67
|
-
const modules = [
|
|
68
|
-
ConfigModule.forRoot({
|
|
69
|
-
isGlobal: true,
|
|
70
|
-
cache: true,
|
|
71
|
-
expandVariables: false,
|
|
72
|
-
envFilePath: [envFilePath, baseEnvFilePath],
|
|
73
|
-
}),
|
|
74
|
-
SentryModule.forRoot(),
|
|
75
|
-
LoggerModule.forRootAsync({
|
|
76
|
-
inject: [ApiConfigService],
|
|
77
|
-
useFactory: (config: ApiConfigService) => config.pinoConfig,
|
|
78
|
-
}),
|
|
79
|
-
I18nModule.forRootAsync({
|
|
80
|
-
inject: [ApiConfigService],
|
|
81
|
-
useFactory: (config: ApiConfigService) => ({
|
|
82
|
-
fallbackLanguage: config.fallbackLanguage,
|
|
83
|
-
loaderOptions: {
|
|
84
|
-
path: path.join(ApiConfigService.rootPath, '/i18n/'),
|
|
85
|
-
watch: config.isDev,
|
|
86
|
-
},
|
|
87
|
-
logging: config.isDev,
|
|
88
|
-
}),
|
|
89
|
-
resolvers: [new QueryResolver(['lang']), AcceptLanguageResolver],
|
|
90
|
-
}),
|
|
91
|
-
HealthCheckerModule,
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
if (ApiConfigService.toBoolean(process.env.DB_ENABLED, true)) {
|
|
95
|
-
modules.push(
|
|
96
|
-
TypeOrmModule.forRootAsync({
|
|
97
|
-
inject: [ApiConfigService],
|
|
98
|
-
useFactory: (config: ApiConfigService) => config.typeormConfig,
|
|
99
|
-
dataSourceFactory: async (options) => {
|
|
100
|
-
return addTransactionalDataSource(new DataSource(options));
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (ApiConfigService.toBoolean(process.env.BULL_ENABLED)) {
|
|
107
|
-
modules.push(
|
|
108
|
-
BullModule.forRootAsync({
|
|
109
|
-
inject: [ApiConfigService],
|
|
110
|
-
useFactory: (config: ApiConfigService) => config.bullConfig,
|
|
111
|
-
}),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
|
|
116
|
-
modules.push(
|
|
117
|
-
CacheModule.registerAsync({
|
|
118
|
-
inject: [ApiConfigService],
|
|
119
|
-
isGlobal: true,
|
|
120
|
-
useFactory: (config: ApiConfigService) => config.cacheConfig(),
|
|
121
|
-
}),
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (ApiConfigService.toBoolean(process.env.SCHEDULE_ENABLED)) {
|
|
126
|
-
modules.push(ScheduleModule.forRoot());
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
@Global()
|
|
130
|
-
@Module({
|
|
131
|
-
providers,
|
|
132
|
-
imports: modules,
|
|
133
|
-
exports: [...providers],
|
|
134
|
-
})
|
|
135
|
-
export class ServiceRegistryModule {}
|