@nest-omni/core 3.1.1-9 → 3.1.2-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.hygen/new/crud/controller.ejs.t +82 -0
- package/.hygen/new/crud/create.dto.ejs.t +12 -0
- package/.hygen/new/crud/entity.ejs.t +26 -0
- package/.hygen/new/crud/get.dto.ejs.t +19 -0
- package/.hygen/new/crud/index-dto.ejs.t +29 -0
- package/.hygen/new/crud/index-response.dto.ejs.t +18 -0
- package/.hygen/new/crud/module.ejs.t +32 -0
- package/.hygen/new/crud/prompt.js +89 -0
- package/.hygen/new/crud/service.ejs.t +76 -0
- package/.hygen/new/crud/update.dto.ejs.t +11 -0
- package/.hygen/new/module/controller.ejs.t +93 -0
- package/.hygen/new/module/create-command.ejs.t +90 -0
- package/.hygen/new/module/create.dto.ejs.t +11 -0
- package/.hygen/new/module/dto.ejs.t +24 -0
- package/.hygen/new/module/entity.ejs.t +33 -0
- package/.hygen/new/module/get-query.ejs.t +57 -0
- package/.hygen/new/module/module.ejs.t +44 -0
- package/.hygen/new/module/not-found.exception.ejs.t +18 -0
- package/.hygen/new/module/page-options.dto.ejs.t +12 -0
- package/.hygen/new/module/prompt.js +104 -0
- package/.hygen/new/module/repository.ejs.t +16 -0
- package/.hygen/new/module/service.ejs.t +139 -0
- package/.hygen/new/module/translation-dto.ejs.t +27 -0
- package/.hygen/new/module/translation-entity.ejs.t +40 -0
- package/.hygen/new/module/translation-repository.ejs.t +16 -0
- package/.hygen/new/module/update.dto.ejs.t +10 -0
- package/.hygen.js +116 -0
- package/cache/cache-metrics.service.d.ts +83 -0
- package/cache/cache-metrics.service.js +298 -0
- package/cache/cache-serialization.service.d.ts +22 -0
- package/cache/cache-serialization.service.js +122 -0
- package/cache/cache.constants.d.ts +2 -0
- package/cache/cache.constants.js +5 -0
- package/cache/cache.health.d.ts +35 -0
- package/cache/cache.health.js +193 -0
- package/cache/cache.module.d.ts +26 -0
- package/cache/cache.module.js +155 -0
- package/cache/cache.service.d.ts +37 -0
- package/cache/cache.service.js +308 -0
- package/cache/cache.warmup.service.d.ts +34 -0
- package/cache/cache.warmup.service.js +199 -0
- package/cache/decorators/cache-evict.decorator.d.ts +2 -0
- package/cache/decorators/cache-evict.decorator.js +72 -0
- package/cache/decorators/cache-put.decorator.d.ts +2 -0
- package/cache/decorators/cache-put.decorator.js +48 -0
- package/cache/decorators/cacheable.decorator.d.ts +4 -0
- package/cache/decorators/cacheable.decorator.js +68 -0
- package/cache/decorators/index.d.ts +3 -0
- package/cache/decorators/index.js +11 -0
- package/cache/dependencies/callback.dependency.d.ts +11 -0
- package/cache/dependencies/callback.dependency.js +92 -0
- package/cache/dependencies/chain.dependency.d.ts +20 -0
- package/cache/dependencies/chain.dependency.js +113 -0
- package/cache/dependencies/db.dependency.d.ts +15 -0
- package/cache/dependencies/db.dependency.js +71 -0
- package/cache/dependencies/file.dependency.d.ts +17 -0
- package/cache/dependencies/file.dependency.js +63 -0
- package/cache/dependencies/index.d.ts +6 -0
- package/cache/dependencies/index.js +22 -0
- package/cache/dependencies/tag.dependency.d.ts +16 -0
- package/cache/dependencies/tag.dependency.js +75 -0
- package/cache/dependencies/time.dependency.d.ts +19 -0
- package/cache/dependencies/time.dependency.js +71 -0
- package/cache/examples/basic-usage.d.ts +58 -0
- package/cache/examples/basic-usage.js +379 -0
- package/cache/index.d.ts +15 -0
- package/cache/index.js +44 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +11 -0
- package/cache/interfaces/cache-dependency.interface.js +2 -0
- package/cache/interfaces/cache-options.interface.d.ts +32 -0
- package/cache/interfaces/cache-options.interface.js +9 -0
- package/cache/interfaces/cache-provider.interface.d.ts +28 -0
- package/cache/interfaces/cache-provider.interface.js +2 -0
- package/cache/interfaces/index.d.ts +3 -0
- package/cache/interfaces/index.js +19 -0
- package/cache/providers/base-cache.provider.d.ts +16 -0
- package/cache/providers/base-cache.provider.js +32 -0
- package/cache/providers/cls-cache.provider.d.ts +16 -0
- package/cache/providers/cls-cache.provider.js +140 -0
- package/cache/providers/index.d.ts +4 -0
- package/cache/providers/index.js +23 -0
- package/cache/providers/memory-cache.provider.d.ts +26 -0
- package/cache/providers/memory-cache.provider.js +171 -0
- package/cache/providers/redis-cache.provider.d.ts +23 -0
- package/cache/providers/redis-cache.provider.js +215 -0
- package/cache/utils/dependency-manager.util.d.ts +15 -0
- package/cache/utils/dependency-manager.util.js +141 -0
- package/cache/utils/index.d.ts +2 -0
- package/cache/utils/index.js +18 -0
- package/cache/utils/key-generator.util.d.ts +13 -0
- package/cache/utils/key-generator.util.js +74 -0
- package/common/abstract.entity.d.ts +20 -0
- package/common/abstract.entity.js +81 -0
- package/common/boilerplate.polyfill.d.ts +50 -0
- package/common/boilerplate.polyfill.js +152 -0
- package/common/dto/abstract.dto.d.ts +13 -0
- package/common/dto/abstract.dto.js +59 -0
- package/common/dto/bulk-id.dto.d.ts +3 -0
- package/common/dto/bulk-id.dto.js +27 -0
- package/common/dto/create-translation.dto.d.ts +5 -0
- package/common/dto/create-translation.dto.js +25 -0
- package/common/dto/dto-container.d.ts +9 -0
- package/common/dto/dto-container.js +59 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +59 -0
- package/common/dto/dto-extensions.d.ts +12 -0
- package/common/dto/dto-extensions.js +63 -0
- package/common/dto/dto-service-accessor.d.ts +7 -0
- package/common/dto/dto-service-accessor.js +49 -0
- package/common/dto/dto-transformer.d.ts +11 -0
- package/common/dto/dto-transformer.js +49 -0
- package/common/dto/index.d.ts +12 -0
- package/common/dto/index.js +28 -0
- package/common/dto/page-meta.dto.d.ts +15 -0
- package/common/dto/page-meta.dto.js +48 -0
- package/common/dto/page-options.dto.d.ts +5 -0
- package/common/dto/page-options.dto.js +40 -0
- package/common/dto/page.dto.d.ts +11 -0
- package/common/dto/page.dto.js +53 -0
- package/common/examples/paginate-and-map.example.d.ts +14 -0
- package/common/examples/paginate-and-map.example.js +158 -0
- package/common/index.d.ts +6 -0
- package/common/index.js +22 -0
- package/common/snake-naming.strategy.d.ts +11 -0
- package/common/snake-naming.strategy.js +37 -0
- package/common/types.d.ts +9 -0
- package/common/types.js +2 -0
- package/common/utils.d.ts +3 -0
- package/common/utils.js +24 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +18 -0
- package/constants/language-code.d.ts +5 -0
- package/constants/language-code.js +9 -0
- package/constants/order.d.ts +4 -0
- package/constants/order.js +8 -0
- package/decorators/api-page-ok-response.decorator.d.ts +5 -0
- package/decorators/api-page-ok-response.decorator.js +24 -0
- package/decorators/api-paginated-response.decorator.d.ts +2 -0
- package/decorators/api-paginated-response.decorator.js +9 -0
- package/decorators/auth-user.decorator.d.ts +1 -0
- package/decorators/auth-user.decorator.js +14 -0
- package/decorators/controller.decorator.d.ts +1 -0
- package/decorators/controller.decorator.js +10 -0
- package/decorators/examples/validation-decorators.example.d.ts +69 -0
- package/decorators/examples/validation-decorators.example.js +331 -0
- package/decorators/field.decorators.d.ts +79 -0
- package/decorators/field.decorators.js +499 -0
- package/decorators/http.decorators.d.ts +3 -0
- package/decorators/http.decorators.js +7 -0
- package/decorators/index.d.ts +14 -0
- package/decorators/index.js +30 -0
- package/decorators/operation.decorator.d.ts +1 -0
- package/decorators/operation.decorator.js +6 -0
- package/decorators/paginated-response.decorator.d.ts +11 -0
- package/decorators/paginated-response.decorator.js +60 -0
- package/decorators/property.decorators.d.ts +15 -0
- package/decorators/property.decorators.js +31 -0
- package/decorators/public-route.decorator.d.ts +3 -0
- package/decorators/public-route.decorator.js +7 -0
- package/decorators/swagger.schema.d.ts +5 -0
- package/decorators/swagger.schema.js +78 -0
- package/decorators/timestamp-column.decorator.d.ts +1 -0
- package/decorators/timestamp-column.decorator.js +27 -0
- package/decorators/transform.decorators.d.ts +8 -0
- package/decorators/transform.decorators.js +100 -0
- package/decorators/translate.decorator.d.ts +5 -0
- package/decorators/translate.decorator.js +17 -0
- package/decorators/use-dto.decorator.d.ts +4 -0
- package/decorators/use-dto.decorator.js +8 -0
- package/decorators/user-check.decorator.d.ts +6 -0
- package/decorators/user-check.decorator.js +21 -0
- package/decorators/user.decorator.d.ts +12 -0
- package/decorators/user.decorator.js +44 -0
- package/decorators/user_auth.decorator.d.ts +1 -0
- package/decorators/user_auth.decorator.js +15 -0
- package/decorators/validator.decorators.d.ts +18 -0
- package/decorators/validator.decorators.js +193 -0
- package/exceptions/file-not-image.exception.d.ts +4 -0
- package/exceptions/file-not-image.exception.js +10 -0
- package/exceptions/index.d.ts +2 -0
- package/exceptions/index.js +18 -0
- package/exceptions/page-type.exception.d.ts +4 -0
- package/exceptions/page-type.exception.js +10 -0
- package/exceptions/user-not-found.exception.d.ts +4 -0
- package/exceptions/user-not-found.exception.js +10 -0
- package/filters/bad-request.filter.d.ts +5 -0
- package/filters/bad-request.filter.js +71 -0
- package/filters/constraint-errors.d.ts +1 -0
- package/filters/constraint-errors.js +6 -0
- package/filters/index.d.ts +3 -0
- package/filters/index.js +19 -0
- package/filters/query-failed.filter.d.ts +10 -0
- package/filters/query-failed.filter.js +42 -0
- package/health-checker/health-checker.controller.d.ts +13 -0
- package/health-checker/health-checker.controller.js +69 -0
- package/health-checker/health-checker.module.d.ts +2 -0
- package/health-checker/health-checker.module.js +24 -0
- package/health-checker/index.d.ts +2 -0
- package/health-checker/index.js +18 -0
- package/helpers/common.helper.d.ts +3 -0
- package/helpers/common.helper.js +36 -0
- package/helpers/date.helper.d.ts +10 -0
- package/helpers/date.helper.js +57 -0
- package/helpers/index.d.ts +2 -0
- package/helpers/index.js +18 -0
- package/i18n/en_US/validation.json +44 -0
- package/i18n/zh_CN/validation.json +44 -0
- package/index.d.ts +18 -0
- package/index.js +3 -0
- package/interceptors/index.d.ts +2 -0
- package/interceptors/index.js +18 -0
- package/interceptors/language-interceptor.service.d.ts +6 -0
- package/interceptors/language-interceptor.service.js +29 -0
- package/interceptors/translation-interceptor.service.d.ts +5 -0
- package/interceptors/translation-interceptor.service.js +34 -0
- package/interfaces/IApiFile.d.ts +4 -0
- package/interfaces/IApiFile.js +2 -0
- package/interfaces/IFile.d.ts +8 -0
- package/interfaces/IFile.js +2 -0
- package/interfaces/ITranslationDecoratorInterface.d.ts +3 -0
- package/interfaces/ITranslationDecoratorInterface.js +2 -0
- package/interfaces/index.d.ts +3 -0
- package/interfaces/index.js +19 -0
- package/interfaces/response.d.ts +25 -0
- package/interfaces/response.js +2 -0
- package/middlewares/index.d.ts +4 -0
- package/middlewares/index.js +20 -0
- package/middlewares/omni-auth.middleware.d.ts +1 -0
- package/middlewares/omni-auth.middleware.js +13 -0
- package/middlewares/powerby.middleware.d.ts +1 -0
- package/middlewares/powerby.middleware.js +10 -0
- package/middlewares/request-id.middleware.d.ts +7 -0
- package/middlewares/request-id.middleware.js +22 -0
- package/middlewares/xml.middleware.d.ts +4 -0
- package/middlewares/xml.middleware.js +24 -0
- package/package.json +41 -116
- package/providers/context.provider.d.ts +34 -0
- package/providers/context.provider.js +80 -0
- package/providers/generator.provider.d.ts +9 -0
- package/providers/generator.provider.js +50 -0
- package/providers/index.d.ts +2 -0
- package/providers/index.js +18 -0
- package/redis-lock/examples/lock-strategy.examples.d.ts +73 -0
- package/redis-lock/examples/lock-strategy.examples.js +387 -0
- package/redis-lock/index.d.ts +4 -0
- package/redis-lock/index.js +16 -0
- package/redis-lock/redis-lock.decorator.d.ts +12 -0
- package/redis-lock/redis-lock.decorator.js +125 -0
- package/redis-lock/redis-lock.module.d.ts +23 -0
- package/redis-lock/redis-lock.module.js +117 -0
- package/redis-lock/redis-lock.service.d.ts +66 -0
- package/redis-lock/redis-lock.service.js +413 -0
- package/setup/bootstrap.setup.d.ts +2 -0
- package/setup/bootstrap.setup.js +184 -0
- package/setup/index.d.ts +4 -0
- package/setup/index.js +20 -0
- package/setup/mode.setup.d.ts +12 -0
- package/setup/mode.setup.js +60 -0
- package/setup/schedule.decorator.d.ts +23 -0
- package/setup/schedule.decorator.js +233 -0
- package/setup/worker.decorator.d.ts +14 -0
- package/setup/worker.decorator.js +130 -0
- package/shared/index.d.ts +2 -0
- package/shared/index.js +18 -0
- package/shared/serviceRegistryModule.d.ts +2 -0
- package/shared/serviceRegistryModule.js +170 -0
- package/shared/services/api-config.service.d.ts +54 -0
- package/shared/services/api-config.service.js +287 -0
- package/shared/services/generator.service.d.ts +4 -0
- package/shared/services/generator.service.js +23 -0
- package/shared/services/index.d.ts +4 -0
- package/shared/services/index.js +20 -0
- package/shared/services/translation.service.d.ts +9 -0
- package/shared/services/translation.service.js +70 -0
- package/shared/services/validator.service.d.ts +3 -0
- package/shared/services/validator.service.js +20 -0
- package/validator-json/decorators.d.ts +6 -0
- package/validator-json/decorators.js +22 -0
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +138 -0
- package/validator-json/defaultConverters.d.ts +8 -0
- package/validator-json/defaultConverters.js +376 -0
- package/validator-json/index.d.ts +4 -0
- package/validator-json/index.js +20 -0
- package/validator-json/options.d.ts +11 -0
- package/validator-json/options.js +10 -0
- package/validators/file-mimetype.validator.d.ts +13 -0
- package/validators/file-mimetype.validator.js +21 -0
- package/validators/index.d.ts +6 -0
- package/validators/index.js +22 -0
- package/validators/is-exists.validator.d.ts +18 -0
- package/validators/is-exists.validator.js +60 -0
- package/validators/is-unique.validator.d.ts +17 -0
- package/validators/is-unique.validator.js +91 -0
- package/validators/phone-country-code.validator.d.ts +2 -0
- package/validators/phone-country-code.validator.js +29 -0
- package/validators/same-as.validator.d.ts +2 -0
- package/validators/same-as.validator.js +24 -0
- package/validators/skip-empty.validator.d.ts +1 -0
- package/validators/skip-empty.validator.js +17 -0
- package/vault/index.d.ts +4 -0
- package/vault/index.js +20 -0
- package/vault/interfaces/vault-options.interface.d.ts +22 -0
- package/vault/interfaces/vault-options.interface.js +2 -0
- package/vault/vault-config.loader.d.ts +13 -0
- package/vault/vault-config.loader.js +246 -0
- package/vault/vault-config.service.d.ts +18 -0
- package/vault/vault-config.service.js +174 -0
- package/vault/vault.module.d.ts +2 -0
- package/vault/vault.module.js +21 -0
|
@@ -0,0 +1,23 @@
|
|
|
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.GeneratorService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const uuid_1 = require("uuid");
|
|
12
|
+
let GeneratorService = class GeneratorService {
|
|
13
|
+
uuid() {
|
|
14
|
+
return (0, uuid_1.v1)();
|
|
15
|
+
}
|
|
16
|
+
fileName(ext) {
|
|
17
|
+
return this.uuid() + '.' + ext;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.GeneratorService = GeneratorService;
|
|
21
|
+
exports.GeneratorService = GeneratorService = __decorate([
|
|
22
|
+
(0, common_1.Injectable)()
|
|
23
|
+
], GeneratorService);
|
|
@@ -0,0 +1,20 @@
|
|
|
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);
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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);
|
|
@@ -0,0 +1,20 @@
|
|
|
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);
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|