UNPKG

redis-time-series-ts

Version:
37 lines (36 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Filter = void 0; const filterOperator_1 = require("../enum/filterOperator"); /** * A `label`-`operator`-`value` object used for filtering queries */ class Filter { /** * The label and value in the constructor create a filter. * * @param label the label of the filter * @param operator the operator used for the filter i.e. FilterOperator.EQUAL or FilterOperator.NOT_EQUAL * @param value the value of the filter */ constructor(label, operator, value) { this.allowedOperator = [filterOperator_1.FilterOperator.EQUAL, filterOperator_1.FilterOperator.NOT_EQUAL]; this.label = label; this.operator = this.validateOperator(operator); this.value = value; } flatten() { let filterString = ""; if (this.value != null) { filterString = this.value instanceof Array ? `(${this.value.join(",")})` : this.value.toString(); } return [`${this.label}${this.operator}${filterString}`]; } validateOperator(operator) { if (!this.allowedOperator.includes(operator)) { throw new Error(`not allowed operator ${operator}`); } return operator; } } exports.Filter = Filter;