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 no query support for timeseries #508

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/hip-cameras-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@osdk/shared.test": patch
"@osdk/client.api": patch
"@osdk/client": patch
---

Add support for no query time series pulls.
4 changes: 2 additions & 2 deletions etc/client.api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,9 @@ export interface TimeSeriesPoint<T extends string | number> {
// @public (undocumented)
export interface TimeSeriesProperty<T extends number | string> {
// (undocumented)
asyncIterPoints(query: TimeSeriesQuery): AsyncGenerator<TimeSeriesPoint<T>>;
asyncIterPoints(query?: TimeSeriesQuery): AsyncGenerator<TimeSeriesPoint<T>>;
// (undocumented)
getAllPoints(query: TimeSeriesQuery): Promise<Array<TimeSeriesPoint<T>>>;
getAllPoints(query?: TimeSeriesQuery): Promise<Array<TimeSeriesPoint<T>>>;
// (undocumented)
getFirstPoint(): Promise<TimeSeriesPoint<T>>;
// (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions packages/client.api/src/timeseries/timeseries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ export interface TimeSeriesPoint<T extends string | number> {
export interface TimeSeriesProperty<T extends number | string> {
getFirstPoint(): Promise<TimeSeriesPoint<T>>;
getLastPoint(): Promise<TimeSeriesPoint<T>>;
getAllPoints(query: TimeSeriesQuery): Promise<Array<TimeSeriesPoint<T>>>;
asyncIterPoints(query: TimeSeriesQuery): AsyncGenerator<TimeSeriesPoint<T>>;
getAllPoints(query?: TimeSeriesQuery): Promise<Array<TimeSeriesPoint<T>>>;
asyncIterPoints(query?: TimeSeriesQuery): AsyncGenerator<TimeSeriesPoint<T>>;
}
10 changes: 5 additions & 5 deletions packages/client/src/createTimeseriesProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function createTimeseriesProperty<T extends number | string>(
propertyName,
) as Promise<TimeSeriesPoint<T>>;
},
async getAllPoints(query: TimeSeriesQuery) {
async getAllPoints(query?: TimeSeriesQuery) {
return getAllTimeSeriesPoints(
client,
objectApiName,
Expand All @@ -70,7 +70,7 @@ export function createTimeseriesProperty<T extends number | string>(
);
},

asyncIterPoints(query: TimeSeriesQuery) {
asyncIterPoints(query?: TimeSeriesQuery) {
return iterateTimeSeriesPoints(
client,
objectApiName,
Expand All @@ -87,7 +87,7 @@ async function getAllTimeSeriesPoints<T extends string | number>(
objectApiName: string,
primaryKey: any,
propertyName: string,
body: TimeSeriesQuery,
body?: TimeSeriesQuery,
): Promise<Array<TimeSeriesPoint<T>>> {
const allPoints: Array<TimeSeriesPoint<T>> = [];

Expand All @@ -113,7 +113,7 @@ async function* iterateTimeSeriesPoints<T extends string | number>(
objectApiName: string,
primaryKey: any,
propertyName: string,
body: TimeSeriesQuery,
body?: TimeSeriesQuery,
): AsyncGenerator<TimeSeriesPoint<T>, any, unknown> {
const utf8decoder = new TextDecoder("utf-8");

Expand All @@ -124,7 +124,7 @@ async function* iterateTimeSeriesPoints<T extends string | number>(
objectApiName,
primaryKey,
propertyName,
{ range: getTimeRange(body) },
body ? { range: getTimeRange(body) } : {},
);

const reader = streamPointsIterator.stream().getReader();
Expand Down
39 changes: 39 additions & 0 deletions packages/client/src/object/timeseries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ describe("Timeseries", () => {
}, { time: "2014-04-14", value: 30 }]);
});

it("getAll points with no query works", async () => {
const employee = await client(Employee).fetchOne(50030);
expect(employee.$primaryKey).toEqual(50030);
const points = await employee.employeeStatus?.getAllPoints();
expect(points).toBeDefined();
expect(points!).toEqual([
{ time: "2012-02-12", value: 10 },
{ time: "2012-02-12", value: 10 },
{
time: "2013-03-13",
value: 20,
},
{ time: "2014-04-14", value: 30 },
{ time: "2014-04-14", value: 30 },
]);
});

it("async iter points with absolute range works", async () => {
const employee = await client(Employee).fetchOne(50030);
expect(employee.$primaryKey).toEqual(50030);
Expand All @@ -127,4 +144,26 @@ describe("Timeseries", () => {
value: 20,
}, { time: "2014-04-14", value: 30 }]);
});

it("async iter points with no query", async () => {
const employee = await client(Employee).fetchOne(50030);
expect(employee.$primaryKey).toEqual(50030);
const pointsIter = employee.employeeStatus?.asyncIterPoints();

const points: TimeSeriesPoint<string>[] = [];
for await (const point of pointsIter!) {
points.push(point);
}
expect(points).toBeDefined();
expect(points!).toEqual([
{ time: "2012-02-12", value: 10 },
{ time: "2012-02-12", value: 10 },
{
time: "2013-03-13",
value: 20,
},
{ time: "2014-04-14", value: 30 },
{ time: "2014-04-14", value: 30 },
]);
});
});
3 changes: 3 additions & 0 deletions packages/shared.test/src/stubs/timeseriesRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const noBodyRequest: StreamTimeSeriesPointsRequest = {
range: { type: "absolute" },
};

const noRangeRequest: StreamTimeSeriesPointsRequest = {};

const fromBodyRequest: StreamTimeSeriesPointsRequest = {
range: {
type: "relative",
Expand Down Expand Up @@ -121,6 +123,7 @@ export const streamPointsRequestHandlers: Record<
StreamTimeSeriesPointsResponse
> = {
[stableStringify(noBodyRequest)]: streamPointsNoBody,
[stableStringify(noRangeRequest)]: streamPointsNoBody,
[stableStringify(rangeBodyRequest)]: streamPointsRange,
[stableStringify(fromBodyRequest)]: streamPointsFrom,
[stableStringify(afterBodyRequest)]: streamPointsAfter,
Expand Down