@zwa73/utils 1.0.254 → 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.
@@ -0,0 +1,4 @@
1
+ import { UtilFT } from "./UtilFileTools";
2
+ export declare const outcome: typeof import("@zwa73/js-utils").JsFunc.outcome, extractOutcome: typeof import("@zwa73/js-utils").JsFunc.extractOutcome, success: typeof import("@zwa73/js-utils").JsFunc.success, failed: typeof import("@zwa73/js-utils").JsFunc.failed, match: typeof import("@zwa73/js-utils").JsFunc.match, isSafeNumber: typeof import("@zwa73/js-utils").JsFunc.isSafeNumber, assertType: typeof import("@zwa73/js-utils").JsFunc.assertType, assertLiteral: typeof import("@zwa73/js-utils").JsFunc.assertLiteral, deepClone: typeof import("@zwa73/js-utils").JsFunc.deepClone, sleep: typeof import("@zwa73/js-utils").JsFunc.sleep, stringifyJToken: typeof import("@zwa73/js-utils").JsFunc.stringifyJToken, getTime: typeof import("@zwa73/js-utils").JsFunc.getTime, mapEntries: typeof import("@zwa73/js-utils").JsFunc.mapEntries, dedent: typeof import("@zwa73/js-utils").JsFunc.dedent, throwError: typeof import("@zwa73/js-utils").JsFunc.throwError, eitherize: typeof import("@zwa73/js-utils").JsFunc.eitherize, memoize: typeof import("@zwa73/js-utils").JsFunc.memoize, lazyFunction: typeof import("@zwa73/js-utils").JsFunc.lazyFunction, ivk: typeof import("@zwa73/js-utils").JsFunc.ivk, l2s: typeof import("@zwa73/js-utils").JsFunc.l2s, s2l: typeof import("@zwa73/js-utils").JsFunc.s2l, structEqual: typeof import("@zwa73/js-utils").JsFunc.structEqual, range: typeof import("@zwa73/js-utils").JsFunc.range, preset: typeof import("@zwa73/js-utils").JsFunc.preset;
3
+ export declare const stylizePath: typeof UtilFT.stylizePath, posixizePath: typeof UtilFT.posixizePath, win32izePath: typeof UtilFT.win32izePath, currosizePath: typeof UtilFT.currosizePath;
4
+ export declare const when: <S extends import("@zwa73/js-utils").Keyable, T, R>(stat: import("@zwa73/js-utils").Literal<S>, f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<S>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends S ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<S, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<S>> | R), map: typeof import("@zwa73/js-utils").JsFP.map, flow: typeof import("@zwa73/js-utils").JsFP.flow, pipe: typeof import("@zwa73/js-utils").JsFP.pipe, chain: <T, R>(f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Success ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Success, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Success>> | R), alt: <T, R>(f: (arg: Extract<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>>) => R) => (arg: T) => ("E" extends import("@zwa73/js-utils").ProperSubsetCheck<symbol, T> ? T | R : import("@zwa73/js-utils").MatchableFlag<T> extends typeof import("@zwa73/js-utils").Failed ? R : import("@zwa73/js-utils").MatchableFlag<T> extends Exclude<typeof import("@zwa73/js-utils").Failed, import("@zwa73/js-utils").MatchableFlag<T>> ? T : Exclude<T, import("@zwa73/js-utils").Matchable<typeof import("@zwa73/js-utils").Failed>> | R), tap: typeof import("@zwa73/js-utils").JsFP.tap, curry: typeof import("@zwa73/js-utils").JsFP.curry;
@@ -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.http(`accept json 接受信息 data:`, UtilFunctions_1.UtilFunc.stringifyJToken(obj, { compress: true, space: 2 }), `result:`, UtilFunctions_1.UtilFunc.stringifyJToken(rest, { compress: true, space: 2 }));
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()}`;
@@ -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("SLogger.timeEnd 错误 flag:" + flag + " 不存在");
244
+ this.warn(`SLogger.timeEnd 错误 flag:${flag} 不存在`);
245
245
  return;
246
246
  }
247
247
  const timelen = process.hrtime(start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.254",
3
+ "version": "1.0.256",
4
4
  "description": "my utils",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {