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

Timeseries #435

Merged
merged 17 commits into from
Jul 23, 2024
Merged

Timeseries #435

merged 17 commits into from
Jul 23, 2024

Conversation

ssanjay1
Copy link
Contributor

@ssanjay1 ssanjay1 commented Jul 2, 2024

Add timeseries functionality for 2.0 syntax

@ssanjay1 ssanjay1 force-pushed the ssanjay/timeseries branch from 26c668e to d34f1f0 Compare July 2, 2024 16:43
@ssanjay1 ssanjay1 changed the base branch from main to ssanjay/codegentimeseries July 2, 2024 16:44
Base automatically changed from ssanjay/codegentimeseries to main July 8, 2024 14:17
@ssanjay1 ssanjay1 marked this pull request as ready for review July 18, 2024 02:23
@ssanjay1 ssanjay1 changed the title WIP Timeseries Timeseries Jul 18, 2024
import { DherlihyComplexObject } from "@osdk/examples.basic.sdk";
import { client } from "./client.js";

export async function runTimeseriesTest() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these just to hit real stack

@@ -139,7 +140,7 @@ export type Osdk<
/** @deprecated use $primaryKey */
__primaryKey: Q extends ObjectTypeDefinition<any>
? OsdkObjectPrimaryKeyType<Q>
: unknown;
: any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to type this as any because unknown doesn't work when we have an interface type. It used to work when PropertyValueClientToWire basically also evaluated to unknown, so it'd be an unknown to unknown check, but now its unknown to string|boolean|number|attachment...

Copy link
Member

Choose a reason for hiding this comment

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

Primary key is always string | number in the fallback case, no? Exposing an any here is sure to create pain for someone.

}
: {
type: "relative",
endTime: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It made the most sense to me to set this as an endtime if the query was after, e.g. give me all the high temperatures 2 weeks after today, will give all the temps from today up to 2 weeks later

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. Can we add an invariant check in this function when not in production mode too? That would help anyone using pure JS (or throwing as any at their code) as well as serve as an extra validation to our own logic.

@@ -167,7 +167,7 @@ describe("convertWireToOsdkObjects", () => {
clientCtx,
[objectFromWire],
undefined,
)) as Osdk<Employee>[];
)) as unknown as Osdk<Employee>[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to do this because Osdk<> type is pretty complex now so it has a hard time casting from Osdk<ObjectOrInterfaceDefinition> to Osdk<myConcreteType>

@@ -50,7 +50,7 @@ export function createOsdkInterface<
};

if (process.env.TARGET !== "browser") {
Object.setPrototypeOf(interfaceHolder, OsdkCustomInspectPrototype);
Object.setPrototypeOf(interfaceHolder, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is what we discussed, are we still good with this for now?

Copy link
Member

Choose a reason for hiding this comment

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

Lets revert this change for now. It only makes sense to do this in non-browser. If it rears its head again, we can come up with a better long term solution.

@@ -38,7 +39,7 @@ import type { PropertyDescriptorRecord } from "./PropertyDescriptorRecord.js";
const objectPrototypeCache = createClientCache(
function(client, objectDef: FetchedObjectTypeDefinition<any, any>) {
return Object.create(
process.env.target !== "browser" ? OsdkCustomInspectPrototype : null,
process.env.target !== "browser" ? null : null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can remove the ternary if we just decide to set the prototype to null

Copy link
Member

Choose a reason for hiding this comment

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

Lets restore this one too

@@ -58,7 +58,18 @@ describe("OsdkObject", () => {

// we should get the employee we requested
const employee = result.data[0];
expect(employee).toEqual(asV2Object(stubData.employee1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to revise this because the employeeStatus property now gets functions

},
]
`);
expect(employees).toMatchObject([
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test checks the same things, just revised so I could tell it to expect anything for the timeseries property

const OBJECT_OPEN_CHAR_CODE = 123; // '{'
const OBJECT_CLOSE_CHAR_CODE = 125; // '}'

export async function* parseStreamedResponse(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pulled this parsing helper from the legacy implementation

Copy link
Member

Choose a reason for hiding this comment

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

Cool with this for now as we know it works but I'm curious if there is something a bit less custom that works out of the box for browsers? Def for a follow up.

import {
type ObjectTypePropertyDefinition,
WirePropertyTypes,
} from "@osdk/api";
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Unnecessary change?

@@ -139,7 +140,7 @@ export type Osdk<
/** @deprecated use $primaryKey */
__primaryKey: Q extends ObjectTypeDefinition<any>
? OsdkObjectPrimaryKeyType<Q>
: unknown;
: any;
Copy link
Member

Choose a reason for hiding this comment

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

Primary key is always string | number in the fallback case, no? Exposing an any here is sure to create pain for someone.

@@ -14,6 +14,8 @@
* limitations under the License.
*/

import { TimeseriesDurationMapping } from "./timeseries/timeseries.js";
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this 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 we very much do not, good catch

primaryKey: any,
propertyName: string,
): TimeSeriesProperty<T> {
return {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can we convert the implementation of TimeSeriesProperty into a class here (either in this PR or in a followup). It will be a tiny improvement to memory/runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure will FLUP

};
}

async function getAllTimeSeriesPoints<T extends string | number>(
Copy link
Member

Choose a reason for hiding this comment

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

A few questions:

  1. Why isn't this function implemented by calling iterateTimeSeriesPoints? It feels duplicative and hard to maintain as two parallel code paths.
  2. Should we be exposing a getAll here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Totally right, I'll do that
  2. We had a getAll in legacy so I exposed for parity, I don't have enough data on usage here though to see if thats how people use it or not

}
: {
type: "relative",
endTime: {
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. Can we add an invariant check in this function when not in production mode too? That would help anyone using pure JS (or throwing as any at their code) as well as serve as an extra validation to our own logic.

@@ -50,7 +50,7 @@ export function createOsdkInterface<
};

if (process.env.TARGET !== "browser") {
Object.setPrototypeOf(interfaceHolder, OsdkCustomInspectPrototype);
Object.setPrototypeOf(interfaceHolder, null);
Copy link
Member

Choose a reason for hiding this comment

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

Lets revert this change for now. It only makes sense to do this in non-browser. If it rears its head again, we can come up with a better long term solution.

@@ -38,7 +39,7 @@ import type { PropertyDescriptorRecord } from "./PropertyDescriptorRecord.js";
const objectPrototypeCache = createClientCache(
function(client, objectDef: FetchedObjectTypeDefinition<any, any>) {
return Object.create(
process.env.target !== "browser" ? OsdkCustomInspectPrototype : null,
process.env.target !== "browser" ? null : null,
Copy link
Member

Choose a reason for hiding this comment

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

Lets restore this one too

const OBJECT_OPEN_CHAR_CODE = 123; // '{'
const OBJECT_CLOSE_CHAR_CODE = 125; // '}'

export async function* parseStreamedResponse(
Copy link
Member

Choose a reason for hiding this comment

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

Cool with this for now as we know it works but I'm curious if there is something a bit less custom that works out of the box for browsers? Def for a follow up.

@ssanjay1 ssanjay1 merged commit 489d13f into main Jul 23, 2024
7 checks passed
@ssanjay1 ssanjay1 deleted the ssanjay/timeseries branch July 23, 2024 13:39
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.

2 participants