Skip to content

Commit

Permalink
Merge pull request #43 from palantir/ea/fix-up-aggregations
Browse files Browse the repository at this point in the history
Fix intellisense for aggregations and fill in more number types
  • Loading branch information
ericanderson committed Feb 7, 2024
2 parents 16efd1e + 9d6f89e commit 139cdaf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
21 changes: 21 additions & 0 deletions examples/basic/cli/src/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ export async function typeChecks(client: Client<Ontology>) {
);
}

// 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({
Expand Down
5 changes: 5 additions & 0 deletions packages/client/changelog/@unreleased/pr-43.v2.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions packages/client/src/objectSet/ObjectSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -69,7 +73,9 @@ export interface BaseObjectSet<
// OsdkObjectFrom<K, O, PropertyKeysFrom<O, K>>
// >;

aggregateOrThrow: <const AO extends AggregateOpts<O, K, any>>(
aggregateOrThrow: <
AO extends AggregateOpts<O, K, AggregationClause<O, K>>,
>(
req: AO,
) => Promise<AggregationsResults<O, K, AO>>;

Expand Down
8 changes: 5 additions & 3 deletions packages/client/src/query/aggregations/AggregationsClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -38,7 +39,8 @@ export type AggregationClause<
K
>[P]["type"] extends "string"
? StringAggregateOption | StringAggregateOption[]
: ObjectTypePropertyDefinitionsFrom<O, K>[P]["type"] extends "double"
: ObjectTypePropertyDefinitionsFrom<O, K>[P]["type"] extends
"double" | "integer" | "float" | "decimal" | "byte" | "long" | "short"
? NumericAggregateOption | NumericAggregateOption[]
: ObjectTypePropertyDefinitionsFrom<O, K>[P]["type"];
: never;
};

0 comments on commit 139cdaf

Please sign in to comment.