@pezkuwi/rpc-core 16.5.5
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/README.md +3 -0
- package/build/bundle.d.ts +91 -0
- package/build/index.d.ts +2 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/types/base.d.ts +22 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/jsonrpc.d.ts +2 -0
- package/build/util/drr.d.ts +15 -0
- package/build/util/index.d.ts +3 -0
- package/build/util/memo.d.ts +6 -0
- package/build/util/refCountDelay.d.ts +3 -0
- package/package.json +35 -0
- package/src/bundle.ts +535 -0
- package/src/cached.spec.ts +129 -0
- package/src/checkTypes.manual.ts +4 -0
- package/src/index.spec.ts +55 -0
- package/src/index.ts +6 -0
- package/src/methodSend.spec.ts +75 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +13 -0
- package/src/packageInfo.ts +6 -0
- package/src/replay.spec.ts +73 -0
- package/src/types/base.ts +28 -0
- package/src/types/index.ts +8 -0
- package/src/types/jsonrpc.ts +7 -0
- package/src/util/drr.spec.ts +50 -0
- package/src/util/drr.ts +52 -0
- package/src/util/index.ts +6 -0
- package/src/util/memo.ts +36 -0
- package/src/util/refCountDelay.ts +45 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ProviderInterface } from '@pezkuwi/rpc-provider/types';
|
|
2
|
+
import type { AnyNumber, DefinitionRpc, DefinitionRpcExt, DefinitionRpcSub, Registry } from '@pezkuwi/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
|
+
/**
|
|
10
|
+
* Custom size of the rpc LRUCache capacity. Defaults to `RPC_CORE_DEFAULT_CAPACITY` (1024 * 10 * 10)
|
|
11
|
+
*/
|
|
12
|
+
rpcCacheCapacity?: number;
|
|
13
|
+
ttl?: number | null;
|
|
14
|
+
userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @name Rpc
|
|
18
|
+
* @summary The API may use a HTTP or WebSockets provider.
|
|
19
|
+
* @description It allows for querying a Polkadot Client Node.
|
|
20
|
+
* WebSockets provider is recommended since HTTP provider only supports basic querying.
|
|
21
|
+
*
|
|
22
|
+
* ```mermaid
|
|
23
|
+
* graph LR;
|
|
24
|
+
* A[Api] --> |WebSockets| B[WsProvider];
|
|
25
|
+
* B --> |endpoint| C[ws://127.0.0.1:9944]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* <BR>
|
|
30
|
+
*
|
|
31
|
+
* ```javascript
|
|
32
|
+
* import Rpc from '@pezkuwi/rpc-core';
|
|
33
|
+
* import { WsProvider } from '@pezkuwi/rpc-provider/ws';
|
|
34
|
+
*
|
|
35
|
+
* const provider = new WsProvider('ws://127.0.0.1:9944');
|
|
36
|
+
* const rpc = new Rpc(provider);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class RpcCore {
|
|
40
|
+
#private;
|
|
41
|
+
readonly mapping: Map<string, DefinitionRpcExt>;
|
|
42
|
+
readonly provider: ProviderInterface;
|
|
43
|
+
readonly sections: string[];
|
|
44
|
+
/**
|
|
45
|
+
* @constructor
|
|
46
|
+
* Default constructor for the core RPC handler
|
|
47
|
+
* @param {Registry} registry Type Registry
|
|
48
|
+
* @param {ProviderInterface} options.provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
|
|
49
|
+
* @param {number} [options.rpcCacheCapacity] Custom size of the rpc LRUCache capacity. Defaults to `RPC_CORE_DEFAULT_CAPACITY` (1024 * 10 * 10)
|
|
50
|
+
*/
|
|
51
|
+
constructor(instanceId: string, registry: Registry, { isPedantic, provider, rpcCacheCapacity, ttl, userRpc }: Options);
|
|
52
|
+
/**
|
|
53
|
+
* @description Returns the connected status of a provider
|
|
54
|
+
*/
|
|
55
|
+
get isConnected(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @description Manually connect from the attached provider
|
|
58
|
+
*/
|
|
59
|
+
connect(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* @description Manually disconnect from the attached provider
|
|
62
|
+
*/
|
|
63
|
+
disconnect(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* @description Returns the underlying core stats, including those from teh provider
|
|
66
|
+
*/
|
|
67
|
+
get stats(): RpcCoreStats | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* @description Sets a registry swap (typically from Api)
|
|
70
|
+
*/
|
|
71
|
+
setRegistrySwap(registrySwap: (blockHash: Uint8Array) => Promise<{
|
|
72
|
+
registry: Registry;
|
|
73
|
+
}>): void;
|
|
74
|
+
/**
|
|
75
|
+
* @description Sets a function to resolve block hash from block number
|
|
76
|
+
*/
|
|
77
|
+
setResolveBlockHash(resolveBlockHash: (blockNumber: AnyNumber) => Promise<Uint8Array>): void;
|
|
78
|
+
addUserInterfaces(userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
|
|
79
|
+
private _memomize;
|
|
80
|
+
private _formatResult;
|
|
81
|
+
private _createMethodSend;
|
|
82
|
+
private _createSubscriber;
|
|
83
|
+
private _createMethodSubscribe;
|
|
84
|
+
private _formatParams;
|
|
85
|
+
private _formatOutput;
|
|
86
|
+
private _formatStorageData;
|
|
87
|
+
private _formatStorageSet;
|
|
88
|
+
private _formatStorageSetEntry;
|
|
89
|
+
private _setToCache;
|
|
90
|
+
private _newType;
|
|
91
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { ProviderInterface } from '@pezkuwi/rpc-provider/types';
|
|
3
|
+
import type { AnyFunction, Codec, DefinitionRpc } from '@pezkuwi/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,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,6 @@
|
|
|
1
|
+
import type { Memoized } from '@pezkuwi/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 {};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Jaco Greeff <jacogr@gmail.com>",
|
|
3
|
+
"bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
|
|
4
|
+
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/rpc-core#readme",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"name": "@pezkuwi/rpc-core",
|
|
11
|
+
"repository": {
|
|
12
|
+
"directory": "packages/rpc-core",
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/pezkuwichain/pezkuwi-api.git"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./packageDetect.js",
|
|
18
|
+
"./packageDetect.cjs"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"version": "16.5.5",
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@pezkuwi/rpc-augment": "16.5.5",
|
|
25
|
+
"@pezkuwi/rpc-provider": "16.5.5",
|
|
26
|
+
"@pezkuwi/types": "16.5.5",
|
|
27
|
+
"@pezkuwi/util": "14.0.5",
|
|
28
|
+
"rxjs": "^7.8.1",
|
|
29
|
+
"tslib": "^2.8.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@pezkuwi/keyring": "14.0.5",
|
|
33
|
+
"@pezkuwi/rpc-augment": "16.5.5"
|
|
34
|
+
}
|
|
35
|
+
}
|