@e-mc/request 0.12.15 → 0.12.17
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 +4 -8
- package/README.md +6 -5
- package/http/adapter/index.js +8 -2
- package/index.js +25 -16
- package/package.json +5 -5
- package/util.d.ts +1 -1
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2025 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
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.17/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
@@ -45,6 +45,7 @@ interface IRequest extends IModule {
|
|
|
45
45
|
rclone(uri: string | URL, pathname: string | URL): Promise<string[]>;
|
|
46
46
|
rclone(uri: string | URL, options?: RcloneOptions): Promise<string[]>;
|
|
47
47
|
json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
|
|
48
|
+
blob(uri: string | URL, options?: OpenOptions): Promise<Blob | null>;
|
|
48
49
|
pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
|
|
49
50
|
opts(url: string | URL, options?: OpenOptions): HostConfig;
|
|
50
51
|
open(uri: string | URL, options: OpenOptions): HttpRequestClient;
|
|
@@ -255,12 +256,12 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
255
256
|
|
|
256
257
|
## References
|
|
257
258
|
|
|
258
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
259
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
260
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
259
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/http.d.ts
|
|
260
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/request.d.ts
|
|
261
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/settings.d.ts
|
|
261
262
|
|
|
262
263
|
* https://www.npmjs.com/package/@types/node
|
|
263
264
|
|
|
264
265
|
## LICENSE
|
|
265
266
|
|
|
266
|
-
|
|
267
|
+
MIT
|
package/http/adapter/index.js
CHANGED
|
@@ -243,6 +243,9 @@ class HttpAdapter {
|
|
|
243
243
|
if ('outFilename' in opts) {
|
|
244
244
|
opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
|
|
245
245
|
}
|
|
246
|
+
if ('outContentType' in opts) {
|
|
247
|
+
opts.outContentType = headers['content-type'];
|
|
248
|
+
}
|
|
246
249
|
const pipeline = this.pipeTo ? !(0, types_1.isString)(this.pipeTo) : false;
|
|
247
250
|
const enabled = opts.connected?.call(this.client, headers) !== false && !pipeline;
|
|
248
251
|
const maxBufferSize = opts.maxBufferSize ? (0, types_1.alignSize)(opts.maxBufferSize) : 0;
|
|
@@ -350,7 +353,7 @@ class HttpAdapter {
|
|
|
350
353
|
break;
|
|
351
354
|
case 'toml':
|
|
352
355
|
try {
|
|
353
|
-
result = require('smol-toml').parse(buffer);
|
|
356
|
+
result = require('smol-toml').parse(buffer, parser);
|
|
354
357
|
}
|
|
355
358
|
catch {
|
|
356
359
|
result = require(packageName = 'toml').parse(buffer);
|
|
@@ -372,6 +375,9 @@ class HttpAdapter {
|
|
|
372
375
|
}
|
|
373
376
|
}
|
|
374
377
|
}
|
|
378
|
+
else if (opts.outFormat) {
|
|
379
|
+
opts.outFormat = undefined;
|
|
380
|
+
}
|
|
375
381
|
if (result === undefined) {
|
|
376
382
|
result = buffer;
|
|
377
383
|
}
|
|
@@ -380,7 +386,7 @@ class HttpAdapter {
|
|
|
380
386
|
if (updating) {
|
|
381
387
|
this.updateProgress(0, this.contentLength);
|
|
382
388
|
}
|
|
383
|
-
if (enabled && this.instance.readExpect === 'always' && !empty) {
|
|
389
|
+
if (enabled && this.instance.readExpect === 'always' && !empty || opts.throwsEmpty) {
|
|
384
390
|
this.terminate("No data received");
|
|
385
391
|
return;
|
|
386
392
|
}
|
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const adapter_1 = require("@e-mc/request/http/adapter");
|
|
|
23
23
|
const kRequest = Symbol.for('request:constructor');
|
|
24
24
|
const SUPPORTED_NODE20 = (0, types_1.supported)(20);
|
|
25
25
|
const SUPPORTED_ZSTD = (0, types_1.supported)(23, 8) || (0, types_1.supported)(22, 15, 0, true);
|
|
26
|
+
const SUPPORTED_FILE = (0, types_1.supported)(19, 2) || (0, types_1.supported)(18, 13, true);
|
|
26
27
|
const REGEXP_PEMCERT = /^-{3,}[ \t]*BEGIN[ \t].+\n-{3,}[ \t]*END[ \t][^-]+-{3,}$/s;
|
|
27
28
|
const REGEXP_GLOBWITHIN = /\\\?|(?:(?<!\\)(?:\*|\[!?[^!\]]+\]|\{(?:[^,]+,)+[^}]+\}|[!?+*@]\((?:[^|]+\|)*[^)]+\)|\?.*\?|\?$))/;
|
|
28
29
|
const REGEXP_RCLONE = /^rclone:\?/i;
|
|
@@ -449,7 +450,7 @@ function finalizeBinArgs(instance, name, bin, args, opts, binOpts, cmd = []) {
|
|
|
449
450
|
const pattern = new RegExp(`^${leading}(?:=|$)`);
|
|
450
451
|
for (let i = 0; i < opts.length; ++i) {
|
|
451
452
|
if (pattern.test(opts[i])) {
|
|
452
|
-
opts.splice(i
|
|
453
|
+
opts.splice(i, 1);
|
|
453
454
|
break;
|
|
454
455
|
}
|
|
455
456
|
}
|
|
@@ -1218,15 +1219,10 @@ class Request extends module_1 {
|
|
|
1218
1219
|
({ signal, silent } = options);
|
|
1219
1220
|
({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file'], options.shellExpansion));
|
|
1220
1221
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
uri = new URL(uri);
|
|
1224
|
-
}
|
|
1225
|
-
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1226
|
-
}
|
|
1227
|
-
catch (err) {
|
|
1228
|
-
return Promise.reject(err);
|
|
1222
|
+
if ((0, types_1.isString)(uri) && module_1.isURL(uri)) {
|
|
1223
|
+
uri = new URL(uri);
|
|
1229
1224
|
}
|
|
1225
|
+
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1230
1226
|
silent ??= this.#singleton;
|
|
1231
1227
|
return new Promise((resolve, reject) => {
|
|
1232
1228
|
let protocol, origin, username, password;
|
|
@@ -1491,15 +1487,11 @@ class Request extends module_1 {
|
|
|
1491
1487
|
default:
|
|
1492
1488
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
|
|
1493
1489
|
}
|
|
1494
|
-
|
|
1495
|
-
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1496
|
-
}
|
|
1497
|
-
catch (err) {
|
|
1498
|
-
return Promise.reject(err);
|
|
1499
|
-
}
|
|
1490
|
+
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1500
1491
|
silent ??= this.#singleton;
|
|
1501
1492
|
return new Promise((resolve, reject) => {
|
|
1502
1493
|
const init = [
|
|
1494
|
+
'--files-only=true',
|
|
1503
1495
|
'--links=false',
|
|
1504
1496
|
'--delete-excluded=false',
|
|
1505
1497
|
'--interactive=false',
|
|
@@ -1690,6 +1682,21 @@ class Request extends module_1 {
|
|
|
1690
1682
|
options.format = 'json';
|
|
1691
1683
|
return this.get(uri, options);
|
|
1692
1684
|
}
|
|
1685
|
+
async blob(uri, options = {}) {
|
|
1686
|
+
options.outContentType = undefined;
|
|
1687
|
+
options.outFilename = undefined;
|
|
1688
|
+
options.outBlob = true;
|
|
1689
|
+
const data = await this.get(uri, options);
|
|
1690
|
+
if (!data) {
|
|
1691
|
+
return null;
|
|
1692
|
+
}
|
|
1693
|
+
const format = options.outFormat?.out;
|
|
1694
|
+
const type = { type: format ? 'application/' + format : options.outContentType || (typeof data === 'string' ? 'text/plain' : undefined) };
|
|
1695
|
+
if (SUPPORTED_FILE && options.outFilename) {
|
|
1696
|
+
return new File([Buffer.from(data)], path.basename(options.outFilename), type);
|
|
1697
|
+
}
|
|
1698
|
+
return new Blob([Buffer.from(data)], type);
|
|
1699
|
+
}
|
|
1693
1700
|
async pipe(uri, to, options = {}) {
|
|
1694
1701
|
options.pipeTo = to;
|
|
1695
1702
|
return this.get(uri, options);
|
|
@@ -1757,7 +1764,9 @@ class Request extends module_1 {
|
|
|
1757
1764
|
}
|
|
1758
1765
|
headers.accept += ', text/plain';
|
|
1759
1766
|
options.encoding = (0, types_1.getEncoding)(encoding);
|
|
1760
|
-
options.
|
|
1767
|
+
if (!options.outBlob) {
|
|
1768
|
+
options.outFormat = { out: format, parser };
|
|
1769
|
+
}
|
|
1761
1770
|
}
|
|
1762
1771
|
if (typeof uri !== 'string') {
|
|
1763
1772
|
url = uri;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.17",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"squared"
|
|
17
17
|
],
|
|
18
18
|
"author": "An Pham <anpham6@gmail.com>",
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/module": "0.12.
|
|
23
|
-
"@e-mc/types": "0.12.
|
|
22
|
+
"@e-mc/module": "0.12.17",
|
|
23
|
+
"@e-mc/types": "0.12.17",
|
|
24
24
|
"combined-stream": "^1.0.8",
|
|
25
25
|
"js-yaml": "^4.1.1",
|
|
26
|
-
"picomatch": "^4.0.
|
|
26
|
+
"picomatch": "^4.0.4",
|
|
27
27
|
"which": "^4.0.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/util.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare namespace util {
|
|
|
13
13
|
function hasBasicAuth(value: string): boolean;
|
|
14
14
|
function checkRetryable(err: unknown): boolean;
|
|
15
15
|
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
16
|
-
function parseHttpProxy(value?: string): HttpProxySettings | undefined;
|
|
16
|
+
function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
|
|
17
17
|
function trimPath(value: string, char?: string): string;
|
|
18
18
|
function asInt(value: unknown): number;
|
|
19
19
|
function asFloat(value: unknown): number;
|