Reference implementation for the Phoenix Architecture. Work in progress. aicoding.leaflet.pub/
ai coding crazy
at main 63 lines 2.2 kB view raw
1/** 2 * Architecture & Runtime Target Registry 3 */ 4 5import type { Architecture, RuntimeTarget, ResolvedTarget } from '../models/architecture.js'; 6import { webApi } from './web-api.js'; 7import { nodeTypescript } from './node-typescript.js'; 8 9// ─── Architecture registry ────────────────────────────────────────────────── 10 11const ARCHITECTURES: Record<string, Architecture> = { 12 'web-api': webApi, 13}; 14 15// ─── Runtime target registry ──────────────────────────────────────────────── 16 17const RUNTIME_TARGETS: Record<string, RuntimeTarget> = { 18 'node-typescript': nodeTypescript, 19}; 20 21// ─── Public API ───────────────────────────────────────────────────────────── 22 23/** 24 * Resolve a target string like "web-api/node-typescript" or legacy "sqlite-web-api" 25 * into a full ResolvedTarget. 26 */ 27export function resolveTarget(target: string): ResolvedTarget | null { 28 // Handle legacy name 29 if (target === 'sqlite-web-api') { 30 return resolveTarget('web-api/node-typescript'); 31 } 32 33 // Try "arch/runtime" format 34 if (target.includes('/')) { 35 const [archName, rtName] = target.split('/'); 36 const arch = ARCHITECTURES[archName]; 37 const rt = RUNTIME_TARGETS[rtName]; 38 if (arch && rt) return { architecture: arch, runtime: rt }; 39 return null; 40 } 41 42 // Try as architecture name, use first available runtime 43 const arch = ARCHITECTURES[target]; 44 if (arch && arch.runtimeTargets.length > 0) { 45 const rt = RUNTIME_TARGETS[arch.runtimeTargets[0]]; 46 if (rt) return { architecture: arch, runtime: rt }; 47 } 48 49 return null; 50} 51 52export function listArchitectures(): string[] { 53 return Object.keys(ARCHITECTURES); 54} 55 56export function listRuntimeTargets(): string[] { 57 return Object.keys(RUNTIME_TARGETS); 58} 59 60/** @deprecated — use resolveTarget instead */ 61export function getArchitecture(name: string): ResolvedTarget | null { 62 return resolveTarget(name); 63}