@hestia-earth/schema-validation 33.5.3 → 33.5.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-validation",
3
- "version": "33.5.3",
3
+ "version": "33.5.5",
4
4
  "description": "HESTIA Schema Validation",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -4,33 +4,17 @@ exports.init = exports.validate = exports.keyword = void 0;
4
4
  exports.keyword = 'matrixSameSize';
5
5
  var validate = function (schema, data, _parentSchema, dataPath, parentData) {
6
6
  var matrixFields = parentData[schema];
7
+ var matrixLength = matrixFields.length;
8
+ var isLengthCorrect = data.length === matrixLength && data.every(function (value) { return value.length === matrixLength; });
7
9
  exports.validate.errors = [
8
- data.length === matrixFields.length - 1
10
+ isLengthCorrect
9
11
  ? null
10
12
  : {
11
13
  dataPath: dataPath,
12
14
  keyword: exports.keyword,
13
15
  schemaPath: '#/invalid',
14
- message: "must contain one less item than ".concat(schema),
15
- params: { keyword: exports.keyword, current: data.length, expected: matrixFields.length - 1 }
16
- },
17
- data.flat(2).every(function (v) { return !v || (-1 <= v && v <= 1); })
18
- ? null
19
- : {
20
- dataPath: dataPath,
21
- keyword: exports.keyword,
22
- schemaPath: '#/invalid',
23
- message: 'every value must be between -1 and 1',
24
- params: { keyword: exports.keyword }
25
- },
26
- data.every(function (value, index) { return value.length === index + 1; })
27
- ? null
28
- : {
29
- dataPath: dataPath,
30
- keyword: exports.keyword,
31
- schemaPath: '#/invalid',
32
- message: 'the length of each array is incorrect',
33
- params: { keyword: exports.keyword }
16
+ message: "must contain as many items as ".concat(schema),
17
+ params: { keyword: exports.keyword, expected: matrixLength }
34
18
  }
35
19
  ].filter(Boolean);
36
20
  return exports.validate.errors.length === 0;