Fix partial compilation, fix tests

This commit is contained in:
Pieter Vander Vennet 2022-07-06 17:11:17 +02:00
parent 9f41e719f2
commit a08a49abb2
3 changed files with 36 additions and 34 deletions

View file

@ -31,6 +31,7 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement";
export default class LayerConfig extends WithContextLoader { export default class LayerConfig extends WithContextLoader {
public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const;
public readonly id: string; public readonly id: string;
public readonly name: Translation; public readonly name: Translation;
public readonly description: Translation; public readonly description: Translation;
@ -44,10 +45,8 @@ export default class LayerConfig extends WithContextLoader {
public readonly maxzoom: number; public readonly maxzoom: number;
public readonly title?: TagRenderingConfig; public readonly title?: TagRenderingConfig;
public readonly titleIcons: TagRenderingConfig[]; public readonly titleIcons: TagRenderingConfig[];
public readonly mapRendering: PointRenderingConfig[] public readonly mapRendering: PointRenderingConfig[]
public readonly lineRendering: LineRenderingConfig[] public readonly lineRendering: LineRenderingConfig[]
public readonly units: Unit[]; public readonly units: Unit[];
public readonly deletion: DeleteConfig | null; public readonly deletion: DeleteConfig | null;
public readonly allowMove: MoveConfig | null public readonly allowMove: MoveConfig | null
@ -57,15 +56,11 @@ export default class LayerConfig extends WithContextLoader {
* In seconds * In seconds
*/ */
public readonly maxAgeOfCache: number public readonly maxAgeOfCache: number
public readonly presets: PresetConfig[]; public readonly presets: PresetConfig[];
public readonly tagRenderings: TagRenderingConfig[]; public readonly tagRenderings: TagRenderingConfig[];
public readonly filters: FilterConfig[]; public readonly filters: FilterConfig[];
public readonly filterIsSameAs: string; public readonly filterIsSameAs: string;
public readonly forceLoad: boolean; public readonly forceLoad: boolean;
public static readonly syncSelectionAllowed = ["no" , "local" , "theme-only" , "global"] as const;
public readonly syncSelection: (typeof LayerConfig.syncSelectionAllowed)[number] // this is a trick to conver a constant array of strings into a type union of these values public readonly syncSelection: (typeof LayerConfig.syncSelectionAllowed)[number] // this is a trick to conver a constant array of strings into a type union of these values
constructor( constructor(
@ -74,18 +69,24 @@ export default class LayerConfig extends WithContextLoader {
official: boolean = true official: boolean = true
) { ) {
context = context + "." + json.id; context = context + "." + json.id;
const translationContext = "layers:"+json.id const translationContext = "layers:" + json.id
super(json, context) super(json, context)
this.id = json.id; this.id = json.id;
if (typeof json === "string") {
throw `Not a valid layer: the layerConfig is a string. 'npm run generate:layeroverview' might be needed (at ${context})`
}
if (json.id === undefined) { if (json.id === undefined) {
throw "Not a valid layer: id is undefined: " + JSON.stringify(json) throw `Not a valid layer: id is undefined: ${JSON.stringify(json)} (At ${context})`
} }
if (json.source === undefined) { if (json.source === undefined) {
throw "Layer " + this.id + " does not define a source section (" + context + ")" throw "Layer " + this.id + " does not define a source section (" + context + ")"
} }
if (json.source.osmTags === undefined) { if (json.source.osmTags === undefined) {
throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")" throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")"
} }
@ -98,8 +99,8 @@ export default class LayerConfig extends WithContextLoader {
} }
this.maxAgeOfCache = json.source.maxCacheAge ?? 24 * 60 * 60 * 30 this.maxAgeOfCache = json.source.maxCacheAge ?? 24 * 60 * 60 * 30
if(json.syncSelection !== undefined && LayerConfig.syncSelectionAllowed.indexOf(json.syncSelection) < 0){ if (json.syncSelection !== undefined && LayerConfig.syncSelectionAllowed.indexOf(json.syncSelection) < 0) {
throw context+ " Invalid sync-selection: must be one of "+LayerConfig.syncSelectionAllowed.map(v => `'${v}'`).join(", ")+" but got '"+json.syncSelection+"'" throw context + " Invalid sync-selection: must be one of " + LayerConfig.syncSelectionAllowed.map(v => `'${v}'`).join(", ") + " but got '" + json.syncSelection + "'"
} }
this.syncSelection = json.syncSelection ?? "no"; this.syncSelection = json.syncSelection ?? "no";
const osmTags = TagUtils.Tag( const osmTags = TagUtils.Tag(
@ -107,10 +108,10 @@ export default class LayerConfig extends WithContextLoader {
context + "source.osmTags" context + "source.osmTags"
); );
if(Constants.priviliged_layers.indexOf(this.id) < 0 && osmTags.isNegative()){ if (Constants.priviliged_layers.indexOf(this.id) < 0 && osmTags.isNegative()) {
throw context + "The source states tags which give a very wide selection: it only uses negative expressions, which will result in too much and unexpected data. Add at least one required tag. The tags are:\n\t"+osmTags.asHumanString(false, false, {}); throw context + "The source states tags which give a very wide selection: it only uses negative expressions, which will result in too much and unexpected data. Add at least one required tag. The tags are:\n\t" + osmTags.asHumanString(false, false, {});
} }
if (json.source["geoJsonSource"] !== undefined) { if (json.source["geoJsonSource"] !== undefined) {
throw context + "Use 'geoJson' instead of 'geoJsonSource'"; throw context + "Use 'geoJson' instead of 'geoJsonSource'";
} }
@ -118,7 +119,7 @@ export default class LayerConfig extends WithContextLoader {
if (json.source["geojson"] !== undefined) { if (json.source["geojson"] !== undefined) {
throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)"; throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)";
} }
this.source = new SourceConfig( this.source = new SourceConfig(
{ {
@ -138,8 +139,8 @@ export default class LayerConfig extends WithContextLoader {
this.allowSplit = json.allowSplit ?? false; this.allowSplit = json.allowSplit ?? false;
this.name = Translations.T(json.name, translationContext + ".name"); this.name = Translations.T(json.name, translationContext + ".name");
if(json.units!==undefined && !Array.isArray(json.units)){ if (json.units !== undefined && !Array.isArray(json.units)) {
throw "At "+context+".units: the 'units'-section should be a list; you probably have an object there" throw "At " + context + ".units: the 'units'-section should be a list; you probably have an object there"
} }
this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`))) this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`)))
@ -167,8 +168,8 @@ export default class LayerConfig extends WithContextLoader {
const index = kv.indexOf("="); const index = kv.indexOf("=");
let key = kv.substring(0, index).trim(); let key = kv.substring(0, index).trim();
const r = "[a-z_][a-z0-9:]*" const r = "[a-z_][a-z0-9:]*"
if(key.match(r) === null){ if (key.match(r) === null) {
throw "At "+context+" invalid key for calculated tag: "+key+"; it should match "+r throw "At " + context + " invalid key for calculated tag: " + key + "; it should match " + r
} }
const isStrict = key.endsWith(':') const isStrict = key.endsWith(':')
if (isStrict) { if (isStrict) {
@ -343,14 +344,14 @@ export default class LayerConfig extends WithContextLoader {
} }
public GenerateDocumentation(usedInThemes: string[], layerIsNeededBy?: Map<string, string[]>, dependencies: { public GenerateDocumentation(usedInThemes: string[], layerIsNeededBy?: Map<string, string[]>, dependencies: {
context?: string; context?: string;
reason: string; reason: string;
neededLayer: string; neededLayer: string;
}[] = [] }[] = []
, addedByDefault = false, canBeIncluded = true): BaseUIElement { , addedByDefault = false, canBeIncluded = true): BaseUIElement {
const extraProps = [] const extraProps = []
extraProps.push("This layer is shown at zoomlevel **"+this.minzoom+"** and higher") extraProps.push("This layer is shown at zoomlevel **" + this.minzoom + "** and higher")
if (canBeIncluded) { if (canBeIncluded) {
if (addedByDefault) { if (addedByDefault) {
@ -440,7 +441,7 @@ export default class LayerConfig extends WithContextLoader {
let overpassLink: BaseUIElement = undefined; let overpassLink: BaseUIElement = undefined;
if (Constants.priviliged_layers.indexOf(this.id) < 0) { if (Constants.priviliged_layers.indexOf(this.id) < 0) {
try { try {
overpassLink = new Link("Execute on overpass", Overpass.AsOverpassTurboLink(<TagsFilter> new And(neededTags).optimize())) overpassLink = new Link("Execute on overpass", Overpass.AsOverpassTurboLink(<TagsFilter>new And(neededTags).optimize()))
} catch (e) { } catch (e) {
console.error("Could not generate overpasslink for " + this.id) console.error("Could not generate overpasslink for " + this.id)
} }

View file

@ -313,7 +313,7 @@ class LayerOverviewUtils {
const usedLayers = Array.from(LayerOverviewUtils.extractLayerIdsFrom(themeFile, false)) const usedLayers = Array.from(LayerOverviewUtils.extractLayerIdsFrom(themeFile, false))
.map(id => LayerOverviewUtils.layerPath + id + ".json") .map(id => LayerOverviewUtils.layerPath + id + ".json")
if (!forceReload && !this.shouldBeUpdated([themePath, ...usedLayers], targetPath)) { if (!forceReload && !this.shouldBeUpdated([themePath, ...usedLayers], targetPath)) {
fixed.set(themeFile.id, themeFile) fixed.set(themeFile.id, JSON.parse(readFileSync(LayerOverviewUtils.themePath+themeFile.id+".json", 'utf8')))
skippedThemes.push(themeFile.id) skippedThemes.push(themeFile.id)
continue; continue;
} }

View file

@ -29,26 +29,27 @@ describe("GenerateCache", () => {
it("should generate a cached file for the Natuurpunt-theme", async () => { it("should generate a cached file for the Natuurpunt-theme", async () => {
// We use /var/tmp instead of /tmp, as more OS's (such as MAC) have this // We use /var/tmp instead of /tmp, as more OS's (such as MAC) have this
if(!existsSync("/var/tmp")){ const dir = "/var/tmp/"
if(!existsSync(dir)){
console.log("Not executing caching test: no temp directory found") console.log("Not executing caching test: no temp directory found")
} }
if (existsSync("/var/tmp/np-cache")) { if (existsSync(dir+"/np-cache")) {
ScriptUtils.readDirRecSync("/var/tmp/np-cache").forEach(p => unlinkSync(p)) ScriptUtils.readDirRecSync(dir+"np-cache").forEach(p => unlinkSync(p))
rmdirSync("/var/tmp/np-cache") rmdirSync(dir+"np-cache")
} }
mkdirSync("/var/tmp/np-cache") mkdirSync(dir+"np-cache")
initDownloads( initDownloads(
"(nwr%5B%22amenity%22%3D%22toilets%22%5D%3Bnwr%5B%22amenity%22%3D%22parking%22%5D%3Bnwr%5B%22amenity%22%3D%22bench%22%5D%3Bnwr%5B%22id%22%3D%22location_track%22%5D%3Bnwr%5B%22id%22%3D%22gps%22%5D%3Bnwr%5B%22information%22%3D%22board%22%5D%3Bnwr%5B%22leisure%22%3D%22picnic_table%22%5D%3Bnwr%5B%22man_made%22%3D%22watermill%22%5D%3Bnwr%5B%22user%3Ahome%22%3D%22yes%22%5D%3Bnwr%5B%22user%3Alocation%22%3D%22yes%22%5D%3Bnwr%5B%22leisure%22%3D%22nature_reserve%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22boundary%22%3D%22protected_area%22%5D%5B%22protect_class%22!%3D%2298%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22visitor_centre%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22office%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*foot.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*hiking.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*bycicle.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*horse.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22leisure%22%3D%22bird_hide%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22amenity%22%3D%22drinking_water%22%5D%5B%22access%22!%3D%22permissive%22%5D%5B%22access%22!%3D%22private%22%5D%3B)%3Bout%20body%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B" "(nwr%5B%22amenity%22%3D%22toilets%22%5D%3Bnwr%5B%22amenity%22%3D%22parking%22%5D%3Bnwr%5B%22amenity%22%3D%22bench%22%5D%3Bnwr%5B%22id%22%3D%22location_track%22%5D%3Bnwr%5B%22id%22%3D%22gps%22%5D%3Bnwr%5B%22information%22%3D%22board%22%5D%3Bnwr%5B%22leisure%22%3D%22picnic_table%22%5D%3Bnwr%5B%22man_made%22%3D%22watermill%22%5D%3Bnwr%5B%22user%3Ahome%22%3D%22yes%22%5D%3Bnwr%5B%22user%3Alocation%22%3D%22yes%22%5D%3Bnwr%5B%22leisure%22%3D%22nature_reserve%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22boundary%22%3D%22protected_area%22%5D%5B%22protect_class%22!%3D%2298%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22visitor_centre%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22office%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*foot.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*hiking.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*bycicle.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*horse.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22leisure%22%3D%22bird_hide%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22amenity%22%3D%22drinking_water%22%5D%5B%22access%22!%3D%22permissive%22%5D%5B%22access%22!%3D%22private%22%5D%3B)%3Bout%20body%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B"
); );
await main([ await main([
"natuurpunt", "natuurpunt",
"12", "12",
"/var/tmp/np-cache", dir+"np-cache",
"51.15423567022531", "3.250579833984375", "51.162821593316934", "3.262810707092285", "51.15423567022531", "3.250579833984375", "51.162821593316934", "3.262810707092285",
"--generate-point-overview", "nature_reserve,visitor_information_centre" "--generate-point-overview", "nature_reserve,visitor_information_centre"
]) ])
await ScriptUtils.sleep(500) await ScriptUtils.sleep(500)
const birdhides = JSON.parse(readFileSync("/var/tmp/np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8")) const birdhides = JSON.parse(readFileSync(dir+"np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8"))
expect(birdhides.features.length).deep.equal(5) expect(birdhides.features.length).deep.equal(5)
expect(birdhides.features.some(f => f.properties.id === "node/5158056232"), "Didn't find birdhide node/5158056232 ").true expect(birdhides.features.some(f => f.properties.id === "node/5158056232"), "Didn't find birdhide node/5158056232 ").true