@dra2020/baseclient 1.0.7 → 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.
@@ -58,6 +58,9 @@ export declare class FilterExpr {
58
58
  set(expr: string): void;
59
59
  test(o: any, types?: any): boolean;
60
60
  asString(): string;
61
+ containsClause(expr: string): boolean;
62
+ addClause(expr: string): void;
63
+ removeClause(expr: string): void;
61
64
  asStringClause(clause: Clause): string;
62
65
  testClause(o: any, types: any, clause: Clause, prop?: string, relation?: TokType): boolean;
63
66
  }
package/dist/fsm/fsm.d.ts CHANGED
@@ -63,6 +63,7 @@ export declare class FsmOnDone extends Fsm {
63
63
  }
64
64
  export declare class FsmSleep extends Fsm {
65
65
  delay: number;
66
+ timeoutHandle: any;
66
67
  constructor(env: FsmEnvironment, delay: number);
67
68
  tick(): void;
68
69
  }
@@ -83,6 +83,8 @@ export interface SessionProps {
83
83
  loadFailed: boolean;
84
84
  accessMap: AccessMap;
85
85
  revisions: RevisionList;
86
+ expunged?: boolean;
87
+ expungeDate?: string;
86
88
  xprops?: {
87
89
  [prop: string]: string;
88
90
  };
@@ -484,6 +484,45 @@ function wordyDate(s: string): string
484
484
  return s;
485
485
  }
486
486
 
487
+ function clauseEqual(c1: Clause, c2: Clause): boolean
488
+ {
489
+ if (c1 == null && c2 == null) return true;
490
+ if (c1 == null || c2 == null) return false;
491
+ if (c1.op.tt === c2.op.tt)
492
+ {
493
+ if (c1.op.tt === TokType.Text)
494
+ return c1.op.text === c2.op.text;
495
+ else
496
+ return clauseEqual(c1.operand1, c2.operand1) && clauseEqual(c1.operand2, c2.operand2);
497
+ }
498
+ else
499
+ return false;
500
+ }
501
+
502
+ function containsClause(c: Clause, s: Clause): boolean
503
+ {
504
+ if (clauseEqual(c, s))
505
+ return true;
506
+ if (c == null || s == null) return false;
507
+ return containsClause(c.operand1, s) || containsClause(c.operand2, s);
508
+ }
509
+
510
+ function removeClause(c: Clause, s: Clause): Clause
511
+ {
512
+ if (c == null || (c.op.tt === TokType.Text && c.op.tt !== s.op.tt))
513
+ return c;
514
+ else if (clauseEqual(c, s))
515
+ return null;
516
+ else
517
+ {
518
+ c.operand1 = removeClause(c.operand1, s);
519
+ c.operand2 = removeClause(c.operand2, s);
520
+ if ((c.op.tt === TokType.And || c.op.tt === TokType.Or) && (c.operand1 == null || c.operand2 == null))
521
+ return c.operand1 || c.operand2;
522
+ return c;
523
+ }
524
+ }
525
+
487
526
  export class FilterExpr
488
527
  {
489
528
  lexer: Lexer;
@@ -512,12 +551,47 @@ export class FilterExpr
512
551
  return this.asStringClause(this.parser.clause);
513
552
  }
514
553
 
554
+ containsClause(expr: string): boolean
555
+ {
556
+ let sub = new FilterExpr(this.lexer.coder, expr);
557
+ return containsClause(this.parser.clause, sub.parser.clause);
558
+ }
559
+
560
+ addClause(expr: string): void
561
+ {
562
+ let sub = new FilterExpr(this.lexer.coder, expr);
563
+ if (! containsClause(this.parser.clause, sub.parser.clause))
564
+ {
565
+ if (this.parser.clause)
566
+ this.parser.clauses = [ { op: { tt: TokType.And }, operand1: this.parser.clause, operand2: sub.parser.clause } ];
567
+ else
568
+ this.parser.clauses = [ sub.parser.clause ];
569
+ }
570
+ }
571
+
572
+ removeClause(expr: string): void
573
+ {
574
+ if (this.containsClause(expr))
575
+ {
576
+ let sub = new FilterExpr(this.lexer.coder, expr);
577
+ this.parser.clauses = [ removeClause(this.parser.clause, sub.parser.clause) ];
578
+ }
579
+ }
580
+
515
581
  asStringClause(clause: Clause): string
516
582
  {
517
583
  if (clause == null) return '';
518
- if (clause.op.tt == TokType.Text) return `'${clause.op.text}'`;
584
+ if (clause.op.tt == TokType.Text)
585
+ {
586
+ this.lexer.set(clause.op.text);
587
+ if (this.lexer.tokens.length == 1 && this.lexer.tokens[0].tt === TokType.Text)
588
+ return clause.op.text;
589
+ else
590
+ return `'${clause.op.text}'`;
591
+ }
519
592
  let a: string[] = [];
520
- a.push('(');
593
+ if (clause !== this.parser.clause)
594
+ a.push('(');
521
595
  switch (clause.op.tt)
522
596
  {
523
597
  case TokType.And:
@@ -535,8 +609,7 @@ export class FilterExpr
535
609
  a.push(this.asStringClause(clause.operand1));
536
610
  break;
537
611
  case TokType.Colon:
538
- a.push(this.asStringClause(clause.operand1));
539
- a.push(':');
612
+ a.push(`${this.asStringClause(clause.operand1)}:`);
540
613
  a.push(this.asStringClause(clause.operand2));
541
614
  break;
542
615
  case TokType.Equal:
@@ -551,7 +624,8 @@ export class FilterExpr
551
624
  default:
552
625
  throw 'Unexpected token in asString';
553
626
  }
554
- a.push(')');
627
+ if (clause !== this.parser.clause)
628
+ a.push(')');
555
629
  return a.join(' ');
556
630
  }
557
631
 
package/lib/fsm/fsm.ts CHANGED
@@ -291,6 +291,7 @@ export class FsmOnDone extends Fsm
291
291
  export class FsmSleep extends Fsm
292
292
  {
293
293
  delay: number;
294
+ timeoutHandle: any;
294
295
 
295
296
  constructor(env: FsmEnvironment, delay: number)
296
297
  {
@@ -300,10 +301,19 @@ export class FsmSleep extends Fsm
300
301
 
301
302
  tick(): void
302
303
  {
303
- if (this.ready && this.state === FSM_STARTING)
304
+ // This allows canceling by simply setting state to done
305
+ if (this.done && this.timeoutHandle !== undefined)
306
+ {
307
+ clearTimeout(this.timeoutHandle);
308
+ delete this.timeoutHandle;
309
+ }
310
+ else if (this.ready && this.state === FSM_STARTING)
304
311
  {
305
312
  this.setState(FSM_PENDING);
306
- setTimeout(() => { this.setState(FSM_DONE); }, this.delay);
313
+ this.timeoutHandle = setTimeout(() => {
314
+ delete this.timeoutHandle;
315
+ this.setState(FSM_DONE)
316
+ }, this.delay);
307
317
  }
308
318
  }
309
319
  }
@@ -111,6 +111,8 @@ export interface SessionProps
111
111
  loadFailed: boolean;
112
112
  accessMap: AccessMap;
113
113
  revisions: RevisionList;
114
+ expunged?: boolean;
115
+ expungeDate?: string;
114
116
  xprops?: { [prop: string]: string };
115
117
  }
116
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",