Skip to content

Commit

Permalink
Adding latestOnly support to getTelemetry (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaya-formant authored Apr 19, 2024
1 parent 2196d1e commit edae8e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/data-sdk/src/api/getTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export async function getTelemetry(
streamNameOrStreamNames: string | string[],
start: Date,
end: Date,
tags?: { [key in string]: string[] }
tags?: { [key in string]: string[] },
latestOnly?: boolean
): Promise<TelemetryResult[]> {
let deviceIds = deviceIdOrDeviceIds;
if (!Array.isArray(deviceIdOrDeviceIds)) {
Expand All @@ -26,6 +27,7 @@ export async function getTelemetry(
names: streamNames,
start: start.toISOString(),
tags,
latestOnly,
}),
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 2 additions & 1 deletion packages/data-sdk/src/devices/BaseDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export abstract class BaseDevice
end: Date,
tags?: { [key in string]: string[] },
limit?: number,
offset?: number
offset?: number,
latestOnly?: boolean
): Promise<TelemetryResult[]>;

protected handleMessage = (peerId: string, message: any) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/data-sdk/src/devices/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ export class Device extends BaseDevice {
end: Date,
tags?: { [key in string]: string[] },
limit?: number,
offset?: number
offset?: number,
latestOnly?: boolean
): Promise<TelemetryResult[]> {
if (limit !== undefined || offset !== undefined) {
throw new Error("Limit and offset are not supported in this method");
Expand All @@ -480,7 +481,8 @@ export class Device extends BaseDevice {
streamNameOrStreamNames,
start,
end,
tags
tags,
latestOnly
);
}

Expand Down
10 changes: 9 additions & 1 deletion packages/data-sdk/src/devices/PeerDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ export class PeerDevice extends BaseDevice {
end: Date,
tags?: { [key in string]: string[] },
limit?: number,
offset?: number
offset?: number,
latestOnly?: boolean
): Promise<TelemetryResult[]> {
if (Array.isArray(streamNameOrStreamNames)) {
throw new Error("Multiple stream names not supported");
}
if (tags) {
throw new Error("Tags not supported");
}

if (latestOnly && limit === undefined) {
limit = 1;
} else if (latestOnly && limit !== undefined) {
throw new Error("latestOnly and limit cannot be used together");
}

let queryUrl = `${
this.peerUrl
}/v1/querydatapoints?stream_name=${streamNameOrStreamNames}&start=${start.toISOString()}&end=${end.toISOString()}`;
Expand Down

0 comments on commit edae8e6

Please sign in to comment.