From df7ffaf4cb722890ca3159c3839c61552f7195d3 Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 15 May 2025 04:37:12 +0700 Subject: all working now... --- src/lib/types/index.ts | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/lib/types/index.ts (limited to 'src/lib/types') diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts new file mode 100644 index 0000000..0a46643 --- /dev/null +++ b/src/lib/types/index.ts @@ -0,0 +1,108 @@ +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; +}; -- cgit v1.2.3