Typescript: utils/config_db.ts

virtualized-window
Alex Gleason 2022-03-20 19:40:08 -05:00
rodzic b3de700732
commit fb9c665e3e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 16 dodań i 7 usunięć

Wyświetl plik

@ -6,17 +6,25 @@ import {
} from 'immutable'; } from 'immutable';
import { trimStart } from 'lodash'; import { trimStart } from 'lodash';
const find = (configs, group, key) => { type Config = ImmutableMap<string, any>;
type Policy = ImmutableMap<string, any>;
const find = (
configs: ImmutableList<Config>,
group: string,
key: string,
): Config => {
return configs.find(config => return configs.find(config =>
config.isSuperset({ group, key }), config.isSuperset(ImmutableMap({ group, key })),
); );
}; };
const toSimplePolicy = configs => { const toSimplePolicy = (configs: ImmutableList<Config>): Policy => {
const config = find(configs, ':pleroma', ':mrf_simple'); const config = find(configs, ':pleroma', ':mrf_simple');
const reducer = (acc, curr) => { const reducer = (acc: ImmutableMap<string, any>, curr: ImmutableMap<string, any>) => {
const { tuple: [key, hosts] } = curr.toJS(); const key = curr.getIn(['tuple', 0]) as string;
const hosts = curr.getIn(['tuple', 1]) as ImmutableList<string>;
return acc.set(trimStart(key, ':'), ImmutableSet(hosts)); return acc.set(trimStart(key, ':'), ImmutableSet(hosts));
}; };
@ -28,8 +36,9 @@ const toSimplePolicy = configs => {
} }
}; };
const fromSimplePolicy = simplePolicy => { const fromSimplePolicy = (simplePolicy: Policy): ImmutableList<Config> => {
const mapper = (hosts, key) => fromJS({ tuple: [`:${key}`, hosts.toJS()] }); const mapper = (hosts: ImmutableList<string>, key: string) => fromJS({ tuple: [`:${key}`, hosts.toJS()] });
const value = simplePolicy.map(mapper).toList(); const value = simplePolicy.map(mapper).toList();
return ImmutableList([ return ImmutableList([