Skip to content

Comments

refactor: migrate zod to arktype#167

Merged
iamEvanYT merged 3 commits intomainfrom
evan/migrate-zod-to-arktype
Oct 31, 2025
Merged

refactor: migrate zod to arktype#167
iamEvanYT merged 3 commits intomainfrom
evan/migrate-zod-to-arktype

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented Oct 31, 2025

  • Improve Speed
  • Reduce Bundle Size by about 3MB

Summary by CodeRabbit

  • Chores

    • Replaced Zod with Arktype as the project's data validation dependency and updated documentation.
  • Refactor

    • Reworked validation and parsing across profiles, spaces, icons, and shortcuts to use the new library.
    • Adjusted parsing/error handling and default-fallback behavior to align with the new validation API.
    • No changes to external/public function signatures or runtime behavior expected.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

Build artifacts for all platforms are ready! 🚀

Download the artifacts from:

(execution 18979648055 / attempt 1)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Migration of runtime/type validation from Zod to Arktype across code, docs, and package.json, updating schemas, parsing/error-check patterns, and related imports.

Changes

Cohort / File(s) Summary
Dependency & Docs
package.json, docs/contributing/dependencies.md
Removed zod (^3.24.4) and added arktype (^2.1.25); docs updated to list arktype as the data validation library.
Profiles controller
src/main/controllers/profiles-controller/raw.ts
Replaced z.object({...}) with type({...}); import changed from zod to arktype; type inference changed from z.infer<...> to typeof ... .infer.
Spaces controller
src/main/controllers/spaces-controller/raw.ts
Migrated SpaceDataSchema from Zod to Arktype (type({...})); optional fields expressed via `...
Icons module
src/main/modules/icons.ts
Replaced Zod enum with Arktype-based enum; switched from safeParse() to direct schema invocation and instanceof type.errors or .summary checks; preserved fallback/default icon behavior.
Shortcuts saving
src/main/saving/shortcuts.ts
Converted ModifiedShortcutData to Arktype type({...}); replaced safeParse usage with direct call and type.errors checks; removed .data extraction and adjusted error logging.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as Caller
  participant SchemaZ as ZodSchema
  participant SchemaA as ArktypeSchema
  Note over SchemaZ,SchemaA: Old vs New validation flow (per-call)

  rect rgba(200,230,255,0.4)
    Caller->>SchemaZ: safeParse(input)
    SchemaZ-->>Caller: { success: true/false, data?, error? }
    alt success
      Caller->>Caller: use parseResult.data
    else failure
      Caller->>Caller: handle parseResult.error
    end
  end

  rect rgba(200,255,200,0.4)
    Caller->>SchemaA: SchemaA(input)
    SchemaA-->>Caller: parsedResult (or type.errors)
    alt valid (not type.errors)
      Caller->>Caller: use parsedResult
    else invalid (instanceof type.errors)
      Caller->>Caller: handle parsedResult.summary
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Pay attention to differences in validation semantics for optional/union types in spaces-controller.
  • Review error-handling and logging changes in icons.ts and shortcuts.ts to ensure behavior parity.
  • Confirm exported type shapes remain compatible where used externally.

Possibly related PRs

Poem

🐰 I hopped from Zod to Arktype light,
schemas rewhiskered, validations bright,
errors summarized, defaults in place,
a nimble rabbit hops through type-space. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "refactor: migrate zod to arktype" directly and clearly describes the primary change across the entire changeset. The PR consistently replaces Zod with Arktype across multiple files including package.json, documentation, and several controller and module files. The title is concise, specific, and uses clear terminology that accurately conveys the migration objective stated in the PR description. There are no vague or generic terms, and the title is neither misleading nor off-topic relative to the actual changes made.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch evan/migrate-zod-to-arktype

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4514640 and daba7eb.

📒 Files selected for processing (2)
  • src/main/modules/icons.ts (5 hunks)
  • src/main/saving/shortcuts.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.{js,jsx,ts,tsx}: Use bun <file> instead of node <file> or ts-node <file>
Bun automatically loads .env, so don't use dotenv.
Use Bun.serve() for HTTP servers and WebSockets instead of express.
Use bun:sqlite for SQLite instead of better-sqlite3.
Use Bun.redis for Redis instead of ioredis.
Use Bun.sql for Postgres instead of pg or postgres.js.
Use built-in WebSocket instead of ws.
Prefer Bun.file over node:fs's readFile/writeFile.
Use Bun.$ for shell commands instead of execa.

Files:

  • src/main/modules/icons.ts
  • src/main/saving/shortcuts.ts
**/*.{html,ts,css}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

Use bun build <file.html|file.ts|file.css> instead of webpack or esbuild

Files:

  • src/main/modules/icons.ts
  • src/main/saving/shortcuts.ts
🧬 Code graph analysis (1)
src/main/modules/icons.ts (1)
src/main/modules/output.ts (2)
  • debugPrint (29-35)
  • debugError (37-45)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build (macos-15-intel)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: build (ubuntu-24.04-arm)
  • GitHub Check: format
  • GitHub Check: main-checks
🔇 Additional comments (9)
src/main/saving/shortcuts.ts (5)

3-3: LGTM! Import updated correctly.

The import statement correctly migrates from Zod to ArkType.


6-9: LGTM! Schema definition and type inference correct.

The ArkType schema definition and type inference pattern are correctly implemented. The schema properly defines a string property, and the type inference uses the correct ArkType pattern.


31-38: LGTM! ArkType validation pattern correctly implemented.

The validation logic correctly uses ArkType's error checking pattern. The code properly:

  • Calls the validator directly as a function
  • Checks for errors using instanceof type.errors
  • Uses the parse result directly as validated data (not .data property)
  • Accesses error details via .summary

50-55: LGTM! Validation correctly handles error cases.

The validation logic correctly implements the ArkType pattern with an early return on error. The validated data is properly used directly from the parse result.


31-38: ArkType migration is complete and structurally sound.

Verification confirms:

  • No remaining Zod imports (migration complete)
  • Consistent instanceof type.errors pattern across 4 files
  • Schema correctly validates newShortcut as string type
  • ArkType's "string" type handles edge cases as expected: accepts empty strings, rejects null/undefined and non-strings
  • Error messages use parseResult.summary for ArkType's built-in error formatting

The implementation at lines 31-38 and 50-55 follows proper ArkType conventions. No issues detected.

src/main/modules/icons.ts (4)

6-6: LGTM!

The import correctly brings in Arktype's type function for schema definition and validation.


110-111: LGTM!

The schema definition correctly creates an enumerated type from the icon IDs. The intermediate iconIds array works correctly. As noted in previous reviews, this could be inlined for brevity, but the current approach is clear and maintainable.


245-256: LGTM!

The Arktype validation pattern is correctly implemented:

  • Calls the schema as a function to validate
  • Uses instanceof type.errors to check for validation failure
  • Accesses parseResult.summary for error details in the failure case
  • Appropriately falls back to the default icon when validation fails

The error handling is robust with the try-catch wrapper ensuring safe fallback behavior.


271-288: LGTM!

The validation logic correctly uses the same Arktype pattern as cacheCurrentIcon, ensuring consistency across the module. The function appropriately:

  • Validates the icon ID before persisting
  • Returns true on successful validation and persistence
  • Returns false on validation failure or storage error
  • Logs errors with detailed messages using parseResult.summary

The boolean return value provides a clear success/failure signal for callers.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@iamEvanYT iamEvanYT marked this pull request as ready for review October 31, 2025 16:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b71462 and 4514640.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • docs/contributing/dependencies.md (1 hunks)
  • package.json (2 hunks)
  • src/main/controllers/profiles-controller/raw.ts (2 hunks)
  • src/main/controllers/spaces-controller/raw.ts (2 hunks)
  • src/main/modules/icons.ts (5 hunks)
  • src/main/saving/shortcuts.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.{js,jsx,ts,tsx}: Use bun <file> instead of node <file> or ts-node <file>
Bun automatically loads .env, so don't use dotenv.
Use Bun.serve() for HTTP servers and WebSockets instead of express.
Use bun:sqlite for SQLite instead of better-sqlite3.
Use Bun.redis for Redis instead of ioredis.
Use Bun.sql for Postgres instead of pg or postgres.js.
Use built-in WebSocket instead of ws.
Prefer Bun.file over node:fs's readFile/writeFile.
Use Bun.$ for shell commands instead of execa.

Files:

  • src/main/controllers/spaces-controller/raw.ts
  • src/main/modules/icons.ts
  • src/main/controllers/profiles-controller/raw.ts
  • src/main/saving/shortcuts.ts
**/*.{html,ts,css}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

Use bun build <file.html|file.ts|file.css> instead of webpack or esbuild

Files:

  • src/main/controllers/spaces-controller/raw.ts
  • src/main/modules/icons.ts
  • src/main/controllers/profiles-controller/raw.ts
  • src/main/saving/shortcuts.ts
package.json

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

package.json: Use bun install instead of npm install or yarn install or pnpm install
Use bun run <script> instead of npm run <script> or yarn run <script> or pnpm run <script>

Files:

  • package.json
🧬 Code graph analysis (1)
src/main/modules/icons.ts (1)
src/main/modules/output.ts (2)
  • debugPrint (29-35)
  • debugError (37-45)
🔇 Additional comments (13)
docs/contributing/dependencies.md (1)

26-26: LGTM! Documentation updated correctly.

The documentation accurately reflects the dependency change from zod to arktype, and the entry maintains the required A-Z sorting.

src/main/controllers/spaces-controller/raw.ts (2)

6-6: LGTM! Arktype import added correctly.

The import statement properly brings in the type function from arktype for schema definition.


28-37: LGTM! Schema migration to arktype is correct.

The schema migration from Zod to Arktype is properly implemented:

  • Schema definition using type({ ... }) syntax
  • Type inference updated to typeof SpaceDataSchema.infer
  • Union types for optional properties correctly expressed using pipe operator
src/main/modules/icons.ts (3)

6-6: LGTM! Arktype import added correctly.


245-256: LGTM! Validation logic migrated correctly.

The validation logic has been properly updated to use arktype's validation pattern:

  • Direct invocation IconIdSchema(iconId) instead of safeParse
  • Correct error checking using instanceof type.errors
  • Error message extraction using toString()
  • Fallback to default icon preserved

271-288: LGTM! Validation logic consistent with cacheCurrentIcon.

The validation pattern matches the implementation in cacheCurrentIcon, correctly using arktype's error handling approach.

src/main/controllers/profiles-controller/raw.ts (2)

7-7: LGTM! Arktype import added correctly.


33-37: LGTM! Schema migration to arktype is correct.

The ProfileDataSchema has been properly migrated from Zod to Arktype:

  • Schema definition using type({ ... }) syntax
  • Type inference updated to typeof ProfileDataSchema.infer
  • Property types correctly specified as strings
src/main/saving/shortcuts.ts (4)

3-3: LGTM! Arktype import added correctly.


6-9: LGTM! Schema and type definition migrated correctly.

The ModifiedShortcutData schema has been properly converted to arktype syntax with correct type inference.


31-38: LGTM! Validation logic migrated correctly.

The validation logic properly uses arktype's error handling pattern:

  • Direct invocation instead of safeParse
  • Correct error checking with instanceof type.errors
  • Error logging with toString()

50-55: LGTM! Validation logic consistent across the file.

The validation pattern matches the implementation in loadShortcuts, correctly using arktype's error handling approach.

package.json (1)

37-37: Arktype version verified as current.

The specified version 2.1.25 matches the latest version available on npm registry. The semver constraint ^2.1.25 appropriately allows for compatible updates while maintaining stability.

@iamEvanYT
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@iamEvanYT iamEvanYT merged commit 05ee924 into main Oct 31, 2025
10 checks passed
@iamEvanYT iamEvanYT deleted the evan/migrate-zod-to-arktype branch October 31, 2025 17:21
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