Merge pull request #21691 from backstage/mhentges/transform-func-path
Add "path" to `TransformFunc` context
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/config-loader': minor
|
||||
---
|
||||
|
||||
Add "path" to `TransformFunc` context
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user