ms-types 0.9.12 → 0.9.15

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,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-types",
3
- "version": "0.9.12",
3
+ "version": "0.9.15",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 云控模块类型定义
3
+ * 提供主脚本侧连接云控、断开连接、判断连接状态、上报 Object 数据和监听服务端事件的能力。
4
+ */
5
+ declare namespace cloud {
6
+ /**
7
+ * 连接云控服务器。
8
+ * @param url 完整 ws:// 或 wss:// 云控地址。
9
+ * @param deviceNo 可选设备编号,不传时沿用当前保存的设备编号。
10
+ * @returns URL 校验通过且连接请求已提交时返回 true。
11
+ * @description 只能在主脚本上下文调用;只影响当前运行期云控连接,不会写入设置页的持久化云控配置。
12
+ * @example
13
+ * const accepted = cloud.connect("wss://example.com/control", "device-001");
14
+ */
15
+ function connect(url: string, deviceNo?: string): boolean;
16
+
17
+ /**
18
+ * 判断云控是否已经连接成功。
19
+ * @returns 已连接时返回 true。
20
+ * @example
21
+ * if (cloud.isConnected()) {
22
+ * cloud.report("status", { value: "ready" });
23
+ * }
24
+ */
25
+ function isConnected(): boolean;
26
+
27
+ /**
28
+ * 断开云控连接并停止自动重连。
29
+ * @example
30
+ * cloud.disconnect();
31
+ */
32
+ function disconnect(): void;
33
+
34
+ /**
35
+ * 上报普通 Object 到云控服务器。
36
+ * @param event 自定义事件名称。
37
+ * @param data 可 JSON 序列化的普通 Object。
38
+ * @returns 已连接且数据可写出时返回 true。
39
+ * @description 设备总览状态固定使用 cloud.report("cloud:status", data) 上报;data 的 key 必须是云控端已配置的自定义字段名,多余字段不会在设备总览显示。
40
+ * @example
41
+ * cloud.report("done", { value: 1 });
42
+ */
43
+ function report(event: string, data: Record<string, any>): boolean;
44
+
45
+ /**
46
+ * 监听服务端下发的 scriptEvent 事件(仅主线程调用,不能在线程脚本中调用)。
47
+ * @param callback 主脚本回调函数;传入 null 可取消监听。
48
+ * @example
49
+ * cloud.onEvent((event, data) => {
50
+ * logi("server event:", event, data);
51
+ * });
52
+ */
53
+ function onEvent(
54
+ callback: ((event: string, data: Record<string, any>) => void) | null,
55
+ ): void;
56
+ }
package/types/global.d.ts CHANGED
@@ -79,18 +79,26 @@ declare const sharedState: {
79
79
  };
80
80
 
81
81
  /**
82
- * 设置停止回调(仅主线程调用)
82
+ * 设置停止回调(仅主线程调用,不能在线程脚本中调用)
83
83
  * @param callback 停止回调
84
- * @description 脚本执行完成或异常停止时调用,exit 退出不会触发
84
+ * @description 脚本执行停止时调用,success 表示正常停止,error 表示异常停止,stopped 表示手动停止
85
85
  * @example
86
- * setStopCallback(() => {
87
- * logi("脚本执行完成");
86
+ * setStopCallback((status) => {
87
+ * if (status === "success") {
88
+ * logi("脚本执行完成");
89
+ * } else if (status === "error") {
90
+ * loge("脚本执行异常");
91
+ * } else if (status === "stopped") {
92
+ * logi("脚本手动停止");
93
+ * }
88
94
  * });
89
95
  */
90
- declare function setStopCallback(callback: () => void): void;
96
+ declare function setStopCallback(
97
+ callback: (status: "success" | "error" | "stopped") => void,
98
+ ): void;
91
99
 
92
100
  /**
93
- * 设置异常停止回调(仅主线程调用)
101
+ * 设置异常停止回调(仅主线程调用,不能在线程脚本中调用)
94
102
  * @param callback 异常停止回调
95
103
  * @description 脚本执行异常停止时调用
96
104
  * @example
@@ -192,7 +200,10 @@ declare function getCpuAutoThrottle(): boolean;
192
200
  * @example
193
201
  * const delay = setCpuThrottleDelay(3, 30);
194
202
  */
195
- declare function setCpuThrottleDelay(minMs: number, maxMs: number): { minMs: number; maxMs: number };
203
+ declare function setCpuThrottleDelay(
204
+ minMs: number,
205
+ maxMs: number,
206
+ ): { minMs: number; maxMs: number };
196
207
 
197
208
  /**
198
209
  * 获取 CPU 限流延迟范围(毫秒)
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference path="action.d.ts" />
2
2
  /// <reference path="appleOcr.d.ts" />
3
+ /// <reference path="cloud.d.ts" />
3
4
  /// <reference path="config.d.ts" />
4
5
  /// <reference path="cryptoUtils.d.ts" />
5
6
  /// <reference path="device.d.ts" />
package/types/ui.d.ts CHANGED
@@ -111,8 +111,8 @@ declare namespace ui {
111
111
  function show(): void;
112
112
 
113
113
  /**
114
- * 设置事件回调函数
115
- * @param onEvent 事件回调函数
114
+ * 设置事件回调函数(仅主线程调用,不能在线程脚本中调用)
115
+ * @param onEvent 事件回调函数,传入 null 会取消监听
116
116
  * @example
117
117
  * ui.onEvent((event, data) => {
118
118
  * // 接收网页发送的事件
@@ -120,7 +120,7 @@ declare namespace ui {
120
120
  * })
121
121
  */
122
122
  function onEvent(
123
- event: (event: string, data: Record<string, any>) => void,
123
+ event: ((event: string, data: Record<string, any>) => void) | null,
124
124
  ): void;
125
125
 
126
126
  /**
@@ -3,6 +3,7 @@
3
3
  /// <reference path="节点模块.d.ts" />
4
4
  /// <reference path="卡密模块.d.ts" />
5
5
  /// <reference path="媒体模块.d.ts" />
6
+ /// <reference path="云控模块.d.ts" />
6
7
  /// <reference path="配置模块.d.ts" />
7
8
  /// <reference path="苹果OCR.d.ts" />
8
9
  /// <reference path="全局模块.d.ts" />
@@ -0,0 +1,54 @@
1
+ /// <reference path="全局模块.d.ts" />
2
+
3
+ declare namespace $云控 {
4
+ /**
5
+ * 连接云控服务器。
6
+ * @param 地址 完整 ws:// 或 wss:// 云控地址。
7
+ * @param 设备编号 可选设备编号,不传时沿用当前保存的设备编号。
8
+ * @returns URL 校验通过且连接请求已提交时返回 true。
9
+ * @description 只能在主脚本上下文调用;只影响当前运行期云控连接,不会写入设置页的持久化云控配置。
10
+ * @example
11
+ * const 已提交 = $云控.连接("wss://example.com/control", "device-001");
12
+ */
13
+ function 连接(地址: 字符串, 设备编号?: 字符串): 布尔值;
14
+
15
+ /**
16
+ * 判断云控是否已经连接成功。
17
+ * @returns 已连接时返回 true。
18
+ * @example
19
+ * if ($云控.是否已连接()) {
20
+ * $云控.上报数据("status", { value: "ready" });
21
+ * }
22
+ */
23
+ function 是否已连接(): 布尔值;
24
+
25
+ /**
26
+ * 断开云控连接并停止自动重连。
27
+ * @example
28
+ * $云控.断开连接();
29
+ */
30
+ function 断开连接(): 无返回值;
31
+
32
+ /**
33
+ * 上报普通 Object 到云控服务器。
34
+ * @param 事件 自定义事件名称。
35
+ * @param 数据 可 JSON 序列化的普通 Object。
36
+ * @returns 已连接且数据可写出时返回 true。
37
+ * @description 设备总览状态固定使用 $云控.上报数据("cloud:status", 数据) 上报;数据的 key 必须是云控端已配置的自定义字段名,多余字段不会在设备总览显示。
38
+ * @example
39
+ * $云控.上报数据("done", { value: 1 });
40
+ */
41
+ function 上报数据(事件: 字符串, 数据: 字典<任意类型>): 布尔值;
42
+
43
+ /**
44
+ * 监听服务端下发的 scriptEvent 事件(仅主线程调用,不能在线程脚本中调用)。
45
+ * @param 回调 主脚本回调函数;传入 null 可取消监听。
46
+ * @example
47
+ * $云控.监听事件回调((事件, 数据) => {
48
+ * $打印信息日志("server event:", 事件, 数据);
49
+ * });
50
+ */
51
+ function 监听事件回调(
52
+ 回调: ((事件: 字符串, 数据: 字典<任意类型>) => 无返回值) | null
53
+ ): 无返回值;
54
+ }
@@ -78,18 +78,26 @@ declare const $共享状态: {
78
78
  };
79
79
 
80
80
  /**
81
- * 设置停止回调(仅主线程调用)
81
+ * 设置停止回调(仅主线程调用,不能在线程脚本中调用)
82
82
  * @param callback 停止回调
83
- * @description 脚本执行完成或异常停止时调用,exit 退出不会触发
83
+ * @description 脚本执行停止时调用,success 表示正常停止,error 表示异常停止,stopped 表示手动停止
84
84
  * @example
85
- * $设置停止回调(() => {
86
- * $打印信息日志("脚本执行完成");
85
+ * $设置停止回调((状态) => {
86
+ * if (状态 === "success") {
87
+ * $打印信息日志("脚本执行完成");
88
+ * } else if (状态 === "error") {
89
+ * $打印错误日志("脚本执行异常");
90
+ * } else if (状态 === "stopped") {
91
+ * $打印信息日志("脚本手动停止");
92
+ * }
87
93
  * });
88
94
  */
89
- declare const $设置停止回调: (回调: () => 无返回值) => 无返回值;
95
+ declare const $设置停止回调: (
96
+ 回调: (状态: "success" | "error" | "stopped") => 无返回值,
97
+ ) => 无返回值;
90
98
 
91
99
  /**
92
- * 设置异常停止回调(仅主线程调用)
100
+ * 设置异常停止回调(仅主线程调用,不能在线程脚本中调用)
93
101
  * @param callback 异常停止回调
94
102
  * @description 脚本执行异常停止时调用
95
103
  * @example
@@ -10,8 +10,8 @@ declare namespace $视图 {
10
10
  function 显示(): 无返回值;
11
11
 
12
12
  /**
13
- * 设置事件回调函数
14
- * @param onEvent 事件回调函数
13
+ * 设置事件回调函数(仅主线程调用,不能在线程脚本中调用)
14
+ * @param onEvent 事件回调函数,传入 null 会取消监听
15
15
  * @example
16
16
  * $视图.监听事件回调((事件名称, 数据) => {
17
17
  * // 接收网页发送的事件
@@ -19,7 +19,7 @@ declare namespace $视图 {
19
19
  * })
20
20
  */
21
21
  function 监听事件回调(
22
- 回调函数: (事件名称: 字符串, 数据: 字典<任意类型>) => 无返回值
22
+ 回调函数: ((事件名称: 字符串, 数据: 字典<任意类型>) => 无返回值) | null
23
23
  ): 无返回值;
24
24
 
25
25
  /**