@hestia-earth/schema-validation 30.7.3 → 31.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
package/validators/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import { keyword as datePattern } from './datePattern';
|
|
|
4
4
|
import { keyword as dateTimePattern } from './dateTimePattern';
|
|
5
5
|
import { keyword as geojson } from './geojson';
|
|
6
6
|
import { keyword as uniqueArrayItem } from './uniqueArrayItem';
|
|
7
|
-
|
|
7
|
+
import { keyword as uniquePrimaryItem } from './uniquePrimaryItem';
|
|
8
|
+
export { arraySameSize, datePattern, dateTimePattern, geojson, uniqueArrayItem, uniquePrimaryItem };
|
|
8
9
|
export declare const init: (ajv: Ajv) => void;
|
package/validators/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.init = exports.uniqueArrayItem = exports.geojson = exports.dateTimePattern = exports.datePattern = exports.arraySameSize = void 0;
|
|
3
|
+
exports.init = exports.uniquePrimaryItem = exports.uniqueArrayItem = exports.geojson = exports.dateTimePattern = exports.datePattern = exports.arraySameSize = void 0;
|
|
4
4
|
var arraySameSize_1 = require("./arraySameSize");
|
|
5
5
|
Object.defineProperty(exports, "arraySameSize", { enumerable: true, get: function () { return arraySameSize_1.keyword; } });
|
|
6
6
|
var datePattern_1 = require("./datePattern");
|
|
@@ -11,11 +11,14 @@ var geojson_1 = require("./geojson");
|
|
|
11
11
|
Object.defineProperty(exports, "geojson", { enumerable: true, get: function () { return geojson_1.keyword; } });
|
|
12
12
|
var uniqueArrayItem_1 = require("./uniqueArrayItem");
|
|
13
13
|
Object.defineProperty(exports, "uniqueArrayItem", { enumerable: true, get: function () { return uniqueArrayItem_1.keyword; } });
|
|
14
|
+
var uniquePrimaryItem_1 = require("./uniquePrimaryItem");
|
|
15
|
+
Object.defineProperty(exports, "uniquePrimaryItem", { enumerable: true, get: function () { return uniquePrimaryItem_1.keyword; } });
|
|
14
16
|
var init = function (ajv) {
|
|
15
17
|
(0, arraySameSize_1.init)(ajv);
|
|
16
18
|
(0, datePattern_1.init)(ajv);
|
|
17
19
|
(0, dateTimePattern_1.init)(ajv);
|
|
18
20
|
(0, geojson_1.init)(ajv);
|
|
19
21
|
(0, uniqueArrayItem_1.init)(ajv);
|
|
22
|
+
(0, uniquePrimaryItem_1.init)(ajv);
|
|
20
23
|
};
|
|
21
24
|
exports.init = init;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = exports.validate = exports.keyword = void 0;
|
|
4
|
+
exports.keyword = 'uniquePrimaryItem';
|
|
5
|
+
var validate = function (schema, data, _parentSchema, dataPath) {
|
|
6
|
+
if (dataPath === void 0) { dataPath = ''; }
|
|
7
|
+
var primaryCount = data.filter(function (item) { return item.primary === true; }).length;
|
|
8
|
+
var errors = primaryCount <= 1
|
|
9
|
+
? []
|
|
10
|
+
: data
|
|
11
|
+
.map(function (v, index) {
|
|
12
|
+
return v.primary !== true
|
|
13
|
+
? null
|
|
14
|
+
: {
|
|
15
|
+
dataPath: "".concat(dataPath, "[").concat(index, "]"),
|
|
16
|
+
keyword: exports.keyword,
|
|
17
|
+
schemaPath: '#/invalid',
|
|
18
|
+
message: 'can only contain one primary item',
|
|
19
|
+
params: {}
|
|
20
|
+
};
|
|
21
|
+
})
|
|
22
|
+
.filter(Boolean);
|
|
23
|
+
exports.validate.errors = errors;
|
|
24
|
+
return errors.length === 0;
|
|
25
|
+
};
|
|
26
|
+
exports.validate = validate;
|
|
27
|
+
var init = function (ajv) {
|
|
28
|
+
return ajv.addKeyword(exports.keyword, {
|
|
29
|
+
type: 'array',
|
|
30
|
+
errors: 'full',
|
|
31
|
+
validate: exports.validate
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.init = init;
|