@e-mc/request 0.8.3 → 0.8.4

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.
Files changed (3) hide show
  1. package/README.md +87 -3
  2. package/index.js +10 -10
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,7 +1,91 @@
1
- ### @e-mc/request
1
+ # @e-mc/request
2
2
 
3
- https://e-mc.readthedocs.io
3
+ * NodeJS 14
4
+ * ES2020
4
5
 
5
- ### LICENSE
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { IModule, ModuleConstructor } from "./index";
16
+ import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
17
+ import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
18
+ import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
19
+
20
+ import type { Writable } from "stream";
21
+ import type { LookupFunction } from "net";
22
+ import type { ClientRequest, OutgoingHttpHeaders } from "http";
23
+
24
+ interface IRequest extends IModule {
25
+ module: RequestModule;
26
+ startTime: number;
27
+ acceptEncoding: boolean;
28
+ keepAlive: boolean | null;
29
+ readTimeout: number;
30
+ readExpect: ReadExpectType;
31
+ proxy: ProxySettings | null;
32
+ init(config?: RequestInit): this;
33
+ apply(options: ApplyOptions): this;
34
+ addDns(hostname: string, address: string, timeout: number): void;
35
+ addDns(hostname: string, address: string, family?: number | string, timeout?: number): void;
36
+ lookupDns(hostname: string): LookupFunction;
37
+ proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
38
+ statusOn(name: number | number[], callback: StatusOnCallback): void;
39
+ statusOn(name: number | number[], patternUrl: string, callback: StatusOnCallback): void;
40
+ headersOn(name: string | string[], callback: HeadersOnCallback): void;
41
+ headersOn(name: string | string[], patternUrl: string, callback: HeadersOnCallback): void;
42
+ headersOf(uri: string): OutgoingHttpHeaders | undefined;
43
+ aria2c(uri: string | URL, pathname: string): Promise<string[]>;
44
+ aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
45
+ json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
46
+ pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
47
+ opts(url: string | URL, options?: OpenOptions): HostConfig;
48
+ open(uri: string | URL, options: OpenOptions): HttpRequestClient;
49
+ head(uri: string | URL, options?: OpenOptions): ClientRequest;
50
+ post(uri: string | URL, data: unknown, contentType: string): Promise<Buffer | string | null>;
51
+ post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
52
+ post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
53
+ post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
54
+ post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
55
+ get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
56
+ detach(singleton?: boolean): void;
57
+ reset(): void;
58
+ close(): void;
59
+ set agentTimeout(value);
60
+ get agentTimeout(): number;
61
+ set httpVersion(value);
62
+ get httpVersion(): HttpProtocolVersion | null;
63
+ set ipVersion(value);
64
+ get ipVersion(): InternetProtocolVersion;
65
+ get settings(): RequestSettings;
66
+ }
67
+
68
+ interface RequestConstructor extends ModuleConstructor {
69
+ readCACert(value: string, cache?: boolean): string;
70
+ readTLSKey(value: string, cache?: boolean): string;
71
+ readTLSCert(value: string, cache?: boolean): string;
72
+ isCert(value: string): boolean;
73
+ fromURL(url: URL, value: string): string;
74
+ fromStatusCode(value: number | string): string;
75
+ defineHttpAgent(options: HttpAgentSettings): void;
76
+ defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
77
+ getAria2Path(): string;
78
+ readonly prototype: IRequest;
79
+ new(module?: RequestModule): IRequest;
80
+ }
81
+ ```
82
+
83
+ ## References
84
+
85
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/http.d.ts
86
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/request.d.ts
87
+ - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
88
+
89
+ ## LICENSE
6
90
 
7
91
  BSD 3-Clause
package/index.js CHANGED
@@ -722,7 +722,7 @@ class Request extends module_1.default {
722
722
  const args = [];
723
723
  for (let i = 0; i < log.length; ++i) {
724
724
  const item = log[i];
725
- if (Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
725
+ if (item[1] === title && Array.isArray(item[2]) && item[2][0].startsWith(origin)) {
726
726
  item[1] = '';
727
727
  item[2][0] = item[2][0].substring(origin.length);
728
728
  item[4].titleBgColor = undefined;
@@ -731,12 +731,17 @@ class Request extends module_1.default {
731
731
  log.splice(i--, 1);
732
732
  }
733
733
  }
734
- output.push([title, origin, value, args]);
734
+ output.push([title, origin, value, args.sort((a, b) => a[2][0] < b[2][0] ? -1 : 1)]);
735
735
  count = Math.max(count, value);
736
736
  }
737
737
  });
738
738
  if (LOG_STDOUT) {
739
- output.sort((a, b) => b[2] - a[2]);
739
+ output.sort((a, b) => {
740
+ if (a[2] === b[2]) {
741
+ return a[1] < b[1] ? -1 : 1;
742
+ }
743
+ return b[2] - a[2];
744
+ });
740
745
  const width = count.toString().length;
741
746
  output.forEach(item => {
742
747
  const [title, origin, downloads, messages] = item;
@@ -1464,7 +1469,7 @@ class Request extends module_1.default {
1464
1469
  }
1465
1470
  }
1466
1471
  if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
1467
- request = ((_p = this[kSession][0])[origin] || (_p[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 });
1472
+ request = ((_p = this[kSession][0])[origin] || (_p[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215 /* CONSTANTS.MAX_FRAME_SIZE */, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1468
1473
  if (getting) {
1469
1474
  const listenerMap = {};
1470
1475
  const onEvent = request.on.bind(request);
@@ -1921,9 +1926,6 @@ class Request extends module_1.default {
1921
1926
  }, readTimeout);
1922
1927
  }
1923
1928
  if (log) {
1924
- if (buffering === false) {
1925
- mibsTime = process.hrtime();
1926
- }
1927
1929
  switch (this.settings?.time_format || LOG_TIMEFORMAT) {
1928
1930
  case 'readable':
1929
1931
  delayTime = process.hrtime(startTime);
@@ -1932,6 +1934,7 @@ class Request extends module_1.default {
1932
1934
  delayTime = Date.now() - this.startTime;
1933
1935
  break;
1934
1936
  }
1937
+ mibsTime = process.hrtime();
1935
1938
  }
1936
1939
  });
1937
1940
  }
@@ -1949,9 +1952,6 @@ class Request extends module_1.default {
1949
1952
  }
1950
1953
  }
1951
1954
  else {
1952
- if (log) {
1953
- mibsTime = process.hrtime();
1954
- }
1955
1955
  buffer = typeof chunk === 'string' ? chunk : [chunk];
1956
1956
  }
1957
1957
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.8.3",
24
- "@e-mc/types": "0.8.3",
23
+ "@e-mc/module": "0.8.4",
24
+ "@e-mc/types": "0.8.4",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^3.0.1",