@chain-registry/utils 1.0.0 → 1.1.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.1.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.0.1...@chain-registry/utils@1.1.0) (2022-10-20)
7
+
8
+ **Note:** Version bump only for package @chain-registry/utils
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.0.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.0.0...@chain-registry/utils@1.0.1) (2022-10-20)
15
+
16
+ **Note:** Version bump only for package @chain-registry/utils
17
+
18
+
19
+
20
+
21
+
6
22
  # [1.0.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.11.0...@chain-registry/utils@1.0.0) (2022-09-29)
7
23
 
8
24
  **Note:** Version bump only for package @chain-registry/utils
package/README.md CHANGED
@@ -13,90 +13,6 @@
13
13
  </p>
14
14
 
15
15
  Utility functions for the chain-registry
16
-
17
-
18
- ## Usage
19
-
20
- ```js
21
- import { ChainRegistryFetcher, ChainRegistryFetcherOptions } from '@chain-registry/utils';
22
-
23
- const options: ChainRegistryFetcherOptions = {
24
- urls: [
25
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/chain.json',
26
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json',
27
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json',
28
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/secretnetwork/assetlist.json',
29
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/juno-osmosis.json',
30
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/osmosis-secretnetwork.json'
31
- ]
32
- };
33
- const registry = new ChainRegistry(options);
34
- await registry.fetchUrls();
35
- ```
36
-
37
- ## Fetching Schemata
38
-
39
- We currently only support fetching JSON schemas as defined in https://github.com/cosmos/chain-registry. Supported are `assetlist.schema.json`, `chain.schema.json` and `ibc_data.schema.json`.
40
-
41
- ### fetchUrls
42
-
43
- You can set the `ChainRegistry.urls` property and call `ChainRegistry.fetchUrls()`
44
-
45
- ```js
46
- registry.urls = [
47
- // urls to fetch
48
- ];
49
- await registry.fetchUrls();
50
- ```
51
-
52
- ### fetch
53
-
54
- Or, you can simply call `ChainRegistry.fetch()`
55
-
56
- ```js
57
- await registry.fetch('https://some-json-schema.com/some-schema.json');
58
- ```
59
-
60
- ## Asset lists
61
-
62
- You can get generated asset lists directly from the registry:
63
-
64
- ```js
65
- // generated asset lists
66
- const generated: AssetList[] = registry.getGeneratedAssetLists('osmosis');
67
- ```
68
-
69
- You can get generated `AssetList[]` objects directly from the `ChainRegistry` via the `assetLists` method:
70
-
71
- ```js
72
- // you can also get generated assets from ChainInfo object
73
- const chainInfo: Chain = registry.getChainInfo('osmosis');
74
- const generatedAssets: AssetList[] = chainInfo.assetLists;
75
- ```
76
- ## Chain info
77
-
78
- You can get `Chain` object directly from the `ChainRegistry` via the `getChain` method:
79
-
80
- ```js
81
- // get Chain from registry
82
- const chain: Chain = registry.getChain('osmosis');
83
- ```
84
-
85
- or get the `ChainInfo` object:
86
-
87
- ```js
88
- const chainInfo: ChainInfo = registry.getChainInfo('osmosis');
89
-
90
- // AssetList[] of the generated assets
91
- const assetes: AssetList[] = chainInfo.assetLists;
92
-
93
- // Chain
94
- const chain: Chain = chainInfo.chain;
95
-
96
- // AssetList[] of the native assets
97
- const assetes: AssetList[] = chainInfo.nativeAssetLists;
98
- ```
99
-
100
16
  ## Credits
101
17
 
102
18
  🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)
package/main/index.js CHANGED
@@ -4,19 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _registry = require("./registry");
8
-
9
- Object.keys(_registry).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _registry[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function get() {
15
- return _registry[key];
16
- }
17
- });
18
- });
19
-
20
7
  var _utils = require("./utils");
21
8
 
22
9
  Object.keys(_utils).forEach(function (key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/utils",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Chain Registry Utils",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmology-tech/chain-registry",
@@ -73,10 +73,8 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@babel/runtime": "^7.19.0",
76
- "@chain-registry/types": "^0.11.0",
77
- "bfs-path": "^1.0.2",
78
- "cross-fetch": "^3.1.5",
76
+ "@chain-registry/types": "^0.12.0",
79
77
  "sha.js": "^2.4.11"
80
78
  },
81
- "gitHead": "3f6b00c23df64fdac243ae5b6af41a69fcf27755"
79
+ "gitHead": "1f570daf2ee8e4a86cd7addf97f453a322b2e9b3"
82
80
  }
package/types/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- export * from './registry';
2
1
  export * from './utils';
package/main/registry.js DELETED
@@ -1,313 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.ChainRegistryFetcher = exports.ChainInfo = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
- var _bfsPath = require("bfs-path");
21
-
22
- var _crossFetch = _interopRequireDefault(require("cross-fetch"));
23
-
24
- var _utils = require("./utils");
25
-
26
- var fetchUrl = function fetchUrl(url) {
27
- return (0, _crossFetch["default"])(url).then(function (res) {
28
- if (res.status >= 400) {
29
- throw new Error('Bad response');
30
- }
31
-
32
- return res.json();
33
- });
34
- };
35
-
36
- var ChainInfo = /*#__PURE__*/function () {
37
- function ChainInfo(options) {
38
- (0, _classCallCheck2["default"])(this, ChainInfo);
39
- (0, _defineProperty2["default"])(this, "chain_name", void 0);
40
- (0, _defineProperty2["default"])(this, "fetcher", void 0);
41
- (0, _defineProperty2["default"])(this, "_asset_list", void 0);
42
- (0, _defineProperty2["default"])(this, "_asset_lists", void 0);
43
- (0, _defineProperty2["default"])(this, "_chain", void 0);
44
- (0, _defineProperty2["default"])(this, "_ibc_data", []);
45
- this.chain_name = options.chain_name;
46
- this.fetcher = options.fetcher;
47
- this.refresh();
48
- }
49
-
50
- (0, _createClass2["default"])(ChainInfo, [{
51
- key: "refresh",
52
- value: function refresh() {
53
- this._asset_list = this.fetcher.getChainAssetList(this.chain_name);
54
- this._ibc_data = this.fetcher.getChainIbcData(this.chain_name);
55
- this._chain = this.fetcher.getChain(this.chain_name);
56
-
57
- var supportedChains = this._ibc_data.reduce(function (m, v) {
58
- if (!m.includes(v.chain_1.chain_name)) m.push(v.chain_1.chain_name);
59
- if (!m.includes(v.chain_2.chain_name)) m.push(v.chain_2.chain_name);
60
- return m;
61
- }, []);
62
-
63
- this._asset_lists = this.fetcher.assetLists.filter(function (list) {
64
- return supportedChains.includes(list.chain_name);
65
- });
66
- }
67
- }, {
68
- key: "nativeAssetLists",
69
- get: function get() {
70
- return this._asset_list;
71
- }
72
- }, {
73
- key: "chain",
74
- get: function get() {
75
- return this._chain;
76
- }
77
- }, {
78
- key: "assetLists",
79
- get: function get() {
80
- return (0, _utils.getAssetLists)(this.chain_name, this._ibc_data, this._asset_lists);
81
- }
82
- }]);
83
- return ChainInfo;
84
- }(); // QUESTION: should ChainRegistryFetcher just be ChainRegistry?
85
-
86
-
87
- exports.ChainInfo = ChainInfo;
88
-
89
- var ChainRegistryFetcher = /*#__PURE__*/function () {
90
- function ChainRegistryFetcher() {
91
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92
- (0, _classCallCheck2["default"])(this, ChainRegistryFetcher);
93
- (0, _defineProperty2["default"])(this, "_asset_lists", []);
94
- (0, _defineProperty2["default"])(this, "_chains", []);
95
- (0, _defineProperty2["default"])(this, "_ibc_data", []);
96
- (0, _defineProperty2["default"])(this, "urls", []);
97
-
98
- //
99
- if (options.assetLists) {
100
- this._asset_lists = options.assetLists;
101
- }
102
-
103
- if (options.chains) {
104
- this._chains = options.chains;
105
- }
106
-
107
- if (options.ibcData) {
108
- this._ibc_data = options.ibcData;
109
- }
110
-
111
- if (options.urls) {
112
- this.urls = options.urls;
113
- }
114
- }
115
-
116
- (0, _createClass2["default"])(ChainRegistryFetcher, [{
117
- key: "assetLists",
118
- get: function get() {
119
- return this._asset_lists;
120
- }
121
- }, {
122
- key: "getChainAssetList",
123
- value: function getChainAssetList(chainName) {
124
- return this._asset_lists.find(function (list) {
125
- return list.chain_name === chainName;
126
- });
127
- }
128
- }, {
129
- key: "getGeneratedAssetLists",
130
- value: function getGeneratedAssetLists(chainName) {
131
- return (0, _utils.getAssetLists)(chainName, this._ibc_data, this._asset_lists);
132
- }
133
- }, {
134
- key: "chains",
135
- get: function get() {
136
- return this._chains;
137
- }
138
- }, {
139
- key: "getChain",
140
- value: function getChain(chainName) {
141
- return this._chains.find(function (chain) {
142
- return chain.chain_name === chainName;
143
- });
144
- }
145
- }, {
146
- key: "ibcData",
147
- get: function get() {
148
- return this._ibc_data;
149
- }
150
- }, {
151
- key: "getChainIbcData",
152
- value: function getChainIbcData(chainName) {
153
- return this._ibc_data.filter(function (info) {
154
- return info.chain_1.chain_name === chainName || info.chain_2.chain_name === chainName;
155
- });
156
- }
157
- }, {
158
- key: "getChainInfo",
159
- value: function getChainInfo(chainName) {
160
- return new ChainInfo({
161
- chain_name: chainName,
162
- fetcher: this
163
- });
164
- }
165
- }, {
166
- key: "upsertChain",
167
- value: function upsertChain(data) {
168
- var found = this._chains.find(function (chain) {
169
- return chain.chain_name === data.chain_name && chain.network_type === data.network_type;
170
- });
171
-
172
- if (!found) {
173
- this._chains.push(data);
174
-
175
- return;
176
- }
177
-
178
- this._chains = this._chains.map(function (chain) {
179
- if (chain.chain_name === data.chain_name && chain.network_type === data.network_type) {
180
- return data;
181
- } else {
182
- return chain;
183
- }
184
- });
185
- }
186
- }, {
187
- key: "updateAssetList",
188
- value: function updateAssetList(data) {
189
- var found = this._asset_lists.find(function (list) {
190
- return list.chain_name === data.chain_name;
191
- });
192
-
193
- if (!found) {
194
- this._asset_lists.push(data);
195
-
196
- return;
197
- }
198
-
199
- this._asset_lists = this._asset_lists.map(function (list) {
200
- if (list.chain_name === data.chain_name) {
201
- return data;
202
- } else {
203
- return list;
204
- }
205
- });
206
- }
207
- }, {
208
- key: "upsertIbcData",
209
- value: function upsertIbcData(data) {
210
- var found = this._ibc_data.find(function (info) {
211
- return info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name;
212
- });
213
-
214
- if (!found) {
215
- this._ibc_data.push(data);
216
-
217
- return;
218
- }
219
-
220
- this._ibc_data = this._ibc_data.map(function (info) {
221
- if (info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name) {
222
- return data;
223
- } else {
224
- return info;
225
- }
226
- });
227
- }
228
- }, {
229
- key: "update",
230
- value: function update(data) {
231
- if (!data.$schema) throw new Error('not a registered JSON schema type');
232
- var type = (0, _bfsPath.basename)(data.$schema, '.schema.json');
233
-
234
- switch (type) {
235
- case 'chain':
236
- this.upsertChain(data);
237
- break;
238
-
239
- case 'assetlist':
240
- this.updateAssetList(data);
241
- break;
242
-
243
- case 'ibc_data':
244
- this.upsertIbcData(data);
245
- break;
246
-
247
- default:
248
- throw new Error('unknown schema type');
249
- }
250
- }
251
- }, {
252
- key: "fetch",
253
- value: function () {
254
- var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(url) {
255
- var data;
256
- return _regenerator["default"].wrap(function _callee$(_context) {
257
- while (1) {
258
- switch (_context.prev = _context.next) {
259
- case 0:
260
- _context.next = 2;
261
- return fetchUrl(url);
262
-
263
- case 2:
264
- data = _context.sent;
265
- this.update(data);
266
-
267
- case 4:
268
- case "end":
269
- return _context.stop();
270
- }
271
- }
272
- }, _callee, this);
273
- }));
274
-
275
- function fetch(_x) {
276
- return _fetch.apply(this, arguments);
277
- }
278
-
279
- return fetch;
280
- }()
281
- }, {
282
- key: "fetchUrls",
283
- value: function () {
284
- var _fetchUrls = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
285
- var _this = this;
286
-
287
- return _regenerator["default"].wrap(function _callee2$(_context2) {
288
- while (1) {
289
- switch (_context2.prev = _context2.next) {
290
- case 0:
291
- return _context2.abrupt("return", Promise.all(this.urls.map(function (url) {
292
- return _this.fetch(url);
293
- })));
294
-
295
- case 1:
296
- case "end":
297
- return _context2.stop();
298
- }
299
- }
300
- }, _callee2, this);
301
- }));
302
-
303
- function fetchUrls() {
304
- return _fetchUrls.apply(this, arguments);
305
- }
306
-
307
- return fetchUrls;
308
- }()
309
- }]);
310
- return ChainRegistryFetcher;
311
- }();
312
-
313
- exports.ChainRegistryFetcher = ChainRegistryFetcher;