@zwa73/utils 1.0.230 → 1.0.232
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/UtilFileTools.d.ts +3 -5
- package/dist/UtilFileTools.js +4 -4
- package/dist/UtilHttp.js +31 -21
- package/package.json +1 -3
package/dist/UtilFileTools.d.ts
CHANGED
|
@@ -27,8 +27,6 @@ type FileSearchGlobOpt = Partial<{
|
|
|
27
27
|
type FileSearchRegexOpt = Partial<{
|
|
28
28
|
/**搜索子目录 默认 true */
|
|
29
29
|
recursive: boolean;
|
|
30
|
-
/**无效项 */
|
|
31
|
-
relative: never;
|
|
32
30
|
/**忽略目录 默认 true */
|
|
33
31
|
nodir: boolean;
|
|
34
32
|
}>;
|
|
@@ -172,7 +170,7 @@ export declare namespace UtilFT {
|
|
|
172
170
|
* @param dir - 起始目录
|
|
173
171
|
* @param traitRegex - 正则表达式
|
|
174
172
|
* @param opt - 可选参数
|
|
175
|
-
* @param opt.
|
|
173
|
+
* @param opt.recursive - 搜索子目录
|
|
176
174
|
* @returns 文件名路径数组
|
|
177
175
|
*/
|
|
178
176
|
function fileSearchRegexSync(dir: string, traitRegex: string | RegExp, opt?: FileSearchRegexOpt): string[];
|
|
@@ -181,7 +179,7 @@ export declare namespace UtilFT {
|
|
|
181
179
|
* @param globPattern - glob匹配
|
|
182
180
|
* @param opt - 可选参数
|
|
183
181
|
* @param opt.ignore - 忽略的文件
|
|
184
|
-
* @param opt.
|
|
182
|
+
* @param opt.recursive - 忽略目录 默认 true
|
|
185
183
|
* @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
|
|
186
184
|
* @returns 文件绝对路径数组
|
|
187
185
|
*/
|
|
@@ -191,7 +189,7 @@ export declare namespace UtilFT {
|
|
|
191
189
|
* @param globPattern - glob匹配
|
|
192
190
|
* @param opt - 可选参数
|
|
193
191
|
* @param opt.ignore - 忽略的文件
|
|
194
|
-
* @param opt.
|
|
192
|
+
* @param opt.recursive - 忽略目录 默认 true
|
|
195
193
|
* @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
|
|
196
194
|
* @returns 文件绝对路径数组
|
|
197
195
|
*/
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -297,7 +297,7 @@ var UtilFT;
|
|
|
297
297
|
return recursive(nextPath);
|
|
298
298
|
return [nextPath, ...await recursive(nextPath)];
|
|
299
299
|
}
|
|
300
|
-
if (regex.test(nextPath))
|
|
300
|
+
if (subFile.isFile() && regex.test(nextPath))
|
|
301
301
|
return [subFilePath];
|
|
302
302
|
return [undefined];
|
|
303
303
|
}));
|
|
@@ -312,7 +312,7 @@ var UtilFT;
|
|
|
312
312
|
* @param dir - 起始目录
|
|
313
313
|
* @param traitRegex - 正则表达式
|
|
314
314
|
* @param opt - 可选参数
|
|
315
|
-
* @param opt.
|
|
315
|
+
* @param opt.recursive - 搜索子目录
|
|
316
316
|
* @returns 文件名路径数组
|
|
317
317
|
*/
|
|
318
318
|
function fileSearchRegexSync(dir, traitRegex, opt) {
|
|
@@ -347,7 +347,7 @@ var UtilFT;
|
|
|
347
347
|
* @param globPattern - glob匹配
|
|
348
348
|
* @param opt - 可选参数
|
|
349
349
|
* @param opt.ignore - 忽略的文件
|
|
350
|
-
* @param opt.
|
|
350
|
+
* @param opt.recursive - 忽略目录 默认 true
|
|
351
351
|
* @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
|
|
352
352
|
* @returns 文件绝对路径数组
|
|
353
353
|
*/
|
|
@@ -364,7 +364,7 @@ var UtilFT;
|
|
|
364
364
|
* @param globPattern - glob匹配
|
|
365
365
|
* @param opt - 可选参数
|
|
366
366
|
* @param opt.ignore - 忽略的文件
|
|
367
|
-
* @param opt.
|
|
367
|
+
* @param opt.recursive - 忽略目录 默认 true
|
|
368
368
|
* @param opt.nodir - 忽略大小写 默认 跟随系统 mac/win为true 其他false
|
|
369
369
|
* @returns 文件绝对路径数组
|
|
370
370
|
*/
|
package/dist/UtilHttp.js
CHANGED
|
@@ -185,8 +185,8 @@ class UtilHttp {
|
|
|
185
185
|
UtilLogger_1.SLogger.http(`json accept 接受信息 data:`, UtilFunctions_1.UtilFunc.stringifyJToken(obj, { compress: true, space: 2 }), `result:`, UtilFunctions_1.UtilFunc.stringifyJToken(rest, { compress: true, space: 2 }));
|
|
186
186
|
return { ...rest, data: obj };
|
|
187
187
|
}
|
|
188
|
-
catch (
|
|
189
|
-
UtilLogger_1.SLogger.warn(`json accept
|
|
188
|
+
catch (err) {
|
|
189
|
+
UtilLogger_1.SLogger.warn(`json accept 接收反馈错误:`, err, UtilFunctions_1.UtilFunc.stringifyJToken(result, { compress: true, space: 2 }));
|
|
190
190
|
return { ...result, raw: data, data: null };
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -362,18 +362,29 @@ class UtilHttp {
|
|
|
362
362
|
*/
|
|
363
363
|
static async request(option, proc, reduce, init) {
|
|
364
364
|
const { protocol, timeout, ...baseReqOpt } = option;
|
|
365
|
+
const plusTimeout = (timeout ?? 0) + 1000;
|
|
365
366
|
const hasTimeLimit = (timeout ? timeout >= 10_000 : false);
|
|
366
367
|
const flagName = `UtilCom.request ${protocol}${baseReqOpt.method} ${UtilFunctions_1.UtilFunc.genUUID()}`;
|
|
367
368
|
const reduceQueue = new js_utils_1.PromiseQueue();
|
|
368
369
|
let dataPromise = null;
|
|
369
370
|
return new Promise(async (resolve, rejecte) => {
|
|
371
|
+
const finallyTimeout = hasTimeLimit
|
|
372
|
+
? setTimeout(() => {
|
|
373
|
+
UtilLogger_1.SLogger.warn(`${flagName} finallyTimeout 超时 ${timeout} ms, 终止请求`);
|
|
374
|
+
req.destroy();
|
|
375
|
+
resolve(undefined);
|
|
376
|
+
}, plusTimeout)
|
|
377
|
+
: undefined;
|
|
378
|
+
const finallyResolve = (t) => {
|
|
379
|
+
clearTimeout(finallyTimeout);
|
|
380
|
+
resolve(t);
|
|
381
|
+
};
|
|
370
382
|
const resFunc = (res) => {
|
|
371
383
|
try {
|
|
372
384
|
//请求超时
|
|
373
385
|
if (hasTimeLimit) {
|
|
374
386
|
res.setTimeout(timeout, () => {
|
|
375
|
-
UtilLogger_1.SLogger.warn(`${flagName}
|
|
376
|
-
res.destroy();
|
|
387
|
+
UtilLogger_1.SLogger.warn(`${flagName} http.response 触发 ${timeout} ms 超时, 继续挂起等待`);
|
|
377
388
|
});
|
|
378
389
|
}
|
|
379
390
|
let mergedata = init;
|
|
@@ -381,18 +392,18 @@ class UtilHttp {
|
|
|
381
392
|
res.on('data', chunk => {
|
|
382
393
|
dataPromise = reduceQueue
|
|
383
394
|
.enqueue(async () => mergedata = await reduce(mergedata, chunk))
|
|
384
|
-
.catch(
|
|
385
|
-
UtilLogger_1.SLogger.error(`${flagName} reduce
|
|
386
|
-
|
|
395
|
+
.catch(err => {
|
|
396
|
+
UtilLogger_1.SLogger.error(`${flagName} reduce函数错误:`, err, `chunk:${chunk}\nmergedata:`, mergedata);
|
|
397
|
+
finallyResolve(undefined);
|
|
387
398
|
});
|
|
388
399
|
});
|
|
389
|
-
res.on('error',
|
|
390
|
-
UtilLogger_1.SLogger.warn(`${flagName}
|
|
391
|
-
|
|
400
|
+
res.on('error', err => {
|
|
401
|
+
UtilLogger_1.SLogger.warn(`${flagName} 接收反馈错误:`, err);
|
|
402
|
+
finallyResolve(undefined);
|
|
392
403
|
});
|
|
393
404
|
res.on('end', async () => {
|
|
394
405
|
await dataPromise;
|
|
395
|
-
|
|
406
|
+
finallyResolve({
|
|
396
407
|
headers: res.headers,
|
|
397
408
|
statusCode: res.statusCode,
|
|
398
409
|
data: mergedata,
|
|
@@ -400,8 +411,8 @@ class UtilHttp {
|
|
|
400
411
|
});
|
|
401
412
|
}
|
|
402
413
|
catch (err) {
|
|
403
|
-
UtilLogger_1.SLogger.warn(`${flagName}
|
|
404
|
-
|
|
414
|
+
UtilLogger_1.SLogger.warn(`${flagName} 未知错误:`, err);
|
|
415
|
+
finallyResolve(undefined);
|
|
405
416
|
return;
|
|
406
417
|
}
|
|
407
418
|
};
|
|
@@ -412,20 +423,19 @@ class UtilHttp {
|
|
|
412
423
|
//请求超时
|
|
413
424
|
if (hasTimeLimit) {
|
|
414
425
|
req.setTimeout(timeout, () => {
|
|
415
|
-
UtilLogger_1.SLogger.warn(`${flagName}
|
|
416
|
-
req.destroy();
|
|
426
|
+
UtilLogger_1.SLogger.warn(`${flagName} http.request 触发 ${timeout} ms 超时, 继续挂起等待`);
|
|
417
427
|
});
|
|
418
428
|
}
|
|
419
|
-
req.on('error',
|
|
420
|
-
UtilLogger_1.SLogger.warn(`${flagName}
|
|
421
|
-
|
|
429
|
+
req.on('error', err => {
|
|
430
|
+
UtilLogger_1.SLogger.warn(`${flagName} 发送请求错误:`, err);
|
|
431
|
+
finallyResolve(undefined);
|
|
422
432
|
});
|
|
423
433
|
try {
|
|
424
434
|
await proc(req);
|
|
425
435
|
}
|
|
426
|
-
catch (
|
|
427
|
-
UtilLogger_1.SLogger.error(`${flagName} proc
|
|
428
|
-
|
|
436
|
+
catch (err) {
|
|
437
|
+
UtilLogger_1.SLogger.error(`${flagName} proc函数错误:`, err);
|
|
438
|
+
finallyResolve(undefined);
|
|
429
439
|
}
|
|
430
440
|
});
|
|
431
441
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.232",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,8 +37,6 @@
|
|
|
37
37
|
"@types/jest": "^29.5.12",
|
|
38
38
|
"@types/node": "^20.14.11",
|
|
39
39
|
"@zwa73/dev-utils": "*",
|
|
40
|
-
"jest": "^29.7.0",
|
|
41
|
-
"ts-jest": "^29.1.2",
|
|
42
40
|
"tsc-alias": "^1.8.8",
|
|
43
41
|
"typescript": "^5.3.3"
|
|
44
42
|
},
|