@chain-registry/workflows 1.40.0 → 1.42.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/registry.js CHANGED
@@ -103,17 +103,23 @@ export class Registry {
103
103
  ignore: IGNORE_ROOT_DIRS.map(dir => `${this.basePath}/${dir}/**/*`)
104
104
  })
105
105
  .map(path => {
106
- const content = JSON.parse(readFileSync(path, 'utf-8'));
107
- if (!this.isJsonSchema(content))
108
- return;
109
- // https://stackoverflow.com/questions/69133771/ajv-no-schema-with-key-or-ref-https-json-schema-org-draft-07-schema
110
- content.$schema = content.$schema.replace(/https/, 'http');
111
- types[basename(content.$schema)] = true;
112
- return {
113
- $schemaFile: basename(content.$schema),
114
- path,
115
- content
116
- };
106
+ try {
107
+ const content = JSON.parse(readFileSync(path, 'utf-8'));
108
+ if (!this.isJsonSchema(content))
109
+ return;
110
+ // https://stackoverflow.com/questions/69133771/ajv-no-schema-with-key-or-ref-https-json-schema-org-draft-07-schema
111
+ content.$schema = content.$schema.replace(/https/, 'http');
112
+ types[basename(content.$schema)] = true;
113
+ return {
114
+ $schemaFile: basename(content.$schema),
115
+ path,
116
+ content
117
+ };
118
+ }
119
+ catch (error) {
120
+ // Throw a custom error with a clear message including the file path
121
+ throw new Error(`Failed to parse JSON. The file at "${path}" is not valid JSON.`);
122
+ }
117
123
  }).filter(Boolean);
118
124
  // filter out schemas (e.g. draft-04/schema )
119
125
  const schemas = this.definitions.filter(schema => this.isSchema(schema.content)).filter(Boolean);
@@ -133,6 +139,20 @@ export class Registry {
133
139
  this.loadData(schema);
134
140
  });
135
141
  }
142
+ mapSchemas(mapper) {
143
+ return Object.entries(this.schemaMappings).map(([title, schema]) => {
144
+ if (schema)
145
+ return [title, schema];
146
+ }).filter(Boolean)
147
+ .map(mapper);
148
+ }
149
+ forEachSchemas(mapper) {
150
+ return Object.entries(this.schemaMappings).map(([title, schema]) => {
151
+ if (schema)
152
+ return [title, schema];
153
+ }).filter(Boolean)
154
+ .forEach(mapper);
155
+ }
136
156
  get chains() {
137
157
  return this.dataMappings.Chain.map(c => c.content);
138
158
  }
@@ -149,7 +169,7 @@ export class Registry {
149
169
  return this.dataMappings.Versions.map(c => c.content);
150
170
  }
151
171
  get schemas() {
152
- return Object.entries(this.schemaMappings).map(([_str, obj]) => {
172
+ return this.mapSchemas(([_str, obj]) => {
153
173
  return obj;
154
174
  });
155
175
  }
package/esm/validator.js CHANGED
@@ -16,7 +16,7 @@ export class SchemaValidator {
16
16
  }
17
17
  validateAllData(verbose = false) {
18
18
  // Compile and validate each schema, then validate corresponding data
19
- Object.entries(this.registry.schemaMappings).forEach(([title, schema]) => {
19
+ this.registry.forEachSchemas(([title, schema]) => {
20
20
  schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
21
21
  const validate = this.ajv.compile(schema.content);
22
22
  const dataMap = this.registry.dataMappings[title];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/workflows",
3
- "version": "1.40.0",
3
+ "version": "1.42.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.39.0",
34
+ "@chain-registry/interfaces": "^0.41.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": "4951764c7bd7a6364f5f6d4d267da3c70e986628"
54
+ "gitHead": "33eb7317dabe560105ed2ababa9232b0e256721a"
55
55
  }
package/registry.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AssetList, Chain, IBCData, MemoKeys, Versions } from '@chain-registry/interfaces';
2
2
  import { JSONSchema } from "schema-typescript";
3
+ export type SchemaMapper = ([title, schema]: [string, JSONSchemaContent<any>]) => any;
3
4
  export interface JSONSchemaContent<T> {
4
5
  $schemaFile: string;
5
6
  path: string;
@@ -33,6 +34,8 @@ export declare class Registry {
33
34
  private loadData;
34
35
  private initStoreForSchema;
35
36
  private initializeData;
37
+ mapSchemas(mapper: SchemaMapper): any;
38
+ forEachSchemas(mapper: SchemaMapper): any;
36
39
  get chains(): Chain[];
37
40
  get assetLists(): AssetList[];
38
41
  get ibcData(): IBCData[];
package/registry.js CHANGED
@@ -106,17 +106,23 @@ class Registry {
106
106
  ignore: IGNORE_ROOT_DIRS.map(dir => `${this.basePath}/${dir}/**/*`)
107
107
  })
108
108
  .map(path => {
109
- const content = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
110
- if (!this.isJsonSchema(content))
111
- return;
112
- // https://stackoverflow.com/questions/69133771/ajv-no-schema-with-key-or-ref-https-json-schema-org-draft-07-schema
113
- content.$schema = content.$schema.replace(/https/, 'http');
114
- types[(0, path_1.basename)(content.$schema)] = true;
115
- return {
116
- $schemaFile: (0, path_1.basename)(content.$schema),
117
- path,
118
- content
119
- };
109
+ try {
110
+ const content = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
111
+ if (!this.isJsonSchema(content))
112
+ return;
113
+ // https://stackoverflow.com/questions/69133771/ajv-no-schema-with-key-or-ref-https-json-schema-org-draft-07-schema
114
+ content.$schema = content.$schema.replace(/https/, 'http');
115
+ types[(0, path_1.basename)(content.$schema)] = true;
116
+ return {
117
+ $schemaFile: (0, path_1.basename)(content.$schema),
118
+ path,
119
+ content
120
+ };
121
+ }
122
+ catch (error) {
123
+ // Throw a custom error with a clear message including the file path
124
+ throw new Error(`Failed to parse JSON. The file at "${path}" is not valid JSON.`);
125
+ }
120
126
  }).filter(Boolean);
121
127
  // filter out schemas (e.g. draft-04/schema )
122
128
  const schemas = this.definitions.filter(schema => this.isSchema(schema.content)).filter(Boolean);
@@ -136,6 +142,20 @@ class Registry {
136
142
  this.loadData(schema);
137
143
  });
138
144
  }
145
+ mapSchemas(mapper) {
146
+ return Object.entries(this.schemaMappings).map(([title, schema]) => {
147
+ if (schema)
148
+ return [title, schema];
149
+ }).filter(Boolean)
150
+ .map(mapper);
151
+ }
152
+ forEachSchemas(mapper) {
153
+ return Object.entries(this.schemaMappings).map(([title, schema]) => {
154
+ if (schema)
155
+ return [title, schema];
156
+ }).filter(Boolean)
157
+ .forEach(mapper);
158
+ }
139
159
  get chains() {
140
160
  return this.dataMappings.Chain.map(c => c.content);
141
161
  }
@@ -152,7 +172,7 @@ class Registry {
152
172
  return this.dataMappings.Versions.map(c => c.content);
153
173
  }
154
174
  get schemas() {
155
- return Object.entries(this.schemaMappings).map(([_str, obj]) => {
175
+ return this.mapSchemas(([_str, obj]) => {
156
176
  return obj;
157
177
  });
158
178
  }
package/validator.js CHANGED
@@ -22,7 +22,7 @@ class SchemaValidator {
22
22
  }
23
23
  validateAllData(verbose = false) {
24
24
  // Compile and validate each schema, then validate corresponding data
25
- Object.entries(this.registry.schemaMappings).forEach(([title, schema]) => {
25
+ this.registry.forEachSchemas(([title, schema]) => {
26
26
  schema.content.$schema = 'https://json-schema.org/draft/2019-09/schema';
27
27
  const validate = this.ajv.compile(schema.content);
28
28
  const dataMap = this.registry.dataMappings[title];