| 1 | // Copyright 2024 LanceDB Developers. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | /** |
| 16 | * Middleware for Remote LanceDB Connection or Table |
| 17 | */ |
| 18 | export interface HttpMiddleware { |
| 19 | /** |
| 20 | * A callback that can be used to instrument the behavior of http requests to remote |
| 21 | * tables. It can be used to add headers, modify the request, or even short-circuit |
| 22 | * the request and return a response without making the request to the remote endpoint. |
| 23 | * It can also be used to modify the response from the remote endpoint. |
| 24 | * |
| 25 | * @param {RemoteResponse} res - Request to the remote endpoint |
| 26 | * @param {onRemoteRequestNext} next - Callback to advance the middleware chain |
| 27 | */ |
| 28 | onRemoteRequest( |
| 29 | req: RemoteRequest, |
| 30 | next: (req: RemoteRequest) => Promise<RemoteResponse>, |
| 31 | ): Promise<RemoteResponse> |
| 32 | }; |
| 33 | |
| 34 | export enum Method { |
| 35 | GET, |
| 36 | POST |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * A LanceDB Remote HTTP Request |
| 41 | */ |
| 42 | export interface RemoteRequest { |
| 43 | uri: string |
| 44 | method: Method |
| 45 | headers: Map<string, string> |
| 46 | params?: Map<string, string> |
| 47 | body?: any |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * A LanceDB Remote HTTP Response |
| 52 | */ |
| 53 | export interface RemoteResponse { |
| 54 | status: number |
| 55 | statusText: string |
| 56 | headers: Map<string, string> |
| 57 | body: () => Promise<any> |
| 58 | } |