import { HttpRequestConfig } from './http'; import { RequestCache } from './cache'; /** * Resource API response wrapper */ export interface ResourceApiResponse { data: T; meta?: { total?: number; page?: number; pageSize?: number; [key: string]: unknown; }; } /** * Paginated response */ export interface PaginatedResponse { items: T[]; total: number; page: number; pageSize: number; hasMore: boolean; } /** * List query parameters */ export interface ListQueryParams { page?: number; pageSize?: number; sort?: string; order?: 'asc' | 'desc'; search?: string; filter?: Record; } /** * Resource client configuration * * **Note**: This is distinct from `ApiClientConfig` in `@/lib/api/types.ts` which * configures the core HTTP client. This interface configures domain-specific * resource clients with caching capabilities. */ export interface ResourceClientConfig { /** Base path for all endpoints */ basePath: string; /** Request cache instance */ cache?: RequestCache; /** Default cache TTL */ cacheTtl?: number; /** Enable caching by default */ enableCache?: boolean; } /** * Resource client interface returned by createResourceClient * * Provides CRUD operations for a specific resource type with built-in caching. * * **Note**: This is distinct from `ApiClient` class in `@/lib/api` which is the * core HTTP client. This interface represents a domain-specific resource client. */ export interface ResourceClient { getAll(params?: ListQueryParams, options?: { cache?: boolean; }): Promise>; getById(id: string | number, options?: { cache?: boolean; }): Promise; create(data: Omit): Promise; update(id: string | number, data: Partial): Promise; replace(id: string | number, data: Omit): Promise; delete(id: string | number): Promise; batchDelete(ids: (string | number)[]): Promise; customGet(path: string, params?: Record, options?: { cache?: boolean; }): Promise; customPost(path: string, body?: unknown, config?: Partial): Promise; invalidateCache(): void; } /** * @deprecated Use `createResourceClient` instead. The name `createApiClient` conflicts * with `@/lib/api/api-client.ts`. This alias will be removed in a future version. */ export declare const createApiClient: typeof createResourceClient; /** * Create a domain-specific resource client with CRUD operations and caching * * This factory creates clients for specific API resources (users, posts, etc.) * with built-in caching, pagination support, and standard CRUD methods. * * For the core HTTP client with interceptors, retry logic, and token refresh, * use `createApiClient` from `@/lib/api` instead. * * @param config - Resource client configuration * @returns Configured resource client with CRUD operations * * @example * ```typescript * const userClient = createResourceClient({ * basePath: '/api/users', * cacheTtl: 5 * 60 * 1000, // 5 minutes * enableCache: true, * }); * * // Fetch all users with pagination * const { items, total, hasMore } = await userClient.getAll({ page: 1, pageSize: 20 }); * * // Fetch single user * const user = await userClient.getById('123'); * * // Create new user * const newUser = await userClient.create({ name: 'John', email: 'john@example.com' }); * ``` */ export declare function createResourceClient(config: ResourceClientConfig): ResourceClient; /** * Pre-configured resource clients for common domains */ export declare const resourceClients: { users: ResourceClient<{ id: string; email: string; name: string; }>; reports: ResourceClient<{ id: string; title: string; type: string; }>; settings: ResourceClient<{ id: string; key: string; value: unknown; }>; }; /** * @deprecated Use `resourceClients` instead. This alias will be removed in a future version. */ export declare const apiClients: { users: ResourceClient<{ id: string; email: string; name: string; }>; reports: ResourceClient<{ id: string; title: string; type: string; }>; settings: ResourceClient<{ id: string; key: string; value: unknown; }>; }; /** * @deprecated Use `ResourceApiResponse` instead. */ export type ApiResponse = ResourceApiResponse; /** * @deprecated Use `ResourceClientConfig` instead. */ export type ApiClientConfig = ResourceClientConfig; /** * @deprecated Use `ResourceClient` instead. */ export type ApiClient = ResourceClient;