drizzle-cube 0.1.0
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/LICENSE +21 -0
- package/dist/adapters/hono/index.js +5 -0
- package/dist/client/index.js +7 -0
- package/dist/server/index.d.ts +495 -0
- package/dist/server/index.js +624 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Drizzle Cube
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
export declare interface CompiledCube extends SemanticCube {
|
|
2
|
+
queryFn: (query: SemanticQuery, context: SecurityContext) => Promise<QueryResult>;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a new semantic layer instance
|
|
7
|
+
* Use this when you need multiple isolated instances
|
|
8
|
+
*/
|
|
9
|
+
export declare function createSemanticLayer(dbExecutor?: DatabaseExecutor): SemanticLayerCompiler;
|
|
10
|
+
|
|
11
|
+
export declare interface CubeMetadata {
|
|
12
|
+
name: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
measures: MeasureMetadata[];
|
|
16
|
+
dimensions: DimensionMetadata[];
|
|
17
|
+
segments: any[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare interface DatabaseExecutor {
|
|
21
|
+
execute(sql: string, params?: any[]): Promise<any[]>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Main semantic layer instance
|
|
26
|
+
* Use this for simple single-instance usage
|
|
27
|
+
*/
|
|
28
|
+
export declare const defaultSemanticLayer: SemanticLayerCompiler;
|
|
29
|
+
|
|
30
|
+
export declare const departmentsCube: SemanticCube;
|
|
31
|
+
|
|
32
|
+
export declare interface DimensionAnnotation {
|
|
33
|
+
title: string;
|
|
34
|
+
shortTitle: string;
|
|
35
|
+
type: string;
|
|
36
|
+
format?: DimensionFormat;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare type DimensionFormat = 'currency' | 'percent' | 'number' | 'date' | 'datetime';
|
|
40
|
+
|
|
41
|
+
export declare interface DimensionMetadata {
|
|
42
|
+
name: string;
|
|
43
|
+
title: string;
|
|
44
|
+
shortTitle: string;
|
|
45
|
+
type: string;
|
|
46
|
+
format?: DimensionFormat;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export declare const employeeDepartmentsCube: SemanticCube;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Example cube definitions for documentation and testing
|
|
54
|
+
* These show the basic patterns for defining cubes
|
|
55
|
+
*/
|
|
56
|
+
export declare const employeesCube: SemanticCube;
|
|
57
|
+
|
|
58
|
+
export declare const exampleCubes: SemanticCube[];
|
|
59
|
+
|
|
60
|
+
export declare type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'notStartsWith' | 'endsWith' | 'notEndsWith' | 'gt' | 'gte' | 'lt' | 'lte' | 'set' | 'notSet' | 'inDateRange' | 'beforeDate' | 'afterDate';
|
|
61
|
+
|
|
62
|
+
export declare interface MeasureAnnotation {
|
|
63
|
+
title: string;
|
|
64
|
+
shortTitle: string;
|
|
65
|
+
type: MeasureType;
|
|
66
|
+
format?: MeasureFormat;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare type MeasureFormat = 'currency' | 'percent' | 'number' | 'integer';
|
|
70
|
+
|
|
71
|
+
export declare interface MeasureMetadata {
|
|
72
|
+
name: string;
|
|
73
|
+
title: string;
|
|
74
|
+
shortTitle: string;
|
|
75
|
+
type: MeasureType;
|
|
76
|
+
format?: MeasureFormat;
|
|
77
|
+
description?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare type MeasureType = 'count' | 'countDistinct' | 'countDistinctApprox' | 'sum' | 'avg' | 'min' | 'max' | 'runningTotal' | 'number';
|
|
81
|
+
|
|
82
|
+
export declare interface QueryContext {
|
|
83
|
+
securityContext: SecurityContext;
|
|
84
|
+
cube: CompiledCube;
|
|
85
|
+
query: SemanticQuery;
|
|
86
|
+
table: {
|
|
87
|
+
[column: string]: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export declare interface QueryResult {
|
|
92
|
+
data: any[];
|
|
93
|
+
annotation: {
|
|
94
|
+
measures: Record<string, MeasureAnnotation>;
|
|
95
|
+
dimensions: Record<string, DimensionAnnotation>;
|
|
96
|
+
segments: Record<string, any>;
|
|
97
|
+
timeDimensions: Record<string, TimeDimensionAnnotation>;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Core types for Drizzle Cube semantic layer
|
|
103
|
+
* Framework-agnostic definitions
|
|
104
|
+
*/
|
|
105
|
+
export declare interface SecurityContext {
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare interface SemanticCube {
|
|
110
|
+
name: string;
|
|
111
|
+
title?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
sql: string | ((context: QueryContext) => SQL | string);
|
|
114
|
+
dimensions: Record<string, SemanticDimension>;
|
|
115
|
+
measures: Record<string, SemanticMeasure>;
|
|
116
|
+
joins?: Record<string, SemanticJoin>;
|
|
117
|
+
public?: boolean;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export declare interface SemanticDimension {
|
|
121
|
+
name: string;
|
|
122
|
+
title?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
type: 'string' | 'number' | 'time' | 'boolean';
|
|
125
|
+
sql: string | ((context: QueryContext) => SQL | string);
|
|
126
|
+
primaryKey?: boolean;
|
|
127
|
+
shown?: boolean;
|
|
128
|
+
format?: DimensionFormat;
|
|
129
|
+
meta?: Record<string, any>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export declare interface SemanticJoin {
|
|
133
|
+
sql: string;
|
|
134
|
+
relationship: 'belongsTo' | 'hasOne' | 'hasMany';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export declare const semanticLayer: SemanticLayerCompiler;
|
|
138
|
+
|
|
139
|
+
export declare class SemanticLayerCompiler {
|
|
140
|
+
private cubes;
|
|
141
|
+
private dbExecutor?;
|
|
142
|
+
constructor(dbExecutor?: DatabaseExecutor);
|
|
143
|
+
setDatabaseExecutor(executor: DatabaseExecutor): void;
|
|
144
|
+
registerCube(cube: SemanticCube): void;
|
|
145
|
+
getCube(name: string): CompiledCube | undefined;
|
|
146
|
+
getAllCubes(): CompiledCube[];
|
|
147
|
+
getMetadata(): CubeMetadata[];
|
|
148
|
+
private validateCube;
|
|
149
|
+
private compileCube;
|
|
150
|
+
private generateCubeMetadata;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Utility functions for working with the semantic layer
|
|
155
|
+
*/
|
|
156
|
+
export declare const SemanticLayerUtils: {
|
|
157
|
+
/**
|
|
158
|
+
* Create a simple query builder
|
|
159
|
+
*/
|
|
160
|
+
query: (_cubeName: string) => {
|
|
161
|
+
measures: (measures: string[]) => {
|
|
162
|
+
dimensions: (dimensions?: string[]) => {
|
|
163
|
+
filters: (filters?: any[]) => {
|
|
164
|
+
timeDimensions: (timeDimensions?: any[]) => {
|
|
165
|
+
limit: (limit?: number) => {
|
|
166
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
167
|
+
measures: string[];
|
|
168
|
+
dimensions: string[];
|
|
169
|
+
filters: any[];
|
|
170
|
+
timeDimensions: any[];
|
|
171
|
+
limit: number | undefined;
|
|
172
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
176
|
+
measures: string[];
|
|
177
|
+
dimensions: string[];
|
|
178
|
+
filters: any[];
|
|
179
|
+
timeDimensions: any[];
|
|
180
|
+
limit: number | undefined;
|
|
181
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
limit: (limit?: number) => {
|
|
185
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
186
|
+
measures: string[];
|
|
187
|
+
dimensions: string[];
|
|
188
|
+
filters: any[];
|
|
189
|
+
timeDimensions: any[];
|
|
190
|
+
limit: number | undefined;
|
|
191
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
195
|
+
measures: string[];
|
|
196
|
+
dimensions: string[];
|
|
197
|
+
filters: any[];
|
|
198
|
+
timeDimensions: any[];
|
|
199
|
+
limit: number | undefined;
|
|
200
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
timeDimensions: (timeDimensions?: any[]) => {
|
|
204
|
+
filters: (filters?: any[]) => {
|
|
205
|
+
limit: (limit?: number) => {
|
|
206
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
207
|
+
measures: string[];
|
|
208
|
+
dimensions: string[];
|
|
209
|
+
filters: any[];
|
|
210
|
+
timeDimensions: any[];
|
|
211
|
+
limit: number | undefined;
|
|
212
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
216
|
+
measures: string[];
|
|
217
|
+
dimensions: string[];
|
|
218
|
+
filters: any[];
|
|
219
|
+
timeDimensions: any[];
|
|
220
|
+
limit: number | undefined;
|
|
221
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
limit: (limit?: number) => {
|
|
225
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
226
|
+
measures: string[];
|
|
227
|
+
dimensions: string[];
|
|
228
|
+
filters: any[];
|
|
229
|
+
timeDimensions: any[];
|
|
230
|
+
limit: number | undefined;
|
|
231
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
235
|
+
measures: string[];
|
|
236
|
+
dimensions: string[];
|
|
237
|
+
filters: any[];
|
|
238
|
+
timeDimensions: any[];
|
|
239
|
+
limit: number | undefined;
|
|
240
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
limit: (limit?: number) => {
|
|
244
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
245
|
+
measures: string[];
|
|
246
|
+
dimensions: string[];
|
|
247
|
+
filters: any[];
|
|
248
|
+
timeDimensions: any[];
|
|
249
|
+
limit: number | undefined;
|
|
250
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
254
|
+
measures: string[];
|
|
255
|
+
dimensions: string[];
|
|
256
|
+
filters: any[];
|
|
257
|
+
timeDimensions: any[];
|
|
258
|
+
limit: number | undefined;
|
|
259
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
filters: (filters?: any[]) => {
|
|
263
|
+
dimensions: (dimensions?: string[]) => {
|
|
264
|
+
timeDimensions: (timeDimensions?: any[]) => {
|
|
265
|
+
limit: (limit?: number) => {
|
|
266
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
267
|
+
measures: string[];
|
|
268
|
+
dimensions: string[];
|
|
269
|
+
filters: any[];
|
|
270
|
+
timeDimensions: any[];
|
|
271
|
+
limit: number | undefined;
|
|
272
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
276
|
+
measures: string[];
|
|
277
|
+
dimensions: string[];
|
|
278
|
+
filters: any[];
|
|
279
|
+
timeDimensions: any[];
|
|
280
|
+
limit: number | undefined;
|
|
281
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
limit: (limit?: number) => {
|
|
285
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
286
|
+
measures: string[];
|
|
287
|
+
dimensions: string[];
|
|
288
|
+
filters: any[];
|
|
289
|
+
timeDimensions: any[];
|
|
290
|
+
limit: number | undefined;
|
|
291
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
295
|
+
measures: string[];
|
|
296
|
+
dimensions: string[];
|
|
297
|
+
filters: any[];
|
|
298
|
+
timeDimensions: any[];
|
|
299
|
+
limit: number | undefined;
|
|
300
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
timeDimensions: (timeDimensions?: any[]) => {
|
|
304
|
+
dimensions: (dimensions?: string[]) => {
|
|
305
|
+
limit: (limit?: number) => {
|
|
306
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
307
|
+
measures: string[];
|
|
308
|
+
dimensions: string[];
|
|
309
|
+
filters: any[];
|
|
310
|
+
timeDimensions: any[];
|
|
311
|
+
limit: number | undefined;
|
|
312
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
316
|
+
measures: string[];
|
|
317
|
+
dimensions: string[];
|
|
318
|
+
filters: any[];
|
|
319
|
+
timeDimensions: any[];
|
|
320
|
+
limit: number | undefined;
|
|
321
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
limit: (limit?: number) => {
|
|
325
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
326
|
+
measures: string[];
|
|
327
|
+
dimensions: string[];
|
|
328
|
+
filters: any[];
|
|
329
|
+
timeDimensions: any[];
|
|
330
|
+
limit: number | undefined;
|
|
331
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
335
|
+
measures: string[];
|
|
336
|
+
dimensions: string[];
|
|
337
|
+
filters: any[];
|
|
338
|
+
timeDimensions: any[];
|
|
339
|
+
limit: number | undefined;
|
|
340
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
limit: (limit?: number) => {
|
|
344
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
345
|
+
measures: string[];
|
|
346
|
+
dimensions: string[];
|
|
347
|
+
filters: any[];
|
|
348
|
+
timeDimensions: any[];
|
|
349
|
+
limit: number | undefined;
|
|
350
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
order: (order?: Record<string, "asc" | "desc">) => {
|
|
354
|
+
measures: string[];
|
|
355
|
+
dimensions: string[];
|
|
356
|
+
filters: any[];
|
|
357
|
+
timeDimensions: any[];
|
|
358
|
+
limit: number | undefined;
|
|
359
|
+
order: Record<string, "asc" | "desc"> | undefined;
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Create filters
|
|
366
|
+
*/
|
|
367
|
+
filters: {
|
|
368
|
+
equals: (member: string, value: any) => {
|
|
369
|
+
member: string;
|
|
370
|
+
operator: "equals";
|
|
371
|
+
values: any[];
|
|
372
|
+
};
|
|
373
|
+
notEquals: (member: string, value: any) => {
|
|
374
|
+
member: string;
|
|
375
|
+
operator: "notEquals";
|
|
376
|
+
values: any[];
|
|
377
|
+
};
|
|
378
|
+
contains: (member: string, value: string) => {
|
|
379
|
+
member: string;
|
|
380
|
+
operator: "contains";
|
|
381
|
+
values: string[];
|
|
382
|
+
};
|
|
383
|
+
greaterThan: (member: string, value: any) => {
|
|
384
|
+
member: string;
|
|
385
|
+
operator: "gt";
|
|
386
|
+
values: any[];
|
|
387
|
+
};
|
|
388
|
+
lessThan: (member: string, value: any) => {
|
|
389
|
+
member: string;
|
|
390
|
+
operator: "lt";
|
|
391
|
+
values: any[];
|
|
392
|
+
};
|
|
393
|
+
inDateRange: (member: string, from: string, to: string) => {
|
|
394
|
+
member: string;
|
|
395
|
+
operator: "inDateRange";
|
|
396
|
+
values: string[];
|
|
397
|
+
};
|
|
398
|
+
set: (member: string) => {
|
|
399
|
+
member: string;
|
|
400
|
+
operator: "set";
|
|
401
|
+
values: never[];
|
|
402
|
+
};
|
|
403
|
+
notSet: (member: string) => {
|
|
404
|
+
member: string;
|
|
405
|
+
operator: "notSet";
|
|
406
|
+
values: never[];
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Create time dimensions
|
|
411
|
+
*/
|
|
412
|
+
timeDimensions: {
|
|
413
|
+
create: (dimension: string, granularity?: TimeGranularity, dateRange?: string | string[]) => {
|
|
414
|
+
dimension: string;
|
|
415
|
+
granularity: TimeGranularity | undefined;
|
|
416
|
+
dateRange: string | string[] | undefined;
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export declare interface SemanticMeasure {
|
|
422
|
+
name: string;
|
|
423
|
+
title?: string;
|
|
424
|
+
description?: string;
|
|
425
|
+
type: MeasureType;
|
|
426
|
+
sql: string | ((context: QueryContext) => SQL | string);
|
|
427
|
+
format?: MeasureFormat;
|
|
428
|
+
filters?: Array<{
|
|
429
|
+
sql: string;
|
|
430
|
+
}>;
|
|
431
|
+
rollingWindow?: {
|
|
432
|
+
trailing?: string;
|
|
433
|
+
leading?: string;
|
|
434
|
+
offset?: string;
|
|
435
|
+
};
|
|
436
|
+
meta?: Record<string, any>;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export declare interface SemanticQuery {
|
|
440
|
+
measures?: string[];
|
|
441
|
+
dimensions?: string[];
|
|
442
|
+
filters?: Array<{
|
|
443
|
+
member: string;
|
|
444
|
+
operator: FilterOperator;
|
|
445
|
+
values: any[];
|
|
446
|
+
}>;
|
|
447
|
+
timeDimensions?: Array<{
|
|
448
|
+
dimension: string;
|
|
449
|
+
granularity?: TimeGranularity;
|
|
450
|
+
dateRange?: string | string[];
|
|
451
|
+
}>;
|
|
452
|
+
limit?: number;
|
|
453
|
+
offset?: number;
|
|
454
|
+
order?: Record<string, 'asc' | 'desc'>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export declare class SemanticQueryExecutor {
|
|
458
|
+
private dbExecutor;
|
|
459
|
+
constructor(dbExecutor: DatabaseExecutor);
|
|
460
|
+
executeQuery(cube: SemanticCube, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
|
|
461
|
+
generateSQL(cube: SemanticCube, query: SemanticQuery, securityContext: SecurityContext): {
|
|
462
|
+
sql: string;
|
|
463
|
+
params?: any[];
|
|
464
|
+
};
|
|
465
|
+
private substituteSecurityVariables;
|
|
466
|
+
private buildSelectClause;
|
|
467
|
+
private buildMeasureSQL;
|
|
468
|
+
private buildWhereClause;
|
|
469
|
+
private buildFilterCondition;
|
|
470
|
+
private buildGroupByClause;
|
|
471
|
+
private buildOrderByClause;
|
|
472
|
+
private buildLimitClause;
|
|
473
|
+
private generateAnnotations;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export declare interface SQL {
|
|
477
|
+
sql: string;
|
|
478
|
+
params?: any[];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export declare interface SqlResult {
|
|
482
|
+
sql: string;
|
|
483
|
+
params?: any[];
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export declare interface TimeDimensionAnnotation {
|
|
487
|
+
title: string;
|
|
488
|
+
shortTitle: string;
|
|
489
|
+
type: string;
|
|
490
|
+
granularity?: TimeGranularity;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export declare type TimeGranularity = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
494
|
+
|
|
495
|
+
export { }
|
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var y = (l, e, n) => e in l ? u(l, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : l[e] = n;
|
|
3
|
+
var c = (l, e, n) => y(l, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
class f {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.dbExecutor = e;
|
|
7
|
+
}
|
|
8
|
+
async executeQuery(e, n, i) {
|
|
9
|
+
try {
|
|
10
|
+
const t = this.generateSQL(e, n, i), s = await this.dbExecutor.execute(t.sql, t.params), a = this.generateAnnotations(e, n);
|
|
11
|
+
return {
|
|
12
|
+
data: s,
|
|
13
|
+
annotation: a
|
|
14
|
+
};
|
|
15
|
+
} catch (t) {
|
|
16
|
+
throw new Error(`Query execution failed: ${t instanceof Error ? t.message : "Unknown error"}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
generateSQL(e, n, i) {
|
|
20
|
+
const t = this.substituteSecurityVariables(
|
|
21
|
+
typeof e.sql == "string" ? e.sql : e.sql.toString(),
|
|
22
|
+
i
|
|
23
|
+
), s = this.buildSelectClause(e, n), a = this.buildWhereClause(e, n), r = this.buildGroupByClause(e, n), o = this.buildOrderByClause(n), m = this.buildLimitClause(n), p = [
|
|
24
|
+
`SELECT ${s.join(", ")}`,
|
|
25
|
+
`FROM (${t}) as base_query`
|
|
26
|
+
];
|
|
27
|
+
return a && p.push(`WHERE ${a}`), r && p.push(`GROUP BY ${r}`), o && p.push(`ORDER BY ${o}`), m && p.push(m), { sql: p.join(" "), params: [] };
|
|
28
|
+
}
|
|
29
|
+
substituteSecurityVariables(e, n) {
|
|
30
|
+
let i = e;
|
|
31
|
+
return Object.entries(n).forEach(([t, s]) => {
|
|
32
|
+
const a = `\${SECURITY_CONTEXT.${t}}`;
|
|
33
|
+
i = i.replaceAll(a, `'${s}'`);
|
|
34
|
+
}), i;
|
|
35
|
+
}
|
|
36
|
+
buildSelectClause(e, n) {
|
|
37
|
+
const i = [];
|
|
38
|
+
if (n.measures)
|
|
39
|
+
for (const t of n.measures) {
|
|
40
|
+
const [s, a] = t.split(".");
|
|
41
|
+
if (s === e.name && e.measures[a]) {
|
|
42
|
+
const r = e.measures[a], o = this.buildMeasureSQL(r, a);
|
|
43
|
+
i.push(`${o} as "${t}"`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (n.dimensions)
|
|
47
|
+
for (const t of n.dimensions) {
|
|
48
|
+
const [s, a] = t.split(".");
|
|
49
|
+
if (s === e.name && e.dimensions[a]) {
|
|
50
|
+
const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
|
|
51
|
+
i.push(`${o} as "${t}"`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (n.timeDimensions)
|
|
55
|
+
for (const t of n.timeDimensions) {
|
|
56
|
+
const [s, a] = t.dimension.split(".");
|
|
57
|
+
if (s === e.name && e.dimensions[a]) {
|
|
58
|
+
const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
|
|
59
|
+
if (t.granularity) {
|
|
60
|
+
const m = `DATE_TRUNC('${t.granularity}', ${o})`;
|
|
61
|
+
i.push(`${m} as "${t.dimension}"`);
|
|
62
|
+
} else
|
|
63
|
+
i.push(`${o} as "${t.dimension}"`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return i.length > 0 ? i : ["1"];
|
|
67
|
+
}
|
|
68
|
+
buildMeasureSQL(e, n) {
|
|
69
|
+
const i = typeof e.sql == "string" ? e.sql : e.sql.toString();
|
|
70
|
+
switch (e.type) {
|
|
71
|
+
case "count":
|
|
72
|
+
return `COUNT(${i})`;
|
|
73
|
+
case "countDistinct":
|
|
74
|
+
return `COUNT(DISTINCT ${i})`;
|
|
75
|
+
case "sum":
|
|
76
|
+
return `SUM(${i})`;
|
|
77
|
+
case "avg":
|
|
78
|
+
return `AVG(${i})`;
|
|
79
|
+
case "min":
|
|
80
|
+
return `MIN(${i})`;
|
|
81
|
+
case "max":
|
|
82
|
+
return `MAX(${i})`;
|
|
83
|
+
case "number":
|
|
84
|
+
return i;
|
|
85
|
+
default:
|
|
86
|
+
return `COUNT(${i})`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
buildWhereClause(e, n) {
|
|
90
|
+
if (!n.filters || n.filters.length === 0)
|
|
91
|
+
return null;
|
|
92
|
+
const i = [];
|
|
93
|
+
for (const t of n.filters) {
|
|
94
|
+
const [s, a] = t.member.split(".");
|
|
95
|
+
if (s !== e.name) continue;
|
|
96
|
+
const r = e.dimensions[a] || e.measures[a];
|
|
97
|
+
if (!r) continue;
|
|
98
|
+
const o = typeof r.sql == "string" ? r.sql : r.sql.toString(), m = this.buildFilterCondition(o, t.operator, t.values);
|
|
99
|
+
m && i.push(m);
|
|
100
|
+
}
|
|
101
|
+
return i.length > 0 ? i.join(" AND ") : null;
|
|
102
|
+
}
|
|
103
|
+
buildFilterCondition(e, n, i) {
|
|
104
|
+
const t = i[0], s = typeof t == "string" ? `'${t.replace(/'/g, "''")}'` : t;
|
|
105
|
+
switch (n) {
|
|
106
|
+
case "equals":
|
|
107
|
+
return `${e} = ${s}`;
|
|
108
|
+
case "notEquals":
|
|
109
|
+
return `${e} != ${s}`;
|
|
110
|
+
case "contains":
|
|
111
|
+
return `${e} ILIKE '%${t}%'`;
|
|
112
|
+
case "notContains":
|
|
113
|
+
return `${e} NOT ILIKE '%${t}%'`;
|
|
114
|
+
case "startsWith":
|
|
115
|
+
return `${e} ILIKE '${t}%'`;
|
|
116
|
+
case "endsWith":
|
|
117
|
+
return `${e} ILIKE '%${t}'`;
|
|
118
|
+
case "gt":
|
|
119
|
+
return `${e} > ${s}`;
|
|
120
|
+
case "gte":
|
|
121
|
+
return `${e} >= ${s}`;
|
|
122
|
+
case "lt":
|
|
123
|
+
return `${e} < ${s}`;
|
|
124
|
+
case "lte":
|
|
125
|
+
return `${e} <= ${s}`;
|
|
126
|
+
case "set":
|
|
127
|
+
return `${e} IS NOT NULL`;
|
|
128
|
+
case "notSet":
|
|
129
|
+
return `${e} IS NULL`;
|
|
130
|
+
case "inDateRange":
|
|
131
|
+
return i.length >= 2 ? `${e} BETWEEN '${i[0]}' AND '${i[1]}'` : null;
|
|
132
|
+
case "beforeDate":
|
|
133
|
+
return `${e} < '${t}'`;
|
|
134
|
+
case "afterDate":
|
|
135
|
+
return `${e} > '${t}'`;
|
|
136
|
+
default:
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
buildGroupByClause(e, n) {
|
|
141
|
+
const i = [];
|
|
142
|
+
if (n.dimensions)
|
|
143
|
+
for (const t of n.dimensions) {
|
|
144
|
+
const [s, a] = t.split(".");
|
|
145
|
+
if (s === e.name && e.dimensions[a]) {
|
|
146
|
+
const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
|
|
147
|
+
i.push(o);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (n.timeDimensions)
|
|
151
|
+
for (const t of n.timeDimensions) {
|
|
152
|
+
const [s, a] = t.dimension.split(".");
|
|
153
|
+
if (s === e.name && e.dimensions[a]) {
|
|
154
|
+
const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
|
|
155
|
+
t.granularity ? i.push(`DATE_TRUNC('${t.granularity}', ${o})`) : i.push(o);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return i.length > 0 ? i.join(", ") : null;
|
|
159
|
+
}
|
|
160
|
+
buildOrderByClause(e) {
|
|
161
|
+
if (!e.order || Object.keys(e.order).length === 0)
|
|
162
|
+
return null;
|
|
163
|
+
const n = [];
|
|
164
|
+
for (const [i, t] of Object.entries(e.order))
|
|
165
|
+
n.push(`"${i}" ${t.toUpperCase()}`);
|
|
166
|
+
return n.join(", ");
|
|
167
|
+
}
|
|
168
|
+
buildLimitClause(e) {
|
|
169
|
+
if (!e.limit)
|
|
170
|
+
return null;
|
|
171
|
+
let n = `LIMIT ${e.limit}`;
|
|
172
|
+
return e.offset && (n += ` OFFSET ${e.offset}`), n;
|
|
173
|
+
}
|
|
174
|
+
generateAnnotations(e, n) {
|
|
175
|
+
const i = {}, t = {}, s = {};
|
|
176
|
+
if (n.measures)
|
|
177
|
+
for (const a of n.measures) {
|
|
178
|
+
const [r, o] = a.split(".");
|
|
179
|
+
if (r === e.name && e.measures[o]) {
|
|
180
|
+
const m = e.measures[o];
|
|
181
|
+
i[a] = {
|
|
182
|
+
title: m.title || o,
|
|
183
|
+
shortTitle: m.title || o,
|
|
184
|
+
type: m.type,
|
|
185
|
+
format: m.format
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (n.dimensions)
|
|
190
|
+
for (const a of n.dimensions) {
|
|
191
|
+
const [r, o] = a.split(".");
|
|
192
|
+
if (r === e.name && e.dimensions[o]) {
|
|
193
|
+
const m = e.dimensions[o];
|
|
194
|
+
t[a] = {
|
|
195
|
+
title: m.title || o,
|
|
196
|
+
shortTitle: m.title || o,
|
|
197
|
+
type: m.type,
|
|
198
|
+
format: m.format
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (n.timeDimensions)
|
|
203
|
+
for (const a of n.timeDimensions) {
|
|
204
|
+
const [r, o] = a.dimension.split(".");
|
|
205
|
+
if (r === e.name && e.dimensions[o]) {
|
|
206
|
+
const m = e.dimensions[o];
|
|
207
|
+
s[a.dimension] = {
|
|
208
|
+
title: m.title || o,
|
|
209
|
+
shortTitle: m.title || o,
|
|
210
|
+
type: m.type,
|
|
211
|
+
granularity: a.granularity
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
measures: i,
|
|
217
|
+
dimensions: t,
|
|
218
|
+
segments: {},
|
|
219
|
+
timeDimensions: s
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
class d {
|
|
224
|
+
constructor(e) {
|
|
225
|
+
c(this, "cubes", /* @__PURE__ */ new Map());
|
|
226
|
+
c(this, "dbExecutor");
|
|
227
|
+
this.dbExecutor = e;
|
|
228
|
+
}
|
|
229
|
+
setDatabaseExecutor(e) {
|
|
230
|
+
this.dbExecutor = e;
|
|
231
|
+
}
|
|
232
|
+
registerCube(e) {
|
|
233
|
+
this.validateCube(e);
|
|
234
|
+
const n = this.compileCube(e);
|
|
235
|
+
this.cubes.set(e.name, n);
|
|
236
|
+
}
|
|
237
|
+
getCube(e) {
|
|
238
|
+
return this.cubes.get(e);
|
|
239
|
+
}
|
|
240
|
+
getAllCubes() {
|
|
241
|
+
return Array.from(this.cubes.values());
|
|
242
|
+
}
|
|
243
|
+
getMetadata() {
|
|
244
|
+
return Array.from(this.cubes.values()).map((e) => this.generateCubeMetadata(e));
|
|
245
|
+
}
|
|
246
|
+
validateCube(e) {
|
|
247
|
+
if (!e.name)
|
|
248
|
+
throw new Error("Cube must have a name");
|
|
249
|
+
if (!e.sql)
|
|
250
|
+
throw new Error(`Cube ${e.name} must have SQL definition`);
|
|
251
|
+
if (!e.measures || Object.keys(e.measures).length === 0)
|
|
252
|
+
throw new Error(`Cube ${e.name} must have at least one measure`);
|
|
253
|
+
}
|
|
254
|
+
compileCube(e) {
|
|
255
|
+
return {
|
|
256
|
+
...e,
|
|
257
|
+
queryFn: async (i, t) => {
|
|
258
|
+
if (!this.dbExecutor)
|
|
259
|
+
throw new Error("Database executor not configured. Call setDatabaseExecutor() first.");
|
|
260
|
+
return new f(this.dbExecutor).executeQuery(e, i, t);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
generateCubeMetadata(e) {
|
|
265
|
+
const n = Object.entries(e.measures).map(([t, s]) => ({
|
|
266
|
+
name: `${e.name}.${t}`,
|
|
267
|
+
title: s.title || t,
|
|
268
|
+
shortTitle: s.title || t,
|
|
269
|
+
type: s.type,
|
|
270
|
+
format: s.format,
|
|
271
|
+
description: s.description
|
|
272
|
+
})), i = Object.entries(e.dimensions).map(([t, s]) => ({
|
|
273
|
+
name: `${e.name}.${t}`,
|
|
274
|
+
title: s.title || t,
|
|
275
|
+
shortTitle: s.title || t,
|
|
276
|
+
type: s.type,
|
|
277
|
+
format: s.format,
|
|
278
|
+
description: s.description
|
|
279
|
+
}));
|
|
280
|
+
return {
|
|
281
|
+
name: e.name,
|
|
282
|
+
title: e.title || e.name,
|
|
283
|
+
description: e.description,
|
|
284
|
+
measures: n,
|
|
285
|
+
dimensions: i,
|
|
286
|
+
segments: []
|
|
287
|
+
// Add segments support later if needed
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const E = new d(), g = {
|
|
292
|
+
name: "Employees",
|
|
293
|
+
title: "Employee Analytics",
|
|
294
|
+
description: "Employee data for workforce analysis",
|
|
295
|
+
sql: `
|
|
296
|
+
SELECT
|
|
297
|
+
e.id,
|
|
298
|
+
e.name,
|
|
299
|
+
e.email,
|
|
300
|
+
e.active,
|
|
301
|
+
e.fte_basis,
|
|
302
|
+
e.start_date,
|
|
303
|
+
e.end_date,
|
|
304
|
+
d.name as department_name,
|
|
305
|
+
s.name as supplier_name,
|
|
306
|
+
s.internal as supplier_internal
|
|
307
|
+
FROM employees e
|
|
308
|
+
LEFT JOIN departments d ON e.department = d.id
|
|
309
|
+
LEFT JOIN suppliers s ON e.supplier = s.id
|
|
310
|
+
WHERE e.organisation = \${SECURITY_CONTEXT.organisation}
|
|
311
|
+
`,
|
|
312
|
+
dimensions: {
|
|
313
|
+
id: {
|
|
314
|
+
name: "id",
|
|
315
|
+
title: "Employee ID",
|
|
316
|
+
type: "string",
|
|
317
|
+
sql: "id",
|
|
318
|
+
primaryKey: !0
|
|
319
|
+
},
|
|
320
|
+
name: {
|
|
321
|
+
name: "name",
|
|
322
|
+
title: "Employee Name",
|
|
323
|
+
type: "string",
|
|
324
|
+
sql: "name"
|
|
325
|
+
},
|
|
326
|
+
email: {
|
|
327
|
+
name: "email",
|
|
328
|
+
title: "Email",
|
|
329
|
+
type: "string",
|
|
330
|
+
sql: "email"
|
|
331
|
+
},
|
|
332
|
+
active: {
|
|
333
|
+
name: "active",
|
|
334
|
+
title: "Active Status",
|
|
335
|
+
type: "boolean",
|
|
336
|
+
sql: "active"
|
|
337
|
+
},
|
|
338
|
+
departmentName: {
|
|
339
|
+
name: "departmentName",
|
|
340
|
+
title: "Department",
|
|
341
|
+
type: "string",
|
|
342
|
+
sql: "department_name"
|
|
343
|
+
},
|
|
344
|
+
supplierName: {
|
|
345
|
+
name: "supplierName",
|
|
346
|
+
title: "Supplier",
|
|
347
|
+
type: "string",
|
|
348
|
+
sql: "supplier_name"
|
|
349
|
+
},
|
|
350
|
+
supplierType: {
|
|
351
|
+
name: "supplierType",
|
|
352
|
+
title: "Supplier Type",
|
|
353
|
+
type: "string",
|
|
354
|
+
sql: "CASE WHEN supplier_internal THEN 'Internal' ELSE 'External' END"
|
|
355
|
+
},
|
|
356
|
+
startDate: {
|
|
357
|
+
name: "startDate",
|
|
358
|
+
title: "Start Date",
|
|
359
|
+
type: "time",
|
|
360
|
+
sql: "start_date"
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
measures: {
|
|
364
|
+
count: {
|
|
365
|
+
name: "count",
|
|
366
|
+
title: "Employee Count",
|
|
367
|
+
type: "count",
|
|
368
|
+
sql: "id"
|
|
369
|
+
},
|
|
370
|
+
activeCount: {
|
|
371
|
+
name: "activeCount",
|
|
372
|
+
title: "Active Employees",
|
|
373
|
+
type: "count",
|
|
374
|
+
sql: "id",
|
|
375
|
+
filters: [{ sql: "active = true" }]
|
|
376
|
+
},
|
|
377
|
+
totalFte: {
|
|
378
|
+
name: "totalFte",
|
|
379
|
+
title: "Total FTE",
|
|
380
|
+
type: "sum",
|
|
381
|
+
sql: "fte_basis",
|
|
382
|
+
format: "number"
|
|
383
|
+
},
|
|
384
|
+
averageFte: {
|
|
385
|
+
name: "averageFte",
|
|
386
|
+
title: "Average FTE",
|
|
387
|
+
type: "avg",
|
|
388
|
+
sql: "fte_basis",
|
|
389
|
+
format: "number"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}, C = {
|
|
393
|
+
name: "Departments",
|
|
394
|
+
title: "Department Analytics",
|
|
395
|
+
description: "Organizational department data",
|
|
396
|
+
sql: `
|
|
397
|
+
SELECT
|
|
398
|
+
d.id,
|
|
399
|
+
d.name,
|
|
400
|
+
d.description,
|
|
401
|
+
COUNT(e.id) as employee_count
|
|
402
|
+
FROM departments d
|
|
403
|
+
LEFT JOIN employees e ON d.id = e.department AND e.active = true
|
|
404
|
+
WHERE d.organisation = \${SECURITY_CONTEXT.organisation}
|
|
405
|
+
GROUP BY d.id, d.name, d.description
|
|
406
|
+
`,
|
|
407
|
+
dimensions: {
|
|
408
|
+
id: {
|
|
409
|
+
name: "id",
|
|
410
|
+
title: "Department ID",
|
|
411
|
+
type: "string",
|
|
412
|
+
sql: "id",
|
|
413
|
+
primaryKey: !0
|
|
414
|
+
},
|
|
415
|
+
name: {
|
|
416
|
+
name: "name",
|
|
417
|
+
title: "Department Name",
|
|
418
|
+
type: "string",
|
|
419
|
+
sql: "name"
|
|
420
|
+
},
|
|
421
|
+
description: {
|
|
422
|
+
name: "description",
|
|
423
|
+
title: "Description",
|
|
424
|
+
type: "string",
|
|
425
|
+
sql: "description"
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
measures: {
|
|
429
|
+
count: {
|
|
430
|
+
name: "count",
|
|
431
|
+
title: "Department Count",
|
|
432
|
+
type: "count",
|
|
433
|
+
sql: "id"
|
|
434
|
+
},
|
|
435
|
+
employeeCount: {
|
|
436
|
+
name: "employeeCount",
|
|
437
|
+
title: "Employee Count",
|
|
438
|
+
type: "sum",
|
|
439
|
+
sql: "employee_count"
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}, $ = {
|
|
443
|
+
name: "EmployeeDepartments",
|
|
444
|
+
title: "Employee Department Analysis",
|
|
445
|
+
description: "Combined employee and department analytics",
|
|
446
|
+
sql: `
|
|
447
|
+
SELECT
|
|
448
|
+
e.id as employee_id,
|
|
449
|
+
e.name as employee_name,
|
|
450
|
+
e.active,
|
|
451
|
+
e.fte_basis,
|
|
452
|
+
d.id as department_id,
|
|
453
|
+
d.name as department_name
|
|
454
|
+
FROM employees e
|
|
455
|
+
LEFT JOIN departments d ON e.department = d.id
|
|
456
|
+
WHERE e.organisation = \${SECURITY_CONTEXT.organisation}
|
|
457
|
+
`,
|
|
458
|
+
dimensions: {
|
|
459
|
+
employeeName: {
|
|
460
|
+
name: "employeeName",
|
|
461
|
+
title: "Employee Name",
|
|
462
|
+
type: "string",
|
|
463
|
+
sql: "employee_name"
|
|
464
|
+
},
|
|
465
|
+
departmentName: {
|
|
466
|
+
name: "departmentName",
|
|
467
|
+
title: "Department Name",
|
|
468
|
+
type: "string",
|
|
469
|
+
sql: "department_name"
|
|
470
|
+
},
|
|
471
|
+
active: {
|
|
472
|
+
name: "active",
|
|
473
|
+
title: "Active",
|
|
474
|
+
type: "boolean",
|
|
475
|
+
sql: "active"
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
measures: {
|
|
479
|
+
employeeCount: {
|
|
480
|
+
name: "employeeCount",
|
|
481
|
+
title: "Employee Count",
|
|
482
|
+
type: "count",
|
|
483
|
+
sql: "employee_id"
|
|
484
|
+
},
|
|
485
|
+
activeEmployeeCount: {
|
|
486
|
+
name: "activeEmployeeCount",
|
|
487
|
+
title: "Active Employee Count",
|
|
488
|
+
type: "count",
|
|
489
|
+
sql: "employee_id",
|
|
490
|
+
filters: [{ sql: "active = true" }]
|
|
491
|
+
},
|
|
492
|
+
totalFte: {
|
|
493
|
+
name: "totalFte",
|
|
494
|
+
title: "Total FTE",
|
|
495
|
+
type: "sum",
|
|
496
|
+
sql: "fte_basis"
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}, T = [
|
|
500
|
+
g,
|
|
501
|
+
C,
|
|
502
|
+
$
|
|
503
|
+
], v = E;
|
|
504
|
+
function q(l) {
|
|
505
|
+
return new d(l);
|
|
506
|
+
}
|
|
507
|
+
const D = {
|
|
508
|
+
/**
|
|
509
|
+
* Create a simple query builder
|
|
510
|
+
*/
|
|
511
|
+
query: (l) => {
|
|
512
|
+
const e = (n, i = [], t = [], s = [], a, r) => ({
|
|
513
|
+
measures: n,
|
|
514
|
+
dimensions: i,
|
|
515
|
+
filters: t,
|
|
516
|
+
timeDimensions: s,
|
|
517
|
+
limit: a,
|
|
518
|
+
order: r
|
|
519
|
+
});
|
|
520
|
+
return {
|
|
521
|
+
measures: (n) => ({
|
|
522
|
+
dimensions: (i = []) => ({
|
|
523
|
+
filters: (t = []) => ({
|
|
524
|
+
timeDimensions: (s = []) => ({
|
|
525
|
+
limit: (a) => ({
|
|
526
|
+
order: (r) => e(n, i, t, s, a, r)
|
|
527
|
+
}),
|
|
528
|
+
order: (a) => e(n, i, t, s, void 0, a)
|
|
529
|
+
}),
|
|
530
|
+
limit: (s) => ({
|
|
531
|
+
order: (a) => e(n, i, t, [], s, a)
|
|
532
|
+
}),
|
|
533
|
+
order: (s) => e(n, i, t, [], void 0, s)
|
|
534
|
+
}),
|
|
535
|
+
timeDimensions: (t = []) => ({
|
|
536
|
+
filters: (s = []) => ({
|
|
537
|
+
limit: (a) => ({
|
|
538
|
+
order: (r) => e(n, i, s, t, a, r)
|
|
539
|
+
}),
|
|
540
|
+
order: (a) => e(n, i, s, t, void 0, a)
|
|
541
|
+
}),
|
|
542
|
+
limit: (s) => ({
|
|
543
|
+
order: (a) => e(n, i, [], t, s, a)
|
|
544
|
+
}),
|
|
545
|
+
order: (s) => e(n, i, [], t, void 0, s)
|
|
546
|
+
}),
|
|
547
|
+
limit: (t) => ({
|
|
548
|
+
order: (s) => e(n, i, [], [], t, s)
|
|
549
|
+
}),
|
|
550
|
+
order: (t) => e(n, i, [], [], void 0, t)
|
|
551
|
+
}),
|
|
552
|
+
filters: (i = []) => ({
|
|
553
|
+
dimensions: (t = []) => ({
|
|
554
|
+
timeDimensions: (s = []) => ({
|
|
555
|
+
limit: (a) => ({
|
|
556
|
+
order: (r) => e(n, t, i, s, a, r)
|
|
557
|
+
}),
|
|
558
|
+
order: (a) => e(n, t, i, s, void 0, a)
|
|
559
|
+
}),
|
|
560
|
+
limit: (s) => ({
|
|
561
|
+
order: (a) => e(n, t, i, [], s, a)
|
|
562
|
+
}),
|
|
563
|
+
order: (s) => e(n, t, i, [], void 0, s)
|
|
564
|
+
}),
|
|
565
|
+
timeDimensions: (t = []) => ({
|
|
566
|
+
dimensions: (s = []) => ({
|
|
567
|
+
limit: (a) => ({
|
|
568
|
+
order: (r) => e(n, s, i, t, a, r)
|
|
569
|
+
}),
|
|
570
|
+
order: (a) => e(n, s, i, t, void 0, a)
|
|
571
|
+
}),
|
|
572
|
+
limit: (s) => ({
|
|
573
|
+
order: (a) => e(n, [], i, t, s, a)
|
|
574
|
+
}),
|
|
575
|
+
order: (s) => e(n, [], i, t, void 0, s)
|
|
576
|
+
}),
|
|
577
|
+
limit: (t) => ({
|
|
578
|
+
order: (s) => e(n, [], i, [], t, s)
|
|
579
|
+
}),
|
|
580
|
+
order: (t) => e(n, [], i, [], void 0, t)
|
|
581
|
+
})
|
|
582
|
+
})
|
|
583
|
+
};
|
|
584
|
+
},
|
|
585
|
+
/**
|
|
586
|
+
* Create filters
|
|
587
|
+
*/
|
|
588
|
+
filters: {
|
|
589
|
+
equals: (l, e) => ({ member: l, operator: "equals", values: [e] }),
|
|
590
|
+
notEquals: (l, e) => ({ member: l, operator: "notEquals", values: [e] }),
|
|
591
|
+
contains: (l, e) => ({ member: l, operator: "contains", values: [e] }),
|
|
592
|
+
greaterThan: (l, e) => ({ member: l, operator: "gt", values: [e] }),
|
|
593
|
+
lessThan: (l, e) => ({ member: l, operator: "lt", values: [e] }),
|
|
594
|
+
inDateRange: (l, e, n) => ({
|
|
595
|
+
member: l,
|
|
596
|
+
operator: "inDateRange",
|
|
597
|
+
values: [e, n]
|
|
598
|
+
}),
|
|
599
|
+
set: (l) => ({ member: l, operator: "set", values: [] }),
|
|
600
|
+
notSet: (l) => ({ member: l, operator: "notSet", values: [] })
|
|
601
|
+
},
|
|
602
|
+
/**
|
|
603
|
+
* Create time dimensions
|
|
604
|
+
*/
|
|
605
|
+
timeDimensions: {
|
|
606
|
+
create: (l, e, n) => ({
|
|
607
|
+
dimension: l,
|
|
608
|
+
granularity: e,
|
|
609
|
+
dateRange: n
|
|
610
|
+
})
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
export {
|
|
614
|
+
d as SemanticLayerCompiler,
|
|
615
|
+
D as SemanticLayerUtils,
|
|
616
|
+
f as SemanticQueryExecutor,
|
|
617
|
+
q as createSemanticLayer,
|
|
618
|
+
v as defaultSemanticLayer,
|
|
619
|
+
C as departmentsCube,
|
|
620
|
+
$ as employeeDepartmentsCube,
|
|
621
|
+
g as employeesCube,
|
|
622
|
+
T as exampleCubes,
|
|
623
|
+
E as semanticLayer
|
|
624
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "drizzle-cube",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A Cube.js-compatible semantic layer for Drizzle ORM with React analytics dashboard",
|
|
5
|
+
"main": "./dist/server/index.js",
|
|
6
|
+
"types": "./dist/server/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./server": {
|
|
10
|
+
"types": "./dist/server/index.d.ts",
|
|
11
|
+
"import": "./dist/server/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client/index.d.ts",
|
|
15
|
+
"import": "./dist/client/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./adapters/hono": {
|
|
18
|
+
"types": "./dist/adapters/hono/index.d.ts",
|
|
19
|
+
"import": "./dist/adapters/hono/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "concurrently \"npm run dev:server\" \"npm run dev:client\" \"npm run dev:examples\"",
|
|
29
|
+
"dev:server": "vite build src/server --watch --mode development",
|
|
30
|
+
"dev:client": "vite build src/client --watch --mode development",
|
|
31
|
+
"dev:examples": "cd examples/hono-app && npm run dev",
|
|
32
|
+
"dev:help": "cd help-site && npm run dev",
|
|
33
|
+
"build": "npm run build:server && npm run build:client && npm run build:adapters",
|
|
34
|
+
"build:server": "vite build --config vite.config.server.ts",
|
|
35
|
+
"build:client": "vite build --config vite.config.client.ts",
|
|
36
|
+
"build:adapters": "vite build --config vite.config.adapters.ts",
|
|
37
|
+
"build:help": "cd help-site && npm run build",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest --watch",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"lint": "eslint src/**/*.ts",
|
|
42
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
43
|
+
"prepublishOnly": "npm run build && npm run test && npm run typecheck"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"drizzle",
|
|
47
|
+
"cube",
|
|
48
|
+
"cubejs",
|
|
49
|
+
"semantic-layer",
|
|
50
|
+
"analytics",
|
|
51
|
+
"dashboard",
|
|
52
|
+
"react",
|
|
53
|
+
"typescript"
|
|
54
|
+
],
|
|
55
|
+
"author": "Clifton Cunningham <clifton@clifton.io>",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"homepage": "https://drizzle-cube.dev",
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/cliftonc/drizzle-cube.git"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/cliftonc/drizzle-cube/issues"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"drizzle-orm": "^0.33.0",
|
|
67
|
+
"react": "^18.0.0",
|
|
68
|
+
"react-dom": "^18.0.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"react": {
|
|
72
|
+
"optional": false
|
|
73
|
+
},
|
|
74
|
+
"react-dom": {
|
|
75
|
+
"optional": false
|
|
76
|
+
},
|
|
77
|
+
"drizzle-orm": {
|
|
78
|
+
"optional": false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@types/node": "^20.0.0",
|
|
83
|
+
"@types/react": "^18.0.0",
|
|
84
|
+
"@types/react-dom": "^18.0.0",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
86
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
87
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
88
|
+
"concurrently": "^8.0.0",
|
|
89
|
+
"eslint": "^8.0.0",
|
|
90
|
+
"typescript": "^5.0.0",
|
|
91
|
+
"vite": "^5.0.0",
|
|
92
|
+
"vite-plugin-dts": "^4.0.0",
|
|
93
|
+
"vitest": "^2.0.0"
|
|
94
|
+
},
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"@heroicons/react": "^2.0.0",
|
|
97
|
+
"react-grid-layout": "^1.4.0",
|
|
98
|
+
"react-hook-form": "^7.47.0",
|
|
99
|
+
"recharts": "^2.8.0",
|
|
100
|
+
"zod": "^3.22.0"
|
|
101
|
+
}
|
|
102
|
+
}
|