@wailsnet/runtime 0.0.0-stage → 0.1.0-alpha.2

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.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Wails.Net 前后端 IPC 协议类型定义。
3
+ *
4
+ * 协议与 Wails.Net 后端 `MessageProcessor` / `ResponseMessage` 严格对齐:
5
+ * - 上行(前端 → 后端):`WailsMessage { id, type, payload, windowId?, origin? }`
6
+ * - 下行(后端 → 前端):`WailsResponse { id, type, result: { result, error } }`
7
+ *
8
+ * 重要:响应是**双层**结构,`result.result` 才是业务返回值,`result.error` 为错误。
9
+ * 部分路径下 `type` 会变成 `"error"`(协议/解析错误),需兼容处理。
10
+ */
11
+ /** 错误种类,与后端 `Wails.Net.Errors.CallErrorKind` 一致。 */
12
+ export type CallErrorKind = "ReferenceError" | "TypeError" | "RuntimeError";
13
+ /** 后端返回的业务错误对象。 */
14
+ export interface WailsCallError {
15
+ /** 错误消息。 */
16
+ message: string;
17
+ /** 触发此错误的底层原因(可能为 null)。 */
18
+ cause: string | null;
19
+ /** 错误种类。 */
20
+ kind: CallErrorKind;
21
+ }
22
+ /** 上行消息信封(前端 → 后端)。 */
23
+ export interface WailsMessage<P = unknown> {
24
+ /** 调用 ID,必须全局唯一且为字符串(取消机制依赖它作为 callId)。 */
25
+ id: string;
26
+ /** 消息类型 / 命令名,如 "call"、"event.emit"、"cancel"、"window.setTitle"、"clipboard.getText"。 */
27
+ type: string;
28
+ /** 载荷(任意 JSON)。 */
29
+ payload: P;
30
+ /** 可选:目标窗口 ID(原生通道会自动注入;HTTP 通道不会)。 */
31
+ windowId?: number;
32
+ /** 可选:来源 URL(Capability.remote 校验用)。 */
33
+ origin?: string;
34
+ }
35
+ /** 下行响应信封(后端 → 前端)。`type` 为 "response" 或 "error"。 */
36
+ export interface WailsResponse<R = unknown> {
37
+ /** 对应上行消息的 id。 */
38
+ id: string;
39
+ /** "response" 表示正常响应(即使其中包含业务错误);"error" 表示协议/解析错误。 */
40
+ type: "response" | "error";
41
+ /** 业务结果:{ result, error } 双层结构。 */
42
+ result: {
43
+ /** 业务返回值(成功时);失败时通常为 null。 */
44
+ result: R | null;
45
+ /** 业务错误(失败时);成功时为 null。 */
46
+ error: WailsCallError | null;
47
+ };
48
+ }
49
+ /** 事件载荷(上行 emit / 下行推送共用)。 */
50
+ export interface WailsEventPayload<D = unknown> {
51
+ /** 事件名(内建事件以 `wails:` 前缀)。 */
52
+ name: string;
53
+ /** 事件数据。 */
54
+ data: D;
55
+ /** 发送方窗口 ID(可选)。 */
56
+ senderWindowId?: number;
57
+ /** 定向目标窗口 ID(OPT-EVENT-002,可选;缺省 = 广播)。 */
58
+ targetWindowId?: number;
59
+ }
60
+ /** 运行时配置标志。C# 端 `RuntimeGenerator` 会注入 `window._wails`,未注入时使用默认值。 */
61
+ export interface WailsRuntimeFlags {
62
+ /** 平台:windows / linux / android / darwin。 */
63
+ platform: string;
64
+ /** 是否调试模式。 */
65
+ isDebug: boolean;
66
+ /** 是否 Server 模式(使用 WebSocket 而非原生/HTTP)。 */
67
+ isServerMode: boolean;
68
+ /** 资源服务器 URL(Server 模式下 HTTP 通道的基址)。 */
69
+ assetServerUrl?: string;
70
+ /** WebSocket URL(Server 模式通道)。 */
71
+ webSocketUrl?: string;
72
+ /** IPC handshake token(OPT-IPC-002):HTTP 请求头 / WebSocket 查询参数回传校验。 */
73
+ ipcToken?: string;
74
+ }
75
+ /** 读取 `window._wails` 运行时标志(若存在)。 */
76
+ export declare function readRuntimeFlags(): Partial<WailsRuntimeFlags> | undefined;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Wails.Net 前后端 IPC 协议类型定义。
3
+ *
4
+ * 协议与 Wails.Net 后端 `MessageProcessor` / `ResponseMessage` 严格对齐:
5
+ * - 上行(前端 → 后端):`WailsMessage { id, type, payload, windowId?, origin? }`
6
+ * - 下行(后端 → 前端):`WailsResponse { id, type, result: { result, error } }`
7
+ *
8
+ * 重要:响应是**双层**结构,`result.result` 才是业务返回值,`result.error` 为错误。
9
+ * 部分路径下 `type` 会变成 `"error"`(协议/解析错误),需兼容处理。
10
+ */
11
+ /** 读取 `window._wails` 运行时标志(若存在)。 */
12
+ export function readRuntimeFlags() {
13
+ const w = globalThis;
14
+ return w._wails;
15
+ }
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAwEH,qCAAqC;AACrC,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,GAAG,UAAgE,CAAC;IAC3E,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@wailsnet/runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "TypeScript frontend runtime SDK for Wails.Net (the .NET 10 port of Wails v3). Self-contained IPC transport (WebView2 / WebKitGTK / Android native postMessage, HTTP chunked upload, Server-mode WebSocket) plus strongly-typed wrappers for every core namespace and all 46 built-in/mobile plugins.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "sideEffects": false,
21
+ "keywords": [
22
+ "wails",
23
+ "wails.net",
24
+ "wails-v3",
25
+ "dotnet",
26
+ "ipc",
27
+ "desktop",
28
+ "tauri-alternative"
29
+ ],
30
+ "author": "Wails.Net contributors",
31
+ "license": "MIT",
32
+ "devDependencies": {
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^5.1.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "registry": "https://registry.npmjs.org"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/lytree/Wails.Net.git",
43
+ "directory": "packages/wails-net-runtime"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json",
47
+ "dev": "tsc -p tsconfig.json --watch",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest"
51
+ }
6
52
  }