@ray-js/robot-data-stream 0.0.14 → 0.0.15-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 (156) hide show
  1. package/lib/mqtt/createCommonOptions.d.ts +4 -2
  2. package/lib/mqtt/createCommonOptions.js +10 -5
  3. package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
  4. package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
  5. package/lib/mqtt/mqttProvider.d.ts +19 -1
  6. package/lib/mqtt/mqttProvider.js +69 -8
  7. package/lib/mqtt/promise.d.ts +57 -4
  8. package/lib/mqtt/promise.js +115 -36
  9. package/lib/mqtt/type/fun.d.ts +49 -0
  10. package/lib/mqtt/type/fun.js +145 -0
  11. package/lib/mqtt/type/index.d.ts +0 -7
  12. package/lib/mqtt/type/index.js +0 -1
  13. package/lib/mqtt/type/protocols/base.d.ts +5 -0
  14. package/lib/mqtt/type/protocols/base.js +32 -0
  15. package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
  16. package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
  17. package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
  18. package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
  19. package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
  20. package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
  21. package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
  22. package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
  23. package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
  24. package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
  25. package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
  26. package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
  27. package/lib/mqtt/type/protocols/index.d.ts +20 -0
  28. package/lib/mqtt/type/protocols/index.js +20 -0
  29. package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
  30. package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
  31. package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
  32. package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
  33. package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
  34. package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
  35. package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
  36. package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
  37. package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
  38. package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
  39. package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
  40. package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
  41. package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
  42. package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
  43. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
  44. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
  45. package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
  46. package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
  47. package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
  48. package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
  49. package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
  50. package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
  51. package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
  52. package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
  53. package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
  54. package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
  55. package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
  56. package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
  57. package/lib/mqtt/useCarpet.d.ts +7 -67
  58. package/lib/mqtt/useCarpet.js +101 -181
  59. package/lib/mqtt/useCarpetClean.d.ts +2 -11
  60. package/lib/mqtt/useCarpetClean.js +24 -51
  61. package/lib/mqtt/useDevInfo.d.ts +8 -6
  62. package/lib/mqtt/useDevInfo.js +44 -36
  63. package/lib/mqtt/useDeviceModel.d.ts +6 -19
  64. package/lib/mqtt/useDeviceModel.js +29 -42
  65. package/lib/mqtt/useFurnitureModel.d.ts +6 -18
  66. package/lib/mqtt/useFurnitureModel.js +29 -43
  67. package/lib/mqtt/useHistoryMap.d.ts +2 -18
  68. package/lib/mqtt/useHistoryMap.js +102 -119
  69. package/lib/mqtt/usePartDivision.d.ts +2 -9
  70. package/lib/mqtt/usePartDivision.js +48 -57
  71. package/lib/mqtt/usePartMerge.d.ts +2 -8
  72. package/lib/mqtt/usePartMerge.js +34 -49
  73. package/lib/mqtt/usePassword.d.ts +6 -13
  74. package/lib/mqtt/usePassword.js +84 -74
  75. package/lib/mqtt/useQuiteHours.d.ts +4 -37
  76. package/lib/mqtt/useQuiteHours.js +66 -100
  77. package/lib/mqtt/useResetMap.d.ts +2 -8
  78. package/lib/mqtt/useResetMap.js +27 -34
  79. package/lib/mqtt/useRoomProperty.d.ts +8 -9
  80. package/lib/mqtt/useRoomProperty.js +67 -65
  81. package/lib/mqtt/useSchedule.d.ts +3 -23
  82. package/lib/mqtt/useSchedule.js +72 -101
  83. package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
  84. package/lib/mqtt/useSelectRoomClean.js +107 -133
  85. package/lib/mqtt/useSpotClean.d.ts +5 -15
  86. package/lib/mqtt/useSpotClean.js +68 -121
  87. package/lib/mqtt/useVirtualArea.d.ts +6 -17
  88. package/lib/mqtt/useVirtualArea.js +109 -119
  89. package/lib/mqtt/useVirtualWall.d.ts +2 -18
  90. package/lib/mqtt/useVirtualWall.js +69 -90
  91. package/lib/mqtt/useVoice.d.ts +2 -16
  92. package/lib/mqtt/useVoice.js +48 -68
  93. package/lib/mqtt/useWifiMap.d.ts +6 -5
  94. package/lib/mqtt/useWifiMap.js +43 -42
  95. package/lib/mqtt/useZoneClean.d.ts +2 -21
  96. package/lib/mqtt/useZoneClean.js +125 -137
  97. package/lib/myLib/zod/mini/index.d.cts +1 -0
  98. package/lib/myLib/zod/mini/index.d.ts +1 -0
  99. package/lib/myLib/zod/mini/index.js +1 -0
  100. package/lib/myLib/zod/mini/package.json +6 -0
  101. package/lib/myLib/zod/src/mini/index.d.ts +1 -0
  102. package/lib/myLib/zod/src/mini/index.js +1 -0
  103. package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
  104. package/lib/myLib/zod/src/v4/core/api.js +1256 -0
  105. package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
  106. package/lib/myLib/zod/src/v4/core/checks.js +816 -0
  107. package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
  108. package/lib/myLib/zod/src/v4/core/config.js +5 -0
  109. package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
  110. package/lib/myLib/zod/src/v4/core/core.js +95 -0
  111. package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
  112. package/lib/myLib/zod/src/v4/core/doc.js +42 -0
  113. package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
  114. package/lib/myLib/zod/src/v4/core/errors.js +232 -0
  115. package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
  116. package/lib/myLib/zod/src/v4/core/index.js +15 -0
  117. package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
  118. package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
  119. package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
  120. package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
  121. package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
  122. package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
  123. package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
  124. package/lib/myLib/zod/src/v4/core/parse.js +147 -0
  125. package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
  126. package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
  127. package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
  128. package/lib/myLib/zod/src/v4/core/registries.js +51 -0
  129. package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
  130. package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
  131. package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
  132. package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
  133. package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
  134. package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
  135. package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
  136. package/lib/myLib/zod/src/v4/core/util.js +656 -0
  137. package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
  138. package/lib/myLib/zod/src/v4/core/versions.js +5 -0
  139. package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
  140. package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
  141. package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
  142. package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
  143. package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
  144. package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
  145. package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
  146. package/lib/myLib/zod/src/v4/mini/external.js +16 -0
  147. package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
  148. package/lib/myLib/zod/src/v4/mini/index.js +3 -0
  149. package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
  150. package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
  151. package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
  152. package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
  153. package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
  154. package/lib/utils/index.d.ts +1 -0
  155. package/lib/utils/index.js +2 -1
  156. package/package.json +5 -3
@@ -0,0 +1,145 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ // protocol-validator.ts
3
+
4
+ import { MqttError } from '../promise';
5
+
6
+ // 导入各个协议的 schema 和验证函数
7
+ import { setCarpetCleanSchema } from './protocols/carpetCleanProtocol';
8
+ import { addCarpetSchema, deleteCarpetSchema, queryCarpetSchema, setCarpetSchema, updateCarpetSchema, validateAddCarpet, validateSetCarpet, validateUpdateCarpet } from './protocols/carpetProtocol';
9
+ import { setDeviceModelSchema } from './protocols/deviceModelProtocol';
10
+ import { requestFurnitureListSchema, setFurnitureModelSchema } from './protocols/furnitureModelProtocol';
11
+ import { changeCurrentMapSchema, deleteHistoryMapSchema, saveMapSchema } from './protocols/historyMapProtocol';
12
+ import { pointsSchema, roomIdSchema, originSchema } from './protocols/partDivisionProtocol';
13
+ import { setPartMergeSchema } from './protocols/partMergeProtocol';
14
+ import { checkPasswordSchema, setPasswordSchema } from './protocols/passwordProtocol';
15
+ import { setQuietHoursSchema } from './protocols/quietHoursProtocol';
16
+ import { setRoomPropertySchema, validateSetRoomProperty } from './protocols/roomPropertyProtocol';
17
+ import { requestScheduleSchema, setScheduleSchema, validateSetSchedule } from './protocols/scheduleProtocol';
18
+ import { setSelectRoomCleanSchema } from './protocols/selectRoomCleanProtocol';
19
+ import { setSpotCleanSchema, validateSetSpotClean } from './protocols/spotCleanProtocol';
20
+ import { setVirtualAreaSchema } from './protocols/virtualAreaProtocol';
21
+ import { setVirtualWallSchema } from './protocols/virtualWallProtocol';
22
+ import { setVoiceSchema } from './protocols/voiceProtocol';
23
+ import { setWifiMapSchema } from './protocols/wifiMapProtocol';
24
+ import { setZoneCleanSchema } from './protocols/zoneCleanProtocol';
25
+
26
+ /**
27
+ * 验证失败错误代码
28
+ * -2 表示数据验证失败
29
+ */
30
+ const VALIDATION_ERROR_CODE = -2;
31
+
32
+ // 协议定义 - 从各个协议文件导入
33
+ export const ProtocolSchemas = {
34
+ query_carpet: queryCarpetSchema,
35
+ add_carpet: addCarpetSchema,
36
+ update_carpet: updateCarpetSchema,
37
+ delete_carpet: deleteCarpetSchema,
38
+ set_carpet: setCarpetSchema,
39
+ set_schedule: setScheduleSchema,
40
+ request_schedule: requestScheduleSchema,
41
+ set_zone_clean: setZoneCleanSchema,
42
+ set_wifi_map: setWifiMapSchema,
43
+ set_voice: setVoiceSchema,
44
+ set_virtual_wall: setVirtualWallSchema,
45
+ set_virtual_area: setVirtualAreaSchema,
46
+ set_spot_clean: setSpotCleanSchema,
47
+ set_select_room_clean: setSelectRoomCleanSchema,
48
+ set_quiet_hours: setQuietHoursSchema,
49
+ set_password: setPasswordSchema,
50
+ check_password: checkPasswordSchema,
51
+ set_part_merge: setPartMergeSchema,
52
+ delete_history_map: deleteHistoryMapSchema,
53
+ save_map: saveMapSchema,
54
+ change_current_map: changeCurrentMapSchema,
55
+ request_furniture_list: requestFurnitureListSchema,
56
+ set_furniture_model: setFurnitureModelSchema,
57
+ set_device_model: setDeviceModelSchema,
58
+ set_carpet_clean: setCarpetCleanSchema,
59
+ set_room_property: setRoomPropertySchema
60
+ };
61
+
62
+ // 协议验证函数类型
63
+
64
+ // 协议注册表 - 将协议名称映射到验证函数
65
+ const protocolValidators = {
66
+ add_carpet: validateAddCarpet,
67
+ update_carpet: validateUpdateCarpet,
68
+ set_carpet: validateSetCarpet,
69
+ set_schedule: validateSetSchedule,
70
+ set_spot_clean: validateSetSpotClean,
71
+ set_room_property: validateSetRoomProperty
72
+ // query_carpet 没有自定义验证逻辑,不需要注册
73
+ // delete_carpet 没有自定义验证逻辑,不需要注册
74
+ // request_schedule 没有自定义验证逻辑,不需要注册
75
+ };
76
+
77
+ // 类型导出
78
+
79
+ // 验证器类
80
+ export class MiniProtocolValidator {
81
+ validate(protocol, data) {
82
+ const schema = ProtocolSchemas[protocol];
83
+
84
+ // 使用 zod/mini 的 safeParse 进行基础验证
85
+ const result = schema.safeParse(data);
86
+ if (!result.success) {
87
+ // 验证失败,抛出 MqttError
88
+ throw new MqttError(`协议 ${protocol} ${JSON.stringify(data)} 验证失败:\n` + result.error.issues.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\n'), {
89
+ errCode: VALIDATION_ERROR_CODE,
90
+ reqType: protocol
91
+ });
92
+ }
93
+ const validatedData = result.data;
94
+
95
+ // 自定义逻辑验证 - 根据协议名称调用对应的验证函数
96
+ const validator = protocolValidators[protocol];
97
+ if (validator) {
98
+ validator(validatedData);
99
+ }
100
+ return validatedData;
101
+ }
102
+
103
+ /**
104
+ * 验证 set_part_division 的三个独立参数
105
+ * @param points 分隔点数组
106
+ * @param roomId 房间ID(可以是 int 或 string)
107
+ * @param origin 地图原点坐标
108
+ * @returns 验证后的数据对象
109
+ */
110
+ validateSetPartDivision(points, roomId, origin) {
111
+ // 分别验证三个参数
112
+ const pointsResult = pointsSchema.safeParse(points);
113
+ if (!pointsResult.success) {
114
+ throw new MqttError(`协议 set_part_division points 参数验证失败:\n` + pointsResult.error.issues.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\n'), {
115
+ errCode: VALIDATION_ERROR_CODE,
116
+ reqType: 'set_part_division'
117
+ });
118
+ }
119
+ const roomIdResult = roomIdSchema.safeParse(roomId);
120
+ if (!roomIdResult.success) {
121
+ throw new MqttError(`协议 set_part_division roomId 参数验证失败:\n` + roomIdResult.error.issues.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\n'), {
122
+ errCode: VALIDATION_ERROR_CODE,
123
+ reqType: 'set_part_division'
124
+ });
125
+ }
126
+ const originResult = originSchema.safeParse(origin);
127
+ if (!originResult.success) {
128
+ throw new MqttError(`协议 set_part_division origin 参数验证失败:\n` + originResult.error.issues.map(e => ` ${e.path.join('.')}: ${e.message}`).join('\n'), {
129
+ errCode: VALIDATION_ERROR_CODE,
130
+ reqType: 'set_part_division'
131
+ });
132
+ }
133
+
134
+ // 组合成对象并验证整体结构
135
+ const data = {
136
+ points: pointsResult.data,
137
+ roomId: roomIdResult.data,
138
+ origin: originResult.data
139
+ };
140
+ return data;
141
+ }
142
+ }
143
+
144
+ // 导出验证器实例
145
+ export const validator = new MiniProtocolValidator();
@@ -1,11 +1,4 @@
1
1
  export * from './requestType';
2
- export interface BaseResponse {
3
- success: boolean;
4
- errCode: number;
5
- reqType: string;
6
- version: string;
7
- taskId: string;
8
- }
9
2
  /**
10
3
  * MQTT 协议号枚举
11
4
  */
@@ -1,5 +1,4 @@
1
1
  export * from './requestType';
2
- // 设备接口响应的统一标准结构
3
2
 
4
3
  /**
5
4
  * MQTT 协议号枚举
@@ -0,0 +1,5 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const Point: any;
3
+ export declare const RoomPreferenceFieldsSchema: any;
4
+ export declare const BaseResponseSchema: any;
5
+ export type BaseResponse = z.infer<typeof BaseResponseSchema>;
@@ -0,0 +1,32 @@
1
+ import * as z from 'zod/mini';
2
+
3
+ // 基础类型
4
+ export const Point = z.object({
5
+ x: z.number(),
6
+ y: z.number()
7
+ });
8
+
9
+ // RoomPreference 相关字段 Schema
10
+ export const RoomPreferenceFieldsSchema = z.object({
11
+ // 吸力, closed - 关闭 gentle - 安静 normal - 正常 strong - 强劲 max - 超强 ,默认值为''
12
+ suctions: z.optional(z.array(z.string())),
13
+ // 拖地水量 "closed"- 关闭,"low"-低,"middle"-中,"high"-高,默认值为''
14
+ cisterns: z.optional(z.array(z.string())),
15
+ // 清扫次数 默认值1
16
+ cleanCounts: z.optional(z.array(z.int())),
17
+ // 拖地模式 1:开启Y型拖地 0:关闭Y型拖地 -1 未设置 默认值-1
18
+ yMops: z.optional(z.array(z.int())),
19
+ // 扫拖模式 "only_sweep":仅扫,"only_mop":仅拖,"both_work":扫拖同时,"clean_before_mop":先扫后拖,默认值为'only_sweep'
20
+ sweepMopModes: z.optional(z.array(z.string())),
21
+ // 房间id集合
22
+ ids: z.optional(z.array(z.int()))
23
+ });
24
+
25
+ // BaseResponse Schema(用于响应类型)
26
+ export const BaseResponseSchema = z.object({
27
+ success: z.boolean(),
28
+ errCode: z.number(),
29
+ reqType: z.string(),
30
+ version: z.string(),
31
+ taskId: z.string()
32
+ });
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod/mini';
2
+ export declare const setCarpetCleanSchema: any;
3
+ declare const carpetCleanResponseSchema: any;
4
+ export type SetCarpetCleanData = z.infer<typeof setCarpetCleanSchema>;
5
+ export type CarpetCleanResponse = z.infer<typeof carpetCleanResponseSchema>;
6
+ export type TRequestCarpetClean = () => Promise<CarpetCleanResponse>;
7
+ export type TSetCarpetClean = (data: SetCarpetCleanData) => Promise<CarpetCleanResponse>;
8
+ export {};
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+
4
+ // 设置地毯清扫参数 Schema
5
+ export const setCarpetCleanSchema = z.object({
6
+ ids: z.array(z.number()) // 地毯ID数组,注意: .min()放在数组元素上
7
+ });
8
+
9
+ // 地毯清扫响应 Schema
10
+ const carpetCleanResponseSchema = z.extend(BaseResponseSchema, {
11
+ ids: z.array(z.number())
12
+ });
13
+
14
+ // 类型导出
15
+
16
+ // 函数类型定义
@@ -0,0 +1,41 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponse } from './base';
3
+ export declare const queryCarpetSchema: any;
4
+ export declare const addCarpetSchema: any;
5
+ export declare const updateCarpetSchema: any;
6
+ export declare const deleteCarpetSchema: any;
7
+ export declare const setCarpetSchema: any;
8
+ declare const addCarpetResponseSchema: any;
9
+ declare const carpetQueryResponseSchema: any;
10
+ export type QueryCarpetData = z.infer<typeof queryCarpetSchema>;
11
+ export type AddCarpetData = z.infer<typeof addCarpetSchema>;
12
+ export type UpdateCarpetData = z.infer<typeof updateCarpetSchema>;
13
+ export type DeleteCarpetData = z.infer<typeof deleteCarpetSchema>;
14
+ export type SetCarpetData = z.infer<typeof setCarpetSchema>;
15
+ export type AddCarpetResponse = z.infer<typeof addCarpetResponseSchema>;
16
+ export type CarpetQueryResponse = z.infer<typeof carpetQueryResponseSchema>;
17
+ /**
18
+ * 验证添加地毯协议数据
19
+ * @param data 已验证基础 schema 的数据
20
+ * @throws MqttError 验证失败时抛出
21
+ */
22
+ export declare function validateAddCarpet(data: AddCarpetData): void;
23
+ /**
24
+ * 验证更新地毯协议数据
25
+ * @param data 已验证基础 schema 的数据
26
+ * @throws MqttError 验证失败时抛出
27
+ */
28
+ export declare function validateUpdateCarpet(data: UpdateCarpetData): void;
29
+ /**
30
+ * 验证设置地毯协议数据
31
+ * @param data 已验证基础 schema 的数据
32
+ * @throws MqttError 验证失败时抛出
33
+ */
34
+ export declare function validateSetCarpet(data: SetCarpetData): void;
35
+ export type TQueryCarpet = (data?: QueryCarpetData) => Promise<CarpetQueryResponse>;
36
+ export type TAddCarpet = (data: AddCarpetData) => Promise<AddCarpetResponse>;
37
+ export type TUpdateCarpet = (data: UpdateCarpetData) => Promise<BaseResponse>;
38
+ export type TDeleteCarpet = (data: DeleteCarpetData) => Promise<BaseResponse>;
39
+ export type TSetCarpet = (data: SetCarpetData) => Promise<CarpetQueryResponse>;
40
+ export type SetCarpetInput = SetCarpetData;
41
+ export {};
@@ -0,0 +1,202 @@
1
+ import * as z from 'zod/mini';
2
+ import { MqttError } from '../../promise';
3
+ import { BaseResponseSchema, Point } from './base';
4
+
5
+ /**
6
+ * 验证失败错误代码
7
+ * -2 表示数据验证失败
8
+ */
9
+ const VALIDATION_ERROR_CODE = -2;
10
+
11
+ // 形状类型
12
+ const ShapeType = z.union([z.literal('rectangle'), z.literal('round'), z.literal('custom')]);
13
+
14
+ // 请求查询地毯参数 Schema(目前为空,但保留扩展性)
15
+ export const queryCarpetSchema = z.object({});
16
+
17
+ // 添加地毯参数 Schema
18
+ export const addCarpetSchema = z.object({
19
+ shape: z.array(ShapeType),
20
+ polygons: z.array(z.array(Point)),
21
+ num: z.number(),
22
+ type: z.array(z.number()),
23
+ cleanMode: z.array(z.number()),
24
+ autoBoost: z.optional(z.array(z.number())),
25
+ fineCleaning: z.optional(z.array(z.number())),
26
+ sideBrushRotating: z.optional(z.array(z.number()))
27
+ });
28
+
29
+ // 更新地毯参数 Schema(所有字段都是可选的,除了 ids)
30
+ export const updateCarpetSchema = z.object({
31
+ ids: z.array(z.number()),
32
+ shape: z.optional(z.array(ShapeType)),
33
+ type: z.optional(z.array(z.number())),
34
+ cleanMode: z.optional(z.array(z.number())),
35
+ autoBoost: z.optional(z.array(z.number())),
36
+ fineCleaning: z.optional(z.array(z.number())),
37
+ sideBrushRotating: z.optional(z.array(z.number())),
38
+ polygons: z.optional(z.array(z.array(Point)))
39
+ });
40
+
41
+ // 删除地毯参数 Schema
42
+ export const deleteCarpetSchema = z.object({
43
+ ids: z.array(z.number())
44
+ });
45
+
46
+ // 设置地毯参数 Schema
47
+ export const setCarpetSchema = z.object({
48
+ num: z.int().check(z.gte(0), z.lte(100)),
49
+ polygons: z.array(z.array(Point).check(z.minLength(3))),
50
+ cleanMode: z.array(z.int().check(z.gte(0), z.lte(10))),
51
+ shape: z.array(ShapeType),
52
+ ids: z.array(z.int()),
53
+ type: z.optional(z.array(z.int())),
54
+ autoBoost: z.optional(z.array(z.int())),
55
+ fineCleaning: z.optional(z.array(z.int())),
56
+ sideBrushRotating: z.optional(z.array(z.int()))
57
+ });
58
+
59
+ // 添加地毯响应 Schema
60
+ const addCarpetResponseSchema = z.extend(BaseResponseSchema, {
61
+ // 返回的地毯ID数组
62
+ ids: z.array(z.int())
63
+ });
64
+
65
+ // 地毯查询响应 Schema
66
+ const carpetQueryResponseSchema = z.extend(BaseResponseSchema, {
67
+ // 地毯数量
68
+ num: z.int(),
69
+ // 轮廓点集合(字符串格式)
70
+ polygons: z.array(z.string()),
71
+ // 清洁属性
72
+ cleanMode: z.optional(z.array(z.int())),
73
+ // 形状
74
+ shape: z.optional(z.array(z.string())),
75
+ // 材质
76
+ type: z.optional(z.array(z.int())),
77
+ // 地毯ID数组
78
+ ids: z.optional(z.array(z.int())),
79
+ // 自动增压
80
+ autoBoost: z.optional(z.array(z.int())),
81
+ // 精细清扫
82
+ fineCleaning: z.optional(z.array(z.int())),
83
+ // 边刷旋转
84
+ sideBrushRotating: z.optional(z.array(z.int()))
85
+ });
86
+
87
+ // 类型导出
88
+
89
+ /**
90
+ * 验证添加地毯协议数据
91
+ * @param data 已验证基础 schema 的数据
92
+ * @throws MqttError 验证失败时抛出
93
+ */
94
+ export function validateAddCarpet(data) {
95
+ const {
96
+ num
97
+ } = data;
98
+
99
+ // 验证数组长度一致性
100
+ const validateLength = (name, array) => {
101
+ if (array.length !== num) {
102
+ throw new MqttError(`${name} 长度必须为 ${num},实际为 ${array.length}`, {
103
+ errCode: VALIDATION_ERROR_CODE,
104
+ reqType: 'add_carpet'
105
+ });
106
+ }
107
+ };
108
+ validateLength('shape', data.shape);
109
+ validateLength('polygons', data.polygons);
110
+ validateLength('type', data.type);
111
+ validateLength('cleanMode', data.cleanMode);
112
+ if (data.autoBoost) {
113
+ validateLength('autoBoost', data.autoBoost);
114
+ }
115
+ if (data.fineCleaning) {
116
+ validateLength('fineCleaning', data.fineCleaning);
117
+ }
118
+ if (data.sideBrushRotating) {
119
+ validateLength('sideBrushRotating', data.sideBrushRotating);
120
+ }
121
+ }
122
+
123
+ /**
124
+ * 验证更新地毯协议数据
125
+ * @param data 已验证基础 schema 的数据
126
+ * @throws MqttError 验证失败时抛出
127
+ */
128
+ export function validateUpdateCarpet(data) {
129
+ const num = data.ids.length;
130
+
131
+ // 验证数组长度一致性(如果提供了数组字段)
132
+ const validateLength = (name, array) => {
133
+ if (array.length !== num) {
134
+ throw new MqttError(`${name} 长度必须为 ${num},实际为 ${array.length}`, {
135
+ errCode: VALIDATION_ERROR_CODE,
136
+ reqType: 'update_carpet'
137
+ });
138
+ }
139
+ };
140
+ if (data.shape) {
141
+ validateLength('shape', data.shape);
142
+ }
143
+ if (data.type) {
144
+ validateLength('type', data.type);
145
+ }
146
+ if (data.cleanMode) {
147
+ validateLength('cleanMode', data.cleanMode);
148
+ }
149
+ if (data.polygons) {
150
+ validateLength('polygons', data.polygons);
151
+ }
152
+ if (data.autoBoost) {
153
+ validateLength('autoBoost', data.autoBoost);
154
+ }
155
+ if (data.fineCleaning) {
156
+ validateLength('fineCleaning', data.fineCleaning);
157
+ }
158
+ if (data.sideBrushRotating) {
159
+ validateLength('sideBrushRotating', data.sideBrushRotating);
160
+ }
161
+ }
162
+
163
+ /**
164
+ * 验证设置地毯协议数据
165
+ * @param data 已验证基础 schema 的数据
166
+ * @throws MqttError 验证失败时抛出
167
+ */
168
+ export function validateSetCarpet(data) {
169
+ const {
170
+ num
171
+ } = data;
172
+
173
+ // 验证数组长度一致性
174
+ const validateLength = (name, array) => {
175
+ if (array.length !== num) {
176
+ throw new MqttError(`${name} 长度必须为 ${num},实际为 ${array.length}`, {
177
+ errCode: VALIDATION_ERROR_CODE,
178
+ reqType: 'set_carpet'
179
+ });
180
+ }
181
+ };
182
+ validateLength('polygons', data.polygons);
183
+ validateLength('cleanMode', data.cleanMode);
184
+ validateLength('shape', data.shape);
185
+ validateLength('ids', data.ids);
186
+ if (data.type) {
187
+ validateLength('type', data.type);
188
+ }
189
+ if (data.autoBoost) {
190
+ validateLength('autoBoost', data.autoBoost);
191
+ }
192
+ if (data.fineCleaning) {
193
+ validateLength('fineCleaning', data.fineCleaning);
194
+ }
195
+ if (data.sideBrushRotating) {
196
+ validateLength('sideBrushRotating', data.sideBrushRotating);
197
+ }
198
+ }
199
+
200
+ // 函数类型定义
201
+
202
+ // 导出 SetCarpetInput 类型别名(向后兼容)
@@ -0,0 +1,5 @@
1
+ import * as z from 'zod/mini';
2
+ declare const devInfoResponseSchema: any;
3
+ export type DevInfoResponse = z.infer<typeof devInfoResponseSchema>;
4
+ export type TRequestDevInfo = () => Promise<DevInfoResponse>;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+
4
+ // 设备信息响应 Schema
5
+ const devInfoResponseSchema = z.extend(BaseResponseSchema, {
6
+ // 设备信息的 JSON 字符串
7
+ info: z.string()
8
+ });
9
+
10
+ // 类型导出
11
+
12
+ // 函数类型定义
@@ -0,0 +1,8 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const setDeviceModelSchema: any;
3
+ declare const deviceModelResponseSchema: any;
4
+ export type SetDeviceModelData = z.infer<typeof setDeviceModelSchema>;
5
+ export type DeviceModelResponse = z.infer<typeof deviceModelResponseSchema>;
6
+ export type TRequestDeviceList = () => Promise<DeviceModelResponse>;
7
+ export type TSetDeviceModel = (data: SetDeviceModelData) => Promise<DeviceModelResponse>;
8
+ export {};
@@ -0,0 +1,34 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+
4
+ // 设备模型信息 Schema
5
+ const deviceModelInfoSchema = z.object({
6
+ id: z.int(),
7
+ // 设备模型ID
8
+ modelType: z.int(),
9
+ // 设备模型类型
10
+ scale: z.number(),
11
+ // 设备模型缩放比例
12
+ size: z.tuple([z.number(), z.number(), z.number()]),
13
+ // 设备模型尺寸
14
+ rotation: z.tuple([z.number(), z.number(), z.number()]),
15
+ // 设备模型旋转角度
16
+ position: z.tuple([z.number(), z.number(), z.number()]),
17
+ // 设备模型位置
18
+ subDevId: z.string() // 当前设备模型所关联的设备ID
19
+ });
20
+
21
+ // 设置设备模型参数 Schema
22
+ export const setDeviceModelSchema = z.object({
23
+ modelInfos: z.array(deviceModelInfoSchema) // 设备模型信息数组
24
+ });
25
+
26
+ // 设备模型响应 Schema
27
+ const deviceModelResponseSchema = z.extend(BaseResponseSchema, {
28
+ // 设备模型信息数组
29
+ modelInfo: z.array(deviceModelInfoSchema)
30
+ });
31
+
32
+ // 类型导出
33
+
34
+ // 函数类型定义
@@ -0,0 +1,10 @@
1
+ import * as z from 'zod/mini';
2
+ export declare const requestFurnitureListSchema: any;
3
+ export declare const setFurnitureModelSchema: any;
4
+ declare const furnitureModelResponseSchema: any;
5
+ type RequestFurnitureListData = z.infer<typeof requestFurnitureListSchema>;
6
+ type SetFurnitureModelData = z.infer<typeof setFurnitureModelSchema>;
7
+ export type FurnitureModelResponse = z.infer<typeof furnitureModelResponseSchema>;
8
+ export type TRequestFurnitureList = (data?: RequestFurnitureListData) => Promise<FurnitureModelResponse>;
9
+ export type TSetFurnitureModel = (data: SetFurnitureModelData) => Promise<FurnitureModelResponse>;
10
+ export {};
@@ -0,0 +1,35 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+
4
+ // 家具模型信息 Schema
5
+ const furnitureModelInfoSchema = z.object({
6
+ id: z.int(),
7
+ // 家具模型ID
8
+ modelType: z.int(),
9
+ // 家具模型类型
10
+ scale: z.number(),
11
+ // 家具模型缩放比例
12
+ size: z.tuple([z.number(), z.number(), z.number()]),
13
+ // 家具模型尺寸
14
+ rotation: z.tuple([z.number(), z.number(), z.number()]),
15
+ // 家具模型旋转角度
16
+ position: z.tuple([z.number(), z.number(), z.number()]) // 家具模型位置
17
+ });
18
+
19
+ // 请求家具列表参数 Schema(目前为空,但保留扩展性)
20
+ export const requestFurnitureListSchema = z.object({});
21
+
22
+ // 设置家具模型参数 Schema
23
+ export const setFurnitureModelSchema = z.object({
24
+ modelInfos: z.array(furnitureModelInfoSchema) // 家具模型信息数组
25
+ });
26
+
27
+ // 家具模型响应 Schema
28
+ const furnitureModelResponseSchema = z.extend(BaseResponseSchema, {
29
+ // 家具模型信息数组
30
+ modelInfo: z.array(furnitureModelInfoSchema)
31
+ });
32
+
33
+ // 类型导出
34
+
35
+ // 函数类型定义
@@ -0,0 +1,17 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+ export declare const deleteHistoryMapSchema: any;
4
+ export declare const saveMapSchema: any;
5
+ export declare const changeCurrentMapSchema: any;
6
+ declare const saveMapResponseSchema: any;
7
+ declare const changeCurrentMapResponseSchema: any;
8
+ export type DeleteHistoryMapData = z.infer<typeof deleteHistoryMapSchema>;
9
+ export type SaveMapData = z.infer<typeof saveMapSchema>;
10
+ export type ChangeCurrentMapData = z.infer<typeof changeCurrentMapSchema>;
11
+ export type DeleteMapResponse = z.infer<typeof BaseResponseSchema>;
12
+ export type SaveMapResponse = z.infer<typeof saveMapResponseSchema>;
13
+ export type UseMapResponse = z.infer<typeof changeCurrentMapResponseSchema>;
14
+ export type TDeleteHistoryMap = (mapId: number) => Promise<DeleteMapResponse>;
15
+ export type TSaveMap = (data?: SaveMapData) => Promise<SaveMapResponse>;
16
+ export type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
17
+ export {};
@@ -0,0 +1,37 @@
1
+ import * as z from 'zod/mini';
2
+ import { BaseResponseSchema } from './base';
3
+
4
+ // 删除历史地图参数 Schema
5
+ export const deleteHistoryMapSchema = z.object({
6
+ mapId: z.int() // 地图ID
7
+ });
8
+
9
+ // 保存当前地图参数 Schema
10
+ export const saveMapSchema = z.object({
11
+ oper: z.int() // 操作类型:0 表示保存
12
+ });
13
+
14
+ // 更改当前使用的地图参数 Schema
15
+ export const changeCurrentMapSchema = z.object({
16
+ mapId: z.int(),
17
+ // 地图ID
18
+ url: z.string(),
19
+ // 地图URL
20
+ urlLen: z.int() // URL 长度
21
+ });
22
+
23
+ // 保存地图响应 Schema
24
+ const saveMapResponseSchema = z.extend(BaseResponseSchema, {
25
+ // 保存后的地图ID
26
+ mapId: z.int()
27
+ });
28
+
29
+ // 更改当前地图响应 Schema
30
+ const changeCurrentMapResponseSchema = z.extend(BaseResponseSchema, {
31
+ // 当前使用的地图ID
32
+ mapId: z.int()
33
+ });
34
+
35
+ // 类型导出
36
+
37
+ // 函数类型定义
@@ -0,0 +1,20 @@
1
+ export * from './scheduleProtocol';
2
+ export * from './carpetProtocol';
3
+ export * from './zoneCleanProtocol';
4
+ export * from './wifiMapProtocol';
5
+ export * from './voiceProtocol';
6
+ export * from './virtualWallProtocol';
7
+ export * from './virtualAreaProtocol';
8
+ export * from './spotCleanProtocol';
9
+ export * from './selectRoomCleanProtocol';
10
+ export * from './resetMapProtocol';
11
+ export * from './quietHoursProtocol';
12
+ export * from './passwordProtocol';
13
+ export * from './partMergeProtocol';
14
+ export * from './partDivisionProtocol';
15
+ export * from './historyMapProtocol';
16
+ export * from './furnitureModelProtocol';
17
+ export * from './deviceModelProtocol';
18
+ export * from './carpetCleanProtocol';
19
+ export * from './devInfoProtocol';
20
+ export * from './roomPropertyProtocol';