@ray-js/lock-sdk 1.0.1 → 1.0.3-beta-1

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.
Files changed (86) hide show
  1. package/lib/api/index.js +13 -15
  2. package/lib/api/linkage.d.ts +0 -18
  3. package/lib/api/linkage.js +61 -81
  4. package/lib/api/lock.d.ts +0 -69
  5. package/lib/api/lock.js +91 -113
  6. package/lib/api/log.d.ts +0 -33
  7. package/lib/api/log.js +33 -38
  8. package/lib/api/setting.d.ts +0 -11
  9. package/lib/api/setting.js +17 -30
  10. package/lib/api/temp.d.ts +0 -48
  11. package/lib/api/temp.js +85 -115
  12. package/lib/api/user.d.ts +5 -54
  13. package/lib/api/user.js +40 -52
  14. package/lib/api/video.d.ts +0 -5
  15. package/lib/api/video.js +9 -15
  16. package/lib/config/dp-code/index.d.ts +0 -117
  17. package/lib/config/dp-code/index.js +79 -221
  18. package/lib/config/dp-map/common.d.ts +0 -3
  19. package/lib/config/dp-map/common.js +101 -116
  20. package/lib/config/dp-map/normal.js +29 -50
  21. package/lib/config/dp-map/open.d.ts +0 -16
  22. package/lib/config/dp-map/open.js +62 -63
  23. package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
  24. package/lib/config/dp-map/unlock-method-big.js +196 -233
  25. package/lib/config/dp-map/unlock-method.d.ts +0 -63
  26. package/lib/config/dp-map/unlock-method.js +189 -227
  27. package/lib/config/index.d.ts +0 -25
  28. package/lib/config/index.js +21 -54
  29. package/lib/constant.d.ts +12 -40
  30. package/lib/constant.js +83 -136
  31. package/lib/event.d.ts +0 -6
  32. package/lib/event.js +1 -8
  33. package/lib/index.d.ts +0 -7
  34. package/lib/index.js +45 -71
  35. package/lib/interface.d.ts +0 -523
  36. package/lib/interface.js +1 -1
  37. package/lib/linkage.d.ts +0 -18
  38. package/lib/linkage.js +125 -162
  39. package/lib/log.d.ts +0 -50
  40. package/lib/log.js +255 -290
  41. package/lib/media.d.ts +0 -34
  42. package/lib/media.js +6 -77
  43. package/lib/open.d.ts +0 -35
  44. package/lib/open.js +129 -224
  45. package/lib/other.d.ts +8 -26
  46. package/lib/other.js +107 -159
  47. package/lib/parse/index.d.ts +0 -4
  48. package/lib/parse/index.js +13 -19
  49. package/lib/signal.d.ts +0 -13
  50. package/lib/signal.js +17 -31
  51. package/lib/sleep.d.ts +0 -42
  52. package/lib/sleep.js +41 -98
  53. package/lib/state.d.ts +0 -38
  54. package/lib/state.js +223 -369
  55. package/lib/sync/remote-serect-key.d.ts +0 -4
  56. package/lib/sync/remote-serect-key.js +33 -49
  57. package/lib/sync/t0.d.ts +0 -3
  58. package/lib/sync/t0.js +14 -21
  59. package/lib/sync/temp.d.ts +0 -5
  60. package/lib/sync/temp.js +68 -77
  61. package/lib/sync/unlock-mothod.d.ts +0 -3
  62. package/lib/sync/unlock-mothod.js +28 -40
  63. package/lib/temporary.d.ts +0 -149
  64. package/lib/temporary.js +469 -593
  65. package/lib/unlock-method.d.ts +0 -185
  66. package/lib/unlock-method.js +479 -650
  67. package/lib/user.d.ts +2 -81
  68. package/lib/user.js +202 -336
  69. package/lib/utils/base64-to-hex.js +10 -10
  70. package/lib/utils/byte.d.ts +0 -16
  71. package/lib/utils/byte.js +57 -68
  72. package/lib/utils/constant.js +7 -11
  73. package/lib/utils/device.d.ts +46 -83
  74. package/lib/utils/device.js +294 -322
  75. package/lib/utils/errors.js +75 -122
  76. package/lib/utils/event.js +79 -135
  77. package/lib/utils/hex-to-base64.js +5 -5
  78. package/lib/utils/hex-to-bytes.d.ts +0 -5
  79. package/lib/utils/hex-to-bytes.js +10 -15
  80. package/lib/utils/index.d.ts +0 -42
  81. package/lib/utils/index.js +247 -377
  82. package/lib/utils/log.d.ts +1 -4
  83. package/lib/utils/log.js +71 -74
  84. package/lib/utils/publishDps.d.ts +0 -5
  85. package/lib/utils/publishDps.js +58 -80
  86. package/package.json +3 -4
@@ -1,419 +1,289 @@
1
- import "core-js/modules/esnext.iterator.constructor.js";
2
- import "core-js/modules/esnext.iterator.for-each.js";
3
- import "core-js/modules/esnext.iterator.map.js";
4
1
  import config from "../config";
5
2
  import dpCodes from "../config/dp-code";
6
- import { ProductCommunicationType } from "../constant";
3
+ import { ProductCommunicationType, } from "../constant";
7
4
  import { LoopTypes } from "./constant";
8
- import { getBackgroundFetchData, getCurrentHomeInfo, onBackgroundFetchData } from "./device";
5
+ import { getBackgroundFetchData, getCurrentHomeInfo, onBackgroundFetchData, } from "./device";
9
6
  import { getError } from "./errors";
10
-
11
- /**
12
- * 格式化为24时间格式
13
- * @param time
14
- * @returns
15
- */
16
- export const get24Time = time => {
17
- const hours = Math.floor(time / 60);
18
- return [hours, time % 60];
7
+ export const get24Time = (time) => {
8
+ const hours = Math.floor(time / 60);
9
+ const minutes = time % 60;
10
+ return [hours, minutes];
19
11
  };
20
12
  export const getNowTime = () => {
21
- const now = new Date();
22
- return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
13
+ const now = new Date();
14
+ return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
23
15
  };
24
-
25
- /**
26
- * 判断设备在线类型
27
- * @param onlineType 设备的通道在线数据
28
- * @param type 待检测的通道类型,0为wifi,1为局域网,2为蓝牙,3为Mesh, 4为 beacon
29
- * @returns
30
- */
31
16
  export const isOnlineByType = (onlineType, type) => {
32
- // eslint-disable-next-line no-bitwise
33
- return (onlineType & 2 ** type) >> type === 1;
17
+ const base = 2 ** type;
18
+ return (onlineType & base) >> type === 1;
34
19
  };
35
-
36
- // 遍历capability类型,通讯类型
37
- const supportCapabilities = [{
38
- id: 0,
39
- name: "wifi",
40
- short: "wf"
41
- }, {
42
- id: 1,
43
- name: "cable",
44
- short: "ca"
45
- }, {
46
- id: 2,
47
- name: "gprs",
48
- short: "gp"
49
- }, {
50
- id: 3,
51
- name: "nb-iot",
52
- short: "nb"
53
- }, {
54
- id: 10,
55
- name: "bluetooth",
56
- short: "ble"
57
- }, {
58
- id: 11,
59
- name: "blemesh",
60
- short: "bm"
61
- }, {
62
- id: 12,
63
- name: "zigbee",
64
- short: "zig"
65
- }, {
66
- id: 13,
67
- name: "infrared",
68
- short: "inf"
69
- }, {
70
- id: 14,
71
- name: "subpieces",
72
- short: "sub"
73
- }, {
74
- id: 15,
75
- name: "sigmesh",
76
- short: "sig"
77
- }, {
78
- id: 16,
79
- name: "mcu",
80
- short: "mcu"
81
- }, {
82
- id: 17,
83
- name: "ty_smesh",
84
- short: "TY_SMESH"
85
- }, {
86
- id: 18,
87
- name: "Zwave",
88
- short: "Zwave"
89
- }, {
90
- id: 19,
91
- name: "pl-mesh",
92
- short: "pl-mesh"
93
- }, {
94
- id: 20,
95
- name: "cat1",
96
- short: "cat1"
97
- }, {
98
- id: 21,
99
- name: "beacon",
100
- short: "beacon"
101
- }, {
102
- id: 22,
103
- name: "cat4",
104
- short: "cat4"
105
- }, {
106
- id: 23,
107
- name: "cat10",
108
- short: "cat10"
109
- }, {
110
- id: 24,
111
- name: "lte-catm",
112
- short: "catm"
113
- }, {
114
- id: 25,
115
- name: "thread",
116
- short: "thread"
117
- }];
20
+ const supportCapabilities = [
21
+ { id: 0, name: "wifi", short: "wf" },
22
+ { id: 1, name: "cable", short: "ca" },
23
+ { id: 2, name: "gprs", short: "gp" },
24
+ { id: 3, name: "nb-iot", short: "nb" },
25
+ { id: 10, name: "bluetooth", short: "ble" },
26
+ { id: 11, name: "blemesh", short: "bm" },
27
+ { id: 12, name: "zigbee", short: "zig" },
28
+ { id: 13, name: "infrared", short: "inf" },
29
+ { id: 14, name: "subpieces", short: "sub" },
30
+ { id: 15, name: "sigmesh", short: "sig" },
31
+ { id: 16, name: "mcu", short: "mcu" },
32
+ { id: 17, name: "ty_smesh", short: "TY_SMESH" },
33
+ { id: 18, name: "Zwave", short: "Zwave" },
34
+ { id: 19, name: "pl-mesh", short: "pl-mesh" },
35
+ { id: 20, name: "cat1", short: "cat1" },
36
+ { id: 21, name: "beacon", short: "beacon" },
37
+ { id: 22, name: "cat4", short: "cat4" },
38
+ { id: 23, name: "cat10", short: "cat10" },
39
+ { id: 24, name: "lte-catm", short: "catm" },
40
+ { id: 25, name: "thread", short: "thread" },
41
+ ];
118
42
  export function isCapability(capability, id) {
119
- const redId = 1 << id;
120
- return (capability & redId) === redId;
43
+ const redId = 1 << id;
44
+ return (capability & redId) === redId;
121
45
  }
122
-
123
- /**
124
- * 获取产品支持的通讯能力
125
- * @param capability 产品能力值
126
- * @returns
127
- */
128
46
  export function getCapabilities(capability) {
129
- return supportCapabilities.filter(item => {
130
- return isCapability(capability, item.id);
131
- });
47
+ return supportCapabilities.filter((item) => {
48
+ return isCapability(capability, item.id);
49
+ });
132
50
  }
133
-
134
- // 格式化周
135
- export const formatWeek = value => {
136
- return parseInt([...value].reverse().join(""), 2);
51
+ export const formatWeek = (value) => {
52
+ return parseInt([...value].reverse().join(""), 2);
137
53
  };
138
-
139
- // 格式化周
140
- export const parseWeek = value => {
141
- return Number(value).toString(2).padStart(7, "0").split("").reverse().map(Number).slice(0, 7);
54
+ export const parseWeek = (value) => {
55
+ return Number(value)
56
+ .toString(2)
57
+ .padStart(7, "0")
58
+ .split("")
59
+ .reverse()
60
+ .map(Number)
61
+ .slice(0, 7);
142
62
  };
143
-
144
- /**
145
- * 获取一个永久生效的设置
146
- * @returns
147
- */
148
63
  export const getPermanentSetting = () => {
149
- const now = Math.floor(+new Date() / 1000);
150
- return {
151
- startTime: now,
152
- // 如果是永久生效,则设置为 100 年后失效
153
- endTime: now + 3153600000,
154
- loop: LoopTypes.NONE,
155
- loopConfig: 0,
156
- weeks: [0, 0, 0, 0, 0, 0, 0],
157
- days: [],
158
- startHour: 0,
159
- startMinute: 0,
160
- endHour: 0,
161
- endMinute: 0
162
- };
64
+ const now = Math.floor(+new Date() / 1000);
65
+ return {
66
+ startTime: now,
67
+ endTime: now + 3153600000,
68
+ loop: LoopTypes.NONE,
69
+ loopConfig: 0,
70
+ weeks: [0, 0, 0, 0, 0, 0, 0],
71
+ days: [],
72
+ startHour: 0,
73
+ startMinute: 0,
74
+ endHour: 0,
75
+ endMinute: 0,
76
+ };
163
77
  };
164
- export const isAdmin = userType => userType === 10 || userType === 50 ? true : false;
165
- export const validateEffectiveConfig = effective => {
166
- if (!effective) {
167
- // 不是永久生效时,需要传入生效时间配置
168
- throw getError(1032);
169
- }
170
- // 生效时间段判断
171
- if (!effective.effectiveDate) {
172
- throw getError(1033);
173
- }
174
- if (!effective.expiredDate) {
175
- throw getError(1034);
176
- }
177
- if (+effective.effectiveDate > +effective.expiredDate) {
178
- throw getError(1010);
179
- }
180
- switch (effective.repeat) {
181
- case "week":
182
- if (!effective.weeks) {
183
- throw getError(1035);
184
- }
185
- break;
186
- // case "month":
187
- // if (!effective.days) {
188
- // throw getError(1036);
189
- // }
190
- // break;
191
- // default:
192
- }
78
+ export const isAdmin = (userType) => userType === 10 || userType === 50 ? true : false;
79
+ export const validateEffectiveConfig = (effective) => {
80
+ if (!effective) {
81
+ throw getError(1032);
82
+ }
83
+ if (!effective.effectiveDate) {
84
+ throw getError(1033);
85
+ }
86
+ if (!effective.expiredDate) {
87
+ throw getError(1034);
88
+ }
89
+ if (+effective.effectiveDate > +effective.expiredDate) {
90
+ throw getError(1010);
91
+ }
92
+ switch (effective.repeat) {
93
+ case "week":
94
+ if (!effective.weeks) {
95
+ throw getError(1035);
96
+ }
97
+ break;
98
+ }
193
99
  };
194
-
195
- /**
196
- * 是否使用近场通道,一般为蓝牙
197
- * @returns
198
- */
199
100
  export const isUseNearChannel = () => {
200
- const {
201
- onlineType,
202
- devInfo,
203
- communication
204
- } = config;
205
- const isBleOnline = isOnlineByType(onlineType, 2);
206
- const isSupportWifi = communication.includes(ProductCommunicationType.WIFI);
207
- const isSupportBle = communication.includes(ProductCommunicationType.BLUETOOTH);
208
- const isSupportThread = communication.includes(ProductCommunicationType.THREAD);
209
- // wifi + ble 双模
210
- if (isSupportWifi && isSupportBle) {
101
+ const { onlineType, devInfo, communication } = config;
102
+ const isBleOnline = isOnlineByType(onlineType, 2);
103
+ const isSupportWifi = communication.includes(ProductCommunicationType.WIFI);
104
+ const isSupportBle = communication.includes(ProductCommunicationType.BLUETOOTH);
105
+ const isSupportThread = communication.includes(ProductCommunicationType.THREAD);
106
+ if (isSupportWifi && isSupportBle) {
107
+ return isBleOnline;
108
+ }
109
+ if (isSupportThread && isSupportBle) {
110
+ return isBleOnline && !devInfo.isCloudOnline && !devInfo.isLocalOnline;
111
+ }
211
112
  return isBleOnline;
212
- }
213
- // thread + ble 双模
214
- if (isSupportThread && isSupportBle) {
215
- return isBleOnline && !devInfo.isCloudOnline && !devInfo.isLocalOnline;
216
- }
217
- return isBleOnline;
218
113
  };
219
- export const parseOfflinePassword = value => {
220
- if (config.passwordDigitalBase === 10) {
221
- // 10进制时,直接显示
222
- return value;
223
- }
224
- // 其他进制时,转换后显示
225
- let digitalCode = Number(value).toString(config.passwordDigitalBase);
226
- // 0
227
- const zeroList = value.match(/(^0+)/);
228
- if (zeroList) {
229
- digitalCode = zeroList[0] + digitalCode;
230
- }
231
- // 是否隐藏0
232
- if (config.passwordSupportZero === false) {
233
- digitalCode = digitalCode.split("").map(n => {
234
- return Number(n) + 1;
235
- }).join("");
236
- }
237
- return digitalCode;
114
+ export const parseOfflinePassword = (value) => {
115
+ if (config.passwordDigitalBase === 10) {
116
+ return value;
117
+ }
118
+ let digitalCode = Number(value).toString(config.passwordDigitalBase);
119
+ const zeroList = value.match(/(^0+)/);
120
+ if (zeroList) {
121
+ digitalCode = zeroList[0] + digitalCode;
122
+ }
123
+ if (config.passwordSupportZero === false) {
124
+ digitalCode = digitalCode
125
+ .split("")
126
+ .map((n) => {
127
+ return Number(n) + 1;
128
+ })
129
+ .join("");
130
+ }
131
+ return digitalCode;
238
132
  };
239
-
240
- /**
241
- * 格式化时间戳为毫秒
242
- * 注意此方法只支持 2010 年之后的时间戳
243
- * @param timestamp 时间戳
244
- */
245
- export const formatTimestampToMilliseconds = timestamp => {
246
- const isMilliseconds = timestamp.toString().length >= 13;
247
- return isMilliseconds ? timestamp : timestamp * 1000;
133
+ export const formatTimestampToMilliseconds = (timestamp) => {
134
+ const isMilliseconds = timestamp.toString().length >= 13;
135
+ return isMilliseconds ? timestamp : timestamp * 1000;
248
136
  };
249
-
250
- /**
251
- * 开锁方式配置数据
252
- */
253
- export const unlockMethodConfigs = [{
254
- type: "password",
255
- code: dpCodes.unlockPassword,
256
- id: 1
257
- }, {
258
- type: "card",
259
- code: dpCodes.unlockCard,
260
- id: 2
261
- }, {
262
- type: "finger",
263
- code: dpCodes.unlockFingerprint,
264
- id: 3
265
- }, {
266
- type: "face",
267
- code: dpCodes.unlockFace,
268
- id: 4
269
- }, {
270
- type: "hand",
271
- code: dpCodes.unlockHand,
272
- id: 5
273
- }, {
274
- type: "fingerVein",
275
- code: dpCodes.unlockFingerVein,
276
- id: 6
277
- }];
278
- const getUnlockMethodType = cb => {
279
- const result = unlockMethodConfigs.find(cb);
280
- // 有此方式且设备是否支持此能力
281
- if (result && config.dpSchema[result.code]) {
282
- return result;
283
- }
284
- throw getError(1014);
137
+ export const unlockMethodConfigs = [
138
+ {
139
+ type: "password",
140
+ code: dpCodes.unlockPassword,
141
+ id: 1,
142
+ },
143
+ {
144
+ type: "card",
145
+ code: dpCodes.unlockCard,
146
+ id: 2,
147
+ },
148
+ {
149
+ type: "finger",
150
+ code: dpCodes.unlockFingerprint,
151
+ id: 3,
152
+ },
153
+ {
154
+ type: "face",
155
+ code: dpCodes.unlockFace,
156
+ id: 4,
157
+ },
158
+ {
159
+ type: "hand",
160
+ code: dpCodes.unlockHand,
161
+ id: 5,
162
+ },
163
+ {
164
+ type: "fingerVein",
165
+ code: dpCodes.unlockFingerVein,
166
+ id: 6,
167
+ },
168
+ ];
169
+ const getUnlockMethodType = (cb) => {
170
+ const result = unlockMethodConfigs.find(cb);
171
+ if (result && config.dpSchema[result.code]) {
172
+ return result;
173
+ }
174
+ throw getError(1014);
285
175
  };
286
- export const getUnlockMethodTypeByDpCode = dpCode => {
287
- return getUnlockMethodType(item => item.code === dpCode);
176
+ export const getUnlockMethodTypeByDpCode = (dpCode) => {
177
+ return getUnlockMethodType((item) => item.code === dpCode);
288
178
  };
289
- export const getUnlockMethodTypeById = id => {
290
- return getUnlockMethodType(item => item.id === id);
179
+ export const getUnlockMethodTypeById = (id) => {
180
+ return getUnlockMethodType((item) => item.id === id);
291
181
  };
292
- export const getUnlockMethodTypeByType = type => {
293
- return getUnlockMethodType(item => item.type === type);
182
+ export const getUnlockMethodTypeByType = (type) => {
183
+ return getUnlockMethodType((item) => item.type === type);
294
184
  };
295
185
  let cbIndex = 0;
296
186
  const cbMap = {};
297
- /**
298
- * 针对异常函数,当函数在短时间内被多次调用时,只保留最先一次调用,并统一返回结果
299
- * @param cb 回调函数
300
- * @returns
301
- */
302
- export const parallelMerge = cb => {
303
- let isRuning = false;
304
- let cbId = cbIndex++;
305
- // @ts-expect-error
306
- return async function () {
307
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
308
- args[_key] = arguments[_key];
309
- }
310
- const key = JSON.stringify(args);
311
- // 如果正在执行,则直接抛错
312
- if (isRuning) {
313
- // 暂存回调
314
- if (!cbMap[cbId]) {
315
- cbMap[cbId] = {};
316
- }
317
- if (!cbMap[cbId][key]) {
318
- cbMap[cbId][key] = [];
319
- }
320
- return new Promise((resolve, reject) => {
321
- cbMap[cbId][key].push({
322
- resolve,
323
- reject
324
- });
325
- });
326
- }
327
- isRuning = true;
328
- try {
329
- const result = await cb(...args);
330
- isRuning = false;
331
- // 如果是 merge 模式,执行所有暂存的回调
332
- if (cbMap[cbId] && cbMap[cbId][key]) {
333
- let list = cbMap[cbId][key];
334
- delete cbMap[cbId][key]; // 删除已处理的回调
335
- setTimeout(() => {
336
- list.forEach(item => item.resolve(result));
337
- }, 0);
338
- }
339
- return result;
340
- } catch (error) {
341
- isRuning = false;
342
- // 如果是 merge 模式,执行所有暂存的回调
343
- if (cbMap[cbId] && cbMap[cbId][key]) {
344
- let list = cbMap[cbId][key];
345
- delete cbMap[cbId][key]; // 删除已处理的回调
346
- setTimeout(() => {
347
- list.forEach(item => item.reject(error));
348
- }, 0);
349
- }
350
- throw error;
351
- }
352
- };
187
+ export const parallelMerge = (cb) => {
188
+ let isRuning = false;
189
+ let cbId = cbIndex++;
190
+ return async (...args) => {
191
+ const key = JSON.stringify(args);
192
+ if (isRuning) {
193
+ if (!cbMap[cbId]) {
194
+ cbMap[cbId] = {};
195
+ }
196
+ if (!cbMap[cbId][key]) {
197
+ cbMap[cbId][key] = [];
198
+ }
199
+ return new Promise((resolve, reject) => {
200
+ cbMap[cbId][key].push({ resolve, reject });
201
+ });
202
+ }
203
+ isRuning = true;
204
+ try {
205
+ const result = await cb(...args);
206
+ isRuning = false;
207
+ if (cbMap[cbId] && cbMap[cbId][key]) {
208
+ let list = cbMap[cbId][key];
209
+ delete cbMap[cbId][key];
210
+ setTimeout(() => {
211
+ list.forEach((item) => item.resolve(result));
212
+ }, 0);
213
+ }
214
+ return result;
215
+ }
216
+ catch (error) {
217
+ isRuning = false;
218
+ if (cbMap[cbId] && cbMap[cbId][key]) {
219
+ let list = cbMap[cbId][key];
220
+ delete cbMap[cbId][key];
221
+ setTimeout(() => {
222
+ list.forEach((item) => item.reject(error));
223
+ }, 0);
224
+ }
225
+ throw error;
226
+ }
227
+ };
353
228
  };
354
-
355
- /**
356
- * 针对异常函数,当函数在短时间内被多次调用时,只允许函数在短时间内执行一次
357
- * @param cb 回调函数
358
- * @returns
359
- */
360
- export const parallelOnly = cb => {
361
- let isRuning = false;
362
- cbIndex++; // @ts-expect-error
363
- return async function () {
364
- // 如果正在执行,则直接抛错
365
- if (isRuning) {
366
- throw getError(1052);
367
- }
368
- isRuning = true;
369
- try {
370
- const result = await cb(...arguments);
371
- isRuning = false;
372
- return result;
373
- } catch (error) {
374
- isRuning = false;
375
- throw error;
376
- }
377
- };
229
+ export const parallelOnly = (cb) => {
230
+ let isRuning = false;
231
+ let cbId = cbIndex++;
232
+ return async (...args) => {
233
+ let key;
234
+ if (isRuning) {
235
+ throw getError(1052);
236
+ }
237
+ isRuning = true;
238
+ try {
239
+ const result = await cb(...args);
240
+ isRuning = false;
241
+ return result;
242
+ }
243
+ catch (error) {
244
+ isRuning = false;
245
+ throw error;
246
+ }
247
+ };
378
248
  };
379
- const preFetchKeys = ["getRotate", "getCurrentUser", "getDeviceProperties"];
380
- /**
381
- * 预加载数据处理
382
- */
249
+ const preFetchKeys = [
250
+ "getRotate",
251
+ "getCurrentUser",
252
+ "getDeviceProperties",
253
+ ];
383
254
  const preFetchData = {};
384
- // @ts-expect-error
385
- onBackgroundFetchData(preFetchKeys, res => {
386
- var _res$fetchedData;
387
- Object.keys((_res$fetchedData = res === null || res === void 0 ? void 0 : res.fetchedData) !== null && _res$fetchedData !== void 0 ? _res$fetchedData : {}).forEach(key => {
388
- preFetchData[key] = res.fetchedData[key].fetchedData;
389
- });
255
+ onBackgroundFetchData(preFetchKeys, (res) => {
256
+ Object.keys(res?.fetchedData ?? {}).forEach((key) => {
257
+ preFetchData[key] = res.fetchedData[key].fetchedData;
258
+ });
390
259
  });
391
260
  export const getDataWithPreFetch = async (key, apiCb) => {
392
- if (preFetchData[key]) {
393
- return preFetchData[key];
394
- }
395
- try {
396
- const result = await getBackgroundFetchData([key]);
397
- if (result && result.fetchedData[key] && result.fetchedData[key].fetchedData) {
398
- // 有数据时,则返回数据,无数据则执行接口调用
399
- return result.fetchedData[key].fetchedData;
261
+ if (preFetchData[key]) {
262
+ return preFetchData[key];
400
263
  }
401
- } catch {
402
- //
403
- }
404
- return apiCb();
264
+ try {
265
+ const result = await getBackgroundFetchData([key]);
266
+ if (result &&
267
+ result.fetchedData[key] &&
268
+ result.fetchedData[key].fetchedData) {
269
+ return result.fetchedData[key].fetchedData;
270
+ }
271
+ }
272
+ catch {
273
+ }
274
+ return apiCb();
405
275
  };
406
276
  export const equels = (source, target) => {
407
- return JSON.stringify(source) === JSON.stringify(target);
277
+ return JSON.stringify(source) === JSON.stringify(target);
408
278
  };
409
- export const sleep = ms => {
410
- return new Promise(resolve => setTimeout(resolve, ms));
279
+ export const sleep = (ms) => {
280
+ return new Promise((resolve) => setTimeout(resolve, ms));
411
281
  };
412
282
  let homeInfo = null;
413
283
  export const getHomeInfo = async () => {
414
- if (homeInfo) {
284
+ if (homeInfo) {
285
+ return homeInfo;
286
+ }
287
+ homeInfo = await getCurrentHomeInfo();
415
288
  return homeInfo;
416
- }
417
- homeInfo = await getCurrentHomeInfo();
418
- return homeInfo;
419
- };
289
+ };
@@ -1,5 +1,2 @@
1
- /**
2
- * 处理日志数据
3
- */
4
1
  import { LocalOperateData, LocalOperateRecordInfo } from "../interface";
5
- export declare const handleLocalOperation: (log?: LocalOperateRecordInfo) => LocalOperateData | undefined;
2
+ export declare const handleLocalOperation: (log?: LocalOperateRecordInfo, dpValue?: string) => LocalOperateData | undefined;