From 64c4b0e6cf604967200489a9d18a5b9d972d7915 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 7 Feb 2024 15:47:23 -0500 Subject: [PATCH 1/2] Fix intellisense for aggregations and fill in more number types --- examples/basic/cli/src/typeChecks.ts | 21 +++++++++++++++++++ packages/client/src/objectSet/ObjectSet.ts | 10 +++++++-- .../query/aggregations/AggregationsClause.ts | 8 ++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/basic/cli/src/typeChecks.ts b/examples/basic/cli/src/typeChecks.ts index 640216191..99e2f729c 100644 --- a/examples/basic/cli/src/typeChecks.ts +++ b/examples/basic/cli/src/typeChecks.ts @@ -50,6 +50,27 @@ export async function typeChecks(client: Client) { ); } + // just a demo of aggregations + { + const q = await client.objects.ObjectTypeWithAllPropertyTypes + .aggregateOrThrow({ + select: { + integer: "sum", + float: "sum", + decimal: "sum", + short: ["max"], + string: "approximateDistinct", + }, + groupBy: { + string: "exact", + stringArray: "exact", + }, + orderBy: { + group: "string", + }, + }); + } + // object $link examples { const page = await client.objectSet("Employee").where({ diff --git a/packages/client/src/objectSet/ObjectSet.ts b/packages/client/src/objectSet/ObjectSet.ts index 4f7005fe1..8f46205d2 100644 --- a/packages/client/src/objectSet/ObjectSet.ts +++ b/packages/client/src/objectSet/ObjectSet.ts @@ -26,7 +26,11 @@ import type { FetchPageOrThrowArgs } from "../object/fetchPageOrThrow.js"; import type { OsdkInterfaceFrom, OsdkObjectFrom } from "../OsdkObjectFrom.js"; import type { PageResult } from "../PageResult.js"; import type { AggregateOpts } from "../query/aggregations/AggregateOpts.js"; -import type { AggregationsResults, WhereClause } from "../query/index.js"; +import type { + AggregationClause, + AggregationsResults, + WhereClause, +} from "../query/index.js"; import type { LinkTypesFrom } from "./LinkTypesFrom.js"; import type { ObjectSetListener } from "./ObjectSetListener.js"; @@ -69,7 +73,9 @@ export interface BaseObjectSet< // OsdkObjectFrom> // >; - aggregateOrThrow: >( + aggregateOrThrow: < + AO extends AggregateOpts>, + >( req: AO, ) => Promise>; diff --git a/packages/client/src/query/aggregations/AggregationsClause.ts b/packages/client/src/query/aggregations/AggregationsClause.ts index f8875505a..0ba931dbb 100644 --- a/packages/client/src/query/aggregations/AggregationsClause.ts +++ b/packages/client/src/query/aggregations/AggregationsClause.ts @@ -21,8 +21,9 @@ import type { } from "@osdk/api"; import type { AggregatableKeys } from "./AggregatableKeys.js"; -type StringAggregateOption = "approximateDistinct"; +type StringAggregateOption = "approximateDistinct" | "count"; type NumericAggregateOption = + | "count" | "min" | "max" | "sum" @@ -38,7 +39,8 @@ export type AggregationClause< K >[P]["type"] extends "string" ? StringAggregateOption | StringAggregateOption[] - : ObjectTypePropertyDefinitionsFrom[P]["type"] extends "double" + : ObjectTypePropertyDefinitionsFrom[P]["type"] extends + "double" | "integer" | "float" | "decimal" | "byte" | "long" | "short" ? NumericAggregateOption | NumericAggregateOption[] - : ObjectTypePropertyDefinitionsFrom[P]["type"]; + : never; }; From 9d6f89eb9d170684a518ca4f618702d7e6637b44 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 7 Feb 2024 20:50:52 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- packages/client/changelog/@unreleased/pr-43.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/client/changelog/@unreleased/pr-43.v2.yml diff --git a/packages/client/changelog/@unreleased/pr-43.v2.yml b/packages/client/changelog/@unreleased/pr-43.v2.yml new file mode 100644 index 000000000..d5d9e9d66 --- /dev/null +++ b/packages/client/changelog/@unreleased/pr-43.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Fix intellisense for aggregations and fill in more number types + links: + - https://github.com/palantir/osdk-ts/pull/43