"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
class QuerySegment {
constructor(_queryRef) {
this._queryRef = _queryRef;
}
escapeValue(value) {
return typeof value === 'string' ? value.replace(/([\!\+\&\|\(\)\[\]\{\}\^\~\:\"])/g, '\\$1') : value;
}
Sort(field, reverse = false) {
this._stringValue = ` .${reverse ? 'REVERSESORT' : 'SORT'}:'${field}'`;
return this.finializeSegment();
}
Top(topCount) {
this._stringValue = ` .TOP:${topCount}`;
return this.finializeSegment();
}
Skip(skipCount) {
this._stringValue = ` .SKIP:${skipCount}`;
return this.finializeSegment();
}
toString() {
return this._stringValue;
}
finializeSegment() {
this._queryRef.AddSegment(this);
return new QuerySegment(this._queryRef);
}
}
exports.QuerySegment = QuerySegment;
class QueryExpression extends QuerySegment {
Term(term) {
this._stringValue = term;
return this.finialize();
}
InTree(path) {
const pathValue = this.escapeValue(path.Path ? path.Path : path.toString());
this._stringValue = `InTree:"${pathValue}"`;
return this.finialize();
}
InFolder(path) {
const pathValue = this.escapeValue(path.Path ? path.Path : path.toString());
this._stringValue = `InFolder:"${pathValue}"`;
return this.finialize();
}
Type(newTypeAssertion) {
this._stringValue = `Type:${newTypeAssertion.name}`;
return this.finialize();
}
TypeIs(newTypeAssertion) {
this._stringValue = `TypeIs:${newTypeAssertion.name}`;
return this.finialize();
}
Equals(fieldName, value) {
this._stringValue = `${fieldName}:'${this.escapeValue(value)}'`;
return this.finialize();
}
NotEquals(fieldName, value) {
this._stringValue = `NOT(${fieldName}:'${this.escapeValue(value)}')`;
return this.finialize();
}
Between(fieldName, minValue, maxValue, minimumInclusive = false, maximumInclusive = false) {
this._stringValue = `${fieldName}:${minimumInclusive ? '[' : '{'}'${this.escapeValue(minValue)}' TO '${this.escapeValue(maxValue)}'${maximumInclusive ? ']' : '}'}`;
return this.finialize();
}
GreatherThan(fieldName, minValue, minimumInclusive = false) {
this._stringValue = `${fieldName}:>${minimumInclusive ? '=' : ''}'${this.escapeValue(minValue)}'`;
return this.finialize();
}
LessThan(fieldName, maxValue, maximumInclusive = false) {
this._stringValue = `${fieldName}:<${maximumInclusive ? '=' : ''}'${this.escapeValue(maxValue)}'`;
return this.finialize();
}
Query(build) {
const innerQuery = new _1.Query(build);
this._stringValue = `(${innerQuery.toString()})`;
return this.finialize();
}
Not(build) {
const innerQuery = new _1.Query(build);
this._stringValue = `NOT(${innerQuery.toString()})`;
return this.finialize();
}
finialize() {
this._queryRef.AddSegment(this);
return new QueryOperators(this._queryRef);
}
}
exports.QueryExpression = QueryExpression;
class QueryOperators extends QuerySegment {
get And() {
this._stringValue = ' AND ';
return this.finialize();
}
get Or() {
this._stringValue = ' OR ';
return this.finialize();
}
finialize() {
this._queryRef.AddSegment(this);
return new QueryExpression(this._queryRef);
}
}
exports.QueryOperators = QueryOperators;
//# sourceMappingURL=QuerySegment.js.map |