Skip to content

Commit

Permalink
Merge pull request #111 from palantir/ssanjay/addStartsWith
Browse files Browse the repository at this point in the history
Add startsWith for string filter
  • Loading branch information
ssanjay1 authored Mar 5, 2024
2 parents c26c8b8 + 87e281f commit 31c6a85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions examples/basic/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ async function runTests() {

await checkLinksAndActionsForVentures();

const testStringClause = await client(BoundariesUsState)
.where({
usState: {
$startsWith: "N",
},
}).fetchPage();

console.log(testStringClause.data.map(data => data.usState));

const testAggregateCountNoGroup = await client.objects.BoundariesUsState
.aggregateOrThrow({
select: { $count: true, latitude: ["min", "max", "avg"] },
Expand Down
2 changes: 1 addition & 1 deletion examples/docs_example/src/osdkExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function osdkObjectSetExample() {
$or: [{ fullName: { $contains: "Clooney" }, employeeId: { $gt: 10 } }, {
$and: [{ $not: { fullName: { $contains: "Pitt" } } }, {
$or: [{ fullName: { $contains: "Downey" } }, {
fullName: { $contains: "Hemsworth" },
fullName: { $startsWith: "Hemsworth" },
employeeId: { $gte: 20 },
}],
}],
Expand Down
5 changes: 5 additions & 0 deletions packages/client/changelog/@unreleased/pr-111.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: Add startsWith for string filter
links:
- https://github.com/palantir/osdk-ts/pull/111
5 changes: 3 additions & 2 deletions packages/client/src/query/WhereClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export type PossibleWhereClauseFilters =
| "$lt"
| "$lte"
| "$within"
| "$intersects";
| "$intersects"
| "$startsWith";

// We need to conditional here to force the union to be distributed
type MakeFilter<K extends PossibleWhereClauseFilters, V> = K extends string ? {
Expand All @@ -45,7 +46,7 @@ type BaseFilter<T> =
| MakeFilter<"$eq" | "$ne" | "$contains", T>
| MakeFilter<"$isNull", boolean>;

type StringFilter = BaseFilter<string>;
type StringFilter = BaseFilter<string> | MakeFilter<"$startsWith", string>;
type NumberFilter =
| BaseFilter<number>
| MakeFilter<"$gt" | "$gte" | "$lt" | "$lte", number>;
Expand Down

0 comments on commit 31c6a85

Please sign in to comment.