Skip to content

fix(ds-elasticsearch): propagate enableCount option to the underlying model#216

Closed
PMerlet wants to merge 1 commit into
mainfrom
fix/es-enable-count
Closed

fix(ds-elasticsearch): propagate enableCount option to the underlying model#216
PMerlet wants to merge 1 commit into
mainfrom
fix/es-enable-count

Conversation

@PMerlet
Copy link
Copy Markdown
Member

@PMerlet PMerlet commented May 5, 2026

Summary

The enableCount option exposed on addCollectionFromIndex and addCollectionFromTemplate was documented and typed, but never destructured from the options object — and introspectTemplate didn't accept it either. As a result, enableCount: true was silently dropped, the produced ModelElasticsearch had enableCount === undefined, and ElasticsearchCollection's constructor never called this.enableCount().

Symptom in Forest Admin: collections backed by this datasource appear non-countable in the UI — no 1-15 of N total, and (depending on the frontend version) no next-page control — even when consumers explicitly opt in via enableCount: true.

Changes

  • src/introspection/builder.ts: destructure enableCount in both addCollectionFromIndex and addCollectionFromTemplate, and forward it to ModelElasticsearch / introspectTemplate. Added the option to the ElasticsearchDatasourceOptionsBuilder interface signatures for consistency.
  • src/introspection/template-introspector.ts: accept enableCount and pass it to both ModelElasticsearch constructor branches (legacy + index template).
  • test/collection.test.ts: unit-test the wiring — the produced ElasticsearchCollection's schema is countable: true iff the model has enableCount = true, otherwise countable: false.
  • test/introspection/builder.integration.test.ts: integration-test the propagation through addCollectionFromTemplate.

No public API changes — enableCount was already declared on ElasticsearchCollectionBase.

Test plan

  • yarn build passes
  • yarn lint passes
  • npx jest --testPathIgnorePatterns=integration — 102/102 passing (includes 2 new unit tests in collection.test.ts)
  • Integration suite (requires docker compose up) — locally verified with the new builder integration test; please re-run in CI

🤖 Generated with Claude Code

Note

Propagate enableCount option to ModelElasticsearch in the Elasticsearch datasource builder

The enableCount flag was accepted by addCollectionFromIndex and addCollectionFromTemplate in the builder interface but not forwarded to the underlying ModelElasticsearch constructor, causing count capability to always be disabled.

  • builder.ts now destructures enableCount from options and passes it to ModelElasticsearch (via direct construction or introspectTemplate).
  • template-introspector.ts accepts enableCount as an optional parameter and forwards it to ModelElasticsearch in both index and legacy template branches.

Macroscope summarized ec4ae19.

… model

The `enableCount` option exposed on `addCollectionFromIndex` and
`addCollectionFromTemplate` was never destructured nor forwarded to
`ModelElasticsearch`, so it was silently dropped. As a result, consumers
setting `enableCount: true` still ended up with a non-countable
collection — Forest Admin's UI then has no total to drive pagination
and effectively shows only the first page of records.

Forward the flag through `addCollectionFromIndex`,
`addCollectionFromTemplate` and `introspectTemplate` to the
`ModelElasticsearch` constructor, and add tests asserting both the
collection-level wiring and the builder propagation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@PMerlet PMerlet closed this May 5, 2026
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