make-client.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /// <reference types="node" />
  2. import { ChannelCredentials } from './channel-credentials';
  3. import { ChannelOptions } from './channel-options';
  4. import { Client } from './client';
  5. import { UntypedServiceImplementation } from './server';
  6. export interface Serialize<T> {
  7. (value: T): Buffer;
  8. }
  9. export interface Deserialize<T> {
  10. (bytes: Buffer): T;
  11. }
  12. export interface ClientMethodDefinition<RequestType, ResponseType> {
  13. path: string;
  14. requestStream: boolean;
  15. responseStream: boolean;
  16. requestSerialize: Serialize<RequestType>;
  17. responseDeserialize: Deserialize<ResponseType>;
  18. originalName?: string;
  19. }
  20. export interface ServerMethodDefinition<RequestType, ResponseType> {
  21. path: string;
  22. requestStream: boolean;
  23. responseStream: boolean;
  24. responseSerialize: Serialize<ResponseType>;
  25. requestDeserialize: Deserialize<RequestType>;
  26. originalName?: string;
  27. }
  28. export interface MethodDefinition<RequestType, ResponseType> extends ClientMethodDefinition<RequestType, ResponseType>, ServerMethodDefinition<RequestType, ResponseType> {
  29. }
  30. export type ServiceDefinition<ImplementationType = UntypedServiceImplementation> = {
  31. readonly [index in keyof ImplementationType]: MethodDefinition<any, any>;
  32. };
  33. export interface ProtobufTypeDefinition {
  34. format: string;
  35. type: object;
  36. fileDescriptorProtos: Buffer[];
  37. }
  38. export interface PackageDefinition {
  39. [index: string]: ServiceDefinition | ProtobufTypeDefinition;
  40. }
  41. export interface ServiceClient extends Client {
  42. [methodName: string]: Function;
  43. }
  44. export interface ServiceClientConstructor {
  45. new (address: string, credentials: ChannelCredentials, options?: Partial<ChannelOptions>): ServiceClient;
  46. service: ServiceDefinition;
  47. serviceName: string;
  48. }
  49. /**
  50. * Creates a constructor for a client with the given methods, as specified in
  51. * the methods argument. The resulting class will have an instance method for
  52. * each method in the service, which is a partial application of one of the
  53. * [Client]{@link grpc.Client} request methods, depending on `requestSerialize`
  54. * and `responseSerialize`, with the `method`, `serialize`, and `deserialize`
  55. * arguments predefined.
  56. * @param methods An object mapping method names to
  57. * method attributes
  58. * @param serviceName The fully qualified name of the service
  59. * @param classOptions An options object.
  60. * @return New client constructor, which is a subclass of
  61. * {@link grpc.Client}, and has the same arguments as that constructor.
  62. */
  63. export declare function makeClientConstructor(methods: ServiceDefinition, serviceName: string, classOptions?: {}): ServiceClientConstructor;
  64. export interface GrpcObject {
  65. [index: string]: GrpcObject | ServiceClientConstructor | ProtobufTypeDefinition;
  66. }
  67. /**
  68. * Load a gRPC package definition as a gRPC object hierarchy.
  69. * @param packageDef The package definition object.
  70. * @return The resulting gRPC object.
  71. */
  72. export declare function loadPackageDefinition(packageDef: PackageDefinition): GrpcObject;