Skip to content

Commit 67e95aa

Browse files
committed
types restructure
1 parent 0917f8b commit 67e95aa

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

packages/cubejs-api-gateway/src/helpers/prepareAnnotation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function prepareAnnotation(metaConfig: MetaConfig[], query: any) {
154154
export default prepareAnnotation;
155155
export {
156156
ConfigItem,
157+
GranularityMeta,
157158
annotation,
158159
prepareAnnotation,
159160
};

packages/cubejs-api-gateway/src/helpers/transformData.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@ import { ConfigItem } from './prepareAnnotation';
1212
import { NormalizedQuery, QueryTimeDimension } from '../types/query';
1313
import { QueryType, ResultType, } from '../types/strings';
1414
import { QueryType as QueryTypeEnum, ResultType as ResultTypeEnum, } from '../types/enums';
15-
import { DBResponsePrimitive, DBResponseValue } from '../types/responses';
15+
import { AliasToMemberMap, DBResponsePrimitive, DBResponseValue, TransformDataResponse } from '../types/responses';
1616

1717
const COMPARE_DATE_RANGE_FIELD = 'compareDateRange';
1818
const COMPARE_DATE_RANGE_SEPARATOR = ' - ';
1919
const BLENDING_QUERY_KEY_PREFIX = 'time.';
2020
const BLENDING_QUERY_RES_SEPARATOR = '.';
2121
const MEMBER_SEPARATOR = '.';
2222

23-
/**
24-
* SQL aliases to cube properties hash map.
25-
*/
26-
type AliasToMemberMap = { [alias: string]: string };
27-
2823
/**
2924
* Parse date range value from time dimension.
3025
* @internal
@@ -311,12 +306,7 @@ function transformData(
311306
query: NormalizedQuery,
312307
queryType: QueryType,
313308
resType?: ResultType
314-
): {
315-
members: string[],
316-
dataset: DBResponsePrimitive[][]
317-
} | {
318-
[member: string]: DBResponsePrimitive
319-
}[] {
309+
): TransformDataResponse {
320310
const d = data as { [sqlAlias: string]: DBResponseValue }[];
321311
const membersToAliasMap = getMembers(
322312
queryType,
@@ -364,7 +354,6 @@ function transformData(
364354

365355
export default transformData;
366356
export {
367-
AliasToMemberMap,
368357
COMPARE_DATE_RANGE_FIELD,
369358
COMPARE_DATE_RANGE_SEPARATOR,
370359
BLENDING_QUERY_KEY_PREFIX,

packages/cubejs-api-gateway/src/interfaces.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010

1111
import {
1212
QueryType,
13+
ResultType,
1314
} from './types/enums';
1415

1516
import {
@@ -43,9 +44,24 @@ import {
4344
QueryRequest
4445
} from './types/request';
4546

47+
import {
48+
AliasToMemberMap,
49+
TransformDataResponse
50+
} from './types/responses';
51+
52+
import {
53+
ConfigItem,
54+
GranularityMeta
55+
} from './helpers/prepareAnnotation';
56+
4657
export {
58+
AliasToMemberMap,
59+
TransformDataResponse,
60+
ConfigItem,
61+
GranularityMeta,
4762
QueryTimeDimensionGranularity,
4863
QueryType,
64+
ResultType,
4965
QueryFilter,
5066
LogicalAndFilter,
5167
LogicalOrFilter,

packages/cubejs-api-gateway/src/types/responses.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
* Query 'or'-filters type definition.
3-
*/
41
export type DBResponsePrimitive =
52
null |
63
boolean |
@@ -18,3 +15,8 @@ export type TransformDataResponse = {
1815
} | {
1916
[member: string]: DBResponsePrimitive
2017
}[];
18+
19+
/**
20+
* SQL aliases to cube properties hash map.
21+
*/
22+
export type AliasToMemberMap = { [alias: string]: string };

packages/cubejs-backend-native/js/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import fs from 'fs';
33
import path from 'path';
44
import { Writable } from 'stream';
55
import type { Request as ExpressRequest } from 'express';
6+
import type {
7+
AliasToMemberMap,
8+
TransformDataResponse,
9+
NormalizedQuery,
10+
QueryType,
11+
ResultType,
12+
ConfigItem,
13+
} from '@cubejs-backend/api-gateway';
614
import { CubeStoreResultWrapper } from './CubeStoreResultWrapper';
715

816
export * from './CubeStoreResultWrapper';
@@ -101,6 +109,15 @@ export type SQLInterfaceOptions = {
101109
gatewayPort?: number,
102110
};
103111

112+
export type TransformDataRequest = {
113+
aliasToMemberNameMap: AliasToMemberMap,
114+
annotation: { [member: string]: ConfigItem },
115+
data: { [sqlAlias: string]: unknown }[],
116+
query: NormalizedQuery,
117+
queryType: QueryType,
118+
resType?: ResultType
119+
};
120+
104121
export function loadNative() {
105122
// Development version
106123
if (fs.existsSync(path.join(__dirname, '/../../index.node'))) {
@@ -366,6 +383,12 @@ export const getCubestoreResult = (ref: CubeStoreResultWrapper): ResultRow[] =>
366383
return native.getCubestoreResult(ref);
367384
};
368385

386+
export const transformData = (data: TransformDataRequest): TransformDataResponse => {
387+
const native = loadNative();
388+
389+
return native.transformQueryData(data);
390+
};
391+
369392
export interface PyConfiguration {
370393
repositoryFactory?: (ctx: unknown) => Promise<unknown>,
371394
logger?: (msg: string, params: Record<string, any>) => void,

0 commit comments

Comments
 (0)