Skip to content

Commit fc06201

Browse files
authored
RSDK-9147: Change Typescript TabularDataBySQL/MQL return type to raw BSON (#401)
1 parent 3aeb2eb commit fc06201

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@bufbuild/protobuf": "^1.10.0",
5555
"@connectrpc/connect": "^1.6.0",
5656
"@connectrpc/connect-web": "^1.6.0",
57+
"bsonfy": "^1.0.2",
5758
"exponential-backoff": "^3.1.1"
5859
},
5960
"devDependencies": {

src/app/data-client.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BSON } from 'bsonfy';
12
import { Struct, Timestamp, type JsonValue } from '@bufbuild/protobuf';
23
import { createRouterTransport, type Transport } from '@connectrpc/connect';
34
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -86,6 +87,7 @@ describe('DataClient tests', () => {
8687
const lastId = 'lastId';
8788
const countOnly = true;
8889
const includeInternalData = false;
90+
const startDate = new Date(1, 1, 1, 1, 1, 1);
8991

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

101103
describe('tabularDataBySQL tests', () => {
102-
const data: Record<string, JsonValue>[] = [
103-
{ key1: 1, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
104+
type returnType = JsonValue | Date;
105+
const data: Record<string, returnType>[] = [
106+
{ key1: startDate, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
104107
];
105108

106109
beforeEach(() => {
107110
mockTransport = createRouterTransport(({ service }) => {
108111
service(DataService, {
109112
tabularDataBySQL: () => {
110113
return new TabularDataBySQLResponse({
111-
data: data.map((x) => Struct.fromJson(x)),
114+
rawData: data.map((x) => BSON.serialize(x)),
112115
});
113116
},
114117
});
@@ -120,21 +123,24 @@ describe('DataClient tests', () => {
120123
'some_org_id',
121124
'some_sql_query'
122125
);
126+
const result = promise as typeof data;
127+
expect(result[0]?.key1).toBeInstanceOf(Date);
123128
expect(promise).toEqual(data);
124129
});
125130
});
126131

127132
describe('tabularDataByMQL tests', () => {
128-
const data: Record<string, JsonValue>[] = [
129-
{ key1: 1, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
133+
type returnType = JsonValue | Date;
134+
const data: Record<string, returnType>[] = [
135+
{ key1: startDate, key2: '2', key3: [1, 2, 3], key4: { key4sub1: 1 } },
130136
];
131137

132138
beforeEach(() => {
133139
mockTransport = createRouterTransport(({ service }) => {
134140
service(DataService, {
135141
tabularDataByMQL: () => {
136142
return new TabularDataByMQLResponse({
137-
data: data.map((x) => Struct.fromJson(x)),
143+
rawData: data.map((x) => BSON.serialize(x)),
138144
});
139145
},
140146
});
@@ -145,6 +151,8 @@ describe('DataClient tests', () => {
145151
const promise = await subject().tabularDataByMQL('some_org_id', [
146152
new TextEncoder().encode('some_mql_query'),
147153
]);
154+
const result = promise as typeof data;
155+
expect(result[0]?.key1).toBeInstanceOf(Date);
148156
expect(promise).toEqual(data);
149157
});
150158
});

src/app/data-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BSON } from 'bsonfy';
12
import { Struct, Timestamp, type JsonValue } from '@bufbuild/protobuf';
23
import {
34
createPromiseClient,
@@ -64,7 +65,7 @@ export class DataClient {
6465
organizationId,
6566
sqlQuery: query,
6667
});
67-
return resp.data.map((value) => value.toJson());
68+
return resp.rawData.map((value) => BSON.deserialize(value));
6869
}
6970

7071
/**
@@ -79,7 +80,7 @@ export class DataClient {
7980
organizationId,
8081
mqlBinary: query,
8182
});
82-
return resp.data.map((value) => value.toJson());
83+
return resp.rawData.map((value) => BSON.deserialize(value));
8384
}
8485

8586
/**

0 commit comments

Comments
 (0)