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 all 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
7 changes: 7 additions & 0 deletions .changeset/forty-eggs-check.md
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
104 changes: 69 additions & 35 deletions etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,43 @@ export interface DataValueWireToClient {
}[];
}

// @public (undocumented)
export namespace DerivedProperty {
// Warning: (ae-forgotten-export) The symbol "Aggregatable" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface AggregateBuilder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean
> extends Builder<Q, CONSTRAINED>, Aggregatable<Q> {}
// Warning: (ae-forgotten-export) The symbol "Filterable" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Pivotable" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface Builder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean
> extends Filterable<Q, CONSTRAINED>, Pivotable<Q, CONSTRAINED> {}
// (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, false>) => 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 };
// Warning: (ae-forgotten-export) The symbol "Selectable" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface SelectPropertyBuilder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean
> extends AggregateBuilder<Q, CONSTRAINED>, Selectable<Q> {}
}

// @public (undocumented)
export const DistanceUnitMapping: {
centimeter: "CENTIMETERS";
Expand Down Expand Up @@ -653,6 +690,18 @@ export namespace ObjectMetadata {
// @public (undocumented)
export type ObjectOrInterfaceDefinition = ObjectTypeDefinition | InterfaceDefinition;

// @public (undocumented)
export namespace ObjectOrInterfaceDefinition {
// (undocumented)
export type WithDerivedProperties<
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
//
// @public (undocumented)
Expand All @@ -663,38 +712,15 @@ export interface ObjectQueryDataType<T_Target extends ObjectTypeDefinition = nev
object: string;
}

// Warning: (ae-forgotten-export) The symbol "MinimalObjectSet" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ObjectSetCleanedTypes" 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
// Warning: (ae-forgotten-export) The symbol "MergeObjectSet" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export interface ObjectSet<
Q extends ObjectOrInterfaceDefinition = any,
_UNUSED = any
> extends MinimalObjectSet<Q> {
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-malformed-inline-tag) Expecting a TSDoc tag starting with "{@"
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
readonly aggregate: <AO extends AggregateOpts<Q>>(req: AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<Q, AO>) => Promise<AggregationsResults<Q, AO>>;
readonly fetchOne: Q extends ObjectTypeDefinition ? <
const L extends PropertyKeys<Q>,
const R extends boolean,
const S extends false | "throw" = NullabilityAdherence.Default
>(primaryKey: PrimaryKeyType<Q>, options?: SelectArg<Q, L, R, S>) => Promise<Osdk.Instance<Q, ExtractOptions<R, S>, L>> : never;
readonly fetchOneWithErrors: Q extends ObjectTypeDefinition ? <
L extends PropertyKeys<Q>,
R extends boolean,
S extends false | "throw" = NullabilityAdherence.Default
>(primaryKey: PrimaryKeyType<Q>, options?: SelectArg<Q, L, R, S>) => Promise<Result<Osdk.Instance<Q, ExtractOptions<R, S>, L>>> : never;
readonly intersect: (...objectSets: ReadonlyArray<CompileTimeMetadata<Q>["objectSet"]>) => this;
readonly pivotTo: <L extends LinkNames<Q>>(type: L) => CompileTimeMetadata<LinkedType<Q, L>>["objectSet"];
readonly subscribe: <const P extends PropertyKeys<Q>>(listener: ObjectSetListener<Q, P>, opts?: ObjectSetListenerOptions<Q, P>) => { unsubscribe: () => void };
readonly subtract: (...objectSets: ReadonlyArray<CompileTimeMetadata<Q>["objectSet"]>) => this;
readonly union: (...objectSets: ReadonlyArray<CompileTimeMetadata<Q>["objectSet"]>) => this;
}
UNUSED_OR_RDP extends ObjectSet<Q, any> | Record<string, SimplePropertyDef> = ObjectSet<Q, any>
> extends ObjectSetCleanedTypes<Q, ExtractRdp<UNUSED_OR_RDP>, MergeObjectSet<Q, UNUSED_OR_RDP>> {}

// @public (undocumented)
export interface ObjectSetListener<
Expand Down Expand Up @@ -771,8 +797,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> = {}
> = OsdkBase<Q> & Pick<CompileTimeMetadata<Q>["props"], GetPropsKeys<Q, P, [R] extends [{}] ? 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 @@ -850,7 +877,10 @@ export interface PropertyDef<
}

// @public (undocumented)
export type PropertyKeys<O extends ObjectOrInterfaceDefinition> = keyof NonNullable<O["__DefinitionMetadata"]>["properties"] & string;
export type PropertyKeys<
O extends ObjectOrInterfaceDefinition,
RDPs extends Record<string, SimplePropertyDef> = {}
> = (keyof NonNullable<O["__DefinitionMetadata"]>["properties"] | keyof RDPs) & string;

// @public
export interface PropertyValueWireToClient {
Expand Down Expand Up @@ -999,10 +1029,11 @@ export interface SingleLinkAccessor<T extends ObjectTypeDefinition> {
// @public
export type SingleOsdkResult<
Q extends ObjectOrInterfaceDefinition,
L extends PropertyKeys<Q>,
L extends PropertyKeys<Q> | (keyof RDPs & string),
R extends boolean,
S extends NullabilityAdherence
> = Osdk.Instance<Q, ExtractOptions<R, S>, L>;
S extends NullabilityAdherence,
RDPs extends Record<string, SimplePropertyDef> = {}
> = Osdk.Instance<Q, ExtractOptions<R, S>, PropertyKeys<Q> extends L ? PropertyKeys<Q> : PropertyKeys<Q> & L, { [K in Extract<keyof RDPs, L>] : RDPs[K] }>;

// Warning: (ae-forgotten-export) The symbol "AggregationKeyDataType" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1091,7 +1122,10 @@ 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> = keyof ({ [KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<GetWirePropertyValueFromClient<CompileTimeMetadata<Q>["properties"][KK]["type"]>>}`]? : 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";
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> = {},
> =
& 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 [{}] ? 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>
Expand Down
14 changes: 11 additions & 3 deletions packages/api/src/aggregate/AggregatableKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

import type {
NumericWithPropAggregateOption,
StringWithPropAggregateOption,
} from "../derivedProperties/WithPropertiesAggregationOptions.js";
import type {
GetWirePropertyValueFromClient,
} from "../mapping/PropertyValueMapping.js";
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename U so its clear what that boolean generic is for

? 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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ssanjay1 Is this what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though maybe keeping parity with the other names it should be aggregate | derivedPropertiesAggregate or something along those lines, basically including the word derive

> = keyof (
& {
[
KK in AggregatableKeys<Q> as `${KK & string}:${AGG_FOR_TYPE<
GetWirePropertyValueFromClient<
CompileTimeMetadata<Q>["properties"][KK]["type"]
>
>,
R extends "aggregate" ? true : false
>}`
]?: any;
}
Expand Down
132 changes: 132 additions & 0 deletions packages/api/src/derivedProperties/DerivedProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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, false>,
) => SelectorResult<T>;

export interface Builder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> extends Filterable<Q, CONSTRAINED>, Pivotable<Q, CONSTRAINED> {
}

export interface AggregateBuilder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> extends Builder<Q, CONSTRAINED>, Aggregatable<Q> {
}

export interface SelectPropertyBuilder<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> extends AggregateBuilder<Q, CONSTRAINED>, Selectable<Q> {
}
}

type BuilderTypeFromConstraint<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> = CONSTRAINED extends true ? DerivedProperty.AggregateBuilder<Q, true>
: DerivedProperty.SelectPropertyBuilder<Q, false>;

type Filterable<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> = {
readonly where: (
clause: WhereClause<Q>,
) => BuilderTypeFromConstraint<Q, CONSTRAINED>;
};

type Pivotable<
Q extends ObjectOrInterfaceDefinition,
CONSTRAINED extends boolean,
> = {
readonly pivotTo: <L extends LinkNames<Q>>(
type: L,
) => CONSTRAINED extends true
? DerivedProperty.AggregateBuilder<LinkedType<Q, L>, true>
: NonNullable<CompileTimeMetadata<Q>["links"][L]["multiplicity"]> extends
true ? DerivedProperty.AggregateBuilder<LinkedType<Q, L>, true>
: DerivedProperty.SelectPropertyBuilder<LinkedType<Q, L>, false>;
};

type Aggregatable<
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
>;
};

type Selectable<Q extends ObjectOrInterfaceDefinition> = {
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"]
>
>;
};
Loading
Loading