Skip to content

Commit f44b475

Browse files
Merge #1338
1338: refactor: Construct date type for related keys r=bidoubiwa a=TheLearneer # Pull Request I have updated the codebase so that the keys which are technically of date type are constructed with `Date()` object before returning. Also I have updated the Test cases. ## What does this PR do? Fixes #1223 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? - [x] Updated the test cases to see they pass Thank you so much for contributing to Meilisearch! Co-authored-by: Santosh Bhandari <[email protected]>
2 parents 81344d4 + 84abd7c commit f44b475

File tree

6 files changed

+189
-43
lines changed

6 files changed

+189
-43
lines changed

src/clients/client.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,15 @@ class Client {
266266
*/
267267
async getKeys(parameters: KeysQuery = {}): Promise<KeysResults> {
268268
const url = `keys`
269-
return await this.httpRequest.get<KeysResults>(url, parameters)
269+
const keys = await this.httpRequest.get<KeysResults>(url, parameters)
270+
271+
keys.results = keys.results.map((key) => ({
272+
...key,
273+
createdAt: new Date(key.createdAt),
274+
updateAt: new Date(key.updateAt),
275+
}))
276+
277+
return keys
270278
}
271279

272280
/**
@@ -395,7 +403,11 @@ class Client {
395403
*/
396404
async createDump(): Promise<EnqueuedTask> {
397405
const url = `dumps`
398-
return await this.httpRequest.post<undefined, EnqueuedTask>(url)
406+
const task = await this.httpRequest.post<undefined, EnqueuedTask>(url)
407+
408+
task.enqueuedAt = new Date(task.enqueuedAt)
409+
410+
return task
399411
}
400412

401413
///

src/indexes.ts

Lines changed: 140 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ class Index<T = Record<string, any>> {
195195
): Promise<EnqueuedTask> {
196196
const url = `indexes`
197197
const req = new HttpRequests(config)
198-
return req.post(url, { ...options, uid })
198+
const task = await req.post(url, { ...options, uid })
199+
200+
task.enqueuedAt = new Date(task.enqueuedAt)
201+
202+
return task
199203
}
200204

201205
/**
@@ -207,7 +211,11 @@ class Index<T = Record<string, any>> {
207211
*/
208212
async update(data: IndexOptions): Promise<EnqueuedTask> {
209213
const url = `indexes/${this.uid}`
210-
return await this.httpRequest.patch(url, data)
214+
const task = await this.httpRequest.patch(url, data)
215+
216+
task.enqueuedAt = new Date(task.enqueuedAt)
217+
218+
return task
211219
}
212220

213221
/**
@@ -218,7 +226,11 @@ class Index<T = Record<string, any>> {
218226
*/
219227
async delete(): Promise<EnqueuedTask> {
220228
const url = `indexes/${this.uid}`
221-
return await this.httpRequest.delete(url)
229+
const task = await this.httpRequest.delete(url)
230+
231+
task.enqueuedAt = new Date(task.enqueuedAt)
232+
233+
return task
222234
}
223235

224236
///
@@ -384,7 +396,11 @@ class Index<T = Record<string, any>> {
384396
options?: DocumentOptions
385397
): Promise<EnqueuedTask> {
386398
const url = `indexes/${this.uid}/documents`
387-
return await this.httpRequest.post(url, documents, options)
399+
const task = await this.httpRequest.post(url, documents, options)
400+
401+
task.enqueuedAt = new Date(task.enqueuedAt)
402+
403+
return task
388404
}
389405

390406
/**
@@ -424,7 +440,11 @@ class Index<T = Record<string, any>> {
424440
options?: DocumentOptions
425441
): Promise<EnqueuedTask> {
426442
const url = `indexes/${this.uid}/documents`
427-
return await this.httpRequest.put(url, documents, options)
443+
const task = await this.httpRequest.put(url, documents, options)
444+
445+
task.enqueuedAt = new Date(task.enqueuedAt)
446+
447+
return task
428448
}
429449

430450
/**
@@ -460,7 +480,11 @@ class Index<T = Record<string, any>> {
460480
*/
461481
async deleteDocument(documentId: string | number): Promise<EnqueuedTask> {
462482
const url = `indexes/${this.uid}/documents/${documentId}`
463-
return await this.httpRequest.delete<EnqueuedTask>(url)
483+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
484+
485+
task.enqueuedAt = new Date(task.enqueuedAt)
486+
487+
return task
464488
}
465489

466490
/**
@@ -475,7 +499,11 @@ class Index<T = Record<string, any>> {
475499
): Promise<EnqueuedTask> {
476500
const url = `indexes/${this.uid}/documents/delete-batch`
477501

478-
return await this.httpRequest.post(url, documentsIds)
502+
const task = await this.httpRequest.post(url, documentsIds)
503+
504+
task.enqueuedAt = new Date(task.enqueuedAt)
505+
506+
return task
479507
}
480508

481509
/**
@@ -486,7 +514,11 @@ class Index<T = Record<string, any>> {
486514
*/
487515
async deleteAllDocuments(): Promise<EnqueuedTask> {
488516
const url = `indexes/${this.uid}/documents`
489-
return await this.httpRequest.delete<EnqueuedTask>(url)
517+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
518+
519+
task.enqueuedAt = new Date(task.enqueuedAt)
520+
521+
return task
490522
}
491523

492524
///
@@ -514,7 +546,11 @@ class Index<T = Record<string, any>> {
514546
*/
515547
async updateSettings(settings: Settings): Promise<EnqueuedTask> {
516548
const url = `indexes/${this.uid}/settings`
517-
return await this.httpRequest.patch(url, settings)
549+
const task = await this.httpRequest.patch(url, settings)
550+
551+
task.enqueued = new Date(task.enqueuedAt)
552+
553+
return task
518554
}
519555

520556
/**
@@ -525,7 +561,11 @@ class Index<T = Record<string, any>> {
525561
*/
526562
async resetSettings(): Promise<EnqueuedTask> {
527563
const url = `indexes/${this.uid}/settings`
528-
return await this.httpRequest.delete<EnqueuedTask>(url)
564+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
565+
566+
task.enqueuedAt = new Date(task.enqueuedAt)
567+
568+
return task
529569
}
530570

531571
///
@@ -552,7 +592,11 @@ class Index<T = Record<string, any>> {
552592
*/
553593
async updateSynonyms(synonyms: Synonyms): Promise<EnqueuedTask> {
554594
const url = `indexes/${this.uid}/settings/synonyms`
555-
return await this.httpRequest.put(url, synonyms)
595+
const task = await this.httpRequest.put(url, synonyms)
596+
597+
task.enqueuedAt = new Date(task.enqueuedAt)
598+
599+
return task
556600
}
557601

558602
/**
@@ -563,7 +607,11 @@ class Index<T = Record<string, any>> {
563607
*/
564608
async resetSynonyms(): Promise<EnqueuedTask> {
565609
const url = `indexes/${this.uid}/settings/synonyms`
566-
return await this.httpRequest.delete<EnqueuedTask>(url)
610+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
611+
612+
task.enqueuedAt = new Date(task.enqueuedAt)
613+
614+
return task
567615
}
568616

569617
///
@@ -590,7 +638,11 @@ class Index<T = Record<string, any>> {
590638
*/
591639
async updateStopWords(stopWords: StopWords): Promise<EnqueuedTask> {
592640
const url = `indexes/${this.uid}/settings/stop-words`
593-
return await this.httpRequest.put(url, stopWords)
641+
const task = await this.httpRequest.put(url, stopWords)
642+
643+
task.enqueuedAt = new Date(task.enqueuedAt)
644+
645+
return task
594646
}
595647

596648
/**
@@ -601,7 +653,11 @@ class Index<T = Record<string, any>> {
601653
*/
602654
async resetStopWords(): Promise<EnqueuedTask> {
603655
const url = `indexes/${this.uid}/settings/stop-words`
604-
return await this.httpRequest.delete<EnqueuedTask>(url)
656+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
657+
658+
task.enqueuedAt = new Date(task.enqueuedAt)
659+
660+
return task
605661
}
606662

607663
///
@@ -628,7 +684,11 @@ class Index<T = Record<string, any>> {
628684
*/
629685
async updateRankingRules(rankingRules: RankingRules): Promise<EnqueuedTask> {
630686
const url = `indexes/${this.uid}/settings/ranking-rules`
631-
return await this.httpRequest.put(url, rankingRules)
687+
const task = await this.httpRequest.put(url, rankingRules)
688+
689+
task.enqueuedAt = new Date(task.enqueuedAt)
690+
691+
return task
632692
}
633693

634694
/**
@@ -639,7 +699,11 @@ class Index<T = Record<string, any>> {
639699
*/
640700
async resetRankingRules(): Promise<EnqueuedTask> {
641701
const url = `indexes/${this.uid}/settings/ranking-rules`
642-
return await this.httpRequest.delete<EnqueuedTask>(url)
702+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
703+
704+
task.enqueuedAt = new Date(task.enqueuedAt)
705+
706+
return task
643707
}
644708

645709
///
@@ -668,7 +732,11 @@ class Index<T = Record<string, any>> {
668732
distinctAttribute: DistinctAttribute
669733
): Promise<EnqueuedTask> {
670734
const url = `indexes/${this.uid}/settings/distinct-attribute`
671-
return await this.httpRequest.put(url, distinctAttribute)
735+
const task = await this.httpRequest.put(url, distinctAttribute)
736+
737+
task.enqueuedAt = new Date(task.enqueuedAt)
738+
739+
return task
672740
}
673741

674742
/**
@@ -679,7 +747,11 @@ class Index<T = Record<string, any>> {
679747
*/
680748
async resetDistinctAttribute(): Promise<EnqueuedTask> {
681749
const url = `indexes/${this.uid}/settings/distinct-attribute`
682-
return await this.httpRequest.delete<EnqueuedTask>(url)
750+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
751+
752+
task.enqueuedAt = new Date(task.enqueuedAt)
753+
754+
return task
683755
}
684756

685757
///
@@ -708,7 +780,11 @@ class Index<T = Record<string, any>> {
708780
filterableAttributes: FilterableAttributes
709781
): Promise<EnqueuedTask> {
710782
const url = `indexes/${this.uid}/settings/filterable-attributes`
711-
return await this.httpRequest.put(url, filterableAttributes)
783+
const task = await this.httpRequest.put(url, filterableAttributes)
784+
785+
task.enqueuedAt = new Date(task.enqueuedAt)
786+
787+
return task
712788
}
713789

714790
/**
@@ -719,7 +795,11 @@ class Index<T = Record<string, any>> {
719795
*/
720796
async resetFilterableAttributes(): Promise<EnqueuedTask> {
721797
const url = `indexes/${this.uid}/settings/filterable-attributes`
722-
return await this.httpRequest.delete<EnqueuedTask>(url)
798+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
799+
800+
task.enqueuedAt = new Date(task.enqueuedAt)
801+
802+
return task
723803
}
724804

725805
///
@@ -748,7 +828,11 @@ class Index<T = Record<string, any>> {
748828
sortableAttributes: SortableAttributes
749829
): Promise<EnqueuedTask> {
750830
const url = `indexes/${this.uid}/settings/sortable-attributes`
751-
return await this.httpRequest.put(url, sortableAttributes)
831+
const task = await this.httpRequest.put(url, sortableAttributes)
832+
833+
task.enqueuedAt = new Date(task.enqueuedAt)
834+
835+
return task
752836
}
753837

754838
/**
@@ -759,7 +843,11 @@ class Index<T = Record<string, any>> {
759843
*/
760844
async resetSortableAttributes(): Promise<EnqueuedTask> {
761845
const url = `indexes/${this.uid}/settings/sortable-attributes`
762-
return await this.httpRequest.delete<EnqueuedTask>(url)
846+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
847+
848+
task.enqueuedAt = new Date(task.enqueuedAt)
849+
850+
return task
763851
}
764852

765853
///
@@ -788,7 +876,11 @@ class Index<T = Record<string, any>> {
788876
searchableAttributes: SearchableAttributes
789877
): Promise<EnqueuedTask> {
790878
const url = `indexes/${this.uid}/settings/searchable-attributes`
791-
return await this.httpRequest.put(url, searchableAttributes)
879+
const task = await this.httpRequest.put(url, searchableAttributes)
880+
881+
task.enqueuedAt = new Date(task.enqueuedAt)
882+
883+
return task
792884
}
793885

794886
/**
@@ -799,7 +891,11 @@ class Index<T = Record<string, any>> {
799891
*/
800892
async resetSearchableAttributes(): Promise<EnqueuedTask> {
801893
const url = `indexes/${this.uid}/settings/searchable-attributes`
802-
return await this.httpRequest.delete<EnqueuedTask>(url)
894+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
895+
896+
task.enqueuedAt = new Date(task.enqueuedAt)
897+
898+
return task
803899
}
804900

805901
///
@@ -828,7 +924,11 @@ class Index<T = Record<string, any>> {
828924
displayedAttributes: DisplayedAttributes
829925
): Promise<EnqueuedTask> {
830926
const url = `indexes/${this.uid}/settings/displayed-attributes`
831-
return await this.httpRequest.put(url, displayedAttributes)
927+
const task = await this.httpRequest.put(url, displayedAttributes)
928+
929+
task.enqueuedAt = new Date(task.enqueuedAt)
930+
931+
return task
832932
}
833933

834934
/**
@@ -839,7 +939,11 @@ class Index<T = Record<string, any>> {
839939
*/
840940
async resetDisplayedAttributes(): Promise<EnqueuedTask> {
841941
const url = `indexes/${this.uid}/settings/displayed-attributes`
842-
return await this.httpRequest.delete<EnqueuedTask>(url)
942+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
943+
944+
task.enqueuedAt = new Date(task.enqueuedAt)
945+
946+
return task
843947
}
844948

845949
///
@@ -868,7 +972,11 @@ class Index<T = Record<string, any>> {
868972
typoTolerance: TypoTolerance
869973
): Promise<EnqueuedTask> {
870974
const url = `indexes/${this.uid}/settings/typo-tolerance`
871-
return await this.httpRequest.patch(url, typoTolerance)
975+
const task = await this.httpRequest.patch(url, typoTolerance)
976+
977+
task.enqueuedAt = new Date(task.enqueuedAt)
978+
979+
return task
872980
}
873981

874982
/**
@@ -879,7 +987,11 @@ class Index<T = Record<string, any>> {
879987
*/
880988
async resetTypoTolerance(): Promise<EnqueuedTask> {
881989
const url = `indexes/${this.uid}/settings/typo-tolerance`
882-
return await this.httpRequest.delete<EnqueuedTask>(url)
990+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
991+
992+
task.enqueuedAt = new Date(task.enqueuedAt)
993+
994+
return task
883995
}
884996
}
885997

0 commit comments

Comments
 (0)