Skip to content

Improve various types #1919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Apr 9, 2025

Pull Request

What does this PR do?

  • improved and/or documented various types and methods

Migration

  • type Health -> HealthResponse
  • type Version -> VersionResponse
- import { ErrorStatusCode } from "meilisearch";
- ErrorStatusCode.INVALID_API_KEY;
+ import type { Code } from "meilisearch";
+ const myErrorCode: Code = "invalid_api_key";

Summary by CodeRabbit

  • New Features

    • Introduced strongly-typed error response structures for clearer error handling.
    • Added new types for health status, index stats, overall stats, and version responses aligned with official API specs.
  • Refactor

    • Replaced enum-based error codes with string literals across code and tests for consistency.
    • Updated method signatures and internal type usage to leverage new response types.
    • Enhanced documentation by linking directly to official Meilisearch API references.
  • Bug Fixes

    • Improved test reliability by standardizing error code assertions with string literals.
  • Chores

    • Removed deprecated types, enums, and unused imports to streamline the codebase.
    • Updated numerous test suites to reflect the new error handling and type system.

@flevi29 flevi29 mentioned this pull request Apr 9, 2025
8 tasks
Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.16%. Comparing base (77505c0) to head (9617de8).

Files with missing lines Patch % Lines
src/meilisearch.ts 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1919      +/-   ##
==========================================
+ Coverage   99.03%   99.16%   +0.12%     
==========================================
  Files          18       18              
  Lines        1449     1315     -134     
  Branches      305      305              
==========================================
- Hits         1435     1304     -131     
+ Misses         14       11       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flevi29 flevi29 added the breaking-change The related changes are breaking for the users label Apr 9, 2025
@flevi29 flevi29 marked this pull request as ready for review April 9, 2025 20:36
@Strift Strift requested a review from Copilot April 21, 2025 06:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves and documents various types and methods, with a focus on renaming types (e.g. Health to HealthResponse and Version to VersionResponse) and replacing inline error code references with string literals.

  • Migrates error codes from ErrorStatusCode enums to inline string literals for improved type safety and clarity
  • Updates documentation comments in source files and refines type definitions
  • Adjusts tests accordingly to match the new error code format

Reviewed Changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated no comments.

File Description
tests/* Replaces ErrorStatusCode with explicit string literals
src/types/* and src/errors/* Updates type names and documentation per migration requirements
src/meilisearch.ts and src/indexes.ts Migrates API responses and error handling to new type definitions
Comments suppressed due to low confidence (2)

tests/get_search.test.ts:551

  • [nitpick] Consider centralizing error code string literals into a shared constant or module rather than using inline strings throughout tests. This can help reduce duplication, avoid potential typos, and simplify future updates.
).rejects.toHaveProperty("cause.code", "index_not_found");

src/meilisearch.ts:187

  • [nitpick] Consider centralizing the error code string literals (e.g., "index_not_found") into a dedicated constants module to ensure consistency and maintainability across both production and test code.
if ((e as MeiliSearchApiError)?.cause?.code === "index_not_found") {

@flevi29
Copy link
Collaborator Author

flevi29 commented Apr 26, 2025

tests/get_search.test.ts:551

* [nitpick] Consider centralizing error code string literals into a shared constant or module rather than using inline strings throughout tests. This can help reduce duplication, avoid potential typos, and simplify future updates.
).rejects.toHaveProperty("cause.code", "index_not_found");

src/meilisearch.ts:187

* [nitpick] Consider centralizing the error code string literals (e.g., "index_not_found") into a dedicated constants module to ensure consistency and maintainability across both production and test code.
if ((e as MeiliSearchApiError)?.cause?.code === "index_not_found") {

I believe TypeScript should be a good enough guarantor that we're using the right literals. Having a huge record object containing these constants isn't necessary, and may increase bundle size if not tree shaken by a non-trivial amount. Even bare JavaScript doesn't have literal-constant-containing-records for things like this.

Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

This update refactors error handling and type definitions across the codebase. It introduces new, strongly-typed modules for error, health, stats, and version responses, replacing older, less precise types and enums. All usages of error code enums are replaced with string literals. Test suites are updated to assert against these string error codes, and type imports are streamlined throughout.

Changes

File(s) Change Summary
src/errors/meilisearch-api-error.ts, src/http-requests.ts, src/types/task_and_batch.ts Updated to use new ResponseError type in place of MeiliSearchErrorResponse for error handling.
src/types/error.ts Introduced new types: Code, ErrorType, and ResponseError for Meilisearch error responses.
src/types/health.ts, src/types/stats.ts, src/types/version.ts Added new modules defining HealthResponse, Stats, IndexStats, and VersionResponse types.
src/types/index.ts Re-exported new types from error.js, health.js, stats.js, and version.js.
src/types/types.ts Removed legacy types and enums for health, stats, version, and error responses; simplified FieldDistribution.
src/types/shared.ts Removed unused type alias NonNullableDeepRecordValues<T>.
src/indexes.ts, src/meilisearch.ts Updated to use new response types and documentation links; removed explicit generics and improved type safety.
All tests/*.test.ts files Replaced all ErrorStatusCode enum usage with string literal error codes in assertions; removed related imports and explicit type annotations where possible.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HttpRequests
    participant MeiliSearchApiError

    Client->>HttpRequests: Make API request
    HttpRequests->>HttpRequests: Parse response as T | ResponseError
    alt Response is Error
        HttpRequests->>MeiliSearchApiError: Throw with ResponseError object
        MeiliSearchApiError-->>Client: Error with {message, code, type, link}
    else Response is OK
        HttpRequests-->>Client: Return parsed response
    end
Loading

Poem

🐇
Refactored types, a hop anew,
Error codes now stringed and true.
Enums gone, responses neat,
Strongly-typed from ears to feet!
Tests now check what’s clear and right—
A rabbit’s code, both swift and light.
🌱

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 2102016 and 9617de8.

📒 Files selected for processing (4)
  • src/meilisearch.ts (4 hunks)
  • src/types/index.ts (1 hunks)
  • tests/documents.test.ts (6 hunks)
  • tests/search.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/types/index.ts
  • tests/documents.test.ts
  • src/meilisearch.ts
  • tests/search.test.ts

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 sequence diagram to generate a sequence diagram of the changes in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants