Files
postgres/src/utils/featureConfig.ts
copilot-swe-agent[bot] 29f7ba86a9 refactor: Address code review feedback
- Replace 'as any' with proper FeaturesConfig type definition
- Improve CHECK constraint SQL injection validation with comprehensive patterns
- Move isValidIdentifier to shared validation module
- Add comprehensive unit tests for identifier validation (12 tests)
- Fix all linting issues
- All 52 unit tests passing

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2026-01-08 03:48:44 +00:00

81 lines
1.7 KiB
TypeScript

import featuresConfig from '@/config/features.json';
export type Feature = {
id: string;
name: string;
description: string;
enabled: boolean;
priority: string;
endpoints: Array<{
path: string;
methods: string[];
description: string;
}>;
ui: {
showInNav: boolean;
icon: string;
actions: string[];
};
};
export type DataType = {
name: string;
category: string;
requiresLength: boolean;
defaultLength?: number;
autoIncrement?: boolean;
};
export type NavItem = {
id: string;
label: string;
icon: string;
featureId: string;
};
export type ConstraintType = {
name: string;
description: string;
requiresColumn: boolean;
requiresExpression: boolean;
};
// Type definition for the features config structure
type FeaturesConfig = {
features: Feature[];
dataTypes: DataType[];
constraintTypes?: ConstraintType[];
navItems: NavItem[];
};
const config = featuresConfig as FeaturesConfig;
export function getFeatures(): Feature[] {
return config.features.filter(f => f.enabled);
}
export function getFeatureById(id: string): Feature | undefined {
return config.features.find(f => f.id === id && f.enabled);
}
export function getDataTypes(): DataType[] {
return config.dataTypes;
}
export function getConstraintTypes(): ConstraintType[] {
return config.constraintTypes || [];
}
export function getNavItems(): NavItem[] {
return config.navItems.filter((item) => {
const feature = getFeatureById(item.featureId);
return feature && feature.enabled;
});
}
export function getEnabledFeaturesByPriority(priority: string): Feature[] {
return config.features.filter(
f => f.enabled && f.priority === priority,
);
}