@polkadot/rpc-core 14.0.1 → 14.2.1

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.d.ts CHANGED
@@ -79,5 +79,6 @@ export declare class RpcCore {
79
79
  private _formatStorageData;
80
80
  private _formatStorageSet;
81
81
  private _formatStorageSetEntry;
82
+ private _setToCache;
82
83
  private _newType;
83
84
  }
package/bundle.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Observable, publishReplay, refCount } from 'rxjs';
2
+ import { DEFAULT_CAPACITY, LRUCache } from '@polkadot/rpc-provider';
2
3
  import { rpcDefinitions } from '@polkadot/types';
3
4
  import { hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
4
5
  import { drr, refCountDelay } from './util/index.js';
@@ -52,9 +53,8 @@ export class RpcCore {
52
53
  __internal__instanceId;
53
54
  __internal__isPedantic;
54
55
  __internal__registryDefault;
55
- __internal__storageCache = new Map();
56
+ __internal__storageCache;
56
57
  __internal__storageCacheHits = 0;
57
- __internal__storageCacheSize = 0;
58
58
  __internal__getBlockRegistry;
59
59
  __internal__getBlockHash;
60
60
  mapping = new Map();
@@ -76,6 +76,7 @@ export class RpcCore {
76
76
  const sectionNames = Object.keys(rpcDefinitions);
77
77
  // these are the base keys (i.e. part of jsonrpc)
78
78
  this.sections.push(...sectionNames);
79
+ this.__internal__storageCache = new LRUCache(DEFAULT_CAPACITY);
79
80
  // decorate all interfaces, defined and user on this instance
80
81
  this.addUserInterfaces(userRpc);
81
82
  }
@@ -94,7 +95,8 @@ export class RpcCore {
94
95
  /**
95
96
  * @description Manually disconnect from the attached provider
96
97
  */
97
- disconnect() {
98
+ async disconnect() {
99
+ await this.__internal__storageCache.clearInterval();
98
100
  return this.provider.disconnect();
99
101
  }
100
102
  /**
@@ -107,7 +109,7 @@ export class RpcCore {
107
109
  ...stats,
108
110
  core: {
109
111
  cacheHits: this.__internal__storageCacheHits,
110
- cacheSize: this.__internal__storageCacheSize
112
+ cacheSize: this.__internal__storageCache.length
111
113
  }
112
114
  }
113
115
  : undefined;
@@ -371,13 +373,12 @@ export class RpcCore {
371
373
  ? value
372
374
  : u8aToU8a(value);
373
375
  const codec = this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
374
- // store the retrieved result - the only issue with this cache is that there is no
375
- // clearing of it, so very long running processes (not just a couple of hours, longer)
376
- // will increase memory beyond what is allowed.
377
- this.__internal__storageCache.set(hexKey, codec);
378
- this.__internal__storageCacheSize++;
376
+ this._setToCache(hexKey, codec);
379
377
  return codec;
380
378
  }
379
+ _setToCache(key, value) {
380
+ this.__internal__storageCache.set(key, value);
381
+ }
381
382
  _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
382
383
  // single return value (via state.getStorage), decode the value based on the
383
384
  // outputType that we have specified. Fallback to Raw on nothing
@@ -0,0 +1,84 @@
1
+ import type { ProviderInterface } from '@polkadot/rpc-provider/types';
2
+ import type { AnyNumber, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@polkadot/types/types';
3
+ import type { RpcCoreStats } from './types/index.js';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export * from './util/index.js';
6
+ interface Options {
7
+ isPedantic?: boolean;
8
+ provider: ProviderInterface;
9
+ userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
10
+ }
11
+ /**
12
+ * @name Rpc
13
+ * @summary The API may use a HTTP or WebSockets provider.
14
+ * @description It allows for querying a Polkadot Client Node.
15
+ * WebSockets provider is recommended since HTTP provider only supports basic querying.
16
+ *
17
+ * ```mermaid
18
+ * graph LR;
19
+ * A[Api] --> |WebSockets| B[WsProvider];
20
+ * B --> |endpoint| C[ws://127.0.0.1:9944]
21
+ * ```
22
+ *
23
+ * @example
24
+ * <BR>
25
+ *
26
+ * ```javascript
27
+ * import Rpc from '@polkadot/rpc-core';
28
+ * import { WsProvider } from '@polkadot/rpc-provider/ws';
29
+ *
30
+ * const provider = new WsProvider('ws://127.0.0.1:9944');
31
+ * const rpc = new Rpc(provider);
32
+ * ```
33
+ */
34
+ export declare class RpcCore {
35
+ #private;
36
+ readonly mapping: Map<string, DefinitionRpcExt>;
37
+ readonly provider: ProviderInterface;
38
+ readonly sections: string[];
39
+ /**
40
+ * @constructor
41
+ * Default constructor for the core RPC handler
42
+ * @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
43
+ */
44
+ constructor(instanceId: string, registry: Registry, { isPedantic, provider, userRpc }: Options);
45
+ /**
46
+ * @description Returns the connected status of a provider
47
+ */
48
+ get isConnected(): boolean;
49
+ /**
50
+ * @description Manually connect from the attached provider
51
+ */
52
+ connect(): Promise<void>;
53
+ /**
54
+ * @description Manually disconnect from the attached provider
55
+ */
56
+ disconnect(): Promise<void>;
57
+ /**
58
+ * @description Returns the underlying core stats, including those from teh provider
59
+ */
60
+ get stats(): RpcCoreStats | undefined;
61
+ /**
62
+ * @description Sets a registry swap (typically from Api)
63
+ */
64
+ setRegistrySwap(registrySwap: (blockHash: Uint8Array) => Promise<{
65
+ registry: Registry;
66
+ }>): void;
67
+ /**
68
+ * @description Sets a function to resolve block hash from block number
69
+ */
70
+ setResolveBlockHash(resolveBlockHash: (blockNumber: AnyNumber) => Promise<Uint8Array>): void;
71
+ addUserInterfaces(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
72
+ private _memomize;
73
+ private _formatResult;
74
+ private _createMethodSend;
75
+ private _createSubscriber;
76
+ private _createMethodSubscribe;
77
+ private _formatParams;
78
+ private _formatOutput;
79
+ private _formatStorageData;
80
+ private _formatStorageSet;
81
+ private _formatStorageSetEntry;
82
+ private _setToCache;
83
+ private _newType;
84
+ }
package/cjs/bundle.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcCore = exports.packageInfo = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const rxjs_1 = require("rxjs");
6
+ const rpc_provider_1 = require("@polkadot/rpc-provider");
6
7
  const types_1 = require("@polkadot/types");
7
8
  const util_1 = require("@polkadot/util");
8
9
  const index_js_1 = require("./util/index.js");
@@ -57,9 +58,8 @@ class RpcCore {
57
58
  __internal__instanceId;
58
59
  __internal__isPedantic;
59
60
  __internal__registryDefault;
60
- __internal__storageCache = new Map();
61
+ __internal__storageCache;
61
62
  __internal__storageCacheHits = 0;
62
- __internal__storageCacheSize = 0;
63
63
  __internal__getBlockRegistry;
64
64
  __internal__getBlockHash;
65
65
  mapping = new Map();
@@ -81,6 +81,7 @@ class RpcCore {
81
81
  const sectionNames = Object.keys(types_1.rpcDefinitions);
82
82
  // these are the base keys (i.e. part of jsonrpc)
83
83
  this.sections.push(...sectionNames);
84
+ this.__internal__storageCache = new rpc_provider_1.LRUCache(rpc_provider_1.DEFAULT_CAPACITY);
84
85
  // decorate all interfaces, defined and user on this instance
85
86
  this.addUserInterfaces(userRpc);
86
87
  }
@@ -99,7 +100,8 @@ class RpcCore {
99
100
  /**
100
101
  * @description Manually disconnect from the attached provider
101
102
  */
102
- disconnect() {
103
+ async disconnect() {
104
+ await this.__internal__storageCache.clearInterval();
103
105
  return this.provider.disconnect();
104
106
  }
105
107
  /**
@@ -112,7 +114,7 @@ class RpcCore {
112
114
  ...stats,
113
115
  core: {
114
116
  cacheHits: this.__internal__storageCacheHits,
115
- cacheSize: this.__internal__storageCacheSize
117
+ cacheSize: this.__internal__storageCache.length
116
118
  }
117
119
  }
118
120
  : undefined;
@@ -376,13 +378,12 @@ class RpcCore {
376
378
  ? value
377
379
  : (0, util_1.u8aToU8a)(value);
378
380
  const codec = this._newType(registry, blockHash, key, input, isEmpty, entryIndex);
379
- // store the retrieved result - the only issue with this cache is that there is no
380
- // clearing of it, so very long running processes (not just a couple of hours, longer)
381
- // will increase memory beyond what is allowed.
382
- this.__internal__storageCache.set(hexKey, codec);
383
- this.__internal__storageCacheSize++;
381
+ this._setToCache(hexKey, codec);
384
382
  return codec;
385
383
  }
384
+ _setToCache(key, value) {
385
+ this.__internal__storageCache.set(key, value);
386
+ }
386
387
  _newType(registry, blockHash, key, input, isEmpty, entryIndex = -1) {
387
388
  // single return value (via state.getStorage), decode the value based on the
388
389
  // outputType that we have specified. Fallback to Raw on nothing
package/cjs/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.1' };
4
+ exports.packageInfo = { name: '@polkadot/rpc-core', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.2.1' };
@@ -0,0 +1,22 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { ProviderInterface } from '@polkadot/rpc-provider/types';
3
+ import type { AnyFunction, Codec, DefinitionRpc } from '@polkadot/types/types';
4
+ export interface RpcInterfaceMethod {
5
+ <T extends Codec>(...params: unknown[]): Observable<T>;
6
+ raw(...params: unknown[]): Observable<unknown>;
7
+ meta: DefinitionRpc;
8
+ }
9
+ export type AugmentedRpc<F extends AnyFunction> = F & {
10
+ raw: <T>(...params: Parameters<F>) => Observable<T>;
11
+ meta: DefinitionRpc;
12
+ };
13
+ /** Stats from the rpc-core layer, including the provider stats */
14
+ export interface RpcCoreStats extends NonNullable<ProviderInterface['stats']> {
15
+ /** Internal stats for the rpc-core layer */
16
+ core: {
17
+ /** The number of values retrieved from the core cache */
18
+ cacheHits: number;
19
+ /** The number of entries in the core cache */
20
+ cacheSize: number;
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ export * from '@polkadot/rpc-core/types/jsonrpc';
2
+ export * from './base.js';
@@ -0,0 +1,2 @@
1
+ export interface RpcInterface {
2
+ }
@@ -0,0 +1,15 @@
1
+ import type { Observable } from 'rxjs';
2
+ export type DrrResult = <T>(source$: Observable<T>) => Observable<T>;
3
+ interface Options {
4
+ delay?: number;
5
+ skipChange?: boolean;
6
+ skipTimeout?: boolean;
7
+ }
8
+ /**
9
+ * Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
10
+ *
11
+ * @ignore
12
+ * @internal
13
+ */
14
+ export declare function drr({ delay, skipChange, skipTimeout }?: Options): DrrResult;
15
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './drr.js';
2
+ export * from './memo.js';
3
+ export * from './refCountDelay.js';
@@ -0,0 +1,6 @@
1
+ import type { Memoized } from '@polkadot/util/types';
2
+ import { Observable } from 'rxjs';
3
+ type ObsFn<T> = (...params: unknown[]) => Observable<T>;
4
+ /** @internal */
5
+ export declare function memo<T>(instanceId: string, inner: Function): Memoized<ObsFn<T>>;
6
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { MonoTypeOperatorFunction } from 'rxjs';
2
+ /** @internal */
3
+ export declare function refCountDelay<T>(delay?: number): MonoTypeOperatorFunction<T>;
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "./cjs/packageDetect.js"
19
19
  ],
20
20
  "type": "module",
21
- "version": "14.0.1",
21
+ "version": "14.2.1",
22
22
  "main": "./cjs/index.js",
23
23
  "module": "./index.js",
24
24
  "types": "./index.d.ts",
@@ -26,88 +26,184 @@
26
26
  "./cjs/package.json": "./cjs/package.json",
27
27
  "./cjs/*": "./cjs/*.js",
28
28
  ".": {
29
- "types": "./index.d.ts",
30
- "module": "./index.js",
31
- "require": "./cjs/index.js",
32
- "default": "./index.js"
29
+ "module": {
30
+ "types": "./index.d.ts",
31
+ "default": "./index.js"
32
+ },
33
+ "require": {
34
+ "types": "./cjs/index.d.ts",
35
+ "default": "./cjs/index.js"
36
+ },
37
+ "default": {
38
+ "types": "./index.d.ts",
39
+ "default": "./index.js"
40
+ }
33
41
  },
34
42
  "./bundle": {
35
- "types": "./bundle.d.ts",
36
- "module": "./bundle.js",
37
- "require": "./cjs/bundle.js",
38
- "default": "./bundle.js"
43
+ "module": {
44
+ "types": "./bundle.d.ts",
45
+ "default": "./bundle.js"
46
+ },
47
+ "require": {
48
+ "types": "./cjs/bundle.d.ts",
49
+ "default": "./cjs/bundle.js"
50
+ },
51
+ "default": {
52
+ "types": "./bundle.d.ts",
53
+ "default": "./bundle.js"
54
+ }
39
55
  },
40
56
  "./package.json": {
41
57
  "require": "./cjs/package.json",
42
58
  "default": "./package.json"
43
59
  },
44
60
  "./packageDetect": {
45
- "types": "./packageDetect.d.ts",
46
- "module": "./packageDetect.js",
47
- "require": "./cjs/packageDetect.js",
48
- "default": "./packageDetect.js"
61
+ "module": {
62
+ "types": "./packageDetect.d.ts",
63
+ "default": "./packageDetect.js"
64
+ },
65
+ "require": {
66
+ "types": "./cjs/packageDetect.d.ts",
67
+ "default": "./cjs/packageDetect.js"
68
+ },
69
+ "default": {
70
+ "types": "./packageDetect.d.ts",
71
+ "default": "./packageDetect.js"
72
+ }
49
73
  },
50
74
  "./packageInfo.js": {
51
- "types": "./packageInfo.d.ts",
52
- "module": "./packageInfo.js",
53
- "require": "./cjs/packageInfo.js",
54
- "default": "./packageInfo.js"
75
+ "module": {
76
+ "types": "./packageInfo.d.ts",
77
+ "default": "./packageInfo.js"
78
+ },
79
+ "require": {
80
+ "types": "./cjs/packageInfo.d.ts",
81
+ "default": "./cjs/packageInfo.js"
82
+ },
83
+ "default": {
84
+ "types": "./packageInfo.d.ts",
85
+ "default": "./packageInfo.js"
86
+ }
55
87
  },
56
88
  "./packageInfo": {
57
- "types": "./packageInfo.d.ts",
58
- "module": "./packageInfo.js",
59
- "require": "./cjs/packageInfo.js",
60
- "default": "./packageInfo.js"
89
+ "module": {
90
+ "types": "./packageInfo.d.ts",
91
+ "default": "./packageInfo.js"
92
+ },
93
+ "require": {
94
+ "types": "./cjs/packageInfo.d.ts",
95
+ "default": "./cjs/packageInfo.js"
96
+ },
97
+ "default": {
98
+ "types": "./packageInfo.d.ts",
99
+ "default": "./packageInfo.js"
100
+ }
61
101
  },
62
102
  "./types": {
63
- "types": "./types/index.d.ts",
64
- "module": "./types/index.js",
65
- "require": "./cjs/types/index.js",
66
- "default": "./types/index.js"
103
+ "module": {
104
+ "types": "./types/index.d.ts",
105
+ "default": "./types/index.js"
106
+ },
107
+ "require": {
108
+ "types": "./cjs/types/index.d.ts",
109
+ "default": "./cjs/types/index.js"
110
+ },
111
+ "default": {
112
+ "types": "./types/index.d.ts",
113
+ "default": "./types/index.js"
114
+ }
67
115
  },
68
116
  "./types/base": {
69
- "types": "./types/base.d.ts",
70
- "module": "./types/base.js",
71
- "require": "./cjs/types/base.js",
72
- "default": "./types/base.js"
117
+ "module": {
118
+ "types": "./types/base.d.ts",
119
+ "default": "./types/base.js"
120
+ },
121
+ "require": {
122
+ "types": "./cjs/types/base.d.ts",
123
+ "default": "./cjs/types/base.js"
124
+ },
125
+ "default": {
126
+ "types": "./types/base.d.ts",
127
+ "default": "./types/base.js"
128
+ }
73
129
  },
74
130
  "./types/jsonrpc": {
75
- "types": "./types/jsonrpc.d.ts",
76
- "module": "./types/jsonrpc.js",
77
- "require": "./cjs/types/jsonrpc.js",
78
- "default": "./types/jsonrpc.js"
131
+ "module": {
132
+ "types": "./types/jsonrpc.d.ts",
133
+ "default": "./types/jsonrpc.js"
134
+ },
135
+ "require": {
136
+ "types": "./cjs/types/jsonrpc.d.ts",
137
+ "default": "./cjs/types/jsonrpc.js"
138
+ },
139
+ "default": {
140
+ "types": "./types/jsonrpc.d.ts",
141
+ "default": "./types/jsonrpc.js"
142
+ }
79
143
  },
80
144
  "./util": {
81
- "types": "./util/index.d.ts",
82
- "module": "./util/index.js",
83
- "require": "./cjs/util/index.js",
84
- "default": "./util/index.js"
145
+ "module": {
146
+ "types": "./util/index.d.ts",
147
+ "default": "./util/index.js"
148
+ },
149
+ "require": {
150
+ "types": "./cjs/util/index.d.ts",
151
+ "default": "./cjs/util/index.js"
152
+ },
153
+ "default": {
154
+ "types": "./util/index.d.ts",
155
+ "default": "./util/index.js"
156
+ }
85
157
  },
86
158
  "./util/drr": {
87
- "types": "./util/drr.d.ts",
88
- "module": "./util/drr.js",
89
- "require": "./cjs/util/drr.js",
90
- "default": "./util/drr.js"
159
+ "module": {
160
+ "types": "./util/drr.d.ts",
161
+ "default": "./util/drr.js"
162
+ },
163
+ "require": {
164
+ "types": "./cjs/util/drr.d.ts",
165
+ "default": "./cjs/util/drr.js"
166
+ },
167
+ "default": {
168
+ "types": "./util/drr.d.ts",
169
+ "default": "./util/drr.js"
170
+ }
91
171
  },
92
172
  "./util/memo": {
93
- "types": "./util/memo.d.ts",
94
- "module": "./util/memo.js",
95
- "require": "./cjs/util/memo.js",
96
- "default": "./util/memo.js"
173
+ "module": {
174
+ "types": "./util/memo.d.ts",
175
+ "default": "./util/memo.js"
176
+ },
177
+ "require": {
178
+ "types": "./cjs/util/memo.d.ts",
179
+ "default": "./cjs/util/memo.js"
180
+ },
181
+ "default": {
182
+ "types": "./util/memo.d.ts",
183
+ "default": "./util/memo.js"
184
+ }
97
185
  },
98
186
  "./util/refCountDelay": {
99
- "types": "./util/refCountDelay.d.ts",
100
- "module": "./util/refCountDelay.js",
101
- "require": "./cjs/util/refCountDelay.js",
102
- "default": "./util/refCountDelay.js"
187
+ "module": {
188
+ "types": "./util/refCountDelay.d.ts",
189
+ "default": "./util/refCountDelay.js"
190
+ },
191
+ "require": {
192
+ "types": "./cjs/util/refCountDelay.d.ts",
193
+ "default": "./cjs/util/refCountDelay.js"
194
+ },
195
+ "default": {
196
+ "types": "./util/refCountDelay.d.ts",
197
+ "default": "./util/refCountDelay.js"
198
+ }
103
199
  }
104
200
  },
105
201
  "dependencies": {
106
- "@polkadot/rpc-augment": "14.0.1",
107
- "@polkadot/rpc-provider": "14.0.1",
108
- "@polkadot/types": "14.0.1",
109
- "@polkadot/util": "^13.1.1",
202
+ "@polkadot/rpc-augment": "14.2.1",
203
+ "@polkadot/rpc-provider": "14.2.1",
204
+ "@polkadot/types": "14.2.1",
205
+ "@polkadot/util": "^13.2.2",
110
206
  "rxjs": "^7.8.1",
111
- "tslib": "^2.7.0"
207
+ "tslib": "^2.8.0"
112
208
  }
113
209
  }
package/packageInfo.js CHANGED
@@ -1 +1 @@
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: '14.0.1' };
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: '14.2.1' };