# All files / microservices/client client-proxy-factory.ts

100% Statements 16/16
100% Branches 6/6
100% Functions 1/1
100% Lines 16/16

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    311x

    1x
    1x
    1x

    1x
    1x
    1x

    1x

    6x
    6x

    1x

    1x

    1x

    1x

    1x

    1x

     import { Transport } from '../enums/transport.enum';
    import { ClientOptions } from '../interfaces/client-metadata.interface';
    import { Closeable } from '../interfaces/closeable.interface';
    import { ClientGrpcProxy } from './client-grpc';
    import { ClientMqtt } from './client-mqtt';
    import { ClientNats } from './client-nats';
    import { ClientProxy } from './client-proxy';
    import { ClientRedis } from './client-redis';
    import { ClientTCP } from './client-tcp';
    import { ClientRMQ } from './client-rmq';

    export class ClientProxyFactory {
      public static create(clientOptions: ClientOptions): ClientProxy & Closeable {
        const { transport, options } = clientOptions;
        switch (transport) {
          case Transport.REDIS:
            return new ClientRedis(options);
          case Transport.NATS:
            return new ClientNats(options);
          case Transport.MQTT:
            return new ClientMqtt(options);
          case Transport.GRPC:
            return new ClientGrpcProxy(options);
          case Transport.RMQ:
            return new ClientRMQ(options);
          default:
            return new ClientTCP(options);
        }
      }
    }