1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 11:43:51 +00:00
Files
browser/libs/common/src/platform/misc/convert-values.ts
Maciej Zieniuk 3924bc9c84 [PM-14445] TS strict for Key Management, Keys and Lock component (#13121)
* PM-14445: TS strict for Key Management Biometrics

* formatting

* callbacks not null expectations

* state nullability expectations updates

* unit tests fix

* secure channel naming, explicit null check on messageId

* KM-14445: TS strict for Key Management, Keys and Lock component

* conflicts resolution, new strict check failures

* null simplifications

* migrate legacy encryption when no active user throw error instead of hiding it

* throw instead of return
2025-02-20 18:45:37 +01:00

26 lines
1011 B
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ObservableInput, OperatorFunction, map } from "rxjs";
/**
* Converts a record of keys and values into a record preserving the original key and converting each value into an {@link ObservableInput}.
* @param project A function to project a given key and value pair into an {@link ObservableInput}
*/
export function convertValues<TKey extends PropertyKey, TInput, TOutput>(
project: (key: TKey, value: TInput) => ObservableInput<TOutput>,
): OperatorFunction<Record<TKey, TInput> | null, Record<TKey, ObservableInput<TOutput>>> {
return map((inputRecord) => {
if (inputRecord == null) {
return null;
}
// Can't use TKey in here, have to use `PropertyKey`
const result: Record<PropertyKey, ObservableInput<TOutput>> = {};
for (const [key, value] of Object.entries(inputRecord) as [TKey, TInput][]) {
result[key] = project(key, value);
}
return result;
});
}