Allow rpc expose definition/ metadata (#3488)
* Expose rpc defination(meta) * Fix lint * Change def to meta
This commit is contained in:
@@ -291,6 +291,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
(section as Record<string, { json: unknown }>)[methodName].json = decorateMethod(method.json, { methodName }) as unknown;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
(section as Record<string, { raw: unknown }>)[methodName].raw = decorateMethod(method.raw, { methodName }) as unknown;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
(section as Record<string, { meta: unknown }>)[methodName].meta = method.meta;
|
||||
}
|
||||
|
||||
return section;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Json, Raw } from '@polkadot/types/codec';
|
||||
import type { AnyFunction, Callback } from '@polkadot/types/types';
|
||||
import type { AnyFunction, Callback, DefinitionRpc } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@@ -11,6 +11,7 @@ import { ApiTypes, PromiseResult, Push, RxResult, UnsubscribePromise } from './b
|
||||
export interface RpcRxResult<F extends AnyFunction> extends RxResult<F> {
|
||||
json (...args: Parameters<F>): Observable<Json>;
|
||||
raw (...args: Parameters<F>): Observable<Raw>;
|
||||
meta: DefinitionRpc;
|
||||
}
|
||||
|
||||
export interface RpcPromiseResult<F extends AnyFunction> extends PromiseResult<F> {
|
||||
@@ -18,6 +19,7 @@ export interface RpcPromiseResult<F extends AnyFunction> extends PromiseResult<F
|
||||
json (...args: Push<Parameters<F>, Callback<Json>>): UnsubscribePromise;
|
||||
raw (...args: Parameters<F>): Promise<Raw>;
|
||||
raw (...args: Push<Parameters<F>, Callback<Raw>>): UnsubscribePromise;
|
||||
meta: DefinitionRpc;
|
||||
}
|
||||
|
||||
export type RpcMethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs'
|
||||
|
||||
@@ -14,7 +14,7 @@ function createApi (): Promise<ApiPromise> {
|
||||
return new ApiPromise({ provider }).isReady;
|
||||
}
|
||||
|
||||
describe.skip('misc quick tests', (): void => {
|
||||
describe('misc quick tests', (): void => {
|
||||
it.skip('retrieves balances correctly', async (): Promise<void> => {
|
||||
const api = await createApi();
|
||||
|
||||
@@ -76,4 +76,12 @@ describe.skip('misc quick tests', (): void => {
|
||||
.map(([block, value]) => [block, value.toRawType(), value.toHuman()])
|
||||
));
|
||||
});
|
||||
|
||||
it('expose rpc and rx definition', async (): Promise<void> => {
|
||||
const api = await createApi();
|
||||
|
||||
console.error(api.rpc.payment.queryFeeDetails.meta);
|
||||
|
||||
console.error(api.rx.rpc.chain.getBlock.meta);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -192,13 +192,14 @@ export class RpcCore {
|
||||
}, {} as RpcInterface[Section]);
|
||||
}
|
||||
|
||||
private _memomize (creator: (outputAs: OutputType) => (...values: any[]) => Observable<any>): Memoized<RpcInterfaceMethod> {
|
||||
private _memomize (creator: (outputAs: OutputType) => (...values: any[]) => Observable<any>, def: DefinitionRpc): Memoized<RpcInterfaceMethod> {
|
||||
const memoized = memoize(creator('scale') as RpcInterfaceMethod, {
|
||||
getInstanceId: () => this.#instanceId
|
||||
});
|
||||
|
||||
memoized.json = creator('json');
|
||||
memoized.raw = creator('raw');
|
||||
memoized.meta = def;
|
||||
|
||||
return memoized;
|
||||
}
|
||||
@@ -253,7 +254,7 @@ export class RpcCore {
|
||||
);
|
||||
};
|
||||
|
||||
memoized = this._memomize(creator);
|
||||
memoized = this._memomize(creator, def);
|
||||
|
||||
return memoized;
|
||||
}
|
||||
@@ -334,7 +335,7 @@ export class RpcCore {
|
||||
}).pipe(drr());
|
||||
};
|
||||
|
||||
memoized = this._memomize(creator);
|
||||
memoized = this._memomize(creator, def);
|
||||
|
||||
return memoized;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { DefinitionRpc } from '@polkadot/types/types';
|
||||
|
||||
export * from './types.jsonrpc';
|
||||
|
||||
export interface RpcInterfaceMethod {
|
||||
(...params: any[]): Observable<any>;
|
||||
json (...params: any[]): Observable<any>;
|
||||
raw (...params: any[]): Observable<any>;
|
||||
meta: DefinitionRpc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user