import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from "@warp-drive/core/types/params"; export interface BuildURLConfig { host: string | null; namespace: string | null; } /** * Sets the global configuration for `buildBaseURL` * for host and namespace values for the application. * * These values may still be overridden by passing * them to buildBaseURL directly. * * This method may be called as many times as needed. * host values of `''` or `'/'` are equivalent. * * Except for the value of `/` as host, host should not * end with `/`. * * namespace should not start or end with a `/`. * * ```ts * type BuildURLConfig = { * host: string; * namespace: string' * } * ``` * * Example: * * ```ts * import { setBuildURLConfig } from '@ember-data/request-utils'; * * setBuildURLConfig({ * host: 'https://api.example.com', * namespace: 'api/v1' * }); * ``` * * @public */ export declare function setBuildURLConfig(config: BuildURLConfig): void; export interface FindRecordUrlOptions { op: "findRecord"; identifier: { type: string; id: string; }; resourcePath?: string; host?: string; namespace?: string; } export interface QueryUrlOptions { op: "query"; identifier: { type: string; }; resourcePath?: string; host?: string; namespace?: string; } export interface FindManyUrlOptions { op: "findMany"; identifiers: { type: string; id: string; }[]; resourcePath?: string; host?: string; namespace?: string; } export interface FindRelatedCollectionUrlOptions { op: "findRelatedCollection"; identifier: { type: string; id: string; }; fieldPath: string; resourcePath?: string; host?: string; namespace?: string; } export interface FindRelatedResourceUrlOptions { op: "findRelatedRecord"; identifier: { type: string; id: string; }; fieldPath: string; resourcePath?: string; host?: string; namespace?: string; } export interface CreateRecordUrlOptions { op: "createRecord"; identifier: { type: string; }; resourcePath?: string; host?: string; namespace?: string; } export interface UpdateRecordUrlOptions { op: "updateRecord"; identifier: { type: string; id: string; }; resourcePath?: string; host?: string; namespace?: string; } export interface DeleteRecordUrlOptions { op: "deleteRecord"; identifier: { type: string; id: string; }; resourcePath?: string; host?: string; namespace?: string; } export interface GenericUrlOptions { resourcePath: string; host?: string; namespace?: string; } export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions; /** * Builds a URL for a request based on the provided options. * Does not include support for building query params (see `buildQueryParams`) * so that it may be composed cleanly with other query-params strategies. * * Usage: * * ```ts * import { buildBaseURL } from '@ember-data/request-utils'; * * const url = buildBaseURL({ * host: 'https://api.example.com', * namespace: 'api/v1', * resourcePath: 'emberDevelopers', * op: 'query', * identifier: { type: 'ember-developer' } * }); * * // => 'https://api.example.com/api/v1/emberDevelopers' * ``` * * On the surface this may seem like a lot of work to do something simple, but * it is designed to be composable with other utilities and interfaces that the * average product engineer will never need to see or use. * * A few notes: * * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used. * - `host` and `namespace` are optional, but if they are not provided, the values globally * configured via `setBuildURLConfig` will be used. * - `op` is required and must be one of the following: * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord' * - Depending on the value of `op`, `identifier` or `identifiers` will be required. * * @public */ export declare function buildBaseURL(urlOptions: UrlOptions): string; /** * filter out keys of an object that have falsy values or point to empty arrays * returning a new object with only those keys that have truthy values / non-empty arrays * * @public * @param source object to filter keys with empty values from * @return A new object with the keys that contained empty values removed */ export declare function filterEmpty(source: Record): Record; /** * Sorts query params by both key and value returning a new URLSearchParams * object with the keys inserted in sorted order. * * Treats `included` specially, splicing it into an array if it is a string and sorting the array. * * Options: * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma' * * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2` * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2` * 'repeat': appends the key for every value e.g. `&ids=1&ids=2` * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2` * * @public * @return A {@link URLSearchParams} with keys inserted in sorted order */ export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams; /** * Sorts query params by both key and value, returning a query params string * * Treats `included` specially, splicing it into an array if it is a string and sorting the array. * * Options: * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma' * * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2` * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2` * 'repeat': appends the key for every value e.g. `ids=1&ids=2` * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2` * * @public * @return A sorted query params string without the leading `?` */ export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;