From 9c50e81ab9910238110171634a5f06590ae6e305 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 4 Feb 2020 12:16:18 +0100 Subject: [PATCH] Cleanup sanitize boxes (#1805) * Cleanup sanitize boxes * yarn.lock * Add space before box as allowed --- packages/api-derive/package.json | 2 +- packages/api/package.json | 6 ++--- packages/api/src/index.ts | 4 +-- packages/metadata/package.json | 6 ++--- packages/rpc-core/package.json | 2 +- packages/rpc-provider/package.json | 6 ++--- packages/types/package.json | 6 ++--- packages/types/src/codec/create/sanitize.ts | 6 ++++- packages/types/src/index.ts | 4 +-- yarn.lock | 30 ++++++++++----------- 10 files changed, 38 insertions(+), 34 deletions(-) diff --git a/packages/api-derive/package.json b/packages/api-derive/package.json index b6a844ddd3..ddb28d1c54 100644 --- a/packages/api-derive/package.json +++ b/packages/api-derive/package.json @@ -32,6 +32,6 @@ "@polkadot/types": "^1.1.0-beta.15" }, "devDependencies": { - "@polkadot/keyring": "^2.1.0-beta.0" + "@polkadot/keyring": "^2.1.0-beta.1" } } diff --git a/packages/api/package.json b/packages/api/package.json index 132a81d754..9b57d9bd4d 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -31,14 +31,14 @@ "dependencies": { "@babel/runtime": "^7.8.3", "@polkadot/api-derive": "^1.1.0-beta.15", - "@polkadot/keyring": "^2.1.0-beta.0", + "@polkadot/keyring": "^2.1.0-beta.1", "@polkadot/metadata": "^1.1.0-beta.15", "@polkadot/rpc-core": "^1.1.0-beta.15", "@polkadot/rpc-provider": "^1.1.0-beta.15", "@polkadot/types": "^1.1.0-beta.15", - "@polkadot/util-crypto": "^2.1.0-beta.0" + "@polkadot/util-crypto": "^2.1.0-beta.1" }, "devDependencies": { - "@polkadot/keyring": "^2.1.0-beta.0" + "@polkadot/keyring": "^2.1.0-beta.1" } } diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index bf078bcfd9..816fb7a808 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -4,7 +4,7 @@ import { detectPackage } from '@polkadot/util'; -let dirname = 'node_modules'; +let dirname; let pkgJson; try { @@ -19,7 +19,7 @@ try { pkgJson = require('../package.json'); } -detectPackage(dirname, pkgJson); +detectPackage(pkgJson, dirname); export { Keyring } from '@polkadot/keyring'; export { WsProvider } from '@polkadot/rpc-provider'; diff --git a/packages/metadata/package.json b/packages/metadata/package.json index 59acb45565..a3c16e17a9 100644 --- a/packages/metadata/package.json +++ b/packages/metadata/package.json @@ -28,10 +28,10 @@ "dependencies": { "@babel/runtime": "^7.8.3", "@polkadot/types": "^1.1.0-beta.15", - "@polkadot/util": "^2.1.0-beta.0", - "@polkadot/util-crypto": "^2.1.0-beta.0" + "@polkadot/util": "^2.1.0-beta.1", + "@polkadot/util-crypto": "^2.1.0-beta.1" }, "devDependencies": { - "@polkadot/keyring": "^2.1.0-beta.0" + "@polkadot/keyring": "^2.1.0-beta.1" } } diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index a44d67a946..0b317eb399 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -30,7 +30,7 @@ "@polkadot/jsonrpc": "^1.1.0-beta.15", "@polkadot/rpc-provider": "^1.1.0-beta.15", "@polkadot/types": "^1.1.0-beta.15", - "@polkadot/util": "^2.1.0-beta.0", + "@polkadot/util": "^2.1.0-beta.1", "rxjs": "^6.5.4" } } diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index bede814300..97c015c0d4 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -28,14 +28,14 @@ "dependencies": { "@babel/runtime": "^7.8.3", "@polkadot/metadata": "^1.1.0-beta.15", - "@polkadot/util": "^2.1.0-beta.0", - "@polkadot/util-crypto": "^2.1.0-beta.0", + "@polkadot/util": "^2.1.0-beta.1", + "@polkadot/util-crypto": "^2.1.0-beta.1", "eventemitter3": "^4.0.0", "isomorphic-fetch": "^2.2.1", "websocket": "^1.0.31" }, "devDependencies": { - "@polkadot/keyring": "^2.1.0-beta.0", + "@polkadot/keyring": "^2.1.0-beta.1", "mock-socket": "^9.0.3", "nock": "^11.7.2" } diff --git a/packages/types/package.json b/packages/types/package.json index bdb7eba70e..0982983b20 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -35,13 +35,13 @@ "dependencies": { "@babel/runtime": "^7.8.3", "@polkadot/metadata": "^1.1.0-beta.15", - "@polkadot/util": "^2.1.0-beta.0", - "@polkadot/util-crypto": "^2.1.0-beta.0", + "@polkadot/util": "^2.1.0-beta.1", + "@polkadot/util-crypto": "^2.1.0-beta.1", "memoizee": "^0.4.14", "yargs": "^15.1.0" }, "devDependencies": { - "@polkadot/keyring": "^2.1.0-beta.0", + "@polkadot/keyring": "^2.1.0-beta.1", "@types/memoizee": "^0.4.3", "@types/yargs": "^15.0.2" } diff --git a/packages/types/src/codec/create/sanitize.ts b/packages/types/src/codec/create/sanitize.ts index da3478afad..6bb50fb633 100644 --- a/packages/types/src/codec/create/sanitize.ts +++ b/packages/types/src/codec/create/sanitize.ts @@ -6,6 +6,7 @@ type Mapper = (value: string) => string; const ALLOWED_BOXES = ['BTreeMap', 'BTreeSet', 'Compact', 'Linkage', 'Result', 'Option', 'Vec']; +const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple const mappings: Mapper[] = [ // alias ::Inherent -> InherentOfflineReport @@ -114,7 +115,10 @@ function _removeGenerics (): Mapper { const box = ALLOWED_BOXES.find((box): boolean => { const start = index - box.length; - return start >= 0 && value.substr(start, box.length) === box; + return (start >= 0 && value.substr(start, box.length) === box) && ( + // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...> + start === 0 || BOX_PRECEDING.includes(value[start - 1]) + ); }); // we have not found anything, unwrap generic innards diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 4600161550..de7e70805e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -7,7 +7,7 @@ import { detectPackage } from '@polkadot/util'; -let dirname = 'node_modules'; +let dirname; let pkgJson; try { @@ -22,7 +22,7 @@ try { pkgJson = require('../package.json'); } -detectPackage(dirname, pkgJson); +detectPackage(pkgJson, dirname); export * from './codec'; export * from './index.types'; diff --git a/yarn.lock b/yarn.lock index cafeeff6bd..5163ddad2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2015,14 +2015,14 @@ typescript "^3.7.5" vuepress "^1.2.0" -"@polkadot/keyring@^2.1.0-beta.0": - version "2.1.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.1.0-beta.0.tgz#5fe05f715794e84eccb1f1efa2f01f92dd325e98" - integrity sha512-Qm9CXzKbb7WfkpaDS35ZaxZQWcwGCKJiCS8ymUnOQhCmd/7nQRu+ueIZpUfyxw5XEDeSA3fOhNmEi7oDxp8EAg== +"@polkadot/keyring@^2.1.0-beta.1": + version "2.1.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.1.0-beta.1.tgz#24e20596306ba1b82f3f358f4cba44f264c7b6b4" + integrity sha512-017xaPtacX5Xdrova3d7pemI9BpTop7N6lJL4rimksXl2M/9iKNM3UmnZqL35C0kWS8UC1XLpM1VZZJXpAx/RQ== dependencies: "@babel/runtime" "^7.8.3" - "@polkadot/util" "^2.1.0-beta.0" - "@polkadot/util-crypto" "^2.1.0-beta.0" + "@polkadot/util" "^2.1.0-beta.1" + "@polkadot/util-crypto" "^2.1.0-beta.1" "@polkadot/ts@^0.2.1": version "0.2.1" @@ -2031,13 +2031,13 @@ dependencies: "@types/chrome" "^0.0.92" -"@polkadot/util-crypto@^2.1.0-beta.0": - version "2.1.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.1.0-beta.0.tgz#0d27cb897e0d116ce9197b6f566f11a416ef26a7" - integrity sha512-NUHLZua94cUcn4NvZOYX8YYmxfbQfhPcbZevJrqvROIVzHkO7IRvIzxNPVQH7KcvQEs+qzJf8VrM0+u1gURpqA== +"@polkadot/util-crypto@^2.1.0-beta.1": + version "2.1.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.1.0-beta.1.tgz#bfbd35f676135e85bd82c5bc5e99e2a9bb3012c5" + integrity sha512-xQKy5SKnDZhrEjq6d50Oj6A4h8UDOkDxMQ7ofKhx8B43c0V1NCeS4gBWgjkOp7+wlznTlA3Jj/Ry6J0u80AKrw== dependencies: "@babel/runtime" "^7.8.3" - "@polkadot/util" "^2.1.0-beta.0" + "@polkadot/util" "^2.1.0-beta.1" "@polkadot/wasm-crypto" "^0.20.1" "@types/bs58" "^4.0.0" "@types/elliptic" "^6.4.12" @@ -2052,10 +2052,10 @@ tweetnacl "^1.0.2" xxhashjs "^0.2.2" -"@polkadot/util@^2.1.0-beta.0": - version "2.1.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.1.0-beta.0.tgz#a0e7c891687e771582fe616047e58f96b7e435ff" - integrity sha512-ZHJ4vG+AJdltqhqotMu9Fw3Um7Gii61Ve2MQYYCaalLr9AZO3fgAq9St4O8vza49ZxOru8bZaexlToxCIt2b4g== +"@polkadot/util@^2.1.0-beta.1": + version "2.1.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.1.0-beta.1.tgz#27c7670d06150c82e9cfa109dbeb06430cddbb5e" + integrity sha512-rqxuaM0GXnVfgSDsO0iIpURlwDgJ1vZEXrB8SkUIK1GldL81w17eNKsds6ZXQjwiBBqaYMeQdfr3ENqkTBLgcw== dependencies: "@babel/runtime" "^7.8.3" "@types/bn.js" "^4.11.6"