@polkadot/types-codec 8.9.2-1 → 8.9.2-4

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.
@@ -10,6 +10,11 @@ import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types';
10
10
  export declare abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
11
11
  readonly registry: Registry;
12
12
  createdAtHash?: IU8a;
13
+ /**
14
+ * @description This ensures that operators such as clice, filter, map, etc. return
15
+ * new Array instances (without this we need to apply overrides)
16
+ */
17
+ static get [Symbol.species](): typeof Array;
13
18
  protected constructor(registry: Registry, length: number);
14
19
  /**
15
20
  * @description The length of the value when encoded as a Uint8Array
@@ -66,24 +71,4 @@ export declare abstract class AbstractArray<T extends Codec> extends Array<T> im
66
71
  */
67
72
  toU8a(isBare?: boolean): Uint8Array;
68
73
  toU8aInner(isBare?: boolean): Uint8Array[];
69
- /**
70
- * @description Concatenates two arrays
71
- */
72
- concat(other: T[]): T[];
73
- /**
74
- * @description Filters the array with the callback
75
- */
76
- filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[];
77
- /**
78
- * @description Maps the array with the callback
79
- */
80
- map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[];
81
- /**
82
- * @description Checks if the array includes a specific value
83
- */
84
- includes(check: unknown): boolean;
85
- /**
86
- * @description Returns a slice of an array
87
- */
88
- slice(start?: number, end?: number): T[];
89
74
  }
package/abstract/Array.js CHANGED
@@ -11,6 +11,14 @@ import { compareArray } from "../utils/compareArray.js";
11
11
  */
12
12
 
13
13
  export class AbstractArray extends Array {
14
+ /**
15
+ * @description This ensures that operators such as clice, filter, map, etc. return
16
+ * new Array instances (without this we need to apply overrides)
17
+ */
18
+ static get [Symbol.species]() {
19
+ return Array;
20
+ }
21
+
14
22
  constructor(registry, length) {
15
23
  super(length);
16
24
  this.registry = registry;
@@ -165,49 +173,6 @@ export class AbstractArray extends Array {
165
173
  }
166
174
 
167
175
  return encoded;
168
- } // Below are methods that we override. When we do a `new Vec(...).map()`,
169
- // we want it to return an Array. We only override the methods that return a
170
- // new instance.
171
-
172
- /**
173
- * @description Concatenates two arrays
174
- */
175
-
176
-
177
- concat(other) {
178
- return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
179
- }
180
- /**
181
- * @description Filters the array with the callback
182
- */
183
-
184
-
185
- filter(callbackfn, thisArg) {
186
- return this.toArray().filter(callbackfn, thisArg);
187
- }
188
- /**
189
- * @description Maps the array with the callback
190
- */
191
-
192
-
193
- map(callbackfn, thisArg) {
194
- return this.toArray().map(callbackfn, thisArg);
195
- }
196
- /**
197
- * @description Checks if the array includes a specific value
198
- */
199
-
200
-
201
- includes(check) {
202
- return this.some(value => value.eq(check));
203
- }
204
- /**
205
- * @description Returns a slice of an array
206
- */
207
-
208
-
209
- slice(start, end) {
210
- return this.toArray().slice(start, end);
211
176
  }
212
177
 
213
178
  }
@@ -0,0 +1,4 @@
1
+ import { BigInt } from '@polkadot/x-bigint';
2
+ export declare abstract class AbstractBigInt extends BigInt {
3
+ constructor(value: string | number | bigint | boolean);
4
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { BigInt } from '@polkadot/x-bigint'; // @ts-expect-error not extensible, we make it extensible here
4
+
5
+ export class AbstractBigInt extends BigInt {
6
+ // @ts-expect-error super() not required, the self magic does that
7
+ constructor(value) {
8
+ const self = Object(BigInt(value));
9
+ Object.setPrototypeOf(self, AbstractBigInt.prototype);
10
+ return self;
11
+ }
12
+
13
+ }
@@ -20,6 +20,14 @@ var _compareArray = require("../utils/compareArray");
20
20
  * @noInheritDoc
21
21
  */
22
22
  class AbstractArray extends Array {
23
+ /**
24
+ * @description This ensures that operators such as clice, filter, map, etc. return
25
+ * new Array instances (without this we need to apply overrides)
26
+ */
27
+ static get [Symbol.species]() {
28
+ return Array;
29
+ }
30
+
23
31
  constructor(registry, length) {
24
32
  super(length);
25
33
  this.registry = registry;
@@ -174,49 +182,6 @@ class AbstractArray extends Array {
174
182
  }
175
183
 
176
184
  return encoded;
177
- } // Below are methods that we override. When we do a `new Vec(...).map()`,
178
- // we want it to return an Array. We only override the methods that return a
179
- // new instance.
180
-
181
- /**
182
- * @description Concatenates two arrays
183
- */
184
-
185
-
186
- concat(other) {
187
- return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
188
- }
189
- /**
190
- * @description Filters the array with the callback
191
- */
192
-
193
-
194
- filter(callbackfn, thisArg) {
195
- return this.toArray().filter(callbackfn, thisArg);
196
- }
197
- /**
198
- * @description Maps the array with the callback
199
- */
200
-
201
-
202
- map(callbackfn, thisArg) {
203
- return this.toArray().map(callbackfn, thisArg);
204
- }
205
- /**
206
- * @description Checks if the array includes a specific value
207
- */
208
-
209
-
210
- includes(check) {
211
- return this.some(value => value.eq(check));
212
- }
213
- /**
214
- * @description Returns a slice of an array
215
- */
216
-
217
-
218
- slice(start, end) {
219
- return this.toArray().slice(start, end);
220
185
  }
221
186
 
222
187
  }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AbstractBigInt = void 0;
7
+
8
+ var _xBigint = require("@polkadot/x-bigint");
9
+
10
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ // @ts-expect-error not extensible, we make it extensible here
13
+ class AbstractBigInt extends _xBigint.BigInt {
14
+ // @ts-expect-error super() not required, the self magic does that
15
+ constructor(value) {
16
+ const self = Object((0, _xBigint.BigInt)(value));
17
+ Object.setPrototypeOf(self, AbstractBigInt.prototype);
18
+ return self;
19
+ }
20
+
21
+ }
22
+
23
+ exports.AbstractBigInt = AbstractBigInt;
package/cjs/native/Raw.js CHANGED
@@ -20,6 +20,14 @@ var _util = require("@polkadot/util");
20
20
  * @noInheritDoc
21
21
  */
22
22
  class Raw extends Uint8Array {
23
+ /**
24
+ * @description This ensures that operators such as clice, filter, map, etc. return
25
+ * new Array instances (without this we need to apply overrides)
26
+ */
27
+ static get [Symbol.species]() {
28
+ return Uint8Array;
29
+ }
30
+
23
31
  constructor(registry, value, initialU8aLength) {
24
32
  super((0, _util.u8aToU8a)(value));
25
33
  this.registry = registry;
@@ -65,15 +73,6 @@ class Raw extends Uint8Array {
65
73
  get isUtf8() {
66
74
  return (0, _util.isUtf8)(this);
67
75
  }
68
- /**
69
- * @description The length of the value
70
- */
71
-
72
-
73
- get length() {
74
- // only included here since we ignore inherited docs
75
- return super.length;
76
- }
77
76
  /**
78
77
  * @description Returns the number of bits in the value
79
78
  */
@@ -104,28 +103,6 @@ class Raw extends Uint8Array {
104
103
  outer: [this.toU8a()]
105
104
  };
106
105
  }
107
- /**
108
- * @description Create a new slice from the actual buffer. (compat)
109
- * @param start The position to start at
110
- * @param end The position to end at
111
- */
112
-
113
-
114
- slice(start, end) {
115
- // Like subarray below, we have to follow this approach since we are extending the TypeArray.
116
- // This happens especially when it comes to further extensions, the length may be an override
117
- return Uint8Array.from(this).slice(start, end);
118
- }
119
- /**
120
- * @description Create a new subarray from the actual buffer. (compat)
121
- * @param begin The position to start at
122
- * @param end The position to end at
123
- */
124
-
125
-
126
- subarray(begin, end) {
127
- return Uint8Array.from(this).subarray(begin, end);
128
- }
129
106
  /**
130
107
  * @description Returns a hex string representation of the value
131
108
  */
@@ -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.9.2-1'
14
+ version: '8.9.2-4'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
package/native/Raw.d.ts CHANGED
@@ -13,6 +13,11 @@ export declare class Raw extends Uint8Array implements IU8a {
13
13
  createdAtHash?: IU8a;
14
14
  readonly initialU8aLength?: number;
15
15
  readonly registry: Registry;
16
+ /**
17
+ * @description This ensures that operators such as clice, filter, map, etc. return
18
+ * new Array instances (without this we need to apply overrides)
19
+ */
20
+ static get [Symbol.species](): typeof Uint8Array;
16
21
  constructor(registry: Registry, value?: AnyU8a, initialU8aLength?: number);
17
22
  /**
18
23
  * @description The length of the value when encoded as a Uint8Array
@@ -34,10 +39,6 @@ export declare class Raw extends Uint8Array implements IU8a {
34
39
  * @description Returns true if the wrapped value contains only utf8 characters
35
40
  */
36
41
  get isUtf8(): boolean;
37
- /**
38
- * @description The length of the value
39
- */
40
- get length(): number;
41
42
  /**
42
43
  * @description Returns the number of bits in the value
43
44
  */
@@ -50,18 +51,6 @@ export declare class Raw extends Uint8Array implements IU8a {
50
51
  * @description Returns a breakdown of the hex encoding for this Codec
51
52
  */
52
53
  inspect(): Inspect;
53
- /**
54
- * @description Create a new slice from the actual buffer. (compat)
55
- * @param start The position to start at
56
- * @param end The position to end at
57
- */
58
- slice(start?: number, end?: number): Uint8Array;
59
- /**
60
- * @description Create a new subarray from the actual buffer. (compat)
61
- * @param begin The position to start at
62
- * @param end The position to end at
63
- */
64
- subarray(begin?: number, end?: number): Uint8Array;
65
54
  /**
66
55
  * @description Returns a hex string representation of the value
67
56
  */
package/native/Raw.js CHANGED
@@ -12,6 +12,14 @@ import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@
12
12
  */
13
13
 
14
14
  export class Raw extends Uint8Array {
15
+ /**
16
+ * @description This ensures that operators such as clice, filter, map, etc. return
17
+ * new Array instances (without this we need to apply overrides)
18
+ */
19
+ static get [Symbol.species]() {
20
+ return Uint8Array;
21
+ }
22
+
15
23
  constructor(registry, value, initialU8aLength) {
16
24
  super(u8aToU8a(value));
17
25
  this.registry = registry;
@@ -57,15 +65,6 @@ export class Raw extends Uint8Array {
57
65
  get isUtf8() {
58
66
  return isUtf8(this);
59
67
  }
60
- /**
61
- * @description The length of the value
62
- */
63
-
64
-
65
- get length() {
66
- // only included here since we ignore inherited docs
67
- return super.length;
68
- }
69
68
  /**
70
69
  * @description Returns the number of bits in the value
71
70
  */
@@ -96,28 +95,6 @@ export class Raw extends Uint8Array {
96
95
  outer: [this.toU8a()]
97
96
  };
98
97
  }
99
- /**
100
- * @description Create a new slice from the actual buffer. (compat)
101
- * @param start The position to start at
102
- * @param end The position to end at
103
- */
104
-
105
-
106
- slice(start, end) {
107
- // Like subarray below, we have to follow this approach since we are extending the TypeArray.
108
- // This happens especially when it comes to further extensions, the length may be an override
109
- return Uint8Array.from(this).slice(start, end);
110
- }
111
- /**
112
- * @description Create a new subarray from the actual buffer. (compat)
113
- * @param begin The position to start at
114
- * @param end The position to end at
115
- */
116
-
117
-
118
- subarray(begin, end) {
119
- return Uint8Array.from(this).subarray(begin, end);
120
- }
121
98
  /**
122
99
  * @description Returns a hex string representation of the value
123
100
  */
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.9.2-1",
23
+ "version": "8.9.2-4",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
@@ -47,6 +47,11 @@
47
47
  "require": "./cjs/abstract/Base.js",
48
48
  "default": "./abstract/Base.js"
49
49
  },
50
+ "./abstract/BigInt": {
51
+ "types": "./abstract/BigInt.d.ts",
52
+ "require": "./cjs/abstract/BigInt.js",
53
+ "default": "./abstract/BigInt.js"
54
+ },
50
55
  "./abstract/Int": {
51
56
  "types": "./abstract/Int.d.ts",
52
57
  "require": "./cjs/abstract/Int.js",
@@ -415,6 +420,7 @@
415
420
  },
416
421
  "dependencies": {
417
422
  "@babel/runtime": "^7.18.3",
418
- "@polkadot/util": "^9.5.1"
423
+ "@polkadot/util": "^9.5.1",
424
+ "@polkadot/x-bigint": "^9.5.1"
419
425
  }
420
426
  }
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.9.2-1'
8
+ version: '8.9.2-4'
9
9
  };