@polkadot/types-codec 8.9.2-1 → 8.9.2-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.
@@ -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;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Float = void 0;
7
+
8
+ var _util = require("@polkadot/util");
9
+
10
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @name Float
15
+ * @description
16
+ * A Codec wrapper for F32 & F64 values. You generally don't want to be using
17
+ * f32/f64 in your runtime, operations on fixed points numbers are preferable. This class
18
+ * was explicitly added since scale-codec has a flag that enables this and it is available
19
+ * in some eth_* RPCs
20
+ */
21
+ class Float extends Number {
22
+ #bitLength;
23
+
24
+ constructor(registry, value) {
25
+ let {
26
+ bitLength = 32
27
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
28
+ super((0, _util.isU8a)(value) || (0, _util.isHex)(value) ? value.length === 0 ? 0 : (0, _util.u8aToFloat)((0, _util.u8aToU8a)(value), {
29
+ bitLength
30
+ }) : value || 0);
31
+ this.#bitLength = bitLength;
32
+ this.encodedLength = bitLength / 8;
33
+ this.initialU8aLength = this.encodedLength;
34
+ this.registry = registry;
35
+ }
36
+
37
+ static with(bitLength) {
38
+ return class extends Float {
39
+ constructor(registry, value) {
40
+ super(registry, value, {
41
+ bitLength
42
+ });
43
+ }
44
+
45
+ };
46
+ }
47
+ /**
48
+ * @description returns a hash of the contents
49
+ */
50
+
51
+
52
+ get hash() {
53
+ return this.registry.hash(this.toU8a());
54
+ }
55
+ /**
56
+ * @description Returns true if the type wraps an empty/default all-0 value
57
+ */
58
+
59
+
60
+ get isEmpty() {
61
+ return this.valueOf() === 0;
62
+ }
63
+ /**
64
+ * @description Compares the value of the input to see if there is a match
65
+ */
66
+
67
+
68
+ eq(other) {
69
+ return this.valueOf() === Number(other);
70
+ }
71
+ /**
72
+ * @description Returns a breakdown of the hex encoding for this Codec
73
+ */
74
+
75
+
76
+ inspect() {
77
+ return {
78
+ outer: [this.toU8a()]
79
+ };
80
+ }
81
+ /**
82
+ * @description Returns a hex string representation of the value
83
+ */
84
+
85
+
86
+ toHex() {
87
+ return (0, _util.u8aToHex)(this.toU8a());
88
+ }
89
+ /**
90
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
91
+ */
92
+
93
+
94
+ toHuman() {
95
+ return this.toString();
96
+ }
97
+ /**
98
+ * @description Converts the Object to JSON, typically used for RPC transfers
99
+ */
100
+
101
+
102
+ toJSON() {
103
+ // Not sure if this is actually a hex or a string value
104
+ // (would need to check against RPCs to see the result here)
105
+ return this.toHex();
106
+ }
107
+ /**
108
+ * @description Returns the number representation (Same as valueOf)
109
+ */
110
+
111
+
112
+ toNumber() {
113
+ return this.valueOf();
114
+ }
115
+ /**
116
+ * @description Returns the base runtime type name for this instance
117
+ */
118
+
119
+
120
+ toRawType() {
121
+ return `f${this.#bitLength}`;
122
+ }
123
+ /**
124
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
125
+ */
126
+
127
+
128
+ toU8a() {
129
+ return (0, _util.floatToU8a)(this, {
130
+ bitLength: this.#bitLength
131
+ });
132
+ }
133
+
134
+ }
135
+
136
+ exports.Float = Float;
@@ -68,6 +68,10 @@ class Json extends Map {
68
68
  eq(other) {
69
69
  return (0, _utils.compareMap)(this, other);
70
70
  }
71
+ /**
72
+ * @description Returns a typed value from the internal map
73
+ */
74
+
71
75
 
72
76
  getT(key) {
73
77
  return this.get(key);
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
  */
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "Date", {
27
27
  return _Date.CodecDate;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "Float", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _Float.Float;
34
+ }
35
+ });
30
36
  Object.defineProperty(exports, "Json", {
31
37
  enumerable: true,
32
38
  get: function () {
@@ -68,6 +74,8 @@ var _Bool = require("./Bool");
68
74
 
69
75
  var _Date = require("./Date");
70
76
 
77
+ var _Float = require("./Float");
78
+
71
79
  var _Json = require("./Json");
72
80
 
73
81
  var _Raw = require("./Raw");
@@ -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-12'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.f32 = void 0;
7
+
8
+ var _Float = require("../native/Float");
9
+
10
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @name f32
15
+ * @description
16
+ * A 32-bit float
17
+ */
18
+ class f32 extends _Float.Float.with(32) {
19
+ // NOTE without this, we cannot properly determine extensions
20
+ __FloatType = 'f32';
21
+ }
22
+
23
+ exports.f32 = f32;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.f64 = void 0;
7
+
8
+ var _Float = require("../native/Float");
9
+
10
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @name f64
15
+ * @description
16
+ * A 64-bit float
17
+ */
18
+ class f64 extends _Float.Float.with(64) {
19
+ // NOTE without this, we cannot properly determine extensions
20
+ __FloatType = 'f64';
21
+ }
22
+
23
+ exports.f64 = f64;
@@ -3,6 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "F32", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _F.f32;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "F64", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _F2.f64;
16
+ }
17
+ });
6
18
  Object.defineProperty(exports, "I128", {
7
19
  enumerable: true,
8
20
  get: function () {
@@ -81,6 +93,18 @@ Object.defineProperty(exports, "USize", {
81
93
  return _USize.usize;
82
94
  }
83
95
  });
96
+ Object.defineProperty(exports, "f32", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _F.f32;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "f64", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _F2.f64;
106
+ }
107
+ });
84
108
  Object.defineProperty(exports, "i128", {
85
109
  enumerable: true,
86
110
  get: function () {
@@ -160,6 +184,10 @@ Object.defineProperty(exports, "usize", {
160
184
  }
161
185
  });
162
186
 
187
+ var _F = require("./F32");
188
+
189
+ var _F2 = require("./F64");
190
+
163
191
  var _I = require("./I8");
164
192
 
165
193
  var _I2 = require("./I16");
package/mod.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './index';
package/mod.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './index';
@@ -0,0 +1,63 @@
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../types';
3
+ interface Options {
4
+ bitLength?: 32 | 64;
5
+ }
6
+ /**
7
+ * @name Float
8
+ * @description
9
+ * A Codec wrapper for F32 & F64 values. You generally don't want to be using
10
+ * f32/f64 in your runtime, operations on fixed points numbers are preferable. This class
11
+ * was explicitly added since scale-codec has a flag that enables this and it is available
12
+ * in some eth_* RPCs
13
+ */
14
+ export declare class Float extends Number implements IFloat {
15
+ #private;
16
+ createdAtHash?: IU8a;
17
+ readonly encodedLength: number;
18
+ readonly initialU8aLength?: number;
19
+ readonly registry: Registry;
20
+ constructor(registry: Registry, value?: AnyFloat, { bitLength }?: Options);
21
+ static with(bitLength: 32 | 64): CodecClass<Float>;
22
+ /**
23
+ * @description returns a hash of the contents
24
+ */
25
+ get hash(): IU8a;
26
+ /**
27
+ * @description Returns true if the type wraps an empty/default all-0 value
28
+ */
29
+ get isEmpty(): boolean;
30
+ /**
31
+ * @description Compares the value of the input to see if there is a match
32
+ */
33
+ eq(other?: unknown): boolean;
34
+ /**
35
+ * @description Returns a breakdown of the hex encoding for this Codec
36
+ */
37
+ inspect(): Inspect;
38
+ /**
39
+ * @description Returns a hex string representation of the value
40
+ */
41
+ toHex(): HexString;
42
+ /**
43
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
44
+ */
45
+ toHuman(): string;
46
+ /**
47
+ * @description Converts the Object to JSON, typically used for RPC transfers
48
+ */
49
+ toJSON(): string;
50
+ /**
51
+ * @description Returns the number representation (Same as valueOf)
52
+ */
53
+ toNumber(): number;
54
+ /**
55
+ * @description Returns the base runtime type name for this instance
56
+ */
57
+ toRawType(): string;
58
+ /**
59
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
60
+ */
61
+ toU8a(): Uint8Array;
62
+ }
63
+ export {};
@@ -0,0 +1,125 @@
1
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
4
+
5
+ /**
6
+ * @name Float
7
+ * @description
8
+ * A Codec wrapper for F32 & F64 values. You generally don't want to be using
9
+ * f32/f64 in your runtime, operations on fixed points numbers are preferable. This class
10
+ * was explicitly added since scale-codec has a flag that enables this and it is available
11
+ * in some eth_* RPCs
12
+ */
13
+ export class Float extends Number {
14
+ #bitLength;
15
+
16
+ constructor(registry, value, {
17
+ bitLength = 32
18
+ } = {}) {
19
+ super(isU8a(value) || isHex(value) ? value.length === 0 ? 0 : u8aToFloat(u8aToU8a(value), {
20
+ bitLength
21
+ }) : value || 0);
22
+ this.#bitLength = bitLength;
23
+ this.encodedLength = bitLength / 8;
24
+ this.initialU8aLength = this.encodedLength;
25
+ this.registry = registry;
26
+ }
27
+
28
+ static with(bitLength) {
29
+ return class extends Float {
30
+ constructor(registry, value) {
31
+ super(registry, value, {
32
+ bitLength
33
+ });
34
+ }
35
+
36
+ };
37
+ }
38
+ /**
39
+ * @description returns a hash of the contents
40
+ */
41
+
42
+
43
+ get hash() {
44
+ return this.registry.hash(this.toU8a());
45
+ }
46
+ /**
47
+ * @description Returns true if the type wraps an empty/default all-0 value
48
+ */
49
+
50
+
51
+ get isEmpty() {
52
+ return this.valueOf() === 0;
53
+ }
54
+ /**
55
+ * @description Compares the value of the input to see if there is a match
56
+ */
57
+
58
+
59
+ eq(other) {
60
+ return this.valueOf() === Number(other);
61
+ }
62
+ /**
63
+ * @description Returns a breakdown of the hex encoding for this Codec
64
+ */
65
+
66
+
67
+ inspect() {
68
+ return {
69
+ outer: [this.toU8a()]
70
+ };
71
+ }
72
+ /**
73
+ * @description Returns a hex string representation of the value
74
+ */
75
+
76
+
77
+ toHex() {
78
+ return u8aToHex(this.toU8a());
79
+ }
80
+ /**
81
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
82
+ */
83
+
84
+
85
+ toHuman() {
86
+ return this.toString();
87
+ }
88
+ /**
89
+ * @description Converts the Object to JSON, typically used for RPC transfers
90
+ */
91
+
92
+
93
+ toJSON() {
94
+ // Not sure if this is actually a hex or a string value
95
+ // (would need to check against RPCs to see the result here)
96
+ return this.toHex();
97
+ }
98
+ /**
99
+ * @description Returns the number representation (Same as valueOf)
100
+ */
101
+
102
+
103
+ toNumber() {
104
+ return this.valueOf();
105
+ }
106
+ /**
107
+ * @description Returns the base runtime type name for this instance
108
+ */
109
+
110
+
111
+ toRawType() {
112
+ return `f${this.#bitLength}`;
113
+ }
114
+ /**
115
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
116
+ */
117
+
118
+
119
+ toU8a() {
120
+ return floatToU8a(this, {
121
+ bitLength: this.#bitLength
122
+ });
123
+ }
124
+
125
+ }
package/native/Json.d.ts CHANGED
@@ -28,6 +28,9 @@ export declare class Json extends Map<string, any> implements Codec {
28
28
  * @description Compares the value of the input to see if there is a match
29
29
  */
30
30
  eq(other?: unknown): boolean;
31
+ /**
32
+ * @description Returns a typed value from the internal map
33
+ */
31
34
  getT<T>(key: string): T;
32
35
  /**
33
36
  * @description Unimplemented, will throw
package/native/Json.js CHANGED
@@ -56,6 +56,10 @@ export class Json extends Map {
56
56
  eq(other) {
57
57
  return compareMap(this, other);
58
58
  }
59
+ /**
60
+ * @description Returns a typed value from the internal map
61
+ */
62
+
59
63
 
60
64
  getT(key) {
61
65
  return this.get(key);
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/native/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { bool, bool as Bool } from './Bool';
2
2
  export { CodecDate, CodecDate as Date } from './Date';
3
+ export { Float } from './Float';
3
4
  export { Json } from './Json';
4
5
  export { Raw } from './Raw';
5
6
  export { CodecSet, CodecSet as Set } from './Set';
package/native/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export { bool, bool as Bool } from "./Bool.js";
4
4
  export { CodecDate, CodecDate as Date } from "./Date.js";
5
+ export { Float } from "./Float.js";
5
6
  export { Json } from "./Json.js";
6
7
  export { Raw } from "./Raw.js";
7
8
  export { CodecSet, CodecSet as Set } from "./Set.js";
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-12",
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",
@@ -207,6 +212,8 @@
207
212
  "require": "./cjs/extended/WrapperOpaque.js",
208
213
  "default": "./extended/WrapperOpaque.js"
209
214
  },
215
+ "./mod.d.ts": "./mod.d.ts",
216
+ "./mod.ts": "./mod.ts",
210
217
  "./native": {
211
218
  "types": "./native/index.d.ts",
212
219
  "require": "./cjs/native/index.js",
@@ -222,6 +229,11 @@
222
229
  "require": "./cjs/native/Date.js",
223
230
  "default": "./native/Date.js"
224
231
  },
232
+ "./native/Float": {
233
+ "types": "./native/Float.d.ts",
234
+ "require": "./cjs/native/Float.js",
235
+ "default": "./native/Float.js"
236
+ },
225
237
  "./native/Json": {
226
238
  "types": "./native/Json.d.ts",
227
239
  "require": "./cjs/native/Json.js",
@@ -267,6 +279,16 @@
267
279
  "require": "./cjs/primitive/index.js",
268
280
  "default": "./primitive/index.js"
269
281
  },
282
+ "./primitive/F32": {
283
+ "types": "./primitive/F32.d.ts",
284
+ "require": "./cjs/primitive/F32.js",
285
+ "default": "./primitive/F32.js"
286
+ },
287
+ "./primitive/F64": {
288
+ "types": "./primitive/F64.d.ts",
289
+ "require": "./cjs/primitive/F64.js",
290
+ "default": "./primitive/F64.js"
291
+ },
270
292
  "./primitive/I128": {
271
293
  "types": "./primitive/I128.d.ts",
272
294
  "require": "./cjs/primitive/I128.js",
@@ -415,6 +437,7 @@
415
437
  },
416
438
  "dependencies": {
417
439
  "@babel/runtime": "^7.18.3",
418
- "@polkadot/util": "^9.5.1"
440
+ "@polkadot/util": "^9.5.2-18",
441
+ "@polkadot/x-bigint": "^9.5.2-18"
419
442
  }
420
443
  }
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-12'
9
9
  };
@@ -0,0 +1,11 @@
1
+ import { Float } from '../native/Float';
2
+ declare const f32_base: import("../types").CodecClass<Float>;
3
+ /**
4
+ * @name f32
5
+ * @description
6
+ * A 32-bit float
7
+ */
8
+ export declare class f32 extends f32_base {
9
+ readonly __FloatType = "f32";
10
+ }
11
+ export {};
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Float } from "../native/Float.js";
4
+ /**
5
+ * @name f32
6
+ * @description
7
+ * A 32-bit float
8
+ */
9
+
10
+ export class f32 extends Float.with(32) {
11
+ // NOTE without this, we cannot properly determine extensions
12
+ __FloatType = 'f32';
13
+ }
@@ -0,0 +1,11 @@
1
+ import { Float } from '../native/Float';
2
+ declare const f64_base: import("../types").CodecClass<Float>;
3
+ /**
4
+ * @name f64
5
+ * @description
6
+ * A 64-bit float
7
+ */
8
+ export declare class f64 extends f64_base {
9
+ readonly __FloatType = "f64";
10
+ }
11
+ export {};
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Float } from "../native/Float.js";
4
+ /**
5
+ * @name f64
6
+ * @description
7
+ * A 64-bit float
8
+ */
9
+
10
+ export class f64 extends Float.with(64) {
11
+ // NOTE without this, we cannot properly determine extensions
12
+ __FloatType = 'f64';
13
+ }
@@ -1,3 +1,5 @@
1
+ export { f32, f32 as F32 } from './F32';
2
+ export { f64, f64 as F64 } from './F64';
1
3
  export { i8, i8 as I8 } from './I8';
2
4
  export { i16, i16 as I16 } from './I16';
3
5
  export { i32, i32 as I32 } from './I32';
@@ -1,5 +1,7 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ export { f32, f32 as F32 } from "./F32.js";
4
+ export { f64, f64 as F64 } from "./F64.js";
3
5
  export { i8, i8 as I8 } from "./I8.js";
4
6
  export { i16, i16 as I16 } from "./I16.js";
5
7
  export { i32, i32 as I32 } from "./I32.js";
@@ -6,6 +6,7 @@ export declare type AnyJson = string | number | boolean | null | undefined | Any
6
6
  };
7
7
  export declare type AnyFunction = (...args: any[]) => any;
8
8
  export declare type AnyNumber = BN | bigint | Uint8Array | number | string;
9
+ export declare type AnyFloat = Number | number | Uint8Array | string;
9
10
  export declare type AnyString = String | string;
10
11
  export declare type AnyBool = Boolean | boolean;
11
12
  export declare type AnyTuple = Codec[];
@@ -25,6 +25,9 @@ export interface INumber extends Codec {
25
25
  toBn(): BN;
26
26
  toNumber(): number;
27
27
  }
28
+ export interface IFloat extends Codec {
29
+ toNumber(): number;
30
+ }
28
31
  export interface IOption<T extends Codec = Codec> extends Codec {
29
32
  readonly isNone: boolean;
30
33
  readonly isSome: boolean;