Repository navigation
chore: remove zod deprecates, chore: drizzle and fix: dashboard port - #86
Conversation
- updated the schemas/dtos across the codebase to remove the deprecated apis and use the new recommended ways by zod v4
- added npm commands to generate and execute migrations for `drizzle-kit` - updated the pgTable call in the schemas from the deprecated way to the new one recommended
- in the `openDashboard` function, the port is got dynamically using the `getDashboardPort` function, and the `dashboardUrl` is inferred from that (i.e it is not necessary the constant port since it can be busy and we have a "find near available port logic") - in the `coding-stats-dashboard.service.ts`, in the `getPeriodGeneralStats`, the mean is calculated using Math.floor before being passed to the formatDuration function to avoid decimal secs
WalkthroughThis set of changes primarily updates schema validation logic across multiple files to use more concise Zod helper methods (e.g., Changes
Sequence Diagram(s)sequenceDiagram
participant VSCodeExt as VSCode Extension
participant Dashboard as Local Dashboard
VSCodeExt->>VSCodeExt: getDashboardPort()
VSCodeExt->>VSCodeExt: Construct dashboard URL (http://localhost:<port>)
VSCodeExt->>VSCodeExt: vscode.env.openExternal(dashboard URL)
VSCodeExt->>VSCodeExt: Show success message with dashboard URL
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🔭 Outside diff range comments (1)
packages/common/src/schemas.ts (1)
4-26:z.email()andz.jwt()helpers may not exist in Zod 4.0.14Unlike
z.ulid(), the helpers for email and JWT are not part of the published Zod API (as of 4.0.x). Compilation will fail unless you have a local augmentation.If you intended to use string refinements, fall back to:
- email: z.email(), + email: z.string().email(),and replace
z.jwt()with the previous validator (regex orz.string().jwt()if you have an extension).Please verify or bump the Zod version accordingly.
♻️ Duplicate comments (2)
apps/api/src/languages/languages.dto.ts (1)
4-15: Samez.ulid()version-compatibility caveat applies hereAll three DTOs rely on
z.ulid(). Verify availability as noted in the previous comment to avoid runtime/type errors.apps/api/src/common/dto.ts (1)
19-19: Align generic constraint with the fix aboveOnce the full generic form of
ZodTypeis adopted (see Line 1 comment), update both signatures consistently:- schema: ZodType<T, unknown, T>, + schema: ZodType<T, unknown, T>,(Shown for emphasis; adjust in both functions.)
Also applies to: 27-27
🧹 Nitpick comments (2)
apps/api/package.json (1)
15-16: Prefer relying on the workspace-installeddrizzle-kitinstead ofnpxfor version safetyUsing
npx drizzle-kitwill execute whatever version is first in the user’s PATH (or download the latest), which can silently diverge from the devDependency ("drizzle-kit": "^0.31.4"). Invoking the local binary ("drizzle-kit") guarantees the project-pinned version is used in CI and by all contributors.- "generate": "npx drizzle-kit generate", - "migrate": "npx drizzle-kit migrate", + "generate": "drizzle-kit generate", + "migrate": "drizzle-kit migrate",If you still need
npx(e.g. when the package is not installed), add--no-installto force it to fail instead of downloading a random version.apps/api/src/common/dto.ts (1)
1-1: Prefer explicit generics to avoid accidental widening
ZodTypeis correct in v4, but using the bareZodType<T>keeps the input and output generic parameters asunknown, which silently turns off some type-safety.
Consider narrowing the type with the full 3-parameter form to preserve the original input/output symmetry:- schema: ZodType<T>, + schema: ZodType<T, unknown, T>,Same applies to Line 27.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (20)
apps/api/package.json(1 hunks)apps/api/src/coding-stats/coding-stats-dashboard.service.ts(1 hunks)apps/api/src/common/dto.ts(2 hunks)apps/api/src/daily-data/daily-data.dto.ts(1 hunks)apps/api/src/drizzle/schema/dailyData.ts(1 hunks)apps/api/src/drizzle/schema/files.ts(1 hunks)apps/api/src/drizzle/schema/languages.ts(1 hunks)apps/api/src/drizzle/schema/projects.ts(1 hunks)apps/api/src/files-stats/files-stats.dto.ts(1 hunks)apps/api/src/files/files.dto.ts(1 hunks)apps/api/src/filters/errorFormatter.ts(1 hunks)apps/api/src/languages/languages.dto.ts(1 hunks)apps/api/src/projects/projects.dto.ts(2 hunks)apps/api/src/users/users.dto.ts(2 hunks)apps/dashboard/src/hooks/useSafeParams.tsx(1 hunks)apps/vscode-extension/src/types-schemas.ts(2 hunks)apps/vscode-extension/src/utils/auth/storeJWTToken.ts(1 hunks)apps/vscode-extension/src/utils/dashboard/openDashboard.ts(1 hunks)packages/common/src/constants.ts(0 hunks)packages/common/src/schemas.ts(2 hunks)
💤 Files with no reviewable changes (1)
- packages/common/src/constants.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in zod v4, the $zodissue types are officially available at the import path "zod/v4/core/errors.cjs" ...
Learnt from: Friedrich482
PR: Friedrich482/mooncode#85
File: apps/api/src/filters/errorFormatter.ts:1-1
Timestamp: 2025-08-06T20:22:58.898Z
Learning: In Zod v4, the $ZodIssue types are officially available at the import path "zod/v4/core/errors.cjs" as part of the new module structure. This is the correct way to import these types in v4, not an internal or fragile import path.
Applied to files:
apps/dashboard/src/hooks/useSafeParams.tsxapps/api/src/filters/errorFormatter.tspackages/common/src/schemas.tsapps/api/src/languages/languages.dto.tsapps/api/src/files/files.dto.tsapps/api/src/common/dto.tsapps/api/src/projects/projects.dto.ts
🔇 Additional comments (17)
apps/api/src/coding-stats/coding-stats-dashboard.service.ts (1)
288-288: LGTM! Good fix for duration formatting.Applying
Math.floorto the mean calculation prevents decimal seconds from being passed toformatDuration, which likely improves the user experience by showing clean average durations. The minimal precision loss in percentage calculations (line 301) is acceptable for this use case.apps/vscode-extension/src/utils/dashboard/openDashboard.ts (3)
2-2: LGTM!Clean import addition that supports the dynamic port determination functionality.
10-10: LGTM!Correct usage of the dynamically constructed dashboard URL.
14-14: LGTM!Great improvement - users now see the actual URL with the dynamic port in the success message, which is more informative.
apps/api/src/drizzle/schema/projects.ts (1)
22-26: LGTM! Modern Drizzle index syntax.The conversion from object-based to array-based index declarations is a valid modernization that aligns with current Drizzle ORM best practices while maintaining identical functionality.
apps/vscode-extension/src/types-schemas.ts (2)
20-20: LGTM! Simplified Zod datetime validation.The replacement of
z.string().min(1).datetime()withz.iso.datetime()is a valid modernization that uses the more concise Zod API while maintaining identical validation behavior.
41-41: LGTM! Consistent datetime validation simplification.Same improvement as line 20 - using the modern
z.iso.datetime()API for cleaner, more readable validation.apps/api/src/drizzle/schema/dailyData.ts (1)
21-24: LGTM! Consistent index syntax modernization.This follows the same valid pattern of converting to array-based index declarations as seen in other schema files, maintaining functionality while using modern Drizzle syntax.
apps/api/src/drizzle/schema/files.ts (1)
26-31: LGTM! Consistent schema modernization.The conversion to array-based index declarations follows the same valid pattern applied across all schema files, maintaining identical functionality with modern Drizzle syntax.
apps/api/src/filters/errorFormatter.ts (1)
1-1: LGTM! Clean import consolidation.Consolidating the
ZodErrorandzimports from the same package is a good practice that improves code organization without affecting functionality.apps/api/src/daily-data/daily-data.dto.ts (1)
6-19: Confirmz.ulid()support in Zod v4.0.14
The previous check failed because it ran outside your workspace and couldn’t locate thezodpackage. Please verify in your project context:• From your repo (e.g.
apps/api), run:npm ls zod node -e "console.log(require('zod').ulid !== undefined)"• If
ulidis not exported in v4.0.14, either upgrade Zod or revert to the stable helper:z.string().ulid()apps/api/src/users/users.dto.ts (1)
11-11: LGTM! Zod API modernization correctly implemented.The replacement of deprecated
z.string().ulid()withz.ulid()andz.string().email()withz.email()maintains the same validation behavior while using the more concise Zod v4 API. The custom error message for email validation is properly preserved.Also applies to: 15-15, 19-20, 32-32
apps/api/src/files/files.dto.ts (1)
4-5: LGTM! Consistent Zod API modernization across all DTOs.All instances of
z.string().ulid()have been correctly replaced withz.ulid()across the DTO schemas. The validation behavior remains identical while using the more concise Zod v4 API.Also applies to: 12-13, 20-21, 27-27
apps/vscode-extension/src/utils/auth/storeJWTToken.ts (1)
9-9: z.jwt() correctly enforces non-empty and valid JWTsTests against Zod v4.0.15 confirm:
- Empty string (
"") fails with{ code: "invalid_format", format: "jwt" }- Arbitrary non-JWT string (
"invalid") fails likewise- Well-formed JWT passes and returns the token
The replacement of
z.string().min(1).pipe(jwt())withz.jwt()is safe and maintains the intended error behavior. No further changes needed.apps/api/src/drizzle/schema/languages.ts (1)
21-24: Array-Based Index Syntax Aligns with Drizzle ORM Best PracticesThe switch from object-based to array-based index definitions in
apps/api/src/drizzle/schema/languages.ts(lines 21–24) matches the latest Drizzle ORM guidance, where object-based syntax is now deprecated and may emit warnings. No further changes are required here.apps/api/src/files-stats/files-stats.dto.ts (1)
36-39: LGTM! Schema composition modernized with object spread syntax.The replacement of
.merge()and.extend()methods with explicit object spread syntax (...Schema.shape) maintains identical validation behavior while using a more modern and explicit composition approach. This change improves readability and aligns with current JavaScript best practices.Also applies to: 43-46, 51-53
apps/api/src/projects/projects.dto.ts (1)
5-5: Good switch toz.ulid()Replacing
z.string().ulid()with the dedicated helper reduces boilerplate and prevents accidental additional string constraints.Also applies to: 12-12, 19-19, 25-25, 32-32
Commits
chore: remove zod deprecates
chore: drizzle
drizzle-kitpgTablecall in the schemas from the deprecated way to the new recommended wayfix: dashboard port
openDashboardfunction, the port is got dynamically using thegetDashboardPortfunction, and thedashboardUrlis inferred from that (i.e it is not necessary the constant port since it can be busy and we have a "find near available port logic")coding-stats-dashboard.service.ts, in thegetPeriodGeneralStats, the mean is calculated using Math.floor before being passed to the formatDuration function to avoid decimal secsSummary by CodeRabbit
Refactor
z.string().ulid(),z.string().email(),z.string().jwt()) with concise shorthand methods (z.ulid(),z.email(),z.jwt()) across multiple forms and DTOs.Style
Chores