diff --git a/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts b/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts index c7b97e620..5a0c5497c 100644 --- a/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts +++ b/examples/basic/cli/src/examples/fetchAggregationForEmployeesGroupedThin.ts @@ -24,16 +24,24 @@ import { expectType } from "ts-expect"; export async function fetchAggregationForEmployeesGroupedThin( clientCtx: ClientContext, ) { - const result = await aggregateOrThrow(clientCtx, Ontology.objects.Employee, { - select: { - locationCity: "approximateDistinct", - locationName: "approximateDistinct", - employeeNumber: ["avg", "max", "min"], + const result = await aggregateOrThrow( + clientCtx, + Ontology.objects.Employee, + { + type: "base", + objectType: "Employee", }, - groupBy: { - locationType: "exact", + { + select: { + locationCity: "approximateDistinct", + locationName: "approximateDistinct", + employeeNumber: ["avg", "max", "min"], + }, + groupBy: { + locationType: "exact", + }, }, - }); + ); result[0].values.employeeNumber.avg; result[0].group.locationType; diff --git a/packages/client/changelog/@unreleased/pr-75.v2.yml b/packages/client/changelog/@unreleased/pr-75.v2.yml new file mode 100644 index 000000000..28595649a --- /dev/null +++ b/packages/client/changelog/@unreleased/pr-75.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Use object set in aggregations + links: + - https://github.com/palantir/osdk-ts/pull/75 diff --git a/packages/client/src/object/aggregateOrThrow.test.ts b/packages/client/src/object/aggregateOrThrow.test.ts index 5082c6fc6..736f175d5 100644 --- a/packages/client/src/object/aggregateOrThrow.test.ts +++ b/packages/client/src/object/aggregateOrThrow.test.ts @@ -127,13 +127,21 @@ describe("aggregateOrThrow", () => { mockFetch, ); - const notGrouped = await aggregateOrThrow(clientCtx, Todo, { - select: { - text: "approximateDistinct", - priority: "avg", - id: ["max", "avg"], + const notGrouped = await aggregateOrThrow( + clientCtx, + Todo, + { + type: "base", + objectType: "ToDo", }, - }); + { + select: { + text: "approximateDistinct", + priority: "avg", + id: ["max", "avg"], + }, + }, + ); expectType(notGrouped.text.approximateDistinct); expectType(notGrouped.priority.avg); @@ -148,14 +156,22 @@ describe("aggregateOrThrow", () => { > >(false); // subselect should hide unused keys - const grouped = await aggregateOrThrow(clientCtx, Todo, { - select: { - text: "approximateDistinct", + const grouped = await aggregateOrThrow( + clientCtx, + Todo, + { + type: "base", + objectType: "ToDo", }, - groupBy: { - text: "exact", + { + select: { + text: "approximateDistinct", + }, + groupBy: { + text: "exact", + }, }, - }); + ); expectType>(grouped); expectType(grouped[0].group.text); expectType(grouped[0].values.text.approximateDistinct); diff --git a/packages/client/src/object/aggregateOrThrow.ts b/packages/client/src/object/aggregateOrThrow.ts index 638925c59..535441bdc 100644 --- a/packages/client/src/object/aggregateOrThrow.ts +++ b/packages/client/src/object/aggregateOrThrow.ts @@ -15,8 +15,8 @@ */ import type { ObjectOrInterfaceDefinition } from "@osdk/api"; -import { aggregateObjectsV2 } from "@osdk/gateway/requests"; -import type { AggregateObjectsRequestV2 } from "@osdk/gateway/types"; +import { aggregateObjectSetV2 } from "@osdk/gateway/requests"; +import type { AggregateObjectsRequestV2, ObjectSet } from "@osdk/gateway/types"; import { createOpenApiRequest } from "@osdk/shared.net"; import type { ClientContext } from "@osdk/shared.net"; import invariant from "tiny-invariant"; @@ -38,6 +38,10 @@ export async function aggregateOrThrow< >( clientCtx: ClientContext, objectType: Q, + objectSet: ObjectSet = { + type: "base", + objectType: objectType["apiName"] as string, + }, req: AO, ): Promise> { const body: AggregateObjectsRequestV2 = { @@ -53,17 +57,18 @@ export async function aggregateOrThrow< } if (req.where) { body.where = modernToLegacyWhereClause(req.where); - // TODO: orderBy - // TODO The token stuff here sucks } - const result = await aggregateObjectsV2( + const result = await aggregateObjectSetV2( createOpenApiRequest( clientCtx.stack, clientCtx.fetch, ), clientCtx.ontology.metadata.ontologyApiName, - objectType["apiName"], - body, + { + objectSet, + groupBy: body.groupBy, + aggregation: body.aggregation, + }, ); if (!req.groupBy) { diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index 2dcb1331b..12068ee12 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -56,7 +56,12 @@ export function createObjectSet< >( req: AO, ): Promise> => { - return aggregateOrThrow(clientCtx, objectType, req); + return aggregateOrThrow( + clientCtx, + objectType, + objectSet, + req, + ); }, // fetchPage: async (args?: { nextPageToken?: string }) => { // throw "TODO";