xjs-common 9.1.3 → 9.1.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/dist/func/u-file.d.ts +5 -0
- package/dist/func/u-file.js +5 -0
- package/dist/func/u.d.ts +2 -1
- package/dist/func/u.js +30 -1
- package/dist/prcs/http/http-resolver-context.d.ts +2 -0
- package/dist/prcs/http/http-resolver-context.js +5 -3
- package/dist/prcs/http/i-http-client.d.ts +6 -0
- package/package.json +1 -1
package/dist/func/u-file.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ export declare namespace UFile {
|
|
|
41
41
|
* @param destDir directory that the decompress files export to.
|
|
42
42
|
*/
|
|
43
43
|
function unzip(zipPath: MaybeArray<string>, destDir?: MaybeArray<string>): void;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated since v9.1.4
|
|
46
|
+
* @removed this will be removed in v10.
|
|
47
|
+
* @replaced it should uses this without namespace `UFile`.
|
|
48
|
+
*/
|
|
44
49
|
function joinPath(...p: MaybeArray<string>[]): string;
|
|
45
50
|
}
|
|
46
51
|
export {};
|
package/dist/func/u-file.js
CHANGED
|
@@ -159,6 +159,11 @@ var UFile;
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
UFile.unzip = unzip;
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated since v9.1.4
|
|
164
|
+
* @removed this will be removed in v10.
|
|
165
|
+
* @replaced it should uses this without namespace `UFile`.
|
|
166
|
+
*/
|
|
162
167
|
function joinPath(...p) {
|
|
163
168
|
return path.join(...p.flatMap(u_type_1.UType.takeAsArray));
|
|
164
169
|
}
|
package/dist/func/u.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Loggable } from "../const/types";
|
|
1
|
+
import { Loggable, MaybeArray } from "../const/types";
|
|
2
2
|
export declare function getJSTDate(d?: Date): Date;
|
|
3
3
|
export declare function delay(sec: number): Promise<void>;
|
|
4
4
|
export declare function int2array(size: number): number[];
|
|
@@ -23,3 +23,4 @@ export declare function retry<T>(cb: () => T, op?: RetryOption<void>): T;
|
|
|
23
23
|
export declare function retry<T>(cb: () => T, op?: RetryOption<Promise<void>>): Promise<T>;
|
|
24
24
|
export declare function retry<T>(cb: () => Promise<T>, op?: RetryOption<void>): Promise<T>;
|
|
25
25
|
export declare function retry<T>(cb: () => Promise<T>, op?: RetryOption<Promise<void>>): Promise<T>;
|
|
26
|
+
export declare function joinPath(...p: MaybeArray<string>[]): string;
|
package/dist/func/u.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retry = exports.checkPortAvailability = exports.bitor = exports.array2map = exports.int2array = exports.delay = exports.getJSTDate = void 0;
|
|
26
|
+
exports.joinPath = exports.retry = exports.checkPortAvailability = exports.bitor = exports.array2map = exports.int2array = exports.delay = exports.getJSTDate = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
4
28
|
const xjs_err_1 = require("../obj/xjs-err");
|
|
29
|
+
const u_type_1 = require("./u-type");
|
|
5
30
|
const s_errCode = 10;
|
|
6
31
|
function getJSTDate(d) {
|
|
7
32
|
return new Date((d ? d.getTime() : Date.now()) + 9 * 60 * 60 * 1000);
|
|
@@ -83,3 +108,7 @@ function retry(cb, op) {
|
|
|
83
108
|
return prcs(initialCount);
|
|
84
109
|
}
|
|
85
110
|
exports.retry = retry;
|
|
111
|
+
function joinPath(...p) {
|
|
112
|
+
return path.join(...p.flatMap(u_type_1.UType.takeAsArray));
|
|
113
|
+
}
|
|
114
|
+
exports.joinPath = joinPath;
|
|
@@ -19,6 +19,7 @@ export declare class HttpResolverContext implements IHttpClient {
|
|
|
19
19
|
* @param op.headers http headers.
|
|
20
20
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
21
21
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
22
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
22
23
|
* @returns string encoded by utf-8 as response payload.
|
|
23
24
|
*/
|
|
24
25
|
get(url: string, op?: RequestOption & {
|
|
@@ -31,6 +32,7 @@ export declare class HttpResolverContext implements IHttpClient {
|
|
|
31
32
|
* @param op.headers http headers.
|
|
32
33
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
33
34
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
35
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
34
36
|
* @returns string encoded by utf-8 as response payload.
|
|
35
37
|
*/
|
|
36
38
|
post(url: string, payload: any, op?: RequestOption): Promise<HttpResponse>;
|
|
@@ -39,12 +39,12 @@ const http_method_1 = require("../../const/http-method");
|
|
|
39
39
|
const u_type_1 = require("../../func/u-type");
|
|
40
40
|
const u_file_1 = require("../../func/u-file");
|
|
41
41
|
const u_string_1 = require("../../func/u-string");
|
|
42
|
+
const u_1 = require("../../func/u");
|
|
42
43
|
exports.s_clientMode = {
|
|
43
44
|
nodejs: { id: 0, cipherOrder: null },
|
|
44
45
|
chrome: { id: 1, cipherOrder: [2, 0, 1] },
|
|
45
46
|
firefox: { id: 2, cipherOrder: [2, 1, 0] }
|
|
46
47
|
};
|
|
47
|
-
const s_timeout = 1000 * 20;
|
|
48
48
|
const s_errCode = 200;
|
|
49
49
|
const s_redirectLimit = 5;
|
|
50
50
|
const s_mode2headers = new Map([
|
|
@@ -106,6 +106,7 @@ class HttpResolverContext {
|
|
|
106
106
|
* @param op.headers http headers.
|
|
107
107
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
108
108
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
109
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
109
110
|
* @returns string encoded by utf-8 as response payload.
|
|
110
111
|
*/
|
|
111
112
|
async get(url, op) {
|
|
@@ -122,6 +123,7 @@ class HttpResolverContext {
|
|
|
122
123
|
* @param op.headers http headers.
|
|
123
124
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
124
125
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
126
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
125
127
|
* @returns string encoded by utf-8 as response payload.
|
|
126
128
|
*/
|
|
127
129
|
async post(url, payload, op) {
|
|
@@ -179,7 +181,7 @@ class HttpResolverContext {
|
|
|
179
181
|
};
|
|
180
182
|
reqHttps(u, params, payload) {
|
|
181
183
|
const rc = this._als.getStore();
|
|
182
|
-
params.timeout =
|
|
184
|
+
params.timeout = rc.timeout ?? 0;
|
|
183
185
|
params.protocol = u.protocol;
|
|
184
186
|
params.host = u.host;
|
|
185
187
|
params.path = (rc.ignoreQuery || !u.search) ? u.pathname : `${u.pathname}${u.search}`;
|
|
@@ -259,7 +261,7 @@ class HttpResolverContext {
|
|
|
259
261
|
.find(f => f.trim().startsWith("filename"))
|
|
260
262
|
?.replace(/^\s+filename\s+=/, "").trim()
|
|
261
263
|
?? u_file_1.UFile.reserveFilePath(d, `xjs-download_${u_string_1.UString.simpleTime()}`);
|
|
262
|
-
return
|
|
264
|
+
return (0, u_1.joinPath)(d, fname);
|
|
263
265
|
};
|
|
264
266
|
if (opPath) {
|
|
265
267
|
const st = u_file_1.UFile.status(opPath);
|
|
@@ -16,6 +16,10 @@ export interface RequestOption {
|
|
|
16
16
|
* default is current directory of the process with `filename` of the disposition.
|
|
17
17
|
*/
|
|
18
18
|
downloadPath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* timeout milliseconds to wait for socket inactivity. default is infinity.
|
|
21
|
+
*/
|
|
22
|
+
timeout?: number;
|
|
19
23
|
}
|
|
20
24
|
export interface HttpResponse {
|
|
21
25
|
/**
|
|
@@ -36,6 +40,7 @@ export interface IHttpClient {
|
|
|
36
40
|
* @param op.proxy proxy configuration.
|
|
37
41
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
38
42
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
43
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
39
44
|
* @param op.redirectAsNewRequest handle redirect as new request. this may be efficient when using proxy which is implemented reverse proxy.
|
|
40
45
|
* @returns http response. {@link HttpResponse}
|
|
41
46
|
*/
|
|
@@ -51,6 +56,7 @@ export interface IHttpClient {
|
|
|
51
56
|
* @param op.proxy proxy configuration.
|
|
52
57
|
* @param op.ignoreQuery {@link RequestOption.ignoreQuery}
|
|
53
58
|
* @param op.downloadPath {@link RequestOption.downloadPath}
|
|
59
|
+
* @param op.timeout {@link RequestOption.timeout}
|
|
54
60
|
* @returns http response. {@link HttpResponse}
|
|
55
61
|
*/
|
|
56
62
|
post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse>;
|