valgen 4.2.4 → 4.3.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/CHANGELOG.md +15 -0
- package/cjs/rules/is-array.js +2 -2
- package/cjs/rules/is-object.js +11 -1
- package/esm/rules/is-array.js +2 -2
- package/esm/rules/is-object.js +11 -1
- package/package.json +2 -2
- package/typings/rules/is-object.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# v4.3.0
|
|
2
|
+
[2023-12-02]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* Updated dependencies ([`4ff01f0`](https://github.com/panates/valgen/commit/4ff01f0f52c7efeab0c3e154946ba32d1cf04e86))
|
|
7
|
+
* Added [preValidation] and [postValidation] to isObject rule ([`2f8351d`](https://github.com/panates/valgen/commit/2f8351d10fd1a9cc78577c52b37681319f3d28b2))
|
|
8
|
+
|
|
9
|
+
# v4.2.5
|
|
10
|
+
[2023-11-27]
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
* Fixed isArray error location property. ([`b42ca30`](https://github.com/panates/valgen/commit/b42ca300c9c5a68685a70a9cff895e9ad97eb650))
|
|
15
|
+
|
|
1
16
|
# v4.2.4
|
|
2
17
|
[2023-11-20]
|
|
3
18
|
|
package/cjs/rules/is-array.js
CHANGED
|
@@ -27,8 +27,8 @@ function isArray(itemValidator, options) {
|
|
|
27
27
|
v = input[i];
|
|
28
28
|
itemContext.scope = input;
|
|
29
29
|
// itemContext.location = location + '[' + i + ']';
|
|
30
|
-
itemContext.location = context.
|
|
31
|
-
? context.
|
|
30
|
+
itemContext.location = context.location
|
|
31
|
+
? context.location + `[${i}]`
|
|
32
32
|
: `<Array>[${i}]`;
|
|
33
33
|
itemContext.index = i;
|
|
34
34
|
v = itemValidator(v, itemContext);
|
package/cjs/rules/is-object.js
CHANGED
|
@@ -34,6 +34,8 @@ function isObject(schema, options) {
|
|
|
34
34
|
const _rule = (0, index_js_1.validator)('isObject', function (input, context, _this) {
|
|
35
35
|
if (typeof input === 'string' && context.coerce)
|
|
36
36
|
input = JSON.parse(input);
|
|
37
|
+
if (input && typeof input === 'object' && ctor && ctor.prototype[isObject.preValidation])
|
|
38
|
+
input = ctor.prototype[isObject.preValidation](input, context);
|
|
37
39
|
if (!(input && typeof input === 'object')) {
|
|
38
40
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
39
41
|
return;
|
|
@@ -87,9 +89,17 @@ function isObject(schema, options) {
|
|
|
87
89
|
if (v !== undefined)
|
|
88
90
|
out[propertyOptions[schemaKey]?.as || schemaKey] = v;
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
if (context.errors.length)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (ctor && ctor.prototype[isObject.postValidation])
|
|
95
|
+
return ctor.prototype[isObject.postValidation](out, context);
|
|
96
|
+
return out;
|
|
91
97
|
}, options);
|
|
92
98
|
_rule.schema = schema;
|
|
93
99
|
return _rule;
|
|
94
100
|
}
|
|
95
101
|
exports.isObject = isObject;
|
|
102
|
+
(function (isObject) {
|
|
103
|
+
isObject.postValidation = Symbol('postValidation');
|
|
104
|
+
isObject.preValidation = Symbol('preValidation');
|
|
105
|
+
})(isObject || (exports.isObject = isObject = {}));
|
package/esm/rules/is-array.js
CHANGED
|
@@ -24,8 +24,8 @@ export function isArray(itemValidator, options) {
|
|
|
24
24
|
v = input[i];
|
|
25
25
|
itemContext.scope = input;
|
|
26
26
|
// itemContext.location = location + '[' + i + ']';
|
|
27
|
-
itemContext.location = context.
|
|
28
|
-
? context.
|
|
27
|
+
itemContext.location = context.location
|
|
28
|
+
? context.location + `[${i}]`
|
|
29
29
|
: `<Array>[${i}]`;
|
|
30
30
|
itemContext.index = i;
|
|
31
31
|
v = itemValidator(v, itemContext);
|
package/esm/rules/is-object.js
CHANGED
|
@@ -31,6 +31,8 @@ export function isObject(schema, options) {
|
|
|
31
31
|
const _rule = validator('isObject', function (input, context, _this) {
|
|
32
32
|
if (typeof input === 'string' && context.coerce)
|
|
33
33
|
input = JSON.parse(input);
|
|
34
|
+
if (input && typeof input === 'object' && ctor && ctor.prototype[isObject.preValidation])
|
|
35
|
+
input = ctor.prototype[isObject.preValidation](input, context);
|
|
34
36
|
if (!(input && typeof input === 'object')) {
|
|
35
37
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
36
38
|
return;
|
|
@@ -84,8 +86,16 @@ export function isObject(schema, options) {
|
|
|
84
86
|
if (v !== undefined)
|
|
85
87
|
out[propertyOptions[schemaKey]?.as || schemaKey] = v;
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
if (context.errors.length)
|
|
90
|
+
return undefined;
|
|
91
|
+
if (ctor && ctor.prototype[isObject.postValidation])
|
|
92
|
+
return ctor.prototype[isObject.postValidation](out, context);
|
|
93
|
+
return out;
|
|
88
94
|
}, options);
|
|
89
95
|
_rule.schema = schema;
|
|
90
96
|
return _rule;
|
|
91
97
|
}
|
|
98
|
+
(function (isObject) {
|
|
99
|
+
isObject.postValidation = Symbol('postValidation');
|
|
100
|
+
isObject.preValidation = Symbol('preValidation');
|
|
101
|
+
})(isObject || (isObject = {}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valgen",
|
|
3
3
|
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.3.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/panates/valgen.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@types/validator": "^13.11.
|
|
15
|
+
"@types/validator": "^13.11.7",
|
|
16
16
|
"dayjs": "^2.0.0-alpha.4",
|
|
17
17
|
"ts-gems": "^2.5.0",
|
|
18
18
|
"validator": "^13.11.0"
|
|
@@ -20,3 +20,7 @@ export interface ObjectValidator<T extends object = object, I = object> extends
|
|
|
20
20
|
* @validator isObject
|
|
21
21
|
*/
|
|
22
22
|
export declare function isObject<T extends object = object, I = object | string>(schema: ObjectSchema, options?: IsObjectOptions<T>): ObjectValidator<T, I>;
|
|
23
|
+
export declare namespace isObject {
|
|
24
|
+
const postValidation: unique symbol;
|
|
25
|
+
const preValidation: unique symbol;
|
|
26
|
+
}
|