@chain-registry/workflows 1.43.0 → 1.45.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 CHANGED
@@ -1,24 +1,66 @@
1
- import Ajv from 'ajv/dist/2019';
1
+ import AjvDraft07 from 'ajv';
2
+ import Ajv2019 from 'ajv/dist/2019';
3
+ import Ajv2020 from 'ajv/dist/2020';
2
4
  import addFormats from 'ajv-formats';
3
5
  import chalk from 'chalk';
4
6
  export class SchemaValidator {
5
7
  ajv;
6
8
  registry;
9
+ options;
10
+ failures = 0;
7
11
  constructor(registry, options) {
8
- const { useStrict = false, allErrors = true, useDefaults = true } = options ?? {};
9
- this.ajv = new Ajv({
10
- strict: useStrict,
11
- allErrors,
12
- useDefaults
13
- });
12
+ const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
13
+ this.options = {
14
+ useDefaults,
15
+ useStrict,
16
+ draft,
17
+ allErrors
18
+ };
19
+ switch (draft) {
20
+ case 'draft-07':
21
+ this.ajv = new AjvDraft07({
22
+ strict: useStrict,
23
+ allErrors,
24
+ useDefaults
25
+ });
26
+ break;
27
+ case '2019-09':
28
+ this.ajv = new Ajv2019({
29
+ strict: useStrict,
30
+ allErrors,
31
+ useDefaults
32
+ });
33
+ break;
34
+ case '2020-12':
35
+ this.ajv = new Ajv2020({
36
+ strict: useStrict,
37
+ allErrors,
38
+ useDefaults
39
+ });
40
+ break;
41
+ default:
42
+ throw new Error('JSONSchema draft not yet supported.');
43
+ }
14
44
  this.registry = registry;
15
45
  addFormats(this.ajv);
16
46
  }
17
47
  validateAllData(verbose = false) {
18
48
  // Compile and validate each schema, then validate corresponding data
19
49
  this.registry.forEachSchemas(([title, schema]) => {
20
- schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
21
50
  try {
51
+ switch (this.options.draft) {
52
+ case 'draft-07':
53
+ schema.content.$schema = 'http://json-schema.org/draft-07/schema';
54
+ break;
55
+ case '2019-09':
56
+ schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
57
+ break;
58
+ case '2020-12':
59
+ schema.content.$schema = 'https://json-schema.org/draft/2020-12/schema';
60
+ break;
61
+ default:
62
+ break;
63
+ }
22
64
  const validate = this.ajv.compile(schema.content);
23
65
  const dataMap = this.registry.dataMappings[title];
24
66
  if (!dataMap) {
@@ -34,9 +76,13 @@ export class SchemaValidator {
34
76
  throw e;
35
77
  }
36
78
  });
79
+ if (this.options.allErrors && this.failures > 0) {
80
+ throw new Error('❌ Validation Failed.');
81
+ }
37
82
  }
38
83
  validateJsonSchema(data, title, validate, verbose) {
39
84
  if (!validate(data.content)) {
85
+ this.failures++;
40
86
  console.error(chalk.red(`❌ Validation errors for ${chalk.bold(title)} in file ${chalk.magenta(data.path)}:`));
41
87
  validate.errors?.forEach(error => {
42
88
  console.error(chalk.red(` ➡️ ${error.instancePath} ${error.message}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/workflows",
3
- "version": "1.43.0",
3
+ "version": "1.45.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.42.0",
34
+ "@chain-registry/interfaces": "^0.44.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": "9aff67535f11998b742af7a345b00bd7bdda9332"
54
+ "gitHead": "0b1edce93eb7fd8f8181e922fd5652675397e309"
55
55
  }
package/validator.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Registry } from './registry';
2
2
  export interface SchemaValidatorOptions {
3
+ draft?: '2019-09' | '2020-12' | 'draft-07';
3
4
  useStrict?: boolean;
4
5
  allErrors?: boolean;
5
6
  useDefaults?: boolean;
@@ -7,6 +8,8 @@ export interface SchemaValidatorOptions {
7
8
  export declare class SchemaValidator {
8
9
  private ajv;
9
10
  private registry;
11
+ private options;
12
+ private failures;
10
13
  constructor(registry: Registry, options?: SchemaValidatorOptions);
11
14
  validateAllData(verbose?: boolean): void;
12
15
  private validateJsonSchema;
package/validator.js CHANGED
@@ -4,27 +4,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SchemaValidator = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
7
8
  const _2019_1 = __importDefault(require("ajv/dist/2019"));
9
+ const _2020_1 = __importDefault(require("ajv/dist/2020"));
8
10
  const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
11
  const chalk_1 = __importDefault(require("chalk"));
10
12
  class SchemaValidator {
11
13
  ajv;
12
14
  registry;
15
+ options;
16
+ failures = 0;
13
17
  constructor(registry, options) {
14
- const { useStrict = false, allErrors = true, useDefaults = true } = options ?? {};
15
- this.ajv = new _2019_1.default({
16
- strict: useStrict,
17
- allErrors,
18
- useDefaults
19
- });
18
+ const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
19
+ this.options = {
20
+ useDefaults,
21
+ useStrict,
22
+ draft,
23
+ allErrors
24
+ };
25
+ switch (draft) {
26
+ case 'draft-07':
27
+ this.ajv = new ajv_1.default({
28
+ strict: useStrict,
29
+ allErrors,
30
+ useDefaults
31
+ });
32
+ break;
33
+ case '2019-09':
34
+ this.ajv = new _2019_1.default({
35
+ strict: useStrict,
36
+ allErrors,
37
+ useDefaults
38
+ });
39
+ break;
40
+ case '2020-12':
41
+ this.ajv = new _2020_1.default({
42
+ strict: useStrict,
43
+ allErrors,
44
+ useDefaults
45
+ });
46
+ break;
47
+ default:
48
+ throw new Error('JSONSchema draft not yet supported.');
49
+ }
20
50
  this.registry = registry;
21
51
  (0, ajv_formats_1.default)(this.ajv);
22
52
  }
23
53
  validateAllData(verbose = false) {
24
54
  // Compile and validate each schema, then validate corresponding data
25
55
  this.registry.forEachSchemas(([title, schema]) => {
26
- schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
27
56
  try {
57
+ switch (this.options.draft) {
58
+ case 'draft-07':
59
+ schema.content.$schema = 'http://json-schema.org/draft-07/schema';
60
+ break;
61
+ case '2019-09':
62
+ schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
63
+ break;
64
+ case '2020-12':
65
+ schema.content.$schema = 'https://json-schema.org/draft/2020-12/schema';
66
+ break;
67
+ default:
68
+ break;
69
+ }
28
70
  const validate = this.ajv.compile(schema.content);
29
71
  const dataMap = this.registry.dataMappings[title];
30
72
  if (!dataMap) {
@@ -40,9 +82,13 @@ class SchemaValidator {
40
82
  throw e;
41
83
  }
42
84
  });
85
+ if (this.options.allErrors && this.failures > 0) {
86
+ throw new Error('❌ Validation Failed.');
87
+ }
43
88
  }
44
89
  validateJsonSchema(data, title, validate, verbose) {
45
90
  if (!validate(data.content)) {
91
+ this.failures++;
46
92
  console.error(chalk_1.default.red(`❌ Validation errors for ${chalk_1.default.bold(title)} in file ${chalk_1.default.magenta(data.path)}:`));
47
93
  validate.errors?.forEach(error => {
48
94
  console.error(chalk_1.default.red(` ➡️ ${error.instancePath} ${error.message}`));