Skip to content

feat(stats): add StatsParams for Meilisearch v1.44 showInternalDatabaseSizes and sizeFormat#2186

Draft
arieleli01212 wants to merge 1 commit into
meilisearch:mainfrom
arieleli01212:feat/stats-v1.44-params
Draft

feat(stats): add StatsParams for Meilisearch v1.44 showInternalDatabaseSizes and sizeFormat#2186
arieleli01212 wants to merge 1 commit into
meilisearch:mainfrom
arieleli01212:feat/stats-v1.44-params

Conversation

@arieleli01212

@arieleli01212 arieleli01212 commented Jun 1, 2026

Copy link
Copy Markdown

Closes #2185.

Adds support for the two new query parameters introduced in Meilisearch v1.44.0 for the stats endpoints.

Changes

src/types/types.ts

  • New StatsParams type with showInternalDatabaseSizes?: boolean and sizeFormat?: "raw" | "human"
  • IndexStats.internalDatabaseSizes?: Record<string, number | string> — present only when showInternalDatabaseSizes: true; typed as Record<string, number | string> per the spec note that keys are subject to change
  • Size fields (rawDocumentDbSize, avgDocumentSize, databaseSize, usedDatabaseSize) widened to number | string to accommodate sizeFormat: "human" responses

src/indexes.tsgetStats(params?: StatsParams) passes params as query string

src/meilisearch.tsgetStats(params?: StatsParams) passes params as query string

.code-samples.meilisearch.yaml — updated get_index_stats_1 and get_indexes_stats_1 to show both new params

Summary

This PR adds support for two new query parameters introduced in Meilisearch v1.44.0 for the stats endpoints: showInternalDatabaseSizes and sizeFormat.

Changes

Type Definitions (src/types/types.ts)

  • Added StatsParams:
    • showInternalDatabaseSizes?: boolean — include internal database size breakdown when true
    • sizeFormat?: "raw" | "human" — return sizes as bytes or human-readable strings
  • Updated IndexStats:
    • rawDocumentDbSize and avgDocumentSize widened from number to number | string
    • added optional internalDatabaseSizes?: Record<string, number | string> (present when showInternalDatabaseSizes is true)
  • Updated Stats:
    • databaseSize and usedDatabaseSize widened from number to number | string

Method Signatures (src/indexes.ts, src/meilisearch.ts)

  • Index.getStats(params?: StatsParams) now accepts optional params and forwards them as query string parameters to GET /indexes/{uid}/stats.
  • Meilisearch.getStats(params?: StatsParams) now accepts optional params and forwards them as query string parameters to GET /stats.

Code Samples (.code-samples.meilisearch.yaml)

  • Updated examples get_index_stats_1 and get_indexes_stats_1 to call getStats() with { showInternalDatabaseSizes: true, sizeFormat: 'human' }.

References

  • Closes #2185
  • Aligns SDK with Meilisearch v1.44.0 stats API changes

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45f9f45b-51dc-4339-8d85-7f640c08997d

📥 Commits

Reviewing files that changed from the base of the PR and between 32357b5 and 4980fef.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml
  • src/indexes.ts
  • src/meilisearch.ts
  • src/types/types.ts
✅ Files skipped from review due to trivial changes (1)
  • .code-samples.meilisearch.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/indexes.ts
  • src/meilisearch.ts

📝 Walkthrough

Walkthrough

This PR implements support for Meilisearch v1.44.0 stats API enhancements. It adds a new StatsParams type for query parameters controlling size format and internal database size visibility, updates both Index.getStats and Meilisearch.getStats methods to accept these parameters, and modifies response types to handle human-readable size strings and optional internal database size maps.

Changes

Stats API: Support human-formatted sizes and internal database size options

Layer / File(s) Summary
Stats parameter and response type definitions
src/types/types.ts
Introduces StatsParams with showInternalDatabaseSizes and sizeFormat options. Updates IndexStats and Stats to accept number | string for size fields and adds optional internalDatabaseSizes map to IndexStats.
Index and client stats methods
src/indexes.ts, src/meilisearch.ts
Imports StatsParams in both files. Updates Index.getStats() and Meilisearch.getStats() method signatures to accept optional params?: StatsParams and forwards parameters as query arguments in API requests.
Code examples
.code-samples.meilisearch.yaml
Updates get_index_stats_1 and get_indexes_stats_1 examples to demonstrate calling getStats with showInternalDatabaseSizes: true and sizeFormat: 'human'.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Poem

🐰 Hippity-hop, the stats now glow,
With human sizes on display!
Internal sizes peek on cue,
Params passed cleanly through and through. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: adding StatsParams type support for Meilisearch v1.44 features (showInternalDatabaseSizes and sizeFormat parameters).
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #2185: adds StatsParams type with both parameters, updates getStats methods in both classes to accept and forward params, widens size fields to support human-formatted strings, and updates code samples.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #2185 requirements. The modifications are scoped to stats API support and do not include unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

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

🧹 Nitpick comments (2)
src/types/types.ts (2)

757-767: ⚡ Quick win

Type widening requires careful handling in consuming code.

The widening of rawDocumentDbSize and avgDocumentSize from number to number | string is correct for supporting human-formatted sizes, but it's a breaking change for TypeScript consumers who perform arithmetic or numeric operations on these fields without type guards. While runtime behavior is preserved when params are omitted (defaults to numeric "raw" format), stricter TypeScript checking will now require users to handle both types.

This is the right approach for type safety, but consider documenting this in a migration guide or changelog so users understand they may need to add type guards when working with size fields.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types/types.ts` around lines 757 - 767, The IndexStats type widened
rawDocumentDbSize and avgDocumentSize from number to number | string which is
correct but is a breaking typing change; update the project migration
docs/changelog and any consumer-facing documentation to clearly state this
change and show recommended fixes (e.g., use type guards, Number() conversion,
or a provided parse/format helper) and include example patterns for safely
performing arithmetic on IndexStats.rawDocumentDbSize and
IndexStats.avgDocumentSize; reference the IndexStats type and the two fields by
name so maintainers and consumers can find and update call sites accordingly.

769-776: ⚡ Quick win

Same type-widening concern applies here.

Similar to IndexStats, the Stats type now has databaseSize and usedDatabaseSize widened to number | string. This correctly reflects the API behavior when sizeFormat: "human" is used, but consumers performing numeric operations on these fields will need to add type guards.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types/types.ts` around lines 769 - 776, The widening of databaseSize and
usedDatabaseSize to number | string can surprise numeric consumers; make the
type explicit by converting Stats into a generic type parameterized by size
(e.g., type Stats<TSize = number | string>) and change databaseSize and
usedDatabaseSize to TSize so callers can opt into number-only or human-string
variants, and mirror the same approach for any related IndexStats fields that
were widened so consumers can pick Stats<number> or Stats<string> as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/types/types.ts`:
- Around line 757-767: The IndexStats type widened rawDocumentDbSize and
avgDocumentSize from number to number | string which is correct but is a
breaking typing change; update the project migration docs/changelog and any
consumer-facing documentation to clearly state this change and show recommended
fixes (e.g., use type guards, Number() conversion, or a provided parse/format
helper) and include example patterns for safely performing arithmetic on
IndexStats.rawDocumentDbSize and IndexStats.avgDocumentSize; reference the
IndexStats type and the two fields by name so maintainers and consumers can find
and update call sites accordingly.
- Around line 769-776: The widening of databaseSize and usedDatabaseSize to
number | string can surprise numeric consumers; make the type explicit by
converting Stats into a generic type parameterized by size (e.g., type
Stats<TSize = number | string>) and change databaseSize and usedDatabaseSize to
TSize so callers can opt into number-only or human-string variants, and mirror
the same approach for any related IndexStats fields that were widened so
consumers can pick Stats<number> or Stats<string> as needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3561847c-ce76-473f-a41f-927c84f4cb35

📥 Commits

Reviewing files that changed from the base of the PR and between 136170b and 32357b5.

📒 Files selected for processing (4)
  • .code-samples.meilisearch.yaml
  • src/indexes.ts
  • src/meilisearch.ts
  • src/types/types.ts

@arieleli01212
arieleli01212 force-pushed the feat/stats-v1.44-params branch from 32357b5 to 4980fef Compare June 9, 2026 11:06
@Strift Strift added the enhancement New feature or request label Jul 6, 2026

@Strift Strift left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hello @arieleli01212 and thanks for your PR!

The CI is not passing. I suggest running linter + formatter + tests locally before requesting another review 🙏

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.07%. Comparing base (a4940de) to head (4980fef).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2186   +/-   ##
=======================================
  Coverage   98.07%   98.07%           
=======================================
  Files          14       14           
  Lines         674      674           
  Branches      110      110           
=======================================
  Hits          661      661           
  Misses         12       12           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 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.

@Strift
Strift marked this pull request as draft July 6, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Meilisearch v1.44.0] Add human-formatted sizes and detailed DB sizes in stats

2 participants