@tradejs/cli 1.0.0
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/README.md +65 -0
- package/dist/cli.js +10727 -0
- package/dist/lib/runBot.js +157 -0
- package/dist/scripts/backtest.js +2044 -0
- package/dist/scripts/bot.js +153 -0
- package/dist/scripts/cleanDir.js +40 -0
- package/dist/scripts/cleanRedis.js +40 -0
- package/dist/scripts/cleanTests.js +81 -0
- package/dist/scripts/continuity.js +183 -0
- package/dist/scripts/derivativesIngest.js +107 -0
- package/dist/scripts/derivativesIngestCoinalyzeAll.js +391 -0
- package/dist/scripts/doctor.js +5143 -0
- package/dist/scripts/findMlSignalsByTestSuite.js +83 -0
- package/dist/scripts/infraCommon.js +135 -0
- package/dist/scripts/infraDown.js +82 -0
- package/dist/scripts/infraInit.js +107 -0
- package/dist/scripts/infraUp.js +82 -0
- package/dist/scripts/migration.js +67 -0
- package/dist/scripts/mlExport.js +95 -0
- package/dist/scripts/mlExportSelect.js +100 -0
- package/dist/scripts/mlInspect.js +553 -0
- package/dist/scripts/mlTrainLatestSelect.js +1056 -0
- package/dist/scripts/results.js +1909 -0
- package/dist/scripts/selectStrategy.js +99 -0
- package/dist/scripts/signals.js +300 -0
- package/dist/scripts/test-ml.js +133 -0
- package/dist/scripts/test.js +16 -0
- package/dist/scripts/user-add.js +64 -0
- package/dist/workers/testerWorker.js +54 -0
- package/package.json +75 -0
|
@@ -0,0 +1,2044 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// ../../node_modules/debug/node_modules/ms/index.js
|
|
29
|
+
var require_ms = __commonJS({
|
|
30
|
+
"../../node_modules/debug/node_modules/ms/index.js"(exports2, module2) {
|
|
31
|
+
"use strict";
|
|
32
|
+
var s = 1e3;
|
|
33
|
+
var m = s * 60;
|
|
34
|
+
var h = m * 60;
|
|
35
|
+
var d = h * 24;
|
|
36
|
+
var w = d * 7;
|
|
37
|
+
var y = d * 365.25;
|
|
38
|
+
module2.exports = function(val, options) {
|
|
39
|
+
options = options || {};
|
|
40
|
+
var type = typeof val;
|
|
41
|
+
if (type === "string" && val.length > 0) {
|
|
42
|
+
return parse(val);
|
|
43
|
+
} else if (type === "number" && isFinite(val)) {
|
|
44
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
45
|
+
}
|
|
46
|
+
throw new Error(
|
|
47
|
+
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
function parse(str) {
|
|
51
|
+
str = String(str);
|
|
52
|
+
if (str.length > 100) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
56
|
+
str
|
|
57
|
+
);
|
|
58
|
+
if (!match) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var n = parseFloat(match[1]);
|
|
62
|
+
var type = (match[2] || "ms").toLowerCase();
|
|
63
|
+
switch (type) {
|
|
64
|
+
case "years":
|
|
65
|
+
case "year":
|
|
66
|
+
case "yrs":
|
|
67
|
+
case "yr":
|
|
68
|
+
case "y":
|
|
69
|
+
return n * y;
|
|
70
|
+
case "weeks":
|
|
71
|
+
case "week":
|
|
72
|
+
case "w":
|
|
73
|
+
return n * w;
|
|
74
|
+
case "days":
|
|
75
|
+
case "day":
|
|
76
|
+
case "d":
|
|
77
|
+
return n * d;
|
|
78
|
+
case "hours":
|
|
79
|
+
case "hour":
|
|
80
|
+
case "hrs":
|
|
81
|
+
case "hr":
|
|
82
|
+
case "h":
|
|
83
|
+
return n * h;
|
|
84
|
+
case "minutes":
|
|
85
|
+
case "minute":
|
|
86
|
+
case "mins":
|
|
87
|
+
case "min":
|
|
88
|
+
case "m":
|
|
89
|
+
return n * m;
|
|
90
|
+
case "seconds":
|
|
91
|
+
case "second":
|
|
92
|
+
case "secs":
|
|
93
|
+
case "sec":
|
|
94
|
+
case "s":
|
|
95
|
+
return n * s;
|
|
96
|
+
case "milliseconds":
|
|
97
|
+
case "millisecond":
|
|
98
|
+
case "msecs":
|
|
99
|
+
case "msec":
|
|
100
|
+
case "ms":
|
|
101
|
+
return n;
|
|
102
|
+
default:
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function fmtShort(ms) {
|
|
107
|
+
var msAbs = Math.abs(ms);
|
|
108
|
+
if (msAbs >= d) {
|
|
109
|
+
return Math.round(ms / d) + "d";
|
|
110
|
+
}
|
|
111
|
+
if (msAbs >= h) {
|
|
112
|
+
return Math.round(ms / h) + "h";
|
|
113
|
+
}
|
|
114
|
+
if (msAbs >= m) {
|
|
115
|
+
return Math.round(ms / m) + "m";
|
|
116
|
+
}
|
|
117
|
+
if (msAbs >= s) {
|
|
118
|
+
return Math.round(ms / s) + "s";
|
|
119
|
+
}
|
|
120
|
+
return ms + "ms";
|
|
121
|
+
}
|
|
122
|
+
function fmtLong(ms) {
|
|
123
|
+
var msAbs = Math.abs(ms);
|
|
124
|
+
if (msAbs >= d) {
|
|
125
|
+
return plural(ms, msAbs, d, "day");
|
|
126
|
+
}
|
|
127
|
+
if (msAbs >= h) {
|
|
128
|
+
return plural(ms, msAbs, h, "hour");
|
|
129
|
+
}
|
|
130
|
+
if (msAbs >= m) {
|
|
131
|
+
return plural(ms, msAbs, m, "minute");
|
|
132
|
+
}
|
|
133
|
+
if (msAbs >= s) {
|
|
134
|
+
return plural(ms, msAbs, s, "second");
|
|
135
|
+
}
|
|
136
|
+
return ms + " ms";
|
|
137
|
+
}
|
|
138
|
+
function plural(ms, msAbs, n, name) {
|
|
139
|
+
var isPlural = msAbs >= n * 1.5;
|
|
140
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ../../node_modules/debug/src/common.js
|
|
146
|
+
var require_common = __commonJS({
|
|
147
|
+
"../../node_modules/debug/src/common.js"(exports2, module2) {
|
|
148
|
+
"use strict";
|
|
149
|
+
function setup(env) {
|
|
150
|
+
createDebug.debug = createDebug;
|
|
151
|
+
createDebug.default = createDebug;
|
|
152
|
+
createDebug.coerce = coerce;
|
|
153
|
+
createDebug.disable = disable;
|
|
154
|
+
createDebug.enable = enable;
|
|
155
|
+
createDebug.enabled = enabled;
|
|
156
|
+
createDebug.humanize = require_ms();
|
|
157
|
+
createDebug.destroy = destroy;
|
|
158
|
+
Object.keys(env).forEach((key) => {
|
|
159
|
+
createDebug[key] = env[key];
|
|
160
|
+
});
|
|
161
|
+
createDebug.names = [];
|
|
162
|
+
createDebug.skips = [];
|
|
163
|
+
createDebug.formatters = {};
|
|
164
|
+
function selectColor(namespace) {
|
|
165
|
+
let hash = 0;
|
|
166
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
167
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
168
|
+
hash |= 0;
|
|
169
|
+
}
|
|
170
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
171
|
+
}
|
|
172
|
+
createDebug.selectColor = selectColor;
|
|
173
|
+
function createDebug(namespace) {
|
|
174
|
+
let prevTime;
|
|
175
|
+
let enableOverride = null;
|
|
176
|
+
let namespacesCache;
|
|
177
|
+
let enabledCache;
|
|
178
|
+
function debug(...args2) {
|
|
179
|
+
if (!debug.enabled) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const self = debug;
|
|
183
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
184
|
+
const ms = curr - (prevTime || curr);
|
|
185
|
+
self.diff = ms;
|
|
186
|
+
self.prev = prevTime;
|
|
187
|
+
self.curr = curr;
|
|
188
|
+
prevTime = curr;
|
|
189
|
+
args2[0] = createDebug.coerce(args2[0]);
|
|
190
|
+
if (typeof args2[0] !== "string") {
|
|
191
|
+
args2.unshift("%O");
|
|
192
|
+
}
|
|
193
|
+
let index = 0;
|
|
194
|
+
args2[0] = args2[0].replace(/%([a-zA-Z%])/g, (match, format2) => {
|
|
195
|
+
if (match === "%%") {
|
|
196
|
+
return "%";
|
|
197
|
+
}
|
|
198
|
+
index++;
|
|
199
|
+
const formatter = createDebug.formatters[format2];
|
|
200
|
+
if (typeof formatter === "function") {
|
|
201
|
+
const val = args2[index];
|
|
202
|
+
match = formatter.call(self, val);
|
|
203
|
+
args2.splice(index, 1);
|
|
204
|
+
index--;
|
|
205
|
+
}
|
|
206
|
+
return match;
|
|
207
|
+
});
|
|
208
|
+
createDebug.formatArgs.call(self, args2);
|
|
209
|
+
const logFn = self.log || createDebug.log;
|
|
210
|
+
logFn.apply(self, args2);
|
|
211
|
+
}
|
|
212
|
+
debug.namespace = namespace;
|
|
213
|
+
debug.useColors = createDebug.useColors();
|
|
214
|
+
debug.color = createDebug.selectColor(namespace);
|
|
215
|
+
debug.extend = extend;
|
|
216
|
+
debug.destroy = createDebug.destroy;
|
|
217
|
+
Object.defineProperty(debug, "enabled", {
|
|
218
|
+
enumerable: true,
|
|
219
|
+
configurable: false,
|
|
220
|
+
get: () => {
|
|
221
|
+
if (enableOverride !== null) {
|
|
222
|
+
return enableOverride;
|
|
223
|
+
}
|
|
224
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
225
|
+
namespacesCache = createDebug.namespaces;
|
|
226
|
+
enabledCache = createDebug.enabled(namespace);
|
|
227
|
+
}
|
|
228
|
+
return enabledCache;
|
|
229
|
+
},
|
|
230
|
+
set: (v) => {
|
|
231
|
+
enableOverride = v;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (typeof createDebug.init === "function") {
|
|
235
|
+
createDebug.init(debug);
|
|
236
|
+
}
|
|
237
|
+
return debug;
|
|
238
|
+
}
|
|
239
|
+
function extend(namespace, delimiter) {
|
|
240
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
241
|
+
newDebug.log = this.log;
|
|
242
|
+
return newDebug;
|
|
243
|
+
}
|
|
244
|
+
function enable(namespaces) {
|
|
245
|
+
createDebug.save(namespaces);
|
|
246
|
+
createDebug.namespaces = namespaces;
|
|
247
|
+
createDebug.names = [];
|
|
248
|
+
createDebug.skips = [];
|
|
249
|
+
let i;
|
|
250
|
+
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
|
|
251
|
+
const len = split.length;
|
|
252
|
+
for (i = 0; i < len; i++) {
|
|
253
|
+
if (!split[i]) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
namespaces = split[i].replace(/\*/g, ".*?");
|
|
257
|
+
if (namespaces[0] === "-") {
|
|
258
|
+
createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
|
|
259
|
+
} else {
|
|
260
|
+
createDebug.names.push(new RegExp("^" + namespaces + "$"));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function disable() {
|
|
265
|
+
const namespaces = [
|
|
266
|
+
...createDebug.names.map(toNamespace),
|
|
267
|
+
...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
|
|
268
|
+
].join(",");
|
|
269
|
+
createDebug.enable("");
|
|
270
|
+
return namespaces;
|
|
271
|
+
}
|
|
272
|
+
function enabled(name) {
|
|
273
|
+
if (name[name.length - 1] === "*") {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
let i;
|
|
277
|
+
let len;
|
|
278
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
279
|
+
if (createDebug.skips[i].test(name)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
284
|
+
if (createDebug.names[i].test(name)) {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
function toNamespace(regexp) {
|
|
291
|
+
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
|
|
292
|
+
}
|
|
293
|
+
function coerce(val) {
|
|
294
|
+
if (val instanceof Error) {
|
|
295
|
+
return val.stack || val.message;
|
|
296
|
+
}
|
|
297
|
+
return val;
|
|
298
|
+
}
|
|
299
|
+
function destroy() {
|
|
300
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
301
|
+
}
|
|
302
|
+
createDebug.enable(createDebug.load());
|
|
303
|
+
return createDebug;
|
|
304
|
+
}
|
|
305
|
+
module2.exports = setup;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// ../../node_modules/debug/src/browser.js
|
|
310
|
+
var require_browser = __commonJS({
|
|
311
|
+
"../../node_modules/debug/src/browser.js"(exports2, module2) {
|
|
312
|
+
"use strict";
|
|
313
|
+
exports2.formatArgs = formatArgs;
|
|
314
|
+
exports2.save = save;
|
|
315
|
+
exports2.load = load;
|
|
316
|
+
exports2.useColors = useColors;
|
|
317
|
+
exports2.storage = localstorage();
|
|
318
|
+
exports2.destroy = /* @__PURE__ */ (() => {
|
|
319
|
+
let warned = false;
|
|
320
|
+
return () => {
|
|
321
|
+
if (!warned) {
|
|
322
|
+
warned = true;
|
|
323
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
})();
|
|
327
|
+
exports2.colors = [
|
|
328
|
+
"#0000CC",
|
|
329
|
+
"#0000FF",
|
|
330
|
+
"#0033CC",
|
|
331
|
+
"#0033FF",
|
|
332
|
+
"#0066CC",
|
|
333
|
+
"#0066FF",
|
|
334
|
+
"#0099CC",
|
|
335
|
+
"#0099FF",
|
|
336
|
+
"#00CC00",
|
|
337
|
+
"#00CC33",
|
|
338
|
+
"#00CC66",
|
|
339
|
+
"#00CC99",
|
|
340
|
+
"#00CCCC",
|
|
341
|
+
"#00CCFF",
|
|
342
|
+
"#3300CC",
|
|
343
|
+
"#3300FF",
|
|
344
|
+
"#3333CC",
|
|
345
|
+
"#3333FF",
|
|
346
|
+
"#3366CC",
|
|
347
|
+
"#3366FF",
|
|
348
|
+
"#3399CC",
|
|
349
|
+
"#3399FF",
|
|
350
|
+
"#33CC00",
|
|
351
|
+
"#33CC33",
|
|
352
|
+
"#33CC66",
|
|
353
|
+
"#33CC99",
|
|
354
|
+
"#33CCCC",
|
|
355
|
+
"#33CCFF",
|
|
356
|
+
"#6600CC",
|
|
357
|
+
"#6600FF",
|
|
358
|
+
"#6633CC",
|
|
359
|
+
"#6633FF",
|
|
360
|
+
"#66CC00",
|
|
361
|
+
"#66CC33",
|
|
362
|
+
"#9900CC",
|
|
363
|
+
"#9900FF",
|
|
364
|
+
"#9933CC",
|
|
365
|
+
"#9933FF",
|
|
366
|
+
"#99CC00",
|
|
367
|
+
"#99CC33",
|
|
368
|
+
"#CC0000",
|
|
369
|
+
"#CC0033",
|
|
370
|
+
"#CC0066",
|
|
371
|
+
"#CC0099",
|
|
372
|
+
"#CC00CC",
|
|
373
|
+
"#CC00FF",
|
|
374
|
+
"#CC3300",
|
|
375
|
+
"#CC3333",
|
|
376
|
+
"#CC3366",
|
|
377
|
+
"#CC3399",
|
|
378
|
+
"#CC33CC",
|
|
379
|
+
"#CC33FF",
|
|
380
|
+
"#CC6600",
|
|
381
|
+
"#CC6633",
|
|
382
|
+
"#CC9900",
|
|
383
|
+
"#CC9933",
|
|
384
|
+
"#CCCC00",
|
|
385
|
+
"#CCCC33",
|
|
386
|
+
"#FF0000",
|
|
387
|
+
"#FF0033",
|
|
388
|
+
"#FF0066",
|
|
389
|
+
"#FF0099",
|
|
390
|
+
"#FF00CC",
|
|
391
|
+
"#FF00FF",
|
|
392
|
+
"#FF3300",
|
|
393
|
+
"#FF3333",
|
|
394
|
+
"#FF3366",
|
|
395
|
+
"#FF3399",
|
|
396
|
+
"#FF33CC",
|
|
397
|
+
"#FF33FF",
|
|
398
|
+
"#FF6600",
|
|
399
|
+
"#FF6633",
|
|
400
|
+
"#FF9900",
|
|
401
|
+
"#FF9933",
|
|
402
|
+
"#FFCC00",
|
|
403
|
+
"#FFCC33"
|
|
404
|
+
];
|
|
405
|
+
function useColors() {
|
|
406
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
413
|
+
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
414
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
415
|
+
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
416
|
+
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
417
|
+
}
|
|
418
|
+
function formatArgs(args2) {
|
|
419
|
+
args2[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args2[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
|
|
420
|
+
if (!this.useColors) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const c = "color: " + this.color;
|
|
424
|
+
args2.splice(1, 0, c, "color: inherit");
|
|
425
|
+
let index = 0;
|
|
426
|
+
let lastC = 0;
|
|
427
|
+
args2[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
428
|
+
if (match === "%%") {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
index++;
|
|
432
|
+
if (match === "%c") {
|
|
433
|
+
lastC = index;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
args2.splice(lastC, 0, c);
|
|
437
|
+
}
|
|
438
|
+
exports2.log = console.debug || console.log || (() => {
|
|
439
|
+
});
|
|
440
|
+
function save(namespaces) {
|
|
441
|
+
try {
|
|
442
|
+
if (namespaces) {
|
|
443
|
+
exports2.storage.setItem("debug", namespaces);
|
|
444
|
+
} else {
|
|
445
|
+
exports2.storage.removeItem("debug");
|
|
446
|
+
}
|
|
447
|
+
} catch (error) {
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function load() {
|
|
451
|
+
let r;
|
|
452
|
+
try {
|
|
453
|
+
r = exports2.storage.getItem("debug");
|
|
454
|
+
} catch (error) {
|
|
455
|
+
}
|
|
456
|
+
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
457
|
+
r = process.env.DEBUG;
|
|
458
|
+
}
|
|
459
|
+
return r;
|
|
460
|
+
}
|
|
461
|
+
function localstorage() {
|
|
462
|
+
try {
|
|
463
|
+
return localStorage;
|
|
464
|
+
} catch (error) {
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
module2.exports = require_common()(exports2);
|
|
468
|
+
var { formatters } = module2.exports;
|
|
469
|
+
formatters.j = function(v) {
|
|
470
|
+
try {
|
|
471
|
+
return JSON.stringify(v);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// ../../node_modules/has-flag/index.js
|
|
480
|
+
var require_has_flag = __commonJS({
|
|
481
|
+
"../../node_modules/has-flag/index.js"(exports2, module2) {
|
|
482
|
+
"use strict";
|
|
483
|
+
module2.exports = (flag, argv = process.argv) => {
|
|
484
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
485
|
+
const position = argv.indexOf(prefix + flag);
|
|
486
|
+
const terminatorPosition = argv.indexOf("--");
|
|
487
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// ../../node_modules/supports-color/index.js
|
|
493
|
+
var require_supports_color = __commonJS({
|
|
494
|
+
"../../node_modules/supports-color/index.js"(exports2, module2) {
|
|
495
|
+
"use strict";
|
|
496
|
+
var os2 = require("os");
|
|
497
|
+
var tty = require("tty");
|
|
498
|
+
var hasFlag = require_has_flag();
|
|
499
|
+
var { env } = process;
|
|
500
|
+
var forceColor;
|
|
501
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
502
|
+
forceColor = 0;
|
|
503
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
504
|
+
forceColor = 1;
|
|
505
|
+
}
|
|
506
|
+
if ("FORCE_COLOR" in env) {
|
|
507
|
+
if (env.FORCE_COLOR === "true") {
|
|
508
|
+
forceColor = 1;
|
|
509
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
510
|
+
forceColor = 0;
|
|
511
|
+
} else {
|
|
512
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function translateLevel(level) {
|
|
516
|
+
if (level === 0) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
level,
|
|
521
|
+
hasBasic: true,
|
|
522
|
+
has256: level >= 2,
|
|
523
|
+
has16m: level >= 3
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
527
|
+
if (forceColor === 0) {
|
|
528
|
+
return 0;
|
|
529
|
+
}
|
|
530
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
531
|
+
return 3;
|
|
532
|
+
}
|
|
533
|
+
if (hasFlag("color=256")) {
|
|
534
|
+
return 2;
|
|
535
|
+
}
|
|
536
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
537
|
+
return 0;
|
|
538
|
+
}
|
|
539
|
+
const min = forceColor || 0;
|
|
540
|
+
if (env.TERM === "dumb") {
|
|
541
|
+
return min;
|
|
542
|
+
}
|
|
543
|
+
if (process.platform === "win32") {
|
|
544
|
+
const osRelease = os2.release().split(".");
|
|
545
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
546
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
547
|
+
}
|
|
548
|
+
return 1;
|
|
549
|
+
}
|
|
550
|
+
if ("CI" in env) {
|
|
551
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
552
|
+
return 1;
|
|
553
|
+
}
|
|
554
|
+
return min;
|
|
555
|
+
}
|
|
556
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
557
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
558
|
+
}
|
|
559
|
+
if (env.COLORTERM === "truecolor") {
|
|
560
|
+
return 3;
|
|
561
|
+
}
|
|
562
|
+
if ("TERM_PROGRAM" in env) {
|
|
563
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
564
|
+
switch (env.TERM_PROGRAM) {
|
|
565
|
+
case "iTerm.app":
|
|
566
|
+
return version >= 3 ? 3 : 2;
|
|
567
|
+
case "Apple_Terminal":
|
|
568
|
+
return 2;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
572
|
+
return 2;
|
|
573
|
+
}
|
|
574
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
575
|
+
return 1;
|
|
576
|
+
}
|
|
577
|
+
if ("COLORTERM" in env) {
|
|
578
|
+
return 1;
|
|
579
|
+
}
|
|
580
|
+
return min;
|
|
581
|
+
}
|
|
582
|
+
function getSupportLevel(stream) {
|
|
583
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
584
|
+
return translateLevel(level);
|
|
585
|
+
}
|
|
586
|
+
module2.exports = {
|
|
587
|
+
supportsColor: getSupportLevel,
|
|
588
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
589
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// ../../node_modules/debug/src/node.js
|
|
595
|
+
var require_node = __commonJS({
|
|
596
|
+
"../../node_modules/debug/src/node.js"(exports2, module2) {
|
|
597
|
+
"use strict";
|
|
598
|
+
var tty = require("tty");
|
|
599
|
+
var util = require("util");
|
|
600
|
+
exports2.init = init;
|
|
601
|
+
exports2.log = log;
|
|
602
|
+
exports2.formatArgs = formatArgs;
|
|
603
|
+
exports2.save = save;
|
|
604
|
+
exports2.load = load;
|
|
605
|
+
exports2.useColors = useColors;
|
|
606
|
+
exports2.destroy = util.deprecate(
|
|
607
|
+
() => {
|
|
608
|
+
},
|
|
609
|
+
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
610
|
+
);
|
|
611
|
+
exports2.colors = [6, 2, 3, 4, 5, 1];
|
|
612
|
+
try {
|
|
613
|
+
const supportsColor = require_supports_color();
|
|
614
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
615
|
+
exports2.colors = [
|
|
616
|
+
20,
|
|
617
|
+
21,
|
|
618
|
+
26,
|
|
619
|
+
27,
|
|
620
|
+
32,
|
|
621
|
+
33,
|
|
622
|
+
38,
|
|
623
|
+
39,
|
|
624
|
+
40,
|
|
625
|
+
41,
|
|
626
|
+
42,
|
|
627
|
+
43,
|
|
628
|
+
44,
|
|
629
|
+
45,
|
|
630
|
+
56,
|
|
631
|
+
57,
|
|
632
|
+
62,
|
|
633
|
+
63,
|
|
634
|
+
68,
|
|
635
|
+
69,
|
|
636
|
+
74,
|
|
637
|
+
75,
|
|
638
|
+
76,
|
|
639
|
+
77,
|
|
640
|
+
78,
|
|
641
|
+
79,
|
|
642
|
+
80,
|
|
643
|
+
81,
|
|
644
|
+
92,
|
|
645
|
+
93,
|
|
646
|
+
98,
|
|
647
|
+
99,
|
|
648
|
+
112,
|
|
649
|
+
113,
|
|
650
|
+
128,
|
|
651
|
+
129,
|
|
652
|
+
134,
|
|
653
|
+
135,
|
|
654
|
+
148,
|
|
655
|
+
149,
|
|
656
|
+
160,
|
|
657
|
+
161,
|
|
658
|
+
162,
|
|
659
|
+
163,
|
|
660
|
+
164,
|
|
661
|
+
165,
|
|
662
|
+
166,
|
|
663
|
+
167,
|
|
664
|
+
168,
|
|
665
|
+
169,
|
|
666
|
+
170,
|
|
667
|
+
171,
|
|
668
|
+
172,
|
|
669
|
+
173,
|
|
670
|
+
178,
|
|
671
|
+
179,
|
|
672
|
+
184,
|
|
673
|
+
185,
|
|
674
|
+
196,
|
|
675
|
+
197,
|
|
676
|
+
198,
|
|
677
|
+
199,
|
|
678
|
+
200,
|
|
679
|
+
201,
|
|
680
|
+
202,
|
|
681
|
+
203,
|
|
682
|
+
204,
|
|
683
|
+
205,
|
|
684
|
+
206,
|
|
685
|
+
207,
|
|
686
|
+
208,
|
|
687
|
+
209,
|
|
688
|
+
214,
|
|
689
|
+
215,
|
|
690
|
+
220,
|
|
691
|
+
221
|
|
692
|
+
];
|
|
693
|
+
}
|
|
694
|
+
} catch (error) {
|
|
695
|
+
}
|
|
696
|
+
exports2.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
697
|
+
return /^debug_/i.test(key);
|
|
698
|
+
}).reduce((obj, key) => {
|
|
699
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_2, k) => {
|
|
700
|
+
return k.toUpperCase();
|
|
701
|
+
});
|
|
702
|
+
let val = process.env[key];
|
|
703
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
704
|
+
val = true;
|
|
705
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
706
|
+
val = false;
|
|
707
|
+
} else if (val === "null") {
|
|
708
|
+
val = null;
|
|
709
|
+
} else {
|
|
710
|
+
val = Number(val);
|
|
711
|
+
}
|
|
712
|
+
obj[prop] = val;
|
|
713
|
+
return obj;
|
|
714
|
+
}, {});
|
|
715
|
+
function useColors() {
|
|
716
|
+
return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
717
|
+
}
|
|
718
|
+
function formatArgs(args2) {
|
|
719
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
720
|
+
if (useColors2) {
|
|
721
|
+
const c = this.color;
|
|
722
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
723
|
+
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
724
|
+
args2[0] = prefix + args2[0].split("\n").join("\n" + prefix);
|
|
725
|
+
args2.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
|
|
726
|
+
} else {
|
|
727
|
+
args2[0] = getDate() + name + " " + args2[0];
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function getDate() {
|
|
731
|
+
if (exports2.inspectOpts.hideDate) {
|
|
732
|
+
return "";
|
|
733
|
+
}
|
|
734
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
735
|
+
}
|
|
736
|
+
function log(...args2) {
|
|
737
|
+
return process.stderr.write(util.format(...args2) + "\n");
|
|
738
|
+
}
|
|
739
|
+
function save(namespaces) {
|
|
740
|
+
if (namespaces) {
|
|
741
|
+
process.env.DEBUG = namespaces;
|
|
742
|
+
} else {
|
|
743
|
+
delete process.env.DEBUG;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function load() {
|
|
747
|
+
return process.env.DEBUG;
|
|
748
|
+
}
|
|
749
|
+
function init(debug) {
|
|
750
|
+
debug.inspectOpts = {};
|
|
751
|
+
const keys = Object.keys(exports2.inspectOpts);
|
|
752
|
+
for (let i = 0; i < keys.length; i++) {
|
|
753
|
+
debug.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
module2.exports = require_common()(exports2);
|
|
757
|
+
var { formatters } = module2.exports;
|
|
758
|
+
formatters.o = function(v) {
|
|
759
|
+
this.inspectOpts.colors = this.useColors;
|
|
760
|
+
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
761
|
+
};
|
|
762
|
+
formatters.O = function(v) {
|
|
763
|
+
this.inspectOpts.colors = this.useColors;
|
|
764
|
+
return util.inspect(v, this.inspectOpts);
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
// ../../node_modules/debug/src/index.js
|
|
770
|
+
var require_src = __commonJS({
|
|
771
|
+
"../../node_modules/debug/src/index.js"(exports2, module2) {
|
|
772
|
+
"use strict";
|
|
773
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
774
|
+
module2.exports = require_browser();
|
|
775
|
+
} else {
|
|
776
|
+
module2.exports = require_node();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
// ../../node_modules/eastasianwidth/eastasianwidth.js
|
|
782
|
+
var require_eastasianwidth = __commonJS({
|
|
783
|
+
"../../node_modules/eastasianwidth/eastasianwidth.js"(exports2, module2) {
|
|
784
|
+
"use strict";
|
|
785
|
+
var eaw = {};
|
|
786
|
+
if ("undefined" == typeof module2) {
|
|
787
|
+
window.eastasianwidth = eaw;
|
|
788
|
+
} else {
|
|
789
|
+
module2.exports = eaw;
|
|
790
|
+
}
|
|
791
|
+
eaw.eastAsianWidth = function(character) {
|
|
792
|
+
var x = character.charCodeAt(0);
|
|
793
|
+
var y = character.length == 2 ? character.charCodeAt(1) : 0;
|
|
794
|
+
var codePoint = x;
|
|
795
|
+
if (55296 <= x && x <= 56319 && (56320 <= y && y <= 57343)) {
|
|
796
|
+
x &= 1023;
|
|
797
|
+
y &= 1023;
|
|
798
|
+
codePoint = x << 10 | y;
|
|
799
|
+
codePoint += 65536;
|
|
800
|
+
}
|
|
801
|
+
if (12288 == codePoint || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510) {
|
|
802
|
+
return "F";
|
|
803
|
+
}
|
|
804
|
+
if (8361 == codePoint || 65377 <= codePoint && codePoint <= 65470 || 65474 <= codePoint && codePoint <= 65479 || 65482 <= codePoint && codePoint <= 65487 || 65490 <= codePoint && codePoint <= 65495 || 65498 <= codePoint && codePoint <= 65500 || 65512 <= codePoint && codePoint <= 65518) {
|
|
805
|
+
return "H";
|
|
806
|
+
}
|
|
807
|
+
if (4352 <= codePoint && codePoint <= 4447 || 4515 <= codePoint && codePoint <= 4519 || 4602 <= codePoint && codePoint <= 4607 || 9001 <= codePoint && codePoint <= 9002 || 11904 <= codePoint && codePoint <= 11929 || 11931 <= codePoint && codePoint <= 12019 || 12032 <= codePoint && codePoint <= 12245 || 12272 <= codePoint && codePoint <= 12283 || 12289 <= codePoint && codePoint <= 12350 || 12353 <= codePoint && codePoint <= 12438 || 12441 <= codePoint && codePoint <= 12543 || 12549 <= codePoint && codePoint <= 12589 || 12593 <= codePoint && codePoint <= 12686 || 12688 <= codePoint && codePoint <= 12730 || 12736 <= codePoint && codePoint <= 12771 || 12784 <= codePoint && codePoint <= 12830 || 12832 <= codePoint && codePoint <= 12871 || 12880 <= codePoint && codePoint <= 13054 || 13056 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42124 || 42128 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 55216 <= codePoint && codePoint <= 55238 || 55243 <= codePoint && codePoint <= 55291 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65106 || 65108 <= codePoint && codePoint <= 65126 || 65128 <= codePoint && codePoint <= 65131 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127490 || 127504 <= codePoint && codePoint <= 127546 || 127552 <= codePoint && codePoint <= 127560 || 127568 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 194367 || 177984 <= codePoint && codePoint <= 196605 || 196608 <= codePoint && codePoint <= 262141) {
|
|
808
|
+
return "W";
|
|
809
|
+
}
|
|
810
|
+
if (32 <= codePoint && codePoint <= 126 || 162 <= codePoint && codePoint <= 163 || 165 <= codePoint && codePoint <= 166 || 172 == codePoint || 175 == codePoint || 10214 <= codePoint && codePoint <= 10221 || 10629 <= codePoint && codePoint <= 10630) {
|
|
811
|
+
return "Na";
|
|
812
|
+
}
|
|
813
|
+
if (161 == codePoint || 164 == codePoint || 167 <= codePoint && codePoint <= 168 || 170 == codePoint || 173 <= codePoint && codePoint <= 174 || 176 <= codePoint && codePoint <= 180 || 182 <= codePoint && codePoint <= 186 || 188 <= codePoint && codePoint <= 191 || 198 == codePoint || 208 == codePoint || 215 <= codePoint && codePoint <= 216 || 222 <= codePoint && codePoint <= 225 || 230 == codePoint || 232 <= codePoint && codePoint <= 234 || 236 <= codePoint && codePoint <= 237 || 240 == codePoint || 242 <= codePoint && codePoint <= 243 || 247 <= codePoint && codePoint <= 250 || 252 == codePoint || 254 == codePoint || 257 == codePoint || 273 == codePoint || 275 == codePoint || 283 == codePoint || 294 <= codePoint && codePoint <= 295 || 299 == codePoint || 305 <= codePoint && codePoint <= 307 || 312 == codePoint || 319 <= codePoint && codePoint <= 322 || 324 == codePoint || 328 <= codePoint && codePoint <= 331 || 333 == codePoint || 338 <= codePoint && codePoint <= 339 || 358 <= codePoint && codePoint <= 359 || 363 == codePoint || 462 == codePoint || 464 == codePoint || 466 == codePoint || 468 == codePoint || 470 == codePoint || 472 == codePoint || 474 == codePoint || 476 == codePoint || 593 == codePoint || 609 == codePoint || 708 == codePoint || 711 == codePoint || 713 <= codePoint && codePoint <= 715 || 717 == codePoint || 720 == codePoint || 728 <= codePoint && codePoint <= 731 || 733 == codePoint || 735 == codePoint || 768 <= codePoint && codePoint <= 879 || 913 <= codePoint && codePoint <= 929 || 931 <= codePoint && codePoint <= 937 || 945 <= codePoint && codePoint <= 961 || 963 <= codePoint && codePoint <= 969 || 1025 == codePoint || 1040 <= codePoint && codePoint <= 1103 || 1105 == codePoint || 8208 == codePoint || 8211 <= codePoint && codePoint <= 8214 || 8216 <= codePoint && codePoint <= 8217 || 8220 <= codePoint && codePoint <= 8221 || 8224 <= codePoint && codePoint <= 8226 || 8228 <= codePoint && codePoint <= 8231 || 8240 == codePoint || 8242 <= codePoint && codePoint <= 8243 || 8245 == codePoint || 8251 == codePoint || 8254 == codePoint || 8308 == codePoint || 8319 == codePoint || 8321 <= codePoint && codePoint <= 8324 || 8364 == codePoint || 8451 == codePoint || 8453 == codePoint || 8457 == codePoint || 8467 == codePoint || 8470 == codePoint || 8481 <= codePoint && codePoint <= 8482 || 8486 == codePoint || 8491 == codePoint || 8531 <= codePoint && codePoint <= 8532 || 8539 <= codePoint && codePoint <= 8542 || 8544 <= codePoint && codePoint <= 8555 || 8560 <= codePoint && codePoint <= 8569 || 8585 == codePoint || 8592 <= codePoint && codePoint <= 8601 || 8632 <= codePoint && codePoint <= 8633 || 8658 == codePoint || 8660 == codePoint || 8679 == codePoint || 8704 == codePoint || 8706 <= codePoint && codePoint <= 8707 || 8711 <= codePoint && codePoint <= 8712 || 8715 == codePoint || 8719 == codePoint || 8721 == codePoint || 8725 == codePoint || 8730 == codePoint || 8733 <= codePoint && codePoint <= 8736 || 8739 == codePoint || 8741 == codePoint || 8743 <= codePoint && codePoint <= 8748 || 8750 == codePoint || 8756 <= codePoint && codePoint <= 8759 || 8764 <= codePoint && codePoint <= 8765 || 8776 == codePoint || 8780 == codePoint || 8786 == codePoint || 8800 <= codePoint && codePoint <= 8801 || 8804 <= codePoint && codePoint <= 8807 || 8810 <= codePoint && codePoint <= 8811 || 8814 <= codePoint && codePoint <= 8815 || 8834 <= codePoint && codePoint <= 8835 || 8838 <= codePoint && codePoint <= 8839 || 8853 == codePoint || 8857 == codePoint || 8869 == codePoint || 8895 == codePoint || 8978 == codePoint || 9312 <= codePoint && codePoint <= 9449 || 9451 <= codePoint && codePoint <= 9547 || 9552 <= codePoint && codePoint <= 9587 || 9600 <= codePoint && codePoint <= 9615 || 9618 <= codePoint && codePoint <= 9621 || 9632 <= codePoint && codePoint <= 9633 || 9635 <= codePoint && codePoint <= 9641 || 9650 <= codePoint && codePoint <= 9651 || 9654 <= codePoint && codePoint <= 9655 || 9660 <= codePoint && codePoint <= 9661 || 9664 <= codePoint && codePoint <= 9665 || 9670 <= codePoint && codePoint <= 9672 || 9675 == codePoint || 9678 <= codePoint && codePoint <= 9681 || 9698 <= codePoint && codePoint <= 9701 || 9711 == codePoint || 9733 <= codePoint && codePoint <= 9734 || 9737 == codePoint || 9742 <= codePoint && codePoint <= 9743 || 9748 <= codePoint && codePoint <= 9749 || 9756 == codePoint || 9758 == codePoint || 9792 == codePoint || 9794 == codePoint || 9824 <= codePoint && codePoint <= 9825 || 9827 <= codePoint && codePoint <= 9829 || 9831 <= codePoint && codePoint <= 9834 || 9836 <= codePoint && codePoint <= 9837 || 9839 == codePoint || 9886 <= codePoint && codePoint <= 9887 || 9918 <= codePoint && codePoint <= 9919 || 9924 <= codePoint && codePoint <= 9933 || 9935 <= codePoint && codePoint <= 9953 || 9955 == codePoint || 9960 <= codePoint && codePoint <= 9983 || 10045 == codePoint || 10071 == codePoint || 10102 <= codePoint && codePoint <= 10111 || 11093 <= codePoint && codePoint <= 11097 || 12872 <= codePoint && codePoint <= 12879 || 57344 <= codePoint && codePoint <= 63743 || 65024 <= codePoint && codePoint <= 65039 || 65533 == codePoint || 127232 <= codePoint && codePoint <= 127242 || 127248 <= codePoint && codePoint <= 127277 || 127280 <= codePoint && codePoint <= 127337 || 127344 <= codePoint && codePoint <= 127386 || 917760 <= codePoint && codePoint <= 917999 || 983040 <= codePoint && codePoint <= 1048573 || 1048576 <= codePoint && codePoint <= 1114109) {
|
|
814
|
+
return "A";
|
|
815
|
+
}
|
|
816
|
+
return "N";
|
|
817
|
+
};
|
|
818
|
+
eaw.characterLength = function(character) {
|
|
819
|
+
var code = this.eastAsianWidth(character);
|
|
820
|
+
if (code == "F" || code == "W" || code == "A") {
|
|
821
|
+
return 2;
|
|
822
|
+
} else {
|
|
823
|
+
return 1;
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
function stringToArray(string) {
|
|
827
|
+
return string.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
|
|
828
|
+
}
|
|
829
|
+
eaw.length = function(string) {
|
|
830
|
+
var characters = stringToArray(string);
|
|
831
|
+
var len = 0;
|
|
832
|
+
for (var i = 0; i < characters.length; i++) {
|
|
833
|
+
len = len + this.characterLength(characters[i]);
|
|
834
|
+
}
|
|
835
|
+
return len;
|
|
836
|
+
};
|
|
837
|
+
eaw.slice = function(text, start, end) {
|
|
838
|
+
textLen = eaw.length(text);
|
|
839
|
+
start = start ? start : 0;
|
|
840
|
+
end = end ? end : 1;
|
|
841
|
+
if (start < 0) {
|
|
842
|
+
start = textLen + start;
|
|
843
|
+
}
|
|
844
|
+
if (end < 0) {
|
|
845
|
+
end = textLen + end;
|
|
846
|
+
}
|
|
847
|
+
var result = "";
|
|
848
|
+
var eawLen = 0;
|
|
849
|
+
var chars = stringToArray(text);
|
|
850
|
+
for (var i = 0; i < chars.length; i++) {
|
|
851
|
+
var char = chars[i];
|
|
852
|
+
var charLen = eaw.length(char);
|
|
853
|
+
if (eawLen >= start - (charLen == 2 ? 1 : 0)) {
|
|
854
|
+
if (eawLen + charLen <= end) {
|
|
855
|
+
result += char;
|
|
856
|
+
} else {
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
eawLen += charLen;
|
|
861
|
+
}
|
|
862
|
+
return result;
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
// ../../node_modules/list-it/lib/data-cell.js
|
|
868
|
+
var require_data_cell = __commonJS({
|
|
869
|
+
"../../node_modules/list-it/lib/data-cell.js"(exports2, module2) {
|
|
870
|
+
"use strict";
|
|
871
|
+
var eaw = require_eastasianwidth();
|
|
872
|
+
function DataCell() {
|
|
873
|
+
this.data = "";
|
|
874
|
+
}
|
|
875
|
+
module2.exports = DataCell;
|
|
876
|
+
DataCell.prototype.getData = function() {
|
|
877
|
+
return this.data;
|
|
878
|
+
};
|
|
879
|
+
DataCell.prototype.setData = function(data) {
|
|
880
|
+
this.data = data;
|
|
881
|
+
};
|
|
882
|
+
DataCell.prototype.visibleLength = function() {
|
|
883
|
+
if (typeof this.data != "string") {
|
|
884
|
+
return ("" + this.data).length;
|
|
885
|
+
}
|
|
886
|
+
return DataCell.visibleLength(this.data);
|
|
887
|
+
};
|
|
888
|
+
DataCell.visibleLength = function(data) {
|
|
889
|
+
const s = data.replace(/\x1b[^m]*m/g, "");
|
|
890
|
+
return eaw.length(s);
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/list-it/lib/row.js
|
|
896
|
+
var require_row = __commonJS({
|
|
897
|
+
"../../node_modules/list-it/lib/row.js"(exports2, module2) {
|
|
898
|
+
"use strict";
|
|
899
|
+
function Row() {
|
|
900
|
+
this.cells = [];
|
|
901
|
+
this.empty = true;
|
|
902
|
+
this.fixed = false;
|
|
903
|
+
}
|
|
904
|
+
module2.exports = Row;
|
|
905
|
+
Row.prototype.getCellLength = function() {
|
|
906
|
+
return this.cells.length;
|
|
907
|
+
};
|
|
908
|
+
Row.prototype.getCell = function(idx) {
|
|
909
|
+
return this.cells[idx];
|
|
910
|
+
};
|
|
911
|
+
Row.prototype.pushCell = function(cell) {
|
|
912
|
+
if (this.isFixed()) {
|
|
913
|
+
throw "pushCell Fail, The row was already fixed.";
|
|
914
|
+
}
|
|
915
|
+
this.empty = false;
|
|
916
|
+
return this.cells.push(cell);
|
|
917
|
+
};
|
|
918
|
+
Row.prototype.fix = function() {
|
|
919
|
+
this.fixed = true;
|
|
920
|
+
};
|
|
921
|
+
Row.prototype.isEmpty = function() {
|
|
922
|
+
return this.empty;
|
|
923
|
+
};
|
|
924
|
+
Row.prototype.isFixed = function() {
|
|
925
|
+
return this.fixed;
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
// ../../node_modules/list-it/lib/column.js
|
|
931
|
+
var require_column = __commonJS({
|
|
932
|
+
"../../node_modules/list-it/lib/column.js"(exports2, module2) {
|
|
933
|
+
"use strict";
|
|
934
|
+
var DataCell = require_data_cell();
|
|
935
|
+
function Column() {
|
|
936
|
+
this.opt = {
|
|
937
|
+
"autoAlign": false
|
|
938
|
+
};
|
|
939
|
+
this.width = 0;
|
|
940
|
+
this.textWidth = null;
|
|
941
|
+
this.intLen = 0;
|
|
942
|
+
this.fracLen = 0;
|
|
943
|
+
this.expLen = 0;
|
|
944
|
+
this.cellAtRow = {};
|
|
945
|
+
this.header = null;
|
|
946
|
+
}
|
|
947
|
+
module2.exports = Column;
|
|
948
|
+
Column.prototype.getWidth = function() {
|
|
949
|
+
return this.width;
|
|
950
|
+
};
|
|
951
|
+
Column.prototype.setTextWidth = function(textWidth) {
|
|
952
|
+
this.textWidth = textWidth;
|
|
953
|
+
};
|
|
954
|
+
Column.prototype.setCellAt = function(row, cell) {
|
|
955
|
+
this.cellAtRow[row] = cell;
|
|
956
|
+
};
|
|
957
|
+
Column.prototype.setHeader = function(header) {
|
|
958
|
+
this.header = header;
|
|
959
|
+
};
|
|
960
|
+
Column.prototype.hasHeader = function() {
|
|
961
|
+
return this.header != null;
|
|
962
|
+
};
|
|
963
|
+
Column.prototype.updateWidth = function() {
|
|
964
|
+
const headerWidth = !this.hasHeader() ? 0 : DataCell.visibleLength("" + this.header);
|
|
965
|
+
this.width = headerWidth;
|
|
966
|
+
Object.keys(this.cellAtRow).forEach((key) => {
|
|
967
|
+
const cell = this.cellAtRow[key];
|
|
968
|
+
const data = cell.getData();
|
|
969
|
+
let width = cell.visibleLength();
|
|
970
|
+
if (typeof data == "number") {
|
|
971
|
+
if (this.opt.autoAlign) {
|
|
972
|
+
this.updateNumWidth(data);
|
|
973
|
+
width = this.getNumMaxWidth();
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (width > this.width) {
|
|
977
|
+
this.width = width;
|
|
978
|
+
}
|
|
979
|
+
if (typeof data == "string") {
|
|
980
|
+
if (this.textWidth && this.textWidth > headerWidth) {
|
|
981
|
+
if (this.width > this.textWidth) {
|
|
982
|
+
this.width = this.textWidth;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
};
|
|
988
|
+
Column.prototype.formatColumnHeader = function() {
|
|
989
|
+
if (!this.hasHeader()) {
|
|
990
|
+
return null;
|
|
991
|
+
}
|
|
992
|
+
const width = this.getWidth();
|
|
993
|
+
const header = this.header;
|
|
994
|
+
const headerWidth = DataCell.visibleLength("" + header);
|
|
995
|
+
if (header.length == headerWidth && width - headerWidth <= 0) {
|
|
996
|
+
return ("" + header).substring(0, width);
|
|
997
|
+
}
|
|
998
|
+
return "" + header + " ".repeat(width - headerWidth);
|
|
999
|
+
};
|
|
1000
|
+
Column.prototype.formatCell = function(data) {
|
|
1001
|
+
const width = this.getWidth();
|
|
1002
|
+
if (this.opt.autoAlign) {
|
|
1003
|
+
if (typeof data == "number") {
|
|
1004
|
+
return this.makeAutoAlignNum(data).padStart(width, " ");
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
const dataWidth = DataCell.visibleLength("" + data);
|
|
1008
|
+
if (data.length == dataWidth && width - dataWidth <= 0) {
|
|
1009
|
+
return ("" + data).substring(0, width);
|
|
1010
|
+
}
|
|
1011
|
+
return "" + data + " ".repeat(width - dataWidth);
|
|
1012
|
+
};
|
|
1013
|
+
Column.prototype.setAutoAlign = function(autoAlign) {
|
|
1014
|
+
this.opt.autoAlign = autoAlign;
|
|
1015
|
+
};
|
|
1016
|
+
Column.prototype.updateNumWidth = function(num) {
|
|
1017
|
+
const numInfo = this.analyzeNumber(num);
|
|
1018
|
+
const intLen = numInfo.intStr.length;
|
|
1019
|
+
const fracLen = numInfo.fracStr.length;
|
|
1020
|
+
const expLen = numInfo.expStr.length;
|
|
1021
|
+
if (intLen > this.intLen) {
|
|
1022
|
+
this.intLen = intLen;
|
|
1023
|
+
}
|
|
1024
|
+
if (fracLen > this.fracLen) {
|
|
1025
|
+
this.fracLen = fracLen;
|
|
1026
|
+
}
|
|
1027
|
+
if (expLen > this.expLen) {
|
|
1028
|
+
this.expLen = expLen;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
Column.prototype.getNumMaxWidth = function() {
|
|
1032
|
+
return this.intLen + this.fracLen + (this.fracLen > 0 ? 1 : 0) + this.expLen + (this.expLen > 0 ? 1 : 0);
|
|
1033
|
+
};
|
|
1034
|
+
Column.prototype.makeAutoAlignNum = function(num) {
|
|
1035
|
+
const numInfo = this.analyzeNumber(num);
|
|
1036
|
+
const intStr = numInfo.intStr.padStart(this.intLen, " ");
|
|
1037
|
+
const fracStr = numInfo.expStr != "" ? numInfo.fracStr.padEnd(this.fracLen, "0") : numInfo.fracStr.padEnd(this.fracLen, " ");
|
|
1038
|
+
const expStr = numInfo.expStr.padEnd(this.expLen, " ");
|
|
1039
|
+
if (numInfo.expStr != "") {
|
|
1040
|
+
return [intStr, ".", fracStr, "e", expStr].join("");
|
|
1041
|
+
}
|
|
1042
|
+
if (numInfo.pointPos >= 0) {
|
|
1043
|
+
if (this.expLen > 0) {
|
|
1044
|
+
return [intStr, ".", fracStr, " ", expStr].join("");
|
|
1045
|
+
}
|
|
1046
|
+
return [intStr, ".", fracStr].join("");
|
|
1047
|
+
} else if (this.fracLen == 0) {
|
|
1048
|
+
return intStr;
|
|
1049
|
+
}
|
|
1050
|
+
if (this.expLen > 0) {
|
|
1051
|
+
return [intStr, ".0", fracStr.substr(1), " ", expStr].join("");
|
|
1052
|
+
}
|
|
1053
|
+
return [intStr, ".0", fracStr.substr(1)].join("");
|
|
1054
|
+
};
|
|
1055
|
+
Column.prototype.analyzeNumber = function(num) {
|
|
1056
|
+
const s = "" + num;
|
|
1057
|
+
let intStr = "";
|
|
1058
|
+
let fracStr = "";
|
|
1059
|
+
const pointPos = s.indexOf(".");
|
|
1060
|
+
const expIndex = s.indexOf("e");
|
|
1061
|
+
if (expIndex >= 0) {
|
|
1062
|
+
if (pointPos < 0) {
|
|
1063
|
+
return {
|
|
1064
|
+
pointPos: expIndex,
|
|
1065
|
+
intStr: s.substr(0, expIndex),
|
|
1066
|
+
fracStr: "0",
|
|
1067
|
+
expStr: s.substr(expIndex + 1)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
pointPos,
|
|
1072
|
+
intStr: s.substr(0, pointPos),
|
|
1073
|
+
fracStr: s.substring(pointPos + 1, expIndex),
|
|
1074
|
+
expStr: s.substr(expIndex + 1)
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
if (pointPos < 0) {
|
|
1078
|
+
intStr = s;
|
|
1079
|
+
} else {
|
|
1080
|
+
intStr = s.substr(0, pointPos);
|
|
1081
|
+
fracStr = s.substr(pointPos + 1);
|
|
1082
|
+
}
|
|
1083
|
+
return {
|
|
1084
|
+
"pointPos": pointPos,
|
|
1085
|
+
"intStr": intStr,
|
|
1086
|
+
"fracStr": fracStr,
|
|
1087
|
+
"expStr": ""
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
// ../../node_modules/ansi-escape-sequences/dist/index.cjs
|
|
1094
|
+
var require_dist = __commonJS({
|
|
1095
|
+
"../../node_modules/ansi-escape-sequences/dist/index.cjs"(exports2, module2) {
|
|
1096
|
+
"use strict";
|
|
1097
|
+
function isObject(input) {
|
|
1098
|
+
return typeof input === "object" && input !== null;
|
|
1099
|
+
}
|
|
1100
|
+
function isArrayLike(input) {
|
|
1101
|
+
return isObject(input) && typeof input.length === "number";
|
|
1102
|
+
}
|
|
1103
|
+
function arrayify(input) {
|
|
1104
|
+
if (Array.isArray(input)) {
|
|
1105
|
+
return input;
|
|
1106
|
+
} else if (input === void 0) {
|
|
1107
|
+
return [];
|
|
1108
|
+
} else if (isArrayLike(input) || input instanceof Set) {
|
|
1109
|
+
return Array.from(input);
|
|
1110
|
+
} else {
|
|
1111
|
+
return [input];
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
var csi = "\x1B[";
|
|
1115
|
+
var ansi = {};
|
|
1116
|
+
ansi.style = {
|
|
1117
|
+
reset: "\x1B[0m",
|
|
1118
|
+
bold: "\x1B[1m",
|
|
1119
|
+
italic: "\x1B[3m",
|
|
1120
|
+
underline: "\x1B[4m",
|
|
1121
|
+
fontDefault: "\x1B[10m",
|
|
1122
|
+
font2: "\x1B[11m",
|
|
1123
|
+
font3: "\x1B[12m",
|
|
1124
|
+
font4: "\x1B[13m",
|
|
1125
|
+
font5: "\x1B[14m",
|
|
1126
|
+
font6: "\x1B[15m",
|
|
1127
|
+
imageNegative: "\x1B[7m",
|
|
1128
|
+
imagePositive: "\x1B[27m",
|
|
1129
|
+
black: "\x1B[30m",
|
|
1130
|
+
red: "\x1B[31m",
|
|
1131
|
+
green: "\x1B[32m",
|
|
1132
|
+
yellow: "\x1B[33m",
|
|
1133
|
+
blue: "\x1B[34m",
|
|
1134
|
+
magenta: "\x1B[35m",
|
|
1135
|
+
cyan: "\x1B[36m",
|
|
1136
|
+
white: "\x1B[37m",
|
|
1137
|
+
grey: "\x1B[90m",
|
|
1138
|
+
gray: "\x1B[90m",
|
|
1139
|
+
brightRed: "\x1B[91m",
|
|
1140
|
+
brightGreen: "\x1B[92m",
|
|
1141
|
+
brightYellow: "\x1B[93m",
|
|
1142
|
+
brightBlue: "\x1B[94m",
|
|
1143
|
+
brightMagenta: "\x1B[95m",
|
|
1144
|
+
brightCyan: "\x1B[96m",
|
|
1145
|
+
brightWhite: "\x1B[97m",
|
|
1146
|
+
"bg-black": "\x1B[40m",
|
|
1147
|
+
"bg-red": "\x1B[41m",
|
|
1148
|
+
"bg-green": "\x1B[42m",
|
|
1149
|
+
"bg-yellow": "\x1B[43m",
|
|
1150
|
+
"bg-blue": "\x1B[44m",
|
|
1151
|
+
"bg-magenta": "\x1B[45m",
|
|
1152
|
+
"bg-cyan": "\x1B[46m",
|
|
1153
|
+
"bg-white": "\x1B[47m",
|
|
1154
|
+
"bg-grey": "\x1B[100m",
|
|
1155
|
+
"bg-gray": "\x1B[100m",
|
|
1156
|
+
"bg-brightRed": "\x1B[101m",
|
|
1157
|
+
"bg-brightGreen": "\x1B[102m",
|
|
1158
|
+
"bg-brightYellow": "\x1B[103m",
|
|
1159
|
+
"bg-brightBlue": "\x1B[104m",
|
|
1160
|
+
"bg-brightMagenta": "\x1B[105m",
|
|
1161
|
+
"bg-brightCyan": "\x1B[106m",
|
|
1162
|
+
"bg-brightWhite": "\x1B[107m"
|
|
1163
|
+
};
|
|
1164
|
+
ansi.rgb = function(r, g, b) {
|
|
1165
|
+
return `\x1B[38;2;${r};${g};${b}m`;
|
|
1166
|
+
};
|
|
1167
|
+
ansi.bgRgb = function(r, g, b) {
|
|
1168
|
+
return `\x1B[48;2;${r};${g};${b}m`;
|
|
1169
|
+
};
|
|
1170
|
+
ansi.styles = function(styles) {
|
|
1171
|
+
styles = arrayify(styles);
|
|
1172
|
+
return styles.map(function(effect) {
|
|
1173
|
+
const rgbMatches = effect.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
|
1174
|
+
const bgRgbMatches = effect.match(/bg-rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
|
1175
|
+
if (bgRgbMatches) {
|
|
1176
|
+
const [full, r, g, b] = bgRgbMatches;
|
|
1177
|
+
return ansi.bgRgb(r, g, b);
|
|
1178
|
+
} else if (rgbMatches) {
|
|
1179
|
+
const [full, r, g, b] = rgbMatches;
|
|
1180
|
+
return ansi.rgb(r, g, b);
|
|
1181
|
+
} else {
|
|
1182
|
+
return ansi.style[effect];
|
|
1183
|
+
}
|
|
1184
|
+
}).join("");
|
|
1185
|
+
};
|
|
1186
|
+
ansi.format = function(str, styleArray) {
|
|
1187
|
+
const re = /\[([\w\s-\(\),]+)\]{([^]*?)}/;
|
|
1188
|
+
let matches;
|
|
1189
|
+
str = String(str);
|
|
1190
|
+
if (!str) return "";
|
|
1191
|
+
while (matches = str.match(re)) {
|
|
1192
|
+
const inlineStyles = matches[1].split(/\s+/);
|
|
1193
|
+
const inlineString = matches[2];
|
|
1194
|
+
str = str.replace(matches[0], ansi.format(inlineString, inlineStyles));
|
|
1195
|
+
}
|
|
1196
|
+
return styleArray && styleArray.length ? ansi.styles(styleArray) + str + ansi.style.reset : str;
|
|
1197
|
+
};
|
|
1198
|
+
ansi.cursor = {
|
|
1199
|
+
/**
|
|
1200
|
+
* Moves the cursor `lines` cells up. If the cursor is already at the edge of the screen, this has no effect
|
|
1201
|
+
* @param [lines=1] {number}
|
|
1202
|
+
* @return {string}
|
|
1203
|
+
*/
|
|
1204
|
+
up: function(lines) {
|
|
1205
|
+
return csi + (lines || 1) + "A";
|
|
1206
|
+
},
|
|
1207
|
+
/**
|
|
1208
|
+
* Moves the cursor `lines` cells down. If the cursor is already at the edge of the screen, this has no effect
|
|
1209
|
+
* @param [lines=1] {number}
|
|
1210
|
+
* @return {string}
|
|
1211
|
+
*/
|
|
1212
|
+
down: function(lines) {
|
|
1213
|
+
return csi + (lines || 1) + "B";
|
|
1214
|
+
},
|
|
1215
|
+
/**
|
|
1216
|
+
* Moves the cursor `lines` cells forward. If the cursor is already at the edge of the screen, this has no effect
|
|
1217
|
+
* @param [lines=1] {number}
|
|
1218
|
+
* @return {string}
|
|
1219
|
+
*/
|
|
1220
|
+
forward: function(lines) {
|
|
1221
|
+
return csi + (lines || 1) + "C";
|
|
1222
|
+
},
|
|
1223
|
+
/**
|
|
1224
|
+
* Moves the cursor `lines` cells back. If the cursor is already at the edge of the screen, this has no effect
|
|
1225
|
+
* @param [lines=1] {number}
|
|
1226
|
+
* @return {string}
|
|
1227
|
+
*/
|
|
1228
|
+
back: function(lines) {
|
|
1229
|
+
return csi + (lines || 1) + "D";
|
|
1230
|
+
},
|
|
1231
|
+
/**
|
|
1232
|
+
* Moves cursor to beginning of the line n lines down.
|
|
1233
|
+
* @param [lines=1] {number}
|
|
1234
|
+
* @return {string}
|
|
1235
|
+
*/
|
|
1236
|
+
nextLine: function(lines) {
|
|
1237
|
+
return csi + (lines || 1) + "E";
|
|
1238
|
+
},
|
|
1239
|
+
/**
|
|
1240
|
+
* Moves cursor to beginning of the line n lines up.
|
|
1241
|
+
* @param [lines=1] {number}
|
|
1242
|
+
* @return {string}
|
|
1243
|
+
*/
|
|
1244
|
+
previousLine: function(lines) {
|
|
1245
|
+
return csi + (lines || 1) + "F";
|
|
1246
|
+
},
|
|
1247
|
+
/**
|
|
1248
|
+
* Moves the cursor to column n.
|
|
1249
|
+
* @param n {number} - column number
|
|
1250
|
+
* @return {string}
|
|
1251
|
+
*/
|
|
1252
|
+
horizontalAbsolute: function(n) {
|
|
1253
|
+
return csi + n + "G";
|
|
1254
|
+
},
|
|
1255
|
+
/**
|
|
1256
|
+
* Moves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted.
|
|
1257
|
+
* @param n {number} - row number
|
|
1258
|
+
* @param m {number} - column number
|
|
1259
|
+
* @return {string}
|
|
1260
|
+
*/
|
|
1261
|
+
position: function(n, m) {
|
|
1262
|
+
return csi + (n || 1) + ";" + (m || 1) + "H";
|
|
1263
|
+
},
|
|
1264
|
+
/**
|
|
1265
|
+
* Hides the cursor
|
|
1266
|
+
*/
|
|
1267
|
+
hide: csi + "?25l",
|
|
1268
|
+
/**
|
|
1269
|
+
* Shows the cursor
|
|
1270
|
+
*/
|
|
1271
|
+
show: csi + "?25h"
|
|
1272
|
+
};
|
|
1273
|
+
ansi.erase = {
|
|
1274
|
+
/**
|
|
1275
|
+
* Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen.
|
|
1276
|
+
* @param n {number}
|
|
1277
|
+
* @return {string}
|
|
1278
|
+
*/
|
|
1279
|
+
display: function(n) {
|
|
1280
|
+
return csi + (n || 0) + "J";
|
|
1281
|
+
},
|
|
1282
|
+
/**
|
|
1283
|
+
* Erases part of the line. If n is zero (or missing), clear from cursor to the end of the line. If n is one, clear from cursor to beginning of the line. If n is two, clear entire line. Cursor position does not change.
|
|
1284
|
+
* @param n {number}
|
|
1285
|
+
* @return {string}
|
|
1286
|
+
*/
|
|
1287
|
+
inLine: function(n) {
|
|
1288
|
+
return csi + (n || 0) + "K";
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
module2.exports = ansi;
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
// ../../node_modules/list-it/lib/list-it-buffer.js
|
|
1296
|
+
var require_list_it_buffer = __commonJS({
|
|
1297
|
+
"../../node_modules/list-it/lib/list-it-buffer.js"(exports2, module2) {
|
|
1298
|
+
"use strict";
|
|
1299
|
+
var debug = require_src()("list-it-buffer");
|
|
1300
|
+
var DataCell = require_data_cell();
|
|
1301
|
+
var Row = require_row();
|
|
1302
|
+
var Column = require_column();
|
|
1303
|
+
var ansi = require_dist();
|
|
1304
|
+
function ListItBuffer(opt) {
|
|
1305
|
+
opt = opt || {};
|
|
1306
|
+
this.opt = {
|
|
1307
|
+
"autoAlign": true,
|
|
1308
|
+
"columnWidth": null,
|
|
1309
|
+
"header": null,
|
|
1310
|
+
"headerBold": false,
|
|
1311
|
+
"headerColor": "",
|
|
1312
|
+
"headerUnderline": false
|
|
1313
|
+
};
|
|
1314
|
+
if (opt.header != null && !Array.isArray(opt.header)) {
|
|
1315
|
+
throw new Error([
|
|
1316
|
+
`Invalid header was specified. It must be an array, but (${JSON.stringify(opt.header)}):${typeof opt.header} was specified.`
|
|
1317
|
+
].join(" "));
|
|
1318
|
+
}
|
|
1319
|
+
if (opt.headerColor && !(opt.headerColor in COLORS)) {
|
|
1320
|
+
throw new Error([
|
|
1321
|
+
`Invalid color ${JSON.stringify(opt.headerColor)} was specified.`,
|
|
1322
|
+
"Available color names:",
|
|
1323
|
+
...AVAILABLE_COLORS.map((color) => `* ${JSON.stringify(color)}`)
|
|
1324
|
+
].join("\n"));
|
|
1325
|
+
}
|
|
1326
|
+
Object.keys(this.opt).forEach((key) => {
|
|
1327
|
+
if (key in opt) {
|
|
1328
|
+
this.opt[key] = opt[key];
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
this.lines = [];
|
|
1332
|
+
this.columns = [];
|
|
1333
|
+
this.columnWidth = this.opt.columnWidth;
|
|
1334
|
+
if (this.opt.header) {
|
|
1335
|
+
this.setHeaderRow(this.opt.header);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
module2.exports = ListItBuffer;
|
|
1339
|
+
ListItBuffer.prototype.nl = function() {
|
|
1340
|
+
const lastRowIndex = this.lines.length - 1;
|
|
1341
|
+
if (lastRowIndex >= 0 && !this.lines[lastRowIndex].isFixed()) {
|
|
1342
|
+
this.lines[lastRowIndex].fix();
|
|
1343
|
+
}
|
|
1344
|
+
this.pushNewRow();
|
|
1345
|
+
return this;
|
|
1346
|
+
};
|
|
1347
|
+
ListItBuffer.prototype.d = function(data) {
|
|
1348
|
+
if (arguments.length > 1) {
|
|
1349
|
+
const array = Array.apply(null, arguments);
|
|
1350
|
+
if (ListItBuffer.isMultiDimensionalArray(array)) {
|
|
1351
|
+
array.forEach((row) => this.addRow(row));
|
|
1352
|
+
} else {
|
|
1353
|
+
array.forEach((data2) => this.d(data2));
|
|
1354
|
+
}
|
|
1355
|
+
return this;
|
|
1356
|
+
}
|
|
1357
|
+
if (Array.isArray(data)) {
|
|
1358
|
+
if (ListItBuffer.isMultiDimensionalArray(data)) {
|
|
1359
|
+
data.forEach((row) => this.addRow(row));
|
|
1360
|
+
} else if (ListItBuffer.isObjectArray(data)) {
|
|
1361
|
+
data = objectArrayToTable(data);
|
|
1362
|
+
if (!this.header && (this.opt.headerBold || this.opt.headerColor || this.opt.headerUnderline)) {
|
|
1363
|
+
this.setHeaderRow(data.shift());
|
|
1364
|
+
}
|
|
1365
|
+
data.forEach((row) => this.addRow(row));
|
|
1366
|
+
} else {
|
|
1367
|
+
this.addRow(data);
|
|
1368
|
+
}
|
|
1369
|
+
return this;
|
|
1370
|
+
}
|
|
1371
|
+
const rowidx = this.lines.length - 1;
|
|
1372
|
+
if (rowidx < 0 || this.lines[rowidx].isFixed()) {
|
|
1373
|
+
this.pushNewRow();
|
|
1374
|
+
}
|
|
1375
|
+
const cell = new DataCell();
|
|
1376
|
+
cell.setData(data);
|
|
1377
|
+
const iRow = this.lines.length - 1;
|
|
1378
|
+
let iCol = this.lines[iRow].getCellLength();
|
|
1379
|
+
if (iCol >= this.columns.length) {
|
|
1380
|
+
this.addColumn();
|
|
1381
|
+
}
|
|
1382
|
+
this.columns[iCol].setCellAt(iRow, cell);
|
|
1383
|
+
this.lines[iRow].pushCell(cell);
|
|
1384
|
+
return this;
|
|
1385
|
+
};
|
|
1386
|
+
ListItBuffer.isMultiDimensionalArray = function(arr) {
|
|
1387
|
+
if (!Array.isArray(arr)) {
|
|
1388
|
+
throw Error("The parameter arr must be array");
|
|
1389
|
+
}
|
|
1390
|
+
for (let element of arr) {
|
|
1391
|
+
if (!Array.isArray(element)) {
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
return true;
|
|
1396
|
+
};
|
|
1397
|
+
ListItBuffer.isObjectArray = function(arr) {
|
|
1398
|
+
if (!Array.isArray(arr)) {
|
|
1399
|
+
throw Error("The parameter arr must be array");
|
|
1400
|
+
}
|
|
1401
|
+
const ctor = arr[0].constructor;
|
|
1402
|
+
for (let element of arr) {
|
|
1403
|
+
if (typeof element != "object") {
|
|
1404
|
+
return false;
|
|
1405
|
+
} else {
|
|
1406
|
+
if (element.constructor.name != ctor.name) {
|
|
1407
|
+
return false;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return true;
|
|
1412
|
+
};
|
|
1413
|
+
ListItBuffer.prototype.addRow = function(row) {
|
|
1414
|
+
row.forEach((col) => {
|
|
1415
|
+
switch (typeof col) {
|
|
1416
|
+
case "string":
|
|
1417
|
+
case "number":
|
|
1418
|
+
this.d(col);
|
|
1419
|
+
break;
|
|
1420
|
+
default:
|
|
1421
|
+
this.d(col != null ? col.toString() : "(null)");
|
|
1422
|
+
break;
|
|
1423
|
+
}
|
|
1424
|
+
});
|
|
1425
|
+
this.nl();
|
|
1426
|
+
};
|
|
1427
|
+
ListItBuffer.prototype.pushNewRow = function() {
|
|
1428
|
+
this.lines.push(new Row());
|
|
1429
|
+
};
|
|
1430
|
+
ListItBuffer.prototype.toString = function() {
|
|
1431
|
+
const rows = [];
|
|
1432
|
+
this.columns.forEach((column, iCol) => {
|
|
1433
|
+
if (this.header != null) {
|
|
1434
|
+
column.setHeader(this.header[iCol] || "");
|
|
1435
|
+
}
|
|
1436
|
+
column.setTextWidth(this.getColumnWidth(iCol));
|
|
1437
|
+
column.updateWidth();
|
|
1438
|
+
});
|
|
1439
|
+
if (this.header != null) {
|
|
1440
|
+
const headerLine = this.applyHeaderStyleOption(
|
|
1441
|
+
this.columns.map((column) => column.formatColumnHeader()).join(" ")
|
|
1442
|
+
);
|
|
1443
|
+
rows.push(headerLine);
|
|
1444
|
+
const headerUnderline = this.generateHeaderUnderline();
|
|
1445
|
+
if (headerUnderline) {
|
|
1446
|
+
rows.push(headerUnderline);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
this.lines.forEach((line) => {
|
|
1450
|
+
if (line.isFixed() || !line.isEmpty()) {
|
|
1451
|
+
if (line.isEmpty()) {
|
|
1452
|
+
rows.push("\n");
|
|
1453
|
+
} else {
|
|
1454
|
+
rows.push(this.columns.map((column, iCol) => {
|
|
1455
|
+
const cell = line.getCell(iCol);
|
|
1456
|
+
const data = cell.getData();
|
|
1457
|
+
return column.formatCell(data);
|
|
1458
|
+
}).join(" "));
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
return rows.join("\n");
|
|
1463
|
+
};
|
|
1464
|
+
var COLORS = {};
|
|
1465
|
+
var BGCOLORS = {};
|
|
1466
|
+
Object.keys(ansi.style).forEach((key) => {
|
|
1467
|
+
const value = ansi.style[key];
|
|
1468
|
+
if (/^bg-/.test(key)) {
|
|
1469
|
+
BGCOLORS[key.substr(3)] = value;
|
|
1470
|
+
} else {
|
|
1471
|
+
COLORS[key] = value;
|
|
1472
|
+
debug(`COLOR-KEY: ${key}`);
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1475
|
+
Object.keys(COLORS).forEach((key) => {
|
|
1476
|
+
if (!(key in BGCOLORS)) {
|
|
1477
|
+
delete COLORS[key];
|
|
1478
|
+
debug(`remove COLOR-KEY: ${key}`);
|
|
1479
|
+
}
|
|
1480
|
+
});
|
|
1481
|
+
var AVAILABLE_COLORS = Object.keys(COLORS);
|
|
1482
|
+
debug(`AVAILABLE_COLORS:${JSON.stringify(AVAILABLE_COLORS)}`);
|
|
1483
|
+
ListItBuffer.prototype.applyHeaderStyleOption = function(line) {
|
|
1484
|
+
if (!this.opt.headerBold && !this.opt.headerColor) {
|
|
1485
|
+
return line;
|
|
1486
|
+
}
|
|
1487
|
+
const textBuffer = [];
|
|
1488
|
+
if (this.opt.headerBold) {
|
|
1489
|
+
textBuffer.push(ansi.style.bold);
|
|
1490
|
+
}
|
|
1491
|
+
if (this.opt.headerColor) {
|
|
1492
|
+
textBuffer.push(COLORS[this.opt.headerColor]);
|
|
1493
|
+
}
|
|
1494
|
+
textBuffer.push(line);
|
|
1495
|
+
textBuffer.push(ansi.style.reset);
|
|
1496
|
+
return textBuffer.join("");
|
|
1497
|
+
};
|
|
1498
|
+
ListItBuffer.prototype.generateHeaderUnderline = function() {
|
|
1499
|
+
if (!this.opt.headerUnderline) {
|
|
1500
|
+
return null;
|
|
1501
|
+
}
|
|
1502
|
+
if (this.header == null) {
|
|
1503
|
+
return null;
|
|
1504
|
+
}
|
|
1505
|
+
return this.columns.map(
|
|
1506
|
+
(column) => "-".repeat(column.getWidth())
|
|
1507
|
+
).join(" ");
|
|
1508
|
+
};
|
|
1509
|
+
function objectArrayToTable(objects) {
|
|
1510
|
+
const keys = Object.keys(objects[0]);
|
|
1511
|
+
const body = objects.map((item) => keys.map((key) => {
|
|
1512
|
+
if (item[key] != null && typeof item[key] == "object" && item[key].constructor.name == "Date") {
|
|
1513
|
+
return item[key].toISOString();
|
|
1514
|
+
}
|
|
1515
|
+
return item[key];
|
|
1516
|
+
}));
|
|
1517
|
+
return [keys, ...body];
|
|
1518
|
+
}
|
|
1519
|
+
ListItBuffer.prototype.setColumnWidth = function(indexOfColumns, width) {
|
|
1520
|
+
this.columnWidth = this.columnWidth || [];
|
|
1521
|
+
if (typeof indexOfColumns !== "number") {
|
|
1522
|
+
throw new Error("indexOfColumns must be a number");
|
|
1523
|
+
}
|
|
1524
|
+
if (!width) {
|
|
1525
|
+
delete this.columnWidth[indexOfColumns];
|
|
1526
|
+
} else {
|
|
1527
|
+
if (typeof width !== "number") {
|
|
1528
|
+
throw new Error("width must be a number");
|
|
1529
|
+
}
|
|
1530
|
+
this.columnWidth[indexOfColumns] = width;
|
|
1531
|
+
}
|
|
1532
|
+
return this;
|
|
1533
|
+
};
|
|
1534
|
+
ListItBuffer.prototype.setColumnWidthAll = function(widthForAll) {
|
|
1535
|
+
if (widthForAll != null && !Array.isArray(widthForAll) && typeof widthForAll !== "number") {
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
"widthForAll must be one of a null, an Array or a number"
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
if (Array.isArray(widthForAll)) {
|
|
1541
|
+
for (let i = 0; i < widthForAll.length; i++) {
|
|
1542
|
+
const width = widthForAll[i];
|
|
1543
|
+
if (width != void 0 && typeof width !== "number") {
|
|
1544
|
+
throw new Error(
|
|
1545
|
+
`widthForAll[${i}] must be an undefined or a number`
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
this.columnWidth = widthForAll;
|
|
1551
|
+
return this;
|
|
1552
|
+
};
|
|
1553
|
+
ListItBuffer.prototype.getColumnWidth = function(indexOfColumns) {
|
|
1554
|
+
if (Array.isArray(this.columnWidth)) {
|
|
1555
|
+
return this.columnWidth[indexOfColumns];
|
|
1556
|
+
}
|
|
1557
|
+
return this.columnWidth;
|
|
1558
|
+
};
|
|
1559
|
+
ListItBuffer.prototype.setHeaderRow = function(header) {
|
|
1560
|
+
if (header && !Array.isArray(header)) {
|
|
1561
|
+
throw new Error([
|
|
1562
|
+
"The header must be an array,",
|
|
1563
|
+
`but ${typeof header} was specified.`,
|
|
1564
|
+
`header: ${JSON.stringify(header)}`
|
|
1565
|
+
].join(" "));
|
|
1566
|
+
}
|
|
1567
|
+
this.header = header;
|
|
1568
|
+
if (this.header == null) {
|
|
1569
|
+
this.columns.forEach((column) => column.setHeader(null));
|
|
1570
|
+
} else {
|
|
1571
|
+
this.header.forEach((headerText, iCol) => {
|
|
1572
|
+
if (iCol >= this.columns.length) {
|
|
1573
|
+
this.addColumn(headerText);
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
return this;
|
|
1578
|
+
};
|
|
1579
|
+
ListItBuffer.prototype.addColumn = function(headerText) {
|
|
1580
|
+
const column = new Column();
|
|
1581
|
+
if (headerText) {
|
|
1582
|
+
column.setHeader(headerText);
|
|
1583
|
+
}
|
|
1584
|
+
if (this.opt.autoAlign) {
|
|
1585
|
+
column.setAutoAlign(true);
|
|
1586
|
+
}
|
|
1587
|
+
this.columns.push(column);
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
// ../../node_modules/list-it/index.js
|
|
1593
|
+
var require_list_it = __commonJS({
|
|
1594
|
+
"../../node_modules/list-it/index.js"(exports2, module2) {
|
|
1595
|
+
"use strict";
|
|
1596
|
+
var ListItBuffer = require_list_it_buffer();
|
|
1597
|
+
function ListIt2(opt) {
|
|
1598
|
+
ListItBuffer.call(this, opt);
|
|
1599
|
+
}
|
|
1600
|
+
ListIt2.prototype = new ListItBuffer();
|
|
1601
|
+
ListIt2.buffer = function(opt) {
|
|
1602
|
+
opt = opt || {};
|
|
1603
|
+
if (!("autoAlign" in opt)) {
|
|
1604
|
+
opt.autoAlign = false;
|
|
1605
|
+
}
|
|
1606
|
+
return new ListIt2(opt);
|
|
1607
|
+
};
|
|
1608
|
+
module2.exports = ListIt2;
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
|
|
1612
|
+
// src/scripts/backtest.ts
|
|
1613
|
+
var import_args = __toESM(require("args"));
|
|
1614
|
+
var import_progress = __toESM(require("progress"));
|
|
1615
|
+
var import_child_process = require("child_process");
|
|
1616
|
+
var import_fs = __toESM(require("fs"));
|
|
1617
|
+
var import_path = __toESM(require("path"));
|
|
1618
|
+
var import_os = __toESM(require("os"));
|
|
1619
|
+
var import_chalk = __toESM(require("chalk"));
|
|
1620
|
+
var import_lodash = __toESM(require("lodash"));
|
|
1621
|
+
var import_date_fns = require("date-fns");
|
|
1622
|
+
var import_uuid = require("uuid");
|
|
1623
|
+
var import_connectors = require("@tradejs/connectors");
|
|
1624
|
+
var import_connectors2 = require("@tradejs/node/connectors");
|
|
1625
|
+
var import_cli = require("@tradejs/node/cli");
|
|
1626
|
+
var import_backtest = require("@tradejs/core/backtest");
|
|
1627
|
+
var import_json = require("@tradejs/core/json");
|
|
1628
|
+
var import_constants = require("@tradejs/core/constants");
|
|
1629
|
+
var import_redis = require("@tradejs/infra/redis");
|
|
1630
|
+
var ListIt = require_list_it();
|
|
1631
|
+
var MAX_PARALLEL = Math.min(import_os.default.cpus().length, 6);
|
|
1632
|
+
import_args.default.example(
|
|
1633
|
+
" yarn backtest -t 400 --cacheOnly",
|
|
1634
|
+
"Run tests on uploaded data for 400 tickers"
|
|
1635
|
+
);
|
|
1636
|
+
import_args.default.option(["t", "tickers"], "Selected tickers");
|
|
1637
|
+
import_args.default.option(["e", "exclude"], "Exclude tickers from tests");
|
|
1638
|
+
import_args.default.option(["l", "tickersLimit"], "Tickers limit");
|
|
1639
|
+
import_args.default.option(["n", "tests"], "Tests limit", import_constants.TESTS_LIMIT);
|
|
1640
|
+
import_args.default.option(["p", "parallel"], "Parallel tasks", MAX_PARALLEL);
|
|
1641
|
+
import_args.default.option(["f", "timeframe"], "Timeframe", 15);
|
|
1642
|
+
import_args.default.option(["T", "top"], "Return N best tests", import_constants.TESTS_TOP_LIMIT);
|
|
1643
|
+
import_args.default.option(["u", "updateOnly"], "Only update tickers history", false);
|
|
1644
|
+
import_args.default.option(["C", "cacheOnly"], "Do not update tickers history", false);
|
|
1645
|
+
import_args.default.option(["c", "config"], "Backtest config", "breakout");
|
|
1646
|
+
import_args.default.option(["L", "showTickersList"], "Just show only ticker list", false);
|
|
1647
|
+
import_args.default.option(["S", "progressStep"], "Progress step", 100);
|
|
1648
|
+
import_args.default.option(["U", "user"], "Use user config", "root");
|
|
1649
|
+
import_args.default.option(
|
|
1650
|
+
"connector",
|
|
1651
|
+
"Connector provider or name for backtest (e.g. bybit, binance, coinbase, custom)",
|
|
1652
|
+
"bybit"
|
|
1653
|
+
);
|
|
1654
|
+
import_args.default.option(
|
|
1655
|
+
["m", "ml"],
|
|
1656
|
+
"Write ML dataset rows to per-worker JSONL chunks",
|
|
1657
|
+
false
|
|
1658
|
+
);
|
|
1659
|
+
var flags = import_args.default.parse(process.argv);
|
|
1660
|
+
var interval = flags.timeframe.toString();
|
|
1661
|
+
var progressStep = flags.progressStep;
|
|
1662
|
+
var uuid = (len = 12) => (0, import_uuid.v4)().slice(-len);
|
|
1663
|
+
var testerWorkerPathCandidates = [
|
|
1664
|
+
import_path.default.resolve(__dirname, "../workers/testerWorker.js"),
|
|
1665
|
+
import_path.default.resolve(__dirname, "../workers/testerWorker.ts")
|
|
1666
|
+
];
|
|
1667
|
+
var testerWorkerPath = testerWorkerPathCandidates.find(
|
|
1668
|
+
(candidate) => import_fs.default.existsSync(candidate)
|
|
1669
|
+
);
|
|
1670
|
+
if (!testerWorkerPath) {
|
|
1671
|
+
throw new Error(
|
|
1672
|
+
`Tester worker file not found. Checked: ${testerWorkerPathCandidates.join(", ")}`
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
var testerNeedsTsRuntime = testerWorkerPath.endsWith(".ts");
|
|
1676
|
+
var HEADERS_RESULTS = [
|
|
1677
|
+
import_chalk.default.blue("ID"),
|
|
1678
|
+
import_chalk.default.yellow("SYMBOL"),
|
|
1679
|
+
import_chalk.default.cyan("PROFIT"),
|
|
1680
|
+
import_chalk.default.cyan("ORDERS"),
|
|
1681
|
+
import_chalk.default.cyan("WIN/LOSS (%)"),
|
|
1682
|
+
import_chalk.default.cyan("RISK"),
|
|
1683
|
+
import_chalk.default.cyan("MAX DRAWDOWN (%)")
|
|
1684
|
+
];
|
|
1685
|
+
var HEADERS_RESULTS_BY_TICKERS = [
|
|
1686
|
+
import_chalk.default.blue("ID"),
|
|
1687
|
+
import_chalk.default.yellow("SYMBOL"),
|
|
1688
|
+
import_chalk.default.cyan("PROFIT"),
|
|
1689
|
+
import_chalk.default.cyan("ORDERS"),
|
|
1690
|
+
import_chalk.default.cyan("WIN/LOSS (%)"),
|
|
1691
|
+
import_chalk.default.cyan("RISK"),
|
|
1692
|
+
import_chalk.default.cyan("MAX DRAWDOWN (%)")
|
|
1693
|
+
];
|
|
1694
|
+
var successTests = 0;
|
|
1695
|
+
var errorTests = 0;
|
|
1696
|
+
var errorMessages = [];
|
|
1697
|
+
var results = [];
|
|
1698
|
+
var resultsByTickers = /* @__PURE__ */ new Map();
|
|
1699
|
+
var userName = flags.user;
|
|
1700
|
+
var runStartedAt = Date.now();
|
|
1701
|
+
var createListIt = () => new ListIt({
|
|
1702
|
+
autoAlign: true,
|
|
1703
|
+
headerUnderline: true
|
|
1704
|
+
});
|
|
1705
|
+
var createTable = (headers, rows) => createListIt().setHeaderRow(headers).d(rows).toString();
|
|
1706
|
+
var createTimestamp = (date) => (0, import_date_fns.format)(date, "yyyyMMddHHmm");
|
|
1707
|
+
var filterGoodTests = (tests) => tests.filter((res) => res.stat?.orders > 5 && res.stat?.profit > 10);
|
|
1708
|
+
var recordError = (error) => {
|
|
1709
|
+
errorMessages.push(error);
|
|
1710
|
+
};
|
|
1711
|
+
var isStrategyConfigGrid = (value) => {
|
|
1712
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1713
|
+
return false;
|
|
1714
|
+
}
|
|
1715
|
+
return Object.values(value).every(
|
|
1716
|
+
(item) => Array.isArray(item)
|
|
1717
|
+
);
|
|
1718
|
+
};
|
|
1719
|
+
var resolveBacktestConnectorName = async (value) => {
|
|
1720
|
+
const connectorName = await (0, import_connectors2.resolveConnectorName)(value);
|
|
1721
|
+
if (connectorName) {
|
|
1722
|
+
return connectorName;
|
|
1723
|
+
}
|
|
1724
|
+
console.log(
|
|
1725
|
+
import_chalk.default.yellow(
|
|
1726
|
+
`Unknown connector "${String(value || "").trim() || String(value)}". Fallback to ${import_connectors2.DEFAULT_CONNECTOR_NAME}.`
|
|
1727
|
+
)
|
|
1728
|
+
);
|
|
1729
|
+
return import_connectors2.DEFAULT_CONNECTOR_NAME;
|
|
1730
|
+
};
|
|
1731
|
+
var getLogsById = async (orderLogId) => {
|
|
1732
|
+
const orderLog = await (0, import_redis.getData)(
|
|
1733
|
+
import_redis.redisKeys.cacheOrders(userName, orderLogId)
|
|
1734
|
+
);
|
|
1735
|
+
const positionLog = await (0, import_redis.getData)(
|
|
1736
|
+
import_redis.redisKeys.cachePositions(userName, orderLogId)
|
|
1737
|
+
);
|
|
1738
|
+
return { orderLog, positionLog };
|
|
1739
|
+
};
|
|
1740
|
+
var setTestData = async (test, stat, orderLog) => {
|
|
1741
|
+
await (0, import_redis.setData)(
|
|
1742
|
+
import_redis.redisKeys.testOrders(test.userName, test.strategyName, test.name),
|
|
1743
|
+
orderLog,
|
|
1744
|
+
{
|
|
1745
|
+
expire: import_constants.TTL_1M
|
|
1746
|
+
}
|
|
1747
|
+
);
|
|
1748
|
+
await (0, import_redis.setData)(
|
|
1749
|
+
import_redis.redisKeys.testConfig(test.userName, test.strategyName, test.name),
|
|
1750
|
+
test,
|
|
1751
|
+
{
|
|
1752
|
+
expire: import_constants.TTL_1M
|
|
1753
|
+
}
|
|
1754
|
+
);
|
|
1755
|
+
await (0, import_redis.setData)(
|
|
1756
|
+
import_redis.redisKeys.testStat(test.userName, test.strategyName, test.name),
|
|
1757
|
+
stat,
|
|
1758
|
+
{
|
|
1759
|
+
expire: import_constants.TTL_1M
|
|
1760
|
+
}
|
|
1761
|
+
);
|
|
1762
|
+
};
|
|
1763
|
+
var backtest = async () => {
|
|
1764
|
+
if (!flags.config) {
|
|
1765
|
+
throw new Error("Backtest config not send");
|
|
1766
|
+
}
|
|
1767
|
+
const strategyName = flags.config.split(":")[0];
|
|
1768
|
+
if (!flags.config) {
|
|
1769
|
+
throw new Error("Strategy name not found");
|
|
1770
|
+
}
|
|
1771
|
+
const backtestConfig = await (0, import_redis.getData)(
|
|
1772
|
+
import_redis.redisKeys.backtestConfig(userName, flags.config),
|
|
1773
|
+
null
|
|
1774
|
+
);
|
|
1775
|
+
if (!backtestConfig) {
|
|
1776
|
+
throw new Error(`Backtest config "${flags.config}" not found`);
|
|
1777
|
+
}
|
|
1778
|
+
const typedBacktestConfig = backtestConfig;
|
|
1779
|
+
if (!isStrategyConfigGrid(typedBacktestConfig)) {
|
|
1780
|
+
throw new Error(
|
|
1781
|
+
`Backtest config "${flags.config}" must include strategyName and strategyConfig grid`
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
const connectorName = await resolveBacktestConnectorName(flags.connector);
|
|
1785
|
+
const connectorFactory = await (0, import_connectors2.getConnectorCreatorByName)(connectorName);
|
|
1786
|
+
if (!connectorFactory) {
|
|
1787
|
+
throw new Error(`Connector "${connectorName}" is not registered`);
|
|
1788
|
+
}
|
|
1789
|
+
const marketConnector = await connectorFactory({
|
|
1790
|
+
userName: flags.user
|
|
1791
|
+
});
|
|
1792
|
+
const tickers = await (0, import_cli.getTickers)(
|
|
1793
|
+
marketConnector,
|
|
1794
|
+
flags.tickers,
|
|
1795
|
+
flags.exclude,
|
|
1796
|
+
flags.tickersLimit
|
|
1797
|
+
);
|
|
1798
|
+
if (flags.showTickersList) {
|
|
1799
|
+
console.log(import_chalk.default.gray(JSON.stringify(tickers.sort(), null, 2)));
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1802
|
+
if (!flags.cacheOnly) {
|
|
1803
|
+
await (0, import_cli.update)(marketConnector, interval, tickers);
|
|
1804
|
+
const binanceConnectorCreator = await (0, import_connectors2.getConnectorCreatorByName)(
|
|
1805
|
+
import_connectors.ConnectorNames.Binance
|
|
1806
|
+
);
|
|
1807
|
+
const coinbaseConnectorCreator = await (0, import_connectors2.getConnectorCreatorByName)(
|
|
1808
|
+
import_connectors.ConnectorNames.Coinbase
|
|
1809
|
+
);
|
|
1810
|
+
if (!binanceConnectorCreator || !coinbaseConnectorCreator) {
|
|
1811
|
+
throw new Error("Binance/Coinbase connectors are required");
|
|
1812
|
+
}
|
|
1813
|
+
const binanceConnector = await binanceConnectorCreator({
|
|
1814
|
+
userName: flags.user
|
|
1815
|
+
});
|
|
1816
|
+
const coinbaseConnector = await coinbaseConnectorCreator({
|
|
1817
|
+
userName: flags.user
|
|
1818
|
+
});
|
|
1819
|
+
await (0, import_cli.update)(binanceConnector, interval, ["BTCUSDT"]);
|
|
1820
|
+
await (0, import_cli.update)(coinbaseConnector, interval, ["BTCUSDT"]);
|
|
1821
|
+
}
|
|
1822
|
+
if (flags.updateOnly) {
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
let testSuite = (0, import_backtest.createTestSuite)(
|
|
1826
|
+
userName,
|
|
1827
|
+
tickers,
|
|
1828
|
+
strategyName,
|
|
1829
|
+
typedBacktestConfig,
|
|
1830
|
+
connectorName
|
|
1831
|
+
).slice(0, parseInt(flags.tests));
|
|
1832
|
+
const mlEnabled = Boolean(flags.ml);
|
|
1833
|
+
testSuite = testSuite.map((test) => ({ ...test, ml: mlEnabled }));
|
|
1834
|
+
const chunkSize = Math.ceil(testSuite.length / parseInt(flags.parallel));
|
|
1835
|
+
const chunks = import_lodash.default.chunk(testSuite, chunkSize);
|
|
1836
|
+
let completedWorkers = 0;
|
|
1837
|
+
let completedTests = 0;
|
|
1838
|
+
let isFinishing = false;
|
|
1839
|
+
const workers = /* @__PURE__ */ new Set();
|
|
1840
|
+
const stopWorkers = () => {
|
|
1841
|
+
for (const worker of workers) {
|
|
1842
|
+
if (!worker.killed) {
|
|
1843
|
+
worker.kill("SIGTERM");
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
process.once("SIGINT", () => {
|
|
1848
|
+
stopWorkers();
|
|
1849
|
+
process.exit(130);
|
|
1850
|
+
});
|
|
1851
|
+
process.once("SIGTERM", () => {
|
|
1852
|
+
stopWorkers();
|
|
1853
|
+
process.exit(143);
|
|
1854
|
+
});
|
|
1855
|
+
console.log(import_chalk.default.yellow(`tests: ${testSuite.length}`));
|
|
1856
|
+
console.log("");
|
|
1857
|
+
const bar = new import_progress.default(
|
|
1858
|
+
":current/:total [:bar][:percent] :symbol :amount :eta(s)",
|
|
1859
|
+
{
|
|
1860
|
+
total: testSuite.length,
|
|
1861
|
+
width: 20
|
|
1862
|
+
}
|
|
1863
|
+
);
|
|
1864
|
+
for (const chunk of chunks) {
|
|
1865
|
+
const chunkId = uuid();
|
|
1866
|
+
const chunkWithId = chunk.map((test) => ({ ...test, chunkId }));
|
|
1867
|
+
const tester = (0, import_child_process.fork)(testerWorkerPath, [], {
|
|
1868
|
+
execArgv: testerNeedsTsRuntime ? [
|
|
1869
|
+
"--max-old-space-size=8192",
|
|
1870
|
+
"-r",
|
|
1871
|
+
"ts-node/register",
|
|
1872
|
+
"-r",
|
|
1873
|
+
"tsconfig-paths/register"
|
|
1874
|
+
] : ["--max-old-space-size=8192"]
|
|
1875
|
+
});
|
|
1876
|
+
workers.add(tester);
|
|
1877
|
+
tester.on("message", async (msg) => {
|
|
1878
|
+
if (msg.done) {
|
|
1879
|
+
completedWorkers++;
|
|
1880
|
+
workers.delete(tester);
|
|
1881
|
+
if (completedWorkers === chunks.length && !isFinishing) {
|
|
1882
|
+
isFinishing = true;
|
|
1883
|
+
results = (0, import_backtest.sortBestTests)(results, flags.top);
|
|
1884
|
+
await finish();
|
|
1885
|
+
}
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
completedTests++;
|
|
1889
|
+
if (msg.error) {
|
|
1890
|
+
errorTests++;
|
|
1891
|
+
recordError({
|
|
1892
|
+
id: msg.id,
|
|
1893
|
+
error: msg.error,
|
|
1894
|
+
payload: msg
|
|
1895
|
+
});
|
|
1896
|
+
console.error(
|
|
1897
|
+
import_chalk.default.red(`Error in test #${msg.id}: ${JSON.stringify(msg)}`)
|
|
1898
|
+
);
|
|
1899
|
+
return;
|
|
1900
|
+
} else {
|
|
1901
|
+
successTests++;
|
|
1902
|
+
}
|
|
1903
|
+
results.push(msg);
|
|
1904
|
+
const goodResults = filterGoodTests(results);
|
|
1905
|
+
goodResults.forEach((res) => {
|
|
1906
|
+
const prevValue = resultsByTickers.get(res.test.symbol);
|
|
1907
|
+
if (!prevValue || prevValue.stat.profit < res.stat.profit) {
|
|
1908
|
+
resultsByTickers.set(res.test.symbol, res);
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
if (completedTests % progressStep === 0 || completedTests === testSuite.length) {
|
|
1912
|
+
results = (0, import_backtest.sortBestTests)(results, flags.top);
|
|
1913
|
+
const {
|
|
1914
|
+
test: { symbol, name },
|
|
1915
|
+
stat: { profit }
|
|
1916
|
+
} = results[0];
|
|
1917
|
+
const profitStr = `${(profit || 0).toFixed(2)}$`;
|
|
1918
|
+
bar.tick(
|
|
1919
|
+
completedTests === testSuite.length ? completedTests % progressStep : progressStep,
|
|
1920
|
+
{
|
|
1921
|
+
symbol: import_chalk.default.yellow(symbol),
|
|
1922
|
+
amount: profit > 0 ? import_chalk.default.green(profitStr) : import_chalk.default.red(profitStr)
|
|
1923
|
+
}
|
|
1924
|
+
);
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
tester.on("error", (err) => {
|
|
1928
|
+
recordError({ error: err?.message ?? err });
|
|
1929
|
+
console.error(import_chalk.default.red(`Worker error: ${err.message}`));
|
|
1930
|
+
});
|
|
1931
|
+
tester.on("exit", (code) => {
|
|
1932
|
+
workers.delete(tester);
|
|
1933
|
+
if (code !== 0) {
|
|
1934
|
+
recordError({ error: `Worker exited with code ${code}` });
|
|
1935
|
+
console.error(import_chalk.default.red(`Worker exited with code ${code}`));
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
await (0, import_redis.setData)(import_redis.redisKeys.cacheChunk(userName, chunkId), chunkWithId, {
|
|
1939
|
+
expire: import_constants.TTL_1D
|
|
1940
|
+
});
|
|
1941
|
+
tester.send({ chunkId, userName });
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
var saveAndPrintResults = async () => {
|
|
1945
|
+
const colorizedResults = [];
|
|
1946
|
+
for await (const result of results) {
|
|
1947
|
+
const { test, orderLogId } = result;
|
|
1948
|
+
const { symbol, name } = test;
|
|
1949
|
+
const { orderLog, positionLog } = await getLogsById(orderLogId);
|
|
1950
|
+
const stat = (0, import_backtest.calculateStatsFull)(positionLog);
|
|
1951
|
+
await setTestData(test, stat, orderLog);
|
|
1952
|
+
const statRow = [
|
|
1953
|
+
import_chalk.default.blue(name),
|
|
1954
|
+
import_chalk.default.yellow(symbol),
|
|
1955
|
+
...(0, import_cli.drawStatInCLI)(stat, [
|
|
1956
|
+
"netProfit",
|
|
1957
|
+
"orders",
|
|
1958
|
+
"winRate",
|
|
1959
|
+
"riskRewardRatio",
|
|
1960
|
+
"maxDrawdown"
|
|
1961
|
+
])
|
|
1962
|
+
];
|
|
1963
|
+
colorizedResults.push(statRow);
|
|
1964
|
+
}
|
|
1965
|
+
console.log("");
|
|
1966
|
+
console.log("RESULTS:");
|
|
1967
|
+
console.log(createTable(HEADERS_RESULTS, colorizedResults));
|
|
1968
|
+
console.log("");
|
|
1969
|
+
};
|
|
1970
|
+
var saveAndPrintResultsByTickers = async () => {
|
|
1971
|
+
const colorizedResultsByTickers = [];
|
|
1972
|
+
for await (const result of resultsByTickers.values()) {
|
|
1973
|
+
const { test, orderLogId } = result;
|
|
1974
|
+
const { symbol, name } = test;
|
|
1975
|
+
const { orderLog, positionLog } = await getLogsById(orderLogId);
|
|
1976
|
+
const stat = (0, import_backtest.calculateStatsFull)(positionLog);
|
|
1977
|
+
await setTestData(test, stat, orderLog);
|
|
1978
|
+
const statRow = [
|
|
1979
|
+
import_chalk.default.blue(name),
|
|
1980
|
+
import_chalk.default.yellow(symbol),
|
|
1981
|
+
...(0, import_cli.drawStatInCLI)(stat, [
|
|
1982
|
+
"netProfit",
|
|
1983
|
+
"orders",
|
|
1984
|
+
"winRate",
|
|
1985
|
+
"riskRewardRatio",
|
|
1986
|
+
"maxDrawdown"
|
|
1987
|
+
])
|
|
1988
|
+
];
|
|
1989
|
+
colorizedResultsByTickers.push(statRow);
|
|
1990
|
+
}
|
|
1991
|
+
console.log("");
|
|
1992
|
+
console.log("RESULTS BY TICKERS:");
|
|
1993
|
+
console.log(
|
|
1994
|
+
createTable(HEADERS_RESULTS_BY_TICKERS, colorizedResultsByTickers)
|
|
1995
|
+
);
|
|
1996
|
+
console.log("");
|
|
1997
|
+
};
|
|
1998
|
+
var finish = async () => {
|
|
1999
|
+
if (flags.tickers) {
|
|
2000
|
+
await saveAndPrintResults();
|
|
2001
|
+
} else {
|
|
2002
|
+
await saveAndPrintResultsByTickers();
|
|
2003
|
+
}
|
|
2004
|
+
const bestConfig = results[0]?.test.strategyConfig;
|
|
2005
|
+
console.log(import_chalk.default.gray("BEST CONFIG:"));
|
|
2006
|
+
console.log(import_chalk.default.green((0, import_json.toJson)(bestConfig, true)));
|
|
2007
|
+
console.log("");
|
|
2008
|
+
const mergedConfig = (0, import_backtest.mergeConfigs)(
|
|
2009
|
+
results.map(({ test: { strategyConfig } }) => strategyConfig)
|
|
2010
|
+
);
|
|
2011
|
+
console.log(import_chalk.default.gray("MERGED CONFIG:"));
|
|
2012
|
+
console.log(import_chalk.default.blue((0, import_json.toJson)(mergedConfig, true)));
|
|
2013
|
+
console.log("");
|
|
2014
|
+
console.log(`${import_chalk.default.green("SUCCESS TESTS")}: ${successTests}`);
|
|
2015
|
+
console.log(`${import_chalk.default.red("ERRORS")}: ${errorTests}`);
|
|
2016
|
+
console.log("");
|
|
2017
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
2018
|
+
const durationSeconds = Number(
|
|
2019
|
+
((Date.now() - runStartedAt) / 1e3).toFixed(2)
|
|
2020
|
+
);
|
|
2021
|
+
const timestamp = createTimestamp(finishedAt);
|
|
2022
|
+
await (0, import_redis.setData)(
|
|
2023
|
+
import_redis.redisKeys.backtestResults(userName, flags.config, timestamp),
|
|
2024
|
+
{
|
|
2025
|
+
config: flags.config,
|
|
2026
|
+
user: userName,
|
|
2027
|
+
startedAt: new Date(runStartedAt).toISOString(),
|
|
2028
|
+
finishedAt: finishedAt.toISOString(),
|
|
2029
|
+
durationSeconds,
|
|
2030
|
+
results,
|
|
2031
|
+
resultsByTickers: resultsByTickers.values(),
|
|
2032
|
+
bestConfig,
|
|
2033
|
+
mergedConfig,
|
|
2034
|
+
successTests,
|
|
2035
|
+
errors: errorMessages,
|
|
2036
|
+
errorTests
|
|
2037
|
+
},
|
|
2038
|
+
{
|
|
2039
|
+
expire: 0
|
|
2040
|
+
}
|
|
2041
|
+
);
|
|
2042
|
+
process.exit();
|
|
2043
|
+
};
|
|
2044
|
+
backtest();
|