UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

147 lines 4.79 kB
/** * Asset Selection Strategies * Phase 2, Checkpoint B2 - Intelligent asset selection algorithms */ import { LoadedAsset } from './asset-loader'; export interface SelectionResult { selected: LoadedAsset[]; total: number; strategy: string; seed?: string; metadata: { selectionRate: number; avgFileSize: number; typeDistribution: Record<string, number>; validAssets: number; executionTime: number; }; } export interface SelectionOptions { count?: number; seed?: string; ensureDeterministic?: boolean; preserveOrder?: boolean; respectWeights?: boolean; } export interface FilterFunction { (asset: LoadedAsset, index: number, assets: LoadedAsset[]): boolean; } export interface WeightFunction { (asset: LoadedAsset, index: number, assets: LoadedAsset[]): number; } export interface WeightedSelectionConfig { weightFunction?: WeightFunction; weights?: Record<string, number>; biases?: { byType?: Record<string, number>; bySize?: 'prefer_small' | 'prefer_large' | 'neutral'; byAge?: 'prefer_new' | 'prefer_old' | 'neutral'; byTags?: Record<string, number>; }; } export declare class AssetSelectionEngine { private static readonly DEFAULT_SEED; /** * Select all assets from the pool (no filtering) */ static selectAll(assets: LoadedAsset[], options?: SelectionOptions): SelectionResult; /** * Select random assets with optional seed for deterministic results */ static selectRandom(assets: LoadedAsset[], count: number, options?: SelectionOptions): SelectionResult; /** * Select assets using custom filter functions */ static selectFiltered(assets: LoadedAsset[], filters: FilterFunction[], options?: SelectionOptions): SelectionResult; /** * Select specific assets by file names or IDs */ static selectManual(assets: LoadedAsset[], identifiers: string[], options?: SelectionOptions): SelectionResult; /** * Select assets using weighted probability distribution */ static selectWeighted(assets: LoadedAsset[], count: number, config: WeightedSelectionConfig, options?: SelectionOptions): SelectionResult; /** * Create a seeded random number generator */ private static createSeededRandom; /** * Calculate bias weight based on asset characteristics */ private static calculateBiasWeight; /** * Perform weighted selection using cumulative probability */ private static performWeightedSelection; /** * Calculate metadata for selection results */ private static calculateSelectionMetadata; /** * Create common filter functions for convenience */ static createFilters: { /** * Filter by asset type */ byType: (types: ("markdown" | "json" | "csv" | "image")[]) => FilterFunction; /** * Filter by tags (asset must have at least one of the specified tags) */ byTags: (tags: string[]) => FilterFunction; /** * Filter by required tags (asset must have all specified tags) */ byRequiredTags: (tags: string[]) => FilterFunction; /** * Filter by category */ byCategory: (categories: string[]) => FilterFunction; /** * Filter by file size range */ bySizeRange: (minSize: number, maxSize: number) => FilterFunction; /** * Filter by date range */ byDateRange: (startDate: Date, endDate: Date) => FilterFunction; /** * Filter by content length */ byContentLength: (minLength: number, maxLength?: number) => FilterFunction; /** * Filter valid assets only */ validOnly: () => FilterFunction; /** * Filter by metadata field existence */ hasField: (fieldName: string) => FilterFunction; /** * Filter by metadata field value */ fieldEquals: (fieldName: string, value: any) => FilterFunction; }; /** * Create common weight functions for convenience */ static createWeightFunctions: { /** * Weight by file size (larger files get higher weight) */ byFileSize: () => WeightFunction; /** * Weight by recency (newer files get higher weight) */ byRecency: () => WeightFunction; /** * Weight by tag count (more tags = higher weight) */ byTagCount: () => WeightFunction; /** * Weight by content length */ byContentLength: () => WeightFunction; }; } //# sourceMappingURL=selection-strategies.d.ts.map