-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: main
Are you sure you want to change the base?
Improve various types #1919
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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") {
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. |
WalkthroughThis 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
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
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit 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. Note ⚡️ Faster reviews with cachingCodeRabbit 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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Pull Request
What does this PR do?
Migration
Health
->HealthResponse
Version
->VersionResponse
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Chores