1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

[PM-7290] replace legacy abstraction with generation algorithms (#9435)

* replace legacy abstraction with generation algorithms
* delete mv2-based generator services
This commit is contained in:
✨ Audrey ✨
2024-06-04 11:26:20 -04:00
committed by GitHub
parent 3e93fc9461
commit 3acdd9d8fd
30 changed files with 535 additions and 1048 deletions

View File

@@ -1,4 +1,7 @@
import { distinctUntilChanged, map, OperatorFunction } from "rxjs";
import { distinctUntilChanged, map, OperatorFunction, pipe } from "rxjs";
import { DefaultPolicyEvaluator } from "./default-policy-evaluator";
import { PolicyConfiguration } from "./policies";
/**
* An observable operator that reduces an emitted collection to a single object,
@@ -36,3 +39,23 @@ export function distinctIfShallowMatch<Item>(): OperatorFunction<Item, Item> {
return isDistinct;
});
}
/** Maps an administrative console policy to a policy evaluator using the provided configuration.
* @param configuration the configuration that constructs the evaluator.
*/
export function mapPolicyToEvaluator<Policy, Evaluator>(
configuration: PolicyConfiguration<Policy, Evaluator>,
) {
return pipe(
reduceCollection(configuration.combine, configuration.disabledValue),
distinctIfShallowMatch(),
map(configuration.createEvaluator),
);
}
/** Constructs a method that maps a policy to the default (no-op) policy. */
export function newDefaultEvaluator<Target>() {
return () => {
return pipe(map((_) => new DefaultPolicyEvaluator<Target>()));
};
}