forked from MapComplete/MapComplete
		
	chore: automated housekeeping...
This commit is contained in:
		
							parent
							
								
									14b2799f08
								
							
						
					
					
						commit
						4add2d1aff
					
				
					 151 changed files with 4561 additions and 3315 deletions
				
			
		| 
						 | 
				
			
			@ -41,7 +41,7 @@ export abstract class Conversion<TIn, TOut> {
 | 
			
		|||
            fixed = this.convert(json, context)
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            console.error(e)
 | 
			
		||||
            context.err("ERROR WHILE RUNNING STEP " + this.name+": "+e)
 | 
			
		||||
            context.err("ERROR WHILE RUNNING STEP " + this.name + ": " + e)
 | 
			
		||||
            fixed = undefined
 | 
			
		||||
        }
 | 
			
		||||
        for (const msg of context.messages) {
 | 
			
		||||
| 
						 | 
				
			
			@ -54,12 +54,11 @@ export abstract class Conversion<TIn, TOut> {
 | 
			
		|||
            throw new Error(
 | 
			
		||||
                [
 | 
			
		||||
                    "Detected one or more errors, stopping now:",
 | 
			
		||||
                    context.getAll("error").map((e) => e.context.path.join(".") + ": " + e.message)
 | 
			
		||||
                    context.getAll("error").map((e) => e.context.path.join(".") + ": " + e.message),
 | 
			
		||||
                ].join("\n\t")
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
        return fixed
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public andThenF<X>(f: (tout: TOut) => X): Conversion<TIn, X> {
 | 
			
		||||
| 
						 | 
				
			
			@ -69,8 +68,7 @@ export abstract class Conversion<TIn, TOut> {
 | 
			
		|||
    public abstract convert(json: TIn, context: ConversionContext): TOut
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export abstract class DesugaringStep<T> extends Conversion<T, T> {
 | 
			
		||||
}
 | 
			
		||||
export abstract class DesugaringStep<T> extends Conversion<T, T> {}
 | 
			
		||||
 | 
			
		||||
export class Pipe<TIn, TInter, TOut> extends Conversion<TIn, TOut> {
 | 
			
		||||
    private readonly _step0: Conversion<TIn, TInter>
 | 
			
		||||
| 
						 | 
				
			
			@ -257,7 +255,7 @@ export class Cached<TIn, TOut> extends Conversion<TIn, TOut> {
 | 
			
		|||
        const converted = this._step.convert(json, context)
 | 
			
		||||
        Object.defineProperty(json, this.key, {
 | 
			
		||||
            value: converted,
 | 
			
		||||
            enumerable: false
 | 
			
		||||
            enumerable: false,
 | 
			
		||||
        })
 | 
			
		||||
        return converted
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -270,8 +268,8 @@ export class Fuse<T> extends DesugaringStep<T> {
 | 
			
		|||
    constructor(doc: string, ...steps: DesugaringStep<T>[]) {
 | 
			
		||||
        super(
 | 
			
		||||
            (doc ?? "") +
 | 
			
		||||
            "This fused pipeline of the following steps: " +
 | 
			
		||||
            steps.map((s) => s.name).join(", "),
 | 
			
		||||
                "This fused pipeline of the following steps: " +
 | 
			
		||||
                steps.map((s) => s.name).join(", "),
 | 
			
		||||
            Utils.Dedup([].concat(...steps.map((step) => step.modifiedAttributes))),
 | 
			
		||||
            "Fuse(" + steps.map((s) => s.name).join(", ") + ")"
 | 
			
		||||
        )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,13 +55,12 @@ export class ExtractImages extends Conversion<
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    static isImageType(metapath: any): boolean {
 | 
			
		||||
        if (metapath.hints.typehint === "icon" ||
 | 
			
		||||
            metapath.hints.typehint === "image") {
 | 
			
		||||
        if (metapath.hints.typehint === "icon" || metapath.hints.typehint === "image") {
 | 
			
		||||
            return true
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const types = metapath.hints.types?.split(";").map(x => x.trim())
 | 
			
		||||
        if (types?.some(t => t === "icon" || t === "image")) {
 | 
			
		||||
        const types = metapath.hints.types?.split(";").map((x) => x.trim())
 | 
			
		||||
        if (types?.some((t) => t === "icon" || t === "image")) {
 | 
			
		||||
            return true
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +119,7 @@ export class ExtractImages extends Conversion<
 | 
			
		|||
            const allRenderedValuesAreImages = ExtractImages.isImageType(metapath)
 | 
			
		||||
 | 
			
		||||
            const found = Utils.CollectPath(metapath.path, json)
 | 
			
		||||
            if(found.length === 0){
 | 
			
		||||
            if (found.length === 0) {
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +176,7 @@ export class ExtractImages extends Conversion<
 | 
			
		|||
                                    } else {
 | 
			
		||||
                                        allFoundImages.push({
 | 
			
		||||
                                            path: img.leaf,
 | 
			
		||||
                                            context: context + "." + path
 | 
			
		||||
                                            context: context + "." + path,
 | 
			
		||||
                                        })
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
| 
						 | 
				
			
			@ -191,7 +190,7 @@ export class ExtractImages extends Conversion<
 | 
			
		|||
                                            .ExtractImages(false)
 | 
			
		||||
                                            .map((path) => ({
 | 
			
		||||
                                                path,
 | 
			
		||||
                                                context: context + "." + path
 | 
			
		||||
                                                context: context + "." + path,
 | 
			
		||||
                                            }))
 | 
			
		||||
                                    )
 | 
			
		||||
                                }
 | 
			
		||||
| 
						 | 
				
			
			@ -211,7 +210,7 @@ export class ExtractImages extends Conversion<
 | 
			
		|||
                    }
 | 
			
		||||
                    allFoundImages.push({
 | 
			
		||||
                        context: context.path.join(".") + "." + foundElement.path.join("."),
 | 
			
		||||
                        path: foundElement.leaf
 | 
			
		||||
                        path: foundElement.leaf,
 | 
			
		||||
                    })
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,10 +7,13 @@ import {
 | 
			
		|||
    FirstOf,
 | 
			
		||||
    Fuse,
 | 
			
		||||
    On,
 | 
			
		||||
    SetDefault
 | 
			
		||||
    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"
 | 
			
		||||
| 
						 | 
				
			
			@ -63,24 +66,27 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
        const newFilters: FilterConfigJson[] = []
 | 
			
		||||
        const filters = <(FilterConfigJson | string)[]>json.filter
 | 
			
		||||
 | 
			
		||||
        for (let i = 0; i < json.tagRenderings?.length; i++){
 | 
			
		||||
            const tagRendering = <TagRenderingConfigJson> json.tagRenderings[i]
 | 
			
		||||
            if(!tagRendering?.filter){
 | 
			
		||||
        for (let i = 0; i < json.tagRenderings?.length; i++) {
 | 
			
		||||
            const tagRendering = <TagRenderingConfigJson>json.tagRenderings[i]
 | 
			
		||||
            if (!tagRendering?.filter) {
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            for (const filterName of tagRendering.filter ?? []) {
 | 
			
		||||
                if(typeof filterName !== "string"){
 | 
			
		||||
                    context.enters("tagRenderings",i,"filter").err("Not a string: "+ filterName)
 | 
			
		||||
                if (typeof filterName !== "string") {
 | 
			
		||||
                    context.enters("tagRenderings", i, "filter").err("Not a string: " + filterName)
 | 
			
		||||
                }
 | 
			
		||||
                const exists = filters.some(existing => {
 | 
			
		||||
                    const id : string =  existing["id"] ?? existing
 | 
			
		||||
                    return filterName === id || (filterName.startsWith("filters.") && filterName.endsWith("."+id))
 | 
			
		||||
                const exists = filters.some((existing) => {
 | 
			
		||||
                    const id: string = existing["id"] ?? existing
 | 
			
		||||
                    return (
 | 
			
		||||
                        filterName === id ||
 | 
			
		||||
                        (filterName.startsWith("filters.") && filterName.endsWith("." + id))
 | 
			
		||||
                    )
 | 
			
		||||
                })
 | 
			
		||||
                if(exists){
 | 
			
		||||
                if (exists) {
 | 
			
		||||
                    continue
 | 
			
		||||
                }
 | 
			
		||||
                if(!filterName){
 | 
			
		||||
                    context.err("Got undefined as filter expansion in "+tagRendering["id"])
 | 
			
		||||
                if (!filterName) {
 | 
			
		||||
                    context.err("Got undefined as filter expansion in " + tagRendering["id"])
 | 
			
		||||
                    continue
 | 
			
		||||
                }
 | 
			
		||||
                filters.push(filterName)
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +95,7 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
 | 
			
		||||
        for (let i = 0; i < filters.length; i++) {
 | 
			
		||||
            const filter = filters[i]
 | 
			
		||||
            if(filter === undefined){
 | 
			
		||||
            if (filter === undefined) {
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            if (typeof filter !== "string") {
 | 
			
		||||
| 
						 | 
				
			
			@ -141,9 +147,9 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
                    const expandedFilter = (<(FilterConfigJson | string)[]>layer.filter).find(
 | 
			
		||||
                        (f) => typeof f !== "string" && f.id === expectedId
 | 
			
		||||
                    )
 | 
			
		||||
                    if(expandedFilter === undefined){
 | 
			
		||||
                        context.err("Did not find filter with name "+filter)
 | 
			
		||||
                    }else{
 | 
			
		||||
                    if (expandedFilter === undefined) {
 | 
			
		||||
                        context.err("Did not find filter with name " + filter)
 | 
			
		||||
                    } else {
 | 
			
		||||
                        newFilters.push(<FilterConfigJson>expandedFilter)
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -644,7 +650,6 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
 | 
			
		||||
 | 
			
		||||
    private readonly _desugaring: DesugaringContext
 | 
			
		||||
    private readonly _addedByDefaultAtTop: QuestionableTagRenderingConfigJson[]
 | 
			
		||||
    private readonly _addedByDefault: QuestionableTagRenderingConfigJson[]
 | 
			
		||||
| 
						 | 
				
			
			@ -669,7 +674,6 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
        return Utils.NoNull(idsInOrder.map((id) => this._desugaring.tagRenderings.get(id)))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    convert(json: LayerConfigJson, _: ConversionContext): LayerConfigJson {
 | 
			
		||||
        if (this._desugaring.tagRenderings === null) {
 | 
			
		||||
            return json
 | 
			
		||||
| 
						 | 
				
			
			@ -734,7 +738,7 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
            const trc: QuestionableTagRenderingConfigJson = {
 | 
			
		||||
                id: "all-tags",
 | 
			
		||||
                render: { "*": "{all_tags()}" },
 | 
			
		||||
                labels:["ignore_docs"],
 | 
			
		||||
                labels: ["ignore_docs"],
 | 
			
		||||
                metacondition: {
 | 
			
		||||
                    or: [
 | 
			
		||||
                        "__featureSwitchIsDebugging=true",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,8 +71,8 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
 | 
			
		|||
 | 
			
		||||
        for (const name of names) {
 | 
			
		||||
            const found = Utils.Clone(state.sharedLayers.get(name))
 | 
			
		||||
            if(found === undefined){
 | 
			
		||||
                context.err("Layer with name "+name+" not found")
 | 
			
		||||
            if (found === undefined) {
 | 
			
		||||
                context.err("Layer with name " + name + " not found")
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            found["_basedOn"] = name
 | 
			
		||||
| 
						 | 
				
			
			@ -393,7 +393,6 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
 | 
			
		|||
            }[] = []
 | 
			
		||||
 | 
			
		||||
            for (const layerConfig of alreadyLoaded) {
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    const layerDeps = DependencyCalculator.getLayerDependencies(
 | 
			
		||||
                        new LayerConfig(layerConfig, themeId + "(dependencies)")
 | 
			
		||||
| 
						 | 
				
			
			@ -402,7 +401,10 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
 | 
			
		|||
                } catch (e) {
 | 
			
		||||
                    console.error(e)
 | 
			
		||||
                    throw (
 | 
			
		||||
                        "Detecting layer dependencies for " + layerConfig?.id + " failed due to " + e
 | 
			
		||||
                        "Detecting layer dependencies for " +
 | 
			
		||||
                        layerConfig?.id +
 | 
			
		||||
                        " failed due to " +
 | 
			
		||||
                        e
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1761,7 +1761,7 @@ export class ValidateFilter extends DesugaringStep<FilterConfigJson> {
 | 
			
		|||
            // Calling another filter, we skip
 | 
			
		||||
            return filter
 | 
			
		||||
        }
 | 
			
		||||
        if(filter === undefined){
 | 
			
		||||
        if (filter === undefined) {
 | 
			
		||||
            context.err("Trying to validate a filter, but this filter is undefined")
 | 
			
		||||
            return undefined
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1990,7 +1990,7 @@ export class ValidateThemeEnsemble extends Conversion<
 | 
			
		|||
        >()
 | 
			
		||||
 | 
			
		||||
        for (const theme of json) {
 | 
			
		||||
            if(theme.id === "personal"){
 | 
			
		||||
            if (theme.id === "personal") {
 | 
			
		||||
                continue
 | 
			
		||||
            }
 | 
			
		||||
            for (const layer of theme.layers) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue