fix: send measures as string array in aggregate() to match backend analytics API#1161
fix: send measures as string array in aggregate() to match backend analytics API#1161
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…alytics API format
The backend MemoryAnalyticsService.resolveMeasure() expects measure names as
strings (e.g. 'amount_sum', 'count') and calls .split('.') on them. Sending
object arrays ({field, function}) caused TypeError: t.split is not a function.
Changes:
- Convert measures from [{field, function}] to string format: 'count' for
count aggregation, '${field}_${function}' for others (e.g. 'amount_sum')
- Send empty dimensions array when groupBy is '_all' (single-bucket)
- Map response measure keys back to original field names for consumers
- Add 10 unit tests covering payload format, response mapping, and fallback
Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/7e803790-d91b-4542-886e-743490f0dfc6
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/7e803790-d91b-4542-886e-743490f0dfc6 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes ObjectStackAdapter.aggregate() to match the backend analytics API’s expected request/response shape, preventing runtime failures on analytics queries and keeping aggregate results consistent for consumers (charts/dashboard widgets).
Changes:
- Send
measuresas a string array (['count']or${field}_${function}likeamount_sum) instead of{ field, function }objects. - Treat
groupBy === '_all'as a single-bucket aggregation by sendingdimensions: []. - Normalize analytics responses by remapping measure keys (e.g.
amount_sum) back to the requestedfieldkey (e.g.amount), plus add Vitest coverage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/data-objectstack/src/index.ts | Updates analytics payload formatting and remaps returned measure keys for consumer compatibility. |
| packages/data-objectstack/src/aggregate.test.ts | Adds unit tests validating payload format, response normalization, envelope variants, and fallback behavior. |
| CHANGELOG.md | Documents the analytics aggregate compatibility fix and related behavior changes. |
| measures: [measureName], | ||
| // When groupBy is '_all' no dimensions are needed (single-bucket). | ||
| dimensions: params.groupBy && params.groupBy !== '_all' ? [params.groupBy] : [], | ||
| }; |
There was a problem hiding this comment.
groupBy === '_all' is now treated as “no dimensions” for the server-side analytics query, but the fallback aggregateClientSide() (used in the catch path) still groups on the literal '_all' field and will return rows containing an _all key (e.g. { _all: 'Unknown', amount: ... }). This makes the output shape differ depending on whether the analytics endpoint is available. Consider aligning the fallback behavior for '_all' (single-bucket result) so both code paths return the same row shape, and add a test for the fallback path with groupBy: '_all'.
| * query payload uses the correct string-based measure/dimension format | ||
| * expected by the backend analytics service (MemoryAnalyticsService). | ||
| * | ||
| * See: https://github.com/objectstack-ai/objectui/issues (measures format bug) |
There was a problem hiding this comment.
The test header comment references https://github.com/objectstack-ai/objectui/issues which points to the generic issues list, not the specific bug/issue being validated. Linking to a specific issue (or removing the link) would make it easier to trace why these tests exist.
| * See: https://github.com/objectstack-ai/objectui/issues (measures format bug) | |
| * Related to prior measures format bug in analytics payloads. |
ObjectStackAdapter.aggregate()sendsmeasuresas[{ field, function }]butMemoryAnalyticsService.resolveMeasure()calls.split('.')on each element, expecting strings. This causesTypeError: t.split is not a functionon every analytics query.Changes
${field}_${function}convention (e.g.'amount_sum'), with'count'as special case[]whengroupBy === '_all'instead of['_all']for single-bucket aggregationamount_sum→amount) to matchaggregateClientSide()output format that consumers expectTests
10 new tests in
aggregate.test.tscovering payload format, response key mapping, all response envelope variants, and client-side fallback.