|
7 | 7 | use Meilisearch\Contracts\DocumentsQuery;
|
8 | 8 | use Meilisearch\Contracts\DocumentsResults;
|
9 | 9 | use Meilisearch\Contracts\Task;
|
| 10 | +use Meilisearch\Endpoints\Tasks; |
10 | 11 | use Meilisearch\Exceptions\ApiException;
|
11 | 12 | use Meilisearch\Exceptions\InvalidResponseBodyException;
|
12 | 13 |
|
| 14 | +use function Meilisearch\partial; |
| 15 | + |
13 | 16 | trait HandlesDocuments
|
14 | 17 | {
|
15 | 18 | /**
|
@@ -42,22 +45,22 @@ public function getDocuments(?DocumentsQuery $options = null): DocumentsResults
|
42 | 45 |
|
43 | 46 | public function addDocuments(array $documents, ?string $primaryKey = null): Task
|
44 | 47 | {
|
45 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey])); |
| 48 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey]), partial(Tasks::waitTask(...), $this->http)); |
46 | 49 | }
|
47 | 50 |
|
48 | 51 | public function addDocumentsJson(string $documents, ?string $primaryKey = null): Task
|
49 | 52 | {
|
50 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/json')); |
| 53 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/json'), partial(Tasks::waitTask(...), $this->http)); |
51 | 54 | }
|
52 | 55 |
|
53 | 56 | public function addDocumentsCsv(string $documents, ?string $primaryKey = null, ?string $delimiter = null): Task
|
54 | 57 | {
|
55 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey, 'csvDelimiter' => $delimiter], 'text/csv')); |
| 58 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey, 'csvDelimiter' => $delimiter], 'text/csv'), partial(Tasks::waitTask(...), $this->http)); |
56 | 59 | }
|
57 | 60 |
|
58 | 61 | public function addDocumentsNdjson(string $documents, ?string $primaryKey = null): Task
|
59 | 62 | {
|
60 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/x-ndjson')); |
| 63 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/x-ndjson'), partial(Tasks::waitTask(...), $this->http)); |
61 | 64 | }
|
62 | 65 |
|
63 | 66 | /**
|
@@ -104,22 +107,22 @@ public function addDocumentsNdjsonInBatches(string $documents, ?int $batchSize =
|
104 | 107 |
|
105 | 108 | public function updateDocuments(array $documents, ?string $primaryKey = null): Task
|
106 | 109 | {
|
107 |
| - return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey])); |
| 110 | + return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey]), partial(Tasks::waitTask(...), $this->http)); |
108 | 111 | }
|
109 | 112 |
|
110 | 113 | public function updateDocumentsJson(string $documents, ?string $primaryKey = null): Task
|
111 | 114 | {
|
112 |
| - return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/json')); |
| 115 | + return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/json'), partial(Tasks::waitTask(...), $this->http)); |
113 | 116 | }
|
114 | 117 |
|
115 | 118 | public function updateDocumentsCsv(string $documents, ?string $primaryKey = null, ?string $delimiter = null): Task
|
116 | 119 | {
|
117 |
| - return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey, 'csvDelimiter' => $delimiter], 'text/csv')); |
| 120 | + return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey, 'csvDelimiter' => $delimiter], 'text/csv'), partial(Tasks::waitTask(...), $this->http)); |
118 | 121 | }
|
119 | 122 |
|
120 | 123 | public function updateDocumentsNdjson(string $documents, ?string $primaryKey = null): Task
|
121 | 124 | {
|
122 |
| - return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/x-ndjson')); |
| 125 | + return Task::fromArray($this->http->put(self::PATH.'/'.$this->uid.'/documents', $documents, ['primaryKey' => $primaryKey], 'application/x-ndjson'), partial(Tasks::waitTask(...), $this->http)); |
123 | 126 | }
|
124 | 127 |
|
125 | 128 | /**
|
@@ -176,29 +179,29 @@ public function updateDocumentsNdjsonInBatches(string $documents, ?int $batchSiz
|
176 | 179 | */
|
177 | 180 | public function updateDocumentsByFunction(string $function, array $options = []): Task
|
178 | 181 | {
|
179 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/edit', array_merge(['function' => $function], $options))); |
| 182 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/edit', array_merge(['function' => $function], $options)), partial(Tasks::waitTask(...), $this->http)); |
180 | 183 | }
|
181 | 184 |
|
182 | 185 | public function deleteAllDocuments(): Task
|
183 | 186 | {
|
184 |
| - return Task::fromArray($this->http->delete(self::PATH.'/'.$this->uid.'/documents')); |
| 187 | + return Task::fromArray($this->http->delete(self::PATH.'/'.$this->uid.'/documents'), partial(Tasks::waitTask(...), $this->http)); |
185 | 188 | }
|
186 | 189 |
|
187 | 190 | public function deleteDocument(string|int $documentId): Task
|
188 | 191 | {
|
189 |
| - return Task::fromArray($this->http->delete(self::PATH.'/'.$this->uid.'/documents/'.$documentId)); |
| 192 | + return Task::fromArray($this->http->delete(self::PATH.'/'.$this->uid.'/documents/'.$documentId), partial(Tasks::waitTask(...), $this->http)); |
190 | 193 | }
|
191 | 194 |
|
192 | 195 | public function deleteDocuments(array $options): Task
|
193 | 196 | {
|
194 | 197 | try {
|
195 | 198 | if (\array_key_exists('filter', $options) && $options['filter']) {
|
196 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/delete', $options)); |
| 199 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/delete', $options), partial(Tasks::waitTask(...), $this->http)); |
197 | 200 | }
|
198 | 201 |
|
199 | 202 | // backwards compatibility:
|
200 | 203 | // expect to be a array to send alongside as $documents_ids.
|
201 |
| - return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/delete-batch', $options)); |
| 204 | + return Task::fromArray($this->http->post(self::PATH.'/'.$this->uid.'/documents/delete-batch', $options), partial(Tasks::waitTask(...), $this->http)); |
202 | 205 | } catch (InvalidResponseBodyException $e) {
|
203 | 206 | throw ApiException::rethrowWithHint($e, __FUNCTION__);
|
204 | 207 | }
|
|
0 commit comments