@e-mc/request 0.6.0 → 0.6.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Studio Trigger
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ### @e-mc/request
1
+ # @e-mc/request
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Ryuko
4
4
 
5
- BSD 3-Clause
5
+ ## LICENSE
6
+
7
+ MIT
@@ -1,5 +1,5 @@
1
- import type { HttpHostConstructor } from '../../../types/lib/request';
2
-
3
- declare const HttpHost: HttpHostConstructor;
4
-
1
+ import type { HttpHostConstructor } from '../../../types/lib/request';
2
+
3
+ declare const HttpHost: HttpHostConstructor;
4
+
5
5
  export = HttpHost;
@@ -2,7 +2,7 @@
2
2
  var _a, _b, _c, _d;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tls = require("tls");
5
- const types_1 = require("../../../types");
5
+ const types_1 = require("@e-mc/types");
6
6
  const kProtocol = Symbol('protocol');
7
7
  const kSecure = Symbol('secure');
8
8
  const kHostname = Symbol('hostname');
@@ -85,15 +85,15 @@ class HttpHost {
85
85
  }
86
86
  }
87
87
  this[kVersion] = 1;
88
- this[kVersionData].forEach(version => version[4 /* HOST_VERSION.ALT_SVC */] = 0);
88
+ this[kVersionData].forEach(version => version[4] = 0);
89
89
  }
90
90
  async hasProtocol(version) {
91
91
  if (version > 1) {
92
92
  const data = this[kVersionData][version - 1];
93
93
  if (!data || !this.secure) {
94
- return 0 /* QUERY_RESULT.FAIL */;
94
+ return 0;
95
95
  }
96
- const status = data[3 /* HOST_VERSION.ALPN */];
96
+ const status = data[3];
97
97
  switch (status) {
98
98
  case 0:
99
99
  case 1:
@@ -102,19 +102,19 @@ class HttpHost {
102
102
  return this._tlsConnect || (this._tlsConnect = new Promise(resolve => {
103
103
  const alpn = 'h' + version;
104
104
  const socket = tls.connect(+this.port, this.hostname, { ALPNProtocols: [alpn], requestCert: true, rejectUnauthorized: false }, () => {
105
- resolve(data[3 /* HOST_VERSION.ALPN */] = alpn === socket.alpnProtocol ? 1 /* QUERY_RESULT.OK */ : 0 /* QUERY_RESULT.FAIL */);
105
+ resolve(data[3] = alpn === socket.alpnProtocol ? 1 : 0);
106
106
  this._tlsConnect = null;
107
107
  });
108
108
  socket
109
109
  .setNoDelay(false)
110
- .setTimeout(10000 /* HOST.TIMEOUT */)
110
+ .setTimeout(10000)
111
111
  .on('timeout', () => {
112
112
  if (this._tlsConnect) {
113
- if (this.error(version) >= 10 /* HOST.MAX_ERROR */) {
114
- resolve(data[3 /* HOST_VERSION.ALPN */] = 0 /* QUERY_RESULT.FAIL */);
113
+ if (this.error(version) >= 10) {
114
+ resolve(data[3] = 0);
115
115
  }
116
116
  else {
117
- resolve(2 /* QUERY_RESULT.TIMEOUT */);
117
+ resolve(2);
118
118
  }
119
119
  this._tlsConnect = null;
120
120
  }
@@ -122,36 +122,36 @@ class HttpHost {
122
122
  })
123
123
  .on('error', () => {
124
124
  this.failed(version);
125
- resolve(data[3 /* HOST_VERSION.ALPN */] = 0 /* QUERY_RESULT.FAIL */);
125
+ resolve(data[3] = 0);
126
126
  this._tlsConnect = null;
127
127
  })
128
128
  .end();
129
129
  }));
130
130
  }
131
131
  }
132
- return 1 /* QUERY_RESULT.OK */;
132
+ return 1;
133
133
  }
134
134
  success(version, status) {
135
135
  const data = this[kVersionData][version - 1];
136
- return status ? data[0 /* HOST_VERSION.SUCCESS */] : ++data[0 /* HOST_VERSION.SUCCESS */];
136
+ return status ? data[0] : ++data[0];
137
137
  }
138
138
  failed(version, status) {
139
139
  const data = this[kVersionData][version - 1];
140
140
  if (status) {
141
- return data[1 /* HOST_VERSION.FAILED */];
141
+ return data[1];
142
142
  }
143
143
  this.clearAltSvc(version);
144
- return ++data[1 /* HOST_VERSION.FAILED */];
144
+ return ++data[1];
145
145
  }
146
146
  error(version, status) {
147
147
  const data = this[kVersionData][version - 1];
148
148
  if (status) {
149
- return data[2 /* HOST_VERSION.ERROR */];
149
+ return data[2];
150
150
  }
151
- if (data[4 /* HOST_VERSION.ALT_SVC */] !== 2) {
151
+ if (data[4] !== 2) {
152
152
  this.closeAltSvc(true);
153
153
  }
154
- return ++data[2 /* HOST_VERSION.ERROR */];
154
+ return ++data[2];
155
155
  }
156
156
  upgrade(version, altSvc) {
157
157
  if (altSvc && this.secure) {
@@ -162,11 +162,11 @@ class HttpHost {
162
162
  const data = this[kVersionData];
163
163
  for (let i = data.length - 1; i >= version; --i) {
164
164
  const host = data[i];
165
- if (host[4 /* HOST_VERSION.ALT_SVC */] === 0) {
165
+ if (host[4] === 0) {
166
166
  continue;
167
167
  }
168
168
  const increment = (flag) => {
169
- host[4 /* HOST_VERSION.ALT_SVC */] = flag;
169
+ host[4] = flag;
170
170
  if (this[kVersion] < i + 1) {
171
171
  this[kVersion] = i + 1;
172
172
  return true;
@@ -192,7 +192,7 @@ class HttpHost {
192
192
  addresses.push([
193
193
  address,
194
194
  port,
195
- ma >= 2592000 /* TIMEOUT.MA */ ? NaN : time + Math.min(ma * 1000 /* TIME.S */, 2147483647 /* TIMEOUT.LIMIT */),
195
+ ma >= 2592000 ? NaN : time + Math.min(ma * 1000, 2147483647),
196
196
  i + 1,
197
197
  match[3].includes('persist=1')
198
198
  ]);
@@ -229,7 +229,7 @@ class HttpHost {
229
229
  }
230
230
  }
231
231
  didAltSvc(version) {
232
- return this[kVersionData][version][4 /* HOST_VERSION.ALT_SVC */] !== -1;
232
+ return this[kVersionData][version][4] !== -1;
233
233
  }
234
234
  nextAltSvc() {
235
235
  const queue = this[kAltSvcQueue].shift();
@@ -279,20 +279,20 @@ class HttpHost {
279
279
  this.closeAltSvc();
280
280
  this[kAltSvcQueue] = [];
281
281
  this[kAltSvcError] = [];
282
- this[kVersionData].forEach(item => item[3 /* HOST_VERSION.ALPN */] && (item[4 /* HOST_VERSION.ALT_SVC */] = -1));
282
+ this[kVersionData].forEach(item => item[3] && (item[4] = -1));
283
283
  }
284
284
  }
285
285
  flagAltSvc(version, value) {
286
- this[kVersionData][version - 1][4 /* HOST_VERSION.ALT_SVC */] = value;
286
+ this[kVersionData][version - 1][4] = value;
287
287
  }
288
288
  reset() {
289
289
  this.clearAltSvc();
290
290
  this[kVersionData].forEach((item, index) => {
291
- item[0 /* HOST_VERSION.SUCCESS */] = 0;
292
- item[1 /* HOST_VERSION.FAILED */] = 0;
293
- item[2 /* HOST_VERSION.ERROR */] = 0;
291
+ item[0] = 0;
292
+ item[1] = 0;
293
+ item[2] = 0;
294
294
  if (index > 0) {
295
- item[3 /* HOST_VERSION.ALPN */] = -1;
295
+ item[3] = -1;
296
296
  }
297
297
  });
298
298
  }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { RequestConstructor } from '../types/lib';
2
-
3
- declare const Request: RequestConstructor;
4
-
1
+ import type { RequestConstructor } from '../types/lib';
2
+
3
+ declare const Request: RequestConstructor;
4
+
5
5
  export = Request;
package/index.js CHANGED
@@ -15,11 +15,11 @@ const qs = require("querystring");
15
15
  const combined = require("combined-stream");
16
16
  const yaml = require("js-yaml");
17
17
  const which = require("which");
18
- const lib_v4_1 = require("../module/lib-v4");
19
- const types_1 = require("../types");
20
- const module_1 = require("../module");
21
- const host_1 = require("./http/host");
22
- const util_1 = require("./util");
18
+ const lib_v4_1 = require("@e-mc/module/lib-v4");
19
+ const types_1 = require("@e-mc/types");
20
+ const module_1 = require("@e-mc/module");
21
+ const host_1 = require("@e-mc/request/http/host");
22
+ const util_1 = require("@e-mc/request/util");
23
23
  const kSession = Symbol('session');
24
24
  const kHttpVersion = Symbol('httpVersion');
25
25
  const kIpVersion = Symbol('ipVersion');
@@ -176,7 +176,7 @@ function resetHttpHost(version) {
176
176
  const host = HTTP.HOST[origin];
177
177
  if (host.secure && host.version === 1) {
178
178
  const failed = host.failed(2, true);
179
- if (failed === 0 && host.failed(2, true) < 10 /* HOST.MAX_ERROR */ || failed < 3 /* HOST.MAX_FAILED */ && host.success(2, true) > 0) {
179
+ if (failed === 0 && host.failed(2, true) < 10 || failed < 3 && host.success(2, true) > 0) {
180
180
  host.version = version;
181
181
  }
182
182
  }
@@ -271,7 +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
- if (!this.enabled("process.password" /* KEY_NAME.PROCESS_PASSWORD */) || super.loadSettings({ process: settings.process }, password)) {
274
+ if (!this.enabled("process.password") || super.loadSettings({ process: settings.process }, password)) {
275
275
  const { request, download } = settings;
276
276
  if (download && (0, types_1.isPlainObject)(download.aria2)) {
277
277
  let { bin, exec, update_status, max_concurrent_downloads, max_connection_per_server, bt_stop_timeout, bt_tracker_connect_timeout, bt_tracker_timeout, min_split_size, disk_cache, lowest_speed_limit, always_resume, file_allocation, conf_path } = download.aria2;
@@ -395,8 +395,8 @@ class Request extends module_1.default {
395
395
  LOG_TIMEFORMAT = time_format;
396
396
  break;
397
397
  }
398
- LOG_HTTP = this.hasLogType(1024 /* LOG_TYPE.HTTP */);
399
- LOG_TIMEPROCESS = this.hasLogType(256 /* LOG_TYPE.TIME_PROCESS */);
398
+ LOG_HTTP = this.hasLogType(1024);
399
+ LOG_TIMEPROCESS = this.hasLogType(256);
400
400
  }
401
401
  return true;
402
402
  }
@@ -412,151 +412,151 @@ class Request extends module_1.default {
412
412
  return this.readCACert(value, cache);
413
413
  }
414
414
  static isCert(value) {
415
- return (0, types_1.isString)(value) && (value = value.trim()) ? value.indexOf('\n') !== -1 && value.startsWith('---') && value.endsWith('---') : false;
415
+ return (0, types_1.isString)(value) && (value = value.trim()) ? value.includes('\n') && value.startsWith('---') && value.endsWith('---') : false;
416
416
  }
417
417
  static fromURL(url, value) {
418
418
  if (this.isURL(value)) {
419
419
  return value;
420
420
  }
421
421
  const auth = host_1.default.formatBasicAuth(url);
422
- return url.protocol + '//' + (auth && (auth + '@')) + url.hostname + (url.port ? ':' + url.port : '') + (value[0] !== '/' ? '/' : '') + value;
422
+ return url.protocol + '//' + (auth && (auth + '@')) + url.hostname + (url.port ? ':' + url.port : '') + (!value.startsWith('/') ? '/' : '') + value;
423
423
  }
424
424
  static fromStatusCode(value) {
425
425
  if ((value = +value) < 200) {
426
426
  switch (value) {
427
- case 100 /* HTTP_STATUS.CONTINUE */:
427
+ case 100:
428
428
  return 'Continue';
429
- case 101 /* HTTP_STATUS.SWITCHING_PROTOCOL */:
429
+ case 101:
430
430
  return 'Switching Protocol';
431
- case 102 /* HTTP_STATUS.PROCESSING */:
431
+ case 102:
432
432
  return 'Processing';
433
- case 103 /* HTTP_STATUS.EARLY_HINTS */:
433
+ case 103:
434
434
  return 'Early Hints';
435
435
  }
436
436
  }
437
437
  else if (value < 300) {
438
438
  switch (value) {
439
- case 200 /* HTTP_STATUS.OK */:
439
+ case 200:
440
440
  return 'OK';
441
- case 201 /* HTTP_STATUS.CREATED */:
441
+ case 201:
442
442
  return 'Created';
443
- case 202 /* HTTP_STATUS.ACCEPTED */:
443
+ case 202:
444
444
  return 'Accepted';
445
- case 203 /* HTTP_STATUS.NON_AUTHORITATIVE_INFORMATION */:
445
+ case 203:
446
446
  return 'Non-Authoritative Information';
447
- case 204 /* HTTP_STATUS.NO_CONTENT */:
447
+ case 204:
448
448
  return 'No Content';
449
- case 205 /* HTTP_STATUS.RESET_CONTENT */:
449
+ case 205:
450
450
  return 'Reset Content';
451
- case 206 /* HTTP_STATUS.PARTIAL_CONTENT */:
451
+ case 206:
452
452
  return 'Partial Content';
453
453
  }
454
454
  }
455
455
  else if (value < 400) {
456
456
  switch (value) {
457
- case 300 /* HTTP_STATUS.MULTIPLE_CHOICES */:
457
+ case 300:
458
458
  return 'Multiple Choice';
459
- case 301 /* HTTP_STATUS.MOVED_PERMANENTLY */:
459
+ case 301:
460
460
  return 'Moved Permanently';
461
- case 302 /* HTTP_STATUS.FOUND */:
461
+ case 302:
462
462
  return 'Found';
463
- case 303 /* HTTP_STATUS.SEE_OTHER */:
463
+ case 303:
464
464
  return 'See Other';
465
- case 304 /* HTTP_STATUS.NOT_MODIFIED */:
465
+ case 304:
466
466
  return 'Not Modified';
467
- case 305 /* HTTP_STATUS.USE_PROXY */:
467
+ case 305:
468
468
  return 'Use Proxy';
469
- case 307 /* HTTP_STATUS.TEMPORARY_REDIRECT */:
469
+ case 307:
470
470
  return 'Temporary Redirect';
471
- case 308 /* HTTP_STATUS.PERMANENT_REDIRECT */:
471
+ case 308:
472
472
  return 'Permanent Redirect';
473
473
  }
474
474
  }
475
475
  else if (value < 500) {
476
476
  switch (value) {
477
- case 400 /* HTTP_STATUS.BAD_REQUEST */:
477
+ case 400:
478
478
  return 'Bad Request';
479
- case 401 /* HTTP_STATUS.UNAUTHORIZED */:
479
+ case 401:
480
480
  return 'Upgrade Required';
481
- case 402 /* HTTP_STATUS.PAYMENT_REQUIRED */:
481
+ case 402:
482
482
  return 'Payment Required';
483
- case 403 /* HTTP_STATUS.FORBIDDEN */:
483
+ case 403:
484
484
  return 'Forbidden';
485
- case 404 /* HTTP_STATUS.NOT_FOUND */:
485
+ case 404:
486
486
  return 'Not Found';
487
- case 405 /* HTTP_STATUS.METHOD_NOT_ALLOWED */:
487
+ case 405:
488
488
  return 'Method Not Allowed';
489
- case 406 /* HTTP_STATUS.NOT_ACCEPTABLE */:
489
+ case 406:
490
490
  return 'Not Acceptable';
491
- case 407 /* HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED */:
491
+ case 407:
492
492
  return 'Proxy Authentication Required';
493
- case 408 /* HTTP_STATUS.REQUEST_TIMEOUT */:
493
+ case 408:
494
494
  return 'Request Timeout';
495
- case 409 /* HTTP_STATUS.CONFLICT */:
495
+ case 409:
496
496
  return 'Conflict';
497
- case 410 /* HTTP_STATUS.GONE */:
497
+ case 410:
498
498
  return 'Gone';
499
- case 411 /* HTTP_STATUS.LENGTH_REQUIRED */:
499
+ case 411:
500
500
  return 'Length Required';
501
- case 412 /* HTTP_STATUS.PRECONDITION_FAILED */:
501
+ case 412:
502
502
  return 'Precondition Failed';
503
- case 413 /* HTTP_STATUS.PAYLOAD_TOO_LARGE */:
503
+ case 413:
504
504
  return 'Payload Too Large';
505
- case 414 /* HTTP_STATUS.REQUEST_URI_TOO_LONG */:
505
+ case 414:
506
506
  return 'URI Too Long';
507
- case 415 /* HTTP_STATUS.UNSUPPORTED_MEDIA_TYPE */:
507
+ case 415:
508
508
  return 'Unsupported Media Type';
509
- case 416 /* HTTP_STATUS.RANGE_NOT_SATISFIABLE */:
509
+ case 416:
510
510
  return 'Range Not Satisfiable';
511
- case 417 /* HTTP_STATUS.EXPECTATION_FAILED */:
511
+ case 417:
512
512
  return 'Expectation Failed';
513
- case 421 /* HTTP_STATUS.MISDIRECTED_REQUEST */:
513
+ case 421:
514
514
  return 'Misdirected Request';
515
- case 422 /* HTTP_STATUS.UNPROCESSABLE_ENTITY */:
515
+ case 422:
516
516
  return 'Unprocessable Entity';
517
- case 423 /* HTTP_STATUS.LOCKED */:
517
+ case 423:
518
518
  return 'Locked';
519
- case 424 /* HTTP_STATUS.FAILED_DEPENDENCY */:
519
+ case 424:
520
520
  return 'Failed Dependency';
521
- case 426 /* HTTP_STATUS.UPGRADE_REQUIRED */:
521
+ case 426:
522
522
  return 'Upgrade Required';
523
- case 428 /* HTTP_STATUS.PRECONDITION_REQUIRED */:
523
+ case 428:
524
524
  return 'Precondition Required';
525
- case 429 /* HTTP_STATUS.TOO_MANY_REQUESTS */:
525
+ case 429:
526
526
  return 'Too Many Requests';
527
- case 431 /* HTTP_STATUS.REQUEST_HEADER_FIELDS_TOO_LARGE */:
527
+ case 431:
528
528
  return 'Request Header Fields Too Large';
529
- case 451 /* HTTP_STATUS.UNAVAILABLE_FOR_LEGAL_REASONS */:
529
+ case 451:
530
530
  return 'Unavailable For Legal Reasons';
531
531
  }
532
532
  }
533
533
  else {
534
534
  switch (value) {
535
- case 500 /* HTTP_STATUS.INTERNAL_SERVER_ERROR */:
535
+ case 500:
536
536
  return 'Internal Server Error';
537
- case 501 /* HTTP_STATUS.NOT_IMPLEMENTED */:
537
+ case 501:
538
538
  return 'Not Implemented';
539
- case 502 /* HTTP_STATUS.BAD_GATEWAY */:
539
+ case 502:
540
540
  return 'Bad Gateway';
541
- case 503 /* HTTP_STATUS.SERVICE_UNAVAILABLE */:
541
+ case 503:
542
542
  return 'Service Unavailable';
543
- case 504 /* HTTP_STATUS.GATEWAY_TIMEOUT */:
543
+ case 504:
544
544
  return 'Gateway Timeout';
545
- case 505 /* HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED */:
545
+ case 505:
546
546
  return 'HTTP Version Not Supported';
547
- case 506 /* HTTP_STATUS.VARIANT_ALSO_NEGOTIATES */:
547
+ case 506:
548
548
  return 'Variant Also Negotiates';
549
- case 507 /* HTTP_STATUS.INSUFFICIENT_STORAGE */:
549
+ case 507:
550
550
  return 'Insufficient Storage';
551
- case 508 /* HTTP_STATUS.LOOP_DETECTED */:
551
+ case 508:
552
552
  return 'Loop Detected';
553
- case 510 /* HTTP_STATUS.NOT_EXTENDED */:
553
+ case 510:
554
554
  return 'Not Extended';
555
- case 511 /* HTTP_STATUS.NETWORK_AUTHENTICATION_REQUIRED */:
555
+ case 511:
556
556
  return 'Network Authentication Required';
557
557
  }
558
558
  }
559
- return "Unknown" /* ERR_MESSAGE.UNKNOWN */;
559
+ return "Unknown";
560
560
  }
561
561
  static defineHttpAgent(options) {
562
562
  const { keepAlive, timeout = 0 } = options;
@@ -613,13 +613,14 @@ class Request extends module_1.default {
613
613
  this.startTime = Date.now();
614
614
  this.readExpect = 'none';
615
615
  this.proxy = null;
616
- this._moduleName = "request" /* VALUES.MODULE */;
616
+ this._moduleName = "request";
617
+ this._threadable = true;
617
618
  this._config = {
618
- timeout: 60000 /* TIME.m */,
619
- connectTimeout: 20 * 1000 /* TIME.S */,
619
+ timeout: 60000,
620
+ connectTimeout: 20 * 1000,
620
621
  redirectLimit: 10,
621
- retryWait: 1000 /* TIME.S */,
622
- retryAfter: 30 * 1000 /* TIME.S */,
622
+ retryWait: 1000,
623
+ retryAfter: 30 * 1000,
623
624
  retryLimit: 5
624
625
  };
625
626
  this[_a] = false;
@@ -703,7 +704,7 @@ class Request extends module_1.default {
703
704
  const args = [];
704
705
  for (let i = 0; i < log.length; ++i) {
705
706
  const item = log[i];
706
- if (Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
707
+ if (item[1] === title && Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
707
708
  item[1] = '';
708
709
  item[2][0] = item[2][0].substring(origin.length);
709
710
  item[4].titleBgColor = undefined;
@@ -712,12 +713,17 @@ class Request extends module_1.default {
712
713
  log.splice(i--, 1);
713
714
  }
714
715
  }
715
- output.push([title, origin, value, args]);
716
+ output.push([title, origin, value, args.sort((a, b) => a[2][0] < b[2][0] ? -1 : 1)]);
716
717
  count = Math.max(count, value);
717
718
  }
718
719
  });
719
720
  if (!this.host?.aborted) {
720
- output.sort((a, b) => b[2] - a[2]);
721
+ output.sort((a, b) => {
722
+ if (a[2] === b[2]) {
723
+ return a[1] < b[1] ? -1 : 1;
724
+ }
725
+ return b[2] - a[2];
726
+ });
721
727
  const width = count.toString().length;
722
728
  output.forEach(item => {
723
729
  const [title, origin, downloads, messages] = item;
@@ -730,7 +736,7 @@ class Request extends module_1.default {
730
736
  module_1.default.formatMessage(...message);
731
737
  }
732
738
  else {
733
- this.formatMessage(1024 /* LOG_TYPE.HTTP */, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
739
+ this.formatMessage(1024, title, [origin, 'downloads: ' + downloads.toString().padStart(width)], '', options);
734
740
  messages.forEach(args => {
735
741
  args[4].titleIndent = true;
736
742
  module_1.default.formatMessage(...args);
@@ -759,7 +765,7 @@ class Request extends module_1.default {
759
765
  }
760
766
  init(config) {
761
767
  if (config) {
762
- const { headers, httpVersion, ipVersion, requestTimeout } = config;
768
+ const { headers, httpVersion, ipVersion, requestTimeout, readTimeout = requestTimeout } = config;
763
769
  if ((0, types_1.isObject)(headers)) {
764
770
  setOutgoingHeaders(this[kHeaders] || (this[kHeaders] = {}), headers);
765
771
  }
@@ -769,8 +775,8 @@ class Request extends module_1.default {
769
775
  if (ipVersion !== undefined) {
770
776
  this.ipVersion = ipVersion;
771
777
  }
772
- if (requestTimeout !== undefined) {
773
- this.readTimeout = (0, util_1.fromSeconds)(requestTimeout);
778
+ if (readTimeout !== undefined) {
779
+ this.readTimeout = (0, util_1.fromSeconds)(readTimeout);
774
780
  }
775
781
  }
776
782
  return this;
@@ -791,7 +797,7 @@ class Request extends module_1.default {
791
797
  this._config.redirectLimit = redirectLimit;
792
798
  }
793
799
  if (retryWait >= 0) {
794
- this._config.retryWait = Math.min(retryWait, 600 * 1000 /* TIME.S */);
800
+ this._config.retryWait = Math.min(retryWait, 600 * 1000);
795
801
  }
796
802
  if (retryAfter >= 0) {
797
803
  this._config.retryAfter = Math.min(retryAfter, module_1.default.MAX_TIMEOUT);
@@ -930,9 +936,9 @@ class Request extends module_1.default {
930
936
  const headers = this[kHeaders];
931
937
  return headers && getBaseHeaders(uri, headers) || (this.host ? getBaseHeaders(uri, HTTP.HEADERS) : undefined);
932
938
  }
933
- aria2c(uri, options) {
939
+ async aria2c(uri, options) {
934
940
  if (!ARIA2.BIN) {
935
- return Promise.reject((0, types_1.errorMessage)("aria2" /* VALUES.ARIA2 */, "Binary not found" /* ERR_MESSAGE.NOTFOUND_BINARY */));
941
+ return Promise.reject((0, types_1.errorMessage)("aria2", "Binary not found"));
936
942
  }
937
943
  if (typeof uri === 'string' && module_1.default.isURL(uri)) {
938
944
  try {
@@ -1000,15 +1006,15 @@ class Request extends module_1.default {
1000
1006
  }
1001
1007
  if (!(0, types_1.isString)(pathname)) {
1002
1008
  if (this.host) {
1003
- return Promise.reject((0, types_1.errorMessage)("aria2" /* VALUES.ARIA2 */, "Invalid parameters" /* ERR_MESSAGE.PARAMETERS */, 'pathname'));
1009
+ return Promise.reject((0, types_1.errorMessage)("aria2", "Invalid parameters", 'pathname'));
1004
1010
  }
1005
1011
  pathname = process.cwd();
1006
1012
  }
1007
1013
  if ((this.host || this.hasOwnPermission()) && !this.canWrite(pathname = path.resolve(pathname.trim()))) {
1008
- return Promise.reject((0, types_1.errorMessage)("aria2" /* VALUES.ARIA2 */, "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */, pathname));
1014
+ return Promise.reject((0, types_1.errorMessage)("aria2", "Unsupported access", pathname));
1009
1015
  }
1010
1016
  if (!module_1.default.createDir(pathname)) {
1011
- return Promise.reject((0, types_1.errorMessage)("aria2" /* VALUES.ARIA2 */, "Path is not a directory" /* ERR_MESSAGE.NOT_DIRECTORY */, pathname));
1017
+ return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
1012
1018
  }
1013
1019
  silent ?? (silent = this[kSingleton]);
1014
1020
  return new Promise((resolve, reject) => {
@@ -1172,8 +1178,8 @@ class Request extends module_1.default {
1172
1178
  }
1173
1179
  args = binOpts.concat(args);
1174
1180
  }
1175
- if (args.length && module_1.default.hasLogType(32768 /* LOG_TYPE.STDOUT */)) {
1176
- this.formatMessage(32768 /* LOG_TYPE.STDOUT */, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
1181
+ if (args.length && module_1.default.hasLogType(32768)) {
1182
+ this.formatMessage(32768, 'ARIA2', ARIA2.BIN, args.join(' '), { ...module_1.default.LOG_STYLE_WARN });
1177
1183
  }
1178
1184
  opts.push(`"${escapeQuote(uri)}"`);
1179
1185
  args = args.concat(init, opts);
@@ -1216,18 +1222,18 @@ class Request extends module_1.default {
1216
1222
  break;
1217
1223
  }
1218
1224
  case 'ERR':
1219
- fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file" /* ERR_MESSAGE.DELETE_FILE */, path.basename(file)], err, { type: 32 /* LOG_TYPE.FILE */, fatal: false }));
1225
+ fs.unlink(file, err => err && !silent && !this[kSingleton] && this.writeFail(["Unable to delete file", path.basename(file)], err, { type: 32, fatal: false }));
1220
1226
  break;
1221
1227
  }
1222
1228
  }
1223
1229
  if (result.length && !silent && LOG_HTTP && LOG_TIMEPROCESS) {
1224
- this.writeTimeProcess("aria2" /* VALUES.ARIA2 */, uri, startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: true, messageUnit, messageUnitMinWidth: 9 });
1230
+ this.writeTimeProcess("aria2", uri, startTime, { type: 1024, queue: true, messageUnit, messageUnitMinWidth: 9 });
1225
1231
  }
1226
- this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2" /* VALUES.ARIA2 */, uri);
1232
+ this.addLog(result.length ? types_1.STATUS_TYPE.INFO : types_1.STATUS_TYPE.ERROR, out, currentTime, currentTime - startTime, "aria2", uri);
1227
1233
  resolve(result);
1228
1234
  }
1229
1235
  else {
1230
- reject((0, types_1.errorValue)(message || "Unknown" /* ERR_MESSAGE.UNKNOWN */, 'Exit status: ' + code));
1236
+ reject((0, types_1.errorValue)(message || "Unknown", 'Exit status: ' + code));
1231
1237
  }
1232
1238
  })
1233
1239
  .on('error', err => errorResponse(pid, err));
@@ -1263,9 +1269,9 @@ class Request extends module_1.default {
1263
1269
  }
1264
1270
  else {
1265
1271
  const current = (0, types_1.getLogCurrent)();
1266
- progressBar = current?.type === 128 /* LOG_TYPE.TIME_ELAPSED */ && current.title === "aria2" /* VALUES.ARIA2 */;
1272
+ progressBar = current?.type === 128 && current.title === "aria2";
1267
1273
  }
1268
- this.formatMessage(128 /* LOG_TYPE.TIME_ELAPSED */, "aria2" /* VALUES.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 });
1274
+ 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 });
1269
1275
  }
1270
1276
  ARIA2.PID_QUEUE.push(item);
1271
1277
  }
@@ -1273,17 +1279,17 @@ class Request extends module_1.default {
1273
1279
  clearTimer();
1274
1280
  }
1275
1281
  }
1276
- }, (ARIA2.UPDATE_STATUS || 30) * 1000 /* TIME.S */);
1282
+ }, (ARIA2.UPDATE_STATUS || 30) * 1000);
1277
1283
  }
1278
1284
  ARIA2.PID_QUEUE.push([pid, uri, this.broadcastId || undefined]);
1279
1285
  }
1280
1286
  });
1281
1287
  }
1282
- json(uri, options = {}) {
1288
+ async json(uri, options = {}) {
1283
1289
  options.format = 'json';
1284
1290
  return this.get(uri, options);
1285
1291
  }
1286
- pipe(uri, to, options = {}) {
1292
+ async pipe(uri, to, options = {}) {
1287
1293
  options.pipeTo = to;
1288
1294
  return this.get(uri, options);
1289
1295
  }
@@ -1352,9 +1358,9 @@ class Request extends module_1.default {
1352
1358
  }
1353
1359
  const checkEncoding = (response, statusCode, contentEncoding = '') => {
1354
1360
  switch (statusCode) {
1355
- case 206 /* HTTP_STATUS.PARTIAL_CONTENT */:
1361
+ case 206:
1356
1362
  request.emit('error', new Error('[ABORT] Partial content'));
1357
- case 204 /* HTTP_STATUS.NO_CONTENT */:
1363
+ case 204:
1358
1364
  return;
1359
1365
  }
1360
1366
  const chunkSize = outStream?.writableHighWaterMark;
@@ -1403,7 +1409,7 @@ class Request extends module_1.default {
1403
1409
  }
1404
1410
  }
1405
1411
  if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
1406
- request = ((_m = this[kSession][0])[origin] || (_m[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { initialWindowSize: 4294967295 /* CONSTANTS.INITIAL_WINDOW_SIZE */, maxFrameSize: 16777215 /* CONSTANTS.MAX_FRAME_SIZE */, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
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 });
1407
1413
  if (getting) {
1408
1414
  const listenerMap = {};
1409
1415
  const onEvent = request.on.bind(request);
@@ -1412,7 +1418,7 @@ class Request extends module_1.default {
1412
1418
  request.on('response', response => {
1413
1419
  connected = true;
1414
1420
  const statusCode = response[':status'];
1415
- if (statusCode >= 200 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
1421
+ if (statusCode >= 200 && statusCode < 300) {
1416
1422
  if (emitter = checkEncoding(request, statusCode, response['content-encoding'])) {
1417
1423
  for (const event in listenerMap) {
1418
1424
  listenerMap[event].forEach(listener => {
@@ -1495,7 +1501,7 @@ class Request extends module_1.default {
1495
1501
  }
1496
1502
  }
1497
1503
  catch (err) {
1498
- this.checkPackage(err, pkg, "Unknown" /* ERR_MESSAGE.UNKNOWN */);
1504
+ this.checkPackage(err, pkg, "Unknown");
1499
1505
  }
1500
1506
  }
1501
1507
  else if (keepAlive === false) {
@@ -1531,7 +1537,7 @@ class Request extends module_1.default {
1531
1537
  agent
1532
1538
  }, response => {
1533
1539
  const statusCode = response.statusCode;
1534
- if ((getting || posting) && statusCode >= 200 /* HTTP_STATUS.OK */ && statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
1540
+ if ((getting || posting) && statusCode >= 200 && statusCode < 300) {
1535
1541
  const incoming = response.headers;
1536
1542
  let source = checkEncoding(response, statusCode, incoming['content-encoding']);
1537
1543
  if (source) {
@@ -1625,7 +1631,7 @@ class Request extends module_1.default {
1625
1631
  options = contentType;
1626
1632
  contentType = undefined;
1627
1633
  }
1628
- if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data" /* MIME.MULTIPART */)) {
1634
+ if (Array.isArray(data) && (!contentType || contentType === "multipart/form-data")) {
1629
1635
  parts = data;
1630
1636
  data = undefined;
1631
1637
  }
@@ -1651,23 +1657,23 @@ class Request extends module_1.default {
1651
1657
  delete headers[attr];
1652
1658
  }
1653
1659
  }
1654
- if (parts || contentType === "multipart/form-data" /* MIME.MULTIPART */ || contentType === 'form-data') {
1660
+ if (parts || contentType === "multipart/form-data" || contentType === 'form-data') {
1655
1661
  let valid;
1656
1662
  if ((0, types_1.isArray)(parts)) {
1657
1663
  const write = combined.create();
1658
1664
  const boundary = (0, types_1.generateUUID)().replace(/-/g, '');
1659
- contentType = "multipart/form-data" /* MIME.MULTIPART */ + `; boundary="${boundary}"`;
1665
+ contentType = "multipart/form-data" + `; boundary="${boundary}"`;
1660
1666
  let contentLength = 0;
1661
1667
  const createPart = (name, filename, type) => {
1662
- const form = ["--" /* FORM_DATA.BOUNDARY_HASH */ + boundary, `Content-Disposition: form-data; name="${escapeQuote(name)}"` + (filename ? `; filename="${escapeQuote(filename)}"` : ''), "\r\n" /* FORM_DATA.CRLF */];
1668
+ const form = ["--" + boundary, `Content-Disposition: form-data; name="${escapeQuote(name)}"` + (filename ? `; filename="${escapeQuote(filename)}"` : ''), "\r\n"];
1663
1669
  if (type) {
1664
1670
  form.splice(2, 0, 'Content-Type: ' + type);
1665
1671
  }
1666
- return form.join("\r\n" /* FORM_DATA.CRLF */);
1672
+ return form.join("\r\n");
1667
1673
  };
1668
1674
  const addValue = (name, value) => {
1669
1675
  if (value !== undefined) {
1670
- const disposition = createPart(name) + module_1.default.asString(value) + "\r\n" /* FORM_DATA.CRLF */;
1676
+ const disposition = createPart(name) + module_1.default.asString(value) + "\r\n";
1671
1677
  write.append(disposition);
1672
1678
  contentLength += Buffer.byteLength(disposition);
1673
1679
  }
@@ -1697,7 +1703,7 @@ class Request extends module_1.default {
1697
1703
  target = Buffer.concat(chunks);
1698
1704
  }
1699
1705
  if (!Buffer.isBuffer(target)) {
1700
- throw (0, types_1.errorMessage)('File', "Unknown" /* ERR_MESSAGE.UNKNOWN */, "multipart/form-data" /* MIME.MULTIPART */);
1706
+ throw (0, types_1.errorMessage)('File', "Unknown", "multipart/form-data");
1701
1707
  }
1702
1708
  if (!type || !filename) {
1703
1709
  const result = await module_1.default.resolveMime(target);
@@ -1713,11 +1719,11 @@ class Request extends module_1.default {
1713
1719
  filename = (0, types_1.generateUUID)() + '.' + ext;
1714
1720
  }
1715
1721
  }
1716
- const disposition = createPart(name, filename, type || "application/octet-stream" /* MIME.OCTET_STREAM */);
1722
+ const disposition = createPart(name, filename, type || "application/octet-stream");
1717
1723
  write.append(disposition);
1718
1724
  write.append(target);
1719
- write.append("\r\n" /* FORM_DATA.CRLF */);
1720
- contentLength += Buffer.byteLength(disposition) + target.length + 2 /* FORM_DATA.CRLF_LENGTH */;
1725
+ write.append("\r\n");
1726
+ contentLength += Buffer.byteLength(disposition) + target.length + 2;
1721
1727
  valid = true;
1722
1728
  }
1723
1729
  catch (err) {
@@ -1729,13 +1735,13 @@ class Request extends module_1.default {
1729
1735
  }
1730
1736
  }
1731
1737
  if (valid) {
1732
- write.append("--" /* FORM_DATA.BOUNDARY_HASH */ + boundary + "--" /* FORM_DATA.BOUNDARY_HASH */ + "\r\n" /* FORM_DATA.CRLF */);
1733
- headers['content-length'] = (contentLength + 38 /* FORM_DATA.BOUNDARY_LENGTH */).toString();
1738
+ write.append("--" + boundary + "--" + "\r\n");
1739
+ headers['content-length'] = (contentLength + 38).toString();
1734
1740
  data = write;
1735
1741
  }
1736
1742
  }
1737
1743
  if (!valid) {
1738
- return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data" /* MIME.MULTIPART */));
1744
+ return Promise.reject((0, types_1.errorValue)('No files were detected', "multipart/form-data"));
1739
1745
  }
1740
1746
  }
1741
1747
  else {
@@ -1745,22 +1751,22 @@ class Request extends module_1.default {
1745
1751
  if (!(0, types_1.isPlainObject)(data)) {
1746
1752
  data = module_1.default.asString(data);
1747
1753
  }
1748
- else if (contentType === "application/x-www-form-urlencoded" /* MIME.URLENCODED */) {
1754
+ else if (contentType === "application/x-www-form-urlencoded") {
1749
1755
  data = qs.stringify(data);
1750
1756
  }
1751
1757
  else {
1752
1758
  data = JSON.stringify(data);
1753
- contentType || (contentType = "application/json" /* MIME.JSON */);
1759
+ contentType || (contentType = "application/json");
1754
1760
  }
1755
1761
  headers['content-length'] = Buffer.byteLength(data, (0, types_1.getEncoding)(dataEncoding)).toString();
1756
1762
  }
1757
1763
  options.method = 'POST';
1758
1764
  options.httpVersion = 1;
1759
1765
  options.postData = data;
1760
- headers['content-type'] = contentType || "text/plain" /* MIME.TEXT */;
1766
+ headers['content-type'] = contentType || "text/plain";
1761
1767
  return this.get(uri, options);
1762
1768
  }
1763
- get(uri, options = {}) {
1769
+ async get(uri, options = {}) {
1764
1770
  const opts = (typeof options === 'string' ? { format: options, encoding: 'utf-8' } : options);
1765
1771
  if (this.readExpect === 'string') {
1766
1772
  opts.encoding = (0, types_1.getEncoding)(opts?.encoding);
@@ -1795,7 +1801,7 @@ class Request extends module_1.default {
1795
1801
  }
1796
1802
  if (pipeTo) {
1797
1803
  if ((0, types_1.isString)(pipeTo)) {
1798
- outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536 /* CONSTANTS.CHUNK_SIZE_LOCAL */ : 4096 /* CONSTANTS.CHUNK_SIZE */ });
1804
+ outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: request.host.localhost ? 65536 : 4096 });
1799
1805
  request.outStream = outStream;
1800
1806
  }
1801
1807
  else {
@@ -1811,9 +1817,9 @@ class Request extends module_1.default {
1811
1817
  ({ httpVersion, outAbort } = request);
1812
1818
  const isAborted = () => client.destroyed || httpVersion === 2 && client.aborted;
1813
1819
  const isRetry = (value) => (0, util_1.isRetryable)(value) && ++retries <= this._config.retryLimit;
1814
- const isUnsupported = (value) => value === 421 /* HTTP_STATUS.MISDIRECTED_REQUEST */ || value === 505 /* HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED */;
1820
+ const isUnsupported = (value) => value === 421 || value === 505;
1815
1821
  const isDowngrade = (err) => err instanceof Error && (err.code === 'ERR_HTTP2_ERROR' || isUnsupported(Math.abs(err.errno)));
1816
- const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024 /* LOG_TYPE.HTTP */, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { titleBgColor: 'bgGrey', titleColor: 'yellow' });
1822
+ const formatWarning = (message) => LOG_HTTP && !silent && this.formatMessage(1024, 'HTTP' + httpVersion, [message, host.origin], url.toString(), { titleBgColor: 'bgGrey', titleColor: 'yellow' });
1817
1823
  const formatNgFlags = (value, statusCode, location) => location ? `Using HTTP 1.1 for URL redirect (${location})` : formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
1818
1824
  const abortResponse = () => {
1819
1825
  if (closed) {
@@ -1853,7 +1859,7 @@ class Request extends module_1.default {
1853
1859
  if (readTimeout > 0) {
1854
1860
  timeout = setTimeout(() => {
1855
1861
  abortResponse();
1856
- throwError((0, types_1.errorValue)("Timeout was exceeded" /* ERR_MESSAGE.TIMEOUT */, href.toString()));
1862
+ throwError((0, types_1.errorValue)("Timeout was exceeded", href.toString()));
1857
1863
  }, readTimeout);
1858
1864
  }
1859
1865
  if (log) {
@@ -1913,19 +1919,19 @@ class Request extends module_1.default {
1913
1919
  }
1914
1920
  }
1915
1921
  if (mibsTime) {
1916
- const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000 /* TIME.S */);
1922
+ const unit = (Buffer.byteLength(buffer, encoding) * 8) / ((0, types_1.convertTime)(process.hrtime(mibsTime)) * 1000);
1917
1923
  if (unit < 1) {
1918
- messageUnit = Math.ceil(unit * 1000 /* TIME.S */) + 'KiB/s';
1924
+ messageUnit = Math.ceil(unit * 1000) + 'KiB/s';
1919
1925
  }
1920
- else if (unit < 1000 /* TIME.S */) {
1926
+ else if (unit < 1000) {
1921
1927
  messageUnit = unit.toPrecision(3) + 'MiB/s';
1922
1928
  }
1923
1929
  else {
1924
- messageUnit = (unit / 1000 /* TIME.S */).toPrecision(3) + 'GiB/s';
1930
+ messageUnit = (unit / 1000).toPrecision(3) + 'GiB/s';
1925
1931
  }
1926
1932
  }
1927
1933
  if (typeof buffer === 'string') {
1928
- if (buffer[0] === '\uFEFF' && encoding !== 'utf16le') {
1934
+ if (buffer.startsWith('\uFEFF') && encoding !== 'utf16le') {
1929
1935
  buffer = buffer.substring(1);
1930
1936
  }
1931
1937
  if (outFormat) {
@@ -1955,7 +1961,7 @@ class Request extends module_1.default {
1955
1961
  }
1956
1962
  catch (err) {
1957
1963
  if (!silent && !this[kSingleton] && !(packageName && this.checkPackage(err, packageName))) {
1958
- this.writeFail(['Unable to parse URI response', format], err, 1024 /* LOG_TYPE.HTTP */);
1964
+ this.writeFail(['Unable to parse URI response', format], err, 1024);
1959
1965
  }
1960
1966
  result = null;
1961
1967
  }
@@ -1975,7 +1981,7 @@ class Request extends module_1.default {
1975
1981
  }
1976
1982
  resolve(result);
1977
1983
  if (log) {
1978
- this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024 /* LOG_TYPE.HTTP */, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: true });
1984
+ this.writeTimeProcess('HTTP' + httpVersion, request.statusMessage || url.toString(), startTime, { type: 1024, queue: !!this.host, titleBgColor, messageUnit, messageUnitMinWidth: 9, delayTime, bypassLog: true });
1979
1985
  }
1980
1986
  });
1981
1987
  host.success(httpVersion);
@@ -2050,7 +2056,7 @@ class Request extends module_1.default {
2050
2056
  host.failed(2);
2051
2057
  if (host.version > 1) {
2052
2058
  if (!silent) {
2053
- this.formatMessage(1024 /* LOG_TYPE.HTTP */, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
2059
+ this.formatMessage(1024, 'HTTP2', ['Unsupported protocol', host.origin], message, { failed: true });
2054
2060
  }
2055
2061
  host.version = 1;
2056
2062
  }
@@ -2063,18 +2069,18 @@ class Request extends module_1.default {
2063
2069
  return;
2064
2070
  }
2065
2071
  const statusCode = headers[':status'];
2066
- if (statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2072
+ if (statusCode < 300) {
2067
2073
  acceptResponse(headers);
2068
2074
  }
2069
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
2075
+ else if (statusCode < 400) {
2070
2076
  redirectResponse(statusCode, headers.location);
2071
2077
  }
2072
- else if (statusCode === 401 /* HTTP_STATUS.UNAUTHORIZED */ ||
2073
- statusCode === 402 /* HTTP_STATUS.PAYMENT_REQUIRED */ ||
2074
- statusCode === 403 /* HTTP_STATUS.FORBIDDEN */ ||
2075
- statusCode === 404 /* HTTP_STATUS.NOT_FOUND */ ||
2076
- statusCode === 407 /* HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED */ ||
2077
- statusCode === 410 /* HTTP_STATUS.GONE */) {
2078
+ else if (statusCode === 401 ||
2079
+ statusCode === 402 ||
2080
+ statusCode === 403 ||
2081
+ statusCode === 404 ||
2082
+ statusCode === 407 ||
2083
+ statusCode === 410) {
2078
2084
  throwError(formatStatus(statusCode), outAbort);
2079
2085
  }
2080
2086
  else if (isRetry(statusCode)) {
@@ -2110,10 +2116,10 @@ class Request extends module_1.default {
2110
2116
  return;
2111
2117
  }
2112
2118
  switch (!isDowngrade(err) && await host.hasProtocol(2)) {
2113
- case 1 /* QUERY_RESULT.OK */:
2119
+ case 1:
2114
2120
  errorResponse(err);
2115
2121
  break;
2116
- case 2 /* QUERY_RESULT.TIMEOUT */:
2122
+ case 2:
2117
2123
  retryDownload(false, err);
2118
2124
  break;
2119
2125
  default:
@@ -2129,10 +2135,10 @@ class Request extends module_1.default {
2129
2135
  return;
2130
2136
  }
2131
2137
  const statusCode = res.statusCode;
2132
- if (statusCode < 300 /* HTTP_STATUS.MULTIPLE_CHOICES */) {
2138
+ if (statusCode < 300) {
2133
2139
  acceptResponse(res.headers);
2134
2140
  }
2135
- else if (statusCode < 400 /* HTTP_STATUS.BAD_REQUEST */) {
2141
+ else if (statusCode < 400) {
2136
2142
  redirectResponse(statusCode, res.headers.location);
2137
2143
  }
2138
2144
  else if (isRetry(statusCode)) {
@@ -2162,7 +2168,7 @@ class Request extends module_1.default {
2162
2168
  retryTimeout();
2163
2169
  }
2164
2170
  else {
2165
- throwError(formatStatus(408 /* HTTP_STATUS.REQUEST_TIMEOUT */));
2171
+ throwError(formatStatus(408));
2166
2172
  }
2167
2173
  });
2168
2174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,11 +17,11 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.6.0",
24
- "@e-mc/types": "0.6.0",
23
+ "@e-mc/module": "0.6.1",
24
+ "@e-mc/types": "0.6.1",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "which": "^2.0.2"
package/util.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference path="../types/lib/object.d.ts" />
2
+
1
3
  import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
2
4
 
3
5
  declare namespace util {
package/util.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fromSeconds = exports.asFloat = exports.asInt = exports.trimPath = exports.isRetryable = exports.checkRetryable = exports.hasBasicAuth = exports.getBasicAuth = exports.normalizeHeaders = exports.parseHeader = void 0;
4
- const module_1 = require("../module");
5
- const types_1 = require("../types");
4
+ const module_1 = require("@e-mc/module");
5
+ const types_1 = require("@e-mc/types");
6
6
  const safeInt = (value) => value >= 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : NaN;
7
7
  function parseHeader(headers, name) {
8
8
  const value = headers[name];
@@ -87,19 +87,19 @@ function checkRetryable(err) {
87
87
  exports.checkRetryable = checkRetryable;
88
88
  function isRetryable(value, timeout) {
89
89
  switch (value) {
90
- case 408 /* HTTP_STATUS.REQUEST_TIMEOUT */:
91
- case 504 /* HTTP_STATUS.GATEWAY_TIMEOUT */:
92
- case 522 /* HTTP_STATUS.CONNECTION_TIMED_OUT */:
93
- case 524 /* HTTP_STATUS.A_TIMEOUT_OCCURRED */:
90
+ case 408:
91
+ case 504:
92
+ case 522:
93
+ case 524:
94
94
  if (timeout) {
95
95
  return true;
96
96
  }
97
- case 429 /* HTTP_STATUS.TOO_MANY_REQUESTS */:
98
- case 499 /* HTTP_STATUS.CLIENT_CLOSED_REQUEST */:
99
- case 500 /* HTTP_STATUS.INTERNAL_SERVER_ERROR */:
100
- case 502 /* HTTP_STATUS.BAD_GATEWAY */:
101
- case 503 /* HTTP_STATUS.SERVICE_UNAVAILABLE */:
102
- case 521 /* HTTP_STATUS.WEB_SERVER_IS_DOWN */:
97
+ case 429:
98
+ case 499:
99
+ case 500:
100
+ case 502:
101
+ case 503:
102
+ case 521:
103
103
  if (!timeout) {
104
104
  return true;
105
105
  }
@@ -138,9 +138,9 @@ exports.asFloat = asFloat;
138
138
  function fromSeconds(value) {
139
139
  switch (typeof value) {
140
140
  case 'string':
141
- return safeInt(Math.ceil(parseFloat(value)) * 1000 /* TIME.S */);
141
+ return safeInt(parseInt(value) * 1000);
142
142
  case 'number':
143
- return safeInt(value * 1000 /* TIME.S */);
143
+ return safeInt(Math.trunc(value) * 1000);
144
144
  default:
145
145
  return NaN;
146
146
  }