@fleek-platform/agents-ui
Version:
The Fleek Platform Agents UI provides a simple interface for deploying, monitoring, and configuring your agents––making management straightforward
93 lines (92 loc) • 4.85 kB
TypeScript
import { type StringifiableRecord } from 'query-string';
/**
* Joins multiple path segments into a single clean URL path, ensuring proper formatting without duplicate slashes.
*
* @param {...string} paths - The path segments to join.
* @returns {string} The joined path.
*
* @example
* joinPaths("/api", "users", "42"); // "/api/users/42"
* joinPaths("https://example.com/", "/users", "/profile"); // "https://example.com/users/profile"
*/
export declare const joinPaths: (...paths: string[]) => string;
/**
* Replaces `:param` placeholders in a URL path with provided values.
*
* @param {string} path - The path template containing `:param` placeholders.
* @param {Record<string, string | string[]>} [params={}] - An object mapping parameter names to values.
* @returns {string} The formatted path with placeholders replaced.
*
* @example
* templatePath("/users/:id", { id: "42" }); // "/users/42"
* templatePath("/projects/:projectId/tasks/:taskId", { projectId: "123", taskId: "456" }); // "/projects/123/tasks/456"
* templatePath("/search/:query", { query: "John Doe" }); // "/search/John%20Doe"
*/
export declare const templatePath: (path: string, params?: Record<string, string | string[]>) => string;
/**
* Constructs a properly encoded query string from an object of key-value pairs.
*
* @param {string} url - The base URL to which the query parameters will be appended.
* @param {StringifiableRecord} [query={}] - An object representing query parameters.
* @returns {string} The full URL with the encoded query string, or the original URL if no parameters exist.
*
* @example
* buildQueryString("https://api.example.com/users", { search: "John Doe", page: 2 });
* // "https://api.example.com/users?search=John%20Doe&page=2"
*
* buildQueryString("https://example.com", { active: true, sort: "asc" });
* // "https://example.com?active=true&sort=asc"
*
* buildQueryString("https://example.com", {});
* // "https://example.com"
*/
export declare const buildQueryString: (url: string, query?: StringifiableRecord) => string;
/**
* Constructs a complete URL by joining the base URL, replacing path parameters (if provided), and appending query parameters (if provided).
*
* @param {string} baseUrl - The base URL (e.g., "https://api.example.com").
* @param {string} path - The path template containing `:param` placeholders.
* @param {Object} [options] - Optional parameters.
* @param {Record<string, string | string[]>} [options.pathParams] - Path parameters to replace in the URL.
* @param {StringifiableRecord} [options.queryParams] - Query parameters to append.
* @returns {string} The fully constructed URL with replaced path parameters and encoded query parameters.
*
* @example
* buildUrl("https://api.example.com", "/users/:id", { pathParams: { id: "42" }, queryParams: { active: true } });
* // "https://api.example.com/users/42?active=true"
*
* buildUrl("https://example.com", "/search", { queryParams: { query: "New York", page: 1 } });
* // "https://example.com/search?query=New%20York&page=1"
*
* buildUrl("https://example.com", "/static/path");
* // "https://example.com/static/path"
*/
export declare const buildUrl: (baseUrl: string, path: string, options?: {
pathParams?: Record<string, string | string[]>;
queryParams?: StringifiableRecord;
}) => string;
/**
* Creates a specialized `buildUrl` function with a default base URL.
* Supports both a static string or a function that returns a base URL dynamically.
*
* @param {string | (() => string)} baseUrl - The base URL to use for all requests.
* Can be a static string or a function returning a string (useful for runtime evaluation).
* @returns {(path: string, options?: { pathParams?: Record<string, string | string[]>; queryParams?: StringifiableRecord }) => string}
* A new `buildUrl` function that automatically applies the default base URL.
*
* @example
* // Static base URL usage
* const apiBuildUrl = createUrlBuilder("https://api.example.com");
* console.log(apiBuildUrl("/users/:id", { pathParams: { id: "42" }, queryParams: { active: true } }));
* // Output: "https://api.example.com/users/42?active=true"
*
* @example
* // Dynamic base URL usage (useful for environments that change)
* const dynamicApiBuildUrl = createUrlBuilder(() => process.env.API_BASE_URL || "https://fallback.example.com");
* console.log(dynamicApiBuildUrl("/products/:id", { pathParams: { id: "123" }, queryParams: { inStock: true } }));
* // Output (if API_BASE_URL="https://dynamic.example.com"): "https://dynamic.example.com/products/123?inStock=true"
*/
export declare const createUrlBuilder: (baseUrl: string | (() => string)) => (path: string, { pathParams, queryParams, }?: {
pathParams?: Record<string, string | string[]>;
queryParams?: StringifiableRecord;
}) => string;