@solana/web3.js 1.70.1 → 1.70.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.cjs.js +3 -4
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +3 -4
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +2448 -69
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.esm.js +2441 -67
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3 -4
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +1 -1
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +3 -4
- package/lib/index.native.js.map +1 -1
- package/package.json +2 -1
- package/src/connection.ts +23 -17
- package/src/publickey.ts +2 -2
- package/src/agent-manager.ts +0 -44
package/lib/index.cjs.js
CHANGED
|
@@ -11,11 +11,16 @@ var sha256 = require('@noble/hashes/sha256');
|
|
|
11
11
|
var borsh = require('borsh');
|
|
12
12
|
var BufferLayout = require('@solana/buffer-layout');
|
|
13
13
|
var bigintBuffer = require('bigint-buffer');
|
|
14
|
-
var
|
|
14
|
+
var require$$0$1 = require('os');
|
|
15
|
+
var require$$0$2 = require('tty');
|
|
16
|
+
var require$$0 = require('util');
|
|
17
|
+
var require$$0$3 = require('events');
|
|
18
|
+
var require$$1 = require('path');
|
|
19
|
+
var require$$0$4 = require('http');
|
|
20
|
+
var require$$0$5 = require('https');
|
|
15
21
|
var superstruct = require('superstruct');
|
|
16
22
|
var rpcWebsockets = require('rpc-websockets');
|
|
17
23
|
var RpcClient = require('jayson/lib/client/browser');
|
|
18
|
-
var http = require('http');
|
|
19
24
|
var nodeFetch = require('node-fetch');
|
|
20
25
|
var sha3 = require('@noble/hashes/sha3');
|
|
21
26
|
var hmac = require('@noble/hashes/hmac');
|
|
@@ -45,9 +50,14 @@ var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
|
|
|
45
50
|
var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
|
|
46
51
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
47
52
|
var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
|
|
48
|
-
var
|
|
53
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
54
|
+
var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
|
|
55
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
56
|
+
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
|
|
57
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
58
|
+
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
|
|
59
|
+
var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
|
|
49
60
|
var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
50
|
-
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
51
61
|
var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
|
|
52
62
|
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
53
63
|
|
|
@@ -225,7 +235,7 @@ class PublicKey extends Struct {
|
|
|
225
235
|
return this.toBase58();
|
|
226
236
|
}
|
|
227
237
|
/**
|
|
228
|
-
* Return the byte array representation of the public key
|
|
238
|
+
* Return the byte array representation of the public key in big endian
|
|
229
239
|
*/
|
|
230
240
|
|
|
231
241
|
|
|
@@ -233,7 +243,7 @@ class PublicKey extends Struct {
|
|
|
233
243
|
return this.toBuffer();
|
|
234
244
|
}
|
|
235
245
|
/**
|
|
236
|
-
* Return the Buffer representation of the public key
|
|
246
|
+
* Return the Buffer representation of the public key in big endian
|
|
237
247
|
*/
|
|
238
248
|
|
|
239
249
|
|
|
@@ -3332,6 +3342,2421 @@ class BpfLoader {
|
|
|
3332
3342
|
|
|
3333
3343
|
}
|
|
3334
3344
|
|
|
3345
|
+
function getDefaultExportFromCjs (x) {
|
|
3346
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
var agentkeepalive = {exports: {}};
|
|
3350
|
+
|
|
3351
|
+
/**
|
|
3352
|
+
* Helpers.
|
|
3353
|
+
*/
|
|
3354
|
+
|
|
3355
|
+
var s = 1000;
|
|
3356
|
+
var m = s * 60;
|
|
3357
|
+
var h = m * 60;
|
|
3358
|
+
var d = h * 24;
|
|
3359
|
+
var w = d * 7;
|
|
3360
|
+
var y = d * 365.25;
|
|
3361
|
+
|
|
3362
|
+
/**
|
|
3363
|
+
* Parse or format the given `val`.
|
|
3364
|
+
*
|
|
3365
|
+
* Options:
|
|
3366
|
+
*
|
|
3367
|
+
* - `long` verbose formatting [false]
|
|
3368
|
+
*
|
|
3369
|
+
* @param {String|Number} val
|
|
3370
|
+
* @param {Object} [options]
|
|
3371
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
3372
|
+
* @return {String|Number}
|
|
3373
|
+
* @api public
|
|
3374
|
+
*/
|
|
3375
|
+
|
|
3376
|
+
var ms$2 = function(val, options) {
|
|
3377
|
+
options = options || {};
|
|
3378
|
+
var type = typeof val;
|
|
3379
|
+
if (type === 'string' && val.length > 0) {
|
|
3380
|
+
return parse(val);
|
|
3381
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
3382
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
3383
|
+
}
|
|
3384
|
+
throw new Error(
|
|
3385
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
3386
|
+
JSON.stringify(val)
|
|
3387
|
+
);
|
|
3388
|
+
};
|
|
3389
|
+
|
|
3390
|
+
/**
|
|
3391
|
+
* Parse the given `str` and return milliseconds.
|
|
3392
|
+
*
|
|
3393
|
+
* @param {String} str
|
|
3394
|
+
* @return {Number}
|
|
3395
|
+
* @api private
|
|
3396
|
+
*/
|
|
3397
|
+
|
|
3398
|
+
function parse(str) {
|
|
3399
|
+
str = String(str);
|
|
3400
|
+
if (str.length > 100) {
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3403
|
+
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(
|
|
3404
|
+
str
|
|
3405
|
+
);
|
|
3406
|
+
if (!match) {
|
|
3407
|
+
return;
|
|
3408
|
+
}
|
|
3409
|
+
var n = parseFloat(match[1]);
|
|
3410
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
3411
|
+
switch (type) {
|
|
3412
|
+
case 'years':
|
|
3413
|
+
case 'year':
|
|
3414
|
+
case 'yrs':
|
|
3415
|
+
case 'yr':
|
|
3416
|
+
case 'y':
|
|
3417
|
+
return n * y;
|
|
3418
|
+
case 'weeks':
|
|
3419
|
+
case 'week':
|
|
3420
|
+
case 'w':
|
|
3421
|
+
return n * w;
|
|
3422
|
+
case 'days':
|
|
3423
|
+
case 'day':
|
|
3424
|
+
case 'd':
|
|
3425
|
+
return n * d;
|
|
3426
|
+
case 'hours':
|
|
3427
|
+
case 'hour':
|
|
3428
|
+
case 'hrs':
|
|
3429
|
+
case 'hr':
|
|
3430
|
+
case 'h':
|
|
3431
|
+
return n * h;
|
|
3432
|
+
case 'minutes':
|
|
3433
|
+
case 'minute':
|
|
3434
|
+
case 'mins':
|
|
3435
|
+
case 'min':
|
|
3436
|
+
case 'm':
|
|
3437
|
+
return n * m;
|
|
3438
|
+
case 'seconds':
|
|
3439
|
+
case 'second':
|
|
3440
|
+
case 'secs':
|
|
3441
|
+
case 'sec':
|
|
3442
|
+
case 's':
|
|
3443
|
+
return n * s;
|
|
3444
|
+
case 'milliseconds':
|
|
3445
|
+
case 'millisecond':
|
|
3446
|
+
case 'msecs':
|
|
3447
|
+
case 'msec':
|
|
3448
|
+
case 'ms':
|
|
3449
|
+
return n;
|
|
3450
|
+
default:
|
|
3451
|
+
return undefined;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
/**
|
|
3456
|
+
* Short format for `ms`.
|
|
3457
|
+
*
|
|
3458
|
+
* @param {Number} ms
|
|
3459
|
+
* @return {String}
|
|
3460
|
+
* @api private
|
|
3461
|
+
*/
|
|
3462
|
+
|
|
3463
|
+
function fmtShort(ms) {
|
|
3464
|
+
var msAbs = Math.abs(ms);
|
|
3465
|
+
if (msAbs >= d) {
|
|
3466
|
+
return Math.round(ms / d) + 'd';
|
|
3467
|
+
}
|
|
3468
|
+
if (msAbs >= h) {
|
|
3469
|
+
return Math.round(ms / h) + 'h';
|
|
3470
|
+
}
|
|
3471
|
+
if (msAbs >= m) {
|
|
3472
|
+
return Math.round(ms / m) + 'm';
|
|
3473
|
+
}
|
|
3474
|
+
if (msAbs >= s) {
|
|
3475
|
+
return Math.round(ms / s) + 's';
|
|
3476
|
+
}
|
|
3477
|
+
return ms + 'ms';
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
/**
|
|
3481
|
+
* Long format for `ms`.
|
|
3482
|
+
*
|
|
3483
|
+
* @param {Number} ms
|
|
3484
|
+
* @return {String}
|
|
3485
|
+
* @api private
|
|
3486
|
+
*/
|
|
3487
|
+
|
|
3488
|
+
function fmtLong(ms) {
|
|
3489
|
+
var msAbs = Math.abs(ms);
|
|
3490
|
+
if (msAbs >= d) {
|
|
3491
|
+
return plural(ms, msAbs, d, 'day');
|
|
3492
|
+
}
|
|
3493
|
+
if (msAbs >= h) {
|
|
3494
|
+
return plural(ms, msAbs, h, 'hour');
|
|
3495
|
+
}
|
|
3496
|
+
if (msAbs >= m) {
|
|
3497
|
+
return plural(ms, msAbs, m, 'minute');
|
|
3498
|
+
}
|
|
3499
|
+
if (msAbs >= s) {
|
|
3500
|
+
return plural(ms, msAbs, s, 'second');
|
|
3501
|
+
}
|
|
3502
|
+
return ms + ' ms';
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
/**
|
|
3506
|
+
* Pluralization helper.
|
|
3507
|
+
*/
|
|
3508
|
+
|
|
3509
|
+
function plural(ms, msAbs, n, name) {
|
|
3510
|
+
var isPlural = msAbs >= n * 1.5;
|
|
3511
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
/*!
|
|
3515
|
+
* humanize-ms - index.js
|
|
3516
|
+
* Copyright(c) 2014 dead_horse <dead_horse@qq.com>
|
|
3517
|
+
* MIT Licensed
|
|
3518
|
+
*/
|
|
3519
|
+
|
|
3520
|
+
/**
|
|
3521
|
+
* Module dependencies.
|
|
3522
|
+
*/
|
|
3523
|
+
|
|
3524
|
+
var util = require$$0__default["default"];
|
|
3525
|
+
var ms$1 = ms$2;
|
|
3526
|
+
|
|
3527
|
+
var humanizeMs = function (t) {
|
|
3528
|
+
if (typeof t === 'number') return t;
|
|
3529
|
+
var r = ms$1(t);
|
|
3530
|
+
if (r === undefined) {
|
|
3531
|
+
var err = new Error(util.format('humanize-ms(%j) result undefined', t));
|
|
3532
|
+
console.warn(err.stack);
|
|
3533
|
+
}
|
|
3534
|
+
return r;
|
|
3535
|
+
};
|
|
3536
|
+
|
|
3537
|
+
var src = {exports: {}};
|
|
3538
|
+
|
|
3539
|
+
var browser = {exports: {}};
|
|
3540
|
+
|
|
3541
|
+
var common;
|
|
3542
|
+
var hasRequiredCommon;
|
|
3543
|
+
|
|
3544
|
+
function requireCommon () {
|
|
3545
|
+
if (hasRequiredCommon) return common;
|
|
3546
|
+
hasRequiredCommon = 1;
|
|
3547
|
+
/**
|
|
3548
|
+
* This is the common logic for both the Node.js and web browser
|
|
3549
|
+
* implementations of `debug()`.
|
|
3550
|
+
*/
|
|
3551
|
+
|
|
3552
|
+
function setup(env) {
|
|
3553
|
+
createDebug.debug = createDebug;
|
|
3554
|
+
createDebug.default = createDebug;
|
|
3555
|
+
createDebug.coerce = coerce;
|
|
3556
|
+
createDebug.disable = disable;
|
|
3557
|
+
createDebug.enable = enable;
|
|
3558
|
+
createDebug.enabled = enabled;
|
|
3559
|
+
createDebug.humanize = ms$2;
|
|
3560
|
+
createDebug.destroy = destroy;
|
|
3561
|
+
|
|
3562
|
+
Object.keys(env).forEach(key => {
|
|
3563
|
+
createDebug[key] = env[key];
|
|
3564
|
+
});
|
|
3565
|
+
|
|
3566
|
+
/**
|
|
3567
|
+
* The currently active debug mode names, and names to skip.
|
|
3568
|
+
*/
|
|
3569
|
+
|
|
3570
|
+
createDebug.names = [];
|
|
3571
|
+
createDebug.skips = [];
|
|
3572
|
+
|
|
3573
|
+
/**
|
|
3574
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
3575
|
+
*
|
|
3576
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
3577
|
+
*/
|
|
3578
|
+
createDebug.formatters = {};
|
|
3579
|
+
|
|
3580
|
+
/**
|
|
3581
|
+
* Selects a color for a debug namespace
|
|
3582
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
3583
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
3584
|
+
* @api private
|
|
3585
|
+
*/
|
|
3586
|
+
function selectColor(namespace) {
|
|
3587
|
+
let hash = 0;
|
|
3588
|
+
|
|
3589
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
3590
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
3591
|
+
hash |= 0; // Convert to 32bit integer
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
3595
|
+
}
|
|
3596
|
+
createDebug.selectColor = selectColor;
|
|
3597
|
+
|
|
3598
|
+
/**
|
|
3599
|
+
* Create a debugger with the given `namespace`.
|
|
3600
|
+
*
|
|
3601
|
+
* @param {String} namespace
|
|
3602
|
+
* @return {Function}
|
|
3603
|
+
* @api public
|
|
3604
|
+
*/
|
|
3605
|
+
function createDebug(namespace) {
|
|
3606
|
+
let prevTime;
|
|
3607
|
+
let enableOverride = null;
|
|
3608
|
+
let namespacesCache;
|
|
3609
|
+
let enabledCache;
|
|
3610
|
+
|
|
3611
|
+
function debug(...args) {
|
|
3612
|
+
// Disabled?
|
|
3613
|
+
if (!debug.enabled) {
|
|
3614
|
+
return;
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
const self = debug;
|
|
3618
|
+
|
|
3619
|
+
// Set `diff` timestamp
|
|
3620
|
+
const curr = Number(new Date());
|
|
3621
|
+
const ms = curr - (prevTime || curr);
|
|
3622
|
+
self.diff = ms;
|
|
3623
|
+
self.prev = prevTime;
|
|
3624
|
+
self.curr = curr;
|
|
3625
|
+
prevTime = curr;
|
|
3626
|
+
|
|
3627
|
+
args[0] = createDebug.coerce(args[0]);
|
|
3628
|
+
|
|
3629
|
+
if (typeof args[0] !== 'string') {
|
|
3630
|
+
// Anything else let's inspect with %O
|
|
3631
|
+
args.unshift('%O');
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
// Apply any `formatters` transformations
|
|
3635
|
+
let index = 0;
|
|
3636
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
3637
|
+
// If we encounter an escaped % then don't increase the array index
|
|
3638
|
+
if (match === '%%') {
|
|
3639
|
+
return '%';
|
|
3640
|
+
}
|
|
3641
|
+
index++;
|
|
3642
|
+
const formatter = createDebug.formatters[format];
|
|
3643
|
+
if (typeof formatter === 'function') {
|
|
3644
|
+
const val = args[index];
|
|
3645
|
+
match = formatter.call(self, val);
|
|
3646
|
+
|
|
3647
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
3648
|
+
args.splice(index, 1);
|
|
3649
|
+
index--;
|
|
3650
|
+
}
|
|
3651
|
+
return match;
|
|
3652
|
+
});
|
|
3653
|
+
|
|
3654
|
+
// Apply env-specific formatting (colors, etc.)
|
|
3655
|
+
createDebug.formatArgs.call(self, args);
|
|
3656
|
+
|
|
3657
|
+
const logFn = self.log || createDebug.log;
|
|
3658
|
+
logFn.apply(self, args);
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
debug.namespace = namespace;
|
|
3662
|
+
debug.useColors = createDebug.useColors();
|
|
3663
|
+
debug.color = createDebug.selectColor(namespace);
|
|
3664
|
+
debug.extend = extend;
|
|
3665
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
3666
|
+
|
|
3667
|
+
Object.defineProperty(debug, 'enabled', {
|
|
3668
|
+
enumerable: true,
|
|
3669
|
+
configurable: false,
|
|
3670
|
+
get: () => {
|
|
3671
|
+
if (enableOverride !== null) {
|
|
3672
|
+
return enableOverride;
|
|
3673
|
+
}
|
|
3674
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
3675
|
+
namespacesCache = createDebug.namespaces;
|
|
3676
|
+
enabledCache = createDebug.enabled(namespace);
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3679
|
+
return enabledCache;
|
|
3680
|
+
},
|
|
3681
|
+
set: v => {
|
|
3682
|
+
enableOverride = v;
|
|
3683
|
+
}
|
|
3684
|
+
});
|
|
3685
|
+
|
|
3686
|
+
// Env-specific initialization logic for debug instances
|
|
3687
|
+
if (typeof createDebug.init === 'function') {
|
|
3688
|
+
createDebug.init(debug);
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
return debug;
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
function extend(namespace, delimiter) {
|
|
3695
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
3696
|
+
newDebug.log = this.log;
|
|
3697
|
+
return newDebug;
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
/**
|
|
3701
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
3702
|
+
* separated by a colon and wildcards.
|
|
3703
|
+
*
|
|
3704
|
+
* @param {String} namespaces
|
|
3705
|
+
* @api public
|
|
3706
|
+
*/
|
|
3707
|
+
function enable(namespaces) {
|
|
3708
|
+
createDebug.save(namespaces);
|
|
3709
|
+
createDebug.namespaces = namespaces;
|
|
3710
|
+
|
|
3711
|
+
createDebug.names = [];
|
|
3712
|
+
createDebug.skips = [];
|
|
3713
|
+
|
|
3714
|
+
let i;
|
|
3715
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
3716
|
+
const len = split.length;
|
|
3717
|
+
|
|
3718
|
+
for (i = 0; i < len; i++) {
|
|
3719
|
+
if (!split[i]) {
|
|
3720
|
+
// ignore empty strings
|
|
3721
|
+
continue;
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
3725
|
+
|
|
3726
|
+
if (namespaces[0] === '-') {
|
|
3727
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
3728
|
+
} else {
|
|
3729
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
/**
|
|
3735
|
+
* Disable debug output.
|
|
3736
|
+
*
|
|
3737
|
+
* @return {String} namespaces
|
|
3738
|
+
* @api public
|
|
3739
|
+
*/
|
|
3740
|
+
function disable() {
|
|
3741
|
+
const namespaces = [
|
|
3742
|
+
...createDebug.names.map(toNamespace),
|
|
3743
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
3744
|
+
].join(',');
|
|
3745
|
+
createDebug.enable('');
|
|
3746
|
+
return namespaces;
|
|
3747
|
+
}
|
|
3748
|
+
|
|
3749
|
+
/**
|
|
3750
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
3751
|
+
*
|
|
3752
|
+
* @param {String} name
|
|
3753
|
+
* @return {Boolean}
|
|
3754
|
+
* @api public
|
|
3755
|
+
*/
|
|
3756
|
+
function enabled(name) {
|
|
3757
|
+
if (name[name.length - 1] === '*') {
|
|
3758
|
+
return true;
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
let i;
|
|
3762
|
+
let len;
|
|
3763
|
+
|
|
3764
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
3765
|
+
if (createDebug.skips[i].test(name)) {
|
|
3766
|
+
return false;
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
3771
|
+
if (createDebug.names[i].test(name)) {
|
|
3772
|
+
return true;
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
return false;
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3779
|
+
/**
|
|
3780
|
+
* Convert regexp to namespace
|
|
3781
|
+
*
|
|
3782
|
+
* @param {RegExp} regxep
|
|
3783
|
+
* @return {String} namespace
|
|
3784
|
+
* @api private
|
|
3785
|
+
*/
|
|
3786
|
+
function toNamespace(regexp) {
|
|
3787
|
+
return regexp.toString()
|
|
3788
|
+
.substring(2, regexp.toString().length - 2)
|
|
3789
|
+
.replace(/\.\*\?$/, '*');
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
/**
|
|
3793
|
+
* Coerce `val`.
|
|
3794
|
+
*
|
|
3795
|
+
* @param {Mixed} val
|
|
3796
|
+
* @return {Mixed}
|
|
3797
|
+
* @api private
|
|
3798
|
+
*/
|
|
3799
|
+
function coerce(val) {
|
|
3800
|
+
if (val instanceof Error) {
|
|
3801
|
+
return val.stack || val.message;
|
|
3802
|
+
}
|
|
3803
|
+
return val;
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
/**
|
|
3807
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
3808
|
+
* XXX It WILL be removed in the next major release.
|
|
3809
|
+
*/
|
|
3810
|
+
function destroy() {
|
|
3811
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
createDebug.enable(createDebug.load());
|
|
3815
|
+
|
|
3816
|
+
return createDebug;
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
common = setup;
|
|
3820
|
+
return common;
|
|
3821
|
+
}
|
|
3822
|
+
|
|
3823
|
+
/* eslint-env browser */
|
|
3824
|
+
|
|
3825
|
+
var hasRequiredBrowser;
|
|
3826
|
+
|
|
3827
|
+
function requireBrowser () {
|
|
3828
|
+
if (hasRequiredBrowser) return browser.exports;
|
|
3829
|
+
hasRequiredBrowser = 1;
|
|
3830
|
+
(function (module, exports) {
|
|
3831
|
+
/**
|
|
3832
|
+
* This is the web browser implementation of `debug()`.
|
|
3833
|
+
*/
|
|
3834
|
+
|
|
3835
|
+
exports.formatArgs = formatArgs;
|
|
3836
|
+
exports.save = save;
|
|
3837
|
+
exports.load = load;
|
|
3838
|
+
exports.useColors = useColors;
|
|
3839
|
+
exports.storage = localstorage();
|
|
3840
|
+
exports.destroy = (() => {
|
|
3841
|
+
let warned = false;
|
|
3842
|
+
|
|
3843
|
+
return () => {
|
|
3844
|
+
if (!warned) {
|
|
3845
|
+
warned = true;
|
|
3846
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
3847
|
+
}
|
|
3848
|
+
};
|
|
3849
|
+
})();
|
|
3850
|
+
|
|
3851
|
+
/**
|
|
3852
|
+
* Colors.
|
|
3853
|
+
*/
|
|
3854
|
+
|
|
3855
|
+
exports.colors = [
|
|
3856
|
+
'#0000CC',
|
|
3857
|
+
'#0000FF',
|
|
3858
|
+
'#0033CC',
|
|
3859
|
+
'#0033FF',
|
|
3860
|
+
'#0066CC',
|
|
3861
|
+
'#0066FF',
|
|
3862
|
+
'#0099CC',
|
|
3863
|
+
'#0099FF',
|
|
3864
|
+
'#00CC00',
|
|
3865
|
+
'#00CC33',
|
|
3866
|
+
'#00CC66',
|
|
3867
|
+
'#00CC99',
|
|
3868
|
+
'#00CCCC',
|
|
3869
|
+
'#00CCFF',
|
|
3870
|
+
'#3300CC',
|
|
3871
|
+
'#3300FF',
|
|
3872
|
+
'#3333CC',
|
|
3873
|
+
'#3333FF',
|
|
3874
|
+
'#3366CC',
|
|
3875
|
+
'#3366FF',
|
|
3876
|
+
'#3399CC',
|
|
3877
|
+
'#3399FF',
|
|
3878
|
+
'#33CC00',
|
|
3879
|
+
'#33CC33',
|
|
3880
|
+
'#33CC66',
|
|
3881
|
+
'#33CC99',
|
|
3882
|
+
'#33CCCC',
|
|
3883
|
+
'#33CCFF',
|
|
3884
|
+
'#6600CC',
|
|
3885
|
+
'#6600FF',
|
|
3886
|
+
'#6633CC',
|
|
3887
|
+
'#6633FF',
|
|
3888
|
+
'#66CC00',
|
|
3889
|
+
'#66CC33',
|
|
3890
|
+
'#9900CC',
|
|
3891
|
+
'#9900FF',
|
|
3892
|
+
'#9933CC',
|
|
3893
|
+
'#9933FF',
|
|
3894
|
+
'#99CC00',
|
|
3895
|
+
'#99CC33',
|
|
3896
|
+
'#CC0000',
|
|
3897
|
+
'#CC0033',
|
|
3898
|
+
'#CC0066',
|
|
3899
|
+
'#CC0099',
|
|
3900
|
+
'#CC00CC',
|
|
3901
|
+
'#CC00FF',
|
|
3902
|
+
'#CC3300',
|
|
3903
|
+
'#CC3333',
|
|
3904
|
+
'#CC3366',
|
|
3905
|
+
'#CC3399',
|
|
3906
|
+
'#CC33CC',
|
|
3907
|
+
'#CC33FF',
|
|
3908
|
+
'#CC6600',
|
|
3909
|
+
'#CC6633',
|
|
3910
|
+
'#CC9900',
|
|
3911
|
+
'#CC9933',
|
|
3912
|
+
'#CCCC00',
|
|
3913
|
+
'#CCCC33',
|
|
3914
|
+
'#FF0000',
|
|
3915
|
+
'#FF0033',
|
|
3916
|
+
'#FF0066',
|
|
3917
|
+
'#FF0099',
|
|
3918
|
+
'#FF00CC',
|
|
3919
|
+
'#FF00FF',
|
|
3920
|
+
'#FF3300',
|
|
3921
|
+
'#FF3333',
|
|
3922
|
+
'#FF3366',
|
|
3923
|
+
'#FF3399',
|
|
3924
|
+
'#FF33CC',
|
|
3925
|
+
'#FF33FF',
|
|
3926
|
+
'#FF6600',
|
|
3927
|
+
'#FF6633',
|
|
3928
|
+
'#FF9900',
|
|
3929
|
+
'#FF9933',
|
|
3930
|
+
'#FFCC00',
|
|
3931
|
+
'#FFCC33'
|
|
3932
|
+
];
|
|
3933
|
+
|
|
3934
|
+
/**
|
|
3935
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
3936
|
+
* and the Firebug extension (any Firefox version) are known
|
|
3937
|
+
* to support "%c" CSS customizations.
|
|
3938
|
+
*
|
|
3939
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
3940
|
+
*/
|
|
3941
|
+
|
|
3942
|
+
// eslint-disable-next-line complexity
|
|
3943
|
+
function useColors() {
|
|
3944
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
3945
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
3946
|
+
// explicitly
|
|
3947
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
3948
|
+
return true;
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3951
|
+
// Internet Explorer and Edge do not support colors.
|
|
3952
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
3953
|
+
return false;
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
3957
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
3958
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
3959
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
3960
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
3961
|
+
// Is firefox >= v31?
|
|
3962
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
3963
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
3964
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
3965
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
3966
|
+
}
|
|
3967
|
+
|
|
3968
|
+
/**
|
|
3969
|
+
* Colorize log arguments if enabled.
|
|
3970
|
+
*
|
|
3971
|
+
* @api public
|
|
3972
|
+
*/
|
|
3973
|
+
|
|
3974
|
+
function formatArgs(args) {
|
|
3975
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
3976
|
+
this.namespace +
|
|
3977
|
+
(this.useColors ? ' %c' : ' ') +
|
|
3978
|
+
args[0] +
|
|
3979
|
+
(this.useColors ? '%c ' : ' ') +
|
|
3980
|
+
'+' + module.exports.humanize(this.diff);
|
|
3981
|
+
|
|
3982
|
+
if (!this.useColors) {
|
|
3983
|
+
return;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
const c = 'color: ' + this.color;
|
|
3987
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
3988
|
+
|
|
3989
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
3990
|
+
// arguments passed either before or after the %c, so we need to
|
|
3991
|
+
// figure out the correct index to insert the CSS into
|
|
3992
|
+
let index = 0;
|
|
3993
|
+
let lastC = 0;
|
|
3994
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
3995
|
+
if (match === '%%') {
|
|
3996
|
+
return;
|
|
3997
|
+
}
|
|
3998
|
+
index++;
|
|
3999
|
+
if (match === '%c') {
|
|
4000
|
+
// We only are interested in the *last* %c
|
|
4001
|
+
// (the user may have provided their own)
|
|
4002
|
+
lastC = index;
|
|
4003
|
+
}
|
|
4004
|
+
});
|
|
4005
|
+
|
|
4006
|
+
args.splice(lastC, 0, c);
|
|
4007
|
+
}
|
|
4008
|
+
|
|
4009
|
+
/**
|
|
4010
|
+
* Invokes `console.debug()` when available.
|
|
4011
|
+
* No-op when `console.debug` is not a "function".
|
|
4012
|
+
* If `console.debug` is not available, falls back
|
|
4013
|
+
* to `console.log`.
|
|
4014
|
+
*
|
|
4015
|
+
* @api public
|
|
4016
|
+
*/
|
|
4017
|
+
exports.log = console.debug || console.log || (() => {});
|
|
4018
|
+
|
|
4019
|
+
/**
|
|
4020
|
+
* Save `namespaces`.
|
|
4021
|
+
*
|
|
4022
|
+
* @param {String} namespaces
|
|
4023
|
+
* @api private
|
|
4024
|
+
*/
|
|
4025
|
+
function save(namespaces) {
|
|
4026
|
+
try {
|
|
4027
|
+
if (namespaces) {
|
|
4028
|
+
exports.storage.setItem('debug', namespaces);
|
|
4029
|
+
} else {
|
|
4030
|
+
exports.storage.removeItem('debug');
|
|
4031
|
+
}
|
|
4032
|
+
} catch (error) {
|
|
4033
|
+
// Swallow
|
|
4034
|
+
// XXX (@Qix-) should we be logging these?
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
/**
|
|
4039
|
+
* Load `namespaces`.
|
|
4040
|
+
*
|
|
4041
|
+
* @return {String} returns the previously persisted debug modes
|
|
4042
|
+
* @api private
|
|
4043
|
+
*/
|
|
4044
|
+
function load() {
|
|
4045
|
+
let r;
|
|
4046
|
+
try {
|
|
4047
|
+
r = exports.storage.getItem('debug');
|
|
4048
|
+
} catch (error) {
|
|
4049
|
+
// Swallow
|
|
4050
|
+
// XXX (@Qix-) should we be logging these?
|
|
4051
|
+
}
|
|
4052
|
+
|
|
4053
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
4054
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
4055
|
+
r = process.env.DEBUG;
|
|
4056
|
+
}
|
|
4057
|
+
|
|
4058
|
+
return r;
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
/**
|
|
4062
|
+
* Localstorage attempts to return the localstorage.
|
|
4063
|
+
*
|
|
4064
|
+
* This is necessary because safari throws
|
|
4065
|
+
* when a user disables cookies/localstorage
|
|
4066
|
+
* and you attempt to access it.
|
|
4067
|
+
*
|
|
4068
|
+
* @return {LocalStorage}
|
|
4069
|
+
* @api private
|
|
4070
|
+
*/
|
|
4071
|
+
|
|
4072
|
+
function localstorage() {
|
|
4073
|
+
try {
|
|
4074
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
4075
|
+
// The Browser also has localStorage in the global context.
|
|
4076
|
+
return localStorage;
|
|
4077
|
+
} catch (error) {
|
|
4078
|
+
// Swallow
|
|
4079
|
+
// XXX (@Qix-) should we be logging these?
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
|
|
4083
|
+
module.exports = requireCommon()(exports);
|
|
4084
|
+
|
|
4085
|
+
const {formatters} = module.exports;
|
|
4086
|
+
|
|
4087
|
+
/**
|
|
4088
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
4089
|
+
*/
|
|
4090
|
+
|
|
4091
|
+
formatters.j = function (v) {
|
|
4092
|
+
try {
|
|
4093
|
+
return JSON.stringify(v);
|
|
4094
|
+
} catch (error) {
|
|
4095
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
4096
|
+
}
|
|
4097
|
+
};
|
|
4098
|
+
} (browser, browser.exports));
|
|
4099
|
+
return browser.exports;
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
var node = {exports: {}};
|
|
4103
|
+
|
|
4104
|
+
var hasFlag;
|
|
4105
|
+
var hasRequiredHasFlag;
|
|
4106
|
+
|
|
4107
|
+
function requireHasFlag () {
|
|
4108
|
+
if (hasRequiredHasFlag) return hasFlag;
|
|
4109
|
+
hasRequiredHasFlag = 1;
|
|
4110
|
+
hasFlag = (flag, argv) => {
|
|
4111
|
+
argv = argv || process.argv;
|
|
4112
|
+
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
4113
|
+
const pos = argv.indexOf(prefix + flag);
|
|
4114
|
+
const terminatorPos = argv.indexOf('--');
|
|
4115
|
+
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
|
4116
|
+
};
|
|
4117
|
+
return hasFlag;
|
|
4118
|
+
}
|
|
4119
|
+
|
|
4120
|
+
var supportsColor_1;
|
|
4121
|
+
var hasRequiredSupportsColor;
|
|
4122
|
+
|
|
4123
|
+
function requireSupportsColor () {
|
|
4124
|
+
if (hasRequiredSupportsColor) return supportsColor_1;
|
|
4125
|
+
hasRequiredSupportsColor = 1;
|
|
4126
|
+
const os = require$$0__default$1["default"];
|
|
4127
|
+
const hasFlag = requireHasFlag();
|
|
4128
|
+
|
|
4129
|
+
const env = process.env;
|
|
4130
|
+
|
|
4131
|
+
let forceColor;
|
|
4132
|
+
if (hasFlag('no-color') ||
|
|
4133
|
+
hasFlag('no-colors') ||
|
|
4134
|
+
hasFlag('color=false')) {
|
|
4135
|
+
forceColor = false;
|
|
4136
|
+
} else if (hasFlag('color') ||
|
|
4137
|
+
hasFlag('colors') ||
|
|
4138
|
+
hasFlag('color=true') ||
|
|
4139
|
+
hasFlag('color=always')) {
|
|
4140
|
+
forceColor = true;
|
|
4141
|
+
}
|
|
4142
|
+
if ('FORCE_COLOR' in env) {
|
|
4143
|
+
forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
function translateLevel(level) {
|
|
4147
|
+
if (level === 0) {
|
|
4148
|
+
return false;
|
|
4149
|
+
}
|
|
4150
|
+
|
|
4151
|
+
return {
|
|
4152
|
+
level,
|
|
4153
|
+
hasBasic: true,
|
|
4154
|
+
has256: level >= 2,
|
|
4155
|
+
has16m: level >= 3
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
function supportsColor(stream) {
|
|
4160
|
+
if (forceColor === false) {
|
|
4161
|
+
return 0;
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
if (hasFlag('color=16m') ||
|
|
4165
|
+
hasFlag('color=full') ||
|
|
4166
|
+
hasFlag('color=truecolor')) {
|
|
4167
|
+
return 3;
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
if (hasFlag('color=256')) {
|
|
4171
|
+
return 2;
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
if (stream && !stream.isTTY && forceColor !== true) {
|
|
4175
|
+
return 0;
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
const min = forceColor ? 1 : 0;
|
|
4179
|
+
|
|
4180
|
+
if (process.platform === 'win32') {
|
|
4181
|
+
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
4182
|
+
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
4183
|
+
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
4184
|
+
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
4185
|
+
// release that supports 256 colors. Windows 10 build 14931 is the first release
|
|
4186
|
+
// that supports 16m/TrueColor.
|
|
4187
|
+
const osRelease = os.release().split('.');
|
|
4188
|
+
if (
|
|
4189
|
+
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
4190
|
+
Number(osRelease[0]) >= 10 &&
|
|
4191
|
+
Number(osRelease[2]) >= 10586
|
|
4192
|
+
) {
|
|
4193
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
4194
|
+
}
|
|
4195
|
+
|
|
4196
|
+
return 1;
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
if ('CI' in env) {
|
|
4200
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
4201
|
+
return 1;
|
|
4202
|
+
}
|
|
4203
|
+
|
|
4204
|
+
return min;
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
4208
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
if (env.COLORTERM === 'truecolor') {
|
|
4212
|
+
return 3;
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
if ('TERM_PROGRAM' in env) {
|
|
4216
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
4217
|
+
|
|
4218
|
+
switch (env.TERM_PROGRAM) {
|
|
4219
|
+
case 'iTerm.app':
|
|
4220
|
+
return version >= 3 ? 3 : 2;
|
|
4221
|
+
case 'Apple_Terminal':
|
|
4222
|
+
return 2;
|
|
4223
|
+
// No default
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
4228
|
+
return 2;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
4232
|
+
return 1;
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
if ('COLORTERM' in env) {
|
|
4236
|
+
return 1;
|
|
4237
|
+
}
|
|
4238
|
+
|
|
4239
|
+
if (env.TERM === 'dumb') {
|
|
4240
|
+
return min;
|
|
4241
|
+
}
|
|
4242
|
+
|
|
4243
|
+
return min;
|
|
4244
|
+
}
|
|
4245
|
+
|
|
4246
|
+
function getSupportLevel(stream) {
|
|
4247
|
+
const level = supportsColor(stream);
|
|
4248
|
+
return translateLevel(level);
|
|
4249
|
+
}
|
|
4250
|
+
|
|
4251
|
+
supportsColor_1 = {
|
|
4252
|
+
supportsColor: getSupportLevel,
|
|
4253
|
+
stdout: getSupportLevel(process.stdout),
|
|
4254
|
+
stderr: getSupportLevel(process.stderr)
|
|
4255
|
+
};
|
|
4256
|
+
return supportsColor_1;
|
|
4257
|
+
}
|
|
4258
|
+
|
|
4259
|
+
/**
|
|
4260
|
+
* Module dependencies.
|
|
4261
|
+
*/
|
|
4262
|
+
|
|
4263
|
+
var hasRequiredNode;
|
|
4264
|
+
|
|
4265
|
+
function requireNode () {
|
|
4266
|
+
if (hasRequiredNode) return node.exports;
|
|
4267
|
+
hasRequiredNode = 1;
|
|
4268
|
+
(function (module, exports) {
|
|
4269
|
+
const tty = require$$0__default$2["default"];
|
|
4270
|
+
const util = require$$0__default["default"];
|
|
4271
|
+
|
|
4272
|
+
/**
|
|
4273
|
+
* This is the Node.js implementation of `debug()`.
|
|
4274
|
+
*/
|
|
4275
|
+
|
|
4276
|
+
exports.init = init;
|
|
4277
|
+
exports.log = log;
|
|
4278
|
+
exports.formatArgs = formatArgs;
|
|
4279
|
+
exports.save = save;
|
|
4280
|
+
exports.load = load;
|
|
4281
|
+
exports.useColors = useColors;
|
|
4282
|
+
exports.destroy = util.deprecate(
|
|
4283
|
+
() => {},
|
|
4284
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
4285
|
+
);
|
|
4286
|
+
|
|
4287
|
+
/**
|
|
4288
|
+
* Colors.
|
|
4289
|
+
*/
|
|
4290
|
+
|
|
4291
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
4292
|
+
|
|
4293
|
+
try {
|
|
4294
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
4295
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4296
|
+
const supportsColor = requireSupportsColor();
|
|
4297
|
+
|
|
4298
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
4299
|
+
exports.colors = [
|
|
4300
|
+
20,
|
|
4301
|
+
21,
|
|
4302
|
+
26,
|
|
4303
|
+
27,
|
|
4304
|
+
32,
|
|
4305
|
+
33,
|
|
4306
|
+
38,
|
|
4307
|
+
39,
|
|
4308
|
+
40,
|
|
4309
|
+
41,
|
|
4310
|
+
42,
|
|
4311
|
+
43,
|
|
4312
|
+
44,
|
|
4313
|
+
45,
|
|
4314
|
+
56,
|
|
4315
|
+
57,
|
|
4316
|
+
62,
|
|
4317
|
+
63,
|
|
4318
|
+
68,
|
|
4319
|
+
69,
|
|
4320
|
+
74,
|
|
4321
|
+
75,
|
|
4322
|
+
76,
|
|
4323
|
+
77,
|
|
4324
|
+
78,
|
|
4325
|
+
79,
|
|
4326
|
+
80,
|
|
4327
|
+
81,
|
|
4328
|
+
92,
|
|
4329
|
+
93,
|
|
4330
|
+
98,
|
|
4331
|
+
99,
|
|
4332
|
+
112,
|
|
4333
|
+
113,
|
|
4334
|
+
128,
|
|
4335
|
+
129,
|
|
4336
|
+
134,
|
|
4337
|
+
135,
|
|
4338
|
+
148,
|
|
4339
|
+
149,
|
|
4340
|
+
160,
|
|
4341
|
+
161,
|
|
4342
|
+
162,
|
|
4343
|
+
163,
|
|
4344
|
+
164,
|
|
4345
|
+
165,
|
|
4346
|
+
166,
|
|
4347
|
+
167,
|
|
4348
|
+
168,
|
|
4349
|
+
169,
|
|
4350
|
+
170,
|
|
4351
|
+
171,
|
|
4352
|
+
172,
|
|
4353
|
+
173,
|
|
4354
|
+
178,
|
|
4355
|
+
179,
|
|
4356
|
+
184,
|
|
4357
|
+
185,
|
|
4358
|
+
196,
|
|
4359
|
+
197,
|
|
4360
|
+
198,
|
|
4361
|
+
199,
|
|
4362
|
+
200,
|
|
4363
|
+
201,
|
|
4364
|
+
202,
|
|
4365
|
+
203,
|
|
4366
|
+
204,
|
|
4367
|
+
205,
|
|
4368
|
+
206,
|
|
4369
|
+
207,
|
|
4370
|
+
208,
|
|
4371
|
+
209,
|
|
4372
|
+
214,
|
|
4373
|
+
215,
|
|
4374
|
+
220,
|
|
4375
|
+
221
|
|
4376
|
+
];
|
|
4377
|
+
}
|
|
4378
|
+
} catch (error) {
|
|
4379
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
4380
|
+
}
|
|
4381
|
+
|
|
4382
|
+
/**
|
|
4383
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
4384
|
+
*
|
|
4385
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
4386
|
+
*/
|
|
4387
|
+
|
|
4388
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
4389
|
+
return /^debug_/i.test(key);
|
|
4390
|
+
}).reduce((obj, key) => {
|
|
4391
|
+
// Camel-case
|
|
4392
|
+
const prop = key
|
|
4393
|
+
.substring(6)
|
|
4394
|
+
.toLowerCase()
|
|
4395
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
4396
|
+
return k.toUpperCase();
|
|
4397
|
+
});
|
|
4398
|
+
|
|
4399
|
+
// Coerce string value into JS value
|
|
4400
|
+
let val = process.env[key];
|
|
4401
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
4402
|
+
val = true;
|
|
4403
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
4404
|
+
val = false;
|
|
4405
|
+
} else if (val === 'null') {
|
|
4406
|
+
val = null;
|
|
4407
|
+
} else {
|
|
4408
|
+
val = Number(val);
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
obj[prop] = val;
|
|
4412
|
+
return obj;
|
|
4413
|
+
}, {});
|
|
4414
|
+
|
|
4415
|
+
/**
|
|
4416
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
4417
|
+
*/
|
|
4418
|
+
|
|
4419
|
+
function useColors() {
|
|
4420
|
+
return 'colors' in exports.inspectOpts ?
|
|
4421
|
+
Boolean(exports.inspectOpts.colors) :
|
|
4422
|
+
tty.isatty(process.stderr.fd);
|
|
4423
|
+
}
|
|
4424
|
+
|
|
4425
|
+
/**
|
|
4426
|
+
* Adds ANSI color escape codes if enabled.
|
|
4427
|
+
*
|
|
4428
|
+
* @api public
|
|
4429
|
+
*/
|
|
4430
|
+
|
|
4431
|
+
function formatArgs(args) {
|
|
4432
|
+
const {namespace: name, useColors} = this;
|
|
4433
|
+
|
|
4434
|
+
if (useColors) {
|
|
4435
|
+
const c = this.color;
|
|
4436
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
4437
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
4438
|
+
|
|
4439
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
4440
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
4441
|
+
} else {
|
|
4442
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
|
|
4446
|
+
function getDate() {
|
|
4447
|
+
if (exports.inspectOpts.hideDate) {
|
|
4448
|
+
return '';
|
|
4449
|
+
}
|
|
4450
|
+
return new Date().toISOString() + ' ';
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
/**
|
|
4454
|
+
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
4455
|
+
*/
|
|
4456
|
+
|
|
4457
|
+
function log(...args) {
|
|
4458
|
+
return process.stderr.write(util.format(...args) + '\n');
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
/**
|
|
4462
|
+
* Save `namespaces`.
|
|
4463
|
+
*
|
|
4464
|
+
* @param {String} namespaces
|
|
4465
|
+
* @api private
|
|
4466
|
+
*/
|
|
4467
|
+
function save(namespaces) {
|
|
4468
|
+
if (namespaces) {
|
|
4469
|
+
process.env.DEBUG = namespaces;
|
|
4470
|
+
} else {
|
|
4471
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
4472
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
4473
|
+
delete process.env.DEBUG;
|
|
4474
|
+
}
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4477
|
+
/**
|
|
4478
|
+
* Load `namespaces`.
|
|
4479
|
+
*
|
|
4480
|
+
* @return {String} returns the previously persisted debug modes
|
|
4481
|
+
* @api private
|
|
4482
|
+
*/
|
|
4483
|
+
|
|
4484
|
+
function load() {
|
|
4485
|
+
return process.env.DEBUG;
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
/**
|
|
4489
|
+
* Init logic for `debug` instances.
|
|
4490
|
+
*
|
|
4491
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
4492
|
+
* differently for a particular `debug` instance.
|
|
4493
|
+
*/
|
|
4494
|
+
|
|
4495
|
+
function init(debug) {
|
|
4496
|
+
debug.inspectOpts = {};
|
|
4497
|
+
|
|
4498
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
4499
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4500
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
|
|
4504
|
+
module.exports = requireCommon()(exports);
|
|
4505
|
+
|
|
4506
|
+
const {formatters} = module.exports;
|
|
4507
|
+
|
|
4508
|
+
/**
|
|
4509
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
4510
|
+
*/
|
|
4511
|
+
|
|
4512
|
+
formatters.o = function (v) {
|
|
4513
|
+
this.inspectOpts.colors = this.useColors;
|
|
4514
|
+
return util.inspect(v, this.inspectOpts)
|
|
4515
|
+
.split('\n')
|
|
4516
|
+
.map(str => str.trim())
|
|
4517
|
+
.join(' ');
|
|
4518
|
+
};
|
|
4519
|
+
|
|
4520
|
+
/**
|
|
4521
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
4522
|
+
*/
|
|
4523
|
+
|
|
4524
|
+
formatters.O = function (v) {
|
|
4525
|
+
this.inspectOpts.colors = this.useColors;
|
|
4526
|
+
return util.inspect(v, this.inspectOpts);
|
|
4527
|
+
};
|
|
4528
|
+
} (node, node.exports));
|
|
4529
|
+
return node.exports;
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
/**
|
|
4533
|
+
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
4534
|
+
* treat as a browser.
|
|
4535
|
+
*/
|
|
4536
|
+
|
|
4537
|
+
(function (module) {
|
|
4538
|
+
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
4539
|
+
module.exports = requireBrowser();
|
|
4540
|
+
} else {
|
|
4541
|
+
module.exports = requireNode();
|
|
4542
|
+
}
|
|
4543
|
+
} (src));
|
|
4544
|
+
|
|
4545
|
+
var compat = {exports: {}};
|
|
4546
|
+
|
|
4547
|
+
/*!
|
|
4548
|
+
* depd
|
|
4549
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
4550
|
+
* MIT Licensed
|
|
4551
|
+
*/
|
|
4552
|
+
|
|
4553
|
+
var callsiteTostring;
|
|
4554
|
+
var hasRequiredCallsiteTostring;
|
|
4555
|
+
|
|
4556
|
+
function requireCallsiteTostring () {
|
|
4557
|
+
if (hasRequiredCallsiteTostring) return callsiteTostring;
|
|
4558
|
+
hasRequiredCallsiteTostring = 1;
|
|
4559
|
+
|
|
4560
|
+
/**
|
|
4561
|
+
* Module exports.
|
|
4562
|
+
*/
|
|
4563
|
+
|
|
4564
|
+
callsiteTostring = callSiteToString;
|
|
4565
|
+
|
|
4566
|
+
/**
|
|
4567
|
+
* Format a CallSite file location to a string.
|
|
4568
|
+
*/
|
|
4569
|
+
|
|
4570
|
+
function callSiteFileLocation (callSite) {
|
|
4571
|
+
var fileName;
|
|
4572
|
+
var fileLocation = '';
|
|
4573
|
+
|
|
4574
|
+
if (callSite.isNative()) {
|
|
4575
|
+
fileLocation = 'native';
|
|
4576
|
+
} else if (callSite.isEval()) {
|
|
4577
|
+
fileName = callSite.getScriptNameOrSourceURL();
|
|
4578
|
+
if (!fileName) {
|
|
4579
|
+
fileLocation = callSite.getEvalOrigin();
|
|
4580
|
+
}
|
|
4581
|
+
} else {
|
|
4582
|
+
fileName = callSite.getFileName();
|
|
4583
|
+
}
|
|
4584
|
+
|
|
4585
|
+
if (fileName) {
|
|
4586
|
+
fileLocation += fileName;
|
|
4587
|
+
|
|
4588
|
+
var lineNumber = callSite.getLineNumber();
|
|
4589
|
+
if (lineNumber != null) {
|
|
4590
|
+
fileLocation += ':' + lineNumber;
|
|
4591
|
+
|
|
4592
|
+
var columnNumber = callSite.getColumnNumber();
|
|
4593
|
+
if (columnNumber) {
|
|
4594
|
+
fileLocation += ':' + columnNumber;
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
|
|
4599
|
+
return fileLocation || 'unknown source'
|
|
4600
|
+
}
|
|
4601
|
+
|
|
4602
|
+
/**
|
|
4603
|
+
* Format a CallSite to a string.
|
|
4604
|
+
*/
|
|
4605
|
+
|
|
4606
|
+
function callSiteToString (callSite) {
|
|
4607
|
+
var addSuffix = true;
|
|
4608
|
+
var fileLocation = callSiteFileLocation(callSite);
|
|
4609
|
+
var functionName = callSite.getFunctionName();
|
|
4610
|
+
var isConstructor = callSite.isConstructor();
|
|
4611
|
+
var isMethodCall = !(callSite.isToplevel() || isConstructor);
|
|
4612
|
+
var line = '';
|
|
4613
|
+
|
|
4614
|
+
if (isMethodCall) {
|
|
4615
|
+
var methodName = callSite.getMethodName();
|
|
4616
|
+
var typeName = getConstructorName(callSite);
|
|
4617
|
+
|
|
4618
|
+
if (functionName) {
|
|
4619
|
+
if (typeName && functionName.indexOf(typeName) !== 0) {
|
|
4620
|
+
line += typeName + '.';
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
line += functionName;
|
|
4624
|
+
|
|
4625
|
+
if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
|
|
4626
|
+
line += ' [as ' + methodName + ']';
|
|
4627
|
+
}
|
|
4628
|
+
} else {
|
|
4629
|
+
line += typeName + '.' + (methodName || '<anonymous>');
|
|
4630
|
+
}
|
|
4631
|
+
} else if (isConstructor) {
|
|
4632
|
+
line += 'new ' + (functionName || '<anonymous>');
|
|
4633
|
+
} else if (functionName) {
|
|
4634
|
+
line += functionName;
|
|
4635
|
+
} else {
|
|
4636
|
+
addSuffix = false;
|
|
4637
|
+
line += fileLocation;
|
|
4638
|
+
}
|
|
4639
|
+
|
|
4640
|
+
if (addSuffix) {
|
|
4641
|
+
line += ' (' + fileLocation + ')';
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
return line
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4647
|
+
/**
|
|
4648
|
+
* Get constructor name of reviver.
|
|
4649
|
+
*/
|
|
4650
|
+
|
|
4651
|
+
function getConstructorName (obj) {
|
|
4652
|
+
var receiver = obj.receiver;
|
|
4653
|
+
return (receiver.constructor && receiver.constructor.name) || null
|
|
4654
|
+
}
|
|
4655
|
+
return callsiteTostring;
|
|
4656
|
+
}
|
|
4657
|
+
|
|
4658
|
+
/*!
|
|
4659
|
+
* depd
|
|
4660
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
4661
|
+
* MIT Licensed
|
|
4662
|
+
*/
|
|
4663
|
+
|
|
4664
|
+
var eventListenerCount_1;
|
|
4665
|
+
var hasRequiredEventListenerCount;
|
|
4666
|
+
|
|
4667
|
+
function requireEventListenerCount () {
|
|
4668
|
+
if (hasRequiredEventListenerCount) return eventListenerCount_1;
|
|
4669
|
+
hasRequiredEventListenerCount = 1;
|
|
4670
|
+
|
|
4671
|
+
/**
|
|
4672
|
+
* Module exports.
|
|
4673
|
+
* @public
|
|
4674
|
+
*/
|
|
4675
|
+
|
|
4676
|
+
eventListenerCount_1 = eventListenerCount;
|
|
4677
|
+
|
|
4678
|
+
/**
|
|
4679
|
+
* Get the count of listeners on an event emitter of a specific type.
|
|
4680
|
+
*/
|
|
4681
|
+
|
|
4682
|
+
function eventListenerCount (emitter, type) {
|
|
4683
|
+
return emitter.listeners(type).length
|
|
4684
|
+
}
|
|
4685
|
+
return eventListenerCount_1;
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4688
|
+
/*!
|
|
4689
|
+
* depd
|
|
4690
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
4691
|
+
* MIT Licensed
|
|
4692
|
+
*/
|
|
4693
|
+
|
|
4694
|
+
(function (module) {
|
|
4695
|
+
|
|
4696
|
+
/**
|
|
4697
|
+
* Module dependencies.
|
|
4698
|
+
* @private
|
|
4699
|
+
*/
|
|
4700
|
+
|
|
4701
|
+
var EventEmitter = require$$0__default$3["default"].EventEmitter;
|
|
4702
|
+
|
|
4703
|
+
/**
|
|
4704
|
+
* Module exports.
|
|
4705
|
+
* @public
|
|
4706
|
+
*/
|
|
4707
|
+
|
|
4708
|
+
lazyProperty(module.exports, 'callSiteToString', function callSiteToString () {
|
|
4709
|
+
var limit = Error.stackTraceLimit;
|
|
4710
|
+
var obj = {};
|
|
4711
|
+
var prep = Error.prepareStackTrace;
|
|
4712
|
+
|
|
4713
|
+
function prepareObjectStackTrace (obj, stack) {
|
|
4714
|
+
return stack
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
Error.prepareStackTrace = prepareObjectStackTrace;
|
|
4718
|
+
Error.stackTraceLimit = 2;
|
|
4719
|
+
|
|
4720
|
+
// capture the stack
|
|
4721
|
+
Error.captureStackTrace(obj);
|
|
4722
|
+
|
|
4723
|
+
// slice the stack
|
|
4724
|
+
var stack = obj.stack.slice();
|
|
4725
|
+
|
|
4726
|
+
Error.prepareStackTrace = prep;
|
|
4727
|
+
Error.stackTraceLimit = limit;
|
|
4728
|
+
|
|
4729
|
+
return stack[0].toString ? toString : requireCallsiteTostring()
|
|
4730
|
+
});
|
|
4731
|
+
|
|
4732
|
+
lazyProperty(module.exports, 'eventListenerCount', function eventListenerCount () {
|
|
4733
|
+
return EventEmitter.listenerCount || requireEventListenerCount()
|
|
4734
|
+
});
|
|
4735
|
+
|
|
4736
|
+
/**
|
|
4737
|
+
* Define a lazy property.
|
|
4738
|
+
*/
|
|
4739
|
+
|
|
4740
|
+
function lazyProperty (obj, prop, getter) {
|
|
4741
|
+
function get () {
|
|
4742
|
+
var val = getter();
|
|
4743
|
+
|
|
4744
|
+
Object.defineProperty(obj, prop, {
|
|
4745
|
+
configurable: true,
|
|
4746
|
+
enumerable: true,
|
|
4747
|
+
value: val
|
|
4748
|
+
});
|
|
4749
|
+
|
|
4750
|
+
return val
|
|
4751
|
+
}
|
|
4752
|
+
|
|
4753
|
+
Object.defineProperty(obj, prop, {
|
|
4754
|
+
configurable: true,
|
|
4755
|
+
enumerable: true,
|
|
4756
|
+
get: get
|
|
4757
|
+
});
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
/**
|
|
4761
|
+
* Call toString() on the obj
|
|
4762
|
+
*/
|
|
4763
|
+
|
|
4764
|
+
function toString (obj) {
|
|
4765
|
+
return obj.toString()
|
|
4766
|
+
}
|
|
4767
|
+
} (compat));
|
|
4768
|
+
|
|
4769
|
+
/*!
|
|
4770
|
+
* depd
|
|
4771
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
4772
|
+
* MIT Licensed
|
|
4773
|
+
*/
|
|
4774
|
+
|
|
4775
|
+
/**
|
|
4776
|
+
* Module dependencies.
|
|
4777
|
+
*/
|
|
4778
|
+
|
|
4779
|
+
var callSiteToString = compat.exports.callSiteToString;
|
|
4780
|
+
var eventListenerCount = compat.exports.eventListenerCount;
|
|
4781
|
+
var relative = require$$1__default["default"].relative;
|
|
4782
|
+
|
|
4783
|
+
/**
|
|
4784
|
+
* Module exports.
|
|
4785
|
+
*/
|
|
4786
|
+
|
|
4787
|
+
var depd_1 = depd;
|
|
4788
|
+
|
|
4789
|
+
/**
|
|
4790
|
+
* Get the path to base files on.
|
|
4791
|
+
*/
|
|
4792
|
+
|
|
4793
|
+
var basePath = process.cwd();
|
|
4794
|
+
|
|
4795
|
+
/**
|
|
4796
|
+
* Determine if namespace is contained in the string.
|
|
4797
|
+
*/
|
|
4798
|
+
|
|
4799
|
+
function containsNamespace (str, namespace) {
|
|
4800
|
+
var vals = str.split(/[ ,]+/);
|
|
4801
|
+
var ns = String(namespace).toLowerCase();
|
|
4802
|
+
|
|
4803
|
+
for (var i = 0; i < vals.length; i++) {
|
|
4804
|
+
var val = vals[i];
|
|
4805
|
+
|
|
4806
|
+
// namespace contained
|
|
4807
|
+
if (val && (val === '*' || val.toLowerCase() === ns)) {
|
|
4808
|
+
return true
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
|
|
4812
|
+
return false
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
/**
|
|
4816
|
+
* Convert a data descriptor to accessor descriptor.
|
|
4817
|
+
*/
|
|
4818
|
+
|
|
4819
|
+
function convertDataDescriptorToAccessor (obj, prop, message) {
|
|
4820
|
+
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
4821
|
+
var value = descriptor.value;
|
|
4822
|
+
|
|
4823
|
+
descriptor.get = function getter () { return value };
|
|
4824
|
+
|
|
4825
|
+
if (descriptor.writable) {
|
|
4826
|
+
descriptor.set = function setter (val) { return (value = val) };
|
|
4827
|
+
}
|
|
4828
|
+
|
|
4829
|
+
delete descriptor.value;
|
|
4830
|
+
delete descriptor.writable;
|
|
4831
|
+
|
|
4832
|
+
Object.defineProperty(obj, prop, descriptor);
|
|
4833
|
+
|
|
4834
|
+
return descriptor
|
|
4835
|
+
}
|
|
4836
|
+
|
|
4837
|
+
/**
|
|
4838
|
+
* Create arguments string to keep arity.
|
|
4839
|
+
*/
|
|
4840
|
+
|
|
4841
|
+
function createArgumentsString (arity) {
|
|
4842
|
+
var str = '';
|
|
4843
|
+
|
|
4844
|
+
for (var i = 0; i < arity; i++) {
|
|
4845
|
+
str += ', arg' + i;
|
|
4846
|
+
}
|
|
4847
|
+
|
|
4848
|
+
return str.substr(2)
|
|
4849
|
+
}
|
|
4850
|
+
|
|
4851
|
+
/**
|
|
4852
|
+
* Create stack string from stack.
|
|
4853
|
+
*/
|
|
4854
|
+
|
|
4855
|
+
function createStackString (stack) {
|
|
4856
|
+
var str = this.name + ': ' + this.namespace;
|
|
4857
|
+
|
|
4858
|
+
if (this.message) {
|
|
4859
|
+
str += ' deprecated ' + this.message;
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
for (var i = 0; i < stack.length; i++) {
|
|
4863
|
+
str += '\n at ' + callSiteToString(stack[i]);
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4866
|
+
return str
|
|
4867
|
+
}
|
|
4868
|
+
|
|
4869
|
+
/**
|
|
4870
|
+
* Create deprecate for namespace in caller.
|
|
4871
|
+
*/
|
|
4872
|
+
|
|
4873
|
+
function depd (namespace) {
|
|
4874
|
+
if (!namespace) {
|
|
4875
|
+
throw new TypeError('argument namespace is required')
|
|
4876
|
+
}
|
|
4877
|
+
|
|
4878
|
+
var stack = getStack();
|
|
4879
|
+
var site = callSiteLocation(stack[1]);
|
|
4880
|
+
var file = site[0];
|
|
4881
|
+
|
|
4882
|
+
function deprecate (message) {
|
|
4883
|
+
// call to self as log
|
|
4884
|
+
log.call(deprecate, message);
|
|
4885
|
+
}
|
|
4886
|
+
|
|
4887
|
+
deprecate._file = file;
|
|
4888
|
+
deprecate._ignored = isignored(namespace);
|
|
4889
|
+
deprecate._namespace = namespace;
|
|
4890
|
+
deprecate._traced = istraced(namespace);
|
|
4891
|
+
deprecate._warned = Object.create(null);
|
|
4892
|
+
|
|
4893
|
+
deprecate.function = wrapfunction;
|
|
4894
|
+
deprecate.property = wrapproperty;
|
|
4895
|
+
|
|
4896
|
+
return deprecate
|
|
4897
|
+
}
|
|
4898
|
+
|
|
4899
|
+
/**
|
|
4900
|
+
* Determine if namespace is ignored.
|
|
4901
|
+
*/
|
|
4902
|
+
|
|
4903
|
+
function isignored (namespace) {
|
|
4904
|
+
/* istanbul ignore next: tested in a child processs */
|
|
4905
|
+
if (process.noDeprecation) {
|
|
4906
|
+
// --no-deprecation support
|
|
4907
|
+
return true
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
var str = process.env.NO_DEPRECATION || '';
|
|
4911
|
+
|
|
4912
|
+
// namespace ignored
|
|
4913
|
+
return containsNamespace(str, namespace)
|
|
4914
|
+
}
|
|
4915
|
+
|
|
4916
|
+
/**
|
|
4917
|
+
* Determine if namespace is traced.
|
|
4918
|
+
*/
|
|
4919
|
+
|
|
4920
|
+
function istraced (namespace) {
|
|
4921
|
+
/* istanbul ignore next: tested in a child processs */
|
|
4922
|
+
if (process.traceDeprecation) {
|
|
4923
|
+
// --trace-deprecation support
|
|
4924
|
+
return true
|
|
4925
|
+
}
|
|
4926
|
+
|
|
4927
|
+
var str = process.env.TRACE_DEPRECATION || '';
|
|
4928
|
+
|
|
4929
|
+
// namespace traced
|
|
4930
|
+
return containsNamespace(str, namespace)
|
|
4931
|
+
}
|
|
4932
|
+
|
|
4933
|
+
/**
|
|
4934
|
+
* Display deprecation message.
|
|
4935
|
+
*/
|
|
4936
|
+
|
|
4937
|
+
function log (message, site) {
|
|
4938
|
+
var haslisteners = eventListenerCount(process, 'deprecation') !== 0;
|
|
4939
|
+
|
|
4940
|
+
// abort early if no destination
|
|
4941
|
+
if (!haslisteners && this._ignored) {
|
|
4942
|
+
return
|
|
4943
|
+
}
|
|
4944
|
+
|
|
4945
|
+
var caller;
|
|
4946
|
+
var callFile;
|
|
4947
|
+
var callSite;
|
|
4948
|
+
var depSite;
|
|
4949
|
+
var i = 0;
|
|
4950
|
+
var seen = false;
|
|
4951
|
+
var stack = getStack();
|
|
4952
|
+
var file = this._file;
|
|
4953
|
+
|
|
4954
|
+
if (site) {
|
|
4955
|
+
// provided site
|
|
4956
|
+
depSite = site;
|
|
4957
|
+
callSite = callSiteLocation(stack[1]);
|
|
4958
|
+
callSite.name = depSite.name;
|
|
4959
|
+
file = callSite[0];
|
|
4960
|
+
} else {
|
|
4961
|
+
// get call site
|
|
4962
|
+
i = 2;
|
|
4963
|
+
depSite = callSiteLocation(stack[i]);
|
|
4964
|
+
callSite = depSite;
|
|
4965
|
+
}
|
|
4966
|
+
|
|
4967
|
+
// get caller of deprecated thing in relation to file
|
|
4968
|
+
for (; i < stack.length; i++) {
|
|
4969
|
+
caller = callSiteLocation(stack[i]);
|
|
4970
|
+
callFile = caller[0];
|
|
4971
|
+
|
|
4972
|
+
if (callFile === file) {
|
|
4973
|
+
seen = true;
|
|
4974
|
+
} else if (callFile === this._file) {
|
|
4975
|
+
file = this._file;
|
|
4976
|
+
} else if (seen) {
|
|
4977
|
+
break
|
|
4978
|
+
}
|
|
4979
|
+
}
|
|
4980
|
+
|
|
4981
|
+
var key = caller
|
|
4982
|
+
? depSite.join(':') + '__' + caller.join(':')
|
|
4983
|
+
: undefined;
|
|
4984
|
+
|
|
4985
|
+
if (key !== undefined && key in this._warned) {
|
|
4986
|
+
// already warned
|
|
4987
|
+
return
|
|
4988
|
+
}
|
|
4989
|
+
|
|
4990
|
+
this._warned[key] = true;
|
|
4991
|
+
|
|
4992
|
+
// generate automatic message from call site
|
|
4993
|
+
var msg = message;
|
|
4994
|
+
if (!msg) {
|
|
4995
|
+
msg = callSite === depSite || !callSite.name
|
|
4996
|
+
? defaultMessage(depSite)
|
|
4997
|
+
: defaultMessage(callSite);
|
|
4998
|
+
}
|
|
4999
|
+
|
|
5000
|
+
// emit deprecation if listeners exist
|
|
5001
|
+
if (haslisteners) {
|
|
5002
|
+
var err = DeprecationError(this._namespace, msg, stack.slice(i));
|
|
5003
|
+
process.emit('deprecation', err);
|
|
5004
|
+
return
|
|
5005
|
+
}
|
|
5006
|
+
|
|
5007
|
+
// format and write message
|
|
5008
|
+
var format = process.stderr.isTTY
|
|
5009
|
+
? formatColor
|
|
5010
|
+
: formatPlain;
|
|
5011
|
+
var output = format.call(this, msg, caller, stack.slice(i));
|
|
5012
|
+
process.stderr.write(output + '\n', 'utf8');
|
|
5013
|
+
}
|
|
5014
|
+
|
|
5015
|
+
/**
|
|
5016
|
+
* Get call site location as array.
|
|
5017
|
+
*/
|
|
5018
|
+
|
|
5019
|
+
function callSiteLocation (callSite) {
|
|
5020
|
+
var file = callSite.getFileName() || '<anonymous>';
|
|
5021
|
+
var line = callSite.getLineNumber();
|
|
5022
|
+
var colm = callSite.getColumnNumber();
|
|
5023
|
+
|
|
5024
|
+
if (callSite.isEval()) {
|
|
5025
|
+
file = callSite.getEvalOrigin() + ', ' + file;
|
|
5026
|
+
}
|
|
5027
|
+
|
|
5028
|
+
var site = [file, line, colm];
|
|
5029
|
+
|
|
5030
|
+
site.callSite = callSite;
|
|
5031
|
+
site.name = callSite.getFunctionName();
|
|
5032
|
+
|
|
5033
|
+
return site
|
|
5034
|
+
}
|
|
5035
|
+
|
|
5036
|
+
/**
|
|
5037
|
+
* Generate a default message from the site.
|
|
5038
|
+
*/
|
|
5039
|
+
|
|
5040
|
+
function defaultMessage (site) {
|
|
5041
|
+
var callSite = site.callSite;
|
|
5042
|
+
var funcName = site.name;
|
|
5043
|
+
|
|
5044
|
+
// make useful anonymous name
|
|
5045
|
+
if (!funcName) {
|
|
5046
|
+
funcName = '<anonymous@' + formatLocation(site) + '>';
|
|
5047
|
+
}
|
|
5048
|
+
|
|
5049
|
+
var context = callSite.getThis();
|
|
5050
|
+
var typeName = context && callSite.getTypeName();
|
|
5051
|
+
|
|
5052
|
+
// ignore useless type name
|
|
5053
|
+
if (typeName === 'Object') {
|
|
5054
|
+
typeName = undefined;
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
// make useful type name
|
|
5058
|
+
if (typeName === 'Function') {
|
|
5059
|
+
typeName = context.name || typeName;
|
|
5060
|
+
}
|
|
5061
|
+
|
|
5062
|
+
return typeName && callSite.getMethodName()
|
|
5063
|
+
? typeName + '.' + funcName
|
|
5064
|
+
: funcName
|
|
5065
|
+
}
|
|
5066
|
+
|
|
5067
|
+
/**
|
|
5068
|
+
* Format deprecation message without color.
|
|
5069
|
+
*/
|
|
5070
|
+
|
|
5071
|
+
function formatPlain (msg, caller, stack) {
|
|
5072
|
+
var timestamp = new Date().toUTCString();
|
|
5073
|
+
|
|
5074
|
+
var formatted = timestamp +
|
|
5075
|
+
' ' + this._namespace +
|
|
5076
|
+
' deprecated ' + msg;
|
|
5077
|
+
|
|
5078
|
+
// add stack trace
|
|
5079
|
+
if (this._traced) {
|
|
5080
|
+
for (var i = 0; i < stack.length; i++) {
|
|
5081
|
+
formatted += '\n at ' + callSiteToString(stack[i]);
|
|
5082
|
+
}
|
|
5083
|
+
|
|
5084
|
+
return formatted
|
|
5085
|
+
}
|
|
5086
|
+
|
|
5087
|
+
if (caller) {
|
|
5088
|
+
formatted += ' at ' + formatLocation(caller);
|
|
5089
|
+
}
|
|
5090
|
+
|
|
5091
|
+
return formatted
|
|
5092
|
+
}
|
|
5093
|
+
|
|
5094
|
+
/**
|
|
5095
|
+
* Format deprecation message with color.
|
|
5096
|
+
*/
|
|
5097
|
+
|
|
5098
|
+
function formatColor (msg, caller, stack) {
|
|
5099
|
+
var formatted = '\x1b[36;1m' + this._namespace + '\x1b[22;39m' + // bold cyan
|
|
5100
|
+
' \x1b[33;1mdeprecated\x1b[22;39m' + // bold yellow
|
|
5101
|
+
' \x1b[0m' + msg + '\x1b[39m'; // reset
|
|
5102
|
+
|
|
5103
|
+
// add stack trace
|
|
5104
|
+
if (this._traced) {
|
|
5105
|
+
for (var i = 0; i < stack.length; i++) {
|
|
5106
|
+
formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m'; // cyan
|
|
5107
|
+
}
|
|
5108
|
+
|
|
5109
|
+
return formatted
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
if (caller) {
|
|
5113
|
+
formatted += ' \x1b[36m' + formatLocation(caller) + '\x1b[39m'; // cyan
|
|
5114
|
+
}
|
|
5115
|
+
|
|
5116
|
+
return formatted
|
|
5117
|
+
}
|
|
5118
|
+
|
|
5119
|
+
/**
|
|
5120
|
+
* Format call site location.
|
|
5121
|
+
*/
|
|
5122
|
+
|
|
5123
|
+
function formatLocation (callSite) {
|
|
5124
|
+
return relative(basePath, callSite[0]) +
|
|
5125
|
+
':' + callSite[1] +
|
|
5126
|
+
':' + callSite[2]
|
|
5127
|
+
}
|
|
5128
|
+
|
|
5129
|
+
/**
|
|
5130
|
+
* Get the stack as array of call sites.
|
|
5131
|
+
*/
|
|
5132
|
+
|
|
5133
|
+
function getStack () {
|
|
5134
|
+
var limit = Error.stackTraceLimit;
|
|
5135
|
+
var obj = {};
|
|
5136
|
+
var prep = Error.prepareStackTrace;
|
|
5137
|
+
|
|
5138
|
+
Error.prepareStackTrace = prepareObjectStackTrace;
|
|
5139
|
+
Error.stackTraceLimit = Math.max(10, limit);
|
|
5140
|
+
|
|
5141
|
+
// capture the stack
|
|
5142
|
+
Error.captureStackTrace(obj);
|
|
5143
|
+
|
|
5144
|
+
// slice this function off the top
|
|
5145
|
+
var stack = obj.stack.slice(1);
|
|
5146
|
+
|
|
5147
|
+
Error.prepareStackTrace = prep;
|
|
5148
|
+
Error.stackTraceLimit = limit;
|
|
5149
|
+
|
|
5150
|
+
return stack
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5153
|
+
/**
|
|
5154
|
+
* Capture call site stack from v8.
|
|
5155
|
+
*/
|
|
5156
|
+
|
|
5157
|
+
function prepareObjectStackTrace (obj, stack) {
|
|
5158
|
+
return stack
|
|
5159
|
+
}
|
|
5160
|
+
|
|
5161
|
+
/**
|
|
5162
|
+
* Return a wrapped function in a deprecation message.
|
|
5163
|
+
*/
|
|
5164
|
+
|
|
5165
|
+
function wrapfunction (fn, message) {
|
|
5166
|
+
if (typeof fn !== 'function') {
|
|
5167
|
+
throw new TypeError('argument fn must be a function')
|
|
5168
|
+
}
|
|
5169
|
+
|
|
5170
|
+
var args = createArgumentsString(fn.length);
|
|
5171
|
+
var stack = getStack();
|
|
5172
|
+
var site = callSiteLocation(stack[1]);
|
|
5173
|
+
|
|
5174
|
+
site.name = fn.name;
|
|
5175
|
+
|
|
5176
|
+
// eslint-disable-next-line no-eval
|
|
5177
|
+
var deprecatedfn = eval('(function (' + args + ') {\n' +
|
|
5178
|
+
'"use strict"\n' +
|
|
5179
|
+
'log.call(deprecate, message, site)\n' +
|
|
5180
|
+
'return fn.apply(this, arguments)\n' +
|
|
5181
|
+
'})');
|
|
5182
|
+
|
|
5183
|
+
return deprecatedfn
|
|
5184
|
+
}
|
|
5185
|
+
|
|
5186
|
+
/**
|
|
5187
|
+
* Wrap property in a deprecation message.
|
|
5188
|
+
*/
|
|
5189
|
+
|
|
5190
|
+
function wrapproperty (obj, prop, message) {
|
|
5191
|
+
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
|
5192
|
+
throw new TypeError('argument obj must be object')
|
|
5193
|
+
}
|
|
5194
|
+
|
|
5195
|
+
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
5196
|
+
|
|
5197
|
+
if (!descriptor) {
|
|
5198
|
+
throw new TypeError('must call property on owner object')
|
|
5199
|
+
}
|
|
5200
|
+
|
|
5201
|
+
if (!descriptor.configurable) {
|
|
5202
|
+
throw new TypeError('property must be configurable')
|
|
5203
|
+
}
|
|
5204
|
+
|
|
5205
|
+
var deprecate = this;
|
|
5206
|
+
var stack = getStack();
|
|
5207
|
+
var site = callSiteLocation(stack[1]);
|
|
5208
|
+
|
|
5209
|
+
// set site name
|
|
5210
|
+
site.name = prop;
|
|
5211
|
+
|
|
5212
|
+
// convert data descriptor
|
|
5213
|
+
if ('value' in descriptor) {
|
|
5214
|
+
descriptor = convertDataDescriptorToAccessor(obj, prop);
|
|
5215
|
+
}
|
|
5216
|
+
|
|
5217
|
+
var get = descriptor.get;
|
|
5218
|
+
var set = descriptor.set;
|
|
5219
|
+
|
|
5220
|
+
// wrap getter
|
|
5221
|
+
if (typeof get === 'function') {
|
|
5222
|
+
descriptor.get = function getter () {
|
|
5223
|
+
log.call(deprecate, message, site);
|
|
5224
|
+
return get.apply(this, arguments)
|
|
5225
|
+
};
|
|
5226
|
+
}
|
|
5227
|
+
|
|
5228
|
+
// wrap setter
|
|
5229
|
+
if (typeof set === 'function') {
|
|
5230
|
+
descriptor.set = function setter () {
|
|
5231
|
+
log.call(deprecate, message, site);
|
|
5232
|
+
return set.apply(this, arguments)
|
|
5233
|
+
};
|
|
5234
|
+
}
|
|
5235
|
+
|
|
5236
|
+
Object.defineProperty(obj, prop, descriptor);
|
|
5237
|
+
}
|
|
5238
|
+
|
|
5239
|
+
/**
|
|
5240
|
+
* Create DeprecationError for deprecation
|
|
5241
|
+
*/
|
|
5242
|
+
|
|
5243
|
+
function DeprecationError (namespace, message, stack) {
|
|
5244
|
+
var error = new Error();
|
|
5245
|
+
var stackString;
|
|
5246
|
+
|
|
5247
|
+
Object.defineProperty(error, 'constructor', {
|
|
5248
|
+
value: DeprecationError
|
|
5249
|
+
});
|
|
5250
|
+
|
|
5251
|
+
Object.defineProperty(error, 'message', {
|
|
5252
|
+
configurable: true,
|
|
5253
|
+
enumerable: false,
|
|
5254
|
+
value: message,
|
|
5255
|
+
writable: true
|
|
5256
|
+
});
|
|
5257
|
+
|
|
5258
|
+
Object.defineProperty(error, 'name', {
|
|
5259
|
+
enumerable: false,
|
|
5260
|
+
configurable: true,
|
|
5261
|
+
value: 'DeprecationError',
|
|
5262
|
+
writable: true
|
|
5263
|
+
});
|
|
5264
|
+
|
|
5265
|
+
Object.defineProperty(error, 'namespace', {
|
|
5266
|
+
configurable: true,
|
|
5267
|
+
enumerable: false,
|
|
5268
|
+
value: namespace,
|
|
5269
|
+
writable: true
|
|
5270
|
+
});
|
|
5271
|
+
|
|
5272
|
+
Object.defineProperty(error, 'stack', {
|
|
5273
|
+
configurable: true,
|
|
5274
|
+
enumerable: false,
|
|
5275
|
+
get: function () {
|
|
5276
|
+
if (stackString !== undefined) {
|
|
5277
|
+
return stackString
|
|
5278
|
+
}
|
|
5279
|
+
|
|
5280
|
+
// prepare stack trace
|
|
5281
|
+
return (stackString = createStackString.call(this, stack))
|
|
5282
|
+
},
|
|
5283
|
+
set: function setter (val) {
|
|
5284
|
+
stackString = val;
|
|
5285
|
+
}
|
|
5286
|
+
});
|
|
5287
|
+
|
|
5288
|
+
return error
|
|
5289
|
+
}
|
|
5290
|
+
|
|
5291
|
+
var constants = {
|
|
5292
|
+
// agent
|
|
5293
|
+
CURRENT_ID: Symbol('agentkeepalive#currentId'),
|
|
5294
|
+
CREATE_ID: Symbol('agentkeepalive#createId'),
|
|
5295
|
+
INIT_SOCKET: Symbol('agentkeepalive#initSocket'),
|
|
5296
|
+
CREATE_HTTPS_CONNECTION: Symbol('agentkeepalive#createHttpsConnection'),
|
|
5297
|
+
// socket
|
|
5298
|
+
SOCKET_CREATED_TIME: Symbol('agentkeepalive#socketCreatedTime'),
|
|
5299
|
+
SOCKET_NAME: Symbol('agentkeepalive#socketName'),
|
|
5300
|
+
SOCKET_REQUEST_COUNT: Symbol('agentkeepalive#socketRequestCount'),
|
|
5301
|
+
SOCKET_REQUEST_FINISHED_COUNT: Symbol('agentkeepalive#socketRequestFinishedCount'),
|
|
5302
|
+
};
|
|
5303
|
+
|
|
5304
|
+
const OriginalAgent = require$$0__default$4["default"].Agent;
|
|
5305
|
+
const ms = humanizeMs;
|
|
5306
|
+
const debug = src.exports('agentkeepalive');
|
|
5307
|
+
const deprecate = depd_1('agentkeepalive');
|
|
5308
|
+
const {
|
|
5309
|
+
INIT_SOCKET: INIT_SOCKET$1,
|
|
5310
|
+
CURRENT_ID,
|
|
5311
|
+
CREATE_ID,
|
|
5312
|
+
SOCKET_CREATED_TIME,
|
|
5313
|
+
SOCKET_NAME,
|
|
5314
|
+
SOCKET_REQUEST_COUNT,
|
|
5315
|
+
SOCKET_REQUEST_FINISHED_COUNT,
|
|
5316
|
+
} = constants;
|
|
5317
|
+
|
|
5318
|
+
// OriginalAgent come from
|
|
5319
|
+
// - https://github.com/nodejs/node/blob/v8.12.0/lib/_http_agent.js
|
|
5320
|
+
// - https://github.com/nodejs/node/blob/v10.12.0/lib/_http_agent.js
|
|
5321
|
+
|
|
5322
|
+
// node <= 10
|
|
5323
|
+
let defaultTimeoutListenerCount = 1;
|
|
5324
|
+
const majorVersion = parseInt(process.version.split('.', 1)[0].substring(1));
|
|
5325
|
+
if (majorVersion >= 11 && majorVersion <= 12) {
|
|
5326
|
+
defaultTimeoutListenerCount = 2;
|
|
5327
|
+
} else if (majorVersion >= 13) {
|
|
5328
|
+
defaultTimeoutListenerCount = 3;
|
|
5329
|
+
}
|
|
5330
|
+
|
|
5331
|
+
class Agent extends OriginalAgent {
|
|
5332
|
+
constructor(options) {
|
|
5333
|
+
options = options || {};
|
|
5334
|
+
options.keepAlive = options.keepAlive !== false;
|
|
5335
|
+
// default is keep-alive and 4s free socket timeout
|
|
5336
|
+
// see https://medium.com/ssense-tech/reduce-networking-errors-in-nodejs-23b4eb9f2d83
|
|
5337
|
+
if (options.freeSocketTimeout === undefined) {
|
|
5338
|
+
options.freeSocketTimeout = 4000;
|
|
5339
|
+
}
|
|
5340
|
+
// Legacy API: keepAliveTimeout should be rename to `freeSocketTimeout`
|
|
5341
|
+
if (options.keepAliveTimeout) {
|
|
5342
|
+
deprecate('options.keepAliveTimeout is deprecated, please use options.freeSocketTimeout instead');
|
|
5343
|
+
options.freeSocketTimeout = options.keepAliveTimeout;
|
|
5344
|
+
delete options.keepAliveTimeout;
|
|
5345
|
+
}
|
|
5346
|
+
// Legacy API: freeSocketKeepAliveTimeout should be rename to `freeSocketTimeout`
|
|
5347
|
+
if (options.freeSocketKeepAliveTimeout) {
|
|
5348
|
+
deprecate('options.freeSocketKeepAliveTimeout is deprecated, please use options.freeSocketTimeout instead');
|
|
5349
|
+
options.freeSocketTimeout = options.freeSocketKeepAliveTimeout;
|
|
5350
|
+
delete options.freeSocketKeepAliveTimeout;
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5353
|
+
// Sets the socket to timeout after timeout milliseconds of inactivity on the socket.
|
|
5354
|
+
// By default is double free socket timeout.
|
|
5355
|
+
if (options.timeout === undefined) {
|
|
5356
|
+
// make sure socket default inactivity timeout >= 8s
|
|
5357
|
+
options.timeout = Math.max(options.freeSocketTimeout * 2, 8000);
|
|
5358
|
+
}
|
|
5359
|
+
|
|
5360
|
+
// support humanize format
|
|
5361
|
+
options.timeout = ms(options.timeout);
|
|
5362
|
+
options.freeSocketTimeout = ms(options.freeSocketTimeout);
|
|
5363
|
+
options.socketActiveTTL = options.socketActiveTTL ? ms(options.socketActiveTTL) : 0;
|
|
5364
|
+
|
|
5365
|
+
super(options);
|
|
5366
|
+
|
|
5367
|
+
this[CURRENT_ID] = 0;
|
|
5368
|
+
|
|
5369
|
+
// create socket success counter
|
|
5370
|
+
this.createSocketCount = 0;
|
|
5371
|
+
this.createSocketCountLastCheck = 0;
|
|
5372
|
+
|
|
5373
|
+
this.createSocketErrorCount = 0;
|
|
5374
|
+
this.createSocketErrorCountLastCheck = 0;
|
|
5375
|
+
|
|
5376
|
+
this.closeSocketCount = 0;
|
|
5377
|
+
this.closeSocketCountLastCheck = 0;
|
|
5378
|
+
|
|
5379
|
+
// socket error event count
|
|
5380
|
+
this.errorSocketCount = 0;
|
|
5381
|
+
this.errorSocketCountLastCheck = 0;
|
|
5382
|
+
|
|
5383
|
+
// request finished counter
|
|
5384
|
+
this.requestCount = 0;
|
|
5385
|
+
this.requestCountLastCheck = 0;
|
|
5386
|
+
|
|
5387
|
+
// including free socket timeout counter
|
|
5388
|
+
this.timeoutSocketCount = 0;
|
|
5389
|
+
this.timeoutSocketCountLastCheck = 0;
|
|
5390
|
+
|
|
5391
|
+
this.on('free', socket => {
|
|
5392
|
+
// https://github.com/nodejs/node/pull/32000
|
|
5393
|
+
// Node.js native agent will check socket timeout eqs agent.options.timeout.
|
|
5394
|
+
// Use the ttl or freeSocketTimeout to overwrite.
|
|
5395
|
+
const timeout = this.calcSocketTimeout(socket);
|
|
5396
|
+
if (timeout > 0 && socket.timeout !== timeout) {
|
|
5397
|
+
socket.setTimeout(timeout);
|
|
5398
|
+
}
|
|
5399
|
+
});
|
|
5400
|
+
}
|
|
5401
|
+
|
|
5402
|
+
get freeSocketKeepAliveTimeout() {
|
|
5403
|
+
deprecate('agent.freeSocketKeepAliveTimeout is deprecated, please use agent.options.freeSocketTimeout instead');
|
|
5404
|
+
return this.options.freeSocketTimeout;
|
|
5405
|
+
}
|
|
5406
|
+
|
|
5407
|
+
get timeout() {
|
|
5408
|
+
deprecate('agent.timeout is deprecated, please use agent.options.timeout instead');
|
|
5409
|
+
return this.options.timeout;
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
get socketActiveTTL() {
|
|
5413
|
+
deprecate('agent.socketActiveTTL is deprecated, please use agent.options.socketActiveTTL instead');
|
|
5414
|
+
return this.options.socketActiveTTL;
|
|
5415
|
+
}
|
|
5416
|
+
|
|
5417
|
+
calcSocketTimeout(socket) {
|
|
5418
|
+
/**
|
|
5419
|
+
* return <= 0: should free socket
|
|
5420
|
+
* return > 0: should update socket timeout
|
|
5421
|
+
* return undefined: not find custom timeout
|
|
5422
|
+
*/
|
|
5423
|
+
let freeSocketTimeout = this.options.freeSocketTimeout;
|
|
5424
|
+
const socketActiveTTL = this.options.socketActiveTTL;
|
|
5425
|
+
if (socketActiveTTL) {
|
|
5426
|
+
// check socketActiveTTL
|
|
5427
|
+
const aliveTime = Date.now() - socket[SOCKET_CREATED_TIME];
|
|
5428
|
+
const diff = socketActiveTTL - aliveTime;
|
|
5429
|
+
if (diff <= 0) {
|
|
5430
|
+
return diff;
|
|
5431
|
+
}
|
|
5432
|
+
if (freeSocketTimeout && diff < freeSocketTimeout) {
|
|
5433
|
+
freeSocketTimeout = diff;
|
|
5434
|
+
}
|
|
5435
|
+
}
|
|
5436
|
+
// set freeSocketTimeout
|
|
5437
|
+
if (freeSocketTimeout) {
|
|
5438
|
+
// set free keepalive timer
|
|
5439
|
+
// try to use socket custom freeSocketTimeout first, support headers['keep-alive']
|
|
5440
|
+
// https://github.com/node-modules/urllib/blob/b76053020923f4d99a1c93cf2e16e0c5ba10bacf/lib/urllib.js#L498
|
|
5441
|
+
const customFreeSocketTimeout = socket.freeSocketTimeout || socket.freeSocketKeepAliveTimeout;
|
|
5442
|
+
return customFreeSocketTimeout || freeSocketTimeout;
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
|
|
5446
|
+
keepSocketAlive(socket) {
|
|
5447
|
+
const result = super.keepSocketAlive(socket);
|
|
5448
|
+
// should not keepAlive, do nothing
|
|
5449
|
+
if (!result) return result;
|
|
5450
|
+
|
|
5451
|
+
const customTimeout = this.calcSocketTimeout(socket);
|
|
5452
|
+
if (typeof customTimeout === 'undefined') {
|
|
5453
|
+
return true;
|
|
5454
|
+
}
|
|
5455
|
+
if (customTimeout <= 0) {
|
|
5456
|
+
debug('%s(requests: %s, finished: %s) free but need to destroy by TTL, request count %s, diff is %s',
|
|
5457
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], customTimeout);
|
|
5458
|
+
return false;
|
|
5459
|
+
}
|
|
5460
|
+
if (socket.timeout !== customTimeout) {
|
|
5461
|
+
socket.setTimeout(customTimeout);
|
|
5462
|
+
}
|
|
5463
|
+
return true;
|
|
5464
|
+
}
|
|
5465
|
+
|
|
5466
|
+
// only call on addRequest
|
|
5467
|
+
reuseSocket(...args) {
|
|
5468
|
+
// reuseSocket(socket, req)
|
|
5469
|
+
super.reuseSocket(...args);
|
|
5470
|
+
const socket = args[0];
|
|
5471
|
+
const req = args[1];
|
|
5472
|
+
req.reusedSocket = true;
|
|
5473
|
+
const agentTimeout = this.options.timeout;
|
|
5474
|
+
if (getSocketTimeout(socket) !== agentTimeout) {
|
|
5475
|
+
// reset timeout before use
|
|
5476
|
+
socket.setTimeout(agentTimeout);
|
|
5477
|
+
debug('%s reset timeout to %sms', socket[SOCKET_NAME], agentTimeout);
|
|
5478
|
+
}
|
|
5479
|
+
socket[SOCKET_REQUEST_COUNT]++;
|
|
5480
|
+
debug('%s(requests: %s, finished: %s) reuse on addRequest, timeout %sms',
|
|
5481
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
5482
|
+
getSocketTimeout(socket));
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5485
|
+
[CREATE_ID]() {
|
|
5486
|
+
const id = this[CURRENT_ID]++;
|
|
5487
|
+
if (this[CURRENT_ID] === Number.MAX_SAFE_INTEGER) this[CURRENT_ID] = 0;
|
|
5488
|
+
return id;
|
|
5489
|
+
}
|
|
5490
|
+
|
|
5491
|
+
[INIT_SOCKET$1](socket, options) {
|
|
5492
|
+
// bugfix here.
|
|
5493
|
+
// https on node 8, 10 won't set agent.options.timeout by default
|
|
5494
|
+
// TODO: need to fix on node itself
|
|
5495
|
+
if (options.timeout) {
|
|
5496
|
+
const timeout = getSocketTimeout(socket);
|
|
5497
|
+
if (!timeout) {
|
|
5498
|
+
socket.setTimeout(options.timeout);
|
|
5499
|
+
}
|
|
5500
|
+
}
|
|
5501
|
+
|
|
5502
|
+
if (this.options.keepAlive) {
|
|
5503
|
+
// Disable Nagle's algorithm: http://blog.caustik.com/2012/04/08/scaling-node-js-to-100k-concurrent-connections/
|
|
5504
|
+
// https://fengmk2.com/benchmark/nagle-algorithm-delayed-ack-mock.html
|
|
5505
|
+
socket.setNoDelay(true);
|
|
5506
|
+
}
|
|
5507
|
+
this.createSocketCount++;
|
|
5508
|
+
if (this.options.socketActiveTTL) {
|
|
5509
|
+
socket[SOCKET_CREATED_TIME] = Date.now();
|
|
5510
|
+
}
|
|
5511
|
+
// don't show the hole '-----BEGIN CERTIFICATE----' key string
|
|
5512
|
+
socket[SOCKET_NAME] = `sock[${this[CREATE_ID]()}#${options._agentKey}]`.split('-----BEGIN', 1)[0];
|
|
5513
|
+
socket[SOCKET_REQUEST_COUNT] = 1;
|
|
5514
|
+
socket[SOCKET_REQUEST_FINISHED_COUNT] = 0;
|
|
5515
|
+
installListeners(this, socket, options);
|
|
5516
|
+
}
|
|
5517
|
+
|
|
5518
|
+
createConnection(options, oncreate) {
|
|
5519
|
+
let called = false;
|
|
5520
|
+
const onNewCreate = (err, socket) => {
|
|
5521
|
+
if (called) return;
|
|
5522
|
+
called = true;
|
|
5523
|
+
|
|
5524
|
+
if (err) {
|
|
5525
|
+
this.createSocketErrorCount++;
|
|
5526
|
+
return oncreate(err);
|
|
5527
|
+
}
|
|
5528
|
+
this[INIT_SOCKET$1](socket, options);
|
|
5529
|
+
oncreate(err, socket);
|
|
5530
|
+
};
|
|
5531
|
+
|
|
5532
|
+
const newSocket = super.createConnection(options, onNewCreate);
|
|
5533
|
+
if (newSocket) onNewCreate(null, newSocket);
|
|
5534
|
+
}
|
|
5535
|
+
|
|
5536
|
+
get statusChanged() {
|
|
5537
|
+
const changed = this.createSocketCount !== this.createSocketCountLastCheck ||
|
|
5538
|
+
this.createSocketErrorCount !== this.createSocketErrorCountLastCheck ||
|
|
5539
|
+
this.closeSocketCount !== this.closeSocketCountLastCheck ||
|
|
5540
|
+
this.errorSocketCount !== this.errorSocketCountLastCheck ||
|
|
5541
|
+
this.timeoutSocketCount !== this.timeoutSocketCountLastCheck ||
|
|
5542
|
+
this.requestCount !== this.requestCountLastCheck;
|
|
5543
|
+
if (changed) {
|
|
5544
|
+
this.createSocketCountLastCheck = this.createSocketCount;
|
|
5545
|
+
this.createSocketErrorCountLastCheck = this.createSocketErrorCount;
|
|
5546
|
+
this.closeSocketCountLastCheck = this.closeSocketCount;
|
|
5547
|
+
this.errorSocketCountLastCheck = this.errorSocketCount;
|
|
5548
|
+
this.timeoutSocketCountLastCheck = this.timeoutSocketCount;
|
|
5549
|
+
this.requestCountLastCheck = this.requestCount;
|
|
5550
|
+
}
|
|
5551
|
+
return changed;
|
|
5552
|
+
}
|
|
5553
|
+
|
|
5554
|
+
getCurrentStatus() {
|
|
5555
|
+
return {
|
|
5556
|
+
createSocketCount: this.createSocketCount,
|
|
5557
|
+
createSocketErrorCount: this.createSocketErrorCount,
|
|
5558
|
+
closeSocketCount: this.closeSocketCount,
|
|
5559
|
+
errorSocketCount: this.errorSocketCount,
|
|
5560
|
+
timeoutSocketCount: this.timeoutSocketCount,
|
|
5561
|
+
requestCount: this.requestCount,
|
|
5562
|
+
freeSockets: inspect(this.freeSockets),
|
|
5563
|
+
sockets: inspect(this.sockets),
|
|
5564
|
+
requests: inspect(this.requests),
|
|
5565
|
+
};
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
|
|
5569
|
+
// node 8 don't has timeout attribute on socket
|
|
5570
|
+
// https://github.com/nodejs/node/pull/21204/files#diff-e6ef024c3775d787c38487a6309e491dR408
|
|
5571
|
+
function getSocketTimeout(socket) {
|
|
5572
|
+
return socket.timeout || socket._idleTimeout;
|
|
5573
|
+
}
|
|
5574
|
+
|
|
5575
|
+
function installListeners(agent, socket, options) {
|
|
5576
|
+
debug('%s create, timeout %sms', socket[SOCKET_NAME], getSocketTimeout(socket));
|
|
5577
|
+
|
|
5578
|
+
// listener socket events: close, timeout, error, free
|
|
5579
|
+
function onFree() {
|
|
5580
|
+
// create and socket.emit('free') logic
|
|
5581
|
+
// https://github.com/nodejs/node/blob/master/lib/_http_agent.js#L311
|
|
5582
|
+
// no req on the socket, it should be the new socket
|
|
5583
|
+
if (!socket._httpMessage && socket[SOCKET_REQUEST_COUNT] === 1) return;
|
|
5584
|
+
|
|
5585
|
+
socket[SOCKET_REQUEST_FINISHED_COUNT]++;
|
|
5586
|
+
agent.requestCount++;
|
|
5587
|
+
debug('%s(requests: %s, finished: %s) free',
|
|
5588
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
5589
|
+
|
|
5590
|
+
// should reuse on pedding requests?
|
|
5591
|
+
const name = agent.getName(options);
|
|
5592
|
+
if (socket.writable && agent.requests[name] && agent.requests[name].length) {
|
|
5593
|
+
// will be reuse on agent free listener
|
|
5594
|
+
socket[SOCKET_REQUEST_COUNT]++;
|
|
5595
|
+
debug('%s(requests: %s, finished: %s) will be reuse on agent free event',
|
|
5596
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
5597
|
+
}
|
|
5598
|
+
}
|
|
5599
|
+
socket.on('free', onFree);
|
|
5600
|
+
|
|
5601
|
+
function onClose(isError) {
|
|
5602
|
+
debug('%s(requests: %s, finished: %s) close, isError: %s',
|
|
5603
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], isError);
|
|
5604
|
+
agent.closeSocketCount++;
|
|
5605
|
+
}
|
|
5606
|
+
socket.on('close', onClose);
|
|
5607
|
+
|
|
5608
|
+
// start socket timeout handler
|
|
5609
|
+
function onTimeout() {
|
|
5610
|
+
// onTimeout and emitRequestTimeout(_http_client.js)
|
|
5611
|
+
// https://github.com/nodejs/node/blob/v12.x/lib/_http_client.js#L711
|
|
5612
|
+
const listenerCount = socket.listeners('timeout').length;
|
|
5613
|
+
// node <= 10, default listenerCount is 1, onTimeout
|
|
5614
|
+
// 11 < node <= 12, default listenerCount is 2, onTimeout and emitRequestTimeout
|
|
5615
|
+
// node >= 13, default listenerCount is 3, onTimeout,
|
|
5616
|
+
// onTimeout(https://github.com/nodejs/node/pull/32000/files#diff-5f7fb0850412c6be189faeddea6c5359R333)
|
|
5617
|
+
// and emitRequestTimeout
|
|
5618
|
+
const timeout = getSocketTimeout(socket);
|
|
5619
|
+
const req = socket._httpMessage;
|
|
5620
|
+
const reqTimeoutListenerCount = req && req.listeners('timeout').length || 0;
|
|
5621
|
+
debug('%s(requests: %s, finished: %s) timeout after %sms, listeners %s, defaultTimeoutListenerCount %s, hasHttpRequest %s, HttpRequest timeoutListenerCount %s',
|
|
5622
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
5623
|
+
timeout, listenerCount, defaultTimeoutListenerCount, !!req, reqTimeoutListenerCount);
|
|
5624
|
+
if (debug.enabled) {
|
|
5625
|
+
debug('timeout listeners: %s', socket.listeners('timeout').map(f => f.name).join(', '));
|
|
5626
|
+
}
|
|
5627
|
+
agent.timeoutSocketCount++;
|
|
5628
|
+
const name = agent.getName(options);
|
|
5629
|
+
if (agent.freeSockets[name] && agent.freeSockets[name].indexOf(socket) !== -1) {
|
|
5630
|
+
// free socket timeout, destroy quietly
|
|
5631
|
+
socket.destroy();
|
|
5632
|
+
// Remove it from freeSockets list immediately to prevent new requests
|
|
5633
|
+
// from being sent through this socket.
|
|
5634
|
+
agent.removeSocket(socket, options);
|
|
5635
|
+
debug('%s is free, destroy quietly', socket[SOCKET_NAME]);
|
|
5636
|
+
} else {
|
|
5637
|
+
// if there is no any request socket timeout handler,
|
|
5638
|
+
// agent need to handle socket timeout itself.
|
|
5639
|
+
//
|
|
5640
|
+
// custom request socket timeout handle logic must follow these rules:
|
|
5641
|
+
// 1. Destroy socket first
|
|
5642
|
+
// 2. Must emit socket 'agentRemove' event tell agent remove socket
|
|
5643
|
+
// from freeSockets list immediately.
|
|
5644
|
+
// Otherise you may be get 'socket hang up' error when reuse
|
|
5645
|
+
// free socket and timeout happen in the same time.
|
|
5646
|
+
if (reqTimeoutListenerCount === 0) {
|
|
5647
|
+
const error = new Error('Socket timeout');
|
|
5648
|
+
error.code = 'ERR_SOCKET_TIMEOUT';
|
|
5649
|
+
error.timeout = timeout;
|
|
5650
|
+
// must manually call socket.end() or socket.destroy() to end the connection.
|
|
5651
|
+
// https://nodejs.org/dist/latest-v10.x/docs/api/net.html#net_socket_settimeout_timeout_callback
|
|
5652
|
+
socket.destroy(error);
|
|
5653
|
+
agent.removeSocket(socket, options);
|
|
5654
|
+
debug('%s destroy with timeout error', socket[SOCKET_NAME]);
|
|
5655
|
+
}
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
socket.on('timeout', onTimeout);
|
|
5659
|
+
|
|
5660
|
+
function onError(err) {
|
|
5661
|
+
const listenerCount = socket.listeners('error').length;
|
|
5662
|
+
debug('%s(requests: %s, finished: %s) error: %s, listenerCount: %s',
|
|
5663
|
+
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
|
|
5664
|
+
err, listenerCount);
|
|
5665
|
+
agent.errorSocketCount++;
|
|
5666
|
+
if (listenerCount === 1) {
|
|
5667
|
+
// if socket don't contain error event handler, don't catch it, emit it again
|
|
5668
|
+
debug('%s emit uncaught error event', socket[SOCKET_NAME]);
|
|
5669
|
+
socket.removeListener('error', onError);
|
|
5670
|
+
socket.emit('error', err);
|
|
5671
|
+
}
|
|
5672
|
+
}
|
|
5673
|
+
socket.on('error', onError);
|
|
5674
|
+
|
|
5675
|
+
function onRemove() {
|
|
5676
|
+
debug('%s(requests: %s, finished: %s) agentRemove',
|
|
5677
|
+
socket[SOCKET_NAME],
|
|
5678
|
+
socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT]);
|
|
5679
|
+
// We need this function for cases like HTTP 'upgrade'
|
|
5680
|
+
// (defined by WebSockets) where we need to remove a socket from the
|
|
5681
|
+
// pool because it'll be locked up indefinitely
|
|
5682
|
+
socket.removeListener('close', onClose);
|
|
5683
|
+
socket.removeListener('error', onError);
|
|
5684
|
+
socket.removeListener('free', onFree);
|
|
5685
|
+
socket.removeListener('timeout', onTimeout);
|
|
5686
|
+
socket.removeListener('agentRemove', onRemove);
|
|
5687
|
+
}
|
|
5688
|
+
socket.on('agentRemove', onRemove);
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
var agent = Agent;
|
|
5692
|
+
|
|
5693
|
+
function inspect(obj) {
|
|
5694
|
+
const res = {};
|
|
5695
|
+
for (const key in obj) {
|
|
5696
|
+
res[key] = obj[key].length;
|
|
5697
|
+
}
|
|
5698
|
+
return res;
|
|
5699
|
+
}
|
|
5700
|
+
|
|
5701
|
+
const OriginalHttpsAgent = require$$0__default$5["default"].Agent;
|
|
5702
|
+
const HttpAgent = agent;
|
|
5703
|
+
const {
|
|
5704
|
+
INIT_SOCKET,
|
|
5705
|
+
CREATE_HTTPS_CONNECTION,
|
|
5706
|
+
} = constants;
|
|
5707
|
+
|
|
5708
|
+
class HttpsAgent extends HttpAgent {
|
|
5709
|
+
constructor(options) {
|
|
5710
|
+
super(options);
|
|
5711
|
+
|
|
5712
|
+
this.defaultPort = 443;
|
|
5713
|
+
this.protocol = 'https:';
|
|
5714
|
+
this.maxCachedSessions = this.options.maxCachedSessions;
|
|
5715
|
+
/* istanbul ignore next */
|
|
5716
|
+
if (this.maxCachedSessions === undefined) {
|
|
5717
|
+
this.maxCachedSessions = 100;
|
|
5718
|
+
}
|
|
5719
|
+
|
|
5720
|
+
this._sessionCache = {
|
|
5721
|
+
map: {},
|
|
5722
|
+
list: [],
|
|
5723
|
+
};
|
|
5724
|
+
}
|
|
5725
|
+
|
|
5726
|
+
createConnection(options) {
|
|
5727
|
+
const socket = this[CREATE_HTTPS_CONNECTION](options);
|
|
5728
|
+
this[INIT_SOCKET](socket, options);
|
|
5729
|
+
return socket;
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
|
|
5733
|
+
// https://github.com/nodejs/node/blob/master/lib/https.js#L89
|
|
5734
|
+
HttpsAgent.prototype[CREATE_HTTPS_CONNECTION] = OriginalHttpsAgent.prototype.createConnection;
|
|
5735
|
+
|
|
5736
|
+
[
|
|
5737
|
+
'getName',
|
|
5738
|
+
'_getSession',
|
|
5739
|
+
'_cacheSession',
|
|
5740
|
+
// https://github.com/nodejs/node/pull/4982
|
|
5741
|
+
'_evictSession',
|
|
5742
|
+
].forEach(function(method) {
|
|
5743
|
+
/* istanbul ignore next */
|
|
5744
|
+
if (typeof OriginalHttpsAgent.prototype[method] === 'function') {
|
|
5745
|
+
HttpsAgent.prototype[method] = OriginalHttpsAgent.prototype[method];
|
|
5746
|
+
}
|
|
5747
|
+
});
|
|
5748
|
+
|
|
5749
|
+
var https_agent = HttpsAgent;
|
|
5750
|
+
|
|
5751
|
+
(function (module) {
|
|
5752
|
+
|
|
5753
|
+
module.exports = agent;
|
|
5754
|
+
module.exports.HttpsAgent = https_agent;
|
|
5755
|
+
module.exports.constants = constants;
|
|
5756
|
+
} (agentkeepalive));
|
|
5757
|
+
|
|
5758
|
+
var HttpKeepAliveAgent = /*@__PURE__*/getDefaultExportFromCjs(agentkeepalive.exports);
|
|
5759
|
+
|
|
3335
5760
|
var objToString = Object.prototype.toString;
|
|
3336
5761
|
var objKeys = Object.keys || function(obj) {
|
|
3337
5762
|
var keys = [];
|
|
@@ -3408,55 +5833,6 @@ var fastStableStringify = function(val) {
|
|
|
3408
5833
|
|
|
3409
5834
|
var fastStableStringify$1 = fastStableStringify;
|
|
3410
5835
|
|
|
3411
|
-
const DESTROY_TIMEOUT_MS = 5000;
|
|
3412
|
-
class AgentManager {
|
|
3413
|
-
static _newAgent(useHttps) {
|
|
3414
|
-
const options = {
|
|
3415
|
-
keepAlive: true,
|
|
3416
|
-
maxSockets: 25
|
|
3417
|
-
};
|
|
3418
|
-
|
|
3419
|
-
if (useHttps) {
|
|
3420
|
-
return new https__default["default"].Agent(options);
|
|
3421
|
-
} else {
|
|
3422
|
-
return new http__default["default"].Agent(options);
|
|
3423
|
-
}
|
|
3424
|
-
}
|
|
3425
|
-
|
|
3426
|
-
constructor(useHttps) {
|
|
3427
|
-
this._agent = void 0;
|
|
3428
|
-
this._activeRequests = 0;
|
|
3429
|
-
this._destroyTimeout = null;
|
|
3430
|
-
this._useHttps = void 0;
|
|
3431
|
-
this._useHttps = useHttps === true;
|
|
3432
|
-
this._agent = AgentManager._newAgent(this._useHttps);
|
|
3433
|
-
}
|
|
3434
|
-
|
|
3435
|
-
requestStart() {
|
|
3436
|
-
this._activeRequests++;
|
|
3437
|
-
|
|
3438
|
-
if (this._destroyTimeout !== null) {
|
|
3439
|
-
clearTimeout(this._destroyTimeout);
|
|
3440
|
-
this._destroyTimeout = null;
|
|
3441
|
-
}
|
|
3442
|
-
|
|
3443
|
-
return this._agent;
|
|
3444
|
-
}
|
|
3445
|
-
|
|
3446
|
-
requestEnd() {
|
|
3447
|
-
this._activeRequests--;
|
|
3448
|
-
|
|
3449
|
-
if (this._activeRequests === 0 && this._destroyTimeout === null) {
|
|
3450
|
-
this._destroyTimeout = setTimeout(() => {
|
|
3451
|
-
this._agent.destroy();
|
|
3452
|
-
|
|
3453
|
-
this._agent = AgentManager._newAgent(this._useHttps);
|
|
3454
|
-
}, DESTROY_TIMEOUT_MS);
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
}
|
|
3459
|
-
|
|
3460
5836
|
const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
|
|
3461
5837
|
|
|
3462
5838
|
function trailingZeros(n) {
|
|
@@ -3957,30 +6333,36 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
|
|
|
3957
6333
|
|
|
3958
6334
|
function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent) {
|
|
3959
6335
|
const fetch = customFetch ? customFetch : fetchImpl;
|
|
3960
|
-
let
|
|
6336
|
+
let agent;
|
|
3961
6337
|
|
|
3962
6338
|
{
|
|
3963
6339
|
if (httpAgent == null) {
|
|
3964
6340
|
{
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
6341
|
+
const agentOptions = {
|
|
6342
|
+
// One second fewer than the Solana RPC's keepalive timeout.
|
|
6343
|
+
// Read more: https://github.com/solana-labs/solana/issues/27859#issuecomment-1340097889
|
|
6344
|
+
freeSocketTimeout: 19000,
|
|
6345
|
+
keepAlive: true,
|
|
6346
|
+
maxSockets: 25
|
|
6347
|
+
};
|
|
6348
|
+
|
|
6349
|
+
if (url.startsWith('https:')) {
|
|
6350
|
+
agent = new agentkeepalive.exports.HttpsAgent(agentOptions);
|
|
6351
|
+
} else {
|
|
6352
|
+
agent = new HttpKeepAliveAgent(agentOptions);
|
|
6353
|
+
}
|
|
3968
6354
|
}
|
|
3969
6355
|
} else {
|
|
3970
6356
|
if (httpAgent !== false) {
|
|
3971
6357
|
const isHttps = url.startsWith('https:');
|
|
3972
6358
|
|
|
3973
|
-
if (isHttps && !(httpAgent instanceof
|
|
6359
|
+
if (isHttps && !(httpAgent instanceof require$$0$5.Agent)) {
|
|
3974
6360
|
throw new Error('The endpoint `' + url + '` can only be paired with an `https.Agent`. You have, instead, supplied an ' + '`http.Agent` through `httpAgent`.');
|
|
3975
|
-
} else if (!isHttps && httpAgent instanceof
|
|
6361
|
+
} else if (!isHttps && httpAgent instanceof require$$0$5.Agent) {
|
|
3976
6362
|
throw new Error('The endpoint `' + url + '` can only be paired with an `http.Agent`. You have, instead, supplied an ' + '`https.Agent` through `httpAgent`.');
|
|
3977
6363
|
}
|
|
3978
6364
|
|
|
3979
|
-
|
|
3980
|
-
requestEnd() {},
|
|
3981
|
-
|
|
3982
|
-
requestStart: () => httpAgent
|
|
3983
|
-
};
|
|
6365
|
+
agent = httpAgent;
|
|
3984
6366
|
}
|
|
3985
6367
|
}
|
|
3986
6368
|
}
|
|
@@ -4001,7 +6383,6 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
4001
6383
|
}
|
|
4002
6384
|
|
|
4003
6385
|
const clientBrowser = new RpcClient__default["default"](async (request, callback) => {
|
|
4004
|
-
const agent = agentManager ? agentManager.requestStart() : undefined;
|
|
4005
6386
|
const options = {
|
|
4006
6387
|
method: 'POST',
|
|
4007
6388
|
body: request,
|
|
@@ -4053,8 +6434,6 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
4053
6434
|
}
|
|
4054
6435
|
} catch (err) {
|
|
4055
6436
|
if (err instanceof Error) callback(err);
|
|
4056
|
-
} finally {
|
|
4057
|
-
agentManager && agentManager.requestEnd();
|
|
4058
6437
|
}
|
|
4059
6438
|
}, {});
|
|
4060
6439
|
return clientBrowser;
|