@gera2ld/common 0.0.1 → 0.0.3
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/dist/index.js +487 -542
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,546 +1,491 @@
|
|
|
1
|
-
import { BigNumber as
|
|
2
|
-
import { delay as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
import { BigNumber as e } from "bignumber.js";
|
|
2
|
+
import { delay as t } from "es-toolkit";
|
|
3
|
+
//#region src/base64.ts
|
|
4
|
+
var n = "=", r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, a, o;
|
|
5
|
+
function s() {
|
|
6
|
+
return i ||= u(r), i;
|
|
7
|
+
}
|
|
8
|
+
function c() {
|
|
9
|
+
return a ||= r.slice(0, -2) + "-_", a;
|
|
10
|
+
}
|
|
11
|
+
function l() {
|
|
12
|
+
return o ||= u(c()), o;
|
|
13
|
+
}
|
|
14
|
+
function u(e) {
|
|
15
|
+
let t = Array(255);
|
|
16
|
+
for (let n = 0; n < e.length; n += 1) t[e.charCodeAt(n)] = n;
|
|
17
|
+
return t;
|
|
18
|
+
}
|
|
19
|
+
function d(e, t) {
|
|
20
|
+
let n = t[e];
|
|
21
|
+
if (n == null) throw Error("Unable to parse base64 string.");
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
function f(e, t, r) {
|
|
25
|
+
let i = "", a = 0;
|
|
26
|
+
for (; a < e.length;) {
|
|
27
|
+
let o = e[a++], s = e[a++], c = e[a++];
|
|
28
|
+
if (i += t[o >> 2], i += t[(o & 3) << 4 | (s || 0) >> 4], s == null ? r && (i += n) : i += t[(s & 15) << 2 | (c || 0) >> 6], c == null) {
|
|
29
|
+
r && (i += n);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
i += t[c & 63];
|
|
33
|
+
}
|
|
34
|
+
return i;
|
|
35
|
+
}
|
|
36
|
+
function p(e, t) {
|
|
37
|
+
let r = e.length;
|
|
38
|
+
for (; r > 0 && e[r - 1] === "=";) --r;
|
|
39
|
+
let i = Math.ceil(r / 4), a = new Uint8Array(3 * i), o = 0, s = 0, c = 0;
|
|
40
|
+
for (s = 0; s < i; s += 1) {
|
|
41
|
+
let r = 0;
|
|
42
|
+
for (c = 0; c < 4; c += 1) {
|
|
43
|
+
o = s * 4 + c;
|
|
44
|
+
let i = e[o];
|
|
45
|
+
if (!i || i === n) break;
|
|
46
|
+
r |= d(e.charCodeAt(o), t) << (3 - c) * 6;
|
|
47
|
+
}
|
|
48
|
+
a[s * 3] = r >> 16, a[s * 3 + 1] = r >> 8 & 255, a[s * 3 + 2] = r & 255;
|
|
49
|
+
}
|
|
50
|
+
if (o < r - 1 || c === 1) throw Error("Invalid base64 string");
|
|
51
|
+
let l = 3 * i;
|
|
52
|
+
for (; c < 4; c += 1) --l;
|
|
53
|
+
return a.subarray(0, l);
|
|
54
|
+
}
|
|
55
|
+
function m(e) {
|
|
56
|
+
return f(e, r, !0);
|
|
57
|
+
}
|
|
58
|
+
function h(e) {
|
|
59
|
+
return p(e, s());
|
|
60
|
+
}
|
|
61
|
+
function g(e) {
|
|
62
|
+
return f(e, c(), !1);
|
|
63
|
+
}
|
|
64
|
+
function _(e) {
|
|
65
|
+
return p(e, l());
|
|
66
|
+
}
|
|
67
|
+
function v(e) {
|
|
68
|
+
return new TextEncoder().encode(e);
|
|
69
|
+
}
|
|
70
|
+
function y(e) {
|
|
71
|
+
return new TextDecoder().decode(e);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/util.ts
|
|
75
|
+
function b(e, t) {
|
|
76
|
+
return typeof t == "bigint" ? `${t}n` : t;
|
|
77
|
+
}
|
|
78
|
+
var x = {
|
|
79
|
+
truncateThreshold: 300,
|
|
80
|
+
headLength: 100,
|
|
81
|
+
tailLength: 100
|
|
82
82
|
};
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!e.handle())
|
|
190
|
-
if (this.isClosed)
|
|
191
|
-
e.deferred.reject(new Error("Buffer is closed"));
|
|
192
|
-
else break;
|
|
193
|
-
this.requests.shift();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function O(n, e) {
|
|
198
|
-
const t = new Uint8Array(n.length + e.length);
|
|
199
|
-
return t.set(n, 0), t.set(e, n.length), t;
|
|
200
|
-
}
|
|
201
|
-
function z(n, e) {
|
|
202
|
-
if (!e.length) return 0;
|
|
203
|
-
for (let t = 0; t <= n.length - e.length; t += 1) {
|
|
204
|
-
let r;
|
|
205
|
-
for (r = 0; r < e.length && n[t + r] === e[r]; r += 1)
|
|
206
|
-
;
|
|
207
|
-
if (r === e.length) return t;
|
|
208
|
-
}
|
|
209
|
-
return -1;
|
|
210
|
-
}
|
|
211
|
-
function re(n, e) {
|
|
212
|
-
const t = [], r = /* @__PURE__ */ new Set();
|
|
213
|
-
async function i() {
|
|
214
|
-
const u = m();
|
|
215
|
-
return t.push(u), o(), await u.promise, u;
|
|
216
|
-
}
|
|
217
|
-
function s(u) {
|
|
218
|
-
r.delete(u), o();
|
|
219
|
-
}
|
|
220
|
-
function o() {
|
|
221
|
-
for (; t.length && r.size < e; ) {
|
|
222
|
-
const u = t.shift();
|
|
223
|
-
r.add(u), u.resolve();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async function a(...u) {
|
|
227
|
-
const f = await i();
|
|
228
|
-
try {
|
|
229
|
-
return await n(...u);
|
|
230
|
-
} finally {
|
|
231
|
-
s(f);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return a;
|
|
235
|
-
}
|
|
236
|
-
class ne {
|
|
237
|
-
constructor(e = 0) {
|
|
238
|
-
this.maxSize = e;
|
|
239
|
-
}
|
|
240
|
-
data = [];
|
|
241
|
-
getQueue = /* @__PURE__ */ new Set();
|
|
242
|
-
putQueue = /* @__PURE__ */ new Set();
|
|
243
|
-
get size() {
|
|
244
|
-
return this.data.length;
|
|
245
|
-
}
|
|
246
|
-
defer(e, t = 0) {
|
|
247
|
-
const r = m();
|
|
248
|
-
return e.add(r), r.promise.finally(() => {
|
|
249
|
-
e.delete(r);
|
|
250
|
-
}), t && setTimeout(r.reject, t), r.promise;
|
|
251
|
-
}
|
|
252
|
-
resolve(e) {
|
|
253
|
-
const t = e.values().next().value;
|
|
254
|
-
t && (t.resolve(), e.delete(t));
|
|
255
|
-
}
|
|
256
|
-
async get(e = 0) {
|
|
257
|
-
this.data.length || await this.defer(this.getQueue, e);
|
|
258
|
-
const t = this.data.shift();
|
|
259
|
-
return this.resolve(this.putQueue), t;
|
|
260
|
-
}
|
|
261
|
-
async put(e, t = 0) {
|
|
262
|
-
this.maxSize && this.data.length >= this.maxSize && await this.defer(this.putQueue, t), this.data.push(e), this.resolve(this.getQueue);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
class U {
|
|
266
|
-
static defaultOptions = {};
|
|
267
|
-
output;
|
|
268
|
-
options;
|
|
269
|
-
constructor(e) {
|
|
270
|
-
this.options = {
|
|
271
|
-
...U.defaultOptions,
|
|
272
|
-
...typeof e == "string" ? { prefix: e } : e
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
getPrefix() {
|
|
276
|
-
let { prefix: e } = this.options;
|
|
277
|
-
return typeof e == "function" && (e = e()), e || "";
|
|
278
|
-
}
|
|
279
|
-
collect() {
|
|
280
|
-
return this.output = [], () => {
|
|
281
|
-
const { output: e } = this;
|
|
282
|
-
if (this.output = void 0, !e) throw new Error("Logs already collected");
|
|
283
|
-
return e;
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
log(e, t, ...r) {
|
|
287
|
-
const i = $(t, ...r);
|
|
288
|
-
this.output && this.output.push(i), console[e](this.getPrefix(), i);
|
|
289
|
-
}
|
|
290
|
-
info(e, ...t) {
|
|
291
|
-
return this.log("info", e, ...t);
|
|
292
|
-
}
|
|
293
|
-
error(e, ...t) {
|
|
294
|
-
return this.log("error", e, ...t);
|
|
295
|
-
}
|
|
296
|
-
wrap(e, t) {
|
|
297
|
-
const r = this;
|
|
298
|
-
return I(e, function(s, ...o) {
|
|
299
|
-
return t.call(this, r, s, ...o);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function ie(n, e) {
|
|
304
|
-
return BigInt(
|
|
305
|
-
g(n).multipliedBy(g(10).exponentiatedBy(e)).toFixed(0)
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
function se(n, e) {
|
|
309
|
-
return g(n).dividedBy(g(10).exponentiatedBy(e)).toNumber();
|
|
310
|
-
}
|
|
311
|
-
const Q = {
|
|
312
|
-
maximumFractionDigits: 4,
|
|
313
|
-
exponentialThresholdLarge: 1e6,
|
|
314
|
-
exponentialThresholdSmall: 1e-6,
|
|
315
|
-
minimumSignificantDigits: 2,
|
|
316
|
-
maximumSignificantDigits: 8,
|
|
317
|
-
quantizationStep: 0,
|
|
318
|
-
keepTrailingZeros: !1
|
|
83
|
+
function S(e, t) {
|
|
84
|
+
let { truncateThreshold: n, headLength: r, tailLength: i } = {
|
|
85
|
+
...x,
|
|
86
|
+
...t
|
|
87
|
+
}, a = Array.from(e);
|
|
88
|
+
if (a.length > n) {
|
|
89
|
+
let t = Math.min(r, a.length), n = Math.min(i, a.length - t), o = a.slice(0, t).join(""), s = a.slice(-n).join("");
|
|
90
|
+
return a.length - t - n > 0 ? o + "..." + s : e;
|
|
91
|
+
}
|
|
92
|
+
return e;
|
|
93
|
+
}
|
|
94
|
+
function C(e, t) {
|
|
95
|
+
return JSON.stringify(e, (e, n) => (typeof n == "bigint" && (n = `${n}n`), typeof n == "string" ? S(n, t) : n));
|
|
96
|
+
}
|
|
97
|
+
function w(e, ...t) {
|
|
98
|
+
let n = e.replace(/%./g, (e) => {
|
|
99
|
+
let n = e[1], r = n.toUpperCase() === n ? { truncateThreshold: Infinity } : void 0;
|
|
100
|
+
if ("df".includes(n)) return String(Number(t.shift()));
|
|
101
|
+
if ("jJ".includes(n)) return C(t.shift(), r);
|
|
102
|
+
if ("sSoO".includes(n)) {
|
|
103
|
+
let e = t.shift();
|
|
104
|
+
return e instanceof Error ? `${e}\n${e.stack}` : e && typeof e == "object" ? C(e, r) : S(String(e), r);
|
|
105
|
+
}
|
|
106
|
+
return e;
|
|
107
|
+
});
|
|
108
|
+
return t.length && (n += " " + t.join(" ")), n;
|
|
109
|
+
}
|
|
110
|
+
function T() {
|
|
111
|
+
let e = { status: "pending" };
|
|
112
|
+
return e.promise = new Promise((t, n) => {
|
|
113
|
+
e.resolve = t, e.reject = n;
|
|
114
|
+
}), e.promise.then(() => {
|
|
115
|
+
e.status = "resolved";
|
|
116
|
+
}, () => {
|
|
117
|
+
e.status = "rejected";
|
|
118
|
+
}), e;
|
|
119
|
+
}
|
|
120
|
+
function E(e, t) {
|
|
121
|
+
return function(...n) {
|
|
122
|
+
return t.call(this, e, ...n);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function D(e) {
|
|
126
|
+
return Array.from(e).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
127
|
+
}
|
|
128
|
+
function O(e) {
|
|
129
|
+
return new Promise((t, n) => {
|
|
130
|
+
let r = document.createElement("script");
|
|
131
|
+
r.src = e, r.onload = t, r.onerror = n, document.head.append(r), r.remove();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/buffer.ts
|
|
136
|
+
var k = new Uint8Array([13, 10]), A = class {
|
|
137
|
+
buffer = new Uint8Array();
|
|
138
|
+
requests = [];
|
|
139
|
+
isClosed = !1;
|
|
140
|
+
read(e = 8192) {
|
|
141
|
+
let t = T();
|
|
142
|
+
return this.requests.push({
|
|
143
|
+
deferred: t,
|
|
144
|
+
handle: () => {
|
|
145
|
+
let n = Math.min(e, this.buffer.length), r = this.buffer.subarray(0, n);
|
|
146
|
+
return this.buffer = this.buffer.subarray(n), t.resolve(r), !0;
|
|
147
|
+
}
|
|
148
|
+
}), this.processBuffer(), t.promise;
|
|
149
|
+
}
|
|
150
|
+
readExact(e) {
|
|
151
|
+
let t = T();
|
|
152
|
+
return this.requests.push({
|
|
153
|
+
deferred: t,
|
|
154
|
+
handle: () => {
|
|
155
|
+
if (e > this.buffer.length) return !1;
|
|
156
|
+
let n = this.buffer.subarray(0, e);
|
|
157
|
+
return this.buffer = this.buffer.subarray(e), t.resolve(n), !0;
|
|
158
|
+
}
|
|
159
|
+
}), this.processBuffer(), t.promise;
|
|
160
|
+
}
|
|
161
|
+
readUntil(e = k) {
|
|
162
|
+
typeof e == "string" && (e = v(e));
|
|
163
|
+
let t = T();
|
|
164
|
+
return this.requests.push({
|
|
165
|
+
deferred: t,
|
|
166
|
+
handle: () => {
|
|
167
|
+
let n = M(this.buffer, e);
|
|
168
|
+
if (n < 0) return !1;
|
|
169
|
+
let r = n + e.length, i = this.buffer.subarray(0, r);
|
|
170
|
+
return this.buffer = this.buffer.subarray(r), t.resolve(i), !0;
|
|
171
|
+
}
|
|
172
|
+
}), this.processBuffer(), t.promise;
|
|
173
|
+
}
|
|
174
|
+
feed(e) {
|
|
175
|
+
if (this.isClosed) throw Error("Buffer is closed");
|
|
176
|
+
this.buffer = j(this.buffer, e), this.processBuffer();
|
|
177
|
+
}
|
|
178
|
+
close() {
|
|
179
|
+
this.isClosed = !0, this.processBuffer();
|
|
180
|
+
}
|
|
181
|
+
processBuffer() {
|
|
182
|
+
for (; this.requests.length;) {
|
|
183
|
+
let e = this.requests[0];
|
|
184
|
+
if (!e.handle()) if (this.isClosed) e.deferred.reject(/* @__PURE__ */ Error("Buffer is closed"));
|
|
185
|
+
else break;
|
|
186
|
+
this.requests.shift();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
319
189
|
};
|
|
320
|
-
function j(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
function
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
190
|
+
function j(e, t) {
|
|
191
|
+
let n = new Uint8Array(e.length + t.length);
|
|
192
|
+
return n.set(e, 0), n.set(t, e.length), n;
|
|
193
|
+
}
|
|
194
|
+
function M(e, t) {
|
|
195
|
+
if (!t.length) return 0;
|
|
196
|
+
for (let n = 0; n <= e.length - t.length; n += 1) {
|
|
197
|
+
let r;
|
|
198
|
+
for (r = 0; r < t.length && e[n + r] === t[r]; r += 1);
|
|
199
|
+
if (r === t.length) return n;
|
|
200
|
+
}
|
|
201
|
+
return -1;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/concurrency.ts
|
|
205
|
+
function N(e, t) {
|
|
206
|
+
let n = [], r = /* @__PURE__ */ new Set();
|
|
207
|
+
async function i() {
|
|
208
|
+
let e = T();
|
|
209
|
+
return n.push(e), o(), await e.promise, e;
|
|
210
|
+
}
|
|
211
|
+
function a(e) {
|
|
212
|
+
r.delete(e), o();
|
|
213
|
+
}
|
|
214
|
+
function o() {
|
|
215
|
+
for (; n.length && r.size < t;) {
|
|
216
|
+
let e = n.shift();
|
|
217
|
+
r.add(e), e.resolve();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function s(...t) {
|
|
221
|
+
let n = await i();
|
|
222
|
+
try {
|
|
223
|
+
return await e(...t);
|
|
224
|
+
} finally {
|
|
225
|
+
a(n);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return s;
|
|
229
|
+
}
|
|
230
|
+
var P = class {
|
|
231
|
+
data = [];
|
|
232
|
+
getQueue = /* @__PURE__ */ new Set();
|
|
233
|
+
putQueue = /* @__PURE__ */ new Set();
|
|
234
|
+
constructor(e = 0) {
|
|
235
|
+
this.maxSize = e;
|
|
236
|
+
}
|
|
237
|
+
get size() {
|
|
238
|
+
return this.data.length;
|
|
239
|
+
}
|
|
240
|
+
defer(e, t = 0) {
|
|
241
|
+
let n = T();
|
|
242
|
+
return e.add(n), n.promise.finally(() => {
|
|
243
|
+
e.delete(n);
|
|
244
|
+
}), t && setTimeout(n.reject, t), n.promise;
|
|
245
|
+
}
|
|
246
|
+
resolve(e) {
|
|
247
|
+
let t = e.values().next().value;
|
|
248
|
+
t && (t.resolve(), e.delete(t));
|
|
249
|
+
}
|
|
250
|
+
async get(e = 0) {
|
|
251
|
+
this.data.length || await this.defer(this.getQueue, e);
|
|
252
|
+
let t = this.data.shift();
|
|
253
|
+
return this.resolve(this.putQueue), t;
|
|
254
|
+
}
|
|
255
|
+
async put(e, t = 0) {
|
|
256
|
+
this.maxSize && this.data.length >= this.maxSize && await this.defer(this.putQueue, t), this.data.push(e), this.resolve(this.getQueue);
|
|
257
|
+
}
|
|
258
|
+
}, F = class e {
|
|
259
|
+
static defaultOptions = {};
|
|
260
|
+
output;
|
|
261
|
+
options;
|
|
262
|
+
constructor(t) {
|
|
263
|
+
this.options = {
|
|
264
|
+
...e.defaultOptions,
|
|
265
|
+
...typeof t == "string" ? { prefix: t } : t
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
getPrefix() {
|
|
269
|
+
let { prefix: e } = this.options;
|
|
270
|
+
return typeof e == "function" && (e = e()), e || "";
|
|
271
|
+
}
|
|
272
|
+
collect() {
|
|
273
|
+
return this.output = [], () => {
|
|
274
|
+
let { output: e } = this;
|
|
275
|
+
if (this.output = void 0, !e) throw Error("Logs already collected");
|
|
276
|
+
return e;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
log(e, t, ...n) {
|
|
280
|
+
let r = w(t, ...n);
|
|
281
|
+
this.output && this.output.push(r), console[e](this.getPrefix(), r);
|
|
282
|
+
}
|
|
283
|
+
info(e, ...t) {
|
|
284
|
+
return this.log("info", e, ...t);
|
|
285
|
+
}
|
|
286
|
+
error(e, ...t) {
|
|
287
|
+
return this.log("error", e, ...t);
|
|
288
|
+
}
|
|
289
|
+
wrap(e, t) {
|
|
290
|
+
let n = this;
|
|
291
|
+
return E(e, function(e, ...r) {
|
|
292
|
+
return t.call(this, n, e, ...r);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
351
295
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}) : n && Object.entries(n).forEach(([t, r]) => {
|
|
401
|
-
if (Array.isArray(r)) {
|
|
402
|
-
const i = t.endsWith("[]") ? t : `${t}[]`;
|
|
403
|
-
r.forEach((s) => {
|
|
404
|
-
e.append(i, s);
|
|
405
|
-
});
|
|
406
|
-
} else
|
|
407
|
-
e.append(t, r);
|
|
408
|
-
}), e;
|
|
409
|
-
}
|
|
410
|
-
function fe(n, e) {
|
|
411
|
-
const { json: t, timeout: r = 1e4, searchParams: i, ...s } = e || {}, o = new AbortController(), a = r ? setTimeout(() => o.abort(), r) : null, u = new Headers(s.headers);
|
|
412
|
-
t != null && (s.body = JSON.stringify(t), u.set("content-type", "application/json"));
|
|
413
|
-
const f = new URL(n);
|
|
414
|
-
i && (f.search = J(i).toString());
|
|
415
|
-
async function c(l) {
|
|
416
|
-
let d;
|
|
417
|
-
try {
|
|
418
|
-
d = await fetch(f, {
|
|
419
|
-
...s,
|
|
420
|
-
headers: u,
|
|
421
|
-
signal: o.signal
|
|
422
|
-
});
|
|
423
|
-
const h = await l(d);
|
|
424
|
-
if (!d.ok)
|
|
425
|
-
throw new p(
|
|
426
|
-
d.statusText,
|
|
427
|
-
{
|
|
428
|
-
url: f.toString(),
|
|
429
|
-
method: s.method || "GET",
|
|
430
|
-
options: e
|
|
431
|
-
},
|
|
432
|
-
d,
|
|
433
|
-
h
|
|
434
|
-
);
|
|
435
|
-
return h;
|
|
436
|
-
} catch (h) {
|
|
437
|
-
throw h instanceof p ? h : new p(
|
|
438
|
-
h?.message || `${h}`,
|
|
439
|
-
{
|
|
440
|
-
url: f.toString(),
|
|
441
|
-
method: s.method || "GET",
|
|
442
|
-
options: e
|
|
443
|
-
},
|
|
444
|
-
d,
|
|
445
|
-
h
|
|
446
|
-
);
|
|
447
|
-
} finally {
|
|
448
|
-
a && clearTimeout(a);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return {
|
|
452
|
-
async arrayBuffer() {
|
|
453
|
-
return c((l) => l.arrayBuffer());
|
|
454
|
-
},
|
|
455
|
-
async blob() {
|
|
456
|
-
return c((l) => l.blob());
|
|
457
|
-
},
|
|
458
|
-
async json() {
|
|
459
|
-
return u.has("accept") || u.set("accept", "application/json"), c((l) => l.json());
|
|
460
|
-
},
|
|
461
|
-
async text() {
|
|
462
|
-
return c((l) => l.text());
|
|
463
|
-
},
|
|
464
|
-
abort() {
|
|
465
|
-
o.abort();
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
const A = [
|
|
470
|
-
["ms", 1],
|
|
471
|
-
["s", 1e3],
|
|
472
|
-
["m", 60],
|
|
473
|
-
["h", 60],
|
|
474
|
-
["d", 24],
|
|
475
|
-
["mo", 30],
|
|
476
|
-
["y", 365 / 30]
|
|
477
|
-
];
|
|
478
|
-
function ce(n, e) {
|
|
479
|
-
let r = `${n}`.match(/[a-zA-Z]+$/)?.[0] || "", i = r ? +`${n}`.slice(0, -r.length) : +n;
|
|
480
|
-
if (r) {
|
|
481
|
-
for (const [s, o] of e?.intervalLevels || A)
|
|
482
|
-
if (i *= o, s === r) {
|
|
483
|
-
r = "";
|
|
484
|
-
break;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (r || isNaN(i))
|
|
488
|
-
throw new Error(`Invalid interval: ${n}`);
|
|
489
|
-
return i;
|
|
490
|
-
}
|
|
491
|
-
function le(n, e) {
|
|
492
|
-
const t = Math.sign(n);
|
|
493
|
-
n = Math.abs(n);
|
|
494
|
-
let r = "ms";
|
|
495
|
-
for (const [i, s] of e?.intervalLevels || A) {
|
|
496
|
-
if (n < s) break;
|
|
497
|
-
n /= s, r = i;
|
|
498
|
-
}
|
|
499
|
-
return `${t < 0 ? "-" : ""}${j(n, e) || ""}${r}`;
|
|
500
|
-
}
|
|
501
|
-
function he(n) {
|
|
502
|
-
return [n.getFullYear(), n.getMonth() + 1, n.getDate()].map((e) => `${e}`.padStart(2, "0")).join("-");
|
|
503
|
-
}
|
|
504
|
-
function de(n) {
|
|
505
|
-
return new Intl.DateTimeFormat("en-GB", {
|
|
506
|
-
dateStyle: "short",
|
|
507
|
-
timeStyle: "medium"
|
|
508
|
-
}).format(new Date(n));
|
|
509
|
-
}
|
|
510
|
-
export {
|
|
511
|
-
te as BufferReader,
|
|
512
|
-
M as CrLf,
|
|
513
|
-
U as Logger,
|
|
514
|
-
ne as Queue,
|
|
515
|
-
p as SimpleRequestError,
|
|
516
|
-
_ as b64decode,
|
|
517
|
-
H as b64encode,
|
|
518
|
-
V as b64urlDecode,
|
|
519
|
-
K as b64urlEncode,
|
|
520
|
-
J as buildSearchParams,
|
|
521
|
-
X as bytesToHex,
|
|
522
|
-
O as concatBuffer,
|
|
523
|
-
Y as decodeText,
|
|
524
|
-
A as defaultIntervalLevels,
|
|
525
|
-
m as defer,
|
|
526
|
-
se as deflateNumber,
|
|
527
|
-
F as encodeText,
|
|
528
|
-
he as formatDate,
|
|
529
|
-
le as formatInterval,
|
|
530
|
-
j as formatNumber,
|
|
531
|
-
oe as formatPercentage,
|
|
532
|
-
$ as formatString,
|
|
533
|
-
ie as inflateNumber,
|
|
534
|
-
re as limitConcurrency,
|
|
535
|
-
ee as loadJS,
|
|
536
|
-
ce as normalizeInterval,
|
|
537
|
-
ae as rateLimiter,
|
|
538
|
-
W as replacerBigInt,
|
|
539
|
-
de as reprDate,
|
|
540
|
-
v as reprJson,
|
|
541
|
-
z as searchBuffer,
|
|
542
|
-
fe as simpleRequest,
|
|
543
|
-
D as truncateString,
|
|
544
|
-
ue as waitUntil,
|
|
545
|
-
I as wrapFunction
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/number.ts
|
|
298
|
+
function I(t, n) {
|
|
299
|
+
return BigInt(e(t).multipliedBy(e(10).exponentiatedBy(n)).toFixed(0));
|
|
300
|
+
}
|
|
301
|
+
function L(t, n) {
|
|
302
|
+
return e(t).dividedBy(e(10).exponentiatedBy(n)).toNumber();
|
|
303
|
+
}
|
|
304
|
+
var R = {
|
|
305
|
+
maximumFractionDigits: 4,
|
|
306
|
+
exponentialThresholdLarge: 1e6,
|
|
307
|
+
exponentialThresholdSmall: 1e-6,
|
|
308
|
+
minimumSignificantDigits: 2,
|
|
309
|
+
maximumSignificantDigits: 8,
|
|
310
|
+
quantizationStep: 0,
|
|
311
|
+
keepTrailingZeros: !1
|
|
312
|
+
};
|
|
313
|
+
function z(e, t) {
|
|
314
|
+
if (e == null || e === "") return "";
|
|
315
|
+
let n = +e;
|
|
316
|
+
if (Number.isNaN(n)) return "";
|
|
317
|
+
let r = {
|
|
318
|
+
...R,
|
|
319
|
+
...t
|
|
320
|
+
};
|
|
321
|
+
r.quantizationStep > 0 && (n = Math.round(n / r.quantizationStep) * r.quantizationStep);
|
|
322
|
+
let i = Math.abs(n), a = r.maximumSignificantDigits;
|
|
323
|
+
if (n !== 0 && (i >= r.exponentialThresholdLarge || i < r.exponentialThresholdSmall)) {
|
|
324
|
+
let e;
|
|
325
|
+
return r.keepTrailingZeros ? e = n.toExponential(Math.max(0, a - 1)) : (e = n.toPrecision(a), e = (+e).toExponential()), e;
|
|
326
|
+
}
|
|
327
|
+
let o = {
|
|
328
|
+
useGrouping: !1,
|
|
329
|
+
notation: "standard"
|
|
330
|
+
};
|
|
331
|
+
t?.maximumFractionDigits === void 0 ? (o.minimumSignificantDigits = r.minimumSignificantDigits, o.maximumSignificantDigits = a) : o.maximumFractionDigits = r.maximumFractionDigits;
|
|
332
|
+
let s = new Intl.NumberFormat("en-US", o).format(n);
|
|
333
|
+
return !r.keepTrailingZeros && s.includes(".") && (s = s.replace(/\.?0+$/, "")), s;
|
|
334
|
+
}
|
|
335
|
+
function B(e, t) {
|
|
336
|
+
return z(e * 100, t) + "%";
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/rate-limiter.ts
|
|
340
|
+
var V = {
|
|
341
|
+
interval: 2e3,
|
|
342
|
+
maxRetry: 6,
|
|
343
|
+
maxInterval: 0
|
|
546
344
|
};
|
|
345
|
+
function H(e) {
|
|
346
|
+
let n = {
|
|
347
|
+
...V,
|
|
348
|
+
...e
|
|
349
|
+
}, { interval: r, maxInterval: i } = n;
|
|
350
|
+
i && i < r && (i = r);
|
|
351
|
+
let a = Promise.resolve();
|
|
352
|
+
return function(e) {
|
|
353
|
+
let o = a.then(async () => {
|
|
354
|
+
let a = "Unknown error";
|
|
355
|
+
for (let o = 0; o < n.maxRetry; o += 1) try {
|
|
356
|
+
let t = await e();
|
|
357
|
+
return r = Math.max(n.interval, r / 2), t;
|
|
358
|
+
} catch (e) {
|
|
359
|
+
if (a = e, n.isTooFrequent?.(e)) r *= 2, i && (r = Math.min(i, r)), n.onScheduleRetry?.(r), await t(r);
|
|
360
|
+
else throw e;
|
|
361
|
+
}
|
|
362
|
+
throw a;
|
|
363
|
+
});
|
|
364
|
+
return a = o.catch(() => {}).then(() => t(r)), o;
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
async function U(e, n) {
|
|
368
|
+
let r = {
|
|
369
|
+
...V,
|
|
370
|
+
...n
|
|
371
|
+
}, { interval: i, maxInterval: a } = r;
|
|
372
|
+
a && a < i && (a = i);
|
|
373
|
+
let o;
|
|
374
|
+
for (let n = 0; n < r.maxRetry && (o = await e(), !o.ok); n += 1) o.interval ? i = o.interval : i *= 2, a && (i = Math.min(a, i)), await t(i);
|
|
375
|
+
return o;
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/request.ts
|
|
379
|
+
var W = class extends Error {
|
|
380
|
+
constructor(e, t, n, r) {
|
|
381
|
+
super(e, { cause: r }), this.request = t, this.response = n;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
function G(e) {
|
|
385
|
+
let t = new URLSearchParams();
|
|
386
|
+
return Array.isArray(e) || e instanceof URLSearchParams ? new URLSearchParams(e).forEach((e, n) => {
|
|
387
|
+
t.append(n, e);
|
|
388
|
+
}) : e && Object.entries(e).forEach(([e, n]) => {
|
|
389
|
+
if (Array.isArray(n)) {
|
|
390
|
+
let r = e.endsWith("[]") ? e : `${e}[]`;
|
|
391
|
+
n.forEach((e) => {
|
|
392
|
+
t.append(r, e);
|
|
393
|
+
});
|
|
394
|
+
} else t.append(e, n);
|
|
395
|
+
}), t;
|
|
396
|
+
}
|
|
397
|
+
function K(e, t) {
|
|
398
|
+
let { json: n, timeout: r = 1e4, searchParams: i, ...a } = t || {}, o = new AbortController(), s = r ? setTimeout(() => o.abort(), r) : null, c = new Headers(a.headers);
|
|
399
|
+
n != null && (a.body = JSON.stringify(n), c.set("content-type", "application/json"));
|
|
400
|
+
let l = new URL(e);
|
|
401
|
+
i && (l.search = G(i).toString());
|
|
402
|
+
async function u(e) {
|
|
403
|
+
let n;
|
|
404
|
+
try {
|
|
405
|
+
n = await fetch(l, {
|
|
406
|
+
...a,
|
|
407
|
+
headers: c,
|
|
408
|
+
signal: o.signal
|
|
409
|
+
});
|
|
410
|
+
let r = await e(n);
|
|
411
|
+
if (!n.ok) throw new W(n.statusText, {
|
|
412
|
+
url: l.toString(),
|
|
413
|
+
method: a.method || "GET",
|
|
414
|
+
options: t
|
|
415
|
+
}, n, r);
|
|
416
|
+
return r;
|
|
417
|
+
} catch (e) {
|
|
418
|
+
throw e instanceof W ? e : new W(e?.message || `${e}`, {
|
|
419
|
+
url: l.toString(),
|
|
420
|
+
method: a.method || "GET",
|
|
421
|
+
options: t
|
|
422
|
+
}, n, e);
|
|
423
|
+
} finally {
|
|
424
|
+
s && clearTimeout(s);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
async arrayBuffer() {
|
|
429
|
+
return u((e) => e.arrayBuffer());
|
|
430
|
+
},
|
|
431
|
+
async blob() {
|
|
432
|
+
return u((e) => e.blob());
|
|
433
|
+
},
|
|
434
|
+
async json() {
|
|
435
|
+
return c.has("accept") || c.set("accept", "application/json"), u((e) => e.json());
|
|
436
|
+
},
|
|
437
|
+
async text() {
|
|
438
|
+
return u((e) => e.text());
|
|
439
|
+
},
|
|
440
|
+
abort() {
|
|
441
|
+
o.abort();
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/time.ts
|
|
447
|
+
var q = [
|
|
448
|
+
["ms", 1],
|
|
449
|
+
["s", 1e3],
|
|
450
|
+
["m", 60],
|
|
451
|
+
["h", 60],
|
|
452
|
+
["d", 24],
|
|
453
|
+
["mo", 30],
|
|
454
|
+
["y", 365 / 30]
|
|
455
|
+
];
|
|
456
|
+
function J(e, t) {
|
|
457
|
+
let n = `${e}`.match(/[a-zA-Z]+$/)?.[0] || "", r = n ? +`${e}`.slice(0, -n.length) : +e;
|
|
458
|
+
if (n) {
|
|
459
|
+
for (let [e, i] of t?.intervalLevels || q) if (r *= i, e === n) {
|
|
460
|
+
n = "";
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (n || isNaN(r)) throw Error(`Invalid interval: ${e}`);
|
|
465
|
+
return r;
|
|
466
|
+
}
|
|
467
|
+
function Y(e, t) {
|
|
468
|
+
let n = Math.sign(e);
|
|
469
|
+
e = Math.abs(e);
|
|
470
|
+
let r = "ms";
|
|
471
|
+
for (let [n, i] of t?.intervalLevels || q) {
|
|
472
|
+
if (e < i) break;
|
|
473
|
+
e /= i, r = n;
|
|
474
|
+
}
|
|
475
|
+
return `${n < 0 ? "-" : ""}${z(e, t) || ""}${r}`;
|
|
476
|
+
}
|
|
477
|
+
function X(e) {
|
|
478
|
+
return [
|
|
479
|
+
e.getFullYear(),
|
|
480
|
+
e.getMonth() + 1,
|
|
481
|
+
e.getDate()
|
|
482
|
+
].map((e) => `${e}`.padStart(2, "0")).join("-");
|
|
483
|
+
}
|
|
484
|
+
function Z(e) {
|
|
485
|
+
return new Intl.DateTimeFormat("en-GB", {
|
|
486
|
+
dateStyle: "short",
|
|
487
|
+
timeStyle: "medium"
|
|
488
|
+
}).format(new Date(e));
|
|
489
|
+
}
|
|
490
|
+
//#endregion
|
|
491
|
+
export { A as BufferReader, k as CrLf, F as Logger, P as Queue, W as SimpleRequestError, h as b64decode, m as b64encode, _ as b64urlDecode, g as b64urlEncode, G as buildSearchParams, D as bytesToHex, j as concatBuffer, y as decodeText, q as defaultIntervalLevels, T as defer, L as deflateNumber, v as encodeText, X as formatDate, Y as formatInterval, z as formatNumber, B as formatPercentage, w as formatString, I as inflateNumber, N as limitConcurrency, O as loadJS, J as normalizeInterval, H as rateLimiter, b as replacerBigInt, Z as reprDate, C as reprJson, M as searchBuffer, K as simpleRequest, S as truncateString, U as waitUntil, E as wrapFunction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gera2ld/common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"registry": "https://registry.npmjs.org/"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"bignumber.js": "^
|
|
20
|
-
"es-toolkit": "^1.
|
|
19
|
+
"bignumber.js": "^11.0.0",
|
|
20
|
+
"es-toolkit": "^1.45.1"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"clean": "del-cli dist tsconfig.tsbuildinfo",
|