From 6ff847170de6b7608a4f6fa05237c9b42b95dba8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 3 Oct 2018 20:31:23 +0200 Subject: [PATCH] Various minor tweaks all-around (#194) * Fix exports for provider * Cleanu jsonrpc method exposure * name -> section --- packages/api-provider/src/index.ts | 9 ++------- packages/api/src/index.ts | 4 ++-- packages/type-jsonrpc/src/author.ts | 21 ++++++++----------- packages/type-jsonrpc/src/chain.ts | 25 +++++++++++------------ packages/type-jsonrpc/src/state.ts | 30 ++++++++++++++++------------ packages/type-jsonrpc/src/system.ts | 22 +++++++++----------- packages/type-jsonrpc/src/types.d.ts | 12 +++++------ 7 files changed, 55 insertions(+), 68 deletions(-) diff --git a/packages/api-provider/src/index.ts b/packages/api-provider/src/index.ts index be7609e409..f2502b9f3f 100644 --- a/packages/api-provider/src/index.ts +++ b/packages/api-provider/src/index.ts @@ -2,10 +2,5 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import http from './http'; -import ws from './ws'; - -export { - http, - ws -}; +export { default as HttpProvider } from './http'; +export { default as WsProvider } from './ws'; diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index f2922b5e75..9abf54cd27 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -63,11 +63,11 @@ export default class Api implements ApiInterface { return `${method} (${inputs}): ${type}`; } - private createInterface ({ methods, name }: Section): ApiInterface$Section { + private createInterface ({ methods, section }: Section): ApiInterface$Section { return Object .keys(methods) .reduce((exposed, method) => { - const rpcName = `${name}_${method}`; + const rpcName = `${section}_${method}`; const def = methods[method]; exposed[method] = def.isSubscription diff --git a/packages/type-jsonrpc/src/author.ts b/packages/type-jsonrpc/src/author.ts index 9a7b81ca48..59646a09ae 100644 --- a/packages/type-jsonrpc/src/author.ts +++ b/packages/type-jsonrpc/src/author.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { MethodOpt, Section, SectionMethods } from './types'; +import { MethodOpt, Section } from './types'; import createMethod from './create/method'; import createParam from './create/param'; @@ -22,11 +22,7 @@ const submitExtrinsic: MethodOpt = { type: 'Hash' }; -const methods: { [index: string]: MethodOpt } = { - pendingExtrinsics, submitExtrinsic -}; - -export type Methods = typeof methods; +const section = 'author'; /** * @summary Methods to work with authors & contributors. @@ -35,10 +31,9 @@ export default { isDeprecated: false, isHidden: false, description: 'Authoring of network items', - name: 'author', - methods: Object.keys(methods).reduce((result, key) => { - result[key] = createMethod('author', key, methods[key]); - - return result; - }, {} as SectionMethods) -} as Section; + section, + methods: { + pendingExtrinsics: createMethod(section, 'pendingExtrinsics', pendingExtrinsics), + submitExtrinsic: createMethod(section, 'submitExtrinsic', submitExtrinsic) + } +} as Section; diff --git a/packages/type-jsonrpc/src/chain.ts b/packages/type-jsonrpc/src/chain.ts index 434587c386..37ac571419 100644 --- a/packages/type-jsonrpc/src/chain.ts +++ b/packages/type-jsonrpc/src/chain.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { MethodOpt, Section, SectionMethods } from './types'; +import { MethodOpt, Section } from './types'; import createMethod from './create/method'; import createParam from './create/param'; @@ -53,11 +53,7 @@ const newHead: MethodOpt = { type: 'Header' }; -const methods: { [index: string]: MethodOpt } = { - getBlock, getHead, getHeader, getRuntimeVersion, getRuntimeVersionAt, newHead -}; - -export type Methods = typeof methods; +const section = 'chain'; /** * @summary Methods to retrieve chain data. @@ -66,10 +62,13 @@ export default { isDeprecated: false, isHidden: false, description: 'Retrieval of chain data', - name: 'chain', - methods: Object.keys(methods).reduce((result, key) => { - result[key] = createMethod('chain', key, methods[key]); - - return result; - }, {} as SectionMethods) -} as Section; + section, + methods: { + getBlock: createMethod(section, 'getBlock', getBlock), + getHead: createMethod(section, 'getHead', getHead), + getHeader: createMethod(section, 'getHeader', getHeader), + getRuntimeVersion: createMethod(section, 'getRuntimeVersion', getRuntimeVersion), + getRuntimeVersionAt: createMethod(section, 'getRuntimeVersionAt', getRuntimeVersionAt), + newHead: createMethod(section, 'newHead', newHead) + } +} as Section; diff --git a/packages/type-jsonrpc/src/state.ts b/packages/type-jsonrpc/src/state.ts index 080102e944..910ca7bdbd 100644 --- a/packages/type-jsonrpc/src/state.ts +++ b/packages/type-jsonrpc/src/state.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { MethodOpt, Section, SectionMethods } from './types'; +import { MethodOpt, Section } from './types'; import createMethod from './create/method'; import createParam from './create/param'; @@ -104,11 +104,7 @@ const storage: MethodOpt = { type: 'StorageChangeSet' }; -const methods: { [index: string]: MethodOpt } = { - call, callAt, getMetadata, getMetadataAt, getStorage, getStorageAt, getStorageHash, getStorageHashAt, getStorageSize, getStorageSizeAt, storage -}; - -export type Methods = typeof methods; +const section = 'state'; /** * @summary Query the state and state storage. @@ -117,10 +113,18 @@ export default { isDeprecated: false, isHidden: false, description: 'Query of state', - name: 'state', - methods: Object.keys(methods).reduce((result, key) => { - result[key] = createMethod('state', key, methods[key]); - - return result; - }, {} as SectionMethods) -} as Section; + section, + methods: { + call: createMethod(section, 'call', call), + callAt: createMethod(section, 'callAt', callAt), + getMetadata: createMethod(section, 'getMetadata', getMetadata), + getMetadataAt: createMethod(section, 'getMetadataAt', getMetadataAt), + getStorage: createMethod(section, 'getStorage', getStorage), + getStorageAt: createMethod(section, 'getStorageAt', getStorageAt), + getStorageHash: createMethod(section, 'getStorageHash', getStorageHash), + getStorageHashAt: createMethod(section, 'getStorageHashAt', getStorageHashAt), + getStorageSize: createMethod(section, 'getStorageSize', getStorageSize), + getStorageSizeAt: createMethod(section, 'getStorageSizeAt', getStorageSizeAt), + storage: createMethod(section, 'storage', storage) + } +} as Section; diff --git a/packages/type-jsonrpc/src/system.ts b/packages/type-jsonrpc/src/system.ts index f7555f1c20..dc9e65b00f 100644 --- a/packages/type-jsonrpc/src/system.ts +++ b/packages/type-jsonrpc/src/system.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { MethodOpt, Section, SectionMethods } from './types'; +import { MethodOpt, Section } from './types'; import createMethod from './create/method'; @@ -24,11 +24,7 @@ const version: MethodOpt = { type: 'Text' }; -const methods: { [index: string]: MethodOpt } = { - chain, name, version -}; - -export type Methods = typeof methods; +const section = 'system'; /** * @summary Methods to retrieve system info. @@ -37,10 +33,10 @@ export default { isDeprecated: false, isHidden: false, description: 'Methods to retrieve system info', - name: 'system', - methods: Object.keys(methods).reduce((result, key) => { - result[key] = createMethod('system', key, methods[key]); - - return result; - }, {} as SectionMethods) -} as Section; + section, + methods: { + chain: createMethod(section, 'chain', chain), + name: createMethod(section, 'name', name), + version: createMethod(section, 'version', version) + } +} as Section; diff --git a/packages/type-jsonrpc/src/types.d.ts b/packages/type-jsonrpc/src/types.d.ts index 9ba6a33527..4cc8e99904 100644 --- a/packages/type-jsonrpc/src/types.d.ts +++ b/packages/type-jsonrpc/src/types.d.ts @@ -34,14 +34,12 @@ export type Method = { type: CodecTypes }; -export type SectionMethods = { - [key in keyof M]: Method -}; - -export type Section = { +export type Section = { isDeprecated: boolean, isHidden: boolean, description: string, - name: string, - methods: SectionMethods + section: string, + methods: { + [index: string]: Method + } };