@nest-omni/core 2.0.1-0 → 2.0.1-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/package.json +1 -1
- 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/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.decorator.js +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}/bootstrap.setup.js +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}/serviceRegistryModule.js +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/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +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,317 +0,0 @@
|
|
|
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
|
-
* 自动分页,返回所有数据(分批查询)
|
|
105
|
-
* @param pageSize 每页大小,默认1000
|
|
106
|
-
* @returns Promise<Entity[]>
|
|
107
|
-
*/
|
|
108
|
-
autoPaginate(
|
|
109
|
-
this: SelectQueryBuilder<Entity>,
|
|
110
|
-
pageSize?: number,
|
|
111
|
-
): Promise<Entity[]>;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 通过异步生成器迭代QueryBuilder结果
|
|
115
|
-
* @param batchSize 每批大小,默认1000
|
|
116
|
-
* @returns AsyncGenerator<Entity, void, unknown>
|
|
117
|
-
*/
|
|
118
|
-
iterate(
|
|
119
|
-
this: SelectQueryBuilder<Entity>,
|
|
120
|
-
batchSize?: number,
|
|
121
|
-
): AsyncGenerator<Entity, void, unknown>;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 通过callback处理每个item,无需外部循环
|
|
125
|
-
* @param callback 处理函数
|
|
126
|
-
* @param batchSize 每批大小,默认1000
|
|
127
|
-
* @returns Promise<void>
|
|
128
|
-
*/
|
|
129
|
-
iterate(
|
|
130
|
-
this: SelectQueryBuilder<Entity>,
|
|
131
|
-
callback: (item: Entity) => Promise<void> | void,
|
|
132
|
-
batchSize?: number,
|
|
133
|
-
): Promise<void>;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
Array.prototype.toDtos = function <
|
|
138
|
-
Entity extends AbstractEntity<Dto>,
|
|
139
|
-
Dto extends AbstractDto,
|
|
140
|
-
>(options?: unknown): Dto[] {
|
|
141
|
-
return compact(
|
|
142
|
-
map<Entity, Dto>(this as Entity[], (item) => item.toDto(options as never)),
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
Array.prototype.getByLanguage = function (languageCode: LanguageCode): string {
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
148
|
-
return this.find((translation) => languageCode === translation.languageCode)!
|
|
149
|
-
.text;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
Array.prototype.toPageDto = function (
|
|
153
|
-
pageMetaDto: PageMetaDto,
|
|
154
|
-
options?: unknown,
|
|
155
|
-
) {
|
|
156
|
-
return new PageDto(this.toDtos(options), pageMetaDto);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
SelectQueryBuilder.prototype.searchByString = function (
|
|
160
|
-
q,
|
|
161
|
-
columnNames,
|
|
162
|
-
options,
|
|
163
|
-
) {
|
|
164
|
-
if (!q) {
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.andWhere(
|
|
169
|
-
new Brackets((qb) => {
|
|
170
|
-
for (const item of columnNames) {
|
|
171
|
-
qb.orWhere(`${item} ILIKE :q`);
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
if (options?.formStart) {
|
|
177
|
-
this.setParameter('q', `${q}%`);
|
|
178
|
-
} else {
|
|
179
|
-
this.setParameter('q', `%${q}%`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return this;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
SelectQueryBuilder.prototype.paginate = async function (
|
|
186
|
-
pageOptionsDto,
|
|
187
|
-
options,
|
|
188
|
-
) {
|
|
189
|
-
if (options?.takeAll) {
|
|
190
|
-
// 自动分页,返回所有数据和总数
|
|
191
|
-
let page = 0;
|
|
192
|
-
const all: any[] = [];
|
|
193
|
-
let batch: any[];
|
|
194
|
-
do {
|
|
195
|
-
batch = await this.clone()
|
|
196
|
-
.skip(page * pageOptionsDto.pageSize)
|
|
197
|
-
.take(pageOptionsDto.pageSize)
|
|
198
|
-
.getMany();
|
|
199
|
-
all.push(...batch);
|
|
200
|
-
page++;
|
|
201
|
-
} while (batch.length === pageOptionsDto.pageSize);
|
|
202
|
-
const itemCount = all.length;
|
|
203
|
-
const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto });
|
|
204
|
-
return [all, pageMetaDto];
|
|
205
|
-
} else {
|
|
206
|
-
this.skip(pageOptionsDto.skip).take(pageOptionsDto.pageSize);
|
|
207
|
-
const entities = await this.getMany();
|
|
208
|
-
let itemCount = -1;
|
|
209
|
-
if (!options?.skipCount) {
|
|
210
|
-
itemCount = await this.getCount();
|
|
211
|
-
}
|
|
212
|
-
const pageMetaDto = new PageMetaDto({
|
|
213
|
-
itemCount,
|
|
214
|
-
pageOptionsDto,
|
|
215
|
-
});
|
|
216
|
-
return [entities, pageMetaDto];
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
SelectQueryBuilder.prototype.withTenant = function (
|
|
221
|
-
tenantId?: number | string,
|
|
222
|
-
tenantFieldName: string = 'tenantId',
|
|
223
|
-
) {
|
|
224
|
-
if (!tenantId) {
|
|
225
|
-
tenantId = ContextProvider.getTenantId();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (this.expressionMap.mainAlias.hasMetadata) {
|
|
229
|
-
const entityMetadata = this.expressionMap.mainAlias.metadata;
|
|
230
|
-
const columnName = entityMetadata.columns.find(
|
|
231
|
-
(column: any) => column.propertyName === tenantFieldName,
|
|
232
|
-
)?.databaseName;
|
|
233
|
-
|
|
234
|
-
if (columnName) {
|
|
235
|
-
return this.andWhere(`${this.alias}.${columnName} = :tenantId`, {
|
|
236
|
-
tenantId,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return this;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
SelectQueryBuilder.prototype.autoPaginate = async function (pageSize = 1000) {
|
|
245
|
-
let page = 0;
|
|
246
|
-
let hasMore = true;
|
|
247
|
-
const all: any[] = [];
|
|
248
|
-
while (hasMore) {
|
|
249
|
-
const batch = await this.clone()
|
|
250
|
-
.skip(page * pageSize)
|
|
251
|
-
.take(pageSize)
|
|
252
|
-
.getMany();
|
|
253
|
-
all.push(...batch);
|
|
254
|
-
if (batch.length < pageSize) {
|
|
255
|
-
hasMore = false;
|
|
256
|
-
} else {
|
|
257
|
-
page++;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return all;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
SelectQueryBuilder.prototype.iterate = function (callbackOrBatchSize?: any, batchSize?: number): any {
|
|
264
|
-
// 支持 iterate(batchSize) 或 iterate(callback, batchSize)
|
|
265
|
-
let callback: ((item: any) => Promise<void> | void) | undefined;
|
|
266
|
-
let realBatchSize = 1000;
|
|
267
|
-
if (typeof callbackOrBatchSize === 'function') {
|
|
268
|
-
callback = callbackOrBatchSize;
|
|
269
|
-
if (typeof batchSize === 'number') realBatchSize = batchSize;
|
|
270
|
-
} else if (typeof callbackOrBatchSize === 'number') {
|
|
271
|
-
realBatchSize = callbackOrBatchSize;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const self = this;
|
|
275
|
-
|
|
276
|
-
if (callback) {
|
|
277
|
-
// callback模式,返回Promise<void>
|
|
278
|
-
return (async function () {
|
|
279
|
-
let page = 0;
|
|
280
|
-
let hasMore = true;
|
|
281
|
-
while (hasMore) {
|
|
282
|
-
const batch = await self.clone()
|
|
283
|
-
.skip(page * realBatchSize)
|
|
284
|
-
.take(realBatchSize)
|
|
285
|
-
.getMany();
|
|
286
|
-
for (const item of batch) {
|
|
287
|
-
await callback(item);
|
|
288
|
-
}
|
|
289
|
-
if (batch.length < realBatchSize) {
|
|
290
|
-
hasMore = false;
|
|
291
|
-
} else {
|
|
292
|
-
page++;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
})();
|
|
296
|
-
} else {
|
|
297
|
-
// generator模式
|
|
298
|
-
return (async function* () {
|
|
299
|
-
let page = 0;
|
|
300
|
-
let hasMore = true;
|
|
301
|
-
while (hasMore) {
|
|
302
|
-
const batch = await self.clone()
|
|
303
|
-
.skip(page * realBatchSize)
|
|
304
|
-
.take(realBatchSize)
|
|
305
|
-
.getMany();
|
|
306
|
-
for (const item of batch) {
|
|
307
|
-
yield item;
|
|
308
|
-
}
|
|
309
|
-
if (batch.length < realBatchSize) {
|
|
310
|
-
hasMore = false;
|
|
311
|
-
} else {
|
|
312
|
-
page++;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
})();
|
|
316
|
-
}
|
|
317
|
-
};
|
|
@@ -1,319 +0,0 @@
|
|
|
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
|
-
* 自动分页,返回所有数据(分批查询)
|
|
105
|
-
* @param pageSize 每页大小,默认1000
|
|
106
|
-
* @returns Promise<Entity[]>
|
|
107
|
-
*/
|
|
108
|
-
autoPaginate(
|
|
109
|
-
this: SelectQueryBuilder<Entity>,
|
|
110
|
-
pageSize?: number,
|
|
111
|
-
): Promise<Entity[]>;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 通过异步生成器迭代QueryBuilder结果
|
|
115
|
-
* @param batchSize 每批大小,默认1000
|
|
116
|
-
* @returns AsyncGenerator<Entity, void, unknown>
|
|
117
|
-
*/
|
|
118
|
-
iterate(
|
|
119
|
-
this: SelectQueryBuilder<Entity>,
|
|
120
|
-
batchSize?: number,
|
|
121
|
-
): AsyncGenerator<Entity, void, unknown>;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 通过callback处理每个item,无需外部循环
|
|
125
|
-
* @param callback 处理函数
|
|
126
|
-
* @param batchSize 每批大小,默认1000
|
|
127
|
-
* @returns Promise<void>
|
|
128
|
-
*/
|
|
129
|
-
iterate(
|
|
130
|
-
this: SelectQueryBuilder<Entity>,
|
|
131
|
-
callback: (item: Entity) => Promise<void> | void,
|
|
132
|
-
batchSize?: number,
|
|
133
|
-
): Promise<void>;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
Array.prototype.toDtos = function <
|
|
138
|
-
Entity extends AbstractEntity<Dto>,
|
|
139
|
-
Dto extends AbstractDto,
|
|
140
|
-
>(options?: unknown): Dto[] {
|
|
141
|
-
return compact(
|
|
142
|
-
map<Entity, Dto>(this as Entity[], (item) => item.toDto(options as never)),
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
Array.prototype.getByLanguage = function (languageCode: LanguageCode): string {
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
148
|
-
return this.find((translation) => languageCode === translation.languageCode)!
|
|
149
|
-
.text;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
Array.prototype.toPageDto = function (
|
|
153
|
-
pageMetaDto: PageMetaDto,
|
|
154
|
-
options?: unknown,
|
|
155
|
-
) {
|
|
156
|
-
return new PageDto(this.toDtos(options), pageMetaDto);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
SelectQueryBuilder.prototype.searchByString = function (
|
|
160
|
-
q,
|
|
161
|
-
columnNames,
|
|
162
|
-
options,
|
|
163
|
-
) {
|
|
164
|
-
if (!q) {
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.andWhere(
|
|
169
|
-
new Brackets((qb) => {
|
|
170
|
-
for (const item of columnNames) {
|
|
171
|
-
qb.orWhere(`${item} ILIKE :q`);
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
if (options?.formStart) {
|
|
177
|
-
this.setParameter('q', `${q}%`);
|
|
178
|
-
} else {
|
|
179
|
-
this.setParameter('q', `%${q}%`);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return this;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
SelectQueryBuilder.prototype.paginate = async function (
|
|
186
|
-
pageOptionsDto,
|
|
187
|
-
options,
|
|
188
|
-
) {
|
|
189
|
-
if (options?.takeAll) {
|
|
190
|
-
// 自动分页,返回所有数据和总数
|
|
191
|
-
let page = 0;
|
|
192
|
-
const all: any[] = [];
|
|
193
|
-
let batch: any[];
|
|
194
|
-
do {
|
|
195
|
-
batch = await this.clone()
|
|
196
|
-
.skip(page * pageOptionsDto.pageSize)
|
|
197
|
-
.take(pageOptionsDto.pageSize)
|
|
198
|
-
.getMany();
|
|
199
|
-
all.push(...batch);
|
|
200
|
-
page++;
|
|
201
|
-
} while (batch.length === pageOptionsDto.pageSize);
|
|
202
|
-
const itemCount = all.length;
|
|
203
|
-
const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto });
|
|
204
|
-
return [all, pageMetaDto];
|
|
205
|
-
} else {
|
|
206
|
-
this.skip(pageOptionsDto.skip).take(pageOptionsDto.pageSize);
|
|
207
|
-
const entities = await this.getMany();
|
|
208
|
-
let itemCount = -1;
|
|
209
|
-
if (!options?.skipCount) {
|
|
210
|
-
itemCount = await this.getCount();
|
|
211
|
-
}
|
|
212
|
-
const pageMetaDto = new PageMetaDto({
|
|
213
|
-
itemCount,
|
|
214
|
-
pageOptionsDto,
|
|
215
|
-
});
|
|
216
|
-
return [entities, pageMetaDto];
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
SelectQueryBuilder.prototype.withTenant = function (
|
|
221
|
-
tenantId?: number | string,
|
|
222
|
-
tenantFieldName: string = 'tenantId',
|
|
223
|
-
) {
|
|
224
|
-
if (!tenantId) {
|
|
225
|
-
tenantId = ContextProvider.getTenantId();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (this.expressionMap.mainAlias.hasMetadata) {
|
|
229
|
-
const entityMetadata = this.expressionMap.mainAlias.metadata;
|
|
230
|
-
const columnName = entityMetadata.columns.find(
|
|
231
|
-
(column: any) => column.propertyName === tenantFieldName,
|
|
232
|
-
)?.databaseName;
|
|
233
|
-
|
|
234
|
-
if (columnName) {
|
|
235
|
-
return this.andWhere(`${this.alias}.${columnName} = :tenantId`, {
|
|
236
|
-
tenantId,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return this;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
SelectQueryBuilder.prototype.autoPaginate = async function (pageSize = 1000) {
|
|
245
|
-
let page = 0;
|
|
246
|
-
let hasMore = true;
|
|
247
|
-
const all: any[] = [];
|
|
248
|
-
while (hasMore) {
|
|
249
|
-
const batch = await this.clone()
|
|
250
|
-
.skip(page * pageSize)
|
|
251
|
-
.take(pageSize)
|
|
252
|
-
.getMany();
|
|
253
|
-
all.push(...batch);
|
|
254
|
-
if (batch.length < pageSize) {
|
|
255
|
-
hasMore = false;
|
|
256
|
-
} else {
|
|
257
|
-
page++;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return all;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
SelectQueryBuilder.prototype.iterate = function (
|
|
264
|
-
callbackOrBatchSize?: any,
|
|
265
|
-
batchSize?: number,
|
|
266
|
-
): any {
|
|
267
|
-
// 支持 iterate(batchSize) 或 iterate(callback, batchSize)
|
|
268
|
-
let callback: ((item: any) => Promise<void> | void) | undefined;
|
|
269
|
-
let realBatchSize = 1000;
|
|
270
|
-
if (typeof callbackOrBatchSize === 'function') {
|
|
271
|
-
callback = callbackOrBatchSize;
|
|
272
|
-
if (typeof batchSize === 'number') realBatchSize = batchSize;
|
|
273
|
-
} else if (typeof callbackOrBatchSize === 'number') {
|
|
274
|
-
realBatchSize = callbackOrBatchSize;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (callback) {
|
|
278
|
-
// callback模式,返回Promise<void>
|
|
279
|
-
return (async () => {
|
|
280
|
-
let page = 0;
|
|
281
|
-
let hasMore = true;
|
|
282
|
-
while (hasMore) {
|
|
283
|
-
const batch = await this.clone()
|
|
284
|
-
.skip(page * realBatchSize)
|
|
285
|
-
.take(realBatchSize)
|
|
286
|
-
.getMany();
|
|
287
|
-
for (const item of batch) {
|
|
288
|
-
await callback(item);
|
|
289
|
-
}
|
|
290
|
-
if (batch.length < realBatchSize) {
|
|
291
|
-
hasMore = false;
|
|
292
|
-
} else {
|
|
293
|
-
page++;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
})();
|
|
297
|
-
} else {
|
|
298
|
-
// generator模式
|
|
299
|
-
return (async function* (that) {
|
|
300
|
-
let page = 0;
|
|
301
|
-
let hasMore = true;
|
|
302
|
-
while (hasMore) {
|
|
303
|
-
const batch = await that.clone()
|
|
304
|
-
.skip(page * realBatchSize)
|
|
305
|
-
.take(realBatchSize)
|
|
306
|
-
.getMany();
|
|
307
|
-
for (const item of batch) {
|
|
308
|
-
yield item;
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
if (batch.length < realBatchSize) {
|
|
312
|
-
hasMore = false;
|
|
313
|
-
} else {
|
|
314
|
-
page++;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
})(this);
|
|
318
|
-
}
|
|
319
|
-
};
|