From 4497be6f19b9f9e2995d6b5684b91205e6c074fc Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 22 Nov 2018 14:44:11 +0100 Subject: [PATCH] Cleanup api-observable Vector FIXMEs (#410) * Cleanup api-observable Vector FIXMEs * Simplify rawStorage * Fix linting * Bump deps --- packages/api-observable/src/Base.ts | 14 ++++------- packages/api-observable/src/Queries.ts | 33 +++++--------------------- packages/rpc-core/package.json | 2 +- packages/rpc-provider/package.json | 6 ++--- packages/type-extrinsics/package.json | 2 +- packages/type-storage/package.json | 6 ++--- packages/types/package.json | 4 ++-- yarn.lock | 30 +++++++++++------------ 8 files changed, 35 insertions(+), 62 deletions(-) diff --git a/packages/api-observable/src/Base.ts b/packages/api-observable/src/Base.ts index 634d022a14..4cfd1f982f 100644 --- a/packages/api-observable/src/Base.ts +++ b/packages/api-observable/src/Base.ts @@ -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 = (combined: R) => T; @@ -115,9 +114,7 @@ export default class ApiBase { ) .pipe( map((result: Array): T | undefined => - result - ? result[0] - : undefined + result[0] ) ); } @@ -134,11 +131,8 @@ export default class ApiBase { return observable.pipe( defaultIfEmpty(), - map((result?: Vector): 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): T => + (result || []) as T ) ); } diff --git a/packages/api-observable/src/Queries.ts b/packages/api-observable/src/Queries.ts index 5b97b3fbf7..7dc3350839 100644 --- a/packages/api-observable/src/Queries.ts +++ b/packages/api-observable/src/Queries.ts @@ -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 => { @@ -52,10 +50,7 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((accounts: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (accounts || ([] as Array)).map((accountId) => - accountId - ) + accounts || ([] as Array) ) ); } @@ -83,7 +78,6 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((proposals: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) (proposals || ([] as Array)) .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 | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (voters || ([] as Array)).map((accountId) => - accountId - ) + voters || ([] as Array) ) ); } @@ -195,10 +186,7 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((validators: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (validators || ([] as Array)).map((authorityId) => - authorityId - ) + validators || ([] as Array) ) ); } @@ -209,10 +197,7 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((intentions: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (intentions || ([] as Array)).map((accountId) => - accountId - ) + intentions || ([] as Array) ) ); } @@ -223,10 +208,7 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((nominators: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (nominators || ([] as Array)).map((accountId) => - accountId - ) + nominators || ([] as Array) ) ); } @@ -241,10 +223,7 @@ export default class ApiQueries extends ApiBase { .pipe( // @ts-ignore After upgrade to 6.3.2 map((events: Array | null | undefined) => - // FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array) - (events || ([] as Array)).map((event) => - event - ) + events || ([] as Array) ) ); } diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 7a40b4cbf7..e704242814 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -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" } } diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 8023fc7e2b..4fe4879cc7 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -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", diff --git a/packages/type-extrinsics/package.json b/packages/type-extrinsics/package.json index 5ad438baa8..a419a67e94 100644 --- a/packages/type-extrinsics/package.json +++ b/packages/type-extrinsics/package.json @@ -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" } } diff --git a/packages/type-storage/package.json b/packages/type-storage/package.json index 5820c0f8a6..991f4b2e5a 100644 --- a/packages/type-storage/package.json +++ b/packages/type-storage/package.json @@ -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" } } diff --git a/packages/types/package.json b/packages/types/package.json index cdfc2f6a55..2dfa5af4d7 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -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" } } diff --git a/yarn.lock b/yarn.lock index 1637b182d1..43ac69da31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"