@@ -20,7 +20,6 @@ import {
2020 IndexStats ,
2121 DocumentsQuery ,
2222 DocumentQuery ,
23- Document ,
2423 DocumentOptions ,
2524 Settings ,
2625 Synonyms ,
@@ -33,11 +32,11 @@ import {
3332 DisplayedAttributes ,
3433 TypoTolerance ,
3534 WaitOptions ,
36- DocumentsResults ,
3735 TasksQuery ,
3836 TasksResults ,
3937 PaginationSettings ,
4038 Faceting ,
39+ ResourceResults ,
4140} from './types'
4241import { removeUndefinedFromObject } from './utils'
4342import { HttpRequests } from './http-requests'
@@ -289,6 +288,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
289288 const url = `indexes/${ this . uid } /stats`
290289 return await this . httpRequest . get < IndexStats > ( url )
291290 }
291+
292292 ///
293293 /// DOCUMENTS
294294 ///
@@ -299,9 +299,9 @@ class Index<T extends Record<string, any> = Record<string, any>> {
299299 * @param parameters - Parameters to browse the documents
300300 * @returns Promise containing Document responses
301301 */
302- async getDocuments < T = Record < string , any > > (
303- parameters : DocumentsQuery < T > = { }
304- ) : Promise < DocumentsResults < T > > {
302+ async getDocuments < D extends Record < string , any > = T > (
303+ parameters : DocumentsQuery < D > = { }
304+ ) : Promise < ResourceResults < D [ ] > > {
305305 const url = `indexes/${ this . uid } /documents`
306306
307307 const fields = ( ( ) => {
@@ -311,7 +311,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
311311 return undefined
312312 } ) ( )
313313
314- return await this . httpRequest . get < Promise < DocumentsResults < T > > > (
314+ return await this . httpRequest . get < Promise < ResourceResults < D [ ] > > > (
315315 url ,
316316 removeUndefinedFromObject ( {
317317 ...parameters ,
@@ -327,10 +327,10 @@ class Index<T extends Record<string, any> = Record<string, any>> {
327327 * @param parameters - Parameters applied on a document
328328 * @returns Promise containing Document response
329329 */
330- async getDocument < T = Record < string , any > > (
330+ async getDocument < D extends Record < string , any > = T > (
331331 documentId : string | number ,
332332 parameters ?: DocumentQuery < T >
333- ) : Promise < Document < T > > {
333+ ) : Promise < D > {
334334 const url = `indexes/${ this . uid } /documents/${ documentId } `
335335
336336 const fields = ( ( ) => {
@@ -340,7 +340,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
340340 return undefined
341341 } ) ( )
342342
343- return await this . httpRequest . get < Document < T > > (
343+ return await this . httpRequest . get < D > (
344344 url ,
345345 removeUndefinedFromObject ( {
346346 ...parameters ,
@@ -357,7 +357,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
357357 * @returns Promise containing an EnqueuedTask
358358 */
359359 async addDocuments (
360- documents : Array < Document < T > > ,
360+ documents : T [ ] ,
361361 options ?: DocumentOptions
362362 ) : Promise < EnqueuedTask > {
363363 const url = `indexes/${ this . uid } /documents`
@@ -375,7 +375,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
375375 * @returns Promise containing array of enqueued task objects for each batch
376376 */
377377 async addDocumentsInBatches (
378- documents : Array < Document < T > > ,
378+ documents : T [ ] ,
379379 batchSize = 1000 ,
380380 options ?: DocumentOptions
381381 ) : Promise < EnqueuedTask [ ] > {
@@ -396,7 +396,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
396396 * @returns Promise containing an EnqueuedTask
397397 */
398398 async updateDocuments (
399- documents : Array < Document < Partial < T > > > ,
399+ documents : Array < Partial < T > > ,
400400 options ?: DocumentOptions
401401 ) : Promise < EnqueuedTask > {
402402 const url = `indexes/${ this . uid } /documents`
@@ -414,7 +414,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
414414 * @returns Promise containing array of enqueued task objects for each batch
415415 */
416416 async updateDocumentsInBatches (
417- documents : Array < Document < Partial < T > > > ,
417+ documents : Array < Partial < T > > ,
418418 batchSize = 1000 ,
419419 options ?: DocumentOptions
420420 ) : Promise < EnqueuedTask [ ] > {
@@ -555,6 +555,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
555555
556556 return new EnqueuedTask ( task )
557557 }
558+
558559 ///
559560 /// SYNONYMS
560561 ///
0 commit comments