@aeriajs/validation 0.0.121 → 0.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/validate.js +21 -21
- package/dist/validate.mjs +19 -19
- package/package.json +3 -3
package/dist/validate.js
CHANGED
|
@@ -10,24 +10,24 @@ const getValueType = (value) => {
|
|
|
10
10
|
: typeof value;
|
|
11
11
|
};
|
|
12
12
|
const getPropertyType = (property) => {
|
|
13
|
-
if ('
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if ('type' in property) {
|
|
14
|
+
if ('format' in property && property.format) {
|
|
15
|
+
if ([
|
|
16
|
+
'date',
|
|
17
|
+
'date-time',
|
|
18
|
+
].includes(property.format)) {
|
|
19
|
+
return 'datetime';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return property.type;
|
|
17
23
|
}
|
|
18
24
|
if ('enum' in property) {
|
|
19
25
|
return typeof property.enum[0];
|
|
20
26
|
}
|
|
21
|
-
if ('
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
].includes(property.format)) {
|
|
26
|
-
return 'datetime';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if ('type' in property) {
|
|
30
|
-
return property.type;
|
|
27
|
+
if ('$ref' in property
|
|
28
|
+
|| 'properties' in property
|
|
29
|
+
|| 'additionalProperties' in property) {
|
|
30
|
+
return 'object';
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
const makePropertyError = (type, details) => {
|
|
@@ -42,9 +42,6 @@ const makeValidationError = (error) => {
|
|
|
42
42
|
exports.makeValidationError = makeValidationError;
|
|
43
43
|
const validateProperty = (propName, what, property, options = {}) => {
|
|
44
44
|
const { filterOutExtraneous, coerce } = options;
|
|
45
|
-
if (what === null || what === undefined) {
|
|
46
|
-
return types_1.Result.result(what);
|
|
47
|
-
}
|
|
48
45
|
if (!property) {
|
|
49
46
|
if (options.parentProperty && 'additionalProperties' in options.parentProperty && options.parentProperty.additionalProperties) {
|
|
50
47
|
const extraneous = options.parentProperty.additionalProperties;
|
|
@@ -57,8 +54,8 @@ const validateProperty = (propName, what, property, options = {}) => {
|
|
|
57
54
|
}
|
|
58
55
|
return types_1.Result.error(makePropertyError(types_2.PropertyValidationErrorCode.Extraneous));
|
|
59
56
|
}
|
|
60
|
-
if (
|
|
61
|
-
return types_1.Result.result(
|
|
57
|
+
if (what === null || what === undefined) {
|
|
58
|
+
return types_1.Result.result(what);
|
|
62
59
|
}
|
|
63
60
|
if ('properties' in property) {
|
|
64
61
|
return (0, exports.validate)(what, property, options);
|
|
@@ -72,11 +69,14 @@ const validateProperty = (propName, what, property, options = {}) => {
|
|
|
72
69
|
}
|
|
73
70
|
return types_1.Result.result(what);
|
|
74
71
|
}
|
|
75
|
-
const expectedType = getPropertyType(property);
|
|
76
|
-
const actualType = getValueType(what);
|
|
77
72
|
if ('enum' in property && property.enum.length === 0) {
|
|
78
73
|
return types_1.Result.result(what);
|
|
79
74
|
}
|
|
75
|
+
if ('getter' in property) {
|
|
76
|
+
return types_1.Result.result(undefined);
|
|
77
|
+
}
|
|
78
|
+
const expectedType = getPropertyType(property);
|
|
79
|
+
const actualType = getValueType(what);
|
|
80
80
|
if (actualType !== expectedType
|
|
81
81
|
&& !('items' in property && actualType === 'array')
|
|
82
82
|
&& !(actualType === 'number' && expectedType === 'integer')) {
|
package/dist/validate.mjs
CHANGED
|
@@ -6,22 +6,22 @@ const getValueType = (value) => {
|
|
|
6
6
|
return Array.isArray(value) ? "array" : typeof value;
|
|
7
7
|
};
|
|
8
8
|
const getPropertyType = (property) => {
|
|
9
|
-
if ("
|
|
10
|
-
|
|
9
|
+
if ("type" in property) {
|
|
10
|
+
if ("format" in property && property.format) {
|
|
11
|
+
if ([
|
|
12
|
+
"date",
|
|
13
|
+
"date-time"
|
|
14
|
+
].includes(property.format)) {
|
|
15
|
+
return "datetime";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return property.type;
|
|
11
19
|
}
|
|
12
20
|
if ("enum" in property) {
|
|
13
21
|
return typeof property.enum[0];
|
|
14
22
|
}
|
|
15
|
-
if ("
|
|
16
|
-
|
|
17
|
-
"date",
|
|
18
|
-
"date-time"
|
|
19
|
-
].includes(property.format)) {
|
|
20
|
-
return "datetime";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if ("type" in property) {
|
|
24
|
-
return property.type;
|
|
23
|
+
if ("$ref" in property || "properties" in property || "additionalProperties" in property) {
|
|
24
|
+
return "object";
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
const makePropertyError = (type, details) => {
|
|
@@ -35,9 +35,6 @@ export const makeValidationError = (error) => {
|
|
|
35
35
|
};
|
|
36
36
|
export const validateProperty = (propName, what, property, options = {}) => {
|
|
37
37
|
const { filterOutExtraneous, coerce } = options;
|
|
38
|
-
if (what === null || what === void 0) {
|
|
39
|
-
return Result.result(what);
|
|
40
|
-
}
|
|
41
38
|
if (!property) {
|
|
42
39
|
if (options.parentProperty && "additionalProperties" in options.parentProperty && options.parentProperty.additionalProperties) {
|
|
43
40
|
const extraneous = options.parentProperty.additionalProperties;
|
|
@@ -50,8 +47,8 @@ export const validateProperty = (propName, what, property, options = {}) => {
|
|
|
50
47
|
}
|
|
51
48
|
return Result.error(makePropertyError(PropertyValidationErrorCode.Extraneous));
|
|
52
49
|
}
|
|
53
|
-
if (
|
|
54
|
-
return Result.result(
|
|
50
|
+
if (what === null || what === void 0) {
|
|
51
|
+
return Result.result(what);
|
|
55
52
|
}
|
|
56
53
|
if ("properties" in property) {
|
|
57
54
|
return validate(what, property, options);
|
|
@@ -65,11 +62,14 @@ export const validateProperty = (propName, what, property, options = {}) => {
|
|
|
65
62
|
}
|
|
66
63
|
return Result.result(what);
|
|
67
64
|
}
|
|
68
|
-
const expectedType = getPropertyType(property);
|
|
69
|
-
const actualType = getValueType(what);
|
|
70
65
|
if ("enum" in property && property.enum.length === 0) {
|
|
71
66
|
return Result.result(what);
|
|
72
67
|
}
|
|
68
|
+
if ("getter" in property) {
|
|
69
|
+
return Result.result(void 0);
|
|
70
|
+
}
|
|
71
|
+
const expectedType = getPropertyType(property);
|
|
72
|
+
const actualType = getValueType(what);
|
|
73
73
|
if (actualType !== expectedType && !("items" in property && actualType === "array") && !(actualType === "number" && expectedType === "integer")) {
|
|
74
74
|
if (expectedType === "datetime" && what instanceof Date) {
|
|
75
75
|
return Result.result(what);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/validation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.123",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@aeriajs/types": "link:../types"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@aeriajs/common": "^0.0.
|
|
30
|
-
"@aeriajs/types": "^0.0.
|
|
29
|
+
"@aeriajs/common": "^0.0.119",
|
|
30
|
+
"@aeriajs/types": "^0.0.102",
|
|
31
31
|
"mongodb": "^6.5.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|