chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2025-05-03 23:48:35 +02:00
parent 612e71a4b6
commit 511d20eb34
245 changed files with 43884 additions and 8661 deletions

View file

@ -3,15 +3,20 @@ import { ConversionContext } from "./ConversionContext"
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
import { Translatable } from "../Json/Translatable"
import { TagConfigJson } from "../Json/TagConfigJson"
import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
import {
MappingConfigJson,
QuestionableTagRenderingConfigJson,
} from "../Json/QuestionableTagRenderingConfigJson"
export default class AddPrefixToTagRenderingConfig extends DesugaringStep<QuestionableTagRenderingConfigJson> {
private readonly _prefix: string
constructor(prefix: string) {
super("Adds `prefix` to _all_ keys. Used to add information about a subamenity withing a bigger amenity (e.g. toilets in a restaurant, a sauna in a water park, ...)", ["*"], "AddPrefixToTagRenderingConfig")
super(
"Adds `prefix` to _all_ keys. Used to add information about a subamenity withing a bigger amenity (e.g. toilets in a restaurant, a sauna in a water park, ...)",
["*"],
"AddPrefixToTagRenderingConfig"
)
this._prefix = prefix
}
@ -49,7 +54,6 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
}
}
return fixedSpec.join("")
}
private updateTranslatable(val: Translatable | undefined): Translatable | undefined {
@ -66,8 +70,8 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
return newTranslations
}
private updateTag(tags: string): string;
private updateTag(tags: TagConfigJson): TagConfigJson;
private updateTag(tags: string): string
private updateTag(tags: TagConfigJson): TagConfigJson
private updateTag(tags: TagConfigJson): TagConfigJson {
if (!tags) {
return tags
@ -82,7 +86,7 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
}
private updateTags(tags: ReadonlyArray<string>): string[] {
return tags?.map(tag => this.updateTag(tag))
return tags?.map((tag) => this.updateTag(tag))
}
private updateMapping(mapping: Readonly<MappingConfigJson>): MappingConfigJson {
@ -94,18 +98,24 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
alsoShowIf: this.updateTag(mapping.alsoShowIf),
ifnot: this.updateTag(mapping.ifnot),
priorityIf: this.updateTag(mapping.priorityIf),
hideInAnswer: mapping.hideInAnswer === true || mapping.hideInAnswer === false ? mapping.hideInAnswer : this.updateTag(mapping.hideInAnswer)
hideInAnswer:
mapping.hideInAnswer === true || mapping.hideInAnswer === false
? mapping.hideInAnswer
: this.updateTag(mapping.hideInAnswer),
}
}
public convert(json: Readonly<QuestionableTagRenderingConfigJson>, context: ConversionContext): QuestionableTagRenderingConfigJson {
public convert(
json: Readonly<QuestionableTagRenderingConfigJson>,
context: ConversionContext
): QuestionableTagRenderingConfigJson {
let freeform = json.freeform
if (freeform) {
const ff = json.freeform
freeform = {
...ff,
key: this._prefix + ":" + ff.key,
addExtraTags: this.updateTags(ff.addExtraTags)
addExtraTags: this.updateTags(ff.addExtraTags),
}
}
@ -121,14 +131,12 @@ export default class AddPrefixToTagRenderingConfig extends DesugaringStep<Questi
editButtonAriaLabel: json.editButtonAriaLabel,
onSoftDelete: this.updateTags(json.onSoftDelete),
invalidValues: this.updateTag(json.invalidValues),
mappings: json.mappings?.map(mapping => this.updateMapping(mapping)),
mappings: json.mappings?.map((mapping) => this.updateMapping(mapping)),
condition: this.updateTag(json.condition),
metacondition: json.metacondition, // no update here
filter: json.filter === true, // We break references to filters, as those references won't have the updated tags
_appliedPrefix: this._prefix
_appliedPrefix: this._prefix,
}
}
}

View file

@ -214,16 +214,20 @@ export class ExpandTagRendering extends Conversion<
const title = layer.title
if (title["render"] || title["mappings"]) {
const titleTr = <TagRenderingConfigJson>layer.title
return [{
...titleTr,
id: layer.id + "_title"
}]
return [
{
...titleTr,
id: layer.id + "_title",
},
]
} else {
const transl = <Translatable>layer.title
return [{
render: transl,
id: layer.id + "_title"
}]
return [
{
render: transl,
id: layer.id + "_title",
},
]
}
} else if (id.startsWith("*")) {
const id_ = id.substring(1)
@ -275,12 +279,18 @@ export class ExpandTagRendering extends Conversion<
* @param tr
* @private
*/
private static applyKeyPrefix(key: string | undefined, tr: Readonly<QuestionableTagRenderingConfigJson>, ctx: ConversionContext): QuestionableTagRenderingConfigJson {
private static applyKeyPrefix(
key: string | undefined,
tr: Readonly<QuestionableTagRenderingConfigJson>,
ctx: ConversionContext
): QuestionableTagRenderingConfigJson {
if (key === undefined || key === null) {
return tr
}
if (key.endsWith(":")) {
ctx.err("A 'prefix'-key should not end with a colon. The offending prefix value is: " + key)
ctx.err(
"A 'prefix'-key should not end with a colon. The offending prefix value is: " + key
)
}
return new AddPrefixToTagRenderingConfig(key).convert(tr, ctx.enter("prefix"))
}
@ -381,7 +391,12 @@ export class ExpandTagRendering extends Conversion<
(s) => s
)
if (candidates.length === 0) {
ctx.err("While reusing a tagRendering: " + name + "; no candidates in layer " + layerName)
ctx.err(
"While reusing a tagRendering: " +
name +
"; no candidates in layer " +
layerName
)
} else {
console.error("Bench was not found...")
ctx.err(
@ -410,8 +425,8 @@ export class ExpandTagRendering extends Conversion<
name +
" was not found.\n\tDid you mean one of " +
candidates.join(", ") +
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first\n" +
"HINT: are you overriding a `condition`? Check that the source condition has the format `condition: {and: [...]}`"
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first\n" +
"HINT: are you overriding a `condition`? Check that the source condition has the format `condition: {and: [...]}`"
)
continue
}

View file

@ -1,7 +1,10 @@
import { DesugaringStep } from "./Conversion"
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
import {
MappingConfigJson,
QuestionableTagRenderingConfigJson,
} from "../Json/QuestionableTagRenderingConfigJson"
import { ConversionContext } from "./ConversionContext"
import { Translation } from "../../../UI/i18n/Translation"
import Validators from "../../../UI/InputElement/Validators"

View file

@ -1,6 +1,18 @@
import { Concat, DesugaringContext, DesugaringStep, Each, FirstOf, Fuse, On, SetDefault } from "./Conversion"
import {
Concat,
DesugaringContext,
DesugaringStep,
Each,
FirstOf,
Fuse,
On,
SetDefault,
} from "./Conversion"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import { MinimalTagRenderingConfigJson, TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
import {
MinimalTagRenderingConfigJson,
TagRenderingConfigJson,
} from "../Json/TagRenderingConfigJson"
import { Utils } from "../../../Utils"
import RewritableConfigJson from "../Json/RewritableConfigJson"
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
@ -1048,10 +1060,13 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
if (json === undefined || json === null) {
throw "Error: prepareLayer got null"
}
if (json.source?.["osmTags"] !== undefined && json.source?.["osmTags"]?.["and"] === undefined) {
if (
json.source?.["osmTags"] !== undefined &&
json.source?.["osmTags"]?.["and"] === undefined
) {
json = { ...json }
json.source = <any>{ ...(<object>json.source) }
json.source["osmTags"] = { "and": [json.source["osmTags"]] }
json.source["osmTags"] = { and: [json.source["osmTags"]] }
}
return super.convert(json, context)
}

View file

@ -1,4 +1,14 @@
import { Concat, Conversion, DesugaringContext, DesugaringStep, Each, Fuse, On, Pass, SetDefault } from "./Conversion"
import {
Concat,
Conversion,
DesugaringContext,
DesugaringStep,
Each,
Fuse,
On,
Pass,
SetDefault,
} from "./Conversion"
import { ThemeConfigJson } from "../Json/ThemeConfigJson"
import { PrepareLayer, RewriteSpecial } from "./PrepareLayer"
import { LayerConfigJson } from "../Json/LayerConfigJson"
@ -153,7 +163,11 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
const unused = Array.from(hideLabels).filter((l) => !usedLabels.has(l))
if (unused.length > 0) {
context.err(
`You are attempting to import layer '${found.id}' in this theme. This layer import specifies that certain tagrenderings have to be removed based on forbidden ids and/or labels. One or more of these forbidden ids did not match any tagRenderings and caused no deletions: ${unused.join(", ")}
`You are attempting to import layer '${
found.id
}' in this theme. This layer import specifies that certain tagrenderings have to be removed based on forbidden ids and/or labels. One or more of these forbidden ids did not match any tagRenderings and caused no deletions: ${unused.join(
", "
)}
This means that this label can be removed or that the original tagRendering that should be deleted does not have this label anymore`
)
}
@ -303,7 +317,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<ThemeConfigJson> {
neededLayer: string
neededBy: string
reason: string
context?: string,
context?: string
minzoom?: number
}[] = []
do {
@ -312,7 +326,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<ThemeConfigJson> {
reason: string
context?: string
neededBy: string
checkHasSnapName: boolean,
checkHasSnapName: boolean
minzoom?: number
}[] = []

View file

@ -153,7 +153,9 @@ export class ValidateTheme extends DesugaringStep<ThemeConfigJson> {
const isCategory =
backgroundId === "photo" || backgroundId === "map" || backgroundId === "osmbasedmap"
const knownIds = Array.from(AvailableRasterLayers.allAvailableGlobalLayers).map(l => l.properties.id)
const knownIds = Array.from(AvailableRasterLayers.allAvailableGlobalLayers).map(
(l) => l.properties.id
)
const available = new Set(knownIds)
if (!isCategory && !available.has(backgroundId)) {
const nearby = Utils.sortedByLevenshteinDistance(backgroundId, knownIds, (t) => t)
@ -162,7 +164,7 @@ export class ValidateTheme extends DesugaringStep<ThemeConfigJson> {
.err(
`This layer ID is not known: ${backgroundId}. Perhaps you meant one of ${nearby
.slice(0, 5)
.join(", ")}`,
.join(", ")}`
)
}
}

View file

@ -879,11 +879,14 @@ export class ValidateLayer extends Conversion<
}
if (typeof json.allowMove === "object") {
if (!(json.allowMove.enableRelocation || json.allowMove.enableImproveAccuracy)) {
context.warn("MoveConfig: At least one default move reason should be allowed (at " + context + "); both 'enableImproveAccuracy and enableRelocation are falsy. If you don't want to allow moving points, set `allowMove: false` instead. Full config is: " + JSON.stringify(json.allowMove))
context.warn(
"MoveConfig: At least one default move reason should be allowed (at " +
context +
"); both 'enableImproveAccuracy and enableRelocation are falsy. If you don't want to allow moving points, set `allowMove: false` instead. Full config is: " +
JSON.stringify(json.allowMove)
)
}
}
return { raw: json, parsed: layerConfig }
}

View file

@ -6,17 +6,17 @@ import SpecialVisualizations from "../../UI/SpecialVisualizations"
export default class DependencyCalculator {
public static GetTagRenderingDependencies(tr: TagRenderingConfig): {
id: string,
minzoom?: number,
id: string
minzoom?: number
neededBy: string
}[] {
if (tr === undefined) {
throw "Got undefined tag rendering in getTagRenderingDependencies"
}
const deps: { id: string, minZoom?: number, neededBy: string }[] = []
const deps: { id: string; minZoom?: number; neededBy: string }[] = []
if (tr.requiredLayers) {
deps.push(...tr.requiredLayers.map(req => ({ ...req, neededBy: tr.id })))
deps.push(...tr.requiredLayers.map((req) => ({ ...req, neededBy: tr.id })))
}
// All translated snippets
@ -29,7 +29,11 @@ export default class DependencyCalculator {
.map((p) => <{ func: SpecialVisualization; args: string[] }>p)
.filter((o) => o?.func?.getLayerDependencies !== undefined)
for (const specialViz of specialVizs) {
deps.push(...specialViz.func.getLayerDependencies(specialViz.args).map(id => ({ id, neededBy: tr.id })))
deps.push(
...specialViz.func
.getLayerDependencies(specialViz.args)
.map((id) => ({ id, neededBy: tr.id }))
)
}
}
return deps
@ -51,7 +55,7 @@ export default class DependencyCalculator {
reason: string
context?: string
neededBy: string
checkHasSnapName: boolean,
checkHasSnapName: boolean
minzoom?: number
}[] = []

View file

@ -423,15 +423,15 @@ export interface LayerConfigJson {
| string
| {
id?: string
/**
* Special value: "<layerid>.title" will return the layer's title for an element
*/
/**
* Special value: "<layerid>.title" will return the layer's title for an element
*/
builtin: string | string[]
override: Partial<QuestionableTagRenderingConfigJson>,
/**
* Add this prefix to all keys. This is applied _before_ the override, thus keys added in 'override' will not be prefixed
*/
prefix?: string
override: Partial<QuestionableTagRenderingConfigJson>
/**
* Add this prefix to all keys. This is applied _before_ the override, thus keys added in 'override' will not be prefixed
*/
prefix?: string
}
| QuestionableTagRenderingConfigJson
| (RewritableConfigJson<

View file

@ -246,5 +246,5 @@ export interface TagRenderingConfigJson {
* Note: if the theme already has a layer with this ID, the value is ignored
* group: hidden
*/
requiredLayers: { id: string, minzoom?: number }[]
requiredLayers: { id: string; minzoom?: number }[]
}

View file

@ -198,8 +198,13 @@ export default class LayerConfig extends WithContextLoader {
throw context + ": Preset " + i + " tags are not an array"
}
if (pr.tags.some(t => typeof t !== "string")) {
throw context + ": Preset " + i + ": all tags should be a simple tag (thus: a string) which should also be uploadable. A non-string type is found"
if (pr.tags.some((t) => typeof t !== "string")) {
throw (
context +
": Preset " +
i +
": all tags should be a simple tag (thus: a string) which should also be uploadable. A non-string type is found"
)
}
const config: PresetConfig = {
@ -285,7 +290,9 @@ export default class LayerConfig extends WithContextLoader {
tr["rewrite"] === undefined
) ?? []
if (missingIds?.length > 0 && official) {
const msg = `Context: ${context}; Some tagRenderings of ${this.id} are missing an id: ${missingIds.map(x => JSON.stringify(x)).join(", ")} `
const msg = `Context: ${context}; Some tagRenderings of ${
this.id
} are missing an id: ${missingIds.map((x) => JSON.stringify(x)).join(", ")} `
console.error(msg)
throw msg
}

View file

@ -1,18 +1,17 @@
import { LayerConfigJson } from "./Json/LayerConfigJson"
export interface LevelInfo {
ids: string[],
ids: string[]
loop?: boolean
}
export class LayerConfigDependencyGraph {
/**
* Calculates the dependencies for the given layer
* @param layerconfig
*/
public static getLayerImports(layerconfig: LayerConfigJson): string[] {
const defaultImports: ReadonlyArray<string> = ["questions", "filters","icons"]
const defaultImports: ReadonlyArray<string> = ["questions", "filters", "icons"]
if (defaultImports.indexOf(layerconfig.id) >= 0) {
return []
}
@ -41,7 +40,6 @@ export class LayerConfigDependencyGraph {
return Array.from(imports)
}
public static buildDirectDependencies(layers: LayerConfigJson[]) {
const dependsOn = new Map<string, string[]>()
for (const layer of layers) {
@ -50,8 +48,7 @@ export class LayerConfigDependencyGraph {
}
return dependsOn
}
public static buildLevels(dependsOn: Map<string, string[]>): LevelInfo[]{
public static buildLevels(dependsOn: Map<string, string[]>): LevelInfo[] {
const levels: LevelInfo[] = []
const seenIds = new Set<string>()
while (Array.from(dependsOn.keys()).length > 0) {
@ -73,19 +70,21 @@ export class LayerConfigDependencyGraph {
continue
}
const dependencies = dependsOn.get(layerId)
newDependsOn.set(layerId, dependencies.filter(d => !seenIds.has(d)))
newDependsOn.set(
layerId,
dependencies.filter((d) => !seenIds.has(d))
)
}
const oldSize = dependsOn.size
if(oldSize === newDependsOn.size){
if (oldSize === newDependsOn.size) {
// We detected a loop.
currentLevel.loop = true
const allLayers =Array.from(newDependsOn.keys())
currentLevel.ids.push(...allLayers )
allLayers.forEach(l => seenIds.add(l))
const allLayers = Array.from(newDependsOn.keys())
currentLevel.ids.push(...allLayers)
allLayers.forEach((l) => seenIds.add(l))
}
dependsOn = newDependsOn
}
return levels
}
}

View file

@ -5,7 +5,10 @@ import { TagUtils } from "../../Logic/Tags/TagUtils"
import { And } from "../../Logic/Tags/And"
import { Utils } from "../../Utils"
import { Tag } from "../../Logic/Tags/Tag"
import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
import {
MappingConfigJson,
QuestionableTagRenderingConfigJson,
} from "./Json/QuestionableTagRenderingConfigJson"
import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import { RegexTag } from "../../Logic/Tags/RegexTag"
@ -65,7 +68,7 @@ export default class TagRenderingConfig {
*/
public readonly _definedIn: [string, string] = undefined
public readonly requiredLayers: { id: string, minzoom?: number }[]
public readonly requiredLayers: { id: string; minzoom?: number }[]
public readonly freeform?: {
readonly key: string