@zwa73/utils 1.0.196 → 1.0.197

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 CHANGED
@@ -96,6 +96,8 @@ export declare class UtilCom<D extends Partial<ComRequestOption>, S extends Send
96
96
  }, S, A>;
97
97
  /**补充参数 */
98
98
  option<OPT extends Partial<ComRequestOption>>(opt: OPT): UtilCom<D & OPT, S, A>;
99
+ /**收发皆为json的预设 */
100
+ json(): UtilCom<D, SendProc<[JsonType<D>]>, AcceptProc<string, JToken>>;
99
101
  /**接收数据类型*/
100
102
  accept<T extends AcceptType>(t: T): {
101
103
  readonly json: UtilCom<D, S, AcceptProc<string, JToken>>;
package/dist/UtilCom.js CHANGED
@@ -52,6 +52,12 @@ class UtilCom {
52
52
  return new UtilCom({ ...this._data, ...opt }, this._send, this._accept);
53
53
  }
54
54
  //#endregion
55
+ //#region 快速预设
56
+ /**收发皆为json的预设 */
57
+ json() {
58
+ return this.sendJson().acceptJson();
59
+ }
60
+ //#endregion
55
61
  //#region 接收数据类型
56
62
  /**接收数据类型*/
57
63
  accept(t) {
@@ -182,8 +188,7 @@ class UtilCom {
182
188
  static async comReq(comReqOpt, procReq, reduceData, initData) {
183
189
  const { protocol, timeout, ...baseReqOpt } = comReqOpt;
184
190
  const hasTimeLimit = (timeout ? timeout >= 10_000 : false);
185
- const flagName = `UtilCom.${protocol}${baseReqOpt.method}`;
186
- const postflag = `comReq:${UtilFunctions_1.UtilFunc.genUUID()}`;
191
+ const flagName = `UtilCom.comReq ${protocol}${baseReqOpt.method} ${UtilFunctions_1.UtilFunc.genUUID()}`;
187
192
  let dataPromise = null;
188
193
  return new Promise(async (resolve, rejecte) => {
189
194
  const resFunc = (res) => {
@@ -198,7 +203,7 @@ class UtilCom {
198
203
  let mergedata = initData;
199
204
  res.setEncoding('utf8');
200
205
  res.on('data', chunk => {
201
- dataPromise = UtilFunctions_1.UtilFunc.queueProc(postflag, async () => mergedata = await reduceData(mergedata, chunk));
206
+ dataPromise = UtilFunctions_1.UtilFunc.queueProc(flagName, async () => mergedata = await reduceData(mergedata, chunk));
202
207
  });
203
208
  res.on('error', (e) => {
204
209
  UtilLogger_1.SLogger.warn(`${flagName} 接收反馈错误:${e}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.196",
3
+ "version": "1.0.197",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -123,6 +123,13 @@ A extends AcceptProc<any,any>,
123
123
  }
124
124
  //#endregion
125
125
 
126
+ //#region 快速预设
127
+ /**收发皆为json的预设 */
128
+ json(){
129
+ return this.sendJson().acceptJson();
130
+ }
131
+ //#endregion
132
+
126
133
  //#region 接收数据类型
127
134
  /**接收数据类型*/
128
135
  accept<T extends AcceptType>(t:T){
@@ -268,9 +275,8 @@ A extends AcceptProc<any,any>,
268
275
 
269
276
  const hasTimeLimit = (timeout ? timeout>=10_000 : false );
270
277
 
271
- const flagName = `UtilCom.${protocol}${baseReqOpt.method}`;
278
+ const flagName = `UtilCom.comReq ${protocol}${baseReqOpt.method} ${UtilFunc.genUUID()}`;
272
279
 
273
- const postflag = `comReq:${UtilFunc.genUUID()}`;
274
280
  let dataPromise:Promise<any>|null = null;
275
281
 
276
282
  return new Promise<ComResp<T>|undefined>(async (resolve, rejecte)=>{
@@ -287,7 +293,7 @@ A extends AcceptProc<any,any>,
287
293
  let mergedata:T = initData;
288
294
  res.setEncoding('utf8');
289
295
  res.on('data', chunk => {
290
- dataPromise = UtilFunc.queueProc(postflag,async()=>mergedata=await reduceData(mergedata,chunk))
296
+ dataPromise = UtilFunc.queueProc(flagName,async()=>mergedata=await reduceData(mergedata,chunk))
291
297
  });
292
298
 
293
299
  res.on('error',(e)=>{