@configurator/ravendb
Version:
RavenDB client for Node.js
85 lines • 3.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RangeBuilder = void 0;
const Exceptions_1 = require("../../../Exceptions");
class RangeBuilder {
constructor(path) {
this._lessSet = false;
this._greaterSet = false;
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) {
(0, Exceptions_1.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) {
(0, Exceptions_1.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) {
(0, Exceptions_1.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) {
(0, Exceptions_1.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) {
(0, Exceptions_1.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;
}
}
exports.RangeBuilder = RangeBuilder;
//# sourceMappingURL=RangeBuilder.js.map