@mearl/cloud-types 3.0.0-beta.1 → 3.0.0-beta.10
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/README.md +16 -14
- package/README.zh-CN.md +89 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# @mearl/cloud-types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Shared types and constants for Mearl's cloud communication links.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`@mearl/client`, `cloud-server`, and `cloud-connector` communicate over WebSocket. This package defines their **shared wire protocol**: message structures, heartbeats, buffer limits, and default timeouts, keeping all three participants consistent.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
> For internal monorepo use only.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
### Message types
|
|
12
14
|
|
|
13
15
|
```typescript
|
|
14
16
|
interface CloudMessage {
|
|
@@ -45,7 +47,7 @@ interface ConnectorHelloMessage {
|
|
|
45
47
|
}
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
###
|
|
50
|
+
### Type guards
|
|
49
51
|
|
|
50
52
|
```typescript
|
|
51
53
|
isAgentHelloMessage(msg): msg is AgentHelloMessage
|
|
@@ -55,31 +57,31 @@ isCloudMessage(msg): msg is CloudMessage
|
|
|
55
57
|
isCloudResponse(msg): msg is CloudResponse
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
`resolveCloudConnectorSelector(connectors, selector)`
|
|
59
|
-
|
|
60
|
+
`resolveCloudConnectorSelector(connectors, selector)` resolves a connector by exact ID, exact name, then unique fuzzy match,
|
|
61
|
+
distinguishing a match, ambiguity, and no match.
|
|
60
62
|
|
|
61
|
-
###
|
|
63
|
+
### Constants
|
|
62
64
|
|
|
63
65
|
```typescript
|
|
64
|
-
MAX_BUFFER_SIZE; // 10 MB
|
|
66
|
+
MAX_BUFFER_SIZE; // 10 MB, maximum buffer per message
|
|
65
67
|
DEFAULT_REQUEST_TIMEOUT; // 60s
|
|
66
68
|
DEFAULT_CONNECT_TIMEOUT; // 30s
|
|
67
69
|
DEFAULT_HEARTBEAT_INTERVAL; // 30s
|
|
68
70
|
DEFAULT_HEARTBEAT_TIMEOUT; // 90s
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
##
|
|
73
|
+
## Usage
|
|
72
74
|
|
|
73
75
|
```typescript
|
|
74
76
|
import { type CloudMessage, isCloudResponse, DEFAULT_REQUEST_TIMEOUT } from '@mearl/cloud-types';
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
##
|
|
79
|
+
## Build
|
|
78
80
|
|
|
79
81
|
```bash
|
|
80
|
-
pnpm build # tsc
|
|
82
|
+
pnpm build # Compile with tsc into dist/
|
|
81
83
|
pnpm dev # tsc --watch
|
|
82
|
-
pnpm typecheck #
|
|
84
|
+
pnpm typecheck # Type checking only
|
|
83
85
|
```
|
|
84
86
|
|
|
85
87
|
## License
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @mearl/cloud-types
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Mearl 云端通信链路的共享类型与常量。
|
|
6
|
+
|
|
7
|
+
`@mearl/client`、`cloud-server`、`cloud-connector` 三端通过 WebSocket 互通,本包定义它们之间消息的**统一协议**(消息结构、心跳、缓冲区上限、各类超时默认值),确保三端对线上格式始终一致。
|
|
8
|
+
|
|
9
|
+
> 仅供 monorepo 内部使用。
|
|
10
|
+
|
|
11
|
+
## 导出
|
|
12
|
+
|
|
13
|
+
### 消息类型
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
interface CloudMessage {
|
|
17
|
+
id: string;
|
|
18
|
+
action: string;
|
|
19
|
+
data: Record<string, any>;
|
|
20
|
+
connector?: string;
|
|
21
|
+
browser?: string;
|
|
22
|
+
timeoutSec?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface CloudResponse {
|
|
26
|
+
id: string;
|
|
27
|
+
success: boolean;
|
|
28
|
+
data?: any;
|
|
29
|
+
error?: string;
|
|
30
|
+
versionWarning?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface HeartbeatMessage {
|
|
34
|
+
type: 'ping' | 'pong';
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface AgentHelloMessage {
|
|
39
|
+
type: 'agent_hello';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ConnectorHelloMessage {
|
|
43
|
+
type: 'connector_hello';
|
|
44
|
+
connectorId: string;
|
|
45
|
+
name: string;
|
|
46
|
+
version?: string;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 类型守卫
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
isAgentHelloMessage(msg): msg is AgentHelloMessage
|
|
54
|
+
isConnectorHelloMessage(msg): msg is ConnectorHelloMessage
|
|
55
|
+
isHeartbeatMessage(msg): msg is HeartbeatMessage
|
|
56
|
+
isCloudMessage(msg): msg is CloudMessage
|
|
57
|
+
isCloudResponse(msg): msg is CloudResponse
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`resolveCloudConnectorSelector(connectors, selector)` 按精确 ID、精确名称、唯一模糊匹配的
|
|
61
|
+
顺序解析 connector 目标,并区分匹配、歧义和未找到。
|
|
62
|
+
|
|
63
|
+
### 常量
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
MAX_BUFFER_SIZE; // 10 MB,单条消息缓冲上限
|
|
67
|
+
DEFAULT_REQUEST_TIMEOUT; // 60s
|
|
68
|
+
DEFAULT_CONNECT_TIMEOUT; // 30s
|
|
69
|
+
DEFAULT_HEARTBEAT_INTERVAL; // 30s
|
|
70
|
+
DEFAULT_HEARTBEAT_TIMEOUT; // 90s
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 使用
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { type CloudMessage, isCloudResponse, DEFAULT_REQUEST_TIMEOUT } from '@mearl/cloud-types';
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 构建
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pnpm build # tsc 编译到 dist/
|
|
83
|
+
pnpm dev # tsc --watch
|
|
84
|
+
pnpm typecheck # 仅类型检查
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearl/cloud-types",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
4
|
"description": "Shared types for Mearl cloud communication packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
24
|
+
"node": ">=20.18.0"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"registry": "https://registry.npmjs.org"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/
|
|
34
|
+
"url": "git+https://github.com/mearlhq/mearl.git",
|
|
35
35
|
"directory": "packages/cloud/cloud-types"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|