Update @polkadot/types (#105)
This commit is contained in:
@@ -37,8 +37,8 @@
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/api-format": "^0.14.5",
|
||||
"@polkadot/api-provider": "^0.14.5",
|
||||
"@polkadot/jsonrpc": "^0.19.5",
|
||||
"@polkadot/params": "^0.19.5",
|
||||
"@polkadot/jsonrpc": "^0.20.1",
|
||||
"@polkadot/params": "^0.20.1",
|
||||
"@polkadot/util": "^0.24.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,29 +4,27 @@
|
||||
|
||||
import isFunction from '@polkadot/util/is/function';
|
||||
|
||||
jest.mock('@polkadot/jsonrpc', () =>
|
||||
new Map([
|
||||
['test', {
|
||||
public: {
|
||||
blah: {
|
||||
params: [
|
||||
{ name: 'foo', type: 'Address' }
|
||||
],
|
||||
type: 'Address'
|
||||
},
|
||||
bleh: {
|
||||
params: [],
|
||||
type: 'Address'
|
||||
},
|
||||
pubsub: {
|
||||
isSubscription: true,
|
||||
params: [],
|
||||
type: 'Address'
|
||||
}
|
||||
jest.mock('@polkadot/jsonrpc', () => ({
|
||||
test: {
|
||||
public: {
|
||||
blah: {
|
||||
params: [
|
||||
{ name: 'foo', type: 'Address' }
|
||||
],
|
||||
type: 'Address'
|
||||
},
|
||||
bleh: {
|
||||
params: [],
|
||||
type: 'Address'
|
||||
},
|
||||
pubsub: {
|
||||
isSubscription: true,
|
||||
params: [],
|
||||
type: 'Address'
|
||||
}
|
||||
}]
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const createInterface = require('./interface').default;
|
||||
|
||||
|
||||
@@ -14,17 +14,16 @@ import methodSend from './methodSend';
|
||||
import methodSubscribe from './methodSubscribe';
|
||||
|
||||
export default function createInterface (provider: ProviderInterface, section: Interface$Sections): ApiInterface$Section {
|
||||
const exposed: ApiInterface$Section = {};
|
||||
const definition = interfaces.get(section);
|
||||
const definition = interfaces[section];
|
||||
|
||||
assert(!isUndefined(definition), `Unable to find section'${section}`);
|
||||
assert(!isUndefined(definition), `Unable to find section '${section}`);
|
||||
|
||||
// @ts-ignore undefined check done in assert
|
||||
const methods = definition.public;
|
||||
|
||||
return Object
|
||||
.keys(methods)
|
||||
.reduce((exposed, name: string) => {
|
||||
.reduce((exposed, name) => {
|
||||
const rpcName = `${section}_${name}`;
|
||||
const def = methods[name];
|
||||
|
||||
@@ -33,5 +32,5 @@ export default function createInterface (provider: ProviderInterface, section: I
|
||||
: methodSend(provider, rpcName, name, def);
|
||||
|
||||
return exposed;
|
||||
}, exposed);
|
||||
}, {} as ApiInterface$Section);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interface$Method } from '@polkadot/jsonrpc/types';
|
||||
import { Interfaces } from '@polkadot/jsonrpc/types';
|
||||
import { SectionItem } from '@polkadot/params/types';
|
||||
import { ProviderInterface } from '@polkadot/api-provider/types';
|
||||
import { ApiInterface$Section$Method } from '../types';
|
||||
|
||||
@@ -12,7 +13,7 @@ import signature from '@polkadot/params/signature';
|
||||
|
||||
import createParams from './params';
|
||||
|
||||
export default function createMethodSend (provider: ProviderInterface, rpcName: string, name: string, method: Interface$Method): ApiInterface$Section$Method {
|
||||
export default function createMethodSend (provider: ProviderInterface, rpcName: string, name: string, method: SectionItem<Interfaces>): ApiInterface$Section$Method {
|
||||
const call = async (...values: Array<any>): Promise<any> => {
|
||||
// TODO Warn on deprecated methods
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interface$Method } from '@polkadot/jsonrpc/types';
|
||||
import { Interfaces } from '@polkadot/jsonrpc/types';
|
||||
import { SectionItem } from '@polkadot/params/types';
|
||||
import { ProviderInterface, ProviderInterface$Callback } from '@polkadot/api-provider/types';
|
||||
import { ApiInterface$Section$Method } from '../types';
|
||||
|
||||
@@ -14,7 +15,7 @@ import isFunction from '@polkadot/util/is/function';
|
||||
|
||||
import createParams from './params';
|
||||
|
||||
export default function methodSubscribe (provider: ProviderInterface, rpcName: string, name: string, method: Interface$Method): ApiInterface$Section$Method {
|
||||
export default function methodSubscribe (provider: ProviderInterface, rpcName: string, name: string, method: SectionItem<Interfaces>): ApiInterface$Section$Method {
|
||||
const unsubscribe = (subscriptionId: any): Promise<any> =>
|
||||
provider.send(`unsubscribe_${name}`, [subscriptionId]);
|
||||
const call = async (...values: Array<any>): Promise<any> => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interface$Sections } from '@polkadot/jsonrpc/types';
|
||||
import { ProviderInterface } from '@polkadot/api-provider/types';
|
||||
import { ApiInterface } from './types';
|
||||
|
||||
@@ -14,11 +15,9 @@ import createInterface from './create/interface';
|
||||
export default function api (provider: ProviderInterface): ApiInterface {
|
||||
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
|
||||
|
||||
const exposed: ApiInterface = {};
|
||||
return Object.keys(interfaces).reduce((exposed, type) => {
|
||||
exposed[type as Interface$Sections] = createInterface(provider, type as Interface$Sections);
|
||||
|
||||
for (let type of interfaces.keys()) {
|
||||
exposed[type] = createInterface(provider, type);
|
||||
}
|
||||
|
||||
return exposed;
|
||||
return exposed;
|
||||
}, {} as ApiInterface);
|
||||
}
|
||||
|
||||
Vendored
+3
-2
@@ -2,10 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interface$Sections } from '@polkadot/jsonrpc/types';
|
||||
import { Interfaces, Interface$Sections } from '@polkadot/jsonrpc/types';
|
||||
|
||||
export type ApiInterface$Section$Method = {
|
||||
(...params: Array<any>): Promise<any>;
|
||||
|
||||
unsubscribe: (id: number) => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -14,5 +15,5 @@ export type ApiInterface$Section = {
|
||||
};
|
||||
|
||||
export type ApiInterface = {
|
||||
[index: string]: ApiInterface$Section
|
||||
[key in keyof Interfaces]: ApiInterface$Section
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user