@polkadot/types-codec
Advanced tools
Comparing version 10.4.1 to 10.5.1
@@ -28,4 +28,5 @@ import { compactToU8a, u8aConcatStrict, u8aToHex } from '@polkadot/util'; | ||
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data | ||
let total = compactToU8a(this.length).length; | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
let total = compactToU8a(count).length; | ||
for (let i = 0; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -74,4 +75,5 @@ } | ||
inspectInner() { | ||
const inner = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const inner = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
inner[i] = this[i].inspect(); | ||
@@ -97,4 +99,5 @@ } | ||
toHuman(isExtended) { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i] && this[i].toHuman(isExtended); | ||
@@ -108,4 +111,5 @@ } | ||
toJSON() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
// We actually log inside the U8a decoding and use JSON.stringify(...), which | ||
@@ -121,4 +125,5 @@ // means that the Vec may be partially populated (same applies to toHuman, same check) | ||
toPrimitive() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i] && this[i].toPrimitive(); | ||
@@ -132,4 +137,5 @@ } | ||
toString() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i].toString(); | ||
@@ -155,4 +161,5 @@ } | ||
toU8aInner(isBare) { | ||
const encoded = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const encoded = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
encoded[i] = this[i].toU8a(isBare); | ||
@@ -159,0 +166,0 @@ } |
@@ -1,3 +0,1 @@ | ||
var _AbstractBase_raw; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
/** | ||
@@ -9,5 +7,4 @@ * @name Base | ||
constructor(registry, value, initialU8aLength) { | ||
_AbstractBase_raw.set(this, void 0); | ||
this.initialU8aLength = initialU8aLength; | ||
__classPrivateFieldSet(this, _AbstractBase_raw, value, "f"); | ||
this.__internal__raw = value; | ||
this.registry = registry; | ||
@@ -31,3 +28,3 @@ } | ||
get inner() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -38,3 +35,3 @@ /** | ||
get isEmpty() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -45,3 +42,3 @@ /** | ||
eq(other) { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").eq(other); | ||
return this.__internal__raw.eq(other); | ||
} | ||
@@ -52,3 +49,3 @@ /** | ||
inspect() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").inspect(); | ||
return this.__internal__raw.inspect(); | ||
} | ||
@@ -59,3 +56,3 @@ /** | ||
toHex(isLe) { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toHex(isLe); | ||
return this.__internal__raw.toHex(isLe); | ||
} | ||
@@ -66,3 +63,3 @@ /** | ||
toHuman(isExtended) { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -73,3 +70,3 @@ /** | ||
toJSON() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toJSON(); | ||
return this.__internal__raw.toJSON(); | ||
} | ||
@@ -80,3 +77,3 @@ /** | ||
toPrimitive() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toPrimitive(); | ||
return this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -87,3 +84,3 @@ /** | ||
toString() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -95,3 +92,3 @@ /** | ||
toU8a(isBare) { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f").toU8a(isBare); | ||
return this.__internal__raw.toU8a(isBare); | ||
} | ||
@@ -102,3 +99,3 @@ /** | ||
unwrap() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -109,5 +106,4 @@ /** | ||
valueOf() { | ||
return __classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
} | ||
_AbstractBase_raw = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _AbstractInt_bitLength; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBigInt, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util'; | ||
@@ -74,7 +72,6 @@ export const DEFAULT_UINT_BITS = 64; | ||
: decodeAbstractInt(value, isSigned)); | ||
_AbstractInt_bitLength.set(this, void 0); | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _AbstractInt_bitLength, bitLength, "f"); | ||
this.encodedLength = __classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8; | ||
this.initialU8aLength = __classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8; | ||
this.__internal__bitLength = bitLength; | ||
this.encodedLength = this.__internal__bitLength / 8; | ||
this.initialU8aLength = this.__internal__bitLength / 8; | ||
this.isUnsigned = !isSigned; | ||
@@ -106,3 +103,3 @@ const isNegative = this.isNeg(); | ||
bitLength() { | ||
return __classPrivateFieldGet(this, _AbstractInt_bitLength, "f"); | ||
return this.__internal__bitLength; | ||
} | ||
@@ -133,3 +130,3 @@ /** | ||
const u8a = this.toU8a().filter((b) => b === 0xff); | ||
return u8a.length === (__classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8); | ||
return u8a.length === (this.__internal__bitLength / 8); | ||
} | ||
@@ -182,5 +179,5 @@ /** | ||
// Options here are | ||
// - super.bitLength() - the actual used bits | ||
// - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic) | ||
return onlyHex || (super.bitLength() > MAX_NUMBER_BITS) | ||
// - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER | ||
// - this.__internal__bitLength - the max used bits, use hex when larger than native Rust type | ||
return onlyHex || (this.__internal__bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS) | ||
? this.toHex() | ||
@@ -227,2 +224,1 @@ : this.toNumber(); | ||
} | ||
_AbstractInt_bitLength = new WeakMap(); |
@@ -1,8 +0,3 @@ | ||
var _Compact_Type, _Compact_raw; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util'; | ||
import { compactFromU8a, compactFromU8aLim, compactToU8a, identity, isU8a } from '@polkadot/util'; | ||
import { typeToConstructor } from '../utils/index.js'; | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function decodeCompact(registry, Type, value) { | ||
@@ -35,10 +30,8 @@ if (isU8a(value)) { | ||
export class Compact { | ||
constructor(registry, Type, value = 0, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Compact_Type.set(this, void 0); | ||
_Compact_raw.set(this, void 0); | ||
constructor(registry, Type, value = 0, { definition, setDefinition = identity } = {}) { | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _Compact_Type, definition || setDefinition(typeToConstructor(registry, Type)), "f"); | ||
const [raw, decodedLength] = decodeCompact(registry, __classPrivateFieldGet(this, _Compact_Type, "f"), value); | ||
this.__internal__Type = definition || setDefinition(typeToConstructor(registry, Type)); | ||
const [raw, decodedLength] = decodeCompact(registry, this.__internal__Type, value); | ||
this.initialU8aLength = decodedLength; | ||
__classPrivateFieldSet(this, _Compact_raw, raw, "f"); | ||
this.__internal__raw = raw; | ||
} | ||
@@ -71,3 +64,3 @@ static with(Type) { | ||
get isEmpty() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -78,3 +71,3 @@ /** | ||
bitLength() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").bitLength(); | ||
return this.__internal__raw.bitLength(); | ||
} | ||
@@ -85,4 +78,4 @@ /** | ||
eq(other) { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").eq(other instanceof Compact | ||
? __classPrivateFieldGet(other, _Compact_raw, "f") | ||
return this.__internal__raw.eq(other instanceof Compact | ||
? other.__internal__raw | ||
: other); | ||
@@ -102,3 +95,3 @@ } | ||
toBigInt() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toBigInt(); | ||
return this.__internal__raw.toBigInt(); | ||
} | ||
@@ -109,3 +102,3 @@ /** | ||
toBn() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toBn(); | ||
return this.__internal__raw.toBn(); | ||
} | ||
@@ -116,3 +109,3 @@ /** | ||
toHex(isLe) { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toHex(isLe); | ||
return this.__internal__raw.toHex(isLe); | ||
} | ||
@@ -123,3 +116,3 @@ /** | ||
toHuman(isExtended) { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -130,3 +123,3 @@ /** | ||
toJSON() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toJSON(); | ||
return this.__internal__raw.toJSON(); | ||
} | ||
@@ -137,3 +130,3 @@ /** | ||
toNumber() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toNumber(); | ||
return this.__internal__raw.toNumber(); | ||
} | ||
@@ -144,3 +137,3 @@ /** | ||
toPrimitive() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toPrimitive(); | ||
return this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -151,3 +144,3 @@ /** | ||
toRawType() { | ||
return `Compact<${this.registry.getClassName(__classPrivateFieldGet(this, _Compact_Type, "f")) || __classPrivateFieldGet(this, _Compact_raw, "f").toRawType()}>`; | ||
return `Compact<${this.registry.getClassName(this.__internal__Type) || this.__internal__raw.toRawType()}>`; | ||
} | ||
@@ -158,3 +151,3 @@ /** | ||
toString() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -165,3 +158,3 @@ /** | ||
toU8a(_isBare) { | ||
return compactToU8a(__classPrivateFieldGet(this, _Compact_raw, "f").toBn()); | ||
return compactToU8a(this.__internal__raw.toBn()); | ||
} | ||
@@ -172,5 +165,4 @@ /** | ||
unwrap() { | ||
return __classPrivateFieldGet(this, _Compact_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
} | ||
_Compact_Type = new WeakMap(), _Compact_raw = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _DoNotConstruct_neverError; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
/** | ||
@@ -10,6 +8,5 @@ * @name DoNotConstruct | ||
constructor(registry, typeName = 'DoNotConstruct') { | ||
_DoNotConstruct_neverError.set(this, void 0); | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _DoNotConstruct_neverError, new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`), "f"); | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
this.__internal__neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -27,3 +24,3 @@ static with(typeName) { | ||
get encodedLength() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -34,3 +31,3 @@ /** | ||
get hash() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -41,3 +38,3 @@ /** | ||
get isEmpty() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -48,3 +45,3 @@ /** | ||
eq() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -55,3 +52,3 @@ /** | ||
inspect() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -62,3 +59,3 @@ /** | ||
toHex() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -69,3 +66,3 @@ /** | ||
toHuman() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -76,3 +73,3 @@ /** | ||
toJSON() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -83,3 +80,3 @@ /** | ||
toPrimitive() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -90,3 +87,3 @@ /** | ||
toRawType() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -97,3 +94,3 @@ /** | ||
toString() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -104,5 +101,4 @@ /** | ||
toU8a() { | ||
throw __classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
} | ||
_DoNotConstruct_neverError = new WeakMap(); |
@@ -1,9 +0,4 @@ | ||
var _Enum_def, _Enum_entryIndex, _Enum_indexes, _Enum_isBasic, _Enum_isIndexed, _Enum_raw; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
import { identity, isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
import { mapToTypeMap, typesToMap } from '../utils/index.js'; | ||
import { Null } from './Null.js'; | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function isRustEnum(def) { | ||
@@ -24,3 +19,3 @@ const defValues = Object.values(def); | ||
if (Array.isArray(_def)) { | ||
for (let i = 0; i < _def.length; i++) { | ||
for (let i = 0, count = _def.length; i < count; i++) { | ||
def[_def[i]] = { Type: Null, index: i }; | ||
@@ -33,3 +28,3 @@ } | ||
const [Types, keys] = mapToTypeMap(registry, _def); | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
def[keys[i]] = { Type: Types[i], index: i }; | ||
@@ -42,3 +37,3 @@ } | ||
const entries = Object.entries(_def); | ||
for (let i = 0; i < entries.length; i++) { | ||
for (let i = 0, count = entries.length; i < count; i++) { | ||
const [key, index] = entries[i]; | ||
@@ -134,9 +129,3 @@ def[key] = { Type: Null, index }; | ||
export class Enum { | ||
constructor(registry, Types, value, index, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Enum_def.set(this, void 0); | ||
_Enum_entryIndex.set(this, void 0); | ||
_Enum_indexes.set(this, void 0); | ||
_Enum_isBasic.set(this, void 0); | ||
_Enum_isIndexed.set(this, void 0); | ||
_Enum_raw.set(this, void 0); | ||
constructor(registry, Types, value, index, { definition, setDefinition = identity } = {}) { | ||
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types)); | ||
@@ -148,10 +137,10 @@ // shortcut isU8a as used in SCALE decoding | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _Enum_def, def, "f"); | ||
__classPrivateFieldSet(this, _Enum_isBasic, isBasic, "f"); | ||
__classPrivateFieldSet(this, _Enum_isIndexed, isIndexed, "f"); | ||
__classPrivateFieldSet(this, _Enum_indexes, Object.values(def).map(({ index }) => index), "f"); | ||
__classPrivateFieldSet(this, _Enum_entryIndex, __classPrivateFieldGet(this, _Enum_indexes, "f").indexOf(decoded.index), "f"); | ||
__classPrivateFieldSet(this, _Enum_raw, decoded.value, "f"); | ||
if (__classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength) { | ||
this.initialU8aLength = 1 + __classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength; | ||
this.__internal__def = def; | ||
this.__internal__isBasic = isBasic; | ||
this.__internal__isIndexed = isIndexed; | ||
this.__internal__indexes = Object.values(def).map(({ index }) => index); | ||
this.__internal__entryIndex = this.__internal__indexes.indexOf(decoded.index); | ||
this.__internal__raw = decoded.value; | ||
if (this.__internal__raw.initialU8aLength) { | ||
this.initialU8aLength = 1 + this.__internal__raw.initialU8aLength; | ||
} | ||
@@ -173,5 +162,6 @@ } | ||
: Object.keys(Types); | ||
const asKeys = new Array(keys.length); | ||
const isKeys = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const count = keys.length; | ||
const asKeys = new Array(count); | ||
const isKeys = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const name = stringPascalCase(keys[i]); | ||
@@ -195,3 +185,3 @@ asKeys[i] = `as${name}`; | ||
get encodedLength() { | ||
return 1 + __classPrivateFieldGet(this, _Enum_raw, "f").encodedLength; | ||
return 1 + this.__internal__raw.encodedLength; | ||
} | ||
@@ -208,3 +198,3 @@ /** | ||
get index() { | ||
return __classPrivateFieldGet(this, _Enum_indexes, "f")[__classPrivateFieldGet(this, _Enum_entryIndex, "f")]; | ||
return this.__internal__indexes[this.__internal__entryIndex]; | ||
} | ||
@@ -215,3 +205,3 @@ /** | ||
get inner() { | ||
return __classPrivateFieldGet(this, _Enum_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -222,3 +212,3 @@ /** | ||
get isBasic() { | ||
return __classPrivateFieldGet(this, _Enum_isBasic, "f"); | ||
return this.__internal__isBasic; | ||
} | ||
@@ -229,3 +219,3 @@ /** | ||
get isEmpty() { | ||
return __classPrivateFieldGet(this, _Enum_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -236,3 +226,3 @@ /** | ||
get isNone() { | ||
return __classPrivateFieldGet(this, _Enum_raw, "f") instanceof Null; | ||
return this.__internal__raw instanceof Null; | ||
} | ||
@@ -243,3 +233,3 @@ /** | ||
get defIndexes() { | ||
return __classPrivateFieldGet(this, _Enum_indexes, "f"); | ||
return this.__internal__indexes; | ||
} | ||
@@ -250,3 +240,3 @@ /** | ||
get defKeys() { | ||
return Object.keys(__classPrivateFieldGet(this, _Enum_def, "f")); | ||
return Object.keys(this.__internal__def); | ||
} | ||
@@ -257,3 +247,3 @@ /** | ||
get type() { | ||
return this.defKeys[__classPrivateFieldGet(this, _Enum_entryIndex, "f")]; | ||
return this.defKeys[this.__internal__entryIndex]; | ||
} | ||
@@ -264,3 +254,3 @@ /** | ||
get value() { | ||
return __classPrivateFieldGet(this, _Enum_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -278,3 +268,3 @@ /** | ||
} | ||
else if (__classPrivateFieldGet(this, _Enum_isBasic, "f") && isString(other)) { | ||
else if (this.__internal__isBasic && isString(other)) { | ||
return this.type === other; | ||
@@ -298,6 +288,6 @@ } | ||
inspect() { | ||
if (__classPrivateFieldGet(this, _Enum_isBasic, "f")) { | ||
if (this.__internal__isBasic) { | ||
return { outer: [new Uint8Array([this.index])] }; | ||
} | ||
const { inner, outer = [] } = __classPrivateFieldGet(this, _Enum_raw, "f").inspect(); | ||
const { inner, outer = [] } = this.__internal__raw.inspect(); | ||
return { | ||
@@ -318,5 +308,5 @@ inner, | ||
toHuman(isExtended) { | ||
return __classPrivateFieldGet(this, _Enum_isBasic, "f") || this.isNone | ||
return this.__internal__isBasic || this.isNone | ||
? this.type | ||
: { [this.type]: __classPrivateFieldGet(this, _Enum_raw, "f").toHuman(isExtended) }; | ||
: { [this.type]: this.__internal__raw.toHuman(isExtended) }; | ||
} | ||
@@ -327,5 +317,5 @@ /** | ||
toJSON() { | ||
return __classPrivateFieldGet(this, _Enum_isBasic, "f") | ||
return this.__internal__isBasic | ||
? this.type | ||
: { [stringCamelCase(this.type)]: __classPrivateFieldGet(this, _Enum_raw, "f").toJSON() }; | ||
: { [stringCamelCase(this.type)]: this.__internal__raw.toJSON() }; | ||
} | ||
@@ -342,5 +332,5 @@ /** | ||
toPrimitive() { | ||
return __classPrivateFieldGet(this, _Enum_isBasic, "f") | ||
return this.__internal__isBasic | ||
? this.type | ||
: { [stringCamelCase(this.type)]: __classPrivateFieldGet(this, _Enum_raw, "f").toPrimitive() }; | ||
: { [stringCamelCase(this.type)]: this.__internal__raw.toPrimitive() }; | ||
} | ||
@@ -351,6 +341,6 @@ /** | ||
_toRawStruct() { | ||
if (__classPrivateFieldGet(this, _Enum_isBasic, "f")) { | ||
return __classPrivateFieldGet(this, _Enum_isIndexed, "f") | ||
if (this.__internal__isBasic) { | ||
return this.__internal__isIndexed | ||
? this.defKeys.reduce((out, key, index) => { | ||
out[key] = __classPrivateFieldGet(this, _Enum_indexes, "f")[index]; | ||
out[key] = this.__internal__indexes[index]; | ||
return out; | ||
@@ -360,3 +350,3 @@ }, {}) | ||
} | ||
const entries = Object.entries(__classPrivateFieldGet(this, _Enum_def, "f")); | ||
const entries = Object.entries(this.__internal__def); | ||
return typesToMap(this.registry, entries.reduce((out, [key, { Type }], i) => { | ||
@@ -388,9 +378,8 @@ out[0][i] = Type; | ||
return isBare | ||
? __classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare) | ||
? this.__internal__raw.toU8a(isBare) | ||
: u8aConcatStrict([ | ||
new Uint8Array([this.index]), | ||
__classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare) | ||
this.__internal__raw.toU8a(isBare) | ||
]); | ||
} | ||
} | ||
_Enum_def = new WeakMap(), _Enum_entryIndex = new WeakMap(), _Enum_indexes = new WeakMap(), _Enum_isBasic = new WeakMap(), _Enum_isIndexed = new WeakMap(), _Enum_raw = new WeakMap(); |
@@ -1,9 +0,4 @@ | ||
var _Option_Type, _Option_raw; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util'; | ||
import { identity, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util'; | ||
import { typeToConstructor } from '../utils/index.js'; | ||
import { Null } from './Null.js'; | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
class None extends Null { | ||
@@ -57,5 +52,3 @@ /** | ||
export class Option { | ||
constructor(registry, typeName, value, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Option_Type.set(this, void 0); | ||
_Option_raw.set(this, void 0); | ||
constructor(registry, typeName, value, { definition, setDefinition = identity } = {}) { | ||
const Type = definition || setDefinition(typeToConstructor(registry, typeName)); | ||
@@ -68,4 +61,4 @@ const decoded = isU8a(value) && value.length && !isCodec(value) | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _Option_Type, Type, "f"); | ||
__classPrivateFieldSet(this, _Option_raw, decoded, "f"); | ||
this.__internal__Type = Type; | ||
this.__internal__raw = decoded; | ||
if (decoded?.initialU8aLength) { | ||
@@ -92,3 +85,3 @@ this.initialU8aLength = 1 + decoded.initialU8aLength; | ||
// boolean byte (has value, doesn't have) along with wrapped length | ||
return 1 + __classPrivateFieldGet(this, _Option_raw, "f").encodedLength; | ||
return 1 + this.__internal__raw.encodedLength; | ||
} | ||
@@ -111,3 +104,3 @@ /** | ||
get isNone() { | ||
return __classPrivateFieldGet(this, _Option_raw, "f") instanceof None; | ||
return this.__internal__raw instanceof None; | ||
} | ||
@@ -124,3 +117,3 @@ /** | ||
get value() { | ||
return __classPrivateFieldGet(this, _Option_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -143,3 +136,3 @@ /** | ||
} | ||
const { inner, outer = [] } = __classPrivateFieldGet(this, _Option_raw, "f").inspect(); | ||
const { inner, outer = [] } = this.__internal__raw.inspect(); | ||
return { | ||
@@ -164,3 +157,3 @@ inner, | ||
toHuman(isExtended) { | ||
return __classPrivateFieldGet(this, _Option_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -173,3 +166,3 @@ /** | ||
? null | ||
: __classPrivateFieldGet(this, _Option_raw, "f").toJSON(); | ||
: this.__internal__raw.toJSON(); | ||
} | ||
@@ -182,3 +175,3 @@ /** | ||
? null | ||
: __classPrivateFieldGet(this, _Option_raw, "f").toPrimitive(); | ||
: this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -189,3 +182,3 @@ /** | ||
toRawType(isBare) { | ||
const wrapped = this.registry.getClassName(__classPrivateFieldGet(this, _Option_Type, "f")) || new (__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry).toRawType(); | ||
const wrapped = this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType(); | ||
return isBare | ||
@@ -199,3 +192,3 @@ ? wrapped | ||
toString() { | ||
return __classPrivateFieldGet(this, _Option_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -208,3 +201,3 @@ /** | ||
if (isBare) { | ||
return __classPrivateFieldGet(this, _Option_raw, "f").toU8a(true); | ||
return this.__internal__raw.toU8a(true); | ||
} | ||
@@ -214,3 +207,3 @@ const u8a = new Uint8Array(this.encodedLength); | ||
u8a.set([1]); | ||
u8a.set(__classPrivateFieldGet(this, _Option_raw, "f").toU8a(), 1); | ||
u8a.set(this.__internal__raw.toU8a(), 1); | ||
} | ||
@@ -226,3 +219,3 @@ return u8a; | ||
} | ||
return __classPrivateFieldGet(this, _Option_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -245,5 +238,4 @@ /** | ||
? this.unwrap() | ||
: new (__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry); | ||
: new this.__internal__Type(this.registry); | ||
} | ||
} | ||
_Option_Type = new WeakMap(), _Option_raw = new WeakMap(); |
@@ -1,9 +0,4 @@ | ||
var _Tuple_Types; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util'; | ||
import { identity, isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util'; | ||
import { AbstractArray } from '../abstract/Array.js'; | ||
import { decodeU8a, mapToTypeMap, typeToConstructor } from '../utils/index.js'; | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
import { decodeU8a, mapToTypeMap, typesToConstructors, typeToConstructor } from '../utils/index.js'; | ||
/** @internal */ | ||
@@ -13,3 +8,3 @@ function decodeTuple(registry, result, value, Classes) { | ||
const Types = Classes[0]; | ||
for (let i = 0; i < Types.length; i++) { | ||
for (let i = 0, count = Types.length; i < count; i++) { | ||
try { | ||
@@ -32,3 +27,3 @@ const entry = value?.[i]; | ||
const Types = Classes[0]; | ||
for (let i = 0; i < Types.length; i++) { | ||
for (let i = 0, count = Types.length; i < count; i++) { | ||
result[i] = new Types[i](registry); | ||
@@ -47,5 +42,5 @@ } | ||
export class Tuple extends AbstractArray { | ||
constructor(registry, Types, value, { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Types, value, { definition, setDefinition = identity } = {}) { | ||
const Classes = definition || setDefinition(Array.isArray(Types) | ||
? [Types.map((t) => typeToConstructor(registry, t)), []] | ||
? [typesToConstructors(registry, Types), []] | ||
: isFunction(Types) || isString(Types) | ||
@@ -55,7 +50,6 @@ ? [[typeToConstructor(registry, Types)], []] | ||
super(registry, Classes[0].length); | ||
_Tuple_Types.set(this, void 0); | ||
this.initialU8aLength = (isU8a(value) | ||
? decodeU8a(registry, this, value, Classes) | ||
: decodeTuple(registry, this, value, Classes))[1]; | ||
__classPrivateFieldSet(this, _Tuple_Types, Classes, "f"); | ||
this.__internal__Types = Classes; | ||
} | ||
@@ -77,3 +71,3 @@ static with(Types) { | ||
let total = 0; | ||
for (let i = 0; i < this.length; i++) { | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -87,5 +81,5 @@ } | ||
get Types() { | ||
return __classPrivateFieldGet(this, _Tuple_Types, "f")[1].length | ||
? __classPrivateFieldGet(this, _Tuple_Types, "f")[1] | ||
: __classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => new T(this.registry).toRawType()); | ||
return this.__internal__Types[1].length | ||
? this.__internal__Types[1] | ||
: this.__internal__Types[0].map((T) => new T(this.registry).toRawType()); | ||
} | ||
@@ -104,3 +98,3 @@ /** | ||
toRawType() { | ||
const types = __classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType()); | ||
const types = this.__internal__Types[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType()); | ||
return `(${types.join(',')})`; | ||
@@ -123,2 +117,1 @@ } | ||
} | ||
_Tuple_Types = new WeakMap(); |
@@ -1,4 +0,2 @@ | ||
var _Vec_Type; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactFromU8aLim, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util'; | ||
import { compactFromU8aLim, identity, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util'; | ||
import { AbstractArray } from '../abstract/Array.js'; | ||
@@ -8,5 +6,2 @@ import { decodeU8aVec, typeToConstructor } from '../utils/index.js'; | ||
const l = logger('Vec'); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function decodeVecLength(value) { | ||
@@ -62,10 +57,9 @@ if (Array.isArray(value)) { | ||
export class Vec extends AbstractArray { | ||
constructor(registry, Type, value = [], { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Type, value = [], { definition, setDefinition = identity } = {}) { | ||
const [decodeFrom, length, startAt] = decodeVecLength(value); | ||
super(registry, length); | ||
_Vec_Type.set(this, void 0); | ||
__classPrivateFieldSet(this, _Vec_Type, definition || setDefinition(typeToConstructor(registry, Type)), "f"); | ||
this.__internal__Type = definition || setDefinition(typeToConstructor(registry, Type)); | ||
this.initialU8aLength = (isU8a(decodeFrom) | ||
? decodeU8aVec(registry, this, decodeFrom, startAt, __classPrivateFieldGet(this, _Vec_Type, "f")) | ||
: decodeVec(registry, this, decodeFrom, startAt, __classPrivateFieldGet(this, _Vec_Type, "f")))[0]; | ||
? decodeU8aVec(registry, this, decodeFrom, startAt, this.__internal__Type) | ||
: decodeVec(registry, this, decodeFrom, startAt, this.__internal__Type))[0]; | ||
} | ||
@@ -86,3 +80,3 @@ static with(Type) { | ||
get Type() { | ||
return __classPrivateFieldGet(this, _Vec_Type, "f").name; | ||
return this.__internal__Type.name; | ||
} | ||
@@ -94,6 +88,6 @@ /** | ||
// convert type first, this removes overhead from the eq | ||
const check = other instanceof __classPrivateFieldGet(this, _Vec_Type, "f") | ||
const check = other instanceof this.__internal__Type | ||
? other | ||
: new (__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry, other); | ||
for (let i = 0; i < this.length; i++) { | ||
: new this.__internal__Type(this.registry, other); | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
if (check.eq(this[i])) { | ||
@@ -109,5 +103,4 @@ return i; | ||
toRawType() { | ||
return `Vec<${this.registry.getClassName(__classPrivateFieldGet(this, _Vec_Type, "f")) || new (__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry).toRawType()}>`; | ||
return `Vec<${this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType()}>`; | ||
} | ||
} | ||
_Vec_Type = new WeakMap(); |
@@ -1,10 +0,5 @@ | ||
var _VecFixed_Type; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isU8a, u8aConcatStrict } from '@polkadot/util'; | ||
import { identity, isU8a, u8aConcatStrict } from '@polkadot/util'; | ||
import { AbstractArray } from '../abstract/Array.js'; | ||
import { decodeU8aVec, typeToConstructor } from '../utils/index.js'; | ||
import { decodeVec } from './Vec.js'; | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
/** | ||
@@ -16,9 +11,8 @@ * @name VecFixed | ||
export class VecFixed extends AbstractArray { | ||
constructor(registry, Type, length, value = [], { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Type, length, value = [], { definition, setDefinition = identity } = {}) { | ||
super(registry, length); | ||
_VecFixed_Type.set(this, void 0); | ||
__classPrivateFieldSet(this, _VecFixed_Type, definition || setDefinition(typeToConstructor(registry, Type)), "f"); | ||
this.__internal__Type = definition || setDefinition(typeToConstructor(registry, Type)); | ||
this.initialU8aLength = (isU8a(value) | ||
? decodeU8aVec(registry, this, value, 0, __classPrivateFieldGet(this, _VecFixed_Type, "f")) | ||
: decodeVec(registry, this, value, 0, __classPrivateFieldGet(this, _VecFixed_Type, "f")))[1]; | ||
? decodeU8aVec(registry, this, value, 0, this.__internal__Type) | ||
: decodeVec(registry, this, value, 0, this.__internal__Type))[1]; | ||
} | ||
@@ -39,3 +33,3 @@ static with(Type, length) { | ||
get Type() { | ||
return new (__classPrivateFieldGet(this, _VecFixed_Type, "f"))(this.registry).toRawType(); | ||
return new this.__internal__Type(this.registry).toRawType(); | ||
} | ||
@@ -47,3 +41,3 @@ /** | ||
let total = 0; | ||
for (let i = 0; i < this.length; i++) { | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -76,2 +70,1 @@ } | ||
} | ||
_VecFixed_Type = new WeakMap(); |
@@ -31,4 +31,5 @@ "use strict"; | ||
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data | ||
let total = (0, util_1.compactToU8a)(this.length).length; | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
let total = (0, util_1.compactToU8a)(count).length; | ||
for (let i = 0; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -77,4 +78,5 @@ } | ||
inspectInner() { | ||
const inner = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const inner = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
inner[i] = this[i].inspect(); | ||
@@ -100,4 +102,5 @@ } | ||
toHuman(isExtended) { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i] && this[i].toHuman(isExtended); | ||
@@ -111,4 +114,5 @@ } | ||
toJSON() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
// We actually log inside the U8a decoding and use JSON.stringify(...), which | ||
@@ -124,4 +128,5 @@ // means that the Vec may be partially populated (same applies to toHuman, same check) | ||
toPrimitive() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i] && this[i].toPrimitive(); | ||
@@ -135,4 +140,5 @@ } | ||
toString() { | ||
const result = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
result[i] = this[i].toString(); | ||
@@ -158,4 +164,5 @@ } | ||
toU8aInner(isBare) { | ||
const encoded = new Array(this.length); | ||
for (let i = 0; i < this.length; i++) { | ||
const count = this.length; | ||
const encoded = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
encoded[i] = this[i].toU8a(isBare); | ||
@@ -162,0 +169,0 @@ } |
"use strict"; | ||
var _AbstractBase_raw; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractBase = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -12,5 +10,4 @@ * @name Base | ||
constructor(registry, value, initialU8aLength) { | ||
_AbstractBase_raw.set(this, void 0); | ||
this.initialU8aLength = initialU8aLength; | ||
tslib_1.__classPrivateFieldSet(this, _AbstractBase_raw, value, "f"); | ||
this.__internal__raw = value; | ||
this.registry = registry; | ||
@@ -34,3 +31,3 @@ } | ||
get inner() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -41,3 +38,3 @@ /** | ||
get isEmpty() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -48,3 +45,3 @@ /** | ||
eq(other) { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").eq(other); | ||
return this.__internal__raw.eq(other); | ||
} | ||
@@ -55,3 +52,3 @@ /** | ||
inspect() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").inspect(); | ||
return this.__internal__raw.inspect(); | ||
} | ||
@@ -62,3 +59,3 @@ /** | ||
toHex(isLe) { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toHex(isLe); | ||
return this.__internal__raw.toHex(isLe); | ||
} | ||
@@ -69,3 +66,3 @@ /** | ||
toHuman(isExtended) { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -76,3 +73,3 @@ /** | ||
toJSON() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toJSON(); | ||
return this.__internal__raw.toJSON(); | ||
} | ||
@@ -83,3 +80,3 @@ /** | ||
toPrimitive() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toPrimitive(); | ||
return this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -90,3 +87,3 @@ /** | ||
toString() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -98,3 +95,3 @@ /** | ||
toU8a(isBare) { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f").toU8a(isBare); | ||
return this.__internal__raw.toU8a(isBare); | ||
} | ||
@@ -105,3 +102,3 @@ /** | ||
unwrap() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -112,6 +109,5 @@ /** | ||
valueOf() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractBase_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
} | ||
exports.AbstractBase = AbstractBase; | ||
_AbstractBase_raw = new WeakMap(); |
"use strict"; | ||
var _AbstractInt_bitLength; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractInt = exports.DEFAULT_UINT_BITS = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -77,7 +75,6 @@ exports.DEFAULT_UINT_BITS = 64; | ||
: decodeAbstractInt(value, isSigned)); | ||
_AbstractInt_bitLength.set(this, void 0); | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _AbstractInt_bitLength, bitLength, "f"); | ||
this.encodedLength = tslib_1.__classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8; | ||
this.initialU8aLength = tslib_1.__classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8; | ||
this.__internal__bitLength = bitLength; | ||
this.encodedLength = this.__internal__bitLength / 8; | ||
this.initialU8aLength = this.__internal__bitLength / 8; | ||
this.isUnsigned = !isSigned; | ||
@@ -109,3 +106,3 @@ const isNegative = this.isNeg(); | ||
bitLength() { | ||
return tslib_1.__classPrivateFieldGet(this, _AbstractInt_bitLength, "f"); | ||
return this.__internal__bitLength; | ||
} | ||
@@ -136,3 +133,3 @@ /** | ||
const u8a = this.toU8a().filter((b) => b === 0xff); | ||
return u8a.length === (tslib_1.__classPrivateFieldGet(this, _AbstractInt_bitLength, "f") / 8); | ||
return u8a.length === (this.__internal__bitLength / 8); | ||
} | ||
@@ -185,5 +182,5 @@ /** | ||
// Options here are | ||
// - super.bitLength() - the actual used bits | ||
// - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic) | ||
return onlyHex || (super.bitLength() > MAX_NUMBER_BITS) | ||
// - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER | ||
// - this.__internal__bitLength - the max used bits, use hex when larger than native Rust type | ||
return onlyHex || (this.__internal__bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS) | ||
? this.toHex() | ||
@@ -231,2 +228,1 @@ : this.toNumber(); | ||
exports.AbstractInt = AbstractInt; | ||
_AbstractInt_bitLength = new WeakMap(); |
"use strict"; | ||
var _Compact_Type, _Compact_raw; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Compact = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
const index_js_1 = require("../utils/index.js"); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function decodeCompact(registry, Type, value) { | ||
@@ -38,10 +33,8 @@ if ((0, util_1.isU8a)(value)) { | ||
class Compact { | ||
constructor(registry, Type, value = 0, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Compact_Type.set(this, void 0); | ||
_Compact_raw.set(this, void 0); | ||
constructor(registry, Type, value = 0, { definition, setDefinition = util_1.identity } = {}) { | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _Compact_Type, definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)), "f"); | ||
const [raw, decodedLength] = decodeCompact(registry, tslib_1.__classPrivateFieldGet(this, _Compact_Type, "f"), value); | ||
this.__internal__Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)); | ||
const [raw, decodedLength] = decodeCompact(registry, this.__internal__Type, value); | ||
this.initialU8aLength = decodedLength; | ||
tslib_1.__classPrivateFieldSet(this, _Compact_raw, raw, "f"); | ||
this.__internal__raw = raw; | ||
} | ||
@@ -74,3 +67,3 @@ static with(Type) { | ||
get isEmpty() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -81,3 +74,3 @@ /** | ||
bitLength() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").bitLength(); | ||
return this.__internal__raw.bitLength(); | ||
} | ||
@@ -88,4 +81,4 @@ /** | ||
eq(other) { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").eq(other instanceof Compact | ||
? tslib_1.__classPrivateFieldGet(other, _Compact_raw, "f") | ||
return this.__internal__raw.eq(other instanceof Compact | ||
? other.__internal__raw | ||
: other); | ||
@@ -105,3 +98,3 @@ } | ||
toBigInt() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toBigInt(); | ||
return this.__internal__raw.toBigInt(); | ||
} | ||
@@ -112,3 +105,3 @@ /** | ||
toBn() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toBn(); | ||
return this.__internal__raw.toBn(); | ||
} | ||
@@ -119,3 +112,3 @@ /** | ||
toHex(isLe) { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toHex(isLe); | ||
return this.__internal__raw.toHex(isLe); | ||
} | ||
@@ -126,3 +119,3 @@ /** | ||
toHuman(isExtended) { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -133,3 +126,3 @@ /** | ||
toJSON() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toJSON(); | ||
return this.__internal__raw.toJSON(); | ||
} | ||
@@ -140,3 +133,3 @@ /** | ||
toNumber() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toNumber(); | ||
return this.__internal__raw.toNumber(); | ||
} | ||
@@ -147,3 +140,3 @@ /** | ||
toPrimitive() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toPrimitive(); | ||
return this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -154,3 +147,3 @@ /** | ||
toRawType() { | ||
return `Compact<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _Compact_Type, "f")) || tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toRawType()}>`; | ||
return `Compact<${this.registry.getClassName(this.__internal__Type) || this.__internal__raw.toRawType()}>`; | ||
} | ||
@@ -161,3 +154,3 @@ /** | ||
toString() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -168,3 +161,3 @@ /** | ||
toU8a(_isBare) { | ||
return (0, util_1.compactToU8a)(tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f").toBn()); | ||
return (0, util_1.compactToU8a)(this.__internal__raw.toBn()); | ||
} | ||
@@ -175,6 +168,5 @@ /** | ||
unwrap() { | ||
return tslib_1.__classPrivateFieldGet(this, _Compact_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
} | ||
exports.Compact = Compact; | ||
_Compact_Type = new WeakMap(), _Compact_raw = new WeakMap(); |
"use strict"; | ||
var _DoNotConstruct_neverError; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DoNotConstruct = void 0; | ||
const tslib_1 = require("tslib"); | ||
/** | ||
@@ -13,6 +11,5 @@ * @name DoNotConstruct | ||
constructor(registry, typeName = 'DoNotConstruct') { | ||
_DoNotConstruct_neverError.set(this, void 0); | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _DoNotConstruct_neverError, new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`), "f"); | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
this.__internal__neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -30,3 +27,3 @@ static with(typeName) { | ||
get encodedLength() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -37,3 +34,3 @@ /** | ||
get hash() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -44,3 +41,3 @@ /** | ||
get isEmpty() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -51,3 +48,3 @@ /** | ||
eq() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -58,3 +55,3 @@ /** | ||
inspect() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -65,3 +62,3 @@ /** | ||
toHex() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -72,3 +69,3 @@ /** | ||
toHuman() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -79,3 +76,3 @@ /** | ||
toJSON() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -86,3 +83,3 @@ /** | ||
toPrimitive() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -93,3 +90,3 @@ /** | ||
toRawType() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -100,3 +97,3 @@ /** | ||
toString() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
@@ -107,6 +104,5 @@ /** | ||
toU8a() { | ||
throw tslib_1.__classPrivateFieldGet(this, _DoNotConstruct_neverError, "f"); | ||
throw this.__internal__neverError; | ||
} | ||
} | ||
exports.DoNotConstruct = DoNotConstruct; | ||
_DoNotConstruct_neverError = new WeakMap(); |
"use strict"; | ||
var _Enum_def, _Enum_entryIndex, _Enum_indexes, _Enum_isBasic, _Enum_isIndexed, _Enum_raw; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Enum = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
const index_js_1 = require("../utils/index.js"); | ||
const Null_js_1 = require("./Null.js"); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function isRustEnum(def) { | ||
@@ -27,3 +22,3 @@ const defValues = Object.values(def); | ||
if (Array.isArray(_def)) { | ||
for (let i = 0; i < _def.length; i++) { | ||
for (let i = 0, count = _def.length; i < count; i++) { | ||
def[_def[i]] = { Type: Null_js_1.Null, index: i }; | ||
@@ -36,3 +31,3 @@ } | ||
const [Types, keys] = (0, index_js_1.mapToTypeMap)(registry, _def); | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
def[keys[i]] = { Type: Types[i], index: i }; | ||
@@ -45,3 +40,3 @@ } | ||
const entries = Object.entries(_def); | ||
for (let i = 0; i < entries.length; i++) { | ||
for (let i = 0, count = entries.length; i < count; i++) { | ||
const [key, index] = entries[i]; | ||
@@ -137,9 +132,3 @@ def[key] = { Type: Null_js_1.Null, index }; | ||
class Enum { | ||
constructor(registry, Types, value, index, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Enum_def.set(this, void 0); | ||
_Enum_entryIndex.set(this, void 0); | ||
_Enum_indexes.set(this, void 0); | ||
_Enum_isBasic.set(this, void 0); | ||
_Enum_isIndexed.set(this, void 0); | ||
_Enum_raw.set(this, void 0); | ||
constructor(registry, Types, value, index, { definition, setDefinition = util_1.identity } = {}) { | ||
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types)); | ||
@@ -151,10 +140,10 @@ // shortcut isU8a as used in SCALE decoding | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _Enum_def, def, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Enum_isBasic, isBasic, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Enum_isIndexed, isIndexed, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Enum_indexes, Object.values(def).map(({ index }) => index), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Enum_entryIndex, tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f").indexOf(decoded.index), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Enum_raw, decoded.value, "f"); | ||
if (tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength) { | ||
this.initialU8aLength = 1 + tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength; | ||
this.__internal__def = def; | ||
this.__internal__isBasic = isBasic; | ||
this.__internal__isIndexed = isIndexed; | ||
this.__internal__indexes = Object.values(def).map(({ index }) => index); | ||
this.__internal__entryIndex = this.__internal__indexes.indexOf(decoded.index); | ||
this.__internal__raw = decoded.value; | ||
if (this.__internal__raw.initialU8aLength) { | ||
this.initialU8aLength = 1 + this.__internal__raw.initialU8aLength; | ||
} | ||
@@ -176,5 +165,6 @@ } | ||
: Object.keys(Types); | ||
const asKeys = new Array(keys.length); | ||
const isKeys = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const count = keys.length; | ||
const asKeys = new Array(count); | ||
const isKeys = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const name = (0, util_1.stringPascalCase)(keys[i]); | ||
@@ -198,3 +188,3 @@ asKeys[i] = `as${name}`; | ||
get encodedLength() { | ||
return 1 + tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").encodedLength; | ||
return 1 + this.__internal__raw.encodedLength; | ||
} | ||
@@ -211,3 +201,3 @@ /** | ||
get index() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f")[tslib_1.__classPrivateFieldGet(this, _Enum_entryIndex, "f")]; | ||
return this.__internal__indexes[this.__internal__entryIndex]; | ||
} | ||
@@ -218,3 +208,3 @@ /** | ||
get inner() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -225,3 +215,3 @@ /** | ||
get isBasic() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f"); | ||
return this.__internal__isBasic; | ||
} | ||
@@ -232,3 +222,3 @@ /** | ||
get isEmpty() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").isEmpty; | ||
return this.__internal__raw.isEmpty; | ||
} | ||
@@ -239,3 +229,3 @@ /** | ||
get isNone() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f") instanceof Null_js_1.Null; | ||
return this.__internal__raw instanceof Null_js_1.Null; | ||
} | ||
@@ -246,3 +236,3 @@ /** | ||
get defIndexes() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f"); | ||
return this.__internal__indexes; | ||
} | ||
@@ -253,3 +243,3 @@ /** | ||
get defKeys() { | ||
return Object.keys(tslib_1.__classPrivateFieldGet(this, _Enum_def, "f")); | ||
return Object.keys(this.__internal__def); | ||
} | ||
@@ -260,3 +250,3 @@ /** | ||
get type() { | ||
return this.defKeys[tslib_1.__classPrivateFieldGet(this, _Enum_entryIndex, "f")]; | ||
return this.defKeys[this.__internal__entryIndex]; | ||
} | ||
@@ -267,3 +257,3 @@ /** | ||
get value() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -281,3 +271,3 @@ /** | ||
} | ||
else if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") && (0, util_1.isString)(other)) { | ||
else if (this.__internal__isBasic && (0, util_1.isString)(other)) { | ||
return this.type === other; | ||
@@ -301,6 +291,6 @@ } | ||
inspect() { | ||
if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")) { | ||
if (this.__internal__isBasic) { | ||
return { outer: [new Uint8Array([this.index])] }; | ||
} | ||
const { inner, outer = [] } = tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").inspect(); | ||
const { inner, outer = [] } = this.__internal__raw.inspect(); | ||
return { | ||
@@ -321,5 +311,5 @@ inner, | ||
toHuman(isExtended) { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") || this.isNone | ||
return this.__internal__isBasic || this.isNone | ||
? this.type | ||
: { [this.type]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toHuman(isExtended) }; | ||
: { [this.type]: this.__internal__raw.toHuman(isExtended) }; | ||
} | ||
@@ -330,5 +320,5 @@ /** | ||
toJSON() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") | ||
return this.__internal__isBasic | ||
? this.type | ||
: { [(0, util_1.stringCamelCase)(this.type)]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toJSON() }; | ||
: { [(0, util_1.stringCamelCase)(this.type)]: this.__internal__raw.toJSON() }; | ||
} | ||
@@ -345,5 +335,5 @@ /** | ||
toPrimitive() { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") | ||
return this.__internal__isBasic | ||
? this.type | ||
: { [(0, util_1.stringCamelCase)(this.type)]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toPrimitive() }; | ||
: { [(0, util_1.stringCamelCase)(this.type)]: this.__internal__raw.toPrimitive() }; | ||
} | ||
@@ -354,6 +344,6 @@ /** | ||
_toRawStruct() { | ||
if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")) { | ||
return tslib_1.__classPrivateFieldGet(this, _Enum_isIndexed, "f") | ||
if (this.__internal__isBasic) { | ||
return this.__internal__isIndexed | ||
? this.defKeys.reduce((out, key, index) => { | ||
out[key] = tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f")[index]; | ||
out[key] = this.__internal__indexes[index]; | ||
return out; | ||
@@ -363,3 +353,3 @@ }, {}) | ||
} | ||
const entries = Object.entries(tslib_1.__classPrivateFieldGet(this, _Enum_def, "f")); | ||
const entries = Object.entries(this.__internal__def); | ||
return (0, index_js_1.typesToMap)(this.registry, entries.reduce((out, [key, { Type }], i) => { | ||
@@ -391,6 +381,6 @@ out[0][i] = Type; | ||
return isBare | ||
? tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare) | ||
? this.__internal__raw.toU8a(isBare) | ||
: (0, util_1.u8aConcatStrict)([ | ||
new Uint8Array([this.index]), | ||
tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare) | ||
this.__internal__raw.toU8a(isBare) | ||
]); | ||
@@ -400,2 +390,1 @@ } | ||
exports.Enum = Enum; | ||
_Enum_def = new WeakMap(), _Enum_entryIndex = new WeakMap(), _Enum_indexes = new WeakMap(), _Enum_isBasic = new WeakMap(), _Enum_isIndexed = new WeakMap(), _Enum_raw = new WeakMap(); |
"use strict"; | ||
var _Option_Type, _Option_raw; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Option = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
const index_js_1 = require("../utils/index.js"); | ||
const Null_js_1 = require("./Null.js"); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
class None extends Null_js_1.Null { | ||
@@ -60,5 +55,3 @@ /** | ||
class Option { | ||
constructor(registry, typeName, value, { definition, setDefinition = noopSetDefinition } = {}) { | ||
_Option_Type.set(this, void 0); | ||
_Option_raw.set(this, void 0); | ||
constructor(registry, typeName, value, { definition, setDefinition = util_1.identity } = {}) { | ||
const Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, typeName)); | ||
@@ -71,4 +64,4 @@ const decoded = (0, util_1.isU8a)(value) && value.length && !(0, util_1.isCodec)(value) | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _Option_Type, Type, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Option_raw, decoded, "f"); | ||
this.__internal__Type = Type; | ||
this.__internal__raw = decoded; | ||
if (decoded?.initialU8aLength) { | ||
@@ -95,3 +88,3 @@ this.initialU8aLength = 1 + decoded.initialU8aLength; | ||
// boolean byte (has value, doesn't have) along with wrapped length | ||
return 1 + tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").encodedLength; | ||
return 1 + this.__internal__raw.encodedLength; | ||
} | ||
@@ -114,3 +107,3 @@ /** | ||
get isNone() { | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f") instanceof None; | ||
return this.__internal__raw instanceof None; | ||
} | ||
@@ -127,3 +120,3 @@ /** | ||
get value() { | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -146,3 +139,3 @@ /** | ||
} | ||
const { inner, outer = [] } = tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").inspect(); | ||
const { inner, outer = [] } = this.__internal__raw.inspect(); | ||
return { | ||
@@ -167,3 +160,3 @@ inner, | ||
toHuman(isExtended) { | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toHuman(isExtended); | ||
return this.__internal__raw.toHuman(isExtended); | ||
} | ||
@@ -176,3 +169,3 @@ /** | ||
? null | ||
: tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toJSON(); | ||
: this.__internal__raw.toJSON(); | ||
} | ||
@@ -185,3 +178,3 @@ /** | ||
? null | ||
: tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toPrimitive(); | ||
: this.__internal__raw.toPrimitive(); | ||
} | ||
@@ -192,3 +185,3 @@ /** | ||
toRawType(isBare) { | ||
const wrapped = this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _Option_Type, "f")) || new (tslib_1.__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry).toRawType(); | ||
const wrapped = this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType(); | ||
return isBare | ||
@@ -202,3 +195,3 @@ ? wrapped | ||
toString() { | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toString(); | ||
return this.__internal__raw.toString(); | ||
} | ||
@@ -211,3 +204,3 @@ /** | ||
if (isBare) { | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toU8a(true); | ||
return this.__internal__raw.toU8a(true); | ||
} | ||
@@ -217,3 +210,3 @@ const u8a = new Uint8Array(this.encodedLength); | ||
u8a.set([1]); | ||
u8a.set(tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toU8a(), 1); | ||
u8a.set(this.__internal__raw.toU8a(), 1); | ||
} | ||
@@ -229,3 +222,3 @@ return u8a; | ||
} | ||
return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f"); | ||
return this.__internal__raw; | ||
} | ||
@@ -248,6 +241,5 @@ /** | ||
? this.unwrap() | ||
: new (tslib_1.__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry); | ||
: new this.__internal__Type(this.registry); | ||
} | ||
} | ||
exports.Option = Option; | ||
_Option_Type = new WeakMap(), _Option_raw = new WeakMap(); |
"use strict"; | ||
var _Tuple_Types; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Tuple = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
const Array_js_1 = require("../abstract/Array.js"); | ||
const index_js_1 = require("../utils/index.js"); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
/** @internal */ | ||
@@ -16,3 +11,3 @@ function decodeTuple(registry, result, value, Classes) { | ||
const Types = Classes[0]; | ||
for (let i = 0; i < Types.length; i++) { | ||
for (let i = 0, count = Types.length; i < count; i++) { | ||
try { | ||
@@ -35,3 +30,3 @@ const entry = value?.[i]; | ||
const Types = Classes[0]; | ||
for (let i = 0; i < Types.length; i++) { | ||
for (let i = 0, count = Types.length; i < count; i++) { | ||
result[i] = new Types[i](registry); | ||
@@ -50,5 +45,5 @@ } | ||
class Tuple extends Array_js_1.AbstractArray { | ||
constructor(registry, Types, value, { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Types, value, { definition, setDefinition = util_1.identity } = {}) { | ||
const Classes = definition || setDefinition(Array.isArray(Types) | ||
? [Types.map((t) => (0, index_js_1.typeToConstructor)(registry, t)), []] | ||
? [(0, index_js_1.typesToConstructors)(registry, Types), []] | ||
: (0, util_1.isFunction)(Types) || (0, util_1.isString)(Types) | ||
@@ -58,7 +53,6 @@ ? [[(0, index_js_1.typeToConstructor)(registry, Types)], []] | ||
super(registry, Classes[0].length); | ||
_Tuple_Types.set(this, void 0); | ||
this.initialU8aLength = ((0, util_1.isU8a)(value) | ||
? (0, index_js_1.decodeU8a)(registry, this, value, Classes) | ||
: decodeTuple(registry, this, value, Classes))[1]; | ||
tslib_1.__classPrivateFieldSet(this, _Tuple_Types, Classes, "f"); | ||
this.__internal__Types = Classes; | ||
} | ||
@@ -80,3 +74,3 @@ static with(Types) { | ||
let total = 0; | ||
for (let i = 0; i < this.length; i++) { | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -90,5 +84,5 @@ } | ||
get Types() { | ||
return tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[1].length | ||
? tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[1] | ||
: tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => new T(this.registry).toRawType()); | ||
return this.__internal__Types[1].length | ||
? this.__internal__Types[1] | ||
: this.__internal__Types[0].map((T) => new T(this.registry).toRawType()); | ||
} | ||
@@ -107,3 +101,3 @@ /** | ||
toRawType() { | ||
const types = tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType()); | ||
const types = this.__internal__Types[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType()); | ||
return `(${types.join(',')})`; | ||
@@ -127,2 +121,1 @@ } | ||
exports.Tuple = Tuple; | ||
_Tuple_Types = new WeakMap(); |
"use strict"; | ||
var _Vec_Type; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Vec = exports.decodeVec = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -11,5 +9,2 @@ const Array_js_1 = require("../abstract/Array.js"); | ||
const l = (0, util_1.logger)('Vec'); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
function decodeVecLength(value) { | ||
@@ -66,10 +61,9 @@ if (Array.isArray(value)) { | ||
class Vec extends Array_js_1.AbstractArray { | ||
constructor(registry, Type, value = [], { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Type, value = [], { definition, setDefinition = util_1.identity } = {}) { | ||
const [decodeFrom, length, startAt] = decodeVecLength(value); | ||
super(registry, length); | ||
_Vec_Type.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _Vec_Type, definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)), "f"); | ||
this.__internal__Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)); | ||
this.initialU8aLength = ((0, util_1.isU8a)(decodeFrom) | ||
? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")) | ||
: decodeVec(registry, this, decodeFrom, startAt, tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")))[0]; | ||
? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, this.__internal__Type) | ||
: decodeVec(registry, this, decodeFrom, startAt, this.__internal__Type))[0]; | ||
} | ||
@@ -90,3 +84,3 @@ static with(Type) { | ||
get Type() { | ||
return tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f").name; | ||
return this.__internal__Type.name; | ||
} | ||
@@ -98,6 +92,6 @@ /** | ||
// convert type first, this removes overhead from the eq | ||
const check = other instanceof tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f") | ||
const check = other instanceof this.__internal__Type | ||
? other | ||
: new (tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry, other); | ||
for (let i = 0; i < this.length; i++) { | ||
: new this.__internal__Type(this.registry, other); | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
if (check.eq(this[i])) { | ||
@@ -113,6 +107,5 @@ return i; | ||
toRawType() { | ||
return `Vec<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")) || new (tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry).toRawType()}>`; | ||
return `Vec<${this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType()}>`; | ||
} | ||
} | ||
exports.Vec = Vec; | ||
_Vec_Type = new WeakMap(); |
"use strict"; | ||
var _VecFixed_Type; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VecFixed = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -10,5 +8,2 @@ const Array_js_1 = require("../abstract/Array.js"); | ||
const Vec_js_1 = require("./Vec.js"); | ||
function noopSetDefinition(d) { | ||
return d; | ||
} | ||
/** | ||
@@ -20,9 +15,8 @@ * @name VecFixed | ||
class VecFixed extends Array_js_1.AbstractArray { | ||
constructor(registry, Type, length, value = [], { definition, setDefinition = noopSetDefinition } = {}) { | ||
constructor(registry, Type, length, value = [], { definition, setDefinition = util_1.identity } = {}) { | ||
super(registry, length); | ||
_VecFixed_Type.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _VecFixed_Type, definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)), "f"); | ||
this.__internal__Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)); | ||
this.initialU8aLength = ((0, util_1.isU8a)(value) | ||
? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f")) | ||
: (0, Vec_js_1.decodeVec)(registry, this, value, 0, tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f")))[1]; | ||
? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, this.__internal__Type) | ||
: (0, Vec_js_1.decodeVec)(registry, this, value, 0, this.__internal__Type))[1]; | ||
} | ||
@@ -43,3 +37,3 @@ static with(Type, length) { | ||
get Type() { | ||
return new (tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f"))(this.registry).toRawType(); | ||
return new this.__internal__Type(this.registry).toRawType(); | ||
} | ||
@@ -51,3 +45,3 @@ /** | ||
let total = 0; | ||
for (let i = 0; i < this.length; i++) { | ||
for (let i = 0, count = this.length; i < count; i++) { | ||
total += this[i].encodedLength; | ||
@@ -81,2 +75,1 @@ } | ||
exports.VecFixed = VecFixed; | ||
_VecFixed_Type = new WeakMap(); |
"use strict"; | ||
var _BitVec_decodedLength, _BitVec_isMsb; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitVec = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -42,6 +40,4 @@ const Raw_js_1 = require("../native/Raw.js"); | ||
super(registry, u8a); | ||
_BitVec_decodedLength.set(this, void 0); | ||
_BitVec_isMsb.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _BitVec_decodedLength, decodedLength, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _BitVec_isMsb, isMsb, "f"); | ||
this.__internal__decodedLength = decodedLength; | ||
this.__internal__isMsb = isMsb; | ||
} | ||
@@ -52,3 +48,3 @@ /** | ||
get encodedLength() { | ||
return this.length + (0, util_1.compactToU8a)(tslib_1.__classPrivateFieldGet(this, _BitVec_decodedLength, "f")).length; | ||
return this.length + (0, util_1.compactToU8a)(this.__internal__decodedLength).length; | ||
} | ||
@@ -60,3 +56,3 @@ /** | ||
return { | ||
outer: [(0, util_1.compactToU8a)(tslib_1.__classPrivateFieldGet(this, _BitVec_decodedLength, "f")), super.toU8a()] | ||
outer: [(0, util_1.compactToU8a)(this.__internal__decodedLength), super.toU8a()] | ||
}; | ||
@@ -78,8 +74,9 @@ } | ||
]); | ||
const result = new Array(8 * map.length); | ||
for (let i = 0; i < map.length; i++) { | ||
const count = map.length; | ||
const result = new Array(8 * count); | ||
for (let i = 0; i < count; i++) { | ||
const off = i * 8; | ||
const v = map[i]; | ||
for (let j = 0; j < 8; j++) { | ||
result[off + j] = tslib_1.__classPrivateFieldGet(this, _BitVec_isMsb, "f") | ||
result[off + j] = this.__internal__isMsb | ||
? v[j] | ||
@@ -97,3 +94,3 @@ : v[7 - j]; | ||
.map((d) => `00000000${d.toString(2)}`.slice(-8)) | ||
.map((s) => tslib_1.__classPrivateFieldGet(this, _BitVec_isMsb, "f") ? s : s.split('').reverse().join('')) | ||
.map((s) => this.__internal__isMsb ? s : s.split('').reverse().join('')) | ||
.join('_')}`; | ||
@@ -115,6 +112,5 @@ } | ||
? bitVec | ||
: (0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(tslib_1.__classPrivateFieldGet(this, _BitVec_decodedLength, "f")), bitVec]); | ||
: (0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(this.__internal__decodedLength), bitVec]); | ||
} | ||
} | ||
exports.BitVec = BitVec; | ||
_BitVec_decodedLength = new WeakMap(), _BitVec_isMsb = new WeakMap(); |
"use strict"; | ||
var _BTreeSet_ValClass; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BTreeSet = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -65,6 +63,5 @@ const index_js_1 = require("../utils/index.js"); | ||
super((0, index_js_1.sortSet)(values)); | ||
_BTreeSet_ValClass.set(this, void 0); | ||
this.registry = registry; | ||
this.initialU8aLength = decodedLength; | ||
tslib_1.__classPrivateFieldSet(this, _BTreeSet_ValClass, ValClass, "f"); | ||
this.__internal__ValClass = ValClass; | ||
} | ||
@@ -155,3 +152,3 @@ static with(valType) { | ||
toRawType() { | ||
return `BTreeSet<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _BTreeSet_ValClass, "f")) || new (tslib_1.__classPrivateFieldGet(this, _BTreeSet_ValClass, "f"))(this.registry).toRawType()}>`; | ||
return `BTreeSet<${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`; | ||
} | ||
@@ -190,2 +187,1 @@ /** | ||
exports.BTreeSet = BTreeSet; | ||
_BTreeSet_ValClass = new WeakMap(); |
"use strict"; | ||
var _CodecMap_KeyClass, _CodecMap_ValClass, _CodecMap_type; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CodecMap = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -22,3 +20,3 @@ const Array_js_1 = require("../abstract/Array.js"); | ||
const [values, decodedLength] = (0, index_js_1.decodeU8a)(registry, new Array(types.length), u8a.subarray(offset), [types, []]); | ||
for (let i = 0; i < values.length; i += 2) { | ||
for (let i = 0, count = values.length; i < count; i += 2) { | ||
output.set(values[i], values[i + 1]); | ||
@@ -85,10 +83,7 @@ } | ||
super(type === 'BTreeMap' ? (0, index_js_1.sortMap)(decoded) : decoded); | ||
_CodecMap_KeyClass.set(this, void 0); | ||
_CodecMap_ValClass.set(this, void 0); | ||
_CodecMap_type.set(this, void 0); | ||
this.registry = registry; | ||
this.initialU8aLength = decodedLength; | ||
tslib_1.__classPrivateFieldSet(this, _CodecMap_KeyClass, KeyClass, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _CodecMap_ValClass, ValClass, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _CodecMap_type, type, "f"); | ||
this.__internal__KeyClass = KeyClass; | ||
this.__internal__ValClass = ValClass; | ||
this.__internal__type = type; | ||
} | ||
@@ -181,3 +176,3 @@ /** | ||
toRawType() { | ||
return `${tslib_1.__classPrivateFieldGet(this, _CodecMap_type, "f")}<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _CodecMap_KeyClass, "f")) || new (tslib_1.__classPrivateFieldGet(this, _CodecMap_KeyClass, "f"))(this.registry).toRawType()},${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _CodecMap_ValClass, "f")) || new (tslib_1.__classPrivateFieldGet(this, _CodecMap_ValClass, "f"))(this.registry).toRawType()}>`; | ||
return `${this.__internal__type}<${this.registry.getClassName(this.__internal__KeyClass) || new this.__internal__KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`; | ||
} | ||
@@ -206,2 +201,1 @@ /** | ||
exports.CodecMap = CodecMap; | ||
_CodecMap_KeyClass = new WeakMap(), _CodecMap_ValClass = new WeakMap(), _CodecMap_type = new WeakMap(); |
"use strict"; | ||
var _Range_rangeName; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Range = void 0; | ||
const tslib_1 = require("tslib"); | ||
const Tuple_js_1 = require("../base/Tuple.js"); | ||
@@ -15,4 +13,3 @@ /** | ||
super(registry, [Type, Type], value); | ||
_Range_rangeName.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _Range_rangeName, rangeName, "f"); | ||
this.__internal__rangeName = rangeName; | ||
} | ||
@@ -42,6 +39,5 @@ static with(Type) { | ||
toRawType() { | ||
return `${tslib_1.__classPrivateFieldGet(this, _Range_rangeName, "f")}<${this.start.toRawType()}>`; | ||
return `${this.__internal__rangeName}<${this.start.toRawType()}>`; | ||
} | ||
} | ||
exports.Range = Range; | ||
_Range_rangeName = new WeakMap(); |
"use strict"; | ||
var _WrapperKeepOpaque_Type, _WrapperKeepOpaque_decoded, _WrapperKeepOpaque_opaqueName; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WrapperKeepOpaque = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -32,8 +30,5 @@ const Raw_js_1 = require("../native/Raw.js"); | ||
super(registry, u8a); | ||
_WrapperKeepOpaque_Type.set(this, void 0); | ||
_WrapperKeepOpaque_decoded.set(this, void 0); | ||
_WrapperKeepOpaque_opaqueName.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _WrapperKeepOpaque_Type, Type, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _WrapperKeepOpaque_decoded, decoded, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _WrapperKeepOpaque_opaqueName, opaqueName, "f"); | ||
this.__internal__Type = Type; | ||
this.__internal__decoded = decoded; | ||
this.__internal__opaqueName = opaqueName; | ||
} | ||
@@ -51,3 +46,3 @@ static with(Type) { | ||
get isDecoded() { | ||
return !!tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f"); | ||
return !!this.__internal__decoded; | ||
} | ||
@@ -58,5 +53,5 @@ /** | ||
inspect() { | ||
return tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
return this.__internal__decoded | ||
? { | ||
inner: [tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").inspect()], | ||
inner: [this.__internal__decoded.inspect()], | ||
outer: [(0, util_1.compactToU8a)(this.length)] | ||
@@ -72,4 +67,4 @@ } | ||
toHuman(isExtended) { | ||
return tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toHuman(isExtended) | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toHuman(isExtended) | ||
: super.toHuman(); | ||
@@ -81,4 +76,4 @@ } | ||
toPrimitive() { | ||
return tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toPrimitive() | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toPrimitive() | ||
: super.toPrimitive(); | ||
@@ -90,3 +85,3 @@ } | ||
toRawType() { | ||
return `${tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f")) || (tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") ? tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toRawType() : new (tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f"))(this.registry).toRawType())}>`; | ||
return `${this.__internal__opaqueName}<${this.registry.getClassName(this.__internal__Type) || (this.__internal__decoded ? this.__internal__decoded.toRawType() : new this.__internal__Type(this.registry).toRawType())}>`; | ||
} | ||
@@ -97,4 +92,4 @@ /** | ||
toString() { | ||
return tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toString() | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toString() | ||
: super.toString(); | ||
@@ -106,9 +101,8 @@ } | ||
unwrap() { | ||
if (!tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")) { | ||
throw new Error(`${tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}: unwrapping an undecodable value`); | ||
if (!this.__internal__decoded) { | ||
throw new Error(`${this.__internal__opaqueName}: unwrapping an undecodable value`); | ||
} | ||
return tslib_1.__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f"); | ||
return this.__internal__decoded; | ||
} | ||
} | ||
exports.WrapperKeepOpaque = WrapperKeepOpaque; | ||
_WrapperKeepOpaque_Type = new WeakMap(), _WrapperKeepOpaque_decoded = new WeakMap(), _WrapperKeepOpaque_opaqueName = new WeakMap(); |
"use strict"; | ||
var _Float_bitLength; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Float = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -22,4 +20,3 @@ /** | ||
: (value || 0)); | ||
_Float_bitLength.set(this, void 0); | ||
tslib_1.__classPrivateFieldSet(this, _Float_bitLength, bitLength, "f"); | ||
this.__internal__bitLength = bitLength; | ||
this.encodedLength = bitLength / 8; | ||
@@ -98,3 +95,3 @@ this.initialU8aLength = this.encodedLength; | ||
toRawType() { | ||
return `f${tslib_1.__classPrivateFieldGet(this, _Float_bitLength, "f")}`; | ||
return `f${this.__internal__bitLength}`; | ||
} | ||
@@ -106,3 +103,3 @@ /** | ||
return (0, util_1.floatToU8a)(this, { | ||
bitLength: tslib_1.__classPrivateFieldGet(this, _Float_bitLength, "f") | ||
bitLength: this.__internal__bitLength | ||
}); | ||
@@ -112,2 +109,1 @@ } | ||
exports.Float = Float; | ||
_Float_bitLength = new WeakMap(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Text = exports.Struct = exports.Set = exports.CodecSet = exports.Raw = exports.Json = exports.Float = exports.Date = exports.CodecDate = exports.Bool = exports.bool = void 0; | ||
exports.Text = exports.Struct = exports.Set = exports.CodecSet = exports.Raw = exports.Json = exports.Float = exports.Date = exports.CodecDate = exports.bool = exports.Bool = void 0; | ||
var Bool_js_1 = require("./Bool.js"); | ||
Object.defineProperty(exports, "Bool", { enumerable: true, get: function () { return Bool_js_1.bool; } }); | ||
Object.defineProperty(exports, "bool", { enumerable: true, get: function () { return Bool_js_1.bool; } }); | ||
Object.defineProperty(exports, "Bool", { enumerable: true, get: function () { return Bool_js_1.bool; } }); | ||
var Date_js_1 = require("./Date.js"); | ||
@@ -8,0 +8,0 @@ Object.defineProperty(exports, "CodecDate", { enumerable: true, get: function () { return Date_js_1.CodecDate; } }); |
"use strict"; | ||
var _CodecSet_allowed, _CodecSet_byteLength; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CodecSet = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -10,3 +8,3 @@ const index_js_1 = require("../utils/index.js"); | ||
const encoded = new util_1.BN(0); | ||
for (let i = 0; i < values.length; i++) { | ||
for (let i = 0, count = values.length; i < count; i++) { | ||
encoded.ior((0, util_1.bnToBn)(setValues[values[i]] || 0)); | ||
@@ -18,4 +16,5 @@ } | ||
function decodeSetArray(setValues, values) { | ||
const result = new Array(values.length); | ||
for (let i = 0; i < values.length; i++) { | ||
const count = values.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const key = values[i]; | ||
@@ -34,3 +33,3 @@ if ((0, util_1.isUndefined)(setValues[key])) { | ||
const result = []; | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
const key = keys[i]; | ||
@@ -78,4 +77,2 @@ if (bn.and((0, util_1.bnToBn)(setValues[key])).eq((0, util_1.bnToBn)(setValues[key]))) { | ||
super(decodeSet(setValues, value, bitLength)); | ||
_CodecSet_allowed.set(this, void 0); | ||
_CodecSet_byteLength.set(this, void 0); | ||
/** | ||
@@ -88,3 +85,3 @@ * @description adds a value to the Set (extended to allow for validity checking) | ||
// in the Set constructor (so it is undefined at this point, and should allow) | ||
if (tslib_1.__classPrivateFieldGet(this, _CodecSet_allowed, "f") && (0, util_1.isUndefined)(tslib_1.__classPrivateFieldGet(this, _CodecSet_allowed, "f")[key])) { | ||
if (this.__internal__allowed && (0, util_1.isUndefined)(this.__internal__allowed[key])) { | ||
throw new Error(`Set: Invalid key '${key}' on add`); | ||
@@ -96,4 +93,4 @@ } | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _CodecSet_allowed, setValues, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _CodecSet_byteLength, bitLength / 8, "f"); | ||
this.__internal__allowed = setValues; | ||
this.__internal__byteLength = bitLength / 8; | ||
} | ||
@@ -109,4 +106,5 @@ static with(values, bitLength) { | ||
const keys = Object.keys(values); | ||
const isKeys = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const count = keys.length; | ||
const isKeys = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
isKeys[i] = `is${(0, util_1.stringPascalCase)(keys[i])}`; | ||
@@ -122,3 +120,3 @@ } | ||
get encodedLength() { | ||
return tslib_1.__classPrivateFieldGet(this, _CodecSet_byteLength, "f"); | ||
return this.__internal__byteLength; | ||
} | ||
@@ -147,3 +145,3 @@ /** | ||
get valueEncoded() { | ||
return encodeSet(tslib_1.__classPrivateFieldGet(this, _CodecSet_allowed, "f"), this.strings); | ||
return encodeSet(this.__internal__allowed, this.strings); | ||
} | ||
@@ -208,3 +206,3 @@ /** | ||
toRawType() { | ||
return (0, util_1.stringify)({ _set: tslib_1.__classPrivateFieldGet(this, _CodecSet_allowed, "f") }); | ||
return (0, util_1.stringify)({ _set: this.__internal__allowed }); | ||
} | ||
@@ -222,3 +220,3 @@ /** | ||
return (0, util_1.bnToU8a)(this.valueEncoded, { | ||
bitLength: tslib_1.__classPrivateFieldGet(this, _CodecSet_byteLength, "f") * 8, | ||
bitLength: this.__internal__byteLength * 8, | ||
isLe: true | ||
@@ -229,2 +227,1 @@ }); | ||
exports.CodecSet = CodecSet; | ||
_CodecSet_allowed = new WeakMap(), _CodecSet_byteLength = new WeakMap(); |
"use strict"; | ||
var _Struct_jsonMap, _Struct_Types; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Struct = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -16,10 +14,11 @@ const index_js_1 = require("../utils/index.js"); | ||
const typeofMap = value instanceof Map; | ||
const count = keys.length; | ||
if (!typeofArray && !typeofMap && !(0, util_1.isObject)(value)) { | ||
throw new Error(`Struct: Cannot decode value ${(0, util_1.stringify)(value)} (typeof ${typeof value}), expected an input object, map or array`); | ||
} | ||
else if (typeofArray && value.length !== keys.length) { | ||
else if (typeofArray && value.length !== count) { | ||
throw new Error(`Struct: Unable to map ${(0, util_1.stringify)(value)} array to object with known keys ${keys.join(', ')}`); | ||
} | ||
const raw = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const raw = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const key = keys[i]; | ||
@@ -42,3 +41,3 @@ const jsonKey = jsonMap.get(key) || key; | ||
jsonObj = {}; | ||
for (let e = 0; e < entries.length; e++) { | ||
for (let e = 0, ecount = entries.length; e < ecount; e++) { | ||
jsonObj[(0, util_1.stringCamelCase)(entries[e][0])] = entries[e][1]; | ||
@@ -89,8 +88,6 @@ } | ||
super(decoded); | ||
_Struct_jsonMap.set(this, void 0); | ||
_Struct_Types.set(this, void 0); | ||
this.initialU8aLength = decodedLength; | ||
this.registry = registry; | ||
tslib_1.__classPrivateFieldSet(this, _Struct_jsonMap, jsonMap, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _Struct_Types, typeMap, "f"); | ||
this.__internal__jsonMap = jsonMap; | ||
this.__internal__Types = typeMap; | ||
} | ||
@@ -117,3 +114,3 @@ static with(Types, jsonMap) { | ||
get defKeys() { | ||
return tslib_1.__classPrivateFieldGet(this, _Struct_Types, "f")[1]; | ||
return this.__internal__Types[1]; | ||
} | ||
@@ -152,4 +149,4 @@ /** | ||
const result = {}; | ||
const [Types, keys] = tslib_1.__classPrivateFieldGet(this, _Struct_Types, "f"); | ||
for (let i = 0; i < keys.length; i++) { | ||
const [Types, keys] = this.__internal__Types; | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
result[keys[i]] = new Types[i](this.registry).toRawType(); | ||
@@ -231,3 +228,3 @@ } | ||
// since this representation goes over RPC and needs to be correct | ||
json[(tslib_1.__classPrivateFieldGet(this, _Struct_jsonMap, "f").get(k) || k)] = v.toJSON(); | ||
json[(this.__internal__jsonMap.get(k) || k)] = v.toJSON(); | ||
} | ||
@@ -250,3 +247,3 @@ return json; | ||
toRawType() { | ||
return (0, util_1.stringify)((0, index_js_1.typesToMap)(this.registry, tslib_1.__classPrivateFieldGet(this, _Struct_Types, "f"))); | ||
return (0, util_1.stringify)((0, index_js_1.typesToMap)(this.registry, this.__internal__Types)); | ||
} | ||
@@ -274,2 +271,1 @@ /** | ||
exports.Struct = Struct; | ||
_Struct_jsonMap = new WeakMap(), _Struct_Types = new WeakMap(); |
"use strict"; | ||
var _Text_override; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Text = void 0; | ||
const tslib_1 = require("tslib"); | ||
const util_1 = require("@polkadot/util"); | ||
@@ -47,3 +45,3 @@ const Raw_js_1 = require("./Raw.js"); | ||
super(str); | ||
_Text_override.set(this, null); | ||
this.__internal__override = null; | ||
this.registry = registry; | ||
@@ -100,3 +98,3 @@ this.initialU8aLength = decodedLength; | ||
setOverride(override) { | ||
tslib_1.__classPrivateFieldSet(this, _Text_override, override, "f"); | ||
this.__internal__override = override; | ||
} | ||
@@ -139,3 +137,3 @@ /** | ||
toString() { | ||
return tslib_1.__classPrivateFieldGet(this, _Text_override, "f") || super.toString(); | ||
return this.__internal__override || super.toString(); | ||
} | ||
@@ -156,2 +154,1 @@ /** | ||
exports.Text = Text; | ||
_Text_override = new WeakMap(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.packageInfo = void 0; | ||
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.4.1' }; | ||
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.5.1' }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.USize = exports.usize = exports.U256 = exports.u256 = exports.U128 = exports.u128 = exports.U64 = exports.u64 = exports.U32 = exports.u32 = exports.U16 = exports.u16 = exports.U8 = exports.u8 = exports.ISize = exports.isize = exports.I256 = exports.i256 = exports.I128 = exports.i128 = exports.I64 = exports.i64 = exports.I32 = exports.i32 = exports.I16 = exports.i16 = exports.I8 = exports.i8 = exports.F64 = exports.f64 = exports.F32 = exports.f32 = void 0; | ||
exports.usize = exports.USize = exports.u256 = exports.U256 = exports.u128 = exports.U128 = exports.u64 = exports.U64 = exports.u32 = exports.U32 = exports.u16 = exports.U16 = exports.u8 = exports.U8 = exports.isize = exports.ISize = exports.i256 = exports.I256 = exports.i128 = exports.I128 = exports.i64 = exports.I64 = exports.i32 = exports.I32 = exports.i16 = exports.I16 = exports.i8 = exports.I8 = exports.f64 = exports.F64 = exports.f32 = exports.F32 = void 0; | ||
var F32_js_1 = require("./F32.js"); | ||
Object.defineProperty(exports, "F32", { enumerable: true, get: function () { return F32_js_1.f32; } }); | ||
Object.defineProperty(exports, "f32", { enumerable: true, get: function () { return F32_js_1.f32; } }); | ||
Object.defineProperty(exports, "F32", { enumerable: true, get: function () { return F32_js_1.f32; } }); | ||
var F64_js_1 = require("./F64.js"); | ||
Object.defineProperty(exports, "F64", { enumerable: true, get: function () { return F64_js_1.f64; } }); | ||
Object.defineProperty(exports, "f64", { enumerable: true, get: function () { return F64_js_1.f64; } }); | ||
Object.defineProperty(exports, "F64", { enumerable: true, get: function () { return F64_js_1.f64; } }); | ||
var I8_js_1 = require("./I8.js"); | ||
Object.defineProperty(exports, "I8", { enumerable: true, get: function () { return I8_js_1.i8; } }); | ||
Object.defineProperty(exports, "i8", { enumerable: true, get: function () { return I8_js_1.i8; } }); | ||
Object.defineProperty(exports, "I8", { enumerable: true, get: function () { return I8_js_1.i8; } }); | ||
var I16_js_1 = require("./I16.js"); | ||
Object.defineProperty(exports, "I16", { enumerable: true, get: function () { return I16_js_1.i16; } }); | ||
Object.defineProperty(exports, "i16", { enumerable: true, get: function () { return I16_js_1.i16; } }); | ||
Object.defineProperty(exports, "I16", { enumerable: true, get: function () { return I16_js_1.i16; } }); | ||
var I32_js_1 = require("./I32.js"); | ||
Object.defineProperty(exports, "I32", { enumerable: true, get: function () { return I32_js_1.i32; } }); | ||
Object.defineProperty(exports, "i32", { enumerable: true, get: function () { return I32_js_1.i32; } }); | ||
Object.defineProperty(exports, "I32", { enumerable: true, get: function () { return I32_js_1.i32; } }); | ||
var I64_js_1 = require("./I64.js"); | ||
Object.defineProperty(exports, "I64", { enumerable: true, get: function () { return I64_js_1.i64; } }); | ||
Object.defineProperty(exports, "i64", { enumerable: true, get: function () { return I64_js_1.i64; } }); | ||
Object.defineProperty(exports, "I64", { enumerable: true, get: function () { return I64_js_1.i64; } }); | ||
var I128_js_1 = require("./I128.js"); | ||
Object.defineProperty(exports, "I128", { enumerable: true, get: function () { return I128_js_1.i128; } }); | ||
Object.defineProperty(exports, "i128", { enumerable: true, get: function () { return I128_js_1.i128; } }); | ||
Object.defineProperty(exports, "I128", { enumerable: true, get: function () { return I128_js_1.i128; } }); | ||
var I256_js_1 = require("./I256.js"); | ||
Object.defineProperty(exports, "I256", { enumerable: true, get: function () { return I256_js_1.i256; } }); | ||
Object.defineProperty(exports, "i256", { enumerable: true, get: function () { return I256_js_1.i256; } }); | ||
Object.defineProperty(exports, "I256", { enumerable: true, get: function () { return I256_js_1.i256; } }); | ||
var ISize_js_1 = require("./ISize.js"); | ||
Object.defineProperty(exports, "ISize", { enumerable: true, get: function () { return ISize_js_1.isize; } }); | ||
Object.defineProperty(exports, "isize", { enumerable: true, get: function () { return ISize_js_1.isize; } }); | ||
Object.defineProperty(exports, "ISize", { enumerable: true, get: function () { return ISize_js_1.isize; } }); | ||
var U8_js_1 = require("./U8.js"); | ||
Object.defineProperty(exports, "U8", { enumerable: true, get: function () { return U8_js_1.u8; } }); | ||
Object.defineProperty(exports, "u8", { enumerable: true, get: function () { return U8_js_1.u8; } }); | ||
Object.defineProperty(exports, "U8", { enumerable: true, get: function () { return U8_js_1.u8; } }); | ||
var U16_js_1 = require("./U16.js"); | ||
Object.defineProperty(exports, "U16", { enumerable: true, get: function () { return U16_js_1.u16; } }); | ||
Object.defineProperty(exports, "u16", { enumerable: true, get: function () { return U16_js_1.u16; } }); | ||
Object.defineProperty(exports, "U16", { enumerable: true, get: function () { return U16_js_1.u16; } }); | ||
var U32_js_1 = require("./U32.js"); | ||
Object.defineProperty(exports, "U32", { enumerable: true, get: function () { return U32_js_1.u32; } }); | ||
Object.defineProperty(exports, "u32", { enumerable: true, get: function () { return U32_js_1.u32; } }); | ||
Object.defineProperty(exports, "U32", { enumerable: true, get: function () { return U32_js_1.u32; } }); | ||
var U64_js_1 = require("./U64.js"); | ||
Object.defineProperty(exports, "U64", { enumerable: true, get: function () { return U64_js_1.u64; } }); | ||
Object.defineProperty(exports, "u64", { enumerable: true, get: function () { return U64_js_1.u64; } }); | ||
Object.defineProperty(exports, "U64", { enumerable: true, get: function () { return U64_js_1.u64; } }); | ||
var U128_js_1 = require("./U128.js"); | ||
Object.defineProperty(exports, "U128", { enumerable: true, get: function () { return U128_js_1.u128; } }); | ||
Object.defineProperty(exports, "u128", { enumerable: true, get: function () { return U128_js_1.u128; } }); | ||
Object.defineProperty(exports, "U128", { enumerable: true, get: function () { return U128_js_1.u128; } }); | ||
var U256_js_1 = require("./U256.js"); | ||
Object.defineProperty(exports, "U256", { enumerable: true, get: function () { return U256_js_1.u256; } }); | ||
Object.defineProperty(exports, "u256", { enumerable: true, get: function () { return U256_js_1.u256; } }); | ||
Object.defineProperty(exports, "U256", { enumerable: true, get: function () { return U256_js_1.u256; } }); | ||
var USize_js_1 = require("./USize.js"); | ||
Object.defineProperty(exports, "USize", { enumerable: true, get: function () { return USize_js_1.usize; } }); | ||
Object.defineProperty(exports, "usize", { enumerable: true, get: function () { return USize_js_1.usize; } }); | ||
Object.defineProperty(exports, "USize", { enumerable: true, get: function () { return USize_js_1.usize; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.typesToMap = exports.sortMap = exports.sortSet = exports.sortAsc = exports.sanitize = exports.typeToConstructor = exports.mapToTypeMap = exports.decodeU8aVec = exports.decodeU8aStruct = exports.decodeU8a = exports.compareSet = exports.compareMap = exports.compareArray = void 0; | ||
exports.typesToMap = exports.typeToConstructor = exports.typesToConstructors = exports.mapToTypeMap = exports.sortSet = exports.sortMap = exports.sortAsc = exports.sanitize = exports.decodeU8aVec = exports.decodeU8aStruct = exports.decodeU8a = exports.compareSet = exports.compareMap = exports.compareArray = void 0; | ||
var compareArray_js_1 = require("./compareArray.js"); | ||
@@ -14,6 +14,2 @@ Object.defineProperty(exports, "compareArray", { enumerable: true, get: function () { return compareArray_js_1.compareArray; } }); | ||
Object.defineProperty(exports, "decodeU8aVec", { enumerable: true, get: function () { return decodeU8a_js_1.decodeU8aVec; } }); | ||
var mapToTypeMap_js_1 = require("./mapToTypeMap.js"); | ||
Object.defineProperty(exports, "mapToTypeMap", { enumerable: true, get: function () { return mapToTypeMap_js_1.mapToTypeMap; } }); | ||
var typeToConstructor_js_1 = require("./typeToConstructor.js"); | ||
Object.defineProperty(exports, "typeToConstructor", { enumerable: true, get: function () { return typeToConstructor_js_1.typeToConstructor; } }); | ||
var sanitize_js_1 = require("./sanitize.js"); | ||
@@ -23,5 +19,9 @@ Object.defineProperty(exports, "sanitize", { enumerable: true, get: function () { return sanitize_js_1.sanitize; } }); | ||
Object.defineProperty(exports, "sortAsc", { enumerable: true, get: function () { return sortValues_js_1.sortAsc; } }); | ||
Object.defineProperty(exports, "sortMap", { enumerable: true, get: function () { return sortValues_js_1.sortMap; } }); | ||
Object.defineProperty(exports, "sortSet", { enumerable: true, get: function () { return sortValues_js_1.sortSet; } }); | ||
Object.defineProperty(exports, "sortMap", { enumerable: true, get: function () { return sortValues_js_1.sortMap; } }); | ||
var toConstructors_js_1 = require("./toConstructors.js"); | ||
Object.defineProperty(exports, "mapToTypeMap", { enumerable: true, get: function () { return toConstructors_js_1.mapToTypeMap; } }); | ||
Object.defineProperty(exports, "typesToConstructors", { enumerable: true, get: function () { return toConstructors_js_1.typesToConstructors; } }); | ||
Object.defineProperty(exports, "typeToConstructor", { enumerable: true, get: function () { return toConstructors_js_1.typeToConstructor; } }); | ||
var typesToMap_js_1 = require("./typesToMap.js"); | ||
Object.defineProperty(exports, "typesToMap", { enumerable: true, get: function () { return typesToMap_js_1.typesToMap; } }); |
@@ -51,10 +51,10 @@ "use strict"; | ||
let depth = 0; | ||
for (let index = start; index < value.length; index++) { | ||
if (value[index] === '>') { | ||
for (let i = start, count = value.length; i < count; i++) { | ||
if (value[i] === '>') { | ||
if (!depth) { | ||
return index; | ||
return i; | ||
} | ||
depth--; | ||
} | ||
else if (value[index] === '<') { | ||
else if (value[i] === '<') { | ||
depth++; | ||
@@ -80,7 +80,7 @@ } | ||
if (value.includes(' as HasCompact')) { | ||
for (let index = 0; index < value.length; index++) { | ||
if (value[index] === '<') { | ||
const end = findClosing(value, index + 1) - 14; | ||
for (let i = 0, count = value.length; i < count; i++) { | ||
if (value[i] === '<') { | ||
const end = findClosing(value, i + 1) - 14; | ||
if (value.substring(end, end + 14) === ' as HasCompact') { | ||
value = `Compact<${value.substring(index + 1, end)}>`; | ||
value = `Compact<${value.substring(i + 1, end)}>`; | ||
} | ||
@@ -121,3 +121,3 @@ } | ||
return (value) => { | ||
for (let i = 0; i < BOUNDED.length; i++) { | ||
for (let i = 0, count = BOUNDED.length; i < count; i++) { | ||
const tag = BOUNDED[i]; | ||
@@ -161,9 +161,9 @@ value = replaceTagWith(value, `${type}${tag}<`, (v) => { | ||
return (value) => { | ||
for (let index = 0; index < value.length; index++) { | ||
if (value[index] === '<') { | ||
for (let i = 0, count = value.length; i < count; i++) { | ||
if (value[i] === '<') { | ||
// check against the allowed wrappers, be it Vec<..>, Option<...> ... | ||
const box = ALLOWED_BOXES.find((box) => { | ||
const start = index - box.length; | ||
const start = i - box.length; | ||
return ((start >= 0 && | ||
value.substring(start, index) === box) && ( | ||
value.substring(start, i) === box) && ( | ||
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...> | ||
@@ -175,4 +175,4 @@ start === 0 || | ||
if (!box) { | ||
const end = findClosing(value, index + 1); | ||
value = `${value.substring(0, index)}${value.substring(end + 1)}`; | ||
const end = findClosing(value, i + 1); | ||
value = `${value.substring(0, i)}${value.substring(end + 1)}`; | ||
} | ||
@@ -233,3 +233,3 @@ } | ||
let result = startValue; | ||
for (let i = 0; i < mappings.length; i++) { | ||
for (let i = 0, count = mappings.length; i < count; i++) { | ||
result = mappings[i](result); | ||
@@ -236,0 +236,0 @@ } |
@@ -10,8 +10,4 @@ "use strict"; | ||
/** @internal **/ | ||
function isCodec(arg) { | ||
return (0, util_1.isFunction)(arg && arg.toU8a); | ||
} | ||
/** @internal **/ | ||
function isEnum(arg) { | ||
return isCodec(arg) && (0, util_1.isNumber)(arg.index) && isCodec(arg.value); | ||
return (0, util_1.isCodec)(arg) && (0, util_1.isNumber)(arg.index) && (0, util_1.isCodec)(arg.value); | ||
} | ||
@@ -53,3 +49,3 @@ /** @internal */ | ||
} | ||
else if (isCodec(a) && isCodec(b)) { | ||
else if ((0, util_1.isCodec)(a) && (0, util_1.isCodec)(b)) { | ||
// Text, Bool etc. | ||
@@ -56,0 +52,0 @@ return sortAsc(a.toU8a(true), b.toU8a(true)); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const result = {}; | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType(); | ||
@@ -9,0 +9,0 @@ } |
@@ -1,3 +0,1 @@ | ||
var _BitVec_decodedLength, _BitVec_isMsb; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactFromU8aLim, compactToU8a, isString, u8aConcatStrict, u8aToU8a } from '@polkadot/util'; | ||
@@ -39,6 +37,4 @@ import { Raw } from '../native/Raw.js'; | ||
super(registry, u8a); | ||
_BitVec_decodedLength.set(this, void 0); | ||
_BitVec_isMsb.set(this, void 0); | ||
__classPrivateFieldSet(this, _BitVec_decodedLength, decodedLength, "f"); | ||
__classPrivateFieldSet(this, _BitVec_isMsb, isMsb, "f"); | ||
this.__internal__decodedLength = decodedLength; | ||
this.__internal__isMsb = isMsb; | ||
} | ||
@@ -49,3 +45,3 @@ /** | ||
get encodedLength() { | ||
return this.length + compactToU8a(__classPrivateFieldGet(this, _BitVec_decodedLength, "f")).length; | ||
return this.length + compactToU8a(this.__internal__decodedLength).length; | ||
} | ||
@@ -57,3 +53,3 @@ /** | ||
return { | ||
outer: [compactToU8a(__classPrivateFieldGet(this, _BitVec_decodedLength, "f")), super.toU8a()] | ||
outer: [compactToU8a(this.__internal__decodedLength), super.toU8a()] | ||
}; | ||
@@ -75,8 +71,9 @@ } | ||
]); | ||
const result = new Array(8 * map.length); | ||
for (let i = 0; i < map.length; i++) { | ||
const count = map.length; | ||
const result = new Array(8 * count); | ||
for (let i = 0; i < count; i++) { | ||
const off = i * 8; | ||
const v = map[i]; | ||
for (let j = 0; j < 8; j++) { | ||
result[off + j] = __classPrivateFieldGet(this, _BitVec_isMsb, "f") | ||
result[off + j] = this.__internal__isMsb | ||
? v[j] | ||
@@ -94,3 +91,3 @@ : v[7 - j]; | ||
.map((d) => `00000000${d.toString(2)}`.slice(-8)) | ||
.map((s) => __classPrivateFieldGet(this, _BitVec_isMsb, "f") ? s : s.split('').reverse().join('')) | ||
.map((s) => this.__internal__isMsb ? s : s.split('').reverse().join('')) | ||
.join('_')}`; | ||
@@ -112,5 +109,4 @@ } | ||
? bitVec | ||
: u8aConcatStrict([compactToU8a(__classPrivateFieldGet(this, _BitVec_decodedLength, "f")), bitVec]); | ||
: u8aConcatStrict([compactToU8a(this.__internal__decodedLength), bitVec]); | ||
} | ||
} | ||
_BitVec_decodedLength = new WeakMap(), _BitVec_isMsb = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _BTreeSet_ValClass; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
@@ -62,6 +60,5 @@ import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils/index.js'; | ||
super(sortSet(values)); | ||
_BTreeSet_ValClass.set(this, void 0); | ||
this.registry = registry; | ||
this.initialU8aLength = decodedLength; | ||
__classPrivateFieldSet(this, _BTreeSet_ValClass, ValClass, "f"); | ||
this.__internal__ValClass = ValClass; | ||
} | ||
@@ -152,3 +149,3 @@ static with(valType) { | ||
toRawType() { | ||
return `BTreeSet<${this.registry.getClassName(__classPrivateFieldGet(this, _BTreeSet_ValClass, "f")) || new (__classPrivateFieldGet(this, _BTreeSet_ValClass, "f"))(this.registry).toRawType()}>`; | ||
return `BTreeSet<${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`; | ||
} | ||
@@ -186,2 +183,1 @@ /** | ||
} | ||
_BTreeSet_ValClass = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _CodecMap_KeyClass, _CodecMap_ValClass, _CodecMap_type; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
@@ -19,3 +17,3 @@ import { AbstractArray } from '../abstract/Array.js'; | ||
const [values, decodedLength] = decodeU8a(registry, new Array(types.length), u8a.subarray(offset), [types, []]); | ||
for (let i = 0; i < values.length; i += 2) { | ||
for (let i = 0, count = values.length; i < count; i += 2) { | ||
output.set(values[i], values[i + 1]); | ||
@@ -82,10 +80,7 @@ } | ||
super(type === 'BTreeMap' ? sortMap(decoded) : decoded); | ||
_CodecMap_KeyClass.set(this, void 0); | ||
_CodecMap_ValClass.set(this, void 0); | ||
_CodecMap_type.set(this, void 0); | ||
this.registry = registry; | ||
this.initialU8aLength = decodedLength; | ||
__classPrivateFieldSet(this, _CodecMap_KeyClass, KeyClass, "f"); | ||
__classPrivateFieldSet(this, _CodecMap_ValClass, ValClass, "f"); | ||
__classPrivateFieldSet(this, _CodecMap_type, type, "f"); | ||
this.__internal__KeyClass = KeyClass; | ||
this.__internal__ValClass = ValClass; | ||
this.__internal__type = type; | ||
} | ||
@@ -178,3 +173,3 @@ /** | ||
toRawType() { | ||
return `${__classPrivateFieldGet(this, _CodecMap_type, "f")}<${this.registry.getClassName(__classPrivateFieldGet(this, _CodecMap_KeyClass, "f")) || new (__classPrivateFieldGet(this, _CodecMap_KeyClass, "f"))(this.registry).toRawType()},${this.registry.getClassName(__classPrivateFieldGet(this, _CodecMap_ValClass, "f")) || new (__classPrivateFieldGet(this, _CodecMap_ValClass, "f"))(this.registry).toRawType()}>`; | ||
return `${this.__internal__type}<${this.registry.getClassName(this.__internal__KeyClass) || new this.__internal__KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`; | ||
} | ||
@@ -202,2 +197,1 @@ /** | ||
} | ||
_CodecMap_KeyClass = new WeakMap(), _CodecMap_ValClass = new WeakMap(), _CodecMap_type = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _Range_rangeName; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { Tuple } from '../base/Tuple.js'; | ||
@@ -12,4 +10,3 @@ /** | ||
super(registry, [Type, Type], value); | ||
_Range_rangeName.set(this, void 0); | ||
__classPrivateFieldSet(this, _Range_rangeName, rangeName, "f"); | ||
this.__internal__rangeName = rangeName; | ||
} | ||
@@ -39,5 +36,4 @@ static with(Type) { | ||
toRawType() { | ||
return `${__classPrivateFieldGet(this, _Range_rangeName, "f")}<${this.start.toRawType()}>`; | ||
return `${this.__internal__rangeName}<${this.start.toRawType()}>`; | ||
} | ||
} | ||
_Range_rangeName = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _WrapperKeepOpaque_Type, _WrapperKeepOpaque_decoded, _WrapperKeepOpaque_opaqueName; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util'; | ||
@@ -29,8 +27,5 @@ import { Raw } from '../native/Raw.js'; | ||
super(registry, u8a); | ||
_WrapperKeepOpaque_Type.set(this, void 0); | ||
_WrapperKeepOpaque_decoded.set(this, void 0); | ||
_WrapperKeepOpaque_opaqueName.set(this, void 0); | ||
__classPrivateFieldSet(this, _WrapperKeepOpaque_Type, Type, "f"); | ||
__classPrivateFieldSet(this, _WrapperKeepOpaque_decoded, decoded, "f"); | ||
__classPrivateFieldSet(this, _WrapperKeepOpaque_opaqueName, opaqueName, "f"); | ||
this.__internal__Type = Type; | ||
this.__internal__decoded = decoded; | ||
this.__internal__opaqueName = opaqueName; | ||
} | ||
@@ -48,3 +43,3 @@ static with(Type) { | ||
get isDecoded() { | ||
return !!__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f"); | ||
return !!this.__internal__decoded; | ||
} | ||
@@ -55,5 +50,5 @@ /** | ||
inspect() { | ||
return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
return this.__internal__decoded | ||
? { | ||
inner: [__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").inspect()], | ||
inner: [this.__internal__decoded.inspect()], | ||
outer: [compactToU8a(this.length)] | ||
@@ -69,4 +64,4 @@ } | ||
toHuman(isExtended) { | ||
return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toHuman(isExtended) | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toHuman(isExtended) | ||
: super.toHuman(); | ||
@@ -78,4 +73,4 @@ } | ||
toPrimitive() { | ||
return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toPrimitive() | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toPrimitive() | ||
: super.toPrimitive(); | ||
@@ -87,3 +82,3 @@ } | ||
toRawType() { | ||
return `${__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}<${this.registry.getClassName(__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f")) || (__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") ? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toRawType() : new (__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f"))(this.registry).toRawType())}>`; | ||
return `${this.__internal__opaqueName}<${this.registry.getClassName(this.__internal__Type) || (this.__internal__decoded ? this.__internal__decoded.toRawType() : new this.__internal__Type(this.registry).toRawType())}>`; | ||
} | ||
@@ -94,4 +89,4 @@ /** | ||
toString() { | ||
return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") | ||
? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toString() | ||
return this.__internal__decoded | ||
? this.__internal__decoded.toString() | ||
: super.toString(); | ||
@@ -103,8 +98,7 @@ } | ||
unwrap() { | ||
if (!__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")) { | ||
throw new Error(`${__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}: unwrapping an undecodable value`); | ||
if (!this.__internal__decoded) { | ||
throw new Error(`${this.__internal__opaqueName}: unwrapping an undecodable value`); | ||
} | ||
return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f"); | ||
return this.__internal__decoded; | ||
} | ||
} | ||
_WrapperKeepOpaque_Type = new WeakMap(), _WrapperKeepOpaque_decoded = new WeakMap(), _WrapperKeepOpaque_opaqueName = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _Float_bitLength; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
@@ -19,4 +17,3 @@ /** | ||
: (value || 0)); | ||
_Float_bitLength.set(this, void 0); | ||
__classPrivateFieldSet(this, _Float_bitLength, bitLength, "f"); | ||
this.__internal__bitLength = bitLength; | ||
this.encodedLength = bitLength / 8; | ||
@@ -95,3 +92,3 @@ this.initialU8aLength = this.encodedLength; | ||
toRawType() { | ||
return `f${__classPrivateFieldGet(this, _Float_bitLength, "f")}`; | ||
return `f${this.__internal__bitLength}`; | ||
} | ||
@@ -103,6 +100,5 @@ /** | ||
return floatToU8a(this, { | ||
bitLength: __classPrivateFieldGet(this, _Float_bitLength, "f") | ||
bitLength: this.__internal__bitLength | ||
}); | ||
} | ||
} | ||
_Float_bitLength = new WeakMap(); |
@@ -1,2 +0,2 @@ | ||
export { bool, bool as Bool } from './Bool.js'; | ||
export { bool as Bool, bool } from './Bool.js'; | ||
export { CodecDate, CodecDate as Date } from './Date.js'; | ||
@@ -3,0 +3,0 @@ export { Float } from './Float.js'; |
@@ -1,2 +0,2 @@ | ||
export { bool, bool as Bool } from './Bool.js'; | ||
export { bool as Bool, bool } from './Bool.js'; | ||
export { CodecDate, CodecDate as Date } from './Date.js'; | ||
@@ -3,0 +3,0 @@ export { Float } from './Float.js'; |
@@ -1,3 +0,1 @@ | ||
var _CodecSet_allowed, _CodecSet_byteLength; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
@@ -7,3 +5,3 @@ import { compareArray } from '../utils/index.js'; | ||
const encoded = new BN(0); | ||
for (let i = 0; i < values.length; i++) { | ||
for (let i = 0, count = values.length; i < count; i++) { | ||
encoded.ior(bnToBn(setValues[values[i]] || 0)); | ||
@@ -15,4 +13,5 @@ } | ||
function decodeSetArray(setValues, values) { | ||
const result = new Array(values.length); | ||
for (let i = 0; i < values.length; i++) { | ||
const count = values.length; | ||
const result = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const key = values[i]; | ||
@@ -31,3 +30,3 @@ if (isUndefined(setValues[key])) { | ||
const result = []; | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
const key = keys[i]; | ||
@@ -75,4 +74,2 @@ if (bn.and(bnToBn(setValues[key])).eq(bnToBn(setValues[key]))) { | ||
super(decodeSet(setValues, value, bitLength)); | ||
_CodecSet_allowed.set(this, void 0); | ||
_CodecSet_byteLength.set(this, void 0); | ||
/** | ||
@@ -85,3 +82,3 @@ * @description adds a value to the Set (extended to allow for validity checking) | ||
// in the Set constructor (so it is undefined at this point, and should allow) | ||
if (__classPrivateFieldGet(this, _CodecSet_allowed, "f") && isUndefined(__classPrivateFieldGet(this, _CodecSet_allowed, "f")[key])) { | ||
if (this.__internal__allowed && isUndefined(this.__internal__allowed[key])) { | ||
throw new Error(`Set: Invalid key '${key}' on add`); | ||
@@ -93,4 +90,4 @@ } | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _CodecSet_allowed, setValues, "f"); | ||
__classPrivateFieldSet(this, _CodecSet_byteLength, bitLength / 8, "f"); | ||
this.__internal__allowed = setValues; | ||
this.__internal__byteLength = bitLength / 8; | ||
} | ||
@@ -106,4 +103,5 @@ static with(values, bitLength) { | ||
const keys = Object.keys(values); | ||
const isKeys = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const count = keys.length; | ||
const isKeys = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
isKeys[i] = `is${stringPascalCase(keys[i])}`; | ||
@@ -119,3 +117,3 @@ } | ||
get encodedLength() { | ||
return __classPrivateFieldGet(this, _CodecSet_byteLength, "f"); | ||
return this.__internal__byteLength; | ||
} | ||
@@ -144,3 +142,3 @@ /** | ||
get valueEncoded() { | ||
return encodeSet(__classPrivateFieldGet(this, _CodecSet_allowed, "f"), this.strings); | ||
return encodeSet(this.__internal__allowed, this.strings); | ||
} | ||
@@ -205,3 +203,3 @@ /** | ||
toRawType() { | ||
return stringify({ _set: __classPrivateFieldGet(this, _CodecSet_allowed, "f") }); | ||
return stringify({ _set: this.__internal__allowed }); | ||
} | ||
@@ -219,3 +217,3 @@ /** | ||
return bnToU8a(this.valueEncoded, { | ||
bitLength: __classPrivateFieldGet(this, _CodecSet_byteLength, "f") * 8, | ||
bitLength: this.__internal__byteLength * 8, | ||
isLe: true | ||
@@ -225,2 +223,1 @@ }); | ||
} | ||
_CodecSet_allowed = new WeakMap(), _CodecSet_byteLength = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _Struct_jsonMap, _Struct_Types; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; | ||
@@ -13,10 +11,11 @@ import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils/index.js'; | ||
const typeofMap = value instanceof Map; | ||
const count = keys.length; | ||
if (!typeofArray && !typeofMap && !isObject(value)) { | ||
throw new Error(`Struct: Cannot decode value ${stringify(value)} (typeof ${typeof value}), expected an input object, map or array`); | ||
} | ||
else if (typeofArray && value.length !== keys.length) { | ||
else if (typeofArray && value.length !== count) { | ||
throw new Error(`Struct: Unable to map ${stringify(value)} array to object with known keys ${keys.join(', ')}`); | ||
} | ||
const raw = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const raw = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
const key = keys[i]; | ||
@@ -39,3 +38,3 @@ const jsonKey = jsonMap.get(key) || key; | ||
jsonObj = {}; | ||
for (let e = 0; e < entries.length; e++) { | ||
for (let e = 0, ecount = entries.length; e < ecount; e++) { | ||
jsonObj[stringCamelCase(entries[e][0])] = entries[e][1]; | ||
@@ -86,8 +85,6 @@ } | ||
super(decoded); | ||
_Struct_jsonMap.set(this, void 0); | ||
_Struct_Types.set(this, void 0); | ||
this.initialU8aLength = decodedLength; | ||
this.registry = registry; | ||
__classPrivateFieldSet(this, _Struct_jsonMap, jsonMap, "f"); | ||
__classPrivateFieldSet(this, _Struct_Types, typeMap, "f"); | ||
this.__internal__jsonMap = jsonMap; | ||
this.__internal__Types = typeMap; | ||
} | ||
@@ -114,3 +111,3 @@ static with(Types, jsonMap) { | ||
get defKeys() { | ||
return __classPrivateFieldGet(this, _Struct_Types, "f")[1]; | ||
return this.__internal__Types[1]; | ||
} | ||
@@ -149,4 +146,4 @@ /** | ||
const result = {}; | ||
const [Types, keys] = __classPrivateFieldGet(this, _Struct_Types, "f"); | ||
for (let i = 0; i < keys.length; i++) { | ||
const [Types, keys] = this.__internal__Types; | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
result[keys[i]] = new Types[i](this.registry).toRawType(); | ||
@@ -228,3 +225,3 @@ } | ||
// since this representation goes over RPC and needs to be correct | ||
json[(__classPrivateFieldGet(this, _Struct_jsonMap, "f").get(k) || k)] = v.toJSON(); | ||
json[(this.__internal__jsonMap.get(k) || k)] = v.toJSON(); | ||
} | ||
@@ -247,3 +244,3 @@ return json; | ||
toRawType() { | ||
return stringify(typesToMap(this.registry, __classPrivateFieldGet(this, _Struct_Types, "f"))); | ||
return stringify(typesToMap(this.registry, this.__internal__Types)); | ||
} | ||
@@ -270,2 +267,1 @@ /** | ||
} | ||
_Struct_jsonMap = new WeakMap(), _Struct_Types = new WeakMap(); |
@@ -1,3 +0,1 @@ | ||
var _Text_override; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util'; | ||
@@ -44,3 +42,3 @@ import { Raw } from './Raw.js'; | ||
super(str); | ||
_Text_override.set(this, null); | ||
this.__internal__override = null; | ||
this.registry = registry; | ||
@@ -97,3 +95,3 @@ this.initialU8aLength = decodedLength; | ||
setOverride(override) { | ||
__classPrivateFieldSet(this, _Text_override, override, "f"); | ||
this.__internal__override = override; | ||
} | ||
@@ -136,3 +134,3 @@ /** | ||
toString() { | ||
return __classPrivateFieldGet(this, _Text_override, "f") || super.toString(); | ||
return this.__internal__override || super.toString(); | ||
} | ||
@@ -152,2 +150,1 @@ /** | ||
} | ||
_Text_override = new WeakMap(); |
@@ -21,3 +21,3 @@ { | ||
"type": "module", | ||
"version": "10.4.1", | ||
"version": "10.5.1", | ||
"main": "./cjs/index.js", | ||
@@ -412,7 +412,2 @@ "module": "./index.js", | ||
}, | ||
"./utils/mapToTypeMap": { | ||
"types": "./utils/mapToTypeMap.d.ts", | ||
"require": "./cjs/utils/mapToTypeMap.js", | ||
"default": "./utils/mapToTypeMap.js" | ||
}, | ||
"./utils/sanitize": { | ||
@@ -428,2 +423,7 @@ "types": "./utils/sanitize.d.ts", | ||
}, | ||
"./utils/toConstructors": { | ||
"types": "./utils/toConstructors.d.ts", | ||
"require": "./cjs/utils/toConstructors.js", | ||
"default": "./utils/toConstructors.js" | ||
}, | ||
"./utils/typesToMap": { | ||
@@ -434,7 +434,2 @@ "types": "./utils/typesToMap.d.ts", | ||
}, | ||
"./utils/typeToConstructor": { | ||
"types": "./utils/typeToConstructor.d.ts", | ||
"require": "./cjs/utils/typeToConstructor.js", | ||
"default": "./utils/typeToConstructor.js" | ||
}, | ||
"./utils/util": { | ||
@@ -447,6 +442,6 @@ "types": "./utils/util.d.ts", | ||
"dependencies": { | ||
"@polkadot/util": "^12.0.1", | ||
"@polkadot/x-bigint": "^12.0.1", | ||
"@polkadot/util": "^12.1.1", | ||
"@polkadot/x-bigint": "^12.1.1", | ||
"tslib": "^2.5.0" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.4.1' }; | ||
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.5.1' }; |
@@ -1,16 +0,16 @@ | ||
export { f32, f32 as F32 } from './F32.js'; | ||
export { f64, f64 as F64 } from './F64.js'; | ||
export { i8, i8 as I8 } from './I8.js'; | ||
export { i16, i16 as I16 } from './I16.js'; | ||
export { i32, i32 as I32 } from './I32.js'; | ||
export { i64, i64 as I64 } from './I64.js'; | ||
export { i128, i128 as I128 } from './I128.js'; | ||
export { i256, i256 as I256 } from './I256.js'; | ||
export { isize, isize as ISize } from './ISize.js'; | ||
export { u8, u8 as U8 } from './U8.js'; | ||
export { u16, u16 as U16 } from './U16.js'; | ||
export { u32, u32 as U32 } from './U32.js'; | ||
export { u64, u64 as U64 } from './U64.js'; | ||
export { u128, u128 as U128 } from './U128.js'; | ||
export { u256, u256 as U256 } from './U256.js'; | ||
export { usize, usize as USize } from './USize.js'; | ||
export { f32 as F32, f32 } from './F32.js'; | ||
export { f64 as F64, f64 } from './F64.js'; | ||
export { i8 as I8, i8 } from './I8.js'; | ||
export { i16 as I16, i16 } from './I16.js'; | ||
export { i32 as I32, i32 } from './I32.js'; | ||
export { i64 as I64, i64 } from './I64.js'; | ||
export { i128 as I128, i128 } from './I128.js'; | ||
export { i256 as I256, i256 } from './I256.js'; | ||
export { isize as ISize, isize } from './ISize.js'; | ||
export { u8 as U8, u8 } from './U8.js'; | ||
export { u16 as U16, u16 } from './U16.js'; | ||
export { u32 as U32, u32 } from './U32.js'; | ||
export { u64 as U64, u64 } from './U64.js'; | ||
export { u128 as U128, u128 } from './U128.js'; | ||
export { u256 as U256, u256 } from './U256.js'; | ||
export { usize as USize, usize } from './USize.js'; |
@@ -1,16 +0,16 @@ | ||
export { f32, f32 as F32 } from './F32.js'; | ||
export { f64, f64 as F64 } from './F64.js'; | ||
export { i8, i8 as I8 } from './I8.js'; | ||
export { i16, i16 as I16 } from './I16.js'; | ||
export { i32, i32 as I32 } from './I32.js'; | ||
export { i64, i64 as I64 } from './I64.js'; | ||
export { i128, i128 as I128 } from './I128.js'; | ||
export { i256, i256 as I256 } from './I256.js'; | ||
export { isize, isize as ISize } from './ISize.js'; | ||
export { u8, u8 as U8 } from './U8.js'; | ||
export { u16, u16 as U16 } from './U16.js'; | ||
export { u32, u32 as U32 } from './U32.js'; | ||
export { u64, u64 as U64 } from './U64.js'; | ||
export { u128, u128 as U128 } from './U128.js'; | ||
export { u256, u256 as U256 } from './U256.js'; | ||
export { usize, usize as USize } from './USize.js'; | ||
export { f32 as F32, f32 } from './F32.js'; | ||
export { f64 as F64, f64 } from './F64.js'; | ||
export { i8 as I8, i8 } from './I8.js'; | ||
export { i16 as I16, i16 } from './I16.js'; | ||
export { i32 as I32, i32 } from './I32.js'; | ||
export { i64 as I64, i64 } from './I64.js'; | ||
export { i128 as I128, i128 } from './I128.js'; | ||
export { i256 as I256, i256 } from './I256.js'; | ||
export { isize as ISize, isize } from './ISize.js'; | ||
export { u8 as U8, u8 } from './U8.js'; | ||
export { u16 as U16, u16 } from './U16.js'; | ||
export { u32 as U32, u32 } from './U32.js'; | ||
export { u64 as U64, u64 } from './U64.js'; | ||
export { u128 as U128, u128 } from './U128.js'; | ||
export { u256 as U256, u256 } from './U256.js'; | ||
export { usize as USize, usize } from './USize.js'; |
@@ -52,2 +52,3 @@ /// <reference types="bn.js" /> | ||
createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T; | ||
get(...params: never[]): any; | ||
getClassName(clazz: CodecClass): string | undefined; | ||
@@ -54,0 +55,0 @@ getOrThrow<T extends Codec = Codec, K extends string = string>(name: K, msg?: string): CodecClass<T>; |
@@ -5,6 +5,5 @@ export { compareArray } from './compareArray.js'; | ||
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a.js'; | ||
export { mapToTypeMap } from './mapToTypeMap.js'; | ||
export { typeToConstructor } from './typeToConstructor.js'; | ||
export { sanitize } from './sanitize.js'; | ||
export { sortAsc, sortSet, sortMap } from './sortValues.js'; | ||
export { sortAsc, sortMap, sortSet } from './sortValues.js'; | ||
export { mapToTypeMap, typesToConstructors, typeToConstructor } from './toConstructors.js'; | ||
export { typesToMap } from './typesToMap.js'; |
@@ -5,6 +5,5 @@ export { compareArray } from './compareArray.js'; | ||
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a.js'; | ||
export { mapToTypeMap } from './mapToTypeMap.js'; | ||
export { typeToConstructor } from './typeToConstructor.js'; | ||
export { sanitize } from './sanitize.js'; | ||
export { sortAsc, sortSet, sortMap } from './sortValues.js'; | ||
export { sortAsc, sortMap, sortSet } from './sortValues.js'; | ||
export { mapToTypeMap, typesToConstructors, typeToConstructor } from './toConstructors.js'; | ||
export { typesToMap } from './typesToMap.js'; |
@@ -47,10 +47,10 @@ const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec']; | ||
let depth = 0; | ||
for (let index = start; index < value.length; index++) { | ||
if (value[index] === '>') { | ||
for (let i = start, count = value.length; i < count; i++) { | ||
if (value[i] === '>') { | ||
if (!depth) { | ||
return index; | ||
return i; | ||
} | ||
depth--; | ||
} | ||
else if (value[index] === '<') { | ||
else if (value[i] === '<') { | ||
depth++; | ||
@@ -74,7 +74,7 @@ } | ||
if (value.includes(' as HasCompact')) { | ||
for (let index = 0; index < value.length; index++) { | ||
if (value[index] === '<') { | ||
const end = findClosing(value, index + 1) - 14; | ||
for (let i = 0, count = value.length; i < count; i++) { | ||
if (value[i] === '<') { | ||
const end = findClosing(value, i + 1) - 14; | ||
if (value.substring(end, end + 14) === ' as HasCompact') { | ||
value = `Compact<${value.substring(index + 1, end)}>`; | ||
value = `Compact<${value.substring(i + 1, end)}>`; | ||
} | ||
@@ -113,3 +113,3 @@ } | ||
return (value) => { | ||
for (let i = 0; i < BOUNDED.length; i++) { | ||
for (let i = 0, count = BOUNDED.length; i < count; i++) { | ||
const tag = BOUNDED[i]; | ||
@@ -151,9 +151,9 @@ value = replaceTagWith(value, `${type}${tag}<`, (v) => { | ||
return (value) => { | ||
for (let index = 0; index < value.length; index++) { | ||
if (value[index] === '<') { | ||
for (let i = 0, count = value.length; i < count; i++) { | ||
if (value[i] === '<') { | ||
// check against the allowed wrappers, be it Vec<..>, Option<...> ... | ||
const box = ALLOWED_BOXES.find((box) => { | ||
const start = index - box.length; | ||
const start = i - box.length; | ||
return ((start >= 0 && | ||
value.substring(start, index) === box) && ( | ||
value.substring(start, i) === box) && ( | ||
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...> | ||
@@ -165,4 +165,4 @@ start === 0 || | ||
if (!box) { | ||
const end = findClosing(value, index + 1); | ||
value = `${value.substring(0, index)}${value.substring(end + 1)}`; | ||
const end = findClosing(value, i + 1); | ||
value = `${value.substring(0, i)}${value.substring(end + 1)}`; | ||
} | ||
@@ -219,3 +219,3 @@ } | ||
let result = startValue; | ||
for (let i = 0; i < mappings.length; i++) { | ||
for (let i = 0, count = mappings.length; i < count; i++) { | ||
result = mappings[i](result); | ||
@@ -222,0 +222,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util'; | ||
import { bnToBn, isBigInt, isBn, isCodec, isNumber, stringify } from '@polkadot/util'; | ||
/** @internal **/ | ||
@@ -7,6 +7,2 @@ function isArrayLike(arg) { | ||
/** @internal **/ | ||
function isCodec(arg) { | ||
return isFunction(arg && arg.toU8a); | ||
} | ||
/** @internal **/ | ||
function isEnum(arg) { | ||
@@ -13,0 +9,0 @@ return isCodec(arg) && isNumber(arg.index) && isCodec(arg.value); |
export function typesToMap(registry, [Types, keys]) { | ||
const result = {}; | ||
for (let i = 0; i < keys.length; i++) { | ||
for (let i = 0, count = keys.length; i < count; i++) { | ||
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType(); | ||
@@ -5,0 +5,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
643073
243
13210
Updated@polkadot/util@^12.1.1
Updated@polkadot/x-bigint@^12.1.1