@polkadot/types-create 8.8.3-3 → 8.8.3-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/packageInfo.js +1 -1
- package/cjs/util/getTypeDef.js +7 -8
- package/cjs/util/typeSplit.js +29 -31
- package/package.json +2 -2
- package/packageInfo.js +1 -1
- package/util/getTypeDef.d.ts +2 -1
- package/util/getTypeDef.js +7 -8
- package/util/typeSplit.js +29 -28
package/cjs/packageInfo.js
CHANGED
package/cjs/util/getTypeDef.js
CHANGED
|
@@ -16,6 +16,8 @@ var _typeSplit = require("./typeSplit");
|
|
|
16
16
|
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
|
17
17
|
// SPDX-License-Identifier: Apache-2.0
|
|
18
18
|
const MAX_NESTED = 64;
|
|
19
|
+
const MAX_FIX_LEN = 2048;
|
|
20
|
+
const MAX_BIT_LEN = 8192;
|
|
19
21
|
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
20
22
|
|
|
21
23
|
function getTypeString(typeOrObj) {
|
|
@@ -133,9 +135,8 @@ function _decodeFixedVec(value, type, _, count) {
|
|
|
133
135
|
(0, _util.assert)(index !== -1, () => `${type}: Unable to extract location of ';'`);
|
|
134
136
|
const vecType = type.substring(1, index);
|
|
135
137
|
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
|
136
|
-
const length = parseInt(strLength.trim(), 10);
|
|
137
|
-
|
|
138
|
-
(0, _util.assert)(length <= 256, () => `${type}: Only support for [Type; <length>], where length <= 256`);
|
|
138
|
+
const length = parseInt(strLength.trim(), 10);
|
|
139
|
+
(0, _util.assert)(length <= MAX_FIX_LEN, () => `${type}: Only support for [Type; <length>], where length <= ${MAX_FIX_LEN}`);
|
|
139
140
|
value.displayName = displayName;
|
|
140
141
|
value.length = length;
|
|
141
142
|
value.sub = getTypeDef(vecType, {}, count);
|
|
@@ -152,9 +153,8 @@ function _decodeTuple(value, _, subType, count) {
|
|
|
152
153
|
|
|
153
154
|
function _decodeAnyInt(value, type, _, clazz) {
|
|
154
155
|
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
|
155
|
-
const length = parseInt(strLength.trim(), 10);
|
|
156
|
-
|
|
157
|
-
(0, _util.assert)(length <= 8192 && length % 8 === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
|
156
|
+
const length = parseInt(strLength.trim(), 10);
|
|
157
|
+
(0, _util.assert)(length <= MAX_BIT_LEN && length % 8 === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= ${MAX_BIT_LEN} and a power of 8, found ${length}`);
|
|
158
158
|
value.displayName = displayName;
|
|
159
159
|
value.length = length;
|
|
160
160
|
return value;
|
|
@@ -187,8 +187,7 @@ const wrappedExtraction = [['BTreeSet<', '>', _types.TypeDefInfo.BTreeSet], ['Co
|
|
|
187
187
|
function extractSubType(type, _ref6) {
|
|
188
188
|
let [start, end] = _ref6;
|
|
189
189
|
return type.substring(start.length, type.length - end.length);
|
|
190
|
-
}
|
|
191
|
-
|
|
190
|
+
}
|
|
192
191
|
|
|
193
192
|
function getTypeDef(_type) {
|
|
194
193
|
let {
|
package/cjs/util/typeSplit.js
CHANGED
|
@@ -9,72 +9,70 @@ var _util = require("@polkadot/util");
|
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
|
|
13
|
-
for (var _len = arguments.length, counters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
14
|
-
counters[_key] = arguments[_key];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return !counters.some(counter => counter !== 0);
|
|
18
|
-
} // safely split a string on ', ' while taking care of any nested occurences
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
// safely split a string on ', ' while taking care of any nested occurences
|
|
21
13
|
function typeSplit(type) {
|
|
22
|
-
|
|
23
|
-
const result = [];
|
|
14
|
+
const result = []; // these are the depths of the various tokens: <, [, {, (
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
};
|
|
16
|
+
let c = 0;
|
|
17
|
+
let f = 0;
|
|
18
|
+
let s = 0;
|
|
19
|
+
let t = 0; // current start position
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
let start = 0;
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < type.length; i++) {
|
|
24
|
+
switch (type[i]) {
|
|
34
25
|
// if we are not nested, add the type
|
|
35
26
|
case ',':
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
{
|
|
28
|
+
if (!(c || f || s || t)) {
|
|
29
|
+
result.push(type.substring(start, i).trim());
|
|
30
|
+
start = i + 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
38
35
|
// adjust compact/vec (and friends) depth
|
|
39
36
|
|
|
40
37
|
case '<':
|
|
41
|
-
|
|
38
|
+
c++;
|
|
42
39
|
break;
|
|
43
40
|
|
|
44
41
|
case '>':
|
|
45
|
-
|
|
42
|
+
c--;
|
|
46
43
|
break;
|
|
47
44
|
// adjust fixed vec depths
|
|
48
45
|
|
|
49
46
|
case '[':
|
|
50
|
-
|
|
47
|
+
f++;
|
|
51
48
|
break;
|
|
52
49
|
|
|
53
50
|
case ']':
|
|
54
|
-
|
|
51
|
+
f--;
|
|
55
52
|
break;
|
|
56
53
|
// adjust struct depth
|
|
57
54
|
|
|
58
55
|
case '{':
|
|
59
|
-
|
|
56
|
+
s++;
|
|
60
57
|
break;
|
|
61
58
|
|
|
62
59
|
case '}':
|
|
63
|
-
|
|
60
|
+
s--;
|
|
64
61
|
break;
|
|
65
62
|
// adjust tuple depth
|
|
66
63
|
|
|
67
64
|
case '(':
|
|
68
|
-
|
|
65
|
+
t++;
|
|
69
66
|
break;
|
|
70
67
|
|
|
71
68
|
case ')':
|
|
72
|
-
|
|
69
|
+
t--;
|
|
73
70
|
break;
|
|
74
71
|
}
|
|
75
|
-
}
|
|
72
|
+
} // ensure we have all the terminators taken care of
|
|
73
|
+
|
|
76
74
|
|
|
77
|
-
(0, _util.assert)(
|
|
75
|
+
(0, _util.assert)(!(c || f || s || t), () => `Invalid definition (missing terminators) found in ${type}`); // the final leg of the journey
|
|
78
76
|
|
|
79
77
|
result.push(type.substring(start, type.length).trim());
|
|
80
78
|
return result;
|
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-6",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@babel/runtime": "^7.18.3",
|
|
124
|
-
"@polkadot/types-codec": "8.8.3-
|
|
124
|
+
"@polkadot/types-codec": "8.8.3-6",
|
|
125
125
|
"@polkadot/util": "^9.4.2-22"
|
|
126
126
|
}
|
|
127
127
|
}
|
package/packageInfo.js
CHANGED
|
@@ -5,5 +5,5 @@ export const packageInfo = {
|
|
|
5
5
|
name: '@polkadot/types-create',
|
|
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-6'
|
|
9
9
|
};
|
package/util/getTypeDef.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { AnyString } from '@polkadot/types-codec/types';
|
|
1
2
|
import type { TypeDef } from '@polkadot/types-create/types';
|
|
2
3
|
interface TypeDefOptions {
|
|
3
4
|
name?: string;
|
|
4
5
|
displayName?: string;
|
|
5
6
|
}
|
|
6
|
-
export declare function getTypeDef(_type:
|
|
7
|
+
export declare function getTypeDef(_type: AnyString, { displayName, name }?: TypeDefOptions, count?: number): TypeDef;
|
|
7
8
|
export {};
|
package/util/getTypeDef.js
CHANGED
|
@@ -5,6 +5,8 @@ import { assert, isNumber, isString, objectSpread } from '@polkadot/util';
|
|
|
5
5
|
import { TypeDefInfo } from "../types/index.js";
|
|
6
6
|
import { typeSplit } from "./typeSplit.js";
|
|
7
7
|
const MAX_NESTED = 64;
|
|
8
|
+
const MAX_FIX_LEN = 2048;
|
|
9
|
+
const MAX_BIT_LEN = 8192;
|
|
8
10
|
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
9
11
|
|
|
10
12
|
function getTypeString(typeOrObj) {
|
|
@@ -110,9 +112,8 @@ function _decodeFixedVec(value, type, _, count) {
|
|
|
110
112
|
assert(index !== -1, () => `${type}: Unable to extract location of ';'`);
|
|
111
113
|
const vecType = type.substring(1, index);
|
|
112
114
|
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
|
113
|
-
const length = parseInt(strLength.trim(), 10);
|
|
114
|
-
|
|
115
|
-
assert(length <= 256, () => `${type}: Only support for [Type; <length>], where length <= 256`);
|
|
115
|
+
const length = parseInt(strLength.trim(), 10);
|
|
116
|
+
assert(length <= MAX_FIX_LEN, () => `${type}: Only support for [Type; <length>], where length <= ${MAX_FIX_LEN}`);
|
|
116
117
|
value.displayName = displayName;
|
|
117
118
|
value.length = length;
|
|
118
119
|
value.sub = getTypeDef(vecType, {}, count);
|
|
@@ -129,9 +130,8 @@ function _decodeTuple(value, _, subType, count) {
|
|
|
129
130
|
|
|
130
131
|
function _decodeAnyInt(value, type, _, clazz) {
|
|
131
132
|
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
|
132
|
-
const length = parseInt(strLength.trim(), 10);
|
|
133
|
-
|
|
134
|
-
assert(length <= 8192 && length % 8 === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
|
133
|
+
const length = parseInt(strLength.trim(), 10);
|
|
134
|
+
assert(length <= MAX_BIT_LEN && length % 8 === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= ${MAX_BIT_LEN} and a power of 8, found ${length}`);
|
|
135
135
|
value.displayName = displayName;
|
|
136
136
|
value.length = length;
|
|
137
137
|
return value;
|
|
@@ -162,8 +162,7 @@ const wrappedExtraction = [['BTreeSet<', '>', TypeDefInfo.BTreeSet], ['Compact<'
|
|
|
162
162
|
|
|
163
163
|
function extractSubType(type, [start, end]) {
|
|
164
164
|
return type.substring(start.length, type.length - end.length);
|
|
165
|
-
}
|
|
166
|
-
|
|
165
|
+
}
|
|
167
166
|
|
|
168
167
|
export function getTypeDef(_type, {
|
|
169
168
|
displayName,
|
package/util/typeSplit.js
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { assert } from '@polkadot/util';
|
|
4
|
-
|
|
5
|
-
function isNotNested(...counters) {
|
|
6
|
-
return !counters.some(counter => counter !== 0);
|
|
7
|
-
} // safely split a string on ', ' while taking care of any nested occurences
|
|
8
|
-
|
|
3
|
+
import { assert } from '@polkadot/util'; // safely split a string on ', ' while taking care of any nested occurences
|
|
9
4
|
|
|
10
5
|
export function typeSplit(type) {
|
|
11
|
-
|
|
12
|
-
const result = [];
|
|
6
|
+
const result = []; // these are the depths of the various tokens: <, [, {, (
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
let c = 0;
|
|
9
|
+
let f = 0;
|
|
10
|
+
let s = 0;
|
|
11
|
+
let t = 0; // current start position
|
|
12
|
+
|
|
13
|
+
let start = 0;
|
|
20
14
|
|
|
21
|
-
for (let
|
|
22
|
-
switch (type[
|
|
15
|
+
for (let i = 0; i < type.length; i++) {
|
|
16
|
+
switch (type[i]) {
|
|
23
17
|
// if we are not nested, add the type
|
|
24
18
|
case ',':
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
{
|
|
20
|
+
if (!(c || f || s || t)) {
|
|
21
|
+
result.push(type.substring(start, i).trim());
|
|
22
|
+
start = i + 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
27
|
// adjust compact/vec (and friends) depth
|
|
28
28
|
|
|
29
29
|
case '<':
|
|
30
|
-
|
|
30
|
+
c++;
|
|
31
31
|
break;
|
|
32
32
|
|
|
33
33
|
case '>':
|
|
34
|
-
|
|
34
|
+
c--;
|
|
35
35
|
break;
|
|
36
36
|
// adjust fixed vec depths
|
|
37
37
|
|
|
38
38
|
case '[':
|
|
39
|
-
|
|
39
|
+
f++;
|
|
40
40
|
break;
|
|
41
41
|
|
|
42
42
|
case ']':
|
|
43
|
-
|
|
43
|
+
f--;
|
|
44
44
|
break;
|
|
45
45
|
// adjust struct depth
|
|
46
46
|
|
|
47
47
|
case '{':
|
|
48
|
-
|
|
48
|
+
s++;
|
|
49
49
|
break;
|
|
50
50
|
|
|
51
51
|
case '}':
|
|
52
|
-
|
|
52
|
+
s--;
|
|
53
53
|
break;
|
|
54
54
|
// adjust tuple depth
|
|
55
55
|
|
|
56
56
|
case '(':
|
|
57
|
-
|
|
57
|
+
t++;
|
|
58
58
|
break;
|
|
59
59
|
|
|
60
60
|
case ')':
|
|
61
|
-
|
|
61
|
+
t--;
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
-
}
|
|
64
|
+
} // ensure we have all the terminators taken care of
|
|
65
|
+
|
|
65
66
|
|
|
66
|
-
assert(
|
|
67
|
+
assert(!(c || f || s || t), () => `Invalid definition (missing terminators) found in ${type}`); // the final leg of the journey
|
|
67
68
|
|
|
68
69
|
result.push(type.substring(start, type.length).trim());
|
|
69
70
|
return result;
|