Code Review Bench PR #26717 - refactor: Remove trpc/server dependency from @calcom/atoms#14
Conversation
| id: number; | ||
| userId: number | null; | ||
| eventTypeId: number | null; | ||
| days: string[]; |
There was a problem hiding this comment.
🚨 Bug: days: string[] contradicts Prisma schema days Int[]
The Prisma schema defines Availability.days as Int[] (see packages/prisma/schema.prisma), and every other usage in the codebase types days as number[] (e.g., packages/lib/schedules/transformers/getScheduleListItemData.ts, packages/types/schedule.d.ts, packages/platform/atoms/availability/AvailabilitySettings.tsx, packages/platform/atoms/availability/types.ts, packages/features/availability/lib/getUserAvailability.ts).
Changing this to string[] in the atoms package creates a type mismatch between what the API/database actually returns (integer arrays like [0, 1, 2, 3, 4] for weekdays) and what this type declares. This will cause TypeScript compilation errors or silent type unsafety at the boundary where this data is consumed.
Was this helpful? React with 👍 / 👎
| days: string[]; | |
| days: number[]; | |
- Apply suggested fix
| bookingUid?: string; | ||
| away?: boolean; | ||
| fromUser?: { | ||
| id: string; |
There was a problem hiding this comment.
🚨 Bug: fromUser.id: string contradicts source IFromUser.id: number
The SlotInfo.fromUser.id field is typed as string, but the source of truth IFromUser interface in packages/features/availability/lib/getUserAvailability.ts defines id: number. The slot data flows from getUserAvailability → slots.ts → the API response, and at every step the fromUser.id is a numeric user ID from the database.
Interestingly, toUser.id on the very next line in the same SlotInfo type is correctly typed as number, making this an internal inconsistency. This will cause consumers of the atoms package to expect a string where a number is actually returned, leading to subtle bugs (e.g., fromUser.id === someStringId would fail with strict equality).
Was this helpful? React with 👍 / 👎
| id: string; | |
| id: number; | |
- Apply suggested fix
|
|
||
| export type Slot = { | ||
| time: string; | ||
| userIds?: string[]; |
There was a problem hiding this comment.
🚨 Bug: Slot.userIds: string[] contradicts upstream number[] type
The Slot.userIds field was changed from number[] to string[], but the upstream code that produces this data (in packages/features/schedules/lib/slots.ts) consistently types userIds as number[]. The TimeFrame type is { userIds?: number[]; startTime: number; endTime: number }, and all slot generation code works with numeric user IDs.
The original type in packages/trpc/server/routers/viewer/slots/types.ts (being deleted in this PR) had userIds?: number[]. Changing this to string[] in the atoms package means the type no longer matches the actual runtime data, which will cause type errors for any code that tries to use both the atom types and the internal slot types together (e.g., apps/web/test/lib/getSchedule/expects.ts which now imports from @calcom/atoms/booker/types).
Was this helpful? React with 👍 / 👎
| userIds?: string[]; | |
| userIds?: number[]; | |
- Apply suggested fix
| eventTypeId?: number; | ||
| }; | ||
|
|
||
| export function validateCreateScheduleInput(input: unknown): CreateScheduleInput { |
There was a problem hiding this comment.
⚠️ Edge Case: validateCreateScheduleInput doesn't validate schedule or eventTypeId
The validation function only checks that name is a non-empty string, then casts the entire object to CreateScheduleInput via as. This means the schedule and eventTypeId fields are completely unvalidated — a caller could pass { name: "foo", schedule: "not-an-array", eventTypeId: "not-a-number" } and it would be returned as a valid CreateScheduleInput.
The original implementation used a Zod schema (ZCreateInputSchema) that validated all fields including the nested schedule array structure (z.array(z.array(z.object({ start: z.date(), end: z.date() })))) and eventTypeId as z.number().optional().
Since this function's purpose is to provide runtime validation for external npm package consumers, the unsafe as cast defeats that goal. Consider either:
- Adding validation for
scheduleandeventTypeIdfields - Documenting that only
nameis validated - Using a schema validation library (the atoms package could add a lightweight one)
Was this helpful? React with 👍 / 👎
- Apply suggested fix
| "./add-members-switch/AddMembersWithSwitchPlatformWrapper": "./add-members-switch/AddMembersWithSwitchPlatformWrapper.tsx", | ||
| "./availability/AvailabilitySettings": "./availability/AvailabilitySettings.tsx", | ||
| "./booker": "./booker/index.ts", | ||
| "./booker/types": "./booker/types.ts", |
There was a problem hiding this comment.
⚠️ Bug: Package export changed from ./booker to ./booker/types (breaking)
The package.json exports map was changed from "./booker": "./booker/index.ts" to "./booker/types": "./booker/types.ts". This is a breaking change for any external consumer of the @calcom/atoms npm package who imports from @calcom/atoms/booker.
While the test file in this repo (apps/web/test/lib/getSchedule/expects.ts) was updated to use the new path @calcom/atoms/booker/types, external consumers won't get that update automatically. Since @calcom/atoms is a published npm package (currently at v2.2.0), this would require a major version bump per semver conventions.
Note: If the ./booker export was only used internally and the main "." export already re-exports the booker module, this may be less impactful. But as written, this removes a previously available import path.
Was this helpful? React with 👍 / 👎
- Apply suggested fix
There was a problem hiding this comment.
Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.
Code Review 🚫 Blocked 0 resolved / 5 findingsThree type changes ( 🚨 Bug:
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
Benchmark PR for Gitar evaluation
Original PR: agentic-review-benchmarks#15
refactor: Remove trpc/server dependency from @calcom/atoms
Summary by Gitar
userIdsandfromUser.idfromnumbertostringinpackages/platform/atoms/booker/types.tsdaysfromnumber[]tostring[]inpackages/platform/atoms/hooks/schedules/types.tsvalidateCreateScheduleInputinpackages/platform/atoms/hooks/schedules/types.tsprovides runtime validation for schedule creationThis will update automatically on new commits.