@hestia-earth/schema-validation 23.1.0 → 23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-validation",
3
- "version": "23.1.0",
3
+ "version": "23.3.0",
4
4
  "description": "Hestia Schema Validation",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
package/validate.d.ts CHANGED
@@ -10,7 +10,16 @@ import { definitions } from '@hestia-earth/json-schema';
10
10
  */
11
11
  export declare const validateContent: (ajv: Ajv.Ajv, schemas: definitions) => (content: HestiaJson<SchemaType>) => Promise<{
12
12
  success: any;
13
- errors: Ajv.ErrorObject[];
13
+ errors: {
14
+ schema?: any;
15
+ parentSchema?: object;
16
+ dataPath: string;
17
+ schemaPath: string;
18
+ params: Ajv.ErrorParameters;
19
+ propertyName?: string;
20
+ message?: string;
21
+ keyword: string;
22
+ }[];
14
23
  }>;
15
24
  export declare const initAjv: () => Ajv.Ajv;
16
25
  /**
@@ -22,5 +31,14 @@ export declare const initAjv: () => Ajv.Ajv;
22
31
  */
23
32
  export declare const validator: (domain?: string, strictMode?: boolean) => (content: HestiaJson<SchemaType>) => Promise<{
24
33
  success: any;
25
- errors: Ajv.ErrorObject[];
34
+ errors: {
35
+ schema?: any;
36
+ parentSchema?: object;
37
+ dataPath: string;
38
+ schemaPath: string;
39
+ params: Ajv.ErrorParameters;
40
+ propertyName?: string;
41
+ message?: string;
42
+ keyword: string;
43
+ }[];
26
44
  }>;
package/validate.js CHANGED
@@ -46,6 +46,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
49
60
  Object.defineProperty(exports, "__esModule", { value: true });
50
61
  exports.validator = exports.initAjv = exports.validateContent = void 0;
51
62
  var Ajv = require("ajv");
@@ -61,6 +72,16 @@ var validateSchemaType = function (schemas, content) {
61
72
  }
62
73
  return true;
63
74
  };
75
+ var ignoreSchemaKeywords = [
76
+ 'if', validators_1.uniqueArrayItem, validators_1.arraySameSize
77
+ ];
78
+ // using `verbose: true` includes data which we don't need
79
+ var cleanErrors = function (errors) {
80
+ return errors.map(function (_a) {
81
+ var keyword = _a.keyword, data = _a.data, schema = _a.schema, parentSchema = _a.parentSchema, error = __rest(_a, ["keyword", "data", "schema", "parentSchema"]);
82
+ return (__assign(__assign({ keyword: keyword }, error), (ignoreSchemaKeywords.includes(keyword) ? {} : { schema: schema, parentSchema: parentSchema })));
83
+ });
84
+ };
64
85
  /**
65
86
  * Validate a single node. Function is asynchronous to return a list of `success` and a list of `errors`.
66
87
  *
@@ -80,7 +101,7 @@ var validateContent = function (ajv, schemas) { return function (content) { retu
80
101
  return [4 /*yield*/, ajv.validate(schemas[content['@type'] || content.type], content)];
81
102
  case 1:
82
103
  _a = (_b.success = _c.sent(),
83
- _b.errors = ajv.errors || [],
104
+ _b.errors = cleanErrors(ajv.errors || []),
84
105
  _b);
85
106
  _c.label = 2;
86
107
  case 2: return [2 /*return*/, _a];
@@ -91,7 +112,8 @@ exports.validateContent = validateContent;
91
112
  var initAjv = function () {
92
113
  var ajv = new Ajv({
93
114
  schemaId: 'auto',
94
- allErrors: true
115
+ allErrors: true,
116
+ verbose: true
95
117
  });
96
118
  ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
97
119
  ajv.addSchema(require('./json-schema/geojson.json'), geojsonSchema);
@@ -1,2 +1,6 @@
1
1
  import { Ajv } from 'ajv';
2
+ import { keyword as arraySameSize } from './arraySameSize';
3
+ import { keyword as datePattern } from './datePattern';
4
+ import { keyword as uniqueArrayItem } from './uniqueArrayItem';
5
+ export { arraySameSize, datePattern, uniqueArrayItem };
2
6
  export declare const init: (ajv: Ajv) => void;
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.init = void 0;
3
+ exports.init = exports.uniqueArrayItem = exports.datePattern = exports.arraySameSize = void 0;
4
4
  var arraySameSize_1 = require("./arraySameSize");
5
+ Object.defineProperty(exports, "arraySameSize", { enumerable: true, get: function () { return arraySameSize_1.keyword; } });
5
6
  var datePattern_1 = require("./datePattern");
7
+ Object.defineProperty(exports, "datePattern", { enumerable: true, get: function () { return datePattern_1.keyword; } });
6
8
  var uniqueArrayItem_1 = require("./uniqueArrayItem");
9
+ Object.defineProperty(exports, "uniqueArrayItem", { enumerable: true, get: function () { return uniqueArrayItem_1.keyword; } });
7
10
  var init = function (ajv) {
8
11
  ajv.addKeyword(arraySameSize_1.keyword, {
9
12
  type: 'array',