@zwa73/utils 1.0.200 → 1.0.202

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
@@ -100,7 +100,7 @@ export declare class UtilCom<D extends Partial<RequestOption> & Required<Pick<Re
100
100
  headers: {
101
101
  "Content-Type": "application/json";
102
102
  };
103
- }, SendProc<[JToken]>, AcceptProc<string, JToken>>;
103
+ }, SendProc<[JToken]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
104
104
  /**收发皆为json的post预设 */
105
105
  postJson(): UtilCom<D & {
106
106
  method: "POST";
@@ -108,15 +108,15 @@ export declare class UtilCom<D extends Partial<RequestOption> & Required<Pick<Re
108
108
  headers: {
109
109
  'Content-Type': "application/json";
110
110
  };
111
- }, SendProc<[JToken]>, AcceptProc<string, JToken>>;
111
+ }, SendProc<[JToken]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
112
112
  /**无查询参数获取json的get预设 */
113
113
  getJson(): UtilCom<D & {
114
114
  method: "GET";
115
- }, SendProc<[]>, AcceptProc<string, JToken>>;
115
+ }, SendProc<[]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
116
116
  /**有查询参数获取json的get预设 */
117
117
  queryJson(): UtilCom<D & {
118
118
  method: "GET";
119
- }, SendProc<[QueryRequestData]>, AcceptProc<string, JToken>>;
119
+ }, SendProc<[QueryRequestData]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
120
120
  /**收发皆为json的https-post预设 */
121
121
  static httpsPostJson(): UtilCom<{
122
122
  readonly protocol: "https:";
@@ -126,7 +126,7 @@ export declare class UtilCom<D extends Partial<RequestOption> & Required<Pick<Re
126
126
  headers: {
127
127
  'Content-Type': "application/json";
128
128
  };
129
- }, SendProc<[JToken]>, AcceptProc<string, JToken>>;
129
+ }, SendProc<[JToken]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
130
130
  /**收发皆为json的http-post预设 */
131
131
  static httpPostJson(): UtilCom<{
132
132
  readonly protocol: "http:";
@@ -136,37 +136,37 @@ export declare class UtilCom<D extends Partial<RequestOption> & Required<Pick<Re
136
136
  headers: {
137
137
  'Content-Type': "application/json";
138
138
  };
139
- }, SendProc<[JToken]>, AcceptProc<string, JToken>>;
139
+ }, SendProc<[JToken]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
140
140
  /**无查询参数获取json的https-get预设 */
141
141
  static httpsGetJson(): UtilCom<{
142
142
  readonly protocol: "https:";
143
143
  } & {
144
144
  method: "GET";
145
- }, SendProc<[]>, AcceptProc<string, JToken>>;
145
+ }, SendProc<[]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
146
146
  /**有查询参数获取json的https-get预设 */
147
147
  static httpsQueryJson(): UtilCom<{
148
148
  readonly protocol: "http:";
149
149
  } & {
150
150
  method: "GET";
151
- }, SendProc<[QueryRequestData]>, AcceptProc<string, JToken>>;
151
+ }, SendProc<[QueryRequestData]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
152
152
  /**无查询参数获取json的http-get预设 */
153
153
  static httpGetJson(): UtilCom<{
154
154
  readonly protocol: "http:";
155
155
  } & {
156
156
  method: "GET";
157
- }, SendProc<[]>, AcceptProc<string, JToken>>;
157
+ }, SendProc<[]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
158
158
  /**有查询参数获取json的http-get预设 */
159
159
  static httpQueryJson(): UtilCom<{
160
160
  readonly protocol: "http:";
161
161
  } & {
162
162
  method: "GET";
163
- }, SendProc<[QueryRequestData]>, AcceptProc<string, JToken>>;
163
+ }, SendProc<[QueryRequestData]>, AcceptProc<string, RequestResult<JToken> | undefined>>;
164
164
  /**预设的接收数据类型*/
165
165
  accept<T extends AcceptType>(t: T): {
166
- readonly json: UtilCom<D, S, AcceptProc<string, JToken>>;
166
+ readonly json: UtilCom<D, S, AcceptProc<string, RequestResult<JToken> | undefined>>;
167
167
  readonly string: UtilCom<D, S, AcceptProc<string, RequestResult<string> | undefined>>;
168
168
  }[T];
169
- acceptJson(): UtilCom<D, S, AcceptProc<string, JToken>>;
169
+ acceptJson(): UtilCom<D, S, AcceptProc<string, RequestResult<JToken> | undefined>>;
170
170
  acceptString(): UtilCom<D, S, typeof AcceptStringProc>;
171
171
  /**自定的接收数据类型*/
172
172
  acceptRaw<AD, AT>(proc: AcceptProc<AD, AT>): UtilCom<D, S, typeof proc>;
package/dist/UtilCom.js CHANGED
@@ -9,7 +9,6 @@ const https_1 = __importDefault(require("https"));
9
9
  const UtilLogger_1 = require("./UtilLogger");
10
10
  const UtilFunctions_1 = require("./UtilFunctions");
11
11
  const querystring_1 = __importDefault(require("querystring"));
12
- const UtilSymbol_1 = require("./UtilSymbol");
13
12
  const http_proxy_agent_1 = __importDefault(require("http-proxy-agent"));
14
13
  const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
15
14
  const AcceptTypeList = ["json", "string"];
@@ -136,8 +135,10 @@ class UtilCom {
136
135
  init: '',
137
136
  reduce: (acc, curr) => acc + curr,
138
137
  parse: (result) => {
139
- if (result == undefined)
138
+ if (result == undefined) {
139
+ UtilLogger_1.SLogger.warn(`json accept 接收反馈错误: 响应结果无效`);
140
140
  return undefined;
141
+ }
141
142
  const { data, ...rest } = result;
142
143
  if (data.trim() == "") {
143
144
  UtilLogger_1.SLogger.warn(`json accept 接收反馈错误: 原始字符串为空`, UtilFunctions_1.UtilFunc.stringifyJToken(result, { compress: true, space: 2 }));
@@ -339,14 +340,10 @@ exports.UtilCom = UtilCom;
339
340
  if (false)
340
341
  ((async () => {
341
342
  const t = await UtilCom.https().postJson()
342
- .retry({
343
- option: {
344
- hostname: 'httpbin.org',
345
- path: '/post',
346
- timeout: 10000
347
- },
348
- verify: () => UtilSymbol_1.Success,
349
- retries: {}
343
+ .once({
344
+ hostname: 'httpbin.org',
345
+ path: '/post',
346
+ timeout: 10000
350
347
  }, { test: 1 });
351
348
  console.log(t);
352
349
  })());
@@ -387,8 +387,10 @@ class UtilFunc {
387
387
  return `${ec}${str}${ec}`;
388
388
  return value;
389
389
  };
390
- return JSON.stringify(token, compressReplacer, space)
391
- .replace(new RegExp(`"${ec}(.*?)${ec}"`, 'g'), (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
390
+ const result = JSON.stringify(token, compressReplacer, space);
391
+ if (typeof result != 'string')
392
+ return result;
393
+ return result.replace(new RegExp(`"${ec}(.*?)${ec}"`, 'g'), (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
392
394
  }
393
395
  /**验证一个变量的类型是否为 T
394
396
  * @template T - 验证类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.200",
3
+ "version": "1.0.202",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -202,11 +202,14 @@ A extends AcceptProc<any,any>,
202
202
  return map[t];
203
203
  }
204
204
  acceptJson(){
205
- const proc:AcceptProc<string,JToken>={
205
+ const proc:AcceptProc<string,RequestResult<JToken>|undefined>={
206
206
  init:'',
207
207
  reduce:(acc,curr)=>acc+curr,
208
208
  parse:(result)=>{
209
- if(result==undefined) return undefined;
209
+ if(result==undefined){
210
+ SLogger.warn(`json accept 接收反馈错误: 响应结果无效`);
211
+ return undefined;
212
+ }
210
213
  const {data,...rest} = result;
211
214
 
212
215
  if(data.trim()==""){
@@ -444,14 +447,10 @@ A extends AcceptProc<any,any>,
444
447
 
445
448
  if(false)((async ()=>{
446
449
  const t = await UtilCom.https().postJson()
447
- .retry({
448
- option:{
449
- hostname:'httpbin.org',
450
- path:'/post',
451
- timeout:10000
452
- },
453
- verify:()=>Success,
454
- retries:{}
450
+ .once({
451
+ hostname:'httpbin.org',
452
+ path:'/post',
453
+ timeout:10000
455
454
  },{test:1});
456
455
  console.log(t);
457
456
  })())
@@ -461,8 +461,9 @@ static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
461
461
  return value;
462
462
  }
463
463
 
464
- return JSON.stringify(token,compressReplacer,space)
465
- .replace(new RegExp(`"${ec}(.*?)${ec}"`,'g'), (match, p1) =>
464
+ const result = JSON.stringify(token,compressReplacer,space);
465
+ if(typeof result!='string') return result;
466
+ return result.replace(new RegExp(`"${ec}(.*?)${ec}"`,'g'), (match, p1) =>
466
467
  p1.replace(/\\([\\"])/g, '$1'));
467
468
  }
468
469