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 }
}