drizzle-cube 0.2.18 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/{compiler-Cwmfwbls.js → compiler-DDXMrb9d.js} +3896 -3309
- package/dist/adapters/compiler-S2NEGW7Q.cjs +22 -0
- package/dist/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/client/charts.js +2 -2
- package/dist/client/chunks/{charts-B8YMw1mi.js → charts-BympPNAT.js} +2249 -2062
- package/dist/client/chunks/charts-BympPNAT.js.map +1 -0
- package/dist/client/chunks/{charts-amt7VOyw.js → charts-CEz9wcfI.js} +32 -32
- package/dist/client/chunks/{charts-amt7VOyw.js.map → charts-CEz9wcfI.js.map} +1 -1
- package/dist/client/chunks/{components-K3xrnHN-.js → components-__XqYVbP.js} +4694 -4502
- package/dist/client/chunks/components-__XqYVbP.js.map +1 -0
- package/dist/client/chunks/core-DWO_N91H.js +6 -0
- package/dist/client/chunks/core-DWO_N91H.js.map +1 -0
- package/dist/client/chunks/{index-B7NSVb33.js → index-mA36fTTV.js} +2 -2
- package/dist/client/chunks/{index-B7NSVb33.js.map → index-mA36fTTV.js.map} +1 -1
- package/dist/client/components/AnalysisBuilder/types.d.ts +9 -0
- package/dist/client/components/charts/ChartTooltip.d.ts +1 -1
- package/dist/client/components.js +2 -2
- package/dist/client/hooks.js +2 -2
- package/dist/client/icons.js +1 -1
- package/dist/client/index.js +3 -3
- package/dist/client/providers.js +1 -1
- package/dist/client/types.d.ts +18 -0
- package/dist/client/utils/comparisonUtils.d.ts +96 -0
- package/dist/client/utils/index.d.ts +1 -0
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/index.cjs +18 -18
- package/dist/server/index.d.ts +118 -2
- package/dist/server/index.js +3619 -3032
- package/package.json +1 -1
- package/dist/adapters/compiler-A8IN32GM.cjs +0 -22
- package/dist/client/chunks/charts-B8YMw1mi.js.map +0 -1
- package/dist/client/chunks/components-K3xrnHN-.js.map +0 -1
- package/dist/client/chunks/core-Dkym7d1O.js +0 -6
- package/dist/client/chunks/core-Dkym7d1O.js.map +0 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -647,8 +647,41 @@ declare interface Measure {
|
|
|
647
647
|
/**
|
|
648
648
|
* Window function configuration
|
|
649
649
|
* Used for lag, lead, rank, movingAvg, and other window function measure types
|
|
650
|
+
*
|
|
651
|
+
* Post-aggregation window functions:
|
|
652
|
+
* When `measure` is specified, the window function operates on AGGREGATED data.
|
|
653
|
+
* The base measure is first aggregated (grouped by query dimensions), then the
|
|
654
|
+
* window function is applied to the aggregated results.
|
|
655
|
+
*
|
|
656
|
+
* Example: Month-over-month revenue change
|
|
657
|
+
* ```typescript
|
|
658
|
+
* revenueChange: {
|
|
659
|
+
* type: 'lag',
|
|
660
|
+
* windowConfig: {
|
|
661
|
+
* measure: 'totalRevenue', // Reference to aggregate measure
|
|
662
|
+
* operation: 'difference', // current - previous
|
|
663
|
+
* orderBy: [{ field: 'date', direction: 'asc' }]
|
|
664
|
+
* }
|
|
665
|
+
* }
|
|
666
|
+
* ```
|
|
650
667
|
*/
|
|
651
668
|
windowConfig?: {
|
|
669
|
+
/**
|
|
670
|
+
* Reference to the measure this window function operates on.
|
|
671
|
+
* The referenced measure will be aggregated first, then the window function applied.
|
|
672
|
+
* Can be a simple name ('totalRevenue') or fully qualified ('Sales.totalRevenue').
|
|
673
|
+
*/
|
|
674
|
+
measure?: string;
|
|
675
|
+
/**
|
|
676
|
+
* Operation to perform after getting the window result:
|
|
677
|
+
* - 'raw': Return the window function result directly (default for rank, rowNumber, ntile)
|
|
678
|
+
* - 'difference': Subtract window result from current value (current - window)
|
|
679
|
+
* - 'ratio': Divide current value by window result (current / window)
|
|
680
|
+
* - 'percentChange': Calculate percentage change ((current - window) / window * 100)
|
|
681
|
+
*
|
|
682
|
+
* Default: 'difference' for lag/lead, 'raw' for rank/rowNumber/ntile/firstValue/lastValue
|
|
683
|
+
*/
|
|
684
|
+
operation?: 'raw' | 'difference' | 'ratio' | 'percentChange';
|
|
652
685
|
/** Dimension references to partition by (e.g., ['employeeId']) */
|
|
653
686
|
partitionBy?: string[];
|
|
654
687
|
/** Columns to order by with direction */
|
|
@@ -727,6 +760,21 @@ export declare class MySQLExecutor extends BaseDatabaseExecutor {
|
|
|
727
760
|
getEngineType(): 'mysql' | 'singlestore';
|
|
728
761
|
}
|
|
729
762
|
|
|
763
|
+
/**
|
|
764
|
+
* Period comparison metadata for compareDateRange queries
|
|
765
|
+
* Provides information about the periods being compared
|
|
766
|
+
*/
|
|
767
|
+
export declare interface PeriodComparisonMetadata {
|
|
768
|
+
/** The date ranges being compared */
|
|
769
|
+
ranges: [string, string][];
|
|
770
|
+
/** Human-readable labels for each period */
|
|
771
|
+
labels: string[];
|
|
772
|
+
/** The time dimension used for comparison */
|
|
773
|
+
timeDimension: string;
|
|
774
|
+
/** Granularity used for the comparison */
|
|
775
|
+
granularity?: TimeGranularity;
|
|
776
|
+
}
|
|
777
|
+
|
|
730
778
|
/**
|
|
731
779
|
* Type helpers for specific database types
|
|
732
780
|
*/
|
|
@@ -755,13 +803,21 @@ export declare interface PreAggregationAnalysis {
|
|
|
755
803
|
cteAlias: string;
|
|
756
804
|
/** Why this cube needs a CTE */
|
|
757
805
|
reason: string;
|
|
758
|
-
/** Measures included in CTE */
|
|
806
|
+
/** Measures included in CTE (aggregate measures + window base measures) */
|
|
759
807
|
measures: string[];
|
|
760
808
|
/** Join keys used */
|
|
761
809
|
joinKeys: Array<{
|
|
762
810
|
sourceColumn: string;
|
|
763
811
|
targetColumn: string;
|
|
764
812
|
}>;
|
|
813
|
+
/**
|
|
814
|
+
* Type of CTE:
|
|
815
|
+
* - 'aggregate': Standard CTE with GROUP BY (count, sum, avg, etc.)
|
|
816
|
+
*
|
|
817
|
+
* Note: Window function CTEs are no longer used. Post-aggregation window
|
|
818
|
+
* functions are applied in the outer query after data is aggregated.
|
|
819
|
+
*/
|
|
820
|
+
cteType?: 'aggregate';
|
|
765
821
|
}
|
|
766
822
|
|
|
767
823
|
/**
|
|
@@ -777,10 +833,19 @@ export declare interface PreAggregationCTEInfo {
|
|
|
777
833
|
cteAlias: string;
|
|
778
834
|
/** Join keys to connect CTE back to main query */
|
|
779
835
|
joinKeys: JoinKeyInfo[];
|
|
780
|
-
/** List of measure names included in this CTE */
|
|
836
|
+
/** List of measure names included in this CTE (aggregate measures + window base measures) */
|
|
781
837
|
measures: string[];
|
|
782
838
|
/** Propagating filters from related cubes (for cross-cube filter propagation) */
|
|
783
839
|
propagatingFilters?: PropagatingFilter[];
|
|
840
|
+
/**
|
|
841
|
+
* Type of CTE:
|
|
842
|
+
* - 'aggregate': Standard CTE with GROUP BY for count/sum/avg measures
|
|
843
|
+
*
|
|
844
|
+
* Note: Window function CTEs are no longer used. Post-aggregation window
|
|
845
|
+
* functions (lag, lead, rank, etc.) operate on aggregated data and are
|
|
846
|
+
* applied in the outer query SELECT clause, not in separate CTEs.
|
|
847
|
+
*/
|
|
848
|
+
cteType?: 'aggregate';
|
|
784
849
|
}
|
|
785
850
|
|
|
786
851
|
/**
|
|
@@ -998,6 +1063,7 @@ export declare class QueryExecutor {
|
|
|
998
1063
|
private queryPlanner;
|
|
999
1064
|
private cteBuilder;
|
|
1000
1065
|
private databaseAdapter;
|
|
1066
|
+
private comparisonQueryBuilder;
|
|
1001
1067
|
constructor(dbExecutor: DatabaseExecutor);
|
|
1002
1068
|
/**
|
|
1003
1069
|
* Unified query execution method that handles both single and multi-cube queries
|
|
@@ -1007,6 +1073,16 @@ export declare class QueryExecutor {
|
|
|
1007
1073
|
* Legacy interface for single cube queries
|
|
1008
1074
|
*/
|
|
1009
1075
|
executeQuery(cube: Cube, query: SemanticQuery, securityContext: SecurityContext): Promise<QueryResult>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Execute a comparison query with multiple date periods
|
|
1078
|
+
* Expands compareDateRange into multiple sub-queries and merges results
|
|
1079
|
+
*/
|
|
1080
|
+
private executeComparisonQuery;
|
|
1081
|
+
/**
|
|
1082
|
+
* Standard query execution (non-comparison)
|
|
1083
|
+
* This is the core execution logic extracted for use by comparison queries
|
|
1084
|
+
*/
|
|
1085
|
+
private executeStandardQuery;
|
|
1010
1086
|
/**
|
|
1011
1087
|
* Validate that all cubes in the query plan have proper security filtering.
|
|
1012
1088
|
* Emits a warning if a cube's sql() function doesn't return a WHERE clause.
|
|
@@ -1051,6 +1127,22 @@ export declare class QueryExecutor {
|
|
|
1051
1127
|
* rather than appearing as separate parameters in different parts of the query
|
|
1052
1128
|
*/
|
|
1053
1129
|
private preloadFilterCache;
|
|
1130
|
+
/**
|
|
1131
|
+
* Build post-aggregation window function expression
|
|
1132
|
+
*
|
|
1133
|
+
* Post-aggregation windows operate on already-aggregated data:
|
|
1134
|
+
* 1. The base measure is aggregated (e.g., SUM(revenue))
|
|
1135
|
+
* 2. The window function is applied (e.g., LAG(...) OVER ORDER BY date)
|
|
1136
|
+
* 3. An optional operation is applied (e.g., current - previous)
|
|
1137
|
+
*
|
|
1138
|
+
* @param measure - The window function measure definition
|
|
1139
|
+
* @param baseMeasureExpr - The aggregated base measure expression
|
|
1140
|
+
* @param query - The semantic query (for dimension context)
|
|
1141
|
+
* @param context - Query context
|
|
1142
|
+
* @param cube - The cube containing this measure
|
|
1143
|
+
* @returns SQL expression for the window function
|
|
1144
|
+
*/
|
|
1145
|
+
private buildPostAggregationWindowExpression;
|
|
1054
1146
|
}
|
|
1055
1147
|
|
|
1056
1148
|
/**
|
|
@@ -1215,6 +1307,8 @@ export declare interface QueryResult {
|
|
|
1215
1307
|
dimensions: Record<string, DimensionAnnotation>;
|
|
1216
1308
|
segments: Record<string, unknown>;
|
|
1217
1309
|
timeDimensions: Record<string, TimeDimensionAnnotation>;
|
|
1310
|
+
/** Period comparison metadata (present when compareDateRange is used) */
|
|
1311
|
+
periods?: PeriodComparisonMetadata;
|
|
1218
1312
|
};
|
|
1219
1313
|
}
|
|
1220
1314
|
|
|
@@ -1230,6 +1324,12 @@ export declare interface QuerySummary {
|
|
|
1230
1324
|
cteCount: number;
|
|
1231
1325
|
/** Has hasMany relationships requiring aggregation */
|
|
1232
1326
|
hasPreAggregation: boolean;
|
|
1327
|
+
/**
|
|
1328
|
+
* Whether query contains post-aggregation window function measures.
|
|
1329
|
+
* These window functions (lag, lead, rank, etc.) operate on aggregated
|
|
1330
|
+
* data and are applied in the outer query after CTEs.
|
|
1331
|
+
*/
|
|
1332
|
+
hasWindowFunctions?: boolean;
|
|
1233
1333
|
}
|
|
1234
1334
|
|
|
1235
1335
|
/**
|
|
@@ -1471,6 +1571,22 @@ export declare interface TimeDimension {
|
|
|
1471
1571
|
* Default: true (enabled)
|
|
1472
1572
|
*/
|
|
1473
1573
|
fillMissingDates?: boolean;
|
|
1574
|
+
/**
|
|
1575
|
+
* Array of date ranges for period-over-period comparison.
|
|
1576
|
+
* When specified, queries are executed for each period and results are merged
|
|
1577
|
+
* with period metadata (__periodIndex, __periodDayIndex) for alignment.
|
|
1578
|
+
*
|
|
1579
|
+
* Each range can be:
|
|
1580
|
+
* - A relative string: 'this week', 'last month', 'last 30 days'
|
|
1581
|
+
* - A tuple: ['2024-01-01', '2024-01-31']
|
|
1582
|
+
*
|
|
1583
|
+
* @example
|
|
1584
|
+
* compareDateRange: [
|
|
1585
|
+
* 'last 30 days', // Current period
|
|
1586
|
+
* ['2024-01-01', '2024-01-30'] // Prior period to compare
|
|
1587
|
+
* ]
|
|
1588
|
+
*/
|
|
1589
|
+
compareDateRange?: (string | [string, string])[];
|
|
1474
1590
|
}
|
|
1475
1591
|
|
|
1476
1592
|
export declare interface TimeDimensionAnnotation {
|