import { Constraint, LiftedConstraint, RelayLocation } from './daemon-rpc-types'; export interface ILocationBuilder { country(country: string): Self; city(country: string, city: string): Self; hostname(country: string, city: string, hostname: string): Self; any(): Self; fromRaw(location: LiftedConstraint): Self; } export default function makeLocationBuilder( context: T, receiver: (constraint: Constraint) => void, ): ILocationBuilder { return { country: (country: string) => { receiver({ only: { country } }); return context; }, city: (country: string, city: string) => { receiver({ only: { city: [country, city] } }); return context; }, hostname: (country: string, city: string, hostname: string) => { receiver({ only: { hostname: [country, city, hostname] } }); return context; }, any: () => { receiver('any'); return context; }, fromRaw(location: LiftedConstraint) { if (location === 'any') { return this.any(); } else { receiver({ only: location }); return context; } }, }; }