|
4 | 4 | // Definitions: https://github.com/meilisearch/meilisearch-js |
5 | 5 | // TypeScript Version: ^5.8.2 |
6 | 6 |
|
| 7 | +import type { WaitOptions } from "./task-and-batch.js"; |
7 | 8 | import type { FilterExpression } from "./search-parameters.js"; |
8 | 9 | import type { RecordAny } from "./shared.js"; |
9 | 10 |
|
| 11 | +/** |
| 12 | + * Shape of allowed record object that can be appended to a |
| 13 | + * {@link URLSearchParams}. |
| 14 | + */ |
| 15 | +export type URLSearchParamsRecord = Record< |
| 16 | + string, |
| 17 | + string | string[] | number | number[] | boolean | null | undefined |
| 18 | +>; |
| 19 | + |
| 20 | +/** |
| 21 | + * {@link RequestInit} without {@link RequestInit.body} and |
| 22 | + * {@link RequestInit.method} properties. |
| 23 | + */ |
| 24 | +export type ExtraRequestInit = Omit<RequestInit, "body" | "method">; |
| 25 | + |
| 26 | +/** Same as {@link ExtraRequestInit} but without {@link ExtraRequestInit.signal}. */ |
| 27 | +export type BaseRequestInit = Omit<ExtraRequestInit, "signal">; |
| 28 | + |
| 29 | +/** |
| 30 | + * Same as {@link BaseRequestInit} but with its headers property forced as a |
| 31 | + * {@link Headers} object. |
| 32 | + */ |
| 33 | +export type HttpRequestsRequestInit = Omit<BaseRequestInit, "headers"> & { |
| 34 | + headers: Headers; |
| 35 | +}; |
| 36 | + |
| 37 | +/** Main configuration object for the meilisearch client. */ |
| 38 | +export type Config = { |
| 39 | + /** |
| 40 | + * The base URL for reaching a meilisearch instance. |
| 41 | + * |
| 42 | + * @remarks |
| 43 | + * Protocol and trailing slash can be omitted. |
| 44 | + */ |
| 45 | + host: string; |
| 46 | + /** |
| 47 | + * API key for interacting with a meilisearch instance. |
| 48 | + * |
| 49 | + * @see {@link https://www.meilisearch.com/docs/learn/security/basic_security} |
| 50 | + */ |
| 51 | + apiKey?: string; |
| 52 | + /** |
| 53 | + * Custom strings that will be concatenated to the "X-Meilisearch-Client" |
| 54 | + * header on each request. |
| 55 | + */ |
| 56 | + clientAgents?: string[]; |
| 57 | + /** Base request options that may override the default ones. */ |
| 58 | + requestInit?: BaseRequestInit; |
| 59 | + /** |
| 60 | + * Custom function that can be provided in place of {@link fetch}. |
| 61 | + * |
| 62 | + * @remarks |
| 63 | + * API response errors will have to be handled manually with this as well. |
| 64 | + * @deprecated This will be removed in a future version. See |
| 65 | + * {@link https://github.com/meilisearch/meilisearch-js/issues/1824 | issue}. |
| 66 | + */ |
| 67 | + httpClient?: (...args: Parameters<typeof fetch>) => Promise<unknown>; |
| 68 | + /** Timeout in milliseconds for each HTTP request. */ |
| 69 | + timeout?: number; |
| 70 | + /** Options for waiting on tasks. */ |
| 71 | + defaultWaitOptions?: WaitOptions; |
| 72 | +}; |
| 73 | + |
| 74 | +/** Main options of a request. */ |
| 75 | +export type MainRequestOptions = { |
| 76 | + /** The path or subpath of the URL to make a request to. */ |
| 77 | + path: string; |
| 78 | + /** The REST method of the request. */ |
| 79 | + method?: string; |
| 80 | + /** The search parameters of the URL. */ |
| 81 | + params?: URLSearchParamsRecord; |
| 82 | + /** |
| 83 | + * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type | Content-Type} |
| 84 | + * passed to request {@link Headers}. |
| 85 | + */ |
| 86 | + contentType?: string; |
| 87 | + /** |
| 88 | + * The body of the request. |
| 89 | + * |
| 90 | + * @remarks |
| 91 | + * This only really supports string for now (any other type gets stringified) |
| 92 | + * but it could support more in the future. |
| 93 | + * {@link https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body} |
| 94 | + */ |
| 95 | + body?: string | boolean | number | object | null; |
| 96 | + /** |
| 97 | + * An extra, more limited {@link RequestInit}, that may override some of the |
| 98 | + * options. |
| 99 | + */ |
| 100 | + extraRequestInit?: ExtraRequestInit; |
| 101 | +}; |
| 102 | + |
| 103 | +/** |
| 104 | + * {@link MainRequestOptions} without {@link MainRequestOptions.method}, for |
| 105 | + * method functions. |
| 106 | + */ |
| 107 | +export type RequestOptions = Omit<MainRequestOptions, "method">; |
| 108 | + |
10 | 109 | /// |
11 | 110 | /// Resources |
12 | 111 | /// |
|
0 commit comments