Modernise zod idioms to v4

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>
This commit is contained in:
Ullrich Schäfer 2026-04-19 11:41:03 +02:00
parent 0eea6f2047
commit 079c3de90c
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
6 changed files with 20 additions and 20 deletions

View file

@ -2,24 +2,24 @@ import { z } from "zod";
/** Activity summary for list views */
export const ActivitySummarySchema = z.object({
id: z.string().uuid(),
id: z.uuid(),
name: z.string(),
description: z.string(),
routeId: z.string().uuid().nullable(),
routeId: z.uuid().nullable(),
routeName: z.string().nullable(),
distance: z.number().nullable(),
duration: z.number().nullable(),
elevationGain: z.number().nullable(),
elevationLoss: z.number().nullable(),
startedAt: z.string().datetime().nullable(),
startedAt: z.iso.datetime().nullable(),
geojson: z.string().nullable(),
createdAt: z.string().datetime(),
createdAt: z.iso.datetime(),
});
/** Full activity detail */
export const ActivityDetailSchema = ActivitySummarySchema.extend({
gpx: z.string().nullable(),
photos: z.array(z.string().url()),
photos: z.array(z.url()),
});
/** Paginated activity list response */
@ -33,8 +33,8 @@ export const CreateActivityRequestSchema = z.object({
name: z.string().min(1).max(200),
description: z.string().max(5000).default(""),
gpx: z.string().optional(),
routeId: z.string().uuid().optional(),
startedAt: z.string().datetime().optional(),
routeId: z.uuid().optional(),
startedAt: z.iso.datetime().optional(),
duration: z.number().optional(),
distance: z.number().optional(),
});