@zucker-framework/things 1.0.0
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/LICENSE +201 -0
- package/NOTICE +22 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/index.d.mts +560 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.js +451 -0
- package/dist/index.mjs +415 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { AggregationQuery, AggregationResult, TimeSeriesService } from '@zucker-framework/timeseries';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 物模型数据类型系统 — 对应 jetlinks DataType / DataTypes
|
|
5
|
+
*
|
|
6
|
+
* 描述属性、事件参数、功能参数的值类型。
|
|
7
|
+
*/
|
|
8
|
+
type DataTypeId = 'string' | 'int' | 'long' | 'float' | 'double' | 'boolean' | 'enum' | 'date' | 'object' | 'array' | 'geo' | 'password' | 'file';
|
|
9
|
+
/**
|
|
10
|
+
* 枚举元素 — 对应 jetlinks EnumType.Element
|
|
11
|
+
*/
|
|
12
|
+
interface EnumElement {
|
|
13
|
+
value: string | number;
|
|
14
|
+
text: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 地理坐标 — 对应 jetlinks GeoType
|
|
19
|
+
*/
|
|
20
|
+
interface GeoPoint {
|
|
21
|
+
lat: number;
|
|
22
|
+
lon: number;
|
|
23
|
+
}
|
|
24
|
+
interface BaseDataType {
|
|
25
|
+
id: DataTypeId;
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
interface StringDataType extends BaseDataType {
|
|
29
|
+
id: 'string';
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
unit?: string;
|
|
32
|
+
}
|
|
33
|
+
interface IntDataType extends BaseDataType {
|
|
34
|
+
id: 'int';
|
|
35
|
+
max?: number;
|
|
36
|
+
min?: number;
|
|
37
|
+
unit?: string;
|
|
38
|
+
}
|
|
39
|
+
interface LongDataType extends BaseDataType {
|
|
40
|
+
id: 'long';
|
|
41
|
+
max?: number;
|
|
42
|
+
min?: number;
|
|
43
|
+
unit?: string;
|
|
44
|
+
}
|
|
45
|
+
interface FloatDataType extends BaseDataType {
|
|
46
|
+
id: 'float';
|
|
47
|
+
max?: number;
|
|
48
|
+
min?: number;
|
|
49
|
+
unit?: string;
|
|
50
|
+
scale?: number;
|
|
51
|
+
}
|
|
52
|
+
interface DoubleDataType extends BaseDataType {
|
|
53
|
+
id: 'double';
|
|
54
|
+
max?: number;
|
|
55
|
+
min?: number;
|
|
56
|
+
unit?: string;
|
|
57
|
+
scale?: number;
|
|
58
|
+
}
|
|
59
|
+
interface BooleanDataType extends BaseDataType {
|
|
60
|
+
id: 'boolean';
|
|
61
|
+
trueText?: string;
|
|
62
|
+
falseText?: string;
|
|
63
|
+
trueValue?: string;
|
|
64
|
+
falseValue?: string;
|
|
65
|
+
}
|
|
66
|
+
interface EnumDataType extends BaseDataType {
|
|
67
|
+
id: 'enum';
|
|
68
|
+
elements: EnumElement[];
|
|
69
|
+
}
|
|
70
|
+
interface DateDataType extends BaseDataType {
|
|
71
|
+
id: 'date';
|
|
72
|
+
/** 日期格式,默认 'yyyy-MM-dd HH:mm:ss' */
|
|
73
|
+
format?: string;
|
|
74
|
+
timeZone?: string;
|
|
75
|
+
}
|
|
76
|
+
interface ObjectDataType extends BaseDataType {
|
|
77
|
+
id: 'object';
|
|
78
|
+
properties?: PropertyMetadataInput[];
|
|
79
|
+
}
|
|
80
|
+
interface ArrayDataType extends BaseDataType {
|
|
81
|
+
id: 'array';
|
|
82
|
+
elementType: DataType;
|
|
83
|
+
}
|
|
84
|
+
interface GeoDataType extends BaseDataType {
|
|
85
|
+
id: 'geo';
|
|
86
|
+
}
|
|
87
|
+
interface PasswordDataType extends BaseDataType {
|
|
88
|
+
id: 'password';
|
|
89
|
+
}
|
|
90
|
+
interface FileDataType extends BaseDataType {
|
|
91
|
+
id: 'file';
|
|
92
|
+
bodyType?: 'url' | 'base64' | 'binary';
|
|
93
|
+
}
|
|
94
|
+
type DataType = StringDataType | IntDataType | LongDataType | FloatDataType | DoubleDataType | BooleanDataType | EnumDataType | DateDataType | ObjectDataType | ArrayDataType | GeoDataType | PasswordDataType | FileDataType;
|
|
95
|
+
/** 属性元数据输入(用于 ObjectDataType.properties,不能自引用完整类型) */
|
|
96
|
+
interface PropertyMetadataInput {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
dataType: DataType;
|
|
100
|
+
description?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 将原始值转换为对应数据类型的 JavaScript 表示 — 对应 jetlinks DataType.convert()
|
|
104
|
+
*/
|
|
105
|
+
declare function convertValue(type: DataType, raw: unknown): unknown;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 物模型元数据 — 对应 jetlinks ThingMetadata / DeviceMetadata
|
|
109
|
+
*
|
|
110
|
+
* 定义一类物(设备)的属性、事件、功能三元素。
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 属性读写权限 — 对应 jetlinks PropertyMetadata.AccessMode
|
|
115
|
+
*/
|
|
116
|
+
declare enum PropertyAccessMode {
|
|
117
|
+
/** 只读 */
|
|
118
|
+
READ = "r",
|
|
119
|
+
/** 只写 */
|
|
120
|
+
WRITE = "w",
|
|
121
|
+
/** 读写 */
|
|
122
|
+
READ_WRITE = "rw"
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 属性元数据 — 对应 jetlinks PropertyMetadata
|
|
126
|
+
*/
|
|
127
|
+
interface PropertyMetadata {
|
|
128
|
+
/** 属性唯一标识 */
|
|
129
|
+
id: string;
|
|
130
|
+
/** 属性名称 */
|
|
131
|
+
name: string;
|
|
132
|
+
/** 数据类型 */
|
|
133
|
+
dataType: DataType;
|
|
134
|
+
/** 读写权限,默认可读写 */
|
|
135
|
+
accessMode?: PropertyAccessMode;
|
|
136
|
+
/** 描述 */
|
|
137
|
+
description?: string;
|
|
138
|
+
/** 存储到时序数据库时的指标名(默认使用 thingType.id) */
|
|
139
|
+
storageMetric?: string;
|
|
140
|
+
/** 是否忽略存储 */
|
|
141
|
+
ignoreStorage?: boolean;
|
|
142
|
+
/** 扩展属性 */
|
|
143
|
+
expands?: Record<string, unknown>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 功能参数 — 对应 jetlinks FunctionMetadata.Parameter / InputOutput
|
|
147
|
+
*/
|
|
148
|
+
interface FunctionParameter {
|
|
149
|
+
id: string;
|
|
150
|
+
name: string;
|
|
151
|
+
dataType: DataType;
|
|
152
|
+
description?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 功能元数据 — 对应 jetlinks FunctionMetadata
|
|
156
|
+
*/
|
|
157
|
+
interface FunctionMetadata {
|
|
158
|
+
id: string;
|
|
159
|
+
name: string;
|
|
160
|
+
/** 输入参数 */
|
|
161
|
+
inputs: FunctionParameter[];
|
|
162
|
+
/** 输出参数(返回值定义) */
|
|
163
|
+
output?: FunctionParameter[];
|
|
164
|
+
/** 是否为异步功能(下行指令,无立即返回值) */
|
|
165
|
+
async?: boolean;
|
|
166
|
+
description?: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 事件级别 — 对应 jetlinks EventMetadata.EventType
|
|
170
|
+
*/
|
|
171
|
+
declare enum EventLevel {
|
|
172
|
+
/** 普通上报 */
|
|
173
|
+
OTHER = "other",
|
|
174
|
+
/** 告警 */
|
|
175
|
+
WARN = "warn",
|
|
176
|
+
/** 故障 */
|
|
177
|
+
ERROR = "error"
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 事件元数据 — 对应 jetlinks EventMetadata
|
|
181
|
+
*/
|
|
182
|
+
interface EventMetadata {
|
|
183
|
+
id: string;
|
|
184
|
+
name: string;
|
|
185
|
+
/** 事件携带的数据结构 */
|
|
186
|
+
valueType: DataType;
|
|
187
|
+
/** 事件级别 */
|
|
188
|
+
level?: EventLevel;
|
|
189
|
+
description?: string;
|
|
190
|
+
/** 是否存储到时序数据库 */
|
|
191
|
+
storeInTimeSeries?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 物模型元数据 — 对应 jetlinks ThingMetadata
|
|
195
|
+
*/
|
|
196
|
+
interface ThingMetadata {
|
|
197
|
+
/** 属性列表 */
|
|
198
|
+
properties: PropertyMetadata[];
|
|
199
|
+
/** 功能列表 */
|
|
200
|
+
functions: FunctionMetadata[];
|
|
201
|
+
/** 事件列表 */
|
|
202
|
+
events: EventMetadata[];
|
|
203
|
+
/** 标签列表(自定义键值对,不参与时序存储) */
|
|
204
|
+
tags?: PropertyMetadata[];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 合并两份 ThingMetadata — 对应 jetlinks SimpleThingMetadata.merge()
|
|
208
|
+
*
|
|
209
|
+
* 后者属性覆盖前者(以 id 为键)。
|
|
210
|
+
*/
|
|
211
|
+
declare function mergeMetadata(base: ThingMetadata, patch: Partial<ThingMetadata>): ThingMetadata;
|
|
212
|
+
/**
|
|
213
|
+
* 工厂:从简单描述创建 ThingMetadata
|
|
214
|
+
*/
|
|
215
|
+
declare function createMetadata(partial?: Partial<ThingMetadata>): ThingMetadata;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 物类型 & 物实例 — 对应 jetlinks ThingType / Thing
|
|
219
|
+
*
|
|
220
|
+
* ThingType = 设备产品(定义一类设备的元数据模板)
|
|
221
|
+
* Thing = 设备实例(具体的一台设备)
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 物类型 — 对应 jetlinks ThingType / ProductInfo
|
|
226
|
+
*/
|
|
227
|
+
interface ThingType {
|
|
228
|
+
/** 类型唯一 ID(如 product ID) */
|
|
229
|
+
id: string;
|
|
230
|
+
/** 名称 */
|
|
231
|
+
name: string;
|
|
232
|
+
/** 物模型元数据 */
|
|
233
|
+
metadata: ThingMetadata;
|
|
234
|
+
/** 协议(protocol ID,用于选择对应的网关解码器) */
|
|
235
|
+
protocol?: string;
|
|
236
|
+
/** 传输方式(对应 network Transport) */
|
|
237
|
+
transport?: string;
|
|
238
|
+
/** 是否启用 */
|
|
239
|
+
enabled?: boolean;
|
|
240
|
+
/** 扩展属性 */
|
|
241
|
+
extra?: Record<string, unknown>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 物状态 — 对应 jetlinks DeviceState
|
|
245
|
+
*/
|
|
246
|
+
declare enum ThingState {
|
|
247
|
+
/** 未激活(从未在线) */
|
|
248
|
+
INACTIVE = "notActive",
|
|
249
|
+
/** 离线 */
|
|
250
|
+
OFFLINE = "offline",
|
|
251
|
+
/** 在线 */
|
|
252
|
+
ONLINE = "online"
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 物实例 — 对应 jetlinks Thing / DeviceInfo
|
|
256
|
+
*/
|
|
257
|
+
interface Thing {
|
|
258
|
+
/** 实例唯一 ID */
|
|
259
|
+
id: string;
|
|
260
|
+
/** 名称 */
|
|
261
|
+
name: string;
|
|
262
|
+
/** 所属物类型 ID */
|
|
263
|
+
thingTypeId: string;
|
|
264
|
+
/** 当前状态 */
|
|
265
|
+
state: ThingState;
|
|
266
|
+
/** 上次在线时间戳 */
|
|
267
|
+
onlineTime?: number;
|
|
268
|
+
/** 上次离线时间戳 */
|
|
269
|
+
offlineTime?: number;
|
|
270
|
+
/** 自定义标签(非时序属性) */
|
|
271
|
+
tags?: Record<string, unknown>;
|
|
272
|
+
/** 实例级元数据覆盖(优先于 ThingType 的 metadata) */
|
|
273
|
+
metadataPatch?: Partial<ThingMetadata>;
|
|
274
|
+
/** 所属父设备 ID(子设备场景) */
|
|
275
|
+
parentId?: string;
|
|
276
|
+
/** 扩展属性 */
|
|
277
|
+
extra?: Record<string, unknown>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 物管理器接口 — 对应 jetlinks ThingManager / DeviceRegistry
|
|
281
|
+
*/
|
|
282
|
+
interface ThingManager {
|
|
283
|
+
/** 获取物类型 */
|
|
284
|
+
getThingType(typeId: string): Promise<ThingType | undefined>;
|
|
285
|
+
/** 注册物类型 */
|
|
286
|
+
registerThingType(type: ThingType): Promise<void>;
|
|
287
|
+
/** 获取物实例 */
|
|
288
|
+
getThing(thingId: string): Promise<Thing | undefined>;
|
|
289
|
+
/** 注册/更新物实例 */
|
|
290
|
+
registerThing(thing: Thing): Promise<void>;
|
|
291
|
+
/** 注销物实例 */
|
|
292
|
+
unregisterThing(thingId: string): Promise<void>;
|
|
293
|
+
/** 更新物状态 */
|
|
294
|
+
updateState(thingId: string, state: ThingState, timestamp?: number): Promise<void>;
|
|
295
|
+
/** 获取物实例的有效元数据(合并 ThingType + 实例覆盖) */
|
|
296
|
+
getEffectiveMetadata(thingId: string): Promise<ThingMetadata | undefined>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare class InMemoryThingManager implements ThingManager {
|
|
300
|
+
private readonly types;
|
|
301
|
+
private readonly things;
|
|
302
|
+
getThingType(typeId: string): Promise<ThingType | undefined>;
|
|
303
|
+
registerThingType(type: ThingType): Promise<void>;
|
|
304
|
+
getThing(thingId: string): Promise<Thing | undefined>;
|
|
305
|
+
registerThing(thing: Thing): Promise<void>;
|
|
306
|
+
unregisterThing(thingId: string): Promise<void>;
|
|
307
|
+
updateState(thingId: string, state: ThingState, timestamp?: number): Promise<void>;
|
|
308
|
+
getEffectiveMetadata(thingId: string): Promise<ThingMetadata | undefined>;
|
|
309
|
+
/** 获取指定类型的所有实例 */
|
|
310
|
+
getThingsByType(typeId: string): Thing[];
|
|
311
|
+
/** 获取所有在线实例数量 */
|
|
312
|
+
countOnline(): number;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* 物消息体系 — 对应 jetlinks ThingMessage / DeviceMessage
|
|
317
|
+
*
|
|
318
|
+
* 所有设备上行/下行消息的类型定义。
|
|
319
|
+
* 设计原则:消息类型通过 messageType 字符串区分,便于序列化和路由。
|
|
320
|
+
*/
|
|
321
|
+
type ThingMessageType = 'ReportProperty' | 'Event' | 'FunctionReply' | 'Register' | 'Unregister' | 'Online' | 'Offline' | 'ReportTags' | 'UpdateMetadata' | 'StateCheck' | 'ReadPropertyReply' | 'ReadProperty' | 'WriteProperty' | 'FunctionInvoke';
|
|
322
|
+
/**
|
|
323
|
+
* 消息基类 — 对应 jetlinks ThingMessage
|
|
324
|
+
*/
|
|
325
|
+
interface ThingMessage {
|
|
326
|
+
/** 消息类型 */
|
|
327
|
+
messageType: ThingMessageType;
|
|
328
|
+
/** 消息 ID,用于请求-响应关联 */
|
|
329
|
+
messageId: string;
|
|
330
|
+
/** 物(设备)ID */
|
|
331
|
+
thingId: string;
|
|
332
|
+
/** 物类型 ID */
|
|
333
|
+
thingType: string;
|
|
334
|
+
/** 时间戳(毫秒) */
|
|
335
|
+
timestamp: number;
|
|
336
|
+
/** 消息头(扩展元数据) */
|
|
337
|
+
headers?: Record<string, unknown>;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* 属性上报 — 对应 jetlinks ReportPropertyMessage
|
|
341
|
+
*/
|
|
342
|
+
interface ReportPropertyMessage extends ThingMessage {
|
|
343
|
+
messageType: 'ReportProperty';
|
|
344
|
+
/** 属性键值对,key 为属性 ID */
|
|
345
|
+
properties: Record<string, unknown>;
|
|
346
|
+
/** 各属性的上报时间(可选,key 与 properties 一致) */
|
|
347
|
+
propertySourceTimes?: Record<string, number>;
|
|
348
|
+
/** 各属性的状态(可选,'success' | 'error' | 'noReport') */
|
|
349
|
+
propertyStates?: Record<string, string>;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* 事件上报 — 对应 jetlinks EventMessage
|
|
353
|
+
*/
|
|
354
|
+
interface EventMessage extends ThingMessage {
|
|
355
|
+
messageType: 'Event';
|
|
356
|
+
/** 事件 ID */
|
|
357
|
+
event: string;
|
|
358
|
+
/** 事件数据 */
|
|
359
|
+
data: unknown;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* 功能调用回复 — 对应 jetlinks FunctionInvokeReplyMessage
|
|
363
|
+
*/
|
|
364
|
+
interface FunctionReplyMessage extends ThingMessage {
|
|
365
|
+
messageType: 'FunctionReply';
|
|
366
|
+
/** 关联的下行消息 ID */
|
|
367
|
+
correlationKey?: string;
|
|
368
|
+
/** 功能 ID */
|
|
369
|
+
functionId: string;
|
|
370
|
+
/** 返回值 */
|
|
371
|
+
output?: unknown;
|
|
372
|
+
/** 是否成功 */
|
|
373
|
+
success: boolean;
|
|
374
|
+
/** 错误信息 */
|
|
375
|
+
errorMessage?: string;
|
|
376
|
+
/** 错误码 */
|
|
377
|
+
errorCode?: string;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* 设备注册 — 对应 jetlinks RegisterMessage
|
|
381
|
+
*/
|
|
382
|
+
interface RegisterMessage extends ThingMessage {
|
|
383
|
+
messageType: 'Register';
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* 设备注销 — 对应 jetlinks UnRegisterMessage
|
|
387
|
+
*/
|
|
388
|
+
interface UnregisterMessage extends ThingMessage {
|
|
389
|
+
messageType: 'Unregister';
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 设备上线 — 对应 jetlinks DeviceOnlineMessage
|
|
393
|
+
*/
|
|
394
|
+
interface OnlineMessage extends ThingMessage {
|
|
395
|
+
messageType: 'Online';
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 设备离线 — 对应 jetlinks DeviceOfflineMessage
|
|
399
|
+
*/
|
|
400
|
+
interface OfflineMessage extends ThingMessage {
|
|
401
|
+
messageType: 'Offline';
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 标签上报 — 对应 jetlinks ReportTagsMessage
|
|
405
|
+
*/
|
|
406
|
+
interface ReportTagsMessage extends ThingMessage {
|
|
407
|
+
messageType: 'ReportTags';
|
|
408
|
+
tags: Record<string, unknown>;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 读属性回复 — 对应 jetlinks ReadPropertyMessageReply
|
|
412
|
+
*/
|
|
413
|
+
interface ReadPropertyReplyMessage extends ThingMessage {
|
|
414
|
+
messageType: 'ReadPropertyReply';
|
|
415
|
+
correlationKey?: string;
|
|
416
|
+
properties: Record<string, unknown>;
|
|
417
|
+
success: boolean;
|
|
418
|
+
errorMessage?: string;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* 读属性指令 — 对应 jetlinks ReadPropertyMessage
|
|
422
|
+
*/
|
|
423
|
+
interface ReadPropertyMessage extends ThingMessage {
|
|
424
|
+
messageType: 'ReadProperty';
|
|
425
|
+
/** 要读取的属性 ID 列表 */
|
|
426
|
+
properties: string[];
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* 写属性指令 — 对应 jetlinks WritePropertyMessage
|
|
430
|
+
*/
|
|
431
|
+
interface WritePropertyMessage extends ThingMessage {
|
|
432
|
+
messageType: 'WriteProperty';
|
|
433
|
+
properties: Record<string, unknown>;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 功能调用指令 — 对应 jetlinks FunctionInvokeMessage
|
|
437
|
+
*/
|
|
438
|
+
interface FunctionInvokeMessage extends ThingMessage {
|
|
439
|
+
messageType: 'FunctionInvoke';
|
|
440
|
+
/** 功能 ID */
|
|
441
|
+
functionId: string;
|
|
442
|
+
/** 输入参数 */
|
|
443
|
+
inputs: Record<string, unknown>;
|
|
444
|
+
/** 是否同步等待回复 */
|
|
445
|
+
sync?: boolean;
|
|
446
|
+
}
|
|
447
|
+
type UpstreamMessage = ReportPropertyMessage | EventMessage | FunctionReplyMessage | RegisterMessage | UnregisterMessage | OnlineMessage | OfflineMessage | ReportTagsMessage | ReadPropertyReplyMessage;
|
|
448
|
+
type DownstreamMessage = ReadPropertyMessage | WritePropertyMessage | FunctionInvokeMessage;
|
|
449
|
+
/**
|
|
450
|
+
* 创建消息 ID — 对应 jetlinks IDGenerator.SNOW_FLAKE_STRING
|
|
451
|
+
*/
|
|
452
|
+
declare function createMessageId(): string;
|
|
453
|
+
/**
|
|
454
|
+
* 创建属性上报消息
|
|
455
|
+
*/
|
|
456
|
+
declare function createReportPropertyMessage(thingId: string, thingType: string, properties: Record<string, unknown>, extra?: Partial<ReportPropertyMessage>): ReportPropertyMessage;
|
|
457
|
+
/**
|
|
458
|
+
* 创建事件消息
|
|
459
|
+
*/
|
|
460
|
+
declare function createEventMessage(thingId: string, thingType: string, event: string, data: unknown): EventMessage;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 属性日志记录
|
|
464
|
+
*/
|
|
465
|
+
interface PropertyLog {
|
|
466
|
+
/** 属性 ID */
|
|
467
|
+
property: string;
|
|
468
|
+
/** 属性值 */
|
|
469
|
+
value: unknown;
|
|
470
|
+
/** 物 ID */
|
|
471
|
+
thingId: string;
|
|
472
|
+
/** 物类型 ID */
|
|
473
|
+
thingType: string;
|
|
474
|
+
/** 时间戳(毫秒) */
|
|
475
|
+
timestamp: number;
|
|
476
|
+
/** 上报状态 */
|
|
477
|
+
state?: string;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* 事件日志记录
|
|
481
|
+
*/
|
|
482
|
+
interface EventLog {
|
|
483
|
+
/** 事件 ID */
|
|
484
|
+
event: string;
|
|
485
|
+
/** 事件数据(JSON 序列化后存储) */
|
|
486
|
+
data: unknown;
|
|
487
|
+
/** 物 ID */
|
|
488
|
+
thingId: string;
|
|
489
|
+
/** 物类型 ID */
|
|
490
|
+
thingType: string;
|
|
491
|
+
/** 时间戳(毫秒) */
|
|
492
|
+
timestamp: number;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* 属性/事件日志查询条件
|
|
496
|
+
*/
|
|
497
|
+
interface ThingLogQuery {
|
|
498
|
+
thingId: string;
|
|
499
|
+
thingType: string;
|
|
500
|
+
/** 属性 ID 或 事件 ID */
|
|
501
|
+
id: string;
|
|
502
|
+
from: number;
|
|
503
|
+
to: number;
|
|
504
|
+
limit?: number;
|
|
505
|
+
order?: 'asc' | 'desc';
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* 物数据服务接口 — 对应 jetlinks ThingsDataService
|
|
509
|
+
*/
|
|
510
|
+
interface ThingsDataService {
|
|
511
|
+
/**
|
|
512
|
+
* 保存属性上报
|
|
513
|
+
* 对应 jetlinks ThingsDataService.save(DeviceMessage)
|
|
514
|
+
*/
|
|
515
|
+
saveProperties(message: ReportPropertyMessage): Promise<void>;
|
|
516
|
+
/**
|
|
517
|
+
* 保存事件
|
|
518
|
+
*/
|
|
519
|
+
saveEvent(message: EventMessage): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* 查询属性历史
|
|
522
|
+
*/
|
|
523
|
+
queryPropertyLogs(query: ThingLogQuery): Promise<PropertyLog[]>;
|
|
524
|
+
/**
|
|
525
|
+
* 查询事件历史
|
|
526
|
+
*/
|
|
527
|
+
queryEventLogs(query: ThingLogQuery): Promise<EventLog[]>;
|
|
528
|
+
/**
|
|
529
|
+
* 聚合查询属性数据
|
|
530
|
+
*/
|
|
531
|
+
aggregateProperties(thingId: string, thingType: string, property: string, aggQuery: Omit<AggregationQuery, 'metric'>): Promise<AggregationResult[]>;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 基于 TimeSeriesService 的默认实现
|
|
535
|
+
*
|
|
536
|
+
* 指标命名约定:
|
|
537
|
+
* 属性:`thing_property_{thingType}`
|
|
538
|
+
* 事件:`thing_event_{thingType}_{eventId}`
|
|
539
|
+
*/
|
|
540
|
+
declare class DefaultThingsDataService implements ThingsDataService {
|
|
541
|
+
private readonly tsService;
|
|
542
|
+
constructor(tsService: TimeSeriesService);
|
|
543
|
+
private propertyMetric;
|
|
544
|
+
private eventMetric;
|
|
545
|
+
saveProperties(message: ReportPropertyMessage): Promise<void>;
|
|
546
|
+
saveEvent(message: EventMessage): Promise<void>;
|
|
547
|
+
queryPropertyLogs(query: ThingLogQuery): Promise<PropertyLog[]>;
|
|
548
|
+
queryEventLogs(query: ThingLogQuery): Promise<EventLog[]>;
|
|
549
|
+
aggregateProperties(thingId: string, thingType: string, property: string, aggQuery: Omit<AggregationQuery, 'metric'>): Promise<AggregationResult[]>;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* ThingsModule — 物模型 NestJS 模块
|
|
554
|
+
*
|
|
555
|
+
* 默认使用内存实现。生产环境可覆盖 ThingManager 提供者。
|
|
556
|
+
*/
|
|
557
|
+
declare class ThingsModule {
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export { type ArrayDataType, type BooleanDataType, type DataType, type DataTypeId, type DateDataType, DefaultThingsDataService, type DoubleDataType, type DownstreamMessage, type EnumDataType, type EnumElement, EventLevel, type EventLog, type EventMessage, type EventMetadata, type FileDataType, type FloatDataType, type FunctionInvokeMessage, type FunctionMetadata, type FunctionParameter, type FunctionReplyMessage, type GeoDataType, type GeoPoint, InMemoryThingManager, type IntDataType, type LongDataType, type ObjectDataType, type OfflineMessage, type OnlineMessage, type PasswordDataType, PropertyAccessMode, type PropertyLog, type PropertyMetadata, type PropertyMetadataInput, type ReadPropertyMessage, type ReadPropertyReplyMessage, type RegisterMessage, type ReportPropertyMessage, type ReportTagsMessage, type StringDataType, type Thing, type ThingLogQuery, type ThingManager, type ThingMessage, type ThingMessageType, type ThingMetadata, ThingState, type ThingType, type ThingsDataService, ThingsModule, type UnregisterMessage, type UpstreamMessage, type WritePropertyMessage, convertValue, createEventMessage, createMessageId, createMetadata, createReportPropertyMessage, mergeMetadata };
|