Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
module.exports = {
};
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module"
}
}
135 changes: 135 additions & 0 deletions lib/elasticsearch/body.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import SearchQuery from '../types/SearchQuery';
import AppliedFilter from '../types/AppliedFilter';
import ElasticsearchQueryConfig from './types/ElasticsearchQueryConfig';
/**
* These are option parameters passed to filters methods like `check` and `filter`
*
* @param {string} operator String representation of the first operator of the filter like `in` and `nor`
* @param {string} attribute Name of the filters attribute
* @param {any} value Set of values to filter in the filters `filter` method
* @param {string} queryChain Representation of the current `bodybuilder` query-chain
*/
export interface FilterOptions {
operator: string;
attribute: string;
value: any;
queryChain?: any;
}
/**
* Option parameters of a single filter
*
* @param {Function} check Method to verfiy if the current `SearchQuery` filter matches this filter
* @param {Function} filter Method to mutate the `bodybuilder` query-chain
* @param {Function} mutator Method to mutate value before it is applied to `filter` method to make it easier to handle it in filter-method
* @param {number} priority Define priority of filters – Filters follow a lower to higher sort, means: lower items are called first
*/
export interface FilterInterface {
check({ operator, value, attribute, queryChain }: FilterOptions): boolean;
filter({ operator, value, attribute, queryChain }: FilterOptions): Object;
mutator?(value: any): any;
priority?: number;
}
/**
* Set of filters to create a request body using `bodybuilder`
*/
export interface FiltersInterface {
[key: string]: FilterInterface;
}
/**
* Class to create elasticsearch request body in modular and reproductive way
*/
export default class RequestBody {
/**
* @var {string[]} rangeOperators Possible range operators
*/
protected rangeOperators: string[];
/**
* @var {string[]} orRangeOperators Possible range operators with or clause prefix
*/
protected orRangeOperators: string[];
/**
* @param {Object} value Get first option of filter values
*/
protected extractFirstValueMutator: (value: any) => any[];
/**
* @var {FiltersInterface} baseFilters Operators for the default filters like: range, or, nor, in, nin
*/
protected baseFilters: FiltersInterface;
protected customFilters: FiltersInterface;
/**
* Bodybuilder object
* – passed in from the outside so we don't need to include in this lib
*/
protected queryChain: any;
/**
* This is an empty clone of the original, empty bodybuilder query chain to use it as plain bodybuilder instance
*/
protected emptyQueryChain: any;
protected config: ElasticsearchQueryConfig;
protected searchQuery: SearchQuery;
/**
* Create a copy of `SearchQuery.getAppliedFilters()` to make them mutable in custom- and base-filters
*/
protected appliedFilters: AppliedFilter[];
protected optionsPrefix: string;
protected _hasCatalogFilters: boolean;
constructor({ config, queryChain, searchQuery, customFilters }: {
config: ElasticsearchQueryConfig;
queryChain: any;
searchQuery: SearchQuery;
customFilters?: FiltersInterface;
});
/**
* @return {this}
*/
buildQueryBodyFromSearchQuery(): this;
/**
* Apply all `default` scoped filters to `queryChain`
* @return {this}
*/
protected applyBaseFilters(): this;
/**
* Apply all `catalog` scoped filters to `queryChain`
* @return {this}
*/
protected applyCatalogFilters(): this;
protected hasCatalogFilters(): boolean;
protected catalogFilterBuilder: (filterQr: any, filter: AppliedFilter, attrPostfix?: string, type?: "query" | "filter") => any;
/**
* Apply filter aggregations
* @return {this}
*/
protected applyAggregations(): this;
/**
* Apply query string
* @return {this}
*/
applyTextQuery(): this;
/**
* @return {this}
*/
protected applySort(): this;
/**
* Combine and sort filters by priority
*/
protected getSortedFilters(): FilterInterface[];
protected checkIfObjectHasScope({ object, scope }: {
object: {
scope: string;
};
scope: string;
}): boolean;
protected getMapping(attribute: string, entityType?: string): string;
protected getQueryBody(body: any): any;
protected getSearchText(): string;
/**
* Get an empty representation of the bodybuilder query-chain without need to import bodybuilder itself
* @return {any}
*/
protected bodybuilder: () => any;
getQueryChain(): any;
/**
* @returns Bodybuilder object
*/
build(): Record<string, any>;
}
Loading