ts-deco 1.0.5 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -6
- package/dist/decorators/utils/apply-decorators.js +8 -2
- package/dist/decorators/utils/apply-decorators.js.map +1 -1
- package/dist/decorators/validators/string.decorator.d.ts.map +1 -1
- package/dist/decorators/validators/string.decorator.js +1 -2
- package/dist/decorators/validators/string.decorator.js.map +1 -1
- package/dist/src/decorators/utils/apply-decorators.d.ts +22 -0
- package/dist/src/decorators/utils/apply-decorators.d.ts.map +1 -0
- package/dist/src/decorators/utils/apply-decorators.js +54 -0
- package/dist/src/decorators/utils/apply-decorators.js.map +1 -0
- package/dist/src/decorators/validators/boolean.decorator.d.ts +6 -0
- package/dist/src/decorators/validators/boolean.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/boolean.decorator.js +40 -0
- package/dist/src/decorators/validators/boolean.decorator.js.map +1 -0
- package/dist/src/decorators/validators/date.decorator.d.ts +6 -0
- package/dist/src/decorators/validators/date.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/date.decorator.js +24 -0
- package/dist/src/decorators/validators/date.decorator.js.map +1 -0
- package/dist/src/decorators/validators/enum.decorator.d.ts +6 -0
- package/dist/src/decorators/validators/enum.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/enum.decorator.js +15 -0
- package/dist/src/decorators/validators/enum.decorator.js.map +1 -0
- package/dist/src/decorators/validators/number.decorator.d.ts +7 -0
- package/dist/src/decorators/validators/number.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/number.decorator.js +44 -0
- package/dist/src/decorators/validators/number.decorator.js.map +1 -0
- package/dist/src/decorators/validators/property.decorator.d.ts +14 -0
- package/dist/src/decorators/validators/property.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/property.decorator.js +58 -0
- package/dist/src/decorators/validators/property.decorator.js.map +1 -0
- package/dist/src/decorators/validators/string.decorator.d.ts +6 -0
- package/dist/src/decorators/validators/string.decorator.d.ts.map +1 -0
- package/dist/src/decorators/validators/string.decorator.js +14 -0
- package/dist/src/decorators/validators/string.decorator.js.map +1 -0
- package/dist/src/decorators/validators/utils/common-decorators.d.ts +29 -0
- package/dist/src/decorators/validators/utils/common-decorators.d.ts.map +1 -0
- package/dist/src/decorators/validators/utils/common-decorators.js +78 -0
- package/dist/src/decorators/validators/utils/common-decorators.js.map +1 -0
- package/dist/src/decorators/validators/utils/validator-options.d.ts +8 -0
- package/dist/src/decorators/validators/utils/validator-options.d.ts.map +1 -0
- package/dist/src/decorators/validators/utils/validator-options.js +11 -0
- package/dist/src/decorators/validators/utils/validator-options.js.map +1 -0
- package/dist/src/decorators/validators/validator.type.d.ts +69 -0
- package/dist/src/decorators/validators/validator.type.d.ts.map +1 -0
- package/dist/src/decorators/validators/validator.type.js +3 -0
- package/dist/src/decorators/validators/validator.type.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +31 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/apply-decorators.test.d.ts +2 -0
- package/dist/tests/apply-decorators.test.d.ts.map +1 -0
- package/dist/tests/apply-decorators.test.js +21 -0
- package/dist/tests/apply-decorators.test.js.map +1 -0
- package/dist/tests/property.decorator.test.d.ts +2 -0
- package/dist/tests/property.decorator.test.d.ts.map +1 -0
- package/dist/tests/property.decorator.test.js +326 -0
- package/dist/tests/property.decorator.test.js.map +1 -0
- package/dist/tests/setup.d.ts +2 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +4 -0
- package/dist/tests/setup.js.map +1 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ class CreateUserDto {
|
|
|
21
21
|
@Property({ type: String, optional: false })
|
|
22
22
|
name: string;
|
|
23
23
|
|
|
24
|
-
@Property({ type: Number, min: 0, max: 120 })
|
|
24
|
+
@Property({ type: Number, min: 0, max: 120, optional: false })
|
|
25
25
|
age: number;
|
|
26
26
|
|
|
27
27
|
@Property({ type: String, optional: true })
|
|
@@ -122,6 +122,34 @@ class UserDto {
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
#### 빈 값 검증 (isNotEmpty)
|
|
126
|
+
|
|
127
|
+
문자열이나 배열이 비어있지 않은지 검증하려면 `isNotEmpty` 옵션을 사용합니다:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { Property } from 'ts-deco';
|
|
131
|
+
|
|
132
|
+
class UserDto {
|
|
133
|
+
@Property({
|
|
134
|
+
type: String,
|
|
135
|
+
optional: false,
|
|
136
|
+
isNotEmpty: true,
|
|
137
|
+
notEmptyMessage: '이름은 필수이며 비어있을 수 없습니다'
|
|
138
|
+
})
|
|
139
|
+
name: string;
|
|
140
|
+
|
|
141
|
+
@Property({
|
|
142
|
+
type: String,
|
|
143
|
+
isArray: true,
|
|
144
|
+
optional: false,
|
|
145
|
+
isNotEmpty: true,
|
|
146
|
+
arrayMessage: '태그는 배열이어야 합니다',
|
|
147
|
+
notEmptyMessage: '태그는 최소 1개 이상 필요합니다'
|
|
148
|
+
})
|
|
149
|
+
tags: string[];
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
125
153
|
#### 커스텀 에러 메시지
|
|
126
154
|
|
|
127
155
|
```typescript
|
|
@@ -149,10 +177,10 @@ class UserDto {
|
|
|
149
177
|
import { DtoString, DtoNumber, DtoDate, DtoBoolean, DtoEnum } from 'ts-deco';
|
|
150
178
|
|
|
151
179
|
class UserDto {
|
|
152
|
-
@DtoString({ optional: false })
|
|
180
|
+
@DtoString({ optional: false, isNotEmpty: true })
|
|
153
181
|
name: string;
|
|
154
182
|
|
|
155
|
-
@DtoNumber({ min: 0, max: 120 })
|
|
183
|
+
@DtoNumber({ min: 0, max: 120, optional: false })
|
|
156
184
|
age: number;
|
|
157
185
|
|
|
158
186
|
@DtoDate({ optional: true })
|
|
@@ -166,6 +194,16 @@ class UserDto {
|
|
|
166
194
|
}
|
|
167
195
|
```
|
|
168
196
|
|
|
197
|
+
#### 개별 데코레이터 옵션
|
|
198
|
+
|
|
199
|
+
각 개별 데코레이터는 `Property` 데코레이터와 동일한 옵션을 지원합니다:
|
|
200
|
+
|
|
201
|
+
- **DtoString**: `optional`, `isNotEmpty`, `isArray`, `validatorMessage`, `notEmptyMessage`, `arrayMessage` 및 Swagger 옵션
|
|
202
|
+
- **DtoNumber**: `optional`, `isNotEmpty`, `isArray`, `isInt`, `min`, `max`, `minMessage`, `maxMessage`, `validatorMessage`, `notEmptyMessage`, `arrayMessage` 및 Swagger 옵션
|
|
203
|
+
- **DtoDate**: `optional`, `isNotEmpty`, `isArray`, `validatorMessage`, `notEmptyMessage`, `arrayMessage` 및 Swagger 옵션
|
|
204
|
+
- **DtoBoolean**: `optional`, `isNotEmpty`, `isArray`, `validatorMessage`, `notEmptyMessage`, `arrayMessage` 및 Swagger 옵션
|
|
205
|
+
- **DtoEnum**: `optional`, `isNotEmpty`, `isArray`, `exclude`, `validatorMessage`, `notEmptyMessage`, `arrayMessage` 및 Swagger 옵션
|
|
206
|
+
|
|
169
207
|
## Property 데코레이터 옵션
|
|
170
208
|
|
|
171
209
|
### 공통 옵션
|
|
@@ -174,11 +212,12 @@ class UserDto {
|
|
|
174
212
|
|------|------|--------|------|
|
|
175
213
|
| `type` | `String \| Number \| Date \| Boolean` | 필수 | 필드 타입 |
|
|
176
214
|
| `enum` | `object` | - | 열거형 타입 (type 대신 사용) |
|
|
177
|
-
| `optional` | `boolean` | `false` | 선택적 필드
|
|
215
|
+
| `optional` | `boolean` | `false` | 선택적 필드 여부. `true`일 경우 `IsOptional` 검증 적용 |
|
|
178
216
|
| `isArray` | `boolean` | `false` | 배열 타입 여부 |
|
|
179
|
-
| `
|
|
217
|
+
| `isNotEmpty` | `boolean` | `false` | 빈 값 검증 여부. `true`일 경우 `IsNotEmpty` 검증 적용 (optional이 false일 때만) |
|
|
218
|
+
| `validatorMessage` | `string` | - | 타입 검증 실패 메시지 |
|
|
180
219
|
| `arrayMessage` | `string` | - | 배열 검증 실패 메시지 |
|
|
181
|
-
| `notEmptyMessage` | `string` | - | 빈 값 검증 실패 메시지 |
|
|
220
|
+
| `notEmptyMessage` | `string` | - | 빈 값 검증 실패 메시지 (isNotEmpty가 true일 때 사용) |
|
|
182
221
|
|
|
183
222
|
### 숫자 타입 전용 옵션
|
|
184
223
|
|
|
@@ -210,6 +249,107 @@ class UserDto {
|
|
|
210
249
|
name: string;
|
|
211
250
|
```
|
|
212
251
|
|
|
252
|
+
## 사용 예제
|
|
253
|
+
|
|
254
|
+
### 기본 사용법
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { Property } from 'ts-deco';
|
|
258
|
+
import { validate } from 'class-validator';
|
|
259
|
+
import { plainToInstance } from 'class-transformer';
|
|
260
|
+
|
|
261
|
+
class CreateUserDto {
|
|
262
|
+
// 필수 문자열 필드
|
|
263
|
+
@Property({ type: String, optional: false })
|
|
264
|
+
name: string;
|
|
265
|
+
|
|
266
|
+
// 선택적 이메일 필드
|
|
267
|
+
@Property({ type: String, optional: true })
|
|
268
|
+
email?: string;
|
|
269
|
+
|
|
270
|
+
// 필수 숫자 필드 (범위 제한)
|
|
271
|
+
@Property({ type: Number, min: 0, max: 120, optional: false })
|
|
272
|
+
age: number;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 사용 예제
|
|
276
|
+
const userData = {
|
|
277
|
+
name: '홍길동',
|
|
278
|
+
age: 25
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const dto = plainToInstance(CreateUserDto, userData);
|
|
282
|
+
const errors = await validate(dto);
|
|
283
|
+
|
|
284
|
+
if (errors.length > 0) {
|
|
285
|
+
console.log('검증 실패:', errors);
|
|
286
|
+
} else {
|
|
287
|
+
console.log('검증 성공:', dto);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### 빈 값 검증 예제
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { Property } from 'ts-deco';
|
|
295
|
+
|
|
296
|
+
class PostDto {
|
|
297
|
+
// 빈 문자열 허용 안 함
|
|
298
|
+
@Property({
|
|
299
|
+
type: String,
|
|
300
|
+
optional: false,
|
|
301
|
+
isNotEmpty: true,
|
|
302
|
+
notEmptyMessage: '제목은 필수이며 비어있을 수 없습니다'
|
|
303
|
+
})
|
|
304
|
+
title: string;
|
|
305
|
+
|
|
306
|
+
// 빈 문자열 허용 (기본값)
|
|
307
|
+
@Property({
|
|
308
|
+
type: String,
|
|
309
|
+
optional: false,
|
|
310
|
+
isNotEmpty: false // 기본값
|
|
311
|
+
})
|
|
312
|
+
description: string; // "" 허용
|
|
313
|
+
|
|
314
|
+
// 빈 배열 허용 안 함
|
|
315
|
+
@Property({
|
|
316
|
+
type: String,
|
|
317
|
+
isArray: true,
|
|
318
|
+
optional: false,
|
|
319
|
+
isNotEmpty: true,
|
|
320
|
+
notEmptyMessage: '태그는 최소 1개 이상 필요합니다'
|
|
321
|
+
})
|
|
322
|
+
tags: string[];
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## 검증 동작 방식
|
|
327
|
+
|
|
328
|
+
### optional 옵션
|
|
329
|
+
|
|
330
|
+
- `optional: false` (기본값): 필드가 필수입니다
|
|
331
|
+
- 값이 `undefined` 또는 `null`이면 `IsDefined` 검증 실패
|
|
332
|
+
- `isNotEmpty: true`인 경우 `IsNotEmpty` 검증 적용 (빈 문자열, 빈 배열 등도 검증)
|
|
333
|
+
- `optional: true`: 필드가 선택적입니다
|
|
334
|
+
- 값이 없어도 통과 (`IsOptional` 검증 적용)
|
|
335
|
+
- 값이 있으면 타입 검증 수행
|
|
336
|
+
|
|
337
|
+
### isNotEmpty 옵션
|
|
338
|
+
|
|
339
|
+
- `isNotEmpty: false` (기본값): 빈 값 검증 없음
|
|
340
|
+
- `optional: false`일 때 `IsDefined` 검증만 수행
|
|
341
|
+
- `isNotEmpty: true`: 빈 값 검증 수행
|
|
342
|
+
- `optional: false`일 때만 적용됨
|
|
343
|
+
- `IsNotEmpty` 검증 적용 (빈 문자열 `""`, 빈 배열 `[]` 등도 검증 실패)
|
|
344
|
+
|
|
345
|
+
### 검증 우선순위
|
|
346
|
+
|
|
347
|
+
1. `optional: true` → `IsOptional` 적용 (값이 없어도 통과)
|
|
348
|
+
2. `optional: false` + `isNotEmpty: true` → `IsNotEmpty` 적용 (빈 값 검증)
|
|
349
|
+
3. `optional: false` + `isNotEmpty: false` → `IsDefined` 적용 (값 존재 여부만 검증)
|
|
350
|
+
4. 타입 검증 (IsString, IsNumber, IsDate, IsBoolean, IsEnum 등)
|
|
351
|
+
5. 추가 검증 (min/max, exclude 등)
|
|
352
|
+
|
|
213
353
|
## 엄격한 검증 규칙
|
|
214
354
|
|
|
215
355
|
`ts-deco`는 다음과 같은 엄격한 검증 규칙을 적용합니다:
|
|
@@ -224,6 +364,7 @@ name: string;
|
|
|
224
364
|
- **타입 불일치 시 즉시 에러**: 잘못된 타입이 전달되면 명확한 에러 메시지 제공
|
|
225
365
|
- **범위 검증**: `min`/`max` 옵션이 제공되면 반드시 검증
|
|
226
366
|
- **필수 필드 검증**: `optional: false`인 경우 값이 없으면 에러
|
|
367
|
+
- **빈 값 검증**: `isNotEmpty: true`인 경우 빈 문자열, 빈 배열 등도 검증 실패
|
|
227
368
|
- **배열 검증**: `isArray: true`인 경우 배열 타입만 허용
|
|
228
369
|
- **열거형 검증**: `enum`이 제공되면 해당 값만 허용
|
|
229
370
|
|
|
@@ -44,9 +44,15 @@ function applyDecorators(...decorators) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
// MethodDecorator일 때는 PropertyDescriptor 반환
|
|
47
|
-
|
|
47
|
+
if (descriptorOrIndex !== undefined && typeof descriptorOrIndex !== 'number') {
|
|
48
|
+
return descriptorOrIndex;
|
|
49
|
+
}
|
|
50
|
+
// ClassDecorator일 때는 Function 반환 (또는 void)
|
|
51
|
+
if (propertyKey === undefined) {
|
|
52
|
+
return target;
|
|
53
|
+
}
|
|
48
54
|
// PropertyDecorator/ParameterDecorator일 때는 반환값 없음 (undefined)
|
|
49
|
-
return
|
|
55
|
+
return undefined;
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
58
|
//# sourceMappingURL=apply-decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-decorators.js","sourceRoot":"","sources":["../../../src/decorators/utils/apply-decorators.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA4BH,
|
|
1
|
+
{"version":3,"file":"apply-decorators.js","sourceRoot":"","sources":["../../../src/decorators/utils/apply-decorators.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA4BH,0CA2CC;AAjDD;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,GAAG,UAAiB;IAChD,OAAO,UAAU,MAAW,EAAE,WAA6B,EAAE,iBAA+C;QACxG,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBAClC,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;oBACxC,oEAAoE;oBACpE,gBAAgB;oBAChB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;gBACtD,CAAC;qBAAM,CAAC;oBACJ,kFAAkF;oBAClF,+BAA+B;oBAC/B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;oBACjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;wBACvB,iBAAiB,GAAG,MAAM,CAAC;oBAC/B,CAAC;gBACL,CAAC;YACL,CAAC;iBAAM,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBACnC,mDAAmD;gBACnD,gBAAgB;gBAChB,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACJ,8CAA8C;gBAC9C,qBAAqB;gBACrB,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;gBACjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACvB,MAAM,GAAG,MAAM,CAAC;gBACpB,CAAC;YACL,CAAC;QACL,CAAC;QAED,4CAA4C;QAC5C,IAAI,iBAAiB,KAAK,SAAS,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;YAC3E,OAAO,iBAAiB,CAAC;QAC7B,CAAC;QAED,2CAA2C;QAC3C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,8DAA8D;QAC9D,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/validators/string.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/validators/string.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAKvD,KAAK,gBAAgB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAEjE,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,qBAmB3D"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = DtoString;
|
|
4
|
-
const class_transformer_1 = require("class-transformer");
|
|
5
4
|
const class_validator_1 = require("class-validator");
|
|
6
5
|
const validator_options_1 = require("./utils/validator-options");
|
|
7
6
|
const common_decorators_1 = require("./utils/common-decorators");
|
|
@@ -10,6 +9,6 @@ function DtoString(options) {
|
|
|
10
9
|
const { isArray = false, optional = false, validatorMessage, notEmptyMessage, arrayMessage, ...swaggerOptions } = options || {};
|
|
11
10
|
const validatorOption = (0, validator_options_1.getValidatorOptions)({ isArray, validatorMessage });
|
|
12
11
|
const each = validatorOption.each ?? false;
|
|
13
|
-
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)(optional, String, isArray, swaggerOptions), (0,
|
|
12
|
+
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)(optional, String, isArray, swaggerOptions), (0, common_decorators_1.getRequiredValidator)(optional, each, false), ...(0, common_decorators_1.getIsArrayDecorator)(isArray, arrayMessage), (0, class_validator_1.IsString)(validatorOption));
|
|
14
13
|
}
|
|
15
14
|
//# sourceMappingURL=string.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.decorator.js","sourceRoot":"","sources":["../../../src/decorators/validators/string.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"string.decorator.js","sourceRoot":"","sources":["../../../src/decorators/validators/string.decorator.ts"],"names":[],"mappings":";;AASA,4BAmBC;AA5BD,qDAA2C;AAG3C,iEAAgE;AAChE,iEAA+G;AAC/G,gEAA4D;AAI5D,SAAwB,SAAS,CAAC,OAA0B;IACxD,MAAM,EACF,OAAO,GAAG,KAAK,EACf,QAAQ,GAAG,KAAK,EAChB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,GAAG,cAAc,EACpB,GAAG,OAAO,IAAI,EAAE,CAAC;IAElB,MAAM,eAAe,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC;IAE3C,OAAO,IAAA,kCAAe,EAClB,IAAA,2CAAuB,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,EAClE,IAAA,wCAAoB,EAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,EAC3C,GAAG,IAAA,uCAAmB,EAAC,OAAO,EAAE,YAAY,CAAC,EAC7C,IAAA,0BAAQ,EAAC,eAAe,CAAC,CAC5B,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PropertyDecorator } from '../validators/validator.type';
|
|
2
|
+
/**
|
|
3
|
+
* 여러 데코레이터를 하나로 합치는 유틸리티 함수
|
|
4
|
+
* TypeScript의 모든 데코레이터 타입을 지원합니다.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Class 데코레이터를 합칩니다.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyDecorators(...decorators: ClassDecorator[]): ClassDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* Property 데코레이터를 합칩니다.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyDecorators(...decorators: PropertyDecorator[]): PropertyDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Method 데코레이터를 합칩니다.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyDecorators(...decorators: MethodDecorator[]): MethodDecorator;
|
|
18
|
+
/**
|
|
19
|
+
* Parameter 데코레이터를 합칩니다.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyDecorators(...decorators: ParameterDecorator[]): ParameterDecorator;
|
|
22
|
+
//# sourceMappingURL=apply-decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-decorators.d.ts","sourceRoot":"","sources":["../../../../src/decorators/utils/apply-decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,UAAU,EAAE,cAAc,EAAE,GAAG,cAAc,CAAC;AAEjF;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,UAAU,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,CAAC;AAEvF;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,UAAU,EAAE,eAAe,EAAE,GAAG,eAAe,CAAC;AAEnF;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,UAAU,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyDecorators = applyDecorators;
|
|
4
|
+
/**
|
|
5
|
+
* 여러 데코레이터를 하나로 합치는 구현 함수
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ 주의: 모든 데코레이터는 동일한 타입이어야 합니다.
|
|
8
|
+
* (ClassDecorator, PropertyDecorator, MethodDecorator, ParameterDecorator 중 하나)
|
|
9
|
+
*/
|
|
10
|
+
function applyDecorators(...decorators) {
|
|
11
|
+
return function (target, propertyKey, descriptorOrIndex) {
|
|
12
|
+
for (const decorator of decorators) {
|
|
13
|
+
if (descriptorOrIndex !== undefined) {
|
|
14
|
+
if (typeof descriptorOrIndex === 'number') {
|
|
15
|
+
// ParameterDecorator: (target, propertyKey, parameterIndex) => void
|
|
16
|
+
// 반환값 없음 (void)
|
|
17
|
+
decorator(target, propertyKey, descriptorOrIndex);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// MethodDecorator: (target, propertyKey, descriptor) => PropertyDescriptor | void
|
|
21
|
+
// PropertyDescriptor를 반환할 수 있음
|
|
22
|
+
const result = decorator(target, propertyKey, descriptorOrIndex);
|
|
23
|
+
if (result !== undefined) {
|
|
24
|
+
descriptorOrIndex = result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (propertyKey !== undefined) {
|
|
29
|
+
// PropertyDecorator: (target, propertyKey) => void
|
|
30
|
+
// 반환값 없음 (void)
|
|
31
|
+
decorator(target, propertyKey);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// ClassDecorator: (target) => Function | void
|
|
35
|
+
// Function을 반환할 수 있음
|
|
36
|
+
const result = decorator(target);
|
|
37
|
+
if (result !== undefined) {
|
|
38
|
+
target = result;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// MethodDecorator일 때는 PropertyDescriptor 반환
|
|
43
|
+
if (descriptorOrIndex !== undefined && typeof descriptorOrIndex !== 'number') {
|
|
44
|
+
return descriptorOrIndex;
|
|
45
|
+
}
|
|
46
|
+
// ClassDecorator일 때는 Function 반환 (또는 void)
|
|
47
|
+
if (propertyKey === undefined) {
|
|
48
|
+
return target;
|
|
49
|
+
}
|
|
50
|
+
// PropertyDecorator/ParameterDecorator일 때는 반환값 없음 (undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=apply-decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-decorators.js","sourceRoot":"","sources":["../../../../src/decorators/utils/apply-decorators.ts"],"names":[],"mappings":";;AAiCA,0CA2CC;AAjDD;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,GAAG,UAAiB;IAChD,OAAO,UAAU,MAAW,EAAE,WAA6B,EAAE,iBAA+C;QACxG,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACjC,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBAClC,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;oBACxC,oEAAoE;oBACpE,gBAAgB;oBAChB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;gBACtD,CAAC;qBAAM,CAAC;oBACJ,kFAAkF;oBAClF,+BAA+B;oBAC/B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;oBACjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;wBACvB,iBAAiB,GAAG,MAAM,CAAC;oBAC/B,CAAC;gBACL,CAAC;YACL,CAAC;iBAAM,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBACnC,mDAAmD;gBACnD,gBAAgB;gBAChB,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACJ,8CAA8C;gBAC9C,qBAAqB;gBACrB,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;gBACjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACvB,MAAM,GAAG,MAAM,CAAC;gBACpB,CAAC;YACL,CAAC;QACL,CAAC;QAED,4CAA4C;QAC5C,IAAI,iBAAiB,KAAK,SAAS,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;YAC3E,OAAO,iBAAiB,CAAC;QAC7B,CAAC;QAED,2CAA2C;QAC3C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,8DAA8D;QAC9D,OAAO,SAAS,CAAC;IACrB,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { DtoValidatorOptions, PropertyDecorator } from './validator.type';
|
|
3
|
+
type DtoBooleanOptions = ApiPropertyOptions & DtoValidatorOptions;
|
|
4
|
+
export default function DtoBoolean(options?: DtoBooleanOptions): PropertyDecorator;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=boolean.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.decorator.d.ts","sourceRoot":"","sources":["../../../../src/decorators/validators/boolean.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKrD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,KAAK,iBAAiB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAElE,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,CAgCjF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DtoBoolean;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const apply_decorators_1 = require("../utils/apply-decorators");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const validator_options_1 = require("./utils/validator-options");
|
|
8
|
+
const common_decorators_1 = require("./utils/common-decorators");
|
|
9
|
+
function DtoBoolean(options) {
|
|
10
|
+
const { isArray = false, optional = false, isNotEmpty = false, validatorMessage, arrayMessage, notEmptyMessage, ...swaggerOptions } = options || {};
|
|
11
|
+
const validatorOption = (0, validator_options_1.getValidatorOptions)({ isArray, validatorMessage });
|
|
12
|
+
const each = validatorOption.each ?? false;
|
|
13
|
+
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)({ optional, type: Boolean, isArray, swaggerOptions }), (0, class_transformer_1.Transform)(({ value }) => {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.map(v => {
|
|
16
|
+
if (typeof v === 'boolean')
|
|
17
|
+
return v;
|
|
18
|
+
if (typeof v === 'string') {
|
|
19
|
+
const lower = v.toLowerCase();
|
|
20
|
+
if (['true', '1'].includes(lower))
|
|
21
|
+
return true;
|
|
22
|
+
if (['false', '0'].includes(lower))
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return v;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'boolean')
|
|
29
|
+
return value;
|
|
30
|
+
if (typeof value === 'string') {
|
|
31
|
+
const lower = value.toLowerCase();
|
|
32
|
+
if (['true', '1'].includes(lower))
|
|
33
|
+
return true;
|
|
34
|
+
if (['false', '0'].includes(lower))
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}), (0, common_decorators_1.getRequiredValidator)({ optional, each, isNotEmpty, notEmptyMessage }), ...(0, common_decorators_1.getIsArrayDecorator)({ isArray, arrayMessage }), (0, class_validator_1.IsBoolean)(validatorOption));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=boolean.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/validators/boolean.decorator.ts"],"names":[],"mappings":";;AAUA,6BAgCC;AAzCD,qDAA4C;AAC5C,gEAA4D;AAC5D,yDAA8C;AAC9C,iEAAgE;AAEhE,iEAA+G;AAI/G,SAAwB,UAAU,CAAC,OAA2B;IAC1D,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,QAAQ,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEpJ,MAAM,eAAe,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC;IAE3C,OAAO,IAAA,kCAAe,EAClB,IAAA,2CAAuB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,EAC7E,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QACpB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBACjB,IAAI,OAAO,CAAC,KAAK,SAAS;oBAAE,OAAO,CAAC,CAAC;gBACrC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;oBACxB,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;oBAC9B,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;wBAAE,OAAO,IAAI,CAAC;oBAC/C,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;wBAAE,OAAO,KAAK,CAAC;gBACrD,CAAC;gBACD,OAAO,CAAC,CAAC;YACb,CAAC,CAAC,CAAC;QACP,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC/C,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;QACrD,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,EACF,IAAA,wCAAoB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EACrE,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EACjD,IAAA,2BAAS,EAAC,eAAe,CAAC,CACR,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { DtoValidatorOptions, PropertyDecorator } from './validator.type';
|
|
3
|
+
type DtoDateOptions = ApiPropertyOptions & DtoValidatorOptions;
|
|
4
|
+
export default function DtoDate(options?: DtoDateOptions): PropertyDecorator;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=date.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.decorator.d.ts","sourceRoot":"","sources":["../../../../src/decorators/validators/date.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKrD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,KAAK,cAAc,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAE/D,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,iBAAiB,CAsB3E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DtoDate;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const apply_decorators_1 = require("../utils/apply-decorators");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const validator_options_1 = require("./utils/validator-options");
|
|
8
|
+
const common_decorators_1 = require("./utils/common-decorators");
|
|
9
|
+
function DtoDate(options) {
|
|
10
|
+
const { isArray = false, optional = false, isNotEmpty = false, validatorMessage, arrayMessage, notEmptyMessage, ...swaggerOptions } = options || {};
|
|
11
|
+
const validatorOption = (0, validator_options_1.getValidatorOptions)({ isArray, validatorMessage });
|
|
12
|
+
const each = validatorOption.each ?? false;
|
|
13
|
+
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)({ optional, type: Date, isArray, swaggerOptions }), (0, class_transformer_1.Transform)(({ value }) => {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.map(v => {
|
|
16
|
+
const d = new Date(v);
|
|
17
|
+
return isNaN(d.getTime()) ? v : d;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const d = new Date(value);
|
|
21
|
+
return isNaN(d.getTime()) ? value : d;
|
|
22
|
+
}), (0, common_decorators_1.getRequiredValidator)({ optional, each, isNotEmpty, notEmptyMessage }), ...(0, common_decorators_1.getIsArrayDecorator)({ isArray, arrayMessage }), (0, class_validator_1.IsDate)(validatorOption));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=date.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/validators/date.decorator.ts"],"names":[],"mappings":";;AAUA,0BAsBC;AA/BD,qDAAyC;AACzC,gEAA4D;AAC5D,yDAA8C;AAC9C,iEAAgE;AAEhE,iEAA+G;AAI/G,SAAwB,OAAO,CAAC,OAAwB;IACpD,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,QAAQ,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEpJ,MAAM,eAAe,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC;IAE3C,OAAO,IAAA,kCAAe,EAClB,IAAA,2CAAuB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,EAC1E,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QACpB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBACjB,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;gBACtB,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACP,CAAC;QACD,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,IAAA,wCAAoB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EACrE,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EACjD,IAAA,wBAAM,EAAC,eAAe,CAAC,CACL,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { DtoEnumValidatorOptions, PropertyDecorator } from './validator.type';
|
|
3
|
+
type DtoEnumOptions = ApiPropertyOptions & DtoEnumValidatorOptions;
|
|
4
|
+
export default function DtoEnum(enumType: object, options?: DtoEnumOptions): PropertyDecorator;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=enum.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.decorator.d.ts","sourceRoot":"","sources":["../../../../src/decorators/validators/enum.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,KAAK,cAAc,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,iBAAiB,CAqB7F"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DtoEnum;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const apply_decorators_1 = require("../utils/apply-decorators");
|
|
6
|
+
const validator_options_1 = require("./utils/validator-options");
|
|
7
|
+
const common_decorators_1 = require("./utils/common-decorators");
|
|
8
|
+
function DtoEnum(enumType, options) {
|
|
9
|
+
const { isArray = false, optional = false, isNotEmpty = false, exclude = [], validatorMessage, arrayMessage, notEmptyMessage, ...swaggerOptions } = options || {};
|
|
10
|
+
const validatorOption = (0, validator_options_1.getValidatorOptions)({ isArray, validatorMessage });
|
|
11
|
+
const each = validatorOption.each ?? false;
|
|
12
|
+
const enumValues = Object.values(enumType).filter(v => !exclude.includes(v));
|
|
13
|
+
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)({ optional, type: undefined, isArray, swaggerOptions: { enum: enumValues, ...swaggerOptions } }), (0, common_decorators_1.getRequiredValidator)({ optional, each, isNotEmpty, notEmptyMessage }), ...(0, common_decorators_1.getIsArrayDecorator)({ isArray, arrayMessage }), (0, class_validator_1.IsEnum)(enumValues, validatorOption));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=enum.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/validators/enum.decorator.ts"],"names":[],"mappings":";;AASA,0BAqBC;AA7BD,qDAAyC;AACzC,gEAA4D;AAC5D,iEAAgE;AAEhE,iEAA+G;AAI/G,SAAwB,OAAO,CAAC,QAAgB,EAAE,OAAwB;IACtE,MAAM,EACF,OAAO,GAAG,KAAK,EACf,QAAQ,GAAG,KAAK,EAChB,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,EAAE,EACZ,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,GAAG,cAAc,EACpB,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,MAAM,eAAe,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7E,OAAO,IAAA,kCAAe,EAClB,IAAA,2CAAuB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC,EACxH,IAAA,wCAAoB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EACrE,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EACjD,IAAA,wBAAM,EAAC,UAAiB,EAAE,eAAe,CAAC,CACxB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { IsNumberOptions } from 'class-validator';
|
|
3
|
+
import { DtoNumberValidatorOptions, PropertyDecorator } from './validator.type';
|
|
4
|
+
type DtoNumberOptions = ApiPropertyOptions & IsNumberOptions & DtoNumberValidatorOptions;
|
|
5
|
+
export default function DtoNumber(options?: DtoNumberOptions): PropertyDecorator;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=number.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.decorator.d.ts","sourceRoot":"","sources":["../../../../src/decorators/validators/number.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAmB,eAAe,EAAY,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIhF,KAAK,gBAAgB,GAAG,kBAAkB,GAAG,eAAe,GAAG,yBAAyB,CAAC;AAEzF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAqE/E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DtoNumber;
|
|
4
|
+
const apply_decorators_1 = require("../utils/apply-decorators");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
const validator_options_1 = require("./utils/validator-options");
|
|
7
|
+
const common_decorators_1 = require("./utils/common-decorators");
|
|
8
|
+
function DtoNumber(options) {
|
|
9
|
+
const { isArray = false, optional = false, isNotEmpty = false, isInt = false, validatorMessage, arrayMessage, notEmptyMessage, min, max,
|
|
10
|
+
// IsNumberOptions
|
|
11
|
+
allowNaN = false, allowInfinity = false, maxDecimalPlaces = 0, minMessage, maxMessage,
|
|
12
|
+
// ApiPropertyOptions
|
|
13
|
+
...swaggerOptions } = options || {};
|
|
14
|
+
const validatorOption = (0, validator_options_1.getValidatorOptions)({ isArray, validatorMessage });
|
|
15
|
+
const each = validatorOption.each ?? false;
|
|
16
|
+
// Min/Max 검증용 옵션 (message 제외, minMessage/maxMessage가 우선)
|
|
17
|
+
const { message: _, ...minMaxValidatorOption } = validatorOption;
|
|
18
|
+
const isNumberOption = allowNaN !== undefined || allowInfinity !== undefined || maxDecimalPlaces !== undefined
|
|
19
|
+
? {
|
|
20
|
+
...(allowNaN !== undefined && { allowNaN }),
|
|
21
|
+
...(allowInfinity !== undefined && { allowInfinity }),
|
|
22
|
+
...(maxDecimalPlaces !== undefined && { maxDecimalPlaces }),
|
|
23
|
+
}
|
|
24
|
+
: undefined;
|
|
25
|
+
// 숫자 검증 데코레이터
|
|
26
|
+
const numberValidator = isInt ? (0, class_validator_1.IsInt)(validatorOption) : (0, class_validator_1.IsNumber)(isNumberOption, validatorOption);
|
|
27
|
+
const minMaxValidators = [];
|
|
28
|
+
if (min !== undefined) {
|
|
29
|
+
minMaxValidators.push((0, class_validator_1.Min)(min, {
|
|
30
|
+
...minMaxValidatorOption,
|
|
31
|
+
each,
|
|
32
|
+
message: minMessage,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
if (max !== undefined) {
|
|
36
|
+
minMaxValidators.push((0, class_validator_1.Max)(max, {
|
|
37
|
+
...minMaxValidatorOption,
|
|
38
|
+
each,
|
|
39
|
+
message: maxMessage,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
return (0, apply_decorators_1.applyDecorators)((0, common_decorators_1.getApiPropertyDecorator)({ optional, type: Number, isArray, swaggerOptions }), (0, common_decorators_1.getRequiredValidator)({ optional, each, isNotEmpty, notEmptyMessage }), numberValidator, ...(0, common_decorators_1.getIsArrayDecorator)({ isArray, arrayMessage }), ...minMaxValidators);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=number.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/validators/number.decorator.ts"],"names":[],"mappings":";;AAUA,4BAqEC;AA/ED,gEAA4D;AAG5D,qDAA6E;AAE7E,iEAAgE;AAChE,iEAA+G;AAI/G,SAAwB,SAAS,CAAC,OAA0B;IACxD,MAAM,EACF,OAAO,GAAG,KAAK,EACf,QAAQ,GAAG,KAAK,EAChB,UAAU,GAAG,KAAK,EAClB,KAAK,GAAG,KAAK,EACb,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,GAAG,EACH,GAAG;IAEH,kBAAkB;IAClB,QAAQ,GAAG,KAAK,EAChB,aAAa,GAAG,KAAK,EACrB,gBAAgB,GAAG,CAAC,EACpB,UAAU,EACV,UAAU;IAEV,qBAAqB;IACrB,GAAG,cAAc,EACpB,GAAG,OAAO,IAAI,EAAE,CAAC;IAElB,MAAM,eAAe,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,KAAK,CAAC;IAE3C,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,qBAAqB,EAAE,GAAG,eAAe,CAAC;IAEjE,MAAM,cAAc,GAChB,QAAQ,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,IAAI,gBAAgB,KAAK,SAAS;QACnF,CAAC,CAAC;YACI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC3C,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,EAAE,aAAa,EAAE,CAAC;YACrD,GAAG,CAAC,gBAAgB,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,CAAC;SAC9D;QACH,CAAC,CAAC,SAAS,CAAC;IAEpB,cAAc;IACd,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,IAAA,uBAAK,EAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAA,0BAAQ,EAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAEnG,MAAM,gBAAgB,GAAwB,EAAE,CAAC;IAEjD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACpB,gBAAgB,CAAC,IAAI,CACjB,IAAA,qBAAG,EAAC,GAAG,EAAE;YACL,GAAG,qBAAqB;YACxB,IAAI;YACJ,OAAO,EAAE,UAAU;SACtB,CAAsB,CAC1B,CAAC;IACN,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACpB,gBAAgB,CAAC,IAAI,CACjB,IAAA,qBAAG,EAAC,GAAG,EAAE;YACL,GAAG,qBAAqB;YACxB,IAAI;YACJ,OAAO,EAAE,UAAU;SACtB,CAAsB,CAC1B,CAAC;IACN,CAAC;IAED,OAAO,IAAA,kCAAe,EAClB,IAAA,2CAAuB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,EAC5E,IAAA,wCAAoB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,EACrE,eAAe,EACf,GAAG,IAAA,uCAAmB,EAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EACjD,GAAG,gBAAgB,CACD,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
2
|
+
import { IsNumberOptions } from 'class-validator';
|
|
3
|
+
import { DtoEnumValidatorOptions, DtoNumberValidatorOptions, DtoValidatorOptions, PropertyDecorator } from './validator.type';
|
|
4
|
+
type PropertyStringOptions = ApiPropertyOptions & DtoValidatorOptions;
|
|
5
|
+
type PropertyNumberOptions = ApiPropertyOptions & IsNumberOptions & DtoNumberValidatorOptions;
|
|
6
|
+
type PropertyDateOptions = ApiPropertyOptions & DtoValidatorOptions;
|
|
7
|
+
type PropertyBooleanOptions = ApiPropertyOptions & DtoValidatorOptions;
|
|
8
|
+
type PropertyEnumOptions = ApiPropertyOptions & DtoEnumValidatorOptions & {
|
|
9
|
+
enum: object;
|
|
10
|
+
};
|
|
11
|
+
type PropertyOptions = PropertyStringOptions | PropertyNumberOptions | PropertyDateOptions | PropertyBooleanOptions | PropertyEnumOptions;
|
|
12
|
+
export default function Property(options: PropertyOptions): PropertyDecorator;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=property.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.decorator.d.ts","sourceRoot":"","sources":["../../../../src/decorators/validators/property.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMlD,OAAO,EACH,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACpB,MAAM,kBAAkB,CAAC;AAG1B,KAAK,qBAAqB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AACtE,KAAK,qBAAqB,GAAG,kBAAkB,GAAG,eAAe,GAAG,yBAAyB,CAAC;AAC9F,KAAK,mBAAmB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AACpE,KAAK,sBAAsB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AACvE,KAAK,mBAAmB,GAAG,kBAAkB,GAAG,uBAAuB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAG3F,KAAK,eAAe,GACd,qBAAqB,GACrB,qBAAqB,GACrB,mBAAmB,GACnB,sBAAsB,GACtB,mBAAmB,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,iBAAiB,CAkD5E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = Property;
|
|
7
|
+
const string_decorator_1 = __importDefault(require("./string.decorator"));
|
|
8
|
+
const number_decorator_1 = __importDefault(require("./number.decorator"));
|
|
9
|
+
const date_decorator_1 = __importDefault(require("./date.decorator"));
|
|
10
|
+
const boolean_decorator_1 = __importDefault(require("./boolean.decorator"));
|
|
11
|
+
const enum_decorator_1 = __importDefault(require("./enum.decorator"));
|
|
12
|
+
function Property(options) {
|
|
13
|
+
// enum이 있으면 enum 처리
|
|
14
|
+
if ('enum' in options && options.enum) {
|
|
15
|
+
const { enum: enumType, ...restOptions } = options;
|
|
16
|
+
return (0, enum_decorator_1.default)(enumType, restOptions);
|
|
17
|
+
}
|
|
18
|
+
// type이 없으면 에러
|
|
19
|
+
if (!options.type) {
|
|
20
|
+
throw new Error('type 또는 enum 속성이 필요합니다.');
|
|
21
|
+
}
|
|
22
|
+
const { type, ...restOptions } = options;
|
|
23
|
+
// type이 생성자 함수인 경우 name으로 분기 처리
|
|
24
|
+
if (typeof type === 'function') {
|
|
25
|
+
const typeName = type.name;
|
|
26
|
+
switch (typeName) {
|
|
27
|
+
case 'String':
|
|
28
|
+
return (0, string_decorator_1.default)(restOptions);
|
|
29
|
+
case 'Number':
|
|
30
|
+
return (0, number_decorator_1.default)(restOptions);
|
|
31
|
+
case 'Date':
|
|
32
|
+
return (0, date_decorator_1.default)(restOptions);
|
|
33
|
+
case 'Boolean':
|
|
34
|
+
return (0, boolean_decorator_1.default)(restOptions);
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`지원하지 않는 타입입니다.: ${typeName}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// type이 문자열인 경우도 처리 (하위 호환성)
|
|
40
|
+
if (typeof type === 'string') {
|
|
41
|
+
const typeStr = type;
|
|
42
|
+
if (typeStr === 'string' || typeStr === 'String') {
|
|
43
|
+
return (0, string_decorator_1.default)(restOptions);
|
|
44
|
+
}
|
|
45
|
+
if (typeStr === 'number' || typeStr === 'Number') {
|
|
46
|
+
return (0, number_decorator_1.default)(restOptions);
|
|
47
|
+
}
|
|
48
|
+
if (typeStr === 'date' || typeStr === 'Date') {
|
|
49
|
+
return (0, date_decorator_1.default)(restOptions);
|
|
50
|
+
}
|
|
51
|
+
if (typeStr === 'boolean' || typeStr === 'Boolean') {
|
|
52
|
+
return (0, boolean_decorator_1.default)(restOptions);
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`지원하지 않는 타입입니다.: ${typeStr}`);
|
|
55
|
+
}
|
|
56
|
+
throw new Error('지원하지 않는 type 형식입니다.');
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=property.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/validators/property.decorator.ts"],"names":[],"mappings":";;;;;AA6BA,2BAkDC;AA7ED,0EAA2C;AAC3C,0EAA2C;AAC3C,sEAAuC;AACvC,4EAA6C;AAC7C,sEAAuC;AAuBvC,SAAwB,QAAQ,CAAC,OAAwB;IACrD,oBAAoB;IACpB,IAAI,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;QACnD,OAAO,IAAA,wBAAO,EAAC,QAAQ,EAAE,WAA4C,CAAsB,CAAC;IAChG,CAAC;IAED,eAAe;IACf,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAEzC,gCAAgC;IAChC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAI,IAAiB,CAAC,IAAI,CAAC;QACzC,QAAQ,QAAQ,EAAE,CAAC;YACf,KAAK,QAAQ;gBACT,OAAO,IAAA,0BAAS,EAAC,WAA8C,CAAsB,CAAC;YAC1F,KAAK,QAAQ;gBACT,OAAO,IAAA,0BAAS,EAAC,WAA8C,CAAsB,CAAC;YAC1F,KAAK,MAAM;gBACP,OAAO,IAAA,wBAAO,EAAC,WAA4C,CAAsB,CAAC;YACtF,KAAK,SAAS;gBACV,OAAO,IAAA,2BAAU,EAAC,WAA+C,CAAsB,CAAC;YAC5F;gBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;IACL,CAAC;IAED,6BAA6B;IAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,IAAW,CAAC;QAC5B,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC/C,OAAO,IAAA,0BAAS,EAAC,WAA8C,CAAsB,CAAC;QAC1F,CAAC;QACD,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC/C,OAAO,IAAA,0BAAS,EAAC,WAA8C,CAAsB,CAAC;QAC1F,CAAC;QACD,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YAC3C,OAAO,IAAA,wBAAO,EAAC,WAA4C,CAAsB,CAAC;QACtF,CAAC;QACD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACjD,OAAO,IAAA,2BAAU,EAAC,WAA+C,CAAsB,CAAC;QAC5F,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC"}
|