@polkadot/types-codec 8.3.3-1 → 8.3.3-12

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/base/Compact.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 { compactFromU8a, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
3
+ import { compactFromU8a, compactToU8a, isU8a } from '@polkadot/util';
4
4
  import { typeToConstructor } from "../utils/index.js";
5
5
  /**
6
6
  * @name Compact
@@ -35,16 +35,16 @@ export class Compact {
35
35
 
36
36
 
37
37
  static decodeCompact(registry, Type, value) {
38
- if (value instanceof Compact) {
38
+ if (isU8a(value)) {
39
+ const [decodedLength, bn] = compactFromU8a(value);
40
+ return [new Type(registry, bn), decodedLength];
41
+ } else if (value instanceof Compact) {
39
42
  return [new Type(registry, value.#raw), 0];
40
43
  } else if (value instanceof Type) {
41
44
  return [value, 0];
42
- } else if (isString(value) || isNumber(value) || isBn(value) || isBigInt(value)) {
43
- return [new Type(registry, value), 0];
44
45
  }
45
46
 
46
- const [decodedLength, bn] = compactFromU8a(value);
47
- return [new Type(registry, bn), decodedLength];
47
+ return [new Type(registry, value), 0];
48
48
  }
49
49
  /**
50
50
  * @description The length of the value when encoded as a Uint8Array
@@ -45,16 +45,16 @@ class Compact {
45
45
 
46
46
 
47
47
  static decodeCompact(registry, Type, value) {
48
- if (value instanceof Compact) {
48
+ if ((0, _util.isU8a)(value)) {
49
+ const [decodedLength, bn] = (0, _util.compactFromU8a)(value);
50
+ return [new Type(registry, bn), decodedLength];
51
+ } else if (value instanceof Compact) {
49
52
  return [new Type(registry, value.#raw), 0];
50
53
  } else if (value instanceof Type) {
51
54
  return [value, 0];
52
- } else if ((0, _util.isString)(value) || (0, _util.isNumber)(value) || (0, _util.isBn)(value) || (0, _util.isBigInt)(value)) {
53
- return [new Type(registry, value), 0];
54
55
  }
55
56
 
56
- const [decodedLength, bn] = (0, _util.compactFromU8a)(value);
57
- return [new Type(registry, bn), decodedLength];
57
+ return [new Type(registry, value), 0];
58
58
  }
59
59
  /**
60
60
  * @description The length of the value when encoded as a Uint8Array
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/types-codec',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '8.3.3-1'
14
+ version: '8.3.3-12'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -73,8 +73,8 @@ function cleanupCompact() {
73
73
  if (value[index] === '<') {
74
74
  const end = findClosing(value, index + 1) - 14;
75
75
 
76
- if (value.substr(end, 14) === ' as HasCompact') {
77
- value = `Compact<${value.substr(index + 1, end - index - 1)}>`;
76
+ if (value.substring(end, end + 14) === ' as HasCompact') {
77
+ value = `Compact<${value.substring(index + 1, end)}>`;
78
78
  }
79
79
  }
80
80
  }
@@ -106,7 +106,7 @@ function replaceTagWith(value, matcher, replacer) {
106
106
 
107
107
  const start = index + matcher.length;
108
108
  const end = findClosing(value, start);
109
- value = `${value.substr(0, index)}${replacer(value.substr(start, end - start))}${value.substr(end + 1)}`;
109
+ value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
110
110
  }
111
111
  } // remove the Bounded* or Weak* wrappers
112
112
 
@@ -134,7 +134,7 @@ function removeColons() {
134
134
  index = value.indexOf('::');
135
135
 
136
136
  if (index === 0) {
137
- value = value.substr(2);
137
+ value = value.substring(2);
138
138
  } else if (index !== -1) {
139
139
  if (allowNamespaces) {
140
140
  return value;
@@ -146,7 +146,7 @@ function removeColons() {
146
146
  start--;
147
147
  }
148
148
 
149
- value = `${value.substr(0, start + 1)}${value.substr(index + 2)}`;
149
+ value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
150
150
  }
151
151
  }
152
152
 
@@ -161,13 +161,13 @@ function removeGenerics() {
161
161
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
162
162
  const box = ALLOWED_BOXES.find(box => {
163
163
  const start = index - box.length;
164
- return start >= 0 && value.substr(start, box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
164
+ return start >= 0 && value.substring(start, start + box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
165
165
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
166
166
  }); // we have not found anything, unwrap generic innards
167
167
 
168
168
  if (!box) {
169
169
  const end = findClosing(value, index + 1);
170
- value = `${value.substr(0, index)}${value.substr(end + 1)}`;
170
+ value = `${value.substring(0, index)}${value.substring(end + 1)}`;
171
171
  }
172
172
  }
173
173
  }
package/native/Text.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyU8a, Codec, Inspect, IU8a, Registry } from '../types';
2
+ import type { AnyU8a, Inspect, IText, IU8a, Registry } from '../types';
3
3
  /**
4
4
  * @name Text
5
5
  * @description
@@ -8,7 +8,7 @@ import type { AnyU8a, Codec, Inspect, IU8a, Registry } from '../types';
8
8
  * object, inheriting all methods exposed from `String`.
9
9
  * @noInheritDoc
10
10
  */
11
- export declare class Text extends String implements Codec {
11
+ export declare class Text extends String implements IText {
12
12
  #private;
13
13
  readonly registry: Registry;
14
14
  createdAtHash?: IU8a;
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.3.3-1",
23
+ "version": "8.3.3-12",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
@@ -410,6 +410,6 @@
410
410
  },
411
411
  "dependencies": {
412
412
  "@babel/runtime": "^7.17.9",
413
- "@polkadot/util": "^9.1.1"
413
+ "@polkadot/util": "^9.1.2-7"
414
414
  }
415
415
  }
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.3.3-1'
8
+ version: '8.3.3-12'
9
9
  };
@@ -47,6 +47,8 @@ export interface IStruct<K = string, V extends Codec = Codec> extends Map<K, V>,
47
47
  getAtIndex(index: number): Codec;
48
48
  toArray(): Codec[];
49
49
  }
50
+ export interface IText extends String, Codec {
51
+ }
50
52
  export declare type ITuple<T extends AnyTuple = Codec[]> = T & Codec;
51
53
  export interface IU8a extends Uint8Array, Codec {
52
54
  readonly isAscii: boolean;
package/utils/sanitize.js CHANGED
@@ -54,8 +54,8 @@ export function cleanupCompact() {
54
54
  if (value[index] === '<') {
55
55
  const end = findClosing(value, index + 1) - 14;
56
56
 
57
- if (value.substr(end, 14) === ' as HasCompact') {
58
- value = `Compact<${value.substr(index + 1, end - index - 1)}>`;
57
+ if (value.substring(end, end + 14) === ' as HasCompact') {
58
+ value = `Compact<${value.substring(index + 1, end)}>`;
59
59
  }
60
60
  }
61
61
  }
@@ -86,7 +86,7 @@ function replaceTagWith(value, matcher, replacer) {
86
86
 
87
87
  const start = index + matcher.length;
88
88
  const end = findClosing(value, start);
89
- value = `${value.substr(0, index)}${replacer(value.substr(start, end - start))}${value.substr(end + 1)}`;
89
+ value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
90
90
  }
91
91
  } // remove the Bounded* or Weak* wrappers
92
92
 
@@ -112,7 +112,7 @@ export function removeColons() {
112
112
  index = value.indexOf('::');
113
113
 
114
114
  if (index === 0) {
115
- value = value.substr(2);
115
+ value = value.substring(2);
116
116
  } else if (index !== -1) {
117
117
  if (allowNamespaces) {
118
118
  return value;
@@ -124,7 +124,7 @@ export function removeColons() {
124
124
  start--;
125
125
  }
126
126
 
127
- value = `${value.substr(0, start + 1)}${value.substr(index + 2)}`;
127
+ value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
128
128
  }
129
129
  }
130
130
 
@@ -138,13 +138,13 @@ export function removeGenerics() {
138
138
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
139
139
  const box = ALLOWED_BOXES.find(box => {
140
140
  const start = index - box.length;
141
- return start >= 0 && value.substr(start, box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
141
+ return start >= 0 && value.substring(start, start + box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
142
142
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
143
143
  }); // we have not found anything, unwrap generic innards
144
144
 
145
145
  if (!box) {
146
146
  const end = findClosing(value, index + 1);
147
- value = `${value.substr(0, index)}${value.substr(end + 1)}`;
147
+ value = `${value.substring(0, index)}${value.substring(end + 1)}`;
148
148
  }
149
149
  }
150
150
  }