@zwa73/utils 1.0.169 → 1.0.170
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/UtilCom.d.ts +4 -4
- package/dist/UtilCom.js +7 -7
- package/dist/UtilFunctions.d.ts +4 -3
- package/dist/UtilFunctions.js +5 -5
- package/dist/UtilLogger.d.ts +1 -1
- package/dist/UtilLogger.js +1 -1
- package/package.json +1 -1
- package/src/UtilCom.ts +16 -16
- package/src/UtilFunctions.ts +8 -7
- package/src/UtilLogger.ts +2 -2
package/dist/UtilCom.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare namespace UtilCom {
|
|
|
30
30
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
31
31
|
* @returns 结果 null 为未能成功接收
|
|
32
32
|
*/
|
|
33
|
-
function httpsPost(json: JObject, options: ComPostOption, timeLimit?: number): Promise<JObject |
|
|
33
|
+
function httpsPost(json: JObject, options: ComPostOption, timeLimit?: number): Promise<JObject | undefined>;
|
|
34
34
|
/**发送一个 http POST请求并接受数据
|
|
35
35
|
* @async
|
|
36
36
|
* @param json - 数据对象
|
|
@@ -38,7 +38,7 @@ export declare namespace UtilCom {
|
|
|
38
38
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
39
39
|
* @returns 结果 null 为未能成功接收
|
|
40
40
|
*/
|
|
41
|
-
function httpPost(json: JObject, options: ComPostOption, timeLimit?: number): Promise<JObject |
|
|
41
|
+
function httpPost(json: JObject, options: ComPostOption, timeLimit?: number): Promise<JObject | undefined>;
|
|
42
42
|
/**重复一个 https POST请求并接受数据
|
|
43
43
|
* @async
|
|
44
44
|
* @param json - 数据对象
|
|
@@ -51,7 +51,7 @@ export declare namespace UtilCom {
|
|
|
51
51
|
* @param opt.try_delay - 重试间隔 秒 默认0
|
|
52
52
|
* @returns 结果 null 为未能成功接收
|
|
53
53
|
*/
|
|
54
|
-
function httpsRepeatPost(json: JObject, options: ComPostOption, verifyFn?: ReqVerifyFn<JObject |
|
|
54
|
+
function httpsRepeatPost(json: JObject, options: ComPostOption, verifyFn?: ReqVerifyFn<JObject | undefined>, opt?: RepeatPostOpt): Promise<RepeatPromiseResult<JObject | undefined> | undefined>;
|
|
55
55
|
/**重复一个 http POST请求并接受数据
|
|
56
56
|
* Object ()
|
|
57
57
|
* @async
|
|
@@ -65,6 +65,6 @@ export declare namespace UtilCom {
|
|
|
65
65
|
* @param opt.try_delay - 重试间隔 秒 默认0
|
|
66
66
|
* @returns 结果 null 为未能成功接收
|
|
67
67
|
*/
|
|
68
|
-
function httpRepeatPost(json: JObject, options: ComPostOption, verifyFn?: ReqVerifyFn<JObject |
|
|
68
|
+
function httpRepeatPost(json: JObject, options: ComPostOption, verifyFn?: ReqVerifyFn<JObject | undefined>, opt?: RepeatPostOpt): Promise<RepeatPromiseResult<JObject | undefined> | undefined>;
|
|
69
69
|
}
|
|
70
70
|
export {};
|
package/dist/UtilCom.js
CHANGED
|
@@ -36,7 +36,7 @@ var UtilCom;
|
|
|
36
36
|
* @param json - 数据对象
|
|
37
37
|
* @param options - 参数对象
|
|
38
38
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
39
|
-
* @returns 结果
|
|
39
|
+
* @returns 结果 undefined 为未能成功接收
|
|
40
40
|
*/
|
|
41
41
|
function post(posttype, json, options, timeLimit) {
|
|
42
42
|
//转换为毫秒
|
|
@@ -54,7 +54,7 @@ var UtilCom;
|
|
|
54
54
|
res.setTimeout(fixlimit, () => {
|
|
55
55
|
//res.abort();
|
|
56
56
|
UtilLogger_1.SLogger.warn(`${funcName} 接收反馈超时: ${timeLimit} ms`);
|
|
57
|
-
resolve(
|
|
57
|
+
resolve(undefined);
|
|
58
58
|
return;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -63,13 +63,13 @@ var UtilCom;
|
|
|
63
63
|
res.on('data', (chunk) => resdata += chunk);
|
|
64
64
|
res.on('error', (e) => {
|
|
65
65
|
UtilLogger_1.SLogger.warn(`${funcName} 接收反馈错误:${e}`);
|
|
66
|
-
resolve(
|
|
66
|
+
resolve(undefined);
|
|
67
67
|
return;
|
|
68
68
|
});
|
|
69
69
|
res.on('end', () => {
|
|
70
70
|
if (resdata == "") {
|
|
71
71
|
UtilLogger_1.SLogger.warn(funcName + " 接收反馈错误: resdata 为空");
|
|
72
|
-
resolve(
|
|
72
|
+
resolve(undefined);
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
try {
|
|
@@ -80,14 +80,14 @@ var UtilCom;
|
|
|
80
80
|
}
|
|
81
81
|
catch (e) {
|
|
82
82
|
UtilLogger_1.SLogger.warn(`${funcName} 接收反馈错误:${e}\n原始字符串:${resdata}`);
|
|
83
|
-
resolve(
|
|
83
|
+
resolve(undefined);
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
catch (err) {
|
|
89
89
|
UtilLogger_1.SLogger.warn(`${funcName} 未知错误:${err}`);
|
|
90
|
-
resolve(
|
|
90
|
+
resolve(undefined);
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
};
|
|
@@ -106,7 +106,7 @@ var UtilCom;
|
|
|
106
106
|
}
|
|
107
107
|
req.on('error', (e) => {
|
|
108
108
|
UtilLogger_1.SLogger.warn(`${funcName} 发送请求错误:${e}`);
|
|
109
|
-
resolve(
|
|
109
|
+
resolve(undefined);
|
|
110
110
|
});
|
|
111
111
|
req.write(jsonStr);
|
|
112
112
|
req.end();
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -35,7 +35,8 @@ type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
|
|
|
35
35
|
/**完成的重试请求 */
|
|
36
36
|
export type RepeatPromiseResult<T> = {
|
|
37
37
|
completed: T;
|
|
38
|
-
|
|
38
|
+
/**还未完成的其他Promise 若是验证失败则会返回undefined */
|
|
39
|
+
pending: Promise<T | undefined>[];
|
|
39
40
|
};
|
|
40
41
|
/**遍历对象的回调函数
|
|
41
42
|
* @param key - 字段名
|
|
@@ -113,9 +114,9 @@ export declare class UtilFunc {
|
|
|
113
114
|
* @param opt.count - 重试次数 默认3
|
|
114
115
|
* @param opt.tryInterval - 超时时间/秒 默认180 最小为5秒
|
|
115
116
|
* @param opt.tryDelay - 重试间隔时间 默认0
|
|
116
|
-
* @returns 结果
|
|
117
|
+
* @returns 结果 undefined 为全部失败/超时
|
|
117
118
|
*/
|
|
118
|
-
static repeatPromise<T>(procFn: () => Promise<T>, verifyFn?: ReqVerifyFn<T>, opt?: RepeatPromiseOpt): Promise<RepeatPromiseResult<T> |
|
|
119
|
+
static repeatPromise<T>(procFn: () => Promise<T>, verifyFn?: ReqVerifyFn<T>, opt?: RepeatPromiseOpt): Promise<RepeatPromiseResult<T> | undefined>;
|
|
119
120
|
/**创建一个限时的Promise
|
|
120
121
|
* @param func - 处理函数
|
|
121
122
|
* @param timeLimit - 毫秒限时
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -173,7 +173,7 @@ class UtilFunc {
|
|
|
173
173
|
* @param opt.count - 重试次数 默认3
|
|
174
174
|
* @param opt.tryInterval - 超时时间/秒 默认180 最小为5秒
|
|
175
175
|
* @param opt.tryDelay - 重试间隔时间 默认0
|
|
176
|
-
* @returns 结果
|
|
176
|
+
* @returns 结果 undefined 为全部失败/超时
|
|
177
177
|
*/
|
|
178
178
|
static async repeatPromise(procFn, verifyFn, opt = {}) {
|
|
179
179
|
opt.count = opt.count ?? 3;
|
|
@@ -264,17 +264,17 @@ class UtilFunc {
|
|
|
264
264
|
if (outres.stat == UtilSymbol_1.Success)
|
|
265
265
|
return outres.result;
|
|
266
266
|
}
|
|
267
|
-
return
|
|
267
|
+
return undefined;
|
|
268
268
|
}),
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
-
//全部失败或超时则返回
|
|
271
|
+
//全部失败或超时则返回 undefined
|
|
272
272
|
UtilLogger_1.SLogger.warn(`${count} 次 repeatPromise 尝试均失败`);
|
|
273
|
-
return
|
|
273
|
+
return undefined;
|
|
274
274
|
}
|
|
275
275
|
catch (err) {
|
|
276
276
|
UtilLogger_1.SLogger.warn(`repeatPromise 发生错误`, err);
|
|
277
|
-
return
|
|
277
|
+
return undefined;
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
/**创建一个限时的Promise
|
package/dist/UtilLogger.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare class SLogger {
|
|
|
83
83
|
* @param level - log等级 === null时不产生log
|
|
84
84
|
* @returns 格式化的时间字符串
|
|
85
85
|
*/
|
|
86
|
-
timeEnd(flag: string, level?: LogLevel | null): string |
|
|
86
|
+
timeEnd(flag: string, level?: LogLevel | null): string | undefined;
|
|
87
87
|
/**名称为default的slogger实例 */
|
|
88
88
|
private static get defaultInstance();
|
|
89
89
|
/**让名称为default的logger 产生一条对应等级的log 返回自身
|
package/dist/UtilLogger.js
CHANGED
|
@@ -242,7 +242,7 @@ class SLogger {
|
|
|
242
242
|
const start = SLogger.timeTable[flag];
|
|
243
243
|
if (start == null) {
|
|
244
244
|
this.warn("SLogger.timeEnd 错误 flag:" + flag + " 不存在");
|
|
245
|
-
return
|
|
245
|
+
return;
|
|
246
246
|
}
|
|
247
247
|
const timelen = process.hrtime(start);
|
|
248
248
|
const totalMicroseconds = (timelen[0] * 1e9 + timelen[1]) / 1000;
|
package/package.json
CHANGED
package/src/UtilCom.ts
CHANGED
|
@@ -35,9 +35,9 @@ export namespace UtilCom{
|
|
|
35
35
|
* @param json - 数据对象
|
|
36
36
|
* @param options - 参数对象
|
|
37
37
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
38
|
-
* @returns 结果
|
|
38
|
+
* @returns 结果 undefined 为未能成功接收
|
|
39
39
|
*/
|
|
40
|
-
function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|
|
|
40
|
+
function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|undefined>{
|
|
41
41
|
//转换为毫秒
|
|
42
42
|
const hasTimeLimit = (timeLimit ? timeLimit>=10 : false );
|
|
43
43
|
if(hasTimeLimit && timeLimit!=undefined) timeLimit*=1000;
|
|
@@ -54,7 +54,7 @@ function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLim
|
|
|
54
54
|
res.setTimeout(fixlimit, ()=>{
|
|
55
55
|
//res.abort();
|
|
56
56
|
SLogger.warn(`${funcName} 接收反馈超时: ${timeLimit} ms`);
|
|
57
|
-
resolve(
|
|
57
|
+
resolve(undefined);
|
|
58
58
|
return;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -65,14 +65,14 @@ function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLim
|
|
|
65
65
|
|
|
66
66
|
res.on('error',(e)=>{
|
|
67
67
|
SLogger.warn(`${funcName} 接收反馈错误:${e}`);
|
|
68
|
-
resolve(
|
|
68
|
+
resolve(undefined);
|
|
69
69
|
return;
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
res.on('end',()=>{
|
|
73
73
|
if(resdata==""){
|
|
74
74
|
SLogger.warn(funcName+" 接收反馈错误: resdata 为空");
|
|
75
|
-
resolve(
|
|
75
|
+
resolve(undefined);
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
try{
|
|
@@ -83,13 +83,13 @@ function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLim
|
|
|
83
83
|
}
|
|
84
84
|
catch(e){
|
|
85
85
|
SLogger.warn(`${funcName} 接收反馈错误:${e}\n原始字符串:${resdata}`);
|
|
86
|
-
resolve(
|
|
86
|
+
resolve(undefined);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}catch(err){
|
|
91
91
|
SLogger.warn(`${funcName} 未知错误:${err}`);
|
|
92
|
-
resolve(
|
|
92
|
+
resolve(undefined);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
};
|
|
@@ -110,7 +110,7 @@ function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLim
|
|
|
110
110
|
|
|
111
111
|
req.on('error', (e)=>{
|
|
112
112
|
SLogger.warn(`${funcName} 发送请求错误:${e}`);
|
|
113
|
-
resolve(
|
|
113
|
+
resolve(undefined);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
req.write(jsonStr);
|
|
@@ -125,7 +125,7 @@ function post(posttype:"http"|"https",json:JObject,options:ComPostOption,timeLim
|
|
|
125
125
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
126
126
|
* @returns 结果 null 为未能成功接收
|
|
127
127
|
*/
|
|
128
|
-
export function httpsPost(json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|
|
|
128
|
+
export function httpsPost(json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|undefined>{
|
|
129
129
|
return post("https",json,options,timeLimit);
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -136,7 +136,7 @@ export function httpsPost(json:JObject,options:ComPostOption,timeLimit?:number):
|
|
|
136
136
|
* @param timeLimit - 超时时间/秒 最小为10秒
|
|
137
137
|
* @returns 结果 null 为未能成功接收
|
|
138
138
|
*/
|
|
139
|
-
export function httpPost(json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|
|
|
139
|
+
export function httpPost(json:JObject,options:ComPostOption,timeLimit?:number):Promise<JObject|undefined>{
|
|
140
140
|
return post("http",json,options,timeLimit);
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -155,8 +155,8 @@ export function httpPost(json:JObject,options:ComPostOption,timeLimit?:number):P
|
|
|
155
155
|
* @param opt.try_delay - 重试间隔 秒 默认0
|
|
156
156
|
* @returns 结果 null 为未能成功接收
|
|
157
157
|
*/
|
|
158
|
-
async function repeatPost(posttype:"http"|"https",json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|
|
|
159
|
-
Promise<RepeatPromiseResult<JObject|
|
|
158
|
+
async function repeatPost(posttype:"http"|"https",json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|undefined>,opt:RepeatPostOpt={}):
|
|
159
|
+
Promise<RepeatPromiseResult<JObject|undefined>|undefined>{
|
|
160
160
|
opt.count = opt.count??3;
|
|
161
161
|
opt.tryInterval = opt.tryInterval??180;
|
|
162
162
|
opt.tryDelay = opt.tryDelay??1;
|
|
@@ -178,8 +178,8 @@ Promise<RepeatPromiseResult<JObject|null>|null>{
|
|
|
178
178
|
* @param opt.try_delay - 重试间隔 秒 默认0
|
|
179
179
|
* @returns 结果 null 为未能成功接收
|
|
180
180
|
*/
|
|
181
|
-
export function httpsRepeatPost(json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|
|
|
182
|
-
Promise<RepeatPromiseResult<JObject|
|
|
181
|
+
export function httpsRepeatPost(json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|undefined>,opt?:RepeatPostOpt):
|
|
182
|
+
Promise<RepeatPromiseResult<JObject|undefined>|undefined>{
|
|
183
183
|
return repeatPost("https",json,options,verifyFn,opt);
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -196,8 +196,8 @@ Promise<RepeatPromiseResult<JObject|null>|null>{
|
|
|
196
196
|
* @param opt.try_delay - 重试间隔 秒 默认0
|
|
197
197
|
* @returns 结果 null 为未能成功接收
|
|
198
198
|
*/
|
|
199
|
-
export function httpRepeatPost(json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|
|
|
200
|
-
Promise<RepeatPromiseResult<JObject|
|
|
199
|
+
export function httpRepeatPost(json:JObject,options:ComPostOption,verifyFn?:ReqVerifyFn<JObject|undefined>,opt?:RepeatPostOpt):
|
|
200
|
+
Promise<RepeatPromiseResult<JObject|undefined>|undefined>{
|
|
201
201
|
return repeatPost("http",json,options,verifyFn,opt);
|
|
202
202
|
}
|
|
203
203
|
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -59,7 +59,8 @@ type PromiseResult<T> = {
|
|
|
59
59
|
/**完成的重试请求 */
|
|
60
60
|
export type RepeatPromiseResult<T> = {
|
|
61
61
|
completed:T;
|
|
62
|
-
|
|
62
|
+
/**还未完成的其他Promise 若是验证失败则会返回undefined */
|
|
63
|
+
pending:Promise<T|undefined>[];
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
|
|
@@ -226,11 +227,11 @@ static getNeverResolvedPromise<T>():Promise<T>{
|
|
|
226
227
|
* @param opt.count - 重试次数 默认3
|
|
227
228
|
* @param opt.tryInterval - 超时时间/秒 默认180 最小为5秒
|
|
228
229
|
* @param opt.tryDelay - 重试间隔时间 默认0
|
|
229
|
-
* @returns 结果
|
|
230
|
+
* @returns 结果 undefined 为全部失败/超时
|
|
230
231
|
*/
|
|
231
232
|
@LogTimeAsync("repeatPromise ",true)
|
|
232
233
|
static async repeatPromise<T>(procFn:()=>Promise<T>,verifyFn?:ReqVerifyFn<T>,opt:RepeatPromiseOpt = {}):
|
|
233
|
-
Promise<RepeatPromiseResult<T>|
|
|
234
|
+
Promise<RepeatPromiseResult<T>|undefined>{
|
|
234
235
|
opt.count = opt.count??3;
|
|
235
236
|
opt.tryInterval = opt.tryInterval??180;
|
|
236
237
|
let {count,tryInterval} = opt;
|
|
@@ -323,16 +324,16 @@ Promise<RepeatPromiseResult<T>|null>{
|
|
|
323
324
|
const outres = await curObj.result;
|
|
324
325
|
if(outres.stat==Success) return outres.result;
|
|
325
326
|
}
|
|
326
|
-
return
|
|
327
|
+
return undefined;
|
|
327
328
|
}),
|
|
328
329
|
};
|
|
329
330
|
}
|
|
330
|
-
//全部失败或超时则返回
|
|
331
|
+
//全部失败或超时则返回 undefined
|
|
331
332
|
SLogger.warn(`${count} 次 repeatPromise 尝试均失败`);
|
|
332
|
-
return
|
|
333
|
+
return undefined;
|
|
333
334
|
}catch(err){
|
|
334
335
|
SLogger.warn(`repeatPromise 发生错误`,err);
|
|
335
|
-
return
|
|
336
|
+
return undefined;
|
|
336
337
|
}
|
|
337
338
|
}
|
|
338
339
|
|
package/src/UtilLogger.ts
CHANGED
|
@@ -230,11 +230,11 @@ export class SLogger{
|
|
|
230
230
|
* @param level - log等级 === null时不产生log
|
|
231
231
|
* @returns 格式化的时间字符串
|
|
232
232
|
*/
|
|
233
|
-
timeEnd(flag:string,level:LogLevel|null="info"):string|
|
|
233
|
+
timeEnd(flag:string,level:LogLevel|null="info"):string|undefined{
|
|
234
234
|
const start = SLogger.timeTable[flag];
|
|
235
235
|
if(start==null){
|
|
236
236
|
this.warn("SLogger.timeEnd 错误 flag:"+flag+" 不存在");
|
|
237
|
-
return
|
|
237
|
+
return;
|
|
238
238
|
}
|
|
239
239
|
const timelen = process.hrtime(start as any as [number,number]);
|
|
240
240
|
|