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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
![ISC](https://img.shields.io/badge/license-ISC-lightgrey.svg)
[![npm (scoped)](https://img.shields.io/npm/v/@polkadot/api.svg)](https://www.npmjs.com/package/@polkadot/api)
[![Build Status](https://travis-ci.org/polkadot-js/api.svg?branch=master)](https://travis-ci.org/polkadot-js/api)
[![Maintainability](https://api.codeclimate.com/v1/badges/bdc230778ec91a5167b8/maintainability)](https://codeclimate.com/github/polkadot-js/api/maintainability)
[![Coverage Status](https://coveralls.io/repos/github/polkadot-js/api/badge.svg?branch=master)](https://coveralls.io/github/polkadot-js/api?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/polkadot-js/api.svg)](https://greenkeeper.io/)

# @polkadot/client

This library provides a clean wrapper around all the methods exposed by a Polkadot network client.
This library provides a clean wrapper around all the methods exposed by a Polkadot network client. As part of the JsonRpc defintions, the [exposed methods are documented][packages/api-jsonrpc/docs/].

It is split up into a number of internal packages -
The API is split up into a number of internal packages -

- [@polkadot/api](packages/api/) The API library
- [@polkadot/api-format](packages/api-format/) Input and output formatters
Expand Down
21 changes: 2 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
{
"name": "@polkadot/api-wrapper",
"version": "0.5.5",
"description": "Non-published, see packages/",
"keywords": [],
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "ISC",
"private": true,
"engines": {
"node": ">=8.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/polkadot-js/api.git"
},
"bugs": {
"url": "https://github.com/polkadot-js/api/issues"
},
"homepage": "https://github.com/polkadot-js/api#readme",
"workspaces": [
"packages/*"
],
Expand All @@ -26,8 +10,7 @@
"test": "jest --coverage packages"
},
"devDependencies": {
"@polkadot/dev": "^0.9.9",
"@polkadot/dev": "^0.10.1",
"lerna": "^2.5.1"
},
"dependencies": {}
}
}
2 changes: 1 addition & 1 deletion packages/api-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@polkadot/api-jsonrpc": "^0.5.5"
},
"dependencies": {
"@polkadot/util": "^0.5.19",
"@polkadot/util": "^0.6.1",
"babel-runtime": "^6.26.0"
}
}
37 changes: 23 additions & 14 deletions packages/api-format/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,40 @@ const formatNoop = require('./noop');

const arrayTypeRegex = /\[\]$/;

function format (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
const isArrayType: boolean = arrayTypeRegex.test(type);
const formatter: FormatterFunction = isArrayType
? formatters[type.replace(arrayTypeRegex, '')]
: formatters[type];
function formatSingleType (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
const formatter: FormatterFunction = formatters[type];

if (isUndefined(formatter)) {
console.warn(`Unable to find default formatter for '${type}', falling back to noop`);

return formatNoop(value);
}

if (isArrayType && !Array.isArray(value)) {
try {
return formatter(value);
} catch (error) {
throw new Error(`Error formatting '${value}' as '${type}': ${error.message}`);
}
}

function formatArrayType (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
if (!Array.isArray(value)) {
throw new Error(`Unable to format non-array '${value}' as '${type}'`);
}

try {
if (isArrayType) {
return (value: Array<any>).map((value) => formatter(value));
} else {
return formatter(value);
}
} catch (error) {
throw new Error(`Error formatting '${value}' as '${type}'': ${error.message}`);
type = type.replace(arrayTypeRegex, '');

return (value: Array<any>).map((value) => {
return formatSingleType(formatters, type, value);
});
}

function format (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
if (arrayTypeRegex.test(type)) {
return formatArrayType(formatters, type, value);
}

return formatSingleType(formatters, type, value);
}

function formatArray (formatters: { [any]: FormatterFunction }, types: Array<string>, values: Array<any>): Array<any> {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/util": "^0.5.19",
"@polkadot/util": "^0.6.1",
"babel-runtime": "^6.26.0",
"isomorphic-fetch": "^2.2.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@polkadot/api-format": "^0.5.5",
"@polkadot/api-jsonrpc": "^0.5.5",
"@polkadot/api-provider": "^0.5.5",
"@polkadot/util": "^0.5.19",
"@polkadot/util": "^0.6.1",
"babel-runtime": "^6.26.0"
}
}
15 changes: 8 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@polkadot/dev@^0.9.9":
version "0.9.9"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.9.9.tgz#b302ba6728a5068c7bffe069fd64290c227d317c"
"@polkadot/dev@^0.10.1":
version "0.10.1"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.10.1.tgz#4c57180413320f0194c340177725f8b8c0ecbffa"
dependencies:
babel-cli "^6.26.0"
babel-core "^6.26.0"
Expand All @@ -73,6 +73,7 @@
eslint "^4.11.0"
eslint-config-semistandard "^11.0.0"
eslint-config-standard "^10.2.1"
eslint-config-standard-jsx "^4.0.2"
eslint-config-standard-react "^5.0.0"
eslint-plugin-flowtype "^2.39.1"
eslint-plugin-import "^2.8.0"
Expand All @@ -89,9 +90,9 @@
stylelint "^8.2.0"
stylelint-config-standard "^18.0.0"

"@polkadot/util@^0.5.19":
version "0.5.19"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.5.19.tgz#e34d917f3fd52b98c6a7633e534f26d182e7cb6f"
"@polkadot/util@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.1.tgz#d08fca12cbef5559f27bb0f51f72e71a3f11c824"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"
Expand Down Expand Up @@ -1882,7 +1883,7 @@ eslint-config-semistandard@^11.0.0:
version "11.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-semistandard/-/eslint-config-semistandard-11.0.0.tgz#44eef7cfdfd47219e3a7b81b91b540e880bb2615"

eslint-config-standard-jsx@^4.0.0:
eslint-config-standard-jsx@^4.0.0, eslint-config-standard-jsx@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-4.0.2.tgz#009e53c4ddb1e9ee70b4650ffe63a7f39f8836e1"

Expand Down