Skip to content

Commit 724b94f

Browse files
Merge #1424
1424: remove `Document` and `Documents` r=bidoubiwa a=trim21 # Pull Request ## Related issue Fixes #1421 ## What does this PR do? remove `Document` and `Documents` ## PR checklist Please check if your PR fulfills the following requirements: - [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [X] Have you read the contributing guidelines? - [X] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Trim21 <[email protected]>
2 parents b1ed904 + b2fcfe5 commit 724b94f

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/indexes.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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'
4241
import { removeUndefinedFromObject } from './utils'
4342
import { 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
///

src/types/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,6 @@ export type DocumentQuery<T = Record<string, any>> = {
161161
fields?: Fields<T>
162162
}
163163

164-
export type Document<T = Record<string, any>> = T
165-
export type Documents<T = Record<string, any>> = Array<Document<T>>
166-
167-
export type DocumentsResults<T = Record<string, any>> = ResourceResults<
168-
Documents<T>
169-
> & {}
170-
171164
/*
172165
** Settings
173166
*/

0 commit comments

Comments
 (0)