Cleanup api-observable Vector FIXMEs (#410)

* Cleanup api-observable Vector FIXMEs

* Simplify rawStorage

* Fix linting

* Bump deps
This commit is contained in:
Jaco Greeff
2018-11-22 14:44:11 +01:00
committed by GitHub
parent 8c5cff55e1
commit 4497be6f19
8 changed files with 35 additions and 62 deletions
+4 -10
View File
@@ -13,11 +13,10 @@ import extrinsicsFromMeta from '@polkadot/extrinsics/fromMetadata';
import extrinsicsStatic from '@polkadot/extrinsics/static';
import storageFromMeta from '@polkadot/storage/fromMetadata';
import storageStatic from '@polkadot/storage/static';
import { Vector } from '@polkadot/types/codec';
import { Hash, Method } from '@polkadot/types/index';
import Event from '@polkadot/types/Event';
import { StorageFunction } from '@polkadot/types/StorageKey';
import { assert, isUndefined, isU8a } from '@polkadot/util';
import { assert, isU8a } from '@polkadot/util';
type MapFn<R, T> = (combined: R) => T;
@@ -115,9 +114,7 @@ export default class ApiBase {
)
.pipe(
map((result: Array<T>): T | undefined =>
result
? result[0]
: undefined
result[0]
)
);
}
@@ -134,11 +131,8 @@ export default class ApiBase {
return observable.pipe(
defaultIfEmpty(),
map((result?: Vector<any>): T =>
isUndefined(result)
? [] as T
// FIXME When Vector extends Array, this mapping can be removed
: result.map((item: any) => item) as T
map((result?: Array<any>): T =>
(result || []) as T
)
);
}
+6 -27
View File
@@ -14,8 +14,6 @@ import { Tuple } from '@polkadot/types/codec';
import ApiBase from './Base';
import { RxProposal, RxProposalDeposits, RxReferendum } from './classes';
// FIXME Revert Vector -> Array mappings in here once https://github.com/polkadot-js/api/pull/172 is in
// Perform storage queries to the API endpoints.
export default class ApiQueries extends ApiBase {
accountNonce = (address: AccountId | string): Observable<Index | undefined> => {
@@ -52,10 +50,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((accounts: Array<AccountId> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(accounts || ([] as Array<AccountId>)).map((accountId) =>
accountId
)
accounts || ([] as Array<AccountId>)
)
);
}
@@ -83,7 +78,6 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((proposals: Array<Tuple> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(proposals || ([] as Array<Tuple>))
.map((result: Tuple): RxProposal | undefined =>
result
@@ -124,10 +118,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((voters: Array<AccountId> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(voters || ([] as Array<AccountId>)).map((accountId) =>
accountId
)
voters || ([] as Array<AccountId>)
)
);
}
@@ -195,10 +186,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((validators: Array<AccountId> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(validators || ([] as Array<AccountId>)).map((authorityId) =>
authorityId
)
validators || ([] as Array<AccountId>)
)
);
}
@@ -209,10 +197,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((intentions: Array<AccountId> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(intentions || ([] as Array<AccountId>)).map((accountId) =>
accountId
)
intentions || ([] as Array<AccountId>)
)
);
}
@@ -223,10 +208,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((nominators: Array<AccountId> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(nominators || ([] as Array<AccountId>)).map((accountId) =>
accountId
)
nominators || ([] as Array<AccountId>)
)
);
}
@@ -241,10 +223,7 @@ export default class ApiQueries extends ApiBase {
.pipe(
// @ts-ignore After upgrade to 6.3.2
map((events: Array<EventRecord> | null | undefined) =>
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
(events || ([] as Array<EventRecord>)).map((event) =>
event
)
events || ([] as Array<EventRecord>)
)
);
}
+1 -1
View File
@@ -33,6 +33,6 @@
"@polkadot/jsonrpc": "^0.32.2",
"@polkadot/rpc-provider": "^0.32.2",
"@polkadot/types": "^0.32.2",
"@polkadot/util": "^0.32.23"
"@polkadot/util": "^0.33.1"
}
}
+3 -3
View File
@@ -30,10 +30,10 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.1.5",
"@polkadot/keyring": "^0.32.23",
"@polkadot/keyring": "^0.33.1",
"@polkadot/storage": "^0.32.2",
"@polkadot/util": "^0.32.23",
"@polkadot/util-crypto": "^0.32.23",
"@polkadot/util": "^0.33.1",
"@polkadot/util-crypto": "^0.33.1",
"@types/nock": "^9.3.0",
"eventemitter3": "^3.1.0",
"isomorphic-fetch": "^2.2.1",
+1 -1
View File
@@ -12,6 +12,6 @@
"dependencies": {
"@babel/runtime": "^7.1.5",
"@polkadot/types": "^0.32.2",
"@polkadot/util": "^0.32.23"
"@polkadot/util": "^0.33.1"
}
}
+3 -3
View File
@@ -30,9 +30,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
"dependencies": {
"@babel/runtime": "^7.1.5",
"@polkadot/keyring": "^0.32.23",
"@polkadot/keyring": "^0.33.1",
"@polkadot/types": "^0.32.2",
"@polkadot/util": "^0.32.23",
"@polkadot/util-crypto": "^0.32.23"
"@polkadot/util": "^0.33.1",
"@polkadot/util-crypto": "^0.33.1"
}
}
+2 -2
View File
@@ -30,7 +30,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.1.5",
"@polkadot/keyring": "^0.32.23",
"@polkadot/util": "^0.32.23"
"@polkadot/keyring": "^0.33.1",
"@polkadot/util": "^0.33.1"
}
}
+15 -15
View File
@@ -1352,14 +1352,14 @@
typedoc-plugin-markdown "^1.1.19"
typescript "^3.1.6"
"@polkadot/keyring@^0.32.23":
version "0.32.23"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.32.23.tgz#6a4ca96638b6824f30dd7ed81e864652262ffb04"
integrity sha512-sTdfIp5J955X8g1MGMgxrffTinqhaaA5pu6teDdeOvYMSfaJfg20uN3CxKz4wa6cU4f+Tav1zGLyWLYYVvxFdw==
"@polkadot/keyring@^0.33.1":
version "0.33.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.1.tgz#e7c363e3d04e4bb2cbc98246565a7b42f67d1262"
integrity sha512-j0YtSw4WscLKhaaBxnR4qjKiI/hgKQR8WdIR3clS1XnIx+CEqNxv/65E7jLPxNzCKXVn0bWrm87j1eJ9PL3EWQ==
dependencies:
"@babel/runtime" "^7.1.5"
"@polkadot/util" "^0.32.23"
"@polkadot/util-crypto" "^0.32.23"
"@polkadot/util" "^0.33.1"
"@polkadot/util-crypto" "^0.33.1"
"@types/bs58" "^3.0.30"
bs58 "^4.0.1"
@@ -1368,13 +1368,13 @@
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.39.tgz#39d3578eaafd96cbc0270b1479fabab7e16e5723"
integrity sha512-NQM1uT+qi8onV0jtGjH7QmJvDTNFNYTEzjaoVZN2tDHi1/tVu1CP66qZGSGsS19JZJSK3ERSFb0vP8CkE7EUuA==
"@polkadot/util-crypto@^0.32.23":
version "0.32.23"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.32.23.tgz#4def26ba6945d4a0c4abfefeca9a506450e738ac"
integrity sha512-h7GOWWw3AQkc9SwOoN6V7X/IgopVwBQLLsXROPnzSpXTt6LluRSAXdzk/62f5KTVz5KJE/cj4EORd4oLfNgMaA==
"@polkadot/util-crypto@^0.33.1":
version "0.33.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.1.tgz#05307e5fb635543b07d47cf5f2eaee83434d5d03"
integrity sha512-GPMJBrm9PGgBlw2PHjtsAjDx4aaV1Zx1JFVuPKD1+tpE9eUnWStPIJJnzowSMiGwOUNtrmx55eTZbBtTSkrMZw==
dependencies:
"@babel/runtime" "^7.1.5"
"@polkadot/util" "^0.32.23"
"@polkadot/util" "^0.33.1"
"@types/bip39" "^2.4.0"
bip39 "^2.5.0"
blakejs "^1.1.0"
@@ -1382,10 +1382,10 @@
tweetnacl "^1.0.0"
xxhashjs "^0.2.2"
"@polkadot/util@^0.32.23":
version "0.32.23"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.32.23.tgz#b49386e3350f8656111832237fb65960f049e862"
integrity sha512-hp33s1wWN/pXeX5irdn2eOPcZIfr28XCZY80oFQFOmFA8U8CWzLgdE31s8Aa8XEtvGX4P7D40VEwk1oKKKiBHg==
"@polkadot/util@^0.33.1":
version "0.33.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.1.tgz#51df8d60ce8ba3934ac464f99e38a8cd13549f2b"
integrity sha512-a0pT7J+bpyMd1MqJojgSbD10/leRpe03MaQXeirI5OxpheMUK+HBE3HWqrYQBzH7dORpncWRzHxpf0VY61AG+g==
dependencies:
"@babel/runtime" "^7.1.5"
"@types/bn.js" "^4.11.3"