@thejrsoft/subway-protocol 1.3.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/ACK_MESSAGES_IMPLEMENTATION_SUMMARY.md +128 -0
- package/ACK_MESSAGE_DESIGN.md +457 -0
- package/CHANGELOG.md +58 -0
- package/COMMAND_VALIDATION_RULES.md +178 -0
- package/DOCUMENTATION_REORGANIZATION_SUMMARY.md +81 -0
- package/DOCUMENTATION_STRUCTURE.md +106 -0
- package/GATEWAY_MIGRATION_GUIDE.md +130 -0
- package/GATEWAY_PROTOCOL_COMPARISON.md +216 -0
- package/INTEGRATION_GUIDE.md +190 -0
- package/OPTIONAL_FIELDS_WITHOUT_DEFAULTS.md +97 -0
- package/PROTOCOL_UTILS_USAGE.md +278 -0
- package/README.md +237 -0
- package/TYPE_FIXES_SUMMARY.md +210 -0
- package/UPDATE_ENUM_VALUES.md +139 -0
- package/dist/asyncapi-sync.d.ts +47 -0
- package/dist/asyncapi-sync.d.ts.map +1 -0
- package/dist/asyncapi-sync.js +85 -0
- package/dist/asyncapi-sync.js.map +1 -0
- package/dist/command-factory.d.ts +62 -0
- package/dist/command-factory.d.ts.map +1 -0
- package/dist/command-factory.js +137 -0
- package/dist/command-factory.js.map +1 -0
- package/dist/command-types.d.ts +27 -0
- package/dist/command-types.d.ts.map +1 -0
- package/dist/command-types.js +31 -0
- package/dist/command-types.js.map +1 -0
- package/dist/index.d.ts +403 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +413 -0
- package/dist/index.js.map +1 -0
- package/dist/message-validator.d.ts +102 -0
- package/dist/message-validator.d.ts.map +1 -0
- package/dist/message-validator.js +640 -0
- package/dist/message-validator.js.map +1 -0
- package/dist/protocol-utils.d.ts +108 -0
- package/dist/protocol-utils.d.ts.map +1 -0
- package/dist/protocol-utils.js +293 -0
- package/dist/protocol-utils.js.map +1 -0
- package/docs/01-protocol/README.md +45 -0
- package/docs/01-protocol/design-rationale.md +198 -0
- package/docs/01-protocol/message-types.md +669 -0
- package/docs/01-protocol/specification.md +1466 -0
- package/docs/02-commands/README.md +56 -0
- package/docs/02-commands/batch-command.md +435 -0
- package/docs/02-commands/complex-command.md +537 -0
- package/docs/02-commands/simple-command.md +332 -0
- package/docs/02-commands/typed-commands.md +362 -0
- package/docs/03-architecture/README.md +66 -0
- package/docs/03-architecture/device-protocol.md +430 -0
- package/docs/03-architecture/edge-proxy.md +727 -0
- package/docs/03-architecture/routing-flow.md +893 -0
- package/docs/04-integration/README.md +144 -0
- package/docs/04-integration/backend-guide.md +551 -0
- package/docs/04-integration/edge-guide.md +684 -0
- package/docs/04-integration/gateway-guide.md +180 -0
- package/docs/04-integration/migration-guide.md +226 -0
- package/docs/05-examples/README.md +141 -0
- package/docs/05-examples/progress-update-examples.md +757 -0
- package/docs/06-reference/README.md +67 -0
- package/docs/06-reference/api.md +572 -0
- package/docs/06-reference/faq.md +302 -0
- package/docs/06-reference/glossary.md +232 -0
- package/examples/backend-upgrade.ts +279 -0
- package/examples/edge-multi-device.ts +513 -0
- package/examples/gateway-upgrade.ts +150 -0
- package/examples/protocol-implementation.ts +715 -0
- package/package.json +48 -0
- package/scripts/validate-asyncapi.ts +78 -0
- package/src/__tests__/protocol.test.ts +297 -0
- package/src/asyncapi-sync.ts +84 -0
- package/src/command-factory.ts +183 -0
- package/src/command-types.ts +72 -0
- package/src/edge-proxy.ts +494 -0
- package/src/gateway-extensions.ts +278 -0
- package/src/index.ts +792 -0
- package/src/message-validator.ts +726 -0
- package/src/protocol-utils.ts +355 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# 类型定义修复总结
|
|
2
|
+
|
|
3
|
+
## 修复的类型定义
|
|
4
|
+
|
|
5
|
+
### 1. Command 接口层次结构 ✅
|
|
6
|
+
|
|
7
|
+
创建了更清晰的命令接口层次结构:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// 基础命令接口
|
|
11
|
+
export interface BaseCommand {
|
|
12
|
+
commandType?: CommandType; // 命令类型(默认为 SIMPLE)
|
|
13
|
+
commandCode: string;
|
|
14
|
+
parameters?: Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 简单命令接口(SIMPLE 和 BATCH)
|
|
18
|
+
export interface SimpleCommand extends BaseCommand {
|
|
19
|
+
commandType?: CommandType.SIMPLE | CommandType.BATCH;
|
|
20
|
+
deviceId: number | number[] | string; // 必需:支持批量
|
|
21
|
+
deviceType: string; // 必需
|
|
22
|
+
operationType: OperationType; // 必需
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 复杂命令接口(COMPLEX)
|
|
26
|
+
export interface ComplexCommand extends BaseCommand {
|
|
27
|
+
commandType: CommandType.COMPLEX;
|
|
28
|
+
deviceId?: number | number[] | string; // 可选
|
|
29
|
+
deviceType?: string; // 可选
|
|
30
|
+
operationType?: OperationType; // 可选
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 通用命令接口(向后兼容)
|
|
34
|
+
export interface GenericCommand {
|
|
35
|
+
commandType?: CommandType;
|
|
36
|
+
commandCode: string;
|
|
37
|
+
deviceId?: number | number[] | string;
|
|
38
|
+
deviceType?: string;
|
|
39
|
+
operationType?: OperationType;
|
|
40
|
+
parameters?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 命令联合类型
|
|
44
|
+
export type Command = SpecificCommand | SimpleCommand | ComplexCommand | GenericCommand;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**关键改进**:
|
|
48
|
+
- 为不同命令类型创建了专门的接口
|
|
49
|
+
- SIMPLE/BATCH 命令必需 deviceId、deviceType 和 operationType
|
|
50
|
+
- COMPLEX 命令这些字段是可选的
|
|
51
|
+
- 支持批量操作:`deviceId: number | number[] | string`
|
|
52
|
+
|
|
53
|
+
### 2. ProgressUpdateMessage 接口 ✅
|
|
54
|
+
|
|
55
|
+
当前定义已包含所有必需字段:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
export interface ProgressUpdateMessage extends BaseMessage {
|
|
59
|
+
type: MessageType.PROGRESS_UPDATE;
|
|
60
|
+
requestRef: string;
|
|
61
|
+
status: ProgressStatus; // 状态
|
|
62
|
+
phase: ProgressPhase | string; // 当前阶段
|
|
63
|
+
progress: number; // 0-100 进度百分比
|
|
64
|
+
sourceType: 'COMMAND' | 'SYSTEM'; // 必需字段
|
|
65
|
+
context?: ProgramContext; // 程序上下文
|
|
66
|
+
command?: DeviceOperationRecord; // 设备操作记录
|
|
67
|
+
report?: ReportMessage; // 包含 level、message、code、data
|
|
68
|
+
timestamp: string;
|
|
69
|
+
version: string;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**ReportMessage 结构**:
|
|
74
|
+
```typescript
|
|
75
|
+
export interface ReportMessage {
|
|
76
|
+
level: ReportLevel;
|
|
77
|
+
message: string;
|
|
78
|
+
code?: string;
|
|
79
|
+
data?: Record<string, any>;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. 枚举定义 ✅
|
|
84
|
+
|
|
85
|
+
所有必需的枚举都已正确定义和导出:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// 命令类型
|
|
89
|
+
export enum CommandType {
|
|
90
|
+
SIMPLE = 'SIMPLE', // 点对点命令
|
|
91
|
+
BATCH = 'BATCH', // 多设备命令
|
|
92
|
+
COMPLEX = 'COMPLEX' // 持续响应命令
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 操作类型
|
|
96
|
+
export enum OperationType {
|
|
97
|
+
READ = 'READ',
|
|
98
|
+
WRITE = 'WRITE'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 进度状态
|
|
102
|
+
export enum ProgressStatus {
|
|
103
|
+
PENDING = 'PENDING',
|
|
104
|
+
IN_PROGRESS = 'IN_PROGRESS',
|
|
105
|
+
PAUSED = 'PAUSED',
|
|
106
|
+
COMPLETED = 'COMPLETED',
|
|
107
|
+
FAILED = 'FAILED',
|
|
108
|
+
CANCELLED = 'CANCELLED'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 报告级别
|
|
112
|
+
export enum ReportLevel {
|
|
113
|
+
DEBUG = 'DEBUG',
|
|
114
|
+
INFO = 'INFO',
|
|
115
|
+
WARNING = 'WARNING',
|
|
116
|
+
ERROR = 'ERROR',
|
|
117
|
+
CRITICAL = 'CRITICAL'
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 使用示例
|
|
122
|
+
|
|
123
|
+
### 创建简单命令
|
|
124
|
+
```typescript
|
|
125
|
+
const simpleCommand: SimpleCommand = {
|
|
126
|
+
commandType: CommandType.SIMPLE,
|
|
127
|
+
commandCode: 'LedSwitch',
|
|
128
|
+
deviceId: 123,
|
|
129
|
+
deviceType: 'pillar',
|
|
130
|
+
operationType: OperationType.WRITE,
|
|
131
|
+
parameters: { switch: 'ON' }
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 创建批量命令
|
|
136
|
+
```typescript
|
|
137
|
+
const batchCommand: SimpleCommand = {
|
|
138
|
+
commandType: CommandType.BATCH,
|
|
139
|
+
commandCode: 'LedSwitch',
|
|
140
|
+
deviceId: [123, 124, 125], // 多设备数组
|
|
141
|
+
deviceType: 'pillar',
|
|
142
|
+
operationType: OperationType.WRITE,
|
|
143
|
+
parameters: { switch: 'OFF' }
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 创建复杂命令
|
|
148
|
+
```typescript
|
|
149
|
+
const complexCommand: ComplexCommand = {
|
|
150
|
+
commandType: CommandType.COMPLEX,
|
|
151
|
+
commandCode: 'SystemDiagnostics',
|
|
152
|
+
// deviceId、deviceType、operationType 都是可选的
|
|
153
|
+
parameters: {
|
|
154
|
+
diagnosticLevel: 'full',
|
|
155
|
+
includeHistory: true
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 创建进度更新
|
|
161
|
+
```typescript
|
|
162
|
+
const progressUpdate: ProgressUpdateMessage = {
|
|
163
|
+
type: MessageType.PROGRESS_UPDATE,
|
|
164
|
+
requestRef: 'req-123',
|
|
165
|
+
status: ProgressStatus.IN_PROGRESS,
|
|
166
|
+
phase: ProgressPhase.DOWNLOAD,
|
|
167
|
+
progress: 45,
|
|
168
|
+
sourceType: 'COMMAND',
|
|
169
|
+
command: {
|
|
170
|
+
commandType: CommandType.SIMPLE,
|
|
171
|
+
commandCode: 'LedSwitch',
|
|
172
|
+
deviceType: 'pillar',
|
|
173
|
+
deviceId: 123,
|
|
174
|
+
operationType: OperationType.WRITE,
|
|
175
|
+
result: { success: true }
|
|
176
|
+
},
|
|
177
|
+
report: {
|
|
178
|
+
level: ReportLevel.INFO,
|
|
179
|
+
message: 'Download in progress',
|
|
180
|
+
code: 'DOWNLOAD_PROGRESS',
|
|
181
|
+
data: { bytesDownloaded: 1024000 }
|
|
182
|
+
},
|
|
183
|
+
timestamp: new Date().toISOString(),
|
|
184
|
+
version: '1.0'
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 验证器支持
|
|
189
|
+
|
|
190
|
+
MessageValidator 已更新以支持这些类型定义:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// 验证命令消息
|
|
194
|
+
const result = MessageValidator.validateCommandMessage(commandMessage);
|
|
195
|
+
if (!result.valid) {
|
|
196
|
+
console.error('Validation errors:', result.errors);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 验证进度更新
|
|
200
|
+
const progressResult = MessageValidator.validateProgressUpdate(progressUpdate);
|
|
201
|
+
if (!progressResult.valid) {
|
|
202
|
+
console.error('Validation errors:', progressResult.errors);
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 向后兼容性
|
|
207
|
+
|
|
208
|
+
- GenericCommand 接口保持向后兼容
|
|
209
|
+
- 现有代码可以继续使用,但建议迁移到新的类型定义
|
|
210
|
+
- 验证器会根据 commandType 自动应用正确的验证规则
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# 枚举值更新映射表
|
|
2
|
+
|
|
3
|
+
## 需要更新的枚举值
|
|
4
|
+
|
|
5
|
+
### MessageType
|
|
6
|
+
- `"register"` → `"REGISTER"`
|
|
7
|
+
- `"register_ack"` → `"REGISTER_ACK"`
|
|
8
|
+
- `"unregister"` → `"UNREGISTER"`
|
|
9
|
+
- `"unregister_ack"` → `"UNREGISTER_ACK"`
|
|
10
|
+
- `"heartbeat"` → `"HEARTBEAT"`
|
|
11
|
+
- `"heartbeat_ack"` → `"HEARTBEAT_ACK"`
|
|
12
|
+
- `"command"` → `"COMMAND"`
|
|
13
|
+
- `"command_response"` → `"COMMAND_RESPONSE"`
|
|
14
|
+
- `"program"` → `"PROGRAM"`
|
|
15
|
+
- `"program_response"` → `"PROGRAM_RESPONSE"`
|
|
16
|
+
- `"progress_update"` → `"PROGRESS_UPDATE"`
|
|
17
|
+
- `"error"` → `"ERROR"`
|
|
18
|
+
|
|
19
|
+
### ClientType
|
|
20
|
+
- `"device"` → `"DEVICE"`
|
|
21
|
+
- `"backend"` → `"BACKEND"`
|
|
22
|
+
- `"edge"` → `"EDGE"`
|
|
23
|
+
- `"gateway"` → `"GATEWAY"`
|
|
24
|
+
|
|
25
|
+
### OperationType
|
|
26
|
+
- `"read"` → `"READ"`
|
|
27
|
+
- `"write"` → `"WRITE"`
|
|
28
|
+
|
|
29
|
+
### Priority
|
|
30
|
+
- `"low"` → `"LOW"`
|
|
31
|
+
- `"normal"` → `"NORMAL"`
|
|
32
|
+
- `"high"` → `"HIGH"`
|
|
33
|
+
- `"critical"` → `"CRITICAL"`
|
|
34
|
+
|
|
35
|
+
### CommandStatus
|
|
36
|
+
- `"completed"` → `"COMPLETED"`
|
|
37
|
+
- `"failed"` → `"FAILED"`
|
|
38
|
+
- `"timeout"` → `"TIMEOUT"`
|
|
39
|
+
- `"cancelled"` → `"CANCELLED"`
|
|
40
|
+
- `"in_progress"` → `"IN_PROGRESS"`
|
|
41
|
+
|
|
42
|
+
### CommandType
|
|
43
|
+
- `"simple"` → `"SIMPLE"`
|
|
44
|
+
- `"batch"` → `"BATCH"`
|
|
45
|
+
- `"complex"` → `"COMPLEX"`
|
|
46
|
+
|
|
47
|
+
### ProgramType
|
|
48
|
+
- `"dynamic"` → `"DYNAMIC"`
|
|
49
|
+
- `"static"` → `"STATIC"`
|
|
50
|
+
|
|
51
|
+
### ProgramDirection
|
|
52
|
+
- `"left_to_right"` → `"LEFT_TO_RIGHT"`
|
|
53
|
+
- `"right_to_left"` → `"RIGHT_TO_LEFT"`
|
|
54
|
+
|
|
55
|
+
### ProgressPhase
|
|
56
|
+
- `"downloading"` → `"DOWNLOADING"`
|
|
57
|
+
- `"decompressing"` → `"DECOMPRESSING"`
|
|
58
|
+
- `"preprocessing"` → `"PREPROCESSING"`
|
|
59
|
+
- `"createFrames"` → `"CREATE_FRAMES"`
|
|
60
|
+
- `"uploading"` → `"UPLOADING"`
|
|
61
|
+
- `"statistics"` → `"STATISTICS"`
|
|
62
|
+
|
|
63
|
+
### ProgressStatus
|
|
64
|
+
- `"pending"` → `"PENDING"`
|
|
65
|
+
- `"in_progress"` → `"IN_PROGRESS"`
|
|
66
|
+
- `"paused"` → `"PAUSED"`
|
|
67
|
+
- `"completed"` → `"COMPLETED"`
|
|
68
|
+
- `"failed"` → `"FAILED"`
|
|
69
|
+
- `"cancelled"` → `"CANCELLED"`
|
|
70
|
+
|
|
71
|
+
### ReportLevel
|
|
72
|
+
- `"debug"` → `"DEBUG"`
|
|
73
|
+
- `"info"` → `"INFO"`
|
|
74
|
+
- `"warning"` → `"WARNING"`
|
|
75
|
+
- `"error"` → `"ERROR"`
|
|
76
|
+
- `"critical"` → `"CRITICAL"`
|
|
77
|
+
|
|
78
|
+
### 其他
|
|
79
|
+
- `"command"` (sourceType) → `"COMMAND"`
|
|
80
|
+
- `"system"` (sourceType) → `"SYSTEM"`
|
|
81
|
+
- `"sha256"` → `"SHA256"`
|
|
82
|
+
|
|
83
|
+
## 更新脚本
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 批量替换文档中的枚举值
|
|
87
|
+
find docs -name "*.md" -type f -exec sed -i '' \
|
|
88
|
+
-e 's/"type": "register"/"type": "REGISTER"/g' \
|
|
89
|
+
-e 's/"type": "register_ack"/"type": "REGISTER_ACK"/g' \
|
|
90
|
+
-e 's/"type": "unregister"/"type": "UNREGISTER"/g' \
|
|
91
|
+
-e 's/"type": "unregister_ack"/"type": "UNREGISTER_ACK"/g' \
|
|
92
|
+
-e 's/"type": "heartbeat"/"type": "HEARTBEAT"/g' \
|
|
93
|
+
-e 's/"type": "heartbeat_ack"/"type": "HEARTBEAT_ACK"/g' \
|
|
94
|
+
-e 's/"type": "command"/"type": "COMMAND"/g' \
|
|
95
|
+
-e 's/"type": "command_response"/"type": "COMMAND_RESPONSE"/g' \
|
|
96
|
+
-e 's/"type": "program"/"type": "PROGRAM"/g' \
|
|
97
|
+
-e 's/"type": "program_response"/"type": "PROGRAM_RESPONSE"/g' \
|
|
98
|
+
-e 's/"type": "progress_update"/"type": "PROGRESS_UPDATE"/g' \
|
|
99
|
+
-e 's/"type": "error"/"type": "ERROR"/g' \
|
|
100
|
+
-e 's/"clientType": "device"/"clientType": "DEVICE"/g' \
|
|
101
|
+
-e 's/"clientType": "backend"/"clientType": "BACKEND"/g' \
|
|
102
|
+
-e 's/"clientType": "edge"/"clientType": "EDGE"/g' \
|
|
103
|
+
-e 's/"clientType": "gateway"/"clientType": "GATEWAY"/g' \
|
|
104
|
+
-e 's/"operationType": "read"/"operationType": "READ"/g' \
|
|
105
|
+
-e 's/"operationType": "write"/"operationType": "WRITE"/g' \
|
|
106
|
+
-e 's/"priority": "low"/"priority": "LOW"/g' \
|
|
107
|
+
-e 's/"priority": "normal"/"priority": "NORMAL"/g' \
|
|
108
|
+
-e 's/"priority": "high"/"priority": "HIGH"/g' \
|
|
109
|
+
-e 's/"priority": "critical"/"priority": "CRITICAL"/g' \
|
|
110
|
+
-e 's/"status": "completed"/"status": "COMPLETED"/g' \
|
|
111
|
+
-e 's/"status": "failed"/"status": "FAILED"/g' \
|
|
112
|
+
-e 's/"status": "timeout"/"status": "TIMEOUT"/g' \
|
|
113
|
+
-e 's/"status": "cancelled"/"status": "CANCELLED"/g' \
|
|
114
|
+
-e 's/"status": "in_progress"/"status": "IN_PROGRESS"/g' \
|
|
115
|
+
-e 's/"commandType": "simple"/"commandType": "SIMPLE"/g' \
|
|
116
|
+
-e 's/"commandType": "batch"/"commandType": "BATCH"/g' \
|
|
117
|
+
-e 's/"commandType": "complex"/"commandType": "COMPLEX"/g' \
|
|
118
|
+
-e 's/"programType": "dynamic"/"programType": "DYNAMIC"/g' \
|
|
119
|
+
-e 's/"programType": "static"/"programType": "STATIC"/g' \
|
|
120
|
+
-e 's/"direction": "left_to_right"/"direction": "LEFT_TO_RIGHT"/g' \
|
|
121
|
+
-e 's/"direction": "right_to_left"/"direction": "RIGHT_TO_LEFT"/g' \
|
|
122
|
+
-e 's/"phase": "downloading"/"phase": "DOWNLOADING"/g' \
|
|
123
|
+
-e 's/"phase": "decompressing"/"phase": "DECOMPRESSING"/g' \
|
|
124
|
+
-e 's/"phase": "preprocessing"/"phase": "PREPROCESSING"/g' \
|
|
125
|
+
-e 's/"phase": "createFrames"/"phase": "CREATE_FRAMES"/g' \
|
|
126
|
+
-e 's/"phase": "uploading"/"phase": "UPLOADING"/g' \
|
|
127
|
+
-e 's/"phase": "statistics"/"phase": "STATISTICS"/g' \
|
|
128
|
+
-e 's/"status": "pending"/"status": "PENDING"/g' \
|
|
129
|
+
-e 's/"status": "paused"/"status": "PAUSED"/g' \
|
|
130
|
+
-e 's/"level": "debug"/"level": "DEBUG"/g' \
|
|
131
|
+
-e 's/"level": "info"/"level": "INFO"/g' \
|
|
132
|
+
-e 's/"level": "warning"/"level": "WARNING"/g' \
|
|
133
|
+
-e 's/"level": "error"/"level": "ERROR"/g' \
|
|
134
|
+
-e 's/"level": "critical"/"level": "CRITICAL"/g' \
|
|
135
|
+
-e 's/"sourceType": "command"/"sourceType": "COMMAND"/g' \
|
|
136
|
+
-e 's/"sourceType": "system"/"sourceType": "SYSTEM"/g' \
|
|
137
|
+
-e 's/"hashAlgorithm": "sha256"/"hashAlgorithm": "SHA256"/g' \
|
|
138
|
+
{} \;
|
|
139
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保持 TypeScript 实现与 AsyncAPI 文档同步的工具
|
|
3
|
+
*/
|
|
4
|
+
import { MessageType, ClientType, OperationType, Priority } from './index';
|
|
5
|
+
/**
|
|
6
|
+
* 生成 AsyncAPI 的枚举定义
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateAsyncApiEnums(): string;
|
|
9
|
+
/**
|
|
10
|
+
* 生成消息示例用于 AsyncAPI 文档
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateMessageExamples(): {
|
|
13
|
+
register_simple: {
|
|
14
|
+
type: string;
|
|
15
|
+
clientId: string;
|
|
16
|
+
};
|
|
17
|
+
register_full: {
|
|
18
|
+
type: MessageType;
|
|
19
|
+
clientId: string;
|
|
20
|
+
clientType: ClientType;
|
|
21
|
+
clientInfo: {
|
|
22
|
+
version: string;
|
|
23
|
+
platform: string;
|
|
24
|
+
capabilities: string[];
|
|
25
|
+
};
|
|
26
|
+
timestamp: string;
|
|
27
|
+
version: string;
|
|
28
|
+
};
|
|
29
|
+
command: {
|
|
30
|
+
type: MessageType;
|
|
31
|
+
requestRef: string;
|
|
32
|
+
clientId: string;
|
|
33
|
+
command: {
|
|
34
|
+
commandCode: string;
|
|
35
|
+
deviceType: string;
|
|
36
|
+
operationType: OperationType;
|
|
37
|
+
parameters: {
|
|
38
|
+
register: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
priority: Priority;
|
|
42
|
+
timeout: number;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
version: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=asyncapi-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncapi-sync.d.ts","sourceRoot":"","sources":["../src/asyncapi-sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAiB,MAAM,SAAS,CAAC;AAE1F;;GAEG;AACH,wBAAgB,qBAAqB,WAmCpC;AAED;;GAEG;AACH,wBAAgB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCtC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 保持 TypeScript 实现与 AsyncAPI 文档同步的工具
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateAsyncApiEnums = generateAsyncApiEnums;
|
|
7
|
+
exports.generateMessageExamples = generateMessageExamples;
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
/**
|
|
10
|
+
* 生成 AsyncAPI 的枚举定义
|
|
11
|
+
*/
|
|
12
|
+
function generateAsyncApiEnums() {
|
|
13
|
+
const enums = {
|
|
14
|
+
MessageType: Object.values(index_1.MessageType),
|
|
15
|
+
ClientType: Object.values(index_1.ClientType),
|
|
16
|
+
OperationType: Object.values(index_1.OperationType),
|
|
17
|
+
Priority: Object.values(index_1.Priority),
|
|
18
|
+
CommandStatus: Object.values(index_1.CommandStatus)
|
|
19
|
+
};
|
|
20
|
+
return `
|
|
21
|
+
# AsyncAPI Enum Definitions
|
|
22
|
+
# Generated from TypeScript implementation
|
|
23
|
+
|
|
24
|
+
components:
|
|
25
|
+
schemas:
|
|
26
|
+
MessageType:
|
|
27
|
+
type: string
|
|
28
|
+
enum: ${JSON.stringify(enums.MessageType)}
|
|
29
|
+
|
|
30
|
+
ClientType:
|
|
31
|
+
type: string
|
|
32
|
+
enum: ${JSON.stringify(enums.ClientType)}
|
|
33
|
+
|
|
34
|
+
OperationType:
|
|
35
|
+
type: string
|
|
36
|
+
enum: ${JSON.stringify(enums.OperationType)}
|
|
37
|
+
|
|
38
|
+
Priority:
|
|
39
|
+
type: string
|
|
40
|
+
enum: ${JSON.stringify(enums.Priority)}
|
|
41
|
+
|
|
42
|
+
CommandStatus:
|
|
43
|
+
type: string
|
|
44
|
+
enum: ${JSON.stringify(enums.CommandStatus)}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 生成消息示例用于 AsyncAPI 文档
|
|
49
|
+
*/
|
|
50
|
+
function generateMessageExamples() {
|
|
51
|
+
return {
|
|
52
|
+
register_simple: {
|
|
53
|
+
type: 'register',
|
|
54
|
+
clientId: 'device001'
|
|
55
|
+
},
|
|
56
|
+
register_full: {
|
|
57
|
+
type: index_1.MessageType.REGISTER,
|
|
58
|
+
clientId: 'backend-server',
|
|
59
|
+
clientType: index_1.ClientType.BACKEND,
|
|
60
|
+
clientInfo: {
|
|
61
|
+
version: '1.0.0',
|
|
62
|
+
platform: 'nodejs',
|
|
63
|
+
capabilities: ['command', 'program']
|
|
64
|
+
},
|
|
65
|
+
timestamp: new Date().toISOString(),
|
|
66
|
+
version: '2.0'
|
|
67
|
+
},
|
|
68
|
+
command: {
|
|
69
|
+
type: index_1.MessageType.COMMAND,
|
|
70
|
+
requestRef: 'req-123',
|
|
71
|
+
clientId: 'device001',
|
|
72
|
+
command: {
|
|
73
|
+
commandCode: 'READ_STATUS',
|
|
74
|
+
deviceType: 'controller',
|
|
75
|
+
operationType: index_1.OperationType.READ,
|
|
76
|
+
parameters: { register: 'R001' }
|
|
77
|
+
},
|
|
78
|
+
priority: index_1.Priority.HIGH,
|
|
79
|
+
timeout: 10000,
|
|
80
|
+
timestamp: new Date().toISOString(),
|
|
81
|
+
version: '2.0'
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=asyncapi-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncapi-sync.js","sourceRoot":"","sources":["../src/asyncapi-sync.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAOH,sDAmCC;AAKD,0DAkCC;AA/ED,mCAA0F;AAE1F;;GAEG;AACH,SAAgB,qBAAqB;IACnC,MAAM,KAAK,GAAG;QACZ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAW,CAAC;QACvC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAU,CAAC;QACrC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,qBAAa,CAAC;QAC3C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAQ,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,qBAAa,CAAC;KAC5C,CAAC;IAEF,OAAO;;;;;;;;cAQK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC;;;;cAIjC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;;;;cAIhC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC;;;;cAInC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;;;;cAI9B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC;GAC9C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB;IACrC,OAAO;QACL,eAAe,EAAE;YACf,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,WAAW;SACtB;QACD,aAAa,EAAE;YACb,IAAI,EAAE,mBAAW,CAAC,QAAQ;YAC1B,QAAQ,EAAE,gBAAgB;YAC1B,UAAU,EAAE,kBAAU,CAAC,OAAO;YAC9B,UAAU,EAAE;gBACV,OAAO,EAAE,OAAO;gBAChB,QAAQ,EAAE,QAAQ;gBAClB,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC;aACrC;YACD,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,KAAK;SACf;QACD,OAAO,EAAE;YACP,IAAI,EAAE,mBAAW,CAAC,OAAO;YACzB,UAAU,EAAE,SAAS;YACrB,QAAQ,EAAE,WAAW;YACrB,OAAO,EAAE;gBACP,WAAW,EAAE,aAAa;gBAC1B,UAAU,EAAE,YAAY;gBACxB,aAAa,EAAE,qBAAa,CAAC,IAAI;gBACjC,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE;aACjC;YACD,QAAQ,EAAE,gBAAQ,CAAC,IAAI;YACvB,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,KAAK;SACf;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 强类型命令工厂
|
|
3
|
+
*
|
|
4
|
+
* 提供类型安全的命令创建和验证功能
|
|
5
|
+
*/
|
|
6
|
+
import type { CommandTypeMap, SpecificCommand } from './command-types';
|
|
7
|
+
import type { CommandMessage, Priority } from './index';
|
|
8
|
+
import { OperationType } from './index';
|
|
9
|
+
/**
|
|
10
|
+
* 强类型命令消息工厂
|
|
11
|
+
*/
|
|
12
|
+
export declare class TypedCommandFactory {
|
|
13
|
+
/**
|
|
14
|
+
* 创建强类型命令消息
|
|
15
|
+
*/
|
|
16
|
+
static createTypedCommandMessage<T extends keyof CommandTypeMap>(requestRef: string, targetClientId: string, commandCode: T, commandProps: Omit<CommandTypeMap[T], 'commandCode'>, options?: {
|
|
17
|
+
priority?: Priority;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
callback?: string;
|
|
20
|
+
}): CommandMessage;
|
|
21
|
+
/**
|
|
22
|
+
* 示例:创建命令的工厂方法
|
|
23
|
+
*
|
|
24
|
+
* 实际使用时,应该为每个从 C# 生成的命令创建对应的工厂方法
|
|
25
|
+
* 例如: createLedSwitchCommand, createBlockPlayCommand 等
|
|
26
|
+
*/
|
|
27
|
+
static createExampleCommand(requestRef: string, targetClientId: string, deviceId: number, exampleField: string, exampleValue: number, operationType?: OperationType, options?: {
|
|
28
|
+
priority?: Priority;
|
|
29
|
+
timeout?: number;
|
|
30
|
+
callback?: string;
|
|
31
|
+
}): CommandMessage;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 命令类型验证器
|
|
35
|
+
*/
|
|
36
|
+
export declare class CommandTypeValidator {
|
|
37
|
+
/**
|
|
38
|
+
* 验证命令是否符合强类型定义
|
|
39
|
+
*/
|
|
40
|
+
static validateCommand(command: any): {
|
|
41
|
+
valid: boolean;
|
|
42
|
+
errors: string[];
|
|
43
|
+
};
|
|
44
|
+
private static validateExampleCommand;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 命令类型转换器
|
|
48
|
+
*/
|
|
49
|
+
export declare class CommandTypeConverter {
|
|
50
|
+
/**
|
|
51
|
+
* 将通用命令转换为强类型命令
|
|
52
|
+
*/
|
|
53
|
+
static toTypedCommand(genericCommand: any): SpecificCommand | null;
|
|
54
|
+
/**
|
|
55
|
+
* 检查命令是否为强类型命令
|
|
56
|
+
*/
|
|
57
|
+
static isTypedCommand(command: any): command is SpecificCommand;
|
|
58
|
+
}
|
|
59
|
+
export declare const createExampleCommand: typeof TypedCommandFactory.createExampleCommand;
|
|
60
|
+
export declare const validateCommand: typeof CommandTypeValidator.validateCommand;
|
|
61
|
+
export declare const toTypedCommand: typeof CommandTypeConverter.toTypedCommand;
|
|
62
|
+
//# sourceMappingURL=command-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-factory.d.ts","sourceRoot":"","sources":["../src/command-factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAkB,aAAa,EAAe,MAAM,SAAS,CAAC;AAErE;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAAC,CAAC,SAAS,MAAM,cAAc,EAC7D,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,CAAC,EACd,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,EACpD,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,cAAc;IAkBjB;;;;;OAKG;IACH,MAAM,CAAC,oBAAoB,CACzB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,aAAa,GAAE,aAAmC,EAClD,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,cAAc;CAelB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAqC1E,OAAO,CAAC,MAAM,CAAC,sBAAsB;CActC;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,GAAG,GAAG,eAAe,GAAG,IAAI;IAmBlE;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,eAAe;CAGhE;AAGD,eAAO,MAAM,oBAAoB,iDAAqE,CAAC;AAMvG,eAAO,MAAM,eAAe,6CAAkE,CAAC;AAC/F,eAAO,MAAM,cAAc,4CAAiE,CAAC"}
|