@fluojs/validation 1.0.0-beta.1 → 1.0.0-beta.3
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 +75 -57
- package/README.md +44 -4
- package/dist/decorators.d.ts +284 -2
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +298 -4
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/standard-schema.d.ts +18 -0
- package/dist/standard-schema.d.ts.map +1 -1
- package/dist/standard-schema.js +21 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +4 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +15 -2
- package/package.json +2 -2
package/dist/validation.js
CHANGED
|
@@ -334,10 +334,10 @@ function createNestedDtoInstance(target, rawValue, context) {
|
|
|
334
334
|
if (rawValue instanceof target) {
|
|
335
335
|
return rawValue;
|
|
336
336
|
}
|
|
337
|
-
const instance = new target();
|
|
338
337
|
if (!isPlainObject(rawValue)) {
|
|
339
|
-
return
|
|
338
|
+
return rawValue;
|
|
340
339
|
}
|
|
340
|
+
const instance = new target();
|
|
341
341
|
if (!enterTraversal(rawValue, context)) {
|
|
342
342
|
return rawValue;
|
|
343
343
|
}
|
|
@@ -494,6 +494,12 @@ function buildIssue(fallback, field, source) {
|
|
|
494
494
|
source
|
|
495
495
|
};
|
|
496
496
|
}
|
|
497
|
+
function buildInvalidRootIssue() {
|
|
498
|
+
return {
|
|
499
|
+
code: 'INVALID_DTO',
|
|
500
|
+
message: 'DTO root value must be a plain object.'
|
|
501
|
+
};
|
|
502
|
+
}
|
|
497
503
|
function getRuleValues(value) {
|
|
498
504
|
return getIterableValues(value) ?? [value];
|
|
499
505
|
}
|
|
@@ -634,6 +640,10 @@ async function collectValidationIssuesInternal(target, value, context, traversal
|
|
|
634
640
|
exitTraversal(value, traversal);
|
|
635
641
|
}
|
|
636
642
|
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Represents the default validator.
|
|
646
|
+
*/
|
|
637
647
|
export class DefaultValidator {
|
|
638
648
|
async validate(value, target) {
|
|
639
649
|
const issues = await collectValidationIssues(target, value);
|
|
@@ -641,6 +651,9 @@ export class DefaultValidator {
|
|
|
641
651
|
throw new DtoValidationError('Validation failed.', issues);
|
|
642
652
|
}
|
|
643
653
|
async materialize(value, target) {
|
|
654
|
+
if (!(value instanceof target) && !isPlainObject(value)) {
|
|
655
|
+
throw new DtoValidationError('Validation failed.', [buildInvalidRootIssue()]);
|
|
656
|
+
}
|
|
644
657
|
const instance = createNestedDtoInstance(target, value, {
|
|
645
658
|
active: new WeakSet()
|
|
646
659
|
});
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"decorators",
|
|
10
10
|
"schema"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.3",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@standard-schema/spec": "^1.1.0",
|
|
44
44
|
"validator": "^13.15.26",
|
|
45
|
-
"@fluojs/core": "^1.0.0-beta.
|
|
45
|
+
"@fluojs/core": "^1.0.0-beta.4"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/validator": "^13.15.10",
|