Files
Genarrative/server-rs/crates/shared-contracts
suzmii f09607d903
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
feat(游戏共创): 收录(收藏)列表补真分页(cursor + limit)
- 纯函数(`module-game-distribution/src/collection.rs`,与收藏另两条规则同文件):`encode/parse_game_distribution_collection_cursor`(`"{created_at_micros}:{collection_id}"`,复用仓库既有 `"{micros}:{id}"` 惯例;非法 → Err「收藏列表游标格式无效」→ 400)、`game_distribution_collection_page_limit`(0/缺省 → 20,超界 → 50)、`game_distribution_collection_page`(稳定全序排序 → 跳过游标之前 → 取 limit → 多取一条判 has_more,只对页内最后一条编码下一游标)
- 排序与顺序语义:`created_at` 倒序 + `collection_id` 升序兜底(主键、同用户内唯一 ⇒ 全序,翻页不重不漏);**先按可见性过滤、再排序切页**——游标位置必须落在已过滤序列上,否则被过滤的行会让下一页漏项(推理写进 tx 与纯函数注释);snapshot 只对最终页成员计算
- 模块:list 的 input 增 `limit` / `cursor`,result 增 `next_cursor`;api-server `my-collections` 加 `Query<MyCollectionsQuery>`,默认 20 / 上限 50(网格一屏 vs 单响应体积;与后台列表的 200 口径不必相等,理由写进注释),超界**截断**不报错,非法游标 400 透传不吞,日志带 `has_more`
- 契约:Rust DTO 增 `next_cursor`、TS 镜像同步、parity 登记(50 组一致)
- 文档:§3.4 的 `my-collections` 行补分页语义(默认/上限/游标格式/非法 400/末页 null/排序口径)
- 测试 13 条:纯函数 8(不足一页 → None;恰好整页不产生空游标;5 条 limit=2 连翻 3 页不重不漏;同 `created_at` 用 `collection_id` 兜底;limit=0 与超界;游标往返 + 7 种非法输入)、模块事务结构 2、api-server 3(默认与截断、`nextCursor` 透传、非法游标 → 400)
- 门禁:wasm build 0;`cargo check --all-targets` 0;`cargo test -p module-game-distribution` **81 passed**;`cargo test -p api-server game_distribution` **73 passed**;`cargo test -p spacetime-module` 274 passed / 1 ignored;DTO parity **50 组**;`check:spacetime-schema` 0(94 tables);`check:encoding` 0(5382 files);`cargo fmt --all -- --check` 0;`git diff --check` 0
2026-10-06 01:31:09 +08:00
..

shared-contracts 共享 crate 说明

日期:2026-04-21

1. crate 职责

shared-contracts 是前后端兼容 contract 共享 crate,后续负责:

  1. HTTP 请求与响应 DTO
  2. SSE 事件结构与事件名约定
  3. response envelope、错误结构、兼容头部契约
  4. 各模块对外暴露的共享协议类型

2. 当前阶段说明

当前阶段已完成 Stage1 最小真实落地:

  1. 统一 response envelope / 头部常量
  2. auth/login-options
  3. auth/me
  4. auth/sessions
  5. runtime/settings

当前阶段继续补齐的 Stage2 鉴权 DTO:

  1. auth/entry
  2. auth/refresh
  3. auth/logout
  4. auth/logout-all
  5. auth/phone/send-code
  6. auth/phone/login
  7. auth/wechat/start
  8. auth/wechat/callback
  9. auth/wechat/bind-phone
  10. auth/wechat/miniprogram-login

当前阶段继续补齐的 Stage3 公开请求 DTO:

  1. assets/direct-upload-tickets
  2. assets/read-url
  3. assets/objects/confirm
  4. assets/objects/bind
  5. story-sessions/begin
  6. story-sessions/continue

当前阶段继续补齐的 Stage4 显式成功响应 DTO:

  1. assets/direct-upload-tickets
  2. assets/read-url
  3. assets/objects/confirm
  4. assets/objects/bind
  5. story-sessions/begin
  6. story-sessions/continue

当前阶段新增 Stage6 character visual 兼容 DTO:

  1. assets/character-visual/generate
  2. assets/character-visual/jobs/:taskId
  3. assets/character-visual/publish

当前阶段新增 Stage7 character animation 模板与导入兼容 DTO:

  1. assets/character-animation/templates
  2. assets/character-animation/import-video

当前阶段新增 Stage8 character workflow cache 第一批兼容 DTO:

  1. assets/character-workflow-cache
  2. assets/character-workflow-cache/:characterId

当前阶段新增 Stage9 character animation 主链兼容 DTO:

  1. assets/character-animation/generate
  2. assets/character-animation/jobs/:taskId
  3. assets/character-animation/publish

当前阶段新增 Stage5 story session scoped runtime story 写读 DTO:

  1. BeginStoryRuntimeSessionRequest
  2. ResolveStoryRuntimeActionRequest
  3. StoryRuntimeProjectionResponse
  4. StoryRuntimeMutationResponse
  5. StoryRuntimeSnapshotPayload 仅用于 story session scoped 写侧持久化边界,不复用旧 /api/runtime/story/* 总入口 contract。

WP-DEL 已删除旧 runtime story HTTP DTO:RuntimeStoryStateResolveRequest、RuntimeStoryBootstrapRequest/Response、RuntimeStoryActionResponse 和旧 RuntimeStorySnapshotPayload。runtime_story 模块中仍保留的 RuntimeStoryViewModel、RuntimeStoryPresentation、RuntimeStoryPatch 与 battle presentation 是当前投影/表现构件,不作为旧 HTTP 写入口。

当前仍刻意未做:

  1. SSE 事件结构
  2. 自动代码生成或跨语言 contract 同步
  3. 其他尚未收口模块的 handler 响应体显式 DTO 化

3. 边界约束

  1. shared-contracts 只放协议类型与兼容结构,不承接业务规则、供应商适配或状态写入逻辑。
  2. 各模块 crate 对外暴露的协议优先复用这里的共享定义,避免重复散落。
  3. 前端兼容契约一旦进入本 crate,就必须与任务清单和基线文档同步维护。
  4. assets 模块依赖 platform-oss 的稳定返回类型,默认通过 oss-contracts feature 给 api-server 使用;SpacetimeDB WASM 构建链路必须通过 workspace 依赖关闭默认 feature,避免把 platform-oss / reqwest / wasm-bindgen 带进 spacetime-module。