Skip to content

Commit 9e43b62

Browse files
Merge #1741
1741: Improve `HttpRequests` r=Strift a=flevi29 # Pull Request Sorry for the huge PR, but `HttpRequests` is core, and is used everywhere. ## What does this PR do? - completely refactors [http-requests.ts](https://github.com/meilisearch/meilisearch-js/blob/main/src/http-requests.ts) - fixes #1654 - request parameters are now simple and straight forward - types are reworked and no longer confusing - makes full use of [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL), [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) and [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) web standard features, which are safer and easier to work with - makes use of [Private properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties) to hide internal implementation that should not be public (this is [widely supported](https://caniuse.com/mdn-javascript_classes_private_class_fields) and [polyfillable](https://babeljs.io/docs/babel-plugin-transform-private-methods)) - fixes some `EnqueuedTaskObject`s not being converted to `EnqueuedTask` > [!CAUTION] > #### BREAKING > Rename `Config.requestConfig` -> `Config.requestInit`, `signal` can no longer be passed to it. > [!WARNING] > Deprecate `Config.httpClient` #1824 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: F. Levi <55688616+flevi29@users.noreply.github.com>
2 parents dafbb44 + cf636f9 commit 9e43b62

16 files changed

+1013
-778
lines changed

src/batch.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
BatchesResults,
66
BatchesResultsObject,
77
} from "./types.js";
8-
import { HttpRequests, toQueryParams } from "./http-requests.js";
8+
import { HttpRequests } from "./http-requests.js";
99

1010
class Batch {
1111
uid: BatchObject["uid"];
@@ -41,8 +41,9 @@ class BatchClient {
4141
* @returns
4242
*/
4343
async getBatch(uid: number): Promise<Batch> {
44-
const url = `batches/${uid}`;
45-
const batch = await this.httpRequest.get<BatchObject>(url);
44+
const batch = await this.httpRequest.get<BatchObject>({
45+
path: `batches/${uid}`,
46+
});
4647
return new Batch(batch);
4748
}
4849

@@ -52,13 +53,11 @@ class BatchClient {
5253
* @param parameters - Parameters to browse the batches
5354
* @returns Promise containing all batches
5455
*/
55-
async getBatches(parameters: BatchesQuery = {}): Promise<BatchesResults> {
56-
const url = `batches`;
57-
58-
const batches = await this.httpRequest.get<Promise<BatchesResultsObject>>(
59-
url,
60-
toQueryParams<BatchesQuery>(parameters),
61-
);
56+
async getBatches(batchesQuery?: BatchesQuery): Promise<BatchesResults> {
57+
const batches = await this.httpRequest.get<BatchesResultsObject>({
58+
path: "batches",
59+
params: batchesQuery,
60+
});
6261

6362
return {
6463
...batches,

0 commit comments

Comments
 (0)