one source of truth for Route/Activity shapes; enforce api contracts
Route and Activity existed three times: hand-written interfaces in packages/types, Zod contracts in packages/api, and Drizzle columns in packages/db — each with different fields and nullability. The hand-written ones had drifted so far they had zero importers; the Zod contracts were advisory because v1 handlers hand-rolled Response.json shapes nothing validated. - packages/types keeps only what both apps actually share (Waypoint, WaypointPoiTags) and documents where row types and wire contracts live; the dead Route/RouteMetadata/RouteVersion/Activity interfaces are gone - packages/db exports canonical inferred row types (RouteRow, ActivityRow, RouteVersionRow, UserRow) - packages/api contracts are reconciled with the real wire format (RouteVersionSchema gains the id and createdBy fields the endpoint has always returned) and gain Create*ResponseSchemas - apiJson(schema, payload) in api-guard parses every v1 response through its contract: drift is now a thrown ZodError in tests/CI, unknown keys are stripped, and payloads are compile-checked as z.input of the schema Enforcement immediately caught two real drifts: nullable DB descriptions could ship null where the contract promises string (now coalesced at the boundary), and GET /api/v1/activities/:id was missing the routeName and photos fields its contract declares. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
1a65b40d18
commit
61a2d0085b
11 changed files with 83 additions and 73 deletions
|
|
@ -1,7 +1,13 @@
|
|||
/**
|
||||
* Shared TypeScript types for trails.cool
|
||||
* Shared TypeScript types for trails.cool — the Waypoint wire format
|
||||
* used by both the Planner and Journal apps (Yjs document, GPX
|
||||
* extensions, handoff payloads).
|
||||
*
|
||||
* These types are used by both the Planner and Journal apps.
|
||||
* Not here on purpose: database row types are derived from the Drizzle
|
||||
* schema (@trails-cool/db, e.g. RouteRow), and API response shapes are
|
||||
* the Zod contracts in @trails-cool/api. Earlier hand-written Route /
|
||||
* Activity interfaces in this file drifted from both and had zero
|
||||
* importers when they were removed.
|
||||
*/
|
||||
|
||||
export interface WaypointPoiTags {
|
||||
|
|
@ -26,48 +32,3 @@ export interface Waypoint {
|
|||
osmId?: number;
|
||||
poiTags?: WaypointPoiTags;
|
||||
}
|
||||
|
||||
export interface RouteMetadata {
|
||||
created: Date;
|
||||
updated: Date;
|
||||
owner: string;
|
||||
contributors: string[];
|
||||
routingProfile: string;
|
||||
dayBreaks: number[];
|
||||
distance: number;
|
||||
elevation: {
|
||||
gain: number;
|
||||
loss: number;
|
||||
};
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
export interface Route {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
gpx: string;
|
||||
metadata: RouteMetadata;
|
||||
plannerState?: Uint8Array;
|
||||
versions: RouteVersion[];
|
||||
}
|
||||
|
||||
export interface RouteVersion {
|
||||
version: number;
|
||||
gpx: string;
|
||||
createdAt: Date;
|
||||
createdBy: string;
|
||||
changeDescription?: string;
|
||||
}
|
||||
|
||||
export interface Activity {
|
||||
id: string;
|
||||
routeId?: string;
|
||||
name: string;
|
||||
description: string;
|
||||
gpx: string;
|
||||
startedAt: Date;
|
||||
duration: number;
|
||||
photos: string[];
|
||||
participants: string[];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue