@polkadot/types-codec 8.8.3-4 → 8.8.3-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstract/{AbstractArray.d.ts → Array.d.ts} +0 -0
- package/abstract/{AbstractArray.js → Array.js} +0 -0
- package/{base → abstract}/Base.d.ts +1 -1
- package/{base → abstract}/Base.js +1 -1
- package/abstract/{AbstractInt.d.ts → Int.d.ts} +0 -0
- package/abstract/{AbstractInt.js → Int.js} +0 -0
- package/abstract/index.d.ts +3 -2
- package/abstract/index.js +3 -2
- package/base/Int.d.ts +1 -1
- package/base/Int.js +1 -1
- package/base/Tuple.d.ts +1 -1
- package/base/Tuple.js +1 -1
- package/base/UInt.d.ts +1 -1
- package/base/UInt.js +1 -1
- package/base/Vec.d.ts +1 -1
- package/base/Vec.js +1 -1
- package/base/VecAny.d.ts +1 -1
- package/base/VecAny.js +1 -1
- package/base/VecFixed.d.ts +1 -1
- package/base/VecFixed.js +1 -1
- package/base/index.d.ts +0 -1
- package/base/index.js +0 -1
- package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
- package/cjs/{base → abstract}/Base.js +3 -3
- package/cjs/abstract/{AbstractInt.js → Int.js} +0 -0
- package/cjs/abstract/index.js +12 -4
- package/cjs/base/Int.js +2 -2
- package/cjs/base/Tuple.js +2 -2
- package/cjs/base/UInt.js +2 -2
- package/cjs/base/Vec.js +2 -2
- package/cjs/base/VecAny.js +2 -2
- package/cjs/base/VecFixed.js +2 -2
- package/cjs/base/index.js +0 -8
- package/cjs/extended/Map.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/sanitize.js +17 -37
- package/extended/Map.js +1 -1
- package/package.json +14 -14
- package/packageInfo.js +1 -1
- package/utils/sanitize.d.ts +3 -5
- package/utils/sanitize.js +17 -37
|
File without changes
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
|
|
|
4
4
|
* @name Base
|
|
5
5
|
* @description A type extends the Base class, when it holds a value
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class
|
|
7
|
+
export declare abstract class AbstractBase<T extends Codec> implements Codec {
|
|
8
8
|
#private;
|
|
9
9
|
createdAtHash?: IU8a;
|
|
10
10
|
readonly initialU8aLength?: number;
|
|
File without changes
|
|
File without changes
|
package/abstract/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { AbstractArray } from './
|
|
2
|
-
export {
|
|
1
|
+
export { AbstractArray } from './Array';
|
|
2
|
+
export { AbstractBase } from './Base';
|
|
3
|
+
export { AbstractInt } from './Int';
|
package/abstract/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { AbstractArray } from "./
|
|
4
|
-
export {
|
|
3
|
+
export { AbstractArray } from "./Array.js";
|
|
4
|
+
export { AbstractBase } from "./Base.js";
|
|
5
|
+
export { AbstractInt } from "./Int.js";
|
package/base/Int.d.ts
CHANGED
package/base/Int.js
CHANGED
package/base/Tuple.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from '../types';
|
|
2
|
-
import { AbstractArray } from '../abstract/
|
|
2
|
+
import { AbstractArray } from '../abstract/Array';
|
|
3
3
|
declare type TupleType = (CodecClass | string);
|
|
4
4
|
declare type TupleTypes = TupleType[] | {
|
|
5
5
|
[index: string]: CodecClass | string;
|
package/base/Tuple.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
|
4
|
-
import { AbstractArray } from "../abstract/
|
|
4
|
+
import { AbstractArray } from "../abstract/Array.js";
|
|
5
5
|
import { decodeU8a, mapToTypeMap, typeToConstructor } from "../utils/index.js";
|
|
6
6
|
|
|
7
7
|
function noopSetDefinition(d) {
|
package/base/UInt.d.ts
CHANGED
package/base/UInt.js
CHANGED
package/base/Vec.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HexString } from '@polkadot/util/types';
|
|
2
2
|
import type { Codec, CodecClass, Registry } from '../types';
|
|
3
|
-
import { AbstractArray } from '../abstract/
|
|
3
|
+
import { AbstractArray } from '../abstract/Array';
|
|
4
4
|
interface Options<T> {
|
|
5
5
|
definition?: CodecClass<T>;
|
|
6
6
|
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
package/base/Vec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { assert, compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
|
|
4
|
-
import { AbstractArray } from "../abstract/
|
|
4
|
+
import { AbstractArray } from "../abstract/Array.js";
|
|
5
5
|
import { decodeU8aVec, typeToConstructor } from "../utils/index.js";
|
|
6
6
|
const MAX_LENGTH = 64 * 1024;
|
|
7
7
|
const l = logger('Vec');
|
package/base/VecAny.d.ts
CHANGED
package/base/VecAny.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AbstractArray } from "../abstract/
|
|
3
|
+
import { AbstractArray } from "../abstract/Array.js";
|
|
4
4
|
/**
|
|
5
5
|
* @name VecAny
|
|
6
6
|
* @description
|
package/base/VecFixed.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HexString } from '@polkadot/util/types';
|
|
2
2
|
import type { Codec, CodecClass, Inspect, Registry } from '../types';
|
|
3
|
-
import { AbstractArray } from '../abstract/
|
|
3
|
+
import { AbstractArray } from '../abstract/Array';
|
|
4
4
|
interface Options<T> {
|
|
5
5
|
definition?: CodecClass<T>;
|
|
6
6
|
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
package/base/VecFixed.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { isU8a, u8aConcatStrict } from '@polkadot/util';
|
|
4
|
-
import { AbstractArray } from "../abstract/
|
|
4
|
+
import { AbstractArray } from "../abstract/Array.js";
|
|
5
5
|
import { decodeU8aVec, typeToConstructor } from "../utils/index.js";
|
|
6
6
|
import { decodeVec } from "./Vec.js";
|
|
7
7
|
|
package/base/index.d.ts
CHANGED
package/base/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { Base } from "./Base.js";
|
|
4
3
|
export { Compact } from "./Compact.js";
|
|
5
4
|
export { DoNotConstruct } from "./DoNotConstruct.js";
|
|
6
5
|
export { Enum } from "./Enum.js";
|
|
File without changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.AbstractBase = void 0;
|
|
7
7
|
|
|
8
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -12,7 +12,7 @@ exports.Base = void 0;
|
|
|
12
12
|
* @name Base
|
|
13
13
|
* @description A type extends the Base class, when it holds a value
|
|
14
14
|
*/
|
|
15
|
-
class
|
|
15
|
+
class AbstractBase {
|
|
16
16
|
#raw;
|
|
17
17
|
|
|
18
18
|
constructor(registry, value, initialU8aLength) {
|
|
@@ -120,4 +120,4 @@ class Base {
|
|
|
120
120
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
exports.
|
|
123
|
+
exports.AbstractBase = AbstractBase;
|
|
File without changes
|
package/cjs/abstract/index.js
CHANGED
|
@@ -6,16 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "AbstractArray", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _Array.AbstractArray;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "AbstractBase", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Base.AbstractBase;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
12
18
|
Object.defineProperty(exports, "AbstractInt", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
15
|
-
return
|
|
21
|
+
return _Int.AbstractInt;
|
|
16
22
|
}
|
|
17
23
|
});
|
|
18
24
|
|
|
19
|
-
var
|
|
25
|
+
var _Array = require("./Array");
|
|
26
|
+
|
|
27
|
+
var _Base = require("./Base");
|
|
20
28
|
|
|
21
|
-
var
|
|
29
|
+
var _Int = require("./Int");
|
package/cjs/base/Int.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Int = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Int = require("../abstract/Int");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
|
|
|
20
20
|
* is available here.
|
|
21
21
|
* @noInheritDoc
|
|
22
22
|
*/
|
|
23
|
-
class Int extends
|
|
23
|
+
class Int extends _Int.AbstractInt {
|
|
24
24
|
constructor(registry) {
|
|
25
25
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
26
26
|
let bitLength = arguments.length > 2 ? arguments[2] : undefined;
|
package/cjs/base/Tuple.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.Tuple = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ function decodeTuple(registry, result, value, Classes) {
|
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
class Tuple extends
|
|
48
|
+
class Tuple extends _Array.AbstractArray {
|
|
49
49
|
#Types;
|
|
50
50
|
|
|
51
51
|
constructor(registry, Types, value) {
|
package/cjs/base/UInt.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.UInt = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Int = require("../abstract/Int");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
|
|
|
20
20
|
* is available here.
|
|
21
21
|
* @noInheritDoc
|
|
22
22
|
*/
|
|
23
|
-
class UInt extends
|
|
23
|
+
class UInt extends _Int.AbstractInt {
|
|
24
24
|
static with(bitLength, typeName) {
|
|
25
25
|
return class extends UInt {
|
|
26
26
|
constructor(registry, value) {
|
package/cjs/base/Vec.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.decodeVec = decodeVec;
|
|
|
8
8
|
|
|
9
9
|
var _util = require("@polkadot/util");
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _Array = require("../abstract/Array");
|
|
12
12
|
|
|
13
13
|
var _utils = require("../utils");
|
|
14
14
|
|
|
@@ -61,7 +61,7 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
class Vec extends
|
|
64
|
+
class Vec extends _Array.AbstractArray {
|
|
65
65
|
#Type;
|
|
66
66
|
|
|
67
67
|
constructor(registry, Type) {
|
package/cjs/base/VecAny.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VecAny = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Array = require("../abstract/Array");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -17,7 +17,7 @@ var _AbstractArray = require("../abstract/AbstractArray");
|
|
|
17
17
|
* a vector, this can be used to manage array-like structures with variable arguments of
|
|
18
18
|
* any types
|
|
19
19
|
*/
|
|
20
|
-
class VecAny extends
|
|
20
|
+
class VecAny extends _Array.AbstractArray {
|
|
21
21
|
/**
|
|
22
22
|
* @description Returns the base runtime type name for this instance
|
|
23
23
|
*/
|
package/cjs/base/VecFixed.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.VecFixed = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ function noopSetDefinition(d) {
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
class VecFixed extends
|
|
28
|
+
class VecFixed extends _Array.AbstractArray {
|
|
29
29
|
#Type;
|
|
30
30
|
|
|
31
31
|
constructor(registry, Type, length) {
|
package/cjs/base/index.js
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "Base", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _Base.Base;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
6
|
Object.defineProperty(exports, "Compact", {
|
|
13
7
|
enumerable: true,
|
|
14
8
|
get: function () {
|
|
@@ -82,8 +76,6 @@ Object.defineProperty(exports, "VecFixed", {
|
|
|
82
76
|
}
|
|
83
77
|
});
|
|
84
78
|
|
|
85
|
-
var _Base = require("./Base");
|
|
86
|
-
|
|
87
79
|
var _Compact = require("./Compact");
|
|
88
80
|
|
|
89
81
|
var _DoNotConstruct = require("./DoNotConstruct");
|
package/cjs/extended/Map.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.CodecMap = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _Enum = require("../base/Enum");
|
|
13
13
|
|
|
@@ -44,7 +44,7 @@ function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
|
44
44
|
const output = new Map();
|
|
45
45
|
|
|
46
46
|
for (const [key, val] of value.entries()) {
|
|
47
|
-
const isComplex = KeyClass.prototype instanceof
|
|
47
|
+
const isComplex = KeyClass.prototype instanceof _Array.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
|
package/cjs/packageInfo.js
CHANGED
package/cjs/utils/sanitize.js
CHANGED
|
@@ -140,10 +140,7 @@ function removeExtensions(type, isSized) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
function removeColons() {
|
|
143
|
-
return
|
|
144
|
-
let {
|
|
145
|
-
allowNamespaces
|
|
146
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
143
|
+
return value => {
|
|
147
144
|
let index = 0;
|
|
148
145
|
|
|
149
146
|
while (index !== -1) {
|
|
@@ -152,10 +149,6 @@ function removeColons() {
|
|
|
152
149
|
if (index === 0) {
|
|
153
150
|
value = value.substring(2);
|
|
154
151
|
} else if (index !== -1) {
|
|
155
|
-
if (allowNamespaces) {
|
|
156
|
-
return value;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
152
|
let start = index;
|
|
160
153
|
|
|
161
154
|
while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
|
|
@@ -177,7 +170,7 @@ function removeGenerics() {
|
|
|
177
170
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
178
171
|
const box = ALLOWED_BOXES.find(box => {
|
|
179
172
|
const start = index - box.length;
|
|
180
|
-
return start >= 0 && value.substring(start,
|
|
173
|
+
return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
181
174
|
start === 0 || BOX_PRECEDING.includes(value[start - 1]));
|
|
182
175
|
}); // we have not found anything, unwrap generic innards
|
|
183
176
|
|
|
@@ -190,17 +183,13 @@ function removeGenerics() {
|
|
|
190
183
|
|
|
191
184
|
return value;
|
|
192
185
|
};
|
|
193
|
-
}
|
|
194
|
-
/** @internal */
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
function pairOfReplacer(v) {
|
|
198
|
-
return `(${v},${v})`;
|
|
199
186
|
} // remove the PairOf wrappers
|
|
200
187
|
|
|
201
188
|
|
|
202
189
|
function removePairOf() {
|
|
203
|
-
|
|
190
|
+
const replacer = v => `(${v},${v})`;
|
|
191
|
+
|
|
192
|
+
return value => replaceTagWith(value, 'PairOf<', replacer);
|
|
204
193
|
} // remove the type traits
|
|
205
194
|
|
|
206
195
|
|
|
@@ -226,40 +215,31 @@ function removeTraits() {
|
|
|
226
215
|
.replace(from5, 'Lookup') // replace `<...>::Type`
|
|
227
216
|
.replace(from6, '');
|
|
228
217
|
};
|
|
229
|
-
}
|
|
230
|
-
/** @internal */
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
function wrapReplacer(v) {
|
|
234
|
-
return v;
|
|
235
218
|
} // remove wrapping values, i.e. Box<Proposal> -> Proposal
|
|
236
219
|
|
|
237
220
|
|
|
238
221
|
function removeWrap(check) {
|
|
239
|
-
|
|
222
|
+
const replacer = v => v;
|
|
223
|
+
|
|
224
|
+
return value => replaceTagWith(value, check, replacer);
|
|
240
225
|
}
|
|
241
226
|
|
|
242
|
-
const sanitizeMap = new Map();
|
|
227
|
+
const sanitizeMap = new Map();
|
|
243
228
|
|
|
244
|
-
function sanitize(value
|
|
229
|
+
function sanitize(value) {
|
|
245
230
|
const startValue = value.toString();
|
|
246
|
-
|
|
231
|
+
const memoized = sanitizeMap.get(startValue);
|
|
247
232
|
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (memoized) {
|
|
252
|
-
return memoized;
|
|
253
|
-
}
|
|
233
|
+
if (memoized) {
|
|
234
|
+
return memoized;
|
|
254
235
|
}
|
|
255
236
|
|
|
256
|
-
|
|
257
|
-
result = mappings[i](result, options);
|
|
258
|
-
}
|
|
237
|
+
let result = startValue;
|
|
259
238
|
|
|
260
|
-
|
|
261
|
-
|
|
239
|
+
for (let i = 0; i < mappings.length; i++) {
|
|
240
|
+
result = mappings[i](result);
|
|
262
241
|
}
|
|
263
242
|
|
|
243
|
+
sanitizeMap.set(startValue, result);
|
|
264
244
|
return result;
|
|
265
245
|
}
|
package/extended/Map.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
|
-
import { AbstractArray } from "../abstract/
|
|
4
|
+
import { AbstractArray } from "../abstract/Array.js";
|
|
5
5
|
import { Enum } from "../base/Enum.js";
|
|
6
6
|
import { Struct } from "../native/Struct.js";
|
|
7
7
|
import { compareMap, decodeU8a, sortMap, typeToConstructor } from "../utils/index.js";
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "8.8.3-
|
|
23
|
+
"version": "8.8.3-7",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"require": "./cjs/abstract/index.js",
|
|
38
38
|
"default": "./abstract/index.js"
|
|
39
39
|
},
|
|
40
|
-
"./abstract/
|
|
41
|
-
"types": "./abstract/
|
|
42
|
-
"require": "./cjs/abstract/
|
|
43
|
-
"default": "./abstract/
|
|
40
|
+
"./abstract/Array": {
|
|
41
|
+
"types": "./abstract/Array.d.ts",
|
|
42
|
+
"require": "./cjs/abstract/Array.js",
|
|
43
|
+
"default": "./abstract/Array.js"
|
|
44
44
|
},
|
|
45
|
-
"./abstract/
|
|
46
|
-
"types": "./abstract/
|
|
47
|
-
"require": "./cjs/abstract/
|
|
48
|
-
"default": "./abstract/
|
|
45
|
+
"./abstract/Base": {
|
|
46
|
+
"types": "./abstract/Base.d.ts",
|
|
47
|
+
"require": "./cjs/abstract/Base.js",
|
|
48
|
+
"default": "./abstract/Base.js"
|
|
49
|
+
},
|
|
50
|
+
"./abstract/Int": {
|
|
51
|
+
"types": "./abstract/Int.d.ts",
|
|
52
|
+
"require": "./cjs/abstract/Int.js",
|
|
53
|
+
"default": "./abstract/Int.js"
|
|
49
54
|
},
|
|
50
55
|
"./base": {
|
|
51
56
|
"types": "./base/index.d.ts",
|
|
52
57
|
"require": "./cjs/base/index.js",
|
|
53
58
|
"default": "./base/index.js"
|
|
54
59
|
},
|
|
55
|
-
"./base/Base": {
|
|
56
|
-
"types": "./base/Base.d.ts",
|
|
57
|
-
"require": "./cjs/base/Base.js",
|
|
58
|
-
"default": "./base/Base.js"
|
|
59
|
-
},
|
|
60
60
|
"./base/Compact": {
|
|
61
61
|
"types": "./base/Compact.d.ts",
|
|
62
62
|
"require": "./cjs/base/Compact.js",
|
package/packageInfo.js
CHANGED
|
@@ -5,5 +5,5 @@ export const packageInfo = {
|
|
|
5
5
|
name: '@polkadot/types-codec',
|
|
6
6
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
7
7
|
type: 'esm',
|
|
8
|
-
version: '8.8.3-
|
|
8
|
+
version: '8.8.3-7'
|
|
9
9
|
};
|
package/utils/sanitize.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
declare type Mapper = (value: string, options?: SanitizeOptions) => string;
|
|
1
|
+
import { AnyString } from '../types';
|
|
2
|
+
declare type Mapper = (value: string) => string;
|
|
5
3
|
export declare function trim(): Mapper;
|
|
6
4
|
export declare function findClosing(value: string, start: number): number;
|
|
7
5
|
export declare function alias(src: string, dest: string, withChecks?: boolean): Mapper;
|
|
@@ -13,5 +11,5 @@ export declare function removeGenerics(): Mapper;
|
|
|
13
11
|
export declare function removePairOf(): Mapper;
|
|
14
12
|
export declare function removeTraits(): Mapper;
|
|
15
13
|
export declare function removeWrap(check: string): Mapper;
|
|
16
|
-
export declare function sanitize(value:
|
|
14
|
+
export declare function sanitize(value: AnyString): string;
|
|
17
15
|
export {};
|
package/utils/sanitize.js
CHANGED
|
@@ -117,9 +117,7 @@ export function removeExtensions(type, isSized) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
export function removeColons() {
|
|
120
|
-
return
|
|
121
|
-
allowNamespaces
|
|
122
|
-
} = {}) => {
|
|
120
|
+
return value => {
|
|
123
121
|
let index = 0;
|
|
124
122
|
|
|
125
123
|
while (index !== -1) {
|
|
@@ -128,10 +126,6 @@ export function removeColons() {
|
|
|
128
126
|
if (index === 0) {
|
|
129
127
|
value = value.substring(2);
|
|
130
128
|
} else if (index !== -1) {
|
|
131
|
-
if (allowNamespaces) {
|
|
132
|
-
return value;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
129
|
let start = index;
|
|
136
130
|
|
|
137
131
|
while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
|
|
@@ -152,7 +146,7 @@ export function removeGenerics() {
|
|
|
152
146
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
153
147
|
const box = ALLOWED_BOXES.find(box => {
|
|
154
148
|
const start = index - box.length;
|
|
155
|
-
return start >= 0 && value.substring(start,
|
|
149
|
+
return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
156
150
|
start === 0 || BOX_PRECEDING.includes(value[start - 1]));
|
|
157
151
|
}); // we have not found anything, unwrap generic innards
|
|
158
152
|
|
|
@@ -165,16 +159,12 @@ export function removeGenerics() {
|
|
|
165
159
|
|
|
166
160
|
return value;
|
|
167
161
|
};
|
|
168
|
-
}
|
|
169
|
-
/** @internal */
|
|
170
|
-
|
|
171
|
-
function pairOfReplacer(v) {
|
|
172
|
-
return `(${v},${v})`;
|
|
173
162
|
} // remove the PairOf wrappers
|
|
174
163
|
|
|
175
|
-
|
|
176
164
|
export function removePairOf() {
|
|
177
|
-
|
|
165
|
+
const replacer = v => `(${v},${v})`;
|
|
166
|
+
|
|
167
|
+
return value => replaceTagWith(value, 'PairOf<', replacer);
|
|
178
168
|
} // remove the type traits
|
|
179
169
|
|
|
180
170
|
export function removeTraits() {
|
|
@@ -199,38 +189,28 @@ export function removeTraits() {
|
|
|
199
189
|
.replace(from5, 'Lookup') // replace `<...>::Type`
|
|
200
190
|
.replace(from6, '');
|
|
201
191
|
};
|
|
202
|
-
}
|
|
203
|
-
/** @internal */
|
|
204
|
-
|
|
205
|
-
function wrapReplacer(v) {
|
|
206
|
-
return v;
|
|
207
192
|
} // remove wrapping values, i.e. Box<Proposal> -> Proposal
|
|
208
193
|
|
|
209
|
-
|
|
210
194
|
export function removeWrap(check) {
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const sanitizeMap = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types
|
|
195
|
+
const replacer = v => v;
|
|
214
196
|
|
|
215
|
-
|
|
197
|
+
return value => replaceTagWith(value, check, replacer);
|
|
198
|
+
}
|
|
199
|
+
const sanitizeMap = new Map();
|
|
200
|
+
export function sanitize(value) {
|
|
216
201
|
const startValue = value.toString();
|
|
217
|
-
|
|
202
|
+
const memoized = sanitizeMap.get(startValue);
|
|
218
203
|
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (memoized) {
|
|
223
|
-
return memoized;
|
|
224
|
-
}
|
|
204
|
+
if (memoized) {
|
|
205
|
+
return memoized;
|
|
225
206
|
}
|
|
226
207
|
|
|
227
|
-
|
|
228
|
-
result = mappings[i](result, options);
|
|
229
|
-
}
|
|
208
|
+
let result = startValue;
|
|
230
209
|
|
|
231
|
-
|
|
232
|
-
|
|
210
|
+
for (let i = 0; i < mappings.length; i++) {
|
|
211
|
+
result = mappings[i](result);
|
|
233
212
|
}
|
|
234
213
|
|
|
214
|
+
sanitizeMap.set(startValue, result);
|
|
235
215
|
return result;
|
|
236
216
|
}
|