UNPKG

ravendb

Version:
86 lines 2.92 kB
import { throwError } from "../../../Exceptions/index.js"; export class RangeBuilder { _path; _lessBound; _greaterBound; _lessInclusive; _greaterInclusive; _lessSet = false; _greaterSet = false; constructor(path) { this._path = path; } static forPath(path) { return new RangeBuilder(path); } _createClone() { const builder = new RangeBuilder(this._path); builder._lessBound = this._lessBound; builder._greaterBound = this._greaterBound; builder._lessInclusive = this._lessInclusive; builder._greaterInclusive = this._greaterInclusive; builder._lessSet = this._lessSet; builder._greaterSet = this._greaterSet; return builder; } isLessThan(value) { if (this._lessSet) { throwError("InvalidOperationException", "Less bound was already set"); } const clone = this._createClone(); clone._lessBound = value; clone._lessInclusive = false; clone._lessSet = true; return clone; } isLessThanOrEqualTo(value) { if (this._lessSet) { throwError("InvalidOperationException", "Less bound was already set"); } const clone = this._createClone(); clone._lessBound = value; clone._lessInclusive = true; clone._lessSet = true; return clone; } isGreaterThan(value) { if (this._greaterSet) { throwError("InvalidOperationException", "Greater bound was already set"); } const clone = this._createClone(); clone._greaterBound = value; clone._greaterInclusive = false; clone._greaterSet = true; return clone; } isGreaterThanOrEqualTo(value) { if (this._greaterSet) { throwError("InvalidOperationException", "Greater bound was already set"); } const clone = this._createClone(); clone._greaterBound = value; clone._greaterInclusive = true; clone._greaterSet = true; return clone; } getStringRepresentation(addQueryParameter) { let less = null; let greater = null; if (!this._lessSet && !this._greaterSet) { throwError("InvalidOperationException", "Bounds were not set"); } if (this._lessSet) { const lessParamName = addQueryParameter(this._lessBound); less = this._path + (this._lessInclusive ? " <= " : " < ") + "$" + lessParamName; } if (this._greaterSet) { const greaterParamName = addQueryParameter(this._greaterBound); greater = this._path + (this._greaterInclusive ? " >= " : " > ") + "$" + greaterParamName; } if (less && greater) { return greater + " and " + less; } return less || greater; } } //# sourceMappingURL=RangeBuilder.js.map