Skip to content

Commit 201075e

Browse files
committed
fix(rpc): type listSchedules output for uptime monitors
Replace loose record schema with structured Zod output so oRPC infers MonitorLight from listSchedules; remove unsafe cast in useMonitorsLight.
1 parent 4c0ae1f commit 201075e

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

apps/dashboard/hooks/use-monitors.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
import { useQuery } from "@tanstack/react-query";
44
import { orpc } from "@/lib/orpc";
55

6-
export interface MonitorLight {
7-
id: string;
8-
name: string | null;
9-
url: string | null;
10-
websiteId: string | null;
11-
website: {
12-
id: string;
13-
name: string | null;
14-
domain: string;
15-
} | null;
16-
}
17-
186
export function useMonitorsLight(options?: { enabled?: boolean }) {
197
const query = useQuery({
208
...orpc.uptime.listSchedules.queryOptions({ input: {} }),
@@ -23,7 +11,11 @@ export function useMonitorsLight(options?: { enabled?: boolean }) {
2311
});
2412

2513
return {
26-
monitors: (query.data ?? []) as MonitorLight[],
14+
monitors: query.data ?? [],
2715
isLoading: query.isLoading,
2816
};
2917
}
18+
19+
export type MonitorLight = ReturnType<
20+
typeof useMonitorsLight
21+
>["monitors"][number];

packages/rpc/src/routers/uptime.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ const getScheduleOutputSchema = z
115115

116116
const scheduleOutputSchema = z.record(z.string(), z.unknown());
117117

118+
const listScheduleItemSchema = getScheduleOutputSchema
119+
.omit({ qstashStatus: true })
120+
.loose();
121+
118122
export const uptimeRouter = {
119123
getScheduleByWebsiteId: protectedProcedure
120124
.route({
@@ -159,7 +163,7 @@ export const uptimeRouter = {
159163
})
160164
.default({})
161165
)
162-
.output(z.array(scheduleOutputSchema))
166+
.output(z.array(listScheduleItemSchema))
163167
.handler(async ({ context, input }) => {
164168
const orgId = input.organizationId ?? context.organizationId;
165169

0 commit comments

Comments
 (0)