@@ -42,6 +42,8 @@ import {
4242 ResourceResults ,
4343 RawDocumentAdditionOptions ,
4444 ContentType ,
45+ DocumentsIds ,
46+ DocumentsDeletionQuery ,
4547} from './types'
4648import { removeUndefinedFromObject } from './utils'
4749import { HttpRequests } from './http-requests'
@@ -522,19 +524,40 @@ class Index<T extends Record<string, any> = Record<string, any>> {
522524 }
523525
524526 /**
525- * Delete multiples documents of an index
527+ * Delete multiples documents of an index.
528+ *
529+ * @param params - Params value can be:
530+ *
531+ * - DocumentsDeletionQuery: An object containing the parameters to customize
532+ * your document deletion. Only available in Meilisearch v1.2 and newer
533+ * - DocumentsIds: An array of document ids to delete
526534 *
527- * @param documentsIds - Array of Document Ids to delete
528535 * @returns Promise containing an EnqueuedTask
529536 */
530537 async deleteDocuments (
531- documentsIds : string [ ] | number [ ]
538+ params : DocumentsDeletionQuery | DocumentsIds
532539 ) : Promise < EnqueuedTask > {
533- const url = `indexes/${ this . uid } /documents/delete-batch`
534-
535- const task = await this . httpRequest . post ( url , documentsIds )
540+ // If params is of type DocumentsDeletionQuery
541+ const isDocumentsDeletionQuery =
542+ ! Array . isArray ( params ) && typeof params === 'object'
543+ const endpoint = isDocumentsDeletionQuery
544+ ? 'documents/delete'
545+ : 'documents/delete-batch'
546+ const url = `indexes/${ this . uid } /${ endpoint } `
547+
548+ try {
549+ const task = await this . httpRequest . post ( url , params )
550+ return new EnqueuedTask ( task )
551+ } catch ( e ) {
552+ if (
553+ e instanceof MeiliSearchCommunicationError &&
554+ isDocumentsDeletionQuery
555+ ) {
556+ e . message = versionErrorHintMessage ( e . message , 'deleteDocuments' )
557+ }
536558
537- return new EnqueuedTask ( task )
559+ throw e
560+ }
538561 }
539562
540563 /**
0 commit comments