valgen 4.3.0 → 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 CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  # v4.3.0
2
9
  [2023-12-02]
3
10
 
@@ -32,10 +32,10 @@ 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
- if (input && typeof input === 'object' && ctor && ctor.prototype[isObject.preValidation])
38
- input = ctor.prototype[isObject.preValidation](input, context);
39
39
  if (!(input && typeof input === 'object')) {
40
40
  context.fail(_this, `{{label}} must be an object`, input);
41
41
  return;
@@ -91,8 +91,10 @@ function isObject(schema, options) {
91
91
  }
92
92
  if (context.errors.length)
93
93
  return undefined;
94
- if (ctor && ctor.prototype[isObject.postValidation])
95
- return ctor.prototype[isObject.postValidation](out, context);
94
+ if (ctor && ctor[isObject.postValidation]) {
95
+ ctor[isObject.postValidation](out, context);
96
+ return out;
97
+ }
96
98
  return out;
97
99
  }, options);
98
100
  _rule.schema = schema;
@@ -29,10 +29,10 @@ 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
- if (input && typeof input === 'object' && ctor && ctor.prototype[isObject.preValidation])
35
- input = ctor.prototype[isObject.preValidation](input, context);
36
36
  if (!(input && typeof input === 'object')) {
37
37
  context.fail(_this, `{{label}} must be an object`, input);
38
38
  return;
@@ -88,8 +88,10 @@ export function isObject(schema, options) {
88
88
  }
89
89
  if (context.errors.length)
90
90
  return undefined;
91
- if (ctor && ctor.prototype[isObject.postValidation])
92
- return ctor.prototype[isObject.postValidation](out, context);
91
+ if (ctor && ctor[isObject.postValidation]) {
92
+ ctor[isObject.postValidation](out, context);
93
+ return out;
94
+ }
93
95
  return out;
94
96
  }, options);
95
97
  _rule.schema = schema;
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.3.0",
4
+ "version": "4.3.1",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"