UNPKG

@ember-data/json-api

Version:

Provides a JSON:API document and resource cache implementation for EmberData

124 lines 4.06 kB
declare module '@ember-data/json-api/-private/builders/-utils' { /** * @module @ember-data/json-api/request */ import type { BuildURLConfig, UrlOptions } from '@ember-data/request-utils'; import type { QueryParamsSource } from '@warp-drive/core-types/params'; import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core-types/request'; export interface JSONAPIConfig extends BuildURLConfig { profiles?: { pagination?: string; [key: string]: string | undefined; }; extensions?: { atomic?: string; [key: string]: string | undefined; }; } export let CONFIG: JSONAPIConfig; export let ACCEPT_HEADER_VALUE: string; /** * Allows setting extensions and profiles to be used in the `Accept` header. * * Extensions and profiles are keyed by their namespace with the value being * their URI. * * Example: * * ```ts * setBuildURLConfig({ * extensions: { * atomic: 'https://jsonapi.org/ext/atomic' * }, * profiles: { * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination' * } * }); * ``` * * This also sets the global configuration for `buildBaseURL` * for host and namespace values for the application * in the `@ember-data/request-utils` package. * * These values may still be overridden by passing * them to buildBaseURL directly. * * This method may be called as many times as needed * * ```ts * type BuildURLConfig = { * host: string; * namespace: string' * } * ``` * * @method setBuildURLConfig * @static * @public * @for @ember-data/json-api/request * @param {BuildURLConfig} config * @return void */ export function setBuildURLConfig(config: JSONAPIConfig): void; export function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void; export function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions; interface RelatedObject { [key: string]: string | string[] | RelatedObject; } export type JsonApiQuery = { include?: string | string[] | RelatedObject; fields?: Record<string, string | string[]>; page?: { size?: number; after?: string; before?: string; }; }; /** * 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. * - If `included` is an object we build paths dynamically for you * Treats `fields` specially, building JSON:API partial fields params from an object * Treats `page` specially, building cursor-pagination profile page params from an object * * ```ts * const params = buildQueryParams({ * include: { * company: { * locations: 'address' * } * }, * fields: { * company: ['name', 'ticker'], * person: 'name' * }, * page: { * size: 10, * after: 'abc', * } * }); * * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10' * ``` * * 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` * * @method buildQueryParams * @static * @public * @for @ember-data/json-api/request * @param {URLSearchParams | object} params * @param {object} [options] * @return {string} A sorted query params string without the leading `?` */ export function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string; export {}; } //# sourceMappingURL=-utils.d.ts.map