valgen 4.2.5 → 4.3.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/CHANGELOG.md +15 -0
- package/cjs/rules/is-object.js +13 -1
- package/esm/rules/is-object.js +13 -1
- package/package.json +1 -1
- package/typings/rules/is-object.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# v4.3.1
|
|
2
|
+
[2023-12-04]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* Made preValidation and postValidation static ([`71fa530`](https://github.com/panates/valgen/commit/71fa53050428fc937dcdda24cb9a43baf0f2d384))
|
|
7
|
+
|
|
8
|
+
# v4.3.0
|
|
9
|
+
[2023-12-02]
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
* Updated dependencies ([`4ff01f0`](https://github.com/panates/valgen/commit/4ff01f0f52c7efeab0c3e154946ba32d1cf04e86))
|
|
14
|
+
* Added [preValidation] and [postValidation] to isObject rule ([`2f8351d`](https://github.com/panates/valgen/commit/2f8351d10fd1a9cc78577c52b37681319f3d28b2))
|
|
15
|
+
|
|
1
16
|
# v4.2.5
|
|
2
17
|
[2023-11-27]
|
|
3
18
|
|
package/cjs/rules/is-object.js
CHANGED
|
@@ -32,6 +32,8 @@ function isObject(schema, options) {
|
|
|
32
32
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
33
33
|
});
|
|
34
34
|
const _rule = (0, index_js_1.validator)('isObject', function (input, context, _this) {
|
|
35
|
+
if (ctor && ctor[isObject.preValidation])
|
|
36
|
+
input = ctor[isObject.preValidation](input, context);
|
|
35
37
|
if (typeof input === 'string' && context.coerce)
|
|
36
38
|
input = JSON.parse(input);
|
|
37
39
|
if (!(input && typeof input === 'object')) {
|
|
@@ -87,9 +89,19 @@ 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[isObject.postValidation]) {
|
|
95
|
+
ctor[isObject.postValidation](out, context);
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
91
99
|
}, options);
|
|
92
100
|
_rule.schema = schema;
|
|
93
101
|
return _rule;
|
|
94
102
|
}
|
|
95
103
|
exports.isObject = isObject;
|
|
104
|
+
(function (isObject) {
|
|
105
|
+
isObject.postValidation = Symbol('postValidation');
|
|
106
|
+
isObject.preValidation = Symbol('preValidation');
|
|
107
|
+
})(isObject || (exports.isObject = isObject = {}));
|
package/esm/rules/is-object.js
CHANGED
|
@@ -29,6 +29,8 @@ export function isObject(schema, options) {
|
|
|
29
29
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
30
30
|
});
|
|
31
31
|
const _rule = validator('isObject', function (input, context, _this) {
|
|
32
|
+
if (ctor && ctor[isObject.preValidation])
|
|
33
|
+
input = ctor[isObject.preValidation](input, context);
|
|
32
34
|
if (typeof input === 'string' && context.coerce)
|
|
33
35
|
input = JSON.parse(input);
|
|
34
36
|
if (!(input && typeof input === 'object')) {
|
|
@@ -84,8 +86,18 @@ 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[isObject.postValidation]) {
|
|
92
|
+
ctor[isObject.postValidation](out, context);
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
88
96
|
}, options);
|
|
89
97
|
_rule.schema = schema;
|
|
90
98
|
return _rule;
|
|
91
99
|
}
|
|
100
|
+
(function (isObject) {
|
|
101
|
+
isObject.postValidation = Symbol('postValidation');
|
|
102
|
+
isObject.preValidation = Symbol('preValidation');
|
|
103
|
+
})(isObject || (isObject = {}));
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|