Strict types in RemoteConfig
This commit is contained in:
parent
a3065796fe
commit
86e6c2499c
1 changed files with 8 additions and 3 deletions
|
@ -10,6 +10,7 @@ import { parseIntOrThrow } from './util/parseIntOrThrow';
|
||||||
import { SECOND, HOUR } from './util/durations';
|
import { SECOND, HOUR } from './util/durations';
|
||||||
import * as Bytes from './Bytes';
|
import * as Bytes from './Bytes';
|
||||||
import { uuidToBytes } from './util/uuidToBytes';
|
import { uuidToBytes } from './util/uuidToBytes';
|
||||||
|
import { dropNull } from './util/dropNull';
|
||||||
import { HashType } from './types/Crypto';
|
import { HashType } from './types/Crypto';
|
||||||
import { getCountryCode } from './types/PhoneNumber';
|
import { getCountryCode } from './types/PhoneNumber';
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ type ConfigValueType = {
|
||||||
name: ConfigKeyType;
|
name: ConfigKeyType;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
enabledAt?: number;
|
enabledAt?: number;
|
||||||
value?: unknown;
|
value?: string;
|
||||||
};
|
};
|
||||||
export type ConfigMapType = {
|
export type ConfigMapType = {
|
||||||
[key in ConfigKeyType]?: ConfigValueType;
|
[key in ConfigKeyType]?: ConfigValueType;
|
||||||
|
@ -105,7 +106,11 @@ export const refreshRemoteConfig = async (
|
||||||
const oldConfig = config;
|
const oldConfig = config;
|
||||||
config = newConfig.reduce((acc, { name, enabled, value }) => {
|
config = newConfig.reduce((acc, { name, enabled, value }) => {
|
||||||
const previouslyEnabled: boolean = get(oldConfig, [name, 'enabled'], false);
|
const previouslyEnabled: boolean = get(oldConfig, [name, 'enabled'], false);
|
||||||
const previousValue: unknown = get(oldConfig, [name, 'value'], undefined);
|
const previousValue: string | undefined = get(
|
||||||
|
oldConfig,
|
||||||
|
[name, 'value'],
|
||||||
|
undefined
|
||||||
|
);
|
||||||
// If a flag was previously not enabled and is now enabled,
|
// If a flag was previously not enabled and is now enabled,
|
||||||
// record the time it was enabled
|
// record the time it was enabled
|
||||||
const enabledAt: number | undefined =
|
const enabledAt: number | undefined =
|
||||||
|
@ -115,7 +120,7 @@ export const refreshRemoteConfig = async (
|
||||||
name: name as ConfigKeyType,
|
name: name as ConfigKeyType,
|
||||||
enabled,
|
enabled,
|
||||||
enabledAt,
|
enabledAt,
|
||||||
value,
|
value: dropNull(value),
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasChanged =
|
const hasChanged =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue