import type { AxiosInstance } from "axios"; import type { PartialDeep } from "type-fest"; import type { Concierge } from "../utils/concierge"; import type { Limit, Offset } from "./pagination"; export interface PaginationConfig { /** * The number of items per page, i.e. "limit". * * @default 10 */ itemsPerPage: Limit; /** * The "limit" parameter's name in the request. * * @default "limit" */ limitParam: string; /** * The "offset" parameter's name in the request. * * @default "offset" */ offsetParam: string; /** * The intial "offset" parameter's value, i.e. the first/default page's * offset. * * @default 0 */ initialOffsetValue: Offset; /** * Whether to transmit the "offset" parameter when the value is `0`. * * In general, the server that receives the request should read the absence * of the "offset" parameter from the request as a way to request the first * page, but some servers expect an explicit value even for such case. * * @default false */ sendZeroOffset: boolean; } /** User-facing concierge options. */ export interface ConciergeConfig { /** Default settings for pagination hooks. */ pagination: PaginationConfig; } interface ConciergeOptions { /** The preferred consumer instance. When set, this can be either: * - A specific Axios instance * - A concierge instance */ instance: Options["instance"]; /** * Whether the hook should use an untouched Axios instance. * * This flag represents a shorter, alternative way of providing an ad-hoc * Axios instance to the hook, without any customization. */ external: Options["external"] extends true ? true : never; /** The ad-hoc concierge options. */ options: Options["withConfig"] extends true ? PartialDeep : never; } /** * Represents the available approaches to override the concierge at the single * hook level: * - `external`: use a new, untouched Axios instance * - `instance`: explicitly pass a custom Axios instance * - Ability to provide concierge options either way */ export type OverrideableConciergeConfig = ConciergeOptions<{ instance: never; external: true; withConfig: true; }> | ConciergeOptions<{ instance: AxiosInstance; external: false; withConfig: true; }> | ConciergeOptions<{ instance: Concierge; external: false; withConfig: false; }>; export interface FlexibleConciergeConfig { /** * Consumer configuration. * * Allows to adopt two startegies: * * - The "external" consumer: the hook will use an untouched Axios instance * - The "instance" consumer: the hook will use the provided instance, either * an Axios or concierge one * * When a consumer that is not a concierge is passed as instance, or the * "external" approach is preferred, the configuration also accepts custom * concierge options. */ concierge?: Partial; } export {};