@chain-registry/workflows 1.42.0 → 1.44.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,32 +1,79 @@
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;
7
10
  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
- });
11
+ const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
12
+ this.options = {
13
+ useDefaults,
14
+ useStrict,
15
+ draft,
16
+ allErrors
17
+ };
18
+ switch (draft) {
19
+ case 'draft-07':
20
+ this.ajv = new AjvDraft07({
21
+ strict: useStrict,
22
+ allErrors,
23
+ useDefaults
24
+ });
25
+ break;
26
+ case '2019-09':
27
+ this.ajv = new Ajv2019({
28
+ strict: useStrict,
29
+ allErrors,
30
+ useDefaults
31
+ });
32
+ break;
33
+ case '2020-12':
34
+ this.ajv = new Ajv2020({
35
+ strict: useStrict,
36
+ allErrors,
37
+ useDefaults
38
+ });
39
+ break;
40
+ default:
41
+ throw new Error('JSONSchema draft not yet supported.');
42
+ }
14
43
  this.registry = registry;
15
44
  addFormats(this.ajv);
16
45
  }
17
46
  validateAllData(verbose = false) {
18
47
  // Compile and validate each schema, then validate corresponding data
19
48
  this.registry.forEachSchemas(([title, schema]) => {
20
- schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
21
- const validate = this.ajv.compile(schema.content);
22
- const dataMap = this.registry.dataMappings[title];
23
- if (!dataMap) {
24
- console.error(chalk.yellow(`⚠️ No data found for schema titled ${chalk.bold(title)}`));
25
- return;
49
+ try {
50
+ switch (this.options.draft) {
51
+ case 'draft-07':
52
+ schema.content.$schema = 'http://json-schema.org/draft-07/schema';
53
+ break;
54
+ case '2019-09':
55
+ schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
56
+ break;
57
+ case '2020-12':
58
+ schema.content.$schema = 'https://json-schema.org/draft/2020-12/schema';
59
+ break;
60
+ default:
61
+ break;
62
+ }
63
+ const validate = this.ajv.compile(schema.content);
64
+ const dataMap = this.registry.dataMappings[title];
65
+ if (!dataMap) {
66
+ console.error(chalk.yellow(`⚠️ No data found for schema titled ${chalk.bold(title)}`));
67
+ return;
68
+ }
69
+ dataMap.forEach(data => {
70
+ this.validateJsonSchema(data, title, validate, verbose);
71
+ });
72
+ }
73
+ catch (e) {
74
+ console.error(chalk.red(`❌ Strict Validation errors for schema ${chalk.bold(title)} in file ${chalk.magenta(schema.path)}:`));
75
+ throw e;
26
76
  }
27
- dataMap.forEach(data => {
28
- this.validateJsonSchema(data, title, validate, verbose);
29
- });
30
77
  });
31
78
  }
32
79
  validateJsonSchema(data, title, validate, verbose) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/workflows",
3
- "version": "1.42.0",
3
+ "version": "1.44.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.41.0",
34
+ "@chain-registry/interfaces": "^0.43.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": "33eb7317dabe560105ed2ababa9232b0e256721a"
54
+ "gitHead": "b171e31c9d099235ad33d2a78b8d9d8c137cb3ca"
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,7 @@ export interface SchemaValidatorOptions {
7
8
  export declare class SchemaValidator {
8
9
  private ajv;
9
10
  private registry;
11
+ private options;
10
12
  constructor(registry: Registry, options?: SchemaValidatorOptions);
11
13
  validateAllData(verbose?: boolean): void;
12
14
  private validateJsonSchema;
package/validator.js CHANGED
@@ -4,35 +4,82 @@ 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;
13
16
  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
- });
17
+ const { useStrict = false, allErrors = true, useDefaults = true, draft = '2019-09' } = options ?? {};
18
+ this.options = {
19
+ useDefaults,
20
+ useStrict,
21
+ draft,
22
+ allErrors
23
+ };
24
+ switch (draft) {
25
+ case 'draft-07':
26
+ this.ajv = new ajv_1.default({
27
+ strict: useStrict,
28
+ allErrors,
29
+ useDefaults
30
+ });
31
+ break;
32
+ case '2019-09':
33
+ this.ajv = new _2019_1.default({
34
+ strict: useStrict,
35
+ allErrors,
36
+ useDefaults
37
+ });
38
+ break;
39
+ case '2020-12':
40
+ this.ajv = new _2020_1.default({
41
+ strict: useStrict,
42
+ allErrors,
43
+ useDefaults
44
+ });
45
+ break;
46
+ default:
47
+ throw new Error('JSONSchema draft not yet supported.');
48
+ }
20
49
  this.registry = registry;
21
50
  (0, ajv_formats_1.default)(this.ajv);
22
51
  }
23
52
  validateAllData(verbose = false) {
24
53
  // Compile and validate each schema, then validate corresponding data
25
54
  this.registry.forEachSchemas(([title, schema]) => {
26
- schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
27
- const validate = this.ajv.compile(schema.content);
28
- const dataMap = this.registry.dataMappings[title];
29
- if (!dataMap) {
30
- console.error(chalk_1.default.yellow(`⚠️ No data found for schema titled ${chalk_1.default.bold(title)}`));
31
- return;
55
+ try {
56
+ switch (this.options.draft) {
57
+ case 'draft-07':
58
+ schema.content.$schema = 'http://json-schema.org/draft-07/schema';
59
+ break;
60
+ case '2019-09':
61
+ schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
62
+ break;
63
+ case '2020-12':
64
+ schema.content.$schema = 'https://json-schema.org/draft/2020-12/schema';
65
+ break;
66
+ default:
67
+ break;
68
+ }
69
+ const validate = this.ajv.compile(schema.content);
70
+ const dataMap = this.registry.dataMappings[title];
71
+ if (!dataMap) {
72
+ console.error(chalk_1.default.yellow(`⚠️ No data found for schema titled ${chalk_1.default.bold(title)}`));
73
+ return;
74
+ }
75
+ dataMap.forEach(data => {
76
+ this.validateJsonSchema(data, title, validate, verbose);
77
+ });
78
+ }
79
+ catch (e) {
80
+ console.error(chalk_1.default.red(`❌ Strict Validation errors for schema ${chalk_1.default.bold(title)} in file ${chalk_1.default.magenta(schema.path)}:`));
81
+ throw e;
32
82
  }
33
- dataMap.forEach(data => {
34
- this.validateJsonSchema(data, title, validate, verbose);
35
- });
36
83
  });
37
84
  }
38
85
  validateJsonSchema(data, title, validate, verbose) {