Skip to content
Merged
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
1 change: 1 addition & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./babel.config.js');
16 changes: 0 additions & 16 deletions .flowconfig

This file was deleted.

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"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"packages/*"
],
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "eslint packages && flow check",
"build": "polkadot-dev-build-ts",
"check": "tsc --noEmit",
"clean": "polkadot-dev-clean-build",
"postinstall": "polkadot-dev-yarn-only",
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.19.25"
"@polkadot/dev": "^0.20.2",
"@polkadot/ts": "^0.0.18"
}
}
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.19.1",
"@polkadot/primitives-json": "^0.19.1",
"@polkadot/util": "^0.24.1",
"@polkadot/util-keyring": "^0.24.1"
}
}
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

module.exports = function echo (value: mixed): mixed {
export default function echo (value: any): any {
return value;
};
}
14 changes: 7 additions & 7 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 All @@ -14,12 +14,12 @@ describe('format', () => {
echoSpy = jest.fn(echo);
warnSpy = jest.spyOn(console, 'warn');

formatters = {
'Address': echoSpy,
'Exception': () => {
formatters = new Map([
['Address', echoSpy],
['Exception', () => {
throw new Error('something went wrong');
}
};
}]
]);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

import type { Param$Types, Param$Type$Array } from '@polkadot/params/types';
import type { FormatterFunction } from './types';
import { Param$Types, Param$Type$Array } from '@polkadot/params/types';
import { FormattersFunctionMap } from './types';

type FormattersFunctionMap = $Shape<{
[Param$Types]: FormatterFunction
}>;
import typeToString from '@polkadot/params/typeToString';
import isUndefined from '@polkadot/util/is/undefined';
import logger from '@polkadot/util/logger';

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

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 {
const formatter: FormatterFunction = formatters[type];
const formatter = formatters.get(type);

if (isUndefined(formatter)) {
l.warn(`Unable to find default formatter for '${typeToString(type)}', falling back to echo`);
Expand All @@ -33,16 +29,14 @@ function formatSingleType (formatters: FormattersFunctionMap, type: Param$Types,
}
}

// flowlint-next-line unclear-type:off
function formatArrayType (formatters: FormattersFunctionMap, [ type ]: Param$Type$Array, value: Array<any>): any {
return value.map((value) => {
return formatSingleType(formatters, type, value);
});
}

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

if (Array.isArray(type)) {
Expand All @@ -52,4 +46,4 @@ module.exports = function format (formatters: FormattersFunctionMap, types: Arra

return formatSingleType(formatters, type, value);
});
};
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// 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
};
26 changes: 0 additions & 26 deletions packages/api-format/src/input.js

This file was deleted.

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
25 changes: 25 additions & 0 deletions packages/api-format/src/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import { Params, Param$Types } from '@polkadot/params/types';
import { FormatterFunction } from './types';

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

import format from './format';

const formatters = new Map<Param$Types, FormatterFunction>([
// funnily named, goes from address -> u8a
['AccountId', addressDecode],
['Bytes', bytesEncode],
['Hash', hashEncode]
]);

export default function formatInputs (params: Params, values: Array<any>): Array<any> {
const types = params.map(({ type }) => type);

return format(formatters, types, values);
}
32 changes: 0 additions & 32 deletions packages/api-format/src/output.js

This file was deleted.

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
32 changes: 32 additions & 0 deletions packages/api-format/src/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

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

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';

import format from './format';

const formatters = new Map<Param$Types, FormatterFunction>([
// publicKey -> address
['AccountId', addressEncode],
['BlockNumber', bnDecode],
['Bytes', bytesDecode],
['Header', headerDecode],
['u64', bnDecode]
]);

export default function formatOutput (type: Param$Types, value?: any): any | null {
if (isUndefined(value) || isNull(value)) {
return value;
}

return format(formatters, [type], [value])[0];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2017-2018 @polkadot/api-format authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow

// flowlint-next-line unclear-type:off
export type FormatterFunction = (value: any) => mixed;
import { Param$Types } from '@polkadot/params/types';

export type FormatterFunction = (value: any) => any;

type FormattersFunctionMap = Map<Param$Types, FormatterFunction>;
11 changes: 6 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,11 @@
},
"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.19.1",
"@polkadot/util": "^0.24.1",
"@polkadot/util-crypto": "^0.24.1",
"@polkadot/util-keyring": "^0.24.1",
"@types/nock": "^9.1.3",
"eventemitter3": "^2.0.3",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
Expand Down
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
Loading