All files / src/Query QuerySegment.js

0% Statements 0/52
0% Branches 0/21
0% Functions 0/23
0% Lines 0/52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106                                                                                                                                                                                                                   
"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