From 8be132d026d04fe23dbab28fdddfe4e540df4c3b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:01:33 -0400 Subject: [PATCH] rc-0.6.0 (#184) Co-authored-by: purplenicole730 Co-authored-by: Nicole Jung <31713368+purplenicole730@users.noreply.github.com> Co-authored-by: Cheuk <90270663+cheukt@users.noreply.github.com> Co-authored-by: clintpurser Co-authored-by: Maxim Pertsov --- package-lock.json | 4 ++-- package.json | 2 +- src/app/data-client.test.ts | 4 ++-- src/app/data-client.ts | 32 +++++++++++++++++++++++++------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 504f868f5..27c3bcf24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@viamrobotics/sdk", - "version": "0.5.0", + "version": "0.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@viamrobotics/sdk", - "version": "0.5.0", + "version": "0.6.0", "license": "Apache-2.0", "dependencies": { "@viamrobotics/rpc": "^0.1.38", diff --git a/package.json b/package.json index a7694f185..b31344353 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app/data-client.test.ts b/src/app/data-client.test.ts index 41c687b72..15759b9cb 100644 --- a/src/app/data-client.test.ts +++ b/src/app/data-client.test.ts @@ -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 () => { diff --git a/src/app/data-client.ts b/src/app/data-client.ts index c4a8a2299..f9b8d0ec0 100644 --- a/src/app/data-client.ts +++ b/src/app/data-client.ts @@ -14,8 +14,8 @@ export type FilterOptions = Partial & { }; type TabularData = { - data?: googleStructPb.Struct.AsObject; - metadataIndex: number; + data?: { [key: string]: googleStructPb.JavaScriptValue }; + metadata?: pb.CaptureMetadata.AsObject; timeRequested?: Date; timeReceived?: Date; }; @@ -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; @@ -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(); }