Skip to content

Commit

Permalink
Merge #1424
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and trim21 authored Dec 13, 2022
2 parents b1ed904 + b2fcfe5 commit 724b94f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
27 changes: 14 additions & 13 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
IndexStats,
DocumentsQuery,
DocumentQuery,
Document,
DocumentOptions,
Settings,
Synonyms,
Expand All @@ -33,11 +32,11 @@ import {
DisplayedAttributes,
TypoTolerance,
WaitOptions,
DocumentsResults,
TasksQuery,
TasksResults,
PaginationSettings,
Faceting,
ResourceResults,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -289,6 +288,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
const url = `indexes/${this.uid}/stats`
return await this.httpRequest.get<IndexStats>(url)
}

///
/// DOCUMENTS
///
Expand All @@ -299,9 +299,9 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @param parameters - Parameters to browse the documents
* @returns Promise containing Document responses
*/
async getDocuments<T = Record<string, any>>(
parameters: DocumentsQuery<T> = {}
): Promise<DocumentsResults<T>> {
async getDocuments<D extends Record<string, any> = T>(
parameters: DocumentsQuery<D> = {}
): Promise<ResourceResults<D[]>> {
const url = `indexes/${this.uid}/documents`

const fields = (() => {
Expand All @@ -311,7 +311,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
return undefined
})()

return await this.httpRequest.get<Promise<DocumentsResults<T>>>(
return await this.httpRequest.get<Promise<ResourceResults<D[]>>>(
url,
removeUndefinedFromObject({
...parameters,
Expand All @@ -327,10 +327,10 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @param parameters - Parameters applied on a document
* @returns Promise containing Document response
*/
async getDocument<T = Record<string, any>>(
async getDocument<D extends Record<string, any> = T>(
documentId: string | number,
parameters?: DocumentQuery<T>
): Promise<Document<T>> {
): Promise<D> {
const url = `indexes/${this.uid}/documents/${documentId}`

const fields = (() => {
Expand All @@ -340,7 +340,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
return undefined
})()

return await this.httpRequest.get<Document<T>>(
return await this.httpRequest.get<D>(
url,
removeUndefinedFromObject({
...parameters,
Expand All @@ -357,7 +357,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @returns Promise containing an EnqueuedTask
*/
async addDocuments(
documents: Array<Document<T>>,
documents: T[],
options?: DocumentOptions
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/documents`
Expand All @@ -375,7 +375,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @returns Promise containing array of enqueued task objects for each batch
*/
async addDocumentsInBatches(
documents: Array<Document<T>>,
documents: T[],
batchSize = 1000,
options?: DocumentOptions
): Promise<EnqueuedTask[]> {
Expand All @@ -396,7 +396,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @returns Promise containing an EnqueuedTask
*/
async updateDocuments(
documents: Array<Document<Partial<T>>>,
documents: Array<Partial<T>>,
options?: DocumentOptions
): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/documents`
Expand All @@ -414,7 +414,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @returns Promise containing array of enqueued task objects for each batch
*/
async updateDocumentsInBatches(
documents: Array<Document<Partial<T>>>,
documents: Array<Partial<T>>,
batchSize = 1000,
options?: DocumentOptions
): Promise<EnqueuedTask[]> {
Expand Down Expand Up @@ -555,6 +555,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {

return new EnqueuedTask(task)
}

///
/// SYNONYMS
///
Expand Down
7 changes: 0 additions & 7 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ export type DocumentQuery<T = Record<string, any>> = {
fields?: Fields<T>
}

export type Document<T = Record<string, any>> = T
export type Documents<T = Record<string, any>> = Array<Document<T>>

export type DocumentsResults<T = Record<string, any>> = ResourceResults<
Documents<T>
> & {}

/*
** Settings
*/
Expand Down

0 comments on commit 724b94f

Please sign in to comment.