diff options
author | polwex <polwex@sortug.com> | 2025-05-15 04:37:12 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-05-15 04:37:12 +0700 |
commit | df7ffaf4cb722890ca3159c3839c61552f7195d3 (patch) | |
tree | c87b7e5e7556f370cfb8ea5486c36aabcd8c8d3b /src/lib/types |
all working now...
Diffstat (limited to 'src/lib/types')
-rw-r--r-- | src/lib/types/index.ts | 108 |
1 files changed, 108 insertions, 0 deletions
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<T> = { ok: T } | { error: string }; +export type AsyncRes<T> = Promise<Result<T>>; +// 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<string>; + getSupportedLanguages(): AsyncRes<Language[]>; + detect?: (text: string) => Promise<string>; + transliterate?: ( + text: string[], + lang: string, + fromScript: string, + toScript: string, + ) => AsyncRes<string>; +} + +// 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<T> = { results: T; page: number }; +// export type Paged<T> = 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; +}; |