@zwa73/utils 1.0.196 → 1.0.198

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,14 @@ 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的post预设 */
100
+ postJson(): UtilCom<D & {
101
+ readonly method: "POST";
102
+ }, SendProc<[JsonType<D & {
103
+ readonly method: "POST";
104
+ }>]>, AcceptProc<string, JToken>>;
105
+ /**收发皆为json的预设 */
106
+ json(): UtilCom<D, SendProc<[JsonType<D>]>, AcceptProc<string, JToken>>;
99
107
  /**接收数据类型*/
100
108
  accept<T extends AcceptType>(t: T): {
101
109
  readonly json: UtilCom<D, S, AcceptProc<string, JToken>>;
package/dist/UtilCom.js CHANGED
@@ -52,6 +52,16 @@ class UtilCom {
52
52
  return new UtilCom({ ...this._data, ...opt }, this._send, this._accept);
53
53
  }
54
54
  //#endregion
55
+ //#region 快速预设
56
+ /**收发皆为json的post预设 */
57
+ postJson() {
58
+ return this.post().json();
59
+ }
60
+ /**收发皆为json的预设 */
61
+ json() {
62
+ return this.sendJson().acceptJson();
63
+ }
64
+ //#endregion
55
65
  //#region 接收数据类型
56
66
  /**接收数据类型*/
57
67
  accept(t) {
@@ -182,8 +192,7 @@ class UtilCom {
182
192
  static async comReq(comReqOpt, procReq, reduceData, initData) {
183
193
  const { protocol, timeout, ...baseReqOpt } = comReqOpt;
184
194
  const hasTimeLimit = (timeout ? timeout >= 10_000 : false);
185
- const flagName = `UtilCom.${protocol}${baseReqOpt.method}`;
186
- const postflag = `comReq:${UtilFunctions_1.UtilFunc.genUUID()}`;
195
+ const flagName = `UtilCom.comReq ${protocol}${baseReqOpt.method} ${UtilFunctions_1.UtilFunc.genUUID()}`;
187
196
  let dataPromise = null;
188
197
  return new Promise(async (resolve, rejecte) => {
189
198
  const resFunc = (res) => {
@@ -198,7 +207,7 @@ class UtilCom {
198
207
  let mergedata = initData;
199
208
  res.setEncoding('utf8');
200
209
  res.on('data', chunk => {
201
- dataPromise = UtilFunctions_1.UtilFunc.queueProc(postflag, async () => mergedata = await reduceData(mergedata, chunk));
210
+ dataPromise = UtilFunctions_1.UtilFunc.queueProc(flagName, async () => mergedata = await reduceData(mergedata, chunk));
202
211
  });
203
212
  res.on('error', (e) => {
204
213
  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.198",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -123,6 +123,17 @@ A extends AcceptProc<any,any>,
123
123
  }
124
124
  //#endregion
125
125
 
126
+ //#region 快速预设
127
+ /**收发皆为json的post预设 */
128
+ postJson(){
129
+ return this.post().json();
130
+ }
131
+ /**收发皆为json的预设 */
132
+ json(){
133
+ return this.sendJson().acceptJson();
134
+ }
135
+ //#endregion
136
+
126
137
  //#region 接收数据类型
127
138
  /**接收数据类型*/
128
139
  accept<T extends AcceptType>(t:T){
@@ -268,9 +279,8 @@ A extends AcceptProc<any,any>,
268
279
 
269
280
  const hasTimeLimit = (timeout ? timeout>=10_000 : false );
270
281
 
271
- const flagName = `UtilCom.${protocol}${baseReqOpt.method}`;
282
+ const flagName = `UtilCom.comReq ${protocol}${baseReqOpt.method} ${UtilFunc.genUUID()}`;
272
283
 
273
- const postflag = `comReq:${UtilFunc.genUUID()}`;
274
284
  let dataPromise:Promise<any>|null = null;
275
285
 
276
286
  return new Promise<ComResp<T>|undefined>(async (resolve, rejecte)=>{
@@ -287,7 +297,7 @@ A extends AcceptProc<any,any>,
287
297
  let mergedata:T = initData;
288
298
  res.setEncoding('utf8');
289
299
  res.on('data', chunk => {
290
- dataPromise = UtilFunc.queueProc(postflag,async()=>mergedata=await reduceData(mergedata,chunk))
300
+ dataPromise = UtilFunc.queueProc(flagName,async()=>mergedata=await reduceData(mergedata,chunk))
291
301
  });
292
302
 
293
303
  res.on('error',(e)=>{