This commit is contained in:
commit
bd774932d5
614 files changed
+77116
No files matched your search
@@ -0,0 +1,24 @@
|
||||
type DashboardVariable = { name?: unknown; default?: unknown };
|
||||
|
||||
// Resolve only exact `$name` references declared by the dashboard. The query
|
||||
// planner remains the authority for accepted scope keys and values; unresolved
|
||||
// references are preserved so they fail visibly instead of widening a query.
|
||||
export function resolveDashboardScope(
|
||||
rawScope: Record<string, unknown>,
|
||||
variables: unknown[],
|
||||
): Record<string, string> {
|
||||
const defaults = new Map<string, string>();
|
||||
for (const candidate of variables) {
|
||||
if (!candidate || typeof candidate !== 'object') continue;
|
||||
const variable = candidate as DashboardVariable;
|
||||
if (typeof variable.name === 'string' && variable.name !== '' && typeof variable.default === 'string') {
|
||||
defaults.set(variable.name, variable.default);
|
||||
}
|
||||
}
|
||||
return Object.fromEntries(Object.entries(rawScope).flatMap(([key, value]) => {
|
||||
if (typeof value !== 'string') return [];
|
||||
const reference = /^\$([A-Za-z][A-Za-z0-9_-]{0,63})$/.exec(value);
|
||||
if (!reference) return [[key, value]];
|
||||
return [[key, defaults.get(reference[1]) ?? value]];
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user