@nest-omni/core 3.1.1-10 → 3.1.1-9
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 +27 -19
- package/.hygen/new/crud/controller.ejs.t +0 -82
- package/.hygen/new/crud/create.dto.ejs.t +0 -12
- package/.hygen/new/crud/entity.ejs.t +0 -26
- package/.hygen/new/crud/get.dto.ejs.t +0 -19
- package/.hygen/new/crud/index-dto.ejs.t +0 -29
- package/.hygen/new/crud/index-response.dto.ejs.t +0 -18
- package/.hygen/new/crud/module.ejs.t +0 -32
- package/.hygen/new/crud/prompt.js +0 -89
- package/.hygen/new/crud/service.ejs.t +0 -76
- package/.hygen/new/crud/update.dto.ejs.t +0 -11
- package/.hygen/new/module/controller.ejs.t +0 -93
- package/.hygen/new/module/create-command.ejs.t +0 -90
- package/.hygen/new/module/create.dto.ejs.t +0 -11
- package/.hygen/new/module/dto.ejs.t +0 -24
- package/.hygen/new/module/entity.ejs.t +0 -33
- package/.hygen/new/module/get-query.ejs.t +0 -57
- package/.hygen/new/module/module.ejs.t +0 -44
- package/.hygen/new/module/not-found.exception.ejs.t +0 -18
- package/.hygen/new/module/page-options.dto.ejs.t +0 -12
- package/.hygen/new/module/prompt.js +0 -104
- package/.hygen/new/module/repository.ejs.t +0 -16
- package/.hygen/new/module/service.ejs.t +0 -139
- package/.hygen/new/module/translation-dto.ejs.t +0 -27
- package/.hygen/new/module/translation-entity.ejs.t +0 -40
- package/.hygen/new/module/translation-repository.ejs.t +0 -16
- package/.hygen/new/module/update.dto.ejs.t +0 -10
- package/.hygen.js +0 -116
- package/common/abstract.entity.d.ts +0 -18
- package/common/abstract.entity.js +0 -78
- package/common/boilerplate.polyfill.d.ts +0 -39
- package/common/boilerplate.polyfill.js +0 -77
- package/common/dto/abstract.dto.d.ts +0 -13
- package/common/dto/abstract.dto.js +0 -59
- package/common/dto/bulk-id.dto.d.ts +0 -3
- package/common/dto/bulk-id.dto.js +0 -27
- package/common/dto/create-translation.dto.d.ts +0 -5
- package/common/dto/create-translation.dto.js +0 -25
- package/common/dto/index.d.ts +0 -6
- package/common/dto/index.js +0 -22
- package/common/dto/page-meta.dto.d.ts +0 -15
- package/common/dto/page-meta.dto.js +0 -48
- package/common/dto/page-options.dto.d.ts +0 -8
- package/common/dto/page-options.dto.js +0 -52
- package/common/dto/page.dto.d.ts +0 -11
- package/common/dto/page.dto.js +0 -53
- package/common/index.d.ts +0 -6
- package/common/index.js +0 -22
- package/common/snake-naming.strategy.d.ts +0 -11
- package/common/snake-naming.strategy.js +0 -37
- package/common/types.d.ts +0 -9
- package/common/types.js +0 -2
- package/common/utils.d.ts +0 -3
- package/common/utils.js +0 -24
- package/constants/index.d.ts +0 -2
- package/constants/index.js +0 -18
- package/constants/language-code.d.ts +0 -5
- package/constants/language-code.js +0 -9
- package/constants/order.d.ts +0 -4
- package/constants/order.js +0 -8
- package/decorators/api-page-ok-response.decorator.d.ts +0 -5
- package/decorators/api-page-ok-response.decorator.js +0 -24
- package/decorators/auth-user.decorator.d.ts +0 -1
- package/decorators/auth-user.decorator.js +0 -14
- package/decorators/controller.decorator.d.ts +0 -1
- package/decorators/controller.decorator.js +0 -10
- package/decorators/field.decorators.d.ts +0 -79
- package/decorators/field.decorators.js +0 -497
- package/decorators/http.decorators.d.ts +0 -3
- package/decorators/http.decorators.js +0 -7
- package/decorators/index.d.ts +0 -12
- package/decorators/index.js +0 -28
- package/decorators/operation.decorator.d.ts +0 -1
- package/decorators/operation.decorator.js +0 -6
- package/decorators/property.decorators.d.ts +0 -15
- package/decorators/property.decorators.js +0 -31
- package/decorators/public-route.decorator.d.ts +0 -3
- package/decorators/public-route.decorator.js +0 -7
- package/decorators/swagger.schema.d.ts +0 -5
- package/decorators/swagger.schema.js +0 -78
- package/decorators/timestamp-column.decorator.d.ts +0 -1
- package/decorators/timestamp-column.decorator.js +0 -27
- package/decorators/transform.decorators.d.ts +0 -8
- package/decorators/transform.decorators.js +0 -100
- package/decorators/translate.decorator.d.ts +0 -5
- package/decorators/translate.decorator.js +0 -17
- package/decorators/use-dto.decorator.d.ts +0 -4
- package/decorators/use-dto.decorator.js +0 -8
- package/decorators/user-check.decorator.d.ts +0 -6
- package/decorators/user-check.decorator.js +0 -21
- package/decorators/user.decorator.d.ts +0 -12
- package/decorators/user.decorator.js +0 -44
- package/decorators/user_auth.decorator.d.ts +0 -1
- package/decorators/user_auth.decorator.js +0 -15
- package/decorators/validator.decorators.d.ts +0 -11
- package/decorators/validator.decorators.js +0 -78
- package/exceptions/file-not-image.exception.d.ts +0 -4
- package/exceptions/file-not-image.exception.js +0 -10
- package/exceptions/index.d.ts +0 -2
- package/exceptions/index.js +0 -18
- package/exceptions/page-type.exception.d.ts +0 -4
- package/exceptions/page-type.exception.js +0 -10
- package/exceptions/user-not-found.exception.d.ts +0 -4
- package/exceptions/user-not-found.exception.js +0 -10
- package/filters/bad-request.filter.d.ts +0 -5
- package/filters/bad-request.filter.js +0 -71
- package/filters/constraint-errors.d.ts +0 -1
- package/filters/constraint-errors.js +0 -6
- package/filters/index.d.ts +0 -3
- package/filters/index.js +0 -19
- package/filters/query-failed.filter.d.ts +0 -10
- package/filters/query-failed.filter.js +0 -42
- package/health-checker/health-checker.controller.d.ts +0 -13
- package/health-checker/health-checker.controller.js +0 -69
- package/health-checker/health-checker.module.d.ts +0 -2
- package/health-checker/health-checker.module.js +0 -24
- package/health-checker/index.d.ts +0 -2
- package/health-checker/index.js +0 -18
- package/helpers/common.helper.d.ts +0 -3
- package/helpers/common.helper.js +0 -36
- package/helpers/date.helper.d.ts +0 -10
- package/helpers/date.helper.js +0 -57
- package/helpers/index.d.ts +0 -2
- package/helpers/index.js +0 -18
- package/i18n/en_US/validation.json +0 -41
- package/i18n/zh_CN/validation.json +0 -41
- package/index.d.ts +0 -15
- package/interceptors/index.d.ts +0 -2
- package/interceptors/index.js +0 -18
- package/interceptors/language-interceptor.service.d.ts +0 -6
- package/interceptors/language-interceptor.service.js +0 -29
- package/interceptors/translation-interceptor.service.d.ts +0 -5
- package/interceptors/translation-interceptor.service.js +0 -34
- package/interfaces/IApiFile.d.ts +0 -4
- package/interfaces/IApiFile.js +0 -2
- package/interfaces/IFile.d.ts +0 -8
- package/interfaces/IFile.js +0 -2
- package/interfaces/ITranslationDecoratorInterface.d.ts +0 -3
- package/interfaces/ITranslationDecoratorInterface.js +0 -2
- package/interfaces/index.d.ts +0 -3
- package/interfaces/index.js +0 -19
- package/interfaces/response.d.ts +0 -25
- package/interfaces/response.js +0 -2
- package/middlewares/index.d.ts +0 -4
- package/middlewares/index.js +0 -20
- package/middlewares/omni-auth.middleware.d.ts +0 -1
- package/middlewares/omni-auth.middleware.js +0 -13
- package/middlewares/powerby.middleware.d.ts +0 -1
- package/middlewares/powerby.middleware.js +0 -10
- package/middlewares/request-id.middleware.d.ts +0 -7
- package/middlewares/request-id.middleware.js +0 -22
- package/middlewares/xml.middleware.d.ts +0 -4
- package/middlewares/xml.middleware.js +0 -24
- package/providers/context.provider.d.ts +0 -34
- package/providers/context.provider.js +0 -80
- package/providers/generator.provider.d.ts +0 -9
- package/providers/generator.provider.js +0 -50
- package/providers/index.d.ts +0 -2
- package/providers/index.js +0 -18
- package/setup/bootstrap.setup.d.ts +0 -2
- package/setup/bootstrap.setup.js +0 -177
- package/setup/index.d.ts +0 -6
- package/setup/index.js +0 -22
- package/setup/mode.setup.d.ts +0 -12
- package/setup/mode.setup.js +0 -60
- package/setup/redis.lock.decorator.d.ts +0 -5
- package/setup/redis.lock.decorator.js +0 -60
- package/setup/redis.lock.service.d.ts +0 -56
- package/setup/redis.lock.service.js +0 -338
- package/setup/schedule.decorator.d.ts +0 -21
- package/setup/schedule.decorator.js +0 -127
- package/setup/worker.decorator.d.ts +0 -14
- package/setup/worker.decorator.js +0 -130
- package/shared/index.d.ts +0 -2
- package/shared/index.js +0 -18
- package/shared/serviceRegistryModule.d.ts +0 -2
- package/shared/serviceRegistryModule.js +0 -109
- package/shared/services/api-config.service.d.ts +0 -59
- package/shared/services/api-config.service.js +0 -311
- package/shared/services/generator.service.d.ts +0 -4
- package/shared/services/generator.service.js +0 -23
- package/shared/services/index.d.ts +0 -4
- package/shared/services/index.js +0 -20
- package/shared/services/translation.service.d.ts +0 -9
- package/shared/services/translation.service.js +0 -70
- package/shared/services/validator.service.d.ts +0 -3
- package/shared/services/validator.service.js +0 -20
- package/validator-json/decorators.d.ts +0 -6
- package/validator-json/decorators.js +0 -22
- package/validator-json/default.d.ts +0 -6
- package/validator-json/default.js +0 -138
- package/validator-json/defaultConverters.d.ts +0 -8
- package/validator-json/defaultConverters.js +0 -376
- package/validator-json/index.d.ts +0 -4
- package/validator-json/index.js +0 -20
- package/validator-json/options.d.ts +0 -11
- package/validator-json/options.js +0 -10
- package/validators/file-mimetype.validator.d.ts +0 -13
- package/validators/file-mimetype.validator.js +0 -21
- package/validators/index.d.ts +0 -6
- package/validators/index.js +0 -22
- package/validators/is-exists.validator.d.ts +0 -18
- package/validators/is-exists.validator.js +0 -60
- package/validators/is-unique.validator.d.ts +0 -17
- package/validators/is-unique.validator.js +0 -91
- package/validators/phone-country-code.validator.d.ts +0 -2
- package/validators/phone-country-code.validator.js +0 -29
- package/validators/same-as.validator.d.ts +0 -2
- package/validators/same-as.validator.js +0 -24
- package/validators/skip-empty.validator.d.ts +0 -1
- package/validators/skip-empty.validator.js +0 -17
package/shared/services/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./api-config.service"), exports);
|
|
18
|
-
__exportStar(require("./generator.service"), exports);
|
|
19
|
-
__exportStar(require("./translation.service"), exports);
|
|
20
|
-
__exportStar(require("./validator.service"), exports);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { TranslateOptions } from 'nestjs-i18n';
|
|
2
|
-
import { I18nService } from 'nestjs-i18n';
|
|
3
|
-
import { AbstractDto } from '../../common/dto/abstract.dto';
|
|
4
|
-
export declare class TranslationService {
|
|
5
|
-
private readonly i18n;
|
|
6
|
-
constructor(i18n: I18nService);
|
|
7
|
-
translate(key: string, options?: TranslateOptions): Promise<string>;
|
|
8
|
-
translateNecessaryKeys<T extends AbstractDto>(dto: T): Promise<T>;
|
|
9
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.TranslationService = void 0;
|
|
22
|
-
const common_1 = require("@nestjs/common");
|
|
23
|
-
const lodash_1 = require("lodash");
|
|
24
|
-
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
25
|
-
const abstract_dto_1 = require("../../common/dto/abstract.dto");
|
|
26
|
-
const decorators_1 = require("../../decorators");
|
|
27
|
-
const providers_1 = require("../../providers");
|
|
28
|
-
let TranslationService = class TranslationService {
|
|
29
|
-
constructor(i18n) {
|
|
30
|
-
this.i18n = i18n;
|
|
31
|
-
}
|
|
32
|
-
translate(key, options) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return this.i18n.translate(`${key}`, Object.assign(Object.assign({}, options), { lang: providers_1.ContextProvider.getLanguage() }));
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
translateNecessaryKeys(dto) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
if ((0, lodash_1.isString)(dto)) {
|
|
40
|
-
return dto;
|
|
41
|
-
}
|
|
42
|
-
yield Promise.all((0, lodash_1.map)(dto, (value, key) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
var _a;
|
|
44
|
-
if ((0, lodash_1.isString)(value)) {
|
|
45
|
-
const translateDec = Reflect.getMetadata(decorators_1.STATIC_TRANSLATION_DECORATOR_KEY, dto, key);
|
|
46
|
-
if (translateDec) {
|
|
47
|
-
return this.translate(`${(_a = translateDec.translationKey) !== null && _a !== void 0 ? _a : key}.${value}`);
|
|
48
|
-
}
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (value instanceof abstract_dto_1.AbstractDto) {
|
|
52
|
-
return this.translateNecessaryKeys(value);
|
|
53
|
-
}
|
|
54
|
-
if ((0, lodash_1.isArray)(value)) {
|
|
55
|
-
return Promise.all((0, lodash_1.map)(value, (v) => {
|
|
56
|
-
if (v instanceof abstract_dto_1.AbstractDto) {
|
|
57
|
-
return this.translateNecessaryKeys(v);
|
|
58
|
-
}
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
})));
|
|
62
|
-
return dto;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
exports.TranslationService = TranslationService;
|
|
67
|
-
exports.TranslationService = TranslationService = __decorate([
|
|
68
|
-
(0, common_1.Injectable)(),
|
|
69
|
-
__metadata("design:paramtypes", [nestjs_i18n_1.I18nService])
|
|
70
|
-
], TranslationService);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ValidatorService = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
let ValidatorService = class ValidatorService {
|
|
12
|
-
isImage(mimeType) {
|
|
13
|
-
const imageMimeTypes = ['image/jpeg', 'image/png'];
|
|
14
|
-
return imageMimeTypes.includes(mimeType);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
exports.ValidatorService = ValidatorService;
|
|
18
|
-
exports.ValidatorService = ValidatorService = __decorate([
|
|
19
|
-
(0, common_1.Injectable)()
|
|
20
|
-
], ValidatorService);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { IOptions } from './options';
|
|
4
|
-
export type DecoratorSchema = ReferenceObject | SchemaObject | ((source: SchemaObject, options: IOptions) => ReferenceObject | SchemaObject);
|
|
5
|
-
export declare function JSONSchema(schema: DecoratorSchema): (target: object | Function, key?: string) => void;
|
|
6
|
-
export declare function getMetadataSchema(target: object | Function, key: string): DecoratorSchema;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONSchema = JSONSchema;
|
|
4
|
-
exports.getMetadataSchema = getMetadataSchema;
|
|
5
|
-
require("reflect-metadata");
|
|
6
|
-
const SCHEMA_KEY = Symbol('class-validator-jsonschema:JSONSchema');
|
|
7
|
-
function JSONSchema(schema) {
|
|
8
|
-
return (target, key) => {
|
|
9
|
-
if (key) {
|
|
10
|
-
setMetadataSchema(schema, target.constructor, key);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
setMetadataSchema(schema, target, target.name);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function getMetadataSchema(target, key) {
|
|
18
|
-
return Reflect.getMetadata(SCHEMA_KEY, target.constructor, key) || {};
|
|
19
|
-
}
|
|
20
|
-
function setMetadataSchema(value, target, key) {
|
|
21
|
-
return Reflect.defineMetadata(SCHEMA_KEY, value, target, key);
|
|
22
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata';
|
|
2
|
-
import { IOptions } from './options';
|
|
3
|
-
import { I18nService } from 'nestjs-i18n';
|
|
4
|
-
export { JSONSchema } from './decorators';
|
|
5
|
-
export declare function validationMetadataArrayToSchemas(metadatas: ValidationMetadata[], i18n: any, userOptions?: Partial<IOptions>): any;
|
|
6
|
-
export declare function targetConstructorToSchema(targetConstructor: Function, i18n: I18nService, userOptions?: Partial<IOptions>): any;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONSchema = void 0;
|
|
4
|
-
exports.validationMetadataArrayToSchemas = validationMetadataArrayToSchemas;
|
|
5
|
-
exports.targetConstructorToSchema = targetConstructorToSchema;
|
|
6
|
-
const cv = require("class-validator");
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const defaultConverters_1 = require("./defaultConverters");
|
|
9
|
-
const options_1 = require("./options");
|
|
10
|
-
var decorators_1 = require("./decorators");
|
|
11
|
-
Object.defineProperty(exports, "JSONSchema", { enumerable: true, get: function () { return decorators_1.JSONSchema; } });
|
|
12
|
-
function validationMetadataArrayToSchemas(metadatas, i18n, userOptions) {
|
|
13
|
-
const options = Object.assign(Object.assign({}, options_1.defaultOptions), userOptions);
|
|
14
|
-
const rules = [];
|
|
15
|
-
Object.entries((0, lodash_1.groupBy)(metadatas, ({ target }) => {
|
|
16
|
-
var _a;
|
|
17
|
-
return (_a = target[options.schemaNameField]) !== null && _a !== void 0 ? _a : target.name;
|
|
18
|
-
})).forEach(([key, ownMetas]) => {
|
|
19
|
-
const target = ownMetas[0].target;
|
|
20
|
-
const metas = ownMetas
|
|
21
|
-
.concat(getInheritedMetadatas(target, metadatas))
|
|
22
|
-
.filter((propMeta) => !(isExcluded(propMeta, options) ||
|
|
23
|
-
isExcluded(Object.assign(Object.assign({}, propMeta), { target }), options)));
|
|
24
|
-
const required = getRequiredPropNames(target, metas, options);
|
|
25
|
-
Object.entries((0, lodash_1.groupBy)(metas, 'propertyName')).forEach(([propName, propMetas]) => {
|
|
26
|
-
const schema = applyConverters(propMetas, options, i18n);
|
|
27
|
-
const filterSchema = schema.filter((item) => !['conditionalValidation', 'notEquals'].includes(item.type));
|
|
28
|
-
const fieldType = getFirstNonNullDataType(filterSchema);
|
|
29
|
-
rules.push({
|
|
30
|
-
field: propName,
|
|
31
|
-
fieldType,
|
|
32
|
-
required: required.includes(propName),
|
|
33
|
-
constraints: filterSchema,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return rules;
|
|
38
|
-
}
|
|
39
|
-
function getFirstNonNullDataType(data) {
|
|
40
|
-
for (const item of data) {
|
|
41
|
-
const dataType = item.dataType;
|
|
42
|
-
delete item.dataType;
|
|
43
|
-
if (dataType) {
|
|
44
|
-
return dataType;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
function targetConstructorToSchema(targetConstructor, i18n, userOptions) {
|
|
50
|
-
const options = Object.assign(Object.assign({}, options_1.defaultOptions), userOptions);
|
|
51
|
-
const storage = options.classValidatorMetadataStorage;
|
|
52
|
-
let metadatas = storage.getTargetValidationMetadatas(targetConstructor, '', true, false);
|
|
53
|
-
metadatas = populateMetadatasWithConstraints(storage, metadatas);
|
|
54
|
-
return validationMetadataArrayToSchemas(metadatas, i18n, userOptions);
|
|
55
|
-
}
|
|
56
|
-
function populateMetadatasWithConstraints(storage, metadatas) {
|
|
57
|
-
return metadatas.map((meta) => {
|
|
58
|
-
if (meta.constraintCls) {
|
|
59
|
-
const constraint = storage.getTargetValidatorConstraints(meta.constraintCls);
|
|
60
|
-
if (constraint.length > 0) {
|
|
61
|
-
return Object.assign(Object.assign({}, meta), { type: constraint[0].name });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return Object.assign({}, meta);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function getInheritedMetadatas(target, metadatas) {
|
|
68
|
-
return metadatas.filter((d) => d.target instanceof Function &&
|
|
69
|
-
target.prototype instanceof d.target &&
|
|
70
|
-
!metadatas.find((m) => m.propertyName === d.propertyName &&
|
|
71
|
-
m.target === target &&
|
|
72
|
-
m.type === d.type));
|
|
73
|
-
}
|
|
74
|
-
function applyConverters(propertyMetadatas, options, i18n) {
|
|
75
|
-
const converters = Object.assign(Object.assign({}, defaultConverters_1.defaultConverters), options.additionalConverters);
|
|
76
|
-
const convert = (meta) => {
|
|
77
|
-
var _a;
|
|
78
|
-
const typeMeta = (_a = options.classTransformerMetadataStorage) === null || _a === void 0 ? void 0 : _a.findTypeMetadata(meta.target, meta.propertyName);
|
|
79
|
-
const isMap = typeMeta &&
|
|
80
|
-
typeMeta.reflectedType &&
|
|
81
|
-
new typeMeta.reflectedType() instanceof Map;
|
|
82
|
-
const converter = converters[meta.type] || converters[cv.ValidationTypes.CUSTOM_VALIDATION];
|
|
83
|
-
const converterResult = typeof converter === 'function' ? converter(meta, options) : converter;
|
|
84
|
-
const items = {};
|
|
85
|
-
let message = '';
|
|
86
|
-
const originMessage = typeof meta.message === 'function'
|
|
87
|
-
? meta.message({
|
|
88
|
-
value: undefined,
|
|
89
|
-
constraints: meta.constraints,
|
|
90
|
-
targetName: meta.target.name || '',
|
|
91
|
-
object: {},
|
|
92
|
-
property: meta.propertyName,
|
|
93
|
-
})
|
|
94
|
-
: meta.message;
|
|
95
|
-
if ((0, lodash_1.isString)(originMessage)) {
|
|
96
|
-
const [translationKey, argsString] = originMessage.split('|');
|
|
97
|
-
const args = !!argsString ? JSON.parse(argsString) : {};
|
|
98
|
-
message = i18n.translate(translationKey, Object.assign(Object.assign({}, options), { args: Object.assign({ constraints: meta.constraints }, args) }));
|
|
99
|
-
}
|
|
100
|
-
items['type'] = meta.type;
|
|
101
|
-
items['dataType'] = (converterResult === null || converterResult === void 0 ? void 0 : converterResult.type) || undefined;
|
|
102
|
-
items['attrs'] = meta.constraints || [];
|
|
103
|
-
items['message'] = message;
|
|
104
|
-
if (meta.each && isMap) {
|
|
105
|
-
return {
|
|
106
|
-
additionalProperties: Object.assign({}, items),
|
|
107
|
-
type: 'object',
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
return meta.each ? { items, type: 'array' } : items;
|
|
111
|
-
};
|
|
112
|
-
const constraints = propertyMetadatas.map((meta) => {
|
|
113
|
-
return convert(meta);
|
|
114
|
-
});
|
|
115
|
-
return (0, lodash_1.reject)(constraints, (item) => (0, lodash_1.isEmpty)(item));
|
|
116
|
-
}
|
|
117
|
-
function isExcluded(propertyMetadata, options) {
|
|
118
|
-
var _a;
|
|
119
|
-
return !!((_a = options.classTransformerMetadataStorage) === null || _a === void 0 ? void 0 : _a.findExcludeMetadata(propertyMetadata.target, propertyMetadata.propertyName));
|
|
120
|
-
}
|
|
121
|
-
function getRequiredPropNames(target, metadatas, options) {
|
|
122
|
-
function isDefined(metas) {
|
|
123
|
-
return (metas && metas.some(({ type }) => type === cv.ValidationTypes.IS_DEFINED));
|
|
124
|
-
}
|
|
125
|
-
function isOptional(metas) {
|
|
126
|
-
return (metas &&
|
|
127
|
-
metas.some(({ type }) => [cv.ValidationTypes.CONDITIONAL_VALIDATION, cv.IS_EMPTY].includes(type)));
|
|
128
|
-
}
|
|
129
|
-
return (Object.entries((0, lodash_1.groupBy)(metadatas, (m) => m.propertyName))
|
|
130
|
-
.filter(([_, metas]) => {
|
|
131
|
-
const own = metas.filter((m) => m.target === target);
|
|
132
|
-
const inherited = metas.filter((m) => m.target !== target);
|
|
133
|
-
return options.skipMissingProperties
|
|
134
|
-
? isDefined(own) || (!isOptional(own) && isDefined(inherited))
|
|
135
|
-
: !(isOptional(own) || isOptional(inherited));
|
|
136
|
-
})
|
|
137
|
-
.map(([name]) => name));
|
|
138
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ValidationMetadata } from 'class-validator/types/metadata/ValidationMetadata';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { IOptions } from './options';
|
|
4
|
-
export interface ISchemaConverters {
|
|
5
|
-
[validatorType: string]: any;
|
|
6
|
-
}
|
|
7
|
-
export type SchemaConverter = (meta: ValidationMetadata, options: IOptions) => any;
|
|
8
|
-
export declare const defaultConverters: ISchemaConverters;
|