ms-types 0.9.12 → 0.9.13

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.13",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1,55 @@
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
+ * @example
40
+ * cloud.report("done", { value: 1 });
41
+ */
42
+ function report(event: string, data: Record<string, any>): boolean;
43
+
44
+ /**
45
+ * 监听服务端下发的 scriptEvent 事件(仅主线程调用,不能在线程脚本中调用)。
46
+ * @param callback 主脚本回调函数;传入 null 可取消监听。
47
+ * @example
48
+ * cloud.onEvent((event, data) => {
49
+ * logi("server event:", event, data);
50
+ * });
51
+ */
52
+ function onEvent(
53
+ callback: ((event: string, data: Record<string, any>) => void) | null,
54
+ ): void;
55
+ }
package/types/global.d.ts CHANGED
@@ -79,7 +79,7 @@ declare const sharedState: {
79
79
  };
80
80
 
81
81
  /**
82
- * 设置停止回调(仅主线程调用)
82
+ * 设置停止回调(仅主线程调用,不能在线程脚本中调用)
83
83
  * @param callback 停止回调
84
84
  * @description 脚本执行完成或异常停止时调用,exit 退出不会触发
85
85
  * @example
@@ -90,7 +90,7 @@ declare const sharedState: {
90
90
  declare function setStopCallback(callback: () => void): void;
91
91
 
92
92
  /**
93
- * 设置异常停止回调(仅主线程调用)
93
+ * 设置异常停止回调(仅主线程调用,不能在线程脚本中调用)
94
94
  * @param callback 异常停止回调
95
95
  * @description 脚本执行异常停止时调用
96
96
  * @example
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,53 @@
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
+ * @example
38
+ * $云控.上报数据("done", { value: 1 });
39
+ */
40
+ function 上报数据(事件: 字符串, 数据: 字典<任意类型>): 布尔值;
41
+
42
+ /**
43
+ * 监听服务端下发的 scriptEvent 事件(仅主线程调用,不能在线程脚本中调用)。
44
+ * @param 回调 主脚本回调函数;传入 null 可取消监听。
45
+ * @example
46
+ * $云控.监听事件回调((事件, 数据) => {
47
+ * $打印信息日志("server event:", 事件, 数据);
48
+ * });
49
+ */
50
+ function 监听事件回调(
51
+ 回调: ((事件: 字符串, 数据: 字典<任意类型>) => 无返回值) | null
52
+ ): 无返回值;
53
+ }
@@ -78,7 +78,7 @@ declare const $共享状态: {
78
78
  };
79
79
 
80
80
  /**
81
- * 设置停止回调(仅主线程调用)
81
+ * 设置停止回调(仅主线程调用,不能在线程脚本中调用)
82
82
  * @param callback 停止回调
83
83
  * @description 脚本执行完成或异常停止时调用,exit 退出不会触发
84
84
  * @example
@@ -89,7 +89,7 @@ declare const $共享状态: {
89
89
  declare const $设置停止回调: (回调: () => 无返回值) => 无返回值;
90
90
 
91
91
  /**
92
- * 设置异常停止回调(仅主线程调用)
92
+ * 设置异常停止回调(仅主线程调用,不能在线程脚本中调用)
93
93
  * @param callback 异常停止回调
94
94
  * @description 脚本执行异常停止时调用
95
95
  * @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
  /**