import { ApprtRequestInit, ApprtRequestTarget, CustomFetch } from 'apprt-fetch'; import { IndexableThing, AsyncStore, Metadata, GetOptions, QueryOptions, AsyncQueryResult, ResultItems } from '../api/Store.js'; import { ComplexQueryExpression } from '../api/ComplexQueryLang.js'; import 'apprt-core/Events'; import '@arcgis/core/geometry/Geometry'; /** * Additional request options. */ interface RequestOptions { /** custom http headers */ headers?: Record; } /** * Extra options, provided in the hook method '_filterParams' */ interface MethodParameters { id?: IDType; query?: ComplexQueryExpression; object?: Partial; options: Record; } interface InternalRequestOptions extends ApprtRequestInit { url: ApprtRequestTarget; data?: string; query?: Record; content?: Record; headers?: Record; } /** * Base Store implementation for simple rest services. * Provides get and query methods. */ declare class BaseRestStore implements AsyncStore { /** The id of this store. */ id: string; /** * Additional headers to pass in all requests to the server. These can be overridden * by passing additional headers to calls to the store. */ headers: {}; /** * The target base URL to use for all requests to the server. This string will be * prepended to the id to generate the URL (relative or absolute) for requests * sent to the server */ target: string; /** *Indicates the property to use as the identity property. The values of this * property should be unique. */ idProperty: string; /** * The query parameter to used for holding sort information. If this is omitted, than * the sort information is included in a functional query token to avoid colliding * with the set of name/value pairs. */ sortParam: string; /** * The filter param transporting the query. */ filterParam: string; /** * Range parameter transporting item range definitions. */ rangeParam: string; /** * Identifies the item array in query responses */ itemProperty: string; /** * Identifies the total property in query responses */ totalProperty: string; /** * Defines the Accept header to use on HTTP requests */ accepts: string; /** * Configuration option for getMetadata method. */ metadata: Partial | undefined; /** * Flag which indicates that an switching to POST is allowed when GET requests are to long. * This is true by default for backwards compatibility. */ supportsPostSwitching: boolean; /** * Property for sub classes which provide static pre-configured metadata template. */ protected _metadata: Partial | undefined; private __metadataReq; private __fetch; /** * Create the store. * @param options allows overwrite of any property * @param fetch the fetch method to use. Provided to customize in the constructor to make tests easier. */ constructor(options?: Partial, keyof BaseRestStore>>, fetch?: CustomFetch); /** * Gets identity of given item. * @param item an item of this store. * @returns id or undefined if no id is found. */ getIdentity(item: Partial): IDType | undefined; /** * Gets metadata of the store. * @returns metadata. */ getMetadata(): Promise; /** * Retrieves an item from this store. * @param id the id. * @param options customization options. * @returns an item. */ get(id: IDType, options?: GetOptions & RequestOptions): Promise; /** * Queries the store for objects. */ query(query?: ComplexQueryExpression, options?: QueryOptions & RequestOptions): AsyncQueryResult; /** * Hook for sub classes to add/change request parameters. */ protected _filterParams(invokedFromMethod: string, requestParameters: InternalRequestOptions, originalMethodParameters: MethodParameters): InternalRequestOptions; /** * Hook for subclasses to convert ComplexQueryExpression into request parameters. * @param requestParameters prepared request parameters * @param query the complex query * @param options the query options */ protected _appendQueryToRequest(requestParameters: InternalRequestOptions, query: ComplexQueryExpression | undefined, options: QueryOptions): void; /** * Converts the options.start and options.count values to request parameters. * By default the headers "Range" and "X-Range" are calculated and * the request parameter 'range' is added. * A range is an string like '5..20' == `${start}-${start+count-1}`. * @param requestParameters request parameters will be changed * @param options the query options, with start + count. */ protected _appendRangeToRequest(requestParameters: InternalRequestOptions, options: QueryOptions): void; /** * Converts the options.sort to request parameters. * By default the sort options are converted into 'sort' request parameter, like '-id,+name,+title'. * @param requestParameters request parameters to change. * @param options the query options. */ protected _appendSortToRequest(requestParameters: InternalRequestOptions, options: QueryOptions): void; /** * Transforms server responses into `ResultItems`. * The default implementation expects a server response of this format: * * ```json * { * total : , * items: [...] * } * ``` * @param result json server response * @returns ResultItems. */ protected _processQueryResponse(result: Record): ResultItems; /** * Overwrite this method to change the filter behavior. */ protected _filterMetadata(metadata: Partial): Metadata; /** * Overwrite this method to provide your own metadata! * The method can return Promises! * Here you can implement http requests to dynamically resolve metadata. */ protected _getMetadata(): Partial | Promise>; /** * Helper method which checks the query options and delegates to fetch. * @param method http method to execute. * @param options the request options. * @returns result of the request. */ protected _executeRequest(method: string, options: InternalRequestOptions): Promise; private _fetchMetadata; } export { BaseRestStore }; export type { InternalRequestOptions, MethodParameters, RequestOptions };