@polkadot/rpc-core 6.6.2-1 → 6.6.2-10

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/bundle.cjs CHANGED
@@ -67,15 +67,19 @@ const EMPTY_META = {
67
67
 
68
68
  /** @internal */
69
69
 
70
- function logErrorMessage(method, {
71
- params,
72
- type
73
- }, error) {
74
- const inputs = params.map(({
75
- isOptional,
76
- name,
70
+ function logErrorMessage(method, _ref, error) {
71
+ let {
72
+ params,
77
73
  type
78
- }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
74
+ } = _ref;
75
+ const inputs = params.map(_ref2 => {
76
+ let {
77
+ isOptional,
78
+ name,
79
+ type
80
+ } = _ref2;
81
+ return `${name}${isOptional ? '?' : ''}: ${type}`;
82
+ }).join(', ');
79
83
  l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
80
84
  }
81
85
 
@@ -123,7 +127,8 @@ class RpcCore {
123
127
  * Default constructor for the Api Object
124
128
  * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
125
129
  */
126
- constructor(instanceId, registry, provider, userRpc = {}) {
130
+ constructor(instanceId, registry, provider) {
131
+ let userRpc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
127
132
  Object.defineProperty(this, _instanceId, {
128
133
  writable: true,
129
134
  value: void 0
@@ -194,22 +199,27 @@ class RpcCore {
194
199
  this.sections.push(...Object.keys(userRpc).filter(key => !this.sections.includes(key))); // decorate the sections with base and user methods
195
200
 
196
201
  this.sections.forEach(sectionName => {
197
- var _ref, _ref2;
202
+ var _ref3, _ref4;
198
203
 
199
- (_ref = this)[_ref2 = sectionName] || (_ref[_ref2] = {});
204
+ (_ref3 = this)[_ref4 = sectionName] || (_ref3[_ref4] = {});
200
205
  const section = this[sectionName];
201
- Object.entries(_objectSpread(_objectSpread({}, this._createInterface(sectionName, _types.rpcDefinitions[sectionName] || {})), this._createInterface(sectionName, userRpc[sectionName] || {}))).forEach(([key, value]) => {
206
+ Object.entries(_objectSpread(_objectSpread({}, this._createInterface(sectionName, _types.rpcDefinitions[sectionName] || {})), this._createInterface(sectionName, userRpc[sectionName] || {}))).forEach(_ref5 => {
207
+ let [key, value] = _ref5;
202
208
  section[key] || (section[key] = value);
203
209
  });
204
210
  });
205
211
  }
206
212
 
207
213
  _createInterface(section, methods) {
208
- return Object.entries(methods).filter(([method, {
209
- endpoint
210
- }]) => !this.mapping.has(endpoint || `${section}_${method}`)).reduce((exposed, [method, {
211
- endpoint
212
- }]) => {
214
+ return Object.entries(methods).filter(_ref6 => {
215
+ let [method, {
216
+ endpoint
217
+ }] = _ref6;
218
+ return !this.mapping.has(endpoint || `${section}_${method}`);
219
+ }).reduce((exposed, _ref7) => {
220
+ let [method, {
221
+ endpoint
222
+ }] = _ref7;
213
223
  const def = methods[method];
214
224
  const isSubscription = !!def.pubsub;
215
225
  const jsonrpc = endpoint || `${section}_${method}`;
@@ -240,9 +250,12 @@ class RpcCore {
240
250
 
241
251
  _createMethodSend(section, method, def) {
242
252
  const rpcName = def.endpoint || `${section}_${method}`;
243
- const hashIndex = def.params.findIndex(({
244
- isHistoric
245
- }) => isHistoric);
253
+ const hashIndex = def.params.findIndex(_ref8 => {
254
+ let {
255
+ isHistoric
256
+ } = _ref8;
257
+ return isHistoric;
258
+ });
246
259
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
247
260
 
248
261
  const callWithRegistry = async (isScale, values) => {
@@ -259,7 +272,11 @@ class RpcCore {
259
272
  return this._formatResult(isScale, registry, blockHash, method, def, params, result);
260
273
  };
261
274
 
262
- const creator = isScale => (...values) => {
275
+ const creator = isScale => function () {
276
+ for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
277
+ values[_key] = arguments[_key];
278
+ }
279
+
263
280
  const isDelayed = isScale && hashIndex !== -1 && !!values[hashIndex];
264
281
  return new _rxjs.Observable(observer => {
265
282
  callWithRegistry(isScale, values).then(value => {
@@ -286,12 +303,13 @@ class RpcCore {
286
303
  } // create a subscriptor, it subscribes once and resolves with the id as subscribe
287
304
 
288
305
 
289
- _createSubscriber({
290
- paramsJson,
291
- subName,
292
- subType,
293
- update
294
- }, errorHandler) {
306
+ _createSubscriber(_ref9, errorHandler) {
307
+ let {
308
+ paramsJson,
309
+ subName,
310
+ subType,
311
+ update
312
+ } = _ref9;
295
313
  return new Promise((resolve, reject) => {
296
314
  this.provider.subscribe(subType, subName, paramsJson, update).then(resolve).catch(error => {
297
315
  errorHandler(error);
@@ -301,18 +319,24 @@ class RpcCore {
301
319
  }
302
320
 
303
321
  _createMethodSubscribe(section, method, def) {
322
+ var _this = this;
323
+
304
324
  const [updateType, subMethod, unsubMethod] = def.pubsub;
305
325
  const subName = `${section}_${subMethod}`;
306
326
  const unsubName = `${section}_${unsubMethod}`;
307
327
  const subType = `${section}_${updateType}`;
308
328
  let memoized = null;
309
329
 
310
- const creator = isScale => (...values) => {
330
+ const creator = isScale => function () {
331
+ for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
332
+ values[_key2] = arguments[_key2];
333
+ }
334
+
311
335
  return new _rxjs.Observable(observer => {
312
336
  // Have at least an empty promise, as used in the unsubscribe
313
337
  let subscriptionPromise = Promise.resolve(null);
314
338
 
315
- const registry = (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault];
339
+ const registry = (0, _classPrivateFieldLooseBase2.default)(_this, _registryDefault)[_registryDefault];
316
340
 
317
341
  const errorHandler = error => {
318
342
  logErrorMessage(method, def, error);
@@ -320,7 +344,7 @@ class RpcCore {
320
344
  };
321
345
 
322
346
  try {
323
- const params = this._formatInputs(registry, null, def, values);
347
+ const params = _this._formatInputs(registry, null, def, values);
324
348
 
325
349
  const paramsJson = params.map(p => p.toJSON());
326
350
 
@@ -331,13 +355,13 @@ class RpcCore {
331
355
  }
332
356
 
333
357
  try {
334
- observer.next(this._formatResult(isScale, registry, null, method, def, params, result));
358
+ observer.next(_this._formatResult(isScale, registry, null, method, def, params, result));
335
359
  } catch (error) {
336
360
  observer.error(error);
337
361
  }
338
362
  };
339
363
 
340
- subscriptionPromise = this._createSubscriber({
364
+ subscriptionPromise = _this._createSubscriber({
341
365
  paramsJson,
342
366
  subName,
343
367
  subType,
@@ -354,7 +378,7 @@ class RpcCore {
354
378
  // Delete from cache, so old results don't hang around
355
379
  (_memoized2 = memoized) === null || _memoized2 === void 0 ? void 0 : _memoized2.unmemoize(...values); // Unsubscribe from provider
356
380
 
357
- subscriptionPromise.then(subscriptionId => (0, _util.isNull)(subscriptionId) ? Promise.resolve(false) : this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
381
+ subscriptionPromise.then(subscriptionId => (0, _util.isNull)(subscriptionId) ? Promise.resolve(false) : _this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
358
382
  };
359
383
  }).pipe((0, _index.drr)());
360
384
  };
@@ -364,9 +388,12 @@ class RpcCore {
364
388
  }
365
389
 
366
390
  _formatInputs(registry, blockHash, def, inputs) {
367
- const reqArgCount = def.params.filter(({
368
- isOptional
369
- }) => !isOptional).length;
391
+ const reqArgCount = def.params.filter(_ref10 => {
392
+ let {
393
+ isOptional
394
+ } = _ref10;
395
+ return !isOptional;
396
+ }).length;
370
397
  const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
371
398
  (0, _util.assert)(inputs.length >= reqArgCount && inputs.length <= def.params.length, () => `Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
372
399
  return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], {
@@ -382,10 +409,13 @@ class RpcCore {
382
409
  const keys = params[0];
383
410
  return keys ? this._formatStorageSet(registry, result.block, keys, result.changes) : registry.createType('StorageChangeSet', result);
384
411
  } else if (rpc.type === 'Vec<StorageChangeSet>') {
385
- const mapped = result.map(({
386
- block,
387
- changes
388
- }) => [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)]); // we only query at a specific block, not a range - flatten
412
+ const mapped = result.map(_ref11 => {
413
+ let {
414
+ block,
415
+ changes
416
+ } = _ref11;
417
+ return [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)];
418
+ }); // we only query at a specific block, not a range - flatten
389
419
 
390
420
  return method === 'queryStorageAt' ? mapped[0][1] : mapped;
391
421
  }
@@ -418,7 +448,10 @@ class RpcCore {
418
448
 
419
449
  _formatStorageSetEntry(registry, blockHash, key, changes, witCache, entryIndex) {
420
450
  const hexKey = key.toHex();
421
- const found = changes.find(([key]) => key === hexKey); // if we don't find the value, this is our fallback
451
+ const found = changes.find(_ref12 => {
452
+ let [key] = _ref12;
453
+ return key === hexKey;
454
+ }); // if we don't find the value, this is our fallback
422
455
  // - in the case of an array of values, fill the hole from the cache
423
456
  // - if a single result value, don't fill - it is not an update hole
424
457
  // - fallback to an empty option in all cases
@@ -434,7 +467,8 @@ class RpcCore {
434
467
  return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
435
468
  }
436
469
 
437
- _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
470
+ _newType(registry, blockHash, key, input, isEmpty) {
471
+ let entryIndex = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1;
438
472
  // single return value (via state.getStorage), decode the value based on the
439
473
  // outputType that we have specified. Fallback to Raw on nothing
440
474
  const type = key.outputType || 'Raw';
package/package.json CHANGED
@@ -20,12 +20,12 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "6.6.2-1",
23
+ "version": "6.6.2-10",
24
24
  "main": "index.js",
25
25
  "dependencies": {
26
- "@babel/runtime": "^7.15.4",
27
- "@polkadot/rpc-provider": "6.6.2-1",
28
- "@polkadot/types": "6.6.2-1",
26
+ "@babel/runtime": "^7.16.0",
27
+ "@polkadot/rpc-provider": "6.6.2-10",
28
+ "@polkadot/types": "6.6.2-10",
29
29
  "@polkadot/util": "^7.7.1",
30
30
  "rxjs": "^7.4.0"
31
31
  },
package/packageInfo.cjs CHANGED
@@ -9,6 +9,6 @@ exports.packageInfo = void 0;
9
9
  // Auto-generated by @polkadot/dev, do not edit
10
10
  const packageInfo = {
11
11
  name: '@polkadot/rpc-core',
12
- version: '6.6.2-1'
12
+ version: '6.6.2-10'
13
13
  };
14
14
  exports.packageInfo = packageInfo;
package/packageInfo.js CHANGED
@@ -3,5 +3,5 @@
3
3
  // Auto-generated by @polkadot/dev, do not edit
4
4
  export const packageInfo = {
5
5
  name: '@polkadot/rpc-core',
6
- version: '6.6.2-1'
6
+ version: '6.6.2-10'
7
7
  };
package/util/drr.cjs CHANGED
@@ -35,10 +35,13 @@ const NOOP = () => undefined;
35
35
  */
36
36
 
37
37
 
38
- const drr = ({
39
- delay,
40
- skipChange = false,
41
- skipTimeout = false
42
- } = {}) => source$ => source$.pipe((0, _rxjs.catchError)(ERR), skipChange ? (0, _rxjs.tap)(NOOP) : (0, _rxjs.distinctUntilChanged)(CMP), (0, _rxjs.publishReplay)(1), skipTimeout ? (0, _rxjs.refCount)() : (0, _refCountDelay.refCountDelay)(delay));
38
+ const drr = function () {
39
+ let {
40
+ delay,
41
+ skipChange = false,
42
+ skipTimeout = false
43
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
44
+ return source$ => source$.pipe((0, _rxjs.catchError)(ERR), skipChange ? (0, _rxjs.tap)(NOOP) : (0, _rxjs.distinctUntilChanged)(CMP), (0, _rxjs.publishReplay)(1), skipTimeout ? (0, _rxjs.refCount)() : (0, _refCountDelay.refCountDelay)(delay));
45
+ };
43
46
 
44
47
  exports.drr = drr;
package/util/memo.cjs CHANGED
@@ -23,12 +23,18 @@ function memo(instanceId, inner) {
23
23
  const options = {
24
24
  getInstanceId: () => instanceId
25
25
  };
26
- const cached = (0, _util.memoize)((...params) => new _rxjs.Observable(observer => {
27
- const subscription = inner(...params).subscribe(observer);
28
- return () => {
29
- cached.unmemoize(...params);
30
- subscription.unsubscribe();
31
- };
32
- }).pipe((0, _drr.drr)()), options);
26
+ const cached = (0, _util.memoize)(function () {
27
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
28
+ params[_key] = arguments[_key];
29
+ }
30
+
31
+ return new _rxjs.Observable(observer => {
32
+ const subscription = inner(...params).subscribe(observer);
33
+ return () => {
34
+ cached.unmemoize(...params);
35
+ subscription.unsubscribe();
36
+ };
37
+ }).pipe((0, _drr.drr)());
38
+ }, options);
33
39
  return cached;
34
40
  }
@@ -11,7 +11,8 @@ var _rxjs = require("rxjs");
11
11
  // SPDX-License-Identifier: Apache-2.0
12
12
 
13
13
  /** @internal */
14
- function refCountDelay(delay = 1750) {
14
+ function refCountDelay() {
15
+ let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1750;
15
16
  return source => {
16
17
  // state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
17
18
  let [state, refCount, connection, scheduler] = [0, 0, _rxjs.Subscription.EMPTY, _rxjs.Subscription.EMPTY];