@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,257 +0,0 @@
|
|
|
1
|
-
import * as cv from 'class-validator';
|
|
2
|
-
import { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata';
|
|
3
|
-
import { groupBy, isEmpty, isString, reject } from 'lodash';
|
|
4
|
-
import { defaultConverters } from './defaultConverters';
|
|
5
|
-
import { defaultOptions, IOptions } from './options';
|
|
6
|
-
import { I18nService } from 'nestjs-i18n';
|
|
7
|
-
|
|
8
|
-
export { JSONSchema } from './decorators';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Convert an array of class-validator metadata into JSON Schema definitions.
|
|
12
|
-
*/
|
|
13
|
-
export function validationMetadataArrayToSchemas(
|
|
14
|
-
metadatas: ValidationMetadata[],
|
|
15
|
-
i18n,
|
|
16
|
-
userOptions?: Partial<IOptions>,
|
|
17
|
-
): any {
|
|
18
|
-
const options: IOptions = {
|
|
19
|
-
...defaultOptions,
|
|
20
|
-
...userOptions,
|
|
21
|
-
};
|
|
22
|
-
const rules = [];
|
|
23
|
-
|
|
24
|
-
Object.entries(
|
|
25
|
-
groupBy(
|
|
26
|
-
metadatas,
|
|
27
|
-
({ target }) =>
|
|
28
|
-
target[options.schemaNameField as keyof typeof target] ??
|
|
29
|
-
(target as Function).name,
|
|
30
|
-
),
|
|
31
|
-
).forEach(([key, ownMetas]) => {
|
|
32
|
-
const target = ownMetas[0].target as Function;
|
|
33
|
-
const metas = ownMetas
|
|
34
|
-
.concat(getInheritedMetadatas(target, metadatas))
|
|
35
|
-
.filter(
|
|
36
|
-
(propMeta) =>
|
|
37
|
-
!(
|
|
38
|
-
isExcluded(propMeta, options) ||
|
|
39
|
-
isExcluded({ ...propMeta, target }, options)
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const required = getRequiredPropNames(target, metas, options);
|
|
44
|
-
|
|
45
|
-
Object.entries(groupBy(metas, 'propertyName')).forEach(
|
|
46
|
-
([propName, propMetas]) => {
|
|
47
|
-
const schema = applyConverters(propMetas, options, i18n);
|
|
48
|
-
const filterSchema = schema.filter(
|
|
49
|
-
(item) => !['conditionalValidation', 'notEquals'].includes(item.type),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const fieldType = getFirstNonNullDataType(filterSchema);
|
|
53
|
-
rules.push({
|
|
54
|
-
field: propName,
|
|
55
|
-
fieldType,
|
|
56
|
-
required: required.includes(propName),
|
|
57
|
-
constraints: filterSchema,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return rules;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getFirstNonNullDataType(data: any[]): string | undefined {
|
|
67
|
-
for (const item of data) {
|
|
68
|
-
const dataType = item.dataType;
|
|
69
|
-
delete item.dataType;
|
|
70
|
-
if (dataType) {
|
|
71
|
-
return dataType;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Generate JSON Schema definitions from the target object constructor.
|
|
79
|
-
*/
|
|
80
|
-
export function targetConstructorToSchema(
|
|
81
|
-
targetConstructor: Function,
|
|
82
|
-
i18n: I18nService,
|
|
83
|
-
userOptions?: Partial<IOptions>,
|
|
84
|
-
): any {
|
|
85
|
-
const options: IOptions = {
|
|
86
|
-
...defaultOptions,
|
|
87
|
-
...userOptions,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const storage = options.classValidatorMetadataStorage;
|
|
91
|
-
let metadatas = storage.getTargetValidationMetadatas(
|
|
92
|
-
targetConstructor,
|
|
93
|
-
'',
|
|
94
|
-
true,
|
|
95
|
-
false,
|
|
96
|
-
);
|
|
97
|
-
metadatas = populateMetadatasWithConstraints(storage, metadatas);
|
|
98
|
-
return validationMetadataArrayToSchemas(metadatas, i18n, userOptions);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function populateMetadatasWithConstraints(
|
|
102
|
-
storage: cv.MetadataStorage,
|
|
103
|
-
metadatas: ValidationMetadata[],
|
|
104
|
-
): ValidationMetadata[] {
|
|
105
|
-
return metadatas.map((meta) => {
|
|
106
|
-
if (meta.constraintCls) {
|
|
107
|
-
const constraint = storage.getTargetValidatorConstraints(
|
|
108
|
-
meta.constraintCls,
|
|
109
|
-
);
|
|
110
|
-
if (constraint.length > 0) {
|
|
111
|
-
return { ...meta, type: constraint[0].name };
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return { ...meta };
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Return target class' inherited validation metadatas, with original metadatas
|
|
120
|
-
* given precedence over inherited ones in case of duplicates.
|
|
121
|
-
*
|
|
122
|
-
* Adapted from `class-validator` source.
|
|
123
|
-
*
|
|
124
|
-
* @param target Target child class.
|
|
125
|
-
* @param metadatas All class-validator metadata objects.
|
|
126
|
-
*/
|
|
127
|
-
function getInheritedMetadatas(
|
|
128
|
-
target: Function,
|
|
129
|
-
metadatas: ValidationMetadata[],
|
|
130
|
-
) {
|
|
131
|
-
return metadatas.filter(
|
|
132
|
-
(d) =>
|
|
133
|
-
d.target instanceof Function &&
|
|
134
|
-
target.prototype instanceof d.target &&
|
|
135
|
-
!metadatas.find(
|
|
136
|
-
(m) =>
|
|
137
|
-
m.propertyName === d.propertyName &&
|
|
138
|
-
m.target === target &&
|
|
139
|
-
m.type === d.type,
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Convert a property's class-validator metadata into a JSON Schema property.
|
|
146
|
-
*/
|
|
147
|
-
function applyConverters(
|
|
148
|
-
propertyMetadatas: ValidationMetadata[],
|
|
149
|
-
options: IOptions,
|
|
150
|
-
i18n: I18nService,
|
|
151
|
-
): any {
|
|
152
|
-
const converters = { ...defaultConverters, ...options.additionalConverters };
|
|
153
|
-
|
|
154
|
-
const convert = (meta: ValidationMetadata) => {
|
|
155
|
-
const typeMeta = options.classTransformerMetadataStorage?.findTypeMetadata(
|
|
156
|
-
meta.target as Function,
|
|
157
|
-
meta.propertyName,
|
|
158
|
-
);
|
|
159
|
-
const isMap =
|
|
160
|
-
typeMeta &&
|
|
161
|
-
typeMeta.reflectedType &&
|
|
162
|
-
new typeMeta.reflectedType() instanceof Map;
|
|
163
|
-
|
|
164
|
-
const converter =
|
|
165
|
-
converters[meta.type] || converters[cv.ValidationTypes.CUSTOM_VALIDATION];
|
|
166
|
-
|
|
167
|
-
const converterResult =
|
|
168
|
-
typeof converter === 'function' ? converter(meta, options) : converter;
|
|
169
|
-
|
|
170
|
-
const items = {};
|
|
171
|
-
let message = '';
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
const originMessage = typeof meta.message === 'function' ? meta.message(meta) : meta.message;
|
|
174
|
-
if (isString(originMessage)) {
|
|
175
|
-
const [translationKey, argsString] = originMessage.split('|');
|
|
176
|
-
const args = !!argsString ? JSON.parse(argsString) : {};
|
|
177
|
-
message = i18n.translate(translationKey, {
|
|
178
|
-
...options,
|
|
179
|
-
args: {
|
|
180
|
-
constraints: meta.constraints,
|
|
181
|
-
...args,
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
items['type'] = meta.type;
|
|
186
|
-
items['dataType'] = converterResult?.type || undefined;
|
|
187
|
-
items['attrs'] = meta.constraints || [];
|
|
188
|
-
items['message'] = message;
|
|
189
|
-
|
|
190
|
-
if (meta.each && isMap) {
|
|
191
|
-
return {
|
|
192
|
-
additionalProperties: {
|
|
193
|
-
...items,
|
|
194
|
-
},
|
|
195
|
-
type: 'object',
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
return meta.each ? { items, type: 'array' } : items;
|
|
199
|
-
};
|
|
200
|
-
// const constraints = [];
|
|
201
|
-
const constraints = propertyMetadatas.map((meta) => {
|
|
202
|
-
return convert(meta);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
return reject(constraints, (item) => isEmpty(item));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** Check whether property is excluded with class-transformer `@Exclude` decorator. */
|
|
209
|
-
function isExcluded(
|
|
210
|
-
propertyMetadata: ValidationMetadata,
|
|
211
|
-
options: IOptions,
|
|
212
|
-
): boolean {
|
|
213
|
-
return !!options.classTransformerMetadataStorage?.findExcludeMetadata(
|
|
214
|
-
propertyMetadata.target as Function,
|
|
215
|
-
propertyMetadata.propertyName,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Get the required property names of a validated class.
|
|
221
|
-
* @param target Validation target class.
|
|
222
|
-
* @param metadatas Validation metadata objects of the validated class.
|
|
223
|
-
* @param options Global class-validator options.
|
|
224
|
-
*/
|
|
225
|
-
function getRequiredPropNames(
|
|
226
|
-
target: Function,
|
|
227
|
-
metadatas: ValidationMetadata[],
|
|
228
|
-
options: IOptions,
|
|
229
|
-
) {
|
|
230
|
-
function isDefined(metas: ValidationMetadata[]) {
|
|
231
|
-
return (
|
|
232
|
-
metas && metas.some(({ type }) => type === cv.ValidationTypes.IS_DEFINED)
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function isOptional(metas: ValidationMetadata[]) {
|
|
237
|
-
return (
|
|
238
|
-
metas &&
|
|
239
|
-
metas.some(({ type }) =>
|
|
240
|
-
[cv.ValidationTypes.CONDITIONAL_VALIDATION, cv.IS_EMPTY].includes(type),
|
|
241
|
-
)
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return (
|
|
246
|
-
Object.entries(groupBy(metadatas, (m) => m.propertyName))
|
|
247
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
248
|
-
.filter(([_, metas]) => {
|
|
249
|
-
const own = metas.filter((m) => m.target === target);
|
|
250
|
-
const inherited = metas.filter((m) => m.target !== target);
|
|
251
|
-
return options.skipMissingProperties
|
|
252
|
-
? isDefined(own) || (!isOptional(own) && isDefined(inherited))
|
|
253
|
-
: !(isOptional(own) || isOptional(inherited));
|
|
254
|
-
})
|
|
255
|
-
.map(([name]) => name)
|
|
256
|
-
);
|
|
257
|
-
}
|
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-submodule-imports
|
|
2
|
-
import * as cv from 'class-validator';
|
|
3
|
-
import type { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata';
|
|
4
|
-
import 'reflect-metadata';
|
|
5
|
-
|
|
6
|
-
import { IOptions } from './options';
|
|
7
|
-
|
|
8
|
-
export interface ISchemaConverters {
|
|
9
|
-
[validatorType: string]: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type SchemaConverter = (
|
|
13
|
-
meta: ValidationMetadata,
|
|
14
|
-
options: IOptions,
|
|
15
|
-
) => any;
|
|
16
|
-
|
|
17
|
-
export const defaultConverters: ISchemaConverters = {
|
|
18
|
-
[cv.ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
|
|
19
|
-
if (typeof meta.target === 'function') {
|
|
20
|
-
const type = getPropType(meta.target.prototype, meta.propertyName);
|
|
21
|
-
return targetToSchema(type, options);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
[cv.ValidationTypes.NESTED_VALIDATION]: (meta, options) => {
|
|
25
|
-
if (typeof meta.target === 'function') {
|
|
26
|
-
const typeMeta = options.classTransformerMetadataStorage
|
|
27
|
-
? options.classTransformerMetadataStorage.findTypeMetadata(
|
|
28
|
-
meta.target,
|
|
29
|
-
meta.propertyName,
|
|
30
|
-
)
|
|
31
|
-
: null;
|
|
32
|
-
const childType = typeMeta
|
|
33
|
-
? typeMeta.typeFunction()
|
|
34
|
-
: getPropType(meta.target.prototype, meta.propertyName);
|
|
35
|
-
return targetToSchema(childType, options);
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
[cv.ValidationTypes.WHITELIST]: {},
|
|
39
|
-
[cv.ValidationTypes.CONDITIONAL_VALIDATION]: {},
|
|
40
|
-
[cv.ValidationTypes.IS_DEFINED]: {
|
|
41
|
-
not: { type: 'null' },
|
|
42
|
-
},
|
|
43
|
-
[cv.EQUALS]: (meta) => {
|
|
44
|
-
const schema = constraintToSchema(meta.constraints[0]);
|
|
45
|
-
if (schema) {
|
|
46
|
-
return { ...schema, enum: [meta.constraints[0]] };
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
[cv.NOT_EQUALS]: (meta) => {
|
|
50
|
-
const schema = constraintToSchema(meta.constraints[0]);
|
|
51
|
-
if (schema) {
|
|
52
|
-
return { not: { ...schema, enum: [meta.constraints[0]] } };
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
[cv.IS_EMPTY]: {
|
|
56
|
-
type: 'string',
|
|
57
|
-
anyOf: [
|
|
58
|
-
{ type: 'string', enum: [''] },
|
|
59
|
-
{
|
|
60
|
-
not: {
|
|
61
|
-
anyOf: [
|
|
62
|
-
{ type: 'string' },
|
|
63
|
-
{ type: 'number' },
|
|
64
|
-
{ type: 'boolean' },
|
|
65
|
-
{ type: 'integer' },
|
|
66
|
-
{ type: 'array' },
|
|
67
|
-
{ type: 'object' },
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
nullable: true,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
[cv.IS_NOT_EMPTY]: {
|
|
75
|
-
minLength: 1,
|
|
76
|
-
type: 'string',
|
|
77
|
-
},
|
|
78
|
-
[cv.IS_IN]: (meta) => {
|
|
79
|
-
const [head, ...rest]: any[] = meta.constraints[0].map(constraintToSchema);
|
|
80
|
-
if (head && rest.every((item) => item.type === head.type)) {
|
|
81
|
-
return { ...head, enum: meta.constraints[0] };
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
type: 'string',
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
[cv.IS_NOT_IN]: (meta) => {
|
|
88
|
-
const [head, ...rest]: any[] = meta.constraints[0].map(constraintToSchema);
|
|
89
|
-
if (head && rest.every((item) => item.type === head.type)) {
|
|
90
|
-
return { not: { ...head, enum: meta.constraints[0] } };
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
type: 'string',
|
|
94
|
-
};
|
|
95
|
-
},
|
|
96
|
-
[cv.IS_BOOLEAN]: {
|
|
97
|
-
type: 'boolean',
|
|
98
|
-
},
|
|
99
|
-
[cv.IS_DATE]: {
|
|
100
|
-
type: 'string',
|
|
101
|
-
oneOf: [
|
|
102
|
-
{ format: 'date', type: 'string' },
|
|
103
|
-
{ format: 'date-time', type: 'string' },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
[cv.IS_NUMBER]: {
|
|
107
|
-
type: 'number',
|
|
108
|
-
},
|
|
109
|
-
[cv.IS_STRING]: {
|
|
110
|
-
type: 'string',
|
|
111
|
-
},
|
|
112
|
-
[cv.IS_DATE_STRING]: {
|
|
113
|
-
pattern: '\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d.\\d+Z?',
|
|
114
|
-
type: 'string',
|
|
115
|
-
},
|
|
116
|
-
[cv.IS_ARRAY]: {
|
|
117
|
-
items: {},
|
|
118
|
-
type: 'array',
|
|
119
|
-
},
|
|
120
|
-
[cv.IS_INT]: {
|
|
121
|
-
type: 'integer',
|
|
122
|
-
},
|
|
123
|
-
[cv.IS_ENUM]: (meta) => {
|
|
124
|
-
return {
|
|
125
|
-
enum: Object.values(meta.constraints[0]),
|
|
126
|
-
type: 'string',
|
|
127
|
-
};
|
|
128
|
-
},
|
|
129
|
-
[cv.IS_DIVISIBLE_BY]: (meta) => ({
|
|
130
|
-
multipleOf: meta.constraints[0],
|
|
131
|
-
type: 'number',
|
|
132
|
-
}),
|
|
133
|
-
[cv.IS_POSITIVE]: {
|
|
134
|
-
exclusiveMinimum: 0,
|
|
135
|
-
type: 'number',
|
|
136
|
-
},
|
|
137
|
-
[cv.IS_NEGATIVE]: {
|
|
138
|
-
exclusiveMaximum: 0,
|
|
139
|
-
type: 'number',
|
|
140
|
-
},
|
|
141
|
-
[cv.MIN]: (meta) => ({
|
|
142
|
-
minimum: meta.constraints[0],
|
|
143
|
-
type: 'number',
|
|
144
|
-
}),
|
|
145
|
-
[cv.MAX]: (meta) => ({
|
|
146
|
-
maximum: meta.constraints[0],
|
|
147
|
-
type: 'number',
|
|
148
|
-
}),
|
|
149
|
-
[cv.MIN_DATE]: (meta) => ({
|
|
150
|
-
description: `After ${meta.constraints[0].toJSON()}`,
|
|
151
|
-
oneOf: [
|
|
152
|
-
{ format: 'date', type: 'string' },
|
|
153
|
-
{ format: 'date-time', type: 'string' },
|
|
154
|
-
],
|
|
155
|
-
}),
|
|
156
|
-
[cv.MAX_DATE]: (meta) => ({
|
|
157
|
-
description: `Before ${meta.constraints[0].toJSON()}`,
|
|
158
|
-
oneOf: [
|
|
159
|
-
{ format: 'date', type: 'string' },
|
|
160
|
-
{ format: 'date-time', type: 'string' },
|
|
161
|
-
],
|
|
162
|
-
}),
|
|
163
|
-
[cv.IS_BOOLEAN_STRING]: {
|
|
164
|
-
enum: ['true', 'false'],
|
|
165
|
-
type: 'string',
|
|
166
|
-
},
|
|
167
|
-
[cv.IS_NUMBER_STRING]: {
|
|
168
|
-
pattern: '^[-+]?[0-9]+$',
|
|
169
|
-
type: 'string',
|
|
170
|
-
},
|
|
171
|
-
[cv.CONTAINS]: (meta) => ({
|
|
172
|
-
pattern: meta.constraints[0],
|
|
173
|
-
type: 'string',
|
|
174
|
-
}),
|
|
175
|
-
[cv.NOT_CONTAINS]: (meta) => ({
|
|
176
|
-
not: { pattern: meta.constraints[0] },
|
|
177
|
-
type: 'string',
|
|
178
|
-
}),
|
|
179
|
-
[cv.IS_ALPHA]: {
|
|
180
|
-
pattern: '^[a-zA-Z]+$',
|
|
181
|
-
type: 'string',
|
|
182
|
-
},
|
|
183
|
-
[cv.IS_ALPHANUMERIC]: {
|
|
184
|
-
pattern: '^[0-9a-zA-Z]+$',
|
|
185
|
-
type: 'string',
|
|
186
|
-
},
|
|
187
|
-
[cv.IS_ASCII]: {
|
|
188
|
-
pattern: '^[\\x00-\\x7F]+$',
|
|
189
|
-
type: 'string',
|
|
190
|
-
},
|
|
191
|
-
[cv.IS_BASE64]: {
|
|
192
|
-
format: 'base64',
|
|
193
|
-
type: 'string',
|
|
194
|
-
},
|
|
195
|
-
[cv.IS_BYTE_LENGTH]: {
|
|
196
|
-
type: 'string',
|
|
197
|
-
},
|
|
198
|
-
[cv.IS_CREDIT_CARD]: {
|
|
199
|
-
format: 'credit-card',
|
|
200
|
-
type: 'string',
|
|
201
|
-
},
|
|
202
|
-
[cv.IS_CURRENCY]: {
|
|
203
|
-
format: 'currency',
|
|
204
|
-
type: 'string',
|
|
205
|
-
},
|
|
206
|
-
[cv.IS_EMAIL]: {
|
|
207
|
-
format: 'email',
|
|
208
|
-
type: 'string',
|
|
209
|
-
},
|
|
210
|
-
[cv.IS_FQDN]: {
|
|
211
|
-
format: 'hostname',
|
|
212
|
-
type: 'string',
|
|
213
|
-
},
|
|
214
|
-
[cv.IS_FULL_WIDTH]: {
|
|
215
|
-
pattern:
|
|
216
|
-
'[^\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
|
|
217
|
-
type: 'string',
|
|
218
|
-
},
|
|
219
|
-
[cv.IS_HALF_WIDTH]: {
|
|
220
|
-
pattern:
|
|
221
|
-
'[\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
|
|
222
|
-
type: 'string',
|
|
223
|
-
},
|
|
224
|
-
[cv.IS_VARIABLE_WIDTH]: {
|
|
225
|
-
type: 'string',
|
|
226
|
-
},
|
|
227
|
-
[cv.IS_HEX_COLOR]: {
|
|
228
|
-
pattern: '^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$',
|
|
229
|
-
type: 'string',
|
|
230
|
-
},
|
|
231
|
-
[cv.IS_HEXADECIMAL]: {
|
|
232
|
-
pattern: '^[0-9a-fA-F]+$',
|
|
233
|
-
type: 'string',
|
|
234
|
-
},
|
|
235
|
-
[cv.IS_IP]: (meta) => ({
|
|
236
|
-
format: 'ipv' + (meta.constraints[0] === '6' ? 6 : 4),
|
|
237
|
-
type: 'string',
|
|
238
|
-
}),
|
|
239
|
-
[cv.IS_ISBN]: {
|
|
240
|
-
format: 'isbn',
|
|
241
|
-
type: 'string',
|
|
242
|
-
},
|
|
243
|
-
[cv.IS_ISIN]: {
|
|
244
|
-
format: 'isin',
|
|
245
|
-
type: 'string',
|
|
246
|
-
},
|
|
247
|
-
[cv.IS_ISO8601]: {
|
|
248
|
-
oneOf: [
|
|
249
|
-
{ format: 'date', type: 'string' },
|
|
250
|
-
{ format: 'date-time', type: 'string' },
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
[cv.IS_JSON]: {
|
|
254
|
-
format: 'json',
|
|
255
|
-
type: 'string',
|
|
256
|
-
},
|
|
257
|
-
[cv.IS_LOWERCASE]: {
|
|
258
|
-
type: 'string',
|
|
259
|
-
},
|
|
260
|
-
[cv.IS_MOBILE_PHONE]: {
|
|
261
|
-
format: 'mobile-phone',
|
|
262
|
-
type: 'string',
|
|
263
|
-
},
|
|
264
|
-
[cv.IS_MONGO_ID]: {
|
|
265
|
-
pattern: '^[0-9a-fA-F]{24}$',
|
|
266
|
-
type: 'string',
|
|
267
|
-
},
|
|
268
|
-
[cv.IS_MULTIBYTE]: {
|
|
269
|
-
pattern: '[^\\x00-\\x7F]',
|
|
270
|
-
type: 'string',
|
|
271
|
-
},
|
|
272
|
-
[cv.IS_SURROGATE_PAIR]: {
|
|
273
|
-
pattern: '[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]',
|
|
274
|
-
type: 'string',
|
|
275
|
-
},
|
|
276
|
-
[cv.IS_URL]: {
|
|
277
|
-
format: 'url',
|
|
278
|
-
type: 'string',
|
|
279
|
-
},
|
|
280
|
-
[cv.IS_UUID]: {
|
|
281
|
-
format: 'uuid',
|
|
282
|
-
type: 'string',
|
|
283
|
-
},
|
|
284
|
-
[cv.IS_LENGTH]: (meta) => {
|
|
285
|
-
const [minLength, maxLength] = meta.constraints;
|
|
286
|
-
if (maxLength || maxLength === 0) {
|
|
287
|
-
return { min: minLength, max: maxLength, type: 'Range' };
|
|
288
|
-
}
|
|
289
|
-
return { min: minLength, type: 'Range' };
|
|
290
|
-
},
|
|
291
|
-
[cv.IS_UPPERCASE]: {
|
|
292
|
-
type: 'string',
|
|
293
|
-
},
|
|
294
|
-
[cv.IS_OBJECT]: {
|
|
295
|
-
type: 'object',
|
|
296
|
-
},
|
|
297
|
-
[cv.IS_NOT_EMPTY_OBJECT]: {
|
|
298
|
-
type: 'object',
|
|
299
|
-
minProperties: 1,
|
|
300
|
-
},
|
|
301
|
-
[cv.MIN_LENGTH]: (meta) => ({
|
|
302
|
-
minLength: meta.constraints[0],
|
|
303
|
-
type: 'string',
|
|
304
|
-
}),
|
|
305
|
-
[cv.MAX_LENGTH]: (meta) => ({
|
|
306
|
-
maxLength: meta.constraints[0],
|
|
307
|
-
type: 'string',
|
|
308
|
-
}),
|
|
309
|
-
[cv.MATCHES]: (meta) => ({
|
|
310
|
-
pattern: meta.constraints[0].source,
|
|
311
|
-
type: 'string',
|
|
312
|
-
}),
|
|
313
|
-
[cv.IS_MILITARY_TIME]: {
|
|
314
|
-
pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$',
|
|
315
|
-
type: 'string',
|
|
316
|
-
},
|
|
317
|
-
[cv.ARRAY_CONTAINS]: (meta) => {
|
|
318
|
-
const schemas: any[] = meta.constraints[0].map(constraintToSchema);
|
|
319
|
-
if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
|
|
320
|
-
return {
|
|
321
|
-
not: {
|
|
322
|
-
anyOf: schemas.map((d, i) => ({
|
|
323
|
-
items: {
|
|
324
|
-
not: {
|
|
325
|
-
...d,
|
|
326
|
-
enum: [meta.constraints[0][i]],
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
})),
|
|
330
|
-
},
|
|
331
|
-
type: 'array',
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
return { items: {}, type: 'array' };
|
|
335
|
-
},
|
|
336
|
-
[cv.ARRAY_NOT_CONTAINS]: (meta) => {
|
|
337
|
-
const schemas: any[] = meta.constraints[0].map(constraintToSchema);
|
|
338
|
-
if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
|
|
339
|
-
return {
|
|
340
|
-
items: {
|
|
341
|
-
not: {
|
|
342
|
-
anyOf: schemas.map((d, i) => ({
|
|
343
|
-
...d,
|
|
344
|
-
enum: [meta.constraints[0][i]],
|
|
345
|
-
})),
|
|
346
|
-
},
|
|
347
|
-
},
|
|
348
|
-
type: 'array',
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
return { items: {}, type: 'array' };
|
|
352
|
-
},
|
|
353
|
-
[cv.ARRAY_NOT_EMPTY]: {
|
|
354
|
-
items: {},
|
|
355
|
-
minItems: 1,
|
|
356
|
-
type: 'array',
|
|
357
|
-
},
|
|
358
|
-
[cv.ARRAY_MIN_SIZE]: (meta) => ({
|
|
359
|
-
items: {},
|
|
360
|
-
minItems: meta.constraints[0],
|
|
361
|
-
type: 'array',
|
|
362
|
-
}),
|
|
363
|
-
[cv.ARRAY_MAX_SIZE]: (meta) => ({
|
|
364
|
-
items: {},
|
|
365
|
-
maxItems: meta.constraints[0],
|
|
366
|
-
type: 'array',
|
|
367
|
-
}),
|
|
368
|
-
[cv.ARRAY_UNIQUE]: {
|
|
369
|
-
items: {},
|
|
370
|
-
type: 'array',
|
|
371
|
-
uniqueItems: true,
|
|
372
|
-
},
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
function getPropType(target: object, property: string) {
|
|
376
|
-
return Reflect.getMetadata('design:type', target, property);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function constraintToSchema(primitive: any): any | void {
|
|
380
|
-
const primitives = ['string', 'number', 'boolean'];
|
|
381
|
-
const type = typeof primitive;
|
|
382
|
-
if (primitives.includes(type)) {
|
|
383
|
-
return { type: type as 'string' | 'number' | 'boolean' };
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function targetToSchema(type: any, options: IOptions): any {
|
|
388
|
-
if (typeof type === 'function') {
|
|
389
|
-
if (
|
|
390
|
-
type.prototype === String.prototype ||
|
|
391
|
-
type.prototype === Symbol.prototype
|
|
392
|
-
) {
|
|
393
|
-
return { type: 'string' };
|
|
394
|
-
} else if (type.prototype === Number.prototype) {
|
|
395
|
-
return { type: 'number' };
|
|
396
|
-
} else if (type.prototype === Boolean.prototype) {
|
|
397
|
-
return { type: 'boolean' };
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
return { $ref: options.refPointerPrefix + type.name };
|
|
401
|
-
}
|
|
402
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { MetadataStorage as ClassTransformerMetadataStorage } from 'class-transformer/types/MetadataStorage'; // tslint:disable-line:no-submodule-imports
|
|
2
|
-
import {
|
|
3
|
-
getMetadataStorage,
|
|
4
|
-
MetadataStorage,
|
|
5
|
-
ValidatorOptions,
|
|
6
|
-
} from 'class-validator';
|
|
7
|
-
|
|
8
|
-
import { ISchemaConverters } from './defaultConverters';
|
|
9
|
-
|
|
10
|
-
export interface IOptions extends ValidatorOptions {
|
|
11
|
-
/**
|
|
12
|
-
* A map of additional metadata-to-schema converters that can be used to
|
|
13
|
-
* supplement or override the default ones. The key should correspond to the
|
|
14
|
-
* 'type' property of a ValidationMetadata object.
|
|
15
|
-
*/
|
|
16
|
-
additionalConverters: ISchemaConverters;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Metadata storage instance of class-transformer. This value can be
|
|
20
|
-
* optionally defined in order for class-transformer's @Type decorators to
|
|
21
|
-
* have effect in JSON Schema generation.
|
|
22
|
-
*/
|
|
23
|
-
classTransformerMetadataStorage?: ClassTransformerMetadataStorage;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Metadata storage instance of class-validator. This value can be
|
|
27
|
-
* optionally defined in order to override the default storage used
|
|
28
|
-
* to parse decorator metadata.
|
|
29
|
-
*/
|
|
30
|
-
classValidatorMetadataStorage: MetadataStorage;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A prefix added to all `$ref` JSON pointers referencing other schemas.
|
|
34
|
-
* Defaults to '#/definitions/'.
|
|
35
|
-
*/
|
|
36
|
-
refPointerPrefix: string;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Property used to group schemas.
|
|
40
|
-
* Defaults to `name`, i.e., class name.
|
|
41
|
-
*/
|
|
42
|
-
schemaNameField: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const defaultOptions: IOptions = {
|
|
46
|
-
additionalConverters: {},
|
|
47
|
-
classValidatorMetadataStorage: getMetadataStorage(),
|
|
48
|
-
refPointerPrefix: '#/definitions/',
|
|
49
|
-
schemaNameField: 'name',
|
|
50
|
-
};
|