@lowdefy/ajv 3.23.2 → 4.0.0-alpha.6
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/dist/createErrorMessage.js +15 -30
- package/dist/index.js +13 -12
- package/dist/validate.js +21 -45
- package/package.json +15 -15
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _nunjucks = require("@lowdefy/nunjucks");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,25 +12,19 @@ var _nunjucks = require("@lowdefy/nunjucks");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
function createErrorMessage() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return "".concat(firstTemplate(errors[0]), "; ").concat(lastTemplate(errors[errors.length - 1]));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return 'Schema validation error.';
|
|
15
|
+
*/ import { nunjucksFunction } from '@lowdefy/nunjucks';
|
|
16
|
+
function createErrorMessage(errors = []) {
|
|
17
|
+
if (errors.length === 1) {
|
|
18
|
+
const template = nunjucksFunction(errors[0].message);
|
|
19
|
+
return template(errors[0]);
|
|
20
|
+
}
|
|
21
|
+
if (errors.length > 1) {
|
|
22
|
+
const firstMessage = errors[0].message;
|
|
23
|
+
const lastMessage = errors[errors.length - 1].message;
|
|
24
|
+
const firstTemplate = nunjucksFunction(firstMessage);
|
|
25
|
+
const lastTemplate = nunjucksFunction(lastMessage);
|
|
26
|
+
return `${firstTemplate(errors[0])}; ${lastTemplate(errors[errors.length - 1])}`;
|
|
27
|
+
}
|
|
28
|
+
return 'Schema validation error.';
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
var _default = createErrorMessage;
|
|
45
|
-
exports.default = _default;
|
|
30
|
+
export default createErrorMessage;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "validate", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _validate.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import validate from './validate.js';
|
|
16
|
+
export { validate };
|
package/dist/validate.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _ajv = _interopRequireDefault(require("ajv"));
|
|
9
|
-
|
|
10
|
-
var _ajvErrors = _interopRequireDefault(require("ajv-errors"));
|
|
11
|
-
|
|
12
|
-
var _createErrorMessage = _interopRequireDefault(require("./createErrorMessage"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
1
|
/*
|
|
17
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
18
3
|
|
|
@@ -27,36 +12,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
27
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
13
|
See the License for the specific language governing permissions and
|
|
29
14
|
limitations under the License.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
*/ import Ajv from 'ajv';
|
|
16
|
+
import ajvErrors from 'ajv-errors';
|
|
17
|
+
import createErrorMessage from './createErrorMessage.js';
|
|
18
|
+
const ajv = new Ajv({
|
|
19
|
+
allErrors: true,
|
|
20
|
+
strict: false
|
|
34
21
|
});
|
|
35
|
-
(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (returnErrors) {
|
|
47
|
-
return {
|
|
48
|
-
valid: false,
|
|
49
|
-
errors: ajv.errors
|
|
50
|
-
};
|
|
22
|
+
ajvErrors(ajv);
|
|
23
|
+
function validate({ schema , data , returnErrors =false }) {
|
|
24
|
+
const valid = ajv.validate(schema, data);
|
|
25
|
+
if (!valid) {
|
|
26
|
+
if (returnErrors) {
|
|
27
|
+
return {
|
|
28
|
+
valid: false,
|
|
29
|
+
errors: ajv.errors
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
throw new Error(createErrorMessage(ajv.errors));
|
|
51
33
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
valid: true
|
|
58
|
-
};
|
|
34
|
+
return {
|
|
35
|
+
valid: true
|
|
36
|
+
};
|
|
59
37
|
}
|
|
60
|
-
|
|
61
|
-
var _default = validate;
|
|
62
|
-
exports.default = _default;
|
|
38
|
+
export default validate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/ajv",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"licence": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -27,31 +27,31 @@
|
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": "./dist/index.js",
|
|
31
32
|
"files": [
|
|
32
33
|
"dist/*"
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
+
"build": "yarn swc",
|
|
36
37
|
"clean": "rm -rf dist",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
38
|
+
"prepare": "yarn build",
|
|
39
|
+
"swc": "swc src --out-dir dist --config-file ../../../.swcrc --delete-dir-on-start",
|
|
40
|
+
"test": "jest --coverage"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@lowdefy/nunjucks": "
|
|
42
|
-
"ajv": "
|
|
43
|
-
"ajv-errors": "
|
|
43
|
+
"@lowdefy/nunjucks": "4.0.0-alpha.6",
|
|
44
|
+
"ajv": "8.8.2",
|
|
45
|
+
"ajv-errors": "3.0.0"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"jest": "26.6.3",
|
|
51
|
-
"jest-diff": "26.6.2"
|
|
48
|
+
"@swc/cli": "0.1.55",
|
|
49
|
+
"@swc/core": "1.2.130",
|
|
50
|
+
"@swc/jest": "0.2.17",
|
|
51
|
+
"jest": "27.3.1"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
|
|
57
57
|
}
|