fix: Fixes #235 TypeDoc updates consistent with renaming (#236)

* fix: Remove docs/api since replaced with docs/rpc-core

* fix: Remove docs/api-provider since replaced with docs/rpc-provider

* fix: Remove docs/api-rx since replaced with docs/rpc-rx

* fix: Remove the guide file that serves no purpose

* fix: Change license from ui-observable to api-observable

* fix: Remove disused mockHttp and mockWs that are duplicates of those in rpc-provider

* fix: Clarifies difference between PropIndex and ProposalIndex from Issue #226

* fix: Update api-observable Readme to refer to rpc-core, previously called api

* misc: Update Readme of rpc-core. See commit message details.

* Update name to be @polkadot/rpc-core instead of @polkadot/api

* Use Yarn instead of NPM for instructions adding dependencies

* Refer to @polkadot/rpc-core as `Rpc`

* Highlight that given block header hash should be a 0x-prefixed hex string with length of 64 (not only length of 10 as shown in the example)

* Showcase more information that you can obtain from the header object (i.e. best block number, parentHash, stateRoot, extrinsicsRoot, and digest)

* Use `header.raw` instead of just `header` to access properties of the header object

* Update the example to console.log the subscription ID

* Add missing semicolon

* fix: Fix name in license header and rename Api to Rpc for rpc-core e2e tests

* fix: Update rpc-provider Readme to use Yarn instead of NPM install

* fix: Fix minor typo

* fix: Rename Api to Rpc for rpc-provider ws

* fix: Refer to rpc-core instead of api in the rpc-rx Readme

* fix: Update rpc-rx files to refer to it as RpcRx instead of RxApi or just Api

* fix: Refer to rpc-core as Rpc instead of Api

* fix: Update type-jsonrpc Readme. Fix typo. Use Yarn not NPM. Refer to TSLint not Flow

* refactor: Move non-type dependency import with non-type dependencies

* docs: Add link to parity-codec repo

* fix: Avoid use of .raw. Fix listen to blocks example

* fix: Add missing error to newHead in listen to blocks example
This commit is contained in:
Luke Schoen
2018-10-10 20:11:22 +02:00
committed by Jaco Greeff
parent 8e9243fdd6
commit 267411d778
83 changed files with 82 additions and 5934 deletions
+1 -1
View File
@@ -10,4 +10,4 @@
# @polkadot/api-observable
An RxJs wrapper around the [@polkadot/api](../api).
An RxJs wrapper around the [@polkadot/rpc-core](../rpc-core).
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2018 @polkadot/ui-observable authors & contributors
// Copyright 2017-2018 @polkadot/api-observable authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
+14 -9
View File
@@ -8,7 +8,7 @@
[![dependency](https://david-dm.org/polkadot-js/api.svg?style=flat-square&path=package/rpc-core)](https://david-dm.org/polkadot-js/api?path=package/rpc-core)
[![devDependency](https://david-dm.org/polkadot-js/api/dev-status.svg?style=flat-square&path=package/rpc-core)](https://david-dm.org/polkadot-js/api?path=package/rpc-core#info=devDependencies)
# @polkadot/api
# @polkadot/rpc-core
This library provides a clean wrapper around all the methods exposed by a Polkadot network client.
@@ -17,20 +17,20 @@ This library provides a clean wrapper around all the methods exposed by a Polkad
Installation -
```
npm install --save @polkadot/rpc-core
yarn add @polkadot/rpc-core
```
Initialisation -
```js
import Api from '@polkadot/rpc-core';
import Rpc from '@polkadot/rpc-core';
import WsProvider from '@polkadot/rpc-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const api = new Api(provider);
const api = new Rpc(provider);
```
Making calls -
Retrieving the block header object for a given block header hash (a 0x-prefixed hex string with length of 64) -
```js
api.chain
@@ -39,7 +39,7 @@ api.chain
.catch((error) => console.error(error));
```
Retrieving the best block (once-off) -
Retrieving the best block number, parent hash, state root hash, extrinsics root hash, and digest (once-off) -
```js
api.chain
@@ -48,7 +48,11 @@ api.chain
return api.chain.getHeader(headerHash);
})
.then((header) => {
console.log(`best #${header.number.toString()}`);
console.log(`best #${header.blockNumber.toString()}`);
console.log(`parentHash: ${header.parentHash.toString()}`);
console.log(`stateRoot: ${header.stateRoot.toString()}`);
console.log(`extrinsicsRoot: ${header.extrinsicsRoot.toString()}`);
console.log(`digest: ${header.digest.toString()}`);
})
.catch((error) => {
console.error('error:', error);
@@ -64,11 +68,12 @@ api.chain
console.error('error:', error);
}
console.log(`best #${header.number.toString()}`);
console.log(`best #${header.blockNumber.toString()}`);
})
.then((subscriptionId) => {
console.log(`subscriptionId: ${subscriptionId}`);
// id for the subscription, can unsubscribe via
// api.chain.newHead.unsubscribe(subscriptionId)
// api.chain.newHead.unsubscribe(subscriptionId);
})
.catch((error) => {
console.error('error subscribing:', error);
+3 -3
View File
@@ -1,17 +1,17 @@
// Copyright 2017-2018 @polkadot/api authors & contributors
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Ws from '@polkadot/rpc-provider/ws';
import Api from '../../src';
import Rpc from '../../src';
describe.skip('e2e basics', () => {
let api;
beforeEach(() => {
jest.setTimeout(30000);
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
it('retrieves the pending extrinsics', () => {
+5 -5
View File
@@ -1,17 +1,17 @@
// Copyright 2017-2018 @polkadot/api authors & contributors
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Ws from '@polkadot/rpc-provider/ws';
import Api from '../../src';
import Rpc from '../../src';
describe.skip('e2e chain', () => {
let api;
beforeEach(() => {
jest.setTimeout(30000);
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
it('subscribes to chain_newHead', (done) => {
@@ -19,12 +19,12 @@ describe.skip('e2e chain', () => {
// tslint:disable-next-line
api.chain
.newHead((error, data) => {
.newHead((error, header) => {
if (error) {
return done(error);
}
expect(data).toBeDefined();
expect(header).toBeDefined();
if (++count === 3) {
done();
@@ -1,18 +1,18 @@
// Copyright 2017-2018 @polkadot/api authors & contributors
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import storage from '@polkadot/storage';
import Ws from '@polkadot/rpc-provider/ws';
import Api from '../../src';
import Rpc from '../../src';
describe.skip('e2e krumme lanke', () => {
let api;
beforeEach(() => {
jest.setTimeout(30000);
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
it('subscribes to storage', (done) => {
+3 -3
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2018 @polkadot/api authors & contributors
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Ws from '@polkadot/rpc-provider/ws';
import storage from '@polkadot/storage/static';
import Api from '../../src';
import Rpc from '../../src';
const ALICE = '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ';
@@ -14,7 +14,7 @@ describe.skip('e2e state', () => {
beforeEach(() => {
jest.setTimeout(30000);
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
it('retrieves code', () => {
+3 -3
View File
@@ -1,18 +1,18 @@
// Copyright 2017-2018 @polkadot/api authors & contributors
// Copyright 2017-2018 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Ws from '@polkadot/rpc-provider/ws';
import storage from '@polkadot/storage/static';
import Api from '../../src';
import Rpc from '../../src';
describe.skip('e2e subscriptions', () => {
let api;
beforeEach(() => {
jest.setTimeout(30000);
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
it('retrieves current timestamp', (done) => {
-27
View File
@@ -1,27 +0,0 @@
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import nock from 'nock';
const TEST_HTTP_URL = 'http://localhost:9944';
function mockHttp (requests: any[]) {
nock.cleanAll();
return requests.reduce((scope, request: any, index: number) => {
return scope
.post('/')
.reply(request.code || 200, (uri: string, body: { id: string }) => {
scope.body = scope.body || {};
scope.body[request.method] = body;
return Object.assign({ id: body.id, jsonrpc: '2.0' }, request.reply || {});
});
}, nock(TEST_HTTP_URL));
}
export {
TEST_HTTP_URL,
mockHttp
};
-83
View File
@@ -1,83 +0,0 @@
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { Server } from 'mock-socket';
const TEST_WS_URL = 'ws://localhost:9955';
let server: Server;
type ErrorDef = {
id: number,
error: {
code: number,
message: string
}
};
type ReplyDef = {
id: number,
reply: {
result: any
}
};
function createError ({ id, error: { code, message } }: ErrorDef) {
return {
id,
jsonrpc: '2.0',
error: {
code,
message
}
};
}
function createReply ({ id, reply: { result } }: ReplyDef) {
return {
id,
jsonrpc: '2.0',
result
};
}
function mockWs (requests: Array<{ method: string }>) {
server = new Server(TEST_WS_URL);
let requestCount = 0;
const scope: { body: { [index: string]: {} }, requests: number, server: Server, done: any } = {
body: {},
requests: 0,
server,
done: () =>
server.stop(() => {
// ignore
})
};
server.on('connection', (socket) => {
// @ts-ignore definitions are wrong, this is 'on', not 'onmessage'
socket.on('message', (body: {}) => {
const request = requests[requestCount];
// @ts-ignore Yes, SHOULD be fixed, this is a mess
const response = request.error
// @ts-ignore Yes, SHOULD be fixed, this is a mess
? createError(request)
// @ts-ignore Yes, SHOULD be fixed, this is a mess
: createReply(request);
scope.body[request.method] = body;
requestCount++;
socket.send(JSON.stringify(response));
});
});
return scope;
}
export {
TEST_WS_URL,
mockWs
};
+1 -1
View File
@@ -17,7 +17,7 @@ Generic transport providers to handle the transport of method calls to and from
Installation -
```
npm install --save @polkadot/rpc-provider
yarn add @polkadot/rpc-provider
```
Initialisation -
+2 -2
View File
@@ -25,11 +25,11 @@ const ERROR_SUBSCRIBE = 'HTTP Provider does not have subscriptions, use WebSocke
* <BR>
*
* ```javascript
* import Api from '@polkadot/rpc-core';
* import Rpc from '@polkadot/rpc-core';
* import HttpProvider from '@polkadot/rpc-provider/http';
*
* const provider = new HttpProvider('http://127.0.0.1:9933');
* const api = new Api(provider);
* const api = new Rpc(provider);
* ```
*
* @see [[WsProvider]]
+1 -1
View File
@@ -12,7 +12,7 @@ import subscribe from './subscribe';
import unsubscribe from './unsubscribe';
/**
* A moock provider mainly used for testing.
* A mock provider mainly used for testing.
* @return {ProviderInterface} The mock provider
*/
export default function mockProvider (): ProviderInterface {
+3 -3
View File
@@ -46,11 +46,11 @@ interface WSProviderInterface extends ProviderInterface {
* <BR>
*
* ```javascript
* import Api from '@polkadot/rpc-core';
* import Rpc from '@polkadot/rpc-core';
* import WsProvider from '@polkadot/rpc-provider/ws';
*
* const provider = new WsProvider('ws://127.0.0.1:9944');
* const api = new Api(provider);
* const api = new Rpc(provider);
* ```
*
* @see [[HttpProvider]]
@@ -182,7 +182,7 @@ export default class WsProvider extends E3.EventEmitter implements WSProviderInt
*
* ```javascript
* const provider = new WsProvider('ws://127.0.0.1:9944');
* const api = new Api(provider);
* const api = new Rpc(provider);
*
* api.state.storage([[storage.balances.freeBalance, <Address>]], (_, values) => {
* console.log(values)
+1 -1
View File
@@ -10,4 +10,4 @@
# @polkadot/rpc-rx
An RxJs wrapper around the [@polkadot/api](../api).
An RxJs wrapper around the [@polkadot/rpc-core](../rpc-core).
+2 -2
View File
@@ -8,7 +8,7 @@ jest.mock('@polkadot/rpc-provider/ws', () => class {
send = () => true;
});
const Api = require('./index').default;
const RpcRx = require('./index').default;
describe('createCachedObservable', () => {
let api;
@@ -16,7 +16,7 @@ describe('createCachedObservable', () => {
let section;
beforeEach(() => {
api = new Api();
api = new RpcRx();
});
beforeEach(() => {
+3 -3
View File
@@ -10,13 +10,13 @@ jest.mock('@polkadot/rpc-provider/ws', () => class {
send = () => true;
});
const Api = require('./index').default;
const RpcRx = require('./index').default;
describe('Api', () => {
describe('RpcRx', () => {
let api;
beforeEach(() => {
api = new Api();
api = new RpcRx();
});
it('creates an instance with all sections', () => {
+2 -2
View File
@@ -29,11 +29,11 @@ type CachedMap = {
* <BR>
*
* ```javascript
* import Rpc from '@polkadot/rpc-rx';
* import RpcRx from '@polkadot/rpc-rx';
* import WsProvider from '@polkadot/rpc-provider/ws';
*
* const provider = new WsProvider('http://127.0.0.1:9944');
* const api = new Rpc(provider);
* const api = new RpcRx(provider);
* ```
*/
export default class RpcRx implements RxRpcInterface {
+2 -2
View File
@@ -8,7 +8,7 @@ jest.mock('@polkadot/rpc-provider/ws', () => class {
send = () => true;
});
const Api = require('./index').default;
const RpcRx = require('./index').default;
describe('subject', () => {
const params = [123, false];
@@ -19,7 +19,7 @@ describe('subject', () => {
let observable;
beforeEach(() => {
api = new Api();
api = new RpcRx();
});
beforeEach(() => {
+2 -2
View File
@@ -5,7 +5,7 @@
import Ws from '@polkadot/rpc-provider/ws';
import storage from '@polkadot/storage/static';
import RxApi from '../../src';
import RpcRx from '../../src';
describe.skip('e2e subscriptions', () => {
let api;
@@ -13,7 +13,7 @@ describe.skip('e2e subscriptions', () => {
beforeEach(() => {
jest.setTimeout(30000);
api = new RxApi(new Ws('ws://127.0.0.1:9944'));
api = new RpcRx(new Ws('ws://127.0.0.1:9944'));
});
it('retrieves current timestamp', (done) => {
+1 -1
View File
@@ -4,9 +4,9 @@
import camelCase from '@polkadot/util/string/camelCase';
import Metadata, { RuntimeModuleMetadata } from '@polkadot/types/Metadata';
import { Extrinsics, ModuleExtrinsics } from './types';
import createUnchecked from './utils/createUnchecked';
import { Extrinsics, ModuleExtrinsics } from './types';
import extrinsics from './index';
/**
@@ -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 Api from '@polkadot/rpc-core';
import Rpc from '@polkadot/rpc-core';
import Ws from '@polkadot/rpc-provider/ws';
import testingPairs from '@polkadot/util-keyring/testingPairs';
@@ -15,7 +15,7 @@ describe.skip('e2e transfer', () => {
beforeAll(() => {
// check other e2e tests here...
api = new Api(new Ws('ws://127.0.0.1:9944'));
api = new Rpc(new Ws('ws://127.0.0.1:9944'));
});
// Error: [1002]: Inherent transactions cannot be queued.
+3 -3
View File
@@ -10,7 +10,7 @@
# @polkadot/jsonrpc
A defintion of all the methods exposed in a general Polkadot client application. These are used not only to provide a comprehensive code-generated document of the available methods, but are also used in the API to auto-generate endpoints with the required type-checking.
A definition of all the methods exposed in a general Polkadot client application. These are used not only to provide a comprehensive code-generated document of the available methods, but are also used in the API to auto-generate endpoints with the required type-checking.
For a list of currently exposed methods, see the [method documentation](docs/README.md).
@@ -19,7 +19,7 @@ For a list of currently exposed methods, see the [method documentation](docs/REA
Installation -
```
npm install --save @polkadot/jsonrpc
yarn add @polkadot/jsonrpc
```
## Adding methods
@@ -27,4 +27,4 @@ npm install --save @polkadot/jsonrpc
As methods are added, simply adding the name, inputs & output will prepare it for use.
- Add the method to the correct file in [src/rpc/](src/rpc/) (Input/Output types as cross-referenced from the canonical implementation and match one-to-one)
- Should a new type be required, add it to the type list, [src/types.js](src/types.js) (Required for flow type checking)
- Should a new type be required, add it to the type list, [src/types.js](src/types.js) (Required for TSLint type checking)
+1 -1
View File
@@ -3,8 +3,8 @@
// of the ISC license. See the LICENSE file for details.
import { StorageFunction } from '@polkadot/types/StorageKey';
import BN from 'bn.js';
import BN from 'bn.js';
import * as substrate from './substrate';
type Substrate = keyof typeof substrate;
+1 -1
View File
@@ -1,3 +1,3 @@
# @polkadot/types
Implementation of the types and their (de-)serialisation via parity-codec.
Implementation of the types and their (de-)serialisation via [parity-codec](https://github.com/paritytech/parity-codec).
+1 -1
View File
@@ -4,6 +4,6 @@
import U32 from './U32';
// An increasing number that represents a specific proposal in the system
// An increasing number that represents a specific public proposal index in the system
export default class PropIndex extends U32 {
}
+1 -1
View File
@@ -4,6 +4,6 @@
import U32 from './U32';
// An increasing number that represents a specific proposal in the system
// An increasing number that represents a specific council proposal index in the system
export default class ProposalIndex extends U32 {
}