illyria-scraper
Version:
Google Translate scraper for Illyria Translate
48 lines (47 loc) • 1.52 kB
TypeScript
import { type AxiosResponse } from 'axios';
import type { LangCodeGoogle } from './language.js';
export declare const Endpoint: {
readonly INFO: "info";
readonly TEXT: "text";
readonly AUDIO: "audio";
};
type EndpointType = (typeof Endpoint)[keyof typeof Endpoint];
/**
* Type definitions for parameters required by each endpoint
*/
type Params = {
[Endpoint.INFO]: {
body: string;
};
[Endpoint.TEXT]: {
source: LangCodeGoogle<'source'>;
target: LangCodeGoogle<'target'>;
query: string;
};
[Endpoint.AUDIO]: {
lang: LangCodeGoogle<'target'>;
text: string;
textLength: number;
speed: number;
};
};
/**
* Creates a request handler for a specific endpoint with built-in retry capabilities
*
* @param endpoint - The API endpoint to call
* @param retry - Current retry attempt number (used internally)
* @returns An object with methods to execute the request
*/
declare const request: <T extends EndpointType>(endpoint: T, retry?: number) => {
with: (params: Params[T]) => {
promise: Promise<AxiosResponse<any, any, {}>>;
/**
* Executes a callback with the response data and handles errors/retries
*
* @param callback - Function to process the API response
* @returns Promise resolving to the callback result or null on failure
*/
doing: <V>(callback: (res: AxiosResponse) => V | undefined) => Promise<V | null>;
};
};
export default request;