Refactor: Move REST wire types into shared crate (kill server/SDK/bot drift) #82

Closed
opened 2026-07-08 02:40:31 +00:00 by icub3d · 0 comments
Owner

Category: Refactor / maintainability — found in code review 2026-07-07. Highest-leverage cleanup.

Problem

Every REST request/response body is hand-duplicated between server/src/**/models.rs and sdk/rust/src/rest/models.rs (the SDK file's own doc-comment admits "must stay in lockstep"). The message/channel/role/member shapes are duplicated a third time in tools/bot-sdk/src/events.rs. Serde silently ignores unknown fields, so drift hides (e.g. bot-sdk MessageEvent already omits deleted/attachments/reactions/thread).

By contrast, shared::gateway and shared::auth types are shared correctly by both sides — that's the model to follow.

Fix

  • Promote REST wire types to shared with #[derive(Serialize, Deserialize)].
  • server/src/**/models.rs re-export or From-convert from shared.
  • Replace sdk/rust/src/rest/models.rs bodies with pub use shared::....
  • Define gateway event payloads once in shared and have both the server broadcaster and bot-sdk consume them.
  • SDK: serialize client commands (SUBSCRIBE/UNSUBSCRIBE/HEARTBEAT_ACK) through the shared Op/ClientCommand enum instead of raw string literals (sdk/rust/src/gateway.rs:197).
**Category: Refactor / maintainability** — found in code review 2026-07-07. Highest-leverage cleanup. ## Problem Every REST request/response body is hand-duplicated between `server/src/**/models.rs` and `sdk/rust/src/rest/models.rs` (the SDK file's own doc-comment admits "must stay in lockstep"). The message/channel/role/member shapes are duplicated a **third** time in `tools/bot-sdk/src/events.rs`. Serde silently ignores unknown fields, so drift hides (e.g. bot-sdk `MessageEvent` already omits `deleted`/`attachments`/`reactions`/`thread`). By contrast, `shared::gateway` and `shared::auth` types *are* shared correctly by both sides — that's the model to follow. ## Fix - [ ] Promote REST wire types to `shared` with `#[derive(Serialize, Deserialize)]`. - [ ] `server/src/**/models.rs` re-export or `From`-convert from `shared`. - [ ] Replace `sdk/rust/src/rest/models.rs` bodies with `pub use shared::...`. - [ ] Define gateway event payloads once in `shared` and have both the server broadcaster and bot-sdk consume them. - [ ] SDK: serialize client commands (`SUBSCRIBE`/`UNSUBSCRIBE`/`HEARTBEAT_ACK`) through the shared `Op`/`ClientCommand` enum instead of raw string literals (`sdk/rust/src/gateway.rs:197`).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icub3d/decentcom#82
No description provided.