@chain-registry/workflows 1.45.4 → 1.47.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/esm/validator.js +21 -8
- package/package.json +3 -3
- package/validator.d.ts +2 -0
- package/validator.js +21 -8
package/esm/validator.js
CHANGED
|
@@ -8,13 +8,15 @@ export class SchemaValidator {
|
|
|
8
8
|
registry;
|
|
9
9
|
options;
|
|
10
10
|
failures = 0;
|
|
11
|
+
tests = 0;
|
|
11
12
|
constructor(registry, options) {
|
|
12
|
-
const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
|
|
13
|
+
const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09', logLevel = 'info' } = options ?? {};
|
|
13
14
|
this.options = {
|
|
14
15
|
useDefaults,
|
|
15
16
|
useStrict,
|
|
16
17
|
draft,
|
|
17
|
-
allErrors
|
|
18
|
+
allErrors,
|
|
19
|
+
logLevel
|
|
18
20
|
};
|
|
19
21
|
switch (draft) {
|
|
20
22
|
case 'draft-07':
|
|
@@ -72,24 +74,35 @@ export class SchemaValidator {
|
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
catch (e) {
|
|
75
|
-
|
|
77
|
+
if (['info', 'error'].includes(this.options.logLevel)) {
|
|
78
|
+
console.error(chalk.red(`❌ Strict Validation errors for schema ${chalk.bold(title)} in file ${chalk.magenta(schema.path)}:`));
|
|
79
|
+
}
|
|
76
80
|
throw e;
|
|
77
81
|
}
|
|
78
82
|
});
|
|
79
83
|
if (this.options.allErrors && this.failures > 0) {
|
|
80
84
|
throw new Error('❌ Validation Failed.');
|
|
81
85
|
}
|
|
86
|
+
if (this.failures === 0) {
|
|
87
|
+
console.log(`✅ Validation Passed.`);
|
|
88
|
+
}
|
|
89
|
+
console.log(`${this.tests} Tests.`);
|
|
82
90
|
}
|
|
83
91
|
validateJsonSchema(data, title, validate, verbose) {
|
|
92
|
+
this.tests++;
|
|
84
93
|
if (!validate(data.content)) {
|
|
85
94
|
this.failures++;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
if (['info', 'error'].includes(this.options.logLevel)) {
|
|
96
|
+
console.error(chalk.red(`❌ Validation errors for ${chalk.bold(title)} in file ${chalk.magenta(data.path)}:`));
|
|
97
|
+
validate.errors?.forEach(error => {
|
|
98
|
+
console.error(chalk.red(` ➡️ ${error.instancePath} ${error.message}`));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
90
101
|
}
|
|
91
102
|
else if (verbose) {
|
|
92
|
-
|
|
103
|
+
if (['info'].includes(this.options.logLevel)) {
|
|
104
|
+
console.log(chalk.green(`✅ Validation passed for ${chalk.bold(title)} in file ${chalk.magenta(data.path)}`));
|
|
105
|
+
}
|
|
93
106
|
}
|
|
94
107
|
}
|
|
95
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/workflows",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.47.0",
|
|
4
4
|
"description": "Chain Registry Workflows",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/cosmology-tech/chain-registry",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@types/sha.js": "^2.4.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@chain-registry/interfaces": "^0.
|
|
34
|
+
"@chain-registry/interfaces": "^0.46.0",
|
|
35
35
|
"ajv": "^8.12.0",
|
|
36
36
|
"ajv-formats": "^3.0.1",
|
|
37
37
|
"bignumber.js": "9.1.2",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"cosmos",
|
|
52
52
|
"interchain"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "f6b313aca6c0953fbc5383cd365f5c060d970c55"
|
|
55
55
|
}
|
package/validator.d.ts
CHANGED
|
@@ -4,12 +4,14 @@ export interface SchemaValidatorOptions {
|
|
|
4
4
|
useStrict?: boolean;
|
|
5
5
|
allErrors?: boolean;
|
|
6
6
|
useDefaults?: boolean;
|
|
7
|
+
logLevel?: 'info' | 'error' | 'none';
|
|
7
8
|
}
|
|
8
9
|
export declare class SchemaValidator {
|
|
9
10
|
private ajv;
|
|
10
11
|
private registry;
|
|
11
12
|
private options;
|
|
12
13
|
private failures;
|
|
14
|
+
private tests;
|
|
13
15
|
constructor(registry: Registry, options?: SchemaValidatorOptions);
|
|
14
16
|
validateAllData(verbose?: boolean): void;
|
|
15
17
|
private validateJsonSchema;
|
package/validator.js
CHANGED
|
@@ -14,13 +14,15 @@ class SchemaValidator {
|
|
|
14
14
|
registry;
|
|
15
15
|
options;
|
|
16
16
|
failures = 0;
|
|
17
|
+
tests = 0;
|
|
17
18
|
constructor(registry, options) {
|
|
18
|
-
const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
|
|
19
|
+
const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09', logLevel = 'info' } = options ?? {};
|
|
19
20
|
this.options = {
|
|
20
21
|
useDefaults,
|
|
21
22
|
useStrict,
|
|
22
23
|
draft,
|
|
23
|
-
allErrors
|
|
24
|
+
allErrors,
|
|
25
|
+
logLevel
|
|
24
26
|
};
|
|
25
27
|
switch (draft) {
|
|
26
28
|
case 'draft-07':
|
|
@@ -78,24 +80,35 @@ class SchemaValidator {
|
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
catch (e) {
|
|
81
|
-
|
|
83
|
+
if (['info', 'error'].includes(this.options.logLevel)) {
|
|
84
|
+
console.error(chalk_1.default.red(`❌ Strict Validation errors for schema ${chalk_1.default.bold(title)} in file ${chalk_1.default.magenta(schema.path)}:`));
|
|
85
|
+
}
|
|
82
86
|
throw e;
|
|
83
87
|
}
|
|
84
88
|
});
|
|
85
89
|
if (this.options.allErrors && this.failures > 0) {
|
|
86
90
|
throw new Error('❌ Validation Failed.');
|
|
87
91
|
}
|
|
92
|
+
if (this.failures === 0) {
|
|
93
|
+
console.log(`✅ Validation Passed.`);
|
|
94
|
+
}
|
|
95
|
+
console.log(`${this.tests} Tests.`);
|
|
88
96
|
}
|
|
89
97
|
validateJsonSchema(data, title, validate, verbose) {
|
|
98
|
+
this.tests++;
|
|
90
99
|
if (!validate(data.content)) {
|
|
91
100
|
this.failures++;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
if (['info', 'error'].includes(this.options.logLevel)) {
|
|
102
|
+
console.error(chalk_1.default.red(`❌ Validation errors for ${chalk_1.default.bold(title)} in file ${chalk_1.default.magenta(data.path)}:`));
|
|
103
|
+
validate.errors?.forEach(error => {
|
|
104
|
+
console.error(chalk_1.default.red(` ➡️ ${error.instancePath} ${error.message}`));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
96
107
|
}
|
|
97
108
|
else if (verbose) {
|
|
98
|
-
|
|
109
|
+
if (['info'].includes(this.options.logLevel)) {
|
|
110
|
+
console.log(chalk_1.default.green(`✅ Validation passed for ${chalk_1.default.bold(title)} in file ${chalk_1.default.magenta(data.path)}`));
|
|
111
|
+
}
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
}
|