Skip to content

Commit 966519a

Browse files
committed
types restructure
1 parent 7d8e843 commit 966519a

File tree

6 files changed

+45
-16
lines changed

6 files changed

+45
-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/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './interfaces';
44
export * from './CubejsHandlerError';
55
export * from './UserError';
66
export { getRequestIdFromRequest } from './requestParser';
7+
export { TransformDataRequest } from './types/responses';

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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/**
2-
* Query 'or'-filters type definition.
3-
*/
1+
import type { ConfigItem } from '../helpers/prepareAnnotation';
2+
import type { NormalizedQuery } from './query';
3+
import type { QueryType, ResultType } from './enums';
4+
45
export type DBResponsePrimitive =
56
null |
67
boolean |
@@ -18,3 +19,17 @@ export type TransformDataResponse = {
1819
} | {
1920
[member: string]: DBResponsePrimitive
2021
}[];
22+
23+
/**
24+
* SQL aliases to cube properties hash map.
25+
*/
26+
export type AliasToMemberMap = { [alias: string]: string };
27+
28+
export type TransformDataRequest = {
29+
aliasToMemberNameMap: { [alias: string]: string },
30+
annotation: { [member: string]: ConfigItem },
31+
data: { [sqlAlias: string]: unknown }[],
32+
query: NormalizedQuery,
33+
queryType: QueryType,
34+
resType?: ResultType
35+
};

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ 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 { TransformDataRequest, TransformDataResponse, } from '@cubejs-backend/api-gateway';
67
import { CubeStoreResultWrapper } from './CubeStoreResultWrapper';
78

89
export * from './CubeStoreResultWrapper';
@@ -366,6 +367,12 @@ export const getCubestoreResult = (ref: CubeStoreResultWrapper): ResultRow[] =>
366367
return native.getCubestoreResult(ref);
367368
};
368369

370+
export const transformData = (data: TransformDataRequest): TransformDataResponse => {
371+
const native = loadNative();
372+
373+
return native.transformQueryData(data);
374+
};
375+
369376
export interface PyConfiguration {
370377
repositoryFactory?: (ctx: unknown) => Promise<unknown>,
371378
logger?: (msg: string, params: Record<string, any>) => void,

0 commit comments

Comments
 (0)