mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
This is a copy of the files. The source in `@bitwarden/common` will be deleted once all of the applications have been ported to the library.
27 lines
920 B
TypeScript
27 lines
920 B
TypeScript
import { map, pipe } from "rxjs";
|
|
|
|
import { reduceCollection, distinctIfShallowMatch } from "@bitwarden/common/tools/rx";
|
|
|
|
import { DefaultPolicyEvaluator } from "./default-policy-evaluator";
|
|
import { PolicyConfiguration } from "./policies";
|
|
|
|
/** 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>()));
|
|
};
|
|
}
|