feat[getAll]: ENG-11765 add fetchTotalCount param from Content API as an option for getAll in SDKs#4352
feat[getAll]: ENG-11765 add fetchTotalCount param from Content API as an option for getAll in SDKs#4352AishwaryaParab wants to merge 1 commit intomainfrom
fetchTotalCount param from Content API as an option for getAll in SDKs#4352Conversation
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
|
View your CI Pipeline Execution ↗ for commit f59f949
☁️ Nx Cloud last updated this comment at |


Description
The Content API (
/api/v3/content/:model) already supports afetchTotalCountquery parameter. WhenfetchTotalCount=trueis passed, the server:countDocumentsquery in parallel with the data fetch{ results: BuilderContent[], totalCount: number }instead of the usual{ results: BuilderContent[] }This is already used internally by admin UI components (e.g.
ComponentsUsageTable,SymbolEntriesTable) which call the API directly. However, the public SDKgetAllmethod does not expose this parameter and currently always returns onlyBuilderContent[], silently discardingtotalCountfrom the response.This PR:
fetchTotalCountoption inGetContentOptionsfetchTotalCount: true, returns{ results: BuilderContent[], totalCount: number }instead ofBuilderContent[]fetchTotalCountis absent orfalse, preserves the existing return shapeBuilderContent[]for full backwards compatibilityScreenshot
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
fetchTotalCountoption toGetContentOptionsand forwards it to the Content API/query URL generation so requests can ask for total matching entry counts.Updates
Builder.getAllwith TypeScript overloads and runtime behavior: whenfetchTotalCount: true, it returns{ results, totalCount }(withtotalCountcaptured from the API response); otherwise it preserves the existingBuilderContent[]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.