@e-mc/request 0.5.4 → 0.5.6

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Mile Square Park
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
@@ -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();
@@ -186,7 +187,7 @@ class HttpHost {
186
187
  break;
187
188
  }
188
189
  const address = match[1] || hostname;
189
- const ma = +(/ma=(\d+)/.exec(match[3])?.[1] || 86400);
190
+ const ma = +(((_e = /ma=(\d+)/.exec(match[3])) === null || _e === void 0 ? void 0 : _e[1]) || 86400);
190
191
  if (!this[kAltSvcError].includes(`h${i + 1}:${address}:${port}`)) {
191
192
  addresses.push([
192
193
  address,
package/index.js CHANGED
@@ -263,6 +263,7 @@ class Request extends module_1.default {
263
263
  return parent ? super.purgeMemory(percent, limit) : Promise.resolve(0);
264
264
  }
265
265
  static loadSettings(settings, password) {
266
+ var _l;
266
267
  if (!this.enabled("process.password") || super.loadSettings({ process: settings.process }, password)) {
267
268
  const { request, download } = settings;
268
269
  if (download && (0, types_1.isPlainObject)(download.aria2)) {
@@ -374,7 +375,7 @@ class Request extends module_1.default {
374
375
  [TLS.TEXT, TLS.FILE] = validateCerts(certs);
375
376
  }
376
377
  HTTP.PROXY = getProxySettings(request, agent_timeout);
377
- const time_format = request.settings?.time_format;
378
+ const time_format = (_l = request.settings) === null || _l === void 0 ? void 0 : _l.time_format;
378
379
  switch (time_format) {
379
380
  case 'readable':
380
381
  case 'relative':
@@ -579,6 +580,7 @@ class Request extends module_1.default {
579
580
  return ARIA2.BIN;
580
581
  }
581
582
  constructor(data) {
583
+ var _l;
582
584
  super();
583
585
  this.startTime = Date.now();
584
586
  this.readExpect = 'none';
@@ -608,16 +610,16 @@ class Request extends module_1.default {
608
610
  const timeout = (0, util_1.fromSeconds)(data.timeout);
609
611
  let value;
610
612
  this.readTimeout = (value = (0, util_1.fromSeconds)(read_timeout)) >= 0 ? value : READ_TIMEOUT;
611
- this.keepAlive = typeof (value = agent?.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
612
- this.acceptEncoding = typeof (value = use?.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
613
- switch (value = (0, util_1.asInt)(use?.http_version)) {
613
+ this.keepAlive = typeof (value = agent === null || agent === void 0 ? void 0 : agent.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
614
+ this.acceptEncoding = typeof (value = use === null || use === void 0 ? void 0 : use.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
615
+ switch (value = (0, util_1.asInt)(use === null || use === void 0 ? void 0 : use.http_version)) {
614
616
  case 1:
615
617
  case 2:
616
618
  this[kHttpVersion] = value;
617
619
  break;
618
620
  }
619
- this[kIpVersion] = (value = (0, util_1.asInt)(data.dns?.family)) && (value === 4 || value === 6) ? value : 0;
620
- if ((value = (0, util_1.fromSeconds)(agent?.timeout)) >= 0) {
621
+ this[kIpVersion] = (value = (0, util_1.asInt)((_l = data.dns) === null || _l === void 0 ? void 0 : _l.family)) && (value === 4 || value === 6) ? value : 0;
622
+ if ((value = (0, util_1.fromSeconds)(agent === null || agent === void 0 ? void 0 : agent.timeout)) >= 0) {
621
623
  this[kAgentTimeout] = value;
622
624
  }
623
625
  else {
@@ -659,6 +661,7 @@ class Request extends module_1.default {
659
661
  this.module = data;
660
662
  }
661
663
  flushLog() {
664
+ var _l;
662
665
  if (this[kSingleton]) {
663
666
  this._logQueued.length = 0;
664
667
  if (LOG_HTTP) {
@@ -690,7 +693,7 @@ class Request extends module_1.default {
690
693
  count = Math.max(count, value);
691
694
  }
692
695
  });
693
- if (!this.host?.aborted) {
696
+ if (!((_l = this.host) === null || _l === void 0 ? void 0 : _l.aborted)) {
694
697
  output.sort((a, b) => {
695
698
  if (a[2] === b[2]) {
696
699
  return a[1] < b[1] ? -1 : 1;
@@ -990,8 +993,9 @@ class Request extends module_1.default {
990
993
  if (!module_1.default.createDir(pathname)) {
991
994
  return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
992
995
  }
993
- silent ?? (silent = this[kSingleton]);
996
+ silent !== null && silent !== void 0 ? silent : (silent = this[kSingleton]);
994
997
  return new Promise((resolve, reject) => {
998
+ var _l;
995
999
  let protocol, origin, username, password;
996
1000
  if (uri instanceof URL) {
997
1001
  ({ protocol, origin, username, password, href: uri } = uri);
@@ -1049,7 +1053,7 @@ class Request extends module_1.default {
1049
1053
  '--file-allocation=' + ARIA2.FILE_ALLOCATION,
1050
1054
  '--max-tries=' + (retryLimit + 1)
1051
1055
  ];
1052
- const ignoreOpt = (...values) => !binOpts?.some(item => values.includes(item));
1056
+ const ignoreOpt = (...values) => !(binOpts === null || binOpts === void 0 ? void 0 : binOpts.some(item => values.includes(item)));
1053
1057
  if (ARIA2.MAX_CONCURRENT_DOWNLOADS) {
1054
1058
  opts.push('--max-concurrent-downloads=' + ARIA2.MAX_CONCURRENT_DOWNLOADS);
1055
1059
  }
@@ -1098,7 +1102,7 @@ class Request extends module_1.default {
1098
1102
  }
1099
1103
  }
1100
1104
  if (origin) {
1101
- const secure = this[kCerts]?.[1][origin] || (this.host ? TLS.FILE[origin] : null);
1105
+ const secure = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[1][origin]) || (this.host ? TLS.FILE[origin] : null);
1102
1106
  if (secure) {
1103
1107
  if (secure.ca && ignoreOpt('--ca-certificate')) {
1104
1108
  args.push(`--ca-certificate="${escapeQuote(secure.ca)}"`);
@@ -1243,7 +1247,7 @@ class Request extends module_1.default {
1243
1247
  }
1244
1248
  else {
1245
1249
  const current = (0, types_1.getLogCurrent)();
1246
- progressBar = current?.type === 128 && current.title === "aria2";
1250
+ progressBar = (current === null || current === void 0 ? void 0 : current.type) === 128 && current.title === "aria2";
1247
1251
  }
1248
1252
  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 });
1249
1253
  }
@@ -1282,7 +1286,8 @@ class Request extends module_1.default {
1282
1286
  return { ...options, host, url };
1283
1287
  }
1284
1288
  open(uri, options) {
1285
- var _l, _m;
1289
+ var _l;
1290
+ var _m, _o;
1286
1291
  let { host, url, httpVersion, method = 'GET', encoding, format, headers, postData, keepAlive, agentTimeout, socketPath, timeout = this._config.connectTimeout, outStream } = options;
1287
1292
  const getting = method === 'GET';
1288
1293
  const posting = method === 'POST';
@@ -1337,7 +1342,7 @@ class Request extends module_1.default {
1337
1342
  case 204:
1338
1343
  return;
1339
1344
  }
1340
- const chunkSize = outStream?.writableHighWaterMark;
1345
+ const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
1341
1346
  let pipeTo;
1342
1347
  switch (contentEncoding.trim().toLowerCase()) {
1343
1348
  case 'gzip':
@@ -1367,17 +1372,17 @@ class Request extends module_1.default {
1367
1372
  const pathname = url.pathname + (socketPath ? '' : url.search);
1368
1373
  const proxy = this.proxyOf(uri, host.localhost);
1369
1374
  let request, ca, cert, key, minVersion, baseHeaders = this.headersOf(uri);
1370
- if (getting && this.acceptEncoding && !host.localhost && !baseHeaders?.['accept-encoding']) {
1371
- (_l = (headers || (headers = {})))['accept-encoding'] || (_l['accept-encoding'] = 'gzip, deflate, br');
1375
+ if (getting && this.acceptEncoding && !host.localhost && !(baseHeaders === null || baseHeaders === void 0 ? void 0 : baseHeaders['accept-encoding'])) {
1376
+ (_m = (headers || (headers = {})))['accept-encoding'] || (_m['accept-encoding'] = 'gzip, deflate, br');
1372
1377
  }
1373
1378
  if (host.secure) {
1374
- const secure = this[kCerts]?.[0][origin] || (this.host ? TLS.TEXT[origin] : null);
1379
+ const secure = ((_l = this[kCerts]) === null || _l === void 0 ? void 0 : _l[0][origin]) || (this.host ? TLS.TEXT[origin] : null);
1375
1380
  if (secure) {
1376
1381
  ({ ca, cert, key, version: minVersion } = secure);
1377
1382
  }
1378
1383
  }
1379
1384
  if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && this.httpVersion !== 1 || host.secure && this.httpVersion === 2 && host.failed(2, true) === 0)) {
1380
- request = ((_m = this[kSession][0])[origin] || (_m[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1385
+ request = ((_o = this[kSession][0])[origin] || (_o[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1381
1386
  if (getting) {
1382
1387
  const listenerMap = {};
1383
1388
  const onEvent = request.on.bind(request);
@@ -1460,8 +1465,8 @@ class Request extends module_1.default {
1460
1465
  const pkg = host.secure ? 'https-proxy-agent' : 'http-proxy-agent';
1461
1466
  try {
1462
1467
  const { protocol, hostname: proxyname, port, username, password, href } = proxy.host;
1463
- keepAlive ?? (keepAlive = proxy.keepAlive || false);
1464
- agentTimeout ?? (agentTimeout = proxy.agentTimeout);
1468
+ keepAlive !== null && keepAlive !== void 0 ? keepAlive : (keepAlive = proxy.keepAlive || false);
1469
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = proxy.agentTimeout);
1465
1470
  agent = require(pkg)(keepAlive || agentTimeout > 0 ? { protocol, hostname: proxyname, port, username, password, keepAlive, timeout: agentTimeout } : href);
1466
1471
  const proxyHeaders = this[kHeaders] && getBaseHeaders(href, this[kHeaders]) || getBaseHeaders(href, HTTP.HEADERS);
1467
1472
  if (proxyHeaders) {
@@ -1480,7 +1485,7 @@ class Request extends module_1.default {
1480
1485
  }
1481
1486
  else if (agentTimeout !== 0) {
1482
1487
  keepAlive = this.keepAlive || false;
1483
- agentTimeout ?? (agentTimeout = this.agentTimeout);
1488
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = this.agentTimeout);
1484
1489
  if (keepAlive || agentTimeout > 0) {
1485
1490
  agent = new (host.secure ? https.Agent : http.Agent)({ keepAlive, timeout: agentTimeout });
1486
1491
  }
@@ -1734,7 +1739,7 @@ class Request extends module_1.default {
1734
1739
  async get(uri, options = {}) {
1735
1740
  const opts = (typeof options === 'string' ? { format: options, encoding: 'utf-8' } : options);
1736
1741
  if (this.readExpect === 'string') {
1737
- opts.encoding = (0, types_1.getEncoding)(opts?.encoding);
1742
+ opts.encoding = (0, types_1.getEncoding)(opts === null || opts === void 0 ? void 0 : opts.encoding);
1738
1743
  }
1739
1744
  return new Promise((resolve, reject) => {
1740
1745
  const { silent = this[kSingleton], pipeTo } = opts;
@@ -1808,18 +1813,20 @@ class Request extends module_1.default {
1808
1813
  downloadUri.call(this, href);
1809
1814
  };
1810
1815
  const acceptResponse = (headers) => {
1816
+ var _l;
1811
1817
  if ('outHeaders' in opts) {
1812
1818
  opts.outHeaders = headers;
1813
1819
  }
1814
1820
  if ('outFilename' in opts) {
1815
1821
  opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
1816
1822
  }
1817
- const buffering = request.connected?.call(client, headers);
1823
+ const buffering = (_l = request.connected) === null || _l === void 0 ? void 0 : _l.call(client, headers);
1818
1824
  const pipeline = pipeTo ? !(0, types_1.isString)(pipeTo) : false;
1819
1825
  const enabled = buffering !== false && !pipeline;
1820
1826
  let mibsTime, delayTime;
1821
1827
  if (log || this.readTimeout > 0) {
1822
1828
  client.once('readable', () => {
1829
+ var _l;
1823
1830
  if (this.readTimeout > 0) {
1824
1831
  timeout = setTimeout(() => {
1825
1832
  abortResponse();
@@ -1830,7 +1837,7 @@ class Request extends module_1.default {
1830
1837
  if (buffering === false) {
1831
1838
  mibsTime = process.hrtime();
1832
1839
  }
1833
- switch (this.settings?.time_format || LOG_TIMEFORMAT) {
1840
+ switch (((_l = this.settings) === null || _l === void 0 ? void 0 : _l.time_format) || LOG_TIMEFORMAT) {
1834
1841
  case 'readable':
1835
1842
  delayTime = process.hrtime(startTime);
1836
1843
  break;
@@ -2157,13 +2164,14 @@ class Request extends module_1.default {
2157
2164
  this[kDownloading].clear();
2158
2165
  }
2159
2166
  set agentTimeout(value) {
2167
+ var _l, _m;
2160
2168
  if (value > 0) {
2161
2169
  this[kAgentTimeout] = value;
2162
- this.keepAlive ?? (this.keepAlive = true);
2170
+ (_l = this.keepAlive) !== null && _l !== void 0 ? _l : (this.keepAlive = true);
2163
2171
  }
2164
2172
  else {
2165
2173
  this[kAgentTimeout] = 0;
2166
- this.keepAlive ?? (this.keepAlive = false);
2174
+ (_m = this.keepAlive) !== null && _m !== void 0 ? _m : (this.keepAlive = false);
2167
2175
  }
2168
2176
  }
2169
2177
  get agentTimeout() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
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.5.4",
24
- "@e-mc/types": "0.5.4",
23
+ "@e-mc/module": "0.5.6",
24
+ "@e-mc/types": "0.5.6",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "which": "^2.0.2"