@polkadot/rpc-core 6.6.2-13 → 6.6.2-14

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
@@ -201,44 +201,38 @@ class RpcCore {
201
201
 
202
202
  addUserInterfaces(userRpc) {
203
203
  // add any extra user-defined sections
204
- this.sections.push(...Object.keys(userRpc).filter(key => !this.sections.includes(key))); // decorate the sections with base and user methods
205
-
206
- this.sections.forEach(sectionName => {
207
- var _ref3, _ref4;
208
-
209
- (_ref3 = this)[_ref4 = sectionName] || (_ref3[_ref4] = {});
210
- const section = this[sectionName];
211
- Object.entries({ ...this._createInterface(sectionName, _types.rpcDefinitions[sectionName] || {}),
212
- ...this._createInterface(sectionName, userRpc[sectionName] || {})
213
- }).forEach(_ref5 => {
214
- let [key, value] = _ref5;
215
- section[key] || (section[key] = value);
216
- });
217
- });
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
+
215
+ if (!this.mapping.has(def.endpoint || `${section}_${method}`)) {
216
+ if (!this[section]) {
217
+ this[section] = {};
218
+ }
219
+
220
+ (0, _util.lazyMethod)(this[section], method, () => this._createInterface(section, method, def));
221
+ }
222
+ }
223
+ }
218
224
  }
219
225
 
220
- _createInterface(section, methods) {
221
- return Object.entries(methods).filter(_ref6 => {
222
- let [method, {
223
- endpoint
224
- }] = _ref6;
225
- return !this.mapping.has(endpoint || `${section}_${method}`);
226
- }).reduce((exposed, _ref7) => {
227
- let [method, {
228
- endpoint
229
- }] = _ref7;
230
- const def = methods[method];
231
- const isSubscription = !!def.pubsub;
232
- const jsonrpc = endpoint || `${section}_${method}`;
233
- this.mapping.set(jsonrpc, { ...def,
234
- isSubscription,
235
- jsonrpc,
236
- method,
237
- section
238
- });
239
- exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
240
- return exposed;
241
- }, {});
226
+ _createInterface(section, method, def) {
227
+ const isSubscription = !!def.pubsub;
228
+ const jsonrpc = def.endpoint || `${section}_${method}`;
229
+ this.mapping.set(jsonrpc, { ...def,
230
+ isSubscription,
231
+ jsonrpc,
232
+ method,
233
+ section
234
+ });
235
+ return isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
242
236
  }
243
237
 
244
238
  _memomize(creator, def) {
@@ -257,10 +251,10 @@ class RpcCore {
257
251
 
258
252
  _createMethodSend(section, method, def) {
259
253
  const rpcName = def.endpoint || `${section}_${method}`;
260
- const hashIndex = def.params.findIndex(_ref8 => {
254
+ const hashIndex = def.params.findIndex(_ref3 => {
261
255
  let {
262
256
  isHistoric
263
- } = _ref8;
257
+ } = _ref3;
264
258
  return isHistoric;
265
259
  });
266
260
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
@@ -310,13 +304,13 @@ class RpcCore {
310
304
  } // create a subscriptor, it subscribes once and resolves with the id as subscribe
311
305
 
312
306
 
313
- _createSubscriber(_ref9, errorHandler) {
307
+ _createSubscriber(_ref4, errorHandler) {
314
308
  let {
315
309
  paramsJson,
316
310
  subName,
317
311
  subType,
318
312
  update
319
- } = _ref9;
313
+ } = _ref4;
320
314
  return new Promise((resolve, reject) => {
321
315
  this.provider.subscribe(subType, subName, paramsJson, update).then(resolve).catch(error => {
322
316
  errorHandler(error);
@@ -394,10 +388,10 @@ class RpcCore {
394
388
  }
395
389
 
396
390
  _formatInputs(registry, blockHash, def, inputs) {
397
- const reqArgCount = def.params.filter(_ref10 => {
391
+ const reqArgCount = def.params.filter(_ref5 => {
398
392
  let {
399
393
  isOptional
400
- } = _ref10;
394
+ } = _ref5;
401
395
  return !isOptional;
402
396
  }).length;
403
397
  const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
@@ -415,11 +409,11 @@ class RpcCore {
415
409
  const keys = params[0];
416
410
  return keys ? this._formatStorageSet(registry, result.block, keys, result.changes) : registry.createType('StorageChangeSet', result);
417
411
  } else if (rpc.type === 'Vec<StorageChangeSet>') {
418
- const mapped = result.map(_ref11 => {
412
+ const mapped = result.map(_ref6 => {
419
413
  let {
420
414
  block,
421
415
  changes
422
- } = _ref11;
416
+ } = _ref6;
423
417
  return [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)];
424
418
  }); // we only query at a specific block, not a range - flatten
425
419
 
@@ -454,8 +448,8 @@ class RpcCore {
454
448
 
455
449
  _formatStorageSetEntry(registry, blockHash, key, changes, witCache, entryIndex) {
456
450
  const hexKey = key.toHex();
457
- const found = changes.find(_ref12 => {
458
- let [key] = _ref12;
451
+ const found = changes.find(_ref7 => {
452
+ let [key] = _ref7;
459
453
  return key === hexKey;
460
454
  }); // if we don't find the value, this is our fallback
461
455
  // - in the case of an array of values, fill the hole from the cache
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,7 +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;
57
+ addUserInterfaces(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
59
58
  private _createInterface;
60
59
  private _memomize;
61
60
  private _formatResult;
package/bundle.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Observable, publishReplay, refCount } from 'rxjs';
4
4
  import { rpcDefinitions } from '@polkadot/types';
5
- 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';
6
6
  import { drr, refCountDelay } from "./util/index.js";
7
7
  export { packageInfo } from "./packageInfo.js";
8
8
  export * from "./util/index.js";
@@ -128,39 +128,38 @@ export class RpcCore {
128
128
 
129
129
  addUserInterfaces(userRpc) {
130
130
  // add any extra user-defined sections
131
- this.sections.push(...Object.keys(userRpc).filter(key => !this.sections.includes(key))); // decorate the sections with base and user methods
131
+ this.sections.push(...Object.keys(userRpc).filter(k => !this.sections.includes(k)));
132
132
 
133
- this.sections.forEach(sectionName => {
134
- var _ref, _ref2;
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);
135
137
 
136
- (_ref = this)[_ref2 = sectionName] || (_ref[_ref2] = {});
137
- const section = this[sectionName];
138
- Object.entries({ ...this._createInterface(sectionName, rpcDefinitions[sectionName] || {}),
139
- ...this._createInterface(sectionName, userRpc[sectionName] || {})
140
- }).forEach(([key, value]) => {
141
- section[key] || (section[key] = value);
142
- });
143
- });
138
+ for (let m = 0; m < methods.length; m++) {
139
+ const method = methods[m];
140
+ const def = defs[method];
141
+
142
+ if (!this.mapping.has(def.endpoint || `${section}_${method}`)) {
143
+ if (!this[section]) {
144
+ this[section] = {};
145
+ }
146
+
147
+ lazyMethod(this[section], method, () => this._createInterface(section, method, def));
148
+ }
149
+ }
150
+ }
144
151
  }
145
152
 
146
- _createInterface(section, methods) {
147
- return Object.entries(methods).filter(([method, {
148
- endpoint
149
- }]) => !this.mapping.has(endpoint || `${section}_${method}`)).reduce((exposed, [method, {
150
- endpoint
151
- }]) => {
152
- const def = methods[method];
153
- const isSubscription = !!def.pubsub;
154
- const jsonrpc = endpoint || `${section}_${method}`;
155
- this.mapping.set(jsonrpc, { ...def,
156
- isSubscription,
157
- jsonrpc,
158
- method,
159
- section
160
- });
161
- exposed[method] = isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
162
- return exposed;
163
- }, {});
153
+ _createInterface(section, method, def) {
154
+ const isSubscription = !!def.pubsub;
155
+ const jsonrpc = def.endpoint || `${section}_${method}`;
156
+ this.mapping.set(jsonrpc, { ...def,
157
+ isSubscription,
158
+ jsonrpc,
159
+ method,
160
+ section
161
+ });
162
+ return isSubscription ? this._createMethodSubscribe(section, method, def) : this._createMethodSend(section, method, def);
164
163
  }
165
164
 
166
165
  _memomize(creator, def) {
package/package.json CHANGED
@@ -20,12 +20,12 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "6.6.2-13",
23
+ "version": "6.6.2-14",
24
24
  "main": "index.js",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.16.0",
27
- "@polkadot/rpc-provider": "6.6.2-13",
28
- "@polkadot/types": "6.6.2-13",
27
+ "@polkadot/rpc-provider": "6.6.2-14",
28
+ "@polkadot/types": "6.6.2-14",
29
29
  "@polkadot/util": "^7.7.2-5",
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-13'
12
+ version: '6.6.2-14'
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-13'
6
+ version: '6.6.2-14'
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
  };