@fluojs/validation 1.0.5 → 2.0.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/README.ko.md +47 -1
- package/README.md +48 -1
- package/dist/decorators.d.ts +71 -69
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +73 -133
- package/dist/internal/decorator-factories.d.ts +12 -0
- package/dist/internal/decorator-factories.d.ts.map +1 -0
- package/dist/internal/decorator-factories.js +32 -0
- package/dist/internal/decorator-metadata.d.ts +7 -0
- package/dist/internal/decorator-metadata.d.ts.map +1 -0
- package/dist/internal/decorator-metadata.js +38 -0
- package/dist/internal/dto-materialization.d.ts +45 -0
- package/dist/internal/dto-materialization.d.ts.map +1 -0
- package/dist/internal/dto-materialization.js +204 -0
- package/dist/internal/dto-metadata-cache.d.ts +17 -0
- package/dist/internal/dto-metadata-cache.d.ts.map +1 -0
- package/dist/internal/dto-metadata-cache.js +49 -0
- package/dist/internal/enum-values.d.ts +2 -0
- package/dist/internal/enum-values.d.ts.map +1 -0
- package/dist/internal/enum-values.js +16 -0
- package/dist/internal/object-utils.d.ts +30 -0
- package/dist/internal/object-utils.d.ts.map +1 -0
- package/dist/internal/object-utils.js +53 -0
- package/dist/internal/rule-handlers.d.ts +19 -0
- package/dist/internal/rule-handlers.d.ts.map +1 -0
- package/dist/internal/rule-handlers.js +209 -0
- package/dist/internal/validation-issues.d.ts +13 -0
- package/dist/internal/validation-issues.d.ts.map +1 -0
- package/dist/internal/validation-issues.js +44 -0
- package/dist/internal/validator-js-adapter.d.ts +5 -0
- package/dist/internal/validator-js-adapter.d.ts.map +1 -0
- package/dist/internal/validator-js-adapter.js +88 -0
- package/dist/mapped-types.d.ts +1 -1
- package/dist/mapped-types.d.ts.map +1 -1
- package/dist/mapped-types.js +1 -1
- package/dist/standard-schema.d.ts +1 -1
- package/dist/standard-schema.d.ts.map +1 -1
- package/dist/types.d.ts +18 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +2 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +24 -509
- package/package.json +4 -4
package/dist/decorators.js
CHANGED
|
@@ -1,81 +1,18 @@
|
|
|
1
|
+
import { createArrayValidationDecorator, createFlagValidationDecorator, createValidationDecorator, createValidationOptionsWithConfigDecorator, createValidatorJsDecorator } from './internal/decorator-factories.js';
|
|
2
|
+
import { appendStandardClassValidationRule } from './internal/decorator-metadata.js';
|
|
3
|
+
import { normalizeEnumValues } from './internal/enum-values.js';
|
|
1
4
|
import { createClassValidatorFromStandardSchema, isStandardSchemaLike } from './standard-schema.js';
|
|
2
|
-
const standardDtoValidationMetadataKey = Symbol.for('fluo.standard.dto-validation');
|
|
3
|
-
const standardClassValidationMetadataKey = Symbol.for('fluo.standard.class-validation');
|
|
4
|
-
function getStandardMetadataBag(metadata) {
|
|
5
|
-
if (metadata === null || metadata === undefined) {
|
|
6
|
-
throw new Error('Decorator metadata is not available. Ensure your environment supports TC39 decorator metadata (Stage 3).');
|
|
7
|
-
}
|
|
8
|
-
return metadata;
|
|
9
|
-
}
|
|
10
|
-
function getStandardDtoValidationMap(metadata) {
|
|
11
|
-
const bag = getStandardMetadataBag(metadata);
|
|
12
|
-
const current = bag[standardDtoValidationMetadataKey];
|
|
13
|
-
if (current) {
|
|
14
|
-
return current;
|
|
15
|
-
}
|
|
16
|
-
const created = new Map();
|
|
17
|
-
bag[standardDtoValidationMetadataKey] = created;
|
|
18
|
-
return created;
|
|
19
|
-
}
|
|
20
|
-
function getStandardClassValidationList(metadata) {
|
|
21
|
-
const bag = getStandardMetadataBag(metadata);
|
|
22
|
-
const current = bag[standardClassValidationMetadataKey];
|
|
23
|
-
if (current) {
|
|
24
|
-
return current;
|
|
25
|
-
}
|
|
26
|
-
const created = [];
|
|
27
|
-
bag[standardClassValidationMetadataKey] = created;
|
|
28
|
-
return created;
|
|
29
|
-
}
|
|
30
|
-
function appendStandardDtoValidationRule(metadata, propertyKey, rule) {
|
|
31
|
-
const map = getStandardDtoValidationMap(metadata);
|
|
32
|
-
map.set(propertyKey, [...(map.get(propertyKey) ?? []), rule]);
|
|
33
|
-
}
|
|
34
|
-
function appendStandardClassValidationRule(metadata, rule) {
|
|
35
|
-
getStandardClassValidationList(metadata).push(rule);
|
|
36
|
-
}
|
|
37
5
|
function resolveClassValidator(validate) {
|
|
38
6
|
if (!isStandardSchemaLike(validate)) {
|
|
39
7
|
return validate;
|
|
40
8
|
}
|
|
41
9
|
return createClassValidatorFromStandardSchema(validate);
|
|
42
10
|
}
|
|
43
|
-
function createValidationDecorator(ruleFactory) {
|
|
44
|
-
const decorator = (_value, context) => {
|
|
45
|
-
appendStandardDtoValidationRule(context.metadata, context.name, ruleFactory());
|
|
46
|
-
};
|
|
47
|
-
return decorator;
|
|
48
|
-
}
|
|
49
|
-
function createValidationOptionsWithConfigDecorator(ruleFactory) {
|
|
50
|
-
return (value, options) => {
|
|
51
|
-
return createValidationDecorator(() => ruleFactory(value, options));
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function createFlagValidationDecorator(ruleFactory) {
|
|
55
|
-
return options => {
|
|
56
|
-
return createValidationDecorator(() => ruleFactory(options));
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function createArrayValidationDecorator(ruleFactory) {
|
|
60
|
-
return (values, options) => {
|
|
61
|
-
return createValidationDecorator(() => ruleFactory(values, options));
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function createValidatorJsDecorator(validator) {
|
|
65
|
-
return (args, options) => {
|
|
66
|
-
return createValidationDecorator(() => ({
|
|
67
|
-
args,
|
|
68
|
-
kind: 'validatorjs',
|
|
69
|
-
validator,
|
|
70
|
-
...options
|
|
71
|
-
}));
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
11
|
|
|
75
12
|
/**
|
|
76
13
|
* Validates that the decorated field is a string value.
|
|
77
14
|
*
|
|
78
|
-
* @param options Optional validation behavior (`message`, `
|
|
15
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
79
16
|
* @returns A field decorator that registers a string validation rule.
|
|
80
17
|
*/
|
|
81
18
|
export function IsString(options) {
|
|
@@ -88,7 +25,7 @@ export function IsString(options) {
|
|
|
88
25
|
/**
|
|
89
26
|
* Validates that the decorated field is a number value.
|
|
90
27
|
*
|
|
91
|
-
* @param options Optional validation behavior (`message`, `
|
|
28
|
+
* @param options Optional validation behavior (`message`, `code`, `each`, `allowNaN`).
|
|
92
29
|
* @returns A field decorator that registers a number validation rule.
|
|
93
30
|
*/
|
|
94
31
|
export function IsNumber(options) {
|
|
@@ -101,7 +38,7 @@ export function IsNumber(options) {
|
|
|
101
38
|
/**
|
|
102
39
|
* Validates that the decorated field is a boolean value.
|
|
103
40
|
*
|
|
104
|
-
* @param options Optional validation behavior (`message`, `
|
|
41
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
105
42
|
* @returns A field decorator that registers a boolean validation rule.
|
|
106
43
|
*/
|
|
107
44
|
export function IsBoolean(options) {
|
|
@@ -115,7 +52,7 @@ export function IsBoolean(options) {
|
|
|
115
52
|
* Applies subsequent validators only when the condition returns `true`.
|
|
116
53
|
*
|
|
117
54
|
* @param validateIf Predicate that decides whether subsequent validators should run.
|
|
118
|
-
* @param options Optional validation behavior (`message`, `
|
|
55
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
119
56
|
* @returns A field decorator that adds conditional validation execution.
|
|
120
57
|
*/
|
|
121
58
|
export const ValidateIf = (validateIf, options) => createValidationDecorator(() => ({
|
|
@@ -127,7 +64,7 @@ export const ValidateIf = (validateIf, options) => createValidationDecorator(()
|
|
|
127
64
|
/**
|
|
128
65
|
* Validates that the decorated field is neither `null` nor `undefined`.
|
|
129
66
|
*
|
|
130
|
-
* @param options Optional validation behavior (`message`, `
|
|
67
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
131
68
|
* @returns A field decorator that registers a required-value rule.
|
|
132
69
|
*/
|
|
133
70
|
export const IsDefined = createFlagValidationDecorator(options => ({
|
|
@@ -137,7 +74,7 @@ export const IsDefined = createFlagValidationDecorator(options => ({
|
|
|
137
74
|
/**
|
|
138
75
|
* Skips subsequent validators when the decorated field is `null` or `undefined`.
|
|
139
76
|
*
|
|
140
|
-
* @param options Optional validation behavior (`message`, `
|
|
77
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
141
78
|
* @returns A field decorator that registers optional-value semantics.
|
|
142
79
|
*/
|
|
143
80
|
export const IsOptional = createFlagValidationDecorator(options => ({
|
|
@@ -148,7 +85,7 @@ export const IsOptional = createFlagValidationDecorator(options => ({
|
|
|
148
85
|
* Validates that the decorated field strictly equals the expected value.
|
|
149
86
|
*
|
|
150
87
|
* @param value Expected value to compare against the field value.
|
|
151
|
-
* @param options Optional validation behavior (`message`, `
|
|
88
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
152
89
|
* @returns A field decorator that registers an equality rule.
|
|
153
90
|
*/
|
|
154
91
|
export const Equals = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -160,7 +97,7 @@ export const Equals = createValidationOptionsWithConfigDecorator((value, options
|
|
|
160
97
|
* Validates that the decorated field does not strictly equal the forbidden value.
|
|
161
98
|
*
|
|
162
99
|
* @param value Forbidden value to compare against the field value.
|
|
163
|
-
* @param options Optional validation behavior (`message`, `
|
|
100
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
164
101
|
* @returns A field decorator that registers an inequality rule.
|
|
165
102
|
*/
|
|
166
103
|
export const NotEquals = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -171,7 +108,7 @@ export const NotEquals = createValidationOptionsWithConfigDecorator((value, opti
|
|
|
171
108
|
/**
|
|
172
109
|
* Validates that the decorated field is empty.
|
|
173
110
|
*
|
|
174
|
-
* @param options Optional validation behavior (`message`, `
|
|
111
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
175
112
|
* @returns A field decorator that registers an empty-value rule.
|
|
176
113
|
*/
|
|
177
114
|
export const IsEmpty = createFlagValidationDecorator(options => ({
|
|
@@ -181,7 +118,7 @@ export const IsEmpty = createFlagValidationDecorator(options => ({
|
|
|
181
118
|
/**
|
|
182
119
|
* Validates that the decorated field is not empty.
|
|
183
120
|
*
|
|
184
|
-
* @param options Optional validation behavior (`message`, `
|
|
121
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
185
122
|
* @returns A field decorator that registers a non-empty-value rule.
|
|
186
123
|
*/
|
|
187
124
|
export const IsNotEmpty = createFlagValidationDecorator(options => ({
|
|
@@ -192,7 +129,7 @@ export const IsNotEmpty = createFlagValidationDecorator(options => ({
|
|
|
192
129
|
* Validates that the decorated field is included in the accepted values.
|
|
193
130
|
*
|
|
194
131
|
* @param values Accepted values for the field.
|
|
195
|
-
* @param options Optional validation behavior (`message`, `
|
|
132
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
196
133
|
* @returns A field decorator that registers an inclusion rule.
|
|
197
134
|
*/
|
|
198
135
|
export const IsIn = createArrayValidationDecorator((values, options) => ({
|
|
@@ -204,7 +141,7 @@ export const IsIn = createArrayValidationDecorator((values, options) => ({
|
|
|
204
141
|
* Validates that the decorated field is not included in the rejected values.
|
|
205
142
|
*
|
|
206
143
|
* @param values Rejected values for the field.
|
|
207
|
-
* @param options Optional validation behavior (`message`, `
|
|
144
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
208
145
|
* @returns A field decorator that registers an exclusion rule.
|
|
209
146
|
*/
|
|
210
147
|
export const IsNotIn = createArrayValidationDecorator((values, options) => ({
|
|
@@ -215,7 +152,7 @@ export const IsNotIn = createArrayValidationDecorator((values, options) => ({
|
|
|
215
152
|
/**
|
|
216
153
|
* Validates that the decorated field is a `Date` value.
|
|
217
154
|
*
|
|
218
|
-
* @param options Optional validation behavior (`message`, `
|
|
155
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
219
156
|
* @returns A field decorator that registers a date validation rule.
|
|
220
157
|
*/
|
|
221
158
|
export const IsDate = createFlagValidationDecorator(options => ({
|
|
@@ -225,7 +162,7 @@ export const IsDate = createFlagValidationDecorator(options => ({
|
|
|
225
162
|
/**
|
|
226
163
|
* Validates that the decorated field is an array.
|
|
227
164
|
*
|
|
228
|
-
* @param options Optional validation behavior (`message`, `
|
|
165
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
229
166
|
* @returns A field decorator that registers an array validation rule.
|
|
230
167
|
*/
|
|
231
168
|
export const IsArray = createFlagValidationDecorator(options => ({
|
|
@@ -233,9 +170,10 @@ export const IsArray = createFlagValidationDecorator(options => ({
|
|
|
233
170
|
...options
|
|
234
171
|
}));
|
|
235
172
|
/**
|
|
236
|
-
* Validates that the decorated field is
|
|
173
|
+
* Validates that the decorated field is a plain object value, including a null-prototype record.
|
|
174
|
+
* Class instances, `Date`, `Map`, and `Set` values are rejected.
|
|
237
175
|
*
|
|
238
|
-
* @param options Optional validation behavior (`message`, `
|
|
176
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
239
177
|
* @returns A field decorator that registers an object validation rule.
|
|
240
178
|
*/
|
|
241
179
|
export const IsObject = createFlagValidationDecorator(options => ({
|
|
@@ -245,7 +183,7 @@ export const IsObject = createFlagValidationDecorator(options => ({
|
|
|
245
183
|
/**
|
|
246
184
|
* Validates that the decorated field is an integer.
|
|
247
185
|
*
|
|
248
|
-
* @param options Optional validation behavior (`message`, `
|
|
186
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
249
187
|
* @returns A field decorator that registers an integer validation rule.
|
|
250
188
|
*/
|
|
251
189
|
export const IsInt = createFlagValidationDecorator(options => ({
|
|
@@ -255,7 +193,7 @@ export const IsInt = createFlagValidationDecorator(options => ({
|
|
|
255
193
|
/**
|
|
256
194
|
* Validates that the decorated field is a positive number.
|
|
257
195
|
*
|
|
258
|
-
* @param options Optional validation behavior (`message`, `
|
|
196
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
259
197
|
* @returns A field decorator that registers a positive-number rule.
|
|
260
198
|
*/
|
|
261
199
|
export const IsPositive = createFlagValidationDecorator(options => ({
|
|
@@ -265,7 +203,7 @@ export const IsPositive = createFlagValidationDecorator(options => ({
|
|
|
265
203
|
/**
|
|
266
204
|
* Validates that the decorated field is a negative number.
|
|
267
205
|
*
|
|
268
|
-
* @param options Optional validation behavior (`message`, `
|
|
206
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
269
207
|
* @returns A field decorator that registers a negative-number rule.
|
|
270
208
|
*/
|
|
271
209
|
export const IsNegative = createFlagValidationDecorator(options => ({
|
|
@@ -277,11 +215,11 @@ export const IsNegative = createFlagValidationDecorator(options => ({
|
|
|
277
215
|
* Validates that the field value is included in the given enum-like set.
|
|
278
216
|
*
|
|
279
217
|
* @param values Enum object or literal value list that defines the accepted set.
|
|
280
|
-
* @param options Optional validation behavior (`message`, `
|
|
218
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
281
219
|
* @returns A field decorator that registers an enum-membership rule.
|
|
282
220
|
*/
|
|
283
221
|
export function IsEnum(values, options) {
|
|
284
|
-
const normalized =
|
|
222
|
+
const normalized = normalizeEnumValues(values);
|
|
285
223
|
return createValidationDecorator(() => ({
|
|
286
224
|
kind: 'enum',
|
|
287
225
|
values: normalized,
|
|
@@ -293,7 +231,7 @@ export function IsEnum(values, options) {
|
|
|
293
231
|
* Validates that the decorated field is divisible by the given divisor.
|
|
294
232
|
*
|
|
295
233
|
* @param value Divisor used for the numeric divisibility check.
|
|
296
|
-
* @param options Optional validation behavior (`message`, `
|
|
234
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
297
235
|
* @returns A field decorator that registers a divisibility rule.
|
|
298
236
|
*/
|
|
299
237
|
export const IsDivisibleBy = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -305,7 +243,7 @@ export const IsDivisibleBy = createValidationOptionsWithConfigDecorator((value,
|
|
|
305
243
|
* Validates that the decorated field is greater than or equal to the minimum.
|
|
306
244
|
*
|
|
307
245
|
* @param value Inclusive minimum allowed numeric value.
|
|
308
|
-
* @param options Optional validation behavior (`message`, `
|
|
246
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
309
247
|
* @returns A field decorator that registers a minimum-value rule.
|
|
310
248
|
*/
|
|
311
249
|
export const Min = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -317,7 +255,7 @@ export const Min = createValidationOptionsWithConfigDecorator((value, options) =
|
|
|
317
255
|
* Validates that the decorated field is less than or equal to the maximum.
|
|
318
256
|
*
|
|
319
257
|
* @param value Inclusive maximum allowed numeric value.
|
|
320
|
-
* @param options Optional validation behavior (`message`, `
|
|
258
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
321
259
|
* @returns A field decorator that registers a maximum-value rule.
|
|
322
260
|
*/
|
|
323
261
|
export const Max = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -329,7 +267,7 @@ export const Max = createValidationOptionsWithConfigDecorator((value, options) =
|
|
|
329
267
|
* Validates that the decorated field is on or after the minimum date.
|
|
330
268
|
*
|
|
331
269
|
* @param value Inclusive minimum allowed date.
|
|
332
|
-
* @param options Optional validation behavior (`message`, `
|
|
270
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
333
271
|
* @returns A field decorator that registers a minimum-date rule.
|
|
334
272
|
*/
|
|
335
273
|
export const MinDate = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -341,7 +279,7 @@ export const MinDate = createValidationOptionsWithConfigDecorator((value, option
|
|
|
341
279
|
* Validates that the decorated field is on or before the maximum date.
|
|
342
280
|
*
|
|
343
281
|
* @param value Inclusive maximum allowed date.
|
|
344
|
-
* @param options Optional validation behavior (`message`, `
|
|
282
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
345
283
|
* @returns A field decorator that registers a maximum-date rule.
|
|
346
284
|
*/
|
|
347
285
|
export const MaxDate = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -353,7 +291,7 @@ export const MaxDate = createValidationOptionsWithConfigDecorator((value, option
|
|
|
353
291
|
* Validates that the decorated field contains the required substring.
|
|
354
292
|
*
|
|
355
293
|
* @param value Required substring.
|
|
356
|
-
* @param options Optional validation behavior (`message`, `
|
|
294
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
357
295
|
* @returns A field decorator that registers a substring-presence rule.
|
|
358
296
|
*/
|
|
359
297
|
export const Contains = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -365,7 +303,7 @@ export const Contains = createValidationOptionsWithConfigDecorator((value, optio
|
|
|
365
303
|
* Validates that the decorated field does not contain the forbidden substring.
|
|
366
304
|
*
|
|
367
305
|
* @param value Forbidden substring.
|
|
368
|
-
* @param options Optional validation behavior (`message`, `
|
|
306
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
369
307
|
* @returns A field decorator that registers a substring-exclusion rule.
|
|
370
308
|
*/
|
|
371
309
|
export const NotContains = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -379,7 +317,7 @@ export const NotContains = createValidationOptionsWithConfigDecorator((value, op
|
|
|
379
317
|
*
|
|
380
318
|
* @param min Minimum inclusive length.
|
|
381
319
|
* @param max Optional maximum inclusive length.
|
|
382
|
-
* @param options Optional validation behavior (`message`, `
|
|
320
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
383
321
|
* @returns A field decorator that registers a bounded-length rule.
|
|
384
322
|
*/
|
|
385
323
|
export function Length(min, max, options) {
|
|
@@ -393,9 +331,10 @@ export function Length(min, max, options) {
|
|
|
393
331
|
|
|
394
332
|
/**
|
|
395
333
|
* Validates a nested DTO instance using the provided constructor.
|
|
334
|
+
* Arrays, Sets, and Maps are traversed automatically without requiring `each`.
|
|
396
335
|
*
|
|
397
336
|
* @param dto DTO constructor (or lazy constructor factory) used for nested validation/materialization.
|
|
398
|
-
* @param options Optional validation behavior (`message`, `
|
|
337
|
+
* @param options Optional validation behavior (`message`, `code`, `each`); collection traversal is automatic.
|
|
399
338
|
* @returns A field decorator that registers recursive nested DTO validation.
|
|
400
339
|
*/
|
|
401
340
|
export function ValidateNested(dto, options) {
|
|
@@ -410,7 +349,7 @@ export function ValidateNested(dto, options) {
|
|
|
410
349
|
* Validates that the decorated field has at least the given length.
|
|
411
350
|
*
|
|
412
351
|
* @param value Inclusive minimum string length.
|
|
413
|
-
* @param options Optional validation behavior (`message`, `
|
|
352
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
414
353
|
* @returns A field decorator that registers a minimum-length rule.
|
|
415
354
|
*/
|
|
416
355
|
export const MinLength = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -422,7 +361,7 @@ export const MinLength = createValidationOptionsWithConfigDecorator((value, opti
|
|
|
422
361
|
* Validates that the decorated field has at most the given length.
|
|
423
362
|
*
|
|
424
363
|
* @param value Inclusive maximum string length.
|
|
425
|
-
* @param options Optional validation behavior (`message`, `
|
|
364
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
426
365
|
* @returns A field decorator that registers a maximum-length rule.
|
|
427
366
|
*/
|
|
428
367
|
export const MaxLength = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -460,196 +399,196 @@ export function Matches(pattern, modifiersOrOptions, options) {
|
|
|
460
399
|
/**
|
|
461
400
|
* Validates that the decorated field contains only alphabetic characters.
|
|
462
401
|
*
|
|
463
|
-
* @param options Optional validation behavior (`message`, `
|
|
402
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
464
403
|
* @returns A field decorator that registers an alphabetic string rule.
|
|
465
404
|
*/
|
|
466
405
|
export const IsAlpha = options => createValidatorJsDecorator('alpha')(undefined, options);
|
|
467
406
|
/**
|
|
468
407
|
* Validates that the decorated field contains only alphanumeric characters.
|
|
469
408
|
*
|
|
470
|
-
* @param options Optional validation behavior (`message`, `
|
|
409
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
471
410
|
* @returns A field decorator that registers an alphanumeric string rule.
|
|
472
411
|
*/
|
|
473
412
|
export const IsAlphanumeric = options => createValidatorJsDecorator('alphanumeric')(undefined, options);
|
|
474
413
|
/**
|
|
475
414
|
* Validates that the decorated field contains only ASCII characters.
|
|
476
415
|
*
|
|
477
|
-
* @param options Optional validation behavior (`message`, `
|
|
416
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
478
417
|
* @returns A field decorator that registers an ASCII string rule.
|
|
479
418
|
*/
|
|
480
419
|
export const IsAscii = options => createValidatorJsDecorator('ascii')(undefined, options);
|
|
481
420
|
/**
|
|
482
421
|
* Validates that the decorated field is a Base64 string.
|
|
483
422
|
*
|
|
484
|
-
* @param options Optional validation behavior (`message`, `
|
|
423
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
485
424
|
* @returns A field decorator that registers a Base64 string rule.
|
|
486
425
|
*/
|
|
487
426
|
export const IsBase64 = options => createValidatorJsDecorator('base64')(undefined, options);
|
|
488
427
|
/**
|
|
489
428
|
* Validates that the decorated field is a boolean-like string.
|
|
490
429
|
*
|
|
491
|
-
* @param options Optional validation behavior (`message`, `
|
|
430
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
492
431
|
* @returns A field decorator that registers a boolean-string rule.
|
|
493
432
|
*/
|
|
494
433
|
export const IsBooleanString = options => createValidatorJsDecorator('booleanString')(undefined, options);
|
|
495
434
|
/**
|
|
496
435
|
* Validates that the decorated field is a data URI string.
|
|
497
436
|
*
|
|
498
|
-
* @param options Optional validation behavior (`message`, `
|
|
437
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
499
438
|
* @returns A field decorator that registers a data URI rule.
|
|
500
439
|
*/
|
|
501
440
|
export const IsDataURI = options => createValidatorJsDecorator('dataURI')(undefined, options);
|
|
502
441
|
/**
|
|
503
442
|
* Validates that the decorated field is a date string.
|
|
504
443
|
*
|
|
505
|
-
* @param options Optional validation behavior (`message`, `
|
|
444
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
506
445
|
* @returns A field decorator that registers a date-string rule.
|
|
507
446
|
*/
|
|
508
447
|
export const IsDateString = options => createValidatorJsDecorator('dateString')(undefined, options);
|
|
509
448
|
/**
|
|
510
449
|
* Validates that the decorated field is a decimal string.
|
|
511
450
|
*
|
|
512
|
-
* @param options Optional validation behavior (`message`, `
|
|
451
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
513
452
|
* @returns A field decorator that registers a decimal-string rule.
|
|
514
453
|
*/
|
|
515
454
|
export const IsDecimal = options => createValidatorJsDecorator('decimal')(undefined, options);
|
|
516
455
|
/**
|
|
517
456
|
* Validates that the decorated field is an email address.
|
|
518
457
|
*
|
|
519
|
-
* @param options Optional validation behavior (`message`, `
|
|
458
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
520
459
|
* @returns A field decorator that registers an email-address rule.
|
|
521
460
|
*/
|
|
522
461
|
export const IsEmail = options => createValidatorJsDecorator('email')(undefined, options);
|
|
523
462
|
/**
|
|
524
463
|
* Validates that the decorated field is a fully qualified domain name.
|
|
525
464
|
*
|
|
526
|
-
* @param options Optional validation behavior (`message`, `
|
|
465
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
527
466
|
* @returns A field decorator that registers an FQDN rule.
|
|
528
467
|
*/
|
|
529
468
|
export const IsFQDN = options => createValidatorJsDecorator('fqdn')(undefined, options);
|
|
530
469
|
/**
|
|
531
470
|
* Validates that the decorated field is a hexadecimal color string.
|
|
532
471
|
*
|
|
533
|
-
* @param options Optional validation behavior (`message`, `
|
|
472
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
534
473
|
* @returns A field decorator that registers a hex-color rule.
|
|
535
474
|
*/
|
|
536
475
|
export const IsHexColor = options => createValidatorJsDecorator('hexColor')(undefined, options);
|
|
537
476
|
/**
|
|
538
477
|
* Validates that the decorated field is a hexadecimal string.
|
|
539
478
|
*
|
|
540
|
-
* @param options Optional validation behavior (`message`, `
|
|
479
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
541
480
|
* @returns A field decorator that registers a hexadecimal string rule.
|
|
542
481
|
*/
|
|
543
482
|
export const IsHexadecimal = options => createValidatorJsDecorator('hexadecimal')(undefined, options);
|
|
544
483
|
/**
|
|
545
484
|
* Validates that the decorated field is a JSON string.
|
|
546
485
|
*
|
|
547
|
-
* @param options Optional validation behavior (`message`, `
|
|
486
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
548
487
|
* @returns A field decorator that registers a JSON-string rule.
|
|
549
488
|
*/
|
|
550
489
|
export const IsJSON = options => createValidatorJsDecorator('json')(undefined, options);
|
|
551
490
|
/**
|
|
552
491
|
* Validates that the decorated field is a JSON Web Token string.
|
|
553
492
|
*
|
|
554
|
-
* @param options Optional validation behavior (`message`, `
|
|
493
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
555
494
|
* @returns A field decorator that registers a JWT-string rule.
|
|
556
495
|
*/
|
|
557
496
|
export const IsJWT = options => createValidatorJsDecorator('jwt')(undefined, options);
|
|
558
497
|
/**
|
|
559
498
|
* Validates that the decorated field is a locale identifier.
|
|
560
499
|
*
|
|
561
|
-
* @param options Optional validation behavior (`message`, `
|
|
500
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
562
501
|
* @returns A field decorator that registers a locale-string rule.
|
|
563
502
|
*/
|
|
564
503
|
export const IsLocale = options => createValidatorJsDecorator('locale')(undefined, options);
|
|
565
504
|
/**
|
|
566
505
|
* Validates that the decorated field is lowercase.
|
|
567
506
|
*
|
|
568
|
-
* @param options Optional validation behavior (`message`, `
|
|
507
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
569
508
|
* @returns A field decorator that registers a lowercase-string rule.
|
|
570
509
|
*/
|
|
571
510
|
export const IsLowercase = options => createValidatorJsDecorator('lowercase')(undefined, options);
|
|
572
511
|
/**
|
|
573
512
|
* Validates that the decorated field is a magnet URI string.
|
|
574
513
|
*
|
|
575
|
-
* @param options Optional validation behavior (`message`, `
|
|
514
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
576
515
|
* @returns A field decorator that registers a magnet URI rule.
|
|
577
516
|
*/
|
|
578
517
|
export const IsMagnetURI = options => createValidatorJsDecorator('magnetURI')(undefined, options);
|
|
579
518
|
/**
|
|
580
519
|
* Validates that the decorated field is a MIME type string.
|
|
581
520
|
*
|
|
582
|
-
* @param options Optional validation behavior (`message`, `
|
|
521
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
583
522
|
* @returns A field decorator that registers a MIME type rule.
|
|
584
523
|
*/
|
|
585
524
|
export const IsMimeType = options => createValidatorJsDecorator('mimeType')(undefined, options);
|
|
586
525
|
/**
|
|
587
526
|
* Validates that the decorated field is a MongoDB object ID string.
|
|
588
527
|
*
|
|
589
|
-
* @param options Optional validation behavior (`message`, `
|
|
528
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
590
529
|
* @returns A field decorator that registers a MongoDB object ID rule.
|
|
591
530
|
*/
|
|
592
531
|
export const IsMongoId = options => createValidatorJsDecorator('mongoId')(undefined, options);
|
|
593
532
|
/**
|
|
594
533
|
* Validates that the decorated field is a numeric string.
|
|
595
534
|
*
|
|
596
|
-
* @param options Optional validation behavior (`message`, `
|
|
535
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
597
536
|
* @returns A field decorator that registers a numeric-string rule.
|
|
598
537
|
*/
|
|
599
538
|
export const IsNumberString = options => createValidatorJsDecorator('numberString')(undefined, options);
|
|
600
539
|
/**
|
|
601
540
|
* Validates that the decorated field is a network port string.
|
|
602
541
|
*
|
|
603
|
-
* @param options Optional validation behavior (`message`, `
|
|
542
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
604
543
|
* @returns A field decorator that registers a port-string rule.
|
|
605
544
|
*/
|
|
606
545
|
export const IsPort = options => createValidatorJsDecorator('port')(undefined, options);
|
|
607
546
|
/**
|
|
608
547
|
* Validates that the decorated field is an RFC 3339 date-time string.
|
|
609
548
|
*
|
|
610
|
-
* @param options Optional validation behavior (`message`, `
|
|
549
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
611
550
|
* @returns A field decorator that registers an RFC 3339 string rule.
|
|
612
551
|
*/
|
|
613
552
|
export const IsRFC3339 = options => createValidatorJsDecorator('rfc3339')(undefined, options);
|
|
614
553
|
/**
|
|
615
554
|
* Validates that the decorated field is a semantic version string.
|
|
616
555
|
*
|
|
617
|
-
* @param options Optional validation behavior (`message`, `
|
|
556
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
618
557
|
* @returns A field decorator that registers a semantic-version rule.
|
|
619
558
|
*/
|
|
620
559
|
export const IsSemVer = options => createValidatorJsDecorator('semVer')(undefined, options);
|
|
621
560
|
/**
|
|
622
561
|
* Validates that the decorated field is uppercase.
|
|
623
562
|
*
|
|
624
|
-
* @param options Optional validation behavior (`message`, `
|
|
563
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
625
564
|
* @returns A field decorator that registers an uppercase-string rule.
|
|
626
565
|
*/
|
|
627
566
|
export const IsUppercase = options => createValidatorJsDecorator('uppercase')(undefined, options);
|
|
628
567
|
/**
|
|
629
568
|
* Validates that the decorated field is an ISO 8601 date-time string.
|
|
630
569
|
*
|
|
631
|
-
* @param options Optional validation behavior (`message`, `
|
|
570
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
632
571
|
* @returns A field decorator that registers an ISO 8601 string rule.
|
|
633
572
|
*/
|
|
634
573
|
export const IsISO8601 = options => createValidatorJsDecorator('iso8601')(undefined, options);
|
|
635
574
|
/**
|
|
636
575
|
* Validates that the decorated field is a latitude value.
|
|
637
576
|
*
|
|
638
|
-
* @param options Optional validation behavior (`message`, `
|
|
577
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
639
578
|
* @returns A field decorator that registers a latitude rule.
|
|
640
579
|
*/
|
|
641
580
|
export const IsLatitude = options => createValidatorJsDecorator('latitude')(undefined, options);
|
|
642
581
|
/**
|
|
643
582
|
* Validates that the decorated field is a longitude value.
|
|
644
583
|
*
|
|
645
|
-
* @param options Optional validation behavior (`message`, `
|
|
584
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
646
585
|
* @returns A field decorator that registers a longitude rule.
|
|
647
586
|
*/
|
|
648
587
|
export const IsLongitude = options => createValidatorJsDecorator('longitude')(undefined, options);
|
|
649
588
|
/**
|
|
650
589
|
* Validates that the decorated field is a latitude/longitude coordinate string.
|
|
651
590
|
*
|
|
652
|
-
* @param options Optional validation behavior (`message`, `
|
|
591
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
653
592
|
* @returns A field decorator that registers a latitude/longitude rule.
|
|
654
593
|
*/
|
|
655
594
|
export const IsLatLong = options => createValidatorJsDecorator('latLong')(undefined, options);
|
|
@@ -662,7 +601,7 @@ export const IsLatLong = options => createValidatorJsDecorator('latLong')(undefi
|
|
|
662
601
|
* version only.
|
|
663
602
|
*
|
|
664
603
|
* @param version Optional IP version filter (`'4'`, `'6'`, or `'4_or_6'`).
|
|
665
|
-
* @param options Optional validation behavior (`message`, `
|
|
604
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
666
605
|
* @returns A field decorator that registers an IP-address rule.
|
|
667
606
|
*/
|
|
668
607
|
export function IsIP(version, options) {
|
|
@@ -758,7 +697,7 @@ export function IsCurrency(options) {
|
|
|
758
697
|
* Validates that the decorated array contains all required values.
|
|
759
698
|
*
|
|
760
699
|
* @param values Required values that must be present in the array.
|
|
761
|
-
* @param options Optional validation behavior (`message`, `
|
|
700
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
762
701
|
* @returns A field decorator that registers an array-contains rule.
|
|
763
702
|
*/
|
|
764
703
|
export const ArrayContains = createArrayValidationDecorator((values, options) => ({
|
|
@@ -770,7 +709,7 @@ export const ArrayContains = createArrayValidationDecorator((values, options) =>
|
|
|
770
709
|
* Validates that the decorated array excludes all forbidden values.
|
|
771
710
|
*
|
|
772
711
|
* @param values Forbidden values that must not be present in the array.
|
|
773
|
-
* @param options Optional validation behavior (`message`, `
|
|
712
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
774
713
|
* @returns A field decorator that registers an array-exclusion rule.
|
|
775
714
|
*/
|
|
776
715
|
export const ArrayNotContains = createArrayValidationDecorator((values, options) => ({
|
|
@@ -781,7 +720,7 @@ export const ArrayNotContains = createArrayValidationDecorator((values, options)
|
|
|
781
720
|
/**
|
|
782
721
|
* Validates that the decorated array is not empty.
|
|
783
722
|
*
|
|
784
|
-
* @param options Optional validation behavior (`message`, `
|
|
723
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
785
724
|
* @returns A field decorator that registers a non-empty-array rule.
|
|
786
725
|
*/
|
|
787
726
|
export const ArrayNotEmpty = createFlagValidationDecorator(options => ({
|
|
@@ -792,7 +731,7 @@ export const ArrayNotEmpty = createFlagValidationDecorator(options => ({
|
|
|
792
731
|
* Validates that the decorated array has at least the given size.
|
|
793
732
|
*
|
|
794
733
|
* @param value Inclusive minimum array length.
|
|
795
|
-
* @param options Optional validation behavior (`message`, `
|
|
734
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
796
735
|
* @returns A field decorator that registers a minimum-array-size rule.
|
|
797
736
|
*/
|
|
798
737
|
export const ArrayMinSize = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -804,7 +743,7 @@ export const ArrayMinSize = createValidationOptionsWithConfigDecorator((value, o
|
|
|
804
743
|
* Validates that the decorated array has at most the given size.
|
|
805
744
|
*
|
|
806
745
|
* @param value Inclusive maximum array length.
|
|
807
|
-
* @param options Optional validation behavior (`message`, `
|
|
746
|
+
* @param options Optional validation behavior (`message`, `code`, `each`).
|
|
808
747
|
* @returns A field decorator that registers a maximum-array-size rule.
|
|
809
748
|
*/
|
|
810
749
|
export const ArrayMaxSize = createValidationOptionsWithConfigDecorator((value, options) => ({
|
|
@@ -833,7 +772,8 @@ export function ArrayUnique(selectorOrOptions, options) {
|
|
|
833
772
|
/**
|
|
834
773
|
* Registers a custom field-level validation function.
|
|
835
774
|
*
|
|
836
|
-
* @param validate Custom validator callback invoked with `(
|
|
775
|
+
* @param validate Custom validator callback invoked with `(value, context)`, where `context.dto`
|
|
776
|
+
* is the containing DTO and `context.propertyKey` is the decorated field key.
|
|
837
777
|
* @param options Optional custom-validator metadata (`message`, `code`, `source`, `each`).
|
|
838
778
|
* @returns A field decorator that registers a custom validation rule.
|
|
839
779
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DtoFieldValidationRule, ValidationDecoratorOptions } from '@fluojs/core/request-pipeline';
|
|
2
|
+
import { type FieldDecoratorFn } from './decorator-metadata.js';
|
|
3
|
+
type ValidatorJsRuleName = Extract<DtoFieldValidationRule, {
|
|
4
|
+
kind: 'validatorjs';
|
|
5
|
+
}>['validator'];
|
|
6
|
+
export declare function createValidationDecorator(ruleFactory: () => DtoFieldValidationRule): FieldDecoratorFn;
|
|
7
|
+
export declare function createValidationOptionsWithConfigDecorator<T>(ruleFactory: (value: T, options: ValidationDecoratorOptions | undefined) => DtoFieldValidationRule): (value: T, options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
8
|
+
export declare function createFlagValidationDecorator(ruleFactory: (options: ValidationDecoratorOptions | undefined) => DtoFieldValidationRule): (options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
9
|
+
export declare function createArrayValidationDecorator<T>(ruleFactory: (values: readonly T[], options: ValidationDecoratorOptions | undefined) => DtoFieldValidationRule): (values: readonly T[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
10
|
+
export declare function createValidatorJsDecorator(validator: ValidatorJsRuleName): (args?: readonly unknown[], options?: ValidationDecoratorOptions) => FieldDecoratorFn;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=decorator-factories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-factories.d.ts","sourceRoot":"","sources":["../../src/internal/decorator-factories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAExG,OAAO,EAAmC,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEjG,KAAK,mBAAmB,GAAG,OAAO,CAAC,sBAAsB,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC,WAAW,CAAC,CAAC;AAEjG,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,sBAAsB,GAAG,gBAAgB,CAMrG;AAED,wBAAgB,0CAA0C,CAAC,CAAC,EAC1D,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,0BAA0B,GAAG,SAAS,KAAK,sBAAsB,IAE1F,OAAO,CAAC,EAAE,UAAU,0BAA0B,KAAG,gBAAgB,CAG1E;AAED,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,CAAC,OAAO,EAAE,0BAA0B,GAAG,SAAS,KAAK,sBAAsB,IAEhF,UAAU,0BAA0B,KAAG,gBAAgB,CAGhE;AAED,wBAAgB,8BAA8B,CAAC,CAAC,EAC9C,WAAW,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,0BAA0B,GAAG,SAAS,KAAK,sBAAsB,IAEtG,QAAQ,SAAS,CAAC,EAAE,EAAE,UAAU,0BAA0B,KAAG,gBAAgB,CAGtF;AAED,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,mBAAmB,IAC/D,OAAO,SAAS,OAAO,EAAE,EAAE,UAAU,0BAA0B,KAAG,gBAAgB,CAQ3F"}
|