Repository navigation
Add meili get stats - #34
Conversation
…one index `--index` selects the route of one index, and its absence the one of the whole instance, as rule 3 of the command contract says. The two query parameters of the routes, `--show-internal-database-sizes` and `--size-format`, travel through `fetchStats` in `src/lib/clients/`: `getStats` of meilisearch-js sends none, and ADR 0003 allows `client.httpRequest` until the SDK takes them, as `fetchDocuments` does. The contract test asked that every parent path flag be required, which would have made `--index` mandatory and `GET /stats` unreachable, while the routes table has documented `meili get stats [--index <index>]` since the first version. It now applies to a parent flag the rule it already applied to `--id`: required only when every route of the command takes it. Rule 4 says it in words, and the skill follows. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Parent flag contract .claude/skills/add-command/SKILL.md, docs/contract/commands.md, test/contract/api.test.ts |
The guidance and contract test require a parent-resource flag only when every route in the command uses it. |
Statistics retrieval oclif.manifest.json, src/commands/get/stats.ts, src/lib/clients/meilisearch.ts, .changeset/first-version.md |
The new command requests global or index statistics. It forwards optional size-format and internal-database-size options, and the release note documents the command. |
Command and API tests test/commands/get/stats.test.ts, test/helpers/meilisearch-handlers.ts, test/integration/meilisearch/get-stats.test.ts, test/contract/docs.test.ts |
Tests cover command output, request parameters, API errors, and real-instance statistics. The docs contract test removes the new command paths from its planned-path list. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant CLI
participant GetStats
participant fetchStats
participant MeilisearchAPI
CLI->>GetStats: Run with optional index and size flags
GetStats->>fetchStats: Pass index and query options
fetchStats->>MeilisearchAPI: GET /stats or /indexes/{index_uid}/stats
MeilisearchAPI-->>fetchStats: Return statistics
fetchStats-->>GetStats: Return statistics
GetStats-->>CLI: Output statistics
Possibly related PRs
- meilisearch/cli#30: Adds
get settingswith a required index flag, which the updated command contract uses as an example.
Merge Risk: 
Minimal · up to 57e05
-
The statistics command is ready to merge after normal checks; no blocking issue was identified.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title "Add
meili get stats" names the main change. The PR adds themeili get statscommand, which callsGET /statsandGET /indexes/{index_uid}/stats, with the--index,--show-internal-database-sizes, and--size-formatoptions. The title is short, specific, and free of noise. It does not mention the contract-test or docs changes, which is acceptable because they are secondary to the main feature.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 6 files. (4 skipped: 4 unsupported.)
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
What
Add
meili get stats, the two routesGET /statsandGET /indexes/{index_uid}/stats.Contract
docs/contract/commands.md, and each route is reachable by a distinct set of flags, or the exception is recorded with its reason (or this pull request changes the contract and nothing else)src/lib/output.ts, errors throughsrc/lib/errors.ts$EDITOR; adeletecommand spreadsBaseCommand.confirmFlagsand its examples carry--yesfetchoutsidesrc/lib/clients/Tests
--helpsnapshot added or updated on purposepnpm lint,pnpm typecheck,pnpm testpass locallySimplicity
src/lib/, is used by this command, and is named belowDocs
docs/contract/updated for every name, flag, variable or code this change adds or renames, or nothing to updateHousekeeping
oclif.manifest.jsonregeneratedNotes for the reviewer
One shared piece and one contract test changed. Both are below, read them first.
fetchStatsinsrc/lib/clients/meilisearch.ts, next tofetchDocuments.getStats()of meilisearch-js sends no query parameter, so neithershowInternalDatabaseSizesnorsizeFormatcan reach the API through it, and rule 6 asks for a flag per query parameter. ADR 0003 covers exactly this: the fix goes to the SDK first, and the CLI usesclient.httpRequestmeanwhile. That is whatfetchDocumentsalready does for the fetch route, three lines above. The helper returns the body untyped on purpose: withsizeFormat=humanthe sizes are strings whereStatsandIndexStatsdeclare numbers, so a cast would claim something false. Happy to open themeilisearch-jsissue and link it here if you want the pointer in the comment.--indexis optional, so the contract test had to stop requiring every parent path flag.test/contract/api.test.tsasked that a parent path parameter berequired, which would have made--indexmandatory andGET /statsunreachable, while the routes table ofcommands.mdhas documentedmeili get stats [--index <index>]since the first version. The contract file wins, so the test now applies to a parent flag the rule it already applied to--id: required only when every route of the command takes it. Rule 4 ofcommands.mdsays it in words now, and the two lines of.claude/skills/add-command/SKILL.mdthat described the old behaviour follow. No other command changes:--indexstays required on every command whose routes all take it, and the test still fails if one of them drops it.The two query parameters are sent only when given.
--size-formatis the closed list the document declares,raworhuman, so oclif refuses anything else withcli_usagebefore the call;--show-internal-database-sizesis a bare boolean. The unit test pins the query string of both routes,/statswith nothing and/indexes/movies/stats?showInternalDatabaseSizes=true&sizeFormat=human, and the integration test checks thathumanreally turnsindexSizeinto a string.Four paths left
PLANNED_PATHSoftest/contract/docs.test.ts. The skill has always usedget statsas its worked example, so its four paths were listed as planned; the test fails when a planned path appears, which is how it asked to be updated here. That is the whole of the diff in that file.Ran the
simplifyskill on the diff. Reuse, simplification and efficiency found nothing. Altitude found two things in the relaxed test, both applied: generalising the check had dropped the guard that a parent flag exists at all, sinceflags[flag]?.required === trueis false for a flag that is optional and for one that is not declared, so the loop now assertstoBeDefined()first, as the--idblock below it does; and the snippet of the skill still spelledFlags.string({ required: true, ... })next to the sentence that had just stopped saying always, so it now readsrequired: trueonly when every route takes it.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
meili get statsto view statistics for a Meilisearch instance or a specific index.Documentation