drizzle-cube 0.1.17 → 0.1.19

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.
@@ -1,14 +1,17 @@
1
1
  import { AnyColumn } from 'drizzle-orm';
2
+ import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
3
+ import { MySql2Database } from 'drizzle-orm/mysql2';
4
+ import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
2
5
  import { SQL } from 'drizzle-orm';
3
6
 
4
7
  /**
5
8
  * Abstract base class for database executors
6
9
  */
7
- export declare abstract class BaseDatabaseExecutor<TSchema extends Record<string, any> = Record<string, any>> implements DatabaseExecutor<TSchema> {
8
- db: DrizzleDatabase<TSchema>;
9
- schema?: TSchema | undefined;
10
+ export declare abstract class BaseDatabaseExecutor implements DatabaseExecutor {
11
+ db: DrizzleDatabase;
12
+ schema?: any | undefined;
10
13
  databaseAdapter: DatabaseAdapter;
11
- constructor(db: DrizzleDatabase<TSchema>, schema?: TSchema | undefined, engineType?: 'postgres' | 'mysql' | 'sqlite');
14
+ constructor(db: DrizzleDatabase, schema?: any | undefined, engineType?: 'postgres' | 'mysql' | 'sqlite');
12
15
  abstract execute<T = any[]>(query: SQL | any, numericFields?: string[]): Promise<T>;
13
16
  abstract getEngineType(): 'postgres' | 'mysql' | 'sqlite';
14
17
  }
@@ -33,7 +36,7 @@ export declare interface BaseQueryDefinition {
33
36
  /**
34
37
  * Compiled cube with execution function
35
38
  */
36
- export declare interface CompiledCube<TSchema extends Record<string, any> = Record<string, any>> extends Cube<TSchema> {
39
+ export declare interface CompiledCube extends Cube {
37
40
  /** Execute a query against this cube */
38
41
  queryFn: (query: SemanticQuery, securityContext: SecurityContext) => Promise<QueryResult>;
39
42
  }
@@ -45,45 +48,51 @@ export declare interface CompiledCube<TSchema extends Record<string, any> = Reco
45
48
  * @param engineType - Optional explicit engine type override
46
49
  * @returns Appropriate database executor
47
50
  */
48
- export declare function createDatabaseExecutor<TSchema extends Record<string, any>>(db: DrizzleDatabase<TSchema>, schema?: TSchema, engineType?: 'postgres' | 'mysql' | 'sqlite'): DatabaseExecutor<TSchema>;
51
+ export declare function createDatabaseExecutor(db: DrizzleDatabase, schema?: any, engineType?: 'postgres' | 'mysql' | 'sqlite'): DatabaseExecutor;
49
52
 
50
53
  /**
51
54
  * Create a new semantic layer instance with Drizzle integration
52
55
  * Use this when you need multiple isolated instances
53
56
  */
54
- export declare function createDrizzleSemanticLayer<TSchema extends Record<string, any>>(options: {
55
- drizzle: DrizzleDatabase<TSchema>;
56
- schema?: TSchema;
57
- }): SemanticLayerCompiler<TSchema>;
57
+ export declare function createDrizzleSemanticLayer(options: {
58
+ drizzle: DrizzleDatabase;
59
+ schema?: any;
60
+ }): SemanticLayerCompiler;
58
61
 
59
62
  /**
60
63
  * Helper to create multi-cube query context
61
64
  */
62
- export declare function createMultiCubeContext<TSchema extends Record<string, any>>(baseContext: QueryContext<TSchema>, cubes: Map<string, Cube<TSchema>>, currentCube: Cube<TSchema>): MultiCubeQueryContext<TSchema>;
65
+ export declare function createMultiCubeContext(baseContext: QueryContext, cubes: Map<string, Cube>, currentCube: Cube): MultiCubeQueryContext;
63
66
 
64
- export declare function createMySQLExecutor<TSchema extends Record<string, any>>(db: DrizzleDatabase<TSchema>, schema?: TSchema): MySQLExecutor<TSchema>;
67
+ /**
68
+ * Factory function for creating MySQL executors
69
+ */
70
+ export declare function createMySQLExecutor(db: DrizzleDatabase, schema?: any): MySQLExecutor;
65
71
 
66
72
  /**
67
- * Factory functions for creating database executors
73
+ * Factory function for creating PostgreSQL executors
68
74
  */
69
- export declare function createPostgresExecutor<TSchema extends Record<string, any>>(db: DrizzleDatabase<TSchema>, schema?: TSchema): PostgresExecutor<TSchema>;
75
+ export declare function createPostgresExecutor(db: DrizzleDatabase, schema?: any): PostgresExecutor;
70
76
 
71
77
  /**
72
78
  * Create a new semantic layer compiler with type inference
73
79
  */
74
- export declare function createSemanticLayer<TSchema extends Record<string, any>>(options?: {
75
- drizzle?: DatabaseExecutor<TSchema>['db'];
76
- schema?: TSchema;
77
- databaseExecutor?: DatabaseExecutor<TSchema>;
80
+ export declare function createSemanticLayer(options?: {
81
+ drizzle?: DatabaseExecutor['db'];
82
+ schema?: any;
83
+ databaseExecutor?: DatabaseExecutor;
78
84
  engineType?: 'postgres' | 'mysql' | 'sqlite';
79
- }): SemanticLayerCompiler<TSchema>;
85
+ }): SemanticLayerCompiler;
80
86
 
81
- export declare function createSQLiteExecutor<TSchema extends Record<string, any>>(db: DrizzleDatabase<TSchema>, schema?: TSchema): SQLiteExecutor<TSchema>;
87
+ /**
88
+ * Factory function for creating SQLite executors
89
+ */
90
+ export declare function createSQLiteExecutor(db: DrizzleDatabase, schema?: any): SQLiteExecutor;
82
91
 
83
92
  /**
84
- * Cube definition focused on dynamic query building
93
+ * Cube definition focused on Drizzle query building
85
94
  */
86
- export declare interface Cube<TSchema extends Record<string, any> = Record<string, any>> {
95
+ declare interface Cube {
87
96
  name: string;
88
97
  title?: string;
89
98
  description?: string;
@@ -91,20 +100,30 @@ export declare interface Cube<TSchema extends Record<string, any> = Record<strin
91
100
  * Base query setup - returns the foundation that can be extended
92
101
  * Should return FROM/JOIN/WHERE setup, NOT a complete SELECT
93
102
  */
94
- sql: (ctx: QueryContext<TSchema>) => BaseQueryDefinition;
103
+ sql: (ctx: QueryContext) => BaseQueryDefinition;
95
104
  /** Cube dimensions using direct column references */
96
- dimensions: Record<string, Dimension<TSchema>>;
105
+ dimensions: Record<string, Dimension>;
97
106
  /** Cube measures using direct column references */
98
- measures: Record<string, Measure<TSchema>>;
107
+ measures: Record<string, Measure>;
99
108
  /** Optional joins to other cubes for multi-cube queries */
100
- joins?: Record<string, CubeJoin<TSchema>>;
109
+ joins?: Record<string, CubeJoin>;
110
+ /** Whether cube is publicly accessible */
111
+ public?: boolean;
112
+ /** SQL alias for the cube */
113
+ sqlAlias?: string;
114
+ /** Data source identifier */
115
+ dataSource?: string;
116
+ /** Additional metadata */
117
+ meta?: Record<string, any>;
101
118
  }
119
+ export { Cube }
120
+ export { Cube as SemanticCube }
102
121
 
103
122
  /**
104
123
  * Helper type for creating type-safe cubes
105
124
  */
106
- export declare interface CubeDefiner<TSchema extends Record<string, any>> {
107
- <TName extends string>(name: TName, definition: CubeDefinition<TSchema>): SemanticCube<TSchema> & {
125
+ export declare interface CubeDefiner {
126
+ <TName extends string>(name: TName, definition: CubeDefinition): Cube & {
108
127
  name: TName;
109
128
  };
110
129
  }
@@ -112,16 +131,16 @@ export declare interface CubeDefiner<TSchema extends Record<string, any>> {
112
131
  /**
113
132
  * Utility type for cube definition with schema inference
114
133
  */
115
- export declare type CubeDefinition<TSchema extends Record<string, any>> = Omit<SemanticCube<TSchema>, 'name'> & {
134
+ export declare type CubeDefinition = Omit<Cube, 'name'> & {
116
135
  name?: string;
117
136
  };
118
137
 
119
138
  /**
120
139
  * Type-safe cube join definition with lazy loading support
121
140
  */
122
- export declare interface CubeJoin<TSchema extends Record<string, any> = Record<string, any>> {
141
+ declare interface CubeJoin {
123
142
  /** Target cube reference - lazy loaded to avoid circular dependencies */
124
- targetCube: Cube<TSchema> | (() => Cube<TSchema>);
143
+ targetCube: Cube | (() => Cube);
125
144
  /** Semantic relationship - determines join behavior */
126
145
  relationship: 'belongsTo' | 'hasOne' | 'hasMany';
127
146
  /** Array of join conditions - supports multi-column joins */
@@ -136,6 +155,8 @@ export declare interface CubeJoin<TSchema extends Record<string, any> = Record<s
136
155
  /** Override default SQL join type (derived from relationship) */
137
156
  sqlJoinType?: 'inner' | 'left' | 'right' | 'full';
138
157
  }
158
+ export { CubeJoin }
159
+ export { CubeJoin as SemanticJoin }
139
160
 
140
161
  /**
141
162
  * Cube metadata for API responses
@@ -224,14 +245,14 @@ declare interface DatabaseAdapter {
224
245
  }
225
246
 
226
247
  /**
227
- * Database executor that wraps Drizzle ORM
248
+ * Database executor interface that wraps Drizzle ORM
228
249
  * Provides type-safe SQL execution with engine-specific implementations
229
250
  */
230
- export declare interface DatabaseExecutor<TSchema extends Record<string, any> = Record<string, any>> {
251
+ export declare interface DatabaseExecutor {
231
252
  /** The Drizzle database instance */
232
- db: DrizzleDatabase<TSchema>;
253
+ db: DrizzleDatabase;
233
254
  /** Optional schema for type inference */
234
- schema?: TSchema;
255
+ schema?: any;
235
256
  /** Database adapter for SQL dialect-specific operations */
236
257
  databaseAdapter: DatabaseAdapter;
237
258
  /** Execute a Drizzle SQL query or query object */
@@ -244,38 +265,34 @@ export declare interface DatabaseExecutor<TSchema extends Record<string, any> =
244
265
  * Main semantic layer instance
245
266
  * Use this for simple single-instance usage
246
267
  */
247
- export declare const defaultSemanticLayer: SemanticLayerCompiler<Record<string, any>>;
268
+ export declare const defaultSemanticLayer: SemanticLayerCompiler;
248
269
 
249
270
  /**
250
271
  * Helper function to create cubes
251
272
  */
252
- export declare function defineCube<TSchema extends Record<string, any>>(name: string, definition: Omit<Cube<TSchema>, 'name'>): Cube<TSchema>;
253
-
254
- /**
255
- * Create a type-safe cube definition with schema inference
256
- * @param _schema - Drizzle schema containing table definitions (used for type inference only)
257
- * @param definition - Cube definition with type inference
258
- * @returns Type-safe semantic cube
259
- */
260
- export declare function defineLegacyCube<TSchema extends Record<string, any>>(_schema: TSchema, definition: CubeDefinition<TSchema> & {
261
- name: string;
262
- }): SemanticCube<TSchema>;
273
+ export declare function defineCube(name: string, definition: Omit<Cube, 'name'>): Cube;
263
274
 
264
275
  /**
265
276
  * Dimension definition
266
277
  */
267
- export declare interface Dimension<TSchema extends Record<string, any> = Record<string, any>> {
278
+ declare interface Dimension {
268
279
  name: string;
269
280
  title?: string;
270
281
  description?: string;
271
282
  type: DimensionType;
272
283
  /** Direct column reference or SQL expression */
273
- sql: AnyColumn | SQL | ((ctx: QueryContext<TSchema>) => AnyColumn | SQL);
284
+ sql: AnyColumn | SQL | ((ctx: QueryContext) => AnyColumn | SQL);
274
285
  /** Whether this is a primary key */
275
286
  primaryKey?: boolean;
287
+ /** Whether to show in UI */
288
+ shown?: boolean;
276
289
  /** Display format */
277
290
  format?: string;
291
+ /** Additional metadata */
292
+ meta?: Record<string, any>;
278
293
  }
294
+ export { Dimension }
295
+ export { Dimension as SemanticDimension }
279
296
 
280
297
  export declare interface DimensionAnnotation {
281
298
  title: string;
@@ -286,6 +303,9 @@ export declare interface DimensionAnnotation {
286
303
 
287
304
  export declare type DimensionFormat = 'currency' | 'percent' | 'number' | 'date' | 'datetime' | 'id' | 'link';
288
305
 
306
+ /**
307
+ * Dimension metadata for API responses
308
+ */
289
309
  export declare interface DimensionMetadata {
290
310
  name: string;
291
311
  title: string;
@@ -299,32 +319,35 @@ export declare type DimensionType = 'string' | 'number' | 'time' | 'boolean';
299
319
 
300
320
  /**
301
321
  * Drizzle column reference type
322
+ * Use native Drizzle AnyColumn type for better type safety
302
323
  */
303
- export declare type DrizzleColumn = {
304
- _: {
305
- name: string;
306
- dataType: string;
307
- columnType: string;
308
- };
309
- };
324
+ export declare type DrizzleColumn = AnyColumn;
310
325
 
311
326
  /**
312
- * Generic Drizzle database type
313
- * Supports any Drizzle client (PostgreSQL, MySQL, SQLite)
327
+ * Core database interface that supports all Drizzle instances
328
+ * Uses flexible typing for maximum compatibility across different database drivers
314
329
  */
315
- export declare type DrizzleDatabase<TSchema extends Record<string, any> = Record<string, any>> = {
330
+ export declare interface DrizzleDatabase {
316
331
  select: (fields?: any) => any;
317
332
  insert: (table: any) => any;
318
333
  update: (table: any) => any;
319
334
  delete: (table: any) => any;
320
- execute?: (query: SQL) => Promise<any>;
321
- run?: (query: SQL) => any;
322
- all?: (query: SQL) => any[];
323
- get?: (query: SQL) => any;
324
- $with: (alias: string) => any;
335
+ execute?: (query: SQL) => Promise<unknown[]>;
336
+ run?: (query: SQL) => unknown;
337
+ all?: (query: SQL) => unknown[];
338
+ get?: (query: SQL) => unknown;
339
+ $with: (alias: string) => {
340
+ as: (query: any) => any;
341
+ };
325
342
  with: (...args: any[]) => any;
326
- schema?: TSchema;
327
- };
343
+ schema?: unknown;
344
+ }
345
+
346
+ /**
347
+ * Type-level utility to extract the schema type from a cube reference
348
+ * Since we removed generics, this now returns 'any'
349
+ */
350
+ export declare type ExtractSchemaFromCubeRef = any;
328
351
 
329
352
  /**
330
353
  * Filter definitions with logical operators
@@ -347,31 +370,12 @@ export declare type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notC
347
370
  */
348
371
  export declare function getJoinType(relationship: string, override?: string): string;
349
372
 
350
- export declare type JoinType = 'left' | 'right' | 'inner' | 'full';
351
-
352
373
  /**
353
- * Compiled cube with executable query function
374
+ * Type guard to check if value is a function-based SQL expression
354
375
  */
355
- export declare interface LegacyCompiledCube<TSchema extends Record<string, any> = Record<string, any>> extends SemanticCube<TSchema> {
356
- queryFn: (query: SemanticQuery, securityContext: SecurityContext) => Promise<QueryResult>;
357
- }
376
+ export declare function isFunctionSqlExpression(expr: SqlExpression): expr is (ctx: QueryContext) => AnyColumn | SQL;
358
377
 
359
- /**
360
- * Query context passed to cube SQL functions
361
- * Provides access to database, schema, and security context
362
- */
363
- export declare interface LegacyQueryContext<TSchema extends Record<string, any> = Record<string, any>> {
364
- /** Drizzle database instance */
365
- db: DrizzleDatabase<TSchema>;
366
- /** Database schema (tables, columns, etc.) */
367
- schema: TSchema;
368
- /** Security context for filtering */
369
- securityContext: SecurityContext;
370
- /** The semantic query being executed */
371
- query: SemanticQuery;
372
- /** The compiled cube being queried */
373
- cube: LegacyCompiledCube<TSchema>;
374
- }
378
+ export declare type JoinType = 'left' | 'right' | 'inner' | 'full';
375
379
 
376
380
  export declare interface LogicalFilter {
377
381
  and?: Filter[];
@@ -381,18 +385,30 @@ export declare interface LogicalFilter {
381
385
  /**
382
386
  * Measure definition
383
387
  */
384
- export declare interface Measure<TSchema extends Record<string, any> = Record<string, any>> {
388
+ declare interface Measure {
385
389
  name: string;
386
390
  title?: string;
387
391
  description?: string;
388
392
  type: MeasureType;
389
393
  /** Column to aggregate or SQL expression */
390
- sql: AnyColumn | SQL | ((ctx: QueryContext<TSchema>) => AnyColumn | SQL);
394
+ sql: AnyColumn | SQL | ((ctx: QueryContext) => AnyColumn | SQL);
391
395
  /** Display format */
392
396
  format?: string;
397
+ /** Whether to show in UI */
398
+ shown?: boolean;
393
399
  /** Filters applied to this measure */
394
- filters?: Array<(ctx: QueryContext<TSchema>) => SQL>;
400
+ filters?: Array<(ctx: QueryContext) => SQL>;
401
+ /** Rolling window configuration */
402
+ rollingWindow?: {
403
+ trailing?: string;
404
+ leading?: string;
405
+ offset?: string;
406
+ };
407
+ /** Additional metadata */
408
+ meta?: Record<string, any>;
395
409
  }
410
+ export { Measure }
411
+ export { Measure as SemanticMeasure }
396
412
 
397
413
  /**
398
414
  * Annotation interfaces for UI metadata
@@ -404,11 +420,11 @@ export declare interface MeasureAnnotation {
404
420
  format?: MeasureFormat;
405
421
  }
406
422
 
407
- /**
408
- * Display formats
409
- */
410
423
  export declare type MeasureFormat = 'currency' | 'percent' | 'number' | 'integer';
411
424
 
425
+ /**
426
+ * Measure metadata for API responses
427
+ */
412
428
  export declare interface MeasureMetadata {
413
429
  name: string;
414
430
  title: string;
@@ -419,27 +435,23 @@ export declare interface MeasureMetadata {
419
435
  }
420
436
 
421
437
  /**
422
- * Measure aggregation types
438
+ * Type enums and constants
423
439
  */
424
440
  export declare type MeasureType = 'count' | 'countDistinct' | 'countDistinctApprox' | 'sum' | 'avg' | 'min' | 'max' | 'runningTotal' | 'number';
425
441
 
426
442
  /**
427
443
  * Multi-cube query context for cross-cube operations
428
444
  */
429
- export declare interface MultiCubeQueryContext<TSchema extends Record<string, any> = Record<string, any>> extends QueryContext<TSchema> {
445
+ export declare interface MultiCubeQueryContext extends QueryContext {
430
446
  /** Available cubes for cross-cube operations */
431
- cubes: Map<string, Cube<TSchema>>;
447
+ cubes: Map<string, Cube>;
432
448
  /** Current cube being processed */
433
- currentCube: Cube<TSchema>;
449
+ currentCube: Cube;
434
450
  }
435
451
 
436
- export declare type MultiCubeQueryPlan<TSchema extends Record<string, any> = Record<string, any>> = QueryPlan<TSchema>;
452
+ export declare type MySQLDatabase = MySql2Database<any>;
437
453
 
438
- /**
439
- * MySQL database executor
440
- * Works with mysql2 driver
441
- */
442
- export declare class MySQLExecutor<TSchema extends Record<string, any> = Record<string, any>> extends BaseDatabaseExecutor<TSchema> {
454
+ export declare class MySQLExecutor extends BaseDatabaseExecutor {
443
455
  execute<T = any[]>(query: SQL | any, numericFields?: string[]): Promise<T>;
444
456
  /**
445
457
  * Convert numeric string fields to numbers (measure fields + numeric dimensions)
@@ -453,10 +465,11 @@ export declare class MySQLExecutor<TSchema extends Record<string, any> = Record<
453
465
  }
454
466
 
455
467
  /**
456
- * PostgreSQL database executor
457
- * Works with postgres.js and Neon drivers
468
+ * Type helpers for specific database types
458
469
  */
459
- export declare class PostgresExecutor<TSchema extends Record<string, any> = Record<string, any>> extends BaseDatabaseExecutor<TSchema> {
470
+ export declare type PostgresDatabase = PostgresJsDatabase<any>;
471
+
472
+ export declare class PostgresExecutor extends BaseDatabaseExecutor {
460
473
  execute<T = any[]>(query: SQL | any, numericFields?: string[]): Promise<T>;
461
474
  /**
462
475
  * Convert numeric string fields to numbers (only for measure fields)
@@ -469,14 +482,14 @@ export declare class PostgresExecutor<TSchema extends Record<string, any> = Reco
469
482
  getEngineType(): 'postgres';
470
483
  }
471
484
 
472
- export declare class QueryBuilder<TSchema extends Record<string, any> = Record<string, any>> {
485
+ export declare class QueryBuilder {
473
486
  private databaseAdapter;
474
487
  constructor(databaseAdapter: DatabaseAdapter);
475
488
  /**
476
489
  * Build dynamic selections for measures, dimensions, and time dimensions
477
490
  * Works for both single and multi-cube queries
478
491
  */
479
- buildSelections(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>): Record<string, SQL | AnyColumn>;
492
+ buildSelections(cubes: Map<string, Cube> | Cube, query: SemanticQuery, context: QueryContext): Record<string, SQL | AnyColumn>;
480
493
  /**
481
494
  * Build measure expression for HAVING clause, handling CTE references correctly
482
495
  */
@@ -484,21 +497,21 @@ export declare class QueryBuilder<TSchema extends Record<string, any> = Record<s
484
497
  /**
485
498
  * Build measure expression with aggregation and filters
486
499
  */
487
- buildMeasureExpression(measure: any, context: QueryContext<TSchema>): SQL;
500
+ buildMeasureExpression(measure: any, context: QueryContext): SQL;
488
501
  /**
489
502
  * Build time dimension expression with granularity using database adapter
490
503
  */
491
- buildTimeDimensionExpression(dimensionSql: any, granularity: string | undefined, context: QueryContext<TSchema>): SQL;
504
+ buildTimeDimensionExpression(dimensionSql: any, granularity: string | undefined, context: QueryContext): SQL;
492
505
  /**
493
506
  * Build WHERE conditions from semantic query filters (dimensions only)
494
507
  * Works for both single and multi-cube queries
495
508
  */
496
- buildWhereConditions(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: QueryPlan<TSchema>): SQL[];
509
+ buildWhereConditions(cubes: Map<string, Cube> | Cube, query: SemanticQuery, context: QueryContext, queryPlan?: QueryPlan): SQL[];
497
510
  /**
498
511
  * Build HAVING conditions from semantic query filters (measures only)
499
512
  * Works for both single and multi-cube queries
500
513
  */
501
- buildHavingConditions(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: QueryPlan<TSchema>): SQL[];
514
+ buildHavingConditions(cubes: Map<string, Cube> | Cube, query: SemanticQuery, context: QueryContext, queryPlan?: QueryPlan): SQL[];
502
515
  /**
503
516
  * Process a single filter (basic or logical)
504
517
  * @param filterType - 'where' for dimension filters, 'having' for measure filters
@@ -527,7 +540,7 @@ export declare class QueryBuilder<TSchema extends Record<string, any> = Record<s
527
540
  * Build GROUP BY fields from dimensions and time dimensions
528
541
  * Works for both single and multi-cube queries
529
542
  */
530
- buildGroupByFields(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: any): (SQL | AnyColumn)[];
543
+ buildGroupByFields(cubes: Map<string, Cube> | Cube, query: SemanticQuery, context: QueryContext, queryPlan?: any): (SQL | AnyColumn)[];
531
544
  /**
532
545
  * Build ORDER BY clause with automatic time dimension sorting
533
546
  */
@@ -536,7 +549,7 @@ export declare class QueryBuilder<TSchema extends Record<string, any> = Record<s
536
549
  * Collect numeric field names (measures + numeric dimensions) for type conversion
537
550
  * Works for both single and multi-cube queries
538
551
  */
539
- collectNumericFields(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery): string[];
552
+ collectNumericFields(cubes: Map<string, Cube> | Cube, query: SemanticQuery): string[];
540
553
  /**
541
554
  * Apply LIMIT and OFFSET to a query with validation
542
555
  * If offset is provided without limit, add a reasonable default limit
@@ -545,31 +558,38 @@ export declare class QueryBuilder<TSchema extends Record<string, any> = Record<s
545
558
  }
546
559
 
547
560
  /**
548
- * Query context for dynamic building
561
+ * Query context passed to cube SQL functions
562
+ * Provides access to database, schema, and security context
549
563
  */
550
- export declare interface QueryContext<TSchema extends Record<string, any> = Record<string, any>> {
564
+ declare interface QueryContext {
551
565
  /** Drizzle database instance */
552
- db: DrizzleDatabase<TSchema>;
553
- /** Database schema */
554
- schema: TSchema;
566
+ db: DrizzleDatabase;
567
+ /** Database schema (tables, columns, etc.) */
568
+ schema?: any;
555
569
  /** Security context for filtering */
556
570
  securityContext: SecurityContext;
571
+ /** The semantic query being executed */
572
+ query?: SemanticQuery;
573
+ /** The compiled cube being queried */
574
+ cube?: Cube;
557
575
  }
576
+ export { QueryContext }
577
+ export { QueryContext as SemanticQueryContext }
558
578
 
559
- export declare class QueryExecutor<TSchema extends Record<string, any> = Record<string, any>> {
579
+ export declare class QueryExecutor {
560
580
  private dbExecutor;
561
581
  private queryBuilder;
562
582
  private queryPlanner;
563
583
  private databaseAdapter;
564
- constructor(dbExecutor: DatabaseExecutor<TSchema>);
584
+ constructor(dbExecutor: DatabaseExecutor);
565
585
  /**
566
586
  * Unified query execution method that handles both single and multi-cube queries
567
587
  */
568
- execute(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
588
+ execute(cubes: Map<string, Cube>, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
569
589
  /**
570
590
  * Legacy interface for single cube queries
571
591
  */
572
- executeQuery(cube: Cube<TSchema>, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
592
+ executeQuery(cube: Cube, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
573
593
  /**
574
594
  * Build pre-aggregation CTE for hasMany relationships
575
595
  */
@@ -589,14 +609,14 @@ export declare class QueryExecutor<TSchema extends Record<string, any> = Record<
589
609
  /**
590
610
  * Generate raw SQL for debugging (without execution) - unified approach
591
611
  */
592
- generateSQL(cube: Cube<TSchema>, query: SemanticQuery, securityContext: SecurityContext): Promise<{
612
+ generateSQL(cube: Cube, query: SemanticQuery, securityContext: SecurityContext): Promise<{
593
613
  sql: string;
594
614
  params?: any[];
595
615
  }>;
596
616
  /**
597
617
  * Generate raw SQL for multi-cube queries without execution - unified approach
598
618
  */
599
- generateMultiCubeSQL(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, securityContext: SecurityContext): Promise<{
619
+ generateMultiCubeSQL(cubes: Map<string, Cube>, query: SemanticQuery, securityContext: SecurityContext): Promise<{
600
620
  sql: string;
601
621
  params?: any[];
602
622
  }>;
@@ -616,12 +636,12 @@ export declare class QueryExecutor<TSchema extends Record<string, any> = Record<
616
636
  * - For multi-cube queries: joinCubes contains the additional cubes to join
617
637
  * - selections, whereConditions, and groupByFields are populated by QueryBuilder
618
638
  */
619
- export declare interface QueryPlan<TSchema extends Record<string, any> = Record<string, any>> {
639
+ export declare interface QueryPlan {
620
640
  /** Primary cube that drives the query */
621
- primaryCube: Cube<TSchema>;
641
+ primaryCube: Cube;
622
642
  /** Additional cubes to join (empty for single-cube queries) */
623
643
  joinCubes: Array<{
624
- cube: Cube<TSchema>;
644
+ cube: Cube;
625
645
  alias: string;
626
646
  joinType: 'inner' | 'left' | 'right' | 'full';
627
647
  joinCondition: SQL;
@@ -634,7 +654,7 @@ export declare interface QueryPlan<TSchema extends Record<string, any> = Record<
634
654
  groupByFields: (SQL | AnyColumn)[];
635
655
  /** Pre-aggregation CTEs for hasMany relationships to prevent fan-out */
636
656
  preAggregationCTEs?: Array<{
637
- cube: Cube<TSchema>;
657
+ cube: Cube;
638
658
  alias: string;
639
659
  cteAlias: string;
640
660
  joinKeys: Array<{
@@ -650,7 +670,7 @@ export declare interface QueryPlan<TSchema extends Record<string, any> = Record<
650
670
  /**
651
671
  * Pre-aggregation plan for handling hasMany relationships
652
672
  */
653
- export declare class QueryPlanner<TSchema extends Record<string, any> = Record<string, any>> {
673
+ export declare class QueryPlanner {
654
674
  /**
655
675
  * Analyze a semantic query to determine which cubes are involved
656
676
  */
@@ -670,12 +690,12 @@ export declare class QueryPlanner<TSchema extends Record<string, any> = Record<s
670
690
  /**
671
691
  * Create a unified query plan that works for both single and multi-cube queries
672
692
  */
673
- createQueryPlan(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, ctx: QueryContext<TSchema>): QueryPlan<TSchema>;
693
+ createQueryPlan(cubes: Map<string, Cube>, query: SemanticQuery, _ctx: QueryContext): QueryPlan;
674
694
  /**
675
695
  * Choose the primary cube based on query analysis
676
696
  * Uses a consistent strategy to avoid measure order dependencies
677
697
  */
678
- choosePrimaryCube(cubeNames: string[], query: SemanticQuery, cubes?: Map<string, Cube<TSchema>>): string;
698
+ choosePrimaryCube(cubeNames: string[], query: SemanticQuery, cubes?: Map<string, Cube>): string;
679
699
  /**
680
700
  * Check if a cube can reach all other cubes in the list via joins
681
701
  */
@@ -708,11 +728,11 @@ export declare class QueryPlanner<TSchema extends Record<string, any> = Record<s
708
728
  * Query execution result
709
729
  */
710
730
  export declare interface QueryResult {
711
- data: any[];
731
+ data: Record<string, unknown>[];
712
732
  annotation: {
713
733
  measures: Record<string, MeasureAnnotation>;
714
734
  dimensions: Record<string, DimensionAnnotation>;
715
- segments: Record<string, any>;
735
+ segments: Record<string, unknown>;
716
736
  timeDimensions: Record<string, TimeDimensionAnnotation>;
717
737
  };
718
738
  }
@@ -720,103 +740,39 @@ export declare interface QueryResult {
720
740
  /**
721
741
  * Resolve cube reference (handles both direct and lazy references)
722
742
  */
723
- export declare function resolveCubeReference<TSchema extends Record<string, any>>(ref: Cube<TSchema> | (() => Cube<TSchema>)): Cube<TSchema>;
743
+ export declare function resolveCubeReference(ref: Cube | (() => Cube)): Cube;
724
744
 
725
745
  /**
726
746
  * Helper to resolve SQL expressions
727
747
  */
728
- export declare function resolveSqlExpression<TSchema extends Record<string, any>>(expr: AnyColumn | SQL | ((ctx: QueryContext<TSchema>) => AnyColumn | SQL), ctx: QueryContext<TSchema>): AnyColumn | SQL;
748
+ export declare function resolveSqlExpression(expr: AnyColumn | SQL | ((ctx: QueryContext) => AnyColumn | SQL), ctx: QueryContext): AnyColumn | SQL;
729
749
 
730
750
  /**
731
751
  * Security context passed to cube SQL functions
732
752
  * Contains user/tenant-specific data for filtering
733
753
  */
734
754
  export declare interface SecurityContext {
735
- [key: string]: any;
755
+ [key: string]: unknown;
736
756
  }
737
757
 
738
- /**
739
- * Semantic cube definition with Drizzle integration
740
- */
741
- export declare interface SemanticCube<TSchema extends Record<string, any> = Record<string, any>> {
742
- name: string;
743
- title?: string;
744
- description?: string;
745
- /** Base SQL for the cube - can use Drizzle query builder */
746
- sql: string | SQL | ((context: LegacyQueryContext<TSchema>) => SQL | Promise<SQL>);
747
- /** Cube dimensions */
748
- dimensions: Record<string, SemanticDimension<TSchema>>;
749
- /** Cube measures */
750
- measures: Record<string, SemanticMeasure<TSchema>>;
751
- /** Joins to other cubes */
752
- joins?: Record<string, SemanticJoin<TSchema>>;
753
- /** Whether cube is publicly accessible */
754
- public?: boolean;
755
- /** SQL alias for the cube */
756
- sqlAlias?: string;
757
- /** Data source identifier */
758
- dataSource?: string;
759
- /** Refresh configuration */
760
- refreshKey?: {
761
- every?: string;
762
- sql?: string | SQL;
763
- };
764
- /** Pre-aggregation definitions */
765
- preAggregations?: Record<string, SemanticPreAggregation>;
766
- /** Additional metadata */
767
- meta?: Record<string, any>;
768
- }
758
+ export declare const semanticLayer: SemanticLayerCompiler;
769
759
 
770
- /**
771
- * Semantic dimension with Drizzle column support
772
- */
773
- export declare interface SemanticDimension<TSchema extends Record<string, any> = Record<string, any>> {
774
- name: string;
775
- title?: string;
776
- description?: string;
777
- type: DimensionType;
778
- /** SQL expression - can be Drizzle column reference or SQL template */
779
- sql: string | SQL | DrizzleColumn | ((context: LegacyQueryContext<TSchema>) => SQL | DrizzleColumn);
780
- /** Whether this is a primary key */
781
- primaryKey?: boolean;
782
- /** Whether to show in UI */
783
- shown?: boolean;
784
- /** Display format */
785
- format?: DimensionFormat;
786
- /** Additional metadata */
787
- meta?: Record<string, any>;
788
- }
789
-
790
- /**
791
- * Join definition between cubes
792
- */
793
- export declare interface SemanticJoin<TSchema extends Record<string, any> = Record<string, any>> {
794
- name?: string;
795
- type?: JoinType;
796
- /** Join condition using Drizzle SQL */
797
- sql: string | SQL | ((context: LegacyQueryContext<TSchema>) => SQL);
798
- /** Relationship type */
799
- relationship: 'belongsTo' | 'hasOne' | 'hasMany';
800
- }
801
-
802
- export declare const semanticLayer: SemanticLayerCompiler<Record<string, any>>;
803
-
804
- export declare class SemanticLayerCompiler<TSchema extends Record<string, any> = Record<string, any>> {
760
+ export declare class SemanticLayerCompiler {
805
761
  private cubes;
806
762
  private dbExecutor?;
807
763
  private metadataCache?;
808
764
  private metadataCacheTimestamp?;
809
765
  private readonly METADATA_CACHE_TTL;
810
766
  constructor(options?: {
811
- drizzle?: DatabaseExecutor<TSchema>['db'];
812
- schema?: TSchema;
813
- databaseExecutor?: DatabaseExecutor<TSchema>;
767
+ drizzle?: DatabaseExecutor['db'];
768
+ schema?: any;
769
+ databaseExecutor?: DatabaseExecutor;
814
770
  engineType?: 'postgres' | 'mysql' | 'sqlite';
815
771
  });
816
772
  /**
817
773
  * Set or update the database executor
818
774
  */
819
- setDatabaseExecutor(executor: DatabaseExecutor<TSchema>): void;
775
+ setDatabaseExecutor(executor: DatabaseExecutor): void;
820
776
  /**
821
777
  * Get the database engine type for SQL formatting
822
778
  */
@@ -824,7 +780,7 @@ export declare class SemanticLayerCompiler<TSchema extends Record<string, any> =
824
780
  /**
825
781
  * Set Drizzle instance and schema directly
826
782
  */
827
- setDrizzle(db: DatabaseExecutor<TSchema>['db'], schema?: TSchema, engineType?: 'postgres' | 'mysql' | 'sqlite'): void;
783
+ setDrizzle(db: DatabaseExecutor['db'], schema?: any, engineType?: 'postgres' | 'mysql' | 'sqlite'): void;
828
784
  /**
829
785
  * Check if database executor is configured
830
786
  */
@@ -832,19 +788,19 @@ export declare class SemanticLayerCompiler<TSchema extends Record<string, any> =
832
788
  /**
833
789
  * Register a simplified cube with dynamic query building
834
790
  */
835
- registerCube(cube: Cube<TSchema>): void;
791
+ registerCube(cube: Cube): void;
836
792
  /**
837
793
  * Get a cube by name
838
794
  */
839
- getCube(name: string): Cube<TSchema> | undefined;
795
+ getCube(name: string): Cube | undefined;
840
796
  /**
841
797
  * Get all registered cubes
842
798
  */
843
- getAllCubes(): Cube<TSchema>[];
799
+ getAllCubes(): Cube[];
844
800
  /**
845
801
  * Get all cubes as a Map for multi-cube queries
846
802
  */
847
- getAllCubesMap(): Map<string, Cube<TSchema>>;
803
+ getAllCubesMap(): Map<string, Cube>;
848
804
  /**
849
805
  * Unified query execution method that handles both single and multi-cube queries
850
806
  */
@@ -1180,34 +1136,6 @@ export declare const SemanticLayerUtils: {
1180
1136
  };
1181
1137
  };
1182
1138
 
1183
- /**
1184
- * Semantic measure with Drizzle aggregation support
1185
- */
1186
- export declare interface SemanticMeasure<TSchema extends Record<string, any> = Record<string, any>> {
1187
- name: string;
1188
- title?: string;
1189
- description?: string;
1190
- type: MeasureType;
1191
- /** SQL expression - can be Drizzle column or aggregation function */
1192
- sql: string | SQL | DrizzleColumn | ((context: LegacyQueryContext<TSchema>) => SQL | DrizzleColumn);
1193
- /** Display format */
1194
- format?: MeasureFormat;
1195
- /** Whether to show in UI */
1196
- shown?: boolean;
1197
- /** Filters applied to this measure */
1198
- filters?: Array<{
1199
- sql: string | SQL | ((context: LegacyQueryContext<TSchema>) => SQL);
1200
- }>;
1201
- /** Rolling window configuration */
1202
- rollingWindow?: {
1203
- trailing?: string;
1204
- leading?: string;
1205
- offset?: string;
1206
- };
1207
- /** Additional metadata */
1208
- meta?: Record<string, any>;
1209
- }
1210
-
1211
1139
  /**
1212
1140
  * Pre-aggregation configuration
1213
1141
  */
@@ -1221,7 +1149,7 @@ export declare interface SemanticPreAggregation {
1221
1149
  };
1222
1150
  refreshKey?: {
1223
1151
  every: string;
1224
- sql?: string | SQL;
1152
+ sql?: string;
1225
1153
  };
1226
1154
  indexes?: Record<string, string[]>;
1227
1155
  }
@@ -1242,10 +1170,13 @@ export declare interface SemanticQuery {
1242
1170
  export { SQL }
1243
1171
 
1244
1172
  /**
1245
- * SQLite database executor
1246
- * Works with better-sqlite3 driver
1173
+ * Type for SQL expressions that can be functions or direct values
1247
1174
  */
1248
- export declare class SQLiteExecutor<TSchema extends Record<string, any> = Record<string, any>> extends BaseDatabaseExecutor<TSchema> {
1175
+ export declare type SqlExpression = AnyColumn | SQL | ((ctx: QueryContext) => AnyColumn | SQL);
1176
+
1177
+ export declare type SQLiteDatabase = BetterSQLite3Database<any>;
1178
+
1179
+ export declare class SQLiteExecutor extends BaseDatabaseExecutor {
1249
1180
  execute<T = any[]>(query: SQL | any, numericFields?: string[]): Promise<T>;
1250
1181
  /**
1251
1182
  * Convert numeric string fields to numbers (only for measure fields)
@@ -1263,7 +1194,7 @@ export declare class SQLiteExecutor<TSchema extends Record<string, any> = Record
1263
1194
  */
1264
1195
  export declare interface SqlResult {
1265
1196
  sql: string;
1266
- params?: any[];
1197
+ params?: unknown[];
1267
1198
  }
1268
1199
 
1269
1200
  /**