@nest-omni/core 2.0.1-9 → 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.
Files changed (205) hide show
  1. package/index.js +4 -0
  2. package/package.json +150 -46
  3. package/.hygen/new/crud/controller.ejs.t +0 -82
  4. package/.hygen/new/crud/create.dto.ejs.t +0 -12
  5. package/.hygen/new/crud/entity.ejs.t +0 -26
  6. package/.hygen/new/crud/get.dto.ejs.t +0 -19
  7. package/.hygen/new/crud/index-dto.ejs.t +0 -29
  8. package/.hygen/new/crud/index-response.dto.ejs.t +0 -18
  9. package/.hygen/new/crud/module.ejs.t +0 -32
  10. package/.hygen/new/crud/prompt.js +0 -89
  11. package/.hygen/new/crud/service.ejs.t +0 -76
  12. package/.hygen/new/crud/update.dto.ejs.t +0 -11
  13. package/.hygen/new/module/controller.ejs.t +0 -93
  14. package/.hygen/new/module/create-command.ejs.t +0 -90
  15. package/.hygen/new/module/create.dto.ejs.t +0 -11
  16. package/.hygen/new/module/dto.ejs.t +0 -24
  17. package/.hygen/new/module/entity.ejs.t +0 -33
  18. package/.hygen/new/module/get-query.ejs.t +0 -57
  19. package/.hygen/new/module/module.ejs.t +0 -44
  20. package/.hygen/new/module/not-found.exception.ejs.t +0 -18
  21. package/.hygen/new/module/page-options.dto.ejs.t +0 -12
  22. package/.hygen/new/module/prompt.js +0 -104
  23. package/.hygen/new/module/repository.ejs.t +0 -16
  24. package/.hygen/new/module/service.ejs.t +0 -139
  25. package/.hygen/new/module/translation-dto.ejs.t +0 -27
  26. package/.hygen/new/module/translation-entity.ejs.t +0 -40
  27. package/.hygen/new/module/translation-repository.ejs.t +0 -16
  28. package/.hygen/new/module/update.dto.ejs.t +0 -10
  29. package/.hygen.js +0 -116
  30. package/common/abstract-client.service.d.ts +0 -16
  31. package/common/abstract-client.service.js +0 -35
  32. package/common/abstract.entity.d.ts +0 -18
  33. package/common/abstract.entity.js +0 -78
  34. package/common/boilerplate.polyfill.d.ts +0 -39
  35. package/common/boilerplate.polyfill.js +0 -77
  36. package/common/dto/abstract.dto.d.ts +0 -13
  37. package/common/dto/abstract.dto.js +0 -59
  38. package/common/dto/bulk-id.dto.d.ts +0 -3
  39. package/common/dto/bulk-id.dto.js +0 -27
  40. package/common/dto/create-translation.dto.d.ts +0 -5
  41. package/common/dto/create-translation.dto.js +0 -25
  42. package/common/dto/index.d.ts +0 -6
  43. package/common/dto/index.js +0 -22
  44. package/common/dto/page-meta.dto.d.ts +0 -15
  45. package/common/dto/page-meta.dto.js +0 -48
  46. package/common/dto/page-options.dto.d.ts +0 -8
  47. package/common/dto/page-options.dto.js +0 -52
  48. package/common/dto/page.dto.d.ts +0 -11
  49. package/common/dto/page.dto.js +0 -53
  50. package/common/index.d.ts +0 -7
  51. package/common/index.js +0 -23
  52. package/common/snake-naming.strategy.d.ts +0 -11
  53. package/common/snake-naming.strategy.js +0 -37
  54. package/common/types.d.ts +0 -9
  55. package/common/types.js +0 -2
  56. package/common/utils.d.ts +0 -3
  57. package/common/utils.js +0 -24
  58. package/constants/index.d.ts +0 -2
  59. package/constants/index.js +0 -18
  60. package/constants/language-code.d.ts +0 -5
  61. package/constants/language-code.js +0 -9
  62. package/constants/order.d.ts +0 -4
  63. package/constants/order.js +0 -8
  64. package/decorators/api-page-ok-response.decorator.d.ts +0 -5
  65. package/decorators/api-page-ok-response.decorator.js +0 -24
  66. package/decorators/auth-user.decorator.d.ts +0 -1
  67. package/decorators/auth-user.decorator.js +0 -14
  68. package/decorators/controller.decorator.d.ts +0 -1
  69. package/decorators/controller.decorator.js +0 -10
  70. package/decorators/field.decorators.d.ts +0 -79
  71. package/decorators/field.decorators.js +0 -497
  72. package/decorators/http.decorators.d.ts +0 -3
  73. package/decorators/http.decorators.js +0 -7
  74. package/decorators/index.d.ts +0 -12
  75. package/decorators/index.js +0 -28
  76. package/decorators/operation.decorator.d.ts +0 -1
  77. package/decorators/operation.decorator.js +0 -6
  78. package/decorators/property.decorators.d.ts +0 -15
  79. package/decorators/property.decorators.js +0 -31
  80. package/decorators/public-route.decorator.d.ts +0 -3
  81. package/decorators/public-route.decorator.js +0 -7
  82. package/decorators/swagger.schema.d.ts +0 -5
  83. package/decorators/swagger.schema.js +0 -78
  84. package/decorators/timestamp-column.decorator.d.ts +0 -1
  85. package/decorators/timestamp-column.decorator.js +0 -27
  86. package/decorators/transform.decorators.d.ts +0 -8
  87. package/decorators/transform.decorators.js +0 -100
  88. package/decorators/translate.decorator.d.ts +0 -5
  89. package/decorators/translate.decorator.js +0 -17
  90. package/decorators/use-dto.decorator.d.ts +0 -4
  91. package/decorators/use-dto.decorator.js +0 -8
  92. package/decorators/user-check.decorator.d.ts +0 -6
  93. package/decorators/user-check.decorator.js +0 -21
  94. package/decorators/user.decorator.d.ts +0 -12
  95. package/decorators/user.decorator.js +0 -44
  96. package/decorators/user_auth.decorator.d.ts +0 -1
  97. package/decorators/user_auth.decorator.js +0 -15
  98. package/decorators/validator.decorators.d.ts +0 -11
  99. package/decorators/validator.decorators.js +0 -78
  100. package/exceptions/file-not-image.exception.d.ts +0 -4
  101. package/exceptions/file-not-image.exception.js +0 -10
  102. package/exceptions/index.d.ts +0 -2
  103. package/exceptions/index.js +0 -18
  104. package/exceptions/page-type.exception.d.ts +0 -4
  105. package/exceptions/page-type.exception.js +0 -10
  106. package/exceptions/user-not-found.exception.d.ts +0 -4
  107. package/exceptions/user-not-found.exception.js +0 -10
  108. package/filters/bad-request.filter.d.ts +0 -5
  109. package/filters/bad-request.filter.js +0 -71
  110. package/filters/constraint-errors.d.ts +0 -1
  111. package/filters/constraint-errors.js +0 -6
  112. package/filters/index.d.ts +0 -3
  113. package/filters/index.js +0 -19
  114. package/filters/query-failed.filter.d.ts +0 -10
  115. package/filters/query-failed.filter.js +0 -42
  116. package/health-checker/health-checker.controller.d.ts +0 -15
  117. package/health-checker/health-checker.controller.js +0 -72
  118. package/health-checker/health-checker.module.d.ts +0 -2
  119. package/health-checker/health-checker.module.js +0 -25
  120. package/health-checker/health-indicators/service.indicator.d.ts +0 -8
  121. package/health-checker/health-indicators/service.indicator.js +0 -66
  122. package/helpers/common.helper.d.ts +0 -3
  123. package/helpers/common.helper.js +0 -36
  124. package/helpers/date.helper.d.ts +0 -10
  125. package/helpers/date.helper.js +0 -57
  126. package/helpers/index.d.ts +0 -2
  127. package/helpers/index.js +0 -18
  128. package/i18n/en_US/validation.json +0 -41
  129. package/i18n/zh_CN/validation.json +0 -41
  130. package/index.d.ts +0 -11
  131. package/interceptors/index.d.ts +0 -2
  132. package/interceptors/index.js +0 -18
  133. package/interceptors/language-interceptor.service.d.ts +0 -6
  134. package/interceptors/language-interceptor.service.js +0 -29
  135. package/interceptors/translation-interceptor.service.d.ts +0 -5
  136. package/interceptors/translation-interceptor.service.js +0 -34
  137. package/interfaces/IApiFile.d.ts +0 -4
  138. package/interfaces/IApiFile.js +0 -2
  139. package/interfaces/IFile.d.ts +0 -8
  140. package/interfaces/IFile.js +0 -2
  141. package/interfaces/ITranslationDecoratorInterface.d.ts +0 -3
  142. package/interfaces/ITranslationDecoratorInterface.js +0 -2
  143. package/interfaces/index.d.ts +0 -3
  144. package/interfaces/index.js +0 -19
  145. package/interfaces/response.d.ts +0 -25
  146. package/interfaces/response.js +0 -2
  147. package/middlewares/index.d.ts +0 -4
  148. package/middlewares/index.js +0 -20
  149. package/middlewares/omni-auth.middleware.d.ts +0 -1
  150. package/middlewares/omni-auth.middleware.js +0 -13
  151. package/middlewares/powerby.middleware.d.ts +0 -1
  152. package/middlewares/powerby.middleware.js +0 -10
  153. package/middlewares/request-id.middleware.d.ts +0 -7
  154. package/middlewares/request-id.middleware.js +0 -22
  155. package/middlewares/xml.middleware.d.ts +0 -4
  156. package/middlewares/xml.middleware.js +0 -24
  157. package/providers/context.provider.d.ts +0 -34
  158. package/providers/context.provider.js +0 -80
  159. package/providers/generator.provider.d.ts +0 -9
  160. package/providers/generator.provider.js +0 -50
  161. package/providers/index.d.ts +0 -2
  162. package/providers/index.js +0 -18
  163. package/setup/bootstrap.setup.d.ts +0 -2
  164. package/setup/bootstrap.setup.js +0 -227
  165. package/setup/index.d.ts +0 -1
  166. package/setup/index.js +0 -17
  167. package/shared/index.d.ts +0 -2
  168. package/shared/index.js +0 -18
  169. package/shared/serviceRegistryModule.d.ts +0 -2
  170. package/shared/serviceRegistryModule.js +0 -111
  171. package/shared/services/api-config.service.d.ts +0 -58
  172. package/shared/services/api-config.service.js +0 -302
  173. package/shared/services/generator.service.d.ts +0 -4
  174. package/shared/services/generator.service.js +0 -23
  175. package/shared/services/index.d.ts +0 -4
  176. package/shared/services/index.js +0 -20
  177. package/shared/services/translation.service.d.ts +0 -9
  178. package/shared/services/translation.service.js +0 -70
  179. package/shared/services/validator.service.d.ts +0 -3
  180. package/shared/services/validator.service.js +0 -20
  181. package/tsconfig.tsbuildinfo +0 -1
  182. package/validator-json/decorators.d.ts +0 -6
  183. package/validator-json/decorators.js +0 -22
  184. package/validator-json/default.d.ts +0 -6
  185. package/validator-json/default.js +0 -130
  186. package/validator-json/defaultConverters.d.ts +0 -8
  187. package/validator-json/defaultConverters.js +0 -376
  188. package/validator-json/index.d.ts +0 -4
  189. package/validator-json/index.js +0 -20
  190. package/validator-json/options.d.ts +0 -11
  191. package/validator-json/options.js +0 -10
  192. package/validators/file-mimetype.validator.d.ts +0 -13
  193. package/validators/file-mimetype.validator.js +0 -21
  194. package/validators/index.d.ts +0 -6
  195. package/validators/index.js +0 -22
  196. package/validators/is-exists.validator.d.ts +0 -18
  197. package/validators/is-exists.validator.js +0 -62
  198. package/validators/is-unique.validator.d.ts +0 -17
  199. package/validators/is-unique.validator.js +0 -93
  200. package/validators/phone-country-code.validator.d.ts +0 -2
  201. package/validators/phone-country-code.validator.js +0 -29
  202. package/validators/same-as.validator.d.ts +0 -2
  203. package/validators/same-as.validator.js +0 -24
  204. package/validators/skip-empty.validator.d.ts +0 -1
  205. package/validators/skip-empty.validator.js +0 -17
@@ -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,130 +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' ? meta.message(meta) : meta.message;
87
- if ((0, lodash_1.isString)(originMessage)) {
88
- const [translationKey, argsString] = originMessage.split('|');
89
- const args = !!argsString ? JSON.parse(argsString) : {};
90
- message = i18n.translate(translationKey, Object.assign(Object.assign({}, options), { args: Object.assign({ constraints: meta.constraints }, args) }));
91
- }
92
- items['type'] = meta.type;
93
- items['dataType'] = (converterResult === null || converterResult === void 0 ? void 0 : converterResult.type) || undefined;
94
- items['attrs'] = meta.constraints || [];
95
- items['message'] = message;
96
- if (meta.each && isMap) {
97
- return {
98
- additionalProperties: Object.assign({}, items),
99
- type: 'object',
100
- };
101
- }
102
- return meta.each ? { items, type: 'array' } : items;
103
- };
104
- const constraints = propertyMetadatas.map((meta) => {
105
- return convert(meta);
106
- });
107
- return (0, lodash_1.reject)(constraints, (item) => (0, lodash_1.isEmpty)(item));
108
- }
109
- function isExcluded(propertyMetadata, options) {
110
- var _a;
111
- return !!((_a = options.classTransformerMetadataStorage) === null || _a === void 0 ? void 0 : _a.findExcludeMetadata(propertyMetadata.target, propertyMetadata.propertyName));
112
- }
113
- function getRequiredPropNames(target, metadatas, options) {
114
- function isDefined(metas) {
115
- return (metas && metas.some(({ type }) => type === cv.ValidationTypes.IS_DEFINED));
116
- }
117
- function isOptional(metas) {
118
- return (metas &&
119
- metas.some(({ type }) => [cv.ValidationTypes.CONDITIONAL_VALIDATION, cv.IS_EMPTY].includes(type)));
120
- }
121
- return (Object.entries((0, lodash_1.groupBy)(metadatas, (m) => m.propertyName))
122
- .filter(([_, metas]) => {
123
- const own = metas.filter((m) => m.target === target);
124
- const inherited = metas.filter((m) => m.target !== target);
125
- return options.skipMissingProperties
126
- ? isDefined(own) || (!isOptional(own) && isDefined(inherited))
127
- : !(isOptional(own) || isOptional(inherited));
128
- })
129
- .map(([name]) => name));
130
- }
@@ -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;
@@ -1,376 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultConverters = void 0;
4
- const cv = require("class-validator");
5
- require("reflect-metadata");
6
- exports.defaultConverters = {
7
- [cv.ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
8
- if (typeof meta.target === 'function') {
9
- const type = getPropType(meta.target.prototype, meta.propertyName);
10
- return targetToSchema(type, options);
11
- }
12
- },
13
- [cv.ValidationTypes.NESTED_VALIDATION]: (meta, options) => {
14
- if (typeof meta.target === 'function') {
15
- const typeMeta = options.classTransformerMetadataStorage
16
- ? options.classTransformerMetadataStorage.findTypeMetadata(meta.target, meta.propertyName)
17
- : null;
18
- const childType = typeMeta
19
- ? typeMeta.typeFunction()
20
- : getPropType(meta.target.prototype, meta.propertyName);
21
- return targetToSchema(childType, options);
22
- }
23
- },
24
- [cv.ValidationTypes.WHITELIST]: {},
25
- [cv.ValidationTypes.CONDITIONAL_VALIDATION]: {},
26
- [cv.ValidationTypes.IS_DEFINED]: {
27
- not: { type: 'null' },
28
- },
29
- [cv.EQUALS]: (meta) => {
30
- const schema = constraintToSchema(meta.constraints[0]);
31
- if (schema) {
32
- return Object.assign(Object.assign({}, schema), { enum: [meta.constraints[0]] });
33
- }
34
- },
35
- [cv.NOT_EQUALS]: (meta) => {
36
- const schema = constraintToSchema(meta.constraints[0]);
37
- if (schema) {
38
- return { not: Object.assign(Object.assign({}, schema), { enum: [meta.constraints[0]] }) };
39
- }
40
- },
41
- [cv.IS_EMPTY]: {
42
- type: 'string',
43
- anyOf: [
44
- { type: 'string', enum: [''] },
45
- {
46
- not: {
47
- anyOf: [
48
- { type: 'string' },
49
- { type: 'number' },
50
- { type: 'boolean' },
51
- { type: 'integer' },
52
- { type: 'array' },
53
- { type: 'object' },
54
- ],
55
- },
56
- nullable: true,
57
- },
58
- ],
59
- },
60
- [cv.IS_NOT_EMPTY]: {
61
- minLength: 1,
62
- type: 'string',
63
- },
64
- [cv.IS_IN]: (meta) => {
65
- const [head, ...rest] = meta.constraints[0].map(constraintToSchema);
66
- if (head && rest.every((item) => item.type === head.type)) {
67
- return Object.assign(Object.assign({}, head), { enum: meta.constraints[0] });
68
- }
69
- return {
70
- type: 'string',
71
- };
72
- },
73
- [cv.IS_NOT_IN]: (meta) => {
74
- const [head, ...rest] = meta.constraints[0].map(constraintToSchema);
75
- if (head && rest.every((item) => item.type === head.type)) {
76
- return { not: Object.assign(Object.assign({}, head), { enum: meta.constraints[0] }) };
77
- }
78
- return {
79
- type: 'string',
80
- };
81
- },
82
- [cv.IS_BOOLEAN]: {
83
- type: 'boolean',
84
- },
85
- [cv.IS_DATE]: {
86
- type: 'string',
87
- oneOf: [
88
- { format: 'date', type: 'string' },
89
- { format: 'date-time', type: 'string' },
90
- ],
91
- },
92
- [cv.IS_NUMBER]: {
93
- type: 'number',
94
- },
95
- [cv.IS_STRING]: {
96
- type: 'string',
97
- },
98
- [cv.IS_DATE_STRING]: {
99
- pattern: '\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d.\\d+Z?',
100
- type: 'string',
101
- },
102
- [cv.IS_ARRAY]: {
103
- items: {},
104
- type: 'array',
105
- },
106
- [cv.IS_INT]: {
107
- type: 'integer',
108
- },
109
- [cv.IS_ENUM]: (meta) => {
110
- return {
111
- enum: Object.values(meta.constraints[0]),
112
- type: 'string',
113
- };
114
- },
115
- [cv.IS_DIVISIBLE_BY]: (meta) => ({
116
- multipleOf: meta.constraints[0],
117
- type: 'number',
118
- }),
119
- [cv.IS_POSITIVE]: {
120
- exclusiveMinimum: 0,
121
- type: 'number',
122
- },
123
- [cv.IS_NEGATIVE]: {
124
- exclusiveMaximum: 0,
125
- type: 'number',
126
- },
127
- [cv.MIN]: (meta) => ({
128
- minimum: meta.constraints[0],
129
- type: 'number',
130
- }),
131
- [cv.MAX]: (meta) => ({
132
- maximum: meta.constraints[0],
133
- type: 'number',
134
- }),
135
- [cv.MIN_DATE]: (meta) => ({
136
- description: `After ${meta.constraints[0].toJSON()}`,
137
- oneOf: [
138
- { format: 'date', type: 'string' },
139
- { format: 'date-time', type: 'string' },
140
- ],
141
- }),
142
- [cv.MAX_DATE]: (meta) => ({
143
- description: `Before ${meta.constraints[0].toJSON()}`,
144
- oneOf: [
145
- { format: 'date', type: 'string' },
146
- { format: 'date-time', type: 'string' },
147
- ],
148
- }),
149
- [cv.IS_BOOLEAN_STRING]: {
150
- enum: ['true', 'false'],
151
- type: 'string',
152
- },
153
- [cv.IS_NUMBER_STRING]: {
154
- pattern: '^[-+]?[0-9]+$',
155
- type: 'string',
156
- },
157
- [cv.CONTAINS]: (meta) => ({
158
- pattern: meta.constraints[0],
159
- type: 'string',
160
- }),
161
- [cv.NOT_CONTAINS]: (meta) => ({
162
- not: { pattern: meta.constraints[0] },
163
- type: 'string',
164
- }),
165
- [cv.IS_ALPHA]: {
166
- pattern: '^[a-zA-Z]+$',
167
- type: 'string',
168
- },
169
- [cv.IS_ALPHANUMERIC]: {
170
- pattern: '^[0-9a-zA-Z]+$',
171
- type: 'string',
172
- },
173
- [cv.IS_ASCII]: {
174
- pattern: '^[\\x00-\\x7F]+$',
175
- type: 'string',
176
- },
177
- [cv.IS_BASE64]: {
178
- format: 'base64',
179
- type: 'string',
180
- },
181
- [cv.IS_BYTE_LENGTH]: {
182
- type: 'string',
183
- },
184
- [cv.IS_CREDIT_CARD]: {
185
- format: 'credit-card',
186
- type: 'string',
187
- },
188
- [cv.IS_CURRENCY]: {
189
- format: 'currency',
190
- type: 'string',
191
- },
192
- [cv.IS_EMAIL]: {
193
- format: 'email',
194
- type: 'string',
195
- },
196
- [cv.IS_FQDN]: {
197
- format: 'hostname',
198
- type: 'string',
199
- },
200
- [cv.IS_FULL_WIDTH]: {
201
- pattern: '[^\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
202
- type: 'string',
203
- },
204
- [cv.IS_HALF_WIDTH]: {
205
- pattern: '[\\u0020-\\u007E\\uFF61-\\uFF9F\\uFFA0-\\uFFDC\\uFFE8-\\uFFEE0-9a-zA-Z]',
206
- type: 'string',
207
- },
208
- [cv.IS_VARIABLE_WIDTH]: {
209
- type: 'string',
210
- },
211
- [cv.IS_HEX_COLOR]: {
212
- pattern: '^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$',
213
- type: 'string',
214
- },
215
- [cv.IS_HEXADECIMAL]: {
216
- pattern: '^[0-9a-fA-F]+$',
217
- type: 'string',
218
- },
219
- [cv.IS_IP]: (meta) => ({
220
- format: 'ipv' + (meta.constraints[0] === '6' ? 6 : 4),
221
- type: 'string',
222
- }),
223
- [cv.IS_ISBN]: {
224
- format: 'isbn',
225
- type: 'string',
226
- },
227
- [cv.IS_ISIN]: {
228
- format: 'isin',
229
- type: 'string',
230
- },
231
- [cv.IS_ISO8601]: {
232
- oneOf: [
233
- { format: 'date', type: 'string' },
234
- { format: 'date-time', type: 'string' },
235
- ],
236
- },
237
- [cv.IS_JSON]: {
238
- format: 'json',
239
- type: 'string',
240
- },
241
- [cv.IS_LOWERCASE]: {
242
- type: 'string',
243
- },
244
- [cv.IS_MOBILE_PHONE]: {
245
- format: 'mobile-phone',
246
- type: 'string',
247
- },
248
- [cv.IS_MONGO_ID]: {
249
- pattern: '^[0-9a-fA-F]{24}$',
250
- type: 'string',
251
- },
252
- [cv.IS_MULTIBYTE]: {
253
- pattern: '[^\\x00-\\x7F]',
254
- type: 'string',
255
- },
256
- [cv.IS_SURROGATE_PAIR]: {
257
- pattern: '[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]',
258
- type: 'string',
259
- },
260
- [cv.IS_URL]: {
261
- format: 'url',
262
- type: 'string',
263
- },
264
- [cv.IS_UUID]: {
265
- format: 'uuid',
266
- type: 'string',
267
- },
268
- [cv.IS_LENGTH]: (meta) => {
269
- const [minLength, maxLength] = meta.constraints;
270
- if (maxLength || maxLength === 0) {
271
- return { min: minLength, max: maxLength, type: 'Range' };
272
- }
273
- return { min: minLength, type: 'Range' };
274
- },
275
- [cv.IS_UPPERCASE]: {
276
- type: 'string',
277
- },
278
- [cv.IS_OBJECT]: {
279
- type: 'object',
280
- },
281
- [cv.IS_NOT_EMPTY_OBJECT]: {
282
- type: 'object',
283
- minProperties: 1,
284
- },
285
- [cv.MIN_LENGTH]: (meta) => ({
286
- minLength: meta.constraints[0],
287
- type: 'string',
288
- }),
289
- [cv.MAX_LENGTH]: (meta) => ({
290
- maxLength: meta.constraints[0],
291
- type: 'string',
292
- }),
293
- [cv.MATCHES]: (meta) => ({
294
- pattern: meta.constraints[0].source,
295
- type: 'string',
296
- }),
297
- [cv.IS_MILITARY_TIME]: {
298
- pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$',
299
- type: 'string',
300
- },
301
- [cv.ARRAY_CONTAINS]: (meta) => {
302
- const schemas = meta.constraints[0].map(constraintToSchema);
303
- if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
304
- return {
305
- not: {
306
- anyOf: schemas.map((d, i) => ({
307
- items: {
308
- not: Object.assign(Object.assign({}, d), { enum: [meta.constraints[0][i]] }),
309
- },
310
- })),
311
- },
312
- type: 'array',
313
- };
314
- }
315
- return { items: {}, type: 'array' };
316
- },
317
- [cv.ARRAY_NOT_CONTAINS]: (meta) => {
318
- const schemas = meta.constraints[0].map(constraintToSchema);
319
- if (schemas.length > 0 && schemas.every((s) => s && s.type)) {
320
- return {
321
- items: {
322
- not: {
323
- anyOf: schemas.map((d, i) => (Object.assign(Object.assign({}, d), { enum: [meta.constraints[0][i]] }))),
324
- },
325
- },
326
- type: 'array',
327
- };
328
- }
329
- return { items: {}, type: 'array' };
330
- },
331
- [cv.ARRAY_NOT_EMPTY]: {
332
- items: {},
333
- minItems: 1,
334
- type: 'array',
335
- },
336
- [cv.ARRAY_MIN_SIZE]: (meta) => ({
337
- items: {},
338
- minItems: meta.constraints[0],
339
- type: 'array',
340
- }),
341
- [cv.ARRAY_MAX_SIZE]: (meta) => ({
342
- items: {},
343
- maxItems: meta.constraints[0],
344
- type: 'array',
345
- }),
346
- [cv.ARRAY_UNIQUE]: {
347
- items: {},
348
- type: 'array',
349
- uniqueItems: true,
350
- },
351
- };
352
- function getPropType(target, property) {
353
- return Reflect.getMetadata('design:type', target, property);
354
- }
355
- function constraintToSchema(primitive) {
356
- const primitives = ['string', 'number', 'boolean'];
357
- const type = typeof primitive;
358
- if (primitives.includes(type)) {
359
- return { type: type };
360
- }
361
- }
362
- function targetToSchema(type, options) {
363
- if (typeof type === 'function') {
364
- if (type.prototype === String.prototype ||
365
- type.prototype === Symbol.prototype) {
366
- return { type: 'string' };
367
- }
368
- else if (type.prototype === Number.prototype) {
369
- return { type: 'number' };
370
- }
371
- else if (type.prototype === Boolean.prototype) {
372
- return { type: 'boolean' };
373
- }
374
- return { $ref: options.refPointerPrefix + type.name };
375
- }
376
- }
@@ -1,4 +0,0 @@
1
- export * from './default';
2
- export * from './decorators';
3
- export * from './defaultConverters';
4
- export * from './options';
@@ -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("./default"), exports);
18
- __exportStar(require("./decorators"), exports);
19
- __exportStar(require("./defaultConverters"), exports);
20
- __exportStar(require("./options"), exports);
@@ -1,11 +0,0 @@
1
- import type { MetadataStorage as ClassTransformerMetadataStorage } from 'class-transformer/types/MetadataStorage';
2
- import { MetadataStorage, ValidatorOptions } from 'class-validator';
3
- import { ISchemaConverters } from './defaultConverters';
4
- export interface IOptions extends ValidatorOptions {
5
- additionalConverters: ISchemaConverters;
6
- classTransformerMetadataStorage?: ClassTransformerMetadataStorage;
7
- classValidatorMetadataStorage: MetadataStorage;
8
- refPointerPrefix: string;
9
- schemaNameField: string;
10
- }
11
- export declare const defaultOptions: IOptions;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultOptions = void 0;
4
- const class_validator_1 = require("class-validator");
5
- exports.defaultOptions = {
6
- additionalConverters: {},
7
- classValidatorMetadataStorage: (0, class_validator_1.getMetadataStorage)(),
8
- refPointerPrefix: '#/definitions/',
9
- schemaNameField: 'name',
10
- };
@@ -1,13 +0,0 @@
1
- import { FileValidator } from '@nestjs/common/pipes/file/file-validator.interface';
2
- import { IFile } from '@nestjs/common/pipes/file/interfaces';
3
- export type FileMimetypeValidatorOptions = {
4
- allowedMimetypes: string[];
5
- message?: string;
6
- };
7
- export declare class FileMimetypeValidator extends FileValidator<FileMimetypeValidatorOptions, IFile> {
8
- private allowedMimetypes;
9
- private message;
10
- constructor(options: FileMimetypeValidatorOptions);
11
- buildErrorMessage(): string;
12
- isValid(file?: IFile): boolean;
13
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileMimetypeValidator = void 0;
4
- const file_validator_interface_1 = require("@nestjs/common/pipes/file/file-validator.interface");
5
- class FileMimetypeValidator extends file_validator_interface_1.FileValidator {
6
- constructor(options) {
7
- super(options);
8
- this.allowedMimetypes = options.allowedMimetypes;
9
- this.message = options.message;
10
- }
11
- buildErrorMessage() {
12
- if (this.message) {
13
- return this.message;
14
- }
15
- return `Invalid file type. Only ${this.allowedMimetypes.join(', ')} are allowed.`;
16
- }
17
- isValid(file) {
18
- return this.allowedMimetypes.includes(file.mimetype);
19
- }
20
- }
21
- exports.FileMimetypeValidator = FileMimetypeValidator;
@@ -1,6 +0,0 @@
1
- export * from './phone-country-code.validator';
2
- export * from './skip-empty.validator';
3
- export * from './file-mimetype.validator';
4
- export * from './is-exists.validator';
5
- export * from './is-unique.validator';
6
- export * from './same-as.validator';
@@ -1,22 +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("./phone-country-code.validator"), exports);
18
- __exportStar(require("./skip-empty.validator"), exports);
19
- __exportStar(require("./file-mimetype.validator"), exports);
20
- __exportStar(require("./is-exists.validator"), exports);
21
- __exportStar(require("./is-unique.validator"), exports);
22
- __exportStar(require("./same-as.validator"), exports);