-
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 6 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 |
---|---|---|
|
@@ -23,52 +23,58 @@ import type { | |
import type { CompileTimeMetadata } from "../ontology/ObjectTypeDefinition.js"; | ||
import type { SimplePropertyDef } from "../ontology/SimplePropertyDef.js"; | ||
import type { LinkedType, LinkNames } from "../util/LinkUtils.js"; | ||
import type { Rdp } from "./Rdp.js"; | ||
import type { CollectWithPropAggregations } from "./WithPropertiesAggregationOptions.js"; | ||
|
||
export interface WithPropertyObjectSet<Q extends ObjectOrInterfaceDefinition> | ||
extends | ||
BaseWithPropertyObjectSet<Q>, | ||
AggregatableWithPropertyObjectSet<Q>, | ||
SingleLinkWithPropertyObjectSet<Q> | ||
{} | ||
export namespace DerivedProperty { | ||
export type SelectorResult< | ||
T extends SimplePropertyDef, | ||
> = { | ||
type: T; | ||
}; | ||
|
||
export interface BaseWithPropertyObjectSet< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> extends FilterableWithPropertyObjectSet<Q> { | ||
readonly pivotTo: <L extends LinkNames<Q>>( | ||
type: L, | ||
) => NonNullable<CompileTimeMetadata<Q>["links"][L]["multiplicity"]> extends | ||
false ? SingleLinkWithPropertyObjectSet<LinkedType<Q, L>> | ||
: ManyLinkWithPropertyObjectSet<LinkedType<Q, L>>; | ||
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 FilterableWithPropertyObjectSet< | ||
interface FilterableBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> { | ||
readonly where: ( | ||
clause: WhereClause<Q>, | ||
) => this; | ||
} | ||
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; | ||
|
||
interface AggregatableWithPropertyObjectSet< | ||
interface AggregatableBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> { | ||
readonly aggregate: < | ||
|
@@ -83,7 +89,7 @@ interface AggregatableWithPropertyObjectSet< | |
: P extends "approximatePercentile" ? { percentile: number } | ||
: never | ||
: never, | ||
) => Rdp.SelectorResult< | ||
) => DerivedProperty.SelectorResult< | ||
V extends `${infer N}:${infer P}` | ||
? P extends CollectWithPropAggregations | ||
? Array<CompileTimeMetadata<Q>["properties"][N]["type"]> | undefined | ||
|
@@ -95,16 +101,21 @@ interface AggregatableWithPropertyObjectSet< | |
>; | ||
} | ||
|
||
interface SingleLinkWithPropertyObjectSet< | ||
/** | ||
* 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 | ||
AggregatableWithPropertyObjectSet<Q>, | ||
FilterableWithPropertyObjectSet<Q>, | ||
BaseWithPropertyObjectSet<Q> | ||
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, | ||
) => Rdp.SelectorResult< | ||
) => DerivedProperty.SelectorResult< | ||
SimplePropertyDef.Make< | ||
CompileTimeMetadata<Q>["properties"][R]["type"], | ||
CompileTimeMetadata<Q>["properties"][R]["nullable"], | ||
|
@@ -114,18 +125,15 @@ interface SingleLinkWithPropertyObjectSet< | |
} | ||
|
||
/* | ||
* The ManyLinkWithPropertyObjectSet overrides the pivotTo operation because once we traverse a single link, | ||
* 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 ManyLinkWithPropertyObjectSet< | ||
interface DefaultBuilder< | ||
Q extends ObjectOrInterfaceDefinition, | ||
> extends | ||
AggregatableWithPropertyObjectSet<Q>, | ||
FilterableWithPropertyObjectSet<Q> | ||
{ | ||
> extends AggregatableBuilder<Q>, FilterableBuilder<Q> { | ||
readonly pivotTo: <L extends LinkNames<Q>>( | ||
type: L, | ||
) => ManyLinkWithPropertyObjectSet<LinkedType<Q, L>>; | ||
) => DefaultBuilder<LinkedType<Q, L>>; | ||
} |
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.