@dra2020/baseclient 1.0.166 → 1.0.168

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 CHANGED
@@ -14,8 +14,8 @@ import * as OT from '../ot-js/all';
14
14
  export { OT };
15
15
  import * as OTE from '../ot-editutil/all';
16
16
  export { OTE };
17
- import { FilterExpr } from '../filterexpr/all';
18
- export { FilterExpr };
17
+ import { FilterExpr, cacheFilterExpr } from '../filterexpr/all';
18
+ export { FilterExpr, cacheFilterExpr };
19
19
  import * as G from '../geo/all';
20
20
  export { G };
21
21
  import * as Emit from '../emit/all';
@@ -53,7 +53,7 @@ var __importStar = (this && this.__importStar) || (function () {
53
53
  };
54
54
  })();
55
55
  Object.defineProperty(exports, "__esModule", ({ value: true }));
56
- exports.Control = exports.Detail = exports.DataFlow = exports.Colors = exports.CSV = exports.Emit = exports.G = exports.FilterExpr = exports.OTE = exports.OT = exports.LogClient = exports.LogAbstract = exports.Poly = exports.FSM = exports.Context = exports.Util = void 0;
56
+ exports.Control = exports.Detail = exports.DataFlow = exports.Colors = exports.CSV = exports.Emit = exports.G = exports.cacheFilterExpr = exports.FilterExpr = exports.OTE = exports.OT = exports.LogClient = exports.LogAbstract = exports.Poly = exports.FSM = exports.Context = exports.Util = void 0;
57
57
  // Client and Server
58
58
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
59
59
  exports.Util = Util;
@@ -73,6 +73,7 @@ const OTE = __importStar(__webpack_require__(/*! ../ot-editutil/all */ "./lib/ot
73
73
  exports.OTE = OTE;
74
74
  const all_1 = __webpack_require__(/*! ../filterexpr/all */ "./lib/filterexpr/all.ts");
75
75
  Object.defineProperty(exports, "FilterExpr", ({ enumerable: true, get: function () { return all_1.FilterExpr; } }));
76
+ Object.defineProperty(exports, "cacheFilterExpr", ({ enumerable: true, get: function () { return all_1.cacheFilterExpr; } }));
76
77
  const G = __importStar(__webpack_require__(/*! ../geo/all */ "./lib/geo/all.ts"));
77
78
  exports.G = G;
78
79
  const Emit = __importStar(__webpack_require__(/*! ../emit/all */ "./lib/emit/all.ts"));
@@ -1502,6 +1503,7 @@ var __importStar = (this && this.__importStar) || (function () {
1502
1503
  })();
1503
1504
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1504
1505
  exports.FilterExpr = void 0;
1506
+ exports.cacheFilterExpr = cacheFilterExpr;
1505
1507
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
1506
1508
  const Space = 32;
1507
1509
  const Tab = 9;
@@ -2035,38 +2037,48 @@ class FilterExpr {
2035
2037
  return a.join(' ');
2036
2038
  }
2037
2039
  testClause(o, types, clause, prop, relation) {
2040
+ const filterProp = (p) => {
2041
+ let s = toString(o[p]);
2042
+ if (s) {
2043
+ let t = types ? types[p] : undefined;
2044
+ if (t === 'skip')
2045
+ return false;
2046
+ if (t && t === 'date')
2047
+ s = wordyDate(s);
2048
+ s = s.toLowerCase();
2049
+ if (relation === undefined) {
2050
+ if (s.indexOf(clause.op.text) >= 0)
2051
+ return true;
2052
+ }
2053
+ else {
2054
+ let op2 = isNaN(Number(clause.op.text)) ? clause.op.text : Number(clause.op.text);
2055
+ let op1 = typeof op2 === 'number' ? Number(s) : s;
2056
+ switch (relation) {
2057
+ case TokType.Equal: return op1 === op2;
2058
+ case TokType.LessThan: return op1 < op2;
2059
+ case TokType.LessThanEqual: return op1 <= op2;
2060
+ case TokType.GreaterThanEqual: return op1 >= op2;
2061
+ case TokType.GreaterThan: return op1 > op2;
2062
+ case TokType.NotEqual: return op1 !== op2;
2063
+ }
2064
+ }
2065
+ }
2066
+ };
2038
2067
  if (clause == null)
2039
2068
  return true;
2040
2069
  switch (clause.op.tt) {
2041
2070
  case TokType.Text:
2042
- for (let p in o)
2043
- if (o.hasOwnProperty(p) && (prop == null || p.toLowerCase() === prop)) {
2044
- let s = toString(o[p]);
2045
- if (s) {
2046
- let t = types ? types[p] : undefined;
2047
- if (t === 'skip')
2048
- continue;
2049
- if (t && t === 'date')
2050
- s = wordyDate(s);
2051
- s = s.toLowerCase();
2052
- if (relation === undefined) {
2053
- if (s.indexOf(clause.op.text) >= 0)
2054
- return true;
2055
- }
2056
- else {
2057
- let op2 = isNaN(Number(clause.op.text)) ? clause.op.text : Number(clause.op.text);
2058
- let op1 = typeof op2 === 'number' ? Number(s) : s;
2059
- switch (relation) {
2060
- case TokType.Equal: return op1 === op2;
2061
- case TokType.LessThan: return op1 < op2;
2062
- case TokType.LessThanEqual: return op1 <= op2;
2063
- case TokType.GreaterThanEqual: return op1 >= op2;
2064
- case TokType.GreaterThan: return op1 > op2;
2065
- case TokType.NotEqual: return op1 !== op2;
2066
- }
2067
- }
2068
- }
2069
- }
2071
+ if (o._filtercache) {
2072
+ if (prop == null)
2073
+ return o._filtercache.indexOf(clause.op.text) >= 0;
2074
+ else
2075
+ return filterProp(prop);
2076
+ }
2077
+ else {
2078
+ for (let p in o)
2079
+ if ((prop == null || p === prop) && filterProp(p))
2080
+ return true;
2081
+ }
2070
2082
  return false;
2071
2083
  case TokType.Colon:
2072
2084
  if (clause.operand1 && clause.operand1.op.tt === TokType.Text)
@@ -2092,6 +2104,26 @@ class FilterExpr {
2092
2104
  }
2093
2105
  }
2094
2106
  exports.FilterExpr = FilterExpr;
2107
+ function cacheFilterExpr(o, types) {
2108
+ if (o) {
2109
+ delete o._filtercache;
2110
+ let a = [];
2111
+ for (let p in o) {
2112
+ let s;
2113
+ let t = types ? types[p] : undefined;
2114
+ if (t === 'skip')
2115
+ s = '';
2116
+ else {
2117
+ s = toString(o[p]);
2118
+ if (t === 'date')
2119
+ s = wordyDate(s);
2120
+ s = s.toLowerCase();
2121
+ }
2122
+ a.push(s);
2123
+ }
2124
+ o._filtercache = a.join('|'); // insert separator to reduce likelihood of spurious matches that cross property values
2125
+ }
2126
+ }
2095
2127
 
2096
2128
 
2097
2129
  /***/ }),
@@ -2736,6 +2768,10 @@ exports.geoCollectionToTopo = geoCollectionToTopo;
2736
2768
  exports.geoCollectionToTopoNonNull = geoCollectionToTopoNonNull;
2737
2769
  exports.geoTopoToCollection = geoTopoToCollection;
2738
2770
  exports.geoTopoToCollectionNonNull = geoTopoToCollectionNonNull;
2771
+ exports.geoFilterFromHidden = geoFilterFromHidden;
2772
+ exports.geoFilteredTopo = geoFilteredTopo;
2773
+ exports.geoFilteredCollection = geoFilteredCollection;
2774
+ exports.geoFilteredMap = geoFilteredMap;
2739
2775
  exports.geoEqual = geoEqual;
2740
2776
  exports.geoMapEqual = geoMapEqual;
2741
2777
  exports.geoIntersect = geoIntersect;
@@ -2912,6 +2948,37 @@ function geoTopoToCollection(topo) {
2912
2948
  function geoTopoToCollectionNonNull(topo) {
2913
2949
  return geoTopoToCollection(topo);
2914
2950
  }
2951
+ function geoFilterFromHidden(hidden) {
2952
+ if (Util.isEmpty(hidden))
2953
+ return undefined;
2954
+ return (s) => { return !hidden[s]; };
2955
+ }
2956
+ function geoFilteredTopo(topo, filter) {
2957
+ if (!topo || !filter)
2958
+ return topo;
2959
+ let copy = Util.shallowCopy(topo);
2960
+ copy.objects = {};
2961
+ Object.keys(topo.objects).forEach(geoid => {
2962
+ if (filter(geoid))
2963
+ copy.objects[geoid] = topo.objects[geoid];
2964
+ });
2965
+ return copy;
2966
+ }
2967
+ function geoFilteredCollection(col, filter) {
2968
+ if (!col || !filter)
2969
+ return col;
2970
+ let copy = Util.shallowCopy(col);
2971
+ copy.features = col.features.filter(f => filter(f.properties.id));
2972
+ return copy;
2973
+ }
2974
+ function geoFilteredMap(map, filter) {
2975
+ if (!map || !filter)
2976
+ return map;
2977
+ let copy = {};
2978
+ Object.keys(map).forEach(geoid => { if (filter(geoid))
2979
+ copy[geoid] = map[geoid]; });
2980
+ return copy;
2981
+ }
2915
2982
  function geoEqual(m1, m2) {
2916
2983
  let n1 = m1 ? m1.length : 0;
2917
2984
  let n2 = m2 ? m2.length : 0;
@@ -2977,12 +3044,15 @@ class GeoMultiCollection {
2977
3044
  });
2978
3045
  for (let p in multi.hidden)
2979
3046
  if (multi.hidden.hasOwnProperty(p)) {
2980
- this.hidden[p] = true;
2981
- this._onChange();
3047
+ if (!this.hidden[p]) {
3048
+ this.hidden[p] = true;
3049
+ this._onChange();
3050
+ }
2982
3051
  }
2983
3052
  }
2984
3053
  // Add the "all" collection from the passed in multi, but do not force compute of any things not computed yet.
2985
3054
  addAll(tag, multi) {
3055
+ var _a;
2986
3056
  if (multi == null || Util.isEmpty(multi.entries))
2987
3057
  this.remove(tag);
2988
3058
  else {
@@ -2990,11 +3060,15 @@ class GeoMultiCollection {
2990
3060
  if (nEntries) {
2991
3061
  // Make sure all collection is created
2992
3062
  if (!multi.all.topo && !multi.all.col && !multi.all.map) {
2993
- // Create cheapest one (collection if I need to create, otherwise copy from single entry)
2994
- if (nEntries > 1)
2995
- multi.allCol();
3063
+ // Make sure at least one all entry is built, preferably topo if there is a base topo
3064
+ let e = (_a = multi.entries['main']) !== null && _a !== void 0 ? _a : multi.nthEntry(0);
3065
+ if (nEntries > 1) {
3066
+ if (e.topo)
3067
+ multi.allTopo();
3068
+ else
3069
+ multi.allCol();
3070
+ }
2996
3071
  else {
2997
- let e = multi.nthEntry(0);
2998
3072
  multi.all.topo = e.topo;
2999
3073
  multi.all.col = e.col;
3000
3074
  multi.all.map = e.map;
@@ -3150,19 +3224,19 @@ class GeoMultiCollection {
3150
3224
  if (!this.all.topo) {
3151
3225
  // optimise case where one entry
3152
3226
  let n = this.nEntries;
3153
- let e = this.nthEntry(0);
3227
+ let e = this.entries['main'] || this.nthEntry(0);
3154
3228
  if (n == 1) {
3155
- // Note that this is potentially invalid shortcut when some features are hidden from base geometry.
3156
- // Could test overall count of objects vs. this count to check.
3157
- this.all.topo = this._topo(e);
3158
- this.all.col = this.all.col || e.col;
3159
- this.all.map = this.all.map || e.map;
3229
+ let filter = geoFilterFromHidden(this.hidden);
3230
+ this.all.topo = geoFilteredTopo(this._topo(e), filter);
3231
+ this.all.col = this.all.col || geoFilteredCollection(e.col, filter);
3232
+ this.all.map = this.all.map || geoFilteredMap(e.map, filter);
3160
3233
  }
3161
3234
  else if (e.topo) {
3162
- // Old-style, goes through map (to filter hidden) and then collection
3163
- // this.all.topo = geoCollectionToTopoNonNull(this.allCol());
3164
3235
  // New style, use splice on packed topologies
3165
- let filterout = Util.isEmpty(this.hidden) ? null : this.hidden; // splice function requires NULL for empty
3236
+ let filterout = this.someHidden() ? this.hidden : null; // splice function requires NULL for empty
3237
+ // DEBUGGING
3238
+ filterout = null;
3239
+ // DEBUGGING
3166
3240
  let topoarray = Object.values(this.entries).filter((e) => this._length(e) > 0)
3167
3241
  .map((e) => { return { topology: this._topo(e), filterout }; });
3168
3242
  this.all.topo = topoarray.length == 0 ? null : topoarray.length == 1 ? topoarray[0].topology : Poly.topoSplice(topoarray);
@@ -3304,6 +3378,9 @@ class GeoMultiCollection {
3304
3378
  });
3305
3379
  return m;
3306
3380
  }
3381
+ someHidden() {
3382
+ return !Util.isEmpty(this.hidden);
3383
+ }
3307
3384
  }
3308
3385
  exports.GeoMultiCollection = GeoMultiCollection;
3309
3386
  var geoIntersectOptions;
@@ -9023,8 +9100,23 @@ function topoToBuffer(coder, topo) {
9023
9100
  // Make sure we're packed
9024
9101
  T.topoPack(topo);
9025
9102
  let savepack = topo.packed;
9103
+ // On-disk format predates the topology.packed.objectArcs WeakMap: each object
9104
+ // carried its own `packedarcs: number` field in the serialized JSON. Preserve
9105
+ // that format. We temporarily project the WeakMap entries back onto each object
9106
+ // before stringifying, then strip them so the in-memory topology is unchanged.
9107
+ let projected = [];
9108
+ if (savepack.objectArcs)
9109
+ for (let id in topo.objects) {
9110
+ let o = topo.objects[id];
9111
+ let off = savepack.objectArcs.get(o);
9112
+ if (off !== undefined) {
9113
+ o.packedarcs = off;
9114
+ projected.push(o);
9115
+ }
9116
+ }
9026
9117
  delete topo.packed;
9027
9118
  let json = JSON.stringify(topo);
9119
+ projected.forEach(o => { delete o.packedarcs; });
9028
9120
  let byteLength = HeaderSize; // 3 lengths + padding
9029
9121
  let stringLength = sizeOfString(coder, json);
9030
9122
  stringLength += pad(stringLength, 8);
@@ -9068,6 +9160,18 @@ function topoFromBuffer(coder, ab) {
9068
9160
  topo.packed = {};
9069
9161
  topo.packed.arcs = new Float64Array(ab, stringLength + HeaderSize, arcsByteLength / 8);
9070
9162
  topo.packed.arcindices = new Int32Array(ab, stringLength + HeaderSize + arcsByteLength, arcindicesByteLength / 4);
9163
+ // Reconstruct the WeakMap from the legacy per-object `packedarcs` field, then
9164
+ // strip the field so the object representation matches a freshly-packed one.
9165
+ let objectArcs = new WeakMap();
9166
+ if (topo.objects)
9167
+ for (let id in topo.objects) {
9168
+ let o = topo.objects[id];
9169
+ if (o && o.packedarcs !== undefined) {
9170
+ objectArcs.set(o, o.packedarcs);
9171
+ delete o.packedarcs;
9172
+ }
9173
+ }
9174
+ topo.packed.objectArcs = objectArcs;
9071
9175
  return topo;
9072
9176
  }
9073
9177