@nest-omni/core 1.0.57 → 2.0.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.history/src/common/boilerplate.polyfill_20250521135408.ts +202 -0
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +291 -0
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +317 -0
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +319 -0
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +289 -0
- package/README.md +16 -0
- package/build.sh +45 -0
- package/{common → dist/common}/abstract.entity.d.ts +1 -0
- package/{common → dist/common}/abstract.entity.js +13 -0
- package/{decorators → dist/decorators}/field.decorators.d.ts +1 -1
- package/dist/package.json +71 -0
- package/dist/setup/bootstrap.setup.d.ts +2 -0
- package/{setup → dist/setup}/bootstrap.setup.js +45 -27
- package/{shared → dist/shared}/serviceRegistryModule.js +4 -11
- package/{shared → dist/shared}/services/api-config.service.d.ts +3 -15
- package/{shared → dist/shared}/services/api-config.service.js +15 -42
- package/{shared → dist/shared}/services/index.d.ts +0 -1
- package/{shared → dist/shared}/services/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/yarn.lock +644 -0
- package/package.json +1 -3
- package/src/.hygen.js +116 -0
- package/src/common/abstract-client.service.ts +56 -0
- package/src/common/abstract.entity.ts +82 -0
- package/src/common/boilerplate.polyfill.ts +202 -0
- package/src/common/dto/abstract.dto.ts +61 -0
- package/src/common/dto/bulk-id.dto.ts +13 -0
- package/src/common/dto/create-translation.dto.ts +10 -0
- package/src/common/dto/index.ts +6 -0
- package/src/common/dto/page-meta.dto.ts +37 -0
- package/src/common/dto/page-options.dto.ts +35 -0
- package/src/common/dto/page.dto.ts +36 -0
- package/src/common/index.ts +7 -0
- package/src/common/snake-naming.strategy.ts +64 -0
- package/src/common/types.ts +44 -0
- package/src/common/utils.ts +45 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/language-code.ts +7 -0
- package/src/constants/order.ts +4 -0
- package/src/decorators/api-page-ok-response.decorator.ts +32 -0
- package/src/decorators/auth-user.decorator.ts +16 -0
- package/src/decorators/controller.decorator.ts +8 -0
- package/src/decorators/field.decorators.ts +856 -0
- package/src/decorators/http.decorators.ts +10 -0
- package/src/decorators/index.ts +12 -0
- package/src/decorators/operation.decorator.ts +4 -0
- package/src/decorators/property.decorators.ts +62 -0
- package/src/decorators/public-route.decorator.ts +8 -0
- package/src/decorators/swagger.schema.ts +117 -0
- package/src/decorators/timestamp-column.decorator.ts +29 -0
- package/src/decorators/transform.decorators.ts +159 -0
- package/src/decorators/translate.decorator.ts +19 -0
- package/src/decorators/use-dto.decorator.ts +11 -0
- package/src/decorators/user-check.decorator.ts +30 -0
- package/src/decorators/user.decorator.ts +59 -0
- package/src/decorators/user_auth.decorator.ts +15 -0
- package/src/decorators/validator.decorators.ts +98 -0
- package/src/exceptions/file-not-image.exception.ts +7 -0
- package/src/exceptions/index.ts +2 -0
- package/src/exceptions/page-type.exception.ts +7 -0
- package/src/exceptions/user-not-found.exception.ts +7 -0
- package/src/filters/bad-request.filter.ts +77 -0
- package/src/filters/constraint-errors.ts +5 -0
- package/src/filters/index.ts +3 -0
- package/src/filters/query-failed.filter.ts +32 -0
- package/src/health-checker/health-checker.controller.ts +51 -0
- package/src/health-checker/health-checker.module.ts +13 -0
- package/src/health-checker/health-indicators/service.indicator.ts +44 -0
- package/src/helpers/common.helper.ts +49 -0
- package/src/helpers/date.helper.ts +64 -0
- package/src/helpers/index.ts +2 -0
- package/src/i18n/en_US/validation.json +41 -0
- package/src/i18n/zh_CN/validation.json +41 -0
- package/src/index.ts +11 -0
- package/src/interceptors/index.ts +2 -0
- package/src/interceptors/language-interceptor.service.ts +28 -0
- package/src/interceptors/translation-interceptor.service.ts +43 -0
- package/src/interfaces/IApiFile.ts +4 -0
- package/src/interfaces/IFile.ts +8 -0
- package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/response.ts +37 -0
- package/src/middlewares/index.ts +4 -0
- package/src/middlewares/omni-auth.middleware.ts +10 -0
- package/src/middlewares/powerby.middleware.ts +6 -0
- package/src/middlewares/request-id.middleware.ts +28 -0
- package/src/middlewares/xml.middleware.ts +14 -0
- package/src/providers/context.provider.ts +109 -0
- package/src/providers/generator.provider.ts +66 -0
- package/src/providers/index.ts +2 -0
- package/src/setup/bootstrap.setup.ts +254 -0
- package/src/setup/index.ts +1 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/serviceRegistryModule.ts +135 -0
- package/src/shared/services/api-config.service.ts +336 -0
- package/src/shared/services/generator.service.ts +13 -0
- package/src/shared/services/index.ts +4 -0
- package/src/shared/services/translation.service.ts +59 -0
- package/src/shared/services/validator.service.ts +10 -0
- package/src/validator-json/decorators.ts +63 -0
- package/src/validator-json/default.ts +257 -0
- package/src/validator-json/defaultConverters.ts +402 -0
- package/src/validator-json/index.ts +4 -0
- package/src/validator-json/options.ts +50 -0
- package/src/validators/file-mimetype.validator.ts +34 -0
- package/src/validators/index.ts +6 -0
- package/src/validators/is-exists.validator.ts +60 -0
- package/src/validators/is-unique.validator.ts +93 -0
- package/src/validators/phone-country-code.validator.ts +36 -0
- package/src/validators/same-as.validator.ts +27 -0
- package/src/validators/skip-empty.validator.ts +25 -0
- package/tsconfig.json +31 -0
- package/tsconfig.lib.json +16 -0
- package/setup/bootstrap.setup.d.ts +0 -2
- package/shared/services/aws-s3.service.d.ts +0 -10
- package/shared/services/aws-s3.service.js +0 -56
- package/tsconfig.tsbuildinfo +0 -1
- /package/{.hygen → dist/.hygen}/new/crud/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create-command.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/get-query.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/module/repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{.hygen.js → dist/.hygen.js} +0 -0
- /package/{common → dist/common}/abstract-client.service.d.ts +0 -0
- /package/{common → dist/common}/abstract-client.service.js +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.d.ts +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.js +0 -0
- /package/{common → dist/common}/dto/abstract.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/abstract.dto.js +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.js +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.js +0 -0
- /package/{common → dist/common}/dto/index.d.ts +0 -0
- /package/{common → dist/common}/dto/index.js +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.js +0 -0
- /package/{common → dist/common}/dto/page-options.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-options.dto.js +0 -0
- /package/{common → dist/common}/dto/page.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page.dto.js +0 -0
- /package/{common → dist/common}/index.d.ts +0 -0
- /package/{common → dist/common}/index.js +0 -0
- /package/{common → dist/common}/snake-naming.strategy.d.ts +0 -0
- /package/{common → dist/common}/snake-naming.strategy.js +0 -0
- /package/{common → dist/common}/types.d.ts +0 -0
- /package/{common → dist/common}/types.js +0 -0
- /package/{common → dist/common}/utils.d.ts +0 -0
- /package/{common → dist/common}/utils.js +0 -0
- /package/{constants → dist/constants}/index.d.ts +0 -0
- /package/{constants → dist/constants}/index.js +0 -0
- /package/{constants → dist/constants}/language-code.d.ts +0 -0
- /package/{constants → dist/constants}/language-code.js +0 -0
- /package/{constants → dist/constants}/order.d.ts +0 -0
- /package/{constants → dist/constants}/order.js +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.js +0 -0
- /package/{decorators → dist/decorators}/field.decorators.js +0 -0
- /package/{decorators → dist/decorators}/http.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/http.decorators.js +0 -0
- /package/{decorators → dist/decorators}/index.d.ts +0 -0
- /package/{decorators → dist/decorators}/index.js +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.js +0 -0
- /package/{decorators → dist/decorators}/property.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/property.decorators.js +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.js +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.d.ts +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.js +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.js +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.js +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.js +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.js +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.js +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/index.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/index.js +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.js +0 -0
- /package/{filters → dist/filters}/bad-request.filter.d.ts +0 -0
- /package/{filters → dist/filters}/bad-request.filter.js +0 -0
- /package/{filters → dist/filters}/constraint-errors.d.ts +0 -0
- /package/{filters → dist/filters}/constraint-errors.js +0 -0
- /package/{filters → dist/filters}/index.d.ts +0 -0
- /package/{filters → dist/filters}/index.js +0 -0
- /package/{filters → dist/filters}/query-failed.filter.d.ts +0 -0
- /package/{filters → dist/filters}/query-failed.filter.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.js +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{helpers → dist/helpers}/common.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/common.helper.js +0 -0
- /package/{helpers → dist/helpers}/date.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/date.helper.js +0 -0
- /package/{helpers → dist/helpers}/index.d.ts +0 -0
- /package/{helpers → dist/helpers}/index.js +0 -0
- /package/{i18n → dist/i18n}/en_US/validation.json +0 -0
- /package/{i18n → dist/i18n}/zh_CN/validation.json +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{interceptors → dist/interceptors}/index.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/index.js +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.js +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.js +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.js +0 -0
- /package/{interfaces → dist/interfaces}/IFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IFile.js +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{interfaces → dist/interfaces}/index.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/index.js +0 -0
- /package/{interfaces → dist/interfaces}/response.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/response.js +0 -0
- /package/{middlewares → dist/middlewares}/index.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/index.js +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.js +0 -0
- /package/{providers → dist/providers}/context.provider.d.ts +0 -0
- /package/{providers → dist/providers}/context.provider.js +0 -0
- /package/{providers → dist/providers}/generator.provider.d.ts +0 -0
- /package/{providers → dist/providers}/generator.provider.js +0 -0
- /package/{providers → dist/providers}/index.d.ts +0 -0
- /package/{providers → dist/providers}/index.js +0 -0
- /package/{setup → dist/setup}/index.d.ts +0 -0
- /package/{setup → dist/setup}/index.js +0 -0
- /package/{shared → dist/shared}/index.d.ts +0 -0
- /package/{shared → dist/shared}/index.js +0 -0
- /package/{shared → dist/shared}/serviceRegistryModule.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.js +0 -0
- /package/{shared → dist/shared}/services/translation.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/translation.service.js +0 -0
- /package/{shared → dist/shared}/services/validator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/validator.service.js +0 -0
- /package/{validator-json → dist/validator-json}/decorators.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/decorators.js +0 -0
- /package/{validator-json → dist/validator-json}/default.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/default.js +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.js +0 -0
- /package/{validator-json → dist/validator-json}/index.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/index.js +0 -0
- /package/{validator-json → dist/validator-json}/options.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/options.js +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.d.ts +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.js +0 -0
- /package/{validators → dist/validators}/index.d.ts +0 -0
- /package/{validators → dist/validators}/index.js +0 -0
- /package/{validators → dist/validators}/is-exists.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-exists.validator.js +0 -0
- /package/{validators → dist/validators}/is-unique.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-unique.validator.js +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.d.ts +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.js +0 -0
- /package/{validators → dist/validators}/same-as.validator.d.ts +0 -0
- /package/{validators → dist/validators}/same-as.validator.js +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.d.ts +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.js +0 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import 'source-map-support/register';
|
|
2
|
+
|
|
3
|
+
import { compact, map } from 'lodash';
|
|
4
|
+
import type { ObjectLiteral } from 'typeorm';
|
|
5
|
+
import { Brackets, SelectQueryBuilder } from 'typeorm';
|
|
6
|
+
|
|
7
|
+
import type { AbstractEntity } from './abstract.entity';
|
|
8
|
+
import type { AbstractDto } from './dto/abstract.dto';
|
|
9
|
+
import type { CreateTranslationDto } from './dto/create-translation.dto';
|
|
10
|
+
import { PageDto } from './dto/page.dto';
|
|
11
|
+
import { PageMetaDto } from './dto/page-meta.dto';
|
|
12
|
+
import type { PageOptionsDto } from './dto/page-options.dto';
|
|
13
|
+
import type { LanguageCode } from '../constants/language-code';
|
|
14
|
+
import type { KeyOfType } from './types';
|
|
15
|
+
import { ContextProvider } from '../providers';
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
export type Uuid = string & { _uuidBrand: undefined };
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-redundant-type-constituents
|
|
20
|
+
export type Todo = any & { _todoBrand: undefined };
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
+
interface Array<T> {
|
|
24
|
+
toDtos<Dto extends AbstractDto>(this: T[], options?: unknown): Dto[];
|
|
25
|
+
|
|
26
|
+
getByLanguage(
|
|
27
|
+
this: CreateTranslationDto[],
|
|
28
|
+
languageCode: LanguageCode,
|
|
29
|
+
): string;
|
|
30
|
+
|
|
31
|
+
toPageDto<Dto extends AbstractDto>(
|
|
32
|
+
this: T[],
|
|
33
|
+
pageMetaDto: PageMetaDto,
|
|
34
|
+
// FIXME make option type visible from entity
|
|
35
|
+
options?: unknown,
|
|
36
|
+
): PageDto<Dto>;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare module 'typeorm' {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
42
|
+
interface SelectQueryBuilder<Entity> {
|
|
43
|
+
searchByString(
|
|
44
|
+
q: string,
|
|
45
|
+
columnNames: string[],
|
|
46
|
+
options?: {
|
|
47
|
+
formStart: boolean;
|
|
48
|
+
},
|
|
49
|
+
): this;
|
|
50
|
+
|
|
51
|
+
withTenant(tenantId?: string | number, tenantFieldName?: string): this;
|
|
52
|
+
|
|
53
|
+
paginate(
|
|
54
|
+
this: SelectQueryBuilder<Entity>,
|
|
55
|
+
pageOptionsDto: PageOptionsDto,
|
|
56
|
+
options?: Partial<{ takeAll: boolean; skipCount: boolean }>,
|
|
57
|
+
): Promise<[Entity[], PageMetaDto]>;
|
|
58
|
+
|
|
59
|
+
leftJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
|
|
60
|
+
this: SelectQueryBuilder<Entity>,
|
|
61
|
+
property: `${A}.${Exclude<
|
|
62
|
+
KeyOfType<AliasEntity, AbstractEntity>,
|
|
63
|
+
symbol
|
|
64
|
+
>}`,
|
|
65
|
+
alias: string,
|
|
66
|
+
condition?: string,
|
|
67
|
+
parameters?: ObjectLiteral,
|
|
68
|
+
): this;
|
|
69
|
+
|
|
70
|
+
leftJoin<AliasEntity extends AbstractEntity, A extends string>(
|
|
71
|
+
this: SelectQueryBuilder<Entity>,
|
|
72
|
+
property: `${A}.${Exclude<
|
|
73
|
+
KeyOfType<AliasEntity, AbstractEntity>,
|
|
74
|
+
symbol
|
|
75
|
+
>}`,
|
|
76
|
+
alias: string,
|
|
77
|
+
condition?: string,
|
|
78
|
+
parameters?: ObjectLiteral,
|
|
79
|
+
): this;
|
|
80
|
+
|
|
81
|
+
innerJoinAndSelect<AliasEntity extends AbstractEntity, A extends string>(
|
|
82
|
+
this: SelectQueryBuilder<Entity>,
|
|
83
|
+
property: `${A}.${Exclude<
|
|
84
|
+
KeyOfType<AliasEntity, AbstractEntity>,
|
|
85
|
+
symbol
|
|
86
|
+
>}`,
|
|
87
|
+
alias: string,
|
|
88
|
+
condition?: string,
|
|
89
|
+
parameters?: ObjectLiteral,
|
|
90
|
+
): this;
|
|
91
|
+
|
|
92
|
+
innerJoin<AliasEntity extends AbstractEntity, A extends string>(
|
|
93
|
+
this: SelectQueryBuilder<Entity>,
|
|
94
|
+
property: `${A}.${Exclude<
|
|
95
|
+
KeyOfType<AliasEntity, AbstractEntity>,
|
|
96
|
+
symbol
|
|
97
|
+
>}`,
|
|
98
|
+
alias: string,
|
|
99
|
+
condition?: string,
|
|
100
|
+
parameters?: ObjectLiteral,
|
|
101
|
+
): this;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 通过异步生成器迭代QueryBuilder结果
|
|
105
|
+
* @param batchSize 每批大小,默认1000
|
|
106
|
+
* @returns AsyncGenerator<Entity, void, unknown>
|
|
107
|
+
*/
|
|
108
|
+
iterate(
|
|
109
|
+
this: SelectQueryBuilder<Entity>,
|
|
110
|
+
batchSize?: number,
|
|
111
|
+
): AsyncGenerator<Entity, void, unknown>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 通过callback处理每个item,无需外部循环
|
|
115
|
+
* @param callback 处理函数
|
|
116
|
+
* @param batchSize 每批大小,默认1000
|
|
117
|
+
* @returns Promise<void>
|
|
118
|
+
*/
|
|
119
|
+
iterate(
|
|
120
|
+
this: SelectQueryBuilder<Entity>,
|
|
121
|
+
callback: (item: Entity) => Promise<void> | void,
|
|
122
|
+
batchSize?: number,
|
|
123
|
+
): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Array.prototype.toDtos = function <
|
|
128
|
+
Entity extends AbstractEntity<Dto>,
|
|
129
|
+
Dto extends AbstractDto,
|
|
130
|
+
>(options?: unknown): Dto[] {
|
|
131
|
+
return compact(
|
|
132
|
+
map<Entity, Dto>(this as Entity[], (item) => item.toDto(options as never)),
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
Array.prototype.getByLanguage = function (languageCode: LanguageCode): string {
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
138
|
+
return this.find((translation) => languageCode === translation.languageCode)!
|
|
139
|
+
.text;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
Array.prototype.toPageDto = function (
|
|
143
|
+
pageMetaDto: PageMetaDto,
|
|
144
|
+
options?: unknown,
|
|
145
|
+
) {
|
|
146
|
+
return new PageDto(this.toDtos(options), pageMetaDto);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
SelectQueryBuilder.prototype.searchByString = function (
|
|
150
|
+
q,
|
|
151
|
+
columnNames,
|
|
152
|
+
options,
|
|
153
|
+
) {
|
|
154
|
+
if (!q) {
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.andWhere(
|
|
159
|
+
new Brackets((qb) => {
|
|
160
|
+
for (const item of columnNames) {
|
|
161
|
+
qb.orWhere(`${item} ILIKE :q`);
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (options?.formStart) {
|
|
167
|
+
this.setParameter('q', `${q}%`);
|
|
168
|
+
} else {
|
|
169
|
+
this.setParameter('q', `%${q}%`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return this;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
SelectQueryBuilder.prototype.paginate = async function (
|
|
176
|
+
pageOptionsDto,
|
|
177
|
+
options,
|
|
178
|
+
) {
|
|
179
|
+
if (options?.takeAll) {
|
|
180
|
+
// 自动分页,返回所有数据和总数
|
|
181
|
+
let page = 0;
|
|
182
|
+
const all: any[] = [];
|
|
183
|
+
let batch: any[];
|
|
184
|
+
do {
|
|
185
|
+
batch = await this.clone()
|
|
186
|
+
.skip(page * pageOptionsDto.pageSize)
|
|
187
|
+
.take(pageOptionsDto.pageSize)
|
|
188
|
+
.getMany();
|
|
189
|
+
all.push(...batch);
|
|
190
|
+
page++;
|
|
191
|
+
} while (batch.length === pageOptionsDto.pageSize);
|
|
192
|
+
const itemCount = all.length;
|
|
193
|
+
const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto });
|
|
194
|
+
return [all, pageMetaDto];
|
|
195
|
+
} else {
|
|
196
|
+
this.skip(pageOptionsDto.skip).take(pageOptionsDto.pageSize);
|
|
197
|
+
const entities = await this.getMany();
|
|
198
|
+
let itemCount = -1;
|
|
199
|
+
if (!options?.skipCount) {
|
|
200
|
+
itemCount = await this.getCount();
|
|
201
|
+
}
|
|
202
|
+
const pageMetaDto = new PageMetaDto({
|
|
203
|
+
itemCount,
|
|
204
|
+
pageOptionsDto,
|
|
205
|
+
});
|
|
206
|
+
return [entities, pageMetaDto];
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
SelectQueryBuilder.prototype.withTenant = function (
|
|
211
|
+
tenantId?: number | string,
|
|
212
|
+
tenantFieldName: string = 'tenantId',
|
|
213
|
+
) {
|
|
214
|
+
if (!tenantId) {
|
|
215
|
+
tenantId = ContextProvider.getTenantId();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (this.expressionMap.mainAlias.hasMetadata) {
|
|
219
|
+
const entityMetadata = this.expressionMap.mainAlias.metadata;
|
|
220
|
+
const columnName = entityMetadata.columns.find(
|
|
221
|
+
(column: any) => column.propertyName === tenantFieldName,
|
|
222
|
+
)?.databaseName;
|
|
223
|
+
|
|
224
|
+
if (columnName) {
|
|
225
|
+
return this.andWhere(`${this.alias}.${columnName} = :tenantId`, {
|
|
226
|
+
tenantId,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return this;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
SelectQueryBuilder.prototype.iterate = function (
|
|
235
|
+
callbackOrBatchSize?: any,
|
|
236
|
+
batchSize?: number,
|
|
237
|
+
): any {
|
|
238
|
+
// 支持 iterate(batchSize) 或 iterate(callback, batchSize)
|
|
239
|
+
let callback: ((item: any) => Promise<void> | void) | undefined;
|
|
240
|
+
let realBatchSize = 1000;
|
|
241
|
+
if (typeof callbackOrBatchSize === 'function') {
|
|
242
|
+
callback = callbackOrBatchSize;
|
|
243
|
+
if (typeof batchSize === 'number') realBatchSize = batchSize;
|
|
244
|
+
} else if (typeof callbackOrBatchSize === 'number') {
|
|
245
|
+
realBatchSize = callbackOrBatchSize;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (callback) {
|
|
249
|
+
// callback模式,返回Promise<void>
|
|
250
|
+
return (async () => {
|
|
251
|
+
let page = 0;
|
|
252
|
+
let hasMore = true;
|
|
253
|
+
while (hasMore) {
|
|
254
|
+
const batch = await this.clone()
|
|
255
|
+
.skip(page * realBatchSize)
|
|
256
|
+
.take(realBatchSize)
|
|
257
|
+
.getMany();
|
|
258
|
+
for (const item of batch) {
|
|
259
|
+
await callback(item);
|
|
260
|
+
}
|
|
261
|
+
if (batch.length < realBatchSize) {
|
|
262
|
+
hasMore = false;
|
|
263
|
+
} else {
|
|
264
|
+
page++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
})();
|
|
268
|
+
} else {
|
|
269
|
+
// generator模式
|
|
270
|
+
return (async function* (that) {
|
|
271
|
+
let page = 0;
|
|
272
|
+
let hasMore = true;
|
|
273
|
+
while (hasMore) {
|
|
274
|
+
const batch = await that.clone()
|
|
275
|
+
.skip(page * realBatchSize)
|
|
276
|
+
.take(realBatchSize)
|
|
277
|
+
.getMany();
|
|
278
|
+
for (const item of batch) {
|
|
279
|
+
yield item;
|
|
280
|
+
}
|
|
281
|
+
if (batch.length < realBatchSize) {
|
|
282
|
+
hasMore = false;
|
|
283
|
+
} else {
|
|
284
|
+
page++;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
})(this);
|
|
288
|
+
}
|
|
289
|
+
};
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Nest Omni Core
|
|
2
|
+
|
|
3
|
+
Nest Omni Core 是一个为快速开发而设计的Nest.js脚手架核心包。它包含了构建高效、可维护的Nest.js应用程序所需的基础依赖和配置。
|
|
4
|
+
|
|
5
|
+
## 特点
|
|
6
|
+
|
|
7
|
+
- **预配置的Nest.js环境**:快速启动和运行Nest.js项目。
|
|
8
|
+
- **核心依赖集成**:包括了所有必要的Nest.js模块和中间件。
|
|
9
|
+
- **易于扩展**:简单的结构让您可以轻松添加更多功能。
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
1. 安装包:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @nest-omni/core
|
package/build.sh
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
files_to_copy=("package.json" ".npmignore" "yarn.lock" "../../.hygen" "../../.hygen.js")
|
|
4
|
+
|
|
5
|
+
if [ -d "dist" ]; then
|
|
6
|
+
rm -rf dist
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
yarn run build
|
|
10
|
+
|
|
11
|
+
if [ ! -d "dist" ]; then
|
|
12
|
+
echo "dist directory was not created by the build command."
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
# 新增测试版发布询问
|
|
17
|
+
read -p "是否发布测试版?(yes/no) " is_beta
|
|
18
|
+
|
|
19
|
+
# 版本号递增逻辑
|
|
20
|
+
if [[ "$is_beta" =~ ^[Yy](es)?$ ]]; then
|
|
21
|
+
npm version prerelease -m "Bump version for beta release"
|
|
22
|
+
else
|
|
23
|
+
npm version patch -m "Bump version for release"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
# 文件复制(注意调整到版本号递增之后)
|
|
27
|
+
for file in "${files_to_copy[@]}"; do
|
|
28
|
+
if [ -f "$file" ]; then
|
|
29
|
+
cp "$file" dist/
|
|
30
|
+
elif [ -d "$file" ]; then
|
|
31
|
+
cp -rf "$file" dist/
|
|
32
|
+
else
|
|
33
|
+
echo "Warning: $file does not exist and cannot be copied to dist."
|
|
34
|
+
fi
|
|
35
|
+
done
|
|
36
|
+
|
|
37
|
+
# 发布逻辑
|
|
38
|
+
cd dist || exit
|
|
39
|
+
if [[ "$is_beta" =~ ^[Yy](es)?$ ]]; then
|
|
40
|
+
npm publish --tag beta --access public
|
|
41
|
+
else
|
|
42
|
+
npm publish --access public
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
echo "Build completed, files copied to dist, and package published to npm."
|
|
@@ -13,6 +13,7 @@ exports.AbstractUuidPrimaryEntity = exports.AbstractTranslationEntity = exports.
|
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
14
|
const decorators_1 = require("../decorators");
|
|
15
15
|
const constants_1 = require("../constants");
|
|
16
|
+
const uuid_1 = require("uuid");
|
|
16
17
|
class AbstractBaseEntity {
|
|
17
18
|
toDto(options) {
|
|
18
19
|
const dtoClass = Object.getPrototypeOf(this).dtoClass;
|
|
@@ -51,6 +52,12 @@ __decorate([
|
|
|
51
52
|
__metadata("design:type", String)
|
|
52
53
|
], AbstractTranslationEntity.prototype, "languageCode", void 0);
|
|
53
54
|
class AbstractUuidPrimaryEntity extends AbstractBaseEntity {
|
|
55
|
+
generateId() {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!this.id || ((_a = this.id) === null || _a === void 0 ? void 0 : _a.length) < 2) {
|
|
58
|
+
this.id = (0, uuid_1.v4)();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
exports.AbstractUuidPrimaryEntity = AbstractUuidPrimaryEntity;
|
|
56
63
|
__decorate([
|
|
@@ -63,3 +70,9 @@ __decorate([
|
|
|
63
70
|
}),
|
|
64
71
|
__metadata("design:type", String)
|
|
65
72
|
], AbstractUuidPrimaryEntity.prototype, "id", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", []),
|
|
77
|
+
__metadata("design:returntype", void 0)
|
|
78
|
+
], AbstractUuidPrimaryEntity.prototype, "generateId", null);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nest-omni/core",
|
|
3
|
+
"version": "2.0.1-0",
|
|
4
|
+
"description": "framework",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.json",
|
|
9
|
+
"test": "jest --passWithNoTests",
|
|
10
|
+
"lint": "eslint 'src/**/*.ts' --fix"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"nest-omni": "nest start",
|
|
14
|
+
"i18n": "i18n",
|
|
15
|
+
"gen": "gen"
|
|
16
|
+
},
|
|
17
|
+
"author": "Jinpy",
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.4.5"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@dataui/crud": "^5.3.0",
|
|
24
|
+
"@dataui/crud-typeorm": "^5.3.0",
|
|
25
|
+
"@mvmdev/nestjs-redis-health": "^10.0.1",
|
|
26
|
+
"@nestjs/bull": "^10.0.1",
|
|
27
|
+
"@nestjs/cache-manager": "^2.1.0",
|
|
28
|
+
"@nestjs/common": "10.2.5",
|
|
29
|
+
"@nestjs/config": "^4.0.0",
|
|
30
|
+
"@nestjs/core": "10.2.5",
|
|
31
|
+
"@nestjs/microservices": "^10.2.5",
|
|
32
|
+
"@nestjs/platform-express": "^10.2.5",
|
|
33
|
+
"@nestjs/schedule": "^3.0.3",
|
|
34
|
+
"@nestjs/swagger": "^7.1.11",
|
|
35
|
+
"@nestjs/terminus": "^10.1.1",
|
|
36
|
+
"@nestjs/typeorm": "^10.0.0",
|
|
37
|
+
"@ntegral/nestjs-sentry": "^4.0.0",
|
|
38
|
+
"@sentry/node": "^7.69.0",
|
|
39
|
+
"axios": "^1.5.0",
|
|
40
|
+
"axios-retry": "^3.7.0",
|
|
41
|
+
"bcrypt": "5.1.0",
|
|
42
|
+
"bull": "^4.11.3",
|
|
43
|
+
"cache-manager-ioredis-yet": "^1.2.2",
|
|
44
|
+
"class-transformer": "~0.5.1",
|
|
45
|
+
"class-validator": "~0.14.0",
|
|
46
|
+
"connect-redis": "^7.1.0",
|
|
47
|
+
"express": "^4.18.2",
|
|
48
|
+
"express-session": "^1.17.3",
|
|
49
|
+
"libphonenumber-js": "^1.10.44",
|
|
50
|
+
"lodash": "^4.17.21",
|
|
51
|
+
"mime-types": "^2.1.35",
|
|
52
|
+
"moment": "^2.29.4",
|
|
53
|
+
"mysql2": "^3.6.1",
|
|
54
|
+
"nestjs-cls": "^4.3.0",
|
|
55
|
+
"nestjs-i18n": "^10.5.0",
|
|
56
|
+
"nestjs-pino": "^3.4.0",
|
|
57
|
+
"pino-http": "^8.5.0",
|
|
58
|
+
"pino-pretty": "^10.2.0",
|
|
59
|
+
"reflect-metadata": "^0.1.13",
|
|
60
|
+
"rxjs": "^7.8.1",
|
|
61
|
+
"skywalking-backend-js": "^0.6.0",
|
|
62
|
+
"source-map-support": "^0.5.21",
|
|
63
|
+
"sprintf-js": "^1.1.3",
|
|
64
|
+
"typeorm": "^0.3.17",
|
|
65
|
+
"typeorm-transactional": "~0.4.1",
|
|
66
|
+
"uuid": "^9.0.1"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"hygen": "^6.2.11"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
2
|
+
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
|
|
@@ -10,19 +10,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.bootstrapSetup = bootstrapSetup;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const session = require("express-session");
|
|
18
|
-
const bodyParse = require("body-parser");
|
|
13
|
+
const Sentry = require("@sentry/nestjs");
|
|
14
|
+
const profiling_node_1 = require("@sentry/profiling-node");
|
|
15
|
+
const dotenv = require("dotenv");
|
|
16
|
+
const fs_1 = require("fs");
|
|
19
17
|
const path_1 = require("path");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
const possibleRootPaths = [process.cwd(), __dirname];
|
|
19
|
+
const path0 = (0, path_1.join)(possibleRootPaths[0], 'config/base.env');
|
|
20
|
+
const path1 = (0, path_1.join)(possibleRootPaths[1], 'config/base.env');
|
|
21
|
+
if ((0, fs_1.existsSync)(path0)) {
|
|
22
|
+
dotenv.config({ path: path0 });
|
|
23
|
+
}
|
|
24
|
+
else if ((0, fs_1.existsSync)(path1)) {
|
|
25
|
+
dotenv.config({ path: path1 });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`No valid base.env file: ${path0} or ${path1}`);
|
|
29
|
+
}
|
|
30
|
+
const requiredEnvVars = ['SENTRY_DSN', 'API_VERSION', 'NODE_ENV'];
|
|
31
|
+
requiredEnvVars.forEach((envVar) => {
|
|
32
|
+
if (!process.env[envVar]) {
|
|
33
|
+
throw new Error(`Missing required environment variable: ${envVar}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Sentry.init({
|
|
37
|
+
dsn: process.env.SENTRY_DSN || '',
|
|
38
|
+
release: process.env.API_VERSION || '',
|
|
39
|
+
environment: process.env.NODE_ENV || 'unkown',
|
|
40
|
+
debug: process.env.NODE_ENV === 'dev',
|
|
41
|
+
tracesSampleRate: 1.0,
|
|
42
|
+
profileSessionSampleRate: 1.0,
|
|
43
|
+
profileLifecycle: 'trace',
|
|
44
|
+
sendDefaultPii: true,
|
|
45
|
+
integrations: [profiling_node_1.nodeProfilingIntegration],
|
|
46
|
+
});
|
|
24
47
|
const crud_1 = require("@dataui/crud");
|
|
25
|
-
const nestjs_cls_1 = require("nestjs-cls");
|
|
26
48
|
crud_1.CrudConfigService.load({
|
|
27
49
|
auth: {
|
|
28
50
|
property: 'user',
|
|
@@ -50,6 +72,16 @@ crud_1.CrudConfigService.load({
|
|
|
50
72
|
},
|
|
51
73
|
},
|
|
52
74
|
});
|
|
75
|
+
const core_1 = require("@nestjs/core");
|
|
76
|
+
const typeorm_transactional_1 = require("typeorm-transactional");
|
|
77
|
+
const nestjs_pino_1 = require("nestjs-pino");
|
|
78
|
+
const session = require("express-session");
|
|
79
|
+
const bodyParse = require("body-parser");
|
|
80
|
+
const __1 = require("../");
|
|
81
|
+
const common_1 = require("@nestjs/common");
|
|
82
|
+
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
83
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
84
|
+
const setup_1 = require("@sentry/nestjs/setup");
|
|
53
85
|
const setupProcessHandlers = (app) => {
|
|
54
86
|
const logger = app.get(nestjs_pino_1.Logger);
|
|
55
87
|
process.on('uncaughtException', (error) => {
|
|
@@ -126,18 +158,8 @@ function bootstrapSetup(AppModule, SetupSwagger) {
|
|
|
126
158
|
app.enable('trust proxy');
|
|
127
159
|
app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)());
|
|
128
160
|
const reflector = app.get(core_1.Reflector);
|
|
129
|
-
app.useGlobalFilters(new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
|
|
130
|
-
app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor()
|
|
131
|
-
filters: [
|
|
132
|
-
{
|
|
133
|
-
type: common_1.HttpException,
|
|
134
|
-
filter: (exception) => {
|
|
135
|
-
const status = exception.getStatus();
|
|
136
|
-
return status === 401 || status === 404 || 200 > status;
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
}));
|
|
161
|
+
app.useGlobalFilters(new setup_1.SentryGlobalFilter(), new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
|
|
162
|
+
app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor());
|
|
141
163
|
app.useGlobalPipes(new nestjs_i18n_1.I18nValidationPipe({
|
|
142
164
|
whitelist: true,
|
|
143
165
|
errorHttpStatusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
|
|
@@ -145,10 +167,6 @@ function bootstrapSetup(AppModule, SetupSwagger) {
|
|
|
145
167
|
stopAtFirstError: true,
|
|
146
168
|
validationError: { target: false, value: false },
|
|
147
169
|
}));
|
|
148
|
-
if (configService.skywalkingEnabled) {
|
|
149
|
-
skywalking_backend_js_1.default.start();
|
|
150
|
-
logger.log('SkyWalking agent initialized');
|
|
151
|
-
}
|
|
152
170
|
if (configService.documentationEnabled && SetupSwagger) {
|
|
153
171
|
SetupSwagger(app, configService.documentationPath);
|
|
154
172
|
logger.log(`Swagger docs available at ${configService.documentationPath}`);
|
|
@@ -25,7 +25,7 @@ const config_1 = require("@nestjs/config");
|
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
26
|
const typeorm_2 = require("@nestjs/typeorm");
|
|
27
27
|
const schedule_1 = require("@nestjs/schedule");
|
|
28
|
-
const
|
|
28
|
+
const setup_1 = require("@sentry/nestjs/setup");
|
|
29
29
|
const cache_manager_1 = require("@nestjs/cache-manager");
|
|
30
30
|
const typeorm_transactional_1 = require("typeorm-transactional");
|
|
31
31
|
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
@@ -77,12 +77,7 @@ const modules = [
|
|
|
77
77
|
expandVariables: false,
|
|
78
78
|
envFilePath: [envFilePath, baseEnvFilePath],
|
|
79
79
|
}),
|
|
80
|
-
|
|
81
|
-
inject: [services_1.ApiConfigService],
|
|
82
|
-
useFactory(configService) {
|
|
83
|
-
return configService.sentryConfig;
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
80
|
+
setup_1.SentryModule.forRoot(),
|
|
86
81
|
nestjs_pino_1.LoggerModule.forRootAsync({
|
|
87
82
|
inject: [services_1.ApiConfigService],
|
|
88
83
|
useFactory: (config) => config.pinoConfig,
|
|
@@ -101,9 +96,6 @@ const modules = [
|
|
|
101
96
|
}),
|
|
102
97
|
health_checker_module_1.HealthCheckerModule,
|
|
103
98
|
];
|
|
104
|
-
if (services_1.ApiConfigService.toBoolean(process.env.S3_ENABLED, false)) {
|
|
105
|
-
providers.push(services_1.AwsS3Service);
|
|
106
|
-
}
|
|
107
99
|
if (services_1.ApiConfigService.toBoolean(process.env.DB_ENABLED, true)) {
|
|
108
100
|
modules.push(typeorm_2.TypeOrmModule.forRootAsync({
|
|
109
101
|
inject: [services_1.ApiConfigService],
|
|
@@ -122,6 +114,7 @@ if (services_1.ApiConfigService.toBoolean(process.env.BULL_ENABLED)) {
|
|
|
122
114
|
if (services_1.ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
|
|
123
115
|
modules.push(cache_manager_1.CacheModule.registerAsync({
|
|
124
116
|
inject: [services_1.ApiConfigService],
|
|
117
|
+
isGlobal: true,
|
|
125
118
|
useFactory: (config) => config.cacheConfig(),
|
|
126
119
|
}));
|
|
127
120
|
}
|
|
@@ -136,6 +129,6 @@ exports.ServiceRegistryModule = ServiceRegistryModule = __decorate([
|
|
|
136
129
|
(0, common_1.Module)({
|
|
137
130
|
providers,
|
|
138
131
|
imports: modules,
|
|
139
|
-
exports: [...providers
|
|
132
|
+
exports: [...providers],
|
|
140
133
|
})
|
|
141
134
|
], ServiceRegistryModule);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
2
|
import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
3
|
-
import { SentryModuleOptions } from '@ntegral/nestjs-sentry/lib/sentry.interfaces';
|
|
4
3
|
import session from 'express-session';
|
|
5
4
|
import { Params } from 'nestjs-pino';
|
|
6
5
|
import { BullRootModuleOptions } from '@nestjs/bull/dist/interfaces/bull-module-options.interface';
|
|
@@ -12,36 +11,25 @@ export declare class ApiConfigService {
|
|
|
12
11
|
constructor(configService: ConfigService);
|
|
13
12
|
static getRootPath(): string;
|
|
14
13
|
get isDev(): boolean;
|
|
14
|
+
get apiVersion(): string;
|
|
15
15
|
get isProd(): boolean;
|
|
16
16
|
get isSit(): boolean;
|
|
17
17
|
get isUat(): boolean;
|
|
18
18
|
get isTest(): boolean;
|
|
19
|
-
getNumber(key: string): number;
|
|
20
|
-
getBoolean(key: string): boolean;
|
|
19
|
+
getNumber(key: string, defaultValue?: number): number;
|
|
20
|
+
getBoolean(key: string, defaultValue?: boolean): boolean;
|
|
21
21
|
static toBoolean(value: string, defaultValue?: any): boolean;
|
|
22
22
|
getString(key: string): string;
|
|
23
23
|
get nodeEnv(): string;
|
|
24
24
|
get fallbackLanguage(): string;
|
|
25
|
-
get sentryConfig(): SentryModuleOptions;
|
|
26
25
|
get typeormConfig(): TypeOrmModuleOptions;
|
|
27
|
-
get awsS3Config(): {
|
|
28
|
-
bucketRegion: string;
|
|
29
|
-
bucketApiVersion: string;
|
|
30
|
-
bucketName: string;
|
|
31
|
-
};
|
|
32
26
|
get documentationEnabled(): boolean;
|
|
33
27
|
get documentationPath(): string;
|
|
34
|
-
get skywalkingEnabled(): boolean;
|
|
35
28
|
get viewsEnabled(): boolean;
|
|
36
29
|
get sessionEnabled(): boolean;
|
|
37
30
|
get corsEnabled(): boolean;
|
|
38
31
|
get corsConfig(): CorsOptions;
|
|
39
32
|
get sessionConfig(): session.SessionOptions;
|
|
40
|
-
get natsEnabled(): boolean;
|
|
41
|
-
get natsConfig(): {
|
|
42
|
-
host: string;
|
|
43
|
-
port: number;
|
|
44
|
-
};
|
|
45
33
|
get authConfig(): {
|
|
46
34
|
privateKey: string;
|
|
47
35
|
publicKey: string;
|