index.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. * TSRPC Browser v3.4.16
  3. * -----------------------------------------
  4. * Copyright (c) King Wang.
  5. * MIT License
  6. * https://github.com/k8w/tsrpc-browser
  7. */
  8. import { ApiReturn } from 'tsrpc-proto';
  9. import { BaseHttpClient } from 'tsrpc-base-client';
  10. import { BaseHttpClientOptions } from 'tsrpc-base-client';
  11. import { BaseServiceType } from 'tsrpc-proto';
  12. import { BaseWsClient } from 'tsrpc-base-client';
  13. import { BaseWsClientOptions } from 'tsrpc-base-client';
  14. import { ServiceProto } from 'tsrpc-proto';
  15. import { TransportOptions } from 'tsrpc-base-client';
  16. import { TsrpcError } from 'tsrpc-proto';
  17. /**
  18. * HTTP Client for TSRPC.
  19. * It uses XMLHttpRequest to send requests.
  20. * @typeParam ServiceType - `ServiceType` from generated `proto.ts`
  21. */
  22. export declare class HttpClient<ServiceType extends BaseServiceType> extends BaseHttpClient<ServiceType> {
  23. readonly options: Readonly<HttpClientOptions>;
  24. constructor(proto: ServiceProto<ServiceType>, options?: Partial<HttpClientOptions>);
  25. callApi<T extends string & keyof ServiceType['api']>(apiName: T, req: ServiceType['api'][T]['req'], options?: HttpClientTransportOptions): Promise<ApiReturn<ServiceType['api'][T]['res']>>;
  26. sendMsg<T extends string & keyof ServiceType['msg']>(msgName: T, msg: ServiceType['msg'][T], options?: HttpClientTransportOptions): Promise<{
  27. isSucc: true;
  28. } | {
  29. isSucc: false;
  30. err: TsrpcError;
  31. }>;
  32. }
  33. export declare interface HttpClientOptions extends BaseHttpClientOptions {
  34. }
  35. export declare interface HttpClientTransportOptions extends TransportOptions {
  36. /**
  37. * Event when progress of data sent is changed
  38. * @param ratio - 0~1
  39. */
  40. onProgress?: (ratio: number) => void;
  41. }
  42. /**
  43. * Client for TSRPC WebSocket Server.
  44. * @typeParam ServiceType - `ServiceType` from generated `proto.ts`
  45. */
  46. export declare class WsClient<ServiceType extends BaseServiceType> extends BaseWsClient<ServiceType> {
  47. readonly options: Readonly<WsClientOptions>;
  48. constructor(proto: ServiceProto<ServiceType>, options?: Partial<WsClientOptions>);
  49. }
  50. export declare interface WsClientOptions extends BaseWsClientOptions {
  51. /** As the 3rd parameter for `new WebSocket()` */
  52. caUrl?: string;
  53. }
  54. export * from "tsrpc-proto";
  55. export { }