Merge pull request #21691 from backstage/mhentges/transform-func-path

Add "path" to `TransformFunc` context
This commit is contained in:
Mitchell Hentges
2023-12-04 13:45:04 +01:00
committed by GitHub
4 changed files with 19 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config-loader': minor
---
Add "path" to `TransformFunc` context
+1
View File
@@ -274,6 +274,7 @@ export type TransformFunc<T extends number | string | boolean> = (
value: T,
context: {
visibility: ConfigVisibility;
path: string;
},
) => T | undefined;
```
@@ -68,7 +68,7 @@ export function filterByVisibility(
if (typeof jsonVal !== 'object') {
if (isVisible) {
if (transformFunc) {
return transformFunc(jsonVal, { visibility });
return transformFunc(jsonVal, { visibility, path: filterPath });
}
return jsonVal;
}
+12 -1
View File
@@ -105,11 +105,22 @@ export type ValidationFunc = (configs: AppConfig[]) => ValidationResult;
/**
* A function used to transform primitive configuration values.
*
* The "path" in the context is a JQ-style path to the current value from
* within the original object passed to filterByVisibility().
* For example, "field.list[2]" would refer to:
* \{
* field: [
* "foo",
* "bar",
* "baz" -- this one
* ]
* \}
*
* @public
*/
export type TransformFunc<T extends number | string | boolean> = (
value: T,
context: { visibility: ConfigVisibility },
context: { visibility: ConfigVisibility; path: string },
) => T | undefined;
/**