Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,37 +413,35 @@ If you want to know more about the development workflow or want to contribute, p

### Tasks <!-- omit in toc -->

- [Get task info using the client](https://docs.meilisearch.com/reference/api/tasks.html#get-all-tasks):
- [Get all tasks](https://docs.meilisearch.com/reference/api/tasks.html#get-all-tasks)

Task list:
`client.getTasks(): Promise<Result<Task[]>>`
`client.getTasks(): Promise<Result<Task[]>>`

One task:
`client.getTask(uid: number): Promise<Task>`
- [Get one task](https://docs.meilisearch.com/reference/api/tasks.html#get-task)

- [Get task info using the index](https://docs.meilisearch.com/reference/api/tasks.html#get-all-tasks-by-index):
`client.getTask(uid: number): Promise<Task>`

Task list:
`index.getTasks(): Promise<Result<Task[]>>`
- [Get all tasks of an index](https://docs.meilisearch.com/reference/api/tasks.html#get-all-tasks-by-index)

One task:
`index.getTask(uid: number): Promise<Task>`
`index.getTasks(): Promise<Result<Task[]>>`

- [Get one task of an index](https://docs.meilisearch.com/reference/api/tasks.html#get-task)

`index.getTask(uid: number): Promise<Task>`

- Wait for one task:

Using de client:
`client.waitForTask(uid: number, { timeOutMs?: number, intervalMs?: number }): Promise<Task>`
`client.waitForTask(uid: number, { timeOutMs?: number, intervalMs?: number }): Promise<Task>`

Using the index:
`index.waitForTask(uid: number, { timeOutMs?: number, intervalMs?: number }): Promise<Task>`
With an index instance:
`index.waitForTask(uid: number, { timeOutMs?: number, intervalMs?: number }): Promise<Task>`

- Wait for multiple tasks:

Using the client:
`client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`
`client.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`

Using the index:
`index.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`
With an index instance:
`index.waitForTasks(uids: number[], { timeOutMs?: number, intervalMs?: number }): Promise<Result<Task[]>>`

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

Expand Down
8 changes: 4 additions & 4 deletions playgrounds/javascript/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const indexUid = 'movies'

const addDataset = async () => {
await client.deleteIndex(indexUid)
const { uid } = await client.createIndex(indexUid)
await client.index(indexUid).waitForTask(uid)
const { taskUid } = await client.createIndex(indexUid)
await client.index(indexUid).waitForTask(taskUid)

const documents = await client.index(indexUid).getDocuments()

Expand All @@ -28,8 +28,8 @@ const addDataset = async () => {
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
]
if (documents.length === 0) {
const task = await client.index(indexUid).addDocuments(dataset)
await client.index(indexUid).waitForTask(task.uid)
const { taskUid } = await client.index(indexUid).addDocuments(dataset)
await client.index(indexUid).waitForTask(taskUid)
}
}

Expand Down
50 changes: 24 additions & 26 deletions src/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
Result,
TokenSearchRules,
TokenOptions,
TaskParams,
WaitOptions,
} from '../types'
import { HttpRequests } from '../http-requests'
import { TaskClient } from '../task'
Expand Down Expand Up @@ -87,8 +89,8 @@ class Client {
* @returns {Promise<Index[]>} Promise returning array of raw index information
*/
async getIndexes(): Promise<Index[]> {
const response = await this.getRawIndexes()
const indexes: Index[] = response.map(
const { results } = await this.getRawIndexes()
const indexes: Index[] = results.map(
(index) => new Index(this.config, index.uid, index.primaryKey)
)
return indexes
Expand All @@ -98,11 +100,11 @@ class Client {
* Get all the indexes in their raw value (no Index instances).
* @memberof MeiliSearch
* @method getRawIndexes
* @returns {Promise<IndexResponse[]>} Promise returning array of raw index information
* @returns {Promise<Result<IndexResponse[]>>} Promise returning array of raw index information
*/
async getRawIndexes(): Promise<IndexResponse[]> {
async getRawIndexes(): Promise<Result<IndexResponse[]>> {
const url = `indexes`
return await this.httpRequest.get<IndexResponse[]>(url)
return await this.httpRequest.get<Result<IndexResponse[]>>(url)
}

/**
Expand Down Expand Up @@ -177,61 +179,57 @@ class Client {
* @method getTasks
* @returns {Promise<Result<Task[]>>} - Promise returning all tasks
*/
async getTasks(): Promise<Result<Task[]>> {
return await this.tasks.getClientTasks()
async getTasks(params?: TaskParams): Promise<Result<Task[]>> {
return await this.tasks.getTasks(params)
}

/**
* Get one task on the client scope
* @memberof MeiliSearch
* @method getTask
* @param {number} taskId - Task identifier
* @param {number} taskUid - Task identifier
* @returns {Promise<Task>} - Promise returning a task
*/
async getTask(taskId: number): Promise<Task> {
return await this.tasks.getClientTask(taskId)
async getTask(taskUid: number): Promise<Task> {
return await this.tasks.getTask(taskUid)
}

/**
* Wait for a batch of tasks to be processed.
* Wait for multiple tasks to be finished.
*
* @memberof MeiliSearch
* @method waitForTasks
* @param {number[]} taskIds - Tasks identifier
* @param {number[]} taskUids - Tasks identifier
* @param {WaitOptions} waitOptions - Options on timeout and interval
*
* @returns {Promise<Result<Task[]>>} - Promise returning an array of tasks
*/
async waitForTasks(
taskIds: number[],
{
timeOutMs = 5000,
intervalMs = 50,
}: { timeOutMs?: number; intervalMs?: number } = {}
taskUids: number[],
{ timeOutMs = 5000, intervalMs = 50 }: WaitOptions = {}
): Promise<Result<Task[]>> {
return await this.tasks.waitForClientTasks(taskIds, {
return await this.tasks.waitForTasks(taskUids, {
timeOutMs,
intervalMs,
})
}

/**
* Wait for a task to be processed.
* Wait for a task to be finished.
*
* @memberof MeiliSearch
* @method waitForTask
* @param {number} taskId - Task identifier
*
* @param {number} taskUid - Task identifier
* @param {WaitOptions} waitOptions - Options on timeout and interval
*
* @returns {Promise<Task>} - Promise returning an array of tasks
*/
async waitForTask(
taskId: number,
{
timeOutMs = 5000,
intervalMs = 50,
}: { timeOutMs?: number; intervalMs?: number } = {}
taskUid: number,
{ timeOutMs = 5000, intervalMs = 50 }: WaitOptions = {}
): Promise<Task> {
return await this.tasks.waitForClientTask(taskId, {
return await this.tasks.waitForTask(taskUid, {
timeOutMs,
intervalMs,
})
Expand Down
37 changes: 16 additions & 21 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
DisplayedAttributes,
TypoTolerance,
Result,
WaitOptions,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -222,71 +223,65 @@ class Index<T = Record<string, any>> {
///

/**
* Get the list of all the index tasks.
* Get the list of all the tasks of the index.
*
* @memberof Indexes
* @method getTasks
*
* @returns {Promise<Result<Task[]>>} - Promise containing all tasks
*/
async getTasks(): Promise<Result<Task[]>> {
return await this.tasks.getIndexTasks(this.uid)
return await this.tasks.getTasks({ indexUid: [this.uid] })
}

/**
* Get one task of the index.
*
* @memberof Indexes
* @method getTask
* @param {number} taskId - Task identifier
* @param {number} taskUid - Task identifier
*
* @returns {Promise<Task>} - Promise containing a task
*/
async getTask(taskId: number): Promise<Task> {
return await this.tasks.getIndexTask(this.uid, taskId)
async getTask(taskUid: number): Promise<Task> {
return await this.tasks.getTask(taskUid)
}

/**
* Wait for a batch of an index tasks to be processed.
* Wait for multiple tasks to be processed.
*
* @memberof Indexes
* @method waitForTasks
* @param {number[]} taskIds - Tasks identifier
* @param {number[]} taskUids - Tasks identifier
* @param {WaitOptions} waitOptions - Options on timeout and interval
*
* @returns {Promise<Result<Task[]>>} - Promise containing an array of tasks
*/
async waitForTasks(
taskIds: number[],
{
timeOutMs = 5000,
intervalMs = 50,
}: { timeOutMs?: number; intervalMs?: number } = {}
taskUids: number[],
{ timeOutMs = 5000, intervalMs = 50 }: WaitOptions = {}
): Promise<Result<Task[]>> {
return await this.tasks.waitForClientTasks(taskIds, {
return await this.tasks.waitForTasks(taskUids, {
timeOutMs,
intervalMs,
})
}

/**
* Wait for an index task to be processed.
* Wait for a task to be processed.
*
* @memberof Indexes
* @method waitForTask
* @param {number} taskId - Task identifier
* @param {number} taskUid - Task identifier
* @param {WaitOptions} waitOptions - Options on timeout and interval
*
* @returns {Promise<Task>} - Promise containing an array of tasks
*/
async waitForTask(
taskId: number,
{
timeOutMs = 5000,
intervalMs = 50,
}: { timeOutMs?: number; intervalMs?: number } = {}
taskUid: number,
{ timeOutMs = 5000, intervalMs = 50 }: WaitOptions = {}
): Promise<Task> {
return await this.tasks.waitForClientTask(taskId, {
return await this.tasks.waitForTask(taskUid, {
timeOutMs,
intervalMs,
})
Expand Down
Loading