Replace the deprecated v3 string-method forms with the top-level
validator helpers zod 4 prefers:
- z.string().url() → z.url() (3 sites)
- z.string().uuid() → z.uuid() (5 sites)
- z.string().datetime() → z.iso.datetime() (9 sites)
Also swap the ZodIssueCode.custom compat-shim reference in
demo-bot.server.ts's superRefine for the bare string literal "custom",
which is v4's idiomatic form. No runtime change.
All 147 tests still pass.
The `parsed.error.issues.map(i => ({field, message}))` pattern in the
five journal API route handlers stays as-is — the fields we read are
unchanged in v4, and zod's new error helpers (z.treeifyError,
z.prettifyError) produce different shapes that would change our
public API error contract.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import { z } from "zod";
|
|
|
|
/** Route summary for list views */
|
|
export const RouteSummarySchema = z.object({
|
|
id: z.uuid(),
|
|
name: z.string(),
|
|
description: z.string(),
|
|
distance: z.number().nullable(),
|
|
elevationGain: z.number().nullable(),
|
|
elevationLoss: z.number().nullable(),
|
|
routingProfile: z.string().nullable(),
|
|
dayBreaks: z.array(z.number()),
|
|
geojson: z.string().nullable(),
|
|
createdAt: z.iso.datetime(),
|
|
updatedAt: z.iso.datetime(),
|
|
});
|
|
|
|
/** Route version info */
|
|
export const RouteVersionSchema = z.object({
|
|
version: z.number(),
|
|
changeDescription: z.string().nullable(),
|
|
createdAt: z.iso.datetime(),
|
|
});
|
|
|
|
/** Full route detail */
|
|
export const RouteDetailSchema = RouteSummarySchema.extend({
|
|
gpx: z.string().nullable(),
|
|
versions: z.array(RouteVersionSchema),
|
|
});
|
|
|
|
/** Paginated route list response */
|
|
export const RouteListResponseSchema = z.object({
|
|
routes: z.array(RouteSummarySchema),
|
|
nextCursor: z.string().nullable(),
|
|
});
|
|
|
|
/** Create route request */
|
|
export const CreateRouteRequestSchema = z.object({
|
|
name: z.string().min(1).max(200),
|
|
description: z.string().max(5000).default(""),
|
|
gpx: z.string().optional(),
|
|
routingProfile: z.string().optional(),
|
|
});
|
|
|
|
/** Update route request */
|
|
export const UpdateRouteRequestSchema = z.object({
|
|
name: z.string().min(1).max(200).optional(),
|
|
description: z.string().max(5000).optional(),
|
|
gpx: z.string().optional(),
|
|
});
|
|
|
|
/** Compute route request (BRouter proxy) */
|
|
export const ComputeRouteRequestSchema = z.object({
|
|
waypoints: z.array(z.object({
|
|
lat: z.number(),
|
|
lon: z.number(),
|
|
})).min(2),
|
|
profile: z.string().default("fastbike"),
|
|
noGoAreas: z.array(z.object({
|
|
points: z.array(z.object({
|
|
lat: z.number(),
|
|
lon: z.number(),
|
|
})),
|
|
})).optional(),
|
|
});
|
|
|
|
export type RouteSummary = z.infer<typeof RouteSummarySchema>;
|
|
export type RouteVersion = z.infer<typeof RouteVersionSchema>;
|
|
export type RouteDetail = z.infer<typeof RouteDetailSchema>;
|
|
export type RouteListResponse = z.infer<typeof RouteListResponseSchema>;
|
|
export type CreateRouteRequest = z.infer<typeof CreateRouteRequestSchema>;
|
|
export type UpdateRouteRequest = z.infer<typeof UpdateRouteRequestSchema>;
|
|
export type ComputeRouteRequest = z.infer<typeof ComputeRouteRequestSchema>;
|