import type { ApiConfigValue, ApisConfig, ConfigFacade, ConfigValues, FetchOptions, FetchResult, UrlOptions } from "../../types/index.js"; /** * FetchApiManager - Singleton para el registro de APIs y peticiones HTTP. * * Aplica el patrón Singleton: una única instancia mantiene el registro de APIs * (`ApisConfig`) y centraliza la construcción de URLs y las peticiones fetch, * devolviendo siempre Safe Results (nunca lanza en rutas async). * * @example * ```ts * const fetchApi = FetchApiManager.getInstance(); * fetchApi.useInit({ pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { byId: "/pokemon/:id/" } } }); * const result = await fetchApi.useFetch("pokeapi", "byId", { params: { id: 25 } }); * ``` */ export declare class FetchApiManager { private static instance; /** Module-level API registry. */ private apis; /** * Constructor privado - enforce singleton. */ private constructor(); /** * Obtiene la instancia única del FetchApiManager (Singleton). * * @returns La instancia única de {@link FetchApiManager}. */ static getInstance(): FetchApiManager; /** * Internal: retrieves a registered API entry or throws. * * @param apiName - The key of the API in the registry. * @returns The {@link ApiEntry} for the given name. * @throws {Error} If the API is not registered. */ private useGetApiEntry; /** * Registers (merges) API definitions into the client registry. * * @param apisConfig - The API definitions to merge into the registry. * * @example * ```ts * FetchApiManager.getInstance().useInit({ * pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { pokemonById: "/pokemon/:id/" } }, * }); * ``` */ useInit(apisConfig: ApisConfig): void; /** * Returns a shallow copy of the registered APIs (safe to mutate locally). * * @returns A shallow copy of the current API registry. */ useGetApis(): ApisConfig; /** * Returns the URL of a registered endpoint **without calling `fetch`**. * * It builds the same URL {@link useFetch} would request - same registry, * same `:param` substitution, same `query` merge with `defaultQueryParams`, * same http(s) guard - then stops and hands you the string. * * @param apiName - Registered API key (from `defineApiConfig`). * @param endpointName - Endpoint key inside that API. * @param options - `params` fills `:placeholders`, `query` becomes the search string. * @returns The fully built URL. * @throws {Error} Unknown API, unknown endpoint, or a scheme that is not http(s). * * @example * ```ts * FetchApiManager.getInstance().useBuildUrl("pokeapi", "pokemonById", { params: { id: 25 } }); * // → "https://pokeapi.co/api/v2/pokemon/25" * ``` * * @remarks Synchronous, so it **throws** instead of returning a Safe Result - * Safe Result covers fallible async work, and this never leaves the process. */ useBuildUrl(apiName: string, endpointName: string, options?: UrlOptions): string; /** * Fetches a registered endpoint and returns a Safe Result. * * URL options sit at the top level, next to `method`/`headers`/`body` - no * nesting, same shape as `useGet` and Nuxt's `useFetch`. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param options - Fetch options: `params`, `query`, `transform` and any `RequestInit` field. * @returns A `FetchResult` with data or error. Never throws - a failing * `transform` comes back as an error result too. * * @example * ```ts * const result = await FetchApiManager.getInstance().useFetch<{ results: unknown[] }>( * "pokeapi", * "pokemons", * { method: "GET", query: { limit: 2 } }, * ); * if (result.ok) console.log(result.data.results); * ``` */ useFetch(apiName: string, endpointName: string, { params, query, ignoreDefaultQuery, urlOptions, transform, ...init }?: FetchOptions): Promise>; /** * GET helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ useGet(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise>; /** * POST helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ usePost(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * PUT helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ usePut(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * PATCH helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ usePatch(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * DELETE helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ useDelete(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise>; } /** * Declares the API registry in a single call - the config-file entry point. * * Registers every {@link ApiEntry} you list and returns them alongside the * props, flags and methods declared on the same literal, so one `export default` * is the whole setup: no second `useInitApis(...)` step. * * Only object entries shaped like `{ baseUri, endpoints }` reach the registry; * boolean flags are kept on `config` for your own methods to read. * * @typeParam T - The literal passed in. * @param input - API entries, flags and methods in one object literal. * @returns The registered config plus the declared methods (see `ConfigFacade`). * @throws {Error} If a non-method value is an object that is not an API entry. * * @example * ```ts * import { defineApiConfig } from "katanakit-js"; * * export default defineApiConfig({ * pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { byId: "/pokemon/:id/" } }, * debug: true, * getPokemon: async function () { * return useFetch("pokeapi", "byId", { params: { id: 25 } }); * }, * }); * ``` * * @remarks Methods must be written with `function`, not as arrows - `this.config` * is undefined inside an arrow function. */ export declare function defineApiConfig(input: T & ThisType> & ConfigValues, ApiConfigValue>): ConfigFacade; /** * Registers (merges) API definitions into the client registry. * * @deprecated Use {@link defineApiConfig}, which registers the config and * returns it with any methods declared on the same literal. * * @param apisConfig - The API definitions to merge into the registry. * * @example * ```ts * import { useInit } from "katanakit-js"; * * useInit({ pokeapi: { baseUri: "https://pokeapi.co/api/v2", endpoints: { pokemonById: "/pokemon/:id/" } } }); * ``` */ export declare function useInit(apisConfig: ApisConfig): void; /** * Registers (merges) API definitions into the client registry. * * @deprecated Use {@link defineApiConfig}. * * @param apisConfig - The API definitions to merge into the registry. */ export declare function useInitApis(apisConfig: ApisConfig): void; /** * Returns a shallow copy of the registered APIs (safe to mutate locally). * * @returns A shallow copy of the current API registry. * * @example * ```ts * import { useGetApis } from "katanakit-js"; * * const apis = useGetApis(); * ``` */ export declare function useGetApis(): ApisConfig; /** * Returns a shallow copy of the registered APIs. Alias for {@link useGetApis}. * * @returns A shallow copy of the current API registry. */ export declare function useGetApisConfig(): ApisConfig; /** * Returns the URL of a registered endpoint **without calling `fetch`**. * * @param apiName - Registered API key (from `defineApiConfig`). * @param endpointName - Endpoint key inside that API. * @param options - `params` fills `:placeholders`, `query` becomes the search string. * @returns The fully built URL. * @throws {Error} Unknown API, unknown endpoint, or a scheme that is not http(s). * * @example * ```ts * import { useBuildUrl } from "katanakit-js"; * * useBuildUrl("pokeapi", "pokemonById", { params: { id: 25 } }); * // → "https://pokeapi.co/api/v2/pokemon/25" * ``` */ export declare function useBuildUrl(apiName: string, endpointName: string, options?: UrlOptions): string; /** * Builds a safe http(s) URL from a registered API + endpoint. * * @deprecated Use {@link useBuildUrl}. Behaviourally identical wrapper kept * for backwards compatibility - scheduled for removal in the next major. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param options - Optional URL building options. * @returns The fully constructed URL string. */ export declare function useBuildApiUrl(apiName: string, endpointName: string, options?: UrlOptions): string; /** * Fetches a registered endpoint and returns a Safe Result. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param options - Fetch options: `params`, `query`, `transform` and any `RequestInit` field. * @returns A `FetchResult` with data or error. Never throws. * * @example * ```ts * import { useFetch } from "katanakit-js"; * * const result = await useFetch("pokeapi", "pokemonById", { params: { id: 25 } }); * if (result.ok) console.log(result.data); * ``` */ export declare function useFetch(apiName: string, endpointName: string, options?: FetchOptions): Promise>; /** * Fetches a registered endpoint and returns a Safe Result. * Alias for {@link useFetch}. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param options - Optional fetch options. * @returns A `FetchResult` with data or error. */ export declare function useFetchApi(apiName: string, endpointName: string, options?: FetchOptions): Promise>; /** * GET helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. * * @example * ```ts * import { useGet } from "katanakit-js"; * * const result = await useGet("pokeapi", "pokemonById", { params: { id: 25 } }); * ``` */ export declare function useGet(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise>; /** * GET helper over a registered API endpoint. Alias for {@link useGet}. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ export declare function useGetApi(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise>; /** * POST helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. * * @example * ```ts * import { usePost } from "katanakit-js"; * * const result = await usePost("pokeapi", "createPokemon", { name: "Pikachu" }); * ``` */ export declare function usePost(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * PUT helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ export declare function usePut(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * PATCH helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param body - Optional request body (auto-serialized to JSON unless raw). * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ export declare function usePatch(apiName: string, endpointName: string, body?: unknown, urlOptions?: UrlOptions): Promise>; /** * DELETE helper over a registered API endpoint. * * @param apiName - The registered API key. * @param endpointName - The endpoint key within the API. * @param urlOptions - Optional URL building options. * @returns A `FetchResult` with data or error. */ export declare function useDelete(apiName: string, endpointName: string, urlOptions?: UrlOptions): Promise>; //# sourceMappingURL=http.service.d.ts.map