index.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { z } from 'zod';
  2. import { AmneziawgInboundSettingsSchema } from './amneziawg';
  3. import { HttpInboundSettingsSchema } from './http';
  4. import { HysteriaInboundSettingsSchema } from './hysteria';
  5. import { MasqueInboundSettingsSchema } from './masque';
  6. import { MixedInboundSettingsSchema } from './mixed';
  7. import { MtprotoInboundSettingsSchema } from './mtproto';
  8. import { ShadowsocksInboundSettingsSchema } from './shadowsocks';
  9. import { TrojanInboundSettingsSchema } from './trojan';
  10. import { TuicInboundSettingsSchema } from './tuic';
  11. import { TunInboundSettingsSchema } from './tun';
  12. import { TunnelInboundSettingsSchema } from './tunnel';
  13. import { VlessInboundSettingsSchema } from './vless';
  14. import { VmessInboundSettingsSchema } from './vmess';
  15. import { WireguardInboundSettingsSchema } from './wireguard';
  16. export * from './amneziawg';
  17. export * from './http';
  18. export * from './hysteria';
  19. export * from './masque';
  20. export * from './mixed';
  21. export * from './mtproto';
  22. export * from './shadowsocks';
  23. export * from './trojan';
  24. export * from './tuic';
  25. export * from './tun';
  26. export * from './tunnel';
  27. export * from './vless';
  28. export * from './vmess';
  29. export * from './wireguard';
  30. // Tagged-wrapper discriminated union. The discriminator (`protocol`) lives on
  31. // the wrapper, not inside `settings`, mirroring the wire format Xray emits:
  32. // { protocol: 'vless', settings: { clients: [...], ... }, ... }
  33. // Consumers narrow on `.protocol` and TypeScript narrows `.settings` to the
  34. // matching leaf type.
  35. export const InboundSettingsSchema = z.discriminatedUnion('protocol', [
  36. z.object({ protocol: z.literal('vmess'), settings: VmessInboundSettingsSchema }),
  37. z.object({ protocol: z.literal('vless'), settings: VlessInboundSettingsSchema }),
  38. z.object({ protocol: z.literal('trojan'), settings: TrojanInboundSettingsSchema }),
  39. z.object({ protocol: z.literal('shadowsocks'), settings: ShadowsocksInboundSettingsSchema }),
  40. z.object({ protocol: z.literal('wireguard'), settings: WireguardInboundSettingsSchema }),
  41. z.object({ protocol: z.literal('hysteria'), settings: HysteriaInboundSettingsSchema }),
  42. z.object({ protocol: z.literal('http'), settings: HttpInboundSettingsSchema }),
  43. z.object({ protocol: z.literal('mixed'), settings: MixedInboundSettingsSchema }),
  44. z.object({ protocol: z.literal('tunnel'), settings: TunnelInboundSettingsSchema }),
  45. z.object({ protocol: z.literal('tun'), settings: TunInboundSettingsSchema }),
  46. z.object({ protocol: z.literal('mtproto'), settings: MtprotoInboundSettingsSchema }),
  47. z.object({ protocol: z.literal('amneziawg'), settings: AmneziawgInboundSettingsSchema }),
  48. z.object({ protocol: z.literal('tuic'), settings: TuicInboundSettingsSchema }),
  49. z.object({ protocol: z.literal('masque'), settings: MasqueInboundSettingsSchema }),
  50. ]);
  51. export type InboundSettings = z.infer<typeof InboundSettingsSchema>;