UNPKG

ravendb

Version:
114 lines 3.67 kB
import { GenericRangeFacet } from "./GenericRangeFacet.js"; import { Facet } from "./Facet.js"; import { throwError } from "../../../Exceptions/index.js"; import { FacetAggregationField } from "./FacetAggregationField.js"; export class FacetBuilder { _range; _default; static _rqlKeywords = new Set([ "as", "select", "where", "load", "group", "order", "include", "update" ]); byRanges(range, ...ranges) { if (!range) { throwError("InvalidArgumentException", "Range cannot be null"); } if (!this._range) { this._range = new GenericRangeFacet(); } this._range.ranges.push(range); if (ranges) { this._range.ranges.push(...ranges); } return this; } byField(fieldName) { if (!this._default) { this._default = new Facet(); } if (FacetBuilder._rqlKeywords.has(fieldName)) { fieldName = `'${fieldName}'`; } this._default.fieldName = fieldName; return this; } allResults() { if (!this._default) { this._default = new Facet(); } this._default.fieldName = null; return this; } withOptions(options) { const facet = this.getFacet(); if (facet instanceof Facet) { facet.options = options; } return this; } withDisplayName(displayName) { this.getFacet().displayFieldName = displayName; return this; } sumOn(path, displayName) { const aggregationsMap = this.getFacet().aggregations; if (!aggregationsMap.has("Sum")) { aggregationsMap.set("Sum", new Set()); } const aggregations = aggregationsMap.get("Sum"); const aggregationField = new FacetAggregationField(); aggregationField.name = path; aggregationField.displayName = displayName; aggregations.add(aggregationField); return this; } minOn(path, displayName) { const aggregationsMap = this.getFacet().aggregations; if (!aggregationsMap.has("Min")) { aggregationsMap.set("Min", new Set()); } const aggregations = aggregationsMap.get("Min"); const aggregationField = new FacetAggregationField(); aggregationField.name = path; aggregationField.displayName = displayName; aggregations.add(aggregationField); return this; } maxOn(path, displayName) { const aggregationsMap = this.getFacet().aggregations; if (!aggregationsMap.has("Max")) { aggregationsMap.set("Max", new Set()); } const aggregations = aggregationsMap.get("Max"); const aggregationField = new FacetAggregationField(); aggregationField.name = path; aggregationField.displayName = displayName; aggregations.add(aggregationField); return this; } averageOn(path, displayName) { const aggregationsMap = this.getFacet().aggregations; if (!aggregationsMap.has("Average")) { aggregationsMap.set("Average", new Set()); } const aggregations = aggregationsMap.get("Average"); const aggregationField = new FacetAggregationField(); aggregationField.name = path; aggregationField.displayName = displayName; aggregations.add(aggregationField); return this; } getFacet() { if (this._default) { return this._default; } return this._range; } } //# sourceMappingURL=FacetBuilder.js.map