@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/Text.cjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Text = void 0;
|
|
9
|
+
|
|
10
|
+
var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
|
|
11
|
+
|
|
12
|
+
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
|
+
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
|
|
16
|
+
var _Raw = require("./Raw.cjs");
|
|
17
|
+
|
|
18
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
const MAX_LENGTH = 128 * 1024;
|
|
21
|
+
/** @internal */
|
|
22
|
+
|
|
23
|
+
function decodeText(value) {
|
|
24
|
+
if ((0, _util.isU8a)(value)) {
|
|
25
|
+
if (!value.length) {
|
|
26
|
+
return ['', 0];
|
|
27
|
+
} // for Raw, the internal buffer does not have an internal length
|
|
28
|
+
// (the same applies in e.g. Bytes, where length is added at encoding-time)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if (value instanceof _Raw.Raw) {
|
|
32
|
+
return [(0, _util.u8aToString)(value), 0];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const [offset, length] = (0, _util.compactFromU8a)(value);
|
|
36
|
+
const total = offset + length.toNumber();
|
|
37
|
+
(0, _util.assert)(length.lten(MAX_LENGTH), () => `Text: length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
38
|
+
(0, _util.assert)(total <= value.length, () => `Text: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
|
39
|
+
return [(0, _util.u8aToString)(value.subarray(offset, total)), total];
|
|
40
|
+
} else if ((0, _util.isHex)(value)) {
|
|
41
|
+
return [(0, _util.u8aToString)((0, _util.hexToU8a)(value)), 0];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [value ? value.toString() : '', 0];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @name Text
|
|
48
|
+
* @description
|
|
49
|
+
* This is a string wrapper, along with the length. It is used both for strings as well
|
|
50
|
+
* as items such as documentation. It simply extends the standard JS `String` built-in
|
|
51
|
+
* object, inheriting all methods exposed from `String`.
|
|
52
|
+
* @noInheritDoc
|
|
53
|
+
*/
|
|
54
|
+
// TODO
|
|
55
|
+
// - Strings should probably be trimmed (docs do come through with extra padding)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
var _initialU8aLength = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("initialU8aLength");
|
|
59
|
+
|
|
60
|
+
var _override = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("override");
|
|
61
|
+
|
|
62
|
+
class Text extends String {
|
|
63
|
+
constructor(registry, value) {
|
|
64
|
+
const [str, decodedLength] = decodeText(value);
|
|
65
|
+
super(str);
|
|
66
|
+
this.registry = void 0;
|
|
67
|
+
this.createdAtHash = void 0;
|
|
68
|
+
Object.defineProperty(this, _initialU8aLength, {
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, _override, {
|
|
73
|
+
writable: true,
|
|
74
|
+
value: null
|
|
75
|
+
});
|
|
76
|
+
this.registry = registry;
|
|
77
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _initialU8aLength)[_initialU8aLength] = decodedLength;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
get encodedLength() {
|
|
85
|
+
return this.toU8a().length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
get initialU8aLength() {
|
|
93
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _initialU8aLength)[_initialU8aLength];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @description returns a hash of the contents
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
get hash() {
|
|
101
|
+
return this.registry.hash(this.toU8a());
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @description Checks if the value is an empty value
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
get isEmpty() {
|
|
109
|
+
return this.length === 0;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @description The length of the value
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
get length() {
|
|
117
|
+
// only included here since we ignore inherited docs
|
|
118
|
+
return super.length;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description Compares the value of the input to see if there is a match
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
eq(other) {
|
|
126
|
+
return (0, _util.isString)(other) ? this.toString() === other.toString() : false;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @description Set an override value for this
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
setOverride(override) {
|
|
134
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _override)[_override] = override;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @description Returns a hex string representation of the value
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
toHex() {
|
|
142
|
+
// like with Vec<u8>, when we are encoding to hex, we don't actually add
|
|
143
|
+
// the length prefix (it is already implied by the actual string length)
|
|
144
|
+
return (0, _util.u8aToHex)(this.toU8a(true));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
toHuman() {
|
|
152
|
+
return this.toJSON();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
toJSON() {
|
|
160
|
+
return this.toString();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @description Returns the base runtime type name for this instance
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
toRawType() {
|
|
168
|
+
return 'Text';
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @description Returns the string representation of the value
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
toString() {
|
|
176
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _override)[_override] || super.toString();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
180
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
toU8a(isBare) {
|
|
185
|
+
// NOTE Here we use the super toString (we are not taking overrides into account,
|
|
186
|
+
// rather encoding the original value the string was constructed with)
|
|
187
|
+
const encoded = (0, _util.stringToU8a)(super.toString());
|
|
188
|
+
return isBare ? encoded : (0, _util.compactAddLength)(encoded);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
exports.Text = Text;
|
package/native/Text.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyU8a, Codec, CodecRegistry, IU8a } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @name Text
|
|
5
|
+
* @description
|
|
6
|
+
* This is a string wrapper, along with the length. It is used both for strings as well
|
|
7
|
+
* as items such as documentation. It simply extends the standard JS `String` built-in
|
|
8
|
+
* object, inheriting all methods exposed from `String`.
|
|
9
|
+
* @noInheritDoc
|
|
10
|
+
*/
|
|
11
|
+
export declare class Text extends String implements Codec {
|
|
12
|
+
#private;
|
|
13
|
+
readonly registry: CodecRegistry;
|
|
14
|
+
createdAtHash?: IU8a;
|
|
15
|
+
constructor(registry: CodecRegistry, value?: null | Text | string | AnyU8a | {
|
|
16
|
+
toString: () => string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
20
|
+
*/
|
|
21
|
+
get encodedLength(): number;
|
|
22
|
+
/**
|
|
23
|
+
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
24
|
+
*/
|
|
25
|
+
get initialU8aLength(): number | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* @description returns a hash of the contents
|
|
28
|
+
*/
|
|
29
|
+
get hash(): IU8a;
|
|
30
|
+
/**
|
|
31
|
+
* @description Checks if the value is an empty value
|
|
32
|
+
*/
|
|
33
|
+
get isEmpty(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description The length of the value
|
|
36
|
+
*/
|
|
37
|
+
get length(): number;
|
|
38
|
+
/**
|
|
39
|
+
* @description Compares the value of the input to see if there is a match
|
|
40
|
+
*/
|
|
41
|
+
eq(other?: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @description Set an override value for this
|
|
44
|
+
*/
|
|
45
|
+
setOverride(override: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* @description Returns a hex string representation of the value
|
|
48
|
+
*/
|
|
49
|
+
toHex(): HexString;
|
|
50
|
+
/**
|
|
51
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
52
|
+
*/
|
|
53
|
+
toHuman(): string;
|
|
54
|
+
/**
|
|
55
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): string;
|
|
58
|
+
/**
|
|
59
|
+
* @description Returns the base runtime type name for this instance
|
|
60
|
+
*/
|
|
61
|
+
toRawType(): string;
|
|
62
|
+
/**
|
|
63
|
+
* @description Returns the string representation of the value
|
|
64
|
+
*/
|
|
65
|
+
toString(): string;
|
|
66
|
+
/**
|
|
67
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
68
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
69
|
+
*/
|
|
70
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
71
|
+
}
|
package/native/Text.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
+
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
import { assert, compactAddLength, compactFromU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
|
6
|
+
import { Raw } from "./Raw.js";
|
|
7
|
+
const MAX_LENGTH = 128 * 1024;
|
|
8
|
+
/** @internal */
|
|
9
|
+
|
|
10
|
+
function decodeText(value) {
|
|
11
|
+
if (isU8a(value)) {
|
|
12
|
+
if (!value.length) {
|
|
13
|
+
return ['', 0];
|
|
14
|
+
} // for Raw, the internal buffer does not have an internal length
|
|
15
|
+
// (the same applies in e.g. Bytes, where length is added at encoding-time)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if (value instanceof Raw) {
|
|
19
|
+
return [u8aToString(value), 0];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const [offset, length] = compactFromU8a(value);
|
|
23
|
+
const total = offset + length.toNumber();
|
|
24
|
+
assert(length.lten(MAX_LENGTH), () => `Text: length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
25
|
+
assert(total <= value.length, () => `Text: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
|
26
|
+
return [u8aToString(value.subarray(offset, total)), total];
|
|
27
|
+
} else if (isHex(value)) {
|
|
28
|
+
return [u8aToString(hexToU8a(value)), 0];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [value ? value.toString() : '', 0];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @name Text
|
|
35
|
+
* @description
|
|
36
|
+
* This is a string wrapper, along with the length. It is used both for strings as well
|
|
37
|
+
* as items such as documentation. It simply extends the standard JS `String` built-in
|
|
38
|
+
* object, inheriting all methods exposed from `String`.
|
|
39
|
+
* @noInheritDoc
|
|
40
|
+
*/
|
|
41
|
+
// TODO
|
|
42
|
+
// - Strings should probably be trimmed (docs do come through with extra padding)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var _initialU8aLength = /*#__PURE__*/_classPrivateFieldLooseKey("initialU8aLength");
|
|
46
|
+
|
|
47
|
+
var _override = /*#__PURE__*/_classPrivateFieldLooseKey("override");
|
|
48
|
+
|
|
49
|
+
export class Text extends String {
|
|
50
|
+
constructor(registry, value) {
|
|
51
|
+
const [str, decodedLength] = decodeText(value);
|
|
52
|
+
super(str);
|
|
53
|
+
this.registry = void 0;
|
|
54
|
+
this.createdAtHash = void 0;
|
|
55
|
+
Object.defineProperty(this, _initialU8aLength, {
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, _override, {
|
|
60
|
+
writable: true,
|
|
61
|
+
value: null
|
|
62
|
+
});
|
|
63
|
+
this.registry = registry;
|
|
64
|
+
_classPrivateFieldLooseBase(this, _initialU8aLength)[_initialU8aLength] = decodedLength;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
get encodedLength() {
|
|
72
|
+
return this.toU8a().length;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
get initialU8aLength() {
|
|
80
|
+
return _classPrivateFieldLooseBase(this, _initialU8aLength)[_initialU8aLength];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @description returns a hash of the contents
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
get hash() {
|
|
88
|
+
return this.registry.hash(this.toU8a());
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @description Checks if the value is an empty value
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
get isEmpty() {
|
|
96
|
+
return this.length === 0;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @description The length of the value
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
get length() {
|
|
104
|
+
// only included here since we ignore inherited docs
|
|
105
|
+
return super.length;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Compares the value of the input to see if there is a match
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
eq(other) {
|
|
113
|
+
return isString(other) ? this.toString() === other.toString() : false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @description Set an override value for this
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
setOverride(override) {
|
|
121
|
+
_classPrivateFieldLooseBase(this, _override)[_override] = override;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @description Returns a hex string representation of the value
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
toHex() {
|
|
129
|
+
// like with Vec<u8>, when we are encoding to hex, we don't actually add
|
|
130
|
+
// the length prefix (it is already implied by the actual string length)
|
|
131
|
+
return u8aToHex(this.toU8a(true));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
toHuman() {
|
|
139
|
+
return this.toJSON();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
toJSON() {
|
|
147
|
+
return this.toString();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @description Returns the base runtime type name for this instance
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
toRawType() {
|
|
155
|
+
return 'Text';
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @description Returns the string representation of the value
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
toString() {
|
|
163
|
+
return _classPrivateFieldLooseBase(this, _override)[_override] || super.toString();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
167
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
toU8a(isBare) {
|
|
172
|
+
// NOTE Here we use the super toString (we are not taking overrides into account,
|
|
173
|
+
// rather encoding the original value the string was constructed with)
|
|
174
|
+
const encoded = stringToU8a(super.toString());
|
|
175
|
+
return isBare ? encoded : compactAddLength(encoded);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
package/native/index.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Bool", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _Bool.bool;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CodecDate", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Date.CodecDate;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "CodecSet", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _Set.CodecSet;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Date", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _Date.CodecDate;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Json", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _Json.Json;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "Raw", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _Raw.Raw;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "Set", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _Set.CodecSet;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "Struct", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _Struct.Struct;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "Text", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _Text.Text;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "bool", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _Bool.bool;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
var _Bool = require("./Bool.cjs");
|
|
68
|
+
|
|
69
|
+
var _Date = require("./Date.cjs");
|
|
70
|
+
|
|
71
|
+
var _Json = require("./Json.cjs");
|
|
72
|
+
|
|
73
|
+
var _Raw = require("./Raw.cjs");
|
|
74
|
+
|
|
75
|
+
var _Set = require("./Set.cjs");
|
|
76
|
+
|
|
77
|
+
var _Struct = require("./Struct.cjs");
|
|
78
|
+
|
|
79
|
+
var _Text = require("./Text.cjs");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { bool, bool as Bool } from './Bool';
|
|
2
|
+
export { CodecDate, CodecDate as Date } from './Date';
|
|
3
|
+
export { Json } from './Json';
|
|
4
|
+
export { Raw } from './Raw';
|
|
5
|
+
export { CodecSet, CodecSet as Set } from './Set';
|
|
6
|
+
export { Struct } from './Struct';
|
|
7
|
+
export { Text } from './Text';
|
package/native/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { bool, bool as Bool } from "./Bool.js";
|
|
4
|
+
export { CodecDate, CodecDate as Date } from "./Date.js";
|
|
5
|
+
export { Json } from "./Json.js";
|
|
6
|
+
export { Raw } from "./Raw.js";
|
|
7
|
+
export { CodecSet, CodecSet as Set } from "./Set.js";
|
|
8
|
+
export { Struct } from "./Struct.js";
|
|
9
|
+
export { Text } from "./Text.js";
|