Skip to content
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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
246f893
Runtime Derived Property Syntax
nihalbhatnagar Dec 4, 2024
50ca838
Working derive clause
nihalbhatnagar Dec 4, 2024
4e17a4e
Update to use map
nihalbhatnagar Dec 4, 2024
01f5935
Update aggregation keys
nihalbhatnagar Dec 5, 2024
ebe19e4
Update
nihalbhatnagar Dec 5, 2024
4ea27dc
Update PR
nihalbhatnagar Dec 5, 2024
d2d0a0d
Initial test suite
nihalbhatnagar Dec 6, 2024
efbed3d
Working version
nihalbhatnagar Dec 9, 2024
40ee625
Cleanup
nihalbhatnagar Dec 9, 2024
3e535da
Add test case
nihalbhatnagar Dec 9, 2024
20835ea
remove use of crypto
nihalbhatnagar Dec 9, 2024
76a3ee1
Changeset
nihalbhatnagar Dec 9, 2024
73c23fe
E2E testing
nihalbhatnagar Dec 10, 2024
d605787
Osdk.Instance typing update
nihalbhatnagar Dec 10, 2024
214dad7
Rename and cleanup
nihalbhatnagar Dec 10, 2024
73fbffa
Fix UUID
nihalbhatnagar Dec 10, 2024
9070c29
Quick fixes
nihalbhatnagar Dec 13, 2024
ac7f03f
Update aggregations syntax
nihalbhatnagar Dec 16, 2024
2777334
Merge branch 'main' into nihalb/rdp-v1
nihalbhatnagar Dec 16, 2024
a8546ca
Update
nihalbhatnagar Dec 18, 2024
0cd49f5
Merge branch 'main' into nihalb/rdp-v1
nihalbhatnagar Jan 8, 2025
0a89f9c
Update names
nihalbhatnagar Jan 8, 2025
a2f331d
Updated types to produce a shorter definition and also allows us to c…
nihalbhatnagar Jan 15, 2025
bec53ca
Updated tests
nihalbhatnagar Jan 15, 2025
d8fa066
Update tests
nihalbhatnagar Jan 15, 2025
ecb0522
Merge branch 'main' into nihalb/rdp-v1
nihalbhatnagar Jan 15, 2025
abc0b2d
Update to no longer use definitionId
nihalbhatnagar Jan 16, 2025
831f890
Additional type test
nihalbhatnagar Jan 16, 2025
a270994
Rework RDP types (#1113)
ericanderson Jan 27, 2025
7a8847f
Reorganize files and rename Rdp to DerivedProperty
nihalbhatnagar Jan 28, 2025
2659b3b
Osdk.Instance<> for RDP's
nihalbhatnagar Jan 29, 2025
1167fae
Refactor tests
nihalbhatnagar Jan 29, 2025
330dac1
Merge branch 'main' into nihalb/rdp-v1
nihalbhatnagar Jan 29, 2025
eb99bab
Add tests back
nihalbhatnagar Jan 29, 2025
c5686e0
Remove comment
nihalbhatnagar Jan 30, 2025
624b662
Simplify types
ericanderson Jan 30, 2025
2812538
slim the delta more
ericanderson Jan 30, 2025
c2c675f
Update names of builders
nihalbhatnagar Jan 30, 2025
95829f8
Use types instead of interfaces to support better hover
nihalbhatnagar Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 64 additions & 60 deletions etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,38 @@ export interface DataValueWireToClient {
}[];
}

// @public (undocumented)
export namespace DerivedProperty {
// Warning: (ae-forgotten-export) The symbol "FilterableBuilder" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface Builder<Q extends ObjectOrInterfaceDefinition> extends FilterableBuilder<Q> {
// Warning: (ae-forgotten-export) The symbol "SelectPropertyBuilder" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DefaultBuilder" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly pivotTo: <L extends LinkNames<Q>>(type: L) => NonNullable<CompileTimeMetadata<Q>["links"][L]["multiplicity"]> extends false ? SelectPropertyBuilder<LinkedType<Q, L>> : DefaultBuilder<LinkedType<Q, L>>;
}
// (undocumented)
export namespace Builder {
// Warning: (ae-forgotten-export) The symbol "AggregatableBuilder" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface Full<Q extends ObjectOrInterfaceDefinition> extends DerivedProperty.Builder<Q>, AggregatableBuilder<Q>, SelectPropertyBuilder<Q> {}
}
// (undocumented)
export type Clause<Q extends ObjectOrInterfaceDefinition> = { [key: string]: Selector<Q, SimplePropertyDef> };
// (undocumented)
export type Selector<
Q extends ObjectOrInterfaceDefinition,
T extends SimplePropertyDef
> = (baseObjectSet: DerivedProperty.Builder<Q>) => SelectorResult<T>;
// Warning: (ae-forgotten-export) The symbol "SimplePropertyDef" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export type SelectorResult<T extends SimplePropertyDef> = { type: T };
}

// @public (undocumented)
export const DistanceUnitMapping: {
centimeter: "CENTIMETERS";
Expand Down Expand Up @@ -655,19 +687,14 @@ export type ObjectOrInterfaceDefinition = ObjectTypeDefinition | InterfaceDefini

// @public (undocumented)
export namespace ObjectOrInterfaceDefinition {
// Warning: (ae-forgotten-export) The symbol "SimplePropertyDef" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export type WithRdp<K extends ObjectOrInterfaceDefinition, D extends Record<string, SimplePropertyDef>> = {
__DefinitionMetadata: {
properties: {
[T in keyof D]: SimplePropertyDef.ToPropertyDef<D[T]>;
};
props: {
[T in keyof D]: SimplePropertyDef.ToRuntimeProperty<D[T]>;
};
};
} & K;
// (undocumented)
export type WithRdp<
K extends ObjectOrInterfaceDefinition,
D extends Record<string, SimplePropertyDef>
> = { __DefinitionMetadata: {
properties: { [T in keyof D] : SimplePropertyDef.ToPropertyDef<D[T]> };
props: { [T in keyof D] : SimplePropertyDef.ToRuntimeProperty<D[T]> };
} } & K;
}

// Warning: (ae-forgotten-export) The symbol "BaseQueryDataTypeDefinition" needs to be exported by the entry point index.d.ts
Expand All @@ -682,27 +709,28 @@ export interface ObjectQueryDataType<T_Target extends ObjectTypeDefinition = nev

// @public (undocumented)
export namespace ObjectSet {
// (undocumented)
// (undocumented)
export namespace Fns {
// (undocumented)
export interface WithProperties<Q extends ObjectOrInterfaceDefinition = any, D extends Record<string, SimplePropertyDef> = {}> {
// (undocumented)
readonly withProperties: <R extends Record<string, SimplePropertyDef>>(clause: {
[K in keyof R]: Rdp.Selector<Q, R[K]>;
}) => ObjectSet<Q, {
[NN in keyof R | keyof D]: NN extends keyof R ? R[NN] : NN extends keyof D ? D[NN] : never;
}>;
}
}
// (undocumented)
export interface WithProperties<
Q extends ObjectOrInterfaceDefinition = any,
D extends Record<string, SimplePropertyDef> = {}
> {
// (undocumented)
readonly withProperties: <R extends Record<string, SimplePropertyDef>>(clause: { [K in keyof R] : DerivedProperty.Selector<Q, R[K]> }) => ObjectSet<Q, { [NN in keyof R | keyof D] : NN extends keyof R ? R[NN] : NN extends keyof D ? D[NN] : never }>;
}
}
}

// Warning: (ae-forgotten-export) The symbol "ObjectSetPrime" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeObjectSet" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExtractRdp" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export interface ObjectSet<Q extends ObjectOrInterfaceDefinition = any, D extends ObjectSet<Q, any> | Record<string, SimplePropertyDef> = ObjectSet<Q, any>> extends ObjectSetPrime<MergeObjectSet<Q, D>>, ObjectSet.Fns.WithProperties<Q, ExtractRdp<D>> {
}
export interface ObjectSet<
Q extends ObjectOrInterfaceDefinition = any,
D extends ObjectSet<Q, any> | Record<string, SimplePropertyDef> = ObjectSet<Q, any>
> extends ObjectSetPrime<MergeObjectSet<Q, D>, Q, D>, ObjectSet.Fns.WithProperties<Q, ExtractRdp<D>> {}

// @public (undocumented)
export interface ObjectSetListener<
Expand Down Expand Up @@ -779,8 +807,9 @@ export namespace Osdk {
export type Instance<
Q extends ObjectOrInterfaceDefinition,
OPTIONS extends never | "$rid" = never,
P extends PropertyKeys<Q> = PropertyKeys<Q>
> = OsdkBase<Q> & Pick<CompileTimeMetadata<Q>["props"], GetPropsKeys<Q, P>> & {
P extends PropertyKeys<Q> = PropertyKeys<Q>,
R extends Record<string, SimplePropertyDef> = never
> = OsdkBase<Q> & Pick<CompileTimeMetadata<Q>["props"], GetPropsKeys<Q, P, [R] extends [never] ? false : true>> & ([R] extends [never] ? {} : { [A in keyof R] : SimplePropertyDef.ToRuntimeProperty<R[A]> }) & {
readonly $link: Q extends { linksType?: any } ? Q["linksType"] : Q extends ObjectTypeDefinition ? OsdkObjectLinksObject<Q> : never;
readonly $as: <NEW_Q extends ValidToFrom<Q>>(type: NEW_Q | string) => Osdk.Instance<NEW_Q, OPTIONS, ConvertProps<Q, NEW_Q, P>>;
} & (IsNever<OPTIONS> extends true ? {} : IsAny<OPTIONS> extends true ? {} : "$rid" extends OPTIONS ? { readonly $rid: string } : {});
Expand Down Expand Up @@ -971,33 +1000,6 @@ export namespace QueryResult {
export type PrimitiveType<T extends keyof DataValueClientToWire> = DataValueWireToClient[T];
}

// @public (undocumented)
export namespace Rdp {
// Warning: (ae-forgotten-export) The symbol "BaseWithPropertyObjectSet" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface Builder<Q extends ObjectOrInterfaceDefinition> extends BaseWithPropertyObjectSet<Q> {
}
// (undocumented)
export namespace Builder {
// Warning: (ae-forgotten-export) The symbol "WithPropertyObjectSet" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface Full<Q extends ObjectOrInterfaceDefinition> extends WithPropertyObjectSet<Q> {
}
}
// (undocumented)
export type Clause<Q extends ObjectOrInterfaceDefinition> = {
[key: string]: Selector<Q, SimplePropertyDef>;
};
// (undocumented)
export type Selector<Q extends ObjectOrInterfaceDefinition, T extends SimplePropertyDef> = (baseObjectSet: Rdp.Builder<Q>) => SelectorResult<T>;
// (undocumented)
export type SelectorResult<T extends SimplePropertyDef> = {
type: T;
};
}

// Warning: (ae-forgotten-export) The symbol "ErrorResult" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand Down Expand Up @@ -1126,11 +1128,13 @@ export type TwoDimensionalQueryAggregationDefinition = AggregationKeyDataType<"d
// Warning: (ae-forgotten-export) The symbol "GetWirePropertyValueFromClient" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type ValidAggregationKeys<Q extends ObjectOrInterfaceDefinition, R extends "aggregate" | "withPropertiesAggregate" = "aggregate"> = keyof ({
[KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<GetWirePropertyValueFromClient<CompileTimeMetadata<Q>["properties"][KK]["type"]>, R extends "aggregate" ? true : false>}`]?: any;
} & {
$count?: any;
});
export type ValidAggregationKeys<
Q extends ObjectOrInterfaceDefinition,
R extends "aggregate" | "withPropertiesAggregate" = "aggregate"
> = keyof ({ [KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<GetWirePropertyValueFromClient<CompileTimeMetadata<Q>["properties"][KK]["type"]>, R extends "aggregate" ? true : false>}`]? : any } & { $count?: any });

// @public (undocumented)
export type ValidBaseActionParameterTypes = "boolean" | "string" | "integer" | "long" | "double" | "datetime" | "timestamp" | "attachment" | "marking" | "objectType";

// Warning: (ae-forgotten-export) The symbol "VersionString" needs to be exported by the entry point index.d.ts
//
Expand Down
10 changes: 8 additions & 2 deletions packages/api/src/OsdkObjectFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
CompileTimeMetadata,
ObjectTypeDefinition,
} from "./ontology/ObjectTypeDefinition.js";
import type { SimplePropertyDef } from "./ontology/SimplePropertyDef.js";
import type { OsdkBase } from "./OsdkBase.js";

type DropDollarOptions<T extends string> = Exclude<
Expand Down Expand Up @@ -154,7 +155,8 @@ export type IsAny<T> = unknown extends T
export type GetPropsKeys<
Q extends ObjectOrInterfaceDefinition,
P extends PropertyKeys<Q>,
> = IsNever<P> extends true ? PropertyKeys<Q>
N extends boolean = false,
> = IsNever<P> extends true ? N extends true ? never : PropertyKeys<Q>
: IsAny<P> extends true ? PropertyKeys<Q>
: P;

Expand Down Expand Up @@ -185,12 +187,16 @@ export namespace Osdk {
Q extends ObjectOrInterfaceDefinition,
OPTIONS extends never | "$rid" = never,
P extends PropertyKeys<Q> = PropertyKeys<Q>,
R extends Record<string, SimplePropertyDef> = never,
> =
& OsdkBase<Q>
& Pick<
CompileTimeMetadata<Q>["props"],
GetPropsKeys<Q, P>
// If there aren't any additional properties, then we want GetPropsKeys to default to PropertyKeys<Q>
GetPropsKeys<Q, P, [R] extends [never] ? false : true>
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor Author

@nihalbhatnagar nihalbhatnagar Jan 30, 2025

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.

>
& ([R] extends [never] ? {}
: { [A in keyof R]: SimplePropertyDef.ToRuntimeProperty<R[A]> })
& {
readonly $link: Q extends { linksType?: any } ? Q["linksType"]
: Q extends ObjectTypeDefinition ? OsdkObjectLinksObject<Q>
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/aggregate/AggregatableKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type {
NumericWithPropAggregateOption,
StringWithPropAggregateOption,
} from "../derivedProperties/WithPropertyObjectSet.js";
} from "../derivedProperties/WithPropertiesAggregationOptions.js";
import type {
GetWirePropertyValueFromClient,
} from "../mapping/PropertyValueMapping.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <
Expand All @@ -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
Expand All @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The 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"],
Expand All @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>>;
}
Loading
Loading