@polkadot/types-create 8.8.3-0 → 8.8.3-11

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.
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/types-create',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '8.8.3-0'
14
+ version: '8.8.3-11'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -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) {
@@ -121,21 +123,35 @@ function _decodeFixedVec(value, type, _, count) {
121
123
  let inner = 0;
122
124
 
123
125
  for (let i = 1; i < max && index === -1; i++) {
124
- if (type[i] === ';' && inner === 0) {
125
- index = i;
126
- } else if (['[', '(', '<'].includes(type[i])) {
127
- inner++;
128
- } else if ([']', ')', '>'].includes(type[i])) {
129
- inner--;
126
+ switch (type[i]) {
127
+ case ';':
128
+ {
129
+ if (inner === 0) {
130
+ index = i;
131
+ }
132
+
133
+ break;
134
+ }
135
+
136
+ case '[':
137
+ case '(':
138
+ case '<':
139
+ inner++;
140
+ break;
141
+
142
+ case ']':
143
+ case ')':
144
+ case '>':
145
+ inner--;
146
+ break;
130
147
  }
131
148
  }
132
149
 
133
150
  (0, _util.assert)(index !== -1, () => `${type}: Unable to extract location of ';'`);
134
151
  const vecType = type.substring(1, index);
135
152
  const [strLength, displayName] = type.substring(index + 1, max).split(';');
136
- const length = parseInt(strLength.trim(), 10); // as a first round, only u8 via u8aFixed, we can add more support
137
-
138
- (0, _util.assert)(length <= 256, () => `${type}: Only support for [Type; <length>], where length <= 256`);
153
+ const length = parseInt(strLength.trim(), 10);
154
+ (0, _util.assert)(length <= MAX_FIX_LEN, () => `${type}: Only support for [Type; <length>], where length <= ${MAX_FIX_LEN}`);
139
155
  value.displayName = displayName;
140
156
  value.length = length;
141
157
  value.sub = getTypeDef(vecType, {}, count);
@@ -152,9 +168,8 @@ function _decodeTuple(value, _, subType, count) {
152
168
 
153
169
  function _decodeAnyInt(value, type, _, clazz) {
154
170
  const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
155
- const length = parseInt(strLength.trim(), 10); // as a first round, only u8 via u8aFixed, we can add more support
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}`);
171
+ const length = parseInt(strLength.trim(), 10);
172
+ (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
173
  value.displayName = displayName;
159
174
  value.length = length;
160
175
  return value;
@@ -187,8 +202,7 @@ const wrappedExtraction = [['BTreeSet<', '>', _types.TypeDefInfo.BTreeSet], ['Co
187
202
  function extractSubType(type, _ref6) {
188
203
  let [start, end] = _ref6;
189
204
  return type.substring(start.length, type.length - end.length);
190
- } // eslint-disable-next-line @typescript-eslint/ban-types
191
-
205
+ }
192
206
 
193
207
  function getTypeDef(_type) {
194
208
  let {
@@ -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
- function isNotNested() {
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
- let [cDepth, fDepth, sDepth, tDepth, start] = [0, 0, 0, 0, 0];
23
- const result = [];
14
+ const result = []; // these are the depths of the various tokens: <, [, {, (
24
15
 
25
- const extract = index => {
26
- if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
27
- result.push(type.substring(start, index).trim());
28
- start = index + 1;
29
- }
30
- };
16
+ let c = 0;
17
+ let f = 0;
18
+ let s = 0;
19
+ let t = 0; // current start position
31
20
 
32
- for (let index = 0; index < type.length; index++) {
33
- switch (type[index]) {
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
- extract(index);
37
- break;
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
- cDepth++;
38
+ c++;
42
39
  break;
43
40
 
44
41
  case '>':
45
- cDepth--;
42
+ c--;
46
43
  break;
47
44
  // adjust fixed vec depths
48
45
 
49
46
  case '[':
50
- fDepth++;
47
+ f++;
51
48
  break;
52
49
 
53
50
  case ']':
54
- fDepth--;
51
+ f--;
55
52
  break;
56
53
  // adjust struct depth
57
54
 
58
55
  case '{':
59
- sDepth++;
56
+ s++;
60
57
  break;
61
58
 
62
59
  case '}':
63
- sDepth--;
60
+ s--;
64
61
  break;
65
62
  // adjust tuple depth
66
63
 
67
64
  case '(':
68
- tDepth++;
65
+ t++;
69
66
  break;
70
67
 
71
68
  case ')':
72
- tDepth--;
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)(isNotNested(cDepth, fDepth, sDepth, tDepth), () => `Invalid definition (missing terminators) found in ${type}`); // the final leg of the journey
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-0",
23
+ "version": "8.8.3-11",
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-0",
125
- "@polkadot/util": "^9.4.1"
124
+ "@polkadot/types-codec": "8.8.3-11",
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-0'
8
+ version: '8.8.3-11'
9
9
  };
@@ -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: String | string, { displayName, name }?: TypeDefOptions, count?: number): TypeDef;
7
+ export declare function getTypeDef(_type: AnyString, { displayName, name }?: TypeDefOptions, count?: number): TypeDef;
7
8
  export {};
@@ -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) {
@@ -98,21 +100,35 @@ function _decodeFixedVec(value, type, _, count) {
98
100
  let inner = 0;
99
101
 
100
102
  for (let i = 1; i < max && index === -1; i++) {
101
- if (type[i] === ';' && inner === 0) {
102
- index = i;
103
- } else if (['[', '(', '<'].includes(type[i])) {
104
- inner++;
105
- } else if ([']', ')', '>'].includes(type[i])) {
106
- inner--;
103
+ switch (type[i]) {
104
+ case ';':
105
+ {
106
+ if (inner === 0) {
107
+ index = i;
108
+ }
109
+
110
+ break;
111
+ }
112
+
113
+ case '[':
114
+ case '(':
115
+ case '<':
116
+ inner++;
117
+ break;
118
+
119
+ case ']':
120
+ case ')':
121
+ case '>':
122
+ inner--;
123
+ break;
107
124
  }
108
125
  }
109
126
 
110
127
  assert(index !== -1, () => `${type}: Unable to extract location of ';'`);
111
128
  const vecType = type.substring(1, index);
112
129
  const [strLength, displayName] = type.substring(index + 1, max).split(';');
113
- const length = parseInt(strLength.trim(), 10); // as a first round, only u8 via u8aFixed, we can add more support
114
-
115
- assert(length <= 256, () => `${type}: Only support for [Type; <length>], where length <= 256`);
130
+ const length = parseInt(strLength.trim(), 10);
131
+ assert(length <= MAX_FIX_LEN, () => `${type}: Only support for [Type; <length>], where length <= ${MAX_FIX_LEN}`);
116
132
  value.displayName = displayName;
117
133
  value.length = length;
118
134
  value.sub = getTypeDef(vecType, {}, count);
@@ -129,9 +145,8 @@ function _decodeTuple(value, _, subType, count) {
129
145
 
130
146
  function _decodeAnyInt(value, type, _, clazz) {
131
147
  const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
132
- const length = parseInt(strLength.trim(), 10); // as a first round, only u8 via u8aFixed, we can add more support
133
-
134
- assert(length <= 8192 && length % 8 === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
148
+ const length = parseInt(strLength.trim(), 10);
149
+ 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
150
  value.displayName = displayName;
136
151
  value.length = length;
137
152
  return value;
@@ -162,8 +177,7 @@ const wrappedExtraction = [['BTreeSet<', '>', TypeDefInfo.BTreeSet], ['Compact<'
162
177
 
163
178
  function extractSubType(type, [start, end]) {
164
179
  return type.substring(start.length, type.length - end.length);
165
- } // eslint-disable-next-line @typescript-eslint/ban-types
166
-
180
+ }
167
181
 
168
182
  export function getTypeDef(_type, {
169
183
  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
- let [cDepth, fDepth, sDepth, tDepth, start] = [0, 0, 0, 0, 0];
12
- const result = [];
6
+ const result = []; // these are the depths of the various tokens: <, [, {, (
13
7
 
14
- const extract = index => {
15
- if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
16
- result.push(type.substring(start, index).trim());
17
- start = index + 1;
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 index = 0; index < type.length; index++) {
22
- switch (type[index]) {
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
- extract(index);
26
- break;
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
- cDepth++;
30
+ c++;
31
31
  break;
32
32
 
33
33
  case '>':
34
- cDepth--;
34
+ c--;
35
35
  break;
36
36
  // adjust fixed vec depths
37
37
 
38
38
  case '[':
39
- fDepth++;
39
+ f++;
40
40
  break;
41
41
 
42
42
  case ']':
43
- fDepth--;
43
+ f--;
44
44
  break;
45
45
  // adjust struct depth
46
46
 
47
47
  case '{':
48
- sDepth++;
48
+ s++;
49
49
  break;
50
50
 
51
51
  case '}':
52
- sDepth--;
52
+ s--;
53
53
  break;
54
54
  // adjust tuple depth
55
55
 
56
56
  case '(':
57
- tDepth++;
57
+ t++;
58
58
  break;
59
59
 
60
60
  case ')':
61
- tDepth--;
61
+ t--;
62
62
  break;
63
63
  }
64
- }
64
+ } // ensure we have all the terminators taken care of
65
+
65
66
 
66
- assert(isNotNested(cDepth, fDepth, sDepth, tDepth), () => `Invalid definition (missing terminators) found in ${type}`); // the final leg of the journey
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;