@e-mc/request 0.8.4 → 0.8.5

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 2024 Mile Square Park
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,91 +1,7 @@
1
1
  # @e-mc/request
2
2
 
3
- * NodeJS 14
4
- * ES2020
5
-
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
3
+ PEP 402
88
4
 
89
5
  ## LICENSE
90
6
 
91
- BSD 3-Clause
7
+ MIT
package/index.js CHANGED
@@ -784,7 +784,7 @@ class Request extends module_1.default {
784
784
  }
785
785
  init(config) {
786
786
  if (config) {
787
- const { headers, httpVersion, ipVersion, requestTimeout } = config;
787
+ const { headers, httpVersion, ipVersion, requestTimeout, readTimeout = requestTimeout } = config;
788
788
  if ((0, types_1.isObject)(headers)) {
789
789
  setOutgoingHeaders(this[kHeaders] || (this[kHeaders] = {}), headers);
790
790
  }
@@ -794,8 +794,8 @@ class Request extends module_1.default {
794
794
  if (ipVersion !== undefined) {
795
795
  this.ipVersion = ipVersion;
796
796
  }
797
- if (requestTimeout !== undefined) {
798
- this.readTimeout = (0, util_1.fromSeconds)(requestTimeout);
797
+ if (readTimeout !== undefined) {
798
+ this.readTimeout = (0, util_1.fromSeconds)(readTimeout);
799
799
  }
800
800
  }
801
801
  return this;
@@ -955,35 +955,35 @@ class Request extends module_1.default {
955
955
  }
956
956
  }
957
957
  }
958
- statusOn(code, patternUrl = '*', callback) {
959
- if (typeof patternUrl === 'function') {
960
- callback = patternUrl;
961
- patternUrl = '*';
958
+ statusOn(code, globUrl = '*', callback) {
959
+ if (typeof globUrl === 'function') {
960
+ callback = globUrl;
961
+ globUrl = '*';
962
962
  }
963
- if ((0, types_1.isString)(patternUrl) && typeof callback === 'function') {
963
+ if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
964
964
  const on = this[kStatusOn] || (this[kStatusOn] = new Map());
965
965
  for (const item of !Array.isArray(code) ? [code] : code) {
966
966
  let status = on.get(item);
967
967
  if (!status) {
968
968
  on.set(item, status = []);
969
969
  }
970
- status.push([patternUrl, callback]);
970
+ status.push([globUrl, callback]);
971
971
  }
972
972
  }
973
973
  }
974
- headersOn(name, patternUrl = '*', callback) {
975
- if (typeof patternUrl === 'function') {
976
- callback = patternUrl;
977
- patternUrl = '*';
974
+ headersOn(name, globUrl = '*', callback) {
975
+ if (typeof globUrl === 'function') {
976
+ callback = globUrl;
977
+ globUrl = '*';
978
978
  }
979
- if ((0, types_1.isString)(patternUrl) && typeof callback === 'function') {
979
+ if ((0, types_1.isString)(globUrl) && typeof callback === 'function') {
980
980
  const on = this[kHeadersOn] || (this[kHeadersOn] = new Map());
981
981
  for (const item of !Array.isArray(name) ? [name] : name) {
982
982
  let headers = on.get(item);
983
983
  if (!headers) {
984
984
  on.set(item, headers = []);
985
985
  }
986
- headers.push([patternUrl, callback]);
986
+ headers.push([globUrl, callback]);
987
987
  }
988
988
  }
989
989
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
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.8.4",
24
- "@e-mc/types": "0.8.4",
23
+ "@e-mc/module": "0.8.5",
24
+ "@e-mc/types": "0.8.5",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^3.0.1",
package/util.js CHANGED
@@ -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 /* TIME.S */);
142
142
  case 'number':
143
- return safeInt(value * 1000 /* TIME.S */);
143
+ return safeInt(Math.trunc(value) * 1000 /* TIME.S */);
144
144
  default:
145
145
  return NaN;
146
146
  }