Skip to content

feat[getAll]: ENG-11765 add fetchTotalCount param from Content API as an option for getAll in SDKs#4352

Open
AishwaryaParab wants to merge 1 commit intomainfrom
ENG-11765_add_fetchTotalCount_to_getAll
Open

feat[getAll]: ENG-11765 add fetchTotalCount param from Content API as an option for getAll in SDKs#4352
AishwaryaParab wants to merge 1 commit intomainfrom
ENG-11765_add_fetchTotalCount_to_getAll

Conversation

@AishwaryaParab
Copy link
Contributor

@AishwaryaParab AishwaryaParab commented Mar 11, 2026

Description

The Content API (/api/v3/content/:model) already supports a fetchTotalCount query parameter. When fetchTotalCount=true is passed, the server:

  1. Runs a countDocuments query in parallel with the data fetch
  2. Returns { results: BuilderContent[], totalCount: number } instead of the usual { results: BuilderContent[] }

This is already used internally by admin UI components (e.g. ComponentsUsageTableSymbolEntriesTable) which call the API directly. However, the public SDK getAll method does not expose this parameter and currently always returns only BuilderContent[], silently discarding totalCount from the response.

This PR:

  1. Accepts a new fetchTotalCount option in GetContentOptions
  2. Forwards the parameter to the Content API as a query string param
  3. When fetchTotalCount: true, returns { results: BuilderContent[], totalCount: number } instead of BuilderContent[]
  4. When fetchTotalCount is absent or false, preserves the existing return shape BuilderContent[] for full backwards compatibility

Screenshot
TBA


Note

Medium Risk
Changes a public SDK method’s return shape conditionally and adds new response-state tracking (totalCountByKey), which could affect callers relying on the previous always-array behavior if they start enabling the flag.

Overview
Adds a new fetchTotalCount option to GetContentOptions and forwards it to the Content API/query URL generation so requests can ask for total matching entry counts.

Updates Builder.getAll with TypeScript overloads and runtime behavior: when fetchTotalCount: true, it returns { results, totalCount } (with totalCount captured from the API response); otherwise it preserves the existing BuilderContent[] return shape. Includes new unit tests validating query param inclusion/exclusion and the conditional return type.

Written by Cursor Bugbot for commit f59f949. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

if (options.fetchTotalCount) {
return {
results,
totalCount: key !== undefined ? instance.totalCountByKey[key] ?? 0 : 0,
Copy link

Choose a reason for hiding this comment

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

Server-side fetchTotalCount always returns zero totalCount

High Severity

On the server side (!Builder.isBrowser), the key variable computed in getAll is undefined (unless options.key is explicitly passed), because the fallback hash is only generated when Builder.isBrowser is true. However, inside queueGetContent, the internal key falls back to modelName. So totalCountByKey is stored under the model name, but the getAll .then() callback checks key !== undefined and short-circuits to totalCount: 0 without ever looking up the stored value. Server-side fetchTotalCount: true always returns zero.

Additional Locations (1)
Fix in Cursor Fix in Web

@nx-cloud
Copy link

nx-cloud bot commented Mar 11, 2026

View your CI Pipeline Execution ↗ for commit f59f949

Command Status Duration Result
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 7m 38s View ↗
nx test @e2e/qwik-city ✅ Succeeded 8m 59s View ↗
nx test @e2e/angular-17 ✅ Succeeded 7m 52s View ↗
nx test @e2e/nuxt ✅ Succeeded 7m 5s View ↗
nx test @e2e/angular-19-ssr ✅ Succeeded 6m 44s View ↗
nx test @e2e/react-sdk-next-15-app ✅ Succeeded 6m 31s View ↗
nx test @e2e/svelte ✅ Succeeded 6m 2s View ↗
nx test @e2e/angular-17-ssr ✅ Succeeded 6m 26s View ↗
Additional runs (37) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2026-03-11 07:38:11 UTC

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