@zwa73/utils 1.0.214 → 1.0.216

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.
@@ -1 +1 @@
1
- export { Piper, Stream, Hbs, BridgeInterface, Bridge, SmartCache, DListMiddleNode, DLinkedList } from "@zwa73/js-utils";
1
+ export { Piper, Stream, Hbs, BridgeInterface, Bridge, SmartCache, DListMiddleNode, DLinkedList, PromiseQueue } from "@zwa73/js-utils";
package/dist/UtilClass.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DLinkedList = exports.SmartCache = exports.Bridge = exports.Hbs = exports.Stream = exports.Piper = void 0;
3
+ exports.PromiseQueue = exports.DLinkedList = exports.SmartCache = exports.Bridge = exports.Hbs = exports.Stream = exports.Piper = void 0;
4
4
  //#region UtilClass转导
5
5
  var js_utils_1 = require("@zwa73/js-utils");
6
6
  Object.defineProperty(exports, "Piper", { enumerable: true, get: function () { return js_utils_1.Piper; } });
@@ -9,4 +9,5 @@ Object.defineProperty(exports, "Hbs", { enumerable: true, get: function () { ret
9
9
  Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return js_utils_1.Bridge; } });
10
10
  Object.defineProperty(exports, "SmartCache", { enumerable: true, get: function () { return js_utils_1.SmartCache; } });
11
11
  Object.defineProperty(exports, "DLinkedList", { enumerable: true, get: function () { return js_utils_1.DLinkedList; } });
12
+ Object.defineProperty(exports, "PromiseQueue", { enumerable: true, get: function () { return js_utils_1.PromiseQueue; } });
12
13
  //#endregion
package/dist/UtilCom.d.ts CHANGED
@@ -216,7 +216,7 @@ export declare class UtilCom<D extends Partial<RequestOption> & Required<Pick<Re
216
216
  option: PartialOption<RequestOption, D>;
217
217
  verify?: StatusVerifyFn<ParseResult<A>>;
218
218
  retries?: PromiseRetries;
219
- }, ...datas: SendParams<S>): Promise<import("./UtilFunctions").PromiseRetryResult<ParseResult<A>>>;
219
+ }, ...datas: SendParams<S>): Promise<import("@zwa73/js-utils").PromiseRetryResult<ParseResult<A>>>;
220
220
  /**发送网络请求
221
221
  * @param option - 网络请求选项
222
222
  * @param proc - 请求处理函数 需调用req.end()
package/dist/UtilCom.js CHANGED
@@ -11,6 +11,7 @@ const UtilFunctions_1 = require("./UtilFunctions");
11
11
  const querystring_1 = __importDefault(require("querystring"));
12
12
  const http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
13
13
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
14
+ const js_utils_1 = require("@zwa73/js-utils");
14
15
  const AcceptTypeList = ["json", "string"];
15
16
  const SendTypeList = ["json", "query", "formData", "none"];
16
17
  const SendNoneProc = {
@@ -286,7 +287,7 @@ class UtilCom {
286
287
  let mergedata = init;
287
288
  res.setEncoding('utf8');
288
289
  res.on('data', chunk => {
289
- dataPromise = UtilFunctions_1.UtilFunc.queueProc(flagName, async () => mergedata = await reduce(mergedata, chunk));
290
+ dataPromise = js_utils_1.PromiseQueue.enqueue(flagName, async () => mergedata = await reduce(mergedata, chunk));
290
291
  });
291
292
  res.on('error', (e) => {
292
293
  UtilLogger_1.SLogger.warn(`${flagName} 接收反馈错误:${e}`);
@@ -115,7 +115,7 @@ export declare namespace UtilFT {
115
115
  * @param opt.forceExt - 不自动修改扩展名为json
116
116
  * @returns 加载完成的对象或默认值
117
117
  */
118
- function loadJSONFile<T extends JToken>(filePath: string, opt: LoadJsonFileOpt<T>): Promise<T>;
118
+ function loadJSONFile<T extends JToken>(filePath: string, opt?: LoadJsonFileOpt<T>): Promise<T>;
119
119
  /**写入JSON文件
120
120
  * @async
121
121
  * @param filePath - 文件路径
@@ -142,37 +142,49 @@ var UtilFT;
142
142
  }
143
143
  UtilFT.ensurePathExistsSync = ensurePathExistsSync;
144
144
  function loadJSONFileSync(filePath, opt) {
145
- if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
146
- filePath += '.json';
147
- const str = pathExistsSync(filePath)
148
- ? fs.readFileSync(filePath, "utf-8")
149
- : "";
150
- // 如果不存在则返回默认值
151
- if (str == "" || str == null) {
152
- if (opt?.default !== undefined)
153
- return opt.default;
154
- return {};
145
+ try {
146
+ if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
147
+ filePath += '.json';
148
+ const str = pathExistsSync(filePath)
149
+ ? fs.readFileSync(filePath, "utf-8")
150
+ : "";
151
+ // 如果不存在则返回默认值
152
+ if (str == "" || str == null) {
153
+ if (opt?.default !== undefined)
154
+ return opt.default;
155
+ return {};
156
+ }
157
+ if (opt?.json5)
158
+ return JSON5.parse(str);
159
+ return JSON.parse(str);
160
+ }
161
+ catch (e) {
162
+ UtilLogger_1.SLogger.error(`loadJSONFileSync 错误 filePath:${filePath}`);
163
+ throw e;
155
164
  }
156
- if (opt?.json5)
157
- return JSON5.parse(str);
158
- return JSON.parse(str);
159
165
  }
160
166
  UtilFT.loadJSONFileSync = loadJSONFileSync;
161
167
  async function loadJSONFile(filePath, opt) {
162
- if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
163
- filePath += '.json';
164
- const str = (await pathExists(filePath))
165
- ? await fs.promises.readFile(filePath, "utf-8")
166
- : "";
167
- // 如果不存在则返回默认值
168
- if (str == "" || str == null) {
169
- if (opt?.default !== undefined)
170
- return opt.default;
171
- return {};
168
+ try {
169
+ if (opt?.forceExt !== true && pathe_1.default.extname(filePath) !== '.json')
170
+ filePath += '.json';
171
+ const str = (await pathExists(filePath))
172
+ ? await fs.promises.readFile(filePath, "utf-8")
173
+ : "";
174
+ // 如果不存在则返回默认值
175
+ if (str == "" || str == null) {
176
+ if (opt?.default !== undefined)
177
+ return opt.default;
178
+ return {};
179
+ }
180
+ if (opt?.json5)
181
+ return JSON5.parse(str);
182
+ return JSON.parse(str);
183
+ }
184
+ catch (e) {
185
+ UtilLogger_1.SLogger.error(`loadJSONFile 错误 filePath:${filePath}`);
186
+ throw e;
172
187
  }
173
- if (opt?.json5)
174
- return JSON5.parse(str);
175
- return JSON.parse(str);
176
188
  }
177
189
  UtilFT.loadJSONFile = loadJSONFile;
178
190
  /**写入JSON文件
@@ -58,5 +58,5 @@ declare class _UtilFunc {
58
58
  */
59
59
  static dynamicImport(moduleName: string): Promise<any>;
60
60
  }
61
- export declare const UtilFunc: ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "genUUID" | "range" | "getTime" | "initField" | "initObject" | "unifyApply" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "splitToChunk" | "mergeFromChunk" | "pendingMap" | "queueProc" | "queueLength" | "outcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
61
+ export declare const UtilFunc: ComposedClass<typeof _UtilFunc, typeof JsFunc, "__jsUtils", "match" | "failed" | "success" | "prototype" | "genUUID" | "range" | "getTime" | "initField" | "initObject" | "unifyApply" | "sleep" | "getNeverResolvedPromise" | "retryPromise" | "timelimitPromise" | "mapEntries" | "eachField" | "stringifyJToken" | "assertType" | "assertLiteral" | "deepClone" | "isSafeNumber" | "dedent" | "throwError" | "getFuncLoc" | "cachePool" | "memoize" | "asyncize" | "splitToChunk" | "mergeFromChunk" | "concurrencyProc" | "outcome" | "isStatus" | "eitherize" | "parseSrtTime" | "formatSrtTime" | "parseSrt" | "createSrt" | "ivk" | "s2l" | "l2s">;
62
62
  export type UtilFunc = typeof UtilFunc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.214",
3
+ "version": "1.0.216",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {