Appearance
Schemas
Valibot schemas are used throughout SafeCall for runtime validation of external data. The shared schemas are defined in lib/src/schemas.ts.
MQTT Schemas
Beacon Advertisement Schemas
| Schema | Message Type | Fields |
|---|---|---|
MqttButtonAdv1Schema | adv1 | Battery, temperature, humidity, button state, alarm counter |
MqttButtonAdv4Schema | adv4 | RSSI (signal strength), gateway MAC |
MqttButtonAdv8Schema | adv8 | Extended sensor data |
Beacon Message Schema
MqttBeaconMessageSchema wraps beacon advertisements with metadata:
mac— Beacon MAC addresstype— Advertisement type (1, 4, or 8)data— The advertisement payload
Gateway Schemas
| Schema | Purpose |
|---|---|
MqttGatewayAliveSchema | Gateway heartbeat (IP, uptime, firmware) |
MqttGatewayAdvDataSchema | Gateway-forwarded beacon advertisements |
MqttGatewayMessageSchema | Top-level gateway message wrapper |
KISS Schemas
| Schema | Purpose |
|---|---|
KissLoginResponseSchema | Response from KISS API login |
LLD Schemas (Zabbix)
| Schema | Purpose |
|---|---|
LLDBeaconSchema | Zabbix Low-Level Discovery beacon format |
LLDGatewaySchema | Zabbix Low-Level Discovery gateway format |
WebSocket Schemas
| Schema | Purpose |
|---|---|
HttpWsMessageSchema | General WebSocket message (type + payload) |
HttpWsMessageTrackSchema | Track/debug subscription (type + mac) |
HttpWsMessageOverviewSchema | Overview subscription (type + map_id) |
HttpWsMessageBeaconTestSchema | Test beacon simulation message |
Web Frontend Contracts
The web frontend defines its own schemas in web/src/lib/contracts.ts. These mirror the server's API contracts and are used for client-side validation:
- Entity schemas:
UserSchema,BeaconSchema,GatewaySchema,MapSchema,FloorSchema,LocationSchema,LogSchema,EventSchema,NodeSchema,EdgeSchema - Request schemas:
LoginRequestSchema,BeaconCreateRequestSchema,FloorCreateRequestSchema, etc. - Response schemas:
LoginResponseSchema,MapsListResponseSchema,FloorGraphResponseSchema, etc.
Server Query Schemas
The server defines additional Valibot schemas in server/src/schemas.ts for validating database query results:
QueryResultUserSchema,QueryResultBeaconSchema,QueryResultLocationSchemaQueryResultGatewaySchema,QueryResultMapSchema,QueryResultFloorSchemaQueryResultZoneSchema,QueryResultNodeSchema,QueryResultEdgeSchema- And more (see Types for the complete list)
Validation Pattern
All schemas use valibot with a consistent pattern:
typescript
import * as v from "valibot";
// Define schema
const MySchema = v.object({
id: v.number(),
name: v.string(),
active: v.boolean(),
});
// Validate data
const result = v.parse(MySchema, data);
// Infer TypeScript type
type MyType = v.InferOutput<typeof MySchema>;