@zwa73/utils 1.0.255 → 1.0.256
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/UtilHttp.d.ts +4 -2
- package/dist/UtilHttp.js +4 -4
- package/dist/UtilLogger.js +1 -1
- package/package.json +1 -1
package/dist/UtilHttp.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnyString, JToken, MPromise, PartialOption, StatusVerifyFn } from "./Ut
|
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import { PromiseRetries } from "./UtilFunctions";
|
|
4
4
|
import FormData from "form-data";
|
|
5
|
-
import { PromiseQueue } from "@zwa73/js-utils";
|
|
5
|
+
import { LogLevel, PromiseQueue } from "@zwa73/js-utils";
|
|
6
6
|
/**网络请求返回值 */
|
|
7
7
|
export type RequestResult<T> = {
|
|
8
8
|
/**响应头 */
|
|
@@ -14,6 +14,8 @@ export type RequestResult<T> = {
|
|
|
14
14
|
};
|
|
15
15
|
/**网络请求选项 */
|
|
16
16
|
export type RequestOption = {
|
|
17
|
+
/**请求的log等级 默认http 不影响警告 */
|
|
18
|
+
logLevel?: LogLevel;
|
|
17
19
|
/**请求协议 */
|
|
18
20
|
protocol: 'http:' | 'https:';
|
|
19
21
|
/**超时时间/毫秒 最小为10_000 默认无限 */
|
|
@@ -41,7 +43,7 @@ export type QueryRequestData = NodeJS.Dict<string | number | boolean | readonly
|
|
|
41
43
|
/**请求处理函数 需调用req.end() */
|
|
42
44
|
export type RequestProcFn = (req: http.ClientRequest) => MPromise<void>;
|
|
43
45
|
/**结果处理函数 */
|
|
44
|
-
export type RequestParseFn<D, R> = (result: RequestResult<D> | undefined) => MPromise<R>;
|
|
46
|
+
export type RequestParseFn<D, R> = (result: RequestResult<D> | undefined, opt: RequestOption) => MPromise<R>;
|
|
45
47
|
/**数据处理函数 */
|
|
46
48
|
export type RequestReduceFn<T> = (acc: T, data: string) => MPromise<T>;
|
|
47
49
|
/**数据初始化函数 */
|
package/dist/UtilHttp.js
CHANGED
|
@@ -162,7 +162,7 @@ class UtilHttp {
|
|
|
162
162
|
const acceptProc = {
|
|
163
163
|
init: () => '',
|
|
164
164
|
reduce: (acc, curr) => acc + curr,
|
|
165
|
-
parse: result => {
|
|
165
|
+
parse: (result, opt) => {
|
|
166
166
|
if (result == undefined) {
|
|
167
167
|
UtilLogger_1.SLogger.warn(`accept json 接收反馈错误: 响应结果无效`);
|
|
168
168
|
return undefined;
|
|
@@ -174,7 +174,7 @@ class UtilHttp {
|
|
|
174
174
|
}
|
|
175
175
|
try {
|
|
176
176
|
const obj = JSON.parse(data.trim());
|
|
177
|
-
UtilLogger_1.SLogger.
|
|
177
|
+
UtilLogger_1.SLogger.log(opt.logLevel, `accept json 接受信息 data:`, UtilFunctions_1.UtilFunc.stringifyJToken(obj, { compress: true, space: 2 }), `result:`, UtilFunctions_1.UtilFunc.stringifyJToken(rest, { compress: true, space: 2 }));
|
|
178
178
|
return { ...rest, data: obj };
|
|
179
179
|
}
|
|
180
180
|
catch (err) {
|
|
@@ -360,7 +360,7 @@ class UtilHttp {
|
|
|
360
360
|
? await this._accept(arg)
|
|
361
361
|
: this._accept;
|
|
362
362
|
const res = await UtilHttp.request(fullopt, sendProc, acceptProc);
|
|
363
|
-
return parse(res);
|
|
363
|
+
return parse(res, fullopt);
|
|
364
364
|
}
|
|
365
365
|
/**重复发送网络请求
|
|
366
366
|
* @param verify - 有效性验证函数
|
|
@@ -384,7 +384,7 @@ class UtilHttp {
|
|
|
384
384
|
static async request(option, sendProc, acceptProc) {
|
|
385
385
|
const { reduce: reqReduce, init: reqInit } = acceptProc;
|
|
386
386
|
const { proc: reqProc } = sendProc;
|
|
387
|
-
const { protocol, timeout = 0, ...baseReqOpt } = option;
|
|
387
|
+
const { protocol, logLevel = 'http', timeout = 0, ...baseReqOpt } = option;
|
|
388
388
|
const plusTimeout = timeout + 1000;
|
|
389
389
|
const hasTimeLimit = timeout >= 10_000;
|
|
390
390
|
const flagName = `UtilCom.request ${protocol}${baseReqOpt.method} ${UtilFunctions_1.UtilFunc.genUUID()}`;
|
package/dist/UtilLogger.js
CHANGED
|
@@ -241,7 +241,7 @@ class SLogger {
|
|
|
241
241
|
timeEnd(flag, level = "info") {
|
|
242
242
|
const start = SLogger.timeTable[flag];
|
|
243
243
|
if (start == null) {
|
|
244
|
-
this.warn(
|
|
244
|
+
this.warn(`SLogger.timeEnd 错误 flag:${flag} 不存在`);
|
|
245
245
|
return;
|
|
246
246
|
}
|
|
247
247
|
const timelen = process.hrtime(start);
|