Skip to content

Commit d3d6f29

Browse files
authored
Replace keys typing (#1126)
* Replace keys types * Remove comment
1 parent f8c3a42 commit d3d6f29

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ If you want to know more about the development workflow or want to contribute, p
419419

420420
- [Get all updates info](https://docs.meilisearch.com/reference/api/updates.html#get-all-update-status):
421421

422-
`index.getTasks(): Promise<Tasks>`
422+
`index.getTasks(): Promise<Result<Task[]>>`
423423

424424
- Wait for one task:
425425

@@ -432,10 +432,10 @@ Using de index:
432432
- Wait for multiple tasks:
433433

434434
Using de client:
435-
`client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Tasks>`
435+
`client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`
436436

437437
Using de index:
438-
`index.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Tasks>`
438+
`index.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`
439439

440440
### Indexes <!-- omit in toc -->
441441

src/lib/indexes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { MeiliSearchError } from '../errors'
1212
import {
1313
Config,
1414
Task,
15-
Tasks,
1615
SearchResponse,
1716
SearchParams,
1817
Filter,
@@ -34,6 +33,7 @@ import {
3433
SortableAttributes,
3534
SearchableAttributes,
3635
DisplayedAttributes,
36+
Result,
3737
} from '../types'
3838
import { removeUndefinedFromObject } from './utils'
3939
import { HttpRequests } from './http-requests'
@@ -230,9 +230,9 @@ class Index<T = Record<string, any>> {
230230
* @memberof Indexes
231231
* @method getTasks
232232
*
233-
* @returns {Promise<Tasks>} - Promise containing all tasks
233+
* @returns {Promise<Result<Task[]>>} - Promise containing all tasks
234234
*/
235-
async getTasks(): Promise<Tasks> {
235+
async getTasks(): Promise<Result<Task[]>> {
236236
return await this.tasks.getIndexTasks(this.uid)
237237
}
238238

@@ -257,15 +257,15 @@ class Index<T = Record<string, any>> {
257257
* @param {number[]} taskIds - Tasks identifier
258258
* @param {WaitOptions} waitOptions - Options on timeout and interval
259259
*
260-
* @returns {Promise<Tasks>} - Promise containing an array of tasks
260+
* @returns {Promise<Result<Task[]>>} - Promise containing an array of tasks
261261
*/
262262
async waitForTasks(
263263
taskIds: number[],
264264
{
265265
timeOutMs = 5000,
266266
intervalMs = 50,
267267
}: { timeOutMs?: number; intervalMs?: number } = {}
268-
): Promise<Tasks> {
268+
): Promise<Result<Task[]>> {
269269
return await this.tasks.waitForClientTasks(taskIds, {
270270
timeOutMs,
271271
intervalMs,

src/lib/meilisearch.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import {
2121
EnqueuedDump,
2222
ErrorStatusCode,
2323
Task,
24-
Tasks,
25-
// FIXME: Should be used in GET /keys
26-
// Result,
24+
Result,
2725
} from '../types'
2826
import { HttpRequests } from './http-requests'
2927
import { addProtocolIfNotPresent } from './utils'
@@ -164,9 +162,9 @@ class MeiliSearch {
164162
* Get the list of all client tasks
165163
* @memberof MeiliSearch
166164
* @method getTasks
167-
* @returns {Promise<Tasks>} - Promise returning all tasks
165+
* @returns {Promise<Result<Task[]>>} - Promise returning all tasks
168166
*/
169-
async getTasks(): Promise<Tasks> {
167+
async getTasks(): Promise<Result<Task[]>> {
170168
return await this.tasks.getClientTasks()
171169
}
172170

@@ -188,15 +186,15 @@ class MeiliSearch {
188186
* @param {number[]} taskIds - Tasks identifier
189187
* @param {WaitOptions} waitOptions - Options on timeout and interval
190188
*
191-
* @returns {Promise<Tasks>} - Promise returning an array of tasks
189+
* @returns {Promise<Result<Task[]>>} - Promise returning an array of tasks
192190
*/
193191
async waitForTasks(
194192
taskIds: number[],
195193
{
196194
timeOutMs = 5000,
197195
intervalMs = 50,
198196
}: { timeOutMs?: number; intervalMs?: number } = {}
199-
): Promise<Tasks> {
197+
): Promise<Result<Task[]>> {
200198
return await this.tasks.waitForClientTasks(taskIds, {
201199
timeOutMs,
202200
intervalMs,

src/lib/task.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MeiliSearchTimeOutError } from '../errors'
2-
import { Config, Task, Tasks, WaitOptions, TaskStatus } from '../types'
2+
import { Config, Task, WaitOptions, TaskStatus, Result } from '../types'
33
import { HttpRequests } from './http-requests'
44
import { sleep } from './utils'
55

@@ -15,19 +15,19 @@ class TaskClient {
1515
return await this.httpRequest.get<Task>(url)
1616
}
1717

18-
async getClientTasks(): Promise<Tasks> {
18+
async getClientTasks(): Promise<Result<Task[]>> {
1919
const url = `tasks`
20-
return await this.httpRequest.get<Tasks>(url)
20+
return await this.httpRequest.get<Result<Task[]>>(url)
2121
}
2222

2323
async getIndexTask(indexUid: string | number, taskId: number): Promise<Task> {
2424
const url = `indexes/${indexUid}/tasks/${taskId}`
2525
return await this.httpRequest.get<Task>(url)
2626
}
2727

28-
async getIndexTasks(indexUid: string | number): Promise<Tasks> {
28+
async getIndexTasks(indexUid: string | number): Promise<Result<Task[]>> {
2929
const url = `indexes/${indexUid}/tasks`
30-
return await this.httpRequest.get<Tasks>(url)
30+
return await this.httpRequest.get<Result<Task[]>>(url)
3131
}
3232

3333
/**
@@ -62,12 +62,12 @@ class TaskClient {
6262
*
6363
* @param {number} taskIds Tasks identifier list
6464
* @param {WaitOptions} options Wait options
65-
* @returns {Promise<Tasks>} Promise returning a list of tasks after they have been processed
65+
* @returns {Promise<Result<Task[]>>} Promise returning a list of tasks after they have been processed
6666
*/
6767
async waitForClientTasks(
6868
taskIds: number[],
6969
{ timeOutMs = 5000, intervalMs = 50 }: WaitOptions = {}
70-
): Promise<Tasks> {
70+
): Promise<Result<Task[]>> {
7171
const tasks: Task[] = []
7272
for (const taskId of taskIds) {
7373
const task = await this.waitForClientTask(taskId, {

tests/keys_tests.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe.each([{ permission: 'Master' }])('Test on keys', ({ permission }) => {
1717
test(`${permission} key: get keys`, async () => {
1818
const client = await getClient(permission)
1919
const keys = await client.getKeys()
20-
// FIXME: should be inside Result object
2120

2221
const defaultKey = keys.find((key: Key) =>
2322
key.description.startsWith('Default Search API')

0 commit comments

Comments
 (0)