@dra2020/baseclient 1.0.165 → 1.0.167
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/all/all.d.ts +2 -2
- package/dist/baseclient.js +71 -36
- package/dist/baseclient.js.map +1 -1
- package/dist/filterexpr/filterexpr.d.ts +1 -0
- package/lib/all/all.ts +2 -2
- package/lib/filterexpr/filterexpr.ts +68 -30
- package/lib/ot-js/otclientengine.ts +10 -7
- package/package.json +1 -1
package/lib/all/all.ts
CHANGED
|
@@ -15,8 +15,8 @@ import * as OT from '../ot-js/all';
|
|
|
15
15
|
export { OT };
|
|
16
16
|
import * as OTE from '../ot-editutil/all';
|
|
17
17
|
export { OTE };
|
|
18
|
-
import { FilterExpr } from '../filterexpr/all';
|
|
19
|
-
export { FilterExpr }
|
|
18
|
+
import { FilterExpr, cacheFilterExpr } from '../filterexpr/all';
|
|
19
|
+
export { FilterExpr, cacheFilterExpr }
|
|
20
20
|
import * as G from '../geo/all';
|
|
21
21
|
export { G };
|
|
22
22
|
import * as Emit from '../emit/all';
|
|
@@ -677,42 +677,55 @@ export class FilterExpr
|
|
|
677
677
|
|
|
678
678
|
testClause(o: any, types: any, clause: Clause, prop?: string, relation?: TokType): boolean
|
|
679
679
|
{
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
case TokType.Text:
|
|
684
|
-
for (let p in o) if (o.hasOwnProperty(p) && (prop == null || p.toLowerCase() === prop))
|
|
680
|
+
const filterProp = (p: string) => {
|
|
681
|
+
let s = toString(o[p]);
|
|
682
|
+
if (s)
|
|
685
683
|
{
|
|
686
|
-
let
|
|
687
|
-
if (
|
|
684
|
+
let t = types ? types[p] : undefined;
|
|
685
|
+
if (t === 'skip')
|
|
686
|
+
return false;
|
|
687
|
+
if (t && t === 'date')
|
|
688
|
+
s = wordyDate(s);
|
|
689
|
+
s = s.toLowerCase();
|
|
690
|
+
if (relation === undefined)
|
|
688
691
|
{
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
692
|
+
if (s.indexOf(clause.op.text) >= 0)
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
else
|
|
696
|
+
{
|
|
697
|
+
let op2: any = isNaN(Number(clause.op.text)) ? clause.op.text : Number(clause.op.text);
|
|
698
|
+
let op1: any = typeof op2 === 'number' ? Number(s) : s;
|
|
699
|
+
switch (relation)
|
|
696
700
|
{
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
let op1: any = typeof op2 === 'number' ? Number(s) : s;
|
|
704
|
-
switch (relation)
|
|
705
|
-
{
|
|
706
|
-
case TokType.Equal: return op1 === op2;
|
|
707
|
-
case TokType.LessThan: return op1 < op2;
|
|
708
|
-
case TokType.LessThanEqual: return op1 <= op2;
|
|
709
|
-
case TokType.GreaterThanEqual: return op1 >= op2;
|
|
710
|
-
case TokType.GreaterThan: return op1 > op2;
|
|
711
|
-
case TokType.NotEqual: return op1 !== op2;
|
|
712
|
-
}
|
|
701
|
+
case TokType.Equal: return op1 === op2;
|
|
702
|
+
case TokType.LessThan: return op1 < op2;
|
|
703
|
+
case TokType.LessThanEqual: return op1 <= op2;
|
|
704
|
+
case TokType.GreaterThanEqual: return op1 >= op2;
|
|
705
|
+
case TokType.GreaterThan: return op1 > op2;
|
|
706
|
+
case TokType.NotEqual: return op1 !== op2;
|
|
713
707
|
}
|
|
714
708
|
}
|
|
715
709
|
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
if (clause == null) return true;
|
|
713
|
+
switch (clause.op.tt)
|
|
714
|
+
{
|
|
715
|
+
case TokType.Text:
|
|
716
|
+
if (o._filtercache)
|
|
717
|
+
{
|
|
718
|
+
if (prop == null)
|
|
719
|
+
return o._filtercache.indexOf(clause.op.text) >= 0;
|
|
720
|
+
else
|
|
721
|
+
return filterProp(prop);
|
|
722
|
+
}
|
|
723
|
+
else
|
|
724
|
+
{
|
|
725
|
+
for (let p in o)
|
|
726
|
+
if ((prop == null || p === prop) && filterProp(p))
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
716
729
|
return false;
|
|
717
730
|
|
|
718
731
|
case TokType.Colon:
|
|
@@ -743,3 +756,28 @@ export class FilterExpr
|
|
|
743
756
|
// NOTREACHED
|
|
744
757
|
}
|
|
745
758
|
}
|
|
759
|
+
|
|
760
|
+
export function cacheFilterExpr(o: any, types: any): void
|
|
761
|
+
{
|
|
762
|
+
if (o)
|
|
763
|
+
{
|
|
764
|
+
delete o._filtercache;
|
|
765
|
+
let a: string[] = [];
|
|
766
|
+
for (let p in o)
|
|
767
|
+
{
|
|
768
|
+
let s: string;
|
|
769
|
+
let t = types ? types[p] : undefined;
|
|
770
|
+
if (t === 'skip')
|
|
771
|
+
s = '';
|
|
772
|
+
else
|
|
773
|
+
{
|
|
774
|
+
s = toString(o[p]);
|
|
775
|
+
if (t === 'date')
|
|
776
|
+
s = wordyDate(s);
|
|
777
|
+
s = s.toLowerCase();
|
|
778
|
+
}
|
|
779
|
+
a.push(s);
|
|
780
|
+
}
|
|
781
|
+
o._filtercache = a.join('|'); // insert separator to reduce likelihood of spurious matches that cross property values
|
|
782
|
+
}
|
|
783
|
+
}
|
|
@@ -34,13 +34,12 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
34
34
|
this.clientID = cid;
|
|
35
35
|
this.initialize();
|
|
36
36
|
this.bReadOnly = false;
|
|
37
|
-
this.valCache = {};
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
initialize(): void
|
|
41
40
|
{
|
|
42
41
|
if (this.prefailCache === undefined && this.clientSequenceNo > 0)
|
|
43
|
-
this.prefailCache = this.
|
|
42
|
+
this.prefailCache = this.toValue();
|
|
44
43
|
this.clientSequenceNo = 0;
|
|
45
44
|
this.isNeedAck = false;
|
|
46
45
|
this.isNeedResend = false;
|
|
@@ -71,11 +70,15 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
71
70
|
|
|
72
71
|
toPartialValue(resourceName: string): any
|
|
73
72
|
{
|
|
73
|
+
if (! this.valCache)
|
|
74
|
+
this.valCache = {};
|
|
74
75
|
return this.valCache[resourceName];
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
toValue(): any
|
|
78
79
|
{
|
|
80
|
+
if (! this.valCache)
|
|
81
|
+
this.valCache = this.stateLocal.toValue();
|
|
79
82
|
return this.valCache;
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -155,7 +158,7 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
155
158
|
{
|
|
156
159
|
console.log('otclientengine: failbackToInitialState');
|
|
157
160
|
if (this.prefailCache === undefined)
|
|
158
|
-
this.prefailCache = this.
|
|
161
|
+
this.prefailCache = this.toValue();
|
|
159
162
|
this.initialize();
|
|
160
163
|
}
|
|
161
164
|
|
|
@@ -164,7 +167,7 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
164
167
|
{
|
|
165
168
|
console.log('otclientengine: failbackToServerState');
|
|
166
169
|
if (this.prefailCache === undefined)
|
|
167
|
-
this.prefailCache = this.
|
|
170
|
+
this.prefailCache = this.toValue();
|
|
168
171
|
this.stateLocal = this.stateServer.copy();
|
|
169
172
|
this.isNeedAck = false;
|
|
170
173
|
this.actionSentClient.empty();
|
|
@@ -172,7 +175,7 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
172
175
|
this.actionServerInterposedSentClient.empty();
|
|
173
176
|
this.actionAllPendingClient.empty();
|
|
174
177
|
this.actionAllClient.empty();
|
|
175
|
-
this.valCache
|
|
178
|
+
delete this.valCache;
|
|
176
179
|
this.emit('state');
|
|
177
180
|
}
|
|
178
181
|
|
|
@@ -284,7 +287,7 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
284
287
|
this.actionServerInterposedSentClient.compose(orig);
|
|
285
288
|
|
|
286
289
|
// Let clients know
|
|
287
|
-
this.valCache
|
|
290
|
+
delete this.valCache;
|
|
288
291
|
this.emit('state');
|
|
289
292
|
}
|
|
290
293
|
}
|
|
@@ -318,7 +321,7 @@ export class OTClientEngine extends OTE.OTEngine
|
|
|
318
321
|
this.actionAllClient.compose(orig);
|
|
319
322
|
this.actionAllPendingClient.compose(orig);
|
|
320
323
|
this.stateLocal.compose(orig);
|
|
321
|
-
this.valCache
|
|
324
|
+
delete this.valCache;
|
|
322
325
|
this.emit('state');
|
|
323
326
|
}
|
|
324
327
|
catch (err)
|