@pezkuwi/types-codec 16.5.5 → 16.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/abstract/Array.js +166 -0
- package/abstract/Base.js +101 -0
- package/abstract/Int.js +226 -0
- package/abstract/Object.js +40 -0
- package/{src/abstract/index.ts → abstract/index.js} +0 -3
- package/base/Compact.js +159 -0
- package/base/DoNotConstruct.js +95 -0
- package/base/Enum.js +369 -0
- package/{build/base → base}/Int.d.ts +1 -1
- package/base/Int.js +26 -0
- package/base/Null.js +77 -0
- package/base/Option.js +232 -0
- package/base/Result.js +63 -0
- package/base/Tuple.js +110 -0
- package/{build/base → base}/UInt.d.ts +1 -1
- package/base/UInt.js +23 -0
- package/base/Vec.js +102 -0
- package/base/VecAny.js +17 -0
- package/base/VecFixed.js +67 -0
- package/{src/base/index.ts → base/index.js} +0 -3
- package/{src/bundle.ts → bundle.js} +0 -6
- package/cjs/abstract/Array.d.ts +89 -0
- package/cjs/abstract/Array.js +170 -0
- package/cjs/abstract/Base.d.ts +75 -0
- package/cjs/abstract/Base.js +105 -0
- package/cjs/abstract/Int.d.ts +80 -0
- package/cjs/abstract/Int.js +230 -0
- package/cjs/abstract/Object.d.ts +67 -0
- package/cjs/abstract/Object.js +44 -0
- package/cjs/abstract/index.d.ts +3 -0
- package/cjs/abstract/index.js +9 -0
- package/cjs/base/Compact.d.ts +88 -0
- package/cjs/base/Compact.js +163 -0
- package/cjs/base/DoNotConstruct.d.ts +63 -0
- package/cjs/base/DoNotConstruct.js +99 -0
- package/cjs/base/Enum.d.ts +118 -0
- package/cjs/base/Enum.js +373 -0
- package/cjs/base/Int.d.ts +16 -0
- package/cjs/base/Int.js +30 -0
- package/cjs/base/Null.d.ts +56 -0
- package/cjs/base/Null.js +81 -0
- package/cjs/base/Option.d.ts +94 -0
- package/cjs/base/Option.js +236 -0
- package/cjs/base/Result.d.ts +38 -0
- package/cjs/base/Result.js +67 -0
- package/cjs/base/Tuple.d.ts +42 -0
- package/cjs/base/Tuple.js +114 -0
- package/cjs/base/UInt.d.ts +15 -0
- package/cjs/base/UInt.js +27 -0
- package/cjs/base/Vec.d.ts +28 -0
- package/cjs/base/Vec.js +107 -0
- package/cjs/base/VecAny.d.ts +15 -0
- package/cjs/base/VecAny.js +21 -0
- package/cjs/base/VecFixed.d.ts +30 -0
- package/cjs/base/VecFixed.js +71 -0
- package/cjs/base/index.d.ts +12 -0
- package/cjs/base/index.js +27 -0
- package/cjs/bundle.d.ts +7 -0
- package/cjs/bundle.js +12 -0
- package/cjs/extended/BTreeMap.js +14 -0
- package/cjs/extended/BTreeSet.js +189 -0
- package/cjs/extended/BitVec.js +112 -0
- package/cjs/extended/Bytes.js +74 -0
- package/cjs/extended/HashMap.js +14 -0
- package/cjs/extended/Linkage.js +70 -0
- package/cjs/extended/Map.js +204 -0
- package/cjs/extended/OptionBool.js +76 -0
- package/cjs/extended/Range.js +42 -0
- package/cjs/extended/RangeInclusive.js +17 -0
- package/cjs/extended/Type.js +25 -0
- package/cjs/extended/U8aFixed.js +46 -0
- package/cjs/extended/WrapperKeepOpaque.js +103 -0
- package/cjs/extended/WrapperOpaque.js +23 -0
- package/cjs/extended/index.js +32 -0
- package/cjs/index.js +5 -0
- package/cjs/native/Bool.js +113 -0
- package/cjs/native/Date.js +144 -0
- package/cjs/native/Float.js +111 -0
- package/cjs/native/Json.js +121 -0
- package/cjs/native/Raw.js +144 -0
- package/cjs/native/Set.js +219 -0
- package/cjs/native/Struct.data.js +4 -0
- package/cjs/native/Struct.js +264 -0
- package/cjs/native/Text.js +154 -0
- package/cjs/native/index.js +22 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.js +5 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/primitive/F32.js +14 -0
- package/cjs/primitive/F64.js +14 -0
- package/cjs/primitive/I128.js +14 -0
- package/cjs/primitive/I16.js +14 -0
- package/cjs/primitive/I256.js +14 -0
- package/cjs/primitive/I32.js +14 -0
- package/cjs/primitive/I64.js +14 -0
- package/cjs/primitive/I8.js +14 -0
- package/cjs/primitive/ISize.js +18 -0
- package/cjs/primitive/U128.js +14 -0
- package/cjs/primitive/U16.js +14 -0
- package/cjs/primitive/U256.js +14 -0
- package/cjs/primitive/U32.js +14 -0
- package/cjs/primitive/U64.js +14 -0
- package/cjs/primitive/U8.js +14 -0
- package/cjs/primitive/USize.js +18 -0
- package/cjs/primitive/index.js +51 -0
- package/{build → cjs}/types/codec.d.ts +1 -1
- package/cjs/types/codec.js +2 -0
- package/cjs/types/helpers.js +2 -0
- package/cjs/types/index.js +7 -0
- package/cjs/types/interfaces.js +2 -0
- package/cjs/types/registry.js +2 -0
- package/cjs/utils/compareArray.js +13 -0
- package/cjs/utils/compareMap.js +30 -0
- package/cjs/utils/compareSet.js +20 -0
- package/cjs/utils/decodeU8a.js +105 -0
- package/cjs/utils/index.js +25 -0
- package/cjs/utils/sanitize.js +233 -0
- package/cjs/utils/sortValues.js +84 -0
- package/cjs/utils/toConstructors.js +40 -0
- package/cjs/utils/typesToMap.js +10 -0
- package/cjs/utils/util.js +7 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +10 -0
- package/extended/BTreeSet.d.ts +64 -0
- package/extended/BTreeSet.js +185 -0
- package/extended/BitVec.d.ts +37 -0
- package/extended/BitVec.js +108 -0
- package/extended/Bytes.d.ts +29 -0
- package/extended/Bytes.js +70 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +10 -0
- package/extended/Linkage.d.ts +37 -0
- package/extended/Linkage.js +65 -0
- package/extended/Map.d.ts +59 -0
- package/extended/Map.js +200 -0
- package/extended/OptionBool.d.ts +36 -0
- package/extended/OptionBool.js +72 -0
- package/extended/Range.d.ts +29 -0
- package/extended/Range.js +38 -0
- package/extended/RangeInclusive.d.ts +6 -0
- package/extended/RangeInclusive.js +13 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +21 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +42 -0
- package/extended/WrapperKeepOpaque.d.ts +40 -0
- package/extended/WrapperKeepOpaque.js +99 -0
- package/extended/WrapperOpaque.d.ts +10 -0
- package/extended/WrapperOpaque.js +19 -0
- package/{src/extended/index.ts → extended/index.d.ts} +0 -3
- package/extended/index.js +14 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/native/Bool.d.ts +71 -0
- package/native/Bool.js +109 -0
- package/native/Date.d.ts +84 -0
- package/native/Date.js +140 -0
- package/native/Float.d.ts +68 -0
- package/native/Float.js +107 -0
- package/native/Json.d.ts +69 -0
- package/native/Json.js +117 -0
- package/native/Raw.d.ts +87 -0
- package/native/Raw.js +140 -0
- package/native/Set.d.ts +84 -0
- package/native/Set.js +215 -0
- package/native/Struct.d.ts +106 -0
- package/{src/native/Struct.data.ts → native/Struct.data.js} +0 -3
- package/native/Struct.js +260 -0
- package/native/Text.d.ts +77 -0
- package/native/Text.js +150 -0
- package/{src/native/index.ts → native/index.d.ts} +0 -3
- package/native/index.js +8 -0
- package/package.json +1126 -11
- package/packageDetect.d.ts +1 -0
- package/packageDetect.js +3 -0
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/primitive/F32.d.ts +11 -0
- package/primitive/F32.js +10 -0
- package/primitive/F64.d.ts +11 -0
- package/primitive/F64.js +10 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +10 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +10 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +10 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +10 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +10 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +10 -0
- package/primitive/ISize.d.ts +12 -0
- package/primitive/ISize.js +14 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +10 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +10 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +10 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +10 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +10 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +10 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +14 -0
- package/{src/primitive/index.ts → primitive/index.d.ts} +0 -3
- package/primitive/index.js +16 -0
- package/types/codec.d.ts +113 -0
- package/types/codec.js +1 -0
- package/{src/types/helpers.ts → types/helpers.d.ts} +8 -31
- package/types/helpers.js +1 -0
- package/{src/types/index.ts → types/index.d.ts} +0 -3
- package/types/index.js +4 -0
- package/types/interfaces.d.ts +74 -0
- package/types/interfaces.js +1 -0
- package/types/registry.d.ts +67 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +10 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +27 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +17 -0
- package/utils/decodeU8a.d.ts +26 -0
- package/utils/decodeU8a.js +100 -0
- package/{src/utils/index.ts → utils/index.d.ts} +0 -3
- package/utils/index.js +8 -0
- package/utils/sanitize.d.ts +15 -0
- package/utils/sanitize.js +219 -0
- package/utils/sortValues.d.ts +12 -0
- package/utils/sortValues.js +79 -0
- package/utils/toConstructors.d.ts +16 -0
- package/utils/toConstructors.js +35 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +7 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +4 -0
- package/src/abstract/Array.ts +0 -213
- package/src/abstract/Base.ts +0 -129
- package/src/abstract/Int.ts +0 -271
- package/src/abstract/Object.ts +0 -99
- package/src/base/Compact.spec.ts +0 -99
- package/src/base/Compact.ts +0 -198
- package/src/base/DoNotConstruct.spec.ts +0 -23
- package/src/base/DoNotConstruct.ts +0 -118
- package/src/base/Enum.spec.ts +0 -487
- package/src/base/Enum.ts +0 -460
- package/src/base/Int.spec.ts +0 -225
- package/src/base/Int.ts +0 -34
- package/src/base/Null.spec.ts +0 -41
- package/src/base/Null.ts +0 -96
- package/src/base/Option.spec.ts +0 -216
- package/src/base/Option.ts +0 -275
- package/src/base/Result.spec.ts +0 -64
- package/src/base/Result.ts +0 -79
- package/src/base/Tuple.spec.ts +0 -161
- package/src/base/Tuple.ts +0 -149
- package/src/base/UInt.spec.ts +0 -192
- package/src/base/UInt.ts +0 -30
- package/src/base/Vec.spec.ts +0 -224
- package/src/base/Vec.ts +0 -133
- package/src/base/VecAny.ts +0 -23
- package/src/base/VecFixed.spec.ts +0 -78
- package/src/base/VecFixed.ts +0 -92
- package/src/checkTypes.manual.ts +0 -12
- package/src/extended/BTreeMap.spec.ts +0 -245
- package/src/extended/BTreeMap.ts +0 -16
- package/src/extended/BTreeSet.spec.ts +0 -260
- package/src/extended/BTreeSet.ts +0 -233
- package/src/extended/BitVec.spec.ts +0 -97
- package/src/extended/BitVec.ts +0 -137
- package/src/extended/Bytes.spec.ts +0 -75
- package/src/extended/Bytes.ts +0 -88
- package/src/extended/HashMap.spec.ts +0 -36
- package/src/extended/HashMap.ts +0 -16
- package/src/extended/Linkage.spec.ts +0 -43
- package/src/extended/Linkage.ts +0 -81
- package/src/extended/Map.spec.ts +0 -123
- package/src/extended/Map.ts +0 -255
- package/src/extended/OptionBool.spec.ts +0 -49
- package/src/extended/OptionBool.ts +0 -93
- package/src/extended/Range.spec.ts +0 -37
- package/src/extended/Range.ts +0 -56
- package/src/extended/RangeInclusive.ts +0 -20
- package/src/extended/Type.spec.ts +0 -118
- package/src/extended/Type.ts +0 -29
- package/src/extended/U8aFixed.spec.ts +0 -117
- package/src/extended/U8aFixed.ts +0 -57
- package/src/extended/WrapperKeepOpaque.spec.ts +0 -101
- package/src/extended/WrapperKeepOpaque.ts +0 -128
- package/src/extended/WrapperOpaque.spec.ts +0 -58
- package/src/extended/WrapperOpaque.ts +0 -27
- package/src/index.ts +0 -6
- package/src/mod.ts +0 -4
- package/src/native/Bool.spec.ts +0 -74
- package/src/native/Bool.ts +0 -137
- package/src/native/Date.spec.ts +0 -85
- package/src/native/Date.ts +0 -169
- package/src/native/Float.spec.ts +0 -51
- package/src/native/Float.ts +0 -136
- package/src/native/Json.ts +0 -147
- package/src/native/Raw.spec.ts +0 -113
- package/src/native/Raw.ts +0 -171
- package/src/native/Set.spec.ts +0 -116
- package/src/native/Set.ts +0 -269
- package/src/native/Struct.spec.ts +0 -411
- package/src/native/Struct.ts +0 -338
- package/src/native/Text.spec.ts +0 -85
- package/src/native/Text.ts +0 -184
- package/src/packageDetect.ts +0 -11
- package/src/packageInfo.ts +0 -6
- package/src/primitive/F32.ts +0 -14
- package/src/primitive/F64.ts +0 -14
- package/src/primitive/I128.ts +0 -14
- package/src/primitive/I16.ts +0 -14
- package/src/primitive/I256.ts +0 -14
- package/src/primitive/I32.ts +0 -14
- package/src/primitive/I64.ts +0 -14
- package/src/primitive/I8.ts +0 -14
- package/src/primitive/ISize.ts +0 -21
- package/src/primitive/U128.ts +0 -14
- package/src/primitive/U16.ts +0 -14
- package/src/primitive/U256.ts +0 -14
- package/src/primitive/U32.ts +0 -14
- package/src/primitive/U64.ts +0 -14
- package/src/primitive/U8.ts +0 -14
- package/src/primitive/USize.ts +0 -21
- package/src/test/performance.ts +0 -61
- package/src/types/codec.ts +0 -140
- package/src/types/interfaces.ts +0 -98
- package/src/types/registry.ts +0 -86
- package/src/utils/compareArray.ts +0 -22
- package/src/utils/compareMap.ts +0 -40
- package/src/utils/compareSet.ts +0 -23
- package/src/utils/decodeU8a.ts +0 -123
- package/src/utils/sanitize.spec.ts +0 -89
- package/src/utils/sanitize.ts +0 -290
- package/src/utils/sortValues.ts +0 -103
- package/src/utils/toConstructors.ts +0 -46
- package/src/utils/typesToMap.ts +0 -14
- package/src/utils/util.ts +0 -8
- package/tsconfig.build.json +0 -16
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -21
- /package/{build/abstract → abstract}/Array.d.ts +0 -0
- /package/{build/abstract → abstract}/Base.d.ts +0 -0
- /package/{build/abstract → abstract}/Int.d.ts +0 -0
- /package/{build/abstract → abstract}/Object.d.ts +0 -0
- /package/{build/abstract → abstract}/index.d.ts +0 -0
- /package/{build/base → base}/Compact.d.ts +0 -0
- /package/{build/base → base}/DoNotConstruct.d.ts +0 -0
- /package/{build/base → base}/Enum.d.ts +0 -0
- /package/{build/base → base}/Null.d.ts +0 -0
- /package/{build/base → base}/Option.d.ts +0 -0
- /package/{build/base → base}/Result.d.ts +0 -0
- /package/{build/base → base}/Tuple.d.ts +0 -0
- /package/{build/base → base}/Vec.d.ts +0 -0
- /package/{build/base → base}/VecAny.d.ts +0 -0
- /package/{build/base → base}/VecFixed.d.ts +0 -0
- /package/{build/base → base}/index.d.ts +0 -0
- /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
- /package/{build → cjs}/extended/BTreeMap.d.ts +0 -0
- /package/{build → cjs}/extended/BTreeSet.d.ts +0 -0
- /package/{build → cjs}/extended/BitVec.d.ts +0 -0
- /package/{build → cjs}/extended/Bytes.d.ts +0 -0
- /package/{build → cjs}/extended/HashMap.d.ts +0 -0
- /package/{build → cjs}/extended/Linkage.d.ts +0 -0
- /package/{build → cjs}/extended/Map.d.ts +0 -0
- /package/{build → cjs}/extended/OptionBool.d.ts +0 -0
- /package/{build → cjs}/extended/Range.d.ts +0 -0
- /package/{build → cjs}/extended/RangeInclusive.d.ts +0 -0
- /package/{build → cjs}/extended/Type.d.ts +0 -0
- /package/{build → cjs}/extended/U8aFixed.d.ts +0 -0
- /package/{build → cjs}/extended/WrapperKeepOpaque.d.ts +0 -0
- /package/{build → cjs}/extended/WrapperOpaque.d.ts +0 -0
- /package/{build → cjs}/extended/index.d.ts +0 -0
- /package/{build → cjs}/index.d.ts +0 -0
- /package/{build → cjs}/native/Bool.d.ts +0 -0
- /package/{build → cjs}/native/Date.d.ts +0 -0
- /package/{build → cjs}/native/Float.d.ts +0 -0
- /package/{build → cjs}/native/Json.d.ts +0 -0
- /package/{build → cjs}/native/Raw.d.ts +0 -0
- /package/{build → cjs}/native/Set.d.ts +0 -0
- /package/{build → cjs}/native/Struct.d.ts +0 -0
- /package/{build → cjs}/native/Text.d.ts +0 -0
- /package/{build → cjs}/native/index.d.ts +0 -0
- /package/{build → cjs}/packageDetect.d.ts +0 -0
- /package/{build → cjs}/packageInfo.d.ts +0 -0
- /package/{build → cjs}/primitive/F32.d.ts +0 -0
- /package/{build → cjs}/primitive/F64.d.ts +0 -0
- /package/{build → cjs}/primitive/I128.d.ts +0 -0
- /package/{build → cjs}/primitive/I16.d.ts +0 -0
- /package/{build → cjs}/primitive/I256.d.ts +0 -0
- /package/{build → cjs}/primitive/I32.d.ts +0 -0
- /package/{build → cjs}/primitive/I64.d.ts +0 -0
- /package/{build → cjs}/primitive/I8.d.ts +0 -0
- /package/{build → cjs}/primitive/ISize.d.ts +0 -0
- /package/{build → cjs}/primitive/U128.d.ts +0 -0
- /package/{build → cjs}/primitive/U16.d.ts +0 -0
- /package/{build → cjs}/primitive/U256.d.ts +0 -0
- /package/{build → cjs}/primitive/U32.d.ts +0 -0
- /package/{build → cjs}/primitive/U64.d.ts +0 -0
- /package/{build → cjs}/primitive/U8.d.ts +0 -0
- /package/{build → cjs}/primitive/USize.d.ts +0 -0
- /package/{build → cjs}/primitive/index.d.ts +0 -0
- /package/{build → cjs}/types/helpers.d.ts +0 -0
- /package/{build → cjs}/types/index.d.ts +0 -0
- /package/{build → cjs}/types/interfaces.d.ts +0 -0
- /package/{build → cjs}/types/registry.d.ts +0 -0
- /package/{build → cjs}/utils/compareArray.d.ts +0 -0
- /package/{build → cjs}/utils/compareMap.d.ts +0 -0
- /package/{build → cjs}/utils/compareSet.d.ts +0 -0
- /package/{build → cjs}/utils/decodeU8a.d.ts +0 -0
- /package/{build → cjs}/utils/index.d.ts +0 -0
- /package/{build → cjs}/utils/sanitize.d.ts +0 -0
- /package/{build → cjs}/utils/sortValues.d.ts +0 -0
- /package/{build → cjs}/utils/toConstructors.d.ts +0 -0
- /package/{build → cjs}/utils/typesToMap.d.ts +0 -0
- /package/{build → cjs}/utils/util.d.ts +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { TypeRegistry } from '@pezkuwi/types';
|
|
7
|
-
import { Linkage } from '@pezkuwi/types-codec';
|
|
8
|
-
|
|
9
|
-
const registry = new TypeRegistry();
|
|
10
|
-
|
|
11
|
-
describe('Linkage', (): void => {
|
|
12
|
-
it('decodes with ValidatorPrefs', (): void => {
|
|
13
|
-
const LINKA = { next: '5GznmRvdi5htUJKnMSWJgJUzSJJXSvWuHRSEdyUbHJZDNcwU', previous: null };
|
|
14
|
-
const PREFS = { commission: '10.00%' };
|
|
15
|
-
|
|
16
|
-
// prefs sanity check
|
|
17
|
-
expect(
|
|
18
|
-
registry.createType(
|
|
19
|
-
'ValidatorPrefsWithCommission',
|
|
20
|
-
'0x0284d717'
|
|
21
|
-
).toHuman()
|
|
22
|
-
).toEqual(PREFS);
|
|
23
|
-
|
|
24
|
-
// linkage sanity checks
|
|
25
|
-
expect(
|
|
26
|
-
new Linkage(registry, 'AccountId', '0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36').toHuman()
|
|
27
|
-
).toEqual(LINKA);
|
|
28
|
-
expect(
|
|
29
|
-
registry.createType(
|
|
30
|
-
'Linkage<AccountId>',
|
|
31
|
-
'0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
|
|
32
|
-
).toHuman()
|
|
33
|
-
).toEqual(LINKA);
|
|
34
|
-
|
|
35
|
-
// actual check
|
|
36
|
-
expect(
|
|
37
|
-
registry.createType(
|
|
38
|
-
'(ValidatorPrefsWithCommission, Linkage<AccountId>)',
|
|
39
|
-
'0x0284d7170001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
|
|
40
|
-
).toHuman()
|
|
41
|
-
).toEqual([PREFS, LINKA]);
|
|
42
|
-
});
|
|
43
|
-
});
|
package/src/extended/Linkage.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
-
import type { Codec, CodecClass, Registry } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
import { Option } from '../base/Option.js';
|
|
8
|
-
import { Tuple } from '../base/Tuple.js';
|
|
9
|
-
import { Vec } from '../base/Vec.js';
|
|
10
|
-
import { Struct } from '../native/Struct.js';
|
|
11
|
-
|
|
12
|
-
type TypeWithValues = [CodecClass, any[]];
|
|
13
|
-
|
|
14
|
-
const EMPTY = new Uint8Array();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @name Linkage
|
|
18
|
-
* @description The wrapper for the result from a LinkedMap
|
|
19
|
-
*/
|
|
20
|
-
export class Linkage<T extends Codec> extends Struct {
|
|
21
|
-
constructor (registry: Registry, Type: CodecClass | string, value?: unknown) {
|
|
22
|
-
super(registry, {
|
|
23
|
-
previous: Option.with(Type),
|
|
24
|
-
// eslint-disable-next-line sort-keys
|
|
25
|
-
next: Option.with(Type)
|
|
26
|
-
}, value as HexString);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static withKey<O extends Codec> (Type: CodecClass | string): CodecClass<Linkage<O>> {
|
|
30
|
-
return class extends Linkage<O> {
|
|
31
|
-
constructor (registry: Registry, value?: unknown) {
|
|
32
|
-
super(registry, Type, value);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @description Returns the next item the Linkage is pointing to
|
|
39
|
-
*/
|
|
40
|
-
public get previous (): Option<T> {
|
|
41
|
-
return this.get('previous') as Option<T>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @description Returns the previous item the Linkage is pointing to
|
|
46
|
-
*/
|
|
47
|
-
public get next (): Option<T> {
|
|
48
|
-
return this.get('next') as Option<T>;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @description Returns the base runtime type name for this instance
|
|
53
|
-
*/
|
|
54
|
-
public override toRawType (): string {
|
|
55
|
-
return `Linkage<${this.next.toRawType(true)}>`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
|
60
|
-
*/
|
|
61
|
-
public override toU8a (isBare?: boolean): Uint8Array {
|
|
62
|
-
// As part of a storage query (where these appear), in the case of empty, the values
|
|
63
|
-
// are NOT populated by the node - follow the same logic, leaving it empty
|
|
64
|
-
return this.isEmpty
|
|
65
|
-
? EMPTY
|
|
66
|
-
: super.toU8a(isBare);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @name LinkageResult
|
|
72
|
-
* @description A Linkage keys/Values tuple
|
|
73
|
-
*/
|
|
74
|
-
export class LinkageResult extends Tuple {
|
|
75
|
-
constructor (registry: Registry, [TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues) {
|
|
76
|
-
super(registry, {
|
|
77
|
-
Keys: Vec.with(TypeKey),
|
|
78
|
-
Values: Vec.with(TypeValue)
|
|
79
|
-
}, [keys, values]);
|
|
80
|
-
}
|
|
81
|
-
}
|
package/src/extended/Map.spec.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import type { CodecTo } from '@pezkuwi/types-codec/types';
|
|
7
|
-
|
|
8
|
-
import { TypeRegistry } from '@pezkuwi/types';
|
|
9
|
-
import { CodecMap, Text, U32 } from '@pezkuwi/types-codec';
|
|
10
|
-
import { stringToU8a } from '@pezkuwi/util';
|
|
11
|
-
|
|
12
|
-
const registry = new TypeRegistry();
|
|
13
|
-
const mockU32TextMap = new Map<Text, U32>();
|
|
14
|
-
|
|
15
|
-
mockU32TextMap.set(new Text(registry, 'bazzing'), new U32(registry, 69));
|
|
16
|
-
|
|
17
|
-
const mockU32TextMapString = '{"bazzing":69}';
|
|
18
|
-
const mockU32TextMapObject = { bazzing: 69 };
|
|
19
|
-
const mockU32TextMapHexString = '0x041c62617a7a696e6745000000';
|
|
20
|
-
const mockU32TextMapUint8Array = Uint8Array.from([4, 28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0]);
|
|
21
|
-
|
|
22
|
-
const mockU32U32Map = new Map<U32, U32>();
|
|
23
|
-
|
|
24
|
-
mockU32U32Map.set(new U32(registry, 1), new U32(registry, 2));
|
|
25
|
-
mockU32U32Map.set(new U32(registry, 23), new U32(registry, 24));
|
|
26
|
-
mockU32U32Map.set(new U32(registry, 28), new U32(registry, 30));
|
|
27
|
-
mockU32U32Map.set(new U32(registry, 45), new U32(registry, 80));
|
|
28
|
-
|
|
29
|
-
const mockU32U32MapString = '{"1":2,"23":24,"28":30,"45":80}';
|
|
30
|
-
const mockU32U32MapObject = { 1: 2, 23: 24, 28: 30, 45: 80 };
|
|
31
|
-
const mockU32U32MapHexString = '0x10043102000000083233180000000832381e00000008343550000000';
|
|
32
|
-
const mockU32U32MapUint8Array = Uint8Array.from([16, 4, 49, 2, 0, 0, 0, 8, 50, 51, 24, 0, 0, 0, 8, 50, 56, 30, 0, 0, 0, 8, 52, 53, 80, 0, 0, 0]);
|
|
33
|
-
|
|
34
|
-
describe('CodecMap', (): void => {
|
|
35
|
-
describe('decoding', (): void => {
|
|
36
|
-
const testDecode = (type: string, input: unknown, output: string): void =>
|
|
37
|
-
it(`can decode from ${type}`, (): void => {
|
|
38
|
-
const s = new CodecMap(registry, Text, U32, input as string);
|
|
39
|
-
|
|
40
|
-
expect(s.toString()).toBe(output);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
testDecode('map', mockU32TextMap, mockU32TextMapString);
|
|
44
|
-
testDecode('hex', mockU32TextMapHexString, mockU32TextMapString);
|
|
45
|
-
testDecode('Uint8Array', mockU32TextMapUint8Array, mockU32TextMapString);
|
|
46
|
-
|
|
47
|
-
testDecode('map', mockU32U32Map, mockU32U32MapString);
|
|
48
|
-
testDecode('hex', mockU32U32MapHexString, mockU32U32MapString);
|
|
49
|
-
testDecode('Uint8Array', mockU32U32MapUint8Array, mockU32U32MapString);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('encoding', (): void => {
|
|
53
|
-
const testEncode = (to: CodecTo, expected: any): void =>
|
|
54
|
-
it(`can encode ${to}`, (): void => {
|
|
55
|
-
const s = new CodecMap(registry, Text, U32, mockU32TextMap, 'BTreeMap');
|
|
56
|
-
|
|
57
|
-
expect(s[to]()).toEqual(expected);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
testEncode('toHex', mockU32TextMapHexString);
|
|
61
|
-
testEncode('toJSON', mockU32TextMapObject);
|
|
62
|
-
testEncode('toU8a', mockU32TextMapUint8Array);
|
|
63
|
-
testEncode('toString', mockU32TextMapString);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('encoding multiple values', (): void => {
|
|
67
|
-
const testEncode = (to: CodecTo, expected: any): void =>
|
|
68
|
-
it(`can encode ${to}`, (): void => {
|
|
69
|
-
const s = new CodecMap(registry, Text, U32, mockU32U32Map, 'BTreeMap');
|
|
70
|
-
|
|
71
|
-
expect(s[to]()).toEqual(expected);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
testEncode('toHex', mockU32U32MapHexString);
|
|
75
|
-
testEncode('toJSON', mockU32U32MapObject);
|
|
76
|
-
testEncode('toU8a', mockU32U32MapUint8Array);
|
|
77
|
-
testEncode('toString', mockU32U32MapString);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('enocodedLength & initialU8aLength', (): void => {
|
|
81
|
-
it('correctly encodes/decodes empty', (): void => {
|
|
82
|
-
const none = new CodecMap(registry, Text, Text, new Map([]));
|
|
83
|
-
|
|
84
|
-
// only the length byte
|
|
85
|
-
expect(none.toHex()).toEqual('0x00');
|
|
86
|
-
expect(none.encodedLength).toEqual(1);
|
|
87
|
-
expect(
|
|
88
|
-
new CodecMap(registry, Text, Text, none.toHex()).initialU8aLength
|
|
89
|
-
).toEqual(none.encodedLength);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('correctly encodes/decodes filled', (): void => {
|
|
93
|
-
const some = new CodecMap(registry, Text, Text, new Map([
|
|
94
|
-
[new Text(registry, '1'), new Text(registry, 'foo')],
|
|
95
|
-
[new Text(registry, '2'), new Text(registry, 'bar')]
|
|
96
|
-
]));
|
|
97
|
-
|
|
98
|
-
// length byte + 2 values, 2 << 2 with Text values
|
|
99
|
-
expect(some.toHex()).toEqual('0x0804310c666f6f04320c626172');
|
|
100
|
-
expect(some.encodedLength).toEqual(1 + ((1 + 1) * 2) + ((1 + 3) * 2));
|
|
101
|
-
expect(
|
|
102
|
-
new CodecMap(registry, Text, Text, some.toHex()).initialU8aLength
|
|
103
|
-
).toEqual(some.encodedLength);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('has a sane inspect', (): void => {
|
|
108
|
-
expect(
|
|
109
|
-
new CodecMap(registry, Text, Text, new Map([
|
|
110
|
-
[new Text(registry, '1'), new Text(registry, 'foo')],
|
|
111
|
-
[new Text(registry, '2'), new Text(registry, 'bar')]
|
|
112
|
-
])).inspect()
|
|
113
|
-
).toEqual({
|
|
114
|
-
inner: [
|
|
115
|
-
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
|
116
|
-
{ outer: [new Uint8Array([3 << 2]), stringToU8a('foo')] },
|
|
117
|
-
{ outer: [new Uint8Array([1 << 2]), stringToU8a('2')] },
|
|
118
|
-
{ outer: [new Uint8Array([3 << 2]), stringToU8a('bar')] }
|
|
119
|
-
],
|
|
120
|
-
outer: [new Uint8Array([2 << 2])]
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
package/src/extended/Map.ts
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
-
import type { AnyJson, Codec, CodecClass, IMap, Inspect, IU8a, Registry } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
|
8
|
-
|
|
9
|
-
import { AbstractArray } from '../abstract/Array.js';
|
|
10
|
-
import { Enum } from '../base/Enum.js';
|
|
11
|
-
import { Raw } from '../native/Raw.js';
|
|
12
|
-
import { Struct } from '../native/Struct.js';
|
|
13
|
-
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils/index.js';
|
|
14
|
-
|
|
15
|
-
const l = logger('Map');
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: Registry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, u8a: Uint8Array): [CodecClass<K>, CodecClass<V>, Map<K, V>, number] {
|
|
19
|
-
const output = new Map<K, V>();
|
|
20
|
-
const [offset, count] = compactFromU8aLim(u8a);
|
|
21
|
-
const types = [];
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < count; i++) {
|
|
24
|
-
types.push(KeyClass, ValClass);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const [values, decodedLength] = decodeU8a(registry, new Array(types.length), u8a.subarray(offset), [types, []]);
|
|
28
|
-
|
|
29
|
-
for (let i = 0, count = values.length; i < count; i += 2) {
|
|
30
|
-
output.set(values[i] as K, values[i + 1] as V);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return [KeyClass, ValClass, output, offset + decodedLength];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** @internal */
|
|
37
|
-
function decodeMapFromMap<K extends Codec, V extends Codec> (registry: Registry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, value: Map<any, any>): [CodecClass<K>, CodecClass<V>, Map<K, V>, number] {
|
|
38
|
-
const output = new Map<K, V>();
|
|
39
|
-
|
|
40
|
-
for (const [key, val] of value.entries()) {
|
|
41
|
-
const isComplex = KeyClass.prototype instanceof AbstractArray ||
|
|
42
|
-
KeyClass.prototype instanceof Struct ||
|
|
43
|
-
KeyClass.prototype instanceof Enum;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
output.set(
|
|
47
|
-
key instanceof KeyClass
|
|
48
|
-
? key
|
|
49
|
-
: new KeyClass(registry, isComplex && typeof key === 'string' ? JSON.parse(key) : key),
|
|
50
|
-
val instanceof ValClass
|
|
51
|
-
? val
|
|
52
|
-
: new ValClass(registry, val)
|
|
53
|
-
);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
l.error('Failed to decode key or value:', (error as Error).message);
|
|
56
|
-
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return [KeyClass, ValClass, output, 0];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Decode input to pass into constructor.
|
|
66
|
-
*
|
|
67
|
-
* @param KeyClass - Type of the map key
|
|
68
|
-
* @param ValClass - Type of the map value
|
|
69
|
-
* @param value - Value to decode, one of:
|
|
70
|
-
* - null
|
|
71
|
-
* - undefined
|
|
72
|
-
* - hex
|
|
73
|
-
* - Uint8Array
|
|
74
|
-
* - Map<any, any>, where both key and value types are either
|
|
75
|
-
* constructors or decodeable values for their types.
|
|
76
|
-
* @param jsonMap
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
function decodeMap<K extends Codec, V extends Codec> (registry: Registry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, value?: Uint8Array | string | Map<any, any>): [CodecClass<K>, CodecClass<V>, Map<K, V>, number] {
|
|
80
|
-
const KeyClass = typeToConstructor(registry, keyType);
|
|
81
|
-
const ValClass = typeToConstructor(registry, valType);
|
|
82
|
-
|
|
83
|
-
if (!value) {
|
|
84
|
-
return [KeyClass, ValClass, new Map<K, V>(), 0];
|
|
85
|
-
} else if (isU8a(value) || isHex(value)) {
|
|
86
|
-
return decodeMapFromU8a<K, V>(registry, KeyClass, ValClass, u8aToU8a(value));
|
|
87
|
-
} else if (value instanceof Map) {
|
|
88
|
-
return decodeMapFromMap<K, V>(registry, KeyClass, ValClass, value);
|
|
89
|
-
} else if (isObject(value)) {
|
|
90
|
-
return decodeMapFromMap<K, V>(registry, KeyClass, ValClass, new Map(Object.entries(value)));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
throw new Error('Map: cannot decode type');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
|
|
97
|
-
readonly registry: Registry;
|
|
98
|
-
|
|
99
|
-
public createdAtHash?: IU8a;
|
|
100
|
-
public initialU8aLength?: number;
|
|
101
|
-
public isStorageFallback?: boolean;
|
|
102
|
-
|
|
103
|
-
readonly #KeyClass: CodecClass<K>;
|
|
104
|
-
readonly #ValClass: CodecClass<V>;
|
|
105
|
-
readonly #type: string;
|
|
106
|
-
|
|
107
|
-
constructor (registry: Registry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, rawValue: Uint8Array | string | Map<any, any> | undefined, type: 'BTreeMap' | 'HashMap' = 'HashMap') {
|
|
108
|
-
const [KeyClass, ValClass, decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
109
|
-
|
|
110
|
-
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
|
111
|
-
|
|
112
|
-
this.registry = registry;
|
|
113
|
-
this.initialU8aLength = decodedLength;
|
|
114
|
-
this.#KeyClass = KeyClass;
|
|
115
|
-
this.#ValClass = ValClass;
|
|
116
|
-
this.#type = type;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
121
|
-
*/
|
|
122
|
-
public get encodedLength (): number {
|
|
123
|
-
let len = compactToU8a(this.size).length;
|
|
124
|
-
|
|
125
|
-
for (const [k, v] of this.entries()) {
|
|
126
|
-
len += k.encodedLength + v.encodedLength;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return len;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @description Returns a hash of the value
|
|
134
|
-
*/
|
|
135
|
-
public get hash (): IU8a {
|
|
136
|
-
return this.registry.hash(this.toU8a());
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @description Checks if the value is an empty value
|
|
141
|
-
*/
|
|
142
|
-
public get isEmpty (): boolean {
|
|
143
|
-
return this.size === 0;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @description Compares the value of the input to see if there is a match
|
|
148
|
-
*/
|
|
149
|
-
public eq (other?: unknown): boolean {
|
|
150
|
-
return compareMap(this, other);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* @description Returns a breakdown of the hex encoding for this Codec
|
|
155
|
-
*/
|
|
156
|
-
public inspect (): Inspect {
|
|
157
|
-
const inner: Inspect[] = [];
|
|
158
|
-
|
|
159
|
-
for (const [k, v] of this.entries()) {
|
|
160
|
-
inner.push(k.inspect());
|
|
161
|
-
inner.push(v.inspect());
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
inner,
|
|
166
|
-
outer: [compactToU8a(this.size)]
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
172
|
-
*/
|
|
173
|
-
public toHex (): HexString {
|
|
174
|
-
return u8aToHex(this.toU8a());
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
179
|
-
*/
|
|
180
|
-
public toHuman (isExtended?: boolean, disableAscii?: boolean): Record<string, AnyJson> {
|
|
181
|
-
const json: Record<string, AnyJson> = {};
|
|
182
|
-
|
|
183
|
-
for (const [k, v] of this.entries()) {
|
|
184
|
-
json[
|
|
185
|
-
k instanceof Raw && !disableAscii && k.isAscii
|
|
186
|
-
? k.toUtf8()
|
|
187
|
-
: k.toString()
|
|
188
|
-
] = v.toHuman(isExtended, disableAscii);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return json;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
196
|
-
*/
|
|
197
|
-
public toJSON (): Record<string, AnyJson> {
|
|
198
|
-
const json: Record<string, AnyJson> = {};
|
|
199
|
-
|
|
200
|
-
for (const [k, v] of this.entries()) {
|
|
201
|
-
json[k.toString()] = v.toJSON();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return json;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @description Converts the value in a best-fit primitive form
|
|
209
|
-
*/
|
|
210
|
-
public toPrimitive (disableAscii?: boolean): AnyJson {
|
|
211
|
-
const json: Record<string, AnyJson> = {};
|
|
212
|
-
|
|
213
|
-
for (const [k, v] of this.entries()) {
|
|
214
|
-
json[
|
|
215
|
-
k instanceof Raw && !disableAscii && k.isAscii
|
|
216
|
-
? k.toUtf8()
|
|
217
|
-
: k.toString()
|
|
218
|
-
] = v.toPrimitive(disableAscii);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return json;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @description Returns the base runtime type name for this instance
|
|
226
|
-
*/
|
|
227
|
-
public toRawType (): string {
|
|
228
|
-
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @description Returns the string representation of the value
|
|
233
|
-
*/
|
|
234
|
-
public override toString (): string {
|
|
235
|
-
return stringify(this.toJSON());
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
240
|
-
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
241
|
-
*/
|
|
242
|
-
public toU8a (isBare?: boolean): Uint8Array {
|
|
243
|
-
const encoded: Uint8Array[] = [];
|
|
244
|
-
|
|
245
|
-
if (!isBare) {
|
|
246
|
-
encoded.push(compactToU8a(this.size));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
for (const [k, v] of this.entries()) {
|
|
250
|
-
encoded.push(k.toU8a(isBare), v.toU8a(isBare));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return u8aConcatStrict(encoded);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { TypeRegistry } from '@pezkuwi/types';
|
|
7
|
-
import { OptionBool } from '@pezkuwi/types-codec';
|
|
8
|
-
|
|
9
|
-
describe('OptionBool', (): void => {
|
|
10
|
-
const registry = new TypeRegistry();
|
|
11
|
-
|
|
12
|
-
describe('decodes', (): void => {
|
|
13
|
-
it('decodes none', (): void => {
|
|
14
|
-
expect(new OptionBool(registry).toJSON()).toEqual(null);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('decodes true', (): void => {
|
|
18
|
-
expect(new OptionBool(registry, true).toJSON()).toEqual(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('decodes false', (): void => {
|
|
22
|
-
expect(new OptionBool(registry, false).toJSON()).toEqual(false);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('encodes', (): void => {
|
|
27
|
-
it('encodes none', (): void => {
|
|
28
|
-
expect(new OptionBool(registry).toU8a()).toEqual(new Uint8Array([0]));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('encodes true', (): void => {
|
|
32
|
-
expect(new OptionBool(registry, true).toU8a()).toEqual(new Uint8Array([1]));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('encodes false', (): void => {
|
|
36
|
-
expect(new OptionBool(registry, false).toU8a()).toEqual(new Uint8Array([2]));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('has a sane toRawType representation', (): void => {
|
|
41
|
-
expect(new OptionBool(registry).toRawType()).toEqual('Option<bool>');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('has a sane inspect', (): void => {
|
|
45
|
-
expect(new OptionBool(registry, true).inspect()).toEqual({
|
|
46
|
-
outer: [new Uint8Array([1])]
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
-
import type { AnyBool, Inspect, Registry } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
import { isHex, isU8a, u8aToU8a } from '@pezkuwi/util';
|
|
8
|
-
|
|
9
|
-
import { Option } from '../base/Option.js';
|
|
10
|
-
import { bool as Bool } from '../native/Bool.js';
|
|
11
|
-
|
|
12
|
-
function decodeU8a (registry: Registry, value: Uint8Array): null | Bool {
|
|
13
|
-
// Encoded as -
|
|
14
|
-
// - 0 = None
|
|
15
|
-
// - 1 = True
|
|
16
|
-
// - 2 = False
|
|
17
|
-
return value[0] === 0
|
|
18
|
-
? null
|
|
19
|
-
: new Bool(registry, value[0] === 1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @name OptionBool
|
|
24
|
-
* @description A specific implementation of Option<bool> than allows for single-byte encoding
|
|
25
|
-
*/
|
|
26
|
-
export class OptionBool extends Option<Bool> {
|
|
27
|
-
constructor (registry: Registry, value?: Option<Bool> | AnyBool | Uint8Array | HexString | null) {
|
|
28
|
-
super(
|
|
29
|
-
registry,
|
|
30
|
-
Bool,
|
|
31
|
-
isU8a(value) || isHex(value)
|
|
32
|
-
? decodeU8a(registry, u8aToU8a(value))
|
|
33
|
-
: value
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
this.initialU8aLength = 1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
41
|
-
*/
|
|
42
|
-
public override get encodedLength (): number {
|
|
43
|
-
return 1 | 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @description Checks if the value is an empty value (always false)
|
|
48
|
-
*/
|
|
49
|
-
public get isFalse (): boolean {
|
|
50
|
-
return this.isSome
|
|
51
|
-
? !this.value.valueOf()
|
|
52
|
-
: false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @description Checks if the value is an empty value (always false)
|
|
57
|
-
*/
|
|
58
|
-
public get isTrue (): boolean {
|
|
59
|
-
return this.isSome
|
|
60
|
-
? this.value.valueOf()
|
|
61
|
-
: false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @description Returns a breakdown of the hex encoding for this Codec
|
|
66
|
-
*/
|
|
67
|
-
public override inspect (): Inspect {
|
|
68
|
-
return { outer: [this.toU8a()] };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @description Returns the base runtime type name for this instance
|
|
73
|
-
*/
|
|
74
|
-
public override toRawType (isBare?: boolean): string {
|
|
75
|
-
return isBare
|
|
76
|
-
? 'bool'
|
|
77
|
-
: 'Option<bool>';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
82
|
-
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
83
|
-
*/
|
|
84
|
-
public override toU8a (isBare?: boolean): Uint8Array {
|
|
85
|
-
if (isBare) {
|
|
86
|
-
return super.toU8a(true);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return this.isSome
|
|
90
|
-
? new Uint8Array([this.isTrue ? 1 : 2])
|
|
91
|
-
: new Uint8Array([0]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/types-codec authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { TypeRegistry } from '@pezkuwi/types';
|
|
7
|
-
import { Range, U32 } from '@pezkuwi/types-codec';
|
|
8
|
-
|
|
9
|
-
describe('Range', (): void => {
|
|
10
|
-
const registry = new TypeRegistry();
|
|
11
|
-
let range: Range<U32>;
|
|
12
|
-
|
|
13
|
-
beforeEach((): void => {
|
|
14
|
-
range = new (Range.with(U32))(registry, [1, 2]);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('decodes', (): void => {
|
|
18
|
-
expect(range.toJSON()).toEqual([1, 2]);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('encodes', (): void => {
|
|
22
|
-
expect(range.toU8a()).toEqual(new Uint8Array([1, 0, 0, 0, 2, 0, 0, 0]));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('has a sane toRawType representation', (): void => {
|
|
26
|
-
expect(range.toRawType()).toEqual('Range<u32>');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('has a sane inspect', (): void => {
|
|
30
|
-
expect(range.inspect()).toEqual({
|
|
31
|
-
inner: [
|
|
32
|
-
{ outer: [new Uint8Array([1, 0, 0, 0])] },
|
|
33
|
-
{ outer: [new Uint8Array([2, 0, 0, 0])] }
|
|
34
|
-
]
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|