Skip to content

Commit

Permalink
Alternate idea for single use (#899)
Browse files Browse the repository at this point in the history
* Alternate idea for single use

* Cleanup

* Restore $in

* Add type sanity checks

* saurav changes

* fix more tests

* remove extraneous files

* add changeset

* fix test

* add new report

---------

Co-authored-by: Saurav <[email protected]>
  • Loading branch information
ericanderson and ssanjay1 authored Nov 19, 2024
1 parent 009650f commit 11088aa
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 64 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-eels-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/client": patch
"@osdk/api": patch
---

Fix where clause types so we don't accept more than one key in the clauses.
4 changes: 2 additions & 2 deletions etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,8 @@ export interface VersionBound<V extends VersionString<any, any, any>> {
// Warning: (ae-forgotten-export) The symbol "FilterFor" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type WhereClause<T extends ObjectOrInterfaceDefinition> = OrWhereClause<T> | AndWhereClause<T> | NotWhereClause<T> | (IsNever<PropertyKeys<T>> extends true ? Record<string, never> : {
[P in PropertyKeys<T>]?: FilterFor<CompileTimeMetadata<T>["properties"][P]>;
export type WhereClause<T extends ObjectOrInterfaceDefinition> = OrWhereClause<T> | AndWhereClause<T> | NotWhereClause<T> | (IsNever<keyof CompileTimeMetadata<T>["properties"]> extends true ? Record<string, never> : {
[P in keyof CompileTimeMetadata<T>["properties"]]?: FilterFor<CompileTimeMetadata<T>["properties"][P]>;
});

// @public (undocumented)
Expand Down
32 changes: 32 additions & 0 deletions packages/api/src/aggregate/ArrayFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Just } from "./Just.js";

interface ArrayFilterOptions<T> {
"$contains": T;
"$isNull": boolean;
}
namespace ArrayFilter {
export interface $contains<T>
extends Just<"$contains", ArrayFilterOptions<T>>
{}
export interface $isNull<T> extends Just<"$isNull", ArrayFilterOptions<T>> {}
}

export type ArrayFilter<T> =
| ArrayFilter.$contains<T>
| ArrayFilter.$isNull<T>;
46 changes: 46 additions & 0 deletions packages/api/src/aggregate/BaseFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Just } from "./Just.js";

export type BaseFilterOptions<T> = {
"$eq": T;
"$ne": T;
"$isNull": boolean;
"$in": ReadonlyArray<T>;
};

export namespace BaseFilter {
export interface $eq<T> extends Just<"$eq", BaseFilterOptions<T>> {}
export interface $ne<T> extends Just<"$ne", BaseFilterOptions<T>> {}
export interface $in<T> extends Just<"$in", BaseFilterOptions<T>> {}
export interface $isNull<T> extends Just<"$isNull", BaseFilterOptions<T>> {}
}

export type BaseFilter<T> =
| BaseFilter.$eq<T>
| BaseFilter.$ne<T>
| BaseFilter.$in<T>
| BaseFilter.$isNull<T>;

/** @internal */
export type CatchThemAll<T> = CatchThemAllInternal<T, keyof T>;

// extends for union distribution
/** @internal */
type CatchThemAllInternal<T, K extends keyof T> = K extends keyof T
? { [k in K]: T[k] }
: never;
38 changes: 38 additions & 0 deletions packages/api/src/aggregate/BooleanFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { BaseFilterOptions, CatchThemAll } from "./BaseFilter.js";
import type { Just } from "./Just.js";

interface BooleanFilterOptions extends BaseFilterOptions<boolean> {}

export namespace BooleanFilter {
export interface $eq extends Just<"$eq", BooleanFilterOptions> {}
export interface $ne extends Just<"$ne", BooleanFilterOptions> {}
export interface $isNull extends Just<"$isNull", BooleanFilterOptions> {}
export interface $in extends Just<"$in", BooleanFilterOptions> {}
}
export type BooleanFilter =
| boolean
| BooleanFilter.$eq
| BooleanFilter.$ne
| BooleanFilter.$in
| BooleanFilter.$isNull;

/** @internal */
function _typeCheck() {
const b: BooleanFilter = {} as CatchThemAll<BooleanFilterOptions>;
}
51 changes: 51 additions & 0 deletions packages/api/src/aggregate/DatetimeFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { BaseFilterOptions, CatchThemAll } from "./BaseFilter.js";
import type { Just } from "./Just.js";

export interface DatetimeFilterOptions extends BaseFilterOptions<string> {
"$gt": string;
"$gte": string;
"$lt": string;
"$lte": string;
}

export namespace DatetimeFilter {
export interface $eq extends Just<"$eq", DatetimeFilterOptions> {}
export interface $ne extends Just<"$ne", DatetimeFilterOptions> {}
export interface $isNull extends Just<"$isNull", DatetimeFilterOptions> {}
export interface $gt extends Just<"$gt", DatetimeFilterOptions> {}
export interface $gte extends Just<"$gte", DatetimeFilterOptions> {}
export interface $lt extends Just<"$lt", DatetimeFilterOptions> {}
export interface $lte extends Just<"$lte", DatetimeFilterOptions> {}
export interface $in extends Just<"$in", DatetimeFilterOptions> {}
}
export type DatetimeFilter =
| string
| DatetimeFilter.$eq
| DatetimeFilter.$ne
| DatetimeFilter.$isNull
| DatetimeFilter.$in
| DatetimeFilter.$gt
| DatetimeFilter.$gte
| DatetimeFilter.$lt
| DatetimeFilter.$lte;

/** @internal */
function _typeCheck() {
const b: DatetimeFilter = {} as CatchThemAll<DatetimeFilterOptions>;
}
66 changes: 66 additions & 0 deletions packages/api/src/aggregate/GeoFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { BBox, Point, Polygon } from "geojson";
import type { Just } from "./Just.js";
import type { DistanceUnitMapping } from "./WhereClause.js";

interface GeoFilterOptions {
"$within":
| {
$distance: [number, keyof typeof DistanceUnitMapping];
$of: [number, number] | Readonly<Point>;
$bbox?: never;
$polygon?: never;
}
| {
$bbox: BBox;
$distance?: never;
$of?: never;
$polygon?: never;
}
| BBox
| {
$polygon: Polygon["coordinates"];
$bbox?: never;
$distance?: never;
$of?: never;
}
| Polygon;
"$intersects":
| {
$bbox: BBox;
$polygon?: never;
}
| BBox
| {
$polygon: Polygon["coordinates"];
$bbox?: never;
}
| Polygon;
"$isNull": boolean;
}

export namespace GeoFilter {
export interface $within extends Just<"$within", GeoFilterOptions> {}
export interface $intersects extends Just<"$intersects", GeoFilterOptions> {}
export interface $isNull extends Just<"$isNull", GeoFilterOptions> {}
}

export type GeoFilter =
| GeoFilter.$within
| GeoFilter.$intersects
| GeoFilter.$isNull;
27 changes: 27 additions & 0 deletions packages/api/src/aggregate/Just.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export type Just<Z extends keyof V, V> =
& {
[k in Z]: V[k];
}
& {
[k in keyof V as k extends Z ? never : k]?: never;
};

export type NeverThese<V extends string | symbol | number> = {
[k in V]?: never;
};
51 changes: 51 additions & 0 deletions packages/api/src/aggregate/NumberFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { BaseFilterOptions, CatchThemAll } from "./BaseFilter.js";
import type { Just } from "./Just.js";

interface NumberFilterOptions extends BaseFilterOptions<number> {
"$gt": number;
"$gte": number;
"$lt": number;
"$lte": number;
}

export namespace NumberFilter {
export interface $eq extends Just<"$eq", NumberFilterOptions> {}
export interface $ne extends Just<"$ne", NumberFilterOptions> {}
export interface $isNull extends Just<"$isNull", NumberFilterOptions> {}
export interface $gt extends Just<"$gt", NumberFilterOptions> {}
export interface $gte extends Just<"$gte", NumberFilterOptions> {}
export interface $lt extends Just<"$lt", NumberFilterOptions> {}
export interface $lte extends Just<"$lte", NumberFilterOptions> {}
export interface $in extends Just<"$in", NumberFilterOptions> {}
}
export type NumberFilter =
| number
| NumberFilter.$eq
| NumberFilter.$ne
| NumberFilter.$isNull
| NumberFilter.$in
| NumberFilter.$gt
| NumberFilter.$gte
| NumberFilter.$lt
| NumberFilter.$lte;

/** @internal */
function _typeCheck() {
const b: NumberFilter = {} as CatchThemAll<NumberFilterOptions>;
}
Loading

0 comments on commit 11088aa

Please sign in to comment.