diff --git a/app/soapbox/utils/config_db.js b/app/soapbox/utils/config_db.ts similarity index 52% rename from app/soapbox/utils/config_db.js rename to app/soapbox/utils/config_db.ts index 98fe650d9..1ea8a0b8c 100644 --- a/app/soapbox/utils/config_db.js +++ b/app/soapbox/utils/config_db.ts @@ -6,17 +6,25 @@ import { } from 'immutable'; import { trimStart } from 'lodash'; -const find = (configs, group, key) => { +type Config = ImmutableMap; +type Policy = ImmutableMap; + +const find = ( + configs: ImmutableList, + group: string, + key: string, +): Config => { return configs.find(config => - config.isSuperset({ group, key }), + config.isSuperset(ImmutableMap({ group, key })), ); }; -const toSimplePolicy = configs => { +const toSimplePolicy = (configs: ImmutableList): Policy => { const config = find(configs, ':pleroma', ':mrf_simple'); - const reducer = (acc, curr) => { - const { tuple: [key, hosts] } = curr.toJS(); + const reducer = (acc: ImmutableMap, curr: ImmutableMap) => { + const key = curr.getIn(['tuple', 0]) as string; + const hosts = curr.getIn(['tuple', 1]) as ImmutableList; return acc.set(trimStart(key, ':'), ImmutableSet(hosts)); }; @@ -28,8 +36,9 @@ const toSimplePolicy = configs => { } }; -const fromSimplePolicy = simplePolicy => { - const mapper = (hosts, key) => fromJS({ tuple: [`:${key}`, hosts.toJS()] }); +const fromSimplePolicy = (simplePolicy: Policy): ImmutableList => { + const mapper = (hosts: ImmutableList, key: string) => fromJS({ tuple: [`:${key}`, hosts.toJS()] }); + const value = simplePolicy.map(mapper).toList(); return ImmutableList([