import type { CcRequestConfig, CcRequestConfigPartial, CcRequestParams } from '../types/request.types.js'; import type { UnknownToClient } from '../types/utils.types.js'; /** * Creates a new object with the specified properties omitted. * * @param obj - The source object to create a subset from * @param keys - The property keys to omit from the result * @returns A new object without the specified keys * * @example * const user = { name: 'John', age: 30, password: 'secret' }; * const safeUser = omit(user, 'password'); * // Result: { name: 'John', age: 30 } */ export declare function omit(obj: T, ...keys: Array): Omit; /** * Ensures a value is an array. If the input is already an array, returns it as-is; * otherwise, wraps the input in an array. * * @param value - The value to convert to an array * @returns An array containing the input value(s) * * @example * toArray(5) // [5] * toArray([1, 2]) // [1, 2] */ export declare function toArray(value: T | Array): Array; /** * Normalizes various date formats into an ISO string representation. * Handles Date objects, timestamps, and string dates including those with '[UTC]' suffix. * * @param date - The date to normalize * @returns The date in ISO string format, or undefined if input is null/undefined * @throws {Error} If the input cannot be parsed as a valid date * * @example * normalizeDate(new Date('2023-01-01')) // '2023-01-01T00:00:00.000Z' * normalizeDate('2023-01-01[UTC]') // '2023-01-01T00:00:00.000Z' * normalizeDate(1672531200000) // '2023-01-01T00:00:00.000Z' */ export declare function normalizeDate(date: Date | string | number | null | undefined): string | undefined; /** * Generates a cryptographically secure random UUID using the crypto module. * * @returns A Promise that resolves to a random UUID v4 * * @example * const id = await randomUUID(); * // Result: '123e4567-e89b-12d3-a456-426614174000' */ export declare function randomUUID(): Promise; /** * Creates a safe URL by automatically encoding interpolated values using `encodeURIComponent()`. * Uses template literal syntax for clean and safe URL construction. * String values are URL-encoded while other types are converted to strings. * * @param strings - The string literals from the template * @param values - The interpolated values to be encoded * @returns The safely constructed URL string * * @example * const name = 'John Doe'; * const id = 123; * const url = safeUrl`/users/${name}/profile/${id}`; * // Result: '/users/John%20Doe/profile/123' */ export declare function safeUrl(strings: TemplateStringsArray, ...values: Array): string; /** * Checks whether a URL is absolute (starts with `http://` or `https://`). * Absolute URLs are used as is by clients, instead of being appended to the client base URL. * * @param url - The URL to check * @returns Whether the URL is absolute */ export declare function isAbsoluteUrl(url: string): boolean; /** * Checks whether a URL sits under a base URL, on a path segment boundary. * This is used to decide whether credentials may be sent along with a request: a command targeting another * origin, or a sibling path outside the base URL, must not receive the client credentials. * * Both URLs are parsed before being compared, so dot segments are resolved and the scheme, the host and the * port are compared on their normalized form. The path comparison is segment aware, so `https://example.com/api` * contains `https://example.com/api/2` but not `https://example.com/api2`. * * A URL that cannot be parsed is considered outside of the base URL. * * @param baseUrl - The base URL delimiting the scope * @param url - The URL to check * @returns Whether the URL sits under the base URL */ export declare function isUrlWithinBaseUrl(baseUrl: string, url: string): boolean; /** * Encodes a string to base64 with proper UTF-8 handling. * Safely handles non-ASCII characters by first encoding to UTF-8 * before performing the base64 transformation. * * @param string - The string to encode * @returns The base64 encoded string * * @example * encodeToBase64('Hello 世界'); * // Result: 'SGVsbG8g5LiW55WM' */ export declare function encodeToBase64(string: string): string; /** * Sorts an array of objects by multiple keys with customizable sort order. * Supports both direct property access and custom getter functions. * * @param array - The array to sort * @param keys - Sort keys or objects with key and order * @return A new sorted array * * @example * // Sort by property keys * const users = [ * { name: 'John', age: 30 }, * { name: 'Alice', age: 30 } * ]; * sortBy(users, 'age', { key: 'name', order: 'desc' }); * // Result: [{ name: 'John', age: 30 }, { name: 'Alice', age: 30 }] * * // Sort using custom getter function * const items = [ * { date: '2023-01-01' }, * { date: '2024-01-01' } * ]; * sortBy(items, item => new Date(item.date)); * // Result: [{ date: '2023-01-01' }, { date: '2024-01-01' }] */ export declare function sortBy unknown)>(array: Array, ...keys: Array): Array; /** * Merges two objects while ignoring null properties from the second object. * Useful for partial updates where null values should not override existing values. * * @param object1 - The base object to merge into * @param object2 - The object with updates (can be null) * @returns A new merged object * * @example * const user = { name: 'John', age: 30 }; * const update = { name: null, age: 31 }; * merge(user, update); * // Result: { name: 'John', age: 31 } */ export declare function merge(object1: T, object2: Partial | undefined): T; /** * Creates a new object with all null or undefined properties removed. * * @param object - The source object to clean * @returns A new object without null/undefined properties * * @example * const obj = { a: 1, b: null, c: undefined, d: 0 }; * pickNonNull(obj); * // Result: { a: 1, d: 0 } */ export declare function pickNonNull(object: T): Partial; /** * Creates a new object with all undefined properties removed. Null properties are kept. * * @param object - The source object to clean * @returns A new object without undefined properties * * @example * const obj = { a: 1, b: null, c: undefined }; * pickDefined(obj); * // Result: { a: 1, b: null } */ export declare function pickDefined(object: T): Partial; /** * The value the discriminant takes on the variant a discriminated union publishes for a value the * client does not know. */ export declare const UNKNOWN_TO_CLIENT = "UNKNOWN_TO_CLIENT"; /** * Builds the variant a discriminated union publishes for a value the client does not know. * * A client is always older than the API it talks to. Rather than throwing, dropping the entry or * falling back to a concrete variant, a transform answers this from its `default` branch and hands * the raw payload to the caller. * * @template D - The key the union discriminates on * @param discriminant - The key the union discriminates on, `type` for most of them * @param payload - The payload as the API sent it * @returns The unknown variant, discriminated on the given key * * @example * unknownToClient('event', payload); * // Result: { event: 'UNKNOWN_TO_CLIENT', payload } */ export declare function unknownToClient(discriminant: D, payload: unknown): UnknownToClient; /** * Combines an external AbortSignal with an AbortController's signal. * * This utility function allows chaining abort signals so that when the external * signal is aborted, it automatically aborts the provided AbortController as well. * This is useful for creating hierarchical cancellation where a parent operation * can cancel child operations. * * The function safely handles cases where: * - The external signal is null/undefined (no-op) * - The signals are the same instance (no-op to prevent infinite loops) * - The external signal is already aborted (immediate abortion) * * @param abortController - The AbortController to abort when signal is aborted * @param signal - External signal to listen for abort events * * @example * const parentController = new AbortController(); * const childController = new AbortController(); * * // When parent is aborted, child will also be aborted * combineWithSignal(childController, parentController.signal); * * // Later, aborting parent will also abort child * parentController.abort(); // childController.signal.aborted === true */ export declare function combineWithSignal(abortController: AbortController, signal: AbortSignal): void; /** * Waits for a promise shared by several callers, until it settles or the signal of this caller aborts. * * Aborting only stops this caller from waiting. It rejects with the reason of its signal, as `fetch()` * does, and the promise goes on for the other callers. What becomes of the shared work once nobody * waits for it is up to `onAbort`. * * @param promise - The shared promise to wait for * @param signal - The signal of this caller, if any * @param onAbort - Called once this caller stopped waiting because its signal aborted, including when it * was aborted already * @returns A promise settling like `promise`, unless the signal aborts first * * @example * // every caller shares the fetch, and the last one to leave aborts it * callerCount++; * return waitUnlessAborted(sharedFetch, signal, () => { * if (--callerCount === 0) { * sharedAbortController.abort(); * } * }); */ export declare function waitUnlessAborted(promise: Promise, signal: AbortSignal | undefined, onAbort?: () => void): Promise; /** * Merges a request configuration over a complete one. * * An `undefined` option counts as an absent option, so it keeps the base value. Only `null` resets the * cache. A caller can thus pass `{ signal: controller?.signal }` without dropping the default signal. * * @param baseConfig - The complete configuration to merge into * @param config - The configuration that overrides it * @returns A new complete configuration */ export declare function mergeRequestConfig(baseConfig: CcRequestConfig, config: CcRequestConfigPartial | undefined): CcRequestConfig; /** * Merges a request configuration over another partial one. * * An `undefined` option counts as an absent option, as in {@link mergeRequestConfig}. The result holds * no `undefined` option. * * @param baseConfig - The partial configuration to merge into * @param config - The configuration that overrides it * @returns A new partial configuration */ export declare function mergeRequestConfigPartial(baseConfig: CcRequestConfigPartial | undefined, config: CcRequestConfigPartial | undefined): CcRequestConfigPartial; /** * A Promise wrapper that provides external resolve/reject capabilities. * * @template T The type of the value that the promise will resolve to */ export declare class Deferred { #private; constructor(); get promise(): Promise; get resolve(): (value: T) => void; get reject(): (error: unknown) => void; } export declare function calculateCacheKey(requestParams: Partial): string; //# sourceMappingURL=utils.d.ts.map