{"version":3,"file":"validate_raster_dem_source.mjs","names":[],"sources":["../../src/validate/validate_raster_dem_source.ts"],"sourcesContent":["import {ValidationError} from '../error/validation_error';\nimport {getType} from '../util/get_type';\nimport type {RasterDEMSourceSpecification, StyleSpecification} from '../types.g';\nimport v8 from '../reference/v8.json' with {type: 'json'};\nimport {unbundle} from '../util/unbundle_jsonlint';\n\ninterface ValidateRasterDENSourceOptions {\n    sourceName?: string;\n    value: RasterDEMSourceSpecification;\n    styleSpec: typeof v8;\n    style: StyleSpecification;\n    validateSpec: Function;\n}\n\nexport function validateRasterDEMSource(\n    options: ValidateRasterDENSourceOptions\n): ValidationError[] {\n    const sourceName = options.sourceName ?? '';\n    const rasterDEM = options.value;\n    const styleSpec = options.styleSpec;\n    const rasterDEMSpec = styleSpec.source_raster_dem;\n    const style = options.style;\n\n    let errors = [];\n\n    const rootType = getType(rasterDEM);\n    if (rasterDEM === undefined) {\n        return errors;\n    } else if (rootType !== 'object') {\n        errors.push(\n            new ValidationError(\n                'source_raster_dem',\n                rasterDEM,\n                `object expected, ${rootType} found`\n            )\n        );\n        return errors;\n    }\n\n    const encoding = unbundle(rasterDEM.encoding);\n    const isCustomEncoding = encoding === 'custom';\n    const customEncodingKeys = ['redFactor', 'greenFactor', 'blueFactor', 'baseShift'];\n    const encodingName = options.value.encoding ? `\"${options.value.encoding}\"` : 'Default';\n\n    for (const key in rasterDEM) {\n        if (!isCustomEncoding && customEncodingKeys.includes(key)) {\n            errors.push(\n                new ValidationError(\n                    key,\n                    rasterDEM[key],\n                    `In \"${sourceName}\": \"${key}\" is only valid when \"encoding\" is set to \"custom\". ${encodingName} encoding found`\n                )\n            );\n        } else if (rasterDEMSpec[key]) {\n            errors = errors.concat(\n                options.validateSpec({\n                    key,\n                    value: rasterDEM[key],\n                    valueSpec: rasterDEMSpec[key],\n                    validateSpec: options.validateSpec,\n                    style,\n                    styleSpec\n                })\n            );\n        } else {\n            errors.push(new ValidationError(key, rasterDEM[key], `unknown property \"${key}\"`));\n        }\n    }\n\n    return errors;\n}\n"],"mappings":";;;;AAcA,SAAgB,wBACZ,SACiB;CACjB,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,YAAY,QAAQ;CAC1B,MAAM,YAAY,QAAQ;CAC1B,MAAM,gBAAgB,UAAU;CAChC,MAAM,QAAQ,QAAQ;CAEtB,IAAI,SAAS,CAAC;CAEd,MAAM,WAAW,QAAQ,SAAS;CAClC,IAAI,cAAc,KAAA,GACd,OAAO;MACJ,IAAI,aAAa,UAAU;EAC9B,OAAO,KACH,IAAI,gBACA,qBACA,WACA,oBAAoB,SAAS,OACjC,CACJ;EACA,OAAO;CACX;CAGA,MAAM,mBADW,SAAS,UAAU,QACJ,MAAM;CACtC,MAAM,qBAAqB;EAAC;EAAa;EAAe;EAAc;CAAW;CACjF,MAAM,eAAe,QAAQ,MAAM,WAAW,IAAI,QAAQ,MAAM,SAAS,KAAK;CAE9E,KAAK,MAAM,OAAO,WACd,IAAI,CAAC,oBAAoB,mBAAmB,SAAS,GAAG,GACpD,OAAO,KACH,IAAI,gBACA,KACA,UAAU,MACV,OAAO,WAAW,MAAM,IAAI,sDAAsD,aAAa,gBACnG,CACJ;MACG,IAAI,cAAc,MACrB,SAAS,OAAO,OACZ,QAAQ,aAAa;EACjB;EACA,OAAO,UAAU;EACjB,WAAW,cAAc;EACzB,cAAc,QAAQ;EACtB;EACA;CACJ,CAAC,CACL;MAEA,OAAO,KAAK,IAAI,gBAAgB,KAAK,UAAU,MAAM,qBAAqB,IAAI,EAAE,CAAC;CAIzF,OAAO;AACX"}