@lightdash/query-sdk 0.2774.0 → 0.2774.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apiTransport.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/query.d.ts +5 -2
- package/dist/query.js +13 -7
- package/dist/types.d.ts +9 -0
- package/package.json +1 -1
package/dist/apiTransport.js
CHANGED
|
@@ -109,7 +109,7 @@ export function createApiTransport(config, adapter) {
|
|
|
109
109
|
descending: s.descending,
|
|
110
110
|
})),
|
|
111
111
|
limit: query.limit,
|
|
112
|
-
tableCalculations:
|
|
112
|
+
tableCalculations: query.tableCalculations,
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
115
|
// Pass label as transport metadata (not in the API body)
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { useLightdash } from './useLightdash';
|
|
|
4
4
|
export { LightdashProvider, useLightdashClient } from './LightdashProvider';
|
|
5
5
|
export { createApiTransport, type FetchAdapter } from './apiTransport';
|
|
6
6
|
export { createPostMessageTransport } from './postMessageTransport';
|
|
7
|
-
export type { Column, Filter, FilterOperator, FilterValue, FormatFunction, LightdashClientConfig, LightdashUser, QueryDefinition, QueryResult, Row, Sort, Transport, UnitOfTime, } from './types';
|
|
7
|
+
export type { Column, Filter, FilterOperator, FilterValue, FormatFunction, LightdashClientConfig, LightdashUser, QueryDefinition, QueryResult, Row, Sort, TableCalculation, Transport, UnitOfTime, } from './types';
|
|
8
8
|
export type { SdkFetchRequest, SdkFetchResponse, SdkReadyMessage, } from './postMessageTransport';
|
package/dist/query.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* The builder is immutable -- each method returns a new instance.
|
|
13
13
|
*/
|
|
14
|
-
import type { Filter, InternalFilterDefinition, QueryDefinition, Sort } from './types';
|
|
14
|
+
import type { Filter, InternalFilterDefinition, QueryDefinition, Sort, TableCalculation } from './types';
|
|
15
15
|
/**
|
|
16
16
|
* Create a query builder for a model.
|
|
17
17
|
*
|
|
@@ -28,12 +28,13 @@ export declare class QueryBuilder {
|
|
|
28
28
|
private readonly _metrics;
|
|
29
29
|
private readonly _filters;
|
|
30
30
|
private readonly _sorts;
|
|
31
|
+
private readonly _tableCalculations;
|
|
31
32
|
private readonly _limit;
|
|
32
33
|
private readonly _label;
|
|
33
34
|
constructor(explore: string, dimensions?: string[], metrics?: string[], filters?: InternalFilterDefinition[], sorts?: {
|
|
34
35
|
fieldId: string;
|
|
35
36
|
descending: boolean;
|
|
36
|
-
}[], limit?: number, label?: string);
|
|
37
|
+
}[], limit?: number, label?: string, tableCalculations?: TableCalculation[]);
|
|
37
38
|
/** Human-readable label for dev tools / query inspector */
|
|
38
39
|
label(name: string): QueryBuilder;
|
|
39
40
|
/** Set dimension fields (GROUP BY columns) */
|
|
@@ -44,6 +45,8 @@ export declare class QueryBuilder {
|
|
|
44
45
|
filters(filters: Filter[]): QueryBuilder;
|
|
45
46
|
/** Add sorts */
|
|
46
47
|
sorts(sorts: Sort[]): QueryBuilder;
|
|
48
|
+
/** Add table calculations (computed columns evaluated after the query) */
|
|
49
|
+
tableCalculations(calcs: TableCalculation[]): QueryBuilder;
|
|
47
50
|
/** Set the maximum number of rows to return (default: 500) */
|
|
48
51
|
limit(n: number): QueryBuilder;
|
|
49
52
|
/** Convert to a plain QueryDefinition object */
|
package/dist/query.js
CHANGED
|
@@ -24,26 +24,27 @@ export function query(modelName) {
|
|
|
24
24
|
return new QueryBuilder(modelName);
|
|
25
25
|
}
|
|
26
26
|
export class QueryBuilder {
|
|
27
|
-
constructor(explore, dimensions = [], metrics = [], filters = [], sorts = [], limit = 500, label) {
|
|
27
|
+
constructor(explore, dimensions = [], metrics = [], filters = [], sorts = [], limit = 500, label, tableCalculations = []) {
|
|
28
28
|
this._explore = explore;
|
|
29
29
|
this._dimensions = dimensions;
|
|
30
30
|
this._metrics = metrics;
|
|
31
31
|
this._filters = filters;
|
|
32
32
|
this._sorts = sorts;
|
|
33
|
+
this._tableCalculations = tableCalculations;
|
|
33
34
|
this._limit = limit;
|
|
34
35
|
this._label = label;
|
|
35
36
|
}
|
|
36
37
|
/** Human-readable label for dev tools / query inspector */
|
|
37
38
|
label(name) {
|
|
38
|
-
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, this._limit, name);
|
|
39
|
+
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, this._limit, name, this._tableCalculations);
|
|
39
40
|
}
|
|
40
41
|
/** Set dimension fields (GROUP BY columns) */
|
|
41
42
|
dimensions(fields) {
|
|
42
|
-
return new QueryBuilder(this._explore, [...this._dimensions, ...fields], this._metrics, this._filters, this._sorts, this._limit, this._label);
|
|
43
|
+
return new QueryBuilder(this._explore, [...this._dimensions, ...fields], this._metrics, this._filters, this._sorts, this._limit, this._label, this._tableCalculations);
|
|
43
44
|
}
|
|
44
45
|
/** Set metric fields (aggregations) */
|
|
45
46
|
metrics(fields) {
|
|
46
|
-
return new QueryBuilder(this._explore, this._dimensions, [...this._metrics, ...fields], this._filters, this._sorts, this._limit, this._label);
|
|
47
|
+
return new QueryBuilder(this._explore, this._dimensions, [...this._metrics, ...fields], this._filters, this._sorts, this._limit, this._label, this._tableCalculations);
|
|
47
48
|
}
|
|
48
49
|
/** Add filters */
|
|
49
50
|
filters(filters) {
|
|
@@ -64,7 +65,7 @@ export class QueryBuilder {
|
|
|
64
65
|
settings: f.unit ? { unitOfTime: f.unit } : null,
|
|
65
66
|
};
|
|
66
67
|
});
|
|
67
|
-
return new QueryBuilder(this._explore, this._dimensions, this._metrics, [...this._filters, ...converted], this._sorts, this._limit, this._label);
|
|
68
|
+
return new QueryBuilder(this._explore, this._dimensions, this._metrics, [...this._filters, ...converted], this._sorts, this._limit, this._label, this._tableCalculations);
|
|
68
69
|
}
|
|
69
70
|
/** Add sorts */
|
|
70
71
|
sorts(sorts) {
|
|
@@ -72,11 +73,15 @@ export class QueryBuilder {
|
|
|
72
73
|
fieldId: s.field,
|
|
73
74
|
descending: s.direction === 'desc',
|
|
74
75
|
}));
|
|
75
|
-
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, [...this._sorts, ...converted], this._limit, this._label);
|
|
76
|
+
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, [...this._sorts, ...converted], this._limit, this._label, this._tableCalculations);
|
|
77
|
+
}
|
|
78
|
+
/** Add table calculations (computed columns evaluated after the query) */
|
|
79
|
+
tableCalculations(calcs) {
|
|
80
|
+
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, this._limit, this._label, [...this._tableCalculations, ...calcs]);
|
|
76
81
|
}
|
|
77
82
|
/** Set the maximum number of rows to return (default: 500) */
|
|
78
83
|
limit(n) {
|
|
79
|
-
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, n, this._label);
|
|
84
|
+
return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, n, this._label, this._tableCalculations);
|
|
80
85
|
}
|
|
81
86
|
/** Convert to a plain QueryDefinition object */
|
|
82
87
|
build() {
|
|
@@ -86,6 +91,7 @@ export class QueryBuilder {
|
|
|
86
91
|
metrics: this._metrics,
|
|
87
92
|
filters: this._filters,
|
|
88
93
|
sorts: this._sorts,
|
|
94
|
+
tableCalculations: this._tableCalculations,
|
|
89
95
|
limit: this._limit,
|
|
90
96
|
...(this._label ? { label: this._label } : {}),
|
|
91
97
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ export type Sort = {
|
|
|
14
14
|
field: string;
|
|
15
15
|
direction: 'asc' | 'desc';
|
|
16
16
|
};
|
|
17
|
+
export type TableCalculation = {
|
|
18
|
+
/** Internal name of the table calculation (used as the field ID in results) */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Display name shown in the UI */
|
|
21
|
+
displayName: string;
|
|
22
|
+
/** SQL expression for the calculation */
|
|
23
|
+
sql: string;
|
|
24
|
+
};
|
|
17
25
|
export type InternalFilterDefinition = {
|
|
18
26
|
fieldId: string;
|
|
19
27
|
operator: string;
|
|
@@ -31,6 +39,7 @@ export type QueryDefinition = {
|
|
|
31
39
|
fieldId: string;
|
|
32
40
|
descending: boolean;
|
|
33
41
|
}[];
|
|
42
|
+
tableCalculations: TableCalculation[];
|
|
34
43
|
limit: number;
|
|
35
44
|
/** Human-readable label for dev tools / query inspector (not sent to the API) */
|
|
36
45
|
label?: string;
|