Skip to content

chore: remove zod deprecates, chore: drizzle and fix: dashboard port - #86

Merged
Friedrich482 merged 3 commits into
mainfrom
features
Aug 6, 2025
Merged

Friedrich482 merged 3 commits into
mainfrom
features

Conversation

@Friedrich482

@Friedrich482 Friedrich482 commented Aug 6, 2025 •

Copy link
Copy Markdown
Owner

Commits

  • chore: remove zod deprecates

    • updated the schemas/dtos across the codebase to remove the deprecated apis and use the new recommended ways by zod v4
  • chore: drizzle

    • 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 recommended way
  • fix: dashboard port

    • 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

Summary by CodeRabbit

  • Refactor

    • Simplified validation schemas by replacing chained string validations (e.g., z.string().ulid(), z.string().email(), z.string().jwt()) with concise shorthand methods (z.ulid(), z.email(), z.jwt()) across multiple forms and DTOs.
    • Updated schema composition to use object spread syntax for combining validation schemas, improving readability.
    • Adjusted date-time and JWT validation to use more direct and robust schema helpers.
    • Removed an unused dashboard URL constant and updated dashboard URL handling to be determined dynamically at runtime.
  • Style

    • Streamlined import statements for better clarity and consistency.
  • Chores

    • Added new npm script commands for database generation and migration tasks.

 - 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
@coderabbitai

coderabbitai Bot commented Aug 6, 2025 •

Copy link
Copy Markdown

Walkthrough

This set of changes primarily updates schema validation logic across multiple files to use more concise Zod helper methods (e.g., z.ulid(), z.email(), z.jwt(), z.iso.datetime()) instead of chaining from z.string(). Several index definitions in Drizzle ORM schemas are refactored from object to array format. Some DTO schemas now use object spread for composition rather than .merge() or .extend(). There are also minor script additions, import consolidations, and the removal of the DASHBOARD_URL constant.

Changes

Cohort / File(s) Change Summary
Zod Schema Simplification
apps/api/src/daily-data/daily-data.dto.ts, apps/api/src/files/files.dto.ts, apps/api/src/languages/languages.dto.ts, apps/api/src/projects/projects.dto.ts, apps/api/src/users/users.dto.ts, packages/common/src/schemas.ts, apps/vscode-extension/src/types-schemas.ts
Replaced z.string().ulid(), z.string().email(), and similar with concise helpers like z.ulid(), z.email(), z.jwt(), and z.iso.datetime(). No changes to validation logic or DTO signatures.
Schema Composition Refactor
apps/api/src/files-stats/files-stats.dto.ts, apps/api/src/common/dto.ts, apps/api/src/projects/projects.dto.ts
Changed schema composition from .merge()/.extend() to object spread syntax, and updated Zod type imports from ZodSchema to ZodType. Some function signatures updated to use ZodType<T>.
Drizzle ORM Index Declaration Refactor
apps/api/src/drizzle/schema/dailyData.ts, apps/api/src/drizzle/schema/files.ts, apps/api/src/drizzle/schema/languages.ts, apps/api/src/drizzle/schema/projects.ts
Changed table index definitions from object with named properties to arrays of index definitions. No changes to index targets or names.
Script Additions
apps/api/package.json
Added generate and migrate npm scripts using npx drizzle-kit.
Import Cleanup
apps/api/src/filters/errorFormatter.ts, apps/dashboard/src/hooks/useSafeParams.tsx
Consolidated or updated import statements for Zod types. Updated hook generic parameter to use ZodType<T>.
Dashboard URL Handling
apps/vscode-extension/src/utils/dashboard/openDashboard.ts, packages/common/src/constants.ts
Removed DASHBOARD_URL constant; dashboard URL is now constructed dynamically using a runtime port.
JWT Validation Simplification
apps/vscode-extension/src/utils/auth/storeJWTToken.ts
Simplified JWT validation by using z.jwt() directly instead of first validating as a non-empty string.
Stats Calculation Update
apps/api/src/coding-stats/coding-stats-dashboard.service.ts
Changed average time calculation from floating-point to integer using Math.floor.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A bunny hopped through Zod’s green fields,
Swapping strings for helpers—oh, what yields!
Indexes now march in tidy arrays,
Scripts and imports got a lighter phase.
The dashboard hops by port, not name—
This code review’s a breezy game! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch features

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Friedrich482 Friedrich482 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes reviewed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🔭 Outside diff range comments (1)
packages/common/src/schemas.ts (1)

4-26: z.email() and z.jwt() helpers may not exist in Zod 4.0.14

Unlike 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 or z.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: Same z.ulid() version-compatibility caveat applies here

All 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 above

Once the full generic form of ZodType is 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-installed drizzle-kit instead of npx for version safety

Using npx drizzle-kit will 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-install to 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

ZodType is correct in v4, but using the bare ZodType<T> keeps the input and output generic parameters as unknown, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 06312bf and a9763b6.

📒 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.tsx
  • apps/api/src/filters/errorFormatter.ts
  • packages/common/src/schemas.ts
  • apps/api/src/languages/languages.dto.ts
  • apps/api/src/files/files.dto.ts
  • apps/api/src/common/dto.ts
  • apps/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.floor to the mean calculation prevents decimal seconds from being passed to formatDuration, 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() with z.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 ZodError and z imports 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: Confirm z.ulid() support in Zod v4.0.14
The previous check failed because it ran outside your workspace and couldn’t locate the zod package. 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 ulid is 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() with z.ulid() and z.string().email() with z.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 with z.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 JWTs

Tests 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()) with z.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 Practices

The 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 to z.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

Comment thread apps/api/src/common/dto.ts
Comment thread apps/api/src/projects/projects.dto.ts
Comment thread apps/dashboard/src/hooks/useSafeParams.tsx
Comment thread apps/vscode-extension/src/utils/dashboard/openDashboard.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant