@e-mc/request 0.6.2 → 0.6.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.
@@ -154,6 +154,7 @@ class HttpHost {
154
154
  return ++data[2];
155
155
  }
156
156
  upgrade(version, altSvc) {
157
+ var _e;
157
158
  if (altSvc && this.secure) {
158
159
  if (altSvc === 'clear') {
159
160
  this.clearAltSvc();
@@ -187,7 +188,7 @@ class HttpHost {
187
188
  break;
188
189
  }
189
190
  const address = match[1] || hostname;
190
- const ma = +(/ma=(\d+)/.exec(match[3])?.[1] || 86400);
191
+ const ma = +(((_e = /ma=(\d+)/.exec(match[3])) === null || _e === void 0 ? void 0 : _e[1]) || 86400);
191
192
  if (!excluded.includes(`h${i + 1}:${address}:${port}`)) {
192
193
  addresses.push([
193
194
  address,
package/index.js CHANGED
@@ -132,7 +132,7 @@ function setOutgoingHeaders(output, headers) {
132
132
  }
133
133
  function getProxySettings(request, agentTimeout) {
134
134
  const proxy = request.proxy;
135
- if (proxy?.address && proxy.port) {
135
+ if ((proxy === null || proxy === void 0 ? void 0 : proxy.address) && proxy.port) {
136
136
  const port = (0, util_1.asInt)(proxy.port);
137
137
  const address = (!module_1.default.isURL(proxy.address) ? port === 80 ? 'http://' : 'https://' : '') + proxy.address;
138
138
  try {
@@ -271,6 +271,7 @@ class Request extends module_1.default {
271
271
  return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
272
272
  }
273
273
  static loadSettings(settings, password) {
274
+ var _l;
274
275
  if (!this.enabled("process.password") || super.loadSettings({ process: settings.process }, password)) {
275
276
  const { request, download } = settings;
276
277
  if (download && (0, types_1.isPlainObject)(download.aria2)) {
@@ -387,7 +388,7 @@ class Request extends module_1.default {
387
388
  [TLS.TEXT, TLS.FILE] = validateCerts(certs);
388
389
  }
389
390
  HTTP.PROXY = getProxySettings(request, agent_timeout);
390
- const time_format = request.settings?.time_format;
391
+ const time_format = (_l = request.settings) === null || _l === void 0 ? void 0 : _l.time_format;
391
392
  switch (time_format) {
392
393
  case 'readable':
393
394
  case 'relative':
@@ -609,6 +610,7 @@ class Request extends module_1.default {
609
610
  return ARIA2.BIN;
610
611
  }
611
612
  constructor(data) {
613
+ var _l;
612
614
  super();
613
615
  this.startTime = Date.now();
614
616
  this.readExpect = 'none';
@@ -638,13 +640,13 @@ class Request extends module_1.default {
638
640
  const timeout = (0, util_1.fromSeconds)(data.timeout);
639
641
  let value;
640
642
  this.readTimeout = (value = (0, util_1.fromSeconds)(read_timeout)) >= 0 ? value : READ_TIMEOUT;
641
- this.keepAlive = typeof (value = agent?.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
642
- this.acceptEncoding = typeof (value = use?.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
643
- if ((value = (0, util_1.asInt)(use?.http_version)) === 1 || value === 2) {
643
+ this.keepAlive = typeof (value = agent === null || agent === void 0 ? void 0 : agent.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
644
+ this.acceptEncoding = typeof (value = use === null || use === void 0 ? void 0 : use.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
645
+ if ((value = (0, util_1.asInt)(use === null || use === void 0 ? void 0 : use.http_version)) === 1 || value === 2) {
644
646
  this[kHttpVersion] = value;
645
647
  }
646
- this[kIpVersion] = (value = (0, util_1.asInt)(data.dns?.family)) && (value === 4 || value === 6) ? value : 0;
647
- if ((value = (0, util_1.fromSeconds)(agent?.timeout)) >= 0) {
648
+ this[kIpVersion] = (value = (0, util_1.asInt)((_l = data.dns) === null || _l === void 0 ? void 0 : _l.family)) && (value === 4 || value === 6) ? value : 0;
649
+ if ((value = (0, util_1.fromSeconds)(agent === null || agent === void 0 ? void 0 : agent.timeout)) >= 0) {
648
650
  this[kAgentTimeout] = value;
649
651
  }
650
652
  else {
@@ -686,6 +688,7 @@ class Request extends module_1.default {
686
688
  this.module = data;
687
689
  }
688
690
  flushLog() {
691
+ var _l;
689
692
  if (this[kSingleton]) {
690
693
  this._logQueued.length = 0;
691
694
  if (LOG_HTTP) {
@@ -717,7 +720,7 @@ class Request extends module_1.default {
717
720
  count = Math.max(count, value);
718
721
  }
719
722
  });
720
- if (!this.host?.aborted) {
723
+ if (!((_l = this.host) === null || _l === void 0 ? void 0 : _l.aborted)) {
721
724
  output.sort((a, b) => {
722
725
  if (a[2] === b[2]) {
723
726
  return a[1] < b[1] ? -1 : 1;
@@ -1016,8 +1019,9 @@ class Request extends module_1.default {
1016
1019
  if (!module_1.default.createDir(pathname)) {
1017
1020
  return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
1018
1021
  }
1019
- silent ?? (silent = this[kSingleton]);
1022
+ silent !== null && silent !== void 0 ? silent : (silent = this[kSingleton]);
1020
1023
  return new Promise((resolve, reject) => {
1024
+ var _l;
1021
1025
  let protocol, origin, username, password;
1022
1026
  if (uri instanceof URL) {
1023
1027
  ({ protocol, origin, username, password, href: uri } = uri);
@@ -1075,7 +1079,7 @@ class Request extends module_1.default {
1075
1079
  '--file-allocation=' + ARIA2.FILE_ALLOCATION,
1076
1080
  '--max-tries=' + (retryLimit + 1)
1077
1081
  ];
1078
- const ignoreOpt = (...values) => !binOpts?.some(item => values.includes(item));
1082
+ const ignoreOpt = (...values) => !(binOpts === null || binOpts === void 0 ? void 0 : binOpts.some(item => values.includes(item)));
1079
1083
  if (ARIA2.MAX_CONCURRENT_DOWNLOADS) {
1080
1084
  opts.push('--max-concurrent-downloads=' + ARIA2.MAX_CONCURRENT_DOWNLOADS);
1081
1085
  }
@@ -1124,7 +1128,7 @@ class Request extends module_1.default {
1124
1128
  }
1125
1129
  }
1126
1130
  if (origin) {
1127
- const secure = this[kCerts]?.[1][origin] || (this.host ? TLS.FILE[origin] : null);
1131
+ const secure = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[1][origin]) || (this.host ? TLS.FILE[origin] : null);
1128
1132
  if (secure) {
1129
1133
  if (secure.ca && ignoreOpt('--ca-certificate')) {
1130
1134
  args.push(`--ca-certificate="${escapeQuote(secure.ca)}"`);
@@ -1269,7 +1273,7 @@ class Request extends module_1.default {
1269
1273
  }
1270
1274
  else {
1271
1275
  const current = (0, types_1.getLogCurrent)();
1272
- progressBar = current?.type === 128 && current.title === "aria2";
1276
+ progressBar = (current === null || current === void 0 ? void 0 : current.type) === 128 && current.title === "aria2";
1273
1277
  }
1274
1278
  this.formatMessage(128, "aria2", ['Downloading...', (0, types_1.formatTime)(startTime, true)], (PLATFORM_WIN32 ? 'taskkill /f /pid' : 'kill') + ` ${item[0]} -> ` + item[1], { ...module_1.default.LOG_STYLE_INFO, progressBar, broadcastId });
1275
1279
  }
@@ -1308,7 +1312,8 @@ class Request extends module_1.default {
1308
1312
  return { ...options, host, url };
1309
1313
  }
1310
1314
  open(uri, options) {
1311
- var _l, _m;
1315
+ var _l;
1316
+ var _m, _o;
1312
1317
  let { host, url, httpVersion, method = 'GET', encoding, format, headers, postData, keepAlive, agentTimeout, socketPath, timeout = this._config.connectTimeout, outStream } = options;
1313
1318
  const getting = method === 'GET';
1314
1319
  const posting = method === 'POST';
@@ -1363,7 +1368,7 @@ class Request extends module_1.default {
1363
1368
  case 204:
1364
1369
  return;
1365
1370
  }
1366
- const chunkSize = outStream?.writableHighWaterMark;
1371
+ const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
1367
1372
  let pipeTo;
1368
1373
  switch (contentEncoding.trim().toLowerCase()) {
1369
1374
  case 'gzip':
@@ -1399,17 +1404,17 @@ class Request extends module_1.default {
1399
1404
  const proxy = this.proxyOf(uri, localhost);
1400
1405
  const version = this.httpVersion;
1401
1406
  let request, ca, cert, key, minVersion, baseHeaders = this.headersOf(uri);
1402
- if (getting && this.acceptEncoding && !localhost && !baseHeaders?.['accept-encoding']) {
1403
- (_l = (headers || (headers = {})))['accept-encoding'] || (_l['accept-encoding'] = 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : ''));
1407
+ if (getting && this.acceptEncoding && !localhost && !(baseHeaders === null || baseHeaders === void 0 ? void 0 : baseHeaders['accept-encoding'])) {
1408
+ (_m = (headers || (headers = {})))['accept-encoding'] || (_m['accept-encoding'] = 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : ''));
1404
1409
  }
1405
1410
  if (secure) {
1406
- const certs = this[kCerts]?.[0][origin] || (this.host ? TLS.TEXT[origin] : null);
1411
+ const certs = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[0][origin]) || (this.host ? TLS.TEXT[origin] : null);
1407
1412
  if (certs) {
1408
1413
  ({ ca, cert, key, version: minVersion } = certs);
1409
1414
  }
1410
1415
  }
1411
1416
  if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
1412
- request = ((_m = this[kSession][0])[origin] || (_m[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1417
+ request = ((_o = this[kSession][0])[origin] || (_o[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1413
1418
  if (getting) {
1414
1419
  const listenerMap = {};
1415
1420
  const onEvent = request.on.bind(request);
@@ -1492,8 +1497,8 @@ class Request extends module_1.default {
1492
1497
  const pkg = secure ? 'https-proxy-agent' : 'http-proxy-agent';
1493
1498
  try {
1494
1499
  const { protocol, hostname: proxyname, port, username, password, href } = proxy.host;
1495
- keepAlive ?? (keepAlive = proxy.keepAlive || false);
1496
- agentTimeout ?? (agentTimeout = proxy.agentTimeout);
1500
+ keepAlive !== null && keepAlive !== void 0 ? keepAlive : (keepAlive = proxy.keepAlive || false);
1501
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = proxy.agentTimeout);
1497
1502
  agent = require(pkg)(keepAlive || agentTimeout > 0 ? { protocol, hostname: proxyname, port, username, password, keepAlive, timeout: agentTimeout } : href);
1498
1503
  const proxyHeaders = this[kHeaders] && getBaseHeaders(href, this[kHeaders]) || getBaseHeaders(href, HTTP.HEADERS);
1499
1504
  if (proxyHeaders) {
@@ -1512,7 +1517,7 @@ class Request extends module_1.default {
1512
1517
  }
1513
1518
  else if (agentTimeout !== 0) {
1514
1519
  keepAlive = this.keepAlive || false;
1515
- agentTimeout ?? (agentTimeout = this.agentTimeout);
1520
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = this.agentTimeout);
1516
1521
  if (keepAlive || agentTimeout > 0) {
1517
1522
  agent = new (secure ? https.Agent : http.Agent)({ keepAlive, timeout: agentTimeout });
1518
1523
  }
@@ -1536,6 +1541,7 @@ class Request extends module_1.default {
1536
1541
  lookup: this.lookupDns(hostname),
1537
1542
  agent
1538
1543
  }, response => {
1544
+ var _l;
1539
1545
  const statusCode = response.statusCode;
1540
1546
  if ((getting || posting) && statusCode >= 200 && statusCode < 300) {
1541
1547
  const incoming = response.headers;
@@ -1571,7 +1577,7 @@ class Request extends module_1.default {
1571
1577
  source.on('error', err => request.emit('error', err));
1572
1578
  }
1573
1579
  if (!posting) {
1574
- if (version === 2 && incoming.upgrade?.includes('h2')) {
1580
+ if (version === 2 && ((_l = incoming.upgrade) === null || _l === void 0 ? void 0 : _l.includes('h2'))) {
1575
1581
  host.version = 2;
1576
1582
  }
1577
1583
  else if (!host.didAltSvc(1)) {
@@ -1769,7 +1775,7 @@ class Request extends module_1.default {
1769
1775
  async get(uri, options = {}) {
1770
1776
  const opts = (typeof options === 'string' ? { format: options, encoding: 'utf-8' } : options);
1771
1777
  if (this.readExpect === 'string') {
1772
- opts.encoding = (0, types_1.getEncoding)(opts?.encoding);
1778
+ opts.encoding = (0, types_1.getEncoding)(opts === null || opts === void 0 ? void 0 : opts.encoding);
1773
1779
  }
1774
1780
  return new Promise((resolve, reject) => {
1775
1781
  const { silent = this[kSingleton], pipeTo } = opts;
@@ -1843,19 +1849,21 @@ class Request extends module_1.default {
1843
1849
  downloadUri.call(this, href);
1844
1850
  };
1845
1851
  const acceptResponse = (headers) => {
1852
+ var _l;
1846
1853
  if ('outHeaders' in opts) {
1847
1854
  opts.outHeaders = headers;
1848
1855
  }
1849
1856
  if ('outFilename' in opts) {
1850
1857
  opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
1851
1858
  }
1852
- const buffering = request.connected?.call(client, headers);
1859
+ const buffering = (_l = request.connected) === null || _l === void 0 ? void 0 : _l.call(client, headers);
1853
1860
  const pipeline = pipeTo ? !(0, types_1.isString)(pipeTo) : false;
1854
1861
  const enabled = buffering !== false && !pipeline;
1855
1862
  const readTimeout = this.readTimeout;
1856
1863
  let mibsTime, delayTime;
1857
1864
  if (log || readTimeout > 0) {
1858
1865
  client.once('readable', () => {
1866
+ var _l;
1859
1867
  if (readTimeout > 0) {
1860
1868
  timeout = setTimeout(() => {
1861
1869
  abortResponse();
@@ -1866,7 +1874,7 @@ class Request extends module_1.default {
1866
1874
  if (buffering === false) {
1867
1875
  mibsTime = process.hrtime();
1868
1876
  }
1869
- switch (this.settings?.time_format || LOG_TIMEFORMAT) {
1877
+ switch (((_l = this.settings) === null || _l === void 0 ? void 0 : _l.time_format) || LOG_TIMEFORMAT) {
1870
1878
  case 'readable':
1871
1879
  delayTime = process.hrtime(startTime);
1872
1880
  break;
@@ -2193,13 +2201,14 @@ class Request extends module_1.default {
2193
2201
  this[kDownloading].clear();
2194
2202
  }
2195
2203
  set agentTimeout(value) {
2204
+ var _l, _m;
2196
2205
  if (value > 0) {
2197
2206
  this[kAgentTimeout] = value;
2198
- this.keepAlive ?? (this.keepAlive = true);
2207
+ (_l = this.keepAlive) !== null && _l !== void 0 ? _l : (this.keepAlive = true);
2199
2208
  }
2200
2209
  else {
2201
2210
  this[kAgentTimeout] = 0;
2202
- this.keepAlive ?? (this.keepAlive = false);
2211
+ (_m = this.keepAlive) !== null && _m !== void 0 ? _m : (this.keepAlive = false);
2203
2212
  }
2204
2213
  }
2205
2214
  get agentTimeout() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.6.2",
24
- "@e-mc/types": "0.6.2",
23
+ "@e-mc/module": "0.6.3",
24
+ "@e-mc/types": "0.6.3",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "which": "^2.0.2"