// (C) 2007-2019 GoodData Corporation // in our URI could be string chars after /obj/ const mdUriRegexp = /\[(\/gdc\/md\/[^\/]+\/obj\/[^\/]+)\]/g; const elementUriRegexp = /\[(\/gdc\/md\/[^\/]+\/obj\/[^\/]+)\/elements\?id=\d+\]/g; export function reduceMAQLItems(bucketItems: string[]): string[] { const itemsHash = bucketItems.reduce((uriItems: { [uri: string]: number }, bucketItem: string) => { if (bucketItem.startsWith("/gdc/md/")) { uriItems[bucketItem] = 1; } else { [mdUriRegexp, elementUriRegexp].forEach(regexp => { let match = regexp.exec(bucketItem); while (match) { uriItems[match[1]] = 1; match = regexp.exec(bucketItem); } }); } return uriItems; }, {}); return Object.keys(itemsHash); }