summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2017-11-21 12:09:40 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-11-23 12:41:13 +0100
commita1a7a920e787689eed8525f4c2ffd521c9d538ff (patch)
tree3a7b70ecefb5c23d0651088c58700e90bb63e3ae
parente32bdb95e3762f1ac48892062a5cdb022d07e5b4 (diff)
downloadmullvadvpn-a1a7a920e787689eed8525f4c2ffd521c9d538ff.tar.xz
mullvadvpn-a1a7a920e787689eed8525f4c2ffd521c9d538ff.zip
Refactor `RelaySettingsUpdate` type
-rw-r--r--app/lib/ipc-facade.js74
1 files changed, 35 insertions, 39 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js
index 1a7b93ad98..60dbc606b9 100644
--- a/app/lib/ipc-facade.js
+++ b/app/lib/ipc-facade.js
@@ -27,53 +27,49 @@ export type BackendState = {
state: SecurityState,
target_state: SecurityState,
};
+
type RelayProtocol = 'tcp' | 'udp';
-type RelaySettings = {
- normal: {
- location: 'any' | {
- only: { city: Array<string> } | { country: string },
- },
- tunnel: {
- openvpn: {
- port: 'any' | { only: number },
- protocol: 'any' | { only: RelayProtocol },
- },
- },
+
+type OpenVpnParameters = {
+ port: 'any' | { only: number },
+ protocol: 'any' | { only: RelayProtocol },
+};
+
+type TunnelOptions<TOpenVpnParameters> = {
+ openvpn: TOpenVpnParameters,
+};
+
+type RelaySettingsNormal<TTunnelOptions> = {
+ location: 'any' | {
+ only: { city: Array<string> } | { country: string },
},
-} | {
- custom_tunnel_endpoint: {
- host: string,
- tunnel: {
- openvpn: {
- port: number,
- protocol: RelayProtocol
- }
+ tunnel: 'any' | TTunnelOptions,
+};
+
+type RelaySettingsCustom = {
+ host: string,
+ tunnel: {
+ openvpn: {
+ port: number,
+ protocol: RelayProtocol
}
}
};
+
+type RelaySettings = {
+ normal: RelaySettingsNormal<TunnelOptions<OpenVpnParameters>>
+} | {
+ custom_tunnel_endpoint: RelaySettingsCustom
+};
+
export type RelaySettingsUpdate = {
- normal: {
- location?: 'any' | {
- only: { city: Array<string> } | { country: string },
- },
- tunnel: {
- openvpn: {
- port?: 'any' | { only: number },
- protocol?: 'any' | { only: RelayProtocol },
- },
- }
- },
+ normal: $Shape<
+ RelaySettingsNormal< TunnelOptions<$Shape<OpenVpnParameters> > >
+ >
} | {
- custom_tunnel_endpoint: {
- host: string,
- tunnel: {
- openvpn: {
- port: number,
- protocol: RelayProtocol
- }
- }
- }
+ custom_tunnel_endpoint: RelaySettingsCustom
};
+
const Constraint = (v) => oneOf(string, object({
only: v,
}));