Api & RxApi now created via new (#153)
* Api & RxApi now created via new * Bump version
This commit is contained in:
@@ -25,11 +25,11 @@ npm install --save @polkadot/api
|
||||
Initialisation -
|
||||
|
||||
```js
|
||||
import createApi from '@polkadot/api';
|
||||
import Api from '@polkadot/api';
|
||||
import WsProvider from '@polkadot/api-provider/ws';
|
||||
|
||||
const provider = new WsProvider('http://127.0.0.1:9944');
|
||||
const api = createApi(provider);
|
||||
const api = new Api(provider);
|
||||
```
|
||||
|
||||
Making calls -
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "0.28.35",
|
||||
"version": "0.29.0",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -30,10 +30,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0",
|
||||
"@polkadot/api-format": "^0.28.35",
|
||||
"@polkadot/api-provider": "^0.28.35",
|
||||
"@polkadot/jsonrpc": "^0.28.35",
|
||||
"@polkadot/params": "^0.28.35",
|
||||
"@polkadot/api-format": "^0.29.0",
|
||||
"@polkadot/api-provider": "^0.29.0",
|
||||
"@polkadot/jsonrpc": "^0.29.0",
|
||||
"@polkadot/params": "^0.29.0",
|
||||
"@polkadot/util": "^0.30.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import storage from '@polkadot/storage';
|
||||
|
||||
import createApi from '../index';
|
||||
import Api from '../index';
|
||||
|
||||
const ADDR_ONE = '5EhmTa7fL6SdjgKXo9g6hetR6nHnRAmrtisoGFWEESjzECtY';
|
||||
const ADDR_TWO = '5FjbQAHSptRU4Q7Py6zDsRnE7UkpZikJVg5nm1tmu3WuZXKd';
|
||||
@@ -31,7 +31,7 @@ describe('formatResult', () => {
|
||||
})
|
||||
)
|
||||
};
|
||||
api = createApi(provider);
|
||||
api = new Api(provider);
|
||||
});
|
||||
|
||||
it('encodes key (with params), decoding response', () => {
|
||||
|
||||
@@ -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 createApi from './index';
|
||||
import Api from './index';
|
||||
|
||||
describe('Api', () => {
|
||||
let api;
|
||||
@@ -16,7 +16,7 @@ describe('Api', () => {
|
||||
}
|
||||
};
|
||||
sendSpy = jest.spyOn(provider, 'send');
|
||||
api = createApi(provider);
|
||||
api = new Api(provider);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -25,7 +25,7 @@ describe('Api', () => {
|
||||
|
||||
it('requires a provider with a send method', () => {
|
||||
expect(
|
||||
() => createApi({})
|
||||
() => new Api({})
|
||||
).toThrow(/Expected Provider/);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,22 +2,29 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interface$Sections } from '@polkadot/jsonrpc/types';
|
||||
import { ProviderInterface } from '@polkadot/api-provider/types';
|
||||
import { ApiInterface } from './types';
|
||||
import { ApiInterface, ApiInterface$Section } from './types';
|
||||
|
||||
import interfaces from '@polkadot/jsonrpc/index';
|
||||
import assert from '@polkadot/util/assert';
|
||||
import isFunction from '@polkadot/util/is/function';
|
||||
|
||||
import createInterface from './create/interface';
|
||||
|
||||
export default function api (provider: ProviderInterface): ApiInterface {
|
||||
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
|
||||
export default class Api implements ApiInterface {
|
||||
private _provider: ProviderInterface;
|
||||
readonly author: ApiInterface$Section;
|
||||
readonly chain: ApiInterface$Section;
|
||||
readonly state: ApiInterface$Section;
|
||||
readonly system: ApiInterface$Section;
|
||||
|
||||
return Object.keys(interfaces).reduce((exposed, type) => {
|
||||
exposed[type as Interface$Sections] = createInterface(provider, type as Interface$Sections);
|
||||
constructor (provider: ProviderInterface) {
|
||||
assert(provider && isFunction(provider.send), 'Expected Provider to API create');
|
||||
|
||||
return exposed;
|
||||
}, {} as ApiInterface);
|
||||
this._provider = provider;
|
||||
|
||||
this.author = createInterface(this._provider, 'author');
|
||||
this.chain = createInterface(this._provider, 'chain');
|
||||
this.state = createInterface(this._provider, 'state');
|
||||
this.system = createInterface(this._provider, 'system');
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -16,5 +16,5 @@ export type ApiInterface$Section = {
|
||||
};
|
||||
|
||||
export type ApiInterface = {
|
||||
[key in keyof Interfaces]: ApiInterface$Section
|
||||
readonly [key in keyof Interfaces]: ApiInterface$Section
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user