@elsikora/nestjs-crud-automator 1.1.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/dist/class/api/base-service.class.d.ts +8 -0
- package/dist/class/api/base-service.class.js +13 -0
- package/dist/class/api/base-service.class.js.map +1 -0
- package/dist/class/api/index.d.ts +1 -0
- package/dist/class/api/index.js +18 -0
- package/dist/class/api/index.js.map +1 -0
- package/dist/class/index.d.ts +1 -0
- package/dist/class/index.js +18 -0
- package/dist/class/index.js.map +1 -0
- package/dist/constant/date.constant.d.ts +4 -0
- package/dist/constant/date.constant.js +10 -0
- package/dist/constant/date.constant.js.map +1 -0
- package/dist/constant/decorator/api/function.constant.d.ts +4 -0
- package/dist/constant/decorator/api/function.constant.js +9 -0
- package/dist/constant/decorator/api/function.constant.js.map +1 -0
- package/dist/constant/decorator/api/index.d.ts +1 -0
- package/dist/constant/decorator/api/index.js +18 -0
- package/dist/constant/decorator/api/index.js.map +1 -0
- package/dist/constant/decorator/index.d.ts +1 -0
- package/dist/constant/decorator/index.js +18 -0
- package/dist/constant/decorator/index.js.map +1 -0
- package/dist/constant/dto/exception.constant.d.ts +6 -0
- package/dist/constant/dto/exception.constant.js +14 -0
- package/dist/constant/dto/exception.constant.js.map +1 -0
- package/dist/constant/dto/index.d.ts +1 -0
- package/dist/constant/dto/index.js +18 -0
- package/dist/constant/dto/index.js.map +1 -0
- package/dist/constant/index.d.ts +5 -0
- package/dist/constant/index.js +22 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/constant/interface/api/filter.constant.d.ts +3 -0
- package/dist/constant/interface/api/filter.constant.js +12 -0
- package/dist/constant/interface/api/filter.constant.js.map +1 -0
- package/dist/constant/interface/api/index.d.ts +1 -0
- package/dist/constant/interface/api/index.js +18 -0
- package/dist/constant/interface/api/index.js.map +1 -0
- package/dist/constant/interface/api/property/index.d.ts +2 -0
- package/dist/constant/interface/api/property/index.js +19 -0
- package/dist/constant/interface/api/property/index.js.map +1 -0
- package/dist/constant/interface/api/property/string.constant.d.ts +6 -0
- package/dist/constant/interface/api/property/string.constant.js +12 -0
- package/dist/constant/interface/api/property/string.constant.js.map +1 -0
- package/dist/constant/interface/api/property/wallet.constant.d.ts +5 -0
- package/dist/constant/interface/api/property/wallet.constant.js +12 -0
- package/dist/constant/interface/api/property/wallet.constant.js.map +1 -0
- package/dist/constant/interface/index.d.ts +1 -0
- package/dist/constant/interface/index.js +18 -0
- package/dist/constant/interface/index.js.map +1 -0
- package/dist/constant/number.constant.d.ts +18 -0
- package/dist/constant/number.constant.js +38 -0
- package/dist/constant/number.constant.js.map +1 -0
- package/dist/decorator/api/function/decorator.d.ts +7 -0
- package/dist/decorator/api/function/decorator.js +27 -0
- package/dist/decorator/api/function/decorator.js.map +1 -0
- package/dist/decorator/api/function/get-list.decorator.d.ts +5 -0
- package/dist/decorator/api/function/get-list.decorator.js +129 -0
- package/dist/decorator/api/function/get-list.decorator.js.map +1 -0
- package/dist/decorator/api/function/get.decorator.d.ts +4 -0
- package/dist/decorator/api/function/get.decorator.js +58 -0
- package/dist/decorator/api/function/get.decorator.js.map +1 -0
- package/dist/decorator/api/function/index.d.ts +2 -0
- package/dist/decorator/api/function/index.js +19 -0
- package/dist/decorator/api/function/index.js.map +1 -0
- package/dist/decorator/api/index.d.ts +3 -0
- package/dist/decorator/api/index.js +20 -0
- package/dist/decorator/api/index.js.map +1 -0
- package/dist/decorator/api/method.decorator.d.ts +2 -0
- package/dist/decorator/api/method.decorator.js +203 -0
- package/dist/decorator/api/method.decorator.js.map +1 -0
- package/dist/decorator/api/property/boolean.decorator.d.ts +2 -0
- package/dist/decorator/api/property/boolean.decorator.js +77 -0
- package/dist/decorator/api/property/boolean.decorator.js.map +1 -0
- package/dist/decorator/api/property/date.decorator.d.ts +2 -0
- package/dist/decorator/api/property/date.decorator.js +87 -0
- package/dist/decorator/api/property/date.decorator.js.map +1 -0
- package/dist/decorator/api/property/index.d.ts +7 -0
- package/dist/decorator/api/property/index.js +24 -0
- package/dist/decorator/api/property/index.js.map +1 -0
- package/dist/decorator/api/property/number.decorator.d.ts +2 -0
- package/dist/decorator/api/property/number.decorator.js +146 -0
- package/dist/decorator/api/property/number.decorator.js.map +1 -0
- package/dist/decorator/api/property/object.decorator.d.ts +2 -0
- package/dist/decorator/api/property/object.decorator.js +124 -0
- package/dist/decorator/api/property/object.decorator.js.map +1 -0
- package/dist/decorator/api/property/string.decorator.d.ts +2 -0
- package/dist/decorator/api/property/string.decorator.js +282 -0
- package/dist/decorator/api/property/string.decorator.js.map +1 -0
- package/dist/decorator/api/property/uuid.decorator.d.ts +2 -0
- package/dist/decorator/api/property/uuid.decorator.js +63 -0
- package/dist/decorator/api/property/uuid.decorator.js.map +1 -0
- package/dist/decorator/api/property/wallet.decorator.d.ts +2 -0
- package/dist/decorator/api/property/wallet.decorator.js +25 -0
- package/dist/decorator/api/property/wallet.decorator.js.map +1 -0
- package/dist/decorator/api/service.decorator.d.ts +8 -0
- package/dist/decorator/api/service.decorator.js +71 -0
- package/dist/decorator/api/service.decorator.js.map +1 -0
- package/dist/decorator/index.d.ts +1 -0
- package/dist/decorator/index.js +18 -0
- package/dist/decorator/index.js.map +1 -0
- package/dist/dto/exception/bad-request.dto.d.ts +8 -0
- package/dist/dto/exception/bad-request.dto.js +84 -0
- package/dist/dto/exception/bad-request.dto.js.map +1 -0
- package/dist/dto/exception/conflict.dto.d.ts +8 -0
- package/dist/dto/exception/conflict.dto.js +84 -0
- package/dist/dto/exception/conflict.dto.js.map +1 -0
- package/dist/dto/exception/forbidden.dto.d.ts +8 -0
- package/dist/dto/exception/forbidden.dto.js +84 -0
- package/dist/dto/exception/forbidden.dto.js.map +1 -0
- package/dist/dto/exception/index.d.ts +7 -0
- package/dist/dto/exception/index.js +24 -0
- package/dist/dto/exception/index.js.map +1 -0
- package/dist/dto/exception/internal-server-error.dto.d.ts +8 -0
- package/dist/dto/exception/internal-server-error.dto.js +84 -0
- package/dist/dto/exception/internal-server-error.dto.js.map +1 -0
- package/dist/dto/exception/not-found.dto.d.ts +8 -0
- package/dist/dto/exception/not-found.dto.js +84 -0
- package/dist/dto/exception/not-found.dto.js.map +1 -0
- package/dist/dto/exception/too-many-requests.dto.d.ts +8 -0
- package/dist/dto/exception/too-many-requests.dto.js +84 -0
- package/dist/dto/exception/too-many-requests.dto.js.map +1 -0
- package/dist/dto/exception/unauthorized.dto.d.ts +8 -0
- package/dist/dto/exception/unauthorized.dto.js +84 -0
- package/dist/dto/exception/unauthorized.dto.js.map +1 -0
- package/dist/dto/index.d.ts +1 -0
- package/dist/dto/index.js +18 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/enum/decorator/api/action.enum.d.ts +14 -0
- package/dist/enum/decorator/api/action.enum.js +19 -0
- package/dist/enum/decorator/api/action.enum.js.map +1 -0
- package/dist/enum/decorator/api/authentication-type.enum.d.ts +5 -0
- package/dist/enum/decorator/api/authentication-type.enum.js +10 -0
- package/dist/enum/decorator/api/authentication-type.enum.js.map +1 -0
- package/dist/enum/decorator/api/function/index.d.ts +1 -0
- package/dist/enum/decorator/api/function/index.js +18 -0
- package/dist/enum/decorator/api/function/index.js.map +1 -0
- package/dist/enum/decorator/api/function/type.enum.d.ts +10 -0
- package/dist/enum/decorator/api/function/type.enum.js +15 -0
- package/dist/enum/decorator/api/function/type.enum.js.map +1 -0
- package/dist/enum/decorator/api/index.d.ts +4 -0
- package/dist/enum/decorator/api/index.js +21 -0
- package/dist/enum/decorator/api/index.js.map +1 -0
- package/dist/enum/decorator/api/property/data-type.enum.d.ts +23 -0
- package/dist/enum/decorator/api/property/data-type.enum.js +42 -0
- package/dist/enum/decorator/api/property/data-type.enum.js.map +1 -0
- package/dist/enum/decorator/api/property/date-type.enum.d.ts +14 -0
- package/dist/enum/decorator/api/property/date-type.enum.js +19 -0
- package/dist/enum/decorator/api/property/date-type.enum.js.map +1 -0
- package/dist/enum/decorator/api/property/index.d.ts +2 -0
- package/dist/enum/decorator/api/property/index.js +19 -0
- package/dist/enum/decorator/api/property/index.js.map +1 -0
- package/dist/enum/decorator/index.d.ts +1 -0
- package/dist/enum/decorator/index.js +18 -0
- package/dist/enum/decorator/index.js.map +1 -0
- package/dist/enum/filter-order-direction.enum.d.ts +4 -0
- package/dist/enum/filter-order-direction.enum.js +9 -0
- package/dist/enum/filter-order-direction.enum.js.map +1 -0
- package/dist/enum/index.d.ts +3 -0
- package/dist/enum/index.js +20 -0
- package/dist/enum/index.js.map +1 -0
- package/dist/enum/utility/error-string-action.enum.d.ts +55 -0
- package/dist/enum/utility/error-string-action.enum.js +60 -0
- package/dist/enum/utility/error-string-action.enum.js.map +1 -0
- package/dist/enum/utility/index.d.ts +1 -0
- package/dist/enum/utility/index.js +18 -0
- package/dist/enum/utility/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptor/correlation-id-response-body.interceptor.d.ts +5 -0
- package/dist/interceptor/correlation-id-response-body.interceptor.js +90 -0
- package/dist/interceptor/correlation-id-response-body.interceptor.js.map +1 -0
- package/dist/interceptor/index.d.ts +1 -0
- package/dist/interceptor/index.js +18 -0
- package/dist/interceptor/index.js.map +1 -0
- package/dist/interface/api-base-entity.interface.d.ts +3 -0
- package/dist/interface/api-base-entity.interface.js +3 -0
- package/dist/interface/api-base-entity.interface.js.map +1 -0
- package/dist/interface/decorator/api/function/index.d.ts +1 -0
- package/dist/interface/decorator/api/function/index.js +3 -0
- package/dist/interface/decorator/api/function/index.js.map +1 -0
- package/dist/interface/decorator/api/get-list-response-result.interface.d.ts +7 -0
- package/dist/interface/decorator/api/get-list-response-result.interface.js +3 -0
- package/dist/interface/decorator/api/get-list-response-result.interface.js.map +1 -0
- package/dist/interface/decorator/api/index.d.ts +5 -0
- package/dist/interface/decorator/api/index.js +22 -0
- package/dist/interface/decorator/api/index.js.map +1 -0
- package/dist/interface/decorator/api/method/index.d.ts +2 -0
- package/dist/interface/decorator/api/method/index.js +19 -0
- package/dist/interface/decorator/api/method/index.js.map +1 -0
- package/dist/interface/decorator/api/method/properties.interface.d.ts +16 -0
- package/dist/interface/decorator/api/method/properties.interface.js +3 -0
- package/dist/interface/decorator/api/method/properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/method/throttler-properties.interface.d.ts +4 -0
- package/dist/interface/decorator/api/method/throttler-properties.interface.js +3 -0
- package/dist/interface/decorator/api/method/throttler-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/base-properties.interface.d.ts +13 -0
- package/dist/interface/decorator/api/property/base-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/base-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/date-properties.interface.d.ts +5 -0
- package/dist/interface/decorator/api/property/date-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/date-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/index.d.ts +6 -0
- package/dist/interface/decorator/api/property/index.js +23 -0
- package/dist/interface/decorator/api/property/index.js.map +1 -0
- package/dist/interface/decorator/api/property/number-properties.interface.d.ts +9 -0
- package/dist/interface/decorator/api/property/number-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/number-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/object-properties.interface.d.ts +10 -0
- package/dist/interface/decorator/api/property/object-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/object-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/string-properties.interface.d.ts +10 -0
- package/dist/interface/decorator/api/property/string-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/string-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/property/uuid-properties.interface.d.ts +8 -0
- package/dist/interface/decorator/api/property/uuid-properties.interface.js +3 -0
- package/dist/interface/decorator/api/property/uuid-properties.interface.js.map +1 -0
- package/dist/interface/decorator/api/response-type.interface.d.ts +9 -0
- package/dist/interface/decorator/api/response-type.interface.js +3 -0
- package/dist/interface/decorator/api/response-type.interface.js.map +1 -0
- package/dist/interface/decorator/index.d.ts +1 -0
- package/dist/interface/decorator/index.js +18 -0
- package/dist/interface/decorator/index.js.map +1 -0
- package/dist/interface/index.d.ts +4 -0
- package/dist/interface/index.js +21 -0
- package/dist/interface/index.js.map +1 -0
- package/dist/interface/service.interface.d.ts +1 -0
- package/dist/interface/service.interface.js +3 -0
- package/dist/interface/service.interface.js.map +1 -0
- package/dist/interface/utility/error-string-properties.interface.d.ts +5 -0
- package/dist/interface/utility/error-string-properties.interface.js +3 -0
- package/dist/interface/utility/error-string-properties.interface.js.map +1 -0
- package/dist/interface/utility/index.d.ts +1 -0
- package/dist/interface/utility/index.js +18 -0
- package/dist/interface/utility/index.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type/api/filter/allowed-types.type.d.ts +1 -0
- package/dist/type/api/filter/allowed-types.type.js +3 -0
- package/dist/type/api/filter/allowed-types.type.js.map +1 -0
- package/dist/type/api/filter/extracted-allowed-types.type.d.ts +2 -0
- package/dist/type/api/filter/extracted-allowed-types.type.js +3 -0
- package/dist/type/api/filter/extracted-allowed-types.type.js.map +1 -0
- package/dist/type/api/filter/field-selector.type.d.ts +3 -0
- package/dist/type/api/filter/field-selector.type.js +3 -0
- package/dist/type/api/filter/field-selector.type.js.map +1 -0
- package/dist/type/api/filter/index.d.ts +4 -0
- package/dist/type/api/filter/index.js +21 -0
- package/dist/type/api/filter/index.js.map +1 -0
- package/dist/type/api/filter/order-by.type.d.ts +5 -0
- package/dist/type/api/filter/order-by.type.js +3 -0
- package/dist/type/api/filter/order-by.type.js.map +1 -0
- package/dist/type/api/function/get-list-properties.type.d.ts +23 -0
- package/dist/type/api/function/get-list-properties.type.js +3 -0
- package/dist/type/api/function/get-list-properties.type.js.map +1 -0
- package/dist/type/api/function/get-properties.type.d.ts +6 -0
- package/dist/type/api/function/get-properties.type.js +3 -0
- package/dist/type/api/function/get-properties.type.js.map +1 -0
- package/dist/type/api/function/index.d.ts +1 -0
- package/dist/type/api/function/index.js +18 -0
- package/dist/type/api/function/index.js.map +1 -0
- package/dist/type/api/index.d.ts +2 -0
- package/dist/type/api/index.js +19 -0
- package/dist/type/api/index.js.map +1 -0
- package/dist/type/index.d.ts +1 -0
- package/dist/type/index.js +18 -0
- package/dist/type/index.js.map +1 -0
- package/dist/utility/api/filter-order-by-from-entity.utility.d.ts +4 -0
- package/dist/utility/api/filter-order-by-from-entity.utility.js +34 -0
- package/dist/utility/api/filter-order-by-from-entity.utility.js.map +1 -0
- package/dist/utility/api/index.d.ts +1 -0
- package/dist/utility/api/index.js +18 -0
- package/dist/utility/api/index.js.map +1 -0
- package/dist/utility/create-rest-application.utility.d.ts +3 -0
- package/dist/utility/create-rest-application.utility.js +9 -0
- package/dist/utility/create-rest-application.utility.js.map +1 -0
- package/dist/utility/error-string.utility.d.ts +2 -0
- package/dist/utility/error-string.utility.js +7 -0
- package/dist/utility/error-string.utility.js.map +1 -0
- package/dist/utility/index.d.ts +3 -0
- package/dist/utility/index.js +20 -0
- package/dist/utility/index.js.map +1 -0
- package/dist/validator/index.d.ts +1 -0
- package/dist/validator/index.js +18 -0
- package/dist/validator/index.js.map +1 -0
- package/dist/validator/is-regular-expression.validator.d.ts +4 -0
- package/dist/validator/is-regular-expression.validator.js +31 -0
- package/dist/validator/is-regular-expression.validator.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiPropertyString = ApiPropertyString;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const class_validator_1 = require("class-validator");
|
|
8
|
+
const constant_1 = require("../../../constant");
|
|
9
|
+
const enum_1 = require("../../../enum");
|
|
10
|
+
const validator_1 = require("../../../validator");
|
|
11
|
+
function ApiPropertyString(properties) {
|
|
12
|
+
if (properties.enum) {
|
|
13
|
+
properties = { ...properties, ...buildOptionsFromEnum(properties) };
|
|
14
|
+
}
|
|
15
|
+
validateOptions(properties);
|
|
16
|
+
const apiPropertyOptions = buildApiPropertyOptions(properties);
|
|
17
|
+
const decorators = buildDecorators(properties, apiPropertyOptions);
|
|
18
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
19
|
+
}
|
|
20
|
+
function buildOptionsFromEnum(properties) {
|
|
21
|
+
const minLength = Number.POSITIVE_INFINITY;
|
|
22
|
+
const maxLength = 0;
|
|
23
|
+
const returnProperties = { ...properties, maxLength, minLength };
|
|
24
|
+
if (properties.enum && returnProperties.minLength !== undefined && returnProperties.maxLength !== undefined) {
|
|
25
|
+
const enumValues = Object.values(properties.enum);
|
|
26
|
+
for (const value of enumValues) {
|
|
27
|
+
const length = value.length;
|
|
28
|
+
returnProperties.minLength = Math.min(returnProperties.minLength, length);
|
|
29
|
+
returnProperties.maxLength = Math.max(returnProperties.maxLength, length);
|
|
30
|
+
}
|
|
31
|
+
returnProperties.example = enumValues[0];
|
|
32
|
+
returnProperties.pattern = `/^(${enumValues.join("|")})$/`;
|
|
33
|
+
}
|
|
34
|
+
return returnProperties;
|
|
35
|
+
}
|
|
36
|
+
function validateOptions(properties) {
|
|
37
|
+
const errors = [];
|
|
38
|
+
if (!properties.response && typeof properties.required !== "boolean") {
|
|
39
|
+
errors.push("Required is not defined");
|
|
40
|
+
}
|
|
41
|
+
if (properties.response && properties.required) {
|
|
42
|
+
errors.push("Required is defined for response");
|
|
43
|
+
}
|
|
44
|
+
if ((!properties.response && (!properties.example || !properties.pattern)) || (properties.example && properties.pattern)) {
|
|
45
|
+
const matches = properties.pattern.match(/^\/(.*?)\/([gimuy]*)$/);
|
|
46
|
+
if (matches) {
|
|
47
|
+
const pattern = matches[constant_1.API_PROPERTY_STRING_INTERFACE_CONSTANT.REGEX_PATTERN_INDEX];
|
|
48
|
+
const flags = matches[constant_1.API_PROPERTY_STRING_INTERFACE_CONSTANT.REGEX_FLAGS_INDEX];
|
|
49
|
+
const regex = new RegExp(pattern, flags);
|
|
50
|
+
if (Array.isArray(properties.example)) {
|
|
51
|
+
for (const example of properties.example) {
|
|
52
|
+
if (!regex.test(example)) {
|
|
53
|
+
errors.push("RegExp pattern does not match example string: " + example);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (!regex.test(properties.example)) {
|
|
58
|
+
errors.push("RegExp pattern does not match example string: " + properties.example);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
errors.push("Invalid RegExp format: " + properties.pattern);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!enum_1.EApiPropertyDataTypeString.has(properties.type)) {
|
|
66
|
+
errors.push("Type is not valid for string property: " + properties.type);
|
|
67
|
+
}
|
|
68
|
+
if (properties.minLength !== undefined && properties.maxLength !== undefined && properties.minLength > properties.maxLength) {
|
|
69
|
+
errors.push("Min length is greater than max length");
|
|
70
|
+
}
|
|
71
|
+
if (properties.minLength !== undefined && properties.minLength < 0) {
|
|
72
|
+
errors.push("Min length is less than 0");
|
|
73
|
+
}
|
|
74
|
+
if (properties.maxLength !== undefined && properties.maxLength < 0) {
|
|
75
|
+
errors.push("Max length is less than 0");
|
|
76
|
+
}
|
|
77
|
+
if (properties.example && properties.minLength && properties.example.length < properties.minLength && !Array.isArray(properties.example)) {
|
|
78
|
+
errors.push("Example length is less than min length");
|
|
79
|
+
}
|
|
80
|
+
else if (properties.example && properties.minLength && Array.isArray(properties.example)) {
|
|
81
|
+
for (const example of properties.example) {
|
|
82
|
+
if (example.length < properties.minLength) {
|
|
83
|
+
errors.push("Example length is less than min length");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (properties.example && properties.maxLength && properties.example.length > properties.maxLength && !Array.isArray(properties.example)) {
|
|
88
|
+
errors.push("Example length is greater than max length");
|
|
89
|
+
}
|
|
90
|
+
else if (properties.example && properties.maxLength && Array.isArray(properties.example)) {
|
|
91
|
+
for (const example of properties.example) {
|
|
92
|
+
if (example.length > properties.maxLength) {
|
|
93
|
+
errors.push("Example length is greater than max length");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (properties.isArray) {
|
|
98
|
+
if (properties.minItems !== undefined && properties.maxItems !== undefined && properties.minItems > properties.maxItems) {
|
|
99
|
+
errors.push("Min items is greater than max items");
|
|
100
|
+
}
|
|
101
|
+
if (properties.minItems !== undefined && properties.minItems < 0) {
|
|
102
|
+
errors.push("Min items is less than 0");
|
|
103
|
+
}
|
|
104
|
+
if (properties.maxItems !== undefined && properties.maxItems < 0) {
|
|
105
|
+
errors.push("Max items is less than 0");
|
|
106
|
+
}
|
|
107
|
+
if (properties.uniqueItems === undefined) {
|
|
108
|
+
errors.push("Unique items is not defined");
|
|
109
|
+
}
|
|
110
|
+
if (properties.uniqueItems && properties.maxItems !== undefined && properties.maxItems <= 1) {
|
|
111
|
+
errors.push("Unique items is true but max items is less than or equal to 1");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (errors.length > 0) {
|
|
115
|
+
throw new Error(`ApiPropertyString error: ${errors.join("\n")}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function buildApiPropertyOptions(properties) {
|
|
119
|
+
const apiPropertyOptions = {
|
|
120
|
+
description: `${properties.entity.name} ${properties.description || ""}`,
|
|
121
|
+
example: properties.example,
|
|
122
|
+
format: properties.format,
|
|
123
|
+
maxLength: properties.maxLength,
|
|
124
|
+
minLength: properties.minLength,
|
|
125
|
+
nullable: properties.nullable,
|
|
126
|
+
pattern: properties.pattern.slice(1, -1),
|
|
127
|
+
required: !properties.response && properties.required,
|
|
128
|
+
type: enum_1.EApiPropertyDataType.STRING,
|
|
129
|
+
};
|
|
130
|
+
if (properties.enum) {
|
|
131
|
+
apiPropertyOptions.enum = properties.enum;
|
|
132
|
+
}
|
|
133
|
+
if (properties.isArray) {
|
|
134
|
+
apiPropertyOptions.isArray = true;
|
|
135
|
+
apiPropertyOptions.minItems = properties.minItems;
|
|
136
|
+
apiPropertyOptions.maxItems = properties.maxItems;
|
|
137
|
+
apiPropertyOptions.uniqueItems = properties.uniqueItems;
|
|
138
|
+
}
|
|
139
|
+
if (properties.isArray && properties.enum) {
|
|
140
|
+
delete apiPropertyOptions.type;
|
|
141
|
+
}
|
|
142
|
+
else if (properties.isArray) {
|
|
143
|
+
apiPropertyOptions.type = [enum_1.EApiPropertyDataType.STRING];
|
|
144
|
+
}
|
|
145
|
+
return apiPropertyOptions;
|
|
146
|
+
}
|
|
147
|
+
function buildDecorators(properties, apiPropertyOptions) {
|
|
148
|
+
const decorators = [(0, swagger_1.ApiProperty)(apiPropertyOptions)];
|
|
149
|
+
if (properties.response) {
|
|
150
|
+
decorators.push(swagger_1.ApiResponseProperty);
|
|
151
|
+
if (properties.expose) {
|
|
152
|
+
decorators.push((0, class_transformer_1.Expose)());
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (properties.isArray) {
|
|
156
|
+
if (!properties.required) {
|
|
157
|
+
decorators.push((0, class_validator_1.IsOptional)());
|
|
158
|
+
}
|
|
159
|
+
decorators.push((0, class_validator_1.IsArray)(), (0, class_validator_1.ArrayNotEmpty)());
|
|
160
|
+
if (properties.minItems) {
|
|
161
|
+
decorators.push((0, class_validator_1.ArrayMinSize)(properties.minItems));
|
|
162
|
+
}
|
|
163
|
+
if (properties.maxItems) {
|
|
164
|
+
decorators.push((0, class_validator_1.ArrayMaxSize)(properties.maxItems));
|
|
165
|
+
}
|
|
166
|
+
if (properties.enum) {
|
|
167
|
+
decorators.push((0, class_validator_1.IsEnum)(properties.enum, { each: true }));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
switch (properties.type) {
|
|
171
|
+
case enum_1.EApiPropertyDataType.URL: {
|
|
172
|
+
decorators.push((0, class_validator_1.IsUrl)({
|
|
173
|
+
protocols: ["https", "http"],
|
|
174
|
+
require_host: true,
|
|
175
|
+
require_protocol: true,
|
|
176
|
+
}, { each: true }));
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case enum_1.EApiPropertyDataType.UUID: {
|
|
180
|
+
decorators.push((0, class_validator_1.IsUUID)("all", { each: true }));
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case enum_1.EApiPropertyDataType.EMAIL: {
|
|
184
|
+
decorators.push((0, class_validator_1.IsEmail)({}, { each: true }));
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case enum_1.EApiPropertyDataType.STRING: {
|
|
188
|
+
decorators.push((0, class_validator_1.IsString)({ each: true }));
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case enum_1.EApiPropertyDataType.UPPERCASE_STRING: {
|
|
192
|
+
decorators.push((0, class_validator_1.IsString)({ each: true }), (0, class_validator_1.IsUppercase)({ each: true }));
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case enum_1.EApiPropertyDataType.LOWERCASE_STRING: {
|
|
196
|
+
decorators.push((0, class_validator_1.IsString)({ each: true }), (0, class_validator_1.IsLowercase)({ each: true }));
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case enum_1.EApiPropertyDataType.REGEXP: {
|
|
200
|
+
decorators.push((0, class_validator_1.Validate)(validator_1.IsRegularExpression, {
|
|
201
|
+
each: true,
|
|
202
|
+
message: `${properties.description} must be valid regular expression string`,
|
|
203
|
+
}), (0, class_validator_1.Matches)(new RegExp(properties.pattern.slice(1, -1))), (0, class_transformer_1.Type)(() => RegExp));
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case enum_1.EApiPropertyDataType.IP: {
|
|
207
|
+
decorators.push((0, class_validator_1.IsIP)(constant_1.API_PROPERTY_STRING_INTERFACE_CONSTANT.IP_VERSION, { each: true }));
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
default: {
|
|
211
|
+
throw new Error("ApiPropertyString error: Type is not valid for string property: " + properties.type);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (properties.pattern) {
|
|
216
|
+
decorators.push((0, class_validator_1.Matches)(new RegExp(properties.pattern.slice(1, -1)), { each: true }));
|
|
217
|
+
}
|
|
218
|
+
if (properties.minLength && properties.maxItems) {
|
|
219
|
+
decorators.push((0, class_validator_1.Length)(properties.minLength, properties.maxLength, { each: true }));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
if (!properties.required) {
|
|
224
|
+
decorators.push((0, class_validator_1.IsOptional)());
|
|
225
|
+
}
|
|
226
|
+
if (properties.enum) {
|
|
227
|
+
decorators.push((0, class_validator_1.IsEnum)(properties.enum));
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
switch (properties.type) {
|
|
231
|
+
case enum_1.EApiPropertyDataType.URL: {
|
|
232
|
+
decorators.push((0, class_validator_1.IsUrl)({ protocols: ["https", "http"], require_host: true, require_protocol: true }));
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case enum_1.EApiPropertyDataType.UUID: {
|
|
236
|
+
decorators.push((0, class_validator_1.IsUUID)());
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case enum_1.EApiPropertyDataType.EMAIL: {
|
|
240
|
+
decorators.push((0, class_validator_1.IsEmail)());
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case enum_1.EApiPropertyDataType.STRING: {
|
|
244
|
+
decorators.push((0, class_validator_1.IsString)());
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case enum_1.EApiPropertyDataType.UPPERCASE_STRING: {
|
|
248
|
+
decorators.push((0, class_validator_1.IsString)(), (0, class_validator_1.IsUppercase)());
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case enum_1.EApiPropertyDataType.LOWERCASE_STRING: {
|
|
252
|
+
decorators.push((0, class_validator_1.IsString)(), (0, class_validator_1.IsLowercase)());
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case enum_1.EApiPropertyDataType.REGEXP: {
|
|
256
|
+
decorators.push((0, class_validator_1.Validate)(validator_1.IsRegularExpression, { message: `${properties.description} must be valid regular expression string` }), (0, class_validator_1.Matches)(new RegExp(properties.pattern.slice(1, -1))), (0, class_transformer_1.Type)(() => RegExp));
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case enum_1.EApiPropertyDataType.IP: {
|
|
260
|
+
decorators.push((0, class_validator_1.IsIP)(constant_1.API_PROPERTY_STRING_INTERFACE_CONSTANT.IP_VERSION));
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case enum_1.EApiPropertyDataType.DATE_TIME:
|
|
264
|
+
case enum_1.EApiPropertyDataType.DATE: {
|
|
265
|
+
decorators.push((0, class_validator_1.IsDate)(), (0, class_transformer_1.Type)(() => Date));
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
default: {
|
|
269
|
+
throw new Error("ApiPropertyString error: Type is not valid for string property: " + properties.type);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (properties.pattern && properties.type !== enum_1.EApiPropertyDataType.DATE_TIME && properties.type !== enum_1.EApiPropertyDataType.DATE) {
|
|
274
|
+
decorators.push((0, class_validator_1.Matches)(new RegExp(properties.pattern.slice(1, -1))));
|
|
275
|
+
}
|
|
276
|
+
if (properties.minLength && properties.maxItems) {
|
|
277
|
+
decorators.push((0, class_validator_1.Length)(properties.minLength, properties.maxLength));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return decorators;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=string.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.decorator.js","sourceRoot":"/","sources":["decorator/api/property/string.decorator.ts"],"names":[],"mappings":";;AAcA,8CAUC;AAxBD,2CAAiD;AAEjD,6CAAmE;AAEnE,yDAAiD;AAEjD,q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C,CAClB,CAAC;oBAEF,MAAM;gBACP,CAAC;gBAED,KAAK,2BAAoB,CAAC,EAAE,CAAC,CAAC,CAAC;oBAC9B,UAAU,CAAC,IAAI,CAAC,IAAA,sBAAI,EAAC,iDAAsC,CAAC,UAAU,CAAC,CAAC,CAAC;oBAEzE,MAAM;gBACP,CAAC;gBAED,KAAK,2BAAoB,CAAC,SAAS,CAAC;gBAEpC,KAAK,2BAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;oBAChC,UAAU,CAAC,IAAI,CACd,IAAA,wBAAM,GAAE,EACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAChB,CAAC;oBAEF,MAAM;gBACP,CAAC;gBAED,OAAO,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,KAAK,CAAC,kEAAkE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;gBACvG,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,UAAU,CAAC,OAAO,IAAI,UAAU,CAAC,IAAI,KAAK,2BAAoB,CAAC,SAAS,IAAI,UAAU,CAAC,IAAI,KAAK,2BAAoB,CAAC,IAAI,EAAE,CAAC;YAC/H,UAAU,CAAC,IAAI,CAAC,IAAA,yBAAO,EAAC,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,UAAU,CAAC,SAAS,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACjD,UAAU,CAAC,IAAI,CAAC,IAAA,wBAAM,EAAC,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;QACrE,CAAC;IACF,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\n\nimport { ApiProperty, ApiResponseProperty } from \"@nestjs/swagger\";\n\nimport { Expose, Type } from \"class-transformer\";\n\nimport { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, IsArray, IsDate, IsEmail, IsEnum, IsIP, IsLowercase, IsOptional, IsString, IsUppercase, IsUrl, IsUUID, Length, Matches, Validate } from \"class-validator\";\n\nimport type { ApiPropertyOptions } from \"@nestjs/swagger\";\nimport type { IApiBaseEntity, IApiPropertyStringProperties } from \"../../../interface\";\nimport { API_PROPERTY_STRING_INTERFACE_CONSTANT } from \"../../../constant\";\nimport { EApiPropertyDataType, EApiPropertyDataTypeString } from \"../../../enum\";\nimport { IsRegularExpression } from \"../../../validator\";\n\nexport function ApiPropertyString<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tif (properties.enum) {\n\t\tproperties = { ...properties, ...buildOptionsFromEnum(properties) };\n\t}\n\tvalidateOptions<T>(properties);\n\n\tconst apiPropertyOptions: ApiPropertyOptions = buildApiPropertyOptions<T>(properties);\n\tconst decorators: Array<PropertyDecorator> = buildDecorators<T>(properties, apiPropertyOptions);\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction buildOptionsFromEnum<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>): IApiPropertyStringProperties<T> {\n\tconst minLength: number = Number.POSITIVE_INFINITY;\n\tconst maxLength: number = 0;\n\tconst returnProperties: IApiPropertyStringProperties<T> = { ...properties, maxLength, minLength };\n\n\tif (properties.enum && returnProperties.minLength !== undefined && returnProperties.maxLength !== undefined) {\n\t\tconst enumValues: Array<string> = Object.values(properties.enum) as Array<string>;\n\n\t\tfor (const value of enumValues) {\n\t\t\tconst length: number = value.length;\n\t\t\treturnProperties.minLength = Math.min(returnProperties.minLength, length);\n\t\t\treturnProperties.maxLength = Math.max(returnProperties.maxLength, length);\n\t\t}\n\n\t\treturnProperties.example = enumValues[0];\n\t\treturnProperties.pattern = `/^(${enumValues.join(\"|\")})$/`;\n\t}\n\n\treturn returnProperties;\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>): void {\n\tconst errors: Array<string> = [];\n\n\tif (!properties.response && typeof properties.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (properties.response && properties.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif ((!properties.response && (!properties.example || !properties.pattern)) || (properties.example && properties.pattern)) {\n\t\tconst matches: null | RegExpMatchArray = properties.pattern.match(/^\\/(.*?)\\/([gimuy]*)$/);\n\n\t\tif (matches) {\n\t\t\tconst pattern: string = matches[API_PROPERTY_STRING_INTERFACE_CONSTANT.REGEX_PATTERN_INDEX];\n\t\t\tconst flags: string = matches[API_PROPERTY_STRING_INTERFACE_CONSTANT.REGEX_FLAGS_INDEX];\n\n\t\t\tconst regex: RegExp = new RegExp(pattern, flags);\n\n\t\t\tif (Array.isArray(properties.example)) {\n\t\t\t\tfor (const example of properties.example) {\n\t\t\t\t\tif (!regex.test(example)) {\n\t\t\t\t\t\terrors.push(\"RegExp pattern does not match example string: \" + example);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (!regex.test(properties.example)) {\n\t\t\t\terrors.push(\"RegExp pattern does not match example string: \" + properties.example);\n\t\t\t}\n\t\t} else {\n\t\t\terrors.push(\"Invalid RegExp format: \" + properties.pattern);\n\t\t}\n\t}\n\n\tif (!EApiPropertyDataTypeString.has(properties.type)) {\n\t\terrors.push(\"Type is not valid for string property: \" + properties.type);\n\t}\n\n\tif (properties.minLength !== undefined && properties.maxLength !== undefined && properties.minLength > properties.maxLength) {\n\t\terrors.push(\"Min length is greater than max length\");\n\t}\n\n\tif (properties.minLength !== undefined && properties.minLength < 0) {\n\t\terrors.push(\"Min length is less than 0\");\n\t}\n\n\tif (properties.maxLength !== undefined && properties.maxLength < 0) {\n\t\terrors.push(\"Max length is less than 0\");\n\t}\n\n\tif (properties.example && properties.minLength && properties.example.length < properties.minLength && !Array.isArray(properties.example)) {\n\t\terrors.push(\"Example length is less than min length\");\n\t} else if (properties.example && properties.minLength && Array.isArray(properties.example)) {\n\t\tfor (const example of properties.example) {\n\t\t\tif (example.length < properties.minLength) {\n\t\t\t\terrors.push(\"Example length is less than min length\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (properties.example && properties.maxLength && properties.example.length > properties.maxLength && !Array.isArray(properties.example)) {\n\t\terrors.push(\"Example length is greater than max length\");\n\t} else if (properties.example && properties.maxLength && Array.isArray(properties.example)) {\n\t\tfor (const example of properties.example) {\n\t\t\tif (example.length > properties.maxLength) {\n\t\t\t\terrors.push(\"Example length is greater than max length\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (properties.isArray) {\n\t\tif (properties.minItems !== undefined && properties.maxItems !== undefined && properties.minItems > properties.maxItems) {\n\t\t\terrors.push(\"Min items is greater than max items\");\n\t\t}\n\n\t\tif (properties.minItems !== undefined && properties.minItems < 0) {\n\t\t\terrors.push(\"Min items is less than 0\");\n\t\t}\n\n\t\tif (properties.maxItems !== undefined && properties.maxItems < 0) {\n\t\t\terrors.push(\"Max items is less than 0\");\n\t\t}\n\n\t\tif (properties.uniqueItems === undefined) {\n\t\t\terrors.push(\"Unique items is not defined\");\n\t\t}\n\n\t\tif (properties.uniqueItems && properties.maxItems !== undefined && properties.maxItems <= 1) {\n\t\t\terrors.push(\"Unique items is true but max items is less than or equal to 1\");\n\t\t}\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`ApiPropertyString error: ${errors.join(\"\\n\")}`);\n\t}\n}\n\nfunction buildApiPropertyOptions<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>): ApiPropertyOptions {\n\tconst apiPropertyOptions: ApiPropertyOptions = {\n\t\tdescription: `${properties.entity.name} ${properties.description || \"\"}`,\n\t\texample: properties.example,\n\t\tformat: properties.format,\n\t\tmaxLength: properties.maxLength,\n\t\tminLength: properties.minLength,\n\t\tnullable: properties.nullable,\n\t\tpattern: properties.pattern.slice(1, -1),\n\t\trequired: !properties.response && properties.required,\n\t\ttype: EApiPropertyDataType.STRING,\n\t};\n\n\tif (properties.enum) {\n\t\tapiPropertyOptions.enum = properties.enum;\n\t}\n\n\tif (properties.isArray) {\n\t\tapiPropertyOptions.isArray = true;\n\t\tapiPropertyOptions.minItems = properties.minItems;\n\t\tapiPropertyOptions.maxItems = properties.maxItems;\n\t\tapiPropertyOptions.uniqueItems = properties.uniqueItems;\n\t}\n\n\tif (properties.isArray && properties.enum) {\n\t\tdelete apiPropertyOptions.type;\n\t} else if (properties.isArray) {\n\t\tapiPropertyOptions.type = [EApiPropertyDataType.STRING];\n\t}\n\n\treturn apiPropertyOptions;\n}\n\nfunction buildDecorators<T extends IApiBaseEntity>(properties: IApiPropertyStringProperties<T>, apiPropertyOptions: ApiPropertyOptions): Array<PropertyDecorator> {\n\tconst decorators: Array<PropertyDecorator> = [ApiProperty(apiPropertyOptions)];\n\n\tif (properties.response) {\n\t\tdecorators.push(ApiResponseProperty);\n\n\t\tif (properties.expose) {\n\t\t\tdecorators.push(Expose());\n\t\t}\n\t} else if (properties.isArray) {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tdecorators.push(IsArray(), ArrayNotEmpty());\n\n\t\tif (properties.minItems) {\n\t\t\tdecorators.push(ArrayMinSize(properties.minItems));\n\t\t}\n\n\t\tif (properties.maxItems) {\n\t\t\tdecorators.push(ArrayMaxSize(properties.maxItems));\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum, { each: true }));\n\t\t} else {\n\t\t\tswitch (properties.type) {\n\t\t\t\tcase EApiPropertyDataType.URL: {\n\t\t\t\t\tdecorators.push(\n\t\t\t\t\t\tIsUrl(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tprotocols: [\"https\", \"http\"],\n\t\t\t\t\t\t\t\trequire_host: true,\n\t\t\t\t\t\t\t\trequire_protocol: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ each: true },\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.UUID: {\n\t\t\t\t\tdecorators.push(IsUUID(\"all\", { each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.EMAIL: {\n\t\t\t\t\tdecorators.push(IsEmail({}, { each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.STRING: {\n\t\t\t\t\tdecorators.push(IsString({ each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.UPPERCASE_STRING: {\n\t\t\t\t\tdecorators.push(IsString({ each: true }), IsUppercase({ each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.LOWERCASE_STRING: {\n\t\t\t\t\tdecorators.push(IsString({ each: true }), IsLowercase({ each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.REGEXP: {\n\t\t\t\t\tdecorators.push(\n\t\t\t\t\t\tValidate(IsRegularExpression, {\n\t\t\t\t\t\t\teach: true,\n\t\t\t\t\t\t\tmessage: `${properties.description} must be valid regular expression string`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tMatches(new RegExp(properties.pattern.slice(1, -1))),\n\t\t\t\t\t\tType(() => RegExp),\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.IP: {\n\t\t\t\t\tdecorators.push(IsIP(API_PROPERTY_STRING_INTERFACE_CONSTANT.IP_VERSION, { each: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"ApiPropertyString error: Type is not valid for string property: \" + properties.type);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (properties.pattern) {\n\t\t\tdecorators.push(Matches(new RegExp(properties.pattern.slice(1, -1)), { each: true }));\n\t\t}\n\n\t\tif (properties.minLength && properties.maxItems) {\n\t\t\tdecorators.push(Length(properties.minLength, properties.maxLength, { each: true }));\n\t\t}\n\t} else {\n\t\tif (!properties.required) {\n\t\t\tdecorators.push(IsOptional());\n\t\t}\n\n\t\tif (properties.enum) {\n\t\t\tdecorators.push(IsEnum(properties.enum));\n\t\t} else {\n\t\t\tswitch (properties.type) {\n\t\t\t\tcase EApiPropertyDataType.URL: {\n\t\t\t\t\tdecorators.push(IsUrl({ protocols: [\"https\", \"http\"], require_host: true, require_protocol: true }));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.UUID: {\n\t\t\t\t\tdecorators.push(IsUUID());\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.EMAIL: {\n\t\t\t\t\tdecorators.push(IsEmail());\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.STRING: {\n\t\t\t\t\tdecorators.push(IsString());\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.UPPERCASE_STRING: {\n\t\t\t\t\tdecorators.push(IsString(), IsUppercase());\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.LOWERCASE_STRING: {\n\t\t\t\t\tdecorators.push(IsString(), IsLowercase());\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.REGEXP: {\n\t\t\t\t\tdecorators.push(\n\t\t\t\t\t\tValidate(IsRegularExpression, { message: `${properties.description} must be valid regular expression string` }),\n\t\t\t\t\t\tMatches(new RegExp(properties.pattern.slice(1, -1))),\n\t\t\t\t\t\tType(() => RegExp),\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.IP: {\n\t\t\t\t\tdecorators.push(IsIP(API_PROPERTY_STRING_INTERFACE_CONSTANT.IP_VERSION));\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase EApiPropertyDataType.DATE_TIME:\n\n\t\t\t\tcase EApiPropertyDataType.DATE: {\n\t\t\t\t\tdecorators.push(\n\t\t\t\t\t\tIsDate(),\n\t\t\t\t\t\tType(() => Date),\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"ApiPropertyString error: Type is not valid for string property: \" + properties.type);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (properties.pattern && properties.type !== EApiPropertyDataType.DATE_TIME && properties.type !== EApiPropertyDataType.DATE) {\n\t\t\tdecorators.push(Matches(new RegExp(properties.pattern.slice(1, -1))));\n\t\t}\n\n\t\tif (properties.minLength && properties.maxItems) {\n\t\t\tdecorators.push(Length(properties.minLength, properties.maxLength));\n\t\t}\n\t}\n\n\treturn decorators;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { IApiBaseEntity, IApiPropertyUuidProperties } from "../../../interface";
|
|
2
|
+
export declare function ApiPropertyUUID<T extends IApiBaseEntity>(properties: IApiPropertyUuidProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiPropertyUUID = ApiPropertyUUID;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const class_transformer_1 = require("class-transformer");
|
|
8
|
+
const class_validator_1 = require("class-validator");
|
|
9
|
+
function ApiPropertyUUID(properties) {
|
|
10
|
+
const uuidExample = (0, node_crypto_1.randomUUID)();
|
|
11
|
+
validateOptions(uuidExample, properties);
|
|
12
|
+
const apiPropertyOptions = buildApiPropertyOptions(uuidExample, properties);
|
|
13
|
+
const decorators = buildDecorators(properties, apiPropertyOptions);
|
|
14
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
15
|
+
}
|
|
16
|
+
function validateOptions(uuidExample, properties) {
|
|
17
|
+
const errors = [];
|
|
18
|
+
const uuidRegex = /^[\dA-Fa-f]{8}-[\dA-Fa-f]{4}-[1-5][\dA-Fa-f]{3}-[89ABab][\dA-Fa-f]{3}-[\dA-Fa-f]{12}$/;
|
|
19
|
+
if (!properties.response && typeof properties.required !== "boolean") {
|
|
20
|
+
errors.push("Required is not defined");
|
|
21
|
+
}
|
|
22
|
+
if (properties.response && properties.required) {
|
|
23
|
+
errors.push("Required is defined for response");
|
|
24
|
+
}
|
|
25
|
+
if (!uuidRegex.test(uuidExample)) {
|
|
26
|
+
errors.push("Generated UUID does not match UUID pattern: " + uuidExample);
|
|
27
|
+
}
|
|
28
|
+
if (errors.length > 0) {
|
|
29
|
+
throw new Error(`ApiPropertyUUID error: ${errors.join("\n")}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function buildApiPropertyOptions(uuidExample, properties) {
|
|
33
|
+
return {
|
|
34
|
+
description: `${properties.entity.name} ${properties.description || "identifier"}`,
|
|
35
|
+
example: uuidExample,
|
|
36
|
+
format: "uuid",
|
|
37
|
+
maxLength: uuidExample.length,
|
|
38
|
+
minLength: uuidExample.length,
|
|
39
|
+
nullable: properties.nullable,
|
|
40
|
+
pattern: "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$",
|
|
41
|
+
required: !properties.response && properties.required,
|
|
42
|
+
type: "string",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function buildDecorators(options, apiPropertyOptions) {
|
|
46
|
+
const decorators = [(0, swagger_1.ApiProperty)(apiPropertyOptions)];
|
|
47
|
+
if (options.response) {
|
|
48
|
+
decorators.push(swagger_1.ApiResponseProperty);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (options.required) {
|
|
52
|
+
decorators.push((0, class_validator_1.IsUUID)());
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
decorators.push((0, class_validator_1.IsOptional)(), (0, class_validator_1.IsUUID)());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (options.response && options.expose) {
|
|
59
|
+
decorators.push((0, class_transformer_1.Expose)());
|
|
60
|
+
}
|
|
61
|
+
return decorators;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=uuid.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.decorator.js","sourceRoot":"/","sources":["decorator/api/property/uuid.decorator.ts"],"names":[],"mappings":";;AAaA,0CAQC;AArBD,6CAAyC;AAEzC,2CAAiD;AAEjD,6CAAmE;AAEnE,yDAA2C;AAE3C,qDAAqD;AAKrD,SAAgB,eAAe,CAA2B,UAAyC;IAClG,MAAM,WAAW,GAAW,IAAA,wBAAU,GAAE,CAAC;IACzC,eAAe,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAEzC,MAAM,kBAAkB,GAAuB,uBAAuB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAChG,MAAM,UAAU,GAA6B,eAAe,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IAE7F,OAAO,IAAA,wBAAe,EAAC,GAAG,UAAU,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,eAAe,CAA2B,WAAmB,EAAE,UAAyC;IAChH,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,MAAM,SAAS,GAAW,uFAAuF,CAAC;IAElH,IAAI,CA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AC,6BAAmB,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACP,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,UAAU,CAAC,IAAI,CAAC,IAAA,wBAAM,GAAE,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACP,UAAU,CAAC,IAAI,CAAC,IAAA,4BAAU,GAAE,EAAE,IAAA,wBAAM,GAAE,CAAC,CAAC;QACzC,CAAC;IACF,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACxC,UAAU,CAAC,IAAI,CAAC,IAAA,0BAAM,GAAE,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport { applyDecorators } from \"@nestjs/common\";\n\nimport { ApiProperty, ApiResponseProperty } from \"@nestjs/swagger\";\n\nimport { Expose } from \"class-transformer\";\n\nimport { IsOptional, IsUUID } from \"class-validator\";\n\nimport type { ApiPropertyOptions } from \"@nestjs/swagger\";\nimport type { IApiBaseEntity, IApiPropertyUuidProperties } from \"../../../interface\";\n\nexport function ApiPropertyUUID<T extends IApiBaseEntity>(properties: IApiPropertyUuidProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tconst uuidExample: string = randomUUID();\n\tvalidateOptions(uuidExample, properties);\n\n\tconst apiPropertyOptions: ApiPropertyOptions = buildApiPropertyOptions(uuidExample, properties);\n\tconst decorators: Array<PropertyDecorator> = buildDecorators(properties, apiPropertyOptions);\n\n\treturn applyDecorators(...decorators);\n}\n\nfunction validateOptions<T extends IApiBaseEntity>(uuidExample: string, properties: IApiPropertyUuidProperties<T>): void {\n\tconst errors: Array<string> = [];\n\tconst uuidRegex: RegExp = /^[\\dA-Fa-f]{8}-[\\dA-Fa-f]{4}-[1-5][\\dA-Fa-f]{3}-[89ABab][\\dA-Fa-f]{3}-[\\dA-Fa-f]{12}$/;\n\n\tif (!properties.response && typeof properties.required !== \"boolean\") {\n\t\terrors.push(\"Required is not defined\");\n\t}\n\n\tif (properties.response && properties.required) {\n\t\terrors.push(\"Required is defined for response\");\n\t}\n\n\tif (!uuidRegex.test(uuidExample)) {\n\t\terrors.push(\"Generated UUID does not match UUID pattern: \" + uuidExample);\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new Error(`ApiPropertyUUID error: ${errors.join(\"\\n\")}`);\n\t}\n}\n\nfunction buildApiPropertyOptions<T extends IApiBaseEntity>(uuidExample: string, properties: IApiPropertyUuidProperties<T>): ApiPropertyOptions {\n\treturn {\n\t\tdescription: `${properties.entity.name} ${properties.description || \"identifier\"}`,\n\t\texample: uuidExample,\n\t\tformat: \"uuid\",\n\t\tmaxLength: uuidExample.length,\n\t\tminLength: uuidExample.length,\n\t\tnullable: properties.nullable,\n\t\tpattern: \"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$\",\n\t\trequired: !properties.response && properties.required,\n\t\ttype: \"string\",\n\t};\n}\n\nfunction buildDecorators<T extends IApiBaseEntity>(options: IApiPropertyUuidProperties<T>, apiPropertyOptions: ApiPropertyOptions): Array<PropertyDecorator> {\n\tconst decorators: Array<PropertyDecorator> = [ApiProperty(apiPropertyOptions)];\n\n\tif (options.response) {\n\t\tdecorators.push(ApiResponseProperty);\n\t} else {\n\t\tif (options.required) {\n\t\t\tdecorators.push(IsUUID());\n\t\t} else {\n\t\t\tdecorators.push(IsOptional(), IsUUID());\n\t\t}\n\t}\n\n\tif (options.response && options.expose) {\n\t\tdecorators.push(Expose());\n\t}\n\n\treturn decorators;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { IApiBaseEntity, IApiPropertyBaseProperties } from "../../../interface";
|
|
2
|
+
export declare function ApiPropertyWallet<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiPropertyWallet = ApiPropertyWallet;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const constant_1 = require("../../../constant");
|
|
6
|
+
const enum_1 = require("../../../enum");
|
|
7
|
+
const number_decorator_1 = require("./number.decorator");
|
|
8
|
+
function ApiPropertyWallet(properties) {
|
|
9
|
+
const apiPropertyOptions = {
|
|
10
|
+
description: "wallet number",
|
|
11
|
+
entity: properties.entity,
|
|
12
|
+
example: constant_1.API_PROPERTY_WALLET_INTERFACE_CONSTANT.EXAMPLE,
|
|
13
|
+
expose: properties.expose,
|
|
14
|
+
maximum: constant_1.API_PROPERTY_WALLET_INTERFACE_CONSTANT.MAXIMUM,
|
|
15
|
+
minimum: constant_1.API_PROPERTY_WALLET_INTERFACE_CONSTANT.MINIMUM,
|
|
16
|
+
multipleOf: 1,
|
|
17
|
+
nullable: properties.nullable,
|
|
18
|
+
required: !properties.response && properties.required,
|
|
19
|
+
response: properties.response,
|
|
20
|
+
type: enum_1.EApiPropertyDataType.INTEGER,
|
|
21
|
+
};
|
|
22
|
+
const decorators = [(0, number_decorator_1.ApiPropertyNumber)({ ...apiPropertyOptions })];
|
|
23
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=wallet.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.decorator.js","sourceRoot":"/","sources":["decorator/api/property/wallet.decorator.ts"],"names":[],"mappings":";;AAMA,8CAkBC;AAxBD,2CAAiD;AACjD,gDAA2E;AAE3E,wCAAqD;AACrD,yDAAuD;AAEvD,SAAgB,iBAAiB,CAA2B,UAAyC;IACpG,MAAM,kBAAkB,GAAoC;QAC3D,WAAW,EAAE,eAAe;QAC5B,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,EAAE,iDAAsC,CAAC,OAAO;QACvD,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,OAAO,EAAE,iDAAsC,CAAC,OAAO;QACvD,OAAO,EAAE,iDAAsC,CAAC,OAAO;QACvD,UAAU,EAAE,CAAC;QACb,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,QAAQ,EAAE,CAAC,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ;QACrD,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,IAAI,EAAE,2BAAoB,CAAC,OAAO;KAClC,CAAC;IAEF,MAAM,UAAU,GAA6B,CAAC,IAAA,oCAAiB,EAAC,EAAE,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC;IAE5F,OAAO,IAAA,wBAAe,EAAC,GAAG,UAAU,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { applyDecorators } from \"@nestjs/common\";\nimport { API_PROPERTY_WALLET_INTERFACE_CONSTANT } from \"../../../constant\";\nimport type { IApiBaseEntity, IApiPropertyBaseProperties, IApiPropertyNumberProperties } from \"../../../interface\";\nimport { EApiPropertyDataType } from \"../../../enum\";\nimport { ApiPropertyNumber } from \"./number.decorator\";\n\nexport function ApiPropertyWallet<T extends IApiBaseEntity>(properties: IApiPropertyBaseProperties<T>): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void {\n\tconst apiPropertyOptions: IApiPropertyNumberProperties<T> = {\n\t\tdescription: \"wallet number\",\n\t\tentity: properties.entity,\n\t\texample: API_PROPERTY_WALLET_INTERFACE_CONSTANT.EXAMPLE,\n\t\texpose: properties.expose,\n\t\tmaximum: API_PROPERTY_WALLET_INTERFACE_CONSTANT.MAXIMUM,\n\t\tminimum: API_PROPERTY_WALLET_INTERFACE_CONSTANT.MINIMUM,\n\t\tmultipleOf: 1,\n\t\tnullable: properties.nullable,\n\t\trequired: !properties.response && properties.required,\n\t\tresponse: properties.response,\n\t\ttype: EApiPropertyDataType.INTEGER,\n\t};\n\n\tconst decorators: Array<PropertyDecorator> = [ApiPropertyNumber({ ...apiPropertyOptions })];\n\n\treturn applyDecorators(...decorators);\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { BaseEntity, EntityTarget, FindOptionsRelations } from "typeorm";
|
|
3
|
+
export declare function ApiService<E extends BaseEntity>(options: {
|
|
4
|
+
entity: EntityTarget<E>;
|
|
5
|
+
relations?: FindOptionsRelations<E>;
|
|
6
|
+
}): <TFunction extends {
|
|
7
|
+
new (...args: any[]): {};
|
|
8
|
+
}>(target: TFunction) => TFunction;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiService = ApiService;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const enum_1 = require("../../enum");
|
|
6
|
+
const function_1 = require("./function");
|
|
7
|
+
const API_SERVICE_METADATA_KEY = Symbol('ApiServiceMetadata');
|
|
8
|
+
function ApiService(options) {
|
|
9
|
+
return function (target) {
|
|
10
|
+
const originalConstructor = target;
|
|
11
|
+
const ExtendedClass = class extends originalConstructor {
|
|
12
|
+
constructor(...args) {
|
|
13
|
+
super(...args);
|
|
14
|
+
if (!this.hasOwnProperty(enum_1.EApiFunctionType.GET_LIST)) {
|
|
15
|
+
Object.defineProperty(this, enum_1.EApiFunctionType.GET_LIST, {
|
|
16
|
+
value: async function (properties) {
|
|
17
|
+
const apiFunctionDecorator = (0, function_1.ApiFunction)({
|
|
18
|
+
model: options.entity,
|
|
19
|
+
type: enum_1.EApiFunctionType.GET_LIST,
|
|
20
|
+
relations: options.relations
|
|
21
|
+
});
|
|
22
|
+
const descriptor = {
|
|
23
|
+
value: function () { },
|
|
24
|
+
writable: true,
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true
|
|
27
|
+
};
|
|
28
|
+
const decoratedDescriptor = apiFunctionDecorator(this, enum_1.EApiFunctionType.GET_LIST, descriptor);
|
|
29
|
+
return decoratedDescriptor.value.apply(this, [properties]);
|
|
30
|
+
},
|
|
31
|
+
writable: true,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!this.hasOwnProperty(enum_1.EApiFunctionType.GET)) {
|
|
37
|
+
Object.defineProperty(this, enum_1.EApiFunctionType.GET, {
|
|
38
|
+
value: async function (id, properties) {
|
|
39
|
+
const apiFunctionDecorator = (0, function_1.ApiFunction)({
|
|
40
|
+
model: options.entity,
|
|
41
|
+
type: enum_1.EApiFunctionType.GET,
|
|
42
|
+
relations: options.relations
|
|
43
|
+
});
|
|
44
|
+
const descriptor = {
|
|
45
|
+
value: function () { },
|
|
46
|
+
writable: true,
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true
|
|
49
|
+
};
|
|
50
|
+
const decoratedDescriptor = apiFunctionDecorator(this, enum_1.EApiFunctionType.GET, descriptor);
|
|
51
|
+
return decoratedDescriptor.value.apply(this, [id, properties]);
|
|
52
|
+
},
|
|
53
|
+
writable: true,
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
Reflect.defineMetadata(API_SERVICE_METADATA_KEY, {
|
|
61
|
+
entity: options.entity,
|
|
62
|
+
getListMetadata: {
|
|
63
|
+
model: options.entity,
|
|
64
|
+
type: enum_1.EApiFunctionType.GET_LIST,
|
|
65
|
+
}
|
|
66
|
+
}, ExtendedClass);
|
|
67
|
+
Object.setPrototypeOf(ExtendedClass, originalConstructor);
|
|
68
|
+
return ExtendedClass;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=service.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.decorator.js","sourceRoot":"/","sources":["decorator/api/service.decorator.ts"],"names":[],"mappings":";;AAUA,gCA4EC;AAtFD,4BAA0B;AAG1B,qCAA8C;AAC9C,yCAAyC;AAIzC,MAAM,wBAAwB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE9D,SAAgB,UAAU,CAAuB,OAAyE;IACzH,OAAO,UAA0D,MAAiB;QACjF,MAAM,mBAAmB,GAAG,MAAM,CAAC;QAEnC,MAAM,aAAa,GAAG,KAAM,SAAQ,mBAAmB;YACtD,YAAY,GAAG,IAAW;gBACzB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;gBAEf,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,uBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACrD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAgB,CAAC,QAAQ,EAAE;wBACtD,KAAK,EAAE,KAAK,WAAU,UAA4C;4BAEjE,MAAM,oBAAoB,GAAG,IAAA,sBAAW,EAAC;gCACxC,KAAK,EAAE,OAAO,CAAC,MAA8B;gCAC7C,IAAI,EAAE,uBAAgB,CAAC,QAAQ;gCAC/B,SAAS,EAAE,OAAO,CAAC,SAAS;6BAC5B,CAAC,CAAC;4BAEH,MAAM,UAAU,GAAG;gCAClB,KAAK,EAAE,cAAY,CAAC;gCACpB,QAAQ,EAAE,IAAI;gCACd,UAAU,EAAE,IAAI;gCAChB,YAAY,EAAE,IAAI;6BAClB,CAAC;4BAEF,MAAM,mBAAmB,GAAsB,oBAAoB,CAAC,IAAI,EAAE,uBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;4BAEjH,OAAO,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;wBAC5D,CAAC;wBACD,QAAQ,EAA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mB,CAAC,CAAC;QAE1D,OAAO,aAA0B,CAAC;IACnC,CAAC,CAAA;AACF,CAAC","sourcesContent":["import 'reflect-metadata';\nimport {BaseEntity, EntityTarget, FindOptionsRelations} from \"typeorm\";\nimport { IApiGetListResponseResult } from \"../../interface\";\nimport { EApiFunctionType } from \"../../enum\";\nimport { ApiFunction } from \"./function\";\nimport {TApiFunctionGetListProperties} from \"../../type\";\nimport {TApiFunctionGetProperties} from \"../../type/api/function/get-properties.type\";\n\nconst API_SERVICE_METADATA_KEY = Symbol('ApiServiceMetadata');\n\nexport function ApiService<E extends BaseEntity>(options: { entity: EntityTarget<E>, relations?: FindOptionsRelations<E> }) {\n\treturn function <TFunction extends { new (...args: any[]): {} }>(target: TFunction) {\n\t\tconst originalConstructor = target;\n\n\t\tconst ExtendedClass = class extends originalConstructor {\n\t\t\tconstructor(...args: any[]) {\n\t\t\t\tsuper(...args);\n\n\t\t\t\tif (!this.hasOwnProperty(EApiFunctionType.GET_LIST)) {\n\t\t\t\t\tObject.defineProperty(this, EApiFunctionType.GET_LIST, {\n\t\t\t\t\t\tvalue: async function(properties: TApiFunctionGetListProperties<E>): Promise<IApiGetListResponseResult<E>> {\n\n\t\t\t\t\t\t\tconst apiFunctionDecorator = ApiFunction({\n\t\t\t\t\t\t\t\tmodel: options.entity as new () => BaseEntity,\n\t\t\t\t\t\t\t\ttype: EApiFunctionType.GET_LIST,\n\t\t\t\t\t\t\t\trelations: options.relations\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tconst descriptor = {\n\t\t\t\t\t\t\t\tvalue: function() {},\n\t\t\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tconst decoratedDescriptor:PropertyDescriptor = apiFunctionDecorator(this, EApiFunctionType.GET_LIST, descriptor);\n\n\t\t\t\t\t\t\treturn decoratedDescriptor.value.apply(this, [properties]);\n\t\t\t\t\t\t},\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (!this.hasOwnProperty(EApiFunctionType.GET)) {\n\t\t\t\t\tObject.defineProperty(this, EApiFunctionType.GET, {\n\t\t\t\t\t\tvalue: async function(id: string, properties: TApiFunctionGetProperties<E>): Promise<E> {\n\n\t\t\t\t\t\t\tconst apiFunctionDecorator = ApiFunction({\n\t\t\t\t\t\t\t\tmodel: options.entity as new () => BaseEntity,\n\t\t\t\t\t\t\t\ttype: EApiFunctionType.GET,\n\t\t\t\t\t\t\t\trelations: options.relations\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tconst descriptor = {\n\t\t\t\t\t\t\t\tvalue: function() {},\n\t\t\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tconst decoratedDescriptor:PropertyDescriptor = apiFunctionDecorator(this, EApiFunctionType.GET, descriptor);\n\n\t\t\t\t\t\t\treturn decoratedDescriptor.value.apply(this, [id, properties]);\n\t\t\t\t\t\t},\n\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tReflect.defineMetadata(API_SERVICE_METADATA_KEY, {\n\t\t\tentity: options.entity,\n\t\t\tgetListMetadata: {\n\t\t\t\tmodel: options.entity,\n\t\t\t\ttype: EApiFunctionType.GET_LIST,\n\t\t\t}\n\t\t}, ExtendedClass);\n\n\t\tObject.setPrototypeOf(ExtendedClass, originalConstructor);\n\n\t\treturn ExtendedClass as TFunction;\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api";
|
|
@@ -0,0 +1,18 @@
|
|
|
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"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["decorator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB","sourcesContent":["export * from \"./api\";\n"]}
|