@polkadot/rpc-core 6.6.2-2 → 6.6.2-23

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
@@ -19,9 +19,9 @@ Object.defineProperty(exports, "packageInfo", {
19
19
 
20
20
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
21
21
 
22
- var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
22
+ var _classPrivateFieldGet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldGet"));
23
23
 
24
- var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
24
+ var _classPrivateFieldSet2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldSet"));
25
25
 
26
26
  var _rxjs = require("rxjs");
27
27
 
@@ -45,9 +45,9 @@ Object.keys(_index).forEach(function (key) {
45
45
 
46
46
  var _packageInfo = require("./packageInfo.cjs");
47
47
 
48
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
48
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
49
49
 
50
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
50
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
51
51
 
52
52
  const l = (0, _util.logger)('rpc-core');
53
53
  const EMPTY_META = {
@@ -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
 
@@ -109,13 +113,13 @@ function isTreatAsHex(key) {
109
113
  */
110
114
 
111
115
 
112
- var _instanceId = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("instanceId");
116
+ var _instanceId = /*#__PURE__*/new WeakMap();
113
117
 
114
- var _registryDefault = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("registryDefault");
118
+ var _registryDefault = /*#__PURE__*/new WeakMap();
115
119
 
116
- var _getBlockRegistry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("getBlockRegistry");
120
+ var _getBlockRegistry = /*#__PURE__*/new WeakMap();
117
121
 
118
- var _storageCache = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("storageCache");
122
+ var _storageCache = /*#__PURE__*/new WeakMap();
119
123
 
120
124
  class RpcCore {
121
125
  /**
@@ -123,30 +127,36 @@ 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 = {}) {
127
- Object.defineProperty(this, _instanceId, {
130
+ constructor(instanceId, registry, provider) {
131
+ let userRpc = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
132
+
133
+ _classPrivateFieldInitSpec(this, _instanceId, {
128
134
  writable: true,
129
135
  value: void 0
130
136
  });
131
- Object.defineProperty(this, _registryDefault, {
137
+
138
+ _classPrivateFieldInitSpec(this, _registryDefault, {
132
139
  writable: true,
133
140
  value: void 0
134
141
  });
135
- Object.defineProperty(this, _getBlockRegistry, {
142
+
143
+ _classPrivateFieldInitSpec(this, _getBlockRegistry, {
136
144
  writable: true,
137
145
  value: void 0
138
146
  });
139
- Object.defineProperty(this, _storageCache, {
147
+
148
+ _classPrivateFieldInitSpec(this, _storageCache, {
140
149
  writable: true,
141
150
  value: new Map()
142
151
  });
143
- this.mapping = new Map();
144
- this.provider = void 0;
145
- this.sections = [];
152
+
153
+ (0, _defineProperty2.default)(this, "mapping", new Map());
154
+ (0, _defineProperty2.default)(this, "provider", void 0);
155
+ (0, _defineProperty2.default)(this, "sections", []);
146
156
  // eslint-disable-next-line @typescript-eslint/unbound-method
147
157
  (0, _util.assert)(provider && (0, _util.isFunction)(provider.send), 'Expected Provider to API create');
148
- (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId] = instanceId;
149
- (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault] = registry;
158
+ (0, _classPrivateFieldSet2.default)(this, _instanceId, instanceId);
159
+ (0, _classPrivateFieldSet2.default)(this, _registryDefault, registry);
150
160
  this.provider = provider;
151
161
  const sectionNames = Object.keys(_types.rpcDefinitions); // these are the base keys (i.e. part of jsonrpc)
152
162
 
@@ -184,49 +194,47 @@ class RpcCore {
184
194
 
185
195
 
186
196
  setRegistrySwap(registrySwap) {
187
- (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry] = (0, _util.memoize)(registrySwap, {
188
- getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
189
- });
197
+ (0, _classPrivateFieldSet2.default)(this, _getBlockRegistry, (0, _util.memoize)(registrySwap, {
198
+ getInstanceId: () => (0, _classPrivateFieldGet2.default)(this, _instanceId)
199
+ }));
190
200
  }
191
201
 
192
202
  addUserInterfaces(userRpc) {
193
203
  // add any extra user-defined sections
194
- this.sections.push(...Object.keys(userRpc).filter(key => !this.sections.includes(key))); // decorate the sections with base and user methods
195
-
196
- this.sections.forEach(sectionName => {
197
- var _ref, _ref2;
198
-
199
- (_ref = this)[_ref2 = sectionName] || (_ref[_ref2] = {});
200
- const section = this[sectionName];
201
- Object.entries(_objectSpread(_objectSpread({}, this._createInterface(sectionName, _types.rpcDefinitions[sectionName] || {})), this._createInterface(sectionName, userRpc[sectionName] || {}))).forEach(([key, value]) => {
202
- section[key] || (section[key] = value);
203
- });
204
- });
205
- }
206
-
207
- _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
- }]) => {
213
- const def = methods[method];
214
- const isSubscription = !!def.pubsub;
215
- const jsonrpc = endpoint || `${section}_${method}`;
216
- this.mapping.set(jsonrpc, _objectSpread(_objectSpread({}, def), {}, {
217
- isSubscription,
218
- jsonrpc,
219
- method,
220
- section
221
- }));
222
- exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
223
- return exposed;
224
- }, {});
204
+ this.sections.push(...Object.keys(userRpc).filter(k => !this.sections.includes(k)));
205
+
206
+ for (let s = 0; s < this.sections.length; s++) {
207
+ const section = this.sections[s];
208
+ const defs = (0, _util.objectSpread)({}, _types.rpcDefinitions[section], userRpc[section]);
209
+ const methods = Object.keys(defs);
210
+
211
+ for (let m = 0; m < methods.length; m++) {
212
+ const method = methods[m];
213
+ const def = defs[method];
214
+ const jsonrpc = def.endpoint || `${section}_${method}`;
215
+
216
+ if (!this.mapping.has(jsonrpc)) {
217
+ const isSubscription = !!def.pubsub;
218
+
219
+ if (!this[section]) {
220
+ this[section] = {};
221
+ }
222
+
223
+ this.mapping.set(jsonrpc, (0, _util.objectSpread)({}, def, {
224
+ isSubscription,
225
+ jsonrpc,
226
+ method,
227
+ section
228
+ }));
229
+ (0, _util.lazyMethod)(this[section], method, () => isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def));
230
+ }
231
+ }
232
+ }
225
233
  }
226
234
 
227
235
  _memomize(creator, def) {
228
236
  const memoOpts = {
229
- getInstanceId: () => (0, _classPrivateFieldLooseBase2.default)(this, _instanceId)[_instanceId]
237
+ getInstanceId: () => (0, _classPrivateFieldGet2.default)(this, _instanceId)
230
238
  };
231
239
  const memoized = (0, _util.memoize)(creator(true), memoOpts);
232
240
  memoized.raw = (0, _util.memoize)(creator(false), memoOpts);
@@ -240,17 +248,20 @@ class RpcCore {
240
248
 
241
249
  _createMethodSend(section, method, def) {
242
250
  const rpcName = def.endpoint || `${section}_${method}`;
243
- const hashIndex = def.params.findIndex(({
244
- isHistoric
245
- }) => isHistoric);
251
+ const hashIndex = def.params.findIndex(_ref3 => {
252
+ let {
253
+ isHistoric
254
+ } = _ref3;
255
+ return isHistoric;
256
+ });
246
257
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
247
258
 
248
259
  const callWithRegistry = async (isScale, values) => {
249
260
  const blockHash = hashIndex === -1 ? null : values[hashIndex];
250
261
  const {
251
262
  registry
252
- } = isScale && blockHash && (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry] ? await (0, _classPrivateFieldLooseBase2.default)(this, _getBlockRegistry)[_getBlockRegistry]((0, _util.u8aToU8a)(blockHash)) : {
253
- registry: (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault]
263
+ } = isScale && blockHash && (0, _classPrivateFieldGet2.default)(this, _getBlockRegistry) ? await (0, _classPrivateFieldGet2.default)(this, _getBlockRegistry).call(this, (0, _util.u8aToU8a)(blockHash)) : {
264
+ registry: (0, _classPrivateFieldGet2.default)(this, _registryDefault)
254
265
  };
255
266
 
256
267
  const params = this._formatInputs(registry, null, def, values);
@@ -259,7 +270,11 @@ class RpcCore {
259
270
  return this._formatResult(isScale, registry, blockHash, method, def, params, result);
260
271
  };
261
272
 
262
- const creator = isScale => (...values) => {
273
+ const creator = isScale => function () {
274
+ for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
275
+ values[_key] = arguments[_key];
276
+ }
277
+
263
278
  const isDelayed = isScale && hashIndex !== -1 && !!values[hashIndex];
264
279
  return new _rxjs.Observable(observer => {
265
280
  callWithRegistry(isScale, values).then(value => {
@@ -286,12 +301,13 @@ class RpcCore {
286
301
  } // create a subscriptor, it subscribes once and resolves with the id as subscribe
287
302
 
288
303
 
289
- _createSubscriber({
290
- paramsJson,
291
- subName,
292
- subType,
293
- update
294
- }, errorHandler) {
304
+ _createSubscriber(_ref4, errorHandler) {
305
+ let {
306
+ paramsJson,
307
+ subName,
308
+ subType,
309
+ update
310
+ } = _ref4;
295
311
  return new Promise((resolve, reject) => {
296
312
  this.provider.subscribe(subType, subName, paramsJson, update).then(resolve).catch(error => {
297
313
  errorHandler(error);
@@ -301,18 +317,23 @@ class RpcCore {
301
317
  }
302
318
 
303
319
  _createMethodSubscribe(section, method, def) {
320
+ var _this = this;
321
+
304
322
  const [updateType, subMethod, unsubMethod] = def.pubsub;
305
323
  const subName = `${section}_${subMethod}`;
306
324
  const unsubName = `${section}_${unsubMethod}`;
307
325
  const subType = `${section}_${updateType}`;
308
326
  let memoized = null;
309
327
 
310
- const creator = isScale => (...values) => {
328
+ const creator = isScale => function () {
329
+ for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
330
+ values[_key2] = arguments[_key2];
331
+ }
332
+
311
333
  return new _rxjs.Observable(observer => {
312
334
  // Have at least an empty promise, as used in the unsubscribe
313
335
  let subscriptionPromise = Promise.resolve(null);
314
-
315
- const registry = (0, _classPrivateFieldLooseBase2.default)(this, _registryDefault)[_registryDefault];
336
+ const registry = (0, _classPrivateFieldGet2.default)(_this, _registryDefault);
316
337
 
317
338
  const errorHandler = error => {
318
339
  logErrorMessage(method, def, error);
@@ -320,7 +341,7 @@ class RpcCore {
320
341
  };
321
342
 
322
343
  try {
323
- const params = this._formatInputs(registry, null, def, values);
344
+ const params = _this._formatInputs(registry, null, def, values);
324
345
 
325
346
  const paramsJson = params.map(p => p.toJSON());
326
347
 
@@ -331,13 +352,13 @@ class RpcCore {
331
352
  }
332
353
 
333
354
  try {
334
- observer.next(this._formatResult(isScale, registry, null, method, def, params, result));
355
+ observer.next(_this._formatResult(isScale, registry, null, method, def, params, result));
335
356
  } catch (error) {
336
357
  observer.error(error);
337
358
  }
338
359
  };
339
360
 
340
- subscriptionPromise = this._createSubscriber({
361
+ subscriptionPromise = _this._createSubscriber({
341
362
  paramsJson,
342
363
  subName,
343
364
  subType,
@@ -354,7 +375,7 @@ class RpcCore {
354
375
  // Delete from cache, so old results don't hang around
355
376
  (_memoized2 = memoized) === null || _memoized2 === void 0 ? void 0 : _memoized2.unmemoize(...values); // Unsubscribe from provider
356
377
 
357
- subscriptionPromise.then(subscriptionId => (0, _util.isNull)(subscriptionId) ? Promise.resolve(false) : this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
378
+ subscriptionPromise.then(subscriptionId => (0, _util.isNull)(subscriptionId) ? Promise.resolve(false) : _this.provider.unsubscribe(subType, unsubName, subscriptionId)).catch(error => logErrorMessage(method, def, error));
358
379
  };
359
380
  }).pipe((0, _index.drr)());
360
381
  };
@@ -364,9 +385,12 @@ class RpcCore {
364
385
  }
365
386
 
366
387
  _formatInputs(registry, blockHash, def, inputs) {
367
- const reqArgCount = def.params.filter(({
368
- isOptional
369
- }) => !isOptional).length;
388
+ const reqArgCount = def.params.filter(_ref5 => {
389
+ let {
390
+ isOptional
391
+ } = _ref5;
392
+ return !isOptional;
393
+ }).length;
370
394
  const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
371
395
  (0, _util.assert)(inputs.length >= reqArgCount && inputs.length <= def.params.length, () => `Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
372
396
  return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], {
@@ -382,10 +406,13 @@ class RpcCore {
382
406
  const keys = params[0];
383
407
  return keys ? this._formatStorageSet(registry, result.block, keys, result.changes) : registry.createType('StorageChangeSet', result);
384
408
  } 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
409
+ const mapped = result.map(_ref6 => {
410
+ let {
411
+ block,
412
+ changes
413
+ } = _ref6;
414
+ return [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)];
415
+ }); // we only query at a specific block, not a range - flatten
389
416
 
390
417
  return method === 'queryStorageAt' ? mapped[0][1] : mapped;
391
418
  }
@@ -418,23 +445,26 @@ class RpcCore {
418
445
 
419
446
  _formatStorageSetEntry(registry, blockHash, key, changes, witCache, entryIndex) {
420
447
  const hexKey = key.toHex();
421
- const found = changes.find(([key]) => key === hexKey); // if we don't find the value, this is our fallback
448
+ const found = changes.find(_ref7 => {
449
+ let [key] = _ref7;
450
+ return key === hexKey;
451
+ }); // if we don't find the value, this is our fallback
422
452
  // - in the case of an array of values, fill the hole from the cache
423
453
  // - if a single result value, don't fill - it is not an update hole
424
454
  // - fallback to an empty option in all cases
425
455
 
426
- const value = (0, _util.isUndefined)(found) ? witCache && (0, _classPrivateFieldLooseBase2.default)(this, _storageCache)[_storageCache].get(hexKey) || null : found[1];
456
+ const value = (0, _util.isUndefined)(found) ? witCache && (0, _classPrivateFieldGet2.default)(this, _storageCache).get(hexKey) || null : found[1];
427
457
  const isEmpty = (0, _util.isNull)(value);
428
458
  const input = isEmpty || isTreatAsHex(key) ? value : (0, _util.u8aToU8a)(value); // store the retrieved result - the only issue with this cache is that there is no
429
459
  // clearing of it, so very long running processes (not just a couple of hours, longer)
430
460
  // will increase memory beyond what is allowed.
431
461
 
432
- (0, _classPrivateFieldLooseBase2.default)(this, _storageCache)[_storageCache].set(hexKey, value);
433
-
462
+ (0, _classPrivateFieldGet2.default)(this, _storageCache).set(hexKey, value);
434
463
  return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
435
464
  }
436
465
 
437
- _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
466
+ _newType(registry, blockHash, key, input, isEmpty) {
467
+ let entryIndex = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1;
438
468
  // single return value (via state.getStorage), decode the value based on the
439
469
  // outputType that we have specified. Fallback to Raw on nothing
440
470
  const type = key.outputType || 'Raw';
package/bundle.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { ProviderInterface } from '@polkadot/rpc-provider/types';
2
2
  import type { DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types';
3
- import type { RpcInterface } from './types';
4
3
  export { packageInfo } from './packageInfo';
5
4
  export * from './util';
6
5
  /**
@@ -55,8 +54,7 @@ export declare class RpcCore {
55
54
  setRegistrySwap(registrySwap: (blockHash: Uint8Array) => Promise<{
56
55
  registry: Registry;
57
56
  }>): void;
58
- addUserInterfaces<Section extends keyof RpcInterface>(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
59
- private _createInterface;
57
+ addUserInterfaces(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
60
58
  private _memomize;
61
59
  private _formatResult;
62
60
  private _createMethodSend;
package/bundle.js CHANGED
@@ -1,16 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
3
- import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
-
9
1
  // Copyright 2017-2021 @polkadot/rpc-core authors & contributors
10
2
  // SPDX-License-Identifier: Apache-2.0
11
3
  import { Observable, publishReplay, refCount } from 'rxjs';
12
4
  import { rpcDefinitions } from '@polkadot/types';
13
- import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, memoize, u8aToU8a } from '@polkadot/util';
5
+ import { assert, hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aToU8a } from '@polkadot/util';
14
6
  import { drr, refCountDelay } from "./util/index.js";
15
7
  export { packageInfo } from "./packageInfo.js";
16
8
  export * from "./util/index.js";
@@ -74,44 +66,24 @@ function isTreatAsHex(key) {
74
66
  */
75
67
 
76
68
 
77
- var _instanceId = /*#__PURE__*/_classPrivateFieldLooseKey("instanceId");
78
-
79
- var _registryDefault = /*#__PURE__*/_classPrivateFieldLooseKey("registryDefault");
80
-
81
- var _getBlockRegistry = /*#__PURE__*/_classPrivateFieldLooseKey("getBlockRegistry");
82
-
83
- var _storageCache = /*#__PURE__*/_classPrivateFieldLooseKey("storageCache");
84
-
85
69
  export class RpcCore {
70
+ #instanceId;
71
+ #registryDefault;
72
+ #getBlockRegistry;
73
+ #storageCache = new Map();
74
+ mapping = new Map();
75
+ sections = [];
86
76
  /**
87
77
  * @constructor
88
78
  * Default constructor for the Api Object
89
79
  * @param {ProviderInterface} provider An API provider using HTTP or WebSocket
90
80
  */
81
+
91
82
  constructor(instanceId, registry, provider, userRpc = {}) {
92
- Object.defineProperty(this, _instanceId, {
93
- writable: true,
94
- value: void 0
95
- });
96
- Object.defineProperty(this, _registryDefault, {
97
- writable: true,
98
- value: void 0
99
- });
100
- Object.defineProperty(this, _getBlockRegistry, {
101
- writable: true,
102
- value: void 0
103
- });
104
- Object.defineProperty(this, _storageCache, {
105
- writable: true,
106
- value: new Map()
107
- });
108
- this.mapping = new Map();
109
- this.provider = void 0;
110
- this.sections = [];
111
83
  // eslint-disable-next-line @typescript-eslint/unbound-method
112
84
  assert(provider && isFunction(provider.send), 'Expected Provider to API create');
113
- _classPrivateFieldLooseBase(this, _instanceId)[_instanceId] = instanceId;
114
- _classPrivateFieldLooseBase(this, _registryDefault)[_registryDefault] = registry;
85
+ this.#instanceId = instanceId;
86
+ this.#registryDefault = registry;
115
87
  this.provider = provider;
116
88
  const sectionNames = Object.keys(rpcDefinitions); // these are the base keys (i.e. part of jsonrpc)
117
89
 
@@ -149,49 +121,47 @@ export class RpcCore {
149
121
 
150
122
 
151
123
  setRegistrySwap(registrySwap) {
152
- _classPrivateFieldLooseBase(this, _getBlockRegistry)[_getBlockRegistry] = memoize(registrySwap, {
153
- getInstanceId: () => _classPrivateFieldLooseBase(this, _instanceId)[_instanceId]
124
+ this.#getBlockRegistry = memoize(registrySwap, {
125
+ getInstanceId: () => this.#instanceId
154
126
  });
155
127
  }
156
128
 
157
129
  addUserInterfaces(userRpc) {
158
130
  // add any extra user-defined sections
159
- this.sections.push(...Object.keys(userRpc).filter(key => !this.sections.includes(key))); // decorate the sections with base and user methods
160
-
161
- this.sections.forEach(sectionName => {
162
- var _ref, _ref2;
163
-
164
- (_ref = this)[_ref2 = sectionName] || (_ref[_ref2] = {});
165
- const section = this[sectionName];
166
- Object.entries(_objectSpread(_objectSpread({}, this._createInterface(sectionName, rpcDefinitions[sectionName] || {})), this._createInterface(sectionName, userRpc[sectionName] || {}))).forEach(([key, value]) => {
167
- section[key] || (section[key] = value);
168
- });
169
- });
170
- }
171
-
172
- _createInterface(section, methods) {
173
- return Object.entries(methods).filter(([method, {
174
- endpoint
175
- }]) => !this.mapping.has(endpoint || `${section}_${method}`)).reduce((exposed, [method, {
176
- endpoint
177
- }]) => {
178
- const def = methods[method];
179
- const isSubscription = !!def.pubsub;
180
- const jsonrpc = endpoint || `${section}_${method}`;
181
- this.mapping.set(jsonrpc, _objectSpread(_objectSpread({}, def), {}, {
182
- isSubscription,
183
- jsonrpc,
184
- method,
185
- section
186
- }));
187
- exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
188
- return exposed;
189
- }, {});
131
+ this.sections.push(...Object.keys(userRpc).filter(k => !this.sections.includes(k)));
132
+
133
+ for (let s = 0; s < this.sections.length; s++) {
134
+ const section = this.sections[s];
135
+ const defs = objectSpread({}, rpcDefinitions[section], userRpc[section]);
136
+ const methods = Object.keys(defs);
137
+
138
+ for (let m = 0; m < methods.length; m++) {
139
+ const method = methods[m];
140
+ const def = defs[method];
141
+ const jsonrpc = def.endpoint || `${section}_${method}`;
142
+
143
+ if (!this.mapping.has(jsonrpc)) {
144
+ const isSubscription = !!def.pubsub;
145
+
146
+ if (!this[section]) {
147
+ this[section] = {};
148
+ }
149
+
150
+ this.mapping.set(jsonrpc, objectSpread({}, def, {
151
+ isSubscription,
152
+ jsonrpc,
153
+ method,
154
+ section
155
+ }));
156
+ lazyMethod(this[section], method, () => isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def));
157
+ }
158
+ }
159
+ }
190
160
  }
191
161
 
192
162
  _memomize(creator, def) {
193
163
  const memoOpts = {
194
- getInstanceId: () => _classPrivateFieldLooseBase(this, _instanceId)[_instanceId]
164
+ getInstanceId: () => this.#instanceId
195
165
  };
196
166
  const memoized = memoize(creator(true), memoOpts);
197
167
  memoized.raw = memoize(creator(false), memoOpts);
@@ -214,8 +184,8 @@ export class RpcCore {
214
184
  const blockHash = hashIndex === -1 ? null : values[hashIndex];
215
185
  const {
216
186
  registry
217
- } = isScale && blockHash && _classPrivateFieldLooseBase(this, _getBlockRegistry)[_getBlockRegistry] ? await _classPrivateFieldLooseBase(this, _getBlockRegistry)[_getBlockRegistry](u8aToU8a(blockHash)) : {
218
- registry: _classPrivateFieldLooseBase(this, _registryDefault)[_registryDefault]
187
+ } = isScale && blockHash && this.#getBlockRegistry ? await this.#getBlockRegistry(u8aToU8a(blockHash)) : {
188
+ registry: this.#registryDefault
219
189
  };
220
190
 
221
191
  const params = this._formatInputs(registry, null, def, values);
@@ -276,8 +246,7 @@ export class RpcCore {
276
246
  return new Observable(observer => {
277
247
  // Have at least an empty promise, as used in the unsubscribe
278
248
  let subscriptionPromise = Promise.resolve(null);
279
-
280
- const registry = _classPrivateFieldLooseBase(this, _registryDefault)[_registryDefault];
249
+ const registry = this.#registryDefault;
281
250
 
282
251
  const errorHandler = error => {
283
252
  logErrorMessage(method, def, error);
@@ -388,14 +357,13 @@ export class RpcCore {
388
357
  // - if a single result value, don't fill - it is not an update hole
389
358
  // - fallback to an empty option in all cases
390
359
 
391
- const value = isUndefined(found) ? witCache && _classPrivateFieldLooseBase(this, _storageCache)[_storageCache].get(hexKey) || null : found[1];
360
+ const value = isUndefined(found) ? witCache && this.#storageCache.get(hexKey) || null : found[1];
392
361
  const isEmpty = isNull(value);
393
362
  const input = isEmpty || isTreatAsHex(key) ? value : u8aToU8a(value); // store the retrieved result - the only issue with this cache is that there is no
394
363
  // clearing of it, so very long running processes (not just a couple of hours, longer)
395
364
  // will increase memory beyond what is allowed.
396
365
 
397
- _classPrivateFieldLooseBase(this, _storageCache)[_storageCache].set(hexKey, value);
398
-
366
+ this.#storageCache.set(hexKey, value);
399
367
  return this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
400
368
  }
401
369
 
package/package.json CHANGED
@@ -20,17 +20,17 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "6.6.2-2",
23
+ "version": "6.6.2-23",
24
24
  "main": "index.js",
25
25
  "dependencies": {
26
- "@babel/runtime": "^7.15.4",
27
- "@polkadot/rpc-provider": "6.6.2-2",
28
- "@polkadot/types": "6.6.2-2",
29
- "@polkadot/util": "^7.7.1",
26
+ "@babel/runtime": "^7.16.0",
27
+ "@polkadot/rpc-provider": "6.6.2-23",
28
+ "@polkadot/types": "6.6.2-23",
29
+ "@polkadot/util": "^7.8.1",
30
30
  "rxjs": "^7.4.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@polkadot/keyring": "^7.7.1"
33
+ "@polkadot/keyring": "^7.8.1"
34
34
  },
35
35
  "exports": {
36
36
  ".": {
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-2'
12
+ version: '6.6.2-23'
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-2'
6
+ version: '6.6.2-23'
7
7
  };
@@ -1,7 +1,8 @@
1
1
  import type { Observable } from 'rxjs';
2
- import type { AnyFunction } from '@polkadot/types/types';
2
+ import type { AnyFunction, DefinitionRpc } from '@polkadot/types/types';
3
3
  export interface RpcInterface {
4
4
  }
5
5
  export declare type AugmentedRpc<F extends AnyFunction> = F & {
6
6
  raw: <T>(...params: Parameters<F>) => Observable<T>;
7
+ meta: DefinitionRpc;
7
8
  };
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];