export type Result = { ok: T } | { error: string }; export type AsyncRes = Promise>; // Language object structure for API responses export interface State { user: { name: string; id: number } | null; } export interface Language { code: string; name: string; nativeName?: string; supportsSource?: boolean; supportsTarget?: boolean; } // Common interface for all translation services export interface TranslationService { endpoint: string; translate( text: string, sourceLang: string, targetLang: string, ): AsyncRes; getSupportedLanguages(): AsyncRes; detect?: (text: string) => Promise; transliterate?: ( text: string[], lang: string, fromScript: string, toScript: string, ) => AsyncRes; } // Service credentials interface export interface TranslationCredentials { apiKey: string; region?: string; endpoint?: string; projectId?: string; } // Translation error class for consistent error handling export class TranslationError extends Error { public statusCode: number; public provider: string; constructor(message: string, statusCode: number = 500, provider: string) { super(message); this.name = "TranslationError"; this.statusCode = statusCode; this.provider = provider; } } // Translation request tracking for rate limiting and analytics export interface TranslationRequest { id: string; timestamp: number; userId: string; provider: string; source: string; target: string; characters: number; success: boolean; processingTimeMs: number; } export type WordData = { spelling: string; lang: string; ipa: string; meanings: Meaning[]; references?: any; }; export type Meaning = { pos: string; // part of speech; meaning: string[]; etymology: string; references?: any; }; export type Paged = { results: T; page: number }; // export type Paged = T & { page: number }; export type AddWord = { spelling: string; lang: string; syllables?: number; frequency?: number; prosody?: string; type: "word" | "expression" | "syllable"; ipa?: string; confidence?: number; }; export type AddSense = { id?: number; parent_id: number | bigint; spelling: string; etymology?: string; pos: string; ipa?: string; prosody?: string; senses?: string; forms?: string; related?: string; confidence?: number; };