Files
Genarrative/server-rs/crates/spacetime-client/README.md

45 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# spacetime-client 共享 package 占位说明
日期:`2026-04-20`
## 1. package 职责
`spacetime-client` 是 SpacetimeDB 客户端适配 package后续负责
1. 生成 bindings 后的客户端访问封装
2. Axum 与各模块对 reducer、view、订阅的调用适配
3. 身份透传、连接配置与基础错误处理适配
## 2. 当前阶段说明
当前目录已不再只是占位,当前阶段已经落下:
1. 通过 `spacetime generate --lang rust --include-private` 生成的最小 Rust bindings
2. `DbConnection` 连接封装
3. `confirm_asset_object_and_return` procedure 的最小调用适配
4. `bind_asset_object_to_entity_and_return` procedure 的最小调用适配
5. `api-server` 所需的 `asset_object` 确认与 `asset_entity_binding` 绑定返回值转换
`confirm_asset_object_and_return``bind_asset_object_to_entity_and_return` 的调用必须等到 SDK `on_connect` 回调后再发起。`DbConnection::build()` 只代表 WebSocket 已经初始化,不代表 SpacetimeDB 身份握手完成;如果过早调用 procedure本地联调会表现为连接建立但请求长期没有回调最终等到 idle timeout。
后续与本 package 直接相关的任务包括:
1. 固化 bindings 生成与更新脚本
2. 设计 reducer、procedure、view、订阅的统一调用接口
3. 设计身份透传与连接配置策略
4. 设计 Axum / worker / 测试环境下的客户端复用方式
## 2.1 `module_bindings` 生成物约束
`src/module_bindings` 目录下的 Rust 文件统一视为 SpacetimeDB CLI 生成产物,后续维护必须遵守:
1. 只允许通过 `spacetime generate --lang rust` 刷新,不允许手工修改。
2. 不允许对该目录执行 `rustfmt`,避免把 CLI 原始输出改写成额外格式化噪音。
3. `src/lib.rs` 已通过 `#[rustfmt::skip] pub mod module_bindings;` 显式阻止 workspace 级 `cargo fmt` 继续递归格式化该目录。
## 3. 边界约束
1. `spacetime-client` 只承接 SpacetimeDB 客户端访问适配,不承接具体业务模块的规则实现。
2. 业务状态真相仍由 `apps/spacetime-module` 管理,业务编排由各模块 package 与 `apps/api-server` 承担。
3. 不允许把 reducer、view、订阅调用细节重新散落到多个业务模块里各自实现。