@polkadot/types-codec 10.11.2 → 10.12.1
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/cjs/index.js +1 -1
- package/cjs/packageDetect.js +5 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/sortValues.js +25 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +9 -15
- package/{detectPackage.js → packageDetect.js} +1 -2
- package/packageInfo.js +1 -1
- package/utils/sortValues.js +26 -3
- package/cjs/detectOther.js +0 -3
- package/cjs/detectPackage.js +0 -7
- package/detectOther.d.ts +0 -2
- package/detectOther.js +0 -1
- /package/{detectPackage.d.ts → packageDetect.d.ts} +0 -0
package/cjs/index.js
CHANGED
package/cjs/packageInfo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.packageInfo = void 0;
|
|
4
|
-
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/types-codec', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '10.12.1' };
|
package/cjs/utils/sortValues.js
CHANGED
|
@@ -10,6 +10,10 @@ function isArrayLike(arg) {
|
|
|
10
10
|
function isEnum(arg) {
|
|
11
11
|
return (0, util_1.isCodec)(arg) && (0, util_1.isNumber)(arg.index) && (0, util_1.isCodec)(arg.value);
|
|
12
12
|
}
|
|
13
|
+
/** @internal **/
|
|
14
|
+
function isOption(arg) {
|
|
15
|
+
return (0, util_1.isCodec)(arg) && (0, util_1.isBoolean)(arg.isSome) && (0, util_1.isCodec)(arg.value);
|
|
16
|
+
}
|
|
13
17
|
/** @internal */
|
|
14
18
|
function isNumberLike(arg) {
|
|
15
19
|
return (0, util_1.isNumber)(arg) || (0, util_1.isBn)(arg) || (0, util_1.isBigInt)(arg);
|
|
@@ -27,6 +31,20 @@ function sortArray(a, b) {
|
|
|
27
31
|
}
|
|
28
32
|
return a.length - b.length;
|
|
29
33
|
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
function checkForDuplicates(container, seen, arg) {
|
|
36
|
+
// Convert the value to hex.
|
|
37
|
+
if ((0, util_1.isCodec)(arg)) {
|
|
38
|
+
const hex = arg.toHex();
|
|
39
|
+
// Check if we have seen the value.
|
|
40
|
+
if (seen.has(hex)) {
|
|
41
|
+
// Duplicates are not allowed.
|
|
42
|
+
throw new Error(`Duplicate value in ${container}: ${(0, util_1.stringify)(arg)}`);
|
|
43
|
+
}
|
|
44
|
+
seen.add(hex);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
30
48
|
/**
|
|
31
49
|
* Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
|
|
32
50
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
|
|
@@ -42,6 +60,9 @@ function sortAsc(a, b) {
|
|
|
42
60
|
else if (isEnum(a) && isEnum(b)) {
|
|
43
61
|
return sortAsc(a.index, b.index) || sortAsc(a.value, b.value);
|
|
44
62
|
}
|
|
63
|
+
else if (isOption(a) && isOption(b)) {
|
|
64
|
+
return sortAsc(a.isNone ? 0 : 1, b.isNone ? 0 : 1) || sortAsc(a.value, b.value);
|
|
65
|
+
}
|
|
45
66
|
else if (isArrayLike(a) && isArrayLike(b)) {
|
|
46
67
|
return sortArray(a, b);
|
|
47
68
|
}
|
|
@@ -53,10 +74,12 @@ function sortAsc(a, b) {
|
|
|
53
74
|
}
|
|
54
75
|
exports.sortAsc = sortAsc;
|
|
55
76
|
function sortSet(set) {
|
|
56
|
-
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
return new Set(Array.from(set).filter((value) => checkForDuplicates('BTreeSet', seen, value)).sort(sortAsc));
|
|
57
79
|
}
|
|
58
80
|
exports.sortSet = sortSet;
|
|
59
81
|
function sortMap(map) {
|
|
60
|
-
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
return new Map(Array.from(map.entries()).filter(([key]) => checkForDuplicates('BTreeMap', seen, key)).sort(([keyA], [keyB]) => sortAsc(keyA, keyB)));
|
|
61
84
|
}
|
|
62
85
|
exports.sortMap = sortMap;
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './
|
|
1
|
+
import './packageDetect.js';
|
|
2
2
|
export * from './bundle.js';
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './
|
|
1
|
+
import './packageDetect.js';
|
|
2
2
|
export * from './bundle.js';
|
package/package.json
CHANGED
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"url": "https://github.com/polkadot-js/api.git"
|
|
15
15
|
},
|
|
16
16
|
"sideEffects": [
|
|
17
|
-
"./
|
|
18
|
-
"./cjs/
|
|
17
|
+
"./packageDetect.js",
|
|
18
|
+
"./cjs/packageDetect.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "10.
|
|
21
|
+
"version": "10.12.1",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -145,18 +145,6 @@
|
|
|
145
145
|
"require": "./cjs/bundle.js",
|
|
146
146
|
"default": "./bundle.js"
|
|
147
147
|
},
|
|
148
|
-
"./detectOther": {
|
|
149
|
-
"types": "./detectOther.d.ts",
|
|
150
|
-
"module": "./detectOther.js",
|
|
151
|
-
"require": "./cjs/detectOther.js",
|
|
152
|
-
"default": "./detectOther.js"
|
|
153
|
-
},
|
|
154
|
-
"./detectPackage": {
|
|
155
|
-
"types": "./detectPackage.d.ts",
|
|
156
|
-
"module": "./detectPackage.js",
|
|
157
|
-
"require": "./cjs/detectPackage.js",
|
|
158
|
-
"default": "./detectPackage.js"
|
|
159
|
-
},
|
|
160
148
|
"./extended": {
|
|
161
149
|
"types": "./extended/index.d.ts",
|
|
162
150
|
"module": "./extended/index.js",
|
|
@@ -310,6 +298,12 @@
|
|
|
310
298
|
"require": "./cjs/package.json",
|
|
311
299
|
"default": "./package.json"
|
|
312
300
|
},
|
|
301
|
+
"./packageDetect": {
|
|
302
|
+
"types": "./packageDetect.d.ts",
|
|
303
|
+
"module": "./packageDetect.js",
|
|
304
|
+
"require": "./cjs/packageDetect.js",
|
|
305
|
+
"default": "./packageDetect.js"
|
|
306
|
+
},
|
|
313
307
|
"./packageInfo.js": {
|
|
314
308
|
"types": "./packageInfo.d.ts",
|
|
315
309
|
"module": "./packageInfo.js",
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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.
|
|
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.12.1' };
|
package/utils/sortValues.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bnToBn, isBigInt, isBn, isCodec, isNumber, stringify } from '@polkadot/util';
|
|
1
|
+
import { bnToBn, isBigInt, isBn, isBoolean, isCodec, isNumber, stringify } from '@polkadot/util';
|
|
2
2
|
/** @internal **/
|
|
3
3
|
function isArrayLike(arg) {
|
|
4
4
|
return arg instanceof Uint8Array || Array.isArray(arg);
|
|
@@ -7,6 +7,10 @@ function isArrayLike(arg) {
|
|
|
7
7
|
function isEnum(arg) {
|
|
8
8
|
return isCodec(arg) && isNumber(arg.index) && isCodec(arg.value);
|
|
9
9
|
}
|
|
10
|
+
/** @internal **/
|
|
11
|
+
function isOption(arg) {
|
|
12
|
+
return isCodec(arg) && isBoolean(arg.isSome) && isCodec(arg.value);
|
|
13
|
+
}
|
|
10
14
|
/** @internal */
|
|
11
15
|
function isNumberLike(arg) {
|
|
12
16
|
return isNumber(arg) || isBn(arg) || isBigInt(arg);
|
|
@@ -24,6 +28,20 @@ function sortArray(a, b) {
|
|
|
24
28
|
}
|
|
25
29
|
return a.length - b.length;
|
|
26
30
|
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
function checkForDuplicates(container, seen, arg) {
|
|
33
|
+
// Convert the value to hex.
|
|
34
|
+
if (isCodec(arg)) {
|
|
35
|
+
const hex = arg.toHex();
|
|
36
|
+
// Check if we have seen the value.
|
|
37
|
+
if (seen.has(hex)) {
|
|
38
|
+
// Duplicates are not allowed.
|
|
39
|
+
throw new Error(`Duplicate value in ${container}: ${stringify(arg)}`);
|
|
40
|
+
}
|
|
41
|
+
seen.add(hex);
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
27
45
|
/**
|
|
28
46
|
* Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
|
|
29
47
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
|
|
@@ -39,6 +57,9 @@ export function sortAsc(a, b) {
|
|
|
39
57
|
else if (isEnum(a) && isEnum(b)) {
|
|
40
58
|
return sortAsc(a.index, b.index) || sortAsc(a.value, b.value);
|
|
41
59
|
}
|
|
60
|
+
else if (isOption(a) && isOption(b)) {
|
|
61
|
+
return sortAsc(a.isNone ? 0 : 1, b.isNone ? 0 : 1) || sortAsc(a.value, b.value);
|
|
62
|
+
}
|
|
42
63
|
else if (isArrayLike(a) && isArrayLike(b)) {
|
|
43
64
|
return sortArray(a, b);
|
|
44
65
|
}
|
|
@@ -49,8 +70,10 @@ export function sortAsc(a, b) {
|
|
|
49
70
|
throw new Error(`Attempting to sort unrecognized values: ${stringify(a)} (typeof ${typeof a}) <-> ${stringify(b)} (typeof ${typeof b})`);
|
|
50
71
|
}
|
|
51
72
|
export function sortSet(set) {
|
|
52
|
-
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
return new Set(Array.from(set).filter((value) => checkForDuplicates('BTreeSet', seen, value)).sort(sortAsc));
|
|
53
75
|
}
|
|
54
76
|
export function sortMap(map) {
|
|
55
|
-
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
return new Map(Array.from(map.entries()).filter(([key]) => checkForDuplicates('BTreeMap', seen, key)).sort(([keyA], [keyB]) => sortAsc(keyA, keyB)));
|
|
56
79
|
}
|
package/cjs/detectOther.js
DELETED
package/cjs/detectPackage.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
const detectOther_js_1 = tslib_1.__importDefault(require("./detectOther.js"));
|
|
6
|
-
const packageInfo_js_1 = require("./packageInfo.js");
|
|
7
|
-
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, detectOther_js_1.default);
|
package/detectOther.d.ts
DELETED
package/detectOther.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default [];
|
|
File without changes
|