/** * @fileoverview Load External Route Catalogs for Parity Validation * Loads and parses route constants from external repositories for comparison * Part of CON-06: Cross-Repo Schema Parity & Integration Validation */ import fs from 'fs'; import path from 'path'; /** * Load route catalog from an external repository */ export async function loadExternalRoutes(repoPath: string): Promise { try { // Look for the SDK in node_modules const sdkPath = path.join(repoPath, 'node_modules/@trader/contracts'); if (!fs.existsSync(sdkPath)) { throw new Error(`SDK not found in repository: ${sdkPath}`); } // Try to load the routes from the SDK const routesPath = path.join(sdkPath, 'src/routes/routes.js'); if (!fs.existsSync(routesPath)) { // Try alternative locations const altRoutesPath = path.join(sdkPath, 'dist/routes.js'); if (!fs.existsSync(altRoutesPath)) { throw new Error(`Routes file not found in SDK: ${routesPath} or ${altRoutesPath}`); } } // For now, we'll return a placeholder structure // In a full implementation, this would dynamically import and parse the routes return { ROUTES: { AUTH: {}, USER: {}, ADMIN: {}, INFRA: {}, PORTFOLIO: {}, MARKET: {}, ML: {}, TRADING: {} } }; } catch (error) { console.warn(`Warning: Could not load routes from ${repoPath}:`, error); return null; } } /** * Load route catalogs from multiple repositories */ export async function loadMultipleExternalRoutes(repoPaths: string[]): Promise> { const results: Record = {}; for (const repoPath of repoPaths) { if (!repoPath) continue; try { const routes = await loadExternalRoutes(repoPath); if (routes) { const repoName = path.basename(repoPath); results[repoName] = routes; } } catch (error) { console.warn(`Failed to load routes from ${repoPath}:`, error); } } return results; } /** * Extract route constants from a routes object for comparison */ export function extractRouteConstants(routesObj: any): string[] { const constants: string[] = []; function extractFromObject(obj: any, prefix = ''): void { for (const [key, value] of Object.entries(obj)) { if (typeof value === 'string') { constants.push(prefix ? `${prefix}.${key}` : key); } else if (typeof value === 'object' && value !== null) { extractFromObject(value, prefix ? `${prefix}.${key}` : key); } } } if (routesObj && typeof routesObj === 'object') { extractFromObject(routesObj); } return constants; }