summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2019-09-10 14:18:30 +0200
committerAndrej Mihajlov <and@mullvad.net>2019-09-11 14:21:07 +0200
commit5f29340d148d7574d072766f2293f30edfa8e704 (patch)
treed631d48d52058e9cd7bc2472ff27a6db47dea5f6 /gui/src/shared
parentdbf9925d8505de938107bfa5973dbed9d6a6dfab (diff)
downloadmullvadvpn-5f29340d148d7574d072766f2293f30edfa8e704.tar.xz
mullvadvpn-5f29340d148d7574d072766f2293f30edfa8e704.zip
Add Constraint<T> and LiftedConstraint<T> helper types
Diffstat (limited to 'gui/src/shared')
-rw-r--r--gui/src/shared/daemon-rpc-types.ts34
1 files changed, 11 insertions, 23 deletions
diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts
index b16355af8f..c2368364ac 100644
--- a/gui/src/shared/daemon-rpc-types.ts
+++ b/gui/src/shared/daemon-rpc-types.ts
@@ -50,11 +50,11 @@ export function tunnelTypeToString(tunnel: TunnelType): string {
export type RelayProtocol = 'tcp' | 'udp';
-export function liftConstraint<T>(constraint: 'any' | { only: T }): 'any' | T {
- if (constraint === 'any') {
- return 'any';
- }
- return constraint.only;
+export type Constraint<T> = 'any' | { only: T };
+export type LiftedConstraint<T> = 'any' | T;
+
+export function liftConstraint<T>(constraint: Constraint<T>): LiftedConstraint<T> {
+ return constraint === 'any' ? constraint : constraint.only;
}
export type ProxyType = 'shadowsocks' | 'custom';
@@ -106,27 +106,19 @@ export type RelayLocation =
| { country: string };
export interface IOpenVpnConstraints {
- port: 'any' | { only: number };
- protocol: 'any' | { only: RelayProtocol };
+ port: Constraint<number>;
+ protocol: Constraint<RelayProtocol>;
}
export interface IWireguardConstraints {
- port: 'any' | { only: number };
+ port: Constraint<number>;
}
export type TunnelProtocol = 'wireguard' | 'openvpn';
interface IRelaySettingsNormal<OpenVpn, Wireguard> {
- location:
- | 'any'
- | {
- only: RelayLocation;
- };
- tunnelProtocol:
- | 'any'
- | {
- only: TunnelProtocol;
- };
+ location: Constraint<RelayLocation>;
+ tunnelProtocol: Constraint<TunnelProtocol>;
openvpnConstraints: OpenVpn;
wireguardConstraints: Wireguard;
}
@@ -311,11 +303,7 @@ export interface IWireguardPublicKey {
export type BridgeState = 'auto' | 'on' | 'off';
export interface IBridgeConstraints {
- location:
- | 'any'
- | {
- only: RelayLocation;
- };
+ location: Constraint<RelayLocation>;
}
export type BridgeSettings = { normal: IBridgeConstraints } | { custom: ProxySettings };