-
Notifications
You must be signed in to change notification settings - Fork 90
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
base: main
Are you sure you want to change the base?
Improve HttpRequests
#1741
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1741 +/- ##
==========================================
- Coverage 97.81% 97.66% -0.16%
==========================================
Files 17 17
Lines 1465 1498 +33
Branches 307 317 +10
==========================================
+ Hits 1433 1463 +30
- Misses 32 35 +3 ☔ View full report in Codecov by Sentry. |
src/clients/client.ts
Outdated
body: params, | ||
})) as EnqueuedTaskObject; | ||
|
||
return new EnqueuedTask(taks); | ||
} |
There was a problem hiding this comment.
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
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", | ||
); | ||
}); |
There was a problem hiding this comment.
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`, () => { |
There was a problem hiding this comment.
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.
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); | ||
} |
There was a problem hiding this comment.
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
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); | ||
} |
There was a problem hiding this comment.
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
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); | ||
} |
There was a problem hiding this comment.
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
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); | ||
} |
There was a problem hiding this comment.
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
Pull Request
Sorry for the huge PR, but
HttpRequests
is core, and is used everywhere.What does this PR do?
EnqueuedTaskObject
s not being converted toEnqueuedTask
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:
Thank you so much for contributing to Meilisearch!