@dra2020/baseclient 1.0.146 → 1.0.148
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 +36 -12
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +2 -0
- package/lib/detail/detail.ts +10 -5
- package/lib/geo/geo.ts +26 -5
- package/package.json +1 -1
package/dist/geo/geo.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface NormalizeOptions {
|
|
|
20
20
|
checkRewind?: boolean;
|
|
21
21
|
ensureID?: boolean;
|
|
22
22
|
}
|
|
23
|
+
export declare function applyCanonicalID(col: GeoFeatureCollection): void;
|
|
24
|
+
export declare function isValidId(col: GeoFeatureCollection): boolean;
|
|
23
25
|
export declare function geoEnsureID(col: GeoFeatureCollection, options?: NormalizeOptions): void;
|
|
24
26
|
export declare function geoNormalizeFeature(f: any, options?: NormalizeOptions): GeoFeature;
|
|
25
27
|
export declare function geoNormalizeCollection(col: GeoFeatureCollection, options?: NormalizeOptions): GeoFeatureCollection;
|
package/lib/detail/detail.ts
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
import * as Util from '../util/all';
|
|
15
15
|
//import { Util } from '@dra2020/baseclient';
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const reIdentifierOrStringOrNumber = /([a-zA-Z0-9_$][a-zA-Z0-9_$]*)|(['"])(?:(?=(\\?))\3.)*?\2/g;
|
|
18
|
+
const reNumber = /[0-9][0-9]*/;
|
|
19
19
|
const reParam = /^__\d+$/;
|
|
20
20
|
const reString = /^['"]/;
|
|
21
21
|
|
|
@@ -73,10 +73,12 @@ class Evaluator
|
|
|
73
73
|
let safenames = names.map(n => namemap[n]);
|
|
74
74
|
|
|
75
75
|
// Replace valid identifiers with safe version
|
|
76
|
-
safeexpr = safeexpr.replace(
|
|
76
|
+
safeexpr = safeexpr.replace(reIdentifierOrStringOrNumber,
|
|
77
77
|
(match) => {
|
|
78
78
|
if (namemap[match])
|
|
79
79
|
return namemap[match];
|
|
80
|
+
else if (reNumber.test(match))
|
|
81
|
+
return match;
|
|
80
82
|
else if (match === '__format' || reString.test(match))
|
|
81
83
|
return match;
|
|
82
84
|
else
|
|
@@ -87,9 +89,12 @@ class Evaluator
|
|
|
87
89
|
});
|
|
88
90
|
|
|
89
91
|
// Remove any identifiers that aren't the simple parameters to prevent out-of-sandbox execution
|
|
90
|
-
safeexpr = safeexpr.replace(
|
|
92
|
+
safeexpr = safeexpr.replace(reIdentifierOrStringOrNumber,
|
|
91
93
|
(match) => {
|
|
92
|
-
let valid = reParam.test(match)
|
|
94
|
+
let valid = reParam.test(match)
|
|
95
|
+
|| match === '__format'
|
|
96
|
+
|| reString.test(match)
|
|
97
|
+
|| reNumber.test(match);
|
|
93
98
|
if (valid)
|
|
94
99
|
return match;
|
|
95
100
|
else
|
package/lib/geo/geo.ts
CHANGED
|
@@ -44,6 +44,27 @@ export interface NormalizeOptions
|
|
|
44
44
|
}
|
|
45
45
|
const NormalizeAll: NormalizeOptions = { joinPolygons: true, checkRewind: true, ensureID: true };
|
|
46
46
|
|
|
47
|
+
export function applyCanonicalID(col: GeoFeatureCollection): void
|
|
48
|
+
{
|
|
49
|
+
if (col && Array.isArray(col.features))
|
|
50
|
+
col.features.forEach((f: GeoFeature, n: number) => { f.properties.id = String(n+1) });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function isValidId(col: GeoFeatureCollection): boolean
|
|
54
|
+
{
|
|
55
|
+
if (! col || ! Array.isArray(col.features)) return true;
|
|
56
|
+
|
|
57
|
+
let set = new Set<string>();
|
|
58
|
+
for (let i = 0; i < col.features.length; i++)
|
|
59
|
+
{
|
|
60
|
+
let f = col.features[i];
|
|
61
|
+
if (typeof f.properties.id !== 'string') return false; // id must be string
|
|
62
|
+
if (set.has(f.properties.id)) return false; // id must be unique
|
|
63
|
+
set.add(f.properties.id);
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
// set the canonical 'id' property from the best property value.
|
|
48
69
|
// if joinPolygons is true, we do not enforce uniqueness.
|
|
49
70
|
//
|
|
@@ -58,7 +79,6 @@ export function geoEnsureID(col: GeoFeatureCollection, options?: NormalizeOption
|
|
|
58
79
|
if (col && col.features && col.features.length > 0)
|
|
59
80
|
{
|
|
60
81
|
let f = col.features[0];
|
|
61
|
-
if (f.properties.id !== undefined) return; // short-cut - assume if 'id' is set, we're all good.
|
|
62
82
|
props.forEach(p => {
|
|
63
83
|
if (prop === undefined)
|
|
64
84
|
if (f.properties[p] !== undefined)
|
|
@@ -71,12 +91,13 @@ export function geoEnsureID(col: GeoFeatureCollection, options?: NormalizeOption
|
|
|
71
91
|
}
|
|
72
92
|
});
|
|
73
93
|
if (prop)
|
|
74
|
-
col.features.forEach(f => { f.properties.id = f.properties[prop] });
|
|
75
|
-
else
|
|
76
94
|
{
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
col.features.forEach(f => { f.properties.id = f.properties[prop] });
|
|
96
|
+
if (! isValidId(col))
|
|
97
|
+
applyCanonicalID(col);
|
|
79
98
|
}
|
|
99
|
+
else
|
|
100
|
+
applyCanonicalID(col);
|
|
80
101
|
}
|
|
81
102
|
}
|
|
82
103
|
|