@mearl/cloud-types 2.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/README.md +74 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +14 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @mearl/cloud-types
|
|
2
|
+
|
|
3
|
+
Mearl 云端通信链路的共享类型与常量。
|
|
4
|
+
|
|
5
|
+
`cloud-client`、`cloud-server`、`cloud-connector` 三端通过 WebSocket 互通,本包定义它们之间消息的**统一协议**(消息结构、心跳、缓冲区上限、各类超时默认值),确保三端对线上格式始终一致。
|
|
6
|
+
|
|
7
|
+
> 仅供 monorepo 内部使用。
|
|
8
|
+
|
|
9
|
+
## 导出
|
|
10
|
+
|
|
11
|
+
### 消息类型
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
interface CloudMessage {
|
|
15
|
+
id: string;
|
|
16
|
+
action: string;
|
|
17
|
+
data: Record<string, any>;
|
|
18
|
+
browser?: string;
|
|
19
|
+
timeoutSec?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface CloudResponse {
|
|
23
|
+
id: string;
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: any;
|
|
26
|
+
error?: string;
|
|
27
|
+
versionWarning?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface HeartbeatMessage {
|
|
31
|
+
type: 'ping' | 'pong';
|
|
32
|
+
timestamp: number;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 类型守卫
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
isHeartbeatMessage(msg): msg is HeartbeatMessage
|
|
40
|
+
isCloudMessage(msg): msg is CloudMessage
|
|
41
|
+
isCloudResponse(msg): msg is CloudResponse
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 常量
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
MAX_BUFFER_SIZE; // 10 MB,单条消息缓冲上限
|
|
48
|
+
DEFAULT_REQUEST_TIMEOUT; // 60s
|
|
49
|
+
DEFAULT_CONNECT_TIMEOUT; // 30s
|
|
50
|
+
DEFAULT_HEARTBEAT_INTERVAL; // 30s
|
|
51
|
+
DEFAULT_HEARTBEAT_TIMEOUT; // 90s
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 使用
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import {
|
|
58
|
+
type CloudMessage,
|
|
59
|
+
isCloudResponse,
|
|
60
|
+
DEFAULT_REQUEST_TIMEOUT,
|
|
61
|
+
} from '@mearl/cloud-types';
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 构建
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pnpm build # tsc 编译到 dist/
|
|
68
|
+
pnpm dev # tsc --watch
|
|
69
|
+
pnpm typecheck # 仅类型检查
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
ISC
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface CloudMessage {
|
|
2
|
+
id: string;
|
|
3
|
+
action: string;
|
|
4
|
+
data: Record<string, any>;
|
|
5
|
+
/**
|
|
6
|
+
* Target a specific browser on the connector's machine by id / name. Omitted →
|
|
7
|
+
* the connector's default (most-recently-focused) browser.
|
|
8
|
+
*/
|
|
9
|
+
browser?: string;
|
|
10
|
+
/** Action execution timeout forwarded to the local socket client. */
|
|
11
|
+
timeoutSec?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface CloudResponse {
|
|
14
|
+
id: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
data?: any;
|
|
17
|
+
error?: string;
|
|
18
|
+
versionWarning?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface HeartbeatMessage {
|
|
21
|
+
type: 'ping' | 'pong';
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
export declare const MAX_BUFFER_SIZE: number;
|
|
25
|
+
export declare const DEFAULT_REQUEST_TIMEOUT = 60;
|
|
26
|
+
export declare const DEFAULT_HEARTBEAT_INTERVAL = 30;
|
|
27
|
+
export declare const DEFAULT_CONNECT_TIMEOUT = 30;
|
|
28
|
+
export declare const DEFAULT_HEARTBEAT_TIMEOUT = 90;
|
|
29
|
+
export declare function isHeartbeatMessage(msg: any): msg is HeartbeatMessage;
|
|
30
|
+
export declare function isCloudMessage(msg: any): msg is CloudMessage;
|
|
31
|
+
export declare function isCloudResponse(msg: any): msg is CloudResponse;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
2
|
+
export const DEFAULT_REQUEST_TIMEOUT = 60;
|
|
3
|
+
export const DEFAULT_HEARTBEAT_INTERVAL = 30;
|
|
4
|
+
export const DEFAULT_CONNECT_TIMEOUT = 30;
|
|
5
|
+
export const DEFAULT_HEARTBEAT_TIMEOUT = 90;
|
|
6
|
+
export function isHeartbeatMessage(msg) {
|
|
7
|
+
return msg && (msg.type === 'ping' || msg.type === 'pong');
|
|
8
|
+
}
|
|
9
|
+
export function isCloudMessage(msg) {
|
|
10
|
+
return msg && typeof msg.id === 'string' && typeof msg.action === 'string';
|
|
11
|
+
}
|
|
12
|
+
export function isCloudResponse(msg) {
|
|
13
|
+
return msg && typeof msg.id === 'string' && typeof msg.success === 'boolean';
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mearl/cloud-types",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Shared types for Mearl cloud communication packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mearl",
|
|
19
|
+
"cloud-types"
|
|
20
|
+
],
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.8.3"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist/ && tsc",
|
|
30
|
+
"dev": "tsc --watch",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
}
|
|
34
|
+
}
|