export const LANGUAGE_CODES = ["en", "it", "ru"] as const; export type Language = (typeof LANGUAGE_CODES)[number]; export type Source = "provider" | "cache"; export const PARTS_OF_SPEECH = [ "noun", "verb", "adjective", "adverb", "pronoun", ] as const; export type PartOfSpeech = (typeof PARTS_OF_SPEECH)[number] | (string & {}); export function isLanguage(value: string): value is Language { return (LANGUAGE_CODES as readonly string[]).includes(value); } export function parseLanguage(value: string): Language | null { const normalized = value.trim().toLowerCase(); return isLanguage(normalized) ? normalized : null; } export interface Form { word: string; tags?: string[]; } export interface Quote { text: string; reference: string; } export interface Sense { definition: string; tags?: string[]; examples?: string[]; quotes?: Quote[]; synonyms?: string[]; antonyms?: string[]; } export interface Entry { language: Language; partOfSpeech: PartOfSpeech; ipa?: string; forms?: Form[]; senses: Sense[]; synonyms?: string[]; antonyms?: string[]; } export interface TranslationResult { source_text: string; source_lang: Language; target_lang: Language; translations: string[]; provider: string; model?: string; source: Source; generated_at?: string; } export interface DictionaryResult { word: string; entries: Entry[]; provider: string; model?: string; source: Source; generated_at?: string; } export interface CollocationsResult { word: string; lang: Language; provider: string; model?: string; source: Source; collocations: string[]; generated_at?: string; } export interface ExamplesResult { word: string; lang: Language; provider: string; model?: string; source: Source; examples: string[]; generated_at?: string; } export interface DeepLUsage { character_count: number; character_limit: number; } export interface AIUsage { requests: number; tokens: number; token_limit: number; } export interface UsageResult { deepl?: DeepLUsage; ai: AIUsage; } export type CollectionType = "auto" | "user"; export interface CollectionResult { id: string; name: string; lang: Language; userId: string; words: string[]; type: CollectionType; updated_at: string; created_at: string; } export type Fetched = T & { fetched_at: string }; export interface User { id: string; email: string; first_name: string; second_name: string; created_at: string; }