Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve HttpRequests #1741

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Oct 9, 2024

Pull Request

Sorry for the huge PR, but HttpRequests is core, and is used everywhere.

What does this PR do?

Caution

BREAKING: From now on only some methods are public on HttpRequests (get, post, put, patch, delete), the rest of the properties and methods are internal implementation details, and are not meant to be directly accessed.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 98.97260% with 6 lines in your changes missing coverage. Please review.

Project coverage is 98.06%. Comparing base (896b5c0) to head (36c174f).

Files with missing lines Patch % Lines
src/http-requests.ts 96.29% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1741      +/-   ##
==========================================
- Coverage   98.20%   98.06%   -0.15%     
==========================================
  Files          18       18              
  Lines        1562     1603      +41     
  Branches      333      343      +10     
==========================================
+ Hits         1534     1572      +38     
- Misses         28       31       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flevi29 flevi29 added maintenance Issue about maintenance (CI, tests, refacto...) breaking-change The related changes are breaking for the users and removed maintenance Issue about maintenance (CI, tests, refacto...) labels Oct 9, 2024
@flevi29 flevi29 linked an issue Oct 10, 2024 that may be closed by this pull request
body: params,
})) as EnqueuedTaskObject;

return new EnqueuedTask(taks);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: previously this did not return EnqueuedTask, but rather EnqueuedTaskObject

Comment on lines +72 to 95
test(`${permission} key: Create client with custom headers (object)`, async () => {
const key = await getKey(permission);
const client = new MeiliSearch({
...config,
apiKey: key,
requestInit: {
headers: {
"Hello-There!": "General Kenobi",
},
},
},
});

assert.isTrue(await client.isHealthy());

assert.isDefined(fetchSpy.mock.lastCall);
const [, requestInit] = fetchSpy.mock.lastCall!;

assert.isDefined(requestInit?.headers);
assert.instanceOf(requestInit!.headers, Headers);
assert.strictEqual(
(requestInit!.headers! as Headers).get("Hello-There!"),
"General Kenobi",
);
});
Copy link
Collaborator Author

@flevi29 flevi29 Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because headers are internal implementation details, to check them we have to spy on fetch now.

});

test(`Client handles host URL with domain and path and no trailing slash`, () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this test into the other.

src/indexes.ts Outdated
Comment on lines 256 to 263
async update(data?: IndexOptions): Promise<EnqueuedTask> {
const task = (await this.httpRequest.patch({
relativeURL: `indexes/${this.uid}`,
body: data,
})) as EnqueuedTaskObject;

task.enqueuedAt = new Date(task.enqueuedAt);

return task;
return new EnqueuedTask(task);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: previously this did not return EnqueuedTask

Comment on lines 565 to 571
async deleteDocument(documentId: string | number): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/documents/${documentId}`;
const task = await this.httpRequest.delete<EnqueuedTask>(url);

task.enqueuedAt = new Date(task.enqueuedAt);
const task = (await this.httpRequest.delete({
relativeURL: `indexes/${this.uid}/documents/${documentId}`,
})) as EnqueuedTaskObject;

return task;
return new EnqueuedTask(task);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: previously this did not return EnqueuedTask

src/indexes.ts Outdated
Comment on lines 617 to 623
async deleteAllDocuments(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/documents`;
const task = await this.httpRequest.delete<EnqueuedTask>(url);
const task = (await this.httpRequest.delete({
relativeURL: `indexes/${this.uid}/documents`,
})) as EnqueuedTaskObject;

task.enqueuedAt = new Date(task.enqueuedAt);

return task;
return new EnqueuedTask(task);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: previously this did not return EnqueuedTask

Comment on lines 669 to 676
async updateSettings(settings: Settings): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings`;
const task = await this.httpRequest.patch(url, settings);
const task = (await this.httpRequest.patch({
relativeURL: `indexes/${this.uid}/settings`,
body: settings,
})) as EnqueuedTaskObject;

task.enqueued = new Date(task.enqueuedAt);

return task;
return new EnqueuedTask(task);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: previously this did not return EnqueuedTask, I'm not going to mark the rest, there are more

src/indexes.ts Outdated Show resolved Hide resolved
@flevi29 flevi29 marked this pull request as ready for review October 11, 2024 08:37
@flevi29 flevi29 requested a review from brunoocasali October 11, 2024 11:00
@Barabasbalazs Barabasbalazs mentioned this pull request Oct 21, 2024
3 tasks
@flevi29 flevi29 added the bug Something isn't working label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout implementation for requests should be re-thought
1 participant