@solana/web3.js 1.70.1 → 1.70.3

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