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

Add structs read support #1047

Merged
merged 10 commits into from
Dec 16, 2024
Merged

Add structs read support #1047

merged 10 commits into from
Dec 16, 2024

Conversation

ssanjay1
Copy link
Contributor

@ssanjay1 ssanjay1 commented Dec 7, 2024

No description provided.

type: "base",
objectType: "ToDo",
},
const grouped = await client(objectTypeWithAllPropertyTypes).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.

For some reason type tests were having issues when using the aggregate function directly, but were all good when using the user exposed aggregate function. This should be fine since the user facing stuff works, but just flagging

Copy link
Member

Choose a reason for hiding this comment

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

hmm, that seems off. what kind of issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, the aggregate function was not capturing clause types correctly and everything was still in generic form (e.g. like it wasn't getting the concrete information passed in $select: {myProp:asc}

@@ -46,6 +46,8 @@ export function wirePropertyV2ToSdkPrimaryKeyTypeDefinition(
case "float":
case "geotimeSeriesReference":
case "mediaReference":
case "struct":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know we want to ignore these property types instead of throwing errors for unsupported, but saving as a separate PR since structs is higher prio.

structMap[structField.apiName] =
objectPropertyTypeToSdkPropertyDefinition(
structField.dataType,
) as SimpleWirePropertyTypes;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fine because right now, structs can only be field -> simple property type, cannot have nested structs yet in OSS

type: "struct",
structFieldTypes: Object.entries(t.type).map(([apiName, dataType]) => ({
apiName,
dataType: { type: dataType } as ObjectPropertyType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This cast should also be fine because the maker package only uses this for primary key types, which are limited to a select few primitive types

Copy link
Member

@ericanderson ericanderson left a comment

Choose a reason for hiding this comment

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

I think we should try to break less

@@ -37,6 +40,9 @@ import {
type Mock,
vi,
} from "vitest";
import type { getWirePropertyValueFromClient } from "../../../api/build/esm/mapping/PropertyValueMapping.js";
Copy link
Member

Choose a reason for hiding this comment

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

bad import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch

type: "base",
objectType: "ToDo",
},
const grouped = await client(objectTypeWithAllPropertyTypes).aggregate(
Copy link
Member

Choose a reason for hiding this comment

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

hmm, that seems off. what kind of issues?

@@ -71,3 +78,9 @@ export interface PropertyValueClientToWire {
sensorTimeseries: TimeSeriesProperty<string | number>;
geotimeSeriesReference: GeotimeSeriesProperty<GeoJSON.Point>;
}
export type getWirePropertyValueFromClient<
Copy link
Member

Choose a reason for hiding this comment

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

I find this type being lower case to be a bit confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah no I agree, bad convention on my part

@@ -15,6 +15,10 @@
*/

export type WirePropertyTypes =
Copy link
Member

Choose a reason for hiding this comment

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

Should this be WireAndStructPropertyTypes? That way we don't break WirePropertyTypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked a bit on slack, just to clarify here as well, the reason you think this is a break is because now instead of just a list of strings, its SimpleWirePropertyTypes and the record type? Because technically this boils down to the same thing and is just an additive change, but if someone is using this type, could be confusing since now it referencs something called SimpleWirePropertyTypes?

| keyof PropertyValueClientToWire
| Record<string, keyof PropertyValueClientToWire>,
> = T extends keyof PropertyValueClientToWire ? PropertyValueClientToWire[T]
: T;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm being a bit silly but I'm not understanding why this type works. Why doesn't it need to be nested to be kind of like T extends keyof PropertyValueClientToWire ? PropertyValueClientToWire[T] : {[K in T]: PropertyValueClientToWire[K]};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmm actually, this is a good point. We should still remap the inner types of the struct. We mainly use this type for agg results which isn't supported for structs yet, but I added some tests to make sure this works as intended

@ssanjay1 ssanjay1 merged commit abfe4b3 into main Dec 16, 2024
8 checks passed
@ssanjay1 ssanjay1 deleted the ssanjay/structsReads branch December 16, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants