@hestia-earth/schema-validation 23.6.0 → 24.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-validation",
3
- "version": "23.6.0",
3
+ "version": "24.0.0",
4
4
  "description": "Hestia Schema Validation",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -10,6 +10,22 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
13
29
  Object.defineProperty(exports, "__esModule", { value: true });
14
30
  exports.init = exports.validate = exports.keyword = void 0;
15
31
  var getByKey = function (prev, curr) {
@@ -23,6 +39,19 @@ var getByKey = function (prev, curr) {
23
39
  };
24
40
  var getItemValue = function (item, key) { return key.split('.').reduce(getByKey, item); };
25
41
  exports.keyword = 'uniqueArrayItem';
42
+ var findIdenticalIndexes = function (values) { return function (value, index) { return ({
43
+ index: index,
44
+ duplicatedIndexes: values
45
+ .map(function (otherValue, otherIndex) { return [otherValue, otherIndex]; })
46
+ .filter(function (_a) {
47
+ var _b = __read(_a, 2), otherValue = _b[0], otherIndex = _b[1];
48
+ return otherIndex !== index && otherValue === value;
49
+ })
50
+ .map(function (_a) {
51
+ var _b = __read(_a, 2), _otherValue = _b[0], otherIndex = _b[1];
52
+ return otherIndex;
53
+ })
54
+ }); }; };
26
55
  var validate = function (schema, data, _parentSchema, dataPath) {
27
56
  if (dataPath === void 0) { dataPath = ''; }
28
57
  var values = data.map(function (item) {
@@ -32,18 +61,22 @@ var validate = function (schema, data, _parentSchema, dataPath) {
32
61
  }, {}));
33
62
  });
34
63
  var indexes = values
35
- .map(function (value, index) {
36
- return values.findIndex(function (otherValue, otherValueIndex) { return otherValueIndex !== index && otherValue === value; });
64
+ .map(findIdenticalIndexes(values))
65
+ .filter(function (_a) {
66
+ var duplicatedIndexes = _a.duplicatedIndexes;
67
+ return duplicatedIndexes.length > 0;
37
68
  })
38
- .filter(function (index) { return index >= 0; })
39
69
  .sort();
40
- exports.validate.errors = indexes.map(function (index) { return ({
41
- dataPath: "".concat(dataPath, "[").concat(index, "]"),
42
- keyword: exports.keyword,
43
- schemaPath: '#/invalid',
44
- message: 'every item in the list should be unique',
45
- params: { keyword: exports.keyword, keys: schema }
46
- }); });
70
+ exports.validate.errors = indexes.map(function (_a) {
71
+ var index = _a.index, duplicatedIndexes = _a.duplicatedIndexes;
72
+ return ({
73
+ dataPath: "".concat(dataPath, "[").concat(index, "]"),
74
+ keyword: exports.keyword,
75
+ schemaPath: '#/invalid',
76
+ message: 'every item in the list should be unique',
77
+ params: { keyword: exports.keyword, keys: schema, duplicatedIndexes: duplicatedIndexes }
78
+ });
79
+ });
47
80
  return indexes.length === 0;
48
81
  };
49
82
  exports.validate = validate;