@lodestar/utils 0.40.0-dev.266f9e2f44
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/LICENSE +201 -0
- package/README.md +12 -0
- package/lib/assert.d.ts +45 -0
- package/lib/assert.js +69 -0
- package/lib/assert.js.map +1 -0
- package/lib/bytes.d.ts +17 -0
- package/lib/bytes.js +58 -0
- package/lib/bytes.js.map +1 -0
- package/lib/errors.d.ts +35 -0
- package/lib/errors.js +52 -0
- package/lib/errors.js.map +1 -0
- package/lib/format.d.ts +6 -0
- package/lib/format.js +10 -0
- package/lib/format.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/logger/format.d.ts +6 -0
- package/lib/logger/format.js +62 -0
- package/lib/logger/format.js.map +1 -0
- package/lib/logger/index.d.ts +9 -0
- package/lib/logger/index.js +8 -0
- package/lib/logger/index.js.map +1 -0
- package/lib/logger/interface.d.ts +63 -0
- package/lib/logger/interface.js +38 -0
- package/lib/logger/interface.js.map +1 -0
- package/lib/logger/json.d.ts +18 -0
- package/lib/logger/json.js +115 -0
- package/lib/logger/json.js.map +1 -0
- package/lib/logger/transport.d.ts +24 -0
- package/lib/logger/transport.js +41 -0
- package/lib/logger/transport.js.map +1 -0
- package/lib/logger/util.d.ts +6 -0
- package/lib/logger/util.js +14 -0
- package/lib/logger/util.js.map +1 -0
- package/lib/logger/winston.d.ts +30 -0
- package/lib/logger/winston.js +83 -0
- package/lib/logger/winston.js.map +1 -0
- package/lib/math.d.ts +27 -0
- package/lib/math.js +53 -0
- package/lib/math.js.map +1 -0
- package/lib/notNullish.d.ts +10 -0
- package/lib/notNullish.js +12 -0
- package/lib/notNullish.js.map +1 -0
- package/lib/objects.d.ts +16 -0
- package/lib/objects.js +72 -0
- package/lib/objects.js.map +1 -0
- package/lib/promise.d.ts +5 -0
- package/lib/promise.js +22 -0
- package/lib/promise.js.map +1 -0
- package/lib/retry.d.ts +24 -0
- package/lib/retry.js +29 -0
- package/lib/retry.js.map +1 -0
- package/lib/sleep.d.ts +6 -0
- package/lib/sleep.js +32 -0
- package/lib/sleep.js.map +1 -0
- package/lib/sort.d.ts +2 -0
- package/lib/sort.js +10 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.d.ts +2 -0
- package/lib/timeout.js +18 -0
- package/lib/timeout.js.map +1 -0
- package/lib/types.d.ts +10 -0
- package/lib/types.js +5 -0
- package/lib/types.js.map +1 -0
- package/lib/verifyMerkleBranch.d.ts +7 -0
- package/lib/verifyMerkleBranch.js +21 -0
- package/lib/verifyMerkleBranch.js.map +1 -0
- package/lib/yaml/index.d.ts +3 -0
- package/lib/yaml/index.js +10 -0
- package/lib/yaml/index.js.map +1 -0
- package/lib/yaml/int.d.ts +3 -0
- package/lib/yaml/int.js +174 -0
- package/lib/yaml/int.js.map +1 -0
- package/lib/yaml/schema.d.ts +3 -0
- package/lib/yaml/schema.js +21 -0
- package/lib/yaml/schema.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# lodestar-utils
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
|
|
7
|
+
|
|
8
|
+
A suite of various utility functions/classes that are used across the various `lodestar-*` monorepo packages.
|
|
9
|
+
|
|
10
|
+
## License
|
|
11
|
+
|
|
12
|
+
Apache-2.0 [ChainSafe Systems](https://chainsafe.io)
|
package/lib/assert.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const assert: {
|
|
2
|
+
/**
|
|
3
|
+
* Assert condition is true, otherwise throw AssertionError
|
|
4
|
+
*/
|
|
5
|
+
true(condition: boolean, message?: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Assert strict equality
|
|
8
|
+
* ```js
|
|
9
|
+
* actual === expected
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
equal<T>(actual: T, expected: T, message?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Assert less than or equal
|
|
15
|
+
* ```js
|
|
16
|
+
* left <= right
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
lte(left: number, right: number, message?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Assert less than
|
|
22
|
+
* ```js
|
|
23
|
+
* left < right
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
lt(left: number, right: number, message?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Assert greater than or equal
|
|
29
|
+
* ```js
|
|
30
|
+
* left >= right
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
gte(left: number, right: number, message?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Assert greater than
|
|
36
|
+
* ```js
|
|
37
|
+
* left > right
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
gt(left: number, right: number, message?: string): void;
|
|
41
|
+
};
|
|
42
|
+
export declare class AssertionError extends Error {
|
|
43
|
+
static code: string;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=assert.d.ts.map
|
package/lib/assert.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export const assert = {
|
|
2
|
+
/**
|
|
3
|
+
* Assert condition is true, otherwise throw AssertionError
|
|
4
|
+
*/
|
|
5
|
+
true(condition, message) {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new AssertionError(message || "Expect condition to be true");
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
/**
|
|
11
|
+
* Assert strict equality
|
|
12
|
+
* ```js
|
|
13
|
+
* actual === expected
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
equal(actual, expected, message) {
|
|
17
|
+
if (!(actual === expected)) {
|
|
18
|
+
throw new AssertionError(`${message || "Expected values to be equal"}: ${actual} === ${expected}`);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Assert less than or equal
|
|
23
|
+
* ```js
|
|
24
|
+
* left <= right
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
lte(left, right, message) {
|
|
28
|
+
if (!(left <= right)) {
|
|
29
|
+
throw new AssertionError(`${message || "Expected value to be lte"}: ${left} <= ${right}`);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Assert less than
|
|
34
|
+
* ```js
|
|
35
|
+
* left < right
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
lt(left, right, message) {
|
|
39
|
+
if (!(left < right)) {
|
|
40
|
+
throw new AssertionError(`${message || "Expected value to be lt"}: ${left} < ${right}`);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Assert greater than or equal
|
|
45
|
+
* ```js
|
|
46
|
+
* left >= right
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
gte(left, right, message) {
|
|
50
|
+
if (!(left >= right)) {
|
|
51
|
+
throw new AssertionError(`${message || "Expected value to be gte"}: ${left} >= ${right}`);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Assert greater than
|
|
56
|
+
* ```js
|
|
57
|
+
* left > right
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
gt(left, right, message) {
|
|
61
|
+
if (!(left > right)) {
|
|
62
|
+
throw new AssertionError(`${message || "Expected value to be gt"}: ${left} > ${right}`);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
export class AssertionError extends Error {
|
|
67
|
+
}
|
|
68
|
+
AssertionError.code = "ERR_ASSERTION";
|
|
69
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;OAEG;IACH,IAAI,CAAC,SAAkB,EAAE,OAAgB;QACvC,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,cAAc,CAAC,OAAO,IAAI,6BAA6B,CAAC,CAAC;SACpE;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAI,MAAS,EAAE,QAAW,EAAE,OAAgB;QAC/C,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE;YAC1B,MAAM,IAAI,cAAc,CAAC,GAAG,OAAO,IAAI,6BAA6B,KAAK,MAAM,QAAQ,QAAQ,EAAE,CAAC,CAAC;SACpG;IACH,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAAgB;QAC/C,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE;YACpB,MAAM,IAAI,cAAc,CAAC,GAAG,OAAO,IAAI,0BAA0B,KAAK,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;SAC3F;IACH,CAAC;IAED;;;;;OAKG;IACH,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,OAAgB;QAC9C,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,EAAE;YACnB,MAAM,IAAI,cAAc,CAAC,GAAG,OAAO,IAAI,yBAAyB,KAAK,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC;SACzF;IACH,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,OAAgB;QAC/C,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE;YACpB,MAAM,IAAI,cAAc,CAAC,GAAG,OAAO,IAAI,0BAA0B,KAAK,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;SAC3F;IACH,CAAC;IAED;;;;;OAKG;IACH,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,OAAgB;QAC9C,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,EAAE;YACnB,MAAM,IAAI,cAAc,CAAC,GAAG,OAAO,IAAI,yBAAyB,KAAK,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC;SACzF;IACH,CAAC;CACF,CAAC;AAEF,MAAM,OAAO,cAAe,SAAQ,KAAK;;AAChC,mBAAI,GAAG,eAAe,CAAC"}
|
package/lib/bytes.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare type Endianness = "le" | "be";
|
|
3
|
+
export declare function toHexString(bytes: Uint8Array): string;
|
|
4
|
+
/**
|
|
5
|
+
* Return a byte array from a number or BigInt
|
|
6
|
+
*/
|
|
7
|
+
export declare function intToBytes(value: bigint | number, length: number, endianness?: Endianness): Buffer;
|
|
8
|
+
/**
|
|
9
|
+
* Convert byte array in LE to integer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function bytesToInt(value: Uint8Array, endianness?: Endianness): number;
|
|
12
|
+
export declare function bigIntToBytes(value: bigint, length: number, endianness?: Endianness): Buffer;
|
|
13
|
+
export declare function bytesToBigInt(value: Uint8Array, endianness?: Endianness): bigint;
|
|
14
|
+
export declare function toHex(buffer: Uint8Array | Parameters<typeof Buffer.from>[0]): string;
|
|
15
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=bytes.d.ts.map
|
package/lib/bytes.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { toBufferLE, toBigIntLE, toBufferBE, toBigIntBE } from "bigint-buffer";
|
|
2
|
+
const hexByByte = [];
|
|
3
|
+
export function toHexString(bytes) {
|
|
4
|
+
let hex = "0x";
|
|
5
|
+
for (const byte of bytes) {
|
|
6
|
+
if (!hexByByte[byte]) {
|
|
7
|
+
hexByByte[byte] = byte < 16 ? "0" + byte.toString(16) : byte.toString(16);
|
|
8
|
+
}
|
|
9
|
+
hex += hexByByte[byte];
|
|
10
|
+
}
|
|
11
|
+
return hex;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Return a byte array from a number or BigInt
|
|
15
|
+
*/
|
|
16
|
+
export function intToBytes(value, length, endianness = "le") {
|
|
17
|
+
return bigIntToBytes(BigInt(value), length, endianness);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert byte array in LE to integer.
|
|
21
|
+
*/
|
|
22
|
+
export function bytesToInt(value, endianness = "le") {
|
|
23
|
+
return Number(bytesToBigInt(value, endianness));
|
|
24
|
+
}
|
|
25
|
+
export function bigIntToBytes(value, length, endianness = "le") {
|
|
26
|
+
if (endianness === "le") {
|
|
27
|
+
return toBufferLE(value, length);
|
|
28
|
+
}
|
|
29
|
+
else if (endianness === "be") {
|
|
30
|
+
return toBufferBE(value, length);
|
|
31
|
+
}
|
|
32
|
+
throw new Error("endianness must be either 'le' or 'be'");
|
|
33
|
+
}
|
|
34
|
+
export function bytesToBigInt(value, endianness = "le") {
|
|
35
|
+
if (endianness === "le") {
|
|
36
|
+
return toBigIntLE(value);
|
|
37
|
+
}
|
|
38
|
+
else if (endianness === "be") {
|
|
39
|
+
return toBigIntBE(value);
|
|
40
|
+
}
|
|
41
|
+
throw new Error("endianness must be either 'le' or 'be'");
|
|
42
|
+
}
|
|
43
|
+
export function toHex(buffer) {
|
|
44
|
+
if (Buffer.isBuffer(buffer)) {
|
|
45
|
+
return "0x" + buffer.toString("hex");
|
|
46
|
+
}
|
|
47
|
+
else if (buffer instanceof Uint8Array) {
|
|
48
|
+
return "0x" + Buffer.from(buffer.buffer, buffer.byteOffset, buffer.length).toString("hex");
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return "0x" + Buffer.from(buffer).toString("hex");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function fromHex(hex) {
|
|
55
|
+
const b = Buffer.from(hex.replace("0x", ""), "hex");
|
|
56
|
+
return new Uint8Array(b.buffer, b.byteOffset, b.length);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=bytes.js.map
|
package/lib/bytes.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAI7E,MAAM,SAAS,GAAa,EAAE,CAAC;AAC/B,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACpB,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SAC3E;QACD,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;KACxB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB,EAAE,MAAc,EAAE,aAAyB,IAAI;IAC9F,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,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CAAC,GAAW;IACjC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Lodestar error with attached metadata
|
|
3
|
+
*/
|
|
4
|
+
export declare class LodestarError<T extends {
|
|
5
|
+
code: string;
|
|
6
|
+
}> extends Error {
|
|
7
|
+
type: T;
|
|
8
|
+
constructor(type: T, message?: string);
|
|
9
|
+
getMetadata(): Record<string, string | number | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the metadata and the stacktrace for the error.
|
|
12
|
+
*/
|
|
13
|
+
toObject(): Record<string, string | number | null>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Throw this error when an upstream abort signal aborts
|
|
17
|
+
*/
|
|
18
|
+
export declare class ErrorAborted extends Error {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Throw this error when wrapped timeout expires
|
|
23
|
+
*/
|
|
24
|
+
export declare class TimeoutError extends Error {
|
|
25
|
+
constructor(message?: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns true if arg `e` is an instance of `ErrorAborted`
|
|
29
|
+
*/
|
|
30
|
+
export declare function isErrorAborted(e: unknown): e is ErrorAborted;
|
|
31
|
+
/**
|
|
32
|
+
* Extend an existing error by appending a string to its `e.message`
|
|
33
|
+
*/
|
|
34
|
+
export declare function extendError(e: Error, appendMessage: string): Error;
|
|
35
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Lodestar error with attached metadata
|
|
3
|
+
*/
|
|
4
|
+
export class LodestarError extends Error {
|
|
5
|
+
constructor(type, message) {
|
|
6
|
+
super(message || type.code);
|
|
7
|
+
this.type = type;
|
|
8
|
+
}
|
|
9
|
+
getMetadata() {
|
|
10
|
+
return this.type;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the metadata and the stacktrace for the error.
|
|
14
|
+
*/
|
|
15
|
+
toObject() {
|
|
16
|
+
return {
|
|
17
|
+
// Ignore message since it's just type.code
|
|
18
|
+
...this.getMetadata(),
|
|
19
|
+
stack: this.stack || "",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Throw this error when an upstream abort signal aborts
|
|
25
|
+
*/
|
|
26
|
+
export class ErrorAborted extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(`Aborted ${message || ""}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Throw this error when wrapped timeout expires
|
|
33
|
+
*/
|
|
34
|
+
export class TimeoutError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(`Timeout ${message || ""}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns true if arg `e` is an instance of `ErrorAborted`
|
|
41
|
+
*/
|
|
42
|
+
export function isErrorAborted(e) {
|
|
43
|
+
return e instanceof ErrorAborted;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extend an existing error by appending a string to its `e.message`
|
|
47
|
+
*/
|
|
48
|
+
export function extendError(e, appendMessage) {
|
|
49
|
+
e.message = `${e.message} - ${appendMessage}`;
|
|
50
|
+
return e;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAwC,SAAQ,KAAK;IAEhE,YAAY,IAAO,EAAE,OAAgB;QACnC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO;YACL,2CAA2C;YAC3C,GAAG,IAAI,CAAC,WAAW,EAAE;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;SACxB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAgB;QAC1B,KAAK,CAAC,WAAW,OAAO,IAAI,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAgB;QAC1B,KAAK,CAAC,WAAW,OAAO,IAAI,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,CAAU;IACvC,OAAO,CAAC,YAAY,YAAY,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,CAAQ,EAAE,aAAqB;IACzD,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,OAAO,MAAM,aAAa,EAAE,CAAC;IAC9C,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/lib/format.d.ts
ADDED
package/lib/format.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { toHexString } from "./bytes.js";
|
|
2
|
+
/**
|
|
3
|
+
* Format bytes as `0x1234…1234`
|
|
4
|
+
* 4 bytes can represent 4294967296 values, so the chance of collision is low
|
|
5
|
+
*/
|
|
6
|
+
export function prettyBytes(root) {
|
|
7
|
+
const str = typeof root === "string" ? root : toHexString(root);
|
|
8
|
+
return `${str.slice(0, 6)}…${str.slice(-4)}`;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAyB;IACnD,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./logger/index.js";
|
|
2
|
+
export * from "./yaml/index.js";
|
|
3
|
+
export * from "./assert.js";
|
|
4
|
+
export * from "./bytes.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export * from "./format.js";
|
|
7
|
+
export * from "./math.js";
|
|
8
|
+
export * from "./objects.js";
|
|
9
|
+
export { retry, RetryOptions } from "./retry.js";
|
|
10
|
+
export * from "./notNullish.js";
|
|
11
|
+
export * from "./sleep.js";
|
|
12
|
+
export * from "./sort.js";
|
|
13
|
+
export * from "./timeout.js";
|
|
14
|
+
export { RecursivePartial, bnToNum } from "./types.js";
|
|
15
|
+
export * from "./verifyMerkleBranch.js";
|
|
16
|
+
export * from "./promise.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./logger/index.js";
|
|
2
|
+
export * from "./yaml/index.js";
|
|
3
|
+
export * from "./assert.js";
|
|
4
|
+
export * from "./bytes.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export * from "./format.js";
|
|
7
|
+
export * from "./math.js";
|
|
8
|
+
export * from "./objects.js";
|
|
9
|
+
export { retry } from "./retry.js";
|
|
10
|
+
export * from "./notNullish.js";
|
|
11
|
+
export * from "./sleep.js";
|
|
12
|
+
export * from "./sort.js";
|
|
13
|
+
export * from "./timeout.js";
|
|
14
|
+
export { bnToNum } from "./types.js";
|
|
15
|
+
export * from "./verifyMerkleBranch.js";
|
|
16
|
+
export * from "./promise.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAC,KAAK,EAAe,MAAM,YAAY,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAmB,OAAO,EAAC,MAAM,YAAY,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
import { logCtxToJson, logCtxToString } from "./json.js";
|
|
3
|
+
import { TimestampFormatCode } from "./interface.js";
|
|
4
|
+
import { formatEpochSlotTime } from "./util.js";
|
|
5
|
+
const { format } = winston;
|
|
6
|
+
export function getFormat(opts) {
|
|
7
|
+
switch (opts.format) {
|
|
8
|
+
case "json":
|
|
9
|
+
return jsonLogFormat(opts);
|
|
10
|
+
case "human":
|
|
11
|
+
default:
|
|
12
|
+
return humanReadableLogFormat(opts);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function humanReadableLogFormat(opts) {
|
|
16
|
+
return format.combine(...(opts.hideTimestamp ? [] : [formatTimestamp(opts)]), format.colorize(), format.printf(humanReadableTemplateFn));
|
|
17
|
+
}
|
|
18
|
+
function formatTimestamp(opts) {
|
|
19
|
+
const { timestampFormat } = opts;
|
|
20
|
+
switch (timestampFormat === null || timestampFormat === void 0 ? void 0 : timestampFormat.format) {
|
|
21
|
+
case TimestampFormatCode.EpochSlot:
|
|
22
|
+
return {
|
|
23
|
+
transform: (info) => {
|
|
24
|
+
info.timestamp = formatEpochSlotTime(timestampFormat);
|
|
25
|
+
return info;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
case TimestampFormatCode.DateRegular:
|
|
29
|
+
default:
|
|
30
|
+
return format.timestamp({ format: "MMM-DD HH:mm:ss.SSS" });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function jsonLogFormat(opts) {
|
|
34
|
+
return format.combine(...(opts.hideTimestamp ? [] : [format.timestamp()]),
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
36
|
+
format((_info) => {
|
|
37
|
+
const info = _info;
|
|
38
|
+
info.context = logCtxToJson(info.context);
|
|
39
|
+
info.error = logCtxToJson(info.error);
|
|
40
|
+
return info;
|
|
41
|
+
})(), format.json());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Winston template function print a human readable string given a log object
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/naming-convention
|
|
47
|
+
function humanReadableTemplateFn(_info) {
|
|
48
|
+
const info = _info;
|
|
49
|
+
const paddingBetweenInfo = 30;
|
|
50
|
+
const infoString = info.module || info.namespace || "";
|
|
51
|
+
const infoPad = paddingBetweenInfo - infoString.length;
|
|
52
|
+
let str = "";
|
|
53
|
+
if (info.timestamp)
|
|
54
|
+
str += info.timestamp;
|
|
55
|
+
str += `[${infoString.toUpperCase()}] ${info.level.padStart(infoPad)}: ${info.message}`;
|
|
56
|
+
if (info.context !== undefined)
|
|
57
|
+
str += " " + logCtxToString(info.context);
|
|
58
|
+
if (info.error !== undefined)
|
|
59
|
+
str += " " + logCtxToString(info.error);
|
|
60
|
+
return str;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/logger/format.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,YAAY,EAAE,cAAc,EAAU,MAAM,WAAW,CAAC;AAChE,OAAO,EAAiB,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAC,mBAAmB,EAAC,MAAM,WAAW,CAAC;AAE9C,MAAM,EAAC,MAAM,EAAC,GAAG,OAAO,CAAC;AAezB,MAAM,UAAU,SAAS,CAAC,IAAoB;IAC5C,QAAQ,IAAI,CAAC,MAAM,EAAE;QACnB,KAAK,MAAM;YACT,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;QAE7B,KAAK,OAAO,CAAC;QACb;YACE,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;KACvC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAoB;IAClD,OAAO,MAAM,CAAC,OAAO,CACnB,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EACtD,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CACvC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAoB;IAC3C,MAAM,EAAC,eAAe,EAAC,G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