@configurator/ravendb
Version:
RavenDB client for Node.js
113 lines • 3.81 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FacetBuilder = void 0;
const GenericRangeFacet_1 = require("./GenericRangeFacet");
const Facet_1 = require("./Facet");
const Exceptions_1 = require("../../../Exceptions");
const FacetAggregationField_1 = require("./FacetAggregationField");
class FacetBuilder {
byRanges(range, ...ranges) {
if (!range) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Range cannot be null");
}
if (!this._range) {
this._range = new GenericRangeFacet_1.GenericRangeFacet();
}
this._range.ranges.push(range);
if (ranges) {
this._range.ranges.push(...ranges);
}
return this;
}
byField(fieldName) {
if (!this._default) {
this._default = new Facet_1.Facet();
}
if (FacetBuilder._rqlKeywords.has(fieldName)) {
fieldName = `'${fieldName}'`;
}
this._default.fieldName = fieldName;
return this;
}
allResults() {
if (!this._default) {
this._default = new Facet_1.Facet();
}
this._default.fieldName = null;
return this;
}
withOptions(options) {
this.getFacet().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_1.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_1.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_1.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_1.FacetAggregationField();
aggregationField.name = path;
aggregationField.displayName = displayName;
aggregations.add(aggregationField);
return this;
}
getFacet() {
if (this._default) {
return this._default;
}
return this._range;
}
}
exports.FacetBuilder = FacetBuilder;
FacetBuilder._rqlKeywords = new Set([
"as",
"select",
"where",
"load",
"group",
"order",
"include",
"update"
]);
//# sourceMappingURL=FacetBuilder.js.map