Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This was causing many other more typical layer references to be set incorrectly as the first
// layerId found in this high level string would be used against the main object.
let parsedProp: any;
try {
parsedProp = JSON.parse(obj[i]);
} catch (error) {
parsedProp = undefined;
}
if (parsedProp && typeof parsedProp === "object") {
clone[i] = JSON.stringify(
_templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys)
);
} else if (typeof obj[i] === "object") {
// some widgets store the layerId as a key to a collection of details that contain field references
if (idTest.test(i) && templatizeKeys) {
obj[i] = common.templatizeFieldReferences(
obj[i],
ds.fields,
ds.basePath,
templatizeKeys
);
}
clone[i] = _templatizeParentByWebMapLayerId(
obj[i],
ds,
id,
templatizeKeys
);
} else {
if (idTest.test(obj[i])) {
obj = common.templatizeFieldReferences(
obj,
obj[i] = common.templatizeFieldReferences(
obj[i],
ds.fields,
ds.basePath,
templatizeKeys
);
}
clone[i] = _templatizeParentByWebMapLayerId(
obj[i],
ds,
id,
templatizeKeys
);
} else {
if (idTest.test(obj[i])) {
obj = common.templatizeFieldReferences(
obj,
ds.fields,
ds.basePath,
templatizeKeys
);
}
clone[i] = obj[i];
}
} else {
clone[i] = obj[i];
}
}
} else {
clone = obj;
}
return clone;
let urlTest: any;
if (url && !isNaN(layerId)) {
urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
}
if (Array.isArray(obj)) {
clone = obj.map(c => {
return _templatizeParentByURL(c, ds, templatizeKeys);
});
} else if (typeof obj === "object") {
for (const i in obj) {
if (obj[i] != null && typeof obj[i] === "object") {
clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
} else {
if (urlTest && urlTest.test(obj[i])) {
obj = common.templatizeFieldReferences(
obj,
ds.fields,
ds.basePath,
templatizeKeys
);
}
clone[i] = obj[i];
}
}
} else {
clone = obj;
}
return clone;
}
replaceOrder.forEach(ds => {
obj = common.templatizeFieldReferences(
obj,
ds.fields,
ds.basePath,
templatizeKeys
);
});
return obj;
_action.fieldMap = _action.fieldMap.map((m: any) => {
const _m: any = m;
_m.targetName = common.templatizeFieldReferences(
_m.targetName,
fields,
basePath
);
return _m;
});
}
_obj.datasets = _obj.datasets.map((dataset: any) => {
let _dataset: any = dataset;
if (_dataset.type === "serviceDataset") {
const datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);
if (datasourceInfo) {
const fields: any[] = common.getProp(datasourceInfo, "fields");
const basePath: string = common.getProp(
datasourceInfo,
"basePath"
);
if (Array.isArray(fields) && basePath) {
_obj = common.templatizeFieldReferences(_obj, fields, basePath);
_dataset = common.templatizeFieldReferences(
_dataset,
fields,
basePath
);
}
}
}
return _dataset;
});
return _obj;