Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"packages": [
"packages/*"
],
"version": "0.13.8"
"version": "0.14.0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.19.25"
"@polkadot/dev": "^0.19.28"
}
}
10 changes: 5 additions & 5 deletions packages/api-format/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-format",
"version": "0.13.8",
"version": "0.14.0",
"description": "Input/Output formatters for JsonRPC exchange",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -35,9 +35,9 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/jsonrpc": "^0.17.24",
"@polkadot/primitives-json": "^0.17.24",
"@polkadot/util": "^0.22.9",
"@polkadot/util-keyring": "^0.22.9"
"@polkadot/jsonrpc": "^0.18.2",
"@polkadot/primitives-json": "^0.18.2",
"@polkadot/util": "^0.23.1",
"@polkadot/util-keyring": "^0.23.1"
}
}
4 changes: 2 additions & 2 deletions packages/api-format/src/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// of the ISC license. See the LICENSE file for details.
// @flow

module.exports = function echo (value: mixed): mixed {
export default function echo (value: mixed): mixed {
return value;
};
}
2 changes: 1 addition & 1 deletion packages/api-format/src/echo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const echo = require('./echo');
import echo from './echo';

describe('echo', () => {
it('returns input value as output value', () => {
Expand Down
16 changes: 9 additions & 7 deletions packages/api-format/src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import type { Param$Types, Param$Type$Array } from '@polkadot/params/types';
import type { FormatterFunction } from './types';

import typeToString from '@polkadot/params/typeToString';
import isUndefined from '@polkadot/util/is/undefined';
import logger from '@polkadot/util/logger';

import echo from './echo';

type FormattersFunctionMap = $Shape<{
[Param$Types]: FormatterFunction
}>;

const typeToString = require('@polkadot/params/typeToString');
const isUndefined = require('@polkadot/util/is/undefined');
const l = require('@polkadot/util/logger')('api-format');

const echo = require('./echo');
const l = logger('api-format');

// flowlint-next-line unclear-type:off
function formatSingleType (formatters: FormattersFunctionMap, type: Param$Types, value: any): any {
Expand All @@ -41,7 +43,7 @@ function formatArrayType (formatters: FormattersFunctionMap, [ type ]: Param$Typ
}

// flowlint-next-line unclear-type:off
module.exports = function format (formatters: FormattersFunctionMap, types: Array<Param$Types>, values: Array<any>): Array<any> {
export default function format (formatters: FormattersFunctionMap, types: Array<Param$Types>, values: Array<any>): Array<any> {
return values.map((value, index): mixed => {
const type = types[index];

Expand All @@ -52,4 +54,4 @@ module.exports = function format (formatters: FormattersFunctionMap, types: Arra

return formatSingleType(formatters, type, value);
});
};
}
4 changes: 2 additions & 2 deletions packages/api-format/src/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const format = require('./format');
const echo = require('./echo');
import format from './format';
import echo from './echo';

describe('format', () => {
let formatters;
Expand Down
6 changes: 3 additions & 3 deletions packages/api-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// of the ISC license. See the LICENSE file for details.
// @flow

const formatInputs = require('./input');
const formatOutput = require('./output');
import formatInputs from './input';
import formatOutput from './output';

module.exports = {
export {
formatInputs,
formatOutput
};
12 changes: 6 additions & 6 deletions packages/api-format/src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import type { Params } from '@polkadot/params/types';

const addressDecode = require('@polkadot/util-keyring/address/decode');
const bytesEncode = require('@polkadot/primitives-json/bytes/encode');
const hashEncode = require('@polkadot/primitives-json/hash/encode');
import addressDecode from '@polkadot/util-keyring/address/decode';
import bytesEncode from '@polkadot/primitives-json/bytes/encode';
import hashEncode from '@polkadot/primitives-json/hash/encode';

const format = require('./format');
import format from './format';

const formatters = {
// funnily named, goes from address -> u8a
Expand All @@ -19,8 +19,8 @@ const formatters = {
};

// flowlint-next-line unclear-type:off
module.exports = function formatInputs (params: Params, values: Array<any>): Array<any> {
export default function formatInputs (params: Params, values: Array<any>): Array<any> {
const types = params.map(({ type }) => type);

return format(formatters, types, values);
};
}
2 changes: 1 addition & 1 deletion packages/api-format/src/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const { formatInputs } = require('./index');
import { formatInputs } from './index';

describe('formatInputs', () => {
it('formats each value in an array', () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/api-format/src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import type { Param$Types } from '@polkadot/params/types';

const addressEncode = require('@polkadot/util-keyring/address/encode');
const bnDecode = require('@polkadot/primitives-json/bn/decode');
const bytesDecode = require('@polkadot/primitives-json/bytes/decode');
const headerDecode = require('@polkadot/primitives-json/header/decode');
const isNull = require('@polkadot/util/is/null');
const isUndefined = require('@polkadot/util/is/undefined');
import addressEncode from '@polkadot/util-keyring/address/encode';
import bnDecode from '@polkadot/primitives-json/bn/decode';
import bytesDecode from '@polkadot/primitives-json/bytes/decode';
import headerDecode from '@polkadot/primitives-json/header/decode';
import isNull from '@polkadot/util/is/null';
import isUndefined from '@polkadot/util/is/undefined';

const format = require('./format');
import format from './format';

const formatters = {
// publicKey -> address
Expand All @@ -23,10 +23,10 @@ const formatters = {
'u64': bnDecode
};

module.exports = function formatOutput (type: Param$Types, value?: mixed): ?mixed {
export default function formatOutput (type: Param$Types, value?: mixed): ?mixed {
if (isUndefined(value) || isNull(value)) {
return value;
}

return format(formatters, [type], [value])[0];
};
}
4 changes: 2 additions & 2 deletions packages/api-format/src/output.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const BN = require('bn.js');
import BN from 'bn.js';

const { formatOutput } = require('./index');
import { formatOutput } from './index';

describe('formatOutput', () => {
it('formats the value', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/api-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-provider",
"version": "0.13.8",
"version": "0.14.0",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -39,10 +39,10 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/storage": "^0.17.24",
"@polkadot/util": "^0.22.9",
"@polkadot/util-crypto": "^0.22.9",
"@polkadot/util-keyring": "^0.22.9",
"@polkadot/storage": "^0.18.2",
"@polkadot/util": "^0.23.1",
"@polkadot/util-crypto": "^0.23.1",
"@polkadot/util-keyring": "^0.23.1",
"eventemitter3": "^2.0.3",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
Expand Down
10 changes: 5 additions & 5 deletions packages/api-provider/src/coder/json/decodeResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import type { JsonRpcResponse, JsonRpcResponseBase$Error } from '../../types';
import type { RpcCoderState } from './types';

const assert = require('@polkadot/util/assert');
const isNumber = require('@polkadot/util/is/number');
const isUndefined = require('@polkadot/util/is/undefined');
import assert from '@polkadot/util/assert';
import isNumber from '@polkadot/util/is/number';
import isUndefined from '@polkadot/util/is/undefined';

function checkError (error?: JsonRpcResponseBase$Error) {
if (!error) {
Expand All @@ -20,7 +20,7 @@ function checkError (error?: JsonRpcResponseBase$Error) {
throw new Error(`[${code}]: ${message}`);
}

module.exports = function decodeResponse (self: RpcCoderState, response: JsonRpcResponse): mixed {
export default function decodeResponse (self: RpcCoderState, response: JsonRpcResponse): mixed {
assert(response, 'Empty response object received');
assert(response.jsonrpc === '2.0', 'Invalid jsonrpc field in decoded object');

Expand All @@ -39,4 +39,4 @@ module.exports = function decodeResponse (self: RpcCoderState, response: JsonRpc
}

return response.result;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const createCoder = require('./index');
import createCoder from './index';

describe('decodeResponse', () => {
let coder;
Expand Down
6 changes: 3 additions & 3 deletions packages/api-provider/src/coder/json/encodeJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import type { RpcCoderState } from './types';

const encodeObject = require('./encodeObject');
import encodeObject from './encodeObject';

module.exports = function encodeJson (self: RpcCoderState, method: string, params: Array<mixed>): string {
export default function encodeJson (self: RpcCoderState, method: string, params: Array<mixed>): string {
return JSON.stringify(
encodeObject(self, method, params)
);
};
}
2 changes: 1 addition & 1 deletion packages/api-provider/src/coder/json/encodeJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const createCoder = require('./index');
import createCoder from './index';

describe('encodeJson', () => {
let coder;
Expand Down
4 changes: 2 additions & 2 deletions packages/api-provider/src/coder/json/encodeObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import type { JsonRpcRequest } from '../../types';
import type { RpcCoderState } from './types';

module.exports = function encodeObject (self: RpcCoderState, method: string, params: Array<mixed>): JsonRpcRequest {
export default function encodeObject (self: RpcCoderState, method: string, params: Array<mixed>): JsonRpcRequest {
return {
id: ++self.id,
jsonrpc: '2.0',
method,
params
};
};
}
2 changes: 1 addition & 1 deletion packages/api-provider/src/coder/json/encodeObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const createCoder = require('./index');
import createCoder from './index';

describe('encodeObject', () => {
let coder;
Expand Down
10 changes: 5 additions & 5 deletions packages/api-provider/src/coder/json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import type { JsonRpcRequest, JsonRpcResponse } from '../../types';
import type { RpcCoder, RpcCoderState } from './types';

const decodeResponse = require('./decodeResponse');
const encodeJson = require('./encodeJson');
const encodeObject = require('./encodeObject');
import decodeResponse from './decodeResponse';
import encodeJson from './encodeJson';
import encodeObject from './encodeObject';

module.exports = function rpcCoder (): RpcCoder {
export default function rpcCoder (): RpcCoder {
const self: RpcCoderState = {
id: 0
};
Expand All @@ -25,4 +25,4 @@ module.exports = function rpcCoder (): RpcCoder {
getId: (): number =>
self.id
};
};
}
16 changes: 8 additions & 8 deletions packages/api-provider/src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import type { ProviderInterface, ProviderInterface$Callback, ProviderInterface$Emitted, ProviderInterface$EmitCb } from '../types';

require('./polyfill');
import './polyfill';

const on = require('./on');
const send = require('./send');
const subscribe = require('./subscribe');
const state = require('./state');
const unsubscribe = require('./unsubscribe');
import on from './on';
import send from './send';
import subscribe from './subscribe';
import state from './state';
import unsubscribe from './unsubscribe';

module.exports = function httpProvider (endpoint: string): ProviderInterface {
export default function httpProvider (endpoint: string): ProviderInterface {
const self = state(endpoint);

return {
Expand All @@ -28,4 +28,4 @@ module.exports = function httpProvider (endpoint: string): ProviderInterface {
unsubscribe: (method: string, id: number): Promise<boolean> =>
unsubscribe(self, method, id)
};
};
}
4 changes: 2 additions & 2 deletions packages/api-provider/src/http/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

const { TEST_HTTP_URL } = require('../../test/mockHttp');
import { TEST_HTTP_URL } from '../../test/mockHttp';

const createHttp = require('./index');
import createHttp from './index';

describe('Http', () => {
let http;
Expand Down
4 changes: 2 additions & 2 deletions packages/api-provider/src/http/on.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import type { ProviderInterface$Emitted, ProviderInterface$EmitCb } from '../types';
import type { HttpState } from './types';

module.exports = function on (self: HttpState, type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void {
export default function on (self: HttpState, type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void {
self.l.error(`Provider does not have 'on' emitters for type '${type}'`);
};
}
6 changes: 3 additions & 3 deletions packages/api-provider/src/http/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import type { HttpState } from './types';

const assert = require('@polkadot/util/assert');
import assert from '@polkadot/util/assert';

module.exports = async function send ({ coder, endpoint }: HttpState, method: string, params: Array<mixed>): Promise<mixed> {
export default async function send ({ coder, endpoint }: HttpState, method: string, params: Array<mixed>): Promise<mixed> {
const body = coder.encodeJson(method, params);
const response = await fetch(endpoint, {
body,
Expand All @@ -24,4 +24,4 @@ module.exports = async function send ({ coder, endpoint }: HttpState, method: st
const result = await response.json();

return coder.decodeResponse(result);
};
}
Loading