-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RDP's in TS OSDK #1035
base: main
Are you sure you want to change the base?
RDP's in TS OSDK #1035
Changes from 35 commits
246f893
50ca838
4e17a4e
01f5935
ebe19e4
4ea27dc
d2d0a0d
efbed3d
40ee625
3e535da
20835ea
76a3ee1
73c23fe
d605787
214dad7
73fbffa
9070c29
ac7f03f
2777334
a8546ca
0cd49f5
0a89f9c
a2f331d
bec53ca
d8fa066
ecb0522
abc0b2d
831f890
a270994
7a8847f
2659b3b
1167fae
330dac1
eb99bab
c5686e0
624b662
2812538
c2c675f
95829f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@osdk/shared.test": minor | ||
"@osdk/client": minor | ||
"@osdk/api": minor | ||
--- | ||
|
||
Adds support for runtime derived properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import type { | ||
NumericWithPropAggregateOption, | ||
StringWithPropAggregateOption, | ||
} from "../derivedProperties/WithPropertiesAggregationOptions.js"; | ||
import type { | ||
GetWirePropertyValueFromClient, | ||
} from "../mapping/PropertyValueMapping.js"; | ||
|
@@ -32,19 +36,23 @@ export type NumericAggregateOption = | |
| "approximateDistinct" | ||
| "exactDistinct"; | ||
|
||
type AGG_FOR_TYPE<T> = number extends T ? NumericAggregateOption | ||
: string extends T ? StringAggregateOption | ||
type AGG_FOR_TYPE<T, U extends boolean> = number extends T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename |
||
? U extends true ? NumericAggregateOption : NumericWithPropAggregateOption | ||
: string extends T | ||
? U extends true ? StringAggregateOption : StringWithPropAggregateOption | ||
: never; | ||
|
||
export type ValidAggregationKeys< | ||
Q extends ObjectOrInterfaceDefinition, | ||
R extends "aggregate" | "withPropertiesAggregate" = "aggregate", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ssanjay1 Is this what you had in mind? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea that works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though maybe keeping parity with the other names it should be |
||
> = keyof ( | ||
& { | ||
[ | ||
KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE< | ||
GetWirePropertyValueFromClient< | ||
CompileTimeMetadata<Q>["properties"][KK]["type"] | ||
> | ||
>, | ||
R extends "aggregate" ? true : false | ||
>}` | ||
]?: any; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* 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 { ValidAggregationKeys } from "../aggregate/AggregatableKeys.js"; | ||
import type { WhereClause } from "../aggregate/WhereClause.js"; | ||
import type { | ||
ObjectOrInterfaceDefinition, | ||
PropertyKeys, | ||
} from "../ontology/ObjectOrInterface.js"; | ||
import type { CompileTimeMetadata } from "../ontology/ObjectTypeDefinition.js"; | ||
import type { SimplePropertyDef } from "../ontology/SimplePropertyDef.js"; | ||
import type { LinkedType, LinkNames } from "../util/LinkUtils.js"; | ||
import type { CollectWithPropAggregations } from "./WithPropertiesAggregationOptions.js"; | ||
|
||
export namespace DerivedProperty { | ||
export type SelectorResult< | ||
T extends SimplePropertyDef, | ||
> = { | ||
type: T; | ||
}; | ||
|
||
export type Clause< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> = { | ||
[key: string]: Selector<Q, SimplePropertyDef>; | ||
}; | ||
|
||
export type Selector< | ||
Q extends ObjectOrInterfaceDefinition, | ||
T extends SimplePropertyDef, | ||
> = ( | ||
baseObjectSet: DerivedProperty.Builder<Q>, | ||
) => SelectorResult<T>; | ||
|
||
export interface Builder<Q extends ObjectOrInterfaceDefinition> | ||
extends FilterableBuilder<Q> | ||
{ | ||
readonly pivotTo: <L extends LinkNames<Q>>( | ||
type: L, | ||
) => NonNullable<CompileTimeMetadata<Q>["links"][L]["multiplicity"]> extends | ||
false ? SelectPropertyBuilder<LinkedType<Q, L>> | ||
: DefaultBuilder<LinkedType<Q, L>>; | ||
} | ||
|
||
export namespace Builder { | ||
export interface Full<Q extends ObjectOrInterfaceDefinition> | ||
extends | ||
DerivedProperty.Builder<Q>, | ||
AggregatableBuilder<Q>, | ||
SelectPropertyBuilder<Q> | ||
{ | ||
} | ||
} | ||
} | ||
|
||
interface FilterableBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> { | ||
readonly where: ( | ||
clause: WhereClause<Q>, | ||
) => this; | ||
} | ||
|
||
interface AggregatableBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> { | ||
readonly aggregate: < | ||
V extends ValidAggregationKeys< | ||
Q, | ||
"withPropertiesAggregate" | ||
>, | ||
>( | ||
aggregationSpecifier: V, | ||
opts?: V extends `${any}:${infer P}` | ||
? P extends CollectWithPropAggregations ? { limit: number } | ||
: P extends "approximatePercentile" ? { percentile: number } | ||
: never | ||
: never, | ||
) => DerivedProperty.SelectorResult< | ||
V extends `${infer N}:${infer P}` | ||
? P extends CollectWithPropAggregations | ||
? Array<CompileTimeMetadata<Q>["properties"][N]["type"]> | undefined | ||
: P extends "approximateDistinct" | "exactDistinct" | "$count" | ||
? "integer" | undefined | ||
: "double" | undefined | ||
: V extends "$count" ? "integer" | undefined | ||
: never | ||
>; | ||
} | ||
|
||
/** | ||
* This is the builder that is used until we encounter a many link traversal. | ||
* Once a many link traversal happens, we switch to the DefaultBuilder and the | ||
* selectProperty option is no longer available. | ||
*/ | ||
interface SelectPropertyBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> extends | ||
AggregatableBuilder<Q>, | ||
FilterableBuilder<Q>, | ||
DerivedProperty.Builder<Q> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused a bit on the hierarchy. Why are some things in the namespace and others not? |
||
{ | ||
readonly selectProperty: <R extends PropertyKeys<Q>>( | ||
propertyName: R, | ||
) => DerivedProperty.SelectorResult< | ||
SimplePropertyDef.Make< | ||
CompileTimeMetadata<Q>["properties"][R]["type"], | ||
CompileTimeMetadata<Q>["properties"][R]["nullable"], | ||
CompileTimeMetadata<Q>["properties"][R]["multiplicity"] | ||
> | ||
>; | ||
} | ||
|
||
/* | ||
* The DefaultBuilder overrides the pivotTo operation because once we traverse a single link, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to bike shed this name because when I first saw it I was a bit confused about what was default vs not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yeah I wrote the name more with a "coming off the tounge nicely" rather than being super informative because I don't imagine any of our users will care about the type of the RDP object set. If the goal is for more readable code, I can add more comments? |
||
* we cannot use the "selectProperty" operation again for the entire chain. The parent pivotTo class will create | ||
* this object set once the user pivots to a many link/ | ||
*/ | ||
|
||
interface DefaultBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> extends AggregatableBuilder<Q>, FilterableBuilder<Q> { | ||
readonly pivotTo: <L extends LinkNames<Q>>( | ||
type: L, | ||
) => DefaultBuilder<LinkedType<Q, L>>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2025 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 CollectWithPropAggregations = "collectSet" | "collectList"; | ||
|
||
export type BaseWithPropAggregations = | ||
| "approximateDistinct" | ||
| "exactDistinct" | ||
| "approximatePercentile"; | ||
|
||
export type StringWithPropAggregateOption = | ||
| BaseWithPropAggregations | ||
| CollectWithPropAggregations; | ||
|
||
export type NumericWithPropAggregateOption = | ||
| "min" | ||
| "max" | ||
| "sum" | ||
| "avg" | ||
| BaseWithPropAggregations | ||
| CollectWithPropAggregations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, I'm a bit confused and probably missing something here, what if they had downselected the original object props?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think I am confused too. Do we have a test that shows what this? NM. I saw a test down below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm ok yea so looking closer, you only default if P is also never and they never downselected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah thats correct, this is to make sure passing in never still defaults to PropertyKeys<Q> but also allows you to pass in a never if you choose to add an RDP.