@ningboyz/types 1.8.46 → 1.8.48

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ningboyz/types",
3
3
  "type": "module",
4
- "version": "1.8.46",
4
+ "version": "1.8.48",
5
5
  "private": false,
6
6
  "description": "宁波甬政类型库",
7
7
  "author": "nbyt-syq",
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import { construct, destruct } from "@aximario/json-tree";
2
3
  import _ from "lodash";
3
4
  import { type IBaseResponse, TBaseResponse } from "../base/IBaseResponse";
@@ -175,7 +176,7 @@ export class TDictResponse extends TBaseResponse<IDictResponse> implements IDict
175
176
  return defaultDictPara;
176
177
  }
177
178
  try {
178
- const obj = JSON.parse(dictPara) as TDictResponseDictPara;
179
+ const obj = JSONUtils.parseJSON(dictPara) as TDictResponseDictPara;
179
180
  return _.merge(defaultDictPara, obj);
180
181
  } catch (e) {}
181
182
  return defaultDictPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import { TCore } from "../index.ts";
2
3
  import _ from "lodash";
3
4
  import { TWithEXPDS, TWithMYOA, WithEXPDS, WithMYOA } from "./IUserResponse.ts";
@@ -105,7 +106,7 @@ export class TPartResponse implements IPartResponse {
105
106
  return defaultPathPara;
106
107
  }
107
108
  try {
108
- const obj = JSON.parse(partPara) as TPathResponsePathPara;
109
+ const obj = JSONUtils.parseJSON(partPara) as TPathResponsePathPara;
109
110
  return _.merge(defaultPathPara, obj);
110
111
  } catch (e) {}
111
112
  return defaultPathPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import _ from "lodash";
2
3
  import type { IWldyPageResponse } from "../wldy/IWldyPageResponse";
3
4
  import type { IDictResponse } from "./IDictResponse";
@@ -157,7 +158,7 @@ export class TSysMenuWithCoreResponse implements ISysMenuWithCoreResponse {
157
158
  return defaultMenuPara;
158
159
  }
159
160
  try {
160
- const obj = JSON.parse(menuPara) as TSysMenuWithCoreResponseMenuPara;
161
+ const obj = JSONUtils.parseJSON(menuPara) as TSysMenuWithCoreResponseMenuPara;
161
162
  return _.merge(defaultMenuPara, obj);
162
163
  } catch (e) {}
163
164
  return defaultMenuPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IFlowMainResponse } from "../flow";
3
4
  import { IGamsCnfgResponse } from "../gams";
@@ -339,7 +340,7 @@ export class TSysMenuWithExpdResponse implements ISysMenuWithExpdResponse {
339
340
  return defaultMenuPara;
340
341
  }
341
342
  try {
342
- const obj = JSON.parse(menuPara) as TSysMenuWithExpdResponseMenuPara;
343
+ const obj = JSONUtils.parseJSON(menuPara) as TSysMenuWithExpdResponseMenuPara;
343
344
  return _.merge(defaultMenuPara, obj);
344
345
  } catch (e) { }
345
346
  return defaultMenuPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import _ from "lodash";
2
3
 
3
4
  export interface ISysTravelWithParaResponse {
@@ -130,7 +131,7 @@ export class TSysTravelResponse implements ISysTravelResponse {
130
131
  return result;
131
132
  }
132
133
  try {
133
- const temp = JSON.parse(withPara) as TSysTravelWithParaResponse;
134
+ const temp = JSONUtils.parseJSON(withPara) as TSysTravelWithParaResponse;
134
135
  return _.merge(result, temp);
135
136
  } catch (e: any) {}
136
137
  return result;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import { construct, destruct } from "@aximario/json-tree";
2
3
  import _ from "lodash";
3
4
  import { type IBaseResponse, TBaseResponse } from "../base/IBaseResponse";
@@ -251,7 +252,7 @@ export class TUnitResponse extends TBaseResponse<IUnitResponse> implements IUnit
251
252
  return defaultUnitPara;
252
253
  }
253
254
  try {
254
- const obj = JSON.parse(unitPara) as TUnitResponseElemPara;
255
+ const obj = JSONUtils.parseJSON(unitPara) as TUnitResponseElemPara;
255
256
  return _.merge(defaultUnitPara, obj);
256
257
  } catch (e) {}
257
258
  return defaultUnitPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "./jsonUtils";
1
2
  import _ from "lodash";
2
3
 
3
4
  export interface IWebSocketResponse {
@@ -31,7 +32,7 @@ export class TWebSocketResponse implements IWebSocketResponse {
31
32
  return result;
32
33
  }
33
34
  try {
34
- const temp = JSON.parse(data) as TWebSocketResponse;
35
+ const temp = JSONUtils.parseJSON(data) as TWebSocketResponse;
35
36
  return _.merge(result, temp);
36
37
  } catch (e: any) {
37
38
  console.error(e.message);
@@ -0,0 +1,24 @@
1
+ import _ from "lodash";
2
+
3
+ class JSONUtils {
4
+ /** 空输入、非法 JSON 或解析结果为 null 时抛出统一错误,返回类型兼容原生解析。 */
5
+ public static parseJSON(jsonStr: string | undefined | null): ReturnType<typeof JSON.parse> {
6
+ try {
7
+ if (typeof jsonStr !== "string") {
8
+ throw new TypeError("参数约定内控不正确,请检查!");
9
+ }
10
+ if (_.isEmpty(jsonStr.trim())) {
11
+ return {};
12
+ }
13
+ const result: unknown = JSON.parse(jsonStr);
14
+ if (result === null) {
15
+ throw new TypeError("JSON 解析失败,请");
16
+ }
17
+ return result;
18
+ } catch {
19
+ throw new Error("json转换失败,请检查参数约定");
20
+ }
21
+ }
22
+ }
23
+
24
+ export default JSONUtils;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import type { IFlowNodeResponse } from "./IFlowNodeResponse";
3
4
  import type { IFlowDutyNodeParaConv } from "./IFlowDutyNodeParaConv";
@@ -77,7 +78,7 @@ export class TFlowDutyResponse implements IFlowDutyResponse {
77
78
  return defaultNodePara;
78
79
  }
79
80
  try {
80
- const obj = JSON.parse(nodePara) as IFlowDutyNodeParaConv;
81
+ const obj = JSONUtils.parseJSON(nodePara) as IFlowDutyNodeParaConv;
81
82
  return _.merge(defaultNodePara, obj);
82
83
  } catch (e) {}
83
84
  return defaultNodePara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import type { IDictResponse } from "../core/IDictResponse";
3
4
  import type { IPartResponse } from "../core/IPartResponse";
@@ -513,7 +514,7 @@ export class TFlowNodeResponse implements IFlowNodeResponse {
513
514
  return result;
514
515
  }
515
516
  try {
516
- const temp = JSON.parse(nodePara) as TFlowNodeResponseNodePara;
517
+ const temp = JSONUtils.parseJSON(nodePara) as TFlowNodeResponseNodePara;
517
518
  return _.merge(result, temp);
518
519
  } catch (e: any) {}
519
520
  return result;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import { construct, destruct } from "@aximario/json-tree";
2
3
  import _ from "lodash";
3
4
  import { IElemElemResponse } from "../elem/IElemElemResponse";
@@ -186,7 +187,7 @@ export class TGzjgGzlmResponse implements IGzjgGzlmResponse {
186
187
  return defaultGzlmPara;
187
188
  }
188
189
  try {
189
- const obj = JSON.parse(gzlmPara) as TGzjgGzlmResponseGzlmPara;
190
+ const obj = JSONUtils.parseJSON(gzlmPara) as TGzjgGzlmResponseGzlmPara;
190
191
  return _.merge(defaultGzlmPara, obj);
191
192
  } catch (_e) { }
192
193
  return defaultGzlmPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import type { IDictResponse } from "../core/IDictResponse";
3
4
  import type { IGzjgBodyLockResponse, TGzjgBodyLockResponse } from "./IGzjgBodyLockResponse";
@@ -252,7 +253,7 @@ export class TGzjgMainResponse implements IGzjgMainResponse {
252
253
  return defaultGzjgPara;
253
254
  }
254
255
  try {
255
- const obj = JSON.parse(gzjgPara) as IGzjgMainResponseGzjgPara;
256
+ const obj = JSONUtils.parseJSON(gzjgPara) as IGzjgMainResponseGzjgPara;
256
257
  return _.merge(defaultGzjgPara, obj);
257
258
  } catch (e) {}
258
259
  return defaultGzjgPara;
package/src/index.ts CHANGED
@@ -123,3 +123,4 @@ export {
123
123
  type IToolDownLoadData,
124
124
  type IWtuiConfig
125
125
  };
126
+ export { default as JSONUtils } from "./core/jsonUtils";
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IWldyDataResponse } from "./IWldyDataResponse";
3
4
  import { TWldyPageParaResponse } from "./IWldyPageParaResponse";
@@ -106,7 +107,7 @@ export class TWldyPageResponse implements IWldyPageResponse {
106
107
  return result;
107
108
  }
108
109
  try {
109
- const temp = JSON.parse(pagePara) as TWldyPageParaResponse;
110
+ const temp = JSONUtils.parseJSON(pagePara) as TWldyPageParaResponse;
110
111
  return _.merge(result, temp);
111
112
  } catch (e) {}
112
113
  return result;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import { construct } from "@aximario/json-tree";
2
3
  import { IBaseResponse, TBaseResponse } from "../base/IBaseResponse";
3
4
  import _ from "lodash";
@@ -90,7 +91,7 @@ export class TViewCtrlResponse extends TBaseResponse<IViewCtrlResponse> implemen
90
91
  return result;
91
92
  }
92
93
  try {
93
- const temp = JSON.parse(withPara) as TViewCtrlResponseWithParaConv;
94
+ const temp = JSONUtils.parseJSON(withPara) as TViewCtrlResponseWithParaConv;
94
95
  return _.merge(result, temp);
95
96
  } catch (e: any) {}
96
97
  return result;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IWtuiFormParaResponse, TWtuiFormParaResponse } from "./IWtuiFormParaResponse";
3
4
  import { IWtuiItemResponse } from "./IWtuiItemResponse";
@@ -83,7 +84,7 @@ export class TWtuiFormResponse implements IWtuiFormResponse {
83
84
  return formParaObj;
84
85
  }
85
86
  try {
86
- const obj = JSON.parse(formPara) as TWtuiFormParaResponse;
87
+ const obj = JSONUtils.parseJSON(formPara) as TWtuiFormParaResponse;
87
88
  const result = _.merge(formParaObj, obj);
88
89
  return result;
89
90
  } catch (e) {}
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IWtuiItemParaResponse, TWtuiItemParaResponse } from "./IWtuiItemParaResponse";
3
4
  import { IDictResponse } from "../core";
@@ -107,7 +108,7 @@ export class TWtuiItemResponse implements IWtuiItemResponse {
107
108
  return itemParaObj;
108
109
  }
109
110
  try {
110
- const obj = JSON.parse(itemPara) as TWtuiItemParaResponse;
111
+ const obj = JSONUtils.parseJSON(itemPara) as TWtuiItemParaResponse;
111
112
  const result = _.merge(itemParaObj, obj);
112
113
  return result;
113
114
  } catch (e) {}
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IWtuiTodoResponseTodoPara, TWtuiTodoResponseTodoPara } from "./IWtuiTodoResponseTodoPara";
3
4
  import { IWtuiTodoResponseWithPara, TWtuiTodoResponseWithPara } from "./IWtuiTodoResponseWithPara";
@@ -83,7 +84,7 @@ export class TWtuiTodoResponse implements IWtuiTodoResponse {
83
84
  return result;
84
85
  }
85
86
  try {
86
- const temp = JSON.parse(withPara) as TWtuiTodoResponseWithPara[];
87
+ const temp = JSONUtils.parseJSON(withPara) as TWtuiTodoResponseWithPara[];
87
88
  return _.merge(result, temp);
88
89
  } catch (e: any) {}
89
90
  return result;
@@ -95,7 +96,7 @@ export class TWtuiTodoResponse implements IWtuiTodoResponse {
95
96
  return result;
96
97
  }
97
98
  try {
98
- const temp = JSON.parse(todoPara) as TWtuiTodoResponseTodoPara;
99
+ const temp = JSONUtils.parseJSON(todoPara) as TWtuiTodoResponseTodoPara;
99
100
  return _.merge(result, temp);
100
101
  } catch (e: any) {}
101
102
  return result;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  import { IUnitResponse } from "../core";
3
4
  import { IWtuiColWidthResponse, TWtuiColWidthResponse } from "./IWtuiColWidthResponse";
@@ -135,7 +136,7 @@ export class TWtuiUserCnfgResponse implements IWtuiUserCnfgResponse {
135
136
  return defaultDictPara;
136
137
  }
137
138
  try {
138
- const obj = JSON.parse(dictPara) as TCnfgPara;
139
+ const obj = JSONUtils.parseJSON(dictPara) as TCnfgPara;
139
140
  return _.merge(defaultDictPara, obj);
140
141
  } catch (e) { }
141
142
  return defaultDictPara;
@@ -1,3 +1,4 @@
1
+ import JSONUtils from "../core/jsonUtils";
1
2
  import _ from "lodash";
2
3
  /* 物资参数约定 */
3
4
  export interface IWzWithParaResponse {
@@ -139,7 +140,7 @@ export class TWzWithParaResponse implements IWzWithParaResponse {
139
140
  return result;
140
141
  }
141
142
  try {
142
- const temp = JSON.parse(withPara) as TWzWithParaResponse;
143
+ const temp = JSONUtils.parseJSON(withPara) as TWzWithParaResponse;
143
144
  return _.merge(result, temp);
144
145
  } catch (e: any) {}
145
146
  return result;