Skip to content

Commit b396b05

Browse files
authored
feat: Update type defs for query transformer (#619) Thanks to @jcw-!
* feat: Update type defs for query transformer * Make dimension on filter optional (prefer member) * Prefer use of member over dimension
1 parent 7788fd4 commit b396b05

File tree

4 files changed

+60
-48
lines changed

4 files changed

+60
-48
lines changed

docs/Cube.js-Backend/@cubejs-backend-server-core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ CubejsServerCore.create({
289289
const user = authInfo.u;
290290
if (user.filterByRegion) {
291291
query.filters.push({
292-
dimension: 'Regions.id',
292+
member: 'Regions.id',
293293
operator: 'equals',
294294
values: [user.regionId]
295295
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
declare module "@cubejs-backend/api-gateway" {
2+
export interface QueryFilter {
3+
member: string;
4+
operator:
5+
| "equals"
6+
| "notEquals"
7+
| "contains"
8+
| "notContains"
9+
| "gt"
10+
| "gte"
11+
| "lt"
12+
| "lte"
13+
| "set"
14+
| "notSet"
15+
| "inDateRange"
16+
| "notInDateRange"
17+
| "beforeDate"
18+
| "afterDate";
19+
values?: string[];
20+
}
21+
22+
export type QueryTimeDimensionGranularity =
23+
| "hour"
24+
| "day"
25+
| "week"
26+
| "month"
27+
| "year";
28+
29+
export interface QueryTimeDimension {
30+
dimension: string;
31+
dateRange?: string[] | string;
32+
granularity?: QueryTimeDimensionGranularity;
33+
}
34+
35+
export interface Query {
36+
measures: string[];
37+
dimensions?: string[];
38+
filters?: QueryFilter[];
39+
timeDimensions?: QueryTimeDimension[];
40+
segments?: string[];
41+
limit?: number;
42+
offset?: number;
43+
order?: "asc" | "desc";
44+
timezone?: string;
45+
renewQuery?: boolean;
46+
ungrouped?: boolean;
47+
}
48+
49+
export interface NormalizedQuery extends Query {
50+
filters?: NormalizedQueryFilter[];
51+
rowLimit?: number;
52+
}
53+
54+
export interface NormalizedQueryFilter extends QueryFilter {
55+
dimension?: string;
56+
}
57+
}

packages/cubejs-api-gateway/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test": "jest"
1616
},
1717
"main": "index.js",
18+
"types": "index.d.ts",
1819
"dependencies": {
1920
"@hapi/joi": "^15.1.1",
2021
"chrono-node": "^1.3.11",

packages/cubejs-server-core/core/index.d.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Response as ExpressResponse,
44
NextFunction as ExpressNextFunction
55
} from "express";
6+
import { NormalizedQuery as Query } from "@cubejs-backend/api-gateway";
67

78
declare module "@cubejs-backend/server-core" {
89
export function create(options?: CreateOptions): any;
@@ -99,51 +100,4 @@ declare module "@cubejs-backend/server-core" {
99100
| "redshift"
100101
| "snowflake"
101102
| "sqlite";
102-
103-
export interface QueryFilter {
104-
member: string;
105-
operator:
106-
| "equals"
107-
| "notEquals"
108-
| "contains"
109-
| "notContains"
110-
| "gt"
111-
| "gte"
112-
| "lt"
113-
| "lte"
114-
| "set"
115-
| "notSet"
116-
| "inDateRange"
117-
| "notInDateRange"
118-
| "beforeDate"
119-
| "afterDate";
120-
values?: string[];
121-
}
122-
123-
export type QueryTimeDimensionGranularity =
124-
| "hour"
125-
| "day"
126-
| "week"
127-
| "month"
128-
| "year";
129-
130-
export interface QueryTimeDimension {
131-
dimension: string;
132-
dateRange?: string[] | string;
133-
granularity?: QueryTimeDimensionGranularity;
134-
}
135-
136-
export interface Query {
137-
measures: string[];
138-
dimensions?: string[];
139-
filters?: QueryFilter[];
140-
timeDimensions?: QueryTimeDimension[];
141-
segments?: string[];
142-
limit?: number;
143-
offset?: number;
144-
order?: "asc" | "desc";
145-
timezone?: string;
146-
renewQuery?: boolean;
147-
ungrouped?: boolean;
148-
}
149103
}

0 commit comments

Comments
 (0)