client-common.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { Headers } from '@algolia/transporter';
  2. import { HostOptions } from '@algolia/transporter';
  3. import { QueryParameters } from '@algolia/transporter';
  4. import { RequestOptions } from '@algolia/transporter';
  5. import { Transporter } from '@algolia/transporter';
  6. import { TransporterOptions } from '@algolia/transporter';
  7. declare type AddedMethods<TBase, TMethods extends Methods<TBase>> = TBase & {
  8. [TKey in keyof TMethods extends string ? keyof TMethods : never]: ReturnType<TMethods[TKey]>;
  9. };
  10. export declare function addMethods<TBase extends {}, TMethods extends Methods<TBase>>(base: TBase, methods?: TMethods): AddedMethods<TBase, TMethods>;
  11. export declare type Auth = {
  12. /**
  13. * Returns the headers related to auth. Should be
  14. * merged to the transporter headers.
  15. */
  16. readonly headers: () => Readonly<Record<string, string>>;
  17. /**
  18. * Returns the query parameters related to auth. Should be
  19. * merged to the query parameters headers.
  20. */
  21. readonly queryParameters: () => Readonly<Record<string, string>>;
  22. };
  23. export declare const AuthMode: Readonly<Record<string, AuthModeType>>;
  24. export declare type AuthModeType = 0 | 1;
  25. export declare type ClientTransporterOptions = Pick<TransporterOptions, Exclude<keyof TransporterOptions, 'headers'> & Exclude<keyof TransporterOptions, 'queryParameters'> & Exclude<keyof TransporterOptions, 'hosts'>> & {
  26. /**
  27. * The hosts used by the requester.
  28. */
  29. readonly hosts?: readonly HostOptions[];
  30. /**
  31. * The headers used by the requester. The transporter
  32. * layer may add some extra headers during the request
  33. * for the user agent, and others.
  34. */
  35. readonly headers?: Headers;
  36. /**
  37. * The query parameters used by the requester. The transporter
  38. * layer may add some extra headers during the request
  39. * for the user agent, and others.
  40. */
  41. readonly queryParameters?: QueryParameters;
  42. };
  43. export declare function createAuth(authMode: AuthModeType, appId: string, apiKey: string): Auth;
  44. export declare type CreateClient<TClient, TOptions> = <TMethods extends {
  45. readonly [key: string]: (base: TClient) => (...args: any) => any;
  46. }>(options: TOptions & {
  47. readonly methods?: TMethods;
  48. }) => TClient & {
  49. [key in keyof TMethods extends string ? keyof TMethods : never]: ReturnType<TMethods[key]>;
  50. };
  51. export declare function createRetryablePromise<TResponse>(callback: (retry: () => Promise<TResponse>) => Promise<TResponse>): Promise<TResponse>;
  52. export declare function createWaitablePromise<TResponse>(promise: Readonly<Promise<TResponse>>, wait?: Wait<TResponse>): Readonly<WaitablePromise<TResponse>>;
  53. export declare const destroy: (base: {
  54. readonly transporter: Transporter;
  55. }) => () => Readonly<Promise<void>>;
  56. export declare function encode(format: string, ...args: readonly any[]): string;
  57. declare type Methods<TBase> = {
  58. readonly [key: string]: (base: TBase) => (...args: any[]) => any;
  59. };
  60. export declare function shuffle<TData>(array: TData[]): TData[];
  61. export declare const version = "4.13.0";
  62. export declare type Wait<TResponse> = (
  63. /**
  64. * The original response.
  65. */
  66. response: TResponse,
  67. /**
  68. * The custom request options.
  69. */
  70. requestOptions?: RequestOptions) => Readonly<Promise<any>>;
  71. export declare type WaitablePromise<TResponse> = Readonly<Promise<TResponse>> & {
  72. /**
  73. * Wait for a task to complete before executing the next line of code, to synchronize index updates.
  74. *
  75. * All write operations in Algolia are asynchronous by design. It means that when you add or
  76. * update an object to your index, our servers will reply to your request with a taskID as
  77. * soon as they understood the write operation. The actual insert and indexing will be
  78. * done after replying to your code.
  79. *
  80. * You can wait for a task to complete by using this method.
  81. */
  82. readonly wait: (requestOptions?: RequestOptions) => Readonly<WaitablePromise<TResponse>>;
  83. };
  84. export { }