New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot/rpc-core

Package Overview
Dependencies
Maintainers
2
Versions
3019
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot/rpc-core - npm Package Compare versions

Comparing version 10.4.1 to 10.5.1

13

bundle.d.ts

@@ -5,2 +5,7 @@ import type { ProviderInterface } from '@polkadot/rpc-provider/types';

export * from './util/index.js';
interface Options {
isPedantic?: boolean;
provider: ProviderInterface;
userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
}
/**

@@ -36,6 +41,6 @@ * @name Rpc

* @constructor
* Default constructor for the Api Object
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
* Default constructor for the core RPC handler
* @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
*/
constructor(instanceId: string, registry: Registry, provider: ProviderInterface, userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>);
constructor(instanceId: string, registry: Registry, { isPedantic, provider, userRpc }: Options);
/**

@@ -69,3 +74,3 @@ * @description Returns the connected status of a provider

private _createMethodSubscribe;
private _formatInputs;
private _formatParams;
private _formatOutput;

@@ -72,0 +77,0 @@ private _formatStorageData;

@@ -1,3 +0,1 @@

var _RpcCore_instanceId, _RpcCore_registryDefault, _RpcCore_getBlockRegistry, _RpcCore_getBlockHash, _RpcCore_storageCache;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { Observable, publishReplay, refCount } from 'rxjs';

@@ -23,4 +21,3 @@ import { rpcDefinitions } from '@polkadot/types';

}
const inputs = params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
l.error(`${method}(${params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ')}): ${type}:: ${error.message}`);
}

@@ -58,11 +55,7 @@ function isTreatAsHex(key) {

* @constructor
* Default constructor for the Api Object
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
* Default constructor for the core RPC handler
* @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
*/
constructor(instanceId, registry, provider, userRpc = {}) {
_RpcCore_instanceId.set(this, void 0);
_RpcCore_registryDefault.set(this, void 0);
_RpcCore_getBlockRegistry.set(this, void 0);
_RpcCore_getBlockHash.set(this, void 0);
_RpcCore_storageCache.set(this, new Map());
constructor(instanceId, registry, { isPedantic = true, provider, userRpc = {} }) {
this.__internal__storageCache = new Map();
this.mapping = new Map();

@@ -74,4 +67,5 @@ this.sections = [];

}
__classPrivateFieldSet(this, _RpcCore_instanceId, instanceId, "f");
__classPrivateFieldSet(this, _RpcCore_registryDefault, registry, "f");
this.__internal__instanceId = instanceId;
this.__internal__isPedantic = isPedantic;
this.__internal__registryDefault = registry;
this.provider = provider;

@@ -106,5 +100,5 @@ const sectionNames = Object.keys(rpcDefinitions);

setRegistrySwap(registrySwap) {
__classPrivateFieldSet(this, _RpcCore_getBlockRegistry, memoize(registrySwap, {
getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f")
}), "f");
this.__internal__getBlockRegistry = memoize(registrySwap, {
getInstanceId: () => this.__internal__instanceId
});
}

@@ -115,5 +109,5 @@ /**

setResolveBlockHash(resolveBlockHash) {
__classPrivateFieldSet(this, _RpcCore_getBlockHash, memoize(resolveBlockHash, {
getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f")
}), "f");
this.__internal__getBlockHash = memoize(resolveBlockHash, {
getInstanceId: () => this.__internal__instanceId
});
}

@@ -123,7 +117,7 @@ addUserInterfaces(userRpc) {

this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
for (let s = 0; s < this.sections.length; s++) {
for (let s = 0, scount = this.sections.length; s < scount; s++) {
const section = this.sections[s];
const defs = objectSpread({}, rpcDefinitions[section], userRpc[section]);
const methods = Object.keys(defs);
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
const method = methods[m];

@@ -146,3 +140,3 @@ const def = defs[method];

_memomize(creator, def) {
const memoOpts = { getInstanceId: () => __classPrivateFieldGet(this, _RpcCore_instanceId, "f") };
const memoOpts = { getInstanceId: () => this.__internal__instanceId };
const memoized = memoize(creator(true), memoOpts);

@@ -168,8 +162,8 @@ memoized.raw = memoize(creator(false), memoOpts);

const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber'
? await __classPrivateFieldGet(this, _RpcCore_getBlockHash, "f")?.call(this, blockId)
? await this.__internal__getBlockHash?.(blockId)
: blockId;
const { registry } = isScale && blockHash && __classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f")
? await __classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f").call(this, u8aToU8a(blockHash))
: { registry: __classPrivateFieldGet(this, _RpcCore_registryDefault, "f") };
const params = this._formatInputs(registry, null, def, values);
const { registry } = isScale && blockHash && this.__internal__getBlockRegistry
? await this.__internal__getBlockRegistry(u8aToU8a(blockHash))
: { registry: this.__internal__registryDefault };
const params = this._formatParams(registry, null, def, values);
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied

@@ -234,3 +228,3 @@ const result = await this.provider.send(rpcName, params.map((p) => p.toJSON()), !!blockHash);

let subscriptionPromise = Promise.resolve(null);
const registry = __classPrivateFieldGet(this, _RpcCore_registryDefault, "f");
const registry = this.__internal__registryDefault;
const errorHandler = (error) => {

@@ -241,4 +235,3 @@ logErrorMessage(method, def, error);

try {
const params = this._formatInputs(registry, null, def, values);
const paramsJson = params.map((p) => p.toJSON());
const params = this._formatParams(registry, null, def, values);
const update = (error, result) => {

@@ -256,3 +249,3 @@ if (error) {

};
subscriptionPromise = this._createSubscriber({ paramsJson, subName, subType, update }, errorHandler);
subscriptionPromise = this._createSubscriber({ paramsJson: params.map((p) => p.toJSON()), subName, subType, update }, errorHandler);
}

@@ -283,11 +276,13 @@ catch (error) {

}
_formatInputs(registry, blockHash, def, inputs) {
const reqArgCount = def.params.filter(({ isOptional }) => !isOptional).length;
const optText = reqArgCount === def.params.length
? ''
: ` (${def.params.length - reqArgCount} optional)`;
if (inputs.length < reqArgCount || inputs.length > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
_formatParams(registry, blockHash, def, inputs) {
const count = inputs.length;
const reqCount = def.params.filter(({ isOptional }) => !isOptional).length;
if (count < reqCount || count > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${reqCount === def.params.length ? '' : ` (${def.params.length - reqCount} optional)`}, ${count} found instead`);
}
return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], { blockHash }));
const params = new Array(count);
for (let i = 0; i < count; i++) {
params[i] = registry.createTypeUnsafe(def.params[i].type, [inputs[i]], { blockHash });
}
return params;
}

@@ -306,6 +301,12 @@ _formatOutput(registry, blockHash, method, rpc, params, result) {

else if (rpc.type === 'Vec<StorageChangeSet>') {
const mapped = result.map(({ block, changes }) => [
registry.createType('Hash', block),
this._formatStorageSet(registry, block, params[0], changes)
]);
const jsonSet = result;
const count = jsonSet.length;
const mapped = new Array(count);
for (let i = 0; i < count; i++) {
const { block, changes } = jsonSet[i];
mapped[i] = [
registry.createType('BlockHash', block),
this._formatStorageSet(registry, block, params[0], changes)
];
}
// we only query at a specific block, not a range - flatten

@@ -331,11 +332,11 @@ return method === 'queryStorageAt'

// For StorageChangeSet, the changes has the [key, value] mappings
const withCache = keys.length !== 1;
// multiple return values (via state.storage subscription), decode the values
// one at a time, all based on the query types. Three values can be returned -
// - Codec - There is a valid value, non-empty
// - null - The storage key is empty
return keys.reduce((results, key, index) => {
results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
return results;
}, []);
const count = keys.length;
const withCache = count !== 1;
const values = new Array(count);
// multiple return values (via state.storage subscription), decode the
// values one at a time, all based on the supplied query types
for (let i = 0; i < count; i++) {
values[i] = this._formatStorageSetEntry(registry, blockHash, keys[i], changes, withCache, i);
}
return values;
}

@@ -351,3 +352,3 @@ _formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {

if (isNotFound && withCache) {
const cached = __classPrivateFieldGet(this, _RpcCore_storageCache, "f").get(hexKey);
const cached = this.__internal__storageCache.get(hexKey);
if (cached) {

@@ -368,3 +369,3 @@ return cached;

// will increase memory beyond what is allowed.
__classPrivateFieldGet(this, _RpcCore_storageCache, "f").set(hexKey, codec);
this.__internal__storageCache.set(hexKey, codec);
return codec;

@@ -390,5 +391,5 @@ }

: meta.modifier.isOptional
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.__internal__isPedantic })
: input
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: this.__internal__isPedantic && !meta.modifier.isOptional });
}

@@ -400,2 +401,1 @@ catch (error) {

}
_RpcCore_instanceId = new WeakMap(), _RpcCore_registryDefault = new WeakMap(), _RpcCore_getBlockRegistry = new WeakMap(), _RpcCore_getBlockHash = new WeakMap(), _RpcCore_storageCache = new WeakMap();
"use strict";
var _RpcCore_instanceId, _RpcCore_registryDefault, _RpcCore_getBlockRegistry, _RpcCore_getBlockHash, _RpcCore_storageCache;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -27,4 +26,3 @@ exports.RpcCore = exports.packageInfo = void 0;

}
const inputs = params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ');
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
l.error(`${method}(${params.map(({ isOptional, name, type }) => `${name}${isOptional ? '?' : ''}: ${type}`).join(', ')}): ${type}:: ${error.message}`);
}

@@ -62,11 +60,7 @@ function isTreatAsHex(key) {

* @constructor
* Default constructor for the Api Object
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
* Default constructor for the core RPC handler
* @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
*/
constructor(instanceId, registry, provider, userRpc = {}) {
_RpcCore_instanceId.set(this, void 0);
_RpcCore_registryDefault.set(this, void 0);
_RpcCore_getBlockRegistry.set(this, void 0);
_RpcCore_getBlockHash.set(this, void 0);
_RpcCore_storageCache.set(this, new Map());
constructor(instanceId, registry, { isPedantic = true, provider, userRpc = {} }) {
this.__internal__storageCache = new Map();
this.mapping = new Map();

@@ -78,4 +72,5 @@ this.sections = [];

}
tslib_1.__classPrivateFieldSet(this, _RpcCore_instanceId, instanceId, "f");
tslib_1.__classPrivateFieldSet(this, _RpcCore_registryDefault, registry, "f");
this.__internal__instanceId = instanceId;
this.__internal__isPedantic = isPedantic;
this.__internal__registryDefault = registry;
this.provider = provider;

@@ -110,5 +105,5 @@ const sectionNames = Object.keys(types_1.rpcDefinitions);

setRegistrySwap(registrySwap) {
tslib_1.__classPrivateFieldSet(this, _RpcCore_getBlockRegistry, (0, util_1.memoize)(registrySwap, {
getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f")
}), "f");
this.__internal__getBlockRegistry = (0, util_1.memoize)(registrySwap, {
getInstanceId: () => this.__internal__instanceId
});
}

@@ -119,5 +114,5 @@ /**

setResolveBlockHash(resolveBlockHash) {
tslib_1.__classPrivateFieldSet(this, _RpcCore_getBlockHash, (0, util_1.memoize)(resolveBlockHash, {
getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f")
}), "f");
this.__internal__getBlockHash = (0, util_1.memoize)(resolveBlockHash, {
getInstanceId: () => this.__internal__instanceId
});
}

@@ -127,7 +122,7 @@ addUserInterfaces(userRpc) {

this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
for (let s = 0; s < this.sections.length; s++) {
for (let s = 0, scount = this.sections.length; s < scount; s++) {
const section = this.sections[s];
const defs = (0, util_1.objectSpread)({}, types_1.rpcDefinitions[section], userRpc[section]);
const methods = Object.keys(defs);
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
const method = methods[m];

@@ -150,3 +145,3 @@ const def = defs[method];

_memomize(creator, def) {
const memoOpts = { getInstanceId: () => tslib_1.__classPrivateFieldGet(this, _RpcCore_instanceId, "f") };
const memoOpts = { getInstanceId: () => this.__internal__instanceId };
const memoized = (0, util_1.memoize)(creator(true), memoOpts);

@@ -172,8 +167,8 @@ memoized.raw = (0, util_1.memoize)(creator(false), memoOpts);

const blockHash = blockId && def.params[hashIndex].type === 'BlockNumber'
? await tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockHash, "f")?.call(this, blockId)
? await this.__internal__getBlockHash?.(blockId)
: blockId;
const { registry } = isScale && blockHash && tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f")
? await tslib_1.__classPrivateFieldGet(this, _RpcCore_getBlockRegistry, "f").call(this, (0, util_1.u8aToU8a)(blockHash))
: { registry: tslib_1.__classPrivateFieldGet(this, _RpcCore_registryDefault, "f") };
const params = this._formatInputs(registry, null, def, values);
const { registry } = isScale && blockHash && this.__internal__getBlockRegistry
? await this.__internal__getBlockRegistry((0, util_1.u8aToU8a)(blockHash))
: { registry: this.__internal__registryDefault };
const params = this._formatParams(registry, null, def, values);
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied

@@ -238,3 +233,3 @@ const result = await this.provider.send(rpcName, params.map((p) => p.toJSON()), !!blockHash);

let subscriptionPromise = Promise.resolve(null);
const registry = tslib_1.__classPrivateFieldGet(this, _RpcCore_registryDefault, "f");
const registry = this.__internal__registryDefault;
const errorHandler = (error) => {

@@ -245,4 +240,3 @@ logErrorMessage(method, def, error);

try {
const params = this._formatInputs(registry, null, def, values);
const paramsJson = params.map((p) => p.toJSON());
const params = this._formatParams(registry, null, def, values);
const update = (error, result) => {

@@ -260,3 +254,3 @@ if (error) {

};
subscriptionPromise = this._createSubscriber({ paramsJson, subName, subType, update }, errorHandler);
subscriptionPromise = this._createSubscriber({ paramsJson: params.map((p) => p.toJSON()), subName, subType, update }, errorHandler);
}

@@ -287,11 +281,13 @@ catch (error) {

}
_formatInputs(registry, blockHash, def, inputs) {
const reqArgCount = def.params.filter(({ isOptional }) => !isOptional).length;
const optText = reqArgCount === def.params.length
? ''
: ` (${def.params.length - reqArgCount} optional)`;
if (inputs.length < reqArgCount || inputs.length > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
_formatParams(registry, blockHash, def, inputs) {
const count = inputs.length;
const reqCount = def.params.filter(({ isOptional }) => !isOptional).length;
if (count < reqCount || count > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${reqCount === def.params.length ? '' : ` (${def.params.length - reqCount} optional)`}, ${count} found instead`);
}
return inputs.map((input, index) => registry.createTypeUnsafe(def.params[index].type, [input], { blockHash }));
const params = new Array(count);
for (let i = 0; i < count; i++) {
params[i] = registry.createTypeUnsafe(def.params[i].type, [inputs[i]], { blockHash });
}
return params;
}

@@ -310,6 +306,12 @@ _formatOutput(registry, blockHash, method, rpc, params, result) {

else if (rpc.type === 'Vec<StorageChangeSet>') {
const mapped = result.map(({ block, changes }) => [
registry.createType('Hash', block),
this._formatStorageSet(registry, block, params[0], changes)
]);
const jsonSet = result;
const count = jsonSet.length;
const mapped = new Array(count);
for (let i = 0; i < count; i++) {
const { block, changes } = jsonSet[i];
mapped[i] = [
registry.createType('BlockHash', block),
this._formatStorageSet(registry, block, params[0], changes)
];
}
// we only query at a specific block, not a range - flatten

@@ -335,11 +337,11 @@ return method === 'queryStorageAt'

// For StorageChangeSet, the changes has the [key, value] mappings
const withCache = keys.length !== 1;
// multiple return values (via state.storage subscription), decode the values
// one at a time, all based on the query types. Three values can be returned -
// - Codec - There is a valid value, non-empty
// - null - The storage key is empty
return keys.reduce((results, key, index) => {
results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
return results;
}, []);
const count = keys.length;
const withCache = count !== 1;
const values = new Array(count);
// multiple return values (via state.storage subscription), decode the
// values one at a time, all based on the supplied query types
for (let i = 0; i < count; i++) {
values[i] = this._formatStorageSetEntry(registry, blockHash, keys[i], changes, withCache, i);
}
return values;
}

@@ -355,3 +357,3 @@ _formatStorageSetEntry(registry, blockHash, key, changes, withCache, entryIndex) {

if (isNotFound && withCache) {
const cached = tslib_1.__classPrivateFieldGet(this, _RpcCore_storageCache, "f").get(hexKey);
const cached = this.__internal__storageCache.get(hexKey);
if (cached) {

@@ -372,3 +374,3 @@ return cached;

// will increase memory beyond what is allowed.
tslib_1.__classPrivateFieldGet(this, _RpcCore_storageCache, "f").set(hexKey, codec);
this.__internal__storageCache.set(hexKey, codec);
return codec;

@@ -394,5 +396,5 @@ }

: meta.modifier.isOptional
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.__internal__isPedantic })
: input
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: this.__internal__isPedantic && !meta.modifier.isOptional });
}

@@ -405,2 +407,1 @@ catch (error) {

exports.RpcCore = RpcCore;
_RpcCore_instanceId = new WeakMap(), _RpcCore_registryDefault = new WeakMap(), _RpcCore_getBlockRegistry = new WeakMap(), _RpcCore_getBlockHash = new WeakMap(), _RpcCore_storageCache = new WeakMap();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.packageInfo = void 0;
exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.4.1' };
exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.5.1' };

@@ -21,3 +21,3 @@ {

"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "./cjs/index.js",

@@ -100,9 +100,9 @@ "module": "./index.js",

"dependencies": {
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/rpc-provider": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/util": "^12.0.1",
"rxjs": "^7.8.0",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/rpc-provider": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/util": "^12.1.1",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
}
}

@@ -1,1 +0,1 @@

export const packageInfo = { name: '@polkadot/rpc-core', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/rpc-core', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.5.1' };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc