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

RSDK-5477 - clearer tabular data objects #185

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).toMatchObject({ key: 'value1' });
expect(data2).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