drizzle-cube 0.1.13 → 0.1.15

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.
Files changed (51) hide show
  1. package/README.md +48 -213
  2. package/dist/adapters/compiler-CQNna-Ig.js +19982 -0
  3. package/dist/adapters/express/index.js +29 -29
  4. package/dist/adapters/fastify/index.js +31 -31
  5. package/dist/adapters/hono/index.js +38 -38
  6. package/dist/adapters/nextjs/index.js +43 -43
  7. package/dist/adapters/utils.d.ts +4 -0
  8. package/dist/client/charts.d.ts +10 -0
  9. package/dist/client/charts.js +18 -0
  10. package/dist/client/charts.js.map +1 -0
  11. package/dist/client/chunks/charts-CM4y1xw4.js +2285 -0
  12. package/dist/client/chunks/charts-CM4y1xw4.js.map +1 -0
  13. package/dist/client/chunks/icons-D95augkg.js +1916 -0
  14. package/dist/client/chunks/icons-D95augkg.js.map +1 -0
  15. package/dist/client/chunks/providers-DdBep5JR.js +208 -0
  16. package/dist/client/chunks/providers-DdBep5JR.js.map +1 -0
  17. package/dist/client/components/AIAssistant/AIAssistantModal.d.ts +9 -0
  18. package/dist/client/components/AIAssistant/constants.d.ts +11 -0
  19. package/dist/client/components/AIAssistant/index.d.ts +7 -0
  20. package/dist/client/components/AIAssistant/types.d.ts +47 -0
  21. package/dist/client/components/AIAssistant/utils.d.ts +17 -0
  22. package/dist/client/components/AnalyticsDashboard.d.ts +1 -1
  23. package/dist/client/components/DashboardGrid.d.ts +1 -2
  24. package/dist/client/components/PortletEditModal.d.ts +1 -2
  25. package/dist/client/components/QueryBuilder/DateRangeFilter.d.ts +4 -0
  26. package/dist/client/components/QueryBuilder/DateRangeSelector.d.ts +11 -0
  27. package/dist/client/components/QueryBuilder/types.d.ts +32 -1
  28. package/dist/client/components/QueryBuilder/utils.d.ts +70 -1
  29. package/dist/client/components.d.ts +16 -0
  30. package/dist/client/components.js +6290 -0
  31. package/dist/client/components.js.map +1 -0
  32. package/dist/client/hooks.d.ts +11 -0
  33. package/dist/client/hooks.js +132 -0
  34. package/dist/client/hooks.js.map +1 -0
  35. package/dist/client/index.d.ts +3 -3
  36. package/dist/client/index.js +29 -30100
  37. package/dist/client/index.js.map +1 -0
  38. package/dist/client/providers/CubeProvider.d.ts +6 -3
  39. package/dist/client/providers.d.ts +9 -0
  40. package/dist/client/providers.js +7 -0
  41. package/dist/client/providers.js.map +1 -0
  42. package/dist/client/styles.css +1 -1
  43. package/dist/client/types.d.ts +0 -2
  44. package/dist/client/utils.d.ts +8 -0
  45. package/dist/client/utils.js +2 -0
  46. package/dist/client/utils.js.map +1 -0
  47. package/dist/client-bundle-stats.html +4949 -0
  48. package/dist/server/index.d.ts +226 -365
  49. package/dist/server/index.js +18880 -1555
  50. package/package.json +26 -2
  51. package/dist/adapters/utils-C3A4JGFs.js +0 -3779
@@ -38,12 +38,6 @@ export declare interface CompiledCube<TSchema extends Record<string, any> = Reco
38
38
  queryFn: (query: SemanticQuery, securityContext: SecurityContext) => Promise<QueryResult>;
39
39
  }
40
40
 
41
- /**
42
- * Helper function to convert Cube.dev-style YAML references
43
- * Converts {CUBE}, {CubeName.field}, etc. to our format
44
- */
45
- export declare function convertCubeReferences(sql: string): string;
46
-
47
41
  /**
48
42
  * Auto-detect database type and create appropriate executor
49
43
  * @param db - Drizzle database instance
@@ -123,17 +117,24 @@ export declare type CubeDefinition<TSchema extends Record<string, any>> = Omit<S
123
117
  };
124
118
 
125
119
  /**
126
- * Cube join definition for multi-cube queries
120
+ * Type-safe cube join definition with lazy loading support
127
121
  */
128
122
  export declare interface CubeJoin<TSchema extends Record<string, any> = Record<string, any>> {
129
- /** Target cube name to join with */
130
- targetCube: string;
131
- /** Join condition */
132
- condition: (ctx: MultiCubeQueryContext<TSchema>) => SQL;
133
- /** Join type */
134
- type?: 'inner' | 'left' | 'right' | 'full';
135
- /** Relationship type for metadata */
123
+ /** Target cube reference - lazy loaded to avoid circular dependencies */
124
+ targetCube: Cube<TSchema> | (() => Cube<TSchema>);
125
+ /** Semantic relationship - determines join behavior */
136
126
  relationship: 'belongsTo' | 'hasOne' | 'hasMany';
127
+ /** Array of join conditions - supports multi-column joins */
128
+ on: Array<{
129
+ /** Column from source cube */
130
+ source: AnyColumn;
131
+ /** Column from target cube */
132
+ target: AnyColumn;
133
+ /** Comparison operator - defaults to eq */
134
+ as?: (source: AnyColumn, target: AnyColumn) => SQL;
135
+ }>;
136
+ /** Override default SQL join type (derived from relationship) */
137
+ sqlJoinType?: 'inner' | 'left' | 'right' | 'full';
137
138
  }
138
139
 
139
140
  /**
@@ -176,41 +177,50 @@ declare interface DatabaseAdapter {
176
177
  */
177
178
  castToType(fieldExpr: AnyColumn | SQL, targetType: 'timestamp' | 'decimal' | 'integer'): SQL;
178
179
  /**
179
- * Build COUNT aggregation expression
180
- * @param fieldExpr - The field expression to count
181
- * @returns SQL expression for COUNT aggregation
180
+ * Build AVG aggregation expression with database-specific null handling
181
+ * @param fieldExpr - The field expression to average
182
+ * @returns SQL expression for AVG aggregation (COALESCE vs IFNULL for null handling)
182
183
  */
183
- buildCount(fieldExpr: AnyColumn | SQL): SQL;
184
+ buildAvg(fieldExpr: AnyColumn | SQL): SQL;
184
185
  /**
185
- * Build COUNT DISTINCT aggregation expression
186
- * @param fieldExpr - The field expression to count distinct values
187
- * @returns SQL expression for COUNT DISTINCT aggregation
186
+ * Build CASE WHEN conditional expression
187
+ * @param conditions - Array of condition/result pairs
188
+ * @param elseValue - Optional ELSE clause value
189
+ * @returns SQL expression for CASE WHEN statement
188
190
  */
189
- buildCountDistinct(fieldExpr: AnyColumn | SQL): SQL;
191
+ buildCaseWhen(conditions: Array<{
192
+ when: SQL;
193
+ then: any;
194
+ }>, elseValue?: any): SQL;
190
195
  /**
191
- * Build SUM aggregation expression
192
- * @param fieldExpr - The field expression to sum
193
- * @returns SQL expression for SUM aggregation
196
+ * Build boolean literal expression
197
+ * @param value - Boolean value to represent
198
+ * @returns SQL expression for boolean literal (TRUE/FALSE/1/0 depending on database)
194
199
  */
195
- buildSum(fieldExpr: AnyColumn | SQL): SQL;
200
+ buildBooleanLiteral(value: boolean): SQL;
196
201
  /**
197
- * Build AVG aggregation expression
198
- * @param fieldExpr - The field expression to average
199
- * @returns SQL expression for AVG aggregation
202
+ * Convert filter values to database-compatible types
203
+ * @param value - The filter value to convert
204
+ * @returns Converted value for database queries
200
205
  */
201
- buildAvg(fieldExpr: AnyColumn | SQL): SQL;
206
+ convertFilterValue(value: any): any;
207
+ /**
208
+ * Prepare date value for database-specific storage format
209
+ * @param date - Date value to prepare
210
+ * @returns Database-compatible date representation
211
+ */
212
+ prepareDateValue(date: Date): any;
202
213
  /**
203
- * Build MIN aggregation expression
204
- * @param fieldExpr - The field expression to find minimum
205
- * @returns SQL expression for MIN aggregation
214
+ * Check if this database stores timestamps as integers
215
+ * @returns True if timestamps are stored as integers (milliseconds), false for native timestamps
206
216
  */
207
- buildMin(fieldExpr: AnyColumn | SQL): SQL;
217
+ isTimestampInteger(): boolean;
208
218
  /**
209
- * Build MAX aggregation expression
210
- * @param fieldExpr - The field expression to find maximum
211
- * @returns SQL expression for MAX aggregation
219
+ * Convert time dimension result values back to Date objects for consistency
220
+ * @param value - The time dimension value from query results
221
+ * @returns Date object or original value if not a time dimension
212
222
  */
213
- buildMax(fieldExpr: AnyColumn | SQL): SQL;
223
+ convertTimeDimensionResult(value: any): any;
214
224
  }
215
225
 
216
226
  /**
@@ -332,6 +342,11 @@ export declare interface FilterCondition {
332
342
  */
333
343
  export declare type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'notStartsWith' | 'endsWith' | 'notEndsWith' | 'gt' | 'gte' | 'lt' | 'lte' | 'set' | 'notSet' | 'inDateRange' | 'beforeDate' | 'afterDate';
334
344
 
345
+ /**
346
+ * Derive SQL join type from semantic relationship
347
+ */
348
+ export declare function getJoinType(relationship: string, override?: string): string;
349
+
335
350
  export declare type JoinType = 'left' | 'right' | 'inner' | 'full';
336
351
 
337
352
  /**
@@ -358,16 +373,6 @@ export declare interface LegacyQueryContext<TSchema extends Record<string, any>
358
373
  cube: LegacyCompiledCube<TSchema>;
359
374
  }
360
375
 
361
- /**
362
- * Load and parse YAML cubes from file content
363
- */
364
- export declare function loadYamlCubes(yamlContent: string): SemanticCube[];
365
-
366
- /**
367
- * Load YAML cubes from file system (Node.js only)
368
- */
369
- export declare function loadYamlCubesFromFile(filePath: string): Promise<SemanticCube[]>;
370
-
371
376
  export declare interface LogicalFilter {
372
377
  and?: Filter[];
373
378
  or?: Filter[];
@@ -418,68 +423,6 @@ export declare interface MeasureMetadata {
418
423
  */
419
424
  export declare type MeasureType = 'count' | 'countDistinct' | 'countDistinctApprox' | 'sum' | 'avg' | 'min' | 'max' | 'runningTotal' | 'number';
420
425
 
421
- export declare class MultiCubeBuilder<TSchema extends Record<string, any> = Record<string, any>> {
422
- private databaseAdapter?;
423
- constructor(databaseAdapter?: DatabaseAdapter | undefined);
424
- /**
425
- * Set the database adapter (for use when not provided in constructor)
426
- */
427
- setDatabaseAdapter(adapter: DatabaseAdapter): void;
428
- /**
429
- * Analyze a semantic query to determine which cubes are involved
430
- */
431
- analyzeCubeUsage(query: SemanticQuery): Set<string>;
432
- /**
433
- * Build a multi-cube query plan
434
- */
435
- buildMultiCubeQueryPlan(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, ctx: QueryContext<TSchema>): MultiCubeQueryPlan<TSchema>;
436
- /**
437
- * Choose the primary cube based on query analysis
438
- */
439
- choosePrimaryCube(cubeNames: string[], query: SemanticQuery): string;
440
- /**
441
- * Build join plan for multi-cube query
442
- */
443
- private buildJoinPlan;
444
- /**
445
- * Build selections across multiple cubes
446
- */
447
- private buildMultiCubeSelections;
448
- /**
449
- * Build measure expression with aggregation (similar to single-cube approach)
450
- */
451
- private buildMeasureExpression;
452
- /**
453
- * Build time dimension expression (similar to single-cube approach)
454
- */
455
- private buildTimeDimensionExpression;
456
- /**
457
- * Build WHERE conditions for multi-cube query
458
- */
459
- private buildMultiCubeWhereConditions;
460
- /**
461
- * Process a single filter for multi-cube queries (handles logical and simple filters)
462
- */
463
- private processMultiCubeFilter;
464
- /**
465
- * Filter condition builder with comprehensive operator support
466
- */
467
- private buildFilterCondition;
468
- /**
469
- * Build date range condition for time dimensions
470
- */
471
- private buildDateRangeCondition;
472
- /**
473
- * Normalize date values to handle both string and Date objects
474
- * For PostgreSQL timestamp fields, Drizzle expects Date objects
475
- */
476
- private normalizeDate;
477
- /**
478
- * Build GROUP BY fields for multi-cube query
479
- */
480
- private buildMultiCubeGroupByFields;
481
- }
482
-
483
426
  /**
484
427
  * Multi-cube query context for cross-cube operations
485
428
  */
@@ -490,26 +433,7 @@ export declare interface MultiCubeQueryContext<TSchema extends Record<string, an
490
433
  currentCube: Cube<TSchema>;
491
434
  }
492
435
 
493
- /**
494
- * Multi-cube query plan - describes how to execute a cross-cube query
495
- */
496
- export declare interface MultiCubeQueryPlan<TSchema extends Record<string, any> = Record<string, any>> {
497
- /** Primary cube that drives the query */
498
- primaryCube: Cube<TSchema>;
499
- /** Additional cubes to join */
500
- joinCubes: Array<{
501
- cube: Cube<TSchema>;
502
- alias: string;
503
- joinType: 'inner' | 'left' | 'right' | 'full';
504
- joinCondition: SQL;
505
- }>;
506
- /** Combined field selections across all cubes */
507
- selections: Record<string, SQL | AnyColumn>;
508
- /** WHERE conditions for the entire query */
509
- whereConditions: SQL[];
510
- /** GROUP BY fields if aggregations are present */
511
- groupByFields: (SQL | AnyColumn)[];
512
- }
436
+ export declare type MultiCubeQueryPlan<TSchema extends Record<string, any> = Record<string, any>> = QueryPlan<TSchema>;
513
437
 
514
438
  /**
515
439
  * MySQL database executor
@@ -528,11 +452,6 @@ export declare class MySQLExecutor<TSchema extends Record<string, any> = Record<
528
452
  getEngineType(): 'mysql';
529
453
  }
530
454
 
531
- /**
532
- * Parse YAML content and return validation result with converted cubes
533
- */
534
- export declare function parseYamlCubes(yamlContent: string): YamlValidationResult;
535
-
536
455
  /**
537
456
  * PostgreSQL database executor
538
457
  * Works with postgres.js and Neon drivers
@@ -550,6 +469,81 @@ export declare class PostgresExecutor<TSchema extends Record<string, any> = Reco
550
469
  getEngineType(): 'postgres';
551
470
  }
552
471
 
472
+ export declare class QueryBuilder<TSchema extends Record<string, any> = Record<string, any>> {
473
+ private databaseAdapter;
474
+ constructor(databaseAdapter: DatabaseAdapter);
475
+ /**
476
+ * Build dynamic selections for measures, dimensions, and time dimensions
477
+ * Works for both single and multi-cube queries
478
+ */
479
+ buildSelections(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>): Record<string, SQL | AnyColumn>;
480
+ /**
481
+ * Build measure expression for HAVING clause, handling CTE references correctly
482
+ */
483
+ private buildHavingMeasureExpression;
484
+ /**
485
+ * Build measure expression with aggregation and filters
486
+ */
487
+ buildMeasureExpression(measure: any, context: QueryContext<TSchema>): SQL;
488
+ /**
489
+ * Build time dimension expression with granularity using database adapter
490
+ */
491
+ buildTimeDimensionExpression(dimensionSql: any, granularity: string | undefined, context: QueryContext<TSchema>): SQL;
492
+ /**
493
+ * Build WHERE conditions from semantic query filters (dimensions only)
494
+ * Works for both single and multi-cube queries
495
+ */
496
+ buildWhereConditions(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: QueryPlan<TSchema>): SQL[];
497
+ /**
498
+ * Build HAVING conditions from semantic query filters (measures only)
499
+ * Works for both single and multi-cube queries
500
+ */
501
+ buildHavingConditions(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: QueryPlan<TSchema>): SQL[];
502
+ /**
503
+ * Process a single filter (basic or logical)
504
+ * @param filterType - 'where' for dimension filters, 'having' for measure filters
505
+ */
506
+ private processFilter;
507
+ /**
508
+ * Build filter condition using Drizzle operators
509
+ */
510
+ private buildFilterCondition;
511
+ /**
512
+ * Build date range condition for time dimensions
513
+ */
514
+ buildDateRangeCondition(fieldExpr: AnyColumn | SQL, dateRange: string | string[]): SQL | null;
515
+ /**
516
+ * Parse relative date range expressions like "today", "yesterday", "last 7 days", "this month", etc.
517
+ * Handles all 14 DATE_RANGE_OPTIONS from the client
518
+ */
519
+ private parseRelativeDateRange;
520
+ /**
521
+ * Normalize date values to handle strings, numbers, and Date objects
522
+ * Always returns a JavaScript Date object or null
523
+ * Database-agnostic - just ensures we have a valid Date
524
+ */
525
+ private normalizeDate;
526
+ /**
527
+ * Build GROUP BY fields from dimensions and time dimensions
528
+ * Works for both single and multi-cube queries
529
+ */
530
+ buildGroupByFields(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery, context: QueryContext<TSchema>, queryPlan?: any): (SQL | AnyColumn)[];
531
+ /**
532
+ * Build ORDER BY clause with automatic time dimension sorting
533
+ */
534
+ buildOrderBy(query: SemanticQuery, selectedFields?: string[]): SQL[];
535
+ /**
536
+ * Collect numeric field names (measures + numeric dimensions) for type conversion
537
+ * Works for both single and multi-cube queries
538
+ */
539
+ collectNumericFields(cubes: Map<string, Cube<TSchema>> | Cube<TSchema>, query: SemanticQuery): string[];
540
+ /**
541
+ * Apply LIMIT and OFFSET to a query with validation
542
+ * If offset is provided without limit, add a reasonable default limit
543
+ */
544
+ applyLimitAndOffset<T>(query: T, semanticQuery: SemanticQuery): T;
545
+ }
546
+
553
547
  /**
554
548
  * Query context for dynamic building
555
549
  */
@@ -564,7 +558,8 @@ export declare interface QueryContext<TSchema extends Record<string, any> = Reco
564
558
 
565
559
  export declare class QueryExecutor<TSchema extends Record<string, any> = Record<string, any>> {
566
560
  private dbExecutor;
567
- private multiCubeBuilder;
561
+ private queryBuilder;
562
+ private queryPlanner;
568
563
  private databaseAdapter;
569
564
  constructor(dbExecutor: DatabaseExecutor<TSchema>);
570
565
  /**
@@ -576,105 +571,137 @@ export declare class QueryExecutor<TSchema extends Record<string, any> = Record<
576
571
  */
577
572
  executeQuery(cube: Cube<TSchema>, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
578
573
  /**
579
- * Execute a single cube query
574
+ * Build pre-aggregation CTE for hasMany relationships
580
575
  */
581
- private executeSingleCube;
576
+ private buildPreAggregationCTE;
582
577
  /**
583
- * Execute a Cube query (dynamic query building)
578
+ * Build join condition for CTE
584
579
  */
585
- private executeCube;
580
+ private buildCTEJoinCondition;
586
581
  /**
587
- * Execute multi-cube query using JOIN resolution
582
+ * Build unified query that works for both single and multi-cube queries
588
583
  */
589
- private executeMultiCube;
584
+ private buildUnifiedQuery;
590
585
  /**
591
- * Generate raw SQL for debugging (without execution)
586
+ * Convert query plan to cube map for QueryBuilder methods
587
+ */
588
+ private getCubesFromPlan;
589
+ /**
590
+ * Generate raw SQL for debugging (without execution) - unified approach
592
591
  */
593
592
  generateSQL(cube: Cube<TSchema>, query: SemanticQuery, securityContext: SecurityContext): Promise<{
594
593
  sql: string;
595
594
  params?: any[];
596
595
  }>;
597
596
  /**
598
- * Generate raw SQL for multi-cube queries without execution
597
+ * Generate raw SQL for multi-cube queries without execution - unified approach
599
598
  */
600
599
  generateMultiCubeSQL(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, securityContext: SecurityContext): Promise<{
601
600
  sql: string;
602
601
  params?: any[];
603
602
  }>;
604
603
  /**
605
- * Build multi-cube query (extracted from executeMultiCube for reuse)
604
+ * Generate SQL using unified approach (works for both single and multi-cube)
606
605
  */
607
- private buildMultiCubeQuery;
606
+ private generateUnifiedSQL;
608
607
  /**
609
- * Collect numeric field names (measures + numeric dimensions) for type conversion
608
+ * Generate annotations for UI metadata - unified approach
610
609
  */
611
- private collectNumericFields;
612
- /**
613
- * Collect numeric field names for multi-cube queries
614
- */
615
- private collectNumericFieldsMultiCube;
616
- /**
617
- * Apply LIMIT and OFFSET to a query with validation
618
- * If offset is provided without limit, add a reasonable default limit
619
- */
620
- private applyLimitAndOffset;
621
- /**
622
- * Generate SQL for Cube
623
- */
624
- private generateCubeSQL;
625
- /**
626
- * Build dynamic selections for Cube measures and dimensions
627
- */
628
- private buildSelections;
610
+ private generateAnnotations;
611
+ }
612
+
613
+ /**
614
+ * Unified Query Plan for both single and multi-cube queries
615
+ * - For single-cube queries: joinCubes array is empty
616
+ * - For multi-cube queries: joinCubes contains the additional cubes to join
617
+ * - selections, whereConditions, and groupByFields are populated by QueryBuilder
618
+ */
619
+ export declare interface QueryPlan<TSchema extends Record<string, any> = Record<string, any>> {
620
+ /** Primary cube that drives the query */
621
+ primaryCube: Cube<TSchema>;
622
+ /** Additional cubes to join (empty for single-cube queries) */
623
+ joinCubes: Array<{
624
+ cube: Cube<TSchema>;
625
+ alias: string;
626
+ joinType: 'inner' | 'left' | 'right' | 'full';
627
+ joinCondition: SQL;
628
+ }>;
629
+ /** Combined field selections across all cubes (built by QueryBuilder) */
630
+ selections: Record<string, SQL | AnyColumn>;
631
+ /** WHERE conditions for the entire query (built by QueryBuilder) */
632
+ whereConditions: SQL[];
633
+ /** GROUP BY fields if aggregations are present (built by QueryBuilder) */
634
+ groupByFields: (SQL | AnyColumn)[];
635
+ /** Pre-aggregation CTEs for hasMany relationships to prevent fan-out */
636
+ preAggregationCTEs?: Array<{
637
+ cube: Cube<TSchema>;
638
+ alias: string;
639
+ cteAlias: string;
640
+ joinKeys: Array<{
641
+ sourceColumn: string;
642
+ targetColumn: string;
643
+ sourceColumnObj?: AnyColumn;
644
+ targetColumnObj?: AnyColumn;
645
+ }>;
646
+ measures: string[];
647
+ }>;
648
+ }
649
+
650
+ /**
651
+ * Pre-aggregation plan for handling hasMany relationships
652
+ */
653
+ export declare class QueryPlanner<TSchema extends Record<string, any> = Record<string, any>> {
629
654
  /**
630
- * Build measure expression with aggregation and filters for Cube
655
+ * Analyze a semantic query to determine which cubes are involved
631
656
  */
632
- private buildMeasureExpression;
657
+ analyzeCubeUsage(query: SemanticQuery): Set<string>;
633
658
  /**
634
- * Build time dimension expression with granularity using database adapter
659
+ * Recursively extract cube names from filters (handles logical filters)
635
660
  */
636
- private buildTimeDimensionExpression;
661
+ private extractCubeNamesFromFilter;
637
662
  /**
638
- * Build WHERE conditions from semantic query filters (Cube)
663
+ * Extract measures referenced in filters (for CTE inclusion)
639
664
  */
640
- private buildWhereConditions;
665
+ private extractMeasuresFromFilters;
641
666
  /**
642
- * Process a single filter for Cube (basic or logical)
667
+ * Recursively extract measures from filters for a specific cube
643
668
  */
644
- private processFilter;
669
+ private extractMeasuresFromFilter;
645
670
  /**
646
- * Build filter condition using Drizzle operators
671
+ * Create a unified query plan that works for both single and multi-cube queries
647
672
  */
648
- private buildFilterCondition;
673
+ createQueryPlan(cubes: Map<string, Cube<TSchema>>, query: SemanticQuery, ctx: QueryContext<TSchema>): QueryPlan<TSchema>;
649
674
  /**
650
- * Build date range condition for time dimensions
675
+ * Choose the primary cube based on query analysis
676
+ * Uses a consistent strategy to avoid measure order dependencies
651
677
  */
652
- private buildDateRangeCondition;
678
+ choosePrimaryCube(cubeNames: string[], query: SemanticQuery, cubes?: Map<string, Cube<TSchema>>): string;
653
679
  /**
654
- * Parse relative date range expressions like "last 7 days", "this month"
680
+ * Check if a cube can reach all other cubes in the list via joins
655
681
  */
656
- private parseRelativeDateRange;
682
+ private canReachAllCubes;
657
683
  /**
658
- * Normalize date values to handle both string and Date objects
659
- * For PostgreSQL timestamp fields, Drizzle expects Date objects
684
+ * Build join plan for multi-cube query
685
+ * Supports both direct joins and transitive joins through intermediate cubes
660
686
  */
661
- private normalizeDate;
687
+ private buildJoinPlan;
662
688
  /**
663
- * Build GROUP BY fields from dimensions and time dimensions (Cube)
689
+ * Build join condition from new array-based join definition
664
690
  */
665
- private buildGroupByFields;
691
+ private buildJoinCondition;
666
692
  /**
667
- * Build ORDER BY clause with automatic time dimension sorting
693
+ * Find join path from source cube to target cube
694
+ * Returns array of join steps to reach target
668
695
  */
669
- private buildOrderBy;
696
+ private findJoinPath;
670
697
  /**
671
- * Generate annotations for UI metadata
698
+ * Plan pre-aggregation CTEs for hasMany relationships to prevent fan-out
672
699
  */
673
- private generateAnnotations;
700
+ private planPreAggregationCTEs;
674
701
  /**
675
- * Generate annotations for multi-cube queries
702
+ * Find hasMany join definition from primary cube to target cube
676
703
  */
677
- private generateMultiCubeAnnotations;
704
+ private findHasManyJoinDef;
678
705
  }
679
706
 
680
707
  /**
@@ -690,6 +717,11 @@ export declare interface QueryResult {
690
717
  };
691
718
  }
692
719
 
720
+ /**
721
+ * Resolve cube reference (handles both direct and lazy references)
722
+ */
723
+ export declare function resolveCubeReference<TSchema extends Record<string, any>>(ref: Cube<TSchema> | (() => Cube<TSchema>)): Cube<TSchema>;
724
+
693
725
  /**
694
726
  * Helper to resolve SQL expressions
695
727
  */
@@ -735,11 +767,6 @@ export declare interface SemanticCube<TSchema extends Record<string, any> = Reco
735
767
  meta?: Record<string, any>;
736
768
  }
737
769
 
738
- /**
739
- * Create a YAML cube definition from a SemanticCube (for export/migration)
740
- */
741
- export declare function semanticCubeToYaml(cube: SemanticCube): string;
742
-
743
770
  /**
744
771
  * Semantic dimension with Drizzle column support
745
772
  */
@@ -790,6 +817,10 @@ export declare class SemanticLayerCompiler<TSchema extends Record<string, any> =
790
817
  * Set or update the database executor
791
818
  */
792
819
  setDatabaseExecutor(executor: DatabaseExecutor<TSchema>): void;
820
+ /**
821
+ * Get the database engine type for SQL formatting
822
+ */
823
+ getEngineType(): 'postgres' | 'mysql' | 'sqlite' | undefined;
793
824
  /**
794
825
  * Set Drizzle instance and schema directly
795
826
  */
@@ -1253,174 +1284,4 @@ export declare interface TimeDimensionAnnotation {
1253
1284
 
1254
1285
  export declare type TimeGranularity = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
1255
1286
 
1256
- /**
1257
- * Single YAML Cube Definition
1258
- */
1259
- export declare interface YamlCube {
1260
- name: string;
1261
- title?: string;
1262
- description?: string;
1263
- sql?: string;
1264
- sql_table?: string;
1265
- sqlTable?: string;
1266
- sql_alias?: string;
1267
- sqlAlias?: string;
1268
- data_source?: string;
1269
- dataSource?: string;
1270
- refresh_key?: {
1271
- every?: string;
1272
- sql?: string;
1273
- };
1274
- refreshKey?: {
1275
- every?: string;
1276
- sql?: string;
1277
- };
1278
- dimensions?: YamlDimension[];
1279
- measures?: YamlMeasure[];
1280
- joins?: YamlJoin[];
1281
- pre_aggregations?: YamlPreAggregation[];
1282
- preAggregations?: YamlPreAggregation[];
1283
- meta?: Record<string, any>;
1284
- }
1285
-
1286
- /**
1287
- * Convert YAML cube to SemanticCube object
1288
- */
1289
- export declare function yamlCubeToSemanticCube(yamlCube: YamlCube): SemanticCube;
1290
-
1291
- /**
1292
- * YAML Dimension Definition
1293
- */
1294
- export declare interface YamlDimension {
1295
- name: string;
1296
- title?: string;
1297
- description?: string;
1298
- type: DimensionType;
1299
- sql: string;
1300
- primary_key?: boolean;
1301
- primaryKey?: boolean;
1302
- shown?: boolean;
1303
- format?: 'id' | 'link' | 'currency' | 'percent' | 'number' | 'date' | 'datetime';
1304
- meta?: Record<string, any>;
1305
- }
1306
-
1307
- /**
1308
- * YAML Join Definition
1309
- */
1310
- export declare interface YamlJoin {
1311
- name: string;
1312
- type?: JoinType;
1313
- relationship: 'one_to_one' | 'one_to_many' | 'many_to_one';
1314
- sql: string;
1315
- }
1316
-
1317
- /**
1318
- * YAML Measure Definition
1319
- */
1320
- export declare interface YamlMeasure {
1321
- name: string;
1322
- title?: string;
1323
- description?: string;
1324
- type: MeasureType;
1325
- sql: string;
1326
- format?: 'currency' | 'percent' | 'number' | 'integer';
1327
- shown?: boolean;
1328
- filters?: Array<{
1329
- sql: string;
1330
- }>;
1331
- rolling_window?: {
1332
- trailing?: string;
1333
- leading?: string;
1334
- offset?: string;
1335
- };
1336
- rollingWindow?: {
1337
- trailing?: string;
1338
- leading?: string;
1339
- offset?: string;
1340
- };
1341
- meta?: Record<string, any>;
1342
- }
1343
-
1344
- /**
1345
- * YAML Pre-aggregation Definition
1346
- */
1347
- export declare interface YamlPreAggregation {
1348
- name: string;
1349
- measures: string[];
1350
- dimensions: string[];
1351
- time_dimension?: {
1352
- dimension: string;
1353
- granularity: TimeGranularity[];
1354
- };
1355
- timeDimension?: {
1356
- dimension: string;
1357
- granularity: TimeGranularity[];
1358
- };
1359
- refresh_key?: {
1360
- every: string;
1361
- sql?: string;
1362
- };
1363
- refreshKey?: {
1364
- every: string;
1365
- sql?: string;
1366
- };
1367
- indexes?: Record<string, string[]>;
1368
- }
1369
-
1370
- /**
1371
- * Root YAML Schema - supports multiple formats:
1372
- * 1. Single cube definition (properties at root)
1373
- * 2. Multiple cubes (cubes array)
1374
- * 3. Cubes and views (separate arrays)
1375
- */
1376
- export declare interface YamlSchema {
1377
- name?: string;
1378
- title?: string;
1379
- description?: string;
1380
- sql?: string;
1381
- sql_table?: string;
1382
- sqlTable?: string;
1383
- sql_alias?: string;
1384
- sqlAlias?: string;
1385
- data_source?: string;
1386
- dataSource?: string;
1387
- refresh_key?: YamlCube['refresh_key'];
1388
- refreshKey?: YamlCube['refreshKey'];
1389
- dimensions?: YamlDimension[];
1390
- measures?: YamlMeasure[];
1391
- joins?: YamlJoin[];
1392
- pre_aggregations?: YamlPreAggregation[];
1393
- preAggregations?: YamlPreAggregation[];
1394
- meta?: Record<string, any>;
1395
- cubes?: YamlCube[];
1396
- views?: YamlView[];
1397
- }
1398
-
1399
- /**
1400
- * Validation result for YAML parsing
1401
- */
1402
- export declare interface YamlValidationResult {
1403
- valid: boolean;
1404
- errors: string[];
1405
- warnings: string[];
1406
- cubes: YamlCube[];
1407
- }
1408
-
1409
- /**
1410
- * YAML View Definition (for future support)
1411
- */
1412
- export declare interface YamlView {
1413
- name: string;
1414
- title?: string;
1415
- description?: string;
1416
- cubes: Array<{
1417
- join_path?: string;
1418
- joinPath?: string;
1419
- prefix?: boolean;
1420
- includes?: string[];
1421
- excludes?: string[];
1422
- }>;
1423
- meta?: Record<string, any>;
1424
- }
1425
-
1426
1287
  export { }