@polkadot/types-codec 6.12.2-2
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/abstract/AbstractArray.cjs +208 -0
- package/abstract/AbstractArray.d.ts +84 -0
- package/abstract/AbstractArray.js +197 -0
- package/abstract/AbstractInt.cjs +254 -0
- package/abstract/AbstractInt.d.ts +75 -0
- package/abstract/AbstractInt.js +231 -0
- package/abstract/index.cjs +21 -0
- package/abstract/index.d.ts +2 -0
- package/abstract/index.js +4 -0
- package/base/Base.cjs +109 -0
- package/base/Base.d.ts +54 -0
- package/base/Base.js +100 -0
- package/base/Compact.cjs +201 -0
- package/base/Compact.d.ts +83 -0
- package/base/Compact.js +186 -0
- package/base/DoNotConstruct.cjs +101 -0
- package/base/DoNotConstruct.d.ts +33 -0
- package/base/DoNotConstruct.js +88 -0
- package/base/Enum.cjs +437 -0
- package/base/Enum.d.ts +101 -0
- package/base/Enum.js +413 -0
- package/base/Int.cjs +45 -0
- package/base/Int.d.ts +16 -0
- package/base/Int.js +33 -0
- package/base/Null.cjs +111 -0
- package/base/Null.d.ts +54 -0
- package/base/Null.js +101 -0
- package/base/Option.cjs +256 -0
- package/base/Option.d.ts +88 -0
- package/base/Option.js +240 -0
- package/base/Result.cjs +109 -0
- package/base/Result.d.ts +46 -0
- package/base/Result.js +98 -0
- package/base/Tuple.cjs +132 -0
- package/base/Tuple.d.ts +39 -0
- package/base/Tuple.js +116 -0
- package/base/UInt.cjs +39 -0
- package/base/UInt.d.ts +15 -0
- package/base/UInt.js +29 -0
- package/base/Vec.cjs +126 -0
- package/base/Vec.d.ts +28 -0
- package/base/Vec.js +104 -0
- package/base/VecAny.cjs +31 -0
- package/base/VecAny.d.ts +15 -0
- package/base/VecAny.js +21 -0
- package/base/VecFixed.cjs +111 -0
- package/base/VecFixed.d.ts +26 -0
- package/base/VecFixed.js +93 -0
- package/base/index.cjs +109 -0
- package/base/index.d.ts +13 -0
- package/base/index.js +15 -0
- package/bundle.cjs +100 -0
- package/bundle.d.ts +7 -0
- package/bundle.js +9 -0
- package/detectPackage.cjs +9 -0
- package/detectPackage.d.ts +1 -0
- package/detectPackage.js +5 -0
- package/extended/BTreeMap.cjs +24 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +14 -0
- package/extended/BTreeSet.cjs +227 -0
- package/extended/BTreeSet.d.ts +55 -0
- package/extended/BTreeSet.js +212 -0
- package/extended/BitVec.cjs +97 -0
- package/extended/BitVec.d.ts +26 -0
- package/extended/BitVec.js +82 -0
- package/extended/Bytes.cjs +86 -0
- package/extended/Bytes.d.ts +25 -0
- package/extended/Bytes.js +75 -0
- package/extended/HashMap.cjs +24 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +14 -0
- package/extended/Linkage.cjs +89 -0
- package/extended/Linkage.d.ts +31 -0
- package/extended/Linkage.js +71 -0
- package/extended/Map.cjs +244 -0
- package/extended/Map.d.ts +50 -0
- package/extended/Map.js +225 -0
- package/extended/Range.cjs +92 -0
- package/extended/Range.d.ts +30 -0
- package/extended/Range.js +75 -0
- package/extended/Type.cjs +39 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +27 -0
- package/extended/U8aFixed.cjs +66 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +53 -0
- package/extended/WrapperOpaque.cjs +68 -0
- package/extended/WrapperOpaque.d.ts +18 -0
- package/extended/WrapperOpaque.js +57 -0
- package/extended/index.cjs +105 -0
- package/extended/index.d.ts +11 -0
- package/extended/index.js +13 -0
- package/index.cjs +20 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/native/Bool.cjs +141 -0
- package/native/Bool.d.ts +62 -0
- package/native/Bool.js +130 -0
- package/native/Date.cjs +170 -0
- package/native/Date.d.ts +76 -0
- package/native/Date.js +158 -0
- package/native/Json.cjs +133 -0
- package/native/Json.d.ts +55 -0
- package/native/Json.js +117 -0
- package/native/Raw.cjs +192 -0
- package/native/Raw.d.ts +90 -0
- package/native/Raw.js +182 -0
- package/native/Set.cjs +268 -0
- package/native/Set.d.ts +76 -0
- package/native/Set.js +251 -0
- package/native/Struct.cjs +289 -0
- package/native/Struct.d.ts +92 -0
- package/native/Struct.js +273 -0
- package/native/Text.cjs +193 -0
- package/native/Text.d.ts +71 -0
- package/native/Text.js +178 -0
- package/native/index.cjs +79 -0
- package/native/index.d.ts +7 -0
- package/native/index.js +9 -0
- package/package.json +387 -0
- package/packageInfo.cjs +14 -0
- package/packageInfo.d.ts +4 -0
- package/packageInfo.js +7 -0
- package/primitive/I128.cjs +26 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +16 -0
- package/primitive/I16.cjs +26 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +16 -0
- package/primitive/I256.cjs +26 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +16 -0
- package/primitive/I32.cjs +26 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +16 -0
- package/primitive/I64.cjs +26 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +16 -0
- package/primitive/I8.cjs +26 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +16 -0
- package/primitive/U128.cjs +26 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +16 -0
- package/primitive/U16.cjs +26 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +16 -0
- package/primitive/U256.cjs +26 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +16 -0
- package/primitive/U32.cjs +26 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +16 -0
- package/primitive/U64.cjs +26 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +16 -0
- package/primitive/U8.cjs +26 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +16 -0
- package/primitive/USize.cjs +28 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +18 -0
- package/primitive/index.cjs +187 -0
- package/primitive/index.d.ts +13 -0
- package/primitive/index.js +15 -0
- package/types/codec.cjs +1 -0
- package/types/codec.d.ts +77 -0
- package/types/codec.js +1 -0
- package/types/helpers.cjs +1 -0
- package/types/helpers.d.ts +14 -0
- package/types/helpers.js +1 -0
- package/types/index.cjs +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +6 -0
- package/types/interfaces.cjs +1 -0
- package/types/interfaces.d.ts +68 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +44 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.cjs +22 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +13 -0
- package/utils/compareMap.cjs +39 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +31 -0
- package/utils/compareSet.cjs +29 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +22 -0
- package/utils/decodeU8a.cjs +69 -0
- package/utils/decodeU8a.d.ts +13 -0
- package/utils/decodeU8a.js +60 -0
- package/utils/index.cjs +95 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +11 -0
- package/utils/mapToTypeMap.cjs +25 -0
- package/utils/mapToTypeMap.d.ts +5 -0
- package/utils/mapToTypeMap.js +17 -0
- package/utils/sanitize.cjs +242 -0
- package/utils/sanitize.d.ts +16 -0
- package/utils/sanitize.js +215 -0
- package/utils/sortValues.cjs +89 -0
- package/utils/sortValues.d.ts +13 -0
- package/utils/sortValues.js +73 -0
- package/utils/typeToConstructor.cjs +14 -0
- package/utils/typeToConstructor.d.ts +2 -0
- package/utils/typeToConstructor.js +6 -0
- package/utils/typesToMap.cjs +20 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +13 -0
- package/utils/util.cjs +15 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +7 -0
package/native/Date.cjs
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CodecDate = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
const BITLENGTH = 64;
|
|
13
|
+
|
|
14
|
+
function decodeDate(value) {
|
|
15
|
+
if ((0, _util.isU8a)(value)) {
|
|
16
|
+
value = (0, _util.u8aToBn)(value.subarray(0, BITLENGTH / 8), true);
|
|
17
|
+
} else if (value instanceof Date) {
|
|
18
|
+
return value;
|
|
19
|
+
} else if ((0, _util.isString)(value)) {
|
|
20
|
+
value = new _util.BN(value.toString(), 10, 'le');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return new Date((0, _util.bnToBn)(value).toNumber() * 1000);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @name Date
|
|
27
|
+
* @description
|
|
28
|
+
* A wrapper around seconds/timestamps. Internally the representation only has
|
|
29
|
+
* second precicion (aligning with Rust), so any numbers passed an/out are always
|
|
30
|
+
* per-second. For any encoding/decoding the 1000 multiplier would be applied to
|
|
31
|
+
* get it in line with JavaScript formats. It extends the base JS `Date` object
|
|
32
|
+
* and has all the methods available that are applicable to any `Date`
|
|
33
|
+
* @noInheritDoc
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CodecDate extends Date {
|
|
38
|
+
constructor(registry) {
|
|
39
|
+
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
40
|
+
super(decodeDate(value));
|
|
41
|
+
this.registry = void 0;
|
|
42
|
+
this.createdAtHash = void 0;
|
|
43
|
+
this.registry = registry;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
get encodedLength() {
|
|
51
|
+
return BITLENGTH / 8;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description returns a hash of the contents
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
get hash() {
|
|
59
|
+
return this.registry.hash(this.toU8a());
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description Checks if the value is an empty value
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
get isEmpty() {
|
|
67
|
+
return this.getTime() === 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description Compares the value of the input to see if there is a match
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
eq(other) {
|
|
75
|
+
return decodeDate(other).getTime() === this.getTime();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @description Returns the number of bits in the value
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
bitLength() {
|
|
83
|
+
return BITLENGTH;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @description Returns a BigInt representation of the number
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
toBigInt() {
|
|
91
|
+
return BigInt(this.toNumber());
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @description Returns the BN representation of the timestamp
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
toBn() {
|
|
99
|
+
return new _util.BN(this.toNumber());
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @description Returns a hex string representation of the value
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
toHex() {
|
|
107
|
+
let isLe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
108
|
+
return (0, _util.bnToHex)(this.toBn(), {
|
|
109
|
+
bitLength: BITLENGTH,
|
|
110
|
+
isLe,
|
|
111
|
+
isNegative: false
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
toHuman() {
|
|
120
|
+
return this.toISOString();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toJSON() {
|
|
128
|
+
// FIXME Return type should be number, but conflicts with Date.toJSON()
|
|
129
|
+
// which returns string
|
|
130
|
+
return this.toNumber();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @description Returns the number representation for the timestamp
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
toNumber() {
|
|
138
|
+
return Math.ceil(this.getTime() / 1000);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @description Returns the base runtime type name for this instance
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
toRawType() {
|
|
146
|
+
return 'Moment';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @description Returns the string representation of the value
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
toString() {
|
|
154
|
+
// only included here since we do not inherit docs
|
|
155
|
+
return super.toString();
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
159
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
160
|
+
*/
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
toU8a(isBare) {
|
|
165
|
+
return (0, _util.bnToU8a)(this.toNumber(), BITLENGTH, true);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
exports.CodecDate = CodecDate;
|
package/native/Date.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import type { HexString } from '@polkadot/util/types';
|
|
3
|
+
import type { AnyNumber, CodecRegistry, INumber, IU8a, UIntBitLength } from '../types';
|
|
4
|
+
import { BN } from '@polkadot/util';
|
|
5
|
+
/**
|
|
6
|
+
* @name Date
|
|
7
|
+
* @description
|
|
8
|
+
* A wrapper around seconds/timestamps. Internally the representation only has
|
|
9
|
+
* second precicion (aligning with Rust), so any numbers passed an/out are always
|
|
10
|
+
* per-second. For any encoding/decoding the 1000 multiplier would be applied to
|
|
11
|
+
* get it in line with JavaScript formats. It extends the base JS `Date` object
|
|
12
|
+
* and has all the methods available that are applicable to any `Date`
|
|
13
|
+
* @noInheritDoc
|
|
14
|
+
*/
|
|
15
|
+
export declare class CodecDate extends Date implements INumber {
|
|
16
|
+
readonly registry: CodecRegistry;
|
|
17
|
+
createdAtHash?: IU8a;
|
|
18
|
+
constructor(registry: CodecRegistry, value?: CodecDate | Date | AnyNumber);
|
|
19
|
+
/**
|
|
20
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
21
|
+
*/
|
|
22
|
+
get encodedLength(): number;
|
|
23
|
+
/**
|
|
24
|
+
* @description returns a hash of the contents
|
|
25
|
+
*/
|
|
26
|
+
get hash(): IU8a;
|
|
27
|
+
/**
|
|
28
|
+
* @description Checks if the value is an empty value
|
|
29
|
+
*/
|
|
30
|
+
get isEmpty(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @description Compares the value of the input to see if there is a match
|
|
33
|
+
*/
|
|
34
|
+
eq(other?: unknown): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* @description Returns the number of bits in the value
|
|
37
|
+
*/
|
|
38
|
+
bitLength(): UIntBitLength;
|
|
39
|
+
/**
|
|
40
|
+
* @description Returns a BigInt representation of the number
|
|
41
|
+
*/
|
|
42
|
+
toBigInt(): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* @description Returns the BN representation of the timestamp
|
|
45
|
+
*/
|
|
46
|
+
toBn(): BN;
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns a hex string representation of the value
|
|
49
|
+
*/
|
|
50
|
+
toHex(isLe?: boolean): HexString;
|
|
51
|
+
/**
|
|
52
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
53
|
+
*/
|
|
54
|
+
toHuman(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
57
|
+
*/
|
|
58
|
+
toJSON(): any;
|
|
59
|
+
/**
|
|
60
|
+
* @description Returns the number representation for the timestamp
|
|
61
|
+
*/
|
|
62
|
+
toNumber(): number;
|
|
63
|
+
/**
|
|
64
|
+
* @description Returns the base runtime type name for this instance
|
|
65
|
+
*/
|
|
66
|
+
toRawType(): string;
|
|
67
|
+
/**
|
|
68
|
+
* @description Returns the string representation of the value
|
|
69
|
+
*/
|
|
70
|
+
toString(): string;
|
|
71
|
+
/**
|
|
72
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
73
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
74
|
+
*/
|
|
75
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
76
|
+
}
|
package/native/Date.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
|
4
|
+
const BITLENGTH = 64;
|
|
5
|
+
|
|
6
|
+
function decodeDate(value) {
|
|
7
|
+
if (isU8a(value)) {
|
|
8
|
+
value = u8aToBn(value.subarray(0, BITLENGTH / 8), true);
|
|
9
|
+
} else if (value instanceof Date) {
|
|
10
|
+
return value;
|
|
11
|
+
} else if (isString(value)) {
|
|
12
|
+
value = new BN(value.toString(), 10, 'le');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return new Date(bnToBn(value).toNumber() * 1000);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @name Date
|
|
19
|
+
* @description
|
|
20
|
+
* A wrapper around seconds/timestamps. Internally the representation only has
|
|
21
|
+
* second precicion (aligning with Rust), so any numbers passed an/out are always
|
|
22
|
+
* per-second. For any encoding/decoding the 1000 multiplier would be applied to
|
|
23
|
+
* get it in line with JavaScript formats. It extends the base JS `Date` object
|
|
24
|
+
* and has all the methods available that are applicable to any `Date`
|
|
25
|
+
* @noInheritDoc
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export class CodecDate extends Date {
|
|
30
|
+
constructor(registry, value = 0) {
|
|
31
|
+
super(decodeDate(value));
|
|
32
|
+
this.registry = void 0;
|
|
33
|
+
this.createdAtHash = void 0;
|
|
34
|
+
this.registry = registry;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
get encodedLength() {
|
|
42
|
+
return BITLENGTH / 8;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @description returns a hash of the contents
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
get hash() {
|
|
50
|
+
return this.registry.hash(this.toU8a());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @description Checks if the value is an empty value
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
get isEmpty() {
|
|
58
|
+
return this.getTime() === 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @description Compares the value of the input to see if there is a match
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
eq(other) {
|
|
66
|
+
return decodeDate(other).getTime() === this.getTime();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @description Returns the number of bits in the value
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
bitLength() {
|
|
74
|
+
return BITLENGTH;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @description Returns a BigInt representation of the number
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
toBigInt() {
|
|
82
|
+
return BigInt(this.toNumber());
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description Returns the BN representation of the timestamp
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
toBn() {
|
|
90
|
+
return new BN(this.toNumber());
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @description Returns a hex string representation of the value
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
toHex(isLe = false) {
|
|
98
|
+
return bnToHex(this.toBn(), {
|
|
99
|
+
bitLength: BITLENGTH,
|
|
100
|
+
isLe,
|
|
101
|
+
isNegative: false
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
toHuman() {
|
|
110
|
+
return this.toISOString();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
toJSON() {
|
|
118
|
+
// FIXME Return type should be number, but conflicts with Date.toJSON()
|
|
119
|
+
// which returns string
|
|
120
|
+
return this.toNumber();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Returns the number representation for the timestamp
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toNumber() {
|
|
128
|
+
return Math.ceil(this.getTime() / 1000);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @description Returns the base runtime type name for this instance
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
toRawType() {
|
|
136
|
+
return 'Moment';
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @description Returns the string representation of the value
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
toString() {
|
|
144
|
+
// only included here since we do not inherit docs
|
|
145
|
+
return super.toString();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
149
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
150
|
+
*/
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
toU8a(isBare) {
|
|
155
|
+
return bnToU8a(this.toNumber(), BITLENGTH, true);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
package/native/Json.cjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Json = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _index = require("../utils/index.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
function decodeJson(value) {
|
|
17
|
+
return Object.entries(value || {});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @name Json
|
|
21
|
+
* @description
|
|
22
|
+
* Wraps the a JSON structure retrieve via RPC. It extends the standard JS Map with. While it
|
|
23
|
+
* implements a Codec, it is limited in that it can only be used with input objects via RPC,
|
|
24
|
+
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
|
|
25
|
+
* @noInheritDoc
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Json extends Map {
|
|
30
|
+
constructor(registry, value) {
|
|
31
|
+
const decoded = decodeJson(value);
|
|
32
|
+
super(decoded);
|
|
33
|
+
this.registry = void 0;
|
|
34
|
+
this.createdAtHash = void 0;
|
|
35
|
+
this.registry = registry;
|
|
36
|
+
(0, _util.objectProperties)(this, decoded.map(_ref => {
|
|
37
|
+
let [k] = _ref;
|
|
38
|
+
return k;
|
|
39
|
+
}), k => this.get(k));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @description Always 0, never encodes as a Uint8Array
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
get encodedLength() {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description returns a hash of the contents
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
get hash() {
|
|
55
|
+
return this.registry.hash(this.toU8a());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @description Checks if the value is an empty value
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
get isEmpty() {
|
|
63
|
+
return [...this.keys()].length === 0;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @description Compares the value of the input to see if there is a match
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
eq(other) {
|
|
71
|
+
return (0, _index.compareMap)(this, other);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description Unimplemented, will throw
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
toHex() {
|
|
79
|
+
throw new Error('Unimplemented');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
toHuman() {
|
|
87
|
+
return [...this.entries()].reduce((json, _ref2) => {
|
|
88
|
+
let [key, value] = _ref2;
|
|
89
|
+
json[key] = (0, _util.isFunction)(value.toHuman) ? value.toHuman() : value;
|
|
90
|
+
return json;
|
|
91
|
+
}, {});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
toJSON() {
|
|
99
|
+
return [...this.entries()].reduce((json, _ref3) => {
|
|
100
|
+
let [key, value] = _ref3;
|
|
101
|
+
json[key] = value;
|
|
102
|
+
return json;
|
|
103
|
+
}, {});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @description Returns the base runtime type name for this instance
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
toRawType() {
|
|
111
|
+
return 'Json';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @description Returns the string representation of the value
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
toString() {
|
|
119
|
+
return (0, _util.stringify)(this.toJSON());
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @description Unimplemented, will throw
|
|
123
|
+
*/
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toU8a(isBare) {
|
|
128
|
+
throw new Error('Unimplemented');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exports.Json = Json;
|
package/native/Json.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecRegistry, IU8a } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @name Json
|
|
5
|
+
* @description
|
|
6
|
+
* Wraps the a JSON structure retrieve via RPC. It extends the standard JS Map with. While it
|
|
7
|
+
* implements a Codec, it is limited in that it can only be used with input objects via RPC,
|
|
8
|
+
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
|
|
9
|
+
* @noInheritDoc
|
|
10
|
+
*/
|
|
11
|
+
export declare class Json extends Map<string, any> implements Codec {
|
|
12
|
+
readonly registry: CodecRegistry;
|
|
13
|
+
createdAtHash?: IU8a;
|
|
14
|
+
constructor(registry: CodecRegistry, value?: Record<string, unknown> | null);
|
|
15
|
+
/**
|
|
16
|
+
* @description Always 0, never encodes as a Uint8Array
|
|
17
|
+
*/
|
|
18
|
+
get encodedLength(): number;
|
|
19
|
+
/**
|
|
20
|
+
* @description returns a hash of the contents
|
|
21
|
+
*/
|
|
22
|
+
get hash(): IU8a;
|
|
23
|
+
/**
|
|
24
|
+
* @description Checks if the value is an empty value
|
|
25
|
+
*/
|
|
26
|
+
get isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description Compares the value of the input to see if there is a match
|
|
29
|
+
*/
|
|
30
|
+
eq(other?: unknown): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @description Unimplemented, will throw
|
|
33
|
+
*/
|
|
34
|
+
toHex(): HexString;
|
|
35
|
+
/**
|
|
36
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
37
|
+
*/
|
|
38
|
+
toHuman(): Record<string, AnyJson>;
|
|
39
|
+
/**
|
|
40
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
41
|
+
*/
|
|
42
|
+
toJSON(): Record<string, AnyJson>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Returns the base runtime type name for this instance
|
|
45
|
+
*/
|
|
46
|
+
toRawType(): string;
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns the string representation of the value
|
|
49
|
+
*/
|
|
50
|
+
toString(): string;
|
|
51
|
+
/**
|
|
52
|
+
* @description Unimplemented, will throw
|
|
53
|
+
*/
|
|
54
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
55
|
+
}
|
package/native/Json.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isFunction, objectProperties, stringify } from '@polkadot/util';
|
|
4
|
+
import { compareMap } from "../utils/index.js";
|
|
5
|
+
/** @internal */
|
|
6
|
+
|
|
7
|
+
function decodeJson(value) {
|
|
8
|
+
return Object.entries(value || {});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @name Json
|
|
12
|
+
* @description
|
|
13
|
+
* Wraps the a JSON structure retrieve via RPC. It extends the standard JS Map with. While it
|
|
14
|
+
* implements a Codec, it is limited in that it can only be used with input objects via RPC,
|
|
15
|
+
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
|
|
16
|
+
* @noInheritDoc
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export class Json extends Map {
|
|
21
|
+
constructor(registry, value) {
|
|
22
|
+
const decoded = decodeJson(value);
|
|
23
|
+
super(decoded);
|
|
24
|
+
this.registry = void 0;
|
|
25
|
+
this.createdAtHash = void 0;
|
|
26
|
+
this.registry = registry;
|
|
27
|
+
objectProperties(this, decoded.map(([k]) => k), k => this.get(k));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @description Always 0, never encodes as a Uint8Array
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
get encodedLength() {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description returns a hash of the contents
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
get hash() {
|
|
43
|
+
return this.registry.hash(this.toU8a());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @description Checks if the value is an empty value
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
get isEmpty() {
|
|
51
|
+
return [...this.keys()].length === 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description Compares the value of the input to see if there is a match
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
eq(other) {
|
|
59
|
+
return compareMap(this, other);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description Unimplemented, will throw
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
toHex() {
|
|
67
|
+
throw new Error('Unimplemented');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
toHuman() {
|
|
75
|
+
return [...this.entries()].reduce((json, [key, value]) => {
|
|
76
|
+
json[key] = isFunction(value.toHuman) ? value.toHuman() : value;
|
|
77
|
+
return json;
|
|
78
|
+
}, {});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
toJSON() {
|
|
86
|
+
return [...this.entries()].reduce((json, [key, value]) => {
|
|
87
|
+
json[key] = value;
|
|
88
|
+
return json;
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @description Returns the base runtime type name for this instance
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
toRawType() {
|
|
97
|
+
return 'Json';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @description Returns the string representation of the value
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
toString() {
|
|
105
|
+
return stringify(this.toJSON());
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Unimplemented, will throw
|
|
109
|
+
*/
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
toU8a(isBare) {
|
|
114
|
+
throw new Error('Unimplemented');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|