@fluojs/validation 1.0.0-beta.1
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/LICENSE +21 -0
- package/README.ko.md +138 -0
- package/README.md +118 -0
- package/dist/decorators.d.ts +165 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +443 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/mapped-types.d.ts +99 -0
- package/dist/mapped-types.d.ts.map +1 -0
- package/dist/mapped-types.js +207 -0
- package/dist/standard-schema.d.ts +6 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/standard-schema.js +75 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/validation.d.ts +7 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +653 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fluo contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# @fluojs/validation
|
|
2
|
+
|
|
3
|
+
<p><a href="./README.md"><kbd>English</kbd></a> <strong><kbd>한국어</kbd></strong></p>
|
|
4
|
+
|
|
5
|
+
fluo를 위한 입력값 검증 데코레이터, Mapped DTO 헬퍼 및 검증 엔진입니다.
|
|
6
|
+
|
|
7
|
+
`@fluojs/validation`은 애플리케이션의 **입력 경계(Input Boundary)**를 담당합니다. 가공되지 않은(untyped) raw 데이터를 검증이 완료된 타입 기반 클래스 인스턴스(DTO)로 변환하는 강력한 데코레이터 세트와 실체화(Materialization) 엔진을 제공합니다. 이를 통해 비즈니스 로직에 도달하기 전 데이터의 무결성을 보장합니다.
|
|
8
|
+
|
|
9
|
+
## 목차
|
|
10
|
+
|
|
11
|
+
- [설치](#설치)
|
|
12
|
+
- [사용 시점](#사용-시점)
|
|
13
|
+
- [빠른 시작](#빠른-시작)
|
|
14
|
+
- [주요 패턴](#주요-패턴)
|
|
15
|
+
- [공개 API](#공개-api)
|
|
16
|
+
- [관련 패키지](#관련-패키지)
|
|
17
|
+
- [예제 소스](#예제-소스)
|
|
18
|
+
|
|
19
|
+
## 설치
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @fluojs/validation
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 사용 시점
|
|
26
|
+
|
|
27
|
+
- 들어오는 데이터(요청 바디, 쿼리 파라미터 등)를 클래스 기반 스키마에 맞춰 검증해야 할 때.
|
|
28
|
+
- 일반 JavaScript 객체를 재귀적 검증이 포함된 타입 기반 클래스 인스턴스로 변환하고 싶을 때.
|
|
29
|
+
- 기존 DTO로부터 새로운 DTO를 파생시키고 싶을 때 (예: `UserDto`에서 `UpdateUserDto` 생성).
|
|
30
|
+
- Zod나 Valibot 같은 기존 검증 라이브러리를 클래스 기반 DTO 구조 내에서 사용하고 싶을 때.
|
|
31
|
+
|
|
32
|
+
## 빠른 시작
|
|
33
|
+
|
|
34
|
+
표준 데코레이터를 사용하여 DTO를 정의하고, `DefaultValidator`를 사용하여 raw 데이터를 실체화 및 검증합니다.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { IsEmail, IsString, MinLength, DefaultValidator } from '@fluojs/validation';
|
|
38
|
+
|
|
39
|
+
class CreateUserDto {
|
|
40
|
+
@IsEmail()
|
|
41
|
+
email: string = '';
|
|
42
|
+
|
|
43
|
+
@IsString()
|
|
44
|
+
@MinLength(2)
|
|
45
|
+
name: string = '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const validator = new DefaultValidator();
|
|
49
|
+
const rawData = { email: 'test@example.com', name: 'Ko' };
|
|
50
|
+
|
|
51
|
+
// materialize()는 CreateUserDto의 인스턴스를 생성하고 검증을 수행합니다.
|
|
52
|
+
const user = await validator.materialize(rawData, CreateUserDto);
|
|
53
|
+
|
|
54
|
+
console.log(user instanceof CreateUserDto); // true
|
|
55
|
+
console.log(user.name); // "Ko"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 주요 패턴
|
|
59
|
+
|
|
60
|
+
### 실체화 vs 검증 (Materialization vs Validation)
|
|
61
|
+
|
|
62
|
+
- **`materialize<T>(value, target)`**: **입력 처리**에 가장 적합합니다. plain 객체를 받아 대상 클래스의 인스턴스를 생성하고, 값을 복사하며, 중첩된 DTO를 재귀적으로 처리한 후 모든 검증 규칙을 실행합니다.
|
|
63
|
+
- **`validate(instance, target)`**: **기존 객체 확인**에 적합합니다. 이미 생성된 인스턴스에 대해 검증 규칙만 실행합니다. 타입 변환이나 중첩된 객체의 실체화는 수행하지 않습니다.
|
|
64
|
+
|
|
65
|
+
### Mapped Types (Pick, Omit, Partial)
|
|
66
|
+
|
|
67
|
+
모든 검증 데코레이터와 바인딩 메타데이터를 보존하면서 새로운 DTO 클래스를 파생합니다.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { IsString, IsEmail, PickType, PartialType } from '@fluojs/validation';
|
|
71
|
+
|
|
72
|
+
class UserDto {
|
|
73
|
+
@IsString() name: string = '';
|
|
74
|
+
@IsEmail() email: string = '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 'email' 필드만 포함
|
|
78
|
+
class EmailOnlyDto extends PickType(UserDto, ['email']) {}
|
|
79
|
+
|
|
80
|
+
// 모든 필드를 선택 사항(optional)으로 변경
|
|
81
|
+
class UpdateUserDto extends PartialType(UserDto) {}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Standard Schema 지원 (Zod, Valibot)
|
|
85
|
+
|
|
86
|
+
`@ValidateClass`를 통해 클래스 레벨에서 선호하는 스키마 라이브러리를 사용할 수 있습니다. fluo는 [Standard Schema](https://github.com/standard-schema/spec) 규격을 구현하는 모든 라이브러리를 지원합니다.
|
|
87
|
+
유효하지 않은 입력은 명시적인 `issues`로 보고되어야 하며, 이슈가 없는 검증 결과는 성공으로 처리합니다.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { ValidateClass } from '@fluojs/validation';
|
|
91
|
+
import { z } from 'zod';
|
|
92
|
+
|
|
93
|
+
const UserSchema = z.object({
|
|
94
|
+
age: z.number().min(18),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
@ValidateClass(UserSchema)
|
|
98
|
+
class RestrictedUserDto {
|
|
99
|
+
age: number = 0;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 중첩 검증 (Nested Validation)
|
|
104
|
+
|
|
105
|
+
`@ValidateNested`를 사용하여 복잡한 계층적 데이터 구조를 검증합니다.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { IsString, ValidateNested } from '@fluojs/validation';
|
|
109
|
+
|
|
110
|
+
class ProfileDto {
|
|
111
|
+
@IsString() bio: string = '';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class UserDto {
|
|
115
|
+
@IsString() name: string = '';
|
|
116
|
+
|
|
117
|
+
@ValidateNested(() => ProfileDto)
|
|
118
|
+
profile?: ProfileDto;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 공개 API
|
|
123
|
+
|
|
124
|
+
- **검증 엔진**: `DefaultValidator`, `DtoValidationError`, `ValidationIssue`
|
|
125
|
+
- **핵심 데코레이터**: `IsString`, `IsNumber`, `IsBoolean`, `IsEmail`, `IsUrl`, `ValidateNested`, `ValidateIf`, `IsOptional`, `ValidateClass`
|
|
126
|
+
- **Mapped DTO 헬퍼**: `PickType`, `OmitType`, `PartialType`, `IntersectionType`
|
|
127
|
+
- **검증 흐름**: 실체화 및 검증을 위한 `materialize()`, 단순 검증을 위한 `validate()`
|
|
128
|
+
|
|
129
|
+
## 관련 패키지
|
|
130
|
+
|
|
131
|
+
- `@fluojs/core`: 데코레이터가 사용하는 메타데이터 시스템을 제공합니다.
|
|
132
|
+
- `@fluojs/http`: 이 패키지를 사용하여 들어오는 요청 데이터를 자동으로 검증합니다.
|
|
133
|
+
- `@fluojs/serialization`: **출력** 측면(응답용 DTO 가공)을 담당합니다.
|
|
134
|
+
|
|
135
|
+
## 예제 소스
|
|
136
|
+
|
|
137
|
+
- `packages/validation/src/validation.test.ts`: 모든 데코레이터와 엔진에 대한 종합 테스트.
|
|
138
|
+
- `examples/realworld-api`: 실제 프로덕션과 유사한 환경에서의 DTO 사용 예시.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @fluojs/validation
|
|
2
|
+
|
|
3
|
+
<p><strong><kbd>English</kbd></strong> <a href="./README.ko.md"><kbd>한국어</kbd></a></p>
|
|
4
|
+
|
|
5
|
+
Input-side validation decorators, mapped DTO helpers, and the materialization engine for fluo.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [When to Use](#when-to-use)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Common Patterns](#common-patterns)
|
|
13
|
+
- [Public API](#public-api)
|
|
14
|
+
- [Related Packages](#related-packages)
|
|
15
|
+
- [Example Sources](#example-sources)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @fluojs/validation
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## When to Use
|
|
24
|
+
|
|
25
|
+
- when raw request payloads need to become validated DTO instances before reaching business logic
|
|
26
|
+
- when you want class-based validation rules instead of ad hoc parsing in controllers and services
|
|
27
|
+
- when you need metadata-preserving mapped DTO helpers such as `PickType`, `PartialType`, and `IntersectionType`
|
|
28
|
+
- when you want to attach Standard Schema validators such as Zod or Valibot through `@ValidateClass(...)`
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { DefaultValidator, DtoValidationError, IsEmail, IsString, MinLength } from '@fluojs/validation';
|
|
34
|
+
|
|
35
|
+
class CreateUserDto {
|
|
36
|
+
@IsEmail()
|
|
37
|
+
email = '';
|
|
38
|
+
|
|
39
|
+
@IsString()
|
|
40
|
+
@MinLength(2)
|
|
41
|
+
name = '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const validator = new DefaultValidator();
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const dto = await validator.materialize(
|
|
48
|
+
{ email: 'hello@example.com', name: 'fluo' },
|
|
49
|
+
CreateUserDto,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
console.log(dto instanceof CreateUserDto);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof DtoValidationError) {
|
|
55
|
+
console.log(error.issues);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Common Patterns
|
|
61
|
+
|
|
62
|
+
### `materialize()` vs `validate()`
|
|
63
|
+
|
|
64
|
+
- `materialize(value, Target)` builds a typed instance and validates it recursively
|
|
65
|
+
- `validate(instance, Target)` only validates an already-created value
|
|
66
|
+
|
|
67
|
+
### Mapped DTO helpers
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { IsEmail, IsString, PartialType, PickType } from '@fluojs/validation';
|
|
71
|
+
|
|
72
|
+
class UserDto {
|
|
73
|
+
@IsString() name = '';
|
|
74
|
+
@IsEmail() email = '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
class EmailOnlyDto extends PickType(UserDto, ['email']) {}
|
|
78
|
+
class UpdateUserDto extends PartialType(UserDto) {}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Standard Schema support
|
|
82
|
+
|
|
83
|
+
Standard Schema adapters are expected to report invalid input through explicit issues. Validation results without issues are treated as successful.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { ValidateClass } from '@fluojs/validation';
|
|
87
|
+
import { z } from 'zod';
|
|
88
|
+
|
|
89
|
+
const UserSchema = z.object({ age: z.number().min(18) });
|
|
90
|
+
|
|
91
|
+
@ValidateClass(UserSchema)
|
|
92
|
+
class RestrictedUserDto {
|
|
93
|
+
age = 0;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### No implicit scalar coercion
|
|
98
|
+
|
|
99
|
+
`materialize()` is intentionally strict. If a transport gives you `'42'` and your DTO expects `number`, the transport or binding layer must convert it first.
|
|
100
|
+
|
|
101
|
+
## Public API
|
|
102
|
+
|
|
103
|
+
- **Validator engine**: `DefaultValidator`, `DtoValidationError`, `ValidationIssue`
|
|
104
|
+
- **Core decorators**: `IsString`, `IsNumber`, `IsBoolean`, `IsEmail`, `IsUrl`, `ValidateNested`, `ValidateIf`, `IsOptional`, `ValidateClass`
|
|
105
|
+
- **Mapped DTO helpers**: `PickType`, `OmitType`, `PartialType`, `IntersectionType`
|
|
106
|
+
- **Validation flow**: `materialize()` for hydration + validation, `validate()` for validation-only checks
|
|
107
|
+
|
|
108
|
+
## Related Packages
|
|
109
|
+
|
|
110
|
+
- `@fluojs/http`: binds request data, then uses this package to validate it
|
|
111
|
+
- `@fluojs/serialization`: shapes output DTOs on the response side
|
|
112
|
+
- `@fluojs/core`: provides the metadata primitives used by validation decorators
|
|
113
|
+
|
|
114
|
+
## Example Sources
|
|
115
|
+
|
|
116
|
+
- `packages/validation/src/validation.test.ts`
|
|
117
|
+
- `examples/realworld-api/src/users/create-user.dto.ts`
|
|
118
|
+
- `examples/auth-jwt-passport/src/auth/login.dto.ts`
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type Constructor } from '@fluojs/core';
|
|
2
|
+
import { type CustomClassValidator, type CustomFieldValidator, type CustomValidationDecoratorOptions, type ValidationDecoratorOptions } from '@fluojs/core/internal';
|
|
3
|
+
import { type StandardSchemaV1Like } from './standard-schema.js';
|
|
4
|
+
type ClassDecoratorFn = (value: Function, context: ClassDecoratorContext) => void;
|
|
5
|
+
type FieldDecoratorFn = <This, Value>(value: undefined, context: ClassFieldDecoratorContext<This, Value>) => void;
|
|
6
|
+
type ValidateClassInput = CustomClassValidator | StandardSchemaV1Like;
|
|
7
|
+
/**
|
|
8
|
+
* Validates that the decorated field is a string value.
|
|
9
|
+
*
|
|
10
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
11
|
+
* @returns A field decorator that registers a string validation rule.
|
|
12
|
+
*/
|
|
13
|
+
export declare function IsString(options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
14
|
+
/**
|
|
15
|
+
* Validates that the decorated field is a number value.
|
|
16
|
+
*
|
|
17
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
18
|
+
* @returns A field decorator that registers a number validation rule.
|
|
19
|
+
*/
|
|
20
|
+
export declare function IsNumber(options?: ValidationDecoratorOptions & {
|
|
21
|
+
allowNaN?: boolean;
|
|
22
|
+
}): FieldDecoratorFn;
|
|
23
|
+
/**
|
|
24
|
+
* Validates that the decorated field is a boolean value.
|
|
25
|
+
*
|
|
26
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
27
|
+
* @returns A field decorator that registers a boolean validation rule.
|
|
28
|
+
*/
|
|
29
|
+
export declare function IsBoolean(options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
30
|
+
/**
|
|
31
|
+
* Applies subsequent validators only when the condition returns `true`.
|
|
32
|
+
*
|
|
33
|
+
* @param validateIf Predicate that decides whether subsequent validators should run.
|
|
34
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
35
|
+
* @returns A field decorator that adds conditional validation execution.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ValidateIf: (validateIf: (dto: unknown, value: unknown) => boolean | Promise<boolean>, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
38
|
+
export declare const IsDefined: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
39
|
+
export declare const IsOptional: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
40
|
+
export declare const Equals: (value: unknown, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
41
|
+
export declare const NotEquals: (value: unknown, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
42
|
+
export declare const IsEmpty: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
43
|
+
export declare const IsNotEmpty: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
44
|
+
export declare const IsIn: (values: readonly unknown[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
45
|
+
export declare const IsNotIn: (values: readonly unknown[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
46
|
+
export declare const IsDate: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
47
|
+
export declare const IsArray: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
48
|
+
export declare const IsObject: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
49
|
+
export declare const IsInt: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
50
|
+
export declare const IsPositive: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
51
|
+
export declare const IsNegative: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
52
|
+
/**
|
|
53
|
+
* Validates that the field value is included in the given enum-like set.
|
|
54
|
+
*
|
|
55
|
+
* @param values Enum object or literal value list that defines the accepted set.
|
|
56
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
57
|
+
* @returns A field decorator that registers an enum-membership rule.
|
|
58
|
+
*/
|
|
59
|
+
export declare function IsEnum(values: Record<string, unknown> | readonly unknown[], options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
60
|
+
export declare const IsDivisibleBy: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
61
|
+
export declare const Min: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
62
|
+
export declare const Max: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
63
|
+
export declare const MinDate: (value: Date, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
64
|
+
export declare const MaxDate: (value: Date, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
65
|
+
export declare const Contains: (value: string, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
66
|
+
export declare const NotContains: (value: string, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
67
|
+
/**
|
|
68
|
+
* Validates string length using optional min/max boundaries.
|
|
69
|
+
*
|
|
70
|
+
* @param min Minimum inclusive length.
|
|
71
|
+
* @param max Optional maximum inclusive length.
|
|
72
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
73
|
+
* @returns A field decorator that registers a bounded-length rule.
|
|
74
|
+
*/
|
|
75
|
+
export declare function Length(min: number, max?: number, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
76
|
+
/**
|
|
77
|
+
* Validates a nested DTO instance using the provided constructor.
|
|
78
|
+
*
|
|
79
|
+
* @param dto DTO constructor (or lazy constructor factory) used for nested validation/materialization.
|
|
80
|
+
* @param options Optional validation behavior (`message`, `groups`, `always`, `each`).
|
|
81
|
+
* @returns A field decorator that registers recursive nested DTO validation.
|
|
82
|
+
*/
|
|
83
|
+
export declare function ValidateNested(dto: Constructor | (() => Constructor), options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
84
|
+
export declare const MinLength: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
85
|
+
export declare const MaxLength: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
86
|
+
/**
|
|
87
|
+
* Validates the field using a regular expression pattern.
|
|
88
|
+
*
|
|
89
|
+
* @param pattern Pattern source (`RegExp` or string) passed to validator.js `matches`.
|
|
90
|
+
* @param modifiersOrOptions Regex modifiers string (for string patterns) or validation options.
|
|
91
|
+
* @param options Validation options used when modifiers are provided separately.
|
|
92
|
+
* @returns A field decorator that registers a regex-matching rule.
|
|
93
|
+
*/
|
|
94
|
+
export declare function Matches(pattern: RegExp | string, modifiersOrOptions?: string | ValidationDecoratorOptions, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
95
|
+
export declare const IsAlpha: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
96
|
+
export declare const IsAlphanumeric: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
97
|
+
export declare const IsAscii: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
98
|
+
export declare const IsBase64: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
99
|
+
export declare const IsBooleanString: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
100
|
+
export declare const IsDataURI: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
101
|
+
export declare const IsDateString: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
102
|
+
export declare const IsDecimal: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
103
|
+
export declare const IsEmail: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
104
|
+
export declare const IsFQDN: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
105
|
+
export declare const IsHexColor: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
106
|
+
export declare const IsHexadecimal: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
107
|
+
export declare const IsJSON: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
108
|
+
export declare const IsJWT: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
109
|
+
export declare const IsLocale: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
110
|
+
export declare const IsLowercase: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
111
|
+
export declare const IsMagnetURI: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
112
|
+
export declare const IsMimeType: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
113
|
+
export declare const IsMongoId: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
114
|
+
export declare const IsNumberString: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
115
|
+
export declare const IsPort: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
116
|
+
export declare const IsRFC3339: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
117
|
+
export declare const IsSemVer: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
118
|
+
export declare const IsUppercase: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
119
|
+
export declare const IsISO8601: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
120
|
+
export declare const IsLatitude: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
121
|
+
export declare const IsLongitude: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
122
|
+
export declare const IsLatLong: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
123
|
+
/** Validates that a value is an IPv4/IPv6 address. */
|
|
124
|
+
export declare function IsIP(version?: '4' | '6' | '4_or_6', options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
125
|
+
/** Validates that a value is an ISBN string. */
|
|
126
|
+
export declare function IsISBN(version?: 10 | 13, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
127
|
+
export declare function IsISSN(options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
128
|
+
export declare function IsMobilePhone(locale?: string | readonly string[], options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
129
|
+
export declare function IsPostalCode(locale?: string, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
130
|
+
export declare function IsRgbColor(includePercentValues?: boolean, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
131
|
+
export declare function IsUrl(options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
132
|
+
export declare function IsUUID(version?: '3' | '4' | '5' | 'all', options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
133
|
+
export declare function IsCurrency(options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
134
|
+
export declare const ArrayContains: (values: readonly unknown[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
135
|
+
export declare const ArrayNotContains: (values: readonly unknown[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
136
|
+
export declare const ArrayNotEmpty: (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
137
|
+
export declare const ArrayMinSize: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
138
|
+
export declare const ArrayMaxSize: (value: number, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
139
|
+
/**
|
|
140
|
+
* Ensures all values in the array are unique, optionally by selector.
|
|
141
|
+
*
|
|
142
|
+
* @param selectorOrOptions Optional selector callback used to compute uniqueness keys, or validation options.
|
|
143
|
+
* @param options Validation options used when a selector callback is provided.
|
|
144
|
+
* @returns A field decorator that registers an array-uniqueness rule.
|
|
145
|
+
*/
|
|
146
|
+
export declare function ArrayUnique(selectorOrOptions?: ((value: unknown) => unknown) | ValidationDecoratorOptions, options?: ValidationDecoratorOptions): FieldDecoratorFn;
|
|
147
|
+
/**
|
|
148
|
+
* Registers a custom field-level validation function.
|
|
149
|
+
*
|
|
150
|
+
* @param validate Custom validator callback invoked with `(dto, value)`.
|
|
151
|
+
* @param options Optional custom-validator metadata (`message`, `code`, `source`, `each`).
|
|
152
|
+
* @returns A field decorator that registers a custom validation rule.
|
|
153
|
+
*/
|
|
154
|
+
export declare function Validate(validate: CustomFieldValidator, options?: CustomValidationDecoratorOptions): FieldDecoratorFn;
|
|
155
|
+
/**
|
|
156
|
+
* Registers class-level validation logic.
|
|
157
|
+
* Supports either a custom validator callback or a Standard Schema object.
|
|
158
|
+
*
|
|
159
|
+
* @param validate Class-level validator callback or a Standard Schema-compatible validator definition.
|
|
160
|
+
* @param options Optional validation behavior (`message`, `code`).
|
|
161
|
+
* @returns A class decorator that appends class-level validation rules.
|
|
162
|
+
*/
|
|
163
|
+
export declare function ValidateClass(validate: ValidateClassInput, options?: ValidationDecoratorOptions): ClassDecoratorFn;
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,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