-
Notifications
You must be signed in to change notification settings - Fork 17
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
Timeseries #435
Conversation
26c668e
to
d34f1f0
Compare
import { DherlihyComplexObject } from "@osdk/examples.basic.sdk"; | ||
import { client } from "./client.js"; | ||
|
||
export async function runTimeseriesTest() { |
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.
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; |
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.
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...
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.
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: { |
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.
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
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.
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>[]; |
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.
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); |
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.
So this is what we discussed, are we still good with this for now?
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.
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, |
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.
Can remove the ternary if we just decide to set the prototype to null
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.
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)); |
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.
Had to revise this because the employeeStatus property now gets functions
}, | ||
] | ||
`); | ||
expect(employees).toMatchObject([ |
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.
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( |
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.
Pulled this parsing helper from the legacy implementation
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.
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"; |
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.
Nit: Unnecessary change?
@@ -139,7 +140,7 @@ export type Osdk< | |||
/** @deprecated use $primaryKey */ | |||
__primaryKey: Q extends ObjectTypeDefinition<any> | |||
? OsdkObjectPrimaryKeyType<Q> | |||
: unknown; | |||
: any; |
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.
Primary key is always string | number
in the fallback case, no? Exposing an any
here is sure to create pain for someone.
packages/client.api/src/index.ts
Outdated
@@ -14,6 +14,8 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
import { TimeseriesDurationMapping } from "./timeseries/timeseries.js"; |
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.
Why do we need this import?
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.
Ah we very much do not, good catch
primaryKey: any, | ||
propertyName: string, | ||
): TimeSeriesProperty<T> { | ||
return { |
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.
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.
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.
Sure will FLUP
}; | ||
} | ||
|
||
async function getAllTimeSeriesPoints<T extends string | number>( |
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.
A few questions:
- Why isn't this function implemented by calling
iterateTimeSeriesPoints
? It feels duplicative and hard to maintain as two parallel code paths. - Should we be exposing a
getAll
here?
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.
- Totally right, I'll do that
- 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: { |
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.
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); |
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.
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, |
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.
Lets restore this one too
const OBJECT_OPEN_CHAR_CODE = 123; // '{' | ||
const OBJECT_CLOSE_CHAR_CODE = 125; // '}' | ||
|
||
export async function* parseStreamedResponse( |
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.
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.
Add timeseries functionality for 2.0 syntax