@fjell/core
Version:
Core Item and Key Framework for Fjell
34 lines (33 loc) • 2.38 kB
TypeScript
import { CompoundCondition, Condition, Item, ItemQuery, QueryParams, Reference } from "@fjell/types";
/**
* When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat
* object that can be sent over a GET request.
*
* Note that there is some discussion about this. Evidently Elastic supports search with POST, but that also
* feels like a bit of a hack. It's not a RESTful way to do things. So we're sticking with GET for now.
*
* For reference, look at RFC 9110 "HTTP Semantics", June which clarified on top of and RFC 7231. It's possible
* but there are so many caveats and conditions in the standard, it's not worth it.
*
* Anticipating the next question - "isn't there a limit to the length of a URL?" The specification does not
* specify a limit, and there are limits in various browsers and servers - Apache is 4,000 chars, Chrome is 2M chars.
* Short answer is that if this query is being used to craft something that complex, it is probably a better idea
* to provide an action or a custom query endpoint on the server.
*
* @param query
* @returns QueryParams ready to be get over a GET request.
*/
export declare const queryToParams: (query: ItemQuery) => QueryParams;
/**
* This method translates from a flat QueryParams object with stringify'd JSON back to a full ItemQuery.
*
* @param params Parameters sent over a GET request
* @returns A fully hydrated ItemQuery object.
*/
export declare const paramsToQuery: (params: QueryParams) => ItemQuery;
export declare const isQueryMatch: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(item: Item<S, L1, L2, L3, L4, L5>, query: ItemQuery) => boolean;
export declare const abbrevQuery: (query: ItemQuery | null | undefined) => string;
export declare const abbrevRef: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(key: string, ref: Reference<S, L1, L2, L3, L4, L5>) => string;
export declare const abbrevAgg: (key: string, agg: ItemQuery) => string;
export declare const abbrevCompoundCondition: (compoundCondition: CompoundCondition) => string;
export declare const abbrevCondition: (condition: Condition | CompoundCondition) => string;