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

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,35 @@ 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
- });
218
- }
219
-
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
- }, {});
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
+ }
242
233
  }
243
234
 
244
235
  _memomize(creator, def) {
@@ -257,10 +248,10 @@ class RpcCore {
257
248
 
258
249
  _createMethodSend(section, method, def) {
259
250
  const rpcName = def.endpoint || `${section}_${method}`;
260
- const hashIndex = def.params.findIndex(_ref8 => {
251
+ const hashIndex = def.params.findIndex(_ref3 => {
261
252
  let {
262
253
  isHistoric
263
- } = _ref8;
254
+ } = _ref3;
264
255
  return isHistoric;
265
256
  });
266
257
  let memoized = null; // execute the RPC call, doing a registry swap for historic as applicable
@@ -310,13 +301,13 @@ class RpcCore {
310
301
  } // create a subscriptor, it subscribes once and resolves with the id as subscribe
311
302
 
312
303
 
313
- _createSubscriber(_ref9, errorHandler) {
304
+ _createSubscriber(_ref4, errorHandler) {
314
305
  let {
315
306
  paramsJson,
316
307
  subName,
317
308
  subType,
318
309
  update
319
- } = _ref9;
310
+ } = _ref4;
320
311
  return new Promise((resolve, reject) => {
321
312
  this.provider.subscribe(subType, subName, paramsJson, update).then(resolve).catch(error => {
322
313
  errorHandler(error);
@@ -394,10 +385,10 @@ class RpcCore {
394
385
  }
395
386
 
396
387
  _formatInputs(registry, blockHash, def, inputs) {
397
- const reqArgCount = def.params.filter(_ref10 => {
388
+ const reqArgCount = def.params.filter(_ref5 => {
398
389
  let {
399
390
  isOptional
400
- } = _ref10;
391
+ } = _ref5;
401
392
  return !isOptional;
402
393
  }).length;
403
394
  const optText = reqArgCount === def.params.length ? '' : ` (${def.params.length - reqArgCount} optional)`;
@@ -415,11 +406,11 @@ class RpcCore {
415
406
  const keys = params[0];
416
407
  return keys ? this._formatStorageSet(registry, result.block, keys, result.changes) : registry.createType('StorageChangeSet', result);
417
408
  } else if (rpc.type === 'Vec<StorageChangeSet>') {
418
- const mapped = result.map(_ref11 => {
409
+ const mapped = result.map(_ref6 => {
419
410
  let {
420
411
  block,
421
412
  changes
422
- } = _ref11;
413
+ } = _ref6;
423
414
  return [registry.createType('Hash', block), this._formatStorageSet(registry, block, params[0], changes)];
424
415
  }); // we only query at a specific block, not a range - flatten
425
416
 
@@ -454,8 +445,8 @@ class RpcCore {
454
445
 
455
446
  _formatStorageSetEntry(registry, blockHash, key, changes, witCache, entryIndex) {
456
447
  const hexKey = key.toHex();
457
- const found = changes.find(_ref12 => {
458
- let [key] = _ref12;
448
+ const found = changes.find(_ref7 => {
449
+ let [key] = _ref7;
459
450
  return key === hexKey;
460
451
  }); // if we don't find the value, this is our fallback
461
452
  // - 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,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
@@ -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,35 @@ 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
132
-
133
- this.sections.forEach(sectionName => {
134
- var _ref, _ref2;
135
-
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
- });
144
- }
145
-
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
- }, {});
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
+ }
164
160
  }
165
161
 
166
162
  _memomize(creator, def) {
package/package.json CHANGED
@@ -20,17 +20,17 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "6.6.2-13",
23
+ "version": "6.6.2-17",
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",
29
- "@polkadot/util": "^7.7.2-5",
27
+ "@polkadot/rpc-provider": "6.6.2-17",
28
+ "@polkadot/types": "6.6.2-17",
29
+ "@polkadot/util": "^7.7.2-6",
30
30
  "rxjs": "^7.4.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@polkadot/keyring": "^7.7.2-5"
33
+ "@polkadot/keyring": "^7.7.2-6"
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-13'
12
+ version: '6.6.2-17'
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-17'
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
  };