Skip to content

Commit

Permalink
RSDK-9147: Change Typescript TabularDataBySQL/MQL return type to raw …
Browse files Browse the repository at this point in the history
…BSON (#401)
  • Loading branch information
jckras authored Nov 1, 2024
1 parent 3aeb2eb commit fc06201
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@bufbuild/protobuf": "^1.10.0",
"@connectrpc/connect": "^1.6.0",
"@connectrpc/connect-web": "^1.6.0",
"bsonfy": "^1.0.2",
"exponential-backoff": "^3.1.1"
},
"devDependencies": {
Expand Down
20 changes: 14 additions & 6 deletions src/app/data-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BSON } from 'bsonfy';
import { Struct, Timestamp, type JsonValue } from '@bufbuild/protobuf';
import { createRouterTransport, type Transport } from '@connectrpc/connect';
import { beforeEach, describe, expect, it, vi } from 'vitest';
Expand Down Expand Up @@ -86,6 +87,7 @@ describe('DataClient tests', () => {
const lastId = 'lastId';
const countOnly = true;
const includeInternalData = false;
const startDate = new Date(1, 1, 1, 1, 1, 1);

const binaryId1 = new BinaryID({
fileId: 'testFileId1',
Expand All @@ -99,16 +101,17 @@ describe('DataClient tests', () => {
});

describe('tabularDataBySQL tests', () => {
const data: Record<string, JsonValue>[] = [
{ key1: 1, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
type returnType = JsonValue | Date;
const data: Record<string, returnType>[] = [
{ key1: startDate, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
];

beforeEach(() => {
mockTransport = createRouterTransport(({ service }) => {
service(DataService, {
tabularDataBySQL: () => {
return new TabularDataBySQLResponse({
data: data.map((x) => Struct.fromJson(x)),
rawData: data.map((x) => BSON.serialize(x)),
});
},
});
Expand All @@ -120,21 +123,24 @@ describe('DataClient tests', () => {
'some_org_id',
'some_sql_query'
);
const result = promise as typeof data;
expect(result[0]?.key1).toBeInstanceOf(Date);
expect(promise).toEqual(data);
});
});

describe('tabularDataByMQL tests', () => {
const data: Record<string, JsonValue>[] = [
{ key1: 1, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
type returnType = JsonValue | Date;
const data: Record<string, returnType>[] = [
{ key1: startDate, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
];

beforeEach(() => {
mockTransport = createRouterTransport(({ service }) => {
service(DataService, {
tabularDataByMQL: () => {
return new TabularDataByMQLResponse({
data: data.map((x) => Struct.fromJson(x)),
rawData: data.map((x) => BSON.serialize(x)),
});
},
});
Expand All @@ -145,6 +151,8 @@ describe('DataClient tests', () => {
const promise = await subject().tabularDataByMQL('some_org_id', [
new TextEncoder().encode('some_mql_query'),
]);
const result = promise as typeof data;
expect(result[0]?.key1).toBeInstanceOf(Date);
expect(promise).toEqual(data);
});
});
Expand Down
5 changes: 3 additions & 2 deletions src/app/data-client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BSON } from 'bsonfy';
import { Struct, Timestamp, type JsonValue } from '@bufbuild/protobuf';
import {
createPromiseClient,
Expand Down Expand Up @@ -64,7 +65,7 @@ export class DataClient {
organizationId,
sqlQuery: query,
});
return resp.data.map((value) => value.toJson());
return resp.rawData.map((value) => BSON.deserialize(value));
}

/**
Expand All @@ -79,7 +80,7 @@ export class DataClient {
organizationId,
mqlBinary: query,
});
return resp.data.map((value) => value.toJson());
return resp.rawData.map((value) => BSON.deserialize(value));
}

/**
Expand Down

0 comments on commit fc06201

Please sign in to comment.