Refactor route search params validation using Zod schemas

Co-authored-by: natemkelley <natemkelley@gmail.com>
This commit is contained in:
Cursor Agent 2025-08-15 13:48:37 +00:00
parent 080dcc8cf5
commit 7e5e3ae63e
14 changed files with 74 additions and 142 deletions

View File

@ -1,22 +1,15 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
metric_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/chats/$chatId/dashboard/$dashboardId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,18 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/chats/$chatId/dashboard/$dashboardId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,16 +1,12 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
metric_version_number?: number
}
const searchParamsSchema = z.object({
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute('/app/chats/$chatId/metrics/$metricId')({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,22 +1,15 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
report_version_number?: number
metric_version_number?: number
}
const searchParamsSchema = z.object({
report_version_number: z.coerce.number().optional(),
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/chats/$chatId/report/$reportId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
report_version_number: search.report_version_number
? Number(search.report_version_number)
: undefined,
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,16 +1,12 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
report_version_number?: number
}
const searchParamsSchema = z.object({
report_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute('/app/chats/$chatId/report/$reportId')({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
report_version_number: search.report_version_number
? Number(search.report_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,22 +1,15 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
metric_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/chats/$chatId/dashboards/$dashboardId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,18 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/chats/$chatId/dashboards/$dashboardId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,18 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
metric_version_number?: number
}
const searchParamsSchema = z.object({
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/chats/$chatId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,22 +1,15 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
metric_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/dashboard/$dashboardId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,18 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
dashboard_version_number?: number
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/dashboard/$dashboardId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,18 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
// Search params interface for type safety
interface RouteSearch {
metric_version_number?: number
}
const searchParamsSchema = z.object({
metric_version_number: z.coerce.number().optional(),
})
export const Route = createFileRoute(
'/app/collections/$collectionId/metrics/$metricId',
)({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
})

View File

@ -1,16 +1,12 @@
import { createFileRoute } from '@tanstack/react-router';
import { z } from 'zod';
// Search params interface for type safety
interface DashboardSearch {
dashboard_version_number?: number;
}
const searchParamsSchema = z.object({
dashboard_version_number: z.coerce.number().optional(),
});
export const Route = createFileRoute('/app/dashboards/$dashboardId')({
validateSearch: (search: Record<string, unknown>): DashboardSearch => ({
dashboard_version_number: search.dashboard_version_number
? Number(search.dashboard_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
});

View File

@ -1,16 +1,12 @@
import { createFileRoute } from '@tanstack/react-router';
import { z } from 'zod';
// Search params interface for type safety
interface RouteSearch {
metric_version_number?: number;
}
const searchParamsSchema = z.object({
metric_version_number: z.coerce.number().optional(),
});
export const Route = createFileRoute('/app/metrics/$metricId')({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
metric_version_number: search.metric_version_number
? Number(search.metric_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
});

View File

@ -1,16 +1,12 @@
import { createFileRoute } from '@tanstack/react-router';
import { z } from 'zod';
// Search params interface for type safety
interface RouteSearch {
report_version_number?: number;
}
const searchParamsSchema = z.object({
report_version_number: z.coerce.number().optional(),
});
export const Route = createFileRoute('/app/reports/$reportId')({
validateSearch: (search: Record<string, unknown>): RouteSearch => ({
report_version_number: search.report_version_number
? Number(search.report_version_number)
: undefined,
}),
validateSearch: searchParamsSchema,
component: RouteComponent,
});