2025-12-09 17:51:05 +00:00
|
|
|
|
---
|
|
|
|
|
|
summary: "TypeBox schemas as the single source of truth for the gateway protocol"
|
|
|
|
|
|
read_when:
|
|
|
|
|
|
- Updating protocol schemas or codegen
|
|
|
|
|
|
---
|
2026-01-08 23:06:56 +01:00
|
|
|
|
# TypeBox as protocol source of truth
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
Last updated: 2026-01-08
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
TypeBox schemas define the Gateway control plane (connect/req/res/event frames and
|
|
|
|
|
|
payloads). All generated artifacts must come from these schemas.
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
|
|
|
|
|
## Current pipeline
|
|
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
- `pnpm protocol:gen`
|
|
|
|
|
|
- writes the JSON Schema output (draft‑07)
|
|
|
|
|
|
- `pnpm protocol:gen:swift`
|
|
|
|
|
|
- generates Swift gateway models
|
|
|
|
|
|
- `pnpm protocol:check`
|
|
|
|
|
|
- runs both generators and verifies the output is committed
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
## Swift codegen behavior
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
The Swift generator emits:
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
- `GatewayFrame` enum with `req`, `res`, `event`, and `unknown` cases
|
|
|
|
|
|
- Strongly typed payload structs/enums
|
|
|
|
|
|
- `ErrorCode` values and `GATEWAY_PROTOCOL_VERSION`
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
Unknown frame types are preserved as raw payloads for forward compatibility.
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
## When you change schemas
|
2025-12-09 15:18:34 +01:00
|
|
|
|
|
2026-01-08 23:06:56 +01:00
|
|
|
|
1) Update the TypeBox schemas.
|
|
|
|
|
|
2) Run `pnpm protocol:check`.
|
|
|
|
|
|
3) Commit the regenerated schema + Swift models.
|