@dra2020/baseclient 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/baseclient.js
CHANGED
|
@@ -597,6 +597,40 @@ function wordyDate(s) {
|
|
|
597
597
|
// But this is close enough to match what gets displayed by "prettyDate" while also letting selection by month year
|
|
598
598
|
return s;
|
|
599
599
|
}
|
|
600
|
+
function clauseEqual(c1, c2) {
|
|
601
|
+
if (c1 == null && c2 == null)
|
|
602
|
+
return true;
|
|
603
|
+
if (c1 == null || c2 == null)
|
|
604
|
+
return false;
|
|
605
|
+
if (c1.op.tt === c2.op.tt) {
|
|
606
|
+
if (c1.op.tt === TokType.Text)
|
|
607
|
+
return c1.op.text === c2.op.text;
|
|
608
|
+
else
|
|
609
|
+
return clauseEqual(c1.operand1, c2.operand1) && clauseEqual(c1.operand2, c2.operand2);
|
|
610
|
+
}
|
|
611
|
+
else
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
function containsClause(c, s) {
|
|
615
|
+
if (clauseEqual(c, s))
|
|
616
|
+
return true;
|
|
617
|
+
if (c == null || s == null)
|
|
618
|
+
return false;
|
|
619
|
+
return containsClause(c.operand1, s) || containsClause(c.operand2, s);
|
|
620
|
+
}
|
|
621
|
+
function removeClause(c, s) {
|
|
622
|
+
if (c == null || (c.op.tt === TokType.Text && c.op.tt !== s.op.tt))
|
|
623
|
+
return c;
|
|
624
|
+
else if (clauseEqual(c, s))
|
|
625
|
+
return null;
|
|
626
|
+
else {
|
|
627
|
+
c.operand1 = removeClause(c.operand1, s);
|
|
628
|
+
c.operand2 = removeClause(c.operand2, s);
|
|
629
|
+
if ((c.op.tt === TokType.And || c.op.tt === TokType.Or) && (c.operand1 == null || c.operand2 == null))
|
|
630
|
+
return c.operand1 || c.operand2;
|
|
631
|
+
return c;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
600
634
|
class FilterExpr {
|
|
601
635
|
constructor(coder, expr) {
|
|
602
636
|
this.lexer = new Lexer(coder);
|
|
@@ -614,13 +648,38 @@ class FilterExpr {
|
|
|
614
648
|
asString() {
|
|
615
649
|
return this.asStringClause(this.parser.clause);
|
|
616
650
|
}
|
|
651
|
+
containsClause(expr) {
|
|
652
|
+
let sub = new FilterExpr(this.lexer.coder, expr);
|
|
653
|
+
return containsClause(this.parser.clause, sub.parser.clause);
|
|
654
|
+
}
|
|
655
|
+
addClause(expr) {
|
|
656
|
+
let sub = new FilterExpr(this.lexer.coder, expr);
|
|
657
|
+
if (!containsClause(this.parser.clause, sub.parser.clause)) {
|
|
658
|
+
if (this.parser.clause)
|
|
659
|
+
this.parser.clauses = [{ op: { tt: TokType.And }, operand1: this.parser.clause, operand2: sub.parser.clause }];
|
|
660
|
+
else
|
|
661
|
+
this.parser.clauses = [sub.parser.clause];
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
removeClause(expr) {
|
|
665
|
+
if (this.containsClause(expr)) {
|
|
666
|
+
let sub = new FilterExpr(this.lexer.coder, expr);
|
|
667
|
+
this.parser.clauses = [removeClause(this.parser.clause, sub.parser.clause)];
|
|
668
|
+
}
|
|
669
|
+
}
|
|
617
670
|
asStringClause(clause) {
|
|
618
671
|
if (clause == null)
|
|
619
672
|
return '';
|
|
620
|
-
if (clause.op.tt == TokType.Text)
|
|
621
|
-
|
|
673
|
+
if (clause.op.tt == TokType.Text) {
|
|
674
|
+
this.lexer.set(clause.op.text);
|
|
675
|
+
if (this.lexer.tokens.length == 1 && this.lexer.tokens[0].tt === TokType.Text)
|
|
676
|
+
return clause.op.text;
|
|
677
|
+
else
|
|
678
|
+
return `'${clause.op.text}'`;
|
|
679
|
+
}
|
|
622
680
|
let a = [];
|
|
623
|
-
|
|
681
|
+
if (clause !== this.parser.clause)
|
|
682
|
+
a.push('(');
|
|
624
683
|
switch (clause.op.tt) {
|
|
625
684
|
case TokType.And:
|
|
626
685
|
a.push(this.asStringClause(clause.operand1));
|
|
@@ -637,8 +696,7 @@ class FilterExpr {
|
|
|
637
696
|
a.push(this.asStringClause(clause.operand1));
|
|
638
697
|
break;
|
|
639
698
|
case TokType.Colon:
|
|
640
|
-
a.push(this.asStringClause(clause.operand1));
|
|
641
|
-
a.push(':');
|
|
699
|
+
a.push(`${this.asStringClause(clause.operand1)}:`);
|
|
642
700
|
a.push(this.asStringClause(clause.operand2));
|
|
643
701
|
break;
|
|
644
702
|
case TokType.Equal:
|
|
@@ -653,7 +711,8 @@ class FilterExpr {
|
|
|
653
711
|
default:
|
|
654
712
|
throw 'Unexpected token in asString';
|
|
655
713
|
}
|
|
656
|
-
|
|
714
|
+
if (clause !== this.parser.clause)
|
|
715
|
+
a.push(')');
|
|
657
716
|
return a.join(' ');
|
|
658
717
|
}
|
|
659
718
|
testClause(o, types, clause, prop, relation) {
|