@yoyo-org/progressive-json
Version:
Stream and render JSON data as it arrives - perfect for AI responses, large datasets, and real-time updates
46 lines (45 loc) • 1.69 kB
TypeScript
import { HttpAdapter, HttpAdapterOptions, ExtendedHttpAdapter, HttpAdapterResponse } from './http-adapter';
interface AxiosInstance {
request<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
}
interface AxiosRequestConfig {
method?: string;
url?: string;
baseURL?: string;
headers?: Record<string, string>;
data?: any;
timeout?: number;
responseType?: 'stream' | 'json' | 'text' | 'blob' | 'arraybuffer';
signal?: AbortSignal;
[key: string]: any;
}
interface AxiosResponse<T = any> {
data: T;
status: number;
statusText: string;
headers: Record<string, string>;
config: AxiosRequestConfig;
}
/**
* HTTP adapter for Axios instances
* Allows using pre-configured Axios instances with Progressive JSON
*/
export declare class AxiosAdapter implements HttpAdapter, ExtendedHttpAdapter {
private axiosInstance;
constructor(axiosInstance: AxiosInstance);
stream(url: string, options?: HttpAdapterOptions): Promise<ReadableStream<Uint8Array>>;
request(url: string, options?: HttpAdapterOptions): Promise<HttpAdapterResponse>;
/**
* Convert Node.js readable stream or browser stream to Web ReadableStream<Uint8Array>
*/
private convertToWebStream;
}
/**
* Factory function to create an Axios adapter
* @param axiosInstance - Your pre-configured Axios instance
* @returns AxiosAdapter instance
*/
export declare function createAxiosAdapter(axiosInstance: AxiosInstance): AxiosAdapter;
export {};