-
Notifications
You must be signed in to change notification settings - Fork 8
/
NestedRestriction.ts
33 lines (27 loc) · 1018 Bytes
/
NestedRestriction.ts
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
import {Operators} from './Operator';
import {Clause} from './Clause';
import {Restriction} from './Restriction';
/**
* Nested query restrictions.
* @module NestedRestriction
*/
export class NestedRestriction {
/** The clauses containing the nested restrictions and their logical operators. */
public clauses = [] as Clause[];
constructor(...clauses: Clause[]) {
this.clauses = clauses;
}
/** Adds an additional restriction using the logical OR operator. */
public withOrRestriction(restriction: Restriction|NestedRestriction) {
return this.withClause(new Clause(restriction, Operators.OR));
}
/** Adds an additional restriction using the logical AND operator. */
public withAndRestriction(restriction: Restriction|NestedRestriction) {
return this.withClause(new Clause(restriction, Operators.AND));
}
/** Adds an additional clause. */
private withClause(clause: Clause) {
this.clauses.push(clause);
return this;
}
}