Skip to content

Commit

Permalink
rc-0.6.0 (#184)
Browse files Browse the repository at this point in the history
Co-authored-by: purplenicole730 <[email protected]>
Co-authored-by: Nicole Jung <[email protected]>
Co-authored-by: Cheuk <[email protected]>
Co-authored-by: clintpurser <[email protected]>
Co-authored-by: Maxim Pertsov <[email protected]>
  • Loading branch information
6 people authored Oct 31, 2023
1 parent 7e64b0a commit 8be132d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/sdk",
"version": "0.5.0",
"version": "0.6.0",
"description": "",
"main": "./dist/main.umd.js",
"module": "./dist/main.es.js",
Expand Down
4 changes: 2 additions & 2 deletions src/app/data-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe('DataClient tests', () => {
const promise = await subject().tabularDataByFilter();
expect(promise.length).toEqual(2);
const [data1, data2] = promise;
expect(data1).toMatchObject(tabData1.toObject());
expect(data2).toMatchObject(tabData2.toObject());
expect(data1?.data).toMatchObject({ key: 'value1' });
expect(data2?.data).toMatchObject({ key: 'value2' });
});

test('get filtered tabular data', async () => {
Expand Down
32 changes: 25 additions & 7 deletions src/app/data-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export type FilterOptions = Partial<pb.Filter.AsObject> & {
};

type TabularData = {
data?: googleStructPb.Struct.AsObject;
metadataIndex: number;
data?: { [key: string]: googleStructPb.JavaScriptValue };
metadata?: pb.CaptureMetadata.AsObject;
timeRequested?: Date;
timeReceived?: Date;
};
Expand All @@ -27,6 +27,14 @@ export class DataClient {
this.service = new DataServiceClient(serviceHost, grpcOptions);
}

/**
* Filter and download tabular data. The returned metadata might be empty if
* the metadata index of the data is out of the bounds of the returned
* metadata list.
*
* @param filter - Optional `pb.Filter` specifying tabular data to retrieve.
* No `filter` implies all tabular data.
*/
async tabularDataByFilter(filter?: pb.Filter) {
const { service } = this;

Expand All @@ -52,12 +60,22 @@ export class DataClient {
if (!dataList || dataList.length === 0) {
break;
}
const mdListLength = response.getMetadataList().length;

dataArray.push(
...dataList.map((data) => ({
...data.toObject(),
timeRequested: data.getTimeRequested()?.toDate(),
timeReceived: data.getTimeReceived()?.toDate(),
}))
...dataList.map((data) => {
const mdIndex = data.getMetadataIndex();
const metadata =
mdListLength !== 0 && mdIndex >= mdListLength
? new pb.CaptureMetadata().toObject()
: response.getMetadataList()[mdIndex]?.toObject();
return {
data: data.getData()?.toJavaScript(),
metadata,
timeRequested: data.getTimeRequested()?.toDate(),
timeReceived: data.getTimeReceived()?.toDate(),
};
})
);
last = response.getLast();
}
Expand Down

0 comments on commit 8be132d

Please sign in to comment.