Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
6.3 KiB
@esengine/rpc
1.1.3
Patch Changes
-
#404
902c0a1Thanks @esengine! - feat(server): add HTTP file-based routing support / 添加 HTTP 文件路由支持New feature that allows organizing HTTP routes in separate files, similar to API and message handlers. 新功能:支持将 HTTP 路由组织在独立文件中,类似于 API 和消息处理器的文件路由方式。
// src/http/login.ts import { defineHttp } from '@esengine/server'; export default defineHttp<{ username: string; password: string }>({ method: 'POST', handler(req, res) { const { username, password } = req.body; res.json({ token: '...', userId: '...' }); } });Server configuration / 服务器配置:
const server = await createServer({ port: 8080, httpDir: 'src/http', // HTTP routes directory / HTTP 路由目录 httpPrefix: '/api', // Route prefix / 路由前缀 cors: true });File naming convention / 文件命名规则:
login.ts→ POST /api/loginusers/profile.ts→ POST /api/users/profileusers/[id].ts→ POST /api/users/:id (dynamic routes / 动态路由)- Set
method: 'GET'in defineHttp for GET requests / 在 defineHttp 中设置method: 'GET'以处理 GET 请求
Also includes / 还包括:
defineHttp<TBody>()helper for type-safe route definitions / 类型安全的路由定义辅助函数- Support for merging file routes with inline
httpconfig / 支持文件路由与内联http配置合并 - RPC server supports attaching to existing HTTP server via
serveroption / RPC 服务器支持通过server选项附加到现有 HTTP 服务器
1.1.2
Patch Changes
-
feat(server): add HTTP file-based routing support
New feature that allows organizing HTTP routes in separate files, similar to API and message handlers:
// src/http/login.ts import { defineHttp } from '@esengine/server'; export default defineHttp<{ username: string; password: string }>({ method: 'POST', handler(req, res) { const { username, password } = req.body; // ... authentication logic res.json({ token: '...', userId: '...' }); } });Server configuration:
const server = await createServer({ port: 8080, httpDir: 'src/http', // HTTP routes directory httpPrefix: '/api', // Route prefix cors: true });File naming convention:
login.ts→ POST /api/loginusers/profile.ts→ POST /api/users/profileusers/[id].ts→ POST /api/users/:id (dynamic routes)- Set
method: 'GET'in defineHttp for GET requests
Also includes:
defineHttp<TBody>()helper function for type-safe route definitions- Support for merging file routes with inline
httpconfig - RPC server now supports attaching to existing HTTP server via
serveroption
1.1.1
Patch Changes
-
#374
a000cc0Thanks @esengine! - feat: export RpcClient and connect from main entry pointRe-export
RpcClient,connect, and related types from the main entry point for better compatibility with bundlers (Cocos Creator, Vite, etc.) that may have issues with subpath exports.// Now works in all environments: import { rpc, RpcClient, connect } from '@esengine/rpc'; // Subpath import still supported: import { RpcClient } from '@esengine/rpc/client';
1.1.0
Minor Changes
-
#364
7940f58Thanks @esengine! - ## @esengine/rpc新增 | Added
- 新增类型安全的 RPC 库,支持 WebSocket 通信
- 新增
RpcClient类:connect/disconnect, call/send/on/off/once 方法 - 新增
RpcServer类:Node.js WebSocket 服务端 - 新增编解码系统:支持 JSON 和 MessagePack
- 新增 TextEncoder/TextDecoder polyfill,兼容微信小游戏平台
- 新增 WebSocketAdapter 接口,支持跨平台 WebSocket 抽象
- Add type-safe RPC library with WebSocket support
- Add
RpcClientclass with connect/disconnect, call/send/on/off/once methods - Add
RpcServerclass for Node.js WebSocket server - Add codec system with JSON and MessagePack support
- Add TextEncoder/TextDecoder polyfill for WeChat platform compatibility
- Add WebSocketAdapter interface for cross-platform WebSocket abstraction
@esengine/network
变更 | Changed
- 重构 NetworkService:拆分为
RpcService<P>基类和GameNetworkService游戏服务类 - 新增
gameProtocol:类型安全的 API (join/leave) 和消息 (input/sync/spawn/despawn) - 新增类型安全的便捷方法:sendInput(), onSync(), onSpawn(), onDespawn()
- 更新 NetworkPlugin 使用新的服务架构
- 移除 TSRPC 依赖,改用 @esengine/rpc
- Refactor NetworkService into
RpcService<P>base class andGameNetworkService - Add
gameProtocolwith type-safe API (join/leave) and messages (input/sync/spawn/despawn) - Add type-safe convenience methods: sendInput(), onSync(), onSpawn(), onDespawn()
- Update NetworkPlugin to use new service architecture
- Remove TSRPC dependency, migrate to @esengine/rpc
@esengine/cli
变更 | Changed
- 更新 Node.js 适配器使用
@esengine/rpc和@esengine/network - 生成的服务器代码改用
RpcServer+gameProtocol - 添加
ws和@types/ws依赖 - 更新 README 模板中的客户端连接示例
- Update Node.js adapter to use
@esengine/rpcand@esengine/network - Generated server code now uses
RpcServer+gameProtocol - Add
wsand@types/wsdependencies - Update client connection example in README template