drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
75 lines (74 loc) • 3.74 kB
TypeScript
import { Filter, DashboardFilter, CubeMeta, DashboardConfig } from '../types';
/**
* Memoization infrastructure to prevent creating new array references
* when filter data is semantically identical
*/
export declare const EMPTY_FILTERS: Filter[];
/**
* Get dashboard filters that should be applied to a portlet based on its mapping configuration
* MEMOIZED: Returns stable array reference when inputs are semantically identical
* @param dashboardFilters - All available dashboard filters
* @param filterMapping - Array of filter IDs that apply to this portlet
* @returns Array of filters that should be applied to the portlet
*/
export declare function getApplicableDashboardFilters(dashboardFilters: DashboardFilter[] | undefined, filterMapping: string[] | undefined): Filter[];
/**
* Merge dashboard filters with portlet filters using AND logic
* Dashboard filters are combined with portlet filters so both sets of filters apply
* MEMOIZED: Returns stable array reference when inputs are semantically identical
* @param dashboardFilters - Filters from dashboard-level configuration
* @param portletFilters - Filters from portlet query
* @returns Merged filter array with AND logic
*/
export declare function mergeDashboardAndPortletFilters(dashboardFilters: Filter[], portletFilters: Filter[] | undefined): Filter[] | undefined;
/**
* Check if a filter field exists in the cube metadata
* This helps identify filters that might not apply to a specific portlet's data
* @param filter - The filter to validate
* @param cubeMeta - Cube metadata to validate against
* @returns true if the filter field exists in any cube's measures or dimensions
*/
export declare function validateFilterForCube(filter: Filter, cubeMeta: CubeMeta | null): boolean;
/**
* Validate that all dashboard filters in a portlet's mapping exist and are valid
* @param dashboardFilters - All available dashboard filters
* @param filterMapping - The portlet's filter mapping
* @param cubeMeta - Cube metadata for validation
* @returns Object with validation result and list of invalid filter IDs
*/
export declare function validatePortletFilterMapping(dashboardFilters: DashboardFilter[] | undefined, filterMapping: string[] | undefined, cubeMeta: CubeMeta | null): {
isValid: boolean;
invalidFilterIds: string[];
missingFilterIds: string[];
};
/**
* Extract all unique measures, dimensions, and timeDimensions used across all portlets in a dashboard
* This helps create a filtered schema view showing only fields relevant to the dashboard
* @param dashboardConfig - Dashboard configuration
* @returns Object with unique measures, dimensions, and timeDimensions
*/
export declare function extractDashboardFields(dashboardConfig: DashboardConfig): {
measures: Set<string>;
dimensions: Set<string>;
timeDimensions: Set<string>;
};
/**
* Time dimension type from CubeQuery
*/
type TimeDimension = {
dimension: string;
granularity?: string;
dateRange?: string[] | string;
};
/**
* Apply universal time filters to a portlet's timeDimensions
* Universal time filters apply their dateRange to ALL time dimensions in the portlet
* MEMOIZED: Returns stable array reference when inputs are semantically identical
*
* @param dashboardFilters - All dashboard filters
* @param filterMapping - Filter IDs that apply to this portlet
* @param portletTimeDimensions - The portlet's existing timeDimensions array
* @returns Updated timeDimensions array with date ranges applied
*/
export declare function applyUniversalTimeFilters(dashboardFilters: DashboardFilter[] | undefined, filterMapping: string[] | undefined, portletTimeDimensions: TimeDimension[] | undefined): TimeDimension[] | undefined;
export {};